@gotgenes/pi-permission-system 14.0.0 → 14.0.1
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 +7 -0
- package/package.json +1 -1
- package/src/bash-arity.ts +24 -0
- package/src/input-normalizer.ts +7 -1
- package/src/pattern-suggest.ts +8 -4
- package/test/bash-arity.test.ts +39 -1
- package/test/input-normalizer.test.ts +28 -0
- package/test/pattern-suggest.test.ts +24 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,13 @@ 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
|
+
## [14.0.1](https://github.com/gotgenes/pi-packages/compare/pi-permission-system-v14.0.0...pi-permission-system-v14.0.1) (2026-06-19)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **pi-permission-system:** strip shell comment lines from bash commands before matching ([d045591](https://github.com/gotgenes/pi-packages/commit/d0455915d6d4ce50534884639e516a9e1ef38976))
|
|
14
|
+
|
|
8
15
|
## [14.0.0](https://github.com/gotgenes/pi-packages/compare/pi-permission-system-v13.2.0...pi-permission-system-v14.0.0) (2026-06-17)
|
|
9
16
|
|
|
10
17
|
|
package/package.json
CHANGED
package/src/bash-arity.ts
CHANGED
|
@@ -184,3 +184,27 @@ export function prefix(tokens: string[]): string[] {
|
|
|
184
184
|
// Unknown command — default arity 1.
|
|
185
185
|
return [tokens[0]];
|
|
186
186
|
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Remove shell comment lines from a bash command string.
|
|
190
|
+
*
|
|
191
|
+
* A comment line is one whose first non-whitespace character is `#`. Agents
|
|
192
|
+
* frequently prepend descriptive comments before the real command
|
|
193
|
+
* (e.g. `"# Check debug logs\nfind ..."`); such prefixes defeat wildcard
|
|
194
|
+
* pattern matching and session-approval suggestions, which tokenize the
|
|
195
|
+
* leading text. Stripping comment lines lets matching operate on the actual
|
|
196
|
+
* command.
|
|
197
|
+
*
|
|
198
|
+
* The original command is never returned: when every line is a comment (or
|
|
199
|
+
* the input is blank) an empty string is returned, and each caller applies
|
|
200
|
+
* its own fallback.
|
|
201
|
+
*
|
|
202
|
+
* @param command - Raw bash command, possibly multi-line.
|
|
203
|
+
* @returns The command with comment lines removed and surrounding whitespace
|
|
204
|
+
* trimmed, or an empty string when nothing meaningful remains.
|
|
205
|
+
*/
|
|
206
|
+
export function stripBashCommentLines(command: string): string {
|
|
207
|
+
const lines = command.split("\n");
|
|
208
|
+
const meaningful = lines.filter((line) => !/^\s*#/.test(line));
|
|
209
|
+
return meaningful.join("\n").trim();
|
|
210
|
+
}
|
package/src/input-normalizer.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { stripBashCommentLines } from "./bash-arity";
|
|
1
2
|
import { getNonEmptyString, toRecord } from "./common";
|
|
2
3
|
import { createMcpPermissionTargets } from "./mcp-targets";
|
|
3
4
|
import { getPathPolicyValues, PATH_BEARING_TOOLS } from "./path-utils";
|
|
@@ -92,9 +93,14 @@ export function normalizeInput(
|
|
|
92
93
|
if (toolName === "bash") {
|
|
93
94
|
const record = toRecord(input);
|
|
94
95
|
const command = typeof record.command === "string" ? record.command : "";
|
|
96
|
+
// Strip leading shell comment lines so pattern matching operates on the
|
|
97
|
+
// actual command, not a `# description` prefix agents often prepend.
|
|
98
|
+
// Fall back to the raw command when stripping leaves nothing, so an
|
|
99
|
+
// all-comment command still evaluates against its literal text.
|
|
100
|
+
const matchValue = stripBashCommentLines(command) || command;
|
|
95
101
|
return {
|
|
96
102
|
surface: "bash",
|
|
97
|
-
values: [
|
|
103
|
+
values: [matchValue],
|
|
98
104
|
resultExtras: { command },
|
|
99
105
|
};
|
|
100
106
|
}
|
package/src/pattern-suggest.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { prefix } from "./bash-arity";
|
|
1
|
+
import { prefix, stripBashCommentLines } from "./bash-arity";
|
|
2
2
|
import { PATH_BEARING_TOOLS } from "./path-utils";
|
|
3
3
|
import { deriveApprovalPattern } from "./session-rules";
|
|
4
4
|
|
|
@@ -26,11 +26,15 @@ export interface SessionApprovalSuggestion {
|
|
|
26
26
|
export function suggestBashPattern(command: string): string {
|
|
27
27
|
const trimmed = command.trim();
|
|
28
28
|
if (!trimmed) return "";
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
// Strip leading shell comment lines so the suggestion is based on the
|
|
30
|
+
// actual command, not a `# description` prefix agents often prepend.
|
|
31
|
+
const stripped = stripBashCommentLines(trimmed);
|
|
32
|
+
if (!stripped) return "";
|
|
33
|
+
const tokens = stripped.split(/\s+/);
|
|
34
|
+
if (tokens.length === 1) return stripped;
|
|
31
35
|
const meaningful = prefix(tokens);
|
|
32
36
|
if (meaningful.length >= tokens.length) {
|
|
33
|
-
return `${
|
|
37
|
+
return `${stripped}*`;
|
|
34
38
|
}
|
|
35
39
|
return `${meaningful.join(" ")} *`;
|
|
36
40
|
}
|
package/test/bash-arity.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { ARITY, prefix } from "#src/bash-arity";
|
|
2
|
+
import { ARITY, prefix, stripBashCommentLines } from "#src/bash-arity";
|
|
3
3
|
|
|
4
4
|
describe("ARITY dictionary", () => {
|
|
5
5
|
it("is exported as a plain object", () => {
|
|
@@ -104,3 +104,41 @@ describe("prefix", () => {
|
|
|
104
104
|
expect(prefix(["ls", "-la", "/tmp"])).toEqual(["ls"]);
|
|
105
105
|
});
|
|
106
106
|
});
|
|
107
|
+
|
|
108
|
+
describe("stripBashCommentLines", () => {
|
|
109
|
+
it("removes a single leading comment line", () => {
|
|
110
|
+
expect(
|
|
111
|
+
stripBashCommentLines("# Check debug logs\nfind /home -type f"),
|
|
112
|
+
).toBe("find /home -type f");
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("removes multiple leading comment lines", () => {
|
|
116
|
+
expect(
|
|
117
|
+
stripBashCommentLines("# Step 1\n# Step 2\ngit status --short"),
|
|
118
|
+
).toBe("git status --short");
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("returns empty string when all lines are comments", () => {
|
|
122
|
+
expect(stripBashCommentLines("# just a comment")).toBe("");
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("returns empty string for blank input", () => {
|
|
126
|
+
expect(stripBashCommentLines("")).toBe("");
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("returns the command unchanged when no comment lines are present", () => {
|
|
130
|
+
expect(stripBashCommentLines("grep -rn foo src/")).toBe(
|
|
131
|
+
"grep -rn foo src/",
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("trims surrounding whitespace from the result", () => {
|
|
136
|
+
expect(stripBashCommentLines("\n\n ls -la \n")).toBe("ls -la");
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("treats indented comment lines as comments", () => {
|
|
140
|
+
expect(stripBashCommentLines(" # indented comment\necho hi")).toBe(
|
|
141
|
+
"echo hi",
|
|
142
|
+
);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
@@ -198,6 +198,34 @@ describe("normalizeInput — non-MCP surfaces", () => {
|
|
|
198
198
|
expect(result.values).toEqual([""]);
|
|
199
199
|
expect(result.resultExtras).toEqual({ command: "" });
|
|
200
200
|
});
|
|
201
|
+
|
|
202
|
+
it("strips leading comment lines from values but keeps original in resultExtras", () => {
|
|
203
|
+
const cmd = "# Check debug logs\nfind /home -path '*debug*' -type f";
|
|
204
|
+
const result = normalizeInput("bash", { command: cmd }, []);
|
|
205
|
+
expect(result.values).toEqual(["find /home -path '*debug*' -type f"]);
|
|
206
|
+
expect(result.resultExtras).toEqual({ command: cmd });
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it("strips multiple comment lines", () => {
|
|
210
|
+
const cmd = "# Step 1\n# Step 2\ngit status --short";
|
|
211
|
+
const result = normalizeInput("bash", { command: cmd }, []);
|
|
212
|
+
expect(result.values).toEqual(["git status --short"]);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("preserves command when no comment lines present", () => {
|
|
216
|
+
const result = normalizeInput(
|
|
217
|
+
"bash",
|
|
218
|
+
{ command: "grep -rn foo src/" },
|
|
219
|
+
[],
|
|
220
|
+
);
|
|
221
|
+
expect(result.values).toEqual(["grep -rn foo src/"]);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("falls back to original when all lines are comments", () => {
|
|
225
|
+
const cmd = "# just a comment";
|
|
226
|
+
const result = normalizeInput("bash", { command: cmd }, []);
|
|
227
|
+
expect(result.values).toEqual(["# just a comment"]);
|
|
228
|
+
});
|
|
201
229
|
});
|
|
202
230
|
|
|
203
231
|
describe("path-bearing tools (read, write, edit, grep, find, ls)", () => {
|
|
@@ -42,6 +42,30 @@ describe("suggestBashPattern", () => {
|
|
|
42
42
|
"docker compose up *",
|
|
43
43
|
);
|
|
44
44
|
});
|
|
45
|
+
|
|
46
|
+
it("strips leading comment lines and suggests based on the actual command", () => {
|
|
47
|
+
expect(
|
|
48
|
+
suggestBashPattern(
|
|
49
|
+
"# Check debug logs\nfind /home -path '*debug*' -type f",
|
|
50
|
+
),
|
|
51
|
+
).toBe("find *");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("strips multiple leading comment lines", () => {
|
|
55
|
+
expect(suggestBashPattern("# Step 1\n# Step 2\ngit status --short")).toBe(
|
|
56
|
+
"git status *",
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("returns empty for comment-only input", () => {
|
|
61
|
+
expect(suggestBashPattern("# just a comment")).toBe("");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("handles mixed comment and command lines", () => {
|
|
65
|
+
expect(suggestBashPattern("# description\nrm -rf ./build; echo done")).toBe(
|
|
66
|
+
"rm *",
|
|
67
|
+
);
|
|
68
|
+
});
|
|
45
69
|
});
|
|
46
70
|
|
|
47
71
|
describe("suggestMcpPattern", () => {
|