zot/examples/extensions/scratchpad
patriceckhart 83b64e2562 examples: scratchpad notes persist to .zot/scratchpad-notes.jsonl
Notes are now project-local and survive zot restarts. The
extension reads its cwd from the hello_ack handshake, then:

  - on /note    appends one line of {"at":..,"text":..} JSONL
                under <cwd>/.zot/scratchpad-notes.jsonl
  - on /notes   reads the in-memory cache (loaded on hello_ack)
  - on /clear-notes truncates the file and clears the cache
  - on read_notes (tool) returns the cached set

Single-writer assumption (one zot session per cwd at a time);
two concurrent zot processes writing to the same file would
interleave but JSONL line boundaries stay intact under POSIX
PIPE_BUF semantics. Good enough for an example.

Verified end-to-end: round 1 writes two notes via the slash
command, round 2 (fresh extension process, same cwd) loads
them and surfaces them via both /notes and the read_notes
tool.
2026-04-19 15:16:06 +02:00
..
extension.json perf(extensions): parallel discovery + auto-ready idle watchdog 2026-04-19 15:13:19 +02:00
index.ts examples: scratchpad notes persist to .zot/scratchpad-notes.jsonl 2026-04-19 15:16:06 +02:00
README.md examples: scratchpad notes persist to .zot/scratchpad-notes.jsonl 2026-04-19 15:16:06 +02:00

scratchpad — TypeScript extension example

Real .ts (not .js), no build step, no SDK. Runs via npx tsx, which downloads itself into the npm cache on first invocation and runs from cache on every subsequent call.

Demonstrates:

  • registering slash commands (/note, /notes, /clear-notes)
  • registering an LLM-callable tool (read_notes)
  • the wire protocol from a typed TypeScript perspective
  • running TypeScript via npx tsx from extension.json

Requirements

Node 18+ and tsx on $PATH:

npm install -g tsx

This is what extension.json invokes (exec: "tsx"). Without the global install, swap to "exec": "npx" + "args": ["--yes", "tsx", "index.ts"] — functional but adds ~1 second to each zot startup because npm checks the registry on every invocation.

Install

From this directory:

zot ext install .

Use

In zot:

  • /note remind me to update the changelog — appends to the scratchpad
  • /notes — shows everything stored
  • /clear-notes — wipes the scratchpad

The model also has a read_notes tool. Ask it:

"What did I tell you to remember?"

…and it will call the tool and tell you.

Storage

Notes persist as JSONL at <cwd>/.zot/scratchpad-notes.jsonl. The file is created on first /note and survives zot restarts. Each line is one note: {"at":"2026-04-19T13:00:00.000Z","text":"..."}.

Scope is per-project: switching to a different cwd gives you a different scratchpad. Cross-project sharing isn't supported in this example (would just be a matter of changing the path constant).

Why TypeScript here

The extension protocol is small enough that you can hand-write it in any language. JS works fine; TS adds type safety on the frame shapes without any infrastructure beyond tsx. If you want richer ergonomics (decorators, schema-from-types), publish your own SDK on top.

See also

  • examples/extensions/clock — JS sibling (no tsx required)
  • examples/extensions/hello — Go SDK
  • examples/extensions/weather — Go SDK, exposes one tool
  • examples/extensions/guard — Go SDK, demonstrates intercepts
  • docs/extensions.md — full protocol reference