@tenonai/yew 0.0.0-stage → 1.3.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 +273 -0
- package/LICENSE +21 -0
- package/README.md +64 -2
- package/THIRD-PARTY-NOTICES.md +122 -0
- package/bin/yew.js +9 -0
- package/dist/cli/app.js +211 -0
- package/dist/cli/export.js +57 -0
- package/dist/cli/io.js +65 -0
- package/dist/cli/key.js +113 -0
- package/dist/cli/main.js +58 -0
- package/dist/cli/mcp.js +76 -0
- package/dist/cli/remote.js +116 -0
- package/dist/cli/run.js +72 -0
- package/dist/cli/schedule.js +123 -0
- package/dist/cli/send.js +127 -0
- package/dist/cli/serve.js +301 -0
- package/dist/cli/service.js +268 -0
- package/dist/cli/system.js +44 -0
- package/dist/remote/access.js +107 -0
- package/dist/remote/connector.js +278 -0
- package/dist/remote/identity.js +71 -0
- package/dist/remote/noise.js +287 -0
- package/dist/remote/protocol.js +51 -0
- package/dist/remote/push.js +37 -0
- package/dist/server/agent/compaction.js +242 -0
- package/dist/server/agent/context.js +120 -0
- package/dist/server/agent/held.js +48 -0
- package/dist/server/agent/helper.js +122 -0
- package/dist/server/agent/mailroom.js +510 -0
- package/dist/server/agent/prompt.js +268 -0
- package/dist/server/agent/runner.js +1159 -0
- package/dist/server/artifacts.js +216 -0
- package/dist/server/budget.js +88 -0
- package/dist/server/data-export.js +105 -0
- package/dist/server/data-usage.js +144 -0
- package/dist/server/db/database.js +49 -0
- package/dist/server/db/migrations.js +343 -0
- package/dist/server/errors.js +16 -0
- package/dist/server/events.js +17 -0
- package/dist/server/export.js +378 -0
- package/dist/server/folder-picker.js +32 -0
- package/dist/server/from-jig.js +98 -0
- package/dist/server/http/agents.js +78 -0
- package/dist/server/http/api.js +465 -0
- package/dist/server/http/app.js +111 -0
- package/dist/server/http/artifacts.js +53 -0
- package/dist/server/http/data.js +54 -0
- package/dist/server/http/devices.js +47 -0
- package/dist/server/http/events.js +134 -0
- package/dist/server/http/idempotency.js +53 -0
- package/dist/server/http/input.js +106 -0
- package/dist/server/http/mail.js +52 -0
- package/dist/server/http/mcp.js +134 -0
- package/dist/server/http/notes.js +91 -0
- package/dist/server/http/problem.js +55 -0
- package/dist/server/http/providers.js +131 -0
- package/dist/server/http/schedules.js +58 -0
- package/dist/server/http/search.js +42 -0
- package/dist/server/http/security.js +168 -0
- package/dist/server/http/skills.js +53 -0
- package/dist/server/http/system.js +26 -0
- package/dist/server/ids.js +30 -0
- package/dist/server/keys.js +70 -0
- package/dist/server/mail/envelope.js +152 -0
- package/dist/server/mail/post.js +603 -0
- package/dist/server/mail/store.js +279 -0
- package/dist/server/manage.js +601 -0
- package/dist/server/mcp-builtin.js +180 -0
- package/dist/server/mcp-config.js +305 -0
- package/dist/server/mcp-oauth.js +448 -0
- package/dist/server/mcp.js +668 -0
- package/dist/server/model/gateway.js +410 -0
- package/dist/server/paths.js +43 -0
- package/dist/server/permissions/engine.js +249 -0
- package/dist/server/permissions/paths.js +93 -0
- package/dist/server/permissions/shell.js +635 -0
- package/dist/server/push.js +345 -0
- package/dist/server/reveal.js +36 -0
- package/dist/server/runtime.js +17 -0
- package/dist/server/schedules.js +356 -0
- package/dist/server/settings.js +77 -0
- package/dist/server/skills.js +263 -0
- package/dist/server/store.js +1077 -0
- package/dist/server/tools/files.js +318 -0
- package/dist/server/tools/html.js +221 -0
- package/dist/server/tools/jobs.js +38 -0
- package/dist/server/tools/mail.js +680 -0
- package/dist/server/tools/match.js +81 -0
- package/dist/server/tools/misc.js +253 -0
- package/dist/server/tools/process.js +128 -0
- package/dist/server/tools/read-state.js +40 -0
- package/dist/server/tools/registry.js +43 -0
- package/dist/server/tools/search.js +175 -0
- package/dist/server/tools/shell.js +124 -0
- package/dist/server/tools/types.js +43 -0
- package/dist/server/tools/web-search.js +198 -0
- package/dist/server/tools/web.js +240 -0
- package/dist/shared/cron.js +105 -0
- package/dist/shared/mcp-presets.js +170 -0
- package/dist/shared/messages.js +45 -0
- package/dist/shared/policy.js +42 -0
- package/dist/shared/types.js +34 -0
- package/dist/shared/version.js +8 -0
- package/mcp-builtin/package-lock.json +3398 -0
- package/mcp-builtin/package.json +14 -0
- package/mcp-builtin/presets/gitee/package-lock.json +105 -0
- package/mcp-builtin/presets/gitee/package.json +10 -0
- package/mcp-builtin/presets/notion/package-lock.json +2243 -0
- package/mcp-builtin/presets/notion/package.json +10 -0
- package/mcp-builtin/presets/sentry/package-lock.json +28 -0
- package/mcp-builtin/presets/sentry/package.json +10 -0
- package/package.json +75 -5
- package/web/dist/THIRD-PARTY-NOTICES.txt +1944 -0
- package/web/dist/assets/index-BtK_SzpF.css +1 -0
- package/web/dist/assets/index-C0rnUFI-.js +68 -0
- package/web/dist/icons/app-icon.png +0 -0
- package/web/dist/icons/apple-touch-icon.png +0 -0
- package/web/dist/icons/favicon-16.png +0 -0
- package/web/dist/icons/favicon-32.png +0 -0
- package/web/dist/icons/favicon-64.png +0 -0
- package/web/dist/icons/tenon-mark.svg +1 -0
- package/web/dist/icons/yew-mark.svg +1 -0
- package/web/dist/index.html +18 -0
- package/web/dist/mascot/gift.webp +0 -0
- package/web/dist/mascot/greeting.webp +0 -0
- package/web/dist/mascot/happy.webp +0 -0
- package/web/dist/mascot/lost.webp +0 -0
- package/web/dist/mascot/shush.webp +0 -0
- package/web/dist/mascot/sleepy.webp +0 -0
- package/web/dist/mascot/sorry.webp +0 -0
- package/web/dist/mascot/thinking.webp +0 -0
- package/web/dist/mascot/waking.webp +0 -0
- package/web/dist/mascot/writing.webp +0 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { dirname } from "node:path";
|
|
2
|
+
import { permissionModeOf, } from "../../shared/types.js";
|
|
3
|
+
import { isInside, isSecretPath, pathMatches, resolvePath, secretLocations } from "./paths.js";
|
|
4
|
+
import { isReadOnly, matchesPrefix, mustConfirmReason, parseShell, pathArguments, rememberPrefix, unwrap, } from "./shell.js";
|
|
5
|
+
const SAFE_REDIRECT_TARGETS = new Set(["/dev/null", "/dev/stdout", "/dev/stderr", "&1", "&2", "-"]);
|
|
6
|
+
/**
|
|
7
|
+
* The rules a new session takes over from the one it was opened by or copied from. "Always allow"
|
|
8
|
+
* for the tools of Yew's own browser and computer control was given for one session, with its scope
|
|
9
|
+
* said at the time (spec 21.2): it does not travel.
|
|
10
|
+
*/
|
|
11
|
+
export function inheritableRules(rules) {
|
|
12
|
+
return rules.filter((rule) => !(rule.effect === "allow" && /^mcp__(browser|computer)__/.test(rule.tool)));
|
|
13
|
+
}
|
|
14
|
+
function strongest(effects) {
|
|
15
|
+
if (effects.includes("deny"))
|
|
16
|
+
return "deny";
|
|
17
|
+
if (effects.includes("ask"))
|
|
18
|
+
return "ask";
|
|
19
|
+
if (effects.includes("allow"))
|
|
20
|
+
return "allow";
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Decides whether a tool call may run, must be asked about, or is refused (M1 plan, section 8).
|
|
25
|
+
* Order: credential locations are refused; must-confirm operations always ask and cannot be remembered
|
|
26
|
+
* (spec 21.2); then the session's rules, where deny beats ask beats allow; then the built-in defaults.
|
|
27
|
+
* Text in the transcript never counts as approval: only the person's answer in Yew does.
|
|
28
|
+
*/
|
|
29
|
+
export class PermissionEngine {
|
|
30
|
+
#secrets;
|
|
31
|
+
/** Folders outside the working folder that may be read without asking: memory and skill folders. */
|
|
32
|
+
readRoots = () => [];
|
|
33
|
+
constructor(yewHome) {
|
|
34
|
+
this.#secrets = secretLocations(yewHome);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* `flagged` is the model's own judgment, through the `confirm` argument: in the automatic mode a
|
|
38
|
+
* flagged call is asked about, others run. Must-confirm operations, explicit "ask" rules and commands
|
|
39
|
+
* Yew cannot read are asked about in every mode.
|
|
40
|
+
*/
|
|
41
|
+
decide(subject, session, flagged = false) {
|
|
42
|
+
switch (subject.kind) {
|
|
43
|
+
case "none":
|
|
44
|
+
return { effect: "allow" };
|
|
45
|
+
case "read":
|
|
46
|
+
case "write":
|
|
47
|
+
return this.#files(subject, session, flagged);
|
|
48
|
+
case "command":
|
|
49
|
+
return this.#command(subject, session, flagged);
|
|
50
|
+
case "url":
|
|
51
|
+
return this.#url(subject, session, flagged);
|
|
52
|
+
case "act":
|
|
53
|
+
return this.#act(subject, session, flagged);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** An approval Yew asks for only by default; the session's mode settles it. */
|
|
57
|
+
#byDefault(session, flagged, tool, summary, remember) {
|
|
58
|
+
const mode = permissionModeOf(session.options);
|
|
59
|
+
if (mode === "skip" || (mode === "auto" && !flagged))
|
|
60
|
+
return { effect: "allow" };
|
|
61
|
+
return this.#ask(tool, summary, undefined, remember);
|
|
62
|
+
}
|
|
63
|
+
#rulesFor(session, tool, matches) {
|
|
64
|
+
const effects = session.rules
|
|
65
|
+
.filter((rule) => (rule.tool === tool || rule.tool === "*") && (!rule.pattern || matches(rule)))
|
|
66
|
+
.map((rule) => rule.effect);
|
|
67
|
+
return strongest(effects);
|
|
68
|
+
}
|
|
69
|
+
#files(subject, session, flagged) {
|
|
70
|
+
const cwd = session.cwd;
|
|
71
|
+
for (const path of subject.paths) {
|
|
72
|
+
if (isSecretPath(path, this.#secrets)) {
|
|
73
|
+
const verb = subject.kind === "read" ? "read" : "change";
|
|
74
|
+
return {
|
|
75
|
+
effect: "deny",
|
|
76
|
+
reason: `${path} holds credentials or Yew's own data; sessions cannot ${verb} it.`,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const effects = subject.paths.map((path) => this.#rulesFor(session, subject.tool, (rule) => pathMatches(path, rule.pattern ?? "", cwd)));
|
|
81
|
+
if (effects.includes("deny")) {
|
|
82
|
+
return { effect: "deny", reason: "A rule in this session refuses this." };
|
|
83
|
+
}
|
|
84
|
+
const outside = subject.paths.filter((path) => !cwd || !isInside(path, cwd));
|
|
85
|
+
if (subject.kind === "write") {
|
|
86
|
+
if (outside.length > 0) {
|
|
87
|
+
return this.#ask(subject.tool, subject.summary, ["write-outside"]);
|
|
88
|
+
}
|
|
89
|
+
if (effects.includes("ask"))
|
|
90
|
+
return this.#ask(subject.tool, subject.summary);
|
|
91
|
+
if (effects.every((effect) => effect === "allow"))
|
|
92
|
+
return { effect: "allow" };
|
|
93
|
+
return this.#byDefault(session, flagged, subject.tool, subject.summary, [
|
|
94
|
+
{ effect: "allow", tool: subject.tool, pattern: "**" },
|
|
95
|
+
]);
|
|
96
|
+
}
|
|
97
|
+
if (effects.includes("ask"))
|
|
98
|
+
return this.#ask(subject.tool, subject.summary);
|
|
99
|
+
const roots = this.readRoots();
|
|
100
|
+
const needed = subject.paths.filter((path, index) => effects[index] !== "allow" &&
|
|
101
|
+
(!cwd || !isInside(path, cwd)) &&
|
|
102
|
+
!roots.some((root) => isInside(path, root)));
|
|
103
|
+
if (needed.length === 0)
|
|
104
|
+
return { effect: "allow" };
|
|
105
|
+
// Remember the folder: allowing ~/memory/a.md once usually means the person trusts ~/memory.
|
|
106
|
+
const folders = [
|
|
107
|
+
...new Set(needed.map((path) => (subject.tool === "read" ? dirname(path) : path))),
|
|
108
|
+
];
|
|
109
|
+
return this.#byDefault(session, flagged, subject.tool, subject.summary, folders.map((pattern) => ({ effect: "allow", tool: subject.tool, pattern })));
|
|
110
|
+
}
|
|
111
|
+
#command(subject, session, flagged) {
|
|
112
|
+
const cwd = session.cwd;
|
|
113
|
+
const parsed = parseShell(subject.command);
|
|
114
|
+
const commands = [];
|
|
115
|
+
let privileged = false;
|
|
116
|
+
let understood = parsed.understood;
|
|
117
|
+
let dynamic = false;
|
|
118
|
+
const redirectTargets = [];
|
|
119
|
+
for (const segment of parsed.segments) {
|
|
120
|
+
dynamic ||= segment.dynamic;
|
|
121
|
+
for (const redirect of segment.redirects) {
|
|
122
|
+
const duplicatesDescriptor = redirect.op.endsWith("&") && /^(\d+|-)$/.test(redirect.target);
|
|
123
|
+
if (redirect.op.includes(">") &&
|
|
124
|
+
!duplicatesDescriptor &&
|
|
125
|
+
!SAFE_REDIRECT_TARGETS.has(redirect.target)) {
|
|
126
|
+
redirectTargets.push(redirect.target);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const inner = unwrap(segment.argv);
|
|
130
|
+
commands.push(...inner.commands);
|
|
131
|
+
privileged ||= inner.privileged;
|
|
132
|
+
understood &&= inner.understood;
|
|
133
|
+
}
|
|
134
|
+
const reasons = new Set();
|
|
135
|
+
for (const argv of commands) {
|
|
136
|
+
const reason = mustConfirmReason(argv);
|
|
137
|
+
if (reason)
|
|
138
|
+
reasons.add(reason);
|
|
139
|
+
// File tools cannot touch these places at all; a command that names one asks every time.
|
|
140
|
+
const secret = pathArguments(argv).some((arg) => {
|
|
141
|
+
const path = resolvePath(arg, cwd);
|
|
142
|
+
return path !== null && isSecretPath(path, this.#secrets);
|
|
143
|
+
});
|
|
144
|
+
if (secret)
|
|
145
|
+
reasons.add("credentials");
|
|
146
|
+
}
|
|
147
|
+
if (privileged)
|
|
148
|
+
reasons.add("admin");
|
|
149
|
+
for (const target of redirectTargets) {
|
|
150
|
+
const path = resolvePath(target, cwd);
|
|
151
|
+
if (!path || !cwd || !isInside(path, cwd))
|
|
152
|
+
reasons.add("write-outside");
|
|
153
|
+
else if (isSecretPath(path, this.#secrets))
|
|
154
|
+
reasons.add("write-credentials");
|
|
155
|
+
}
|
|
156
|
+
const ruleFor = (argv) => this.#rulesFor(session, subject.tool, (r) => matchesPrefix(argv, r.pattern ?? ""));
|
|
157
|
+
if (commands.some((argv) => ruleFor(argv) === "deny")) {
|
|
158
|
+
return { effect: "deny", reason: "A rule in this session refuses this command." };
|
|
159
|
+
}
|
|
160
|
+
if (reasons.size > 0)
|
|
161
|
+
return this.#ask(subject.tool, subject.command, [...reasons]);
|
|
162
|
+
if (!understood || dynamic)
|
|
163
|
+
return this.#ask(subject.tool, subject.command);
|
|
164
|
+
const pending = [];
|
|
165
|
+
let ruleAsks = false;
|
|
166
|
+
for (const argv of commands) {
|
|
167
|
+
const rule = ruleFor(argv);
|
|
168
|
+
if (rule === "ask")
|
|
169
|
+
ruleAsks = true;
|
|
170
|
+
if (rule === "allow")
|
|
171
|
+
continue;
|
|
172
|
+
if (rule === null && this.#readOnlyHere(argv, cwd))
|
|
173
|
+
continue;
|
|
174
|
+
pending.push(argv);
|
|
175
|
+
}
|
|
176
|
+
if (ruleAsks)
|
|
177
|
+
return this.#ask(subject.tool, subject.command);
|
|
178
|
+
if (redirectTargets.length === 0 && pending.length === 0)
|
|
179
|
+
return { effect: "allow" };
|
|
180
|
+
const remember = [...new Set(pending.map(rememberPrefix))].map((pattern) => ({
|
|
181
|
+
effect: "allow",
|
|
182
|
+
tool: subject.tool,
|
|
183
|
+
pattern,
|
|
184
|
+
}));
|
|
185
|
+
return this.#byDefault(session, flagged, subject.tool, subject.command, pending.length === 0 ? undefined : remember);
|
|
186
|
+
}
|
|
187
|
+
#readOnlyHere(argv, cwd) {
|
|
188
|
+
if (!cwd || !isReadOnly(argv))
|
|
189
|
+
return false;
|
|
190
|
+
return pathArguments(argv).every((arg) => {
|
|
191
|
+
const path = resolvePath(arg, cwd);
|
|
192
|
+
return path !== null && isInside(path, cwd) && !isSecretPath(path, this.#secrets);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
#url(subject, session, flagged) {
|
|
196
|
+
let host;
|
|
197
|
+
try {
|
|
198
|
+
host = new URL(subject.url).hostname.toLowerCase();
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
return { effect: "deny", reason: "This is not a valid URL." };
|
|
202
|
+
}
|
|
203
|
+
const rule = this.#rulesFor(session, subject.tool, (r) => {
|
|
204
|
+
const pattern = (r.pattern ?? "").toLowerCase();
|
|
205
|
+
return pattern.startsWith("*.")
|
|
206
|
+
? host.endsWith(pattern.slice(1)) || host === pattern.slice(2)
|
|
207
|
+
: host === pattern;
|
|
208
|
+
});
|
|
209
|
+
if (rule === "deny")
|
|
210
|
+
return { effect: "deny", reason: `A rule in this session refuses ${host}.` };
|
|
211
|
+
if (rule === "allow")
|
|
212
|
+
return { effect: "allow" };
|
|
213
|
+
if (rule === "ask")
|
|
214
|
+
return this.#ask(subject.tool, subject.url);
|
|
215
|
+
return this.#byDefault(session, flagged, subject.tool, subject.url, [
|
|
216
|
+
{ effect: "allow", tool: subject.tool, pattern: host },
|
|
217
|
+
]);
|
|
218
|
+
}
|
|
219
|
+
#act(subject, session, flagged) {
|
|
220
|
+
const rule = this.#rulesFor(session, subject.tool, (r) => !r.pattern || r.pattern === subject.scope);
|
|
221
|
+
if (rule === "deny")
|
|
222
|
+
return { effect: "deny", reason: "A rule in this session refuses this." };
|
|
223
|
+
if (subject.reasons && subject.reasons.length > 0) {
|
|
224
|
+
return this.#ask(subject.tool, subject.summary, subject.reasons);
|
|
225
|
+
}
|
|
226
|
+
if (rule === "allow")
|
|
227
|
+
return { effect: "allow" };
|
|
228
|
+
const remember = [
|
|
229
|
+
subject.scope
|
|
230
|
+
? { effect: "allow", tool: subject.tool, pattern: subject.scope }
|
|
231
|
+
: { effect: "allow", tool: subject.tool },
|
|
232
|
+
];
|
|
233
|
+
if (rule === "ask" || subject.always) {
|
|
234
|
+
const decision = this.#ask(subject.tool, subject.summary, undefined, remember);
|
|
235
|
+
if (subject.warning && decision.effect === "ask")
|
|
236
|
+
decision.request.warning = subject.warning;
|
|
237
|
+
return decision;
|
|
238
|
+
}
|
|
239
|
+
return this.#byDefault(session, flagged, subject.tool, subject.summary, remember);
|
|
240
|
+
}
|
|
241
|
+
#ask(tool, summary, reasons, remember) {
|
|
242
|
+
const request = { tool, summary, mustConfirm: reasons !== undefined };
|
|
243
|
+
if (reasons)
|
|
244
|
+
request.reasons = reasons;
|
|
245
|
+
else if (remember && remember.length > 0)
|
|
246
|
+
request.rememberRules = remember;
|
|
247
|
+
return { effect: "ask", request };
|
|
248
|
+
}
|
|
249
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
4
|
+
/** Expands `~` and resolves against the working folder. Returns null for a relative path without one. */
|
|
5
|
+
export function resolvePath(input, cwd) {
|
|
6
|
+
const expanded = input === "~" ? homedir() : input.startsWith("~/") ? join(homedir(), input.slice(2)) : input;
|
|
7
|
+
if (isAbsolute(expanded))
|
|
8
|
+
return canonical(resolve(expanded));
|
|
9
|
+
if (!cwd)
|
|
10
|
+
return null;
|
|
11
|
+
return canonical(resolve(cwd, expanded));
|
|
12
|
+
}
|
|
13
|
+
/** Resolves symlinks in the longest existing part of the path, so a link cannot lead out of a folder unnoticed. */
|
|
14
|
+
export function canonical(path) {
|
|
15
|
+
let existing = path;
|
|
16
|
+
const missing = [];
|
|
17
|
+
while (!existsSync(existing)) {
|
|
18
|
+
const parent = dirname(existing);
|
|
19
|
+
if (parent === existing)
|
|
20
|
+
return path;
|
|
21
|
+
missing.unshift(basename(existing));
|
|
22
|
+
existing = parent;
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
return join(realpathSync(existing), ...missing);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return path;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function isInside(path, folder) {
|
|
32
|
+
if (path === folder)
|
|
33
|
+
return true;
|
|
34
|
+
const rel = relative(folder, path);
|
|
35
|
+
return rel !== "" && !rel.startsWith("..") && !isAbsolute(rel);
|
|
36
|
+
}
|
|
37
|
+
/** Places that hold credentials. Sessions never read or write them through file tools (M1 plan, section 7). */
|
|
38
|
+
export function secretLocations(yewHome) {
|
|
39
|
+
const home = homedir();
|
|
40
|
+
return [
|
|
41
|
+
yewHome,
|
|
42
|
+
join(home, ".ssh"),
|
|
43
|
+
join(home, ".gnupg"),
|
|
44
|
+
join(home, ".aws"),
|
|
45
|
+
join(home, ".azure"),
|
|
46
|
+
join(home, ".kube"),
|
|
47
|
+
join(home, ".docker"),
|
|
48
|
+
join(home, ".config", "gcloud"),
|
|
49
|
+
join(home, ".config", "gh"),
|
|
50
|
+
join(home, ".netrc"),
|
|
51
|
+
join(home, ".npmrc"),
|
|
52
|
+
join(home, ".pypirc"),
|
|
53
|
+
join(home, ".git-credentials"),
|
|
54
|
+
join(home, "Library", "Keychains"),
|
|
55
|
+
].map(canonical);
|
|
56
|
+
}
|
|
57
|
+
export function isSecretPath(path, secrets) {
|
|
58
|
+
return secrets.some((secret) => isInside(path, secret));
|
|
59
|
+
}
|
|
60
|
+
/** Converts a path glob (`*`, `**`, `?`) to a regular expression over absolute paths. */
|
|
61
|
+
export function globToRegExp(glob) {
|
|
62
|
+
let pattern = "";
|
|
63
|
+
for (let i = 0; i < glob.length; i++) {
|
|
64
|
+
const c = glob[i];
|
|
65
|
+
if (c === "*") {
|
|
66
|
+
if (glob[i + 1] === "*") {
|
|
67
|
+
const slash = glob[i + 2] === "/";
|
|
68
|
+
pattern += slash ? "(?:.*/)?" : ".*";
|
|
69
|
+
i += slash ? 2 : 1;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
pattern += "[^/]*";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else if (c === "?") {
|
|
76
|
+
pattern += "[^/]";
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
pattern += c.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return new RegExp(`^${pattern}$`);
|
|
83
|
+
}
|
|
84
|
+
/** Matches a rule's path pattern; relative patterns are relative to the working folder. */
|
|
85
|
+
export function pathMatches(path, pattern, cwd) {
|
|
86
|
+
const absolute = resolvePath(pattern, cwd);
|
|
87
|
+
if (!absolute)
|
|
88
|
+
return false;
|
|
89
|
+
if (!/[*?]/.test(pattern))
|
|
90
|
+
return isInside(path, absolute);
|
|
91
|
+
const base = pattern.startsWith("~") || isAbsolute(pattern) ? absolute : join(cwd ?? "", pattern);
|
|
92
|
+
return globToRegExp(base.split(sep).join("/")).test(path.split(sep).join("/"));
|
|
93
|
+
}
|