@amaster.ai/pi-security 0.1.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 +201 -0
- package/README.md +122 -0
- package/dist/extension.d.ts +32 -0
- package/dist/extension.d.ts.map +1 -0
- package/dist/extension.js +281 -0
- package/dist/extension.js.map +1 -0
- package/dist/index.d.ts +158 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +517 -0
- package/dist/index.js.map +1 -0
- package/dist/policy-loader.d.ts +4 -0
- package/dist/policy-loader.d.ts.map +1 -0
- package/dist/policy-loader.js +36 -0
- package/dist/policy-loader.js.map +1 -0
- package/examples/auto-review.settings.json +24 -0
- package/examples/reviewer.json +19 -0
- package/package.json +67 -0
- package/preview.png +0 -0
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,122 @@
|
|
|
1
|
+
# Pi Security
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
`@amaster.ai/pi-security` provides a sandbox-aware security policy engine and a Pi extension entry point.
|
|
6
|
+
|
|
7
|
+
The core engine classifies tool calls into resources (files, shell commands, network access), assesses risk, and applies profile rules to decide whether a call is allowed, denied, or requires human approval. Profiles are built from two orthogonal axes — **sandbox** (what tools are exposed) and **approval** (when to ask the user) — inspired by Codex.
|
|
8
|
+
|
|
9
|
+
## Pi extension
|
|
10
|
+
|
|
11
|
+
Install the extension entry point `@amaster.ai/pi-security/extension` and load the `pi-security` settings key through Pi `SettingsManager`:
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"pi-security": {
|
|
16
|
+
"enabled": true,
|
|
17
|
+
"profile": "default",
|
|
18
|
+
"approvals": {
|
|
19
|
+
"allowSessionGrants": true
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
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.
|
|
26
|
+
|
|
27
|
+
## Built-in profiles
|
|
28
|
+
|
|
29
|
+
Profiles are derived from a `sandbox` × `approval` matrix. Pick one as a starting point and override either axis in your own profiles.
|
|
30
|
+
|
|
31
|
+
| Profile | Sandbox | Approval | Use case |
|
|
32
|
+
|----------------|--------------------|--------------|---------------------------------------------------------|
|
|
33
|
+
| `read-only` | `read-only` | `never` | Read-only inspection, no modifications |
|
|
34
|
+
| `default` | `workspace-write` | `on-request` | Workspace edits with approval for writes (recommended) |
|
|
35
|
+
| `auto` | `workspace-write` | `on-failure` | Autonomous edits, only ask when risk is high |
|
|
36
|
+
| `full-access` | `full-access` | `never` | Trusted automation, no gating (use with care) |
|
|
37
|
+
|
|
38
|
+
### Sandbox modes
|
|
39
|
+
|
|
40
|
+
| Mode | Allowed tools | Denied tools |
|
|
41
|
+
|--------------------|------------------------------------------------|-----------------------|
|
|
42
|
+
| `read-only` | `read`, `ls`, `find`, `grep` | `write`, `edit`, `bash` |
|
|
43
|
+
| `workspace-write` | `read`, `ls`, `find`, `grep`, `write`, `edit`, `bash` | — |
|
|
44
|
+
| `full-access` | `*` (all tools) | — |
|
|
45
|
+
|
|
46
|
+
Tool names align with the pi-coding-agent built-in tools: `bash`, `read`, `write`, `edit`, `ls`, `find`, `grep`.
|
|
47
|
+
|
|
48
|
+
### Approval modes
|
|
49
|
+
|
|
50
|
+
| Mode | Behavior |
|
|
51
|
+
|---------------|---------------------------------------------------------------------------|
|
|
52
|
+
| `never` | No approval prompts (deny rules still apply, e.g. for secrets). |
|
|
53
|
+
| `on-failure` | Ask only on high/critical risk operations. |
|
|
54
|
+
| `on-request` | Ask on workspace writes/deletes (in addition to high-risk ops). |
|
|
55
|
+
| `untrusted` | Ask on workspace writes plus high-risk ops; default decision is also ask. |
|
|
56
|
+
|
|
57
|
+
Baseline secret protection (denying `.ssh/`, `.env`, `*.pem`, `*.key`, etc.) is always enabled, regardless of profile.
|
|
58
|
+
|
|
59
|
+
## Custom profiles
|
|
60
|
+
|
|
61
|
+
Profiles can be defined in three places. Higher-priority sources override lower-priority ones with the same name:
|
|
62
|
+
|
|
63
|
+
1. **Project**: `<cwd>/.pi/policy/<name>.json` (highest priority)
|
|
64
|
+
2. **Agent**: `<agentDir>/policy/<name>.json`
|
|
65
|
+
3. **User**: `~/.pi/agent/policy/<name>.json`
|
|
66
|
+
4. **Settings**: under `pi-security.security.profiles` in `pi.json`
|
|
67
|
+
|
|
68
|
+
Each JSON file defines a single profile; the filename (without `.json`) is the profile name.
|
|
69
|
+
|
|
70
|
+
### JSON config examples
|
|
71
|
+
|
|
72
|
+
Ready-to-copy samples live under [`examples/`](./examples) and are exercised by the test suite:
|
|
73
|
+
|
|
74
|
+
- [`examples/reviewer.json`](./examples/reviewer.json) — a project-level file policy. Drop into `<project>/.pi/policy/reviewer.json`. Starts from `read-only`, opens to `workspace-write`, asks on `bash`, denies external network.
|
|
75
|
+
- [`examples/auto-review.settings.json`](./examples/auto-review.settings.json) — a `pi.json` snippet that defines a custom `auto-review` profile inline. Extends `default` and asks before package-manager installs (`npm/pnpm/yarn/pip install|add`) via `argsRegex`.
|
|
76
|
+
|
|
77
|
+
### Profile schema
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
type SecurityProfileConfig = {
|
|
81
|
+
extends?: string; // built-in profile name or another custom profile
|
|
82
|
+
sandbox?: 'read-only' | 'workspace-write' | 'full-access';
|
|
83
|
+
approval?: 'never' | 'on-failure' | 'on-request' | 'untrusted';
|
|
84
|
+
rules?: SecurityRule[]; // appended after parent rules
|
|
85
|
+
defaultDecision?: SecurityDecision; // overrides parent default for unmatched tools
|
|
86
|
+
};
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Rule schema
|
|
90
|
+
|
|
91
|
+
Rules are evaluated in priority order (descending); the first match wins.
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
type SecurityRule = {
|
|
95
|
+
id: string;
|
|
96
|
+
priority?: number; // default 300 for user rules
|
|
97
|
+
tools?: string[]; // tool name patterns ('*', 'mcp_*', 'bash')
|
|
98
|
+
sources?: ToolSource[]; // 'builtin' | 'mcp' | 'runtime'
|
|
99
|
+
triggers?: Array<'user' | 'agent' | 'scheduler'>;
|
|
100
|
+
senderTrusts?: Array<'owner' | 'trusted' | 'untrusted'>;
|
|
101
|
+
args?: Record<string, string>; // exact/glob match against args
|
|
102
|
+
argsRegex?: Record<string, string>; // regex match against args
|
|
103
|
+
resources?: ('file' | 'shell' | 'network')[];
|
|
104
|
+
operations?: ('read' | 'write' | 'execute' | 'delete' | 'connect' | 'search')[];
|
|
105
|
+
scopes?: ('workspace' | 'home' | 'system' | 'external' | 'unknown')[];
|
|
106
|
+
sensitivity?: ('normal' | 'source' | 'config' | 'secret' | 'credential')[];
|
|
107
|
+
risk?: ('low' | 'medium' | 'high' | 'critical')[];
|
|
108
|
+
decision: { kind: 'allow' } | { kind: 'deny'; reason: string } | { kind: 'ask'; reason: string; prompt?: string };
|
|
109
|
+
};
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Commands
|
|
113
|
+
|
|
114
|
+
- `/pi-security-status` shows the active profile, audit count, and in-session grants.
|
|
115
|
+
- `/pi-security-audit [limit]` shows recent authorization decisions without raw sensitive output.
|
|
116
|
+
- `/pi-security-reset` clears in-session approval grants.
|
|
117
|
+
|
|
118
|
+
## Trust model
|
|
119
|
+
|
|
120
|
+
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; sandbox enforcement still depends on the runtime that executes the tool.
|
|
121
|
+
|
|
122
|
+
Sensitive paths such as SSH keys, `.env`, credentials, tokens, private keys, and `secrets/` directories are denied by baseline policy across all profiles. 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":"AAQA,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,mBAAmB,EACnB,aAAa,EACb,mBAAmB,EACpB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EAIpB,MAAM,YAAY,CAAC;AAQpB,MAAM,MAAM,yBAAyB,GAAG;IACtC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE;QACV,kBAAkB,CAAC,EAAE,OAAO,CAAC;KAC9B,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,MAAM,EAAE,iCAAiC,CAAC;IAC1C,QAAQ,EAAE,kBAAkB,EAAE,CAAC;IAC/B,MAAM,EAAE,sBAAsB,EAAE,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG;IAC9C,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,kBAAkB,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CA+ClE;AAED,wBAAsB,mBAAmB,CACvC,KAAK,EAAE,aAAa,EACpB,GAAG,EAAE,gBAAgB,EACrB,KAAK,EAAE,wBAAwB,GAC9B,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAc1C;AAED,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,aAAa,EACpB,GAAG,EAAE,gBAAgB,EACrB,KAAK,EAAE,wBAAwB,GAC9B,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CA8B1C;AAED,wBAAgB,uBAAuB,CACrC,MAAM,CAAC,EAAE,yBAAyB,GACjC,iCAAiC,CAenC"}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { loadPiSettings } from '@amaster.ai/pi-shared/settings';
|
|
2
|
+
import { getAgentDir } from '@earendil-works/pi-coding-agent';
|
|
3
|
+
import { SecurityGate, securityEvaluationDetails, } from './index.js';
|
|
4
|
+
import { loadFilePolicies } from './policy-loader.js';
|
|
5
|
+
const SETTINGS_KEY = 'pi-security';
|
|
6
|
+
const EXTENSION_STATUS_KEY = 'pi-security';
|
|
7
|
+
const DEFAULT_PROFILE = 'auto-review';
|
|
8
|
+
const DEFAULT_AUDIT_LIMIT = 200;
|
|
9
|
+
export default function piSecurityExtension(pi) {
|
|
10
|
+
const state = {
|
|
11
|
+
config: resolvePiSecurityConfig(),
|
|
12
|
+
auditLog: [],
|
|
13
|
+
grants: [],
|
|
14
|
+
};
|
|
15
|
+
pi.on('session_start', async (_event, ctx) => {
|
|
16
|
+
state.config = resolvePiSecurityConfig(loadSettings(ctx.cwd));
|
|
17
|
+
state.auditLog = [];
|
|
18
|
+
state.grants = [];
|
|
19
|
+
ctx.ui.setStatus(EXTENSION_STATUS_KEY, state.config.enabled ? `security: ${state.config.profile}` : 'security: disabled');
|
|
20
|
+
});
|
|
21
|
+
pi.on('session_shutdown', async (_event, ctx) => {
|
|
22
|
+
ctx.ui.setStatus(EXTENSION_STATUS_KEY, undefined);
|
|
23
|
+
state.auditLog = [];
|
|
24
|
+
state.grants = [];
|
|
25
|
+
});
|
|
26
|
+
pi.on('tool_call', async (event, ctx) => authorizePiToolCall(event, ctx, state));
|
|
27
|
+
pi.on('user_bash', async (event, ctx) => authorizeUserBash(event, ctx, state));
|
|
28
|
+
pi.registerCommand('pi-security-status', {
|
|
29
|
+
description: 'Show Pi security policy status.',
|
|
30
|
+
handler: async (_args, ctx) => {
|
|
31
|
+
ctx.ui.notify(formatSecurityStatus(state), 'info');
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
pi.registerCommand('pi-security-audit', {
|
|
35
|
+
description: 'Show recent Pi security authorization decisions.',
|
|
36
|
+
handler: async (args, ctx) => {
|
|
37
|
+
ctx.ui.notify(formatAuditLog(state, parseAuditLimit(args)), 'info');
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
pi.registerCommand('pi-security-reset', {
|
|
41
|
+
description: 'Clear in-session Pi security approval grants.',
|
|
42
|
+
handler: async (_args, ctx) => {
|
|
43
|
+
state.grants = [];
|
|
44
|
+
ctx.ui.notify('Pi security session grants cleared.', 'info');
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
export async function authorizePiToolCall(event, ctx, state) {
|
|
49
|
+
if (!state.config.enabled) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
const toolCall = toolCallFromPiEvent(event);
|
|
53
|
+
const evaluation = await createGate(ctx, state).authorize({
|
|
54
|
+
request: requestFromContext(ctx),
|
|
55
|
+
toolCall,
|
|
56
|
+
workspaceDir: ctx.cwd,
|
|
57
|
+
});
|
|
58
|
+
if (evaluation.decision.kind === 'deny' || evaluation.decision.kind === 'ask') {
|
|
59
|
+
return { block: true, reason: evaluation.decision.reason };
|
|
60
|
+
}
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
export async function authorizeUserBash(event, ctx, state) {
|
|
64
|
+
if (!state.config.enabled) {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
const toolCall = {
|
|
68
|
+
id: 'user-bash',
|
|
69
|
+
name: 'bash',
|
|
70
|
+
source: 'builtin',
|
|
71
|
+
args: {
|
|
72
|
+
command: event.command,
|
|
73
|
+
cwd: event.cwd,
|
|
74
|
+
excludeFromContext: event.excludeFromContext,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
const evaluation = await createGate(ctx, state).authorize({
|
|
78
|
+
request: requestFromContext(ctx),
|
|
79
|
+
toolCall,
|
|
80
|
+
workspaceDir: ctx.cwd,
|
|
81
|
+
});
|
|
82
|
+
if (evaluation.decision.kind === 'deny' || evaluation.decision.kind === 'ask') {
|
|
83
|
+
return {
|
|
84
|
+
result: {
|
|
85
|
+
output: evaluation.decision.reason,
|
|
86
|
+
exitCode: 1,
|
|
87
|
+
cancelled: false,
|
|
88
|
+
truncated: false,
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
export function resolvePiSecurityConfig(config) {
|
|
95
|
+
const configuredAuditLimit = config?.auditLimit;
|
|
96
|
+
const auditLimit = Number.isInteger(configuredAuditLimit) &&
|
|
97
|
+
configuredAuditLimit !== undefined &&
|
|
98
|
+
configuredAuditLimit > 0
|
|
99
|
+
? Math.min(configuredAuditLimit, 1_000)
|
|
100
|
+
: DEFAULT_AUDIT_LIMIT;
|
|
101
|
+
return {
|
|
102
|
+
enabled: config?.enabled !== false,
|
|
103
|
+
profile: config?.profile?.trim() || DEFAULT_PROFILE,
|
|
104
|
+
...(config?.security ? { security: config.security } : {}),
|
|
105
|
+
auditLimit,
|
|
106
|
+
allowSessionGrants: config?.approvals?.allowSessionGrants !== false,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function createGate(ctx, state) {
|
|
110
|
+
return new SecurityGate({
|
|
111
|
+
profile: state.config.profile,
|
|
112
|
+
...(state.config.security ? { config: state.config.security } : {}),
|
|
113
|
+
filePolicies: loadFilePolicies(ctx.cwd, getAgentDir()),
|
|
114
|
+
approvalHandler: async ({ toolCall, decision }) => resolveApproval(ctx, state, toolCall, decision),
|
|
115
|
+
auditSink: (event) => {
|
|
116
|
+
state.auditLog.push(event);
|
|
117
|
+
if (state.auditLog.length > state.config.auditLimit) {
|
|
118
|
+
state.auditLog.splice(0, state.auditLog.length - state.config.auditLimit);
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
async function resolveApproval(ctx, state, toolCall, decision) {
|
|
124
|
+
if (hasSessionGrant(state, toolCall, decision)) {
|
|
125
|
+
return { kind: 'allow', reason: `Allowed by in-session grant: ${decision.reason}` };
|
|
126
|
+
}
|
|
127
|
+
if (!ctx.hasUI) {
|
|
128
|
+
return decision;
|
|
129
|
+
}
|
|
130
|
+
if (!state.config.allowSessionGrants) {
|
|
131
|
+
const approved = await ctx.ui.confirm(decision.prompt ?? 'Approve tool call?', approvalMessage(toolCall, decision));
|
|
132
|
+
return approved
|
|
133
|
+
? { kind: 'allow', reason: `Approved by user: ${decision.reason}` }
|
|
134
|
+
: denyByUser(decision);
|
|
135
|
+
}
|
|
136
|
+
const choice = await ctx.ui.select(`${decision.prompt ?? 'Approve tool call?'}\n${approvalMessage(toolCall, decision)}`, ['Allow once', 'Allow similar for this session', 'Deny']);
|
|
137
|
+
if (choice === 'Allow once') {
|
|
138
|
+
return { kind: 'allow', reason: `Approved by user: ${decision.reason}` };
|
|
139
|
+
}
|
|
140
|
+
if (choice === 'Allow similar for this session') {
|
|
141
|
+
state.grants.push({ toolName: toolCall.name, reason: decision.reason });
|
|
142
|
+
return { kind: 'allow', reason: `Approved by user with session grant: ${decision.reason}` };
|
|
143
|
+
}
|
|
144
|
+
return denyByUser(decision);
|
|
145
|
+
}
|
|
146
|
+
function loadSettings(cwd) {
|
|
147
|
+
try {
|
|
148
|
+
const config = loadPiSettings(SETTINGS_KEY, {
|
|
149
|
+
cwd,
|
|
150
|
+
agentDir: getAgentDir(),
|
|
151
|
+
});
|
|
152
|
+
return Object.keys(config).length > 0 ? config : undefined;
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function isPlainObject(value) {
|
|
159
|
+
return Boolean(value && typeof value === 'object' && !Array.isArray(value));
|
|
160
|
+
}
|
|
161
|
+
function requestFromContext(ctx) {
|
|
162
|
+
const sessionId = ctx.sessionManager.getSessionId();
|
|
163
|
+
const model = ctx.model;
|
|
164
|
+
return {
|
|
165
|
+
sessionId,
|
|
166
|
+
conversationId: sessionId,
|
|
167
|
+
trigger: 'user',
|
|
168
|
+
senderTrust: 'owner',
|
|
169
|
+
interactive: ctx.hasUI,
|
|
170
|
+
model: {
|
|
171
|
+
provider: stringFromRecord(model, 'provider') ?? 'pi',
|
|
172
|
+
model: stringFromRecord(model, 'id') ?? stringFromRecord(model, 'name') ?? 'unknown',
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function toolCallFromPiEvent(event) {
|
|
177
|
+
return {
|
|
178
|
+
id: event.toolCallId,
|
|
179
|
+
name: event.toolName,
|
|
180
|
+
source: toolSourceForPiTool(event.toolName),
|
|
181
|
+
args: normalizeToolArgs(event.toolName, event.input),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
function toolSourceForPiTool(toolName) {
|
|
185
|
+
if (toolName.startsWith('mcp_') || toolName.startsWith('mcp__')) {
|
|
186
|
+
return 'mcp';
|
|
187
|
+
}
|
|
188
|
+
if (['bash', 'write', 'edit', 'read', 'ls', 'grep', 'find'].includes(toolName)) {
|
|
189
|
+
return 'builtin';
|
|
190
|
+
}
|
|
191
|
+
return 'runtime';
|
|
192
|
+
}
|
|
193
|
+
function normalizeToolArgs(toolName, input) {
|
|
194
|
+
const args = toJsonObject(input);
|
|
195
|
+
if (toolName === 'bash' && typeof input.command === 'string') {
|
|
196
|
+
return { ...args, command: input.command };
|
|
197
|
+
}
|
|
198
|
+
return args;
|
|
199
|
+
}
|
|
200
|
+
function toJsonObject(input) {
|
|
201
|
+
const result = {};
|
|
202
|
+
for (const [key, value] of Object.entries(input)) {
|
|
203
|
+
const jsonValue = toJsonValue(value);
|
|
204
|
+
if (jsonValue !== undefined) {
|
|
205
|
+
result[key] = jsonValue;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return result;
|
|
209
|
+
}
|
|
210
|
+
function toJsonValue(value) {
|
|
211
|
+
if (value === null ||
|
|
212
|
+
typeof value === 'string' ||
|
|
213
|
+
typeof value === 'number' ||
|
|
214
|
+
typeof value === 'boolean') {
|
|
215
|
+
return value;
|
|
216
|
+
}
|
|
217
|
+
if (Array.isArray(value)) {
|
|
218
|
+
return value.map(toJsonValue).filter((item) => item !== undefined);
|
|
219
|
+
}
|
|
220
|
+
if (isPlainObject(value)) {
|
|
221
|
+
return toJsonObject(value);
|
|
222
|
+
}
|
|
223
|
+
return undefined;
|
|
224
|
+
}
|
|
225
|
+
function hasSessionGrant(state, toolCall, decision) {
|
|
226
|
+
return state.grants.some((grant) => grant.toolName === toolCall.name && grant.reason === decision.reason);
|
|
227
|
+
}
|
|
228
|
+
function denyByUser(decision) {
|
|
229
|
+
return { kind: 'deny', reason: `User denied approval: ${decision.reason}` };
|
|
230
|
+
}
|
|
231
|
+
function approvalMessage(toolCall, decision) {
|
|
232
|
+
const target = summarizeToolCall(toolCall);
|
|
233
|
+
return target ? `${decision.reason}\n\n${target}` : decision.reason;
|
|
234
|
+
}
|
|
235
|
+
function summarizeToolCall(toolCall) {
|
|
236
|
+
const command = stringArg(toolCall.args, 'command');
|
|
237
|
+
if (command) {
|
|
238
|
+
return command;
|
|
239
|
+
}
|
|
240
|
+
const filePath = stringArg(toolCall.args, 'path') ?? stringArg(toolCall.args, 'file_path');
|
|
241
|
+
if (filePath) {
|
|
242
|
+
return filePath;
|
|
243
|
+
}
|
|
244
|
+
return toolCall.name;
|
|
245
|
+
}
|
|
246
|
+
function formatSecurityStatus(state) {
|
|
247
|
+
return [
|
|
248
|
+
`Pi security: ${state.config.enabled ? 'enabled' : 'disabled'}`,
|
|
249
|
+
`Profile: ${state.config.profile}`,
|
|
250
|
+
`Audit entries: ${state.auditLog.length}`,
|
|
251
|
+
`Session grants: ${state.grants.length}`,
|
|
252
|
+
].join('\n');
|
|
253
|
+
}
|
|
254
|
+
function formatAuditLog(state, limit) {
|
|
255
|
+
if (state.auditLog.length === 0) {
|
|
256
|
+
return 'Pi security audit log is empty.';
|
|
257
|
+
}
|
|
258
|
+
return state.auditLog
|
|
259
|
+
.slice(-limit)
|
|
260
|
+
.map((event) => {
|
|
261
|
+
const details = securityEvaluationDetails(event);
|
|
262
|
+
return `${event.createdAt} ${event.toolName} -> ${event.decision.kind} (${details.risk})`;
|
|
263
|
+
})
|
|
264
|
+
.join('\n');
|
|
265
|
+
}
|
|
266
|
+
function parseAuditLimit(args) {
|
|
267
|
+
const parsed = Number.parseInt((args ?? '').trim(), 10);
|
|
268
|
+
return Number.isFinite(parsed) && parsed > 0 ? Math.min(parsed, 50) : 10;
|
|
269
|
+
}
|
|
270
|
+
function stringArg(args, key) {
|
|
271
|
+
const value = args[key];
|
|
272
|
+
return typeof value === 'string' ? value : undefined;
|
|
273
|
+
}
|
|
274
|
+
function stringFromRecord(value, key) {
|
|
275
|
+
if (!value || typeof value !== 'object') {
|
|
276
|
+
return undefined;
|
|
277
|
+
}
|
|
278
|
+
const actual = value[key];
|
|
279
|
+
return typeof actual === 'string' ? actual : undefined;
|
|
280
|
+
}
|
|
281
|
+
//# sourceMappingURL=extension.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAShE,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAIL,YAAY,EACZ,yBAAyB,GAC1B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