@narumitw/pi-starship 0.46.0 → 0.49.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 +3 -2
- package/package.json +2 -2
- package/src/command-contract.ts +13 -0
- package/src/commands.ts +40 -44
- package/src/config.ts +12 -8
- package/src/pi-starship.ts +25 -2
- package/src/runtime/workspace.ts +39 -19
package/README.md
CHANGED
|
@@ -633,7 +633,8 @@ Keep `extension_status` last in the catalog so arbitrary third-party statuses fo
|
|
|
633
633
|
- `src/index.ts` — Pi package entrypoint.
|
|
634
634
|
- `src/pi-starship.ts` — extension lifecycle, cached refresh binding, live preview, and footer.
|
|
635
635
|
- `src/usage.ts` — native-aligned session usage and cache aggregation.
|
|
636
|
-
- `src/
|
|
636
|
+
- `src/command-contract.ts` — lightweight command routes and completions loaded at startup.
|
|
637
|
+
- `src/commands.ts` — lazily loaded menu, preview/confirmation flow, diagnostics, and compatibility routes.
|
|
637
638
|
- `src/command-inspector.ts` — adaptive Explain and searchable read-only module inspection surfaces.
|
|
638
639
|
- `src/command-preview.ts` — adaptive, scrollable, keybinding-aware preview action surface.
|
|
639
640
|
- `src/config.ts` — TOML loading, draft validation, defaults, atomic persistence, and rollback.
|
|
@@ -642,7 +643,7 @@ Keep `extension_status` last in the catalog so arbitrary third-party statuses fo
|
|
|
642
643
|
- `src/modules/git/` — bounded local Git reader plus branch, status, and worktree modules.
|
|
643
644
|
- `src/modules/github-pr.ts` — pure native GitHub PR snapshot presentation.
|
|
644
645
|
- `src/runtime/github-pr.ts` — bounded `gh` query, validation, terminal-safe links, and expiry data.
|
|
645
|
-
- `src/runtime/` — shared refresh controller and
|
|
646
|
+
- `src/runtime/` — shared refresh controller and requirement-gated, lazily loaded package/language/context collectors.
|
|
646
647
|
|
|
647
648
|
## 🔎 Keywords
|
|
648
649
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@narumitw/pi-starship",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.49.0",
|
|
4
4
|
"description": "Native Starship-style TOML statusline for the Pi coding agent.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"typecheck": "tsc --noEmit"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@narumitw/pi-tui-kit": "^0.
|
|
34
|
+
"@narumitw/pi-tui-kit": "^0.46.0",
|
|
35
35
|
"smol-toml": "^1.7.1",
|
|
36
36
|
"yaml": "^2.9.0"
|
|
37
37
|
},
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AutocompleteItem } from "@earendil-works/pi-tui";
|
|
2
|
+
|
|
3
|
+
export const STARSHIP_SUBCOMMANDS: readonly AutocompleteItem[] = [
|
|
4
|
+
{ value: "settings", label: "settings", description: "Customize the footer TOML" },
|
|
5
|
+
{ value: "status", label: "status", description: "Show configuration health and source" },
|
|
6
|
+
{ value: "help", label: "help", description: "Show configuration help" },
|
|
7
|
+
];
|
|
8
|
+
|
|
9
|
+
export function completeStarshipArguments(prefix: string): AutocompleteItem[] | null {
|
|
10
|
+
const normalized = prefix.trim().toLowerCase();
|
|
11
|
+
const matches = STARSHIP_SUBCOMMANDS.filter((item) => item.value.startsWith(normalized));
|
|
12
|
+
return matches.length > 0 ? [...matches] : null;
|
|
13
|
+
}
|
package/src/commands.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import type { AutocompleteItem } from "@earendil-works/pi-tui";
|
|
3
2
|
import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
|
|
3
|
+
import { completeStarshipArguments, STARSHIP_SUBCOMMANDS } from "./command-contract.js";
|
|
4
4
|
import { showFooterExplanation } from "./command-inspector.js";
|
|
5
5
|
import { type PreviewMenuResult, showPreviewActionMenu } from "./command-preview.js";
|
|
6
6
|
import {
|
|
@@ -13,12 +13,6 @@ import {
|
|
|
13
13
|
} from "./config.js";
|
|
14
14
|
import { inspectUnavailableModules, type StatuslineInspection } from "./modules/inspection.js";
|
|
15
15
|
|
|
16
|
-
const SUBCOMMANDS: AutocompleteItem[] = [
|
|
17
|
-
{ value: "settings", label: "settings", description: "Customize the footer TOML" },
|
|
18
|
-
{ value: "status", label: "status", description: "Show configuration health and source" },
|
|
19
|
-
{ value: "help", label: "help", description: "Show configuration help" },
|
|
20
|
-
];
|
|
21
|
-
|
|
22
16
|
const MAIN_ACTIONS = {
|
|
23
17
|
customize: "customize",
|
|
24
18
|
explain: "explain",
|
|
@@ -58,46 +52,48 @@ interface WorkflowOwner {
|
|
|
58
52
|
export function registerStarshipCommand(pi: ExtensionAPI, options: StarshipCommandOptions) {
|
|
59
53
|
pi.registerCommand("starship", {
|
|
60
54
|
description: "Customize or inspect the native Starship-style footer",
|
|
61
|
-
getArgumentCompletions
|
|
62
|
-
|
|
63
|
-
const matches = SUBCOMMANDS.filter((item) => item.value.startsWith(normalized));
|
|
64
|
-
return matches.length > 0 ? matches : null;
|
|
65
|
-
},
|
|
66
|
-
handler: async (args, ctx) => {
|
|
67
|
-
const normalized = args.trim();
|
|
68
|
-
if (!normalized) {
|
|
69
|
-
if (ctx.mode === "tui") await showMainMenu(ctx, options);
|
|
70
|
-
else showHelp(ctx, options.settingsPath);
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const [subcommand = "", ...trailing] = normalized.split(/\s+/u);
|
|
75
|
-
const route = subcommand.toLowerCase();
|
|
76
|
-
if (trailing.length > 0 || !SUBCOMMANDS.some((item) => item.value === route)) {
|
|
77
|
-
if (canNotify(ctx)) {
|
|
78
|
-
const reason =
|
|
79
|
-
trailing.length > 0
|
|
80
|
-
? `Unexpected arguments for /starship ${safeText(route)}.`
|
|
81
|
-
: `Unknown /starship subcommand: ${safeText(route)}.`;
|
|
82
|
-
ctx.ui.notify(`${reason} Usage: /starship [settings|status|help]`, "warning");
|
|
83
|
-
}
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
switch (route) {
|
|
87
|
-
case "settings":
|
|
88
|
-
await editSettings(ctx, options);
|
|
89
|
-
return;
|
|
90
|
-
case "status":
|
|
91
|
-
showStatus(ctx, options);
|
|
92
|
-
return;
|
|
93
|
-
case "help":
|
|
94
|
-
showHelp(ctx, options.settingsPath);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
},
|
|
55
|
+
getArgumentCompletions: completeStarshipArguments,
|
|
56
|
+
handler: (args, ctx) => handleStarshipCommand(args, ctx, options),
|
|
98
57
|
});
|
|
99
58
|
}
|
|
100
59
|
|
|
60
|
+
export async function handleStarshipCommand(
|
|
61
|
+
args: string,
|
|
62
|
+
ctx: ExtensionCommandContext,
|
|
63
|
+
options: StarshipCommandOptions,
|
|
64
|
+
) {
|
|
65
|
+
const normalized = args.trim();
|
|
66
|
+
if (!normalized) {
|
|
67
|
+
if (ctx.mode === "tui") await showMainMenu(ctx, options);
|
|
68
|
+
else showHelp(ctx, options.settingsPath);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const [subcommand = "", ...trailing] = normalized.split(/\s+/u);
|
|
73
|
+
const route = subcommand.toLowerCase();
|
|
74
|
+
if (trailing.length > 0 || !STARSHIP_SUBCOMMANDS.some((item) => item.value === route)) {
|
|
75
|
+
if (canNotify(ctx)) {
|
|
76
|
+
const reason =
|
|
77
|
+
trailing.length > 0
|
|
78
|
+
? `Unexpected arguments for /starship ${safeText(route)}.`
|
|
79
|
+
: `Unknown /starship subcommand: ${safeText(route)}.`;
|
|
80
|
+
ctx.ui.notify(`${reason} Usage: /starship [settings|status|help]`, "warning");
|
|
81
|
+
}
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
switch (route) {
|
|
85
|
+
case "settings":
|
|
86
|
+
await editSettings(ctx, options);
|
|
87
|
+
return;
|
|
88
|
+
case "status":
|
|
89
|
+
showStatus(ctx, options);
|
|
90
|
+
return;
|
|
91
|
+
case "help":
|
|
92
|
+
showHelp(ctx, options.settingsPath);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
101
97
|
async function showMainMenu(ctx: ExtensionCommandContext, options: StarshipCommandOptions) {
|
|
102
98
|
const fallbackController = new AbortController();
|
|
103
99
|
const owner = options.getMenuOwner?.() ?? {
|
package/src/config.ts
CHANGED
|
@@ -8,8 +8,9 @@ import {
|
|
|
8
8
|
rmSync,
|
|
9
9
|
writeFileSync,
|
|
10
10
|
} from "node:fs";
|
|
11
|
+
import { createRequire } from "node:module";
|
|
11
12
|
import { dirname, join } from "node:path";
|
|
12
|
-
import {
|
|
13
|
+
import type { TomlTable } from "smol-toml";
|
|
13
14
|
import {
|
|
14
15
|
type FormatNode,
|
|
15
16
|
formatVariables,
|
|
@@ -83,7 +84,8 @@ $activity\
|
|
|
83
84
|
$context\
|
|
84
85
|
$time"""`;
|
|
85
86
|
|
|
86
|
-
const BUILT_IN_FORMAT =
|
|
87
|
+
const BUILT_IN_FORMAT =
|
|
88
|
+
"$brand$model$thinking$directory$git_branch$git_status$activity$context$time";
|
|
87
89
|
|
|
88
90
|
const BUILT_IN_MODULES = Object.fromEntries(
|
|
89
91
|
MODULE_DEFINITIONS.map(({ name, defaults, styleDefaults, displayDefaults, options }) => [
|
|
@@ -114,10 +116,12 @@ export const BUILT_IN_CONFIG: StarshipConfig = {
|
|
|
114
116
|
|
|
115
117
|
export const BUILT_IN_EXAMPLE = `# Native Pi modules with Starship-compatible format and style syntax.\n${BUILT_IN_FORMAT_DOCUMENT}\n`;
|
|
116
118
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
const require = createRequire(import.meta.url);
|
|
120
|
+
let parseTomlImplementation: typeof import("smol-toml")["parse"] | undefined;
|
|
121
|
+
|
|
122
|
+
function parseToml(document: string): TomlTable {
|
|
123
|
+
parseTomlImplementation ??= (require("smol-toml") as typeof import("smol-toml")).parse;
|
|
124
|
+
return parseTomlImplementation(document);
|
|
121
125
|
}
|
|
122
126
|
|
|
123
127
|
export function settingsFilePath(agentDir: string): string {
|
|
@@ -147,7 +151,7 @@ export function loadStarshipConfig(settingsPath: string): LoadedStarshipConfig {
|
|
|
147
151
|
|
|
148
152
|
let parsed: TomlTable;
|
|
149
153
|
try {
|
|
150
|
-
parsed =
|
|
154
|
+
parsed = parseToml(rawDocument);
|
|
151
155
|
} catch (error) {
|
|
152
156
|
return {
|
|
153
157
|
config: cloneBuiltInConfig(),
|
|
@@ -413,7 +417,7 @@ export function validateConfigDocument(
|
|
|
413
417
|
): LoadedStarshipConfig {
|
|
414
418
|
let parsed: TomlTable;
|
|
415
419
|
try {
|
|
416
|
-
parsed =
|
|
420
|
+
parsed = parseToml(rawDocument);
|
|
417
421
|
} catch (error) {
|
|
418
422
|
throw new Error(`Unable to parse TOML: ${formatError(error)}`);
|
|
419
423
|
}
|
package/src/pi-starship.ts
CHANGED
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
type ReadonlyFooterDataProvider,
|
|
7
7
|
} from "@earendil-works/pi-coding-agent";
|
|
8
8
|
import { wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
9
|
-
import {
|
|
9
|
+
import { completeStarshipArguments } from "./command-contract.js";
|
|
10
|
+
import type { StarshipCommandOptions } from "./commands.js";
|
|
10
11
|
import {
|
|
11
12
|
type LoadedStarshipConfig,
|
|
12
13
|
loadStarshipConfig,
|
|
@@ -40,6 +41,19 @@ const GITHUB_PR_REFRESH_INTERVAL_MS = 60_000;
|
|
|
40
41
|
const EVENT_DEBOUNCE_MS = 250;
|
|
41
42
|
const MAX_TIMER_DELAY_MS = 2_147_483_647;
|
|
42
43
|
|
|
44
|
+
type StarshipCommands = typeof import("./commands.js");
|
|
45
|
+
let starshipCommandsPromise: Promise<StarshipCommands> | undefined;
|
|
46
|
+
|
|
47
|
+
function loadStarshipCommands(): Promise<StarshipCommands> {
|
|
48
|
+
if (!starshipCommandsPromise) {
|
|
49
|
+
starshipCommandsPromise = import("./commands.js").catch((error) => {
|
|
50
|
+
starshipCommandsPromise = undefined;
|
|
51
|
+
throw error;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return starshipCommandsPromise;
|
|
55
|
+
}
|
|
56
|
+
|
|
43
57
|
interface RuntimeState {
|
|
44
58
|
activeTools: Map<string, number>;
|
|
45
59
|
isStreaming: boolean;
|
|
@@ -328,7 +342,7 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
328
342
|
};
|
|
329
343
|
|
|
330
344
|
const configPath = settingsFilePath(getAgentDir());
|
|
331
|
-
|
|
345
|
+
const commandOptions: StarshipCommandOptions = {
|
|
332
346
|
settingsPath: configPath,
|
|
333
347
|
getLoaded: () => loaded ?? loadStarshipConfig(configPath),
|
|
334
348
|
getInspection: () => {
|
|
@@ -363,6 +377,15 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
363
377
|
]
|
|
364
378
|
);
|
|
365
379
|
},
|
|
380
|
+
};
|
|
381
|
+
pi.registerCommand("starship", {
|
|
382
|
+
description: "Customize or inspect the native Starship-style footer",
|
|
383
|
+
getArgumentCompletions: completeStarshipArguments,
|
|
384
|
+
handler: async (args, ctx) => {
|
|
385
|
+
const commands = await loadStarshipCommands();
|
|
386
|
+
if (sessionOwner !== ctx.sessionManager) return;
|
|
387
|
+
await commands.handleStarshipCommand(args, ctx, commandOptions);
|
|
388
|
+
},
|
|
366
389
|
});
|
|
367
390
|
|
|
368
391
|
pi.on("session_start", (_event, ctx) => {
|
package/src/runtime/workspace.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import type { ModuleName } from "../modules/catalog.js";
|
|
2
2
|
import { reachableModuleRequirements } from "../modules/render.js";
|
|
3
3
|
import type { WorkspaceSnapshot } from "../modules/types.js";
|
|
4
|
-
import { collectCloud } from "./cloud.js";
|
|
5
|
-
import { collectDeployment } from "./deployment.js";
|
|
6
|
-
import { collectDevelopment } from "./development.js";
|
|
7
|
-
import { collectExecution } from "./execution.js";
|
|
8
4
|
import { createFileSystem } from "./helpers.js";
|
|
9
|
-
import { collectLanguages } from "./languages.js";
|
|
10
|
-
import { collectPackage } from "./package.js";
|
|
11
5
|
import {
|
|
12
6
|
type CollectorContext,
|
|
13
7
|
type MutableModuleSnapshot,
|
|
@@ -16,9 +10,6 @@ import {
|
|
|
16
10
|
type WorkspaceRefreshInput,
|
|
17
11
|
} from "./types.js";
|
|
18
12
|
|
|
19
|
-
export { parseTerraformVersion } from "./deployment.js";
|
|
20
|
-
export { parseDirenvStatus, parseMiseHealth } from "./development.js";
|
|
21
|
-
export { parseRuntimeVersion } from "./languages.js";
|
|
22
13
|
export type { WorkspaceExec, WorkspaceExecResult, WorkspaceRefreshInput } from "./types.js";
|
|
23
14
|
|
|
24
15
|
export async function collectWorkspaceSnapshot(
|
|
@@ -45,16 +36,17 @@ export async function collectWorkspaceSnapshot(
|
|
|
45
36
|
},
|
|
46
37
|
};
|
|
47
38
|
const modules: MutableModuleSnapshot = {};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
39
|
+
if (requirements.has("package")) {
|
|
40
|
+
const { collectPackage } = await import("./package.js");
|
|
41
|
+
if (input.signal?.aborted) return freezeSnapshot({});
|
|
42
|
+
const packageValues = await collectPackage(context);
|
|
43
|
+
if (input.signal?.aborted) return freezeSnapshot({});
|
|
44
|
+
if (packageValues) modules.package = packageValues;
|
|
45
|
+
}
|
|
46
|
+
for (const descriptor of COLLECTOR_GROUPS) {
|
|
47
|
+
if (!descriptor.modules.some((name) => requirements.has(name))) continue;
|
|
48
|
+
if (input.signal?.aborted) return freezeSnapshot({});
|
|
49
|
+
const collector = await descriptor.load();
|
|
58
50
|
if (input.signal?.aborted) return freezeSnapshot({});
|
|
59
51
|
mergeModules(modules, await collector(context));
|
|
60
52
|
}
|
|
@@ -74,6 +66,34 @@ function hasWorkspaceRequirement(
|
|
|
74
66
|
return [...requirements.keys()].some((name) => !BUILT_IN_ONLY_MODULES.has(name));
|
|
75
67
|
}
|
|
76
68
|
|
|
69
|
+
type WorkspaceCollector = (context: CollectorContext) => Promise<MutableModuleSnapshot>;
|
|
70
|
+
|
|
71
|
+
const COLLECTOR_GROUPS: readonly {
|
|
72
|
+
modules: readonly ModuleName[];
|
|
73
|
+
load(): Promise<WorkspaceCollector>;
|
|
74
|
+
}[] = [
|
|
75
|
+
{
|
|
76
|
+
modules: ["nodejs", "python", "rust", "golang", "bun", "deno"],
|
|
77
|
+
load: async () => (await import("./languages.js")).collectLanguages,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
modules: ["mise", "direnv", "pixi", "conda", "nix_shell", "guix_shell"],
|
|
81
|
+
load: async () => (await import("./development.js")).collectDevelopment,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
modules: ["docker_context", "kubernetes", "terraform"],
|
|
85
|
+
load: async () => (await import("./deployment.js")).collectDeployment,
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
modules: ["aws", "gcloud", "azure", "openstack"],
|
|
89
|
+
load: async () => (await import("./cloud.js")).collectCloud,
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
modules: ["container", "hostname", "os", "username"],
|
|
93
|
+
load: async () => (await import("./execution.js")).collectExecution,
|
|
94
|
+
},
|
|
95
|
+
];
|
|
96
|
+
|
|
77
97
|
const BUILT_IN_ONLY_MODULES = new Set<ModuleName>([
|
|
78
98
|
"brand",
|
|
79
99
|
"provider",
|