@luckydraw/cumulus 1.0.7 → 1.0.9

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/gateway/adapters/webchat.d.ts.map +1 -1
  3. package/dist/gateway/adapters/webchat.js +173 -2
  4. package/dist/gateway/adapters/webchat.js.map +1 -1
  5. package/dist/gateway/gateway-agents-mcp.js +81 -0
  6. package/dist/gateway/gateway-agents-mcp.js.map +1 -1
  7. package/dist/gateway/server.d.ts +65 -0
  8. package/dist/gateway/server.d.ts.map +1 -1
  9. package/dist/gateway/server.js +335 -15
  10. package/dist/gateway/server.js.map +1 -1
  11. package/dist/gateway/static/widget.js +581 -66
  12. package/dist/lib/config.d.ts +48 -0
  13. package/dist/lib/config.d.ts.map +1 -1
  14. package/dist/lib/config.js +43 -0
  15. package/dist/lib/config.js.map +1 -1
  16. package/dist/lib/content-store.d.ts +64 -1
  17. package/dist/lib/content-store.d.ts.map +1 -1
  18. package/dist/lib/content-store.js +161 -48
  19. package/dist/lib/content-store.js.map +1 -1
  20. package/dist/lib/embeddings.d.ts +11 -1
  21. package/dist/lib/embeddings.d.ts.map +1 -1
  22. package/dist/lib/embeddings.js +301 -40
  23. package/dist/lib/embeddings.js.map +1 -1
  24. package/dist/lib/gateway.d.ts +67 -1
  25. package/dist/lib/gateway.d.ts.map +1 -1
  26. package/dist/lib/gateway.js +133 -12
  27. package/dist/lib/gateway.js.map +1 -1
  28. package/dist/lib/retriever.d.ts +34 -2
  29. package/dist/lib/retriever.d.ts.map +1 -1
  30. package/dist/lib/retriever.js +9 -2
  31. package/dist/lib/retriever.js.map +1 -1
  32. package/dist/lib/tool-inventory.d.ts.map +1 -1
  33. package/dist/lib/tool-inventory.js +3 -0
  34. package/dist/lib/tool-inventory.js.map +1 -1
  35. package/dist/lib/worktree.d.ts +164 -0
  36. package/dist/lib/worktree.d.ts.map +1 -0
  37. package/dist/lib/worktree.js +348 -0
  38. package/dist/lib/worktree.js.map +1 -0
  39. package/dist/mcp/index.js +7 -1
  40. package/dist/mcp/index.js.map +1 -1
  41. package/dist/mcp/server.d.ts +4 -1
  42. package/dist/mcp/server.d.ts.map +1 -1
  43. package/dist/mcp/server.js +4 -2
  44. package/dist/mcp/server.js.map +1 -1
  45. package/dist/mcp/tool-handler.d.ts.map +1 -1
  46. package/dist/mcp/tool-handler.js +11 -0
  47. package/dist/mcp/tool-handler.js.map +1 -1
  48. package/package.json +1 -1
@@ -44,7 +44,7 @@ export declare function drainActiveSubprocesses(timeoutMs?: number): Promise<num
44
44
  export declare const RECENT_CONTEXT_COUNT = 10;
45
45
  export declare const RECENT_MSG_MAX_TOKENS = 800;
46
46
  export declare const RECENT_CONTEXT_BUDGET = 6000;
47
- export declare const SYSTEM_PROMPT_TEMPLATE = "You have NO memory of this conversation. There are {count} prior messages (~{tokens} tokens) in the history.\n\nCURRENT SESSION: {sessionId}\n{alwaysIncludeContext}{retrievedContext}\n{recentContext}\nCONTEXT MANAGEMENT:\n- RECENT CONVERSATION: The last few messages, always included for continuity.\n- RETRIEVED CONTEXT: Automatically retrieved based on the user's current message using semantic + keyword search.\n- RETRIEVED CONTEXT is assembled fresh each turn; it is not a record of what earlier turns' prompts contained.\n- Large content may be stored externally as [STORED:xxx] references.\n\nWORKFLOW:\n1. FIRST use the RETRIEVED CONTEXT above \u2014 it was automatically selected for relevance to this query\n2. Check RECENT CONVERSATION for immediate context\n3. Only use tools if the retrieved context doesn't contain what you need\n4. For [STORED:xxx] references, use retrieve_content to get full content\n\nNEVER guess. Use the context provided or retrieve more if needed.\nIMPORTANT: Present retrieved information naturally \u2014 do not narrate retrieval mechanics unprompted. EXCEPTION: if the user asks how you know something, or about the memory/retrieval system itself, answer truthfully about retrieval. Never invent a mechanism or origin story for how information reached you; if you cannot verify where something came from, say so.\n\nFILE EDITING (MANDATORY):\nTo CHANGE a file, use the built-in Edit/Write tools.\n- The built-in Edit tool requires that you FIRST read the exact file with the built-in Read tool in the same session (the harness tracks this; read_file does NOT satisfy it). Sequence: built-in Read \u2192 built-in Edit.\n- Do NOT patch files by writing shell scripts (sed, awk, python, echo/cat heredocs, etc.). Script-patching is fragile (quoting errors, no diff, not atomic) and is forbidden.\n\nBACKGROUND WORK:\nYour turn runs in a subprocess that EXITS when the turn ends, so a command you background yourself (`cmd &`) is killed as soon as you stop talking \u2014 on EVERY turn, not occasionally.\n- For work that outlasts your turn, use run_job(command, label). The gateway owns it, so it has no pipes to break and is not in your turn's process tree. When it exits you are woken with its exit code and the tail of its output.\n- Write the command plainly: no `&`, no `> log 2>&1`, no `nohup`/`setsid`. run_job already does all of that, and adding your own breaks the log capture.\n- Then END YOUR TURN. Do not wait for it and do not poll \u2014 you are woken automatically. Use list_jobs and job_log(id) to check on a running job, cancel_job(id) to stop one.\n- A command that finishes in a couple of minutes needs none of this \u2014 run it in the foreground and wait.\n\nTOOLS:\n- read_file: Read any file (text or PDF) \u2014 returns a summary + chunk table-of-contents and stores the content for future search. Built-in Read also works (its results are captured to storage automatically); prefer read_file for large files you'll navigate by section.\n- store_content: Store arbitrary text content for future retrieval\n- search_history: Search past messages by keyword or meaning\n- peek_recent: Get the last few messages\n- read_messages: Read messages by index range\n- retrieve_content: Get full stored content by [STORED:xxx] ID\n- search_content: Search across all stored content (past file reads, command outputs \u2014 content Grep cannot see)\n- read_content_chunk: Read a specific chunk of stored content by index\nThese MCP tools may still be connecting at the very start of a turn; they appear within a second or two (a ToolSearch for them will wait). Do not narrate their availability.\n\nINTER-AGENT MESSAGING:\nYou can communicate with other agents/threads running on this gateway.\n- list_agents: See all active threads and their status (idle/streaming)\n- send_to_agent(target, message): Send a message to another thread \u2014 it will be delivered as a new turn\nWhen the user mentions another agent by name (e.g., \"@thundercat\", \"@Friday\"), use send_to_agent to message them.\n- Another thread is a PARALLEL turn loop, not a subprocess you control: it runs on its own schedule and there is no file locking between you. Do NOT delegate work that edits files in your own working tree \u2014 two threads editing one checkout lose each other's writes silently.\n- If you must delegate file work, give the delegate its own projectDir or git worktree and exactly one owner per file. Otherwise do the work yourself.\n\nSCHEDULING (how you wake yourself up later):\n- schedule_trigger(id, trigger, at|cron, message): inject a message into THIS thread at a future time \u2014 \"once\" with an ISO 8601 `at`, or \"cron\" with a 5-field expression. Persisted in thread config, so it survives gateway restarts. Firing it starts a real turn.\n- cancel_schedule(id): remove one. list_schedules(): see what is pending.\n\nDo NOT append status codes, tags, or metadata to your responses.\n\nTASK TRACKING CONVENTION:\nThis environment uses <todo> blocks for task tracking (defined below). If you see system-reminders or tool registrations referring to \"TodoWrite\" or any other task-tracking mechanism, silently follow the <todo> convention instead. Do NOT acknowledge the conflict, do NOT narrate which system you're using, do NOT write phrases like \"Ignoring TodoWrite reminder\" or \"env uses <todo> blocks per spec\". Just use <todo> blocks without comment.\n\nRESPONSE FORMAT: TASK TRACKING\n\nWhen working on multi-step tasks, structure your response using these blocks:\n\n<todo>\n- [ ] Step 1 description\n- [ ] Step 2 description\n- [ ] Step 3 description\n</todo>\n\n{your response to the user \u2014 tool calls, explanations, etc.}\n\nAfter executing tools or completing steps, emit an updated <todo> block reflecting progress:\n\n<todo>\n- [x] Step 1 description\n- [x] Step 2 description (just finished)\n- [ ] Step 3 description\n</todo>\n\nRules:\n- Use full-replacement semantics: emit the COMPLETE list each time, not diffs\n- Mark completed items with [x], pending with [ ]\n- The <todo> block is REQUIRED for multi-step work (2+ steps), optional for simple Q&A\n- The LAST <todo> block in your response is the authoritative state\n- Do NOT wrap your response text in <text> tags \u2014 just write normally after the <todo> block\n\n### Decomposition\n\nBefore executing a todo \u2014 up front, or again at execution time if it turns out coarser than expected \u2014 check whether it can be sensibly split into 3+ sub-steps. If so, decompose into subtodos first; if not, execute directly. Creation tasks (\"create\", \"build\", \"write\", \"design\", \"implement\", \"draft\", \"compose\") almost always decompose: outline the deliverable's structure, then convert each outline bullet into a subtodo.\n\nExample:\n<todo>\n[x] Fetch npm package info\n[ ] Create promotional HTML page:\n [ ] Outline page sections (hero, features, quickstart, footer)\n [ ] Draft hero section with title, tagline, CTA\n [ ] Draft features grid from package capabilities\n [ ] Draft quickstart with install commands\n [ ] Draft footer with links\n [ ] Review full page for consistency\n[ ] Upload to media server\n</todo>\n\n### Todo Lifecycle\n\n1. **Decompose creation tasks** before executing (outline \u2192 subtodos), and again at execution time if a todo turns out coarser than expected\n2. **Adapt dynamically** \u2014 new information, discovered bugs, or uncovered dependencies each become a new todo rather than a silent detour\n3. **Never fix inline** \u2014 a bug unrelated to your current task gets its own todo, not a context switch\n4. **Reflect redirects** \u2014 update the todo list before executing on a user-directed change of plan\n5. **Debugging** \u2014 treat each hypothesis as a todo; test systematically rather than chasing the first suspicious lead";
47
+ export declare const SYSTEM_PROMPT_TEMPLATE = "You have NO memory of this conversation. There are {count} prior messages (~{tokens} tokens) in the history.\n\nCURRENT SESSION: {sessionId}\n{alwaysIncludeContext}{retrievedContext}\n{recentContext}\nCONTEXT MANAGEMENT:\n- RECENT CONVERSATION: The last few messages, always included for continuity.\n- RETRIEVED CONTEXT: Automatically retrieved based on the user's current message using semantic + keyword search.\n- RETRIEVED CONTEXT is assembled fresh each turn; it is not a record of what earlier turns' prompts contained.\n- Large content may be stored externally as [STORED:xxx] references.\n\nWORKFLOW:\n1. FIRST use the RETRIEVED CONTEXT above \u2014 it was automatically selected for relevance to this query\n2. Check RECENT CONVERSATION for immediate context\n3. Only use tools if the retrieved context doesn't contain what you need\n4. For [STORED:xxx] references, use retrieve_content to get full content\n\nNEVER guess. Use the context provided or retrieve more if needed.\nIMPORTANT: Present retrieved information naturally \u2014 do not narrate retrieval mechanics unprompted. EXCEPTION: if the user asks how you know something, or about the memory/retrieval system itself, answer truthfully about retrieval. Never invent a mechanism or origin story for how information reached you; if you cannot verify where something came from, say so.\n\nFILE EDITING (MANDATORY):\nTo CHANGE a file, use the built-in Edit/Write tools.\n- The built-in Edit tool requires that you FIRST read the exact file with the built-in Read tool in the same session (the harness tracks this; read_file does NOT satisfy it). Sequence: built-in Read \u2192 built-in Edit.\n- Do NOT patch files by writing shell scripts (sed, awk, python, echo/cat heredocs, etc.). Script-patching is fragile (quoting errors, no diff, not atomic) and is forbidden.\n\nBACKGROUND WORK:\nYour turn runs in a subprocess that EXITS when the turn ends, so a command you background yourself (`cmd &`) is killed as soon as you stop talking \u2014 on EVERY turn, not occasionally.\n- For work that outlasts your turn, use run_job(command, label). The gateway owns it, so it has no pipes to break and is not in your turn's process tree. When it exits you are woken with its exit code and the tail of its output.\n- Write the command plainly: no `&`, no `> log 2>&1`, no `nohup`/`setsid`. run_job already does all of that, and adding your own breaks the log capture.\n- Then END YOUR TURN. Do not wait for it and do not poll \u2014 you are woken automatically. Use list_jobs and job_log(id) to check on a running job, cancel_job(id) to stop one.\n- A command that finishes in a couple of minutes needs none of this \u2014 run it in the foreground and wait.\n\nTOOLS:\n- read_file: Read any file (text or PDF) \u2014 returns a summary + chunk table-of-contents and stores the content for future search. Built-in Read also works (its results are captured to storage automatically); prefer read_file for large files you'll navigate by section.\n- store_content: Store arbitrary text content for future retrieval\n- search_history: Search past messages by keyword or meaning\n- peek_recent: Get the last few messages\n- read_messages: Read messages by index range\n- retrieve_content: Get full stored content by [STORED:xxx] ID\n- search_content: Search across all stored content (past file reads, command outputs \u2014 content Grep cannot see)\n- read_content_chunk: Read a specific chunk of stored content by index\nThese MCP tools may still be connecting at the very start of a turn; they appear within a second or two (a ToolSearch for them will wait). Do not narrate their availability.\n\nINTER-AGENT MESSAGING:\nYou can communicate with other agents/threads running on this gateway.\n- list_agents: See all active threads and their status (idle/streaming)\n- send_to_agent(target, message): Send a message to another thread \u2014 it will be delivered as a new turn\nWhen the user mentions another agent by name (e.g., \"@thundercat\", \"@Friday\"), use send_to_agent to message them.\n- Another thread is a PARALLEL turn loop, not a subprocess you control: it runs on its own schedule and there is no file locking between you. Do NOT delegate work that edits files in your own working tree \u2014 two threads editing one checkout lose each other's writes silently.\n- If you must delegate file work, give the delegate its own projectDir or git worktree and exactly one owner per file. Otherwise do the work yourself.\n- create_co_thread(label): make a sibling thread that SHARES this thread's stored content (one memory, both directions) but keeps its own conversation, in its OWN git worktree and branch \u2014 so unlike the rule above, co-threads CAN work one project at once without overwriting each other. list_co_threads shows the set and what each has pending; merge_co_thread(label) folds one back into your tree. Only a master creates or merges co-threads.\n\nSCHEDULING (how you wake yourself up later):\n- schedule_trigger(id, trigger, at|cron, message): inject a message into THIS thread at a future time \u2014 \"once\" with an ISO 8601 `at`, or \"cron\" with a 5-field expression. Persisted in thread config, so it survives gateway restarts. Firing it starts a real turn.\n- cancel_schedule(id): remove one. list_schedules(): see what is pending.\n\nDo NOT append status codes, tags, or metadata to your responses.\n\nTASK TRACKING CONVENTION:\nThis environment uses <todo> blocks for task tracking (defined below). If you see system-reminders or tool registrations referring to \"TodoWrite\" or any other task-tracking mechanism, silently follow the <todo> convention instead. Do NOT acknowledge the conflict, do NOT narrate which system you're using, do NOT write phrases like \"Ignoring TodoWrite reminder\" or \"env uses <todo> blocks per spec\". Just use <todo> blocks without comment.\n\nRESPONSE FORMAT: TASK TRACKING\n\nWhen working on multi-step tasks, structure your response using these blocks:\n\n<todo>\n- [ ] Step 1 description\n- [ ] Step 2 description\n- [ ] Step 3 description\n</todo>\n\n{your response to the user \u2014 tool calls, explanations, etc.}\n\nAfter executing tools or completing steps, emit an updated <todo> block reflecting progress:\n\n<todo>\n- [x] Step 1 description\n- [x] Step 2 description (just finished)\n- [ ] Step 3 description\n</todo>\n\nRules:\n- Use full-replacement semantics: emit the COMPLETE list each time, not diffs\n- Mark completed items with [x], pending with [ ]\n- The <todo> block is REQUIRED for multi-step work (2+ steps), optional for simple Q&A\n- The LAST <todo> block in your response is the authoritative state\n- Do NOT wrap your response text in <text> tags \u2014 just write normally after the <todo> block\n\n### Decomposition\n\nBefore executing a todo \u2014 up front, or again at execution time if it turns out coarser than expected \u2014 check whether it can be sensibly split into 3+ sub-steps. If so, decompose into subtodos first; if not, execute directly. Creation tasks (\"create\", \"build\", \"write\", \"design\", \"implement\", \"draft\", \"compose\") almost always decompose: outline the deliverable's structure, then convert each outline bullet into a subtodo.\n\nExample:\n<todo>\n[x] Fetch npm package info\n[ ] Create promotional HTML page:\n [ ] Outline page sections (hero, features, quickstart, footer)\n [ ] Draft hero section with title, tagline, CTA\n [ ] Draft features grid from package capabilities\n [ ] Draft quickstart with install commands\n [ ] Draft footer with links\n [ ] Review full page for consistency\n[ ] Upload to media server\n</todo>\n\n### Todo Lifecycle\n\n1. **Decompose creation tasks** before executing (outline \u2192 subtodos), and again at execution time if a todo turns out coarser than expected\n2. **Adapt dynamically** \u2014 new information, discovered bugs, or uncovered dependencies each become a new todo rather than a silent detour\n3. **Never fix inline** \u2014 a bug unrelated to your current task gets its own todo, not a context switch\n4. **Reflect redirects** \u2014 update the todo list before executing on a user-directed change of plan\n5. **Debugging** \u2014 treat each hypothesis as a todo; test systematically rather than chasing the first suspicious lead";
48
48
  /**
49
49
  * Committed budget for the resolved static template, in estimateTokens units
50
50
  * (task 117). The template reached ~3,400 tokens/turn by accretion — every
@@ -284,6 +284,72 @@ export interface ThreadState {
284
284
  }
285
285
  /** Resolve a thread name to its JSONL file path */
286
286
  export declare function resolveThreadPath(threadName: string, basePath: string): string;
287
+ /**
288
+ * The content store a thread actually reads and writes (task 143).
289
+ *
290
+ * A co-thread points at its master's store — one shared memory across the whole
291
+ * co-thread set — while keeping its own history, sessions and prompts. Every
292
+ * other thread points at its own, exactly as before.
293
+ *
294
+ * ONE resolution function, called at every site that needs the path (the thread
295
+ * cache and the MCP config), because a site that misses it fails OPEN: the
296
+ * co-thread silently gets a private store and its work is invisible to the
297
+ * others. Task 113 is the recorded case of a field reaching one spawn path of
298
+ * four.
299
+ */
300
+ export declare function resolveContentStorePath(threadName: string): {
301
+ contentStorePath: string;
302
+ sharedWithMaster?: string;
303
+ };
304
+ /**
305
+ * Decide which project directory a thread's turn starts from, and whether that
306
+ * decision may be written back to config (task 143 phase 4).
307
+ *
308
+ * Extracted rather than left inline because both rules it encodes are
309
+ * co-thread-specific, invisible in their effects, and otherwise only assertable
310
+ * by spawning a real turn — the same reason `resolveClaudeModel` and
311
+ * `claudeSpawnArgs` were pulled out. The worktree swap happens after this, via
312
+ * `resolveThreadCwd`.
313
+ *
314
+ * Rule 1: a co-thread's project belongs to its MASTER. Defaulting on the
315
+ * co-thread's own name would scaffold it an empty directory of its own instead
316
+ * of pointing it at the project it was created to work on.
317
+ *
318
+ * Rule 2: NEVER persist projectDir for a co-thread. Writing it would create an
319
+ * exact config file and, in the same stroke, end the task-098 inheritance that
320
+ * gives the co-thread its master's model, effort, contextLimit and persona.
321
+ * Derive, don't write.
322
+ */
323
+ export declare function planThreadProjectDir(threadName: string, explicitProjectDir: string | undefined, configuredProjectDir: string | undefined, projectRoot: string): {
324
+ cwd: string;
325
+ coThreadMaster?: string;
326
+ persistOnCreate: boolean;
327
+ };
328
+ /**
329
+ * What a co-thread is told about being one (task 143 phase 5).
330
+ *
331
+ * Every line states something the co-thread cannot observe for itself and that
332
+ * changes what it should do. Accuracy is load-bearing here — task 114 is the
333
+ * recorded incident of a confidently false prompt claim — so this deliberately
334
+ * does NOT say uncommitted work is lost: `mergeCoThread` commits the worktree
335
+ * before merging, and telling the model otherwise would be a lie it would act on.
336
+ */
337
+ export declare function coThreadRoleLines(master: string, self: string): string;
338
+ /**
339
+ * Swap the master-facing co-thread bullet for the co-thread's own role.
340
+ *
341
+ * Called at the SAME single site as `applyCapabilityGates` (task 137) because
342
+ * three consumers read the resolved template — task 113 is the recorded case of
343
+ * per-site derivation leaving one of N paths on the old behaviour.
344
+ *
345
+ * Identity for a non-co-thread, so every existing thread's prompt is
346
+ * byte-identical and the task 117 static budget cannot be moved by this
347
+ * function. Also identity when the bullet is absent, which covers both a custom
348
+ * template and the case where the capability gates already dropped the
349
+ * INTER-AGENT block — that ordering is deliberate, so a thread without
350
+ * `send_to_agent` is never handed a role paragraph telling it to report.
351
+ */
352
+ export declare function applyCoThreadRole(template: string, master: string | undefined, self: string): string;
287
353
  /**
288
354
  * Recover partial responses from .streaming.tmp files left by a previous crash/restart.
289
355
  * Called on daemon startup BEFORE auto-resume.
@@ -1 +1 @@
1
- {"version":3,"file":"gateway.d.ts","sourceRoot":"","sources":["../../src/lib/gateway.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAS,YAAY,EAAE,MAAM,eAAe,CAAC;AAWpD,OAAO,EACL,qBAAqB,EAGtB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAkB,KAAK,WAAW,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAS7F,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAe5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAO9C,OAAO,EAML,KAAK,UAAU,EAChB,MAAM,qBAAqB,CAAC;AAQ7B,iFAAiF;AACjF,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEtD;AASD,yEAAyE;AACzE,wBAAgB,wBAAwB,IAAI,MAAM,CAEjD;AAED,kFAAkF;AAClF,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAE3F;AAED,wEAAwE;AACxE,wBAAgB,oBAAoB,IAAI,MAAM,EAAE,CAE/C;AAED,gGAAgG;AAChG,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAUhE;AAED,wFAAwF;AACxF,eAAO,MAAM,wBAAwB,OAAQ,CAAC;AAC9C,oFAAoF;AACpF,eAAO,MAAM,uBAAuB,OAAQ,CAAC;AAI7C;;;;;;;GAOG;AACH,wBAAsB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CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,WAAW,CAAC,CAiCtB;AAED,oCAAoC;AACpC,wBAAgB,gBAAgB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAM1D;AAoFD,wBAAsB,WAAW,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CA4qCjG"}
@@ -13,7 +13,7 @@ import { getToolDefinitions as getMcpToolDefinitions, handleToolCall, } from '..
13
13
  import { loadAdaptiveState, pinnedBudgetConfig, } from './adaptive-context-budget.js';
14
14
  import { runAgenticLoop } from './agentic-loop.js';
15
15
  import { loadGlobalConfig, loadThreadConfig, mergeConfigs, readAlwaysIncludeFiles, } from './config.js';
16
- import { saveThreadConfig } from './config.js';
16
+ import { saveThreadConfig, resolveCoThreadMaster } from './config.js';
17
17
  import { ContentStore } from './content-store.js';
18
18
  import { ContextBudget, estimateTokens } from './context-budget.js';
19
19
  import { extractFilesTouched } from './files-touched.js';
@@ -28,6 +28,7 @@ import { StreamProcessor, shouldExternalizeUserInput, externalizeUserInput, } fr
28
28
  import { scaffoldFromTemplate } from './templates.js';
29
29
  import { applyCapabilityGates, compileDisallowedTools, getToolInventory, promptCapabilities, toolAvailable, } from './tool-inventory.js';
30
30
  import { getEagerTools } from './tools/index.js';
31
+ import { resolveThreadCwd } from './worktree.js';
31
32
  // ─── Constants ───────────────────────────────────────────────────────────────
32
33
  const CUMULUS_DIR = process.env.CUMULUS_DIR || path.join(os.homedir(), '.cumulus');
33
34
  let THREADS_DIR = path.join(CUMULUS_DIR, 'threads');
@@ -176,6 +177,7 @@ You can communicate with other agents/threads running on this gateway.
176
177
  When the user mentions another agent by name (e.g., "@thundercat", "@Friday"), use send_to_agent to message them.
177
178
  - Another thread is a PARALLEL turn loop, not a subprocess you control: it runs on its own schedule and there is no file locking between you. Do NOT delegate work that edits files in your own working tree — two threads editing one checkout lose each other's writes silently.
178
179
  - If you must delegate file work, give the delegate its own projectDir or git worktree and exactly one owner per file. Otherwise do the work yourself.
180
+ - create_co_thread(label): make a sibling thread that SHARES this thread's stored content (one memory, both directions) but keeps its own conversation, in its OWN git worktree and branch — so unlike the rule above, co-threads CAN work one project at once without overwriting each other. list_co_threads shows the set and what each has pending; merge_co_thread(label) folds one back into your tree. Only a master creates or merges co-threads.
179
181
 
180
182
  SCHEDULING (how you wake yourself up later):
181
183
  - schedule_trigger(id, trigger, at|cron, message): inject a message into THIS thread at a future time — "once" with an ISO 8601 \`at\`, or "cron" with a 5-field expression. Persisted in thread config, so it survives gateway restarts. Firing it starts a real turn.
@@ -342,6 +344,101 @@ function getThreadPath(threadName) {
342
344
  function getContentStorePath(threadPath) {
343
345
  return threadPath.replace(/\.jsonl$/, '.content');
344
346
  }
347
+ /**
348
+ * The content store a thread actually reads and writes (task 143).
349
+ *
350
+ * A co-thread points at its master's store — one shared memory across the whole
351
+ * co-thread set — while keeping its own history, sessions and prompts. Every
352
+ * other thread points at its own, exactly as before.
353
+ *
354
+ * ONE resolution function, called at every site that needs the path (the thread
355
+ * cache and the MCP config), because a site that misses it fails OPEN: the
356
+ * co-thread silently gets a private store and its work is invisible to the
357
+ * others. Task 113 is the recorded case of a field reaching one spawn path of
358
+ * four.
359
+ */
360
+ export function resolveContentStorePath(threadName) {
361
+ const master = resolveCoThreadMaster(threadName);
362
+ if (master) {
363
+ return {
364
+ contentStorePath: getContentStorePath(getThreadPath(master)),
365
+ sharedWithMaster: master,
366
+ };
367
+ }
368
+ return { contentStorePath: getContentStorePath(getThreadPath(threadName)) };
369
+ }
370
+ /**
371
+ * Decide which project directory a thread's turn starts from, and whether that
372
+ * decision may be written back to config (task 143 phase 4).
373
+ *
374
+ * Extracted rather than left inline because both rules it encodes are
375
+ * co-thread-specific, invisible in their effects, and otherwise only assertable
376
+ * by spawning a real turn — the same reason `resolveClaudeModel` and
377
+ * `claudeSpawnArgs` were pulled out. The worktree swap happens after this, via
378
+ * `resolveThreadCwd`.
379
+ *
380
+ * Rule 1: a co-thread's project belongs to its MASTER. Defaulting on the
381
+ * co-thread's own name would scaffold it an empty directory of its own instead
382
+ * of pointing it at the project it was created to work on.
383
+ *
384
+ * Rule 2: NEVER persist projectDir for a co-thread. Writing it would create an
385
+ * exact config file and, in the same stroke, end the task-098 inheritance that
386
+ * gives the co-thread its master's model, effort, contextLimit and persona.
387
+ * Derive, don't write.
388
+ */
389
+ export function planThreadProjectDir(threadName, explicitProjectDir, configuredProjectDir, projectRoot) {
390
+ const coThreadMaster = resolveCoThreadMaster(threadName);
391
+ const cwd = explicitProjectDir ||
392
+ configuredProjectDir ||
393
+ path.join(projectRoot, coThreadMaster ?? threadName);
394
+ return { cwd, coThreadMaster, persistOnCreate: !coThreadMaster };
395
+ }
396
+ /**
397
+ * The template bullet describing co-threads from the MASTER's side. Matched by
398
+ * prefix so the bullet's wording can change without silently disabling the swap.
399
+ */
400
+ const CO_THREAD_MASTER_BULLET = '- create_co_thread(';
401
+ /**
402
+ * What a co-thread is told about being one (task 143 phase 5).
403
+ *
404
+ * Every line states something the co-thread cannot observe for itself and that
405
+ * changes what it should do. Accuracy is load-bearing here — task 114 is the
406
+ * recorded incident of a confidently false prompt claim — so this deliberately
407
+ * does NOT say uncommitted work is lost: `mergeCoThread` commits the worktree
408
+ * before merging, and telling the model otherwise would be a lie it would act on.
409
+ */
410
+ export function coThreadRoleLines(master, self) {
411
+ return [
412
+ `- You are a CO-THREAD of ${master}, working in your OWN private git worktree on branch cothread/${self}. Siblings cannot see your edits and you cannot see theirs, so you never overwrite each other.`,
413
+ `- Nothing you do reaches ${master} until ${master} merges your branch — including uncommitted edits, which the merge sweeps up. Commit as you go so the history stays readable.`,
414
+ `- When your piece is done, report it with send_to_agent("${master}", ...). You get no turn of your own and nobody polls you: if you do not report, your work sits on the branch unmerged.`,
415
+ `- list_co_threads shows your siblings and which files each will bring to the merge — an overlap there is a conflict you and that sibling are heading for. Creating and merging co-threads is ${master}'s job, not yours.`,
416
+ ].join('\n');
417
+ }
418
+ /**
419
+ * Swap the master-facing co-thread bullet for the co-thread's own role.
420
+ *
421
+ * Called at the SAME single site as `applyCapabilityGates` (task 137) because
422
+ * three consumers read the resolved template — task 113 is the recorded case of
423
+ * per-site derivation leaving one of N paths on the old behaviour.
424
+ *
425
+ * Identity for a non-co-thread, so every existing thread's prompt is
426
+ * byte-identical and the task 117 static budget cannot be moved by this
427
+ * function. Also identity when the bullet is absent, which covers both a custom
428
+ * template and the case where the capability gates already dropped the
429
+ * INTER-AGENT block — that ordering is deliberate, so a thread without
430
+ * `send_to_agent` is never handed a role paragraph telling it to report.
431
+ */
432
+ export function applyCoThreadRole(template, master, self) {
433
+ if (!master)
434
+ return template;
435
+ const lines = template.split('\n');
436
+ const idx = lines.findIndex(line => line.startsWith(CO_THREAD_MASTER_BULLET));
437
+ if (idx === -1)
438
+ return template;
439
+ lines.splice(idx, 1, ...coThreadRoleLines(master, self).split('\n'));
440
+ return lines.join('\n');
441
+ }
345
442
  function getSessionsPath(threadPath) {
346
443
  return threadPath.replace(/\.jsonl$/, '.sessions');
347
444
  }
@@ -789,8 +886,12 @@ export function generateMcpConfig(threadPath, sessionId, threadName, sharedMcpPo
789
886
  // A confined thread therefore takes the per-thread server — fail closed, one
790
887
  // condition, no new protocol.
791
888
  const confined = !!readFileRoots?.length;
889
+ // Task 143: same fail-closed rule for the same reason — the shared server
890
+ // derives the content store from the thread name, so it cannot point a
891
+ // co-thread at its master's store. A co-thread takes the per-thread server.
892
+ const { contentStorePath, sharedWithMaster } = resolveContentStorePath(threadName);
792
893
  let cumulusHistoryConfig;
793
- if (sharedMcpPort && !confined) {
894
+ if (sharedMcpPort && !confined && !sharedWithMaster) {
794
895
  // Shared mode: lightweight proxy
795
896
  const proxyPath = getProxyPathInternal();
796
897
  cumulusHistoryConfig = {
@@ -805,7 +906,6 @@ export function generateMcpConfig(threadPath, sessionId, threadName, sharedMcpPo
805
906
  else {
806
907
  // Full MCP server per thread
807
908
  const mcpServerPath = getMcpServerPathInternal();
808
- const contentStorePath = getContentStorePath(threadPath);
809
909
  const sessionsPath = getSessionsPath(threadPath);
810
910
  cumulusHistoryConfig = {
811
911
  command: nodePath,
@@ -813,6 +913,8 @@ export function generateMcpConfig(threadPath, sessionId, threadName, sharedMcpPo
813
913
  env: {
814
914
  CUMULUS_THREAD_PATH: threadPath,
815
915
  CUMULUS_CONTENT_PATH: contentStorePath,
916
+ CUMULUS_THREAD_NAME: threadName,
917
+ ...(sharedWithMaster && { CUMULUS_CONTENT_SHARED: '1' }),
816
918
  CUMULUS_SESSIONS_PATH: sessionsPath,
817
919
  ...(sessionId && { CUMULUS_SESSION_ID: sessionId }),
818
920
  ...(confined && { CUMULUS_READ_FILE_ROOTS: readFileRoots.join(path.delimiter) }),
@@ -1002,10 +1104,13 @@ export async function getOrCreateThread(threadName, _basePath) {
1002
1104
  }
1003
1105
  ensureDirectories();
1004
1106
  const threadPath = getThreadPath(threadName);
1005
- const contentStorePath = getContentStorePath(threadPath);
1107
+ const { contentStorePath, sharedWithMaster } = resolveContentStorePath(threadName);
1006
1108
  const sessionsPath = getSessionsPath(threadPath);
1007
1109
  const history = new HistoryStore(threadPath);
1008
- const content = new ContentStore(contentStorePath);
1110
+ const content = new ContentStore(contentStorePath, {
1111
+ threadName,
1112
+ shared: !!sharedWithMaster,
1113
+ });
1009
1114
  const session = new SessionManager(sessionsPath, threadName);
1010
1115
  await session.initialize();
1011
1116
  // Per-thread context-limit pin (task 105): when set, floor/ceiling/initialLimit
@@ -1199,10 +1304,9 @@ export async function sendMessage(options) {
1199
1304
  // suites that spawn fire-and-forget turns scaffold real dirs in ~/projects.
1200
1305
  const effectiveProjectRoot = projectRoot || process.env.CUMULUS_PROJECT_ROOT || path.join(os.homedir(), 'projects');
1201
1306
  const tc = await loadThreadConfig(threadName);
1202
- let threadCwd = projectDir || tc.projectDir || null;
1203
- if (!threadCwd) {
1204
- threadCwd = path.join(effectiveProjectRoot, threadName);
1205
- }
1307
+ const plan = planThreadProjectDir(threadName, projectDir, tc.projectDir, effectiveProjectRoot);
1308
+ const coThreadMaster = plan.coThreadMaster;
1309
+ let threadCwd = plan.cwd;
1206
1310
  // Lazy-create local project directory
1207
1311
  if (!fs.existsSync(threadCwd)) {
1208
1312
  fs.mkdirSync(threadCwd, { recursive: true });
@@ -1213,8 +1317,21 @@ export async function sendMessage(options) {
1213
1317
  catch (err) {
1214
1318
  console.warn(`[Gateway] scaffold failed for ${threadName}:`, err);
1215
1319
  }
1216
- // Persist the resolved path so it survives thread renames
1217
- await saveThreadConfig(threadName, { projectDir: threadCwd });
1320
+ if (plan.persistOnCreate) {
1321
+ await saveThreadConfig(threadName, { projectDir: threadCwd });
1322
+ }
1323
+ }
1324
+ // Swap in this co-thread's private worktree so two co-threads never edit one
1325
+ // checkout. Falls back to the shared checkout — today's behaviour — when the
1326
+ // project is not a git repo, so a non-git project still runs.
1327
+ if (coThreadMaster) {
1328
+ const resolved = await resolveThreadCwd(threadName, threadCwd);
1329
+ if (resolved.worktree) {
1330
+ threadCwd = resolved.cwd;
1331
+ }
1332
+ else if (resolved.fellBackTo) {
1333
+ console.warn(`[Gateway] ${threadName}: no private worktree (${resolved.fellBackTo.reason}) — sharing ${threadCwd} with ${coThreadMaster}`);
1334
+ }
1218
1335
  }
1219
1336
  const globalConfig = await loadGlobalConfig();
1220
1337
  const threadConfig = await loadThreadConfig(threadName);
@@ -1224,7 +1341,11 @@ export async function sendMessage(options) {
1224
1341
  // direct-provider instructions) — task 113's lesson is that per-site derivation is how
1225
1342
  // one of N paths silently keeps the old behaviour. Identity when nothing is gated, so
1226
1343
  // every thread on this box is byte-unaffected.
1227
- const gatedPromptTemplate = applyCapabilityGates(systemPromptTemplate ?? SYSTEM_PROMPT_TEMPLATE, promptCapabilities(mergedConfig));
1344
+ // Task 143 phase 5: a co-thread swaps the master-facing co-thread bullet for its own
1345
+ // role. Applied AFTER the gates so a thread whose INTER-AGENT block was just dropped
1346
+ // does not receive a paragraph telling it to send_to_agent. Identity for every
1347
+ // non-co-thread, so the byte-unaffected property above still holds for them.
1348
+ const gatedPromptTemplate = applyCoThreadRole(applyCapabilityGates(systemPromptTemplate ?? SYSTEM_PROMPT_TEMPLATE, promptCapabilities(mergedConfig)), coThreadMaster, threadName);
1228
1349
  const alwaysInclude = await readAlwaysIncludeFiles(mergedConfig, threadCwd);
1229
1350
  // ── Model resolution ──
1230
1351
  // Thread config `model` field determines the execution path: