greprag 5.59.4 → 5.60.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 (81) hide show
  1. package/dist/commands/arm-reminder.d.ts +5 -0
  2. package/dist/commands/arm-reminder.js +11 -0
  3. package/dist/commands/arm-reminder.js.map +1 -1
  4. package/dist/commands/codex-chip/breakthrough-ack-command.d.ts +1 -0
  5. package/dist/commands/codex-chip/breakthrough-ack-command.js +25 -0
  6. package/dist/commands/codex-chip/breakthrough-ack-command.js.map +1 -0
  7. package/dist/commands/codex-chip/breakthrough-command.d.ts +5 -0
  8. package/dist/commands/codex-chip/breakthrough-command.js +46 -0
  9. package/dist/commands/codex-chip/breakthrough-command.js.map +1 -0
  10. package/dist/commands/codex-chip/breakthrough.d.ts +15 -0
  11. package/dist/commands/codex-chip/breakthrough.js +147 -0
  12. package/dist/commands/codex-chip/breakthrough.js.map +1 -0
  13. package/dist/commands/codex-chip/cleanup-command.js +11 -1
  14. package/dist/commands/codex-chip/cleanup-command.js.map +1 -1
  15. package/dist/commands/codex-chip/command.d.ts +1 -1
  16. package/dist/commands/codex-chip/command.js +48 -84
  17. package/dist/commands/codex-chip/command.js.map +1 -1
  18. package/dist/commands/codex-chip/goal-command.js +27 -4
  19. package/dist/commands/codex-chip/goal-command.js.map +1 -1
  20. package/dist/commands/codex-chip/goals.d.ts +15 -2
  21. package/dist/commands/codex-chip/goals.js +157 -9
  22. package/dist/commands/codex-chip/goals.js.map +1 -1
  23. package/dist/commands/codex-chip/help.d.ts +1 -0
  24. package/dist/commands/codex-chip/help.js +34 -0
  25. package/dist/commands/codex-chip/help.js.map +1 -0
  26. package/dist/commands/codex-chip/inbox.d.ts +1 -1
  27. package/dist/commands/codex-chip/inbox.js +5 -3
  28. package/dist/commands/codex-chip/inbox.js.map +1 -1
  29. package/dist/commands/codex-chip/mechanic-lifecycle.d.ts +5 -0
  30. package/dist/commands/codex-chip/mechanic-lifecycle.js +67 -0
  31. package/dist/commands/codex-chip/mechanic-lifecycle.js.map +1 -0
  32. package/dist/commands/codex-chip/model.d.ts +39 -1
  33. package/dist/commands/codex-chip/model.js +6 -0
  34. package/dist/commands/codex-chip/model.js.map +1 -1
  35. package/dist/commands/codex-chip/naming.d.ts +2 -2
  36. package/dist/commands/codex-chip/naming.js +8 -5
  37. package/dist/commands/codex-chip/naming.js.map +1 -1
  38. package/dist/commands/codex-chip/native.js +5 -1
  39. package/dist/commands/codex-chip/native.js.map +1 -1
  40. package/dist/commands/codex-chip/prompt.js +22 -2
  41. package/dist/commands/codex-chip/prompt.js.map +1 -1
  42. package/dist/commands/codex-chip/resume-command.js +3 -0
  43. package/dist/commands/codex-chip/resume-command.js.map +1 -1
  44. package/dist/commands/codex-chip/selection.d.ts +6 -3
  45. package/dist/commands/codex-chip/selection.js +81 -27
  46. package/dist/commands/codex-chip/selection.js.map +1 -1
  47. package/dist/commands/codex-chip/worker.js +19 -0
  48. package/dist/commands/codex-chip/worker.js.map +1 -1
  49. package/dist/commands/codex-delivery.d.ts +7 -1
  50. package/dist/commands/codex-delivery.js +98 -15
  51. package/dist/commands/codex-delivery.js.map +1 -1
  52. package/dist/commands/codex-native-delivery.d.ts +70 -0
  53. package/dist/commands/codex-native-delivery.js +285 -0
  54. package/dist/commands/codex-native-delivery.js.map +1 -0
  55. package/dist/commands/codex-startup.js +1 -1
  56. package/dist/commands/codex-startup.js.map +1 -1
  57. package/dist/commands/codex.js +17 -12
  58. package/dist/commands/codex.js.map +1 -1
  59. package/dist/commands/docptr.js +4 -4
  60. package/dist/commands/docptr.js.map +1 -1
  61. package/dist/commands/inbox-primer-reminder.js +2 -2
  62. package/dist/commands/inbox-primer-reminder.js.map +1 -1
  63. package/dist/commands/init.js +1 -1
  64. package/dist/commands/load-primer-reminder.js +2 -2
  65. package/dist/commands/load-primer-reminder.js.map +1 -1
  66. package/dist/commands/load.js +2 -2
  67. package/dist/commands/load.js.map +1 -1
  68. package/dist/index.js +96 -1
  69. package/dist/index.js.map +1 -1
  70. package/dist/opencode-plugin.bundle.js +4 -4
  71. package/dist/procedure-run.js +5 -5
  72. package/dist/procedure-run.js.map +1 -1
  73. package/dist/session-id.d.ts +4 -0
  74. package/dist/session-id.js +13 -0
  75. package/dist/session-id.js.map +1 -1
  76. package/package.json +1 -1
  77. package/skill/greprag/SKILL.md +1 -1
  78. package/skill/greprag/docs/codex-chip.md +10 -8
  79. package/skill/greprag/docs/setup.md +6 -6
  80. package/skill/templates/chip-leader.md +9 -6
  81. package/skill/templates/codex-chip-spawn.md +46 -32
@@ -19,6 +19,11 @@ export declare function armDetect(env: ReminderEnv): Detection;
19
19
  * + the forced-decision are the reminder-interrupt doctrine's two missing rules
20
20
  * (docs/reminder-interrupt.md: reason · live-grounding · forced-decision · loud). */
21
21
  export declare function buildArmReminder(d: Detection, env?: ReminderEnv): string | null;
22
+ /** Compatibility formatter for integrations that still request the original
23
+ * SessionStart announce. The live registry now uses buildInboxPrimer, but
24
+ * retaining this pure export keeps older hook callers from crashing while
25
+ * preserving the same copyable Monitor command. */
26
+ export declare function buildArmAnnounce(short: string, ownerPid?: number | null, alias?: string | null): string;
22
27
  /** The reference module — now REMINDER-ONLY. No SessionStart announce: arming is taught
23
28
  * once by the inbox-primer (the single announce line). This stays the per-turn poke that
24
29
  * fires while unarmed and auto-silences when armed. Wired into reminder-registry.ts. */
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.watcherArmModule = void 0;
10
10
  exports.armDetect = armDetect;
11
11
  exports.buildArmReminder = buildArmReminder;
12
+ exports.buildArmAnnounce = buildArmAnnounce;
12
13
  const session_id_1 = require("../session-id");
13
14
  // SessionStart arming guidance lives in the inbox-primer now (the ONE announce line,
14
15
  // carrying the Monitor how-to). This module is REMINDER-ONLY — the per-turn poke when
@@ -47,6 +48,16 @@ function buildArmReminder(d, env) {
47
48
  }
48
49
  return `⚠ UNARMED — ${grounded}. You're invisible; messages pile up silently. Re-arm now, or state why you're choosing to stay dark: ${arm}.`;
49
50
  }
51
+ /** Compatibility formatter for integrations that still request the original
52
+ * SessionStart announce. The live registry now uses buildInboxPrimer, but
53
+ * retaining this pure export keeps older hook callers from crashing while
54
+ * preserving the same copyable Monitor command. */
55
+ function buildArmAnnounce(short, ownerPid, alias) {
56
+ const command = (0, session_id_1.armMonitorCommand)(short, ownerPid);
57
+ return `ARM YOUR INBOX WATCHER NOW — peers are reaching this session. DROP ANYTIME means you MUST re-arm. `
58
+ + `ToolSearch query "select:Monitor"; call Monitor with persistent:true, timeout_ms:3600000, description:"greprag inbox ${short}", command: \`${command}\`. `
59
+ + `Reply address: ${(alias || '<handle>')}@greprag.com/${short}.`;
60
+ }
50
61
  /** The reference module — now REMINDER-ONLY. No SessionStart announce: arming is taught
51
62
  * once by the inbox-primer (the single announce line). This stays the per-turn poke that
52
63
  * fires while unarmed and auto-silences when armed. Wired into reminder-registry.ts. */
@@ -1 +1 @@
1
- {"version":3,"file":"arm-reminder.js","sourceRoot":"","sources":["../../src/commands/arm-reminder.ts"],"names":[],"mappings":";AAAA;;;;;uCAKuC;;;AAavC,8BAMC;AAWD,4CAWC;AAtCD,8CAAkD;AAElD,qFAAqF;AACrF,sFAAsF;AACtF,oFAAoF;AACpF,uFAAuF;AAEvF;;iFAEiF;AACjF,SAAgB,SAAS,CAAC,GAAgB;IACxC,IAAI,GAAG,CAAC,KAAK;QAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IACzC,MAAM,MAAM,GAAG,GAAG,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7D,OAAO,MAAM,GAAG,CAAC;QACf,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,EAAE;QACrC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,EA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AAM,OAAO,GAAG,IAAA,8BAAiB,EAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACnD,OAAO,oGAAoG;UACvG,wHAAwH,KAAK,iBAAiB,OAAO,MAAM;UAC3J,kBAAkB,CAAC,KAAK,IAAI,UAAU,CAAC,gBAAgB,KAAK,GAAG,CAAC;AACtE,CAAC;AAED;;yFAEyF;AAC5E,QAAA,gBAAgB,GAAmB;IAC9C,EAAE,EAAE,aAAa;IACjB,MAAM,EAAE,SAAS;IACjB,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI;IACpB,QAAQ,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,gBAAgB,CAAC,CAAC,EAAE,GAAG,CAAC;CAC/C,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function runBreakthroughAckCommand(args: string[]): Promise<void>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runBreakthroughAckCommand = runBreakthroughAckCommand;
4
+ const breakthrough_1 = require("./breakthrough");
5
+ const inbox_1 = require("./inbox");
6
+ function flag(args, name) {
7
+ const index = args.indexOf(name);
8
+ return index >= 0 ? args[index + 1] : undefined;
9
+ }
10
+ async function runBreakthroughAckCommand(args) {
11
+ const id = args[0];
12
+ const nonce = flag(args, '--nonce');
13
+ const action = flag(args, '--action');
14
+ const actor = flag(args, '--actor-session') || process.env.CODEX_THREAD_ID;
15
+ if (!id || !nonce || !action || !actor)
16
+ throw new Error('breakthrough-ack requires <chip-id> --nonce <nonce> --action "<action>" and a target session.');
17
+ let manifest = (0, breakthrough_1.readBreakthroughChip)(id);
18
+ manifest = (0, breakthrough_1.acknowledgeBreakthrough)(manifest, nonce, actor, action);
19
+ manifest = (0, breakthrough_1.actBreakthrough)(manifest, nonce);
20
+ await (0, inbox_1.sendChipEvent)(manifest, manifest.codex.threadId, {
21
+ kind: 'breakthrough-ack', summary: `BREAKTHROUGH_ACK:${nonce} action=${action.trim()}`,
22
+ }, actor);
23
+ console.log(`BREAKTHROUGH_ACK:${nonce} acted for chip ${id.slice(0, 8)}.`);
24
+ }
25
+ //# sourceMappingURL=breakthrough-ack-command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"breakthrough-ack-command.js","sourceRoot":"","sources":["../../../src/commands/codex-chip/breakthrough-ack-command.ts"],"names":[],"mappings":";;AAOA,8DAWC;AAlBD,iDAAgG;AAChG,mCAAwC;AAExC,SAAS,IAAI,CAAC,IAAc,EAAE,IAAY;IACxC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAAC,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACpF,CAAC;AAEM,KAAK,UAAU,yBAAyB,CAAC,IAAc;IAC5D,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IAAC,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAAC,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IAC/F,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,iBAAiB,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;IAC3E,IAAI,CAAC,EAAE,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,+FAA+F,CAAC,CAAC;IACzJ,IAAI,QAAQ,GAAG,IAAA,mCAAoB,EAAC,EAAE,CAAC,CAAC;IACxC,QAAQ,GAAG,IAAA,sCAAuB,EAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IACnE,QAAQ,GAAG,IAAA,8BAAe,EAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC5C,MAAM,IAAA,qBAAa,EAAC,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE;QACrD,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,oBAAoB,KAAK,WAAW,MAAM,CAAC,IAAI,EAAE,EAAE;KACvF,EAAE,KAAK,CAAC,CAAC;IACV,OAAO,CAAC,GAAG,CAAC,oBAAoB,KAAK,mBAAmB,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;AAC7E,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { findManifest } from './store';
2
+ export declare function runBreakthroughCommand(args: string[]): Promise<void>;
3
+ export declare function routeBreakthrough(manifest: NonNullable<ReturnType<typeof findManifest>>, reason: string, targetSession?: string): Promise<{
4
+ nonce: string;
5
+ }>;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runBreakthroughCommand = runBreakthroughCommand;
4
+ exports.routeBreakthrough = routeBreakthrough;
5
+ const inbox_1 = require("./inbox");
6
+ const git_1 = require("./git");
7
+ const store_1 = require("./store");
8
+ const breakthrough_1 = require("./breakthrough");
9
+ const mechanic_lifecycle_1 = require("./mechanic-lifecycle");
10
+ const store_2 = require("./store");
11
+ function flag(args, name) {
12
+ const index = args.indexOf(name);
13
+ return index >= 0 ? args[index + 1] : undefined;
14
+ }
15
+ async function runBreakthroughCommand(args) {
16
+ const id = args[0];
17
+ const reason = flag(args, '--reason') || args[1];
18
+ if (!id)
19
+ throw new Error('Chip id is required.');
20
+ if (!reason || reason.trim().length < 12) {
21
+ throw new Error('--reason must document the boundary or blocker (at least 12 characters).');
22
+ }
23
+ const marker = (0, git_1.readChipMarker)(process.cwd());
24
+ if (!marker || marker.id !== id)
25
+ throw new Error('Breakthrough must run from the matching managed chip checkout.');
26
+ const found = (0, store_1.findManifest)(id);
27
+ if (!found)
28
+ throw new Error(`Unknown chip: ${id}`);
29
+ const routed = await routeBreakthrough(found, reason.trim(), found.parent.sessionId);
30
+ console.log(`BREAKTHROUGH:${routed.nonce}`);
31
+ console.log(`Breakthrough routed for chip ${id.slice(0, 8)}.`);
32
+ }
33
+ async function routeBreakthrough(manifest, reason, targetSession) {
34
+ if (manifest.codex.role === 'mechanic' && manifest.codex.mechanic?.state === 'dormant') {
35
+ manifest = (0, store_2.updateManifest)(manifest.id, { codex: {
36
+ ...manifest.codex, mechanic: (0, mechanic_lifecycle_1.reopenMechanicIncident)(manifest.codex.mechanic),
37
+ } });
38
+ }
39
+ const queued = (0, breakthrough_1.queueBreakthrough)(manifest, reason, targetSession);
40
+ await (0, inbox_1.sendChipEvent)(queued.manifest, queued.delivery.targetSession, {
41
+ kind: 'breakthrough', summary: `BREAKTHROUGH:${queued.delivery.nonce} ${reason}`,
42
+ }, queued.manifest.codex.threadId || queued.manifest.parent.sessionId);
43
+ (0, breakthrough_1.markBreakthroughInjected)(queued.manifest, queued.delivery.nonce, 'live');
44
+ return { nonce: queued.delivery.nonce };
45
+ }
46
+ //# sourceMappingURL=breakthrough-command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"breakthrough-command.js","sourceRoot":"","sources":["../../../src/commands/codex-chip/breakthrough-command.ts"],"names":[],"mappings":";;AAYA,wDAcC;AAED,8CAYC;AAxCD,mCAAwC;AACxC,+BAAuC;AACvC,mCAAuC;AACvC,iDAA6E;AAC7E,6DAA8D;AAC9D,mCAAyC;AAEzC,SAAS,IAAI,CAAC,IAAc,EAAE,IAAY;IACxC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAClD,CAAC;AAEM,KAAK,UAAU,sBAAsB,CAAC,IAAc;IACzD,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACnB,MAAM,MAAM,GAAG,IAAI,C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BAC9C,GAAG,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAA,2CAAsB,EAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC;aAC7E,EAAE,CAAC,CAAC;IACP,CAAC;IACD,MAAM,MAAM,GAAG,IAAA,gCAAiB,EAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;IAClE,MAAM,IAAA,qBAAa,EAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE;QAClE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,gBAAgB,MAAM,CAAC,QAAQ,CAAC,KAAK,IAAI,MAAM,EAAE;KACjF,EAAE,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACvE,IAAA,uCAAwB,EAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACzE,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { BreakthroughDelivery, BreakthroughState, ChipManifest } from './model';
2
+ export declare const BREAKTHROUGH_TERMINAL_STATES: Set<BreakthroughState>;
3
+ export declare function queueBreakthrough(manifest: ChipManifest, summary: string, targetSession?: string | undefined, nonce?: string): {
4
+ manifest: ChipManifest;
5
+ delivery: BreakthroughDelivery;
6
+ };
7
+ export declare function markBreakthroughInjected(manifest: ChipManifest, nonce: string, transport?: 'live' | 'native-fallback'): ChipManifest;
8
+ export declare function markBreakthroughDegraded(manifest: ChipManifest, nonce: string, error: string): ChipManifest;
9
+ export declare function acknowledgeBreakthrough(manifest: ChipManifest, nonce: string, actorSession: string, action: string): ChipManifest;
10
+ export declare function actBreakthrough(manifest: ChipManifest, nonce: string): ChipManifest;
11
+ export declare function markBreakthroughTerminal(manifest: ChipManifest, nonce: string): ChipManifest;
12
+ export declare function pendingBreakthroughs(manifest: ChipManifest): BreakthroughDelivery[];
13
+ export declare function assertNoPendingBreakthroughs(manifest: ChipManifest): void;
14
+ export declare function breakthroughState(manifest: ChipManifest, nonce: string): BreakthroughDelivery;
15
+ export declare function readBreakthroughChip(id: string): ChipManifest;
@@ -0,0 +1,147 @@
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.BREAKTHROUGH_TERMINAL_STATES = void 0;
37
+ exports.queueBreakthrough = queueBreakthrough;
38
+ exports.markBreakthroughInjected = markBreakthroughInjected;
39
+ exports.markBreakthroughDegraded = markBreakthroughDegraded;
40
+ exports.acknowledgeBreakthrough = acknowledgeBreakthrough;
41
+ exports.actBreakthrough = actBreakthrough;
42
+ exports.markBreakthroughTerminal = markBreakthroughTerminal;
43
+ exports.pendingBreakthroughs = pendingBreakthroughs;
44
+ exports.assertNoPendingBreakthroughs = assertNoPendingBreakthroughs;
45
+ exports.breakthroughState = breakthroughState;
46
+ exports.readBreakthroughChip = readBreakthroughChip;
47
+ const crypto = __importStar(require("crypto"));
48
+ const store_1 = require("./store");
49
+ exports.BREAKTHROUGH_TERMINAL_STATES = new Set(['acted', 'terminal']);
50
+ function now() { return new Date().toISOString(); }
51
+ function sameSession(left, right) {
52
+ return Boolean(left && right && left.slice(0, 8).toLowerCase() === right.slice(0, 8).toLowerCase());
53
+ }
54
+ function withBreakthrough(manifest, nonce, mutate) {
55
+ // A send/ACK event may update the manifest between queueing and the state
56
+ // transition. Always merge against the latest durable record so transport
57
+ // receipts and prior attempts cannot be clobbered by a stale caller copy.
58
+ const authoritative = (0, store_1.readManifest)(manifest.id) || manifest;
59
+ const current = authoritative.codex.breakthroughs?.[nonce];
60
+ if (!current)
61
+ throw new Error(`Unknown breakthrough nonce ${nonce}.`);
62
+ return (0, store_1.updateManifest)(authoritative.id, { codex: {
63
+ ...authoritative.codex,
64
+ breakthroughs: { ...(authoritative.codex.breakthroughs || {}), [nonce]: mutate(current) },
65
+ } });
66
+ }
67
+ function queueBreakthrough(manifest, summary, targetSession = manifest.parent.sessionId, nonce = crypto.randomBytes(16).toString('hex')) {
68
+ if (!targetSession)
69
+ throw new Error('Breakthrough has no target parent session.');
70
+ const delivery = {
71
+ nonce, summary: summary.trim(), targetSession, state: 'queued', required: true,
72
+ requestedAt: now(), attempts: 0,
73
+ };
74
+ const next = (0, store_1.updateManifest)(manifest.id, { codex: {
75
+ ...manifest.codex, breakthroughs: { ...(manifest.codex.breakthroughs || {}), [nonce]: delivery },
76
+ } });
77
+ return { manifest: next, delivery };
78
+ }
79
+ function markBreakthroughInjected(manifest, nonce, transport = 'live') {
80
+ return withBreakthrough(manifest, nonce, current => {
81
+ if (current.state !== 'queued' && current.state !== 'degraded') {
82
+ throw new Error(`Breakthrough ${nonce.slice(0, 8)} is ${current.state}; it is not injectable.`);
83
+ }
84
+ return { ...current, state: 'injected', injectedAt: now(), attempts: current.attempts + 1, lastTransport: transport, lastError: undefined };
85
+ });
86
+ }
87
+ function markBreakthroughDegraded(manifest, nonce, error) {
88
+ return withBreakthrough(manifest, nonce, current => {
89
+ if (exports.BREAKTHROUGH_TERMINAL_STATES.has(current.state)) {
90
+ throw new Error(`Breakthrough ${nonce.slice(0, 8)} is ${current.state}; terminal delivery cannot degrade.`);
91
+ }
92
+ return {
93
+ ...current, state: 'degraded', attempts: current.attempts + 1,
94
+ emptyTurnCount: /empty|unacknowledged/i.test(error) ? (current.emptyTurnCount || 0) + 1 : current.emptyTurnCount,
95
+ lastTransport: 'native-fallback', lastError: error,
96
+ };
97
+ });
98
+ }
99
+ function acknowledgeBreakthrough(manifest, nonce, actorSession, action) {
100
+ const current = manifest.codex.breakthroughs?.[nonce];
101
+ if (!current)
102
+ throw new Error(`Unknown breakthrough nonce ${nonce}.`);
103
+ if (!sameSession(current.targetSession, actorSession))
104
+ throw new Error('Breakthrough ACK must come from its recorded target session.');
105
+ if (!['injected', 'acknowledged', 'degraded'].includes(current.state)) {
106
+ throw new Error(`Breakthrough ${nonce.slice(0, 8)} is ${current.state}; ACK is no longer valid.`);
107
+ }
108
+ return withBreakthrough(manifest, nonce, item => ({
109
+ ...item, state: 'acknowledged', acknowledgedAt: item.acknowledgedAt || now(), action: action.trim(), lastError: undefined,
110
+ }));
111
+ }
112
+ function actBreakthrough(manifest, nonce) {
113
+ return withBreakthrough(manifest, nonce, current => {
114
+ if (current.state !== 'acknowledged')
115
+ throw new Error(`Breakthrough ${nonce.slice(0, 8)} requires an acknowledged action.`);
116
+ return { ...current, state: 'acted', actedAt: now() };
117
+ });
118
+ }
119
+ function markBreakthroughTerminal(manifest, nonce) {
120
+ return withBreakthrough(manifest, nonce, current => {
121
+ if (current.state !== 'acted')
122
+ throw new Error(`Breakthrough ${nonce.slice(0, 8)} requires ACK and action before terminal closeout.`);
123
+ return { ...current, state: 'terminal', terminalAt: now() };
124
+ });
125
+ }
126
+ function pendingBreakthroughs(manifest) {
127
+ return Object.values(manifest.codex.breakthroughs || {}).filter(item => item.required && !exports.BREAKTHROUGH_TERMINAL_STATES.has(item.state));
128
+ }
129
+ function assertNoPendingBreakthroughs(manifest) {
130
+ const pending = pendingBreakthroughs(manifest);
131
+ if (pending.length) {
132
+ throw new Error(`Required BREAKTHROUGH ACK/action remains pending: ${pending.map(item => item.nonce.slice(0, 8)).join(', ')}.`);
133
+ }
134
+ }
135
+ function breakthroughState(manifest, nonce) {
136
+ const delivery = manifest.codex.breakthroughs?.[nonce];
137
+ if (!delivery)
138
+ throw new Error(`Unknown breakthrough nonce ${nonce}.`);
139
+ return delivery;
140
+ }
141
+ function readBreakthroughChip(id) {
142
+ const manifest = (0, store_1.readManifest)(id);
143
+ if (!manifest)
144
+ throw new Error(`Unknown chip: ${id}`);
145
+ return manifest;
146
+ }
147
+ //# sourceMappingURL=breakthrough.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"breakthrough.js","sourceRoot":"","sources":["../../../src/commands/codex-chip/breakthrough.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,8CAYC;AAED,4DASC;AAED,4DAWC;AAED,0DAYC;AAED,0CAKC;AAED,4DAKC;AAED,oDAEC;AAED,oEAKC;AAED,8CAIC;AAED,oDAIC;AAlHD,+CAAiC;AAEjC,mCAAuD;AAE1C,QAAA,4BAA4B,GAAG,IAAI,GAAG,CAAoB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;AAE9F,SAAS,GAAG,KAAa,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;AAE3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AAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AAC1I,CAAC;AAED,SAAgB,4BAA4B,CAAC,QAAsB;IACjE,MAAM,OAAO,GAAG,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IAC/C,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,qDAAqD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClI,CAAC;AACH,CAAC;AAED,SAAgB,iBAAiB,CAAC,QAAsB,EAAE,KAAa;IACrE,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC,KAAK,CAAC,CAAC;IACvD,IAAI,CAAC,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,KAAK,GAAG,CAAC,CAAC;IACvE,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAgB,oBAAoB,CAAC,EAAU;IAC7C,MAAM,QAAQ,GAAG,IAAA,oBAAY,EAAC,EAAE,CAAC,CAAC;IAClC,IAAI,CAAC,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;IACtD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -41,6 +41,7 @@ const model_1 = require("./model");
41
41
  const store_1 = require("./store");
42
42
  const lifecycle_1 = require("./lifecycle");
43
43
  const goals_1 = require("./goals");
44
+ const mechanic_lifecycle_1 = require("./mechanic-lifecycle");
44
45
  function alive(pid) { try {
45
46
  process.kill(pid, 0);
46
47
  return true;
@@ -57,10 +58,15 @@ function runCleanupCommand(args) {
57
58
  throw new Error(`Unknown chip: ${ref}`);
58
59
  const force = args.includes('--force');
59
60
  (0, goals_1.assertGoalAcceptedForCleanup)(manifest);
61
+ if (manifest.codex.role === 'mechanic' && !args.includes('--mechanic-final')) {
62
+ throw new Error('MECHANIC remains OPEN+DORMANT after incident repair; only final LEAD mission teardown may pass --mechanic-final.');
63
+ }
60
64
  manifest = (0, lifecycle_1.prepareCleanup)(manifest, args.includes('--integrated'));
61
65
  if (manifest.codex.runtime === 'native' && manifest.codex.threadId && !args.includes('--native-archived')) {
62
66
  throw new Error(`Archive native Codex task ${manifest.codex.threadId} first, then rerun cleanup with --native-archived.`);
63
67
  }
68
+ const nativeArchiveAt = manifest.codex.runtime === 'native' && manifest.codex.threadId && args.includes('--native-archived')
69
+ ? new Date().toISOString() : undefined;
64
70
  if ((0, model_1.isActiveChip)(manifest))
65
71
  throw new Error(`Chip is ${manifest.state}; stop it before cleanup.`);
66
72
  if (!manifest.worker?.settledAt && manifest.worker?.pid && alive(manifest.worker.pid)) {
@@ -86,7 +92,11 @@ function runCleanupCommand(args) {
86
92
  }
87
93
  if (branchExists)
88
94
  (0, git_1.deleteBranch)(manifest.parent.root, manifest.worktree.branch);
89
- manifest = (0, store_1.updateManifest)(manifest.id, { state: 'cleaned' });
95
+ manifest = (0, store_1.updateManifest)(manifest.id, nativeArchiveAt
96
+ ? { state: 'cleaned', codex: { ...manifest.codex, nativeArchivedAt: nativeArchiveAt,
97
+ mechanic: manifest.codex.role === 'mechanic' && manifest.codex.mechanic
98
+ ? (0, mechanic_lifecycle_1.terminalMechanic)(manifest.codex.mechanic) : manifest.codex.mechanic } }
99
+ : { state: 'cleaned' });
90
100
  if (args.includes('--json'))
91
101
  return void console.log(JSON.stringify({
92
102
  protocol: 'greprag-codex-chip-closeout-v1', manifest,
@@ -1 +1 @@
1
- {"version":3,"file":"cleanup-command.js","sourceRoot":"","sources":["../../../src/commands/codex-chip/cleanup-command.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,8CA4BC;AAtCD,uCAAyB;AACzB,2CAA6B;AAC7B,+BAA6E;AAC7E,mCAAuC;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
+ export { resolveChipModel, resolveChipRole } from './selection';
2
2
  export declare function reconcile(): Promise<void>;
3
3
  export declare function runCodexChip(args: string[]): Promise<void>;
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.resolveChipModel = void 0;
36
+ exports.resolveChipRole = exports.resolveChipModel = void 0;
37
37
  exports.reconcile = reconcile;
38
38
  exports.runCodexChip = runCodexChip;
39
39
  const crypto = __importStar(require("crypto"));
@@ -55,23 +55,16 @@ const naming_1 = require("./naming");
55
55
  const goals_1 = require("./goals");
56
56
  const goal_command_1 = require("./goal-command");
57
57
  const cleanup_command_1 = require("./cleanup-command");
58
+ const breakthrough_command_1 = require("./breakthrough-command");
59
+ const breakthrough_command_2 = require("./breakthrough-command");
60
+ const breakthrough_ack_command_1 = require("./breakthrough-ack-command");
61
+ const breakthrough_1 = require("./breakthrough");
62
+ const mechanic_lifecycle_1 = require("./mechanic-lifecycle");
58
63
  const resume_command_1 = require("./resume-command");
64
+ const help_1 = require("./help");
59
65
  var selection_2 = require("./selection");
60
66
  Object.defineProperty(exports, "resolveChipModel", { enumerable: true, get: function () { return selection_2.resolveChipModel; } });
61
- const HELP = `greprag codex chip collision-safe Codex task orchestration
62
-
63
- spawn "<task>" --name <slug> [--title <purview>] [--multi-chip --label A] (--owns <glob> | --read-only)
64
- greprag codex chip handoff <id|name> [--json]
65
- greprag codex chip verify-title <id|name> <attestation flags from handoff>
66
- greprag codex chip attach|status|stop|cleanup <id|name>
67
- greprag codex chip steer <id|name> "<message>" | report <id|name> --summary "<result>"
68
- greprag codex chip block <id|name> --reason "<blocker>" | list | reconcile
69
- greprag codex chip resume <id|name> | resume-ack <id> --nonce <nonce>
70
- greprag codex chip goal create|status|accept|exclude|cancel ...
71
-
72
- Spawn prepares a native Codex Desktop project/worktree handoff and reserves its
73
- starting branch. Write chips must declare non-overlapping ownership paths. Use
74
- --runtime cli only for a model exposed by the installed PATH Codex app-server.`;
67
+ Object.defineProperty(exports, "resolveChipRole", { enumerable: true, get: function () { return selection_2.resolveChipRole; } });
75
68
  function flag(args, name) {
76
69
  const index = args.indexOf(name);
77
70
  return index >= 0 ? args[index + 1] : undefined;
@@ -145,19 +138,23 @@ async function spawnChip(args) {
145
138
  if (!parentSession) {
146
139
  throw new Error('No parent Codex session detected. Run inside Codex or pass --parent-session <thread-id>.');
147
140
  }
148
- const role = args.includes('--leader') ? 'leader' : 'worker';
141
+ const role = (0, selection_1.resolveChipRole)(args);
142
+ if (role === 'planner' && !args.includes('--read-only')) {
143
+ throw new Error('PLANNER tasks are control-plane/read-only; pass --read-only.');
144
+ }
145
+ if ((role === 'advisor' || role === 'mechanic') && !args.includes('--read-only')) {
146
+ throw new Error(`${role.toUpperCase()} tasks are read-only; pass --read-only.`);
147
+ }
149
148
  const naming = (0, naming_1.resolveChipNaming)(name, flag(args, '--title'), flag(args, '--label'), role, args.includes('--multi-chip'));
150
149
  const goalId = flag(args, '--goal-id');
151
150
  if (!goalId)
152
151
  throw new Error('Every new chip requires a parent-owned --goal-id. Create one with `greprag codex chip goal create`.');
153
152
  const covers = flags(args, '--covers');
154
- (0, goals_1.requireGoalForSpawn)(goalId, anchor.projectId, parentSession, covers);
155
- const selectionArgs = role === 'leader' && !args.includes('--complex') && !flag(args, '--profile') &&
156
- !flag(args, '--model') && !flag(args, '--effort')
157
- ? [...args, '--complex', '--model-reason', 'Multi-chip orchestration and integration',
158
- '--complexity-signal', 'orchestration']
159
- : args;
160
- const selection = (0, selection_1.resolveChipSelection)(selectionArgs, parentSession);
153
+ (0, goals_1.requireGoalForSpawn)(goalId, anchor.projectId, parentSession, covers, role);
154
+ if (role === 'worker' || role === 'advisor' || role === 'mechanic') {
155
+ (0, goals_1.requireLeaderMissionGoalForDispatch)(goalId, anchor.projectId, parentSession);
156
+ }
157
+ const selection = (0, selection_1.resolveChipSelection)(args, parentSession, role, mode);
161
158
  const nativeModelVerified = args.includes('--native-model-verified');
162
159
  const timeoutMinutes = (0, selection_1.resolveNativeTimeout)(args);
163
160
  if (runtime === 'native')
@@ -185,6 +182,7 @@ async function spawnChip(args) {
185
182
  codex: {
186
183
  projectId: codexProjectId,
187
184
  role,
185
+ mechanic: role === 'mechanic' ? (0, mechanic_lifecycle_1.newMechanicLifecycle)(now) : undefined,
188
186
  label: naming.label, displayName: naming.displayName,
189
187
  bindingNonce: runtime === 'native' ? crypto.randomBytes(16).toString('hex') : undefined,
190
188
  nativeModelVerified,
@@ -202,7 +200,10 @@ async function spawnChip(args) {
202
200
  updatedAt: now,
203
201
  };
204
202
  (0, store_1.withProjectChipLock)(anchor.projectId, () => {
205
- (0, goals_1.requireGoalForSpawn)(goalId, anchor.projectId, parentSession, covers);
203
+ (0, goals_1.requireGoalForSpawn)(goalId, anchor.projectId, parentSession, covers, role);
204
+ if (role === 'worker' || role === 'advisor' || role === 'mechanic') {
205
+ (0, goals_1.requireLeaderMissionGoalForDispatch)(goalId, anchor.projectId, parentSession);
206
+ }
206
207
  const active = (0, store_1.activeManifests)(anchor.projectId);
207
208
  (0, naming_1.assertNoNamingConflicts)(manifest, active);
208
209
  (0, git_1.assertNoLeaseConflicts)(owns, active);
@@ -281,6 +282,8 @@ function startNativeMonitorProcess(manifest) {
281
282
  }
282
283
  async function attachNativeChip(args) {
283
284
  let manifest = requireManifest(args[0]);
285
+ if (manifest.codex.role === 'leader')
286
+ (0, goals_1.requireLeaderMissionGoal)(manifest);
284
287
  manifest = (0, native_1.attachNativeCheckout)(manifest);
285
288
  try {
286
289
  await (0, inbox_1.sendChipEvent)(manifest, manifest.parent.sessionId, {
@@ -326,6 +329,12 @@ async function reportChip(args) {
326
329
  const marker = (0, git_1.readChipMarker)(process.cwd());
327
330
  if (!marker || marker.id !== id)
328
331
  throw new Error('Report must run from the matching managed chip checkout.');
332
+ const reportManifest = (0, store_1.findManifest)(id);
333
+ if (reportManifest?.codex.role === 'leader') {
334
+ const goal = (0, goals_1.requireLeaderMissionGoal)(reportManifest, true);
335
+ if (goal.state !== 'accepted')
336
+ throw new Error(`LEAD report is blocked until mission goal ${goal.id} is accepted.`);
337
+ }
329
338
  const reportBranch = (0, git_1.branchName)(process.cwd());
330
339
  if ((!reportBranch && !marker.detachedAllowed) || (reportBranch && reportBranch !== marker.branch)) {
331
340
  throw new Error('Chip branch does not match its marker.');
@@ -347,6 +356,7 @@ async function reportChip(args) {
347
356
  throw new Error(`Changed files outside the chip lease: ${escaped.join(', ')}`);
348
357
  }
349
358
  const manifest = requireManifest(id);
359
+ (0, breakthrough_1.assertNoPendingBreakthroughs)(manifest);
350
360
  const evidence = (0, goals_1.parseReportEvidence)(flags(args, '--evidence'), manifest.covers || []);
351
361
  (0, lifecycle_1.writeChipReceipt)({ type: 'report', id, commit, summary, checks: flags(args, '--check'), evidence, at: new Date().toISOString() });
352
362
  console.log(`Report submitted for chip ${id.slice(0, 8)}; host validation pending.`);
@@ -356,68 +366,18 @@ async function steerChip(args) {
356
366
  const message = args[1];
357
367
  if (!message)
358
368
  throw new Error('Steer requires a message.');
369
+ if (!['running', 'blocked'].includes(manifest.state))
370
+ throw new Error(`Chip is ${manifest.state}; only running or blocked chips can receive a breakthrough.`);
359
371
  if (!manifest.codex.threadId)
360
372
  throw new Error('Chip has not acquired a Codex thread yet.');
361
- if (!['running', 'blocked'].includes(manifest.state)) {
362
- throw new Error(`Chip is ${manifest.state}; only running or blocked chips can be steered.`);
363
- }
364
- if (manifest.codex.runtime === 'native') {
365
- if (manifest.state === 'blocked') {
366
- (0, native_1.assertNoLiveNativeMonitor)(manifest);
367
- manifest = (0, store_1.updateManifest)(manifest.id, { state: 'running', error: undefined });
368
- startNativeMonitorProcess(manifest);
369
- }
370
- console.log(JSON.stringify({
371
- protocol: 'greprag-codex-native-steer-v1',
372
- threadId: manifest.codex.threadId,
373
- message,
374
- instruction: 'Deliver message with the Codex Desktop native send_message_to_thread surface.',
375
- }, null, 2));
376
- return;
377
- }
378
373
  if (manifest.state === 'blocked') {
379
- manifest = (0, store_1.updateManifest)(manifest.id, {
380
- state: 'running', error: undefined,
381
- codex: { ...manifest.codex, turnId: undefined },
382
- worker: { pid: process.pid, heartbeatAt: new Date().toISOString() },
383
- });
384
- await (0, worker_1.runChipWorker)(manifest.id, undefined, 2_000, message);
385
- console.log(`Restarted chip ${manifest.id.slice(0, 8)} (${manifest.name}) with steering.`);
386
- return;
387
- }
388
- const client = new codex_app_server_client_1.CodexAppServerClient({ timeoutMs: 15_000, transport: manifest.codex.transport });
389
- let needsContinuation = false;
390
- try {
391
- await client.initialize();
392
- await client.request('thread/resume', { threadId: manifest.codex.threadId });
393
- const turns = await client.request('thread/turns/list', {
394
- threadId: manifest.codex.threadId, limit: 5, sortDirection: 'desc', itemsView: 'notLoaded',
395
- });
396
- const active = turns.data?.find(turn => ['inProgress', 'in_progress', 'running'].includes(turn.status || ''));
397
- const input = [{ type: 'text', text: message }];
398
- let turnId;
399
- if (active?.id) {
400
- await client.request('turn/steer', { threadId: manifest.codex.threadId, input, expectedTurnId: active.id });
401
- turnId = active.id;
402
- }
403
- else
404
- needsContinuation = true;
405
- if (turnId)
406
- await waitForTurn(client, manifest.codex.threadId, turnId);
407
- }
408
- finally {
409
- client.close();
410
- }
411
- if (needsContinuation) {
412
- (0, store_1.updateManifest)(manifest.id, {
413
- codex: { ...manifest.codex, turnId: undefined },
414
- worker: { pid: process.pid, heartbeatAt: new Date().toISOString() },
415
- });
416
- await (0, worker_1.runChipWorker)(manifest.id, undefined, 2_000, message);
417
- console.log(`Continued chip ${manifest.id.slice(0, 8)} (${manifest.name}) with steering.`);
418
- return;
374
+ (0, native_1.assertNoLiveNativeMonitor)(manifest);
375
+ manifest = (0, store_1.updateManifest)(manifest.id, { state: 'running', error: undefined });
376
+ if (manifest.codex.runtime === 'native')
377
+ startNativeMonitorProcess(manifest);
419
378
  }
420
- console.log(`Steered chip ${manifest.id.slice(0, 8)} (${manifest.name}).`);
379
+ const routed = await (0, breakthrough_command_2.routeBreakthrough)(manifest, message, manifest.codex.threadId);
380
+ console.log(JSON.stringify({ protocol: 'greprag-breakthrough-v1', nonce: routed.nonce, targetSession: manifest.codex.threadId }, null, 2));
421
381
  }
422
382
  async function stopChip(args) {
423
383
  let manifest = requireManifest(args[0]);
@@ -526,7 +486,7 @@ async function runCodexChip(args) {
526
486
  const sub = args[0];
527
487
  const rest = args.slice(1);
528
488
  if (!sub || ['help', '--help', '-h'].includes(sub))
529
- return void console.log(HELP);
489
+ return void console.log(help_1.CODEX_CHIP_HELP);
530
490
  if (sub === 'goal')
531
491
  return (0, goal_command_1.runGoalCommand)(rest);
532
492
  if (sub === 'spawn')
@@ -551,6 +511,10 @@ async function runCodexChip(args) {
551
511
  }
552
512
  if (sub === 'report')
553
513
  return reportChip(rest);
514
+ if (sub === 'breakthrough')
515
+ return (0, breakthrough_command_1.runBreakthroughCommand)(rest);
516
+ if (sub === 'breakthrough-ack')
517
+ return (0, breakthrough_ack_command_1.runBreakthroughAckCommand)(rest);
554
518
  if (sub === 'resume-ack')
555
519
  return (0, resume_command_1.acknowledgeResume)(rest);
556
520
  if (sub === 'resume') {
@@ -586,6 +550,6 @@ async function runCodexChip(args) {
586
550
  }
587
551
  if (sub === 'status')
588
552
  return printManifest(requireManifest(rest[0]), rest.includes('--json'));
589
- throw new Error(`Unknown codex chip command: ${sub}\n\n${HELP}`);
553
+ throw new Error(`Unknown codex chip command: ${sub}\n\n${help_1.CODEX_CHIP_HELP}`);
590
554
  }
591
555
  //# sourceMappingURL=command.js.map