@tenonai/yew 1.5.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 (38) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +23 -5
  3. package/THIRD-PARTY-NOTICES.md +6 -1
  4. package/dist/cli/serve.js +75 -3
  5. package/dist/server/agent/prompt.js +3 -2
  6. package/dist/server/agent/runner.js +40 -0
  7. package/dist/server/http/api.js +17 -1
  8. package/dist/server/http/app.js +10 -2
  9. package/dist/server/mail/envelope.js +11 -6
  10. package/dist/server/mcp-builtin.js +14 -1
  11. package/dist/server/mcp.js +70 -8
  12. package/dist/server/permissions/engine.js +23 -5
  13. package/dist/server/sandbox.js +447 -0
  14. package/dist/server/settings.js +34 -1
  15. package/dist/server/tools/jobs.js +3 -2
  16. package/dist/server/tools/mail.js +11 -1
  17. package/dist/server/tools/process.js +63 -12
  18. package/dist/server/tools/search.js +5 -2
  19. package/dist/server/tools/shell.js +70 -17
  20. package/dist/shared/policy.js +20 -20
  21. package/dist/shared/version.js +6 -0
  22. package/dist/sim/client.d.ts +17 -0
  23. package/dist/sim/client.js +41 -0
  24. package/dist/sim/index.d.ts +7 -0
  25. package/dist/sim/index.js +6 -0
  26. package/dist/sim/types.d.ts +161 -0
  27. package/dist/sim/types.js +5 -0
  28. package/dist/sim/world.d.ts +6 -0
  29. package/dist/sim/world.js +359 -0
  30. package/package.json +17 -3
  31. package/web/dist/assets/index-BQdFuM-f.css +1 -0
  32. package/web/dist/assets/index-Dh9QdEsc.js +70 -0
  33. package/web/dist/icons/apple-touch-icon.png +0 -0
  34. package/web/dist/index.html +2 -2
  35. package/web/dist/mascot/on-duty.webp +0 -0
  36. package/web/dist/mascot/permission.webp +0 -0
  37. package/web/dist/assets/index-B_NesKxw.js +0 -68
  38. package/web/dist/assets/index-BqTqnE18.css +0 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,33 @@
2
2
 
3
3
  本文件记录 Yew Harness(原名 Jig,1.3.0、1.4.0 叫 Yew)各版本中用户能感知的变化。格式参照 [Keep a Changelog 1.1.0](https://keepachangelog.com/zh-CN/1.1.0/),版本号遵循[语义化版本 2.0.0](https://semver.org/lang/zh-CN/)。
4
4
 
5
+ ## [1.6.0] - 2026-11-18
6
+
7
+ ### 新增
8
+
9
+ - 设置改成一个窗口:左边是分区,右边是内容。侧栏底部的「设置」和 ⌘, 都打开它;原来菜单里的主题、语言和「界面里的 Yew」,以及服务商与密钥、默认设置、MCP 服务、技能、手机访问、启动、数据管理和关于,都并进了这个窗口。窗口窄时先列分区,点进去看内容,可以返回。
10
+ - 设置里新增「个性化」,放主题、语言、界面里的 Yew 和开场。开场可以选「点击进入」:启动完成后停在开场,点一下或按任意键再进去;默认仍是自动进入。
11
+ - 会话的命令和你自己加的 MCP 服务器在系统沙箱里运行(Anthropic 开源的 sandbox-runtime;macOS 上是 Seatbelt,Linux 上是 bubblewrap,要装 bubblewrap、socat 和 ripgrep):读写不了 Yew Harness 的数据,读不到钥匙串,只能写工作区、临时文件夹和沙箱自己的缓存,改不了程序和开机启动项,连不上 Yew Harness 的端口和局域网。联网只放行常用的包管理源、GitHub、Gitee 和配了密钥的模型服务商,连别的网站时先问你。凭据文件和 ssh-agent 默认不给,设置的「启动」里可以打开。要在沙箱外跑的命令每次都问你,在外面跑的 git 不执行仓库里的钩子。沙箱起不来时照常运行,`yew serve` 和设置的「启动」里写明原因;起 `yew serve` 时设 `YEW_SANDBOX=off` 可以关掉。
12
+ - 默认设置里新增「会话读不到的目录」:列在这里的文件夹,会话的文件工具读不到也改不了,搜索结果里也没有里面的文件;沙箱里的命令也读不到。
13
+ - 侧栏的 Yew 多了两个姿势:有授权请求等你时,她拿着一张待批的卡片;没有要你处理的事、也没有会话在干活,但有定时任务开着时,她在值守。
14
+
15
+ ### 变更
16
+
17
+ - 授权方式的说明写明:按需授权和完全授权下,不问就跑的命令以你的系统账户运行,能改 Yew Harness 自己的记录(包括决定和授权),也能读它保存的密钥;会话要处理网页、邮件、MCP 返回这类外来内容时,建议用逐项授权。README 加了「安全」一节说同样的事。
18
+ - 侧栏和关于页的标志,以及 iPhone 和安卓应用第一屏和关于页的标志,不再带橙色的 T。关于页的出品方写成小号横版组合「出品方 〔T〕榫卯 Tenon AI」;网页加到手机桌面时的图标去掉了右下角的 T。
19
+ - 隐私政策和用户协议更新到 2.6:产品名写成 Yew Harness;用户协议第 4 段写明,Yew Harness、Yew 和榫卯 Tenon 的名称和标志,以及角色 Yew 的形象和图片,不在 MIT 许可证的授权范围内。处理哪些数据、怎样处理都没有变。
20
+
21
+ ### 修复
22
+
23
+ - 开场动画里标志超出了外圈:叶尖越过圆圈,果子贴着圈边。现在整个标志缩小后居中放在圈里。
24
+ - 环境里没有 SHELL 时(比如在 Linux 上作为后台服务运行,或在容器里),会话的命令会因为找不到 /bin/zsh 而起不来;现在依次用 zsh、bash、sh 里这台电脑有的那个。
25
+ - 在设置里打开另一个对话框(比如关于页里的隐私政策)后按 Esc,外面的窗口也会跟着关掉;现在只关最上面那个。
26
+
27
+ ### 安全
28
+
29
+ - 自带的浏览器只能访问它自己的空文件夹,打不开 file:// 网页,也连不上 Yew Harness 的端口。
30
+ - 会话写的信里如果有一行冒充 Yew Harness 加的核验(比如「[Yew checked decision #3: …]」),收信的会话可能当真。现在 Yew Harness 的核验和说明放在信的结束标记之后,写信的一方写不到那里;信里冒充的行会改用全角的方括号,看得出来不是 Yew Harness 加的。
31
+
5
32
  ## [1.5.0] - 2026-11-18
6
33
 
7
34
  ### 新增
package/README.md CHANGED
@@ -6,11 +6,11 @@ AI 原生的多 Agent 工作台。
6
6
 
7
7
  每个会话有名字、职责、工作区、模型和权限,按团队组织:常设会话长期负责一块事,任务会话为一件事开设,做完回报,之后可以归档。会话之间用信件分派和回报。会话跑在你电脑上的 Yew Harness 服务里,网页关了也照常干活。
8
8
 
9
- Yew Harness 以 MIT 许可证开源,当前版本 1.5.0。能做什么见[更新记录](CHANGELOG.md),为什么这样做见[产品蓝图](docs/blueprint.md)。iPhone 应用的源码在 `ios/`,还没有上架;安卓版的源码在 `android/`,安装包见下面的「手机端」。
9
+ Yew Harness 以 MIT 许可证开源,当前版本 1.6.0。能做什么见[更新记录](CHANGELOG.md),为什么这样做见[产品蓝图](docs/blueprint.md)。iPhone 应用的源码在 `ios/`,还没有上架;安卓版的源码在 `android/`,安装包见下面的「手机端」。
10
10
 
11
11
  ## 安装与快速开始
12
12
 
13
- 需要 macOS 或 Linux、Node.js 24 或更高版本和 ripgrep(macOS:`brew install ripgrep`)。Windows 请在 WSL 里使用。
13
+ 需要 macOS 或 Linux、Node.js 24 或更高版本和 ripgrep(macOS:`brew install ripgrep`);Linux 上还要 bubblewrap 和 socat(Debian、Ubuntu:`sudo apt install ripgrep bubblewrap socat`)。Windows 请在 WSL 里使用。
14
14
 
15
15
  1. 安装:`npm install -g @tenonai/yew`。
16
16
  2. 存入一个模型服务商的 API Key(默认服务商是 DeepSeek):`yew key set deepseek`。Key 只存进系统钥匙串。
@@ -30,6 +30,24 @@ Yew Harness 以 MIT 许可证开源,当前版本 1.5.0。能做什么见[更
30
30
 
31
31
  Yew Harness 不收集任何数据,也不含统计、遥测或上报代码。会话、消息和设置存在你自己的电脑上,API Key 存在系统钥匙串里。你选用的模型服务商会收到发给它的对话内容,这部分适用该服务商的隐私政策。
32
32
 
33
+ ## 安全
34
+
35
+ 会话的命令和你自己加的 MCP 服务器在系统沙箱里运行。沙箱用的是 Anthropic 开源的 [sandbox-runtime](https://github.com/anthropics/sandbox-runtime)(Apache-2.0),macOS 上底层是系统的 Seatbelt,Linux 上是 bubblewrap。在沙箱里:
36
+
37
+ - 读写不了 Yew Harness 的数据目录(里面有你的决定、登录令牌和日志),也读不到钥匙串里的条目;
38
+ - 只能写会话的工作区、临时文件夹和沙箱自己的缓存,写不了 `~/.zshrc`、`~/.gitconfig` 这类文件,也写不了仓库的钩子和配置;
39
+ - 改不了 Yew Harness 的程序和开机启动项,连不上它的本机端口,也连不上别的本机端口和局域网;
40
+ - 联网只放行常用的包管理源、GitHub、Gitee 和配了密钥的模型服务商,连别的网站时先问你;
41
+ - 读不到 `~/.ssh`、`~/.aws`、`~/.netrc` 这类凭据文件,也用不了 ssh-agent,除非你在设置的「启动」里打开;
42
+ - 读不到你在「默认设置 → 会话读不到的目录」里列的文件夹,会话的文件工具也读不到;
43
+ - Linux 上连不上本机的 Unix 套接字,包括 D-Bus 会话总线。
44
+
45
+ 要在沙箱外跑的命令(比如要用钥匙串里凭据的 `git push`、新建或克隆仓库、要监听本机端口的开发服务器、Xcode 构建),每次都先问你;在外面跑的 git 不执行仓库里的钩子。自带的浏览器和电脑操控不进沙箱:浏览器只能访问它自己的空文件夹,打不开 `file://` 网页,也连不上 Yew Harness 的端口。从源码目录运行 Yew Harness 时,这个目录在沙箱里写不了,要用 Yew Harness 改 Yew Harness,请运行 npm 安装的版本。
46
+
47
+ 沙箱起不来时,Yew Harness 不进沙箱照常运行,并在 `yew serve` 的输出和设置的「启动」里写明原因:缺少要用的程序(macOS 要 ripgrep,Linux 要 bubblewrap、socat 和 ripgrep),系统不让 bubblewrap 建用户命名空间(比如 Ubuntu 24.04 起的默认设置,放开的办法见 sandbox-runtime 的说明),或起 `yew serve` 时设了 `YEW_SANDBOX=off`。这时按需授权和完全授权下,会话不问就跑的命令以你的系统账户运行,能做你在终端里能做的事,包括改 Yew Harness 自己的记录(决定和授权也在里面)、读它保存的 API Key。Linux 上的沙箱在 Debian 12 的容器里跑过日常的测试,还没在实机上测过。
48
+
49
+ 别的会话的信、网页、邮件和 MCP 返回的内容,Yew Harness 只当作数据,不能替你授权;会话要处理这类外来内容时,仍建议给它用逐项授权,让命令每次都先问你。
50
+
33
51
  ## 文档
34
52
 
35
53
  - [产品蓝图](docs/blueprint.md):为什么做、做什么、不做什么、怎么验收
@@ -45,11 +63,11 @@ Yew Harness 不收集任何数据,也不含统计、遥测或上报代码。
45
63
 
46
64
  [MIT](LICENSE)。运行时依赖和网页界面里用到的第三方包见 [THIRD-PARTY-NOTICES.md](THIRD-PARTY-NOTICES.md)。
47
65
 
48
- ## 名称和标志
66
+ ## 名称、标志和角色
49
67
 
50
- Yew 和榫卯 Tenon 的名称和标志(包括 `web/public/icons/`、`ios/Yew/Assets.xcassets/` 里的图标)不在 MIT 许可证的授权范围内。你可以照原样提到它们,说明你在使用 Yew 或基于它修改;但不要把它们用作你自己产品的名称或标志,也不要让人以为你的产品来自榫卯 Tenon AI 或得到它的认可。
68
+ Yew Harness、Yew 和榫卯 Tenon 的名称和标志(包括 `web/public/icons/`、`ios/Yew/Assets.xcassets/` 里的图标),以及角色 Yew 的形象和图片(包括 `web/public/mascot/`、`android/app/src/main/res/drawable-nodpi/` 里的图片和 `ios/Yew/Assets.xcassets/` 里 Mascot 开头的图片),不在 MIT 许可证的授权范围内。你可以照原样提到这些名称,说明你在使用 Yew Harness 或基于它修改;但不要把这些名称和标志用作你自己产品的名称或标志,不要在你自己的产品里使用 Yew 的形象和图片,也不要让人以为你的产品来自榫卯 Tenon AI 或得到它的认可。
51
69
 
52
- Name and logos: The Yew and Tenon AI names and logos, including the icons in `web/public/icons/` and `ios/Yew/Assets.xcassets/`, are not licensed under the MIT License. You may refer to them as they are to say that you use Yew or that your work is based on it, but do not use them as the name or logo of your own product, or in a way that suggests your product comes from or is endorsed by Tenon AI.
70
+ Names, logos and the character: The Yew Harness, Yew and Tenon AI names and logos, including the icons in `web/public/icons/` and `ios/Yew/Assets.xcassets/`, and the design and images of the character Yew, including the images in `web/public/mascot/` and `android/app/src/main/res/drawable-nodpi/` and the Mascot images in `ios/Yew/Assets.xcassets/`, are not licensed under the MIT License. You may refer to the names as they are to say that you use Yew Harness or that your work is based on it, but do not use the names or logos as the name or logo of your own product, do not use the character's design or images in your own product, and do not suggest that your product comes from or is endorsed by Tenon AI.
53
71
 
54
72
  ## 出品方
55
73
 
@@ -7,10 +7,11 @@ generated from `package-lock.json` by `scripts/notices.mjs`.
7
7
  The web interface is built from further packages; they are listed with their license texts in
8
8
  `web/dist/THIRD-PARTY-NOTICES.txt`.
9
9
 
10
- 109 packages: MIT 56, Apache-2.0 35, BSD-3-Clause 12, BSD-2-Clause 4, Unlicense 1, 0BSD 1.
10
+ 114 packages: MIT 59, Apache-2.0 36, BSD-3-Clause 12, BSD-2-Clause 4, Unlicense 1, (BSD-3-Clause OR GPL-2.0) 1, 0BSD 1.
11
11
 
12
12
  | Package | Version | License |
13
13
  | --- | --- | --- |
14
+ | @anthropic-ai/sandbox-runtime | 0.0.83 | Apache-2.0 |
14
15
  | @anthropic-ai/sdk | 0.129.0 | MIT |
15
16
  | @aws-sdk/client-bedrock-runtime | 3.1127.0 | Apache-2.0 |
16
17
  | @aws-sdk/core | 3.980.1 | Apache-2.0 |
@@ -51,6 +52,7 @@ The web interface is built from further packages; they are listed with their lic
51
52
  | @napi-rs/keyring-win32-arm64-msvc | 2.1.2 | MIT |
52
53
  | @napi-rs/keyring-win32-ia32-msvc | 2.1.2 | MIT |
53
54
  | @napi-rs/keyring-win32-x64-msvc | 2.1.2 | MIT |
55
+ | @pondwader/socks5-server | 1.0.10 | MIT |
54
56
  | @protobufjs/aspromise | 1.1.2 | BSD-3-Clause |
55
57
  | @protobufjs/base64 | 1.1.2 | BSD-3-Clause |
56
58
  | @protobufjs/codegen | 2.0.5 | BSD-3-Clause |
@@ -76,6 +78,7 @@ The web interface is built from further packages; they are listed with their lic
76
78
  | bignumber.js | 9.3.1 | MIT |
77
79
  | bowser | 2.15.0 | MIT |
78
80
  | buffer-equal-constant-time | 1.0.1 | BSD-3-Clause |
81
+ | commander | 12.1.0 | MIT |
79
82
  | data-uri-to-buffer | 4.0.1 | MIT |
80
83
  | debug | 4.4.3 | MIT |
81
84
  | diff | 9.0.0 | BSD-3-Clause |
@@ -106,6 +109,7 @@ The web interface is built from further packages; they are listed with their lic
106
109
  | ms | 2.1.3 | MIT |
107
110
  | node-domexception | 1.0.0 | MIT |
108
111
  | node-fetch | 3.3.2 | MIT |
112
+ | node-forge | 1.4.3 | (BSD-3-Clause OR GPL-2.0) |
109
113
  | openai | 7.19.0 | Apache-2.0 |
110
114
  | p-retry | 4.6.2 | MIT |
111
115
  | partial-json | 0.1.7 | MIT |
@@ -120,3 +124,4 @@ The web interface is built from further packages; they are listed with their lic
120
124
  | uqr | 0.1.3 | MIT |
121
125
  | web-streams-polyfill | 3.3.3 | MIT |
122
126
  | ws | 8.22.0 | MIT |
127
+ | zod | 4.6.6 | MIT |
package/dist/cli/serve.js CHANGED
@@ -32,6 +32,33 @@ Options:
32
32
  -h, --help Show this help
33
33
  `;
34
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
+ }
35
62
  /** The short commit of a source checkout; null when Yew does not run from a git checkout. */
36
63
  function shortCommit() {
37
64
  try {
@@ -85,6 +112,38 @@ export function serveCommand() {
85
112
  const { Scheduler } = await import("../server/schedules.js");
86
113
  const runtime = openRuntime({ env: io.env });
87
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
+ }
88
147
  const stuck = store.recoverAfterRestart();
89
148
  if (stuck.length > 0) {
90
149
  io.stderr.write(`${stuck.length} session(s) were working when Yew Harness last stopped. They are marked for review; nothing was redone.\n`);
@@ -106,7 +165,7 @@ export function serveCommand() {
106
165
  yewHome: home,
107
166
  version: VERSION,
108
167
  log,
109
- builtin: builtinMcp(home, io.env),
168
+ builtin: builtinMcp(home, io.env, port),
110
169
  prepare: mcpInstaller({ yewHome: home, env: io.env, log }),
111
170
  // Sign-ins to MCP servers: tokens in the keychain; the browser comes back to this port.
112
171
  auth: new McpAuth({
@@ -193,6 +252,7 @@ export function serveCommand() {
193
252
  });
194
253
  });
195
254
  if (!started) {
255
+ await sandbox.stopSandbox().catch(() => { });
196
256
  runtime.close();
197
257
  return EXIT_ERROR;
198
258
  }
@@ -212,6 +272,10 @@ export function serveCommand() {
212
272
  };
213
273
  syncRemote();
214
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);
215
279
  const info = { port, pid: process.pid, startedAt: Date.now() };
216
280
  writeFileSync(serveFile(home), JSON.stringify(info), { mode: 0o600 });
217
281
  const url = `http://127.0.0.1:${port}/#t=${issueLoginToken(store)}`;
@@ -223,6 +287,8 @@ export function serveCommand() {
223
287
  io.stderr.write("Stopping Yew Harness…\n");
224
288
  clearInterval(sweep);
225
289
  clearInterval(remoteSweep);
290
+ if (sitesSweep)
291
+ clearInterval(sitesSweep);
226
292
  scheduler.stop();
227
293
  notifier.stop();
228
294
  mcp.stop();
@@ -233,8 +299,14 @@ export function serveCommand() {
233
299
  if ("closeAllConnections" in server)
234
300
  server.closeAllConnections();
235
301
  rmSync(serveFile(home), { force: true });
236
- runtime.close();
237
- 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
+ });
238
310
  };
239
311
  process.once("SIGINT", stop);
240
312
  process.once("SIGTERM", stop);
@@ -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", []),
@@ -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,
@@ -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";
@@ -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) } : {}),
@@ -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. */
@@ -37,6 +37,12 @@ const PRESET_PROGRAMS = {
37
37
  sentry: "@sentry/mcp-server/dist/sentry-mcp.cjs",
38
38
  };
39
39
  export const INSTALLED_PRESETS = Object.keys(PRESET_PROGRAMS);
40
+ /** The services the presets talk to: what they may reach from the system sandbox (sandbox.ts). */
41
+ export const PRESET_SITES = {
42
+ gitee: ["gitee.com"],
43
+ notion: ["api.notion.com"],
44
+ sentry: ["sentry.io", "*.sentry.io"],
45
+ };
40
46
  /**
41
47
  * How the preset `id` is started: with node from Yew's data folder, with a small part of Yew's
42
48
  * environment and the entry's own variables (its token). Null for a preset Yew does not install.
@@ -52,7 +58,9 @@ export function presetMcp(yewHome, id) {
52
58
  preset: id,
53
59
  };
54
60
  }
55
- export function builtinMcp(yewHome, env = process.env) {
61
+ export function builtinMcp(yewHome, env = process.env,
62
+ /** Yew Harness's own port, which the browser is kept from. */
63
+ port) {
56
64
  if (env.YEW_MCP_BUILTIN === "off")
57
65
  return {};
58
66
  const modules = join(installDir(yewHome), "node_modules");
@@ -66,7 +74,12 @@ export function builtinMcp(yewHome, env = process.env) {
66
74
  // Page snapshots and screenshots it saves; otherwise they land in the folder Yew was started in.
67
75
  "--output-dir",
68
76
  join(yewHome, "tmp", "browser"),
77
+ // One more layer over Yew Harness's own port (the security group, 11-18).
78
+ ...(port ? ["--blocked-origins", `http://127.0.0.1:${port};http://localhost:${port}`] : []),
69
79
  ],
80
+ // Its root for files: uploads and named screenshots stay in this empty folder, not the whole
81
+ // computer, and file:// pages are refused (it is started without unrestricted file access).
82
+ cwd: join(yewHome, "browser-files"),
70
83
  ownEnv: true,
71
84
  },
72
85
  computer: {
@@ -1,9 +1,10 @@
1
1
  import { spawn } from "node:child_process";
2
- import { existsSync, readFileSync, statSync } from "node:fs";
2
+ import { existsSync, mkdirSync, readFileSync, statSync } from "node:fs";
3
3
  import { join } from "node:path";
4
4
  import { MCP_PRESETS } from "../shared/mcp-presets.js";
5
- import { presetMcp, serverEnv } from "./mcp-builtin.js";
5
+ import { PRESET_SITES, presetMcp, serverEnv } from "./mcp-builtin.js";
6
6
  import { SignInRequired } from "./mcp-oauth.js";
7
+ import { quote, sandboxed } from "./sandbox.js";
7
8
  import { errorResult, text } from "./tools/types.js";
8
9
  /** What the computer control tool does without changing anything. */
9
10
  const COMPUTER_READS = new Set(["get_screenshot", "get_cursor_position"]);
@@ -143,6 +144,16 @@ function oauthOf(value, env) {
143
144
  ...(scopes?.length ? { scopes } : {}),
144
145
  };
145
146
  }
147
+ /** The sites of an entry's `allowedDomains`: names with an optional `*.` and `:port`, up to 50. */
148
+ function sitesOf(value) {
149
+ if (!Array.isArray(value))
150
+ return undefined;
151
+ const sites = value
152
+ .filter((site) => typeof site === "string" &&
153
+ /^(\*\.)?[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*(:\d{1,5})?$/.test(site))
154
+ .slice(0, 50);
155
+ return sites.length > 0 ? sites : undefined;
156
+ }
146
157
  export function readMcpConfig(yewHome, env = process.env, builtin = {}) {
147
158
  const file = join(yewHome, "mcp.json");
148
159
  if (!existsSync(file))
@@ -175,20 +186,24 @@ export function readMcpConfig(yewHome, env = process.env, builtin = {}) {
175
186
  }
176
187
  else if (typeof entry.preset === "string" && presetMcp(yewHome, entry.preset)) {
177
188
  const envs = strings(entry.env);
189
+ const sites = sitesOf(entry.allowedDomains);
178
190
  configs[name] = {
179
191
  ...presetMcp(yewHome, entry.preset),
180
192
  ...(envs ? { env: envs } : {}),
193
+ ...(sites ? { allowedDomains: sites } : {}),
181
194
  ...off,
182
195
  };
183
196
  }
184
197
  else if (typeof entry.command === "string" && entry.command) {
185
198
  const envs = strings(entry.env);
199
+ const sites = sitesOf(entry.allowedDomains);
186
200
  configs[name] = {
187
201
  command: expand(entry.command, env),
188
202
  args: Array.isArray(entry.args)
189
203
  ? entry.args.filter((arg) => typeof arg === "string").map((arg) => expand(arg, env))
190
204
  : [],
191
205
  ...(envs ? { env: envs } : {}),
206
+ ...(sites ? { allowedDomains: sites } : {}),
192
207
  ...off,
193
208
  };
194
209
  }
@@ -207,11 +222,51 @@ class StdioTransport {
207
222
  #next = 1;
208
223
  #buffer = "";
209
224
  #closed = null;
210
- constructor(config, env) {
211
- this.#child = spawn(config.command, config.args ?? [], {
212
- env: { ...(config.ownEnv ? serverEnv(env) : env), ...config.env },
225
+ /**
226
+ * Starts a server. Yew Harness's own two run as they are: the browser's Chrome brings its own
227
+ * sandbox, which cannot start inside another, and computer control needs the screen. Every other
228
+ * server runs in the system sandbox when it is on (sandbox.ts), like a session's commands: it
229
+ * writes only temporary files and caches, reaches the sites it is allowed, and a preset may read
230
+ * its own code in the data folder.
231
+ */
232
+ static async start(config, env, yewHome, name) {
233
+ const variables = { ...(config.ownEnv ? serverEnv(env) : env), ...config.env };
234
+ if (config.cwd)
235
+ mkdirSync(config.cwd, { recursive: true });
236
+ const own = config.ownEnv === true && config.preset === undefined;
237
+ const line = [config.command, ...(config.args ?? [])].map(quote).join(" ");
238
+ const box = own
239
+ ? null
240
+ : await sandboxed(`exec ${line}`, {
241
+ grant: {
242
+ readable: config.preset ? [join(yewHome, "mcp-presets", config.preset)] : [],
243
+ sites: [
244
+ ...(config.preset ? (PRESET_SITES[config.preset] ?? []) : []),
245
+ ...(config.allowedDomains ?? []),
246
+ ],
247
+ },
248
+ text: line,
249
+ label: { kind: "mcp", text: name },
250
+ });
251
+ if (box) {
252
+ for (const variable of box.unset)
253
+ delete variables[variable];
254
+ Object.assign(variables, box.env);
255
+ }
256
+ const options = {
257
+ ...(config.cwd ? { cwd: config.cwd } : {}),
258
+ env: variables,
213
259
  stdio: ["pipe", "pipe", "pipe"],
214
- });
260
+ };
261
+ const child = box
262
+ ? spawn(box.line, { ...options, shell: true })
263
+ : spawn(config.command, config.args ?? [], options);
264
+ if (box)
265
+ child.once("exit", () => box.finish());
266
+ return new StdioTransport(child);
267
+ }
268
+ constructor(child) {
269
+ this.#child = child;
215
270
  this.#child.stdout.setEncoding("utf8");
216
271
  this.#child.stdout.on("data", (chunk) => this.#read(chunk));
217
272
  // What a server prints as diagnostics is not kept: it may hold what the server was given.
@@ -397,6 +452,7 @@ class Server {
397
452
  /** Where its sign-in page is, while it wants one. */
398
453
  signInAt = null;
399
454
  #transport = null;
455
+ #closed = false;
400
456
  constructor(name, config) {
401
457
  this.name = name;
402
458
  this.config = config;
@@ -407,7 +463,12 @@ class Server {
407
463
  return;
408
464
  }
409
465
  try {
410
- const transport = make(this.config);
466
+ const transport = await make(this.config);
467
+ // Closed while it was starting: the server it started goes too.
468
+ if (this.#closed) {
469
+ transport.close();
470
+ return;
471
+ }
411
472
  this.#transport = transport;
412
473
  const limit = AbortSignal.timeout(CONNECT_MS);
413
474
  await transport.request("initialize", {
@@ -459,6 +520,7 @@ class Server {
459
520
  }
460
521
  }
461
522
  close() {
523
+ this.#closed = true;
462
524
  this.#transport?.close();
463
525
  this.#transport = null;
464
526
  }
@@ -504,7 +566,7 @@ export class McpHub {
504
566
  const auth = this.#options.auth;
505
567
  const make = (name, config) => config.url
506
568
  ? new HttpTransport(config, this.#options.version, this.#options.fetch ?? fetch, auth ? () => auth.bearer(name, config.url) : null)
507
- : new StdioTransport(config, env);
569
+ : StdioTransport.start(config, env, this.#options.yewHome, name);
508
570
  const offer = () => {
509
571
  this.#definitions = [...this.#servers.values()].flatMap((server) => server.tools.map((tool) => this.#definition(server, tool)));
510
572
  };