dsh-extra-paths 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +98 -2
- package/README.zh.md +88 -0
- package/cordis.patch.yml +6 -0
- package/lib/argv.js +45 -0
- package/lib/argv.js.map +1 -0
- package/lib/client.js +905 -0
- package/lib/config.js +123 -0
- package/lib/config.js.map +1 -0
- package/lib/context.js +30 -0
- package/lib/context.js.map +1 -0
- package/lib/grant.js +21 -0
- package/lib/grant.js.map +1 -0
- package/lib/index.js +173 -0
- package/lib/index.js.map +1 -0
- package/lib/listener.js +57 -0
- package/lib/listener.js.map +1 -0
- package/lib/paths.js +70 -0
- package/lib/paths.js.map +1 -0
- package/lib/pattern.js +206 -0
- package/lib/pattern.js.map +1 -0
- package/lib/policy.js +17 -0
- package/lib/policy.js.map +1 -0
- package/lib/preview.js +126 -0
- package/lib/preview.js.map +1 -0
- package/lib/resolve.js +153 -0
- package/lib/resolve.js.map +1 -0
- package/lib/schema.js +54 -0
- package/lib/schema.js.map +1 -0
- package/lib/types/argv.d.ts +17 -0
- package/lib/types/config.d.ts +55 -0
- package/lib/types/context.d.ts +13 -0
- package/lib/types/grant.d.ts +17 -0
- package/lib/types/index.d.ts +86 -0
- package/lib/types/listener.d.ts +40 -0
- package/lib/types/paths.d.ts +32 -0
- package/lib/types/pattern.d.ts +88 -0
- package/lib/types/policy.d.ts +21 -0
- package/lib/types/preview.d.ts +77 -0
- package/lib/types/resolve.d.ts +63 -0
- package/lib/types/schema.d.ts +42 -0
- package/lib/types/wrap-fs.d.ts +50 -0
- package/lib/types/wrap-sandbox.d.ts +60 -0
- package/lib/wrap-fs.js +75 -0
- package/lib/wrap-fs.js.map +1 -0
- package/lib/wrap-sandbox.js +89 -0
- package/lib/wrap-sandbox.js.map +1 -0
- package/package.json +114 -4
package/lib/pattern.js
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Root patterns: a configured spelling may describe a SET of directories instead
|
|
3
|
+
* of one literal path, so a grant can be anchored to a structure (a directory
|
|
4
|
+
* that CONTAINS `.worktrees`) rather than to a hand-written path.
|
|
5
|
+
*
|
|
6
|
+
* Grammar — every other segment is a literal directory name:
|
|
7
|
+
* - `*` exactly one existing directory name;
|
|
8
|
+
* - `**` zero or more existing directory names (any depth);
|
|
9
|
+
* - one or more TRAILING `..` segments are applied to each MATCH, after
|
|
10
|
+
* matching, so `…/**/.worktrees/..` means "the directory that contains a
|
|
11
|
+
* `.worktrees` child" and is not eaten by lexical collapsing.
|
|
12
|
+
*
|
|
13
|
+
* Matching only ever yields directories that EXIST, which is what makes "the path
|
|
14
|
+
* contains `.worktrees`" a structural condition rather than a spelling.
|
|
15
|
+
*
|
|
16
|
+
* Safety envelope, enforced here and validated again at save time:
|
|
17
|
+
* - the literal prefix before the first wildcard is the anchor; it must be
|
|
18
|
+
* absolute after `~` expansion, must not be a filesystem root, and must not
|
|
19
|
+
* CONTAIN the home directory — a pattern can never walk `/`, `/Users` or `~`;
|
|
20
|
+
* - the walk never descends into `node_modules` or `.git`;
|
|
21
|
+
* - every cap (depth, directories scanned, matches) makes the WHOLE pattern yield
|
|
22
|
+
* nothing (fail closed) instead of a partial set: a half-expanded grant would
|
|
23
|
+
* be an unpredictable permission.
|
|
24
|
+
* @module dsh-extra-paths/pattern
|
|
25
|
+
*/
|
|
26
|
+
import { readdirSync, statSync } from 'node:fs';
|
|
27
|
+
import { homedir } from 'node:os';
|
|
28
|
+
import { dirname, isAbsolute, join } from 'node:path';
|
|
29
|
+
import { isFilesystemRoot } from './config.js';
|
|
30
|
+
import { canonicalizeRoot, expandPath, isUnder } from './paths.js';
|
|
31
|
+
/** Caps that keep one pattern's expansion bounded. */
|
|
32
|
+
export const PATTERN_LIMITS = {
|
|
33
|
+
/** Directory entries examined in one expansion. */
|
|
34
|
+
maxDirs: 4096,
|
|
35
|
+
/** Matches one pattern may yield. */
|
|
36
|
+
maxMatches: 256,
|
|
37
|
+
/**
|
|
38
|
+
* `**` levels walked below the anchor. Deliberately small: a repository that
|
|
39
|
+
* keeps its worktrees in `.worktrees` sits one or two levels down, and every
|
|
40
|
+
* extra level multiplies the walk into unrelated source trees. A deeper
|
|
41
|
+
* structure is spelled explicitly, level by level, instead of with `**`.
|
|
42
|
+
*/
|
|
43
|
+
maxDepth: 3,
|
|
44
|
+
};
|
|
45
|
+
/** Names the walk never descends into. */
|
|
46
|
+
const PRUNED = new Set(['node_modules', '.git']);
|
|
47
|
+
/** Whether a spelling is a pattern rather than a literal path. */
|
|
48
|
+
export function isPattern(raw) {
|
|
49
|
+
return raw.includes('*');
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Parse a pattern spelling.
|
|
53
|
+
* @param raw - the configured spelling.
|
|
54
|
+
* @param workspaceRoot - the base a relative anchor resolves against.
|
|
55
|
+
* @param home - the home directory to expand `~` with.
|
|
56
|
+
* @returns the parsed pattern, or undefined when it cannot be walked safely.
|
|
57
|
+
*/
|
|
58
|
+
export function parsePattern(raw, workspaceRoot, home = homedir()) {
|
|
59
|
+
const segments = raw.split('/').filter(segment => segment !== '');
|
|
60
|
+
const firstWildcard = segments.findIndex(segment => segment.includes('*'));
|
|
61
|
+
if (firstWildcard < 0)
|
|
62
|
+
return undefined;
|
|
63
|
+
// Trailing `..` run: applied AFTER matching, so it must not be part of the walk.
|
|
64
|
+
let end = segments.length;
|
|
65
|
+
let up = 0;
|
|
66
|
+
while (end > firstWildcard && segments[end - 1] === '..') {
|
|
67
|
+
up += 1;
|
|
68
|
+
end -= 1;
|
|
69
|
+
}
|
|
70
|
+
const walk = segments.slice(firstWildcard, end);
|
|
71
|
+
if (walk.length === 0)
|
|
72
|
+
return undefined;
|
|
73
|
+
// The anchor spelling keeps its leading `/` or `~`. Rebuilding it from the
|
|
74
|
+
// filtered segments would turn `/a/b/**` into the RELATIVE `a/b` and resolve
|
|
75
|
+
// the walk against the session workspace instead of `/a/b` — the defect this
|
|
76
|
+
// guard was extracted from.
|
|
77
|
+
const anchorSpelling = raw.slice(0, raw.indexOf('*')).replace(/\/+$/, '');
|
|
78
|
+
if (!anchorSpelling.startsWith('/') && !anchorSpelling.startsWith('~'))
|
|
79
|
+
return undefined;
|
|
80
|
+
// `/**`, `~/**` and `/srv/**` would walk the filesystem, a whole home
|
|
81
|
+
// directory, or a top-level directory: a pattern needs two literal segments.
|
|
82
|
+
if (firstWildcard < 2)
|
|
83
|
+
return undefined;
|
|
84
|
+
const anchor = canonicalizeRoot(expandPath(anchorSpelling, workspaceRoot, home));
|
|
85
|
+
if (!isAbsolute(anchor) || isFilesystemRoot(anchor))
|
|
86
|
+
return undefined;
|
|
87
|
+
const homeRoot = canonicalizeRoot(home);
|
|
88
|
+
// An anchor that IS or CONTAINS the home directory would walk far too much.
|
|
89
|
+
if (anchor === homeRoot || isUnder(homeRoot, anchor))
|
|
90
|
+
return undefined;
|
|
91
|
+
return { source: raw, anchor, segments: walk, up };
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* What one directory contributes: its child directories, or nothing when
|
|
95
|
+
* unreadable.
|
|
96
|
+
* @param directory - the directory to list.
|
|
97
|
+
* @param visibleOnly - skip HIDDEN child directories. `**` uses this: a search
|
|
98
|
+
* for a repository's `.worktrees` has no business inside `.cache`, `.gradle` or
|
|
99
|
+
* a checked-out tool tree, and skipping them is what keeps the walk bounded.
|
|
100
|
+
* The pattern's own literal segments are matched at their level regardless, so
|
|
101
|
+
* `.worktrees` itself is still found.
|
|
102
|
+
*/
|
|
103
|
+
function childDirectories(directory, visibleOnly = false) {
|
|
104
|
+
let names;
|
|
105
|
+
try {
|
|
106
|
+
names = readdirSync(directory);
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
const children = [];
|
|
112
|
+
for (const name of names) {
|
|
113
|
+
if (PRUNED.has(name))
|
|
114
|
+
continue;
|
|
115
|
+
if (visibleOnly && name.startsWith('.'))
|
|
116
|
+
continue;
|
|
117
|
+
const child = join(directory, name);
|
|
118
|
+
try {
|
|
119
|
+
if (statSync(child).isDirectory())
|
|
120
|
+
children.push(child);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
// A vanishing entry is not an error: the next pass simply will not see it.
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return children.sort();
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Expand a pattern against the filesystem.
|
|
130
|
+
* @param pattern - the parsed pattern.
|
|
131
|
+
* @param limits - caps to apply (defaults to {@link PATTERN_LIMITS}).
|
|
132
|
+
* @returns the matches, or `{ capped: true }` when a cap was hit.
|
|
133
|
+
*/
|
|
134
|
+
export function expandPattern(pattern, limits = PATTERN_LIMITS) {
|
|
135
|
+
const matches = new Set();
|
|
136
|
+
let scanned = 0;
|
|
137
|
+
let capped = false;
|
|
138
|
+
let cap;
|
|
139
|
+
let truncated = false;
|
|
140
|
+
const stop = (which) => {
|
|
141
|
+
capped = true;
|
|
142
|
+
cap ??= which;
|
|
143
|
+
};
|
|
144
|
+
const walk = (directory, index, depth) => {
|
|
145
|
+
if (capped)
|
|
146
|
+
return;
|
|
147
|
+
if (scanned >= limits.maxDirs) {
|
|
148
|
+
stop('directories');
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
scanned += 1;
|
|
152
|
+
if (index === pattern.segments.length) {
|
|
153
|
+
if (matches.size >= limits.maxMatches) {
|
|
154
|
+
stop('matches');
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
matches.add(directory);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const segment = pattern.segments[index] ?? '';
|
|
161
|
+
if (segment === '**') {
|
|
162
|
+
// Zero segments consumed — always allowed, so `**` matches the anchor's own
|
|
163
|
+
// level even at the depth bound (checking the bound first would lose a
|
|
164
|
+
// level to an off-by-one).
|
|
165
|
+
walk(directory, index + 1, depth);
|
|
166
|
+
if (capped)
|
|
167
|
+
return;
|
|
168
|
+
if (depth >= limits.maxDepth) {
|
|
169
|
+
// A documented bound, not a failure: keep whatever the walk already
|
|
170
|
+
// found and let the caller mention that deeper levels were not searched.
|
|
171
|
+
truncated = true;
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
// …or one more level, keeping `**` active. Hidden directories are skipped
|
|
175
|
+
// here only: this is the branch that would otherwise wander into every
|
|
176
|
+
// source tree below the anchor.
|
|
177
|
+
for (const child of childDirectories(directory, true)) {
|
|
178
|
+
walk(child, index, depth + 1);
|
|
179
|
+
if (capped)
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
for (const child of childDirectories(directory)) {
|
|
185
|
+
const name = child.slice(child.lastIndexOf('/') + 1);
|
|
186
|
+
if (segment === '*' || segment === name)
|
|
187
|
+
walk(child, index + 1, depth);
|
|
188
|
+
if (capped)
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
walk(pattern.anchor, 0, 0);
|
|
193
|
+
if (capped)
|
|
194
|
+
return { matches: [], capped: true, ...(cap === undefined ? {} : { cap }), scanned };
|
|
195
|
+
const up = pattern.up;
|
|
196
|
+
const resolved = [...matches]
|
|
197
|
+
.map(match => {
|
|
198
|
+
let result = match;
|
|
199
|
+
for (let step = 0; step < up; step += 1)
|
|
200
|
+
result = dirname(result);
|
|
201
|
+
return canonicalizeRoot(result);
|
|
202
|
+
})
|
|
203
|
+
.filter(candidate => !isFilesystemRoot(candidate));
|
|
204
|
+
return { matches: [...new Set(resolved)].sort(), capped: false, ...(truncated ? { truncated: true } : {}), scanned };
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=pattern.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pattern.js","sourceRoot":"","sources":["../src/pattern.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;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1
|
+
/**
|
|
2
|
+
* Per-call policy shapes and the translation the fs wrapper performs.
|
|
3
|
+
* @module dsh-extra-paths/policy
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The policy one call is re-stamped with so the base fence accepts a target
|
|
7
|
+
* under a configured root. The mode rises to `workspace-write` because that is
|
|
8
|
+
* this grant's meaning: a single call is allowed to write this root, while the
|
|
9
|
+
* base class keeps owning resolution, atomic publication and the version guard.
|
|
10
|
+
* @param policy - the caller's resolved policy.
|
|
11
|
+
* @param workspaceRoot - the canonical configured root that matched the target.
|
|
12
|
+
* @returns the policy to hand the base implementation.
|
|
13
|
+
*/
|
|
14
|
+
export function syntheticPolicy(policy, workspaceRoot) {
|
|
15
|
+
return { ...policy, mode: 'workspace-write', workspaceRoot };
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,MAAkB,EAAE,aAAqB;IACvE,OAAO,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAE,aAAa,EAAE,CAAA;AAC9D,CAAC"}
|
package/lib/preview.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The settings page's effective-roots preview: one authenticated read-only
|
|
3
|
+
* route that resolves the entries the page asks about for a workspace the page
|
|
4
|
+
* supplies. It never probes arbitrary paths — every entry still goes through
|
|
5
|
+
* `normalizeConfig` + `resolveRoots`, the same pair the enforcement layers use —
|
|
6
|
+
* and it computes only path spellings, never file contents.
|
|
7
|
+
* @module dsh-extra-paths/preview
|
|
8
|
+
*/
|
|
9
|
+
import { homedir } from 'node:os';
|
|
10
|
+
import { isAbsolute } from 'node:path';
|
|
11
|
+
import { normalizeConfig } from './config.js';
|
|
12
|
+
import { canonicalizeRoot, expandPath } from './paths.js';
|
|
13
|
+
import { resolveRoots } from './resolve.js';
|
|
14
|
+
/** The single route this plugin owns. */
|
|
15
|
+
export const PREVIEW_PATH = '/extra-paths/resolved';
|
|
16
|
+
/** The most entries one preview request may carry (a settings page sends its rows). */
|
|
17
|
+
export const MAX_PREVIEW_ENTRIES = 64;
|
|
18
|
+
/**
|
|
19
|
+
* Parse the optional `paths` query parameter: the page's UNSAVED rows, so the
|
|
20
|
+
* preview can answer for what the user is typing instead of only for what is
|
|
21
|
+
* already stored.
|
|
22
|
+
* @param raw - the raw query value (a JSON array of strings / entry objects).
|
|
23
|
+
* @returns a raw configuration carrying those entries, or undefined when absent.
|
|
24
|
+
* @throws {Error} when the payload is not a usable array (the caller answers 400).
|
|
25
|
+
*/
|
|
26
|
+
export function parseStagedPaths(raw) {
|
|
27
|
+
if (raw === null || raw === undefined || raw === '')
|
|
28
|
+
return undefined;
|
|
29
|
+
if (raw.length > 8192)
|
|
30
|
+
throw new Error('paths is too long');
|
|
31
|
+
let parsed;
|
|
32
|
+
try {
|
|
33
|
+
parsed = JSON.parse(raw);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
throw new Error('paths must be JSON');
|
|
37
|
+
}
|
|
38
|
+
if (!Array.isArray(parsed))
|
|
39
|
+
throw new Error('paths must be a JSON array');
|
|
40
|
+
if (parsed.length > MAX_PREVIEW_ENTRIES)
|
|
41
|
+
throw new Error(`paths must hold at most ${MAX_PREVIEW_ENTRIES} entries`);
|
|
42
|
+
return { paths: parsed };
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Normalise the workspace base the page sent.
|
|
46
|
+
*
|
|
47
|
+
* `~` is expanded here — the page cannot know the home directory before its
|
|
48
|
+
* first answer — and a RELATIVE spelling is refused outright. That refusal is
|
|
49
|
+
* the fix for a real defect: `resolvePath('~/projects', '..')` used to be evaluated
|
|
50
|
+
* server-side, so a `~` base produced `…/<server cwd>/~/` in the preview while
|
|
51
|
+
* looking like an ordinary path.
|
|
52
|
+
* @param workspaceRoot - the raw query value.
|
|
53
|
+
* @returns the canonical absolute base.
|
|
54
|
+
* @throws {Error} when the base is missing, relative, or a `~user` spelling.
|
|
55
|
+
*/
|
|
56
|
+
function workspaceBaseOf(workspaceRoot) {
|
|
57
|
+
if (workspaceRoot === undefined || workspaceRoot.trim() === '')
|
|
58
|
+
throw new Error('cwd is required');
|
|
59
|
+
const trimmed = workspaceRoot.trim();
|
|
60
|
+
if (trimmed === '~' || trimmed.startsWith('~/'))
|
|
61
|
+
return canonicalizeRoot(expandPath(trimmed, homedir()));
|
|
62
|
+
if (!isAbsolute(trimmed)) {
|
|
63
|
+
throw new Error(`cwd must be an absolute path or start with ~, received ${JSON.stringify(workspaceRoot)}`);
|
|
64
|
+
}
|
|
65
|
+
return canonicalizeRoot(trimmed);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Resolve a configuration for one workspace.
|
|
69
|
+
* @param config - the stored configuration snapshot.
|
|
70
|
+
* @param workspaceRoot - the workspace the page is asking about.
|
|
71
|
+
* @param staged - the page's unsaved rows, when it sent any: they REPLACE the
|
|
72
|
+
* stored entries so the preview answers for the draft, not for the document.
|
|
73
|
+
* @returns the preview payload.
|
|
74
|
+
* @throws {Error} when no usable workspace was supplied or the staged rows are
|
|
75
|
+
* invalid (the caller answers 400).
|
|
76
|
+
*/
|
|
77
|
+
export function buildPreview(config, workspaceRoot, staged) {
|
|
78
|
+
const base = workspaceBaseOf(workspaceRoot);
|
|
79
|
+
// `normalizeConfig` is the same gate the settings service and the enforcement
|
|
80
|
+
// layers use, so an invalid draft fails here with the user's own message.
|
|
81
|
+
const effectiveConfig = staged === undefined ? config : normalizeConfig(staged);
|
|
82
|
+
const report = resolveRoots(effectiveConfig, base);
|
|
83
|
+
return {
|
|
84
|
+
workspaceCwd: base,
|
|
85
|
+
home: homedir(),
|
|
86
|
+
entries: report.entries,
|
|
87
|
+
effective: report.roots.map(root => root.root),
|
|
88
|
+
warnings: report.warnings,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Register the preview route on the calling fiber.
|
|
93
|
+
* Optional capability: if the composition has no web carrier or no Connection
|
|
94
|
+
* service, the caller never invokes this, and enforcement is unaffected.
|
|
95
|
+
* @param ctx - a context that has both `webServer` and `connection`.
|
|
96
|
+
* @param deps - configuration source and warning sink.
|
|
97
|
+
*/
|
|
98
|
+
export function registerPreviewRoute(ctx, deps) {
|
|
99
|
+
const handler = async (req, res) => {
|
|
100
|
+
const rejection = ctx.connection.requestRejection(req);
|
|
101
|
+
if (rejection !== undefined) {
|
|
102
|
+
res.writeHead(rejection);
|
|
103
|
+
res.end(rejection === 401 ? 'unauthorized' : 'forbidden');
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if ((req.method ?? 'GET') !== 'GET') {
|
|
107
|
+
res.writeHead(405, { 'content-type': 'text/plain; charset=utf-8' });
|
|
108
|
+
res.end('method not allowed');
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
const url = new URL(req.url ?? '/', 'http://localhost');
|
|
113
|
+
const staged = parseStagedPaths(url.searchParams.get('paths'));
|
|
114
|
+
const body = JSON.stringify(buildPreview(deps.readConfig(), url.searchParams.get('cwd') ?? undefined, staged));
|
|
115
|
+
res.writeHead(200, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' });
|
|
116
|
+
res.end(body);
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
deps.warn(`extra-paths: preview route failed: ${String(error)}`);
|
|
120
|
+
res.writeHead(400, { 'content-type': 'text/plain; charset=utf-8' });
|
|
121
|
+
res.end(String(error.message ?? error));
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
ctx.effect(() => ctx.webServer.register({ kind: 'exact', path: PREVIEW_PATH, handler }), 'extra-paths: preview route');
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=preview.js.map
|
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OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,IAAI,CAAC,sCAAsC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;YAChE,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,2BAA2B,EAAE,CAAC,CAAA;YACnE,GAAG,CAAC,GAAG,CAAC,MAAM,CAAE,KAAe,CAAC,OAAO,IAAI,KAAK,CAAC,CAAC,CAAA;QACpD,CAAC;IACH,CAAC,CAAA;IACD,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC,EAAE,4BAA4B,CAAC,CAAA;AACxH,CAAC"}
|
package/lib/resolve.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one place a configuration becomes a set of effective writable roots.
|
|
3
|
+
* Enforcement (both wrappers) and the settings preview call this, so what the
|
|
4
|
+
* page shows and what the sandbox grants cannot drift.
|
|
5
|
+
* @module dsh-extra-paths/resolve
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync } from 'node:fs';
|
|
8
|
+
import { homedir } from 'node:os';
|
|
9
|
+
import { SURFACES, isFilesystemRoot } from './config.js';
|
|
10
|
+
import { expandPattern, isPattern, parsePattern, PATTERN_LIMITS } from './pattern.js';
|
|
11
|
+
import { canonicalizeRoot, expandPath, isUnder } from './paths.js';
|
|
12
|
+
/**
|
|
13
|
+
* How long one pattern's expansion is reused (milliseconds). Long enough that a
|
|
14
|
+
* broad `**` walk costs one hiccup rather than one per five seconds; short enough
|
|
15
|
+
* that a worktree created a moment ago shows up without any manual refresh.
|
|
16
|
+
*/
|
|
17
|
+
export const PATTERN_CACHE_MS = 30000;
|
|
18
|
+
/** Expansions seen recently, keyed by the configured spelling. */
|
|
19
|
+
const patternCache = new Map();
|
|
20
|
+
/** Drop every cached expansion (a fresh directory should not wait out the TTL). */
|
|
21
|
+
export function clearPatternCache() {
|
|
22
|
+
patternCache.clear();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Expand one pattern, reusing a recent expansion.
|
|
26
|
+
* @param raw - the configured spelling.
|
|
27
|
+
* @param workspaceRoot - the session workspace a relative anchor resolves against.
|
|
28
|
+
* @param now - current time in milliseconds (injected for tests).
|
|
29
|
+
* @returns the matches and whether a cap was hit.
|
|
30
|
+
*/
|
|
31
|
+
function expansionOf(raw, workspaceRoot, now) {
|
|
32
|
+
const cached = patternCache.get(raw);
|
|
33
|
+
if (cached !== undefined && now - cached.at < PATTERN_CACHE_MS) {
|
|
34
|
+
return {
|
|
35
|
+
matches: cached.matches,
|
|
36
|
+
capped: cached.capped,
|
|
37
|
+
...(cached.cap === undefined ? {} : { cap: cached.cap }),
|
|
38
|
+
...(cached.truncated === undefined ? {} : { truncated: cached.truncated }),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const parsed = parsePattern(raw, workspaceRoot);
|
|
42
|
+
const expansion = parsed === undefined
|
|
43
|
+
? { matches: [], capped: true, cap: 'anchor' }
|
|
44
|
+
: expandPattern(parsed);
|
|
45
|
+
patternCache.set(raw, {
|
|
46
|
+
at: now,
|
|
47
|
+
matches: expansion.matches,
|
|
48
|
+
capped: expansion.capped,
|
|
49
|
+
...(expansion.cap === undefined ? {} : { cap: expansion.cap }),
|
|
50
|
+
...('truncated' in expansion && expansion.truncated === true ? { truncated: true } : {}),
|
|
51
|
+
});
|
|
52
|
+
return {
|
|
53
|
+
matches: expansion.matches,
|
|
54
|
+
capped: expansion.capped,
|
|
55
|
+
...(expansion.cap === undefined ? {} : { cap: expansion.cap }),
|
|
56
|
+
...('truncated' in expansion && expansion.truncated === true ? { truncated: true } : {}),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Whether a root contains (or is) the home directory. Exact equality alone is
|
|
61
|
+
* not enough: `~/..` canonicalises to the directory holding every user's home,
|
|
62
|
+
* which is strictly broader than `~` yet would otherwise pass unwarned.
|
|
63
|
+
* @param root - canonical root under test.
|
|
64
|
+
* @param homeRoot - canonical home directory, resolved once per pass.
|
|
65
|
+
* @returns true when home lies at or beneath the root.
|
|
66
|
+
*/
|
|
67
|
+
function containsHome(root, homeRoot) {
|
|
68
|
+
return isUnder(homeRoot, root);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Resolve every configured entry against one session workspace.
|
|
72
|
+
* @param config - the normalised configuration.
|
|
73
|
+
* @param workspaceRoot - the session workspace a relative entry resolves against.
|
|
74
|
+
* @returns effective roots plus per-entry detail and warnings.
|
|
75
|
+
*/
|
|
76
|
+
export function resolveRoots(config, workspaceRoot) {
|
|
77
|
+
const entries = [];
|
|
78
|
+
const warnings = [];
|
|
79
|
+
const byRoot = new Map();
|
|
80
|
+
// Probed at most once per pass — and not at all when no entry is active,
|
|
81
|
+
// because this runs on every enforcement decision.
|
|
82
|
+
let homeRoot;
|
|
83
|
+
const now = Date.now();
|
|
84
|
+
const acceptEntry = (raw, scope, surfaces, root) => {
|
|
85
|
+
// A COPY of the caller's array: handing the config's own instance to a
|
|
86
|
+
// report lets a caller mutate future grants through it.
|
|
87
|
+
const shared = { raw, resolved: root, scope, surfaces: [...surfaces] };
|
|
88
|
+
if (isFilesystemRoot(root)) {
|
|
89
|
+
entries.push({ ...shared, status: 'rejected' });
|
|
90
|
+
warnings.push(`extra-paths: ${JSON.stringify(raw)} resolves to the filesystem root; the entry is ignored`);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (!existsSync(root)) {
|
|
94
|
+
entries.push({ ...shared, status: 'missing' });
|
|
95
|
+
warnings.push(`extra-paths: ${JSON.stringify(raw)} resolves to ${root}, which does not exist; the entry is inactive until it does`);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
entries.push({ ...shared, status: 'ok' });
|
|
99
|
+
homeRoot ??= canonicalizeRoot(homedir());
|
|
100
|
+
if (containsHome(root, homeRoot)) {
|
|
101
|
+
warnings.push(`extra-paths: ${JSON.stringify(raw)} resolves to ${root}, which contains your entire home directory; `
|
|
102
|
+
+ 'prefer a narrower root');
|
|
103
|
+
}
|
|
104
|
+
if (root !== workspaceRoot && isUnder(workspaceRoot, root)) {
|
|
105
|
+
warnings.push(`extra-paths: ${JSON.stringify(raw)} resolves to ${root}, which contains this session's workspace; `
|
|
106
|
+
+ 'prefer a sibling-scoped root');
|
|
107
|
+
}
|
|
108
|
+
const existing = byRoot.get(root);
|
|
109
|
+
if (existing === undefined) {
|
|
110
|
+
// SURFACES order here too, not only on merge: a lone entry spelled
|
|
111
|
+
// ['shell', 'fs'] must yield the same root identity as ['fs', 'shell'].
|
|
112
|
+
const ordered = SURFACES.filter(surface => surfaces.includes(surface));
|
|
113
|
+
byRoot.set(root, { raw, root, scope, surfaces: ordered });
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const merged = existing.scope === 'always-write' || scope === 'always-write' ? 'always-write' : 'write';
|
|
117
|
+
// SURFACES order, not insertion order: a config edit that only reorders
|
|
118
|
+
// surfaces must not change a report's identity.
|
|
119
|
+
const present = new Set([...existing.surfaces, ...surfaces]);
|
|
120
|
+
byRoot.set(root, { raw: existing.raw, root, scope: merged, surfaces: SURFACES.filter(surface => present.has(surface)) });
|
|
121
|
+
};
|
|
122
|
+
for (const entry of config.paths) {
|
|
123
|
+
if (!isPattern(entry.path)) {
|
|
124
|
+
acceptEntry(entry.path, entry.scope, entry.surfaces, canonicalizeRoot(expandPath(entry.path, workspaceRoot)));
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const expansion = expansionOf(entry.path, workspaceRoot, now);
|
|
128
|
+
if (expansion.capped) {
|
|
129
|
+
entries.push({ raw: entry.path, resolved: '', scope: entry.scope, surfaces: [...entry.surfaces], status: 'rejected' });
|
|
130
|
+
const reason = expansion.cap === 'anchor'
|
|
131
|
+
? 'its anchor is not walkable (needs a literal absolute or ~/ path at least two segments deep)'
|
|
132
|
+
: expansion.cap === 'matches'
|
|
133
|
+
? `it matches more than ${PATTERN_LIMITS.maxMatches} directories`
|
|
134
|
+
: `it examined more than ${PATTERN_LIMITS.maxDirs} directories`;
|
|
135
|
+
warnings.push(`extra-paths: pattern ${JSON.stringify(entry.path)} was not expanded because ${reason}; `
|
|
136
|
+
+ 'nothing is granted for it — narrow the pattern, name a deeper anchor, or spell the levels explicitly');
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (expansion.truncated === true) {
|
|
140
|
+
warnings.push(`extra-paths: pattern ${JSON.stringify(entry.path)} searched only ${PATTERN_LIMITS.maxDepth} levels below its anchor; `
|
|
141
|
+
+ 'spell the deeper levels explicitly if a matching directory lives further down');
|
|
142
|
+
}
|
|
143
|
+
if (expansion.matches.length === 0) {
|
|
144
|
+
entries.push({ raw: entry.path, resolved: '', scope: entry.scope, surfaces: [...entry.surfaces], status: 'missing' });
|
|
145
|
+
warnings.push(`extra-paths: pattern ${JSON.stringify(entry.path)} matches no existing directory; the entry is inactive until one appears`);
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
for (const match of expansion.matches)
|
|
149
|
+
acceptEntry(entry.path, entry.scope, entry.surfaces, match);
|
|
150
|
+
}
|
|
151
|
+
return { roots: [...byRoot.values()], entries, warnings: [...new Set(warnings)] };
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEjC,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,YAA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AAI,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAA;YACrH,QAAQ,CAAC,IAAI,CACX,wBAAwB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,yEAAyE,CAC5H,CAAA;YACD,SAAQ;QACV,CAAC;QACD,KAAK,MAAM,KAAK,IAAI,SAAS,CAAC,OAAO;YAAE,WAAW,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;IACpG,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAA;AACnF,CAAC"}
|
package/lib/schema.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The settings namespace schema. The resolved section is what the enforcement
|
|
3
|
+
* layers read; `base` (the entry config) supplies deployment defaults beneath
|
|
4
|
+
* the user layer.
|
|
5
|
+
* @module dsh-extra-paths/schema
|
|
6
|
+
*/
|
|
7
|
+
import z from '@deepseek-ai/schemastery';
|
|
8
|
+
// Every schema is annotated: a bare `z.object({...})` inside a heterogeneous
|
|
9
|
+
// union both fails to infer and (per TS2742) leaks a non-portable type name.
|
|
10
|
+
const scopeSchema = z.union(['write', 'always-write']);
|
|
11
|
+
const surfaceSchema = z.union(['fs', 'shell']);
|
|
12
|
+
const entrySchema = z.object({
|
|
13
|
+
path: z.string().required(),
|
|
14
|
+
scope: scopeSchema,
|
|
15
|
+
surfaces: z.array(surfaceSchema),
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* Mark a field volatile when the RUNNING schemastery supports it.
|
|
19
|
+
*
|
|
20
|
+
* `volatile()` arrived in schemastery 3.18.4 (0.2.x ships ~3.18.4, 0.1.5 ships
|
|
21
|
+
* 3.18.2), and calling it on an older instance would throw while this module is
|
|
22
|
+
* being evaluated — a hard boot failure. Feature-detecting keeps the export safe
|
|
23
|
+
* everywhere; on a host without it the field is simply not volatile, which costs
|
|
24
|
+
* the generated settings form and nothing else.
|
|
25
|
+
* @param schema - the field schema.
|
|
26
|
+
* @returns the same schema, volatile when the runtime offers it.
|
|
27
|
+
*/
|
|
28
|
+
function asVolatile(schema) {
|
|
29
|
+
const candidate = schema;
|
|
30
|
+
return typeof candidate.volatile === 'function' ? candidate.volatile.call(schema) : schema;
|
|
31
|
+
}
|
|
32
|
+
/** The `extra-paths` namespace value. */
|
|
33
|
+
export const extraPathsSchema = z.object({
|
|
34
|
+
defaultScope: scopeSchema.default('write'),
|
|
35
|
+
defaultSurfaces: z.array(surfaceSchema).default(['fs', 'shell']),
|
|
36
|
+
paths: z.array(z.union([z.string(), entrySchema])).default([]),
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* The same section for 0.2.x, where a plugin's settings ARE its exported
|
|
40
|
+
* `Config` and the framework's settings form only describes `volatile()` fields:
|
|
41
|
+
* a schema without one yields no descriptor at all, so all three fields are
|
|
42
|
+
* volatile here. `volatile()` wraps a field in a value holder (`get()`), and the
|
|
43
|
+
* host half re-reads those per enforcement decision — that is what makes an edit
|
|
44
|
+
* in the settings form apply without a restart.
|
|
45
|
+
*
|
|
46
|
+
* Kept separate from {@link extraPathsSchema} because the 0.1.5 settings service
|
|
47
|
+
* consumes plain values, not volatile wrappers.
|
|
48
|
+
*/
|
|
49
|
+
export const extraPathsConfigSchema = z.object({
|
|
50
|
+
defaultScope: asVolatile(scopeSchema.default('write')),
|
|
51
|
+
defaultSurfaces: asVolatile(z.array(surfaceSchema).default(['fs', 'shell'])),
|
|
52
|
+
paths: asVolatile(z.array(z.union([z.string(), entrySchema])).default([])),
|
|
53
|
+
});
|
|
54
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAiBxC,6EAA6E;AAC7E,6EAA6E;AAC7E,MAAM,WAAW,GAAa,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,cAAc,CAAU,CAAC,CAAA;AACzE,MAAM,aAAa,GAAe,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,OAAO,CAAU,CAAC,CAAA;AACnE,MAAM,WAAW,GAA8B,CAAC,CAAC,MAAM,CAAC;IACtD,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,KAAK,EAAE,WAAW;IAClB,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC;CACjC,CAAC,CAAA;AAEF;;;;;;;;;;GAUG;AACH,SAAS,UAAU,CAAI,MAAS;IAC9B,MAAM,SAAS,GAAG,MAAsC,CAAA;IACxD,OAAO,OAAO,SAAS,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAE,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAO,CAAC,CAAC,CAAC,MAAM,CAAA;AACnG,CAAC;AAED,yCAAyC;AACzC,MAAM,CAAC,MAAM,gBAAgB,GAAyB,CAAC,CAAC,MAAM,CAAC;IAC7D,YAAY,EAAE,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC;IAC1C,eAAe,EAAE,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAChE,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;CAC/D,CAAC,CAAA;AAEF;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,YAAY,EAAE,UAAU,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACtD,eAAe,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IAC5E,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;CAC3E,CAAC,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runner-dialect widening: append one write grant per configured root to an
|
|
3
|
+
* argv the base provider already wrapped. Detection is structural (flags, not
|
|
4
|
+
* program names) and every unrecognised shape fails closed by returning
|
|
5
|
+
* `undefined` — the caller then leaves the argv untouched, so the write is
|
|
6
|
+
* denied rather than silently mis-granted.
|
|
7
|
+
* @module dsh-extra-paths/argv
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Insert write grants for `roots` into a confined argv.
|
|
11
|
+
* @param confined - the argv the base provider produced (runner, profile, `--`, command).
|
|
12
|
+
* @param wrappedLength - length of the caller's original argv, which locates the separator.
|
|
13
|
+
* @param roots - canonical roots to grant.
|
|
14
|
+
* @returns the widened argv, the unchanged argv when there is nothing to grant,
|
|
15
|
+
* or `undefined` when the dialect is unrecognised (the caller must not grant).
|
|
16
|
+
*/
|
|
17
|
+
export declare function widenArgv(confined: readonly string[], wrappedLength: number, roots: readonly string[]): readonly string[] | undefined;
|