@narumitw/pi-starship 0.60.1 → 0.63.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 +67 -9
- package/dist/chunks/chunk-63R6R5DH.ts +679 -0
- package/dist/chunks/chunk-63R6R5DH.ts.map +7 -0
- package/dist/chunks/{chunk-KZZKGGFW.ts → chunk-A65IOGL6.ts} +858 -1007
- package/dist/chunks/chunk-A65IOGL6.ts.map +7 -0
- package/dist/chunks/chunk-IYDZ3R2T.ts +69 -0
- package/dist/chunks/chunk-IYDZ3R2T.ts.map +7 -0
- package/dist/chunks/chunk-KP33I6BR.ts +579 -0
- package/dist/chunks/chunk-KP33I6BR.ts.map +7 -0
- package/dist/chunks/{chunk-PD457PX5.ts → chunk-S2KBLHE2.ts} +75 -10
- package/dist/chunks/chunk-S2KBLHE2.ts.map +7 -0
- package/dist/chunks/chunk-XQUIQO2G.ts +20 -0
- package/dist/chunks/chunk-XQUIQO2G.ts.map +7 -0
- package/dist/chunks/{chunk-ADX4CY27.ts → chunk-XTLQ4WUL.ts} +1 -1
- package/dist/chunks/chunk-XTLQ4WUL.ts.map +7 -0
- package/dist/chunks/chunk-Y24TJYG6.ts +1586 -0
- package/dist/chunks/chunk-Y24TJYG6.ts.map +7 -0
- package/dist/chunks/{cloud-EPAEV4ZB.ts → cloud-J2ZOE3HE.ts} +6 -2
- package/dist/chunks/cloud-J2ZOE3HE.ts.map +7 -0
- package/dist/chunks/command-configuration-menu-YOLN2SPR.ts +147 -0
- package/dist/chunks/command-configuration-menu-YOLN2SPR.ts.map +7 -0
- package/dist/chunks/command-settings-chat-5AHP3JGV.ts +1124 -0
- package/dist/chunks/command-settings-chat-5AHP3JGV.ts.map +7 -0
- package/dist/chunks/commands-IOG2PL67.ts +1026 -0
- package/dist/chunks/commands-IOG2PL67.ts.map +7 -0
- package/dist/chunks/{deployment-7J54EHNR.ts → deployment-NOJ2KCLI.ts} +85 -5
- package/dist/chunks/deployment-NOJ2KCLI.ts.map +7 -0
- package/dist/chunks/{development-IWJAAAEV.ts → development-T3XXVVDP.ts} +67 -15
- package/dist/chunks/development-T3XXVVDP.ts.map +7 -0
- package/dist/chunks/directory-OX6BWJZA.ts +31 -0
- package/dist/chunks/directory-OX6BWJZA.ts.map +7 -0
- package/dist/chunks/{execution-P4WZALW2.ts → execution-R2OHIP2L.ts} +8 -4
- package/dist/chunks/execution-R2OHIP2L.ts.map +7 -0
- package/dist/chunks/jujutsu-XLDYKSX2.ts +174 -0
- package/dist/chunks/jujutsu-XLDYKSX2.ts.map +7 -0
- package/dist/chunks/languages-CBQNNYXM.ts +262 -0
- package/dist/chunks/languages-CBQNNYXM.ts.map +7 -0
- package/dist/chunks/{package-H24VJEX3.ts → package-7KVAK3TC.ts} +6 -2
- package/dist/chunks/package-7KVAK3TC.ts.map +7 -0
- package/dist/chunks/system-574MHB4R.ts +165 -0
- package/dist/chunks/system-574MHB4R.ts.map +7 -0
- package/dist/index.ts +670 -206
- package/dist/index.ts.map +4 -4
- package/package.json +5 -1
- package/skills/configure-pi-starship/SKILL.md +17 -1
- package/skills/configure-pi-starship/references/configuration.md +119 -32
- package/skills/configure-pi-starship/references/module-catalog.md +278 -25
- package/skills/configure-pi-starship/references/modules.md +213 -36
- package/skills/configure-pi-starship/references/runtime-and-security.md +88 -28
- package/src/command-commit.ts +41 -7
- package/src/command-configuration-menu.ts +155 -0
- package/src/command-configuration.ts +15 -94
- package/src/command-preview.ts +3 -3
- package/src/command-settings-chat.ts +168 -0
- package/src/commands.ts +76 -124
- package/src/config/module-options.ts +112 -0
- package/src/config.ts +23 -59
- package/src/effective-config.ts +5 -4
- package/src/format/bounded-regex.ts +66 -0
- package/src/format/version.ts +24 -0
- package/src/modules/catalog.ts +10 -0
- package/src/modules/cloud.ts +1 -0
- package/src/modules/deployment.ts +8 -0
- package/src/modules/development.ts +20 -2
- package/src/modules/directory.ts +171 -51
- package/src/modules/execution.ts +2 -0
- package/src/modules/git/branch.ts +19 -4
- package/src/modules/git/commit.ts +9 -2
- package/src/modules/git/metrics.ts +9 -4
- package/src/modules/git/runtime.ts +122 -33
- package/src/modules/git/state.ts +23 -2
- package/src/modules/git/status-templates.ts +58 -0
- package/src/modules/git/status.ts +96 -30
- package/src/modules/jujutsu.ts +225 -0
- package/src/modules/languages.ts +26 -2
- package/src/modules/package.ts +1 -0
- package/src/modules/render.ts +42 -16
- package/src/modules/system.ts +54 -0
- package/src/modules/time-format.ts +188 -0
- package/src/modules/time.ts +11 -5
- package/src/modules/types.ts +42 -4
- package/src/pi-starship.ts +198 -88
- package/src/profile-store.ts +5 -0
- package/src/runtime/cloud.ts +3 -0
- package/src/runtime/command.ts +1 -1
- package/src/runtime/deployment.ts +120 -4
- package/src/runtime/development.ts +86 -13
- package/src/runtime/directory.ts +33 -0
- package/src/runtime/execution.ts +12 -2
- package/src/runtime/helpers.ts +57 -8
- package/src/runtime/jujutsu.ts +225 -0
- package/src/runtime/languages.ts +106 -19
- package/src/runtime/package.ts +3 -0
- package/src/runtime/system.ts +202 -0
- package/src/runtime/types.ts +3 -0
- package/src/runtime/version-requirements.ts +30 -0
- package/src/runtime/workspace.ts +12 -1
- package/src/settings-agent.ts +80 -0
- package/src/settings-chat-transcript.ts +192 -0
- package/src/settings-chat-ui.ts +526 -0
- package/src/settings-draft.ts +260 -0
- package/src/settings-snapshots.ts +41 -0
- package/dist/chunks/chunk-ADX4CY27.ts.map +0 -7
- package/dist/chunks/chunk-KZZKGGFW.ts.map +0 -7
- package/dist/chunks/chunk-PD457PX5.ts.map +0 -7
- package/dist/chunks/cloud-EPAEV4ZB.ts.map +0 -7
- package/dist/chunks/commands-C2VJ6ZBN.ts +0 -3374
- package/dist/chunks/commands-C2VJ6ZBN.ts.map +0 -7
- package/dist/chunks/deployment-7J54EHNR.ts.map +0 -7
- package/dist/chunks/development-IWJAAAEV.ts.map +0 -7
- package/dist/chunks/execution-P4WZALW2.ts.map +0 -7
- package/dist/chunks/languages-JO6R2PHL.ts +0 -168
- package/dist/chunks/languages-JO6R2PHL.ts.map +0 -7
- package/dist/chunks/package-H24VJEX3.ts.map +0 -7
- package/src/command-inspector.ts +0 -41
package/src/command-commit.ts
CHANGED
|
@@ -58,9 +58,13 @@ export async function commitActiveDocument(
|
|
|
58
58
|
expected: CommitExpectation,
|
|
59
59
|
allowInvalid = false,
|
|
60
60
|
checkCandidate?: () => void,
|
|
61
|
+
restoreNative = false,
|
|
61
62
|
): Promise<"applied" | "cancel"> {
|
|
62
63
|
const raw = candidate.rawDocument;
|
|
63
|
-
if (
|
|
64
|
+
if (restoreNative) {
|
|
65
|
+
if (raw !== undefined || candidate.source !== "built-in" || candidate.diagnostics.length > 0)
|
|
66
|
+
throw new Error("The native footer candidate is invalid");
|
|
67
|
+
} else if (raw === undefined) throw new Error("The candidate settings document is unavailable");
|
|
64
68
|
return withFileMutationQueue(options.settingsPath, async () => {
|
|
65
69
|
if (!commitOwnerCurrent(options, owner, expected)) return "cancel";
|
|
66
70
|
checkCandidate?.();
|
|
@@ -75,8 +79,10 @@ export async function commitActiveDocument(
|
|
|
75
79
|
if (invalid && !allowInvalid)
|
|
76
80
|
throw new Error("The active settings document is invalid. Use explicit repair or recovery before replacing it.");
|
|
77
81
|
// Always validate again at the publication boundary, not only in the preview layer.
|
|
78
|
-
|
|
79
|
-
|
|
82
|
+
if (raw !== undefined) {
|
|
83
|
+
validateConfigDocument(options.settingsPath, raw);
|
|
84
|
+
if (previousBytes?.equals(Buffer.from(raw))) return "applied";
|
|
85
|
+
}
|
|
80
86
|
|
|
81
87
|
let recoveryPath: string | undefined;
|
|
82
88
|
if (previousBytes !== undefined) {
|
|
@@ -92,10 +98,28 @@ export async function commitActiveDocument(
|
|
|
92
98
|
}
|
|
93
99
|
let saved: LoadedStarshipConfig;
|
|
94
100
|
try {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
101
|
+
if (raw === undefined) {
|
|
102
|
+
if (previousBytes !== undefined) {
|
|
103
|
+
if (!expected.disk.fileIdentity) throw new Error("The settings document identity is unavailable");
|
|
104
|
+
removeConfigDocumentIfMatches(
|
|
105
|
+
options.settingsPath,
|
|
106
|
+
previousBytes.toString("utf8"),
|
|
107
|
+
expected.disk.fileIdentity,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
saved = candidate;
|
|
111
|
+
} else {
|
|
112
|
+
saved = options.save
|
|
113
|
+
? options.save(options.settingsPath, raw)
|
|
114
|
+
: atomicSaveConfigDocument(options.settingsPath, raw, {}, expected.disk);
|
|
115
|
+
}
|
|
98
116
|
} catch (error) {
|
|
117
|
+
if (restoreNative) {
|
|
118
|
+
const rollback = restorePrevious(ctx, options, owner, expected, undefined, undefined, false);
|
|
119
|
+
throw new Error(
|
|
120
|
+
`Pi native footer was not restored: ${message(error)}. ${rollback}${recoveryNote(recoveryPath)}`,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
99
123
|
if (error instanceof ConfigPublicationError) {
|
|
100
124
|
const rollback = restorePrevious(ctx, options, owner, expected, raw, error.fileIdentity, false);
|
|
101
125
|
throw new Error(`Footer settings were not saved: ${message(error)}. ${rollback}${recoveryNote(recoveryPath)}`);
|
|
@@ -128,7 +152,7 @@ function restorePrevious(
|
|
|
128
152
|
options: CommitOptions,
|
|
129
153
|
owner: WorkflowOwner,
|
|
130
154
|
expected: CommitExpectation,
|
|
131
|
-
raw: string,
|
|
155
|
+
raw: string | undefined,
|
|
132
156
|
identity: LoadedStarshipConfig["fileIdentity"],
|
|
133
157
|
restoreRuntime: boolean,
|
|
134
158
|
): string {
|
|
@@ -139,6 +163,16 @@ function restorePrevious(
|
|
|
139
163
|
if (current.rawDocument !== expected.previous.rawDocument && current.rawDocument !== raw) {
|
|
140
164
|
throw new Error("The active runtime changed; stale restoration was blocked");
|
|
141
165
|
}
|
|
166
|
+
if (raw === undefined) {
|
|
167
|
+
const disk = readConfigDocumentSnapshot(options.settingsPath);
|
|
168
|
+
if (disk.rawBytes !== undefined) {
|
|
169
|
+
assertConfigDocumentUnchanged(options.settingsPath, expected.disk);
|
|
170
|
+
} else if (expected.disk.rawBytes !== undefined) {
|
|
171
|
+
atomicRestoreConfigDocument(options.settingsPath, expected.disk.rawBytes, {}, disk);
|
|
172
|
+
}
|
|
173
|
+
if (restoreRuntime) options.apply(expected.previous, ctx);
|
|
174
|
+
return "The previous configuration was restored.";
|
|
175
|
+
}
|
|
142
176
|
if (!identity) throw new Error("The saved settings document identity is unavailable");
|
|
143
177
|
assertConfigDocumentUnchanged(options.settingsPath, { rawBytes: Buffer.from(raw), fileIdentity: identity });
|
|
144
178
|
if (expected.disk.rawBytes === undefined) {
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { stripVTControlCharacters } from "node:util";
|
|
2
|
+
import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import { isKeyRelease, Key, matchesKey, SelectList } from "@earendil-works/pi-tui";
|
|
4
|
+
import {
|
|
5
|
+
formatInteractionHints,
|
|
6
|
+
HorizontalRule,
|
|
7
|
+
hardWrapTerminalDocument,
|
|
8
|
+
renderBoundedFrameLayout,
|
|
9
|
+
runCustomInteraction,
|
|
10
|
+
} from "@narumitw/pi-tui-kit";
|
|
11
|
+
import {
|
|
12
|
+
type ConfigurationCommandOptions,
|
|
13
|
+
configurationMenuScreen,
|
|
14
|
+
type WorkflowOwner,
|
|
15
|
+
} from "./command-configuration.js";
|
|
16
|
+
|
|
17
|
+
type ConfigurationAction = ReturnType<typeof configurationMenuScreen>["items"][number]["action"];
|
|
18
|
+
|
|
19
|
+
/** Kit action headers do not scroll. Keep this extension-owned summary viewport above a native SelectList. */
|
|
20
|
+
export function showConfigurationMenu(
|
|
21
|
+
ctx: ExtensionCommandContext,
|
|
22
|
+
options: ConfigurationCommandOptions,
|
|
23
|
+
owner: WorkflowOwner,
|
|
24
|
+
selected?: string,
|
|
25
|
+
) {
|
|
26
|
+
return runCustomInteraction<ConfigurationAction | "back" | "close">(ctx, {
|
|
27
|
+
signal: owner.signal,
|
|
28
|
+
isCurrent: owner.isCurrent,
|
|
29
|
+
create: ({ tui, theme, keybindings, complete }) => {
|
|
30
|
+
const screen = configurationMenuScreen(options.getLoaded(), options.settingsPath);
|
|
31
|
+
const list = new SelectList(
|
|
32
|
+
screen.items.map((item) => ({ value: item.action, label: item.label, description: item.description })),
|
|
33
|
+
4,
|
|
34
|
+
{
|
|
35
|
+
selectedPrefix: (text) => theme.fg("accent", text),
|
|
36
|
+
selectedText: (text) => theme.fg("accent", text),
|
|
37
|
+
description: (text) => theme.fg("muted", text),
|
|
38
|
+
scrollInfo: (text) => theme.fg("muted", text),
|
|
39
|
+
noMatch: (text) => theme.fg("muted", text),
|
|
40
|
+
},
|
|
41
|
+
);
|
|
42
|
+
let index = Math.max(
|
|
43
|
+
0,
|
|
44
|
+
screen.items.findIndex((item) => item.action === selected),
|
|
45
|
+
);
|
|
46
|
+
list.setSelectedIndex(index);
|
|
47
|
+
let offset = 0;
|
|
48
|
+
let pageSize = 1;
|
|
49
|
+
let lastOffset = 0;
|
|
50
|
+
let disposed = false;
|
|
51
|
+
let layout: ReturnType<typeof renderBoundedFrameLayout> | undefined;
|
|
52
|
+
let listStart = 0;
|
|
53
|
+
let lastWidth = 0;
|
|
54
|
+
const rule = new HorizontalRule({ ruleStyle: (text) => theme.fg("border", text) });
|
|
55
|
+
const scroll = (direction: number) => {
|
|
56
|
+
offset = Math.max(0, Math.min(lastOffset, offset + direction * pageSize));
|
|
57
|
+
tui.requestRender();
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
render(width) {
|
|
61
|
+
if (disposed) return [];
|
|
62
|
+
lastWidth = width;
|
|
63
|
+
const rows = Number.isFinite(tui.terminal.rows) ? Math.floor(tui.terminal.rows) : 24;
|
|
64
|
+
const maxRows = Math.max(1, rows - 3);
|
|
65
|
+
const summary = hardWrapTerminalDocument(screen.lines.join("\n"), width);
|
|
66
|
+
const listRows = list.render(width);
|
|
67
|
+
const description = screen.items[index]?.description;
|
|
68
|
+
const details =
|
|
69
|
+
description && !listRows.some((line) => stripVTControlCharacters(line).includes(description))
|
|
70
|
+
? hardWrapTerminalDocument(description, width).map((line) => theme.fg("muted", line))
|
|
71
|
+
: [];
|
|
72
|
+
pageSize = Math.max(1, maxRows - 11 - (details.length ? details.length + 1 : 0));
|
|
73
|
+
lastOffset = Math.max(0, summary.length - pageSize);
|
|
74
|
+
offset = Math.min(offset, lastOffset);
|
|
75
|
+
const visibleSummary = summary.slice(offset, offset + pageSize).map((line) => theme.fg("muted", line));
|
|
76
|
+
const status =
|
|
77
|
+
lastOffset > 0
|
|
78
|
+
? [
|
|
79
|
+
theme.fg(
|
|
80
|
+
"muted",
|
|
81
|
+
`Summary ${offset + 1}-${Math.min(summary.length, offset + pageSize)}/${summary.length} · Page navigation scrolls summary`,
|
|
82
|
+
),
|
|
83
|
+
]
|
|
84
|
+
: [];
|
|
85
|
+
listStart = visibleSummary.length + status.length + 1;
|
|
86
|
+
const detailStart = listStart + listRows.length + 1;
|
|
87
|
+
const content = [...visibleSummary, ...status, "", ...listRows, ...(details.length ? ["", ...details] : [])];
|
|
88
|
+
const hints = formatInteractionHints(keybindings, [
|
|
89
|
+
{ bindings: ["tui.select.up", "tui.select.down"], label: "navigate" },
|
|
90
|
+
{ bindings: ["tui.select.confirm"], label: "select" },
|
|
91
|
+
{ bindings: ["tui.select.cancel"], label: "back" },
|
|
92
|
+
]);
|
|
93
|
+
layout = renderBoundedFrameLayout({
|
|
94
|
+
width,
|
|
95
|
+
maxRows,
|
|
96
|
+
rule: rule.render(width)[0] ?? "",
|
|
97
|
+
title: [theme.fg("accent", theme.bold(screen.title))],
|
|
98
|
+
content,
|
|
99
|
+
hints: [theme.fg("muted", `${hints} • ctrl+c close`)],
|
|
100
|
+
compactHint: "",
|
|
101
|
+
focusedRow: listStart + index,
|
|
102
|
+
priorityRows: [listStart + index, ...details.map((_, index) => detailStart + index)],
|
|
103
|
+
});
|
|
104
|
+
return layout.lines;
|
|
105
|
+
},
|
|
106
|
+
invalidate() {
|
|
107
|
+
layout = undefined;
|
|
108
|
+
list.invalidate();
|
|
109
|
+
},
|
|
110
|
+
handleInput(data) {
|
|
111
|
+
if (disposed || isKeyRelease(data)) return;
|
|
112
|
+
// Standard selection and cancellation take priority over summary scrolling.
|
|
113
|
+
if (matchesKey(data, Key.ctrl("c"))) complete("close");
|
|
114
|
+
else if (keybindings.matches(data, "tui.select.cancel")) complete("back");
|
|
115
|
+
else if (keybindings.matches(data, "tui.select.up")) {
|
|
116
|
+
index = (index + screen.items.length - 1) % screen.items.length;
|
|
117
|
+
list.setSelectedIndex(index);
|
|
118
|
+
} else if (keybindings.matches(data, "tui.select.down")) {
|
|
119
|
+
index = (index + 1) % screen.items.length;
|
|
120
|
+
list.setSelectedIndex(index);
|
|
121
|
+
} else if (matchesKey(data, Key.home)) {
|
|
122
|
+
index = 0;
|
|
123
|
+
list.setSelectedIndex(index);
|
|
124
|
+
} else if (matchesKey(data, Key.end)) {
|
|
125
|
+
index = screen.items.length - 1;
|
|
126
|
+
list.setSelectedIndex(index);
|
|
127
|
+
} else if (keybindings.matches(data, "tui.select.confirm")) {
|
|
128
|
+
const item = screen.items[index];
|
|
129
|
+
if (item) complete(item.action);
|
|
130
|
+
} else if (keybindings.matches(data, "tui.select.pageUp")) scroll(-1);
|
|
131
|
+
else if (keybindings.matches(data, "tui.select.pageDown")) scroll(1);
|
|
132
|
+
tui.requestRender();
|
|
133
|
+
},
|
|
134
|
+
handleMouse(event) {
|
|
135
|
+
if (disposed || !layout || event.width !== lastWidth) return undefined;
|
|
136
|
+
const row = layout.contentRows.find((row) => row.frameIndex === event.y)?.contentIndex;
|
|
137
|
+
if (row === undefined) return undefined;
|
|
138
|
+
if (row < listStart) {
|
|
139
|
+
if (event.type !== "wheel" || !event.wheelDelta) return undefined;
|
|
140
|
+
scroll(event.wheelDelta < 0 ? -1 : 1);
|
|
141
|
+
return { handled: true, render: true };
|
|
142
|
+
}
|
|
143
|
+
const result = list.handleMouse({ ...event, y: row - listStart });
|
|
144
|
+
index = screen.items.findIndex((item) => item.action === list.getSelectedItem()?.value);
|
|
145
|
+
const item = screen.items[index];
|
|
146
|
+
if (event.type === "click" && result?.handled && item) complete(item.action);
|
|
147
|
+
return result;
|
|
148
|
+
},
|
|
149
|
+
dispose() {
|
|
150
|
+
disposed = true;
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
}
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
loadStarshipConfig,
|
|
10
10
|
readConfigDocumentSnapshot,
|
|
11
11
|
} from "./config.js";
|
|
12
|
-
import { serializeEffectiveConfig } from "./effective-config.js";
|
|
13
12
|
import { presetForDocument } from "./presets/catalog.js";
|
|
14
13
|
import { archiveConfigDocument } from "./profile-store.js";
|
|
15
14
|
|
|
@@ -50,7 +49,7 @@ export function configurationPresentation(loaded: LoadedStarshipConfig): Configu
|
|
|
50
49
|
const fallback = loaded.source === "built-in" && loaded.diagnostics.length > 0;
|
|
51
50
|
return {
|
|
52
51
|
state: healthyMissing
|
|
53
|
-
? "
|
|
52
|
+
? "Pi native footer"
|
|
54
53
|
: savedBuiltIn
|
|
55
54
|
? "Saved built-in configuration"
|
|
56
55
|
: activePreset
|
|
@@ -66,44 +65,25 @@ export function configurationPresentation(loaded: LoadedStarshipConfig): Configu
|
|
|
66
65
|
? "User file"
|
|
67
66
|
: "Built-in fallback",
|
|
68
67
|
health: configurationHealth(loaded),
|
|
69
|
-
restoreDisabled: healthyMissing
|
|
68
|
+
restoreDisabled: healthyMissing,
|
|
70
69
|
restoreDescription: healthyMissing
|
|
71
|
-
? "Already using
|
|
72
|
-
:
|
|
73
|
-
? "Built-in configuration already saved"
|
|
74
|
-
: fallback
|
|
75
|
-
? "Preview before replacing invalid settings"
|
|
76
|
-
: "Preview before replacing the document",
|
|
70
|
+
? "Already using Pi native footer · no file to remove"
|
|
71
|
+
: "Preview before restoring Pi native footer",
|
|
77
72
|
};
|
|
78
73
|
}
|
|
79
74
|
|
|
80
|
-
export function configurationMenuScreen(loaded: LoadedStarshipConfig) {
|
|
75
|
+
export function configurationMenuScreen(loaded: LoadedStarshipConfig, settingsPath: string) {
|
|
81
76
|
const presentation = configurationPresentation(loaded);
|
|
82
77
|
return {
|
|
83
78
|
kind: "actions" as const,
|
|
84
79
|
title: "Configuration",
|
|
85
|
-
lines: [
|
|
80
|
+
lines: [
|
|
81
|
+
`State: ${presentation.state}`,
|
|
82
|
+
`Source: ${presentation.source}`,
|
|
83
|
+
`Path: ${sanitizeTerminalText(settingsPath)}`,
|
|
84
|
+
...diagnosticLines(loaded, true, loaded.diagnostics.length),
|
|
85
|
+
],
|
|
86
86
|
items: [
|
|
87
|
-
{
|
|
88
|
-
id: "configuration-overview",
|
|
89
|
-
label: "Overview",
|
|
90
|
-
description: "State, source, path, health, and warnings",
|
|
91
|
-
to: "configuration-overview" as const,
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
id: "configuration-effective",
|
|
95
|
-
label: "Effective configuration",
|
|
96
|
-
description: "Normalized public TOML currently in use",
|
|
97
|
-
to: "configuration-effective" as const,
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
id: "configuration-document",
|
|
101
|
-
label: "Settings document",
|
|
102
|
-
description: isHealthyMissing(loaded)
|
|
103
|
-
? "No settings file · built-in defaults are active"
|
|
104
|
-
: "Exact loaded UTF-8 text · read-only",
|
|
105
|
-
to: "configuration-document" as const,
|
|
106
|
-
},
|
|
107
87
|
{
|
|
108
88
|
id: "configuration-reload",
|
|
109
89
|
label: "Reload from disk…",
|
|
@@ -133,65 +113,6 @@ export function configurationMenuScreen(loaded: LoadedStarshipConfig) {
|
|
|
133
113
|
};
|
|
134
114
|
}
|
|
135
115
|
|
|
136
|
-
export function configurationOverviewScreen(loaded: LoadedStarshipConfig, settingsPath: string) {
|
|
137
|
-
const presentation = configurationPresentation(loaded);
|
|
138
|
-
return {
|
|
139
|
-
kind: "detail" as const,
|
|
140
|
-
title: "Configuration overview",
|
|
141
|
-
lines: [
|
|
142
|
-
`State: ${presentation.state}`,
|
|
143
|
-
`Source: ${presentation.source}`,
|
|
144
|
-
`Path: ${sanitizeTerminalText(settingsPath)}`,
|
|
145
|
-
...diagnosticLines(loaded, true),
|
|
146
|
-
],
|
|
147
|
-
hint: "back" as const,
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export function effectiveConfigurationScreen(loaded: LoadedStarshipConfig) {
|
|
152
|
-
const presentation = configurationPresentation(loaded);
|
|
153
|
-
return {
|
|
154
|
-
kind: "review" as const,
|
|
155
|
-
title: "Effective configuration",
|
|
156
|
-
lines: [
|
|
157
|
-
`${presentation.state} · ${presentation.health}`,
|
|
158
|
-
"Normalized public TOML; comments and unknown fields are intentionally excluded.",
|
|
159
|
-
],
|
|
160
|
-
content: serializeEffectiveConfig(loaded.config),
|
|
161
|
-
enableSearch: true,
|
|
162
|
-
format: { kind: "code" as const, language: "toml" },
|
|
163
|
-
viewportSize: "adaptive" as const,
|
|
164
|
-
hint: "back" as const,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export function settingsDocumentScreen(loaded: LoadedStarshipConfig, settingsPath: string) {
|
|
169
|
-
const path = sanitizeTerminalText(settingsPath);
|
|
170
|
-
if (loaded.rawDocument !== undefined) {
|
|
171
|
-
return {
|
|
172
|
-
kind: "review" as const,
|
|
173
|
-
title: "Settings document",
|
|
174
|
-
lines: ["Exact loaded UTF-8 text · display controls sanitized · read-only", `Path: ${path}`],
|
|
175
|
-
content: loaded.rawDocument,
|
|
176
|
-
enableSearch: true,
|
|
177
|
-
format: { kind: "code" as const, language: "toml" },
|
|
178
|
-
viewportSize: "adaptive" as const,
|
|
179
|
-
hint: "back" as const,
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
return {
|
|
183
|
-
kind: "detail" as const,
|
|
184
|
-
title: "Settings document",
|
|
185
|
-
lines: [
|
|
186
|
-
...(isHealthyMissing(loaded)
|
|
187
|
-
? ["No settings document exists.", "Built-in defaults are active; this read created no file."]
|
|
188
|
-
: ["The settings document could not be loaded.", ...diagnosticLines(loaded, false)]),
|
|
189
|
-
`Path: ${path}`,
|
|
190
|
-
],
|
|
191
|
-
hint: "back" as const,
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
|
|
195
116
|
export async function reloadConfiguration(
|
|
196
117
|
ctx: ExtensionCommandContext,
|
|
197
118
|
options: ConfigurationCommandOptions,
|
|
@@ -235,7 +156,7 @@ export async function reloadConfiguration(
|
|
|
235
156
|
const confirmed = await ctx.ui.confirm(
|
|
236
157
|
"Apply configuration from disk?",
|
|
237
158
|
candidate.loaded.rawDocument === undefined
|
|
238
|
-
? "
|
|
159
|
+
? "Show Pi's native footer for this session? No settings file will be created."
|
|
239
160
|
: "Apply the validated settings document to this session without changing its bytes? The previous loaded document will be kept in History.",
|
|
240
161
|
{ signal: owner.signal },
|
|
241
162
|
);
|
|
@@ -340,7 +261,7 @@ function reloadPreviewBody(
|
|
|
340
261
|
`Source: ${presentation.source}`,
|
|
341
262
|
`Path: ${sanitizeTerminalText(options.settingsPath)}`,
|
|
342
263
|
loaded.rawDocument === undefined
|
|
343
|
-
? "Applying
|
|
264
|
+
? "Applying shows Pi's native footer and creates no settings file."
|
|
344
265
|
: "Applying changes only the active session; the settings document bytes stay unchanged.",
|
|
345
266
|
...diagnosticLines(loaded, true),
|
|
346
267
|
"",
|
|
@@ -348,9 +269,9 @@ function reloadPreviewBody(
|
|
|
348
269
|
];
|
|
349
270
|
}
|
|
350
271
|
|
|
351
|
-
export function diagnosticLines(loaded: LoadedStarshipConfig, includeSummary: boolean): string[] {
|
|
272
|
+
export function diagnosticLines(loaded: LoadedStarshipConfig, includeSummary: boolean, limit = 8): string[] {
|
|
352
273
|
const diagnostics = loaded.diagnostics
|
|
353
|
-
.slice(0,
|
|
274
|
+
.slice(0, limit)
|
|
354
275
|
.map((item) => `${sanitizeTerminalText(item.path || "root")}: ${sanitizeTerminalText(item.message)}`);
|
|
355
276
|
const remaining = loaded.diagnostics.length - diagnostics.length;
|
|
356
277
|
return [
|
package/src/command-preview.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { stripVTControlCharacters } from "node:util";
|
|
2
|
-
import type { ExtensionCommandContext, KeybindingsManager } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { ExtensionCommandContext, KeybindingsManager, Theme } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import { Key, matchesKey, truncateToWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
4
4
|
import { runCustomInteraction } from "@narumitw/pi-tui-kit";
|
|
5
5
|
|
|
@@ -18,7 +18,7 @@ export type PreviewMenuResult<Value extends string> =
|
|
|
18
18
|
export async function showPreviewActionMenu<Value extends string>(
|
|
19
19
|
ctx: ExtensionCommandContext,
|
|
20
20
|
title: string,
|
|
21
|
-
body: (width: number) => readonly string[],
|
|
21
|
+
body: (width: number, theme: Theme) => readonly string[],
|
|
22
22
|
items: readonly PreviewMenuItem<Value>[],
|
|
23
23
|
signal?: AbortSignal,
|
|
24
24
|
isCurrent: () => boolean = () => !signal?.aborted,
|
|
@@ -52,7 +52,7 @@ export async function showPreviewActionMenu<Value extends string>(
|
|
|
52
52
|
const safeWidth = Math.max(1, width);
|
|
53
53
|
const terminalRows = Number.isFinite(tui.terminal.rows) ? Math.floor(tui.terminal.rows) : 24;
|
|
54
54
|
const availableRows = Math.max(1, terminalRows - RESERVED_HOST_ROWS);
|
|
55
|
-
const bodyLines = body(safeWidth).flatMap((line) => (line ? wrapTextWithAnsi(line, safeWidth) : [""]));
|
|
55
|
+
const bodyLines = body(safeWidth, theme).flatMap((line) => (line ? wrapTextWithAnsi(line, safeWidth) : [""]));
|
|
56
56
|
const layout = allocateLayout(availableRows, items.length, bodyLines.length);
|
|
57
57
|
lastViewportSize = layout.previewRows;
|
|
58
58
|
lastMaximumScroll = Math.max(0, bodyLines.length - layout.previewRows);
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { withFileMutationQueue } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
|
|
4
|
+
import { sanitizeTerminalDocument } from "@narumitw/pi-tui-kit/terminal-document";
|
|
5
|
+
import { captureCommitExpectation, commitActiveDocument, commitOwnerCurrent } from "./command-commit.js";
|
|
6
|
+
import type { WorkflowOwner } from "./command-configuration.js";
|
|
7
|
+
import { saveAsProfile } from "./command-profiles.js";
|
|
8
|
+
import type { StarshipCommandOptions } from "./commands.js";
|
|
9
|
+
import { assertProfileUnchanged } from "./profile-store.js";
|
|
10
|
+
import { createSettingsAgent, starshipPackageRoot } from "./settings-agent.js";
|
|
11
|
+
import { type ChatViewState, showSettingsChat } from "./settings-chat-ui.js";
|
|
12
|
+
import { createSettingsDraft } from "./settings-draft.js";
|
|
13
|
+
import { settingsSnapshots } from "./settings-snapshots.js";
|
|
14
|
+
|
|
15
|
+
export async function showSettingsAgentChat(
|
|
16
|
+
ctx: ExtensionCommandContext,
|
|
17
|
+
options: StarshipCommandOptions,
|
|
18
|
+
base: WorkflowOwner,
|
|
19
|
+
): Promise<"applied" | "close"> {
|
|
20
|
+
if (ctx.mode !== "tui" || base.signal.aborted || !base.isCurrent()) return "close";
|
|
21
|
+
const expected = await withFileMutationQueue(options.settingsPath, async () => {
|
|
22
|
+
if (base.signal.aborted || !base.isCurrent()) return undefined;
|
|
23
|
+
return captureCommitExpectation(options);
|
|
24
|
+
});
|
|
25
|
+
if (!expected || base.signal.aborted || !base.isCurrent()) return "close";
|
|
26
|
+
const owner: WorkflowOwner = {
|
|
27
|
+
signal: base.signal,
|
|
28
|
+
isCurrent: () => commitOwnerCurrent(options, base, expected),
|
|
29
|
+
isSessionCurrent: base.isSessionCurrent ?? base.isCurrent,
|
|
30
|
+
};
|
|
31
|
+
const packageRoot = starshipPackageRoot();
|
|
32
|
+
const draft = createSettingsDraft({
|
|
33
|
+
settingsPath: options.settingsPath,
|
|
34
|
+
baseline: expected.disk.rawBytes,
|
|
35
|
+
snapshots: settingsSnapshots(expected.previous, options.settingsPath, options.getInspection?.()),
|
|
36
|
+
packageRoot,
|
|
37
|
+
isCurrent: owner.isCurrent,
|
|
38
|
+
onPreview: (loaded) => {
|
|
39
|
+
if (owner.isCurrent()) options.preview?.(loaded, ctx);
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
let agent: ReturnType<typeof createSettingsAgent> | undefined;
|
|
43
|
+
let closing: Promise<void> | undefined;
|
|
44
|
+
const cleanup = () => {
|
|
45
|
+
if (closing) return closing;
|
|
46
|
+
agent?.abort();
|
|
47
|
+
closing = (async () => {
|
|
48
|
+
try {
|
|
49
|
+
await agent?.waitForIdle();
|
|
50
|
+
} finally {
|
|
51
|
+
agent?.reset();
|
|
52
|
+
draft.dispose();
|
|
53
|
+
}
|
|
54
|
+
})();
|
|
55
|
+
return closing;
|
|
56
|
+
};
|
|
57
|
+
const abort = () => {
|
|
58
|
+
agent?.abort();
|
|
59
|
+
};
|
|
60
|
+
const unregister = options.registerChatCleanup?.(cleanup);
|
|
61
|
+
owner.signal.addEventListener("abort", abort, { once: true });
|
|
62
|
+
const state: ChatViewState = { input: "", error: "" };
|
|
63
|
+
const preview = (width: number) => {
|
|
64
|
+
const candidate = draft.candidate;
|
|
65
|
+
return candidate
|
|
66
|
+
? (options.renderPreview?.(candidate, width, ctx) ?? ["Footer preview unavailable"])
|
|
67
|
+
: ["Invalid draft; the last valid footer preview is retained."];
|
|
68
|
+
};
|
|
69
|
+
try {
|
|
70
|
+
if (!owner.isCurrent()) return "close";
|
|
71
|
+
agent = createSettingsAgent(ctx, draft, packageRoot);
|
|
72
|
+
while (owner.isCurrent()) {
|
|
73
|
+
const action = await showSettingsChat(ctx, agent, draft, state, owner, preview);
|
|
74
|
+
if (!owner.isCurrent() || action === "discard") return "close";
|
|
75
|
+
if (!draft.candidate) continue;
|
|
76
|
+
const candidate = draft.candidate;
|
|
77
|
+
const revision = draft.revision;
|
|
78
|
+
const reviewed = await reviewText(ctx, owner, "Review draft before saving", candidate.rawDocument ?? "", true);
|
|
79
|
+
if (!owner.isCurrent() || !reviewed) return "close";
|
|
80
|
+
draft.assertRevision(revision);
|
|
81
|
+
const saved = await saveAsProfile(
|
|
82
|
+
ctx,
|
|
83
|
+
options,
|
|
84
|
+
{ ...owner, isCurrent: () => owner.isCurrent() && draft.revision === revision },
|
|
85
|
+
candidate.rawDocument ?? "",
|
|
86
|
+
);
|
|
87
|
+
if (!owner.isCurrent() || saved === "close") return "close";
|
|
88
|
+
draft.assertRevision(revision);
|
|
89
|
+
if (!saved) continue;
|
|
90
|
+
const repair = expected.previous.diagnostics.some((item) => item.severity === "error");
|
|
91
|
+
const confirmed = await ctx.ui.confirm(
|
|
92
|
+
"Apply saved profile?",
|
|
93
|
+
[
|
|
94
|
+
`Profile saved: ${sanitizeTerminalDocument(saved.name)}. Apply it to the current footer without reload?`,
|
|
95
|
+
"This replaces the complete active settings document. Declining keeps the profile and leaves active settings unchanged.",
|
|
96
|
+
"Applying can run enabled module commands and network requests; review their configuration before accepting.",
|
|
97
|
+
"The previous file is retained in History. Detected concurrent edits block replacement.",
|
|
98
|
+
...(repair ? ["The original settings document is invalid. Confirm only if you requested its repair."] : []),
|
|
99
|
+
...candidate.diagnostics.map((item) => `${item.severity}: ${item.path}: ${item.message}`),
|
|
100
|
+
].join("\n"),
|
|
101
|
+
{ signal: owner.signal },
|
|
102
|
+
);
|
|
103
|
+
if (!owner.isCurrent()) return "close";
|
|
104
|
+
if (!confirmed) return "close";
|
|
105
|
+
try {
|
|
106
|
+
const result = await commitActiveDocument(ctx, options, candidate, owner, expected, repair, () => {
|
|
107
|
+
draft.assertRevision(revision);
|
|
108
|
+
assertProfileUnchanged(options.settingsPath, saved);
|
|
109
|
+
});
|
|
110
|
+
if (result === "applied") return "applied";
|
|
111
|
+
return "close";
|
|
112
|
+
} catch (error) {
|
|
113
|
+
if (!base.signal.aborted && base.isCurrent())
|
|
114
|
+
ctx.ui.notify(
|
|
115
|
+
`Profile was saved as ${sanitizeTerminalDocument(saved.name)}. Settings were not applied: ${sanitizeTerminalDocument(error instanceof Error ? error.message : String(error))}`,
|
|
116
|
+
"error",
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return "close";
|
|
121
|
+
} finally {
|
|
122
|
+
owner.signal.removeEventListener("abort", abort);
|
|
123
|
+
try {
|
|
124
|
+
await cleanup();
|
|
125
|
+
} finally {
|
|
126
|
+
unregister?.();
|
|
127
|
+
// Hard cancellation ends the command owner, not its session. Clear the owned
|
|
128
|
+
// preview even after Ctrl+C, but never redraw a replaced or shut-down session.
|
|
129
|
+
if (base.isSessionCurrent?.() ?? base.isCurrent()) options.preview?.(undefined, ctx);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async function reviewText(
|
|
135
|
+
ctx: ExtensionCommandContext,
|
|
136
|
+
owner: WorkflowOwner,
|
|
137
|
+
title: string,
|
|
138
|
+
content: string,
|
|
139
|
+
toml: boolean,
|
|
140
|
+
) {
|
|
141
|
+
let continued = false;
|
|
142
|
+
const menu = defineMenu<undefined, "review", "continue", ExtensionCommandContext>({
|
|
143
|
+
start: "review",
|
|
144
|
+
screens: {
|
|
145
|
+
review: () => ({
|
|
146
|
+
kind: "review",
|
|
147
|
+
title,
|
|
148
|
+
content,
|
|
149
|
+
enableSearch: true,
|
|
150
|
+
format: toml ? { kind: "code", language: "toml" } : { kind: "text" },
|
|
151
|
+
confirm: { id: "continue", label: "Continue", action: "continue" },
|
|
152
|
+
hint: "close",
|
|
153
|
+
}),
|
|
154
|
+
},
|
|
155
|
+
actions: {
|
|
156
|
+
continue: () => {
|
|
157
|
+
continued = true;
|
|
158
|
+
return { kind: "close" };
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
const result = await runMenu(ctx, menu, {
|
|
163
|
+
getState: () => undefined,
|
|
164
|
+
signal: owner.signal,
|
|
165
|
+
isCurrent: owner.isCurrent,
|
|
166
|
+
});
|
|
167
|
+
return result.kind === "closed" && continued;
|
|
168
|
+
}
|