zapagent 1.14.11 → 1.14.13
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/bundled-dependencies.json +201 -201
- package/package.json +1 -1
- package/src/agent-factory.ts +6 -3
- package/src/commands/dispatcher.ts +10 -0
- package/src/commands.ts +4 -0
- package/src/execution-environment.ts +1 -1
- package/src/goal-command.ts +173 -0
- package/src/goal-host.ts +408 -0
- package/src/goal-runner.ts +31 -0
- package/src/headless/goal-npm-install.ts +96 -0
- package/src/headless/goalPhase.ts +380 -0
- package/src/headless/runHeadless.ts +56 -4
- package/src/hooks/useTurnDispatcher.ts +3 -0
- package/src/index.tsx +17 -0
- package/src/ui/slash-palette.tsx +1 -0
- package/zapsdk/agent/loop.ts +13 -2
- package/zapsdk/agent/subagent-assembly.ts +5 -0
- package/zapsdk/agent/tool-execution-guards.ts +30 -17
- package/zapsdk/builtin-tools/command.ts +11 -0
- package/zapsdk/builtin-tools/subagent.ts +10 -3
- package/zapsdk/core/llm.ts +2 -0
- package/zapsdk/core/retry.ts +3 -0
- package/zapsdk/execution/broker.ts +18 -1
- package/zapsdk/execution/goal-workspace-gate.ts +95 -0
- package/zapsdk/execution/required-process-seal.ts +35 -0
- package/zapsdk/execution/types.ts +8 -0
- package/zapsdk/execution/workspace-runtime.ts +6 -0
- package/zapsdk/execution/zapvm.ts +117 -15
- package/zapsdk/goal/acceptance.ts +139 -0
- package/zapsdk/goal/budget.ts +406 -0
- package/zapsdk/goal/contracts.ts +93 -0
- package/zapsdk/goal/controller.ts +234 -0
- package/zapsdk/goal/errors.ts +17 -0
- package/zapsdk/goal/git-history-snapshot.ts +210 -0
- package/zapsdk/goal/git-operation-owner.ts +64 -0
- package/zapsdk/goal/metered-provider.ts +80 -0
- package/zapsdk/goal/npm-installer.ts +362 -0
- package/zapsdk/goal/scheduler.ts +34 -0
- package/zapsdk/goal/store.ts +173 -0
- package/zapsdk/goal/structured-output.ts +84 -0
- package/zapsdk/goal/workspace-broker.ts +11 -0
- package/zapsdk/goal/workspace.ts +425 -0
- package/zapsdk/policy/types.ts +4 -0
- package/zapsdk/runtime/factory.ts +7 -0
- package/zapsdk/scheduler/batch-scheduler.ts +2 -2
- package/zapsdk/tools/executor.ts +79 -6
- package/zapsdk/tools/types.ts +2 -0
- package/zapsdk/workspace/context.ts +8 -4
- package/zapsdk/workspace/copy.ts +14 -1
- package/zapsdk/workspace/manager.ts +67 -3
- package/zapsdk/workspace/types.ts +11 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { OutcomeProtocolError } from "../runtime/outcome.js";
|
|
3
|
+
|
|
4
|
+
export class GoalStructuredOutputError extends OutcomeProtocolError {
|
|
5
|
+
constructor() { super("GOAL_STRUCTURED_OUTPUT_INVALID", "GOAL_STRUCTURED_OUTPUT_INVALID: result is missing, ambiguous or fails its schema"); }
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function parseUniqueKeys(text: string): unknown {
|
|
9
|
+
const stack: Set<string>[] = [];
|
|
10
|
+
let start = -1, escaped = false;
|
|
11
|
+
for (let i = 0; i < text.length; i++) {
|
|
12
|
+
const char = text[i];
|
|
13
|
+
if (start >= 0) {
|
|
14
|
+
if (escaped) { escaped = false; continue; }
|
|
15
|
+
if (char === "\\") { escaped = true; continue; }
|
|
16
|
+
if (char === '\"') {
|
|
17
|
+
let next = i + 1; while (/\s/.test(text[next] ?? "") && next < text.length) next++;
|
|
18
|
+
if (text[next] === ":") {
|
|
19
|
+
const key = JSON.parse(text.slice(start, i + 1)) as string, keys = stack.at(-1);
|
|
20
|
+
if (!keys || keys.has(key)) throw new GoalStructuredOutputError();
|
|
21
|
+
keys.add(key);
|
|
22
|
+
}
|
|
23
|
+
start = -1;
|
|
24
|
+
}
|
|
25
|
+
} else if (char === '\"') start = i;
|
|
26
|
+
else if (char === "{") stack.push(new Set());
|
|
27
|
+
else if (char === "}") stack.pop();
|
|
28
|
+
}
|
|
29
|
+
return JSON.parse(text);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Extract a single balanced object, ignoring braces inside JSON strings.
|
|
33
|
+
* Surrounding prose/fences are tolerated; multiple objects never select a winner. */
|
|
34
|
+
export function parseGoalObject<T>(text: string, schema: z.ZodType<T>): T {
|
|
35
|
+
if (text.length > 1024 * 1024) throw new GoalStructuredOutputError();
|
|
36
|
+
const objects: string[] = [];
|
|
37
|
+
let start = -1, depth = 0, quoted = false, escaped = false;
|
|
38
|
+
for (let i = 0; i < text.length; i++) {
|
|
39
|
+
const char = text[i];
|
|
40
|
+
if (start < 0) { if (char === "{") { start = i; depth = 1; } continue; }
|
|
41
|
+
if (quoted) {
|
|
42
|
+
if (escaped) escaped = false;
|
|
43
|
+
else if (char === "\\") escaped = true;
|
|
44
|
+
else if (char === '"') quoted = false;
|
|
45
|
+
} else if (char === '"') quoted = true;
|
|
46
|
+
else if (char === "{") depth++;
|
|
47
|
+
else if (char === "}" && --depth === 0) { objects.push(text.slice(start, i + 1)); start = -1; }
|
|
48
|
+
}
|
|
49
|
+
if (start >= 0 || objects.length !== 1) throw new GoalStructuredOutputError();
|
|
50
|
+
// A whole JSON value (e.g. an array containing an object) must not be
|
|
51
|
+
// reinterpreted as prose around an otherwise valid inner object.
|
|
52
|
+
const trimmed = text.trim();
|
|
53
|
+
if (trimmed.startsWith("[")) throw new GoalStructuredOutputError();
|
|
54
|
+
try { return schema.parse(parseUniqueKeys(objects[0]!)); }
|
|
55
|
+
catch { throw new GoalStructuredOutputError(); }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const goalPlanSchema = z.strictObject({ tasks: z.array(z.strictObject({
|
|
59
|
+
id: z.string().regex(/^[a-zA-Z0-9_-]{1,80}$/), description: z.string().trim().min(1),
|
|
60
|
+
acceptance: z.string().trim().min(1), dependencies: z.array(z.string()).optional(),
|
|
61
|
+
})).min(1).max(64) }).superRefine((plan, ctx) => {
|
|
62
|
+
const tasks = new Map(plan.tasks.map(task => [task.id, task]));
|
|
63
|
+
const done = new Set<string>(), visiting = new Set<string>();
|
|
64
|
+
const visit = (id: string): boolean => {
|
|
65
|
+
if (done.has(id)) return true;
|
|
66
|
+
const task = tasks.get(id);
|
|
67
|
+
if (!task || visiting.has(id)) return false;
|
|
68
|
+
visiting.add(id);
|
|
69
|
+
for (const dep of task.dependencies ?? []) if (!visit(dep)) return false;
|
|
70
|
+
visiting.delete(id); done.add(id); return true;
|
|
71
|
+
};
|
|
72
|
+
if (tasks.size !== plan.tasks.length || plan.tasks.some(task => !visit(task.id))) ctx.addIssue({ code: "custom", message: "Invalid task DAG" });
|
|
73
|
+
});
|
|
74
|
+
export const goalVerdictSchema = z.strictObject({ status: z.enum(["passed", "failed", "unverified"]), detail: z.string().trim().min(1).max(8000) });
|
|
75
|
+
|
|
76
|
+
/** Only schema failures are retried. The caller supplies a fresh sealed,
|
|
77
|
+
* metered read-only phase each time; execution/permission errors propagate. */
|
|
78
|
+
export async function readGoalStructuredResult<T>(run: (correction: string) => Promise<string>, schema: z.ZodType<T>): Promise<T> {
|
|
79
|
+
for (let attempt = 0; ; attempt++) {
|
|
80
|
+
const text = await run(attempt === 0 ? "" : "\n\nYour previous result failed the required JSON schema. Return exactly the requested JSON object, without commentary or examples. Do not perform development work.");
|
|
81
|
+
try { return parseGoalObject(text, schema); }
|
|
82
|
+
catch (error) { if (!(error instanceof GoalStructuredOutputError) || attempt >= 2) throw error; }
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ToolResult } from "../tools/types.js";
|
|
2
|
+
import type { GoalVerifierWorkspace } from "./workspace.js";
|
|
3
|
+
|
|
4
|
+
/** Host machine checks remain unavailable until the platform can establish
|
|
5
|
+
* that every descendant stopped. Process groups and OS filesystem/network
|
|
6
|
+
* sandboxes do not prevent a command from forking and calling setsid(). */
|
|
7
|
+
export function createGoalVerifierCommandRunner(_workspace: GoalVerifierWorkspace, _options: { network?: boolean; timeoutMs?: number } = {}) {
|
|
8
|
+
return async (_command: string, _signal?: AbortSignal): Promise<ToolResult> => {
|
|
9
|
+
throw new Error("GOAL_VERIFIER_PROCESS_SEAL_UNSUPPORTED");
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { execFile } from "node:child_process";
|
|
3
|
+
import { cp, lstat, mkdir, mkdtemp, readFile, readdir, readlink, realpath, rm } from "node:fs/promises";
|
|
4
|
+
import { basename, dirname, isAbsolute, join, relative, sep } from "node:path";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
import { MergeCoordinator } from "../merge/coordinator.js";
|
|
7
|
+
import { WorkspaceManager } from "../workspace/manager.js";
|
|
8
|
+
import { isWithin, workspaceContext } from "../workspace/context.js";
|
|
9
|
+
import { materializeCopyTree, removeOwnedCopyTree, scanCopyTree } from "../workspace/copy.js";
|
|
10
|
+
import type { AgentArtifact, MergeResult, WorkspaceLease } from "../workspace/types.js";
|
|
11
|
+
import { assertGoalAcceptance, assertGoalFinalAcceptance, type GoalAcceptanceReceipt, type GoalFinalAcceptanceReceipt } from "./acceptance.js";
|
|
12
|
+
import type { InlineAcceptanceStore } from "../runtime/inline-acceptance.js";
|
|
13
|
+
import { validateOutcome, type AgentOutcomeV1 } from "../runtime/outcome.js";
|
|
14
|
+
import { capturePrivateGitHistory, assertPrivateGitHistoryMatches } from "./git-history-snapshot.js";
|
|
15
|
+
import { withPersistentGitOperation } from "./git-operation-owner.js";
|
|
16
|
+
|
|
17
|
+
const exec = promisify(execFile);
|
|
18
|
+
|
|
19
|
+
/** A content fingerprint of an already isolated tree. It never follows symlinks.
|
|
20
|
+
* This is an integrity check, not a substitute for filesystem sandboxing. */
|
|
21
|
+
export async function goalTreeHash(root: string, ignored: readonly string[] = []): Promise<string> {
|
|
22
|
+
const hash = createHash("sha256");
|
|
23
|
+
const normalized = ignored.map(path => {
|
|
24
|
+
if (!path || isAbsolute(path) || path.includes("\\") || path.split("/").some(p => !p || p === "." || p === "..") || path === ".git") {
|
|
25
|
+
throw new Error("Invalid verifier generated path");
|
|
26
|
+
}
|
|
27
|
+
return path.replace(/\/$/, "");
|
|
28
|
+
});
|
|
29
|
+
async function visit(rel: string): Promise<void> {
|
|
30
|
+
for (const name of (await readdir(join(root, rel))).sort()) {
|
|
31
|
+
const path = rel ? `${rel}/${name}` : name;
|
|
32
|
+
if (path === ".git" || normalized.some(p => path === p || path.startsWith(`${p}/`))) continue;
|
|
33
|
+
const full = join(root, path);
|
|
34
|
+
const before = await lstat(full);
|
|
35
|
+
let kind: string;
|
|
36
|
+
let value = "";
|
|
37
|
+
if (before.isSymbolicLink()) { kind = "link"; value = await readlink(full); }
|
|
38
|
+
else if (before.isDirectory()) kind = "dir";
|
|
39
|
+
else if (before.isFile()) { kind = "file"; value = createHash("sha256").update(await readFile(full)).digest("hex"); }
|
|
40
|
+
else throw new Error(`Unsupported workspace entry: ${path}`);
|
|
41
|
+
const after = await lstat(full);
|
|
42
|
+
if (before.ino !== after.ino || before.size !== after.size || before.mtimeMs !== after.mtimeMs || before.mode !== after.mode) {
|
|
43
|
+
throw new Error(`Workspace changed while fingerprinting: ${path}`);
|
|
44
|
+
}
|
|
45
|
+
hash.update(JSON.stringify([path, kind, before.mode & 0o777, value]));
|
|
46
|
+
hash.update("\n");
|
|
47
|
+
if (kind === "dir") await visit(path);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
await visit("");
|
|
51
|
+
return hash.digest("hex");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface GoalWorkspaceCandidate {
|
|
55
|
+
goalId: string;
|
|
56
|
+
candidateId: string;
|
|
57
|
+
attemptId: string;
|
|
58
|
+
artifact: AgentArtifact;
|
|
59
|
+
snapshotPath: string;
|
|
60
|
+
treeHash: string;
|
|
61
|
+
integrationHash: string;
|
|
62
|
+
/** Isolated commits remain private; file delivery never updates user refs. */
|
|
63
|
+
privateHistory?: { repository: string; treeHash: string };
|
|
64
|
+
}
|
|
65
|
+
export interface GoalWorker {
|
|
66
|
+
lease: WorkspaceLease;
|
|
67
|
+
integrationHash: string;
|
|
68
|
+
}
|
|
69
|
+
export interface GoalWorkspaceState {
|
|
70
|
+
version: 1;
|
|
71
|
+
goalId: string;
|
|
72
|
+
root: string;
|
|
73
|
+
hostDir: string;
|
|
74
|
+
integrationPath: string;
|
|
75
|
+
baseLease: WorkspaceLease;
|
|
76
|
+
baseTreeHash: string;
|
|
77
|
+
/** Private history is for isolated development only; delivery is file-only. */
|
|
78
|
+
privateGit?: { ownerDirectory: string; snapshotRepository: string; treeHash: string };
|
|
79
|
+
worker?: GoalWorker;
|
|
80
|
+
workerOwnerRunId?: string;
|
|
81
|
+
candidate?: GoalWorkspaceCandidate;
|
|
82
|
+
previous?: Array<{ worker: GoalWorker; candidate: GoalWorkspaceCandidate }>;
|
|
83
|
+
abandoned?: Array<{ worker: GoalWorker; ownerRunId: string; reason: string; stoppedAt: number }>;
|
|
84
|
+
delivery?: { snapshotId: string; treeHash: string; artifact: AgentArtifact; status: "prepared" | "applied" };
|
|
85
|
+
}
|
|
86
|
+
export interface GoalVerifierWorkspace {
|
|
87
|
+
candidateId: string;
|
|
88
|
+
candidateHash: string;
|
|
89
|
+
path: string;
|
|
90
|
+
generatedPaths: string[];
|
|
91
|
+
}
|
|
92
|
+
export interface GoalFinalSnapshot {
|
|
93
|
+
goalId: string;
|
|
94
|
+
snapshotId: string;
|
|
95
|
+
path: string;
|
|
96
|
+
treeHash: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Serial Goal workspace composition. The caller must persist exportState()
|
|
101
|
+
* after acquisition/finalization and must use its Broker to restrict writes
|
|
102
|
+
* to the selected lease; these directories alone are not a security boundary.
|
|
103
|
+
*/
|
|
104
|
+
export class GoalWorkspace {
|
|
105
|
+
private workerManager?: WorkspaceManager;
|
|
106
|
+
private constructor(private state: GoalWorkspaceState, private readonly baseManager: WorkspaceManager) {}
|
|
107
|
+
|
|
108
|
+
private static owner(goalId: string, suffix: string) {
|
|
109
|
+
return { threadId: `goal:${goalId}:${suffix}`, instanceId: randomUUID(), pid: process.pid };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
static async create(root: string, goalId: string, hostDir: string): Promise<GoalWorkspace> {
|
|
113
|
+
if (!goalId || goalId.includes("\0")) throw new Error("Invalid goal id");
|
|
114
|
+
const realRoot = await realpath(root);
|
|
115
|
+
await mkdir(hostDir, { recursive: true, mode: 0o700 });
|
|
116
|
+
const realHost = await realpath(hostDir);
|
|
117
|
+
if (isWithin(realRoot, realHost)) throw new Error("Goal host directory must be outside its source workspace");
|
|
118
|
+
const ownerDirectory = dirname(realHost);
|
|
119
|
+
let privateGit: GoalWorkspaceState["privateGit"];
|
|
120
|
+
await withPersistentGitOperation(ownerDirectory, async () => {
|
|
121
|
+
const context = await workspaceContext(realRoot, realHost, false, true);
|
|
122
|
+
if (context.mode !== "isolated-git") return;
|
|
123
|
+
if (context.repoRoot !== realRoot) throw new Error("Git Goal requires the repository root as its workspace");
|
|
124
|
+
const before = await scanCopyTree(realRoot, true);
|
|
125
|
+
const history = join(realHost, "private-git-history");
|
|
126
|
+
await capturePrivateGitHistory(realRoot, history);
|
|
127
|
+
const after = await scanCopyTree(realRoot, true);
|
|
128
|
+
if (JSON.stringify(before) !== JSON.stringify(after)) throw new Error("Git working tree changed during history capture");
|
|
129
|
+
const snapshotRepository = join(history, "repository.git");
|
|
130
|
+
privateGit = { ownerDirectory, snapshotRepository, treeHash: await goalTreeHash(snapshotRepository) };
|
|
131
|
+
});
|
|
132
|
+
const manager = new WorkspaceManager({ root: realRoot, tempRoot: realHost, owner: this.owner(goalId, "base"), retention: false, forbidGit: true, copyWithPrivateGit: privateGit });
|
|
133
|
+
try {
|
|
134
|
+
const lease = await manager.acquire(`goal-base-${randomUUID()}`, true);
|
|
135
|
+
if (!lease.repoPath) throw new Error("Goal snapshot has no repository path");
|
|
136
|
+
const integration = await manager.integrationWorkspace(`goal-${randomUUID()}`);
|
|
137
|
+
const integrationPath = join(integration.path, relative(lease.repoPath, lease.path));
|
|
138
|
+
const baseTreeHash = await goalTreeHash(lease.path);
|
|
139
|
+
if (privateGit) await withPersistentGitOperation(ownerDirectory, () => assertPrivateGitHistoryMatches(realRoot, privateGit!.snapshotRepository));
|
|
140
|
+
return new GoalWorkspace({ version: 1, goalId, root: realRoot, hostDir: realHost, integrationPath, baseLease: lease, baseTreeHash, ...(privateGit ? { privateGit } : {}) }, manager);
|
|
141
|
+
} catch (error) { await manager.cleanup(); throw error; }
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
static async open(input: GoalWorkspaceState): Promise<GoalWorkspace> {
|
|
145
|
+
const state = structuredClone(input);
|
|
146
|
+
if (state.version !== 1 || !state.goalId || !state.baseLease.batchPath || !state.baseLease.repoPath || !state.baseTreeHash) throw new Error("Invalid Goal workspace state");
|
|
147
|
+
if (state.baseLease.mode !== "isolated-copy" || (state.worker && state.worker.lease.mode !== "isolated-copy")) {
|
|
148
|
+
throw new Error("Goal Git workspaces are unavailable: host Git execution is not sealed");
|
|
149
|
+
}
|
|
150
|
+
if (state.privateGit) {
|
|
151
|
+
const host = await realpath(state.hostDir), owner = await realpath(state.privateGit.ownerDirectory), repo = await realpath(state.privateGit.snapshotRepository);
|
|
152
|
+
if (owner !== dirname(host) || !isWithin(host, repo) || await goalTreeHash(repo) !== state.privateGit.treeHash) throw new Error("Private Goal Git history is invalid");
|
|
153
|
+
}
|
|
154
|
+
const manager = new WorkspaceManager({ root: state.root, tempRoot: state.hostDir, owner: this.owner(state.goalId, "base"), retention: false, forbidGit: true, copyWithPrivateGit: state.privateGit });
|
|
155
|
+
await manager.hydrate({ leases: [state.baseLease], artifacts: state.delivery ? [state.delivery.artifact] : [] });
|
|
156
|
+
const expectedParent = join(state.baseLease.batchPath, "integration");
|
|
157
|
+
const realIntegration = await realpath(state.integrationPath);
|
|
158
|
+
if (!isWithin(await realpath(expectedParent), realIntegration)) throw new Error("Goal integration escaped its recorded batch");
|
|
159
|
+
const goal = new GoalWorkspace(state, manager);
|
|
160
|
+
if (state.worker) {
|
|
161
|
+
const wm = new WorkspaceManager({ root: state.integrationPath, tempRoot: state.hostDir,
|
|
162
|
+
owner: this.owner(state.goalId, `worker:${state.workerOwnerRunId ?? state.worker.lease.runId}`), retention: false, forbidGit: true, copyWithPrivateGit: state.privateGit });
|
|
163
|
+
const previous = state.previous ?? [];
|
|
164
|
+
const abandoned = (state.abandoned ?? []).filter(item => item.worker.lease.batchPath === state.worker!.lease.batchPath);
|
|
165
|
+
await wm.hydrate({ leases: [...previous.map(item => item.worker.lease), ...abandoned.map(item => item.worker.lease), state.worker.lease],
|
|
166
|
+
artifacts: [...previous.map(item => item.candidate.artifact), ...(state.candidate ? [state.candidate.artifact] : [])] });
|
|
167
|
+
goal.workerManager = wm;
|
|
168
|
+
if (state.candidate) await goal.assertCandidate(state.candidate);
|
|
169
|
+
}
|
|
170
|
+
return goal;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
exportState(): GoalWorkspaceState { return structuredClone(this.state); }
|
|
174
|
+
get integrationPath(): string { return this.state.integrationPath; }
|
|
175
|
+
|
|
176
|
+
async acquireWorker(runId: string): Promise<GoalWorker> {
|
|
177
|
+
if (this.state.worker) throw new Error("A Goal worker is already active");
|
|
178
|
+
if (!runId || runId.includes("\0")) throw new Error("Invalid run id");
|
|
179
|
+
const integrationHash = await goalTreeHash(this.state.integrationPath);
|
|
180
|
+
const wm = new WorkspaceManager({ root: this.state.integrationPath, tempRoot: this.state.hostDir,
|
|
181
|
+
owner: GoalWorkspace.owner(this.state.goalId, `worker:${runId}`), retention: false, forbidGit: true, copyWithPrivateGit: this.state.privateGit });
|
|
182
|
+
const lease = await wm.acquire(runId, true);
|
|
183
|
+
if (await goalTreeHash(this.state.integrationPath) !== integrationHash) { await wm.cleanup(); throw new Error("Goal integration changed during acquisition"); }
|
|
184
|
+
this.workerManager = wm;
|
|
185
|
+
this.state.worker = { lease, integrationHash };
|
|
186
|
+
this.state.workerOwnerRunId = runId;
|
|
187
|
+
return structuredClone(this.state.worker);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async finalizeWorker(worker: GoalWorker, outcome: AgentOutcomeV1): Promise<GoalWorkspaceCandidate> {
|
|
191
|
+
if (!this.workerManager || JSON.stringify(worker) !== JSON.stringify(this.state.worker) || this.state.candidate) throw new Error("Unknown or already finalized worker");
|
|
192
|
+
validateOutcome(outcome);
|
|
193
|
+
if (outcome.execution.status !== "finished" || outcome.execution.unresolvedActions.length) throw new Error("Worker outcome is not eligible for freezing");
|
|
194
|
+
const artifact = await this.workerManager.finalize(worker.lease);
|
|
195
|
+
if (!artifact) throw new Error("Worker did not produce an isolated artifact");
|
|
196
|
+
const dir = await mkdtemp(join(this.state.hostDir, "candidate-"));
|
|
197
|
+
const checkoutRoot = join(dir, "snapshot");
|
|
198
|
+
const rootRelative = worker.lease.repoPath ? relative(worker.lease.repoPath, worker.lease.path) : "";
|
|
199
|
+
const prefix = rootRelative.split(sep).join("/");
|
|
200
|
+
if (prefix && artifact.changedPaths.some(path => path !== prefix && !path.startsWith(`${prefix}/`))) {
|
|
201
|
+
throw new Error("Worker artifact changed paths outside its Goal workspace");
|
|
202
|
+
}
|
|
203
|
+
const snapshotPath = join(checkoutRoot, rootRelative);
|
|
204
|
+
if (artifact.mode === "isolated-copy") {
|
|
205
|
+
await cp(this.workerManager.copyArtifactPath(artifact), checkoutRoot, { recursive: true, verbatimSymlinks: true, errorOnExist: true });
|
|
206
|
+
} else {
|
|
207
|
+
await exec("git", ["clone", "--local", "--no-hardlinks", "--no-checkout", artifact.repoPath, checkoutRoot], { env: { ...process.env, GIT_TERMINAL_PROMPT: "0" } });
|
|
208
|
+
await exec("git", ["-C", checkoutRoot, "checkout", "--detach", artifact.resultOid], { env: { ...process.env, GIT_TERMINAL_PROMPT: "0" } });
|
|
209
|
+
}
|
|
210
|
+
const treeHash = await goalTreeHash(snapshotPath);
|
|
211
|
+
let privateHistory: GoalWorkspaceCandidate["privateHistory"];
|
|
212
|
+
if (worker.lease.privateGit && this.state.privateGit) {
|
|
213
|
+
const historyDir = join(dir, "private-history");
|
|
214
|
+
await withPersistentGitOperation(this.state.privateGit.ownerDirectory, async () => {
|
|
215
|
+
await capturePrivateGitHistory(worker.lease.path, historyDir);
|
|
216
|
+
await assertPrivateGitHistoryMatches(worker.lease.path, join(historyDir, "repository.git"));
|
|
217
|
+
});
|
|
218
|
+
if (await goalTreeHash(worker.lease.path) !== treeHash) throw new Error("Worker changed while its Git history was frozen");
|
|
219
|
+
const repository = join(historyDir, "repository.git");
|
|
220
|
+
privateHistory = { repository, treeHash: await goalTreeHash(repository) };
|
|
221
|
+
}
|
|
222
|
+
const candidate: GoalWorkspaceCandidate = { goalId: this.state.goalId, candidateId: randomUUID(), attemptId: outcome.attemptId,
|
|
223
|
+
artifact, snapshotPath, treeHash, integrationHash: worker.integrationHash, ...(privateHistory ? { privateHistory } : {}) };
|
|
224
|
+
this.state.candidate = candidate;
|
|
225
|
+
return structuredClone(candidate);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** Re-run from the failed immutable candidate while retaining the original
|
|
229
|
+
* integration base. The caller persists exportState() before starting work. */
|
|
230
|
+
async acquireRepair(candidate: GoalWorkspaceCandidate, runId: string): Promise<GoalWorker> {
|
|
231
|
+
await this.assertCandidate(candidate);
|
|
232
|
+
if (!this.workerManager || !this.state.worker || !runId || runId.includes("\0")) throw new Error("Cannot repair this Goal candidate");
|
|
233
|
+
if (await goalTreeHash(this.state.integrationPath) !== candidate.integrationHash) throw new Error("Goal integration changed before repair");
|
|
234
|
+
let lease = await this.workerManager.acquire(runId, true);
|
|
235
|
+
if (lease.mode === "isolated-copy") {
|
|
236
|
+
const tree = await scanCopyTree(candidate.snapshotPath);
|
|
237
|
+
await removeOwnedCopyTree(lease.path);
|
|
238
|
+
await materializeCopyTree(candidate.snapshotPath, lease.path, tree);
|
|
239
|
+
if (this.state.privateGit) {
|
|
240
|
+
if (!candidate.privateHistory) throw new Error("Frozen private Git history is missing");
|
|
241
|
+
lease = await this.workerManager.restorePrivateGit(lease, candidate.privateHistory.repository);
|
|
242
|
+
}
|
|
243
|
+
} else {
|
|
244
|
+
if (!lease.repoPath) throw new Error("Repair workspace has no private Git repository");
|
|
245
|
+
const env = { ...process.env, GIT_TERMINAL_PROMPT: "0", GIT_NO_REPLACE_OBJECTS: "1" };
|
|
246
|
+
await exec("git", ["-C", lease.repoPath, "fetch", "--no-tags", candidate.artifact.repoPath, candidate.artifact.resultOid], { env });
|
|
247
|
+
await exec("git", ["-C", lease.repoPath, "checkout", "--detach", candidate.artifact.resultOid], { env });
|
|
248
|
+
}
|
|
249
|
+
if (await goalTreeHash(lease.path) !== candidate.treeHash) throw new Error("Repair workspace does not match its frozen candidate");
|
|
250
|
+
this.state.previous ??= [];
|
|
251
|
+
this.state.previous.push({ worker: this.state.worker, candidate: this.state.candidate! });
|
|
252
|
+
this.state.worker = { lease, integrationHash: candidate.integrationHash };
|
|
253
|
+
this.state.candidate = undefined;
|
|
254
|
+
return structuredClone(this.state.worker);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** Reconcile an interrupted, unfinalized worker only after the Host has
|
|
258
|
+
* verified process-tree termination and absence of opaque side effects.
|
|
259
|
+
* The worker lease is retained as evidence; no files are deleted. */
|
|
260
|
+
async abandonWorker(input: { runId: string; stopped: true; externalEffects: "none"; reason: string }): Promise<void> {
|
|
261
|
+
const worker = this.state.worker;
|
|
262
|
+
if (!worker || this.state.candidate || input.runId !== worker.lease.runId || input.stopped !== true
|
|
263
|
+
|| input.externalEffects !== "none" || !input.reason.trim()) throw new Error("Worker abandonment requires confirmed safe reconciliation");
|
|
264
|
+
this.state.abandoned ??= [];
|
|
265
|
+
this.state.abandoned.push({ worker: structuredClone(worker), ownerRunId: this.state.workerOwnerRunId ?? worker.lease.runId,
|
|
266
|
+
reason: input.reason, stoppedAt: Date.now() });
|
|
267
|
+
const prior = this.state.previous?.pop();
|
|
268
|
+
if (prior) {
|
|
269
|
+
this.state.worker = prior.worker;
|
|
270
|
+
this.state.candidate = prior.candidate;
|
|
271
|
+
await this.assertCandidate(prior.candidate);
|
|
272
|
+
} else {
|
|
273
|
+
this.state.worker = undefined;
|
|
274
|
+
this.state.workerOwnerRunId = undefined;
|
|
275
|
+
this.workerManager = undefined;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
async assertCandidate(candidate: GoalWorkspaceCandidate): Promise<void> {
|
|
280
|
+
if (!this.state.candidate || JSON.stringify(candidate) !== JSON.stringify(this.state.candidate)) throw new Error("Candidate is not owned by this Goal");
|
|
281
|
+
const base = await realpath(this.state.hostDir);
|
|
282
|
+
const snapshot = await realpath(candidate.snapshotPath);
|
|
283
|
+
const parts = relative(base, snapshot).split(sep);
|
|
284
|
+
if (!isWithin(base, snapshot) || !parts[0]?.startsWith("candidate-") || parts[1] !== "snapshot") throw new Error("Candidate snapshot escaped its host directory");
|
|
285
|
+
if (await goalTreeHash(snapshot) !== candidate.treeHash) throw new Error("Candidate snapshot was modified after freezing");
|
|
286
|
+
if (candidate.privateHistory) {
|
|
287
|
+
const repository = await realpath(candidate.privateHistory.repository);
|
|
288
|
+
if (!isWithin(dirname(snapshot), repository) || await goalTreeHash(repository) !== candidate.privateHistory.treeHash) throw new Error("Frozen private Git history was modified");
|
|
289
|
+
}
|
|
290
|
+
if (candidate.artifact.mode === "isolated-copy") {
|
|
291
|
+
if (!this.workerManager || await goalTreeHash(this.workerManager.copyArtifactPath(candidate.artifact)) !== candidate.treeHash) throw new Error("Frozen artifact was modified");
|
|
292
|
+
} else {
|
|
293
|
+
// Resolve the object named at freeze; disable replace refs so it cannot be substituted.
|
|
294
|
+
const value = (await exec("git", ["--no-replace-objects", "-C", candidate.artifact.repoPath, "rev-parse", `${candidate.artifact.resultOid}^{commit}`])).stdout.trim();
|
|
295
|
+
if (value !== candidate.artifact.resultOid) throw new Error("Frozen Git artifact was modified");
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
async prepareVerifier(candidate: GoalWorkspaceCandidate, generatedPaths: string[] = []): Promise<GoalVerifierWorkspace> {
|
|
300
|
+
await this.assertCandidate(candidate);
|
|
301
|
+
// Existing candidate paths can never be excluded from integrity checks.
|
|
302
|
+
for (const path of generatedPaths) {
|
|
303
|
+
if (!path || isAbsolute(path) || path.includes("\\") || path.split("/").some(p => !p || p === "." || p === ".." || p.toLowerCase() === ".git")) throw new Error("Invalid verifier generated path");
|
|
304
|
+
try { await lstat(join(candidate.snapshotPath, path)); throw new Error(`Generated path is part of the candidate: ${path}`); }
|
|
305
|
+
catch (e) { if ((e as NodeJS.ErrnoException).code !== "ENOENT") throw e; }
|
|
306
|
+
}
|
|
307
|
+
const dir = await mkdtemp(join(this.state.hostDir, "verifier-"));
|
|
308
|
+
const path = join(dir, "workspace");
|
|
309
|
+
await cp(candidate.snapshotPath, path, { recursive: true, verbatimSymlinks: true, errorOnExist: true });
|
|
310
|
+
if (await goalTreeHash(path) !== candidate.treeHash) throw new Error("Verifier copy does not match the candidate");
|
|
311
|
+
return { candidateId: candidate.candidateId, candidateHash: candidate.treeHash, path, generatedPaths: [...generatedPaths] };
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
async assertVerifierUnchanged(candidate: GoalWorkspaceCandidate, verifier: GoalVerifierWorkspace): Promise<void> {
|
|
315
|
+
await this.assertCandidate(candidate);
|
|
316
|
+
if (verifier.candidateId !== candidate.candidateId || verifier.candidateHash !== candidate.treeHash
|
|
317
|
+
|| await goalTreeHash(verifier.path, verifier.generatedPaths) !== candidate.treeHash) throw new Error("Verifier modified candidate source");
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** The store and receipt binding must come from host-owned state. */
|
|
321
|
+
async merge(candidate: GoalWorkspaceCandidate, receipt: GoalAcceptanceReceipt, store: InlineAcceptanceStore): Promise<MergeResult> {
|
|
322
|
+
await this.assertCandidate(candidate);
|
|
323
|
+
await assertGoalAcceptance(candidate, receipt, store);
|
|
324
|
+
if (!this.workerManager || await goalTreeHash(this.state.integrationPath) !== candidate.integrationHash) throw new Error("Goal integration changed before merge");
|
|
325
|
+
const result = await new MergeCoordinator(this.workerManager).merge([candidate.artifact.artifactId]);
|
|
326
|
+
if (result.success) {
|
|
327
|
+
if (this.state.privateGit && candidate.privateHistory) this.state.privateGit = { ...this.state.privateGit, snapshotRepository: candidate.privateHistory.repository, treeHash: candidate.privateHistory.treeHash };
|
|
328
|
+
this.state.worker = undefined; this.state.workerOwnerRunId = undefined; this.state.candidate = undefined; this.state.previous = undefined; this.workerManager = undefined;
|
|
329
|
+
}
|
|
330
|
+
return result;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
async finalSnapshot(): Promise<GoalFinalSnapshot> {
|
|
334
|
+
const before = await goalTreeHash(this.state.integrationPath);
|
|
335
|
+
const dir = await mkdtemp(join(this.state.hostDir, "integration-snapshot-"));
|
|
336
|
+
const path = join(dir, "snapshot");
|
|
337
|
+
await cp(this.state.integrationPath, path, { recursive: true, verbatimSymlinks: true, errorOnExist: true,
|
|
338
|
+
filter: source => relative(this.state.integrationPath, source) !== ".git" });
|
|
339
|
+
if (await goalTreeHash(path) !== before || await goalTreeHash(this.state.integrationPath) !== before) throw new Error("Goal integration changed during snapshot");
|
|
340
|
+
return { goalId: this.state.goalId, snapshotId: randomUUID(), path, treeHash: before };
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
async assertFinalSnapshot(snapshot: GoalFinalSnapshot): Promise<void> {
|
|
344
|
+
const base = await realpath(this.state.hostDir);
|
|
345
|
+
const path = await realpath(snapshot.path);
|
|
346
|
+
const parts = relative(base, path).split(sep);
|
|
347
|
+
if (snapshot.goalId !== this.state.goalId || !snapshot.snapshotId || !isWithin(base, path)
|
|
348
|
+
|| !parts[0]?.startsWith("integration-snapshot-") || parts[1] !== "snapshot"
|
|
349
|
+
|| await goalTreeHash(path) !== snapshot.treeHash || await goalTreeHash(this.state.integrationPath) !== snapshot.treeHash) {
|
|
350
|
+
throw new Error("Final Goal snapshot is stale or invalid");
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
async prepareFinalVerifier(snapshot: GoalFinalSnapshot, generatedPaths: string[] = []): Promise<GoalVerifierWorkspace> {
|
|
355
|
+
await this.assertFinalSnapshot(snapshot);
|
|
356
|
+
for (const path of generatedPaths) {
|
|
357
|
+
if (!path || isAbsolute(path) || path.includes("\\") || path.split("/").some(p => !p || p === "." || p === ".." || p.toLowerCase() === ".git")) throw new Error("Invalid verifier generated path");
|
|
358
|
+
try { await lstat(join(snapshot.path, path)); throw new Error(`Generated path is part of the candidate: ${path}`); }
|
|
359
|
+
catch (e) { if ((e as NodeJS.ErrnoException).code !== "ENOENT") throw e; }
|
|
360
|
+
}
|
|
361
|
+
const dir = await mkdtemp(join(this.state.hostDir, "verifier-"));
|
|
362
|
+
const path = join(dir, "workspace");
|
|
363
|
+
await cp(snapshot.path, path, { recursive: true, verbatimSymlinks: true, errorOnExist: true });
|
|
364
|
+
if (await goalTreeHash(path) !== snapshot.treeHash) throw new Error("Verifier copy does not match the final Goal snapshot");
|
|
365
|
+
return { candidateId: snapshot.snapshotId, candidateHash: snapshot.treeHash, path, generatedPaths: [...generatedPaths] };
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
async assertFinalVerifierUnchanged(snapshot: GoalFinalSnapshot, verifier: GoalVerifierWorkspace): Promise<void> {
|
|
369
|
+
await this.assertFinalSnapshot(snapshot);
|
|
370
|
+
if (verifier.candidateId !== snapshot.snapshotId || verifier.candidateHash !== snapshot.treeHash
|
|
371
|
+
|| await goalTreeHash(verifier.path, verifier.generatedPaths) !== snapshot.treeHash) throw new Error("Verifier modified final Goal source");
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/** Create the final artifact against the original user-disk baseline.
|
|
375
|
+
* Host must persist its operation intent before calling and persist the
|
|
376
|
+
* returned exportState() before applyDelivery(). Interrupted preparation is
|
|
377
|
+
* not replay-safe and must be reconciled, not automatically restarted. */
|
|
378
|
+
async prepareDelivery(snapshot: GoalFinalSnapshot, receipt: GoalFinalAcceptanceReceipt, store: InlineAcceptanceStore): Promise<AgentArtifact> {
|
|
379
|
+
await assertGoalFinalAcceptance(this, snapshot, receipt, store);
|
|
380
|
+
if (this.state.worker || this.state.delivery) throw new Error("Goal workspace is not ready to prepare delivery");
|
|
381
|
+
const lease = this.state.baseLease;
|
|
382
|
+
if (!lease.batchPath || !lease.repoPath) throw new Error("Missing Goal baseline workspace");
|
|
383
|
+
const privatePath = await realpath(lease.path);
|
|
384
|
+
const runsPath = await realpath(join(lease.batchPath, "runs"));
|
|
385
|
+
if (!isWithin(runsPath, privatePath) || await goalTreeHash(privatePath) !== this.state.baseTreeHash) {
|
|
386
|
+
throw new Error("Goal baseline workspace changed before delivery preparation");
|
|
387
|
+
}
|
|
388
|
+
// Only the Host-owned private baseline clone is modified. Its .git is
|
|
389
|
+
// retained; the user's index and refs are never staged or committed.
|
|
390
|
+
for (const entry of await readdir(privatePath)) {
|
|
391
|
+
if (entry !== ".git") await rm(join(privatePath, entry), { recursive: true, force: true });
|
|
392
|
+
}
|
|
393
|
+
for (const entry of await readdir(snapshot.path)) {
|
|
394
|
+
if (entry !== ".git") await cp(join(snapshot.path, entry), join(privatePath, entry), { recursive: true, verbatimSymlinks: true, errorOnExist: true });
|
|
395
|
+
}
|
|
396
|
+
if (await goalTreeHash(privatePath) !== snapshot.treeHash) throw new Error("Delivery candidate differs from final verified snapshot");
|
|
397
|
+
await assertGoalFinalAcceptance(this, snapshot, receipt, store);
|
|
398
|
+
const artifact = await this.baseManager.finalize(lease);
|
|
399
|
+
if (!artifact) throw new Error("Goal delivery did not produce an isolated artifact");
|
|
400
|
+
this.state.delivery = { snapshotId: snapshot.snapshotId, treeHash: snapshot.treeHash, artifact, status: "prepared" };
|
|
401
|
+
return structuredClone(artifact);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/** Apply one persisted prepared artifact. Host must persist an in-flight
|
|
405
|
+
* claim before calling; a lost acknowledgement is unknown, not permission
|
|
406
|
+
* to replay this method. Existing MergeCoordinator checks root drift and
|
|
407
|
+
* performs the copy backend's journaled recovery. */
|
|
408
|
+
async applyDelivery(snapshot: GoalFinalSnapshot, receipt: GoalFinalAcceptanceReceipt, store: InlineAcceptanceStore): Promise<MergeResult> {
|
|
409
|
+
await assertGoalFinalAcceptance(this, snapshot, receipt, store);
|
|
410
|
+
const delivery = this.state.delivery;
|
|
411
|
+
if (!delivery || delivery.status !== "prepared" || delivery.snapshotId !== snapshot.snapshotId || delivery.treeHash !== snapshot.treeHash) {
|
|
412
|
+
throw new Error("No matching prepared Goal delivery");
|
|
413
|
+
}
|
|
414
|
+
const result = await new MergeCoordinator(this.baseManager).merge([delivery.artifact.artifactId]);
|
|
415
|
+
if (result.success) delivery.status = "applied";
|
|
416
|
+
return result;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/** Explicit cleanup only; caller must retain batches needed for crash recovery. */
|
|
420
|
+
async cleanup(): Promise<void> {
|
|
421
|
+
if (this.workerManager) await this.workerManager.cleanup();
|
|
422
|
+
if (this.state.candidate) await rm(dirname(this.state.candidate.snapshotPath), { recursive: true, force: true });
|
|
423
|
+
await this.baseManager.cleanup();
|
|
424
|
+
}
|
|
425
|
+
}
|
package/zapsdk/policy/types.ts
CHANGED
|
@@ -24,6 +24,10 @@ export interface WorkspaceIdentity {
|
|
|
24
24
|
/** Host-owned standalone Git directory of a writing Agent's private clone.
|
|
25
25
|
* Never derived from tool arguments, repository files or linked worktrees. */
|
|
26
26
|
privateGitDirectory?: string;
|
|
27
|
+
/** Optional Host-recorded identity of the privately created Git directory. */
|
|
28
|
+
privateGitIdentity?: { device: string; inode: string };
|
|
29
|
+
/** Extra relative paths selected by the Host, never by tool arguments. */
|
|
30
|
+
protectedWorkspacePaths?: readonly string[];
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
export interface CapabilityGrant {
|
|
@@ -26,6 +26,10 @@ import {
|
|
|
26
26
|
|
|
27
27
|
export interface RuntimeWorkspaceOptions {
|
|
28
28
|
root: string;
|
|
29
|
+
/** Host-controlled location and backend restriction for isolated children. */
|
|
30
|
+
tempRoot?: string;
|
|
31
|
+
forbidGit?: boolean;
|
|
32
|
+
capturePrivateGitFromRoot?: { ownerDirectory: string; sourceBinding: import("../workspace/types.js").PrivateGitBinding };
|
|
29
33
|
onTrackEdit?: (paths: string[]) => Promise<void>;
|
|
30
34
|
retention?: false | Partial<WorkspaceRetentionPolicy>;
|
|
31
35
|
onRetention?: (report: WorkspaceRetentionReport) => void | Promise<void>;
|
|
@@ -80,6 +84,9 @@ export function createAgentRuntime(options: CreateAgentRuntimeOptions): AgentRun
|
|
|
80
84
|
const runtimeOwner = stateTracker.ownerSnapshot();
|
|
81
85
|
const workspaceManager = new WorkspaceManager({
|
|
82
86
|
root: options.workspace.root,
|
|
87
|
+
tempRoot: options.workspace.tempRoot,
|
|
88
|
+
forbidGit: options.workspace.forbidGit,
|
|
89
|
+
capturePrivateGitFromRoot: options.workspace.capturePrivateGitFromRoot,
|
|
83
90
|
owner: {
|
|
84
91
|
threadId: options.threadId,
|
|
85
92
|
instanceId: runtimeOwner.instanceId,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isAbsolute, relative, resolve } from "node:path";
|
|
1
|
+
import { isAbsolute, relative, resolve, sep } from "node:path";
|
|
2
2
|
import type { ResourceClaim } from "../tools/effects.js";
|
|
3
3
|
|
|
4
4
|
export type ToolRunStatus =
|
|
@@ -39,7 +39,7 @@ function fsPath(key: string): string | undefined {
|
|
|
39
39
|
function pathsOverlap(left: string, right: string): boolean {
|
|
40
40
|
const leftToRight = relative(left, right);
|
|
41
41
|
const rightToLeft = relative(right, left);
|
|
42
|
-
const contains = (rel: string) => rel === "" || (!rel.startsWith(
|
|
42
|
+
const contains = (rel: string) => rel === "" || (rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel));
|
|
43
43
|
return contains(leftToRight) || contains(rightToLeft);
|
|
44
44
|
}
|
|
45
45
|
|