@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,3 +1,4 @@
|
|
|
1
|
+
import { workflowAccounting } from "./budget.js";
|
|
1
2
|
import { randomUUID } from "node:crypto";
|
|
2
3
|
export function workflowState(name, tasks, options) {
|
|
3
4
|
const executionId = randomUUID();
|
|
@@ -6,11 +7,17 @@ export function workflowState(name, tasks, options) {
|
|
|
6
7
|
? AbortSignal.any([options.signal, stop.signal])
|
|
7
8
|
: stop.signal;
|
|
8
9
|
const values = new Map();
|
|
10
|
+
const activeAttempts = new Map();
|
|
9
11
|
const records = new Map(tasks.map((item) => [
|
|
10
12
|
item,
|
|
11
13
|
{ key: item.key, status: "waiting", attempts: 0 },
|
|
12
14
|
]));
|
|
13
15
|
const errors = [], observerErrors = [];
|
|
16
|
+
const accounting = workflowAccounting(options.budget, (error) => {
|
|
17
|
+
errors.push(error);
|
|
18
|
+
if (error.dimension !== "attempts")
|
|
19
|
+
stop.abort(error);
|
|
20
|
+
});
|
|
14
21
|
const record = (item) => records.get(item);
|
|
15
22
|
function emit(event) {
|
|
16
23
|
try {
|
|
@@ -35,13 +42,31 @@ export function workflowState(name, tasks, options) {
|
|
|
35
42
|
key: item.key,
|
|
36
43
|
status,
|
|
37
44
|
attempt: record(item).attempts,
|
|
45
|
+
...(record(item).startedAt
|
|
46
|
+
? { durationMs: Date.now() - Date.parse(record(item).startedAt) }
|
|
47
|
+
: {}),
|
|
38
48
|
});
|
|
39
49
|
}
|
|
40
50
|
function context(item, attempt, taskSignal) {
|
|
51
|
+
if (attempt > 0)
|
|
52
|
+
activeAttempts.set(item, attempt);
|
|
41
53
|
return {
|
|
42
54
|
signal: taskSignal,
|
|
43
55
|
attempt,
|
|
44
56
|
executionId,
|
|
57
|
+
reportUsage(usage) {
|
|
58
|
+
if (attempt === 0 ||
|
|
59
|
+
record(item).status !== "active" ||
|
|
60
|
+
activeAttempts.get(item) !== attempt)
|
|
61
|
+
throw new Error("Usage must be reported during its active task attempt");
|
|
62
|
+
accounting.report(usage);
|
|
63
|
+
emit({
|
|
64
|
+
type: "usage",
|
|
65
|
+
key: item.key,
|
|
66
|
+
attempt,
|
|
67
|
+
usage: Object.freeze({ ...usage }),
|
|
68
|
+
});
|
|
69
|
+
},
|
|
45
70
|
value(dependency) {
|
|
46
71
|
if (!item.after.includes(dependency))
|
|
47
72
|
throw new Error(`${item.key}: undeclared dependency ${dependency.key}`);
|
|
@@ -53,6 +78,10 @@ export function workflowState(name, tasks, options) {
|
|
|
53
78
|
}
|
|
54
79
|
return {
|
|
55
80
|
executionId,
|
|
81
|
+
accounting,
|
|
82
|
+
closeAttempt(item) {
|
|
83
|
+
activeAttempts.delete(item);
|
|
84
|
+
},
|
|
56
85
|
stop,
|
|
57
86
|
signal,
|
|
58
87
|
values,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-state.js","sourceRoot":"","sources":["../../../src/domain/workflow/workflow-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAWzC,MAAM,UAAU,aAAa,CAC3B,IAAY,EACZ,KAAsB,EACtB,OAAwB;IAExB,MAAM,WAAW,GAAG,UAAU,EAAE,CAAC;IACjC,MAAM,IAAI,GAAG,IAAI,eAAe,EAAE,CAAC;IACnC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM;QAC3B,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAChD,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;IAChB,MAAM,MAAM,GAAG,IAAI,GAAG,EAAiB,CAAC;IACxC,MAAM,OAAO,GAAG,IAAI,GAAG,CACrB,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;QAClB,IAAI;QACJ,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,EAAE;KAClD,CAAC,CACH,CAAC;IACF,MAAM,MAAM,GAAc,EAAE,EAC1B,cAAc,GAAc,EAAE,CAAC;IACjC,MAAM,MAAM,GAAG,CAAC,IAAU,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC;IAClD,SAAS,IAAI,CACX,KAAoE;QAEpE,IAAI,CAAC;YACH,OAAO,CAAC,OAAO,EAAE,CAAC;gBAChB,GAAG,KAAK;gBACR,WAAW;gBACX,QAAQ,EAAE,IAAI;gBACd,SAAS,EAAE,IAAI,IAAI,E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,CAAC;SACF,CAAC;IACJ,CAAC;IAED,OAAO;QACL,WAAW;QACX,UAAU;QACV,YAAY,CAAC,IAAI;YACf,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9B,CAAC;QACD,IAAI;QACJ,MAAM;QACN,MAAM;QACN,OAAO;QACP,MAAM;QACN,cAAc;QACd,MAAM;QACN,IAAI;QACJ,MAAM;QACN,OAAO;QACP,OAAO;KACR,CAAC;AACJ,CAAC","sourcesContent":["import { workflowAccounting } from \"./budget.ts\";\nimport { randomUUID } from \"node:crypto\";\nimport type {\n Task,\n TaskContext,\n TaskRecord,\n TaskStatus,\n WorkflowEvent,\n WorkflowExecutionState,\n WorkflowOptions,\n} from \"../workflow.types.ts\";\n\nexport function workflowState(\n name: string,\n tasks: readonly Task[],\n options: WorkflowOptions,\n): WorkflowExecutionState {\n const executionId = randomUUID();\n const stop = new AbortController();\n const signal = options.signal\n ? AbortSignal.any([options.signal, stop.signal])\n : stop.signal;\n const values = new Map<Task, unknown>();\n const activeAttempts = new Map<Task, number>();\n const records = new Map<Task, TaskRecord>(\n tasks.map((item) => [\n item,\n { key: item.key, status: \"waiting\", attempts: 0 },\n ]),\n );\n const errors: unknown[] = [],\n observerErrors: unknown[] = [];\n const accounting = workflowAccounting(options.budget, (error) => {\n errors.push(error);\n if (error.dimension !== \"attempts\") stop.abort(error);\n });\n const record = (item: Task) => records.get(item)!;\n function emit(\n event: Omit<WorkflowEvent, \"executionId\" | \"workflow\" | \"timestamp\">,\n ): void {\n try {\n options.observe?.({\n ...event,\n executionId,\n workflow: name,\n timestamp: new Date().toISOString(),\n });\n } catch (error) {\n observerErrors.push(error);\n }\n }\n function finish(item: Task, status: TaskStatus): void {\n Object.assign(record(item), {\n status,\n finishedAt: new Date().toISOString(),\n });\n emit({\n type: \"task\",\n key: item.key,\n status,\n attempt: record(item).attempts,\n ...(record(item).startedAt\n ? { durationMs: Date.now() - Date.parse(record(item).startedAt!) }\n : {}),\n });\n }\n function context(\n item: Task,\n attempt: number,\n taskSignal: AbortSignal,\n ): TaskContext {\n if (attempt > 0) activeAttempts.set(item, attempt);\n return {\n signal: taskSignal,\n attempt,\n executionId,\n reportUsage(usage) {\n if (\n attempt === 0 ||\n record(item).status !== \"active\" ||\n activeAttempts.get(item) !== attempt\n )\n throw new Error(\n \"Usage must be reported during its active task attempt\",\n );\n accounting.report(usage);\n emit({\n type: \"usage\",\n key: item.key,\n attempt,\n usage: Object.freeze({ ...usage }),\n });\n },\n value<T>(dependency: Task<T>): T {\n if (!item.after.includes(dependency))\n throw new Error(\n `${item.key}: undeclared dependency ${dependency.key}`,\n );\n if (!values.has(dependency))\n throw new Error(`${dependency.key} has no successful value`);\n return values.get(dependency) as T;\n },\n };\n }\n\n return {\n executionId,\n accounting,\n closeAttempt(item) {\n activeAttempts.delete(item);\n },\n stop,\n signal,\n values,\n records,\n errors,\n observerErrors,\n record,\n emit,\n finish,\n context,\n options,\n };\n}\n"]}
|
|
@@ -3,3 +3,5 @@ export type { Retry, Task, TaskContext, TaskOptions, TaskRecord, TaskStatus, Wor
|
|
|
3
3
|
export { WorkflowFailure } from "./workflow/failure.ts";
|
|
4
4
|
export { task } from "./workflow/task.ts";
|
|
5
5
|
export declare function workflow(name: string, tasks: readonly Task[]): Workflow;
|
|
6
|
+
export { WorkflowBudgetExceeded } from "./workflow/budget.ts";
|
|
7
|
+
export type { WorkflowBudget, WorkflowUsage } from "./workflow/budget.types.ts";
|
package/dist/domain/workflow.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.js","sourceRoot":"","sources":["../../src/domain/workflow.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAc5D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,KAAsB;IAC3D,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACnE,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;IACxC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChB,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,IAAI;QACJ,KAAK,EAAE,KAAK;QACZ,KAAK,EAAE,CAAC,UAA2B,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC;QACxE,OAAO;YACL,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;YACrE,OAAO;gBACL,cAAc;gBACd,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;oBACzB,KAAK,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,GAAG,IAAI;oBACnC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CACf,CAAC,UAAU,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAChE;iBACF,CAAC;aACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACf,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { Task, Workflow, WorkflowOptions } from \"./workflow.types.ts\";\nimport { validate } from \"./workflow/validation.ts\";\nimport { schedule } from \"./workflow/workflow-scheduler.ts\";\n\nexport type {\n Retry,\n Task,\n TaskContext,\n TaskOptions,\n TaskRecord,\n TaskStatus,\n Workflow,\n WorkflowEvent,\n WorkflowOptions,\n WorkflowResult,\n} from \"./workflow.types.ts\";\nexport { WorkflowFailure } from \"./workflow/failure.ts\";\nexport { task } from \"./workflow/task.ts\";\n\nexport function workflow(name: string, tasks: readonly Task[]): Workflow {\n if (!name.trim()) throw new Error(\"Workflow name cannot be empty\");\n const graph = Object.freeze([...tasks]);\n validate(graph);\n return Object.freeze({\n name,\n tasks: graph,\n start: (options: WorkflowOptions = {}) => schedule(name, graph, options),\n diagram() {\n const ids = new Map(graph.map((item, index) => [item, `n${index}`]));\n return [\n \"flowchart LR\",\n ...graph.flatMap((item) => [\n ` ${ids.get(item)}[\"${item.key}\"]`,\n ...item.after.map(\n (dependency) => ` ${ids.get(dependency)} --> ${ids.get(item)}`,\n ),\n ]),\n ].join(\"\\n\");\n },\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"workflow.js","sourceRoot":"","sources":["../../src/domain/workflow.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAc5D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,KAAsB;IAC3D,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACnE,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;IACxC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChB,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,IAAI;QACJ,KAAK,EAAE,KAAK;QACZ,KAAK,EAAE,CAAC,UAA2B,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC;QACxE,OAAO;YACL,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;YACrE,OAAO;gBACL,cAAc;gBACd,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;oBACzB,KAAK,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,GAAG,IAAI;oBACnC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CACf,CAAC,UAAU,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAChE;iBACF,CAAC;aACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACf,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["import type { Task, Workflow, WorkflowOptions } from \"./workflow.types.ts\";\nimport { validate } from \"./workflow/validation.ts\";\nimport { schedule } from \"./workflow/workflow-scheduler.ts\";\n\nexport type {\n Retry,\n Task,\n TaskContext,\n TaskOptions,\n TaskRecord,\n TaskStatus,\n Workflow,\n WorkflowEvent,\n WorkflowOptions,\n WorkflowResult,\n} from \"./workflow.types.ts\";\nexport { WorkflowFailure } from \"./workflow/failure.ts\";\nexport { task } from \"./workflow/task.ts\";\n\nexport function workflow(name: string, tasks: readonly Task[]): Workflow {\n if (!name.trim()) throw new Error(\"Workflow name cannot be empty\");\n const graph = Object.freeze([...tasks]);\n validate(graph);\n return Object.freeze({\n name,\n tasks: graph,\n start: (options: WorkflowOptions = {}) => schedule(name, graph, options),\n diagram() {\n const ids = new Map(graph.map((item, index) => [item, `n${index}`]));\n return [\n \"flowchart LR\",\n ...graph.flatMap((item) => [\n ` ${ids.get(item)}[\"${item.key}\"]`,\n ...item.after.map(\n (dependency) => ` ${ids.get(dependency)} --> ${ids.get(item)}`,\n ),\n ]),\n ].join(\"\\n\");\n },\n });\n}\n\nexport { WorkflowBudgetExceeded } from \"./workflow/budget.ts\";\nexport type { WorkflowBudget, WorkflowUsage } from \"./workflow/budget.types.ts\";\n"]}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import type { Usage } from "./agent.types.ts";
|
|
2
|
+
import type { WorkflowAccounting, WorkflowBudget, WorkflowUsage } from "./workflow/budget.types.ts";
|
|
1
3
|
export interface TaskContext {
|
|
2
4
|
readonly signal: AbortSignal;
|
|
3
5
|
readonly attempt: number;
|
|
4
6
|
readonly executionId: string;
|
|
7
|
+
reportUsage(usage: Usage): void;
|
|
5
8
|
value<T>(dependency: Task<T>): T;
|
|
6
9
|
}
|
|
7
10
|
export interface Retry {
|
|
@@ -33,14 +36,17 @@ export interface WorkflowEvent {
|
|
|
33
36
|
readonly executionId: string;
|
|
34
37
|
readonly workflow: string;
|
|
35
38
|
readonly timestamp: string;
|
|
36
|
-
readonly type: "start" | "task" | "retry" | "finish";
|
|
39
|
+
readonly type: "start" | "task" | "attempt" | "retry" | "usage" | "finish";
|
|
37
40
|
readonly key?: string;
|
|
38
41
|
readonly status?: TaskStatus;
|
|
39
42
|
readonly attempt?: number;
|
|
43
|
+
readonly usage?: Usage;
|
|
44
|
+
readonly durationMs?: number;
|
|
40
45
|
}
|
|
41
46
|
export interface WorkflowOptions {
|
|
42
47
|
readonly signal?: AbortSignal;
|
|
43
48
|
readonly concurrency?: number;
|
|
49
|
+
readonly budget?: WorkflowBudget;
|
|
44
50
|
readonly stopOnError?: boolean;
|
|
45
51
|
readonly observe?: (event: WorkflowEvent) => void;
|
|
46
52
|
}
|
|
@@ -51,6 +57,7 @@ export interface WorkflowResult {
|
|
|
51
57
|
readonly tasks: readonly Readonly<TaskRecord>[];
|
|
52
58
|
readonly errors: readonly unknown[];
|
|
53
59
|
readonly observerErrors: readonly unknown[];
|
|
60
|
+
readonly usage: WorkflowUsage;
|
|
54
61
|
value<T>(task: Task<T>): T;
|
|
55
62
|
unwrap(): void;
|
|
56
63
|
}
|
|
@@ -70,6 +77,8 @@ export interface WorkflowExecutionState {
|
|
|
70
77
|
readonly errors: unknown[];
|
|
71
78
|
readonly observerErrors: unknown[];
|
|
72
79
|
readonly options: WorkflowOptions;
|
|
80
|
+
readonly accounting: WorkflowAccounting;
|
|
81
|
+
closeAttempt(task: Task): void;
|
|
73
82
|
record(task: Task): TaskRecord;
|
|
74
83
|
emit(event: WorkflowNotification): void;
|
|
75
84
|
finish(task: Task, status: TaskStatus): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.types.js","sourceRoot":"","sources":["../../src/domain/workflow.types.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"workflow.types.js","sourceRoot":"","sources":["../../src/domain/workflow.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Usage } from \"./agent.types.ts\";\nimport type {\n WorkflowAccounting,\n WorkflowBudget,\n WorkflowUsage,\n} from \"./workflow/budget.types.ts\";\n\nexport interface TaskContext {\n readonly signal: AbortSignal;\n readonly attempt: number;\n readonly executionId: string;\n reportUsage(usage: Usage): void;\n value<T>(dependency: Task<T>): T;\n}\n\nexport interface Retry {\n readonly attempts: number;\n readonly delayMs?: number;\n readonly accepts?: (error: unknown, attempt: number) => boolean;\n}\n\nexport interface Task<T = unknown> {\n readonly key: string;\n readonly after: readonly Task[];\n readonly perform: (context: TaskContext) => T | Promise<T>;\n readonly condition?: (context: TaskContext) => boolean | Promise<boolean>;\n readonly retry?: Retry;\n readonly timeoutMs?: number;\n}\n\nexport type TaskOptions<T> = Omit<Task<T>, \"after\"> & {\n readonly after?: readonly Task[];\n};\n\nexport type TaskStatus =\n \"waiting\" | \"active\" | \"done\" | \"failed\" | \"skipped\" | \"cancelled\";\n\nexport interface TaskRecord {\n readonly key: string;\n status: TaskStatus;\n attempts: number;\n startedAt?: string;\n finishedAt?: string;\n error?: string;\n}\n\nexport interface WorkflowEvent {\n readonly executionId: string;\n readonly workflow: string;\n readonly timestamp: string;\n readonly type: \"start\" | \"task\" | \"attempt\" | \"retry\" | \"usage\" | \"finish\";\n readonly key?: string;\n readonly status?: TaskStatus;\n readonly attempt?: number;\n readonly usage?: Usage;\n readonly durationMs?: number;\n}\n\nexport interface WorkflowOptions {\n readonly signal?: AbortSignal;\n readonly concurrency?: number;\n readonly budget?: WorkflowBudget;\n readonly stopOnError?: boolean;\n readonly observe?: (event: WorkflowEvent) => void;\n}\n\nexport interface WorkflowResult {\n readonly executionId: string;\n readonly name: string;\n readonly status: \"done\" | \"failed\" | \"cancelled\";\n readonly tasks: readonly Readonly<TaskRecord>[];\n readonly errors: readonly unknown[];\n readonly observerErrors: readonly unknown[];\n readonly usage: WorkflowUsage;\n value<T>(task: Task<T>): T;\n unwrap(): void;\n}\n\nexport interface Workflow {\n readonly name: string;\n readonly tasks: readonly Task[];\n start(options?: WorkflowOptions): Promise<WorkflowResult>;\n diagram(): string;\n}\n\nexport type WorkflowNotification = Omit<\n WorkflowEvent,\n \"executionId\" | \"workflow\" | \"timestamp\"\n>;\nexport interface WorkflowExecutionState {\n readonly executionId: string;\n readonly stop: AbortController;\n readonly signal: AbortSignal;\n readonly values: Map<Task, unknown>;\n readonly records: Map<Task, TaskRecord>;\n readonly errors: unknown[];\n readonly observerErrors: unknown[];\n readonly options: WorkflowOptions;\n readonly accounting: WorkflowAccounting;\n closeAttempt(task: Task): void;\n record(task: Task): TaskRecord;\n emit(event: WorkflowNotification): void;\n finish(task: Task, status: TaskStatus): void;\n context(task: Task, attempt: number, signal: AbortSignal): TaskContext;\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { attach, createSandbox, dispatch, openWorkspace, } from "./application/outpost.ts";
|
|
2
2
|
export type { AttachOptions, AttachResult, ContinuationOptions, DispatchResult, Sandbox, SandboxOptions, WarmDispatchResult, Workspace, WorkspaceOptions, } from "./application/outpost.ts";
|
|
3
3
|
export type { DispatchOptions, Execution, Turn, } from "./application/execution.ts";
|
|
4
|
-
export { WorkflowFailure, task, workflow } from "./domain/workflow.ts";
|
|
5
|
-
export type { Retry, Task, TaskContext, TaskOptions, TaskRecord, TaskStatus, Workflow, WorkflowEvent, WorkflowOptions, WorkflowResult, } from "./domain/workflow.ts";
|
|
4
|
+
export { WorkflowFailure, WorkflowBudgetExceeded, task, workflow, } from "./domain/workflow.ts";
|
|
5
|
+
export type { Retry, Task, TaskContext, TaskOptions, TaskRecord, TaskStatus, Workflow, WorkflowEvent, WorkflowOptions, WorkflowBudget, WorkflowUsage, WorkflowResult, } from "./domain/workflow.ts";
|
|
6
6
|
export { agentTask, commandTask, isolatedTask } from "./application/tasks.ts";
|
|
7
7
|
export { claude, codex } from "./providers/agents.ts";
|
|
8
8
|
export { agentVersions } from "./providers/versions.ts";
|
|
@@ -14,9 +14,18 @@ export { ResponseError, response } from "./domain/response.ts";
|
|
|
14
14
|
export type { ResponseSpec, StandardValidator } from "./domain/response.ts";
|
|
15
15
|
export { OutpostError, recoveryDetails } from "./domain/errors.ts";
|
|
16
16
|
export type { FaultCode } from "./domain/errors.ts";
|
|
17
|
-
export type { AgentAdapter, AgentEvent, AgentInput, AgentObservation, BranchPolicy, Channel, Command, CommandResult, Commit, ConversationContext, ConversationRecord, ConversationStore, Disposal, LifecycleHooks, SandboxContext, SandboxLease, SandboxProvider, StageLimits, TransferOptions, Usage, Variables, Volume, WorkspaceRecord, } from "./domain/ports.ts";
|
|
17
|
+
export type { AgentAdapter, AgentEvent, AgentInput, AgentObservation, BranchPolicy, Channel, Command, CommandResult, Commit, ConversationContext, ConversationRecord, ConversationStore, Disposal, LifecycleHooks, FileManifestEntry, FileTransfers, SandboxContext, SandboxLease, SandboxProvider, StageLimits, TransferOptions, Usage, Variables, Volume, WorkspaceRecord, } from "./domain/ports.ts";
|
|
18
18
|
export type { Brief, PromptVariables } from "./domain/prompts.ts";
|
|
19
19
|
export type { Logging } from "./infrastructure/journal.ts";
|
|
20
20
|
export { reporter } from "./infrastructure/reporter.ts";
|
|
21
21
|
export type { ReporterOptions } from "./infrastructure/reporter.ts";
|
|
22
22
|
export type { VariableQuestion } from "./application/interactive-brief.ts";
|
|
23
|
+
export { planRecoveryRetention, pruneRecoveryRetention, assertRecoveryQuota, } from "./application/recovery-retention.ts";
|
|
24
|
+
export type { RecoveryRetentionPolicy, RecoveryRetentionOptions, RecoveryRetentionPlan, RecoveryRetentionEntry, RecoveryPruneResult, RecoveryQuotaOptions, } from "./application/recovery-retention.types.ts";
|
|
25
|
+
export { verifyRecoveryTransfer } from "./application/recovery-verification.ts";
|
|
26
|
+
export type { RecoveryVerification, RecoveryVerificationOptions, } from "./application/recovery-verification.types.ts";
|
|
27
|
+
export { diagnoseSandbox } from "./application/doctor-sandbox.ts";
|
|
28
|
+
export type { SandboxDiagnosticOptions, SandboxDiagnosticReport, DiagnosticCapability, } from "./application/doctor-sandbox.types.ts";
|
|
29
|
+
export type { DiagnosticCheck, DiagnosticStatus, DoctorAgent, } from "./application/doctor.types.ts";
|
|
30
|
+
export { diagnoseAgentProtocol } from "./application/doctor-protocol.ts";
|
|
31
|
+
export type { AgentProtocolReport } from "./application/doctor-protocol.types.ts";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { attach, createSandbox, dispatch, openWorkspace, } from "./application/outpost.js";
|
|
2
|
-
export { WorkflowFailure, task, workflow } from "./domain/workflow.js";
|
|
2
|
+
export { WorkflowFailure, WorkflowBudgetExceeded, task, workflow, } from "./domain/workflow.js";
|
|
3
3
|
export { agentTask, commandTask, isolatedTask } from "./application/tasks.js";
|
|
4
4
|
export { claude, codex } from "./providers/agents.js";
|
|
5
5
|
export { agentVersions } from "./providers/versions.js";
|
|
@@ -8,4 +8,8 @@ export { mountedProvider, remoteProvider } from "./providers/factories.js";
|
|
|
8
8
|
export { ResponseError, response } from "./domain/response.js";
|
|
9
9
|
export { OutpostError, recoveryDetails } from "./domain/errors.js";
|
|
10
10
|
export { reporter } from "./infrastructure/reporter.js";
|
|
11
|
+
export { planRecoveryRetention, pruneRecoveryRetention, assertRecoveryQuota, } from "./application/recovery-retention.js";
|
|
12
|
+
export { verifyRecoveryTransfer } from "./application/recovery-verification.js";
|
|
13
|
+
export { diagnoseSandbox } from "./application/doctor-sandbox.js";
|
|
14
|
+
export { diagnoseAgentProtocol } from "./application/doctor-protocol.js";
|
|
11
15
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,aAAa,EACb,QAAQ,EACR,aAAa,GACd,MAAM,0BAA0B,CAAC;AAoBlC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,aAAa,EACb,QAAQ,EACR,aAAa,GACd,MAAM,0BAA0B,CAAC;AAoBlC,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,IAAI,EACJ,QAAQ,GACT,MAAM,sBAAsB,CAAC;AAiB9B,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE9E,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEtD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AASlE,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE3E,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAI/D,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAoCnE,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAMxD,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,qCAAqC,CAAC;AAS7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAMhF,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAWlE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC","sourcesContent":["export {\n attach,\n createSandbox,\n dispatch,\n openWorkspace,\n} from \"./application/outpost.ts\";\n\nexport type {\n AttachOptions,\n AttachResult,\n ContinuationOptions,\n DispatchResult,\n Sandbox,\n SandboxOptions,\n WarmDispatchResult,\n Workspace,\n WorkspaceOptions,\n} from \"./application/outpost.ts\";\n\nexport type {\n DispatchOptions,\n Execution,\n Turn,\n} from \"./application/execution.ts\";\n\nexport {\n WorkflowFailure,\n WorkflowBudgetExceeded,\n task,\n workflow,\n} from \"./domain/workflow.ts\";\n\nexport type {\n Retry,\n Task,\n TaskContext,\n TaskOptions,\n TaskRecord,\n TaskStatus,\n Workflow,\n WorkflowEvent,\n WorkflowOptions,\n WorkflowBudget,\n WorkflowUsage,\n WorkflowResult,\n} from \"./domain/workflow.ts\";\n\nexport { agentTask, commandTask, isolatedTask } from \"./application/tasks.ts\";\n\nexport { claude, codex } from \"./providers/agents.ts\";\n\nexport { agentVersions } from \"./providers/versions.ts\";\n\nexport { conversations } from \"./infrastructure/conversations.ts\";\n\nexport type {\n ConversationFormat,\n ConversationLocation,\n} from \"./infrastructure/conversations.ts\";\n\nexport type { ClaudeSettings, CodexSettings } from \"./providers/agents.ts\";\n\nexport { mountedProvider, remoteProvider } from \"./providers/factories.ts\";\n\nexport { ResponseError, response } from \"./domain/response.ts\";\n\nexport type { ResponseSpec, StandardValidator } from \"./domain/response.ts\";\n\nexport { OutpostError, recoveryDetails } from \"./domain/errors.ts\";\n\nexport type { FaultCode } from \"./domain/errors.ts\";\n\nexport type {\n AgentAdapter,\n AgentEvent,\n AgentInput,\n AgentObservation,\n BranchPolicy,\n Channel,\n Command,\n CommandResult,\n Commit,\n ConversationContext,\n ConversationRecord,\n ConversationStore,\n Disposal,\n LifecycleHooks,\n FileManifestEntry,\n FileTransfers,\n SandboxContext,\n SandboxLease,\n SandboxProvider,\n StageLimits,\n TransferOptions,\n Usage,\n Variables,\n Volume,\n WorkspaceRecord,\n} from \"./domain/ports.ts\";\n\nexport type { Brief, PromptVariables } from \"./domain/prompts.ts\";\n\nexport type { Logging } from \"./infrastructure/journal.ts\";\n\nexport { reporter } from \"./infrastructure/reporter.ts\";\n\nexport type { ReporterOptions } from \"./infrastructure/reporter.ts\";\n\nexport type { VariableQuestion } from \"./application/interactive-brief.ts\";\n\nexport {\n planRecoveryRetention,\n pruneRecoveryRetention,\n assertRecoveryQuota,\n} from \"./application/recovery-retention.ts\";\nexport type {\n RecoveryRetentionPolicy,\n RecoveryRetentionOptions,\n RecoveryRetentionPlan,\n RecoveryRetentionEntry,\n RecoveryPruneResult,\n RecoveryQuotaOptions,\n} from \"./application/recovery-retention.types.ts\";\nexport { verifyRecoveryTransfer } from \"./application/recovery-verification.ts\";\nexport type {\n RecoveryVerification,\n RecoveryVerificationOptions,\n} from \"./application/recovery-verification.types.ts\";\n\nexport { diagnoseSandbox } from \"./application/doctor-sandbox.ts\";\nexport type {\n SandboxDiagnosticOptions,\n SandboxDiagnosticReport,\n DiagnosticCapability,\n} from \"./application/doctor-sandbox.types.ts\";\nexport type {\n DiagnosticCheck,\n DiagnosticStatus,\n DoctorAgent,\n} from \"./application/doctor.types.ts\";\nexport { diagnoseAgentProtocol } from \"./application/doctor-protocol.ts\";\nexport type { AgentProtocolReport } from \"./application/doctor-protocol.types.ts\";\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FileManifestEntry } from "../domain/sandbox.types.ts";
|
|
2
|
+
export declare function fileManifest(root: string, path: string): Promise<FileManifestEntry>;
|
|
3
|
+
export declare function sameFile(left: FileManifestEntry, right: FileManifestEntry): boolean;
|
|
4
|
+
export declare function sameLocalFile(remote: FileManifestEntry, local: FileManifestEntry): boolean;
|
|
5
|
+
export declare function validateFilePaths(paths: readonly string[]): void;
|
|
6
|
+
export declare function parseManifest(value: unknown, paths: readonly string[]): FileManifestEntry[];
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { createReadStream } from "node:fs";
|
|
3
|
+
import { lstat, readlink } from "node:fs/promises";
|
|
4
|
+
import { OutpostError } from "../domain/errors.js";
|
|
5
|
+
import { safeDestination } from "./files.js";
|
|
6
|
+
export async function fileManifest(root, path) {
|
|
7
|
+
const target = await safeDestination(root, path);
|
|
8
|
+
const info = await lstat(target);
|
|
9
|
+
if (!info.isFile() && !info.isSymbolicLink())
|
|
10
|
+
throw new OutpostError("provider", "Unsupported manifest file type", {
|
|
11
|
+
path,
|
|
12
|
+
});
|
|
13
|
+
const hash = createHash("sha256");
|
|
14
|
+
let size = info.size;
|
|
15
|
+
if (info.isSymbolicLink()) {
|
|
16
|
+
const value = Buffer.from(await readlink(target));
|
|
17
|
+
size = value.length;
|
|
18
|
+
hash.update(value);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
for await (const chunk of createReadStream(target))
|
|
22
|
+
hash.update(chunk);
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
path,
|
|
26
|
+
kind: info.isSymbolicLink() ? "link" : "file",
|
|
27
|
+
mode: info.mode & 0o777,
|
|
28
|
+
size,
|
|
29
|
+
sha256: hash.digest("hex"),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export function sameFile(left, right) {
|
|
33
|
+
return (left.path === right.path &&
|
|
34
|
+
left.kind === right.kind &&
|
|
35
|
+
left.mode === right.mode &&
|
|
36
|
+
left.size === right.size &&
|
|
37
|
+
left.sha256 === right.sha256);
|
|
38
|
+
}
|
|
39
|
+
export function sameLocalFile(remote, local) {
|
|
40
|
+
if (process.platform !== "win32")
|
|
41
|
+
return sameFile(remote, local);
|
|
42
|
+
return sameFile({ ...remote, mode: remote.mode & 0o200 }, { ...local, mode: local.mode & 0o200 });
|
|
43
|
+
}
|
|
44
|
+
export function validateFilePaths(paths) {
|
|
45
|
+
if (new Set(paths).size !== paths.length ||
|
|
46
|
+
paths.some((path) => !path ||
|
|
47
|
+
path.includes("\\") ||
|
|
48
|
+
path.includes("\0") ||
|
|
49
|
+
path
|
|
50
|
+
.split("/")
|
|
51
|
+
.some((part) => !part ||
|
|
52
|
+
part === "." ||
|
|
53
|
+
part === ".." ||
|
|
54
|
+
part.toLowerCase() === ".git")))
|
|
55
|
+
throw new OutpostError("provider", "Unsafe or duplicate manifest path");
|
|
56
|
+
}
|
|
57
|
+
export function parseManifest(value, paths) {
|
|
58
|
+
validateFilePaths(paths);
|
|
59
|
+
if (!Array.isArray(value) || value.length !== paths.length)
|
|
60
|
+
throw new OutpostError("provider", "Invalid file manifest");
|
|
61
|
+
return value.map((entry, index) => {
|
|
62
|
+
if (!entry ||
|
|
63
|
+
typeof entry !== "object" ||
|
|
64
|
+
!("path" in entry) ||
|
|
65
|
+
typeof entry.path !== "string" ||
|
|
66
|
+
entry.path !== paths[index] ||
|
|
67
|
+
!("kind" in entry) ||
|
|
68
|
+
(entry.kind !== "file" && entry.kind !== "link") ||
|
|
69
|
+
!("mode" in entry) ||
|
|
70
|
+
typeof entry.mode !== "number" ||
|
|
71
|
+
!Number.isInteger(entry.mode) ||
|
|
72
|
+
entry.mode < 0 ||
|
|
73
|
+
entry.mode > 0o777 ||
|
|
74
|
+
!("size" in entry) ||
|
|
75
|
+
typeof entry.size !== "number" ||
|
|
76
|
+
!Number.isSafeInteger(entry.size) ||
|
|
77
|
+
entry.size < 0 ||
|
|
78
|
+
!("sha256" in entry) ||
|
|
79
|
+
typeof entry.sha256 !== "string" ||
|
|
80
|
+
!/^[a-f0-9]{64}$/.test(entry.sha256))
|
|
81
|
+
throw new OutpostError("provider", "Invalid file manifest entry");
|
|
82
|
+
return {
|
|
83
|
+
path: entry.path,
|
|
84
|
+
kind: entry.kind,
|
|
85
|
+
mode: entry.mode,
|
|
86
|
+
size: entry.size,
|
|
87
|
+
sha256: entry.sha256,
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=file-manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-manifest.js","sourceRoot":"","sources":["../../src/infrastructure/file-manifest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,IAAY,EACZ,IAAY;IAEZ,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACjD,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE;QAC1C,MAAM,IAAI,YAAY,CAAC,UAAU,EAAE,gCAAgC,EAAE;YACnE,IAAI;SACL,CAAC,CAAC;IACL,MAAM,IAAI,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;IAClC,IAAI,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;IACrB,IAAI,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,QAAQ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AI,KAAK,QAAQ;YAC9B,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC;YAC7B,KAAK,CAAC,IAAI,GAAG,CAAC;YACd,KAAK,CAAC,IAAI,GAAG,KAAK;YAClB,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC;YAClB,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;YAC9B,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC;YACjC,KAAK,CAAC,IAAI,GAAG,CAAC;YACd,CAAC,CAAC,QAAQ,IAAI,KAAK,CAAC;YACpB,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ;YAChC,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;YAEpC,MAAM,IAAI,YAAY,CAAC,UAAU,EAAE,6BAA6B,CAAC,CAAC;QACpE,OAAO;YACL,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,MAAM,EAAE,KAAK,CAAC,MAAM;SACrB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { createReadStream } from \"node:fs\";\nimport { lstat, readlink } from \"node:fs/promises\";\nimport { OutpostError } from \"../domain/errors.ts\";\nimport type { FileManifestEntry } from \"../domain/sandbox.types.ts\";\nimport { safeDestination } from \"./files.ts\";\n\nexport async function fileManifest(\n root: string,\n path: string,\n): Promise<FileManifestEntry> {\n const target = await safeDestination(root, path);\n const info = await lstat(target);\n if (!info.isFile() && !info.isSymbolicLink())\n throw new OutpostError(\"provider\", \"Unsupported manifest file type\", {\n path,\n });\n const hash = createHash(\"sha256\");\n let size = info.size;\n if (info.isSymbolicLink()) {\n const value = Buffer.from(await readlink(target));\n size = value.length;\n hash.update(value);\n } else {\n for await (const chunk of createReadStream(target)) hash.update(chunk);\n }\n return {\n path,\n kind: info.isSymbolicLink() ? \"link\" : \"file\",\n mode: info.mode & 0o777,\n size,\n sha256: hash.digest(\"hex\"),\n };\n}\n\nexport function sameFile(\n left: FileManifestEntry,\n right: FileManifestEntry,\n): boolean {\n return (\n left.path === right.path &&\n left.kind === right.kind &&\n left.mode === right.mode &&\n left.size === right.size &&\n left.sha256 === right.sha256\n );\n}\n\nexport function sameLocalFile(\n remote: FileManifestEntry,\n local: FileManifestEntry,\n): boolean {\n if (process.platform !== \"win32\") return sameFile(remote, local);\n return sameFile(\n { ...remote, mode: remote.mode & 0o200 },\n { ...local, mode: local.mode & 0o200 },\n );\n}\n\nexport function validateFilePaths(paths: readonly string[]): void {\n if (\n new Set(paths).size !== paths.length ||\n paths.some(\n (path) =>\n !path ||\n path.includes(\"\\\\\") ||\n path.includes(\"\\0\") ||\n path\n .split(\"/\")\n .some(\n (part) =>\n !part ||\n part === \".\" ||\n part === \"..\" ||\n part.toLowerCase() === \".git\",\n ),\n )\n )\n throw new OutpostError(\"provider\", \"Unsafe or duplicate manifest path\");\n}\n\nexport function parseManifest(\n value: unknown,\n paths: readonly string[],\n): FileManifestEntry[] {\n validateFilePaths(paths);\n if (!Array.isArray(value) || value.length !== paths.length)\n throw new OutpostError(\"provider\", \"Invalid file manifest\");\n return value.map((entry: unknown, index) => {\n if (\n !entry ||\n typeof entry !== \"object\" ||\n !(\"path\" in entry) ||\n typeof entry.path !== \"string\" ||\n entry.path !== paths[index] ||\n !(\"kind\" in entry) ||\n (entry.kind !== \"file\" && entry.kind !== \"link\") ||\n !(\"mode\" in entry) ||\n typeof entry.mode !== \"number\" ||\n !Number.isInteger(entry.mode) ||\n entry.mode < 0 ||\n entry.mode > 0o777 ||\n !(\"size\" in entry) ||\n typeof entry.size !== \"number\" ||\n !Number.isSafeInteger(entry.size) ||\n entry.size < 0 ||\n !(\"sha256\" in entry) ||\n typeof entry.sha256 !== \"string\" ||\n !/^[a-f0-9]{64}$/.test(entry.sha256)\n )\n throw new OutpostError(\"provider\", \"Invalid file manifest entry\");\n return {\n path: entry.path,\n kind: entry.kind,\n mode: entry.mode,\n size: entry.size,\n sha256: entry.sha256,\n };\n });\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock-inspection.constants.js","sourceRoot":"","sources":["../../../src/infrastructure/git/lock-inspection.constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,QAAQ,EAAE,IAAI;IACd,MAAM,EAAE,aAAa;CACb,CAAC","sourcesContent":["export const lockInspectionDefaults = {\n maxBytes: 4096,\n maxPid: 2_147_483_647,\n} as const;\n"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { observeOwnership } from "./process-identity.js";
|
|
2
|
+
import { readInspectionFile } from "../inspection-file.js";
|
|
3
|
+
import { lockInspectionDefaults } from "./lock-inspection.constants.js";
|
|
4
|
+
async function readPid(path) {
|
|
5
|
+
const record = JSON.parse((await readInspectionFile(path, lockInspectionDefaults.maxBytes)).toString("utf8"));
|
|
6
|
+
if (!record || typeof record !== "object" || !("pid" in record))
|
|
7
|
+
return undefined;
|
|
8
|
+
const pid = record.pid;
|
|
9
|
+
if (typeof pid !== "number" ||
|
|
10
|
+
!Number.isInteger(pid) ||
|
|
11
|
+
pid <= 0 ||
|
|
12
|
+
pid > lockInspectionDefaults.maxPid)
|
|
13
|
+
return undefined;
|
|
14
|
+
return {
|
|
15
|
+
pid,
|
|
16
|
+
...("identity" in record ? { identity: record.identity } : {}),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
async function inspectEntry(entry, probe) {
|
|
20
|
+
if (entry.kind !== "file")
|
|
21
|
+
return { state: "skipped", reason: "NOT_FILE" };
|
|
22
|
+
let record;
|
|
23
|
+
try {
|
|
24
|
+
record = await readPid(entry.path);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return { state: "unknown", reason: "LOCK_READ_FAILED" };
|
|
28
|
+
}
|
|
29
|
+
if (record === undefined)
|
|
30
|
+
return { state: "unknown", reason: "INVALID_PID" };
|
|
31
|
+
const { pid, identity } = record;
|
|
32
|
+
const ownership = await observeOwnership(pid, identity);
|
|
33
|
+
try {
|
|
34
|
+
probe(pid);
|
|
35
|
+
return { state: "present", pid, ownership };
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (error &&
|
|
39
|
+
typeof error === "object" &&
|
|
40
|
+
"code" in error &&
|
|
41
|
+
error.code === "ESRCH")
|
|
42
|
+
return { state: "absent", pid, ownership };
|
|
43
|
+
return { state: "unknown", pid, reason: "PID_PROBE_FAILED", ownership };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export async function inspectLocks(entries, probe = (pid) => {
|
|
47
|
+
process.kill(pid, 0);
|
|
48
|
+
}) {
|
|
49
|
+
const locks = [];
|
|
50
|
+
const issues = [];
|
|
51
|
+
for (const entry of entries) {
|
|
52
|
+
const state = await inspectEntry(entry, probe);
|
|
53
|
+
locks.push({ name: entry.name, path: entry.path, ...state });
|
|
54
|
+
if (state.state === "unknown")
|
|
55
|
+
issues.push({ path: entry.path, code: state.reason });
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
scope: "local-pid",
|
|
59
|
+
complete: issues.length === 0,
|
|
60
|
+
entries: locks,
|
|
61
|
+
issues,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=lock-inspection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock-inspection.js","sourceRoot":"","sources":["../../../src/infrastructure/git/lock-inspection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AASxE,KAAK,UAAU,O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AC;IACD,OAAO;QACL,KAAK,EAAE,WAAW;QAClB,QAAQ,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;QAC7B,OAAO,EAAE,KAAK;QACd,MAAM;KACP,CAAC;AACJ,CAAC","sourcesContent":["import { observeOwnership } from \"./process-identity.ts\";\nimport { readInspectionFile } from \"../inspection-file.ts\";\nimport type { StorageEntry, StorageIssue } from \"../storage-inventory.types.ts\";\nimport { lockInspectionDefaults } from \"./lock-inspection.constants.ts\";\nimport type {\n LockIdentityRecord,\n LockInspection,\n LockInspectionEntry,\n LockInspectionState,\n LockPidProbe,\n} from \"./lock-inspection.types.ts\";\n\nasync function readPid(path: string): Promise<LockIdentityRecord | undefined> {\n const record: unknown = JSON.parse(\n (await readInspectionFile(path, lockInspectionDefaults.maxBytes)).toString(\n \"utf8\",\n ),\n );\n if (!record || typeof record !== \"object\" || !(\"pid\" in record))\n return undefined;\n const pid = record.pid;\n if (\n typeof pid !== \"number\" ||\n !Number.isInteger(pid) ||\n pid <= 0 ||\n pid > lockInspectionDefaults.maxPid\n )\n return undefined;\n return {\n pid,\n ...(\"identity\" in record ? { identity: record.identity } : {}),\n };\n}\n\nasync function inspectEntry(\n entry: StorageEntry,\n probe: LockPidProbe,\n): Promise<LockInspectionState> {\n if (entry.kind !== \"file\") return { state: \"skipped\", reason: \"NOT_FILE\" };\n let record: LockIdentityRecord | undefined;\n try {\n record = await readPid(entry.path);\n } catch {\n return { state: \"unknown\", reason: \"LOCK_READ_FAILED\" };\n }\n if (record === undefined) return { state: \"unknown\", reason: \"INVALID_PID\" };\n const { pid, identity } = record;\n const ownership = await observeOwnership(pid, identity);\n try {\n probe(pid);\n return { state: \"present\", pid, ownership };\n } catch (error) {\n if (\n error &&\n typeof error === \"object\" &&\n \"code\" in error &&\n error.code === \"ESRCH\"\n )\n return { state: \"absent\", pid, ownership };\n return { state: \"unknown\", pid, reason: \"PID_PROBE_FAILED\", ownership };\n }\n}\n\nexport async function inspectLocks(\n entries: readonly StorageEntry[],\n probe: LockPidProbe = (pid) => {\n process.kill(pid, 0);\n },\n): Promise<LockInspection> {\n const locks: LockInspectionEntry[] = [];\n const issues: StorageIssue[] = [];\n for (const entry of entries) {\n const state = await inspectEntry(entry, probe);\n locks.push({ name: entry.name, path: entry.path, ...state });\n if (state.state === \"unknown\")\n issues.push({ path: entry.path, code: state.reason });\n }\n return {\n scope: \"local-pid\",\n complete: issues.length === 0,\n entries: locks,\n issues,\n };\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { LockOwnership } from "./process-identity.types.ts";
|
|
2
|
+
import type { StorageEntry, StorageIssue } from "../storage-inventory.types.ts";
|
|
3
|
+
export type LockPidProbe = (pid: number) => void;
|
|
4
|
+
export interface LockIdentityRecord {
|
|
5
|
+
readonly pid: number;
|
|
6
|
+
readonly identity?: unknown;
|
|
7
|
+
}
|
|
8
|
+
export type LockInspectionState = {
|
|
9
|
+
readonly ownership?: LockOwnership;
|
|
10
|
+
} & ({
|
|
11
|
+
readonly state: "present" | "absent";
|
|
12
|
+
readonly pid: number;
|
|
13
|
+
} | {
|
|
14
|
+
readonly state: "unknown";
|
|
15
|
+
readonly reason: string;
|
|
16
|
+
readonly pid?: number;
|
|
17
|
+
} | {
|
|
18
|
+
readonly state: "skipped";
|
|
19
|
+
readonly reason: "NOT_FILE";
|
|
20
|
+
});
|
|
21
|
+
export type LockInspectionEntry = Pick<StorageEntry, "name" | "path"> & LockInspectionState;
|
|
22
|
+
export interface LockInspection {
|
|
23
|
+
readonly complete: boolean;
|
|
24
|
+
readonly scope: "local-pid";
|
|
25
|
+
readonly entries: readonly LockInspectionEntry[];
|
|
26
|
+
readonly issues: readonly StorageIssue[];
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock-inspection.types.js","sourceRoot":"","sources":["../../../src/infrastructure/git/lock-inspection.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { LockOwnership } from \"./process-identity.types.ts\";\nimport type { StorageEntry, StorageIssue } from \"../storage-inventory.types.ts\";\n\nexport type LockPidProbe = (pid: number) => void;\n\nexport interface LockIdentityRecord {\n readonly pid: number;\n readonly identity?: unknown;\n}\n\nexport type LockInspectionState = { readonly ownership?: LockOwnership } & (\n | { readonly state: \"present\" | \"absent\"; readonly pid: number }\n | {\n readonly state: \"unknown\";\n readonly reason: string;\n readonly pid?: number;\n }\n | { readonly state: \"skipped\"; readonly reason: \"NOT_FILE\" }\n);\n\nexport type LockInspectionEntry = Pick<StorageEntry, \"name\" | \"path\"> &\n LockInspectionState;\n\nexport interface LockInspection {\n readonly complete: boolean;\n readonly scope: \"local-pid\";\n readonly entries: readonly LockInspectionEntry[];\n readonly issues: readonly StorageIssue[];\n}\n"]}
|