@narumitw/pi-plan-mode 0.60.0 → 0.60.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 +16 -0
- package/README.md +8 -0
- package/dist/index.ts +126 -43
- package/dist/index.ts.map +3 -3
- package/package.json +2 -2
- package/src/plan-mode.ts +55 -20
- package/src/presentation.ts +61 -25
- package/src/state-persistence.ts +34 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @narumitw/pi-plan-mode
|
|
2
2
|
|
|
3
|
+
## 0.60.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 757800f: Skip unchanged branch-local state writes so an idle instance does not append a stale state branch during shutdown. Preserve meaningful state changes and completion recovery, and make repeated shutdown share one cleanup task.
|
|
8
|
+
|
|
9
|
+
## 0.60.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- cf7b63d: Put editor widget names and short current count/state summaries in their divider lines. Remove duplicate body titles while retaining safety text, detail rows, privacy modes, and standalone RPC/tool output. In fullscreen Pi, click anywhere in a widget to collapse it to one named line, then click that line to restore the latest content. Preserve independent, session-local disclosure through updates without taking editor focus, changing domain data, or stopping background work. Existing owner controls provide keyboard restoration; regular-mode mouse input remains terminal-owned.
|
|
14
|
+
|
|
15
|
+
The Kit minor release supplies the named widget state and publisher disclosure APIs. Changesets raises all adopting consumers' Kit dependency floors in the same Version PR. Publish and verify the exact Kit artifact before its consumers.
|
|
16
|
+
- Updated dependencies [cf7b63d]
|
|
17
|
+
- @narumitw/pi-tui-kit@0.70.0
|
|
18
|
+
|
|
3
19
|
## 0.60.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -177,6 +177,7 @@ Enabling questionnaires again does not call the model or reopen old questions.
|
|
|
177
177
|
Free discussion keeps the same read-only restrictions and allows plain-text questions without questionnaire dialogs.
|
|
178
178
|
Completed plans are still displayed, stored, and marked `plan ready`, but no automatic action menu opens; use `/plan` manually to implement, save, export, revise, exit, or enable questionnaires.
|
|
179
179
|
The editor widget shows the interaction mode and the available F2 or `/plan` entry point, including when a plan is ready.
|
|
180
|
+
In fullscreen TUI mode, click the **Plan mode** divider or any body row, including its blank right side, to collapse or expand it. Collapse changes only the display, not the workflow or read-only restrictions. The choice survives status updates and branch navigation, but resets on session replacement or reload. Open `/plan` without arguments to expand it from the keyboard.
|
|
180
181
|
The interaction mode restores with the active workflow on reload or resume; a new workflow starts with questionnaires enabled.
|
|
181
182
|
See [interaction switching](./docs/command-workflows.md#questionnaires-and-free-discussion) for RPC behavior and recovery.
|
|
182
183
|
|
|
@@ -416,6 +417,13 @@ Invalid settings remain untouched and make Settings read-only; session-start fai
|
|
|
416
417
|
|
|
417
418
|
Read the [settings reference](./docs/settings.md) for all accepted values, tool-policy resolution, reinjection choices, shortcut configuration, shell-override examples, and legacy-file migration.
|
|
418
419
|
|
|
420
|
+
## 🚧 Limitations
|
|
421
|
+
|
|
422
|
+
Plan mode skips unchanged session-state writes, including idle shutdown, while preserving branch-local workflow changes.
|
|
423
|
+
This does not coordinate concurrent writers: do not open the same persisted session in multiple Pi processes.
|
|
424
|
+
Meaningful state changes and writes from Pi or other extensions can still create a branch from an old resume position.
|
|
425
|
+
Plan mode does not repair existing branches; use `/tree` to return to the conversation branch if resume shows incomplete history.
|
|
426
|
+
|
|
419
427
|
## 🧠 Codex-like behavior
|
|
420
428
|
|
|
421
429
|
This extension maps Codex's `ModeKind::Plan` behavior onto Pi's extension API:
|
package/dist/index.ts
CHANGED
|
@@ -1197,35 +1197,55 @@ import { EditorStatusWidget } from "@narumitw/pi-tui-kit/editor-status-widget";
|
|
|
1197
1197
|
var STATUS_KEY = "plan-mode";
|
|
1198
1198
|
var PLAN_WIDGET_KEY = "plan-mode-plan";
|
|
1199
1199
|
var BIDI_CONTROLS = /[\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/gu;
|
|
1200
|
-
function updatePlanModeUi(ctx, state, toolSummary, interactionShortcut) {
|
|
1200
|
+
function updatePlanModeUi(ctx, state, toolSummary, interactionShortcut, widgetState) {
|
|
1201
1201
|
ctx.ui.setStatus(STATUS_KEY, formatStatus(state));
|
|
1202
1202
|
const discussion = state.interactionMode === "discussion";
|
|
1203
1203
|
const interactionHint = formatInteractionHint(state, ctx.mode === "tui" ? interactionShortcut : void 0);
|
|
1204
|
-
let
|
|
1204
|
+
let presentation;
|
|
1205
1205
|
if (state.enabled && state.latestPlan) {
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
"
|
|
1210
|
-
|
|
1211
|
-
|
|
1206
|
+
const actions = "Use /plan to implement, save, revise, or exit Plan mode.";
|
|
1207
|
+
presentation = {
|
|
1208
|
+
summary: discussion ? "Ready \xB7 Free discussion" : "Ready",
|
|
1209
|
+
body: ["File edits remain blocked.", actions, interactionHint],
|
|
1210
|
+
fallback: [
|
|
1211
|
+
"Proposed plan ready",
|
|
1212
|
+
...discussion ? ["Plan mode: free discussion"] : [],
|
|
1213
|
+
actions,
|
|
1214
|
+
interactionHint
|
|
1215
|
+
]
|
|
1216
|
+
};
|
|
1212
1217
|
} else if (state.enabled) {
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
discussion ? "
|
|
1217
|
-
interactionHint
|
|
1218
|
-
|
|
1218
|
+
const tools = toolSummary();
|
|
1219
|
+
const discussionHint = "Plain-text questions are allowed; questionnaires are paused.";
|
|
1220
|
+
presentation = {
|
|
1221
|
+
summary: discussion ? "Free discussion" : "Planning",
|
|
1222
|
+
body: ["File edits remain blocked.", tools, ...discussion ? [discussionHint] : [], interactionHint],
|
|
1223
|
+
fallback: [
|
|
1224
|
+
discussion ? "Plan mode: free discussion" : "Plan mode: planning",
|
|
1225
|
+
tools,
|
|
1226
|
+
discussion ? discussionHint : "Finish with plan_mode_complete when decision-ready.",
|
|
1227
|
+
interactionHint
|
|
1228
|
+
]
|
|
1229
|
+
};
|
|
1219
1230
|
} else if (state.savedPlan) {
|
|
1220
|
-
|
|
1231
|
+
const actions = "Use /plan to show, implement, or clear it.";
|
|
1232
|
+
presentation = { summary: "Saved", body: [actions], fallback: ["Plan saved for later", actions] };
|
|
1221
1233
|
} else if (state.activeImplementation) {
|
|
1222
|
-
|
|
1234
|
+
const actions = "Use /plan to show, replace, or clear it.";
|
|
1235
|
+
presentation = {
|
|
1236
|
+
summary: "Implementation active",
|
|
1237
|
+
body: [actions],
|
|
1238
|
+
fallback: ["Implementation plan active", actions]
|
|
1239
|
+
};
|
|
1223
1240
|
}
|
|
1224
|
-
publishPlanModeWidget(ctx,
|
|
1241
|
+
publishPlanModeWidget(ctx, presentation, widgetState);
|
|
1225
1242
|
}
|
|
1226
|
-
function createPlanModeWidget(lines, theme) {
|
|
1243
|
+
function createPlanModeWidget(lines, theme, state, summary) {
|
|
1227
1244
|
return new EditorStatusWidget({
|
|
1228
1245
|
theme,
|
|
1246
|
+
name: "Plan mode",
|
|
1247
|
+
summary,
|
|
1248
|
+
state,
|
|
1229
1249
|
renderBody: () => lines.map((line, index) => {
|
|
1230
1250
|
const text = sanitizePlanModeWidgetLine(line);
|
|
1231
1251
|
return index === 0 ? text : theme.fg("muted", text);
|
|
@@ -1287,17 +1307,20 @@ function planModeStatusText(state, toolSummary) {
|
|
|
1287
1307
|
if (state.activeImplementation) return "An implementation plan is active.";
|
|
1288
1308
|
return "Plan mode is off.";
|
|
1289
1309
|
}
|
|
1290
|
-
function publishPlanModeWidget(ctx,
|
|
1291
|
-
if (!
|
|
1310
|
+
function publishPlanModeWidget(ctx, presentation, widgetState) {
|
|
1311
|
+
if (!presentation) {
|
|
1292
1312
|
ctx.ui.setWidget(PLAN_WIDGET_KEY, void 0);
|
|
1293
1313
|
return;
|
|
1294
1314
|
}
|
|
1295
1315
|
if (ctx.mode !== "tui") {
|
|
1296
|
-
ctx.ui.setWidget(PLAN_WIDGET_KEY, [...
|
|
1316
|
+
ctx.ui.setWidget(PLAN_WIDGET_KEY, [...presentation.fallback]);
|
|
1297
1317
|
return;
|
|
1298
1318
|
}
|
|
1299
|
-
const snapshot = [...
|
|
1300
|
-
ctx.ui.setWidget(
|
|
1319
|
+
const snapshot = [...presentation.body];
|
|
1320
|
+
ctx.ui.setWidget(
|
|
1321
|
+
PLAN_WIDGET_KEY,
|
|
1322
|
+
(_tui, theme) => createPlanModeWidget(snapshot, theme, widgetState, presentation.summary)
|
|
1323
|
+
);
|
|
1301
1324
|
}
|
|
1302
1325
|
function formatInteractionHint(state, interactionShortcut) {
|
|
1303
1326
|
const action = state.interactionMode === "discussion" ? "enable questionnaires" : "switch to free discussion";
|
|
@@ -1476,6 +1499,35 @@ async function preflightSavedPlanImplementation(ctx, isCurrent) {
|
|
|
1476
1499
|
return true;
|
|
1477
1500
|
}
|
|
1478
1501
|
|
|
1502
|
+
// src/state-persistence.ts
|
|
1503
|
+
import { isDeepStrictEqual } from "node:util";
|
|
1504
|
+
function createPlanModeStatePersistence(stateEntryType, append) {
|
|
1505
|
+
let persisted = JSON.stringify({ enabled: false, awaitingAction: false });
|
|
1506
|
+
let appendFailed = false;
|
|
1507
|
+
return {
|
|
1508
|
+
restore(state) {
|
|
1509
|
+
persisted = JSON.stringify(state);
|
|
1510
|
+
appendFailed = false;
|
|
1511
|
+
},
|
|
1512
|
+
persist(state, branch) {
|
|
1513
|
+
const serialized = JSON.stringify(state);
|
|
1514
|
+
const payload = JSON.parse(serialized);
|
|
1515
|
+
if (!appendFailed && isDeepStrictEqual(payload, JSON.parse(persisted))) {
|
|
1516
|
+
const clearsRecoveredPlan = state.enabled && !state.latestPlan && restorePlanModeState(branch, stateEntryType).latestPlan !== void 0;
|
|
1517
|
+
if (!clearsRecoveredPlan) return;
|
|
1518
|
+
}
|
|
1519
|
+
try {
|
|
1520
|
+
append(payload);
|
|
1521
|
+
} catch (error) {
|
|
1522
|
+
appendFailed = true;
|
|
1523
|
+
throw error;
|
|
1524
|
+
}
|
|
1525
|
+
persisted = serialized;
|
|
1526
|
+
appendFailed = false;
|
|
1527
|
+
}
|
|
1528
|
+
};
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1479
1531
|
// src/workflow-mutex.ts
|
|
1480
1532
|
var WORKFLOW_MUTEX_CHANNEL = "workflow:mutex:v1";
|
|
1481
1533
|
var AGENT_WORKFLOW_GROUP = "agent-workflow";
|
|
@@ -1550,6 +1602,9 @@ function planMode(pi, dependencies = {}) {
|
|
|
1550
1602
|
let workflowOwner;
|
|
1551
1603
|
let currentSession;
|
|
1552
1604
|
let currentSessionContext;
|
|
1605
|
+
let shutdownStarted = false;
|
|
1606
|
+
let shutdownTask;
|
|
1607
|
+
let widgetState = { collapsed: false };
|
|
1553
1608
|
let interactiveUiPromise;
|
|
1554
1609
|
const loadInteractiveUi = () => {
|
|
1555
1610
|
if (dependencies.loadInteractiveUi) return dependencies.loadInteractiveUi();
|
|
@@ -1587,7 +1642,11 @@ function planMode(pi, dependencies = {}) {
|
|
|
1587
1642
|
let settingsReloadTimer;
|
|
1588
1643
|
const implementationRetention = createImplementationRetentionCoordinator();
|
|
1589
1644
|
const finalizationRequest = createFinalizationRequestCoordinator();
|
|
1590
|
-
const
|
|
1645
|
+
const statePersistence = createPlanModeStatePersistence(
|
|
1646
|
+
STATE_ENTRY_TYPE,
|
|
1647
|
+
(snapshot) => pi.appendEntry(STATE_ENTRY_TYPE, snapshot)
|
|
1648
|
+
);
|
|
1649
|
+
const persistState = () => statePersistence.persist(state, currentSessionContext?.sessionManager.getBranch() ?? []);
|
|
1591
1650
|
const interaction = createInteractionCoordinator(pi, {
|
|
1592
1651
|
getState: () => state,
|
|
1593
1652
|
setState: (next) => {
|
|
@@ -1774,6 +1833,10 @@ function planMode(pi, dependencies = {}) {
|
|
|
1774
1833
|
"The interactive /plan menu is unavailable in print and JSON modes. Use /plan start or /plan <prompt>."
|
|
1775
1834
|
);
|
|
1776
1835
|
}
|
|
1836
|
+
if (ctx.mode === "tui" && widgetState.collapsed) {
|
|
1837
|
+
widgetState.collapsed = false;
|
|
1838
|
+
updateUi(ctx);
|
|
1839
|
+
}
|
|
1777
1840
|
if (!state.enabled) {
|
|
1778
1841
|
if (state.activeImplementation && ctx.hasUI) {
|
|
1779
1842
|
await showActivePlanMenu(ctx);
|
|
@@ -1864,8 +1927,11 @@ function planMode(pi, dependencies = {}) {
|
|
|
1864
1927
|
cancelDeferredFreshImplementation();
|
|
1865
1928
|
const generation = ++menuGeneration;
|
|
1866
1929
|
finalizationRequest.reset();
|
|
1930
|
+
widgetState = { collapsed: false };
|
|
1867
1931
|
currentSession = ctx.sessionManager;
|
|
1868
1932
|
currentSessionContext = ctx;
|
|
1933
|
+
shutdownStarted = false;
|
|
1934
|
+
shutdownTask = void 0;
|
|
1869
1935
|
workflowOwner = void 0;
|
|
1870
1936
|
workflowMutex.bindSession(ctx.sessionManager);
|
|
1871
1937
|
refreshStateBeforeFirstAgentStart = event.reason === "new";
|
|
@@ -1881,6 +1947,7 @@ function planMode(pi, dependencies = {}) {
|
|
|
1881
1947
|
settings = { thinkingLevel: "inherit" };
|
|
1882
1948
|
const branch = ctx.sessionManager.getBranch();
|
|
1883
1949
|
const restoredState = restorePlanModeState(branch, STATE_ENTRY_TYPE);
|
|
1950
|
+
statePersistence.restore(restoredState);
|
|
1884
1951
|
restoreModeContractTracking(branch, restoredState);
|
|
1885
1952
|
state = { enabled: false, awaitingAction: false };
|
|
1886
1953
|
await applyPlanModeSettings(generation, ctx, true);
|
|
@@ -1929,6 +1996,7 @@ function planMode(pi, dependencies = {}) {
|
|
|
1929
1996
|
const branch = ctx.sessionManager.getBranch();
|
|
1930
1997
|
const restoredState = restorePlanModeState(branch, STATE_ENTRY_TYPE);
|
|
1931
1998
|
restoreModeContractTracking(branch, restoredState);
|
|
1999
|
+
statePersistence.restore(restoredState);
|
|
1932
2000
|
if (!installRestoredState(restoredState, ctx)) return;
|
|
1933
2001
|
implementationRetention.restore(state.activeImplementation);
|
|
1934
2002
|
startPlanModeSettingsWatch(menuGeneration);
|
|
@@ -1936,7 +2004,7 @@ function planMode(pi, dependencies = {}) {
|
|
|
1936
2004
|
await applyPendingImplementationRuntime(ctx);
|
|
1937
2005
|
});
|
|
1938
2006
|
pi.on("thinking_level_select", (event) => {
|
|
1939
|
-
if (!state.enabled || !state.appliedThinkingLevel) return;
|
|
2007
|
+
if (shutdownStarted || !state.enabled || !state.appliedThinkingLevel) return;
|
|
1940
2008
|
if (event.level !== state.appliedThinkingLevel) {
|
|
1941
2009
|
state = {
|
|
1942
2010
|
...state,
|
|
@@ -1947,11 +2015,16 @@ function planMode(pi, dependencies = {}) {
|
|
|
1947
2015
|
persistState();
|
|
1948
2016
|
}
|
|
1949
2017
|
});
|
|
1950
|
-
pi.on("session_shutdown",
|
|
2018
|
+
pi.on("session_shutdown", (_event, ctx) => {
|
|
1951
2019
|
if (currentSession !== void 0 && currentSession !== ctx.sessionManager) {
|
|
1952
2020
|
workflowMutex.unbindSession(ctx.sessionManager);
|
|
1953
2021
|
return;
|
|
1954
2022
|
}
|
|
2023
|
+
shutdownTask ??= shutdownPlanModeSession(ctx);
|
|
2024
|
+
return shutdownTask;
|
|
2025
|
+
});
|
|
2026
|
+
async function shutdownPlanModeSession(ctx) {
|
|
2027
|
+
shutdownStarted = true;
|
|
1955
2028
|
interaction.disposeSession();
|
|
1956
2029
|
invalidateReadyMenu();
|
|
1957
2030
|
cancelDeferredFreshImplementation();
|
|
@@ -1970,7 +2043,7 @@ function planMode(pi, dependencies = {}) {
|
|
|
1970
2043
|
);
|
|
1971
2044
|
}
|
|
1972
2045
|
finalizationRequest.reset();
|
|
1973
|
-
|
|
2046
|
+
const shutdownGeneration = ++menuGeneration;
|
|
1974
2047
|
menuController.abort(new DOMException("Plan-mode session shut down", "AbortError"));
|
|
1975
2048
|
readyPresentationIntent = void 0;
|
|
1976
2049
|
latestCommandContext = void 0;
|
|
@@ -1980,28 +2053,36 @@ function planMode(pi, dependencies = {}) {
|
|
|
1980
2053
|
workflowAllowedToolNames = void 0;
|
|
1981
2054
|
pendingWorkflowToolPolicy = void 0;
|
|
1982
2055
|
implementationRetention.reset();
|
|
2056
|
+
const shutdownIsCurrent = () => shutdownGeneration === menuGeneration && (currentSession === void 0 || currentSession === shutdownSession);
|
|
1983
2057
|
if (runtimeApplication) await runtimeApplication.completion;
|
|
1984
|
-
if (
|
|
1985
|
-
workflowMutex.unbindSession(shutdownSession);
|
|
2058
|
+
if (!shutdownIsCurrent()) {
|
|
2059
|
+
if (currentSession !== shutdownSession) workflowMutex.unbindSession(shutdownSession);
|
|
1986
2060
|
return;
|
|
1987
2061
|
}
|
|
1988
2062
|
await awaitPlanModeSettingsWrites(dependencies.settingsPath);
|
|
1989
|
-
if (
|
|
1990
|
-
workflowMutex.unbindSession(shutdownSession);
|
|
2063
|
+
if (!shutdownIsCurrent()) {
|
|
2064
|
+
if (currentSession !== shutdownSession) workflowMutex.unbindSession(shutdownSession);
|
|
1991
2065
|
return;
|
|
1992
2066
|
}
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2067
|
+
try {
|
|
2068
|
+
captureManualThinkingLevel();
|
|
2069
|
+
persistState();
|
|
2070
|
+
} finally {
|
|
2071
|
+
try {
|
|
2072
|
+
if (state.enabled) restoreThinkingLevel();
|
|
2073
|
+
} finally {
|
|
2074
|
+
stopPlanModeSettingsWatch();
|
|
2075
|
+
clearUi(ctx);
|
|
2076
|
+
releaseWorkflowOwner();
|
|
2077
|
+
workflowMutex.unbindSession(ctx.sessionManager);
|
|
2078
|
+
if (currentSession === ctx.sessionManager) {
|
|
2079
|
+
currentSession = void 0;
|
|
2080
|
+
currentSessionContext = void 0;
|
|
2081
|
+
widgetState = { collapsed: false };
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2003
2084
|
}
|
|
2004
|
-
}
|
|
2085
|
+
}
|
|
2005
2086
|
pi.on("tool_call", async (event, ctx) => {
|
|
2006
2087
|
const requiredHelper = event.toolName === PLAN_MODE_QUESTION_TOOL_NAME || event.toolName === PLAN_MODE_COMPLETE_TOOL_NAME;
|
|
2007
2088
|
if (!state.enabled) {
|
|
@@ -2892,6 +2973,7 @@ ${intent.plan}`,
|
|
|
2892
2973
|
implementationRetention.reset();
|
|
2893
2974
|
const branch = ctx.sessionManager.getBranch();
|
|
2894
2975
|
const restoredState = restorePlanModeState(branch, STATE_ENTRY_TYPE);
|
|
2976
|
+
statePersistence.restore(restoredState);
|
|
2895
2977
|
restoreModeContractTracking(branch, restoredState);
|
|
2896
2978
|
if (!installRestoredState(restoredState, ctx)) return;
|
|
2897
2979
|
implementationRetention.restore(state.activeImplementation);
|
|
@@ -3169,6 +3251,7 @@ ${intent.plan}`,
|
|
|
3169
3251
|
}
|
|
3170
3252
|
function bindWorkflowSessionIfNeeded(ctx) {
|
|
3171
3253
|
if (currentSession === ctx.sessionManager) return;
|
|
3254
|
+
widgetState = { collapsed: false };
|
|
3172
3255
|
currentSession = ctx.sessionManager;
|
|
3173
3256
|
workflowOwner = void 0;
|
|
3174
3257
|
workflowMutex.bindSession(ctx.sessionManager);
|
|
@@ -3206,7 +3289,7 @@ ${intent.plan}`,
|
|
|
3206
3289
|
return false;
|
|
3207
3290
|
}
|
|
3208
3291
|
function updateUi(ctx) {
|
|
3209
|
-
updatePlanModeUi(ctx, state, formatToolSummary, interaction.shortcutLabel(ctx));
|
|
3292
|
+
updatePlanModeUi(ctx, state, formatToolSummary, interaction.shortcutLabel(ctx), widgetState);
|
|
3210
3293
|
}
|
|
3211
3294
|
function clearUi(ctx) {
|
|
3212
3295
|
clearPlanModeUi(ctx);
|