@narumitw/pi-plan-mode 0.47.0 → 0.47.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 CHANGED
@@ -93,7 +93,7 @@ When Plan mode is active, ask the agent to design the change. The agent may insp
93
93
 
94
94
  By default, Plan mode manages only Pi's built-in tools: `read`, limited `bash`, available read-only built-ins such as `grep`, `find`, and `ls`, plus the required `plan_mode_question` and `plan_mode_complete` tools. Built-in `edit` and `write` are blocked. `update_plan` is also blocked because it tracks execution progress rather than conversational planning. Extension and custom tools are disabled by default because Pi tools do not expose standardized mutability metadata; enable them from `/plan tools` only when you accept the risk for that session. For example, you can opt into `firecrawl_scrape`, `firecrawl_search`, or `lsp_diagnostics` if those extensions are loaded and you want to use them during planning.
95
95
 
96
- Limited `bash` uses a fail-closed policy, including when an extension overrides the canonical `bash` tool name. It accepts common inspection commands, read-only Git and npm queries, pipelines and command lists composed entirely of accepted commands, plus selected checks such as `npm test`, `npm run typecheck`, and `cargo test`. It rejects output/input redirects, shell expansion, substitutions, subshells, background jobs, mutating flags, dependency changes, editors, and unknown commands. Tests and builds may still write ignored caches or build artifacts and may execute project-defined hooks; enable or invoke them only when the repository is trusted. This is extension-level risk reduction, not an OS sandbox.
96
+ Limited `bash` uses a fail-closed policy, including when an extension overrides the canonical `bash` tool name. It accepts common inspection commands, read-only Git and npm queries, pipelines and command lists composed entirely of accepted commands, plus selected checks such as `npm test`, `npm run typecheck`, and `cargo test`. It rejects output/input redirects, shell expansion, substitutions, subshells, background jobs, mutating flags, dependency changes, editors, and unknown commands. A rejected parsed command list or pipeline identifies its first blocked command segment; malformed or unsupported shell syntax reports the complete submitted input instead. Tests and builds may still write ignored caches or build artifacts and may execute project-defined hooks; enable or invoke them only when the repository is trusted. This is extension-level risk reduction, not an OS sandbox.
97
97
 
98
98
  `plan_mode_question` follows Codex's `request_user_input` pattern: the agent can ask 1-3 concise questions, each with meaningful options and a free-form Other path. If you cancel or no interactive UI is available, the agent should ask a concise plain-text question or proceed only with a clearly stated low-risk assumption instead of prematurely producing a final plan.
99
99
 
@@ -166,7 +166,10 @@ With the example configuration above, commands such as these are accepted:
166
166
 
167
167
  ```bash
168
168
  git rev-parse --show-toplevel
169
- git blame --no-textconv -- src/plan-mode.ts
169
+ git blame -- src/plan-mode.ts
170
+ git diff --cached
171
+ git show --stat --oneline HEAD
172
+ git log -p -1 HEAD -- src/plan-mode.ts
170
173
  gh pr view 218 --json number,title,state
171
174
  gh issue list --state open --json number,title,state
172
175
  ```
@@ -174,12 +177,12 @@ gh issue list --state open --json number,title,state
174
177
  The command-specific validators still reject unsafe forms, including:
175
178
 
176
179
  ```bash
177
- git blame -- src/plan-mode.ts
180
+ git blame --textconv -- src/plan-mode.ts
178
181
  git cat-file --filters HEAD
179
- git diff
180
- git log -Ssecret
182
+ git diff --ext-diff
183
+ git log --show-signature -1
181
184
  git remote show origin
182
- git show --ext-diff HEAD
185
+ git show --textconv HEAD
183
186
  gh pr merge 218
184
187
  gh pr view 218
185
188
  gh pr view 218 --web
@@ -187,9 +190,9 @@ gh pr view 218 > pr.txt
187
190
  gh pr list --json number,title && gh pr merge 218
188
191
  ```
189
192
 
190
- Redirects, shell expansion and substitution, pagers or browsers, external diff/textconv/filter/signature helpers, output flags, malformed command layouts, and any chain containing an unsafe segment fail closed. Commands that can invoke configured Git helpers implicitly require explicit guards: use `--no-textconv` with `blame`, `show`, and patch-producing or pickaxe/searching `log`; use both `--no-ext-diff` and `--no-textconv` with content-producing `diff` (`git diff --check` remains accepted); and use `git remote show -n` to avoid invoking a transport helper. GitHub CLI read paths require `--json <fields>` output so Plan mode does not rely on `GH_PAGER`, `PAGER`, or gh pager configuration. Unknown `safeSubcommands` keys or values, non-array values, and non-string entries invalidate the entire settings file and trigger the normal warning/default fallback on session start.
193
+ Redirects, shell expansion and substitution, explicit pager or browser requests, explicit external diff/textconv/filter/signature helpers, output flags, malformed command layouts, and any chain containing an unsafe segment fail closed. Read-dominant Git validators accept ordinary inspection flags without requiring `--no-textconv` or `--no-ext-diff`; Git may therefore invoke a helper configured by the user or trusted repository even when the command does not request one explicitly. Use the negative flags when you want to suppress those configured helpers. Mixed read/write surfaces remain narrower: use `git remote show -n` to avoid invoking a transport helper, while mutating `branch` and `remote` forms remain blocked. GitHub CLI read paths require `--json <fields>` output so Plan mode does not rely on `GH_PAGER`, `PAGER`, or gh pager configuration. Unknown `safeSubcommands` keys or values, non-array values, and non-string entries invalidate the entire settings file and trigger the normal warning/default fallback on session start.
191
194
 
192
- Read-only does not mean private: Git inspection can expose repository history and tracked secrets, while `gh` queries can expose remote repository, pull request, and issue data available to your authenticated account. The policy reduces accidental mutation and helper execution; it is not a sandbox or a confidentiality boundary.
195
+ Read-only does not mean private: Git inspection can expose repository history and tracked secrets, while `gh` queries can expose remote repository, pull request, and issue data available to your authenticated account. The policy reduces accidental mutation and explicit helper execution; it is not a sandbox or a confidentiality boundary.
193
196
 
194
197
  ### Thinking level
195
198
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narumitw/pi-plan-mode",
3
- "version": "0.47.0",
3
+ "version": "0.47.1",
4
4
  "description": "Pi extension that adds a Codex-like read-only /plan collaboration mode.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/plan-mode.ts CHANGED
@@ -59,8 +59,8 @@ import { type PlanCompletionSource, type PlanModeState, restorePlanModeState } f
59
59
  import {
60
60
  canSelectToolInPlanMode,
61
61
  classifyPlanModeTool,
62
+ findBlockedCommandSegment,
62
63
  isBuiltinTool,
63
- isSafeCommand,
64
64
  readCommand,
65
65
  SAFE_BUILTIN_PLAN_TOOLS,
66
66
  } from "./tool-policy.js";
@@ -328,11 +328,11 @@ export default function planMode(
328
328
  // Built-in-compatible overrides retain the canonical name but replace its source metadata.
329
329
  if (event.toolName !== "bash") return;
330
330
 
331
- const command = readCommand(event.input);
332
- if (!isSafeCommand(command, settings.safeSubcommands)) {
331
+ const blocked = findBlockedCommandSegment(readCommand(event.input), settings.safeSubcommands);
332
+ if (blocked !== undefined) {
333
333
  return {
334
334
  block: true,
335
- reason: `Plan mode blocks mutating or non-allowlisted bash commands.\nCommand: ${command}`,
335
+ reason: `Plan mode blocks bash commands outside its reviewed inspection policy or containing explicitly unsafe arguments.\nBlocked command: ${blocked}`,
336
336
  };
337
337
  }
338
338
  });
@@ -121,13 +121,17 @@ export function readCommand(input: unknown) {
121
121
  return typeof command?.command === "string" ? command.command : "";
122
122
  }
123
123
 
124
- export function isSafeCommand(command: string, safeSubcommands: SafeSubcommands = {}) {
124
+ export function findBlockedCommandSegment(
125
+ command: string,
126
+ safeSubcommands: SafeSubcommands = {},
127
+ ): string | undefined {
125
128
  const segments = splitShellSegments(command);
126
- return (
127
- segments !== undefined &&
128
- segments.length > 0 &&
129
- segments.every((segment) => isSafeSegment(segment, safeSubcommands))
130
- );
129
+ if (!segments || segments.length === 0) return command.trim() || "(empty command)";
130
+ return segments.find((segment) => !isSafeSegment(segment, safeSubcommands));
131
+ }
132
+
133
+ export function isSafeCommand(command: string, safeSubcommands: SafeSubcommands = {}) {
134
+ return findBlockedCommandSegment(command, safeSubcommands) === undefined;
131
135
  }
132
136
 
133
137
  function splitShellSegments(command: string): string[] | undefined {
@@ -344,9 +348,9 @@ type ArgumentValidator = (args: string[]) => boolean;
344
348
  const allowReadOnlyArguments: ArgumentValidator = () => true;
345
349
  const BUILTIN_GIT_VALIDATORS: Record<BuiltinSafeGitSubcommand, ArgumentValidator> = {
346
350
  status: allowReadOnlyArguments,
347
- log: isSafeGitLogArguments,
348
- diff: isSafeGitDiffArguments,
349
- show: requiresNoTextconv,
351
+ log: allowReadOnlyArguments,
352
+ diff: allowReadOnlyArguments,
353
+ show: allowReadOnlyArguments,
350
354
  branch: isSafeGitBranchArguments,
351
355
  remote: isSafeGitRemoteArguments,
352
356
  "ls-files": allowReadOnlyArguments,
@@ -354,7 +358,7 @@ const BUILTIN_GIT_VALIDATORS: Record<BuiltinSafeGitSubcommand, ArgumentValidator
354
358
  };
355
359
  const CONFIGURABLE_GIT_VALIDATORS: Record<ConfigurableSafeGitSubcommand, ArgumentValidator> = {
356
360
  "rev-parse": allowReadOnlyArguments,
357
- blame: requiresNoTextconv,
361
+ blame: allowReadOnlyArguments,
358
362
  describe: allowReadOnlyArguments,
359
363
  "merge-base": allowReadOnlyArguments,
360
364
  "ls-tree": allowReadOnlyArguments,
@@ -484,43 +488,6 @@ function matchesLongOptionPrefix(argument: string, option: string, shortest: str
484
488
  return optionName.length >= shortest.length && option.startsWith(optionName);
485
489
  }
486
490
 
487
- function isSafeGitDiffArguments(args: string[]) {
488
- return (
489
- args.includes("--check") || (args.includes("--no-ext-diff") && args.includes("--no-textconv"))
490
- );
491
- }
492
-
493
- function isSafeGitLogArguments(args: string[]) {
494
- if (args.includes("--no-textconv")) return true;
495
- return !args.some(requiresTextconvGuardForGitLog);
496
- }
497
-
498
- function requiresTextconvGuardForGitLog(argument: string) {
499
- return (
500
- argument === "-p" ||
501
- argument.startsWith("-p") ||
502
- argument === "-u" ||
503
- argument.startsWith("-U") ||
504
- argument === "-c" ||
505
- argument === "--patch" ||
506
- argument.startsWith("--patch=") ||
507
- argument.startsWith("--patch-with-") ||
508
- argument === "--unified" ||
509
- argument.startsWith("--unified=") ||
510
- argument === "--binary" ||
511
- argument === "--cc" ||
512
- argument === "--remerge-diff" ||
513
- argument.startsWith("-S") ||
514
- argument.startsWith("-G") ||
515
- argument === "--find-object" ||
516
- argument.startsWith("--find-object=")
517
- );
518
- }
519
-
520
- function requiresNoTextconv(args: string[]) {
521
- return args.includes("--no-textconv");
522
- }
523
-
524
491
  function isSafeGitBranchArguments(args: string[]) {
525
492
  if (args.some((argument) => !argument.startsWith("-"))) return false;
526
493
  return !args.some(