@mrclrchtr/supi-review 0.1.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 +78 -0
- package/node_modules/@mrclrchtr/supi-core/README.md +90 -0
- package/node_modules/@mrclrchtr/supi-core/package.json +30 -0
- package/node_modules/@mrclrchtr/supi-core/src/config-settings.ts +76 -0
- package/node_modules/@mrclrchtr/supi-core/src/config.ts +186 -0
- package/node_modules/@mrclrchtr/supi-core/src/context-messages.ts +119 -0
- package/node_modules/@mrclrchtr/supi-core/src/context-provider-registry.ts +36 -0
- package/node_modules/@mrclrchtr/supi-core/src/context-tag.ts +31 -0
- package/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +255 -0
- package/node_modules/@mrclrchtr/supi-core/src/index.ts +83 -0
- package/node_modules/@mrclrchtr/supi-core/src/project-roots.ts +170 -0
- package/node_modules/@mrclrchtr/supi-core/src/registry-utils.ts +54 -0
- package/node_modules/@mrclrchtr/supi-core/src/session-utils.ts +29 -0
- package/node_modules/@mrclrchtr/supi-core/src/settings-command.ts +15 -0
- package/node_modules/@mrclrchtr/supi-core/src/settings-registry.ts +41 -0
- package/node_modules/@mrclrchtr/supi-core/src/settings-ui.ts +226 -0
- package/node_modules/@mrclrchtr/supi-core/src/terminal.ts +60 -0
- package/package.json +43 -0
- package/src/format-content.ts +71 -0
- package/src/git.ts +197 -0
- package/src/index.ts +1 -0
- package/src/progress-widget.ts +82 -0
- package/src/prompts.ts +116 -0
- package/src/renderer.ts +181 -0
- package/src/review.ts +351 -0
- package/src/runner-types.ts +32 -0
- package/src/runner.ts +424 -0
- package/src/settings.ts +246 -0
- package/src/target-resolution.ts +102 -0
- package/src/types.ts +49 -0
- package/src/ui.ts +116 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
// Generic settings overlay for SuPi extensions.
|
|
2
|
+
//
|
|
3
|
+
// Uses pi-tui's SettingsList with scope toggle (Tab), extension grouping,
|
|
4
|
+
// and search. Each extension declares its settings via registerSettings().
|
|
5
|
+
|
|
6
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
7
|
+
import { getSettingsListTheme } from "@earendil-works/pi-coding-agent";
|
|
8
|
+
import {
|
|
9
|
+
Container,
|
|
10
|
+
Input,
|
|
11
|
+
Key,
|
|
12
|
+
matchesKey,
|
|
13
|
+
type SettingItem,
|
|
14
|
+
SettingsList,
|
|
15
|
+
Text,
|
|
16
|
+
} from "@earendil-works/pi-tui";
|
|
17
|
+
import {
|
|
18
|
+
getRegisteredSettings,
|
|
19
|
+
type SettingsScope,
|
|
20
|
+
type SettingsSection,
|
|
21
|
+
} from "./settings-registry.ts";
|
|
22
|
+
|
|
23
|
+
// ── Input submenu component ──────────────────────────────────
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Creates a pi-tui Input-backed submenu component with enter-to-confirm
|
|
27
|
+
* and escape-to-cancel handling.
|
|
28
|
+
*
|
|
29
|
+
* @param currentValue - Initial value for the text input.
|
|
30
|
+
* @param label - Label text displayed above the input.
|
|
31
|
+
* @param done - Callback invoked with the confirmed value, or undefined on cancel.
|
|
32
|
+
*/
|
|
33
|
+
export function createInputSubmenu(
|
|
34
|
+
currentValue: string,
|
|
35
|
+
label: string,
|
|
36
|
+
done: (selectedValue?: string) => void,
|
|
37
|
+
): {
|
|
38
|
+
render: (width: number) => string[];
|
|
39
|
+
invalidate: () => void;
|
|
40
|
+
handleInput: (data: string) => boolean;
|
|
41
|
+
} {
|
|
42
|
+
const input = new Input();
|
|
43
|
+
input.setValue(currentValue);
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
render: (_width: number) => {
|
|
47
|
+
const lines = [` ${label}`];
|
|
48
|
+
lines.push(...input.render(_width));
|
|
49
|
+
lines.push(" enter confirm • esc cancel");
|
|
50
|
+
return lines;
|
|
51
|
+
},
|
|
52
|
+
invalidate: () => {
|
|
53
|
+
input.invalidate();
|
|
54
|
+
},
|
|
55
|
+
handleInput: (data: string) => {
|
|
56
|
+
if (matchesKey(data, Key.escape)) {
|
|
57
|
+
done();
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
if (matchesKey(data, Key.enter)) {
|
|
61
|
+
done(input.getValue());
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
input.handleInput(data);
|
|
65
|
+
return true;
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ── Types ────────────────────────────────────────────────────
|
|
71
|
+
|
|
72
|
+
interface OverlayState {
|
|
73
|
+
scope: SettingsScope;
|
|
74
|
+
cwd: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ── Pure helpers ─────────────────────────────────────────────
|
|
78
|
+
|
|
79
|
+
function getScopeLabel(scope: SettingsScope): string {
|
|
80
|
+
return scope === "project" ? "Project" : "Global";
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function buildFlatItems(
|
|
84
|
+
sections: SettingsSection[],
|
|
85
|
+
scope: SettingsScope,
|
|
86
|
+
cwd: string,
|
|
87
|
+
): SettingItem[] {
|
|
88
|
+
const items: SettingItem[] = [];
|
|
89
|
+
for (const section of sections) {
|
|
90
|
+
const sectionItems = section.loadValues(scope, cwd);
|
|
91
|
+
for (const item of sectionItems) {
|
|
92
|
+
items.push({
|
|
93
|
+
...item,
|
|
94
|
+
id: `${section.id}.${item.id}`,
|
|
95
|
+
label: `${section.label}: ${item.label}`,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return items;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function findSectionAndId(
|
|
103
|
+
sections: SettingsSection[],
|
|
104
|
+
flatId: string,
|
|
105
|
+
): { section: SettingsSection; itemId: string } | null {
|
|
106
|
+
const dotIndex = flatId.indexOf(".");
|
|
107
|
+
if (dotIndex === -1) return null;
|
|
108
|
+
const sectionId = flatId.slice(0, dotIndex);
|
|
109
|
+
const itemId = flatId.slice(dotIndex + 1);
|
|
110
|
+
const section = sections.find((s) => s.id === sectionId);
|
|
111
|
+
if (!section) return null;
|
|
112
|
+
return { section, itemId };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// ── Component ────────────────────────────────────────────────
|
|
116
|
+
|
|
117
|
+
interface SettingsOverlayDeps {
|
|
118
|
+
state: OverlayState;
|
|
119
|
+
container: Container;
|
|
120
|
+
settingsList: SettingsList | null;
|
|
121
|
+
tui: Parameters<Parameters<ExtensionContext["ui"]["custom"]>[0]>[0];
|
|
122
|
+
theme: Parameters<Parameters<ExtensionContext["ui"]["custom"]>[0]>[1];
|
|
123
|
+
done: () => void;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function createSettingsList(deps: SettingsOverlayDeps): SettingsList {
|
|
127
|
+
const sections = getRegisteredSettings();
|
|
128
|
+
const items = buildFlatItems(sections, deps.state.scope, deps.state.cwd);
|
|
129
|
+
const onChange = (flatId: string, newValue: string) => {
|
|
130
|
+
const found = findSectionAndId(sections, flatId);
|
|
131
|
+
if (found) {
|
|
132
|
+
found.section.persistChange(deps.state.scope, deps.state.cwd, found.itemId, newValue);
|
|
133
|
+
}
|
|
134
|
+
// Re-read all values to reflect persisted changes, but keep the list
|
|
135
|
+
// instance (and its selectedIndex) intact.
|
|
136
|
+
const updatedItems = buildFlatItems(sections, deps.state.scope, deps.state.cwd);
|
|
137
|
+
for (const updated of updatedItems) {
|
|
138
|
+
const existing = items.find((i) => i.id === updated.id);
|
|
139
|
+
if (existing && existing.currentValue !== updated.currentValue) {
|
|
140
|
+
settingsList.updateValue(updated.id, updated.currentValue);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
deps.tui.requestRender();
|
|
144
|
+
};
|
|
145
|
+
const settingsList = new SettingsList(
|
|
146
|
+
items,
|
|
147
|
+
Math.min(items.length + 4, 20),
|
|
148
|
+
getSettingsListTheme(),
|
|
149
|
+
onChange,
|
|
150
|
+
() => deps.done(),
|
|
151
|
+
{ enableSearch: true },
|
|
152
|
+
);
|
|
153
|
+
return settingsList;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function rebuildSettingsList(deps: SettingsOverlayDeps): SettingsList {
|
|
157
|
+
const settingsList = createSettingsList(deps);
|
|
158
|
+
deps.settingsList = settingsList;
|
|
159
|
+
|
|
160
|
+
deps.container.clear();
|
|
161
|
+
deps.container.addChild(createHeaderComponent(deps));
|
|
162
|
+
deps.container.addChild(settingsList);
|
|
163
|
+
|
|
164
|
+
return settingsList;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function createHeaderComponent(deps: SettingsOverlayDeps): Text {
|
|
168
|
+
const { theme, state } = deps;
|
|
169
|
+
const scopeLabel = getScopeLabel(state.scope);
|
|
170
|
+
const otherScope = state.scope === "project" ? "Global" : "Project";
|
|
171
|
+
const headerText = new Text(
|
|
172
|
+
`${theme.fg("accent", theme.bold("SuPi Settings"))} ${theme.fg("text", `Scope: ${scopeLabel}`)} ${theme.fg("dim", `(tab → ${otherScope})`)}`,
|
|
173
|
+
0,
|
|
174
|
+
0,
|
|
175
|
+
);
|
|
176
|
+
return headerText;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function handleScopeToggle(deps: SettingsOverlayDeps): void {
|
|
180
|
+
deps.state.scope = deps.state.scope === "project" ? "global" : "project";
|
|
181
|
+
rebuildSettingsList(deps);
|
|
182
|
+
deps.tui.requestRender();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// ── Entry point ──────────────────────────────────────────────
|
|
186
|
+
|
|
187
|
+
export function openSettingsOverlay(ctx: ExtensionContext): void {
|
|
188
|
+
const sections = getRegisteredSettings();
|
|
189
|
+
if (sections.length === 0) {
|
|
190
|
+
ctx.ui.notify("No settings registered by SuPi extensions", "info");
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
void ctx.ui.custom<void>((tui, theme, _kb, done) => {
|
|
195
|
+
const state: OverlayState = { scope: "project", cwd: ctx.cwd };
|
|
196
|
+
const container = new Container();
|
|
197
|
+
|
|
198
|
+
const deps: SettingsOverlayDeps = {
|
|
199
|
+
state,
|
|
200
|
+
container,
|
|
201
|
+
settingsList: null,
|
|
202
|
+
tui,
|
|
203
|
+
theme,
|
|
204
|
+
done,
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
rebuildSettingsList(deps);
|
|
208
|
+
|
|
209
|
+
const component = {
|
|
210
|
+
render: (width: number) => container.render(width),
|
|
211
|
+
invalidate: () => container.invalidate(),
|
|
212
|
+
handleInput: (data: string) => {
|
|
213
|
+
if (matchesKey(data, Key.tab)) {
|
|
214
|
+
handleScopeToggle(deps);
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
// Delegate input to the settings list (always set after rebuildSettingsList)
|
|
218
|
+
deps.settingsList?.handleInput?.(data);
|
|
219
|
+
deps.tui.requestRender();
|
|
220
|
+
return true;
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
return component;
|
|
225
|
+
});
|
|
226
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared terminal title formatting and signaling utilities.
|
|
3
|
+
*
|
|
4
|
+
* Centralized place for pi title convention (π prefix), completion (✓)
|
|
5
|
+
* and waiting (●) indicators, and the audible terminal bell.
|
|
6
|
+
*/
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
|
|
9
|
+
/** Unicode checkmark shown when the agent finishes a turn. */
|
|
10
|
+
export const DONE_SYMBOL = "\u2713";
|
|
11
|
+
/** Unicode dot shown when waiting for user input. */
|
|
12
|
+
export const WAITING_SYMBOL = "\u25CF";
|
|
13
|
+
|
|
14
|
+
/** Minimal UI surface needed for title operations. */
|
|
15
|
+
export interface TitleTarget {
|
|
16
|
+
ui: {
|
|
17
|
+
setTitle?(title: string): void;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Format pi's canonical terminal title from session name and cwd.
|
|
23
|
+
* Falls back gracefully when either is missing.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* formatTitle("my-session", "/home/projects/foo") // "π - my-session - foo"
|
|
27
|
+
* formatTitle(undefined, "/home/projects/foo") // "π - foo"
|
|
28
|
+
* formatTitle("my-session") // "π - my-session"
|
|
29
|
+
* formatTitle() // "π"
|
|
30
|
+
*/
|
|
31
|
+
export function formatTitle(sessionName?: string, cwd?: string): string {
|
|
32
|
+
const base = cwd ? path.basename(cwd) : undefined;
|
|
33
|
+
if (sessionName && base) return `π - ${sessionName} - ${base}`;
|
|
34
|
+
if (sessionName) return `π - ${sessionName}`;
|
|
35
|
+
if (base) return `π - ${base}`;
|
|
36
|
+
return "π";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Sound the audible terminal bell (ASCII BEL). */
|
|
40
|
+
export function signalBell(): void {
|
|
41
|
+
process.stdout.write("\x07");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Set the terminal title to indicate the agent is waiting for user input.
|
|
46
|
+
* Prefixes with ● and sounds the terminal bell.
|
|
47
|
+
*/
|
|
48
|
+
export function signalWaiting(ctx: TitleTarget, title: string): void {
|
|
49
|
+
ctx.ui.setTitle?.(`${WAITING_SYMBOL} ${title}`);
|
|
50
|
+
signalBell();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Set the terminal title to indicate the agent turn has completed.
|
|
55
|
+
* Prefixes with ✓ and sounds the terminal bell.
|
|
56
|
+
*/
|
|
57
|
+
export function signalDone(ctx: TitleTarget, title: string): void {
|
|
58
|
+
ctx.ui.setTitle?.(`${DONE_SYMBOL} ${title}`);
|
|
59
|
+
signalBell();
|
|
60
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mrclrchtr/supi-review",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "SuPi Review extension — structured code review via /supi-review command",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/mrclrchtr/supi.git"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"pi-package",
|
|
15
|
+
"pi",
|
|
16
|
+
"pi-coding-agent"
|
|
17
|
+
],
|
|
18
|
+
"files": [
|
|
19
|
+
"src/**/*.ts",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@mrclrchtr/supi-core": "workspace:*"
|
|
24
|
+
},
|
|
25
|
+
"bundledDependencies": [
|
|
26
|
+
"@mrclrchtr/supi-core"
|
|
27
|
+
],
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"@earendil-works/pi-ai": "*",
|
|
30
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
31
|
+
"@earendil-works/pi-tui": "*",
|
|
32
|
+
"typebox": "*"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"vitest": "^4.1.4"
|
|
36
|
+
},
|
|
37
|
+
"pi": {
|
|
38
|
+
"extensions": [
|
|
39
|
+
"./src/review.ts"
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
"main": "src/index.ts"
|
|
43
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { ReviewResult } from "./types.ts";
|
|
2
|
+
|
|
3
|
+
function priorityLabel(priority: number): string {
|
|
4
|
+
switch (priority) {
|
|
5
|
+
case 0:
|
|
6
|
+
return "info";
|
|
7
|
+
case 1:
|
|
8
|
+
return "minor";
|
|
9
|
+
case 2:
|
|
10
|
+
return "major";
|
|
11
|
+
case 3:
|
|
12
|
+
return "critical";
|
|
13
|
+
default:
|
|
14
|
+
return "info";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function formatReviewContent(result: ReviewResult): string {
|
|
19
|
+
switch (result.kind) {
|
|
20
|
+
case "success":
|
|
21
|
+
return formatSuccessContent(result);
|
|
22
|
+
case "failed":
|
|
23
|
+
return `Review failed: ${result.reason}`;
|
|
24
|
+
case "canceled":
|
|
25
|
+
return "Review canceled";
|
|
26
|
+
case "timeout":
|
|
27
|
+
return formatTimeoutContent(result);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function formatTimeoutContent(result: Extract<ReviewResult, { kind: "timeout" }>): string {
|
|
32
|
+
const parts = [`Review timed out (exceeded ${(result.timeoutMs / 1000).toFixed(0)}s)`];
|
|
33
|
+
if (result.partialOutput) {
|
|
34
|
+
parts.push("", "Partial output:", result.partialOutput);
|
|
35
|
+
}
|
|
36
|
+
return parts.join("\n");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function formatSuccessContent(result: Extract<ReviewResult, { kind: "success" }>): string {
|
|
40
|
+
const output = result.output;
|
|
41
|
+
const confidencePercent = Math.round(output.overall_confidence_score * 100);
|
|
42
|
+
const lines = [
|
|
43
|
+
"## Code Review Result",
|
|
44
|
+
"",
|
|
45
|
+
`Verdict: ${output.overall_correctness} (confidence: ${confidencePercent}%)`,
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
if (output.findings.length > 0) {
|
|
49
|
+
lines.push("", "### Findings", "", ...formatFindings(output.findings));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
lines.push("", `Overall: ${output.overall_explanation}`);
|
|
53
|
+
return lines.join("\n");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function formatFindings(
|
|
57
|
+
findings: Extract<ReviewResult, { kind: "success" }>["output"]["findings"],
|
|
58
|
+
): string[] {
|
|
59
|
+
return findings.flatMap((finding, index) => {
|
|
60
|
+
const loc = finding.code_location;
|
|
61
|
+
const lineRange =
|
|
62
|
+
loc.line_range.start === loc.line_range.end
|
|
63
|
+
? String(loc.line_range.start)
|
|
64
|
+
: `${loc.line_range.start}-${loc.line_range.end}`;
|
|
65
|
+
return [
|
|
66
|
+
`#${index + 1} [${priorityLabel(finding.priority)}] ${finding.title}`,
|
|
67
|
+
` ${loc.absolute_file_path}:${lineRange}`,
|
|
68
|
+
` ${finding.body}`,
|
|
69
|
+
];
|
|
70
|
+
});
|
|
71
|
+
}
|
package/src/git.ts
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
|
|
4
|
+
const execFileAsync = promisify(execFile);
|
|
5
|
+
|
|
6
|
+
const GIT_TIMEOUT_MS = 30_000;
|
|
7
|
+
|
|
8
|
+
export async function getMergeBase(repoPath: string, branch: string): Promise<string | undefined> {
|
|
9
|
+
try {
|
|
10
|
+
const { stdout } = await execFileAsync("git", ["merge-base", "HEAD", branch], {
|
|
11
|
+
cwd: repoPath,
|
|
12
|
+
timeout: GIT_TIMEOUT_MS,
|
|
13
|
+
});
|
|
14
|
+
return stdout.trim() || undefined;
|
|
15
|
+
} catch {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function getDiff(repoPath: string, baseSha: string): Promise<string> {
|
|
21
|
+
const { stdout } = await execFileAsync("git", ["diff", baseSha], {
|
|
22
|
+
cwd: repoPath,
|
|
23
|
+
timeout: GIT_TIMEOUT_MS,
|
|
24
|
+
});
|
|
25
|
+
return stdout;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function getUncommittedDiff(repoPath: string): Promise<string> {
|
|
29
|
+
const [staged, unstaged, untracked] = await Promise.all([
|
|
30
|
+
execFileAsync("git", ["diff", "--cached"], { cwd: repoPath, timeout: GIT_TIMEOUT_MS }).then(
|
|
31
|
+
(r) => r.stdout,
|
|
32
|
+
() => "",
|
|
33
|
+
),
|
|
34
|
+
execFileAsync("git", ["diff"], { cwd: repoPath, timeout: GIT_TIMEOUT_MS }).then(
|
|
35
|
+
(r) => r.stdout,
|
|
36
|
+
() => "",
|
|
37
|
+
),
|
|
38
|
+
execFileAsync("git", ["ls-files", "--others", "--exclude-standard"], {
|
|
39
|
+
cwd: repoPath,
|
|
40
|
+
timeout: GIT_TIMEOUT_MS,
|
|
41
|
+
}).then(
|
|
42
|
+
(r) => r.stdout,
|
|
43
|
+
() => "",
|
|
44
|
+
),
|
|
45
|
+
]);
|
|
46
|
+
|
|
47
|
+
let result = "";
|
|
48
|
+
if (staged.trim()) {
|
|
49
|
+
result += `=== Staged ===\n${staged}\n`;
|
|
50
|
+
}
|
|
51
|
+
if (unstaged.trim()) {
|
|
52
|
+
result += `=== Unstaged ===\n${unstaged}\n`;
|
|
53
|
+
}
|
|
54
|
+
if (untracked.trim()) {
|
|
55
|
+
const files = untracked
|
|
56
|
+
.trim()
|
|
57
|
+
.split("\n")
|
|
58
|
+
.map((f) => f.trim())
|
|
59
|
+
.filter((f) => f.length > 0);
|
|
60
|
+
if (files.length > 0) {
|
|
61
|
+
result += `=== Untracked files ===\n${files.join("\n")}\n`;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return result.trimEnd();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface CommitEntry {
|
|
68
|
+
sha: string;
|
|
69
|
+
subject: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export async function getRecentCommits(repoPath: string, limit = 20): Promise<CommitEntry[]> {
|
|
73
|
+
const { stdout } = await execFileAsync(
|
|
74
|
+
"git",
|
|
75
|
+
["log", `--max-count=${limit}`, "--pretty=format:%H %s"],
|
|
76
|
+
{ cwd: repoPath, timeout: GIT_TIMEOUT_MS },
|
|
77
|
+
);
|
|
78
|
+
return stdout
|
|
79
|
+
.split("\n")
|
|
80
|
+
.map((line) => {
|
|
81
|
+
const idx = line.indexOf(" ");
|
|
82
|
+
if (idx <= 0) return undefined;
|
|
83
|
+
return { sha: line.slice(0, idx), subject: line.slice(idx + 1) };
|
|
84
|
+
})
|
|
85
|
+
.filter((e): e is CommitEntry => e !== undefined);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export async function getCommitShow(repoPath: string, sha: string): Promise<string> {
|
|
89
|
+
const { stdout } = await execFileAsync("git", ["show", sha], {
|
|
90
|
+
cwd: repoPath,
|
|
91
|
+
timeout: GIT_TIMEOUT_MS,
|
|
92
|
+
});
|
|
93
|
+
return stdout;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export async function getDiffFileNames(repoPath: string, baseSha: string): Promise<string[]> {
|
|
97
|
+
const { stdout } = await execFileAsync("git", ["diff", "--name-only", baseSha], {
|
|
98
|
+
cwd: repoPath,
|
|
99
|
+
timeout: GIT_TIMEOUT_MS,
|
|
100
|
+
});
|
|
101
|
+
return stdout
|
|
102
|
+
.trim()
|
|
103
|
+
.split("\n")
|
|
104
|
+
.map((f) => f.trim())
|
|
105
|
+
.filter((f) => f.length > 0);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export async function getUncommittedFileNames(repoPath: string): Promise<string[]> {
|
|
109
|
+
const [unstaged, staged, untracked] = await Promise.all([
|
|
110
|
+
execFileAsync("git", ["diff", "--name-only"], { cwd: repoPath, timeout: GIT_TIMEOUT_MS }).then(
|
|
111
|
+
(r) => r.stdout,
|
|
112
|
+
() => "",
|
|
113
|
+
),
|
|
114
|
+
execFileAsync("git", ["diff", "--cached", "--name-only"], {
|
|
115
|
+
cwd: repoPath,
|
|
116
|
+
timeout: GIT_TIMEOUT_MS,
|
|
117
|
+
}).then(
|
|
118
|
+
(r) => r.stdout,
|
|
119
|
+
() => "",
|
|
120
|
+
),
|
|
121
|
+
execFileAsync("git", ["ls-files", "--others", "--exclude-standard"], {
|
|
122
|
+
cwd: repoPath,
|
|
123
|
+
timeout: GIT_TIMEOUT_MS,
|
|
124
|
+
}).then(
|
|
125
|
+
(r) => r.stdout,
|
|
126
|
+
() => "",
|
|
127
|
+
),
|
|
128
|
+
]);
|
|
129
|
+
|
|
130
|
+
const set = new Set([
|
|
131
|
+
...unstaged
|
|
132
|
+
.trim()
|
|
133
|
+
.split("\n")
|
|
134
|
+
.map((f) => f.trim())
|
|
135
|
+
.filter((f) => f.length > 0),
|
|
136
|
+
...staged
|
|
137
|
+
.trim()
|
|
138
|
+
.split("\n")
|
|
139
|
+
.map((f) => f.trim())
|
|
140
|
+
.filter((f) => f.length > 0),
|
|
141
|
+
...untracked
|
|
142
|
+
.trim()
|
|
143
|
+
.split("\n")
|
|
144
|
+
.map((f) => f.trim())
|
|
145
|
+
.filter((f) => f.length > 0),
|
|
146
|
+
]);
|
|
147
|
+
return Array.from(set).sort();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export async function getCommitFileNames(repoPath: string, sha: string): Promise<string[]> {
|
|
151
|
+
const { stdout } = await execFileAsync(
|
|
152
|
+
"git",
|
|
153
|
+
["diff-tree", "--no-commit-id", "--name-only", "-r", sha],
|
|
154
|
+
{ cwd: repoPath, timeout: GIT_TIMEOUT_MS },
|
|
155
|
+
);
|
|
156
|
+
return stdout
|
|
157
|
+
.trim()
|
|
158
|
+
.split("\n")
|
|
159
|
+
.map((f) => f.trim())
|
|
160
|
+
.filter((f) => f.length > 0);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export async function getLocalBranches(repoPath: string): Promise<string[]> {
|
|
164
|
+
const [{ stdout: local }, { stdout: current }] = await Promise.all([
|
|
165
|
+
execFileAsync("git", ["branch", "--format=%(refname:short)"], {
|
|
166
|
+
cwd: repoPath,
|
|
167
|
+
timeout: GIT_TIMEOUT_MS,
|
|
168
|
+
}),
|
|
169
|
+
execFileAsync("git", ["branch", "--show-current"], {
|
|
170
|
+
cwd: repoPath,
|
|
171
|
+
timeout: GIT_TIMEOUT_MS,
|
|
172
|
+
}),
|
|
173
|
+
]);
|
|
174
|
+
|
|
175
|
+
const names = local
|
|
176
|
+
.trim()
|
|
177
|
+
.split("\n")
|
|
178
|
+
.map((b) => b.trim())
|
|
179
|
+
.filter((b) => b.length > 0);
|
|
180
|
+
|
|
181
|
+
const currentBranch = current.trim();
|
|
182
|
+
const set = new Set(names);
|
|
183
|
+
const sorted: string[] = [];
|
|
184
|
+
|
|
185
|
+
// Put default candidates first
|
|
186
|
+
for (const candidate of ["main", "master", currentBranch]) {
|
|
187
|
+
if (candidate && set.has(candidate)) {
|
|
188
|
+
sorted.push(candidate);
|
|
189
|
+
set.delete(candidate);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Then remaining alphabetically
|
|
194
|
+
const remaining = Array.from(set).sort((a, b) => a.localeCompare(b));
|
|
195
|
+
sorted.push(...remaining);
|
|
196
|
+
return sorted;
|
|
197
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./review.ts";
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { CancellableLoader, Container, Text, type TUI } from "@earendil-works/pi-tui";
|
|
3
|
+
import { formatTokens } from "./runner.ts";
|
|
4
|
+
import type { ReviewProgress } from "./runner-types.ts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Live progress widget for code review.
|
|
8
|
+
*
|
|
9
|
+
* Shows an animated loader, turn count, tool uses, token count,
|
|
10
|
+
* and human-readable activity description.
|
|
11
|
+
*/
|
|
12
|
+
export class ReviewProgressWidget extends Container {
|
|
13
|
+
private _message: string;
|
|
14
|
+
private _progress: ReviewProgress = { turns: 0, toolUses: 0, activities: [] };
|
|
15
|
+
private _loader: CancellableLoader;
|
|
16
|
+
private _tui: TUI;
|
|
17
|
+
private _theme: Theme;
|
|
18
|
+
|
|
19
|
+
constructor(tui: TUI, theme: Theme, message: string) {
|
|
20
|
+
super();
|
|
21
|
+
this._tui = tui;
|
|
22
|
+
this._theme = theme;
|
|
23
|
+
this._message = message;
|
|
24
|
+
this._loader = new CancellableLoader(
|
|
25
|
+
tui,
|
|
26
|
+
(s: string) => theme.fg("accent", s),
|
|
27
|
+
(s: string) => theme.fg("muted", s),
|
|
28
|
+
message,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
this._renderContent();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get signal(): AbortSignal {
|
|
35
|
+
return this._loader.signal;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
set onAbort(fn: (() => void) | undefined) {
|
|
39
|
+
this._loader.onAbort = fn;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
handleInput(data: string): void {
|
|
43
|
+
this._loader.handleInput(data);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Update progress state and re-render. */
|
|
47
|
+
updateProgress(progress: ReviewProgress): void {
|
|
48
|
+
this._progress = progress;
|
|
49
|
+
this._renderContent();
|
|
50
|
+
this._tui.requestRender();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
dispose(): void {
|
|
54
|
+
this._loader.dispose();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private _renderContent(): void {
|
|
58
|
+
this.clear();
|
|
59
|
+
|
|
60
|
+
const { turns, toolUses, activities, tokens } = this._progress;
|
|
61
|
+
|
|
62
|
+
// Build the loader message with stats
|
|
63
|
+
const stats: string[] = [];
|
|
64
|
+
if (turns > 0) stats.push(`⟳${turns}`);
|
|
65
|
+
if (toolUses > 0) stats.push(`${toolUses} tool uses`);
|
|
66
|
+
if (tokens) {
|
|
67
|
+
stats.push(`${formatTokens(tokens.total)} tokens`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const loaderMessage =
|
|
71
|
+
stats.length > 0 ? `${this._message} · ${stats.join(" · ")}` : this._message;
|
|
72
|
+
|
|
73
|
+
this._loader.setMessage(loaderMessage);
|
|
74
|
+
this.addChild(this._loader);
|
|
75
|
+
|
|
76
|
+
// Activity line
|
|
77
|
+
if (activities.length > 0) {
|
|
78
|
+
const activityText = activities.join(", ");
|
|
79
|
+
this.addChild(new Text(this._theme.fg("dim", ` ⎿ ${activityText}…`), 1, 0));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|