@narumitw/pi-starship 0.55.1 → 0.56.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.
Files changed (106) hide show
  1. package/README.md +2 -0
  2. package/dist/chunks/{chunk-UX6PBXVK.js → chunk-SD7TUSSU.js} +113 -113
  3. package/dist/chunks/chunk-SD7TUSSU.js.map +7 -0
  4. package/dist/chunks/{chunk-P4XMFSQW.js → chunk-YWY5RIDQ.js} +3 -7
  5. package/dist/chunks/chunk-YWY5RIDQ.js.map +7 -0
  6. package/dist/chunks/{chunk-EOGXAMTA.js → chunk-ZQZSXXPI.js} +1 -1
  7. package/dist/chunks/chunk-ZQZSXXPI.js.map +7 -0
  8. package/dist/chunks/{cloud-BKHYWCTA.js → cloud-C4VU3TX3.js} +7 -14
  9. package/dist/chunks/cloud-C4VU3TX3.js.map +7 -0
  10. package/dist/chunks/{commands-53ZO2JUK.js → commands-MJCAK6JL.js} +18 -42
  11. package/dist/chunks/commands-MJCAK6JL.js.map +7 -0
  12. package/dist/chunks/{deployment-RKKOEQQ2.js → deployment-FMNTYRBW.js} +6 -21
  13. package/dist/chunks/deployment-FMNTYRBW.js.map +7 -0
  14. package/dist/chunks/{development-BERD42HW.js → development-OUYXDPBS.js} +4 -8
  15. package/dist/chunks/development-OUYXDPBS.js.map +7 -0
  16. package/dist/chunks/{execution-42JTEY3N.js → execution-HJOGLMWD.js} +3 -3
  17. package/dist/chunks/execution-HJOGLMWD.js.map +7 -0
  18. package/dist/chunks/{languages-RMP6DW7H.js → languages-WXMF4GOF.js} +6 -22
  19. package/dist/chunks/languages-WXMF4GOF.js.map +7 -0
  20. package/dist/chunks/{package-LG5H7BBM.js → package-YXRZQAOV.js} +5 -14
  21. package/dist/chunks/package-YXRZQAOV.js.map +7 -0
  22. package/dist/index.ts +20 -55
  23. package/dist/index.ts.map +2 -2
  24. package/package.json +60 -61
  25. package/skills/configuring-pi-starship/SKILL.md +18 -4
  26. package/skills/configuring-pi-starship/references/configuration.md +70 -2
  27. package/skills/configuring-pi-starship/references/module-catalog.md +21 -0
  28. package/skills/configuring-pi-starship/references/modules.md +2 -0
  29. package/skills/configuring-pi-starship/scripts/apply.mjs +48 -47
  30. package/skills/configuring-pi-starship/scripts/backup.mjs +118 -0
  31. package/skills/configuring-pi-starship/scripts/config-path.mjs +3 -3
  32. package/skills/configuring-pi-starship/scripts/script-support.mjs +6 -6
  33. package/skills/configuring-pi-starship/scripts/validate.mjs +18 -18
  34. package/src/command-configuration.ts +267 -286
  35. package/src/command-contract.ts +6 -6
  36. package/src/command-inspector.ts +27 -27
  37. package/src/command-preset-picker.ts +45 -50
  38. package/src/command-preview.ts +153 -166
  39. package/src/commands.ts +590 -618
  40. package/src/config.ts +635 -660
  41. package/src/effective-config.ts +49 -48
  42. package/src/format/formatter.ts +211 -227
  43. package/src/format/style.ts +205 -216
  44. package/src/modules/activity.ts +74 -74
  45. package/src/modules/brand.ts +9 -9
  46. package/src/modules/cache.ts +18 -18
  47. package/src/modules/catalog.ts +79 -83
  48. package/src/modules/cloud.ts +54 -54
  49. package/src/modules/context.ts +27 -27
  50. package/src/modules/cost.ts +23 -23
  51. package/src/modules/deployment.ts +45 -45
  52. package/src/modules/development.ts +80 -81
  53. package/src/modules/directory.ts +89 -113
  54. package/src/modules/display.ts +9 -9
  55. package/src/modules/execution.ts +62 -69
  56. package/src/modules/extension-status.ts +59 -64
  57. package/src/modules/fill.ts +10 -10
  58. package/src/modules/git/branch.ts +26 -26
  59. package/src/modules/git/commit.ts +21 -23
  60. package/src/modules/git/metrics.ts +22 -22
  61. package/src/modules/git/runtime.ts +299 -334
  62. package/src/modules/git/state.ts +17 -17
  63. package/src/modules/git/status.ts +77 -79
  64. package/src/modules/git/worktree.ts +10 -12
  65. package/src/modules/github-pr.ts +20 -20
  66. package/src/modules/helpers.ts +3 -3
  67. package/src/modules/index.ts +21 -21
  68. package/src/modules/inspection.ts +105 -108
  69. package/src/modules/languages.ts +52 -59
  70. package/src/modules/model.ts +61 -67
  71. package/src/modules/package.ts +12 -12
  72. package/src/modules/provider.ts +25 -24
  73. package/src/modules/render.ts +131 -141
  74. package/src/modules/style-rules.ts +21 -0
  75. package/src/modules/thinking.ts +31 -26
  76. package/src/modules/time.ts +10 -13
  77. package/src/modules/tokens.ts +13 -13
  78. package/src/modules/truncation.ts +14 -17
  79. package/src/modules/turn.ts +9 -9
  80. package/src/modules/types.ts +133 -132
  81. package/src/modules/workspace-helpers.ts +4 -7
  82. package/src/pi-starship.ts +567 -603
  83. package/src/presets/catalog.ts +113 -113
  84. package/src/runtime/cloud.ts +122 -150
  85. package/src/runtime/command.ts +106 -108
  86. package/src/runtime/deployment.ts +150 -179
  87. package/src/runtime/development.ts +107 -124
  88. package/src/runtime/execution.ts +110 -124
  89. package/src/runtime/github-pr.ts +223 -252
  90. package/src/runtime/helpers.ts +186 -199
  91. package/src/runtime/languages.ts +149 -180
  92. package/src/runtime/package.ts +74 -87
  93. package/src/runtime/refresh-controller.ts +82 -86
  94. package/src/runtime/types.ts +38 -38
  95. package/src/runtime/workspace.ts +108 -116
  96. package/src/usage.ts +40 -40
  97. package/dist/chunks/chunk-EOGXAMTA.js.map +0 -7
  98. package/dist/chunks/chunk-P4XMFSQW.js.map +0 -7
  99. package/dist/chunks/chunk-UX6PBXVK.js.map +0 -7
  100. package/dist/chunks/cloud-BKHYWCTA.js.map +0 -7
  101. package/dist/chunks/commands-53ZO2JUK.js.map +0 -7
  102. package/dist/chunks/deployment-RKKOEQQ2.js.map +0 -7
  103. package/dist/chunks/development-BERD42HW.js.map +0 -7
  104. package/dist/chunks/execution-42JTEY3N.js.map +0 -7
  105. package/dist/chunks/languages-RMP6DW7H.js.map +0 -7
  106. package/dist/chunks/package-LG5H7BBM.js.map +0 -7
@@ -1,107 +1,103 @@
1
1
  export interface AsyncRefreshControllerOptions<Input, Snapshot> {
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;
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
- generation: number;
10
- requestId: number;
11
- input: Input;
9
+ generation: number;
10
+ requestId: number;
11
+ input: Input;
12
12
  }
13
13
 
14
14
  interface ActiveRefresh<Input> {
15
- request: RefreshRequest<Input>;
16
- controller: AbortController;
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
- 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;
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
- constructor(private readonly options: AsyncRefreshControllerOptions<Input, Snapshot>) {}
27
+ constructor(private readonly options: AsyncRefreshControllerOptions<Input, Snapshot>) {}
28
28
 
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
- }
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
- clear(): void {
38
- this.current = undefined;
39
- }
37
+ clear(): void {
38
+ this.current = undefined;
39
+ }
40
40
 
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
- }
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
- 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
- }
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
- 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 (
80
- this.active === active &&
81
- this.isCurrentRequest(request) &&
82
- !active.controller.signal.aborted
83
- ) {
84
- this.options.onError?.(error);
85
- }
86
- })
87
- .finally(() => {
88
- if (this.active !== active) return;
89
- this.active = undefined;
90
- const pending = this.pending;
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
- private cancelActive(reason: string): void {
97
- this.active?.controller.abort(new DOMException(reason, "AbortError"));
98
- }
92
+ private cancelActive(reason: string): void {
93
+ this.active?.controller.abort(new DOMException(reason, "AbortError"));
94
+ }
99
95
 
100
- private isCurrentTarget(request: RefreshRequest<Input>): boolean {
101
- return this.generation !== undefined && request.generation === this.generation;
102
- }
96
+ private isCurrentTarget(request: RefreshRequest<Input>): boolean {
97
+ return this.generation !== undefined && request.generation === this.generation;
98
+ }
103
99
 
104
- private isCurrentRequest(request: RefreshRequest<Input>): boolean {
105
- return this.isCurrentTarget(request) && request.requestId === this.requestId;
106
- }
100
+ private isCurrentRequest(request: RefreshRequest<Input>): boolean {
101
+ return this.isCurrentTarget(request) && request.requestId === this.requestId;
102
+ }
107
103
  }
@@ -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
- stdout: string;
7
- stderr: string;
8
- code: number;
9
- killed: boolean;
6
+ stdout: string;
7
+ stderr: string;
8
+ code: number;
9
+ killed: boolean;
10
10
  }
11
11
 
12
12
  export type WorkspaceExec = (
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
- },
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
- name: string;
26
- isFile: boolean;
27
- isDirectory: boolean;
25
+ name: string;
26
+ isFile: boolean;
27
+ isDirectory: boolean;
28
28
  }
29
29
 
30
30
  export interface WorkspaceFileSystem {
31
- readFile(path: string, maxBytes: number): Promise<string | undefined>;
32
- readDirectory(path: string): Promise<readonly WorkspaceEntry[]>;
33
- fileExists(path: string): Promise<boolean>;
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
- 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;
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
- 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;
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";
@@ -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
- type CollectorContext,
7
- type MutableModuleSnapshot,
8
- PRIVATE_STYLE_SELECTOR,
9
- type WorkspaceEntry,
10
- type WorkspaceRefreshInput,
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
- input: WorkspaceRefreshInput,
17
- ): Promise<WorkspaceSnapshot> {
18
- const requirements = reachableModuleRequirements(input.config);
19
- if (input.signal?.aborted || !hasWorkspaceRequirement(requirements)) return freezeSnapshot({});
20
- const fs = createFileSystem(input);
21
- let listing: Promise<readonly WorkspaceEntry[]> | undefined;
22
- const context: CollectorContext = {
23
- input,
24
- fs,
25
- requirements,
26
- entries() {
27
- listing ??= fs.readDirectory(input.cwd);
28
- return listing;
29
- },
30
- options(name) {
31
- return input.config.modules[name].options;
32
- },
33
- needs(name, variable) {
34
- const variables = requirements.get(name);
35
- return Boolean(variables && (variable === undefined || variables.has(variable)));
36
- },
37
- };
38
- const modules: MutableModuleSnapshot = {};
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();
50
- if (input.signal?.aborted) return freezeSnapshot({});
51
- mergeModules(modules, await collector(context));
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
- left: WorkspaceSnapshot | undefined,
58
- right: WorkspaceSnapshot | undefined,
55
+ left: WorkspaceSnapshot | undefined,
56
+ right: WorkspaceSnapshot | undefined,
59
57
  ): boolean {
60
- return JSON.stringify(left) === JSON.stringify(right);
58
+ return JSON.stringify(left) === JSON.stringify(right);
61
59
  }
62
60
 
63
- function hasWorkspaceRequirement(
64
- requirements: ReadonlyMap<ModuleName, ReadonlySet<string>>,
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
- modules: readonly ModuleName[];
73
- load(): Promise<WorkspaceCollector>;
68
+ modules: readonly ModuleName[];
69
+ load(): Promise<WorkspaceCollector>;
74
70
  }[] = [
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
- },
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
- "brand",
99
- "provider",
100
- "model",
101
- "thinking",
102
- "directory",
103
- "git_worktree",
104
- "git_branch",
105
- "github_pr",
106
- "git_commit",
107
- "git_state",
108
- "git_metrics",
109
- "git_status",
110
- "activity",
111
- "context",
112
- "tokens",
113
- "cost",
114
- "time",
115
- "turn",
116
- "fill",
117
- "extension_status",
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
- for (const [name, values] of Object.entries(source)) {
122
- Object.defineProperty(target, name, {
123
- value: values,
124
- writable: true,
125
- enumerable: true,
126
- configurable: true,
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
- const styleSelectors: Record<string, string> = {};
133
- for (const [name, values] of Object.entries(modules)) {
134
- const selector = Object.hasOwn(values, PRIVATE_STYLE_SELECTOR)
135
- ? values[PRIVATE_STYLE_SELECTOR]
136
- : undefined;
137
- delete values[PRIVATE_STYLE_SELECTOR];
138
- if (selector !== undefined) styleSelectors[name] = selector;
139
- Object.freeze(values);
140
- }
141
- return Object.freeze({
142
- modules: Object.freeze(modules),
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
- input?: number;
5
- output?: number;
6
- cacheRead?: number;
7
- cacheWrite?: number;
8
- cost?: { total?: number };
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
- input: number;
13
- output: number;
14
- cacheRead: number;
15
- cacheWrite: number;
16
- cost: number;
17
- latestCacheHitRate?: number;
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
- const totals: FooterUsageSummary = {
22
- input: 0,
23
- output: 0,
24
- cacheRead: 0,
25
- cacheWrite: 0,
26
- cost: 0,
27
- };
21
+ const totals: FooterUsageSummary = {
22
+ input: 0,
23
+ output: 0,
24
+ cacheRead: 0,
25
+ cacheWrite: 0,
26
+ cost: 0,
27
+ };
28
28
 
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;
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
- 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
- }
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
- return totals;
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
- }