@narumitw/pi-starship 0.60.1 → 0.62.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -6
- package/dist/chunks/chunk-43VIENBN.ts +1586 -0
- package/dist/chunks/chunk-43VIENBN.ts.map +7 -0
- package/dist/chunks/chunk-HPZTMIZS.ts +646 -0
- package/dist/chunks/chunk-HPZTMIZS.ts.map +7 -0
- package/dist/chunks/chunk-IYDZ3R2T.ts +69 -0
- package/dist/chunks/chunk-IYDZ3R2T.ts.map +7 -0
- package/dist/chunks/chunk-KP33I6BR.ts +579 -0
- package/dist/chunks/chunk-KP33I6BR.ts.map +7 -0
- package/dist/chunks/{chunk-KZZKGGFW.ts → chunk-PWTSHSP3.ts} +853 -1001
- package/dist/chunks/chunk-PWTSHSP3.ts.map +7 -0
- package/dist/chunks/{chunk-PD457PX5.ts → chunk-S2KBLHE2.ts} +75 -10
- package/dist/chunks/chunk-S2KBLHE2.ts.map +7 -0
- package/dist/chunks/chunk-XQUIQO2G.ts +20 -0
- package/dist/chunks/chunk-XQUIQO2G.ts.map +7 -0
- package/dist/chunks/{chunk-ADX4CY27.ts → chunk-XTLQ4WUL.ts} +1 -1
- package/dist/chunks/chunk-XTLQ4WUL.ts.map +7 -0
- package/dist/chunks/{cloud-EPAEV4ZB.ts → cloud-J2ZOE3HE.ts} +6 -2
- package/dist/chunks/cloud-J2ZOE3HE.ts.map +7 -0
- package/dist/chunks/command-configuration-menu-S2LXCOJG.ts +147 -0
- package/dist/chunks/command-configuration-menu-S2LXCOJG.ts.map +7 -0
- package/dist/chunks/command-settings-chat-O34BEU4X.ts +1041 -0
- package/dist/chunks/command-settings-chat-O34BEU4X.ts.map +7 -0
- package/dist/chunks/commands-ZYIJVIEJ.ts +1022 -0
- package/dist/chunks/commands-ZYIJVIEJ.ts.map +7 -0
- package/dist/chunks/{deployment-7J54EHNR.ts → deployment-NOJ2KCLI.ts} +85 -5
- package/dist/chunks/deployment-NOJ2KCLI.ts.map +7 -0
- package/dist/chunks/{development-IWJAAAEV.ts → development-T3XXVVDP.ts} +67 -15
- package/dist/chunks/development-T3XXVVDP.ts.map +7 -0
- package/dist/chunks/directory-OX6BWJZA.ts +31 -0
- package/dist/chunks/directory-OX6BWJZA.ts.map +7 -0
- package/dist/chunks/{execution-P4WZALW2.ts → execution-R2OHIP2L.ts} +8 -4
- package/dist/chunks/execution-R2OHIP2L.ts.map +7 -0
- package/dist/chunks/jujutsu-XLDYKSX2.ts +174 -0
- package/dist/chunks/jujutsu-XLDYKSX2.ts.map +7 -0
- package/dist/chunks/languages-CBQNNYXM.ts +262 -0
- package/dist/chunks/languages-CBQNNYXM.ts.map +7 -0
- package/dist/chunks/{package-H24VJEX3.ts → package-7KVAK3TC.ts} +6 -2
- package/dist/chunks/package-7KVAK3TC.ts.map +7 -0
- package/dist/chunks/system-574MHB4R.ts +165 -0
- package/dist/chunks/system-574MHB4R.ts.map +7 -0
- package/dist/index.ts +558 -150
- package/dist/index.ts.map +4 -4
- package/package.json +5 -1
- package/skills/configure-pi-starship/SKILL.md +14 -0
- package/skills/configure-pi-starship/references/configuration.md +109 -24
- package/skills/configure-pi-starship/references/module-catalog.md +278 -25
- package/skills/configure-pi-starship/references/modules.md +213 -36
- package/skills/configure-pi-starship/references/runtime-and-security.md +88 -28
- package/src/command-configuration-menu.ts +155 -0
- package/src/command-configuration.ts +9 -84
- package/src/command-preview.ts +3 -3
- package/src/command-settings-chat.ts +210 -0
- package/src/commands.ts +54 -98
- package/src/config/module-options.ts +112 -0
- package/src/config.ts +17 -53
- package/src/effective-config.ts +5 -4
- package/src/format/bounded-regex.ts +66 -0
- package/src/format/version.ts +24 -0
- package/src/modules/catalog.ts +10 -0
- package/src/modules/cloud.ts +1 -0
- package/src/modules/deployment.ts +8 -0
- package/src/modules/development.ts +20 -2
- package/src/modules/directory.ts +171 -51
- package/src/modules/execution.ts +2 -0
- package/src/modules/git/branch.ts +19 -4
- package/src/modules/git/commit.ts +9 -2
- package/src/modules/git/metrics.ts +9 -4
- package/src/modules/git/runtime.ts +122 -33
- package/src/modules/git/state.ts +23 -2
- package/src/modules/git/status-templates.ts +58 -0
- package/src/modules/git/status.ts +96 -30
- package/src/modules/jujutsu.ts +225 -0
- package/src/modules/languages.ts +26 -2
- package/src/modules/package.ts +1 -0
- package/src/modules/render.ts +42 -16
- package/src/modules/system.ts +54 -0
- package/src/modules/time-format.ts +188 -0
- package/src/modules/time.ts +11 -5
- package/src/modules/types.ts +42 -4
- package/src/pi-starship.ts +56 -12
- package/src/profile-store.ts +5 -0
- package/src/runtime/cloud.ts +3 -0
- package/src/runtime/command.ts +1 -1
- package/src/runtime/deployment.ts +120 -4
- package/src/runtime/development.ts +86 -13
- package/src/runtime/directory.ts +33 -0
- package/src/runtime/execution.ts +12 -2
- package/src/runtime/helpers.ts +57 -8
- package/src/runtime/jujutsu.ts +225 -0
- package/src/runtime/languages.ts +106 -19
- package/src/runtime/package.ts +3 -0
- package/src/runtime/system.ts +202 -0
- package/src/runtime/types.ts +3 -0
- package/src/runtime/version-requirements.ts +30 -0
- package/src/runtime/workspace.ts +12 -1
- package/src/settings-agent.ts +80 -0
- package/src/settings-chat-transcript.ts +140 -0
- package/src/settings-chat-ui.ts +426 -0
- package/src/settings-draft.ts +260 -0
- package/src/settings-snapshots.ts +41 -0
- package/dist/chunks/chunk-ADX4CY27.ts.map +0 -7
- package/dist/chunks/chunk-KZZKGGFW.ts.map +0 -7
- package/dist/chunks/chunk-PD457PX5.ts.map +0 -7
- package/dist/chunks/cloud-EPAEV4ZB.ts.map +0 -7
- package/dist/chunks/commands-C2VJ6ZBN.ts +0 -3374
- package/dist/chunks/commands-C2VJ6ZBN.ts.map +0 -7
- package/dist/chunks/deployment-7J54EHNR.ts.map +0 -7
- package/dist/chunks/development-IWJAAAEV.ts.map +0 -7
- package/dist/chunks/execution-P4WZALW2.ts.map +0 -7
- package/dist/chunks/languages-JO6R2PHL.ts +0 -168
- package/dist/chunks/languages-JO6R2PHL.ts.map +0 -7
- package/dist/chunks/package-H24VJEX3.ts.map +0 -7
- package/src/command-inspector.ts +0 -41
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/commands.ts", "../../src/command-gist.ts", "../../src/gist.ts", "../../src/command-preset-picker.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ExtensionAPI, ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport { isKeyRelease, Key, matchesKey } from \"@earendil-works/pi-tui\";\nimport { defineMenu, runMenu } from \"@narumitw/pi-tui-kit\";\nimport {\n type CommitExpectation,\n type CommitOptions,\n captureCommitExpectation,\n commitActiveDocument,\n commitOwnerCurrent,\n} from \"./command-commit.js\";\nimport {\n type ConfigurationCommandOptions,\n configurationPresentation,\n reloadConfiguration,\n type WorkflowOwner,\n} from \"./command-configuration.js\";\nimport { completeStarshipArguments, STARSHIP_SUBCOMMANDS } from \"./command-contract.js\";\nimport { importSettingsGist, shareSettingsGist } from \"./command-gist.js\";\nimport { showPresetPicker } from \"./command-preset-picker.js\";\nimport { type PreviewMenuResult, showPreviewActionMenu } from \"./command-preview.js\";\nimport { saveAsProfile, showHistory, showProfiles } from \"./command-profiles.js\";\nimport { BUILT_IN_EXAMPLE, type LoadedStarshipConfig, validateConfigDocument } from \"./config.js\";\nimport type { GhApi } from \"./gist.js\";\nimport type { StatuslineInspection } from \"./modules/inspection.js\";\nimport { getStarshipPreset, presetForDocument, STARSHIP_PRESETS, type StarshipPreset } from \"./presets/catalog.js\";\n\nconst MAIN_ACTIONS = {\n presets: \"presets\",\n configuration: \"configuration\",\n help: \"help\",\n restore: \"restore\",\n profiles: \"profiles\",\n chat: \"settings-chat\",\n} as const;\n\nconst PREVIEW_ACTIONS = {\n continue: \"continue\",\n edit: \"edit\",\n cancel: \"cancel\",\n saveProfile: \"save-profile\",\n} as const;\n\nexport interface StarshipCommandOptions extends ConfigurationCommandOptions, CommitOptions {\n getInspection?(): StatuslineInspection | undefined;\n preview?(loaded: LoadedStarshipConfig | undefined, ctx: ExtensionCommandContext): void;\n save?: (settingsPath: string, rawDocument: string) => LoadedStarshipConfig;\n restore?: (settingsPath: string, rawDocument: string) => void;\n validate?: (settingsPath: string, rawDocument: string) => LoadedStarshipConfig;\n getMenuOwner?(): WorkflowOwner;\n gistApi?: GhApi;\n registerChatCleanup?(cleanup: () => Promise<void>): () => void;\n}\n\nexport type ReviewIntent =\n | { kind: \"customize\" }\n | { kind: \"restore\" }\n | { kind: \"import\" }\n | { kind: \"profile\"; name: string }\n | { kind: \"history\"; name?: string }\n | { kind: \"preset\"; preset: StarshipPreset };\n\nexport function registerStarshipCommand(pi: ExtensionAPI, options: StarshipCommandOptions) {\n pi.registerCommand(\"starship\", {\n description: \"Configure the footer with agent, presets, profiles, and recovery\",\n getArgumentCompletions: completeStarshipArguments,\n handler: (args, ctx) => handleStarshipCommand(args, ctx, options),\n });\n}\n\nexport async function handleStarshipCommand(\n args: string,\n ctx: ExtensionCommandContext,\n options: StarshipCommandOptions,\n) {\n if (ctx.mode !== \"tui\") return runStarshipCommand(args, ctx, options);\n const base = workflowOwner(options);\n if (!isCurrentOwner(base)) return;\n const controller = new AbortController();\n const signal = AbortSignal.any([base.signal, controller.signal]);\n const owner: WorkflowOwner = {\n signal,\n isCurrent: () => !signal.aborted && base.isCurrent(),\n isSessionCurrent: () => base.isSessionCurrent?.() ?? base.isCurrent(),\n };\n // Pi delivers bracketed paste as one framed packet. Exact key matching does\n // not treat controls inside pasted text as cancellation or consume native input.\n const unsubscribe = ctx.ui.onTerminalInput((data) => {\n if (!isKeyRelease(data) && matchesKey(data, Key.ctrl(\"c\"))) {\n // Let the current native dialog receive this input before abort restores\n // focus; otherwise the same key can reach the underlying editor.\n queueMicrotask(() => controller.abort());\n }\n return undefined;\n });\n let listening = true;\n const release = () => {\n if (!listening) return;\n listening = false;\n unsubscribe();\n };\n signal.addEventListener(\"abort\", release, { once: true });\n try {\n return await runStarshipCommand(args, ctx, { ...options, getMenuOwner: () => owner });\n } finally {\n signal.removeEventListener(\"abort\", release);\n release();\n controller.abort();\n }\n}\n\nasync function runStarshipCommand(args: string, ctx: ExtensionCommandContext, options: StarshipCommandOptions) {\n const normalized = args.trim();\n if (!normalized) {\n if (ctx.mode === \"tui\") await showMainMenu(ctx, options);\n else showHelp(ctx, options.settingsPath);\n return;\n }\n\n const [subcommand = \"\", ...trailing] = normalized.split(/\\s+/u);\n const route = subcommand.toLowerCase();\n if (trailing.length > 0 || !STARSHIP_SUBCOMMANDS.some((item) => item.value === route)) {\n if (canNotify(ctx)) {\n const reason =\n trailing.length > 0\n ? `Unexpected arguments for /starship ${safeText(route)}.`\n : `Unknown /starship subcommand: ${safeText(route)}.`;\n ctx.ui.notify(`${reason} Usage: /starship [settings|status|help]`, \"warning\");\n }\n return;\n }\n switch (route) {\n case \"settings\":\n await editSettings(ctx, options);\n return;\n case \"status\":\n showStatus(ctx, options);\n return;\n case \"help\":\n showHelp(ctx, options.settingsPath);\n return;\n }\n}\n\nasync function showMainMenu(ctx: ExtensionCommandContext, options: StarshipCommandOptions) {\n const fallbackController = new AbortController();\n const owner = options.getMenuOwner?.() ?? {\n signal: fallbackController.signal,\n isCurrent: () => !fallbackController.signal.aborted,\n };\n type Screen = \"main\" | \"help\";\n type Action =\n | \"configuration\"\n | \"presets\"\n | \"profiles\"\n | \"history\"\n | \"configuration-reload\"\n | \"restore\"\n | \"gist-share\"\n | \"gist-import\"\n | \"settings-chat\";\n const menu = defineMenu<undefined, Screen, Action, ExtensionCommandContext>({\n start: \"main\",\n screens: {\n main: () => {\n const loaded = options.getLoaded();\n const presentation = configurationPresentation(loaded);\n return {\n kind: \"actions\",\n title: \"pi-starship\",\n lines: [\n `${presentation.state} \u00B7 ${presentation.health}`,\n \"Configure with agent for edits, module questions, and footer explanations.\",\n ],\n items: [\n {\n id: MAIN_ACTIONS.chat,\n label: \"Configure with agent\",\n description: \"Separate conversation \u00B7 draft tools \u00B7 live preview only until you save\",\n action: \"settings-chat\",\n },\n {\n id: MAIN_ACTIONS.presets,\n label: \"Presets\",\n description: \"Browse and live-preview bundled footer starting points\",\n action: \"presets\",\n },\n {\n id: MAIN_ACTIONS.profiles,\n label: \"Profiles\",\n description: \"Save, edit, manage, and live-preview named TOML documents\",\n action: \"profiles\",\n },\n {\n id: MAIN_ACTIONS.configuration,\n label: \"Configuration\",\n description: presentation.health,\n action: \"configuration\",\n },\n {\n id: MAIN_ACTIONS.restore,\n label: \"Restore built-in\u2026\",\n description: presentation.restoreDescription,\n disabled: presentation.restoreDisabled,\n action: \"restore\",\n },\n {\n id: MAIN_ACTIONS.help,\n label: \"Help\",\n description: \"Settings, modules, and commands\",\n to: \"help\",\n },\n ],\n hint: \"close\",\n };\n },\n help: () => ({\n kind: \"detail\",\n title: \"pi-starship help\",\n lines: [\n \"/starship settings retains the TOML editor with preview and confirmation.\",\n \"Configure with agent opens a separate skill-backed chat; edits preview only until you explicitly save.\",\n \"Presets live-previews the cursor in the footer; Enter confirms apply, e customizes, and s saves a profile when available.\",\n \"Profiles manages named TOML copies; selecting a document previews it without saving.\",\n \"Configuration History reviews and restores recovery copies; external edits are not fully tracked.\",\n \"Ask Configure with agent about active settings and module states captured when the chat opens.\",\n \"Configuration includes disk reload plus unlisted Gist sharing and reviewed Gist import through gh.\",\n `Settings: ${safeText(options.settingsPath)}`,\n \"Docs: https://github.com/narumiruna/pi-extensions/tree/main/packages/pi-starship\",\n ],\n hint: \"back\",\n }),\n },\n actions: {\n \"settings-chat\": async () => {\n const { showSettingsAgentChat } = await import(\"./command-settings-chat.js\");\n if (!isCurrentOwner(owner)) return { kind: \"close\" };\n await showSettingsAgentChat(ctx, options, owner);\n return { kind: \"close\" };\n },\n configuration: async () => {\n const { showConfigurationMenu } = await import(\"./command-configuration-menu.js\");\n if (!isCurrentOwner(owner)) return { kind: \"close\" };\n let selected: string | undefined;\n while (isCurrentOwner(owner)) {\n const result = await showConfigurationMenu(ctx, options, owner, selected);\n if (!isCurrentOwner(owner) || result.kind !== \"completed\") return { kind: \"close\" };\n if (result.value === \"back\") return { kind: \"stay\" };\n if (result.value === \"close\") return { kind: \"close\" };\n selected = result.value;\n const transition = await menu.actions[result.value]({\n ctx,\n state: undefined,\n signal: owner.signal,\n itemId: result.value,\n });\n if (!isCurrentOwner(owner) || transition?.kind === \"close\") return { kind: \"close\" };\n }\n return { kind: \"close\" };\n },\n presets: async () => {\n const result = await choosePreset(ctx, options, owner);\n return result === \"applied\" || result === \"close\" ? { kind: \"close\" } : { kind: \"stay\" };\n },\n profiles: async () => {\n const result = await showProfiles(ctx, options, owner, async (loaded, guardedOwner, checkCandidate, name) => {\n const applied = await reviewAndApply(\n ctx,\n options,\n loaded,\n { kind: \"profile\", name },\n guardedOwner,\n false,\n checkCandidate,\n );\n return applied === \"applied\" ? \"applied\" : applied === \"close\" ? \"close\" : \"stay\";\n });\n return result === \"close\" ? { kind: \"close\" } : { kind: \"stay\" };\n },\n history: async () => {\n const result = await showHistory(ctx, options, owner, async (loaded, guardedOwner, checkCandidate, name) => {\n const applied = await reviewAndApply(\n ctx,\n options,\n loaded,\n { kind: \"history\", name },\n guardedOwner,\n false,\n checkCandidate,\n );\n return applied === \"applied\" ? \"applied\" : applied === \"close\" ? \"close\" : \"stay\";\n });\n return result === \"close\" ? { kind: \"close\" } : { kind: \"stay\" };\n },\n \"gist-share\": async () => {\n const result = await shareSettingsGist(ctx, options, owner, options.gistApi);\n return result === \"close\" ? { kind: \"close\" } : { kind: \"stay\" };\n },\n \"gist-import\": async () => {\n const result = await importSettingsGist(\n ctx,\n options,\n owner,\n async (loaded, guardedOptions, guardedOwner) => {\n const applied = await reviewAndApply(ctx, guardedOptions, loaded, { kind: \"import\" }, guardedOwner);\n return applied === \"edit\" ? \"cancel\" : applied;\n },\n options.gistApi,\n );\n return result === \"applied\" || result === \"close\" ? { kind: \"close\" } : { kind: \"stay\" };\n },\n \"configuration-reload\": async () => {\n const result = await reloadConfiguration(ctx, options, owner);\n return result === \"close\" ? { kind: \"close\" } : { kind: \"stay\" };\n },\n restore: async () => {\n const presentation = configurationPresentation(options.getLoaded());\n if (presentation.restoreDisabled) {\n ctx.ui.notify(presentation.restoreDescription, \"info\");\n return { kind: \"stay\" };\n }\n const result = await restoreBuiltIn(ctx, options);\n return result === \"applied\" || result === \"close\" ? { kind: \"close\" } : { kind: \"stay\" };\n },\n },\n });\n try {\n await runMenu(ctx, menu, {\n getState: () => undefined,\n signal: owner.signal,\n isCurrent: owner.isCurrent,\n });\n } finally {\n fallbackController.abort(new DOMException(\"Starship menu closed\", \"AbortError\"));\n }\n}\n\nasync function editSettings(\n ctx: ExtensionCommandContext,\n options: StarshipCommandOptions,\n): Promise<\"applied\" | \"cancel\" | \"close\"> {\n const owner = workflowOwner(options);\n if (!isCurrentOwner(owner)) return \"cancel\";\n if (ctx.mode !== \"tui\") {\n if (ctx.hasUI) ctx.ui.notify(`Edit settings manually: ${options.settingsPath}`, \"info\");\n return \"cancel\";\n }\n const expected = captureExpectation(ctx, options);\n if (!expected) return \"cancel\";\n let draft = expected.previous.rawDocument ?? BUILT_IN_EXAMPLE;\n while (true) {\n const edited = await ctx.ui.editor(\"Customize footer \u2014 close to preview\", draft);\n if (!commitOwnerCurrent(options, owner, expected) || edited === undefined) return \"cancel\";\n draft = edited;\n let validated: LoadedStarshipConfig;\n try {\n validated = (options.validate ?? validateConfigDocument)(options.settingsPath, draft);\n } catch (error) {\n ctx.ui.notify(`Footer draft is invalid: ${safeText(formatError(error))}`, \"error\");\n const action = await showPreviewActionMenu(\n ctx,\n \"Configuration needs attention\",\n () => [safeText(formatError(error)), \"The current footer has not changed.\"],\n [\n { value: PREVIEW_ACTIONS.edit, label: \"Continue editing\" },\n { value: PREVIEW_ACTIONS.cancel, label: \"Discard draft\" },\n ],\n owner.signal,\n owner.isCurrent,\n );\n if (!commitOwnerCurrent(options, owner, expected)) return \"cancel\";\n if (action?.kind === \"closed\") return \"close\";\n if (selectedPreviewAction(action) === PREVIEW_ACTIONS.edit) continue;\n return \"cancel\";\n }\n\n const result = await reviewAndApply(\n ctx,\n options,\n validated,\n { kind: \"customize\" },\n owner,\n false,\n undefined,\n expected,\n );\n if (result === \"edit\") continue;\n return result;\n }\n}\n\nasync function choosePreset(\n ctx: ExtensionCommandContext,\n options: StarshipCommandOptions,\n owner: WorkflowOwner,\n): Promise<\"applied\" | \"cancel\" | \"close\"> {\n const expected = captureExpectation(ctx, options);\n if (!expected) return \"cancel\";\n const activePreset = presetForDocument(expected.previous.rawDocument);\n const selection = await showPresetPicker(ctx, {\n presets: STARSHIP_PRESETS,\n activePresetId: activePreset?.id,\n initialPresetId: activePreset?.id ?? STARSHIP_PRESETS[0]?.id,\n signal: owner.signal,\n isCurrent: owner.isCurrent,\n preview(preset) {\n const loaded = (options.validate ?? validateConfigDocument)(options.settingsPath, preset.rawDocument);\n options.preview?.(loaded, ctx);\n },\n });\n if (!commitOwnerCurrent(options, owner, expected)) {\n clearSessionPreview(ctx, options, owner);\n return \"cancel\";\n }\n if (selection.kind === \"back\" || selection.kind === \"close\") {\n clearSessionPreview(ctx, options, owner);\n return selection.kind === \"close\" ? \"close\" : \"cancel\";\n }\n\n const preset = getStarshipPreset(selection.presetId);\n try {\n if (selection.kind === \"save-profile\") {\n const saved = await saveAsProfile(ctx, options, owner, preset.rawDocument);\n return saved === \"close\" ? \"close\" : \"cancel\";\n }\n return await applyPreset(\n ctx,\n options,\n preset,\n selection.kind === \"customize\" ? \"customize\" : \"confirm\",\n expected,\n owner,\n );\n } finally {\n clearSessionPreview(ctx, options, owner);\n }\n}\n\nasync function applyPreset(\n ctx: ExtensionCommandContext,\n options: StarshipCommandOptions,\n preset: StarshipPreset,\n start: \"review\" | \"confirm\" | \"customize\" = \"review\",\n captured?: CommitExpectation,\n capturedOwner?: WorkflowOwner,\n): Promise<\"applied\" | \"cancel\" | \"close\"> {\n const owner = capturedOwner ?? workflowOwner(options);\n if (!isCurrentOwner(owner)) return \"cancel\";\n const expected = captured ?? captureExpectation(ctx, options);\n if (!expected) return \"cancel\";\n let draft = preset.rawDocument;\n if (start === \"customize\") {\n const edited = await ctx.ui.editor(`Customize ${preset.label} preset`, draft);\n if (!commitOwnerCurrent(options, owner, expected) || edited === undefined) return \"cancel\";\n draft = edited;\n }\n while (true) {\n let validated: LoadedStarshipConfig;\n try {\n validated = (options.validate ?? validateConfigDocument)(options.settingsPath, draft);\n } catch (error) {\n ctx.ui.notify(`Preset draft is invalid: ${safeText(formatError(error))}`, \"error\");\n const action = await showPreviewActionMenu(\n ctx,\n \"Preset needs attention\",\n () => [safeText(formatError(error)), \"The current footer has not changed.\"],\n [\n { value: PREVIEW_ACTIONS.edit, label: \"Continue editing\" },\n { value: PREVIEW_ACTIONS.cancel, label: \"Choose another preset\" },\n ],\n owner.signal,\n owner.isCurrent,\n );\n if (!commitOwnerCurrent(options, owner, expected)) return \"cancel\";\n if (action?.kind === \"closed\") return \"close\";\n if (selectedPreviewAction(action) !== PREVIEW_ACTIONS.edit) return \"cancel\";\n const edited = await ctx.ui.editor(`Customize ${preset.label} preset`, draft);\n if (!commitOwnerCurrent(options, owner, expected) || edited === undefined) return \"cancel\";\n draft = edited;\n continue;\n }\n\n const result = await reviewAndApply(\n ctx,\n options,\n validated,\n { kind: \"preset\", preset },\n owner,\n start === \"confirm\",\n undefined,\n expected,\n );\n if (result !== \"edit\") return result;\n const edited = await ctx.ui.editor(`Customize ${preset.label} preset`, draft);\n if (!commitOwnerCurrent(options, owner, expected) || edited === undefined) return \"cancel\";\n draft = edited;\n }\n}\n\nasync function restoreBuiltIn(\n ctx: ExtensionCommandContext,\n options: StarshipCommandOptions,\n): Promise<\"applied\" | \"cancel\" | \"close\"> {\n const owner = workflowOwner(options);\n if (!isCurrentOwner(owner)) return \"cancel\";\n const validated = (options.validate ?? validateConfigDocument)(options.settingsPath, BUILT_IN_EXAMPLE);\n const result = await reviewAndApply(ctx, options, validated, { kind: \"restore\" }, owner);\n return result === \"edit\" ? \"cancel\" : result;\n}\n\nexport async function reviewAndApply(\n ctx: ExtensionCommandContext,\n options: StarshipCommandOptions,\n validated: LoadedStarshipConfig,\n intent: ReviewIntent,\n owner: WorkflowOwner,\n skipReview = false,\n checkCandidate?: () => void,\n captured?: CommitExpectation,\n): Promise<\"applied\" | \"edit\" | \"cancel\" | \"close\"> {\n if (ctx.mode !== \"tui\" || !isCurrentOwner(owner)) return \"cancel\";\n const expected = captured ?? captureExpectation(ctx, options);\n if (!expected) return \"cancel\";\n let reviewRequired = !skipReview;\n while (true) {\n const directAttempt = !reviewRequired;\n if (reviewRequired) {\n const selection = await showPreviewActionMenu(\n ctx,\n reviewTitle(intent),\n (width) => reviewPreviewBody(ctx, options, validated, width, intent),\n [\n { value: PREVIEW_ACTIONS.continue, label: continueLabel(intent) },\n ...(intent.kind !== \"customize\" && intent.kind !== \"preset\"\n ? []\n : [\n {\n value: PREVIEW_ACTIONS.edit,\n label: intent.kind === \"preset\" ? \"Customize before applying\" : \"Continue editing\",\n },\n ]),\n {\n value: PREVIEW_ACTIONS.cancel,\n label:\n intent.kind === \"restore\"\n ? \"Cancel\"\n : intent.kind === \"preset\"\n ? \"Choose another preset\"\n : \"Discard draft\",\n },\n ...(intent.kind === \"customize\" || intent.kind === \"preset\" || intent.kind === \"import\"\n ? [{ value: PREVIEW_ACTIONS.saveProfile, label: \"Save as profile\u2026\" }]\n : []),\n ],\n owner.signal,\n owner.isCurrent,\n );\n if (!commitOwnerCurrent(options, owner, expected)) return \"cancel\";\n if (selection?.kind === \"closed\") return \"close\";\n const selected = selectedPreviewAction(selection);\n if (selected === PREVIEW_ACTIONS.edit) return \"edit\";\n if (selected === PREVIEW_ACTIONS.saveProfile) {\n const saved = await saveAsProfile(ctx, options, owner, validated.rawDocument ?? BUILT_IN_EXAMPLE);\n if (saved === \"close\") return \"close\";\n if (!commitOwnerCurrent(options, owner, expected)) return \"cancel\";\n continue;\n }\n if (selected !== PREVIEW_ACTIONS.continue) return \"cancel\";\n }\n reviewRequired = true;\n\n const confirmed = await ctx.ui.confirm(\n confirmationTitle(intent),\n confirmationMessage(options.settingsPath, intent, expected.previous),\n { signal: owner.signal },\n );\n if (!commitOwnerCurrent(options, owner, expected)) return \"cancel\";\n if (!confirmed) {\n if (directAttempt) return \"cancel\";\n continue;\n }\n\n try {\n const result = await commitActiveDocument(\n ctx,\n options,\n validated,\n owner,\n expected,\n intent.kind === \"restore\" || intent.kind === \"history\" || intent.kind === \"customize\",\n checkCandidate,\n );\n if (!isSessionOwnerCurrent(owner) || result === \"cancel\") return \"cancel\";\n } catch (error) {\n if (!isSessionOwnerCurrent(owner)) return \"cancel\";\n ctx.ui.notify(safeText(formatError(error)), \"error\");\n if (directAttempt) return \"cancel\";\n continue;\n }\n\n const warningSuffix =\n validated.diagnostics.length > 0\n ? ` (${validated.diagnostics.length} warning${validated.diagnostics.length === 1 ? \"\" : \"s\"})`\n : \"\";\n ctx.ui.notify(`${successMessage(intent)}${warningSuffix}.`, \"info\");\n return \"applied\";\n }\n}\n\nfunction reviewTitle(intent: ReviewIntent): string {\n switch (intent.kind) {\n case \"customize\":\n return \"Footer preview\";\n case \"restore\":\n return \"Restore preview\";\n case \"import\":\n return \"Gist footer preview\";\n case \"profile\":\n return `${safeText(intent.name)} profile preview`;\n case \"history\":\n return \"History recovery preview\";\n case \"preset\":\n return `${intent.preset.label} preset preview`;\n }\n}\n\nfunction continueLabel(intent: ReviewIntent): string {\n switch (intent.kind) {\n case \"customize\":\n return \"Apply changes\u2026\";\n case \"restore\":\n return \"Replace with built-in\u2026\";\n case \"import\":\n return \"Replace with Gist settings\u2026\";\n case \"profile\":\n return `Apply ${safeText(intent.name)} profile\u2026`;\n case \"history\":\n return \"Restore history document\u2026\";\n case \"preset\":\n return `Apply ${intent.preset.label} preset\u2026`;\n }\n}\n\nfunction confirmationTitle(intent: ReviewIntent): string {\n switch (intent.kind) {\n case \"customize\":\n return \"Apply footer changes?\";\n case \"restore\":\n return \"Restore built-in footer?\";\n case \"import\":\n return \"Replace settings with Gist?\";\n case \"profile\":\n return `Apply ${safeText(intent.name)} profile?`;\n case \"history\":\n return \"Restore settings from history?\";\n case \"preset\":\n return `Apply ${intent.preset.label} preset?`;\n }\n}\n\nfunction confirmationMessage(settingsPath: string, intent: ReviewIntent, previous: LoadedStarshipConfig): string {\n if (previous.diagnostics.some((item) => item.severity === \"error\")) {\n 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.`;\n }\n if (intent.kind === \"customize\")\n return \"Replace the entire settings document and apply it immediately? Its previous bytes will be kept in History.\";\n const replacement =\n intent.kind === \"restore\"\n ? \"the built-in configuration\"\n : intent.kind === \"import\"\n ? \"the reviewed Gist settings\"\n : intent.kind === \"profile\"\n ? `the ${safeText(intent.name)} profile`\n : intent.kind === \"history\"\n ? \"the reviewed history document\"\n : `the ${intent.preset.label} preset`;\n 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.`;\n}\n\nfunction successMessage(intent: ReviewIntent): string {\n switch (intent.kind) {\n case \"customize\":\n return \"Footer settings saved and applied\";\n case \"restore\":\n return \"Built-in footer restored and applied\";\n case \"import\":\n return \"Gist settings saved and applied\";\n case \"profile\":\n return `${safeText(intent.name)} profile applied`;\n case \"history\":\n return \"History document restored and applied\";\n case \"preset\":\n return `${intent.preset.label} preset saved and applied`;\n }\n}\n\nfunction workflowOwner(options: StarshipCommandOptions): WorkflowOwner {\n if (options.getMenuOwner) return options.getMenuOwner();\n const controller = new AbortController();\n return { signal: controller.signal, isCurrent: () => true };\n}\n\nfunction isCurrentOwner(owner: WorkflowOwner): boolean {\n return !owner.signal.aborted && owner.isCurrent();\n}\n\nfunction isSessionOwnerCurrent(owner: WorkflowOwner): boolean {\n return !owner.signal.aborted && (owner.isSessionCurrent?.() ?? owner.isCurrent());\n}\n\nfunction clearSessionPreview(ctx: ExtensionCommandContext, options: StarshipCommandOptions, owner: WorkflowOwner) {\n if (owner.isSessionCurrent?.() ?? owner.isCurrent()) options.preview?.(undefined, ctx);\n}\n\nfunction captureExpectation(\n ctx: ExtensionCommandContext,\n options: StarshipCommandOptions,\n): CommitExpectation | undefined {\n try {\n return captureCommitExpectation(options);\n } catch (error) {\n ctx.ui.notify(`Footer settings were not saved: ${safeText(formatError(error))}`, \"error\");\n return undefined;\n }\n}\n\nfunction reviewPreviewBody(\n ctx: ExtensionCommandContext,\n options: StarshipCommandOptions,\n loaded: LoadedStarshipConfig,\n width: number,\n intent: ReviewIntent,\n): string[] {\n if (intent.kind === \"restore\") return restorePreviewBody(ctx, options, loaded, width);\n if (intent.kind !== \"preset\") return previewBody(ctx, options, loaded, width);\n const current = configurationPresentation(options.getLoaded());\n return [\n `Preset: ${intent.preset.label}`,\n `Requirement: ${intent.preset.requiresNerdFont ? \"Nerd Font\" : \"No special font\"}`,\n `Current: ${current.state}`,\n `Path: ${safeText(options.settingsPath)}`,\n \"Applying replaces the entire settings document, including custom settings, unknown fields, and comments.\",\n \"The previous document will be kept in History before replacement.\",\n \"\",\n ...previewBody(ctx, options, loaded, width),\n ];\n}\n\nfunction restorePreviewBody(\n ctx: ExtensionCommandContext,\n options: StarshipCommandOptions,\n loaded: LoadedStarshipConfig,\n width: number,\n): string[] {\n const current = configurationPresentation(options.getLoaded());\n return [\n `Current: ${current.state}`,\n `Path: ${safeText(options.settingsPath)}`,\n \"The entire settings document will be replaced, including custom settings, unknown fields, and comments.\",\n \"The previous document will be kept in History before replacement.\",\n \"\",\n ...previewBody(ctx, options, loaded, width),\n ];\n}\n\nfunction previewBody(\n ctx: ExtensionCommandContext,\n options: StarshipCommandOptions,\n loaded: LoadedStarshipConfig,\n width: number,\n): string[] {\n let lines: string[];\n try {\n lines = options.renderPreview?.(loaded, width, ctx) ?? [\n \"Live preview is unavailable until the footer is ready.\",\n \"The draft is valid and can still be applied.\",\n ];\n } catch (error) {\n lines = [`Preview unavailable: ${safeText(formatError(error))}`];\n }\n const warning =\n loaded.diagnostics.length === 0\n ? \"Draft validation: Healthy\"\n : `Draft validation: ${loaded.diagnostics.length} warning${loaded.diagnostics.length === 1 ? \"\" : \"s\"}`;\n return [...lines, \"\", warning];\n}\n\nfunction selectedPreviewAction<Value extends string>(result: PreviewMenuResult<Value> | undefined): Value | null {\n return result?.kind === \"selected\" ? result.value : null;\n}\n\nfunction showStatus(ctx: ExtensionCommandContext, options: StarshipCommandOptions) {\n if (!canNotify(ctx)) return;\n const loaded = options.getLoaded();\n const diagnostics = loaded.diagnostics\n .slice(0, 5)\n .map((item) => `${safeText(item.path || \"root\")}: ${safeText(item.message)}`)\n .join(\"; \");\n ctx.ui.notify(\n [\n `pi-starship source: ${loaded.source}`,\n `path: ${options.settingsPath}`,\n diagnostics ? `warnings: ${diagnostics}` : \"warnings: none\",\n ].join(\"\\n\"),\n loaded.diagnostics.length > 0 ? \"warning\" : \"info\",\n );\n}\n\nfunction showHelp(ctx: ExtensionCommandContext, settingsPath: string) {\n if (!canNotify(ctx)) return;\n ctx.ui.notify(\n [\n \"/starship \u2014 configure with agent, manage profiles, preview presets, or recover settings in TUI mode\",\n \"/starship settings \u2014 customize, preview, and apply TOML\",\n \"/starship status \u2014 show source, path, and warnings\",\n \"/starship help \u2014 show this help\",\n `Settings: ${settingsPath}`,\n \"Format/module docs: https://github.com/narumiruna/pi-extensions/tree/main/packages/pi-starship\",\n ].join(\"\\n\"),\n \"info\",\n );\n}\n\nfunction canNotify(ctx: ExtensionCommandContext): boolean {\n return ctx.mode === \"tui\" || ctx.hasUI;\n}\n\nfunction safeText(value: string): string {\n return Array.from(value, (character) => {\n const codePoint = character.codePointAt(0) ?? 0;\n const unsafe =\n codePoint <= 0x08 || (codePoint >= 0x0b && codePoint <= 0x1f) || (codePoint >= 0x7f && codePoint <= 0x9f);\n return unsafe ? `\\\\u${codePoint.toString(16).padStart(4, \"0\")}` : character;\n }).join(\"\");\n}\n\nfunction formatError(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n", "import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport { defineMenu, runMenu, runTask } 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 {\n atomicSaveConfigDocument,\n BUILT_IN_EXAMPLE,\n type LoadedStarshipConfig,\n loadStarshipConfig,\n readConfigDocumentSnapshot,\n validateConfigDocument,\n} from \"./config.js\";\nimport { checkGistDocument, createSettingsGist, fetchSettingsGist, type GhApi, gistId } from \"./gist.js\";\n\nexport type GistWorkflowResult = \"applied\" | \"cancel\" | \"close\";\nexport type ReviewImport = (\n loaded: LoadedStarshipConfig,\n options: StarshipCommandOptions,\n owner: WorkflowOwner,\n) => Promise<GistWorkflowResult>;\n\nexport async function shareSettingsGist(\n ctx: ExtensionCommandContext,\n options: StarshipCommandOptions,\n owner: WorkflowOwner,\n api?: GhApi,\n): Promise<GistWorkflowResult> {\n if (ctx.mode !== \"tui\" || !current(owner)) return \"cancel\";\n const loaded = options.getLoaded();\n if (loaded.diagnostics.some((item) => item.severity === \"error\")) {\n ctx.ui.notify(\"Fix configuration errors before sharing settings.\", \"warning\");\n return \"cancel\";\n }\n const raw = loaded.rawDocument ?? BUILT_IN_EXAMPLE;\n try {\n checkGistDocument(raw);\n } catch (error) {\n ctx.ui.notify(safeError(error), \"error\");\n return \"cancel\";\n }\n const review = await reviewDocument(\n ctx,\n owner,\n \"Share settings as Gist\",\n raw,\n [\n \"Review the entire loaded document, including comments and unknown fields, for secrets and local paths.\",\n \"No settings file is created when sharing built-in defaults.\",\n ],\n \"Share unlisted Gist\u2026\",\n );\n if (!current(owner)) return \"cancel\";\n if (!review) return \"close\";\n const confirmed = await ctx.ui.confirm(\n \"Upload settings to GitHub?\",\n [\n \"Send the reviewed pi-starship.toml to github.com as a new unlisted Gist?\",\n \"Unlisted is not private: anyone with the link can read it. Comments and unknown fields are included.\",\n \"Cancellation or a network error cannot undo an upload already accepted by GitHub; check your Gists before retrying.\",\n ].join(\"\\n\"),\n { signal: owner.signal },\n );\n if (!current(owner) || !confirmed) return \"cancel\";\n const result = await runTask(ctx, {\n label: \"Sharing settings with GitHub\u2026\",\n signal: owner.signal,\n isCurrent: owner.isCurrent,\n task: ({ signal }) => createSettingsGist(raw, signal, api),\n onError: () =>\n ctx.ui.notify(\n \"Gist upload failed. Check gh auth status, Gist access, connectivity, and your Gists before retrying. The upload may already exist.\",\n \"error\",\n ),\n });\n if (!current(owner)) return \"cancel\";\n if (result.kind === \"completed\") {\n ctx.ui.notify(`Settings Gist: ${result.value}`, \"info\");\n return \"cancel\";\n }\n return result.kind === \"error\" ? \"cancel\" : \"close\";\n}\n\nexport async function importSettingsGist(\n ctx: ExtensionCommandContext,\n options: StarshipCommandOptions,\n owner: WorkflowOwner,\n reviewImport: ReviewImport,\n api?: GhApi,\n): Promise<GistWorkflowResult> {\n if (ctx.mode !== \"tui\" || !current(owner)) return \"cancel\";\n const previous = options.getLoaded();\n const revision = options.getLoadedRevision?.();\n const disk = diskSnapshot(options);\n const initialDisk = readConfigDocumentSnapshot(options.settingsPath);\n const guardedOwner: WorkflowOwner = {\n signal: owner.signal,\n isSessionCurrent: () => owner.isSessionCurrent?.() ?? owner.isCurrent(),\n isCurrent: () =>\n current(owner) &&\n options.getLoadedRevision?.() === revision &&\n options.getLoaded().rawDocument === previous.rawDocument &&\n options.getLoaded().source === previous.source,\n };\n const value = await ctx.ui.input(\"Import pi-starship settings from Gist\", \"https://gist.github.com/<owner>/<id>\", {\n signal: owner.signal,\n });\n if (!current(guardedOwner) || value === undefined) return \"cancel\";\n let id: string;\n try {\n id = gistId(value);\n } catch (error) {\n ctx.ui.notify(safeError(error), \"error\");\n return \"cancel\";\n }\n const result = await runTask(ctx, {\n label: \"Reading settings from GitHub\u2026\",\n signal: owner.signal,\n isCurrent: guardedOwner.isCurrent,\n task: ({ signal }) => fetchSettingsGist(id, signal, api),\n onError: () =>\n ctx.ui.notify(\n \"Gist import failed. Check the Gist ID, gh auth status, connectivity, and a complete pi-starship.toml file (up to 64 KiB).\",\n \"error\",\n ),\n });\n if (!current(guardedOwner)) return \"cancel\";\n if (result.kind !== \"completed\") return result.kind === \"error\" ? \"cancel\" : \"close\";\n let validated: LoadedStarshipConfig;\n try {\n validated = (options.validate ?? validateConfigDocument)(options.settingsPath, result.value);\n } catch (error) {\n ctx.ui.notify(`Gist settings are invalid: ${safeError(error)}`, \"error\");\n return \"cancel\";\n }\n const reviewed = await reviewDocument(\n ctx,\n guardedOwner,\n \"Review Gist settings\",\n result.value,\n [\n `Source: https://gist.github.com/${id}`,\n \"Untrusted settings can enable local commands and network requests. Review the complete TOML before applying.\",\n \"Import replaces the entire local document, including comments and unknown fields; its previous bytes will be kept in History.\",\n ],\n \"Preview imported footer\u2026\",\n );\n if (!current(guardedOwner)) return \"cancel\";\n if (!reviewed) return \"close\";\n return reviewImport(\n validated,\n {\n ...options,\n save(path, raw) {\n if (!current(guardedOwner) || diskSnapshot(options) !== disk) {\n throw new Error(\"Settings changed during import. Start a new import to review the latest state.\");\n }\n return options.save ? options.save(path, raw) : atomicSaveConfigDocument(path, raw, {}, initialDisk);\n },\n },\n guardedOwner,\n );\n}\n\nasync function reviewDocument(\n ctx: ExtensionCommandContext,\n owner: WorkflowOwner,\n title: string,\n content: string,\n lines: string[],\n label: string,\n): Promise<boolean> {\n let approved = false;\n const menu = defineMenu<undefined, \"document\", \"continue\", ExtensionCommandContext>({\n start: \"document\",\n screens: {\n document: () => ({\n kind: \"review\",\n title,\n lines,\n content,\n format: { kind: \"code\", language: \"toml\" },\n viewportSize: \"adaptive\",\n enableSearch: true,\n confirm: { id: \"continue\", label, action: \"continue\" },\n hint: \"close\",\n }),\n },\n actions: {\n continue: () => {\n approved = true;\n return { kind: \"close\" };\n },\n },\n });\n await runMenu(ctx, menu, { getState: () => undefined, signal: owner.signal, isCurrent: owner.isCurrent });\n return current(owner) && approved;\n}\n\nfunction diskSnapshot(options: StarshipCommandOptions): string {\n const loaded = (options.read ?? loadStarshipConfig)(options.settingsPath);\n return JSON.stringify([\n loaded.rawDocument,\n loaded.source,\n loaded.diagnostics,\n readConfigDocumentSnapshot(options.settingsPath),\n ]);\n}\n\nfunction current(owner: WorkflowOwner): boolean {\n return !owner.signal.aborted && owner.isCurrent();\n}\n\nfunction safeError(error: unknown): string {\n return sanitizeTerminalText(error instanceof Error ? error.message : String(error));\n}\n", "import { spawn } from \"node:child_process\";\n\nexport const GIST_FILENAME = \"pi-starship.toml\";\nexport const MAX_GIST_DOCUMENT_BYTES = 64 * 1024;\nconst MAX_RESPONSE_BYTES = 512 * 1024;\nconst REQUEST_TIMEOUT_MS = 30_000;\n\nexport type GhApi = (args: string[], input: string | undefined, signal: AbortSignal) => Promise<string>;\n\n/** Gists are intentionally limited to github.com; never forward auth to a pasted host. */\nexport function gistId(value: string): string {\n const text = value.trim();\n if (/^[a-f\\d]{5,64}$/iu.test(text)) return text;\n try {\n const url = new URL(text);\n const match = /^\\/(?:[\\w-]+\\/)?([a-f\\d]{5,64})\\/?$/iu.exec(url.pathname);\n if (\n url.protocol === \"https:\" &&\n url.hostname === \"gist.github.com\" &&\n !url.port &&\n !url.username &&\n !url.password &&\n !url.search &&\n match?.[1]\n )\n return match[1];\n } catch {\n // Report one fixed error without echoing untrusted input.\n }\n throw new Error(\"Enter a github.com Gist ID or https://gist.github.com/<owner>/<id> URL.\");\n}\n\nexport function checkGistDocument(rawDocument: string): void {\n if (!rawDocument.trim()) throw new Error(\"The Gist settings document is empty.\");\n if (Buffer.byteLength(rawDocument, \"utf8\") > MAX_GIST_DOCUMENT_BYTES) {\n throw new Error(\"The Gist settings document exceeds 64 KiB.\");\n }\n}\n\nexport async function createSettingsGist(\n rawDocument: string,\n signal: AbortSignal,\n api: GhApi = executeGhApi,\n): Promise<string> {\n checkGistDocument(rawDocument);\n const response = JSON.parse(\n await api(\n [\"/gists\", \"--method\", \"POST\", \"--input\", \"-\"],\n JSON.stringify({\n description: \"pi-starship footer settings\",\n public: false,\n files: { [GIST_FILENAME]: { content: rawDocument } },\n }),\n signal,\n ),\n ) as unknown;\n signal.throwIfAborted();\n if (!isRecord(response) || response.public !== false || typeof response.html_url !== \"string\") {\n throw new Error(\"GitHub returned an invalid Gist response. Check your Gists before retrying.\");\n }\n return `https://gist.github.com/${gistId(response.html_url)}`;\n}\n\nexport async function fetchSettingsGist(\n value: string,\n signal: AbortSignal,\n api: GhApi = executeGhApi,\n): Promise<string> {\n const id = gistId(value);\n const response = JSON.parse(await api([`/gists/${id}`, \"--method\", \"GET\"], undefined, signal)) as unknown;\n signal.throwIfAborted();\n const file = isRecord(response) && isRecord(response.files) ? response.files[GIST_FILENAME] : undefined;\n if (!isRecord(file) || typeof file.content !== \"string\" || file.truncated !== false) {\n throw new Error(`The Gist must contain a complete ${GIST_FILENAME} file. Truncated files are not supported.`);\n }\n checkGistDocument(file.content);\n return file.content;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\n/** Bound output and lifetime, keep request bodies on stdin, and never expose gh stderr. */\nexport const executeGhApi: GhApi = (args, input, signal) => {\n signal.throwIfAborted();\n return new Promise((resolve, reject) => {\n const child = spawn(process.platform === \"win32\" ? \"gh.exe\" : \"gh\", [\"api\", \"--hostname\", \"github.com\", ...args], {\n env: { ...process.env, GH_PROMPT_DISABLED: \"1\", GH_PAGER: \"\", GH_DEBUG: \"\" },\n stdio: [\"pipe\", \"pipe\", \"ignore\"],\n windowsHide: true,\n });\n const chunks: Buffer[] = [];\n let bytes = 0;\n let failure: Error | undefined;\n const stop = (error: Error) => {\n failure ??= error;\n child.kill(\"SIGKILL\");\n };\n const onAbort = () => stop(new Error(\"Gist request cancelled.\"));\n const timer = setTimeout(\n () => stop(new Error(\"Gist request timed out. Check GitHub before retrying an upload.\")),\n REQUEST_TIMEOUT_MS,\n );\n timer.unref();\n signal.addEventListener(\"abort\", onAbort, { once: true });\n child.stdout.on(\"data\", (chunk: Buffer) => {\n bytes += chunk.length;\n if (bytes > MAX_RESPONSE_BYTES) stop(new Error(\"GitHub Gist response exceeds 512 KiB.\"));\n else chunks.push(chunk);\n });\n child.stdin.on(\"error\", () => {\n stop(new Error(\"Unable to send settings to gh.\"));\n });\n child.on(\"error\", () => {\n failure ??= new Error(\"Unable to start gh. Install GitHub CLI and run gh auth login with Gist access.\");\n });\n child.on(\"close\", (code) => {\n clearTimeout(timer);\n signal.removeEventListener(\"abort\", onAbort);\n if (failure) reject(failure);\n else if (code !== 0)\n reject(\n new Error(\n \"Gist request failed. Check gh auth status, Gist access, and connectivity. An upload may already exist.\",\n ),\n );\n else resolve(Buffer.concat(chunks).toString(\"utf8\"));\n });\n if (signal.aborted) onAbort();\n child.stdin.end(input);\n });\n};\n", "import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport { runLiveChoice } from \"@narumitw/pi-tui-kit\";\nimport type { StarshipPreset } from \"./presets/catalog.js\";\n\nexport type PresetPickerResult =\n | { kind: \"apply\"; presetId: StarshipPreset[\"id\"] }\n | { kind: \"customize\"; presetId: StarshipPreset[\"id\"] }\n | { kind: \"save-profile\"; presetId: StarshipPreset[\"id\"] }\n | { kind: \"back\" }\n | { kind: \"close\" };\n\nexport interface PresetPickerOptions {\n presets: readonly StarshipPreset[];\n activePresetId?: StarshipPreset[\"id\"];\n initialPresetId?: StarshipPreset[\"id\"];\n signal: AbortSignal;\n isCurrent(): boolean;\n preview(preset: StarshipPreset): void;\n}\n\nexport async function showPresetPicker(\n ctx: ExtensionCommandContext,\n options: PresetPickerOptions,\n): Promise<PresetPickerResult> {\n const current =\n options.presets.find((preset) => preset.id === options.activePresetId)?.label ?? \"Custom configuration\";\n const result = await runLiveChoice(ctx, {\n title: `Presets \u00B7 current: ${current}`,\n items: options.presets.map((preset) => ({\n id: preset.id,\n label: preset.label,\n description:\n preset.id === options.activePresetId ? `Currently applied \u00B7 ${preset.description}` : preset.description,\n details: [`Selected: ${preset.label} \u00B7 ${preset.requiresNerdFont ? \"requires Nerd Font\" : \"font-safe\"}`],\n confirmationDisabled: preset.id === options.activePresetId,\n confirmationDisabledReason: \"Already applied; press e to customize\",\n })),\n currentItemId: options.activePresetId,\n initialItemId: options.initialPresetId ?? options.activePresetId,\n viewportSize: Math.min(options.presets.length, 10),\n hint: \"back\",\n navigationLabel: \"live preview\",\n confirmLabel: \"apply\",\n shortcuts: [\n { id: \"customize\", keys: [\"e\", \"shift+e\"], label: \"customize\" },\n { id: \"save-profile\", keys: [\"s\", \"shift+s\"], label: \"save as profile\" },\n ],\n onSelectionChange: ({ item }) => {\n const preset = options.presets.find((candidate) => candidate.id === item.id);\n if (preset) options.preview(preset);\n },\n signal: options.signal,\n isCurrent: options.isCurrent,\n });\n if (result.kind === \"selected\") return { kind: \"apply\", presetId: result.itemId };\n if (result.kind === \"shortcut\") {\n return { kind: result.shortcutId === \"save-profile\" ? \"save-profile\" : \"customize\", presetId: result.itemId };\n }\n if (result.kind === \"closed\" && result.reason === \"back\") return { kind: \"back\" };\n return { kind: \"close\" };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,SAAS,cAAc,KAAK,kBAAkB;AAC9C,SAAS,cAAAA,aAAY,WAAAC,gBAAe;;;ACDpC,SAAS,YAAY,SAAS,eAAe;AAC7C,SAAS,4BAA4B;;;ACFrC,SAAS,aAAa;AAEf,IAAM,gBAAgB;AACtB,IAAM,0BAA0B,KAAK;AAC5C,IAAM,qBAAqB,MAAM;AACjC,IAAM,qBAAqB;AAKpB,SAAS,OAAO,OAAuB;AAC5C,QAAM,OAAO,MAAM,KAAK;AACxB,MAAI,oBAAoB,KAAK,IAAI,EAAG,QAAO;AAC3C,MAAI;AACF,UAAM,MAAM,IAAI,IAAI,IAAI;AACxB,UAAM,QAAQ,wCAAwC,KAAK,IAAI,QAAQ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AA,IAC7C,EAAE,KAAK,IAAI;AAAA,IACX,OAAO,YAAY,SAAS,IAAI,YAAY;AAAA,EAC9C;AACF;AAEA,SAAS,SAAS,KAA8B,cAAsB;AACpE,MAAI,CAAC,UAAU,GAAG,EAAG;AACrB,MAAI,GAAG;AAAA,IACL;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,aAAa,YAAY;AAAA,MACzB;AAAA,IACF,EAAE,KAAK,IAAI;AAAA,IACX;AAAA,EACF;AACF;AAEA,SAAS,UAAU,KAAuC;AACxD,SAAO,IAAI,SAAS,SAAS,IAAI;AACnC;AAEA,SAAS,SAAS,OAAuB;AACvC,SAAO,MAAM,KAAK,OAAO,CAAC,cAAc;AACtC,UAAM,YAAY,UAAU,YAAY,CAAC,KAAK;AAC9C,UAAM,SACJ,aAAa,KAAS,aAAa,MAAQ,aAAa,MAAU,aAAa,OAAQ,aAAa;AACtG,WAAO,SAAS,MAAM,UAAU,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,KAAK;AAAA,EACpE,CAAC,EAAE,KAAK,EAAE;AACZ;AAEA,SAAS,YAAY,OAAwB;AAC3C,SAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAC9D;",
|
|
6
|
+
"names": ["defineMenu", "runMenu", "current", "defineMenu", "runMenu", "preset", "edited", "current"]
|
|
7
|
+
}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
// @generated by scripts/build-runtime.mjs; do not edit.
|
|
2
2
|
// @ts-nocheck -- the generated entry uses a .ts extension for Pi's Jiti loader.
|
|
3
|
+
import {
|
|
4
|
+
matchPattern,
|
|
5
|
+
replacePattern
|
|
6
|
+
} from "./chunk-IYDZ3R2T.ts";
|
|
7
|
+
import {
|
|
8
|
+
PRIVATE_STYLE_SELECTOR
|
|
9
|
+
} from "./chunk-XTLQ4WUL.ts";
|
|
3
10
|
import {
|
|
4
11
|
MAX_METADATA_FILE_BYTES,
|
|
12
|
+
detectEnvironment,
|
|
5
13
|
directMatch,
|
|
6
14
|
exactAlias,
|
|
7
15
|
formatVersion,
|
|
@@ -14,21 +22,26 @@ import {
|
|
|
14
22
|
optionStrings,
|
|
15
23
|
runBounded,
|
|
16
24
|
safeMetadata
|
|
17
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-S2KBLHE2.ts";
|
|
26
|
+
import "./chunk-KP33I6BR.ts";
|
|
18
27
|
|
|
19
28
|
// src/runtime/deployment.ts
|
|
20
29
|
import { extname, isAbsolute, join, resolve } from "node:path";
|
|
30
|
+
import { sanitizeTerminalText } from "@narumitw/pi-tui-kit/terminal-text";
|
|
21
31
|
import { parse as parseYaml } from "yaml";
|
|
22
32
|
async function collectDeployment(context) {
|
|
23
33
|
const result = {};
|
|
34
|
+
if (context.input.signal?.aborted) return result;
|
|
24
35
|
if (context.needs("docker_context")) {
|
|
25
36
|
const docker = await collectDocker(context);
|
|
26
37
|
if (docker) result.docker_context = docker;
|
|
27
38
|
}
|
|
39
|
+
if (context.input.signal?.aborted) return result;
|
|
28
40
|
if (context.needs("kubernetes")) {
|
|
29
41
|
const kubernetes = await collectKubernetes(context);
|
|
30
42
|
if (kubernetes) result.kubernetes = kubernetes;
|
|
31
43
|
}
|
|
44
|
+
if (context.input.signal?.aborted) return result;
|
|
32
45
|
if (context.needs("terraform")) {
|
|
33
46
|
const terraform = await collectTerraform(context);
|
|
34
47
|
if (terraform) result.terraform = terraform;
|
|
@@ -63,6 +76,7 @@ async function collectDocker(context) {
|
|
|
63
76
|
return active && active !== "default" ? { context: active } : void 0;
|
|
64
77
|
}
|
|
65
78
|
async function collectKubernetes(context) {
|
|
79
|
+
if (!await kubernetesDetected(context) || context.input.signal?.aborted) return void 0;
|
|
66
80
|
const selected = safeMetadata(context.input.environment.KUBECONFIG, 4096);
|
|
67
81
|
const candidates = selected ? selected.split(context.input.platform === "win32" ? ";" : ":").filter(Boolean) : [joinHome(context.input, ".kube", "config")];
|
|
68
82
|
const limit = optionNumber(context, "kubernetes", "max_config_files") ?? 8;
|
|
@@ -71,7 +85,9 @@ async function collectKubernetes(context) {
|
|
|
71
85
|
const users = /* @__PURE__ */ new Set();
|
|
72
86
|
let currentContext;
|
|
73
87
|
for (const path of candidates.slice(0, limit)) {
|
|
88
|
+
if (context.input.signal?.aborted) return void 0;
|
|
74
89
|
const source = await context.fs.readFile(path, MAX_METADATA_FILE_BYTES);
|
|
90
|
+
if (context.input.signal?.aborted) return void 0;
|
|
75
91
|
if (!source) continue;
|
|
76
92
|
try {
|
|
77
93
|
const document = parseYaml(source);
|
|
@@ -97,18 +113,82 @@ async function collectKubernetes(context) {
|
|
|
97
113
|
const cluster = safeMetadata(selectedContext?.cluster);
|
|
98
114
|
const user = safeMetadata(selectedContext?.user);
|
|
99
115
|
const namespace = safeMetadata(selectedContext?.namespace) ?? "default";
|
|
116
|
+
const matched = matchKubernetesRule(context.options("kubernetes").contexts, currentContext, user);
|
|
117
|
+
const displayContext = matched?.context ?? currentContext;
|
|
118
|
+
const displayUser = matched?.user ?? user;
|
|
100
119
|
const values = {
|
|
101
|
-
context: exactAlias(
|
|
120
|
+
context: exactAlias(displayContext, optionMap(context, "kubernetes", "context_aliases")) ?? displayContext,
|
|
102
121
|
namespace: exactAlias(namespace, optionMap(context, "kubernetes", "namespace_aliases")) ?? namespace
|
|
103
122
|
};
|
|
104
123
|
if (cluster && clusters.has(cluster)) {
|
|
105
124
|
values.cluster = exactAlias(cluster, optionMap(context, "kubernetes", "cluster_aliases")) ?? cluster;
|
|
106
125
|
}
|
|
107
|
-
if (user && users.has(user)) {
|
|
108
|
-
values.user = exactAlias(
|
|
126
|
+
if (displayUser !== void 0 && (user && users.has(user) || matched?.rule.user_alias !== void 0)) {
|
|
127
|
+
values.user = exactAlias(displayUser, optionMap(context, "kubernetes", "user_aliases")) ?? displayUser;
|
|
109
128
|
}
|
|
129
|
+
if (matched?.rule.symbol !== void 0) values.symbol = matched.rule.symbol;
|
|
130
|
+
if (matched?.rule.style !== void 0) values[PRIVATE_STYLE_SELECTOR] = matched.rule.style;
|
|
110
131
|
return values;
|
|
111
132
|
}
|
|
133
|
+
async function kubernetesDetected(context) {
|
|
134
|
+
const files = optionStrings(context, "kubernetes", "detect_files");
|
|
135
|
+
const extensions = optionStrings(context, "kubernetes", "detect_extensions");
|
|
136
|
+
const folders = optionStrings(context, "kubernetes", "detect_folders");
|
|
137
|
+
if (files.length + extensions.length + folders.length > 0) {
|
|
138
|
+
const entries = await context.entries();
|
|
139
|
+
return !context.input.signal?.aborted && kubernetesDirectoryMatch(entries, files, extensions, folders);
|
|
140
|
+
}
|
|
141
|
+
return detectEnvironment(context.input.environment, optionStrings(context, "kubernetes", "detect_env_vars"));
|
|
142
|
+
}
|
|
143
|
+
function kubernetesDirectoryMatch(entries, files, extensions, folders) {
|
|
144
|
+
const foundFiles = /* @__PURE__ */ new Set();
|
|
145
|
+
const foundFolders = /* @__PURE__ */ new Set();
|
|
146
|
+
const foundExtensions = /* @__PURE__ */ new Set();
|
|
147
|
+
for (const entry of entries) {
|
|
148
|
+
if (entry.isDirectory) foundFolders.add(entry.name);
|
|
149
|
+
if (!entry.isFile) continue;
|
|
150
|
+
foundFiles.add(entry.name);
|
|
151
|
+
if (entry.name.startsWith(".")) continue;
|
|
152
|
+
const firstDot = entry.name.indexOf(".");
|
|
153
|
+
if (firstDot < 0) continue;
|
|
154
|
+
foundExtensions.add(entry.name.slice(firstDot + 1));
|
|
155
|
+
foundExtensions.add(entry.name.slice(entry.name.lastIndexOf(".") + 1));
|
|
156
|
+
}
|
|
157
|
+
const criteria = [
|
|
158
|
+
[files, foundFiles],
|
|
159
|
+
[extensions, foundExtensions],
|
|
160
|
+
[folders, foundFolders]
|
|
161
|
+
];
|
|
162
|
+
return criteria.every(([patterns, found]) => !patterns.some((name) => name.startsWith("!") && found.has(name.slice(1)))) && criteria.some(([patterns, found]) => patterns.some((name) => !name.startsWith("!") && found.has(name)));
|
|
163
|
+
}
|
|
164
|
+
function matchKubernetesRule(rules, context, user) {
|
|
165
|
+
if (!Array.isArray(rules)) return void 0;
|
|
166
|
+
for (const rule of rules.slice(0, 64)) {
|
|
167
|
+
if (!isKubernetesRule(rule)) continue;
|
|
168
|
+
const contextAlias = kubernetesRuleAlias(rule.context_pattern, context, rule.context_alias);
|
|
169
|
+
if (contextAlias === void 0) continue;
|
|
170
|
+
const userAlias = kubernetesRuleAlias(rule.user_pattern, user, rule.user_alias);
|
|
171
|
+
if (rule.user_pattern !== void 0 && userAlias === void 0) continue;
|
|
172
|
+
return { rule, context: contextAlias, user: userAlias };
|
|
173
|
+
}
|
|
174
|
+
return void 0;
|
|
175
|
+
}
|
|
176
|
+
function isKubernetesRule(rule) {
|
|
177
|
+
return isRecord(rule) && typeof rule.context_pattern === "string" && ["user_pattern", "symbol", "style", "context_alias", "user_alias"].every(
|
|
178
|
+
(key) => rule[key] === void 0 || typeof rule[key] === "string"
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
function kubernetesRuleAlias(pattern, value, alias) {
|
|
182
|
+
const replacement = alias ?? value;
|
|
183
|
+
if (replacement === void 0) return void 0;
|
|
184
|
+
if (pattern === void 0 || value === pattern) {
|
|
185
|
+
return alias === void 0 ? replacement : safeMetadata(sanitizeTerminalText(replacement)) ?? "";
|
|
186
|
+
}
|
|
187
|
+
if (value === void 0 || !matchPattern(pattern, value)) return void 0;
|
|
188
|
+
if (alias === void 0) return value;
|
|
189
|
+
const replaced = replacePattern(`^(?:${pattern})$`, value, alias);
|
|
190
|
+
return replaced === void 0 ? void 0 : safeMetadata(sanitizeTerminalText(replaced)) ?? "";
|
|
191
|
+
}
|
|
112
192
|
async function collectTerraform(context) {
|
|
113
193
|
const entries = await context.entries();
|
|
114
194
|
const configuredFiles = optionStrings(context, "terraform", "detect_files");
|
|
@@ -154,4 +234,4 @@ export {
|
|
|
154
234
|
collectDeployment,
|
|
155
235
|
parseTerraformVersion
|
|
156
236
|
};
|
|
157
|
-
//# sourceMappingURL=deployment-
|
|
237
|
+
//# sourceMappingURL=deployment-NOJ2KCLI.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/runtime/deployment.ts"],
|
|
4
|
+
"sourcesContent": ["import { extname, isAbsolute, join, resolve } from \"node:path\";\nimport { sanitizeTerminalText } from \"@narumitw/pi-tui-kit/terminal-text\";\nimport { parse as parseYaml } from \"yaml\";\nimport { matchPattern, replacePattern } from \"../format/bounded-regex.js\";\nimport type { ModuleContextRule } from \"../modules/types.js\";\nimport {\n detectEnvironment,\n directMatch,\n exactAlias,\n formatVersion,\n isRecord,\n joinHome,\n MAX_METADATA_FILE_BYTES,\n optionBoolean,\n optionMap,\n optionNumber,\n optionString,\n optionStrings,\n runBounded,\n safeMetadata,\n} from \"./helpers.js\";\nimport {\n type CollectorContext,\n type MutableModuleSnapshot,\n PRIVATE_STYLE_SELECTOR,\n type WorkspaceEntry,\n} from \"./types.js\";\n\nexport async function collectDeployment(context: CollectorContext): Promise<MutableModuleSnapshot> {\n const result: MutableModuleSnapshot = {};\n if (context.input.signal?.aborted) return result;\n if (context.needs(\"docker_context\")) {\n const docker = await collectDocker(context);\n if (docker) result.docker_context = docker;\n }\n if (context.input.signal?.aborted) return result;\n if (context.needs(\"kubernetes\")) {\n const kubernetes = await collectKubernetes(context);\n if (kubernetes) result.kubernetes = kubernetes;\n }\n if (context.input.signal?.aborted) return result;\n if (context.needs(\"terraform\")) {\n const terraform = await collectTerraform(context);\n if (terraform) result.terraform = terraform;\n }\n return result;\n}\n\nasync function collectDocker(context: CollectorContext): Promise<Record<string, string> | undefined> {\n const entries = await context.entries();\n if (optionBoolean(context, \"docker_context\", \"only_with_files\")) {\n const configuredFiles = optionStrings(context, \"docker_context\", \"detect_files\");\n if (\n !directMatch(\n entries,\n configuredFiles.length > 0\n ? configuredFiles\n : [\"Dockerfile\", \"docker-compose.yml\", \"docker-compose.yaml\", \"compose.yml\", \"compose.yaml\"],\n optionStrings(context, \"docker_context\", \"detect_extensions\"),\n optionStrings(context, \"docker_context\", \"detect_folders\"),\n )\n ) {\n return undefined;\n }\n }\n let active = safeMetadata(context.input.environment.DOCKER_CONTEXT);\n if (!active) {\n const configDirectory =\n safeMetadata(context.input.environment.DOCKER_CONFIG, 1_024) ?? joinHome(context.input, \".docker\");\n const source = await context.fs.readFile(join(configDirectory, \"config.json\"), MAX_METADATA_FILE_BYTES);\n if (source) {\n try {\n const document = JSON.parse(source) as unknown;\n active = isRecord(document) ? safeMetadata(document.currentContext) : undefined;\n } catch {\n // Malformed metadata degrades to an empty module.\n }\n }\n }\n return active && active !== \"default\" ? { context: active } : undefined;\n}\n\nasync function collectKubernetes(context: CollectorContext): Promise<Record<string, string> | undefined> {\n if (!(await kubernetesDetected(context)) || context.input.signal?.aborted) return undefined;\n const selected = safeMetadata(context.input.environment.KUBECONFIG, 4_096);\n const candidates = selected\n ? selected.split(context.input.platform === \"win32\" ? \";\" : \":\").filter(Boolean)\n : [joinHome(context.input, \".kube\", \"config\")];\n const limit = optionNumber(context, \"kubernetes\", \"max_config_files\") ?? 8;\n const contexts = new Map<string, Record<string, unknown>>();\n const clusters = new Set<string>();\n const users = new Set<string>();\n let currentContext: string | undefined;\n for (const path of candidates.slice(0, limit)) {\n if (context.input.signal?.aborted) return undefined;\n const source = await context.fs.readFile(path, MAX_METADATA_FILE_BYTES);\n if (context.input.signal?.aborted) return undefined;\n if (!source) continue;\n try {\n const document = parseYaml(source) as unknown;\n if (!isRecord(document)) continue;\n currentContext ??= safeMetadata(document[\"current-context\"]);\n for (const item of arrayRecords(document.contexts)) {\n const name = safeMetadata(item.name);\n if (name && !contexts.has(name) && isRecord(item.context)) contexts.set(name, item.context);\n }\n for (const item of arrayRecords(document.clusters)) {\n const name = safeMetadata(item.name);\n if (name) clusters.add(name);\n }\n for (const item of arrayRecords(document.users)) {\n const name = safeMetadata(item.name);\n if (name) users.add(name);\n }\n } catch {\n // Ignore malformed files independently.\n }\n }\n if (!currentContext) return undefined;\n const selectedContext = contexts.get(currentContext);\n const cluster = safeMetadata(selectedContext?.cluster);\n const user = safeMetadata(selectedContext?.user);\n const namespace = safeMetadata(selectedContext?.namespace) ?? \"default\";\n const matched = matchKubernetesRule(context.options(\"kubernetes\").contexts, currentContext, user);\n const displayContext = matched?.context ?? currentContext;\n const displayUser = matched?.user ?? user;\n const values: Record<string, string> = {\n context: exactAlias(displayContext, optionMap(context, \"kubernetes\", \"context_aliases\")) ?? displayContext,\n namespace: exactAlias(namespace, optionMap(context, \"kubernetes\", \"namespace_aliases\")) ?? namespace,\n };\n if (cluster && clusters.has(cluster)) {\n values.cluster = exactAlias(cluster, optionMap(context, \"kubernetes\", \"cluster_aliases\")) ?? cluster;\n }\n // Preserve Pi's existing named-user requirement unless a rule supplies a label.\n if (displayUser !== undefined && ((user && users.has(user)) || matched?.rule.user_alias !== undefined)) {\n values.user = exactAlias(displayUser, optionMap(context, \"kubernetes\", \"user_aliases\")) ?? displayUser;\n }\n if (matched?.rule.symbol !== undefined) values.symbol = matched.rule.symbol;\n if (matched?.rule.style !== undefined) values[PRIVATE_STYLE_SELECTOR] = matched.rule.style;\n return values;\n}\n\nasync function kubernetesDetected(context: CollectorContext): Promise<boolean> {\n const files = optionStrings(context, \"kubernetes\", \"detect_files\");\n const extensions = optionStrings(context, \"kubernetes\", \"detect_extensions\");\n const folders = optionStrings(context, \"kubernetes\", \"detect_folders\");\n // Upstream gives a configured directory scan precedence over environment checks.\n if (files.length + extensions.length + folders.length > 0) {\n const entries = await context.entries();\n return !context.input.signal?.aborted && kubernetesDirectoryMatch(entries, files, extensions, folders);\n }\n return detectEnvironment(context.input.environment, optionStrings(context, \"kubernetes\", \"detect_env_vars\"));\n}\n\nfunction kubernetesDirectoryMatch(\n entries: readonly WorkspaceEntry[],\n files: readonly string[],\n extensions: readonly string[],\n folders: readonly string[],\n): boolean {\n // Unlike the shared legacy detector, upstream ignores hidden-file extensions\n // and recognizes both the last suffix and a complete compound suffix.\n // Use only regular entries from the bounded listing; do not follow symlinks.\n const foundFiles = new Set<string>();\n const foundFolders = new Set<string>();\n const foundExtensions = new Set<string>();\n for (const entry of entries) {\n if (entry.isDirectory) foundFolders.add(entry.name);\n if (!entry.isFile) continue;\n foundFiles.add(entry.name);\n if (entry.name.startsWith(\".\")) continue;\n const firstDot = entry.name.indexOf(\".\");\n if (firstDot < 0) continue;\n foundExtensions.add(entry.name.slice(firstDot + 1));\n foundExtensions.add(entry.name.slice(entry.name.lastIndexOf(\".\") + 1));\n }\n const criteria = [\n [files, foundFiles],\n [extensions, foundExtensions],\n [folders, foundFolders],\n ] as const;\n return (\n criteria.every(([patterns, found]) => !patterns.some((name) => name.startsWith(\"!\") && found.has(name.slice(1)))) &&\n criteria.some(([patterns, found]) => patterns.some((name) => !name.startsWith(\"!\") && found.has(name)))\n );\n}\n\ninterface MatchedKubernetesRule {\n rule: ModuleContextRule;\n context: string;\n user?: string;\n}\n\nfunction matchKubernetesRule(\n rules: unknown,\n context: string,\n user: string | undefined,\n): MatchedKubernetesRule | undefined {\n if (!Array.isArray(rules)) return undefined;\n for (const rule of rules.slice(0, 64)) {\n if (!isKubernetesRule(rule)) continue;\n const contextAlias = kubernetesRuleAlias(rule.context_pattern, context, rule.context_alias);\n if (contextAlias === undefined) continue;\n const userAlias = kubernetesRuleAlias(rule.user_pattern, user, rule.user_alias);\n if (rule.user_pattern !== undefined && userAlias === undefined) continue;\n return { rule, context: contextAlias, user: userAlias };\n }\n return undefined;\n}\n\nfunction isKubernetesRule(rule: unknown): rule is ModuleContextRule {\n return (\n isRecord(rule) &&\n typeof rule.context_pattern === \"string\" &&\n [\"user_pattern\", \"symbol\", \"style\", \"context_alias\", \"user_alias\"].every(\n (key) => rule[key] === undefined || typeof rule[key] === \"string\",\n )\n );\n}\n\nfunction kubernetesRuleAlias(\n pattern: string | undefined,\n value: string | undefined,\n alias: string | undefined,\n): string | undefined {\n const replacement = alias ?? value;\n if (replacement === undefined) return undefined;\n if (pattern === undefined || value === pattern) {\n return alias === undefined ? replacement : (safeMetadata(sanitizeTerminalText(replacement)) ?? \"\");\n }\n if (value === undefined || !matchPattern(pattern, value)) return undefined;\n if (alias === undefined) return value;\n // Grouped anchors keep replacements whole-label even with alternation.\n const replaced = replacePattern(`^(?:${pattern})$`, value, alias);\n return replaced === undefined ? undefined : (safeMetadata(sanitizeTerminalText(replaced)) ?? \"\");\n}\n\nasync function collectTerraform(context: CollectorContext): Promise<Record<string, string> | undefined> {\n const entries = await context.entries();\n const configuredFiles = optionStrings(context, \"terraform\", \"detect_files\");\n const configuredExtensions = optionStrings(context, \"terraform\", \"detect_extensions\");\n const configuredFolders = optionStrings(context, \"terraform\", \"detect_folders\");\n const detected =\n configuredFiles.length + configuredExtensions.length + configuredFolders.length > 0\n ? directMatch(entries, configuredFiles, configuredExtensions, configuredFolders)\n : entries.some(\n (entry) =>\n (entry.isFile && [\".tf\", \".tfplan\", \".tfstate\"].includes(extname(entry.name))) ||\n (entry.isDirectory && entry.name === \".terraform\"),\n );\n if (!detected) return undefined;\n const values: Record<string, string> = {};\n const workspace = await terraformWorkspace(context);\n if (workspace) values.workspace = workspace;\n if (context.needs(\"terraform\", \"version\")) {\n for (const command of [\"terraform\", \"tofu\"]) {\n const output = await runBounded(context, command, [\"version\"]);\n const parsed = output ? parseTerraformVersion(output, command) : undefined;\n if (parsed) {\n values.version = formatVersion(parsed, optionString(context, \"terraform\", \"version_format\"));\n break;\n }\n }\n }\n return values;\n}\n\nasync function terraformWorkspace(context: CollectorContext): Promise<string | undefined> {\n const direct = safeMetadata(context.input.environment.TF_WORKSPACE);\n if (direct) return direct;\n const dataDirectory = safeMetadata(context.input.environment.TF_DATA_DIR, 1_024);\n const candidate = dataDirectory\n ? join(isAbsolute(dataDirectory) ? dataDirectory : resolve(context.input.cwd, dataDirectory), \"environment\")\n : join(context.input.cwd, \".terraform\", \"environment\");\n return safeMetadata(await context.fs.readFile(candidate, 1_024));\n}\n\nexport function parseTerraformVersion(output: string, command: \"terraform\" | \"tofu\" | string): string | undefined {\n const escaped = command === \"tofu\" ? \"OpenTofu\" : \"Terraform\";\n const match = new RegExp(`^${escaped} v?(\\\\d+\\\\.\\\\d+\\\\.\\\\d+(?:[-+][0-9A-Za-z.-]+)?)$`, \"u\").exec(\n output.trim().split(/\\r?\\n/u)[0] ?? \"\",\n );\n return match?.[1] ? `v${match[1]}` : undefined;\n}\n\nfunction arrayRecords(value: unknown): Record<string, unknown>[] {\n return Array.isArray(value) ? value.filter(isRecord) : [];\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,SAAS,YAAY,MAAM,eAAe;AACnD,SAAS,4BAA4B;AACrC,SAAS,SAAS,iBAAiB;AA0BnC,eAAsB,kBAAkB,SAA2D;AACjG,QAAM,SAAgC,CAAC;AACvC,MAAI,QAAQ,MAAM,QAAQ,QAAS,QAAO;AAC1C,MAAI,QAAQ,MAAM,gBAAgB,GAAG;AACnC,UAAM,SAAS,MAAM,cAAc,OAAO;AAC1C,QAAI,OAAQ,QAAO,iBAAiB;AAAA,EACtC;AACA,MAAI,QAAQ,MAAM,QAAQ,QAAS,QAAO;AAC1C,MAAI,QAAQ,MAAM,YAAY,GAAG;AAC/B,UAAM,aAAa,MAAM,kBAAkB,OAAO;AAClD,QAAI,WAAY,QAAO,aAAa;AAAA,EACtC;AACA,MAAI,QAAQ,MAAM,QAAQ,QAAS,QAAO;AAC1C,MAAI,QAAQ,MAAM,WAAW,GAAG;AAC9B,UAAM,YAAY,MAAM,iBAAiB,OAAO;AAChD,QAAI,UAAW,QAAO,YAAY;AAAA,EACpC;AACA,SAAO;AACT;AAEA,eAAe,cAAc,SAAwE;AACnG,QAAM,UAAU,MAAM,QAAQ,QAAQ;AACtC,MAAI,cAAc,SAAS,kBAAkB,iBAAiB,GAAG;AAC/D,UAAM,kBAAkB,cAAc,SAAS,kBAAkB,cAAc;AAC/E,QACE,CAAC;AAAA,MACC;AAAA,MACA,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AQ;AACV,eAAO,UAAU,cAAc,QAAQ,aAAa,SAAS,aAAa,gBAAgB,CAAC;AAC3F;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEA,eAAe,mBAAmB,SAAwD;AACxF,QAAM,SAAS,aAAa,QAAQ,MAAM,YAAY,YAAY;AAClE,MAAI,OAAQ,QAAO;AACnB,QAAM,gBAAgB,aAAa,QAAQ,MAAM,YAAY,aAAa,IAAK;AAC/E,QAAM,YAAY,gBACd,KAAK,WAAW,aAAa,IAAI,gBAAgB,QAAQ,QAAQ,MAAM,KAAK,aAAa,GAAG,aAAa,IACzG,KAAK,QAAQ,MAAM,KAAK,cAAc,aAAa;AACvD,SAAO,aAAa,MAAM,QAAQ,GAAG,SAAS,WAAW,IAAK,CAAC;AACjE;AAEO,SAAS,sBAAsB,QAAgB,SAA4D;AAChH,QAAM,UAAU,YAAY,SAAS,aAAa;AAClD,QAAM,QAAQ,IAAI,OAAO,IAAI,OAAO,mDAAmD,GAAG,EAAE;AAAA,IAC1F,OAAO,KAAK,EAAE,MAAM,QAAQ,EAAE,CAAC,KAAK;AAAA,EACtC;AACA,SAAO,QAAQ,CAAC,IAAI,IAAI,MAAM,CAAC,CAAC,KAAK;AACvC;AAEA,SAAS,aAAa,OAA2C;AAC/D,SAAO,MAAM,QAAQ,KAAK,IAAI,MAAM,OAAO,QAAQ,IAAI,CAAC;AAC1D;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// @ts-nocheck -- the generated entry uses a .ts extension for Pi's Jiti loader.
|
|
3
3
|
import {
|
|
4
4
|
MAX_METADATA_FILE_BYTES,
|
|
5
|
+
detectEnvironment,
|
|
5
6
|
directMatch,
|
|
6
7
|
formatVersion,
|
|
7
8
|
isRecord,
|
|
@@ -11,7 +12,8 @@ import {
|
|
|
11
12
|
runBounded,
|
|
12
13
|
safeMetadata,
|
|
13
14
|
setString
|
|
14
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-S2KBLHE2.ts";
|
|
16
|
+
import "./chunk-KP33I6BR.ts";
|
|
15
17
|
|
|
16
18
|
// src/runtime/development.ts
|
|
17
19
|
import { join } from "node:path";
|
|
@@ -26,20 +28,34 @@ async function collectDevelopment(context) {
|
|
|
26
28
|
if (context.needs("mise", "health")) {
|
|
27
29
|
const output = await runBounded(context, "mise", ["doctor"]);
|
|
28
30
|
const health = output ? parseMiseHealth(output) : void 0;
|
|
29
|
-
if (health)
|
|
31
|
+
if (health) {
|
|
32
|
+
values.health = optionString(context, "mise", health === "healthy" ? "healthy_symbol" : "unhealthy_symbol") ?? health;
|
|
33
|
+
}
|
|
30
34
|
}
|
|
31
35
|
result.mise = values;
|
|
32
36
|
}
|
|
33
|
-
if (context.needs("direnv") && detected(context, entries, "direnv", [".envrc"])) {
|
|
37
|
+
if (context.needs("direnv") && (detected(context, entries, "direnv", [".envrc"]) || optionStrings(context, "direnv", "detect_env_vars").length > 0 && detectEnvironment(context.input.environment, optionStrings(context, "direnv", "detect_env_vars")))) {
|
|
34
38
|
const values = {};
|
|
35
39
|
if (["rc_path", "allowed", "loaded"].some((variable) => context.needs("direnv", variable))) {
|
|
36
40
|
const output = await runBounded(context, "direnv", ["status", "--json"]);
|
|
37
|
-
if (output)
|
|
41
|
+
if (output) {
|
|
42
|
+
Object.assign(
|
|
43
|
+
values,
|
|
44
|
+
parseDirenvStatus(output, {
|
|
45
|
+
allowed: optionString(context, "direnv", "allowed_msg"),
|
|
46
|
+
notAllowed: optionString(context, "direnv", "not_allowed_msg"),
|
|
47
|
+
denied: optionString(context, "direnv", "denied_msg"),
|
|
48
|
+
loaded: optionString(context, "direnv", "loaded_msg"),
|
|
49
|
+
unloaded: optionString(context, "direnv", "unloaded_msg")
|
|
50
|
+
})
|
|
51
|
+
);
|
|
52
|
+
}
|
|
38
53
|
}
|
|
39
54
|
result.direnv = values;
|
|
40
55
|
}
|
|
56
|
+
if (context.input.signal?.aborted) return {};
|
|
41
57
|
const conda = safeMetadata(context.input.environment.CONDA_DEFAULT_ENV);
|
|
42
|
-
if (context.needs("conda") && conda && !(optionBoolean(context, "conda", "ignore_base") && conda === "base")) {
|
|
58
|
+
if (context.needs("conda") && conda && !(optionBoolean(context, "conda", "ignore_base") && conda === "base") && detectEnvironment(context.input.environment, optionStrings(context, "conda", "detect_env_vars"))) {
|
|
43
59
|
result.conda = { environment: conda };
|
|
44
60
|
}
|
|
45
61
|
if (context.needs("pixi") && detected(context, entries, "pixi", ["pixi.toml", "pixi.lock"])) {
|
|
@@ -50,6 +66,7 @@ async function collectDevelopment(context) {
|
|
|
50
66
|
}
|
|
51
67
|
const project = safeMetadata(context.input.environment.PIXI_PROJECT_NAME) ?? await readPixiProject(context);
|
|
52
68
|
if (project) values.project_name = project;
|
|
69
|
+
if (context.input.signal?.aborted) return {};
|
|
53
70
|
if (context.needs("pixi", "version")) {
|
|
54
71
|
const output = await runBounded(context, "pixi", ["--version"]);
|
|
55
72
|
const version = output ? parsePixiVersion(output) : void 0;
|
|
@@ -59,7 +76,9 @@ async function collectDevelopment(context) {
|
|
|
59
76
|
}
|
|
60
77
|
const nixState = safeMetadata(context.input.environment.IN_NIX_SHELL);
|
|
61
78
|
if (context.needs("nix_shell") && (nixState === "pure" || nixState === "impure")) {
|
|
62
|
-
const values = {
|
|
79
|
+
const values = {
|
|
80
|
+
state: optionString(context, "nix_shell", nixState === "pure" ? "pure_msg" : "impure_msg") ?? nixState
|
|
81
|
+
};
|
|
63
82
|
setString(values, "name", context.input.environment.NIX_SHELL_NAME);
|
|
64
83
|
setString(values, "level", context.input.environment.NIX_SHELL_LEVEL);
|
|
65
84
|
result.nix_shell = values;
|
|
@@ -85,25 +104,58 @@ function parseMiseHealth(output) {
|
|
|
85
104
|
if (/\b(?:error|unhealthy|problem|warning)\b/u.test(text)) return "issues";
|
|
86
105
|
return void 0;
|
|
87
106
|
}
|
|
88
|
-
function parseDirenvStatus(output) {
|
|
107
|
+
function parseDirenvStatus(output, messages = {}) {
|
|
108
|
+
const labels = {
|
|
109
|
+
allowed: messages.allowed ?? "allowed",
|
|
110
|
+
notAllowed: messages.notAllowed ?? "not allowed",
|
|
111
|
+
denied: messages.denied ?? "denied",
|
|
112
|
+
loaded: messages.loaded ?? "loaded",
|
|
113
|
+
unloaded: messages.unloaded ?? "not loaded"
|
|
114
|
+
};
|
|
89
115
|
try {
|
|
90
116
|
const document = JSON.parse(output);
|
|
91
117
|
if (!isRecord(document)) return {};
|
|
118
|
+
if (Object.hasOwn(document, "state")) {
|
|
119
|
+
if (!isRecord(document.state)) return {};
|
|
120
|
+
const found2 = isRecord(document.state.foundRC) ? document.state.foundRC : void 0;
|
|
121
|
+
const loaded2 = isRecord(document.state.loadedRC) ? document.state.loadedRC : void 0;
|
|
122
|
+
const path = safeMetadata(found2?.path);
|
|
123
|
+
const allowed = typeof found2?.allowed === "number" ? direnvAllowed(found2.allowed) : void 0;
|
|
124
|
+
const loadedAllowed = loaded2 && typeof loaded2.allowed === "number" ? direnvAllowed(loaded2.allowed) : void 0;
|
|
125
|
+
if (!found2 || !path || !allowed || loaded2 && !loadedAllowed) return {};
|
|
126
|
+
return {
|
|
127
|
+
rc_path: path,
|
|
128
|
+
allowed: labels[allowed],
|
|
129
|
+
loaded: loadedAllowed === "allowed" ? labels.loaded : labels.unloaded
|
|
130
|
+
};
|
|
131
|
+
}
|
|
92
132
|
const values = {};
|
|
93
133
|
const found = isRecord(document.foundRC) ? document.foundRC : void 0;
|
|
94
134
|
const loaded = isRecord(document.loadedRC) ? document.loadedRC : void 0;
|
|
95
135
|
setString(values, "rc_path", found?.path ?? loaded?.path);
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (
|
|
100
|
-
else if (found) values.loaded = "not loaded";
|
|
136
|
+
if (found?.allowed === true || found?.allowed === 1) values.allowed = labels.allowed;
|
|
137
|
+
if (found?.allowed === false || found?.allowed === 0) values.allowed = labels.denied;
|
|
138
|
+
if (loaded) values.loaded = labels.loaded;
|
|
139
|
+
else if (found) values.loaded = labels.unloaded;
|
|
101
140
|
return values;
|
|
102
141
|
} catch {
|
|
103
|
-
const path = /^Found RC path ([^\r\n]+)$/mu.exec(output)?.[1];
|
|
104
|
-
|
|
142
|
+
const path = safeMetadata(/^Found RC path[ \t]+([^\r\n]+)$/mu.exec(output)?.[1]);
|
|
143
|
+
if (!path) return {};
|
|
144
|
+
const values = { rc_path: path };
|
|
145
|
+
const allowed = direnvAllowed(/^Found RC allowed[ \t]+([^\r\n]+)$/mu.exec(output)?.[1]);
|
|
146
|
+
if (allowed) {
|
|
147
|
+
values.allowed = labels[allowed];
|
|
148
|
+
values.loaded = output.includes("No .envrc or .env loaded") ? labels.unloaded : labels.loaded;
|
|
149
|
+
}
|
|
150
|
+
return values;
|
|
105
151
|
}
|
|
106
152
|
}
|
|
153
|
+
function direnvAllowed(value) {
|
|
154
|
+
if (value === 0 || value === "0" || value === "true") return "allowed";
|
|
155
|
+
if (value === 1 || value === "1") return "notAllowed";
|
|
156
|
+
if (value === 2 || value === "2" || value === "false") return "denied";
|
|
157
|
+
return void 0;
|
|
158
|
+
}
|
|
107
159
|
async function readPixiProject(context) {
|
|
108
160
|
const source = await context.fs.readFile(join(context.input.cwd, "pixi.toml"), MAX_METADATA_FILE_BYTES);
|
|
109
161
|
if (!source) return void 0;
|
|
@@ -125,4 +177,4 @@ export {
|
|
|
125
177
|
parseDirenvStatus,
|
|
126
178
|
parseMiseHealth
|
|
127
179
|
};
|
|
128
|
-
//# sourceMappingURL=development-
|
|
180
|
+
//# sourceMappingURL=development-T3XXVVDP.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/runtime/development.ts"],
|
|
4
|
+
"sourcesContent": ["import { join } from \"node:path\";\nimport { parse } from \"smol-toml\";\nimport {\n detectEnvironment,\n directMatch,\n formatVersion,\n isRecord,\n MAX_METADATA_FILE_BYTES,\n optionBoolean,\n optionString,\n optionStrings,\n runBounded,\n safeMetadata,\n setString,\n} from \"./helpers.js\";\nimport type { CollectorContext, MutableModuleSnapshot } from \"./types.js\";\n\nexport async function collectDevelopment(context: CollectorContext): Promise<MutableModuleSnapshot> {\n const result: MutableModuleSnapshot = {};\n const directNames = [\"mise\", \"direnv\", \"pixi\"] as const;\n const needsListing = directNames.some((name) => context.needs(name));\n const entries = needsListing ? await context.entries() : [];\n\n if (context.needs(\"mise\") && detected(context, entries, \"mise\", [\"mise.toml\", \".mise.toml\", \".tool-versions\"])) {\n const values: Record<string, string> = {};\n if (context.needs(\"mise\", \"health\")) {\n const output = await runBounded(context, \"mise\", [\"doctor\"]);\n const health = output ? parseMiseHealth(output) : undefined;\n if (health) {\n values.health =\n optionString(context, \"mise\", health === \"healthy\" ? \"healthy_symbol\" : \"unhealthy_symbol\") ?? health;\n }\n }\n result.mise = values;\n }\n\n if (\n context.needs(\"direnv\") &&\n (detected(context, entries, \"direnv\", [\".envrc\"]) ||\n (optionStrings(context, \"direnv\", \"detect_env_vars\").length > 0 &&\n detectEnvironment(context.input.environment, optionStrings(context, \"direnv\", \"detect_env_vars\"))))\n ) {\n const values: Record<string, string> = {};\n if ([\"rc_path\", \"allowed\", \"loaded\"].some((variable) => context.needs(\"direnv\", variable))) {\n const output = await runBounded(context, \"direnv\", [\"status\", \"--json\"]);\n if (output) {\n Object.assign(\n values,\n parseDirenvStatus(output, {\n allowed: optionString(context, \"direnv\", \"allowed_msg\"),\n notAllowed: optionString(context, \"direnv\", \"not_allowed_msg\"),\n denied: optionString(context, \"direnv\", \"denied_msg\"),\n loaded: optionString(context, \"direnv\", \"loaded_msg\"),\n unloaded: optionString(context, \"direnv\", \"unloaded_msg\"),\n }),\n );\n }\n }\n result.direnv = values;\n }\n\n if (context.input.signal?.aborted) return {};\n const conda = safeMetadata(context.input.environment.CONDA_DEFAULT_ENV);\n if (\n context.needs(\"conda\") &&\n conda &&\n !(optionBoolean(context, \"conda\", \"ignore_base\") && conda === \"base\") &&\n detectEnvironment(context.input.environment, optionStrings(context, \"conda\", \"detect_env_vars\"))\n ) {\n result.conda = { environment: conda };\n }\n\n if (context.needs(\"pixi\") && detected(context, entries, \"pixi\", [\"pixi.toml\", \"pixi.lock\"])) {\n const values: Record<string, string> = {};\n const environment = safeMetadata(context.input.environment.PIXI_ENVIRONMENT_NAME);\n if (environment && (environment !== \"default\" || optionBoolean(context, \"pixi\", \"show_default_environment\"))) {\n values.environment = environment;\n }\n const project = safeMetadata(context.input.environment.PIXI_PROJECT_NAME) ?? (await readPixiProject(context));\n if (project) values.project_name = project;\n if (context.input.signal?.aborted) return {};\n if (context.needs(\"pixi\", \"version\")) {\n const output = await runBounded(context, \"pixi\", [\"--version\"]);\n const version = output ? parsePixiVersion(output) : undefined;\n if (version) values.version = formatVersion(version, optionString(context, \"pixi\", \"version_format\"));\n }\n result.pixi = values;\n }\n\n const nixState = safeMetadata(context.input.environment.IN_NIX_SHELL);\n if (context.needs(\"nix_shell\") && (nixState === \"pure\" || nixState === \"impure\")) {\n const values: Record<string, string> = {\n state: optionString(context, \"nix_shell\", nixState === \"pure\" ? \"pure_msg\" : \"impure_msg\") ?? nixState,\n };\n setString(values, \"name\", context.input.environment.NIX_SHELL_NAME);\n setString(values, \"level\", context.input.environment.NIX_SHELL_LEVEL);\n result.nix_shell = values;\n }\n\n if (context.needs(\"guix_shell\") && safeMetadata(context.input.environment.GUIX_ENVIRONMENT)) {\n result.guix_shell = { state: \"active\" };\n }\n return result;\n}\n\nfunction detected(\n context: CollectorContext,\n entries: Awaited<ReturnType<CollectorContext[\"entries\"]>>,\n name: \"mise\" | \"direnv\" | \"pixi\",\n defaultFiles: string[],\n): boolean {\n const files = optionStrings(context, name, \"detect_files\");\n return directMatch(\n entries,\n files.length > 0 ? files : defaultFiles,\n optionStrings(context, name, \"detect_extensions\"),\n optionStrings(context, name, \"detect_folders\"),\n );\n}\n\nexport function parseMiseHealth(output: string): string | undefined {\n const text = safeMetadata(output, 8_192)?.toLowerCase();\n if (!text) return undefined;\n if (/\\b(?:healthy|no problems found|all checks passed)\\b/u.test(text)) return \"healthy\";\n if (/\\b(?:error|unhealthy|problem|warning)\\b/u.test(text)) return \"issues\";\n return undefined;\n}\n\ninterface DirenvMessages {\n allowed?: string;\n notAllowed?: string;\n denied?: string;\n loaded?: string;\n unloaded?: string;\n}\n\nexport function parseDirenvStatus(output: string, messages: DirenvMessages = {}): Record<string, string> {\n const labels = {\n allowed: messages.allowed ?? \"allowed\",\n notAllowed: messages.notAllowed ?? \"not allowed\",\n denied: messages.denied ?? \"denied\",\n loaded: messages.loaded ?? \"loaded\",\n unloaded: messages.unloaded ?? \"not loaded\",\n };\n try {\n const document = JSON.parse(output) as unknown;\n if (!isRecord(document)) return {};\n if (Object.hasOwn(document, \"state\")) {\n if (!isRecord(document.state)) return {};\n const found = isRecord(document.state.foundRC) ? document.state.foundRC : undefined;\n const loaded = isRecord(document.state.loadedRC) ? document.state.loadedRC : undefined;\n const path = safeMetadata(found?.path);\n const allowed = typeof found?.allowed === \"number\" ? direnvAllowed(found.allowed) : undefined;\n const loadedAllowed = loaded && typeof loaded.allowed === \"number\" ? direnvAllowed(loaded.allowed) : undefined;\n if (!found || !path || !allowed || (loaded && !loadedAllowed)) return {};\n return {\n rc_path: path,\n allowed: labels[allowed],\n loaded: loadedAllowed === \"allowed\" ? labels.loaded : labels.unloaded,\n };\n }\n // Retain Pi's older top-level boolean/0-or-1 snapshot interpretation.\n // Actual direnv JSON nests numeric 0/1/2 statuses under state (handled above).\n const values: Record<string, string> = {};\n const found = isRecord(document.foundRC) ? document.foundRC : undefined;\n const loaded = isRecord(document.loadedRC) ? document.loadedRC : undefined;\n setString(values, \"rc_path\", found?.path ?? loaded?.path);\n if (found?.allowed === true || found?.allowed === 1) values.allowed = labels.allowed;\n if (found?.allowed === false || found?.allowed === 0) values.allowed = labels.denied;\n if (loaded) values.loaded = labels.loaded;\n else if (found) values.loaded = labels.unloaded;\n return values;\n } catch {\n const path = safeMetadata(/^Found RC path[ \\t]+([^\\r\\n]+)$/mu.exec(output)?.[1]);\n if (!path) return {};\n const values: Record<string, string> = { rc_path: path };\n const allowed = direnvAllowed(/^Found RC allowed[ \\t]+([^\\r\\n]+)$/mu.exec(output)?.[1]);\n if (allowed) {\n values.allowed = labels[allowed];\n values.loaded = output.includes(\"No .envrc or .env loaded\") ? labels.unloaded : labels.loaded;\n }\n return values;\n }\n}\n\nfunction direnvAllowed(value: unknown): \"allowed\" | \"notAllowed\" | \"denied\" | undefined {\n if (value === 0 || value === \"0\" || value === \"true\") return \"allowed\";\n if (value === 1 || value === \"1\") return \"notAllowed\";\n if (value === 2 || value === \"2\" || value === \"false\") return \"denied\";\n return undefined;\n}\n\nasync function readPixiProject(context: CollectorContext): Promise<string | undefined> {\n const source = await context.fs.readFile(join(context.input.cwd, \"pixi.toml\"), MAX_METADATA_FILE_BYTES);\n if (!source) return undefined;\n try {\n const document = parse(source);\n const project = isRecord(document.project) ? document.project : undefined;\n const workspace = isRecord(document.workspace) ? document.workspace : undefined;\n return safeMetadata(project?.name) ?? safeMetadata(workspace?.name);\n } catch {\n return undefined;\n }\n}\n\nfunction parsePixiVersion(output: string): string | undefined {\n const match = /^(?:pixi\\s+)?(\\d+\\.\\d+\\.\\d+(?:[-+][0-9A-Za-z.-]+)?)$/u.exec(output.trim());\n return match?.[1] ? `v${match[1]}` : undefined;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY;AACrB,SAAS,aAAa;AAgBtB,eAAsB,mBAAmB,SAA2D;AAClG,QAAM,SAAgC,CAAC;AACvC,QAAM,cAAc,CAAC,QAAQ,UAAU,MAAM;AAC7C,QAAM,eAAe,YAAY,KAAK,CAAC,SAAS,QAAQ,MAAM,IAAI,CAAC;AACnE,QAAM,UAAU,eAAe,MAAM,QAAQ,QAAQ,IAAI,CAAC;AAE1D,MAAI,QAAQ,MAAM,MAAM,KAAK,SAAS,SAAS,SAAS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AACzC,MAAI,UAAU,KAAK,UAAU,OAAO,UAAU,QAAS,QAAO;AAC9D,SAAO;AACT;AAEA,eAAe,gBAAgB,SAAwD;AACrF,QAAM,SAAS,MAAM,QAAQ,GAAG,SAAS,KAAK,QAAQ,MAAM,KAAK,WAAW,GAAG,uBAAuB;AACtG,MAAI,CAAC,OAAQ,QAAO;AACpB,MAAI;AACF,UAAM,WAAW,MAAM,MAAM;AAC7B,UAAM,UAAU,SAAS,SAAS,OAAO,IAAI,SAAS,UAAU;AAChE,UAAM,YAAY,SAAS,SAAS,SAAS,IAAI,SAAS,YAAY;AACtE,WAAO,aAAa,SAAS,IAAI,KAAK,aAAa,WAAW,IAAI;AAAA,EACpE,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,iBAAiB,QAAoC;AAC5D,QAAM,QAAQ,wDAAwD,KAAK,OAAO,KAAK,CAAC;AACxF,SAAO,QAAQ,CAAC,IAAI,IAAI,MAAM,CAAC,CAAC,KAAK;AACvC;",
|
|
6
|
+
"names": ["found", "loaded"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// @generated by scripts/build-runtime.mjs; do not edit.
|
|
2
|
+
// @ts-nocheck -- the generated entry uses a .ts extension for Pi's Jiti loader.
|
|
3
|
+
|
|
4
|
+
// src/runtime/directory.ts
|
|
5
|
+
import { isAbsolute } from "node:path";
|
|
6
|
+
import { sanitizeTerminalText } from "@narumitw/pi-tui-kit/terminal-text";
|
|
7
|
+
var PATH_VARIABLES = ["path", "full_path", "before_root_path", "repo_root"];
|
|
8
|
+
async function collectDirectory(context) {
|
|
9
|
+
const { input } = context;
|
|
10
|
+
if (input.signal?.aborted || !context.needs("directory")) return {};
|
|
11
|
+
const options = context.options("directory");
|
|
12
|
+
const needsPhysicalPath = options.use_logical_path === false && PATH_VARIABLES.some((name) => context.needs("directory", name));
|
|
13
|
+
const needsPermission = context.needs("directory", "read_only") && typeof options.read_only === "string" && sanitizeTerminalText(options.read_only).length > 0;
|
|
14
|
+
if (!needsPhysicalPath && !needsPermission) return {};
|
|
15
|
+
const values = {};
|
|
16
|
+
if (needsPhysicalPath) {
|
|
17
|
+
const path = await context.fs.realPath?.(input.cwd).catch(() => void 0);
|
|
18
|
+
if (input.signal?.aborted) return {};
|
|
19
|
+
if (typeof path === "string" && isAbsolute(path)) values.physical_path = path;
|
|
20
|
+
}
|
|
21
|
+
if (needsPermission) {
|
|
22
|
+
const writable = await context.fs.isWritable?.(input.cwd).catch(() => void 0);
|
|
23
|
+
if (input.signal?.aborted) return {};
|
|
24
|
+
if (typeof writable === "boolean") values.read_only = writable ? "false" : "true";
|
|
25
|
+
}
|
|
26
|
+
return Object.keys(values).length > 0 ? { directory: values } : {};
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
collectDirectory
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=directory-OX6BWJZA.ts.map
|