@ouro.bot/cli 0.1.0-alpha.19 → 0.1.0-alpha.190

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 (202) hide show
  1. package/README.md +187 -191
  2. package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/agent.json +3 -2
  3. package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/SOUL.md +1 -1
  4. package/changelog.json +1280 -0
  5. package/dist/heart/active-work.js +832 -0
  6. package/dist/heart/bridges/manager.js +358 -0
  7. package/dist/heart/bridges/state-machine.js +135 -0
  8. package/dist/heart/bridges/store.js +123 -0
  9. package/dist/heart/cares.js +174 -0
  10. package/dist/heart/commitments.js +111 -0
  11. package/dist/heart/config.js +40 -30
  12. package/dist/heart/core.js +620 -124
  13. package/dist/heart/cross-chat-delivery.js +146 -0
  14. package/dist/heart/daemon/agent-discovery.js +81 -0
  15. package/dist/heart/daemon/agent-service.js +360 -0
  16. package/dist/heart/daemon/auth-flow.js +477 -0
  17. package/dist/heart/daemon/cadence.js +70 -0
  18. package/dist/heart/daemon/daemon-cli.js +2470 -210
  19. package/dist/heart/daemon/daemon-entry.js +157 -4
  20. package/dist/heart/daemon/daemon-health.js +136 -0
  21. package/dist/heart/daemon/daemon-runtime-sync.js +212 -0
  22. package/dist/heart/daemon/daemon-tombstone.js +123 -0
  23. package/dist/heart/daemon/daemon.js +449 -17
  24. package/dist/heart/daemon/habit-migration.js +181 -0
  25. package/dist/heart/daemon/habit-parser.js +119 -0
  26. package/dist/heart/daemon/habit-scheduler.js +369 -0
  27. package/dist/heart/daemon/hatch-flow.js +31 -112
  28. package/dist/heart/daemon/hatch-specialist.js +3 -3
  29. package/dist/heart/daemon/hooks/agent-config-v2.js +33 -0
  30. package/dist/heart/daemon/hooks/bundle-meta.js +92 -0
  31. package/dist/heart/daemon/inner-status.js +89 -0
  32. package/dist/heart/daemon/launchd.js +165 -0
  33. package/dist/heart/daemon/log-tailer.js +4 -3
  34. package/dist/heart/daemon/mcp-server.js +591 -0
  35. package/dist/heart/daemon/message-router.js +17 -8
  36. package/dist/heart/daemon/os-cron-deps.js +134 -0
  37. package/dist/heart/daemon/ouro-bot-global-installer.js +128 -0
  38. package/dist/heart/daemon/ouro-path-installer.js +78 -34
  39. package/dist/heart/daemon/ouro-version-manager.js +171 -0
  40. package/dist/heart/daemon/outlook-http.js +399 -0
  41. package/dist/heart/daemon/outlook-read.js +1331 -0
  42. package/dist/heart/daemon/outlook-render.js +1032 -0
  43. package/dist/heart/daemon/outlook-types.js +7 -0
  44. package/dist/heart/daemon/outlook-view.js +194 -0
  45. package/dist/heart/daemon/process-manager.js +75 -0
  46. package/dist/heart/daemon/run-hooks.js +39 -0
  47. package/dist/heart/daemon/runtime-logging.js +58 -15
  48. package/dist/heart/daemon/runtime-metadata.js +219 -0
  49. package/dist/heart/daemon/runtime-mode.js +67 -0
  50. package/dist/heart/daemon/safe-mode.js +161 -0
  51. package/dist/heart/daemon/sense-manager.js +50 -2
  52. package/dist/heart/daemon/session-id-resolver.js +131 -0
  53. package/dist/heart/daemon/skill-management-installer.js +94 -0
  54. package/dist/heart/daemon/socket-client.js +202 -0
  55. package/dist/heart/daemon/specialist-prompt.js +10 -7
  56. package/dist/heart/daemon/specialist-tools.js +49 -3
  57. package/dist/heart/daemon/staged-restart.js +114 -0
  58. package/dist/heart/daemon/task-scheduler.js +3 -25
  59. package/dist/heart/daemon/thoughts.js +507 -0
  60. package/dist/heart/daemon/update-checker.js +111 -0
  61. package/dist/heart/daemon/update-hooks.js +138 -0
  62. package/dist/heart/daemon/wrapper-publish-guard.js +86 -0
  63. package/dist/heart/delegation.js +62 -0
  64. package/dist/heart/identity.js +136 -55
  65. package/dist/heart/intentions.js +168 -0
  66. package/dist/heart/kicks.js +2 -20
  67. package/dist/heart/migrate-config.js +127 -0
  68. package/dist/heart/model-capabilities.js +48 -0
  69. package/dist/heart/obligations.js +220 -0
  70. package/dist/heart/presence.js +185 -0
  71. package/dist/heart/progress-story.js +42 -0
  72. package/dist/heart/provider-failover.js +88 -0
  73. package/dist/heart/provider-ping.js +172 -0
  74. package/dist/heart/providers/anthropic-token.js +163 -0
  75. package/dist/heart/providers/anthropic.js +187 -41
  76. package/dist/heart/providers/azure.js +116 -10
  77. package/dist/heart/providers/github-copilot.js +157 -0
  78. package/dist/heart/providers/minimax.js +33 -3
  79. package/dist/heart/providers/openai-codex.js +51 -16
  80. package/dist/heart/session-activity.js +172 -0
  81. package/dist/heart/session-recall.js +216 -0
  82. package/dist/heart/streaming.js +36 -27
  83. package/dist/heart/target-resolution.js +127 -0
  84. package/dist/heart/tempo.js +93 -0
  85. package/dist/heart/temporal-view.js +41 -0
  86. package/dist/heart/tool-activity-callbacks.js +36 -0
  87. package/dist/heart/tool-description.js +135 -0
  88. package/dist/heart/tool-loop.js +200 -0
  89. package/dist/heart/turn-coordinator.js +28 -0
  90. package/dist/heart/wake-packet.js +226 -0
  91. package/dist/mind/associative-recall.js +122 -32
  92. package/dist/mind/bundle-manifest.js +14 -0
  93. package/dist/mind/context.js +125 -14
  94. package/dist/mind/{memory.js → diary.js} +70 -56
  95. package/dist/mind/episodes.js +116 -0
  96. package/dist/mind/file-state.js +179 -0
  97. package/dist/mind/first-impressions.js +16 -2
  98. package/dist/mind/friends/channel.js +56 -0
  99. package/dist/mind/friends/group-context.js +144 -0
  100. package/dist/mind/friends/store-file.js +36 -0
  101. package/dist/mind/friends/trust-explanation.js +74 -0
  102. package/dist/mind/friends/types.js +8 -0
  103. package/dist/mind/journal-index.js +161 -0
  104. package/dist/mind/obligation-steering.js +221 -0
  105. package/dist/mind/obligations.js +134 -0
  106. package/dist/mind/pending.js +76 -9
  107. package/dist/mind/phrases.js +1 -0
  108. package/dist/mind/prompt.js +779 -102
  109. package/dist/mind/scrutiny.js +173 -0
  110. package/dist/mind/token-estimate.js +8 -12
  111. package/dist/nerves/coverage/audit.js +1 -1
  112. package/dist/nerves/coverage/run-artifacts.js +1 -1
  113. package/dist/nerves/event-buffer.js +111 -0
  114. package/dist/nerves/index.js +63 -3
  115. package/dist/nerves/observation.js +20 -0
  116. package/dist/nerves/runtime.js +5 -1
  117. package/dist/outlook-ui/assets/index-DN6vVYPm.css +1 -0
  118. package/dist/outlook-ui/assets/index-M1l1tDTX.js +61 -0
  119. package/dist/outlook-ui/index.html +15 -0
  120. package/dist/repertoire/ado-semantic.js +11 -5
  121. package/dist/repertoire/coding/codex-jsonl.js +64 -0
  122. package/dist/repertoire/coding/context-pack.js +330 -0
  123. package/dist/repertoire/coding/feedback.js +197 -30
  124. package/dist/repertoire/coding/manager.js +149 -2
  125. package/dist/repertoire/coding/spawner.js +55 -9
  126. package/dist/repertoire/coding/tools.js +170 -7
  127. package/dist/repertoire/guardrails.js +291 -0
  128. package/dist/repertoire/mcp-client.js +254 -0
  129. package/dist/repertoire/mcp-manager.js +198 -0
  130. package/dist/repertoire/shell-sessions.js +133 -0
  131. package/dist/repertoire/skills.js +14 -23
  132. package/dist/repertoire/tasks/board.js +43 -5
  133. package/dist/repertoire/tasks/fix.js +182 -0
  134. package/dist/repertoire/tasks/index.js +28 -10
  135. package/dist/repertoire/tasks/lifecycle.js +2 -2
  136. package/dist/repertoire/tasks/parser.js +3 -2
  137. package/dist/repertoire/tasks/scanner.js +194 -37
  138. package/dist/repertoire/tasks/transitions.js +11 -28
  139. package/dist/repertoire/tools-base.js +1345 -320
  140. package/dist/repertoire/tools-bluebubbles.js +94 -0
  141. package/dist/repertoire/tools-github.js +1 -6
  142. package/dist/repertoire/tools-teams.js +12 -59
  143. package/dist/repertoire/tools.js +318 -124
  144. package/dist/scripts/claude-code-hook.js +41 -0
  145. package/dist/scripts/claude-code-stop-hook.js +47 -0
  146. package/dist/senses/attention-queue.js +97 -0
  147. package/dist/senses/bluebubbles-client.js +102 -3
  148. package/dist/senses/bluebubbles-entry.js +2 -0
  149. package/dist/senses/bluebubbles-inbound-log.js +109 -0
  150. package/dist/senses/bluebubbles-media.js +118 -23
  151. package/dist/senses/bluebubbles-model.js +12 -4
  152. package/dist/senses/bluebubbles-mutation-log.js +45 -5
  153. package/dist/senses/bluebubbles-runtime-state.js +109 -0
  154. package/dist/senses/bluebubbles-session-cleanup.js +72 -0
  155. package/dist/senses/bluebubbles.js +1008 -102
  156. package/dist/senses/cli/adapter.js +274 -0
  157. package/dist/senses/cli/ink-app.js +156 -0
  158. package/dist/senses/cli/inline-diff.js +64 -0
  159. package/dist/senses/cli/message-list.js +51 -0
  160. package/dist/senses/cli/ouro-tui.js +349 -0
  161. package/dist/senses/cli/spinner-imperative.js +135 -0
  162. package/dist/senses/cli/spinner.js +101 -0
  163. package/dist/senses/cli/status-line.js +60 -0
  164. package/dist/senses/cli/streaming-markdown.js +526 -0
  165. package/dist/senses/cli/tool-display.js +83 -0
  166. package/dist/senses/cli/tool-render.js +85 -0
  167. package/dist/senses/cli/tui-store.js +198 -0
  168. package/dist/senses/cli/virtual-list.js +35 -0
  169. package/dist/senses/cli-entry.js +1 -1
  170. package/dist/senses/cli-layout.js +187 -0
  171. package/dist/senses/cli.js +508 -243
  172. package/dist/senses/commands.js +65 -1
  173. package/dist/senses/continuity.js +94 -0
  174. package/dist/senses/habit-turn-message.js +108 -0
  175. package/dist/senses/inner-dialog-worker.js +112 -19
  176. package/dist/senses/inner-dialog.js +592 -84
  177. package/dist/senses/pipeline.js +633 -0
  178. package/dist/senses/shared-turn.js +196 -0
  179. package/dist/senses/surface-tool.js +95 -0
  180. package/dist/senses/teams.js +667 -120
  181. package/dist/senses/trust-gate.js +112 -2
  182. package/package.json +16 -6
  183. package/skills/configure-dev-tools.md +81 -0
  184. package/subagents/README.md +4 -70
  185. package/dist/heart/daemon/subagent-installer.js +0 -134
  186. package/dist/senses/debug-activity.js +0 -107
  187. package/subagents/work-doer.md +0 -235
  188. package/subagents/work-merger.md +0 -618
  189. package/subagents/work-planner.md +0 -382
  190. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/basilisk.md +0 -0
  191. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/jafar.md +0 -0
  192. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/jormungandr.md +0 -0
  193. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/kaa.md +0 -0
  194. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/medusa.md +0 -0
  195. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/monty.md +0 -0
  196. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/nagini.md +0 -0
  197. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/ouroboros.md +0 -0
  198. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/python.md +0 -0
  199. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/quetzalcoatl.md +0 -0
  200. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/sir-hiss.md +0 -0
  201. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-serpent.md +0 -0
  202. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-snake.md +0 -0
@@ -0,0 +1,15 @@
1
+ <!doctype html>
2
+ <html lang="en" class="dark">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <meta name="color-scheme" content="dark" />
7
+ <title>Ouro Outlook</title>
8
+ <meta name="description" content="The daemon-hosted shared orientation surface for agents alive on this machine." />
9
+ <script type="module" crossorigin src="/assets/index-M1l1tDTX.js"></script>
10
+ <link rel="stylesheet" crossorigin href="/assets/index-DN6vVYPm.css">
11
+ </head>
12
+ <body>
13
+ <div id="app"></div>
14
+ </body>
15
+ </html>
@@ -221,7 +221,7 @@ exports.adoSemanticToolDefinitions = [
221
221
  type: "function",
222
222
  function: {
223
223
  name: "ado_backlog_list",
224
- description: "Query the backlog and return enriched work items with hierarchy, type, parent, assignee, area path, and iteration. Supports filtering. Use this instead of raw WIQL queries.",
224
+ description: "Query the backlog and return enriched work items with hierarchy, type, parent, assignee, area path, and iteration. Supports filtering. Use this instead of raw WIQL queries. Provides enriched results with hierarchy.",
225
225
  parameters: {
226
226
  type: "object",
227
227
  properties: {
@@ -279,6 +279,7 @@ exports.adoSemanticToolDefinitions = [
279
279
  return formatForChannel(items, ctx, organization, project);
280
280
  },
281
281
  integration: "ado",
282
+ summaryKeys: ["organization", "project"],
282
283
  },
283
284
  // -- ado_create_epic --
284
285
  {
@@ -286,7 +287,7 @@ exports.adoSemanticToolDefinitions = [
286
287
  type: "function",
287
288
  function: {
288
289
  name: "ado_create_epic",
289
- description: "Create an epic in Azure DevOps with title, description, area path, and optional parent.",
290
+ description: "Create an epic in Azure DevOps with title, description, area path, and optional parent. Use ado_preview_changes first to dry-run the operation.",
290
291
  parameters: {
291
292
  type: "object",
292
293
  properties: {
@@ -318,6 +319,7 @@ exports.adoSemanticToolDefinitions = [
318
319
  },
319
320
  integration: "ado",
320
321
  confirmationRequired: true,
322
+ summaryKeys: ["organization", "project", "title"],
321
323
  },
322
324
  // -- ado_create_issue --
323
325
  {
@@ -325,7 +327,7 @@ exports.adoSemanticToolDefinitions = [
325
327
  type: "function",
326
328
  function: {
327
329
  name: "ado_create_issue",
328
- description: "Create an issue or user story in Azure DevOps with title, description, area path, and parent epic.",
330
+ description: "Create an issue or user story in Azure DevOps with title, description, area path, and parent epic. Use ado_preview_changes first to dry-run the operation.",
329
331
  parameters: {
330
332
  type: "object",
331
333
  properties: {
@@ -359,6 +361,7 @@ exports.adoSemanticToolDefinitions = [
359
361
  },
360
362
  integration: "ado",
361
363
  confirmationRequired: true,
364
+ summaryKeys: ["organization", "project", "title"],
362
365
  },
363
366
  // -- ado_move_items --
364
367
  {
@@ -366,7 +369,7 @@ exports.adoSemanticToolDefinitions = [
366
369
  type: "function",
367
370
  function: {
368
371
  name: "ado_move_items",
369
- description: "Reparent work items -- move them to a new parent epic or feature.",
372
+ description: "Reparent work items -- move them to a new parent epic or feature. Use ado_preview_changes first. These mutations affect real work items.",
370
373
  parameters: {
371
374
  type: "object",
372
375
  properties: {
@@ -413,6 +416,7 @@ exports.adoSemanticToolDefinitions = [
413
416
  },
414
417
  integration: "ado",
415
418
  confirmationRequired: true,
419
+ summaryKeys: ["organization", "project", "workItemIds"],
416
420
  },
417
421
  // -- ado_restructure_backlog --
418
422
  {
@@ -420,7 +424,7 @@ exports.adoSemanticToolDefinitions = [
420
424
  type: "function",
421
425
  function: {
422
426
  name: "ado_restructure_backlog",
423
- description: "Bulk restructure: reparent multiple work items in a single logical operation.",
427
+ description: "Bulk restructure: reparent multiple work items in a single logical operation. Use ado_preview_changes first. These mutations affect real work items.",
424
428
  parameters: {
425
429
  type: "object",
426
430
  properties: {
@@ -471,6 +475,7 @@ exports.adoSemanticToolDefinitions = [
471
475
  },
472
476
  integration: "ado",
473
477
  confirmationRequired: true,
478
+ summaryKeys: ["organization", "project"],
474
479
  },
475
480
  // -- ado_validate_structure --
476
481
  {
@@ -672,6 +677,7 @@ exports.adoSemanticToolDefinitions = [
672
677
  },
673
678
  integration: "ado",
674
679
  confirmationRequired: true,
680
+ summaryKeys: ["organization", "project"],
675
681
  },
676
682
  // -- ado_detect_orphans --
677
683
  {
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ /**
3
+ * Codex JSONL event parser.
4
+ * Parses typed events from Codex --json output:
5
+ * thread.started, turn.started, turn.completed, item.completed.
6
+ * Maps events to coding session status transitions.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.parseCodexJsonlEvent = parseCodexJsonlEvent;
10
+ const runtime_1 = require("../../nerves/runtime");
11
+ const KNOWN_TYPES = new Set(["thread.started", "turn.started", "turn.completed", "item.completed"]);
12
+ /**
13
+ * Parse a single JSONL line from Codex --json output.
14
+ * Returns null for invalid JSON, empty strings, or unknown event types.
15
+ */
16
+ function parseCodexJsonlEvent(line) {
17
+ const trimmed = line.trim();
18
+ if (trimmed.length === 0)
19
+ return null;
20
+ let parsed;
21
+ try {
22
+ parsed = JSON.parse(trimmed);
23
+ }
24
+ catch {
25
+ (0, runtime_1.emitNervesEvent)({
26
+ component: "repertoire",
27
+ event: "repertoire.codex_jsonl_parse_error",
28
+ message: "failed to parse codex JSONL line",
29
+ meta: { line: trimmed.slice(0, 100) },
30
+ });
31
+ return null;
32
+ }
33
+ const type = parsed.type;
34
+ if (!type || !KNOWN_TYPES.has(type))
35
+ return null;
36
+ const event = {
37
+ type: type,
38
+ threadId: typeof parsed.thread_id === "string" ? parsed.thread_id : undefined,
39
+ turnId: typeof parsed.turn_id === "string" ? parsed.turn_id : undefined,
40
+ item: typeof parsed.item === "object" && parsed.item !== null ? parsed.item : undefined,
41
+ raw: parsed,
42
+ statusHint: mapStatusHint(type),
43
+ };
44
+ (0, runtime_1.emitNervesEvent)({
45
+ component: "repertoire",
46
+ event: "repertoire.codex_jsonl_event",
47
+ message: "parsed codex JSONL event",
48
+ meta: { type, threadId: event.threadId ?? null },
49
+ });
50
+ return event;
51
+ }
52
+ function mapStatusHint(type) {
53
+ switch (type) {
54
+ case "thread.started":
55
+ case "turn.started":
56
+ return "running";
57
+ case "turn.completed":
58
+ case "item.completed":
59
+ return null; // No automatic status change for completion events
60
+ /* v8 ignore next -- defensive default for unknown event types */
61
+ default:
62
+ return null;
63
+ }
64
+ }
@@ -0,0 +1,330 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.prepareCodingContextPack = prepareCodingContextPack;
37
+ exports.emitCodingEpisode = emitCodingEpisode;
38
+ const crypto = __importStar(require("crypto"));
39
+ const fs = __importStar(require("fs"));
40
+ const path = __importStar(require("path"));
41
+ const child_process_1 = require("child_process");
42
+ const active_work_1 = require("../../heart/active-work");
43
+ const identity_1 = require("../../heart/identity");
44
+ const runtime_1 = require("../../nerves/runtime");
45
+ const episodes_1 = require("../../mind/episodes");
46
+ const skills_1 = require("../skills");
47
+ const CONTEXT_FILENAMES = ["AGENTS.md", "CLAUDE.md"];
48
+ function defaultRunCommand(command, args, cwd) {
49
+ const result = (0, child_process_1.spawnSync)(command, args, {
50
+ cwd,
51
+ encoding: "utf-8",
52
+ });
53
+ return {
54
+ status: result.status ?? 1,
55
+ stdout: typeof result.stdout === "string" ? result.stdout : "",
56
+ stderr: typeof result.stderr === "string" ? result.stderr : "",
57
+ };
58
+ }
59
+ function stableContextKey(request) {
60
+ const payload = JSON.stringify({
61
+ runner: request.runner,
62
+ workdir: request.workdir,
63
+ taskRef: request.taskRef ?? "",
64
+ parentAgent: request.parentAgent ?? "",
65
+ obligationId: request.obligationId ?? "",
66
+ originSession: request.originSession ?? null,
67
+ });
68
+ return crypto.createHash("sha1").update(payload).digest("hex").slice(0, 12);
69
+ }
70
+ function collectProjectContextFiles(workdir, deps) {
71
+ const files = [];
72
+ const seen = new Set();
73
+ let current = path.resolve(workdir);
74
+ const root = path.parse(current).root;
75
+ while (true) {
76
+ for (const filename of CONTEXT_FILENAMES) {
77
+ const candidate = path.join(current, filename);
78
+ if (!deps.existsSync(candidate) || seen.has(candidate))
79
+ continue;
80
+ try {
81
+ const content = deps.readFileSync(candidate, "utf-8").trim();
82
+ if (content.length > 0) {
83
+ files.unshift({ path: candidate, content });
84
+ seen.add(candidate);
85
+ }
86
+ }
87
+ catch {
88
+ // Best-effort loading only.
89
+ }
90
+ }
91
+ if (current === root)
92
+ break;
93
+ current = path.dirname(current);
94
+ }
95
+ return files;
96
+ }
97
+ function captureRepoSnapshot(workdir, runCommand) {
98
+ const repoRoot = runCommand("git", ["rev-parse", "--show-toplevel"], workdir);
99
+ if (repoRoot.status !== 0) {
100
+ return {
101
+ available: false,
102
+ repoRoot: null,
103
+ branch: null,
104
+ head: null,
105
+ statusLines: [],
106
+ };
107
+ }
108
+ const branch = runCommand("git", ["rev-parse", "--abbrev-ref", "HEAD"], workdir);
109
+ const head = runCommand("git", ["rev-parse", "--short", "HEAD"], workdir);
110
+ const status = runCommand("git", ["status", "--short"], workdir);
111
+ return {
112
+ available: true,
113
+ repoRoot: repoRoot.stdout.trim() || null,
114
+ branch: branch.status === 0 ? branch.stdout.trim() || null : null,
115
+ head: head.status === 0 ? head.stdout.trim() || null : null,
116
+ statusLines: status.status === 0
117
+ ? status.stdout.split(/\r?\n/).map((line) => line.trimEnd()).filter(Boolean)
118
+ : [],
119
+ };
120
+ }
121
+ function buildIdentityPacket(snapshot, request) {
122
+ if (!snapshot.available) {
123
+ return {
124
+ repoPath: null,
125
+ worktreePath: null,
126
+ branch: null,
127
+ commit: null,
128
+ dirty: false,
129
+ dirtyFiles: [],
130
+ taskRef: request.taskRef ?? null,
131
+ verificationCommands: request.verificationCommands ?? [],
132
+ verificationStatus: "not-verified",
133
+ };
134
+ }
135
+ const dirtyFiles = snapshot.statusLines.filter((line) => line.length > 0);
136
+ return {
137
+ repoPath: snapshot.repoRoot,
138
+ worktreePath: snapshot.repoRoot,
139
+ branch: snapshot.branch,
140
+ commit: snapshot.head,
141
+ dirty: dirtyFiles.length > 0,
142
+ dirtyFiles,
143
+ taskRef: request.taskRef ?? null,
144
+ verificationCommands: request.verificationCommands ?? [],
145
+ verificationStatus: "not-verified",
146
+ };
147
+ }
148
+ function formatIdentitySection(packet) {
149
+ const lines = [
150
+ "## Coding Identity",
151
+ `repoPath: ${packet.repoPath ?? "unknown"}`,
152
+ `worktreePath: ${packet.worktreePath ?? "unknown"}`,
153
+ `branch: ${packet.branch ?? "unknown"}`,
154
+ `commit: ${packet.commit ?? "unknown"}`,
155
+ `dirty: ${packet.dirty}`,
156
+ ];
157
+ if (packet.dirtyFiles.length > 0) {
158
+ lines.push("dirtyFiles:");
159
+ for (const file of packet.dirtyFiles) {
160
+ lines.push(file);
161
+ }
162
+ }
163
+ lines.push(`taskRef: ${packet.taskRef ?? "none"}`);
164
+ if (packet.verificationCommands.length > 0) {
165
+ lines.push(`verificationCommands: ${packet.verificationCommands.join(", ")}`);
166
+ }
167
+ lines.push(`verificationStatus: ${packet.verificationStatus}`);
168
+ return lines.join("\n");
169
+ }
170
+ function formatContextFiles(files) {
171
+ if (files.length === 0)
172
+ return "(none found)";
173
+ return files.map((file) => `### ${file.path}\n${file.content}`).join("\n\n");
174
+ }
175
+ function formatSkills(skills) {
176
+ return skills.length > 0 ? skills.join(", ") : "(none found)";
177
+ }
178
+ function formatExistingSessions(sessions) {
179
+ if (sessions.length === 0)
180
+ return "activeSessions: none";
181
+ return sessions
182
+ .map((session) => {
183
+ return [
184
+ `- ${session.id}`,
185
+ `status=${session.status}`,
186
+ `lastActivityAt=${session.lastActivityAt}`,
187
+ session.taskRef ? `taskRef=${session.taskRef}` : null,
188
+ session.checkpoint ? `checkpoint=${session.checkpoint}` : null,
189
+ session.artifactPath ? `artifact=${session.artifactPath}` : null,
190
+ ].filter(Boolean).join(" ");
191
+ })
192
+ .join("\n");
193
+ }
194
+ function formatOrigin(request) {
195
+ if (!request.originSession)
196
+ return "originSession: none";
197
+ return `originSession: ${request.originSession.channel}/${request.originSession.key} (${request.originSession.friendId})`;
198
+ }
199
+ function buildScopeContent(request, contextFiles, skills, agentName) {
200
+ return [
201
+ "# Coding Session Scope",
202
+ "",
203
+ "## Request",
204
+ `runner: ${request.runner}`,
205
+ `taskRef: ${request.taskRef ?? "unassigned"}`,
206
+ `parentAgent: ${request.parentAgent ?? agentName}`,
207
+ `workdir: ${request.workdir}`,
208
+ formatOrigin(request),
209
+ `obligationId: ${request.obligationId ?? "none"}`,
210
+ "",
211
+ "## Prompt",
212
+ request.prompt,
213
+ "",
214
+ "## Session Contract",
215
+ "- This is a focused coding lane opened by the parent Ouro agent.",
216
+ "- Execute the concrete prompt in the supplied workdir directly.",
217
+ "- Do not switch into planning/doing workflows or approval gates unless the prompt explicitly asks for them.",
218
+ "- Treat the current prompt, scope file, and live world-state checkpoint in the state file as the authoritative briefing for this lane.",
219
+ "",
220
+ "## Project Context Files",
221
+ formatContextFiles(contextFiles),
222
+ "",
223
+ "## Available Bundle Skills",
224
+ formatSkills(skills),
225
+ ].join("\n");
226
+ }
227
+ function buildStateContent(request, contextKey, generatedAt, snapshot, existingSessions, agentName, identityPacket, activeWorkFrame, wakePacket) {
228
+ const gitSection = snapshot.available
229
+ ? [
230
+ `repoRoot: ${snapshot.repoRoot ?? "unknown"}`,
231
+ `branch: ${snapshot.branch ?? "unknown"}`,
232
+ `head: ${snapshot.head ?? "unknown"}`,
233
+ "status:",
234
+ snapshot.statusLines.length > 0 ? snapshot.statusLines.join("\n") : "(clean)",
235
+ ].join("\n")
236
+ : "git: unavailable";
237
+ return [
238
+ "# Coding Session State",
239
+ `generatedAt: ${generatedAt}`,
240
+ `contextKey: ${contextKey}`,
241
+ `agent: ${request.parentAgent ?? agentName}`,
242
+ formatOrigin(request),
243
+ `obligationId: ${request.obligationId ?? "none"}`,
244
+ ...(wakePacket ? ["", "## Continuity", wakePacket] : []),
245
+ "",
246
+ formatIdentitySection(identityPacket),
247
+ "",
248
+ "## Workspace Snapshot",
249
+ gitSection,
250
+ ...(activeWorkFrame ? ["", (0, active_work_1.formatLiveWorldStateCheckpoint)(activeWorkFrame)] : []),
251
+ "",
252
+ "## Related Coding Sessions",
253
+ formatExistingSessions(existingSessions),
254
+ ].join("\n");
255
+ }
256
+ function relatedSessions(request, existingSessions) {
257
+ return existingSessions.filter((session) => {
258
+ return session.runner === request.runner
259
+ && session.workdir === request.workdir
260
+ && session.taskRef === request.taskRef;
261
+ });
262
+ }
263
+ function prepareCodingContextPack(input, deps = {}) {
264
+ const agentRoot = deps.agentRoot ?? (0, identity_1.getAgentRoot)();
265
+ const agentName = deps.agentName ?? (0, identity_1.getAgentName)();
266
+ const nowIso = deps.nowIso ?? (() => new Date().toISOString());
267
+ const existsSync = deps.existsSync ?? fs.existsSync;
268
+ const readFileSync = deps.readFileSync ?? fs.readFileSync;
269
+ const writeFileSync = deps.writeFileSync ?? fs.writeFileSync;
270
+ const mkdirSync = deps.mkdirSync ?? fs.mkdirSync;
271
+ const listAvailableSkills = deps.listSkills ?? skills_1.listSkills;
272
+ const runCommand = deps.runCommand ?? defaultRunCommand;
273
+ const contextKey = stableContextKey(input.request);
274
+ const contextDir = path.join(agentRoot, "state", "coding", "context");
275
+ const scopeFile = path.join(contextDir, `${contextKey}-scope.md`);
276
+ const stateFile = path.join(contextDir, `${contextKey}-state.md`);
277
+ const contextFiles = collectProjectContextFiles(input.request.workdir, { existsSync, readFileSync });
278
+ const skills = listAvailableSkills();
279
+ const existingSessions = relatedSessions(input.request, input.existingSessions ?? []);
280
+ const snapshot = captureRepoSnapshot(input.request.workdir, runCommand);
281
+ const generatedAt = nowIso();
282
+ const identityPacket = buildIdentityPacket(snapshot, input.request);
283
+ const scopeContent = buildScopeContent(input.request, contextFiles, skills, agentName);
284
+ const stateContent = buildStateContent(input.request, contextKey, generatedAt, snapshot, existingSessions, agentName, identityPacket, input.activeWorkFrame, input.wakePacket || undefined);
285
+ mkdirSync(contextDir, { recursive: true });
286
+ writeFileSync(scopeFile, `${scopeContent}\n`, "utf-8");
287
+ writeFileSync(stateFile, `${stateContent}\n`, "utf-8");
288
+ (0, runtime_1.emitNervesEvent)({
289
+ component: "repertoire",
290
+ event: "repertoire.coding_context_pack_written",
291
+ message: "prepared coding session context pack",
292
+ meta: {
293
+ contextKey,
294
+ workdir: input.request.workdir,
295
+ taskRef: input.request.taskRef ?? null,
296
+ contextFiles: contextFiles.length,
297
+ skills: skills.length,
298
+ relatedSessions: existingSessions.length,
299
+ gitAvailable: snapshot.available,
300
+ },
301
+ });
302
+ return {
303
+ contextKey,
304
+ scopeFile,
305
+ stateFile,
306
+ scopeContent,
307
+ stateContent,
308
+ identityPacket,
309
+ };
310
+ }
311
+ /**
312
+ * Emit a coding milestone episode when a session completes or blocks.
313
+ * This is the outbound leg of the coding round-trip: compact wake packet goes IN,
314
+ * episodes come BACK OUT.
315
+ */
316
+ function emitCodingEpisode(agentRoot, session, outcome) {
317
+ (0, episodes_1.emitEpisode)(agentRoot, {
318
+ kind: "coding_milestone",
319
+ summary: `coding session ${session.id} (${session.runner}): ${outcome}`,
320
+ whyItMattered: `coding lane ${session.status}`,
321
+ relatedEntities: [`coding:${session.id}`],
322
+ salience: session.status === "failed" ? "high" : "medium",
323
+ });
324
+ (0, runtime_1.emitNervesEvent)({
325
+ component: "repertoire",
326
+ event: "repertoire.coding_episode_emitted",
327
+ message: `coding episode emitted for ${session.id}`,
328
+ meta: { sessionId: session.id, outcome, status: session.status },
329
+ });
330
+ }