@yaosu/pi-path-guard 1.1.0 → 1.1.1
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 +4 -3
- package/extensions/path-guard.ts +22 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ pi install /path/to/pi-path-guard
|
|
|
22
22
|
# Try without installing (no settings change / 临时试用,不写入 settings)
|
|
23
23
|
pi -e ./pi-path-guard
|
|
24
24
|
|
|
25
|
-
# npm
|
|
25
|
+
# npm: scope package
|
|
26
26
|
# pi install npm:@yaosu/pi-path-guard
|
|
27
27
|
```
|
|
28
28
|
|
|
@@ -36,6 +36,7 @@ After installing, run `/reload` or restart pi. 安装后 `/reload` 或重启 pi
|
|
|
36
36
|
- `/guard <strict|normal|loose|trusted|naked>` — quick switch (trusted requires a warning; naked requires a double warning) 快捷切换(trusted 需警告确认;naked 需两级确认)
|
|
37
37
|
- Invalid argument → falls back to the interactive picker 非法参数 → 兜底弹出交互选择
|
|
38
38
|
- Every new session resets to `normal` 每次新会话自动回到 `normal`
|
|
39
|
+
- The active mode is shown in the footer status bar (`🛡 <mode>`, `🛡 NAKED` in warning color) 当前模式显示在底部状态栏(`🛡 <mode>`,naked 用警示色 `🛡 NAKED`)
|
|
39
40
|
|
|
40
41
|
### Guard mode matrix / 防护模式矩阵
|
|
41
42
|
|
|
@@ -72,13 +73,13 @@ After installing, run `/reload` or restart pi. 安装后 `/reload` 或重启 pi
|
|
|
72
73
|
|
|
73
74
|
## Development / 开发与测试
|
|
74
75
|
|
|
75
|
-
Automated tests (
|
|
76
|
+
Automated tests (99 assertions) load the real extension with a mocked pi API, covering the 5 modes × protected paths / dangerous commands / truncation / git destructive matrix, plus `/guard` command interaction, trusted-mode confirmation, naked-mode double confirmation, and the footer status indicator:
|
|
76
77
|
|
|
77
78
|
```bash
|
|
78
79
|
cd tests && node --experimental-strip-types test-pathguard.ts
|
|
79
80
|
```
|
|
80
81
|
|
|
81
|
-
自动化测试(
|
|
82
|
+
自动化测试(99 断言)模拟 pi API 加载真实扩展,覆盖 5 种模式 × 受保护路径 / 危险命令 / 截断 / git 破坏性等判定矩阵,以及 `/guard` 命令交互、trusted 确认与 naked 两级确认、底部状态栏指示等流程:
|
|
82
83
|
|
|
83
84
|
```bash
|
|
84
85
|
cd tests && node --experimental-strip-types test-pathguard.ts
|
package/extensions/path-guard.ts
CHANGED
|
@@ -52,6 +52,7 @@ import type {
|
|
|
52
52
|
EditToolInput,
|
|
53
53
|
WriteToolInput,
|
|
54
54
|
ToolCallEventResult,
|
|
55
|
+
ExtensionUIContext,
|
|
55
56
|
} from "@earendil-works/pi-coding-agent";
|
|
56
57
|
import {
|
|
57
58
|
resolve,
|
|
@@ -250,10 +251,27 @@ type GuardVerdict =
|
|
|
250
251
|
|
|
251
252
|
// ─── Entry ────────────────────────────────────────────────────────────
|
|
252
253
|
|
|
254
|
+
/** Set the current guard mode and mirror it into the TUI footer status bar. */
|
|
255
|
+
function setMode(mode: GuardMode, ui: ExtensionUIContext) {
|
|
256
|
+
currentMode = mode;
|
|
257
|
+
refreshModeStatus(ui);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Show the active guard mode in the footer status bar (persists across renders).
|
|
262
|
+
* naked is highlighted in warning color so the "bare" state is unmissable.
|
|
263
|
+
*/
|
|
264
|
+
function refreshModeStatus(ui: ExtensionUIContext) {
|
|
265
|
+
const t = ui.theme;
|
|
266
|
+
const color = currentMode === "naked" ? "warning" : "accent";
|
|
267
|
+
const label = currentMode === "naked" ? "🛡 NAKED" : `🛡 ${currentMode}`;
|
|
268
|
+
ui.setStatus("path-guard", t.fg(color, label));
|
|
269
|
+
}
|
|
270
|
+
|
|
253
271
|
export default function (pi: ExtensionAPI) {
|
|
254
272
|
// Reset to normal on every new session (startup, /new, /resume all fire session_start)
|
|
255
|
-
pi.on("session_start", () => {
|
|
256
|
-
|
|
273
|
+
pi.on("session_start", (_event, ctx) => {
|
|
274
|
+
setMode("normal", ctx.ui);
|
|
257
275
|
});
|
|
258
276
|
|
|
259
277
|
// /guard slash command: view / switch guard mode
|
|
@@ -273,6 +291,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
273
291
|
return;
|
|
274
292
|
}
|
|
275
293
|
currentMode = m;
|
|
294
|
+
refreshModeStatus(ctx.ui);
|
|
276
295
|
ctx.ui.notify(
|
|
277
296
|
`Path Guard switched to: ${m} (session-only; new sessions reset to normal)`,
|
|
278
297
|
"info",
|
|
@@ -309,6 +328,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
309
328
|
return;
|
|
310
329
|
}
|
|
311
330
|
currentMode = picked;
|
|
331
|
+
refreshModeStatus(ctx.ui);
|
|
312
332
|
ctx.ui.notify(
|
|
313
333
|
`Path Guard switched to: ${picked} (session-only; new sessions reset to normal)`,
|
|
314
334
|
"info",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yaosu/pi-path-guard",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Path Guard for pi — blocks destructive commands & path overwrites, protects .env/keys, with strict/normal/loose/trusted/naked guard modes (/guard). pi 防误删/防误覆盖扩展,支持 5 种防护模式。",
|
|
6
6
|
"keywords": [
|