@nathanstephenson/flow 0.1.2 → 0.1.4

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 (74) hide show
  1. package/README.md +46 -2
  2. package/build/workflow-runtime.cjs +1 -46
  3. package/dist/backend/claude/index.js +135 -39
  4. package/dist/backend/claude/mcp.js +3 -1
  5. package/dist/backend/claude/permissions.js +26 -15
  6. package/dist/backend/claude/subagents.js +4 -0
  7. package/dist/backend/claude/workflow-parent.js +4 -1
  8. package/dist/backend/claude/workflow-subagent.js +2 -2
  9. package/dist/backend/mcp-stdio-supervisor.js +196 -0
  10. package/dist/backend/mcp.js +146 -51
  11. package/dist/backend/permission-errors.js +3 -0
  12. package/dist/backend/pi/agent-permissions.js +74 -0
  13. package/dist/backend/pi/auto-compaction.js +1 -3
  14. package/dist/backend/pi/compaction-model.js +38 -0
  15. package/dist/backend/pi/index.js +71 -24
  16. package/dist/backend/pi/work.js +1 -1
  17. package/dist/backend/pi/workflow-subagent.js +11 -2
  18. package/dist/backend/registry.js +5 -30
  19. package/dist/backend/worker/assets.js +16 -0
  20. package/dist/backend/worker/claude-state.js +61 -0
  21. package/dist/backend/worker/entry.js +186 -0
  22. package/dist/backend/worker/index.js +255 -0
  23. package/dist/backend/worker/launcher.js +67 -0
  24. package/dist/backend/worker/protocol.js +11 -0
  25. package/dist/backend/worker/rpc.js +108 -0
  26. package/dist/build-id +1 -1
  27. package/dist/cli/bootstrap.js +1 -1
  28. package/dist/cli/main.js +9 -1
  29. package/dist/client/connection.js +107 -2
  30. package/dist/client/diff.js +43 -0
  31. package/dist/client/reduce.js +3 -0
  32. package/dist/daemon/config-store.js +38 -2
  33. package/dist/daemon/config.js +110 -51
  34. package/dist/daemon/host.js +301 -30
  35. package/dist/daemon/log.js +98 -0
  36. package/dist/daemon/runtime.js +10 -1
  37. package/dist/daemon/server.js +67 -1
  38. package/dist/daemon/workflow-execution-routes.js +1 -1
  39. package/dist/daemon/workflow-executions.js +72 -27
  40. package/dist/daemon/workflow-mcp.js +2 -4
  41. package/dist/daemon/workflow-routes.js +4 -3
  42. package/dist/isolation/filesystem.js +382 -0
  43. package/dist/isolation/launcher.js +40 -0
  44. package/dist/isolation/node-assets.js +84 -0
  45. package/dist/isolation/support.js +40 -0
  46. package/dist/isolation/toolchain-assets.js +62 -0
  47. package/dist/protocol/presentation.js +230 -0
  48. package/dist/protocol/settings.js +1 -4
  49. package/dist/workflows/executors.js +118 -62
  50. package/dist/workflows/graph.js +3 -6
  51. package/dist/workflows/json-schema.js +8 -3
  52. package/dist/workflows/mcp.js +15 -1
  53. package/dist/workflows/runtime-settings.js +7 -7
  54. package/dist/workflows/runtime.js +1 -34
  55. package/package.json +5 -4
  56. package/web/dist/assets/index-Bn-ECZ7w.js +174 -0
  57. package/web/dist/assets/index-DL0CGVaN.css +2 -0
  58. package/web/dist/assets/input-NIrLDFaS.js +6 -0
  59. package/web/dist/assets/settings-mcp-B60T2XUv.js +1 -0
  60. package/web/dist/assets/settings-secrets-BtQwc-w4.js +1 -0
  61. package/web/dist/assets/settings-workflows-BZ4W0Ja8.js +23 -0
  62. package/web/dist/assets/switch-DyYU6B5T.js +1 -0
  63. package/web/dist/assets/workflows-BAdf2yKH.js +7 -0
  64. package/web/dist/assets/workflows-pane-MSSNIrgu.js +1 -0
  65. package/web/dist/index.html +4 -4
  66. package/web/dist/assets/index-BlZBshi8.js +0 -170
  67. package/web/dist/assets/index-DWF4-3Fh.css +0 -2
  68. package/web/dist/assets/select-6i3wxovH.js +0 -1
  69. package/web/dist/assets/settings-mcp-ZMIfuuZU.js +0 -1
  70. package/web/dist/assets/settings-secrets-CgTrBpi2.js +0 -1
  71. package/web/dist/assets/settings-workflows-1DMYfZtn.js +0 -23
  72. package/web/dist/assets/switch-ftZleVB8.js +0 -6
  73. package/web/dist/assets/workflows-CBuB_bva.js +0 -7
  74. package/web/dist/assets/workflows-pane-DPXGg0na.js +0 -1
@@ -2,6 +2,7 @@ import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
2
2
  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
+ import { detectFilesystemIsolationSupport, } from "../isolation/support.js";
5
6
  import { expandHome } from "./projects.js";
6
7
  import { defaultStateRoot } from "./store.js";
7
8
  /**
@@ -20,15 +21,43 @@ export class ConfigStore {
20
21
  path;
21
22
  root;
22
23
  config;
24
+ isolationSupport;
25
+ isolationInitialization;
26
+ isolationDetector;
23
27
  /** Why part of the file on disk was ignored, for the daemon to print on the way up. */
24
28
  warning;
25
- constructor(root = defaultStateRoot()) {
29
+ constructor(root = defaultStateRoot(), detector = detectFilesystemIsolationSupport) {
30
+ this.isolationDetector = detector;
26
31
  this.root = root;
27
32
  this.path = join(root, "config.json");
28
33
  const loaded = loadConfig(root);
29
34
  this.config = loaded.config;
30
35
  this.warning = loaded.warning;
31
36
  }
37
+ /**
38
+ * Probe once, including concurrent callers, and latch the automatic startup decision.
39
+ * A later failed restricted launch must never turn this policy off.
40
+ */
41
+ 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
+ });
50
+ await this.isolationInitialization;
51
+ }
52
+ /** Pending automatic selection is fail-closed; explicit true stays enabled even if unsupported. */
53
+ filesystemIsolationEnabled = () => this.config.filesystemIsolation ?? this.isolationSupport?.supported ?? true;
54
+ filesystemIsolationStatus = () => ({
55
+ supported: this.isolationSupport?.supported ?? false,
56
+ enabled: this.filesystemIsolationEnabled(),
57
+ automatic: this.config.filesystemIsolation === undefined,
58
+ checking: this.isolationSupport === undefined,
59
+ ...(this.isolationSupport?.reason === undefined ? {} : { reason: this.isolationSupport.reason }),
60
+ });
32
61
  /** The current Config, in the file's own units. Cheap: held in memory, not re-read. */
33
62
  current() {
34
63
  return this.config;
@@ -84,7 +113,8 @@ export class ConfigStore {
84
113
  * method rather than the store itself, for the reason `retention` is one.
85
114
  */
86
115
  defaultModel = (backend) => this.config.providers?.defaults?.[backend];
87
- autoCompaction = (backend) => structuredClone(this.config.providers?.autoCompaction?.[backend] ?? {});
116
+ autoCompaction = (backend) => structuredClone(this.config.providers?.autoCompaction?.[backend]);
117
+ compactionModel = (backend) => this.config.providers?.compactionModels?.[backend];
88
118
  defaultBackend = () => this.config.providers?.defaultBackend;
89
119
  /** The Summary Model, asked fresh. Undefined means no Agent Session is named by a model. */
90
120
  summaryModel = (backend) => {
@@ -96,6 +126,7 @@ export class ConfigStore {
96
126
  return { backend, ...summary };
97
127
  return providers?.summary?.backend === backend ? providers.summary : undefined;
98
128
  };
129
+ defaultPermissionMode = (backend) => this.config.providers?.permissionModes?.[backend];
99
130
  defaultEffort = (backend) => this.config.providers?.efforts?.[backend];
100
131
  /**
101
132
  * Grant a Standing Authorisation for one tool — what an Always decision leaves behind.
@@ -131,6 +162,10 @@ export class ConfigStore {
131
162
  // cleared. Both optional sections can be cleared, so both are deleted when absent — and for
132
163
  // `permissions` that is not tidiness: a section left behind would keep a Standing Authorisation
133
164
  // the human had just revoked.
165
+ // Keep automatic selection absent, including after reset or a leniently ignored disk value.
166
+ // Persisting the resolved default here would pin the next host to today's probe result.
167
+ if (next.filesystemIsolation === undefined)
168
+ delete document["filesystemIsolation"];
134
169
  if (next.projects === undefined)
135
170
  delete document["projects"];
136
171
  if (next.permissions === undefined)
@@ -174,6 +209,7 @@ function settingsOf(config) {
174
209
  fonts: config.fonts,
175
210
  mcp: config.mcp ?? [],
176
211
  workflowRuntime: { ...DEFAULT_WORKFLOW_RUNTIME, ...config.workflowRuntime },
212
+ ...(config.filesystemIsolation === undefined ? {} : { filesystemIsolation: config.filesystemIsolation }),
177
213
  // Omitted rather than defaulted when there is no Project Root, which is what
178
214
  // `Settings["projects"]` being optional means — see src/protocol/settings.ts.
179
215
  ...(config.projects === undefined ? {} : { projects: config.projects }),
@@ -31,10 +31,12 @@ export function loadConfig(stateRoot) {
31
31
  const projects = parseProjects(parsed, warnings);
32
32
  const permissions = parsePermissions(parsed, warnings);
33
33
  const providers = parseProviders(parsed, warnings);
34
+ const filesystemIsolation = readFilesystemIsolation(parsed, warnings);
34
35
  return {
35
36
  config: {
36
37
  retention,
37
38
  fonts,
39
+ ...(filesystemIsolation === undefined ? {} : { filesystemIsolation }),
38
40
  mcp: readMcp(parsed, warnings),
39
41
  workflowRuntime: readWorkflowRuntime(parsed, warnings),
40
42
  ...(projects === undefined ? {} : { projects }),
@@ -59,24 +61,19 @@ function patchWorkflowRuntime(current, patch) {
59
61
  if (!patch || typeof patch !== 'object' || Array.isArray(patch))
60
62
  throw new ConfigError('workflowRuntime must be an object');
61
63
  for (const [key, value] of Object.entries(patch)) {
62
- if (key === 'externalSandbox') {
63
- if (typeof value !== 'boolean')
64
- throw new ConfigError('workflowRuntime.externalSandbox must be boolean');
65
- next.externalSandbox = value;
66
- }
67
- else if (key === 'dockerImage' || key === 'nodePath' || key === 'dockerPath') {
64
+ if (key === 'nodePath') {
68
65
  if (typeof value !== 'string' || value.length > 4096 || /[\x00-\x1f]/.test(value))
69
- throw new ConfigError('Invalid workflowRuntime field');
70
- if (key !== 'dockerImage' && value === '') {
71
- delete next[key];
66
+ throw new ConfigError('workflowRuntime.nodePath must be an absolute executable path');
67
+ if (value === '') {
68
+ delete next.nodePath;
72
69
  continue;
73
70
  }
74
- if (key === 'dockerImage' ? !/^[A-Za-z0-9][A-Za-z0-9._/:@-]*$/.test(value) : !value.startsWith('/'))
75
- throw new ConfigError('Invalid workflowRuntime field');
76
- next[key] = value;
71
+ if (!value.startsWith('/'))
72
+ throw new ConfigError('workflowRuntime.nodePath must be absolute');
73
+ next.nodePath = value;
77
74
  }
78
75
  else
79
- throw new ConfigError('Unknown workflowRuntime field');
76
+ throw new ConfigError(`Unknown workflowRuntime field: ${key}`);
80
77
  }
81
78
  return next;
82
79
  }
@@ -90,17 +87,39 @@ function readWorkflowRuntime(parsed, warnings) {
90
87
  return result;
91
88
  }
92
89
  for (const [key, value] of Object.entries(section)) {
93
- if (!['externalSandbox', 'dockerImage', 'nodePath', 'dockerPath'].includes(key))
90
+ if (['externalSandbox', 'dockerImage', 'dockerPath'].includes(key)) {
91
+ warnings.push(`Retired workflowRuntime.${key} ignored: Docker Workflow execution was removed; local execution follows the machine-wide filesystem isolation setting`);
92
+ continue;
93
+ }
94
+ if (key !== 'nodePath')
94
95
  continue;
95
96
  try {
96
97
  result = patchWorkflowRuntime(result, { [key]: value });
97
98
  }
98
99
  catch {
99
- warnings.push('Invalid workflowRuntime field; using default');
100
+ warnings.push('Invalid workflowRuntime.nodePath; using automatic discovery');
100
101
  }
101
102
  }
102
103
  return result;
103
104
  }
105
+ function readFilesystemIsolation(parsed, warnings) {
106
+ const value = parsed?.filesystemIsolation;
107
+ if (value === undefined)
108
+ return undefined;
109
+ if (typeof value === "boolean")
110
+ return value;
111
+ warnings.push("filesystemIsolation must be true or false; using automatic selection");
112
+ return undefined;
113
+ }
114
+ function patchFilesystemIsolation(current, value) {
115
+ if (value === undefined)
116
+ return current;
117
+ if (value === null)
118
+ return undefined;
119
+ if (typeof value !== "boolean")
120
+ throw new ConfigError("filesystemIsolation must be true, false, or null");
121
+ return value;
122
+ }
104
123
  function parseProviders(parsed, warnings) {
105
124
  const section = parsed?.providers;
106
125
  if (section === undefined || section === null)
@@ -156,7 +175,7 @@ function parseProviders(parsed, warnings) {
156
175
  };
157
176
  }
158
177
  }
159
- for (const field of ["efforts", "summaries", "autoCompaction"]) {
178
+ for (const field of ["efforts", "summaries", "autoCompaction", "compactionModels", "permissionModes"]) {
160
179
  const entries = section[field];
161
180
  if (entries === undefined)
162
181
  continue;
@@ -166,15 +185,24 @@ function parseProviders(parsed, warnings) {
166
185
  }
167
186
  for (const [backend, value] of Object.entries(entries)) {
168
187
  try {
169
- if (field === "autoCompaction" && typeof value === "object" && value !== null && !Array.isArray(value)) {
170
- for (const [model, setting] of Object.entries(value)) {
171
- try {
172
- providers = patchProviders(providers, { autoCompaction: { [backend]: { [model]: setting } } }) ?? {};
173
- }
174
- catch (error) {
175
- warnings.push(String(error));
188
+ if (field === "autoCompaction" && typeof value === "object" && value !== null && !Array.isArray(value) && !("mode" in value)) {
189
+ // Older files mapped each backend to models. Only promote identical entries: choosing
190
+ // one of several conflicting policies would silently impose it on other models.
191
+ const legacy = Object.entries(value);
192
+ if (!legacy.length)
193
+ continue;
194
+ const validated = legacy.map(([model, setting]) => {
195
+ const entry = patchProviders(undefined, { autoCompaction: { [backend]: setting } })?.autoCompaction?.[backend];
196
+ if (checkModelId(model, `providers.autoCompaction.${backend}.${model}`) || model !== model.trim() || !entry) {
197
+ throw new ConfigError(`Invalid legacy auto-compaction setting for ${backend}/${model}; using backend default`);
176
198
  }
199
+ return entry;
200
+ });
201
+ if (!validated.every((setting) => JSON.stringify(setting) === JSON.stringify(validated[0]))) {
202
+ warnings.push(`Conflicting legacy auto-compaction settings for ${backend}; using backend default`);
203
+ continue;
177
204
  }
205
+ providers = patchProviders(providers, { autoCompaction: { [backend]: validated[0] } }) ?? {};
178
206
  }
179
207
  else
180
208
  providers = patchProviders(providers, { [field]: { [backend]: value } }) ?? {};
@@ -375,11 +403,13 @@ export function applyPatch(current, patch) {
375
403
  throw new ConfigError("expected an object");
376
404
  }
377
405
  const body = patch;
378
- refuseUnknownKeys(body, ["retention", "fonts", "projects", "permissions", "providers", "workflowRuntime", "mcp"], "config");
406
+ refuseUnknownKeys(body, ["retention", "fonts", "projects", "permissions", "providers", "workflowRuntime", "mcp", "filesystemIsolation"], "config");
379
407
  const projects = patchProjects(current.projects, body.projects);
380
408
  const permissions = patchPermissions(current.permissions, body.permissions);
381
409
  const providers = patchProviders(current.providers, body.providers);
410
+ const filesystemIsolation = patchFilesystemIsolation(current.filesystemIsolation, body.filesystemIsolation);
382
411
  return {
412
+ ...(filesystemIsolation === undefined ? {} : { filesystemIsolation }),
383
413
  mcp: body.mcp === undefined ? current.mcp ?? [] : parseMcp(body.mcp),
384
414
  workflowRuntime: patchWorkflowRuntime(current.workflowRuntime, body.workflowRuntime),
385
415
  retention: { settled: patchRetention(current.retention.settled, body.retention) },
@@ -404,11 +434,13 @@ export function applyPatch(current, patch) {
404
434
  function patchProviders(current, patch) {
405
435
  if (patch === undefined)
406
436
  return current;
407
- refuseUnknownKeys(patch, ["defaultBackend", "defaults", "summary", "efforts", "summaries", "autoCompaction"], "providers");
437
+ refuseUnknownKeys(patch, ["defaultBackend", "defaults", "summary", "efforts", "summaries", "autoCompaction", "compactionModels", "permissionModes"], "providers");
408
438
  const next = {
409
439
  ...(current?.autoCompaction === undefined ? {} : { autoCompaction: { ...current.autoCompaction } }),
440
+ ...(current?.compactionModels === undefined ? {} : { compactionModels: { ...current.compactionModels } }),
410
441
  ...(current?.defaultBackend === undefined ? {} : { defaultBackend: current.defaultBackend }),
411
442
  ...(current?.efforts === undefined ? {} : { efforts: { ...current.efforts } }),
443
+ ...(current?.permissionModes === undefined ? {} : { permissionModes: { ...current.permissionModes } }),
412
444
  ...(current?.summaries === undefined ? {} : { summaries: { ...current.summaries } }),
413
445
  ...(current?.defaults === undefined ? {} : { defaults: { ...current.defaults } }),
414
446
  ...(current?.summary === undefined ? {} : { summary: current.summary }),
@@ -429,41 +461,54 @@ function patchProviders(current, patch) {
429
461
  throw new ConfigError("providers.autoCompaction must be an object");
430
462
  }
431
463
  const merged = { ...next.autoCompaction };
432
- for (const [backend, models] of Object.entries(entries)) {
433
- const path = `providers.autoCompaction.${backend}`;
434
- if (backend !== backend.trim() || checkModelId(backend, path) || typeof models !== "object" || models === null || Array.isArray(models)) {
435
- throw new ConfigError(`${path} must map model ids to auto-compaction settings`);
464
+ for (const [backend, value] of Object.entries(entries)) {
465
+ const field = `providers.autoCompaction.${backend}`;
466
+ if (backend !== backend.trim() || checkModelId(backend, field))
467
+ throw new ConfigError(`${field} must name a backend without surrounding whitespace`);
468
+ if (value === null) {
469
+ delete merged[backend];
470
+ continue;
436
471
  }
437
- const values = { ...merged[backend] };
438
- for (const [model, value] of Object.entries(models)) {
439
- const field = `${path}.${model}`;
440
- if (model !== model.trim() || checkModelId(model, field))
441
- throw new ConfigError(`${field} must name a model without surrounding whitespace`);
442
- if (value === null) {
443
- delete values[model];
444
- continue;
445
- }
446
- if (typeof value !== "object" || Array.isArray(value))
447
- throw new ConfigError(`${field} must be an auto-compaction setting`);
448
- refuseUnknownKeys(value, value.mode === "disabled" ? ["mode"] : ["mode", "targetPercent"], field);
449
- if (value.mode === "disabled")
450
- values[model] = { mode: "disabled" };
451
- else if (value.mode === "enabled" && Number.isInteger(value.targetPercent) && value.targetPercent >= 1 && value.targetPercent <= 99) {
452
- values[model] = { mode: "enabled", targetPercent: value.targetPercent };
453
- }
454
- else
455
- throw new ConfigError(`${field} must be disabled or enabled with an integer targetPercent from 1 to 99`);
472
+ if (typeof value !== "object" || Array.isArray(value))
473
+ throw new ConfigError(`${field} must be an auto-compaction setting`);
474
+ refuseUnknownKeys(value, value.mode === "disabled" ? ["mode"] : ["mode", "targetPercent"], field);
475
+ if (value.mode === "disabled")
476
+ merged[backend] = { mode: "disabled" };
477
+ else if (value.mode === "enabled" && Number.isInteger(value.targetPercent) && value.targetPercent >= 1 && value.targetPercent <= 99) {
478
+ merged[backend] = { mode: "enabled", targetPercent: value.targetPercent };
456
479
  }
457
- if (Object.keys(values).length)
458
- merged[backend] = values;
459
480
  else
460
- delete merged[backend];
481
+ throw new ConfigError(`${field} must be disabled or enabled with an integer targetPercent from 1 to 99`);
461
482
  }
462
483
  if (Object.keys(merged).length)
463
484
  next.autoCompaction = merged;
464
485
  else
465
486
  delete next.autoCompaction;
466
487
  }
488
+ if (patch.compactionModels !== undefined) {
489
+ const entries = patch.compactionModels;
490
+ if (typeof entries !== "object" || entries === null || Array.isArray(entries)) {
491
+ throw new ConfigError("providers.compactionModels must map a backend to a model id");
492
+ }
493
+ const merged = { ...next.compactionModels };
494
+ for (const [backend, modelId] of Object.entries(entries)) {
495
+ const field = `providers.compactionModels.${backend}`;
496
+ if (backend !== "pi")
497
+ throw new ConfigError(`${field} is supported only by Pi`);
498
+ if (modelId === "") {
499
+ delete merged[backend];
500
+ continue;
501
+ }
502
+ const problem = checkModelId(modelId, field);
503
+ if (problem || modelId !== modelId.trim())
504
+ throw new ConfigError(problem ?? `${field} must name a model without surrounding whitespace`);
505
+ merged[backend] = modelId;
506
+ }
507
+ if (Object.keys(merged).length)
508
+ next.compactionModels = merged;
509
+ else
510
+ delete next.compactionModels;
511
+ }
467
512
  const defaults = patch.defaults;
468
513
  if (defaults !== undefined) {
469
514
  if (typeof defaults !== "object" || defaults === null || Array.isArray(defaults)) {
@@ -511,6 +556,20 @@ function patchProviders(current, patch) {
511
556
  };
512
557
  }
513
558
  }
559
+ if (patch.permissionModes !== undefined) {
560
+ if (typeof patch.permissionModes !== "object" || patch.permissionModes === null || Array.isArray(patch.permissionModes))
561
+ throw new ConfigError("providers.permissionModes must be an object");
562
+ const modes = { ...next.permissionModes };
563
+ for (const [backend, mode] of Object.entries(patch.permissionModes)) {
564
+ if (mode === "")
565
+ delete modes[backend];
566
+ else if ((backend === "claude" && ["ask", "auto", "always"].includes(mode)) || (backend === "pi" && ["ask", "always"].includes(mode)))
567
+ modes[backend] = mode;
568
+ else
569
+ throw new ConfigError(`Unsupported permission mode for ${backend}`);
570
+ }
571
+ next.permissionModes = modes;
572
+ }
514
573
  for (const field of ["efforts", "summaries"]) {
515
574
  const entries = patch[field];
516
575
  if (entries === undefined)