@gotgenes/pi-permission-system 20.5.0 → 20.6.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/CHANGELOG.md +14 -0
- package/README.md +1 -1
- package/docs/configuration.md +3 -3
- package/package.json +1 -1
- package/src/access-intent/bash/bash-path-resolver.ts +63 -4
- package/src/access-intent/bash/program.ts +22 -1
- package/src/access-intent/tool-kind.ts +55 -0
- package/src/handlers/gates/bash-external-directory.ts +6 -7
- package/src/handlers/gates/bash-path.ts +7 -8
- package/src/handlers/gates/tool-call-gate-pipeline.ts +51 -24
- package/src/handlers/gates/tool.ts +18 -8
- package/src/permission-session.ts +11 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,20 @@ 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
|
+
## [20.6.0](https://github.com/gotgenes/pi-packages/compare/pi-permission-system-v20.5.0...pi-permission-system-v20.6.0) (2026-07-13)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* **pi-permission-system:** add resolveShellInvocation dispatch point ([5c5edc8](https://github.com/gotgenes/pi-packages/commit/5c5edc84cd46dafb5dade9fd51b2946632b72776))
|
|
14
|
+
* **pi-permission-system:** gate aliased shell tools through the bash stack ([2c17f2c](https://github.com/gotgenes/pi-packages/commit/2c17f2ce4b6207684f999d0bc30fe630c79934bb)), closes [#574](https://github.com/gotgenes/pi-packages/issues/574)
|
|
15
|
+
* **pi-permission-system:** resolve and gate aliased shell workdir ([d9b2af8](https://github.com/gotgenes/pi-packages/commit/d9b2af86107671366935242e704d1f17821db73f)), closes [#574](https://github.com/gotgenes/pi-packages/issues/574)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Documentation
|
|
19
|
+
|
|
20
|
+
* **pi-permission-system:** document live shellTools enforcement ([b8048ed](https://github.com/gotgenes/pi-packages/commit/b8048eddba5f8c0e9b82cf0c3e31055e7813b745))
|
|
21
|
+
|
|
8
22
|
## [20.5.0](https://github.com/gotgenes/pi-packages/compare/pi-permission-system-v20.4.2...pi-permission-system-v20.5.0) (2026-07-13)
|
|
9
23
|
|
|
10
24
|
|
package/README.md
CHANGED
|
@@ -109,7 +109,7 @@ Project overrides global; per-agent YAML frontmatter overrides both.
|
|
|
109
109
|
|
|
110
110
|
Within a surface map like `bash` or `mcp`, **last matching rule wins** — put broad catch-alls first and specific overrides after.
|
|
111
111
|
|
|
112
|
-
The optional `shellTools` field records which non-`bash` tools carry shell semantics (e.g. an `exec_command` tool that replaces native `bash`), so they
|
|
112
|
+
The optional `shellTools` field records which non-`bash` tools carry shell semantics (e.g. an `exec_command` tool that replaces native `bash`), so they are gated at full parity with native `bash` — see [docs/configuration.md](docs/configuration.md#shelltools--gating-aliased-shell-tools).
|
|
113
113
|
|
|
114
114
|
For the full reference — all surfaces, runtime knobs, per-agent overrides, merge semantics, and common recipes — see [docs/configuration.md](docs/configuration.md).
|
|
115
115
|
|
package/docs/configuration.md
CHANGED
|
@@ -115,7 +115,7 @@ The native `bash` tool goes through the full bash enforcement stack: command dec
|
|
|
115
115
|
Some extensions replace `bash` with a differently-named tool — for example [`@howaboua/pi-codex-conversion`](https://github.com/IgorWarzocha/howaboua-pi-stuff) registers `exec_command`, which carries the shell command in a `cmd` argument and an optional working directory in `workdir`.
|
|
116
116
|
Without a hint, the permission system cannot tell that such a tool is really a shell, so it gates it as a generic extension tool and the bash rules never apply.
|
|
117
117
|
|
|
118
|
-
`shellTools` records that hint.
|
|
118
|
+
`shellTools` records that hint, and an aliased tool is then gated at full parity with native `bash` — command decomposition, wrapper flooring, path and external-directory token gates, and `bash:` rules — with the invoked tool name preserved in the review log.
|
|
119
119
|
Each key is a tool name; its value maps the tool's input arguments (the keys of the tool call's `arguments` object):
|
|
120
120
|
|
|
121
121
|
```jsonc
|
|
@@ -131,6 +131,8 @@ Each key is a tool name; its value maps the tool's input arguments (the keys of
|
|
|
131
131
|
| `commandArgument` | yes | The tool's input argument holding the shell command string (e.g. `cmd`). |
|
|
132
132
|
| `workdirArgument` | no | The tool's input argument holding the working directory (e.g. `workdir`). |
|
|
133
133
|
|
|
134
|
+
When `workdirArgument` is set, the tool's working directory is the base the command's relative paths resolve against, and the working directory itself is gated by `external_directory` when it falls outside the session's working directory.
|
|
135
|
+
|
|
134
136
|
Merge semantics: `shellTools` **shallow-merges by tool name** across global → project.
|
|
135
137
|
A project entry overrides a specific tool's mapping on a key collision but never drops a global entry — so adding a project-scoped alias cannot silently remove enforcement for a tool the global config already covers.
|
|
136
138
|
To change a specific tool's mapping, set that tool's key at the project scope (the alias object is replaced wholesale, not deep-merged).
|
|
@@ -138,8 +140,6 @@ To change a specific tool's mapping, set that tool's key at the project scope (t
|
|
|
138
140
|
`shellTools` only ever *tightens* enforcement and is inert when the named tool is not registered in the current session.
|
|
139
141
|
Opting a project out of a shell-aliasing extension is a package-disable concern, not a `shellTools` edit.
|
|
140
142
|
|
|
141
|
-
> **Note:** `shellTools` records the alias; the enforcement wiring that consumes it is tracked in [#574](https://github.com/gotgenes/pi-packages/issues/574).
|
|
142
|
-
|
|
143
143
|
---
|
|
144
144
|
|
|
145
145
|
## Policy Reference
|
package/package.json
CHANGED
|
@@ -101,20 +101,57 @@ export class BashPathResolver {
|
|
|
101
101
|
constructor(
|
|
102
102
|
private readonly normalizer: PathNormalizer,
|
|
103
103
|
private readonly isPromotablePathToken: PathRuleTokenMatcher = NO_PROMOTION,
|
|
104
|
+
private readonly workdir?: string,
|
|
104
105
|
) {}
|
|
105
106
|
|
|
106
107
|
/**
|
|
107
108
|
* Resolve a parsed bash program's path references into its external-path and
|
|
108
109
|
* rule-candidate slices, walking the AST exactly once.
|
|
110
|
+
*
|
|
111
|
+
* When a `workdir` is set (an aliased shell tool's working directory, #574),
|
|
112
|
+
* it seeds the initial effective base — as if the program were prefixed with
|
|
113
|
+
* `cd <workdir>` — so relative tokens resolve against it, and the `workdir`
|
|
114
|
+
* itself is added to the external paths when it resolves outside the cwd.
|
|
115
|
+
* Containment is always measured against the session cwd baked into the
|
|
116
|
+
* normalizer, so a `workdir` outside the cwd does not widen the sandbox.
|
|
109
117
|
*/
|
|
110
118
|
resolve(rootNode: TSNode): ResolvedBashPaths {
|
|
111
|
-
const
|
|
119
|
+
const initialBase =
|
|
120
|
+
this.workdir === undefined
|
|
121
|
+
? CWD_BASE
|
|
122
|
+
: this.deriveBaseFromCdTarget(CWD_BASE, this.workdir);
|
|
123
|
+
const candidates = this.collectPathCandidates(rootNode, initialBase);
|
|
112
124
|
return {
|
|
113
|
-
externalPaths: this.
|
|
125
|
+
externalPaths: this.withWorkdirExternal(
|
|
126
|
+
this.projectExternalPaths(candidates),
|
|
127
|
+
),
|
|
114
128
|
ruleCandidates: this.projectRuleCandidates(candidates),
|
|
115
129
|
};
|
|
116
130
|
}
|
|
117
131
|
|
|
132
|
+
/**
|
|
133
|
+
* Prepend the `workdir`'s own {@link AccessPath} to the external paths when it
|
|
134
|
+
* resolves outside the cwd. A real `cd /etc` flags `/etc` via its argument
|
|
135
|
+
* token; the seeded base carries no such token, so it is added explicitly and
|
|
136
|
+
* deduplicated against the command's own external tokens (#574).
|
|
137
|
+
*/
|
|
138
|
+
private withWorkdirExternal(
|
|
139
|
+
tokenExternals: readonly AccessPath[],
|
|
140
|
+
): AccessPath[] {
|
|
141
|
+
if (this.workdir === undefined) return [...tokenExternals];
|
|
142
|
+
const wdPath = this.normalizer.forBashToken(this.workdir);
|
|
143
|
+
const canonical = wdPath.boundaryValue();
|
|
144
|
+
const isExternal = canonical
|
|
145
|
+
? this.normalizer.isBoundaryOutsideWorkingDirectory(canonical)
|
|
146
|
+
: true;
|
|
147
|
+
if (!isExternal) return [...tokenExternals];
|
|
148
|
+
const key = canonical || wdPath.value();
|
|
149
|
+
const alreadyPresent = tokenExternals.some(
|
|
150
|
+
(p) => (p.boundaryValue() || p.value()) === key,
|
|
151
|
+
);
|
|
152
|
+
return alreadyPresent ? [...tokenExternals] : [wdPath, ...tokenExternals];
|
|
153
|
+
}
|
|
154
|
+
|
|
118
155
|
// ── AST walk — collect PathCandidates ──────────────────────────────────
|
|
119
156
|
|
|
120
157
|
/**
|
|
@@ -129,9 +166,12 @@ export class BashPathResolver {
|
|
|
129
166
|
* inherit the enclosing base without folding their own `cd`s (a conservative
|
|
130
167
|
* first tier).
|
|
131
168
|
*/
|
|
132
|
-
private collectPathCandidates(
|
|
169
|
+
private collectPathCandidates(
|
|
170
|
+
rootNode: TSNode,
|
|
171
|
+
initialBase: EffectiveBase,
|
|
172
|
+
): PathCandidate[] {
|
|
133
173
|
const out: PathCandidate[] = [];
|
|
134
|
-
this.walkForCandidates(rootNode,
|
|
174
|
+
this.walkForCandidates(rootNode, initialBase, out);
|
|
135
175
|
return out;
|
|
136
176
|
}
|
|
137
177
|
|
|
@@ -330,6 +370,25 @@ export class BashPathResolver {
|
|
|
330
370
|
if (extractCommandName(commandNode) !== "cd") return base;
|
|
331
371
|
const target = cdLiteralTarget(commandNode);
|
|
332
372
|
if (target === null) return UNKNOWN_BASE;
|
|
373
|
+
return this.deriveBaseFromCdTarget(base, target);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Fold a literal `cd`/working-directory target string into the effective
|
|
378
|
+
* base, delegating the platform/MSYS interpretation to the
|
|
379
|
+
* {@link PathNormalizer}. Owns only the base-folding state:
|
|
380
|
+
*
|
|
381
|
+
* - `absolute` → a fresh known base (recovers from an earlier unknown base).
|
|
382
|
+
* - `unknown` → the base becomes conservatively unknown.
|
|
383
|
+
* - `relative` → join into a known base, or stay unknown if already unknown.
|
|
384
|
+
*
|
|
385
|
+
* Shared by {@link foldCd} (inline `cd` commands) and the initial-base seed
|
|
386
|
+
* (an aliased shell tool's `workdir`, an implicit leading `cd <workdir>`).
|
|
387
|
+
*/
|
|
388
|
+
private deriveBaseFromCdTarget(
|
|
389
|
+
base: EffectiveBase,
|
|
390
|
+
target: string,
|
|
391
|
+
): EffectiveBase {
|
|
333
392
|
const interpreted = this.normalizer.interpretBashCdTarget(target);
|
|
334
393
|
switch (interpreted.kind) {
|
|
335
394
|
case "absolute":
|
|
@@ -25,6 +25,7 @@ export type { BashCommand, BashPathRuleCandidate };
|
|
|
25
25
|
*/
|
|
26
26
|
export class BashProgram {
|
|
27
27
|
private constructor(
|
|
28
|
+
private readonly sourceCommand: string,
|
|
28
29
|
private readonly commandUnits: readonly BashCommand[],
|
|
29
30
|
private readonly resolvedExternalPaths: readonly AccessPath[],
|
|
30
31
|
private readonly resolvedRuleCandidates: readonly BashPathRuleCandidate[],
|
|
@@ -44,22 +45,30 @@ export class BashProgram {
|
|
|
44
45
|
* specific `path` deny/ask rule (#509). Defaults to promoting nothing, so
|
|
45
46
|
* callers that only read `externalPaths()` (e.g. `bash-path-extractor.ts`)
|
|
46
47
|
* are unaffected.
|
|
48
|
+
*
|
|
49
|
+
* `options.workdir`, when supplied (an aliased shell tool's working directory,
|
|
50
|
+
* #574), seeds the initial effective base — as if the command were prefixed
|
|
51
|
+
* with `cd <workdir>` — so relative tokens resolve against it, and the workdir
|
|
52
|
+
* itself is flagged as external when it resolves outside the cwd.
|
|
47
53
|
*/
|
|
48
54
|
static async parse(
|
|
49
55
|
command: string,
|
|
50
56
|
normalizer: PathNormalizer,
|
|
51
57
|
isPromotablePathToken?: PathRuleTokenMatcher,
|
|
58
|
+
options?: { workdir?: string },
|
|
52
59
|
): Promise<BashProgram> {
|
|
53
60
|
const parser = await getParser();
|
|
54
61
|
const tree = parser.parse(command);
|
|
55
|
-
if (!tree) return new BashProgram([], [], []);
|
|
62
|
+
if (!tree) return new BashProgram(command, [], [], []);
|
|
56
63
|
|
|
57
64
|
try {
|
|
58
65
|
const { externalPaths, ruleCandidates } = new BashPathResolver(
|
|
59
66
|
normalizer,
|
|
60
67
|
isPromotablePathToken,
|
|
68
|
+
options?.workdir,
|
|
61
69
|
).resolve(tree.rootNode);
|
|
62
70
|
return new BashProgram(
|
|
71
|
+
command,
|
|
63
72
|
collectCommands(tree.rootNode),
|
|
64
73
|
externalPaths,
|
|
65
74
|
ruleCandidates,
|
|
@@ -69,6 +78,18 @@ export class BashProgram {
|
|
|
69
78
|
}
|
|
70
79
|
}
|
|
71
80
|
|
|
81
|
+
/**
|
|
82
|
+
* The source command string this program was parsed from.
|
|
83
|
+
*
|
|
84
|
+
* The bash gates read this for prompts, logs, and decision display instead of
|
|
85
|
+
* receiving the command as a separate parameter — the program is the parsed
|
|
86
|
+
* command, so it owns its source text (#574). Native `bash` and an aliased
|
|
87
|
+
* shell tool alike reach the gates through this single collaborator.
|
|
88
|
+
*/
|
|
89
|
+
commandText(): string {
|
|
90
|
+
return this.sourceCommand;
|
|
91
|
+
}
|
|
92
|
+
|
|
72
93
|
/**
|
|
73
94
|
* The top-level command-pattern units of the chain, in source order.
|
|
74
95
|
*
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { ShellToolsConfig } from "#src/config-schema";
|
|
2
|
+
import { getNonEmptyString, toRecord } from "#src/value-guards";
|
|
1
3
|
import { PATH_BEARING_TOOLS } from "./path-surfaces";
|
|
2
4
|
|
|
3
5
|
/**
|
|
@@ -39,6 +41,59 @@ export function classifyToolKind(toolName: string): ToolKind {
|
|
|
39
41
|
return "extension";
|
|
40
42
|
}
|
|
41
43
|
|
|
44
|
+
/** A shell invocation's effective command and optional working directory. */
|
|
45
|
+
export interface ShellInvocation {
|
|
46
|
+
/** The shell command string to decompose and gate. */
|
|
47
|
+
command: string;
|
|
48
|
+
/** The working directory the command runs in, if the tool projects one. */
|
|
49
|
+
workdir: string | undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Decide whether a tool invocation carries shell semantics, and if so extract
|
|
54
|
+
* its command and working directory.
|
|
55
|
+
*
|
|
56
|
+
* Native `bash` and any tool recorded in `shellTools` both yield a
|
|
57
|
+
* {@link ShellInvocation}; every other tool yields `null`. This is the single
|
|
58
|
+
* dispatch point the bash gate pipeline consults instead of re-deriving
|
|
59
|
+
* `toolName === "bash"` and reading `input.command`, so an aliased shell tool
|
|
60
|
+
* (e.g. `@howaboua/pi-codex-conversion`'s `exec_command`) is routed through the
|
|
61
|
+
* same bash enforcement stack as native `bash` (#574).
|
|
62
|
+
*
|
|
63
|
+
* The command and workdir are read through {@link getNonEmptyString} (trimmed,
|
|
64
|
+
* empty → `""`/`undefined`), matching the pipeline's existing native-bash
|
|
65
|
+
* extraction. Kept separate from {@link classifyToolKind} because it needs
|
|
66
|
+
* config (the alias map) and returns a richer product than a {@link ToolKind}
|
|
67
|
+
* string — `classifyToolKind` stays AccessPath-free and config-free.
|
|
68
|
+
*/
|
|
69
|
+
export function resolveShellInvocation(
|
|
70
|
+
toolName: string,
|
|
71
|
+
input: unknown,
|
|
72
|
+
aliases: ShellToolsConfig | undefined,
|
|
73
|
+
): ShellInvocation | null {
|
|
74
|
+
const name = toolName.trim();
|
|
75
|
+
const record = toRecord(input);
|
|
76
|
+
|
|
77
|
+
if (name === "bash") {
|
|
78
|
+
return {
|
|
79
|
+
command: getNonEmptyString(record.command) ?? "",
|
|
80
|
+
workdir: undefined,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const alias = aliases?.[name];
|
|
85
|
+
if (alias) {
|
|
86
|
+
return {
|
|
87
|
+
command: getNonEmptyString(record[alias.commandArgument]) ?? "",
|
|
88
|
+
workdir: alias.workdirArgument
|
|
89
|
+
? (getNonEmptyString(record[alias.workdirArgument]) ?? undefined)
|
|
90
|
+
: undefined,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
|
|
42
97
|
/** The resolved-check fields that decide MCP-ness. */
|
|
43
98
|
interface McpKindFields {
|
|
44
99
|
toolName: string;
|
|
@@ -2,7 +2,6 @@ import type { BashProgram } from "#src/access-intent/bash/program";
|
|
|
2
2
|
import type { ScopedPermissionResolver } from "#src/permission-resolver";
|
|
3
3
|
import { SessionApproval } from "#src/session-approval";
|
|
4
4
|
import { deriveApprovalPattern } from "#src/session-rules";
|
|
5
|
-
import { getNonEmptyString, toRecord } from "#src/value-guards";
|
|
6
5
|
import type { GateResult } from "./descriptor";
|
|
7
6
|
import { formatBashExternalDirectoryAskPrompt } from "./external-directory-messages";
|
|
8
7
|
import { selectUncoveredExternalPaths } from "./external-directory-policy";
|
|
@@ -13,21 +12,21 @@ import type { ToolCallContext } from "./types";
|
|
|
13
12
|
*
|
|
14
13
|
* Reads the external paths from the injected `BashProgram` and checks whether
|
|
15
14
|
* any reference directories outside the working directory. Returns `null` when the gate
|
|
16
|
-
* does not apply (
|
|
15
|
+
* does not apply (not a shell invocation, no command, or no external paths found).
|
|
17
16
|
* Returns a `GateBypass` when all paths are allowed (by config or session rule).
|
|
18
17
|
* Returns a `GateDescriptor` with multi-pattern sessionApproval for uncovered paths.
|
|
18
|
+
*
|
|
19
|
+
* The shell command (native `bash` or an aliased shell tool) is read from the
|
|
20
|
+
* injected `BashProgram`, which owns the source text it was parsed from, so
|
|
21
|
+
* this gate does not re-derive the input field name (#574).
|
|
19
22
|
*/
|
|
20
23
|
export function describeBashExternalDirectoryGate(
|
|
21
24
|
tcc: ToolCallContext,
|
|
22
25
|
bashProgram: BashProgram | null,
|
|
23
26
|
resolver: ScopedPermissionResolver,
|
|
24
27
|
): GateResult {
|
|
25
|
-
if (tcc.toolName !== "bash") return null;
|
|
26
|
-
|
|
27
|
-
const command = getNonEmptyString(toRecord(tcc.input).command);
|
|
28
|
-
if (!command) return null;
|
|
29
|
-
|
|
30
28
|
if (!bashProgram) return null;
|
|
29
|
+
const command = bashProgram.commandText();
|
|
31
30
|
|
|
32
31
|
const externalPaths = bashProgram.externalPaths();
|
|
33
32
|
if (externalPaths.length === 0) return null;
|
|
@@ -4,7 +4,6 @@ import type { ScopedPermissionResolver } from "#src/permission-resolver";
|
|
|
4
4
|
import { SessionApproval } from "#src/session-approval";
|
|
5
5
|
import { deriveApprovalPattern } from "#src/session-rules";
|
|
6
6
|
import type { PermissionCheckResult } from "#src/types";
|
|
7
|
-
import { getNonEmptyString, toRecord } from "#src/value-guards";
|
|
8
7
|
import { pickMostRestrictive } from "./candidate-check";
|
|
9
8
|
import type { GateResult } from "./descriptor";
|
|
10
9
|
import { formatPathAskPrompt } from "./path";
|
|
@@ -20,22 +19,22 @@ import type { ToolCallContext } from "./types";
|
|
|
20
19
|
* restrictive result, while prompts, logs, and session approvals use the raw
|
|
21
20
|
* token.
|
|
22
21
|
*
|
|
23
|
-
* Returns `null` when the gate does not apply (
|
|
24
|
-
* no tokens extracted, or all tokens evaluate to `allow`).
|
|
22
|
+
* Returns `null` when the gate does not apply (not a shell invocation, no
|
|
23
|
+
* command, no tokens extracted, or all tokens evaluate to `allow`).
|
|
25
24
|
* Returns a `GateBypass` when all tokens are session-covered.
|
|
26
25
|
* Returns a `GateDescriptor` for the most restrictive token needing a check.
|
|
26
|
+
*
|
|
27
|
+
* The shell command (native `bash` or an aliased shell tool) is read from the
|
|
28
|
+
* injected `BashProgram`, which owns the source text it was parsed from, so
|
|
29
|
+
* this gate does not re-derive the input field name (#574).
|
|
27
30
|
*/
|
|
28
31
|
export function describeBashPathGate(
|
|
29
32
|
tcc: ToolCallContext,
|
|
30
33
|
bashProgram: BashProgram | null,
|
|
31
34
|
resolver: ScopedPermissionResolver,
|
|
32
35
|
): GateResult {
|
|
33
|
-
if (tcc.toolName !== "bash") return null;
|
|
34
|
-
|
|
35
|
-
const command = getNonEmptyString(toRecord(tcc.input).command);
|
|
36
|
-
if (!command) return null;
|
|
37
|
-
|
|
38
36
|
if (!bashProgram) return null;
|
|
37
|
+
const command = bashProgram.commandText();
|
|
39
38
|
|
|
40
39
|
const candidates = bashProgram.pathRuleCandidates();
|
|
41
40
|
if (candidates.length === 0) return null;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { AccessPath } from "#src/access-intent/access-path";
|
|
2
2
|
import { BashProgram } from "#src/access-intent/bash/program";
|
|
3
3
|
import { getPathBearingToolPath } from "#src/access-intent/tool-input-path";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
resolveShellInvocation,
|
|
6
|
+
type ShellInvocation,
|
|
7
|
+
} from "#src/access-intent/tool-kind";
|
|
8
|
+
import type { ShellToolsConfig } from "#src/config-schema";
|
|
5
9
|
import type { PathNormalizer } from "#src/path-normalizer";
|
|
6
10
|
import type { ScopedPermissionResolver } from "#src/permission-resolver";
|
|
7
11
|
import type { SkillPromptEntry } from "#src/skill-prompt-sanitizer";
|
|
@@ -12,7 +16,6 @@ import {
|
|
|
12
16
|
type ToolPreviewFormatterOptions,
|
|
13
17
|
} from "#src/tool-preview-formatter";
|
|
14
18
|
import type { PathRuleTokenMatcher, PermissionCheckResult } from "#src/types";
|
|
15
|
-
import { getNonEmptyString, toRecord } from "#src/value-guards";
|
|
16
19
|
import { resolveBashCommandCheck } from "./bash-command";
|
|
17
20
|
import { describeBashExternalDirectoryGate } from "./bash-external-directory";
|
|
18
21
|
import { describeBashPathGate } from "./bash-path";
|
|
@@ -43,6 +46,12 @@ export interface ToolCallGateInputs {
|
|
|
43
46
|
getToolPreviewLimits(): ToolPreviewFormatterOptions;
|
|
44
47
|
/** The session's path normalizer (platform + cwd baked in). */
|
|
45
48
|
getPathNormalizer(): PathNormalizer;
|
|
49
|
+
/**
|
|
50
|
+
* The configured shell-tool aliases (`shellTools`), or `undefined` when none
|
|
51
|
+
* are set. Consulted by {@link resolveShellInvocation} so an aliased shell
|
|
52
|
+
* tool is gated through the bash stack at parity with native `bash` (#574).
|
|
53
|
+
*/
|
|
54
|
+
getShellToolAliases(): ShellToolsConfig | undefined;
|
|
46
55
|
/**
|
|
47
56
|
* Predicate deciding whether a bare bash token should be promoted into the
|
|
48
57
|
* `path` rule-candidate surface (#509), scoped to the given agent.
|
|
@@ -73,20 +82,24 @@ export class ToolCallGatePipeline {
|
|
|
73
82
|
tcc: ToolCallContext,
|
|
74
83
|
runner: GateRunner,
|
|
75
84
|
): Promise<GateOutcome> {
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
|
|
85
|
+
// Resolve the shell invocation once: native `bash` and any tool recorded in
|
|
86
|
+
// `shellTools` both yield a command (+ optional workdir); every other tool
|
|
87
|
+
// yields null (#574). The three bash gates then share the single BashProgram
|
|
88
|
+
// parsed from that command instead of each re-parsing (#308).
|
|
89
|
+
const shell = resolveShellInvocation(
|
|
90
|
+
tcc.toolName,
|
|
91
|
+
tcc.input,
|
|
92
|
+
this.inputs.getShellToolAliases(),
|
|
93
|
+
);
|
|
79
94
|
const normalizer = this.inputs.getPathNormalizer();
|
|
80
|
-
const bashProgram =
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
)
|
|
89
|
-
: null;
|
|
95
|
+
const bashProgram = shell?.command
|
|
96
|
+
? await BashProgram.parse(
|
|
97
|
+
shell.command,
|
|
98
|
+
normalizer,
|
|
99
|
+
this.inputs.getPromotablePathTokenMatcher(tcc.agentName ?? undefined),
|
|
100
|
+
{ workdir: shell.workdir },
|
|
101
|
+
)
|
|
102
|
+
: null;
|
|
90
103
|
|
|
91
104
|
const formatter = new ToolPreviewFormatter(
|
|
92
105
|
this.inputs.getToolPreviewLimits(),
|
|
@@ -115,8 +128,8 @@ export class ToolCallGatePipeline {
|
|
|
115
128
|
() => {
|
|
116
129
|
const { toolCheck, accessPath } = this.resolvePerToolCheck(
|
|
117
130
|
tcc,
|
|
131
|
+
shell,
|
|
118
132
|
bashProgram,
|
|
119
|
-
command,
|
|
120
133
|
normalizer,
|
|
121
134
|
);
|
|
122
135
|
const toolDescriptor = describeToolGate(
|
|
@@ -124,6 +137,7 @@ export class ToolCallGatePipeline {
|
|
|
124
137
|
toolCheck,
|
|
125
138
|
formatter,
|
|
126
139
|
accessPath,
|
|
140
|
+
shell,
|
|
127
141
|
);
|
|
128
142
|
toolDescriptor.preCheck = toolCheck;
|
|
129
143
|
return toolDescriptor;
|
|
@@ -156,18 +170,31 @@ export class ToolCallGatePipeline {
|
|
|
156
170
|
*/
|
|
157
171
|
private resolvePerToolCheck(
|
|
158
172
|
tcc: ToolCallContext,
|
|
173
|
+
shell: ShellInvocation | null,
|
|
159
174
|
bashProgram: BashProgram | null,
|
|
160
|
-
command: string | null,
|
|
161
175
|
normalizer: PathNormalizer,
|
|
162
176
|
): { toolCheck: PermissionCheckResult; accessPath?: AccessPath } {
|
|
163
|
-
if (
|
|
177
|
+
if (shell) {
|
|
178
|
+
if (bashProgram) {
|
|
179
|
+
return {
|
|
180
|
+
toolCheck: resolveBashCommandCheck(
|
|
181
|
+
bashProgram.commandText(),
|
|
182
|
+
bashProgram.commands(),
|
|
183
|
+
tcc.agentName ?? undefined,
|
|
184
|
+
this.resolver,
|
|
185
|
+
),
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
// A shell invocation whose command did not parse (e.g. empty) still
|
|
189
|
+
// resolves on the `bash` surface, so an aliased tool never falls through
|
|
190
|
+
// to its own extension-tool surface.
|
|
164
191
|
return {
|
|
165
|
-
toolCheck:
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
),
|
|
192
|
+
toolCheck: this.resolver.resolve({
|
|
193
|
+
kind: "tool",
|
|
194
|
+
surface: "bash",
|
|
195
|
+
input: { command: shell.command },
|
|
196
|
+
agentName: tcc.agentName ?? undefined,
|
|
197
|
+
}),
|
|
171
198
|
};
|
|
172
199
|
}
|
|
173
200
|
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { AccessPath } from "#src/access-intent/access-path";
|
|
2
2
|
import { PATH_BEARING_TOOLS } from "#src/access-intent/path-surfaces";
|
|
3
3
|
import { getPathBearingToolPath } from "#src/access-intent/tool-input-path";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
classifyToolKind,
|
|
6
|
+
type ShellInvocation,
|
|
7
|
+
} from "#src/access-intent/tool-kind";
|
|
5
8
|
import { suggestSessionPattern } from "#src/pattern-suggest";
|
|
6
9
|
import { formatAskPrompt } from "#src/permission-prompts";
|
|
7
10
|
import { SessionApproval } from "#src/session-approval";
|
|
@@ -20,11 +23,11 @@ import type { ToolCallContext } from "./types";
|
|
|
20
23
|
* others (or a path-bearing tool with no path) → catch-all wildcard.
|
|
21
24
|
*/
|
|
22
25
|
function deriveSuggestionValue(
|
|
23
|
-
|
|
26
|
+
toolName: string,
|
|
24
27
|
check: PermissionCheckResult,
|
|
25
28
|
accessPath?: AccessPath,
|
|
26
29
|
): string {
|
|
27
|
-
switch (classifyToolKind(
|
|
30
|
+
switch (classifyToolKind(toolName)) {
|
|
28
31
|
case "bash":
|
|
29
32
|
return check.command ?? "";
|
|
30
33
|
case "mcp":
|
|
@@ -45,7 +48,14 @@ export function describeToolGate(
|
|
|
45
48
|
check: PermissionCheckResult,
|
|
46
49
|
formatter: ToolPreviewFormatter,
|
|
47
50
|
accessPath?: AccessPath,
|
|
51
|
+
shell?: ShellInvocation | null,
|
|
48
52
|
): GateDescriptor {
|
|
53
|
+
// A shell invocation (native `bash` or an aliased shell tool) is gated on the
|
|
54
|
+
// `bash` surface — its session rule, decision value, and suggestion are
|
|
55
|
+
// bash-shaped — while the invoked tool name is preserved in the prompt and
|
|
56
|
+
// review log so a user sees which tool actually ran (#574).
|
|
57
|
+
const gateSurface = shell ? "bash" : tcc.toolName;
|
|
58
|
+
|
|
49
59
|
const permissionLogContext = formatter.getPermissionLogContext(
|
|
50
60
|
check,
|
|
51
61
|
tcc.input,
|
|
@@ -54,8 +64,8 @@ export function describeToolGate(
|
|
|
54
64
|
|
|
55
65
|
// Compute session approval suggestion for the "for this session" option.
|
|
56
66
|
const suggestion = suggestSessionPattern(
|
|
57
|
-
|
|
58
|
-
deriveSuggestionValue(
|
|
67
|
+
gateSurface,
|
|
68
|
+
deriveSuggestionValue(gateSurface, check, accessPath),
|
|
59
69
|
);
|
|
60
70
|
|
|
61
71
|
const askMessage = formatAskPrompt(
|
|
@@ -66,7 +76,7 @@ export function describeToolGate(
|
|
|
66
76
|
);
|
|
67
77
|
|
|
68
78
|
return {
|
|
69
|
-
surface:
|
|
79
|
+
surface: gateSurface,
|
|
70
80
|
input: tcc.input,
|
|
71
81
|
denialContext: {
|
|
72
82
|
kind: "tool",
|
|
@@ -95,9 +105,9 @@ export function describeToolGate(
|
|
|
95
105
|
...permissionLogContext,
|
|
96
106
|
},
|
|
97
107
|
decision: {
|
|
98
|
-
surface:
|
|
108
|
+
surface: gateSurface,
|
|
99
109
|
value: deriveDecisionValue(
|
|
100
|
-
|
|
110
|
+
gateSurface,
|
|
101
111
|
check,
|
|
102
112
|
getPathBearingToolPath(tcc.toolName, tcc.input) ?? undefined,
|
|
103
113
|
),
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
getActiveAgentNameFromSystemPrompt,
|
|
6
6
|
} from "./active-agent";
|
|
7
7
|
import type { AuthorizerSelectionLifecycle } from "./authority/authorizer-selection";
|
|
8
|
+
import type { ShellToolsConfig } from "./config-schema";
|
|
8
9
|
import type { SessionConfigStore } from "./config-store";
|
|
9
10
|
import type { PermissionSystemExtensionConfig } from "./extension-config";
|
|
10
11
|
import type { ExtensionPaths } from "./extension-paths";
|
|
@@ -205,6 +206,16 @@ export class PermissionSession implements ToolCallGateInputs {
|
|
|
205
206
|
return resolveToolPreviewLimits(this.config);
|
|
206
207
|
}
|
|
207
208
|
|
|
209
|
+
/**
|
|
210
|
+
* The configured shell-tool aliases (`shellTools`), mapping a non-`bash` tool
|
|
211
|
+
* name to the input arguments holding its command and optional working
|
|
212
|
+
* directory. `undefined` when no aliases are configured. Consumed by the
|
|
213
|
+
* gate pipeline's {@link resolveShellInvocation} consult (#574).
|
|
214
|
+
*/
|
|
215
|
+
getShellToolAliases(): ShellToolsConfig | undefined {
|
|
216
|
+
return this.config.shellTools;
|
|
217
|
+
}
|
|
218
|
+
|
|
208
219
|
// ── Path normalization ────────────────────────────────────────────────
|
|
209
220
|
|
|
210
221
|
/**
|