@nathanstephenson/flow 0.1.6 → 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.
Files changed (76) hide show
  1. package/README.md +122 -640
  2. package/build/backend-worker-chunks/chunk-J2DBNTL7.mjs +94 -0
  3. package/build/backend-worker-chunks/chunk-MLOUI3ZM.mjs +19752 -0
  4. package/build/backend-worker-chunks/chunk-UQDH2COY.mjs +15296 -0
  5. package/build/backend-worker-chunks/claude-GTW5KHY5.mjs +30778 -0
  6. package/build/backend-worker-chunks/pi-M4OA2FGL.mjs +5730 -0
  7. package/build/backend-worker.mjs +4401 -0
  8. package/dist/backend/fake/index.js +2 -0
  9. package/dist/backend/mcp.js +34 -15
  10. package/dist/backend/pi/state.js +18 -0
  11. package/dist/backend/registry.js +2 -1
  12. package/dist/backend/worker/claude-state.js +24 -3
  13. package/dist/backend/worker/entry.js +70 -13
  14. package/dist/backend/worker/frames.js +34 -0
  15. package/dist/backend/worker/index.js +139 -16
  16. package/dist/backend/worker/launcher.js +22 -3
  17. package/dist/backend/worker/sandbox-mcp.js +86 -0
  18. package/dist/build-id +1 -1
  19. package/dist/cli/bootstrap.js +7 -6
  20. package/dist/cli/install-guard.js +1 -1
  21. package/dist/cli/main.js +3 -6
  22. package/dist/cli/update.js +3 -3
  23. package/dist/cli/web-update.js +9 -6
  24. package/dist/client/connection.js +5 -2
  25. package/dist/client/diff.js +6 -9
  26. package/dist/client/reduce.js +19 -0
  27. package/dist/client/tool-chains.js +12 -4
  28. package/dist/daemon/config-store.js +21 -14
  29. package/dist/daemon/config.js +48 -5
  30. package/dist/daemon/git.js +47 -0
  31. package/dist/daemon/host.js +208 -29
  32. package/dist/daemon/models.js +27 -24
  33. package/dist/daemon/release-checker.js +48 -34
  34. package/dist/daemon/runtime.js +10 -4
  35. package/dist/daemon/server.js +13 -1
  36. package/dist/daemon/shell.js +2 -1
  37. package/dist/daemon/skills.js +34 -31
  38. package/dist/daemon/summariser.js +33 -14
  39. package/dist/daemon/timings.js +14 -0
  40. package/dist/daemon/workflow-authoring-scope-checks.js +5 -26
  41. package/dist/daemon/workflow-authoring-scope-reader.js +20 -9
  42. package/dist/daemon/workflow-builder-files.js +5 -5
  43. package/dist/daemon/workflow-builder-guidance.js +3 -3
  44. package/dist/daemon/workflow-builder-reader.js +21 -10
  45. package/dist/daemon/workflow-builder.js +66 -8
  46. package/dist/daemon/workflow-executions.js +10 -10
  47. package/dist/daemon/workflow-mcp-authoring-routes.js +18 -6
  48. package/dist/daemon/workflow-mcp-authoring.js +50 -23
  49. package/dist/isolation/filesystem.js +8 -9
  50. package/dist/isolation/sandbox-supervisor.js +50 -0
  51. package/dist/isolation/sandbox.js +165 -0
  52. package/dist/isolation/shared-sandbox.js +77 -0
  53. package/dist/workflows/executors.js +16 -4
  54. package/dist/workflows/json-schema.js +14 -4
  55. package/package.json +7 -4
  56. package/web/dist/assets/index-CiEgCpiO.js +40 -0
  57. package/web/dist/assets/index-ClwLFMZN.css +2 -0
  58. package/web/dist/assets/settings-mcp-CoRWT-D_.js +1 -0
  59. package/web/dist/assets/settings-secrets-BIO_hXZ1.js +1 -0
  60. package/web/dist/assets/settings-workflows-BXbj0TKs.js +23 -0
  61. package/web/dist/assets/switch-DIogWclb.js +1 -0
  62. package/web/dist/assets/workflow-api-BfExddae.js +6 -0
  63. package/web/dist/assets/workflow-editors-CsbVx4WJ.js +139 -0
  64. package/web/dist/assets/workflows-Bv0sj7d0.js +7 -0
  65. package/web/dist/assets/workflows-pane-C_Yg4pgr.js +1 -0
  66. package/web/dist/index.html +5 -5
  67. package/web/dist/assets/index-C_M0oDHN.js +0 -38
  68. package/web/dist/assets/index-D8CGXp1X.css +0 -2
  69. package/web/dist/assets/input-D9fbSfQF.js +0 -6
  70. package/web/dist/assets/settings-mcp-BvSvGrcs.js +0 -1
  71. package/web/dist/assets/settings-secrets-DlkU6W_Z.js +0 -1
  72. package/web/dist/assets/settings-workflows-DNGE-b_U.js +0 -23
  73. package/web/dist/assets/switch-DEvHojwW.js +0 -1
  74. package/web/dist/assets/workflow-editors-D6XT6pcb.js +0 -137
  75. package/web/dist/assets/workflows-LSCnXIxN.js +0 -7
  76. package/web/dist/assets/workflows-pane-BIlp7uyg.js +0 -1
@@ -18,7 +18,10 @@
18
18
  */
19
19
  const TOOL_PREFIX = "tool:";
20
20
  const THINKING_PREFIX = "thinking:";
21
- /** Below this many adjacent tool calls a run is just some rows, and hiding them helps nobody. */
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
- export function toolChains(keys, min = MIN_CHAIN) {
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
- if (run.length >= min && run.some(isToolKey))
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(async () => {
43
- try {
44
- this.isolationSupport = { ...await this.isolationDetector({ stateRoot: this.root }) };
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 true stays enabled even if unsupported. */
53
- filesystemIsolationEnabled = () => this.config.filesystemIsolation ?? this.isolationSupport?.supported ?? true;
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
- supported: this.isolationSupport?.supported ?? false,
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 }),
@@ -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 (typeof value === "boolean")
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("filesystemIsolation must be true or false; using automatic selection");
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 (typeof value !== "boolean")
120
- throw new ConfigError("filesystemIsolation must be true, false, or null");
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) },
@@ -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
+ }