@gotgenes/pi-permission-system 16.1.0 → 16.2.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 (34) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/package.json +1 -1
  3. package/src/access-intent/access-intent.ts +57 -0
  4. package/src/handlers/gates/bash-command.ts +18 -3
  5. package/src/handlers/gates/bash-path.ts +6 -4
  6. package/src/handlers/gates/external-directory-policy.ts +9 -8
  7. package/src/handlers/gates/path.ts +6 -5
  8. package/src/handlers/gates/runner.ts +6 -5
  9. package/src/handlers/gates/tool-call-gate-pipeline.ts +6 -5
  10. package/src/permission-event-rpc.ts +4 -6
  11. package/src/permission-manager.ts +39 -55
  12. package/src/permission-resolver.ts +45 -57
  13. package/src/permissions-service.ts +2 -4
  14. package/src/skill-prompt-sanitizer.ts +2 -2
  15. package/test/handlers/before-agent-start.test.ts +6 -9
  16. package/test/handlers/external-directory-session-dedup.test.ts +16 -40
  17. package/test/handlers/gates/bash-command-metamorphic.test.ts +5 -3
  18. package/test/handlers/gates/bash-command.test.ts +26 -23
  19. package/test/handlers/gates/bash-external-directory.test.ts +36 -32
  20. package/test/handlers/gates/bash-path.test.ts +12 -8
  21. package/test/handlers/gates/external-directory-policy.test.ts +34 -22
  22. package/test/handlers/gates/external-directory.test.ts +11 -5
  23. package/test/handlers/gates/path.test.ts +30 -25
  24. package/test/handlers/gates/runner.test.ts +6 -1
  25. package/test/handlers/gates/tool-call-gate-pipeline.test.ts +2 -2
  26. package/test/handlers/input.test.ts +1 -1
  27. package/test/helpers/gate-fixtures.ts +12 -24
  28. package/test/helpers/handler-fixtures.ts +21 -15
  29. package/test/helpers/session-fixtures.ts +3 -18
  30. package/test/permission-event-rpc.test.ts +24 -20
  31. package/test/permission-manager-unified.test.ts +445 -209
  32. package/test/permission-resolver.test.ts +112 -89
  33. package/test/permissions-service.test.ts +10 -7
  34. package/test/skill-prompt-sanitizer.test.ts +30 -7
package/CHANGELOG.md CHANGED
@@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [16.2.0](https://github.com/gotgenes/pi-packages/compare/pi-permission-system-v16.1.0...pi-permission-system-v16.2.0) (2026-06-26)
9
+
10
+
11
+ ### Features
12
+
13
+ * **pi-permission-system:** add ScopedPermissionManager.check(intent) ([#478](https://github.com/gotgenes/pi-packages/issues/478)) ([7cb600a](https://github.com/gotgenes/pi-packages/commit/7cb600a11efd4bc60bd31c70d85550c7e1b28058))
14
+ * **pi-permission-system:** narrow ScopedPermissionResolver to resolve(intent) ([#478](https://github.com/gotgenes/pi-packages/issues/478)) ([908176f](https://github.com/gotgenes/pi-packages/commit/908176f8341e05d9181d5cf22ede10a6d5a470d0))
15
+
16
+
17
+ ### Documentation
18
+
19
+ * **pi-permission-system:** record resolve(intent) narrowing ([#478](https://github.com/gotgenes/pi-packages/issues/478)) ([fb8f986](https://github.com/gotgenes/pi-packages/commit/fb8f986e15e5db20d84030d0f77b2aa4aad39aab))
20
+
8
21
  ## [16.1.0](https://github.com/gotgenes/pi-packages/compare/pi-permission-system-v16.0.2...pi-permission-system-v16.1.0) (2026-06-26)
9
22
 
10
23
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gotgenes/pi-permission-system",
3
- "version": "16.1.0",
3
+ "version": "16.2.0",
4
4
  "description": "Permission enforcement extension for the Pi coding agent.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -0,0 +1,57 @@
1
+ import type { AccessPath } from "#src/access-intent/access-path";
2
+
3
+ /**
4
+ * Raw tool input the manager must normalize (path / bash / MCP / extension tools).
5
+ *
6
+ * The `surface` is the tool name fed to `normalizeInput` (e.g. `"read"`, `"bash"`,
7
+ * an MCP server name).
8
+ */
9
+ export interface ToolAccessIntent {
10
+ kind: "tool";
11
+ /** Tool name fed to input normalization. */
12
+ surface: string;
13
+ input: unknown;
14
+ agentName?: string;
15
+ }
16
+
17
+ /**
18
+ * Precomputed equivalent policy values for a path-shaped surface.
19
+ *
20
+ * Used by the bash-path gate (`path` surface), whose cd-resolved lexical
21
+ * `string[]` carry no canonical-boundary notion.
22
+ */
23
+ export interface PathValuesAccessIntent {
24
+ kind: "path-values";
25
+ /** `"path"` or `"external_directory"`. */
26
+ surface: string;
27
+ values: readonly string[];
28
+ agentName?: string;
29
+ }
30
+
31
+ /**
32
+ * An `AccessPath` value object for a path-shaped surface.
33
+ *
34
+ * Used by the external-directory gates; lets `AccessPath` flow into the
35
+ * resolver as a first-class variant so the resolver — not the gate — asks it
36
+ * for `matchValues()` (Tell-Don't-Ask).
37
+ */
38
+ export interface AccessPathAccessIntent {
39
+ kind: "access-path";
40
+ surface: string;
41
+ path: AccessPath;
42
+ agentName?: string;
43
+ }
44
+
45
+ /** What a gate emits — the full three-variant union. */
46
+ export type AccessIntent =
47
+ | ToolAccessIntent
48
+ | PathValuesAccessIntent
49
+ | AccessPathAccessIntent;
50
+
51
+ /**
52
+ * What the manager consumes — the `access-path` variant has already been
53
+ * unwrapped to `path-values` by the resolver via `path.matchValues()`.
54
+ *
55
+ * The manager stays string-based and never imports `AccessPath`.
56
+ */
57
+ export type ResolvedAccessIntent = ToolAccessIntent | PathValuesAccessIntent;
@@ -38,7 +38,12 @@ export function resolveBashCommandCheck(
38
38
  ): PermissionCheckResult {
39
39
  if (commands.length === 0) {
40
40
  if (isTriviallyEmptyCommand(command)) {
41
- return resolver.resolve("bash", { command }, agentName);
41
+ return resolver.resolve({
42
+ kind: "tool",
43
+ surface: "bash",
44
+ input: { command },
45
+ agentName,
46
+ });
42
47
  }
43
48
  return {
44
49
  state: "ask",
@@ -51,12 +56,22 @@ export function resolveBashCommandCheck(
51
56
  }
52
57
 
53
58
  const results = commands.map((cmd) => {
54
- const result = resolver.resolve("bash", { command: cmd.text }, agentName);
59
+ const result = resolver.resolve({
60
+ kind: "tool",
61
+ surface: "bash",
62
+ input: { command: cmd.text },
63
+ agentName,
64
+ });
55
65
  return cmd.context ? { ...result, commandContext: cmd.context } : result;
56
66
  });
57
67
  return (
58
68
  pickMostRestrictive(results) ??
59
- resolver.resolve("bash", { command }, agentName)
69
+ resolver.resolve({
70
+ kind: "tool",
71
+ surface: "bash",
72
+ input: { command },
73
+ agentName,
74
+ })
60
75
  );
61
76
  }
62
77
 
@@ -51,10 +51,12 @@ export function describeBashPathGate(
51
51
  let allSessionCovered = true;
52
52
 
53
53
  for (const { token, policyValues } of candidates) {
54
- const check = resolver.resolvePathPolicy(
55
- policyValues,
56
- tcc.agentName ?? undefined,
57
- );
54
+ const check = resolver.resolve({
55
+ kind: "path-values",
56
+ surface: "path",
57
+ values: policyValues,
58
+ agentName: tcc.agentName ?? undefined,
59
+ });
58
60
 
59
61
  // No explicit path rule matched — only the universal default fired.
60
62
  // Treat this token as unrestricted to preserve backward compatibility
@@ -19,10 +19,10 @@ export interface UncoveredExternalPaths {
19
19
  /**
20
20
  * Resolve one external path's policy on the `external_directory` surface.
21
21
  *
22
- * Matches against the typed and symlink-resolved aliases
23
- * ({@link AccessPath.matchValues}) so a config pattern on either form applies
24
- * (#418). This is the single source for the alias-derivation plus
25
- * surface-tagged resolve that the two external-directory gates previously
22
+ * Emits an `access-path` {@link AccessIntent}; the resolver unwraps it via
23
+ * {@link AccessPath.matchValues} so a config pattern on either the typed or
24
+ * symlink-resolved alias applies (#418). This is the single source for the
25
+ * external-directory resolve that the two external-directory gates previously
26
26
  * duplicated.
27
27
  */
28
28
  export function resolveExternalDirectoryPolicy(
@@ -30,11 +30,12 @@ export function resolveExternalDirectoryPolicy(
30
30
  resolver: ScopedPermissionResolver,
31
31
  agentName: string | undefined,
32
32
  ): PermissionCheckResult {
33
- return resolver.resolvePathPolicy(
34
- path.matchValues(),
33
+ return resolver.resolve({
34
+ kind: "access-path",
35
+ surface: "external_directory",
36
+ path,
35
37
  agentName,
36
- "external_directory",
37
- );
38
+ });
38
39
  }
39
40
 
40
41
  /**
@@ -22,11 +22,12 @@ export function describePathGate(
22
22
  const filePath = getToolInputPath(tcc.toolName, tcc.input, extractors);
23
23
  if (!filePath) return null;
24
24
 
25
- const check = resolver.resolve(
26
- "path",
27
- { path: filePath },
28
- tcc.agentName ?? undefined,
29
- );
25
+ const check = resolver.resolve({
26
+ kind: "tool",
27
+ surface: "path",
28
+ input: { path: filePath },
29
+ agentName: tcc.agentName ?? undefined,
30
+ });
30
31
 
31
32
  if (check.state === "allow") return null;
32
33
 
@@ -77,11 +77,12 @@ export class GateRunner {
77
77
  origin: "builtin",
78
78
  };
79
79
  } else {
80
- check = this.resolver.resolve(
81
- descriptor.surface,
82
- descriptor.input,
83
- agentName ?? undefined,
84
- );
80
+ check = this.resolver.resolve({
81
+ kind: "tool",
82
+ surface: descriptor.surface,
83
+ input: descriptor.input,
84
+ agentName: agentName ?? undefined,
85
+ });
85
86
  }
86
87
 
87
88
  // 2. Session-hit fast path
@@ -102,11 +102,12 @@ export class ToolCallGatePipeline {
102
102
  tcc.agentName ?? undefined,
103
103
  this.resolver,
104
104
  )
105
- : this.resolver.resolve(
106
- tcc.toolName,
107
- tcc.input,
108
- tcc.agentName ?? undefined,
109
- );
105
+ : this.resolver.resolve({
106
+ kind: "tool",
107
+ surface: tcc.toolName,
108
+ input: tcc.input,
109
+ agentName: tcc.agentName ?? undefined,
110
+ });
110
111
  const toolDescriptor = describeToolGate(tcc, toolCheck, formatter);
111
112
  toolDescriptor.preCheck = toolCheck;
112
113
  return toolDescriptor;
@@ -26,7 +26,7 @@ import {
26
26
  PERMISSIONS_RPC_CHECK_CHANNEL,
27
27
  PERMISSIONS_RPC_PROMPT_CHANNEL,
28
28
  } from "./permission-events";
29
- import type { PermissionManager } from "./permission-manager";
29
+ import type { ScopedPermissionManager } from "./permission-manager";
30
30
  import { buildRpcUiPrompt } from "./permission-ui-prompt";
31
31
  import type { ReviewLogger } from "./session-logger";
32
32
  import type { SessionRules } from "./session-rules";
@@ -34,7 +34,7 @@ import type { SessionRules } from "./session-rules";
34
34
  /** Dependencies injected into the RPC handler registry. */
35
35
  export interface PermissionRpcDeps {
36
36
  /** The shared PermissionManager instance. */
37
- permissionManager: Pick<PermissionManager, "checkPermission">;
37
+ permissionManager: Pick<ScopedPermissionManager, "check">;
38
38
  /** The shared SessionRules instance. */
39
39
  sessionRules: Pick<SessionRules, "getRuleset">;
40
40
  /**
@@ -109,10 +109,8 @@ function handleCheckRpc(
109
109
 
110
110
  const input = buildInputForSurface(surface, value);
111
111
  const sessionRules = deps.sessionRules.getRuleset();
112
- const result = deps.permissionManager.checkPermission(
113
- surface,
114
- input,
115
- agentName ?? undefined,
112
+ const result = deps.permissionManager.check(
113
+ { kind: "tool", surface, input, agentName: agentName ?? undefined },
116
114
  sessionRules,
117
115
  );
118
116
 
@@ -1,4 +1,5 @@
1
1
  import { join } from "node:path";
2
+ import type { ResolvedAccessIntent } from "./access-intent/access-intent";
2
3
  import { isPermissionState } from "./common";
3
4
  import {
4
5
  getGlobalConfigPath,
@@ -50,7 +51,7 @@ type FileCacheEntry<TValue> = {
50
51
  type ResolvedPermissions = {
51
52
  /**
52
53
  * Fully composed ruleset: synthesized defaults → baseline → config.
53
- * Session rules are appended at call-time inside checkPermission().
54
+ * Session rules are appended at call-time inside check().
54
55
  */
55
56
  composedRules: Ruleset;
56
57
  };
@@ -62,25 +63,16 @@ type ResolvedPermissions = {
62
63
  */
63
64
  export interface ScopedPermissionManager {
64
65
  configureForCwd(cwd: string | undefined | null): void;
65
- checkPermission(
66
- toolName: string,
67
- input: unknown,
68
- agentName?: string,
69
- sessionRules?: Ruleset,
70
- ): PermissionCheckResult;
71
66
  /**
72
- * Evaluate a path-shaped surface (`path` or `external_directory`) against a
73
- * caller-supplied set of equivalent policy values (e.g. bash tokens already
74
- * resolved against a preceding literal `cd`, or a path's typed and
75
- * symlink-resolved aliases). The values are trusted because they are computed
76
- * internally, never read from a field on raw tool input. `surface` defaults
77
- * to `path`.
67
+ * Unified resolution entry point (Phase 6 Step 6, #478).
68
+ *
69
+ * Replaces the former `checkPermission` + `checkPathPolicy` method pair with
70
+ * a single dispatched call, making it structurally impossible to stub one
71
+ * method and forget the other (the #393 false-green class).
78
72
  */
79
- checkPathPolicy(
80
- values: readonly string[],
81
- agentName?: string,
73
+ check(
74
+ intent: ResolvedAccessIntent,
82
75
  sessionRules?: Ruleset,
83
- surface?: string,
84
76
  ): PermissionCheckResult;
85
77
  getToolPermission(toolName: string, agentName?: string): PermissionState;
86
78
  getConfigIssues(agentName?: string): string[];
@@ -243,56 +235,48 @@ export class PermissionManager implements ScopedPermissionManager {
243
235
  return evaluate(normalizedToolName, "*", composedRules).action;
244
236
  }
245
237
 
246
- checkPermission(
247
- toolName: string,
248
- input: unknown,
249
- agentName?: string,
238
+ /**
239
+ * Unified resolution entry point — dispatches on intent kind.
240
+ *
241
+ * `"tool"` → normalizes raw input through `normalizeInput`.
242
+ * `"path-values"` → evaluates the precomputed values directly.
243
+ */
244
+ check(
245
+ intent: ResolvedAccessIntent,
250
246
  sessionRules?: Ruleset,
251
247
  ): PermissionCheckResult {
252
- const { composedRules } = this.resolvePermissions(agentName);
253
- const normalizedToolName = toolName.trim();
254
-
255
- // Append session rules at the end (highest priority) so evaluate() handles
256
- // them via last-match-wins — no separate per-branch pre-check needed.
248
+ const { composedRules } = this.resolvePermissions(intent.agentName);
257
249
  const fullRules: Ruleset = sessionRules?.length
258
250
  ? [...composedRules, ...sessionRules]
259
251
  : composedRules;
260
252
 
253
+ if (intent.kind === "path-values") {
254
+ const lookupValues =
255
+ intent.values.length > 0 ? [...intent.values] : ["*"];
256
+ return buildCheckResult(
257
+ intent.surface,
258
+ lookupValues,
259
+ {},
260
+ intent.surface,
261
+ intent.surface,
262
+ fullRules,
263
+ );
264
+ }
265
+
266
+ // kind === "tool"
267
+ const toolName = intent.surface.trim();
261
268
  const { surface, values, resultExtras } = normalizeInput(
262
- normalizedToolName,
263
- input,
269
+ toolName,
270
+ intent.input,
264
271
  this.loader.getConfiguredMcpServerNames(),
265
272
  this.currentCwd,
266
273
  );
267
-
268
274
  return buildCheckResult(
269
275
  surface,
270
276
  values,
271
277
  resultExtras,
272
- normalizedToolName,
273
278
  toolName,
274
- fullRules,
275
- );
276
- }
277
-
278
- checkPathPolicy(
279
- values: readonly string[],
280
- agentName?: string,
281
- sessionRules?: Ruleset,
282
- surface = "path",
283
- ): PermissionCheckResult {
284
- const { composedRules } = this.resolvePermissions(agentName);
285
- const fullRules: Ruleset = sessionRules?.length
286
- ? [...composedRules, ...sessionRules]
287
- : composedRules;
288
-
289
- const lookupValues = values.length > 0 ? [...values] : ["*"];
290
- return buildCheckResult(
291
- surface,
292
- lookupValues,
293
- {},
294
- surface,
295
- surface,
279
+ intent.surface,
296
280
  fullRules,
297
281
  );
298
282
  }
@@ -302,8 +286,8 @@ export class PermissionManager implements ScopedPermissionManager {
302
286
  * Evaluate a normalized surface/values triple and shape the result.
303
287
  *
304
288
  * Path surfaces use {@link evaluateAnyValue} (last-match-wins across equivalent
305
- * aliases); every other surface keeps {@link evaluateFirst}. Shared by
306
- * `checkPermission` and `checkPathPolicy`.
289
+ * aliases); every other surface keeps {@link evaluateFirst}. Shared by the
290
+ * `"tool"` and `"path-values"` branches of {@link PermissionManager.check}.
307
291
  */
308
292
  function buildCheckResult(
309
293
  surface: string,
@@ -357,7 +341,7 @@ function derivePolicyLoaderOptions(
357
341
  * Map a matched rule + tool name to the correct PermissionCheckResult.source.
358
342
  *
359
343
  * Mirrors the source-derivation logic from the former per-branch
360
- * checkPermission() implementation:
344
+ * permission-check implementation:
361
345
  *
362
346
  * - session → "session" (always, all surfaces)
363
347
  * - mcp + default → "default"
@@ -1,34 +1,42 @@
1
+ import type {
2
+ AccessIntent,
3
+ ResolvedAccessIntent,
4
+ } from "./access-intent/access-intent";
1
5
  import type { ScopedPermissionManager } from "./permission-manager";
2
6
  import type { Rule } from "./rule";
3
7
  import type { SessionRules } from "./session-rules";
8
+ import type { SkillPermissionChecker } from "./skill-prompt-sanitizer";
4
9
  import type { PermissionCheckResult, PermissionState } from "./types";
5
10
 
6
11
  /**
7
- * Resolves the effective permission for a surface/input, applying the current
8
- * session rules internally.
12
+ * Answers an {@link AccessIntent} a gate emits, applying the current session
13
+ * rules internally.
9
14
  *
10
- * Collapses the `checkPermission` + `getSessionRuleset` relay that every gate
11
- * previously threaded by hand: the ruleset was only ever fetched to be passed
12
- * straight back into `checkPermission`, so the two are one operation.
15
+ * A single `resolve(intent)` entry point means adding a gate cannot widen the
16
+ * resolver surface, and a test fixture cannot stub one resolution method and
17
+ * forget another (the #393 false-green class) #478.
13
18
  */
14
19
  export interface ScopedPermissionResolver {
15
- resolve(
16
- surface: string,
17
- input: unknown,
18
- agentName?: string,
19
- ): PermissionCheckResult;
20
- /**
21
- * Resolve a path-shaped surface against a caller-supplied set of equivalent
22
- * policy values, applying the current session rules. Used by the bash path
23
- * gate (`path`) and the external-directory gates (`external_directory`),
24
- * which compute equivalent path aliases per token. `surface` defaults to
25
- * `path`.
26
- */
27
- resolvePathPolicy(
28
- values: readonly string[],
29
- agentName?: string,
30
- surface?: string,
31
- ): PermissionCheckResult;
20
+ resolve(intent: AccessIntent): PermissionCheckResult;
21
+ }
22
+
23
+ /**
24
+ * Reduce a gate-emitted {@link AccessIntent} to the string-based
25
+ * {@link ResolvedAccessIntent} the manager consumes.
26
+ *
27
+ * Tell-Don't-Ask: the resolver asks an `AccessPath` for its `matchValues()`,
28
+ * so the low-level manager never imports the value object.
29
+ */
30
+ function toResolvedIntent(intent: AccessIntent): ResolvedAccessIntent {
31
+ if (intent.kind === "access-path") {
32
+ return {
33
+ kind: "path-values",
34
+ surface: intent.surface,
35
+ values: intent.path.matchValues(),
36
+ agentName: intent.agentName,
37
+ };
38
+ }
39
+ return intent;
32
40
  }
33
41
 
34
42
  /**
@@ -41,60 +49,40 @@ export interface ScopedPermissionResolver {
41
49
  * - `permissionManager` — the narrow session-scoped permission-checking interface
42
50
  * - `sessionRules` — narrowed to `getRuleset` (ISP: the resolver only reads, never records)
43
51
  */
44
- export class PermissionResolver implements ScopedPermissionResolver {
52
+ export class PermissionResolver
53
+ implements ScopedPermissionResolver, SkillPermissionChecker
54
+ {
45
55
  constructor(
46
56
  private readonly permissionManager: ScopedPermissionManager,
47
57
  private readonly sessionRules: Pick<SessionRules, "getRuleset">,
48
58
  ) {}
49
59
 
50
60
  /**
51
- * Resolve the effective permission for a surface/input, applying the current
52
- * session rules. Composes `checkPermission` with `getRuleset()` so callers
53
- * never thread the ruleset by hand.
61
+ * Answer a gate-emitted access intent, composing the current session ruleset
62
+ * so callers never thread it by hand. Unwraps the `access-path` variant via
63
+ * `matchValues()` before handing a string-based intent to the manager.
54
64
  */
55
- resolve(
56
- surface: string,
57
- input: unknown,
58
- agentName?: string,
59
- ): PermissionCheckResult {
60
- return this.checkPermission(
61
- surface,
62
- input,
63
- agentName,
65
+ resolve(intent: AccessIntent): PermissionCheckResult {
66
+ return this.permissionManager.check(
67
+ toResolvedIntent(intent),
64
68
  this.sessionRules.getRuleset(),
65
69
  );
66
70
  }
67
71
 
68
72
  /**
69
- * Resolve a path-shaped surface (`path` or `external_directory`) for
70
- * precomputed policy values, composing the current session ruleset so callers
71
- * never thread it by hand. `surface` defaults to `path`; the external-directory
72
- * gates pass `external_directory` so a path's typed and symlink-resolved
73
- * aliases match against the `external_directory` rules.
73
+ * Raw permission check without session rules the no-session-rules path
74
+ * consumed by `SkillInputGateInputs` / `SkillPermissionChecker`.
75
+ *
76
+ * Not on `ScopedPermissionResolver` (ISP: gates do not use this).
74
77
  */
75
- resolvePathPolicy(
76
- values: readonly string[],
77
- agentName?: string,
78
- surface = "path",
79
- ): PermissionCheckResult {
80
- return this.permissionManager.checkPathPolicy(
81
- values,
82
- agentName,
83
- this.sessionRules.getRuleset(),
84
- surface,
85
- );
86
- }
87
-
88
78
  checkPermission(
89
79
  surface: string,
90
80
  input: unknown,
91
81
  agentName?: string,
92
82
  sessionRules?: Rule[],
93
83
  ): PermissionCheckResult {
94
- return this.permissionManager.checkPermission(
95
- surface,
96
- input,
97
- agentName,
84
+ return this.permissionManager.check(
85
+ { kind: "tool", surface, input, agentName },
98
86
  sessionRules,
99
87
  );
100
88
  }
@@ -32,10 +32,8 @@ export class LocalPermissionsService implements PermissionsService {
32
32
  agentName?: string,
33
33
  ): ReturnType<PermissionsService["checkPermission"]> {
34
34
  const input = buildInputForSurface(surface, value);
35
- return this.permissionManager.checkPermission(
36
- surface,
37
- input,
38
- agentName,
35
+ return this.permissionManager.check(
36
+ { kind: "tool", surface, input, agentName },
39
37
  this.sessionRules.getRuleset(),
40
38
  );
41
39
  }
@@ -7,8 +7,8 @@ import {
7
7
  import type { PermissionCheckResult, PermissionState } from "./types";
8
8
 
9
9
  /**
10
- * Narrow interface for the permission checker used by skill prompt resolution.
11
- * Both `PermissionManager` and `PermissionResolver` satisfy this structurally.
10
+ * Narrow interface for the raw (no-session-rules) permission checker used by
11
+ * skill prompt resolution. `PermissionResolver` implements it (#478).
12
12
  */
13
13
  export interface SkillPermissionChecker {
14
14
  checkPermission(
@@ -49,10 +49,8 @@ function makeSetup(opts?: {
49
49
  opts.toolPermission,
50
50
  );
51
51
  }
52
- // Default checkPermission returns allow (for skill-prompt sanitizer)
53
- vi.mocked(permissionManager.checkPermission).mockReturnValue(
54
- makeCheckResult(),
55
- );
52
+ // Default check returns allow (for skill-prompt sanitizer via resolver.checkPermission)
53
+ vi.mocked(permissionManager.check).mockReturnValue(makeCheckResult());
56
54
  const toolRegistry = makeToolRegistry(opts?.toolRegistry);
57
55
  const handler = new AgentPrepHandler(session, resolver, toolRegistry);
58
56
  return {
@@ -195,11 +193,10 @@ describe("AgentPrepHandler.handle", () => {
195
193
  "</available_skills>",
196
194
  ].join("\n");
197
195
  const { handler, permissionManager } = makeSetup();
198
- vi.mocked(permissionManager.checkPermission).mockImplementation(
199
- (surface) =>
200
- surface === "skill"
201
- ? makeCheckResult({ state: "deny" })
202
- : makeCheckResult(),
196
+ vi.mocked(permissionManager.check).mockImplementation((intent) =>
197
+ intent.surface === "skill"
198
+ ? makeCheckResult({ state: "deny" })
199
+ : makeCheckResult(),
203
200
  );
204
201
 
205
202
  const first = await handler.handle(makeEvent(systemPrompt), makeCtx());