@jeffober/thatch 0.2.2 → 0.2.3
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.
- package/bin/thatch +9 -5
- package/docs/dev/README.md +21 -25
- package/docs/dev/features/cli.md +1 -0
- package/docs/dev/features/extraction.md +120 -81
- package/docs/dev/features/nudge-pipeline.md +44 -39
- package/docs/dev/features/session-lifecycle.md +34 -20
- package/docs/dev/features/watchers.md +9 -0
- package/docs/dev/gotchas.md +20 -26
- package/docs/dev/mcp-parity.md +16 -17
- package/docs/dev/setup-and-hooks.md +1 -1
- package/docs/user/watchers.md +6 -0
- package/package.json +1 -1
- package/src/chat.ts +1 -1
- package/src/extract-queue.ts +16 -1
- package/src/extraction.ts +4 -3
- package/src/opencode/v2.ts +4 -3
- package/src/prompts.ts +12 -33
- package/src/runtime.ts +110 -107
- package/src/tool-defs.ts +39 -31
- package/src/watchers.ts +31 -0
|
@@ -27,7 +27,10 @@ Subscribes to all session bus events. Dispatches based on `event.type`.
|
|
|
27
27
|
2. Snapshot the parent's current pending buffer: `parentSnapshots.set(childID, [...extraction.peek(parentID)])`
|
|
28
28
|
3. Return early -- child sessions don't get the session-start reminder
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
The snapshot is journal-recovery data only (restored child bookkeeping
|
|
31
|
+
after a reload); live delivery is claim-based: the child's payload fetch
|
|
32
|
+
records exactly which entries it received, and its completion signal
|
|
33
|
+
consumes only those.
|
|
31
34
|
|
|
32
35
|
### session.created without parentID (top-level session)
|
|
33
36
|
|
|
@@ -39,20 +42,22 @@ This snapshot is used by `consumeSnapshot` for snapshot-aware drain: when the ch
|
|
|
39
42
|
|
|
40
43
|
When a child created by `triggerExtraction` goes idle:
|
|
41
44
|
|
|
42
|
-
1.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
1. `completeClaimed(childID)` -- consume only the entries this child
|
|
46
|
+
claimed via its payload fetch. A no-claim idle is a no-op: a child that
|
|
47
|
+
never fetched processed nothing, and its idle signal must not drop
|
|
48
|
+
entries another extractor holds. Held entries with no completer are
|
|
49
|
+
bounded by the 15-minute stale reaper
|
|
50
|
+
2. Fire a toast with extraction metrics (new/updated/deleted counts) -- only if memories were actually written
|
|
51
|
+
3. Clean up all maps: `extracting`, `childToParent`, `parentSnapshots`, `childMetrics`, `extractionChildren`
|
|
52
|
+
4. `consume(childID)` -- drain child's own buffer
|
|
53
|
+
5. Delete the child session via `client.session.delete`
|
|
49
54
|
|
|
50
55
|
### session.status idle -- task-dispatched sub-agent
|
|
51
56
|
|
|
52
57
|
When a task-dispatched sub-agent (not created by `triggerExtraction`) goes idle:
|
|
53
58
|
|
|
54
|
-
- `
|
|
55
|
-
-
|
|
59
|
+
- `completeClaimed(childID)` -- complete only what THIS child claimed via
|
|
60
|
+
its payload fetch (a no-claim idle consumes nothing)
|
|
56
61
|
- Does NOT drain the buffer or delete the session -- the task tool that dispatched the sub-agent needs to read its output
|
|
57
62
|
|
|
58
63
|
### session.status idle -- parent session
|
|
@@ -60,8 +65,9 @@ When a task-dispatched sub-agent (not created by `triggerExtraction`) goes idle:
|
|
|
60
65
|
When a parent session (no parentID) goes idle:
|
|
61
66
|
|
|
62
67
|
- Wrap-up resolution first (below): a pending `/thatch/compact` or `/thatch/exit` resolves here, and a greenlit action returns early
|
|
68
|
+
- `requeueStaleAccepted()` first: accepted entries whose completion signal never came (15 min) return to pending
|
|
63
69
|
- If not compacting, not already extracting, and buffer has pending interactions: `triggerExtraction(sessionID)`
|
|
64
|
-
- On failure: log error, clear `extracting` flag (
|
|
70
|
+
- On failure: log error, clear `extracting` flag (the next idle retries -- there is no model-facing nudge fallback)
|
|
65
71
|
|
|
66
72
|
### Wrap-up commands (`/thatch/compact`, `/thatch/exit`)
|
|
67
73
|
|
|
@@ -84,12 +90,21 @@ first-ever install is invisible until the next server start.
|
|
|
84
90
|
|
|
85
91
|
### session.error (child session)
|
|
86
92
|
|
|
87
|
-
- `
|
|
93
|
+
- `requeueClaimed(childID)` if it fetched (the delivery was never
|
|
94
|
+
processed), else `requeueAccepted(parentID)` -- the error is a terminal
|
|
95
|
+
death signal, so a claim-less child falls back to whole-set requeue for
|
|
96
|
+
immediate recovery
|
|
97
|
+
- Clear `extracting` for the parent (the next idle re-triggers)
|
|
88
98
|
- Clean up all maps for the child
|
|
89
99
|
|
|
90
100
|
### session.deleted -- child
|
|
91
101
|
|
|
92
|
-
- `
|
|
102
|
+
- Extraction child: `requeueClaimed(childID)`, else
|
|
103
|
+
`requeueAccepted(parentID)` (never processed)
|
|
104
|
+
- Task-kind child: `requeueClaimed(childID)` only -- task children are
|
|
105
|
+
deleted ROUTINELY, so a claim-less task child's deletion must not requeue
|
|
106
|
+
the whole accepted set (it would yank an in-flight extractor's payload
|
|
107
|
+
back to pending for duplicate extraction)
|
|
93
108
|
- Clean up all maps for the child
|
|
94
109
|
|
|
95
110
|
### session.deleted -- parent
|
|
@@ -106,21 +121,20 @@ first-ever install is invisible until the next server start.
|
|
|
106
121
|
### Internal state maps
|
|
107
122
|
|
|
108
123
|
- **childToParent**: `Map<childID, parentID>` -- maps child sessions to their parents
|
|
109
|
-
- **parentSnapshots**: `Map<childID, Interaction[]>` -- snapshot of parent's buffer at child creation time
|
|
124
|
+
- **parentSnapshots**: `Map<childID, Interaction[]>` -- snapshot of parent's buffer at child creation time (journal recovery only; live delivery is claim-based)
|
|
110
125
|
- **childMetrics**: `Map<childID, {new, updated, deleted}>` -- extraction metrics per child
|
|
111
|
-
- **extracting**: `Set<parentID>` -- parent IDs with an active direct-extraction child (
|
|
126
|
+
- **extracting**: `Set<parentID>` -- parent IDs with an active direct-extraction child (gates re-triggering)
|
|
112
127
|
- **extractionChildren**: `Set<childID>` -- distinguishes extraction children from task-dispatched sub-agents
|
|
113
128
|
- **compacting**: `Set<sessionID>` -- sessions currently being compacted (suppresses nudges)
|
|
114
129
|
- **pendingWrapUp**: `Map<sessionID, {token, kind}>` -- wrap-up commands awaiting their greenlight check; armed by `command.execute.before`, resolved on the next idle, cleared on session deletion
|
|
115
|
-
- **missedNudges**: `Map<sessionID, number>` -- extraction nudge escalation counter
|
|
116
130
|
|
|
117
131
|
## Interactions with other features
|
|
118
132
|
|
|
119
133
|
- Extraction pipeline ([extraction.md](extraction.md)): direct extraction is triggered by `session.status idle`; child lifecycle managed here
|
|
120
|
-
- Nudge pipeline ([nudge-pipeline.md](nudge-pipeline.md)): `
|
|
134
|
+
- Nudge pipeline ([nudge-pipeline.md](nudge-pipeline.md)): `compacting` set suppresses all nudges; task-dispatched sub-agents (in `childToParent`, not in `extractionChildren`) suppress all tiers
|
|
121
135
|
- Hygiene ([hygiene.md](hygiene.md)): hygiene report runs at `session.created` for top-level sessions
|
|
122
136
|
- Compaction recovery ([compaction-recovery.md](compaction-recovery.md)): `session.compacted` event clears the compacting flag
|
|
123
|
-
- Memory store ([memory-store.md](memory-store.md)): child sessions write memories via `memory_remember`, which
|
|
137
|
+
- Memory store ([memory-store.md](memory-store.md)): child sessions write memories via `memory_remember`, which completes their claimed delivery via `tool.execute.after`
|
|
124
138
|
|
|
125
139
|
## Source files
|
|
126
140
|
|
|
@@ -130,7 +144,7 @@ first-ever install is invisible until the next server start.
|
|
|
130
144
|
## Key invariants
|
|
131
145
|
|
|
132
146
|
- Child sessions don't get the session-start reminder (early return in `session.created` with parentID).
|
|
133
|
-
-
|
|
147
|
+
- Delivery is claim-based: the payload fetch records what the fetcher received; only the fetcher's completion consumes it. A no-claim completion is a no-op, never a whole-set drop.
|
|
134
148
|
- Extraction children are deleted after going idle; task-dispatched sub-agents are NOT deleted (task tool reads output).
|
|
135
|
-
- Child errors requeue the
|
|
149
|
+
- Child errors requeue what the child held (never processed). Child deletion also requeues.
|
|
136
150
|
- Parent deletion completes accepted entries (takes them with it).
|
|
@@ -73,6 +73,15 @@ gh setup fails registration with a real error instead of producing a
|
|
|
73
73
|
watcher that never fires. Watch creation is also gated on a cached
|
|
74
74
|
`gh --version` availability check.
|
|
75
75
|
|
|
76
|
+
CI events (`pr_ci`, `branch_ci`) fire only on a running -> completed
|
|
77
|
+
check-run transition, so a watcher registered after a fast pipeline has
|
|
78
|
+
already finished holds completed runs in its baseline and can never
|
|
79
|
+
notify for that head. When every check run on the head is already
|
|
80
|
+
completed at registration, the tool response says so, with the
|
|
81
|
+
conclusion breakdown (`describeBaselineCheckRuns`), so the caller reads
|
|
82
|
+
the result instead of waiting on a notification that cannot come. The
|
|
83
|
+
rule for catching a push's CI: register the watcher before pushing.
|
|
84
|
+
|
|
76
85
|
### Polling
|
|
77
86
|
|
|
78
87
|
A `setInterval` loop (unref'd - it never keeps the process alive)
|
package/docs/dev/gotchas.md
CHANGED
|
@@ -67,32 +67,26 @@ here first. These are the things that have already cost time.
|
|
|
67
67
|
- **Hook failures are logged with a `[thatch]` prefix and never swallowed.** Two
|
|
68
68
|
hooks were dead for weeks before failures were made visible. If you add a
|
|
69
69
|
hook, log on failure.
|
|
70
|
-
-
|
|
71
|
-
|
|
72
|
-
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
Without this, either path would write memories in the child but never
|
|
91
|
-
clear the parent's queue — the nudge would replay every turn.
|
|
92
|
-
`thatch_extraction_done` is the belt-and-suspenders explicit
|
|
93
|
-
acknowledgment: it drains the buffer without requiring a memory write
|
|
94
|
-
(covers cases where the sub-agent errors out or the host doesn't expose
|
|
95
|
-
parent-child session relationships).
|
|
70
|
+
- **There is no model-facing extraction nudge on opencode.** The old
|
|
71
|
+
`chat.message` extraction nudge (and its `missedNudges` escalation) drove
|
|
72
|
+
a model-driven handshake that raced its own state machine: parent acks
|
|
73
|
+
landed before the child's payload fetch, no-claim completions wiped
|
|
74
|
+
in-flight accepted sets, and mis-targeted session ids made every
|
|
75
|
+
transition a silent no-op - so the same buffered count re-fired forever
|
|
76
|
+
(the September 2026 dispatch-loop report). Extraction is now plugin-driven
|
|
77
|
+
end-to-end: `triggerExtraction` at session idle creates the child and
|
|
78
|
+
interpolates the session ID itself; the child's payload fetch records the
|
|
79
|
+
claim; completions are claim-scoped; the 15-minute stale reaper bounds
|
|
80
|
+
crashed extractors. The nudge survives on MCP hosts only, where no plugin
|
|
81
|
+
can create sessions and the file-backed queue is durable until the
|
|
82
|
+
extractor completes.
|
|
83
|
+
- **A child's `thatch_memory_remember` completes only its claimed delivery**
|
|
84
|
+
via the `childToParent` Map and the claim recorded by its payload fetch.
|
|
85
|
+
A child that never fetched has no claim, and its memory write (or idle
|
|
86
|
+
signal, or ack) consumes nothing - the entries stay held/pending for the
|
|
87
|
+
real extractor. `thatch_extraction_done` is the explicit no-save
|
|
88
|
+
completion: claim-scoped like everything else, so a mis-ordered or
|
|
89
|
+
mis-targeted ack can never drop another extractor's in-flight delivery.
|
|
96
90
|
- **The no-save drain runs in the child-idle handler regardless of writes.**
|
|
97
91
|
When the extraction child goes idle after a no-save run (nothing worth
|
|
98
92
|
extracting), the parent's snapshot entries must still be drained from the
|
package/docs/dev/mcp-parity.md
CHANGED
|
@@ -78,28 +78,27 @@ and the nudge (fallback):
|
|
|
78
78
|
2. When the parent session goes idle (`session.status` idle event) with pending
|
|
79
79
|
buffer entries, the plugin calls `triggerExtraction`: creates a child session
|
|
80
80
|
via `client.session.create` (with `parentID`), then prompts it via
|
|
81
|
-
`client.session.promptAsync` (or `prompt`) with the extraction
|
|
82
|
-
|
|
81
|
+
`client.session.promptAsync` (or `prompt`) with the extraction prompt (the
|
|
82
|
+
parent's session ID is interpolated into the prompt by the plugin). The
|
|
83
|
+
`extracting` set gates re-triggering while the child runs.
|
|
83
84
|
3. The child session runs the `thatch-fact-extractor` skill, writes memories via
|
|
84
|
-
`thatch_memory_remember`.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
4. When the child goes idle, the handler
|
|
88
|
-
|
|
85
|
+
`thatch_memory_remember`. The child's payload fetch records its claim; its
|
|
86
|
+
memory write (or `extraction_done`) completes that claim - consuming only
|
|
87
|
+
the entries it received.
|
|
88
|
+
4. When the child goes idle, the handler finalizes the claim-scoped
|
|
89
|
+
completion, deletes the child session, and fires a toast via
|
|
89
90
|
`client.tui.showToast`.
|
|
90
91
|
|
|
91
|
-
**
|
|
92
|
+
**Failure recovery (no model-facing nudge exists on opencode):**
|
|
92
93
|
|
|
93
94
|
1. If `triggerExtraction` throws (session creation or prompt fails), the catch
|
|
94
|
-
block clears the `extracting` flag.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
(or a child sub-agent via the `childToParent` Map) or `thatch_extraction_done`
|
|
102
|
-
drains the buffer and resets the missed-nudge counter.
|
|
95
|
+
block clears the `extracting` flag. The pending buffer is untouched, and
|
|
96
|
+
the next idle re-triggers extraction - the plugin retries without any
|
|
97
|
+
model cooperation.
|
|
98
|
+
2. If the child errors or is deleted before completing, what it held is
|
|
99
|
+
requeued to pending. If its completion signal never comes at all, the
|
|
100
|
+
15-minute stale reaper returns accepted entries to pending. Either way
|
|
101
|
+
the next idle re-extracts - no interaction is silently lost.
|
|
103
102
|
|
|
104
103
|
Claude Code and Cursor use a **file-backed** queue (`src/extract-queue.ts`)
|
|
105
104
|
because hooks fire one-shot with no cross-call state:
|
|
@@ -25,7 +25,7 @@ code (`src/opencode/v1.ts`):
|
|
|
25
25
|
| `experimental.session.compacting` | `{ sessionID }` | `{ context: string[] }` | Marks the session as compacting, pushes re-familiarization context. |
|
|
26
26
|
| `experimental.compaction.autocontinue` | `{ sessionID }` | `{ enabled: boolean }` | Clears the compacting flag so `chat.message` nudges resume post-compaction. |
|
|
27
27
|
| `tool.execute.after` | `{ tool, sessionID, callID, args }` | `{ title, output, metadata }` | Buffers non-`thatch_`, non-`skill`, non-`task` tool calls into the in-memory extraction ring buffer (max 20). In child sessions, also tracks new/updated/deleted counts via `childMetrics` for the extraction toast. |
|
|
28
|
-
| `chat.message` | `{ sessionID, messageID }` | `{ message, parts }` |
|
|
28
|
+
| `chat.message` | `{ sessionID, messageID }` | `{ message, parts }` | Prompt-aware recall nudge (plus prediction/behavior auto-fire). No extraction nudge - extraction is plugin-driven at session idle. Suppressed while compacting or for task-dispatched sub-agent sessions (children that are not extraction children). |
|
|
29
29
|
| `event` | `{ event: { type, properties } }` | — | Dispatches on `event.type`: `session.created` (top-level) → `client.session.prompt` with reminder + hygiene heartbeat; `session.created` (child with `parentID`) → records `childToParent` + snapshots parent's pending buffer. `session.status` idle (parent, pending interactions) → `triggerExtraction` (direct child-session extraction); idle (child) → complete/drain, `showToast` with metrics, delete child. `session.error` (child) → requeue parent's accepted entries. `session.deleted` → requeue if child, drop accepted if parent, clean maps. `session.compacted` → clear compacting flag. |
|
|
30
30
|
| `dispose` | — | — | Closes the DB. |
|
|
31
31
|
|
package/docs/user/watchers.md
CHANGED
|
@@ -16,6 +16,12 @@ baseline, then polls the GitHub API through the `gh` CLI once a
|
|
|
16
16
|
minute. When the target changes in a way the watcher cares about, the
|
|
17
17
|
plugin prompts the agent with a notification.
|
|
18
18
|
|
|
19
|
+
Register before you push. CI notifications fire when a check run goes
|
|
20
|
+
from running to completed, so a watcher created after a fast pipeline
|
|
21
|
+
has already finished will never fire for that commit. If every check on
|
|
22
|
+
the head is already done when the watcher is created, the response says
|
|
23
|
+
so and reports the results directly.
|
|
24
|
+
|
|
19
25
|
PR watched events:
|
|
20
26
|
|
|
21
27
|
- `pr_comment` - new top-level comments on the PR
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jeffober/thatch",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
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.ts
CHANGED
|
@@ -212,7 +212,7 @@ export type ChatHostKind = "opencode" | "mcp";
|
|
|
212
212
|
// Display names appear inside wake prompts and chat_list output, so they are
|
|
213
213
|
// capped tight. Bodies are capped so a runaway sender cannot turn a nudge
|
|
214
214
|
// into a context bomb; the reader fetches full content via chat_read anyway.
|
|
215
|
-
const MAX_BODY_LEN = 10_000;
|
|
215
|
+
export const MAX_BODY_LEN = 10_000;
|
|
216
216
|
|
|
217
217
|
// Assigned names are lowercase slugs of a pool name with a numeric counter
|
|
218
218
|
// suffix ("al-go-rithm-00001"), which satisfies NAME_CHARSET. The charset
|
package/src/extract-queue.ts
CHANGED
|
@@ -56,10 +56,25 @@ export function appendBatch(sessionID: string, toolCalls: BatchToolCall[]): void
|
|
|
56
56
|
const additions: ToolInteraction[] = [];
|
|
57
57
|
for (const tc of toolCalls) {
|
|
58
58
|
const lower = tc.tool_name.toLowerCase();
|
|
59
|
-
if (lower === "mcp__thatch__memory_remember"
|
|
59
|
+
if (lower === "mcp__thatch__memory_remember") {
|
|
60
|
+
// The session that writes a memory has processed its queued
|
|
61
|
+
// interactions itself - drain. This is the parent's self-serve path.
|
|
60
62
|
resetMissedCount(sessionID);
|
|
61
63
|
consumeQueue(sessionID);
|
|
62
64
|
existing.length = 0;
|
|
65
|
+
} else if (lower === "mcp__thatch__extraction_done") {
|
|
66
|
+
// An extraction_done ack must NOT drain the queue. When the PARENT
|
|
67
|
+
// acks after dispatching (per the nudge), a drain here deletes the
|
|
68
|
+
// queue before the sub-agent's get_extraction_payload fetch - the
|
|
69
|
+
// accept-before-fetch race, which on this path is a hard delete
|
|
70
|
+
// (silent interaction loss). The queue is consumed instead by the
|
|
71
|
+
// extractor's completion: extraction_done with the parent's
|
|
72
|
+
// session_id (drainExtractionQueue in mcp.ts), or the parent's own
|
|
73
|
+
// memory_remember above. A no-drain ack only resets the escalation
|
|
74
|
+
// counter - the queue persists on disk (durable across
|
|
75
|
+
// interruption), and an extractor that dies without completing
|
|
76
|
+
// leaves it in place for the next nudge to re-dispatch.
|
|
77
|
+
resetMissedCount(sessionID);
|
|
63
78
|
}
|
|
64
79
|
if (lower.startsWith("mcp__thatch__")) continue;
|
|
65
80
|
if (lower === "skill" || lower === "task" || lower === "agent") continue;
|
package/src/extraction.ts
CHANGED
|
@@ -342,9 +342,10 @@ export class ExtractionPipeline {
|
|
|
342
342
|
* Requeues accepted entries that have waited longer than maxAgeMs for a
|
|
343
343
|
* completion signal that never came: the extractor sub-agent crashed
|
|
344
344
|
* without acking, or the completion ack was lost. Without this, accepted
|
|
345
|
-
* entries linger unprocessed
|
|
346
|
-
*
|
|
347
|
-
*
|
|
345
|
+
* entries linger unprocessed with nothing to re-extract them - silent
|
|
346
|
+
* loss. Returns the session ids that had entries requeued; on opencode
|
|
347
|
+
* the idle trigger re-extracts them, on MCP hosts the next flush-tools
|
|
348
|
+
* nudge picks them up.
|
|
348
349
|
*/
|
|
349
350
|
requeueStaleAccepted(maxAgeMs = ACCEPTED_STALE_MS): string[] {
|
|
350
351
|
const stale = [...this.#acceptedAt.entries()]
|
package/src/opencode/v2.ts
CHANGED
|
@@ -529,8 +529,9 @@ function buildCapabilities(context: V2Context, worktree: string, childSessions:
|
|
|
529
529
|
// returns the created SessionInfo directly.
|
|
530
530
|
const result = await session.create({ location: { directory: worktree }, title: input.title });
|
|
531
531
|
const id = result?.id;
|
|
532
|
-
// A shape mismatch must fail
|
|
533
|
-
//
|
|
532
|
+
// A shape mismatch must fail loudly: the runtime logs it and retries
|
|
533
|
+
// extraction at the next idle. It must not silently corrupt the
|
|
534
|
+
// child-session maps.
|
|
534
535
|
if (!id) throw new Error(`v2 session.create returned no id: ${JSON.stringify(result)?.slice(0, 200)}`);
|
|
535
536
|
// Register for event forwarding: the child's events carry the project
|
|
536
537
|
// directory, which the pump's directory filter would otherwise drop.
|
|
@@ -539,7 +540,7 @@ function buildCapabilities(context: V2Context, worktree: string, childSessions:
|
|
|
539
540
|
},
|
|
540
541
|
// No delete on the v2 SessionDomain: extraction child sessions are not
|
|
541
542
|
// cleaned up on v2 (documented gap; the bookkeeping maps still keep the
|
|
542
|
-
//
|
|
543
|
+
// claim/completion lifecycle consistent). Two user-visible consequences: the session
|
|
543
544
|
// picker accumulates one thatch-extraction entry per extraction, and
|
|
544
545
|
// "continue last session" (-c) logic that picks the newest top-level
|
|
545
546
|
// session will land in an extraction child after any session that
|
package/src/prompts.ts
CHANGED
|
@@ -802,46 +802,25 @@ export function reflectCore(tool: ToolNamer): string {
|
|
|
802
802
|
}
|
|
803
803
|
|
|
804
804
|
/**
|
|
805
|
-
* Extraction nudge with escalation
|
|
806
|
-
*
|
|
807
|
-
*
|
|
808
|
-
*
|
|
809
|
-
*
|
|
805
|
+
* Extraction nudge with escalation - MCP hosts only (Claude Code / Cursor).
|
|
806
|
+
* There is deliberately no opencode variant: the opencode plugin extracts via
|
|
807
|
+
* its own child sessions (triggerExtraction at session idle) and no longer
|
|
808
|
+
* asks the model to run the handshake. Only hosts with no plugin lifecycle
|
|
809
|
+
* (each hook a fresh process, no session-creation API) still need a model-
|
|
810
|
+
* driven dispatch, and their file-backed queue (extract-queue.ts) is durable
|
|
811
|
+
* until the extractor's completion, so the handshake cannot lose entries
|
|
812
|
+
* there.
|
|
813
|
+
*
|
|
814
|
+
* The missedCount parameter tracks consecutive nudges delivered without any
|
|
815
|
+
* memory_remember call in between, escalating the tone from polite to
|
|
816
|
+
* insistent to shouting.
|
|
810
817
|
*
|
|
811
818
|
* The sessionID replaces the inline payload: the nudge tells the model to
|
|
812
819
|
* dispatch a sub-agent that calls get_extraction_payload to fetch the queued
|
|
813
820
|
* interactions as a tool response. This keeps the full payload out of the
|
|
814
821
|
* main session's context window.
|
|
815
|
-
*
|
|
816
|
-
* Call extractionNudgeOpencode for the opencode plugin path (task tool with
|
|
817
|
-
* background parameter) or extractionNudgeMcp for the Claude Code/Cursor
|
|
818
|
-
* CLI path (generic sub-agent wording).
|
|
819
822
|
*/
|
|
820
823
|
export function extractionNudge(
|
|
821
|
-
count: number,
|
|
822
|
-
missedCount: number,
|
|
823
|
-
toolName: string,
|
|
824
|
-
sessionID: string,
|
|
825
|
-
): string {
|
|
826
|
-
const isOpencode = toolName.startsWith("thatch_");
|
|
827
|
-
return isOpencode
|
|
828
|
-
? extractionNudgeOpencode(count, missedCount, sessionID)
|
|
829
|
-
: extractionNudgeMcp(count, missedCount, sessionID);
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
function extractionNudgeOpencode(
|
|
833
|
-
count: number,
|
|
834
|
-
missedCount: number,
|
|
835
|
-
sessionID: string,
|
|
836
|
-
): string {
|
|
837
|
-
const plural = count === 1 ? "" : "s";
|
|
838
|
-
const dispatch = 'Dispatch a task with background: true and subagent_type: "general" (required for thatch tool access)';
|
|
839
|
-
const drainTool = "thatch_extraction_done";
|
|
840
|
-
const fetchTool = "thatch_get_extraction_payload";
|
|
841
|
-
return buildExtractionNudge(count, missedCount, plural, dispatch, drainTool, fetchTool, sessionID);
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
function extractionNudgeMcp(
|
|
845
824
|
count: number,
|
|
846
825
|
missedCount: number,
|
|
847
826
|
sessionID: string,
|