@jeffober/thatch 0.1.42 → 0.1.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,144 @@
1
+ # Thatch Actions: Prompt Cores Shared by Nudges and /thatch Commands
2
+
3
+ ## Synopsis
4
+
5
+ Extract the behavior instructions currently embedded in nudge text into
6
+ prompt-core constants in `src/prompts.ts`, then build `/thatch/*` user-facing
7
+ commands on top of the same constants. The nudge and the command become two
8
+ envelopes around one instruction body: the nudge adds escalation tiers and
9
+ stop-and-wait framing, the command adds user-invocation framing. First
10
+ payoff is `/thatch/defrag`, but the structure covers any behavior the nudges
11
+ currently ask the agent to perform on demand.
12
+
13
+ ## Background
14
+
15
+ Nudges are instruction-carrying messages injected by hooks. Several encode a
16
+ multi-step behavior the agent must execute (dispatch a sub-agent, fetch the
17
+ extraction payload, run a skill, ack). The same behaviors have no user-facing
18
+ invocation path: the user cannot say "drain the extraction queue now" or
19
+ "consolidate duplicate memories now" -- they can only wait for a nudge or
20
+ describe the desired behavior in prose and hope the agent maps it to the right
21
+ skill + tool sequence.
22
+
23
+ Two existing pieces make this cheap to add:
24
+
25
+ - `src/commands.ts` already ships `/thatch/compact` and `/thatch/exit` as
26
+ markdown command files synced into the opencode config dir, and already
27
+ composes them from shared fragments (`sharedChecklist`,
28
+ `userMessageSection`).
29
+ - The "Shared prose sync across prompt variants" problem is documented:
30
+ prompt prose lives in parallel functions with no single source of truth,
31
+ and drift in unasserted sections passes tests. This plan makes the shared
32
+ behavior text a true constant.
33
+
34
+ ## Design: prompt cores and envelopes
35
+
36
+ A **prompt core** is a constant string in `src/prompts.ts` holding the
37
+ host-agnostic instruction body for one behavior: which tools to call, in what
38
+ order, with what arguments, and what "done" looks like.
39
+
40
+ An **envelope** wraps a core with delivery-specific framing:
41
+
42
+ - The nudge envelope adds: escalation tier wording, the load-bearing
43
+ stop-and-wait ending (see "Extraction nudge stop-and-wait wording is
44
+ load-bearing" -- the stop-and-wait text is nudge-only and must NOT leak
45
+ into action envelopes, because an action IS user input), and the
46
+ "system nudge, not user input" disclaimer.
47
+ - The action envelope adds: frontmatter description, the `# User Message`
48
+ section with `$ARGUMENTS`, and any greenlight-token mechanics (wrap-up
49
+ commands only).
50
+
51
+ Cores are plain string constants, not template functions, so both envelopes
52
+ interpolate them identically. Where a core needs host-specific tool names
53
+ (`thatch_memory_remember` vs `mcp__thatch__memory_remember`), the core takes
54
+ the opencode spelling and MCP consumers apply the documented token
55
+ substitution, matching the existing systemPrompt/mcpInstructions convention.
56
+
57
+ ## Actions v1
58
+
59
+ | Command | Core behavior | Existing machinery |
60
+ |---|---|---|
61
+ | `/thatch/defrag` | Run `thatch_find_duplicates`, classify each pair with the thatch-dedup-classifier skill, consolidate (remember/overwrite or forget), mark pairs checked | find_duplicates + dedup classifier skill |
62
+ | `/thatch/extract` | Fetch the extraction payload, run the fact-extractor skill, call `extraction_done` | get_extraction_payload + fact-extractor skill |
63
+ | `/thatch/hygiene` | Run the hygiene report, act on stale and orphaned branch-scoped memories | `hygieneReport()` + `/thatch hygiene` CLI |
64
+ | `/thatch/reflect` | Run the session-reflection skill over the current session | thatch-session-reflection skill |
65
+
66
+ The wrap-up commands (`compact`, `exit`) stay as-is; their checklist text
67
+ becomes a core reused by both templates (already true via `sharedChecklist`).
68
+
69
+ ## Host parity
70
+
71
+ Commands are markdown or MCP prompts, synced per host. Behavior parity is the
72
+ goal; format differences are documented, not hidden.
73
+
74
+ - **opencode** (existing): `installOpencodeCommands` syncs markdown to
75
+ `~/.config/opencode/command/thatch/` on every plugin load.
76
+ - **Claude Code**: native user-level slash commands read markdown from
77
+ `~/.claude/commands/thatch/` with the same `$ARGUMENTS` substitution.
78
+ `thatch setup --claude` gains a sync step (idempotent content-compare, same
79
+ as the opencode installer). Differences: no plugin, so no
80
+ `command.execute.before` arming -- greenlight-token wrap-up commands do not
81
+ ship to Claude Code; and tool names use the `mcp__thatch__` prefix.
82
+ - **Cursor**: no file-based commands. The stdio MCP server (`mcp.ts`) gains
83
+ MCP Prompts support (`prompts/list`, `prompts/get`), which Cursor surfaces
84
+ as slash commands. Prompt arguments use MCP's
85
+ `{{argument}}`-style templating, so each action core gets an MCP-prompt
86
+ rendering alongside the markdown rendering.
87
+
88
+ README gains "What works in Claude Code" and "What works in Cursor" sections
89
+ listing per-host support without restating the shared docs.
90
+
91
+ ## Session ID plumbing
92
+
93
+ `get_extraction_payload` and `extraction_done` take `session_id`. Today the
94
+ nudge carries the ID; an action has no way to know it.
95
+
96
+ - opencode path: the thin wrappers in `tools.ts` receive the invoking
97
+ session's ID from the host. `session_id` becomes optional there; omitted
98
+ means "the current session."
99
+ - MCP path: there is no session context in a tool call, so `session_id`
100
+ stays required. The tool description and docs state this plainly.
101
+
102
+ The rule the LLM must apply, stated everywhere the tools are described:
103
+
104
+ > Omit `session_id` when acting on the session you are running in. Pass the
105
+ > parent session's `session_id` when running inside a sub-agent that was
106
+ > dispatched to process another session's extraction queue.
107
+
108
+ This rule appears in: the tool descriptions in `tool-defs.ts`, the extraction
109
+ prompt core (used by both nudge and action envelopes), the fact-extractor
110
+ skill, and the dev docs. Tests cover both paths: omit-resolves-to-current and
111
+ explicit-parent-ID (the existing sub-agent drain bug's regression path).
112
+
113
+ ## Decisions
114
+
115
+ - Prompt cores live in `src/prompts.ts`, not a new module; `commands.ts`
116
+ imports them. One prompt module, consistent with the existing module map.
117
+ - Actions are generated, not hand-written: each action has one core and a
118
+ per-host renderer, so a wording change cannot drift between nudge and
119
+ command.
120
+ - No `--dry-run` flag for defrag in v1; the dedup classifier skill already
121
+ asks for pair-by-pair verdicts, which is the interactive safety net.
122
+ - MCP Prompts for Cursor are additive to `mcp.ts` and do not change the
123
+ tools/list contract.
124
+
125
+ ## Testing
126
+
127
+ - `tests/commands.test.ts` (or the existing plugin tests): command-file
128
+ content assertions per host, including that each action's markdown contains
129
+ its core text verbatim.
130
+ - MCP tests: `prompts/list` returns every action; `prompts/get` interpolates
131
+ arguments.
132
+ - Plugin tests: `get_extraction_payload` without `session_id` resolves to the
133
+ invoking session; with an explicit parent ID, drains the parent's queue.
134
+ - Parity guard: a test asserts every opencode command def has a
135
+ corresponding MCP prompt (and vice versa) except the documented exclusions
136
+ (wrap-up greenlight commands on non-opencode hosts).
137
+
138
+ ## Docs
139
+
140
+ - `docs/dev/commands.md` (two-tier: dev doc + user-facing README section):
141
+ action list, host parity matrix, session ID rule.
142
+ - README: "What works in Claude Code" / "What works in Cursor" sections.
143
+ - QA use cases: one auto use case for `/thatch/defrag` end-to-end, one for
144
+ `/thatch/extract` with omitted session ID.
@@ -190,8 +190,8 @@ requirements.
190
190
 
191
191
  | Tool | What it does |
192
192
  |------|-------------|
193
- | `thatch_chat_register` | Join the cross-session chat directory, so other sessions on this machine can message you. Display names are assigned by thatch, never chosen (a slug plus a never-reused counter), so a name always refers to the same session. Call with no arguments to join, rejoin after unregistering, or check your name. On hosts without session context (Claude Code, Cursor), pass the name your thatch hook printed as `as`. |
194
- | `thatch_chat_list` | List registered sessions with a liveness marker (fresh = its process is alive, stale = likely gone), each session's project and topic, and your unread count. |
193
+ | `thatch_chat_register` | Join the cross-session chat directory, so other sessions on this machine can message you. Display names are assigned by thatch, never chosen (a pool name plus a never-reused counter), so a name always refers to the same session. Call with no arguments to join, rejoin after unregistering, or check your name. On hosts without session context (Claude Code, Cursor), pass the name your thatch hook printed as `as`. |
194
+ | `thatch_chat_list` | List registered sessions grouped into Active and Stale sections (stale = two missed heartbeats, about a minute; its host process has probably stopped), with how long ago each last checked in, each session's project and checkout kind (project root or linked worktree), its topic, and your unread count. |
195
195
  | `thatch_chat_send` | Send a message to another registered session, by name or session id. The recipient is nudged when its session is idle. |
196
196
  | `thatch_chat_read` | Drain your inbox: all unread messages oldest-first, marked read. Senders identified by display name. |
197
197
  | `thatch_chat_unregister` | Leave the chat directory. |
@@ -232,6 +232,21 @@ Beyond the tools, thatch hooks into opencode itself:
232
232
  notification (`[thatch] recalled 3 memories`, `[thatch] 2 predictions
233
233
  surfaced`, or `[thatch] 1 behavior surfaced`). The toast is ephemeral. It
234
234
  fades after a few seconds.
235
+ - **Wrap-up commands.** `/thatch/compact` and `/thatch/exit` (opencode only)
236
+ run a pre-flight checklist before you compact or close a session: the agent
237
+ flushes pending fact extraction, finishes any promised memory writes, and
238
+ surfaces todos or follow-ups it never addressed. The agent ends its
239
+ response with a greenlight token only when the checklist is clean. Thatch
240
+ watches for the token and then runs the compaction or exits opencode.
241
+ Without the token nothing fires -- a toast points you at the items the
242
+ agent listed, and you re-run the command once they're handled. Text typed
243
+ after the command reaches the agent first, labeled as a `User Message`
244
+ section ahead of the checklist (say goodbye or hand off context:
245
+ `/thatch/exit Good work - see you tomorrow`).
246
+ A greenlit `/thatch/exit` also unregisters the session from the chat
247
+ directory, so other sessions stop sending it mail. The commands
248
+ self-install into `~/.config/opencode/command/thatch/` at plugin startup;
249
+ a first install becomes available after the next opencode start.
235
250
  - **Compaction context.** When opencode compacts a long session, thatch injects
236
251
  a reminder so the summarized session still knows memory tools exist.
237
252
  - **Prediction auto-fire.** When a prompt matches learned contexts, thatch
@@ -314,6 +329,7 @@ response, walkthrough, and workflow skills that support the review pipeline:
314
329
  | `thatch-pr-description` | Drafts PR descriptions with SYNOPSIS / PURPOSE / DESCRIPTION / WALK-THROUGH / NOTES, project-context research, clarity checks, and bold/italic emphasis for scanning. |
315
330
  | `thatch-ticket-description` | Drafts ticket or issue descriptions (Linear or Jira) with clear sections, project-context research, clarity checks, and bold/italic emphasis for scanning. |
316
331
  | `thatch-split-overlarge-pr` | Splits already-completed work from an overlarge PR into human-reviewable, release-safe PRs targeting main. |
332
+ | `thatch-clear-writing` | Prose rules for every human-facing text the dedicated writing skills do not cover: PR and ticket comments, documentation, plans, reports, and chat replies. Clarity over compression. |
317
333
 
318
334
  ### opencode-only skills
319
335
 
@@ -430,6 +446,7 @@ Most configuration needs none. Two layers exist:
430
446
  | `THATCH_DB_PATH` | `$XDG_CONFIG_HOME/thatch/thatch.db` | Override database location (the config file follows it) |
431
447
  | `THATCH_MODEL` | `Xenova/bge-small-en-v1.5` | Override embedding model |
432
448
  | `THATCH_EMBEDDING_BACKEND` | `wasm` | Set to `native` to run embeddings on onnxruntime-node (NAPI) instead of the wasm runtime |
449
+ | `THATCH_DEBUG` | unset (off) | Diagnostic logging to `debug.log` beside the database. `1` logs everything; or a comma-separated list of tags, e.g. `chat` or `chat:startup` |
433
450
 
434
451
  Unchanged defaults: the database is created automatically, the embedding
435
452
  model downloads once and is cached, the store name is auto-detected from
package/docs/user/cli.md CHANGED
@@ -46,7 +46,7 @@ Read-only access to the chat directory your opencode sessions share
46
46
 
47
47
  ```bash
48
48
  thatch chat list # who is registered: name, age, project, topic
49
- thatch chat tail # follow sent and read events, live
49
+ thatch chat tail # follow sent and read events, live (JSONL)
50
50
  thatch chat tail --once # print the last 20 messages and exit
51
51
  thatch chat tail --once --limit 50 # a longer backlog (or --limit all)
52
52
  thatch chat tail --match "rebase" --match "payments" # body must match both
@@ -54,41 +54,41 @@ thatch chat tail --from al --to bob # substring match on names
54
54
  thatch chat tail --since 2026-09-12 --until "2026-09-13 09:00" # a window
55
55
  ```
56
56
 
57
- `chat list` shows every registered session with how long since its last
58
- heartbeat (a large age means the session's process is probably gone), its
59
- project, and the topic it registered with - the fastest way to answer
60
- "which session should I talk to about X?"
61
-
62
- `chat tail` prints the conversation as styled chat cards (labels on a
63
- colored background, names in color, timestamps dimmed; a drawn rule
64
- separates cards, with blank lines on either side). After each name, the
65
- session's registered topic appears in muted italics - so the tail tells
66
- you not just who is talking but what they are working on:
57
+ `chat list` shows every registered session in two sections, Active and
58
+ Stale, each as aligned columns under a header row: how long since its
59
+ last heartbeat, its status (`fresh` or `stale` for opencode sessions;
60
+ `active` or `idle` for Claude Code and Cursor sessions, which only beat
61
+ when a prompt runs), its project, and its topic (the session's title) -
62
+ the fastest way to answer "which session should I talk to about X?" A
63
+ stale session has missed two heartbeats, about a minute: the opencode
64
+ process hosting it has probably stopped. Color is added only when the
65
+ output is a terminal; a pipe prints plain aligned text.
66
+
67
+ `chat tail` prints the conversation as a JSONL event log: one JSON
68
+ object per line, one event per line. Sending a message and reading it
69
+ are separate events, linked by the message `id`. Every field is plain
70
+ data: names as registered, each participant's topic, the message body
71
+ exactly as sent, and ISO-8601 UTC timestamps. No color, no markdown
72
+ rendering, no local time; pipe through `jq` for either.
67
73
 
68
74
  ```text
69
- From Al Go Rithm <cross-session messaging between opencode sessions>
70
- To Brute the Dream Farrier <diagnosing watcher underuse>
71
- When 2026-09-12 14:02 America/Denver
72
-
73
- CI is green on main
74
- ____________________________________________________________
75
-
76
- To broadcast
77
- When 2026-09-12 21:07 America/Denver
78
-
79
- rebasing payments, hold off
80
- ____________________________________________________________
75
+ {"event":"sent","at":"2026-09-12T20:02:11Z","id":41,"from":"al-go-rithm-00001","from_topic":"cross-session messaging","to":"brute-the-dream-farrier-00001","to_topic":"diagnosing watcher underuse","broadcast":false,"body":"CI is green on main"}
76
+ {"event":"read","at":"2026-09-12T20:02:40Z","id":41,"reader":"brute-the-dream-farrier-00001","reader_topic":"diagnosing watcher underuse","from":"al-go-rithm-00001","from_topic":"cross-session messaging"}
77
+ {"event":"sent","at":"2026-09-13T03:07:02Z","id":42,"from":"al-go-rithm-00001","from_topic":"cross-session messaging","to":"kurn-the-typechecker-00001","to_topic":"release QA","broadcast":true,"body":"rebasing payments, hold off"}
78
+ ```
81
79
 
82
- From Kurn the Typechecker <release QA>
83
- read Marlowe the Cherry Picker <payments refactor>
84
- When 2026-09-12 21:08 America/Denver
80
+ A broadcast is one `sent` event per recipient, each with `broadcast:
81
+ true` and its real `to`, so every copy tracks its own read. Handy
82
+ one-liners:
85
83
 
86
- direct ping
84
+ ```bash
85
+ thatch chat tail | jq -r '"\(.at) \(.event) \(.from) -> \(.to // .reader): \(.body // "")"'
86
+ thatch chat tail --once --limit all | jq -c 'select(.event == "read")'
87
87
  ```
88
88
 
89
- Follow mode runs until Ctrl-C. Read events appear only in follow mode
90
- (they fire when an inbox is drained after the tail started). When
91
- timestamps are in your local timezone. The chat itself flows through the
89
+ Follow mode runs until Ctrl-C. The backlog includes the `read` event of
90
+ every message already read; in follow mode, reads appear as inboxes
91
+ drain. The chat itself flows through the
92
92
  agents (the CLI never sends, reads, or registers on a session's behalf;
93
93
  that happens from opencode sessions via the `thatch_chat_*` tools).
94
94
 
@@ -102,10 +102,8 @@ too, so a filtered tail keeps watching the same way:
102
102
  together: every one must match the message body.
103
103
  - `--from NAME` and `--to NAME` match participant names (case doesn't
104
104
  matter). A departed sender can only be found as the `unknown`
105
- rendering the tail shows. Broadcast cards say `broadcast` in the To
106
- slot, but the row underneath keeps the real recipient: `--to <name>`
107
- finds the fan-out rows that reached them, while `--to broadcast`
108
- matches nothing.
105
+ rendering the tail shows. Broadcast events carry their real recipient,
106
+ so `--to <name>` finds the fan-out copies that reached them.
109
107
  - `--since DT` and `--until DT` bound the window; a message counts if
110
108
  it was sent at or after `--since` and before `--until`. The date
111
109
  format is `YYYY-MM-DD` with an optional `HH:MM` in your local
@@ -113,9 +111,9 @@ too, so a filtered tail keeps watching the same way:
113
111
 
114
112
  A `--until` already in the past exits after the backlog (a closed
115
113
  window has nothing left to follow); one in the future follows until
116
- the window closes. Note that the limit hides sent cards, not their
117
- reads: a hidden message that gets read during follow mode still emits
118
- its read card.
114
+ the window closes. In the backlog, a hidden message's read is hidden
115
+ with it; in follow mode, a hidden message that gets read still emits
116
+ its read event.
119
117
 
120
118
  ## Priming a new project
121
119
 
@@ -1,6 +1,7 @@
1
1
  # Cross-Session Chat
2
2
 
3
- Cross-session chat lets your opencode sessions talk to each other. If one
3
+ Cross-session chat lets your agent sessions talk to each other, in
4
+ opencode, Claude Code, and Cursor. If one
4
5
  session is QAing a release and another is planning a feature, the second can
5
6
  ask the first "is the release green yet?" instead of you relaying messages
6
7
  between tabs all afternoon.
@@ -8,9 +9,9 @@ between tabs all afternoon.
8
9
  ## What it does
9
10
 
10
11
  opencode sessions join the directory automatically, on their first idle
11
- moment. Names are assigned by thatch, never chosen: a lowercase slug of the
12
- session's title plus a counter (a session titled "Fix auth bug" becomes
13
- `fix-auth-bug-00001`). The counter only ever increments, so a name is
12
+ moment. Names are assigned by thatch, never chosen: a name drawn from a
13
+ built-in pool plus a counter (`al-go-rithm-00001`). The counter only ever
14
+ increments, so a name is
14
15
  minted exactly once per machine - pruning an old session never reissues its
15
16
  name to someone else, and the same name always refers to the same session.
16
17
  The live title rides along as the session's topic (refreshed as the
@@ -19,11 +20,14 @@ board without anyone filling in forms. A session can also join or rejoin
19
20
  explicitly with `thatch_chat_register` (no arguments) - useful after
20
21
  `chat_unregister`, or just to check your assigned name. Once registered:
21
22
 
22
- - `thatch_chat_list` shows every registered session on the machine, with a
23
- liveness marker (fresh or stale), its project, its topic, and your unread
24
- count
23
+ - `thatch_chat_list` shows every registered session on the machine, grouped
24
+ into Active and Stale sections: active sessions can be woken; stale ones
25
+ have missed two heartbeats, about a minute (the opencode process hosting
26
+ them has probably stopped). Each row carries how long ago the session last
27
+ checked in, its project, whether it runs in the project root or a linked
28
+ git worktree, its topic, and your unread count
25
29
  - `thatch_chat_send` delivers a message to another registered session, by
26
- name or session id
30
+ name or session id, and states the recipient's liveness at send time
27
31
  - `thatch_chat_read` drains the session's inbox
28
32
  - `thatch_chat_broadcast` delivers one message to every other live
29
33
  registered session at once
@@ -55,8 +59,12 @@ toggle reveals those output blocks if you want them.)
55
59
 
56
60
  ## How to use it
57
61
 
58
- With auto-registration you usually do nothing: both sessions are already
59
- in the directory. To introduce them, just tell each session who to talk to:
62
+ With auto-registration you usually do nothing: a session joins the
63
+ directory when it first goes idle, and a session continued with
64
+ `opencode -s <id>` is registered again the moment its harness starts -
65
+ same session id, same name, reclaimed. The agent gets a quiet toast with
66
+ its assigned name when it first registers. To introduce two sessions,
67
+ just tell each one who to talk to:
60
68
 
61
69
  > Ask the other session whether the release has shipped; answer its
62
70
  > questions directly.
@@ -71,13 +79,68 @@ doing. When in doubt it summarizes the mail for you and waits. If you want
71
79
  two sessions to actively cooperate on something, say so explicitly in both
72
80
  sessions.
73
81
 
82
+ ## Claude Code and Cursor
83
+
84
+ Chat works from Claude Code and Cursor through the same MCP server and the
85
+ same shared directory. The seven tools are identical on every host; two
86
+ things differ.
87
+
88
+ **Identity comes from the hook.** Claude Code and Cursor pass no session
89
+ context to MCP tool calls, so the thatch hook anchors identity instead. It
90
+ registers the conversation under a stable id derived from the host's
91
+ session id, and prints `you are NAME (unread count)` at session start and
92
+ on every prompt. The model passes that name as the `as` argument on the
93
+ chat tools. Without the hook (MCP registered by hand, hooks removed), the
94
+ model can still join: `chat_register` with no arguments mints a fresh
95
+ identity for the conversation, and the model uses the returned name from
96
+ there. That identity does not survive a compacted context - re-register
97
+ then, or prefer the hooked path.
98
+
99
+ **Delivery model.** Only opencode can start a turn when mail arrives
100
+ while you are away. The other hosts surface mail at their hook points,
101
+ and both wake the agent when a turn ends:
102
+
103
+ - **Cursor** checks the mailbox when a turn ends (the `stop` hook): unread
104
+ mail is auto-submitted as a follow-up message, so the agent reads it
105
+ without you typing anything. The notification is a pointer (sender
106
+ names + count, never message bodies); bodies flow only through the
107
+ framed `chat_read`. A loop cap bounds consecutive follow-ups, and an
108
+ aborted or errored turn is never auto-continued.
109
+ - **Claude Code** also checks at turn end (the `Stop` hook): unread mail
110
+ arrives as a Stop-hook reminder and the turn continues so the agent
111
+ reads it. The host's own loop protections plus the delivered stamp
112
+ bound repeats, and a session paused on background work is not
113
+ interrupted - the wake lands when that work's turn ends. Mail is also
114
+ announced at startup and resume (the `SessionStart` hook line) and at
115
+ every prompt; if an answer is urgent, say so to the agent directly.
116
+
117
+ Two limits worth knowing:
118
+
119
+ - Cursor cloud agents run no client-side hooks: no identity anchor, no
120
+ mail lines. The MCP tools still work, with a self-registered identity.
121
+ - A conversation idle past the prune window (a week) re-registers under a
122
+ fresh name; mail addressed to the old name is swept.
123
+
124
+ The terminal view ([cli.md](cli.md)) works the same regardless of which
125
+ host the sessions run in.
126
+
74
127
  ## Liveness
75
128
 
76
- A session shows as fresh while its opencode process is running. A crashed
77
- or closed process stops heartbeat-ing, and the session shows as stale in
78
- `thatch_chat_list` after ten minutes. Messages to a stale session wait in
79
- its inbox unread - a dead session never reads them. Explicitly closing a
80
- session (deleting it in the TUI) unregisters it immediately.
129
+ A session shows as fresh while the opencode process hosting it is
130
+ running: hosted sessions keep beating (idle ones included), so the
131
+ freshness is real. When that process dies, its sessions stop beating and
132
+ show as stale about a minute later (two missed heartbeats), grouped into
133
+ a separate Stale section. A laptop that slept reads the same way until
134
+ its processes catch up.
135
+ Messages to a stale session wait in its inbox unread - a dead session
136
+ never reads them, and `chat_send` says so at send time. Continuing a
137
+ session with `opencode -s <id>` reclaims its name and row, and any mail
138
+ that queued while it was down is delivered at startup. Explicitly
139
+ closing a session (deleting it in the TUI) unregisters it immediately,
140
+ and a greenlit `/thatch/exit` unregisters the session too: the wrap-up
141
+ checklist calls `chat_unregister`, and the plugin removes the row itself
142
+ when the exit token passes the greenlight check, so other sessions stop
143
+ addressing mail to a process that is about to vanish.
81
144
 
82
145
  ## Turning chat off
83
146
 
@@ -127,16 +190,26 @@ construction. Three mitigations:
127
190
  - **Names are assigned, not claimed.** Display names are minted by thatch
128
191
  with a never-reused counter, so a name cannot be grabbed by an unrelated
129
192
  session and an old name cannot be resurrected by an impersonator.
193
+ - **Claude Code identity is anchored by the host process.** Hooks learn
194
+ the true session id from the host and record which process spawned them;
195
+ the MCP server resolves its own parent process against that record, so
196
+ the model cannot claim another session's identity there. On Cursor, chat
197
+ tools still trust the `as` argument the caller supplies (hooks and MCP
198
+ servers share one workspace process, so process identity is ambiguous) -
199
+ a local session that knows a name can act as it. opencode is immune (the
200
+ host supplies identity). The threat model is one user's machine.
130
201
  - **No external content via wake.** The wake notification names senders
131
202
  and counts only - bodies flow exclusively through the framed
132
203
  `chat_read` surface.
133
204
 
134
205
  ## Requirements and limitations
135
206
 
136
- - **Wake-up delivery is opencode only.** The chat tools work everywhere
137
- (other hosts declare their identity with `as`), but only opencode can
138
- start a turn when a message arrives; Claude Code and Cursor see pending
139
- mail at their next prompt (the flush-tools hook line, or `chat_status`).
207
+ - **Idle wake (starting a turn with nobody at the keyboard) is opencode
208
+ only.** The chat tools work everywhere (other hosts declare their
209
+ identity with `as`). Cursor and Claude Code additionally wake the agent
210
+ when a turn ends with mail unread (the `stop`/`Stop` hooks); Claude
211
+ Code also announces mail at startup and resume, and both see pending
212
+ mail at prompt time (the flush-tools hook line, or `chat_status`).
140
213
  - **Same machine only.** The directory and inbox live in thatch's local
141
214
  database. There is no network relay.
142
215
  - **Opt-in.** Unregistered sessions cannot be messaged and cannot send.
@@ -68,6 +68,7 @@ Skills are split into shared (all hosts) and opencode-only:
68
68
  | `thatch-pr-description` | Drafts PR descriptions with SYNOPSIS / PURPOSE / DESCRIPTION / WALK-THROUGH / NOTES, using bold and italic emphasis for scanning. |
69
69
  | `thatch-ticket-description` | Drafts ticket or issue descriptions (Linear or Jira) with clear sections and bold/italic emphasis for scanning. |
70
70
  | `thatch-split-overlarge-pr` | Splits already-completed work from an overlarge PR into human-reviewable, release-safe PRs targeting main. |
71
+ | `thatch-clear-writing` | Prose rules for every human-facing text the dedicated writing skills do not cover: PR and ticket comments, documentation, plans, reports, and chat replies. Clarity over compression. |
71
72
 
72
73
  ### Workflow skills
73
74
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jeffober/thatch",
3
- "version": "0.1.42",
3
+ "version": "0.1.44",
4
4
  "description": "Persistent memory for AI coding agents — local embeddings, SQLite stores, zero config. Works with OpenCode (as a plugin), Claude Code (as an MCP server), and Cursor (as an MCP server).",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
package/src/chat-names.ts CHANGED
@@ -9,8 +9,8 @@
9
9
  * unnamed-cast extras). fnord generates its names with an LLM at runtime;
10
10
  * thatch bakes the pool in - static contents, no model call.
11
11
  *
12
- * The pool is the fallback base for registrations with no usable session
13
- * title (ChatStore.register slugifies a random pool name). Pool names are
12
+ * The pool is the base for every registration (ChatStore.register
13
+ * slugifies a random pool name and appends a counter). Pool names are
14
14
  * case-insensitively distinct from each other; slugify is lossy, but a
15
15
  * shared base is harmless - the per-base counter still yields unique
16
16
  * names.