@jackice/pi-approval-gate 0.1.3 → 0.1.4

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/CHANGELOG.md CHANGED
@@ -1,31 +1,35 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.4
4
+
5
+ - English code comments, changelog, and review notes. No behavior change.
6
+
3
7
  ## 0.1.3
4
8
 
5
- - 内建可选 uv 命令拦截(`--approval-guard uv` 或 `approvalGate.guard: "uv"`),默认关闭。
6
- - 移除 `guard`/`sourcePath` 宿主复用选项:审批包自己注册 `bash`,不再需要第二个扩展。
9
+ - Built-in optional uv command guard (`--approval-guard uv` or `approvalGate.guard: "uv"`), off by default.
10
+ - Removed the `guard`/`sourcePath` host options: the package registers `bash` itself, so no second extension is needed.
7
11
 
8
12
  ## 0.1.2
9
13
 
10
- - 加固原生审批视图:保留软换行空格、转义不可见字符,并在窄屏显示风险与分页状态;视图内容被裁切时拒绝批准。
11
- - 原生选择列表成为默认审批 UI,`--approval-ui panel` 可切回面板。
12
- - 新增 `guard` 与 `sourcePath` 选项,允许宿主扩展持有唯一的 `bash` 注册并复用审批;`guard` 在对话框之前拦截。
13
- - 将 `glab mr merge/close` 纳入远端写入审批。
14
+ - Hardened the native approval view: keeps soft-wrap spaces, escapes invisible characters, shows risk and page status on narrow screens, and refuses approval when the view is clipped.
15
+ - The native selection list is now the default approval UI; `--approval-ui panel` switches back to the styled panel.
16
+ - Added `guard` and `sourcePath` options so a host extension can own the single `bash` registration and reuse approval; `guard` ran before the dialog.
17
+ - `glab mr merge/close` now counts as a remote write.
14
18
 
15
19
  ## 0.1.1
16
20
 
17
- - 新增 `--approval-ui native`:用 Pi 原生选择列表回滚新版面板,保留默认拒绝、确认延迟和 Gate 决策。
18
- - 将 `@jackice/pi-ui` 固定为运行时依赖;Pi 省略 peer 安装时仍能加载候选扩展。
19
- - 按真实文件路径验证 `bash` 注册来源,避免符号链接安装误阻断自身工具;无法确认来源时仍拒绝。
20
- - 安全评审 C1/H1/H2/H3 修复:线性 quote-aware 策略、包装命令递归、fail-closed、git/gh 全局选项、fullscreen 分页
21
- - M1/M2/M3/M4/M5 修复:移除超线性正则、继承 shell 前缀、拦截 user_bash、bidi 清洗、影子注册自检
22
- - L1/L3/L4/L6 修复:关闭清理指纹、maxCommandLines 兜底、分页键位、配置 clamp
23
- - 66 个测试;真实 TUI/fullscreen/user_bash/RPC/子代理验证
21
+ - Added `--approval-ui native`: the Pi native selection list replaces the styled panel while keeping default-deny, the arming delay, and Gate decisions.
22
+ - Pinned `@jackice/pi-ui` as a runtime dependency so the candidate extension still loads when Pi omits peer installs.
23
+ - Verify the `bash` registration source by real file path so symlinked installs do not block their own tool; refuse when the source cannot be confirmed.
24
+ - Security review C1/H1/H2/H3: linear quote-aware policy, recursive wrapper parsing, fail-closed behavior, git/gh global options, fullscreen paging.
25
+ - M1/M2/M3/M4/M5: removed the superlinear regex, inherited the shell prefix, intercepted `user_bash`, bidi cleanup, shadow-registration self-check.
26
+ - L1/L3/L4/L6: fingerprint cleanup on close, `maxCommandLines` fallback, paging keys, config clamp.
27
+ - 66 tests; real TUI/fullscreen/user_bash/RPC/subagent verification.
24
28
 
25
29
  ## 0.1.0
26
30
 
27
- - 新增 ApprovalGate:FIFO 队列、120s 超时、abort/shutdown 幂等取消、最多 16 个待请求
28
- - 新增 `bash` 执行边界替换:审批后写入一次性 command+cwd 指纹,spawnHook 消费
29
- - 新增 `ApprovalView` 对话框:完整命令、cwd、reason、风险、Allow once/Deny、滚动、500ms arm
30
- - RPC/headless/子代理默认拒绝
31
- - 真实 Pi RPC 与 `PI_SUBAGENT_CHILD=1` 验证默认拒绝
31
+ - Added ApprovalGate: FIFO queue, 120s timeout, idempotent abort/shutdown cancellation, up to 16 pending requests.
32
+ - Replaced the `bash` execution boundary: after approval a one-shot command+cwd fingerprint is written and consumed by the spawn hook.
33
+ - Added the `ApprovalView` dialog: full command, cwd, reason, risk, Allow once/Deny, scrolling, 500ms arm.
34
+ - RPC/headless/subagent requests are denied by default.
35
+ - Verified default denial on real Pi RPC and with `PI_SUBAGENT_CHILD=1`.
package/index.ts CHANGED
@@ -49,7 +49,7 @@ export default function approvalGateExtension(pi: ExtensionAPI): void {
49
49
  ...(pi.getFlag("approval-ui") === "panel" ? {} : { ui: "native" as const }),
50
50
  });
51
51
 
52
- /** 每次调用重新解析,flag 与 settings 都可能在扩展加载后才可读。 */
52
+ /** Resolved per call: flags and settings are only readable after the extension loads. */
53
53
  const commandGuard = (): CommandGuard | undefined => {
54
54
  if (pi.getFlag("approval-guard") === "uv") return uvGuard;
55
55
  const settings = pi.getSettings() as { approvalGate?: { guard?: unknown } } | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jackice/pi-approval-gate",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Dangerous bash approval gate for Pi with final execution-parameter binding.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/bash-hook.ts CHANGED
@@ -4,7 +4,7 @@ import { verifyFinalBinding } from "./binding.ts";
4
4
  import type { ApprovalAuthorization, ApprovalRequest } from "./gate.ts";
5
5
 
6
6
  export interface BashGuardOptions {
7
- /** 返回拦截说明时阻止执行;在消费审批之前运行。 */
7
+ /** Returns a message to block the command; runs before the approval is consumed. */
8
8
  guard?: ((command: string) => string | undefined) | undefined;
9
9
  authorization?: ApprovalAuthorization | undefined;
10
10
  request?: ApprovalRequest | undefined;
@@ -12,7 +12,7 @@ export interface BashGuardOptions {
12
12
  }
13
13
 
14
14
  /**
15
- * 组合命令拦截与最终审批绑定,供 Bash 工具的 spawn hook 使用。
15
+ * Combines the command guard with final approval binding for a Bash spawn hook.
16
16
  */
17
17
  export function createBashSpawnHook(options: BashGuardOptions): BashSpawnHook {
18
18
  return (context: BashSpawnContext): BashSpawnContext => {
package/src/binding.ts CHANGED
@@ -4,8 +4,8 @@ import type { ApprovalAuthorization, ApprovalRequest } from "./gate.ts";
4
4
  import { isDangerousBash } from "./policy.ts";
5
5
 
6
6
  /**
7
- * 在真正 spawn 前校验最终 command/cwd。
8
- * 危险命令必须消费绑定到本次调用的一次性批准。
7
+ * Verifies the final command and working directory right before spawn.
8
+ * Dangerous commands must consume an approval bound to this exact call.
9
9
  */
10
10
  export function verifyFinalBinding(
11
11
  authorization: ApprovalAuthorization | undefined,
package/src/dialog.ts CHANGED
@@ -89,7 +89,7 @@ export function createApprovalPrompt(
89
89
  try {
90
90
  doneFn?.("deny");
91
91
  } catch {
92
- // 组件可能已因 reload/switch 被销毁。
92
+ // The host component may already be gone after a reload or session switch.
93
93
  }
94
94
  },
95
95
  };
package/src/gate.ts CHANGED
@@ -65,8 +65,8 @@ export function fingerprint(command: string, cwd: string): string {
65
65
  }
66
66
 
67
67
  /**
68
- * 单写者审批队列。超时/abort/shutdown 都走同一幂等 settle 路径,
69
- * 不依赖 custom<T> 的 Promise 结算。
68
+ * Single-writer approval queue. Timeout, abort, and shutdown share one idempotent
69
+ * settle path and never depend on the custom<T> promise settling.
70
70
  */
71
71
  export class ApprovalGate {
72
72
  private readonly timeoutMs: number | (() => number);
@@ -204,7 +204,7 @@ export class ApprovalGate {
204
204
  try {
205
205
  entry.cancelPrompt?.();
206
206
  } catch {
207
- // 宿主组件可能已销毁;结算不依赖关闭 UI。
207
+ // The host component may be gone; settling must not depend on closing the UI.
208
208
  }
209
209
  if (this.active === entry) this.active = undefined;
210
210
  const index = this.queue.indexOf(entry);
package/src/policy.ts CHANGED
@@ -32,8 +32,8 @@ function basename(value: string): string {
32
32
  }
33
33
 
34
34
  /**
35
- * 线性、quote-aware 分词;遇到 shell 展开、重定向、未闭合引号时返回 undefined,
36
- * 调用方按危险命令处理(fail-closed)。
35
+ * Linear, quote-aware tokenizer. Shell expansion, redirection, or an unclosed quote
36
+ * returns undefined so callers fail closed and treat the command as dangerous.
37
37
  */
38
38
  function splitSegments(command: string): string[][] | undefined {
39
39
  const segments: string[][] = [];
package/src/uv-guard.ts CHANGED
@@ -32,7 +32,7 @@ const PY_COMPILE_MESSAGE = [
32
32
  "",
33
33
  ].join("\n");
34
34
 
35
- // 只在命令位置匹配(行首、换行、; && || | 之后),避免 grep/echo 参数误报。
35
+ // Match only in command position (start, newline, after ; && || |) to avoid grep/echo arguments.
36
36
  const SEGMENT_PREFIX = String.raw`(?:^|\n|[;|&]{1,2})\s*(?:\S+\/)?`;
37
37
 
38
38
  const PIP_PATTERN = new RegExp(`${SEGMENT_PREFIX}pip\\s*(?:$|\\s)`, "m");
@@ -44,7 +44,7 @@ const PYTHON_VENV_PATTERN = new RegExp(`${PYTHON_PREFIX}(?:\\s-m\\s*venv\\b|\\s-
44
44
  const PYTHON_PY_COMPILE_PATTERN = new RegExp(`${PYTHON_PREFIX}(?:\\s-m\\s*py_compile\\b|\\s-mpy_compile\\b)`, "m");
45
45
 
46
46
  /**
47
- * 阻止被禁用的 Python 包管理命令,并提示 uv 等价写法。
47
+ * Blocks disabled Python package-manager commands and suggests the uv equivalent.
48
48
  */
49
49
  export function uvGuard(command: string): string | undefined {
50
50
  if (PIP_PATTERN.test(command)) return PIP_MESSAGE;