@narumitw/pi-plan-mode 0.57.1 → 0.58.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.
Files changed (41) hide show
  1. package/README.md +68 -4
  2. package/dist/chunks/{chunk-57OBPS7P.js → chunk-HF7ZEYIC.js} +169 -164
  3. package/dist/chunks/chunk-HF7ZEYIC.js.map +7 -0
  4. package/dist/chunks/{interactive-ui-N2ZKBVNE.js → interactive-ui-UK7IGPOE.js} +312 -32
  5. package/dist/chunks/interactive-ui-UK7IGPOE.js.map +7 -0
  6. package/dist/index.ts +670 -212
  7. package/dist/index.ts.map +4 -4
  8. package/docs/settings.md +26 -2
  9. package/package.json +50 -51
  10. package/src/active-implementation-menu.ts +57 -60
  11. package/src/command.ts +22 -21
  12. package/src/completion-tool.ts +53 -56
  13. package/src/extension-runtime.ts +5 -5
  14. package/src/finalization-request.ts +40 -44
  15. package/src/fresh-handoff-coordinator.ts +52 -0
  16. package/src/fresh-implementation.ts +312 -205
  17. package/src/implementation-models.ts +43 -0
  18. package/src/implementation-retention.ts +109 -123
  19. package/src/message-transform.ts +218 -252
  20. package/src/mode-contract.ts +46 -49
  21. package/src/plan-action-controller.ts +139 -89
  22. package/src/plan-action-menus.ts +414 -177
  23. package/src/plan-export-controller.ts +23 -28
  24. package/src/plan-export-screen.ts +13 -13
  25. package/src/plan-export.ts +85 -102
  26. package/src/plan-launch-menu.ts +119 -119
  27. package/src/plan-mode.ts +2027 -1675
  28. package/src/presentation.ts +84 -108
  29. package/src/prompt.ts +1 -1
  30. package/src/question-tool.ts +239 -267
  31. package/src/required-tools.ts +15 -19
  32. package/src/saved-plan-menu.ts +82 -84
  33. package/src/saved-plan-preflight.ts +29 -33
  34. package/src/settings-menu.ts +489 -377
  35. package/src/settings.ts +403 -382
  36. package/src/state.ts +177 -146
  37. package/src/tool-policy.ts +634 -699
  38. package/src/tool-selection.ts +39 -44
  39. package/src/workflow-mutex.ts +66 -66
  40. package/dist/chunks/chunk-57OBPS7P.js.map +0 -7
  41. package/dist/chunks/interactive-ui-N2ZKBVNE.js.map +0 -7
@@ -0,0 +1,43 @@
1
+ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
+
3
+ export const MAX_PENDING_IMPLEMENTATION_MODEL_IDENTIFIER_LENGTH = 512;
4
+
5
+ export interface ImplementationModelOverride {
6
+ provider: string;
7
+ modelId: string;
8
+ }
9
+
10
+ export interface AvailableImplementationModel {
11
+ provider: string;
12
+ id: string;
13
+ name?: string;
14
+ }
15
+
16
+ export function isPendingImplementationModelIdentifier(value: unknown): value is string {
17
+ return (
18
+ typeof value === "string" &&
19
+ value.trim().length > 0 &&
20
+ value.length <= MAX_PENDING_IMPLEMENTATION_MODEL_IDENTIFIER_LENGTH
21
+ );
22
+ }
23
+
24
+ export function snapshotAvailableImplementationModels(ctx: ExtensionContext): AvailableImplementationModel[] {
25
+ const getAvailable = ctx.modelRegistry.getAvailable;
26
+ const availableModels = typeof getAvailable === "function" ? getAvailable.call(ctx.modelRegistry) : [];
27
+ const scopedModels = ctx.scopedModels ?? [];
28
+ if (scopedModels.length === 0) return availableModels;
29
+ return scopedModels.flatMap((entry) => {
30
+ const availableModel = availableModels.find(
31
+ (model) => model.provider === entry.model.provider && model.id === entry.model.id,
32
+ );
33
+ return availableModel ? [availableModel] : [];
34
+ });
35
+ }
36
+
37
+ export function findAvailableImplementationModel(
38
+ models: readonly AvailableImplementationModel[],
39
+ configured: ImplementationModelOverride | undefined,
40
+ ): AvailableImplementationModel | undefined {
41
+ if (!configured) return undefined;
42
+ return models.find((model) => model.provider === configured.provider && model.id === configured.modelId);
43
+ }
@@ -1,146 +1,132 @@
1
1
  import {
2
- findHistoryImplementationArtifact,
3
- injectActiveImplementationContext,
4
- isEmptyAssistantMessage,
5
- messageContainsExactPlanModeImplementationHandoff,
6
- messageContainsInactivePlanModeArtifact,
7
- messageContainsLegacyPlanModeContextArtifact,
8
- messageContainsPlanModeImplementationContextArtifact,
9
- messageContainsPlanModeImplementationHandoff,
10
- stripPlanModeCompletionCallsFromMessage,
11
- stripProposedPlanBlocksFromMessage,
2
+ findHistoryImplementationArtifact,
3
+ injectActiveImplementationContext,
4
+ isEmptyAssistantMessage,
5
+ messageContainsExactPlanModeImplementationHandoff,
6
+ messageContainsInactivePlanModeArtifact,
7
+ messageContainsLegacyPlanModeContextArtifact,
8
+ messageContainsPlanModeImplementationContextArtifact,
9
+ messageContainsPlanModeImplementationHandoff,
10
+ stripPlanModeCompletionCallsFromMessage,
11
+ stripProposedPlanBlocksFromMessage,
12
12
  } from "./message-transform.js";
13
13
  import type { ImplementationPlanRetention } from "./settings.js";
14
14
  import type { ActiveImplementationPlan, PlanModeState } from "./state.js";
15
15
 
16
16
  export function retentionLabel(retention: ImplementationPlanRetention) {
17
- return {
18
- "clear-on-start": "Off — conversation history only",
19
- "clear-after-first-run": "Through first implementation run",
20
- keep: "Until manually cleared",
21
- }[retention];
17
+ return {
18
+ "clear-on-start": "Off — conversation history only",
19
+ "clear-after-first-run": "Through first implementation run",
20
+ keep: "Until manually cleared",
21
+ }[retention];
22
22
  }
23
23
 
24
24
  export function implementationRetentionPreview(retention: ImplementationPlanRetention) {
25
- return {
26
- "clear-on-start": "Plan reinjection: Off; use conversation history only.",
27
- "clear-after-first-run": "Plan reinjection: Through the first implementation run.",
28
- keep: "Plan reinjection: Until /plan exit.",
29
- }[retention];
25
+ return {
26
+ "clear-on-start": "Plan reinjection: Off; use conversation history only.",
27
+ "clear-after-first-run": "Plan reinjection: Through the first implementation run.",
28
+ keep: "Plan reinjection: Until /plan exit.",
29
+ }[retention];
30
30
  }
31
31
 
32
32
  export interface ImplementationContextResult {
33
- messages: unknown[];
34
- clearActiveImplementationId?: string;
33
+ messages: unknown[];
34
+ clearActiveImplementationId?: string;
35
35
  }
36
36
 
37
37
  export interface ImplementationRetentionCoordinator {
38
- restore(activeImplementation: ActiveImplementationPlan | undefined): void;
39
- transformContext(messages: unknown[], state: PlanModeState): ImplementationContextResult;
40
- implementationSettled(
41
- activeImplementation: ActiveImplementationPlan | undefined,
42
- ): string | undefined;
43
- reset(): void;
38
+ restore(activeImplementation: ActiveImplementationPlan | undefined): void;
39
+ transformContext(messages: unknown[], state: PlanModeState): ImplementationContextResult;
40
+ implementationSettled(activeImplementation: ActiveImplementationPlan | undefined): string | undefined;
41
+ reset(): void;
44
42
  }
45
43
 
46
44
  export function createImplementationRetentionCoordinator(): ImplementationRetentionCoordinator {
47
- let implementationWithDeliveredContext: string | undefined;
48
- let restoredImplementationAwaitingContext: string | undefined;
45
+ let implementationWithDeliveredContext: string | undefined;
46
+ let restoredImplementationAwaitingContext: string | undefined;
49
47
 
50
- return {
51
- restore(activeImplementation) {
52
- restoredImplementationAwaitingContext =
53
- activeImplementation && activeImplementation.retention !== "keep"
54
- ? activeImplementation.id
55
- : undefined;
56
- },
57
- transformContext(messages, state) {
58
- const messagesWithoutLegacyContext = messages.filter(
59
- (message) => !messageContainsLegacyPlanModeContextArtifact(message),
60
- );
61
- if (state.enabled) {
62
- return {
63
- messages: messagesWithoutLegacyContext.filter(
64
- (message) =>
65
- !messageContainsPlanModeImplementationContextArtifact(message) &&
66
- !messageContainsPlanModeImplementationHandoff(message),
67
- ),
68
- };
69
- }
48
+ return {
49
+ restore(activeImplementation) {
50
+ restoredImplementationAwaitingContext =
51
+ activeImplementation && activeImplementation.retention !== "keep" ? activeImplementation.id : undefined;
52
+ },
53
+ transformContext(messages, state) {
54
+ const messagesWithoutLegacyContext = messages.filter(
55
+ (message) => !messageContainsLegacyPlanModeContextArtifact(message),
56
+ );
57
+ if (state.enabled) {
58
+ return {
59
+ messages: messagesWithoutLegacyContext.filter(
60
+ (message) =>
61
+ !messageContainsPlanModeImplementationContextArtifact(message) &&
62
+ !messageContainsPlanModeImplementationHandoff(message),
63
+ ),
64
+ };
65
+ }
70
66
 
71
- const activeImplementation = state.activeImplementation;
72
- const inactiveMessages = activeImplementation
73
- ? messagesWithoutLegacyContext
74
- : messagesWithoutLegacyContext.filter(
75
- (message) =>
76
- !messageContainsPlanModeImplementationContextArtifact(message) &&
77
- !messageContainsPlanModeImplementationHandoff(message),
78
- );
79
- const historyArtifact = activeImplementation
80
- ? undefined
81
- : findHistoryImplementationArtifact(inactiveMessages);
82
- const historyArtifactMessage = historyArtifact
83
- ? inactiveMessages[historyArtifact.messageIndex]
84
- : undefined;
85
- const historyToolCallMessage =
86
- historyArtifact?.toolCallMessageIndex !== undefined
87
- ? inactiveMessages[historyArtifact.toolCallMessageIndex]
88
- : undefined;
89
- const filteredMessages = inactiveMessages
90
- .filter(
91
- (message) =>
92
- message === historyArtifactMessage || !messageContainsInactivePlanModeArtifact(message),
93
- )
94
- .map((message) =>
95
- message === historyArtifactMessage && historyArtifact?.kind === "legacy"
96
- ? message
97
- : stripProposedPlanBlocksFromMessage(message),
98
- )
99
- .map((message) =>
100
- stripPlanModeCompletionCallsFromMessage(
101
- message,
102
- message === historyToolCallMessage ? historyArtifact?.toolCallId : undefined,
103
- ),
104
- )
105
- .filter((message) => !isEmptyAssistantMessage(message));
106
- if (!activeImplementation) return { messages: filteredMessages };
67
+ const activeImplementation = state.activeImplementation;
68
+ const inactiveMessages = activeImplementation
69
+ ? messagesWithoutLegacyContext
70
+ : messagesWithoutLegacyContext.filter(
71
+ (message) =>
72
+ !messageContainsPlanModeImplementationContextArtifact(message) &&
73
+ !messageContainsPlanModeImplementationHandoff(message),
74
+ );
75
+ const historyArtifact = activeImplementation ? undefined : findHistoryImplementationArtifact(inactiveMessages);
76
+ const historyArtifactMessage = historyArtifact ? inactiveMessages[historyArtifact.messageIndex] : undefined;
77
+ const historyToolCallMessage =
78
+ historyArtifact?.toolCallMessageIndex !== undefined
79
+ ? inactiveMessages[historyArtifact.toolCallMessageIndex]
80
+ : undefined;
81
+ const filteredMessages = inactiveMessages
82
+ .filter((message) => message === historyArtifactMessage || !messageContainsInactivePlanModeArtifact(message))
83
+ .map((message) =>
84
+ message === historyArtifactMessage && historyArtifact?.kind === "legacy"
85
+ ? message
86
+ : stripProposedPlanBlocksFromMessage(message),
87
+ )
88
+ .map((message) =>
89
+ stripPlanModeCompletionCallsFromMessage(
90
+ message,
91
+ message === historyToolCallMessage ? historyArtifact?.toolCallId : undefined,
92
+ ),
93
+ )
94
+ .filter((message) => !isEmptyAssistantMessage(message));
95
+ if (!activeImplementation) return { messages: filteredMessages };
107
96
 
108
- const contextualMessages = injectActiveImplementationContext(
109
- filteredMessages,
110
- activeImplementation,
111
- );
112
- // A busy /plan implement queues its handoff behind an older run. Do not arm cleanup
113
- // until that exact handoff reaches context; a restored session has no older run to drain.
114
- const deliveredCurrentHandoff =
115
- restoredImplementationAwaitingContext === activeImplementation.id ||
116
- filteredMessages.some((message) =>
117
- messageContainsExactPlanModeImplementationHandoff(message, activeImplementation.plan),
118
- );
119
- if (!deliveredCurrentHandoff) return { messages: contextualMessages };
120
- restoredImplementationAwaitingContext = undefined;
97
+ const contextualMessages = injectActiveImplementationContext(filteredMessages, activeImplementation);
98
+ // A busy /plan implement queues its handoff behind an older run. Do not arm cleanup
99
+ // until that exact handoff reaches context; a restored session has no older run to drain.
100
+ const deliveredCurrentHandoff =
101
+ restoredImplementationAwaitingContext === activeImplementation.id ||
102
+ filteredMessages.some((message) =>
103
+ messageContainsExactPlanModeImplementationHandoff(message, activeImplementation.plan),
104
+ );
105
+ if (!deliveredCurrentHandoff) return { messages: contextualMessages };
106
+ restoredImplementationAwaitingContext = undefined;
121
107
 
122
- if (activeImplementation.retention === "clear-after-first-run") {
123
- implementationWithDeliveredContext = activeImplementation.id;
124
- }
125
- return {
126
- messages: contextualMessages,
127
- clearActiveImplementationId:
128
- activeImplementation.retention === "clear-on-start" ? activeImplementation.id : undefined,
129
- };
130
- },
131
- implementationSettled(activeImplementation) {
132
- if (
133
- activeImplementation?.retention !== "clear-after-first-run" ||
134
- implementationWithDeliveredContext !== activeImplementation.id
135
- ) {
136
- return undefined;
137
- }
138
- implementationWithDeliveredContext = undefined;
139
- return activeImplementation.id;
140
- },
141
- reset() {
142
- implementationWithDeliveredContext = undefined;
143
- restoredImplementationAwaitingContext = undefined;
144
- },
145
- };
108
+ if (activeImplementation.retention === "clear-after-first-run") {
109
+ implementationWithDeliveredContext = activeImplementation.id;
110
+ }
111
+ return {
112
+ messages: contextualMessages,
113
+ clearActiveImplementationId:
114
+ activeImplementation.retention === "clear-on-start" ? activeImplementation.id : undefined,
115
+ };
116
+ },
117
+ implementationSettled(activeImplementation) {
118
+ if (
119
+ activeImplementation?.retention !== "clear-after-first-run" ||
120
+ implementationWithDeliveredContext !== activeImplementation.id
121
+ ) {
122
+ return undefined;
123
+ }
124
+ implementationWithDeliveredContext = undefined;
125
+ return activeImplementation.id;
126
+ },
127
+ reset() {
128
+ implementationWithDeliveredContext = undefined;
129
+ restoredImplementationAwaitingContext = undefined;
130
+ },
131
+ };
146
132
  }