@chrischow/pi-lockdown 0.1.0 → 0.3.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 +62 -114
- package/dist/constants.d.ts +5 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +5 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +39 -86
- package/dist/index.js.map +1 -1
- package/dist/schema.d.ts +78 -59
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +30 -27
- package/dist/schema.js.map +1 -1
- package/dist/utils.d.ts +3 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +54 -5
- package/dist/utils.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Lockdown
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An opinionated [Pi](https://pi.dev/) extension that adds security constraints to agent tool usage. It intercepts every tool call and enforces fine-grained read/edit/write permissions based on whether files are inside or outside the project, and whether they match protected patterns (e.g., `.env`, `.git/`, `node_modules/`).
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,42 +8,80 @@ 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
|
+
Configure Lockdown (see [Configuration](#configuration) below), then start 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 configured under the `tools` 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 unconditionally
|
|
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
|
-
Add a `lockdown` property in your project or global `settings.json
|
|
37
|
+
Add a `lockdown` property in your project or global `settings.json`. The order of hierarchy that Lockdown respects is: (1) project, (2) global, then (3) defaults (see below). Lockdown **does not** merge project and global settings. For example, if a `lockdown` config exists in **both** the project and global `settings.json` files, only the properties in the **project** will be applied on top of the defaults, and none of the configs in the global `settings.json` will be applied.
|
|
38
|
+
|
|
39
|
+
Mandatory properties:
|
|
40
|
+
- `customTools`: You must add the permissions for all custom tools and tools from other extensions here. Otherwise, Lockdown will not load them into your session.
|
|
41
|
+
|
|
42
|
+
**All other properties are optional.** Any omitted fields will fall back to the built-in defaults listed below.
|
|
13
43
|
|
|
14
44
|
```json
|
|
15
45
|
{
|
|
16
46
|
"lockdown": {
|
|
47
|
+
"customTools": {
|
|
48
|
+
"custom-tool-name": "<allow|warn|block>"
|
|
49
|
+
},
|
|
17
50
|
// No Bash
|
|
18
51
|
"tools": ["read", "edit", "write", "grep", "find", "ls"],
|
|
19
|
-
"customTools": [],
|
|
20
52
|
"protectedPatterns": [
|
|
21
53
|
"**/.env*",
|
|
22
54
|
"**/.git/**",
|
|
23
55
|
"**/node_modules/**"
|
|
24
56
|
],
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
57
|
+
"fileAccess": {
|
|
58
|
+
"external": {
|
|
59
|
+
"protected": {
|
|
60
|
+
"read": "block",
|
|
61
|
+
"write": "block",
|
|
62
|
+
"edit": "block",
|
|
63
|
+
"other": "block"
|
|
64
|
+
},
|
|
65
|
+
"unprotected": {
|
|
66
|
+
"read": "warn",
|
|
67
|
+
"write": "block",
|
|
68
|
+
"edit": "block",
|
|
69
|
+
"other": "block"
|
|
70
|
+
}
|
|
30
71
|
},
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"read": "allow",
|
|
45
|
-
"write": "warn",
|
|
46
|
-
"edit": "warn"
|
|
72
|
+
"internal": {
|
|
73
|
+
"protected": {
|
|
74
|
+
"read": "warn",
|
|
75
|
+
"write": "warn",
|
|
76
|
+
"edit": "warn",
|
|
77
|
+
"other": "warn"
|
|
78
|
+
},
|
|
79
|
+
"unprotected": {
|
|
80
|
+
"read": "allow",
|
|
81
|
+
"write": "warn",
|
|
82
|
+
"edit": "warn",
|
|
83
|
+
"other": "warn"
|
|
84
|
+
}
|
|
47
85
|
}
|
|
48
86
|
}
|
|
49
87
|
}
|
|
@@ -57,93 +95,3 @@ Default protected patterns:
|
|
|
57
95
|
**/.git/**
|
|
58
96
|
**/node_modules/**
|
|
59
97
|
```
|
|
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,5 @@
|
|
|
1
|
+
export declare const LOCATION: readonly ["internal", "external"];
|
|
2
|
+
export declare const PROTECTION: readonly ["unprotected", "protected"];
|
|
3
|
+
export declare const PERM_ACTION: readonly ["read", "edit", "write"];
|
|
4
|
+
export declare const SETTING_ID_SEPARATOR = "__";
|
|
5
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -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,oCAAqC,CAAA;AAC7D,eAAO,MAAM,oBAAoB,OAAO,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,CAAU,CAAA;AAC7D,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,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;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,YAAY,EAA6C,MAAM,iCAAiC,CAAA;AAc9G;;GAEG;AACH,MAAM,CAAC,OAAO,WAAW,EAAE,EAAE,YAAY,QAqKxC"}
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
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
|
-
|
|
9
|
-
|
|
8
|
+
fileAccess: {
|
|
9
|
+
external: { protected: {}, unprotected: {} },
|
|
10
|
+
internal: { protected: {}, unprotected: {} },
|
|
11
|
+
},
|
|
10
12
|
});
|
|
11
13
|
/**
|
|
12
14
|
* Lockdown: A Pi extension to add security constraints to agents' tool usage.
|
|
@@ -15,9 +17,15 @@ export default function (pi) {
|
|
|
15
17
|
// Set allowed tools
|
|
16
18
|
pi.on('session_start', (_, ctx) => {
|
|
17
19
|
// Load settings
|
|
18
|
-
|
|
20
|
+
const loadedSettings = loadSettings(ctx);
|
|
21
|
+
if (!loadedSettings) {
|
|
22
|
+
ctx.ui.notify('Could not load settings.', 'error');
|
|
23
|
+
ctx.shutdown();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
lockdownSettings = loadedSettings;
|
|
19
27
|
// Set tools
|
|
20
|
-
const tools = lockdownSettings.
|
|
28
|
+
const tools = lockdownSettings.defaultTools.concat(Object.keys(lockdownSettings.customTools));
|
|
21
29
|
pi.setActiveTools(Array.from(new Set(tools)));
|
|
22
30
|
});
|
|
23
31
|
pi.on('tool_call', async (event, ctx) => {
|
|
@@ -47,10 +55,13 @@ export default function (pi) {
|
|
|
47
55
|
else if (isGrep || isFind || isLs) {
|
|
48
56
|
inputPath = event.input.path ?? '.';
|
|
49
57
|
}
|
|
58
|
+
else {
|
|
59
|
+
inputPath = event.input ? JSON.stringify(event.input) : '.';
|
|
60
|
+
}
|
|
50
61
|
const location = isInside(ctx.cwd, inputPath) ? 'internal' : 'external';
|
|
51
62
|
const isProtected = lockdownSettings.protectedPatterns.some((pattern) => path.matchesGlob(inputPath, pattern));
|
|
52
63
|
const protection = isProtected ? 'protected' : 'unprotected';
|
|
53
|
-
let permAction;
|
|
64
|
+
let permAction = undefined;
|
|
54
65
|
if (isRead) {
|
|
55
66
|
permAction = 'read';
|
|
56
67
|
}
|
|
@@ -66,10 +77,14 @@ export default function (pi) {
|
|
|
66
77
|
else if (isWrite) {
|
|
67
78
|
permAction = 'write';
|
|
68
79
|
}
|
|
80
|
+
let permission;
|
|
81
|
+
if (permAction && ['read', 'edit', 'write'].includes(permAction)) {
|
|
82
|
+
permission = lockdownSettings.fileAccess[location][protection][permAction];
|
|
83
|
+
}
|
|
69
84
|
else {
|
|
70
|
-
|
|
85
|
+
// Custom tools: Default to warn
|
|
86
|
+
permission = lockdownSettings.customTools[event.toolName] ?? 'warn';
|
|
71
87
|
}
|
|
72
|
-
const permission = lockdownSettings[location][protection][permAction];
|
|
73
88
|
switch (permission) {
|
|
74
89
|
case 'block':
|
|
75
90
|
return {
|
|
@@ -94,7 +109,13 @@ export default function (pi) {
|
|
|
94
109
|
pi.registerCommand('lockdown:reset', {
|
|
95
110
|
description: 'Reset permissions to those specified in settings.json and/or defaults.',
|
|
96
111
|
handler: async (_, ctx) => {
|
|
97
|
-
|
|
112
|
+
const loadedSettings = loadSettings(ctx);
|
|
113
|
+
if (!loadedSettings) {
|
|
114
|
+
ctx.ui.notify('Could not update permissions.', 'error');
|
|
115
|
+
ctx.shutdown();
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
lockdownSettings = loadedSettings;
|
|
98
119
|
ctx.ui.notify('Permissions have been reset.', 'info');
|
|
99
120
|
},
|
|
100
121
|
});
|
|
@@ -102,80 +123,7 @@ export default function (pi) {
|
|
|
102
123
|
pi.registerCommand('lockdown:session-permissions', {
|
|
103
124
|
description: 'Configure file access permissions for session.',
|
|
104
125
|
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
|
-
];
|
|
126
|
+
const items = constructSettingsList(lockdownSettings);
|
|
179
127
|
await ctx.ui.custom((_tui, theme, _kb, done) => {
|
|
180
128
|
const container = new Container();
|
|
181
129
|
const titleBox = new Box(0, 1);
|
|
@@ -184,8 +132,13 @@ export default function (pi) {
|
|
|
184
132
|
container.addChild(titleBox);
|
|
185
133
|
const settingsList = new SettingsList(items, Math.min(items.length + 2, 15), getSettingsListTheme(), (id, newValue) => {
|
|
186
134
|
// Handle value change
|
|
187
|
-
const [
|
|
188
|
-
|
|
135
|
+
const [permType, locationOrCustomTool, protection, perm] = id.split('__');
|
|
136
|
+
if (permType === 'fileAccess') {
|
|
137
|
+
lockdownSettings.fileAccess[locationOrCustomTool][protection][perm] = LockdownLevelSchema.parse(newValue);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
lockdownSettings.customTools[locationOrCustomTool] = LockdownLevelSchema.parse(newValue);
|
|
141
|
+
}
|
|
189
142
|
}, () => done(undefined), // On close
|
|
190
143
|
{ enableSearch: true });
|
|
191
144
|
container.addChild(settingsList);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IA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,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;oBACzE,IAAI,QAAQ,KAAK,YAAY,EAAE,CAAC;wBAC9B,gBAAgB,CAAC,UAAU,CAAC,oBAA+C,CAAC,CAC1E,UAAyC,CAC1C,CAAC,IAAiC,CAAC,GAAG,mBAAmB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;oBAC5E,CAAC;yBAAM,CAAC;wBACN,gBAAgB,CAAC,WAAW,CAAC,oBAA8B,CAAC,GAAG,mBAAmB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;oBACpG,CAAC;gBACH,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/schema.d.ts
CHANGED
|
@@ -4,68 +4,87 @@ export declare const LockdownLevelSchema: z.ZodEnum<{
|
|
|
4
4
|
[x: string]: string;
|
|
5
5
|
}>;
|
|
6
6
|
export type LockdownLevel = z.infer<typeof LockdownLevelSchema>;
|
|
7
|
+
export declare const DefaultToolsSchema: z.ZodArray<z.ZodEnum<{
|
|
8
|
+
read: "read";
|
|
9
|
+
edit: "edit";
|
|
10
|
+
write: "write";
|
|
11
|
+
grep: "grep";
|
|
12
|
+
find: "find";
|
|
13
|
+
ls: "ls";
|
|
14
|
+
}>>;
|
|
7
15
|
export declare const LockdownSettingsSchema: z.ZodObject<{
|
|
8
|
-
|
|
9
|
-
|
|
16
|
+
defaultTools: z.ZodDefault<z.ZodArray<z.ZodEnum<{
|
|
17
|
+
read: "read";
|
|
18
|
+
edit: "edit";
|
|
19
|
+
write: "write";
|
|
20
|
+
grep: "grep";
|
|
21
|
+
find: "find";
|
|
22
|
+
ls: "ls";
|
|
23
|
+
}>>>;
|
|
10
24
|
protectedPatterns: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
customTools: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodEnum<{
|
|
26
|
+
[x: string]: string;
|
|
27
|
+
}>>>;
|
|
28
|
+
fileAccess: z.ZodObject<{
|
|
29
|
+
external: z.ZodObject<{
|
|
30
|
+
protected: z.ZodObject<{
|
|
31
|
+
read: z.ZodDefault<z.ZodEnum<{
|
|
32
|
+
[x: string]: string;
|
|
33
|
+
}>>;
|
|
34
|
+
write: z.ZodDefault<z.ZodEnum<{
|
|
35
|
+
[x: string]: string;
|
|
36
|
+
}>>;
|
|
37
|
+
edit: z.ZodDefault<z.ZodEnum<{
|
|
38
|
+
[x: string]: string;
|
|
39
|
+
}>>;
|
|
40
|
+
other: z.ZodDefault<z.ZodEnum<{
|
|
41
|
+
[x: string]: string;
|
|
42
|
+
}>>;
|
|
43
|
+
}, z.core.$strip>;
|
|
44
|
+
unprotected: z.ZodObject<{
|
|
45
|
+
read: z.ZodDefault<z.ZodEnum<{
|
|
46
|
+
[x: string]: string;
|
|
47
|
+
}>>;
|
|
48
|
+
write: z.ZodDefault<z.ZodEnum<{
|
|
49
|
+
[x: string]: string;
|
|
50
|
+
}>>;
|
|
51
|
+
edit: z.ZodDefault<z.ZodEnum<{
|
|
52
|
+
[x: string]: string;
|
|
53
|
+
}>>;
|
|
54
|
+
other: z.ZodDefault<z.ZodEnum<{
|
|
55
|
+
[x: string]: string;
|
|
56
|
+
}>>;
|
|
57
|
+
}, z.core.$strip>;
|
|
25
58
|
}, z.core.$strip>;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
}, z.core.$strip>;
|
|
56
|
-
unprotected: z.ZodObject<{
|
|
57
|
-
read: z.ZodDefault<z.ZodEnum<{
|
|
58
|
-
[x: string]: string;
|
|
59
|
-
}>>;
|
|
60
|
-
write: z.ZodDefault<z.ZodEnum<{
|
|
61
|
-
[x: string]: string;
|
|
62
|
-
}>>;
|
|
63
|
-
edit: z.ZodDefault<z.ZodEnum<{
|
|
64
|
-
[x: string]: string;
|
|
65
|
-
}>>;
|
|
66
|
-
other: z.ZodDefault<z.ZodEnum<{
|
|
67
|
-
[x: string]: string;
|
|
68
|
-
}>>;
|
|
59
|
+
internal: z.ZodObject<{
|
|
60
|
+
protected: z.ZodObject<{
|
|
61
|
+
read: z.ZodDefault<z.ZodEnum<{
|
|
62
|
+
[x: string]: string;
|
|
63
|
+
}>>;
|
|
64
|
+
write: z.ZodDefault<z.ZodEnum<{
|
|
65
|
+
[x: string]: string;
|
|
66
|
+
}>>;
|
|
67
|
+
edit: z.ZodDefault<z.ZodEnum<{
|
|
68
|
+
[x: string]: string;
|
|
69
|
+
}>>;
|
|
70
|
+
other: z.ZodDefault<z.ZodEnum<{
|
|
71
|
+
[x: string]: string;
|
|
72
|
+
}>>;
|
|
73
|
+
}, z.core.$strip>;
|
|
74
|
+
unprotected: z.ZodObject<{
|
|
75
|
+
read: z.ZodDefault<z.ZodEnum<{
|
|
76
|
+
[x: string]: string;
|
|
77
|
+
}>>;
|
|
78
|
+
write: z.ZodDefault<z.ZodEnum<{
|
|
79
|
+
[x: string]: string;
|
|
80
|
+
}>>;
|
|
81
|
+
edit: z.ZodDefault<z.ZodEnum<{
|
|
82
|
+
[x: string]: string;
|
|
83
|
+
}>>;
|
|
84
|
+
other: z.ZodDefault<z.ZodEnum<{
|
|
85
|
+
[x: string]: string;
|
|
86
|
+
}>>;
|
|
87
|
+
}, z.core.$strip>;
|
|
69
88
|
}, z.core.$strip>;
|
|
70
89
|
}, z.core.$strip>;
|
|
71
90
|
}, z.core.$strip>;
|
package/dist/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AAEnB,eAAO,MAAM,oBAAoB,UAA6B,CAAA;AAC9D,eAAO,MAAM,mBAAmB;;EAA+B,CAAA;AAC/D,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AAEnB,eAAO,MAAM,oBAAoB,UAA6B,CAAA;AAC9D,eAAO,MAAM,mBAAmB;;EAA+B,CAAA;AAC/D,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAA;AAG/D,eAAO,MAAM,kBAAkB;;;;;;;GAAgC,CAAA;AAE/D,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkCjC,CAAA;AACF,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAA"}
|
package/dist/schema.js
CHANGED
|
@@ -2,36 +2,39 @@ import z from 'zod';
|
|
|
2
2
|
export const lockdownLevelOptions = ['allow', 'warn', 'block'];
|
|
3
3
|
export const LockdownLevelSchema = z.enum(lockdownLevelOptions);
|
|
4
4
|
const defaultTools = ['read', 'edit', 'write', 'grep', 'find', 'ls'];
|
|
5
|
+
export const DefaultToolsSchema = z.array(z.enum(defaultTools));
|
|
5
6
|
export const LockdownSettingsSchema = z.object({
|
|
6
|
-
|
|
7
|
-
customTools: z.array(z.string()).default([]),
|
|
7
|
+
defaultTools: DefaultToolsSchema.default([...defaultTools]),
|
|
8
8
|
protectedPatterns: z.array(z.string()).default(['**/.env*', '**/.git/**', '**/node_modules/**']),
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
customTools: z.record(z.string(), LockdownLevelSchema).default({}),
|
|
10
|
+
fileAccess: z.object({
|
|
11
|
+
external: z.object({
|
|
12
|
+
protected: z.object({
|
|
13
|
+
read: LockdownLevelSchema.default('block'),
|
|
14
|
+
write: LockdownLevelSchema.default('block'),
|
|
15
|
+
edit: LockdownLevelSchema.default('block'),
|
|
16
|
+
other: LockdownLevelSchema.default('block'),
|
|
17
|
+
}),
|
|
18
|
+
unprotected: z.object({
|
|
19
|
+
read: LockdownLevelSchema.default('allow'),
|
|
20
|
+
write: LockdownLevelSchema.default('block'),
|
|
21
|
+
edit: LockdownLevelSchema.default('block'),
|
|
22
|
+
other: LockdownLevelSchema.default('block'),
|
|
23
|
+
}),
|
|
15
24
|
}),
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}),
|
|
30
|
-
unprotected: z.object({
|
|
31
|
-
read: LockdownLevelSchema.default('allow'),
|
|
32
|
-
write: LockdownLevelSchema.default('warn'),
|
|
33
|
-
edit: LockdownLevelSchema.default('warn'),
|
|
34
|
-
other: LockdownLevelSchema.default('warn'),
|
|
25
|
+
internal: z.object({
|
|
26
|
+
protected: z.object({
|
|
27
|
+
read: LockdownLevelSchema.default('warn'),
|
|
28
|
+
write: LockdownLevelSchema.default('warn'),
|
|
29
|
+
edit: LockdownLevelSchema.default('warn'),
|
|
30
|
+
other: LockdownLevelSchema.default('warn'),
|
|
31
|
+
}),
|
|
32
|
+
unprotected: z.object({
|
|
33
|
+
read: LockdownLevelSchema.default('allow'),
|
|
34
|
+
write: LockdownLevelSchema.default('warn'),
|
|
35
|
+
edit: LockdownLevelSchema.default('warn'),
|
|
36
|
+
other: LockdownLevelSchema.default('warn'),
|
|
37
|
+
}),
|
|
35
38
|
}),
|
|
36
39
|
}),
|
|
37
40
|
});
|
package/dist/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AAEnB,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;AAC9D,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAA;AAG/D,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;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AAmB,CAAC,OAAO,CAAC,OAAO,CAAC;gBAC1C,KAAK,EAAE,mBAAmB,CAAC,OAAO,CAAC,OAAO,CAAC;gBAC3C,IAAI,EAAE,mBAAmB,CAAC,OAAO,CAAC,OAAO,CAAC;gBAC1C,KAAK,EAAE,mBAAmB,CAAC,OAAO,CAAC,OAAO,CAAC;aAC5C,CAAC;SACH,CAAC;QACF,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC;YACjB,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC;gBAClB,IAAI,EAAE,mBAAmB,CAAC,OAAO,CAAC,MAAM,CAAC;gBACzC,KAAK,EAAE,mBAAmB,CAAC,OAAO,CAAC,MAAM,CAAC;gBAC1C,IAAI,EAAE,mBAAmB,CAAC,OAAO,CAAC,MAAM,CAAC;gBACzC,KAAK,EAAE,mBAAmB,CAAC,OAAO,CAAC,MAAM,CAAC;aAC3C,CAAC;YACF,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;gBACpB,IAAI,EAAE,mBAAmB,CAAC,OAAO,CAAC,OAAO,CAAC;gBAC1C,KAAK,EAAE,mBAAmB,CAAC,OAAO,CAAC,MAAM,CAAC;gBAC1C,IAAI,EAAE,mBAAmB,CAAC,OAAO,CAAC,MAAM,CAAC;gBACzC,KAAK,EAAE,mBAAmB,CAAC,OAAO,CAAC,MAAM,CAAC;aAC3C,CAAC;SACH,CAAC;KACH,CAAC;CACH,CAAC,CAAA"}
|
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 | null;
|
|
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,GAAG,IAAI,CAkD3E;AAED,wBAAgB,qBAAqB,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,WAAW,EAAE,CAsCvF"}
|
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, SETTING_ID_SEPARATOR } 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,17 +13,31 @@ 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();
|
|
19
20
|
// Read project settings first
|
|
20
|
-
const { success, data: projectLockdownSettings } = LockdownSettingsSchema.safeParse(projectSettings.lockdown);
|
|
21
|
-
if (
|
|
21
|
+
const { success: projectSuccess, data: projectLockdownSettings, error: projectError, } = LockdownSettingsSchema.safeParse(projectSettings.lockdown);
|
|
22
|
+
if (!projectSuccess && projectError.issues.length > 0) {
|
|
23
|
+
for (const issue of projectError.issues) {
|
|
24
|
+
ctx.ui.notify(`[LOCKDOWN] ${issue.path[0]} - ${issue.message}`, 'error');
|
|
25
|
+
}
|
|
26
|
+
ctx.shutdown();
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
if (projectSuccess && projectLockdownSettings) {
|
|
22
30
|
return projectLockdownSettings;
|
|
23
31
|
}
|
|
24
32
|
// Global settings fallback
|
|
25
|
-
const { success: globalSuccess, data: globalLockdownSettings } = LockdownSettingsSchema.safeParse(globalSettings.lockdown);
|
|
33
|
+
const { success: globalSuccess, data: globalLockdownSettings, error: globalError, } = LockdownSettingsSchema.safeParse(globalSettings.lockdown);
|
|
34
|
+
if (!globalSuccess && globalError.issues.length > 0) {
|
|
35
|
+
for (const issue of globalError.issues) {
|
|
36
|
+
ctx.ui.notify(`[LOCKDOWN] ${issue.path[0]} - ${issue.message}`, 'error');
|
|
37
|
+
}
|
|
38
|
+
ctx.shutdown();
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
26
41
|
if (globalSuccess && globalLockdownSettings) {
|
|
27
42
|
return globalLockdownSettings;
|
|
28
43
|
}
|
|
@@ -32,4 +47,38 @@ export default function loadSettings(ctx) {
|
|
|
32
47
|
internal: { protected: {}, unprotected: {} },
|
|
33
48
|
});
|
|
34
49
|
}
|
|
50
|
+
export function constructSettingsList(lockdownSettings) {
|
|
51
|
+
const items = [];
|
|
52
|
+
// File access
|
|
53
|
+
for (const location of LOCATION) {
|
|
54
|
+
for (const protection of PROTECTION) {
|
|
55
|
+
for (const permAction of PERM_ACTION) {
|
|
56
|
+
const id = ['fileAccess', location, protection, permAction].join(SETTING_ID_SEPARATOR);
|
|
57
|
+
const fullLabel = permAction;
|
|
58
|
+
const titleCaseLabel = fullLabel[0]?.toUpperCase() + fullLabel.slice(1);
|
|
59
|
+
const label = `${titleCaseLabel.padEnd(12, ' ')}> ${location} ${protection.padEnd(11, ' ')}`;
|
|
60
|
+
const currentValue = lockdownSettings.fileAccess[location][protection][permAction];
|
|
61
|
+
items.push({
|
|
62
|
+
id,
|
|
63
|
+
label,
|
|
64
|
+
currentValue,
|
|
65
|
+
values: lockdownLevelOptions,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Custom tools
|
|
71
|
+
Object.keys(lockdownSettings.customTools).forEach((customTool) => {
|
|
72
|
+
const id = ['customTool', customTool].join(SETTING_ID_SEPARATOR);
|
|
73
|
+
const label = customTool.padEnd(36, ' ');
|
|
74
|
+
const currentValue = lockdownSettings.customTools[customTool] ?? 'warn';
|
|
75
|
+
items.push({
|
|
76
|
+
id,
|
|
77
|
+
label,
|
|
78
|
+
currentValue,
|
|
79
|
+
values: lockdownLevelOptions,
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
return items;
|
|
83
|
+
}
|
|
35
84
|
//# 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,W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,KAAK,CAAC,IAAI,CAAC;YACT,EAAE;YACF,KAAK;YACL,YAAY;YACZ,MAAM,EAAE,oBAAoB;SAC7B,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,OAAO,KAAK,CAAA;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chrischow/pi-lockdown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
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
|
+
}
|