oh-my-copilot 5.19.6 → 5.19.7

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 (73) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/bridge/claude-md-coordinator.cjs +2 -2
  4. package/bridge/cli.cjs +59 -13
  5. package/bridge/mcp-server.cjs +59 -13
  6. package/commands/omc-setup.md +3 -1
  7. package/dist/__tests__/helpers/runner-clock.d.ts +22 -0
  8. package/dist/__tests__/helpers/runner-clock.d.ts.map +1 -0
  9. package/dist/__tests__/helpers/runner-clock.js +45 -0
  10. package/dist/__tests__/helpers/runner-clock.js.map +1 -0
  11. package/dist/__tests__/hook-stdin-budget.test.d.ts +2 -0
  12. package/dist/__tests__/hook-stdin-budget.test.d.ts.map +1 -0
  13. package/dist/__tests__/hook-stdin-budget.test.js +105 -0
  14. package/dist/__tests__/hook-stdin-budget.test.js.map +1 -0
  15. package/dist/__tests__/parse-max-workers.test.d.ts +2 -0
  16. package/dist/__tests__/parse-max-workers.test.d.ts.map +1 -0
  17. package/dist/__tests__/parse-max-workers.test.js +12 -0
  18. package/dist/__tests__/parse-max-workers.test.js.map +1 -0
  19. package/dist/__tests__/post-tool-use-failure.test.js +5 -9
  20. package/dist/__tests__/post-tool-use-failure.test.js.map +1 -1
  21. package/dist/__tests__/pre-tool-enforcer.test.js +6 -2
  22. package/dist/__tests__/pre-tool-enforcer.test.js.map +1 -1
  23. package/dist/__tests__/run-cjs-generic-timeout.test.js +35 -15
  24. package/dist/__tests__/run-cjs-generic-timeout.test.js.map +1 -1
  25. package/dist/__tests__/run-cjs-graceful-fallback.test.js +21 -9
  26. package/dist/__tests__/run-cjs-graceful-fallback.test.js.map +1 -1
  27. package/dist/__tests__/run-cjs-windows-stdio-contract.test.js +109 -77
  28. package/dist/__tests__/run-cjs-windows-stdio-contract.test.js.map +1 -1
  29. package/dist/__tests__/session-end-process-exit.test.js +24 -12
  30. package/dist/__tests__/session-end-process-exit.test.js.map +1 -1
  31. package/dist/__tests__/session-start-script-context.test.js +39 -8
  32. package/dist/__tests__/session-start-script-context.test.js.map +1 -1
  33. package/dist/__tests__/setup-config-script.test.js +23 -40
  34. package/dist/__tests__/setup-config-script.test.js.map +1 -1
  35. package/dist/__tests__/setup-lifecycle-node.test.js +3 -3
  36. package/dist/__tests__/setup-lifecycle-node.test.js.map +1 -1
  37. package/dist/__tests__/skills.test.js +6 -6
  38. package/dist/__tests__/skills.test.js.map +1 -1
  39. package/dist/cli/commands/__tests__/factory-run-cli.test.js +8 -3
  40. package/dist/cli/commands/__tests__/factory-run-cli.test.js.map +1 -1
  41. package/dist/lib/__tests__/mode-state-lock.test.js +36 -1
  42. package/dist/lib/__tests__/mode-state-lock.test.js.map +1 -1
  43. package/dist/lib/mode-state-io.d.ts +2 -0
  44. package/dist/lib/mode-state-io.d.ts.map +1 -1
  45. package/dist/lib/mode-state-io.js +85 -12
  46. package/dist/lib/mode-state-io.js.map +1 -1
  47. package/docs/CLAUDE.md +1 -1
  48. package/docs/HOOKS.md +2 -1
  49. package/package.json +2 -2
  50. package/plugin.json +1 -1
  51. package/scripts/budget-guard.mjs +2 -2
  52. package/scripts/ci/parse-max-workers.mjs +6 -0
  53. package/scripts/git-guardrails.mjs +10 -2
  54. package/scripts/lib/state-lock.mjs +125 -13
  55. package/scripts/lib/stdin.mjs +71 -8
  56. package/scripts/persistent-mode.cjs +15 -1
  57. package/scripts/premium-budget.mjs +2 -2
  58. package/scripts/run.cjs +19 -1
  59. package/scripts/runs-reconciler.mjs +2 -2
  60. package/scripts/setup-config.mjs +16 -64
  61. package/scripts/stale-run-reporter.mjs +2 -2
  62. package/skills/configure-notifications/SKILL.md +7 -6
  63. package/skills/hud/SKILL.md +2 -1
  64. package/skills/omc-doctor/SKILL.md +15 -14
  65. package/skills/omc-setup/SKILL.md +32 -22
  66. package/skills/omc-setup/phases/01-install-claude-md.md +10 -8
  67. package/skills/omc-setup/phases/02-configure.md +16 -14
  68. package/skills/omc-setup/phases/03-integrations.md +19 -111
  69. package/skills/omc-setup/phases/04-welcome.md +18 -16
  70. package/skills/skill/SKILL.md +6 -5
  71. package/skills/skillify/SKILL.md +2 -1
  72. package/skills/team/SKILL.md +82 -5
  73. package/templates/hooks/lib/stdin.mjs +71 -8
@@ -9,7 +9,7 @@
9
9
  {
10
10
  "name": "oh-my-copilot",
11
11
  "description": "Multi-agent orchestration for GitHub Copilot CLI with intelligent model routing across agents and skills. Zero learning curve. Maximum power.",
12
- "version": "5.19.6",
12
+ "version": "5.19.7",
13
13
  "author": {
14
14
  "name": "Robin Norberg"
15
15
  },
@@ -25,5 +25,5 @@
25
25
  ]
26
26
  }
27
27
  ],
28
- "version": "5.19.6"
28
+ "version": "5.19.7"
29
29
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oh-my-copilot",
3
- "version": "5.19.6",
3
+ "version": "5.19.7",
4
4
  "description": "Multi-agent orchestration system for GitHub Copilot CLI",
5
5
  "author": {
6
6
  "name": "oh-my-copilot contributors"
@@ -909,8 +909,8 @@ function executeClaudeMdTransaction(request) {
909
909
  // src/cli/claude-md-coordinator.ts
910
910
  hardenWindowsExeSearch();
911
911
  var CLAUDE_MD_COORDINATOR_SCHEMA_VERSION = 1;
912
- var COMPILED_ENGINE_VERSION = true ? "5.19.6" : "";
913
- var COMPILED_SOURCE_SHA256 = true ? "018b2b085abc4009f63e9daf0955aabe28d8d9c96f91846161654e946e8e87f6" : "";
912
+ var COMPILED_ENGINE_VERSION = true ? "5.19.7" : "";
913
+ var COMPILED_SOURCE_SHA256 = true ? "74bc35c9f568cf519ea5f9f8c145f181d22e333197d58ac5ca20b72da1784945" : "";
914
914
  function runClaudeMdCoordinatorHandshake() {
915
915
  if (!COMPILED_ENGINE_VERSION || !COMPILED_SOURCE_SHA256) {
916
916
  return { exitCode: 2, response: coordinatorError(2, "Coordinator build handshake is unavailable") };
package/bridge/cli.cjs CHANGED
@@ -40577,6 +40577,39 @@ function ownProcessStartIdentity() {
40577
40577
  }
40578
40578
  return ownProcessStartIdentityCache;
40579
40579
  }
40580
+ function ownStartBoundIdentity() {
40581
+ if (process.env.NODE_ENV === "test" && process.env.OMC_TEST_EMERGENCY_PROCESS_START_UNKNOWN_PID === String(process.pid)) return null;
40582
+ if (ownStartBoundCache !== null) return ownStartBoundCache;
40583
+ const origin = performance.timeOrigin;
40584
+ const uptimeOrigin = Date.now() - process.uptime() * 1e3;
40585
+ if (!Number.isFinite(origin) || origin <= 0 || Math.abs(origin - uptimeOrigin) > START_BOUND_ORIGIN_TOLERANCE_MS) return null;
40586
+ const wait = Math.ceil(START_BOUND_SLACK_MS - performance.now());
40587
+ if (wait > 0) Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, wait);
40588
+ ownStartBoundCache = `${START_BOUND_PREFIX}${BigInt(Math.ceil(origin + START_BOUND_SLACK_MS)) * 10000n + 621355968000000000n}`;
40589
+ return ownStartBoundCache;
40590
+ }
40591
+ function ownLockStartIdentity() {
40592
+ if (process.platform === "win32") {
40593
+ const bound = ownStartBoundIdentity();
40594
+ if (bound !== null) return bound;
40595
+ }
40596
+ return ownProcessStartIdentity();
40597
+ }
40598
+ function lockOwnerVersion(processStart) {
40599
+ return processStart.startsWith(START_BOUND_PREFIX) ? 2 : 1;
40600
+ }
40601
+ function validOwnerIdentity(version3, processStart) {
40602
+ if (typeof processStart !== "string") return false;
40603
+ if (version3 === 2) return /^ticksmax:\d+$/.test(processStart);
40604
+ return version3 === 1 && /^\S+$/.test(processStart) && !processStart.startsWith(START_BOUND_PREFIX);
40605
+ }
40606
+ function startIdentityMatches(recorded, current) {
40607
+ if (!recorded.startsWith(START_BOUND_PREFIX)) return current === recorded;
40608
+ const ticks = current.match(/^ticks:(\d+)$/)?.[1];
40609
+ const bound = recorded.slice(START_BOUND_PREFIX.length);
40610
+ if (!ticks || !/^\d+$/.test(bound)) return null;
40611
+ return BigInt(ticks) <= BigInt(bound);
40612
+ }
40580
40613
  function isStateMutationLockingSupported() {
40581
40614
  return !(process.env.NODE_ENV === "test" && process.env.OMC_TEST_STATE_LOCK_MODE === "none");
40582
40615
  }
@@ -40617,8 +40650,8 @@ function mutationDbPath(lockPath2) {
40617
40650
  return (0, import_path32.join)(current, ".state-mutation-locks.db");
40618
40651
  }
40619
40652
  function ownerFromRow(row) {
40620
- if (!row || row.version !== 1 || !Number.isSafeInteger(row.pid) || row.pid <= 0 || typeof row.process_start !== "string" || typeof row.created_at !== "string" || typeof row.nonce !== "string") return null;
40621
- return { version: 1, pid: row.pid, processStart: row.process_start, createdAt: row.created_at, nonce: row.nonce };
40653
+ if (!row || !validOwnerIdentity(row.version, row.process_start) || !Number.isSafeInteger(row.pid) || row.pid <= 0 || typeof row.created_at !== "string" || typeof row.nonce !== "string") return null;
40654
+ return { version: row.version, pid: row.pid, processStart: row.process_start, createdAt: row.created_at, nonce: row.nonce };
40622
40655
  }
40623
40656
  function writeAllSync2(fd, content2, label2) {
40624
40657
  const bytes = Buffer.from(content2, "utf8");
@@ -40634,7 +40667,7 @@ function readLockOwner(path30) {
40634
40667
  try {
40635
40668
  const value = JSON.parse((0, import_fs26.readFileSync)(path30, "utf8"));
40636
40669
  const pid = value.pid;
40637
- if (value.version !== 1 || !Number.isSafeInteger(pid) || pid <= 0 || typeof value.processStart !== "string" || !/^\S+$/.test(value.processStart) || typeof value.createdAt !== "string" || !Number.isFinite(Date.parse(value.createdAt)) || typeof value.nonce !== "string" || !/^[0-9a-f-]{36}$/i.test(value.nonce)) return null;
40670
+ if (!validOwnerIdentity(value.version, value.processStart) || !Number.isSafeInteger(pid) || pid <= 0 || typeof value.createdAt !== "string" || !Number.isFinite(Date.parse(value.createdAt)) || typeof value.nonce !== "string" || !/^[0-9a-f-]{36}$/i.test(value.nonce)) return null;
40638
40671
  return value;
40639
40672
  } catch (error2) {
40640
40673
  return error2.code === "ENOENT" ? "absent" : null;
@@ -40689,11 +40722,12 @@ function reclaimDeadLockOwner(path30, observedOwner, observedIdentity) {
40689
40722
  return "changed";
40690
40723
  }
40691
40724
  function ownerLive(owner) {
40692
- if (owner.pid === process.pid && abandonedOwnNonces.has(owner.nonce) && owner.processStart === ownProcessStartIdentity()) return false;
40725
+ if (owner.pid === process.pid && abandonedOwnNonces.has(owner.nonce) && owner.processStart === ownLockStartIdentity()) return false;
40693
40726
  if (process.env.NODE_ENV === "test" && process.env.OMC_TEST_EMERGENCY_PROCESS_START_UNKNOWN_PID === String(owner.pid)) return null;
40727
+ if (owner.pid === process.pid && owner.processStart === ownLockStartIdentity()) return true;
40694
40728
  const current = owner.pid === process.pid ? ownProcessStartIdentity() : processStartIdentity2(owner.pid);
40695
40729
  if (current === null) return null;
40696
- return current === "absent" ? false : current === owner.processStart;
40730
+ return current === "absent" ? false : startIdentityMatches(owner.processStart, current);
40697
40731
  }
40698
40732
  function publishLockOwner(path30, owner) {
40699
40733
  const tempPath = `${path30}.${owner.pid}.${owner.nonce}.tmp`;
@@ -40769,15 +40803,16 @@ function acquireFileLockAt(path30, attempts) {
40769
40803
  return (0, import_path32.resolve)(path30);
40770
40804
  }
40771
40805
  })();
40772
- const processStart = ownProcessStartIdentity();
40806
+ const processStart = ownLockStartIdentity();
40773
40807
  if (!processStart || processStart === "absent") {
40774
40808
  lastMutationLockFailure = "unverifiable";
40775
40809
  return null;
40776
40810
  }
40777
40811
  let verifiedLiveOwner = null;
40812
+ let inconclusiveRetries = 0;
40778
40813
  for (let attempt = 0; attempt < attempts; attempt += 1) {
40779
40814
  const owner = {
40780
- version: 1,
40815
+ version: lockOwnerVersion(processStart),
40781
40816
  pid: process.pid,
40782
40817
  processStart,
40783
40818
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -40835,6 +40870,11 @@ function acquireFileLockAt(path30, attempts) {
40835
40870
  const live = verifiedLiveOwner !== null && sameOwner(existing, verifiedLiveOwner) ? true : ownerLive(existing);
40836
40871
  if (live === null) {
40837
40872
  lastMutationLockFailure = "unverifiable";
40873
+ if (attempt + 1 < attempts && inconclusiveRetries < INCONCLUSIVE_PROBE_RETRY_LIMIT) {
40874
+ inconclusiveRetries += 1;
40875
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
40876
+ continue;
40877
+ }
40838
40878
  return null;
40839
40879
  }
40840
40880
  if (live) {
@@ -40866,7 +40906,7 @@ function cachedOwnerLive(owner, verified, slot, probe) {
40866
40906
  else if (live === false) verified.dead.push(owner);
40867
40907
  return live;
40868
40908
  }
40869
- function acquireLockAt(path30, attempts = 50, verified = { row: null, artifact: null, dead: [] }) {
40909
+ function acquireLockAt(path30, attempts = 50, verified = { row: null, artifact: null, dead: [], inconclusiveRetries: 0 }) {
40870
40910
  lastMutationLockFailureDetail = null;
40871
40911
  (0, import_fs26.mkdirSync)((0, import_path32.dirname)(path30), { recursive: true });
40872
40912
  const key = (() => {
@@ -40893,7 +40933,7 @@ function acquireLockAt(path30, attempts = 50, verified = { row: null, artifact:
40893
40933
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
40894
40934
  return acquireLockAt(path30, attempts - 1, verified);
40895
40935
  }
40896
- const processStart = ownProcessStartIdentity();
40936
+ const processStart = ownLockStartIdentity();
40897
40937
  if (!processStart) {
40898
40938
  try {
40899
40939
  db.close();
@@ -40907,7 +40947,7 @@ function acquireLockAt(path30, attempts = 50, verified = { row: null, artifact:
40907
40947
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
40908
40948
  return acquireLockAt(path30, attempts - 1, verified);
40909
40949
  }
40910
- const owner = { version: 1, pid: process.pid, processStart, createdAt: (/* @__PURE__ */ new Date()).toISOString(), nonce: (0, import_crypto8.randomUUID)() };
40950
+ const owner = { version: lockOwnerVersion(processStart), pid: process.pid, processStart, createdAt: (/* @__PURE__ */ new Date()).toISOString(), nonce: (0, import_crypto8.randomUUID)() };
40911
40951
  const selectRow = () => db.prepare("SELECT version, pid, process_start, created_at, nonce FROM state_mutation_locks WHERE lock_key = ?").get(key);
40912
40952
  let preLive = false;
40913
40953
  try {
@@ -40925,10 +40965,11 @@ function acquireLockAt(path30, attempts = 50, verified = { row: null, artifact:
40925
40965
  db.close();
40926
40966
  } catch {
40927
40967
  }
40928
- if (preLive === null || attempts <= 1) {
40968
+ if (attempts <= 1 || preLive === null && verified.inconclusiveRetries >= INCONCLUSIVE_PROBE_RETRY_LIMIT) {
40929
40969
  lastMutationLockFailure = preLive === null ? "unverifiable" : "contention";
40930
40970
  return null;
40931
40971
  }
40972
+ if (preLive === null) verified.inconclusiveRetries += 1;
40932
40973
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
40933
40974
  return acquireLockAt(path30, attempts - 1, verified);
40934
40975
  }
@@ -41002,7 +41043,7 @@ function acquireLockAt(path30, attempts = 50, verified = { row: null, artifact:
41002
41043
  return null;
41003
41044
  }
41004
41045
  }
41005
- db.prepare("INSERT INTO state_mutation_locks (lock_key, version, pid, process_start, created_at, nonce) VALUES (?, 1, ?, ?, ?, ?)").run(key, owner.pid, owner.processStart, owner.createdAt, owner.nonce);
41046
+ db.prepare("INSERT INTO state_mutation_locks (lock_key, version, pid, process_start, created_at, nonce) VALUES (?, ?, ?, ?, ?, ?)").run(key, owner.version, owner.pid, owner.processStart, owner.createdAt, owner.nonce);
41006
41047
  if (!publishLockOwner(path30, owner)) {
41007
41048
  abandonedOwnNonces.add(owner.nonce);
41008
41049
  db.exec("ROLLBACK");
@@ -42301,7 +42342,7 @@ function clearModeStateFile(mode, directory, sessionId, expectedState, cleanupSn
42301
42342
  }
42302
42343
  return success;
42303
42344
  }
42304
- var import_fs26, import_path32, import_crypto8, import_module2, require2, SQLITE_NATIVE_BINDING, SQLITE_NATIVE_BINDING_REMEDIATION, Database, sqliteBindingLoadError, localLocks, lastMutationLockFailure, lastMutationLockFailureDetail, abandonedOwnNonces, ownProcessStartIdentityCache, RELEASE_BUSY_BUDGET_MS;
42345
+ var import_fs26, import_path32, import_crypto8, import_module2, require2, SQLITE_NATIVE_BINDING, SQLITE_NATIVE_BINDING_REMEDIATION, Database, sqliteBindingLoadError, localLocks, lastMutationLockFailure, lastMutationLockFailureDetail, abandonedOwnNonces, INCONCLUSIVE_PROBE_RETRY_LIMIT, ownProcessStartIdentityCache, START_BOUND_PREFIX, START_BOUND_SLACK_MS, START_BOUND_ORIGIN_TOLERANCE_MS, ownStartBoundCache, RELEASE_BUSY_BUDGET_MS;
42305
42346
  var init_mode_state_io = __esm({
42306
42347
  "src/lib/mode-state-io.ts"() {
42307
42348
  "use strict";
@@ -42334,7 +42375,12 @@ var init_mode_state_io = __esm({
42334
42375
  lastMutationLockFailure = null;
42335
42376
  lastMutationLockFailureDetail = null;
42336
42377
  abandonedOwnNonces = /* @__PURE__ */ new Set();
42378
+ INCONCLUSIVE_PROBE_RETRY_LIMIT = 2;
42337
42379
  ownProcessStartIdentityCache = null;
42380
+ START_BOUND_PREFIX = "ticksmax:";
42381
+ START_BOUND_SLACK_MS = 20;
42382
+ START_BOUND_ORIGIN_TOLERANCE_MS = 1e3;
42383
+ ownStartBoundCache = null;
42338
42384
  RELEASE_BUSY_BUDGET_MS = 5e3;
42339
42385
  }
42340
42386
  });
@@ -18686,6 +18686,39 @@ function ownProcessStartIdentity() {
18686
18686
  }
18687
18687
  return ownProcessStartIdentityCache;
18688
18688
  }
18689
+ function ownStartBoundIdentity() {
18690
+ if (process.env.NODE_ENV === "test" && process.env.OMC_TEST_EMERGENCY_PROCESS_START_UNKNOWN_PID === String(process.pid)) return null;
18691
+ if (ownStartBoundCache !== null) return ownStartBoundCache;
18692
+ const origin = performance.timeOrigin;
18693
+ const uptimeOrigin = Date.now() - process.uptime() * 1e3;
18694
+ if (!Number.isFinite(origin) || origin <= 0 || Math.abs(origin - uptimeOrigin) > START_BOUND_ORIGIN_TOLERANCE_MS) return null;
18695
+ const wait = Math.ceil(START_BOUND_SLACK_MS - performance.now());
18696
+ if (wait > 0) Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, wait);
18697
+ ownStartBoundCache = `${START_BOUND_PREFIX}${BigInt(Math.ceil(origin + START_BOUND_SLACK_MS)) * 10000n + 621355968000000000n}`;
18698
+ return ownStartBoundCache;
18699
+ }
18700
+ function ownLockStartIdentity() {
18701
+ if (process.platform === "win32") {
18702
+ const bound = ownStartBoundIdentity();
18703
+ if (bound !== null) return bound;
18704
+ }
18705
+ return ownProcessStartIdentity();
18706
+ }
18707
+ function lockOwnerVersion(processStart) {
18708
+ return processStart.startsWith(START_BOUND_PREFIX) ? 2 : 1;
18709
+ }
18710
+ function validOwnerIdentity(version2, processStart) {
18711
+ if (typeof processStart !== "string") return false;
18712
+ if (version2 === 2) return /^ticksmax:\d+$/.test(processStart);
18713
+ return version2 === 1 && /^\S+$/.test(processStart) && !processStart.startsWith(START_BOUND_PREFIX);
18714
+ }
18715
+ function startIdentityMatches(recorded, current) {
18716
+ if (!recorded.startsWith(START_BOUND_PREFIX)) return current === recorded;
18717
+ const ticks = current.match(/^ticks:(\d+)$/)?.[1];
18718
+ const bound = recorded.slice(START_BOUND_PREFIX.length);
18719
+ if (!ticks || !/^\d+$/.test(bound)) return null;
18720
+ return BigInt(ticks) <= BigInt(bound);
18721
+ }
18689
18722
  function isStateMutationLockingSupported() {
18690
18723
  return !(process.env.NODE_ENV === "test" && process.env.OMC_TEST_STATE_LOCK_MODE === "none");
18691
18724
  }
@@ -18726,8 +18759,8 @@ function mutationDbPath(lockPath) {
18726
18759
  return (0, import_path20.join)(current, ".state-mutation-locks.db");
18727
18760
  }
18728
18761
  function ownerFromRow(row) {
18729
- if (!row || row.version !== 1 || !Number.isSafeInteger(row.pid) || row.pid <= 0 || typeof row.process_start !== "string" || typeof row.created_at !== "string" || typeof row.nonce !== "string") return null;
18730
- return { version: 1, pid: row.pid, processStart: row.process_start, createdAt: row.created_at, nonce: row.nonce };
18762
+ if (!row || !validOwnerIdentity(row.version, row.process_start) || !Number.isSafeInteger(row.pid) || row.pid <= 0 || typeof row.created_at !== "string" || typeof row.nonce !== "string") return null;
18763
+ return { version: row.version, pid: row.pid, processStart: row.process_start, createdAt: row.created_at, nonce: row.nonce };
18731
18764
  }
18732
18765
  function writeAllSync2(fd, content, label) {
18733
18766
  const bytes = Buffer.from(content, "utf8");
@@ -18743,7 +18776,7 @@ function readLockOwner(path15) {
18743
18776
  try {
18744
18777
  const value = JSON.parse((0, import_fs19.readFileSync)(path15, "utf8"));
18745
18778
  const pid = value.pid;
18746
- if (value.version !== 1 || !Number.isSafeInteger(pid) || pid <= 0 || typeof value.processStart !== "string" || !/^\S+$/.test(value.processStart) || typeof value.createdAt !== "string" || !Number.isFinite(Date.parse(value.createdAt)) || typeof value.nonce !== "string" || !/^[0-9a-f-]{36}$/i.test(value.nonce)) return null;
18779
+ if (!validOwnerIdentity(value.version, value.processStart) || !Number.isSafeInteger(pid) || pid <= 0 || typeof value.createdAt !== "string" || !Number.isFinite(Date.parse(value.createdAt)) || typeof value.nonce !== "string" || !/^[0-9a-f-]{36}$/i.test(value.nonce)) return null;
18747
18780
  return value;
18748
18781
  } catch (error2) {
18749
18782
  return error2.code === "ENOENT" ? "absent" : null;
@@ -18798,11 +18831,12 @@ function reclaimDeadLockOwner(path15, observedOwner, observedIdentity) {
18798
18831
  return "changed";
18799
18832
  }
18800
18833
  function ownerLive(owner) {
18801
- if (owner.pid === process.pid && abandonedOwnNonces.has(owner.nonce) && owner.processStart === ownProcessStartIdentity()) return false;
18834
+ if (owner.pid === process.pid && abandonedOwnNonces.has(owner.nonce) && owner.processStart === ownLockStartIdentity()) return false;
18802
18835
  if (process.env.NODE_ENV === "test" && process.env.OMC_TEST_EMERGENCY_PROCESS_START_UNKNOWN_PID === String(owner.pid)) return null;
18836
+ if (owner.pid === process.pid && owner.processStart === ownLockStartIdentity()) return true;
18803
18837
  const current = owner.pid === process.pid ? ownProcessStartIdentity() : processStartIdentity(owner.pid);
18804
18838
  if (current === null) return null;
18805
- return current === "absent" ? false : current === owner.processStart;
18839
+ return current === "absent" ? false : startIdentityMatches(owner.processStart, current);
18806
18840
  }
18807
18841
  function publishLockOwner(path15, owner) {
18808
18842
  const tempPath = `${path15}.${owner.pid}.${owner.nonce}.tmp`;
@@ -18878,15 +18912,16 @@ function acquireFileLockAt(path15, attempts) {
18878
18912
  return (0, import_path20.resolve)(path15);
18879
18913
  }
18880
18914
  })();
18881
- const processStart = ownProcessStartIdentity();
18915
+ const processStart = ownLockStartIdentity();
18882
18916
  if (!processStart || processStart === "absent") {
18883
18917
  lastMutationLockFailure = "unverifiable";
18884
18918
  return null;
18885
18919
  }
18886
18920
  let verifiedLiveOwner = null;
18921
+ let inconclusiveRetries = 0;
18887
18922
  for (let attempt = 0; attempt < attempts; attempt += 1) {
18888
18923
  const owner = {
18889
- version: 1,
18924
+ version: lockOwnerVersion(processStart),
18890
18925
  pid: process.pid,
18891
18926
  processStart,
18892
18927
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -18944,6 +18979,11 @@ function acquireFileLockAt(path15, attempts) {
18944
18979
  const live = verifiedLiveOwner !== null && sameOwner(existing, verifiedLiveOwner) ? true : ownerLive(existing);
18945
18980
  if (live === null) {
18946
18981
  lastMutationLockFailure = "unverifiable";
18982
+ if (attempt + 1 < attempts && inconclusiveRetries < INCONCLUSIVE_PROBE_RETRY_LIMIT) {
18983
+ inconclusiveRetries += 1;
18984
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
18985
+ continue;
18986
+ }
18947
18987
  return null;
18948
18988
  }
18949
18989
  if (live) {
@@ -18975,7 +19015,7 @@ function cachedOwnerLive(owner, verified, slot, probe) {
18975
19015
  else if (live === false) verified.dead.push(owner);
18976
19016
  return live;
18977
19017
  }
18978
- function acquireLockAt(path15, attempts = 50, verified = { row: null, artifact: null, dead: [] }) {
19018
+ function acquireLockAt(path15, attempts = 50, verified = { row: null, artifact: null, dead: [], inconclusiveRetries: 0 }) {
18979
19019
  lastMutationLockFailureDetail = null;
18980
19020
  (0, import_fs19.mkdirSync)((0, import_path20.dirname)(path15), { recursive: true });
18981
19021
  const key = (() => {
@@ -19002,7 +19042,7 @@ function acquireLockAt(path15, attempts = 50, verified = { row: null, artifact:
19002
19042
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
19003
19043
  return acquireLockAt(path15, attempts - 1, verified);
19004
19044
  }
19005
- const processStart = ownProcessStartIdentity();
19045
+ const processStart = ownLockStartIdentity();
19006
19046
  if (!processStart) {
19007
19047
  try {
19008
19048
  db.close();
@@ -19016,7 +19056,7 @@ function acquireLockAt(path15, attempts = 50, verified = { row: null, artifact:
19016
19056
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
19017
19057
  return acquireLockAt(path15, attempts - 1, verified);
19018
19058
  }
19019
- const owner = { version: 1, pid: process.pid, processStart, createdAt: (/* @__PURE__ */ new Date()).toISOString(), nonce: (0, import_crypto4.randomUUID)() };
19059
+ const owner = { version: lockOwnerVersion(processStart), pid: process.pid, processStart, createdAt: (/* @__PURE__ */ new Date()).toISOString(), nonce: (0, import_crypto4.randomUUID)() };
19020
19060
  const selectRow = () => db.prepare("SELECT version, pid, process_start, created_at, nonce FROM state_mutation_locks WHERE lock_key = ?").get(key);
19021
19061
  let preLive = false;
19022
19062
  try {
@@ -19034,10 +19074,11 @@ function acquireLockAt(path15, attempts = 50, verified = { row: null, artifact:
19034
19074
  db.close();
19035
19075
  } catch {
19036
19076
  }
19037
- if (preLive === null || attempts <= 1) {
19077
+ if (attempts <= 1 || preLive === null && verified.inconclusiveRetries >= INCONCLUSIVE_PROBE_RETRY_LIMIT) {
19038
19078
  lastMutationLockFailure = preLive === null ? "unverifiable" : "contention";
19039
19079
  return null;
19040
19080
  }
19081
+ if (preLive === null) verified.inconclusiveRetries += 1;
19041
19082
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
19042
19083
  return acquireLockAt(path15, attempts - 1, verified);
19043
19084
  }
@@ -19111,7 +19152,7 @@ function acquireLockAt(path15, attempts = 50, verified = { row: null, artifact:
19111
19152
  return null;
19112
19153
  }
19113
19154
  }
19114
- db.prepare("INSERT INTO state_mutation_locks (lock_key, version, pid, process_start, created_at, nonce) VALUES (?, 1, ?, ?, ?, ?)").run(key, owner.pid, owner.processStart, owner.createdAt, owner.nonce);
19155
+ db.prepare("INSERT INTO state_mutation_locks (lock_key, version, pid, process_start, created_at, nonce) VALUES (?, ?, ?, ?, ?, ?)").run(key, owner.version, owner.pid, owner.processStart, owner.createdAt, owner.nonce);
19115
19156
  if (!publishLockOwner(path15, owner)) {
19116
19157
  abandonedOwnNonces.add(owner.nonce);
19117
19158
  db.exec("ROLLBACK");
@@ -20118,7 +20159,7 @@ function findCompletedSessionStateCandidates(mode, directory, requesterSessionId
20118
20159
  function findCompletedSessionStateFiles(mode, directory, requesterSessionId) {
20119
20160
  return findCompletedSessionStateCandidates(mode, directory, requesterSessionId).map((candidate) => candidate.path);
20120
20161
  }
20121
- var import_fs19, import_path20, import_crypto4, import_module2, require2, SQLITE_NATIVE_BINDING, SQLITE_NATIVE_BINDING_REMEDIATION, Database, sqliteBindingLoadError, localLocks, lastMutationLockFailure, lastMutationLockFailureDetail, abandonedOwnNonces, ownProcessStartIdentityCache, RELEASE_BUSY_BUDGET_MS;
20162
+ var import_fs19, import_path20, import_crypto4, import_module2, require2, SQLITE_NATIVE_BINDING, SQLITE_NATIVE_BINDING_REMEDIATION, Database, sqliteBindingLoadError, localLocks, lastMutationLockFailure, lastMutationLockFailureDetail, abandonedOwnNonces, INCONCLUSIVE_PROBE_RETRY_LIMIT, ownProcessStartIdentityCache, START_BOUND_PREFIX, START_BOUND_SLACK_MS, START_BOUND_ORIGIN_TOLERANCE_MS, ownStartBoundCache, RELEASE_BUSY_BUDGET_MS;
20122
20163
  var init_mode_state_io = __esm({
20123
20164
  "src/lib/mode-state-io.ts"() {
20124
20165
  "use strict";
@@ -20151,7 +20192,12 @@ var init_mode_state_io = __esm({
20151
20192
  lastMutationLockFailure = null;
20152
20193
  lastMutationLockFailureDetail = null;
20153
20194
  abandonedOwnNonces = /* @__PURE__ */ new Set();
20195
+ INCONCLUSIVE_PROBE_RETRY_LIMIT = 2;
20154
20196
  ownProcessStartIdentityCache = null;
20197
+ START_BOUND_PREFIX = "ticksmax:";
20198
+ START_BOUND_SLACK_MS = 20;
20199
+ START_BOUND_ORIGIN_TOLERANCE_MS = 1e3;
20200
+ ownStartBoundCache = null;
20155
20201
  RELEASE_BUSY_BUDGET_MS = 5e3;
20156
20202
  }
20157
20203
  });
@@ -8,7 +8,9 @@ This compatibility command keeps `/oh-my-copilot:omc-setup` available without lo
8
8
 
9
9
  ## Dispatch
10
10
 
11
- 1. Read the full bundled skill instructions from the active OMC plugin/install: `skills/omc-setup/SKILL.md`.
11
+ <!-- Claude Code docs (plugins-reference, "Where each variable resolves"): for "Skill, command, and agent content", `${...}` resolves "Anywhere in the Markdown body". -->
12
+
13
+ 1. Read the full bundled skill instructions from `${CLAUDE_PLUGIN_ROOT}/skills/omc-setup/SKILL.md` (Claude Code substitutes the plugin root; if the placeholder is still literal, use the fallback below).
12
14
  2. Follow that SKILL.md exactly, treating the user's arguments as:
13
15
 
14
16
  ```text
@@ -0,0 +1,22 @@
1
+ export declare const RUNNER_CLOCK_ENV = "OMC_TEST_RUNNER_CLOCK_FILE";
2
+ export interface RunnerClock {
3
+ /** Runner process start, epoch ms (the origin run.cjs counts its inner timeout from). */
4
+ startedAt: number;
5
+ /** Epoch ms at which the runner's process 'exit' event fired. */
6
+ exitedAt: number;
7
+ /** exitedAt - startedAt. */
8
+ lifetimeMs: number;
9
+ }
10
+ /** node argv for a clocked run.cjs: `[...clockedRunnerArgs(runCjs, target)]`. */
11
+ export declare function clockedRunnerArgs(runCjsPath: string, ...args: string[]): string[];
12
+ /** Env entry that tells the preload where to write the clock record. */
13
+ export declare function runnerClockEnv(clockFile: string): Record<string, string>;
14
+ /** Read the record written at runner exit; throws if the runner never exited normally. */
15
+ export declare function readRunnerClock(clockFile: string): RunnerClock;
16
+ /**
17
+ * Test-side hang guard for a runner whose budget is `budgetMs`: the budget plus
18
+ * a scaled slack for process creation and exit notification. It only stops a
19
+ * hung runner; the budget assertion uses the runner's clock.
20
+ */
21
+ export declare function runnerHangGuardMs(budgetMs: number, slackMs?: number): number;
22
+ //# sourceMappingURL=runner-clock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner-clock.d.ts","sourceRoot":"","sources":["../../../src/__tests__/helpers/runner-clock.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,gBAAgB,+BAA+B,CAAC;AAE7D,MAAM,WAAW,WAAW;IAC1B,yFAAyF;IACzF,SAAS,EAAE,MAAM,CAAC;IAClB,iEAAiE;IACjE,QAAQ,EAAE,MAAM,CAAC;IACjB,4BAA4B;IAC5B,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,iFAAiF;AACjF,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAEjF;AAED,wEAAwE;AACxE,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAExE;AAED,0FAA0F;AAC1F,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,WAAW,CAM9D;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,SAAQ,GAAG,MAAM,CAE3E"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * The run.cjs runner's own clock, for tests that assert a wall-time budget.
3
+ *
4
+ * run.cjs counts its inner timeout from its own process start
5
+ * (`performance.timeOrigin`). A test that measures from its `spawn()` call to
6
+ * its `exit` event also counts two delays the runner does not control: the OS
7
+ * creating the process before node starts, and the test's event loop noticing
8
+ * the exit. Both grow without bound on a loaded host. These helpers start the
9
+ * runner with a `--require` preload (src/__tests__/fixtures/runner-clock.cjs)
10
+ * that records its start and exit, so the budget is asserted on the runner's
11
+ * clock while the declared budget itself stays unchanged.
12
+ *
13
+ * The test-side wall clock is still a hang guard: `runnerHangGuardMs` scales
14
+ * only the slack above the budget with the platform timing scale.
15
+ */
16
+ import { existsSync, readFileSync } from 'node:fs';
17
+ import { join } from 'node:path';
18
+ import { scaleTiming } from './platform.js';
19
+ const RUNNER_CLOCK_PRELOAD = join(process.cwd(), 'src', '__tests__', 'fixtures', 'runner-clock.cjs');
20
+ export const RUNNER_CLOCK_ENV = 'OMC_TEST_RUNNER_CLOCK_FILE';
21
+ /** node argv for a clocked run.cjs: `[...clockedRunnerArgs(runCjs, target)]`. */
22
+ export function clockedRunnerArgs(runCjsPath, ...args) {
23
+ return ['--require', RUNNER_CLOCK_PRELOAD, runCjsPath, ...args];
24
+ }
25
+ /** Env entry that tells the preload where to write the clock record. */
26
+ export function runnerClockEnv(clockFile) {
27
+ return { [RUNNER_CLOCK_ENV]: clockFile };
28
+ }
29
+ /** Read the record written at runner exit; throws if the runner never exited normally. */
30
+ export function readRunnerClock(clockFile) {
31
+ if (!existsSync(clockFile)) {
32
+ throw new Error(`run.cjs wrote no clock record at ${clockFile}: it was killed or never exited`);
33
+ }
34
+ const { startedAt, exitedAt } = JSON.parse(readFileSync(clockFile, 'utf8'));
35
+ return { startedAt, exitedAt, lifetimeMs: exitedAt - startedAt };
36
+ }
37
+ /**
38
+ * Test-side hang guard for a runner whose budget is `budgetMs`: the budget plus
39
+ * a scaled slack for process creation and exit notification. It only stops a
40
+ * hung runner; the budget assertion uses the runner's clock.
41
+ */
42
+ export function runnerHangGuardMs(budgetMs, slackMs = 1_000) {
43
+ return budgetMs + scaleTiming(slackMs);
44
+ }
45
+ //# sourceMappingURL=runner-clock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner-clock.js","sourceRoot":"","sources":["../../../src/__tests__/helpers/runner-clock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OA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test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook-stdin-budget.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/hook-stdin-budget.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,105 @@
1
+ import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
2
+ import { tmpdir } from 'node:os';
3
+ import { join } from 'node:path';
4
+ import { afterEach, describe, expect, it, vi } from 'vitest';
5
+ const runCjs = require('../../scripts/run.cjs');
6
+ const STDIN_LIB_PATH = '../../scripts/lib/stdin.mjs';
7
+ const originalPlatform = process.platform;
8
+ // stdin.mjs picks its margin from process.platform at import, so load a fresh
9
+ // copy with the platform under test.
10
+ async function stdinLibFor(platform) {
11
+ Object.defineProperty(process, 'platform', { value: platform });
12
+ try {
13
+ vi.resetModules();
14
+ return (await import(STDIN_LIB_PATH));
15
+ }
16
+ finally {
17
+ Object.defineProperty(process, 'platform', { value: originalPlatform });
18
+ }
19
+ }
20
+ afterEach(() => {
21
+ Object.defineProperty(process, 'platform', { value: originalPlatform });
22
+ vi.resetModules();
23
+ });
24
+ describe('hook stdin wait vs run.cjs inner budget', () => {
25
+ it('names the same env variables on both sides', async () => {
26
+ const lib = await stdinLibFor(originalPlatform);
27
+ expect(runCjs.HOOK_INNER_BUDGET_ENV).toBe('OMC_HOOK_INNER_BUDGET_MS');
28
+ expect(runCjs.HOOK_INNER_BUDGET_START_ENV).toBe('OMC_HOOK_INNER_BUDGET_START_MS');
29
+ expect(lib.HOOK_INNER_BUDGET_ENV).toBe(runCjs.HOOK_INNER_BUDGET_ENV);
30
+ expect(lib.HOOK_INNER_BUDGET_START_ENV).toBe(runCjs.HOOK_INNER_BUDGET_START_ENV);
31
+ });
32
+ const cases = [];
33
+ for (const platform of ['win32', 'linux']) {
34
+ cases.push({ platform, timeoutMs: 5000, event: 'PreToolUse' });
35
+ cases.push({ platform, timeoutMs: 3000, event: 'PostToolUse' });
36
+ }
37
+ it.each(cases)('derived wait plus margin fits the inner budget ($platform, $timeoutMs ms $event)', async ({ platform, timeoutMs, event }) => {
38
+ const lib = await stdinLibFor(platform);
39
+ const budget = runCjs.resolveInnerTimeoutMs({ timeoutMs, event }, platform);
40
+ const startedAt = Date.now();
41
+ // The env run.cjs hands the hook, read as the hook starts.
42
+ const env = runCjs.hookBudgetEnv(budget, startedAt);
43
+ expect(env[lib.HOOK_INNER_BUDGET_ENV]).toBe(String(budget));
44
+ // 5s hooks pass the platform constant as cap; 3s hooks use the default.
45
+ const wait = timeoutMs === 5000
46
+ ? lib.hookStdinTimeoutMs(lib.HOOK_STDIN_TIMEOUT_MS, lib.HOOK_STDIN_TIMEOUT_MS, env, startedAt)
47
+ : lib.hookStdinTimeoutMs(undefined, undefined, env, startedAt);
48
+ expect(wait).toBeGreaterThanOrEqual(lib.HOOK_STDIN_MIN_WAIT_MS);
49
+ expect(wait + lib.HOOK_STDIN_MARGIN_MS).toBeLessThanOrEqual(budget);
50
+ });
51
+ it('keeps the POSIX waits the hooks had before the budget was exported', async () => {
52
+ const lib = await stdinLibFor('linux');
53
+ const now = 50_000;
54
+ const env = (timeoutMs, event) => runCjs.hookBudgetEnv(runCjs.resolveInnerTimeoutMs({ timeoutMs, event }, 'linux'), now);
55
+ expect(lib.hookStdinTimeoutMs(lib.HOOK_STDIN_TIMEOUT_MS, lib.HOOK_STDIN_TIMEOUT_MS, env(5000, 'PreToolUse'), now)).toBe(3000);
56
+ expect(lib.hookStdinTimeoutMs(undefined, undefined, env(3000, 'PostToolUse'), now)).toBe(2000);
57
+ });
58
+ it('subtracts the start-up time already spent from the budget', async () => {
59
+ const lib = await stdinLibFor('win32');
60
+ const env = runCjs.hookBudgetEnv(3500, 10_000);
61
+ // 3500 - 400 elapsed - 1500 margin = 1600, capped at 1500.
62
+ expect(lib.hookStdinTimeoutMs(1500, 1500, env, 10_400)).toBe(1500);
63
+ // 3500 - 1200 elapsed - 1500 margin = 800.
64
+ expect(lib.hookStdinTimeoutMs(1500, 1500, env, 11_200)).toBe(800);
65
+ // Past the point where any wait fits: the floor.
66
+ expect(lib.hookStdinTimeoutMs(1500, 1500, env, 13_000)).toBe(lib.HOOK_STDIN_MIN_WAIT_MS);
67
+ // A clock that went backwards counts as no time spent.
68
+ expect(lib.hookStdinTimeoutMs(1500, 1500, env, 9_000)).toBe(1500);
69
+ // No start exported: the budget alone.
70
+ expect(lib.hookStdinTimeoutMs(5000, 5000, { [lib.HOOK_INNER_BUDGET_ENV]: '3500' }, 99_999)).toBe(2000);
71
+ });
72
+ it('falls back without a usable budget and floors a starved one', async () => {
73
+ const lib = await stdinLibFor(originalPlatform);
74
+ const key = lib.HOOK_INNER_BUDGET_ENV;
75
+ expect(lib.hookStdinTimeoutMs(1500, 1500, {})).toBe(1500);
76
+ expect(lib.hookStdinTimeoutMs(undefined, undefined, {})).toBe(2000);
77
+ for (const bad of ['', 'abc', '0', '-5', '12.5']) {
78
+ expect(lib.hookStdinTimeoutMs(2000, 777, { [key]: bad })).toBe(777);
79
+ }
80
+ expect(lib.hookStdinTimeoutMs(2000, 2000, { [key]: '1' })).toBe(lib.HOOK_STDIN_MIN_WAIT_MS);
81
+ expect(lib.hookStdinTimeoutMs(2000, 2000, { [key]: '600000' })).toBe(2000);
82
+ });
83
+ it('exports the budget and its start to a generic child', async () => {
84
+ const dir = mkdtempSync(join(tmpdir(), 'omc-stdin-budget-'));
85
+ try {
86
+ const probe = join(dir, 'probe.mjs');
87
+ const out = join(dir, 'budget.json');
88
+ writeFileSync(probe, "import { writeFileSync } from 'node:fs';\n" +
89
+ 'const env = process.env;\n' +
90
+ 'writeFileSync(process.argv[2], JSON.stringify([env.OMC_HOOK_INNER_BUDGET_MS, env.OMC_HOOK_INNER_BUDGET_START_MS]));\n');
91
+ const before = Date.now();
92
+ const status = await runCjs.runGenericChild(probe, [out], 30000, { timeoutMs: 31000, event: 'PostToolUse' });
93
+ expect(status).toBe(0);
94
+ const [budget, start] = JSON.parse(readFileSync(out, 'utf8'));
95
+ expect(budget).toBe('30000');
96
+ expect(Number.isInteger(Number(start))).toBe(true);
97
+ expect(Number(start)).toBeGreaterThanOrEqual(before - 1);
98
+ expect(Number(start)).toBeLessThanOrEqual(Date.now());
99
+ }
100
+ finally {
101
+ rmSync(dir, { recursive: true, force: true });
102
+ }
103
+ }, 40000);
104
+ });
105
+ //# sourceMappingURL=hook-stdin-budget.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook-stdin-budget.test.js","sourceRoot":"","sources":["../../src/__tests__/hook-stdin-budget.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE7D,MAAM,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;AAgBhD,MAAM,cAAc,GAAG,6BAA6B,CAAC;AACrD,MAAM,gBAAgB,GAAG,OAAO,CAAC,QAAQ,CAAC;AAE1C,8EAA8E;AAC9E,qCAAqC;AACrC,KAAK,UAAU,WAAW,CAAC,QAAyB;IAClD,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;IAChE,IAAI,CAAC;QACH,EAAE,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,CAAC,MAAM,MAAM,CAAC,cAAc,CAAC,CAAa,CAAC;IACpD,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,gBAAgB,EAAE,CAAC,CAAC;IAC1E,CAAC;AACH,CAAC;AAED,SAAS,CAAC,GAAG,EAAE;IACb,MAAM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AC,CAAC;QAChD,CAAC;IACH,CAAC,EAAE,KAAK,CAAC,CAAC;AACZ,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=parse-max-workers.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-max-workers.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/parse-max-workers.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ // @ts-expect-error plain .mjs helper without types
3
+ import { parseMaxWorkers } from '../../scripts/ci/parse-max-workers.mjs';
4
+ describe('parseMaxWorkers', () => {
5
+ it.each([['2', 2], ['10', 10], ['16', 16], [' 6 ', 6]])('accepts %j', (input, expected) => {
6
+ expect(parseMaxWorkers(input)).toBe(expected);
7
+ });
8
+ it.each(['8d', '1.5', '-2', '0', '', 'abc', undefined, '9'.repeat(30)])('rejects %j', (input) => {
9
+ expect(parseMaxWorkers(input)).toBe(0);
10
+ });
11
+ });
12
+ //# sourceMappingURL=parse-max-workers.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-max-workers.test.js","sourceRoot":"","sources":["../../src/__tests__/parse-max-workers.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,mDAAmD;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AAEzE,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;QACxF,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,KAAK,EAAE,EAAE;QAC9F,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}