@hop-top/kit 0.5.0-alpha.0 → 0.5.0-alpha.2

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 (100) hide show
  1. package/CHANGELOG.md +98 -0
  2. package/README.md +237 -9
  3. package/dist/aim-CTp-kJW2.d.ts +139 -0
  4. package/dist/aim.d.ts +1 -116
  5. package/dist/alias-dhhr08Ei.d.ts +88 -0
  6. package/dist/alias.d.ts +2 -73
  7. package/dist/api-miiso81x.d.ts +77 -0
  8. package/dist/api.d.ts +1 -62
  9. package/dist/auth-2-jfgiHn.d.ts +34 -0
  10. package/dist/auth.d.ts +1 -26
  11. package/dist/cli-DgOEOsPB.d.ts +450 -0
  12. package/dist/cli.d.ts +5 -309
  13. package/dist/cli.js +250 -62
  14. package/dist/config-BUY7_W2n.d.ts +103 -0
  15. package/dist/config.d.ts +1 -97
  16. package/dist/errcorrect-BcX1Ft0K.d.ts +44 -0
  17. package/dist/errcorrect.d.ts +1 -37
  18. package/dist/id/index.d.ts +2 -83
  19. package/dist/index--C7Mtsmm.d.ts +328 -0
  20. package/dist/index-C3Zw4wDJ.d.ts +359 -0
  21. package/dist/index-MLrRDvEG.d.ts +1073 -0
  22. package/dist/index-QSffbLnj.d.ts +94 -0
  23. package/dist/index.d.ts +26 -0
  24. package/dist/index.js +5863 -0
  25. package/dist/llm-B5XUWH8T.d.ts +231 -0
  26. package/dist/llm.d.ts +1 -188
  27. package/dist/mcp/index.d.ts +2 -0
  28. package/dist/mcp/index.js +1453 -0
  29. package/dist/netpolicy-asvCfwi8.d.ts +138 -0
  30. package/dist/netpolicy.d.ts +1 -0
  31. package/dist/netpolicy.js +118 -0
  32. package/dist/output-VFFLqor9.d.ts +521 -0
  33. package/dist/output.d.ts +2 -213
  34. package/dist/output.js +554 -43
  35. package/dist/progress-CAzyxeWl.d.ts +38 -0
  36. package/dist/progress.d.ts +1 -30
  37. package/dist/provenance-SMFHm5gx.d.ts +30 -0
  38. package/dist/provenance.d.ts +1 -24
  39. package/dist/routellm-PGSt2D1y.d.ts +75 -0
  40. package/dist/routellm.d.ts +2 -64
  41. package/dist/rpc-D5xLEf8V.d.ts +32 -0
  42. package/dist/rpc.d.ts +2 -25
  43. package/dist/safety-CUaYEjZc.d.ts +30 -0
  44. package/dist/safety.d.ts +1 -24
  45. package/dist/scope-BrhYB4ij.d.ts +141 -0
  46. package/dist/scope.d.ts +1 -121
  47. package/dist/stream-CrjeCp0M.d.ts +44 -0
  48. package/dist/stream.d.ts +1 -35
  49. package/dist/telemetry/index.d.ts +1 -315
  50. package/dist/telemetry/index.js +12 -1
  51. package/dist/tui/index.d.ts +4 -298
  52. package/dist/tui/index.js +61 -9
  53. package/dist/upgrade-p_zh3pvV.d.ts +102 -0
  54. package/dist/upgrade.d.ts +1 -95
  55. package/dist/xdg-DB7Shoib.d.ts +179 -0
  56. package/dist/xdg.d.ts +1 -169
  57. package/package.json +65 -25
  58. package/src/cli.offline.test.ts +93 -0
  59. package/src/cli.parity.test.ts +192 -0
  60. package/src/cli.ts +112 -12
  61. package/src/index.test.ts +58 -0
  62. package/src/index.ts +36 -0
  63. package/src/log.parity.test.ts +105 -0
  64. package/src/log.ts +64 -13
  65. package/src/mcp/bridge.test.ts +150 -0
  66. package/src/mcp/bridge.ts +246 -0
  67. package/src/mcp/conformance.test.ts +336 -0
  68. package/src/mcp/dispatch.ts +313 -0
  69. package/src/mcp/index.ts +138 -0
  70. package/src/mcp/legacy.ts +314 -0
  71. package/src/mcp/mcp.test.ts +697 -0
  72. package/src/mcp/modern-confirm.test.ts +520 -0
  73. package/src/mcp/modern-confirm.ts +452 -0
  74. package/src/mcp/modern.ts +723 -0
  75. package/src/mcp/tasks.ts +82 -0
  76. package/src/mcp/testtree.ts +250 -0
  77. package/src/mcp/types.ts +504 -0
  78. package/src/netpolicy.test.ts +202 -0
  79. package/src/netpolicy.ts +231 -0
  80. package/src/output/dispatch.ts +10 -2
  81. package/src/output/error.ts +293 -0
  82. package/src/output/formatter.ts +29 -5
  83. package/src/output/formatters/csv.ts +48 -12
  84. package/src/output/formatters/json.ts +4 -25
  85. package/src/output/formatters/project.ts +34 -0
  86. package/src/output/formatters/table.ts +8 -6
  87. package/src/output/formatters/text.ts +7 -3
  88. package/src/output/formatters/yaml.ts +5 -22
  89. package/src/output/projection.test.ts +298 -0
  90. package/src/output/projection.ts +33 -59
  91. package/src/output/template.ts +11 -21
  92. package/src/output.surface.test.ts +41 -0
  93. package/src/output.ts +39 -3
  94. package/src/telemetry/client.test.ts +31 -0
  95. package/src/telemetry/client.ts +7 -1
  96. package/src/telemetry/offline.test.ts +64 -0
  97. package/src/tui/parity.test.ts +142 -0
  98. package/src/tui/parity.ts +59 -13
  99. package/test/output/csv.test.ts +164 -0
  100. package/test/output/error.test.ts +241 -0
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @module progress
3
+ * @package @hop-top/kit
4
+ *
5
+ * Factor 9 — Observable Long-Running Operations.
6
+ *
7
+ * Emits structured progress events (JSON in non-TTY,
8
+ * human-readable in TTY).
9
+ */
10
+ interface ProgressEvent {
11
+ phase: string;
12
+ step: string;
13
+ current: number;
14
+ total: number;
15
+ percent: number;
16
+ message?: string;
17
+ }
18
+ interface JobHandle {
19
+ id: string;
20
+ status: 'running' | 'completed' | 'failed' | 'cancelled';
21
+ }
22
+ declare class ProgressReporter {
23
+ private w;
24
+ private tty;
25
+ constructor(w: NodeJS.WritableStream, isTTY: boolean);
26
+ emit(event: ProgressEvent): void;
27
+ done(message: string): void;
28
+ }
29
+
30
+ type progress_JobHandle = JobHandle;
31
+ type progress_ProgressEvent = ProgressEvent;
32
+ type progress_ProgressReporter = ProgressReporter;
33
+ declare const progress_ProgressReporter: typeof ProgressReporter;
34
+ declare namespace progress {
35
+ export { type progress_JobHandle as JobHandle, type progress_ProgressEvent as ProgressEvent, progress_ProgressReporter as ProgressReporter };
36
+ }
37
+
38
+ export { type JobHandle as J, type ProgressEvent as P, ProgressReporter as a, progress as p };
@@ -1,30 +1 @@
1
- /**
2
- * @module progress
3
- * @package @hop-top/kit
4
- *
5
- * Factor 9 — Observable Long-Running Operations.
6
- *
7
- * Emits structured progress events (JSON in non-TTY,
8
- * human-readable in TTY).
9
- */
10
- interface ProgressEvent {
11
- phase: string;
12
- step: string;
13
- current: number;
14
- total: number;
15
- percent: number;
16
- message?: string;
17
- }
18
- interface JobHandle {
19
- id: string;
20
- status: 'running' | 'completed' | 'failed' | 'cancelled';
21
- }
22
- declare class ProgressReporter {
23
- private w;
24
- private tty;
25
- constructor(w: NodeJS.WritableStream, isTTY: boolean);
26
- emit(event: ProgressEvent): void;
27
- done(message: string): void;
28
- }
29
-
30
- export { type JobHandle, type ProgressEvent, ProgressReporter };
1
+ export { J as JobHandle, P as ProgressEvent, a as ProgressReporter } from './progress-CAzyxeWl.js';
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @module provenance
3
+ * @package @hop-top/kit
4
+ *
5
+ * Factor 11 — Provenance.
6
+ *
7
+ * Attaches origin metadata to any data payload for JSON output,
8
+ * enabling consumers to verify source, timing, and method.
9
+ */
10
+ interface Provenance {
11
+ source: string;
12
+ /** ISO 8601 timestamp */
13
+ timestamp: string;
14
+ method: string;
15
+ }
16
+ /**
17
+ * Wraps `data` with provenance metadata under `_meta`.
18
+ */
19
+ declare function withProvenance<T>(data: T, p: Provenance): {
20
+ data: T;
21
+ _meta: Provenance;
22
+ };
23
+
24
+ type provenance_Provenance = Provenance;
25
+ declare const provenance_withProvenance: typeof withProvenance;
26
+ declare namespace provenance {
27
+ export { type provenance_Provenance as Provenance, provenance_withProvenance as withProvenance };
28
+ }
29
+
30
+ export { type Provenance as P, provenance as p, withProvenance as w };
@@ -1,24 +1 @@
1
- /**
2
- * @module provenance
3
- * @package @hop-top/kit
4
- *
5
- * Factor 11 — Provenance.
6
- *
7
- * Attaches origin metadata to any data payload for JSON output,
8
- * enabling consumers to verify source, timing, and method.
9
- */
10
- interface Provenance {
11
- source: string;
12
- /** ISO 8601 timestamp */
13
- timestamp: string;
14
- method: string;
15
- }
16
- /**
17
- * Wraps `data` with provenance metadata under `_meta`.
18
- */
19
- declare function withProvenance<T>(data: T, p: Provenance): {
20
- data: T;
21
- _meta: Provenance;
22
- };
23
-
24
- export { type Provenance, withProvenance };
1
+ export { P as Provenance, w as withProvenance } from './provenance-SMFHm5gx.js';
@@ -0,0 +1,75 @@
1
+ import { c as Completer, S as Streamer, i as ResolvedConfig, h as Request, j as Response, T as Token } from './llm-B5XUWH8T.js';
2
+
3
+ /**
4
+ * @packageDocumentation
5
+ *
6
+ * RouteLLM adapter — registers the `routellm` URI scheme.
7
+ *
8
+ * URI format: `routellm://router_name:threshold` (e.g. `routellm://mf:0.7`).
9
+ *
10
+ * Delegates HTTP completions to an OpenAI-compatible endpoint on the
11
+ * RouteLLM server, translating the model field into the server's
12
+ * expected `router-[name]-[threshold]` format.
13
+ */
14
+
15
+ interface EvaConfig {
16
+ contracts: string[];
17
+ enforce: boolean;
18
+ }
19
+ interface RouterConfig {
20
+ baseUrl: string;
21
+ grpcPort: number;
22
+ strongModel: string;
23
+ weakModel: string;
24
+ routers: string[];
25
+ routerConfig: Record<string, unknown>;
26
+ eva: EvaConfig;
27
+ autostart: boolean;
28
+ }
29
+ /**
30
+ * Extract and validate RouteLLM configuration from provider extras.
31
+ * Environment variables override all other sources.
32
+ */
33
+ declare function parseRouterConfig(extras?: Record<string, unknown>): RouterConfig;
34
+ interface ParsedModel {
35
+ routerName: string;
36
+ threshold: number;
37
+ }
38
+ /**
39
+ * Split a model string of the form `router_name:threshold` into its
40
+ * components.
41
+ */
42
+ declare function parseModelField(model: string): ParsedModel;
43
+ /**
44
+ * RouteLLM adapter implementing Completer and Streamer.
45
+ *
46
+ * Delegates to an OpenAI-compatible HTTP endpoint on the RouteLLM
47
+ * server using the standard fetch API.
48
+ */
49
+ declare class RouteLLMAdapter implements Completer, Streamer {
50
+ readonly config: RouterConfig;
51
+ readonly routerName: string;
52
+ readonly threshold: number;
53
+ private readonly _baseUrl;
54
+ private readonly _serverModel;
55
+ private readonly _apiKey;
56
+ constructor(cfg: ResolvedConfig);
57
+ complete(req: Request): Promise<Response>;
58
+ stream(req: Request): AsyncGenerator<Token>;
59
+ close(): void;
60
+ private _buildBody;
61
+ private _post;
62
+ }
63
+
64
+ type routellm_EvaConfig = EvaConfig;
65
+ type routellm_ParsedModel = ParsedModel;
66
+ type routellm_RouteLLMAdapter = RouteLLMAdapter;
67
+ declare const routellm_RouteLLMAdapter: typeof RouteLLMAdapter;
68
+ type routellm_RouterConfig = RouterConfig;
69
+ declare const routellm_parseModelField: typeof parseModelField;
70
+ declare const routellm_parseRouterConfig: typeof parseRouterConfig;
71
+ declare namespace routellm {
72
+ export { type routellm_EvaConfig as EvaConfig, type routellm_ParsedModel as ParsedModel, routellm_RouteLLMAdapter as RouteLLMAdapter, type routellm_RouterConfig as RouterConfig, routellm_parseModelField as parseModelField, routellm_parseRouterConfig as parseRouterConfig };
73
+ }
74
+
75
+ export { type EvaConfig as E, type ParsedModel as P, RouteLLMAdapter as R, type RouterConfig as a, parseRouterConfig as b, parseModelField as p, routellm as r };
@@ -1,64 +1,2 @@
1
- import { Completer, Streamer, ResolvedConfig, Request, Response, Token } from './llm.js';
2
-
3
- /**
4
- * @packageDocumentation
5
- *
6
- * RouteLLM adapter — registers the `routellm` URI scheme.
7
- *
8
- * URI format: `routellm://router_name:threshold` (e.g. `routellm://mf:0.7`).
9
- *
10
- * Delegates HTTP completions to an OpenAI-compatible endpoint on the
11
- * RouteLLM server, translating the model field into the server's
12
- * expected `router-[name]-[threshold]` format.
13
- */
14
-
15
- interface EvaConfig {
16
- contracts: string[];
17
- enforce: boolean;
18
- }
19
- interface RouterConfig {
20
- baseUrl: string;
21
- grpcPort: number;
22
- strongModel: string;
23
- weakModel: string;
24
- routers: string[];
25
- routerConfig: Record<string, unknown>;
26
- eva: EvaConfig;
27
- autostart: boolean;
28
- }
29
- /**
30
- * Extract and validate RouteLLM configuration from provider extras.
31
- * Environment variables override all other sources.
32
- */
33
- declare function parseRouterConfig(extras?: Record<string, unknown>): RouterConfig;
34
- interface ParsedModel {
35
- routerName: string;
36
- threshold: number;
37
- }
38
- /**
39
- * Split a model string of the form `router_name:threshold` into its
40
- * components.
41
- */
42
- declare function parseModelField(model: string): ParsedModel;
43
- /**
44
- * RouteLLM adapter implementing Completer and Streamer.
45
- *
46
- * Delegates to an OpenAI-compatible HTTP endpoint on the RouteLLM
47
- * server using the standard fetch API.
48
- */
49
- declare class RouteLLMAdapter implements Completer, Streamer {
50
- readonly config: RouterConfig;
51
- readonly routerName: string;
52
- readonly threshold: number;
53
- private readonly _baseUrl;
54
- private readonly _serverModel;
55
- private readonly _apiKey;
56
- constructor(cfg: ResolvedConfig);
57
- complete(req: Request): Promise<Response>;
58
- stream(req: Request): AsyncGenerator<Token>;
59
- close(): void;
60
- private _buildBody;
61
- private _post;
62
- }
63
-
64
- export { type EvaConfig, type ParsedModel, RouteLLMAdapter, type RouterConfig, parseModelField, parseRouterConfig };
1
+ import './llm-B5XUWH8T.js';
2
+ export { E as EvaConfig, P as ParsedModel, R as RouteLLMAdapter, a as RouterConfig, p as parseModelField, b as parseRouterConfig } from './routellm-PGSt2D1y.js';
@@ -0,0 +1,32 @@
1
+ import { E as Entity, Q as Query } from './api-miiso81x.js';
2
+
3
+ /**
4
+ * Typed ConnectRPC client for kit EntityService.
5
+ *
6
+ * Thin wrapper over generated Connect stubs, mapping between
7
+ * JS objects and protobuf Struct (JSON intermediate).
8
+ */
9
+
10
+ interface RPCClientOptions {
11
+ baseURL: string;
12
+ auth?: string;
13
+ }
14
+ declare class RPCClient<T extends Entity> {
15
+ private client;
16
+ private auth?;
17
+ constructor(opts: RPCClientOptions);
18
+ create(entity: Omit<T, "id"> | T): Promise<T>;
19
+ get(id: string): Promise<T>;
20
+ list(q?: Query): Promise<T[]>;
21
+ update(entity: T): Promise<T>;
22
+ delete(id: string): Promise<void>;
23
+ }
24
+
25
+ type rpc_RPCClient<T extends Entity> = RPCClient<T>;
26
+ declare const rpc_RPCClient: typeof RPCClient;
27
+ type rpc_RPCClientOptions = RPCClientOptions;
28
+ declare namespace rpc {
29
+ export { rpc_RPCClient as RPCClient, type rpc_RPCClientOptions as RPCClientOptions };
30
+ }
31
+
32
+ export { RPCClient as R, type RPCClientOptions as a, rpc as r };
package/dist/rpc.d.ts CHANGED
@@ -1,25 +1,2 @@
1
- import { Entity, Query } from './api.js';
2
-
3
- /**
4
- * Typed ConnectRPC client for kit EntityService.
5
- *
6
- * Thin wrapper over generated Connect stubs, mapping between
7
- * JS objects and protobuf Struct (JSON intermediate).
8
- */
9
-
10
- interface RPCClientOptions {
11
- baseURL: string;
12
- auth?: string;
13
- }
14
- declare class RPCClient<T extends Entity> {
15
- private client;
16
- private auth?;
17
- constructor(opts: RPCClientOptions);
18
- create(entity: Omit<T, "id"> | T): Promise<T>;
19
- get(id: string): Promise<T>;
20
- list(q?: Query): Promise<T[]>;
21
- update(entity: T): Promise<T>;
22
- delete(id: string): Promise<void>;
23
- }
24
-
25
- export { RPCClient, type RPCClientOptions };
1
+ import './api-miiso81x.js';
2
+ export { R as RPCClient, a as RPCClientOptions } from './rpc-D5xLEf8V.js';
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @module safety
3
+ * @package @hop-top/kit
4
+ *
5
+ * Factor 10 — Delegation Safety.
6
+ *
7
+ * Guards destructive operations behind --force, with stricter
8
+ * requirements in non-TTY (scripted/agent) contexts.
9
+ */
10
+ type SafetyLevel = 'read' | 'caution' | 'dangerous';
11
+ /**
12
+ * Validates that the current context permits the requested safety level.
13
+ *
14
+ * - `read`: always passes
15
+ * - `caution`: passes in TTY; requires `--force` in non-TTY
16
+ * - `dangerous`: always requires `--force`
17
+ *
18
+ * @throws {Error} when guard fails, with message referencing --force
19
+ */
20
+ declare function safetyGuard(level: SafetyLevel, opts?: {
21
+ force?: boolean;
22
+ }): void;
23
+
24
+ type safety_SafetyLevel = SafetyLevel;
25
+ declare const safety_safetyGuard: typeof safetyGuard;
26
+ declare namespace safety {
27
+ export { type safety_SafetyLevel as SafetyLevel, safety_safetyGuard as safetyGuard };
28
+ }
29
+
30
+ export { type SafetyLevel as S, safetyGuard as a, safety as s };
package/dist/safety.d.ts CHANGED
@@ -1,24 +1 @@
1
- /**
2
- * @module safety
3
- * @package @hop-top/kit
4
- *
5
- * Factor 10 — Delegation Safety.
6
- *
7
- * Guards destructive operations behind --force, with stricter
8
- * requirements in non-TTY (scripted/agent) contexts.
9
- */
10
- type SafetyLevel = 'read' | 'caution' | 'dangerous';
11
- /**
12
- * Validates that the current context permits the requested safety level.
13
- *
14
- * - `read`: always passes
15
- * - `caution`: passes in TTY; requires `--force` in non-TTY
16
- * - `dangerous`: always requires `--force`
17
- *
18
- * @throws {Error} when guard fails, with message referencing --force
19
- */
20
- declare function safetyGuard(level: SafetyLevel, opts?: {
21
- force?: boolean;
22
- }): void;
23
-
24
- export { type SafetyLevel, safetyGuard };
1
+ export { S as SafetyLevel, a as safetyGuard } from './safety-CUaYEjZc.js';
@@ -0,0 +1,141 @@
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * Filesystem path policy guardrails — TypeScript port of `hop.top/kit/go/core/scope`.
5
+ *
6
+ * Mirrors the Go API surface (`New`, `Default`, `Allow`, `Deny`, `Check`,
7
+ * `Enforce`, `SetMode`, `SetDefault`, `Snapshot`, `SecretPaths`). The default
8
+ * deny list is loaded from `contracts/parity/scope-defaults.json` (the
9
+ * cross-language source of truth).
10
+ *
11
+ * Glob matching uses [`picomatch`](https://github.com/micromatch/picomatch)
12
+ * which supports the subset of bash-style globs (including `**`) that the Go
13
+ * port relies on via `bmatcuk/doublestar/v4`.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { Default, Op, Strict } from '@hop-top/kit/scope';
18
+ *
19
+ * const dec = Default().check('/Users/me/.ssh/id_rsa', Op.Read);
20
+ * // -> Decision.Denied
21
+ * ```
22
+ */
23
+ /** Mode controls how `Enforce` reacts to a `Denied` decision. */
24
+ declare enum Mode {
25
+ /** Strict denies → throws `ErrDenied`. The default. */
26
+ Strict = "strict",
27
+ /** Warn denies → logs to stderr and returns. */
28
+ Warn = "warn",
29
+ /** Prompt denies → invokes the prompt callback. */
30
+ Prompt = "prompt"
31
+ }
32
+ /** Op is a bitset of filesystem operations. */
33
+ declare enum Op {
34
+ Read = 1,
35
+ Write = 2,
36
+ Exec = 4
37
+ }
38
+ /** Decision is the outcome of `Check`. */
39
+ declare enum Decision {
40
+ Unknown = "unknown",
41
+ Allowed = "allowed",
42
+ Denied = "denied"
43
+ }
44
+ /** A single rule: glob patterns + ops bitset + allow/deny verdict. */
45
+ interface Rule {
46
+ patterns: string[];
47
+ ops: Op;
48
+ allow: boolean;
49
+ }
50
+ /** Prompt callback used in `Mode.Prompt`. Return `true` to allow this call. */
51
+ type PromptFunc = (path: string, op: Op) => boolean;
52
+ /** Error thrown by `Enforce` when a path is denied. */
53
+ declare class ErrDenied extends Error {
54
+ constructor(p: string, op: Op);
55
+ }
56
+ /**
57
+ * Policy holds an ordered list of rules, a Mode, and an optional prompt
58
+ * callback. Construct via `New()` or `Default()`.
59
+ */
60
+ declare class Policy {
61
+ private rules;
62
+ private mode;
63
+ private prompt?;
64
+ /** Register an allow rule covering Read|Write|Exec. */
65
+ allow(...patterns: string[]): this;
66
+ /** Register an allow rule for the given operations. */
67
+ allowOp(op: Op, ...patterns: string[]): this;
68
+ /** Register a deny rule covering Read|Write|Exec. */
69
+ deny(...patterns: string[]): this;
70
+ /** Register a deny rule for the given operations. */
71
+ denyOp(op: Op, ...patterns: string[]): this;
72
+ /** Set the enforcement mode. */
73
+ setMode(m: Mode): this;
74
+ /** Get the current enforcement mode. */
75
+ getMode(): Mode;
76
+ /** Set the prompt callback used in `Mode.Prompt`. */
77
+ setPromptFunc(fn: PromptFunc): this;
78
+ /** Defensive copy of the policy's rules in registration order. */
79
+ getRules(): Rule[];
80
+ /**
81
+ * Evaluate `(p, op)` against the policy. Pure — no prompt, no mutation.
82
+ * Resolves symlinks before matching to defeat symlink escapes; on ENOENT
83
+ * the cleaned path is used so "intent to write" still matches deny rules.
84
+ */
85
+ check(p: string, op: Op): Decision;
86
+ /**
87
+ * Enforce calls `check` and translates the decision according to mode:
88
+ * Strict + (Denied|Unknown) throws; Warn + Denied logs; Prompt + Denied
89
+ * invokes the prompt callback.
90
+ */
91
+ enforce(p: string, op: Op): void;
92
+ private handleDeny;
93
+ /** Deep copy. Useful for per-test isolation paired with `setDefault`. */
94
+ snapshot(): Policy;
95
+ }
96
+ /** Create an empty `Policy` in `Mode.Strict`. */
97
+ declare function New(): Policy;
98
+ /**
99
+ * Returns the package-level singleton policy used by primitives that don't
100
+ * accept an explicit policy. Lazy-initialised on first call. The singleton is
101
+ * pre-seeded with `SecretPaths()` as a deny-all-ops rule.
102
+ */
103
+ declare function Default(): Policy;
104
+ /**
105
+ * Swap the package-level singleton with `p`. Returns a restore function that
106
+ * puts the previous policy back. Intended for tests:
107
+ *
108
+ * ```ts
109
+ * const restore = setDefault(New().allow('~/tmp/**'));
110
+ * try { ... } finally { restore(); }
111
+ * ```
112
+ */
113
+ declare function setDefault(p: Policy): () => void;
114
+ /**
115
+ * Returns the default deny pattern set: common patterns plus the patterns
116
+ * specific to the current platform. Patterns are ready to feed into
117
+ * `Policy.deny`. `~` and Windows env macros are resolved at match time.
118
+ */
119
+ declare function SecretPaths(): string[];
120
+
121
+ type scope_Decision = Decision;
122
+ declare const scope_Decision: typeof Decision;
123
+ declare const scope_Default: typeof Default;
124
+ type scope_ErrDenied = ErrDenied;
125
+ declare const scope_ErrDenied: typeof ErrDenied;
126
+ type scope_Mode = Mode;
127
+ declare const scope_Mode: typeof Mode;
128
+ declare const scope_New: typeof New;
129
+ type scope_Op = Op;
130
+ declare const scope_Op: typeof Op;
131
+ type scope_Policy = Policy;
132
+ declare const scope_Policy: typeof Policy;
133
+ type scope_PromptFunc = PromptFunc;
134
+ type scope_Rule = Rule;
135
+ declare const scope_SecretPaths: typeof SecretPaths;
136
+ declare const scope_setDefault: typeof setDefault;
137
+ declare namespace scope {
138
+ export { scope_Decision as Decision, scope_Default as Default, scope_ErrDenied as ErrDenied, scope_Mode as Mode, scope_New as New, scope_Op as Op, scope_Policy as Policy, type scope_PromptFunc as PromptFunc, type scope_Rule as Rule, scope_SecretPaths as SecretPaths, scope_setDefault as setDefault };
139
+ }
140
+
141
+ export { Decision as D, ErrDenied as E, Mode as M, New as N, Op as O, Policy as P, type Rule as R, SecretPaths as S, Default as a, type PromptFunc as b, setDefault as c, scope as s };
package/dist/scope.d.ts CHANGED
@@ -1,121 +1 @@
1
- /**
2
- * @packageDocumentation
3
- *
4
- * Filesystem path policy guardrails — TypeScript port of `hop.top/kit/go/core/scope`.
5
- *
6
- * Mirrors the Go API surface (`New`, `Default`, `Allow`, `Deny`, `Check`,
7
- * `Enforce`, `SetMode`, `SetDefault`, `Snapshot`, `SecretPaths`). The default
8
- * deny list is loaded from `contracts/parity/scope-defaults.json` (the
9
- * cross-language source of truth).
10
- *
11
- * Glob matching uses [`picomatch`](https://github.com/micromatch/picomatch)
12
- * which supports the subset of bash-style globs (including `**`) that the Go
13
- * port relies on via `bmatcuk/doublestar/v4`.
14
- *
15
- * @example
16
- * ```ts
17
- * import { Default, Op, Strict } from '@hop-top/kit/scope';
18
- *
19
- * const dec = Default().check('/Users/me/.ssh/id_rsa', Op.Read);
20
- * // -> Decision.Denied
21
- * ```
22
- */
23
- /** Mode controls how `Enforce` reacts to a `Denied` decision. */
24
- declare enum Mode {
25
- /** Strict denies → throws `ErrDenied`. The default. */
26
- Strict = "strict",
27
- /** Warn denies → logs to stderr and returns. */
28
- Warn = "warn",
29
- /** Prompt denies → invokes the prompt callback. */
30
- Prompt = "prompt"
31
- }
32
- /** Op is a bitset of filesystem operations. */
33
- declare enum Op {
34
- Read = 1,
35
- Write = 2,
36
- Exec = 4
37
- }
38
- /** Decision is the outcome of `Check`. */
39
- declare enum Decision {
40
- Unknown = "unknown",
41
- Allowed = "allowed",
42
- Denied = "denied"
43
- }
44
- /** A single rule: glob patterns + ops bitset + allow/deny verdict. */
45
- interface Rule {
46
- patterns: string[];
47
- ops: Op;
48
- allow: boolean;
49
- }
50
- /** Prompt callback used in `Mode.Prompt`. Return `true` to allow this call. */
51
- type PromptFunc = (path: string, op: Op) => boolean;
52
- /** Error thrown by `Enforce` when a path is denied. */
53
- declare class ErrDenied extends Error {
54
- constructor(p: string, op: Op);
55
- }
56
- /**
57
- * Policy holds an ordered list of rules, a Mode, and an optional prompt
58
- * callback. Construct via `New()` or `Default()`.
59
- */
60
- declare class Policy {
61
- private rules;
62
- private mode;
63
- private prompt?;
64
- /** Register an allow rule covering Read|Write|Exec. */
65
- allow(...patterns: string[]): this;
66
- /** Register an allow rule for the given operations. */
67
- allowOp(op: Op, ...patterns: string[]): this;
68
- /** Register a deny rule covering Read|Write|Exec. */
69
- deny(...patterns: string[]): this;
70
- /** Register a deny rule for the given operations. */
71
- denyOp(op: Op, ...patterns: string[]): this;
72
- /** Set the enforcement mode. */
73
- setMode(m: Mode): this;
74
- /** Get the current enforcement mode. */
75
- getMode(): Mode;
76
- /** Set the prompt callback used in `Mode.Prompt`. */
77
- setPromptFunc(fn: PromptFunc): this;
78
- /** Defensive copy of the policy's rules in registration order. */
79
- getRules(): Rule[];
80
- /**
81
- * Evaluate `(p, op)` against the policy. Pure — no prompt, no mutation.
82
- * Resolves symlinks before matching to defeat symlink escapes; on ENOENT
83
- * the cleaned path is used so "intent to write" still matches deny rules.
84
- */
85
- check(p: string, op: Op): Decision;
86
- /**
87
- * Enforce calls `check` and translates the decision according to mode:
88
- * Strict + (Denied|Unknown) throws; Warn + Denied logs; Prompt + Denied
89
- * invokes the prompt callback.
90
- */
91
- enforce(p: string, op: Op): void;
92
- private handleDeny;
93
- /** Deep copy. Useful for per-test isolation paired with `setDefault`. */
94
- snapshot(): Policy;
95
- }
96
- /** Create an empty `Policy` in `Mode.Strict`. */
97
- declare function New(): Policy;
98
- /**
99
- * Returns the package-level singleton policy used by primitives that don't
100
- * accept an explicit policy. Lazy-initialised on first call. The singleton is
101
- * pre-seeded with `SecretPaths()` as a deny-all-ops rule.
102
- */
103
- declare function Default(): Policy;
104
- /**
105
- * Swap the package-level singleton with `p`. Returns a restore function that
106
- * puts the previous policy back. Intended for tests:
107
- *
108
- * ```ts
109
- * const restore = setDefault(New().allow('~/tmp/**'));
110
- * try { ... } finally { restore(); }
111
- * ```
112
- */
113
- declare function setDefault(p: Policy): () => void;
114
- /**
115
- * Returns the default deny pattern set: common patterns plus the patterns
116
- * specific to the current platform. Patterns are ready to feed into
117
- * `Policy.deny`. `~` and Windows env macros are resolved at match time.
118
- */
119
- declare function SecretPaths(): string[];
120
-
121
- export { Decision, Default, ErrDenied, Mode, New, Op, Policy, type PromptFunc, type Rule, SecretPaths, setDefault };
1
+ export { D as Decision, a as Default, E as ErrDenied, M as Mode, N as New, O as Op, P as Policy, b as PromptFunc, R as Rule, S as SecretPaths, c as setDefault } from './scope-BrhYB4ij.js';