@amaster.ai/pi-security 0.1.1-beta.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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Pi Security
2
+
3
+ `@amaster.ai/pi-security` provides a resource-aware security policy engine and a Pi extension entry point.
4
+
5
+ The core engine classifies tool calls into resources such as files, shell commands, network access, memory writes, MCP calls, and subagent spawns. It then applies profile rules to decide whether a call is allowed, denied, sandbox-only, allowed with constraints, or requires human approval.
6
+
7
+ ## Pi extension
8
+
9
+ Install the extension entry point `@amaster.ai/pi-security/extension` and load the `pi-security` settings key through Pi `SettingsManager`:
10
+
11
+ ```json
12
+ {
13
+ "pi-security": {
14
+ "enabled": true,
15
+ "profile": "auto-review",
16
+ "approvals": {
17
+ "allowSessionGrants": true
18
+ },
19
+ "security": {
20
+ "profiles": {
21
+ "auto-review": {
22
+ "rules": [
23
+ {
24
+ "id": "ask-file-writes",
25
+ "tools": ["write_file", "edit_file"],
26
+ "decision": { "kind": "ask", "reason": "File modifications require approval." }
27
+ }
28
+ ]
29
+ }
30
+ }
31
+ }
32
+ }
33
+ }
34
+ ```
35
+
36
+ The extension listens to Pi `tool_call` and `user_bash` events. It does not register an LLM-callable tool that can bypass policy. Human approvals are requested through Pi UI primitives when UI is available; non-interactive contexts fail closed when a rule requires approval.
37
+
38
+ ## Commands
39
+
40
+ - `/pi-security-status` shows the active profile, audit count, and in-session grants.
41
+ - `/pi-security-audit [limit]` shows recent authorization decisions without raw sensitive output.
42
+ - `/pi-security-reset` clears in-session approval grants.
43
+
44
+ ## Trust model
45
+
46
+ This module is an execution gate, not a filesystem sandbox by itself. Deny and approval decisions are enforceable because they run before Pi tool execution. Constraint decisions must be paired with a runtime that actually enforces the returned constraints.
47
+
48
+ Sensitive paths such as SSH keys, `.env`, credentials, tokens, private keys, and secret files are denied by baseline policy. Audit entries include tool names, resource summaries, risk level, and decision metadata, but they should not include plaintext secrets.
@@ -0,0 +1,32 @@
1
+ import type { ExtensionAPI, ExtensionContext, ToolCallEvent, ToolCallEventResult, UserBashEvent, UserBashEventResult } from '@earendil-works/pi-coding-agent';
2
+ import { type SecurityAuditEvent, type SecurityConfig } from './index.js';
3
+ export type PiSecurityExtensionConfig = {
4
+ enabled?: boolean;
5
+ profile?: string;
6
+ security?: SecurityConfig;
7
+ auditLimit?: number;
8
+ approvals?: {
9
+ allowSessionGrants?: boolean;
10
+ };
11
+ };
12
+ export type PiSecuritySessionGrant = {
13
+ toolName: string;
14
+ reason: string;
15
+ };
16
+ export type PiSecurityExtensionState = {
17
+ config: ResolvedPiSecurityExtensionConfig;
18
+ auditLog: SecurityAuditEvent[];
19
+ grants: PiSecuritySessionGrant[];
20
+ };
21
+ export type ResolvedPiSecurityExtensionConfig = {
22
+ enabled: boolean;
23
+ profile: string;
24
+ security?: SecurityConfig;
25
+ auditLimit: number;
26
+ allowSessionGrants: boolean;
27
+ };
28
+ export default function piSecurityExtension(pi: ExtensionAPI): void;
29
+ export declare function authorizePiToolCall(event: ToolCallEvent, ctx: ExtensionContext, state: PiSecurityExtensionState): Promise<ToolCallEventResult | undefined>;
30
+ export declare function authorizeUserBash(event: UserBashEvent, ctx: ExtensionContext, state: PiSecurityExtensionState): Promise<UserBashEventResult | undefined>;
31
+ export declare function resolvePiSecurityConfig(config?: PiSecurityExtensionConfig): ResolvedPiSecurityExtensionConfig;
32
+ //# sourceMappingURL=extension.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,mBAAmB,EACnB,aAAa,EACb,mBAAmB,EACpB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EACL,KAAK,kB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C,iCAAiC,CAenC"}
@@ -0,0 +1,307 @@
1
+ import { getAgentDir, SettingsManager } from '@earendil-works/pi-coding-agent';
2
+ import { SecurityGate, securityEvaluationDetails, } from './index.js';
3
+ const SETTINGS_KEY = 'pi-security';
4
+ const EXTENSION_STATUS_KEY = 'pi-security';
5
+ const DEFAULT_PROFILE = 'auto-review';
6
+ const DEFAULT_AUDIT_LIMIT = 200;
7
+ export default function piSecurityExtension(pi) {
8
+ const state = {
9
+ config: resolvePiSecurityConfig(),
10
+ auditLog: [],
11
+ grants: [],
12
+ };
13
+ pi.on('session_start', async (_event, ctx) => {
14
+ state.config = resolvePiSecurityConfig(loadSettings(ctx.cwd));
15
+ state.auditLog = [];
16
+ state.grants = [];
17
+ ctx.ui.setStatus(EXTENSION_STATUS_KEY, state.config.enabled ? `security: ${state.config.profile}` : 'security: disabled');
18
+ });
19
+ pi.on('session_shutdown', async (_event, ctx) => {
20
+ ctx.ui.setStatus(EXTENSION_STATUS_KEY, undefined);
21
+ state.auditLog = [];
22
+ state.grants = [];
23
+ });
24
+ pi.on('tool_call', async (event, ctx) => authorizePiToolCall(event, ctx, state));
25
+ pi.on('user_bash', async (event, ctx) => authorizeUserBash(event, ctx, state));
26
+ pi.registerCommand('pi-security-status', {
27
+ description: 'Show Pi security policy status.',
28
+ handler: async (_args, ctx) => {
29
+ ctx.ui.notify(formatSecurityStatus(state), 'info');
30
+ },
31
+ });
32
+ pi.registerCommand('pi-security-audit', {
33
+ description: 'Show recent Pi security authorization decisions.',
34
+ handler: async (args, ctx) => {
35
+ ctx.ui.notify(formatAuditLog(state, parseAuditLimit(args)), 'info');
36
+ },
37
+ });
38
+ pi.registerCommand('pi-security-reset', {
39
+ description: 'Clear in-session Pi security approval grants.',
40
+ handler: async (_args, ctx) => {
41
+ state.grants = [];
42
+ ctx.ui.notify('Pi security session grants cleared.', 'info');
43
+ },
44
+ });
45
+ }
46
+ export async function authorizePiToolCall(event, ctx, state) {
47
+ if (!state.config.enabled) {
48
+ return undefined;
49
+ }
50
+ const toolCall = toolCallFromPiEvent(event);
51
+ const evaluation = await createGate(ctx, state).authorize({
52
+ request: requestFromContext(ctx),
53
+ toolCall,
54
+ workspaceDir: ctx.cwd,
55
+ });
56
+ if (evaluation.decision.kind === 'deny' || evaluation.decision.kind === 'ask') {
57
+ return { block: true, reason: evaluation.decision.reason };
58
+ }
59
+ return undefined;
60
+ }
61
+ export async function authorizeUserBash(event, ctx, state) {
62
+ if (!state.config.enabled) {
63
+ return undefined;
64
+ }
65
+ const toolCall = {
66
+ id: 'user-bash',
67
+ name: 'run_shell',
68
+ source: 'builtin',
69
+ args: {
70
+ command: event.command,
71
+ cwd: event.cwd,
72
+ excludeFromContext: event.excludeFromContext,
73
+ },
74
+ };
75
+ const evaluation = await createGate(ctx, state).authorize({
76
+ request: requestFromContext(ctx),
77
+ toolCall,
78
+ workspaceDir: ctx.cwd,
79
+ });
80
+ if (evaluation.decision.kind === 'deny' || evaluation.decision.kind === 'ask') {
81
+ return {
82
+ result: {
83
+ output: evaluation.decision.reason,
84
+ exitCode: 1,
85
+ cancelled: false,
86
+ truncated: false,
87
+ },
88
+ };
89
+ }
90
+ return undefined;
91
+ }
92
+ export function resolvePiSecurityConfig(config) {
93
+ const configuredAuditLimit = config?.auditLimit;
94
+ const auditLimit = Number.isInteger(configuredAuditLimit) &&
95
+ configuredAuditLimit !== undefined &&
96
+ configuredAuditLimit > 0
97
+ ? Math.min(configuredAuditLimit, 1_000)
98
+ : DEFAULT_AUDIT_LIMIT;
99
+ return {
100
+ enabled: config?.enabled !== false,
101
+ profile: config?.profile?.trim() || DEFAULT_PROFILE,
102
+ ...(config?.security ? { security: config.security } : {}),
103
+ auditLimit,
104
+ allowSessionGrants: config?.approvals?.allowSessionGrants !== false,
105
+ };
106
+ }
107
+ function createGate(ctx, state) {
108
+ return new SecurityGate({
109
+ profile: state.config.profile,
110
+ ...(state.config.security ? { config: state.config.security } : {}),
111
+ approvalHandler: async ({ toolCall, decision }) => resolveApproval(ctx, state, toolCall, decision),
112
+ auditSink: (event) => {
113
+ state.auditLog.push(event);
114
+ if (state.auditLog.length > state.config.auditLimit) {
115
+ state.auditLog.splice(0, state.auditLog.length - state.config.auditLimit);
116
+ }
117
+ },
118
+ });
119
+ }
120
+ async function resolveApproval(ctx, state, toolCall, decision) {
121
+ if (hasSessionGrant(state, toolCall, decision)) {
122
+ return { kind: 'allow', reason: `Allowed by in-session grant: ${decision.reason}` };
123
+ }
124
+ if (!ctx.hasUI) {
125
+ return decision;
126
+ }
127
+ if (!state.config.allowSessionGrants) {
128
+ const approved = await ctx.ui.confirm(decision.prompt ?? 'Approve tool call?', approvalMessage(toolCall, decision));
129
+ return approved
130
+ ? { kind: 'allow', reason: `Approved by user: ${decision.reason}` }
131
+ : denyByUser(decision);
132
+ }
133
+ const choice = await ctx.ui.select(`${decision.prompt ?? 'Approve tool call?'}\n${approvalMessage(toolCall, decision)}`, ['Allow once', 'Allow similar for this session', 'Deny']);
134
+ if (choice === 'Allow once') {
135
+ return { kind: 'allow', reason: `Approved by user: ${decision.reason}` };
136
+ }
137
+ if (choice === 'Allow similar for this session') {
138
+ state.grants.push({ toolName: toolCall.name, reason: decision.reason });
139
+ return { kind: 'allow', reason: `Approved by user with session grant: ${decision.reason}` };
140
+ }
141
+ return denyByUser(decision);
142
+ }
143
+ function loadSettings(cwd) {
144
+ try {
145
+ const settings = SettingsManager.create(cwd, getAgentDir());
146
+ const global = settings.getGlobalSettings();
147
+ const project = settings.getProjectSettings();
148
+ return mergePlainObjects(global[SETTINGS_KEY], project[SETTINGS_KEY]);
149
+ }
150
+ catch {
151
+ return undefined;
152
+ }
153
+ }
154
+ function mergePlainObjects(first, second) {
155
+ const a = isPlainObject(first) ? first : undefined;
156
+ const b = isPlainObject(second) ? second : undefined;
157
+ if (!a && !b) {
158
+ return undefined;
159
+ }
160
+ return {
161
+ ...(a ?? {}),
162
+ ...(b ?? {}),
163
+ };
164
+ }
165
+ function isPlainObject(value) {
166
+ return Boolean(value && typeof value === 'object' && !Array.isArray(value));
167
+ }
168
+ function requestFromContext(ctx) {
169
+ const sessionId = ctx.sessionManager.getSessionId();
170
+ const model = ctx.model;
171
+ return {
172
+ sessionId,
173
+ conversationId: sessionId,
174
+ trigger: 'user',
175
+ senderTrust: 'owner',
176
+ interactive: ctx.hasUI,
177
+ model: {
178
+ provider: stringFromRecord(model, 'provider') ?? 'pi',
179
+ model: stringFromRecord(model, 'id') ?? stringFromRecord(model, 'name') ?? 'unknown',
180
+ },
181
+ };
182
+ }
183
+ function toolCallFromPiEvent(event) {
184
+ return {
185
+ id: event.toolCallId,
186
+ name: normalizeToolName(event.toolName),
187
+ source: toolSourceForPiTool(event.toolName),
188
+ args: normalizeToolArgs(event.toolName, event.input),
189
+ };
190
+ }
191
+ function normalizeToolName(toolName) {
192
+ switch (toolName) {
193
+ case 'bash':
194
+ return 'run_shell';
195
+ case 'write':
196
+ return 'write_file';
197
+ case 'edit':
198
+ return 'edit_file';
199
+ case 'read':
200
+ return 'read_file';
201
+ case 'ls':
202
+ return 'list_files';
203
+ case 'grep':
204
+ case 'find':
205
+ return 'search_files';
206
+ default:
207
+ return toolName;
208
+ }
209
+ }
210
+ function toolSourceForPiTool(toolName) {
211
+ if (toolName.startsWith('mcp_') || toolName.startsWith('mcp__')) {
212
+ return 'mcp';
213
+ }
214
+ if (['bash', 'write', 'edit', 'read', 'ls', 'grep', 'find'].includes(toolName)) {
215
+ return 'builtin';
216
+ }
217
+ return 'runtime';
218
+ }
219
+ function normalizeToolArgs(toolName, input) {
220
+ const args = toJsonObject(input);
221
+ if (toolName === 'bash' && typeof input.command === 'string') {
222
+ return { ...args, command: input.command };
223
+ }
224
+ return args;
225
+ }
226
+ function toJsonObject(input) {
227
+ const result = {};
228
+ for (const [key, value] of Object.entries(input)) {
229
+ const jsonValue = toJsonValue(value);
230
+ if (jsonValue !== undefined) {
231
+ result[key] = jsonValue;
232
+ }
233
+ }
234
+ return result;
235
+ }
236
+ function toJsonValue(value) {
237
+ if (value === null ||
238
+ typeof value === 'string' ||
239
+ typeof value === 'number' ||
240
+ typeof value === 'boolean') {
241
+ return value;
242
+ }
243
+ if (Array.isArray(value)) {
244
+ return value.map(toJsonValue).filter((item) => item !== undefined);
245
+ }
246
+ if (isPlainObject(value)) {
247
+ return toJsonObject(value);
248
+ }
249
+ return undefined;
250
+ }
251
+ function hasSessionGrant(state, toolCall, decision) {
252
+ return state.grants.some((grant) => grant.toolName === toolCall.name && grant.reason === decision.reason);
253
+ }
254
+ function denyByUser(decision) {
255
+ return { kind: 'deny', reason: `User denied approval: ${decision.reason}` };
256
+ }
257
+ function approvalMessage(toolCall, decision) {
258
+ const target = summarizeToolCall(toolCall);
259
+ return target ? `${decision.reason}\n\n${target}` : decision.reason;
260
+ }
261
+ function summarizeToolCall(toolCall) {
262
+ const command = stringArg(toolCall.args, 'command');
263
+ if (command) {
264
+ return command;
265
+ }
266
+ const filePath = stringArg(toolCall.args, 'path') ?? stringArg(toolCall.args, 'file_path');
267
+ if (filePath) {
268
+ return filePath;
269
+ }
270
+ return toolCall.name;
271
+ }
272
+ function formatSecurityStatus(state) {
273
+ return [
274
+ `Pi security: ${state.config.enabled ? 'enabled' : 'disabled'}`,
275
+ `Profile: ${state.config.profile}`,
276
+ `Audit entries: ${state.auditLog.length}`,
277
+ `Session grants: ${state.grants.length}`,
278
+ ].join('\n');
279
+ }
280
+ function formatAuditLog(state, limit) {
281
+ if (state.auditLog.length === 0) {
282
+ return 'Pi security audit log is empty.';
283
+ }
284
+ return state.auditLog
285
+ .slice(-limit)
286
+ .map((event) => {
287
+ const details = securityEvaluationDetails(event);
288
+ return `${event.createdAt} ${event.toolName} -> ${event.decision.kind} (${details.risk})`;
289
+ })
290
+ .join('\n');
291
+ }
292
+ function parseAuditLimit(args) {
293
+ const parsed = Number.parseInt((args ?? '').trim(), 10);
294
+ return Number.isFinite(parsed) && parsed > 0 ? Math.min(parsed, 50) : 10;
295
+ }
296
+ function stringArg(args, key) {
297
+ const value = args[key];
298
+ return typeof value === 'string' ? value : undefined;
299
+ }
300
+ function stringFromRecord(value, key) {
301
+ if (!value || typeof value !== 'object') {
302
+ return undefined;
303
+ }
304
+ const actual = value[key];
305
+ return typeof actual === 'string' ? actual : undefined;
306
+ }
307
+ //# sourceMappingURL=extension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,EAIL,YAAY,EACZ,yBAAyB,GAC1B,MAAM,YAAY,CAAC;AAEpB,MAAM,YAAY,GAAG,aAAa,CAAC;AACnC,MAAM,oBAAoB,GAAG,aAAa,CAAC;AAC3C,MAAM,eAAe,GAAG,aAAa,CAAC;AACtC,MAAM,mBAAmB,GAAG,GAAG,CAAC;AA+BhC,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,EAAgB;IAC1D,MAAM,KAAK,GAA6B;QACtC,MAAM,EAAE,uBAAuB,EAAE;QACjC,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,EAAE;KACX,CAAC;IAEF,EAAE,CAAC,EAAE,CAAC,eAAe,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE;QAC3C,KAAK,CAAC,MAAM,GAAG,uBAAuB,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QAC9D,KAAK,CAAC,QAAQ,GAAG,EAAE,CAAC;QACpB,KAAK,CAAC,MAAM,GAAG,EAAE,CAAC;QAClB,GAAG,CAAC,EAAE,CAAC,SAAS,CACd,oBAAoB,EACpB,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,aAAa,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,oBAAoB,CAClF,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,EAAE,CAAC,kBAAkB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