harnery 0.45.1 → 0.46.0
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.
- package/dist/commander.d.ts +13 -0
- package/dist/commander.d.ts.map +1 -1
- package/dist/commands/admission.d.ts.map +1 -1
- package/dist/commands/admission.js +214 -27
- package/dist/commands/agents.d.ts +4 -0
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +102 -25
- package/dist/commands/browse.d.ts +3 -0
- package/dist/commands/browse.d.ts.map +1 -1
- package/dist/commands/browse.js +172 -8
- package/dist/commands/fetch.js +1 -0
- package/dist/commands/ledger-v3.d.ts.map +1 -1
- package/dist/commands/ledger-v3.js +8 -2
- package/dist/commands/presence.d.ts.map +1 -1
- package/dist/commands/presence.js +40 -0
- package/dist/commands/qa-run.d.ts.map +1 -1
- package/dist/commands/qa-run.js +4 -3
- package/dist/commands/review-pack.d.ts.map +1 -1
- package/dist/commands/review-pack.js +33 -6
- package/dist/commands/workflow.d.ts.map +1 -1
- package/dist/commands/workflow.js +6 -45
- package/dist/core/agents/coord-client.d.ts.map +1 -1
- package/dist/core/agents/coord-client.js +0 -18
- package/dist/core/agents/index.d.ts +1 -0
- package/dist/core/agents/index.d.ts.map +1 -1
- package/dist/core/agents/index.js +1 -0
- package/dist/core/agents/live-authority-v3.d.ts.map +1 -1
- package/dist/core/agents/live-authority-v3.js +11 -4
- package/dist/core/agents/render/session-context.d.ts +0 -6
- package/dist/core/agents/render/session-context.d.ts.map +1 -1
- package/dist/core/agents/render/session-context.js +1 -6
- package/dist/core/agents/session-events.d.ts.map +1 -1
- package/dist/core/agents/session-events.js +12 -4
- package/dist/core/agents/state/heartbeat-reader.d.ts +3 -0
- package/dist/core/agents/state/heartbeat-reader.d.ts.map +1 -1
- package/dist/core/agents/state/live-coordination-view.d.ts +3 -1
- package/dist/core/agents/state/live-coordination-view.d.ts.map +1 -1
- package/dist/core/agents/state/live-coordination-view.js +6 -2
- package/dist/core/agents/state/parent-reference-contract.d.ts +16 -0
- package/dist/core/agents/state/parent-reference-contract.d.ts.map +1 -0
- package/dist/core/agents/state/parent-reference-contract.js +1 -0
- package/dist/core/agents/state/parent-reference.d.ts +18 -0
- package/dist/core/agents/state/parent-reference.d.ts.map +1 -0
- package/dist/core/agents/state/parent-reference.js +119 -0
- package/dist/core/agents/state/pidmap.js +2 -2
- package/dist/core/agents/state/proc-start.d.ts +20 -31
- package/dist/core/agents/state/proc-start.d.ts.map +1 -1
- package/dist/core/agents/state/proc-start.js +37 -70
- package/dist/core/agents/state/service-process.d.ts +61 -0
- package/dist/core/agents/state/service-process.d.ts.map +1 -0
- package/dist/core/agents/state/service-process.js +143 -0
- package/dist/core/config.d.ts +39 -0
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +63 -0
- package/dist/core/context/index.d.ts +6 -4
- package/dist/core/context/index.d.ts.map +1 -1
- package/dist/core/context/index.js +194 -256
- package/dist/core/context/observation.d.ts +9 -9
- package/dist/core/context/observation.d.ts.map +1 -1
- package/dist/core/context/observation.js +37 -6
- package/dist/core/diagnostics/path-identity.d.ts +1 -1
- package/dist/core/diagnostics/path-identity.d.ts.map +1 -1
- package/dist/core/diagnostics/path-identity.js +51 -6
- package/dist/core/events/v3/canonical.js +43 -14
- package/dist/core/events/v3/index.d.ts +1 -1
- package/dist/core/events/v3/index.d.ts.map +1 -1
- package/dist/core/events/v3/index.js +1 -1
- package/dist/core/events/v3/producers/recorder.d.ts +34 -0
- package/dist/core/events/v3/producers/recorder.d.ts.map +1 -1
- package/dist/core/events/v3/producers/recorder.js +117 -13
- package/dist/core/events/v3/reader.d.ts.map +1 -1
- package/dist/core/events/v3/reader.js +53 -13
- package/dist/core/events/v3/runtime-build.d.ts +14 -0
- package/dist/core/events/v3/runtime-build.d.ts.map +1 -1
- package/dist/core/events/v3/runtime-build.js +44 -0
- package/dist/core/events/v3/validate.d.ts.map +1 -1
- package/dist/core/events/v3/validate.js +36 -1
- package/dist/core/governor/index.d.ts +2 -1
- package/dist/core/governor/index.d.ts.map +1 -1
- package/dist/core/governor/index.js +2 -1
- package/dist/core/governor/service-read.d.ts +3 -10
- package/dist/core/governor/service-read.d.ts.map +1 -1
- package/dist/core/governor/service-read.js +10 -94
- package/dist/core/governor/service.d.ts +3 -7
- package/dist/core/governor/service.d.ts.map +1 -1
- package/dist/core/governor/service.js +17 -182
- package/dist/core/hooks/adapter/native-parent.d.ts +23 -0
- package/dist/core/hooks/adapter/native-parent.d.ts.map +1 -0
- package/dist/core/hooks/adapter/native-parent.js +91 -0
- package/dist/core/hooks/cli.js +79 -4
- package/dist/core/hooks/resolve/owner.d.ts +0 -11
- package/dist/core/hooks/resolve/owner.d.ts.map +1 -1
- package/dist/core/hooks/resolve/owner.js +2 -25
- package/dist/core/hooks/shell-admission.d.ts +84 -0
- package/dist/core/hooks/shell-admission.d.ts.map +1 -0
- package/dist/core/hooks/shell-admission.js +622 -0
- package/dist/core/hooks/shell-commit-tree.d.ts +2 -0
- package/dist/core/hooks/shell-commit-tree.d.ts.map +1 -0
- package/dist/core/hooks/shell-commit-tree.js +104 -0
- package/dist/core/inbox/contract.d.ts +12 -0
- package/dist/core/inbox/contract.d.ts.map +1 -1
- package/dist/core/inbox/contract.js +16 -0
- package/dist/core/inbox/peer-messages.d.ts +41 -16
- package/dist/core/inbox/peer-messages.d.ts.map +1 -1
- package/dist/core/inbox/peer-messages.js +372 -15
- package/dist/core/inbox/service.d.ts +8 -1
- package/dist/core/inbox/service.d.ts.map +1 -1
- package/dist/core/inbox/service.js +83 -3
- package/dist/core/inbox/targets.d.ts +17 -3
- package/dist/core/inbox/targets.d.ts.map +1 -1
- package/dist/core/inbox/targets.js +77 -2
- package/dist/core/presence/git.d.ts +18 -12
- package/dist/core/presence/git.d.ts.map +1 -1
- package/dist/core/presence/git.js +32 -38
- package/dist/core/presence/index.d.ts +2 -2
- package/dist/core/presence/index.d.ts.map +1 -1
- package/dist/core/presence/index.js +8 -6
- package/dist/core/presence/mail.d.ts +133 -0
- package/dist/core/presence/mail.d.ts.map +1 -0
- package/dist/core/presence/mail.js +464 -0
- package/dist/core/resources/sampler.js +2 -2
- package/dist/core/resources/service-status.d.ts +2 -14
- package/dist/core/resources/service-status.d.ts.map +1 -1
- package/dist/core/resources/service-status.js +3 -23
- package/dist/core/resources/service.d.ts +3 -7
- package/dist/core/resources/service.d.ts.map +1 -1
- package/dist/core/resources/service.js +12 -101
- package/dist/core/resources/status.d.ts.map +1 -1
- package/dist/core/resources/status.js +3 -2
- package/dist/core/semantic/contract.d.ts +5 -5
- package/dist/core/semantic/service.d.ts.map +1 -1
- package/dist/core/semantic/service.js +9 -2
- package/dist/core/servers/index.d.ts +0 -2
- package/dist/core/servers/index.d.ts.map +1 -1
- package/dist/core/servers/index.js +3 -18
- package/dist/core/storage/modes.d.ts +4 -0
- package/dist/core/storage/modes.d.ts.map +1 -1
- package/dist/core/storage/modes.js +4 -0
- package/dist/core/storage/segments.d.ts.map +1 -1
- package/dist/core/storage/segments.js +5 -4
- package/dist/core/supervisor/service.d.ts +4 -7
- package/dist/core/supervisor/service.d.ts.map +1 -1
- package/dist/core/supervisor/service.js +23 -122
- package/dist/core/supervisor/services.js +2 -2
- package/dist/core/supervisor/status.d.ts +3 -17
- package/dist/core/supervisor/status.d.ts.map +1 -1
- package/dist/core/supervisor/status.js +7 -70
- package/dist/core/workflow/engine.js +2 -1
- package/dist/core/workflow/index.d.ts +3 -4
- package/dist/core/workflow/index.d.ts.map +1 -1
- package/dist/core/workflow/index.js +2 -2
- package/dist/core/workflow/proof.d.ts.map +1 -1
- package/dist/core/workflow/proof.js +30 -74
- package/dist/core/workflow/resume-lock.d.ts +17 -0
- package/dist/core/workflow/resume-lock.d.ts.map +1 -0
- package/dist/core/workflow/resume-lock.js +158 -0
- package/dist/core/workflow/run-state.d.ts +0 -21
- package/dist/core/workflow/run-state.d.ts.map +1 -1
- package/dist/core/workflow/run-state.js +3 -174
- package/dist/core/workflow/workspaces/leases.d.ts +4 -0
- package/dist/core/workflow/workspaces/leases.d.ts.map +1 -1
- package/dist/core/workflow/workspaces/leases.js +1 -1
- package/dist/core/workflow/workspaces/local-git.js +91 -210
- package/dist/core/workflow/workspaces/ownership.d.ts +0 -7
- package/dist/core/workflow/workspaces/ownership.d.ts.map +1 -1
- package/dist/core/workflow/workspaces/ownership.js +3 -130
- package/dist/core/workflow/workspaces/reclaim.d.ts +4 -7
- package/dist/core/workflow/workspaces/reclaim.d.ts.map +1 -1
- package/dist/core/workflow/workspaces/reclaim.js +0 -4
- package/dist/core/workflow/workspaces/recovery.d.ts +1 -1
- package/dist/core/workflow/workspaces/recovery.d.ts.map +1 -1
- package/dist/core/workflow/workspaces/recovery.js +1 -1
- package/dist/core/workflow/workspaces/state.d.ts.map +1 -1
- package/dist/core/workflow/workspaces/state.js +1 -4
- package/dist/lib/admission-history.d.ts +96 -0
- package/dist/lib/admission-history.d.ts.map +1 -0
- package/dist/lib/admission-history.js +196 -0
- package/dist/lib/admission.d.ts +56 -7
- package/dist/lib/admission.d.ts.map +1 -1
- package/dist/lib/admission.js +161 -19
- package/dist/lib/browser/client.d.ts +18 -0
- package/dist/lib/browser/client.d.ts.map +1 -1
- package/dist/lib/browser/client.js +100 -12
- package/dist/lib/browser/content-checks.d.ts +3 -1
- package/dist/lib/browser/content-checks.d.ts.map +1 -1
- package/dist/lib/browser/content-checks.js +10 -2
- package/dist/lib/browser/critique.d.ts +32 -0
- package/dist/lib/browser/critique.d.ts.map +1 -1
- package/dist/lib/browser/critique.js +72 -3
- package/dist/lib/browser/geometry.d.ts +2 -0
- package/dist/lib/browser/geometry.d.ts.map +1 -1
- package/dist/lib/browser/geometry.js +61 -15
- package/dist/lib/browser/index.d.ts +1 -1
- package/dist/lib/browser/index.d.ts.map +1 -1
- package/dist/lib/browser/index.js +1 -1
- package/dist/lib/browser/page-review-contracts.d.ts +6 -1
- package/dist/lib/browser/page-review-contracts.d.ts.map +1 -1
- package/dist/lib/browser/page-review-contracts.js +6 -1
- package/dist/lib/browser/page-review-judge.d.ts +3 -1
- package/dist/lib/browser/page-review-judge.d.ts.map +1 -1
- package/dist/lib/browser/page-review-judge.js +41 -11
- package/dist/lib/browser/page-review-pack.d.ts +3 -0
- package/dist/lib/browser/page-review-pack.d.ts.map +1 -1
- package/dist/lib/browser/page-review-pack.js +5 -2
- package/dist/lib/browser/qa-run-contracts.d.ts +11 -0
- package/dist/lib/browser/qa-run-contracts.d.ts.map +1 -1
- package/dist/lib/browser/qa-run-contracts.js +11 -4
- package/dist/lib/browser/qa-run.d.ts.map +1 -1
- package/dist/lib/browser/qa-run.js +73 -16
- package/dist/lib/browser/runts.d.ts +4 -2
- package/dist/lib/browser/runts.d.ts.map +1 -1
- package/dist/lib/browser/runts.js +84 -33
- package/dist/lib/browser/windows-chrome.d.ts +14 -0
- package/dist/lib/browser/windows-chrome.d.ts.map +1 -1
- package/dist/lib/browser/windows-chrome.js +42 -0
- package/dist/lib/browser/windows-login-sync.d.ts +110 -0
- package/dist/lib/browser/windows-login-sync.d.ts.map +1 -0
- package/dist/lib/browser/windows-login-sync.js +171 -0
- package/dist/lib/cookies/client.d.ts +30 -5
- package/dist/lib/cookies/client.d.ts.map +1 -1
- package/dist/lib/cookies/client.js +55 -10
- package/dist/lib/cookies/index.d.ts +1 -1
- package/dist/lib/cookies/index.d.ts.map +1 -1
- package/dist/lib/cookies/index.js +1 -1
- package/dist/lib/docs-metadata-sync.d.ts.map +1 -1
- package/dist/lib/docs-metadata-sync.js +41 -2
- package/dist/lib/durable-job.d.ts +8 -0
- package/dist/lib/durable-job.d.ts.map +1 -1
- package/dist/lib/durable-job.js +10 -0
- package/dist/lib/http/client.d.ts +9 -8
- package/dist/lib/http/client.d.ts.map +1 -1
- package/dist/lib/http/client.js +44 -2
- package/dist/lib/instructions/templates.js +4 -4
- package/package.json +2 -2
- package/src/commander.ts +13 -0
- package/src/commands/admission.ts +272 -29
- package/src/commands/agents.ts +132 -27
- package/src/commands/browse.ts +208 -6
- package/src/commands/fetch.ts +1 -0
- package/src/commands/ledger-v3.ts +8 -2
- package/src/commands/presence.ts +49 -0
- package/src/commands/qa-run.ts +4 -3
- package/src/commands/review-pack.ts +41 -5
- package/src/commands/workflow.ts +8 -58
- package/src/core/agents/coord-client.ts +0 -20
- package/src/core/agents/index.ts +6 -0
- package/src/core/agents/live-authority-v3.ts +11 -4
- package/src/core/agents/render/session-context.ts +1 -7
- package/src/core/agents/session-events.ts +18 -3
- package/src/core/agents/state/heartbeat-reader.ts +3 -0
- package/src/core/agents/state/live-coordination-view.ts +13 -6
- package/src/core/agents/state/parent-reference-contract.ts +14 -0
- package/src/core/agents/state/parent-reference.ts +179 -0
- package/src/core/agents/state/pidmap.ts +2 -2
- package/src/core/agents/state/proc-start.ts +41 -69
- package/src/core/agents/state/service-process.ts +217 -0
- package/src/core/config.ts +85 -0
- package/src/core/context/index.ts +207 -272
- package/src/core/context/observation.ts +40 -9
- package/src/core/diagnostics/path-identity.ts +52 -6
- package/src/core/events/v3/canonical.ts +46 -13
- package/src/core/events/v3/index.ts +3 -0
- package/src/core/events/v3/producers/recorder.ts +151 -13
- package/src/core/events/v3/reader.ts +55 -11
- package/src/core/events/v3/runtime-build.ts +62 -0
- package/src/core/events/v3/validate.ts +42 -1
- package/src/core/governor/index.ts +1 -2
- package/src/core/governor/service-read.ts +15 -114
- package/src/core/governor/service.ts +36 -220
- package/src/core/hooks/adapter/native-parent.ts +109 -0
- package/src/core/hooks/cli.ts +83 -4
- package/src/core/hooks/resolve/owner.ts +2 -25
- package/src/core/hooks/shell-admission.ts +634 -0
- package/src/core/hooks/shell-commit-tree.ts +102 -0
- package/src/core/inbox/contract.ts +18 -0
- package/src/core/inbox/peer-messages.ts +501 -15
- package/src/core/inbox/service.ts +108 -3
- package/src/core/inbox/targets.ts +94 -3
- package/src/core/presence/git.ts +45 -37
- package/src/core/presence/index.ts +16 -8
- package/src/core/presence/mail.ts +620 -0
- package/src/core/resources/sampler.ts +3 -2
- package/src/core/resources/service-status.ts +6 -35
- package/src/core/resources/service.ts +23 -133
- package/src/core/resources/status.ts +3 -2
- package/src/core/semantic/service.ts +8 -2
- package/src/core/servers/index.ts +3 -23
- package/src/core/storage/modes.ts +6 -0
- package/src/core/storage/segments.ts +5 -4
- package/src/core/supervisor/service.ts +33 -155
- package/src/core/supervisor/services.ts +2 -2
- package/src/core/supervisor/status.ts +10 -85
- package/src/core/workflow/engine.ts +1 -1
- package/src/core/workflow/index.ts +2 -13
- package/src/core/workflow/proof.ts +35 -83
- package/src/core/workflow/resume-lock.ts +179 -0
- package/src/core/workflow/run-state.ts +3 -207
- package/src/core/workflow/workspaces/leases.ts +1 -1
- package/src/core/workflow/workspaces/local-git.ts +120 -239
- package/src/core/workflow/workspaces/ownership.ts +3 -158
- package/src/core/workflow/workspaces/reclaim.ts +3 -9
- package/src/core/workflow/workspaces/recovery.ts +1 -1
- package/src/core/workflow/workspaces/state.ts +1 -5
- package/src/lib/admission-history.ts +267 -0
- package/src/lib/admission.ts +217 -19
- package/src/lib/browser/client.ts +147 -35
- package/src/lib/browser/content-checks.ts +14 -3
- package/src/lib/browser/critique.ts +113 -3
- package/src/lib/browser/geometry.ts +63 -14
- package/src/lib/browser/index.ts +5 -0
- package/src/lib/browser/page-review-contracts.ts +6 -1
- package/src/lib/browser/page-review-judge.ts +58 -13
- package/src/lib/browser/page-review-pack.ts +13 -2
- package/src/lib/browser/qa-run-contracts.ts +30 -4
- package/src/lib/browser/qa-run.ts +78 -17
- package/src/lib/browser/runts.ts +85 -37
- package/src/lib/browser/windows-chrome.ts +50 -0
- package/src/lib/browser/windows-login-sync.ts +275 -0
- package/src/lib/cookies/client.ts +62 -10
- package/src/lib/cookies/index.ts +3 -0
- package/src/lib/docs-metadata-sync.ts +44 -2
- package/src/lib/durable-job.ts +15 -0
- package/src/lib/http/client.ts +63 -1
- package/src/lib/instructions/templates.ts +4 -4
- package/dist/core/agents/state/process-handle.d.ts +0 -26
- package/dist/core/agents/state/process-handle.d.ts.map +0 -1
- package/dist/core/agents/state/process-handle.js +0 -121
- package/dist/core/workflow/recovery-audit.d.ts +0 -30
- package/dist/core/workflow/recovery-audit.d.ts.map +0 -1
- package/dist/core/workflow/recovery-audit.js +0 -116
- package/src/core/agents/state/process-handle.ts +0 -165
- package/src/core/workflow/recovery-audit.ts +0 -181
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { spawnSync } from "node:child_process";
|
|
2
|
-
import { constants } from "node:os";
|
|
3
|
-
// The helper owns the descriptor throughout observation and effect. The second
|
|
4
|
-
// input line authorizes the effect; EOF releases the handle without signaling.
|
|
5
|
-
export const LINUX_PROCESS_HANDLE_SCRIPT = `
|
|
6
|
-
import json, os, pathlib, signal, sys
|
|
7
|
-
result = {"sent": False, "verdict": "unknown"}
|
|
8
|
-
fd = None
|
|
9
|
-
try:
|
|
10
|
-
request = json.loads(sys.stdin.readline())
|
|
11
|
-
if not hasattr(os, "pidfd_open") or not hasattr(signal, "pidfd_send_signal"):
|
|
12
|
-
raise RuntimeError("pidfd support unavailable")
|
|
13
|
-
fd = os.pidfd_open(request["pid"])
|
|
14
|
-
stat = pathlib.Path("/proc/%d/stat" % request["pid"]).read_text()
|
|
15
|
-
ticks = stat[stat.rfind(") ") + 2:].split()[19]
|
|
16
|
-
boot = pathlib.Path("/proc/sys/kernel/random/boot_id").read_text().strip().replace("-", "")[:8]
|
|
17
|
-
token = "l%s.%s" % (boot, ticks)
|
|
18
|
-
result["token"] = token
|
|
19
|
-
recorded = request.get("token")
|
|
20
|
-
result["verdict"] = "same" if token == recorded else "different"
|
|
21
|
-
if request["mode"] == "signal" and result["verdict"] == "same":
|
|
22
|
-
print(json.dumps({"phase": "verified"}), flush=True)
|
|
23
|
-
if sys.stdin.readline().strip() == "signal":
|
|
24
|
-
signal.pidfd_send_signal(fd, request["signal"])
|
|
25
|
-
result["sent"] = True
|
|
26
|
-
except Exception:
|
|
27
|
-
pass
|
|
28
|
-
finally:
|
|
29
|
-
if fd is not None:
|
|
30
|
-
os.close(fd)
|
|
31
|
-
print(json.dumps(result), flush=True)
|
|
32
|
-
`;
|
|
33
|
-
export const WINDOWS_PROCESS_HANDLE_SCRIPT = `
|
|
34
|
-
$ErrorActionPreference = 'Stop'
|
|
35
|
-
$result = @{ sent = $false; verdict = 'unknown' }
|
|
36
|
-
$handle = [IntPtr]::Zero
|
|
37
|
-
try {
|
|
38
|
-
Add-Type -TypeDefinition @'
|
|
39
|
-
using System;
|
|
40
|
-
using System.Runtime.InteropServices;
|
|
41
|
-
public static class HarneryProcessHandle {
|
|
42
|
-
[DllImport("kernel32.dll", SetLastError=true)] public static extern IntPtr OpenProcess(uint access, bool inherit, uint processId);
|
|
43
|
-
[DllImport("kernel32.dll", SetLastError=true)] public static extern bool GetProcessTimes(IntPtr handle, out long creation, out long exit, out long kernel, out long user);
|
|
44
|
-
[DllImport("kernel32.dll", SetLastError=true)] public static extern bool TerminateProcess(IntPtr handle, uint exitCode);
|
|
45
|
-
[DllImport("kernel32.dll")] public static extern uint WaitForSingleObject(IntPtr handle, uint milliseconds);
|
|
46
|
-
[DllImport("kernel32.dll")] public static extern bool CloseHandle(IntPtr handle);
|
|
47
|
-
}
|
|
48
|
-
'@
|
|
49
|
-
$request = [Console]::In.ReadLine() | ConvertFrom-Json
|
|
50
|
-
$access = [uint32]0x101000
|
|
51
|
-
if ($request.mode -eq 'signal') { $access = $access -bor 1 }
|
|
52
|
-
$handle = [HarneryProcessHandle]::OpenProcess($access, $false, [uint32]$request.pid)
|
|
53
|
-
if ($handle -eq [IntPtr]::Zero) { throw 'process handle unavailable' }
|
|
54
|
-
[long]$creation = 0; [long]$exitTime = 0; [long]$kernel = 0; [long]$userTime = 0
|
|
55
|
-
if (-not [HarneryProcessHandle]::GetProcessTimes($handle, [ref]$creation, [ref]$exitTime, [ref]$kernel, [ref]$userTime)) { throw 'process time unavailable' }
|
|
56
|
-
$token = 'w' + $creation.ToString([Globalization.CultureInfo]::InvariantCulture)
|
|
57
|
-
$result.token = $token
|
|
58
|
-
$result.verdict = if ($token -ceq $request.token) { 'same' } else { 'different' }
|
|
59
|
-
if ($request.mode -eq 'signal' -and $result.verdict -eq 'same') {
|
|
60
|
-
[Console]::Out.WriteLine('{"phase":"verified"}')
|
|
61
|
-
[Console]::Out.Flush()
|
|
62
|
-
if ([Console]::In.ReadLine() -eq 'signal' -and [HarneryProcessHandle]::WaitForSingleObject($handle, 0) -eq 258) {
|
|
63
|
-
$result.sent = [HarneryProcessHandle]::TerminateProcess($handle, 1)
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
} catch {} finally {
|
|
67
|
-
if ($handle -ne [IntPtr]::Zero) { [void][HarneryProcessHandle]::CloseHandle($handle) }
|
|
68
|
-
}
|
|
69
|
-
$result | ConvertTo-Json -Compress
|
|
70
|
-
`;
|
|
71
|
-
function runHelper(request, platform, run) {
|
|
72
|
-
const unknown = { sent: false, verdict: "unknown" };
|
|
73
|
-
if (!Number.isInteger(request.pid) || request.pid <= 0)
|
|
74
|
-
return unknown;
|
|
75
|
-
if (platform !== "linux" && platform !== "win32")
|
|
76
|
-
return unknown;
|
|
77
|
-
try {
|
|
78
|
-
const command = platform === "linux" ? "python3" : "powershell.exe";
|
|
79
|
-
const args = platform === "linux"
|
|
80
|
-
? ["-I", "-c", LINUX_PROCESS_HANDLE_SCRIPT]
|
|
81
|
-
: ["-NoLogo", "-NoProfile", "-NonInteractive", "-Command", WINDOWS_PROCESS_HANDLE_SCRIPT];
|
|
82
|
-
const output = run(command, args, {
|
|
83
|
-
input: `${JSON.stringify(request)}\nsignal\n`,
|
|
84
|
-
encoding: "utf8",
|
|
85
|
-
timeout: 10_000,
|
|
86
|
-
maxBuffer: 64 * 1024,
|
|
87
|
-
windowsHide: true,
|
|
88
|
-
});
|
|
89
|
-
if (output.error || output.status !== 0)
|
|
90
|
-
return unknown;
|
|
91
|
-
const lines = String(output.stdout ?? "")
|
|
92
|
-
.trim()
|
|
93
|
-
.split(/\r?\n/);
|
|
94
|
-
const parsed = JSON.parse(lines.at(-1) ?? "");
|
|
95
|
-
if (typeof parsed.sent !== "boolean" ||
|
|
96
|
-
!["same", "different", "unknown"].includes(parsed.verdict) ||
|
|
97
|
-
(parsed.sent && parsed.verdict !== "same"))
|
|
98
|
-
return unknown;
|
|
99
|
-
return parsed;
|
|
100
|
-
}
|
|
101
|
-
catch {
|
|
102
|
-
return unknown;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
/** Windows creation FILETIME, read from an OpenProcess handle. */
|
|
106
|
-
export function windowsProcessStartToken(pid, run = spawnSync) {
|
|
107
|
-
const result = runHelper({ mode: "probe", pid }, "win32", run);
|
|
108
|
-
return typeof result.token === "string" && /^w\d+$/.test(result.token) ? result.token : null;
|
|
109
|
-
}
|
|
110
|
-
/** No numeric-PID signaling fallback is permitted when an exact handle fails. */
|
|
111
|
-
export function signalProcessWithHandle(pid, recordedToken, signal, options = {}) {
|
|
112
|
-
const platform = options.platform ?? process.platform;
|
|
113
|
-
const number = typeof signal === "number" ? signal : constants.signals[signal];
|
|
114
|
-
if (!Number.isInteger(number) ||
|
|
115
|
-
number <= 0 ||
|
|
116
|
-
(platform === "linux" && !/^l[0-9a-f]{8}\.\d+$/.test(recordedToken)) ||
|
|
117
|
-
(platform === "win32" && (!/^w\d+$/.test(recordedToken) || ![9, 15].includes(number))))
|
|
118
|
-
return { sent: false, verdict: "unknown" };
|
|
119
|
-
const result = runHelper({ mode: "signal", pid, token: recordedToken, signal: number }, platform, options.run ?? spawnSync);
|
|
120
|
-
return { sent: result.sent, verdict: result.verdict };
|
|
121
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export interface WorkflowRecoveryAuthorization {
|
|
2
|
-
actor: string;
|
|
3
|
-
reason: string;
|
|
4
|
-
}
|
|
5
|
-
export interface WorkflowRecoveryIntent extends WorkflowRecoveryAuthorization {
|
|
6
|
-
schema_version: 1;
|
|
7
|
-
operation_id: string;
|
|
8
|
-
run_id: string;
|
|
9
|
-
action: "reclaim_unknown_liveness" | "unlock_resume";
|
|
10
|
-
target_sha256: string;
|
|
11
|
-
target: Record<string, unknown>;
|
|
12
|
-
recorded_at: string;
|
|
13
|
-
pid: number;
|
|
14
|
-
host: string;
|
|
15
|
-
outcome: "unknown";
|
|
16
|
-
}
|
|
17
|
-
export interface WorkflowRecoveryRecord {
|
|
18
|
-
intent: WorkflowRecoveryIntent;
|
|
19
|
-
outcome: "unknown" | "completed";
|
|
20
|
-
}
|
|
21
|
-
export declare function validateWorkflowRecoveryAuthorization(authorization: WorkflowRecoveryAuthorization): void;
|
|
22
|
-
/** Canonical recovery ledger: immutable intent is durable before effects.
|
|
23
|
-
* Completion cites that exact intent; absence always means unknown. */
|
|
24
|
-
export declare function beginWorkflowRecovery(coordRoot: string, input: Omit<WorkflowRecoveryIntent, "schema_version" | "operation_id" | "recorded_at" | "pid" | "host" | "outcome">): {
|
|
25
|
-
intent: WorkflowRecoveryIntent;
|
|
26
|
-
assertCurrent(): void;
|
|
27
|
-
complete(): void;
|
|
28
|
-
};
|
|
29
|
-
export declare function readWorkflowRecoveryLedger(coordRoot: string, runId: string): WorkflowRecoveryRecord[];
|
|
30
|
-
//# sourceMappingURL=recovery-audit.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"recovery-audit.d.ts","sourceRoot":"","sources":["../../../src/core/workflow/recovery-audit.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,6BAA6B;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,sBAAuB,SAAQ,6BAA6B;IAC3E,cAAc,EAAE,CAAC,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,0BAA0B,GAAG,eAAe,CAAC;IACrD,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,SAAS,CAAC;CACpB;AAED,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,sBAAsB,CAAC;IAC/B,OAAO,EAAE,SAAS,GAAG,WAAW,CAAC;CAClC;AAED,wBAAgB,qCAAqC,CACnD,aAAa,EAAE,6BAA6B,GAC3C,IAAI,CAmBN;AAED;uEACuE;AACvE,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,IAAI,CACT,sBAAsB,EACtB,gBAAgB,GAAG,cAAc,GAAG,aAAa,GAAG,KAAK,GAAG,MAAM,GAAG,SAAS,CAC/E,GACA;IAAE,MAAM,EAAE,sBAAsB,CAAC;IAAC,aAAa,IAAI,IAAI,CAAC;IAAC,QAAQ,IAAI,IAAI,CAAA;CAAE,CAmD7E;AAkBD,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,GACZ,sBAAsB,EAAE,CAyC1B"}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { existsSync, lstatSync, mkdirSync, readdirSync } from "node:fs";
|
|
3
|
-
import { hostname } from "node:os";
|
|
4
|
-
import { dirname, join } from "node:path";
|
|
5
|
-
import { stateDirMode } from "../storage/modes.js";
|
|
6
|
-
import { assertWorkflowRunId } from "./approvals.js";
|
|
7
|
-
import { fsyncParentDirectory, readJsonRecord, stableDigest, writeImmutableJson, } from "./durable-record.js";
|
|
8
|
-
export function validateWorkflowRecoveryAuthorization(authorization) {
|
|
9
|
-
for (const [field, limit] of [
|
|
10
|
-
["actor", 200],
|
|
11
|
-
["reason", 2_000],
|
|
12
|
-
]) {
|
|
13
|
-
const value = authorization[field];
|
|
14
|
-
if (typeof value !== "string" ||
|
|
15
|
-
!value.trim() ||
|
|
16
|
-
value.length > limit ||
|
|
17
|
-
Array.from(value).some((character) => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127)) {
|
|
18
|
-
throw new Error(`workflow recovery requires a nonempty ${field} of at most ${limit} characters without control characters`);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
/** Canonical recovery ledger: immutable intent is durable before effects.
|
|
23
|
-
* Completion cites that exact intent; absence always means unknown. */
|
|
24
|
-
export function beginWorkflowRecovery(coordRoot, input) {
|
|
25
|
-
assertWorkflowRunId(input.run_id);
|
|
26
|
-
validateWorkflowRecoveryAuthorization(input);
|
|
27
|
-
if (!/^[a-f0-9]{64}$/.test(input.target_sha256))
|
|
28
|
-
throw new Error("workflow recovery requires an exact preview digest");
|
|
29
|
-
const intent = {
|
|
30
|
-
...input,
|
|
31
|
-
schema_version: 1,
|
|
32
|
-
operation_id: `recovery-${randomUUID()}`,
|
|
33
|
-
recorded_at: new Date().toISOString(),
|
|
34
|
-
pid: process.pid,
|
|
35
|
-
host: hostname(),
|
|
36
|
-
outcome: "unknown",
|
|
37
|
-
};
|
|
38
|
-
const directory = join(coordRoot, ".harnery", "workflows", input.run_id, "recovery", intent.operation_id);
|
|
39
|
-
// Sync each newly published directory name too. Syncing only the intent's
|
|
40
|
-
// immediate parent cannot make a newly created ancestor durable.
|
|
41
|
-
const runDirectory = join(coordRoot, ".harnery", "workflows", input.run_id);
|
|
42
|
-
ensureDurableDirectory(runDirectory);
|
|
43
|
-
const ledgerDirectory = join(runDirectory, "recovery");
|
|
44
|
-
ensureDurableDirectory(ledgerDirectory);
|
|
45
|
-
fsyncParentDirectory(ledgerDirectory);
|
|
46
|
-
mkdirSync(directory, { mode: stateDirMode() });
|
|
47
|
-
fsyncParentDirectory(directory);
|
|
48
|
-
const intentPath = join(directory, "intent.json");
|
|
49
|
-
writeImmutableJson(intentPath, intent);
|
|
50
|
-
const assertCurrent = () => {
|
|
51
|
-
if (stableDigest(readJsonRecord(intentPath, "recovery intent")) !== stableDigest(intent))
|
|
52
|
-
throw new Error("workflow recovery audit authority changed");
|
|
53
|
-
};
|
|
54
|
-
return {
|
|
55
|
-
intent,
|
|
56
|
-
assertCurrent,
|
|
57
|
-
complete: () => {
|
|
58
|
-
assertCurrent();
|
|
59
|
-
writeImmutableJson(join(directory, "completion.json"), {
|
|
60
|
-
schema_version: 1,
|
|
61
|
-
operation_id: intent.operation_id,
|
|
62
|
-
intent_sha256: stableDigest(intent),
|
|
63
|
-
outcome: "completed",
|
|
64
|
-
recorded_at: new Date().toISOString(),
|
|
65
|
-
});
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
function ensureDurableDirectory(path) {
|
|
70
|
-
if (existsSync(path)) {
|
|
71
|
-
if (!lstatSync(path).isDirectory())
|
|
72
|
-
throw new Error("workflow recovery ledger is not a directory");
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
ensureDurableDirectory(dirname(path));
|
|
76
|
-
try {
|
|
77
|
-
mkdirSync(path, { mode: stateDirMode() });
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
if (error.code !== "EEXIST" || !lstatSync(path).isDirectory())
|
|
81
|
-
throw error;
|
|
82
|
-
}
|
|
83
|
-
fsyncParentDirectory(path);
|
|
84
|
-
}
|
|
85
|
-
export function readWorkflowRecoveryLedger(coordRoot, runId) {
|
|
86
|
-
assertWorkflowRunId(runId);
|
|
87
|
-
const directory = join(coordRoot, ".harnery", "workflows", runId, "recovery");
|
|
88
|
-
if (!existsSync(directory))
|
|
89
|
-
return [];
|
|
90
|
-
return readdirSync(directory)
|
|
91
|
-
.sort()
|
|
92
|
-
.map((entry) => {
|
|
93
|
-
if (!/^recovery-[a-f0-9-]{36}$/.test(entry))
|
|
94
|
-
throw new Error("invalid workflow recovery ledger entry");
|
|
95
|
-
const intent = readJsonRecord(join(directory, entry, "intent.json"), "recovery intent");
|
|
96
|
-
if (intent.schema_version !== 1 ||
|
|
97
|
-
intent.operation_id !== entry ||
|
|
98
|
-
intent.run_id !== runId ||
|
|
99
|
-
intent.outcome !== "unknown" ||
|
|
100
|
-
!["reclaim_unknown_liveness", "unlock_resume"].includes(intent.action) ||
|
|
101
|
-
!/^[a-f0-9]{64}$/.test(intent.target_sha256)) {
|
|
102
|
-
throw new Error("invalid workflow recovery intent authority");
|
|
103
|
-
}
|
|
104
|
-
validateWorkflowRecoveryAuthorization(intent);
|
|
105
|
-
const completionPath = join(directory, entry, "completion.json");
|
|
106
|
-
if (!existsSync(completionPath))
|
|
107
|
-
return { intent, outcome: "unknown" };
|
|
108
|
-
const completion = readJsonRecord(completionPath, "recovery completion");
|
|
109
|
-
if (completion.schema_version !== 1 ||
|
|
110
|
-
completion.operation_id !== entry ||
|
|
111
|
-
completion.intent_sha256 !== stableDigest(intent) ||
|
|
112
|
-
completion.outcome !== "completed")
|
|
113
|
-
throw new Error("invalid workflow recovery completion authority");
|
|
114
|
-
return { intent, outcome: "completed" };
|
|
115
|
-
});
|
|
116
|
-
}
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import { spawnSync } from "node:child_process";
|
|
2
|
-
import { constants } from "node:os";
|
|
3
|
-
import type { ProcessGenerationVerdict } from "./proc-start.ts";
|
|
4
|
-
|
|
5
|
-
export interface ProcessHandleSignalResult {
|
|
6
|
-
sent: boolean;
|
|
7
|
-
verdict: ProcessGenerationVerdict;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
interface NativeHelperResult extends ProcessHandleSignalResult {
|
|
11
|
-
token?: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export type NativeProcessHelperRunner = (
|
|
15
|
-
command: string,
|
|
16
|
-
args: string[],
|
|
17
|
-
options: {
|
|
18
|
-
input: string;
|
|
19
|
-
encoding: "utf8";
|
|
20
|
-
timeout: number;
|
|
21
|
-
maxBuffer: number;
|
|
22
|
-
windowsHide: boolean;
|
|
23
|
-
},
|
|
24
|
-
) => { status: number | null; stdout: string | Buffer | null; error?: Error };
|
|
25
|
-
|
|
26
|
-
// The helper owns the descriptor throughout observation and effect. The second
|
|
27
|
-
// input line authorizes the effect; EOF releases the handle without signaling.
|
|
28
|
-
export const LINUX_PROCESS_HANDLE_SCRIPT = `
|
|
29
|
-
import json, os, pathlib, signal, sys
|
|
30
|
-
result = {"sent": False, "verdict": "unknown"}
|
|
31
|
-
fd = None
|
|
32
|
-
try:
|
|
33
|
-
request = json.loads(sys.stdin.readline())
|
|
34
|
-
if not hasattr(os, "pidfd_open") or not hasattr(signal, "pidfd_send_signal"):
|
|
35
|
-
raise RuntimeError("pidfd support unavailable")
|
|
36
|
-
fd = os.pidfd_open(request["pid"])
|
|
37
|
-
stat = pathlib.Path("/proc/%d/stat" % request["pid"]).read_text()
|
|
38
|
-
ticks = stat[stat.rfind(") ") + 2:].split()[19]
|
|
39
|
-
boot = pathlib.Path("/proc/sys/kernel/random/boot_id").read_text().strip().replace("-", "")[:8]
|
|
40
|
-
token = "l%s.%s" % (boot, ticks)
|
|
41
|
-
result["token"] = token
|
|
42
|
-
recorded = request.get("token")
|
|
43
|
-
result["verdict"] = "same" if token == recorded else "different"
|
|
44
|
-
if request["mode"] == "signal" and result["verdict"] == "same":
|
|
45
|
-
print(json.dumps({"phase": "verified"}), flush=True)
|
|
46
|
-
if sys.stdin.readline().strip() == "signal":
|
|
47
|
-
signal.pidfd_send_signal(fd, request["signal"])
|
|
48
|
-
result["sent"] = True
|
|
49
|
-
except Exception:
|
|
50
|
-
pass
|
|
51
|
-
finally:
|
|
52
|
-
if fd is not None:
|
|
53
|
-
os.close(fd)
|
|
54
|
-
print(json.dumps(result), flush=True)
|
|
55
|
-
`;
|
|
56
|
-
|
|
57
|
-
export const WINDOWS_PROCESS_HANDLE_SCRIPT = `
|
|
58
|
-
$ErrorActionPreference = 'Stop'
|
|
59
|
-
$result = @{ sent = $false; verdict = 'unknown' }
|
|
60
|
-
$handle = [IntPtr]::Zero
|
|
61
|
-
try {
|
|
62
|
-
Add-Type -TypeDefinition @'
|
|
63
|
-
using System;
|
|
64
|
-
using System.Runtime.InteropServices;
|
|
65
|
-
public static class HarneryProcessHandle {
|
|
66
|
-
[DllImport("kernel32.dll", SetLastError=true)] public static extern IntPtr OpenProcess(uint access, bool inherit, uint processId);
|
|
67
|
-
[DllImport("kernel32.dll", SetLastError=true)] public static extern bool GetProcessTimes(IntPtr handle, out long creation, out long exit, out long kernel, out long user);
|
|
68
|
-
[DllImport("kernel32.dll", SetLastError=true)] public static extern bool TerminateProcess(IntPtr handle, uint exitCode);
|
|
69
|
-
[DllImport("kernel32.dll")] public static extern uint WaitForSingleObject(IntPtr handle, uint milliseconds);
|
|
70
|
-
[DllImport("kernel32.dll")] public static extern bool CloseHandle(IntPtr handle);
|
|
71
|
-
}
|
|
72
|
-
'@
|
|
73
|
-
$request = [Console]::In.ReadLine() | ConvertFrom-Json
|
|
74
|
-
$access = [uint32]0x101000
|
|
75
|
-
if ($request.mode -eq 'signal') { $access = $access -bor 1 }
|
|
76
|
-
$handle = [HarneryProcessHandle]::OpenProcess($access, $false, [uint32]$request.pid)
|
|
77
|
-
if ($handle -eq [IntPtr]::Zero) { throw 'process handle unavailable' }
|
|
78
|
-
[long]$creation = 0; [long]$exitTime = 0; [long]$kernel = 0; [long]$userTime = 0
|
|
79
|
-
if (-not [HarneryProcessHandle]::GetProcessTimes($handle, [ref]$creation, [ref]$exitTime, [ref]$kernel, [ref]$userTime)) { throw 'process time unavailable' }
|
|
80
|
-
$token = 'w' + $creation.ToString([Globalization.CultureInfo]::InvariantCulture)
|
|
81
|
-
$result.token = $token
|
|
82
|
-
$result.verdict = if ($token -ceq $request.token) { 'same' } else { 'different' }
|
|
83
|
-
if ($request.mode -eq 'signal' -and $result.verdict -eq 'same') {
|
|
84
|
-
[Console]::Out.WriteLine('{"phase":"verified"}')
|
|
85
|
-
[Console]::Out.Flush()
|
|
86
|
-
if ([Console]::In.ReadLine() -eq 'signal' -and [HarneryProcessHandle]::WaitForSingleObject($handle, 0) -eq 258) {
|
|
87
|
-
$result.sent = [HarneryProcessHandle]::TerminateProcess($handle, 1)
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
} catch {} finally {
|
|
91
|
-
if ($handle -ne [IntPtr]::Zero) { [void][HarneryProcessHandle]::CloseHandle($handle) }
|
|
92
|
-
}
|
|
93
|
-
$result | ConvertTo-Json -Compress
|
|
94
|
-
`;
|
|
95
|
-
|
|
96
|
-
function runHelper(
|
|
97
|
-
request: { mode: "probe" | "signal"; pid: number; token?: string; signal?: number },
|
|
98
|
-
platform: NodeJS.Platform,
|
|
99
|
-
run: NativeProcessHelperRunner,
|
|
100
|
-
): NativeHelperResult {
|
|
101
|
-
const unknown = { sent: false, verdict: "unknown" } as const;
|
|
102
|
-
if (!Number.isInteger(request.pid) || request.pid <= 0) return unknown;
|
|
103
|
-
if (platform !== "linux" && platform !== "win32") return unknown;
|
|
104
|
-
try {
|
|
105
|
-
const command = platform === "linux" ? "python3" : "powershell.exe";
|
|
106
|
-
const args =
|
|
107
|
-
platform === "linux"
|
|
108
|
-
? ["-I", "-c", LINUX_PROCESS_HANDLE_SCRIPT]
|
|
109
|
-
: ["-NoLogo", "-NoProfile", "-NonInteractive", "-Command", WINDOWS_PROCESS_HANDLE_SCRIPT];
|
|
110
|
-
const output = run(command, args, {
|
|
111
|
-
input: `${JSON.stringify(request)}\nsignal\n`,
|
|
112
|
-
encoding: "utf8",
|
|
113
|
-
timeout: 10_000,
|
|
114
|
-
maxBuffer: 64 * 1024,
|
|
115
|
-
windowsHide: true,
|
|
116
|
-
});
|
|
117
|
-
if (output.error || output.status !== 0) return unknown;
|
|
118
|
-
const lines = String(output.stdout ?? "")
|
|
119
|
-
.trim()
|
|
120
|
-
.split(/\r?\n/);
|
|
121
|
-
const parsed = JSON.parse(lines.at(-1) ?? "") as NativeHelperResult;
|
|
122
|
-
if (
|
|
123
|
-
typeof parsed.sent !== "boolean" ||
|
|
124
|
-
!["same", "different", "unknown"].includes(parsed.verdict) ||
|
|
125
|
-
(parsed.sent && parsed.verdict !== "same")
|
|
126
|
-
)
|
|
127
|
-
return unknown;
|
|
128
|
-
return parsed;
|
|
129
|
-
} catch {
|
|
130
|
-
return unknown;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/** Windows creation FILETIME, read from an OpenProcess handle. */
|
|
135
|
-
export function windowsProcessStartToken(
|
|
136
|
-
pid: number,
|
|
137
|
-
run: NativeProcessHelperRunner = spawnSync,
|
|
138
|
-
): string | null {
|
|
139
|
-
const result = runHelper({ mode: "probe", pid }, "win32", run);
|
|
140
|
-
return typeof result.token === "string" && /^w\d+$/.test(result.token) ? result.token : null;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/** No numeric-PID signaling fallback is permitted when an exact handle fails. */
|
|
144
|
-
export function signalProcessWithHandle(
|
|
145
|
-
pid: number,
|
|
146
|
-
recordedToken: string,
|
|
147
|
-
signal: NodeJS.Signals | number,
|
|
148
|
-
options: { platform?: NodeJS.Platform; run?: NativeProcessHelperRunner } = {},
|
|
149
|
-
): ProcessHandleSignalResult {
|
|
150
|
-
const platform = options.platform ?? process.platform;
|
|
151
|
-
const number = typeof signal === "number" ? signal : constants.signals[signal];
|
|
152
|
-
if (
|
|
153
|
-
!Number.isInteger(number) ||
|
|
154
|
-
number <= 0 ||
|
|
155
|
-
(platform === "linux" && !/^l[0-9a-f]{8}\.\d+$/.test(recordedToken)) ||
|
|
156
|
-
(platform === "win32" && (!/^w\d+$/.test(recordedToken) || ![9, 15].includes(number)))
|
|
157
|
-
)
|
|
158
|
-
return { sent: false, verdict: "unknown" };
|
|
159
|
-
const result = runHelper(
|
|
160
|
-
{ mode: "signal", pid, token: recordedToken, signal: number },
|
|
161
|
-
platform,
|
|
162
|
-
options.run ?? spawnSync,
|
|
163
|
-
);
|
|
164
|
-
return { sent: result.sent, verdict: result.verdict };
|
|
165
|
-
}
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { existsSync, lstatSync, mkdirSync, readdirSync } from "node:fs";
|
|
3
|
-
import { hostname } from "node:os";
|
|
4
|
-
import { dirname, join } from "node:path";
|
|
5
|
-
import { stateDirMode } from "../storage/modes.ts";
|
|
6
|
-
import { assertWorkflowRunId } from "./approvals.ts";
|
|
7
|
-
import {
|
|
8
|
-
fsyncParentDirectory,
|
|
9
|
-
readJsonRecord,
|
|
10
|
-
stableDigest,
|
|
11
|
-
writeImmutableJson,
|
|
12
|
-
} from "./durable-record.ts";
|
|
13
|
-
|
|
14
|
-
export interface WorkflowRecoveryAuthorization {
|
|
15
|
-
actor: string;
|
|
16
|
-
reason: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface WorkflowRecoveryIntent extends WorkflowRecoveryAuthorization {
|
|
20
|
-
schema_version: 1;
|
|
21
|
-
operation_id: string;
|
|
22
|
-
run_id: string;
|
|
23
|
-
action: "reclaim_unknown_liveness" | "unlock_resume";
|
|
24
|
-
target_sha256: string;
|
|
25
|
-
target: Record<string, unknown>;
|
|
26
|
-
recorded_at: string;
|
|
27
|
-
pid: number;
|
|
28
|
-
host: string;
|
|
29
|
-
outcome: "unknown";
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface WorkflowRecoveryRecord {
|
|
33
|
-
intent: WorkflowRecoveryIntent;
|
|
34
|
-
outcome: "unknown" | "completed";
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function validateWorkflowRecoveryAuthorization(
|
|
38
|
-
authorization: WorkflowRecoveryAuthorization,
|
|
39
|
-
): void {
|
|
40
|
-
for (const [field, limit] of [
|
|
41
|
-
["actor", 200],
|
|
42
|
-
["reason", 2_000],
|
|
43
|
-
] as const) {
|
|
44
|
-
const value = authorization[field];
|
|
45
|
-
if (
|
|
46
|
-
typeof value !== "string" ||
|
|
47
|
-
!value.trim() ||
|
|
48
|
-
value.length > limit ||
|
|
49
|
-
Array.from(value).some(
|
|
50
|
-
(character) => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127,
|
|
51
|
-
)
|
|
52
|
-
) {
|
|
53
|
-
throw new Error(
|
|
54
|
-
`workflow recovery requires a nonempty ${field} of at most ${limit} characters without control characters`,
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** Canonical recovery ledger: immutable intent is durable before effects.
|
|
61
|
-
* Completion cites that exact intent; absence always means unknown. */
|
|
62
|
-
export function beginWorkflowRecovery(
|
|
63
|
-
coordRoot: string,
|
|
64
|
-
input: Omit<
|
|
65
|
-
WorkflowRecoveryIntent,
|
|
66
|
-
"schema_version" | "operation_id" | "recorded_at" | "pid" | "host" | "outcome"
|
|
67
|
-
>,
|
|
68
|
-
): { intent: WorkflowRecoveryIntent; assertCurrent(): void; complete(): void } {
|
|
69
|
-
assertWorkflowRunId(input.run_id);
|
|
70
|
-
validateWorkflowRecoveryAuthorization(input);
|
|
71
|
-
if (!/^[a-f0-9]{64}$/.test(input.target_sha256))
|
|
72
|
-
throw new Error("workflow recovery requires an exact preview digest");
|
|
73
|
-
const intent: WorkflowRecoveryIntent = {
|
|
74
|
-
...input,
|
|
75
|
-
schema_version: 1,
|
|
76
|
-
operation_id: `recovery-${randomUUID()}`,
|
|
77
|
-
recorded_at: new Date().toISOString(),
|
|
78
|
-
pid: process.pid,
|
|
79
|
-
host: hostname(),
|
|
80
|
-
outcome: "unknown",
|
|
81
|
-
};
|
|
82
|
-
const directory = join(
|
|
83
|
-
coordRoot,
|
|
84
|
-
".harnery",
|
|
85
|
-
"workflows",
|
|
86
|
-
input.run_id,
|
|
87
|
-
"recovery",
|
|
88
|
-
intent.operation_id,
|
|
89
|
-
);
|
|
90
|
-
// Sync each newly published directory name too. Syncing only the intent's
|
|
91
|
-
// immediate parent cannot make a newly created ancestor durable.
|
|
92
|
-
const runDirectory = join(coordRoot, ".harnery", "workflows", input.run_id);
|
|
93
|
-
ensureDurableDirectory(runDirectory);
|
|
94
|
-
const ledgerDirectory = join(runDirectory, "recovery");
|
|
95
|
-
ensureDurableDirectory(ledgerDirectory);
|
|
96
|
-
fsyncParentDirectory(ledgerDirectory);
|
|
97
|
-
mkdirSync(directory, { mode: stateDirMode() });
|
|
98
|
-
fsyncParentDirectory(directory);
|
|
99
|
-
const intentPath = join(directory, "intent.json");
|
|
100
|
-
writeImmutableJson(intentPath, intent);
|
|
101
|
-
const assertCurrent = () => {
|
|
102
|
-
if (stableDigest(readJsonRecord(intentPath, "recovery intent")) !== stableDigest(intent))
|
|
103
|
-
throw new Error("workflow recovery audit authority changed");
|
|
104
|
-
};
|
|
105
|
-
return {
|
|
106
|
-
intent,
|
|
107
|
-
assertCurrent,
|
|
108
|
-
complete: () => {
|
|
109
|
-
assertCurrent();
|
|
110
|
-
writeImmutableJson(join(directory, "completion.json"), {
|
|
111
|
-
schema_version: 1,
|
|
112
|
-
operation_id: intent.operation_id,
|
|
113
|
-
intent_sha256: stableDigest(intent),
|
|
114
|
-
outcome: "completed",
|
|
115
|
-
recorded_at: new Date().toISOString(),
|
|
116
|
-
});
|
|
117
|
-
},
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function ensureDurableDirectory(path: string): void {
|
|
122
|
-
if (existsSync(path)) {
|
|
123
|
-
if (!lstatSync(path).isDirectory())
|
|
124
|
-
throw new Error("workflow recovery ledger is not a directory");
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
ensureDurableDirectory(dirname(path));
|
|
128
|
-
try {
|
|
129
|
-
mkdirSync(path, { mode: stateDirMode() });
|
|
130
|
-
} catch (error) {
|
|
131
|
-
if ((error as NodeJS.ErrnoException).code !== "EEXIST" || !lstatSync(path).isDirectory())
|
|
132
|
-
throw error;
|
|
133
|
-
}
|
|
134
|
-
fsyncParentDirectory(path);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export function readWorkflowRecoveryLedger(
|
|
138
|
-
coordRoot: string,
|
|
139
|
-
runId: string,
|
|
140
|
-
): WorkflowRecoveryRecord[] {
|
|
141
|
-
assertWorkflowRunId(runId);
|
|
142
|
-
const directory = join(coordRoot, ".harnery", "workflows", runId, "recovery");
|
|
143
|
-
if (!existsSync(directory)) return [];
|
|
144
|
-
return readdirSync(directory)
|
|
145
|
-
.sort()
|
|
146
|
-
.map((entry) => {
|
|
147
|
-
if (!/^recovery-[a-f0-9-]{36}$/.test(entry))
|
|
148
|
-
throw new Error("invalid workflow recovery ledger entry");
|
|
149
|
-
const intent = readJsonRecord<WorkflowRecoveryIntent>(
|
|
150
|
-
join(directory, entry, "intent.json"),
|
|
151
|
-
"recovery intent",
|
|
152
|
-
);
|
|
153
|
-
if (
|
|
154
|
-
intent.schema_version !== 1 ||
|
|
155
|
-
intent.operation_id !== entry ||
|
|
156
|
-
intent.run_id !== runId ||
|
|
157
|
-
intent.outcome !== "unknown" ||
|
|
158
|
-
!["reclaim_unknown_liveness", "unlock_resume"].includes(intent.action) ||
|
|
159
|
-
!/^[a-f0-9]{64}$/.test(intent.target_sha256)
|
|
160
|
-
) {
|
|
161
|
-
throw new Error("invalid workflow recovery intent authority");
|
|
162
|
-
}
|
|
163
|
-
validateWorkflowRecoveryAuthorization(intent);
|
|
164
|
-
const completionPath = join(directory, entry, "completion.json");
|
|
165
|
-
if (!existsSync(completionPath)) return { intent, outcome: "unknown" };
|
|
166
|
-
const completion = readJsonRecord<{
|
|
167
|
-
schema_version: number;
|
|
168
|
-
operation_id: string;
|
|
169
|
-
intent_sha256: string;
|
|
170
|
-
outcome: string;
|
|
171
|
-
}>(completionPath, "recovery completion");
|
|
172
|
-
if (
|
|
173
|
-
completion.schema_version !== 1 ||
|
|
174
|
-
completion.operation_id !== entry ||
|
|
175
|
-
completion.intent_sha256 !== stableDigest(intent) ||
|
|
176
|
-
completion.outcome !== "completed"
|
|
177
|
-
)
|
|
178
|
-
throw new Error("invalid workflow recovery completion authority");
|
|
179
|
-
return { intent, outcome: "completed" };
|
|
180
|
-
});
|
|
181
|
-
}
|