@narumitw/pi-starship 0.28.0 → 0.31.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/NOTICES.md +18 -1
- package/README.md +189 -15
- package/package.json +6 -5
- package/src/commands.ts +405 -22
- package/src/config.ts +113 -11
- package/src/format/formatter.ts +26 -11
- package/src/format/style.ts +13 -1
- package/src/modules/catalog.ts +20 -0
- package/src/modules/cloud.ts +74 -0
- package/src/modules/deployment.ts +61 -0
- package/src/modules/development.ts +95 -0
- package/src/modules/execution.ts +73 -0
- package/src/modules/fill.ts +14 -0
- package/src/modules/git/branch.ts +7 -3
- package/src/modules/git/commit.ts +22 -0
- package/src/modules/git/metrics.ts +20 -0
- package/src/modules/git/runtime.ts +320 -41
- package/src/modules/git/state.ts +21 -0
- package/src/modules/git/status.ts +62 -11
- package/src/modules/index.ts +7 -1
- package/src/modules/languages.ts +87 -0
- package/src/modules/package.ts +17 -0
- package/src/modules/render.ts +97 -9
- package/src/modules/types.ts +65 -2
- package/src/modules/workspace-helpers.ts +10 -0
- package/src/pi-starship.ts +230 -104
- package/src/runtime/cloud.ts +166 -0
- package/src/runtime/command.ts +85 -0
- package/src/runtime/deployment.ts +201 -0
- package/src/runtime/development.ts +154 -0
- package/src/runtime/execution.ts +141 -0
- package/src/runtime/helpers.ts +273 -0
- package/src/runtime/languages.ts +205 -0
- package/src/runtime/package.ts +112 -0
- package/src/runtime/refresh-controller.ts +85 -0
- package/src/runtime/types.ts +59 -0
- package/src/runtime/workspace.ts +110 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { StarshipConfig } from "../config.js";
|
|
2
|
+
import type { ModuleName } from "../modules/catalog.js";
|
|
3
|
+
import type { WorkspaceSnapshot } from "../modules/types.js";
|
|
4
|
+
|
|
5
|
+
export interface WorkspaceExecResult {
|
|
6
|
+
stdout: string;
|
|
7
|
+
stderr: string;
|
|
8
|
+
code: number;
|
|
9
|
+
killed: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type WorkspaceExec = (
|
|
13
|
+
command: string,
|
|
14
|
+
args: string[],
|
|
15
|
+
options: {
|
|
16
|
+
cwd: string;
|
|
17
|
+
timeout: number;
|
|
18
|
+
maxOutputBytes: number;
|
|
19
|
+
environment: Readonly<Record<string, string | undefined>>;
|
|
20
|
+
},
|
|
21
|
+
) => Promise<WorkspaceExecResult>;
|
|
22
|
+
|
|
23
|
+
export interface WorkspaceEntry {
|
|
24
|
+
name: string;
|
|
25
|
+
isFile: boolean;
|
|
26
|
+
isDirectory: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface WorkspaceFileSystem {
|
|
30
|
+
readFile(path: string, maxBytes: number): Promise<string | undefined>;
|
|
31
|
+
readDirectory(path: string): Promise<readonly WorkspaceEntry[]>;
|
|
32
|
+
fileExists(path: string): Promise<boolean>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface WorkspaceRefreshInput {
|
|
36
|
+
cwd: string;
|
|
37
|
+
config: StarshipConfig;
|
|
38
|
+
environment: Readonly<Record<string, string | undefined>>;
|
|
39
|
+
homeDir: string;
|
|
40
|
+
platform: NodeJS.Platform;
|
|
41
|
+
hostname: string;
|
|
42
|
+
username: string;
|
|
43
|
+
exec: WorkspaceExec;
|
|
44
|
+
fileSystem?: Partial<WorkspaceFileSystem>;
|
|
45
|
+
fileExists?(path: string): Promise<boolean>;
|
|
46
|
+
reason?: "initial" | "event" | "periodic";
|
|
47
|
+
previous?: WorkspaceSnapshot;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface CollectorContext {
|
|
51
|
+
input: WorkspaceRefreshInput;
|
|
52
|
+
fs: WorkspaceFileSystem;
|
|
53
|
+
requirements: ReadonlyMap<ModuleName, ReadonlySet<string>>;
|
|
54
|
+
entries(): Promise<readonly WorkspaceEntry[]>;
|
|
55
|
+
options(name: ModuleName): Readonly<Record<string, unknown>>;
|
|
56
|
+
needs(name: ModuleName, variable?: string): boolean;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type MutableModuleSnapshot = Record<string, Record<string, string>>;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { ModuleName } from "../modules/catalog.js";
|
|
2
|
+
import { reachableModuleRequirements } from "../modules/render.js";
|
|
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
|
+
import { createFileSystem } from "./helpers.js";
|
|
9
|
+
import { collectLanguages } from "./languages.js";
|
|
10
|
+
import { collectPackage } from "./package.js";
|
|
11
|
+
import type {
|
|
12
|
+
CollectorContext,
|
|
13
|
+
MutableModuleSnapshot,
|
|
14
|
+
WorkspaceEntry,
|
|
15
|
+
WorkspaceRefreshInput,
|
|
16
|
+
} from "./types.js";
|
|
17
|
+
|
|
18
|
+
export { parseTerraformVersion } from "./deployment.js";
|
|
19
|
+
export { parseDirenvStatus, parseMiseHealth } from "./development.js";
|
|
20
|
+
export { parseRuntimeVersion } from "./languages.js";
|
|
21
|
+
export type { WorkspaceExec, WorkspaceRefreshInput } from "./types.js";
|
|
22
|
+
|
|
23
|
+
export async function collectWorkspaceSnapshot(
|
|
24
|
+
input: WorkspaceRefreshInput,
|
|
25
|
+
): Promise<WorkspaceSnapshot> {
|
|
26
|
+
const requirements = reachableModuleRequirements(input.config);
|
|
27
|
+
if (!hasWorkspaceRequirement(requirements)) return freezeSnapshot({});
|
|
28
|
+
const fs = createFileSystem(input);
|
|
29
|
+
let listing: Promise<readonly WorkspaceEntry[]> | undefined;
|
|
30
|
+
const context: CollectorContext = {
|
|
31
|
+
input,
|
|
32
|
+
fs,
|
|
33
|
+
requirements,
|
|
34
|
+
entries() {
|
|
35
|
+
listing ??= fs.readDirectory(input.cwd);
|
|
36
|
+
return listing;
|
|
37
|
+
},
|
|
38
|
+
options(name) {
|
|
39
|
+
return input.config.modules[name].options;
|
|
40
|
+
},
|
|
41
|
+
needs(name, variable) {
|
|
42
|
+
const variables = requirements.get(name);
|
|
43
|
+
return Boolean(variables && (variable === undefined || variables.has(variable)));
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
const modules: MutableModuleSnapshot = {};
|
|
47
|
+
const packageValues = await collectPackage(context);
|
|
48
|
+
if (packageValues) modules.package = packageValues;
|
|
49
|
+
for (const collector of [
|
|
50
|
+
collectLanguages,
|
|
51
|
+
collectDevelopment,
|
|
52
|
+
collectDeployment,
|
|
53
|
+
collectCloud,
|
|
54
|
+
collectExecution,
|
|
55
|
+
]) {
|
|
56
|
+
mergeModules(modules, await collector(context));
|
|
57
|
+
}
|
|
58
|
+
return freezeSnapshot(modules);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function workspaceSnapshotEqual(
|
|
62
|
+
left: WorkspaceSnapshot | undefined,
|
|
63
|
+
right: WorkspaceSnapshot | undefined,
|
|
64
|
+
): boolean {
|
|
65
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function hasWorkspaceRequirement(
|
|
69
|
+
requirements: ReadonlyMap<ModuleName, ReadonlySet<string>>,
|
|
70
|
+
): boolean {
|
|
71
|
+
return [...requirements.keys()].some((name) => !BUILT_IN_ONLY_MODULES.has(name));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const BUILT_IN_ONLY_MODULES = new Set<ModuleName>([
|
|
75
|
+
"brand",
|
|
76
|
+
"provider",
|
|
77
|
+
"model",
|
|
78
|
+
"thinking",
|
|
79
|
+
"directory",
|
|
80
|
+
"git_worktree",
|
|
81
|
+
"git_branch",
|
|
82
|
+
"git_commit",
|
|
83
|
+
"git_state",
|
|
84
|
+
"git_metrics",
|
|
85
|
+
"git_status",
|
|
86
|
+
"activity",
|
|
87
|
+
"context",
|
|
88
|
+
"tokens",
|
|
89
|
+
"cost",
|
|
90
|
+
"time",
|
|
91
|
+
"turn",
|
|
92
|
+
"fill",
|
|
93
|
+
"extension_status",
|
|
94
|
+
]);
|
|
95
|
+
|
|
96
|
+
function mergeModules(target: MutableModuleSnapshot, source: MutableModuleSnapshot): void {
|
|
97
|
+
for (const [name, values] of Object.entries(source)) {
|
|
98
|
+
Object.defineProperty(target, name, {
|
|
99
|
+
value: values,
|
|
100
|
+
writable: true,
|
|
101
|
+
enumerable: true,
|
|
102
|
+
configurable: true,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function freezeSnapshot(modules: MutableModuleSnapshot): WorkspaceSnapshot {
|
|
108
|
+
for (const values of Object.values(modules)) Object.freeze(values);
|
|
109
|
+
return Object.freeze({ modules: Object.freeze(modules) });
|
|
110
|
+
}
|