dsh-extra-paths 0.0.0-stage → 0.1.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/README.md +79 -2
- 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 +113 -4
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The plugin's configuration vocabulary: a plugin-level default scope and
|
|
3
|
+
* surface set, plus per-path entries that override them. Everything here is
|
|
4
|
+
* pure so the settings schema, the CLI-facing validator, and the enforcement
|
|
5
|
+
* layers share one normalisation.
|
|
6
|
+
* @module dsh-extra-paths/config
|
|
7
|
+
*/
|
|
8
|
+
/** How far one configured root's write grant reaches across session modes. */
|
|
9
|
+
export type Scope = 'write' | 'always-write';
|
|
10
|
+
/** Which enforcement surface a configured root's grant applies to. */
|
|
11
|
+
export type Surface = 'fs' | 'shell';
|
|
12
|
+
/** All scopes, in escalation order. */
|
|
13
|
+
export declare const SCOPES: readonly Scope[];
|
|
14
|
+
/** All surfaces. `fs` is the write/edit tool family; `shell` is the subprocess sandbox. */
|
|
15
|
+
export declare const SURFACES: readonly Surface[];
|
|
16
|
+
/** One configured root after normalisation. */
|
|
17
|
+
export interface PathEntry {
|
|
18
|
+
readonly path: string;
|
|
19
|
+
readonly scope: Scope;
|
|
20
|
+
readonly surfaces: readonly Surface[];
|
|
21
|
+
}
|
|
22
|
+
/** The normalised configuration the enforcement layers read. */
|
|
23
|
+
export interface ExtraPathsConfig {
|
|
24
|
+
readonly defaultScope: Scope;
|
|
25
|
+
readonly defaultSurfaces: readonly Surface[];
|
|
26
|
+
readonly paths: readonly PathEntry[];
|
|
27
|
+
}
|
|
28
|
+
/** Untrusted configuration as it arrives from the settings document or entry config. */
|
|
29
|
+
export interface RawConfig {
|
|
30
|
+
readonly defaultScope?: unknown;
|
|
31
|
+
readonly defaultSurfaces?: unknown;
|
|
32
|
+
readonly paths?: unknown;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Normalise untrusted configuration, applying defaults and rejecting anything
|
|
36
|
+
* the enforcement layers could not act on.
|
|
37
|
+
* @param raw - the settings section or entry config.
|
|
38
|
+
* @returns the normalised configuration.
|
|
39
|
+
* @throws {Error} on a malformed entry, unknown vocabulary, or empty surfaces.
|
|
40
|
+
*/
|
|
41
|
+
export declare function normalizeConfig(raw: RawConfig | undefined): ExtraPathsConfig;
|
|
42
|
+
/**
|
|
43
|
+
* Whether a path names a filesystem root, which would disable the sandbox
|
|
44
|
+
* outright. A bare drive (`C:`) is drive-RELATIVE rather than a root, but it is
|
|
45
|
+
* rejected conservatively: on Windows it can still resolve to a whole volume,
|
|
46
|
+
* and the message says so instead of mislabelling it.
|
|
47
|
+
*/
|
|
48
|
+
export declare function isFilesystemRoot(path: string): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* The settings service's `validate` hook: refuse a write the plugin could never
|
|
51
|
+
* act on, so the user learns at save time instead of storing a dead section.
|
|
52
|
+
* @param raw - the resolved section the write would store.
|
|
53
|
+
* @throws {Error} on a duplicate literal entry or a filesystem root.
|
|
54
|
+
*/
|
|
55
|
+
export declare function validateConfig(raw: RawConfig | undefined): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The runtime-context section that tells the model which extra roots this
|
|
3
|
+
* session may write under, so it neither refuses nor escalates pre-emptively.
|
|
4
|
+
* @module dsh-extra-paths/context
|
|
5
|
+
*/
|
|
6
|
+
import type { ExtraPathsConfig } from './config.js';
|
|
7
|
+
/**
|
|
8
|
+
* Render the section text, or an empty string when there is nothing to say.
|
|
9
|
+
* @param readConfig - current configuration snapshot.
|
|
10
|
+
* @param cwd - the calling session's workspace (undefined outside a session).
|
|
11
|
+
* @returns the prompt text.
|
|
12
|
+
*/
|
|
13
|
+
export declare function renderExtraPathsContext(readConfig: () => ExtraPathsConfig, cwd: string | undefined): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The mode gate: which configured roots one call may write under.
|
|
3
|
+
* `write` rides the session mode; `always-write` survives `read-only` too.
|
|
4
|
+
* @module dsh-extra-paths/grant
|
|
5
|
+
*/
|
|
6
|
+
import type { Surface } from './config.js';
|
|
7
|
+
import type { ResolvedRoot } from './resolve.js';
|
|
8
|
+
/** The modes a resolved policy can carry (kept local so the plugin imports no core type). */
|
|
9
|
+
export type SandboxModeLike = 'read-only' | 'workspace-write' | 'danger-full-access';
|
|
10
|
+
/**
|
|
11
|
+
* Select the roots a call under `mode` may write under for one surface.
|
|
12
|
+
* @param mode - the resolved per-call sandbox mode.
|
|
13
|
+
* @param roots - effective roots for this session workspace.
|
|
14
|
+
* @param surface - the enforcement surface asking.
|
|
15
|
+
* @returns the roots to grant; empty means "delegate unchanged".
|
|
16
|
+
*/
|
|
17
|
+
export declare function grantFor(mode: SandboxModeLike, roots: readonly ResolvedRoot[], surface: Surface): readonly ResolvedRoot[];
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-extra-paths: configured extra writable roots for the sandboxed fs tools
|
|
3
|
+
* and the sandboxed shell, plus the settings surface and its preview route.
|
|
4
|
+
*
|
|
5
|
+
* Host half only. No `@deepseek-ai/*` VALUE import except the schema builder:
|
|
6
|
+
* every failure below degrades to "no grant + warning", never to a failed boot.
|
|
7
|
+
*
|
|
8
|
+
* Two host generations are supported from one body, because the settings seam
|
|
9
|
+
* changed shape in 0.2.0 and the plugin must not throw on either:
|
|
10
|
+
* - 0.1.5: `ctx.settings.register(ns, schema, { base, applies, validate })`
|
|
11
|
+
* returns a scope whose `get()`/`watch()` drive `current`.
|
|
12
|
+
* - 0.2.x: that API is GONE. A namespace IS the plugin's loader entry, its
|
|
13
|
+
* schema is this module's exported {@link Config}, and live values are the
|
|
14
|
+
* `volatile()` fields of the config the loader hands to {@link apply} — which
|
|
15
|
+
* are re-read on every enforcement decision, so an edit in the framework's
|
|
16
|
+
* settings form applies without a restart.
|
|
17
|
+
* @module dsh-extra-paths
|
|
18
|
+
*/
|
|
19
|
+
import { type ExtraPathsConfig, type RawConfig } from './config.js';
|
|
20
|
+
import { installListener } from './listener.js';
|
|
21
|
+
/** The settings namespace the client page binds to. */
|
|
22
|
+
export declare const SETTINGS_NAMESPACE = "extra-paths";
|
|
23
|
+
/**
|
|
24
|
+
* The plugin's configuration schema as the 0.2.x loader expects to find it: a
|
|
25
|
+
* module-level `Config` export, read through `entry.fiber.runtime.Config`. Fields
|
|
26
|
+
* are `volatile()` because a settings form only describes volatile fields.
|
|
27
|
+
*/
|
|
28
|
+
export declare const Config: import("@deepseek-ai/schemastery").default<Schemastery.ObjectS<NoInfer<{
|
|
29
|
+
defaultScope: import("@deepseek-ai/schemastery").default<import("./config.js").Scope, import("./config.js").Scope, "defined">;
|
|
30
|
+
defaultSurfaces: import("@deepseek-ai/schemastery").default<import("./config.js").Surface[], import("./config.js").Surface[], "defined">;
|
|
31
|
+
paths: import("@deepseek-ai/schemastery").default<(string | import("./schema.js").ExtraPathsSectionEntry)[], (string | import("./schema.js").ExtraPathsSectionEntry)[], "defined">;
|
|
32
|
+
}>>, Schemastery.ObjectT<NoInfer<{
|
|
33
|
+
defaultScope: import("@deepseek-ai/schemastery").default<import("./config.js").Scope, import("./config.js").Scope, "defined">;
|
|
34
|
+
defaultSurfaces: import("@deepseek-ai/schemastery").default<import("./config.js").Surface[], import("./config.js").Surface[], "defined">;
|
|
35
|
+
paths: import("@deepseek-ai/schemastery").default<(string | import("./schema.js").ExtraPathsSectionEntry)[], (string | import("./schema.js").ExtraPathsSectionEntry)[], "defined">;
|
|
36
|
+
}>>, "plain">;
|
|
37
|
+
/**
|
|
38
|
+
* Normalise the entry config, degrading to the documented empty configuration
|
|
39
|
+
* on any problem. This is the plugin's only untrusted-input boundary that runs
|
|
40
|
+
* before the settings service can validate anything, so it must not throw.
|
|
41
|
+
* @param raw - the entry config as loaded from the composition.
|
|
42
|
+
* @param warn - warning sink.
|
|
43
|
+
* @returns a normalised configuration safe to read on every enforcement decision.
|
|
44
|
+
*/
|
|
45
|
+
export declare function safeEntryConfig(raw: RawConfig | undefined, warn: (message: string) => void): ExtraPathsConfig;
|
|
46
|
+
/**
|
|
47
|
+
* Read the 0.2.x live config: every `volatile()` field is a wrapper with `get()`,
|
|
48
|
+
* so this returns the CURRENT value rather than the value captured at load. A
|
|
49
|
+
* plain object (0.1.5, or a hand-written patch without volatile fields) is
|
|
50
|
+
* returned as-is so both generations share one reader.
|
|
51
|
+
* @param config - the config the loader passed to {@link apply}.
|
|
52
|
+
* @returns a raw section, or undefined when nothing usable is present.
|
|
53
|
+
*/
|
|
54
|
+
export declare function readLiveConfig(config: unknown): RawConfig | undefined;
|
|
55
|
+
/** Minimal plugin context surface (the loader passes the real cordis context). */
|
|
56
|
+
interface PluginContext {
|
|
57
|
+
logger: {
|
|
58
|
+
info(message: string): void;
|
|
59
|
+
warn(message: string): void;
|
|
60
|
+
};
|
|
61
|
+
on: Parameters<typeof installListener>[0]['on'];
|
|
62
|
+
inject(names: readonly string[], callback: (scope: never) => void): unknown;
|
|
63
|
+
effect?(callback: () => unknown, label?: string): unknown;
|
|
64
|
+
sandboxPolicy: unknown;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Plugin body.
|
|
68
|
+
* @param ctx - the entry context.
|
|
69
|
+
* @param config - the entry config: the settings `base` layer on 0.1.5, and the
|
|
70
|
+
* live (volatile) settings themselves on 0.2.x.
|
|
71
|
+
*/
|
|
72
|
+
export declare function apply(ctx: PluginContext, config?: RawConfig): void;
|
|
73
|
+
/** Property carrier so the loader waits for the policy service. */
|
|
74
|
+
declare const plugin: typeof apply & {
|
|
75
|
+
inject: readonly ["sandboxPolicy"];
|
|
76
|
+
Config: import("@deepseek-ai/schemastery").default<Schemastery.ObjectS<NoInfer<{
|
|
77
|
+
defaultScope: import("@deepseek-ai/schemastery").default<import("./config.js").Scope, import("./config.js").Scope, "defined">;
|
|
78
|
+
defaultSurfaces: import("@deepseek-ai/schemastery").default<import("./config.js").Surface[], import("./config.js").Surface[], "defined">;
|
|
79
|
+
paths: import("@deepseek-ai/schemastery").default<(string | import("./schema.js").ExtraPathsSectionEntry)[], (string | import("./schema.js").ExtraPathsSectionEntry)[], "defined">;
|
|
80
|
+
}>>, Schemastery.ObjectT<NoInfer<{
|
|
81
|
+
defaultScope: import("@deepseek-ai/schemastery").default<import("./config.js").Scope, import("./config.js").Scope, "defined">;
|
|
82
|
+
defaultSurfaces: import("@deepseek-ai/schemastery").default<import("./config.js").Surface[], import("./config.js").Surface[], "defined">;
|
|
83
|
+
paths: import("@deepseek-ai/schemastery").default<(string | import("./schema.js").ExtraPathsSectionEntry)[], (string | import("./schema.js").ExtraPathsSectionEntry)[], "defined">;
|
|
84
|
+
}>>, "plain">;
|
|
85
|
+
};
|
|
86
|
+
export default plugin;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `internal/get` interception: wraps `ctx.fs` and `ctx.sandbox` as they are
|
|
3
|
+
* read. The callback must never change the semantics of a service read — it
|
|
4
|
+
* always calls `next()`, rethrows a resolution failure unchanged, and falls
|
|
5
|
+
* back to the unwrapped value if its own wrapping throws.
|
|
6
|
+
* @module dsh-extra-paths/listener
|
|
7
|
+
*/
|
|
8
|
+
import type { ExtraPathsConfig } from './config.js';
|
|
9
|
+
import type { PolicyLike } from './policy.js';
|
|
10
|
+
/** The context surface the listener needs (cordis `on`, deliberately minimal). */
|
|
11
|
+
export interface ListenerContext {
|
|
12
|
+
on(name: 'internal/get', listener: (ctx: unknown, name: unknown, error: unknown, next: () => unknown) => unknown): unknown;
|
|
13
|
+
}
|
|
14
|
+
/** What the listener needs from the plugin. */
|
|
15
|
+
export interface ListenerDeps {
|
|
16
|
+
readConfig(): ExtraPathsConfig;
|
|
17
|
+
/** Resolve the deployment fallback policy through the READING context. */
|
|
18
|
+
fallbackPolicy(readCtx: unknown): PolicyLike | undefined;
|
|
19
|
+
warn(message: string): void;
|
|
20
|
+
}
|
|
21
|
+
/** Observability of one installation (the load-time self-test reads it). */
|
|
22
|
+
export interface ListenerState {
|
|
23
|
+
reads: number;
|
|
24
|
+
fsWraps: number;
|
|
25
|
+
sandboxWraps: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Resolve `ctx.sandboxPolicy.resolve()` through a reading context without
|
|
29
|
+
* requiring an injection — `reflect.get` is exactly the non-strict read.
|
|
30
|
+
* @param readCtx - the context whose proxy served the service read.
|
|
31
|
+
* @returns the deployment policy, or undefined when the service is unavailable.
|
|
32
|
+
*/
|
|
33
|
+
export declare function fallbackPolicyOf(readCtx: unknown): PolicyLike | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Install the interception listener on the calling fiber.
|
|
36
|
+
* @param ctx - the plugin context (the listener is disposed with its fiber).
|
|
37
|
+
* @param deps - configuration and logging sources.
|
|
38
|
+
* @returns counters the caller uses for the load-time self-test.
|
|
39
|
+
*/
|
|
40
|
+
export declare function installListener(ctx: ListenerContext, deps: ListenerDeps): ListenerState;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path arithmetic for configured roots. Every root is canonicalised the same
|
|
3
|
+
* way the filesystem service canonicalises a write target — realpath of the
|
|
4
|
+
* deepest EXISTING ancestor plus the remaining suffix — so a not-yet-created
|
|
5
|
+
* directory still compares equal to the path the enforcement layer computes.
|
|
6
|
+
* @module dsh-extra-paths/paths
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Resolve one configured path spelling to an absolute path.
|
|
10
|
+
* @param raw - the configured spelling: absolute, `~`-anchored, or relative.
|
|
11
|
+
* @param workspaceRoot - the session workspace a relative spelling is resolved against.
|
|
12
|
+
* @param home - home directory seam (tests).
|
|
13
|
+
* @returns the absolute path, not yet canonicalised.
|
|
14
|
+
*/
|
|
15
|
+
export declare function expandPath(raw: string, workspaceRoot: string, home?: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Canonical spelling of a configured root. Symlinked ancestors are resolved
|
|
18
|
+
* (so `/tmp` and `/private/tmp` cannot silently fail to match), while a suffix
|
|
19
|
+
* that does not exist yet is appended verbatim.
|
|
20
|
+
* @param path - an absolute path.
|
|
21
|
+
* @returns the canonical spelling.
|
|
22
|
+
*/
|
|
23
|
+
export declare function canonicalizeRoot(path: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Whether a canonical target is a root or lies beneath it. Both sides must
|
|
26
|
+
* already be canonical; containment is then purely lexical, which is why the
|
|
27
|
+
* caller canonicalises before comparing.
|
|
28
|
+
* @param targetKey - canonical write target.
|
|
29
|
+
* @param root - canonical configured root.
|
|
30
|
+
* @returns true for the root itself and every descendant.
|
|
31
|
+
*/
|
|
32
|
+
export declare function isUnder(targetKey: string, root: string): boolean;
|
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
/** Caps that keep one pattern's expansion bounded. */
|
|
27
|
+
export declare const PATTERN_LIMITS: {
|
|
28
|
+
/** Directory entries examined in one expansion. */
|
|
29
|
+
readonly maxDirs: 4096;
|
|
30
|
+
/** Matches one pattern may yield. */
|
|
31
|
+
readonly maxMatches: 256;
|
|
32
|
+
/**
|
|
33
|
+
* `**` levels walked below the anchor. Deliberately small: a repository that
|
|
34
|
+
* keeps its worktrees in `.worktrees` sits one or two levels down, and every
|
|
35
|
+
* extra level multiplies the walk into unrelated source trees. A deeper
|
|
36
|
+
* structure is spelled explicitly, level by level, instead of with `**`.
|
|
37
|
+
*/
|
|
38
|
+
readonly maxDepth: 3;
|
|
39
|
+
};
|
|
40
|
+
/** A parsed pattern. */
|
|
41
|
+
export interface RootPattern {
|
|
42
|
+
/** The configured spelling this came from (for messages and the preview). */
|
|
43
|
+
readonly source: string;
|
|
44
|
+
/** The literal directory the walk starts from (absolute). */
|
|
45
|
+
readonly anchor: string;
|
|
46
|
+
/** Segments after the anchor, each `*`, `**`, or a literal name. */
|
|
47
|
+
readonly segments: readonly string[];
|
|
48
|
+
/** Trailing `..` segments applied to each match. */
|
|
49
|
+
readonly up: number;
|
|
50
|
+
}
|
|
51
|
+
/** One expansion. */
|
|
52
|
+
export interface PatternExpansion {
|
|
53
|
+
/** Matching directories, canonicalised and sorted; empty when capped. */
|
|
54
|
+
readonly matches: readonly string[];
|
|
55
|
+
/** True when a cap was hit: `matches` is empty and the caller must warn. */
|
|
56
|
+
readonly capped: boolean;
|
|
57
|
+
/** Which runaway cap stopped the walk (nothing is granted when set). */
|
|
58
|
+
readonly cap?: 'directories' | 'matches';
|
|
59
|
+
/**
|
|
60
|
+
* The depth bound cut the walk short. NOT a failure: `**` is defined as "up to
|
|
61
|
+
* {@link PATTERN_LIMITS.maxDepth} levels below the anchor", so the matches
|
|
62
|
+
* found within it stand and the caller only mentions it.
|
|
63
|
+
*/
|
|
64
|
+
readonly truncated?: boolean;
|
|
65
|
+
/** Directories examined, for diagnostics. */
|
|
66
|
+
readonly scanned: number;
|
|
67
|
+
}
|
|
68
|
+
/** Whether a spelling is a pattern rather than a literal path. */
|
|
69
|
+
export declare function isPattern(raw: string): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Parse a pattern spelling.
|
|
72
|
+
* @param raw - the configured spelling.
|
|
73
|
+
* @param workspaceRoot - the base a relative anchor resolves against.
|
|
74
|
+
* @param home - the home directory to expand `~` with.
|
|
75
|
+
* @returns the parsed pattern, or undefined when it cannot be walked safely.
|
|
76
|
+
*/
|
|
77
|
+
export declare function parsePattern(raw: string, workspaceRoot: string, home?: string): RootPattern | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* Expand a pattern against the filesystem.
|
|
80
|
+
* @param pattern - the parsed pattern.
|
|
81
|
+
* @param limits - caps to apply (defaults to {@link PATTERN_LIMITS}).
|
|
82
|
+
* @returns the matches, or `{ capped: true }` when a cap was hit.
|
|
83
|
+
*/
|
|
84
|
+
export declare function expandPattern(pattern: RootPattern, limits?: {
|
|
85
|
+
maxDirs: number;
|
|
86
|
+
maxMatches: number;
|
|
87
|
+
maxDepth: number;
|
|
88
|
+
}): PatternExpansion;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-call policy shapes and the translation the fs wrapper performs.
|
|
3
|
+
* @module dsh-extra-paths/policy
|
|
4
|
+
*/
|
|
5
|
+
import type { SandboxModeLike } from './grant.js';
|
|
6
|
+
/** The subset of the fs/sandbox per-call policy this plugin reads and rewrites. */
|
|
7
|
+
export interface PolicyLike {
|
|
8
|
+
readonly mode: SandboxModeLike;
|
|
9
|
+
readonly workspaceRoot: string;
|
|
10
|
+
readonly sessionId?: unknown;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The policy one call is re-stamped with so the base fence accepts a target
|
|
14
|
+
* under a configured root. The mode rises to `workspace-write` because that is
|
|
15
|
+
* this grant's meaning: a single call is allowed to write this root, while the
|
|
16
|
+
* base class keeps owning resolution, atomic publication and the version guard.
|
|
17
|
+
* @param policy - the caller's resolved policy.
|
|
18
|
+
* @param workspaceRoot - the canonical configured root that matched the target.
|
|
19
|
+
* @returns the policy to hand the base implementation.
|
|
20
|
+
*/
|
|
21
|
+
export declare function syntheticPolicy(policy: PolicyLike, workspaceRoot: string): PolicyLike;
|
|
@@ -0,0 +1,77 @@
|
|
|
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 { type ExtraPathsConfig, type RawConfig } from './config.js';
|
|
10
|
+
import { type EntryResolution } from './resolve.js';
|
|
11
|
+
/** The single route this plugin owns. */
|
|
12
|
+
export declare const PREVIEW_PATH = "/extra-paths/resolved";
|
|
13
|
+
/** The most entries one preview request may carry (a settings page sends its rows). */
|
|
14
|
+
export declare const MAX_PREVIEW_ENTRIES = 64;
|
|
15
|
+
/** The preview payload. */
|
|
16
|
+
export interface PreviewResponse {
|
|
17
|
+
readonly workspaceCwd: string;
|
|
18
|
+
/** The host's home directory, so the page can resolve `~` locally too. */
|
|
19
|
+
readonly home: string;
|
|
20
|
+
readonly entries: readonly EntryResolution[];
|
|
21
|
+
readonly effective: readonly string[];
|
|
22
|
+
readonly warnings: readonly string[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Parse the optional `paths` query parameter: the page's UNSAVED rows, so the
|
|
26
|
+
* preview can answer for what the user is typing instead of only for what is
|
|
27
|
+
* already stored.
|
|
28
|
+
* @param raw - the raw query value (a JSON array of strings / entry objects).
|
|
29
|
+
* @returns a raw configuration carrying those entries, or undefined when absent.
|
|
30
|
+
* @throws {Error} when the payload is not a usable array (the caller answers 400).
|
|
31
|
+
*/
|
|
32
|
+
export declare function parseStagedPaths(raw: string | null | undefined): RawConfig | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Resolve a configuration for one workspace.
|
|
35
|
+
* @param config - the stored configuration snapshot.
|
|
36
|
+
* @param workspaceRoot - the workspace the page is asking about.
|
|
37
|
+
* @param staged - the page's unsaved rows, when it sent any: they REPLACE the
|
|
38
|
+
* stored entries so the preview answers for the draft, not for the document.
|
|
39
|
+
* @returns the preview payload.
|
|
40
|
+
* @throws {Error} when no usable workspace was supplied or the staged rows are
|
|
41
|
+
* invalid (the caller answers 400).
|
|
42
|
+
*/
|
|
43
|
+
export declare function buildPreview(config: ExtraPathsConfig, workspaceRoot: string | undefined, staged?: RawConfig | undefined): PreviewResponse;
|
|
44
|
+
/** The route-registration context surface (webServer + connection). */
|
|
45
|
+
export interface PreviewRouteContext {
|
|
46
|
+
webServer: {
|
|
47
|
+
register(route: {
|
|
48
|
+
kind: 'exact';
|
|
49
|
+
path: string;
|
|
50
|
+
handler: (req: IncomingMessageLike, res: ServerResponseLike) => void | Promise<void>;
|
|
51
|
+
}): () => void;
|
|
52
|
+
};
|
|
53
|
+
connection: {
|
|
54
|
+
requestRejection(request: unknown): number | undefined;
|
|
55
|
+
};
|
|
56
|
+
effect(callback: () => () => void, label: string): unknown;
|
|
57
|
+
}
|
|
58
|
+
/** Minimal node:http shapes (the plugin imports no core type for them). */
|
|
59
|
+
export interface IncomingMessageLike {
|
|
60
|
+
readonly method?: string;
|
|
61
|
+
readonly url?: string;
|
|
62
|
+
}
|
|
63
|
+
export interface ServerResponseLike {
|
|
64
|
+
writeHead(status: number, headers?: Record<string, string>): unknown;
|
|
65
|
+
end(body?: string): unknown;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Register the preview route on the calling fiber.
|
|
69
|
+
* Optional capability: if the composition has no web carrier or no Connection
|
|
70
|
+
* service, the caller never invokes this, and enforcement is unaffected.
|
|
71
|
+
* @param ctx - a context that has both `webServer` and `connection`.
|
|
72
|
+
* @param deps - configuration source and warning sink.
|
|
73
|
+
*/
|
|
74
|
+
export declare function registerPreviewRoute(ctx: PreviewRouteContext, deps: {
|
|
75
|
+
readConfig(): ExtraPathsConfig;
|
|
76
|
+
warn(message: string): void;
|
|
77
|
+
}): void;
|
|
@@ -0,0 +1,63 @@
|
|
|
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 type { ExtraPathsConfig, Scope, Surface } from './config.js';
|
|
8
|
+
/** One effective root after canonicalisation and merging. */
|
|
9
|
+
export interface ResolvedRoot {
|
|
10
|
+
/** The configured spelling that first produced this root (for messages). */
|
|
11
|
+
readonly raw: string;
|
|
12
|
+
/** The canonical absolute root. */
|
|
13
|
+
readonly root: string;
|
|
14
|
+
/** The widest scope across every entry that produced this root. */
|
|
15
|
+
readonly scope: Scope;
|
|
16
|
+
/** The union of surfaces across every entry that produced this root. */
|
|
17
|
+
readonly surfaces: readonly Surface[];
|
|
18
|
+
}
|
|
19
|
+
/** Per-entry outcome, in configured order (what the settings preview renders). */
|
|
20
|
+
export interface EntryResolution {
|
|
21
|
+
readonly raw: string;
|
|
22
|
+
readonly resolved: string;
|
|
23
|
+
readonly scope: Scope;
|
|
24
|
+
readonly surfaces: readonly Surface[];
|
|
25
|
+
readonly status: 'ok' | 'missing' | 'rejected';
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* One resolution pass.
|
|
29
|
+
*
|
|
30
|
+
* Contract for consumers:
|
|
31
|
+
* - **Re-resolve per decision, never cache.** The result depends on the
|
|
32
|
+
* filesystem's CURRENT state (existence) and on `$HOME`, so a cached report
|
|
33
|
+
* would freeze an entry inactive — or worse, keep granting a root that moved.
|
|
34
|
+
* The one deliberate exception is a pattern's directory EXPANSION, which is
|
|
35
|
+
* cached for {@link PATTERN_CACHE_MS} because walking a tree on every write
|
|
36
|
+
* would be wasteful; a literal entry is never cached.
|
|
37
|
+
* - **Grants are a union, and the widest ancestor wins.** Nested roots are both
|
|
38
|
+
* kept: a narrower child cannot narrow a broader parent, so a target under the
|
|
39
|
+
* child is granted by whichever root matches first (every root is one the user
|
|
40
|
+
* configured, so this never grants outside the configured set).
|
|
41
|
+
* - A root that exists but is not a directory is still reported `ok`; writes
|
|
42
|
+
* beneath it fail at the filesystem layer (ENOTDIR), not here.
|
|
43
|
+
*/
|
|
44
|
+
export interface ResolveReport {
|
|
45
|
+
readonly roots: readonly ResolvedRoot[];
|
|
46
|
+
readonly entries: readonly EntryResolution[];
|
|
47
|
+
readonly warnings: readonly string[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* How long one pattern's expansion is reused (milliseconds). Long enough that a
|
|
51
|
+
* broad `**` walk costs one hiccup rather than one per five seconds; short enough
|
|
52
|
+
* that a worktree created a moment ago shows up without any manual refresh.
|
|
53
|
+
*/
|
|
54
|
+
export declare const PATTERN_CACHE_MS = 30000;
|
|
55
|
+
/** Drop every cached expansion (a fresh directory should not wait out the TTL). */
|
|
56
|
+
export declare function clearPatternCache(): void;
|
|
57
|
+
/**
|
|
58
|
+
* Resolve every configured entry against one session workspace.
|
|
59
|
+
* @param config - the normalised configuration.
|
|
60
|
+
* @param workspaceRoot - the session workspace a relative entry resolves against.
|
|
61
|
+
* @returns effective roots plus per-entry detail and warnings.
|
|
62
|
+
*/
|
|
63
|
+
export declare function resolveRoots(config: ExtraPathsConfig, workspaceRoot: string): ResolveReport;
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
import type { Scope, Surface } from './config.js';
|
|
9
|
+
/** One configured path as stored in the settings document. */
|
|
10
|
+
export interface ExtraPathsSectionEntry {
|
|
11
|
+
path: string;
|
|
12
|
+
scope?: Scope;
|
|
13
|
+
surfaces?: Surface[];
|
|
14
|
+
}
|
|
15
|
+
/** The `extra-paths` settings section as stored (the schema supplies the defaults). */
|
|
16
|
+
export interface ExtraPathsSection {
|
|
17
|
+
defaultScope?: Scope;
|
|
18
|
+
defaultSurfaces?: Surface[];
|
|
19
|
+
paths?: (string | ExtraPathsSectionEntry)[];
|
|
20
|
+
}
|
|
21
|
+
/** The `extra-paths` namespace value. */
|
|
22
|
+
export declare const extraPathsSchema: z<ExtraPathsSection>;
|
|
23
|
+
/**
|
|
24
|
+
* The same section for 0.2.x, where a plugin's settings ARE its exported
|
|
25
|
+
* `Config` and the framework's settings form only describes `volatile()` fields:
|
|
26
|
+
* a schema without one yields no descriptor at all, so all three fields are
|
|
27
|
+
* volatile here. `volatile()` wraps a field in a value holder (`get()`), and the
|
|
28
|
+
* host half re-reads those per enforcement decision — that is what makes an edit
|
|
29
|
+
* in the settings form apply without a restart.
|
|
30
|
+
*
|
|
31
|
+
* Kept separate from {@link extraPathsSchema} because the 0.1.5 settings service
|
|
32
|
+
* consumes plain values, not volatile wrappers.
|
|
33
|
+
*/
|
|
34
|
+
export declare const extraPathsConfigSchema: z<Schemastery.ObjectS<NoInfer<{
|
|
35
|
+
defaultScope: z<Scope, Scope, "defined">;
|
|
36
|
+
defaultSurfaces: z<Surface[], Surface[], "defined">;
|
|
37
|
+
paths: z<(string | ExtraPathsSectionEntry)[], (string | ExtraPathsSectionEntry)[], "defined">;
|
|
38
|
+
}>>, Schemastery.ObjectT<NoInfer<{
|
|
39
|
+
defaultScope: z<Scope, Scope, "defined">;
|
|
40
|
+
defaultSurfaces: z<Surface[], Surface[], "defined">;
|
|
41
|
+
paths: z<(string | ExtraPathsSectionEntry)[], (string | ExtraPathsSectionEntry)[], "defined">;
|
|
42
|
+
}>>, "plain">;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The filesystem half of the plugin: a transparent Proxy over `ctx.fs` that
|
|
3
|
+
* re-stamps ONE call's policy when its target lies under a configured root.
|
|
4
|
+
*
|
|
5
|
+
* Transparency rules (verified against cordis 4.0.2 by
|
|
6
|
+
* spike/cordis-get-wrap-baseline.mjs): forward every property with the inner
|
|
7
|
+
* value as the receiver, bind methods to the inner instance — except
|
|
8
|
+
* `constructor`, whose binding breaks the framework's own `instanceof`
|
|
9
|
+
* (`Service[Symbol.hasInstance]` walks `instance.constructor`).
|
|
10
|
+
* @module dsh-extra-paths/wrap-fs
|
|
11
|
+
*/
|
|
12
|
+
import type { ExtraPathsConfig } from './config.js';
|
|
13
|
+
import { type PolicyLike } from './policy.js';
|
|
14
|
+
/** A resolved filesystem target (the fs service's own shape). */
|
|
15
|
+
export interface FsTargetLike {
|
|
16
|
+
readonly targetKey: unknown;
|
|
17
|
+
readonly displayPath: string;
|
|
18
|
+
}
|
|
19
|
+
/** The subset of the filesystem service this wrapper intercepts. */
|
|
20
|
+
export interface FsInnerLike {
|
|
21
|
+
resolve(path: string, opts?: {
|
|
22
|
+
cwd?: string;
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
}): Promise<FsTargetLike>;
|
|
25
|
+
writeText(target: FsTargetLike, content: string, expected?: unknown, signal?: AbortSignal, policy?: PolicyLike): Promise<unknown>;
|
|
26
|
+
editText(target: FsTargetLike, edit: unknown, expected?: unknown, signal?: AbortSignal, policy?: PolicyLike): Promise<unknown>;
|
|
27
|
+
readonly sandboxMode?: string;
|
|
28
|
+
}
|
|
29
|
+
/** What the wrapper needs from the plugin. */
|
|
30
|
+
export interface FsWrapDeps {
|
|
31
|
+
/** Live configuration: re-read on EVERY call, never captured at wrap time. */
|
|
32
|
+
readConfig(): ExtraPathsConfig;
|
|
33
|
+
/** Deployment policy for a caller that stamped none; resolved per call. */
|
|
34
|
+
fallbackPolicy(): PolicyLike | undefined;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Whether a service is the sandboxed filesystem: mutating methods plus the
|
|
38
|
+
* capability fact (`sandboxMode`) that only a confining backend exposes.
|
|
39
|
+
* A plain local filesystem is left unwrapped — nothing confines it.
|
|
40
|
+
* @param value - the service read from the context.
|
|
41
|
+
* @returns true when the wrapper applies.
|
|
42
|
+
*/
|
|
43
|
+
export declare function isConfiningFs(value: unknown): value is FsInnerLike;
|
|
44
|
+
/**
|
|
45
|
+
* Wrap one filesystem service.
|
|
46
|
+
* @param inner - the service instance read from the context.
|
|
47
|
+
* @param deps - configuration and policy sources.
|
|
48
|
+
* @returns a transparent proxy that grants configured roots on mutation.
|
|
49
|
+
*/
|
|
50
|
+
export declare function wrapFs(inner: FsInnerLike, deps: FsWrapDeps): FsInnerLike;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The subprocess half of the plugin: a transparent Proxy over `ctx.sandbox`
|
|
3
|
+
* that appends one write grant per configured root to the argv the base
|
|
4
|
+
* provider already wrapped. An unrecognised runner dialect fails closed: the
|
|
5
|
+
* argv is returned untouched (the write stays denied) and a warning is logged.
|
|
6
|
+
*
|
|
7
|
+
* THE WRAPPER MIRRORS THE INNER PROVIDER'S SYNC-NESS, because that changed
|
|
8
|
+
* between host generations and both must work:
|
|
9
|
+
*
|
|
10
|
+
* - 0.1.5 returns the confinement record SYNCHRONOUSLY and its callers read
|
|
11
|
+
* `.argv` off the result without awaiting
|
|
12
|
+
* (`return sandbox.confine(argv, policy).argv`). An `async` wrapper there
|
|
13
|
+
* yields `undefined` and every confined process dies with "Cannot read
|
|
14
|
+
* properties of undefined (reading '0')".
|
|
15
|
+
* - 0.2.x declares `confine(argv, policy, signal): Promise<ConfinedArgv>` and
|
|
16
|
+
* every caller awaits it.
|
|
17
|
+
*
|
|
18
|
+
* So a synchronous result is widened synchronously, and a thenable result is
|
|
19
|
+
* widened in a continuation instead of being forced through `async` — the same
|
|
20
|
+
* code satisfies a caller that awaits and one that does not.
|
|
21
|
+
*
|
|
22
|
+
* A dialect the wrapper does not recognise (`windows-acl`, a remote
|
|
23
|
+
* `sandbox-ssh` runner) also fails closed, as does an unknown one.
|
|
24
|
+
* @module dsh-extra-paths/wrap-sandbox
|
|
25
|
+
*/
|
|
26
|
+
import type { ExtraPathsConfig } from './config.js';
|
|
27
|
+
import type { PolicyLike } from './policy.js';
|
|
28
|
+
/** The base provider's confinement result (the fields this plugin preserves verbatim). */
|
|
29
|
+
export interface ConfinedArgvLike {
|
|
30
|
+
readonly argv: readonly string[];
|
|
31
|
+
readonly enforcement: unknown;
|
|
32
|
+
readonly denialSignatures: readonly string[];
|
|
33
|
+
readonly runnerFailureRules: readonly unknown[];
|
|
34
|
+
}
|
|
35
|
+
/** The subset of the sandbox provider this wrapper intercepts. */
|
|
36
|
+
export interface SandboxInnerLike {
|
|
37
|
+
confine(argv: readonly string[], policy: PolicyLike, signal?: AbortSignal): ConfinedArgvLike | Promise<ConfinedArgvLike>;
|
|
38
|
+
}
|
|
39
|
+
/** What the wrapper needs from the plugin. */
|
|
40
|
+
export interface SandboxWrapDeps {
|
|
41
|
+
readConfig(): ExtraPathsConfig;
|
|
42
|
+
warn(message: string): void;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Whether a service is a process-sandbox provider.
|
|
46
|
+
*
|
|
47
|
+
* Only `confine` is probed: it is the provider's whole public surface, the
|
|
48
|
+
* abstract base declares it, and every concrete runner implements it. A false
|
|
49
|
+
* positive could only wrap a service that already answers `confine`.
|
|
50
|
+
* @param value - the service read from the context.
|
|
51
|
+
* @returns true when the value looks like a sandbox provider.
|
|
52
|
+
*/
|
|
53
|
+
export declare function isConfiningSandbox(value: unknown): value is SandboxInnerLike;
|
|
54
|
+
/**
|
|
55
|
+
* Wrap one sandbox provider.
|
|
56
|
+
* @param inner - the provider read from the context.
|
|
57
|
+
* @param deps - configuration source and warning sink.
|
|
58
|
+
* @returns a transparent proxy that widens profiles for configured roots.
|
|
59
|
+
*/
|
|
60
|
+
export declare function wrapSandbox(inner: SandboxInnerLike, deps: SandboxWrapDeps): SandboxInnerLike;
|