oh-my-codex 0.21.48 → 0.22.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 (183) hide show
  1. package/Cargo.lock +6 -6
  2. package/Cargo.toml +1 -1
  3. package/README.md +15 -0
  4. package/crates/omx-mux/src/herdr.rs +481 -0
  5. package/crates/omx-mux/src/lib.rs +5 -0
  6. package/dist/cli/__tests__/plugin-cache-live-pin-3790.test.js +104 -3
  7. package/dist/cli/__tests__/plugin-cache-live-pin-3790.test.js.map +1 -1
  8. package/dist/cli/__tests__/question.test.js +33 -0
  9. package/dist/cli/__tests__/question.test.js.map +1 -1
  10. package/dist/cli/__tests__/session-compare.test.d.ts +2 -0
  11. package/dist/cli/__tests__/session-compare.test.d.ts.map +1 -0
  12. package/dist/cli/__tests__/session-compare.test.js +183 -0
  13. package/dist/cli/__tests__/session-compare.test.js.map +1 -0
  14. package/dist/cli/__tests__/team.test.js +8 -0
  15. package/dist/cli/__tests__/team.test.js.map +1 -1
  16. package/dist/cli/plugin-marketplace.d.ts.map +1 -1
  17. package/dist/cli/plugin-marketplace.js +11 -4
  18. package/dist/cli/plugin-marketplace.js.map +1 -1
  19. package/dist/cli/question.d.ts.map +1 -1
  20. package/dist/cli/question.js +8 -1
  21. package/dist/cli/question.js.map +1 -1
  22. package/dist/cli/session-compare.d.ts +11 -0
  23. package/dist/cli/session-compare.d.ts.map +1 -0
  24. package/dist/cli/session-compare.js +172 -0
  25. package/dist/cli/session-compare.js.map +1 -0
  26. package/dist/cli/session-search.d.ts.map +1 -1
  27. package/dist/cli/session-search.js +7 -0
  28. package/dist/cli/session-search.js.map +1 -1
  29. package/dist/cli/team.d.ts.map +1 -1
  30. package/dist/cli/team.js +2 -0
  31. package/dist/cli/team.js.map +1 -1
  32. package/dist/config/__tests__/multiplexer.test.d.ts +2 -0
  33. package/dist/config/__tests__/multiplexer.test.d.ts.map +1 -0
  34. package/dist/config/__tests__/multiplexer.test.js +118 -0
  35. package/dist/config/__tests__/multiplexer.test.js.map +1 -0
  36. package/dist/config/multiplexer.d.ts +29 -0
  37. package/dist/config/multiplexer.d.ts.map +1 -0
  38. package/dist/config/multiplexer.js +91 -0
  39. package/dist/config/multiplexer.js.map +1 -0
  40. package/dist/question/__tests__/ui.test.js +40 -1
  41. package/dist/question/__tests__/ui.test.js.map +1 -1
  42. package/dist/question/ui.d.ts.map +1 -1
  43. package/dist/question/ui.js +37 -7
  44. package/dist/question/ui.js.map +1 -1
  45. package/dist/scripts/__tests__/codex-native-hook.test.js +281 -1
  46. package/dist/scripts/__tests__/codex-native-hook.test.js.map +1 -1
  47. package/dist/scripts/codex-native-hook.d.ts.map +1 -1
  48. package/dist/scripts/codex-native-hook.js +8 -2
  49. package/dist/scripts/codex-native-hook.js.map +1 -1
  50. package/dist/scripts/notify-hook/team-worker-lease.d.ts +15 -0
  51. package/dist/scripts/notify-hook/team-worker-lease.d.ts.map +1 -0
  52. package/dist/scripts/notify-hook/team-worker-lease.js +63 -0
  53. package/dist/scripts/notify-hook/team-worker-lease.js.map +1 -0
  54. package/dist/scripts/notify-hook/team-worker-posttooluse.d.ts +1 -0
  55. package/dist/scripts/notify-hook/team-worker-posttooluse.d.ts.map +1 -1
  56. package/dist/scripts/notify-hook/team-worker-posttooluse.js +16 -5
  57. package/dist/scripts/notify-hook/team-worker-posttooluse.js.map +1 -1
  58. package/dist/scripts/notify-hook/team-worker.d.ts +12 -1
  59. package/dist/scripts/notify-hook/team-worker.d.ts.map +1 -1
  60. package/dist/scripts/notify-hook/team-worker.js +16 -4
  61. package/dist/scripts/notify-hook/team-worker.js.map +1 -1
  62. package/dist/session-history/__tests__/compare.test.d.ts +2 -0
  63. package/dist/session-history/__tests__/compare.test.d.ts.map +1 -0
  64. package/dist/session-history/__tests__/compare.test.js +257 -0
  65. package/dist/session-history/__tests__/compare.test.js.map +1 -0
  66. package/dist/session-history/compare.d.ts +74 -0
  67. package/dist/session-history/compare.d.ts.map +1 -0
  68. package/dist/session-history/compare.js +165 -0
  69. package/dist/session-history/compare.js.map +1 -0
  70. package/dist/team/__tests__/api-interop.test.js +3 -3
  71. package/dist/team/__tests__/completion-evidence.test.js +31 -1
  72. package/dist/team/__tests__/completion-evidence.test.js.map +1 -1
  73. package/dist/team/__tests__/cross-rebase-smoke.test.js +263 -31
  74. package/dist/team/__tests__/cross-rebase-smoke.test.js.map +1 -1
  75. package/dist/team/__tests__/herdr-session-realherdr.test.d.ts +2 -0
  76. package/dist/team/__tests__/herdr-session-realherdr.test.d.ts.map +1 -0
  77. package/dist/team/__tests__/herdr-session-realherdr.test.js +68 -0
  78. package/dist/team/__tests__/herdr-session-realherdr.test.js.map +1 -0
  79. package/dist/team/__tests__/herdr-session.test.d.ts +2 -0
  80. package/dist/team/__tests__/herdr-session.test.d.ts.map +1 -0
  81. package/dist/team/__tests__/herdr-session.test.js +228 -0
  82. package/dist/team/__tests__/herdr-session.test.js.map +1 -0
  83. package/dist/team/__tests__/hook-primary-e2e-contract.test.js +9 -3
  84. package/dist/team/__tests__/hook-primary-e2e-contract.test.js.map +1 -1
  85. package/dist/team/__tests__/idle-nudge.test.js +84 -0
  86. package/dist/team/__tests__/idle-nudge.test.js.map +1 -1
  87. package/dist/team/__tests__/mcp-comm.test.js +25 -1
  88. package/dist/team/__tests__/mcp-comm.test.js.map +1 -1
  89. package/dist/team/__tests__/rebalance-policy.test.js +27 -9
  90. package/dist/team/__tests__/rebalance-policy.test.js.map +1 -1
  91. package/dist/team/__tests__/runtime-delivery.test.d.ts +2 -0
  92. package/dist/team/__tests__/runtime-delivery.test.d.ts.map +1 -0
  93. package/dist/team/__tests__/runtime-delivery.test.js +570 -0
  94. package/dist/team/__tests__/runtime-delivery.test.js.map +1 -0
  95. package/dist/team/__tests__/runtime.test.js +938 -70
  96. package/dist/team/__tests__/runtime.test.js.map +1 -1
  97. package/dist/team/__tests__/scaling.test.js +645 -1
  98. package/dist/team/__tests__/scaling.test.js.map +1 -1
  99. package/dist/team/__tests__/state-renewal.test.d.ts +2 -0
  100. package/dist/team/__tests__/state-renewal.test.d.ts.map +1 -0
  101. package/dist/team/__tests__/state-renewal.test.js +555 -0
  102. package/dist/team/__tests__/state-renewal.test.js.map +1 -0
  103. package/dist/team/__tests__/state.test.js +121 -2
  104. package/dist/team/__tests__/state.test.js.map +1 -1
  105. package/dist/team/__tests__/task-lease.test.d.ts +2 -0
  106. package/dist/team/__tests__/task-lease.test.d.ts.map +1 -0
  107. package/dist/team/__tests__/task-lease.test.js +179 -0
  108. package/dist/team/__tests__/task-lease.test.js.map +1 -0
  109. package/dist/team/__tests__/team-ops-contract.test.js +1 -0
  110. package/dist/team/__tests__/team-ops-contract.test.js.map +1 -1
  111. package/dist/team/__tests__/worker-bootstrap.test.js +2 -0
  112. package/dist/team/__tests__/worker-bootstrap.test.js.map +1 -1
  113. package/dist/team/api-interop.d.ts +1 -1
  114. package/dist/team/api-interop.d.ts.map +1 -1
  115. package/dist/team/api-interop.js +13 -1
  116. package/dist/team/api-interop.js.map +1 -1
  117. package/dist/team/completion-evidence.d.ts +1 -1
  118. package/dist/team/completion-evidence.d.ts.map +1 -1
  119. package/dist/team/completion-evidence.js +9 -0
  120. package/dist/team/completion-evidence.js.map +1 -1
  121. package/dist/team/goal-workflow.js +1 -1
  122. package/dist/team/herdr-session.d.ts +234 -0
  123. package/dist/team/herdr-session.d.ts.map +1 -0
  124. package/dist/team/herdr-session.js +489 -0
  125. package/dist/team/herdr-session.js.map +1 -0
  126. package/dist/team/idle-nudge.d.ts +16 -4
  127. package/dist/team/idle-nudge.d.ts.map +1 -1
  128. package/dist/team/idle-nudge.js +51 -19
  129. package/dist/team/idle-nudge.js.map +1 -1
  130. package/dist/team/mcp-comm.d.ts +6 -4
  131. package/dist/team/mcp-comm.d.ts.map +1 -1
  132. package/dist/team/mcp-comm.js +4 -0
  133. package/dist/team/mcp-comm.js.map +1 -1
  134. package/dist/team/rebalance-policy.d.ts.map +1 -1
  135. package/dist/team/rebalance-policy.js +5 -2
  136. package/dist/team/rebalance-policy.js.map +1 -1
  137. package/dist/team/runtime.d.ts.map +1 -1
  138. package/dist/team/runtime.js +463 -166
  139. package/dist/team/runtime.js.map +1 -1
  140. package/dist/team/scaling.d.ts +3 -3
  141. package/dist/team/scaling.d.ts.map +1 -1
  142. package/dist/team/scaling.js +394 -200
  143. package/dist/team/scaling.js.map +1 -1
  144. package/dist/team/state/monitor.d.ts +3 -0
  145. package/dist/team/state/monitor.d.ts.map +1 -1
  146. package/dist/team/state/monitor.js +3 -0
  147. package/dist/team/state/monitor.js.map +1 -1
  148. package/dist/team/state/tasks.d.ts +4 -1
  149. package/dist/team/state/tasks.d.ts.map +1 -1
  150. package/dist/team/state/tasks.js +36 -5
  151. package/dist/team/state/tasks.js.map +1 -1
  152. package/dist/team/state/types.d.ts +9 -0
  153. package/dist/team/state/types.d.ts.map +1 -1
  154. package/dist/team/state/types.js.map +1 -1
  155. package/dist/team/state.d.ts +15 -2
  156. package/dist/team/state.d.ts.map +1 -1
  157. package/dist/team/state.js +73 -5
  158. package/dist/team/state.js.map +1 -1
  159. package/dist/team/task-lease.d.ts +4 -0
  160. package/dist/team/task-lease.d.ts.map +1 -0
  161. package/dist/team/task-lease.js +74 -0
  162. package/dist/team/task-lease.js.map +1 -0
  163. package/dist/team/team-ops.d.ts +2 -1
  164. package/dist/team/team-ops.d.ts.map +1 -1
  165. package/dist/team/team-ops.js +1 -0
  166. package/dist/team/team-ops.js.map +1 -1
  167. package/dist/team/tmux-session.d.ts +1 -1
  168. package/dist/team/tmux-session.d.ts.map +1 -1
  169. package/dist/team/tmux-session.js +10 -2
  170. package/dist/team/tmux-session.js.map +1 -1
  171. package/dist/team/worker-bootstrap.d.ts.map +1 -1
  172. package/dist/team/worker-bootstrap.js +16 -3
  173. package/dist/team/worker-bootstrap.js.map +1 -1
  174. package/package.json +1 -1
  175. package/plugins/oh-my-codex/.codex-plugin/plugin.json +1 -1
  176. package/plugins/oh-my-codex/hooks/codex-native-hook.mjs +4 -1
  177. package/plugins/oh-my-codex/skills/worker/SKILL.md +7 -1
  178. package/skills/worker/SKILL.md +7 -1
  179. package/src/scripts/__tests__/codex-native-hook.test.ts +279 -0
  180. package/src/scripts/codex-native-hook.ts +8 -2
  181. package/src/scripts/notify-hook/team-worker-lease.ts +69 -0
  182. package/src/scripts/notify-hook/team-worker-posttooluse.ts +16 -4
  183. package/src/scripts/notify-hook/team-worker.ts +15 -4
@@ -0,0 +1,69 @@
1
+ import { readFile, writeFile } from 'node:fs/promises';
2
+ import { join, resolve } from 'node:path';
3
+ import { teamReadTask, teamRenewTaskClaim, teamSendMessage, type RenewTaskClaimResult, type TeamTask } from '../../team/team-ops.js';
4
+ import { resolveCanonicalTeamStateRoot } from '../../team/state-root.js';
5
+
6
+ type WorkerTaskLeaseRenewalResult = RenewTaskClaimResult
7
+ | { ok: false; error: string }
8
+ // Local automatic-hook outcome only: terminal handoff grants no lease or editing authority.
9
+ | { ok: true; task: TeamTask; terminalHandoff: true };
10
+
11
+ /** Heartbeats carry the worker's captured token, never a token looked up from the current task. */
12
+ export async function renewWorkerTaskLease(
13
+ stateRoot: string,
14
+ teamName: string,
15
+ workerName: string,
16
+ ): Promise<WorkerTaskLeaseRenewalResult | null> {
17
+ let status: { state?: string; current_task_id?: string; current_claim_token?: string };
18
+ try {
19
+ status = JSON.parse(await readFile(join(stateRoot, 'team', teamName, 'workers', workerName, 'status.json'), 'utf8'));
20
+ } catch (error) {
21
+ if ((error as NodeJS.ErrnoException).code === 'ENOENT' || error instanceof SyntaxError) return null;
22
+ return { ok: false, error: `renewal_error:${String(error)}` };
23
+ }
24
+ if (!status) return null;
25
+ if (status.state !== 'working' || typeof status.current_task_id !== 'string' || typeof status.current_claim_token !== 'string'
26
+ || !status.current_task_id || !status.current_claim_token) return null;
27
+ try {
28
+ const config = JSON.parse(await readFile(join(stateRoot, 'team', teamName, 'config.json'), 'utf8'));
29
+ const cwd = typeof config.leader_cwd === 'string' && config.leader_cwd ? config.leader_cwd : resolve(stateRoot, '../..');
30
+ // Do not let a cross-worktree hook renew a different team's local state.
31
+ if (resolveCanonicalTeamStateRoot(cwd) !== resolve(stateRoot)) return null;
32
+ const renewal = await teamRenewTaskClaim(teamName, status.current_task_id, workerName, status.current_claim_token, cwd);
33
+ if (!renewal.ok && renewal.error === 'already_terminal') {
34
+ const task = await teamReadTask(teamName, status.current_task_id, cwd);
35
+ if (task && (task.status === 'completed' || task.status === 'failed') && task.owner === workerName && !task.claim) {
36
+ return { ok: true, task, terminalHandoff: true };
37
+ }
38
+ }
39
+ return renewal;
40
+ } catch (error) {
41
+ // Automatic callers must report STOP, not lose renewal exceptions in their outer hook catch.
42
+ return { ok: false, error: `renewal_error:${String(error)}` };
43
+ }
44
+ }
45
+
46
+ /** Keep lease loss visible even when notify treats hook errors as non-critical. */
47
+ export async function reportWorkerTaskLeaseLoss(
48
+ stateRoot: string,
49
+ teamName: string,
50
+ workerName: string,
51
+ error: string,
52
+ ): Promise<string> {
53
+ const message = `LEASE LOST: ${teamName}/${workerName} renewal rejected (${error}). STOP editing and claim-dependent work; contact the leader. Do not adopt another token or revive an expired claim.`;
54
+ const warn = (detail = ''): void => {
55
+ try { process.stderr.write(`${message}${detail}\n`); } catch { /* Diagnostics must not erase the returned STOP. */ }
56
+ };
57
+ warn();
58
+ const config = await readFile(join(stateRoot, 'team', teamName, 'config.json'), 'utf8').then(JSON.parse).catch(() => ({}));
59
+ const cwd = typeof config?.leader_cwd === 'string' && config.leader_cwd ? config.leader_cwd : resolve(stateRoot, '../..');
60
+ await writeFile(join(stateRoot, 'team', teamName, 'workers', workerName, 'lease-loss.json'), JSON.stringify({ message, error, updated_at: new Date().toISOString() })).catch((cause) => {
61
+ warn(` Lease-loss record failed: ${String(cause)}`);
62
+ });
63
+ for (const recipient of [workerName, 'leader-fixed']) {
64
+ await teamSendMessage(teamName, workerName, recipient, message, cwd).catch((cause) => {
65
+ warn(` Notification to ${recipient} failed: ${String(cause)}`);
66
+ });
67
+ }
68
+ return message;
69
+ }
@@ -1,3 +1,4 @@
1
+ import { renewWorkerTaskLease, reportWorkerTaskLeaseLoss } from './team-worker-lease.js';
1
2
  import { execFile } from 'child_process';
2
3
  import { existsSync } from 'fs';
3
4
  import { mkdir, readFile, writeFile } from 'fs/promises';
@@ -18,6 +19,7 @@ export interface TeamWorkerPostToolUseResult {
18
19
  handled: boolean;
19
20
  status: PostToolUseStatus;
20
21
  reason?: string;
22
+ stopMessage?: string;
21
23
  teamName?: string;
22
24
  workerName?: string;
23
25
  stateRoot?: string;
@@ -397,9 +399,6 @@ export async function handleTeamWorkerPostToolUseSuccess(
397
399
  ): Promise<TeamWorkerPostToolUseResult> {
398
400
  try {
399
401
  if (readHookEvent(payload) !== 'PostToolUse') return { handled: false, status: 'skipped', reason: 'not_posttooluse', operationKinds: [] };
400
- if (readToolName(payload) !== 'Bash') return { handled: false, status: 'skipped', reason: 'not_bash', operationKinds: [] };
401
- if (readExitCode(payload) !== 0) return { handled: false, status: 'skipped', reason: 'nonzero_exit', operationKinds: [] };
402
-
403
402
  const parsedWorker = parseTeamWorkerEnv(env.OMX_TEAM_INTERNAL_WORKER ?? env.OMX_TEAM_WORKER);
404
403
  if (!parsedWorker) return { handled: false, status: 'skipped', reason: 'missing_worker_env', operationKinds: [] };
405
404
 
@@ -423,7 +422,20 @@ export async function handleTeamWorkerPostToolUseSuccess(
423
422
  }
424
423
 
425
424
  const nowIso = new Date().toISOString();
426
- await writeHeartbeat(stateRoot, teamName, workerName, nowIso);
425
+ // Best-effort heartbeat telemetry must not bypass authoritative renewal.
426
+ await writeHeartbeat(stateRoot, teamName, workerName, nowIso).catch(() => {});
427
+ const renewal = await renewWorkerTaskLease(stateRoot, teamName, workerName);
428
+ if (renewal && 'terminalHandoff' in renewal) {
429
+ return { handled: true, status: 'skipped', reason: 'terminal_handoff', teamName, workerName, stateRoot, worktreePath, operationKinds: [] };
430
+ }
431
+ if (renewal && !renewal.ok) {
432
+ const stopMessage = await reportWorkerTaskLeaseLoss(stateRoot, teamName, workerName, renewal.error);
433
+ return { handled: true, status: 'skipped', reason: `lease_lost:${renewal.error}`, stopMessage, teamName, workerName, stateRoot, worktreePath, operationKinds: [] };
434
+ }
435
+
436
+ // Tool activity renews the claim; only explicit Bash success authorizes checkpointing.
437
+ if (readToolName(payload) !== 'Bash') return { handled: false, status: 'skipped', reason: 'not_bash', operationKinds: [] };
438
+ if (readExitCode(payload) !== 0) return { handled: false, status: 'skipped', reason: 'nonzero_exit', operationKinds: [] };
427
439
 
428
440
  const config = await readTeamConfig(stateRoot, teamName);
429
441
  const leaderArtifactCwd = readLeaderArtifactCwd(config, cwd);
@@ -3,7 +3,8 @@
3
3
  * Team worker: heartbeat, idle detection, and leader notification.
4
4
  */
5
5
 
6
- import { readFile, writeFile, mkdir, appendFile, rename, stat, readdir } from 'fs/promises';
6
+ import { renewWorkerTaskLease, reportWorkerTaskLeaseLoss } from './team-worker-lease.js';
7
+ import { readFile, writeFile, mkdir, appendFile, rename, stat, readdir, rm } from 'fs/promises';
7
8
  import { existsSync } from 'fs';
8
9
  import { join } from 'path';
9
10
  import { resolveWorkerNotifyTeamStateRootPath } from '../../team/state-root.js';
@@ -342,10 +343,20 @@ export async function updateWorkerHeartbeat(stateDir, teamName, workerName) {
342
343
  turn_count: turnCount + 1,
343
344
  alive: true,
344
345
  };
345
- // Atomic write: tmp + rename
346
+ // Best-effort heartbeat telemetry must not bypass authoritative renewal.
346
347
  const tmpPath = heartbeatPath + '.tmp.' + process.pid;
347
- await writeFile(tmpPath, JSON.stringify(heartbeat, null, 2));
348
- await rename(tmpPath, heartbeatPath);
348
+ try {
349
+ await writeFile(tmpPath, JSON.stringify(heartbeat, null, 2));
350
+ await rename(tmpPath, heartbeatPath);
351
+ } catch {
352
+ await rm(tmpPath, { force: true }).catch(() => {});
353
+ }
354
+ const renewal = await renewWorkerTaskLease(stateDir, teamName, workerName);
355
+ if (renewal && !renewal.ok) {
356
+ const stopMessage = await reportWorkerTaskLeaseLoss(stateDir, teamName, workerName, renewal.error);
357
+ return { ok: false, error: renewal.error, stopMessage };
358
+ }
359
+ return renewal;
349
360
  }
350
361
 
351
362
  export async function maybeNotifyLeaderAllWorkersIdle({ cwd, stateDir, logsDir, parsedTeamWorker }) {