@nathanstephenson/flow 0.1.7 → 0.1.8
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 +122 -640
- package/build/backend-worker-chunks/chunk-J2DBNTL7.mjs +94 -0
- package/build/backend-worker-chunks/chunk-MLOUI3ZM.mjs +19752 -0
- package/build/backend-worker-chunks/chunk-UQDH2COY.mjs +15296 -0
- package/build/backend-worker-chunks/claude-GTW5KHY5.mjs +30778 -0
- package/build/backend-worker-chunks/pi-M4OA2FGL.mjs +5730 -0
- package/build/backend-worker.mjs +4401 -0
- package/dist/backend/fake/index.js +2 -0
- package/dist/backend/mcp.js +34 -15
- package/dist/backend/pi/state.js +18 -0
- package/dist/backend/registry.js +2 -1
- package/dist/backend/worker/claude-state.js +24 -3
- package/dist/backend/worker/entry.js +70 -13
- package/dist/backend/worker/frames.js +34 -0
- package/dist/backend/worker/index.js +139 -16
- package/dist/backend/worker/launcher.js +22 -3
- package/dist/backend/worker/sandbox-mcp.js +86 -0
- package/dist/build-id +1 -1
- package/dist/cli/bootstrap.js +7 -6
- package/dist/cli/install-guard.js +1 -1
- package/dist/cli/main.js +3 -6
- package/dist/cli/update.js +3 -3
- package/dist/cli/web-update.js +9 -6
- package/dist/client/connection.js +5 -2
- package/dist/client/diff.js +6 -9
- package/dist/client/reduce.js +19 -0
- package/dist/client/tool-chains.js +12 -4
- package/dist/daemon/config-store.js +21 -14
- package/dist/daemon/config.js +48 -5
- package/dist/daemon/git.js +47 -0
- package/dist/daemon/host.js +208 -29
- package/dist/daemon/models.js +27 -24
- package/dist/daemon/release-checker.js +48 -34
- package/dist/daemon/runtime.js +10 -4
- package/dist/daemon/server.js +13 -1
- package/dist/daemon/shell.js +2 -1
- package/dist/daemon/skills.js +34 -31
- package/dist/daemon/summariser.js +33 -14
- package/dist/daemon/timings.js +14 -0
- package/dist/daemon/workflow-authoring-scope-checks.js +5 -8
- package/dist/daemon/workflow-authoring-scope-reader.js +20 -9
- package/dist/daemon/workflow-builder-files.js +5 -5
- package/dist/daemon/workflow-builder-guidance.js +3 -3
- package/dist/daemon/workflow-builder-reader.js +21 -10
- package/dist/daemon/workflow-builder.js +66 -8
- package/dist/daemon/workflow-executions.js +10 -10
- package/dist/daemon/workflow-mcp-authoring-routes.js +18 -6
- package/dist/daemon/workflow-mcp-authoring.js +44 -20
- package/dist/isolation/filesystem.js +8 -9
- package/dist/isolation/sandbox-supervisor.js +50 -0
- package/dist/isolation/sandbox.js +165 -0
- package/dist/isolation/shared-sandbox.js +77 -0
- package/dist/workflows/executors.js +16 -4
- package/dist/workflows/json-schema.js +14 -4
- package/package.json +7 -4
- package/web/dist/assets/index-CiEgCpiO.js +40 -0
- package/web/dist/assets/index-ClwLFMZN.css +2 -0
- package/web/dist/assets/settings-mcp-CoRWT-D_.js +1 -0
- package/web/dist/assets/settings-secrets-BIO_hXZ1.js +1 -0
- package/web/dist/assets/settings-workflows-BXbj0TKs.js +23 -0
- package/web/dist/assets/switch-DIogWclb.js +1 -0
- package/web/dist/assets/workflow-api-BfExddae.js +6 -0
- package/web/dist/assets/workflow-editors-CsbVx4WJ.js +139 -0
- package/web/dist/assets/workflows-Bv0sj7d0.js +7 -0
- package/web/dist/assets/workflows-pane-C_Yg4pgr.js +1 -0
- package/web/dist/index.html +5 -5
- package/web/dist/assets/index-DxTV-TYZ.js +0 -38
- package/web/dist/assets/index-jwsr3cpu.css +0 -2
- package/web/dist/assets/input-BOuBzJVY.js +0 -6
- package/web/dist/assets/settings-mcp-D-jWezcS.js +0 -1
- package/web/dist/assets/settings-secrets-DdQ0eujd.js +0 -1
- package/web/dist/assets/settings-workflows-BCzYKkOk.js +0 -23
- package/web/dist/assets/switch-B0hMd_dH.js +0 -1
- package/web/dist/assets/workflow-editors-CDZqnDvT.js +0 -137
- package/web/dist/assets/workflows-BpPNiK-H.js +0 -7
- package/web/dist/assets/workflows-pane-N3Vf30Cb.js +0 -1
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { existsSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { isAbsolute, join, sep } from "node:path";
|
|
4
|
+
import { sandboxSupervisorSource } from "./sandbox-supervisor.js";
|
|
5
|
+
const placeholders = {
|
|
6
|
+
probe: { allowed: [], required: [] },
|
|
7
|
+
create: { allowed: ["{spec}", "{name}"], required: ["{spec}"] },
|
|
8
|
+
exec: { allowed: ["{name}", "{cwd}"], required: ["{name}", "{cwd}"] },
|
|
9
|
+
remove: { allowed: ["{name}"], required: ["{name}"] },
|
|
10
|
+
shell: { allowed: ["{name}", "{cwd}"], required: ["{name}", "{cwd}"] },
|
|
11
|
+
};
|
|
12
|
+
export function sandboxUnavailable() {
|
|
13
|
+
return new Error("Sandbox isolation is unavailable; unrestricted launch refused");
|
|
14
|
+
}
|
|
15
|
+
export function sandboxProviderPath(stateRoot, env = process.env) {
|
|
16
|
+
return env.FLOW_SANDBOX_PROVIDER || join(stateRoot, "sandbox-provider.json");
|
|
17
|
+
}
|
|
18
|
+
export function parseSandboxProvider(text) {
|
|
19
|
+
const value = JSON.parse(text);
|
|
20
|
+
if (!value || typeof value !== "object" || value.version !== 1)
|
|
21
|
+
throw new Error("version must be 1");
|
|
22
|
+
for (const key of ["nodePath", "claudePath", "claudeAuthDir"]) {
|
|
23
|
+
if (key === "claudeAuthDir" && value[key] === undefined)
|
|
24
|
+
continue;
|
|
25
|
+
if (typeof value[key] !== "string" || !isAbsolute(value[key]))
|
|
26
|
+
throw new Error(`${key} must be an absolute path`);
|
|
27
|
+
}
|
|
28
|
+
for (const [command, { allowed, required }] of Object.entries(placeholders)) {
|
|
29
|
+
const template = value[command];
|
|
30
|
+
if (command === "shell" && template === undefined)
|
|
31
|
+
continue;
|
|
32
|
+
if (!Array.isArray(template) || !template.length || !template.every((part) => typeof part === "string" && part.length)) {
|
|
33
|
+
throw new Error(`${command} must be a non-empty array of strings`);
|
|
34
|
+
}
|
|
35
|
+
for (const part of template) {
|
|
36
|
+
if (/^\{.*\}$/.test(part) && !allowed.includes(part))
|
|
37
|
+
throw new Error(`${command} has unknown placeholder ${part}`);
|
|
38
|
+
}
|
|
39
|
+
for (const part of required)
|
|
40
|
+
if (!template.includes(part))
|
|
41
|
+
throw new Error(`${command} must contain ${part}`);
|
|
42
|
+
}
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
export function fillTemplate(template, values) {
|
|
46
|
+
return template.map((part) => {
|
|
47
|
+
const key = /^\{(.+)\}$/.exec(part)?.[1];
|
|
48
|
+
return key !== undefined && key in values ? values[key] : part;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
export const detectSandboxSupport = async ({ stateRoot, env = process.env, timeoutMs = 300_000 }) => {
|
|
52
|
+
const path = sandboxProviderPath(stateRoot, env);
|
|
53
|
+
let provider;
|
|
54
|
+
try {
|
|
55
|
+
provider = parseSandboxProvider(readFileSync(path, "utf8"));
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
const missing = error.code === "ENOENT";
|
|
59
|
+
return { supported: false, reason: missing ? `No sandbox provider file at ${path}.` : `Invalid sandbox provider file ${path}: ${error.message}` };
|
|
60
|
+
}
|
|
61
|
+
const [command, ...args] = provider.probe;
|
|
62
|
+
return new Promise((resolve) => {
|
|
63
|
+
execFile(command, args, { timeout: timeoutMs, killSignal: "SIGKILL", maxBuffer: 1024 * 1024 }, (error, _stdout, stderr) => {
|
|
64
|
+
if (error)
|
|
65
|
+
resolve({ supported: false, reason: `Sandbox provider probe failed: ${stderr.trim().slice(-1024) || error.message}` });
|
|
66
|
+
else
|
|
67
|
+
resolve({ supported: true, path, provider });
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
export function sandboxMounts(writable, readable) {
|
|
72
|
+
const mounts = new Map();
|
|
73
|
+
for (const path of writable)
|
|
74
|
+
mounts.set(realpathSync(path), false);
|
|
75
|
+
for (const path of readable) {
|
|
76
|
+
const real = realpathSync(path);
|
|
77
|
+
if (!mounts.has(real))
|
|
78
|
+
mounts.set(real, true);
|
|
79
|
+
}
|
|
80
|
+
const sorted = [...mounts].sort(([a], [b]) => a.length - b.length);
|
|
81
|
+
const kept = [];
|
|
82
|
+
for (const [path, readOnly] of sorted) {
|
|
83
|
+
if (kept.some(([parent, parentReadOnly]) => parentReadOnly === readOnly && (path === parent || path.startsWith(parent + sep))))
|
|
84
|
+
continue;
|
|
85
|
+
kept.push([path, readOnly]);
|
|
86
|
+
}
|
|
87
|
+
return kept.map(([path, readOnly]) => {
|
|
88
|
+
const stat = statSync(path);
|
|
89
|
+
return { path, readOnly, dev: stat.dev, ino: stat.ino };
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function runProvider(argv, timeoutMs, signal) {
|
|
93
|
+
const [command, ...args] = argv;
|
|
94
|
+
return new Promise((resolve, reject) => {
|
|
95
|
+
execFile(command, args, { timeout: timeoutMs, killSignal: "SIGKILL", maxBuffer: 1024 * 1024, ...(signal ? { signal } : {}) }, (error, _stdout, stderr) => {
|
|
96
|
+
if (error)
|
|
97
|
+
reject(new Error(`Sandbox provider ${argv.join(" ")} failed: ${stderr.trim().slice(-2048) || error.message}`));
|
|
98
|
+
else
|
|
99
|
+
resolve();
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
export async function createSandbox(provider, spec, specPath, signal) {
|
|
104
|
+
for (const mount of spec.mounts) {
|
|
105
|
+
const stat = statSync(mount.path);
|
|
106
|
+
if (realpathSync(mount.path) !== mount.path || stat.dev !== mount.dev || stat.ino !== mount.ino)
|
|
107
|
+
throw new Error(`Sandbox mount changed since validation: ${mount.path}`);
|
|
108
|
+
}
|
|
109
|
+
const stale = existsSync(specPath);
|
|
110
|
+
writeFileSync(specPath, JSON.stringify({ schemaVersion: "1", name: spec.name, workspace: spec.workspace,
|
|
111
|
+
additionalWorkspaces: spec.mounts.filter((mount) => mount.path !== spec.workspace).map(({ path, readOnly }) => ({ path, readOnly })),
|
|
112
|
+
env: spec.env }), { mode: 0o600 });
|
|
113
|
+
const remove = () => runProvider(fillTemplate(provider.remove, { name: spec.name }), 120_000);
|
|
114
|
+
let start = performance.now();
|
|
115
|
+
if (stale)
|
|
116
|
+
await remove().catch(() => { });
|
|
117
|
+
const startup = { remove: performance.now() - start, create: 0 };
|
|
118
|
+
start = performance.now();
|
|
119
|
+
try {
|
|
120
|
+
await runProvider(fillTemplate(provider.create, { spec: specPath, name: spec.name }), 600_000, signal);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
await remove().catch(() => { });
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
startup.create = performance.now() - start;
|
|
127
|
+
let holds = 0, closed = false, removing = false;
|
|
128
|
+
let finish;
|
|
129
|
+
const removed = new Promise((resolve) => { finish = resolve; });
|
|
130
|
+
removed.catch(() => { });
|
|
131
|
+
const settle = () => {
|
|
132
|
+
if (closed && !holds && !removing) {
|
|
133
|
+
removing = true;
|
|
134
|
+
finish(remove().then(() => rmSync(specPath, { force: true })));
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
return {
|
|
138
|
+
name: spec.name,
|
|
139
|
+
nodePath: provider.nodePath,
|
|
140
|
+
startup,
|
|
141
|
+
hold: () => {
|
|
142
|
+
if (closed)
|
|
143
|
+
throw new Error(`Sandbox ${spec.name} is stopping`);
|
|
144
|
+
holds++;
|
|
145
|
+
let released = false;
|
|
146
|
+
return () => { if (!released) {
|
|
147
|
+
released = true;
|
|
148
|
+
holds--;
|
|
149
|
+
settle();
|
|
150
|
+
} };
|
|
151
|
+
},
|
|
152
|
+
close: () => { closed = true; settle(); return removed; },
|
|
153
|
+
command: (cwd, argv, env) => {
|
|
154
|
+
const [command, ...args] = fillTemplate(provider.exec, { name: spec.name, cwd });
|
|
155
|
+
return { command: command, args: [...args, provider.nodePath, "-e", sandboxSupervisorSource, "--", "env",
|
|
156
|
+
...Object.entries(env).map(([key, value]) => `${key}=${value}`), ...argv] };
|
|
157
|
+
},
|
|
158
|
+
shellCommand: (cwd) => {
|
|
159
|
+
if (!provider.shell)
|
|
160
|
+
return undefined;
|
|
161
|
+
const [command, ...args] = fillTemplate(provider.shell, { name: spec.name, cwd });
|
|
162
|
+
return { command: command, args: [...args, "/bin/bash", "-l"] };
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { mkdirSync, realpathSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join, sep } from "node:path";
|
|
5
|
+
import { createSandbox, sandboxUnavailable } from "./sandbox.js";
|
|
6
|
+
/** The fixed folder for Workflow builder Scopes, the Summary Model Scope and temporary sandbox state, so that one mount covers them. */
|
|
7
|
+
export function workflowBuilderFolder() {
|
|
8
|
+
const path = join(tmpdir(), "flow-workflow-builders");
|
|
9
|
+
mkdirSync(path, { recursive: true, mode: 0o700 });
|
|
10
|
+
return realpathSync(path);
|
|
11
|
+
}
|
|
12
|
+
/** The empty, neutral Scope of every throwaway Summary Model session. It is in the builder folder, so a shared VM mounts it. */
|
|
13
|
+
export function summaryFolder() {
|
|
14
|
+
const path = join(workflowBuilderFolder(), "summary");
|
|
15
|
+
mkdirSync(path, { recursive: true, mode: 0o700 });
|
|
16
|
+
return path;
|
|
17
|
+
}
|
|
18
|
+
/** One VM for all sandbox sessions of a Session Host. sbx cannot add mounts after create, so it mounts fixed roots. */
|
|
19
|
+
export class SharedSandbox {
|
|
20
|
+
vm;
|
|
21
|
+
holds = new Set();
|
|
22
|
+
queue = Promise.resolve();
|
|
23
|
+
stateRoot;
|
|
24
|
+
projectRoot;
|
|
25
|
+
constructor(stateRoot, projectRoot) { this.stateRoot = stateRoot; this.projectRoot = projectRoot; }
|
|
26
|
+
/** Project Root, Worktrees folder and builder folder hold shared Scopes; the sessions folder holds session state. */
|
|
27
|
+
roots() {
|
|
28
|
+
const projectRoot = this.projectRoot();
|
|
29
|
+
if (!projectRoot)
|
|
30
|
+
throw new Error(`${sandboxUnavailable().message}: a shared sandbox needs a Project Root`);
|
|
31
|
+
const worktrees = join(this.stateRoot, "worktrees"), sessions = join(this.stateRoot, "sessions");
|
|
32
|
+
for (const path of [worktrees, sessions])
|
|
33
|
+
mkdirSync(path, { recursive: true });
|
|
34
|
+
return [realpathSync(projectRoot), realpathSync(worktrees), workflowBuilderFolder(), realpathSync(sessions)];
|
|
35
|
+
}
|
|
36
|
+
/** Single-flight: creates the VM when none fits the mounts and every session that holds it can be evicted. */
|
|
37
|
+
acquire(provider, workspace, mounts, signal, evict) {
|
|
38
|
+
const next = this.queue.then(() => this.take(provider, workspace, mounts, signal, evict));
|
|
39
|
+
this.queue = next.catch(() => { });
|
|
40
|
+
return next;
|
|
41
|
+
}
|
|
42
|
+
async take(provider, workspace, mounts, signal, evict) {
|
|
43
|
+
let startup = { remove: 0, create: 0 };
|
|
44
|
+
const missing = mounts.filter((mount) => !this.vm?.mounts.some((vm) => (mount.path === vm.path || mount.path.startsWith(vm.path + sep)) && (mount.readOnly || !vm.readOnly)));
|
|
45
|
+
if (this.vm && missing.length) {
|
|
46
|
+
const holds = [...this.holds];
|
|
47
|
+
if (holds.some((hold) => !hold.evict))
|
|
48
|
+
throw new Error(`${sandboxUnavailable().message}: the shared sandbox is in use and does not mount ${missing.map((mount) => mount.path).join(", ")}`);
|
|
49
|
+
for (const hold of holds)
|
|
50
|
+
hold.evict();
|
|
51
|
+
await Promise.all(holds.map((hold) => hold.released));
|
|
52
|
+
await this.vm.sandbox.close();
|
|
53
|
+
this.vm = undefined;
|
|
54
|
+
}
|
|
55
|
+
if (!this.vm) {
|
|
56
|
+
const folder = join(this.stateRoot, "sandbox");
|
|
57
|
+
mkdirSync(folder, { recursive: true, mode: 0o700 });
|
|
58
|
+
const name = `flow-shared-${createHash("sha256").update(this.stateRoot).digest("hex").slice(0, 16)}`;
|
|
59
|
+
const sandbox = await createSandbox(provider, { name, workspace, mounts, env: {} }, join(folder, "shared.json"), signal);
|
|
60
|
+
this.vm = { sandbox, mounts };
|
|
61
|
+
startup = sandbox.startup;
|
|
62
|
+
}
|
|
63
|
+
const unhold = this.vm.sandbox.hold();
|
|
64
|
+
let release;
|
|
65
|
+
const entry = { evict, released: new Promise((resolve) => { release = resolve; }) };
|
|
66
|
+
this.holds.add(entry);
|
|
67
|
+
return { sandbox: this.vm.sandbox, startup, release: () => { if (this.holds.delete(entry)) {
|
|
68
|
+
unhold();
|
|
69
|
+
release();
|
|
70
|
+
} } };
|
|
71
|
+
}
|
|
72
|
+
/** Removes the VM when the Session Host stops, after every hold is released. */
|
|
73
|
+
async close() {
|
|
74
|
+
await this.queue;
|
|
75
|
+
await this.vm?.sandbox.close();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -3,6 +3,7 @@ import { existsSync, mkdtempSync, realpathSync, rmSync, statSync } from 'node:fs
|
|
|
3
3
|
import { isAbsolute, join, resolve } from 'node:path';
|
|
4
4
|
import { parseValue, toTypeScript } from "./schema.js";
|
|
5
5
|
import { prepareFilesystemIsolation, validateFilesystemScope } from "../isolation/filesystem.js";
|
|
6
|
+
import { sandboxUnavailable } from "../isolation/sandbox.js";
|
|
6
7
|
const environment = { PATH: '/usr/local/bin:/usr/bin:/bin', LANG: 'C.UTF-8' };
|
|
7
8
|
function probe(command, args, stdioFds = [], env = environment) {
|
|
8
9
|
if (!isAbsolute(command))
|
|
@@ -15,7 +16,8 @@ function probe(command, args, stdioFds = [], env = environment) {
|
|
|
15
16
|
});
|
|
16
17
|
}
|
|
17
18
|
export async function createCodeExecutors(options) {
|
|
18
|
-
const
|
|
19
|
+
const isolationMode = options.isolationMode ?? 'bubblewrap';
|
|
20
|
+
const isolationEnabled = isolationMode !== 'none';
|
|
19
21
|
function canonicalScope(scope) {
|
|
20
22
|
if (isolationEnabled)
|
|
21
23
|
return validateFilesystemScope({ scope, expectedScope: resolve(scope),
|
|
@@ -32,6 +34,12 @@ export async function createCodeExecutors(options) {
|
|
|
32
34
|
const args = ['-e', 'process.exit(Number(process.versions.node.split(".")[0]) >= 22 ? 0 : 1)'];
|
|
33
35
|
if (!isolationEnabled)
|
|
34
36
|
return probe(options.nodePath, args);
|
|
37
|
+
if (isolationMode === 'sandbox') {
|
|
38
|
+
if (options.sandbox)
|
|
39
|
+
return true;
|
|
40
|
+
boundaryError = sandboxUnavailable().message;
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
35
43
|
const scope = mkdtempSync(join(realpathSync('/tmp'), 'flow-runtime-probe-'));
|
|
36
44
|
let isolation;
|
|
37
45
|
try {
|
|
@@ -91,7 +99,8 @@ export async function createCodeExecutors(options) {
|
|
|
91
99
|
const stateRoot = options.stateRoot ? { stateRoot: options.stateRoot } : {};
|
|
92
100
|
const scope = canonicalScope(context.scope);
|
|
93
101
|
const runtimePath = realpathSync(options.runtimePath);
|
|
94
|
-
const
|
|
102
|
+
const sandbox = isolationMode === 'sandbox' ? await options.sandbox(context.sessionId) : undefined;
|
|
103
|
+
const nodePath = sandbox ? sandbox.nodePath : realpathSync(options.nodePath);
|
|
95
104
|
const args = ['--noprofile', '--norc', '-c', 'ulimit -c 0; exec "$@"', 'flow-workflow', nodePath, '--max-old-space-size=128', runtimePath];
|
|
96
105
|
const timeout = Math.min(context.step.timeoutMs ?? 60_000, 2_147_000_000);
|
|
97
106
|
const request = JSON.stringify({ ...context.step, scope, input: context.input, inputType: inputSchema ? toTypeScript(inputSchema) : 'unknown', outputType: context.step.kind === 'typescript' ? toTypeScript(context.step.outputSchema) : 'unknown', secrets, timeout });
|
|
@@ -102,11 +111,13 @@ export async function createCodeExecutors(options) {
|
|
|
102
111
|
FLOW_BWRAP_PATH: process.env.FLOW_BWRAP_PATH, FLOW_STATE_DIR: process.env.FLOW_STATE_DIR,
|
|
103
112
|
HOME: process.env.HOME, PI_CODING_AGENT_DIR: process.env.PI_CODING_AGENT_DIR,
|
|
104
113
|
CLAUDE_CONFIG_DIR: process.env.CLAUDE_CONFIG_DIR };
|
|
105
|
-
const
|
|
114
|
+
const launch = sandbox?.command(scope, ['/bin/bash', ...args], environment);
|
|
115
|
+
const isolation = isolationEnabled && !sandbox ? await prepareFilesystemIsolation({ scope, expectedScope: resolve(context.scope),
|
|
106
116
|
...stateRoot, command: '/bin/bash', args, env, readablePaths: [nodePath, runtimePath], credentials: 'none' }) : undefined;
|
|
117
|
+
const release = sandbox?.hold();
|
|
107
118
|
try {
|
|
108
119
|
context.signal.throwIfAborted();
|
|
109
|
-
const child = spawn(isolation?.command ?? '/bin/bash', isolation?.args ?? args, { env: isolation?.env ?? environment, ...(!isolation ? { cwd: scope } : {}), detached: true,
|
|
120
|
+
const child = spawn(launch?.command ?? isolation?.command ?? '/bin/bash', launch?.args ?? isolation?.args ?? args, { env: launch ? process.env : isolation?.env ?? environment, ...(!isolation && !launch ? { cwd: scope } : {}), detached: true,
|
|
110
121
|
stdio: ['pipe', 'pipe', 'pipe', ...(isolation?.stdioFds ?? [])] });
|
|
111
122
|
let stdout = '', stderr = '', stopped = false;
|
|
112
123
|
// Restricted launches also end the PID namespace. Unrestricted detached descendants
|
|
@@ -167,6 +178,7 @@ export async function createCodeExecutors(options) {
|
|
|
167
178
|
}
|
|
168
179
|
finally {
|
|
169
180
|
isolation?.cleanup();
|
|
181
|
+
release?.();
|
|
170
182
|
}
|
|
171
183
|
}
|
|
172
184
|
return { shell: executor, typescript: executor };
|
|
@@ -2,13 +2,23 @@ import { Ajv } from 'ajv';
|
|
|
2
2
|
import { Ajv2019 } from 'ajv/dist/2019.js';
|
|
3
3
|
import { Ajv2020 } from 'ajv/dist/2020.js';
|
|
4
4
|
import { default as formats } from 'ajv-formats';
|
|
5
|
-
//
|
|
5
|
+
// Recognizable presentation annotations and `x-*` vendor extensions are ignored. Any other unknown keyword fails.
|
|
6
6
|
const annotationKeywords = ['example', 'externalDocs', 'xml', 'markdownDescription', 'enumDescriptions', 'enumNames', 'enumTitles'];
|
|
7
|
+
function extensionKeywords(value, found = new Set()) {
|
|
8
|
+
if (value && typeof value === 'object') {
|
|
9
|
+
for (const [key, child] of Object.entries(value)) {
|
|
10
|
+
if (key.startsWith('x-'))
|
|
11
|
+
found.add(key);
|
|
12
|
+
extensionKeywords(child, found);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return found;
|
|
16
|
+
}
|
|
7
17
|
// No coercion, defaults, removal of properties or remote schema fetching.
|
|
8
|
-
function engineFor(Engine) {
|
|
18
|
+
function engineFor(Engine, schema) {
|
|
9
19
|
const engine = new Engine({ strict: true, strictTypes: false, strictTuples: false, strictRequired: false, allowUnionTypes: true, allErrors: true });
|
|
10
20
|
formats(engine);
|
|
11
|
-
for (const keyword of annotationKeywords)
|
|
21
|
+
for (const keyword of [...annotationKeywords, ...extensionKeywords(schema)])
|
|
12
22
|
engine.addKeyword({ keyword, valid: true });
|
|
13
23
|
return engine;
|
|
14
24
|
}
|
|
@@ -19,7 +29,7 @@ export function compileJsonSchema(schema) {
|
|
|
19
29
|
if (prior)
|
|
20
30
|
return prior;
|
|
21
31
|
const dialect = typeof schema === 'object' ? schema.$schema : undefined;
|
|
22
|
-
const engine = engineFor(typeof dialect === 'string' && dialect.includes('draft-07') ? Ajv : typeof dialect === 'string' && dialect.includes('2019-09') ? Ajv2019 : Ajv2020);
|
|
32
|
+
const engine = engineFor(typeof dialect === 'string' && dialect.includes('draft-07') ? Ajv : typeof dialect === 'string' && dialect.includes('2019-09') ? Ajv2019 : Ajv2020, schema);
|
|
23
33
|
try {
|
|
24
34
|
const validator = engine.compile(schema);
|
|
25
35
|
if ('$async' in validator)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nathanstephenson/flow",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -15,19 +15,22 @@
|
|
|
15
15
|
"files": [
|
|
16
16
|
"dist/",
|
|
17
17
|
"web/dist/",
|
|
18
|
-
"build/workflow-runtime.cjs"
|
|
18
|
+
"build/workflow-runtime.cjs",
|
|
19
|
+
"build/backend-worker.mjs",
|
|
20
|
+
"build/backend-worker-chunks/"
|
|
19
21
|
],
|
|
20
22
|
"scripts": {
|
|
21
23
|
"build": "node scripts/build-cli.mjs",
|
|
22
|
-
"prepack": "npm run build && npm run build:web && npm run build:workflow-runtime",
|
|
24
|
+
"prepack": "npm run build && npm run build:web && npm run build:workflow-runtime && npm run build:worker",
|
|
23
25
|
"test:package": "node scripts/test-package.mjs",
|
|
24
26
|
"build:workflow-runtime": "node scripts/build-workflow-runtime.mjs",
|
|
27
|
+
"build:worker": "node scripts/build-worker.mjs",
|
|
25
28
|
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.presentation.json && tsc -p web/tsconfig.json --noEmit && tsc -p web/tsconfig.node.json --noEmit",
|
|
26
29
|
"dev": "vite --config web/vite.config.ts",
|
|
27
30
|
"test": "node --test --experimental-strip-types \"test/**/*.test.ts\" \"web/**/*.test.ts\"",
|
|
28
31
|
"spike:auth": "node --experimental-strip-types spikes/subscription-auth.ts",
|
|
29
32
|
"test:oidc-issuer": "node --experimental-strip-types scripts/test-oidc-issuer.ts",
|
|
30
|
-
"prestart": "npm run build:web && npm run build:workflow-runtime",
|
|
33
|
+
"prestart": "npm run build:web && npm run build:workflow-runtime && npm run build:worker",
|
|
31
34
|
"start": "node --experimental-strip-types src/cli/main.ts",
|
|
32
35
|
"spike:adapter": "node --experimental-strip-types spikes/adapter-smoke.ts",
|
|
33
36
|
"build:web": "node scripts/build-web.mjs",
|