@elie-laloum/outpost 2.0.0 → 3.0.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/CHANGELOG.md +24 -0
- package/dist/adapters/agents/claude-diagnostics.d.ts +1 -0
- package/dist/adapters/agents/claude-diagnostics.js +7 -0
- package/dist/adapters/agents/claude-diagnostics.js.map +1 -0
- package/dist/adapters/agents/cli-diagnostics.constants.d.ts +12 -0
- package/dist/adapters/agents/cli-diagnostics.constants.js +24 -0
- package/dist/adapters/agents/cli-diagnostics.constants.js.map +1 -0
- package/dist/adapters/agents/cli-diagnostics.d.ts +4 -0
- package/dist/adapters/agents/cli-diagnostics.js +14 -0
- package/dist/adapters/agents/cli-diagnostics.js.map +1 -0
- package/dist/adapters/agents/cli-diagnostics.types.d.ts +13 -0
- package/dist/adapters/agents/cli-diagnostics.types.js +2 -0
- package/dist/adapters/agents/cli-diagnostics.types.js.map +1 -0
- package/dist/adapters/agents/codex-diagnostics.d.ts +1 -0
- package/dist/adapters/agents/codex-diagnostics.js +7 -0
- package/dist/adapters/agents/codex-diagnostics.js.map +1 -0
- package/dist/adapters/agents/protocol-fixtures.constants.d.ts +2 -0
- package/dist/adapters/agents/protocol-fixtures.constants.js +68 -0
- package/dist/adapters/agents/protocol-fixtures.constants.js.map +1 -0
- package/dist/adapters/agents/protocol-fixtures.types.d.ts +6 -0
- package/dist/adapters/agents/protocol-fixtures.types.js +2 -0
- package/dist/adapters/agents/protocol-fixtures.types.js.map +1 -0
- package/dist/application/diagnostic-probe.d.ts +3 -0
- package/dist/application/diagnostic-probe.js +55 -0
- package/dist/application/diagnostic-probe.js.map +1 -0
- package/dist/application/doctor-agent.constants.d.ts +9 -0
- package/dist/application/doctor-agent.constants.js +8 -0
- package/dist/application/doctor-agent.constants.js.map +1 -0
- package/dist/application/doctor-agent.d.ts +3 -0
- package/dist/application/doctor-agent.js +53 -0
- package/dist/application/doctor-agent.js.map +1 -0
- package/dist/application/doctor-image.d.ts +3 -0
- package/dist/application/doctor-image.js +133 -0
- package/dist/application/doctor-image.js.map +1 -0
- package/dist/application/doctor-protocol.d.ts +3 -0
- package/dist/application/doctor-protocol.js +29 -0
- package/dist/application/doctor-protocol.js.map +1 -0
- package/dist/application/doctor-protocol.types.d.ts +10 -0
- package/dist/application/doctor-protocol.types.js +2 -0
- package/dist/application/doctor-protocol.types.js.map +1 -0
- package/dist/application/doctor-sandbox.constants.d.ts +5 -0
- package/dist/application/doctor-sandbox.constants.js +6 -0
- package/dist/application/doctor-sandbox.constants.js.map +1 -0
- package/dist/application/doctor-sandbox.d.ts +4 -0
- package/dist/application/doctor-sandbox.js +133 -0
- package/dist/application/doctor-sandbox.js.map +1 -0
- package/dist/application/doctor-sandbox.types.d.ts +23 -0
- package/dist/application/doctor-sandbox.types.js +2 -0
- package/dist/application/doctor-sandbox.types.js.map +1 -0
- package/dist/application/doctor-transfers.constants.d.ts +6 -0
- package/dist/application/doctor-transfers.constants.js +7 -0
- package/dist/application/doctor-transfers.constants.js.map +1 -0
- package/dist/application/doctor-transfers.d.ts +4 -0
- package/dist/application/doctor-transfers.js +88 -0
- package/dist/application/doctor-transfers.js.map +1 -0
- package/dist/application/doctor.constants.d.ts +9 -0
- package/dist/application/doctor.constants.js +15 -0
- package/dist/application/doctor.constants.js.map +1 -0
- package/dist/application/doctor.d.ts +3 -0
- package/dist/application/doctor.js +106 -0
- package/dist/application/doctor.js.map +1 -0
- package/dist/application/doctor.types.d.ts +39 -0
- package/dist/application/doctor.types.js +2 -0
- package/dist/application/doctor.types.js.map +1 -0
- package/dist/application/execution.js +1 -0
- package/dist/application/execution.js.map +1 -1
- package/dist/application/outpost.types.d.ts +2 -0
- package/dist/application/outpost.types.js.map +1 -1
- package/dist/application/recovery-checksum-capture.d.ts +2 -0
- package/dist/application/recovery-checksum-capture.js +32 -0
- package/dist/application/recovery-checksum-capture.js.map +1 -0
- package/dist/application/recovery-checksum-paths.d.ts +2 -0
- package/dist/application/recovery-checksum-paths.js +11 -0
- package/dist/application/recovery-checksum-paths.js.map +1 -0
- package/dist/application/recovery-checksums.constants.d.ts +5 -0
- package/dist/application/recovery-checksums.constants.js +6 -0
- package/dist/application/recovery-checksums.constants.js.map +1 -0
- package/dist/application/recovery-checksums.d.ts +3 -0
- package/dist/application/recovery-checksums.js +94 -0
- package/dist/application/recovery-checksums.js.map +1 -0
- package/dist/application/recovery-checksums.types.d.ts +17 -0
- package/dist/application/recovery-checksums.types.js +2 -0
- package/dist/application/recovery-checksums.types.js.map +1 -0
- package/dist/application/recovery-inspection.d.ts +2 -0
- package/dist/application/recovery-inspection.js +27 -0
- package/dist/application/recovery-inspection.js.map +1 -0
- package/dist/application/recovery-inspection.types.d.ts +15 -0
- package/dist/application/recovery-inspection.types.js +2 -0
- package/dist/application/recovery-inspection.types.js.map +1 -0
- package/dist/application/recovery-restorability.d.ts +2 -0
- package/dist/application/recovery-restorability.js +137 -0
- package/dist/application/recovery-restorability.js.map +1 -0
- package/dist/application/recovery-retention-policy.d.ts +2 -0
- package/dist/application/recovery-retention-policy.js +21 -0
- package/dist/application/recovery-retention-policy.js.map +1 -0
- package/dist/application/recovery-retention.constants.d.ts +3 -0
- package/dist/application/recovery-retention.constants.js +2 -0
- package/dist/application/recovery-retention.constants.js.map +1 -0
- package/dist/application/recovery-retention.d.ts +4 -0
- package/dist/application/recovery-retention.js +202 -0
- package/dist/application/recovery-retention.js.map +1 -0
- package/dist/application/recovery-retention.types.d.ts +52 -0
- package/dist/application/recovery-retention.types.js +2 -0
- package/dist/application/recovery-retention.types.js.map +1 -0
- package/dist/application/recovery-verification.constants.d.ts +5 -0
- package/dist/application/recovery-verification.constants.js +10 -0
- package/dist/application/recovery-verification.constants.js.map +1 -0
- package/dist/application/recovery-verification.d.ts +2 -0
- package/dist/application/recovery-verification.js +107 -0
- package/dist/application/recovery-verification.js.map +1 -0
- package/dist/application/recovery-verification.types.d.ts +26 -0
- package/dist/application/recovery-verification.types.js +2 -0
- package/dist/application/recovery-verification.types.js.map +1 -0
- package/dist/application/remote-apply.js +24 -6
- package/dist/application/remote-apply.js.map +1 -1
- package/dist/application/remote-backup.js +6 -2
- package/dist/application/remote-backup.js.map +1 -1
- package/dist/application/remote-download.js +36 -4
- package/dist/application/remote-download.js.map +1 -1
- package/dist/application/remote-validation.js +19 -0
- package/dist/application/remote-validation.js.map +1 -1
- package/dist/application/remote-workspace.constants.d.ts +3 -0
- package/dist/application/remote-workspace.constants.js +2 -0
- package/dist/application/remote-workspace.constants.js.map +1 -0
- package/dist/application/remote-workspace.js +6 -0
- package/dist/application/remote-workspace.js.map +1 -1
- package/dist/application/remote-workspace.types.d.ts +3 -1
- package/dist/application/remote-workspace.types.js.map +1 -1
- package/dist/application/sandbox.js +11 -0
- package/dist/application/sandbox.js.map +1 -1
- package/dist/application/task-usage.d.ts +4 -0
- package/dist/application/task-usage.js +41 -0
- package/dist/application/task-usage.js.map +1 -0
- package/dist/application/task-usage.types.d.ts +5 -0
- package/dist/application/task-usage.types.js +2 -0
- package/dist/application/task-usage.types.js.map +1 -0
- package/dist/application/tasks.js +23 -2
- package/dist/application/tasks.js.map +1 -1
- package/dist/cli/commands.js +4 -0
- package/dist/cli/commands.js.map +1 -1
- package/dist/cli/doctor-command.d.ts +3 -0
- package/dist/cli/doctor-command.js +38 -0
- package/dist/cli/doctor-command.js.map +1 -0
- package/dist/cli/main.constants.d.ts +28 -1
- package/dist/cli/main.constants.js +15 -0
- package/dist/cli/main.constants.js.map +1 -1
- package/dist/cli/recovery-command.d.ts +2 -0
- package/dist/cli/recovery-command.js +69 -0
- package/dist/cli/recovery-command.js.map +1 -0
- package/dist/cli/recovery-prune-command.d.ts +2 -0
- package/dist/cli/recovery-prune-command.js +34 -0
- package/dist/cli/recovery-prune-command.js.map +1 -0
- package/dist/cli/recovery-verify-command.d.ts +2 -0
- package/dist/cli/recovery-verify-command.js +43 -0
- package/dist/cli/recovery-verify-command.js.map +1 -0
- package/dist/domain/ports.d.ts +1 -1
- package/dist/domain/ports.js.map +1 -1
- package/dist/domain/sandbox.types.d.ts +12 -0
- package/dist/domain/sandbox.types.js.map +1 -1
- package/dist/domain/workflow/budget.constants.d.ts +1 -0
- package/dist/domain/workflow/budget.constants.js +7 -0
- package/dist/domain/workflow/budget.constants.js.map +1 -0
- package/dist/domain/workflow/budget.d.ts +9 -0
- package/dist/domain/workflow/budget.js +67 -0
- package/dist/domain/workflow/budget.js.map +1 -0
- package/dist/domain/workflow/budget.types.d.ts +15 -0
- package/dist/domain/workflow/budget.types.js +2 -0
- package/dist/domain/workflow/budget.types.js.map +1 -0
- package/dist/domain/workflow/task-runner.js +8 -1
- package/dist/domain/workflow/task-runner.js.map +1 -1
- package/dist/domain/workflow/workflow-scheduler.js +4 -2
- package/dist/domain/workflow/workflow-scheduler.js.map +1 -1
- package/dist/domain/workflow/workflow-state.js +29 -0
- package/dist/domain/workflow/workflow-state.js.map +1 -1
- package/dist/domain/workflow.d.ts +2 -0
- package/dist/domain/workflow.js +1 -0
- package/dist/domain/workflow.js.map +1 -1
- package/dist/domain/workflow.types.d.ts +10 -1
- package/dist/domain/workflow.types.js.map +1 -1
- package/dist/index.d.ts +12 -3
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/file-manifest.d.ts +6 -0
- package/dist/infrastructure/file-manifest.js +91 -0
- package/dist/infrastructure/file-manifest.js.map +1 -0
- package/dist/infrastructure/git/lock-inspection.constants.d.ts +4 -0
- package/dist/infrastructure/git/lock-inspection.constants.js +5 -0
- package/dist/infrastructure/git/lock-inspection.constants.js.map +1 -0
- package/dist/infrastructure/git/lock-inspection.d.ts +3 -0
- package/dist/infrastructure/git/lock-inspection.js +64 -0
- package/dist/infrastructure/git/lock-inspection.js.map +1 -0
- package/dist/infrastructure/git/lock-inspection.types.d.ts +27 -0
- package/dist/infrastructure/git/lock-inspection.types.js +2 -0
- package/dist/infrastructure/git/lock-inspection.types.js.map +1 -0
- package/dist/infrastructure/git/lock.d.ts +1 -0
- package/dist/infrastructure/git/lock.js +70 -29
- package/dist/infrastructure/git/lock.js.map +1 -1
- package/dist/infrastructure/git/process-identity.d.ts +3 -0
- package/dist/infrastructure/git/process-identity.js +73 -0
- package/dist/infrastructure/git/process-identity.js.map +1 -0
- package/dist/infrastructure/git/process-identity.types.d.ts +10 -0
- package/dist/infrastructure/git/process-identity.types.js +2 -0
- package/dist/infrastructure/git/process-identity.types.js.map +1 -0
- package/dist/infrastructure/git/verification-command.d.ts +1 -0
- package/dist/infrastructure/git/verification-command.js +36 -0
- package/dist/infrastructure/git/verification-command.js.map +1 -0
- package/dist/infrastructure/git/workspace-lease.js +1 -0
- package/dist/infrastructure/git/workspace-lease.js.map +1 -1
- package/dist/infrastructure/git/workspace.js +5 -1
- package/dist/infrastructure/git/workspace.js.map +1 -1
- package/dist/infrastructure/git/worktree-inspection.constants.d.ts +5 -0
- package/dist/infrastructure/git/worktree-inspection.constants.js +16 -0
- package/dist/infrastructure/git/worktree-inspection.constants.js.map +1 -0
- package/dist/infrastructure/git/worktree-inspection.d.ts +3 -0
- package/dist/infrastructure/git/worktree-inspection.js +120 -0
- package/dist/infrastructure/git/worktree-inspection.js.map +1 -0
- package/dist/infrastructure/git/worktree-inspection.types.d.ts +19 -0
- package/dist/infrastructure/git/worktree-inspection.types.js +2 -0
- package/dist/infrastructure/git/worktree-inspection.types.js.map +1 -0
- package/dist/infrastructure/inspection-file.constants.d.ts +1 -0
- package/dist/infrastructure/inspection-file.constants.js +5 -0
- package/dist/infrastructure/inspection-file.constants.js.map +1 -0
- package/dist/infrastructure/inspection-file.d.ts +1 -0
- package/dist/infrastructure/inspection-file.js +43 -0
- package/dist/infrastructure/inspection-file.js.map +1 -0
- package/dist/infrastructure/inspection-hash.constants.d.ts +1 -0
- package/dist/infrastructure/inspection-hash.constants.js +2 -0
- package/dist/infrastructure/inspection-hash.constants.js.map +1 -0
- package/dist/infrastructure/inspection-hash.d.ts +2 -0
- package/dist/infrastructure/inspection-hash.js +62 -0
- package/dist/infrastructure/inspection-hash.js.map +1 -0
- package/dist/infrastructure/inspection-hash.types.d.ts +5 -0
- package/dist/infrastructure/inspection-hash.types.js +2 -0
- package/dist/infrastructure/inspection-hash.types.js.map +1 -0
- package/dist/infrastructure/journal-retention.constants.d.ts +4 -0
- package/dist/infrastructure/journal-retention.constants.js +5 -0
- package/dist/infrastructure/journal-retention.constants.js.map +1 -0
- package/dist/infrastructure/journal-retention.d.ts +2 -0
- package/dist/infrastructure/journal-retention.js +51 -0
- package/dist/infrastructure/journal-retention.js.map +1 -0
- package/dist/infrastructure/journal.js +37 -13
- package/dist/infrastructure/journal.js.map +1 -1
- package/dist/infrastructure/opentelemetry.constants.d.ts +10 -0
- package/dist/infrastructure/opentelemetry.constants.js +11 -0
- package/dist/infrastructure/opentelemetry.constants.js.map +1 -0
- package/dist/infrastructure/opentelemetry.d.ts +3 -0
- package/dist/infrastructure/opentelemetry.js +131 -0
- package/dist/infrastructure/opentelemetry.js.map +1 -0
- package/dist/infrastructure/opentelemetry.types.d.ts +21 -0
- package/dist/infrastructure/opentelemetry.types.js +2 -0
- package/dist/infrastructure/opentelemetry.types.js.map +1 -0
- package/dist/infrastructure/storage-inventory.constants.d.ts +6 -0
- package/dist/infrastructure/storage-inventory.constants.js +11 -0
- package/dist/infrastructure/storage-inventory.constants.js.map +1 -0
- package/dist/infrastructure/storage-inventory.d.ts +2 -0
- package/dist/infrastructure/storage-inventory.js +123 -0
- package/dist/infrastructure/storage-inventory.js.map +1 -0
- package/dist/infrastructure/storage-inventory.types.d.ts +38 -0
- package/dist/infrastructure/storage-inventory.types.js +2 -0
- package/dist/infrastructure/storage-inventory.types.js.map +1 -0
- package/dist/infrastructure/transfer.js +12 -0
- package/dist/infrastructure/transfer.js.map +1 -1
- package/dist/providers/cloud.constants.d.ts +1 -0
- package/dist/providers/cloud.constants.js +1 -0
- package/dist/providers/cloud.constants.js.map +1 -1
- package/dist/providers/container-cache.constants.d.ts +11 -0
- package/dist/providers/container-cache.constants.js +9 -0
- package/dist/providers/container-cache.constants.js.map +1 -0
- package/dist/providers/container-cache.d.ts +4 -0
- package/dist/providers/container-cache.js +48 -0
- package/dist/providers/container-cache.js.map +1 -0
- package/dist/providers/container-cache.types.d.ts +8 -0
- package/dist/providers/container-cache.types.js +2 -0
- package/dist/providers/container-cache.types.js.map +1 -0
- package/dist/providers/container-plan.js +3 -1
- package/dist/providers/container-plan.js.map +1 -1
- package/dist/providers/container.js +31 -1
- package/dist/providers/container.js.map +1 -1
- package/dist/providers/container.types.d.ts +2 -0
- package/dist/providers/container.types.js.map +1 -1
- package/dist/providers/daytona-command.js +7 -4
- package/dist/providers/daytona-command.js.map +1 -1
- package/dist/providers/daytona.js +13 -4
- package/dist/providers/daytona.js.map +1 -1
- package/dist/providers/diagnostic-container.d.ts +4 -0
- package/dist/providers/diagnostic-container.js +15 -0
- package/dist/providers/diagnostic-container.js.map +1 -0
- package/dist/providers/docker.d.ts +1 -0
- package/dist/providers/docker.js.map +1 -1
- package/dist/providers/file-batches.constants.d.ts +10 -0
- package/dist/providers/file-batches.constants.js +57 -0
- package/dist/providers/file-batches.constants.js.map +1 -0
- package/dist/providers/file-batches.d.ts +2 -0
- package/dist/providers/file-batches.js +151 -0
- package/dist/providers/file-batches.js.map +1 -0
- package/dist/providers/podman.d.ts +1 -0
- package/dist/providers/podman.js.map +1 -1
- package/dist/providers/vercel.js +3 -1
- package/dist/providers/vercel.js.map +1 -1
- package/package.json +12 -1
|
@@ -1,36 +1,77 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
-
import { mkdir, open,
|
|
2
|
+
import { mkdir, open, rm } from "node:fs/promises";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { OutpostError } from "../../domain/errors.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
5
|
+
import { localProcessIdentity, observeOwnership } from "./process-identity.js";
|
|
6
|
+
import { readInspectionFile } from "../inspection-file.js";
|
|
7
|
+
import { lockInspectionDefaults } from "./lock-inspection.constants.js";
|
|
8
|
+
export function lockPath(root, key) {
|
|
9
|
+
return join(root, ".outpost", "locks", `${createHash("sha256").update(key).digest("hex").slice(0, 20)}.json`);
|
|
10
|
+
}
|
|
11
|
+
async function readOwner(path) {
|
|
12
|
+
return JSON.parse((await readInspectionFile(path, lockInspectionDefaults.maxBytes)).toString("utf8"));
|
|
13
|
+
}
|
|
14
|
+
async function createLock(path) {
|
|
15
|
+
const file = await open(path, "wx", 0o600);
|
|
16
|
+
const nonce = randomUUID();
|
|
17
|
+
try {
|
|
18
|
+
await file.writeFile(JSON.stringify({
|
|
19
|
+
pid: process.pid,
|
|
20
|
+
nonce,
|
|
21
|
+
identity: await localProcessIdentity(),
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
await file.close();
|
|
26
|
+
}
|
|
27
|
+
return async () => {
|
|
28
|
+
const current = await readOwner(path).catch(() => null);
|
|
29
|
+
if (current &&
|
|
30
|
+
typeof current === "object" &&
|
|
31
|
+
"nonce" in current &&
|
|
32
|
+
current.nonce === nonce)
|
|
31
33
|
await rm(path, { force: true });
|
|
32
|
-
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export async function lock(root, key) {
|
|
37
|
+
await mkdir(join(root, ".outpost", "locks"), { recursive: true });
|
|
38
|
+
const path = lockPath(root, key);
|
|
39
|
+
try {
|
|
40
|
+
return await createLock(path);
|
|
41
|
+
}
|
|
42
|
+
catch (cause) {
|
|
43
|
+
if (!(cause &&
|
|
44
|
+
typeof cause === "object" &&
|
|
45
|
+
"code" in cause &&
|
|
46
|
+
cause.code === "EEXIST"))
|
|
47
|
+
throw cause;
|
|
48
|
+
}
|
|
49
|
+
const conflict = () => new OutpostError("conflict", `Workspace is already in use or ownership is unknown: ${key}`, { lock: path });
|
|
50
|
+
// Serialize stale reclamation so another contender cannot unlink a new owner.
|
|
51
|
+
const releaseGuard = await createLock(`${path}.reclaim`).catch(() => {
|
|
52
|
+
throw conflict();
|
|
53
|
+
});
|
|
54
|
+
try {
|
|
55
|
+
const owner = await readOwner(path).catch(() => null);
|
|
56
|
+
const pid = owner && typeof owner === "object" && "pid" in owner
|
|
57
|
+
? owner.pid
|
|
58
|
+
: undefined;
|
|
59
|
+
const identity = owner && typeof owner === "object" && "identity" in owner
|
|
60
|
+
? owner.identity
|
|
61
|
+
: undefined;
|
|
62
|
+
const ownership = typeof pid === "number" &&
|
|
63
|
+
Number.isSafeInteger(pid) &&
|
|
64
|
+
pid > 0 &&
|
|
65
|
+
pid <= lockInspectionDefaults.maxPid
|
|
66
|
+
? await observeOwnership(pid, identity)
|
|
67
|
+
: undefined;
|
|
68
|
+
if (ownership?.status !== "inactive")
|
|
69
|
+
throw conflict();
|
|
70
|
+
await rm(path, { force: true });
|
|
71
|
+
return await createLock(path);
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
await releaseGuard();
|
|
33
75
|
}
|
|
34
|
-
throw new OutpostError("conflict", "Unable to acquire workspace lock");
|
|
35
76
|
}
|
|
36
77
|
//# sourceMappingURL=lock.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lock.js","sourceRoot":"","sources":["../../../src/infrastructure/git/lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"lock.js","sourceRoot":"","sources":["../../../src/infrastructure/git/l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AAC;IACnB,CAAC,CAAC,CAAC;IACH,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;QACtD,MAAM,GAAG,GACP,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,IAAI,KAAK;YAClD,CAAC,CAAC,KAAK,CAAC,GAAG;YACX,CAAC,CAAC,SAAS,CAAC;QAChB,MAAM,QAAQ,GACZ,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,UAAU,IAAI,KAAK;YACvD,CAAC,CAAC,KAAK,CAAC,QAAQ;YAChB,CAAC,CAAC,SAAS,CAAC;QAChB,MAAM,SAAS,GACb,OAAO,GAAG,KAAK,QAAQ;YACvB,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC;YACzB,GAAG,GAAG,CAAC;YACP,GAAG,IAAI,sBAAsB,CAAC,MAAM;YAClC,CAAC,CAAC,MAAM,gBAAgB,CAAC,GAAG,EAAE,QAAQ,CAAC;YACvC,CAAC,CAAC,SAAS,CAAC;QAChB,IAAI,SAAS,EAAE,MAAM,KAAK,UAAU;YAAE,MAAM,QAAQ,EAAE,CAAC;QACvD,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAChC,OAAO,MAAM,UAAU,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;YAAS,CAAC;QACT,MAAM,YAAY,EAAE,CAAC;IACvB,CAAC;AACH,CAAC","sourcesContent":["import { createHash, randomUUID } from \"node:crypto\";\nimport { mkdir, open, rm } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { OutpostError } from \"../../domain/errors.ts\";\nimport { localProcessIdentity, observeOwnership } from \"./process-identity.ts\";\nimport { readInspectionFile } from \"../inspection-file.ts\";\nimport { lockInspectionDefaults } from \"./lock-inspection.constants.ts\";\n\nexport function lockPath(root: string, key: string): string {\n return join(\n root,\n \".outpost\",\n \"locks\",\n `${createHash(\"sha256\").update(key).digest(\"hex\").slice(0, 20)}.json`,\n );\n}\n\nasync function readOwner(path: string): Promise<unknown> {\n return JSON.parse(\n (await readInspectionFile(path, lockInspectionDefaults.maxBytes)).toString(\n \"utf8\",\n ),\n );\n}\n\nasync function createLock(path: string): Promise<() => Promise<void>> {\n const file = await open(path, \"wx\", 0o600);\n const nonce = randomUUID();\n try {\n await file.writeFile(\n JSON.stringify({\n pid: process.pid,\n nonce,\n identity: await localProcessIdentity(),\n }),\n );\n } finally {\n await file.close();\n }\n return async () => {\n const current = await readOwner(path).catch(() => null);\n if (\n current &&\n typeof current === \"object\" &&\n \"nonce\" in current &&\n current.nonce === nonce\n )\n await rm(path, { force: true });\n };\n}\n\nexport async function lock(\n root: string,\n key: string,\n): Promise<() => Promise<void>> {\n await mkdir(join(root, \".outpost\", \"locks\"), { recursive: true });\n const path = lockPath(root, key);\n try {\n return await createLock(path);\n } catch (cause) {\n if (!(\n cause &&\n typeof cause === \"object\" &&\n \"code\" in cause &&\n cause.code === \"EEXIST\"\n ))\n throw cause;\n }\n const conflict = () =>\n new OutpostError(\n \"conflict\",\n `Workspace is already in use or ownership is unknown: ${key}`,\n { lock: path },\n );\n // Serialize stale reclamation so another contender cannot unlink a new owner.\n const releaseGuard = await createLock(`${path}.reclaim`).catch(() => {\n throw conflict();\n });\n try {\n const owner = await readOwner(path).catch(() => null);\n const pid =\n owner && typeof owner === \"object\" && \"pid\" in owner\n ? owner.pid\n : undefined;\n const identity =\n owner && typeof owner === \"object\" && \"identity\" in owner\n ? owner.identity\n : undefined;\n const ownership =\n typeof pid === \"number\" &&\n Number.isSafeInteger(pid) &&\n pid > 0 &&\n pid <= lockInspectionDefaults.maxPid\n ? await observeOwnership(pid, identity)\n : undefined;\n if (ownership?.status !== \"inactive\") throw conflict();\n await rm(path, { force: true });\n return await createLock(path);\n } finally {\n await releaseGuard();\n }\n}\n"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { LocalProcessIdentity, LockOwnership } from "./process-identity.types.ts";
|
|
2
|
+
export declare function localProcessIdentity(pid?: number): Promise<LocalProcessIdentity | undefined>;
|
|
3
|
+
export declare function observeOwnership(pid: number, identity: unknown): Promise<LockOwnership>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { readFile, readlink } from "node:fs/promises";
|
|
3
|
+
export async function localProcessIdentity(pid = process.pid) {
|
|
4
|
+
if (process.platform !== "linux")
|
|
5
|
+
return undefined;
|
|
6
|
+
try {
|
|
7
|
+
const [machine, boot, namespace, stat] = await Promise.all([
|
|
8
|
+
readFile("/etc/machine-id", "utf8"),
|
|
9
|
+
readFile("/proc/sys/kernel/random/boot_id", "utf8"),
|
|
10
|
+
readlink(`/proc/${pid}/ns/pid`),
|
|
11
|
+
readFile(`/proc/${pid}/stat`, "utf8"),
|
|
12
|
+
]);
|
|
13
|
+
const started = stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19];
|
|
14
|
+
if (!machine.trim() || !boot.trim() || !started || !/^\d+$/.test(started))
|
|
15
|
+
return undefined;
|
|
16
|
+
return {
|
|
17
|
+
host: createHash("sha256").update(machine.trim()).digest("hex"),
|
|
18
|
+
boot: boot.trim(),
|
|
19
|
+
namespace,
|
|
20
|
+
started,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function validIdentity(value) {
|
|
28
|
+
if (!value || typeof value !== "object")
|
|
29
|
+
return false;
|
|
30
|
+
return ("host" in value &&
|
|
31
|
+
typeof value.host === "string" &&
|
|
32
|
+
value.host.length > 0 &&
|
|
33
|
+
"boot" in value &&
|
|
34
|
+
typeof value.boot === "string" &&
|
|
35
|
+
value.boot.length > 0 &&
|
|
36
|
+
"namespace" in value &&
|
|
37
|
+
typeof value.namespace === "string" &&
|
|
38
|
+
value.namespace.length > 0 &&
|
|
39
|
+
"started" in value &&
|
|
40
|
+
typeof value.started === "string" &&
|
|
41
|
+
/^\d+$/.test(value.started));
|
|
42
|
+
}
|
|
43
|
+
export async function observeOwnership(pid, identity) {
|
|
44
|
+
if (!validIdentity(identity))
|
|
45
|
+
return { status: "unknown", reason: "LEGACY_OR_INVALID_IDENTITY" };
|
|
46
|
+
const local = await localProcessIdentity();
|
|
47
|
+
if (!local)
|
|
48
|
+
return { status: "unknown", reason: "LOCAL_IDENTITY_UNAVAILABLE" };
|
|
49
|
+
if (identity.host !== local.host)
|
|
50
|
+
return { status: "unknown", reason: "OTHER_HOST" };
|
|
51
|
+
if (identity.boot !== local.boot)
|
|
52
|
+
return { status: "unknown", reason: "OTHER_BOOT" };
|
|
53
|
+
if (identity.namespace !== local.namespace)
|
|
54
|
+
return { status: "unknown", reason: "OTHER_PID_NAMESPACE" };
|
|
55
|
+
try {
|
|
56
|
+
process.kill(pid, 0);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (error &&
|
|
60
|
+
typeof error === "object" &&
|
|
61
|
+
"code" in error &&
|
|
62
|
+
error.code === "ESRCH")
|
|
63
|
+
return { status: "inactive", reason: "PROCESS_EXITED" };
|
|
64
|
+
return { status: "unknown", reason: "PROCESS_INACCESSIBLE" };
|
|
65
|
+
}
|
|
66
|
+
const current = await localProcessIdentity(pid);
|
|
67
|
+
if (!current)
|
|
68
|
+
return { status: "unknown", reason: "PROCESS_IDENTITY_UNAVAILABLE" };
|
|
69
|
+
if (current.started !== identity.started)
|
|
70
|
+
return { status: "unknown", reason: "PID_REUSED" };
|
|
71
|
+
return { status: "active", reason: "LOCAL_IDENTITY_MATCH" };
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=process-identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-identity.js","sourceRoot":"","sources":["../../../src/infrastructure/git/process-identity.ts"],"names":[],"mappings":"AAAA,OAA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M,EAAE,SAAS,EAAE,MAAM,EAAE,qBAAqB,EAAE,CAAC;IAC9D,IAAI,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACvB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IACE,KAAK;YACL,OAAO,KAAK,KAAK,QAAQ;YACzB,MAAM,IAAI,KAAK;YACf,KAAK,CAAC,IAAI,KAAK,OAAO;YAEtB,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC;QAC1D,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,sBAAsB,EAAE,CAAC;IAC/D,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,oBAAoB,CAAC,GAAG,CAAC,CAAC;IAChD,IAAI,CAAC,OAAO;QACV,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,8BAA8B,EAAE,CAAC;IACvE,IAAI,OAAO,CAAC,OAAO,KAAK,QAAQ,CAAC,OAAO;QACtC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;IACrD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,sBAAsB,EAAE,CAAC;AAC9D,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { readFile, readlink } from \"node:fs/promises\";\nimport type {\n LocalProcessIdentity,\n LockOwnership,\n} from \"./process-identity.types.ts\";\n\nexport async function localProcessIdentity(\n pid = process.pid,\n): Promise<LocalProcessIdentity | undefined> {\n if (process.platform !== \"linux\") return undefined;\n try {\n const [machine, boot, namespace, stat] = await Promise.all([\n readFile(\"/etc/machine-id\", \"utf8\"),\n readFile(\"/proc/sys/kernel/random/boot_id\", \"utf8\"),\n readlink(`/proc/${pid}/ns/pid`),\n readFile(`/proc/${pid}/stat`, \"utf8\"),\n ]);\n const started = stat.slice(stat.lastIndexOf(\")\") + 2).split(\" \")[19];\n if (!machine.trim() || !boot.trim() || !started || !/^\\d+$/.test(started))\n return undefined;\n return {\n host: createHash(\"sha256\").update(machine.trim()).digest(\"hex\"),\n boot: boot.trim(),\n namespace,\n started,\n };\n } catch {\n return undefined;\n }\n}\n\nfunction validIdentity(value: unknown): value is LocalProcessIdentity {\n if (!value || typeof value !== \"object\") return false;\n return (\n \"host\" in value &&\n typeof value.host === \"string\" &&\n value.host.length > 0 &&\n \"boot\" in value &&\n typeof value.boot === \"string\" &&\n value.boot.length > 0 &&\n \"namespace\" in value &&\n typeof value.namespace === \"string\" &&\n value.namespace.length > 0 &&\n \"started\" in value &&\n typeof value.started === \"string\" &&\n /^\\d+$/.test(value.started)\n );\n}\n\nexport async function observeOwnership(\n pid: number,\n identity: unknown,\n): Promise<LockOwnership> {\n if (!validIdentity(identity))\n return { status: \"unknown\", reason: \"LEGACY_OR_INVALID_IDENTITY\" };\n const local = await localProcessIdentity();\n if (!local)\n return { status: \"unknown\", reason: \"LOCAL_IDENTITY_UNAVAILABLE\" };\n if (identity.host !== local.host)\n return { status: \"unknown\", reason: \"OTHER_HOST\" };\n if (identity.boot !== local.boot)\n return { status: \"unknown\", reason: \"OTHER_BOOT\" };\n if (identity.namespace !== local.namespace)\n return { status: \"unknown\", reason: \"OTHER_PID_NAMESPACE\" };\n try {\n process.kill(pid, 0);\n } catch (error) {\n if (\n error &&\n typeof error === \"object\" &&\n \"code\" in error &&\n error.code === \"ESRCH\"\n )\n return { status: \"inactive\", reason: \"PROCESS_EXITED\" };\n return { status: \"unknown\", reason: \"PROCESS_INACCESSIBLE\" };\n }\n const current = await localProcessIdentity(pid);\n if (!current)\n return { status: \"unknown\", reason: \"PROCESS_IDENTITY_UNAVAILABLE\" };\n if (current.started !== identity.started)\n return { status: \"unknown\", reason: \"PID_REUSED\" };\n return { status: \"active\", reason: \"LOCAL_IDENTITY_MATCH\" };\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface LocalProcessIdentity {
|
|
2
|
+
readonly host: string;
|
|
3
|
+
readonly boot: string;
|
|
4
|
+
readonly namespace: string;
|
|
5
|
+
readonly started: string;
|
|
6
|
+
}
|
|
7
|
+
export interface LockOwnership {
|
|
8
|
+
readonly status: "active" | "inactive" | "unknown";
|
|
9
|
+
readonly reason: string;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-identity.types.js","sourceRoot":"","sources":["../../../src/infrastructure/git/process-identity.types.ts"],"names":[],"mappings":"","sourcesContent":["export interface LocalProcessIdentity {\n readonly host: string;\n readonly boot: string;\n readonly namespace: string;\n readonly started: string;\n}\nexport interface LockOwnership {\n readonly status: \"active\" | \"inactive\" | \"unknown\";\n readonly reason: string;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function verificationGit(directory: string, args: readonly string[]): Promise<string>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
import { gitDefaults } from "./git.constants.js";
|
|
4
|
+
export async function verificationGit(directory, args) {
|
|
5
|
+
const environment = Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.toUpperCase().startsWith("GIT_")));
|
|
6
|
+
const result = await promisify(execFile)("git", [
|
|
7
|
+
"-c",
|
|
8
|
+
`core.hooksPath=${process.platform === "win32" ? "NUL" : "/dev/null"}`,
|
|
9
|
+
"-c",
|
|
10
|
+
"core.fsmonitor=false",
|
|
11
|
+
"-c",
|
|
12
|
+
"maintenance.auto=false",
|
|
13
|
+
"-c",
|
|
14
|
+
"gc.auto=0",
|
|
15
|
+
...args,
|
|
16
|
+
], {
|
|
17
|
+
cwd: directory,
|
|
18
|
+
env: {
|
|
19
|
+
...environment,
|
|
20
|
+
GIT_CONFIG_NOSYSTEM: "1",
|
|
21
|
+
GIT_CONFIG_GLOBAL: process.platform === "win32" ? "NUL" : "/dev/null",
|
|
22
|
+
GIT_ATTR_NOSYSTEM: "1",
|
|
23
|
+
GIT_NO_LAZY_FETCH: "1",
|
|
24
|
+
GIT_ALLOW_PROTOCOL: "file",
|
|
25
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
26
|
+
GIT_OPTIONAL_LOCKS: "0",
|
|
27
|
+
LC_ALL: "C",
|
|
28
|
+
},
|
|
29
|
+
timeout: gitDefaults.deadlineMs,
|
|
30
|
+
maxBuffer: gitDefaults.retainBytes,
|
|
31
|
+
encoding: "utf8",
|
|
32
|
+
windowsHide: true,
|
|
33
|
+
});
|
|
34
|
+
return result.stdout;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=verification-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verification-command.js","sourceRoot":"","sources":["../../../src/infrastructure/git/verification-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,SAAiB,EACjB,IAAuB;IAEvB,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CACpC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAChC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CACjD,CACF,CAAC;IACF,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,CACtC,KAAK,EACL;QACE,IAAI;QACJ,kBAAkB,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,EAAE;QACtE,IAAI;QACJ,sBAAsB;QACtB,IAAI;QACJ,wBAAwB;QACxB,IAAI;QACJ,WAAW;QACX,GAAG,IAAI;KACR,EACD;QACE,GAAG,EAAE,SAAS;QACd,GAAG,EAAE;YACH,GAAG,WAAW;YACd,mBAAmB,EAAE,GAAG;YACxB,iBAAiB,EAAE,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW;YACrE,iBAAiB,EAAE,GAAG;YACtB,iBAAiB,EAAE,GAAG;YACtB,kBAAkB,EAAE,MAAM;YAC1B,mBAAmB,EAAE,GAAG;YACxB,kBAAkB,EAAE,GAAG;YACvB,MAAM,EAAE,GAAG;SACZ;QACD,OAAO,EAAE,WAAW,CAAC,UAAU;QAC/B,SAAS,EAAE,WAAW,CAAC,WAAW;QAClC,QAAQ,EAAE,MAAM;QAChB,WAAW,EAAE,IAAI;KAClB,CACF,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,CAAC","sourcesContent":["import { execFile } from \"node:child_process\";\nimport { promisify } from \"node:util\";\nimport { gitDefaults } from \"./git.constants.ts\";\n\nexport async function verificationGit(\n directory: string,\n args: readonly string[],\n): Promise<string> {\n const environment = Object.fromEntries(\n Object.entries(process.env).filter(\n ([key]) => !key.toUpperCase().startsWith(\"GIT_\"),\n ),\n );\n const result = await promisify(execFile)(\n \"git\",\n [\n \"-c\",\n `core.hooksPath=${process.platform === \"win32\" ? \"NUL\" : \"/dev/null\"}`,\n \"-c\",\n \"core.fsmonitor=false\",\n \"-c\",\n \"maintenance.auto=false\",\n \"-c\",\n \"gc.auto=0\",\n ...args,\n ],\n {\n cwd: directory,\n env: {\n ...environment,\n GIT_CONFIG_NOSYSTEM: \"1\",\n GIT_CONFIG_GLOBAL: process.platform === \"win32\" ? \"NUL\" : \"/dev/null\",\n GIT_ATTR_NOSYSTEM: \"1\",\n GIT_NO_LAZY_FETCH: \"1\",\n GIT_ALLOW_PROTOCOL: \"file\",\n GIT_TERMINAL_PROMPT: \"0\",\n GIT_OPTIONAL_LOCKS: \"0\",\n LC_ALL: \"C\",\n },\n timeout: gitDefaults.deadlineMs,\n maxBuffer: gitDefaults.retainBytes,\n encoding: \"utf8\",\n windowsHide: true,\n },\n );\n return result.stdout;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace-lease.js","sourceRoot":"","sources":["../../../src/infrastructure/git/workspace-lease.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAKtD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAMjC,MAAM,UAAU,cAAc,CAC5B,MAAuB,EACvB,OAAgC,EAChC,MAA2B;IAE3B,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAC9E,IAAI,QAAuC,CAAC;IAC5C,OAAO;QACL,GAAG,MAAM;QACT,KAAK,CAAC,SAAS;YACb,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW;gBAAE,OAAO;YACxC,MAAM,OAAO,GAAG,CACd,MAAM,GAAG,CAAC,UAAU,EAAE,CAAC,cAAc,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,CAC3D,CAAC,IAAI,EAAE,CAAC;YACT,IAAI,OAAO,KAAK,UAAU;gBACxB,MAAM,IAAI,YAAY,CACpB,UAAU,EACV,oCAAoC,EACpC,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,CACtD,CAAC;YACJ,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,SAAS,UAAU,EAAE,CAAC,CAAC;YACnE,IAAI,CAAC;gBACH,MAAM,GAAG,CACP,UAAU,EACV,CAA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,CAAC,EAAE,CAAC;YACL,OAAO,QAAQ,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { join } from \"node:path\";\nimport { OutpostError } from \"../../domain/errors.ts\";\nimport type {\n Disposal,\n WorkspaceRecord,\n} from \"../../domain/workspace.types.ts\";\nimport { inside } from \"../files.ts\";\nimport { git } from \"./command.ts\";\nimport { lock } from \"./lock.ts\";\nimport type {\n AcquireWorkspaceOptions,\n WorkspaceLease,\n} from \"./workspace.types.ts\";\n\nexport function workspaceLease(\n record: WorkspaceRecord,\n options: AcquireWorkspaceOptions,\n unlock: () => Promise<void>,\n): WorkspaceLease {\n const { policy, repository, baseBranch, branch, directory: workdir } = record;\n let disposal: Promise<Disposal> | undefined;\n return {\n ...record,\n async integrate() {\n if (policy.mode !== \"integrate\") return;\n const current = (\n await git(repository, [\"symbolic-ref\", \"--short\", \"HEAD\"])\n ).trim();\n if (current !== baseBranch)\n throw new OutpostError(\n \"conflict\",\n \"Host branch changed during the job\",\n { expected: baseBranch, current, directory: workdir },\n );\n const releaseMerge = await lock(repository, `merge:${baseBranch}`);\n try {\n await git(\n repository,\n [\"merge\", \"--no-edit\", branch],\n options.limits?.mergeMs,\n );\n } catch (cause) {\n throw new OutpostError(\n \"conflict\",\n \"Automatic integration failed; workspace retained\",\n { directory: workdir, branch },\n cause,\n );\n } finally {\n await releaseMerge();\n }\n },\n dispose(preserve = false) {\n if (disposal) return disposal;\n disposal = (async () => {\n try {\n if (policy.mode === \"current\") return {};\n if (preserve) return { retainedDirectory: workdir };\n const attached = await git(workdir, [\n \"symbolic-ref\",\n \"--quiet\",\n \"HEAD\",\n ]).catch(() => \"\");\n if (!attached.trim()) return { retainedDirectory: workdir };\n const dirty = await git(workdir, [\n \"status\",\n \"--porcelain\",\n \"--untracked-files=normal\",\n \"--ignored\",\n ]);\n if (dirty.trim()) return { retainedDirectory: workdir };\n if (!inside(join(repository, \".outpost\", \"workspaces\"), workdir))\n throw new OutpostError(\n \"workspace\",\n \"Refusing to remove an unmanaged workspace\",\n );\n await git(repository, [\"worktree\", \"remove\", workdir]);\n if (policy.mode === \"integrate\")\n await git(repository, [\"branch\", \"-d\", branch]).catch(\n () => undefined,\n );\n return {};\n } finally {\n await unlock();\n }\n })();\n return disposal;\n },\n };\n}\n"]}
|
|
@@ -59,7 +59,11 @@ export async function acquireWorkspace(options) {
|
|
|
59
59
|
}
|
|
60
60
|
catch (error) {
|
|
61
61
|
if (created) {
|
|
62
|
-
const clean = await git(workdir, [
|
|
62
|
+
const clean = await git(workdir, [
|
|
63
|
+
"status",
|
|
64
|
+
"--porcelain",
|
|
65
|
+
"--ignored",
|
|
66
|
+
]).then((output) => !output.trim(), () => false);
|
|
63
67
|
if (clean && inside(join(repository, ".outpost", "workspaces"), workdir))
|
|
64
68
|
await git(repository, ["worktree", "remove", workdir]).catch(() => undefined);
|
|
65
69
|
else
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace.js","sourceRoot":"","sources":["../../../src/infrastructure/git/workspace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAMtD,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAAgC;IAEhC,MAAM,UAAU,GAAG,MAAM,iBAAiB,CAAC,OAAO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AO,EAAE,CAAC,WAAW,EAAE,oBAAoB,CAAC,CAAC,CACxD,CAAC,IAAI,EAAE,CAAC;QACT,MAAM,MAAM,GAAG,CACb,MAAM,GAAG,CAAC,OAAO,EAAE;YACjB,WAAW;YACX,wBAAwB;YACxB,kBAAkB;SACnB,CAAC,CACH,CAAC,IAAI,EAAE,CAAC;QACT,OAAO,cAAc,CACnB;YACE,UAAU;YACV,SAAS,EAAE,OAAO;YAClB,MAAM;YACN,UAAU;YACV,QAAQ;YACR,MAAM;YACN,cAAc,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;SAC/C,EACD,OAAO,EACP,MAAM,CACP,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,OAAO,EAAE;gBAC/B,QAAQ;gBACR,aAAa;gBACb,WAAW;aACZ,CAAC,CAAC,IAAI,CACL,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,EAC1B,GAAG,EAAE,CAAC,KAAK,CACZ,CAAC;YACF,IAAI,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,EAAE,YAAY,CAAC,EAAE,OAAO,CAAC;gBACtE,MAAM,GAAG,CAAC,UAAU,EAAE,CAAC,UAAU,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAC1D,GAAG,EAAE,CAAC,SAAS,CAChB,CAAC;;gBACC,cAAc,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;QAC7D,CAAC;QACD,MAAM,MAAM,EAAE,CAAC;QACf,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { join } from \"node:path\";\nimport { OutpostError, recordRecovery } from \"../../domain/errors.ts\";\nimport { copySelected, inside } from \"../files.ts\";\nimport { git } from \"./command.ts\";\nimport { lock } from \"./lock.ts\";\nimport { managedWorktree } from \"./managed-worktree.ts\";\nimport { prepareRepository } from \"./repository.ts\";\nimport { workspaceLease } from \"./workspace-lease.ts\";\nimport type {\n AcquireWorkspaceOptions,\n WorkspaceLease,\n} from \"./workspace.types.ts\";\n\nexport async function acquireWorkspace(\n options: AcquireWorkspaceOptions,\n): Promise<WorkspaceLease> {\n const repository = await prepareRepository(options);\n const policy = options.branch ?? { mode: \"current\" };\n const baseBranch = (\n await git(repository, [\"symbolic-ref\", \"--quiet\", \"--short\", \"HEAD\"]).catch(\n () => \"\",\n )\n ).trim();\n if (policy.mode === \"integrate\" && !baseBranch)\n throw new OutpostError(\n \"workspace\",\n \"Automatic integration requires an attached host branch\",\n );\n if (policy.mode === \"current\" && options.copies?.length)\n throw new OutpostError(\n \"configuration\",\n \"Copied inputs require a separate workspace\",\n );\n const branch =\n policy.mode === \"current\"\n ? baseBranch || \"HEAD\"\n : policy.mode === \"named\"\n ? policy.name\n : `outpost/${\n options.label\n ? options.label\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"-\")\n .slice(0, 48) + \"-\"\n : \"job-\"\n }${randomUUID()}`;\n if (policy.mode !== \"current\")\n await git(repository, [\"check-ref-format\", \"--branch\", branch]);\n const unlock = await lock(\n repository,\n policy.mode === \"current\" ? repository : branch,\n );\n let workdir = repository;\n let created = false;\n try {\n if (policy.mode !== \"current\") {\n ({ workdir, created } = await managedWorktree({\n repository,\n policy,\n branch,\n options,\n }));\n }\n await copySelected(\n repository,\n workdir,\n options.copies ?? [],\n options.limits?.copyMs,\n );\n const baseline = (await git(workdir, [\"rev-parse\", \"HEAD\"])).trim();\n const gitDir = (\n await git(workdir, [\"rev-parse\", \"--absolute-git-dir\"])\n ).trim();\n const common = (\n await git(workdir, [\n \"rev-parse\",\n \"--path-format=absolute\",\n \"--git-common-dir\",\n ])\n ).trim();\n return workspaceLease(\n {\n repository,\n directory: workdir,\n branch,\n baseBranch,\n baseline,\n policy,\n gitDirectories: [...new Set([gitDir, common])],\n },\n options,\n unlock,\n );\n } catch (error) {\n if (created) {\n const clean = await git(workdir, [\n \"status\",\n \"--porcelain\",\n \"--ignored\",\n ]).then(\n (output) => !output.trim(),\n () => false,\n );\n if (clean && inside(join(repository, \".outpost\", \"workspaces\"), workdir))\n await git(repository, [\"worktree\", \"remove\", workdir]).catch(\n () => undefined,\n );\n else recordRecovery(error, { branch, directory: workdir });\n }\n await unlock();\n throw error;\n }\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const worktreeInspectionDefaults: {
|
|
2
|
+
readonly deadlineMs: 10000;
|
|
3
|
+
readonly retainBytes: 1048576;
|
|
4
|
+
};
|
|
5
|
+
export declare const worktreeInspectionArguments: readonly ["--no-optional-locks", "-c", "core.fsmonitor=false", "-c", string, "-c", "maintenance.auto=false", "-c", "gc.auto=0"];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const worktreeInspectionDefaults = {
|
|
2
|
+
deadlineMs: 10_000,
|
|
3
|
+
retainBytes: 1_048_576,
|
|
4
|
+
};
|
|
5
|
+
export const worktreeInspectionArguments = [
|
|
6
|
+
"--no-optional-locks",
|
|
7
|
+
"-c",
|
|
8
|
+
"core.fsmonitor=false",
|
|
9
|
+
"-c",
|
|
10
|
+
"core.hooksPath=" + (process.platform === "win32" ? "NUL" : "/dev/null"),
|
|
11
|
+
"-c",
|
|
12
|
+
"maintenance.auto=false",
|
|
13
|
+
"-c",
|
|
14
|
+
"gc.auto=0",
|
|
15
|
+
];
|
|
16
|
+
//# sourceMappingURL=worktree-inspection.constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worktree-inspection.constants.js","sourceRoot":"","sources":["../../../src/infrastructure/git/worktree-inspection.constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,UAAU,EAAE,MAAM;IAClB,WAAW,EAAE,SAAS;CACd,CAAC;AAEX,MAAM,CAAC,MAAM,2BAA2B,GAAG;IACzC,qBAAqB;IACrB,IAAI;IACJ,sBAAsB;IACtB,IAAI;IACJ,iBAAiB,GAAG,CAAC,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC;IACxE,IAAI;IACJ,wBAAwB;IACxB,IAAI;IACJ,WAAW;CACH,CAAC","sourcesContent":["export const worktreeInspectionDefaults = {\n deadlineMs: 10_000,\n retainBytes: 1_048_576,\n} as const;\n\nexport const worktreeInspectionArguments = [\n \"--no-optional-locks\",\n \"-c\",\n \"core.fsmonitor=false\",\n \"-c\",\n \"core.hooksPath=\" + (process.platform === \"win32\" ? \"NUL\" : \"/dev/null\"),\n \"-c\",\n \"maintenance.auto=false\",\n \"-c\",\n \"gc.auto=0\",\n] as const;\n"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { StorageEntry } from "../storage-inventory.types.ts";
|
|
2
|
+
import type { WorkspaceGitInspection } from "./worktree-inspection.types.ts";
|
|
3
|
+
export declare function inspectWorktreeGit(repository: string, entries: readonly StorageEntry[]): Promise<WorkspaceGitInspection>;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { lstat, realpath } from "node:fs/promises";
|
|
2
|
+
import { resolve, join } from "node:path";
|
|
3
|
+
import { OutpostError } from "../../domain/errors.js";
|
|
4
|
+
import { requireSuccess } from "../process.js";
|
|
5
|
+
import { worktreeInspectionArguments, worktreeInspectionDefaults, } from "./worktree-inspection.constants.js";
|
|
6
|
+
async function inspectGit(path, args) {
|
|
7
|
+
let length = 0;
|
|
8
|
+
const result = await requireSuccess({
|
|
9
|
+
executable: "git",
|
|
10
|
+
arguments: [...worktreeInspectionArguments, ...args],
|
|
11
|
+
directory: path,
|
|
12
|
+
variables: { LC_ALL: "C", GIT_TERMINAL_PROMPT: "0" },
|
|
13
|
+
deadlineMs: worktreeInspectionDefaults.deadlineMs,
|
|
14
|
+
retain: worktreeInspectionDefaults.retainBytes,
|
|
15
|
+
observe(channel, text) {
|
|
16
|
+
if (channel !== "stdout")
|
|
17
|
+
return;
|
|
18
|
+
length += Buffer.byteLength(text);
|
|
19
|
+
if (length > worktreeInspectionDefaults.retainBytes)
|
|
20
|
+
throw new OutpostError("workspace", "Git inspection output limit exceeded");
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
return result.stdout;
|
|
24
|
+
}
|
|
25
|
+
async function inspectEntry(entry, records, commonDirectory) {
|
|
26
|
+
if (entry.kind !== "directory")
|
|
27
|
+
return { state: "skipped", reason: "NOT_DIRECTORY" };
|
|
28
|
+
const fields = records.find((record) => {
|
|
29
|
+
const path = record
|
|
30
|
+
.find((field) => field.startsWith("worktree "))
|
|
31
|
+
?.slice(9);
|
|
32
|
+
return path !== undefined && resolve(path) === resolve(entry.path);
|
|
33
|
+
});
|
|
34
|
+
if (!fields)
|
|
35
|
+
return { state: "unregistered" };
|
|
36
|
+
const head = fields.find((field) => field.startsWith("HEAD "))?.slice(5);
|
|
37
|
+
if (!head)
|
|
38
|
+
return { state: "unavailable", reason: "INVALID_REGISTRATION" };
|
|
39
|
+
// A listed worktree may have been replaced since registration or inventory.
|
|
40
|
+
if (!(await lstat(entry.path)).isDirectory() ||
|
|
41
|
+
(await realpath(entry.path)) !== resolve(entry.path))
|
|
42
|
+
return { state: "unavailable", reason: "WORKSPACE_CHANGED" };
|
|
43
|
+
const marker = await lstat(join(entry.path, ".git"));
|
|
44
|
+
if (!marker.isFile())
|
|
45
|
+
return { state: "unavailable", reason: "INVALID_GIT_MARKER" };
|
|
46
|
+
const top = (await inspectGit(entry.path, ["rev-parse", "--show-toplevel"])).trim();
|
|
47
|
+
if (resolve(top) !== resolve(entry.path))
|
|
48
|
+
return { state: "unavailable", reason: "WORKSPACE_CHANGED" };
|
|
49
|
+
const common = (await inspectGit(entry.path, [
|
|
50
|
+
"rev-parse",
|
|
51
|
+
"--path-format=absolute",
|
|
52
|
+
"--git-common-dir",
|
|
53
|
+
])).trim();
|
|
54
|
+
if ((await realpath(common)) !== commonDirectory)
|
|
55
|
+
return { state: "unavailable", reason: "REGISTRATION_MISMATCH" };
|
|
56
|
+
const status = await inspectGit(entry.path, [
|
|
57
|
+
"status",
|
|
58
|
+
"--porcelain=v1",
|
|
59
|
+
"-z",
|
|
60
|
+
"--untracked-files=normal",
|
|
61
|
+
"--ignore-submodules=none",
|
|
62
|
+
]);
|
|
63
|
+
return {
|
|
64
|
+
state: "registered",
|
|
65
|
+
head,
|
|
66
|
+
branch: fields
|
|
67
|
+
.find((field) => field.startsWith("branch refs/heads/"))
|
|
68
|
+
?.slice(18) ?? null,
|
|
69
|
+
dirty: status.length > 0,
|
|
70
|
+
locked: fields.some((field) => field === "locked" || field.startsWith("locked ")),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export async function inspectWorktreeGit(repository, entries) {
|
|
74
|
+
const workspaces = [];
|
|
75
|
+
const issues = [];
|
|
76
|
+
if (!entries.length)
|
|
77
|
+
return { complete: true, workspaces, issues };
|
|
78
|
+
let records;
|
|
79
|
+
let commonDirectory;
|
|
80
|
+
try {
|
|
81
|
+
commonDirectory = await realpath((await inspectGit(repository, [
|
|
82
|
+
"rev-parse",
|
|
83
|
+
"--path-format=absolute",
|
|
84
|
+
"--git-common-dir",
|
|
85
|
+
])).trim());
|
|
86
|
+
const list = await inspectGit(repository, [
|
|
87
|
+
"worktree",
|
|
88
|
+
"list",
|
|
89
|
+
"--porcelain",
|
|
90
|
+
"-z",
|
|
91
|
+
]);
|
|
92
|
+
records = list
|
|
93
|
+
.split("\0\0")
|
|
94
|
+
.filter(Boolean)
|
|
95
|
+
.map((record) => record.split("\0"));
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return {
|
|
99
|
+
complete: false,
|
|
100
|
+
workspaces: entries.map(({ name, path }) => ({
|
|
101
|
+
name,
|
|
102
|
+
path,
|
|
103
|
+
state: "unavailable",
|
|
104
|
+
reason: "GIT_LIST_FAILED",
|
|
105
|
+
})),
|
|
106
|
+
issues: [{ path: repository, code: "GIT_LIST_FAILED" }],
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
for (const entry of entries) {
|
|
110
|
+
const state = await inspectEntry(entry, records, commonDirectory).catch(() => ({
|
|
111
|
+
state: "unavailable",
|
|
112
|
+
reason: "GIT_INSPECTION_FAILED",
|
|
113
|
+
}));
|
|
114
|
+
workspaces.push({ name: entry.name, path: entry.path, ...state });
|
|
115
|
+
if (state.state === "unavailable")
|
|
116
|
+
issues.push({ path: entry.path, code: state.reason });
|
|
117
|
+
}
|
|
118
|
+
return { complete: issues.length === 0, workspaces, issues };
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=worktree-inspection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worktree-inspection.js","sourceRoot":"","sources":["../../../src/infrastructure/git/worktree-inspection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,EACL,2BAA2B,EAC3B,0BAA0B,GAC3B,MAAM,oCAAoC,CAAC;AAO5C,KAAK,UAAU,UAAU,CACvB,IAAY,EACZ,IAAuB;IAEvB,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC;QAClC,UAAU,EAAE,KAAK;QACjB,SAAS,EAAE,CAAC,GAAG,2BAA2B,EAAE,GAAG,IAAI,CAAC;QACpD,SAAS,EAAE,IAAI;QACf,SAAS,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,m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CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IACzC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO;YACL,QAAQ,EAAE,KAAK;YACf,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;gBAC3C,IAAI;gBACJ,IAAI;gBACJ,KAAK,EAAE,aAAa;gBACpB,MAAM,EAAE,iBAAiB;aAC1B,CAAC,CAAC;YACH,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC;SACxD,CAAC;IACJ,CAAC;IACD,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,MAAM,KAAK,GAAG,MAAM,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC,KAAK,CACrE,GAAsB,EAAE,CAAC,CAAC;YACxB,KAAK,EAAE,aAAa;YACpB,MAAM,EAAE,uBAAuB;SAChC,CAAC,CACH,CAAC;QACF,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;QAClE,IAAI,KAAK,CAAC,KAAK,KAAK,aAAa;YAC/B,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1D,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;AAC/D,CAAC","sourcesContent":["import { lstat, realpath } from \"node:fs/promises\";\nimport { resolve, join } from \"node:path\";\nimport { OutpostError } from \"../../domain/errors.ts\";\nimport { requireSuccess } from \"../process.ts\";\nimport type { StorageEntry, StorageIssue } from \"../storage-inventory.types.ts\";\nimport {\n worktreeInspectionArguments,\n worktreeInspectionDefaults,\n} from \"./worktree-inspection.constants.ts\";\nimport type {\n WorkspaceGitEntry,\n WorkspaceGitInspection,\n WorkspaceGitState,\n} from \"./worktree-inspection.types.ts\";\n\nasync function inspectGit(\n path: string,\n args: readonly string[],\n): Promise<string> {\n let length = 0;\n const result = await requireSuccess({\n executable: \"git\",\n arguments: [...worktreeInspectionArguments, ...args],\n directory: path,\n variables: { LC_ALL: \"C\", GIT_TERMINAL_PROMPT: \"0\" },\n deadlineMs: worktreeInspectionDefaults.deadlineMs,\n retain: worktreeInspectionDefaults.retainBytes,\n observe(channel, text) {\n if (channel !== \"stdout\") return;\n length += Buffer.byteLength(text);\n if (length > worktreeInspectionDefaults.retainBytes)\n throw new OutpostError(\n \"workspace\",\n \"Git inspection output limit exceeded\",\n );\n },\n });\n return result.stdout;\n}\n\nasync function inspectEntry(\n entry: StorageEntry,\n records: readonly (readonly string[])[],\n commonDirectory: string,\n): Promise<WorkspaceGitState> {\n if (entry.kind !== \"directory\")\n return { state: \"skipped\", reason: \"NOT_DIRECTORY\" };\n const fields = records.find((record) => {\n const path = record\n .find((field) => field.startsWith(\"worktree \"))\n ?.slice(9);\n return path !== undefined && resolve(path) === resolve(entry.path);\n });\n if (!fields) return { state: \"unregistered\" };\n const head = fields.find((field) => field.startsWith(\"HEAD \"))?.slice(5);\n if (!head) return { state: \"unavailable\", reason: \"INVALID_REGISTRATION\" };\n // A listed worktree may have been replaced since registration or inventory.\n if (\n !(await lstat(entry.path)).isDirectory() ||\n (await realpath(entry.path)) !== resolve(entry.path)\n )\n return { state: \"unavailable\", reason: \"WORKSPACE_CHANGED\" };\n const marker = await lstat(join(entry.path, \".git\"));\n if (!marker.isFile())\n return { state: \"unavailable\", reason: \"INVALID_GIT_MARKER\" };\n const top = (\n await inspectGit(entry.path, [\"rev-parse\", \"--show-toplevel\"])\n ).trim();\n if (resolve(top) !== resolve(entry.path))\n return { state: \"unavailable\", reason: \"WORKSPACE_CHANGED\" };\n const common = (\n await inspectGit(entry.path, [\n \"rev-parse\",\n \"--path-format=absolute\",\n \"--git-common-dir\",\n ])\n ).trim();\n if ((await realpath(common)) !== commonDirectory)\n return { state: \"unavailable\", reason: \"REGISTRATION_MISMATCH\" };\n const status = await inspectGit(entry.path, [\n \"status\",\n \"--porcelain=v1\",\n \"-z\",\n \"--untracked-files=normal\",\n \"--ignore-submodules=none\",\n ]);\n return {\n state: \"registered\",\n head,\n branch:\n fields\n .find((field) => field.startsWith(\"branch refs/heads/\"))\n ?.slice(18) ?? null,\n dirty: status.length > 0,\n locked: fields.some(\n (field) => field === \"locked\" || field.startsWith(\"locked \"),\n ),\n };\n}\n\nexport async function inspectWorktreeGit(\n repository: string,\n entries: readonly StorageEntry[],\n): Promise<WorkspaceGitInspection> {\n const workspaces: WorkspaceGitEntry[] = [];\n const issues: StorageIssue[] = [];\n if (!entries.length) return { complete: true, workspaces, issues };\n let records: string[][];\n let commonDirectory: string;\n try {\n commonDirectory = await realpath(\n (\n await inspectGit(repository, [\n \"rev-parse\",\n \"--path-format=absolute\",\n \"--git-common-dir\",\n ])\n ).trim(),\n );\n const list = await inspectGit(repository, [\n \"worktree\",\n \"list\",\n \"--porcelain\",\n \"-z\",\n ]);\n records = list\n .split(\"\\0\\0\")\n .filter(Boolean)\n .map((record) => record.split(\"\\0\"));\n } catch {\n return {\n complete: false,\n workspaces: entries.map(({ name, path }) => ({\n name,\n path,\n state: \"unavailable\",\n reason: \"GIT_LIST_FAILED\",\n })),\n issues: [{ path: repository, code: \"GIT_LIST_FAILED\" }],\n };\n }\n for (const entry of entries) {\n const state = await inspectEntry(entry, records, commonDirectory).catch(\n (): WorkspaceGitState => ({\n state: \"unavailable\",\n reason: \"GIT_INSPECTION_FAILED\",\n }),\n );\n workspaces.push({ name: entry.name, path: entry.path, ...state });\n if (state.state === \"unavailable\")\n issues.push({ path: entry.path, code: state.reason });\n }\n return { complete: issues.length === 0, workspaces, issues };\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { StorageEntry, StorageIssue } from "../storage-inventory.types.ts";
|
|
2
|
+
export type WorkspaceGitState = {
|
|
3
|
+
readonly state: "registered";
|
|
4
|
+
readonly head: string;
|
|
5
|
+
readonly branch: string | null;
|
|
6
|
+
readonly dirty: boolean;
|
|
7
|
+
readonly locked: boolean;
|
|
8
|
+
} | {
|
|
9
|
+
readonly state: "unregistered";
|
|
10
|
+
} | {
|
|
11
|
+
readonly state: "skipped" | "unavailable";
|
|
12
|
+
readonly reason: string;
|
|
13
|
+
};
|
|
14
|
+
export type WorkspaceGitEntry = Pick<StorageEntry, "name" | "path"> & WorkspaceGitState;
|
|
15
|
+
export interface WorkspaceGitInspection {
|
|
16
|
+
readonly complete: boolean;
|
|
17
|
+
readonly workspaces: readonly WorkspaceGitEntry[];
|
|
18
|
+
readonly issues: readonly StorageIssue[];
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worktree-inspection.types.js","sourceRoot":"","sources":["../../../src/infrastructure/git/worktree-inspection.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { StorageEntry, StorageIssue } from \"../storage-inventory.types.ts\";\n\nexport type WorkspaceGitState =\n | {\n readonly state: \"registered\";\n readonly head: string;\n readonly branch: string | null;\n readonly dirty: boolean;\n readonly locked: boolean;\n }\n | { readonly state: \"unregistered\" }\n | { readonly state: \"skipped\" | \"unavailable\"; readonly reason: string };\n\nexport type WorkspaceGitEntry = Pick<StorageEntry, \"name\" | \"path\"> &\n WorkspaceGitState;\n\nexport interface WorkspaceGitInspection {\n readonly complete: boolean;\n readonly workspaces: readonly WorkspaceGitEntry[];\n readonly issues: readonly StorageIssue[];\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const inspectionFileFlags: number;
|