@narumitw/pi-starship 0.64.0 → 0.64.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/chunks/{chunk-DIHVBO5Z.ts → chunk-D563JANR.ts} +9 -4
- package/dist/chunks/{chunk-DIHVBO5Z.ts.map → chunk-D563JANR.ts.map} +2 -2
- package/dist/chunks/{command-settings-chat-KLUVZXMO.ts → command-settings-chat-B2FCDVBH.ts} +41 -58
- package/dist/chunks/command-settings-chat-B2FCDVBH.ts.map +7 -0
- package/dist/chunks/{commands-UAUSSHVS.ts → commands-SVLRVXUW.ts} +3 -3
- package/dist/index.ts +1 -1
- package/package.json +5 -5
- package/src/command-profiles.ts +10 -3
- package/src/settings-chat-fullscreen.ts +42 -65
- package/dist/chunks/command-settings-chat-KLUVZXMO.ts.map +0 -7
- /package/dist/chunks/{commands-UAUSSHVS.ts.map → commands-SVLRVXUW.ts.map} +0 -0
package/README.md
CHANGED
|
@@ -165,7 +165,7 @@ The parent TUI is suspended while the chat owns the shared terminal; only one re
|
|
|
165
165
|
Terminal ownership returns before the existing parent-hosted review, profile-name, and apply-confirmation screens open.
|
|
166
166
|
This intentionally deviates from Pi's guidance not to create a second terminal renderer in an extension: Starship uses a separate fullscreen host for native history scrolling and a fixed dock, with lifecycle tests required for safe ownership transfer.
|
|
167
167
|
It is not a claim of official support or a diagnosis or verified fix of the originally reported wheel/key failure.
|
|
168
|
-
See [Configuration chat runtime](https://github.com/narumiruna/pi-extensions/blob/main/packages/pi-starship/docs/configuration-chat-runtime.md) in the repository for ownership rules, verification evidence, and the maintainer's physical-terminal checklist.
|
|
168
|
+
See [Configuration chat runtime](https://github.com/narumiruna/pi-extensions/blob/main/packages/pi-starship/docs/configuration-chat-runtime.md) in the repository for ownership rules, verification evidence, and the maintainer's physical-terminal checklist. The [shared fullscreen handoff record](https://github.com/narumiruna/pi-extensions/blob/main/packages/pi-tui-kit/docs/fullscreen-handoff.md) records the Kit extraction's two-consumer proof, checks, and physical/release limits; it does not change chat permissions, input policy, or save behavior.
|
|
169
169
|
|
|
170
170
|
Your chat input, settings and runtime module snapshots read by the agent, local paths, and tool results are sent to the selected model provider.
|
|
171
171
|
Do not include secrets in the draft or conversation.
|
|
@@ -295,6 +295,7 @@ async function documentActions(ctx, options, flow, document, applyCandidate) {
|
|
|
295
295
|
const profile = document.kind === "profile";
|
|
296
296
|
const activeInvalid = profile && options.getLoaded().diagnostics.some((item) => item.severity === "error");
|
|
297
297
|
const action = await actionScreen(ctx, flow, {
|
|
298
|
+
kind: document.kind,
|
|
298
299
|
title: `${profile ? "Profile" : "Recovery copy"}: ${safe(document.name)}`,
|
|
299
300
|
lines: [
|
|
300
301
|
`Path: ${safe(document.path)}`,
|
|
@@ -314,8 +315,8 @@ async function documentActions(ctx, options, flow, document, applyCandidate) {
|
|
|
314
315
|
},
|
|
315
316
|
...profile ? [
|
|
316
317
|
{ id: "edit", label: "Edit TOML\u2026" },
|
|
317
|
-
{ id: "
|
|
318
|
-
{ id: "
|
|
318
|
+
{ id: "duplicate", label: "Duplicate\u2026" },
|
|
319
|
+
{ id: "rename", label: "Rename\u2026" }
|
|
319
320
|
] : [
|
|
320
321
|
{
|
|
321
322
|
id: "save-as",
|
|
@@ -497,6 +498,7 @@ async function actionScreen(ctx, flow, screen) {
|
|
|
497
498
|
title: screen.title,
|
|
498
499
|
lines: screen.lines,
|
|
499
500
|
items: [
|
|
501
|
+
...screen.kind === "profile" ? screen.actions.slice(0, 1).map((action) => ({ ...action, action: "select" })) : [],
|
|
500
502
|
{
|
|
501
503
|
id: "review",
|
|
502
504
|
label: "Review TOML",
|
|
@@ -504,7 +506,10 @@ async function actionScreen(ctx, flow, screen) {
|
|
|
504
506
|
disabled: screen.raw === void 0,
|
|
505
507
|
disabledReason: "The document is not valid UTF-8"
|
|
506
508
|
},
|
|
507
|
-
...screen.actions.map((action) => ({
|
|
509
|
+
...(screen.kind === "profile" ? screen.actions.slice(1) : screen.actions).map((action) => ({
|
|
510
|
+
...action,
|
|
511
|
+
action: "select"
|
|
512
|
+
}))
|
|
508
513
|
],
|
|
509
514
|
hint: "back"
|
|
510
515
|
}),
|
|
@@ -676,4 +681,4 @@ export {
|
|
|
676
681
|
showHistory,
|
|
677
682
|
saveAsProfile
|
|
678
683
|
};
|
|
679
|
-
//# sourceMappingURL=chunk-
|
|
684
|
+
//# sourceMappingURL=chunk-D563JANR.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/command-commit.ts", "../../src/command-profiles.ts"],
|
|
4
|
-
"sourcesContent": ["import { type ExtensionCommandContext, withFileMutationQueue } from \"@earendil-works/pi-coding-agent\";\nimport type { ConfigurationCommandOptions, WorkflowOwner } from \"./command-configuration.js\";\nimport {\n assertConfigDocumentUnchanged,\n atomicRestoreConfigDocument,\n atomicSaveConfigDocument,\n type ConfigDocumentSnapshot,\n ConfigPublicationError,\n type LoadedStarshipConfig,\n readConfigDocumentSnapshot,\n removeConfigDocumentIfMatches,\n validateConfigDocument,\n} from \"./config.js\";\nimport { archiveConfigDocument } from \"./profile-store.js\";\n\nexport interface CommitOptions extends ConfigurationCommandOptions {\n save?: (settingsPath: string, rawDocument: string) => LoadedStarshipConfig;\n restore?: (settingsPath: string, rawDocument: string) => void;\n archive?: typeof archiveConfigDocument;\n}\n\nexport interface CommitExpectation {\n previous: LoadedStarshipConfig;\n revision: number | undefined;\n disk: ConfigDocumentSnapshot;\n}\n\nexport function captureCommitExpectation(options: ConfigurationCommandOptions): CommitExpectation {\n return {\n previous: options.getLoaded(),\n revision: options.getLoadedRevision?.(),\n disk: readConfigDocumentSnapshot(options.settingsPath),\n };\n}\n\nexport function commitOwnerCurrent(\n options: ConfigurationCommandOptions,\n owner: WorkflowOwner,\n expected: CommitExpectation,\n): boolean {\n const loaded = options.getLoaded();\n return (\n !owner.signal.aborted &&\n owner.isCurrent() &&\n loaded.rawDocument === expected.previous.rawDocument &&\n loaded.source === expected.previous.source &&\n JSON.stringify(loaded.diagnostics) === JSON.stringify(expected.previous.diagnostics) &&\n options.getLoadedRevision?.() === expected.revision\n );\n}\n\n/** The queue has asynchronous admission; the owned file/runtime transaction has no await boundary. */\nexport async function commitActiveDocument(\n ctx: ExtensionCommandContext,\n options: CommitOptions,\n candidate: LoadedStarshipConfig,\n owner: WorkflowOwner,\n expected: CommitExpectation,\n allowInvalid = false,\n checkCandidate?: () => void,\n restoreNative = false,\n): Promise<\"applied\" | \"cancel\"> {\n const raw = candidate.rawDocument;\n if (restoreNative) {\n if (raw !== undefined || candidate.source !== \"built-in\" || candidate.diagnostics.length > 0)\n throw new Error(\"The native footer candidate is invalid\");\n } else if (raw === undefined) throw new Error(\"The candidate settings document is unavailable\");\n return withFileMutationQueue(options.settingsPath, async () => {\n if (!commitOwnerCurrent(options, owner, expected)) return \"cancel\";\n checkCandidate?.();\n assertConfigDocumentUnchanged(options.settingsPath, expected.disk);\n const previousBytes = expected.disk.rawBytes;\n if (expected.previous.rawDocument !== previousBytes?.toString(\"utf8\")) {\n throw new Error(\n \"The active file differs from the loaded document. Reload and review it before replacing settings.\",\n );\n }\n const invalid = expected.previous.diagnostics.some((item) => item.severity === \"error\");\n if (invalid && !allowInvalid)\n throw new Error(\"The active settings document is invalid. Use explicit repair or recovery before replacing it.\");\n // Always validate again at the publication boundary, not only in the preview layer.\n if (raw !== undefined) {\n validateConfigDocument(options.settingsPath, raw);\n if (previousBytes?.equals(Buffer.from(raw))) return \"applied\";\n }\n\n let recoveryPath: string | undefined;\n if (previousBytes !== undefined) {\n recoveryPath = (options.archive ?? archiveConfigDocument)(options.settingsPath, previousBytes).path;\n }\n // A recovery publication can fail or observe an external edit. Never publish over that edit.\n try {\n assertConfigDocumentUnchanged(options.settingsPath, expected.disk);\n if (!commitOwnerCurrent(options, owner, expected)) return \"cancel\";\n checkCandidate?.();\n } catch (error) {\n throw new Error(`${message(error)}.${recoveryNote(recoveryPath)}`);\n }\n let saved: LoadedStarshipConfig;\n try {\n if (raw === undefined) {\n if (previousBytes !== undefined) {\n if (!expected.disk.fileIdentity) throw new Error(\"The settings document identity is unavailable\");\n removeConfigDocumentIfMatches(\n options.settingsPath,\n previousBytes.toString(\"utf8\"),\n expected.disk.fileIdentity,\n );\n }\n saved = candidate;\n } else {\n saved = options.save\n ? options.save(options.settingsPath, raw)\n : atomicSaveConfigDocument(options.settingsPath, raw, {}, expected.disk);\n }\n } catch (error) {\n if (restoreNative) {\n const rollback = restorePrevious(ctx, options, owner, expected, undefined, undefined, false);\n throw new Error(\n `Pi native footer was not restored: ${message(error)}. ${rollback}${recoveryNote(recoveryPath)}`,\n );\n }\n if (error instanceof ConfigPublicationError) {\n const rollback = restorePrevious(ctx, options, owner, expected, raw, error.fileIdentity, false);\n throw new Error(`Footer settings were not saved: ${message(error)}. ${rollback}${recoveryNote(recoveryPath)}`);\n }\n throw new Error(\n `Footer settings were not saved: ${message(error)}. The previous footer remains active.${recoveryNote(recoveryPath)}`,\n );\n }\n try {\n if (\n owner.signal.aborted ||\n !(owner.isSessionCurrent?.() ?? owner.isCurrent()) ||\n options.getLoadedRevision?.() !== expected.revision\n ) {\n throw new Error(\"The configuration owner changed during publication\");\n }\n options.apply(saved, ctx);\n } catch (error) {\n const rollback = restorePrevious(ctx, options, owner, expected, raw, saved.fileIdentity, true);\n throw new Error(\n `Footer settings could not be applied: ${message(error)}. ${rollback}${recoveryNote(recoveryPath)}`,\n );\n }\n return \"applied\";\n });\n}\n\nfunction restorePrevious(\n ctx: ExtensionCommandContext,\n options: CommitOptions,\n owner: WorkflowOwner,\n expected: CommitExpectation,\n raw: string | undefined,\n identity: LoadedStarshipConfig[\"fileIdentity\"],\n restoreRuntime: boolean,\n): string {\n try {\n if (owner.signal.aborted || !(owner.isSessionCurrent?.() ?? owner.isCurrent()))\n throw new Error(\"The session owner changed; stale restoration was blocked\");\n const current = options.getLoaded();\n if (current.rawDocument !== expected.previous.rawDocument && current.rawDocument !== raw) {\n throw new Error(\"The active runtime changed; stale restoration was blocked\");\n }\n if (raw === undefined) {\n const disk = readConfigDocumentSnapshot(options.settingsPath);\n if (disk.rawBytes !== undefined) {\n assertConfigDocumentUnchanged(options.settingsPath, expected.disk);\n } else if (expected.disk.rawBytes !== undefined) {\n atomicRestoreConfigDocument(options.settingsPath, expected.disk.rawBytes, {}, disk);\n }\n if (restoreRuntime) options.apply(expected.previous, ctx);\n return \"The previous configuration was restored.\";\n }\n if (!identity) throw new Error(\"The saved settings document identity is unavailable\");\n assertConfigDocumentUnchanged(options.settingsPath, { rawBytes: Buffer.from(raw), fileIdentity: identity });\n if (expected.disk.rawBytes === undefined) {\n removeConfigDocumentIfMatches(options.settingsPath, raw, identity);\n } else if (options.restore && expected.disk.rawBytes.equals(Buffer.from(expected.previous.rawDocument ?? \"\"))) {\n options.restore(options.settingsPath, expected.previous.rawDocument ?? \"\");\n } else {\n atomicRestoreConfigDocument(\n options.settingsPath,\n expected.disk.rawBytes,\n {},\n { rawBytes: Buffer.from(raw), fileIdentity: identity },\n );\n }\n if (restoreRuntime) options.apply(expected.previous, ctx);\n return \"The previous configuration was restored.\";\n } catch (error) {\n return `Restoring the previous configuration also failed: ${message(error)}. Active path: ${options.settingsPath}.`;\n }\n}\n\nfunction recoveryNote(path: string | undefined): string {\n return path ? ` Recovery copy retained: ${path}.` : \"\";\n}\n\nfunction message(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n", "import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport { isKeyRelease, Key, matchesKey } from \"@earendil-works/pi-tui\";\nimport { defineMenu, runLiveChoice, runMenu } from \"@narumitw/pi-tui-kit\";\nimport { sanitizeTerminalText } from \"@narumitw/pi-tui-kit/terminal-text\";\nimport type { WorkflowOwner } from \"./command-configuration.js\";\nimport type { StarshipCommandOptions } from \"./commands.js\";\nimport { BUILT_IN_EXAMPLE, type LoadedStarshipConfig, validateConfigDocument } from \"./config.js\";\nimport {\n createProfile,\n deleteHistory,\n deleteProfile,\n duplicateProfile,\n type HistoryDocument,\n listHistory,\n listProfiles,\n type ProfileDocument,\n readHistory,\n readProfile,\n renameProfile,\n saveProfile,\n} from \"./profile-store.js\";\n\nexport type ProfileApplyCandidate = (\n loaded: LoadedStarshipConfig,\n owner: WorkflowOwner,\n checkCandidate: () => void,\n name: string,\n) => Promise<\"applied\" | \"stay\" | \"close\">;\n\ntype Document = ProfileDocument | HistoryDocument;\ntype Exit = \"back\" | \"close\";\ninterface Action {\n id: string;\n label: string;\n description?: string;\n disabled?: boolean;\n disabledReason?: string;\n}\ninterface Candidate {\n loaded?: LoadedStarshipConfig;\n lines: string[];\n}\n\nconst PREVIEW_NOTICE = \"Preview uses the current runtime snapshot only; unavailable module data can be empty.\";\nconst SAVE_CURRENT = \"save-current\";\nclass FlowEnded extends Error {}\n\n/** Profiles are independent copies. Only applyCandidate may replace active settings. */\nexport async function showProfiles(\n ctx: ExtensionCommandContext,\n options: StarshipCommandOptions,\n owner: WorkflowOwner,\n applyCandidate: ProfileApplyCandidate,\n): Promise<Exit> {\n return browseDocuments(ctx, options, owner, applyCandidate, \"profile\");\n}\n\nexport async function showHistory(\n ctx: ExtensionCommandContext,\n options: StarshipCommandOptions,\n owner: WorkflowOwner,\n applyCandidate: ProfileApplyCandidate,\n): Promise<Exit> {\n return browseDocuments(ctx, options, owner, applyCandidate, \"history\");\n}\n\n/** Reusable by reviewed preset/Gist candidates; never writes the active file. */\nexport async function saveAsProfile(\n ctx: ExtensionCommandContext,\n options: StarshipCommandOptions,\n owner: WorkflowOwner,\n raw: string,\n): Promise<ProfileDocument | \"close\" | undefined> {\n if (!interactive(ctx) || !current(owner)) return undefined;\n const flow = createFlow(ctx, options, owner);\n try {\n candidateFor(options, raw, true);\n const saved = await saveNamedCopy(ctx, options, flow, raw);\n flow.ensure();\n return saved;\n } catch (error) {\n if (flow.signal.aborted || !flow.sessionCurrent()) return \"close\";\n report(ctx, flow, error);\n return undefined;\n } finally {\n flow.dispose();\n }\n}\n\nasync function browseDocuments(\n ctx: ExtensionCommandContext,\n options: StarshipCommandOptions,\n owner: WorkflowOwner,\n applyCandidate: ProfileApplyCandidate,\n kind: Document[\"kind\"],\n): Promise<Exit> {\n if (!interactive(ctx) || !current(owner)) return \"close\";\n const flow = createFlow(ctx, options, owner);\n let selectedId: string | undefined;\n try {\n while (flow.current()) {\n let interacted = false;\n try {\n const documents: Document[] =\n kind === \"profile\" ? listProfiles(options.settingsPath) : listHistory(options.settingsPath);\n const active = options.getLoaded();\n const matches = documents.filter(\n (document) => document.rawDocument !== undefined && document.rawDocument === active.rawDocument,\n );\n const candidates = new Map(\n documents.map((document) => [documentId(document), candidateFor(options, document.rawDocument)]),\n );\n const selection = await runLiveChoice(ctx, {\n title: kind === \"profile\" ? \"Profiles\" : \"History\",\n lines: [\n active.rawDocument === undefined && active.diagnostics.length === 0\n ? \"Active: Built-in defaults\"\n : active.diagnostics.some((item) => item.severity === \"error\")\n ? \"Active: Invalid settings document \u00B7 replacement requires explicit recovery\"\n : \"Active: Independent settings document\",\n ...(kind === \"profile\" && matches.length === 0 ? [\"Current settings are not saved as a profile\"] : []),\n PREVIEW_NOTICE,\n ],\n items: [\n ...(kind === \"profile\"\n ? [\n {\n id: SAVE_CURRENT,\n label: \"Save current as\u2026\",\n description: \"Copy exact loaded TOML; keep active settings unchanged\",\n },\n ]\n : []),\n ...documents.map((document) => ({\n id: documentId(document),\n label: safe(document.name),\n description: [\n ...(document.kind === \"history\"\n ? [safe(document.createdAt), ...(document.legacy ? [\"Legacy \u00B7 read-only\"] : [])]\n : []),\n ...(document.rawDocument !== undefined && document.rawDocument === active.rawDocument\n ? [\"Matches active settings\"]\n : []),\n ...(!candidates.get(documentId(document))?.loaded ? [\"Invalid document \u00B7 review or repair\"] : []),\n ].join(\" \u00B7 \"),\n details: [\n `Selected: ${safe(document.name)}`,\n `Path: ${safe(document.path)}`,\n ...(candidates.get(documentId(document))?.lines ?? []),\n ],\n })),\n ],\n initialItemId: selectedId,\n enableSearch: true,\n viewportSize: 10,\n hint: \"back\",\n confirmLabel: \"actions\",\n navigationLabel: \"live preview\",\n signal: flow.signal,\n isCurrent: flow.current,\n onSelectionChange: ({ item, signal }) => {\n if (signal.aborted || !flow.current()) return;\n selectedId = item.id;\n flow.preview(candidates.get(item.id)?.loaded);\n },\n });\n flow.ensure();\n interacted = true;\n if (selection.kind !== \"selected\") {\n return selection.kind === \"closed\" && selection.reason === \"back\" ? \"back\" : \"close\";\n }\n selectedId = selection.itemId;\n if (selectedId === SAVE_CURRENT) {\n flow.preview(undefined);\n const loaded = options.getLoaded();\n if (loaded.diagnostics.some((item) => item.severity === \"error\")) {\n throw new Error(\n \"Cannot save unreadable or malformed active settings as a profile. Repair the settings document first.\",\n );\n }\n const raw = loaded.rawDocument ?? BUILT_IN_EXAMPLE;\n candidateFor(options, raw, true);\n const saved = await saveNamedCopy(ctx, options, flow, raw);\n flow.ensure();\n if (saved) selectedId = documentId(saved);\n continue;\n }\n const document = documents.find((item) => documentId(item) === selectedId);\n if (!document) continue;\n flow.ensure(document);\n const outcome = await documentActions(ctx, options, flow, document, applyCandidate);\n flow.ensure();\n if (outcome === \"close\") return \"close\";\n if (outcome) selectedId = documentId(outcome);\n } catch (error) {\n if (error instanceof FlowEnded || !flow.current()) return \"close\";\n flow.preview(undefined);\n report(ctx, flow, error);\n if (!interacted) return \"close\";\n }\n }\n return \"close\";\n } finally {\n flow.dispose();\n }\n}\n\nasync function documentActions(\n ctx: ExtensionCommandContext,\n options: StarshipCommandOptions,\n flow: ReturnType<typeof createFlow>,\n document: Document,\n applyCandidate: ProfileApplyCandidate,\n): Promise<Document | \"close\" | undefined> {\n const candidate = candidateFor(options, document.rawDocument);\n const profile = document.kind === \"profile\";\n const activeInvalid = profile && options.getLoaded().diagnostics.some((item) => item.severity === \"error\");\n const action = await actionScreen(ctx, flow, {\n title: `${profile ? \"Profile\" : \"Recovery copy\"}: ${safe(document.name)}`,\n lines: [\n `Path: ${safe(document.path)}`,\n ...(document.kind === \"history\"\n ? [`Recovery time: ${safe(document.createdAt)}`, \"A recovery copy is not proof that an application succeeded.\"]\n : []),\n ...(document.kind === \"history\" && document.legacy\n ? [\"Legacy backup \u00B7 read-only; restore copies bytes without changing this backup.\"]\n : []),\n ...(document.readError ? [safe(document.readError)] : []),\n ...candidate.lines,\n PREVIEW_NOTICE,\n ],\n raw: document.rawDocument,\n actions: [\n {\n id: \"apply\",\n label: profile ? \"Apply\u2026\" : \"Restore\u2026\",\n disabled: !candidate.loaded || activeInvalid,\n disabledReason: activeInvalid\n ? \"Repair active settings or use explicit recovery first\"\n : \"Invalid TOML cannot be applied\",\n },\n ...(profile\n ? [\n { id: \"edit\", label: \"Edit TOML\u2026\" },\n { id: \"rename\", label: \"Rename\u2026\" },\n { id: \"duplicate\", label: \"Duplicate\u2026\" },\n ]\n : [\n {\n id: \"save-as\",\n label: \"Save as a profile\u2026\",\n disabled: !candidate.loaded,\n disabledReason: \"Invalid TOML cannot be saved as a validated profile\",\n },\n ]),\n {\n id: \"delete\",\n label: \"Delete\u2026\",\n disabled: document.kind === \"history\" && document.legacy,\n disabledReason: \"Legacy backups are read-only\",\n },\n ],\n });\n flow.ensure(document);\n if (action === \"close\") return \"close\";\n if (action === \"back\") return undefined;\n if (action === \"apply\" && candidate.loaded) {\n const result = await applyReviewedCandidate(flow, candidate.loaded, applyCandidate, document);\n flow.ensure(document);\n return result === \"close\" ? \"close\" : document;\n }\n if (action === \"edit\" && profile) {\n const result = await editProfile(ctx, options, flow, document, applyCandidate);\n flow.ensure();\n return result;\n }\n if (action === \"rename\" && profile) {\n const name = await flow.dialog(() =>\n ctx.ui.input(`Rename profile: ${safe(document.name)}`, \"New profile name\", { signal: flow.signal }),\n );\n flow.ensure(document);\n if (name === undefined) return document;\n return renameProfile(options.settingsPath, document.name, name, document);\n }\n if (action === \"duplicate\" || (action === \"save-as\" && document.rawDocument !== undefined)) {\n const saved = await saveNamedCopy(ctx, options, flow, document.rawDocument, document);\n flow.ensure(document);\n return action === \"duplicate\" || document.kind === \"history\" ? document : (saved ?? document);\n }\n if (action === \"delete\" && !(document.kind === \"history\" && document.legacy)) {\n const confirmed = await flow.dialog(() =>\n ctx.ui.confirm(\n `Delete ${profile ? \"profile\" : \"recovery copy\"}: ${safe(document.name)}?`,\n `Path: ${safe(document.path)}\\n${profile ? \"This deletes only the saved profile. The active settings copy remains unchanged.\" : \"This permanently deletes only this recovery copy. Active settings remain unchanged.\"}`,\n { signal: flow.signal },\n ),\n );\n flow.ensure(document);\n if (confirmed) {\n if (document.kind === \"profile\") deleteProfile(options.settingsPath, document.name, document);\n else deleteHistory(options.settingsPath, document.name, document);\n }\n }\n return undefined;\n}\n\nasync function editProfile(\n ctx: ExtensionCommandContext,\n options: StarshipCommandOptions,\n flow: ReturnType<typeof createFlow>,\n original: ProfileDocument,\n applyCandidate: ProfileApplyCandidate,\n): Promise<ProfileDocument | \"close\"> {\n let draft = original.rawDocument ?? \"\";\n if (original.rawDocument === undefined) {\n const repair = await flow.dialog(() =>\n ctx.ui.confirm(\n `Repair invalid UTF-8 profile: ${safe(original.name)}?`,\n `Path: ${safe(original.path)}\\nThe original bytes cannot be edited as TOML text. Open an empty repair draft? Saving replaces these invalid bytes; the saved copy stays unchanged until you select Save profile. Duplicate it first to keep the original bytes.`,\n { signal: flow.signal },\n ),\n );\n flow.ensure(original);\n if (!repair) return original;\n }\n while (flow.current()) {\n // Pi's editor has no signal or public dismissal API. Drain it, then reject\n // stale completion. The owner abort listener clears the footer immediately.\n const edited = await flow.dialog(() => ctx.ui.editor(`Edit profile: ${safe(original.name)}`, draft));\n flow.ensure(original);\n if (edited === undefined) return original;\n draft = edited;\n const candidate = candidateFor(options, draft);\n flow.preview(candidate.loaded);\n const action = await actionScreen(ctx, flow, {\n title: candidate.loaded ? \"Profile draft preview\" : \"Profile draft needs attention\",\n lines: [\n \"Save profile changes only the saved copy, even when it matches active settings.\",\n ...candidate.lines,\n PREVIEW_NOTICE,\n ],\n raw: draft,\n actions: [\n {\n id: \"save\",\n label: \"Save profile\",\n disabled: !candidate.loaded,\n disabledReason: \"Repair the draft before saving\",\n },\n {\n id: \"save-apply\",\n label: \"Save profile and apply\u2026\",\n description: \"Two operations: a failed apply retains the saved profile\",\n disabled: !candidate.loaded,\n disabledReason: \"Repair the draft before saving\",\n },\n { id: \"continue\", label: \"Continue editing\" },\n { id: \"discard\", label: \"Discard draft\" },\n ],\n });\n flow.ensure(original);\n if (action === \"close\") return \"close\";\n if (action === \"discard\") return original;\n if (action === \"continue\" || action === \"back\") continue;\n if (!candidate.loaded || (action !== \"save\" && action !== \"save-apply\")) continue;\n const saved = saveProfile(options.settingsPath, original.name, draft, original);\n ctx.ui.notify(`Profile saved: ${safe(saved.name)}. Active settings are unchanged.`, \"info\");\n if (action === \"save-apply\") {\n try {\n const result = await applyReviewedCandidate(flow, candidate.loaded, applyCandidate, saved);\n flow.ensure(saved);\n if (result === \"close\") return \"close\";\n if (result !== \"applied\")\n ctx.ui.notify(\n \"The profile was saved. Application did not complete; review the configuration result before retrying.\",\n \"warning\",\n );\n } catch (error) {\n if (!flow.current()) throw error;\n ctx.ui.notify(\n `The saved profile was retained, but application did not complete: ${safeError(error)}. Review active settings before retrying.`,\n \"error\",\n );\n }\n }\n return saved;\n }\n throw new FlowEnded();\n}\n\nasync function applyReviewedCandidate(\n flow: ReturnType<typeof createFlow>,\n loaded: LoadedStarshipConfig,\n applyCandidate: ProfileApplyCandidate,\n document: Document,\n) {\n flow.ensure(document);\n const result = await applyCandidate(\n loaded,\n {\n signal: flow.signal,\n // The shared commit policy captures the active revision before applying.\n // A successful apply changes it; session ownership must remain valid after it.\n isCurrent: () => !flow.signal.aborted && flow.sessionCurrent(),\n isSessionCurrent: flow.sessionCurrent,\n },\n () => flow.ensure(document),\n document.name,\n );\n // Only this operation may advance the loaded revision. Other awaits must keep\n // the reviewed active revision; failed or cancelled applies cannot adopt it.\n if (result === \"applied\") flow.adoptAppliedRevision();\n flow.ensure(document);\n flow.preview(undefined);\n return result;\n}\n\nasync function saveNamedCopy(\n ctx: ExtensionCommandContext,\n options: StarshipCommandOptions,\n flow: ReturnType<typeof createFlow>,\n raw: string | undefined,\n source?: Document,\n): Promise<ProfileDocument | undefined> {\n while (flow.current()) {\n const name = await flow.dialog(() =>\n ctx.ui.input(\"Save as a profile\", \"Profile name (without .toml)\", { signal: flow.signal }),\n );\n flow.ensure(source);\n if (name === undefined) return undefined;\n try {\n const saved =\n source?.kind === \"profile\"\n ? duplicateProfile(options.settingsPath, source.name, name, source)\n : createProfile(options.settingsPath, name, requireText(raw));\n ctx.ui.notify(`Profile saved: ${safe(saved.name)}. Active settings are unchanged.`, \"info\");\n return saved;\n } catch (error) {\n report(ctx, flow, error);\n }\n }\n throw new FlowEnded();\n}\n\nasync function actionScreen(\n ctx: ExtensionCommandContext,\n flow: ReturnType<typeof createFlow>,\n screen: { title: string; lines: string[]; actions: Action[]; raw: string | undefined },\n): Promise<string> {\n let selected: string | undefined;\n const menu = defineMenu<undefined, \"actions\" | \"document\", \"select\">({\n start: \"actions\",\n screens: {\n actions: () => ({\n kind: \"actions\",\n title: screen.title,\n lines: screen.lines,\n items: [\n {\n id: \"review\",\n label: \"Review TOML\",\n to: \"document\",\n disabled: screen.raw === undefined,\n disabledReason: \"The document is not valid UTF-8\",\n },\n ...screen.actions.map((action) => ({ ...action, action: \"select\" as const })),\n ],\n hint: \"back\",\n }),\n document: () => ({\n kind: \"review\",\n title: screen.title,\n lines: [\"Exact UTF-8 text \u00B7 display controls sanitized \u00B7 read-only\"],\n content: screen.raw ?? \"The document is not valid UTF-8; no decoded fallback is shown.\",\n format: { kind: \"code\", language: \"toml\" },\n enableSearch: true,\n viewportSize: \"adaptive\",\n hint: \"back\",\n }),\n },\n actions: {\n select: ({ itemId }) => {\n flow.ensure();\n selected = itemId;\n return { kind: \"close\" };\n },\n },\n });\n const result = await runMenu(ctx, menu, { getState: () => undefined, signal: flow.signal, isCurrent: flow.current });\n flow.ensure();\n return selected ?? (result.kind === \"closed\" && result.reason === \"back\" ? \"back\" : \"close\");\n}\n\nfunction createFlow(ctx: ExtensionCommandContext, options: StarshipCommandOptions, owner: WorkflowOwner) {\n const controller = new AbortController();\n const signal = AbortSignal.any([controller.signal, owner.signal]);\n let revision = options.getLoadedRevision?.();\n let activeDocument = activeFingerprint(options.getLoaded());\n let previewOwned = false;\n const isCurrent = () =>\n !signal.aborted &&\n owner.isCurrent() &&\n (revision === undefined\n ? activeFingerprint(options.getLoaded()) === activeDocument\n : options.getLoadedRevision?.() === revision);\n const clearPreview = () => {\n if (!previewOwned) return;\n previewOwned = false;\n // The session owner, not a captured footer snapshot, decides whether cleanup\n // can touch the UI, even after command cancellation. Runtime lifecycle\n // cleanup owns a replaced session.\n if (owner.isSessionCurrent?.() ?? owner.isCurrent()) {\n try {\n options.preview?.(undefined, ctx);\n } catch (error) {\n ctx.ui.notify(`Could not clear the footer preview: ${safeError(error)}`, \"error\");\n }\n }\n };\n const matches = (expected?: Document) => {\n if (!isCurrent()) return false;\n if (!expected) return true;\n try {\n const fresh =\n expected.kind === \"profile\"\n ? readProfile(options.settingsPath, expected.name)\n : readHistory(options.settingsPath, expected.name);\n return (\n fresh.rawDocument === expected.rawDocument &&\n fresh.identity.dev === expected.identity.dev &&\n fresh.identity.ino === expected.identity.ino &&\n fresh.identity.size === expected.identity.size &&\n fresh.identity.mtimeNs === expected.identity.mtimeNs &&\n fresh.identity.ctimeNs === expected.identity.ctimeNs &&\n fresh.rawBytes.equals(expected.rawBytes)\n );\n } catch {\n return false;\n }\n };\n const ensure = (expected?: Document) => {\n if (!isCurrent()) throw new FlowEnded();\n if (!matches(expected))\n throw new Error(\"The selected document changed or was removed. Review the latest copy before trying again.\");\n };\n signal.addEventListener(\"abort\", clearPreview, { once: true });\n return {\n signal,\n current: isCurrent,\n sessionCurrent: () => owner.isSessionCurrent?.() ?? owner.isCurrent(),\n ensure,\n preview(loaded: LoadedStarshipConfig | undefined) {\n ensure();\n if (!loaded) {\n clearPreview();\n return;\n }\n previewOwned = true;\n try {\n options.preview?.(loaded, ctx);\n } catch (error) {\n clearPreview();\n throw error;\n }\n },\n async dialog<Value>(run: () => Promise<Value>): Promise<Value> {\n ensure();\n // Native dialogs collapse Escape and Ctrl+C into one result. Observe only\n // hard cancellation; never consume, rewrite, or forward editor content.\n const unsubscribe = ctx.ui.onTerminalInput((data) => {\n if (!isKeyRelease(data) && matchesKey(data, Key.ctrl(\"c\"))) {\n // Abort after native input dispatch, before its promise continuation.\n // Synchronous abort could restore focus and leak this key to Pi's editor.\n queueMicrotask(() => controller.abort());\n }\n return undefined;\n });\n let released = false;\n const release = () => {\n if (released) return;\n released = true;\n unsubscribe();\n };\n signal.addEventListener(\"abort\", release, { once: true });\n try {\n if (signal.aborted) release();\n ensure();\n const result = await run();\n ensure();\n return result;\n } finally {\n signal.removeEventListener(\"abort\", release);\n release();\n }\n },\n adoptAppliedRevision() {\n if (signal.aborted || !(owner.isSessionCurrent?.() ?? owner.isCurrent())) throw new FlowEnded();\n revision = options.getLoadedRevision?.();\n activeDocument = activeFingerprint(options.getLoaded());\n },\n dispose() {\n try {\n clearPreview();\n } finally {\n signal.removeEventListener(\"abort\", clearPreview);\n controller.abort();\n }\n },\n };\n}\n\nfunction candidateFor(options: StarshipCommandOptions, raw: string | undefined, required = false): Candidate {\n try {\n if (raw === undefined) throw new Error(\"The document is not valid UTF-8; no decoded fallback is shown.\");\n const loaded = (options.validate ?? validateConfigDocument)(options.settingsPath, raw);\n if (loaded.diagnostics.some((item) => item.severity === \"error\"))\n throw new Error(loaded.diagnostics.map((item) => item.message).join(\"; \"));\n return {\n loaded,\n lines:\n loaded.diagnostics.length === 0\n ? [\"No configuration warnings.\"]\n : loaded.diagnostics.map((item) => `${safe(item.path || \"root\")}: ${safe(item.message)}`),\n };\n } catch (error) {\n if (required) throw error;\n return { lines: [`Invalid TOML: ${safeError(error)}`, \"No candidate footer preview is shown.\"] };\n }\n}\n\nfunction requireText(raw: string | undefined): string {\n if (raw === undefined) throw new Error(\"The document is not valid UTF-8; no decoded fallback can be saved.\");\n return raw;\n}\n\nfunction activeFingerprint(loaded: LoadedStarshipConfig) {\n return JSON.stringify([loaded.source, loaded.rawDocument, loaded.diagnostics]);\n}\n\nfunction current(owner: WorkflowOwner) {\n return !owner.signal.aborted && owner.isCurrent();\n}\n\nfunction interactive(ctx: ExtensionCommandContext) {\n if (ctx.mode === \"tui\" && ctx.hasUI) return true;\n if (ctx.hasUI) ctx.ui.notify(\"Profiles and History require TUI mode.\", \"info\");\n return false;\n}\n\nfunction documentId(document: Document) {\n return `${document.kind}:${document.name}`;\n}\n\nfunction report(ctx: ExtensionCommandContext, flow: ReturnType<typeof createFlow>, error: unknown) {\n if (!(error instanceof FlowEnded) && flow.current()) ctx.ui.notify(safeError(error), \"error\");\n}\n\nfunction safeError(error: unknown) {\n return safe(error instanceof Error ? error.message : String(error));\n}\n\nfunction safe(value: string) {\n return sanitizeTerminalText(value);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAuC,6BAA6B;AA2B7D,SAAS,yBAAyB,SAAyD;AAChG,SAAO;AAAA,IACL,UAAU,QAAQ,UAAU;AAAA,IAC5B,UAAU,QAAQ,oBAAoB;AAAA,IACtC,MAAM,2BAA2B,QAAQ,YAAY;AAAA,EACvD;AACF;AAEO,SAAS,mBACd,SACA,OACA,UACS;AACT,QAAM,SAAS,QAAQ,UAAU;AACjC,SACE,CAAC,MAAM,OAAO,WACd,MAAM,UAAU,KAChB,OAAO,gBAAgB,SAAS,SAAS,eACzC,OAAO,WAAW,SAAS,SAAS,UACpC,KAAK,UAAU,OAAO,WAAW,MAAM,KAAK,UAAU,SAAS,SAAS,WAAW,KACnF,QAAQ,oBAAoB,MAAM,SAAS;AAE/C;AAGA,eAAsB,qBACpB,KACA,SACA,WACA,OACA,UACA,eAAe,OACf,gBACA,gBAAgB,OACe;AAC/B,QAAM,MA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,IAAI;AAC1C;AAEA,SAAS,OAAO,KAA8B,MAAqC,OAAgB;AACjG,MAAI,EAAE,iBAAiB,cAAc,KAAK,QAAQ,EAAG,KAAI,GAAG,OAAO,UAAU,KAAK,GAAG,OAAO;AAC9F;AAEA,SAAS,UAAU,OAAgB;AACjC,SAAO,KAAK,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AACpE;AAEA,SAAS,KAAK,OAAe;AAC3B,SAAO,qBAAqB,KAAK;AACnC;",
|
|
4
|
+
"sourcesContent": ["import { type ExtensionCommandContext, withFileMutationQueue } from \"@earendil-works/pi-coding-agent\";\nimport type { ConfigurationCommandOptions, WorkflowOwner } from \"./command-configuration.js\";\nimport {\n assertConfigDocumentUnchanged,\n atomicRestoreConfigDocument,\n atomicSaveConfigDocument,\n type ConfigDocumentSnapshot,\n ConfigPublicationError,\n type LoadedStarshipConfig,\n readConfigDocumentSnapshot,\n removeConfigDocumentIfMatches,\n validateConfigDocument,\n} from \"./config.js\";\nimport { archiveConfigDocument } from \"./profile-store.js\";\n\nexport interface CommitOptions extends ConfigurationCommandOptions {\n save?: (settingsPath: string, rawDocument: string) => LoadedStarshipConfig;\n restore?: (settingsPath: string, rawDocument: string) => void;\n archive?: typeof archiveConfigDocument;\n}\n\nexport interface CommitExpectation {\n previous: LoadedStarshipConfig;\n revision: number | undefined;\n disk: ConfigDocumentSnapshot;\n}\n\nexport function captureCommitExpectation(options: ConfigurationCommandOptions): CommitExpectation {\n return {\n previous: options.getLoaded(),\n revision: options.getLoadedRevision?.(),\n disk: readConfigDocumentSnapshot(options.settingsPath),\n };\n}\n\nexport function commitOwnerCurrent(\n options: ConfigurationCommandOptions,\n owner: WorkflowOwner,\n expected: CommitExpectation,\n): boolean {\n const loaded = options.getLoaded();\n return (\n !owner.signal.aborted &&\n owner.isCurrent() &&\n loaded.rawDocument === expected.previous.rawDocument &&\n loaded.source === expected.previous.source &&\n JSON.stringify(loaded.diagnostics) === JSON.stringify(expected.previous.diagnostics) &&\n options.getLoadedRevision?.() === expected.revision\n );\n}\n\n/** The queue has asynchronous admission; the owned file/runtime transaction has no await boundary. */\nexport async function commitActiveDocument(\n ctx: ExtensionCommandContext,\n options: CommitOptions,\n candidate: LoadedStarshipConfig,\n owner: WorkflowOwner,\n expected: CommitExpectation,\n allowInvalid = false,\n checkCandidate?: () => void,\n restoreNative = false,\n): Promise<\"applied\" | \"cancel\"> {\n const raw = candidate.rawDocument;\n if (restoreNative) {\n if (raw !== undefined || candidate.source !== \"built-in\" || candidate.diagnostics.length > 0)\n throw new Error(\"The native footer candidate is invalid\");\n } else if (raw === undefined) throw new Error(\"The candidate settings document is unavailable\");\n return withFileMutationQueue(options.settingsPath, async () => {\n if (!commitOwnerCurrent(options, owner, expected)) return \"cancel\";\n checkCandidate?.();\n assertConfigDocumentUnchanged(options.settingsPath, expected.disk);\n const previousBytes = expected.disk.rawBytes;\n if (expected.previous.rawDocument !== previousBytes?.toString(\"utf8\")) {\n throw new Error(\n \"The active file differs from the loaded document. Reload and review it before replacing settings.\",\n );\n }\n const invalid = expected.previous.diagnostics.some((item) => item.severity === \"error\");\n if (invalid && !allowInvalid)\n throw new Error(\"The active settings document is invalid. Use explicit repair or recovery before replacing it.\");\n // Always validate again at the publication boundary, not only in the preview layer.\n if (raw !== undefined) {\n validateConfigDocument(options.settingsPath, raw);\n if (previousBytes?.equals(Buffer.from(raw))) return \"applied\";\n }\n\n let recoveryPath: string | undefined;\n if (previousBytes !== undefined) {\n recoveryPath = (options.archive ?? archiveConfigDocument)(options.settingsPath, previousBytes).path;\n }\n // A recovery publication can fail or observe an external edit. Never publish over that edit.\n try {\n assertConfigDocumentUnchanged(options.settingsPath, expected.disk);\n if (!commitOwnerCurrent(options, owner, expected)) return \"cancel\";\n checkCandidate?.();\n } catch (error) {\n throw new Error(`${message(error)}.${recoveryNote(recoveryPath)}`);\n }\n let saved: LoadedStarshipConfig;\n try {\n if (raw === undefined) {\n if (previousBytes !== undefined) {\n if (!expected.disk.fileIdentity) throw new Error(\"The settings document identity is unavailable\");\n removeConfigDocumentIfMatches(\n options.settingsPath,\n previousBytes.toString(\"utf8\"),\n expected.disk.fileIdentity,\n );\n }\n saved = candidate;\n } else {\n saved = options.save\n ? options.save(options.settingsPath, raw)\n : atomicSaveConfigDocument(options.settingsPath, raw, {}, expected.disk);\n }\n } catch (error) {\n if (restoreNative) {\n const rollback = restorePrevious(ctx, options, owner, expected, undefined, undefined, false);\n throw new Error(\n `Pi native footer was not restored: ${message(error)}. ${rollback}${recoveryNote(recoveryPath)}`,\n );\n }\n if (error instanceof ConfigPublicationError) {\n const rollback = restorePrevious(ctx, options, owner, expected, raw, error.fileIdentity, false);\n throw new Error(`Footer settings were not saved: ${message(error)}. ${rollback}${recoveryNote(recoveryPath)}`);\n }\n throw new Error(\n `Footer settings were not saved: ${message(error)}. The previous footer remains active.${recoveryNote(recoveryPath)}`,\n );\n }\n try {\n if (\n owner.signal.aborted ||\n !(owner.isSessionCurrent?.() ?? owner.isCurrent()) ||\n options.getLoadedRevision?.() !== expected.revision\n ) {\n throw new Error(\"The configuration owner changed during publication\");\n }\n options.apply(saved, ctx);\n } catch (error) {\n const rollback = restorePrevious(ctx, options, owner, expected, raw, saved.fileIdentity, true);\n throw new Error(\n `Footer settings could not be applied: ${message(error)}. ${rollback}${recoveryNote(recoveryPath)}`,\n );\n }\n return \"applied\";\n });\n}\n\nfunction restorePrevious(\n ctx: ExtensionCommandContext,\n options: CommitOptions,\n owner: WorkflowOwner,\n expected: CommitExpectation,\n raw: string | undefined,\n identity: LoadedStarshipConfig[\"fileIdentity\"],\n restoreRuntime: boolean,\n): string {\n try {\n if (owner.signal.aborted || !(owner.isSessionCurrent?.() ?? owner.isCurrent()))\n throw new Error(\"The session owner changed; stale restoration was blocked\");\n const current = options.getLoaded();\n if (current.rawDocument !== expected.previous.rawDocument && current.rawDocument !== raw) {\n throw new Error(\"The active runtime changed; stale restoration was blocked\");\n }\n if (raw === undefined) {\n const disk = readConfigDocumentSnapshot(options.settingsPath);\n if (disk.rawBytes !== undefined) {\n assertConfigDocumentUnchanged(options.settingsPath, expected.disk);\n } else if (expected.disk.rawBytes !== undefined) {\n atomicRestoreConfigDocument(options.settingsPath, expected.disk.rawBytes, {}, disk);\n }\n if (restoreRuntime) options.apply(expected.previous, ctx);\n return \"The previous configuration was restored.\";\n }\n if (!identity) throw new Error(\"The saved settings document identity is unavailable\");\n assertConfigDocumentUnchanged(options.settingsPath, { rawBytes: Buffer.from(raw), fileIdentity: identity });\n if (expected.disk.rawBytes === undefined) {\n removeConfigDocumentIfMatches(options.settingsPath, raw, identity);\n } else if (options.restore && expected.disk.rawBytes.equals(Buffer.from(expected.previous.rawDocument ?? \"\"))) {\n options.restore(options.settingsPath, expected.previous.rawDocument ?? \"\");\n } else {\n atomicRestoreConfigDocument(\n options.settingsPath,\n expected.disk.rawBytes,\n {},\n { rawBytes: Buffer.from(raw), fileIdentity: identity },\n );\n }\n if (restoreRuntime) options.apply(expected.previous, ctx);\n return \"The previous configuration was restored.\";\n } catch (error) {\n return `Restoring the previous configuration also failed: ${message(error)}. Active path: ${options.settingsPath}.`;\n }\n}\n\nfunction recoveryNote(path: string | undefined): string {\n return path ? ` Recovery copy retained: ${path}.` : \"\";\n}\n\nfunction message(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n", "import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport { isKeyRelease, Key, matchesKey } from \"@earendil-works/pi-tui\";\nimport { defineMenu, runLiveChoice, runMenu } from \"@narumitw/pi-tui-kit\";\nimport { sanitizeTerminalText } from \"@narumitw/pi-tui-kit/terminal-text\";\nimport type { WorkflowOwner } from \"./command-configuration.js\";\nimport type { StarshipCommandOptions } from \"./commands.js\";\nimport { BUILT_IN_EXAMPLE, type LoadedStarshipConfig, validateConfigDocument } from \"./config.js\";\nimport {\n createProfile,\n deleteHistory,\n deleteProfile,\n duplicateProfile,\n type HistoryDocument,\n listHistory,\n listProfiles,\n type ProfileDocument,\n readHistory,\n readProfile,\n renameProfile,\n saveProfile,\n} from \"./profile-store.js\";\n\nexport type ProfileApplyCandidate = (\n loaded: LoadedStarshipConfig,\n owner: WorkflowOwner,\n checkCandidate: () => void,\n name: string,\n) => Promise<\"applied\" | \"stay\" | \"close\">;\n\ntype Document = ProfileDocument | HistoryDocument;\ntype Exit = \"back\" | \"close\";\ninterface Action {\n id: string;\n label: string;\n description?: string;\n disabled?: boolean;\n disabledReason?: string;\n}\ninterface Candidate {\n loaded?: LoadedStarshipConfig;\n lines: string[];\n}\n\nconst PREVIEW_NOTICE = \"Preview uses the current runtime snapshot only; unavailable module data can be empty.\";\nconst SAVE_CURRENT = \"save-current\";\nclass FlowEnded extends Error {}\n\n/** Profiles are independent copies. Only applyCandidate may replace active settings. */\nexport async function showProfiles(\n ctx: ExtensionCommandContext,\n options: StarshipCommandOptions,\n owner: WorkflowOwner,\n applyCandidate: ProfileApplyCandidate,\n): Promise<Exit> {\n return browseDocuments(ctx, options, owner, applyCandidate, \"profile\");\n}\n\nexport async function showHistory(\n ctx: ExtensionCommandContext,\n options: StarshipCommandOptions,\n owner: WorkflowOwner,\n applyCandidate: ProfileApplyCandidate,\n): Promise<Exit> {\n return browseDocuments(ctx, options, owner, applyCandidate, \"history\");\n}\n\n/** Reusable by reviewed preset/Gist candidates; never writes the active file. */\nexport async function saveAsProfile(\n ctx: ExtensionCommandContext,\n options: StarshipCommandOptions,\n owner: WorkflowOwner,\n raw: string,\n): Promise<ProfileDocument | \"close\" | undefined> {\n if (!interactive(ctx) || !current(owner)) return undefined;\n const flow = createFlow(ctx, options, owner);\n try {\n candidateFor(options, raw, true);\n const saved = await saveNamedCopy(ctx, options, flow, raw);\n flow.ensure();\n return saved;\n } catch (error) {\n if (flow.signal.aborted || !flow.sessionCurrent()) return \"close\";\n report(ctx, flow, error);\n return undefined;\n } finally {\n flow.dispose();\n }\n}\n\nasync function browseDocuments(\n ctx: ExtensionCommandContext,\n options: StarshipCommandOptions,\n owner: WorkflowOwner,\n applyCandidate: ProfileApplyCandidate,\n kind: Document[\"kind\"],\n): Promise<Exit> {\n if (!interactive(ctx) || !current(owner)) return \"close\";\n const flow = createFlow(ctx, options, owner);\n let selectedId: string | undefined;\n try {\n while (flow.current()) {\n let interacted = false;\n try {\n const documents: Document[] =\n kind === \"profile\" ? listProfiles(options.settingsPath) : listHistory(options.settingsPath);\n const active = options.getLoaded();\n const matches = documents.filter(\n (document) => document.rawDocument !== undefined && document.rawDocument === active.rawDocument,\n );\n const candidates = new Map(\n documents.map((document) => [documentId(document), candidateFor(options, document.rawDocument)]),\n );\n const selection = await runLiveChoice(ctx, {\n title: kind === \"profile\" ? \"Profiles\" : \"History\",\n lines: [\n active.rawDocument === undefined && active.diagnostics.length === 0\n ? \"Active: Built-in defaults\"\n : active.diagnostics.some((item) => item.severity === \"error\")\n ? \"Active: Invalid settings document \u00B7 replacement requires explicit recovery\"\n : \"Active: Independent settings document\",\n ...(kind === \"profile\" && matches.length === 0 ? [\"Current settings are not saved as a profile\"] : []),\n PREVIEW_NOTICE,\n ],\n items: [\n ...(kind === \"profile\"\n ? [\n {\n id: SAVE_CURRENT,\n label: \"Save current as\u2026\",\n description: \"Copy exact loaded TOML; keep active settings unchanged\",\n },\n ]\n : []),\n ...documents.map((document) => ({\n id: documentId(document),\n label: safe(document.name),\n description: [\n ...(document.kind === \"history\"\n ? [safe(document.createdAt), ...(document.legacy ? [\"Legacy \u00B7 read-only\"] : [])]\n : []),\n ...(document.rawDocument !== undefined && document.rawDocument === active.rawDocument\n ? [\"Matches active settings\"]\n : []),\n ...(!candidates.get(documentId(document))?.loaded ? [\"Invalid document \u00B7 review or repair\"] : []),\n ].join(\" \u00B7 \"),\n details: [\n `Selected: ${safe(document.name)}`,\n `Path: ${safe(document.path)}`,\n ...(candidates.get(documentId(document))?.lines ?? []),\n ],\n })),\n ],\n initialItemId: selectedId,\n enableSearch: true,\n viewportSize: 10,\n hint: \"back\",\n confirmLabel: \"actions\",\n navigationLabel: \"live preview\",\n signal: flow.signal,\n isCurrent: flow.current,\n onSelectionChange: ({ item, signal }) => {\n if (signal.aborted || !flow.current()) return;\n selectedId = item.id;\n flow.preview(candidates.get(item.id)?.loaded);\n },\n });\n flow.ensure();\n interacted = true;\n if (selection.kind !== \"selected\") {\n return selection.kind === \"closed\" && selection.reason === \"back\" ? \"back\" : \"close\";\n }\n selectedId = selection.itemId;\n if (selectedId === SAVE_CURRENT) {\n flow.preview(undefined);\n const loaded = options.getLoaded();\n if (loaded.diagnostics.some((item) => item.severity === \"error\")) {\n throw new Error(\n \"Cannot save unreadable or malformed active settings as a profile. Repair the settings document first.\",\n );\n }\n const raw = loaded.rawDocument ?? BUILT_IN_EXAMPLE;\n candidateFor(options, raw, true);\n const saved = await saveNamedCopy(ctx, options, flow, raw);\n flow.ensure();\n if (saved) selectedId = documentId(saved);\n continue;\n }\n const document = documents.find((item) => documentId(item) === selectedId);\n if (!document) continue;\n flow.ensure(document);\n const outcome = await documentActions(ctx, options, flow, document, applyCandidate);\n flow.ensure();\n if (outcome === \"close\") return \"close\";\n if (outcome) selectedId = documentId(outcome);\n } catch (error) {\n if (error instanceof FlowEnded || !flow.current()) return \"close\";\n flow.preview(undefined);\n report(ctx, flow, error);\n if (!interacted) return \"close\";\n }\n }\n return \"close\";\n } finally {\n flow.dispose();\n }\n}\n\nasync function documentActions(\n ctx: ExtensionCommandContext,\n options: StarshipCommandOptions,\n flow: ReturnType<typeof createFlow>,\n document: Document,\n applyCandidate: ProfileApplyCandidate,\n): Promise<Document | \"close\" | undefined> {\n const candidate = candidateFor(options, document.rawDocument);\n const profile = document.kind === \"profile\";\n const activeInvalid = profile && options.getLoaded().diagnostics.some((item) => item.severity === \"error\");\n const action = await actionScreen(ctx, flow, {\n kind: document.kind,\n title: `${profile ? \"Profile\" : \"Recovery copy\"}: ${safe(document.name)}`,\n lines: [\n `Path: ${safe(document.path)}`,\n ...(document.kind === \"history\"\n ? [`Recovery time: ${safe(document.createdAt)}`, \"A recovery copy is not proof that an application succeeded.\"]\n : []),\n ...(document.kind === \"history\" && document.legacy\n ? [\"Legacy backup \u00B7 read-only; restore copies bytes without changing this backup.\"]\n : []),\n ...(document.readError ? [safe(document.readError)] : []),\n ...candidate.lines,\n PREVIEW_NOTICE,\n ],\n raw: document.rawDocument,\n actions: [\n {\n id: \"apply\",\n label: profile ? \"Apply\u2026\" : \"Restore\u2026\",\n disabled: !candidate.loaded || activeInvalid,\n disabledReason: activeInvalid\n ? \"Repair active settings or use explicit recovery first\"\n : \"Invalid TOML cannot be applied\",\n },\n ...(profile\n ? [\n { id: \"edit\", label: \"Edit TOML\u2026\" },\n { id: \"duplicate\", label: \"Duplicate\u2026\" },\n { id: \"rename\", label: \"Rename\u2026\" },\n ]\n : [\n {\n id: \"save-as\",\n label: \"Save as a profile\u2026\",\n disabled: !candidate.loaded,\n disabledReason: \"Invalid TOML cannot be saved as a validated profile\",\n },\n ]),\n {\n id: \"delete\",\n label: \"Delete\u2026\",\n disabled: document.kind === \"history\" && document.legacy,\n disabledReason: \"Legacy backups are read-only\",\n },\n ],\n });\n flow.ensure(document);\n if (action === \"close\") return \"close\";\n if (action === \"back\") return undefined;\n if (action === \"apply\" && candidate.loaded) {\n const result = await applyReviewedCandidate(flow, candidate.loaded, applyCandidate, document);\n flow.ensure(document);\n return result === \"close\" ? \"close\" : document;\n }\n if (action === \"edit\" && profile) {\n const result = await editProfile(ctx, options, flow, document, applyCandidate);\n flow.ensure();\n return result;\n }\n if (action === \"rename\" && profile) {\n const name = await flow.dialog(() =>\n ctx.ui.input(`Rename profile: ${safe(document.name)}`, \"New profile name\", { signal: flow.signal }),\n );\n flow.ensure(document);\n if (name === undefined) return document;\n return renameProfile(options.settingsPath, document.name, name, document);\n }\n if (action === \"duplicate\" || (action === \"save-as\" && document.rawDocument !== undefined)) {\n const saved = await saveNamedCopy(ctx, options, flow, document.rawDocument, document);\n flow.ensure(document);\n return action === \"duplicate\" || document.kind === \"history\" ? document : (saved ?? document);\n }\n if (action === \"delete\" && !(document.kind === \"history\" && document.legacy)) {\n const confirmed = await flow.dialog(() =>\n ctx.ui.confirm(\n `Delete ${profile ? \"profile\" : \"recovery copy\"}: ${safe(document.name)}?`,\n `Path: ${safe(document.path)}\\n${profile ? \"This deletes only the saved profile. The active settings copy remains unchanged.\" : \"This permanently deletes only this recovery copy. Active settings remain unchanged.\"}`,\n { signal: flow.signal },\n ),\n );\n flow.ensure(document);\n if (confirmed) {\n if (document.kind === \"profile\") deleteProfile(options.settingsPath, document.name, document);\n else deleteHistory(options.settingsPath, document.name, document);\n }\n }\n return undefined;\n}\n\nasync function editProfile(\n ctx: ExtensionCommandContext,\n options: StarshipCommandOptions,\n flow: ReturnType<typeof createFlow>,\n original: ProfileDocument,\n applyCandidate: ProfileApplyCandidate,\n): Promise<ProfileDocument | \"close\"> {\n let draft = original.rawDocument ?? \"\";\n if (original.rawDocument === undefined) {\n const repair = await flow.dialog(() =>\n ctx.ui.confirm(\n `Repair invalid UTF-8 profile: ${safe(original.name)}?`,\n `Path: ${safe(original.path)}\\nThe original bytes cannot be edited as TOML text. Open an empty repair draft? Saving replaces these invalid bytes; the saved copy stays unchanged until you select Save profile. Duplicate it first to keep the original bytes.`,\n { signal: flow.signal },\n ),\n );\n flow.ensure(original);\n if (!repair) return original;\n }\n while (flow.current()) {\n // Pi's editor has no signal or public dismissal API. Drain it, then reject\n // stale completion. The owner abort listener clears the footer immediately.\n const edited = await flow.dialog(() => ctx.ui.editor(`Edit profile: ${safe(original.name)}`, draft));\n flow.ensure(original);\n if (edited === undefined) return original;\n draft = edited;\n const candidate = candidateFor(options, draft);\n flow.preview(candidate.loaded);\n const action = await actionScreen(ctx, flow, {\n title: candidate.loaded ? \"Profile draft preview\" : \"Profile draft needs attention\",\n lines: [\n \"Save profile changes only the saved copy, even when it matches active settings.\",\n ...candidate.lines,\n PREVIEW_NOTICE,\n ],\n raw: draft,\n actions: [\n {\n id: \"save\",\n label: \"Save profile\",\n disabled: !candidate.loaded,\n disabledReason: \"Repair the draft before saving\",\n },\n {\n id: \"save-apply\",\n label: \"Save profile and apply\u2026\",\n description: \"Two operations: a failed apply retains the saved profile\",\n disabled: !candidate.loaded,\n disabledReason: \"Repair the draft before saving\",\n },\n { id: \"continue\", label: \"Continue editing\" },\n { id: \"discard\", label: \"Discard draft\" },\n ],\n });\n flow.ensure(original);\n if (action === \"close\") return \"close\";\n if (action === \"discard\") return original;\n if (action === \"continue\" || action === \"back\") continue;\n if (!candidate.loaded || (action !== \"save\" && action !== \"save-apply\")) continue;\n const saved = saveProfile(options.settingsPath, original.name, draft, original);\n ctx.ui.notify(`Profile saved: ${safe(saved.name)}. Active settings are unchanged.`, \"info\");\n if (action === \"save-apply\") {\n try {\n const result = await applyReviewedCandidate(flow, candidate.loaded, applyCandidate, saved);\n flow.ensure(saved);\n if (result === \"close\") return \"close\";\n if (result !== \"applied\")\n ctx.ui.notify(\n \"The profile was saved. Application did not complete; review the configuration result before retrying.\",\n \"warning\",\n );\n } catch (error) {\n if (!flow.current()) throw error;\n ctx.ui.notify(\n `The saved profile was retained, but application did not complete: ${safeError(error)}. Review active settings before retrying.`,\n \"error\",\n );\n }\n }\n return saved;\n }\n throw new FlowEnded();\n}\n\nasync function applyReviewedCandidate(\n flow: ReturnType<typeof createFlow>,\n loaded: LoadedStarshipConfig,\n applyCandidate: ProfileApplyCandidate,\n document: Document,\n) {\n flow.ensure(document);\n const result = await applyCandidate(\n loaded,\n {\n signal: flow.signal,\n // The shared commit policy captures the active revision before applying.\n // A successful apply changes it; session ownership must remain valid after it.\n isCurrent: () => !flow.signal.aborted && flow.sessionCurrent(),\n isSessionCurrent: flow.sessionCurrent,\n },\n () => flow.ensure(document),\n document.name,\n );\n // Only this operation may advance the loaded revision. Other awaits must keep\n // the reviewed active revision; failed or cancelled applies cannot adopt it.\n if (result === \"applied\") flow.adoptAppliedRevision();\n flow.ensure(document);\n flow.preview(undefined);\n return result;\n}\n\nasync function saveNamedCopy(\n ctx: ExtensionCommandContext,\n options: StarshipCommandOptions,\n flow: ReturnType<typeof createFlow>,\n raw: string | undefined,\n source?: Document,\n): Promise<ProfileDocument | undefined> {\n while (flow.current()) {\n const name = await flow.dialog(() =>\n ctx.ui.input(\"Save as a profile\", \"Profile name (without .toml)\", { signal: flow.signal }),\n );\n flow.ensure(source);\n if (name === undefined) return undefined;\n try {\n const saved =\n source?.kind === \"profile\"\n ? duplicateProfile(options.settingsPath, source.name, name, source)\n : createProfile(options.settingsPath, name, requireText(raw));\n ctx.ui.notify(`Profile saved: ${safe(saved.name)}. Active settings are unchanged.`, \"info\");\n return saved;\n } catch (error) {\n report(ctx, flow, error);\n }\n }\n throw new FlowEnded();\n}\n\nasync function actionScreen(\n ctx: ExtensionCommandContext,\n flow: ReturnType<typeof createFlow>,\n screen: { kind?: Document[\"kind\"]; title: string; lines: string[]; actions: Action[]; raw: string | undefined },\n): Promise<string> {\n let selected: string | undefined;\n const menu = defineMenu<undefined, \"actions\" | \"document\", \"select\">({\n start: \"actions\",\n screens: {\n actions: () => ({\n kind: \"actions\",\n title: screen.title,\n lines: screen.lines,\n items: [\n ...(screen.kind === \"profile\"\n ? screen.actions.slice(0, 1).map((action) => ({ ...action, action: \"select\" as const }))\n : []),\n {\n id: \"review\",\n label: \"Review TOML\",\n to: \"document\",\n disabled: screen.raw === undefined,\n disabledReason: \"The document is not valid UTF-8\",\n },\n ...(screen.kind === \"profile\" ? screen.actions.slice(1) : screen.actions).map((action) => ({\n ...action,\n action: \"select\" as const,\n })),\n ],\n hint: \"back\",\n }),\n document: () => ({\n kind: \"review\",\n title: screen.title,\n lines: [\"Exact UTF-8 text \u00B7 display controls sanitized \u00B7 read-only\"],\n content: screen.raw ?? \"The document is not valid UTF-8; no decoded fallback is shown.\",\n format: { kind: \"code\", language: \"toml\" },\n enableSearch: true,\n viewportSize: \"adaptive\",\n hint: \"back\",\n }),\n },\n actions: {\n select: ({ itemId }) => {\n flow.ensure();\n selected = itemId;\n return { kind: \"close\" };\n },\n },\n });\n const result = await runMenu(ctx, menu, { getState: () => undefined, signal: flow.signal, isCurrent: flow.current });\n flow.ensure();\n return selected ?? (result.kind === \"closed\" && result.reason === \"back\" ? \"back\" : \"close\");\n}\n\nfunction createFlow(ctx: ExtensionCommandContext, options: StarshipCommandOptions, owner: WorkflowOwner) {\n const controller = new AbortController();\n const signal = AbortSignal.any([controller.signal, owner.signal]);\n let revision = options.getLoadedRevision?.();\n let activeDocument = activeFingerprint(options.getLoaded());\n let previewOwned = false;\n const isCurrent = () =>\n !signal.aborted &&\n owner.isCurrent() &&\n (revision === undefined\n ? activeFingerprint(options.getLoaded()) === activeDocument\n : options.getLoadedRevision?.() === revision);\n const clearPreview = () => {\n if (!previewOwned) return;\n previewOwned = false;\n // The session owner, not a captured footer snapshot, decides whether cleanup\n // can touch the UI, even after command cancellation. Runtime lifecycle\n // cleanup owns a replaced session.\n if (owner.isSessionCurrent?.() ?? owner.isCurrent()) {\n try {\n options.preview?.(undefined, ctx);\n } catch (error) {\n ctx.ui.notify(`Could not clear the footer preview: ${safeError(error)}`, \"error\");\n }\n }\n };\n const matches = (expected?: Document) => {\n if (!isCurrent()) return false;\n if (!expected) return true;\n try {\n const fresh =\n expected.kind === \"profile\"\n ? readProfile(options.settingsPath, expected.name)\n : readHistory(options.settingsPath, expected.name);\n return (\n fresh.rawDocument === expected.rawDocument &&\n fresh.identity.dev === expected.identity.dev &&\n fresh.identity.ino === expected.identity.ino &&\n fresh.identity.size === expected.identity.size &&\n fresh.identity.mtimeNs === expected.identity.mtimeNs &&\n fresh.identity.ctimeNs === expected.identity.ctimeNs &&\n fresh.rawBytes.equals(expected.rawBytes)\n );\n } catch {\n return false;\n }\n };\n const ensure = (expected?: Document) => {\n if (!isCurrent()) throw new FlowEnded();\n if (!matches(expected))\n throw new Error(\"The selected document changed or was removed. Review the latest copy before trying again.\");\n };\n signal.addEventListener(\"abort\", clearPreview, { once: true });\n return {\n signal,\n current: isCurrent,\n sessionCurrent: () => owner.isSessionCurrent?.() ?? owner.isCurrent(),\n ensure,\n preview(loaded: LoadedStarshipConfig | undefined) {\n ensure();\n if (!loaded) {\n clearPreview();\n return;\n }\n previewOwned = true;\n try {\n options.preview?.(loaded, ctx);\n } catch (error) {\n clearPreview();\n throw error;\n }\n },\n async dialog<Value>(run: () => Promise<Value>): Promise<Value> {\n ensure();\n // Native dialogs collapse Escape and Ctrl+C into one result. Observe only\n // hard cancellation; never consume, rewrite, or forward editor content.\n const unsubscribe = ctx.ui.onTerminalInput((data) => {\n if (!isKeyRelease(data) && matchesKey(data, Key.ctrl(\"c\"))) {\n // Abort after native input dispatch, before its promise continuation.\n // Synchronous abort could restore focus and leak this key to Pi's editor.\n queueMicrotask(() => controller.abort());\n }\n return undefined;\n });\n let released = false;\n const release = () => {\n if (released) return;\n released = true;\n unsubscribe();\n };\n signal.addEventListener(\"abort\", release, { once: true });\n try {\n if (signal.aborted) release();\n ensure();\n const result = await run();\n ensure();\n return result;\n } finally {\n signal.removeEventListener(\"abort\", release);\n release();\n }\n },\n adoptAppliedRevision() {\n if (signal.aborted || !(owner.isSessionCurrent?.() ?? owner.isCurrent())) throw new FlowEnded();\n revision = options.getLoadedRevision?.();\n activeDocument = activeFingerprint(options.getLoaded());\n },\n dispose() {\n try {\n clearPreview();\n } finally {\n signal.removeEventListener(\"abort\", clearPreview);\n controller.abort();\n }\n },\n };\n}\n\nfunction candidateFor(options: StarshipCommandOptions, raw: string | undefined, required = false): Candidate {\n try {\n if (raw === undefined) throw new Error(\"The document is not valid UTF-8; no decoded fallback is shown.\");\n const loaded = (options.validate ?? validateConfigDocument)(options.settingsPath, raw);\n if (loaded.diagnostics.some((item) => item.severity === \"error\"))\n throw new Error(loaded.diagnostics.map((item) => item.message).join(\"; \"));\n return {\n loaded,\n lines:\n loaded.diagnostics.length === 0\n ? [\"No configuration warnings.\"]\n : loaded.diagnostics.map((item) => `${safe(item.path || \"root\")}: ${safe(item.message)}`),\n };\n } catch (error) {\n if (required) throw error;\n return { lines: [`Invalid TOML: ${safeError(error)}`, \"No candidate footer preview is shown.\"] };\n }\n}\n\nfunction requireText(raw: string | undefined): string {\n if (raw === undefined) throw new Error(\"The document is not valid UTF-8; no decoded fallback can be saved.\");\n return raw;\n}\n\nfunction activeFingerprint(loaded: LoadedStarshipConfig) {\n return JSON.stringify([loaded.source, loaded.rawDocument, loaded.diagnostics]);\n}\n\nfunction current(owner: WorkflowOwner) {\n return !owner.signal.aborted && owner.isCurrent();\n}\n\nfunction interactive(ctx: ExtensionCommandContext) {\n if (ctx.mode === \"tui\" && ctx.hasUI) return true;\n if (ctx.hasUI) ctx.ui.notify(\"Profiles and History require TUI mode.\", \"info\");\n return false;\n}\n\nfunction documentId(document: Document) {\n return `${document.kind}:${document.name}`;\n}\n\nfunction report(ctx: ExtensionCommandContext, flow: ReturnType<typeof createFlow>, error: unknown) {\n if (!(error instanceof FlowEnded) && flow.current()) ctx.ui.notify(safeError(error), \"error\");\n}\n\nfunction safeError(error: unknown) {\n return safe(error instanceof Error ? error.message : String(error));\n}\n\nfunction safe(value: string) {\n return sanitizeTerminalText(value);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAuC,6BAA6B;AA2B7D,SAAS,yBAAyB,SAAyD;AAChG,SAAO;AAAA,IACL,UAAU,QAAQ,UAAU;AAAA,IAC5B,UAAU,QAAQ,oBAAoB;AAAA,IACtC,MAAM,2BAA2B,QAAQ,YAAY;AAAA,EACvD;AACF;AAEO,SAAS,mBACd,SACA,OACA,UACS;AACT,QAAM,SAAS,QAAQ,UAAU;AACjC,SACE,CAAC,MAAM,OAAO,WACd,MAAM,UAAU,KAChB,OAAO,gBAAgB,SAAS,SAAS,eACzC,OAAO,WAAW,SAAS,SAAS,UACpC,KAAK,UAAU,OAAO,WAAW,MAAM,KAAK,UAAU,SAAS,SAAS,WAAW,KACnF,QAAQ,oBAAoB,MAAM,SAAS;AAE/C;AAGA,eAAsB,qBACpB,KACA,SACA,WAC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AAQ,OAAsB;AACrC,SAAO,CAAC,MAAM,OAAO,WAAW,MAAM,UAAU;AAClD;AAEA,SAAS,YAAY,KAA8B;AACjD,MAAI,IAAI,SAAS,SAAS,IAAI,MAAO,QAAO;AAC5C,MAAI,IAAI,MAAO,KAAI,GAAG,OAAO,0CAA0C,MAAM;AAC7E,SAAO;AACT;AAEA,SAAS,WAAW,UAAoB;AACtC,SAAO,GAAG,SAAS,IAAI,IAAI,SAAS,IAAI;AAC1C;AAEA,SAAS,OAAO,KAA8B,MAAqC,OAAgB;AACjG,MAAI,EAAE,iBAAiB,cAAc,KAAK,QAAQ,EAAG,KAAI,GAAG,OAAO,UAAU,KAAK,GAAG,OAAO;AAC9F;AAEA,SAAS,UAAU,OAAgB;AACjC,SAAO,KAAK,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AACpE;AAEA,SAAS,KAAK,OAAe;AAC3B,SAAO,qBAAqB,KAAK;AACnC;",
|
|
6
6
|
"names": ["current", "document"]
|
|
7
7
|
}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
commitActiveDocument,
|
|
6
6
|
commitOwnerCurrent,
|
|
7
7
|
saveAsProfile
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-D563JANR.ts";
|
|
9
9
|
import {
|
|
10
10
|
assertProfileUnchanged,
|
|
11
11
|
configurationPresentation
|
|
@@ -117,6 +117,7 @@ import {
|
|
|
117
117
|
matchesKey,
|
|
118
118
|
TuiAltScreen
|
|
119
119
|
} from "@earendil-works/pi-tui";
|
|
120
|
+
import { createFullscreenHandoff } from "@narumitw/pi-tui-kit/fullscreen-handoff";
|
|
120
121
|
var SettingsChatTui = class extends TuiAltScreen {
|
|
121
122
|
addInputListener(listener) {
|
|
122
123
|
if (!this.guardInstalled) {
|
|
@@ -138,16 +139,17 @@ async function runSettingsChatFullscreen(ctx, owner, create, cancelledValue, dep
|
|
|
138
139
|
const controller = new AbortController();
|
|
139
140
|
let child;
|
|
140
141
|
let component;
|
|
141
|
-
let overlay;
|
|
142
|
-
let parentStopped = false;
|
|
143
142
|
let entry;
|
|
144
|
-
let entryDrainStarted = false;
|
|
145
143
|
let finished = false;
|
|
146
144
|
let closing = false;
|
|
147
145
|
let cleanup;
|
|
148
146
|
let pasting = false;
|
|
149
147
|
let result = { value: cancelledValue };
|
|
150
148
|
const errors = [];
|
|
149
|
+
const handoff = createFullscreenHandoff(parent, {
|
|
150
|
+
isCurrent: () => !closing && current(),
|
|
151
|
+
canRestoreParent: canRestoreTerminal
|
|
152
|
+
});
|
|
151
153
|
const removers = [];
|
|
152
154
|
const attempt = (action) => {
|
|
153
155
|
try {
|
|
@@ -163,28 +165,12 @@ async function runSettingsChatFullscreen(ctx, owner, create, cancelledValue, dep
|
|
|
163
165
|
controller.abort();
|
|
164
166
|
cleanup = Promise.resolve().then(async () => {
|
|
165
167
|
await entry;
|
|
166
|
-
if (parentStopped) {
|
|
167
|
-
try {
|
|
168
|
-
await parent.terminal.drainInput?.();
|
|
169
|
-
} catch (error) {
|
|
170
|
-
errors.push(error);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
if (entryDrainStarted && !parentStopped) {
|
|
174
|
-
parentStopped = true;
|
|
175
|
-
attempt(() => parent.stop({ preserveScreen: true }));
|
|
176
|
-
}
|
|
177
168
|
for (const remove of removers.splice(0)) attempt(remove);
|
|
178
169
|
attempt(() => component?.dispose?.());
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
if (canRestoreTerminal()) {
|
|
184
|
-
attempt(() => parent.start());
|
|
185
|
-
attempt(() => parent.renderNow(false));
|
|
186
|
-
}
|
|
187
|
-
});
|
|
170
|
+
try {
|
|
171
|
+
await handoff.restore();
|
|
172
|
+
} catch (error) {
|
|
173
|
+
errors.push(error);
|
|
188
174
|
}
|
|
189
175
|
try {
|
|
190
176
|
await component?.waitForPending?.();
|
|
@@ -242,44 +228,41 @@ async function runSettingsChatFullscreen(ctx, owner, create, cancelledValue, dep
|
|
|
242
228
|
}
|
|
243
229
|
};
|
|
244
230
|
mount = (handle) => {
|
|
245
|
-
|
|
231
|
+
handoff.setOverlayHandle(handle);
|
|
246
232
|
queueMicrotask(() => {
|
|
247
233
|
if (closing) return;
|
|
248
234
|
entry = (async () => {
|
|
249
235
|
try {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
236
|
+
child = await handoff.enter(() => {
|
|
237
|
+
const createDefault = () => new SettingsChatTui(parent.terminal, parent.getShowHardwareCursor(), void 0, { mouse: true });
|
|
238
|
+
const created = dependencies.createTui?.(parent, createDefault) ?? createDefault();
|
|
239
|
+
child = created;
|
|
240
|
+
try {
|
|
241
|
+
if (created instanceof SettingsChatTui) created.guard = guard;
|
|
242
|
+
else removers.push(created.addInputListener(guard));
|
|
243
|
+
component = create({
|
|
244
|
+
tui: created,
|
|
245
|
+
theme,
|
|
246
|
+
keybindings,
|
|
247
|
+
signal: controller.signal,
|
|
248
|
+
complete: (value) => finish({ value })
|
|
249
|
+
});
|
|
250
|
+
if (!closing && current()) {
|
|
251
|
+
created.setLayoutRoot(component.getFullscreenLayout?.() ?? component);
|
|
252
|
+
created.setFocus(component);
|
|
253
|
+
}
|
|
254
|
+
return created;
|
|
255
|
+
} catch (error) {
|
|
256
|
+
controller.abort();
|
|
257
|
+
try {
|
|
258
|
+
created.stop({ preserveScreen: true });
|
|
259
|
+
} catch (cleanupError) {
|
|
260
|
+
throw new AggregateError([error, cleanupError], "Fullscreen child factory cleanup failed");
|
|
261
|
+
}
|
|
262
|
+
throw error;
|
|
263
|
+
}
|
|
274
264
|
});
|
|
275
|
-
if (closing)
|
|
276
|
-
if (!current()) {
|
|
277
|
-
cancel();
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
child.setLayoutRoot(component.getFullscreenLayout?.() ?? component);
|
|
281
|
-
child.setFocus(component);
|
|
282
|
-
child.start();
|
|
265
|
+
if (!child && !closing) cancel();
|
|
283
266
|
} catch (error) {
|
|
284
267
|
if (closing) errors.push(error);
|
|
285
268
|
else finish({ error });
|
|
@@ -1474,4 +1457,4 @@ async function reviewText(ctx, owner, title, content, toml) {
|
|
|
1474
1457
|
export {
|
|
1475
1458
|
showSettingsAgentChat
|
|
1476
1459
|
};
|
|
1477
|
-
//# sourceMappingURL=command-settings-chat-
|
|
1460
|
+
//# sourceMappingURL=command-settings-chat-B2FCDVBH.ts.map
|