oh-my-codex 0.22.4 → 0.22.6

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 (99) hide show
  1. package/Cargo.lock +6 -6
  2. package/Cargo.toml +1 -1
  3. package/crates/omx-api/src/lib.rs +7 -2
  4. package/crates/omx-api/tests/cli.rs +58 -0
  5. package/dist/cli/__tests__/cleanup.test.js +58 -73
  6. package/dist/cli/__tests__/cleanup.test.js.map +1 -1
  7. package/dist/cli/__tests__/launch-fallback.test.js +41 -0
  8. package/dist/cli/__tests__/launch-fallback.test.js.map +1 -1
  9. package/dist/cli/__tests__/question.test.js +193 -2
  10. package/dist/cli/__tests__/question.test.js.map +1 -1
  11. package/dist/cli/cleanup.d.ts +0 -16
  12. package/dist/cli/cleanup.d.ts.map +1 -1
  13. package/dist/cli/cleanup.js +2 -71
  14. package/dist/cli/cleanup.js.map +1 -1
  15. package/dist/cli/index.d.ts +1 -1
  16. package/dist/cli/index.d.ts.map +1 -1
  17. package/dist/cli/index.js +8 -4
  18. package/dist/cli/index.js.map +1 -1
  19. package/dist/cli/question.d.ts.map +1 -1
  20. package/dist/cli/question.js +38 -20
  21. package/dist/cli/question.js.map +1 -1
  22. package/dist/mcp/__tests__/memory-server-concurrency.test.d.ts +2 -0
  23. package/dist/mcp/__tests__/memory-server-concurrency.test.d.ts.map +1 -0
  24. package/dist/mcp/__tests__/memory-server-concurrency.test.js +128 -0
  25. package/dist/mcp/__tests__/memory-server-concurrency.test.js.map +1 -0
  26. package/dist/mcp/memory-server.d.ts.map +1 -1
  27. package/dist/mcp/memory-server.js +40 -49
  28. package/dist/mcp/memory-server.js.map +1 -1
  29. package/dist/notifications/__tests__/reply-routing-realtmux.test.d.ts +2 -0
  30. package/dist/notifications/__tests__/reply-routing-realtmux.test.d.ts.map +1 -0
  31. package/dist/notifications/__tests__/reply-routing-realtmux.test.js +133 -0
  32. package/dist/notifications/__tests__/reply-routing-realtmux.test.js.map +1 -0
  33. package/dist/notifications/index.d.ts.map +1 -1
  34. package/dist/notifications/index.js +5 -1
  35. package/dist/notifications/index.js.map +1 -1
  36. package/dist/notifications/reply-listener.d.ts +2 -1
  37. package/dist/notifications/reply-listener.d.ts.map +1 -1
  38. package/dist/notifications/reply-listener.js +13 -5
  39. package/dist/notifications/reply-listener.js.map +1 -1
  40. package/dist/notifications/session-registry.d.ts +2 -0
  41. package/dist/notifications/session-registry.d.ts.map +1 -1
  42. package/dist/notifications/session-registry.js.map +1 -1
  43. package/dist/notifications/tmux-detector.d.ts +12 -0
  44. package/dist/notifications/tmux-detector.d.ts.map +1 -1
  45. package/dist/notifications/tmux-detector.js +46 -2
  46. package/dist/notifications/tmux-detector.js.map +1 -1
  47. package/dist/question/__tests__/renderer.test.js +84 -50
  48. package/dist/question/__tests__/renderer.test.js.map +1 -1
  49. package/dist/question/__tests__/state.test.js +192 -2
  50. package/dist/question/__tests__/state.test.js.map +1 -1
  51. package/dist/question/__tests__/ui.test.js +82 -1
  52. package/dist/question/__tests__/ui.test.js.map +1 -1
  53. package/dist/question/renderer.d.ts +2 -2
  54. package/dist/question/renderer.d.ts.map +1 -1
  55. package/dist/question/renderer.js +14 -22
  56. package/dist/question/renderer.js.map +1 -1
  57. package/dist/question/state.d.ts +4 -0
  58. package/dist/question/state.d.ts.map +1 -1
  59. package/dist/question/state.js +76 -23
  60. package/dist/question/state.js.map +1 -1
  61. package/dist/question/ui.d.ts.map +1 -1
  62. package/dist/question/ui.js +8 -2
  63. package/dist/question/ui.js.map +1 -1
  64. package/dist/scripts/__tests__/worker-stop-task-read.test.d.ts +2 -0
  65. package/dist/scripts/__tests__/worker-stop-task-read.test.d.ts.map +1 -0
  66. package/dist/scripts/__tests__/worker-stop-task-read.test.js +76 -0
  67. package/dist/scripts/__tests__/worker-stop-task-read.test.js.map +1 -0
  68. package/dist/scripts/codex-native-hook.d.ts.map +1 -1
  69. package/dist/scripts/codex-native-hook.js +28 -14
  70. package/dist/scripts/codex-native-hook.js.map +1 -1
  71. package/dist/scripts/notify-hook/team-dispatch.d.ts.map +1 -1
  72. package/dist/scripts/notify-hook/team-dispatch.js +137 -128
  73. package/dist/scripts/notify-hook/team-dispatch.js.map +1 -1
  74. package/dist/subagents/tracker.d.ts.map +1 -1
  75. package/dist/subagents/tracker.js +12 -2
  76. package/dist/subagents/tracker.js.map +1 -1
  77. package/dist/team/__tests__/lock-recovery.test.d.ts +2 -0
  78. package/dist/team/__tests__/lock-recovery.test.d.ts.map +1 -0
  79. package/dist/team/__tests__/lock-recovery.test.js +304 -0
  80. package/dist/team/__tests__/lock-recovery.test.js.map +1 -0
  81. package/dist/team/__tests__/state.test.js +8 -6
  82. package/dist/team/__tests__/state.test.js.map +1 -1
  83. package/dist/team/state/dispatch-lock.d.ts.map +1 -1
  84. package/dist/team/state/dispatch-lock.js +3 -11
  85. package/dist/team/state/dispatch-lock.js.map +1 -1
  86. package/dist/team/state/locks.d.ts +1 -0
  87. package/dist/team/state/locks.d.ts.map +1 -1
  88. package/dist/team/state/locks.js +29 -13
  89. package/dist/team/state/locks.js.map +1 -1
  90. package/dist/vscode/__tests__/index.test.js +21 -0
  91. package/dist/vscode/__tests__/index.test.js.map +1 -1
  92. package/dist/vscode/index.d.ts.map +1 -1
  93. package/dist/vscode/index.js +8 -4
  94. package/dist/vscode/index.js.map +1 -1
  95. package/package.json +1 -1
  96. package/plugins/oh-my-codex/.codex-plugin/plugin.json +1 -1
  97. package/src/scripts/__tests__/worker-stop-task-read.test.ts +77 -0
  98. package/src/scripts/codex-native-hook.ts +25 -11
  99. package/src/scripts/notify-hook/team-dispatch.ts +133 -125
@@ -8,6 +8,7 @@ import { safeString } from './utils.js';
8
8
  import { getDefaultBridge, isRuntimeTransportError, isStrictDispatchRecord, preflightRuntimeBridge, resolveBridgeStateDir, RuntimeBridgeError } from '../../runtime/bridge.js';
9
9
  import { hasRuntimeAuthority, hasRuntimeDispatchIdentity, recordRuntimeFinalization, reconcileRuntimeFinalizations } from '../../team/state/dispatch-recovery.js';
10
10
  import { readDispatchRequests } from '../../team/state.js';
11
+ import { assertTeamLockNotStale } from '../../team/state/locks.js';
11
12
  import { appendTeamDeliveryLog } from '../../team/delivery-log.js';
12
13
  import { hasUniqueScopedMailboxMatch, mailboxMessageContentMatches, mailboxMessageIdentity, mailboxRecordBelongsToTeam, normalizeBridgeMailboxMessage, readLegacyMailboxMessageIds } from '../../team/state/mailbox.js';
13
14
 
@@ -298,15 +299,7 @@ async function withLockDirectory(lockDir, timeoutError, fn) {
298
299
  break;
299
300
  } catch (error) {
300
301
  if (error?.code !== 'EEXIST') throw error;
301
- try {
302
- const info = await stat(lockDir);
303
- if (Date.now() - info.mtimeMs > DISPATCH_LOCK_STALE_MS) {
304
- await rm(lockDir, { recursive: true, force: true });
305
- continue;
306
- }
307
- } catch {
308
- // best effort
309
- }
302
+ await assertTeamLockNotStale(lockDir, DISPATCH_LOCK_STALE_MS);
310
303
  if (Date.now() > deadline) throw new Error(timeoutError);
311
304
  await new Promise((resolveDelay) => setTimeout(resolveDelay, 25));
312
305
  }
@@ -1188,136 +1181,151 @@ export async function drainPendingTeamDispatch({
1188
1181
  const requestsPath = join(teamDirPath, 'dispatch', 'requests.json');
1189
1182
  const config = await readJson(existsSync(manifestPath) ? manifestPath : configPath, {});
1190
1183
  const claims = [];
1191
- await withDispatchLock(teamDirPath, async () => {
1192
- await reconcileRuntimeFinalizations(stateDir, teamName);
1193
- let authoritativeRecords;
1194
- if (hasRuntimeAuthority(stateDir)) {
1195
- if (process.env.OMX_RUNTIME_BRIDGE === '0') throw new Error('runtime dispatch authority requires an enabled bridge');
1196
- authoritativeRecords = await refreshDispatchProjection(stateDir);
1197
- if (!authoritativeRecords) {
1198
- const records = getDefaultBridge(stateDir).readCompatFile('dispatch.json')?.records;
1199
- if (Array.isArray(records)) authoritativeRecords = records;
1184
+ let lockAcquired = false;
1185
+ try {
1186
+ await withDispatchLock(teamDirPath, async () => {
1187
+ lockAcquired = true;
1188
+ await reconcileRuntimeFinalizations(stateDir, teamName);
1189
+ let authoritativeRecords;
1190
+ if (hasRuntimeAuthority(stateDir)) {
1191
+ if (process.env.OMX_RUNTIME_BRIDGE === '0') throw new Error('runtime dispatch authority requires an enabled bridge');
1192
+ authoritativeRecords = await refreshDispatchProjection(stateDir);
1193
+ if (!authoritativeRecords) {
1194
+ const records = getDefaultBridge(stateDir).readCompatFile('dispatch.json')?.records;
1195
+ if (Array.isArray(records)) authoritativeRecords = records;
1196
+ }
1200
1197
  }
1201
- }
1202
- const requests = await readBridgeDispatchRequests(stateDir, teamName, cwd, authoritativeRecords);
1203
- if (!Array.isArray(requests)) return;
1204
- if (requests.some((request) => request && typeof request === 'object' && !shouldSkipRequest(request))) {
1205
- preflightRuntimeBridge(stateDir);
1206
- }
1207
- const issueCooldownState = await readIssueCooldownState(teamDirPath);
1208
- const triggerCooldownState = await readTriggerCooldownState(teamDirPath);
1209
- const issueCooldownByIssue = issueCooldownState.by_issue || {};
1210
- const triggerCooldownByKey = triggerCooldownState.by_trigger || {};
1211
- const nowMs = Date.now();
1212
-
1213
- let mutated = false;
1214
- for (const request of requests) {
1215
- if (processed + claims.length >= maxPerTick) break;
1216
- if (!request || typeof request !== 'object') continue;
1217
- if (shouldSkipRequest(request)) {
1218
- skipped += 1;
1219
- continue;
1198
+ const requests = await readBridgeDispatchRequests(stateDir, teamName, cwd, authoritativeRecords);
1199
+ if (!Array.isArray(requests)) return;
1200
+ if (requests.some((request) => request && typeof request === 'object' && !shouldSkipRequest(request))) {
1201
+ preflightRuntimeBridge(stateDir);
1220
1202
  }
1221
-
1222
- if (request.to_worker === 'leader-fixed' && !resolveLeaderPaneId(config) && !explicitPaneIdentity(request.pane_id).provided) {
1223
- const nowIso = new Date().toISOString();
1224
- const alreadyDeferred = safeString(request.last_reason).trim() === LEADER_PANE_MISSING_DEFERRED_REASON;
1225
- request.updated_at = nowIso;
1226
- request.last_reason = LEADER_PANE_MISSING_DEFERRED_REASON;
1227
- request.status = 'pending';
1228
- skipped += 1;
1229
- mutated = true;
1230
- if (!alreadyDeferred) {
1231
- await appendDispatchLog(logsDir, {
1232
- type: 'dispatch_deferred',
1233
- team: teamName,
1234
- request_id: request.request_id,
1235
- worker: request.to_worker,
1236
- to_worker: request.to_worker,
1237
- message_id: request.message_id || null,
1238
- reason: LEADER_PANE_MISSING_DEFERRED_REASON,
1239
- status: 'pending',
1240
- tmux_session: safeString(config?.tmux_session).trim() || null,
1241
- leader_pane_id: safeString(config?.leader_pane_id).trim() || null,
1242
- tmux_injection_attempted: false,
1243
- pane_target: null,
1244
- pane_source: null,
1245
- readiness_evidence: null,
1246
- pane_current_command: null,
1247
- });
1248
- await appendDeliveryTelemetry(logsDir, {
1249
- event: 'dispatch_result',
1250
- team: teamName,
1251
- request_id: request.request_id,
1252
- message_id: request.message_id || null,
1253
- to_worker: request.to_worker,
1254
- transport: 'send-keys',
1255
- result: 'deferred',
1256
- reason: LEADER_PANE_MISSING_DEFERRED_REASON,
1257
- });
1258
- await appendLeaderNotificationDeferredEvent({
1259
- stateDir,
1260
- teamName,
1261
- request,
1262
- reason: LEADER_PANE_MISSING_DEFERRED_REASON,
1263
- nowIso,
1264
- tmuxSession: safeString(config?.tmux_session).trim(),
1265
- leaderPaneId: safeString(config?.leader_pane_id).trim(),
1266
- sourceType: 'team_dispatch',
1267
- });
1203
+ const issueCooldownState = await readIssueCooldownState(teamDirPath);
1204
+ const triggerCooldownState = await readTriggerCooldownState(teamDirPath);
1205
+ const issueCooldownByIssue = issueCooldownState.by_issue || {};
1206
+ const triggerCooldownByKey = triggerCooldownState.by_trigger || {};
1207
+ const nowMs = Date.now();
1208
+
1209
+ let mutated = false;
1210
+ for (const request of requests) {
1211
+ if (processed + claims.length >= maxPerTick) break;
1212
+ if (!request || typeof request !== 'object') continue;
1213
+ if (shouldSkipRequest(request)) {
1214
+ skipped += 1;
1215
+ continue;
1268
1216
  }
1269
- continue;
1270
- }
1271
1217
 
1272
- const issueKey = extractIssueKey(request.trigger_message);
1273
- if (issueCooldownMs > 0 && issueKey) {
1274
- const lastInjectedMs = Number(issueCooldownByIssue[issueKey]);
1275
- if (Number.isFinite(lastInjectedMs) && lastInjectedMs > 0 && nowMs - lastInjectedMs < issueCooldownMs) {
1218
+ if (request.to_worker === 'leader-fixed' && !resolveLeaderPaneId(config) && !explicitPaneIdentity(request.pane_id).provided) {
1219
+ const nowIso = new Date().toISOString();
1220
+ const alreadyDeferred = safeString(request.last_reason).trim() === LEADER_PANE_MISSING_DEFERRED_REASON;
1221
+ request.updated_at = nowIso;
1222
+ request.last_reason = LEADER_PANE_MISSING_DEFERRED_REASON;
1223
+ request.status = 'pending';
1276
1224
  skipped += 1;
1225
+ mutated = true;
1226
+ if (!alreadyDeferred) {
1227
+ await appendDispatchLog(logsDir, {
1228
+ type: 'dispatch_deferred',
1229
+ team: teamName,
1230
+ request_id: request.request_id,
1231
+ worker: request.to_worker,
1232
+ to_worker: request.to_worker,
1233
+ message_id: request.message_id || null,
1234
+ reason: LEADER_PANE_MISSING_DEFERRED_REASON,
1235
+ status: 'pending',
1236
+ tmux_session: safeString(config?.tmux_session).trim() || null,
1237
+ leader_pane_id: safeString(config?.leader_pane_id).trim() || null,
1238
+ tmux_injection_attempted: false,
1239
+ pane_target: null,
1240
+ pane_source: null,
1241
+ readiness_evidence: null,
1242
+ pane_current_command: null,
1243
+ });
1244
+ await appendDeliveryTelemetry(logsDir, {
1245
+ event: 'dispatch_result',
1246
+ team: teamName,
1247
+ request_id: request.request_id,
1248
+ message_id: request.message_id || null,
1249
+ to_worker: request.to_worker,
1250
+ transport: 'send-keys',
1251
+ result: 'deferred',
1252
+ reason: LEADER_PANE_MISSING_DEFERRED_REASON,
1253
+ });
1254
+ await appendLeaderNotificationDeferredEvent({
1255
+ stateDir,
1256
+ teamName,
1257
+ request,
1258
+ reason: LEADER_PANE_MISSING_DEFERRED_REASON,
1259
+ nowIso,
1260
+ tmuxSession: safeString(config?.tmux_session).trim(),
1261
+ leaderPaneId: safeString(config?.leader_pane_id).trim(),
1262
+ sourceType: 'team_dispatch',
1263
+ });
1264
+ }
1277
1265
  continue;
1278
1266
  }
1279
- }
1280
1267
 
1281
- const triggerKey = normalizeTriggerKey(request.trigger_message);
1282
- if (triggerCooldownMs > 0 && triggerKey) {
1283
- const parsed = parseTriggerCooldownEntry(triggerCooldownByKey[triggerKey]);
1284
- const withinCooldown = Number.isFinite(parsed.at) && parsed.at > 0 && nowMs - parsed.at < triggerCooldownMs;
1285
- const sameRequestRetry = parsed.lastRequestId !== '' && parsed.lastRequestId === safeString(request.request_id).trim();
1286
- if (withinCooldown && !sameRequestRetry) {
1268
+ const issueKey = extractIssueKey(request.trigger_message);
1269
+ if (issueCooldownMs > 0 && issueKey) {
1270
+ const lastInjectedMs = Number(issueCooldownByIssue[issueKey]);
1271
+ if (Number.isFinite(lastInjectedMs) && lastInjectedMs > 0 && nowMs - lastInjectedMs < issueCooldownMs) {
1272
+ skipped += 1;
1273
+ continue;
1274
+ }
1275
+ }
1276
+
1277
+ const triggerKey = normalizeTriggerKey(request.trigger_message);
1278
+ if (triggerCooldownMs > 0 && triggerKey) {
1279
+ const parsed = parseTriggerCooldownEntry(triggerCooldownByKey[triggerKey]);
1280
+ const withinCooldown = Number.isFinite(parsed.at) && parsed.at > 0 && nowMs - parsed.at < triggerCooldownMs;
1281
+ const sameRequestRetry = parsed.lastRequestId !== '' && parsed.lastRequestId === safeString(request.request_id).trim();
1282
+ if (withinCooldown && !sameRequestRetry) {
1283
+ skipped += 1;
1284
+ continue;
1285
+ }
1286
+ }
1287
+
1288
+ const lease = await tryAcquireDispatchRequestLease(teamDirPath, request.request_id);
1289
+ if (!lease) {
1287
1290
  skipped += 1;
1288
1291
  continue;
1289
1292
  }
1293
+ mutated = reserveDispatchCooldowns({
1294
+ issueCooldownMs,
1295
+ triggerCooldownMs,
1296
+ issueCooldownByIssue,
1297
+ triggerCooldownByKey,
1298
+ issueKey,
1299
+ triggerKey,
1300
+ requestId: request.request_id,
1301
+ }) || mutated;
1302
+ claims.push({
1303
+ request: { ...request },
1304
+ authoritativeRecords,
1305
+ lease,
1306
+ });
1290
1307
  }
1291
1308
 
1292
- const lease = await tryAcquireDispatchRequestLease(teamDirPath, request.request_id);
1293
- if (!lease) {
1294
- skipped += 1;
1295
- continue;
1309
+ if (mutated) {
1310
+ issueCooldownState.by_issue = issueCooldownByIssue;
1311
+ await writeJsonAtomic(issueCooldownStatePath(teamDirPath), issueCooldownState);
1312
+ triggerCooldownState.by_trigger = triggerCooldownByKey;
1313
+ await writeJsonAtomic(triggerCooldownStatePath(teamDirPath), triggerCooldownState);
1314
+ await writeJsonAtomic(requestsPath, requests);
1296
1315
  }
1297
- mutated = reserveDispatchCooldowns({
1298
- issueCooldownMs,
1299
- triggerCooldownMs,
1300
- issueCooldownByIssue,
1301
- triggerCooldownByKey,
1302
- issueKey,
1303
- triggerKey,
1304
- requestId: request.request_id,
1305
- }) || mutated;
1306
- claims.push({
1307
- request: { ...request },
1308
- authoritativeRecords,
1309
- lease,
1310
- });
1311
- }
1312
-
1313
- if (mutated) {
1314
- issueCooldownState.by_issue = issueCooldownByIssue;
1315
- await writeJsonAtomic(issueCooldownStatePath(teamDirPath), issueCooldownState);
1316
- triggerCooldownState.by_trigger = triggerCooldownByKey;
1317
- await writeJsonAtomic(triggerCooldownStatePath(teamDirPath), triggerCooldownState);
1318
- await writeJsonAtomic(requestsPath, requests);
1319
- }
1320
- });
1316
+ });
1317
+ } catch (error) {
1318
+ // An abandoned dispatch lock needs manual recovery for this team only: keep the lock,
1319
+ // report it, and let the other teams under the same state root drain.
1320
+ if (lockAcquired || !safeString(error?.message).startsWith('team_lock_recovery_required:')) throw error;
1321
+ failed += 1;
1322
+ await appendDispatchLog(logsDir, {
1323
+ type: 'dispatch_lock_recovery_required',
1324
+ team: teamName,
1325
+ reason: safeString(error.message),
1326
+ });
1327
+ continue;
1328
+ }
1321
1329
 
1322
1330
  try {
1323
1331
  for (const claim of claims) {