@narumitw/pi-starship 0.55.0 → 0.55.2
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 +21 -36
- package/dist/chunks/{chunk-UX6PBXVK.js → chunk-JO5PH6FN.js} +28 -110
- package/dist/chunks/chunk-JO5PH6FN.js.map +7 -0
- package/dist/chunks/{chunk-P4XMFSQW.js → chunk-YWY5RIDQ.js} +3 -7
- package/dist/chunks/chunk-YWY5RIDQ.js.map +7 -0
- package/dist/chunks/{chunk-EOGXAMTA.js → chunk-ZQZSXXPI.js} +1 -1
- package/dist/chunks/chunk-ZQZSXXPI.js.map +7 -0
- package/dist/chunks/{cloud-BKHYWCTA.js → cloud-C4VU3TX3.js} +7 -14
- package/dist/chunks/cloud-C4VU3TX3.js.map +7 -0
- package/dist/chunks/{commands-53ZO2JUK.js → commands-ATILSUVK.js} +13 -42
- package/dist/chunks/commands-ATILSUVK.js.map +7 -0
- package/dist/chunks/{deployment-RKKOEQQ2.js → deployment-FMNTYRBW.js} +6 -21
- package/dist/chunks/deployment-FMNTYRBW.js.map +7 -0
- package/dist/chunks/{development-BERD42HW.js → development-OUYXDPBS.js} +4 -8
- package/dist/chunks/development-OUYXDPBS.js.map +7 -0
- package/dist/chunks/{execution-42JTEY3N.js → execution-HJOGLMWD.js} +3 -3
- package/dist/chunks/execution-HJOGLMWD.js.map +7 -0
- package/dist/chunks/{languages-RMP6DW7H.js → languages-WXMF4GOF.js} +6 -22
- package/dist/chunks/languages-WXMF4GOF.js.map +7 -0
- package/dist/chunks/{package-LG5H7BBM.js → package-YXRZQAOV.js} +5 -14
- package/dist/chunks/package-YXRZQAOV.js.map +7 -0
- package/dist/index.ts +38 -53
- package/dist/index.ts.map +2 -2
- package/package.json +60 -61
- package/skills/configuring-pi-starship/references/runtime-and-security.md +5 -1
- package/skills/configuring-pi-starship/scripts/apply.mjs +43 -47
- package/skills/configuring-pi-starship/scripts/config-path.mjs +3 -3
- package/skills/configuring-pi-starship/scripts/script-support.mjs +6 -6
- package/skills/configuring-pi-starship/scripts/validate.mjs +18 -18
- package/src/command-configuration.ts +267 -286
- package/src/command-contract.ts +6 -6
- package/src/command-inspector.ts +27 -27
- package/src/command-preset-picker.ts +45 -50
- package/src/command-preview.ts +153 -166
- package/src/commands.ts +588 -618
- package/src/config.ts +580 -660
- package/src/effective-config.ts +46 -48
- package/src/format/formatter.ts +211 -227
- package/src/format/style.ts +205 -216
- package/src/modules/activity.ts +74 -74
- package/src/modules/brand.ts +9 -9
- package/src/modules/cache.ts +18 -18
- package/src/modules/catalog.ts +79 -83
- package/src/modules/cloud.ts +54 -54
- package/src/modules/context.ts +27 -27
- package/src/modules/cost.ts +23 -23
- package/src/modules/deployment.ts +45 -45
- package/src/modules/development.ts +80 -81
- package/src/modules/directory.ts +89 -113
- package/src/modules/display.ts +9 -9
- package/src/modules/execution.ts +62 -69
- package/src/modules/extension-status.ts +59 -64
- package/src/modules/fill.ts +10 -10
- package/src/modules/git/branch.ts +26 -26
- package/src/modules/git/commit.ts +21 -23
- package/src/modules/git/metrics.ts +22 -22
- package/src/modules/git/runtime.ts +299 -334
- package/src/modules/git/state.ts +17 -17
- package/src/modules/git/status.ts +77 -79
- package/src/modules/git/worktree.ts +10 -12
- package/src/modules/github-pr.ts +20 -20
- package/src/modules/helpers.ts +3 -3
- package/src/modules/index.ts +21 -21
- package/src/modules/inspection.ts +101 -108
- package/src/modules/languages.ts +52 -59
- package/src/modules/model.ts +57 -67
- package/src/modules/package.ts +12 -12
- package/src/modules/provider.ts +22 -24
- package/src/modules/render.ts +124 -140
- package/src/modules/thinking.ts +27 -26
- package/src/modules/time.ts +10 -13
- package/src/modules/tokens.ts +13 -13
- package/src/modules/truncation.ts +14 -17
- package/src/modules/turn.ts +9 -9
- package/src/modules/types.ts +125 -132
- package/src/modules/workspace-helpers.ts +4 -7
- package/src/pi-starship.ts +567 -571
- package/src/presets/catalog.ts +113 -113
- package/src/runtime/cloud.ts +122 -150
- package/src/runtime/command.ts +106 -108
- package/src/runtime/deployment.ts +150 -179
- package/src/runtime/development.ts +107 -124
- package/src/runtime/execution.ts +110 -124
- package/src/runtime/github-pr.ts +223 -252
- package/src/runtime/helpers.ts +186 -199
- package/src/runtime/languages.ts +149 -180
- package/src/runtime/package.ts +74 -87
- package/src/runtime/refresh-controller.ts +82 -86
- package/src/runtime/types.ts +38 -38
- package/src/runtime/workspace.ts +108 -116
- package/src/usage.ts +40 -40
- package/dist/chunks/chunk-EOGXAMTA.js.map +0 -7
- package/dist/chunks/chunk-P4XMFSQW.js.map +0 -7
- package/dist/chunks/chunk-UX6PBXVK.js.map +0 -7
- package/dist/chunks/cloud-BKHYWCTA.js.map +0 -7
- package/dist/chunks/commands-53ZO2JUK.js.map +0 -7
- package/dist/chunks/deployment-RKKOEQQ2.js.map +0 -7
- package/dist/chunks/development-BERD42HW.js.map +0 -7
- package/dist/chunks/execution-42JTEY3N.js.map +0 -7
- package/dist/chunks/languages-RMP6DW7H.js.map +0 -7
- package/dist/chunks/package-LG5H7BBM.js.map +0 -7
|
@@ -1,107 +1,103 @@
|
|
|
1
1
|
export interface AsyncRefreshControllerOptions<Input, Snapshot> {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
read(input: Input, signal: AbortSignal): Promise<Snapshot>;
|
|
3
|
+
equal(left: Snapshot | undefined, right: Snapshot): boolean;
|
|
4
|
+
publish(snapshot: Snapshot): void;
|
|
5
|
+
onError?(error: unknown): void;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
interface RefreshRequest<Input> {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
generation: number;
|
|
10
|
+
requestId: number;
|
|
11
|
+
input: Input;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
interface ActiveRefresh<Input> {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
request: RefreshRequest<Input>;
|
|
16
|
+
controller: AbortController;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/** Coalesces refreshes to one active read plus the latest pending request. */
|
|
20
20
|
export class AsyncRefreshController<Input, Snapshot> {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
private generation: number | undefined;
|
|
22
|
+
private requestId = 0;
|
|
23
|
+
private active: ActiveRefresh<Input> | undefined;
|
|
24
|
+
private pending: RefreshRequest<Input> | undefined;
|
|
25
|
+
private current: Snapshot | undefined;
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
constructor(private readonly options: AsyncRefreshControllerOptions<Input, Snapshot>) {}
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
start(generation: number): void {
|
|
30
|
+
this.cancelActive("Refresh generation replaced");
|
|
31
|
+
this.generation = generation;
|
|
32
|
+
this.requestId += 1;
|
|
33
|
+
this.pending = undefined;
|
|
34
|
+
this.current = undefined;
|
|
35
|
+
}
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
clear(): void {
|
|
38
|
+
this.current = undefined;
|
|
39
|
+
}
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
request(input: Input): void {
|
|
42
|
+
if (this.generation === undefined) return;
|
|
43
|
+
const request = {
|
|
44
|
+
generation: this.generation,
|
|
45
|
+
requestId: ++this.requestId,
|
|
46
|
+
input,
|
|
47
|
+
};
|
|
48
|
+
if (this.active) {
|
|
49
|
+
this.pending = request;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
this.run(request);
|
|
53
|
+
}
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
stop(): void {
|
|
56
|
+
this.generation = undefined;
|
|
57
|
+
this.requestId += 1;
|
|
58
|
+
this.pending = undefined;
|
|
59
|
+
this.current = undefined;
|
|
60
|
+
this.cancelActive("Refresh controller stopped");
|
|
61
|
+
}
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
this.pending = undefined;
|
|
92
|
-
if (pending) this.run(pending);
|
|
93
|
-
});
|
|
94
|
-
}
|
|
63
|
+
private run(request: RefreshRequest<Input>): void {
|
|
64
|
+
if (!this.isCurrentTarget(request)) return;
|
|
65
|
+
const active: ActiveRefresh<Input> = {
|
|
66
|
+
request,
|
|
67
|
+
controller: new AbortController(),
|
|
68
|
+
};
|
|
69
|
+
this.active = active;
|
|
70
|
+
void this.options
|
|
71
|
+
.read(request.input, active.controller.signal)
|
|
72
|
+
.then((snapshot) => {
|
|
73
|
+
if (this.active !== active || !this.isCurrentRequest(request)) return;
|
|
74
|
+
if (this.options.equal(this.current, snapshot)) return;
|
|
75
|
+
this.current = snapshot;
|
|
76
|
+
this.options.publish(snapshot);
|
|
77
|
+
})
|
|
78
|
+
.catch((error: unknown) => {
|
|
79
|
+
if (this.active === active && this.isCurrentRequest(request) && !active.controller.signal.aborted) {
|
|
80
|
+
this.options.onError?.(error);
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
.finally(() => {
|
|
84
|
+
if (this.active !== active) return;
|
|
85
|
+
this.active = undefined;
|
|
86
|
+
const pending = this.pending;
|
|
87
|
+
this.pending = undefined;
|
|
88
|
+
if (pending) this.run(pending);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
95
91
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
92
|
+
private cancelActive(reason: string): void {
|
|
93
|
+
this.active?.controller.abort(new DOMException(reason, "AbortError"));
|
|
94
|
+
}
|
|
99
95
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
96
|
+
private isCurrentTarget(request: RefreshRequest<Input>): boolean {
|
|
97
|
+
return this.generation !== undefined && request.generation === this.generation;
|
|
98
|
+
}
|
|
103
99
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
100
|
+
private isCurrentRequest(request: RefreshRequest<Input>): boolean {
|
|
101
|
+
return this.isCurrentTarget(request) && request.requestId === this.requestId;
|
|
102
|
+
}
|
|
107
103
|
}
|
package/src/runtime/types.ts
CHANGED
|
@@ -3,59 +3,59 @@ import type { ModuleName } from "../modules/catalog.js";
|
|
|
3
3
|
import type { WorkspaceSnapshot } from "../modules/types.js";
|
|
4
4
|
|
|
5
5
|
export interface WorkspaceExecResult {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
stdout: string;
|
|
7
|
+
stderr: string;
|
|
8
|
+
code: number;
|
|
9
|
+
killed: boolean;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export type WorkspaceExec = (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
command: string,
|
|
14
|
+
args: string[],
|
|
15
|
+
options: {
|
|
16
|
+
cwd: string;
|
|
17
|
+
timeout: number;
|
|
18
|
+
maxOutputBytes: number;
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
environment: Readonly<Record<string, string | undefined>>;
|
|
21
|
+
},
|
|
22
22
|
) => Promise<WorkspaceExecResult>;
|
|
23
23
|
|
|
24
24
|
export interface WorkspaceEntry {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
name: string;
|
|
26
|
+
isFile: boolean;
|
|
27
|
+
isDirectory: boolean;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export interface WorkspaceFileSystem {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
readFile(path: string, maxBytes: number): Promise<string | undefined>;
|
|
32
|
+
readDirectory(path: string): Promise<readonly WorkspaceEntry[]>;
|
|
33
|
+
fileExists(path: string): Promise<boolean>;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export interface WorkspaceRefreshInput {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
37
|
+
cwd: string;
|
|
38
|
+
config: StarshipConfig;
|
|
39
|
+
environment: Readonly<Record<string, string | undefined>>;
|
|
40
|
+
homeDir: string;
|
|
41
|
+
platform: NodeJS.Platform;
|
|
42
|
+
hostname: string;
|
|
43
|
+
username: string;
|
|
44
|
+
exec: WorkspaceExec;
|
|
45
|
+
fileSystem?: Partial<WorkspaceFileSystem>;
|
|
46
|
+
fileExists?(path: string): Promise<boolean>;
|
|
47
|
+
reason?: "initial" | "event" | "periodic";
|
|
48
|
+
previous?: WorkspaceSnapshot;
|
|
49
|
+
signal?: AbortSignal;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
export interface CollectorContext {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
input: WorkspaceRefreshInput;
|
|
54
|
+
fs: WorkspaceFileSystem;
|
|
55
|
+
requirements: ReadonlyMap<ModuleName, ReadonlySet<string>>;
|
|
56
|
+
entries(): Promise<readonly WorkspaceEntry[]>;
|
|
57
|
+
options(name: ModuleName): Readonly<Record<string, unknown>>;
|
|
58
|
+
needs(name: ModuleName, variable?: string): boolean;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
export const PRIVATE_STYLE_SELECTOR = "__pi_style_selector";
|
package/src/runtime/workspace.ts
CHANGED
|
@@ -3,145 +3,137 @@ import { reachableModuleRequirements } from "../modules/render.js";
|
|
|
3
3
|
import type { WorkspaceSnapshot } from "../modules/types.js";
|
|
4
4
|
import { createFileSystem } from "./helpers.js";
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
type CollectorContext,
|
|
7
|
+
type MutableModuleSnapshot,
|
|
8
|
+
PRIVATE_STYLE_SELECTOR,
|
|
9
|
+
type WorkspaceEntry,
|
|
10
|
+
type WorkspaceRefreshInput,
|
|
11
11
|
} from "./types.js";
|
|
12
12
|
|
|
13
13
|
export type { WorkspaceExec, WorkspaceExecResult, WorkspaceRefreshInput } from "./types.js";
|
|
14
14
|
|
|
15
|
-
export async function collectWorkspaceSnapshot(
|
|
16
|
-
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
return input.signal?.aborted ? freezeSnapshot({}) : freezeSnapshot(modules);
|
|
15
|
+
export async function collectWorkspaceSnapshot(input: WorkspaceRefreshInput): Promise<WorkspaceSnapshot> {
|
|
16
|
+
const requirements = reachableModuleRequirements(input.config);
|
|
17
|
+
if (input.signal?.aborted || !hasWorkspaceRequirement(requirements)) return freezeSnapshot({});
|
|
18
|
+
const fs = createFileSystem(input);
|
|
19
|
+
let listing: Promise<readonly WorkspaceEntry[]> | undefined;
|
|
20
|
+
const context: CollectorContext = {
|
|
21
|
+
input,
|
|
22
|
+
fs,
|
|
23
|
+
requirements,
|
|
24
|
+
entries() {
|
|
25
|
+
listing ??= fs.readDirectory(input.cwd);
|
|
26
|
+
return listing;
|
|
27
|
+
},
|
|
28
|
+
options(name) {
|
|
29
|
+
return input.config.modules[name].options;
|
|
30
|
+
},
|
|
31
|
+
needs(name, variable) {
|
|
32
|
+
const variables = requirements.get(name);
|
|
33
|
+
return Boolean(variables && (variable === undefined || variables.has(variable)));
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
const modules: MutableModuleSnapshot = {};
|
|
37
|
+
if (requirements.has("package")) {
|
|
38
|
+
const { collectPackage } = await import("./package.js");
|
|
39
|
+
if (input.signal?.aborted) return freezeSnapshot({});
|
|
40
|
+
const packageValues = await collectPackage(context);
|
|
41
|
+
if (input.signal?.aborted) return freezeSnapshot({});
|
|
42
|
+
if (packageValues) modules.package = packageValues;
|
|
43
|
+
}
|
|
44
|
+
for (const descriptor of COLLECTOR_GROUPS) {
|
|
45
|
+
if (!descriptor.modules.some((name) => requirements.has(name))) continue;
|
|
46
|
+
if (input.signal?.aborted) return freezeSnapshot({});
|
|
47
|
+
const collector = await descriptor.load();
|
|
48
|
+
if (input.signal?.aborted) return freezeSnapshot({});
|
|
49
|
+
mergeModules(modules, await collector(context));
|
|
50
|
+
}
|
|
51
|
+
return input.signal?.aborted ? freezeSnapshot({}) : freezeSnapshot(modules);
|
|
54
52
|
}
|
|
55
53
|
|
|
56
54
|
export function workspaceSnapshotEqual(
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
left: WorkspaceSnapshot | undefined,
|
|
56
|
+
right: WorkspaceSnapshot | undefined,
|
|
59
57
|
): boolean {
|
|
60
|
-
|
|
58
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
61
59
|
}
|
|
62
60
|
|
|
63
|
-
function hasWorkspaceRequirement(
|
|
64
|
-
|
|
65
|
-
): boolean {
|
|
66
|
-
return [...requirements.keys()].some((name) => !BUILT_IN_ONLY_MODULES.has(name));
|
|
61
|
+
function hasWorkspaceRequirement(requirements: ReadonlyMap<ModuleName, ReadonlySet<string>>): boolean {
|
|
62
|
+
return [...requirements.keys()].some((name) => !BUILT_IN_ONLY_MODULES.has(name));
|
|
67
63
|
}
|
|
68
64
|
|
|
69
65
|
type WorkspaceCollector = (context: CollectorContext) => Promise<MutableModuleSnapshot>;
|
|
70
66
|
|
|
71
67
|
const COLLECTOR_GROUPS: readonly {
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
modules: readonly ModuleName[];
|
|
69
|
+
load(): Promise<WorkspaceCollector>;
|
|
74
70
|
}[] = [
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
71
|
+
{
|
|
72
|
+
modules: ["nodejs", "python", "rust", "golang", "bun", "deno"],
|
|
73
|
+
load: async () => (await import("./languages.js")).collectLanguages,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
modules: ["mise", "direnv", "pixi", "conda", "nix_shell", "guix_shell"],
|
|
77
|
+
load: async () => (await import("./development.js")).collectDevelopment,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
modules: ["docker_context", "kubernetes", "terraform"],
|
|
81
|
+
load: async () => (await import("./deployment.js")).collectDeployment,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
modules: ["aws", "gcloud", "azure", "openstack"],
|
|
85
|
+
load: async () => (await import("./cloud.js")).collectCloud,
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
modules: ["container", "hostname", "os", "username"],
|
|
89
|
+
load: async () => (await import("./execution.js")).collectExecution,
|
|
90
|
+
},
|
|
95
91
|
];
|
|
96
92
|
|
|
97
93
|
const BUILT_IN_ONLY_MODULES = new Set<ModuleName>([
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
94
|
+
"brand",
|
|
95
|
+
"provider",
|
|
96
|
+
"model",
|
|
97
|
+
"thinking",
|
|
98
|
+
"directory",
|
|
99
|
+
"git_worktree",
|
|
100
|
+
"git_branch",
|
|
101
|
+
"github_pr",
|
|
102
|
+
"git_commit",
|
|
103
|
+
"git_state",
|
|
104
|
+
"git_metrics",
|
|
105
|
+
"git_status",
|
|
106
|
+
"activity",
|
|
107
|
+
"context",
|
|
108
|
+
"tokens",
|
|
109
|
+
"cost",
|
|
110
|
+
"time",
|
|
111
|
+
"turn",
|
|
112
|
+
"fill",
|
|
113
|
+
"extension_status",
|
|
118
114
|
]);
|
|
119
115
|
|
|
120
116
|
function mergeModules(target: MutableModuleSnapshot, source: MutableModuleSnapshot): void {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
117
|
+
for (const [name, values] of Object.entries(source)) {
|
|
118
|
+
Object.defineProperty(target, name, {
|
|
119
|
+
value: values,
|
|
120
|
+
writable: true,
|
|
121
|
+
enumerable: true,
|
|
122
|
+
configurable: true,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
129
125
|
}
|
|
130
126
|
|
|
131
127
|
function freezeSnapshot(modules: MutableModuleSnapshot): WorkspaceSnapshot {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
...(Object.keys(styleSelectors).length > 0
|
|
144
|
-
? { styleSelectors: Object.freeze(styleSelectors) }
|
|
145
|
-
: {}),
|
|
146
|
-
});
|
|
128
|
+
const styleSelectors: Record<string, string> = {};
|
|
129
|
+
for (const [name, values] of Object.entries(modules)) {
|
|
130
|
+
const selector = Object.hasOwn(values, PRIVATE_STYLE_SELECTOR) ? values[PRIVATE_STYLE_SELECTOR] : undefined;
|
|
131
|
+
delete values[PRIVATE_STYLE_SELECTOR];
|
|
132
|
+
if (selector !== undefined) styleSelectors[name] = selector;
|
|
133
|
+
Object.freeze(values);
|
|
134
|
+
}
|
|
135
|
+
return Object.freeze({
|
|
136
|
+
modules: Object.freeze(modules),
|
|
137
|
+
...(Object.keys(styleSelectors).length > 0 ? { styleSelectors: Object.freeze(styleSelectors) } : {}),
|
|
138
|
+
});
|
|
147
139
|
}
|
package/src/usage.ts
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
1
|
import type { SessionEntry } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
|
|
3
3
|
interface UsageLike {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
input?: number;
|
|
5
|
+
output?: number;
|
|
6
|
+
cacheRead?: number;
|
|
7
|
+
cacheWrite?: number;
|
|
8
|
+
cost?: { total?: number };
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export interface FooterUsageSummary {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
input: number;
|
|
13
|
+
output: number;
|
|
14
|
+
cacheRead: number;
|
|
15
|
+
cacheWrite: number;
|
|
16
|
+
cost: number;
|
|
17
|
+
latestCacheHitRate?: number;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export function summarizeFooterUsage(entries: readonly SessionEntry[]): FooterUsageSummary {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
const totals: FooterUsageSummary = {
|
|
22
|
+
input: 0,
|
|
23
|
+
output: 0,
|
|
24
|
+
cacheRead: 0,
|
|
25
|
+
cacheWrite: 0,
|
|
26
|
+
cost: 0,
|
|
27
|
+
};
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
29
|
+
for (const entry of entries) {
|
|
30
|
+
let usage: UsageLike | undefined;
|
|
31
|
+
if (entry.type === "message" && entry.message.role === "assistant") {
|
|
32
|
+
usage = entry.message.usage;
|
|
33
|
+
const input = usage.input ?? 0;
|
|
34
|
+
const cacheRead = usage.cacheRead ?? 0;
|
|
35
|
+
const cacheWrite = usage.cacheWrite ?? 0;
|
|
36
|
+
const promptTokens = input + cacheRead + cacheWrite;
|
|
37
|
+
totals.latestCacheHitRate = promptTokens > 0 ? (cacheRead / promptTokens) * 100 : undefined;
|
|
38
|
+
} else if (entry.type === "message" && entry.message.role === "toolResult") {
|
|
39
|
+
usage = entry.message.usage;
|
|
40
|
+
} else if (entry.type === "compaction" || entry.type === "branch_summary") {
|
|
41
|
+
usage = entry.usage;
|
|
42
|
+
}
|
|
43
|
+
if (!usage) continue;
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
totals.input += usage.input ?? 0;
|
|
46
|
+
totals.output += usage.output ?? 0;
|
|
47
|
+
totals.cacheRead += usage.cacheRead ?? 0;
|
|
48
|
+
totals.cacheWrite += usage.cacheWrite ?? 0;
|
|
49
|
+
totals.cost += usage.cost?.total ?? 0;
|
|
50
|
+
}
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
return totals;
|
|
53
53
|
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/runtime/types.ts"],
|
|
4
|
-
"sourcesContent": ["import type { StarshipConfig } from \"../config.js\";\nimport type { ModuleName } from \"../modules/catalog.js\";\nimport type { WorkspaceSnapshot } from \"../modules/types.js\";\n\nexport interface WorkspaceExecResult {\n\tstdout: string;\n\tstderr: string;\n\tcode: number;\n\tkilled: boolean;\n}\n\nexport type WorkspaceExec = (\n\tcommand: string,\n\targs: string[],\n\toptions: {\n\t\tcwd: string;\n\t\ttimeout: number;\n\t\tmaxOutputBytes: number;\n\t\tsignal?: AbortSignal;\n\t\tenvironment: Readonly<Record<string, string | undefined>>;\n\t},\n) => Promise<WorkspaceExecResult>;\n\nexport interface WorkspaceEntry {\n\tname: string;\n\tisFile: boolean;\n\tisDirectory: boolean;\n}\n\nexport interface WorkspaceFileSystem {\n\treadFile(path: string, maxBytes: number): Promise<string | undefined>;\n\treadDirectory(path: string): Promise<readonly WorkspaceEntry[]>;\n\tfileExists(path: string): Promise<boolean>;\n}\n\nexport interface WorkspaceRefreshInput {\n\tcwd: string;\n\tconfig: StarshipConfig;\n\tenvironment: Readonly<Record<string, string | undefined>>;\n\thomeDir: string;\n\tplatform: NodeJS.Platform;\n\thostname: string;\n\tusername: string;\n\texec: WorkspaceExec;\n\tfileSystem?: Partial<WorkspaceFileSystem>;\n\tfileExists?(path: string): Promise<boolean>;\n\treason?: \"initial\" | \"event\" | \"periodic\";\n\tprevious?: WorkspaceSnapshot;\n\tsignal?: AbortSignal;\n}\n\nexport interface CollectorContext {\n\tinput: WorkspaceRefreshInput;\n\tfs: WorkspaceFileSystem;\n\trequirements: ReadonlyMap<ModuleName, ReadonlySet<string>>;\n\tentries(): Promise<readonly WorkspaceEntry[]>;\n\toptions(name: ModuleName): Readonly<Record<string, unknown>>;\n\tneeds(name: ModuleName, variable?: string): boolean;\n}\n\nexport const PRIVATE_STYLE_SELECTOR = \"__pi_style_selector\";\n\nexport type MutableModuleSnapshot = Record<string, Record<string, string>>;\n"],
|
|
5
|
-
"mappings": ";;;;AA4DO,IAAM,yBAAyB;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|