@narumitw/pi-starship 0.43.0 → 0.45.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 +274 -89
- package/package.json +2 -2
- package/src/command-inspector.ts +470 -0
- package/src/command-preview.ts +206 -0
- package/src/commands.ts +187 -152
- package/src/config.ts +177 -67
- package/src/format/style.ts +64 -45
- package/src/modules/activity.ts +1 -1
- package/src/modules/brand.ts +1 -1
- package/src/modules/cache.ts +1 -1
- package/src/modules/catalog.ts +65 -4
- package/src/modules/context.ts +13 -1
- package/src/modules/cost.ts +12 -1
- package/src/modules/development.ts +1 -1
- package/src/modules/directory.ts +1 -1
- package/src/modules/display.ts +14 -0
- package/src/modules/execution.ts +12 -1
- package/src/modules/extension-status.ts +7 -98
- package/src/modules/fill.ts +1 -1
- package/src/modules/git/branch.ts +3 -37
- package/src/modules/git/commit.ts +1 -1
- package/src/modules/git/metrics.ts +8 -2
- package/src/modules/git/runtime.ts +5 -2
- package/src/modules/git/state.ts +1 -1
- package/src/modules/git/status.ts +1 -1
- package/src/modules/git/worktree.ts +1 -1
- package/src/modules/github-pr.ts +24 -0
- package/src/modules/index.ts +15 -6
- package/src/modules/inspection.ts +138 -0
- package/src/modules/model.ts +1 -1
- package/src/modules/provider.ts +1 -1
- package/src/modules/render.ts +23 -19
- package/src/modules/thinking.ts +1 -1
- package/src/modules/time.ts +1 -1
- package/src/modules/tokens.ts +1 -1
- package/src/modules/turn.ts +1 -1
- package/src/modules/types.ts +32 -5
- package/src/pi-starship.ts +149 -27
- package/src/runtime/command.ts +46 -8
- package/src/runtime/execution.ts +15 -3
- package/src/runtime/github-pr.ts +332 -0
- package/src/runtime/helpers.ts +1 -0
- package/src/runtime/refresh-controller.ts +30 -8
- package/src/runtime/types.ts +4 -0
- package/src/runtime/workspace.ts +27 -10
- package/src/installed-packages.ts +0 -84
package/src/modules/render.ts
CHANGED
|
@@ -22,28 +22,34 @@ export function renderStatusline(
|
|
|
22
22
|
modules[name] = [];
|
|
23
23
|
layoutModules[name] = [];
|
|
24
24
|
}
|
|
25
|
-
const consumedExtensionStatusKeys = new Set<string>();
|
|
26
|
-
|
|
27
25
|
for (const definition of MODULE_DEFINITIONS) {
|
|
28
26
|
const name = definition.name;
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
);
|
|
27
|
+
const module = config.modules[name];
|
|
28
|
+
const values = definition.values(valueContext(config, name, runtime));
|
|
32
29
|
if (!values) continue;
|
|
33
|
-
const
|
|
30
|
+
const styleVariables = definition.resolveStyleVariables
|
|
31
|
+
? definition.resolveStyleVariables({
|
|
32
|
+
runtime,
|
|
33
|
+
values,
|
|
34
|
+
style: module.style,
|
|
35
|
+
styles: module.styles,
|
|
36
|
+
display: module.display,
|
|
37
|
+
})
|
|
38
|
+
: { style: module.style };
|
|
39
|
+
if (!styleVariables) continue;
|
|
40
|
+
const contentValues = Object.fromEntries(
|
|
41
|
+
definition.variables.flatMap((variable) =>
|
|
42
|
+
variable !== "symbol" && Object.hasOwn(values, variable)
|
|
43
|
+
? [[variable, values[variable]]]
|
|
44
|
+
: [],
|
|
45
|
+
),
|
|
46
|
+
);
|
|
47
|
+
const rendered = renderModule(module, contentValues, styleVariables, palette);
|
|
34
48
|
modules[name] = rendered;
|
|
35
49
|
layoutModules[name] =
|
|
36
|
-
definition.layout === "fill" && !
|
|
50
|
+
definition.layout === "fill" && !module.disabled
|
|
37
51
|
? [{ type: "fill", pattern: rendered }]
|
|
38
52
|
: rendered;
|
|
39
|
-
if (
|
|
40
|
-
name === "git_branch" &&
|
|
41
|
-
values.pr &&
|
|
42
|
-
formatVariables(config.modules.git_branch.formatAst).has("pr") &&
|
|
43
|
-
rendered.some((chunk) => chunk.text.includes(values.pr ?? ""))
|
|
44
|
-
) {
|
|
45
|
-
consumedExtensionStatusKeys.add("github-pr");
|
|
46
|
-
}
|
|
47
53
|
}
|
|
48
54
|
|
|
49
55
|
const explicitModules = formatVariables(config.formatAst);
|
|
@@ -58,7 +64,6 @@ export function renderStatusline(
|
|
|
58
64
|
ansi: renderChunksToAnsi(chunks),
|
|
59
65
|
chunks,
|
|
60
66
|
modules,
|
|
61
|
-
consumedExtensionStatusKeys,
|
|
62
67
|
};
|
|
63
68
|
}
|
|
64
69
|
|
|
@@ -66,26 +71,25 @@ function valueContext(
|
|
|
66
71
|
config: StarshipConfig,
|
|
67
72
|
name: ModuleName,
|
|
68
73
|
runtime: StarshipRuntimeSnapshot,
|
|
69
|
-
hiddenExtensionStatusKeys: ReadonlySet<string>,
|
|
70
74
|
): ModuleValueContext {
|
|
71
75
|
return {
|
|
72
76
|
runtime,
|
|
73
77
|
symbol: config.modules[name].symbol,
|
|
74
78
|
options: config.modules[name].options,
|
|
75
79
|
extensionStatus: config.extensionStatus,
|
|
76
|
-
hiddenExtensionStatusKeys,
|
|
77
80
|
};
|
|
78
81
|
}
|
|
79
82
|
|
|
80
83
|
function renderModule(
|
|
81
84
|
module: ModuleConfig,
|
|
82
85
|
values: Readonly<Record<string, FormatValue>>,
|
|
86
|
+
styleVariables: Readonly<Record<string, string>>,
|
|
83
87
|
palette: Readonly<Record<string, string>>,
|
|
84
88
|
): StyledChunk[] {
|
|
85
89
|
if (module.disabled) return [];
|
|
86
90
|
return renderFormat(module.formatAst, {
|
|
87
91
|
variables: { symbol: module.symbol, ...values },
|
|
88
|
-
styleVariables
|
|
92
|
+
styleVariables,
|
|
89
93
|
palette,
|
|
90
94
|
}).filter((chunk): chunk is StyledChunk => !isFillChunk(chunk));
|
|
91
95
|
}
|
package/src/modules/thinking.ts
CHANGED
package/src/modules/time.ts
CHANGED
package/src/modules/tokens.ts
CHANGED
package/src/modules/turn.ts
CHANGED
package/src/modules/types.ts
CHANGED
|
@@ -50,6 +50,18 @@ export interface GitWorktreeSnapshot {
|
|
|
50
50
|
path: string;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
export type GithubPrState = "open" | "draft" | "merged" | "closed";
|
|
54
|
+
|
|
55
|
+
export interface GithubPrSnapshot {
|
|
56
|
+
readonly number: string;
|
|
57
|
+
readonly link: string;
|
|
58
|
+
readonly state: GithubPrState;
|
|
59
|
+
readonly checks: string;
|
|
60
|
+
readonly review: string;
|
|
61
|
+
readonly status: string;
|
|
62
|
+
readonly expiresAt?: number;
|
|
63
|
+
}
|
|
64
|
+
|
|
53
65
|
export interface GitSnapshot {
|
|
54
66
|
branch?: GitBranchSnapshot;
|
|
55
67
|
commit?: GitCommitSnapshot;
|
|
@@ -59,10 +71,9 @@ export interface GitSnapshot {
|
|
|
59
71
|
worktree?: GitWorktreeSnapshot;
|
|
60
72
|
}
|
|
61
73
|
|
|
62
|
-
export type ExtensionStatusIconAliasMap = ReadonlyMap<string, readonly string[]>;
|
|
63
|
-
|
|
64
74
|
export interface WorkspaceSnapshot {
|
|
65
75
|
modules: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
76
|
+
styleSelectors?: Readonly<Record<string, string>>;
|
|
66
77
|
}
|
|
67
78
|
|
|
68
79
|
export interface StarshipRuntimeSnapshot {
|
|
@@ -94,8 +105,8 @@ export interface StarshipRuntimeSnapshot {
|
|
|
94
105
|
gitMetrics?: GitMetricsSnapshot;
|
|
95
106
|
gitStatus?: GitStatusSnapshot;
|
|
96
107
|
gitWorktree?: GitWorktreeSnapshot;
|
|
108
|
+
githubPr?: GithubPrSnapshot;
|
|
97
109
|
extensionStatuses: ReadonlyMap<string, string>;
|
|
98
|
-
extensionStatusIconAliases: ExtensionStatusIconAliasMap;
|
|
99
110
|
now: Date;
|
|
100
111
|
workspace?: WorkspaceSnapshot;
|
|
101
112
|
}
|
|
@@ -118,7 +129,6 @@ export interface ModuleValueContext {
|
|
|
118
129
|
symbol: string;
|
|
119
130
|
options: Readonly<Record<string, ModuleOptionValue>>;
|
|
120
131
|
extensionStatus: ExtensionStatusPresentation;
|
|
121
|
-
hiddenExtensionStatusKeys: ReadonlySet<string>;
|
|
122
132
|
}
|
|
123
133
|
|
|
124
134
|
export type ModuleOptionSchema =
|
|
@@ -129,6 +139,12 @@ export type ModuleOptionSchema =
|
|
|
129
139
|
| { kind: "string-array"; default: readonly string[]; allowNegative?: boolean }
|
|
130
140
|
| { kind: "string-map"; default: Readonly<Record<string, string>> };
|
|
131
141
|
|
|
142
|
+
export interface ModuleDisplayConfig {
|
|
143
|
+
threshold: number;
|
|
144
|
+
style: string;
|
|
145
|
+
hidden: boolean;
|
|
146
|
+
}
|
|
147
|
+
|
|
132
148
|
export interface ModuleDefaults {
|
|
133
149
|
format: string;
|
|
134
150
|
symbol: string;
|
|
@@ -136,10 +152,22 @@ export interface ModuleDefaults {
|
|
|
136
152
|
disabled: boolean;
|
|
137
153
|
}
|
|
138
154
|
|
|
155
|
+
export interface ModuleStyleContext {
|
|
156
|
+
runtime: StarshipRuntimeSnapshot;
|
|
157
|
+
values: Readonly<Record<string, string>>;
|
|
158
|
+
style: string;
|
|
159
|
+
styles: Readonly<Record<string, string>>;
|
|
160
|
+
display: readonly ModuleDisplayConfig[];
|
|
161
|
+
}
|
|
162
|
+
|
|
139
163
|
export interface ModuleDefinition<Name extends string> {
|
|
140
164
|
name: Name;
|
|
141
165
|
variables: readonly string[];
|
|
142
166
|
defaults: ModuleDefaults;
|
|
167
|
+
styleDefaults?: Readonly<Record<string, string>>;
|
|
168
|
+
displayDefaults?: readonly ModuleDisplayConfig[];
|
|
169
|
+
styleVariables?: readonly string[];
|
|
170
|
+
resolveStyleVariables?(context: ModuleStyleContext): Readonly<Record<string, string>> | undefined;
|
|
143
171
|
options?: Readonly<Record<string, ModuleOptionSchema>>;
|
|
144
172
|
layout?: "fill";
|
|
145
173
|
values(context: ModuleValueContext): Record<string, string> | undefined;
|
|
@@ -155,5 +183,4 @@ export interface RenderedStatusline<Name extends string = string> {
|
|
|
155
183
|
ansi: string;
|
|
156
184
|
chunks: StyledChunk[];
|
|
157
185
|
modules: Record<Name, StyledChunk[]>;
|
|
158
|
-
consumedExtensionStatusKeys: ReadonlySet<string>;
|
|
159
186
|
}
|
package/src/pi-starship.ts
CHANGED
|
@@ -13,28 +13,32 @@ import {
|
|
|
13
13
|
type StarshipConfig,
|
|
14
14
|
settingsFilePath,
|
|
15
15
|
} from "./config.js";
|
|
16
|
-
import { readInstalledPackageInfo } from "./installed-packages.js";
|
|
17
16
|
import { gitSnapshotEqual, readGitSnapshot } from "./modules/git/runtime.js";
|
|
18
17
|
import {
|
|
19
|
-
type
|
|
18
|
+
type GithubPrSnapshot,
|
|
20
19
|
type GitSnapshot,
|
|
20
|
+
inspectStatuslineModules,
|
|
21
21
|
reachableModuleRequirements,
|
|
22
22
|
renderStatusline,
|
|
23
23
|
type StarshipRuntimeSnapshot,
|
|
24
|
+
type StatuslineInspection,
|
|
24
25
|
type WorkspaceSnapshot,
|
|
25
26
|
} from "./modules/index.js";
|
|
26
27
|
import { execWorkspaceCommand } from "./runtime/command.js";
|
|
28
|
+
import { githubPrSnapshotEqual, queryGithubPr } from "./runtime/github-pr.js";
|
|
27
29
|
import { AsyncRefreshController } from "./runtime/refresh-controller.js";
|
|
28
30
|
import {
|
|
29
31
|
collectWorkspaceSnapshot,
|
|
32
|
+
type WorkspaceExec,
|
|
30
33
|
type WorkspaceRefreshInput,
|
|
31
34
|
workspaceSnapshotEqual,
|
|
32
35
|
} from "./runtime/workspace.js";
|
|
33
36
|
import { summarizeFooterUsage } from "./usage.js";
|
|
34
37
|
|
|
35
38
|
const REFRESH_INTERVAL_MS = 30_000;
|
|
39
|
+
const GITHUB_PR_REFRESH_INTERVAL_MS = 60_000;
|
|
36
40
|
const EVENT_DEBOUNCE_MS = 250;
|
|
37
|
-
const
|
|
41
|
+
const MAX_TIMER_DELAY_MS = 2_147_483_647;
|
|
38
42
|
|
|
39
43
|
interface RuntimeState {
|
|
40
44
|
activeTools: Map<string, number>;
|
|
@@ -42,15 +46,18 @@ interface RuntimeState {
|
|
|
42
46
|
thinkingLevel: string;
|
|
43
47
|
lastCompletedTool?: string;
|
|
44
48
|
git?: GitSnapshot;
|
|
49
|
+
githubPr?: GithubPrSnapshot;
|
|
45
50
|
workspace?: WorkspaceSnapshot;
|
|
46
|
-
extensionStatusIconAliases: ExtensionStatusIconAliasMap;
|
|
47
51
|
requestRender?: () => void;
|
|
48
52
|
renderPreview?: (loaded: LoadedStarshipConfig, width: number) => string[];
|
|
53
|
+
inspect?: (loaded: LoadedStarshipConfig) => StatuslineInspection;
|
|
54
|
+
footerWidth?: number;
|
|
49
55
|
}
|
|
50
56
|
|
|
51
57
|
interface RefreshTarget {
|
|
52
58
|
cwd: string;
|
|
53
59
|
generation: number;
|
|
60
|
+
sessionManager: ExtensionContext["sessionManager"];
|
|
54
61
|
}
|
|
55
62
|
|
|
56
63
|
interface GitRefreshInput {
|
|
@@ -58,23 +65,30 @@ interface GitRefreshInput {
|
|
|
58
65
|
config: StarshipConfig;
|
|
59
66
|
}
|
|
60
67
|
|
|
61
|
-
|
|
68
|
+
interface PiStarshipOptions {
|
|
69
|
+
githubPrExec?: WorkspaceExec;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions = {}) {
|
|
62
73
|
let loaded: LoadedStarshipConfig | undefined;
|
|
63
74
|
const runtime: RuntimeState = {
|
|
64
75
|
activeTools: new Map(),
|
|
65
76
|
isStreaming: false,
|
|
66
77
|
thinkingLevel: "off",
|
|
67
|
-
extensionStatusIconAliases: EMPTY_ALIASES,
|
|
68
78
|
};
|
|
69
|
-
let conflictWarningShown = false;
|
|
70
79
|
let sessionGeneration = 0;
|
|
71
80
|
let menuController = new AbortController();
|
|
81
|
+
let sessionOwner: ExtensionContext["sessionManager"] | undefined;
|
|
72
82
|
let activeTarget: RefreshTarget | undefined;
|
|
73
83
|
let eventDebounceTimer: ReturnType<typeof setTimeout> | undefined;
|
|
84
|
+
let githubPrRefreshTimer: ReturnType<typeof setInterval> | undefined;
|
|
85
|
+
let githubPrExpiryTimer: ReturnType<typeof setTimeout> | undefined;
|
|
86
|
+
let githubPrGeneration = 0;
|
|
74
87
|
|
|
75
88
|
const refresh = () => runtime.requestRender?.();
|
|
89
|
+
const githubPrExec = options.githubPrExec ?? execWorkspaceCommand;
|
|
76
90
|
const gitController = new AsyncRefreshController<GitRefreshInput, GitSnapshot | undefined>({
|
|
77
|
-
async read(input) {
|
|
91
|
+
async read(input, signal) {
|
|
78
92
|
const requirements = reachableModuleRequirements(input.config);
|
|
79
93
|
const gitReachable = [...requirements.keys()].some((name) => name.startsWith("git_"));
|
|
80
94
|
if (!gitReachable) return undefined;
|
|
@@ -82,6 +96,7 @@ export default function piStarship(pi: ExtensionAPI) {
|
|
|
82
96
|
return await readGitSnapshot(pi, input.cwd, {
|
|
83
97
|
includeMetrics: requirements.has("git_metrics"),
|
|
84
98
|
includeTag: requirements.get("git_commit")?.has("tag") ?? false,
|
|
99
|
+
signal,
|
|
85
100
|
});
|
|
86
101
|
} catch {
|
|
87
102
|
return undefined;
|
|
@@ -93,10 +108,22 @@ export default function piStarship(pi: ExtensionAPI) {
|
|
|
93
108
|
refresh();
|
|
94
109
|
},
|
|
95
110
|
});
|
|
111
|
+
const githubPrController = new AsyncRefreshController<
|
|
112
|
+
Pick<RefreshTarget, "cwd">,
|
|
113
|
+
GithubPrSnapshot | undefined
|
|
114
|
+
>({
|
|
115
|
+
read: (input, signal) => queryGithubPr(githubPrExec, input.cwd, signal),
|
|
116
|
+
equal: githubPrSnapshotEqual,
|
|
117
|
+
publish(snapshot) {
|
|
118
|
+
runtime.githubPr = snapshot;
|
|
119
|
+
scheduleGithubPrExpiry(snapshot);
|
|
120
|
+
refresh();
|
|
121
|
+
},
|
|
122
|
+
});
|
|
96
123
|
const workspaceController = new AsyncRefreshController<WorkspaceRefreshInput, WorkspaceSnapshot>({
|
|
97
|
-
async read(input) {
|
|
124
|
+
async read(input, signal) {
|
|
98
125
|
try {
|
|
99
|
-
return await collectWorkspaceSnapshot(input);
|
|
126
|
+
return await collectWorkspaceSnapshot({ ...input, signal });
|
|
100
127
|
} catch {
|
|
101
128
|
return { modules: {} };
|
|
102
129
|
}
|
|
@@ -116,6 +143,7 @@ export default function piStarship(pi: ExtensionAPI) {
|
|
|
116
143
|
const isActiveTarget = (target: RefreshTarget) =>
|
|
117
144
|
activeTarget?.cwd === target.cwd &&
|
|
118
145
|
activeTarget.generation === target.generation &&
|
|
146
|
+
activeTarget.sessionManager === target.sessionManager &&
|
|
119
147
|
target.generation === sessionGeneration;
|
|
120
148
|
|
|
121
149
|
const requestRefresh = (
|
|
@@ -130,7 +158,9 @@ export default function piStarship(pi: ExtensionAPI) {
|
|
|
130
158
|
};
|
|
131
159
|
const scheduleRefresh = (ctx: ExtensionContext) => {
|
|
132
160
|
const target = activeTarget;
|
|
133
|
-
if (!target || target.cwd !== ctx.cwd)
|
|
161
|
+
if (!target || target.cwd !== ctx.cwd || target.sessionManager !== ctx.sessionManager) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
134
164
|
clearDebounce();
|
|
135
165
|
eventDebounceTimer = setTimeout(() => {
|
|
136
166
|
eventDebounceTimer = undefined;
|
|
@@ -138,33 +168,92 @@ export default function piStarship(pi: ExtensionAPI) {
|
|
|
138
168
|
}, EVENT_DEBOUNCE_MS);
|
|
139
169
|
};
|
|
140
170
|
|
|
171
|
+
function restartLocalControllers(target: RefreshTarget) {
|
|
172
|
+
if (!isActiveTarget(target)) return;
|
|
173
|
+
gitController.start(target.generation);
|
|
174
|
+
workspaceController.start(target.generation);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function clearGithubPrTimers() {
|
|
178
|
+
if (githubPrRefreshTimer) clearInterval(githubPrRefreshTimer);
|
|
179
|
+
if (githubPrExpiryTimer) clearTimeout(githubPrExpiryTimer);
|
|
180
|
+
githubPrRefreshTimer = undefined;
|
|
181
|
+
githubPrExpiryTimer = undefined;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function stopGithubPr() {
|
|
185
|
+
clearGithubPrTimers();
|
|
186
|
+
githubPrController.stop();
|
|
187
|
+
runtime.githubPr = undefined;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function githubPrReachable(): boolean {
|
|
191
|
+
return Boolean(loaded && reachableModuleRequirements(loaded.config).has("github_pr"));
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function startGithubPr(target: RefreshTarget): boolean {
|
|
195
|
+
if (!isActiveTarget(target)) return false;
|
|
196
|
+
stopGithubPr();
|
|
197
|
+
if (!githubPrReachable()) return false;
|
|
198
|
+
githubPrController.start(++githubPrGeneration);
|
|
199
|
+
githubPrRefreshTimer = setInterval(() => {
|
|
200
|
+
requestGithubPr(target);
|
|
201
|
+
}, GITHUB_PR_REFRESH_INTERVAL_MS);
|
|
202
|
+
githubPrRefreshTimer.unref?.();
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function requestGithubPr(target: RefreshTarget) {
|
|
207
|
+
if (!isActiveTarget(target) || !githubPrReachable()) return;
|
|
208
|
+
githubPrController.request({ cwd: target.cwd });
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function scheduleGithubPrExpiry(snapshot: GithubPrSnapshot | undefined) {
|
|
212
|
+
if (githubPrExpiryTimer) clearTimeout(githubPrExpiryTimer);
|
|
213
|
+
githubPrExpiryTimer = undefined;
|
|
214
|
+
if (snapshot?.expiresAt === undefined) return;
|
|
215
|
+
const target = activeTarget;
|
|
216
|
+
if (!target) return;
|
|
217
|
+
const delay = snapshot.expiresAt - Date.now();
|
|
218
|
+
if (delay <= 0) {
|
|
219
|
+
runtime.githubPr = undefined;
|
|
220
|
+
githubPrController.clear();
|
|
221
|
+
refresh();
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
githubPrExpiryTimer = setTimeout(
|
|
225
|
+
() => {
|
|
226
|
+
githubPrExpiryTimer = undefined;
|
|
227
|
+
if (!isActiveTarget(target) || runtime.githubPr !== snapshot) return;
|
|
228
|
+
scheduleGithubPrExpiry(snapshot);
|
|
229
|
+
},
|
|
230
|
+
Math.min(delay, MAX_TIMER_DELAY_MS),
|
|
231
|
+
);
|
|
232
|
+
githubPrExpiryTimer.unref?.();
|
|
233
|
+
}
|
|
234
|
+
|
|
141
235
|
const installFooter = (ctx: ExtensionContext) => {
|
|
142
236
|
const generation = ++sessionGeneration;
|
|
237
|
+
sessionOwner = ctx.sessionManager;
|
|
143
238
|
menuController.abort(new DOMException("Starship session context replaced", "AbortError"));
|
|
144
239
|
menuController = new AbortController();
|
|
145
|
-
const target = { cwd: ctx.cwd, generation };
|
|
240
|
+
const target: RefreshTarget = { cwd: ctx.cwd, generation, sessionManager: ctx.sessionManager };
|
|
146
241
|
clearDebounce();
|
|
147
242
|
gitController.stop();
|
|
148
243
|
workspaceController.stop();
|
|
244
|
+
stopGithubPr();
|
|
149
245
|
runtime.git = undefined;
|
|
150
246
|
runtime.workspace = undefined;
|
|
151
247
|
runtime.requestRender = undefined;
|
|
152
248
|
runtime.renderPreview = undefined;
|
|
249
|
+
runtime.inspect = undefined;
|
|
250
|
+
runtime.footerWidth = undefined;
|
|
153
251
|
activeTarget = ctx.mode === "tui" ? target : undefined;
|
|
154
252
|
ctx.ui.setStatus("starship", undefined);
|
|
155
253
|
if (!activeTarget || !loaded) return;
|
|
156
254
|
gitController.start(generation);
|
|
157
255
|
workspaceController.start(generation);
|
|
158
|
-
|
|
159
|
-
const installed = readInstalledPackageInfo(getAgentDir(), target.cwd, ctx.isProjectTrusted());
|
|
160
|
-
runtime.extensionStatusIconAliases = installed.aliases;
|
|
161
|
-
if (installed.hasStatuslineConflict && !conflictWarningShown) {
|
|
162
|
-
conflictWarningShown = true;
|
|
163
|
-
ctx.ui.notify(
|
|
164
|
-
"pi-starship and pi-statusline both replace Pi's footer; disable one to avoid a footer conflict.",
|
|
165
|
-
"warning",
|
|
166
|
-
);
|
|
167
|
-
}
|
|
256
|
+
startGithubPr(target);
|
|
168
257
|
|
|
169
258
|
ctx.ui.setFooter((tui, _theme, footerData) => {
|
|
170
259
|
runtime.requestRender = () => tui.requestRender();
|
|
@@ -175,14 +264,24 @@ export default function piStarship(pi: ExtensionAPI) {
|
|
|
175
264
|
width,
|
|
176
265
|
);
|
|
177
266
|
};
|
|
267
|
+
runtime.inspect = (current) =>
|
|
268
|
+
inspectStatuslineModules(
|
|
269
|
+
current.config,
|
|
270
|
+
runtimeSnapshot(ctx, footerData, runtime),
|
|
271
|
+
runtime.footerWidth ?? 80,
|
|
272
|
+
);
|
|
178
273
|
const unsubscribe = footerData.onBranchChange(() => {
|
|
274
|
+
if (!isActiveTarget(target)) return;
|
|
179
275
|
runtime.git = undefined;
|
|
180
|
-
|
|
276
|
+
restartLocalControllers(target);
|
|
181
277
|
clearDebounce();
|
|
278
|
+
startGithubPr(target);
|
|
182
279
|
requestRefresh(target);
|
|
280
|
+
requestGithubPr(target);
|
|
183
281
|
tui.requestRender();
|
|
184
282
|
});
|
|
185
283
|
const timer = setInterval(() => {
|
|
284
|
+
if (!isActiveTarget(target)) return;
|
|
186
285
|
clearDebounce();
|
|
187
286
|
requestRefresh(target, "periodic");
|
|
188
287
|
tui.requestRender();
|
|
@@ -200,14 +299,18 @@ export default function piStarship(pi: ExtensionAPI) {
|
|
|
200
299
|
clearDebounce();
|
|
201
300
|
gitController.stop();
|
|
202
301
|
workspaceController.stop();
|
|
302
|
+
stopGithubPr();
|
|
203
303
|
runtime.git = undefined;
|
|
204
304
|
runtime.workspace = undefined;
|
|
205
305
|
runtime.requestRender = undefined;
|
|
206
306
|
runtime.renderPreview = undefined;
|
|
307
|
+
runtime.inspect = undefined;
|
|
308
|
+
runtime.footerWidth = undefined;
|
|
207
309
|
}
|
|
208
310
|
},
|
|
209
311
|
invalidate() {},
|
|
210
312
|
render(width: number): string[] {
|
|
313
|
+
runtime.footerWidth = width;
|
|
211
314
|
if (!loaded) return [];
|
|
212
315
|
const snapshot = runtimeSnapshot(ctx, footerData, runtime);
|
|
213
316
|
return wrapFormattedStatusline(
|
|
@@ -218,12 +321,17 @@ export default function piStarship(pi: ExtensionAPI) {
|
|
|
218
321
|
};
|
|
219
322
|
});
|
|
220
323
|
requestRefresh(target, "initial");
|
|
324
|
+
requestGithubPr(target);
|
|
221
325
|
};
|
|
222
326
|
|
|
223
327
|
const configPath = settingsFilePath(getAgentDir());
|
|
224
328
|
registerStarshipCommand(pi, {
|
|
225
329
|
settingsPath: configPath,
|
|
226
330
|
getLoaded: () => loaded ?? loadStarshipConfig(configPath),
|
|
331
|
+
getInspection: () => {
|
|
332
|
+
const current = loaded ?? loadStarshipConfig(configPath);
|
|
333
|
+
return runtime.inspect?.(current);
|
|
334
|
+
},
|
|
227
335
|
getMenuOwner: () => {
|
|
228
336
|
const generation = sessionGeneration;
|
|
229
337
|
return {
|
|
@@ -231,10 +339,18 @@ export default function piStarship(pi: ExtensionAPI) {
|
|
|
231
339
|
isCurrent: () => generation === sessionGeneration && !menuController.signal.aborted,
|
|
232
340
|
};
|
|
233
341
|
},
|
|
234
|
-
apply(next) {
|
|
342
|
+
apply(next, ctx) {
|
|
343
|
+
if (sessionOwner !== ctx.sessionManager) {
|
|
344
|
+
throw new Error("Starship session context was replaced");
|
|
345
|
+
}
|
|
235
346
|
loaded = next;
|
|
236
347
|
const target = activeTarget;
|
|
237
|
-
if (target)
|
|
348
|
+
if (target) {
|
|
349
|
+
restartLocalControllers(target);
|
|
350
|
+
startGithubPr(target);
|
|
351
|
+
requestRefresh(target);
|
|
352
|
+
requestGithubPr(target);
|
|
353
|
+
}
|
|
238
354
|
refresh();
|
|
239
355
|
},
|
|
240
356
|
renderPreview(preview, width) {
|
|
@@ -261,17 +377,21 @@ export default function piStarship(pi: ExtensionAPI) {
|
|
|
261
377
|
});
|
|
262
378
|
|
|
263
379
|
pi.on("session_shutdown", (_event, ctx) => {
|
|
380
|
+
if (sessionOwner !== ctx.sessionManager) return;
|
|
381
|
+
sessionOwner = undefined;
|
|
264
382
|
sessionGeneration += 1;
|
|
265
383
|
menuController.abort(new DOMException("Starship session shut down", "AbortError"));
|
|
266
384
|
activeTarget = undefined;
|
|
267
385
|
clearDebounce();
|
|
268
386
|
gitController.stop();
|
|
269
387
|
workspaceController.stop();
|
|
388
|
+
stopGithubPr();
|
|
270
389
|
runtime.git = undefined;
|
|
271
390
|
runtime.workspace = undefined;
|
|
272
|
-
runtime.extensionStatusIconAliases = EMPTY_ALIASES;
|
|
273
391
|
runtime.requestRender = undefined;
|
|
274
392
|
runtime.renderPreview = undefined;
|
|
393
|
+
runtime.inspect = undefined;
|
|
394
|
+
runtime.footerWidth = undefined;
|
|
275
395
|
ctx.ui.setFooter(undefined);
|
|
276
396
|
ctx.ui.setStatus("starship", undefined);
|
|
277
397
|
});
|
|
@@ -288,6 +408,8 @@ export default function piStarship(pi: ExtensionAPI) {
|
|
|
288
408
|
pi.on("agent_end", (_event, ctx) => {
|
|
289
409
|
runtime.isStreaming = false;
|
|
290
410
|
scheduleRefresh(ctx);
|
|
411
|
+
const target = activeTarget;
|
|
412
|
+
if (target?.sessionManager === ctx.sessionManager) requestGithubPr(target);
|
|
291
413
|
refresh();
|
|
292
414
|
});
|
|
293
415
|
pi.on("turn_start", () => {
|
|
@@ -415,9 +537,9 @@ function runtimeSnapshot(
|
|
|
415
537
|
gitMetrics: runtime.git?.metrics,
|
|
416
538
|
gitStatus: runtime.git?.status,
|
|
417
539
|
gitWorktree: runtime.git?.worktree,
|
|
540
|
+
githubPr: runtime.githubPr,
|
|
418
541
|
workspace: runtime.workspace,
|
|
419
542
|
extensionStatuses: footerData.getExtensionStatuses(),
|
|
420
|
-
extensionStatusIconAliases: runtime.extensionStatusIconAliases,
|
|
421
543
|
now: new Date(),
|
|
422
544
|
};
|
|
423
545
|
}
|
package/src/runtime/command.ts
CHANGED
|
@@ -5,10 +5,16 @@ const FORCE_KILL_DELAY_MS = 250;
|
|
|
5
5
|
|
|
6
6
|
export const execWorkspaceCommand: WorkspaceExec = async (command, args, options) =>
|
|
7
7
|
new Promise((resolve) => {
|
|
8
|
+
if (options.signal?.aborted) {
|
|
9
|
+
resolve({ stdout: "", stderr: "", code: 1, killed: true });
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
|
|
8
13
|
let child: ReturnType<typeof spawn>;
|
|
9
14
|
try {
|
|
10
15
|
child = spawn(command, args, {
|
|
11
16
|
cwd: options.cwd,
|
|
17
|
+
detached: process.platform !== "win32",
|
|
12
18
|
env: explicitEnvironment(options.environment),
|
|
13
19
|
shell: false,
|
|
14
20
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -25,12 +31,14 @@ export const execWorkspaceCommand: WorkspaceExec = async (command, args, options
|
|
|
25
31
|
let killed = false;
|
|
26
32
|
let settled = false;
|
|
27
33
|
let forceKillTimer: NodeJS.Timeout | undefined;
|
|
34
|
+
let timeoutTimer: NodeJS.Timeout | undefined;
|
|
28
35
|
|
|
29
36
|
const finish = (code: number) => {
|
|
30
37
|
if (settled) return;
|
|
31
38
|
settled = true;
|
|
32
|
-
clearTimeout(timeoutTimer);
|
|
39
|
+
if (timeoutTimer) clearTimeout(timeoutTimer);
|
|
33
40
|
if (forceKillTimer) clearTimeout(forceKillTimer);
|
|
41
|
+
options.signal?.removeEventListener("abort", terminate);
|
|
34
42
|
resolve({
|
|
35
43
|
stdout: Buffer.concat(stdout).toString("utf8"),
|
|
36
44
|
stderr: Buffer.concat(stderr).toString("utf8"),
|
|
@@ -39,17 +47,41 @@ export const execWorkspaceCommand: WorkspaceExec = async (command, args, options
|
|
|
39
47
|
});
|
|
40
48
|
};
|
|
41
49
|
|
|
42
|
-
const
|
|
50
|
+
const signalProcessTree = (signal: NodeJS.Signals) => {
|
|
51
|
+
const pid = child.pid;
|
|
52
|
+
if (pid === undefined) return;
|
|
53
|
+
if (process.platform !== "win32") {
|
|
54
|
+
try {
|
|
55
|
+
process.kill(-pid, signal);
|
|
56
|
+
return;
|
|
57
|
+
} catch {
|
|
58
|
+
child.kill(signal);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
const killer = spawn("taskkill.exe", ["/pid", String(pid), "/t", "/f"], {
|
|
64
|
+
stdio: "ignore",
|
|
65
|
+
windowsHide: true,
|
|
66
|
+
});
|
|
67
|
+
killer.once("error", () => child.kill(signal));
|
|
68
|
+
killer.unref();
|
|
69
|
+
} catch {
|
|
70
|
+
child.kill(signal);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
function terminate() {
|
|
43
75
|
if (killed || settled) return;
|
|
44
76
|
killed = true;
|
|
45
|
-
|
|
77
|
+
signalProcessTree("SIGTERM");
|
|
46
78
|
forceKillTimer = setTimeout(() => {
|
|
47
|
-
|
|
79
|
+
signalProcessTree("SIGKILL");
|
|
48
80
|
child.stdout?.destroy();
|
|
49
81
|
child.stderr?.destroy();
|
|
50
82
|
finish(1);
|
|
51
83
|
}, FORCE_KILL_DELAY_MS);
|
|
52
|
-
}
|
|
84
|
+
}
|
|
53
85
|
|
|
54
86
|
const collect = (target: Buffer[]) => (data: Buffer | string) => {
|
|
55
87
|
const chunk = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
@@ -61,9 +93,15 @@ export const execWorkspaceCommand: WorkspaceExec = async (command, args, options
|
|
|
61
93
|
|
|
62
94
|
child.stdout?.on("data", collect(stdout));
|
|
63
95
|
child.stderr?.on("data", collect(stderr));
|
|
64
|
-
child.once("error", () =>
|
|
65
|
-
|
|
66
|
-
|
|
96
|
+
child.once("error", () => {
|
|
97
|
+
if (!killed) finish(1);
|
|
98
|
+
});
|
|
99
|
+
child.once("close", (code) => {
|
|
100
|
+
if (!killed) finish(code ?? 1);
|
|
101
|
+
});
|
|
102
|
+
options.signal?.addEventListener("abort", terminate, { once: true });
|
|
103
|
+
if (options.signal?.aborted) terminate();
|
|
104
|
+
timeoutTimer = setTimeout(terminate, options.timeout);
|
|
67
105
|
});
|
|
68
106
|
|
|
69
107
|
function explicitEnvironment(
|