@narumitw/pi-plan-mode 0.34.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 +1 -1
- 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
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);
|