@narumitw/pi-plan-mode 0.31.0 → 0.35.0
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 +1 -1
- package/package.json +6 -1
- package/src/completion-tool.ts +23 -0
- package/src/plan-mode.ts +2 -0
- package/src/settings.ts +9 -85
package/README.md
CHANGED
|
@@ -160,7 +160,7 @@ Read-only does not mean private: Git inspection can expose repository history an
|
|
|
160
160
|
|
|
161
161
|
Plan mode inherits Pi's current thinking level by default. Set `thinkingLevel` to request a fixed level only while Plan mode is active. Supported values are `inherit`, `off`, `minimal`, `low`, `medium`, `high`, `xhigh`, and `max`. The extension snapshots the prior level and restores it on exit only if the level still matches the value it applied; a manual change made during Plan mode is preserved. The setting never changes Pi's default thinking level.
|
|
162
162
|
|
|
163
|
-
Invalid settings produce a warning and fall back to inherited thinking plus the available safe-built-in tool defaults. Compatibility: a valid legacy `plan-mode.json` is
|
|
163
|
+
Invalid settings produce a warning and fall back to inherited thinking plus the available safe-built-in tool defaults. Compatibility: a valid legacy `plan-mode.json` remains readable with a warning and is never modified automatically; rename it to `pi-plan-mode.json`. If both files exist, the new filename takes precedence.
|
|
164
164
|
|
|
165
165
|
## 🧠 Codex-like behavior
|
|
166
166
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@narumitw/pi-plan-mode",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.0",
|
|
4
4
|
"description": "Pi extension that adds a Codex-like read-only /plan collaboration mode.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,9 +27,14 @@
|
|
|
27
27
|
"format": "biome check --write .",
|
|
28
28
|
"typecheck": "tsc --noEmit"
|
|
29
29
|
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
32
|
+
"@earendil-works/pi-tui": "*"
|
|
33
|
+
},
|
|
30
34
|
"devDependencies": {
|
|
31
35
|
"@biomejs/biome": "2.5.5",
|
|
32
36
|
"@earendil-works/pi-coding-agent": "0.82.1",
|
|
37
|
+
"@earendil-works/pi-tui": "0.82.1",
|
|
33
38
|
"typescript": "7.0.2"
|
|
34
39
|
},
|
|
35
40
|
"repository": {
|
package/src/completion-tool.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { getMarkdownTheme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { Markdown } from "@earendil-works/pi-tui";
|
|
3
|
+
|
|
1
4
|
export const PLAN_MODE_COMPLETE_TOOL_NAME = "plan_mode_complete";
|
|
2
5
|
export const PLAN_MODE_COMPLETE_VERSION = 1;
|
|
3
6
|
export const PLAN_MODE_MAX_CHARS = 50_000;
|
|
@@ -63,6 +66,26 @@ export function planModeCompleted(plan: string) {
|
|
|
63
66
|
};
|
|
64
67
|
}
|
|
65
68
|
|
|
69
|
+
type PlanModeCompletionRenderResult = {
|
|
70
|
+
content: Array<{ type: string; text?: string }>;
|
|
71
|
+
details?: unknown;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export function planModeCompletionMarkdown(result: PlanModeCompletionRenderResult) {
|
|
75
|
+
const content = result.content
|
|
76
|
+
.filter((block) => block.type === "text" && typeof block.text === "string")
|
|
77
|
+
.map((block) => block.text)
|
|
78
|
+
.join("\n")
|
|
79
|
+
.trim();
|
|
80
|
+
if (content) return content;
|
|
81
|
+
const plan = planFromCompletionDetails(result.details);
|
|
82
|
+
return plan ? `**Proposed Plan**\n\n${plan}` : "";
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function renderPlanModeCompletion(result: PlanModeCompletionRenderResult) {
|
|
86
|
+
return new Markdown(planModeCompletionMarkdown(result), 0, 0, getMarkdownTheme());
|
|
87
|
+
}
|
|
88
|
+
|
|
66
89
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
67
90
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
68
91
|
}
|
package/src/plan-mode.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
PLAN_MODE_COMPLETE_PARAMS,
|
|
5
5
|
PLAN_MODE_COMPLETE_TOOL_NAME,
|
|
6
6
|
planModeCompleted,
|
|
7
|
+
renderPlanModeCompletion,
|
|
7
8
|
} from "./completion-tool.js";
|
|
8
9
|
import {
|
|
9
10
|
isEmptyAssistantMessage,
|
|
@@ -157,6 +158,7 @@ export default function planMode(pi: ExtensionAPI) {
|
|
|
157
158
|
"Call plan_mode_complete alone as the final action only after the implementation plan is decision-complete.",
|
|
158
159
|
],
|
|
159
160
|
parameters: PLAN_MODE_COMPLETE_PARAMS,
|
|
161
|
+
renderResult: renderPlanModeCompletion,
|
|
160
162
|
async execute(_toolCallId, params: unknown, _signal, _onUpdate, ctx) {
|
|
161
163
|
if (!state.enabled) {
|
|
162
164
|
throw new Error("plan_mode_complete is only available while Plan mode is active");
|
package/src/settings.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { dirname, join } from "node:path";
|
|
1
|
+
import { access, readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
4
3
|
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
5
4
|
import {
|
|
6
5
|
SAFE_GH_SUBCOMMAND_PATHS,
|
|
@@ -119,82 +118,15 @@ export async function readPlanModeSettings(
|
|
|
119
118
|
: canonical;
|
|
120
119
|
}
|
|
121
120
|
|
|
122
|
-
const
|
|
123
|
-
const legacy = legacySnapshot.result;
|
|
121
|
+
const legacy = await readSettingsFile(legacyPath);
|
|
124
122
|
const raced = await readSettingsFile(canonicalPath);
|
|
125
123
|
if (raced.kind !== "missing") return raced;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (created.kind !== "missing") {
|
|
133
|
-
return {
|
|
134
|
-
...created,
|
|
135
|
-
notice: `${LEGACY_PLAN_MODE_SETTINGS_FILE} ignored because ${PLAN_MODE_SETTINGS_FILE} was created concurrently.`,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
return {
|
|
139
|
-
...legacy,
|
|
140
|
-
notice: `Plan-mode settings migration failed: ${formatError(error)}. The legacy file was used for this session.`,
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
if (!(await fileContentsEqual(legacyPath, legacySnapshot.contents ?? ""))) {
|
|
144
|
-
const removed = await removeFileIfIdentityMatches(
|
|
145
|
-
canonicalPath,
|
|
146
|
-
installedIdentity,
|
|
147
|
-
legacySnapshot.contents ?? "",
|
|
148
|
-
);
|
|
149
|
-
return {
|
|
150
|
-
...legacy,
|
|
151
|
-
notice: removed
|
|
152
|
-
? `${LEGACY_PLAN_MODE_SETTINGS_FILE} changed during migration; the stale ${PLAN_MODE_SETTINGS_FILE} snapshot was removed.`
|
|
153
|
-
: `${LEGACY_PLAN_MODE_SETTINGS_FILE} changed during migration, but ${PLAN_MODE_SETTINGS_FILE} was replaced concurrently and takes precedence on the next load.`,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
try {
|
|
157
|
-
await rm(legacyPath);
|
|
158
|
-
return {
|
|
159
|
-
...legacy,
|
|
160
|
-
notice: `Plan-mode settings migrated from ${LEGACY_PLAN_MODE_SETTINGS_FILE} to ${PLAN_MODE_SETTINGS_FILE}.`,
|
|
161
|
-
};
|
|
162
|
-
} catch (error) {
|
|
163
|
-
return {
|
|
164
|
-
...legacy,
|
|
165
|
-
notice: `Plan-mode settings migrated to ${PLAN_MODE_SETTINGS_FILE}, but ${LEGACY_PLAN_MODE_SETTINGS_FILE} could not be removed: ${formatError(error)}.`,
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
type FileIdentity = { dev: number; ino: number };
|
|
171
|
-
|
|
172
|
-
async function installFileExclusively(filePath: string, contents: string): Promise<FileIdentity> {
|
|
173
|
-
const tempFile = join(dirname(filePath), `.${PLAN_MODE_SETTINGS_FILE}.${randomUUID()}.tmp`);
|
|
174
|
-
try {
|
|
175
|
-
await writeFile(tempFile, contents, { encoding: "utf8", flag: "wx" });
|
|
176
|
-
const identity = await lstat(tempFile);
|
|
177
|
-
await link(tempFile, filePath);
|
|
178
|
-
return { dev: identity.dev, ino: identity.ino };
|
|
179
|
-
} finally {
|
|
180
|
-
await rm(tempFile, { force: true }).catch(() => undefined);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
async function removeFileIfIdentityMatches(
|
|
185
|
-
filePath: string,
|
|
186
|
-
expected: FileIdentity,
|
|
187
|
-
expectedContents: string,
|
|
188
|
-
) {
|
|
189
|
-
try {
|
|
190
|
-
const current = await lstat(filePath);
|
|
191
|
-
if (current.dev !== expected.dev || current.ino !== expected.ino) return false;
|
|
192
|
-
if ((await readFile(filePath, "utf8")) !== expectedContents) return false;
|
|
193
|
-
await rm(filePath);
|
|
194
|
-
return true;
|
|
195
|
-
} catch {
|
|
196
|
-
return false;
|
|
197
|
-
}
|
|
124
|
+
return legacy.kind === "loaded"
|
|
125
|
+
? {
|
|
126
|
+
...legacy,
|
|
127
|
+
notice: `Using legacy ${LEGACY_PLAN_MODE_SETTINGS_FILE}; rename it to ${PLAN_MODE_SETTINGS_FILE}. The legacy file was not modified.`,
|
|
128
|
+
}
|
|
129
|
+
: legacy;
|
|
198
130
|
}
|
|
199
131
|
|
|
200
132
|
async function readSettingsFile(settingsPath: string): Promise<PlanModeSettingsLoadResult> {
|
|
@@ -231,14 +163,6 @@ export function configuredThinkingLevel(
|
|
|
231
163
|
return settings.thinkingLevel === "inherit" ? undefined : settings.thinkingLevel;
|
|
232
164
|
}
|
|
233
165
|
|
|
234
|
-
async function fileContentsEqual(path: string, expected: string) {
|
|
235
|
-
try {
|
|
236
|
-
return (await readFile(path, "utf8")) === expected;
|
|
237
|
-
} catch {
|
|
238
|
-
return false;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
166
|
async function exists(path: string) {
|
|
243
167
|
try {
|
|
244
168
|
await access(path);
|