xtrm-tools 2.4.0 → 2.4.2
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 +23 -9
- package/cli/dist/index.cjs +774 -240
- package/cli/dist/index.cjs.map +1 -1
- package/cli/package.json +1 -1
- package/config/hooks.json +10 -0
- package/config/pi/extensions/core/adapter.ts +2 -14
- package/config/pi/extensions/core/guard-rules.ts +70 -0
- package/config/pi/extensions/core/session-state.ts +59 -0
- package/config/pi/extensions/main-guard.ts +10 -14
- package/config/pi/extensions/plan-mode/README.md +65 -0
- package/config/pi/extensions/plan-mode/index.ts +340 -0
- package/config/pi/extensions/plan-mode/utils.ts +168 -0
- package/config/pi/extensions/service-skills.ts +51 -7
- package/config/pi/extensions/session-flow.ts +117 -0
- package/hooks/beads-claim-sync.mjs +123 -2
- package/hooks/beads-compact-restore.mjs +41 -9
- package/hooks/beads-compact-save.mjs +36 -5
- package/hooks/beads-gate-messages.mjs +27 -1
- package/hooks/beads-stop-gate.mjs +58 -8
- package/hooks/guard-rules.mjs +86 -0
- package/hooks/hooks.json +28 -18
- package/hooks/main-guard.mjs +3 -21
- package/hooks/quality-check.cjs +1286 -0
- package/hooks/quality-check.py +345 -0
- package/hooks/session-state.mjs +138 -0
- package/package.json +2 -1
- package/project-skills/quality-gates/.claude/settings.json +1 -24
- package/skills/creating-service-skills/SKILL.md +433 -0
- package/skills/creating-service-skills/references/script_quality_standards.md +425 -0
- package/skills/creating-service-skills/references/service_skill_system_guide.md +278 -0
- package/skills/creating-service-skills/scripts/bootstrap.py +326 -0
- package/skills/creating-service-skills/scripts/deep_dive.py +304 -0
- package/skills/creating-service-skills/scripts/scaffolder.py +482 -0
- package/skills/scoping-service-skills/SKILL.md +231 -0
- package/skills/scoping-service-skills/scripts/scope.py +74 -0
- package/skills/sync-docs/SKILL.md +235 -0
- package/skills/sync-docs/evals/evals.json +89 -0
- package/skills/sync-docs/references/doc-structure.md +104 -0
- package/skills/sync-docs/references/schema.md +103 -0
- package/skills/sync-docs/scripts/context_gatherer.py +246 -0
- package/skills/sync-docs/scripts/doc_structure_analyzer.py +495 -0
- package/skills/sync-docs/scripts/validate_doc.py +365 -0
- package/skills/sync-docs-workspace/iteration-1/benchmark.json +293 -0
- package/skills/sync-docs-workspace/iteration-1/benchmark.md +13 -0
- package/skills/sync-docs-workspace/iteration-1/eval-doc-audit/eval_metadata.json +27 -0
- package/skills/sync-docs-workspace/iteration-1/eval-doc-audit/with_skill/outputs/result.md +210 -0
- package/skills/sync-docs-workspace/iteration-1/eval-doc-audit/with_skill/run-1/grading.json +28 -0
- package/skills/sync-docs-workspace/iteration-1/eval-doc-audit/with_skill/run-1/timing.json +1 -0
- package/skills/sync-docs-workspace/iteration-1/eval-doc-audit/without_skill/outputs/result.md +101 -0
- package/skills/sync-docs-workspace/iteration-1/eval-doc-audit/without_skill/run-1/grading.json +28 -0
- package/skills/sync-docs-workspace/iteration-1/eval-doc-audit/without_skill/run-1/timing.json +5 -0
- package/skills/sync-docs-workspace/iteration-1/eval-doc-audit/without_skill/timing.json +5 -0
- package/skills/sync-docs-workspace/iteration-1/eval-fix-mode/eval_metadata.json +27 -0
- package/skills/sync-docs-workspace/iteration-1/eval-fix-mode/with_skill/outputs/result.md +198 -0
- package/skills/sync-docs-workspace/iteration-1/eval-fix-mode/with_skill/run-1/grading.json +28 -0
- package/skills/sync-docs-workspace/iteration-1/eval-fix-mode/with_skill/run-1/timing.json +1 -0
- package/skills/sync-docs-workspace/iteration-1/eval-fix-mode/without_skill/outputs/result.md +94 -0
- package/skills/sync-docs-workspace/iteration-1/eval-fix-mode/without_skill/run-1/grading.json +28 -0
- package/skills/sync-docs-workspace/iteration-1/eval-fix-mode/without_skill/run-1/timing.json +1 -0
- package/skills/sync-docs-workspace/iteration-1/eval-sprint-closeout/eval_metadata.json +27 -0
- package/skills/sync-docs-workspace/iteration-1/eval-sprint-closeout/with_skill/outputs/result.md +237 -0
- package/skills/sync-docs-workspace/iteration-1/eval-sprint-closeout/with_skill/run-1/grading.json +28 -0
- package/skills/sync-docs-workspace/iteration-1/eval-sprint-closeout/with_skill/run-1/timing.json +1 -0
- package/skills/sync-docs-workspace/iteration-1/eval-sprint-closeout/without_skill/outputs/result.md +134 -0
- package/skills/sync-docs-workspace/iteration-1/eval-sprint-closeout/without_skill/run-1/grading.json +28 -0
- package/skills/sync-docs-workspace/iteration-1/eval-sprint-closeout/without_skill/run-1/timing.json +1 -0
- package/skills/sync-docs-workspace/iteration-2/benchmark.json +297 -0
- package/skills/sync-docs-workspace/iteration-2/benchmark.md +13 -0
- package/skills/sync-docs-workspace/iteration-2/eval-doc-audit/eval_metadata.json +27 -0
- package/skills/sync-docs-workspace/iteration-2/eval-doc-audit/with_skill/outputs/result.md +137 -0
- package/skills/sync-docs-workspace/iteration-2/eval-doc-audit/with_skill/run-1/grading.json +92 -0
- package/skills/sync-docs-workspace/iteration-2/eval-doc-audit/with_skill/run-1/timing.json +1 -0
- package/skills/sync-docs-workspace/iteration-2/eval-doc-audit/without_skill/outputs/result.md +134 -0
- package/skills/sync-docs-workspace/iteration-2/eval-doc-audit/without_skill/run-1/grading.json +86 -0
- package/skills/sync-docs-workspace/iteration-2/eval-doc-audit/without_skill/run-1/timing.json +1 -0
- package/skills/sync-docs-workspace/iteration-2/eval-fix-mode/eval_metadata.json +27 -0
- package/skills/sync-docs-workspace/iteration-2/eval-fix-mode/with_skill/outputs/result.md +193 -0
- package/skills/sync-docs-workspace/iteration-2/eval-fix-mode/with_skill/run-1/grading.json +72 -0
- package/skills/sync-docs-workspace/iteration-2/eval-fix-mode/with_skill/run-1/timing.json +1 -0
- package/skills/sync-docs-workspace/iteration-2/eval-fix-mode/without_skill/outputs/result.md +211 -0
- package/skills/sync-docs-workspace/iteration-2/eval-fix-mode/without_skill/run-1/grading.json +91 -0
- package/skills/sync-docs-workspace/iteration-2/eval-fix-mode/without_skill/run-1/timing.json +5 -0
- package/skills/sync-docs-workspace/iteration-2/eval-sprint-closeout/eval_metadata.json +27 -0
- package/skills/sync-docs-workspace/iteration-2/eval-sprint-closeout/with_skill/outputs/result.md +182 -0
- package/skills/sync-docs-workspace/iteration-2/eval-sprint-closeout/with_skill/run-1/grading.json +95 -0
- package/skills/sync-docs-workspace/iteration-2/eval-sprint-closeout/with_skill/run-1/timing.json +1 -0
- package/skills/sync-docs-workspace/iteration-2/eval-sprint-closeout/without_skill/outputs/result.md +222 -0
- package/skills/sync-docs-workspace/iteration-2/eval-sprint-closeout/without_skill/run-1/grading.json +88 -0
- package/skills/sync-docs-workspace/iteration-2/eval-sprint-closeout/without_skill/run-1/timing.json +5 -0
- package/skills/sync-docs-workspace/iteration-3/benchmark.json +298 -0
- package/skills/sync-docs-workspace/iteration-3/benchmark.md +13 -0
- package/skills/sync-docs-workspace/iteration-3/eval-doc-audit/eval_metadata.json +27 -0
- package/skills/sync-docs-workspace/iteration-3/eval-doc-audit/with_skill/outputs/result.md +125 -0
- package/skills/sync-docs-workspace/iteration-3/eval-doc-audit/with_skill/run-1/grading.json +97 -0
- package/skills/sync-docs-workspace/iteration-3/eval-doc-audit/with_skill/run-1/timing.json +5 -0
- package/skills/sync-docs-workspace/iteration-3/eval-doc-audit/without_skill/outputs/result.md +144 -0
- package/skills/sync-docs-workspace/iteration-3/eval-doc-audit/without_skill/run-1/grading.json +78 -0
- package/skills/sync-docs-workspace/iteration-3/eval-doc-audit/without_skill/run-1/timing.json +5 -0
- package/skills/sync-docs-workspace/iteration-3/eval-fix-mode/eval_metadata.json +27 -0
- package/skills/sync-docs-workspace/iteration-3/eval-fix-mode/with_skill/outputs/result.md +104 -0
- package/skills/sync-docs-workspace/iteration-3/eval-fix-mode/with_skill/run-1/grading.json +91 -0
- package/skills/sync-docs-workspace/iteration-3/eval-fix-mode/with_skill/run-1/timing.json +5 -0
- package/skills/sync-docs-workspace/iteration-3/eval-fix-mode/without_skill/outputs/result.md +79 -0
- package/skills/sync-docs-workspace/iteration-3/eval-fix-mode/without_skill/run-1/grading.json +82 -0
- package/skills/sync-docs-workspace/iteration-3/eval-fix-mode/without_skill/run-1/timing.json +5 -0
- package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/eval_metadata.json +27 -0
- package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/with_skill/outputs/phase1_context.json +302 -0
- package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/with_skill/outputs/phase2_drift.txt +33 -0
- package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/with_skill/outputs/phase3_analysis.json +114 -0
- package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/with_skill/outputs/phase4_fix.txt +118 -0
- package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/with_skill/outputs/phase5_validate.txt +38 -0
- package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/with_skill/outputs/result.md +158 -0
- package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/with_skill/run-1/grading.json +95 -0
- package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/with_skill/run-1/timing.json +5 -0
- package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/without_skill/outputs/result.md +71 -0
- package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/without_skill/run-1/grading.json +90 -0
- package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/without_skill/run-1/timing.json +5 -0
- package/skills/updating-service-skills/SKILL.md +136 -0
- package/skills/updating-service-skills/scripts/drift_detector.py +222 -0
- package/skills/using-quality-gates/SKILL.md +254 -0
- package/skills/using-service-skills/SKILL.md +108 -0
- package/skills/using-service-skills/scripts/cataloger.py +74 -0
- package/skills/using-service-skills/scripts/skill_activator.py +152 -0
- package/skills/using-service-skills/scripts/test_skill_activator.py +58 -0
- package/skills/using-xtrm/SKILL.md +34 -38
package/cli/package.json
CHANGED
package/config/hooks.json
CHANGED
|
@@ -48,6 +48,16 @@
|
|
|
48
48
|
"script": "main-guard-post-push.mjs",
|
|
49
49
|
"timeout": 5000
|
|
50
50
|
},
|
|
51
|
+
{
|
|
52
|
+
"matcher": "Write|Edit|MultiEdit|mcp__serena__rename_symbol|mcp__serena__replace_symbol_body|mcp__serena__insert_after_symbol|mcp__serena__insert_before_symbol",
|
|
53
|
+
"script": "quality-check.cjs",
|
|
54
|
+
"timeout": 30000
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"matcher": "Write|Edit|MultiEdit|mcp__serena__rename_symbol|mcp__serena__replace_symbol_body|mcp__serena__insert_after_symbol|mcp__serena__insert_before_symbol",
|
|
58
|
+
"script": "quality-check.py",
|
|
59
|
+
"timeout": 30000
|
|
60
|
+
},
|
|
51
61
|
{
|
|
52
62
|
"matcher": "Bash|mcp__serena__find_symbol|mcp__serena__get_symbols_overview|mcp__serena__search_for_pattern|mcp__serena__find_referencing_symbols|mcp__serena__replace_symbol_body|mcp__serena__insert_after_symbol|mcp__serena__insert_before_symbol|mcp__serena__rename_symbol",
|
|
53
63
|
"script": "gitnexus/gitnexus-hook.cjs",
|
|
@@ -2,26 +2,14 @@ import * as fs from "node:fs";
|
|
|
2
2
|
import * as nodePath from "node:path";
|
|
3
3
|
|
|
4
4
|
import type { ExtensionAPI, ToolCallEvent } from "@mariozechner/pi-coding-agent";
|
|
5
|
+
import { PI_MUTATING_FILE_TOOLS } from "./guard-rules";
|
|
5
6
|
|
|
6
7
|
export class EventAdapter {
|
|
7
8
|
/**
|
|
8
9
|
* Checks if the tool event is a mutating file operation (write, edit, etc).
|
|
9
10
|
*/
|
|
10
11
|
static isMutatingFileTool(event: ToolCallEvent<any, any>): boolean {
|
|
11
|
-
|
|
12
|
-
"write",
|
|
13
|
-
"edit",
|
|
14
|
-
"replace_content",
|
|
15
|
-
"replace_lines",
|
|
16
|
-
"delete_lines",
|
|
17
|
-
"insert_at_line",
|
|
18
|
-
"create_text_file",
|
|
19
|
-
"rename_symbol",
|
|
20
|
-
"replace_symbol_body",
|
|
21
|
-
"insert_after_symbol",
|
|
22
|
-
"insert_before_symbol",
|
|
23
|
-
];
|
|
24
|
-
return tools.includes(event.toolName);
|
|
12
|
+
return PI_MUTATING_FILE_TOOLS.includes(event.toolName);
|
|
25
13
|
}
|
|
26
14
|
|
|
27
15
|
/**
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Canonical guard-rule constants for Pi extensions.
|
|
2
|
+
// Mirrors hooks/guard-rules.mjs with Pi-specific tool naming where needed.
|
|
3
|
+
|
|
4
|
+
export const PI_MUTATING_FILE_TOOLS = [
|
|
5
|
+
"write",
|
|
6
|
+
"edit",
|
|
7
|
+
"replace_content",
|
|
8
|
+
"replace_lines",
|
|
9
|
+
"delete_lines",
|
|
10
|
+
"insert_at_line",
|
|
11
|
+
"create_text_file",
|
|
12
|
+
"rename_symbol",
|
|
13
|
+
"replace_symbol_body",
|
|
14
|
+
"insert_after_symbol",
|
|
15
|
+
"insert_before_symbol",
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
export const SAFE_BASH_PREFIXES = [
|
|
19
|
+
"git status",
|
|
20
|
+
"git log",
|
|
21
|
+
"git diff",
|
|
22
|
+
"git show",
|
|
23
|
+
"git blame",
|
|
24
|
+
"git branch",
|
|
25
|
+
"git fetch",
|
|
26
|
+
"git remote",
|
|
27
|
+
"git config",
|
|
28
|
+
"git pull",
|
|
29
|
+
"git stash",
|
|
30
|
+
"git worktree",
|
|
31
|
+
"git checkout -b",
|
|
32
|
+
"git switch -c",
|
|
33
|
+
"gh",
|
|
34
|
+
"bd",
|
|
35
|
+
"touch .beads/",
|
|
36
|
+
"npx gitnexus",
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
export const DANGEROUS_BASH_PATTERNS = [
|
|
40
|
+
"sed\\s+-i",
|
|
41
|
+
"echo\\s+[^\\n]*>",
|
|
42
|
+
"printf\\s+[^\\n]*>",
|
|
43
|
+
"cat\\s+[^\\n]*>",
|
|
44
|
+
"tee\\b",
|
|
45
|
+
"(?:^|\\s)(?:vim|nano|vi)\\b",
|
|
46
|
+
"(?:^|\\s)mv\\b",
|
|
47
|
+
"(?:^|\\s)cp\\b",
|
|
48
|
+
"(?:^|\\s)rm\\b",
|
|
49
|
+
"(?:^|\\s)mkdir\\b",
|
|
50
|
+
"(?:^|\\s)touch\\b",
|
|
51
|
+
"(?:^|\\s)chmod\\b",
|
|
52
|
+
"(?:^|\\s)chown\\b",
|
|
53
|
+
">>",
|
|
54
|
+
"(?:^|\\s)git\\s+add\\b",
|
|
55
|
+
"(?:^|\\s)git\\s+commit\\b",
|
|
56
|
+
"(?:^|\\s)git\\s+merge\\b",
|
|
57
|
+
"(?:^|\\s)git\\s+push\\b",
|
|
58
|
+
"(?:^|\\s)git\\s+reset\\b",
|
|
59
|
+
"(?:^|\\s)git\\s+checkout\\b",
|
|
60
|
+
"(?:^|\\s)git\\s+rebase\\b",
|
|
61
|
+
"(?:^|\\s)git\\s+stash\\b",
|
|
62
|
+
"(?:^|\\s)npm\\s+install\\b",
|
|
63
|
+
"(?:^|\\s)bun\\s+install\\b",
|
|
64
|
+
"(?:^|\\s)bun\\s+add\\b",
|
|
65
|
+
"(?:^|\\s)node\\s+(?:-e|--eval)\\b",
|
|
66
|
+
"(?:^|\\s)bun\\s+(?:-e|--eval)\\b",
|
|
67
|
+
"(?:^|\\s)python\\s+-c\\b",
|
|
68
|
+
"(?:^|\\s)perl\\s+-e\\b",
|
|
69
|
+
"(?:^|\\s)ruby\\s+-e\\b",
|
|
70
|
+
];
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
|
|
4
|
+
export type SessionPhase =
|
|
5
|
+
| 'claimed'
|
|
6
|
+
| 'phase1-done'
|
|
7
|
+
| 'waiting-merge'
|
|
8
|
+
| 'conflicting'
|
|
9
|
+
| 'pending-cleanup'
|
|
10
|
+
| 'merged'
|
|
11
|
+
| 'cleanup-done';
|
|
12
|
+
|
|
13
|
+
export interface SessionState {
|
|
14
|
+
issueId: string;
|
|
15
|
+
branch: string;
|
|
16
|
+
worktreePath: string;
|
|
17
|
+
prNumber: number | null;
|
|
18
|
+
prUrl: string | null;
|
|
19
|
+
phase: SessionPhase;
|
|
20
|
+
conflictFiles: string[];
|
|
21
|
+
startedAt: string;
|
|
22
|
+
lastChecked: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const SESSION_STATE_FILE = '.xtrm-session-state.json';
|
|
26
|
+
|
|
27
|
+
export function findSessionStateFile(startCwd: string): string | null {
|
|
28
|
+
let current = path.resolve(startCwd || process.cwd());
|
|
29
|
+
for (;;) {
|
|
30
|
+
const candidate = path.join(current, SESSION_STATE_FILE);
|
|
31
|
+
if (fs.existsSync(candidate)) return candidate;
|
|
32
|
+
const parent = path.dirname(current);
|
|
33
|
+
if (parent === current) return null;
|
|
34
|
+
current = parent;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function readSessionState(startCwd: string): SessionState | null {
|
|
39
|
+
const filePath = findSessionStateFile(startCwd);
|
|
40
|
+
if (!filePath) return null;
|
|
41
|
+
try {
|
|
42
|
+
const parsed = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
43
|
+
if (!parsed || typeof parsed !== 'object') return null;
|
|
44
|
+
if (!parsed.issueId || !parsed.branch || !parsed.worktreePath || !parsed.phase) return null;
|
|
45
|
+
return {
|
|
46
|
+
issueId: String(parsed.issueId),
|
|
47
|
+
branch: String(parsed.branch),
|
|
48
|
+
worktreePath: String(parsed.worktreePath),
|
|
49
|
+
prNumber: parsed.prNumber ?? null,
|
|
50
|
+
prUrl: parsed.prUrl ?? null,
|
|
51
|
+
phase: parsed.phase,
|
|
52
|
+
conflictFiles: Array.isArray(parsed.conflictFiles) ? parsed.conflictFiles.map(String) : [],
|
|
53
|
+
startedAt: String(parsed.startedAt || ''),
|
|
54
|
+
lastChecked: String(parsed.lastChecked || ''),
|
|
55
|
+
} as SessionState;
|
|
56
|
+
} catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ExtensionAPI, ToolCallEvent } from "@mariozechner/pi-coding-agent";
|
|
2
2
|
import { isToolCallEventType } from "@mariozechner/pi-coding-agent";
|
|
3
3
|
import { SubprocessRunner, EventAdapter, Logger } from "./core/lib";
|
|
4
|
+
import { SAFE_BASH_PREFIXES, DANGEROUS_BASH_PATTERNS } from "./core/guard-rules";
|
|
4
5
|
|
|
5
6
|
const logger = new Logger({ namespace: "main-guard" });
|
|
6
7
|
|
|
@@ -37,12 +38,14 @@ export default function (pi: ExtensionAPI) {
|
|
|
37
38
|
// 2. Safety Check: Dangerous Commands (Global)
|
|
38
39
|
if (isToolCallEventType("bash", event)) {
|
|
39
40
|
const cmd = event.input.command.trim();
|
|
40
|
-
|
|
41
|
+
const dangerousRegexes = DANGEROUS_BASH_PATTERNS.map((pattern) => new RegExp(pattern));
|
|
42
|
+
const dangerousMatch = dangerousRegexes.some((rx) => rx.test(cmd));
|
|
43
|
+
if (dangerousMatch && !cmd.includes("--help")) {
|
|
41
44
|
if (ctx.hasUI) {
|
|
42
45
|
const ok = await ctx.ui.confirm("Dangerous Command", `Allow execution of: ${cmd}?`);
|
|
43
46
|
if (!ok) return { block: true, reason: "Blocked by user confirmation" };
|
|
44
47
|
} else {
|
|
45
|
-
return { block: true, reason: "Dangerous command
|
|
48
|
+
return { block: true, reason: "Dangerous command blocked in non-interactive mode" };
|
|
46
49
|
}
|
|
47
50
|
}
|
|
48
51
|
}
|
|
@@ -78,18 +81,11 @@ export default function (pi: ExtensionAPI) {
|
|
|
78
81
|
}
|
|
79
82
|
|
|
80
83
|
// Safe allowlist
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
/^git\s+checkout\s+-b\s+\S+/,
|
|
87
|
-
/^git\s+switch\s+-c\s+\S+/,
|
|
88
|
-
...protectedBranches.map(b => new RegExp(`^git\\s+reset\\s+--hard\\s+origin/${b}\\b`)),
|
|
89
|
-
/^gh\s+/,
|
|
90
|
-
/^bd\s+/,
|
|
91
|
-
/^touch\s+\.beads\//,
|
|
92
|
-
];
|
|
84
|
+
const safePrefixRegexes = SAFE_BASH_PREFIXES.map((prefix) =>
|
|
85
|
+
new RegExp(`^${prefix.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`),
|
|
86
|
+
);
|
|
87
|
+
const safeResetRegexes = protectedBranches.map((b) => new RegExp(`^git\\s+reset\\s+--hard\\s+origin/${b}\\b`));
|
|
88
|
+
const SAFE_BASH_PATTERNS = [...safePrefixRegexes, ...safeResetRegexes];
|
|
93
89
|
|
|
94
90
|
if (SAFE_BASH_PATTERNS.some(p => p.test(cmd))) {
|
|
95
91
|
return undefined;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Plan Mode Extension
|
|
2
|
+
|
|
3
|
+
Read-only exploration mode for safe code analysis.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Read-only tools**: Restricts available tools to read, bash, grep, find, ls, question
|
|
8
|
+
- **Bash allowlist**: Only read-only bash commands are allowed
|
|
9
|
+
- **Plan extraction**: Extracts numbered steps from `Plan:` sections
|
|
10
|
+
- **Progress tracking**: Widget shows completion status during execution
|
|
11
|
+
- **[DONE:n] markers**: Explicit step completion tracking
|
|
12
|
+
- **Session persistence**: State survives session resume
|
|
13
|
+
|
|
14
|
+
## Commands
|
|
15
|
+
|
|
16
|
+
- `/plan` - Toggle plan mode
|
|
17
|
+
- `/todos` - Show current plan progress
|
|
18
|
+
- `Ctrl+Alt+P` - Toggle plan mode (shortcut)
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
1. Enable plan mode with `/plan` or `--plan` flag
|
|
23
|
+
2. Ask the agent to analyze code and create a plan
|
|
24
|
+
3. The agent should output a numbered plan under a `Plan:` header:
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
Plan:
|
|
28
|
+
1. First step description
|
|
29
|
+
2. Second step description
|
|
30
|
+
3. Third step description
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
4. Choose "Execute the plan" when prompted
|
|
34
|
+
5. During execution, the agent marks steps complete with `[DONE:n]` tags
|
|
35
|
+
6. Progress widget shows completion status
|
|
36
|
+
|
|
37
|
+
## How It Works
|
|
38
|
+
|
|
39
|
+
### Plan Mode (Read-Only)
|
|
40
|
+
- Only read-only tools available
|
|
41
|
+
- Bash commands filtered through allowlist
|
|
42
|
+
- Agent creates a plan without making changes
|
|
43
|
+
|
|
44
|
+
### Execution Mode
|
|
45
|
+
- Full tool access restored
|
|
46
|
+
- Agent executes steps in order
|
|
47
|
+
- `[DONE:n]` markers track completion
|
|
48
|
+
- Widget shows progress
|
|
49
|
+
|
|
50
|
+
### Command Allowlist
|
|
51
|
+
|
|
52
|
+
Safe commands (allowed):
|
|
53
|
+
- File inspection: `cat`, `head`, `tail`, `less`, `more`
|
|
54
|
+
- Search: `grep`, `find`, `rg`, `fd`
|
|
55
|
+
- Directory: `ls`, `pwd`, `tree`
|
|
56
|
+
- Git read: `git status`, `git log`, `git diff`, `git branch`
|
|
57
|
+
- Package info: `npm list`, `npm outdated`, `yarn info`
|
|
58
|
+
- System info: `uname`, `whoami`, `date`, `uptime`
|
|
59
|
+
|
|
60
|
+
Blocked commands:
|
|
61
|
+
- File modification: `rm`, `mv`, `cp`, `mkdir`, `touch`
|
|
62
|
+
- Git write: `git add`, `git commit`, `git push`
|
|
63
|
+
- Package install: `npm install`, `yarn add`, `pip install`
|
|
64
|
+
- System: `sudo`, `kill`, `reboot`
|
|
65
|
+
- Editors: `vim`, `nano`, `code`
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plan Mode Extension
|
|
3
|
+
*
|
|
4
|
+
* Read-only exploration mode for safe code analysis.
|
|
5
|
+
* When enabled, only read-only tools are available.
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - /plan command or Ctrl+Alt+P to toggle
|
|
9
|
+
* - Bash restricted to allowlisted read-only commands
|
|
10
|
+
* - Extracts numbered plan steps from "Plan:" sections
|
|
11
|
+
* - [DONE:n] markers to complete steps during execution
|
|
12
|
+
* - Progress tracking widget during execution
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type { AgentMessage } from "@mariozechner/pi-agent-core";
|
|
16
|
+
import type { AssistantMessage, TextContent } from "@mariozechner/pi-ai";
|
|
17
|
+
import type { ExtensionAPI, ExtensionContext } from "@mariozechner/pi-coding-agent";
|
|
18
|
+
import { Key } from "@mariozechner/pi-tui";
|
|
19
|
+
import { extractTodoItems, isSafeCommand, markCompletedSteps, type TodoItem } from "./utils.js";
|
|
20
|
+
|
|
21
|
+
// Tools
|
|
22
|
+
const PLAN_MODE_TOOLS = ["read", "bash", "grep", "find", "ls", "questionnaire"];
|
|
23
|
+
const NORMAL_MODE_TOOLS = ["read", "bash", "edit", "write"];
|
|
24
|
+
|
|
25
|
+
// Type guard for assistant messages
|
|
26
|
+
function isAssistantMessage(m: AgentMessage): m is AssistantMessage {
|
|
27
|
+
return m.role === "assistant" && Array.isArray(m.content);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Extract text content from an assistant message
|
|
31
|
+
function getTextContent(message: AssistantMessage): string {
|
|
32
|
+
return message.content
|
|
33
|
+
.filter((block): block is TextContent => block.type === "text")
|
|
34
|
+
.map((block) => block.text)
|
|
35
|
+
.join("\n");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default function planModeExtension(pi: ExtensionAPI): void {
|
|
39
|
+
let planModeEnabled = false;
|
|
40
|
+
let executionMode = false;
|
|
41
|
+
let todoItems: TodoItem[] = [];
|
|
42
|
+
|
|
43
|
+
pi.registerFlag("plan", {
|
|
44
|
+
description: "Start in plan mode (read-only exploration)",
|
|
45
|
+
type: "boolean",
|
|
46
|
+
default: false,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
function updateStatus(ctx: ExtensionContext): void {
|
|
50
|
+
// Footer status
|
|
51
|
+
if (executionMode && todoItems.length > 0) {
|
|
52
|
+
const completed = todoItems.filter((t) => t.completed).length;
|
|
53
|
+
ctx.ui.setStatus("plan-mode", ctx.ui.theme.fg("accent", `📋 ${completed}/${todoItems.length}`));
|
|
54
|
+
} else if (planModeEnabled) {
|
|
55
|
+
ctx.ui.setStatus("plan-mode", ctx.ui.theme.fg("warning", "⏸ plan"));
|
|
56
|
+
} else {
|
|
57
|
+
ctx.ui.setStatus("plan-mode", undefined);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Widget showing todo list
|
|
61
|
+
if (executionMode && todoItems.length > 0) {
|
|
62
|
+
const lines = todoItems.map((item) => {
|
|
63
|
+
if (item.completed) {
|
|
64
|
+
return (
|
|
65
|
+
ctx.ui.theme.fg("success", "☑ ") + ctx.ui.theme.fg("muted", ctx.ui.theme.strikethrough(item.text))
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
return `${ctx.ui.theme.fg("muted", "☐ ")}${item.text}`;
|
|
69
|
+
});
|
|
70
|
+
ctx.ui.setWidget("plan-todos", lines);
|
|
71
|
+
} else {
|
|
72
|
+
ctx.ui.setWidget("plan-todos", undefined);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function togglePlanMode(ctx: ExtensionContext): void {
|
|
77
|
+
planModeEnabled = !planModeEnabled;
|
|
78
|
+
executionMode = false;
|
|
79
|
+
todoItems = [];
|
|
80
|
+
|
|
81
|
+
if (planModeEnabled) {
|
|
82
|
+
pi.setActiveTools(PLAN_MODE_TOOLS);
|
|
83
|
+
ctx.ui.notify(`Plan mode enabled. Tools: ${PLAN_MODE_TOOLS.join(", ")}`);
|
|
84
|
+
} else {
|
|
85
|
+
pi.setActiveTools(NORMAL_MODE_TOOLS);
|
|
86
|
+
ctx.ui.notify("Plan mode disabled. Full access restored.");
|
|
87
|
+
}
|
|
88
|
+
updateStatus(ctx);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function persistState(): void {
|
|
92
|
+
pi.appendEntry("plan-mode", {
|
|
93
|
+
enabled: planModeEnabled,
|
|
94
|
+
todos: todoItems,
|
|
95
|
+
executing: executionMode,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
pi.registerCommand("plan", {
|
|
100
|
+
description: "Toggle plan mode (read-only exploration)",
|
|
101
|
+
handler: async (_args, ctx) => togglePlanMode(ctx),
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
pi.registerCommand("todos", {
|
|
105
|
+
description: "Show current plan todo list",
|
|
106
|
+
handler: async (_args, ctx) => {
|
|
107
|
+
if (todoItems.length === 0) {
|
|
108
|
+
ctx.ui.notify("No todos. Create a plan first with /plan", "info");
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const list = todoItems.map((item, i) => `${i + 1}. ${item.completed ? "✓" : "○"} ${item.text}`).join("\n");
|
|
112
|
+
ctx.ui.notify(`Plan Progress:\n${list}`, "info");
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
pi.registerShortcut(Key.ctrlAlt("p"), {
|
|
117
|
+
description: "Toggle plan mode",
|
|
118
|
+
handler: async (ctx) => togglePlanMode(ctx),
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// Block destructive bash commands in plan mode
|
|
122
|
+
pi.on("tool_call", async (event) => {
|
|
123
|
+
if (!planModeEnabled || event.toolName !== "bash") return;
|
|
124
|
+
|
|
125
|
+
const command = event.input.command as string;
|
|
126
|
+
if (!isSafeCommand(command)) {
|
|
127
|
+
return {
|
|
128
|
+
block: true,
|
|
129
|
+
reason: `Plan mode: command blocked (not allowlisted). Use /plan to disable plan mode first.\nCommand: ${command}`,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// Filter out stale plan mode context when not in plan mode
|
|
135
|
+
pi.on("context", async (event) => {
|
|
136
|
+
if (planModeEnabled) return;
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
messages: event.messages.filter((m) => {
|
|
140
|
+
const msg = m as AgentMessage & { customType?: string };
|
|
141
|
+
if (msg.customType === "plan-mode-context") return false;
|
|
142
|
+
if (msg.role !== "user") return true;
|
|
143
|
+
|
|
144
|
+
const content = msg.content;
|
|
145
|
+
if (typeof content === "string") {
|
|
146
|
+
return !content.includes("[PLAN MODE ACTIVE]");
|
|
147
|
+
}
|
|
148
|
+
if (Array.isArray(content)) {
|
|
149
|
+
return !content.some(
|
|
150
|
+
(c) => c.type === "text" && (c as TextContent).text?.includes("[PLAN MODE ACTIVE]"),
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
return true;
|
|
154
|
+
}),
|
|
155
|
+
};
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// Inject plan/execution context before agent starts
|
|
159
|
+
pi.on("before_agent_start", async () => {
|
|
160
|
+
if (planModeEnabled) {
|
|
161
|
+
return {
|
|
162
|
+
message: {
|
|
163
|
+
customType: "plan-mode-context",
|
|
164
|
+
content: `[PLAN MODE ACTIVE]
|
|
165
|
+
You are in plan mode - a read-only exploration mode for safe code analysis.
|
|
166
|
+
|
|
167
|
+
Restrictions:
|
|
168
|
+
- You can only use: read, bash, grep, find, ls, questionnaire
|
|
169
|
+
- You CANNOT use: edit, write (file modifications are disabled)
|
|
170
|
+
- Bash is restricted to an allowlist of read-only commands
|
|
171
|
+
|
|
172
|
+
Ask clarifying questions using the questionnaire tool.
|
|
173
|
+
Use brave-search skill via bash for web research.
|
|
174
|
+
|
|
175
|
+
Create a detailed numbered plan under a "Plan:" header:
|
|
176
|
+
|
|
177
|
+
Plan:
|
|
178
|
+
1. First step description
|
|
179
|
+
2. Second step description
|
|
180
|
+
...
|
|
181
|
+
|
|
182
|
+
Do NOT attempt to make changes - just describe what you would do.`,
|
|
183
|
+
display: false,
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (executionMode && todoItems.length > 0) {
|
|
189
|
+
const remaining = todoItems.filter((t) => !t.completed);
|
|
190
|
+
const todoList = remaining.map((t) => `${t.step}. ${t.text}`).join("\n");
|
|
191
|
+
return {
|
|
192
|
+
message: {
|
|
193
|
+
customType: "plan-execution-context",
|
|
194
|
+
content: `[EXECUTING PLAN - Full tool access enabled]
|
|
195
|
+
|
|
196
|
+
Remaining steps:
|
|
197
|
+
${todoList}
|
|
198
|
+
|
|
199
|
+
Execute each step in order.
|
|
200
|
+
After completing a step, include a [DONE:n] tag in your response.`,
|
|
201
|
+
display: false,
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// Track progress after each turn
|
|
208
|
+
pi.on("turn_end", async (event, ctx) => {
|
|
209
|
+
if (!executionMode || todoItems.length === 0) return;
|
|
210
|
+
if (!isAssistantMessage(event.message)) return;
|
|
211
|
+
|
|
212
|
+
const text = getTextContent(event.message);
|
|
213
|
+
if (markCompletedSteps(text, todoItems) > 0) {
|
|
214
|
+
updateStatus(ctx);
|
|
215
|
+
}
|
|
216
|
+
persistState();
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// Handle plan completion and plan mode UI
|
|
220
|
+
pi.on("agent_end", async (event, ctx) => {
|
|
221
|
+
// Check if execution is complete
|
|
222
|
+
if (executionMode && todoItems.length > 0) {
|
|
223
|
+
if (todoItems.every((t) => t.completed)) {
|
|
224
|
+
const completedList = todoItems.map((t) => `~~${t.text}~~`).join("\n");
|
|
225
|
+
pi.sendMessage(
|
|
226
|
+
{ customType: "plan-complete", content: `**Plan Complete!** ✓\n\n${completedList}`, display: true },
|
|
227
|
+
{ triggerTurn: false },
|
|
228
|
+
);
|
|
229
|
+
executionMode = false;
|
|
230
|
+
todoItems = [];
|
|
231
|
+
pi.setActiveTools(NORMAL_MODE_TOOLS);
|
|
232
|
+
updateStatus(ctx);
|
|
233
|
+
persistState(); // Save cleared state so resume doesn't restore old execution mode
|
|
234
|
+
}
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (!planModeEnabled || !ctx.hasUI) return;
|
|
239
|
+
|
|
240
|
+
// Extract todos from last assistant message
|
|
241
|
+
const lastAssistant = [...event.messages].reverse().find(isAssistantMessage);
|
|
242
|
+
if (lastAssistant) {
|
|
243
|
+
const extracted = extractTodoItems(getTextContent(lastAssistant));
|
|
244
|
+
if (extracted.length > 0) {
|
|
245
|
+
todoItems = extracted;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Show plan steps and prompt for next action
|
|
250
|
+
if (todoItems.length > 0) {
|
|
251
|
+
const todoListText = todoItems.map((t, i) => `${i + 1}. ☐ ${t.text}`).join("\n");
|
|
252
|
+
pi.sendMessage(
|
|
253
|
+
{
|
|
254
|
+
customType: "plan-todo-list",
|
|
255
|
+
content: `**Plan Steps (${todoItems.length}):**\n\n${todoListText}`,
|
|
256
|
+
display: true,
|
|
257
|
+
},
|
|
258
|
+
{ triggerTurn: false },
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const choice = await ctx.ui.select("Plan mode - what next?", [
|
|
263
|
+
todoItems.length > 0 ? "Execute the plan (track progress)" : "Execute the plan",
|
|
264
|
+
"Stay in plan mode",
|
|
265
|
+
"Refine the plan",
|
|
266
|
+
]);
|
|
267
|
+
|
|
268
|
+
if (choice?.startsWith("Execute")) {
|
|
269
|
+
planModeEnabled = false;
|
|
270
|
+
executionMode = todoItems.length > 0;
|
|
271
|
+
pi.setActiveTools(NORMAL_MODE_TOOLS);
|
|
272
|
+
updateStatus(ctx);
|
|
273
|
+
|
|
274
|
+
const execMessage =
|
|
275
|
+
todoItems.length > 0
|
|
276
|
+
? `Execute the plan. Start with: ${todoItems[0].text}`
|
|
277
|
+
: "Execute the plan you just created.";
|
|
278
|
+
pi.sendMessage(
|
|
279
|
+
{ customType: "plan-mode-execute", content: execMessage, display: true },
|
|
280
|
+
{ triggerTurn: true },
|
|
281
|
+
);
|
|
282
|
+
} else if (choice === "Refine the plan") {
|
|
283
|
+
const refinement = await ctx.ui.editor("Refine the plan:", "");
|
|
284
|
+
if (refinement?.trim()) {
|
|
285
|
+
pi.sendUserMessage(refinement.trim());
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
// Restore state on session start/resume
|
|
291
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
292
|
+
if (pi.getFlag("plan") === true) {
|
|
293
|
+
planModeEnabled = true;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const entries = ctx.sessionManager.getEntries();
|
|
297
|
+
|
|
298
|
+
// Restore persisted state
|
|
299
|
+
const planModeEntry = entries
|
|
300
|
+
.filter((e: { type: string; customType?: string }) => e.type === "custom" && e.customType === "plan-mode")
|
|
301
|
+
.pop() as { data?: { enabled: boolean; todos?: TodoItem[]; executing?: boolean } } | undefined;
|
|
302
|
+
|
|
303
|
+
if (planModeEntry?.data) {
|
|
304
|
+
planModeEnabled = planModeEntry.data.enabled ?? planModeEnabled;
|
|
305
|
+
todoItems = planModeEntry.data.todos ?? todoItems;
|
|
306
|
+
executionMode = planModeEntry.data.executing ?? executionMode;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// On resume: re-scan messages to rebuild completion state
|
|
310
|
+
// Only scan messages AFTER the last "plan-mode-execute" to avoid picking up [DONE:n] from previous plans
|
|
311
|
+
const isResume = planModeEntry !== undefined;
|
|
312
|
+
if (isResume && executionMode && todoItems.length > 0) {
|
|
313
|
+
// Find the index of the last plan-mode-execute entry (marks when current execution started)
|
|
314
|
+
let executeIndex = -1;
|
|
315
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
316
|
+
const entry = entries[i] as { type: string; customType?: string };
|
|
317
|
+
if (entry.customType === "plan-mode-execute") {
|
|
318
|
+
executeIndex = i;
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// Only scan messages after the execute marker
|
|
324
|
+
const messages: AssistantMessage[] = [];
|
|
325
|
+
for (let i = executeIndex + 1; i < entries.length; i++) {
|
|
326
|
+
const entry = entries[i];
|
|
327
|
+
if (entry.type === "message" && "message" in entry && isAssistantMessage(entry.message as AgentMessage)) {
|
|
328
|
+
messages.push(entry.message as AssistantMessage);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
const allText = messages.map(getTextContent).join("\n");
|
|
332
|
+
markCompletedSteps(allText, todoItems);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (planModeEnabled) {
|
|
336
|
+
pi.setActiveTools(PLAN_MODE_TOOLS);
|
|
337
|
+
}
|
|
338
|
+
updateStatus(ctx);
|
|
339
|
+
});
|
|
340
|
+
}
|