@bacnh85/pi-plan 0.1.7 → 0.1.9
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/index.ts +34 -9
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -11,7 +11,7 @@ const PLAN_TOOL = "write_plan";
|
|
|
11
11
|
const PLAN_QUESTION_TOOL = "ask_plan_question";
|
|
12
12
|
const PLAN_EXECUTE_COMMAND = "plan-execute";
|
|
13
13
|
const PREFERENCES_FILE = path.join(os.homedir(), ".pi", "agent", "pi-plan", "preferences.json");
|
|
14
|
-
const DEFAULT_PLAN_TOOLS = ["read", "bash", "grep", "find", "ls", PLAN_TOOL, PLAN_QUESTION_TOOL];
|
|
14
|
+
const DEFAULT_PLAN_TOOLS = ["read", "bash", "grep", "find", "ls", "searxng_search", "brave_search", "brave_content", "firecrawl_search", "firecrawl_scrape", "firecrawl_map", "firecrawl_crawl", "web_status", PLAN_TOOL, PLAN_QUESTION_TOOL];
|
|
15
15
|
const PLAN_ALLOWED_TOOLS = new Set(DEFAULT_PLAN_TOOLS);
|
|
16
16
|
const THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh"] as const;
|
|
17
17
|
|
|
@@ -181,6 +181,26 @@ function tokenizeSimpleCommand(command: string): string[] | undefined {
|
|
|
181
181
|
return trimmed.split(/\s+/).filter(Boolean);
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
+
function sanitizeCommand(command: string): string[] {
|
|
185
|
+
let sanitized = command;
|
|
186
|
+
|
|
187
|
+
// Strip /dev/null redirects: 2>/dev/null, >/dev/null, >>/dev/null, &>/dev/null
|
|
188
|
+
sanitized = sanitized.replace(/\d*>>?\s*\/dev\/null/g, "");
|
|
189
|
+
sanitized = sanitized.replace(/&>\s*\/dev\/null/g, "");
|
|
190
|
+
// Strip fd redirections: 2>&1, 1>&2, etc.
|
|
191
|
+
sanitized = sanitized.replace(/\s*\d*>&\d+\s*/g, " ");
|
|
192
|
+
|
|
193
|
+
// Strip cd <path> && / cd <path> ; prefix
|
|
194
|
+
sanitized = sanitized.replace(/^cd\s+(?:"[^"]*"|'[^']*'|[^\s;&|]+)\s*(?:&&|;)\s*/i, "").trim();
|
|
195
|
+
|
|
196
|
+
// If command contains pipes, split into segments and validate each
|
|
197
|
+
if (sanitized.includes("|")) {
|
|
198
|
+
return sanitized.split("|").map((s) => s.trim()).filter(Boolean);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return [sanitized.trim()];
|
|
202
|
+
}
|
|
203
|
+
|
|
184
204
|
function hasOptionValue(tokens: string[], index: number): boolean {
|
|
185
205
|
return index + 1 < tokens.length && !tokens[index + 1].startsWith("-");
|
|
186
206
|
}
|
|
@@ -219,14 +239,19 @@ function isAllowedGitCommand(tokens: string[]): boolean {
|
|
|
219
239
|
}
|
|
220
240
|
|
|
221
241
|
export function isReadOnlyBash(command: string): boolean {
|
|
222
|
-
const
|
|
223
|
-
if (
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
242
|
+
const segments = sanitizeCommand(command);
|
|
243
|
+
if (segments.length === 0) return true;
|
|
244
|
+
|
|
245
|
+
return segments.every((segment) => {
|
|
246
|
+
const tokens = tokenizeSimpleCommand(segment);
|
|
247
|
+
if (!tokens) return false;
|
|
248
|
+
if (tokens.length === 0) return true;
|
|
249
|
+
const normalized = tokens[0] === "rtk" ? tokens.slice(1) : tokens;
|
|
250
|
+
if (normalized.length === 0) return false;
|
|
251
|
+
if (isAllowedGitCommand(normalized)) return true;
|
|
252
|
+
if (isAllowedNpmMetadataCommand(normalized)) return true;
|
|
253
|
+
return /^(rg|grep|find|fd|ls|pwd|cat|head|tail|sed|awk|wc|sort|uniq|cut|read)$/.test(normalized[0]);
|
|
254
|
+
});
|
|
230
255
|
}
|
|
231
256
|
|
|
232
257
|
export default function piPlanExtension(pi: ExtensionAPI): void {
|