@nathanstephenson/flow 0.1.10-beta.7 → 0.1.10-beta.9

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 (42) hide show
  1. package/build/backend-worker-chunks/{claude-THGSOTC2.mjs → claude-X57GT57M.mjs} +12 -4
  2. package/build/backend-worker-chunks/{pi-5LAWIJNE.mjs → pi-IZ3GX6HN.mjs} +5 -1
  3. package/build/backend-worker.mjs +7 -4
  4. package/dist/backend/claude/index.js +15 -4
  5. package/dist/backend/mcp.js +4 -1
  6. package/dist/backend/pi/index.js +6 -1
  7. package/dist/backend/worker/index.js +8 -3
  8. package/dist/build-id +1 -1
  9. package/dist/cli/bootstrap.js +1 -1
  10. package/dist/client/connection.js +46 -0
  11. package/dist/client/project-name.js +3 -1
  12. package/dist/client/reduce.js +1 -0
  13. package/dist/client/scope-kind.js +4 -0
  14. package/dist/daemon/changes.js +22 -12
  15. package/dist/daemon/git.js +10 -1
  16. package/dist/daemon/host.js +263 -47
  17. package/dist/daemon/pull-request.js +92 -34
  18. package/dist/daemon/repository.js +26 -9
  19. package/dist/daemon/runtime.js +2 -0
  20. package/dist/daemon/server.js +25 -0
  21. package/dist/daemon/stack.js +37 -3
  22. package/dist/daemon/tour.js +7 -1
  23. package/dist/daemon/workflow-environment.js +6 -4
  24. package/dist/daemon/workflow-executions.js +1 -1
  25. package/dist/isolation/filesystem.js +1 -1
  26. package/dist/protocol/spend.js +1 -1
  27. package/dist/protocol/stack.js +14 -1
  28. package/dist/workflows/executors.js +2 -1
  29. package/package.json +1 -1
  30. package/web/dist/assets/index-CHFNROUs.js +51 -0
  31. package/web/dist/assets/index-D9AneSPi.css +2 -0
  32. package/web/dist/assets/{select-C-BND5Jn.js → select-COVn-75j.js} +1 -1
  33. package/web/dist/assets/{settings-mcp-CBXZt_cf.js → settings-mcp-BHZwEeJF.js} +1 -1
  34. package/web/dist/assets/{settings-secrets-29ZG3w6p.js → settings-secrets-NGSRhEbU.js} +1 -1
  35. package/web/dist/assets/settings-workflows-uew3ONyO.js +23 -0
  36. package/web/dist/assets/{workflow-api-DkUjAZ4w.js → workflow-api-3z2Qqsmo.js} +1 -1
  37. package/web/dist/assets/{workflows-DdogjBu3.js → workflows-hcZXxss1.js} +14 -14
  38. package/web/dist/assets/{workflows-pane-B0dyuSuz.js → workflows-pane-DntY7Dcw.js} +1 -1
  39. package/web/dist/index.html +5 -5
  40. package/web/dist/assets/index-5E7qbtVD.js +0 -51
  41. package/web/dist/assets/index-BvkM2cWL.css +0 -2
  42. package/web/dist/assets/settings-workflows-CE11fxNj.js +0 -23
@@ -34745,6 +34745,10 @@ var DEFAULT_ALLOWED_TOOLS = [
34745
34745
  // what it cannot show is what the Subagent spent, which is a different measure.
34746
34746
  "Agent"
34747
34747
  ];
34748
+ function readOnlyDeniedTools(readOnly) {
34749
+ if (!readOnly) return [];
34750
+ return ["Write", "Edit", "NotebookEdit", ...readOnly === "tools" ? ["Bash", "mcp__workflow__bash"] : []];
34751
+ }
34748
34752
  var ClaudeSession = class {
34749
34753
  capabilities = { providers: ["anthropic"], models: [], compaction: true, autoCompaction: "startup", fork: true, rewind: true, rewindFiles: true, subagents: true, enquiries: true, permissions: true };
34750
34754
  inbox = new AsyncQueue();
@@ -34807,6 +34811,7 @@ var ClaudeSession = class {
34807
34811
  priorSpend;
34808
34812
  options;
34809
34813
  backendOptions;
34814
+ disallowedTools;
34810
34815
  workflowAutoCompaction;
34811
34816
  claudeState;
34812
34817
  constructor(options, backendOptions, claudeState, resumeAt) {
@@ -34814,6 +34819,8 @@ var ClaudeSession = class {
34814
34819
  this.parentWorkflow = options.workflowBuilder ? workflowBuilderServer(options.workflowBuilder) : workflowParentServer(options.tools === "none" ? void 0 : options.workflow);
34815
34820
  this.parentSessions = sessionToolsServer(options.workflowBuilder || options.tools === "none" ? void 0 : options.sessionTools);
34816
34821
  if (options.workflowBuilder) this.capabilities = { ...this.capabilities, subagents: false, enquiries: false, permissions: false };
34822
+ if (options.readOnly) this.capabilities = { ...this.capabilities, rewindFiles: false };
34823
+ this.disallowedTools = [...backendOptions.disallowedTools ?? [], ...readOnlyDeniedTools(options.readOnly)];
34817
34824
  this.options = options;
34818
34825
  this.permissionMode = options.permissionMode ?? "ask";
34819
34826
  this.backendOptions = backendOptions;
@@ -34826,7 +34833,7 @@ var ClaudeSession = class {
34826
34833
  this.spend = options.priorSpend;
34827
34834
  const builder = options.workflowBuilder;
34828
34835
  const toolless = !builder && options.tools === "none";
34829
- const preApproved = builder ? claudeWorkflowBuilderToolNames : toolless ? [] : [...backendOptions.allowedTools ?? DEFAULT_ALLOWED_TOOLS, ...options.workflow ? ["mcp__flow_workflow__workflow_inspect", "mcp__flow_workflow__workflow_recover", "mcp__flow_workflow__workflow_relay_enquiry", "mcp__flow_workflow__workflow_relay_permission"] : []];
34836
+ const preApproved = builder ? claudeWorkflowBuilderToolNames : toolless ? [] : [...(backendOptions.allowedTools ?? DEFAULT_ALLOWED_TOOLS).filter((tool) => !this.disallowedTools.includes(tool)), ...options.workflow ? ["mcp__flow_workflow__workflow_inspect", "mcp__flow_workflow__workflow_recover", "mcp__flow_workflow__workflow_relay_enquiry", "mcp__flow_workflow__workflow_relay_permission"] : []];
34830
34837
  if (!builder && !toolless && options.sessionTools) preApproved.push(...claudeSessionReadTools);
34831
34838
  this.allowed = new Set(toolless ? [] : [...preApproved, ...options.standingAuthorisations ?? []]);
34832
34839
  const startingEffort = sdkEffort(options.effort);
@@ -34858,7 +34865,7 @@ var ClaudeSession = class {
34858
34865
  // set, and canUseTool catches only the fall-through so nothing can stall waiting on a prompt.
34859
34866
  permissionMode: "default",
34860
34867
  allowedTools: preApproved,
34861
- ...backendOptions.disallowedTools ? { disallowedTools: backendOptions.disallowedTools } : {},
34868
+ ...this.disallowedTools.length ? { disallowedTools: this.disallowedTools } : {},
34862
34869
  ...builder ? {
34863
34870
  tools: [],
34864
34871
  settingSources: [],
@@ -34881,7 +34888,7 @@ var ClaudeSession = class {
34881
34888
  ...startingEffort ? { effort: startingEffort } : {},
34882
34889
  ...options.resume ? { resume: options.resume } : {},
34883
34890
  ...resumeAt ? { resumeSessionAt: resumeAt } : {},
34884
- ...builder || toolless ? {} : { enableFileCheckpointing: true },
34891
+ ...builder || toolless || options.readOnly ? {} : { enableFileCheckpointing: true },
34885
34892
  ...backendOptions.pathToClaudeCodeExecutable ? { pathToClaudeCodeExecutable: backendOptions.pathToClaudeCodeExecutable } : {},
34886
34893
  ...isSingleExecutable() ? { spawnClaudeCodeProcess: spawnClaudeDirectly } : {},
34887
34894
  /*
@@ -34904,6 +34911,7 @@ var ClaudeSession = class {
34904
34911
  behavior: "deny",
34905
34912
  message: "Agent Session tools are available only to the parent Agent Session"
34906
34913
  };
34914
+ if (this.disallowedTools.includes(toolName)) return { behavior: "deny", message: `${toolName} is disabled for this session` };
34907
34915
  if (toolName === ASK_TOOL) return await this.ask(extra.toolUseID, input);
34908
34916
  if (this.permissionMode === "always" || this.allowed.has(toolName) || this.workflowGrants.has(toolName)) return { behavior: "allow", updatedInput: input };
34909
34917
  const producer = extra.agentID ? this.subagents.callIdOf(extra.agentID) ?? extra.agentID : "";
@@ -35237,7 +35245,7 @@ var ClaudeSession = class {
35237
35245
  const handle = new ClaudeWorkflowSubagent({
35238
35246
  cwd: this.options.scope,
35239
35247
  mcpServers: claudeMcpServers(this.options.mcp),
35240
- ...this.backendOptions.disallowedTools ? { disallowedTools: this.backendOptions.disallowedTools } : {},
35248
+ ...this.disallowedTools.length ? { disallowedTools: this.disallowedTools } : {},
35241
35249
  ...this.backendOptions.pathToClaudeCodeExecutable ? { pathToClaudeCodeExecutable: this.backendOptions.pathToClaudeCodeExecutable } : {}
35242
35250
  }, options, this.workflowGrants, {
35243
35251
  ...this.backendOptions.query ? { query: this.backendOptions.query } : {},
@@ -7526,7 +7526,7 @@ var PiBackend = class {
7526
7526
  ASK_TOOL,
7527
7527
  SUBAGENT_TOOL,
7528
7528
  ...defaults.includes("bash") ? ["bash_output", "kill_shell"] : []
7529
- ]];
7529
+ ]].filter((name) => !readOnlyDeniedTools(options.readOnly).includes(name));
7530
7530
  const mcp = builder || options.tools === "none" ? void 0 : options.mcp;
7531
7531
  const workflowTools = workflowParentTools(builder || options.tools === "none" ? void 0 : options.workflow);
7532
7532
  const sessionTools = piSessionTools(builder || options.tools === "none" ? void 0 : options.sessionTools);
@@ -7599,6 +7599,10 @@ var PiBackend = class {
7599
7599
  return piSession;
7600
7600
  }
7601
7601
  };
7602
+ function readOnlyDeniedTools(readOnly) {
7603
+ if (!readOnly) return [];
7604
+ return ["edit", "write", ...readOnly === "tools" ? ["bash", "bash_output", "kill_shell", "powershell"] : []];
7605
+ }
7602
7606
  async function runSubagent(parent, scope, agentDir, work, id, input, signal, emit, mcp, compactionModelId, agentPermissions) {
7603
7607
  const available = parent.modelRuntime.getAvailableSnapshot();
7604
7608
  const model = input.model ? findPiModel(available, input.model) : parent.model;
@@ -1065,7 +1065,7 @@ async function prepareFilesystemIsolation(options) {
1065
1065
  mkdirSync(join3(privateHome, ".pi/agent"), { recursive: true, mode: 448 });
1066
1066
  mkdirSync(join3(privateHome, ".claude"), { mode: 448 });
1067
1067
  args.push(
1068
- "--bind-fd",
1068
+ options.scopeReadOnly ? "--ro-bind-fd" : "--bind-fd",
1069
1069
  pinned(scope, options.expectedScopeIdentity),
1070
1070
  scope,
1071
1071
  "--dir",
@@ -3688,12 +3688,14 @@ var McpSession = class {
3688
3688
  stateRoot;
3689
3689
  isolationMode;
3690
3690
  expectedScopeIdentity;
3691
+ scopeReadOnly;
3691
3692
  /** Sandbox workers: the host owns OAuth, refreshes on request and returns only access tokens. */
3692
3693
  hostToken;
3693
3694
  /** Sandbox workers start local servers from host paths over the VM's shared file system. */
3694
3695
  connectTimeoutMs = 1e4;
3695
- constructor(connections, scope, auth2, direct = false, resolveSecret, protectedPaths, stateRoot, isolationMode = "bubblewrap", expectedScopeIdentity, hostToken) {
3696
+ constructor(connections, scope, auth2, direct = false, resolveSecret, protectedPaths, stateRoot, isolationMode = "bubblewrap", expectedScopeIdentity, hostToken, scopeReadOnly = false) {
3696
3697
  this.hostToken = hostToken;
3698
+ this.scopeReadOnly = scopeReadOnly;
3697
3699
  this.connections = structuredClone(connections);
3698
3700
  this.scope = scope;
3699
3701
  this.auth = auth2;
@@ -3822,7 +3824,8 @@ var McpSession = class {
3822
3824
  },
3823
3825
  ...this.protectedPaths ? { protectedPaths: this.protectedPaths } : {},
3824
3826
  ...this.stateRoot ? { stateRoot: this.stateRoot } : {},
3825
- credentials: "none"
3827
+ credentials: "none",
3828
+ scopeReadOnly: this.scopeReadOnly
3826
3829
  });
3827
3830
  if (this.disposed) {
3828
3831
  isolation.cleanup();
@@ -4147,7 +4150,7 @@ function runWorker() {
4147
4150
  let backend;
4148
4151
  const importing = performance.now();
4149
4152
  try {
4150
- backend = backendModule ? isSea3() ? createRequire(pathToFileURL(process.execPath))(fileURLToPath(backendModule)).default : (await import(backendModule)).default : backendName === "claude" ? new (await import("./backend-worker-chunks/claude-THGSOTC2.mjs")).ClaudeBackend() : new (await import("./backend-worker-chunks/pi-5LAWIJNE.mjs")).PiBackend();
4153
+ backend = backendModule ? isSea3() ? createRequire(pathToFileURL(process.execPath))(fileURLToPath(backendModule)).default : (await import(backendModule)).default : backendName === "claude" ? new (await import("./backend-worker-chunks/claude-X57GT57M.mjs")).ClaudeBackend() : new (await import("./backend-worker-chunks/pi-IZ3GX6HN.mjs")).PiBackend();
4151
4154
  } catch (error) {
4152
4155
  throw new Error(`Backend "${backendName}" is not available in this build: ${errorText(error)}`);
4153
4156
  }
@@ -176,6 +176,11 @@ const DEFAULT_ALLOWED_TOOLS = [
176
176
  // what it cannot show is what the Subagent spent, which is a different measure.
177
177
  "Agent",
178
178
  ];
179
+ function readOnlyDeniedTools(readOnly) {
180
+ if (!readOnly)
181
+ return [];
182
+ return ["Write", "Edit", "NotebookEdit", ...(readOnly === "tools" ? ["Bash", "mcp__workflow__bash"] : [])];
183
+ }
179
184
  class ClaudeSession {
180
185
  capabilities = { providers: ["anthropic"], models: [], compaction: true, autoCompaction: "startup", fork: true, rewind: true, rewindFiles: true, subagents: true, enquiries: true, permissions: true };
181
186
  inbox = new AsyncQueue();
@@ -238,6 +243,7 @@ class ClaudeSession {
238
243
  priorSpend;
239
244
  options;
240
245
  backendOptions;
246
+ disallowedTools;
241
247
  workflowAutoCompaction;
242
248
  claudeState;
243
249
  constructor(options, backendOptions, claudeState, resumeAt) {
@@ -247,6 +253,9 @@ class ClaudeSession {
247
253
  this.parentSessions = sessionToolsServer(options.workflowBuilder || options.tools === "none" ? undefined : options.sessionTools);
248
254
  if (options.workflowBuilder)
249
255
  this.capabilities = { ...this.capabilities, subagents: false, enquiries: false, permissions: false };
256
+ if (options.readOnly)
257
+ this.capabilities = { ...this.capabilities, rewindFiles: false };
258
+ this.disallowedTools = [...backendOptions.disallowedTools ?? [], ...readOnlyDeniedTools(options.readOnly)];
250
259
  this.options = options;
251
260
  this.permissionMode = options.permissionMode ?? "ask";
252
261
  this.backendOptions = backendOptions;
@@ -262,7 +271,7 @@ class ClaudeSession {
262
271
  // `BackendCreateOptions.tools`. The deny in `canUseTool` below is the half that makes it hold.
263
272
  const builder = options.workflowBuilder;
264
273
  const toolless = !builder && options.tools === "none";
265
- const preApproved = builder ? claudeWorkflowBuilderToolNames : toolless ? [] : [...(backendOptions.allowedTools ?? DEFAULT_ALLOWED_TOOLS), ...(options.workflow ? ["mcp__flow_workflow__workflow_inspect", "mcp__flow_workflow__workflow_recover", "mcp__flow_workflow__workflow_relay_enquiry", "mcp__flow_workflow__workflow_relay_permission"] : [])];
274
+ const preApproved = builder ? claudeWorkflowBuilderToolNames : toolless ? [] : [...(backendOptions.allowedTools ?? DEFAULT_ALLOWED_TOOLS).filter((tool) => !this.disallowedTools.includes(tool)), ...(options.workflow ? ["mcp__flow_workflow__workflow_inspect", "mcp__flow_workflow__workflow_recover", "mcp__flow_workflow__workflow_relay_enquiry", "mcp__flow_workflow__workflow_relay_permission"] : [])];
266
275
  if (!builder && !toolless && options.sessionTools)
267
276
  preApproved.push(...claudeSessionReadTools);
268
277
  this.allowed = new Set(toolless ? [] : [...preApproved, ...(options.standingAuthorisations ?? [])]);
@@ -298,7 +307,7 @@ class ClaudeSession {
298
307
  // set, and canUseTool catches only the fall-through so nothing can stall waiting on a prompt.
299
308
  permissionMode: "default",
300
309
  allowedTools: preApproved,
301
- ...(backendOptions.disallowedTools ? { disallowedTools: backendOptions.disallowedTools } : {}),
310
+ ...(this.disallowedTools.length ? { disallowedTools: this.disallowedTools } : {}),
302
311
  ...(builder ? {
303
312
  tools: [], settingSources: [], skills: [], plugins: [], agents: {},
304
313
  settings: { disableAllHooks: true, enabledPlugins: {}, syncClaudeAiSkills: false, syncClaudeAiPlugins: false,
@@ -311,7 +320,7 @@ class ClaudeSession {
311
320
  ...(startingEffort ? { effort: startingEffort } : {}),
312
321
  ...(options.resume ? { resume: options.resume } : {}),
313
322
  ...(resumeAt ? { resumeSessionAt: resumeAt } : {}),
314
- ...(builder || toolless ? {} : { enableFileCheckpointing: true }),
323
+ ...(builder || toolless || options.readOnly ? {} : { enableFileCheckpointing: true }),
315
324
  ...(backendOptions.pathToClaudeCodeExecutable
316
325
  ? { pathToClaudeCodeExecutable: backendOptions.pathToClaudeCodeExecutable }
317
326
  : {}),
@@ -343,6 +352,8 @@ class ClaudeSession {
343
352
  if (extra.agentID && toolName.startsWith(SESSION_TOOL_PREFIX))
344
353
  return { behavior: "deny",
345
354
  message: "Agent Session tools are available only to the parent Agent Session" };
355
+ if (this.disallowedTools.includes(toolName))
356
+ return { behavior: "deny", message: `${toolName} is disabled for this session` };
346
357
  if (toolName === ASK_TOOL)
347
358
  return await this.ask(extra.toolUseID, input);
348
359
  if (this.permissionMode === "always" || this.allowed.has(toolName) || this.workflowGrants.has(toolName))
@@ -728,7 +739,7 @@ class ClaudeSession {
728
739
  throw new Error("This Backend Session runs no tools");
729
740
  const handle = new ClaudeWorkflowSubagent({ cwd: this.options.scope,
730
741
  mcpServers: claudeMcpServers(this.options.mcp),
731
- ...(this.backendOptions.disallowedTools ? { disallowedTools: this.backendOptions.disallowedTools } : {}),
742
+ ...(this.disallowedTools.length ? { disallowedTools: this.disallowedTools } : {}),
732
743
  ...(this.backendOptions.pathToClaudeCodeExecutable ? { pathToClaudeCodeExecutable: this.backendOptions.pathToClaudeCodeExecutable } : {}),
733
744
  }, options, this.workflowGrants, {
734
745
  ...(this.backendOptions.query ? { query: this.backendOptions.query } : {}),
@@ -60,12 +60,14 @@ export class McpSession {
60
60
  stateRoot;
61
61
  isolationMode;
62
62
  expectedScopeIdentity;
63
+ scopeReadOnly;
63
64
  /** Sandbox workers: the host owns OAuth, refreshes on request and returns only access tokens. */
64
65
  hostToken;
65
66
  /** Sandbox workers start local servers from host paths over the VM's shared file system. */
66
67
  connectTimeoutMs = 10_000;
67
- constructor(connections, scope, auth, direct = false, resolveSecret, protectedPaths, stateRoot, isolationMode = "bubblewrap", expectedScopeIdentity, hostToken) {
68
+ constructor(connections, scope, auth, direct = false, resolveSecret, protectedPaths, stateRoot, isolationMode = "bubblewrap", expectedScopeIdentity, hostToken, scopeReadOnly = false) {
68
69
  this.hostToken = hostToken;
70
+ this.scopeReadOnly = scopeReadOnly;
69
71
  this.connections = structuredClone(connections);
70
72
  this.scope = scope;
71
73
  this.auth = auth;
@@ -196,6 +198,7 @@ export class McpSession {
196
198
  ...(this.protectedPaths ? { protectedPaths: this.protectedPaths } : {}),
197
199
  ...(this.stateRoot ? { stateRoot: this.stateRoot } : {}),
198
200
  credentials: "none",
201
+ scopeReadOnly: this.scopeReadOnly,
199
202
  });
200
203
  // Disposal can arrive while the mount/namespace probe is in flight. No spawn may
201
204
  // follow it, even when preparation succeeds after dispose() has closed the client.
@@ -519,7 +519,7 @@ export class PiBackend {
519
519
  const builderTools = builder ? piWorkflowBuilderTools(builder) : [];
520
520
  const tools = builder ? builderTools.map(tool => tool.name) : options.tools === "none" ? [] : [...(this.options.tools ?? [
521
521
  ...defaults, ASK_TOOL, SUBAGENT_TOOL, ...(defaults.includes("bash") ? ["bash_output", "kill_shell"] : []),
522
- ])];
522
+ ])].filter((name) => !readOnlyDeniedTools(options.readOnly).includes(name));
523
523
  const mcp = builder || options.tools === "none" ? undefined : options.mcp;
524
524
  const workflowTools = workflowParentTools(builder || options.tools === "none" ? undefined : options.workflow);
525
525
  const sessionTools = piSessionTools(builder || options.tools === "none" ? undefined : options.sessionTools);
@@ -605,6 +605,11 @@ export class PiBackend {
605
605
  return piSession;
606
606
  }
607
607
  }
608
+ function readOnlyDeniedTools(readOnly) {
609
+ if (!readOnly)
610
+ return [];
611
+ return ["edit", "write", ...(readOnly === "tools" ? ["bash", "bash_output", "kill_shell", "powershell"] : [])];
612
+ }
608
613
  async function runSubagent(parent, scope, agentDir, work, id, input, signal, emit, mcp, compactionModelId, agentPermissions) {
609
614
  const available = parent.modelRuntime.getAvailableSnapshot();
610
615
  const model = input.model ? findPiModel(available, input.model) : parent.model;
@@ -153,7 +153,8 @@ export class WorkerBackend {
153
153
  let proxy;
154
154
  try {
155
155
  const auth = support.provider.claudeAuthDir && (shared || this.name === "claude") ? [support.provider.claudeAuthDir] : [];
156
- const mounts = sandboxMounts([...roots ?? [scope, stateDir], ...auth], assets);
156
+ const readOnly = scopeReadOnly(options);
157
+ const mounts = sandboxMounts([...roots ?? (readOnly ? [stateDir] : [scope, stateDir]), ...auth], readOnly ? [scope, ...assets] : assets);
157
158
  let sandbox, startup;
158
159
  if (shared) {
159
160
  const acquired = await shared.acquire(support.provider, roots[0], mounts, options.signal, options.evict);
@@ -162,7 +163,7 @@ export class WorkerBackend {
162
163
  }
163
164
  else {
164
165
  sandbox = await createSandbox(support.provider, { name: `flow-${createHash("sha256").update(stateDir).digest("hex").slice(0, 16)}`,
165
- workspace: scope, mounts, env: {} }, join(stateDir, "sandbox.json"), options.signal);
166
+ workspace: readOnly ? realpathSync(stateDir) : scope, mounts, env: {} }, join(stateDir, "sandbox.json"), options.signal);
166
167
  ({ startup } = sandbox);
167
168
  cleanups.push(() => { removed = sandbox.close().catch((error) => console.error(`Sandbox ${sandbox.name} removal failed: ${error.message}`)); });
168
169
  }
@@ -240,7 +241,8 @@ export class WorkerBackend {
240
241
  const isolation = await prepareFilesystemIsolation({ ...plan, scope: options.scope, expectedScope: resolve(options.scope),
241
242
  ...(options.stateDir ? { stateDir: options.stateDir } : {}),
242
243
  ...(this.options.stateRoot ? { stateRoot: this.options.stateRoot } : {}),
243
- env: this.options.env ?? {}, credentials: this.name, workflowBuilder: !!options.workflowBuilder, worker: true, readablePaths: assets });
244
+ env: this.options.env ?? {}, credentials: this.name, workflowBuilder: !!options.workflowBuilder, worker: true, readablePaths: assets,
245
+ scopeReadOnly: scopeReadOnly(options) });
244
246
  let proxy;
245
247
  try {
246
248
  this.assertRunning();
@@ -515,3 +517,6 @@ class WorkerSession {
515
517
  })();
516
518
  }
517
519
  }
520
+ function scopeReadOnly(options) {
521
+ return options.readOnly === "mounted" || (options.tools === "none" && !options.workflowBuilder);
522
+ }
package/dist/build-id CHANGED
@@ -1 +1 @@
1
- 8ab6f68e-a8d0-4e4f-a520-68e8a0b6b031
1
+ 9e6f61e8-dc68-4014-8b0a-94b14e93a2d4
@@ -889,7 +889,7 @@ async function bootstrap() {
889
889
  if (!managed) throw new Error("Missing systemd update configuration");
890
890
  await assertSystemdOwner(managed, managed.updater, process.pid);
891
891
  }
892
- const lease = await install.register("8ab6f68e-a8d0-4e4f-a520-68e8a0b6b031", root, args, process.env.FLOW_UPDATE_CAPABILITY ?? systemdCapability(root));
892
+ const lease = await install.register("9e6f61e8-dc68-4014-8b0a-94b14e93a2d4", root, args, process.env.FLOW_UPDATE_CAPABILITY ?? systemdCapability(root));
893
893
  delete process.env.FLOW_UPDATE_CAPABILITY;
894
894
  process.on("exit", lease.release);
895
895
  if (args[0] === "update") {
@@ -121,6 +121,52 @@ export function connect(options) {
121
121
  })();
122
122
  return () => { stopped = true; stream?.abort(); wake?.(); };
123
123
  },
124
+ subscribeAttention(onRaise) {
125
+ let stopped = false;
126
+ let stream;
127
+ let wake;
128
+ let attempt = 0;
129
+ void (async () => {
130
+ while (!stopped) {
131
+ const controller = new AbortController();
132
+ stream = controller;
133
+ const arm = () => setTimeout(() => controller.abort(), SILENCE_MS);
134
+ let watchdog = arm();
135
+ const receivedChunk = () => { clearTimeout(watchdog); watchdog = arm(); };
136
+ const openedAt = Date.now();
137
+ try {
138
+ const response = await fetch(`${options.url}/api/attention/events`, {
139
+ headers, ...credentials, signal: controller.signal,
140
+ });
141
+ if (FATAL_STATUS.has(response.status))
142
+ return;
143
+ if (response.ok && response.body) {
144
+ for await (const raised of readEventStream(response.body, receivedChunk)) {
145
+ if (stopped)
146
+ return;
147
+ onRaise(raised);
148
+ }
149
+ }
150
+ }
151
+ catch {
152
+ if (stopped)
153
+ return;
154
+ }
155
+ finally {
156
+ clearTimeout(watchdog);
157
+ }
158
+ if (stopped)
159
+ return;
160
+ attempt = Date.now() - openedAt >= BACKOFF_MIN_MS ? 1 : attempt + 1;
161
+ await new Promise(resolve => {
162
+ const timer = setTimeout(resolve, backoffMs(attempt));
163
+ wake = () => { clearTimeout(timer); resolve(); };
164
+ });
165
+ wake = undefined;
166
+ }
167
+ })();
168
+ return () => { stopped = true; stream?.abort(); wake?.(); };
169
+ },
124
170
  subscribe({ sessionId, since, onEntry, onError, onLink, silenceMs }) {
125
171
  const events = `${options.url}/api/sessions/${encodeURIComponent(sessionId)}/events`;
126
172
  const silence = silenceMs ?? SILENCE_MS;
@@ -12,7 +12,9 @@
12
12
  * question is asked one segment higher up. A flag rather than the repository's name over the wire,
13
13
  * because the name is already here in the Scope.
14
14
  */
15
- export function projectName(scope, worktree) {
15
+ export function projectName(scope, worktree, readOnly) {
16
+ if (readOnly)
17
+ return "<chat>";
16
18
  const path = worktree ? scope.slice(0, Math.max(0, scope.lastIndexOf("/"))) : scope;
17
19
  const cut = path.lastIndexOf("/");
18
20
  return (cut < 0 ? path : path.slice(cut + 1)) || scope;
@@ -117,6 +117,7 @@ function applyEvent(state, event, at) {
117
117
  ...(event.fromSessionId === undefined
118
118
  ? { text: event.text }
119
119
  : { text: event.text.slice(event.text.indexOf("\n") + 1), fromSessionId: event.fromSessionId }),
120
+ ...(event.note === undefined ? {} : { note: event.note }),
120
121
  ...(event.attachments === undefined ? {} : { attachments: event.attachments }),
121
122
  at,
122
123
  }),
@@ -11,6 +11,8 @@
11
11
  * between the Project's own checkout and a Worktree cut from it, so that is the one named.
12
12
  */
13
13
  export function scopeKindLabel(scope) {
14
+ if (scope.readOnly)
15
+ return "Read-only Project Root";
14
16
  return scope.worktree ? "Worktree" : "Project checkout";
15
17
  }
16
18
  /**
@@ -21,6 +23,8 @@ export function scopeKindLabel(scope) {
21
23
  * client can say it as a tooltip.
22
24
  */
23
25
  export function scopeKindHint(scope) {
26
+ if (scope.readOnly)
27
+ return "The Project Root, read-only. This Agent Session can read it but not write to it, for its whole life.";
24
28
  return scope.worktree
25
29
  ? "A worktree the Session Host made for this Agent Session. It is bound to it for its whole life."
26
30
  : "The Project's own checkout. This Agent Session is bound to it for its whole life.";
@@ -18,15 +18,18 @@ async function baseRef(scope, remote, branch, preferLocal) {
18
18
  }
19
19
  return undefined;
20
20
  }
21
- async function rangeFiles(scope, base) {
22
- const raw = (await git(scope, ["diff", "--name-status", "-z", "--no-renames", `${base}...HEAD`, "--"])).split("\0").filter(Boolean);
21
+ async function rangeFiles(scope, base, to) {
22
+ const raw = (await git(scope, ["diff", "--name-status", "-z", "--no-renames", `${base}...${to}`, "--"])).split("\0").filter(Boolean);
23
23
  const files = [];
24
24
  for (let index = 0; index < raw.length; index += 2)
25
25
  files.push({ status: raw[index], path: raw[index + 1] });
26
26
  return files;
27
27
  }
28
- async function rangeCommits(scope, base) {
29
- return (await git(scope, ["log", "--format=%h %s", `${base}..HEAD`, "--"])).trim().split("\n").filter(Boolean);
28
+ async function rangeCommits(scope, base, to) {
29
+ return (await git(scope, ["log", "--format=%h %s", `${base}..${to}`, "--"])).trim().split("\n").filter(Boolean);
30
+ }
31
+ export async function rangeChanges(scope, base, to) {
32
+ return { files: await rangeFiles(scope, base, to), commits: await rangeCommits(scope, base, to) };
30
33
  }
31
34
  async function branchBase(scope, pullRequestBase, github) {
32
35
  const current = await head(scope);
@@ -44,7 +47,7 @@ export async function changes(scope, view, pullRequestBase, github = gh) {
44
47
  if (view !== "branch")
45
48
  return { files: await files(scope), commits: [] };
46
49
  const base = await branchBase(scope, pullRequestBase, github);
47
- return { files: await rangeFiles(scope, base), commits: await rangeCommits(scope, base), base: base.replace(/^refs\/(heads|remotes)\//, "") };
50
+ return { ...await rangeChanges(scope, base, "HEAD"), base: base.replace(/^refs\/(heads|remotes)\//, "") };
48
51
  }
49
52
  function added(path, content) {
50
53
  const lines = content.match(/[^\n]*\n|[^\n]+$/g) ?? [];
@@ -70,19 +73,21 @@ async function blobSize(scope, object) {
70
73
  return size.ok ? Number(size.value) : 0;
71
74
  }
72
75
  export async function diff(scope, view, path, pullRequestBase, github = gh) {
73
- const base = view === "branch" ? await branchBase(scope, pullRequestBase, github) : undefined;
74
- const listed = base ? await rangeFiles(scope, base) : await files(scope);
76
+ return fileDiff(scope, path, view === "branch" ? await branchBase(scope, pullRequestBase, github) : undefined, "HEAD");
77
+ }
78
+ export async function fileDiff(scope, path, base, to) {
79
+ const listed = base ? await rangeFiles(scope, base, to) : await files(scope);
75
80
  const file = listed.find(item => item.path === path);
76
81
  if (!file)
77
82
  throw new Error("This file is not in the list of changes. Read the list again.");
78
83
  if (file.status === "??")
79
84
  return untracked(scope, path);
80
- const from = base ? (await git(scope, ["merge-base", base, "HEAD"])).trim() : (await run(scope, ["rev-parse", "--verify", "--quiet", "HEAD"], GIT_READ_TIMEOUT_MS)).ok ? "HEAD" : EMPTY_TREE;
85
+ const from = base ? (await git(scope, ["merge-base", base, to])).trim() : (await run(scope, ["rev-parse", "--verify", "--quiet", "HEAD"], GIT_READ_TIMEOUT_MS)).ok ? "HEAD" : EMPTY_TREE;
81
86
  const oldSize = await blobSize(scope, `${from}:${path}`);
82
- const newSize = base ? await blobSize(scope, `HEAD:${path}`) : (await lstat(resolve(scope, path)).catch(() => undefined))?.size ?? 0;
87
+ const newSize = base ? await blobSize(scope, `${to}:${path}`) : (await lstat(resolve(scope, path)).catch(() => undefined))?.size ?? 0;
83
88
  if (oldSize > SIDE_LIMIT || newSize > SIDE_LIMIT)
84
89
  return { tooLarge: true };
85
- const range = base ? [from, "HEAD"] : [from];
90
+ const range = base ? [from, to] : [from];
86
91
  const numstat = await git(scope, ["--literal-pathspecs", "diff", "--numstat", ...range, "--", path]);
87
92
  if (numstat.startsWith("-\t-\t"))
88
93
  return { binary: true };
@@ -102,14 +107,19 @@ export async function commitContext(scope, branch, pullRequest) {
102
107
  return { ...(branch ? { branch } : {}), ...(defaultBranch ? { defaultBranch } : {}), canRename };
103
108
  }
104
109
  export async function changesText(scope, view, paths, pullRequestBase, github = gh) {
105
- const listed = await changes(scope, view, pullRequestBase, github);
110
+ return textOf(await changes(scope, view, pullRequestBase, github), paths, path => diff(scope, view, path, pullRequestBase, github));
111
+ }
112
+ export async function rangeText(scope, base, to) {
113
+ return textOf(await rangeChanges(scope, base, to), undefined, path => fileDiff(scope, path, base, to));
114
+ }
115
+ async function textOf(listed, paths, read) {
106
116
  let text = listed.commits.length > 0 ? `Commits:\n${listed.commits.join("\n")}\n` : "";
107
117
  for (const file of listed.files) {
108
118
  if (text.length > 24_000)
109
119
  break;
110
120
  if (paths && !paths.includes(file.path))
111
121
  continue;
112
- const shown = await diff(scope, view, file.path, pullRequestBase, github);
122
+ const shown = await read(file.path);
113
123
  text += "text" in shown ? shown.text : `${file.status} ${file.path}: no text diff\n`;
114
124
  }
115
125
  return text;
@@ -219,7 +219,7 @@ function millisecondOfDay(now) {
219
219
  const midnight = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate());
220
220
  return now.getTime() - midnight;
221
221
  }
222
- async function refExists(repo, branch) {
222
+ export async function refExists(repo, branch) {
223
223
  const found = await run(repo, ["show-ref", "--verify", "--quiet", `refs/heads/${branch}`], GIT_READ_TIMEOUT_MS);
224
224
  return found.ok;
225
225
  }
@@ -372,6 +372,15 @@ export async function removeWorktree(options) {
372
372
  return removed;
373
373
  return { ok: true, value: undefined };
374
374
  }
375
+ /** Check out `oid` with a detached HEAD at `path`, for read-only host work such as a Tour. */
376
+ export async function addDetachedCheckout(repo, oid, path) {
377
+ const added = await run(repo, ["worktree", "add", "--detach", path, oid], GIT_WRITE_TIMEOUT_MS);
378
+ return added.ok ? { ok: true, value: undefined } : added;
379
+ }
380
+ export async function removeDetachedCheckout(repo, path) {
381
+ await run(repo, ["worktree", "remove", "--force", path], GIT_WRITE_TIMEOUT_MS);
382
+ await run(repo, ["worktree", "prune"], GIT_WRITE_TIMEOUT_MS);
383
+ }
375
384
  /**
376
385
  * Reconnect a worktree and its repository after one or both moved. Run from the repository.
377
386
  *