dsh-extra-paths 0.2.0 → 0.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.
Files changed (52) hide show
  1. package/README.md +192 -28
  2. package/README.zh.md +166 -21
  3. package/lib/argv.js +96 -24
  4. package/lib/argv.js.map +1 -1
  5. package/lib/client.js +1310 -450
  6. package/lib/config.js +140 -44
  7. package/lib/config.js.map +1 -1
  8. package/lib/context.js +48 -12
  9. package/lib/context.js.map +1 -1
  10. package/lib/denial.js +132 -0
  11. package/lib/denial.js.map +1 -0
  12. package/lib/index.js +40 -5
  13. package/lib/index.js.map +1 -1
  14. package/lib/name-rule.js +217 -0
  15. package/lib/name-rule.js.map +1 -0
  16. package/lib/paths.js +155 -27
  17. package/lib/paths.js.map +1 -1
  18. package/lib/pattern.js +128 -62
  19. package/lib/pattern.js.map +1 -1
  20. package/lib/platform.js +325 -0
  21. package/lib/platform.js.map +1 -0
  22. package/lib/preview.js +47 -20
  23. package/lib/preview.js.map +1 -1
  24. package/lib/resolve.js +345 -64
  25. package/lib/resolve.js.map +1 -1
  26. package/lib/schema.js +19 -6
  27. package/lib/schema.js.map +1 -1
  28. package/lib/shell-dialect.js +92 -0
  29. package/lib/shell-dialect.js.map +1 -0
  30. package/lib/tool-guard.js +214 -0
  31. package/lib/tool-guard.js.map +1 -0
  32. package/lib/types/argv.d.ts +50 -12
  33. package/lib/types/config.d.ts +29 -13
  34. package/lib/types/context.d.ts +6 -1
  35. package/lib/types/denial.d.ts +88 -0
  36. package/lib/types/index.d.ts +8 -4
  37. package/lib/types/name-rule.d.ts +112 -0
  38. package/lib/types/paths.d.ts +55 -10
  39. package/lib/types/pattern.d.ts +43 -5
  40. package/lib/types/platform.d.ts +148 -0
  41. package/lib/types/preview.d.ts +39 -3
  42. package/lib/types/resolve.d.ts +129 -23
  43. package/lib/types/schema.d.ts +24 -8
  44. package/lib/types/shell-dialect.d.ts +60 -0
  45. package/lib/types/tool-guard.d.ts +103 -0
  46. package/lib/types/wrap-fs.d.ts +86 -4
  47. package/lib/types/wrap-sandbox.d.ts +26 -6
  48. package/lib/wrap-fs.js +323 -47
  49. package/lib/wrap-fs.js.map +1 -1
  50. package/lib/wrap-sandbox.js +149 -12
  51. package/lib/wrap-sandbox.js.map +1 -1
  52. package/package.json +3 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAiBH,wCAAwC;AACxC,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAA;AAY5C,sDAAsD;AACtD,MAAM,eAAe,GAAG,WAAW,CAAA;AACnC,MAAM,mBAAmB,GAAG,iBAAiB,CAAA;AAC7C,qDAAqD;AACrD,MAAM,kBAAkB,GAAG,iBAAiB,CAAA;AAC5C,kFAAkF;AAClF,MAAM,kBAAkB,GAAG,qBAAqB,CAAA;AAChD,gFAAgF;AAChF,MAAM,OAAO,GAAG,YAAY,CAAA;AAC5B,gEAAgE;AAChE,MAAM,eAAe,GAAG,mBAAmB,CAAA;AAC3C,uFAAuF;AACvF,MAAM,iBAAiB,GAAG,WAAW,CAAA;AAErC,mFAAmF;AACnF,MAAM,UAAU,kBAAkB,CAAC,QAAgB;IACjD,IAAI,mBAAmB,CAAC,IAAI,CAAC,QAAQ,CAAC;QAAE,OAAO,OAAO,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,CAAA;IAC7F,IAAI,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC;QAAE,OAAO,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;IAC3E,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED,gCAAgC;AAChC,MAAM,UAAU,WAAW,CAAC,KAAoB;IAC9C,OAAO,KAAK,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC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ClE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,eAAe,CAAC,aAAa,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,CAAA;QAC1G,KAAK,UAAU,CAAC;QAChB;YACE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,eAAe,CAAC,aAAa,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,CAAA;IAC5G,CAAC;AACH,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,kBAAkB,CAAC,QAAgB,EAAE,MAAc;IACjE,OAAO,gBAAgB,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,oCAAoC,MAAM,gFAAgF,CAAA;AAC3K,CAAC"}
package/lib/preview.js CHANGED
@@ -1,16 +1,21 @@
1
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
2
+ * The settings page's effective-rules preview: one authenticated read-only route
3
+ * that resolves the entries the page asks about for a workspace the page
4
4
  * supplies. It never probes arbitrary paths — every entry still goes through
5
5
  * `normalizeConfig` + `resolveRoots`, the same pair the enforcement layers use —
6
6
  * and it computes only path spellings, never file contents.
7
+ *
8
+ * The payload also carries the HOST's platform facts and shell capability: the
9
+ * browser cannot know either (under WSL it runs as Windows Chrome while the host
10
+ * is Linux, and a remote client is a different machine entirely), so the page
11
+ * only ever displays the host's answers.
7
12
  * @module dsh-extra-paths/preview
8
13
  */
9
- import { homedir } from 'node:os';
10
- import { isAbsolute } from 'node:path';
11
14
  import { normalizeConfig } from './config.js';
12
- import { canonicalizeRoot, expandPath } from './paths.js';
15
+ import { isAbsoluteSpelling } from './platform.js';
16
+ import { canonicalizeRoot, discoverPlatformFacts, expandConfiguredPath, hostPathDialect } from './paths.js';
13
17
  import { resolveRoots } from './resolve.js';
18
+ import { shellCapabilityOf } from './shell-dialect.js';
14
19
  /** The single route this plugin owns. */
15
20
  export const PREVIEW_PATH = '/extra-paths/resolved';
16
21
  /** The most entries one preview request may carry (a settings page sends its rows). */
@@ -45,24 +50,26 @@ export function parseStagedPaths(raw) {
45
50
  * Normalise the workspace base the page sent.
46
51
  *
47
52
  * `~` 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.
53
+ * first answer — and a spelling that is not absolute in the HOST's dialect is
54
+ * refused outright. That refusal is the fix for a real defect:
55
+ * `resolvePath('~/projects', '..')` used to be evaluated server-side, so a `~`
56
+ * base produced `…/<server cwd>/~/` in the preview while looking like an
57
+ * ordinary path. The host's dialect (not the browser's) decides what "absolute"
58
+ * means, so a `C:\…` workspace is accepted on Windows and a POSIX one inside WSL.
52
59
  * @param workspaceRoot - the raw query value.
60
+ * @param facts - the host facts, which also supply the home directory.
53
61
  * @returns the canonical absolute base.
54
- * @throws {Error} when the base is missing, relative, or a `~user` spelling.
62
+ * @throws {Error} when the base is missing, relative, foreign, or a `~user` spelling.
55
63
  */
56
- function workspaceBaseOf(workspaceRoot) {
64
+ function workspaceBaseOf(workspaceRoot, facts) {
57
65
  if (workspaceRoot === undefined || workspaceRoot.trim() === '')
58
66
  throw new Error('cwd is required');
59
67
  const trimmed = workspaceRoot.trim();
60
- if (trimmed === '~' || trimmed.startsWith('~/'))
61
- return canonicalizeRoot(expandPath(trimmed, homedir()));
62
- if (!isAbsolute(trimmed)) {
68
+ const expanded = isAbsoluteSpelling(trimmed) ? expandConfiguredPath(trimmed, facts.home, facts) : undefined;
69
+ if (expanded === undefined || !expanded.ok) {
63
70
  throw new Error(`cwd must be an absolute path or start with ~, received ${JSON.stringify(workspaceRoot)}`);
64
71
  }
65
- return canonicalizeRoot(trimmed);
72
+ return canonicalizeRoot(expanded.path, facts);
66
73
  }
67
74
  /**
68
75
  * Resolve a configuration for one workspace.
@@ -70,21 +77,41 @@ function workspaceBaseOf(workspaceRoot) {
70
77
  * @param workspaceRoot - the workspace the page is asking about.
71
78
  * @param staged - the page's unsaved rows, when it sent any: they REPLACE the
72
79
  * stored entries so the preview answers for the draft, not for the document.
80
+ * @param options - optional host inputs (tests); defaults to the live host.
73
81
  * @returns the preview payload.
74
82
  * @throws {Error} when no usable workspace was supplied or the staged rows are
75
83
  * invalid (the caller answers 400).
76
84
  */
77
- export function buildPreview(config, workspaceRoot, staged) {
78
- const base = workspaceBaseOf(workspaceRoot);
85
+ export function buildPreview(config, workspaceRoot, staged, options) {
86
+ const facts = options?.facts ?? discoverPlatformFacts();
87
+ const base = workspaceBaseOf(workspaceRoot, facts);
79
88
  // `normalizeConfig` is the same gate the settings service and the enforcement
80
89
  // layers use, so an invalid draft fails here with the user's own message.
81
90
  const effectiveConfig = staged === undefined ? config : normalizeConfig(staged);
82
- const report = resolveRoots(effectiveConfig, base);
91
+ // Name rules are FS-ONLY, so they are deliberately absent from the
92
+ // effective-roots arrays (those describe the shell-expressible roots, which is
93
+ // what they always meant). They are still enumerated here — one bounded walk
94
+ // per rule, cached for NAME_RULE_LIMITS.cacheMs — only so a row can show "N
95
+ // matches right now"; the walk never runs on the enforcement path.
96
+ const report = resolveRoots(effectiveConfig, base, facts, { expandNameRules: true });
97
+ const writable = report.roots.map(root => root.root);
98
+ const readOnly = report.readOnly.map(rule => rule.root);
99
+ const denied = report.denied.map(rule => rule.root);
83
100
  return {
84
101
  workspaceCwd: base,
85
- home: homedir(),
102
+ home: facts.home,
103
+ platform: {
104
+ platform: facts.platform,
105
+ wsl: facts.wsl,
106
+ wslMountRoot: facts.wslMountRoot,
107
+ dialect: hostPathDialect(facts),
108
+ },
109
+ capabilities: options?.capability ?? shellCapabilityOf(facts.platform),
86
110
  entries: report.entries,
87
- effective: report.roots.map(root => root.root),
111
+ effective: writable,
112
+ writable,
113
+ readOnly,
114
+ denied,
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AC9G,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,iCAAiC,EAAE,eAAe,EAAE,UAAU,EAAE,CAAC,CAAA;YACtG,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QACf,CAAC;QAAC,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 CHANGED
@@ -1,91 +1,264 @@
1
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.
2
+ * The one place a configuration becomes the effective access rules. Enforcement
3
+ * (both wrappers) and the settings preview call this, so what the page shows and
4
+ * what the sandbox grants cannot drift.
5
+ *
6
+ * 0.3.0 widened the report from "writable roots" to four levels: `deny`, `read`,
7
+ * `write`, `always-write`. The aggregation is deliberately NOT "the most
8
+ * specific path wins": a narrower rule must never widen a broader grant by
9
+ * accident, so every rule that covers one canonical root is merged with the
10
+ * STRICTER level winning (`deny > read > write`), and `write`/`always-write`
11
+ * merge to the wider `always-write`. Surfaces are aggregated separately, which
12
+ * is what lets one root be writable for `fs` while the shell may only read it.
13
+ *
14
+ * A BARE NAME (`.git`, `.env`, `node_modules`) is a name rule: it matches that
15
+ * component at any depth under the session workspace plus every configured
16
+ * writable root (see {@link module:dsh-extra-paths/name-rule}). It is resolved
17
+ * in two deliberately different ways:
18
+ * - The report ALWAYS carries `nameRules` (lexical, no filesystem access), which
19
+ * is all the fs surface needs: it matches the target's components on every
20
+ * call, so it even covers a directory created a moment ago.
21
+ * - `nameMatches` — the concrete paths a shell profile must deny/grant — needs
22
+ * a bounded directory walk, so it is filled ONLY when the caller asks for it
23
+ * (`expandNameRules`). The fs hot path runs once per write and must not walk.
24
+ *
5
25
  * @module dsh-extra-paths/resolve
6
26
  */
7
27
  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';
28
+ import { SURFACES } from './config.js';
29
+ import { expandNameMatches, NAME_RULE_LIMITS, scopeRootsOf } from './name-rule.js';
30
+ import { expandPattern, isPattern, parsePatternOutcome, PATTERN_LIMITS } from './pattern.js';
31
+ import { foreignPathMessage, isBareNameSpelling } from './platform.js';
32
+ import { canonicalizeRoot, discoverPlatformFacts, expandConfiguredPath, isHostVolumeRootPath, isUnder, } from './paths.js';
12
33
  /**
13
34
  * How long one pattern's expansion is reused (milliseconds). Long enough that a
14
35
  * broad `**` walk costs one hiccup rather than one per five seconds; short enough
15
36
  * that a worktree created a moment ago shows up without any manual refresh.
16
37
  */
17
- export const PATTERN_CACHE_MS = 30000;
18
- /** Expansions seen recently, keyed by the configured spelling. */
38
+ const PATTERN_CACHE_MS = 30000;
39
+ /** Expansions seen recently, keyed by the configured spelling AND its workspace base. */
19
40
  const patternCache = new Map();
20
- /** Drop every cached expansion (a fresh directory should not wait out the TTL). */
41
+ /**
42
+ * The cache key of one expansion. The workspace base is part of it: a relative
43
+ * anchor is refused by the parser today, but keying on the raw spelling alone
44
+ * would let a future grammar change (or a hand-built pattern) reuse one
45
+ * session's expansion in another workspace — and a reused expansion now
46
+ * mis-applies DENY/READ rules, which is security-relevant, not cosmetic.
47
+ */
48
+ function expansionKey(raw, workspaceRoot) {
49
+ return `${workspaceRoot}\u0000${raw}`;
50
+ }
51
+ /**
52
+ * Drop every cached expansion (a fresh directory should not wait out the TTL).
53
+ * Name-rule walks go too: tests use this as the one "forget the walk caches"
54
+ * hook, and a stale name list is the same class of surprise as a stale pattern
55
+ * list.
56
+ */
21
57
  export function clearPatternCache() {
22
58
  patternCache.clear();
59
+ nameRuleCache.clear();
60
+ }
61
+ /** Drop only the cached name-rule walks (the fs hot path never fills them). */
62
+ export function clearNameRuleCache() {
63
+ nameRuleCache.clear();
64
+ }
65
+ /** Turn a cache row into a snapshot, so a caller cannot mutate the cache. */
66
+ function snapshot(row) {
67
+ return {
68
+ matches: row.matches,
69
+ capped: row.capped,
70
+ ...(row.cap === undefined ? {} : { cap: row.cap }),
71
+ ...(row.truncated === undefined ? {} : { truncated: row.truncated }),
72
+ };
23
73
  }
24
74
  /**
25
75
  * Expand one pattern, reusing a recent expansion.
26
76
  * @param raw - the configured spelling.
27
77
  * @param workspaceRoot - the session workspace a relative anchor resolves against.
78
+ * @param facts - host facts the anchor is translated with.
28
79
  * @param now - current time in milliseconds (injected for tests).
29
- * @returns the matches and whether a cap was hit.
80
+ * @returns the expansion, or the reason the anchor is foreign to this host.
30
81
  */
31
- function expansionOf(raw, workspaceRoot, now) {
32
- const cached = patternCache.get(raw);
82
+ function expansionOf(raw, workspaceRoot, facts, now) {
83
+ const key = expansionKey(raw, workspaceRoot);
84
+ const cached = patternCache.get(key);
33
85
  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
- };
86
+ return { expansion: snapshot(cached) };
87
+ }
88
+ const outcome = parsePatternOutcome(raw, workspaceRoot, facts);
89
+ // A foreign anchor is NOT cached: it is a platform fact rather than a walk, and
90
+ // the caller answers it with a warning instead of an expansion.
91
+ if (!outcome.ok && outcome.foreign !== undefined) {
92
+ return { foreign: outcome.foreign, expansion: { matches: [], capped: true, cap: 'anchor' } };
40
93
  }
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
- });
94
+ const expansion = outcome.ok
95
+ ? expandPattern(outcome.pattern)
96
+ : { matches: [], capped: true, cap: 'anchor' };
97
+ patternCache.set(key, { at: now, ...snapshot(expansion) });
98
+ return { expansion: snapshot(expansion) };
99
+ }
100
+ /**
101
+ * Name-rule walks seen recently. The shell surface resolves once per
102
+ * confinement, and walking the session workspace on every command would be a
103
+ * self-inflicted stall; a directory created a moment ago still appears after the
104
+ * TTL (or after a config save clears the caches).
105
+ */
106
+ const nameRuleCache = new Map();
107
+ /**
108
+ * The cache key of one name walk. The scope roots ARE the walk, so a rule
109
+ * resolved for one workspace must never be reused for another (the same
110
+ * security reasoning as {@link expansionKey}). The host facts ride along because
111
+ * case folding and the path API are host properties.
112
+ */
113
+ function nameRuleKey(name, scopeRoots, facts) {
114
+ return JSON.stringify([name, scopeRoots, facts.platform, facts.wsl, facts.wslMountRoot, facts.home]);
115
+ }
116
+ /** Turn a cache row into a snapshot, so a caller cannot mutate the cache. */
117
+ function nameExpansionSnapshot(row) {
52
118
  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 } : {}),
119
+ matches: [...row.matches],
120
+ capped: row.capped,
121
+ ...(row.cap === undefined ? {} : { cap: row.cap }),
122
+ truncated: row.truncated,
123
+ incompleteRoots: [...row.incompleteRoots],
124
+ skippedSymlinks: row.skippedSymlinks,
125
+ scanned: row.scanned,
126
+ complete: row.complete,
57
127
  };
58
128
  }
129
+ /**
130
+ * One name rule's bounded walk, reusing a recent one.
131
+ * @param name - the component to match.
132
+ * @param scopeRoots - {@link scopeRootsOf} output for this pass.
133
+ * @param facts - host facts.
134
+ * @param now - current time in milliseconds (injected for tests).
135
+ * @returns the expansion (cached or fresh), including the completeness verdict.
136
+ */
137
+ function nameExpansionOf(name, scopeRoots, facts, now) {
138
+ const key = nameRuleKey(name, scopeRoots, facts);
139
+ const cached = nameRuleCache.get(key);
140
+ if (cached !== undefined && now - cached.at < NAME_RULE_LIMITS.cacheMs) {
141
+ return nameExpansionSnapshot(cached);
142
+ }
143
+ const expansion = expandNameMatches(name, scopeRoots, facts);
144
+ const snapshot = nameExpansionSnapshot(expansion);
145
+ nameRuleCache.set(key, { at: now, ...snapshot });
146
+ return snapshot;
147
+ }
148
+ /**
149
+ * Why one name rule could not be enumerated exhaustively, in user terms. A cap
150
+ * and a truncation are different problems (a cap says "narrow the scope", a
151
+ * truncation says "spell the deep paths explicitly"), so they are named instead
152
+ * of being collapsed into a generic failure.
153
+ * @param expansion - the incomplete walk's verdict.
154
+ * @returns the reasons, joined for one warning line.
155
+ */
156
+ function incompleteNameRuleReason(expansion) {
157
+ const reasons = [];
158
+ if (expansion.cap === 'matches') {
159
+ reasons.push(`it currently matches more than ${NAME_RULE_LIMITS.maxMatches} paths`);
160
+ }
161
+ else if (expansion.cap === 'directories') {
162
+ reasons.push(`it examined more than ${NAME_RULE_LIMITS.maxDirs} directories`);
163
+ }
164
+ if (expansion.truncated) {
165
+ reasons.push(`the walk stopped at the ${NAME_RULE_LIMITS.maxDepth}-level depth limit or at an unreadable entry`);
166
+ }
167
+ if (expansion.skippedSymlinks > 0) {
168
+ reasons.push(`${expansion.skippedSymlinks} matching path(s) are symbolic links, which a shell profile cannot mask`);
169
+ }
170
+ return reasons.length > 0 ? reasons.join('; ') : 'the enumeration was incomplete';
171
+ }
172
+ /**
173
+ * The one warning an incomplete name rule produces.
174
+ *
175
+ * The matches that WERE found stay enforced (denying more concrete paths is
176
+ * always safe); the warning is about the paths the walk could not reach, which
177
+ * the shell surface may therefore miss. The fs surface is unaffected: it matches
178
+ * the rule lexically on every call.
179
+ * @param raw - the configured spelling.
180
+ * @param expansion - the incomplete walk's verdict.
181
+ * @returns one user-facing warning line.
182
+ */
183
+ function incompleteNameRuleWarning(raw, expansion) {
184
+ const roots = expansion.incompleteRoots;
185
+ const shown = roots.length > 2 ? `${roots.slice(0, 2).join(', ')} and ${roots.length - 2} more` : roots.join(', ');
186
+ return `extra-paths: name rule ${JSON.stringify(raw)} match count is partial because `
187
+ + `${incompleteNameRuleReason(expansion)}; the ${expansion.matches.length} match(es) found still apply to the fs tools, `
188
+ + `but paths under ${shown || 'an unscannable root'} were not scanned — the preview's match count is partial, `
189
+ + 'while fs enforcement keeps matching the name live on every call';
190
+ }
59
191
  /**
60
192
  * Whether a root contains (or is) the home directory. Exact equality alone is
61
193
  * not enough: `~/..` canonicalises to the directory holding every user's home,
62
194
  * which is strictly broader than `~` yet would otherwise pass unwarned.
63
195
  * @param root - canonical root under test.
64
196
  * @param homeRoot - canonical home directory, resolved once per pass.
197
+ * @param facts - host facts.
65
198
  * @returns true when home lies at or beneath the root.
66
199
  */
67
- function containsHome(root, homeRoot) {
68
- return isUnder(homeRoot, root);
200
+ function containsHome(root, homeRoot, facts) {
201
+ return isUnder(homeRoot, root, facts);
202
+ }
203
+ /**
204
+ * Fold one active entry into its canonical root's accumulator.
205
+ * @param aggregates - per-root accumulators (insertion order is report order).
206
+ * @param raw - the configured spelling.
207
+ * @param access - the entry's access level.
208
+ * @param surfaces - the surfaces the entry applies to.
209
+ * @param root - the canonical root the entry resolved to.
210
+ */
211
+ function mergeEntry(aggregates, raw, access, surfaces, root) {
212
+ let aggregate = aggregates.get(root);
213
+ if (aggregate === undefined) {
214
+ aggregate = { raw, root, writable: new Map(), read: new Set(), deny: new Set() };
215
+ aggregates.set(root, aggregate);
216
+ }
217
+ for (const surface of surfaces) {
218
+ switch (access) {
219
+ case 'deny':
220
+ aggregate.deny.add(surface);
221
+ break;
222
+ case 'read':
223
+ aggregate.read.add(surface);
224
+ break;
225
+ case 'write':
226
+ case 'always-write': {
227
+ const widest = aggregate.writable.get(surface) === 'always-write' || access === 'always-write'
228
+ ? 'always-write'
229
+ : 'write';
230
+ aggregate.writable.set(surface, widest);
231
+ break;
232
+ }
233
+ }
234
+ }
69
235
  }
70
236
  /**
71
237
  * Resolve every configured entry against one session workspace.
72
238
  * @param config - the normalised configuration.
73
239
  * @param workspaceRoot - the session workspace a relative entry resolves against.
74
- * @returns effective roots plus per-entry detail and warnings.
240
+ * @param facts - host facts (defaults to the discovered ones).
241
+ * @param options - pass `{ expandNameRules: true }` to fill `nameMatches` with
242
+ * concrete paths (shell surface and preview); the default leaves the walk out.
243
+ * @returns effective rules, per-entry detail and warnings.
75
244
  */
76
- export function resolveRoots(config, workspaceRoot) {
245
+ export function resolveRoots(config, workspaceRoot, facts = discoverPlatformFacts(), options) {
77
246
  const entries = [];
78
247
  const warnings = [];
79
- const byRoot = new Map();
248
+ const aggregates = new Map();
249
+ const nameRules = [];
250
+ const nameRuleByName = new Map();
251
+ /** Entry indexes of the bare-name rows, so an expansion can fill `matches`. */
252
+ const bareEntries = [];
80
253
  // Probed at most once per pass — and not at all when no entry is active,
81
254
  // because this runs on every enforcement decision.
82
255
  let homeRoot;
83
256
  const now = Date.now();
84
- const acceptEntry = (raw, scope, surfaces, root) => {
257
+ const acceptEntry = (raw, access, surfaces, root) => {
85
258
  // A COPY of the caller's array: handing the config's own instance to a
86
259
  // report lets a caller mutate future grants through it.
87
- const shared = { raw, resolved: root, scope, surfaces: [...surfaces] };
88
- if (isFilesystemRoot(root)) {
260
+ const shared = { raw, resolved: root, access, surfaces: [...surfaces] };
261
+ if (isHostVolumeRootPath(root, facts)) {
89
262
  entries.push({ ...shared, status: 'rejected' });
90
263
  warnings.push(`extra-paths: ${JSON.stringify(raw)} resolves to the filesystem root; the entry is ignored`);
91
264
  return;
@@ -96,37 +269,71 @@ export function resolveRoots(config, workspaceRoot) {
96
269
  return;
97
270
  }
98
271
  entries.push({ ...shared, status: 'ok' });
99
- homeRoot ??= canonicalizeRoot(homedir());
100
- if (containsHome(root, homeRoot)) {
272
+ homeRoot ??= canonicalizeRoot(facts.home, facts);
273
+ if (containsHome(root, homeRoot, facts)) {
101
274
  warnings.push(`extra-paths: ${JSON.stringify(raw)} resolves to ${root}, which contains your entire home directory; `
102
275
  + 'prefer a narrower root');
103
276
  }
104
- if (root !== workspaceRoot && isUnder(workspaceRoot, root)) {
277
+ if (root !== workspaceRoot && isUnder(workspaceRoot, root, facts)) {
105
278
  warnings.push(`extra-paths: ${JSON.stringify(raw)} resolves to ${root}, which contains this session's workspace; `
106
279
  + 'prefer a sibling-scoped root');
107
280
  }
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)) });
281
+ mergeEntry(aggregates, raw, access, surfaces, root);
282
+ };
283
+ /** Report one entry that is inactive without contributing a rule. */
284
+ const inactive = (raw, access, surfaces, status) => {
285
+ entries.push({ raw, resolved: '', access, surfaces: [...surfaces], status });
121
286
  };
122
287
  for (const entry of config.paths) {
288
+ if (isBareNameSpelling(entry.path)) {
289
+ // A name rule is never "missing": the fs surface applies it lexically on
290
+ // every call, so it is live even when the current walk finds nothing (the
291
+ // directory may be created a moment later) and even when the report was
292
+ // resolved without a walk.
293
+ if (!nameRuleByName.has(entry.path)) {
294
+ // One rule per name. The settings gate already refuses duplicate bare
295
+ // names; a config that bypassed it (a synthesized/older document) still
296
+ // gets one walk per name, and the first entry's level wins.
297
+ const rule = {
298
+ raw: entry.path,
299
+ name: entry.path,
300
+ access: entry.access,
301
+ surfaces: [...entry.surfaces],
302
+ };
303
+ nameRuleByName.set(entry.path, rule);
304
+ nameRules.push(rule);
305
+ }
306
+ entries.push({
307
+ raw: entry.path,
308
+ resolved: '',
309
+ access: entry.access,
310
+ surfaces: [...entry.surfaces],
311
+ status: 'ok',
312
+ });
313
+ bareEntries.push({ index: entries.length - 1, name: entry.path });
314
+ continue;
315
+ }
123
316
  if (!isPattern(entry.path)) {
124
- acceptEntry(entry.path, entry.scope, entry.surfaces, canonicalizeRoot(expandPath(entry.path, workspaceRoot)));
317
+ const expanded = expandConfiguredPath(entry.path, workspaceRoot, facts);
318
+ if (!expanded.ok) {
319
+ // A spelling of the other platform: the entry stays inactive with ONE
320
+ // informative warning instead of failing the configuration, so the same
321
+ // document can be used on every host.
322
+ inactive(entry.path, entry.access, entry.surfaces, 'foreign');
323
+ warnings.push(foreignPathMessage(entry.path, expanded.foreign));
324
+ continue;
325
+ }
326
+ acceptEntry(entry.path, entry.access, entry.surfaces, canonicalizeRoot(expanded.path, facts));
327
+ continue;
328
+ }
329
+ const { expansion, foreign } = expansionOf(entry.path, workspaceRoot, facts, now);
330
+ if (foreign !== undefined) {
331
+ inactive(entry.path, entry.access, entry.surfaces, 'foreign');
332
+ warnings.push(foreignPathMessage(entry.path, foreign));
125
333
  continue;
126
334
  }
127
- const expansion = expansionOf(entry.path, workspaceRoot, now);
128
335
  if (expansion.capped) {
129
- entries.push({ raw: entry.path, resolved: '', scope: entry.scope, surfaces: [...entry.surfaces], status: 'rejected' });
336
+ inactive(entry.path, entry.access, entry.surfaces, 'rejected');
130
337
  const reason = expansion.cap === 'anchor'
131
338
  ? 'its anchor is not walkable (needs a literal absolute or ~/ path at least two segments deep)'
132
339
  : expansion.cap === 'matches'
@@ -141,13 +348,87 @@ export function resolveRoots(config, workspaceRoot) {
141
348
  + 'spell the deeper levels explicitly if a matching directory lives further down');
142
349
  }
143
350
  if (expansion.matches.length === 0) {
144
- entries.push({ raw: entry.path, resolved: '', scope: entry.scope, surfaces: [...entry.surfaces], status: 'missing' });
351
+ inactive(entry.path, entry.access, entry.surfaces, 'missing');
145
352
  warnings.push(`extra-paths: pattern ${JSON.stringify(entry.path)} matches no existing directory; the entry is inactive until one appears`);
146
353
  continue;
147
354
  }
148
355
  for (const match of expansion.matches)
149
- acceptEntry(entry.path, entry.scope, entry.surfaces, match);
356
+ acceptEntry(entry.path, entry.access, entry.surfaces, match);
357
+ }
358
+ const roots = [];
359
+ const readOnly = [];
360
+ const denied = [];
361
+ for (const aggregate of aggregates.values()) {
362
+ // SURFACES order, not insertion order: a config edit that only reorders
363
+ // surfaces must not change a report's identity. Precedence per surface:
364
+ // deny > read > write, and deny/read only ever subtract from the writable set.
365
+ const writableSurfaces = SURFACES.filter(surface => aggregate.writable.has(surface)
366
+ && !aggregate.read.has(surface)
367
+ && !aggregate.deny.has(surface));
368
+ if (writableSurfaces.length > 0) {
369
+ const scope = writableSurfaces.some(surface => aggregate.writable.get(surface) === 'always-write')
370
+ ? 'always-write'
371
+ : 'write';
372
+ roots.push({ raw: aggregate.raw, root: aggregate.root, scope, surfaces: writableSurfaces });
373
+ }
374
+ const readSurfaces = SURFACES.filter(surface => aggregate.read.has(surface) && !aggregate.deny.has(surface));
375
+ if (readSurfaces.length > 0) {
376
+ readOnly.push({ raw: aggregate.raw, root: aggregate.root, access: 'read', surfaces: readSurfaces });
377
+ }
378
+ const denySurfaces = SURFACES.filter(surface => aggregate.deny.has(surface));
379
+ if (denySurfaces.length > 0) {
380
+ denied.push({ raw: aggregate.raw, root: aggregate.root, access: 'deny', surfaces: denySurfaces });
381
+ }
382
+ }
383
+ // Name rules are enumerated LAST, because their scope is the session
384
+ // workspace plus the writable roots this pass just resolved — a name rule
385
+ // must see the same roots the shell would. The walk is opt-in: the fs hot
386
+ // path resolves without it and matches lexically instead.
387
+ const nameMatches = [];
388
+ if (options?.expandNameRules === true && nameRules.length > 0) {
389
+ const scopeRoots = scopeRootsOf(workspaceRoot, roots.map(root => root.root), facts);
390
+ const expansions = new Map();
391
+ for (const rule of nameRules) {
392
+ const expansion = nameExpansionOf(rule.name, scopeRoots, facts, now);
393
+ expansions.set(rule.name, expansion);
394
+ if (!expansion.complete) {
395
+ // PARTIAL coverage: matches that were found stay enforced (denying more
396
+ // concrete paths is always safe) and the warning names the roots the walk
397
+ // could not finish. Dropping every match here was the earlier bug: one
398
+ // deep writable runtime tree (~/.dsh) made a `.git` rule protect the fs
399
+ // tools but not the shell in the actual workspace.
400
+ warnings.push(incompleteNameRuleWarning(rule.raw, expansion));
401
+ }
402
+ for (const root of expansion.matches)
403
+ nameMatches.push({ rule, root });
404
+ }
405
+ for (const bare of bareEntries) {
406
+ const entry = entries[bare.index];
407
+ const expansion = expansions.get(bare.name);
408
+ if (entry === undefined || expansion === undefined)
409
+ continue;
410
+ // `matches` mirrors the concrete paths the surface ACTUALLY acts on: the
411
+ // found ones are enforced even when the walk was partial (the warning
412
+ // covers the difference), so the count is the enforced count.
413
+ entries[bare.index] = { ...entry, matches: expansion.matches.length };
414
+ }
150
415
  }
151
- return { roots: [...byRoot.values()], entries, warnings: [...new Set(warnings)] };
416
+ return { roots, readOnly, denied, entries, nameRules, nameMatches, warnings: [...new Set(warnings)] };
417
+ }
418
+ /**
419
+ * The walk scope of the name rules in one report: the session workspace plus
420
+ * every configured writable root, nested roots collapsed.
421
+ *
422
+ * Exported because the fs wrapper resolves a report WITHOUT an expansion (its
423
+ * per-call test is lexical) but must still use the SAME scope the shell
424
+ * expansion and the preview used — two scope definitions would be a way for one
425
+ * rule to apply on one surface but not the other.
426
+ * @param report - a report from {@link resolveRoots}, expanded or not.
427
+ * @param workspaceRoot - the session workspace the report was resolved against.
428
+ * @param facts - host facts.
429
+ * @returns scope roots in walk order (workspace first).
430
+ */
431
+ export function nameScopeRoots(report, workspaceRoot, facts) {
432
+ return scopeRootsOf(workspaceRoot, report.roots.map(root => root.root), facts);
152
433
  }
153
434
  //# sourceMappingURL=resolve.js.map