@diegopetrucci/pi-extensions 0.1.5 → 0.1.7
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 +37 -17
- package/extensions/confirm-destructive/README.md +43 -0
- package/extensions/confirm-destructive/index.ts +59 -0
- package/extensions/confirm-destructive/package.json +27 -0
- package/extensions/permission-gate/README.md +45 -0
- package/extensions/permission-gate/index.ts +34 -0
- package/extensions/permission-gate/package.json +27 -0
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -8,6 +8,8 @@ A collection of [pi](https://github.com/badlogic/pi-mono) agent extensions I mad
|
|
|
8
8
|
|---|---|
|
|
9
9
|
| [`minimal-footer`](./extensions/minimal-footer) | Replaces pi's built-in footer with a minimal two-line layout: branch/repo on the first line, context/model on the second. |
|
|
10
10
|
| [`oracle`](./extensions/oracle) | Adds an Amp-style read-only oracle tool that auto-selects the strongest reasoning model on the current provider/subscription, covers pi’s built-in providers with hardcoded rankings, sets reasoning to xhigh by default, and shows live status while running. |
|
|
11
|
+
| [`permission-gate`](./extensions/permission-gate) | Prompts for confirmation before dangerous bash commands like `rm -rf`, `sudo`, and `chmod 777`. |
|
|
12
|
+
| [`confirm-destructive`](./extensions/confirm-destructive) | Confirms before destructive session actions like clear, switch, and fork. |
|
|
11
13
|
|
|
12
14
|
## Install
|
|
13
15
|
|
|
@@ -22,7 +24,7 @@ pi install git:github.com/diegopetrucci/pi-extensions
|
|
|
22
24
|
Or pin to a tagged version:
|
|
23
25
|
|
|
24
26
|
```bash
|
|
25
|
-
pi install git:github.com/diegopetrucci/pi-extensions@v0.1.
|
|
27
|
+
pi install git:github.com/diegopetrucci/pi-extensions@v0.1.7
|
|
26
28
|
```
|
|
27
29
|
|
|
28
30
|
### npm
|
|
@@ -53,6 +55,14 @@ pi install npm:@diegopetrucci/pi-minimal-footer
|
|
|
53
55
|
pi install npm:@diegopetrucci/pi-oracle
|
|
54
56
|
```
|
|
55
57
|
|
|
58
|
+
```bash
|
|
59
|
+
pi install npm:@diegopetrucci/pi-permission-gate
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pi install npm:@diegopetrucci/pi-confirm-destructive
|
|
64
|
+
```
|
|
65
|
+
|
|
56
66
|
### Option 2: filter the repo package
|
|
57
67
|
|
|
58
68
|
If you prefer the collection package, you can filter it in your pi settings.
|
|
@@ -83,25 +93,35 @@ Oracle only:
|
|
|
83
93
|
}
|
|
84
94
|
```
|
|
85
95
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
The repo is set up to support both:
|
|
89
|
-
|
|
90
|
-
- the collection package: `@diegopetrucci/pi-extensions`
|
|
91
|
-
- standalone extension packages like `@diegopetrucci/pi-minimal-footer`
|
|
96
|
+
Permission gate only:
|
|
92
97
|
|
|
93
|
-
|
|
98
|
+
```json
|
|
99
|
+
{
|
|
100
|
+
"packages": [
|
|
101
|
+
{
|
|
102
|
+
"source": "npm:@diegopetrucci/pi-extensions",
|
|
103
|
+
"extensions": ["extensions/permission-gate/index.ts"]
|
|
104
|
+
}
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
```
|
|
94
108
|
|
|
95
|
-
|
|
109
|
+
Confirm destructive only:
|
|
96
110
|
|
|
97
|
-
|
|
111
|
+
```json
|
|
112
|
+
{
|
|
113
|
+
"packages": [
|
|
114
|
+
{
|
|
115
|
+
"source": "npm:@diegopetrucci/pi-extensions",
|
|
116
|
+
"extensions": ["extensions/confirm-destructive/index.ts"]
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
```
|
|
98
121
|
|
|
99
|
-
|
|
100
|
-
- [Release notes for v0.1.5](./docs/release-notes-v0.1.5.md)
|
|
101
|
-
- [GitHub release body for v0.1.5](./docs/github-release-v0.1.5.md)
|
|
102
|
-
- [Publish checklist for v0.1.5](./docs/publish-checklist-v0.1.5.md)
|
|
103
|
-
- [Announcement copy for v0.1.5](./docs/announcement-v0.1.5.md)
|
|
122
|
+
## npm publishing
|
|
104
123
|
|
|
105
|
-
|
|
124
|
+
The repo is set up to support both:
|
|
106
125
|
|
|
107
|
-
|
|
126
|
+
- the collection package: `@diegopetrucci/pi-extensions`
|
|
127
|
+
- standalone extension packages like `@diegopetrucci/pi-minimal-footer`, `@diegopetrucci/pi-oracle`, `@diegopetrucci/pi-permission-gate`, and `@diegopetrucci/pi-confirm-destructive`
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# confirm-destructive
|
|
2
|
+
|
|
3
|
+
A small pi extension that asks for confirmation before destructive session actions.
|
|
4
|
+
|
|
5
|
+
This is adapted from the original `confirm-destructive.ts` example in [`badlogic/pi-mono`](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/examples/extensions/confirm-destructive.ts) and kept basically the same.
|
|
6
|
+
|
|
7
|
+
## What it checks
|
|
8
|
+
|
|
9
|
+
- clearing the current session
|
|
10
|
+
- switching sessions when the current session has user messages
|
|
11
|
+
- forking from an entry
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
### Standalone npm package
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pi install npm:@diegopetrucci/pi-confirm-destructive
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Collection package
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pi install npm:@diegopetrucci/pi-extensions
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### GitHub package
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pi install git:github.com/diegopetrucci/pi-extensions
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Then reload pi:
|
|
34
|
+
|
|
35
|
+
```text
|
|
36
|
+
/reload
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Notes
|
|
40
|
+
|
|
41
|
+
- Hooks `session_before_switch` and `session_before_fork`.
|
|
42
|
+
- Cancels the action when the user declines.
|
|
43
|
+
- Does nothing in non-interactive mode.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Confirm Destructive Actions Extension
|
|
3
|
+
*
|
|
4
|
+
* Prompts for confirmation before destructive session actions (clear, switch, branch).
|
|
5
|
+
* Demonstrates how to cancel session events using the before_* events.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ExtensionAPI, SessionBeforeSwitchEvent, SessionMessageEntry } from "@mariozechner/pi-coding-agent";
|
|
9
|
+
|
|
10
|
+
export default function (pi: ExtensionAPI) {
|
|
11
|
+
pi.on("session_before_switch", async (event: SessionBeforeSwitchEvent, ctx) => {
|
|
12
|
+
if (!ctx.hasUI) return;
|
|
13
|
+
|
|
14
|
+
if (event.reason === "new") {
|
|
15
|
+
const confirmed = await ctx.ui.confirm(
|
|
16
|
+
"Clear session?",
|
|
17
|
+
"This will delete all messages in the current session.",
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
if (!confirmed) {
|
|
21
|
+
ctx.ui.notify("Clear cancelled", "info");
|
|
22
|
+
return { cancel: true };
|
|
23
|
+
}
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// reason === "resume" - check if there are unsaved changes (messages since last assistant response)
|
|
28
|
+
const entries = ctx.sessionManager.getEntries();
|
|
29
|
+
const hasUnsavedWork = entries.some(
|
|
30
|
+
(e): e is SessionMessageEntry => e.type === "message" && e.message.role === "user",
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
if (hasUnsavedWork) {
|
|
34
|
+
const confirmed = await ctx.ui.confirm(
|
|
35
|
+
"Switch session?",
|
|
36
|
+
"You have messages in the current session. Switch anyway?",
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
if (!confirmed) {
|
|
40
|
+
ctx.ui.notify("Switch cancelled", "info");
|
|
41
|
+
return { cancel: true };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
pi.on("session_before_fork", async (event, ctx) => {
|
|
47
|
+
if (!ctx.hasUI) return;
|
|
48
|
+
|
|
49
|
+
const choice = await ctx.ui.select(`Fork from entry ${event.entryId.slice(0, 8)}?`, [
|
|
50
|
+
"Yes, create fork",
|
|
51
|
+
"No, stay in current session",
|
|
52
|
+
]);
|
|
53
|
+
|
|
54
|
+
if (choice !== "Yes, create fork") {
|
|
55
|
+
ctx.ui.notify("Fork cancelled", "info");
|
|
56
|
+
return { cancel: true };
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@diegopetrucci/pi-confirm-destructive",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A pi extension that confirms destructive session actions.",
|
|
5
|
+
"keywords": ["pi-package", "pi", "session", "safety"],
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/diegopetrucci/pi-extensions.git",
|
|
10
|
+
"directory": "extensions/confirm-destructive"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"index.ts",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"pi": {
|
|
20
|
+
"extensions": [
|
|
21
|
+
"index.ts"
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@mariozechner/pi-coding-agent": "*"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# permission-gate
|
|
2
|
+
|
|
3
|
+
A small pi extension that prompts for confirmation before running potentially dangerous bash commands.
|
|
4
|
+
|
|
5
|
+
This is adapted from the original `permission-gate.ts` example in [`badlogic/pi-mono`](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/examples/extensions/permission-gate.ts) and kept basically the same.
|
|
6
|
+
|
|
7
|
+
## What it checks
|
|
8
|
+
|
|
9
|
+
- `rm -rf`
|
|
10
|
+
- `sudo`
|
|
11
|
+
- `chmod` / `chown` with `777`
|
|
12
|
+
|
|
13
|
+
If pi is running without an interactive UI, it blocks matching commands by default.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
### Standalone npm package
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pi install npm:@diegopetrucci/pi-permission-gate
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Collection package
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pi install npm:@diegopetrucci/pi-extensions
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### GitHub package
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pi install git:github.com/diegopetrucci/pi-extensions
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Then reload pi:
|
|
36
|
+
|
|
37
|
+
```text
|
|
38
|
+
/reload
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Notes
|
|
42
|
+
|
|
43
|
+
- Hooks the `tool_call` event.
|
|
44
|
+
- Only inspects the `bash` tool.
|
|
45
|
+
- Prompts with a simple `Yes` / `No` selector before allowing dangerous commands.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Permission Gate Extension
|
|
3
|
+
*
|
|
4
|
+
* Prompts for confirmation before running potentially dangerous bash commands.
|
|
5
|
+
* Patterns checked: rm -rf, sudo, chmod/chown 777
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
9
|
+
|
|
10
|
+
export default function (pi: ExtensionAPI) {
|
|
11
|
+
const dangerousPatterns = [/\brm\s+(-rf?|--recursive)/i, /\bsudo\b/i, /\b(chmod|chown)\b.*777/i];
|
|
12
|
+
|
|
13
|
+
pi.on("tool_call", async (event, ctx) => {
|
|
14
|
+
if (event.toolName !== "bash") return undefined;
|
|
15
|
+
|
|
16
|
+
const command = event.input.command as string;
|
|
17
|
+
const isDangerous = dangerousPatterns.some((p) => p.test(command));
|
|
18
|
+
|
|
19
|
+
if (isDangerous) {
|
|
20
|
+
if (!ctx.hasUI) {
|
|
21
|
+
// In non-interactive mode, block by default
|
|
22
|
+
return { block: true, reason: "Dangerous command blocked (no UI for confirmation)" };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const choice = await ctx.ui.select(`⚠️ Dangerous command:\n\n ${command}\n\nAllow?`, ["Yes", "No"]);
|
|
26
|
+
|
|
27
|
+
if (choice !== "Yes") {
|
|
28
|
+
return { block: true, reason: "Blocked by user" };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return undefined;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@diegopetrucci/pi-permission-gate",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A pi extension that prompts before dangerous bash commands.",
|
|
5
|
+
"keywords": ["pi-package", "pi", "security", "bash"],
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/diegopetrucci/pi-extensions.git",
|
|
10
|
+
"directory": "extensions/permission-gate"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"index.ts",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"pi": {
|
|
20
|
+
"extensions": [
|
|
21
|
+
"index.ts"
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@mariozechner/pi-coding-agent": "*"
|
|
26
|
+
}
|
|
27
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diegopetrucci/pi-extensions",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "A collection of pi extensions, including a minimal custom footer
|
|
3
|
+
"version": "0.1.7",
|
|
4
|
+
"description": "A collection of pi extensions, including a minimal custom footer, an Amp-style oracle, a permission gate for dangerous bash commands, and confirm-before-destructive session actions.",
|
|
5
5
|
"keywords": ["pi-package", "pi", "terminal", "agent"],
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -27,7 +27,9 @@
|
|
|
27
27
|
"pi": {
|
|
28
28
|
"extensions": [
|
|
29
29
|
"./extensions/minimal-footer/index.ts",
|
|
30
|
-
"./extensions/oracle/index.ts"
|
|
30
|
+
"./extensions/oracle/index.ts",
|
|
31
|
+
"./extensions/permission-gate/index.ts",
|
|
32
|
+
"./extensions/confirm-destructive/index.ts"
|
|
31
33
|
],
|
|
32
34
|
"image": "https://raw.githubusercontent.com/diegopetrucci/pi-extensions/main/assets/oracle-preview.svg"
|
|
33
35
|
}
|