@tenonai/yew 1.4.0 → 1.6.0

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 (89) hide show
  1. package/CHANGELOG.md +48 -5
  2. package/README.md +31 -13
  3. package/THIRD-PARTY-NOTICES.md +6 -1
  4. package/dist/cli/app.js +22 -12
  5. package/dist/cli/export.js +5 -5
  6. package/dist/cli/mcp.js +7 -7
  7. package/dist/cli/remote.js +6 -6
  8. package/dist/cli/run.js +3 -3
  9. package/dist/cli/schedule.js +3 -3
  10. package/dist/cli/send.js +4 -4
  11. package/dist/cli/serve.js +88 -14
  12. package/dist/cli/service.js +13 -13
  13. package/dist/server/agent/prompt.js +3 -2
  14. package/dist/server/agent/runner.js +41 -1
  15. package/dist/server/data-usage.js +1 -1
  16. package/dist/server/db/database.js +1 -1
  17. package/dist/server/export.js +2 -2
  18. package/dist/server/folder-picker.js +1 -1
  19. package/dist/server/http/api.js +17 -1
  20. package/dist/server/http/app.js +13 -5
  21. package/dist/server/http/data.js +1 -1
  22. package/dist/server/http/mcp.js +2 -2
  23. package/dist/server/http/problem.js +1 -1
  24. package/dist/server/http/security.js +5 -5
  25. package/dist/server/mail/envelope.js +11 -6
  26. package/dist/server/mail/post.js +2 -2
  27. package/dist/server/mcp-builtin.js +15 -2
  28. package/dist/server/mcp-config.js +4 -4
  29. package/dist/server/mcp-oauth.js +6 -6
  30. package/dist/server/mcp.js +70 -8
  31. package/dist/server/permissions/engine.js +23 -5
  32. package/dist/server/sandbox.js +447 -0
  33. package/dist/server/settings.js +34 -1
  34. package/dist/server/store.js +2 -2
  35. package/dist/server/tools/jobs.js +3 -2
  36. package/dist/server/tools/mail.js +11 -1
  37. package/dist/server/tools/process.js +63 -12
  38. package/dist/server/tools/search.js +5 -2
  39. package/dist/server/tools/shell.js +70 -17
  40. package/dist/shared/policy.js +20 -20
  41. package/dist/shared/version.js +8 -0
  42. package/dist/sim/client.d.ts +17 -0
  43. package/dist/sim/client.js +41 -0
  44. package/dist/sim/index.d.ts +7 -0
  45. package/dist/sim/index.js +6 -0
  46. package/dist/sim/types.d.ts +161 -0
  47. package/dist/sim/types.js +5 -0
  48. package/dist/sim/world.d.ts +6 -0
  49. package/dist/sim/world.js +359 -0
  50. package/package.json +17 -3
  51. package/web/dist/THIRD-PARTY-NOTICES.txt +1 -1
  52. package/web/dist/assets/index-BQdFuM-f.css +1 -0
  53. package/web/dist/assets/index-Dh9QdEsc.js +70 -0
  54. package/web/dist/icons/apple-touch-icon.png +0 -0
  55. package/web/dist/index.html +3 -3
  56. package/web/dist/mascot/alarm.webp +0 -0
  57. package/web/dist/mascot/books.webp +0 -0
  58. package/web/dist/mascot/bow.webp +0 -0
  59. package/web/dist/mascot/branch.webp +0 -0
  60. package/web/dist/mascot/clipboard.webp +0 -0
  61. package/web/dist/mascot/dozing.webp +0 -0
  62. package/web/dist/mascot/fired-up.webp +0 -0
  63. package/web/dist/mascot/giftbox.webp +0 -0
  64. package/web/dist/mascot/halt.webp +0 -0
  65. package/web/dist/mascot/jump.webp +0 -0
  66. package/web/dist/mascot/letter-run.webp +0 -0
  67. package/web/dist/mascot/magnifier.webp +0 -0
  68. package/web/dist/mascot/mini.webp +0 -0
  69. package/web/dist/mascot/nap.webp +0 -0
  70. package/web/dist/mascot/on-duty.webp +0 -0
  71. package/web/dist/mascot/pajamas.webp +0 -0
  72. package/web/dist/mascot/paper-plane.webp +0 -0
  73. package/web/dist/mascot/peek.webp +0 -0
  74. package/web/dist/mascot/permission.webp +0 -0
  75. package/web/dist/mascot/phone.webp +0 -0
  76. package/web/dist/mascot/pointing.webp +0 -0
  77. package/web/dist/mascot/portrait.webp +0 -0
  78. package/web/dist/mascot/pout.webp +0 -0
  79. package/web/dist/mascot/proud.webp +0 -0
  80. package/web/dist/mascot/reading.webp +0 -0
  81. package/web/dist/mascot/stamp.webp +0 -0
  82. package/web/dist/mascot/stretch.webp +0 -0
  83. package/web/dist/mascot/surprised.webp +0 -0
  84. package/web/dist/mascot/tea.webp +0 -0
  85. package/web/dist/mascot/teary.webp +0 -0
  86. package/web/dist/mascot/typing.webp +0 -0
  87. package/dist/server/from-jig.js +0 -98
  88. package/web/dist/assets/index-B9oWPSod.css +0 -1
  89. package/web/dist/assets/index-C5qBMzFX.js +0 -68
package/dist/cli/serve.js CHANGED
@@ -13,8 +13,9 @@ const LETTER_SWEEP_MS = 2000;
13
13
  const REMOTE_SYNC_MS = 5000;
14
14
  const SERVE_HELP = `Usage: yew serve [options]
15
15
 
16
- Start Yew's local service. It listens on 127.0.0.1 only, keeps running while
17
- the browser is closed, and prints a one-time link to open the web interface.
16
+ Start Yew Harness's local service. It listens on 127.0.0.1 only, keeps running
17
+ while the browser is closed, and prints a one-time link to open the web
18
+ interface.
18
19
 
19
20
  Options:
20
21
  -p, --port <n> Port to listen on (default ${DEFAULT_PORT})
@@ -23,13 +24,41 @@ Options:
23
24
  `;
24
25
  const OPEN_HELP = `Usage: yew open [options]
25
26
 
26
- Open the web interface of the running Yew service with a new one-time link.
27
+ Open the web interface of the running Yew Harness service with a new one-time
28
+ link.
27
29
 
28
30
  Options:
29
31
  --print Print the link instead of opening a browser
30
32
  -h, --help Show this help
31
33
  `;
32
34
  const serveFile = (home) => join(home, "serve.json");
35
+ /** How often the sites of model providers with a key are read again for the sandbox. */
36
+ const PROVIDER_SITES_MS = 60_000;
37
+ /**
38
+ * The sites of the model providers that have a key, which commands in the sandbox may reach
39
+ * (blueprint, section 11). Providers on this computer are left out: local ports stay closed.
40
+ */
41
+ async function modelSites(gateway) {
42
+ const sites = [];
43
+ for (const provider of gateway.providers()) {
44
+ let url;
45
+ try {
46
+ url = new URL(provider.baseUrl);
47
+ }
48
+ catch {
49
+ continue;
50
+ }
51
+ const host = url.hostname;
52
+ if (host === "localhost" || host.endsWith(".localhost") || host === "[::1]")
53
+ continue;
54
+ if (/^127\./.test(host) || host === "0.0.0.0")
55
+ continue;
56
+ if (!(await gateway.hasKey(provider.id).catch(() => false)))
57
+ continue;
58
+ sites.push(url.port ? `${host}:${url.port}` : host);
59
+ }
60
+ return [...new Set(sites)];
61
+ }
33
62
  /** The short commit of a source checkout; null when Yew does not run from a git checkout. */
34
63
  function shortCommit() {
35
64
  try {
@@ -54,7 +83,7 @@ export function openBrowser(url) {
54
83
  export function serveCommand() {
55
84
  return {
56
85
  name: "serve",
57
- summary: "Start Yew's local service",
86
+ summary: "Start Yew Harness's local service",
58
87
  async run(args, io) {
59
88
  const { values } = parseArgs({
60
89
  args,
@@ -83,9 +112,41 @@ export function serveCommand() {
83
112
  const { Scheduler } = await import("../server/schedules.js");
84
113
  const runtime = openRuntime({ env: io.env });
85
114
  const { store, bus, gateway, home } = runtime;
115
+ // Sessions' commands and the MCP servers people add go into the system sandbox, set up before
116
+ // anything can start one (blueprint, section 11): on macOS by default, on Linux once tested.
117
+ const sandbox = await import("../server/sandbox.js");
118
+ let providerSites = [];
119
+ const refreshProviderSites = async () => {
120
+ providerSites = await modelSites(gateway);
121
+ };
122
+ if (!sandbox.sandboxWanted(io.env.YEW_SANDBOX)) {
123
+ io.stderr.write(io.env.YEW_SANDBOX === "off"
124
+ ? "The system sandbox is off (YEW_SANDBOX=off): sessions' commands run as your user account.\n"
125
+ : `No system sandbox on ${process.platform} yet: sessions' commands run as your user account.\n`);
126
+ }
127
+ else {
128
+ const { homedir } = await import("node:os");
129
+ await refreshProviderSites();
130
+ const started = await sandbox
131
+ .startSandbox({
132
+ home,
133
+ install: sandbox.INSTALL_DIR,
134
+ userHome: homedir(),
135
+ port,
136
+ root: sandbox.sandboxRoot(homedir(), process.platform, io.env),
137
+ }, () => ({
138
+ sites: providerSites,
139
+ credentials: store.getSetting("sandboxCredentials", false),
140
+ hidden: store.getSetting("hiddenFolders", []),
141
+ }), io.env)
142
+ .catch((error) => ({ kind: "none", problems: [error.message] }));
143
+ io.stderr.write(started.kind === "none"
144
+ ? `The system sandbox could not start, so sessions' commands run as your user account: ${started.problems.join("; ")}\n`
145
+ : `Sessions' commands run in the system sandbox (sandbox-runtime, ${started.kind === "macos" ? "Seatbelt" : "bubblewrap"}).\n${started.problems.map((line) => `sandbox: ${line}\n`).join("")}`);
146
+ }
86
147
  const stuck = store.recoverAfterRestart();
87
148
  if (stuck.length > 0) {
88
- io.stderr.write(`${stuck.length} session(s) were working when Yew last stopped. They are marked for review; nothing was redone.\n`);
149
+ io.stderr.write(`${stuck.length} session(s) were working when Yew Harness last stopped. They are marked for review; nothing was redone.\n`);
89
150
  }
90
151
  store.pruneEvents(Date.now() - EVENT_RETENTION_MS);
91
152
  // Answers handed to a waiting call whose result was never stored come back as letters.
@@ -104,7 +165,7 @@ export function serveCommand() {
104
165
  yewHome: home,
105
166
  version: VERSION,
106
167
  log,
107
- builtin: builtinMcp(home, io.env),
168
+ builtin: builtinMcp(home, io.env, port),
108
169
  prepare: mcpInstaller({ yewHome: home, env: io.env, log }),
109
170
  // Sign-ins to MCP servers: tokens in the keychain; the browser comes back to this port.
110
171
  auth: new McpAuth({
@@ -140,7 +201,7 @@ export function serveCommand() {
140
201
  log,
141
202
  handle: async (request, device) => {
142
203
  if (!handle)
143
- throw new Error("Yew is still starting.");
204
+ throw new Error("Yew Harness is still starting.");
144
205
  return handle(request, device.id);
145
206
  },
146
207
  });
@@ -185,12 +246,13 @@ export function serveCommand() {
185
246
  server.once("listening", () => resolve(true));
186
247
  server.once("error", (error) => {
187
248
  io.stderr.write(error.code === "EADDRINUSE"
188
- ? `yew: port ${port} is in use. Is Yew already running? Try 'yew open', or pick another port with --port.\n`
249
+ ? `yew: port ${port} is in use. Is Yew Harness already running? Try 'yew open', or pick another port with --port.\n`
189
250
  : `yew: could not start: ${error.message}\n`);
190
251
  resolve(false);
191
252
  });
192
253
  });
193
254
  if (!started) {
255
+ await sandbox.stopSandbox().catch(() => { });
194
256
  runtime.close();
195
257
  return EXIT_ERROR;
196
258
  }
@@ -210,17 +272,23 @@ export function serveCommand() {
210
272
  };
211
273
  syncRemote();
212
274
  const remoteSweep = setInterval(syncRemote, REMOTE_SYNC_MS);
275
+ // A model provider's key saved since is a site commands in the sandbox may reach.
276
+ const sitesSweep = sandbox.activeSandbox() === "none"
277
+ ? null
278
+ : setInterval(() => void refreshProviderSites().catch(() => { }), PROVIDER_SITES_MS);
213
279
  const info = { port, pid: process.pid, startedAt: Date.now() };
214
280
  writeFileSync(serveFile(home), JSON.stringify(info), { mode: 0o600 });
215
281
  const url = `http://127.0.0.1:${port}/#t=${issueLoginToken(store)}`;
216
- io.stdout.write(`Yew ${VERSION} is running at http://127.0.0.1:${port}/\nSign in with this link (works once, within 10 minutes):\n${url}\nStop with Ctrl-C. For a new link later, run: yew open\n`);
282
+ io.stdout.write(`Yew Harness ${VERSION} is running at http://127.0.0.1:${port}/\nSign in with this link (works once, within 10 minutes):\n${url}\nStop with Ctrl-C. For a new link later, run: yew open\n`);
217
283
  if (values.open)
218
284
  openBrowser(url);
219
285
  return await new Promise((resolve) => {
220
286
  const stop = () => {
221
- io.stderr.write("Stopping Yew…\n");
287
+ io.stderr.write("Stopping Yew Harness…\n");
222
288
  clearInterval(sweep);
223
289
  clearInterval(remoteSweep);
290
+ if (sitesSweep)
291
+ clearInterval(sitesSweep);
224
292
  scheduler.stop();
225
293
  notifier.stop();
226
294
  mcp.stop();
@@ -231,8 +299,14 @@ export function serveCommand() {
231
299
  if ("closeAllConnections" in server)
232
300
  server.closeAllConnections();
233
301
  rmSync(serveFile(home), { force: true });
234
- runtime.close();
235
- resolve(EXIT_OK);
302
+ // The sandbox's proxies stop once the commands and servers in it have been ended.
303
+ void sandbox
304
+ .stopSandbox()
305
+ .catch((error) => log(`sandbox: ${error.message}`))
306
+ .finally(() => {
307
+ runtime.close();
308
+ resolve(EXIT_OK);
309
+ });
236
310
  };
237
311
  process.once("SIGINT", stop);
238
312
  process.once("SIGTERM", stop);
@@ -273,7 +347,7 @@ export function openCommand() {
273
347
  process.kill(info.pid, 0);
274
348
  }
275
349
  catch {
276
- io.stderr.write("yew: Yew is not running. Start it with: yew serve\n");
350
+ io.stderr.write("yew: Yew Harness is not running. Start it with: yew serve\n");
277
351
  return EXIT_ERROR;
278
352
  }
279
353
  const { openDatabase } = await import("../server/db/database.js");
@@ -289,7 +363,7 @@ export function openCommand() {
289
363
  }
290
364
  else {
291
365
  openBrowser(url);
292
- io.stdout.write(`Opened Yew in the browser (http://127.0.0.1:${info.port}/).\n`);
366
+ io.stdout.write(`Opened Yew Harness in the browser (http://127.0.0.1:${info.port}/).\n`);
293
367
  }
294
368
  return EXIT_OK;
295
369
  }
@@ -8,15 +8,15 @@ import { EXIT_ERROR, EXIT_OK, UsageError } from "./io.js";
8
8
  import { serviceRunning } from "./serve.js";
9
9
  const HELP = `Usage: yew service <install|uninstall|status> [options]
10
10
 
11
- Start Yew when you log in, so your phone and scheduled tasks can reach it
12
- without a terminal open. On macOS this is a LaunchAgent for your user, on
13
- Linux a systemd user unit. Yew is restarted if it exits with an error, and
14
- its log goes to the logs folder in Yew's data directory. Nothing is changed
15
- on your system until you run install.
11
+ Start Yew Harness when you log in, so your phone and scheduled tasks can reach
12
+ it without a terminal open. On macOS this is a LaunchAgent for your user, on
13
+ Linux a systemd user unit. Yew Harness is restarted if it exits with an error,
14
+ and its log goes to the logs folder in Yew Harness's data directory. Nothing
15
+ is changed on your system until you run install.
16
16
 
17
17
  Commands:
18
- install Start Yew at login, and start it now
19
- uninstall Stop starting Yew at login, and stop it now
18
+ install Start Yew Harness at login, and start it now
19
+ uninstall Stop starting Yew Harness at login, and stop it now
20
20
  status Show whether it is installed and running
21
21
 
22
22
  Options:
@@ -83,7 +83,7 @@ export function systemdUnit(host, env, log) {
83
83
  .map(([key, value]) => `Environment=${quoted(`${key}=${value}`)}`)
84
84
  .join("\n");
85
85
  return `[Unit]
86
- Description=Yew, an AI-native multi-agent workbench
86
+ Description=Yew Harness, an AI-native multi-agent workbench
87
87
 
88
88
  [Service]
89
89
  ExecStart=${quoted(host.node)} ${quoted(host.entry)} serve
@@ -181,7 +181,7 @@ export function uninstallService(host, options) {
181
181
  export function serviceCommand(host = realServiceHost()) {
182
182
  return {
183
183
  name: "service",
184
- summary: "Start Yew when you log in",
184
+ summary: "Start Yew Harness when you log in",
185
185
  async run(args, io) {
186
186
  const { values, positionals } = parseArgs({
187
187
  args,
@@ -216,13 +216,13 @@ export function serviceCommand(host = realServiceHost()) {
216
216
  io.stdout.write(`${JSON.stringify({ installed: false, file })}\n`);
217
217
  else {
218
218
  io.stdout.write(had
219
- ? "Yew no longer starts at login, and was stopped.\n"
220
- : "Yew was not set to start at login.\n");
219
+ ? "Yew Harness no longer starts at login, and was stopped.\n"
220
+ : "Yew Harness was not set to start at login.\n");
221
221
  }
222
222
  return EXIT_OK;
223
223
  }
224
224
  if (!serviceLoaded(host) && serviceRunning(home)) {
225
- io.stderr.write("yew: Yew is already running, started by hand. Stop that 'yew serve' first, then run this again.\n");
225
+ io.stderr.write("yew: Yew Harness is already running, started by hand. Stop that 'yew serve' first, then run this again.\n");
226
226
  return EXIT_ERROR;
227
227
  }
228
228
  const { code, log } = installService(host, home, io.env, { start: true });
@@ -233,7 +233,7 @@ export function serviceCommand(host = realServiceHost()) {
233
233
  if (values.json)
234
234
  io.stdout.write(`${JSON.stringify({ installed: true, file, log })}\n`);
235
235
  else {
236
- io.stdout.write(`Yew now starts when you log in, and was started.\nLog: ${log}\nOpen the web interface with 'yew open'.\n`);
236
+ io.stdout.write(`Yew Harness now starts when you log in, and was started.\nLog: ${log}\nOpen the web interface with 'yew open'.\n`);
237
237
  }
238
238
  return EXIT_OK;
239
239
  },
@@ -5,6 +5,7 @@ import { dirname, join, relative, resolve, sep } from "node:path";
5
5
  import { permissionModeOf } from "../../shared/types.js";
6
6
  import { isInside } from "../permissions/paths.js";
7
7
  import { findSkills, memoryIndex, memoryNote, skillsNote } from "../skills.js";
8
+ import { loginShell } from "../tools/process.js";
8
9
  const MAX_INSTRUCTIONS = 32 * 1024;
9
10
  const MAX_IMPORT_DEPTH = 5;
10
11
  const MAX_GIT_STATUS = 2000;
@@ -123,7 +124,7 @@ export function takeSnapshot(session, yewHome, placement = { main: null, parent:
123
124
  return {
124
125
  date: today(),
125
126
  platform: platformName(),
126
- shell: process.env.SHELL ?? "/bin/sh",
127
+ shell: loginShell(),
127
128
  cwd: session.cwd,
128
129
  git: session.cwd ? gitStatus(session.cwd) : null,
129
130
  instructions: loadInstructions(session.cwd, yewHome, extras),
@@ -262,7 +263,7 @@ export function helperPrompt(sender, cwd, now = new Date()) {
262
263
  "",
263
264
  "Environment:",
264
265
  `- Date: ${today(now)}`,
265
- `- System: ${platformName()}; shell: ${process.env.SHELL || "/bin/sh"}`,
266
+ `- System: ${platformName()}; shell: ${loginShell()}`,
266
267
  cwd ? `- Working folder: ${cwd}` : "- No working folder: no file or shell tools.",
267
268
  ].join("\n");
268
269
  }
@@ -148,6 +148,8 @@ export class Agents {
148
148
  placement: (session) => this.#placement(session),
149
149
  extras: () => this.#extras(),
150
150
  });
151
+ // Folders the person keeps from sessions are refused like credential locations.
152
+ this.#permissions.hidden = () => this.#store.getSetting("hiddenFolders", []);
151
153
  // Memory folders and the person's skill folders are read without asking, like the working folder.
152
154
  this.#permissions.readRoots = () => [
153
155
  ...this.#store.getSetting("memoryDirs", []),
@@ -539,7 +541,7 @@ export class Agents {
539
541
  detail =
540
542
  error instanceof YewError
541
543
  ? error.message
542
- : `Yew hit an internal error: ${error.message}`;
544
+ : `Yew Harness hit an internal error: ${error.message}`;
543
545
  if (!(error instanceof YewError))
544
546
  this.#log(`session ${sessionId}: ${error.stack ?? error}`);
545
547
  // The code lets the interface explain the problem in the person's language.
@@ -879,6 +881,7 @@ export class Agents {
879
881
  const model = this.#gateway.model(session.provider, session.model);
880
882
  let tail = "";
881
883
  let timer = null;
884
+ let permits = Promise.resolve(true);
882
885
  const context = {
883
886
  session,
884
887
  signal: live.controller.signal,
@@ -897,6 +900,7 @@ export class Agents {
897
900
  }, 200);
898
901
  },
899
902
  setTodos: (todos) => this.#store.setTodos(sessionId, todos),
903
+ offLimits: (path) => this.#permissions.offLimits(path),
900
904
  ask: async (request) => {
901
905
  const run = this.#mail.run(sessionId);
902
906
  if (run?.unattended) {
@@ -915,6 +919,41 @@ export class Agents {
915
919
  throw new ToolInputError("Stopped before the person answered.");
916
920
  return answer.answer;
917
921
  },
922
+ permit: (request, until) => {
923
+ // One card at a time for a call; the next waits until the person has answered.
924
+ const next = permits.then(async () => {
925
+ if (until?.aborted)
926
+ return false;
927
+ const run = this.#mail.run(sessionId);
928
+ if (run?.unattended) {
929
+ run.refused.push(request.summary);
930
+ return false;
931
+ }
932
+ this.#store.updateToolCall(row.id, { status: "waiting" });
933
+ const approval = this.#store.createApproval({
934
+ sessionId,
935
+ toolCallId: row.id,
936
+ kind: "permission",
937
+ request,
938
+ });
939
+ // The need passed before the person answered: the card is withdrawn.
940
+ const withdraw = () => {
941
+ if (this.#store.getApproval(approval.id).status !== "pending")
942
+ return;
943
+ this.#store.cancelApproval(approval.id);
944
+ live.waiters.get(approval.id)?.(null);
945
+ };
946
+ until?.addEventListener("abort", withdraw, { once: true });
947
+ const answer = await this.#waitFor(sessionId, approval.id, live);
948
+ until?.removeEventListener("abort", withdraw);
949
+ if (!live.controller.signal.aborted) {
950
+ this.#store.updateToolCall(row.id, { status: "running" });
951
+ }
952
+ return answer?.decision === "allow_once" || answer?.decision === "allow_always";
953
+ });
954
+ permits = next.catch(() => false);
955
+ return next;
956
+ },
918
957
  mail: this.#mailContext(sessionId, live, row.id),
919
958
  helper: (task) => {
920
959
  const parent = this.#store.getSession(sessionId);
@@ -933,6 +972,7 @@ export class Agents {
933
972
  ask: async () => {
934
973
  throw new ToolInputError("A helper cannot ask the person.");
935
974
  },
975
+ permit: async () => false,
936
976
  },
937
977
  systemPrompt: helperPrompt(parent.name, parent.cwd),
938
978
  task,
@@ -78,7 +78,7 @@ function scanTemp(home, inUse) {
78
78
  walk(real, false, true);
79
79
  return scan;
80
80
  }
81
- const outside = () => conflict("The tmp folder in Yew's data folder is a link to somewhere else. Yew does not delete through it.", undefined, "temp-outside");
81
+ const outside = () => conflict("The tmp folder in Yew Harness's data folder is a link to somewhere else. Yew Harness does not delete through it.", undefined, "temp-outside");
82
82
  export function dataUsage(home, inUse = () => false, now = Date.now()) {
83
83
  const bytes = {
84
84
  database: 0,
@@ -17,7 +17,7 @@ export function openDatabase(path) {
17
17
  export function migrate(db) {
18
18
  const row = db.prepare("PRAGMA user_version").get();
19
19
  if (row.user_version > migrations.length) {
20
- throw new Error(`The database was written by a newer version of Yew (schema ${row.user_version}); upgrade Yew.`);
20
+ throw new Error(`The database was written by a newer version of Yew Harness (schema ${row.user_version}); upgrade Yew Harness.`);
21
21
  }
22
22
  for (let version = row.user_version; version < migrations.length; version++) {
23
23
  transaction(db, () => {
@@ -29,7 +29,7 @@ const ZH = {
29
29
  image: "图片",
30
30
  stopped: "已停止",
31
31
  modelChanged: "换了模型",
32
- restarted: "Yew 重启时这个会话在干活,已标为待核对。检查过后点「继续」接着运行。",
32
+ restarted: "Yew Harness 重启时这个会话在干活,已标为待核对。检查过后点「继续」接着运行。",
33
33
  changed: "{by} 改了这个会话的设置",
34
34
  compacted: "较早的记录已压成摘要",
35
35
  modelError: "模型请求失败",
@@ -92,7 +92,7 @@ const EN = {
92
92
  image: "Image",
93
93
  stopped: "Stopped",
94
94
  modelChanged: "Model changed",
95
- restarted: "Yew restarted while this session was working, so it is marked for review. Check it, then choose Continue.",
95
+ restarted: "Yew Harness restarted while this session was working, so it is marked for review. Check it, then choose Continue.",
96
96
  changed: "{by} changed this session's settings",
97
97
  compacted: "Earlier messages were summarized",
98
98
  modelError: "The model request failed",
@@ -16,7 +16,7 @@ const runOsascript = (args) => new Promise((resolve, reject) => {
16
16
  */
17
17
  export async function pickFolder(platform = process.platform, run = runOsascript) {
18
18
  if (platform !== "darwin") {
19
- throw new YewError("not-supported", 501, "Yew cannot open a folder picker on this computer. Type the folder's path instead.");
19
+ throw new YewError("not-supported", 501, "Yew Harness cannot open a folder picker on this computer. Type the folder's path instead.");
20
20
  }
21
21
  try {
22
22
  const out = (await run(["-e", "activate", "-e", "POSIX path of (choose folder)"])).trim();
@@ -6,7 +6,7 @@ import { invalid } from "../errors.js";
6
6
  import { exportFileName, sessionMarkdown } from "../export.js";
7
7
  import { pickFolder } from "../folder-picker.js";
8
8
  import { resolveWorkingFolder } from "../paths.js";
9
- import { NOTIFY_KINDS, readSettings, resolveLogFile, } from "../settings.js";
9
+ import { NOTIFY_KINDS, OPENING_MODES, readSettings, resolveHiddenFolder, resolveLogFile, } from "../settings.js";
10
10
  import { resolveMemoryDir } from "../skills.js";
11
11
  import { idempotent } from "./idempotency.js";
12
12
  import { optArray, optBoolean, optEnum, optIntQuery, optNullableString, optNumber, optObject, optString, pageParams, readJson, reqString, } from "./input.js";
@@ -362,6 +362,22 @@ export function api(deps) {
362
362
  const mascot = optBoolean(fields, "mascot");
363
363
  if (mascot !== undefined)
364
364
  store.setSetting("mascot", mascot);
365
+ const opening = optEnum(fields, "opening", OPENING_MODES);
366
+ if (opening)
367
+ store.setSetting("opening", opening);
368
+ const credentials = optBoolean(fields, "sandboxCredentials");
369
+ if (credentials !== undefined)
370
+ store.setSetting("sandboxCredentials", credentials);
371
+ const hidden = optArray(fields, "hiddenFolders");
372
+ if (hidden) {
373
+ if (hidden.length > 20 ||
374
+ hidden.some((dir) => typeof dir !== "string" || dir.length > 4096)) {
375
+ throw invalid("hiddenFolders is a list of up to 20 folders.", "hiddenFolders");
376
+ }
377
+ store.setSetting("hiddenFolders", [
378
+ ...new Set(hidden.filter((dir) => dir.trim()).map((dir) => resolveHiddenFolder(dir))),
379
+ ]);
380
+ }
365
381
  const workspaces = optArray(fields, "workspaces");
366
382
  if (workspaces) {
367
383
  store.setSetting("workspaces", parseWorkspaces(workspaces, readSettings(store).workspaces));
@@ -2,8 +2,9 @@ import { existsSync, readFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { serveStatic } from "@hono/node-server/serve-static";
4
4
  import { Hono } from "hono";
5
- import { VERSION } from "../../shared/version.js";
5
+ import { PROTOCOL_VERSION, VERSION } from "../../shared/version.js";
6
6
  import { PostOffice } from "../mail/post.js";
7
+ import { activeSandbox } from "../sandbox.js";
7
8
  import { agentRoutes } from "./agents.js";
8
9
  import { api } from "./api.js";
9
10
  import { artifactRoutes } from "./artifacts.js";
@@ -20,10 +21,10 @@ import { searchRoutes } from "./search.js";
20
21
  import { authRoutes, deviceLimits, localOnly, requireBrowser, securityHeaders, } from "./security.js";
21
22
  import { skillRoutes } from "./skills.js";
22
23
  import { systemRoutes } from "./system.js";
23
- const NOT_BUILT = `<!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><title>Yew</title>
24
+ const NOT_BUILT = `<!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><title>Yew Harness</title>
24
25
  <meta name="color-scheme" content="light dark"></head><body>
25
- <p>网页界面还没有构建。在 Yew 的目录运行 npm run build:web,然后刷新这个页面。</p>
26
- <p lang="en">The web interface has not been built yet. In the Yew folder, run npm run build:web, then reload this page.</p>
26
+ <p>网页界面还没有构建。在 Yew Harness 的目录运行 npm run build:web,然后刷新这个页面。</p>
27
+ <p lang="en">The web interface has not been built yet. In the Yew Harness folder, run npm run build:web, then reload this page.</p>
27
28
  </body></html>`;
28
29
  export function createApp(options) {
29
30
  const log = options.log ?? ((line) => process.stderr.write(`${line}\n`));
@@ -39,7 +40,14 @@ export function createApp(options) {
39
40
  app.route("/api", authRoutes(store, options.security.port));
40
41
  }
41
42
  app.use("*", deviceLimits());
42
- app.get("/api/health", (c) => c.json({ ok: true, version: VERSION, build: options.build ?? null }));
43
+ app.get("/api/health", (c) => c.json({
44
+ ok: true,
45
+ version: VERSION,
46
+ build: options.build ?? null,
47
+ protocol: PROTOCOL_VERSION,
48
+ // Which system sandbox sessions' commands run in, for the settings (blueprint, section 11).
49
+ sandbox: activeSandbox(),
50
+ }));
43
51
  app.route("/api", api({
44
52
  store,
45
53
  ...(gateway ? { checkModel: (p, m) => gateway.check(p, m) } : {}),
@@ -44,7 +44,7 @@ export function dataRoutes(store, options) {
44
44
  }
45
45
  const dir = target === "home" ? options.home : exported;
46
46
  if (dir === null) {
47
- throw conflict("Nothing was exported since Yew started.", { field: "target" }, "no-export");
47
+ throw conflict("Nothing was exported since Yew Harness started.", { field: "target" }, "no-export");
48
48
  }
49
49
  // The folder itself is opened, so its contents are what the person sees.
50
50
  await showInFileManager(dir, { platform, run: options.run, inside: true, field: "target" });
@@ -123,11 +123,11 @@ export function oauthCallbackRoute(hub, log) {
123
123
  c.header("Cache-Control", "no-store");
124
124
  try {
125
125
  const name = await hub.completeSignIn(state, c.req.query("code") ?? null, c.req.query("error") ?? null, c.req.query("iss") ?? null);
126
- return c.html(page("已登录 · Signed in", `已登录 ${html(name)},可以关掉这个页面回到 Yew。<br>Signed in to ${html(name)}. You can close this page and go back to Yew.`));
126
+ return c.html(page("已登录 · Signed in", `已登录 ${html(name)},可以关掉这个页面回到 Yew Harness。<br>Signed in to ${html(name)}. You can close this page and go back to Yew Harness.`));
127
127
  }
128
128
  catch (error) {
129
129
  log?.(`mcp: sign-in did not finish: ${error.message}`);
130
- return c.html(page("没有登录 · Not signed in", `${html(error.message)}<br>回到 Yew 的「MCP 服务」再试一次。Go back to MCP servers in Yew and try again.`), 400);
130
+ return c.html(page("没有登录 · Not signed in", `${html(error.message)}<br>回到 Yew Harness 的「MCP 服务」再试一次。Go back to MCP servers in Yew Harness and try again.`), 400);
131
131
  }
132
132
  });
133
133
  return app;
@@ -50,6 +50,6 @@ export function errorHandler(log) {
50
50
  return problemResponse(c, error.status, "http-error", titleFor(error.status), error.message);
51
51
  }
52
52
  log(`[${c.get("requestId")}] ${c.req.method} ${c.req.path}: ${error.stack ?? error.message}`);
53
- return problemResponse(c, 500, "internal-error", titleFor(500), "Something went wrong inside Yew. The request ID is in the log.");
53
+ return problemResponse(c, 500, "internal-error", titleFor(500), "Something went wrong inside Yew Harness. The request ID is in the log.");
54
54
  };
55
55
  }
@@ -33,7 +33,7 @@ export function localOnly(port) {
33
33
  return next();
34
34
  const host = c.req.header("Host") ?? "";
35
35
  if (!hosts.has(host)) {
36
- return problemResponse(c, 421, "wrong-host", titleFor(421), "Yew only answers on 127.0.0.1 and localhost.");
36
+ return problemResponse(c, 421, "wrong-host", titleFor(421), "Yew Harness only answers on 127.0.0.1 and localhost.");
37
37
  }
38
38
  for (const header of [
39
39
  "Forwarded",
@@ -52,12 +52,12 @@ export function localOnly(port) {
52
52
  }
53
53
  const dest = c.req.header("Sec-Fetch-Dest");
54
54
  if (dest === "iframe" || dest === "frame" || dest === "embed" || dest === "object") {
55
- return problemResponse(c, 403, "embedded", titleFor(403), "Yew cannot be embedded.");
55
+ return problemResponse(c, 403, "embedded", titleFor(403), "Yew Harness cannot be embedded.");
56
56
  }
57
57
  if (c.req.method !== "GET" && c.req.method !== "HEAD") {
58
58
  const origin = c.req.header("Origin");
59
59
  if (origin !== `http://${host}`) {
60
- return problemResponse(c, 403, "bad-origin", titleFor(403), "This request did not come from Yew's own page.");
60
+ return problemResponse(c, 403, "bad-origin", titleFor(403), "This request did not come from Yew Harness's own page.");
61
61
  }
62
62
  }
63
63
  }
@@ -96,7 +96,7 @@ export function requireBrowser(store, port) {
96
96
  return next();
97
97
  const token = getCookie(c, cookieName(port));
98
98
  if (!token || !store.touchBrowserToken(hashToken(token), Date.now() + BROWSER_TTL_MS)) {
99
- return problemResponse(c, 401, "sign-in-required", titleFor(401), "Open Yew with the link from `yew serve` or `yew open`.");
99
+ return problemResponse(c, 401, "sign-in-required", titleFor(401), "Open Yew Harness with the link from `yew serve` or `yew open`.");
100
100
  }
101
101
  await next();
102
102
  };
@@ -161,7 +161,7 @@ export function deviceLimits() {
161
161
  // Artifacts are looked at on the phone and managed on the Mac.
162
162
  (path.startsWith("/api/artifacts/") && write) ||
163
163
  path.startsWith("/api/auth/")) {
164
- return problemResponse(c, 403, "mac-only", titleFor(403), "Only Yew on the Mac can do this: API keys, devices and remote access stay there.");
164
+ return problemResponse(c, 403, "mac-only", titleFor(403), "Only Yew Harness on the Mac can do this: API keys, devices and remote access stay there.");
165
165
  }
166
166
  await next();
167
167
  };
@@ -7,7 +7,11 @@ const attr = (value) => value.replace(/["\n\r<>]/g, " ");
7
7
  * person. Only what the model reads changes; the interface shows the text as written.
8
8
  */
9
9
  export function neutralize(text) {
10
- return text.replace(/<(\/?)(letter|decision)\b/gi, "&lt;$1$2");
10
+ return (text
11
+ .replace(/<(\/?)(letter|decision)\b/gi, "&lt;$1$2")
12
+ // Yew's own lines start with "[Yew" or "[From Yew"; one written in a letter gets a full-width
13
+ // bracket, so it cannot pass for Yew's.
14
+ .replace(/^(\s*)\[(?=(?:From )?Yew\b)/gim, "$1["));
11
15
  }
12
16
  function senderLabel(letter) {
13
17
  if (letter.fromKind === "cli")
@@ -52,8 +56,9 @@ function decisionLines(decision) {
52
56
  }
53
57
  /**
54
58
  * What the model reads for a delivered letter. The closing tag repeats the letter's id, which the sender
55
- * could not know while writing, so text inside a letter cannot pass itself off as the end of it. `note`
56
- * is Yew's own line about the letter, such as how a scheduled run works.
59
+ * could not know while writing, so text inside a letter cannot pass itself off as the end of it. Yew's
60
+ * own lines come after that tag: the check of a decision the letter refers to, and `note`, such as how a
61
+ * scheduled run works. Inside the letter everything is the sender's.
57
62
  */
58
63
  export function letterText(letter, decision, schedule = null, note = null) {
59
64
  if (letter.fromKind === "person" && decision) {
@@ -76,12 +81,12 @@ export function letterText(letter, decision, schedule = null, note = null) {
76
81
  const lines = [`<letter ${attributes.join(" ")}>`, neutralize(letter.summary)];
77
82
  if (letter.body)
78
83
  lines.push("", neutralize(letter.body));
84
+ lines.push(`</letter id="${letter.id}">`);
79
85
  if (decision) {
80
- lines.push("", `[Yew checked decision #${decision.number}: the person decided it in Yew.]`, ...decisionLines(decision));
86
+ lines.push(`[Yew checked decision #${decision.number}: the person decided it in Yew.]`, ...decisionLines(decision));
81
87
  }
82
88
  if (note)
83
- lines.push("", `[Yew] ${note}`);
84
- lines.push(`</letter id="${letter.id}">`);
89
+ lines.push(`[Yew] ${note}`);
85
90
  return lines.join("\n");
86
91
  }
87
92
  /** A decision for check_decision, with its state told plainly. */
@@ -473,7 +473,7 @@ export class PostOffice {
473
473
  `Chosen: ${chosen ?? "(note only)"}`,
474
474
  ...(card.note ? [`Note: ${oneLine(card.note)}`] : []),
475
475
  ...(requester ? [`Requested by: ${requester}`] : []),
476
- "Decided by the person in Yew",
476
+ "Decided by the person in Yew Harness",
477
477
  ]
478
478
  : [
479
479
  stamp,
@@ -482,7 +482,7 @@ export class PostOffice {
482
482
  `选择:${chosen ?? "(只写了备注)"}`,
483
483
  ...(card.note ? [`备注:${oneLine(card.note)}`] : []),
484
484
  ...(requester ? [`提出:${requester}`] : []),
485
- "本人在 Yew 里决定",
485
+ "本人在 Yew Harness 里决定",
486
486
  ];
487
487
  try {
488
488
  const header = existsSync(path) ? "" : english ? "# Approval log\n\n" : "# 审批记录\n\n";