harnery 0.43.0 → 0.45.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/README.md +3 -3
- package/dist/commander.js +1 -0
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +41 -48
- package/dist/commands/browse.d.ts.map +1 -1
- package/dist/commands/browse.js +38 -11
- package/dist/commands/diagnostics.d.ts.map +1 -1
- package/dist/commands/diagnostics.js +10 -0
- package/dist/commands/doctor.d.ts +12 -0
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +22 -7
- package/dist/commands/files.d.ts +2 -2
- package/dist/commands/files.d.ts.map +1 -1
- package/dist/commands/files.js +7 -4
- package/dist/commands/governor.js +22 -10
- package/dist/commands/inbox.d.ts +1 -1
- package/dist/commands/inbox.d.ts.map +1 -1
- package/dist/commands/inbox.js +55 -2
- package/dist/commands/rm.d.ts.map +1 -1
- package/dist/commands/rm.js +28 -4
- package/dist/commands/servers.d.ts.map +1 -1
- package/dist/commands/servers.js +26 -17
- package/dist/commands/supervisor.d.ts.map +1 -1
- package/dist/commands/supervisor.js +7 -2
- package/dist/commands/toc.d.ts +14 -0
- package/dist/commands/toc.d.ts.map +1 -1
- package/dist/commands/toc.js +7 -4
- package/dist/commands/tunnel.d.ts +15 -0
- package/dist/commands/tunnel.d.ts.map +1 -1
- package/dist/commands/tunnel.js +453 -153
- package/dist/commands/turn-rollback.d.ts +5 -0
- package/dist/commands/turn-rollback.d.ts.map +1 -0
- package/dist/commands/turn-rollback.js +76 -0
- package/dist/commands/workflow.d.ts.map +1 -1
- package/dist/commands/workflow.js +68 -30
- package/dist/core/agents/coord-client.d.ts.map +1 -1
- package/dist/core/agents/coord-client.js +18 -0
- package/dist/core/agents/live-authority-v3.d.ts +1 -0
- package/dist/core/agents/live-authority-v3.d.ts.map +1 -1
- package/dist/core/agents/live-authority-v3.js +11 -0
- package/dist/core/agents/live-lifecycle-v3.d.ts +4 -2
- package/dist/core/agents/live-lifecycle-v3.d.ts.map +1 -1
- package/dist/core/agents/live-lifecycle-v3.js +28 -7
- package/dist/core/agents/mailbox.d.ts +9 -8
- package/dist/core/agents/mailbox.d.ts.map +1 -1
- package/dist/core/agents/mailbox.js +24 -17
- package/dist/core/agents/render/prompt-context.d.ts +2 -0
- package/dist/core/agents/render/prompt-context.d.ts.map +1 -1
- package/dist/core/agents/render/prompt-context.js +8 -12
- package/dist/core/agents/render/session-context.d.ts +2 -8
- package/dist/core/agents/render/session-context.d.ts.map +1 -1
- package/dist/core/agents/render/session-context.js +7 -30
- package/dist/core/agents/rules/stop-hook.js +3 -3
- package/dist/core/agents/state/heartbeat-writer.d.ts.map +1 -1
- package/dist/core/agents/state/heartbeat-writer.js +25 -14
- package/dist/core/agents/state/live-coordination-writer.d.ts.map +1 -1
- package/dist/core/agents/state/live-coordination-writer.js +5 -0
- package/dist/core/agents/state/pidmap.d.ts.map +1 -1
- package/dist/core/agents/state/pidmap.js +5 -0
- package/dist/core/agents/state/proc-start.d.ts +19 -1
- package/dist/core/agents/state/proc-start.d.ts.map +1 -1
- package/dist/core/agents/state/proc-start.js +46 -1
- package/dist/core/agents/state/process-handle.d.ts +26 -0
- package/dist/core/agents/state/process-handle.d.ts.map +1 -0
- package/dist/core/agents/state/process-handle.js +121 -0
- package/dist/core/agents/state/stale-sweep.d.ts.map +1 -1
- package/dist/core/agents/state/stale-sweep.js +180 -70
- package/dist/core/agents/state/unchanged-file.d.ts +44 -0
- package/dist/core/agents/state/unchanged-file.d.ts.map +1 -0
- package/dist/core/agents/state/unchanged-file.js +390 -0
- package/dist/core/artifacts/delivery-card.d.ts.map +1 -1
- package/dist/core/artifacts/delivery-card.js +2 -1
- package/dist/core/context/index.d.ts +22 -10
- package/dist/core/context/index.d.ts.map +1 -1
- package/dist/core/context/index.js +381 -119
- package/dist/core/context/observation.d.ts +26 -0
- package/dist/core/context/observation.d.ts.map +1 -0
- package/dist/core/context/observation.js +11 -0
- package/dist/core/diagnostics/bundle.d.ts.map +1 -1
- package/dist/core/diagnostics/bundle.js +25 -14
- package/dist/core/diagnostics/path-identity.d.ts +3 -0
- package/dist/core/diagnostics/path-identity.d.ts.map +1 -0
- package/dist/core/diagnostics/path-identity.js +12 -0
- package/dist/core/diagnostics/sanitize.d.ts.map +1 -1
- package/dist/core/diagnostics/sanitize.js +4 -3
- package/dist/core/events/v3/authority-outbox.d.ts.map +1 -1
- package/dist/core/events/v3/authority-outbox.js +29 -0
- package/dist/core/events/v3/generation-custody.d.ts +5 -0
- package/dist/core/events/v3/generation-custody.d.ts.map +1 -0
- package/dist/core/events/v3/generation-custody.js +50 -0
- package/dist/core/events/v3/producers/coordination-recorder.d.ts +1 -0
- package/dist/core/events/v3/producers/coordination-recorder.d.ts.map +1 -1
- package/dist/core/events/v3/producers/coordination-recorder.js +7 -0
- package/dist/core/events/v3/producers/recorder.d.ts.map +1 -1
- package/dist/core/events/v3/producers/recorder.js +77 -64
- package/dist/core/governor/planning.d.ts.map +1 -1
- package/dist/core/governor/planning.js +14 -1
- package/dist/core/governor/service-read.d.ts +10 -2
- package/dist/core/governor/service-read.d.ts.map +1 -1
- package/dist/core/governor/service-read.js +105 -22
- package/dist/core/governor/service.d.ts +20 -2
- package/dist/core/governor/service.d.ts.map +1 -1
- package/dist/core/governor/service.js +72 -47
- package/dist/core/hooks/cli.js +33 -5
- package/dist/core/inbox/contract.d.ts +2 -1
- package/dist/core/inbox/contract.d.ts.map +1 -1
- package/dist/core/inbox/index.d.ts +2 -0
- package/dist/core/inbox/index.d.ts.map +1 -1
- package/dist/core/inbox/index.js +2 -0
- package/dist/core/inbox/peer-messages.d.ts +37 -0
- package/dist/core/inbox/peer-messages.d.ts.map +1 -0
- package/dist/core/inbox/peer-messages.js +72 -0
- 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 +67 -21
- package/dist/core/inbox/targets.d.ts +22 -0
- package/dist/core/inbox/targets.d.ts.map +1 -0
- package/dist/core/inbox/targets.js +108 -0
- package/dist/core/inbox/watcher.js +7 -3
- package/dist/core/journal/index.d.ts.map +1 -1
- package/dist/core/journal/index.js +17 -2
- package/dist/core/resources/contract.d.ts +3 -0
- package/dist/core/resources/contract.d.ts.map +1 -1
- package/dist/core/resources/service-status.d.ts +14 -1
- package/dist/core/resources/service-status.d.ts.map +1 -1
- package/dist/core/resources/service-status.js +23 -13
- package/dist/core/resources/service.d.ts +7 -13
- package/dist/core/resources/service.d.ts.map +1 -1
- package/dist/core/resources/service.js +34 -91
- package/dist/core/resources/status.d.ts +2 -5
- package/dist/core/resources/status.d.ts.map +1 -1
- package/dist/core/resources/status.js +36 -7
- package/dist/core/semantic/service.d.ts.map +1 -1
- package/dist/core/semantic/service.js +2 -9
- package/dist/core/servers/index.d.ts +34 -22
- package/dist/core/servers/index.d.ts.map +1 -1
- package/dist/core/servers/index.js +297 -144
- package/dist/core/servers/tunnels.d.ts +7 -7
- package/dist/core/servers/tunnels.d.ts.map +1 -1
- package/dist/core/servers/tunnels.js +47 -10
- package/dist/core/supervisor/contract.d.ts +12 -0
- package/dist/core/supervisor/contract.d.ts.map +1 -1
- package/dist/core/supervisor/explanations.d.ts.map +1 -1
- package/dist/core/supervisor/explanations.js +2 -1
- package/dist/core/supervisor/findings.d.ts.map +1 -1
- package/dist/core/supervisor/findings.js +54 -9
- package/dist/core/supervisor/service.d.ts +7 -1
- package/dist/core/supervisor/service.d.ts.map +1 -1
- package/dist/core/supervisor/service.js +59 -29
- package/dist/core/supervisor/services.d.ts.map +1 -1
- package/dist/core/supervisor/services.js +22 -1
- package/dist/core/supervisor/status.d.ts +17 -2
- package/dist/core/supervisor/status.d.ts.map +1 -1
- package/dist/core/supervisor/status.js +70 -12
- package/dist/core/supervisor/timeline.d.ts.map +1 -1
- package/dist/core/supervisor/timeline.js +2 -1
- package/dist/core/turn-rollback/content.d.ts +53 -0
- package/dist/core/turn-rollback/content.d.ts.map +1 -0
- package/dist/core/turn-rollback/content.js +396 -0
- package/dist/core/turn-rollback/index.d.ts +72 -0
- package/dist/core/turn-rollback/index.d.ts.map +1 -0
- package/dist/core/turn-rollback/index.js +443 -0
- package/dist/core/work/state.js +7 -7
- package/dist/core/workflow/engine.d.ts.map +1 -1
- package/dist/core/workflow/engine.js +105 -32
- package/dist/core/workflow/failure-evidence.d.ts +16 -0
- package/dist/core/workflow/failure-evidence.d.ts.map +1 -0
- package/dist/core/workflow/failure-evidence.js +114 -0
- package/dist/core/workflow/index.d.ts +5 -3
- package/dist/core/workflow/index.d.ts.map +1 -1
- package/dist/core/workflow/index.js +3 -2
- package/dist/core/workflow/live-session-v3.d.ts +6 -0
- package/dist/core/workflow/live-session-v3.d.ts.map +1 -1
- package/dist/core/workflow/live-session-v3.js +126 -5
- package/dist/core/workflow/proof.d.ts +5 -5
- package/dist/core/workflow/proof.d.ts.map +1 -1
- package/dist/core/workflow/proof.js +115 -20
- package/dist/core/workflow/recovery-audit.d.ts +30 -0
- package/dist/core/workflow/recovery-audit.d.ts.map +1 -0
- package/dist/core/workflow/recovery-audit.js +116 -0
- package/dist/core/workflow/run-state.d.ts +20 -1
- package/dist/core/workflow/run-state.d.ts.map +1 -1
- package/dist/core/workflow/run-state.js +141 -32
- package/dist/core/workflow/spawn-claude.d.ts.map +1 -1
- package/dist/core/workflow/spawn-claude.js +19 -0
- package/dist/core/workflow/spawn-codex.d.ts.map +1 -1
- package/dist/core/workflow/spawn-codex.js +13 -0
- package/dist/core/workflow/spawn-cursor.d.ts.map +1 -1
- package/dist/core/workflow/spawn-cursor.js +19 -0
- package/dist/core/workflow/spawn-opencode.d.ts.map +1 -1
- package/dist/core/workflow/spawn-opencode.js +14 -0
- package/dist/core/workflow/types.d.ts +64 -17
- package/dist/core/workflow/types.d.ts.map +1 -1
- package/dist/core/workflow/workspaces/index.d.ts +0 -1
- package/dist/core/workflow/workspaces/index.d.ts.map +1 -1
- package/dist/core/workflow/workspaces/index.js +0 -1
- package/dist/core/workflow/workspaces/leases.d.ts +3 -1
- package/dist/core/workflow/workspaces/leases.d.ts.map +1 -1
- package/dist/core/workflow/workspaces/leases.js +30 -16
- package/dist/core/workflow/workspaces/local-git.d.ts +6 -2
- package/dist/core/workflow/workspaces/local-git.d.ts.map +1 -1
- package/dist/core/workflow/workspaces/local-git.js +328 -8
- package/dist/core/workflow/workspaces/ownership.d.ts +11 -0
- package/dist/core/workflow/workspaces/ownership.d.ts.map +1 -0
- package/dist/core/workflow/workspaces/ownership.js +194 -0
- package/dist/core/workflow/workspaces/reclaim.d.ts +40 -0
- package/dist/core/workflow/workspaces/reclaim.d.ts.map +1 -1
- package/dist/core/workflow/workspaces/reclaim.js +14 -0
- package/dist/core/workflow/workspaces/recovery.d.ts +2 -0
- package/dist/core/workflow/workspaces/recovery.d.ts.map +1 -1
- package/dist/core/workflow/workspaces/recovery.js +42 -10
- package/dist/core/workflow/workspaces/state.d.ts +1 -0
- package/dist/core/workflow/workspaces/state.d.ts.map +1 -1
- package/dist/core/workflow/workspaces/state.js +21 -1
- package/dist/lib/browser/windows-chrome.d.ts +100 -12
- package/dist/lib/browser/windows-chrome.d.ts.map +1 -1
- package/dist/lib/browser/windows-chrome.js +262 -73
- package/dist/lib/docs-links.d.ts.map +1 -1
- package/dist/lib/docs-links.js +45 -2
- package/dist/lib/guarded-remove.d.ts +7 -0
- package/dist/lib/guarded-remove.d.ts.map +1 -1
- package/dist/lib/guarded-remove.js +106 -12
- package/dist/lib/identities/assume.d.ts.map +1 -1
- package/dist/lib/identities/assume.js +4 -0
- package/dist/lib/tunnel/state.d.ts +13 -6
- package/dist/lib/tunnel/state.d.ts.map +1 -1
- package/dist/lib/tunnel/state.js +58 -12
- package/dist/lib/zip/index.d.ts +41 -0
- package/dist/lib/zip/index.d.ts.map +1 -0
- package/dist/lib/zip/index.js +398 -0
- package/package.json +12 -1
- package/src/commander.ts +10 -0
- package/src/commands/agents.ts +54 -63
- package/src/commands/browse.ts +50 -14
- package/src/commands/diagnostics.ts +10 -0
- package/src/commands/doctor.ts +26 -7
- package/src/commands/files.ts +13 -5
- package/src/commands/governor.ts +23 -10
- package/src/commands/inbox.ts +52 -2
- package/src/commands/rm.ts +43 -4
- package/src/commands/servers.ts +27 -26
- package/src/commands/supervisor.ts +7 -2
- package/src/commands/toc.ts +14 -6
- package/src/commands/tunnel.ts +533 -166
- package/src/commands/turn-rollback.ts +111 -0
- package/src/commands/workflow.ts +89 -30
- package/src/core/agents/coord-client.ts +20 -0
- package/src/core/agents/live-authority-v3.ts +17 -0
- package/src/core/agents/live-lifecycle-v3.ts +52 -14
- package/src/core/agents/mailbox.ts +26 -17
- package/src/core/agents/render/prompt-context.ts +10 -12
- package/src/core/agents/render/session-context.ts +9 -32
- package/src/core/agents/rules/stop-hook.ts +3 -3
- package/src/core/agents/state/heartbeat-writer.ts +29 -12
- package/src/core/agents/state/live-coordination-writer.ts +29 -0
- package/src/core/agents/state/pidmap.ts +13 -0
- package/src/core/agents/state/proc-start.ts +62 -2
- package/src/core/agents/state/process-handle.ts +165 -0
- package/src/core/agents/state/stale-sweep.ts +247 -82
- package/src/core/agents/state/unchanged-file.ts +456 -0
- package/src/core/artifacts/delivery-card.ts +7 -1
- package/src/core/context/index.ts +446 -136
- package/src/core/context/observation.ts +29 -0
- package/src/core/diagnostics/bundle.ts +23 -18
- package/src/core/diagnostics/path-identity.ts +15 -0
- package/src/core/diagnostics/sanitize.ts +4 -3
- package/src/core/events/v3/authority-outbox.ts +56 -0
- package/src/core/events/v3/generation-custody.ts +59 -0
- package/src/core/events/v3/producers/coordination-recorder.ts +15 -0
- package/src/core/events/v3/producers/recorder.ts +94 -68
- package/src/core/governor/planning.ts +20 -8
- package/src/core/governor/service-read.ts +128 -20
- package/src/core/governor/service.ts +119 -42
- package/src/core/hooks/cli.ts +33 -5
- package/src/core/inbox/contract.ts +2 -1
- package/src/core/inbox/index.ts +2 -0
- package/src/core/inbox/peer-messages.ts +94 -0
- package/src/core/inbox/service.ts +88 -22
- package/src/core/inbox/targets.ts +148 -0
- package/src/core/inbox/watcher.ts +8 -9
- package/src/core/journal/index.ts +19 -2
- package/src/core/resources/contract.ts +4 -0
- package/src/core/resources/service-status.ts +35 -12
- package/src/core/resources/service.ts +57 -95
- package/src/core/resources/status.ts +57 -8
- package/src/core/semantic/service.ts +2 -8
- package/src/core/servers/index.ts +376 -141
- package/src/core/servers/tunnels.ts +57 -13
- package/src/core/supervisor/contract.ts +13 -0
- package/src/core/supervisor/explanations.ts +4 -1
- package/src/core/supervisor/findings.ts +68 -10
- package/src/core/supervisor/service.ts +87 -26
- package/src/core/supervisor/services.ts +26 -8
- package/src/core/supervisor/status.ts +89 -12
- package/src/core/supervisor/timeline.ts +2 -1
- package/src/core/turn-rollback/content.ts +499 -0
- package/src/core/turn-rollback/index.ts +580 -0
- package/src/core/work/state.ts +7 -7
- package/src/core/workflow/engine.ts +131 -49
- package/src/core/workflow/failure-evidence.ts +141 -0
- package/src/core/workflow/index.ts +12 -2
- package/src/core/workflow/live-session-v3.ts +146 -5
- package/src/core/workflow/proof.ts +134 -26
- package/src/core/workflow/recovery-audit.ts +181 -0
- package/src/core/workflow/run-state.ts +165 -34
- package/src/core/workflow/spawn-claude.ts +18 -0
- package/src/core/workflow/spawn-codex.ts +13 -0
- package/src/core/workflow/spawn-cursor.ts +18 -0
- package/src/core/workflow/spawn-opencode.ts +14 -0
- package/src/core/workflow/types.ts +51 -17
- package/src/core/workflow/workspaces/index.ts +0 -1
- package/src/core/workflow/workspaces/leases.ts +48 -17
- package/src/core/workflow/workspaces/local-git.ts +388 -7
- package/src/core/workflow/workspaces/ownership.ts +232 -0
- package/src/core/workflow/workspaces/reclaim.ts +62 -0
- package/src/core/workflow/workspaces/recovery.ts +45 -10
- package/src/core/workflow/workspaces/state.ts +20 -0
- package/src/lib/browser/windows-chrome.ts +346 -86
- package/src/lib/docs-links.ts +49 -2
- package/src/lib/guarded-remove.ts +132 -14
- package/src/lib/identities/assume.ts +4 -0
- package/src/lib/tunnel/state.ts +70 -15
- package/src/lib/zip/index.ts +483 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
+
import { canonicalizeDiagnosticIdentity } from "../diagnostics/path-identity.ts";
|
|
2
3
|
import {
|
|
3
4
|
SUPERVISOR_DIAGNOSTIC_LIMITS,
|
|
4
5
|
SUPERVISOR_TIMELINE_SCHEMA_VERSION,
|
|
@@ -129,5 +130,5 @@ function clusterRelatedSources(
|
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
function stableId(prefix: string, value: string): string {
|
|
132
|
-
return `${prefix}_${createHash("sha256").update(value).digest("hex").slice(0, 24)}`;
|
|
133
|
+
return `${prefix}_${createHash("sha256").update(canonicalizeDiagnosticIdentity(value)).digest("hex").slice(0, 24)}`;
|
|
133
134
|
}
|
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import {
|
|
4
|
+
closeSync,
|
|
5
|
+
constants,
|
|
6
|
+
existsSync,
|
|
7
|
+
fchmodSync,
|
|
8
|
+
fstatSync,
|
|
9
|
+
fsyncSync,
|
|
10
|
+
lstatSync,
|
|
11
|
+
mkdirSync,
|
|
12
|
+
openSync,
|
|
13
|
+
readFileSync,
|
|
14
|
+
realpathSync,
|
|
15
|
+
renameSync,
|
|
16
|
+
unlinkSync,
|
|
17
|
+
writeFileSync,
|
|
18
|
+
} from "node:fs";
|
|
19
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
20
|
+
import { stateDirMode, stateFileMode } from "../storage/modes.ts";
|
|
21
|
+
import { fsyncParentDirectory, stableDigest } from "../workflow/durable-record.ts";
|
|
22
|
+
import {
|
|
23
|
+
assertSafeRelativeSegment,
|
|
24
|
+
containsPath,
|
|
25
|
+
descriptorPath,
|
|
26
|
+
filesystemIdentity,
|
|
27
|
+
sameFilesystemIdentity,
|
|
28
|
+
} from "../workflow/workspaces/paths.ts";
|
|
29
|
+
import type { WorkspaceBinding } from "../workflow/workspaces/types.ts";
|
|
30
|
+
|
|
31
|
+
export const SNAPSHOT_LIMIT = 8 * 1024 * 1024;
|
|
32
|
+
export interface BlobEntry {
|
|
33
|
+
oid: string;
|
|
34
|
+
mode: "100644" | "100755";
|
|
35
|
+
}
|
|
36
|
+
export interface ContentEntry {
|
|
37
|
+
path: string;
|
|
38
|
+
index: BlobEntry | null;
|
|
39
|
+
worktree: BlobEntry | null;
|
|
40
|
+
untracked: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface ContentSnapshot {
|
|
43
|
+
head: string;
|
|
44
|
+
index_tree: string;
|
|
45
|
+
worktree_tree: string;
|
|
46
|
+
entries: ContentEntry[];
|
|
47
|
+
total_bytes: number;
|
|
48
|
+
sha256: string;
|
|
49
|
+
}
|
|
50
|
+
interface ObservedContent {
|
|
51
|
+
entries: ContentEntry[];
|
|
52
|
+
blobs: Map<string, Buffer>;
|
|
53
|
+
total: number;
|
|
54
|
+
head: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function git(
|
|
58
|
+
root: string,
|
|
59
|
+
args: string[],
|
|
60
|
+
options: { input?: Buffer | string; index?: string; bare?: boolean } = {},
|
|
61
|
+
): Buffer {
|
|
62
|
+
const env = { ...process.env };
|
|
63
|
+
for (const key of Object.keys(env)) if (key.startsWith("GIT_")) delete env[key];
|
|
64
|
+
Object.assign(env, {
|
|
65
|
+
GIT_OPTIONAL_LOCKS: "0",
|
|
66
|
+
GIT_CONFIG_NOSYSTEM: "1",
|
|
67
|
+
GIT_CONFIG_GLOBAL: "/dev/null",
|
|
68
|
+
GIT_LITERAL_PATHSPECS: "1",
|
|
69
|
+
});
|
|
70
|
+
if (args[0] === "check-ignore") delete env.GIT_LITERAL_PATHSPECS;
|
|
71
|
+
if (options.index) env.GIT_INDEX_FILE = options.index;
|
|
72
|
+
return execFileSync(
|
|
73
|
+
"git",
|
|
74
|
+
[options.bare ? `--git-dir=${root}` : "-C", ...(options.bare ? [] : [root]), ...args],
|
|
75
|
+
{
|
|
76
|
+
env,
|
|
77
|
+
input: options.input,
|
|
78
|
+
maxBuffer: SNAPSHOT_LIMIT + 1024 * 1024,
|
|
79
|
+
timeout: 10_000,
|
|
80
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
81
|
+
},
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
export function textGit(root: string, args: string[], options?: Parameters<typeof git>[2]): string {
|
|
85
|
+
return git(root, args, options).toString("utf8").trim();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function safePaths(binding: WorkspaceBinding, paths: readonly string[]): string[] {
|
|
89
|
+
if (!Array.isArray(paths) || paths.length === 0 || paths.length > 100)
|
|
90
|
+
throw new Error("path count limit is 1 to 100");
|
|
91
|
+
const normalized = paths
|
|
92
|
+
.map((path) => {
|
|
93
|
+
if (typeof path !== "string" || path.length > 2000) throw new Error("invalid content path");
|
|
94
|
+
for (const part of path.split("/")) {
|
|
95
|
+
assertSafeRelativeSegment(part, "content path");
|
|
96
|
+
if ([".git", ".harnery"].includes(part.toLowerCase()))
|
|
97
|
+
throw new Error("administrative content path is forbidden");
|
|
98
|
+
}
|
|
99
|
+
if (
|
|
100
|
+
relative(binding.workspace_root, resolve(binding.workspace_root, path)).replaceAll(
|
|
101
|
+
"\\",
|
|
102
|
+
"/",
|
|
103
|
+
) !== path
|
|
104
|
+
)
|
|
105
|
+
throw new Error("content path escapes workspace");
|
|
106
|
+
return path;
|
|
107
|
+
})
|
|
108
|
+
.sort();
|
|
109
|
+
if (new Set(normalized).size !== normalized.length) throw new Error("duplicate content paths");
|
|
110
|
+
for (const path of normalized) {
|
|
111
|
+
const opened = openParent(binding, path);
|
|
112
|
+
opened.close();
|
|
113
|
+
}
|
|
114
|
+
return normalized;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function openParent(
|
|
118
|
+
binding: WorkspaceBinding,
|
|
119
|
+
path: string,
|
|
120
|
+
): { path: string; close(): void } {
|
|
121
|
+
const fds: number[] = [];
|
|
122
|
+
try {
|
|
123
|
+
const root = binding.workspace_root;
|
|
124
|
+
let fd = openSync(root, constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
|
|
125
|
+
fds.push(fd);
|
|
126
|
+
if (
|
|
127
|
+
!sameFilesystemIdentity(
|
|
128
|
+
filesystemIdentity(descriptorPath(fd)),
|
|
129
|
+
binding.workspace_root_identity,
|
|
130
|
+
)
|
|
131
|
+
)
|
|
132
|
+
throw new Error("workspace root identity changed");
|
|
133
|
+
for (const segment of path.split("/").slice(0, -1)) {
|
|
134
|
+
fd = openSync(
|
|
135
|
+
join(descriptorPath(fd), segment),
|
|
136
|
+
constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW,
|
|
137
|
+
);
|
|
138
|
+
fds.push(fd);
|
|
139
|
+
if (existsSync(join(descriptorPath(fd), ".git")))
|
|
140
|
+
throw new Error("nested repository boundary is forbidden");
|
|
141
|
+
}
|
|
142
|
+
const parent = descriptorPath(fd);
|
|
143
|
+
const real = realpathSync(parent);
|
|
144
|
+
if (!containsPath(root, real)) throw new Error("content parent escaped workspace");
|
|
145
|
+
for (const reserved of [
|
|
146
|
+
binding.repository?.gitdir.realpath,
|
|
147
|
+
binding.repository?.common_dir.realpath,
|
|
148
|
+
]) {
|
|
149
|
+
if (reserved && containsPath(reserved, real))
|
|
150
|
+
throw new Error("Git administrative content is forbidden");
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
path: join(parent, path.split("/").at(-1)!),
|
|
154
|
+
close: () => {
|
|
155
|
+
for (const handle of fds.reverse()) closeSync(handle);
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
} catch (error) {
|
|
159
|
+
for (const fd of fds.reverse()) closeSync(fd);
|
|
160
|
+
throw error;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function bytesAt(
|
|
165
|
+
binding: WorkspaceBinding,
|
|
166
|
+
path: string,
|
|
167
|
+
): { bytes: Buffer; mode: BlobEntry["mode"] } | null {
|
|
168
|
+
const parent = openParent(binding, path);
|
|
169
|
+
try {
|
|
170
|
+
let stat: import("node:fs").Stats;
|
|
171
|
+
try {
|
|
172
|
+
stat = lstatSync(parent.path);
|
|
173
|
+
} catch (error) {
|
|
174
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") return null;
|
|
175
|
+
throw error;
|
|
176
|
+
}
|
|
177
|
+
if (!stat.isFile() || stat.nlink !== 1)
|
|
178
|
+
throw new Error("content must be an unlinked regular file");
|
|
179
|
+
if (stat.size > SNAPSHOT_LIMIT) throw new Error("snapshot byte limit exceeded");
|
|
180
|
+
const fd = openSync(parent.path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
181
|
+
try {
|
|
182
|
+
const current = fstatSync(fd);
|
|
183
|
+
if (
|
|
184
|
+
!current.isFile() ||
|
|
185
|
+
current.nlink !== 1 ||
|
|
186
|
+
current.ino !== stat.ino ||
|
|
187
|
+
current.dev !== stat.dev
|
|
188
|
+
)
|
|
189
|
+
throw new Error("content identity changed");
|
|
190
|
+
const bytes = readFileSync(fd);
|
|
191
|
+
const after = fstatSync(fd);
|
|
192
|
+
if (
|
|
193
|
+
after.size !== current.size ||
|
|
194
|
+
after.mtimeMs !== current.mtimeMs ||
|
|
195
|
+
after.ctimeMs !== current.ctimeMs
|
|
196
|
+
)
|
|
197
|
+
throw new Error("content changed during capture");
|
|
198
|
+
return { bytes, mode: current.mode & 0o111 ? "100755" : "100644" };
|
|
199
|
+
} finally {
|
|
200
|
+
closeSync(fd);
|
|
201
|
+
}
|
|
202
|
+
} finally {
|
|
203
|
+
parent.close();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function indexEntries(
|
|
208
|
+
binding: WorkspaceBinding,
|
|
209
|
+
paths: string[],
|
|
210
|
+
): Map<string, { mode: BlobEntry["mode"]; source: string }> {
|
|
211
|
+
const root = binding.workspace_root;
|
|
212
|
+
if (textGit(root, ["rev-parse", "--shared-index-path"]))
|
|
213
|
+
throw new Error("split index is unsupported");
|
|
214
|
+
try {
|
|
215
|
+
if (textGit(root, ["config", "--bool", "index.sparse"]) === "true")
|
|
216
|
+
throw new Error("sparse index is unsupported");
|
|
217
|
+
} catch (error) {
|
|
218
|
+
if (!(error && typeof error === "object" && "status" in error && error.status === 1))
|
|
219
|
+
throw error;
|
|
220
|
+
}
|
|
221
|
+
const flags = git(root, ["ls-files", "-v", "-z", "--", ...paths])
|
|
222
|
+
.toString("utf8")
|
|
223
|
+
.split("\0")
|
|
224
|
+
.filter(Boolean);
|
|
225
|
+
if (flags.some((flag) => !flag.startsWith("H ")))
|
|
226
|
+
throw new Error("selected index flags are unsupported");
|
|
227
|
+
const entries = new Map<string, { mode: BlobEntry["mode"]; source: string }>();
|
|
228
|
+
const debugFlags = git(root, ["ls-files", "--debug", "-z", "--", ...paths]).toString("utf8");
|
|
229
|
+
for (const match of debugFlags.matchAll(/flags: ([a-f0-9]+)\n/g)) {
|
|
230
|
+
if ((Number.parseInt(match[1]!, 16) & 0x20000000) !== 0)
|
|
231
|
+
throw new Error("intent-to-add index entries are unsupported");
|
|
232
|
+
}
|
|
233
|
+
for (const line of git(root, ["ls-files", "--stage", "-z", "--", ...paths])
|
|
234
|
+
.toString("utf8")
|
|
235
|
+
.split("\0")
|
|
236
|
+
.filter(Boolean)) {
|
|
237
|
+
const match = /^(100644|100755) ([a-f0-9]{40,64}) 0\t(.+)$/.exec(line);
|
|
238
|
+
if (!match || /^0+$/.test(match[2]!) || !paths.includes(match[3]!))
|
|
239
|
+
throw new Error("unsupported index entry");
|
|
240
|
+
entries.set(match[3]!, { mode: match[1] as BlobEntry["mode"], source: match[2]! });
|
|
241
|
+
}
|
|
242
|
+
return entries;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export function observe(
|
|
246
|
+
binding: WorkspaceBinding,
|
|
247
|
+
store: string,
|
|
248
|
+
paths: string[],
|
|
249
|
+
): ObservedContent {
|
|
250
|
+
const staged = indexEntries(binding, paths);
|
|
251
|
+
const blobs = new Map<string, Buffer>();
|
|
252
|
+
let total = 0;
|
|
253
|
+
const blob = (bytes: Buffer, mode: BlobEntry["mode"]): BlobEntry => {
|
|
254
|
+
total += bytes.length;
|
|
255
|
+
if (total > SNAPSHOT_LIMIT) throw new Error("snapshot byte limit exceeded");
|
|
256
|
+
const oid = textGit(store, ["hash-object", "--stdin"], { bare: true, input: bytes });
|
|
257
|
+
blobs.set(oid, bytes);
|
|
258
|
+
return { oid, mode };
|
|
259
|
+
};
|
|
260
|
+
const entries = paths.map((path): ContentEntry => {
|
|
261
|
+
const index = staged.get(path);
|
|
262
|
+
const worktree = bytesAt(binding, path);
|
|
263
|
+
// check-ignore without --no-index only reports untracked ignored paths.
|
|
264
|
+
if (!index) {
|
|
265
|
+
try {
|
|
266
|
+
git(binding.workspace_root, ["check-ignore", "-q", "--", path]);
|
|
267
|
+
throw new Error("ignored content path is forbidden");
|
|
268
|
+
} catch (error) {
|
|
269
|
+
if (!(error && typeof error === "object" && "status" in error && error.status === 1))
|
|
270
|
+
throw error;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return {
|
|
274
|
+
path,
|
|
275
|
+
index: index
|
|
276
|
+
? blob(git(binding.workspace_root, ["cat-file", "blob", index.source]), index.mode)
|
|
277
|
+
: null,
|
|
278
|
+
worktree: worktree ? blob(worktree.bytes, worktree.mode) : null,
|
|
279
|
+
untracked: !index && worktree !== null,
|
|
280
|
+
};
|
|
281
|
+
});
|
|
282
|
+
return { entries, blobs, total, head: textGit(binding.workspace_root, ["rev-parse", "HEAD"]) };
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function tree(store: string, entries: ContentEntry[], side: "index" | "worktree"): string {
|
|
286
|
+
const temporary = join(dirname(store), `tree-${randomUUID()}.index`);
|
|
287
|
+
try {
|
|
288
|
+
git(store, ["read-tree", "--empty"], { bare: true, index: temporary });
|
|
289
|
+
for (const entry of entries) {
|
|
290
|
+
const blob = entry[side];
|
|
291
|
+
if (blob)
|
|
292
|
+
git(
|
|
293
|
+
store,
|
|
294
|
+
["update-index", "--add", "--cacheinfo", `${blob.mode},${blob.oid},${entry.path}`],
|
|
295
|
+
{ bare: true, index: temporary },
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
return textGit(store, ["write-tree"], { bare: true, index: temporary });
|
|
299
|
+
} finally {
|
|
300
|
+
if (existsSync(temporary)) unlinkSync(temporary);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export function persistSnapshot(
|
|
305
|
+
store: string,
|
|
306
|
+
observed: ObservedContent,
|
|
307
|
+
ref: string,
|
|
308
|
+
): ContentSnapshot {
|
|
309
|
+
for (const bytes of observed.blobs.values())
|
|
310
|
+
git(store, ["hash-object", "-w", "--stdin"], { bare: true, input: bytes });
|
|
311
|
+
const basis = {
|
|
312
|
+
head: observed.head,
|
|
313
|
+
entries: observed.entries,
|
|
314
|
+
total_bytes: observed.total,
|
|
315
|
+
index_tree: tree(store, observed.entries, "index"),
|
|
316
|
+
worktree_tree: tree(store, observed.entries, "worktree"),
|
|
317
|
+
};
|
|
318
|
+
for (const side of ["index", "worktree"] as const)
|
|
319
|
+
git(store, ["update-ref", `refs/turns/${ref}/${side}`, basis[`${side}_tree`]], { bare: true });
|
|
320
|
+
return { ...basis, sha256: stableDigest(basis) };
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
export function verifySnapshot(store: string, snapshot: ContentSnapshot): void {
|
|
324
|
+
const { sha256, ...basis } = snapshot;
|
|
325
|
+
if (
|
|
326
|
+
sha256 !== stableDigest(basis) ||
|
|
327
|
+
!Number.isSafeInteger(snapshot.total_bytes) ||
|
|
328
|
+
snapshot.total_bytes < 0 ||
|
|
329
|
+
snapshot.total_bytes > SNAPSHOT_LIMIT
|
|
330
|
+
)
|
|
331
|
+
throw new Error("snapshot digest or byte limit changed");
|
|
332
|
+
let total = 0;
|
|
333
|
+
for (const side of ["index", "worktree"] as const) {
|
|
334
|
+
const actual = git(store, ["ls-tree", "-r", "-z", snapshot[`${side}_tree`]], { bare: true })
|
|
335
|
+
.toString("utf8")
|
|
336
|
+
.split("\0")
|
|
337
|
+
.filter(Boolean)
|
|
338
|
+
.sort();
|
|
339
|
+
const expected = snapshot.entries
|
|
340
|
+
.filter((entry) => entry[side])
|
|
341
|
+
.map((entry) => `${entry[side]!.mode} blob ${entry[side]!.oid}\t${entry.path}`)
|
|
342
|
+
.sort();
|
|
343
|
+
if (stableDigest(actual) !== stableDigest(expected)) throw new Error("snapshot tree changed");
|
|
344
|
+
for (const entry of snapshot.entries) {
|
|
345
|
+
const blob = entry[side];
|
|
346
|
+
if (blob) {
|
|
347
|
+
const bytes = git(store, ["cat-file", "blob", blob.oid], { bare: true });
|
|
348
|
+
if (textGit(store, ["hash-object", "--stdin"], { bare: true, input: bytes }) !== blob.oid)
|
|
349
|
+
throw new Error("snapshot blob digest changed");
|
|
350
|
+
total += bytes.length;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
if (total !== snapshot.total_bytes) throw new Error("snapshot byte count changed");
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
export function currentMatches(
|
|
358
|
+
binding: WorkspaceBinding,
|
|
359
|
+
store: string,
|
|
360
|
+
snapshot: ContentSnapshot,
|
|
361
|
+
): boolean {
|
|
362
|
+
const current = observe(
|
|
363
|
+
binding,
|
|
364
|
+
store,
|
|
365
|
+
snapshot.entries.map((entry) => entry.path),
|
|
366
|
+
);
|
|
367
|
+
return (
|
|
368
|
+
current.head === snapshot.head &&
|
|
369
|
+
stableDigest(current.entries) === stableDigest(snapshot.entries)
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export interface IndexLock {
|
|
374
|
+
path: string;
|
|
375
|
+
privatePath: string;
|
|
376
|
+
publish(): void;
|
|
377
|
+
close(): void;
|
|
378
|
+
}
|
|
379
|
+
export function lockIndex(binding: WorkspaceBinding, state: string): IndexLock {
|
|
380
|
+
const path = join(binding.repository!.gitdir.realpath, "index");
|
|
381
|
+
const lock = `${path}.lock`;
|
|
382
|
+
const fd = openSync(lock, "wx", stateFileMode());
|
|
383
|
+
const identity = fstatSync(fd, { bigint: true });
|
|
384
|
+
const privatePath = join(state, `live-${randomUUID()}.index`);
|
|
385
|
+
let published = false;
|
|
386
|
+
const exact = () => {
|
|
387
|
+
const current = lstatSync(lock, { bigint: true });
|
|
388
|
+
if (!current.isFile() || current.dev !== identity.dev || current.ino !== identity.ino)
|
|
389
|
+
throw new Error("Git index lock changed");
|
|
390
|
+
};
|
|
391
|
+
try {
|
|
392
|
+
writeFileSync(privatePath, readFileSync(path), { flag: "wx", mode: stateFileMode() });
|
|
393
|
+
} catch (error) {
|
|
394
|
+
closeSync(fd);
|
|
395
|
+
exact();
|
|
396
|
+
unlinkSync(lock);
|
|
397
|
+
throw error;
|
|
398
|
+
}
|
|
399
|
+
return {
|
|
400
|
+
path,
|
|
401
|
+
privatePath,
|
|
402
|
+
publish() {
|
|
403
|
+
exact();
|
|
404
|
+
writeFileSync(fd, readFileSync(privatePath));
|
|
405
|
+
fsyncSync(fd);
|
|
406
|
+
exact();
|
|
407
|
+
renameSync(lock, path);
|
|
408
|
+
published = true;
|
|
409
|
+
const dir = openSync(dirname(path), "r");
|
|
410
|
+
try {
|
|
411
|
+
fsyncSync(dir);
|
|
412
|
+
} finally {
|
|
413
|
+
closeSync(dir);
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
close() {
|
|
417
|
+
closeSync(fd);
|
|
418
|
+
if (!published) {
|
|
419
|
+
exact();
|
|
420
|
+
unlinkSync(lock);
|
|
421
|
+
}
|
|
422
|
+
if (existsSync(privatePath)) unlinkSync(privatePath);
|
|
423
|
+
},
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
export function stageBefore(
|
|
428
|
+
binding: WorkspaceBinding,
|
|
429
|
+
store: string,
|
|
430
|
+
before: ContentSnapshot,
|
|
431
|
+
index: IndexLock,
|
|
432
|
+
): void {
|
|
433
|
+
for (const entry of before.entries) {
|
|
434
|
+
if (entry.index) {
|
|
435
|
+
const bytes = git(store, ["cat-file", "blob", entry.index.oid], { bare: true });
|
|
436
|
+
const sourceOid = textGit(binding.workspace_root, ["hash-object", "-w", "--stdin"], {
|
|
437
|
+
input: bytes,
|
|
438
|
+
});
|
|
439
|
+
git(
|
|
440
|
+
binding.workspace_root,
|
|
441
|
+
["update-index", "--add", "--cacheinfo", `${entry.index.mode},${sourceOid},${entry.path}`],
|
|
442
|
+
{ index: index.privatePath },
|
|
443
|
+
);
|
|
444
|
+
} else
|
|
445
|
+
git(binding.workspace_root, ["update-index", "--force-remove", "--", entry.path], {
|
|
446
|
+
index: index.privatePath,
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export function restoreFile(binding: WorkspaceBinding, store: string, entry: ContentEntry): void {
|
|
452
|
+
const parent = openParent(binding, entry.path);
|
|
453
|
+
const temporary = `${parent.path}.restore-${randomUUID()}`;
|
|
454
|
+
try {
|
|
455
|
+
if (!entry.worktree) {
|
|
456
|
+
if (existsSync(parent.path)) unlinkSync(parent.path);
|
|
457
|
+
} else {
|
|
458
|
+
const fd = openSync(temporary, "wx", entry.worktree.mode === "100755" ? 0o755 : 0o644);
|
|
459
|
+
try {
|
|
460
|
+
fchmodSync(fd, entry.worktree.mode === "100755" ? 0o755 : 0o644);
|
|
461
|
+
writeFileSync(fd, git(store, ["cat-file", "blob", entry.worktree.oid], { bare: true }));
|
|
462
|
+
fsyncSync(fd);
|
|
463
|
+
} finally {
|
|
464
|
+
closeSync(fd);
|
|
465
|
+
}
|
|
466
|
+
renameSync(temporary, parent.path);
|
|
467
|
+
}
|
|
468
|
+
const fd = openSync(dirname(parent.path), "r");
|
|
469
|
+
try {
|
|
470
|
+
fsyncSync(fd);
|
|
471
|
+
} finally {
|
|
472
|
+
closeSync(fd);
|
|
473
|
+
}
|
|
474
|
+
} finally {
|
|
475
|
+
if (existsSync(temporary)) unlinkSync(temporary);
|
|
476
|
+
parent.close();
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
export function ensureDirectory(path: string): void {
|
|
481
|
+
if (!existsSync(path)) {
|
|
482
|
+
ensureDirectory(dirname(path));
|
|
483
|
+
mkdirSync(path, { mode: stateDirMode() });
|
|
484
|
+
const fd = openSync(path, constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
|
|
485
|
+
try {
|
|
486
|
+
fchmodSync(fd, stateDirMode());
|
|
487
|
+
fsyncSync(fd);
|
|
488
|
+
} finally {
|
|
489
|
+
closeSync(fd);
|
|
490
|
+
}
|
|
491
|
+
fsyncParentDirectory(path);
|
|
492
|
+
}
|
|
493
|
+
if (
|
|
494
|
+
!lstatSync(path).isDirectory() ||
|
|
495
|
+
lstatSync(path).isSymbolicLink() ||
|
|
496
|
+
realpathSync(path) !== resolve(path)
|
|
497
|
+
)
|
|
498
|
+
throw new Error("rollback state path is unsafe");
|
|
499
|
+
}
|