@staff0rd/assist 0.392.0 → 0.394.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/dist/commands/sessions/web/bundle.js +77 -77
- package/dist/index.js +326 -180
- package/package.json +2 -1
- package/pi/permission-gate.ts +46 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@staff0rd/assist",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.394.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"dist",
|
|
13
13
|
"claude",
|
|
14
14
|
"codex",
|
|
15
|
+
"pi",
|
|
15
16
|
"allowed.cli-reads",
|
|
16
17
|
"allowed.cli-writes"
|
|
17
18
|
],
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
|
|
4
|
+
type Decision = { decision: "allow" | "deny" | "gate"; reason?: string };
|
|
5
|
+
|
|
6
|
+
function classify(command: string): Decision {
|
|
7
|
+
try {
|
|
8
|
+
const result = spawnSync("assist", ["pi-hook"], {
|
|
9
|
+
input: JSON.stringify({ toolName: "bash", command }),
|
|
10
|
+
encoding: "utf8",
|
|
11
|
+
});
|
|
12
|
+
const out = result.stdout?.trim();
|
|
13
|
+
if (!out) return { decision: "gate" };
|
|
14
|
+
return JSON.parse(out) as Decision;
|
|
15
|
+
} catch {
|
|
16
|
+
return { decision: "gate" };
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default function (pi: ExtensionAPI) {
|
|
21
|
+
pi.on("tool_call", async (event, ctx) => {
|
|
22
|
+
if (event.toolName !== "bash") return undefined;
|
|
23
|
+
|
|
24
|
+
const command =
|
|
25
|
+
typeof event.input.command === "string" ? event.input.command.trim() : "";
|
|
26
|
+
if (!command) return undefined;
|
|
27
|
+
|
|
28
|
+
const { decision, reason } = classify(command);
|
|
29
|
+
|
|
30
|
+
if (decision === "allow") return undefined;
|
|
31
|
+
if (decision === "deny")
|
|
32
|
+
return {
|
|
33
|
+
block: true,
|
|
34
|
+
reason: reason ?? "Denied by the assist allowlist",
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
if (!ctx.hasUI) return undefined;
|
|
38
|
+
|
|
39
|
+
const choice = await ctx.ui.select(
|
|
40
|
+
"Command not in the assist allowlist:\n\n " + command + "\n\nRun it?",
|
|
41
|
+
["Yes", "No"],
|
|
42
|
+
);
|
|
43
|
+
if (choice !== "Yes") return { block: true, reason: "Blocked by user" };
|
|
44
|
+
return undefined;
|
|
45
|
+
});
|
|
46
|
+
}
|