@narumitw/pi-plan-mode 0.59.6 → 0.60.1
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/README.md +40 -13
- package/dist/chunks/{chunk-W7D6N2MI.ts → chunk-UJ6TV2YV.ts} +101 -86
- package/dist/chunks/chunk-UJ6TV2YV.ts.map +7 -0
- package/dist/chunks/{interactive-ui-RG7CBW6F.ts → interactive-ui-EMUWYNHT.ts} +15 -2
- package/dist/chunks/interactive-ui-EMUWYNHT.ts.map +7 -0
- package/dist/index.ts +657 -42
- package/dist/index.ts.map +4 -4
- package/docs/command-workflows.md +30 -0
- package/package.json +2 -2
- package/src/finalization-request.ts +3 -0
- package/src/interaction-contract.ts +73 -0
- package/src/interaction-coordinator.ts +379 -0
- package/src/plan-action-controller.ts +11 -2
- package/src/plan-action-menus.ts +18 -0
- package/src/plan-mode.ts +125 -24
- package/src/presentation.ts +89 -20
- package/src/question-renderer.ts +174 -0
- package/src/question-tool.ts +31 -4
- package/src/state.ts +40 -0
- package/dist/chunks/chunk-W7D6N2MI.ts.map +0 -7
- package/dist/chunks/interactive-ui-RG7CBW6F.ts.map +0 -7
package/src/plan-mode.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
InputEvent,
|
|
10
10
|
InputSource,
|
|
11
11
|
} from "@earendil-works/pi-coding-agent";
|
|
12
|
+
import type { EditorStatusWidgetState } from "@narumitw/pi-tui-kit/editor-status-widget";
|
|
12
13
|
import { completePlanArguments } from "./command.js";
|
|
13
14
|
import {
|
|
14
15
|
normalizePlanModeCompletion,
|
|
@@ -20,6 +21,7 @@ import {
|
|
|
20
21
|
import { isStaleExtensionContextError } from "./extension-runtime.js";
|
|
21
22
|
import {
|
|
22
23
|
createFinalizationRequestCoordinator,
|
|
24
|
+
DISCUSSION_FINALIZE_PLAN_PROMPT,
|
|
23
25
|
FINALIZE_PLAN_PROMPT,
|
|
24
26
|
type FinalizationRunOutcome,
|
|
25
27
|
RETRY_FINALIZE_PLAN_PROMPT,
|
|
@@ -35,6 +37,8 @@ import {
|
|
|
35
37
|
createImplementationRetentionCoordinator,
|
|
36
38
|
implementationRetentionPreview,
|
|
37
39
|
} from "./implementation-retention.js";
|
|
40
|
+
import { INTERACTION_CONTRACT_MESSAGE_TYPE } from "./interaction-contract.js";
|
|
41
|
+
import { createInteractionCoordinator } from "./interaction-coordinator.js";
|
|
38
42
|
import {
|
|
39
43
|
invalidPlanMessage,
|
|
40
44
|
latestAssistantStopReason,
|
|
@@ -58,8 +62,8 @@ import {
|
|
|
58
62
|
showStoredPlan,
|
|
59
63
|
updatePlanModeUi,
|
|
60
64
|
} from "./presentation.js";
|
|
65
|
+
import { renderPlanModeQuestionCall, renderPlanModeQuestionResult } from "./question-renderer.js";
|
|
61
66
|
import {
|
|
62
|
-
answerPlanModeQuestions,
|
|
63
67
|
normalizePlanModeQuestionParams,
|
|
64
68
|
PLAN_MODE_QUESTION_PARAMS,
|
|
65
69
|
PLAN_MODE_QUESTION_TOOL_NAME,
|
|
@@ -112,6 +116,7 @@ interface ReadyPresentationIntent {
|
|
|
112
116
|
nonce: number;
|
|
113
117
|
plan: string;
|
|
114
118
|
source: PlanCompletionSource;
|
|
119
|
+
showMenu: boolean;
|
|
115
120
|
}
|
|
116
121
|
interface DeferredFreshImplementation {
|
|
117
122
|
ctx: ExtensionContext;
|
|
@@ -163,6 +168,7 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
163
168
|
let workflowOwner: WorkflowMutexOwner | undefined;
|
|
164
169
|
let currentSession: object | undefined;
|
|
165
170
|
let currentSessionContext: ExtensionContext | undefined;
|
|
171
|
+
let widgetState: EditorStatusWidgetState = { collapsed: false };
|
|
166
172
|
let interactiveUiPromise: Promise<InteractiveUi> | undefined;
|
|
167
173
|
const loadInteractiveUi = () => {
|
|
168
174
|
if (dependencies.loadInteractiveUi) return dependencies.loadInteractiveUi();
|
|
@@ -184,6 +190,7 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
184
190
|
let publishedContractMode: PlanModeContract | undefined;
|
|
185
191
|
let modeContractsRelevant = false;
|
|
186
192
|
let readyPresentationIntent: ReadyPresentationIntent | undefined;
|
|
193
|
+
let readyMenuController = new AbortController();
|
|
187
194
|
let latestCommandContext: ExtensionCommandContext | undefined;
|
|
188
195
|
let stagedFreshImplementation: DeferredFreshImplementation | undefined;
|
|
189
196
|
const deferredFreshHandoff = createDeferredFreshHandoffCoordinator();
|
|
@@ -200,6 +207,34 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
200
207
|
const implementationRetention = createImplementationRetentionCoordinator();
|
|
201
208
|
const finalizationRequest = createFinalizationRequestCoordinator();
|
|
202
209
|
const persistState = () => pi.appendEntry<PlanModeState>(STATE_ENTRY_TYPE, state);
|
|
210
|
+
const interaction = createInteractionCoordinator(pi, {
|
|
211
|
+
getState: () => state,
|
|
212
|
+
setState: (next) => {
|
|
213
|
+
state = next;
|
|
214
|
+
},
|
|
215
|
+
persistState,
|
|
216
|
+
captureCurrent: (ctx) => {
|
|
217
|
+
const session = ctx.sessionManager;
|
|
218
|
+
const generation = workflowGeneration;
|
|
219
|
+
const sessionGeneration = menuGeneration;
|
|
220
|
+
const owner = workflowOwner;
|
|
221
|
+
return () =>
|
|
222
|
+
currentSession === session &&
|
|
223
|
+
generation === workflowGeneration &&
|
|
224
|
+
sessionGeneration === menuGeneration &&
|
|
225
|
+
!menuController.signal.aborted &&
|
|
226
|
+
workflowMutex.isOwner(owner);
|
|
227
|
+
},
|
|
228
|
+
clearReadyIntent: () => {
|
|
229
|
+
invalidateReadyMenu();
|
|
230
|
+
readyPresentationIntent =
|
|
231
|
+
readyPresentationIntent?.source === "legacy_proposed_plan"
|
|
232
|
+
? { ...readyPresentationIntent, showMenu: false }
|
|
233
|
+
: undefined;
|
|
234
|
+
},
|
|
235
|
+
resetFinalization: () => finalizationRequest.reset(),
|
|
236
|
+
updateUi,
|
|
237
|
+
});
|
|
203
238
|
const planExports = createPlanExportController({
|
|
204
239
|
getState: () => state,
|
|
205
240
|
getSettings: () => settings,
|
|
@@ -226,6 +261,9 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
226
261
|
settings: showSettings,
|
|
227
262
|
save: savePlanForLater,
|
|
228
263
|
stay: updateUi,
|
|
264
|
+
toggleInteraction: (ctx) => {
|
|
265
|
+
interaction.toggle(ctx);
|
|
266
|
+
},
|
|
229
267
|
exitReady: (ctx) => {
|
|
230
268
|
if (exitPlanMode(ctx)) {
|
|
231
269
|
ctx.ui.notify("Plan mode disabled. Proposed plan discarded.", "info");
|
|
@@ -242,7 +280,9 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
242
280
|
description:
|
|
243
281
|
"Ask one to three structured questions only when the latest effective Plan contract explicitly says /plan mode is active. Tool visibility alone does not activate Plan mode. Never call for ordinary planning requests, the writing-plans skill, roadmaps, checklists, or plan-file work.",
|
|
244
282
|
parameters: PLAN_MODE_QUESTION_PARAMS,
|
|
245
|
-
|
|
283
|
+
renderCall: renderPlanModeQuestionCall,
|
|
284
|
+
renderResult: renderPlanModeQuestionResult,
|
|
285
|
+
async execute(toolCallId, params: unknown, signal, _onUpdate, ctx) {
|
|
246
286
|
if (!state.enabled || !workflowMutex.isOwner(workflowOwner)) {
|
|
247
287
|
return planModeQuestionCancelled(
|
|
248
288
|
[],
|
|
@@ -257,6 +297,7 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
257
297
|
}
|
|
258
298
|
finalizationRequest.satisfy();
|
|
259
299
|
|
|
300
|
+
if (interaction.questionsPaused()) return interaction.answer(toolCallId, parsed.questions, ctx, signal);
|
|
260
301
|
if (!ctx.hasUI) {
|
|
261
302
|
return planModeQuestionCancelled(
|
|
262
303
|
parsed.questions,
|
|
@@ -265,16 +306,7 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
265
306
|
);
|
|
266
307
|
}
|
|
267
308
|
|
|
268
|
-
|
|
269
|
-
const questionWorkflowGeneration = workflowGeneration;
|
|
270
|
-
const questionOwner = workflowOwner;
|
|
271
|
-
return answerPlanModeQuestions(parsed.questions, ctx, {
|
|
272
|
-
isCurrent: () =>
|
|
273
|
-
sessionGeneration === menuGeneration &&
|
|
274
|
-
questionWorkflowGeneration === workflowGeneration &&
|
|
275
|
-
workflowMutex.isOwner(questionOwner),
|
|
276
|
-
isEnabled: () => state.enabled,
|
|
277
|
-
});
|
|
309
|
+
return interaction.answer(toolCallId, parsed.questions, ctx, signal);
|
|
278
310
|
},
|
|
279
311
|
});
|
|
280
312
|
|
|
@@ -379,6 +411,11 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
379
411
|
"The interactive /plan menu is unavailable in print and JSON modes. Use /plan start or /plan <prompt>.",
|
|
380
412
|
);
|
|
381
413
|
}
|
|
414
|
+
// Opening the existing manager restores the summary without changing Plan mode.
|
|
415
|
+
if (ctx.mode === "tui" && widgetState.collapsed) {
|
|
416
|
+
widgetState.collapsed = false;
|
|
417
|
+
updateUi(ctx);
|
|
418
|
+
}
|
|
382
419
|
if (!state.enabled) {
|
|
383
420
|
if (state.activeImplementation && ctx.hasUI) {
|
|
384
421
|
await showActivePlanMenu(ctx);
|
|
@@ -480,9 +517,12 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
480
517
|
};
|
|
481
518
|
|
|
482
519
|
pi.on("session_start", async (event, ctx) => {
|
|
520
|
+
interaction.disposeSession();
|
|
521
|
+
invalidateReadyMenu();
|
|
483
522
|
cancelDeferredFreshImplementation();
|
|
484
523
|
const generation = ++menuGeneration;
|
|
485
524
|
finalizationRequest.reset();
|
|
525
|
+
widgetState = { collapsed: false };
|
|
486
526
|
currentSession = ctx.sessionManager;
|
|
487
527
|
currentSessionContext = ctx;
|
|
488
528
|
workflowOwner = undefined;
|
|
@@ -505,6 +545,7 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
505
545
|
await applyPlanModeSettings(generation, ctx, true);
|
|
506
546
|
if (generation !== menuGeneration || menuController.signal.aborted) return;
|
|
507
547
|
initializePlanModeShortcut();
|
|
548
|
+
interaction.startSession(ctx, startupToggleShortcut);
|
|
508
549
|
startPlanModeSettingsWatch(generation);
|
|
509
550
|
if (!installRestoredState(restoredState, ctx)) return;
|
|
510
551
|
implementationRetention.restore(state.activeImplementation);
|
|
@@ -526,7 +567,10 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
526
567
|
return { cancel: true };
|
|
527
568
|
}
|
|
528
569
|
const target = ctx.sessionManager.getEntry(event.preparation.targetId);
|
|
529
|
-
if (
|
|
570
|
+
if (
|
|
571
|
+
target?.type !== "custom_message" ||
|
|
572
|
+
(target.customType !== MODE_CONTRACT_MESSAGE_TYPE && target.customType !== INTERACTION_CONTRACT_MESSAGE_TYPE)
|
|
573
|
+
) {
|
|
530
574
|
return;
|
|
531
575
|
}
|
|
532
576
|
if (ctx.hasUI) {
|
|
@@ -573,6 +617,12 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
573
617
|
});
|
|
574
618
|
|
|
575
619
|
pi.on("session_shutdown", async (_event, ctx) => {
|
|
620
|
+
if (currentSession !== undefined && currentSession !== ctx.sessionManager) {
|
|
621
|
+
workflowMutex.unbindSession(ctx.sessionManager);
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
interaction.disposeSession();
|
|
625
|
+
invalidateReadyMenu();
|
|
576
626
|
cancelDeferredFreshImplementation();
|
|
577
627
|
const shutdownSession = ctx.sessionManager;
|
|
578
628
|
const runtimeApplication =
|
|
@@ -623,6 +673,7 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
623
673
|
if (currentSession === ctx.sessionManager) {
|
|
624
674
|
currentSession = undefined;
|
|
625
675
|
currentSessionContext = undefined;
|
|
676
|
+
widgetState = { collapsed: false };
|
|
626
677
|
}
|
|
627
678
|
});
|
|
628
679
|
|
|
@@ -722,9 +773,21 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
722
773
|
}
|
|
723
774
|
});
|
|
724
775
|
|
|
776
|
+
pi.on("tool_execution_end", (event, ctx) => {
|
|
777
|
+
interaction.toolExecutionEnd(event.toolCallId, ctx);
|
|
778
|
+
});
|
|
779
|
+
|
|
780
|
+
pi.on("ui_prompt_start", (_event, ctx) => {
|
|
781
|
+
interaction.promptChanged(true, ctx);
|
|
782
|
+
});
|
|
783
|
+
pi.on("ui_prompt_end", (_event, ctx) => {
|
|
784
|
+
interaction.promptChanged(false, ctx);
|
|
785
|
+
});
|
|
786
|
+
|
|
725
787
|
pi.on("message_start", (event) => {
|
|
726
788
|
if (
|
|
727
789
|
state.enabled &&
|
|
790
|
+
interaction.mode() === "questions" &&
|
|
728
791
|
event.message.role === "user" &&
|
|
729
792
|
messageTextContent(event.message).trim() === FINALIZE_PLAN_PROMPT
|
|
730
793
|
) {
|
|
@@ -742,7 +805,7 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
742
805
|
state.enabled || modeContractsRelevant
|
|
743
806
|
? reconcileModeContract(result.messages, state.enabled ? "plan" : "normal")
|
|
744
807
|
: result.messages;
|
|
745
|
-
return { messages: messages as typeof event.messages };
|
|
808
|
+
return { messages: interaction.transformContext(messages, ctx) as typeof event.messages };
|
|
746
809
|
});
|
|
747
810
|
|
|
748
811
|
pi.on("input", async (event, ctx) => {
|
|
@@ -786,6 +849,7 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
786
849
|
refreshStateForFirstPrompt(ctx);
|
|
787
850
|
if (!state.enabled || !workflowMutex.isOwner(workflowOwner)) return;
|
|
788
851
|
if (state.latestPlan || state.awaitingAction) {
|
|
852
|
+
invalidateReadyMenu();
|
|
789
853
|
cancelDeferredFreshImplementation();
|
|
790
854
|
readyPresentationIntent = undefined;
|
|
791
855
|
state = {
|
|
@@ -805,7 +869,9 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
805
869
|
const text = latestAssistantText(event.messages);
|
|
806
870
|
const parsedPlan = parseProposedPlan(text);
|
|
807
871
|
if (parsedPlan.kind !== "valid") {
|
|
808
|
-
|
|
872
|
+
if (interaction.mode() === "questions") {
|
|
873
|
+
finalizationRequest.observeRunEnd(workflowGeneration, finalizationRunOutcome(event.messages));
|
|
874
|
+
}
|
|
809
875
|
if (parsedPlan.kind !== "absent") {
|
|
810
876
|
ctx.ui.notify(invalidPlanMessage(parsedPlan.kind), "warning");
|
|
811
877
|
}
|
|
@@ -820,7 +886,12 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
820
886
|
const settledImplementationId = implementationRetention.implementationSettled(state.activeImplementation);
|
|
821
887
|
if (settledImplementationId) clearActiveImplementation(settledImplementationId, ctx);
|
|
822
888
|
|
|
823
|
-
if (
|
|
889
|
+
if (
|
|
890
|
+
interaction.mode() === "questions" &&
|
|
891
|
+
finalizationRequest.hasPendingRequest() &&
|
|
892
|
+
state.enabled &&
|
|
893
|
+
workflowMutex.isOwner(workflowOwner)
|
|
894
|
+
) {
|
|
824
895
|
if (!ctx.isIdle() || ctx.hasPendingMessages()) return;
|
|
825
896
|
const action = finalizationRequest.settle(workflowGeneration);
|
|
826
897
|
if (action === "retry") {
|
|
@@ -852,8 +923,12 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
852
923
|
{ triggerTurn: false },
|
|
853
924
|
);
|
|
854
925
|
}
|
|
855
|
-
if (ctx.hasUI && completedPlanIsCurrent(intent)) {
|
|
856
|
-
|
|
926
|
+
if (intent.showMenu && ctx.hasUI && completedPlanIsCurrent(intent)) {
|
|
927
|
+
const controller = readyMenuController;
|
|
928
|
+
await planActions.showReady(latestCommandContext ?? ctx, {
|
|
929
|
+
signal: controller.signal,
|
|
930
|
+
isCurrent: () => completedPlanIsCurrent(intent) && interaction.mode() === "questions",
|
|
931
|
+
});
|
|
857
932
|
}
|
|
858
933
|
const request = stagedFreshImplementation;
|
|
859
934
|
stagedFreshImplementation = undefined;
|
|
@@ -892,6 +967,7 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
892
967
|
state = {
|
|
893
968
|
...state,
|
|
894
969
|
enabled: true,
|
|
970
|
+
interactionMode: "questions",
|
|
895
971
|
awaitingAction: false,
|
|
896
972
|
savedPlan: undefined,
|
|
897
973
|
activeImplementation: undefined,
|
|
@@ -902,6 +978,7 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
902
978
|
beginWorkflowToolPolicy();
|
|
903
979
|
applyPlanThinkingLevel();
|
|
904
980
|
persistState();
|
|
981
|
+
interaction.publish("questions");
|
|
905
982
|
updateUi(ctx);
|
|
906
983
|
return true;
|
|
907
984
|
} catch (error: unknown) {
|
|
@@ -935,6 +1012,7 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
935
1012
|
state = {
|
|
936
1013
|
...state,
|
|
937
1014
|
enabled: false,
|
|
1015
|
+
interactionMode: undefined,
|
|
938
1016
|
latestPlan: undefined,
|
|
939
1017
|
latestPlanSource: undefined,
|
|
940
1018
|
awaitingAction: false,
|
|
@@ -1010,21 +1088,32 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
1010
1088
|
) {
|
|
1011
1089
|
return;
|
|
1012
1090
|
}
|
|
1091
|
+
invalidateReadyMenu();
|
|
1013
1092
|
state = {
|
|
1014
1093
|
...state,
|
|
1015
1094
|
latestPlan: normalized.plan,
|
|
1016
1095
|
latestPlanSource: source,
|
|
1017
1096
|
awaitingAction: true,
|
|
1018
1097
|
};
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1098
|
+
const showMenu = interaction.mode() === "questions";
|
|
1099
|
+
readyPresentationIntent =
|
|
1100
|
+
showMenu || source === "legacy_proposed_plan"
|
|
1101
|
+
? {
|
|
1102
|
+
nonce: ++nextReadyPresentationNonce,
|
|
1103
|
+
plan: normalized.plan,
|
|
1104
|
+
source,
|
|
1105
|
+
showMenu,
|
|
1106
|
+
}
|
|
1107
|
+
: undefined;
|
|
1024
1108
|
persistState();
|
|
1025
1109
|
updateUi(ctx);
|
|
1026
1110
|
}
|
|
1027
1111
|
|
|
1112
|
+
function invalidateReadyMenu() {
|
|
1113
|
+
readyMenuController.abort(new DOMException("Plan presentation superseded", "AbortError"));
|
|
1114
|
+
readyMenuController = new AbortController();
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1028
1117
|
function completedPlanIsCurrent(intent: ReadyPresentationIntent) {
|
|
1029
1118
|
return (
|
|
1030
1119
|
state.enabled &&
|
|
@@ -1066,6 +1155,11 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
1066
1155
|
ctx.ui.notify("Plan mode is not active. Use /plan first.", "warning");
|
|
1067
1156
|
return;
|
|
1068
1157
|
}
|
|
1158
|
+
if (interaction.mode() === "discussion") {
|
|
1159
|
+
finalizationRequest.reset();
|
|
1160
|
+
sendPlanModeUserMessage(DISCUSSION_FINALIZE_PLAN_PROMPT, ctx);
|
|
1161
|
+
return;
|
|
1162
|
+
}
|
|
1069
1163
|
finalizationRequest.request(workflowGeneration);
|
|
1070
1164
|
if (!sendPlanModeUserMessage(FINALIZE_PLAN_PROMPT, ctx)) finalizationRequest.reset();
|
|
1071
1165
|
}
|
|
@@ -1088,6 +1182,7 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
1088
1182
|
state = {
|
|
1089
1183
|
...state,
|
|
1090
1184
|
enabled: false,
|
|
1185
|
+
interactionMode: undefined,
|
|
1091
1186
|
latestPlan: undefined,
|
|
1092
1187
|
latestPlanSource: undefined,
|
|
1093
1188
|
awaitingAction: false,
|
|
@@ -1235,6 +1330,7 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
1235
1330
|
state = {
|
|
1236
1331
|
...state,
|
|
1237
1332
|
enabled: false,
|
|
1333
|
+
interactionMode: undefined,
|
|
1238
1334
|
latestPlan: undefined,
|
|
1239
1335
|
latestPlanSource: undefined,
|
|
1240
1336
|
awaitingAction: false,
|
|
@@ -1271,6 +1367,7 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
1271
1367
|
if (wasEnabled) {
|
|
1272
1368
|
restoreWorkflowToolPolicy(state.workflowToolPolicy);
|
|
1273
1369
|
publishModeContract("plan", ctx);
|
|
1370
|
+
interaction.publish(interaction.mode());
|
|
1274
1371
|
applyPlanThinkingLevel();
|
|
1275
1372
|
}
|
|
1276
1373
|
persistState();
|
|
@@ -1444,6 +1541,8 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
1444
1541
|
}
|
|
1445
1542
|
|
|
1446
1543
|
function advanceWorkflowGeneration() {
|
|
1544
|
+
interaction.reset();
|
|
1545
|
+
invalidateReadyMenu();
|
|
1447
1546
|
cancelDeferredFreshImplementation();
|
|
1448
1547
|
workflowGeneration += 1;
|
|
1449
1548
|
pendingWorkflowToolPolicy = undefined;
|
|
@@ -1950,6 +2049,7 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
1950
2049
|
previousOwner?: WorkflowMutexOwner,
|
|
1951
2050
|
) {
|
|
1952
2051
|
const activatedOwner = workflowOwner;
|
|
2052
|
+
interaction.reset();
|
|
1953
2053
|
readyPresentationIntent = undefined;
|
|
1954
2054
|
try {
|
|
1955
2055
|
if (state.enabled) {
|
|
@@ -1974,6 +2074,7 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
1974
2074
|
|
|
1975
2075
|
function bindWorkflowSessionIfNeeded(ctx: ExtensionContext) {
|
|
1976
2076
|
if (currentSession === ctx.sessionManager) return;
|
|
2077
|
+
widgetState = { collapsed: false };
|
|
1977
2078
|
currentSession = ctx.sessionManager;
|
|
1978
2079
|
workflowOwner = undefined;
|
|
1979
2080
|
workflowMutex.bindSession(ctx.sessionManager);
|
|
@@ -2017,7 +2118,7 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
2017
2118
|
}
|
|
2018
2119
|
|
|
2019
2120
|
function updateUi(ctx: ExtensionContext) {
|
|
2020
|
-
updatePlanModeUi(ctx, state, formatToolSummary);
|
|
2121
|
+
updatePlanModeUi(ctx, state, formatToolSummary, interaction.shortcutLabel(ctx), widgetState);
|
|
2021
2122
|
}
|
|
2022
2123
|
|
|
2023
2124
|
function clearUi(ctx: ExtensionContext) {
|
package/src/presentation.ts
CHANGED
|
@@ -1,35 +1,91 @@
|
|
|
1
1
|
import type { ExtensionAPI, ExtensionContext, Theme } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { stripTerminalSequences } from "@earendil-works/pi-tui";
|
|
3
|
-
import { EditorStatusWidget } from "@narumitw/pi-tui-kit/editor-status-widget";
|
|
3
|
+
import { EditorStatusWidget, type EditorStatusWidgetState } from "@narumitw/pi-tui-kit/editor-status-widget";
|
|
4
4
|
import type { PlanModeState } from "./state.js";
|
|
5
5
|
|
|
6
6
|
const STATUS_KEY = "plan-mode";
|
|
7
7
|
const PLAN_WIDGET_KEY = "plan-mode-plan";
|
|
8
8
|
const BIDI_CONTROLS = /[\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/gu;
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
interface PlanModeWidgetPresentation {
|
|
11
|
+
summary: string;
|
|
12
|
+
body: readonly string[];
|
|
13
|
+
fallback: readonly string[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function updatePlanModeUi(
|
|
17
|
+
ctx: ExtensionContext,
|
|
18
|
+
state: PlanModeState,
|
|
19
|
+
toolSummary: () => string,
|
|
20
|
+
interactionShortcut?: string,
|
|
21
|
+
widgetState?: EditorStatusWidgetState,
|
|
22
|
+
) {
|
|
11
23
|
ctx.ui.setStatus(STATUS_KEY, formatStatus(state));
|
|
12
|
-
|
|
24
|
+
const discussion = state.interactionMode === "discussion";
|
|
25
|
+
const interactionHint = formatInteractionHint(state, ctx.mode === "tui" ? interactionShortcut : undefined);
|
|
26
|
+
let presentation: PlanModeWidgetPresentation | undefined;
|
|
13
27
|
if (state.enabled && state.latestPlan) {
|
|
14
|
-
|
|
28
|
+
const actions = "Use /plan to implement, save, revise, or exit Plan mode.";
|
|
29
|
+
presentation = {
|
|
30
|
+
summary: discussion ? "Ready · Free discussion" : "Ready",
|
|
31
|
+
body: ["File edits remain blocked.", actions, interactionHint],
|
|
32
|
+
fallback: [
|
|
33
|
+
"Proposed plan ready",
|
|
34
|
+
...(discussion ? ["Plan mode: free discussion"] : []),
|
|
35
|
+
actions,
|
|
36
|
+
interactionHint,
|
|
37
|
+
],
|
|
38
|
+
};
|
|
15
39
|
} else if (state.enabled) {
|
|
16
|
-
|
|
40
|
+
const tools = toolSummary();
|
|
41
|
+
const discussionHint = "Plain-text questions are allowed; questionnaires are paused.";
|
|
42
|
+
presentation = {
|
|
43
|
+
summary: discussion ? "Free discussion" : "Planning",
|
|
44
|
+
body: ["File edits remain blocked.", tools, ...(discussion ? [discussionHint] : []), interactionHint],
|
|
45
|
+
fallback: [
|
|
46
|
+
discussion ? "Plan mode: free discussion" : "Plan mode: planning",
|
|
47
|
+
tools,
|
|
48
|
+
discussion ? discussionHint : "Finish with plan_mode_complete when decision-ready.",
|
|
49
|
+
interactionHint,
|
|
50
|
+
],
|
|
51
|
+
};
|
|
17
52
|
} else if (state.savedPlan) {
|
|
18
|
-
|
|
53
|
+
const actions = "Use /plan to show, implement, or clear it.";
|
|
54
|
+
presentation = { summary: "Saved", body: [actions], fallback: ["Plan saved for later", actions] };
|
|
19
55
|
} else if (state.activeImplementation) {
|
|
20
|
-
|
|
56
|
+
const actions = "Use /plan to show, replace, or clear it.";
|
|
57
|
+
presentation = {
|
|
58
|
+
summary: "Implementation active",
|
|
59
|
+
body: [actions],
|
|
60
|
+
fallback: ["Implementation plan active", actions],
|
|
61
|
+
};
|
|
21
62
|
}
|
|
22
63
|
|
|
23
|
-
publishPlanModeWidget(ctx,
|
|
64
|
+
publishPlanModeWidget(ctx, presentation, widgetState);
|
|
24
65
|
}
|
|
25
66
|
|
|
26
67
|
export function renderPlanModeWidget(lines: readonly string[], theme: Theme, width: number): string[] {
|
|
27
68
|
return createPlanModeWidget(lines, theme).render(width);
|
|
28
69
|
}
|
|
29
70
|
|
|
30
|
-
function createPlanModeWidget(
|
|
71
|
+
function createPlanModeWidget(
|
|
72
|
+
lines: readonly string[],
|
|
73
|
+
theme: Theme,
|
|
74
|
+
state?: EditorStatusWidgetState,
|
|
75
|
+
summary?: string,
|
|
76
|
+
): EditorStatusWidget {
|
|
31
77
|
// Kit normalizes fractional and invalid widths before clipping sanitized body rows.
|
|
32
|
-
return new EditorStatusWidget({
|
|
78
|
+
return new EditorStatusWidget({
|
|
79
|
+
theme,
|
|
80
|
+
name: "Plan mode",
|
|
81
|
+
summary,
|
|
82
|
+
state,
|
|
83
|
+
renderBody: () =>
|
|
84
|
+
lines.map((line, index) => {
|
|
85
|
+
const text = sanitizePlanModeWidgetLine(line);
|
|
86
|
+
return index === 0 ? text : theme.fg("muted", text);
|
|
87
|
+
}),
|
|
88
|
+
});
|
|
33
89
|
}
|
|
34
90
|
|
|
35
91
|
export function sanitizePlanModeWidgetLine(value: string): string {
|
|
@@ -81,34 +137,47 @@ export function showPlanModePlan(pi: ExtensionAPI, ctx: ExtensionContext, title:
|
|
|
81
137
|
|
|
82
138
|
export function planModeStatusText(state: PlanModeState, toolSummary: () => string) {
|
|
83
139
|
if (state.enabled) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
140
|
+
const ready = state.latestPlan ? " A proposed plan is ready." : "";
|
|
141
|
+
const interaction =
|
|
142
|
+
state.interactionMode === "discussion"
|
|
143
|
+
? "Free discussion is active; questionnaires are paused and plain-text questions are allowed."
|
|
144
|
+
: "Explore, ask, and finish with plan_mode_complete when decision-ready.";
|
|
145
|
+
return `Plan mode is active.${ready} ${interaction} File edits remain blocked. ${toolSummary()}`;
|
|
88
146
|
}
|
|
89
147
|
if (state.savedPlan) return "A plan is saved for later.";
|
|
90
148
|
if (state.activeImplementation) return "An implementation plan is active.";
|
|
91
149
|
return "Plan mode is off.";
|
|
92
150
|
}
|
|
93
151
|
|
|
94
|
-
function publishPlanModeWidget(
|
|
95
|
-
|
|
152
|
+
function publishPlanModeWidget(
|
|
153
|
+
ctx: ExtensionContext,
|
|
154
|
+
presentation: PlanModeWidgetPresentation | undefined,
|
|
155
|
+
widgetState?: EditorStatusWidgetState,
|
|
156
|
+
) {
|
|
157
|
+
if (!presentation) {
|
|
96
158
|
ctx.ui.setWidget(PLAN_WIDGET_KEY, undefined);
|
|
97
159
|
return;
|
|
98
160
|
}
|
|
99
161
|
if (ctx.mode !== "tui") {
|
|
100
|
-
ctx.ui.setWidget(PLAN_WIDGET_KEY, [...
|
|
162
|
+
ctx.ui.setWidget(PLAN_WIDGET_KEY, [...presentation.fallback]);
|
|
101
163
|
return;
|
|
102
164
|
}
|
|
103
165
|
|
|
104
|
-
const snapshot = [...
|
|
105
|
-
ctx.ui.setWidget(PLAN_WIDGET_KEY, (_tui, theme) =>
|
|
166
|
+
const snapshot = [...presentation.body];
|
|
167
|
+
ctx.ui.setWidget(PLAN_WIDGET_KEY, (_tui, theme) =>
|
|
168
|
+
createPlanModeWidget(snapshot, theme, widgetState, presentation.summary),
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function formatInteractionHint(state: PlanModeState, interactionShortcut?: string) {
|
|
173
|
+
const action = state.interactionMode === "discussion" ? "enable questionnaires" : "switch to free discussion";
|
|
174
|
+
return interactionShortcut ? `${interactionShortcut}: ${action}.` : `Use /plan to ${action}.`;
|
|
106
175
|
}
|
|
107
176
|
|
|
108
177
|
function formatStatus(state: PlanModeState) {
|
|
109
178
|
if (state.enabled) {
|
|
110
179
|
if (state.awaitingAction || state.latestPlan) return "plan ready";
|
|
111
|
-
return "plan active";
|
|
180
|
+
return state.interactionMode === "discussion" ? "plan discussion" : "plan active";
|
|
112
181
|
}
|
|
113
182
|
if (state.savedPlan) return "plan saved";
|
|
114
183
|
if (state.activeImplementation) return "plan implementing";
|