@goondocks/myco 0.20.2 → 0.21.1

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 (216) hide show
  1. package/bin/myco-run +68 -7
  2. package/dist/agent-eval-YK2VP2S4.js +356 -0
  3. package/dist/agent-eval-YK2VP2S4.js.map +1 -0
  4. package/dist/{agent-run-X25Q2A6T.js → agent-run-GEJBD2YD.js} +10 -8
  5. package/dist/{agent-run-X25Q2A6T.js.map → agent-run-GEJBD2YD.js.map} +1 -1
  6. package/dist/{agent-tasks-7B6OFERB.js → agent-tasks-5XSRGTRX.js} +10 -8
  7. package/dist/{agent-tasks-7B6OFERB.js.map → agent-tasks-5XSRGTRX.js.map} +1 -1
  8. package/dist/{chunk-OD4AA7PV.js → chunk-53RPGOEN.js} +56 -8
  9. package/dist/chunk-53RPGOEN.js.map +1 -0
  10. package/dist/chunk-54SXG5HF.js +26 -0
  11. package/dist/chunk-54SXG5HF.js.map +1 -0
  12. package/dist/{chunk-XATDZX7U.js → chunk-6ALVMIB4.js} +19 -5
  13. package/dist/{chunk-XATDZX7U.js.map → chunk-6ALVMIB4.js.map} +1 -1
  14. package/dist/{chunk-FLLBJLHM.js → chunk-6C6QZ4PM.js} +9 -5
  15. package/dist/chunk-6C6QZ4PM.js.map +1 -0
  16. package/dist/{chunk-CCRGY3QW.js → chunk-AUIXX33A.js} +24 -95
  17. package/dist/chunk-AUIXX33A.js.map +1 -0
  18. package/dist/chunk-CISWUP5W.js +101 -0
  19. package/dist/chunk-CISWUP5W.js.map +1 -0
  20. package/dist/{chunk-MYOZLMB2.js → chunk-DTWUHHFI.js} +576 -20
  21. package/dist/chunk-DTWUHHFI.js.map +1 -0
  22. package/dist/chunk-EEOJWLMP.js +582 -0
  23. package/dist/chunk-EEOJWLMP.js.map +1 -0
  24. package/dist/{chunk-XG5RRUYF.js → chunk-ENZR5NG7.js} +2 -2
  25. package/dist/{chunk-6RFZWV4R.js → chunk-FCJ5JV54.js} +1 -1
  26. package/dist/{chunk-6RFZWV4R.js.map → chunk-FCJ5JV54.js.map} +1 -1
  27. package/dist/{chunk-US4LNCAT.js → chunk-IPPMYQ2Y.js} +5 -1
  28. package/dist/chunk-IPPMYQ2Y.js.map +1 -0
  29. package/dist/{chunk-VVNL26WX.js → chunk-KTTSXYEK.js} +22 -10
  30. package/dist/chunk-KTTSXYEK.js.map +1 -0
  31. package/dist/chunk-LQIPXVDH.js +17 -0
  32. package/dist/chunk-LQIPXVDH.js.map +1 -0
  33. package/dist/{chunk-DCSGJ7W4.js → chunk-N2DGFACQ.js} +3 -3
  34. package/dist/chunk-N7Z3LUEZ.js +858 -0
  35. package/dist/chunk-N7Z3LUEZ.js.map +1 -0
  36. package/dist/{chunk-2PDWCDKY.js → chunk-NFO7BRCO.js} +10 -7
  37. package/dist/{chunk-2PDWCDKY.js.map → chunk-NFO7BRCO.js.map} +1 -1
  38. package/dist/{chunk-Q36VMZST.js → chunk-OTQH5KZW.js} +89 -38
  39. package/dist/chunk-OTQH5KZW.js.map +1 -0
  40. package/dist/chunk-OUJSQSKE.js +113 -0
  41. package/dist/chunk-OUJSQSKE.js.map +1 -0
  42. package/dist/chunk-OZ3FBAK5.js +50 -0
  43. package/dist/chunk-OZ3FBAK5.js.map +1 -0
  44. package/dist/chunk-QATYARI5.js +408 -0
  45. package/dist/chunk-QATYARI5.js.map +1 -0
  46. package/dist/{chunk-KESLPBKV.js → chunk-QDLVIW2O.js} +4 -4
  47. package/dist/{chunk-5XIVBO25.js → chunk-QLLBJEM7.js} +6 -2
  48. package/dist/chunk-QLLBJEM7.js.map +1 -0
  49. package/dist/{chunk-EVDQKYCG.js → chunk-RQSJLWP4.js} +13 -2
  50. package/dist/chunk-RQSJLWP4.js.map +1 -0
  51. package/dist/{chunk-BPRIYNLE.js → chunk-TKAJ3JVF.js} +3 -3
  52. package/dist/chunk-TSM6VESW.js +25 -0
  53. package/dist/chunk-TSM6VESW.js.map +1 -0
  54. package/dist/{chunk-6X2ERTQV.js → chunk-USVFEWYL.js} +6 -4
  55. package/dist/{chunk-6X2ERTQV.js.map → chunk-USVFEWYL.js.map} +1 -1
  56. package/dist/{chunk-JZGN33AY.js → chunk-VRI56337.js} +4 -4
  57. package/dist/chunk-X2IRGXGF.js +14103 -0
  58. package/dist/chunk-X2IRGXGF.js.map +1 -0
  59. package/dist/{chunk-FMRZ26U5.js → chunk-X3IGT5RV.js} +5 -2
  60. package/dist/{chunk-FMRZ26U5.js.map → chunk-X3IGT5RV.js.map} +1 -1
  61. package/dist/{chunk-KHT24OWC.js → chunk-YDUOSRGD.js} +8 -94
  62. package/dist/{chunk-KHT24OWC.js.map → chunk-YDUOSRGD.js.map} +1 -1
  63. package/dist/{chunk-NGROSFOH.js → chunk-Z66IT5KL.js} +14 -9
  64. package/dist/chunk-Z66IT5KL.js.map +1 -0
  65. package/dist/{cli-GGPWH4UO.js → cli-HSLIG7EX.js} +50 -43
  66. package/dist/cli-HSLIG7EX.js.map +1 -0
  67. package/dist/{client-YXQUTXVZ.js → client-Z43DNLJH.js} +4 -4
  68. package/dist/{config-OMCYHG2S.js → config-VC4ACP42.js} +6 -4
  69. package/dist/{config-OMCYHG2S.js.map → config-VC4ACP42.js.map} +1 -1
  70. package/dist/{detect-PXNM6TA7.js → detect-7NUD5B5R.js} +2 -2
  71. package/dist/{detect-providers-5KOPZ7J2.js → detect-providers-ILLQZROY.js} +4 -4
  72. package/dist/{doctor-5JXJ36KA.js → doctor-HJCWHAU4.js} +49 -16
  73. package/dist/doctor-HJCWHAU4.js.map +1 -0
  74. package/dist/executor-DO6QFC6G.js +45 -0
  75. package/dist/{init-LMYOVZAV.js → init-4KVK7W2E.js} +16 -14
  76. package/dist/{init-LMYOVZAV.js.map → init-4KVK7W2E.js.map} +1 -1
  77. package/dist/{installer-FS257JRZ.js → installer-N4UTEACX.js} +6 -4
  78. package/dist/{llm-TH4NLIRM.js → llm-AGVEF5XD.js} +5 -4
  79. package/dist/{loader-CQYTFHEW.js → loader-LX7TFRM6.js} +5 -3
  80. package/dist/{loader-NOMBJUPW.js → loader-UDNUMEDA.js} +5 -3
  81. package/dist/{main-YTBVRTBI.js → main-4J4QZZTZ.js} +2518 -656
  82. package/dist/main-4J4QZZTZ.js.map +1 -0
  83. package/dist/{open-HG2DX6RN.js → open-7TXJQM3H.js} +10 -8
  84. package/dist/{open-HG2DX6RN.js.map → open-7TXJQM3H.js.map} +1 -1
  85. package/dist/{post-compact-JSECI44W.js → post-compact-7AEFVCZS.js} +8 -8
  86. package/dist/{post-tool-use-POGPTJBA.js → post-tool-use-TZINWWDH.js} +11 -9
  87. package/dist/post-tool-use-TZINWWDH.js.map +1 -0
  88. package/dist/{post-tool-use-failure-OT7BFWQW.js → post-tool-use-failure-TCFEU2GI.js} +8 -8
  89. package/dist/{pre-compact-OXVODKH4.js → pre-compact-LO2VZCGR.js} +8 -8
  90. package/dist/{provider-check-43LAMSMH.js → provider-check-ZEV5P4KM.js} +4 -4
  91. package/dist/{registry-U4CHXK6R.js → registry-F3THYC5M.js} +6 -4
  92. package/dist/{remove-N7ZPELFU.js → remove-F77AAALE.js} +12 -10
  93. package/dist/{remove-N7ZPELFU.js.map → remove-F77AAALE.js.map} +1 -1
  94. package/dist/{restart-ADG5GBTB.js → restart-UEFDPMLT.js} +11 -9
  95. package/dist/{restart-ADG5GBTB.js.map → restart-UEFDPMLT.js.map} +1 -1
  96. package/dist/{search-AHZEUNRR.js → search-NHNVUAQQ.js} +11 -9
  97. package/dist/{search-AHZEUNRR.js.map → search-NHNVUAQQ.js.map} +1 -1
  98. package/dist/{server-AGVYZVP5.js → server-AZJSTQEK.js} +369 -270
  99. package/dist/server-AZJSTQEK.js.map +1 -0
  100. package/dist/{session-6IU4AXYP.js → session-3HLC5KOD.js} +11 -9
  101. package/dist/{session-6IU4AXYP.js.map → session-3HLC5KOD.js.map} +1 -1
  102. package/dist/{session-end-FT27DWYZ.js → session-end-FS46UARX.js} +7 -7
  103. package/dist/session-start-46KPFV2H.js +134 -0
  104. package/dist/session-start-46KPFV2H.js.map +1 -0
  105. package/dist/{setup-llm-77MP4I2G.js → setup-llm-JMWSNQ2C.js} +11 -9
  106. package/dist/{setup-llm-77MP4I2G.js.map → setup-llm-JMWSNQ2C.js.map} +1 -1
  107. package/dist/src/agent/definitions/agent.yaml +9 -5
  108. package/dist/src/agent/definitions/tasks/cortex-instructions.yaml +115 -0
  109. package/dist/src/agent/definitions/tasks/cortex-prompt-builder.yaml +67 -0
  110. package/dist/src/agent/definitions/tasks/digest-only.yaml +1 -1
  111. package/dist/src/agent/definitions/tasks/extract-only.yaml +1 -1
  112. package/dist/src/agent/definitions/tasks/review-session.yaml +10 -39
  113. package/dist/src/agent/definitions/tasks/skill-evolve.yaml +181 -25
  114. package/dist/src/agent/definitions/tasks/skill-generate.yaml +21 -7
  115. package/dist/src/agent/definitions/tasks/skill-survey.yaml +2 -6
  116. package/dist/src/agent/definitions/tasks/supersession-sweep.yaml +1 -1
  117. package/dist/src/agent/definitions/tasks/title-summary.yaml +12 -19
  118. package/dist/src/agent/definitions/tasks/{full-intelligence.yaml → vault-evolve.yaml} +74 -129
  119. package/dist/src/agent/definitions/tasks/vault-seed.yaml +370 -0
  120. package/dist/src/agent/prompts/agent.md +12 -38
  121. package/dist/src/cli.js +1 -1
  122. package/dist/src/daemon/main.js +1 -1
  123. package/dist/src/hooks/post-tool-use.js +1 -1
  124. package/dist/src/hooks/session-end.js +1 -1
  125. package/dist/src/hooks/session-start.js +1 -1
  126. package/dist/src/hooks/stop.js +1 -1
  127. package/dist/src/hooks/user-prompt-submit.js +1 -1
  128. package/dist/src/mcp/server.js +1 -1
  129. package/dist/src/symbionts/manifests/claude-code.yaml +4 -0
  130. package/dist/src/symbionts/manifests/opencode.yaml +7 -0
  131. package/dist/src/symbionts/manifests/pi.yaml +22 -0
  132. package/dist/src/symbionts/templates/agents-starter.md +1 -1
  133. package/dist/src/symbionts/templates/pi/package.json +6 -0
  134. package/dist/src/symbionts/templates/pi/plugin.ts +559 -0
  135. package/dist/{stats-NVPWOYTE.js → stats-MKMETHMA.js} +11 -9
  136. package/dist/{stats-NVPWOYTE.js.map → stats-MKMETHMA.js.map} +1 -1
  137. package/dist/{stop-ZPIKVLH4.js → stop-OUEX6KA4.js} +7 -7
  138. package/dist/{stop-failure-2PX67YJC.js → stop-failure-2BWVNZEG.js} +8 -8
  139. package/dist/{subagent-start-UUE6EHQD.js → subagent-start-J4VV6DEE.js} +8 -8
  140. package/dist/{subagent-stop-KQWWWPE6.js → subagent-stop-JMLVEPIA.js} +8 -8
  141. package/dist/{task-completed-WMHOFQ7B.js → task-completed-65CHMMKA.js} +8 -8
  142. package/dist/{team-LRZ6GTQK.js → team-U2LDKIS4.js} +7 -5
  143. package/dist/{turns-YFNI5CQC.js → turns-HU2CTZAP.js} +2 -2
  144. package/dist/ui/assets/index-BUGor9dk.js +842 -0
  145. package/dist/ui/assets/index-_OP4ifzH.css +1 -0
  146. package/dist/ui/index.html +2 -2
  147. package/dist/{update-O6V4RC4W.js → update-ZSHVXWSQ.js} +12 -10
  148. package/dist/{update-O6V4RC4W.js.map → update-ZSHVXWSQ.js.map} +1 -1
  149. package/dist/{user-prompt-submit-N36KUPHI.js → user-prompt-submit-APMO6FVU.js} +10 -9
  150. package/dist/{user-prompt-submit-N36KUPHI.js.map → user-prompt-submit-APMO6FVU.js.map} +1 -1
  151. package/dist/{verify-LXPV7NYG.js → verify-R76ZFJSZ.js} +8 -5
  152. package/dist/{verify-LXPV7NYG.js.map → verify-R76ZFJSZ.js.map} +1 -1
  153. package/dist/{version-XMPPJQHR.js → version-TXPPS3L5.js} +2 -2
  154. package/dist/version-TXPPS3L5.js.map +1 -0
  155. package/package.json +3 -1
  156. package/skills/myco/SKILL.md +16 -1
  157. package/skills/myco/references/cli-usage.md +1 -1
  158. package/skills/myco-rules/SKILL.md +94 -0
  159. package/skills/{rules → myco-rules}/references/rules-bad-example.md +1 -1
  160. package/skills/{rules → myco-rules}/references/rules-good-example.md +1 -1
  161. package/dist/chunk-4YFKBL3F.js +0 -195
  162. package/dist/chunk-4YFKBL3F.js.map +0 -1
  163. package/dist/chunk-5XIVBO25.js.map +0 -1
  164. package/dist/chunk-CCRGY3QW.js.map +0 -1
  165. package/dist/chunk-CUDIZJY7.js +0 -36
  166. package/dist/chunk-CUDIZJY7.js.map +0 -1
  167. package/dist/chunk-EVDQKYCG.js.map +0 -1
  168. package/dist/chunk-FLLBJLHM.js.map +0 -1
  169. package/dist/chunk-MYOZLMB2.js.map +0 -1
  170. package/dist/chunk-NGROSFOH.js.map +0 -1
  171. package/dist/chunk-OD4AA7PV.js.map +0 -1
  172. package/dist/chunk-Q36VMZST.js.map +0 -1
  173. package/dist/chunk-US4LNCAT.js.map +0 -1
  174. package/dist/chunk-UYMFCYBF.js +0 -2326
  175. package/dist/chunk-UYMFCYBF.js.map +0 -1
  176. package/dist/chunk-VVNL26WX.js.map +0 -1
  177. package/dist/cli-GGPWH4UO.js.map +0 -1
  178. package/dist/doctor-5JXJ36KA.js.map +0 -1
  179. package/dist/executor-HWW2QNZQ.js +0 -2472
  180. package/dist/executor-HWW2QNZQ.js.map +0 -1
  181. package/dist/main-YTBVRTBI.js.map +0 -1
  182. package/dist/post-tool-use-POGPTJBA.js.map +0 -1
  183. package/dist/server-AGVYZVP5.js.map +0 -1
  184. package/dist/session-start-LAFICHII.js +0 -189
  185. package/dist/session-start-LAFICHII.js.map +0 -1
  186. package/dist/src/agent/definitions/tasks/graph-maintenance.yaml +0 -93
  187. package/dist/ui/assets/index-C2JuNtRB.css +0 -1
  188. package/dist/ui/assets/index-JLVaQKV2.js +0 -832
  189. package/skills/myco-curate/SKILL.md +0 -86
  190. package/skills/rules/SKILL.md +0 -214
  191. /package/dist/{chunk-XG5RRUYF.js.map → chunk-ENZR5NG7.js.map} +0 -0
  192. /package/dist/{chunk-DCSGJ7W4.js.map → chunk-N2DGFACQ.js.map} +0 -0
  193. /package/dist/{chunk-KESLPBKV.js.map → chunk-QDLVIW2O.js.map} +0 -0
  194. /package/dist/{chunk-BPRIYNLE.js.map → chunk-TKAJ3JVF.js.map} +0 -0
  195. /package/dist/{chunk-JZGN33AY.js.map → chunk-VRI56337.js.map} +0 -0
  196. /package/dist/{client-YXQUTXVZ.js.map → client-Z43DNLJH.js.map} +0 -0
  197. /package/dist/{detect-PXNM6TA7.js.map → detect-7NUD5B5R.js.map} +0 -0
  198. /package/dist/{detect-providers-5KOPZ7J2.js.map → detect-providers-ILLQZROY.js.map} +0 -0
  199. /package/dist/{installer-FS257JRZ.js.map → executor-DO6QFC6G.js.map} +0 -0
  200. /package/dist/{llm-TH4NLIRM.js.map → installer-N4UTEACX.js.map} +0 -0
  201. /package/dist/{loader-CQYTFHEW.js.map → llm-AGVEF5XD.js.map} +0 -0
  202. /package/dist/{loader-NOMBJUPW.js.map → loader-LX7TFRM6.js.map} +0 -0
  203. /package/dist/{provider-check-43LAMSMH.js.map → loader-UDNUMEDA.js.map} +0 -0
  204. /package/dist/{post-compact-JSECI44W.js.map → post-compact-7AEFVCZS.js.map} +0 -0
  205. /package/dist/{post-tool-use-failure-OT7BFWQW.js.map → post-tool-use-failure-TCFEU2GI.js.map} +0 -0
  206. /package/dist/{pre-compact-OXVODKH4.js.map → pre-compact-LO2VZCGR.js.map} +0 -0
  207. /package/dist/{registry-U4CHXK6R.js.map → provider-check-ZEV5P4KM.js.map} +0 -0
  208. /package/dist/{team-LRZ6GTQK.js.map → registry-F3THYC5M.js.map} +0 -0
  209. /package/dist/{session-end-FT27DWYZ.js.map → session-end-FS46UARX.js.map} +0 -0
  210. /package/dist/{stop-ZPIKVLH4.js.map → stop-OUEX6KA4.js.map} +0 -0
  211. /package/dist/{stop-failure-2PX67YJC.js.map → stop-failure-2BWVNZEG.js.map} +0 -0
  212. /package/dist/{subagent-start-UUE6EHQD.js.map → subagent-start-J4VV6DEE.js.map} +0 -0
  213. /package/dist/{subagent-stop-KQWWWPE6.js.map → subagent-stop-JMLVEPIA.js.map} +0 -0
  214. /package/dist/{task-completed-WMHOFQ7B.js.map → task-completed-65CHMMKA.js.map} +0 -0
  215. /package/dist/{turns-YFNI5CQC.js.map → team-U2LDKIS4.js.map} +0 -0
  216. /package/dist/{version-XMPPJQHR.js.map → turns-HU2CTZAP.js.map} +0 -0
@@ -0,0 +1,858 @@
1
+ import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
2
+ import {
3
+ enqueueOutbox,
4
+ getTeamMachineId,
5
+ isTeamSyncEnabled,
6
+ listSessions,
7
+ syncRow
8
+ } from "./chunk-RQSJLWP4.js";
9
+ import {
10
+ COLLECTIVE_TOOL_DEFINITIONS,
11
+ TOOL_DEFINITIONS,
12
+ getToolCortexPriority
13
+ } from "./chunk-EEOJWLMP.js";
14
+ import {
15
+ getDatabase
16
+ } from "./chunk-MYX5NCRH.js";
17
+ import {
18
+ CONTENT_HASH_ALGORITHM,
19
+ DEFAULT_AGENT_ID,
20
+ DIGEST_FALLBACK_TIER,
21
+ DIGEST_TIERS,
22
+ epochSeconds
23
+ } from "./chunk-6C6QZ4PM.js";
24
+
25
+ // src/db/queries/cortex-instructions.ts
26
+ var CORTEX_INSTRUCTION_COLUMNS = [
27
+ "id",
28
+ "agent_id",
29
+ "content",
30
+ "input_hash",
31
+ "source_run_id",
32
+ "generated_at",
33
+ "machine_id",
34
+ "synced_at"
35
+ ];
36
+ var SELECT_COLUMNS = CORTEX_INSTRUCTION_COLUMNS.join(", ");
37
+ var DEFAULT_CORTEX_INSTRUCTIONS_ID = "session-start";
38
+ function toCortexInstructionsRow(row) {
39
+ return {
40
+ id: row.id,
41
+ agent_id: row.agent_id,
42
+ content: row.content,
43
+ input_hash: row.input_hash,
44
+ source_run_id: row.source_run_id ?? null,
45
+ generated_at: row.generated_at,
46
+ machine_id: row.machine_id ?? "local",
47
+ synced_at: row.synced_at ?? null
48
+ };
49
+ }
50
+ function upsertCortexInstructions(input) {
51
+ const db = getDatabase();
52
+ const id = input.id ?? `${input.agent_id}:${DEFAULT_CORTEX_INSTRUCTIONS_ID}`;
53
+ const row = db.prepare(
54
+ `INSERT INTO cortex_instructions (
55
+ id, agent_id, content, input_hash, source_run_id, generated_at, machine_id
56
+ ) VALUES (
57
+ ?, ?, ?, ?, ?, ?, ?
58
+ )
59
+ ON CONFLICT (id) DO UPDATE SET
60
+ content = EXCLUDED.content,
61
+ input_hash = EXCLUDED.input_hash,
62
+ source_run_id = EXCLUDED.source_run_id,
63
+ generated_at = EXCLUDED.generated_at,
64
+ machine_id = EXCLUDED.machine_id
65
+ RETURNING ${SELECT_COLUMNS}`
66
+ ).get(
67
+ id,
68
+ input.agent_id,
69
+ input.content,
70
+ input.input_hash,
71
+ input.source_run_id ?? null,
72
+ input.generated_at,
73
+ input.machine_id ?? getTeamMachineId()
74
+ );
75
+ return toCortexInstructionsRow(row);
76
+ }
77
+ function getCortexInstructions(agentId) {
78
+ const db = getDatabase();
79
+ const row = db.prepare(
80
+ `SELECT ${SELECT_COLUMNS}
81
+ FROM cortex_instructions
82
+ WHERE agent_id = ?
83
+ ORDER BY generated_at DESC
84
+ LIMIT 1`
85
+ ).get(agentId);
86
+ return row ? toCortexInstructionsRow(row) : null;
87
+ }
88
+
89
+ // src/db/queries/digest-extracts.ts
90
+ var EXTRACT_COLUMNS = [
91
+ "id",
92
+ "agent_id",
93
+ "tier",
94
+ "content",
95
+ "substrate_hash",
96
+ "generated_at",
97
+ "machine_id",
98
+ "synced_at"
99
+ ];
100
+ var SELECT_COLUMNS2 = EXTRACT_COLUMNS.join(", ");
101
+ function toDigestExtractRow(row) {
102
+ return {
103
+ id: row.id,
104
+ agent_id: row.agent_id,
105
+ tier: row.tier,
106
+ content: row.content,
107
+ substrate_hash: row.substrate_hash ?? null,
108
+ generated_at: row.generated_at,
109
+ machine_id: row.machine_id ?? "local",
110
+ synced_at: row.synced_at ?? null
111
+ };
112
+ }
113
+ function upsertDigestExtract(data, options = {}) {
114
+ if (options.dryRun) return null;
115
+ const db = getDatabase();
116
+ return db.transaction(() => {
117
+ const existingRow = db.prepare(
118
+ `SELECT ${SELECT_COLUMNS2} FROM digest_extracts WHERE agent_id = ? AND tier = ?`
119
+ ).get(data.agent_id, data.tier);
120
+ if (existingRow) {
121
+ const priorRevisionId = db.prepare(
122
+ `SELECT id FROM digest_extract_revisions
123
+ WHERE agent_id = ? AND tier = ?
124
+ ORDER BY id DESC
125
+ LIMIT 1`
126
+ ).get(data.agent_id, data.tier);
127
+ db.prepare(
128
+ `INSERT INTO digest_extract_revisions
129
+ (agent_id, tier, content, metadata, run_id, parent_revision_id, created_at)
130
+ VALUES (?, ?, ?, ?, ?, ?, ?)`
131
+ ).run(
132
+ data.agent_id,
133
+ data.tier,
134
+ existingRow.content,
135
+ options.metadata ?? null,
136
+ options.runId ?? null,
137
+ priorRevisionId?.id ?? null,
138
+ epochSeconds()
139
+ );
140
+ }
141
+ db.prepare(
142
+ `INSERT INTO digest_extracts (agent_id, tier, content, generated_at)
143
+ VALUES (?, ?, ?, ?)
144
+ ON CONFLICT (agent_id, tier) DO UPDATE SET
145
+ content = EXCLUDED.content,
146
+ generated_at = EXCLUDED.generated_at`
147
+ ).run(data.agent_id, data.tier, data.content, data.generated_at);
148
+ const row = db.prepare(
149
+ `SELECT ${SELECT_COLUMNS2} FROM digest_extracts WHERE agent_id = ? AND tier = ?`
150
+ ).get(data.agent_id, data.tier);
151
+ return toDigestExtractRow(row);
152
+ })();
153
+ }
154
+ function getDigestExtract(agentId, tier) {
155
+ const db = getDatabase();
156
+ const row = db.prepare(
157
+ `SELECT ${SELECT_COLUMNS2} FROM digest_extracts
158
+ WHERE agent_id = ? AND tier = ?`
159
+ ).get(agentId, tier);
160
+ if (!row) return null;
161
+ return toDigestExtractRow(row);
162
+ }
163
+ function listDigestExtracts(agentId) {
164
+ const db = getDatabase();
165
+ const tierPlaceholders = DIGEST_TIERS.map(() => "?").join(", ");
166
+ const rows = db.prepare(
167
+ `SELECT ${SELECT_COLUMNS2}
168
+ FROM digest_extracts
169
+ WHERE agent_id = ? AND tier IN (${tierPlaceholders})
170
+ ORDER BY tier ASC`
171
+ ).all(agentId, ...DIGEST_TIERS);
172
+ return rows.map(toDigestExtractRow);
173
+ }
174
+ var REVISION_COLUMNS = [
175
+ "id",
176
+ "agent_id",
177
+ "tier",
178
+ "content",
179
+ "metadata",
180
+ "run_id",
181
+ "parent_revision_id",
182
+ "created_at"
183
+ ];
184
+ var REVISION_SELECT = REVISION_COLUMNS.join(", ");
185
+ function toRevisionRow(row) {
186
+ return {
187
+ id: row.id,
188
+ agent_id: row.agent_id,
189
+ tier: row.tier,
190
+ content: row.content,
191
+ metadata: row.metadata ?? null,
192
+ run_id: row.run_id ?? null,
193
+ parent_revision_id: row.parent_revision_id ?? null,
194
+ created_at: row.created_at
195
+ };
196
+ }
197
+ function listDigestRevisions(options) {
198
+ const db = getDatabase();
199
+ const limit = options.limit ?? 50;
200
+ const rows = db.prepare(
201
+ `SELECT ${REVISION_SELECT}
202
+ FROM digest_extract_revisions
203
+ WHERE agent_id = ? AND tier = ?
204
+ ORDER BY created_at DESC, id DESC
205
+ LIMIT ?`
206
+ ).all(options.agentId, options.tier, limit);
207
+ return rows.map(toRevisionRow);
208
+ }
209
+ function rollbackDigestExtract(options) {
210
+ const db = getDatabase();
211
+ const revision = db.prepare(
212
+ `SELECT ${REVISION_SELECT}
213
+ FROM digest_extract_revisions
214
+ WHERE id = ?`
215
+ ).get(options.revisionId);
216
+ if (!revision) return null;
217
+ const agentId = revision.agent_id;
218
+ const tier = revision.tier;
219
+ const targetContent = revision.content;
220
+ const now = epochSeconds();
221
+ return db.transaction(() => {
222
+ const currentRow = db.prepare(
223
+ `SELECT ${SELECT_COLUMNS2} FROM digest_extracts WHERE agent_id = ? AND tier = ?`
224
+ ).get(agentId, tier);
225
+ let newRevisionId = null;
226
+ if (currentRow) {
227
+ const priorRevisionId = db.prepare(
228
+ `SELECT id FROM digest_extract_revisions
229
+ WHERE agent_id = ? AND tier = ?
230
+ ORDER BY id DESC
231
+ LIMIT 1`
232
+ ).get(agentId, tier);
233
+ const info = db.prepare(
234
+ `INSERT INTO digest_extract_revisions
235
+ (agent_id, tier, content, metadata, run_id, parent_revision_id, created_at)
236
+ VALUES (?, ?, ?, ?, ?, ?, ?)`
237
+ ).run(
238
+ agentId,
239
+ tier,
240
+ currentRow.content,
241
+ JSON.stringify({ rollback_of: options.revisionId }),
242
+ options.runId ?? null,
243
+ priorRevisionId?.id ?? null,
244
+ now
245
+ );
246
+ newRevisionId = Number(info.lastInsertRowid);
247
+ }
248
+ db.prepare(
249
+ `INSERT INTO digest_extracts (agent_id, tier, content, generated_at)
250
+ VALUES (?, ?, ?, ?)
251
+ ON CONFLICT (agent_id, tier) DO UPDATE SET
252
+ content = EXCLUDED.content,
253
+ generated_at = EXCLUDED.generated_at`
254
+ ).run(agentId, tier, targetContent, now);
255
+ const restored = db.prepare(
256
+ `SELECT ${SELECT_COLUMNS2} FROM digest_extracts WHERE agent_id = ? AND tier = ?`
257
+ ).get(agentId, tier);
258
+ return {
259
+ row: toDigestExtractRow(restored),
260
+ newRevisionId
261
+ };
262
+ })();
263
+ }
264
+
265
+ // src/db/queries/plans.ts
266
+ var DEFAULT_LIST_LIMIT = 100;
267
+ var DEFAULT_STATUS = "active";
268
+ var DEFAULT_PROCESSED = 0;
269
+ var PLAN_COLUMNS = [
270
+ "id",
271
+ "logical_key",
272
+ "status",
273
+ "author",
274
+ "title",
275
+ "content",
276
+ "source_path",
277
+ "tags",
278
+ "session_id",
279
+ "prompt_batch_id",
280
+ "content_hash",
281
+ "processed",
282
+ "embedded",
283
+ "created_at",
284
+ "updated_at",
285
+ "machine_id",
286
+ "synced_at"
287
+ ];
288
+ var SELECT_COLUMNS3 = PLAN_COLUMNS.join(", ");
289
+ function toPlanRow(row) {
290
+ return {
291
+ id: row.id,
292
+ logical_key: row.logical_key,
293
+ status: row.status,
294
+ author: row.author ?? null,
295
+ title: row.title ?? null,
296
+ content: row.content ?? null,
297
+ source_path: row.source_path ?? null,
298
+ tags: row.tags ?? null,
299
+ session_id: row.session_id ?? null,
300
+ prompt_batch_id: row.prompt_batch_id ?? null,
301
+ content_hash: row.content_hash ?? null,
302
+ processed: row.processed,
303
+ embedded: row.embedded ?? 0,
304
+ created_at: row.created_at,
305
+ updated_at: row.updated_at ?? null,
306
+ machine_id: row.machine_id ?? "local",
307
+ synced_at: row.synced_at ?? null
308
+ };
309
+ }
310
+ function upsertPlan(data) {
311
+ const db = getDatabase();
312
+ db.prepare(
313
+ `INSERT INTO plans (
314
+ id, logical_key, status, author, title, content,
315
+ source_path, tags, session_id, prompt_batch_id, content_hash,
316
+ processed, created_at, updated_at, machine_id
317
+ ) VALUES (
318
+ ?, ?, ?, ?, ?, ?,
319
+ ?, ?, ?, ?, ?,
320
+ ?, ?, ?, ?
321
+ )
322
+ ON CONFLICT (logical_key) DO UPDATE SET
323
+ id = EXCLUDED.id,
324
+ status = EXCLUDED.status,
325
+ author = EXCLUDED.author,
326
+ title = EXCLUDED.title,
327
+ content = EXCLUDED.content,
328
+ source_path = EXCLUDED.source_path,
329
+ tags = EXCLUDED.tags,
330
+ session_id = EXCLUDED.session_id,
331
+ prompt_batch_id = EXCLUDED.prompt_batch_id,
332
+ content_hash = EXCLUDED.content_hash,
333
+ processed = EXCLUDED.processed,
334
+ updated_at = EXCLUDED.updated_at,
335
+ embedded = CASE
336
+ WHEN EXCLUDED.content_hash != plans.content_hash THEN 0
337
+ ELSE plans.embedded
338
+ END`
339
+ ).run(
340
+ data.id,
341
+ data.logical_key,
342
+ data.status ?? DEFAULT_STATUS,
343
+ data.author ?? null,
344
+ data.title ?? null,
345
+ data.content ?? null,
346
+ data.source_path ?? null,
347
+ data.tags ?? null,
348
+ data.session_id ?? null,
349
+ data.prompt_batch_id ?? null,
350
+ data.content_hash ?? null,
351
+ data.processed ?? DEFAULT_PROCESSED,
352
+ data.created_at,
353
+ data.updated_at ?? null,
354
+ data.machine_id ?? getTeamMachineId()
355
+ );
356
+ const row = toPlanRow(
357
+ db.prepare(`SELECT ${SELECT_COLUMNS3} FROM plans WHERE logical_key = ?`).get(data.logical_key)
358
+ );
359
+ syncRow("plans", row);
360
+ return row;
361
+ }
362
+ function getPlan(id) {
363
+ const db = getDatabase();
364
+ const row = db.prepare(
365
+ `SELECT ${SELECT_COLUMNS3} FROM plans WHERE id = ?`
366
+ ).get(id);
367
+ if (!row) return null;
368
+ return toPlanRow(row);
369
+ }
370
+ function getPlanByLogicalKey(logicalKey) {
371
+ const db = getDatabase();
372
+ const row = db.prepare(
373
+ `SELECT ${SELECT_COLUMNS3} FROM plans WHERE logical_key = ?`
374
+ ).get(logicalKey);
375
+ if (!row) return null;
376
+ return toPlanRow(row);
377
+ }
378
+ function deletePlan(id) {
379
+ const db = getDatabase();
380
+ const row = getPlan(id);
381
+ if (!row) return null;
382
+ const info = db.prepare(`DELETE FROM plans WHERE id = ?`).run(id);
383
+ if (info.changes === 0) return null;
384
+ if (isTeamSyncEnabled()) {
385
+ enqueueOutbox({
386
+ table_name: "plans",
387
+ row_id: row.id,
388
+ operation: "delete",
389
+ payload: JSON.stringify({
390
+ id: row.id,
391
+ logical_key: row.logical_key,
392
+ title: row.title
393
+ }),
394
+ machine_id: getTeamMachineId(),
395
+ created_at: epochSeconds()
396
+ });
397
+ }
398
+ return row;
399
+ }
400
+ function listPlans(options = {}) {
401
+ const db = getDatabase();
402
+ const conditions = [];
403
+ const params = [];
404
+ if (options.status !== void 0) {
405
+ conditions.push(`status = ?`);
406
+ params.push(options.status);
407
+ }
408
+ const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
409
+ const limit = options.limit ?? DEFAULT_LIST_LIMIT;
410
+ params.push(limit);
411
+ const rows = db.prepare(
412
+ `SELECT ${SELECT_COLUMNS3}
413
+ FROM plans
414
+ ${where}
415
+ ORDER BY created_at DESC
416
+ LIMIT ?`
417
+ ).all(...params);
418
+ return rows.map(toPlanRow);
419
+ }
420
+ function listPlansBySession(sessionId) {
421
+ const db = getDatabase();
422
+ const rows = db.prepare(
423
+ `SELECT ${SELECT_COLUMNS3}
424
+ FROM plans
425
+ WHERE session_id = ?
426
+ ORDER BY created_at DESC`
427
+ ).all(sessionId);
428
+ return rows.map(toPlanRow);
429
+ }
430
+
431
+ // src/db/queries/spores.ts
432
+ var DEFAULT_LIST_LIMIT2 = 100;
433
+ var DEFAULT_STATUS2 = "active";
434
+ var DEFAULT_IMPORTANCE = 5;
435
+ var SPORE_COLUMNS = [
436
+ "id",
437
+ "agent_id",
438
+ "session_id",
439
+ "prompt_batch_id",
440
+ "observation_type",
441
+ "status",
442
+ "content",
443
+ "context",
444
+ "importance",
445
+ "file_path",
446
+ "tags",
447
+ "content_hash",
448
+ "properties",
449
+ "embedded",
450
+ "created_at",
451
+ "updated_at",
452
+ "machine_id",
453
+ "synced_at"
454
+ ];
455
+ var SELECT_COLUMNS4 = SPORE_COLUMNS.join(", ");
456
+ function toSporeRow(row) {
457
+ return {
458
+ id: row.id,
459
+ agent_id: row.agent_id,
460
+ session_id: row.session_id ?? null,
461
+ prompt_batch_id: row.prompt_batch_id ?? null,
462
+ observation_type: row.observation_type,
463
+ status: row.status,
464
+ content: row.content,
465
+ context: row.context ?? null,
466
+ importance: row.importance,
467
+ file_path: row.file_path ?? null,
468
+ tags: row.tags ?? null,
469
+ content_hash: row.content_hash ?? null,
470
+ properties: row.properties ?? null,
471
+ embedded: row.embedded ?? 0,
472
+ created_at: row.created_at,
473
+ updated_at: row.updated_at ?? null,
474
+ machine_id: row.machine_id ?? "local",
475
+ synced_at: row.synced_at ?? null
476
+ };
477
+ }
478
+ function insertSpore(data) {
479
+ const db = getDatabase();
480
+ db.prepare(
481
+ `INSERT INTO spores (
482
+ id, agent_id, session_id, prompt_batch_id,
483
+ observation_type, status, content, context,
484
+ importance, file_path, tags, content_hash,
485
+ properties, created_at, updated_at, machine_id
486
+ ) VALUES (
487
+ ?, ?, ?, ?,
488
+ ?, ?, ?, ?,
489
+ ?, ?, ?, ?,
490
+ ?, ?, ?, ?
491
+ )`
492
+ ).run(
493
+ data.id,
494
+ data.agent_id,
495
+ data.session_id ?? null,
496
+ data.prompt_batch_id ?? null,
497
+ data.observation_type,
498
+ data.status ?? DEFAULT_STATUS2,
499
+ data.content,
500
+ data.context ?? null,
501
+ data.importance ?? DEFAULT_IMPORTANCE,
502
+ data.file_path ?? null,
503
+ data.tags ?? null,
504
+ data.content_hash ?? null,
505
+ data.properties ?? null,
506
+ data.created_at,
507
+ data.updated_at ?? null,
508
+ data.machine_id ?? getTeamMachineId()
509
+ );
510
+ const row = toSporeRow(
511
+ db.prepare(`SELECT ${SELECT_COLUMNS4} FROM spores WHERE id = ?`).get(data.id)
512
+ );
513
+ syncRow("spores", row);
514
+ return row;
515
+ }
516
+ function getSpore(id) {
517
+ const db = getDatabase();
518
+ const row = db.prepare(
519
+ `SELECT ${SELECT_COLUMNS4} FROM spores WHERE id = ?`
520
+ ).get(id);
521
+ if (!row) return null;
522
+ return toSporeRow(row);
523
+ }
524
+ function buildSporeWhere(options) {
525
+ const conditions = [];
526
+ const params = [];
527
+ if (options.agent_id !== void 0) {
528
+ conditions.push(`agent_id = ?`);
529
+ params.push(options.agent_id);
530
+ }
531
+ if (options.observation_type !== void 0) {
532
+ conditions.push(`observation_type = ?`);
533
+ params.push(options.observation_type);
534
+ }
535
+ if (options.status !== void 0) {
536
+ conditions.push(`status = ?`);
537
+ params.push(options.status);
538
+ }
539
+ if (options.session_id !== void 0) {
540
+ conditions.push(`session_id = ?`);
541
+ params.push(options.session_id);
542
+ }
543
+ if (options.search !== void 0 && options.search.length > 0) {
544
+ conditions.push(`(content LIKE ? OR observation_type LIKE ?)`);
545
+ const pattern = `%${options.search}%`;
546
+ params.push(pattern, pattern);
547
+ }
548
+ if (options.since !== void 0) {
549
+ conditions.push("created_at > ?");
550
+ params.push(options.since);
551
+ }
552
+ if (options.includeActive === false && options.session_id === void 0) {
553
+ conditions.push(
554
+ `(session_id IS NULL OR EXISTS (SELECT 1 FROM sessions s WHERE s.id = spores.session_id AND s.status != 'active'))`
555
+ );
556
+ }
557
+ return {
558
+ where: conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "",
559
+ params
560
+ };
561
+ }
562
+ function listSpores(options = {}) {
563
+ const db = getDatabase();
564
+ const { where, params } = buildSporeWhere(options);
565
+ const limit = options.limit ?? DEFAULT_LIST_LIMIT2;
566
+ const offset = options.offset ?? 0;
567
+ const rows = db.prepare(
568
+ `SELECT ${SELECT_COLUMNS4}
569
+ FROM spores
570
+ ${where}
571
+ ORDER BY created_at DESC
572
+ LIMIT ?
573
+ OFFSET ?`
574
+ ).all(...params, limit, offset);
575
+ return rows.map(toSporeRow);
576
+ }
577
+ function countSpores(options = {}) {
578
+ const db = getDatabase();
579
+ const { where, params } = buildSporeWhere(options);
580
+ const row = db.prepare(
581
+ `SELECT COUNT(*) as count FROM spores ${where}`
582
+ ).get(...params);
583
+ return row.count;
584
+ }
585
+ function listSporeIdsSince(sinceEpoch, limit = 20) {
586
+ const db = getDatabase();
587
+ const rows = db.prepare(
588
+ `SELECT id FROM spores WHERE created_at > ? AND status = 'active' ORDER BY created_at DESC LIMIT ?`
589
+ ).all(sinceEpoch, limit);
590
+ return rows.map((r) => r.id);
591
+ }
592
+ function updateSporeStatus(id, status, updatedAt) {
593
+ const db = getDatabase();
594
+ const info = db.prepare(
595
+ `UPDATE spores
596
+ SET status = ?, updated_at = ?
597
+ WHERE id = ?`
598
+ ).run(status, updatedAt, id);
599
+ if (info.changes === 0) return null;
600
+ const row = toSporeRow(
601
+ db.prepare(`SELECT ${SELECT_COLUMNS4} FROM spores WHERE id = ?`).get(id)
602
+ );
603
+ syncRow("spores", row);
604
+ return row;
605
+ }
606
+
607
+ // src/context/cortex-brief.ts
608
+ import { createHash } from "crypto";
609
+ var MAX_COLLECTIVE_CAPABILITY_LABELS = 4;
610
+ var ALL_CORTEX_TOOL_DEFINITIONS = [...TOOL_DEFINITIONS, ...COLLECTIVE_TOOL_DEFINITIONS];
611
+ var RECENT_SESSION_LIMIT = 5;
612
+ var RECENT_WISDOM_SPORE_LIMIT = 3;
613
+ var RECENT_DECISION_SPORE_LIMIT = 3;
614
+ var RECENT_DISCOVERY_SPORE_LIMIT = 3;
615
+ var RECENT_PLAN_LIMIT = 3;
616
+ var CONTENT_PREVIEW_MAX_CHARS = 360;
617
+ var DIGEST_EXCERPT_MAX_CHARS = 1800;
618
+ var JSON_INDENT = 2;
619
+ var CORTEX_SKILLS_NOTE = "Project and Myco skills are already registered with the agent separately. Tell the agent to use those skills directly when relevant, and do not instruct it to call `myco_skills`.";
620
+ function toCortexToolGuidance(tool) {
621
+ const cortex = tool.cortex;
622
+ if (!cortex) return null;
623
+ return {
624
+ tool: tool.name,
625
+ guidance: cortex.guidance,
626
+ requiresTeam: cortex.requiresTeam,
627
+ requiresCollective: cortex.requiresCollective,
628
+ priority: getToolCortexPriority(tool)
629
+ };
630
+ }
631
+ var RETRIEVAL_GUIDANCE = ALL_CORTEX_TOOL_DEFINITIONS.map(toCortexToolGuidance).filter((entry) => entry !== null).sort((left, right) => left.priority - right.priority);
632
+ async function resolveCortexCapabilities(config, getTeamClient) {
633
+ const teamClient = getTeamClient?.() ?? null;
634
+ const teamEnabled = Boolean(config.team.enabled && teamClient);
635
+ let collectiveConnected = false;
636
+ let collectiveCapabilities = [];
637
+ if (teamEnabled && teamClient) {
638
+ try {
639
+ const status = await teamClient.getCollectiveStatus();
640
+ collectiveConnected = Boolean(status?.connected);
641
+ collectiveCapabilities = status?.capabilities ?? [];
642
+ } catch {
643
+ collectiveConnected = false;
644
+ collectiveCapabilities = [];
645
+ }
646
+ }
647
+ return {
648
+ teamEnabled,
649
+ collectiveConnected,
650
+ collectiveCapabilities
651
+ };
652
+ }
653
+ function shouldInjectCortex(config) {
654
+ return config.cortex_enabled;
655
+ }
656
+ function resolveInstructionDelivery(config, symbiont) {
657
+ if (!symbiont) {
658
+ return { inlineInstructions: true, reason: "missing-symbiont" };
659
+ }
660
+ if (!config.cortex_enabled) {
661
+ return { inlineInstructions: true, reason: "session-start-disabled" };
662
+ }
663
+ if (symbiont.supportsSessionStartInjection) {
664
+ return { inlineInstructions: false, reason: "session-start-supported" };
665
+ }
666
+ return { inlineInstructions: true, reason: "no-session-start" };
667
+ }
668
+ function buildCapabilitySummary(capabilities) {
669
+ const summary = [
670
+ capabilities.collectiveConnected ? "Myco can retrieve local, team, and collective knowledge in this project." : capabilities.teamEnabled ? "Myco can retrieve local and shared team knowledge in this project." : "Myco can retrieve local project knowledge in this project.",
671
+ "Use only the currently available Myco MCP tools described below, and omit any surfaces that are offline."
672
+ ];
673
+ if (capabilities.collectiveConnected && capabilities.collectiveCapabilities.length > 0) {
674
+ const labels = capabilities.collectiveCapabilities.slice(0, MAX_COLLECTIVE_CAPABILITY_LABELS);
675
+ const remaining = Math.max(
676
+ 0,
677
+ capabilities.collectiveCapabilities.length - MAX_COLLECTIVE_CAPABILITY_LABELS
678
+ );
679
+ const suffix = remaining > 0 ? ` (+${remaining} more)` : "";
680
+ summary.push(`Collective capabilities online: ${labels.join(", ")}${suffix}.`);
681
+ }
682
+ return summary;
683
+ }
684
+ function buildRetrievalGuidanceLines(capabilities) {
685
+ const lines = [];
686
+ for (const entry of RETRIEVAL_GUIDANCE) {
687
+ if (entry.requiresTeam && !capabilities.teamEnabled) continue;
688
+ if (entry.requiresCollective && !capabilities.collectiveConnected) continue;
689
+ lines.push(`- \`${entry.tool}\`: ${entry.guidance}`);
690
+ }
691
+ return lines;
692
+ }
693
+ function hashInput(value) {
694
+ return createHash(CONTENT_HASH_ALGORITHM).update(JSON.stringify(value)).digest("hex");
695
+ }
696
+ function truncatePreview(text, maxChars = CONTENT_PREVIEW_MAX_CHARS) {
697
+ if (!text) return null;
698
+ return text.length > maxChars ? `${text.slice(0, maxChars)}...` : text;
699
+ }
700
+ function formatRecentSessions() {
701
+ const sessions = listSessions({
702
+ includeActive: false,
703
+ limit: RECENT_SESSION_LIMIT
704
+ });
705
+ if (sessions.length === 0) return "No recent sessions are available.";
706
+ return sessions.map((session) => {
707
+ const head = `- ${session.title ?? session.id}${session.branch ? ` (branch=${session.branch})` : ""}`;
708
+ const body = truncatePreview(session.summary);
709
+ return body ? `${head}
710
+ ${body}` : head;
711
+ }).join("\n");
712
+ }
713
+ function formatSporesOfType(observationType, limit) {
714
+ const spores = listSpores({
715
+ observation_type: observationType,
716
+ includeActive: false,
717
+ status: "active",
718
+ limit
719
+ });
720
+ if (spores.length === 0) return `No recent ${observationType} spores are available.`;
721
+ return spores.map((spore) => {
722
+ const parts = [
723
+ `- ${truncatePreview(spore.content)}`,
724
+ spore.session_id ? `session=${spore.session_id}` : null
725
+ ].filter(Boolean);
726
+ return parts.join(" \u2014 ");
727
+ }).join("\n");
728
+ }
729
+ function formatRecentPlans() {
730
+ const plans = listPlans({
731
+ status: "active",
732
+ limit: RECENT_PLAN_LIMIT
733
+ });
734
+ if (plans.length === 0) return "No active plans are available.";
735
+ return plans.map((plan) => {
736
+ const parts = [
737
+ `- ${plan.title ?? plan.id}`,
738
+ `status=${plan.status}`,
739
+ truncatePreview(plan.content)
740
+ ].filter(Boolean);
741
+ return parts.join(" \u2014 ");
742
+ }).join("\n");
743
+ }
744
+ function formatDigestExcerpt(config) {
745
+ const preferredTier = config.context.digest_tier;
746
+ const extract = getDigestExtract(DEFAULT_AGENT_ID, preferredTier) ?? getDigestExtract(DEFAULT_AGENT_ID, DIGEST_FALLBACK_TIER);
747
+ if (!extract) return "No current digest extract is available.";
748
+ const excerpt = truncatePreview(extract.content, DIGEST_EXCERPT_MAX_CHARS) ?? "";
749
+ return excerpt ? `Tier ${extract.tier} digest excerpt:
750
+ ${excerpt}` : `Tier ${extract.tier} digest extract is empty.`;
751
+ }
752
+ async function buildCortexInstructionsInput(config, getTeamClient) {
753
+ const capabilities = await resolveCortexCapabilities(config, getTeamClient);
754
+ const capabilitySummary = buildCapabilitySummary(capabilities);
755
+ const retrievalGuidance = buildRetrievalGuidanceLines(capabilities);
756
+ const recentSessions = formatRecentSessions();
757
+ const recentWisdomSpores = formatSporesOfType("wisdom", RECENT_WISDOM_SPORE_LIMIT);
758
+ const recentDecisionSpores = formatSporesOfType("decision", RECENT_DECISION_SPORE_LIMIT);
759
+ const recentDiscoverySpores = formatSporesOfType("discovery", RECENT_DISCOVERY_SPORE_LIMIT);
760
+ const recentPlans = formatRecentPlans();
761
+ const digestExcerpt = formatDigestExcerpt(config);
762
+ const input = {
763
+ context: {
764
+ digest_tier: config.context.digest_tier,
765
+ cortex_enabled: config.context.cortex_enabled,
766
+ prompt_search: config.context.prompt_search,
767
+ prompt_max_spores: config.context.prompt_max_spores
768
+ },
769
+ capabilities,
770
+ digestExcerpt,
771
+ recentSessions,
772
+ recentWisdomSpores,
773
+ recentDecisionSpores,
774
+ recentDiscoverySpores,
775
+ recentPlans,
776
+ skillsNote: CORTEX_SKILLS_NOTE
777
+ };
778
+ return {
779
+ inputHash: hashInput(input),
780
+ instruction: [
781
+ "Author compact session-start instructions for another coding agent.",
782
+ "Focus on teaching how to use the highest-signal Myco tools correctly, especially retrieval and plan persistence.",
783
+ "Do not restate AGENTS.md or static installation details.",
784
+ "",
785
+ "## Runtime config",
786
+ JSON.stringify(input.context, null, JSON_INDENT),
787
+ "",
788
+ "## Authoring requirements",
789
+ "- Start with the heading `## Myco-Enabled Project`.",
790
+ "- Follow the heading with one brief sentence explaining that Myco provides project memory, prior decisions, plans, and retrieval tools for this repository.",
791
+ "- Teach the most useful current Myco MCP tool behavior, especially retrieval and plan persistence.",
792
+ "- Use the recent vault activity below to mention live project hotspots when that improves usefulness.",
793
+ `- ${CORTEX_SKILLS_NOTE}`,
794
+ "- Keep the heading and description brief so most of the budget goes to retrieval guidance.",
795
+ "- Keep the output compact and ready for direct injection.",
796
+ "",
797
+ "## Capability summary",
798
+ ...capabilitySummary,
799
+ "",
800
+ "## Tool guidance to encode",
801
+ ...retrievalGuidance,
802
+ "",
803
+ "## Current digest excerpt",
804
+ digestExcerpt,
805
+ "",
806
+ "## Recent sessions",
807
+ recentSessions,
808
+ "",
809
+ "## Recent wisdom spores",
810
+ recentWisdomSpores,
811
+ "",
812
+ "## Recent decision spores",
813
+ recentDecisionSpores,
814
+ "",
815
+ "## Recent discovery spores",
816
+ recentDiscoverySpores,
817
+ "",
818
+ "## Active plans",
819
+ recentPlans
820
+ ].join("\n")
821
+ };
822
+ }
823
+ async function buildScheduledCortexInstruction(config, getTeamClient) {
824
+ const built = await buildCortexInstructionsInput(config, getTeamClient);
825
+ const existing = getCortexInstructions(DEFAULT_AGENT_ID);
826
+ if (existing?.input_hash === built.inputHash) {
827
+ return void 0;
828
+ }
829
+ return built;
830
+ }
831
+
832
+ export {
833
+ upsertCortexInstructions,
834
+ getCortexInstructions,
835
+ upsertDigestExtract,
836
+ getDigestExtract,
837
+ listDigestExtracts,
838
+ listDigestRevisions,
839
+ rollbackDigestExtract,
840
+ upsertPlan,
841
+ getPlan,
842
+ getPlanByLogicalKey,
843
+ deletePlan,
844
+ listPlans,
845
+ listPlansBySession,
846
+ DEFAULT_IMPORTANCE,
847
+ insertSpore,
848
+ getSpore,
849
+ listSpores,
850
+ countSpores,
851
+ listSporeIdsSince,
852
+ updateSporeStatus,
853
+ shouldInjectCortex,
854
+ resolveInstructionDelivery,
855
+ buildCortexInstructionsInput,
856
+ buildScheduledCortexInstruction
857
+ };
858
+ //# sourceMappingURL=chunk-N7Z3LUEZ.js.map