@chrischow/pi-lockdown 0.1.0 → 0.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.
- package/README.md +33 -94
- package/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +4 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -76
- package/dist/index.js.map +1 -1
- package/dist/utils.d.ts +3 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +24 -2
- package/dist/utils.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -8,6 +8,31 @@ A [Pi](https://pi.dev/) extension that adds security constraints to the agent's
|
|
|
8
8
|
pi install npm:@chrischow/pi-lockdown
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
## Usage
|
|
12
|
+
Just run Pi.
|
|
13
|
+
|
|
14
|
+
If you need to amend settings for the session:
|
|
15
|
+
|
|
16
|
+
| Command | Description |
|
|
17
|
+
|---------|-------------|
|
|
18
|
+
| `/lockdown:session-permissions` | Open the interactive session permissions dialog |
|
|
19
|
+
| `/lockdown:reset` | Reset all permissions to settings/default values |
|
|
20
|
+
|
|
21
|
+
**Note:** `/lockdown:session-permissions` allows you to toggle any of the 16 permission slots on the fly. Changes apply immediately and last for the current session only.
|
|
22
|
+
|
|
23
|
+
## What It Does
|
|
24
|
+
When you start Pi, Lockdown automatically sets the tools listed in the `tools` (default Pi tools, less Bash) and `customTools` properties in your settings.
|
|
25
|
+
|
|
26
|
+
On every tool call, Lockdown evaluates (1) whether the target path is internal or external, (2) whether the path matches a proteted pattern, and (3) what is the tool call. Lockdown then applies the appropriate permission:
|
|
27
|
+
|
|
28
|
+
- `allow`: Execution continues
|
|
29
|
+
- `warn`: Execution is halted - you must confirm the action
|
|
30
|
+
- `block`: Execution is blocked without confirmation from you
|
|
31
|
+
|
|
32
|
+
### Empty write protection
|
|
33
|
+
|
|
34
|
+
Lockdown also blocks empty writes (`write` with empty content) as a safeguard against file soft-deletion workarounds.
|
|
35
|
+
|
|
11
36
|
## Configuration
|
|
12
37
|
Add a `lockdown` property in your project or global `settings.json` with one or more of the keys as outlined in the default settings below. Configuration is optional: any omitted fields fall back to the built-in defaults.
|
|
13
38
|
|
|
@@ -26,24 +51,28 @@ Add a `lockdown` property in your project or global `settings.json` with one or
|
|
|
26
51
|
"protected": {
|
|
27
52
|
"read": "block",
|
|
28
53
|
"write": "block",
|
|
29
|
-
"edit": "block"
|
|
54
|
+
"edit": "block",
|
|
55
|
+
"other": "block"
|
|
30
56
|
},
|
|
31
57
|
"unprotected": {
|
|
32
58
|
"read": "warn",
|
|
33
59
|
"write": "block",
|
|
34
|
-
"edit": "block"
|
|
60
|
+
"edit": "block",
|
|
61
|
+
"other": "block"
|
|
35
62
|
}
|
|
36
63
|
},
|
|
37
64
|
"internal": {
|
|
38
65
|
"protected": {
|
|
39
66
|
"read": "warn",
|
|
40
67
|
"write": "warn",
|
|
41
|
-
"edit": "warn"
|
|
68
|
+
"edit": "warn",
|
|
69
|
+
"other": "warn"
|
|
42
70
|
},
|
|
43
71
|
"unprotected": {
|
|
44
72
|
"read": "allow",
|
|
45
73
|
"write": "warn",
|
|
46
|
-
"edit": "warn"
|
|
74
|
+
"edit": "warn",
|
|
75
|
+
"other": "warn"
|
|
47
76
|
}
|
|
48
77
|
}
|
|
49
78
|
}
|
|
@@ -57,93 +86,3 @@ Default protected patterns:
|
|
|
57
86
|
**/.git/**
|
|
58
87
|
**/node_modules/**
|
|
59
88
|
```
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
## Usage
|
|
63
|
-
|
|
64
|
-
## What It Does
|
|
65
|
-
When you start Pi, Lockdown automatically sets the
|
|
66
|
-
|
|
67
|
-
## Features
|
|
68
|
-
|
|
69
|
-
- **Bash blocking** — All `bash` tool calls are blocked by default
|
|
70
|
-
- **Granular permissions** — Three modes per permission: `allow`, `warn`, `block`
|
|
71
|
-
- **Two dimensions of control**:
|
|
72
|
-
- **Location**: internal (within the project) vs. external (outside the project)
|
|
73
|
-
- **Protection level**: protected (matching `protectedPatterns`) vs. unprotected (everything else)
|
|
74
|
-
- **Interactive session configuration** — Adjust permissions mid-session via a TUI dialog
|
|
75
|
-
- **Settings persistence** — Per-project or global settings via `settings.json`
|
|
76
|
-
- **Quick reset** — One command to restore all permissions to defaults
|
|
77
|
-
|
|
78
|
-
## Default Permissions
|
|
79
|
-
|
|
80
|
-
| Location | Protection | Read | Edit | Write |
|
|
81
|
-
|----------|------------|------|------|-------|
|
|
82
|
-
| **External** | Protected | `block` | `block` | `block` |
|
|
83
|
-
| **External** | Unprotected | `warn` | `block` | `block` |
|
|
84
|
-
| **Internal** | Protected | `warn` | `warn` | `warn` |
|
|
85
|
-
| **Internal** | Unprotected | `allow` | `warn` | `warn` |
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
### Per-session override
|
|
91
|
-
|
|
92
|
-
Run the `/lockdown:session-permissions` command to open an interactive TUI where you can toggle any of the 12 permission slots on the fly. Changes apply immediately and last for the current session only.
|
|
93
|
-
|
|
94
|
-
## Commands
|
|
95
|
-
|
|
96
|
-
| Command | Description |
|
|
97
|
-
|---------|-------------|
|
|
98
|
-
| `/lockdown:session-permissions` | Open the interactive session permissions dialog |
|
|
99
|
-
| `/lockdown:reset` | Reset all permissions to settings/default values |
|
|
100
|
-
|
|
101
|
-
## How it Works
|
|
102
|
-
|
|
103
|
-
1. On `session_start`, lockdown sets the agent's active tool list to the safe subset: `read`, `edit`, `write`, `grep`, `find`, `ls`
|
|
104
|
-
2. On every `tool_call`, the extension evaluates:
|
|
105
|
-
- **Is the target path internal or external?** — Resolved relative to the project CWD
|
|
106
|
-
- **Does the path match a protected pattern?** — Uses glob matching
|
|
107
|
-
- **What is the action type?** — `read`, `edit`, `write`, `grep`, `list`, etc.
|
|
108
|
-
3. The permission is looked up in the 4×3 permission matrix (2 locations × 2 protection levels × 3 action types)
|
|
109
|
-
4. Depending on the permission level:
|
|
110
|
-
- **`block`** — The call is denied with a `[LOCKDOWN]` reason
|
|
111
|
-
- **`warn`** — A select dialog prompts the user to allow or deny
|
|
112
|
-
- **`allow`** — The call proceeds normally
|
|
113
|
-
|
|
114
|
-
### Empty write protection
|
|
115
|
-
|
|
116
|
-
Lockdown also blocks empty writes (`write` with empty content) as a safeguard against file soft-deletion workarounds.
|
|
117
|
-
|
|
118
|
-
## Installation
|
|
119
|
-
|
|
120
|
-
Place the extension in your extensions directory for auto-discovery:
|
|
121
|
-
|
|
122
|
-
**Project-local:**
|
|
123
|
-
|
|
124
|
-
```bash
|
|
125
|
-
cp -r .pi/extensions/lockdown .pi/extensions/lockdown
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
**Global:**
|
|
129
|
-
|
|
130
|
-
```bash
|
|
131
|
-
cp -r .pi/extensions/lockdown ~/.pi/agent/extensions/lockdown
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
Or load manually for testing:
|
|
135
|
-
|
|
136
|
-
```bash
|
|
137
|
-
pi --extension .pi/extensions/lockdown
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
## Extension Structure
|
|
141
|
-
|
|
142
|
-
```
|
|
143
|
-
lockdown/
|
|
144
|
-
├── index.ts # Entry point — event handlers, commands, TUI
|
|
145
|
-
├── schema.ts # Zod schemas for settings validation
|
|
146
|
-
├── utils.ts # Path resolution helpers (isInside, loadSettings)
|
|
147
|
-
├── package.json # Dependencies (zod)
|
|
148
|
-
└── README.md # This file
|
|
149
|
-
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,mCAAoC,CAAA;AACzD,eAAO,MAAM,UAAU,uCAAwC,CAAA;AAC/D,eAAO,MAAM,WAAW,6CAA8C,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,UAAU,EAAE,UAAU,CAAU,CAAA;AACzD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,aAAa,EAAE,WAAW,CAAU,CAAA;AAC/D,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAU,CAAA"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,YAAY,EAA6C,MAAM,iCAAiC,CAAA;AAY9G;;GAEG;AACH,MAAM,CAAC,OAAO,WAAW,EAAE,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,YAAY,EAA6C,MAAM,iCAAiC,CAAA;AAY9G;;GAEG;AACH,MAAM,CAAC,OAAO,WAAW,EAAE,EAAE,YAAY,QA8IxC"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { getSettingsListTheme, isToolCallEventType } from '@earendil-works/pi-coding-agent';
|
|
3
3
|
import { Box, Container, SettingsList, Text } from '@earendil-works/pi-tui';
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
4
|
+
import { LockdownLevelSchema, LockdownSettingsSchema } from './schema';
|
|
5
|
+
import { constructSettingsList, isInside, loadSettings } from './utils';
|
|
6
6
|
// Settings
|
|
7
7
|
let lockdownSettings = LockdownSettingsSchema.parse({
|
|
8
8
|
external: { protected: {}, unprotected: {} },
|
|
@@ -102,80 +102,7 @@ export default function (pi) {
|
|
|
102
102
|
pi.registerCommand('lockdown:session-permissions', {
|
|
103
103
|
description: 'Configure file access permissions for session.',
|
|
104
104
|
handler: async (_args, ctx) => {
|
|
105
|
-
const items =
|
|
106
|
-
{
|
|
107
|
-
id: 'external-protected-read',
|
|
108
|
-
label: 'Read external protected files',
|
|
109
|
-
currentValue: lockdownSettings.external.protected.read,
|
|
110
|
-
values: lockdownLevelOptions,
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
id: 'external-protected-edit',
|
|
114
|
-
label: 'Edit external protected files',
|
|
115
|
-
currentValue: lockdownSettings.external.protected.edit,
|
|
116
|
-
values: lockdownLevelOptions,
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
id: 'external-protected-write',
|
|
120
|
-
label: 'Write external protected files',
|
|
121
|
-
currentValue: lockdownSettings.external.protected.write,
|
|
122
|
-
values: lockdownLevelOptions,
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
id: 'external-unprotected-read',
|
|
126
|
-
label: 'Read external unprotected files',
|
|
127
|
-
currentValue: lockdownSettings.external.unprotected.read,
|
|
128
|
-
values: lockdownLevelOptions,
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
id: 'external-unprotected-edit',
|
|
132
|
-
label: 'Edit external unprotected files',
|
|
133
|
-
currentValue: lockdownSettings.external.unprotected.edit,
|
|
134
|
-
values: lockdownLevelOptions,
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
id: 'external-unprotected-write',
|
|
138
|
-
label: 'Write external unprotected files',
|
|
139
|
-
currentValue: lockdownSettings.external.unprotected.write,
|
|
140
|
-
values: lockdownLevelOptions,
|
|
141
|
-
},
|
|
142
|
-
{
|
|
143
|
-
id: 'internal-protected-read',
|
|
144
|
-
label: 'Read internal protected files',
|
|
145
|
-
currentValue: lockdownSettings.internal.protected.read,
|
|
146
|
-
values: lockdownLevelOptions,
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
id: 'internal-protected-edit',
|
|
150
|
-
label: 'Edit internal protected files',
|
|
151
|
-
currentValue: lockdownSettings.internal.protected.edit,
|
|
152
|
-
values: lockdownLevelOptions,
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
id: 'internal-protected-write',
|
|
156
|
-
label: 'Write internal protected files',
|
|
157
|
-
currentValue: lockdownSettings.internal.protected.write,
|
|
158
|
-
values: lockdownLevelOptions,
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
id: 'internal-unprotected-read',
|
|
162
|
-
label: 'Read internal unprotected files',
|
|
163
|
-
currentValue: lockdownSettings.internal.unprotected.read,
|
|
164
|
-
values: lockdownLevelOptions,
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
id: 'internal-unprotected-edit',
|
|
168
|
-
label: 'Edit internal unprotected files',
|
|
169
|
-
currentValue: lockdownSettings.internal.unprotected.edit,
|
|
170
|
-
values: lockdownLevelOptions,
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
id: 'internal-unprotected-write',
|
|
174
|
-
label: 'Write internal unprotected files',
|
|
175
|
-
currentValue: lockdownSettings.internal.unprotected.write,
|
|
176
|
-
values: lockdownLevelOptions,
|
|
177
|
-
},
|
|
178
|
-
];
|
|
105
|
+
const items = constructSettingsList(lockdownSettings);
|
|
179
106
|
await ctx.ui.custom((_tui, theme, _kb, done) => {
|
|
180
107
|
const container = new Container();
|
|
181
108
|
const titleBox = new Box(0, 1);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,OAAO,EAAqB,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAA;AAC9G,OAAO,EAAE,GAAG,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,OAAO,EAAqB,oBAAoB,EAA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AAE,EAAE;oBACf,sBAAsB;oBACtB,MAAM,CAAC,QAAQ,EAAE,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;oBAClD,gBAAgB,CAAC,QAAmC,CAAC,CAAC,UAAyC,CAAC,CAC9F,IAAiC,CAClC,GAAG,mBAAmB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;gBACzC,CAAC,EACD,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,WAAW;gBAClC,EAAE,YAAY,EAAE,IAAI,EAAE,CACvB,CAAA;gBACD,SAAS,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAA;gBAEhC,OAAO;oBACL,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;oBAClC,UAAU,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE;oBACxC,WAAW,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC;iBACxD,CAAA;YACH,CAAC,CAAC,CAAA;QACJ,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type ExtensionContext } from '@earendil-works/pi-coding-agent';
|
|
2
|
+
import type { SettingItem } from '@earendil-works/pi-tui';
|
|
2
3
|
import { type LockdownSettings } from './schema';
|
|
3
4
|
export declare function isInside(root: string, value: string): boolean;
|
|
4
|
-
export
|
|
5
|
+
export declare function loadSettings(ctx: ExtensionContext): LockdownSettings;
|
|
6
|
+
export declare function constructSettingsList(lockdownSettings: LockdownSettings): SettingItem[];
|
|
5
7
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,gBAAgB,EAAmB,MAAM,iCAAiC,CAAA;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,gBAAgB,EAAmB,MAAM,iCAAiC,CAAA;AACxF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAGzD,OAAO,EAAwB,KAAK,gBAAgB,EAA0B,MAAM,UAAU,CAAA;AAE9F,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAY7D;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,gBAAgB,GAAG,gBAAgB,CA4BpE;AAED,wBAAgB,qBAAqB,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,WAAW,EAAE,CAsBvF"}
|
package/dist/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { SettingsManager } from '@earendil-works/pi-coding-agent';
|
|
3
|
-
import {
|
|
3
|
+
import { LOCATION, PERM_ACTION, PROTECTION } from './constants';
|
|
4
|
+
import { lockdownLevelOptions, LockdownSettingsSchema } from './schema';
|
|
4
5
|
export function isInside(root, value) {
|
|
5
6
|
// Resolve `value` relative to `root`, NOT the process CWD.
|
|
6
7
|
// This prevents a bug where a relative `value` resolves differently
|
|
@@ -12,7 +13,7 @@ export function isInside(root, value) {
|
|
|
12
13
|
// Allow value == root itself (no trailing separator needed).
|
|
13
14
|
return normalizedValue === root || normalizedValue.startsWith(normalizedRoot);
|
|
14
15
|
}
|
|
15
|
-
export
|
|
16
|
+
export function loadSettings(ctx) {
|
|
16
17
|
const sm = SettingsManager.create(ctx.cwd);
|
|
17
18
|
const projectSettings = sm.getProjectSettings();
|
|
18
19
|
const globalSettings = sm.getGlobalSettings();
|
|
@@ -32,4 +33,25 @@ export default function loadSettings(ctx) {
|
|
|
32
33
|
internal: { protected: {}, unprotected: {} },
|
|
33
34
|
});
|
|
34
35
|
}
|
|
36
|
+
export function constructSettingsList(lockdownSettings) {
|
|
37
|
+
const items = [];
|
|
38
|
+
for (const location of LOCATION) {
|
|
39
|
+
for (const protection of PROTECTION) {
|
|
40
|
+
for (const permAction of PERM_ACTION) {
|
|
41
|
+
const id = `${location}-${protection}-${permAction}`;
|
|
42
|
+
const fullLabel = permAction === 'other' ? `${permAction} tool` : permAction;
|
|
43
|
+
const titleCaseLabel = fullLabel[0]?.toUpperCase() + fullLabel.slice(1);
|
|
44
|
+
const label = `${titleCaseLabel.padEnd(12, ' ')}> ${location} ${protection.padEnd(11, ' ')}`;
|
|
45
|
+
const currentValue = lockdownSettings[location][protection][permAction];
|
|
46
|
+
items.push({
|
|
47
|
+
id,
|
|
48
|
+
label,
|
|
49
|
+
currentValue,
|
|
50
|
+
values: lockdownLevelOptions,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return items;
|
|
56
|
+
}
|
|
35
57
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,OAAO,EAAyB,eAAe,EAAE,MAAM,iCAAiC,CAAA;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,OAAO,EAAyB,eAAe,EAAE,MAAM,iCAAiC,CAAA;AAGxF,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC/D,OAAO,EAAE,oBAAoB,EAAyB,sBAAsB,EAAE,MAAM,UAAU,CAAA;AAE9F,MAAM,UAAU,QAAQ,C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",
|
|
4
4
|
"description": "A Pi extension to add security constraints to agent tool usage.",
|
|
5
5
|
"author": "Chris Chow",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,4 +39,4 @@
|
|
|
39
39
|
"@earendil-works/pi-tui": "^0.79.1",
|
|
40
40
|
"@types/node": "^25.9.3"
|
|
41
41
|
}
|
|
42
|
-
}
|
|
42
|
+
}
|