@narumitw/pi-plan-mode 0.57.0 → 0.58.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 +68 -18
- package/dist/chunks/{chunk-YUFPCQVG.js → chunk-QHHHBTDO.js} +315 -362
- package/dist/chunks/chunk-QHHHBTDO.js.map +7 -0
- package/dist/chunks/{interactive-ui-M3GEZN4M.js → interactive-ui-UNJGC2RQ.js} +397 -188
- package/dist/chunks/interactive-ui-UNJGC2RQ.js.map +7 -0
- package/dist/index.ts +669 -322
- package/dist/index.ts.map +4 -4
- package/docs/command-workflows.md +1 -5
- package/docs/settings.md +26 -24
- package/package.json +1 -1
- package/src/command.ts +1 -0
- package/src/fresh-handoff-coordinator.ts +55 -0
- package/src/fresh-implementation.ts +155 -74
- package/src/implementation-models.ts +48 -0
- package/src/plan-action-controller.ts +78 -23
- package/src/plan-action-menus.ts +361 -67
- package/src/plan-mode.ts +450 -117
- package/src/saved-plan-menu.ts +7 -35
- package/src/settings-menu.ts +156 -35
- package/src/settings.ts +80 -34
- package/src/state.ts +62 -0
- package/dist/chunks/chunk-YUFPCQVG.js.map +0 -7
- package/dist/chunks/interactive-ui-M3GEZN4M.js.map +0 -7
- package/src/fresh-implementation-preferences.ts +0 -102
- package/src/implementation-options.ts +0 -127
- package/src/implementation-preferences.ts +0 -145
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import type { ChoiceScreen, SettingsScreen } from "@narumitw/pi-tui-kit";
|
|
3
|
-
import { safeImplementationText as terminalText } from "./implementation-preferences.js";
|
|
4
|
-
import { type ImplementationPreferences, PLAN_MODE_THINKING_LEVELS } from "./settings.js";
|
|
5
|
-
|
|
6
|
-
export function implementationModelLabel(model: ImplementationPreferences["implementationModel"]) {
|
|
7
|
-
return model ? terminalText(`${model.provider} / ${model.id}`) : "Use current";
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function implementationSummary(preferences: ImplementationPreferences) {
|
|
11
|
-
return `Model: ${implementationModelLabel(preferences.implementationModel)} · Thinking: ${preferences.implementationThinkingLevel && preferences.implementationThinkingLevel !== "inherit" ? preferences.implementationThinkingLevel : "Use normal behavior"}`;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export type ImplementationOptionAction =
|
|
15
|
-
| "open-implementation-model"
|
|
16
|
-
| "set-implementation-model"
|
|
17
|
-
| "set-implementation-thinking";
|
|
18
|
-
|
|
19
|
-
export function implementationSettingItems(
|
|
20
|
-
preferences: ImplementationPreferences,
|
|
21
|
-
): SettingsScreen<ImplementationOptionAction>["items"] {
|
|
22
|
-
return [
|
|
23
|
-
{
|
|
24
|
-
id: "implementationModel",
|
|
25
|
-
label: "Implementation model",
|
|
26
|
-
currentValue: implementationModelLabel(preferences.implementationModel),
|
|
27
|
-
description:
|
|
28
|
-
"Select the model only when implementation starts; never switch back automatically.",
|
|
29
|
-
action: "open-implementation-model",
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
id: "implementationThinkingLevel",
|
|
33
|
-
label: "Implementation thinking",
|
|
34
|
-
currentValue: preferences.implementationThinkingLevel ?? "inherit",
|
|
35
|
-
values: PLAN_MODE_THINKING_LEVELS,
|
|
36
|
-
description:
|
|
37
|
-
"inherit preserves normal behavior, including restoration of Plan thinking. Explicit levels apply after model selection and are clamped by Pi.",
|
|
38
|
-
action: "set-implementation-thinking",
|
|
39
|
-
},
|
|
40
|
-
];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function createImplementationModelPicker(ctx: ExtensionContext) {
|
|
44
|
-
// Snapshot Pi's scoped catalogue without network refresh or auth execution.
|
|
45
|
-
// Unlike /model, this picker stages a preference and never persists Pi defaults.
|
|
46
|
-
const models = ctx.scopedModels?.length
|
|
47
|
-
? ctx.scopedModels.map(({ model }) => model)
|
|
48
|
-
: ctx.modelRegistry.getAvailable();
|
|
49
|
-
const byId = new Map(
|
|
50
|
-
models.map((model, index) => [
|
|
51
|
-
`implementation-model:${index}`,
|
|
52
|
-
{ provider: model.provider, id: model.id },
|
|
53
|
-
]),
|
|
54
|
-
);
|
|
55
|
-
return {
|
|
56
|
-
selection(itemId: string) {
|
|
57
|
-
return itemId === "implementation-current" ? null : byId.get(itemId);
|
|
58
|
-
},
|
|
59
|
-
screen(preferences: ImplementationPreferences): ChoiceScreen<"set-implementation-model"> {
|
|
60
|
-
return {
|
|
61
|
-
kind: "choice",
|
|
62
|
-
title: "Implementation model",
|
|
63
|
-
enableSearch: true,
|
|
64
|
-
viewportSize: 10,
|
|
65
|
-
hint: "back",
|
|
66
|
-
action: "set-implementation-model",
|
|
67
|
-
lines: [
|
|
68
|
-
"Use current makes no model change. Reopen this menu to refresh the catalogue.",
|
|
69
|
-
"Implement here sends the planning conversation to the selected provider; fresh transfers only the approved plan and normal destination resources.",
|
|
70
|
-
`Selected: ${implementationModelLabel(preferences.implementationModel)}`,
|
|
71
|
-
],
|
|
72
|
-
items: [
|
|
73
|
-
{ id: "implementation-current", label: "Use current" },
|
|
74
|
-
...[...byId].map(([id, model]) => ({ id, label: implementationModelLabel(model) })),
|
|
75
|
-
],
|
|
76
|
-
};
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** Local draft lives only as long as the owning action menu. */
|
|
82
|
-
export function createImplementationOptions(
|
|
83
|
-
ctx: ExtensionContext,
|
|
84
|
-
initial: ImplementationPreferences = {},
|
|
85
|
-
) {
|
|
86
|
-
let preferences = { ...initial };
|
|
87
|
-
let picker: ReturnType<typeof createImplementationModelPicker> | undefined;
|
|
88
|
-
return {
|
|
89
|
-
get: () => preferences,
|
|
90
|
-
summary: () => implementationSummary(preferences),
|
|
91
|
-
screens: {
|
|
92
|
-
"implementation-options": (): SettingsScreen<ImplementationOptionAction> => ({
|
|
93
|
-
kind: "settings",
|
|
94
|
-
title: "Implementation options",
|
|
95
|
-
lines: [
|
|
96
|
-
"Applies to both implementation actions in this menu only.",
|
|
97
|
-
"Changes take effect only when implementation starts. No automatic restoration afterwards.",
|
|
98
|
-
`Current model: ${implementationModelLabel(ctx.model)}`,
|
|
99
|
-
"inherit keeps normal thinking behavior, not necessarily the temporary Plan thinking level.",
|
|
100
|
-
],
|
|
101
|
-
items: implementationSettingItems(preferences),
|
|
102
|
-
}),
|
|
103
|
-
"implementation-model": () => {
|
|
104
|
-
picker ??= createImplementationModelPicker(ctx);
|
|
105
|
-
return picker.screen(preferences);
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
actions: {
|
|
109
|
-
"open-implementation-model": async () => ({
|
|
110
|
-
kind: "to" as const,
|
|
111
|
-
screen: "implementation-model" as const,
|
|
112
|
-
}),
|
|
113
|
-
"set-implementation-model": async ({ itemId }: { itemId: string }) => {
|
|
114
|
-
const selected = picker?.selection(itemId);
|
|
115
|
-
if (selected === undefined) return { kind: "rejected" as const };
|
|
116
|
-
preferences = { ...preferences, implementationModel: selected ?? undefined };
|
|
117
|
-
return { kind: "back" as const };
|
|
118
|
-
},
|
|
119
|
-
"set-implementation-thinking": async ({ value }: { value?: string }) => {
|
|
120
|
-
const level = PLAN_MODE_THINKING_LEVELS.find((level) => level === value);
|
|
121
|
-
if (!level) return { kind: "rejected" as const };
|
|
122
|
-
preferences = { ...preferences, implementationThinkingLevel: level };
|
|
123
|
-
return { kind: "stay" as const };
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
};
|
|
127
|
-
}
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import type { ImplementationPreferences } from "./settings.js";
|
|
3
|
-
|
|
4
|
-
type Model = NonNullable<ExtensionContext["model"]>;
|
|
5
|
-
type Thinking = ReturnType<ExtensionAPI["getThinkingLevel"]>;
|
|
6
|
-
export interface ImplementationSnapshot {
|
|
7
|
-
model: Model | undefined;
|
|
8
|
-
thinking: Thinking;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function observeImplementationModelSelections(pi: ExtensionAPI) {
|
|
12
|
-
let latest: ImplementationSnapshot | undefined;
|
|
13
|
-
pi.on("model_select", (_event, ctx) => {
|
|
14
|
-
latest = { model: ctx.model, thinking: pi.getThinkingLevel() };
|
|
15
|
-
});
|
|
16
|
-
return () => latest;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function hasImplementationPreferences(preferences: ImplementationPreferences) {
|
|
20
|
-
return (
|
|
21
|
-
preferences.implementationModel !== undefined ||
|
|
22
|
-
(preferences.implementationThinkingLevel !== undefined &&
|
|
23
|
-
preferences.implementationThinkingLevel !== "inherit")
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function sameModel(
|
|
28
|
-
left: { provider: string; id: string } | undefined,
|
|
29
|
-
right: { provider: string; id: string } | undefined,
|
|
30
|
-
) {
|
|
31
|
-
return left?.provider === right?.provider && left?.id === right?.id;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function safeImplementationText(value: string) {
|
|
35
|
-
return [...value]
|
|
36
|
-
.map((character) => {
|
|
37
|
-
const code = character.codePointAt(0) ?? 0;
|
|
38
|
-
return code <= 0x1f || (code >= 0x7f && code <= 0x9f) ? " " : character;
|
|
39
|
-
})
|
|
40
|
-
.join("")
|
|
41
|
-
.trim();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function preferenceError(error: unknown) {
|
|
45
|
-
return safeImplementationText(error instanceof Error ? error.message : String(error)).slice(
|
|
46
|
-
0,
|
|
47
|
-
500,
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export async function preflightImplementationPreferences(
|
|
52
|
-
ctx: ExtensionContext,
|
|
53
|
-
preferences: ImplementationPreferences,
|
|
54
|
-
isCurrent: () => boolean,
|
|
55
|
-
): Promise<Model | undefined> {
|
|
56
|
-
if (!isCurrent()) return undefined;
|
|
57
|
-
const identity = preferences.implementationModel;
|
|
58
|
-
const model = identity ? ctx.modelRegistry.find(identity.provider, identity.id) : ctx.model;
|
|
59
|
-
if (!model)
|
|
60
|
-
throw new Error(
|
|
61
|
-
"Implementation model is unavailable. Select a registered model or use current.",
|
|
62
|
-
);
|
|
63
|
-
// Pi's auth facade has no AbortSignal. Pi owns this operation; drain it and
|
|
64
|
-
// revalidate rather than claiming that cancellation stops provider auth work.
|
|
65
|
-
const auth = await ctx.modelRegistry.getApiKeyAndHeaders(model);
|
|
66
|
-
if (!isCurrent()) return undefined;
|
|
67
|
-
// Composed registries may materialize a new definition on every lookup.
|
|
68
|
-
const currentModel = identity ? ctx.modelRegistry.find(identity.provider, identity.id) : model;
|
|
69
|
-
if (!currentModel) {
|
|
70
|
-
throw new Error(
|
|
71
|
-
"Implementation model catalogue changed during preflight. Reopen the menu and retry.",
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
if (!auth.ok) throw new Error(auth.error);
|
|
75
|
-
return currentModel;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** A one-shot handoff transaction, never an implementation-run restoration hook. */
|
|
79
|
-
export function createImplementationPreferenceChange(
|
|
80
|
-
pi: ExtensionAPI,
|
|
81
|
-
ctx: ExtensionContext,
|
|
82
|
-
isSessionCurrent: () => boolean,
|
|
83
|
-
original: ImplementationSnapshot = { model: ctx.model, thinking: pi.getThinkingLevel() },
|
|
84
|
-
selectionSnapshot?: () => ImplementationSnapshot | undefined,
|
|
85
|
-
) {
|
|
86
|
-
let applied: ImplementationSnapshot | undefined;
|
|
87
|
-
const snapshot = (): ImplementationSnapshot => ({
|
|
88
|
-
model: ctx.model,
|
|
89
|
-
thinking: pi.getThinkingLevel(),
|
|
90
|
-
});
|
|
91
|
-
const matches = (value: ImplementationSnapshot) =>
|
|
92
|
-
sameModel(ctx.model, value.model) && pi.getThinkingLevel() === value.thinking;
|
|
93
|
-
return {
|
|
94
|
-
async apply(model: Model, preferences: ImplementationPreferences, isCurrent: () => boolean) {
|
|
95
|
-
if (!isCurrent()) return false;
|
|
96
|
-
// Includes any Plan-thinking restoration performed immediately before apply.
|
|
97
|
-
applied = snapshot();
|
|
98
|
-
if (preferences.implementationModel && !sameModel(ctx.model, model)) {
|
|
99
|
-
const beforeSelection = selectionSnapshot?.();
|
|
100
|
-
if (!(await pi.setModel(model)))
|
|
101
|
-
throw new Error("Implementation model authentication is unavailable.");
|
|
102
|
-
if (!isSessionCurrent()) return false;
|
|
103
|
-
if (!sameModel(ctx.model, model)) return false;
|
|
104
|
-
const selected = selectionSnapshot?.();
|
|
105
|
-
applied = selected && selected !== beforeSelection ? selected : snapshot();
|
|
106
|
-
if (!matches(applied)) {
|
|
107
|
-
if (ctx.hasUI)
|
|
108
|
-
ctx.ui.notify(
|
|
109
|
-
"Model or thinking changed during implementation preparation. The plan remains available; retry when ready.",
|
|
110
|
-
"warning",
|
|
111
|
-
);
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
if (!isCurrent()) return false;
|
|
115
|
-
}
|
|
116
|
-
const level = preferences.implementationThinkingLevel;
|
|
117
|
-
if (level && level !== "inherit") {
|
|
118
|
-
pi.setThinkingLevel(level);
|
|
119
|
-
applied = snapshot();
|
|
120
|
-
if (applied.thinking !== level && ctx.hasUI)
|
|
121
|
-
ctx.ui.notify(
|
|
122
|
-
`Implementation thinking: ${applied.thinking} (requested ${level}; adjusted by Pi for this model).`,
|
|
123
|
-
"info",
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
return isCurrent();
|
|
127
|
-
},
|
|
128
|
-
async rollback() {
|
|
129
|
-
if (!applied || !isSessionCurrent() || !ctx.isIdle() || !matches(applied)) return;
|
|
130
|
-
if (!sameModel(ctx.model, original.model)) {
|
|
131
|
-
const beforeSelection = selectionSnapshot?.();
|
|
132
|
-
if (!original.model || !(await pi.setModel(original.model))) {
|
|
133
|
-
throw new Error(
|
|
134
|
-
"Could not restore the previous model. The plan remains available; select a model before retrying.",
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
if (!isSessionCurrent() || !ctx.isIdle() || !sameModel(ctx.model, original.model)) return;
|
|
138
|
-
const selected = selectionSnapshot?.();
|
|
139
|
-
if (selected && selected !== beforeSelection && !matches(selected)) return;
|
|
140
|
-
}
|
|
141
|
-
pi.setThinkingLevel(original.thinking);
|
|
142
|
-
applied = undefined;
|
|
143
|
-
},
|
|
144
|
-
};
|
|
145
|
-
}
|