@dreki-gg/pi-plan-mode 0.13.0 → 0.14.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/CHANGELOG.md +23 -0
- package/extensions/plan-mode/__tests__/atomic-write.test.ts +43 -0
- package/extensions/plan-mode/__tests__/html-render.test.ts +43 -0
- package/extensions/plan-mode/__tests__/phase-transitions.test.ts +42 -0
- package/extensions/plan-mode/__tests__/plans-manifest.test.ts +37 -0
- package/extensions/plan-mode/__tests__/prompts.test.ts +39 -1
- package/extensions/plan-mode/__tests__/task-storage.test.ts +52 -0
- package/extensions/plan-mode/__tests__/types.test.ts +68 -0
- package/extensions/plan-mode/constants.ts +2 -1
- package/extensions/plan-mode/html/render.ts +67 -0
- package/extensions/plan-mode/html/templates/plan.pug +59 -0
- package/extensions/plan-mode/index.ts +60 -72
- package/extensions/plan-mode/phase-transitions.ts +1 -1
- package/extensions/plan-mode/plan-storage.ts +1 -80
- package/extensions/plan-mode/prompts.ts +37 -32
- package/extensions/plan-mode/pug.d.ts +5 -0
- package/extensions/plan-mode/resume.ts +38 -37
- package/extensions/plan-mode/state.ts +7 -0
- package/extensions/plan-mode/storage/atomic-write.ts +53 -0
- package/extensions/plan-mode/storage/plan-storage.ts +47 -0
- package/extensions/plan-mode/storage/plans-manifest.ts +57 -0
- package/extensions/plan-mode/storage/task-storage.ts +44 -0
- package/extensions/plan-mode/tools/submit-plan.ts +41 -81
- package/extensions/plan-mode/tools/update-task.ts +82 -0
- package/extensions/plan-mode/types.ts +57 -4
- package/extensions/plan-mode/ui.ts +18 -11
- package/package.json +3 -2
- package/extensions/plan-mode/plans-json.ts +0 -48
- package/extensions/plan-mode/tools/update-step.ts +0 -146
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plan disk I/O — exec-pending markers and handoff documents.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { mkdir, readFile, readdir, unlink, writeFile } from 'node:fs/promises';
|
|
6
|
+
import type { ExecPendingConfig } from '../types.js';
|
|
7
|
+
import { EXEC_PENDING_FILE } from '../constants.js';
|
|
8
|
+
|
|
9
|
+
export async function writeExecPending(dir: string, config: ExecPendingConfig): Promise<void> {
|
|
10
|
+
await mkdir(dir, { recursive: true });
|
|
11
|
+
await writeFile(`${dir}/${EXEC_PENDING_FILE}`, JSON.stringify(config, null, 2) + '\n', 'utf-8');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function readAndClearExecPending(): Promise<{ planDir: string; config: ExecPendingConfig } | undefined> {
|
|
15
|
+
try {
|
|
16
|
+
const entries = await readdir('.plans', { withFileTypes: true });
|
|
17
|
+
for (const entry of entries) {
|
|
18
|
+
if (!entry.isDirectory()) continue;
|
|
19
|
+
const dir = `.plans/${entry.name}`;
|
|
20
|
+
const markerPath = `${dir}/${EXEC_PENDING_FILE}`;
|
|
21
|
+
try {
|
|
22
|
+
const text = await readFile(markerPath, 'utf-8');
|
|
23
|
+
const config = JSON.parse(text) as ExecPendingConfig;
|
|
24
|
+
await unlink(markerPath);
|
|
25
|
+
return { planDir: dir, config };
|
|
26
|
+
} catch {
|
|
27
|
+
// No marker in this directory
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
} catch {
|
|
31
|
+
// .plans/ doesn't exist
|
|
32
|
+
}
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function saveHandoff(planDir: string, content: string): Promise<void> {
|
|
37
|
+
await mkdir(planDir, { recursive: true });
|
|
38
|
+
await writeFile(`${planDir}/HANDOFF.md`, content, 'utf-8');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function loadHandoff(planDir: string): Promise<string | undefined> {
|
|
42
|
+
try {
|
|
43
|
+
return await readFile(`${planDir}/HANDOFF.md`, 'utf-8');
|
|
44
|
+
} catch {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { mkdir, readFile } from 'node:fs/promises';
|
|
2
|
+
import { writeFileAtomic } from './atomic-write.js';
|
|
3
|
+
|
|
4
|
+
const MANIFEST_PATH = '.plans/plans.jsonl';
|
|
5
|
+
|
|
6
|
+
export interface PlanManifestEntry {
|
|
7
|
+
_type: 'plan';
|
|
8
|
+
name: string;
|
|
9
|
+
status: 'in-progress' | 'done';
|
|
10
|
+
title: string;
|
|
11
|
+
created_at: string;
|
|
12
|
+
completed_at: string | null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function readPlansManifest(): Promise<PlanManifestEntry[]> {
|
|
16
|
+
let text: string;
|
|
17
|
+
try { text = await readFile(MANIFEST_PATH, 'utf8'); } catch { return []; }
|
|
18
|
+
const entries: PlanManifestEntry[] = [];
|
|
19
|
+
for (const [index, raw] of text.split(/\r?\n/).entries()) {
|
|
20
|
+
if (!raw.trim()) continue;
|
|
21
|
+
let parsed: unknown;
|
|
22
|
+
try { parsed = JSON.parse(raw); } catch (error) { throw new Error(`Invalid plans.jsonl at line ${index + 1}: ${(error as Error).message}`); }
|
|
23
|
+
if (!isPlanManifestEntry(parsed)) throw new Error(`Invalid plans.jsonl record at line ${index + 1}`);
|
|
24
|
+
entries.push(parsed);
|
|
25
|
+
}
|
|
26
|
+
return entries;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function writePlansManifest(entries: PlanManifestEntry[]): Promise<void> {
|
|
30
|
+
await mkdir('.plans', { recursive: true });
|
|
31
|
+
const content = entries.map((entry) => JSON.stringify(entry)).join('\n') + (entries.length ? '\n' : '');
|
|
32
|
+
await writeFileAtomic(MANIFEST_PATH, content);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function upsertPlanEntry(name: string, updates: { status: 'in-progress' | 'done'; title?: string }): Promise<void> {
|
|
36
|
+
const entries = await readPlansManifest();
|
|
37
|
+
const now = new Date().toISOString();
|
|
38
|
+
const index = entries.findIndex((entry) => entry.name === name);
|
|
39
|
+
const existing = index === -1 ? undefined : entries[index];
|
|
40
|
+
const entry: PlanManifestEntry = {
|
|
41
|
+
_type: 'plan',
|
|
42
|
+
name,
|
|
43
|
+
status: updates.status,
|
|
44
|
+
title: updates.title ?? existing?.title ?? 'Untitled plan',
|
|
45
|
+
created_at: existing?.created_at ?? now,
|
|
46
|
+
completed_at: updates.status === 'done' ? now : null,
|
|
47
|
+
};
|
|
48
|
+
if (index === -1) entries.push(entry);
|
|
49
|
+
else entries[index] = entry;
|
|
50
|
+
await writePlansManifest(entries);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function isPlanManifestEntry(value: unknown): value is PlanManifestEntry {
|
|
54
|
+
if (typeof value !== 'object' || value === null) return false;
|
|
55
|
+
const record = value as Record<string, unknown>;
|
|
56
|
+
return record._type === 'plan' && typeof record.name === 'string' && (record.status === 'in-progress' || record.status === 'done') && typeof record.title === 'string' && typeof record.created_at === 'string' && (record.completed_at === null || typeof record.completed_at === 'string');
|
|
57
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { mkdir, readFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { isTaskMeta, isTaskRecord, type TaskMeta, type TaskRecord } from '../types.js';
|
|
4
|
+
import { writeFileAtomic } from './atomic-write.js';
|
|
5
|
+
|
|
6
|
+
const TASKS_FILE = 'tasks.jsonl';
|
|
7
|
+
|
|
8
|
+
export interface TasksSnapshot { meta: TaskMeta; tasks: TaskRecord[] }
|
|
9
|
+
|
|
10
|
+
export async function readTasksJsonl(planDir: string): Promise<TasksSnapshot | undefined> {
|
|
11
|
+
let text: string;
|
|
12
|
+
try { text = await readFile(join(planDir, TASKS_FILE), 'utf8'); } catch { return undefined; }
|
|
13
|
+
if (!text.trim()) throw new Error('tasks.jsonl is missing meta record');
|
|
14
|
+
|
|
15
|
+
let meta: TaskMeta | undefined;
|
|
16
|
+
const tasks: TaskRecord[] = [];
|
|
17
|
+
for (const [index, raw] of text.split(/\r?\n/).entries()) {
|
|
18
|
+
if (!raw.trim()) continue;
|
|
19
|
+
let parsed: unknown;
|
|
20
|
+
try { parsed = JSON.parse(raw); } catch (error) { throw new Error(`Invalid JSONL at line ${index + 1}: ${(error as Error).message}`); }
|
|
21
|
+
if (isTaskMeta(parsed)) meta = parsed;
|
|
22
|
+
else if (isTaskRecord(parsed)) tasks.push(parsed);
|
|
23
|
+
else throw new Error(`Invalid tasks.jsonl record at line ${index + 1}`);
|
|
24
|
+
}
|
|
25
|
+
if (!meta) throw new Error('tasks.jsonl is missing meta record');
|
|
26
|
+
return { meta, tasks };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function writeTasksJsonl(planDir: string, meta: TaskMeta, tasks: TaskRecord[]): Promise<void> {
|
|
30
|
+
await mkdir(planDir, { recursive: true });
|
|
31
|
+
const content = [meta, ...tasks].map((record) => JSON.stringify(record)).join('\n') + '\n';
|
|
32
|
+
await writeFileAtomic(join(planDir, TASKS_FILE), content);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function updateTask(planDir: string, taskId: string, updates: Partial<Omit<TaskRecord, '_type' | 'id' | 'created_at'>>): Promise<TaskRecord> {
|
|
36
|
+
const snapshot = await readTasksJsonl(planDir);
|
|
37
|
+
if (!snapshot) throw new Error(`No tasks.jsonl found in ${planDir}`);
|
|
38
|
+
const index = snapshot.tasks.findIndex((task) => task.id === taskId);
|
|
39
|
+
if (index === -1) throw new Error(`Task not found: ${taskId}`);
|
|
40
|
+
const updated: TaskRecord = { ...snapshot.tasks[index], ...updates, updated_at: new Date().toISOString() };
|
|
41
|
+
snapshot.tasks[index] = updated;
|
|
42
|
+
await writeTasksJsonl(planDir, snapshot.meta, snapshot.tasks);
|
|
43
|
+
return updated;
|
|
44
|
+
}
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* submit_plan tool — available during the plan phase.
|
|
3
|
-
*
|
|
4
|
-
* The planner calls this to submit a structured plan with typed steps.
|
|
5
|
-
* Writes `.plans/<name>/plan.json` and updates the plans.json manifest.
|
|
6
3
|
*/
|
|
7
4
|
|
|
8
5
|
import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
|
|
9
6
|
import { Text } from '@earendil-works/pi-tui';
|
|
10
7
|
import { Type } from 'typebox';
|
|
11
8
|
import { mkdir, writeFile } from 'node:fs/promises';
|
|
12
|
-
import {
|
|
13
|
-
import { saveHandoff } from '../plan-storage.js';
|
|
9
|
+
import { renderPlanHtml } from '../html/render.js';
|
|
10
|
+
import { saveHandoff } from '../storage/plan-storage.js';
|
|
11
|
+
import { writeTasksJsonl } from '../storage/task-storage.js';
|
|
12
|
+
import { upsertPlanEntry } from '../storage/plans-manifest.js';
|
|
14
13
|
import { toKebabCase } from '../utils.js';
|
|
15
|
-
import type { PlanData,
|
|
14
|
+
import type { PlanData, TaskMeta, TaskRecord } from '../types.js';
|
|
16
15
|
|
|
17
16
|
export interface SubmitPlanCallbacks {
|
|
18
17
|
onPlanSubmitted: (planDir: string, plan: PlanData) => void;
|
|
@@ -22,80 +21,58 @@ export function registerSubmitPlanTool(pi: ExtensionAPI, callbacks: SubmitPlanCa
|
|
|
22
21
|
pi.registerTool({
|
|
23
22
|
name: 'submit_plan',
|
|
24
23
|
label: 'Submit Plan',
|
|
25
|
-
description:
|
|
26
|
-
|
|
27
|
-
'Each step has a short description (for progress display) and detailed implementation instructions. ' +
|
|
28
|
-
'This finalizes the plan, writes .plans/<name>/plan.json and .plans/<name>/HANDOFF.md.',
|
|
29
|
-
promptSnippet:
|
|
30
|
-
'Submit a structured plan with title, handoff (what/why/context), and steps',
|
|
24
|
+
description: 'Finalize a conversational plan with task IDs, JSONL storage, HANDOFF.md, and generated plan.html.',
|
|
25
|
+
promptSnippet: 'Finalize the plan with title, handoff, tasks, dependencies, and optional prototype Pug',
|
|
31
26
|
promptGuidelines: [
|
|
32
|
-
'
|
|
33
|
-
'Each
|
|
34
|
-
'
|
|
27
|
+
'Only call submit_plan after shared understanding has been reached with the user.',
|
|
28
|
+
'Each task needs an id like t-001, a short description, and optional depends_on task IDs.',
|
|
29
|
+
'When a different agent or human will execute the plan, include detailed implementation instructions in each task\'s details field.',
|
|
30
|
+
'When you are planning and executing yourself (same session), use lightweight checklist-style tasks: just id + description, omit details. Put the real context in the handoff document instead.',
|
|
31
|
+
'The handoff must be thorough enough that both a human reviewer and executor agent with zero prior context can understand the plan.',
|
|
35
32
|
],
|
|
36
33
|
parameters: Type.Object({
|
|
37
|
-
name: Type.String({
|
|
38
|
-
description: 'Short kebab-case name for the plan (e.g. "add-auth-middleware")',
|
|
39
|
-
}),
|
|
34
|
+
name: Type.String({ description: 'Short kebab-case name for the plan (e.g. "add-auth-middleware")' }),
|
|
40
35
|
title: Type.String({ description: 'Human-readable plan title' }),
|
|
41
|
-
handoff: Type.String({
|
|
42
|
-
|
|
43
|
-
'Markdown content for HANDOFF.md — explains what change is being made, why, and includes relevant codebase context for the executor',
|
|
44
|
-
}),
|
|
45
|
-
steps: Type.Array(
|
|
36
|
+
handoff: Type.String({ description: 'Markdown content for HANDOFF.md' }),
|
|
37
|
+
tasks: Type.Array(
|
|
46
38
|
Type.Object({
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}),
|
|
50
|
-
|
|
51
|
-
description: 'Full implementation instructions for this step',
|
|
52
|
-
}),
|
|
39
|
+
id: Type.String({ description: 'Stable task ID, e.g. t-001' }),
|
|
40
|
+
description: Type.String({ description: 'Short task label for progress display (≤60 chars)' }),
|
|
41
|
+
details: Type.Optional(Type.String({ description: 'Full implementation instructions for this task. Omit for lightweight checklist-style plans when you are executing yourself.' })),
|
|
42
|
+
depends_on: Type.Optional(Type.Array(Type.String({ description: 'Dependency task ID' }))),
|
|
53
43
|
}),
|
|
54
44
|
{ minItems: 1 },
|
|
55
45
|
),
|
|
46
|
+
prototype: Type.Optional(Type.String({ description: 'Optional Pug markup for the prototype section in plan.html' })),
|
|
56
47
|
}),
|
|
57
48
|
|
|
58
49
|
async execute(_toolCallId, params) {
|
|
59
50
|
const planName = toKebabCase(params.name);
|
|
60
51
|
const planDir = `.plans/${planName}`;
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
52
|
+
const now = new Date().toISOString();
|
|
53
|
+
const meta: TaskMeta = { _type: 'meta', title: params.title, plan_name: planName, created_at: now };
|
|
54
|
+
const tasks: TaskRecord[] = params.tasks.map((task) => ({
|
|
55
|
+
_type: 'task',
|
|
56
|
+
id: task.id,
|
|
57
|
+
description: task.description.slice(0, 60),
|
|
58
|
+
details: task.details ?? '',
|
|
59
|
+
status: 'pending',
|
|
60
|
+
depends_on: task.depends_on,
|
|
61
|
+
created_at: now,
|
|
62
|
+
updated_at: now,
|
|
66
63
|
}));
|
|
64
|
+
const plan: PlanData = { title: params.title, planName, handoff: params.handoff, tasks };
|
|
67
65
|
|
|
68
|
-
const plan: PlanData = {
|
|
69
|
-
title: params.title,
|
|
70
|
-
handoff: params.handoff,
|
|
71
|
-
steps,
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
// Write plan.json and HANDOFF.md
|
|
75
66
|
await mkdir(planDir, { recursive: true });
|
|
76
|
-
await
|
|
67
|
+
await writeTasksJsonl(planDir, meta, tasks);
|
|
77
68
|
await saveHandoff(planDir, params.handoff);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const manifest = await readPlansJson();
|
|
81
|
-
const now = new Date().toISOString();
|
|
82
|
-
manifest[planName] = {
|
|
83
|
-
status: 'in-progress',
|
|
84
|
-
title: params.title,
|
|
85
|
-
created: manifest[planName]?.created ?? now,
|
|
86
|
-
completed: null,
|
|
87
|
-
};
|
|
88
|
-
await writeFile('.plans/plans.json', serializePlansJson(manifest), 'utf-8');
|
|
69
|
+
await writeFile(`${planDir}/plan.html`, renderPlanHtml(plan, params.prototype), 'utf-8');
|
|
70
|
+
await upsertPlanEntry(planName, { status: 'in-progress', title: params.title });
|
|
89
71
|
|
|
90
72
|
callbacks.onPlanSubmitted(planDir, plan);
|
|
91
73
|
|
|
92
74
|
return {
|
|
93
|
-
content: [
|
|
94
|
-
{
|
|
95
|
-
type: 'text' as const,
|
|
96
|
-
text: `Plan "${params.title}" saved with ${steps.length} steps. Waiting for user to review and execute.`,
|
|
97
|
-
},
|
|
98
|
-
],
|
|
75
|
+
content: [{ type: 'text' as const, text: `Plan "${params.title}" saved with ${tasks.length} tasks. Review ${planDir}/plan.html, then execute when ready.` }],
|
|
99
76
|
details: { planDir, plan },
|
|
100
77
|
terminate: true,
|
|
101
78
|
};
|
|
@@ -106,32 +83,15 @@ export function registerSubmitPlanTool(pi: ExtensionAPI, callbacks: SubmitPlanCa
|
|
|
106
83
|
const title = (args as { title?: string }).title ?? '';
|
|
107
84
|
let content = theme.fg('toolTitle', theme.bold('submit_plan '));
|
|
108
85
|
content += theme.fg('accent', name);
|
|
109
|
-
if (title) {
|
|
110
|
-
content += ' ' + theme.fg('dim', `"${title}"`);
|
|
111
|
-
}
|
|
86
|
+
if (title) content += ' ' + theme.fg('dim', `"${title}"`);
|
|
112
87
|
return new Text(content, 0, 0);
|
|
113
88
|
},
|
|
114
89
|
|
|
115
90
|
renderResult(result, _options, theme) {
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const lines: string[] = [];
|
|
123
|
-
|
|
124
|
-
// Title
|
|
125
|
-
lines.push(theme.fg('success', '✓ ') + theme.fg('accent', theme.bold(plan.title)));
|
|
126
|
-
lines.push('');
|
|
127
|
-
|
|
128
|
-
// Steps
|
|
129
|
-
for (let i = 0; i < plan.steps.length; i++) {
|
|
130
|
-
const step = plan.steps[i];
|
|
131
|
-
const num = theme.fg('muted', `${i + 1}.`);
|
|
132
|
-
lines.push(` ${num} ${step.description}`);
|
|
133
|
-
}
|
|
134
|
-
|
|
91
|
+
const plan = (result.details as { plan?: PlanData } | undefined)?.plan;
|
|
92
|
+
if (!plan) return new Text(theme.fg('success', '✓ Plan saved'), 0, 0);
|
|
93
|
+
const lines = [theme.fg('success', '✓ ') + theme.fg('accent', theme.bold(plan.title)), ''];
|
|
94
|
+
for (const task of plan.tasks) lines.push(` ${theme.fg('muted', task.id)} ${task.description}`);
|
|
135
95
|
return new Text(lines.join('\n'), 0, 0);
|
|
136
96
|
},
|
|
137
97
|
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* update_task tool — available during execution and after exiting plan mode with a submitted plan.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
|
|
6
|
+
import { StringEnum } from '@earendil-works/pi-ai';
|
|
7
|
+
import { Text } from '@earendil-works/pi-tui';
|
|
8
|
+
import { Type } from 'typebox';
|
|
9
|
+
import type { PlanData, TaskStatus } from '../types.js';
|
|
10
|
+
|
|
11
|
+
export interface UpdateTaskCallbacks {
|
|
12
|
+
getPlan: () => PlanData | undefined;
|
|
13
|
+
onTaskUpdated: (taskId: string, status: Exclude<TaskStatus, 'pending'>, notes?: string) => void | Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function registerUpdateTaskTool(pi: ExtensionAPI, callbacks: UpdateTaskCallbacks): void {
|
|
17
|
+
pi.registerTool({
|
|
18
|
+
name: 'update_task',
|
|
19
|
+
label: 'Update Task',
|
|
20
|
+
description: 'Mark a plan task as done, skipped, or blocked. If blocked, execution pauses for user intervention.',
|
|
21
|
+
promptSnippet: 'Mark a plan task as done, skipped, or blocked',
|
|
22
|
+
promptGuidelines: [
|
|
23
|
+
'Call update_task after completing each plan task before moving to the next.',
|
|
24
|
+
'Always include notes summarizing what was done, why skipped, or why blocked.',
|
|
25
|
+
'Use update_task with status "blocked" and explain the reason in notes if a task cannot be completed.',
|
|
26
|
+
],
|
|
27
|
+
parameters: Type.Object({
|
|
28
|
+
task_id: Type.String({ description: 'Task ID (for example, t-001)' }),
|
|
29
|
+
status: StringEnum(['done', 'skipped', 'blocked'] as const),
|
|
30
|
+
notes: Type.Optional(Type.String({ description: 'What was done, why skipped, or why blocked' })),
|
|
31
|
+
}),
|
|
32
|
+
|
|
33
|
+
async execute(_toolCallId, params) {
|
|
34
|
+
const plan = callbacks.getPlan();
|
|
35
|
+
if (!plan) throw new Error('No active plan. Cannot update task.');
|
|
36
|
+
|
|
37
|
+
const task = plan.tasks.find((candidate) => candidate.id === params.task_id);
|
|
38
|
+
if (!task) throw new Error(`Task not found: ${params.task_id}`);
|
|
39
|
+
if (task.status !== 'pending') {
|
|
40
|
+
throw new Error(`Task ${params.task_id} is already "${task.status}". Only pending tasks can be updated.`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
await callbacks.onTaskUpdated(params.task_id, params.status, params.notes);
|
|
44
|
+
|
|
45
|
+
const details = { task_id: params.task_id, status: params.status, notes: params.notes, description: task.description };
|
|
46
|
+
if (params.status === 'blocked') {
|
|
47
|
+
return {
|
|
48
|
+
content: [{ type: 'text' as const, text: `Task ${params.task_id} blocked. Execution paused — waiting for user input.` }],
|
|
49
|
+
details,
|
|
50
|
+
terminate: true,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const done = plan.tasks.filter((candidate) => candidate.status === 'done').length;
|
|
55
|
+
const skipped = plan.tasks.filter((candidate) => candidate.status === 'skipped').length;
|
|
56
|
+
const resolved = done + skipped;
|
|
57
|
+
const next = plan.tasks.find((candidate) => candidate.status === 'pending');
|
|
58
|
+
const statusEmoji = params.status === 'done' ? '✓' : '⊘';
|
|
59
|
+
let text = `${statusEmoji} Task ${params.task_id} ${params.status}. Progress: ${resolved}/${plan.tasks.length}`;
|
|
60
|
+
if (params.notes) text += ` — ${params.notes}`;
|
|
61
|
+
text += next ? `\n\nNext task ${next.id}: ${next.description}` : '\n\nAll tasks resolved!';
|
|
62
|
+
|
|
63
|
+
return { content: [{ type: 'text' as const, text }], details, terminate: !next };
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
renderCall(args, theme) {
|
|
67
|
+
const taskId = (args as { task_id?: string }).task_id ?? '?';
|
|
68
|
+
const status = (args as { status?: string }).status ?? '';
|
|
69
|
+
let content = theme.fg('toolTitle', theme.bold('update_task '));
|
|
70
|
+
content += theme.fg('muted', taskId);
|
|
71
|
+
if (status) content += ' ' + theme.fg(status === 'done' ? 'success' : status === 'skipped' ? 'warning' : 'error', status);
|
|
72
|
+
return new Text(content, 0, 0);
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
renderResult(result, _options, theme) {
|
|
76
|
+
const details = result.details as { task_id?: string; status?: string; description?: string } | undefined;
|
|
77
|
+
if (!details) return new Text(theme.fg('dim', 'Updated'), 0, 0);
|
|
78
|
+
const statusMap: Record<string, string> = { done: theme.fg('success', '✓'), skipped: theme.fg('warning', '⊘'), blocked: theme.fg('error', '✗') };
|
|
79
|
+
return new Text(`${statusMap[details.status ?? ''] ?? ''} Task ${details.task_id}: ${details.description ?? ''}`, 0, 0);
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
@@ -2,17 +2,32 @@
|
|
|
2
2
|
* Shared types for plan mode.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
export
|
|
5
|
+
export type TaskStatus = 'pending' | 'done' | 'skipped' | 'blocked';
|
|
6
|
+
|
|
7
|
+
export interface TaskRecord {
|
|
8
|
+
_type: 'task';
|
|
9
|
+
id: string;
|
|
6
10
|
description: string;
|
|
7
|
-
details
|
|
8
|
-
status:
|
|
11
|
+
details?: string;
|
|
12
|
+
status: TaskStatus;
|
|
13
|
+
depends_on?: string[];
|
|
9
14
|
notes?: string;
|
|
15
|
+
created_at: string;
|
|
16
|
+
updated_at: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface TaskMeta {
|
|
20
|
+
_type: 'meta';
|
|
21
|
+
title: string;
|
|
22
|
+
plan_name: string;
|
|
23
|
+
created_at: string;
|
|
10
24
|
}
|
|
11
25
|
|
|
12
26
|
export interface PlanData {
|
|
13
27
|
title: string;
|
|
28
|
+
planName: string;
|
|
14
29
|
handoff: string;
|
|
15
|
-
|
|
30
|
+
tasks: TaskRecord[];
|
|
16
31
|
}
|
|
17
32
|
|
|
18
33
|
export type ThinkingLevel = 'off' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
@@ -29,3 +44,41 @@ export interface PersistedState {
|
|
|
29
44
|
plan: PlanData | undefined;
|
|
30
45
|
executionStartIdx: number | undefined;
|
|
31
46
|
}
|
|
47
|
+
|
|
48
|
+
const TASK_STATUSES = new Set<TaskStatus>(['pending', 'done', 'skipped', 'blocked']);
|
|
49
|
+
|
|
50
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
51
|
+
return typeof value === 'object' && value !== null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function isStringArray(value: unknown): value is string[] {
|
|
55
|
+
return Array.isArray(value) && value.every((item) => typeof item === 'string');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function isTaskRecord(value: unknown): value is TaskRecord {
|
|
59
|
+
if (!isRecord(value)) return false;
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
value._type === 'task' &&
|
|
63
|
+
typeof value.id === 'string' &&
|
|
64
|
+
typeof value.description === 'string' &&
|
|
65
|
+
(value.details === undefined || typeof value.details === 'string') &&
|
|
66
|
+
typeof value.status === 'string' &&
|
|
67
|
+
TASK_STATUSES.has(value.status as TaskStatus) &&
|
|
68
|
+
(value.depends_on === undefined || isStringArray(value.depends_on)) &&
|
|
69
|
+
(value.notes === undefined || typeof value.notes === 'string') &&
|
|
70
|
+
typeof value.created_at === 'string' &&
|
|
71
|
+
typeof value.updated_at === 'string'
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function isTaskMeta(value: unknown): value is TaskMeta {
|
|
76
|
+
if (!isRecord(value)) return false;
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
value._type === 'meta' &&
|
|
80
|
+
typeof value.title === 'string' &&
|
|
81
|
+
typeof value.plan_name === 'string' &&
|
|
82
|
+
typeof value.created_at === 'string'
|
|
83
|
+
);
|
|
84
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Plan mode UI — status bar and
|
|
2
|
+
* Plan mode UI — status bar and task widget rendering.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import type { ExtensionContext } from '@earendil-works/pi-coding-agent';
|
|
@@ -9,27 +9,34 @@ export function updateUI(state: PlanModeState, ctx: ExtensionContext): void {
|
|
|
9
9
|
const { theme } = ctx.ui;
|
|
10
10
|
|
|
11
11
|
if (state.executing && state.plan) {
|
|
12
|
-
const done = state.plan.
|
|
13
|
-
const total = state.plan.
|
|
12
|
+
const done = state.plan.tasks.filter((task) => task.status === 'done').length;
|
|
13
|
+
const total = state.plan.tasks.length;
|
|
14
14
|
ctx.ui.setStatus('plan-mode', theme.fg('accent', `📋 exec ${done}/${total}`));
|
|
15
|
+
} else if (state.plan && !state.planEnabled) {
|
|
16
|
+
const done = state.plan.tasks.filter((task) => task.status === 'done').length;
|
|
17
|
+
const total = state.plan.tasks.length;
|
|
18
|
+
ctx.ui.setStatus('plan-mode', theme.fg('muted', `📋 ${done}/${total}`));
|
|
15
19
|
} else if (state.planEnabled) {
|
|
16
20
|
ctx.ui.setStatus('plan-mode', theme.fg('warning', '📝 plan'));
|
|
17
21
|
} else {
|
|
18
22
|
ctx.ui.setStatus('plan-mode', undefined);
|
|
19
23
|
}
|
|
20
24
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
const allResolved =
|
|
26
|
+
state.plan?.tasks.every((t) => t.status === 'done' || t.status === 'skipped' || t.status === 'blocked') ?? false;
|
|
27
|
+
|
|
28
|
+
if ((state.executing || state.plan) && state.plan && !allResolved) {
|
|
29
|
+
const lines = state.plan.tasks.map((task) => {
|
|
30
|
+
const label = `${task.id} ${task.description}`;
|
|
31
|
+
switch (task.status) {
|
|
25
32
|
case 'done':
|
|
26
|
-
return theme.fg('success', '✓ ') + theme.fg('muted', theme.strikethrough(
|
|
33
|
+
return theme.fg('success', '✓ ') + theme.fg('muted', theme.strikethrough(label));
|
|
27
34
|
case 'skipped':
|
|
28
|
-
return theme.fg('warning', '⊘ ') + theme.fg('muted', theme.strikethrough(
|
|
35
|
+
return theme.fg('warning', '⊘ ') + theme.fg('muted', theme.strikethrough(label));
|
|
29
36
|
case 'blocked':
|
|
30
|
-
return theme.fg('error', '✗ ') + theme.fg('error',
|
|
37
|
+
return theme.fg('error', '✗ ') + theme.fg('error', label);
|
|
31
38
|
default:
|
|
32
|
-
return theme.fg('muted', '☐ ') +
|
|
39
|
+
return theme.fg('muted', '☐ ') + label;
|
|
33
40
|
}
|
|
34
41
|
});
|
|
35
42
|
ctx.ui.setWidget('plan-todos', lines);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dreki-gg/pi-plan-mode",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.2",
|
|
4
4
|
"description": "Two-phase planning workflow for pi — plan with claude-opus-4-6:medium, execute with gpt-5.5:low, with .plans/ file-based handoff",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package"
|
|
@@ -40,7 +40,8 @@
|
|
|
40
40
|
]
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@dreki-gg/pi-command-sandbox": "^0.2.0"
|
|
43
|
+
"@dreki-gg/pi-command-sandbox": "^0.2.0",
|
|
44
|
+
"pug": "^3.0.3"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"@types/node": "24",
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reads and writes `.plans/plans.json` — the tracking manifest for plan lifecycle.
|
|
3
|
-
*
|
|
4
|
-
* Schema:
|
|
5
|
-
* ```json
|
|
6
|
-
* {
|
|
7
|
-
* "<plan-name>": {
|
|
8
|
-
* "status": "in-progress" | "done",
|
|
9
|
-
* "title": "Human-readable plan title",
|
|
10
|
-
* "created": "2026-05-08T12:00:00.000Z",
|
|
11
|
-
* "completed": "2026-05-08T13:00:00.000Z" | null
|
|
12
|
-
* }
|
|
13
|
-
* }
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
export interface PlanEntry {
|
|
18
|
-
status: 'in-progress' | 'done';
|
|
19
|
-
title: string;
|
|
20
|
-
created: string;
|
|
21
|
-
completed: string | null;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export type PlansManifest = Record<string, PlanEntry>;
|
|
25
|
-
|
|
26
|
-
import { readFile } from 'node:fs/promises';
|
|
27
|
-
|
|
28
|
-
const PLANS_JSON = '.plans/plans.json';
|
|
29
|
-
|
|
30
|
-
/** Read plans.json, returning current manifest (empty object if missing). */
|
|
31
|
-
export async function readPlansJson(): Promise<PlansManifest> {
|
|
32
|
-
try {
|
|
33
|
-
const text = await readFile(PLANS_JSON, 'utf-8');
|
|
34
|
-
if (text.trim()) {
|
|
35
|
-
return JSON.parse(text) as PlansManifest;
|
|
36
|
-
}
|
|
37
|
-
} catch {
|
|
38
|
-
// File doesn't exist or isn't valid JSON
|
|
39
|
-
}
|
|
40
|
-
return {};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** Serialize the manifest to a formatted JSON string. */
|
|
44
|
-
export function serializePlansJson(manifest: PlansManifest): string {
|
|
45
|
-
return `${JSON.stringify(manifest, null, 2)}\n`;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|