@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.
- package/CHANGELOG.md +48 -5
- package/README.md +31 -13
- package/THIRD-PARTY-NOTICES.md +6 -1
- package/dist/cli/app.js +22 -12
- package/dist/cli/export.js +5 -5
- package/dist/cli/mcp.js +7 -7
- package/dist/cli/remote.js +6 -6
- package/dist/cli/run.js +3 -3
- package/dist/cli/schedule.js +3 -3
- package/dist/cli/send.js +4 -4
- package/dist/cli/serve.js +88 -14
- package/dist/cli/service.js +13 -13
- package/dist/server/agent/prompt.js +3 -2
- package/dist/server/agent/runner.js +41 -1
- package/dist/server/data-usage.js +1 -1
- package/dist/server/db/database.js +1 -1
- package/dist/server/export.js +2 -2
- package/dist/server/folder-picker.js +1 -1
- package/dist/server/http/api.js +17 -1
- package/dist/server/http/app.js +13 -5
- package/dist/server/http/data.js +1 -1
- package/dist/server/http/mcp.js +2 -2
- package/dist/server/http/problem.js +1 -1
- package/dist/server/http/security.js +5 -5
- package/dist/server/mail/envelope.js +11 -6
- package/dist/server/mail/post.js +2 -2
- package/dist/server/mcp-builtin.js +15 -2
- package/dist/server/mcp-config.js +4 -4
- package/dist/server/mcp-oauth.js +6 -6
- package/dist/server/mcp.js +70 -8
- package/dist/server/permissions/engine.js +23 -5
- package/dist/server/sandbox.js +447 -0
- package/dist/server/settings.js +34 -1
- package/dist/server/store.js +2 -2
- package/dist/server/tools/jobs.js +3 -2
- package/dist/server/tools/mail.js +11 -1
- package/dist/server/tools/process.js +63 -12
- package/dist/server/tools/search.js +5 -2
- package/dist/server/tools/shell.js +70 -17
- package/dist/shared/policy.js +20 -20
- package/dist/shared/version.js +8 -0
- package/dist/sim/client.d.ts +17 -0
- package/dist/sim/client.js +41 -0
- package/dist/sim/index.d.ts +7 -0
- package/dist/sim/index.js +6 -0
- package/dist/sim/types.d.ts +161 -0
- package/dist/sim/types.js +5 -0
- package/dist/sim/world.d.ts +6 -0
- package/dist/sim/world.js +359 -0
- package/package.json +17 -3
- package/web/dist/THIRD-PARTY-NOTICES.txt +1 -1
- package/web/dist/assets/index-BQdFuM-f.css +1 -0
- package/web/dist/assets/index-Dh9QdEsc.js +70 -0
- package/web/dist/icons/apple-touch-icon.png +0 -0
- package/web/dist/index.html +3 -3
- package/web/dist/mascot/alarm.webp +0 -0
- package/web/dist/mascot/books.webp +0 -0
- package/web/dist/mascot/bow.webp +0 -0
- package/web/dist/mascot/branch.webp +0 -0
- package/web/dist/mascot/clipboard.webp +0 -0
- package/web/dist/mascot/dozing.webp +0 -0
- package/web/dist/mascot/fired-up.webp +0 -0
- package/web/dist/mascot/giftbox.webp +0 -0
- package/web/dist/mascot/halt.webp +0 -0
- package/web/dist/mascot/jump.webp +0 -0
- package/web/dist/mascot/letter-run.webp +0 -0
- package/web/dist/mascot/magnifier.webp +0 -0
- package/web/dist/mascot/mini.webp +0 -0
- package/web/dist/mascot/nap.webp +0 -0
- package/web/dist/mascot/on-duty.webp +0 -0
- package/web/dist/mascot/pajamas.webp +0 -0
- package/web/dist/mascot/paper-plane.webp +0 -0
- package/web/dist/mascot/peek.webp +0 -0
- package/web/dist/mascot/permission.webp +0 -0
- package/web/dist/mascot/phone.webp +0 -0
- package/web/dist/mascot/pointing.webp +0 -0
- package/web/dist/mascot/portrait.webp +0 -0
- package/web/dist/mascot/pout.webp +0 -0
- package/web/dist/mascot/proud.webp +0 -0
- package/web/dist/mascot/reading.webp +0 -0
- package/web/dist/mascot/stamp.webp +0 -0
- package/web/dist/mascot/stretch.webp +0 -0
- package/web/dist/mascot/surprised.webp +0 -0
- package/web/dist/mascot/tea.webp +0 -0
- package/web/dist/mascot/teary.webp +0 -0
- package/web/dist/mascot/typing.webp +0 -0
- package/dist/server/from-jig.js +0 -98
- package/web/dist/assets/index-B9oWPSod.css +0 -1
- package/web/dist/assets/index-C5qBMzFX.js +0 -68
|
@@ -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: {
|
|
@@ -125,7 +138,7 @@ function lockedInstaller(options, source, folder, what) {
|
|
|
125
138
|
}
|
|
126
139
|
/** Makes sure Yew's own two servers are installed as the lock file that ships with this Yew says. */
|
|
127
140
|
export function builtinInstaller(options) {
|
|
128
|
-
return lockedInstaller(options, options.source ?? SOURCE, installDir(options.yewHome), "Yew's own servers (browser, computer control)");
|
|
141
|
+
return lockedInstaller(options, options.source ?? SOURCE, installDir(options.yewHome), "Yew Harness's own servers (browser, computer control)");
|
|
129
142
|
}
|
|
130
143
|
/**
|
|
131
144
|
* What the hub calls before it starts a server Yew runs from its data folder: installs Yew's own
|
|
@@ -34,7 +34,7 @@ function readFile(yewHome) {
|
|
|
34
34
|
}
|
|
35
35
|
if (!isObject(doc)) {
|
|
36
36
|
// Not overwritten: the person may have servers in it that a typo is hiding.
|
|
37
|
-
throw conflict("mcp.json in Yew's data folder is not valid JSON. Correct it by hand first.", undefined, "mcp-unreadable");
|
|
37
|
+
throw conflict("mcp.json in Yew Harness's data folder is not valid JSON. Correct it by hand first.", undefined, "mcp-unreadable");
|
|
38
38
|
}
|
|
39
39
|
const key = doc.mcpServers === undefined && doc.servers !== undefined ? "servers" : "mcpServers";
|
|
40
40
|
if (doc[key] !== undefined && !isObject(doc[key])) {
|
|
@@ -192,7 +192,7 @@ export function addMcpEntry(yewHome, input) {
|
|
|
192
192
|
let entry;
|
|
193
193
|
if (preset) {
|
|
194
194
|
if (!presetPackage(preset))
|
|
195
|
-
throw invalid(`Yew has no preset named ${preset}.`, "preset");
|
|
195
|
+
throw invalid(`Yew Harness has no preset named ${preset}.`, "preset");
|
|
196
196
|
const env = input.env ?? {};
|
|
197
197
|
checkValues(env, ENV_NAME, "env");
|
|
198
198
|
entry = { preset, ...(Object.keys(env).length > 0 ? { env } : {}) };
|
|
@@ -248,7 +248,7 @@ export function patchMcpEntry(yewHome, name, patch, builtin = {}) {
|
|
|
248
248
|
if (builtin[name] && (!Object.hasOwn(servers, name) || turnsOff(servers[name]))) {
|
|
249
249
|
// One of Yew's own: the file only records that it is off.
|
|
250
250
|
if (patch.env || patch.headers) {
|
|
251
|
-
throw invalid("A server Yew sets up by itself has no variables to set.", "env");
|
|
251
|
+
throw invalid("A server Yew Harness sets up by itself has no variables to set.", "env");
|
|
252
252
|
}
|
|
253
253
|
if (patch.disabled === true)
|
|
254
254
|
servers[name] = { disabled: true };
|
|
@@ -297,7 +297,7 @@ export function patchMcpEntry(yewHome, name, patch, builtin = {}) {
|
|
|
297
297
|
export function removeMcpEntry(yewHome, name, builtin = {}) {
|
|
298
298
|
const { doc, servers } = readFile(yewHome);
|
|
299
299
|
if (builtin[name] && (!Object.hasOwn(servers, name) || turnsOff(servers[name]))) {
|
|
300
|
-
throw conflict(`${name} is set up by Yew itself. It can be turned off, not removed.`, undefined, "mcp-builtin");
|
|
300
|
+
throw conflict(`${name} is set up by Yew Harness itself. It can be turned off, not removed.`, undefined, "mcp-builtin");
|
|
301
301
|
}
|
|
302
302
|
entryOf(servers, name);
|
|
303
303
|
delete servers[name];
|
package/dist/server/mcp-oauth.js
CHANGED
|
@@ -220,13 +220,13 @@ export class McpAuth {
|
|
|
220
220
|
const pending = this.#pending.get(state);
|
|
221
221
|
this.#pending.delete(state);
|
|
222
222
|
if (!pending || this.#now() - pending.createdAt > PENDING_MS) {
|
|
223
|
-
throw new Error("This sign-in is not valid any more. Start it again from Yew.");
|
|
223
|
+
throw new Error("This sign-in is not valid any more. Start it again from Yew Harness.");
|
|
224
224
|
}
|
|
225
225
|
const { saved } = pending;
|
|
226
226
|
// RFC 9207: a return that names a sign-in server, or that should and does not, comes from the
|
|
227
227
|
// one the browser was sent to, or it is not used.
|
|
228
228
|
if (iss !== null ? !same(iss, saved.endpoints.issuer) : saved.endpoints.namesItself) {
|
|
229
|
-
throw new Error("The sign-in came back from another server than the one Yew sent you to.");
|
|
229
|
+
throw new Error("The sign-in came back from another server than the one Yew Harness sent you to.");
|
|
230
230
|
}
|
|
231
231
|
if (error || !code)
|
|
232
232
|
throw new Error(`The sign-in was not completed (${error ?? "no code"}).`);
|
|
@@ -242,7 +242,7 @@ export class McpAuth {
|
|
|
242
242
|
body.set("client_secret", saved.client.secret);
|
|
243
243
|
const answer = await this.#post(saved.endpoints.token, body);
|
|
244
244
|
if (!answer || typeof answer.access_token !== "string") {
|
|
245
|
-
throw new Error("The server did not give Yew a token.");
|
|
245
|
+
throw new Error("The server did not give Yew Harness a token.");
|
|
246
246
|
}
|
|
247
247
|
await this.#save(pending.server, { ...saved, tokens: tokensFrom(answer, this.#now()) });
|
|
248
248
|
return pending.server;
|
|
@@ -337,7 +337,7 @@ export class McpAuth {
|
|
|
337
337
|
const at = new URL(resource);
|
|
338
338
|
const local = at.protocol === "http:" && LOOPBACK.has(at.hostname);
|
|
339
339
|
if (!usable(resource, local)) {
|
|
340
|
-
throw new Error("Yew signs in only to servers at https addresses.");
|
|
340
|
+
throw new Error("Yew Harness signs in only to servers at https addresses.");
|
|
341
341
|
}
|
|
342
342
|
const named = param(challenge, "resource_metadata");
|
|
343
343
|
if (named !== null && !usable(named, local)) {
|
|
@@ -428,7 +428,7 @@ export class McpAuth {
|
|
|
428
428
|
throw new Error("This server only accepts clients registered in advance. Add its client ID and secret to its entry in mcp.json.");
|
|
429
429
|
}
|
|
430
430
|
const answer = await this.#post(endpoints.registration, JSON.stringify({
|
|
431
|
-
client_name: "Yew",
|
|
431
|
+
client_name: "Yew Harness",
|
|
432
432
|
redirect_uris: [this.#redirect],
|
|
433
433
|
grant_types: ["authorization_code", "refresh_token"],
|
|
434
434
|
response_types: ["code"],
|
|
@@ -436,7 +436,7 @@ export class McpAuth {
|
|
|
436
436
|
software_version: this.#version,
|
|
437
437
|
}));
|
|
438
438
|
if (!answer || typeof answer.client_id !== "string") {
|
|
439
|
-
throw new Error("The server did not let Yew register to sign in.");
|
|
439
|
+
throw new Error("The server did not let Yew Harness register to sign in.");
|
|
440
440
|
}
|
|
441
441
|
return {
|
|
442
442
|
id: answer.client_id,
|
package/dist/server/mcp.js
CHANGED
|
@@ -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
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
-
:
|
|
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
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { dirname } from "node:path";
|
|
2
2
|
import { permissionModeOf, } from "../../shared/types.js";
|
|
3
|
-
import { isInside, isSecretPath, pathMatches, resolvePath, secretLocations } from "./paths.js";
|
|
3
|
+
import { canonical, isInside, isSecretPath, pathMatches, resolvePath, secretLocations, } from "./paths.js";
|
|
4
4
|
import { isReadOnly, matchesPrefix, mustConfirmReason, parseShell, pathArguments, rememberPrefix, unwrap, } from "./shell.js";
|
|
5
5
|
const SAFE_REDIRECT_TARGETS = new Set(["/dev/null", "/dev/stdout", "/dev/stderr", "&1", "&2", "-"]);
|
|
6
6
|
/**
|
|
@@ -30,9 +30,19 @@ export class PermissionEngine {
|
|
|
30
30
|
#secrets;
|
|
31
31
|
/** Folders outside the working folder that may be read without asking: memory and skill folders. */
|
|
32
32
|
readRoots = () => [];
|
|
33
|
+
/** Folders the person keeps from sessions (the settings): refused like credential locations. */
|
|
34
|
+
hidden = () => [];
|
|
33
35
|
constructor(yewHome) {
|
|
34
36
|
this.#secrets = secretLocations(yewHome);
|
|
35
37
|
}
|
|
38
|
+
/** Credential locations, Yew's own data and the folders the person keeps from sessions. */
|
|
39
|
+
#offLimits() {
|
|
40
|
+
return [...this.#secrets, ...this.hidden().map(canonical)];
|
|
41
|
+
}
|
|
42
|
+
/** Whether sessions may never read or change `path` (an absolute path). */
|
|
43
|
+
offLimits(path) {
|
|
44
|
+
return isSecretPath(path, this.#offLimits());
|
|
45
|
+
}
|
|
36
46
|
/**
|
|
37
47
|
* `flagged` is the model's own judgment, through the `confirm` argument: in the automatic mode a
|
|
38
48
|
* flagged call is asked about, others run. Must-confirm operations, explicit "ask" rules and commands
|
|
@@ -69,13 +79,19 @@ export class PermissionEngine {
|
|
|
69
79
|
#files(subject, session, flagged) {
|
|
70
80
|
const cwd = session.cwd;
|
|
71
81
|
for (const path of subject.paths) {
|
|
82
|
+
const verb = subject.kind === "read" ? "read" : "change";
|
|
72
83
|
if (isSecretPath(path, this.#secrets)) {
|
|
73
|
-
const verb = subject.kind === "read" ? "read" : "change";
|
|
74
84
|
return {
|
|
75
85
|
effect: "deny",
|
|
76
86
|
reason: `${path} holds credentials or Yew's own data; sessions cannot ${verb} it.`,
|
|
77
87
|
};
|
|
78
88
|
}
|
|
89
|
+
if (this.offLimits(path)) {
|
|
90
|
+
return {
|
|
91
|
+
effect: "deny",
|
|
92
|
+
reason: `${path} is in a folder the person keeps from sessions; sessions cannot ${verb} it.`,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
79
95
|
}
|
|
80
96
|
const effects = subject.paths.map((path) => this.#rulesFor(session, subject.tool, (rule) => pathMatches(path, rule.pattern ?? "", cwd)));
|
|
81
97
|
if (effects.includes("deny")) {
|
|
@@ -139,18 +155,20 @@ export class PermissionEngine {
|
|
|
139
155
|
// File tools cannot touch these places at all; a command that names one asks every time.
|
|
140
156
|
const secret = pathArguments(argv).some((arg) => {
|
|
141
157
|
const path = resolvePath(arg, cwd);
|
|
142
|
-
return path !== null && isSecretPath(path, this.#
|
|
158
|
+
return path !== null && isSecretPath(path, this.#offLimits());
|
|
143
159
|
});
|
|
144
160
|
if (secret)
|
|
145
161
|
reasons.add("credentials");
|
|
146
162
|
}
|
|
147
163
|
if (privileged)
|
|
148
164
|
reasons.add("admin");
|
|
165
|
+
if (subject.outsideSandbox)
|
|
166
|
+
reasons.add("outside-sandbox");
|
|
149
167
|
for (const target of redirectTargets) {
|
|
150
168
|
const path = resolvePath(target, cwd);
|
|
151
169
|
if (!path || !cwd || !isInside(path, cwd))
|
|
152
170
|
reasons.add("write-outside");
|
|
153
|
-
else if (isSecretPath(path, this.#
|
|
171
|
+
else if (isSecretPath(path, this.#offLimits()))
|
|
154
172
|
reasons.add("write-credentials");
|
|
155
173
|
}
|
|
156
174
|
const ruleFor = (argv) => this.#rulesFor(session, subject.tool, (r) => matchesPrefix(argv, r.pattern ?? ""));
|
|
@@ -189,7 +207,7 @@ export class PermissionEngine {
|
|
|
189
207
|
return false;
|
|
190
208
|
return pathArguments(argv).every((arg) => {
|
|
191
209
|
const path = resolvePath(arg, cwd);
|
|
192
|
-
return path !== null && isInside(path, cwd) && !isSecretPath(path, this.#
|
|
210
|
+
return path !== null && isInside(path, cwd) && !isSecretPath(path, this.#offLimits());
|
|
193
211
|
});
|
|
194
212
|
}
|
|
195
213
|
#url(subject, session, flagged) {
|