@abelxiaoxing/cadence 1.8.4 → 2.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/README.md +324 -117
- package/THIRD_PARTY_NOTICES.md +15 -0
- package/agents/design-explorer.md +14 -18
- package/agents/diagnosis-worker.md +14 -14
- package/agents/implementation-worker.md +16 -17
- package/config/workflow-task.example.json +7 -0
- package/docs/remote-access.md +60 -0
- package/docs/reuse-and-distribution.md +44 -0
- package/docs/service-management.md +108 -0
- package/licenses/bundled-web.txt +6245 -0
- package/licenses/pi-web-ui-MIT.txt +21 -0
- package/licenses/pi-web-ui-reuse.md +22 -0
- package/package.json +94 -21
- package/src/index.ts +21 -1802
- package/src/native-build.ts +6 -0
- package/src/native-client.ts +103 -0
- package/src/native-export.ts +58 -0
- package/src/native-history.ts +359 -0
- package/src/operator-cli.mjs +453 -1937
- package/src/plan-proposal.ts +87 -0
- package/src/sdk-worker.mjs +549 -0
- package/src/service/contracts/active.ts +82 -0
- package/src/service/contracts/budget.ts +148 -0
- package/src/service/contracts/build.ts +67 -0
- package/src/service/contracts/capture.ts +48 -0
- package/src/service/contracts/core.ts +33 -0
- package/src/service/contracts/current.ts +261 -0
- package/src/service/contracts/domain.ts +68 -0
- package/src/service/contracts/history.ts +2245 -0
- package/src/service/contracts/models.ts +139 -0
- package/src/service/coordination.ts +862 -0
- package/src/service/private-files.ts +204 -0
- package/src/service-cli.mjs +5592 -0
- package/src/service-client.ts +747 -0
- package/src/service-contract.ts +245 -0
- package/src/service-host.mjs +22382 -0
- package/src/service-http-client.ts +425 -0
- package/src/service-wire.ts +372 -0
- package/src/task-shell.ts +1045 -0
- package/src/task-store.ts +479 -0
- package/src/task-types.ts +184 -0
- package/src/verification-diagnostics.ts +29 -72
- package/src/worker-capture.mjs +1197 -0
- package/src/worker-public.mjs +1753 -0
- package/src/worker-redaction.mjs +608 -0
- package/src/worker-tools.mjs +202 -0
- package/web/dist/assets/KaTeX_AMS-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_AMS-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_AMS-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Bold.ttf +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Bold.woff +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Bold.woff2 +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Bold.ttf +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Bold.woff +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Bold.woff2 +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Main-Bold.ttf +0 -0
- package/web/dist/assets/KaTeX_Main-Bold.woff +0 -0
- package/web/dist/assets/KaTeX_Main-Bold.woff2 +0 -0
- package/web/dist/assets/KaTeX_Main-BoldItalic.ttf +0 -0
- package/web/dist/assets/KaTeX_Main-BoldItalic.woff +0 -0
- package/web/dist/assets/KaTeX_Main-BoldItalic.woff2 +0 -0
- package/web/dist/assets/KaTeX_Main-Italic.ttf +0 -0
- package/web/dist/assets/KaTeX_Main-Italic.woff +0 -0
- package/web/dist/assets/KaTeX_Main-Italic.woff2 +0 -0
- package/web/dist/assets/KaTeX_Main-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Main-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Main-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Math-BoldItalic.ttf +0 -0
- package/web/dist/assets/KaTeX_Math-BoldItalic.woff +0 -0
- package/web/dist/assets/KaTeX_Math-BoldItalic.woff2 +0 -0
- package/web/dist/assets/KaTeX_Math-Italic.ttf +0 -0
- package/web/dist/assets/KaTeX_Math-Italic.woff +0 -0
- package/web/dist/assets/KaTeX_Math-Italic.woff2 +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Bold.ttf +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Bold.woff +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Bold.woff2 +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Italic.ttf +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Italic.woff +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Italic.woff2 +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Script-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Script-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Script-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Size1-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Size1-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Size1-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Size2-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Size2-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Size2-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Size3-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Size3-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Size3-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Size4-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Size4-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Size4-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Typewriter-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Typewriter-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Typewriter-Regular.woff2 +0 -0
- package/web/dist/assets/cadence.css +2 -0
- package/web/dist/assets/cadence.js +7 -0
- package/web/dist/assets/markdown.js +296 -0
- package/web/dist/assets/react.js +9 -0
- package/web/dist/assets/rolldown-runtime.js +1 -0
- package/web/dist/assets/timeline-client.js +41 -0
- package/web/dist/assets/vis-timeline.css +1274 -0
- package/web/dist/assets/vis-timeline.js +32 -0
- package/web/dist/index.html +18 -0
- package/web/dist/manifest.json +505 -0
- package/config/plan-draft.example.json +0 -125
- package/config/plan-draft.multiple-tasks.example.json +0 -375
- package/config/plan-draft.quick.example.json +0 -78
- package/prompts/abel-design.md +0 -382
- package/prompts/abel-diagnose.md +0 -71
- package/prompts/abel-implement.md +0 -284
- package/prompts/abel-init.md +0 -52
- package/src/activation.ts +0 -44
- package/src/activity-contracts.ts +0 -82
- package/src/agent-registry.ts +0 -53
- package/src/apply-transaction.ts +0 -1437
- package/src/artifact-store.ts +0 -213
- package/src/build-windows-job.mjs +0 -95
- package/src/candidate-artifact.ts +0 -143
- package/src/candidate-context.ts +0 -289
- package/src/candidate-patch.ts +0 -271
- package/src/candidate-workspace.ts +0 -80
- package/src/canonical.ts +0 -16
- package/src/change-contract-schema.ts +0 -191
- package/src/change-contract.ts +0 -324
- package/src/change-verification.ts +0 -1617
- package/src/contracts.ts +0 -2466
- package/src/control-contracts.ts +0 -382
- package/src/delivery-compiler.ts +0 -1805
- package/src/delivery-revision.ts +0 -42
- package/src/design-control.ts +0 -1299
- package/src/design-diagnostics.ts +0 -181
- package/src/design-journal.ts +0 -1773
- package/src/directory-sync.ts +0 -36
- package/src/durable-contracts.ts +0 -227
- package/src/durable-workflow.ts +0 -822
- package/src/evidence-draft.ts +0 -122
- package/src/execution-profile.ts +0 -64
- package/src/execution-retention.ts +0 -77
- package/src/file-snapshot.ts +0 -163
- package/src/implement-continuation.ts +0 -559
- package/src/implement-graph.ts +0 -690
- package/src/implement-plan.ts +0 -72
- package/src/install-config.d.mts +0 -6
- package/src/isolation-backend.ts +0 -353
- package/src/model-source.ts +0 -22
- package/src/openspec-cli.ts +0 -494
- package/src/operator-cli-entry.mjs +0 -24
- package/src/operator-tools.ts +0 -309
- package/src/package-candidate-process.ts +0 -206
- package/src/package-candidate.ts +0 -24
- package/src/package-delivery.ts +0 -486
- package/src/package-state.ts +0 -320
- package/src/package-verification.ts +0 -635
- package/src/package-workflow.ts +0 -305
- package/src/packet-runtime.ts +0 -459
- package/src/phase-execution.ts +0 -2163
- package/src/pi-adapter.ts +0 -19
- package/src/plan-draft-summary.ts +0 -527
- package/src/plan-draft.ts +0 -502
- package/src/remove-path.ts +0 -32
- package/src/run-state.ts +0 -420
- package/src/run-store.ts +0 -1179
- package/src/safe-path.ts +0 -77
- package/src/scoped-grep-worker.mjs +0 -23
- package/src/scoped-tools.ts +0 -775
- package/src/single-task-draft.ts +0 -142
- package/src/sqlite-schema.ts +0 -171
- package/src/state-root.ts +0 -215
- package/src/storage-schema.ts +0 -360
- package/src/subagent-activity.ts +0 -1417
- package/src/subagent-process.ts +0 -476
- package/src/task-ledger.ts +0 -1338
- package/src/transport-budget.ts +0 -50
- package/src/verification-capability.ts +0 -1191
- package/src/verification-environment-io.ts +0 -389
- package/src/verification-environment.ts +0 -162
- package/src/verification-identity.ts +0 -77
- package/src/verification-scan.ts +0 -64
- package/src/windows-job-backend.ts +0 -419
- package/src/windows-job.c +0 -149
- package/src/workflow-engine.ts +0 -28
- package/src/workflow-policy.ts +0 -1670
- package/src/workflow-recovery-policy.ts +0 -97
- package/src/workflow-scheduling.ts +0 -105
- package/src/workflow-state-machine.ts +0 -4341
- package/src/workflow-status.ts +0 -576
- package/src/workspace-io-entry.mjs +0 -76
- package/src/workspace-io-worker.mjs +0 -1312
- package/src/workspace-io.ts +0 -89
- package/src/workspace-store.ts +0 -634
package/src/implement-plan.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import type { ChangeContract } from "./change-contract.ts";
|
|
2
|
-
import type {
|
|
3
|
-
AgentsImpact,
|
|
4
|
-
ImplementGraphOutput,
|
|
5
|
-
ImplementTaskBoundary,
|
|
6
|
-
PhaseBoundary,
|
|
7
|
-
StructuredVerificationContract,
|
|
8
|
-
} from "./contracts.ts";
|
|
9
|
-
|
|
10
|
-
/** Complete execution contracts. No authoring references or defaults cross this boundary. */
|
|
11
|
-
export interface PlanTaskDraft extends Omit<ImplementTaskBoundary, "phases"> {
|
|
12
|
-
phases: {
|
|
13
|
-
red: PhaseBoundary;
|
|
14
|
-
green: PhaseBoundary;
|
|
15
|
-
refactor?: PhaseBoundary;
|
|
16
|
-
};
|
|
17
|
-
/** Explicit original-revision check. Absent only in retained legacy plans. */
|
|
18
|
-
baselineVerification?: StructuredVerificationContract;
|
|
19
|
-
affectedVerification: StructuredVerificationContract;
|
|
20
|
-
repairVerification: StructuredVerificationContract;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface PlanVerification {
|
|
24
|
-
baseline: {
|
|
25
|
-
target: "task-red-contracts";
|
|
26
|
-
affected: "task-affected-contracts";
|
|
27
|
-
fullSuite: StructuredVerificationContract;
|
|
28
|
-
failureIdentity: "normalized";
|
|
29
|
-
};
|
|
30
|
-
change: {
|
|
31
|
-
affected: "task-affected-contracts";
|
|
32
|
-
fullSuite: StructuredVerificationContract;
|
|
33
|
-
postApply: StructuredVerificationContract;
|
|
34
|
-
};
|
|
35
|
-
artifactCorrection: {
|
|
36
|
-
maxAttempts: number;
|
|
37
|
-
};
|
|
38
|
-
repair: {
|
|
39
|
-
maxAttempts: number;
|
|
40
|
-
inBoundaryOnly: true;
|
|
41
|
-
approvalOnBoundaryExpansion: true;
|
|
42
|
-
attribution: ["pre-existing", "introduced", "unresolved", "environment"];
|
|
43
|
-
};
|
|
44
|
-
agentsCheckpoint: {
|
|
45
|
-
required: boolean;
|
|
46
|
-
verification: StructuredVerificationContract | null;
|
|
47
|
-
operations: PlanAgentsCheckpointOperation[];
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export interface PlanAgentsCheckpointOperation {
|
|
52
|
-
target: string;
|
|
53
|
-
impact: Exclude<AgentsImpact, "none">;
|
|
54
|
-
taskIds: string[];
|
|
55
|
-
managedBlock: string | null;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface PlanTracking {
|
|
59
|
-
path: "tasks.md";
|
|
60
|
-
format: "markdown-checkbox";
|
|
61
|
-
taskIds: string[];
|
|
62
|
-
completionOwner: "parent";
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export interface ImplementPlan {
|
|
66
|
-
changeContract?: ChangeContract;
|
|
67
|
-
changeId: string;
|
|
68
|
-
tasks: PlanTaskDraft[];
|
|
69
|
-
outputs: ImplementGraphOutput[];
|
|
70
|
-
verification: PlanVerification;
|
|
71
|
-
tracking: PlanTracking;
|
|
72
|
-
}
|
package/src/install-config.d.mts
DELETED
package/src/isolation-backend.ts
DELETED
|
@@ -1,353 +0,0 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
|
-
import { accessSync, constants, lstatSync } from "node:fs";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
|
|
5
|
-
export interface IsolationMount {
|
|
6
|
-
source: string;
|
|
7
|
-
target: string;
|
|
8
|
-
writable?: boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface IsolationRunInput {
|
|
12
|
-
root: string;
|
|
13
|
-
executable: string;
|
|
14
|
-
args?: string[];
|
|
15
|
-
mounts?: IsolationMount[];
|
|
16
|
-
environment?: Record<string, string>;
|
|
17
|
-
signal?: AbortSignal;
|
|
18
|
-
outputWitness?: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export type IsolationRunResult =
|
|
22
|
-
| {
|
|
23
|
-
ok: true;
|
|
24
|
-
state: "completed";
|
|
25
|
-
exitCode: number;
|
|
26
|
-
stdout: string;
|
|
27
|
-
stderr: string;
|
|
28
|
-
outputWitnessMatched?: boolean;
|
|
29
|
-
logs: {
|
|
30
|
-
stdout: { bytes: number; truncated: boolean };
|
|
31
|
-
stderr: { bytes: number; truncated: boolean };
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
| {
|
|
35
|
-
ok: false;
|
|
36
|
-
state: "paused";
|
|
37
|
-
code:
|
|
38
|
-
| "isolation-backend-unavailable"
|
|
39
|
-
| "isolation-backend-launch-failed"
|
|
40
|
-
| "isolation-termination-unconfirmed"
|
|
41
|
-
| "isolation-execution-timeout";
|
|
42
|
-
}
|
|
43
|
-
| { ok: false; state: "cancelled"; code: "cancelled" };
|
|
44
|
-
|
|
45
|
-
export const ISOLATION_RUN_LIMITS = Object.freeze({
|
|
46
|
-
timeoutMs: 10 * 60_000,
|
|
47
|
-
maxOutputBytes: 256 * 1024,
|
|
48
|
-
terminateGraceMs: 1_000,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
export interface BubblewrapIsolationOptions {
|
|
52
|
-
bwrapPath?: string;
|
|
53
|
-
probe?: (path: string) => boolean | Promise<boolean>;
|
|
54
|
-
spawnProcess?: typeof spawn;
|
|
55
|
-
timeoutMs?: number;
|
|
56
|
-
maxOutputBytes?: number;
|
|
57
|
-
terminateGraceMs?: number;
|
|
58
|
-
/** Explicit operator opt-in; never an availability fallback. */
|
|
59
|
-
localTrusted?: boolean;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function defaultProbe(executable: string): boolean {
|
|
63
|
-
try {
|
|
64
|
-
accessSync(executable, constants.X_OK);
|
|
65
|
-
return true;
|
|
66
|
-
} catch {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function validEnvironmentName(name: string): boolean {
|
|
72
|
-
return /^[A-Za-z_][A-Za-z0-9_]*$/u.test(name);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** Retains independent head/tail copies; discarded chunks never stay referenced. */
|
|
76
|
-
export class BoundedLog {
|
|
77
|
-
bytes = 0;
|
|
78
|
-
#head = Buffer.alloc(0);
|
|
79
|
-
#tail = Buffer.alloc(0);
|
|
80
|
-
readonly limit: number;
|
|
81
|
-
readonly #witness?: Buffer;
|
|
82
|
-
#witnessTail = Buffer.alloc(0);
|
|
83
|
-
witnessMatched = false;
|
|
84
|
-
constructor(limit: number, witness?: string) {
|
|
85
|
-
this.limit = limit;
|
|
86
|
-
if (witness) this.#witness = Buffer.from(witness);
|
|
87
|
-
}
|
|
88
|
-
append(chunk: Buffer | string): void {
|
|
89
|
-
const input = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
90
|
-
this.bytes += input.byteLength;
|
|
91
|
-
if (this.#witness && !this.witnessMatched) {
|
|
92
|
-
const searchable = Buffer.concat([this.#witnessTail, input]);
|
|
93
|
-
this.witnessMatched = searchable.includes(this.#witness);
|
|
94
|
-
this.#witnessTail = this.witnessMatched
|
|
95
|
-
? Buffer.alloc(0)
|
|
96
|
-
: Buffer.from(
|
|
97
|
-
searchable.subarray(
|
|
98
|
-
Math.max(0, searchable.length - this.#witness.length + 1),
|
|
99
|
-
),
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
const headLimit = Math.ceil(this.limit / 2);
|
|
103
|
-
const take = Math.min(input.length, headLimit - this.#head.length);
|
|
104
|
-
if (take > 0)
|
|
105
|
-
this.#head = Buffer.concat([this.#head, input.subarray(0, take)]);
|
|
106
|
-
const rest = input.subarray(take);
|
|
107
|
-
const tailLimit = this.limit - headLimit;
|
|
108
|
-
if (rest.length && tailLimit) {
|
|
109
|
-
this.#tail =
|
|
110
|
-
rest.length >= tailLimit
|
|
111
|
-
? Buffer.from(rest.subarray(-tailLimit))
|
|
112
|
-
: Buffer.concat([
|
|
113
|
-
this.#tail.subarray(
|
|
114
|
-
Math.max(0, this.#tail.length + rest.length - tailLimit),
|
|
115
|
-
),
|
|
116
|
-
rest,
|
|
117
|
-
]);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
text(): string {
|
|
121
|
-
return Buffer.concat([this.#head, this.#tail]).toString("utf8");
|
|
122
|
-
}
|
|
123
|
-
metadata() {
|
|
124
|
-
return { bytes: this.bytes, truncated: this.bytes > this.limit };
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/** Linux isolation capability. Lack of Bubblewrap is a pause, never a fallback. */
|
|
129
|
-
export class BubblewrapIsolationBackend {
|
|
130
|
-
readonly #localTrusted: boolean;
|
|
131
|
-
readonly #bwrapPath: string;
|
|
132
|
-
readonly #probe: (path: string) => boolean | Promise<boolean>;
|
|
133
|
-
readonly #spawn: typeof spawn;
|
|
134
|
-
readonly #timeoutMs: number;
|
|
135
|
-
readonly #maxOutputBytes: number;
|
|
136
|
-
readonly #terminateGraceMs: number;
|
|
137
|
-
|
|
138
|
-
constructor(options: BubblewrapIsolationOptions = {}) {
|
|
139
|
-
this.#localTrusted = options.localTrusted === true;
|
|
140
|
-
this.#bwrapPath = options.bwrapPath ?? "/usr/bin/bwrap";
|
|
141
|
-
this.#probe = options.probe ?? defaultProbe;
|
|
142
|
-
this.#spawn = options.spawnProcess ?? spawn;
|
|
143
|
-
this.#timeoutMs = options.timeoutMs ?? ISOLATION_RUN_LIMITS.timeoutMs;
|
|
144
|
-
this.#maxOutputBytes =
|
|
145
|
-
options.maxOutputBytes ?? ISOLATION_RUN_LIMITS.maxOutputBytes;
|
|
146
|
-
this.#terminateGraceMs =
|
|
147
|
-
options.terminateGraceMs ?? ISOLATION_RUN_LIMITS.terminateGraceMs;
|
|
148
|
-
if (
|
|
149
|
-
!Number.isSafeInteger(this.#timeoutMs) ||
|
|
150
|
-
this.#timeoutMs < 1 ||
|
|
151
|
-
!Number.isSafeInteger(this.#maxOutputBytes) ||
|
|
152
|
-
this.#maxOutputBytes < 1 ||
|
|
153
|
-
!Number.isSafeInteger(this.#terminateGraceMs) ||
|
|
154
|
-
this.#terminateGraceMs < 1
|
|
155
|
-
) {
|
|
156
|
-
throw new Error("isolation-run-limits-invalid");
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
async available(): Promise<boolean> {
|
|
161
|
-
try {
|
|
162
|
-
if (this.#localTrusted && process.platform !== "linux") return false;
|
|
163
|
-
return Boolean(await this.#probe(this.#bwrapPath));
|
|
164
|
-
} catch {
|
|
165
|
-
return false;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
async run(input: IsolationRunInput): Promise<IsolationRunResult> {
|
|
170
|
-
if (
|
|
171
|
-
input.outputWitness !== undefined &&
|
|
172
|
-
(typeof input.outputWitness !== "string" ||
|
|
173
|
-
input.outputWitness.length < 1 ||
|
|
174
|
-
input.outputWitness.length > 512)
|
|
175
|
-
)
|
|
176
|
-
throw new Error("isolation-output-witness-invalid");
|
|
177
|
-
if (!(await this.available())) {
|
|
178
|
-
return {
|
|
179
|
-
ok: false,
|
|
180
|
-
state: "paused",
|
|
181
|
-
code: "isolation-backend-unavailable",
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
if (input.signal?.aborted) {
|
|
185
|
-
return { ok: false, state: "cancelled", code: "cancelled" };
|
|
186
|
-
}
|
|
187
|
-
const root = path.resolve(input.root);
|
|
188
|
-
const rootStat = lstatSync(root, { throwIfNoEntry: false });
|
|
189
|
-
if (!rootStat?.isDirectory() || rootStat.isSymbolicLink()) {
|
|
190
|
-
throw new Error("isolation-root-invalid");
|
|
191
|
-
}
|
|
192
|
-
// Trusted mode shares host files/network, but still needs a PID namespace:
|
|
193
|
-
// process groups alone cannot contain detached descendants. No fallback.
|
|
194
|
-
const argv = this.#localTrusted
|
|
195
|
-
? [
|
|
196
|
-
"--die-with-parent",
|
|
197
|
-
"--new-session",
|
|
198
|
-
"--unshare-pid",
|
|
199
|
-
"--bind",
|
|
200
|
-
"/",
|
|
201
|
-
"/",
|
|
202
|
-
"--proc",
|
|
203
|
-
"/proc",
|
|
204
|
-
"--dev",
|
|
205
|
-
"/dev",
|
|
206
|
-
"--chdir",
|
|
207
|
-
root,
|
|
208
|
-
"--clearenv",
|
|
209
|
-
]
|
|
210
|
-
: [
|
|
211
|
-
"--die-with-parent",
|
|
212
|
-
"--new-session",
|
|
213
|
-
"--unshare-all",
|
|
214
|
-
"--proc",
|
|
215
|
-
"/proc",
|
|
216
|
-
"--dev",
|
|
217
|
-
"/dev",
|
|
218
|
-
"--tmpfs",
|
|
219
|
-
"/tmp",
|
|
220
|
-
"--bind",
|
|
221
|
-
root,
|
|
222
|
-
"/workspace",
|
|
223
|
-
"--chdir",
|
|
224
|
-
"/workspace",
|
|
225
|
-
"--clearenv",
|
|
226
|
-
"--setenv",
|
|
227
|
-
"PATH",
|
|
228
|
-
"/usr/local/bin:/usr/bin:/bin",
|
|
229
|
-
];
|
|
230
|
-
if (!this.#localTrusted) {
|
|
231
|
-
for (const systemRoot of ["/usr", "/bin", "/lib", "/lib64"]) {
|
|
232
|
-
if (lstatSync(systemRoot, { throwIfNoEntry: false }))
|
|
233
|
-
argv.push("--ro-bind", systemRoot, systemRoot);
|
|
234
|
-
}
|
|
235
|
-
for (const mount of input.mounts ?? []) {
|
|
236
|
-
if (!path.isAbsolute(mount.source) || !path.isAbsolute(mount.target))
|
|
237
|
-
throw new Error("isolation-mount-invalid");
|
|
238
|
-
argv.push(
|
|
239
|
-
mount.writable ? "--bind" : "--ro-bind",
|
|
240
|
-
mount.source,
|
|
241
|
-
mount.target,
|
|
242
|
-
);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
for (const [name, value] of Object.entries(
|
|
246
|
-
input.environment ?? {},
|
|
247
|
-
).sort()) {
|
|
248
|
-
if (!validEnvironmentName(name) || value.includes("\0"))
|
|
249
|
-
throw new Error("isolation-environment-invalid");
|
|
250
|
-
argv.push("--setenv", name, value);
|
|
251
|
-
}
|
|
252
|
-
argv.push("--", input.executable, ...(input.args ?? []));
|
|
253
|
-
|
|
254
|
-
return new Promise((resolve) => {
|
|
255
|
-
let settled = false;
|
|
256
|
-
const stdout = new BoundedLog(this.#maxOutputBytes, input.outputWitness);
|
|
257
|
-
const stderr = new BoundedLog(this.#maxOutputBytes, input.outputWitness);
|
|
258
|
-
let child: ReturnType<typeof spawn>;
|
|
259
|
-
let executionTimer: ReturnType<typeof setTimeout> | undefined;
|
|
260
|
-
let killTimer: ReturnType<typeof setTimeout> | undefined;
|
|
261
|
-
let terminationResult: IsolationRunResult | undefined;
|
|
262
|
-
const settle = (result: IsolationRunResult): void => {
|
|
263
|
-
if (settled) return;
|
|
264
|
-
settled = true;
|
|
265
|
-
if (executionTimer) clearTimeout(executionTimer);
|
|
266
|
-
input.signal?.removeEventListener("abort", abort);
|
|
267
|
-
resolve(result);
|
|
268
|
-
};
|
|
269
|
-
const kill = (signal: NodeJS.Signals) => {
|
|
270
|
-
child?.kill(signal);
|
|
271
|
-
};
|
|
272
|
-
const terminate = (result: IsolationRunResult): void => {
|
|
273
|
-
if (settled || terminationResult) return;
|
|
274
|
-
terminationResult = result;
|
|
275
|
-
if (executionTimer) clearTimeout(executionTimer);
|
|
276
|
-
killTimer = setTimeout(() => kill("SIGKILL"), this.#terminateGraceMs);
|
|
277
|
-
killTimer.unref?.();
|
|
278
|
-
kill("SIGTERM");
|
|
279
|
-
};
|
|
280
|
-
const abort = (): void => {
|
|
281
|
-
terminate({ ok: false, state: "cancelled", code: "cancelled" });
|
|
282
|
-
};
|
|
283
|
-
try {
|
|
284
|
-
child = this.#spawn(this.#bwrapPath, argv, {
|
|
285
|
-
cwd: root,
|
|
286
|
-
shell: false,
|
|
287
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
288
|
-
});
|
|
289
|
-
} catch {
|
|
290
|
-
settle({
|
|
291
|
-
ok: false,
|
|
292
|
-
state: "paused",
|
|
293
|
-
code: "isolation-backend-launch-failed",
|
|
294
|
-
});
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
const capture = (
|
|
298
|
-
destination: BoundedLog,
|
|
299
|
-
chunk: Buffer | string,
|
|
300
|
-
): void => {
|
|
301
|
-
if (!settled && !terminationResult) destination.append(chunk);
|
|
302
|
-
};
|
|
303
|
-
child.stdout?.on("data", (chunk: Buffer | string) => {
|
|
304
|
-
capture(stdout, chunk);
|
|
305
|
-
});
|
|
306
|
-
child.stderr?.on("data", (chunk: Buffer | string) => {
|
|
307
|
-
capture(stderr, chunk);
|
|
308
|
-
});
|
|
309
|
-
child.once("error", () => {
|
|
310
|
-
if (terminationResult) return;
|
|
311
|
-
settle({
|
|
312
|
-
ok: false,
|
|
313
|
-
state: "paused",
|
|
314
|
-
code: "isolation-backend-launch-failed",
|
|
315
|
-
});
|
|
316
|
-
});
|
|
317
|
-
child.once("close", (code) => {
|
|
318
|
-
if (killTimer) clearTimeout(killTimer);
|
|
319
|
-
settle(
|
|
320
|
-
terminationResult ?? {
|
|
321
|
-
ok: true,
|
|
322
|
-
state: "completed",
|
|
323
|
-
exitCode: code ?? 1,
|
|
324
|
-
stdout: stdout.text(),
|
|
325
|
-
stderr: stderr.text(),
|
|
326
|
-
logs: { stdout: stdout.metadata(), stderr: stderr.metadata() },
|
|
327
|
-
...(input.outputWitness
|
|
328
|
-
? {
|
|
329
|
-
outputWitnessMatched:
|
|
330
|
-
stdout.witnessMatched || stderr.witnessMatched,
|
|
331
|
-
}
|
|
332
|
-
: {}),
|
|
333
|
-
},
|
|
334
|
-
);
|
|
335
|
-
});
|
|
336
|
-
input.signal?.addEventListener("abort", abort, { once: true });
|
|
337
|
-
if (input.signal?.aborted) {
|
|
338
|
-
abort();
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
executionTimer = setTimeout(
|
|
342
|
-
() =>
|
|
343
|
-
terminate({
|
|
344
|
-
ok: false,
|
|
345
|
-
state: "paused",
|
|
346
|
-
code: "isolation-execution-timeout",
|
|
347
|
-
}),
|
|
348
|
-
this.#timeoutMs,
|
|
349
|
-
);
|
|
350
|
-
executionTimer.unref?.();
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
}
|
package/src/model-source.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { Model, Provider } from "@earendil-works/pi-ai";
|
|
2
|
-
|
|
3
|
-
/** Code-owned capability boundary. No session events, tools, UI or host context. */
|
|
4
|
-
export interface ParentModelSource {
|
|
5
|
-
readonly model?: Model<string>;
|
|
6
|
-
readonly modelRegistry: {
|
|
7
|
-
getProvider(id: string): Provider | undefined;
|
|
8
|
-
getApiKeyAndHeaders(model: Model<string>): Promise<
|
|
9
|
-
| {
|
|
10
|
-
ok: true;
|
|
11
|
-
apiKey?: string;
|
|
12
|
-
headers?: Record<string, string | null>;
|
|
13
|
-
baseUrl?: string;
|
|
14
|
-
env?: Record<string, string>;
|
|
15
|
-
}
|
|
16
|
-
| { ok: false }
|
|
17
|
-
>;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
export interface PackageContext extends ParentModelSource {
|
|
21
|
-
readonly cwd: string;
|
|
22
|
-
}
|