@narumitw/pi-starship 0.62.0 → 0.64.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.
Files changed (34) hide show
  1. package/README.md +23 -11
  2. package/dist/chunks/{chunk-PWTSHSP3.ts → chunk-A65IOGL6.ts} +6 -7
  3. package/dist/chunks/chunk-A65IOGL6.ts.map +7 -0
  4. package/dist/chunks/{chunk-HPZTMIZS.ts → chunk-DIHVBO5Z.ts} +41 -8
  5. package/dist/chunks/chunk-DIHVBO5Z.ts.map +7 -0
  6. package/dist/chunks/{chunk-43VIENBN.ts → chunk-UIKPE4UC.ts} +7 -7
  7. package/dist/chunks/{chunk-43VIENBN.ts.map → chunk-UIKPE4UC.ts.map} +2 -2
  8. package/dist/chunks/{command-configuration-menu-S2LXCOJG.ts → command-configuration-menu-ZN2VXU4L.ts} +3 -3
  9. package/dist/chunks/{command-settings-chat-O34BEU4X.ts → command-settings-chat-KLUVZXMO.ts} +632 -196
  10. package/dist/chunks/command-settings-chat-KLUVZXMO.ts.map +7 -0
  11. package/dist/chunks/{commands-ZYIJVIEJ.ts → commands-UAUSSHVS.ts} +25 -20
  12. package/dist/chunks/commands-UAUSSHVS.ts.map +7 -0
  13. package/dist/index.ts +116 -59
  14. package/dist/index.ts.map +3 -3
  15. package/package.json +1 -1
  16. package/skills/configure-pi-starship/SKILL.md +3 -1
  17. package/skills/configure-pi-starship/references/configuration.md +14 -12
  18. package/src/command-commit.ts +41 -7
  19. package/src/command-configuration.ts +8 -10
  20. package/src/command-settings-chat.ts +18 -48
  21. package/src/commands.ts +23 -26
  22. package/src/config.ts +6 -6
  23. package/src/pi-starship.ts +155 -88
  24. package/src/settings-chat-display.ts +11 -0
  25. package/src/settings-chat-fullscreen.ts +264 -0
  26. package/src/settings-chat-scroll.ts +17 -0
  27. package/src/settings-chat-tools.ts +207 -0
  28. package/src/settings-chat-transcript.ts +133 -62
  29. package/src/settings-chat-ui.ts +109 -98
  30. package/dist/chunks/chunk-HPZTMIZS.ts.map +0 -7
  31. package/dist/chunks/chunk-PWTSHSP3.ts.map +0 -7
  32. package/dist/chunks/command-settings-chat-O34BEU4X.ts.map +0 -7
  33. package/dist/chunks/commands-ZYIJVIEJ.ts.map +0 -7
  34. /package/dist/chunks/{command-configuration-menu-S2LXCOJG.ts.map → command-configuration-menu-ZN2VXU4L.ts.map} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narumitw/pi-starship",
3
- "version": "0.62.0",
3
+ "version": "0.64.0",
4
4
  "description": "Native Starship-style TOML statusline and configuration skill for Pi.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -81,7 +81,9 @@ Do not install another Pi copy, modify `node_modules`, hard-code a Bun global di
81
81
 
82
82
  Read the existing document before editing it.
83
83
 
84
- Treat a missing document as built-in defaults, and create it only when the requested change requires a persisted configuration.
84
+ Treat a missing document as Pi's native footer, and create it only when the requested change requires a persisted Starship configuration.
85
+ Use the built-in Starship example as an editing seed, not as a document equivalent to Pi's native footer.
86
+ The menu action **Restore built-in…** archives the exact active bytes in History and removes the settings document; a saved built-in Starship example remains eligible for Restore.
85
87
 
86
88
  Do not redirect this workflow to `starship.toml`, `pi-statusline.json`, project-local overrides, or extension source files.
87
89
 
@@ -10,8 +10,9 @@ The only configuration source is:
10
10
  <getAgentDir()>/pi-starship.toml
11
11
  ```
12
12
 
13
- When this file is absent, the extension uses its palette-free default without creating the file or its parent directory.
14
- The built-in root is the explicit sequence `$brand$model$thinking$directory` `$git_branch$git_status$activity$context$time`; it does not start the opt-in GitHub PR query.
13
+ When this file is absent, the extension uses Pi's native footer without creating the file or its parent directory.
14
+ The built-in Starship example remains an editing seed; saving it enables a Starship footer, not Pi's native footer.
15
+ Its root is the explicit sequence `$brand$model$thinking$directory` `$git_branch$git_status$activity$context$time`; it does not start the opt-in GitHub PR query.
15
16
  The first successful settings save creates the file atomically.
16
17
  Existing malformed documents are never overwritten.
17
18
 
@@ -41,19 +42,18 @@ The ordinary main-session skill has no live runtime access; direct active-state
41
42
  The preview uses cached data without starting module commands or network requests.
42
43
  During a response, normal submission queues steering for the next assistant turn; the configured app.message.followUp action queues work after natural completion and submits normally when idle.
43
44
  The app.message.dequeue action restores pending messages to the editor; these message actions use Pi's native precedence, including explicit history bindings.
44
- The configured cancel action stops a response and restores undelivered messages, or opens review when idle; editor actions win review-key collisions, with Escape as a review fallback unless assigned to an editor action.
45
+ The configured cancel action stops a response and restores undelivered messages; when idle, it leaves the conversation open without opening a menu. Editor actions win cancel-key collisions, with Escape as a stop fallback unless assigned to an editor action.
45
46
  Failed or aborted responses restore undelivered input without automatic restart.
46
47
  Ctrl+C discards the flow, clears both queues, and restores the active footer unless its session was replaced.
47
48
  When idle with a valid draft, Ctrl+S opens the Save draft as profile flow directly; its gray editor-border hint switches to F2 if Ctrl+S is reserved, or is omitted when both keys conflict.
48
- The review menu retains the same save action.
49
49
  Saving requires exact-draft review and a profile name; invalid or existing names are rejected without overwriting a profile.
50
50
  After saving, the host asks whether to apply that profile through managed History and atomic replacement; declining keeps the profile without changing active settings.
51
51
  Cancelling naming returns to the chat without saving; closing or session replacement removes the temporary draft, not any saved profile.
52
52
  Application checks the initial disk snapshot, loaded revision, and saved profile identity, blocks detected concurrent changes, and warns before explicitly repairing an invalid original.
53
53
  Chat content and settings read by the agent go to the selected model provider; the child uses the opening model/thinking selection with Pi authentication, has no shell tool, and does not persist its transcript or change the main conversation.
54
54
  The fullscreen view uses Pi's native user/assistant/tool message components. Short gray status and control labels sit on the editor borders; the live preview ends at the terminal bottom, in the saved footer's position.
55
- It shows recent output with expanded, read-only tool results; review actions expose the complete transcript and exact draft.
56
- Choose **Continue** to leave a document/transcript review; cancelling the review discards the flow without publishing.
55
+ It shows recent output with expanded, read-only tool results; saving opens an exact-draft review.
56
+ Choose **Continue** to leave the save review; cancelling the review discards the flow without publishing.
57
57
 
58
58
  Outside this hosted chat, the bundled `configure-pi-starship` skill uses a separate external-edit workflow.
59
59
  Before its apply script replaces an existing document, it preserves the inspected document under `<getAgentDir()>/pi-starship/pi-starship-YYYYMMDDHHmm.toml`; these backups use local time and remain after a successful apply.
@@ -69,13 +69,15 @@ The focused action remains visible at small terminal heights; enlarge an extreme
69
69
  Gist actions use `gh` authentication for github.com and transfer only `pi-starship.toml`, limited to 64 KiB; sharing includes comments and unknown fields and requires review and confirmation before creating an unlisted Gist.
70
70
  Unlisted Gists are readable by anyone with the link; remove sensitive data before sharing, and check GitHub before retrying a cancelled or failed upload because a remote Gist may already exist.
71
71
  Import accepts a Gist ID or URL, validates the complete document, requires raw TOML review, footer preview, and full-replacement confirmation, and preserves the previous document before applying; review untrusted settings for command execution and network access before accepting.
72
- A missing file is **Built-in defaults**, an exact bundled document uses its preset name, and read or parse errors are **Built-in fallback**.
72
+ A missing file uses Pi's native footer, an exact bundled document uses its preset name, and read or parse errors are **Built-in fallback**.
73
73
  Reload from disk reads only after the explicit action, validates and previews the current external state from the existing runtime snapshot, and asks for separate confirmation before changing the active session.
74
- A deleted document is a valid previewable transition to built-in defaults and creates no file.
74
+ A deleted document is a valid previewable transition to Pi's native footer and creates no file.
75
75
  An unchanged document is a no-op, while read or parse failure, cancellation, disposal, external changes after preview, session replacement, shutdown, or runtime apply failure preserves the prior effective footer and every file byte.
76
76
  Reload re-reads immediately after confirmation and rejects a different external snapshot; it does not claim cross-process locking or continuing synchronization with later edits.
77
- Restore is disabled when no settings document exists or the exact built-in document is already saved.
78
- For a custom or invalid document, Restore previews the result and warns that the complete document, including custom settings, unknown fields, and comments, will be replaced before asking for confirmation. The previous bytes are preserved first, including invalid content on an explicit recovery path.
77
+ **Restore built-in…** remains in the main menu and is disabled only when no settings document exists.
78
+ A saved built-in Starship example is not Pi's native footer and can be restored.
79
+ Restore previews Pi's native footer and asks for confirmation before archiving the exact document bytes in History and removing the active settings document, including custom settings, unknown fields, and comments.
80
+ Invalid content is preserved through the explicit recovery path.
79
81
 
80
82
  ### Named profiles
81
83
 
@@ -405,7 +407,7 @@ See [Git status behavior](modules.md#git-display-controls-and-status-templates)
405
407
 
406
408
  | Failure | Result |
407
409
  | --- | --- |
408
- | Missing file | Use built-in defaults without creating a file or directory. |
410
+ | Missing file | Use Pi's native footer without creating a file or directory. |
409
411
  | Read failure | Use built-in defaults and report an error diagnostic. |
410
412
  | TOML syntax failure | Preserve the raw document, use built-in defaults, and report an error diagnostic. |
411
413
  | Unknown root, module, option, or display field | Warn, ignore that field, and keep processing the document. |
@@ -631,6 +633,6 @@ Choose one migration:
631
633
 
632
634
  1. Replace old aliases with direct styles such as `cyan bold`, `bold bright-yellow`, or `fg:#e3e5e5 bg:#769ff0`.
633
635
  2. Define every needed alias under your own `[palettes.<name>]` table and explicitly select it with `palette = "<name>"`.
634
- 3. Use **Restore built-in…** from `/starship` to review and replace the complete document with the new plain nine-module configuration.
636
+ 3. Use **Restore built-in…** from `/starship` to archive the complete document in History, remove the active settings file, and return to Pi's native footer.
635
637
 
636
638
  There is no hidden compatibility overlay or automatic migration.
@@ -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 (raw === undefined) throw new Error("The candidate settings document is unavailable");
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
- validateConfigDocument(options.settingsPath, raw);
79
- if (previousBytes?.equals(Buffer.from(raw))) return "applied";
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
- saved = options.save
96
- ? options.save(options.settingsPath, raw)
97
- : atomicSaveConfigDocument(options.settingsPath, raw, {}, expected.disk);
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) {
@@ -22,6 +22,8 @@ export interface WorkflowOwner {
22
22
  isCurrent(): boolean;
23
23
  /** Session ownership independent of command cancellation and candidate/revision guards. */
24
24
  isSessionCurrent?(): boolean;
25
+ /** The shared parent terminal can remain live after its session context changes. */
26
+ canRestoreTerminal?(): boolean;
25
27
  }
26
28
 
27
29
  export interface ConfigurationCommandOptions {
@@ -49,7 +51,7 @@ export function configurationPresentation(loaded: LoadedStarshipConfig): Configu
49
51
  const fallback = loaded.source === "built-in" && loaded.diagnostics.length > 0;
50
52
  return {
51
53
  state: healthyMissing
52
- ? "Built-in defaults"
54
+ ? "Pi native footer"
53
55
  : savedBuiltIn
54
56
  ? "Saved built-in configuration"
55
57
  : activePreset
@@ -65,14 +67,10 @@ export function configurationPresentation(loaded: LoadedStarshipConfig): Configu
65
67
  ? "User file"
66
68
  : "Built-in fallback",
67
69
  health: configurationHealth(loaded),
68
- restoreDisabled: healthyMissing || savedBuiltIn,
70
+ restoreDisabled: healthyMissing,
69
71
  restoreDescription: healthyMissing
70
- ? "Already using defaults · no file to replace"
71
- : savedBuiltIn
72
- ? "Built-in configuration already saved"
73
- : fallback
74
- ? "Preview before replacing invalid settings"
75
- : "Preview before replacing the document",
72
+ ? "Already using Pi native footer · no file to remove"
73
+ : "Preview before restoring Pi native footer",
76
74
  };
77
75
  }
78
76
 
@@ -160,7 +158,7 @@ export async function reloadConfiguration(
160
158
  const confirmed = await ctx.ui.confirm(
161
159
  "Apply configuration from disk?",
162
160
  candidate.loaded.rawDocument === undefined
163
- ? "Use built-in defaults for this session? No settings file will be created."
161
+ ? "Show Pi's native footer for this session? No settings file will be created."
164
162
  : "Apply the validated settings document to this session without changing its bytes? The previous loaded document will be kept in History.",
165
163
  { signal: owner.signal },
166
164
  );
@@ -265,7 +263,7 @@ function reloadPreviewBody(
265
263
  `Source: ${presentation.source}`,
266
264
  `Path: ${sanitizeTerminalText(options.settingsPath)}`,
267
265
  loaded.rawDocument === undefined
268
- ? "Applying uses built-in defaults and creates no settings file."
266
+ ? "Applying shows Pi's native footer and creates no settings file."
269
267
  : "Applying changes only the active session; the settings document bytes stay unchanged.",
270
268
  ...diagnosticLines(loaded, true),
271
269
  "",
@@ -4,17 +4,11 @@ import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
4
4
  import { sanitizeTerminalDocument } from "@narumitw/pi-tui-kit/terminal-document";
5
5
  import { captureCommitExpectation, commitActiveDocument, commitOwnerCurrent } from "./command-commit.js";
6
6
  import type { WorkflowOwner } from "./command-configuration.js";
7
- import { showPreviewActionMenu } from "./command-preview.js";
8
7
  import { saveAsProfile } from "./command-profiles.js";
9
8
  import type { StarshipCommandOptions } from "./commands.js";
10
9
  import { assertProfileUnchanged } from "./profile-store.js";
11
10
  import { createSettingsAgent, starshipPackageRoot } from "./settings-agent.js";
12
- import {
13
- type ChatViewState,
14
- renderSettingsChatPreview,
15
- settingsChatTranscript,
16
- showSettingsChat,
17
- } from "./settings-chat-ui.js";
11
+ import { type ChatViewState, type SettingsChatAction, showSettingsChat } from "./settings-chat-ui.js";
18
12
  import { createSettingsDraft } from "./settings-draft.js";
19
13
  import { settingsSnapshots } from "./settings-snapshots.js";
20
14
 
@@ -29,10 +23,12 @@ export async function showSettingsAgentChat(
29
23
  return captureCommitExpectation(options);
30
24
  });
31
25
  if (!expected || base.signal.aborted || !base.isCurrent()) return "close";
26
+ const chatLifetime = new AbortController();
32
27
  const owner: WorkflowOwner = {
33
- signal: base.signal,
34
- isCurrent: () => commitOwnerCurrent(options, base, expected),
28
+ signal: AbortSignal.any([base.signal, chatLifetime.signal]),
29
+ isCurrent: () => !chatLifetime.signal.aborted && commitOwnerCurrent(options, base, expected),
35
30
  isSessionCurrent: base.isSessionCurrent ?? base.isCurrent,
31
+ canRestoreTerminal: base.canRestoreTerminal,
36
32
  };
37
33
  const packageRoot = starshipPackageRoot();
38
34
  const draft = createSettingsDraft({
@@ -47,12 +43,16 @@ export async function showSettingsAgentChat(
47
43
  });
48
44
  let agent: ReturnType<typeof createSettingsAgent> | undefined;
49
45
  let closing: Promise<void> | undefined;
46
+ let activeChat: Promise<SettingsChatAction> | undefined;
50
47
  const cleanup = () => {
51
48
  if (closing) return closing;
49
+ chatLifetime.abort();
52
50
  agent?.abort();
51
+ const pendingChat = activeChat;
53
52
  closing = (async () => {
54
53
  try {
55
- await agent?.waitForIdle();
54
+ // Shutdown must join terminal teardown, not only the model request.
55
+ await Promise.all([agent?.waitForIdle(), pendingChat]);
56
56
  } finally {
57
57
  agent?.reset();
58
58
  draft.dispose();
@@ -76,45 +76,15 @@ export async function showSettingsAgentChat(
76
76
  if (!owner.isCurrent()) return "close";
77
77
  agent = createSettingsAgent(ctx, draft, packageRoot);
78
78
  while (owner.isCurrent()) {
79
- const action = await showSettingsChat(ctx, agent, draft, state, owner, preview);
80
- if (!owner.isCurrent() || action === "discard") return "close";
81
- const result =
82
- action === "save"
83
- ? { kind: "selected" as const, value: "save" as const }
84
- : await showPreviewActionMenu(
85
- ctx,
86
- "Configuration chat — preview only",
87
- (width, theme) => [
88
- "The agent has not changed the active settings file.",
89
- "Preview uses cached data; enabling modules here does not run commands or network requests.",
90
- ...renderSettingsChatPreview(width, preview(width), theme),
91
- ...sanitizeTerminalDocument(draft.diagnostics).split("\n"),
92
- ],
93
- [
94
- { value: "continue", label: "Continue conversation" },
95
- { value: "document", label: "Review exact draft…" },
96
- { value: "transcript", label: "Review full conversation…" },
97
- ...(draft.candidate ? [{ value: "save" as const, label: "Save draft as profile…" }] : []),
98
- { value: "discard", label: "Discard preview and close" },
99
- ],
100
- owner.signal,
101
- owner.isCurrent,
102
- );
103
- if (!owner.isCurrent() || !result || result.kind === "closed") return "close";
104
- if (result?.kind !== "selected") continue;
105
- if (result.value === "discard") return "close";
106
- if (result.value === "document" || result.value === "transcript") {
107
- const reviewed = await reviewText(
108
- ctx,
109
- owner,
110
- result.value === "document" ? "Settings draft" : "Configuration conversation",
111
- result.value === "document" ? draft.rawDocument : settingsChatTranscript(agent).join("\n\n"),
112
- result.value === "document",
113
- );
114
- if (!owner.isCurrent() || !reviewed) return "close";
115
- continue;
79
+ activeChat = showSettingsChat(ctx, agent, draft, state, owner, preview);
80
+ let action: SettingsChatAction;
81
+ try {
82
+ action = await activeChat;
83
+ } finally {
84
+ activeChat = undefined;
116
85
  }
117
- if (result.value !== "save" || !draft.candidate) continue;
86
+ if (!owner.isCurrent() || action === "discard") return "close";
87
+ if (!draft.candidate) continue;
118
88
  const candidate = draft.candidate;
119
89
  const revision = draft.revision;
120
90
  const reviewed = await reviewText(ctx, owner, "Review draft before saving", candidate.rawDocument ?? "", true);
package/src/commands.ts CHANGED
@@ -19,7 +19,7 @@ import { importSettingsGist, shareSettingsGist } from "./command-gist.js";
19
19
  import { showPresetPicker } from "./command-preset-picker.js";
20
20
  import { type PreviewMenuResult, showPreviewActionMenu } from "./command-preview.js";
21
21
  import { saveAsProfile, showHistory, showProfiles } from "./command-profiles.js";
22
- import { BUILT_IN_EXAMPLE, type LoadedStarshipConfig, validateConfigDocument } from "./config.js";
22
+ import { BUILT_IN_EXAMPLE, type LoadedStarshipConfig, nativeFooterConfig, validateConfigDocument } from "./config.js";
23
23
  import type { GhApi } from "./gist.js";
24
24
  import type { StatuslineInspection } from "./modules/inspection.js";
25
25
  import { getStarshipPreset, presetForDocument, STARSHIP_PRESETS, type StarshipPreset } from "./presets/catalog.js";
@@ -81,6 +81,7 @@ export async function handleStarshipCommand(
81
81
  signal,
82
82
  isCurrent: () => !signal.aborted && base.isCurrent(),
83
83
  isSessionCurrent: () => base.isSessionCurrent?.() ?? base.isCurrent(),
84
+ canRestoreTerminal: base.canRestoreTerminal,
84
85
  };
85
86
  // Pi delivers bracketed paste as one framed packet. Exact key matching does
86
87
  // not treat controls inside pasted text as cancellation or consume native input.
@@ -502,8 +503,8 @@ async function restoreBuiltIn(
502
503
  ): Promise<"applied" | "cancel" | "close"> {
503
504
  const owner = workflowOwner(options);
504
505
  if (!isCurrentOwner(owner)) return "cancel";
505
- const validated = (options.validate ?? validateConfigDocument)(options.settingsPath, BUILT_IN_EXAMPLE);
506
- const result = await reviewAndApply(ctx, options, validated, { kind: "restore" }, owner);
506
+ const candidate = nativeFooterConfig(options.settingsPath);
507
+ const result = await reviewAndApply(ctx, options, candidate, { kind: "restore" }, owner);
507
508
  return result === "edit" ? "cancel" : result;
508
509
  }
509
510
 
@@ -588,6 +589,7 @@ export async function reviewAndApply(
588
589
  expected,
589
590
  intent.kind === "restore" || intent.kind === "history" || intent.kind === "customize",
590
591
  checkCandidate,
592
+ intent.kind === "restore",
591
593
  );
592
594
  if (!isSessionOwnerCurrent(owner) || result === "cancel") return "cancel";
593
595
  } catch (error) {
@@ -628,7 +630,7 @@ function continueLabel(intent: ReviewIntent): string {
628
630
  case "customize":
629
631
  return "Apply changes…";
630
632
  case "restore":
631
- return "Replace with built-in…";
633
+ return "Restore Pi native footer…";
632
634
  case "import":
633
635
  return "Replace with Gist settings…";
634
636
  case "profile":
@@ -645,7 +647,7 @@ function confirmationTitle(intent: ReviewIntent): string {
645
647
  case "customize":
646
648
  return "Apply footer changes?";
647
649
  case "restore":
648
- return "Restore built-in footer?";
650
+ return "Restore Pi native footer?";
649
651
  case "import":
650
652
  return "Replace settings with Gist?";
651
653
  case "profile":
@@ -658,21 +660,21 @@ function confirmationTitle(intent: ReviewIntent): string {
658
660
  }
659
661
 
660
662
  function confirmationMessage(settingsPath: string, intent: ReviewIntent, previous: LoadedStarshipConfig): string {
663
+ if (intent.kind === "restore")
664
+ return `Remove ${safeText(settingsPath)} and show Pi's native footer? The exact previous document, including invalid settings, unknown fields, and comments, will be kept in History.`;
661
665
  if (previous.diagnostics.some((item) => item.severity === "error")) {
662
666
  return `Explicit recovery: replace the invalid settings file ${safeText(settingsPath)} entirely with the reviewed document? Its exact original bytes will be kept in History before replacement.`;
663
667
  }
664
668
  if (intent.kind === "customize")
665
669
  return "Replace the entire settings document and apply it immediately? Its previous bytes will be kept in History.";
666
670
  const replacement =
667
- intent.kind === "restore"
668
- ? "the built-in configuration"
669
- : intent.kind === "import"
670
- ? "the reviewed Gist settings"
671
- : intent.kind === "profile"
672
- ? `the ${safeText(intent.name)} profile`
673
- : intent.kind === "history"
674
- ? "the reviewed history document"
675
- : `the ${intent.preset.label} preset`;
671
+ intent.kind === "import"
672
+ ? "the reviewed Gist settings"
673
+ : intent.kind === "profile"
674
+ ? `the ${safeText(intent.name)} profile`
675
+ : intent.kind === "history"
676
+ ? "the reviewed history document"
677
+ : `the ${intent.preset.label} preset`;
676
678
  return `Replace ${safeText(settingsPath)} entirely with ${replacement}? All custom settings, unknown fields, and comments will be replaced. The previous document will be kept in History.`;
677
679
  }
678
680
 
@@ -681,7 +683,7 @@ function successMessage(intent: ReviewIntent): string {
681
683
  case "customize":
682
684
  return "Footer settings saved and applied";
683
685
  case "restore":
684
- return "Built-in footer restored and applied";
686
+ return "Pi native footer restored and applied";
685
687
  case "import":
686
688
  return "Gist settings saved and applied";
687
689
  case "profile":
@@ -730,7 +732,7 @@ function reviewPreviewBody(
730
732
  width: number,
731
733
  intent: ReviewIntent,
732
734
  ): string[] {
733
- if (intent.kind === "restore") return restorePreviewBody(ctx, options, loaded, width);
735
+ if (intent.kind === "restore") return restorePreviewBody(options);
734
736
  if (intent.kind !== "preset") return previewBody(ctx, options, loaded, width);
735
737
  const current = configurationPresentation(options.getLoaded());
736
738
  return [
@@ -745,20 +747,15 @@ function reviewPreviewBody(
745
747
  ];
746
748
  }
747
749
 
748
- function restorePreviewBody(
749
- ctx: ExtensionCommandContext,
750
- options: StarshipCommandOptions,
751
- loaded: LoadedStarshipConfig,
752
- width: number,
753
- ): string[] {
750
+ function restorePreviewBody(options: StarshipCommandOptions): string[] {
754
751
  const current = configurationPresentation(options.getLoaded());
755
752
  return [
756
753
  `Current: ${current.state}`,
757
754
  `Path: ${safeText(options.settingsPath)}`,
758
- "The entire settings document will be replaced, including custom settings, unknown fields, and comments.",
759
- "The previous document will be kept in History before replacement.",
760
- "",
761
- ...previewBody(ctx, options, loaded, width),
755
+ "The entire settings document will be removed, including custom settings, unknown fields, and comments.",
756
+ "The previous document will be kept in History before removal.",
757
+ "Pi's native footer will be shown instead of the pi-starship footer.",
758
+ "No replacement settings file will be created.",
762
759
  ];
763
760
  }
764
761
 
package/src/config.ts CHANGED
@@ -115,6 +115,11 @@ export function settingsFilePath(agentDir: string): string {
115
115
  return join(agentDir, CONFIG_FILE_NAME);
116
116
  }
117
117
 
118
+ /** No active Starship document: Pi owns the footer. Module defaults remain available for new drafts. */
119
+ export function nativeFooterConfig(settingsPath: string): LoadedStarshipConfig {
120
+ return { config: cloneBuiltInConfig(), source: "built-in", settingsPath, diagnostics: [] };
121
+ }
122
+
118
123
  export function loadStarshipConfig(settingsPath: string): LoadedStarshipConfig {
119
124
  let rawDocument: string;
120
125
  let snapshot: ConfigDocumentSnapshot;
@@ -125,12 +130,7 @@ export function loadStarshipConfig(settingsPath: string): LoadedStarshipConfig {
125
130
  rawDocument = rawBytes.toString("utf8");
126
131
  } catch (error) {
127
132
  if ((error as NodeJS.ErrnoException).code === "ENOENT" && !existsSync(settingsPath)) {
128
- return {
129
- config: cloneBuiltInConfig(),
130
- source: "built-in",
131
- settingsPath,
132
- diagnostics: [],
133
- };
133
+ return nativeFooterConfig(settingsPath);
134
134
  }
135
135
  return {
136
136
  config: cloneBuiltInConfig(),