@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
|
@@ -18,7 +18,10 @@
|
|
|
18
18
|
*/
|
|
19
19
|
const TOOL_PREFIX = "tool:";
|
|
20
20
|
const THINKING_PREFIX = "thinking:";
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Below this many adjacent rows a run is just some rows, and hiding them helps nobody. A chain also
|
|
23
|
+
* needs two calls, one of them a tool call: one call beside some thinking is not a run of tools.
|
|
24
|
+
*/
|
|
22
25
|
const MIN_CHAIN = 3;
|
|
23
26
|
export const isToolKey = (key) => key.startsWith(TOOL_PREFIX);
|
|
24
27
|
/**
|
|
@@ -28,11 +31,16 @@ export const isToolKey = (key) => key.startsWith(TOOL_PREFIX);
|
|
|
28
31
|
* A run of thinking alone is not a chain, though: there is no tool in it to name.
|
|
29
32
|
*/
|
|
30
33
|
const isChainable = (key) => isToolKey(key) || key.startsWith(THINKING_PREFIX);
|
|
31
|
-
|
|
34
|
+
/**
|
|
35
|
+
* `ridesAlong` lets a caller fold in more calls — the web client passes finished Background Calls,
|
|
36
|
+
* which it can tell apart only by reading their Entries. They count as calls, but never chain alone.
|
|
37
|
+
*/
|
|
38
|
+
export function toolChains(keys, min = MIN_CHAIN, ridesAlong = () => false) {
|
|
32
39
|
const segments = [];
|
|
33
40
|
let run = [];
|
|
34
41
|
const flush = () => {
|
|
35
|
-
|
|
42
|
+
const calls = run.filter((key) => isToolKey(key) || ridesAlong(key)).length;
|
|
43
|
+
if (run.length >= min && calls >= 2 && run.some(isToolKey))
|
|
36
44
|
segments.push({ kind: "chain", keys: run });
|
|
37
45
|
else
|
|
38
46
|
for (const key of run)
|
|
@@ -40,7 +48,7 @@ export function toolChains(keys, min = MIN_CHAIN) {
|
|
|
40
48
|
run = [];
|
|
41
49
|
};
|
|
42
50
|
for (const key of keys) {
|
|
43
|
-
if (isChainable(key)) {
|
|
51
|
+
if (isChainable(key) || ridesAlong(key)) {
|
|
44
52
|
run.push(key);
|
|
45
53
|
continue;
|
|
46
54
|
}
|
|
@@ -3,6 +3,7 @@ import { join } from "node:path";
|
|
|
3
3
|
import { applyPatch, formatDuration, loadConfig, } from "./config.js";
|
|
4
4
|
import { DEFAULT_WORKFLOW_RUNTIME } from "../protocol/settings.js";
|
|
5
5
|
import { detectFilesystemIsolationSupport, } from "../isolation/support.js";
|
|
6
|
+
import { detectSandboxSupport } from "../isolation/sandbox.js";
|
|
6
7
|
import { expandHome } from "./projects.js";
|
|
7
8
|
import { defaultStateRoot } from "./store.js";
|
|
8
9
|
/**
|
|
@@ -24,10 +25,13 @@ export class ConfigStore {
|
|
|
24
25
|
isolationSupport;
|
|
25
26
|
isolationInitialization;
|
|
26
27
|
isolationDetector;
|
|
28
|
+
sandboxDetector;
|
|
29
|
+
sandbox;
|
|
27
30
|
/** Why part of the file on disk was ignored, for the daemon to print on the way up. */
|
|
28
31
|
warning;
|
|
29
|
-
constructor(root = defaultStateRoot(), detector = detectFilesystemIsolationSupport) {
|
|
32
|
+
constructor(root = defaultStateRoot(), detector = detectFilesystemIsolationSupport, sandboxDetector = detectSandboxSupport) {
|
|
30
33
|
this.isolationDetector = detector;
|
|
34
|
+
this.sandboxDetector = sandboxDetector;
|
|
31
35
|
this.root = root;
|
|
32
36
|
this.path = join(root, "config.json");
|
|
33
37
|
const loaded = loadConfig(root);
|
|
@@ -39,25 +43,26 @@ export class ConfigStore {
|
|
|
39
43
|
* A later failed restricted launch must never turn this policy off.
|
|
40
44
|
*/
|
|
41
45
|
async initializeFilesystemIsolation() {
|
|
42
|
-
this.isolationInitialization ??= Promise.resolve().then(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
catch (error) {
|
|
47
|
-
this.isolationSupport = { supported: false, reason: error instanceof Error ? error.message : String(error) };
|
|
48
|
-
}
|
|
49
|
-
});
|
|
46
|
+
this.isolationInitialization ??= Promise.resolve().then(() => Promise.all([
|
|
47
|
+
this.isolationDetector({ stateRoot: this.root }).then((support) => { this.isolationSupport = { ...support }; }, (error) => { this.isolationSupport = { supported: false, reason: error instanceof Error ? error.message : String(error) }; }),
|
|
48
|
+
this.sandboxDetector({ stateRoot: this.root }).then((support) => { this.sandbox = support; }, (error) => { this.sandbox = { supported: false, reason: error instanceof Error ? error.message : String(error) }; }),
|
|
49
|
+
])).then(() => { });
|
|
50
50
|
await this.isolationInitialization;
|
|
51
51
|
}
|
|
52
|
-
/** Pending automatic selection is fail-closed; explicit
|
|
53
|
-
|
|
52
|
+
/** Pending automatic selection is fail-closed; an explicit restricted mode stays selected even if unsupported. */
|
|
53
|
+
filesystemIsolationMode = () => this.config.filesystemIsolation ?? (this.isolationSupport?.supported ?? true ? "bubblewrap" : "none");
|
|
54
54
|
filesystemIsolationStatus = () => ({
|
|
55
|
-
|
|
56
|
-
enabled: this.filesystemIsolationEnabled(),
|
|
55
|
+
mode: this.filesystemIsolationMode(),
|
|
57
56
|
automatic: this.config.filesystemIsolation === undefined,
|
|
58
|
-
checking: this.isolationSupport === undefined,
|
|
57
|
+
checking: this.isolationSupport === undefined || this.sandbox === undefined,
|
|
58
|
+
supported: this.isolationSupport?.supported ?? false,
|
|
59
59
|
...(this.isolationSupport?.reason === undefined ? {} : { reason: this.isolationSupport.reason }),
|
|
60
|
+
sandbox: this.sandbox?.supported ? { supported: true, path: this.sandbox.path } : { supported: false, reason: this.sandbox?.reason ?? "Checking the sandbox provider." },
|
|
60
61
|
});
|
|
62
|
+
sandboxSupport = () => this.sandbox;
|
|
63
|
+
/** Read when a sandbox-mode Backend Session starts. */
|
|
64
|
+
sandboxSharing = () => this.config.sandboxSharing ?? "session";
|
|
65
|
+
updateChannel = () => this.config.updateChannel ?? "stable";
|
|
61
66
|
/** The current Config, in the file's own units. Cheap: held in memory, not re-read. */
|
|
62
67
|
current() {
|
|
63
68
|
return this.config;
|
|
@@ -210,6 +215,8 @@ function settingsOf(config) {
|
|
|
210
215
|
mcp: config.mcp ?? [],
|
|
211
216
|
workflowRuntime: { ...DEFAULT_WORKFLOW_RUNTIME, ...config.workflowRuntime },
|
|
212
217
|
...(config.filesystemIsolation === undefined ? {} : { filesystemIsolation: config.filesystemIsolation }),
|
|
218
|
+
...(config.sandboxSharing === undefined ? {} : { sandboxSharing: config.sandboxSharing }),
|
|
219
|
+
...(config.updateChannel === undefined ? {} : { updateChannel: config.updateChannel }),
|
|
213
220
|
// Omitted rather than defaulted when there is no Project Root, which is what
|
|
214
221
|
// `Settings["projects"]` being optional means — see src/protocol/settings.ts.
|
|
215
222
|
...(config.projects === undefined ? {} : { projects: config.projects }),
|
package/dist/daemon/config.js
CHANGED
|
@@ -32,11 +32,15 @@ export function loadConfig(stateRoot) {
|
|
|
32
32
|
const permissions = parsePermissions(parsed, warnings);
|
|
33
33
|
const providers = parseProviders(parsed, warnings);
|
|
34
34
|
const filesystemIsolation = readFilesystemIsolation(parsed, warnings);
|
|
35
|
+
const sandboxSharing = readSandboxSharing(parsed, warnings);
|
|
36
|
+
const updateChannel = readUpdateChannel(parsed, warnings);
|
|
35
37
|
return {
|
|
36
38
|
config: {
|
|
37
39
|
retention,
|
|
38
40
|
fonts,
|
|
39
41
|
...(filesystemIsolation === undefined ? {} : { filesystemIsolation }),
|
|
42
|
+
...(sandboxSharing === undefined ? {} : { sandboxSharing }),
|
|
43
|
+
...(updateChannel === undefined ? {} : { updateChannel }),
|
|
40
44
|
mcp: readMcp(parsed, warnings),
|
|
41
45
|
workflowRuntime: readWorkflowRuntime(parsed, warnings),
|
|
42
46
|
...(projects === undefined ? {} : { projects }),
|
|
@@ -102,13 +106,18 @@ function readWorkflowRuntime(parsed, warnings) {
|
|
|
102
106
|
}
|
|
103
107
|
return result;
|
|
104
108
|
}
|
|
109
|
+
const isolationModes = ["none", "bubblewrap", "sandbox"];
|
|
105
110
|
function readFilesystemIsolation(parsed, warnings) {
|
|
106
111
|
const value = parsed?.filesystemIsolation;
|
|
107
112
|
if (value === undefined)
|
|
108
113
|
return undefined;
|
|
109
|
-
if (
|
|
114
|
+
if (value === true)
|
|
115
|
+
return "bubblewrap";
|
|
116
|
+
if (value === false)
|
|
117
|
+
return "none";
|
|
118
|
+
if (isolationModes.includes(value))
|
|
110
119
|
return value;
|
|
111
|
-
warnings.push(
|
|
120
|
+
warnings.push('filesystemIsolation must be "none", "bubblewrap" or "sandbox"; using automatic selection');
|
|
112
121
|
return undefined;
|
|
113
122
|
}
|
|
114
123
|
function patchFilesystemIsolation(current, value) {
|
|
@@ -116,8 +125,38 @@ function patchFilesystemIsolation(current, value) {
|
|
|
116
125
|
return current;
|
|
117
126
|
if (value === null)
|
|
118
127
|
return undefined;
|
|
119
|
-
if (
|
|
120
|
-
throw new ConfigError(
|
|
128
|
+
if (!isolationModes.includes(value))
|
|
129
|
+
throw new ConfigError('filesystemIsolation must be "none", "bubblewrap", "sandbox", or null');
|
|
130
|
+
return value;
|
|
131
|
+
}
|
|
132
|
+
const sharingModes = ["session", "shared"];
|
|
133
|
+
function readSandboxSharing(parsed, warnings) {
|
|
134
|
+
const value = parsed?.sandboxSharing;
|
|
135
|
+
if (value === undefined || sharingModes.includes(value))
|
|
136
|
+
return value;
|
|
137
|
+
warnings.push('sandboxSharing must be "session" or "shared"; using "session"');
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
function patchSandboxSharing(current, value) {
|
|
141
|
+
if (value === undefined)
|
|
142
|
+
return current;
|
|
143
|
+
if (!sharingModes.includes(value))
|
|
144
|
+
throw new ConfigError('sandboxSharing must be "session" or "shared"');
|
|
145
|
+
return value;
|
|
146
|
+
}
|
|
147
|
+
const updateChannels = ["stable", "beta"];
|
|
148
|
+
function readUpdateChannel(parsed, warnings) {
|
|
149
|
+
const value = parsed?.updateChannel;
|
|
150
|
+
if (value === undefined || updateChannels.includes(value))
|
|
151
|
+
return value;
|
|
152
|
+
warnings.push('updateChannel must be "stable" or "beta"; using "stable"');
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
function patchUpdateChannel(current, value) {
|
|
156
|
+
if (value === undefined)
|
|
157
|
+
return current;
|
|
158
|
+
if (!updateChannels.includes(value))
|
|
159
|
+
throw new ConfigError('updateChannel must be "stable" or "beta"');
|
|
121
160
|
return value;
|
|
122
161
|
}
|
|
123
162
|
function parseProviders(parsed, warnings) {
|
|
@@ -403,13 +442,17 @@ export function applyPatch(current, patch) {
|
|
|
403
442
|
throw new ConfigError("expected an object");
|
|
404
443
|
}
|
|
405
444
|
const body = patch;
|
|
406
|
-
refuseUnknownKeys(body, ["retention", "fonts", "projects", "permissions", "providers", "workflowRuntime", "mcp", "filesystemIsolation"], "config");
|
|
445
|
+
refuseUnknownKeys(body, ["retention", "fonts", "projects", "permissions", "providers", "workflowRuntime", "mcp", "filesystemIsolation", "sandboxSharing", "updateChannel"], "config");
|
|
407
446
|
const projects = patchProjects(current.projects, body.projects);
|
|
408
447
|
const permissions = patchPermissions(current.permissions, body.permissions);
|
|
409
448
|
const providers = patchProviders(current.providers, body.providers);
|
|
410
449
|
const filesystemIsolation = patchFilesystemIsolation(current.filesystemIsolation, body.filesystemIsolation);
|
|
450
|
+
const sandboxSharing = patchSandboxSharing(current.sandboxSharing, body.sandboxSharing);
|
|
451
|
+
const updateChannel = patchUpdateChannel(current.updateChannel, body.updateChannel);
|
|
411
452
|
return {
|
|
412
453
|
...(filesystemIsolation === undefined ? {} : { filesystemIsolation }),
|
|
454
|
+
...(sandboxSharing === undefined ? {} : { sandboxSharing }),
|
|
455
|
+
...(updateChannel === undefined ? {} : { updateChannel }),
|
|
413
456
|
mcp: body.mcp === undefined ? current.mcp ?? [] : parseMcp(body.mcp),
|
|
414
457
|
workflowRuntime: patchWorkflowRuntime(current.workflowRuntime, body.workflowRuntime),
|
|
415
458
|
retention: { settled: patchRetention(current.retention.settled, body.retention) },
|
package/dist/daemon/git.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
2
3
|
import { existsSync, statSync } from "node:fs";
|
|
3
4
|
import { basename, join } from "node:path";
|
|
4
5
|
import { promisify } from "node:util";
|
|
@@ -296,6 +297,33 @@ export async function createWorktree(options) {
|
|
|
296
297
|
return added;
|
|
297
298
|
return { ok: true, value: planned.value };
|
|
298
299
|
}
|
|
300
|
+
export async function removeMergedBranch(repo, branch) {
|
|
301
|
+
const target = await head(repo);
|
|
302
|
+
if (!target.ok)
|
|
303
|
+
return target;
|
|
304
|
+
if (target.value.detached)
|
|
305
|
+
return refuse(`delete refs/heads/${branch}`, "The source repository has a detached HEAD");
|
|
306
|
+
const branchRef = `refs/heads/${branch}`;
|
|
307
|
+
const targetRef = `refs/heads/${target.value.name}`;
|
|
308
|
+
const merged = await run(repo, ["merge-base", "--is-ancestor", branchRef, targetRef], GIT_READ_TIMEOUT_MS);
|
|
309
|
+
if (!merged.ok)
|
|
310
|
+
return merged;
|
|
311
|
+
const configured = await run(repo, ["config", "--get-all", `branch.${branch}.merge`], GIT_READ_TIMEOUT_MS);
|
|
312
|
+
if (!configured.ok && configured.failure.code !== 1)
|
|
313
|
+
return configured;
|
|
314
|
+
const mergeRef = configured.ok ? configured.value.trim().split("\n")[0] : branchRef;
|
|
315
|
+
const cleanupRemote = `flow-cleanup-${randomUUID()}`;
|
|
316
|
+
const removed = await run(repo, [
|
|
317
|
+
"-c", `branch.${branch}.remote=${cleanupRemote}`,
|
|
318
|
+
"-c", `branch.${branch}.merge=${mergeRef}`,
|
|
319
|
+
"-c", `remote.${cleanupRemote}.url=.`,
|
|
320
|
+
"-c", `remote.${cleanupRemote}.fetch=${mergeRef}:${targetRef}`,
|
|
321
|
+
"branch", "-d", "--", branch,
|
|
322
|
+
], GIT_WRITE_TIMEOUT_MS);
|
|
323
|
+
if (!removed.ok)
|
|
324
|
+
return removed;
|
|
325
|
+
return { ok: true, value: undefined };
|
|
326
|
+
}
|
|
299
327
|
/**
|
|
300
328
|
* Remove a worktree this host created.
|
|
301
329
|
*
|
|
@@ -310,3 +338,22 @@ export async function removeWorktree(options) {
|
|
|
310
338
|
return removed;
|
|
311
339
|
return { ok: true, value: undefined };
|
|
312
340
|
}
|
|
341
|
+
/**
|
|
342
|
+
* Reconnect a worktree and its repository after one or both moved. Run from the repository.
|
|
343
|
+
*
|
|
344
|
+
* git can accept a path that is not a worktree of this repository, so the link is read back.
|
|
345
|
+
*/
|
|
346
|
+
export async function repairWorktree(repo, path) {
|
|
347
|
+
const repaired = await run(repo, ["worktree", "repair", path], GIT_WRITE_TIMEOUT_MS);
|
|
348
|
+
if (!repaired.ok)
|
|
349
|
+
return repaired;
|
|
350
|
+
const common = await run(path, ["rev-parse", "--path-format=absolute", "--git-common-dir"], GIT_READ_TIMEOUT_MS);
|
|
351
|
+
if (!common.ok)
|
|
352
|
+
return common;
|
|
353
|
+
const expected = await run(repo, ["rev-parse", "--path-format=absolute", "--git-common-dir"], GIT_READ_TIMEOUT_MS);
|
|
354
|
+
if (!expected.ok)
|
|
355
|
+
return expected;
|
|
356
|
+
if (common.value.trim() !== expected.value.trim())
|
|
357
|
+
return refuse(`worktree repair ${path}`, `${path} is not a worktree of ${repo}`);
|
|
358
|
+
return { ok: true, value: undefined };
|
|
359
|
+
}
|