harnery 0.44.0 → 0.45.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 (138) hide show
  1. package/dist/commands/workflow.d.ts.map +1 -1
  2. package/dist/commands/workflow.js +44 -0
  3. package/dist/core/agents/coord-client.d.ts.map +1 -1
  4. package/dist/core/agents/coord-client.js +18 -0
  5. package/dist/core/agents/live-authority-v3.d.ts +0 -1
  6. package/dist/core/agents/live-authority-v3.d.ts.map +1 -1
  7. package/dist/core/agents/live-authority-v3.js +0 -11
  8. package/dist/core/agents/live-lifecycle-v3.d.ts +2 -4
  9. package/dist/core/agents/live-lifecycle-v3.d.ts.map +1 -1
  10. package/dist/core/agents/live-lifecycle-v3.js +7 -28
  11. package/dist/core/agents/state/heartbeat-writer.d.ts.map +1 -1
  12. package/dist/core/agents/state/heartbeat-writer.js +14 -25
  13. package/dist/core/agents/state/live-coordination-writer.d.ts.map +1 -1
  14. package/dist/core/agents/state/live-coordination-writer.js +0 -5
  15. package/dist/core/agents/state/pidmap.d.ts.map +1 -1
  16. package/dist/core/agents/state/pidmap.js +0 -5
  17. package/dist/core/agents/state/proc-start.d.ts +5 -6
  18. package/dist/core/agents/state/proc-start.d.ts.map +1 -1
  19. package/dist/core/agents/state/proc-start.js +13 -9
  20. package/dist/core/agents/state/process-handle.d.ts +26 -0
  21. package/dist/core/agents/state/process-handle.d.ts.map +1 -0
  22. package/dist/core/agents/state/process-handle.js +121 -0
  23. package/dist/core/agents/state/stale-sweep.d.ts.map +1 -1
  24. package/dist/core/agents/state/stale-sweep.js +70 -180
  25. package/dist/core/artifacts/activity.d.ts +4 -1
  26. package/dist/core/artifacts/activity.d.ts.map +1 -1
  27. package/dist/core/artifacts/activity.js +8 -2
  28. package/dist/core/artifacts/index.d.ts.map +1 -1
  29. package/dist/core/artifacts/index.js +38 -12
  30. package/dist/core/events/v3/authority-outbox.d.ts.map +1 -1
  31. package/dist/core/events/v3/authority-outbox.js +0 -29
  32. package/dist/core/events/v3/producers/coordination-recorder.d.ts +0 -1
  33. package/dist/core/events/v3/producers/coordination-recorder.d.ts.map +1 -1
  34. package/dist/core/events/v3/producers/coordination-recorder.js +0 -7
  35. package/dist/core/events/v3/producers/recorder.d.ts.map +1 -1
  36. package/dist/core/events/v3/producers/recorder.js +64 -77
  37. package/dist/core/hooks/cli.js +78 -48
  38. package/dist/core/resources/service.d.ts +2 -16
  39. package/dist/core/resources/service.d.ts.map +1 -1
  40. package/dist/core/resources/service.js +1 -78
  41. package/dist/core/semantic/service.d.ts.map +1 -1
  42. package/dist/core/semantic/service.js +2 -9
  43. package/dist/core/servers/index.d.ts +4 -0
  44. package/dist/core/servers/index.d.ts.map +1 -1
  45. package/dist/core/servers/index.js +21 -3
  46. package/dist/core/storage/durable-history.js +56 -22
  47. package/dist/core/storage/segments.d.ts.map +1 -1
  48. package/dist/core/storage/segments.js +73 -17
  49. package/dist/core/supervisor/service.d.ts +2 -4
  50. package/dist/core/supervisor/service.d.ts.map +1 -1
  51. package/dist/core/work/state.js +7 -7
  52. package/dist/core/workflow/engine.d.ts.map +1 -1
  53. package/dist/core/workflow/engine.js +21 -65
  54. package/dist/core/workflow/index.d.ts +4 -2
  55. package/dist/core/workflow/index.d.ts.map +1 -1
  56. package/dist/core/workflow/index.js +2 -1
  57. package/dist/core/workflow/live-session-v3.d.ts +0 -6
  58. package/dist/core/workflow/live-session-v3.d.ts.map +1 -1
  59. package/dist/core/workflow/live-session-v3.js +5 -126
  60. package/dist/core/workflow/proof.d.ts +4 -4
  61. package/dist/core/workflow/proof.d.ts.map +1 -1
  62. package/dist/core/workflow/proof.js +4 -12
  63. package/dist/core/workflow/recovery-audit.d.ts +30 -0
  64. package/dist/core/workflow/recovery-audit.d.ts.map +1 -0
  65. package/dist/core/workflow/recovery-audit.js +116 -0
  66. package/dist/core/workflow/run-state.d.ts +19 -2
  67. package/dist/core/workflow/run-state.d.ts.map +1 -1
  68. package/dist/core/workflow/run-state.js +113 -8
  69. package/dist/core/workflow/spawn-claude.d.ts.map +1 -1
  70. package/dist/core/workflow/spawn-claude.js +0 -19
  71. package/dist/core/workflow/spawn-codex.d.ts.map +1 -1
  72. package/dist/core/workflow/spawn-codex.js +0 -13
  73. package/dist/core/workflow/spawn-cursor.d.ts.map +1 -1
  74. package/dist/core/workflow/spawn-cursor.js +0 -19
  75. package/dist/core/workflow/spawn-opencode.d.ts.map +1 -1
  76. package/dist/core/workflow/spawn-opencode.js +0 -14
  77. package/dist/core/workflow/types.d.ts +11 -54
  78. package/dist/core/workflow/types.d.ts.map +1 -1
  79. package/dist/core/workflow/workspaces/local-git.d.ts.map +1 -1
  80. package/dist/core/workflow/workspaces/local-git.js +70 -14
  81. package/dist/core/workflow/workspaces/reclaim.d.ts +6 -1
  82. package/dist/core/workflow/workspaces/reclaim.d.ts.map +1 -1
  83. package/dist/core/workflow/workspaces/recovery.d.ts +2 -0
  84. package/dist/core/workflow/workspaces/recovery.d.ts.map +1 -1
  85. package/dist/core/workflow/workspaces/recovery.js +24 -0
  86. package/dist/lib/identities/assume.d.ts.map +1 -1
  87. package/dist/lib/identities/assume.js +0 -4
  88. package/package.json +1 -1
  89. package/src/commands/workflow.ts +59 -0
  90. package/src/core/agents/coord-client.ts +20 -0
  91. package/src/core/agents/live-authority-v3.ts +0 -17
  92. package/src/core/agents/live-lifecycle-v3.ts +14 -52
  93. package/src/core/agents/state/heartbeat-writer.ts +12 -29
  94. package/src/core/agents/state/live-coordination-writer.ts +0 -29
  95. package/src/core/agents/state/pidmap.ts +0 -13
  96. package/src/core/agents/state/proc-start.ts +14 -11
  97. package/src/core/agents/state/process-handle.ts +165 -0
  98. package/src/core/agents/state/stale-sweep.ts +82 -247
  99. package/src/core/artifacts/activity.ts +9 -2
  100. package/src/core/artifacts/index.ts +45 -12
  101. package/src/core/events/v3/authority-outbox.ts +0 -56
  102. package/src/core/events/v3/producers/coordination-recorder.ts +0 -15
  103. package/src/core/events/v3/producers/recorder.ts +68 -94
  104. package/src/core/hooks/cli.ts +85 -47
  105. package/src/core/resources/service.ts +3 -88
  106. package/src/core/semantic/service.ts +2 -8
  107. package/src/core/servers/index.ts +30 -3
  108. package/src/core/storage/durable-history.ts +52 -20
  109. package/src/core/storage/segments.ts +79 -17
  110. package/src/core/supervisor/service.ts +2 -3
  111. package/src/core/work/state.ts +7 -7
  112. package/src/core/workflow/engine.ts +21 -73
  113. package/src/core/workflow/index.ts +12 -1
  114. package/src/core/workflow/live-session-v3.ts +5 -146
  115. package/src/core/workflow/proof.ts +5 -21
  116. package/src/core/workflow/recovery-audit.ts +181 -0
  117. package/src/core/workflow/run-state.ts +137 -8
  118. package/src/core/workflow/spawn-claude.ts +0 -18
  119. package/src/core/workflow/spawn-codex.ts +0 -13
  120. package/src/core/workflow/spawn-cursor.ts +0 -18
  121. package/src/core/workflow/spawn-opencode.ts +0 -14
  122. package/src/core/workflow/types.ts +11 -41
  123. package/src/core/workflow/workspaces/local-git.ts +86 -15
  124. package/src/core/workflow/workspaces/reclaim.ts +4 -0
  125. package/src/core/workflow/workspaces/recovery.ts +23 -0
  126. package/src/lib/identities/assume.ts +0 -4
  127. package/dist/core/agents/state/unchanged-file.d.ts +0 -44
  128. package/dist/core/agents/state/unchanged-file.d.ts.map +0 -1
  129. package/dist/core/agents/state/unchanged-file.js +0 -390
  130. package/dist/core/events/v3/generation-custody.d.ts +0 -5
  131. package/dist/core/events/v3/generation-custody.d.ts.map +0 -1
  132. package/dist/core/events/v3/generation-custody.js +0 -50
  133. package/dist/core/workflow/failure-evidence.d.ts +0 -16
  134. package/dist/core/workflow/failure-evidence.d.ts.map +0 -1
  135. package/dist/core/workflow/failure-evidence.js +0 -114
  136. package/src/core/agents/state/unchanged-file.ts +0 -456
  137. package/src/core/events/v3/generation-custody.ts +0 -59
  138. package/src/core/workflow/failure-evidence.ts +0 -141
@@ -1 +1 @@
1
- {"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../src/commands/workflow.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AA0EnD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CAmvBjF"}
1
+ {"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../src/commands/workflow.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAmFnD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CAqyBjF"}
@@ -475,6 +475,9 @@ export function registerWorkflowCommand(program, emit) {
475
475
  .description("Preview reclaim of an inactive owned workspace, or confirm salvage or discard and release.")
476
476
  .option("--yes", "Confirm that this commits or discards uncommitted work, then releases")
477
477
  .option("--discard", "Throw the uncommitted work away instead of salvaging it")
478
+ .option("--unknown-liveness <sha256>", "Recover unknown evidence pinned by the preview digest; active evidence still refuses")
479
+ .option("--actor <id>", "Actor responsible for an audited recovery")
480
+ .option("--reason <text>", "Reason for an audited recovery")
478
481
  .option("--json", "Emit the reclaim preview or confirmed result as JSON")
479
482
  .action(async (runId, opts) => {
480
483
  const coordRoot = resolveCoordRoot();
@@ -499,6 +502,13 @@ export function registerWorkflowCommand(program, emit) {
499
502
  const result = await provider.reclaim(binding, {
500
503
  mode: opts.discard ? "discard" : "salvage",
501
504
  yes: opts.yes,
505
+ unknownLiveness: opts.unknownLiveness
506
+ ? {
507
+ evidenceSha256: opts.unknownLiveness,
508
+ actor: opts.actor,
509
+ reason: opts.reason,
510
+ }
511
+ : undefined,
502
512
  });
503
513
  if (opts.json) {
504
514
  emit.config({ format: "json" });
@@ -509,6 +519,7 @@ export function registerWorkflowCommand(program, emit) {
509
519
  const holders = result.lease_holder.map((holder) => `${holder.scope}: ${holder.owner_id ?? "unknown"}${holder.pid ? ` (pid ${holder.pid})` : ""}${holder.detail ? `; ${holder.detail}` : ""}`);
510
520
  emit.text(`reclaim preview: ${result.run_id}\n` +
511
521
  `mode: ${result.mode}\nliveness: ${result.liveness}\nownership: ${result.ownership}\n` +
522
+ `evidence sha256: ${result.evidence_sha256}\n` +
512
523
  `lease holder: ${holders.length > 0 ? holders.join(", ") : "none observed"}\n` +
513
524
  `dirty paths: ${result.dirty_paths === null ? "unknown" : result.dirty_paths.length > 0 ? result.dirty_paths.join(", ") : "none"}\n` +
514
525
  (result.ownership_detail ? `ownership detail: ${result.ownership_detail}\n` : "") +
@@ -528,6 +539,39 @@ export function registerWorkflowCommand(program, emit) {
528
539
  process.exit(1);
529
540
  }
530
541
  });
542
+ workflow
543
+ .command("unlock <run-id>")
544
+ .description("Preview or explicitly retire one exact resume lock whose local owner is proven dead.")
545
+ .option("--lock-sha256 <sha256>", "Exact lock identity digest returned by the preview")
546
+ .option("--actor <id>", "Actor responsible for the recovery")
547
+ .option("--reason <text>", "Reason for the recovery")
548
+ .option("--yes", "Confirm removal after dead-owner and exact-lock checks")
549
+ .option("--json", "Emit the recovery preview or result as JSON")
550
+ .action(async (runId, opts) => {
551
+ try {
552
+ const coordRoot = resolveCoordRoot();
553
+ if (!coordRoot)
554
+ throw new Error("no .harnery/ coordination root found");
555
+ const { recoverWorkflowResumeLease } = await import("../core/workflow/index.js");
556
+ const result = recoverWorkflowResumeLease(coordRoot, runId, opts);
557
+ if (opts.json) {
558
+ emit.config({ format: "json" });
559
+ emit.data(result);
560
+ return;
561
+ }
562
+ emit.text(`resume lock ${result.action}: ${runId}\nowner: ${result.owner_state}\nlock sha256: ${result.lock_sha256 ?? "absent"}\n` +
563
+ (result.action === "preview"
564
+ ? "Pass --lock-sha256, --actor, --reason and --yes to confirm exact dead-owner recovery.\n"
565
+ : `recovery: ${result.recovery_id}\n`));
566
+ }
567
+ catch (error) {
568
+ emit.error({
569
+ code: "workflow_resume_unlock_failed",
570
+ message: error instanceof Error ? error.message : String(error),
571
+ });
572
+ process.exit(1);
573
+ }
574
+ });
531
575
  const approvals = program
532
576
  .command("approval")
533
577
  .description("Inspect and resolve durable run-policy approvals.");
@@ -1 +1 @@
1
- {"version":3,"file":"coord-client.d.ts","sourceRoot":"","sources":["../../../src/core/agents/coord-client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAeH;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAWhE;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,MAAM,CAI5E;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAOhF;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,IAAI,MAAM,GAAG,IAAI,CAE5C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,GAAE,MAAsB,GAAG,MAAM,GAAG,IAAI,CA+B7E;AAED,iEAAiE;AACjE,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAE7D;AAeD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGtD;AAiED,qEAAqE;AACrE,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIvD;AAED,+EAA+E;AAC/E,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG1D;AAED,mFAAmF;AACnF,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAExE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,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BAAkB,GAAG,MAAM,CAAC;CAC5F,CAsEA;AAED;;;;;;;;;GASG;AACH,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,MAAM,GACX;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAsB5C;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG;IAClD,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,MAAM,EAAE,QAAQ,GAAG,iBAAiB,GAAG,MAAM,CAAC;CAC/C,CAyBA;AAyBD,sFAAsF;AACtF;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,IAAI,MAAM,GAAG,IAAI,CAEtD;AAuCD;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAEpE;AAED;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAC9C,IAAI,EAAE,MAAM,GACX;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG,IAAI,CAmB9C;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAOpE"}
@@ -251,7 +251,25 @@ export function parsePidmapRowStartToken(row) {
251
251
  * a test can hold this one against `processStartToken` and fail on drift.
252
252
  */
253
253
  export function pidStartToken(pid) {
254
+ if (!Number.isInteger(pid) || pid <= 0)
255
+ return null;
254
256
  const forced = process.env.HARNERY_PID_PROBE;
257
+ if (process.platform === "win32" && forced !== "procfs" && forced !== "ps") {
258
+ try {
259
+ const out = spawnSync("powershell.exe", [
260
+ "-NoLogo",
261
+ "-NoProfile",
262
+ "-NonInteractive",
263
+ "-Command",
264
+ `$process = [Diagnostics.Process]::GetProcessById(${pid}); try { 'w' + $process.StartTime.ToFileTimeUtc().ToString([Globalization.CultureInfo]::InvariantCulture) } finally { $process.Dispose() }`,
265
+ ], { encoding: "utf8", timeout: 10_000, windowsHide: true });
266
+ const token = String(out.stdout ?? "").trim();
267
+ return out.status === 0 && /^w\d+$/.test(token) ? token : null;
268
+ }
269
+ catch {
270
+ return null;
271
+ }
272
+ }
255
273
  const useProcfs = forced === "procfs" || (forced !== "ps" && existsSync("/proc/self/stat"));
256
274
  // One machine, one probe. Falling back to the other on a read failure would
257
275
  // answer in the wrong dialect and read as a recycled pid.
@@ -38,7 +38,6 @@ interface LiveAuthorityBaseV3 {
38
38
  nativeSessionId: string;
39
39
  adapter: Adapter;
40
40
  observationId?: string;
41
- expectedGenerationId?: `gen_${string}`;
42
41
  }
43
42
  /**
44
43
  * Establish the missing generation authority for one adapter-native session,
@@ -1 +1 @@
1
- {"version":3,"file":"live-authority-v3.d.ts","sourceRoot":"","sources":["../../../src/core/agents/live-authority-v3.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAI7C,OAAO,EAAE,KAAK,gBAAgB,EAA2B,MAAM,yBAAyB,CAAC;AAgBzF,OAAO,EACL,KAAK,mCAAmC,EAEzC,MAAM,iDAAiD,CAAC;AASzD,OAAO,EAEL,KAAK,SAAS,EAMf,MAAM,6BAA6B,CAAC;AAQrC,eAAO,MAAM,gCAAgC,EAAG,iBAA0B,CAAC;AAE3E,qBAAa,gCAAiC,SAAQ,KAAK;aAC7B,MAAM,EAAE,MAAM;gBAAd,MAAM,EAAE,MAAM;CAI3C;AAED,MAAM,MAAM,iCAAiC,GACzC;IAAE,KAAK,EAAE,WAAW,CAAA;CAAE,GACtB;IAAE,KAAK,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,mCAAmC,CAAA;CAAE,CAAC;AAEvE,MAAM,WAAW,oCAAoC;IACnD,KAAK,EAAE,UAAU,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,mBAAmB,EAAE,OAAO,MAAM,EAAE,CAAC;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,iCAAiC,CAwBnC;AAuDD,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,CAI/E;AAaD,wBAAgB,kCAAkC,CAAC,SAAS,EAAE,SAAS,GAAG,UAAU,MAAM,EAAE,CAa3F"}
@@ -419,10 +419,6 @@ function recordLiveAuthority(input, signal, observation, expected, desired, appl
419
419
  platform: livePlatformV3(),
420
420
  expected_prior_state_digest: coordinationAuthorityStateDigestV3(expected),
421
421
  desired_state_digest: coordinationAuthorityStateDigestV3(desired),
422
- expected_generation_id: input.expectedGenerationId ??
423
- (subject === input.owner
424
- ? expected.v3_generation_id
425
- : readLiveCoordinationRow(input.coordRoot, input.owner)?.v3_generation_id),
426
422
  reconciler: {
427
423
  readStateDigest: () => {
428
424
  const heartbeat = readHeartbeat(input.coordRoot, subject);
@@ -452,16 +448,9 @@ export function liveCoordinationWriteModeV3(coordRoot) {
452
448
  return route.mode;
453
449
  }
454
450
  function requireHeartbeat(input, owner) {
455
- if (input.expectedGenerationId &&
456
- readLiveCoordinationRow(input.coordRoot, owner)?.v3_generation_id !== input.expectedGenerationId) {
457
- throw new LiveCoordinationAuthorityV3Error("expected_generation_changed");
458
- }
459
451
  const heartbeat = ensureLiveCoordinationHeartbeat(input.coordRoot, owner, owner === input.owner ? input.nativeSessionId : owner, input.adapter);
460
452
  if (!heartbeat)
461
453
  throw new LiveCoordinationAuthorityV3Error(`heartbeat_missing:${owner}`);
462
- if (input.expectedGenerationId && heartbeat.v3_generation_id !== input.expectedGenerationId) {
463
- throw new LiveCoordinationAuthorityV3Error("expected_generation_changed");
464
- }
465
454
  return heartbeat;
466
455
  }
467
456
  export function coordinationAuthorityStateDigestV3(heartbeat) {
@@ -11,12 +11,10 @@ interface LiveLifecycleObservationBaseV3 {
11
11
  adapter: EventAdapterIdV3;
12
12
  observedAt?: string;
13
13
  }
14
- interface LiveSweepObservationV3Input extends LiveLifecycleObservationBaseV3 {
15
- expectedGenerationId: `gen_${string}` | null;
14
+ export declare function recordLiveSweepObservationV3(input: LiveLifecycleObservationBaseV3 & {
16
15
  observation: "stale_heartbeat" | "killed" | "unparseable_heartbeat" | "missing_timestamp";
17
16
  ageMs: number;
18
- }
19
- export declare function recordLiveSweepObservationV3(input: LiveSweepObservationV3Input): LiveLifecycleObservationV3Result;
17
+ }): LiveLifecycleObservationV3Result;
20
18
  export declare function recordLiveResumeObservationV3(input: LiveLifecycleObservationBaseV3): LiveLifecycleObservationV3Result;
21
19
  export {};
22
20
  //# sourceMappingURL=live-lifecycle-v3.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"live-lifecycle-v3.d.ts","sourceRoot":"","sources":["../../../src/core/agents/live-lifecycle-v3.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAGnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAcxD,MAAM,MAAM,gCAAgC,GAAG;IAAE,KAAK,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC;AAErF,UAAU,8BAA8B;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,UAAU,2BAA4B,SAAQ,8BAA8B;IAC1E,oBAAoB,EAAE,OAAO,MAAM,EAAE,GAAG,IAAI,CAAC;IAC7C,WAAW,EAAE,iBAAiB,GAAG,QAAQ,GAAG,uBAAuB,GAAG,mBAAmB,CAAC;IAC1F,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,2BAA2B,GACjC,gCAAgC,CAqBlC;AAED,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,8BAA8B,GACpC,gCAAgC,CAalC"}
1
+ {"version":3,"file":"live-lifecycle-v3.d.ts","sourceRoot":"","sources":["../../../src/core/agents/live-lifecycle-v3.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAGnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAaxD,MAAM,MAAM,gCAAgC,GAAG;IAAE,KAAK,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC;AAErF,UAAU,8BAA8B;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,8BAA8B,GAAG;IACtC,WAAW,EAAE,iBAAiB,GAAG,QAAQ,GAAG,uBAAuB,GAAG,mBAAmB,CAAC;IAC1F,KAAK,EAAE,MAAM,CAAC;CACf,GACA,gCAAgC,CAOlC;AAED,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,8BAA8B,GACpC,gCAAgC,CAQlC"}
@@ -3,27 +3,17 @@ import { buildEventV3 } from "../events/v3/builder.js";
3
3
  import { normalizeNativeIdV3 } from "../events/v3/canonical.js";
4
4
  import { readEventV3ControlState } from "../events/v3/control.js";
5
5
  import { fingerprintContextV3 } from "../events/v3/fingerprint-keys.js";
6
- import { withGenerationCustodyV3 } from "../events/v3/generation-custody.js";
7
6
  import { liveInstanceIdV3, livePlatformV3, resolveLiveEventLedgerRouteV3, } from "../events/v3/live-routing.js";
8
7
  import { readJoinableHookProducerStateV3 } from "../events/v3/producers/recorder.js";
9
8
  import { writeEventV3 } from "../events/v3/writer.js";
10
9
  import { LiveCoordinationAuthorityV3Error } from "./live-authority-v3.js";
11
10
  import { liveCoordinationAdapterV3 } from "./state/live-coordination-view.js";
12
11
  export function recordLiveSweepObservationV3(input) {
13
- input = { ...input };
14
- // Reject stale observations before preparing durable custody state. The
15
- // in-custody checks cover replacement while acquiring custody and reentry.
16
- requireSweepHookState(input);
17
- return withGenerationCustodyV3(input.coordRoot, [liveInstanceIdV3(input.owner)], () => {
18
- requireSweepHookState(input);
19
- return recordObservation(input, "lifecycle.sweep_observed", {
20
- subject_instance_id: liveInstanceIdV3(input.owner),
21
- observation: input.observation,
22
- provisional: true,
23
- age_ms: Math.max(0, Math.floor(input.ageMs)),
24
- }, () => {
25
- requireSweepHookState(input);
26
- });
12
+ return recordObservation(input, "lifecycle.sweep_observed", {
13
+ subject_instance_id: liveInstanceIdV3(input.owner),
14
+ observation: input.observation,
15
+ provisional: true,
16
+ age_ms: Math.max(0, Math.floor(input.ageMs)),
27
17
  });
28
18
  }
29
19
  export function recordLiveResumeObservationV3(input) {
@@ -33,9 +23,9 @@ export function recordLiveResumeObservationV3(input) {
33
23
  prior_generation_id: hook.generation_id,
34
24
  continuity: "native",
35
25
  evidence_reference: "heartbeat_recreated",
36
- }, () => { });
26
+ });
37
27
  }
38
- function recordObservation(input, eventType, payload, beforeWrite) {
28
+ function recordObservation(input, eventType, payload) {
39
29
  const route = resolveLiveEventLedgerRouteV3(input.coordRoot);
40
30
  if (route.state === "blocked")
41
31
  throw new LiveCoordinationAuthorityV3Error(route.reason);
@@ -83,7 +73,6 @@ function recordObservation(input, eventType, payload, beforeWrite) {
83
73
  monotonic_ns: process.hrtime.bigint().toString(),
84
74
  };
85
75
  const event = buildEventV3(eventType, { ...common, payload });
86
- beforeWrite();
87
76
  const durability = writeEventV3(input.coordRoot, event, {
88
77
  expectedGenesisId: control.genesis.event.payload.genesis_id,
89
78
  });
@@ -92,16 +81,6 @@ function recordObservation(input, eventType, payload, beforeWrite) {
92
81
  }
93
82
  return { state: "recorded", event };
94
83
  }
95
- function requireSweepHookState(input) {
96
- if (typeof input.expectedGenerationId !== "string" ||
97
- !/^gen_[a-zA-Z0-9._-]+$/.test(input.expectedGenerationId)) {
98
- throw new LiveCoordinationAuthorityV3Error("hook_generation_not_joinable");
99
- }
100
- const hook = requireHookState(withAttestedAdapter(input));
101
- if (hook.generation_id !== input.expectedGenerationId) {
102
- throw new LiveCoordinationAuthorityV3Error("expected_generation_changed");
103
- }
104
- }
105
84
  function withAttestedAdapter(input) {
106
85
  const adapter = liveCoordinationAdapterV3(input.coordRoot, input.owner);
107
86
  if (!adapter)
@@ -1 +1 @@
1
- {"version":3,"file":"heartbeat-writer.d.ts","sourceRoot":"","sources":["../../../../src/core/agents/state/heartbeat-writer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAkBH,OAAO,EAAE,KAAK,SAAS,EAAgC,MAAM,uBAAuB,CAAC;AACrF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAE,KAAK,SAAS,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAatE,kFAAkF;AAClF,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,SAAS,EAChB,MAAM,CAAC,EAAE,MAAM,EACf,oBAAoB,CAAC,EAAE,MAAM,GAC5B,SAAS,GAAG,IAAI,CAQlB;AAkBD,wBAAgB,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAoB7F;AAED,6EAA6E;AAC7E,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,SAAS,GAAG,IAAI,CAUlB;AAED;;;;6BAI6B;AAC7B,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,SAAS,GAAG,UAAU,GAAG,WAAuB,GACrD,SAA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;GAgBG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,GACX,eAAe,EAAE,CA6BnB;AAED,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CASrF;AAED,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAiBnF"}
@@ -15,8 +15,6 @@
15
15
  */
16
16
  import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, unlinkSync, writeFileSync, } from "node:fs";
17
17
  import { dirname, join } from "node:path";
18
- import { assertCurrentGenerationV3, withGenerationCustodyV3, } from "../../events/v3/generation-custody.js";
19
- import { liveInstanceIdV3 } from "../../events/v3/live-routing.js";
20
18
  import { canonicalClaimPath } from "../claim-path.js";
21
19
  import { heartbeatPath, readHeartbeat } from "./heartbeat-reader.js";
22
20
  export { readHeartbeat } from "./heartbeat-reader.js";
@@ -40,16 +38,13 @@ export function setLifecycleCache(coordRoot, instanceId, state, reason, suggeste
40
38
  }));
41
39
  }
42
40
  function mutate(coordRoot, instanceId, fn) {
43
- return withGenerationCustodyV3(coordRoot, [liveInstanceIdV3(instanceId)], () => {
44
- const hb = readHeartbeat(coordRoot, instanceId);
45
- if (!hb)
46
- return null;
47
- const next = fn(hb);
48
- next.last_heartbeat = nowIsoSeconds();
49
- assertCurrentGenerationV3(coordRoot, liveInstanceIdV3(instanceId), hb.v3_generation_id);
50
- atomicWrite(heartbeatPath(coordRoot, instanceId), JSON.stringify(next, null, 2));
51
- return next;
52
- });
41
+ const hb = readHeartbeat(coordRoot, instanceId);
42
+ if (!hb)
43
+ return null;
44
+ const next = fn(hb);
45
+ next.last_heartbeat = nowIsoSeconds();
46
+ atomicWrite(heartbeatPath(coordRoot, instanceId), JSON.stringify(next, null, 2));
47
+ return next;
53
48
  }
54
49
  export function setTask(coordRoot, instanceId, task) {
55
50
  return mutate(coordRoot, instanceId, (hb) => {
@@ -73,16 +68,13 @@ export function setTask(coordRoot, instanceId, task) {
73
68
  }
74
69
  /** Update the disposable identity cache after a canonical V3 attestation. */
75
70
  export function setIdentityCache(coordRoot, instanceId, name, agentId) {
76
- return withGenerationCustodyV3(coordRoot, [liveInstanceIdV3(instanceId)], () => {
77
- const heartbeat = readHeartbeat(coordRoot, instanceId);
78
- if (!heartbeat)
79
- return null;
80
- heartbeat.name = name;
81
- heartbeat.agent_id = agentId;
82
- assertCurrentGenerationV3(coordRoot, liveInstanceIdV3(instanceId), heartbeat.v3_generation_id);
83
- atomicWrite(heartbeatPath(coordRoot, instanceId), JSON.stringify(heartbeat, null, 2));
84
- return heartbeat;
85
- });
71
+ const heartbeat = readHeartbeat(coordRoot, instanceId);
72
+ if (!heartbeat)
73
+ return null;
74
+ heartbeat.name = name;
75
+ heartbeat.agent_id = agentId;
76
+ atomicWrite(heartbeatPath(coordRoot, instanceId), JSON.stringify(heartbeat, null, 2));
77
+ return heartbeat;
86
78
  }
87
79
  /** Restore the pool-assigned display name on a generation that was
88
80
  * materialized before the adapter's normal SessionStart naming path ran.
@@ -256,9 +248,6 @@ export function clearCoordinationCache(coordRoot, instanceId) {
256
248
  }
257
249
  }
258
250
  export function healPidmap(coordRoot, instanceId, pid) {
259
- withGenerationCustodyV3(coordRoot, [liveInstanceIdV3(instanceId)], () => healPidmapUnderCustody(coordRoot, instanceId, pid));
260
- }
261
- function healPidmapUnderCustody(coordRoot, instanceId, pid) {
262
251
  const dir = join(coordRoot, ".harnery", "pid-map");
263
252
  mkdirSync(dir, { recursive: true });
264
253
  const hb = readHeartbeat(coordRoot, instanceId);
@@ -1 +1 @@
1
- {"version":3,"file":"live-coordination-writer.d.ts","sourceRoot":"","sources":["../../../../src/core/agents/state/live-coordination-writer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAUhD,OAAO,EAAE,KAAK,SAAS,EAAiB,MAAM,uBAAuB,CAAC;AAUtE;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC7C,SAAS,EAAE,MAAM,EACjB,gBAAgB,EAAE,MAAM,EACxB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,OAAO,EACjB,KAAK,CAAC,EAAE,MAAM,GACb,SAAS,GAAG,IAAI,CASlB;AAED,wFAAwF;AACxF,wBAAgB,+BAA+B,CAC7C,SAAS,EAAE,MAAM,EACjB,gBAAgB,EAAE,MAAM,EACxB,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,OAAO,EAChB,KAAK,CAAC,EAAE,MAAM,GACb,SAAS,GAAG,IAAI,CASlB"}
1
+ {"version":3,"file":"live-coordination-writer.d.ts","sourceRoot":"","sources":["../../../../src/core/agents/state/live-coordination-writer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAMhD,OAAO,EAAE,KAAK,SAAS,EAAiB,MAAM,uBAAuB,CAAC;AAUtE;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC7C,SAAS,EAAE,MAAM,EACjB,gBAAgB,EAAE,MAAM,EACxB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,OAAO,EACjB,KAAK,CAAC,EAAE,MAAM,GACb,SAAS,GAAG,IAAI,CASlB;AAED,wFAAwF;AACxF,wBAAgB,+BAA+B,CAC7C,SAAS,EAAE,MAAM,EACjB,gBAAgB,EAAE,MAAM,EACxB,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,OAAO,EAChB,KAAK,CAAC,EAAE,MAAM,GACb,SAAS,GAAG,IAAI,CASlB"}
@@ -1,7 +1,6 @@
1
1
  import { mkdirSync, renameSync, writeFileSync } from "node:fs";
2
2
  import { dirname, join } from "node:path";
3
3
  import { readCoordinationViewV3, requireAuthoritySafeCoordinationViewV3, } from "../../events/v3/coordination-view.js";
4
- import { assertCurrentGenerationV3, withGenerationCustodyV3, } from "../../events/v3/generation-custody.js";
5
4
  import { liveInstanceIdV3, resolveLiveEventLedgerRouteV3 } from "../../events/v3/live-routing.js";
6
5
  import { readHeartbeat } from "./heartbeat-reader.js";
7
6
  import { isAdapterV3, isCurrentV3HeartbeatCache, observedAdapterV3, projectHeartbeatV3, } from "./live-coordination-view.js";
@@ -20,9 +19,6 @@ export function repairLiveCoordinationHeartbeat(coordRoot, nativeInstanceId, nat
20
19
  return materializeLiveCoordinationHeartbeat(coordRoot, nativeInstanceId, nativeSessionId, adapter, model, true);
21
20
  }
22
21
  function materializeLiveCoordinationHeartbeat(coordRoot, nativeInstanceId, nativeSessionId, _adapter, model, force) {
23
- return withGenerationCustodyV3(coordRoot, [liveInstanceIdV3(nativeInstanceId)], () => materializeHeartbeatUnderCustody(coordRoot, nativeInstanceId, nativeSessionId, _adapter, model, force));
24
- }
25
- function materializeHeartbeatUnderCustody(coordRoot, nativeInstanceId, nativeSessionId, _adapter, model, force) {
26
22
  const route = resolveLiveEventLedgerRouteV3(coordRoot);
27
23
  if (route.state === "blocked")
28
24
  throw new Error(`event_v3_coordination_view:${route.reason}`);
@@ -89,7 +85,6 @@ function materializeHeartbeatUnderCustody(coordRoot, nativeInstanceId, nativeSes
89
85
  v3_projection_event_id: generation.last_event_id,
90
86
  v3_task_state: generation.task_state === "set" ? "set" : "cleared",
91
87
  };
92
- assertCurrentGenerationV3(coordRoot, liveInstanceIdV3(nativeInstanceId), generation.generation_id);
93
88
  writeHeartbeatCache(coordRoot, nativeInstanceId, materialized);
94
89
  return materialized;
95
90
  }
@@ -1 +1 @@
1
- {"version":3,"file":"pidmap.d.ts","sourceRoot":"","sources":["../../../../src/core/agents/state/pidmap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA2BH,6EAA6E;AAC7E,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG;IAC3C,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MA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8 +15,6 @@
15
15
  */
16
16
  import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, unlinkSync, writeFileSync, } from "node:fs";
17
17
  import { dirname, join } from "node:path";
18
- import { withGenerationCustodyV3 } from "../../events/v3/generation-custody.js";
19
- import { liveInstanceIdV3 } from "../../events/v3/live-routing.js";
20
18
  import { checkPidToken, processStartToken } from "./proc-start.js";
21
19
  /**
22
20
  * Row count that triggers a dead-row sweep on the next write.
@@ -112,9 +110,6 @@ export function prunePidmapDeadRows(coordRoot) {
112
110
  return removed;
113
111
  }
114
112
  export function writePidmapRow(coordRoot, pid, instanceId, platform) {
115
- withGenerationCustodyV3(coordRoot, [liveInstanceIdV3(instanceId)], () => writePidmapRowUnderCustody(coordRoot, pid, instanceId, platform));
116
- }
117
- function writePidmapRowUnderCustody(coordRoot, pid, instanceId, platform) {
118
113
  const dir = join(coordRoot, ".harnery", "pid-map");
119
114
  const path = join(dir, String(pid));
120
115
  // Stamped at write time, when the pid provably belongs to the process we
@@ -30,8 +30,9 @@
30
30
  * through the caller's locale and timezone, so both are pinned; without that,
31
31
  * two callers reading the same live process disagree.
32
32
  */
33
+ import { signalProcessWithHandle } from "./process-handle.js";
33
34
  /** Which probe answers "when did this process start?" on this machine. */
34
- export type StartTokenProbe = "procfs" | "ps";
35
+ export type StartTokenProbe = "procfs" | "ps" | "windows";
35
36
  /**
36
37
  * Which probe this machine uses, decided once.
37
38
  *
@@ -74,13 +75,11 @@ type ReadProcessStartToken = (pid: number) => string | null;
74
75
  export declare function verifyProcessGeneration(pid: number, recordedToken: string | null | undefined, readToken?: ReadProcessStartToken): ProcessGenerationVerdict;
75
76
  export interface ProcessGenerationSignalDependencies {
76
77
  readToken?: ReadProcessStartToken;
77
- kill?: (pid: number, signal: NodeJS.Signals | number) => unknown;
78
+ signalProcess?: typeof signalProcessWithHandle;
78
79
  }
79
80
  /**
80
- * Recheck the process generation immediately before sending the signal.
81
- *
82
- * The process can still exit and its PID can be reused between the token read
83
- * and the signal. Eliminating that race requires a generation-bound OS handle.
81
+ * Observations may refuse a signal, but only the retained native process handle
82
+ * can authorize it. No numeric-PID effect follows the preliminary token read.
84
83
  */
85
84
  export declare function signalIfSameGeneration(pid: number, recordedToken: string | null | undefined, signal: NodeJS.Signals | number, dependencies?: ProcessGenerationSignalDependencies): {
86
85
  sent: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"proc-start.d.ts","sourceRoot":"","sources":["../../../../src/core/agents/state/proc-start.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAMH,0EAA0E;AAC1E,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,IAAI,CAAC;AAc9C;;;;;;GAMG;AACH,wBAAgB,eAAe,IAAI,eAAe,CAOjD;AAyBD,uDAAuD;AACvD,wBAAgB,qBAAqB,IAAI,IAAI,CAG5C;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAc3D;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,EACX,GAAG,GAAE,CAAC,GAAG,EAAE,MAAM,KAAK;IAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAiB,GAC7E,MAAM,GAAG,IAAI,CAUf;AAWD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAG5D;AAED,MAAM,MAAM,wBAAwB,GAAG,MAAM,GAAG,WAAW,GAAG,SAAS,CAAC;AAExE,KAAK,qBAAqB,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;AAE5D,wEAAwE;AACxE,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,MAAM,EACX,aAAa,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACxC,SAAS,GAAE,qBAA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AKrC"}
@@ -33,6 +33,7 @@
33
33
  import { spawnSync } from "node:child_process";
34
34
  import { existsSync, readFileSync } from "node:fs";
35
35
  import { coordEnv } from "../../../lib/env.js";
36
+ import { signalProcessWithHandle, windowsProcessStartToken } from "./process-handle.js";
36
37
  /**
37
38
  * The `ps` probe is text formatted by `strftime("%c", localtime(...))`, so its
38
39
  * output moves with `TZ` and `LC_TIME`. A hook running under `LC_ALL=C` (git
@@ -54,6 +55,8 @@ export function startTokenProbe() {
54
55
  const override = coordEnv("PID_PROBE");
55
56
  if (override === "procfs" || override === "ps")
56
57
  return override;
58
+ if (process.platform === "win32")
59
+ return "windows";
57
60
  if (cachedProbe === undefined) {
58
61
  cachedProbe = existsSync("/proc/self/stat") ? "procfs" : "ps";
59
62
  }
@@ -149,7 +152,12 @@ function defaultPsRun(pid) {
149
152
  export function processStartToken(pid) {
150
153
  if (!Number.isFinite(pid) || pid <= 0)
151
154
  return null;
152
- return startTokenProbe() === "procfs" ? procfsStartToken(pid) : psStartToken(pid);
155
+ const probe = startTokenProbe();
156
+ return probe === "windows"
157
+ ? windowsProcessStartToken(pid)
158
+ : probe === "procfs"
159
+ ? procfsStartToken(pid)
160
+ : psStartToken(pid);
153
161
  }
154
162
  /** A missing or unreadable token never establishes process identity. */
155
163
  export function verifyProcessGeneration(pid, recordedToken, readToken = processStartToken) {
@@ -174,22 +182,18 @@ export function verifyProcessGeneration(pid, recordedToken, readToken = processS
174
182
  }
175
183
  }
176
184
  /**
177
- * Recheck the process generation immediately before sending the signal.
178
- *
179
- * The process can still exit and its PID can be reused between the token read
180
- * and the signal. Eliminating that race requires a generation-bound OS handle.
185
+ * Observations may refuse a signal, but only the retained native process handle
186
+ * can authorize it. No numeric-PID effect follows the preliminary token read.
181
187
  */
182
188
  export function signalIfSameGeneration(pid, recordedToken, signal, dependencies = {}) {
183
- const kill = dependencies.kill ?? process.kill;
184
189
  const verdict = verifyProcessGeneration(pid, recordedToken, dependencies.readToken);
185
190
  if (verdict !== "same")
186
191
  return { sent: false, verdict };
187
192
  try {
188
- kill(pid, signal);
189
- return { sent: true, verdict };
193
+ return (dependencies.signalProcess ?? signalProcessWithHandle)(pid, recordedToken, signal);
190
194
  }
191
195
  catch {
192
- return { sent: false, verdict };
196
+ return { sent: false, verdict: "unknown" };
193
197
  }
194
198
  }
195
199
  /**
@@ -0,0 +1,26 @@
1
+ import type { ProcessGenerationVerdict } from "./proc-start.js";
2
+ export interface ProcessHandleSignalResult {
3
+ sent: boolean;
4
+ verdict: ProcessGenerationVerdict;
5
+ }
6
+ export type NativeProcessHelperRunner = (command: string, args: string[], options: {
7
+ input: string;
8
+ encoding: "utf8";
9
+ timeout: number;
10
+ maxBuffer: number;
11
+ windowsHide: boolean;
12
+ }) => {
13
+ status: number | null;
14
+ stdout: string | Buffer | null;
15
+ error?: Error;
16
+ };
17
+ export declare const LINUX_PROCESS_HANDLE_SCRIPT = "\nimport json, os, pathlib, signal, sys\nresult = {\"sent\": False, \"verdict\": \"unknown\"}\nfd = None\ntry:\n request = json.loads(sys.stdin.readline())\n if not hasattr(os, \"pidfd_open\") or not hasattr(signal, \"pidfd_send_signal\"):\n raise RuntimeError(\"pidfd support unavailable\")\n fd = os.pidfd_open(request[\"pid\"])\n stat = pathlib.Path(\"/proc/%d/stat\" % request[\"pid\"]).read_text()\n ticks = stat[stat.rfind(\") \") + 2:].split()[19]\n boot = pathlib.Path(\"/proc/sys/kernel/random/boot_id\").read_text().strip().replace(\"-\", \"\")[:8]\n token = \"l%s.%s\" % (boot, ticks)\n result[\"token\"] = token\n recorded = request.get(\"token\")\n result[\"verdict\"] = \"same\" if token == recorded else \"different\"\n if request[\"mode\"] == \"signal\" and result[\"verdict\"] == \"same\":\n print(json.dumps({\"phase\": \"verified\"}), flush=True)\n if sys.stdin.readline().strip() == \"signal\":\n signal.pidfd_send_signal(fd, request[\"signal\"])\n result[\"sent\"] = True\nexcept Exception:\n pass\nfinally:\n if fd is not None:\n os.close(fd)\nprint(json.dumps(result), flush=True)\n";
18
+ export declare const WINDOWS_PROCESS_HANDLE_SCRIPT = "\n$ErrorActionPreference = 'Stop'\n$result = @{ sent = $false; verdict = 'unknown' }\n$handle = [IntPtr]::Zero\ntry {\n Add-Type -TypeDefinition @'\nusing System;\nusing System.Runtime.InteropServices;\npublic static class HarneryProcessHandle {\n [DllImport(\"kernel32.dll\", SetLastError=true)] public static extern IntPtr OpenProcess(uint access, bool inherit, uint processId);\n [DllImport(\"kernel32.dll\", SetLastError=true)] public static extern bool GetProcessTimes(IntPtr handle, out long creation, out long exit, out long kernel, out long user);\n [DllImport(\"kernel32.dll\", SetLastError=true)] public static extern bool TerminateProcess(IntPtr handle, uint exitCode);\n [DllImport(\"kernel32.dll\")] public static extern uint WaitForSingleObject(IntPtr handle, uint milliseconds);\n [DllImport(\"kernel32.dll\")] public static extern bool CloseHandle(IntPtr handle);\n}\n'@\n $request = [Console]::In.ReadLine() | ConvertFrom-Json\n $access = [uint32]0x101000\n if ($request.mode -eq 'signal') { $access = $access -bor 1 }\n $handle = [HarneryProcessHandle]::OpenProcess($access, $false, [uint32]$request.pid)\n if ($handle -eq [IntPtr]::Zero) { throw 'process handle unavailable' }\n [long]$creation = 0; [long]$exitTime = 0; [long]$kernel = 0; [long]$userTime = 0\n if (-not [HarneryProcessHandle]::GetProcessTimes($handle, [ref]$creation, [ref]$exitTime, [ref]$kernel, [ref]$userTime)) { throw 'process time unavailable' }\n $token = 'w' + $creation.ToString([Globalization.CultureInfo]::InvariantCulture)\n $result.token = $token\n $result.verdict = if ($token -ceq $request.token) { 'same' } else { 'different' }\n if ($request.mode -eq 'signal' -and $result.verdict -eq 'same') {\n [Console]::Out.WriteLine('{\"phase\":\"verified\"}')\n [Console]::Out.Flush()\n if ([Console]::In.ReadLine() -eq 'signal' -and [HarneryProcessHandle]::WaitForSingleObject($handle, 0) -eq 258) {\n $result.sent = [HarneryProcessHandle]::TerminateProcess($handle, 1)\n }\n }\n} catch {} finally {\n if ($handle -ne [IntPtr]::Zero) { [void][HarneryProcessHandle]::CloseHandle($handle) }\n}\n$result | ConvertTo-Json -Compress\n";
19
+ /** Windows creation FILETIME, read from an OpenProcess handle. */
20
+ export declare function windowsProcessStartToken(pid: number, run?: NativeProcessHelperRunner): string | null;
21
+ /** No numeric-PID signaling fallback is permitted when an exact handle fails. */
22
+ export declare function signalProcessWithHandle(pid: number, recordedToken: string, signal: NodeJS.Signals | number, options?: {
23
+ platform?: NodeJS.Platform;
24
+ run?: NativeProcessHelperRunner;
25
+ }): ProcessHandleSignalResult;
26
+ //# sourceMappingURL=process-handle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-handle.d.ts","sourceRoot":"","sources":["../../../../src/core/agents/state/process-handle.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAEhE,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,wBAAwB,CAAC;CACnC;AAMD,MAAM,MAAM,yBAAyB,GAAG,CACtC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,EAAE;IACP,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,OAAO,CAAC;CACtB,KACE;IAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AAI9E,eAAO,MAAM,2BAA2B,+qCA2BvC,CAAC;AAEF,eAAO,MAAM,6BAA6B,qnEAqCzC,CAAC;AAwCF,kEAAkE;AAClE,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,MAAM,EACX,GAAG,GAAE,yBAAqC,GACzC,MAAM,GAAG,IAAI,CAGf;AAED,iFAAiF;AACjF,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,MAAM,EACX,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,MAAM,EAC/B,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC;IAAC,GAAG,CAAC,EAAE,yBAAyB,CAAA;CAAO,GAC5E,yBAAyB,CAgB3B"}