@mrclrchtr/supi-settings 4.6.0 → 4.8.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 +8 -6
- package/node_modules/@mrclrchtr/supi-core/README.md +26 -34
- package/node_modules/@mrclrchtr/supi-core/package.json +4 -7
- package/node_modules/@mrclrchtr/supi-core/src/api.ts +4 -6
- package/node_modules/@mrclrchtr/supi-core/src/config/config.ts +0 -20
- package/node_modules/@mrclrchtr/supi-core/src/config/prompt-surface.ts +7 -1
- package/node_modules/@mrclrchtr/supi-core/src/config.ts +0 -1
- package/node_modules/@mrclrchtr/supi-core/src/context.ts +1 -9
- package/node_modules/@mrclrchtr/supi-core/src/index.ts +4 -6
- package/node_modules/@mrclrchtr/supi-core/src/settings/settings-registry.ts +54 -28
- package/node_modules/@mrclrchtr/supi-core/src/settings/settings-schema.ts +91 -125
- package/node_modules/@mrclrchtr/supi-core/src/settings.ts +10 -7
- package/package.json +2 -2
- package/src/api.ts +2 -1
- package/src/extension.ts +5 -2
- package/src/index.ts +1 -1
- package/{node_modules/@mrclrchtr/supi-core/src/settings → src/ui}/scoped-settings-list.ts +112 -93
- package/{node_modules/@mrclrchtr/supi-core/src/settings → src/ui}/settings-action-menu.ts +1 -2
- package/src/ui/settings-module-reader.ts +36 -0
- package/src/ui/settings-row-model.ts +30 -0
- package/{node_modules/@mrclrchtr/supi-core/src/settings → src/ui}/settings-submenus.ts +2 -2
- package/{node_modules/@mrclrchtr/supi-core/src/settings → src/ui}/settings-ui.ts +43 -34
- package/node_modules/@mrclrchtr/supi-core/src/context/context-messages.ts +0 -119
- package/node_modules/@mrclrchtr/supi-core/src/progress-widget.ts +0 -189
- package/node_modules/@mrclrchtr/supi-core/src/settings/settings-command.ts +0 -15
- package/node_modules/@mrclrchtr/supi-core/src/settings-ui.ts +0 -3
- package/node_modules/@mrclrchtr/supi-core/src/tool-framework.ts +0 -192
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
// Shared context-message utilities for SuPi extensions.
|
|
2
|
-
//
|
|
3
|
-
// Provides a generic prune-and-reorder pattern for extensions that inject
|
|
4
|
-
// managed context messages (via `before_agent_start` with a `customType` and
|
|
5
|
-
// `contextToken`) and maintain them via the `context` event.
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Minimal message shape needed for context-message operations.
|
|
9
|
-
* Extensions cast their event.messages entries to this type.
|
|
10
|
-
*/
|
|
11
|
-
export type ContextMessageLike = {
|
|
12
|
-
role?: string;
|
|
13
|
-
customType?: string;
|
|
14
|
-
content?: unknown;
|
|
15
|
-
details?: unknown;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Extract the `contextToken` string from a message's `details` object.
|
|
20
|
-
* Returns `null` when the token is absent or not a string.
|
|
21
|
-
*/
|
|
22
|
-
export function getContextToken(details: unknown): string | null {
|
|
23
|
-
if (!details || typeof details !== "object") return null;
|
|
24
|
-
const token = (details as { contextToken?: unknown }).contextToken;
|
|
25
|
-
return typeof token === "string" ? token : null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Find the index of the last message with `role: "user"`.
|
|
30
|
-
* Returns `-1` when no user message exists.
|
|
31
|
-
*/
|
|
32
|
-
export function findLastUserMessageIndex<T extends ContextMessageLike>(messages: T[]): number {
|
|
33
|
-
for (let index = messages.length - 1; index >= 0; index--) {
|
|
34
|
-
if (messages[index]?.role === "user") return index;
|
|
35
|
-
}
|
|
36
|
-
return -1;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Filter stale context messages and reorder the active one before the last user message.
|
|
41
|
-
*
|
|
42
|
-
* - Removes all messages matching `customType` whose token differs from `activeToken`.
|
|
43
|
-
* - When `activeToken` is `null`, removes **all** messages of that `customType`.
|
|
44
|
-
* - If the active context message is after the last user message, moves it before.
|
|
45
|
-
*
|
|
46
|
-
* Returns the modified array, or the original reference when no changes were needed.
|
|
47
|
-
*/
|
|
48
|
-
export function pruneAndReorderContextMessages<T extends ContextMessageLike>(
|
|
49
|
-
messages: T[],
|
|
50
|
-
customType: string,
|
|
51
|
-
activeToken: string | null,
|
|
52
|
-
): T[] {
|
|
53
|
-
// Remove stale messages of the target customType
|
|
54
|
-
const filtered = messages.filter((message) => {
|
|
55
|
-
if (message.customType !== customType) return true;
|
|
56
|
-
if (!activeToken) return false;
|
|
57
|
-
return getContextToken(message.details) === activeToken;
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
if (!activeToken) return filtered;
|
|
61
|
-
|
|
62
|
-
// Find the active context message
|
|
63
|
-
const contextIndex = filtered.findIndex(
|
|
64
|
-
(message) =>
|
|
65
|
-
message.customType === customType && getContextToken(message.details) === activeToken,
|
|
66
|
-
);
|
|
67
|
-
if (contextIndex === -1) return filtered;
|
|
68
|
-
|
|
69
|
-
// Find the last user message
|
|
70
|
-
const userIndex = findLastUserMessageIndex(filtered);
|
|
71
|
-
if (userIndex === -1 || contextIndex < userIndex) return filtered;
|
|
72
|
-
|
|
73
|
-
// Move context message before last user message
|
|
74
|
-
const next = [...filtered];
|
|
75
|
-
const [contextMessage] = next.splice(contextIndex, 1);
|
|
76
|
-
if (!contextMessage) return filtered;
|
|
77
|
-
next.splice(userIndex, 0, contextMessage);
|
|
78
|
-
return next;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Restore the raw prompt content on a context message that was swapped for display text.
|
|
83
|
-
*
|
|
84
|
-
* Extensions using `registerMessageRenderer` store their LLM-facing content in
|
|
85
|
-
* `details.promptContent` and put a human-readable summary in `content`. This function
|
|
86
|
-
* reverses the swap so the model sees the original prompt content.
|
|
87
|
-
*
|
|
88
|
-
* Returns the original array reference when no change is needed.
|
|
89
|
-
*/
|
|
90
|
-
export function restorePromptContent<T extends ContextMessageLike>(
|
|
91
|
-
messages: T[],
|
|
92
|
-
customType: string,
|
|
93
|
-
activeToken: string | null,
|
|
94
|
-
): T[] {
|
|
95
|
-
if (!activeToken) return messages;
|
|
96
|
-
|
|
97
|
-
const index = messages.findIndex(
|
|
98
|
-
(message) =>
|
|
99
|
-
message.customType === customType && getContextToken(message.details) === activeToken,
|
|
100
|
-
);
|
|
101
|
-
if (index === -1) return messages;
|
|
102
|
-
|
|
103
|
-
const promptContent = getPromptContent(messages[index]?.details);
|
|
104
|
-
if (!promptContent || messages[index]?.content === promptContent) return messages;
|
|
105
|
-
|
|
106
|
-
const next = [...messages];
|
|
107
|
-
next[index] = { ...next[index], content: promptContent };
|
|
108
|
-
return next;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Extract the `promptContent` string from a message's `details` object.
|
|
113
|
-
* Returns `null` when absent or not a string.
|
|
114
|
-
*/
|
|
115
|
-
export function getPromptContent(details: unknown): string | null {
|
|
116
|
-
if (!details || typeof details !== "object") return null;
|
|
117
|
-
const promptContent = (details as { promptContent?: unknown }).promptContent;
|
|
118
|
-
return typeof promptContent === "string" ? promptContent : null;
|
|
119
|
-
}
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
// Generic progress widget for SuPi long-running operations.
|
|
2
|
-
//
|
|
3
|
-
// Provides a TUI-based progress display with animated loader, turn counts,
|
|
4
|
-
// tool usage, and activity descriptions.
|
|
5
|
-
|
|
6
|
-
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
7
|
-
import { CancellableLoader, Container, Text } from "@earendil-works/pi-tui";
|
|
8
|
-
|
|
9
|
-
// ── Types ──────────────────────────────────────────────────────────────────
|
|
10
|
-
|
|
11
|
-
/** What the reviewer is currently doing and on what. */
|
|
12
|
-
export interface CurrentFocus {
|
|
13
|
-
/** Display label for the active tool (e.g. "Reading", "Searching", "Finding"). */
|
|
14
|
-
label: string;
|
|
15
|
-
/** Context detail (e.g. file path, search pattern, directory). */
|
|
16
|
-
detail: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** Progress state for widget display, compatible with child-session updates. */
|
|
20
|
-
export interface WidgetProgress {
|
|
21
|
-
/** Number of agent turns completed. */
|
|
22
|
-
turns: number;
|
|
23
|
-
/** Number of tool executions started. */
|
|
24
|
-
toolUses: number;
|
|
25
|
-
/** Token usage stats, if available. */
|
|
26
|
-
tokens?: {
|
|
27
|
-
input: number;
|
|
28
|
-
output: number;
|
|
29
|
-
total: number;
|
|
30
|
-
cacheRead?: number;
|
|
31
|
-
cacheWrite?: number;
|
|
32
|
-
};
|
|
33
|
-
/** Per-tool execution counts keyed by short display label (e.g. "diffs", "reads", "greps"). */
|
|
34
|
-
toolCounts?: Record<string, number>;
|
|
35
|
-
/** Number of distinct files inspected so far (via read_snapshot_diff / read_snapshot_file). */
|
|
36
|
-
filesInspected?: number;
|
|
37
|
-
/** Total files in the review snapshot. */
|
|
38
|
-
filesTotal?: number;
|
|
39
|
-
/** Current tool + context for the progress narrative line. */
|
|
40
|
-
currentFocus?: CurrentFocus;
|
|
41
|
-
/** Elapsed time in milliseconds since the operation started. */
|
|
42
|
-
elapsedMs?: number;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// ── Widget ─────────────────────────────────────────────────────────────────
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* TUI progress widget for long-running operations.
|
|
49
|
-
*
|
|
50
|
-
* Two-line layout: top line shows the narrative (current focus + file progress),
|
|
51
|
-
* bottom line shows stats (tokens, elapsed time, turns, tool counts).
|
|
52
|
-
*/
|
|
53
|
-
export class ProgressWidget extends Container {
|
|
54
|
-
private message: string;
|
|
55
|
-
private progress: WidgetProgress = { turns: 0, toolUses: 0 };
|
|
56
|
-
private loader: CancellableLoader;
|
|
57
|
-
private tui: { requestRender(): void };
|
|
58
|
-
private theme: Theme;
|
|
59
|
-
|
|
60
|
-
constructor(tui: { requestRender(): void }, theme: Theme, message: string) {
|
|
61
|
-
super();
|
|
62
|
-
this.tui = tui;
|
|
63
|
-
this.theme = theme;
|
|
64
|
-
this.message = message;
|
|
65
|
-
this.loader = new CancellableLoader(
|
|
66
|
-
tui as ConstructorParameters<typeof CancellableLoader>[0],
|
|
67
|
-
(text: string) => theme.fg("accent", text),
|
|
68
|
-
(text: string) => theme.fg("muted", text),
|
|
69
|
-
message,
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
this.renderContent();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** AbortSignal that fires when the user presses Escape. */
|
|
76
|
-
get signal(): AbortSignal {
|
|
77
|
-
return this.loader.signal;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** Callback invoked when the user presses Escape. */
|
|
81
|
-
set onAbort(fn: (() => void) | undefined) {
|
|
82
|
-
this.loader.onAbort = fn;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/** Delegate keyboard input to the loader. */
|
|
86
|
-
handleInput(data: string): void {
|
|
87
|
-
this.loader.handleInput(data);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/** Update progress state and request a re-render. */
|
|
91
|
-
updateProgress(progress: WidgetProgress): void {
|
|
92
|
-
this.progress = progress;
|
|
93
|
-
this.renderContent();
|
|
94
|
-
this.tui.requestRender();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/** Clean up the widget. */
|
|
98
|
-
dispose(): void {
|
|
99
|
-
this.loader.dispose();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
private renderContent(): void {
|
|
103
|
-
this.clear();
|
|
104
|
-
this.renderTopLine();
|
|
105
|
-
this.renderBottomLine();
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
private renderTopLine(): void {
|
|
109
|
-
const topParts: string[] = [];
|
|
110
|
-
|
|
111
|
-
if (this.progress.currentFocus) {
|
|
112
|
-
const { label, detail } = this.progress.currentFocus;
|
|
113
|
-
topParts.push(detail ? `${label}: ${detail}` : label);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (this.progress.filesTotal && this.progress.filesTotal > 0) {
|
|
117
|
-
const inspected = this.progress.filesInspected ?? 0;
|
|
118
|
-
topParts.push(`${inspected}/${this.progress.filesTotal} files`);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const loaderMessage =
|
|
122
|
-
topParts.length > 0 ? `${this.message} · ${topParts.join(" · ")}` : this.message;
|
|
123
|
-
this.loader.setMessage(loaderMessage);
|
|
124
|
-
this.addChild(this.loader);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
private renderBottomLine(): void {
|
|
128
|
-
const stats: string[] = [];
|
|
129
|
-
|
|
130
|
-
this.appendTokenStats(stats);
|
|
131
|
-
|
|
132
|
-
if (this.progress.elapsedMs !== undefined && this.progress.elapsedMs >= 1000) {
|
|
133
|
-
stats.push(formatElapsed(this.progress.elapsedMs));
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (this.progress.turns > 0) {
|
|
137
|
-
stats.push(`⟳ ${this.progress.turns}`);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (this.progress.toolCounts) {
|
|
141
|
-
const parts = Object.entries(this.progress.toolCounts)
|
|
142
|
-
.filter(([, count]) => count > 0)
|
|
143
|
-
.sort(([, a], [, b]) => b - a)
|
|
144
|
-
.map(([label, count]) => `${count} ${label}`);
|
|
145
|
-
if (parts.length > 0) stats.push(parts.join(" · "));
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (stats.length > 0) {
|
|
149
|
-
this.addChild(new Text(this.theme.fg("dim", ` ${stats.join(" · ")}`), 1, 0));
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
private appendTokenStats(stats: string[]): void {
|
|
154
|
-
const tokens = this.progress.tokens;
|
|
155
|
-
if (!tokens) return;
|
|
156
|
-
|
|
157
|
-
stats.push(`↑ ${formatTokens(tokens.input)}`);
|
|
158
|
-
if (tokens.cacheRead !== undefined && tokens.cacheRead > 0) {
|
|
159
|
-
stats.push(`↲ ${formatTokens(tokens.cacheRead)}`);
|
|
160
|
-
}
|
|
161
|
-
if (tokens.cacheWrite !== undefined && tokens.cacheWrite > 0) {
|
|
162
|
-
stats.push(`↱ ${formatTokens(tokens.cacheWrite)}`);
|
|
163
|
-
}
|
|
164
|
-
stats.push(`↓ ${formatTokens(tokens.output)}`);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// ── Helpers ────────────────────────────────────────────────────────────────
|
|
169
|
-
|
|
170
|
-
export function formatTokens(count: number): string {
|
|
171
|
-
if (count >= 1_000_000) return `${(count / 1_000_000).toFixed(1)}M`;
|
|
172
|
-
if (count >= 1_000) return `${(count / 1_000).toFixed(1)}k`;
|
|
173
|
-
return String(count);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export function formatElapsed(ms: number): string {
|
|
177
|
-
const totalSec = Math.floor(ms / 1000);
|
|
178
|
-
const hours = Math.floor(totalSec / 3600);
|
|
179
|
-
const minutes = Math.floor((totalSec % 3600) / 60);
|
|
180
|
-
const seconds = totalSec % 60;
|
|
181
|
-
|
|
182
|
-
if (hours > 0) {
|
|
183
|
-
return `${hours}h ${minutes}m ${seconds}s`;
|
|
184
|
-
}
|
|
185
|
-
if (minutes > 0) {
|
|
186
|
-
return `${minutes}m ${seconds}s`;
|
|
187
|
-
}
|
|
188
|
-
return `${seconds}s`;
|
|
189
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// /supi-settings command registration.
|
|
2
|
-
//
|
|
3
|
-
// Thin wrapper that registers the command and delegates to openSettingsOverlay.
|
|
4
|
-
|
|
5
|
-
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
6
|
-
import { openSettingsOverlay } from "./settings-ui.ts";
|
|
7
|
-
|
|
8
|
-
export function registerSettingsCommand(pi: ExtensionAPI): void {
|
|
9
|
-
pi.registerCommand("supi-settings", {
|
|
10
|
-
description: "Manage SuPi extension settings",
|
|
11
|
-
handler: async (_args, ctx) => {
|
|
12
|
-
openSettingsOverlay(pi, ctx);
|
|
13
|
-
},
|
|
14
|
-
});
|
|
15
|
-
}
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
// Shared tool framework for SuPi extensions.
|
|
2
|
-
//
|
|
3
|
-
// Provides a standard ToolSpec→PromptSurface→registerTool pipeline so
|
|
4
|
-
// individual packages do not duplicate spec interfaces, guidance derivation,
|
|
5
|
-
// registration loops, or common TypeBox parameter schemas.
|
|
6
|
-
|
|
7
|
-
import type {
|
|
8
|
-
AgentToolResult,
|
|
9
|
-
AgentToolUpdateCallback,
|
|
10
|
-
ExtensionAPI,
|
|
11
|
-
ExtensionCommandContext,
|
|
12
|
-
ExtensionContext,
|
|
13
|
-
} from "@earendil-works/pi-coding-agent";
|
|
14
|
-
import { type TSchema, Type } from "typebox";
|
|
15
|
-
import { ProgressWidget, type WidgetProgress } from "./progress-widget.ts";
|
|
16
|
-
|
|
17
|
-
// ---------------------------------------------------------------------------
|
|
18
|
-
// Types
|
|
19
|
-
// ---------------------------------------------------------------------------
|
|
20
|
-
|
|
21
|
-
/** Minimum contract for a SuPi tool definition. */
|
|
22
|
-
export interface SuiPiToolSpec {
|
|
23
|
-
name: string;
|
|
24
|
-
label: string;
|
|
25
|
-
description: string;
|
|
26
|
-
promptSnippet: string;
|
|
27
|
-
promptGuidelines: string[];
|
|
28
|
-
parameters: TSchema;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** Derived prompt surface — what pi flattens into the system prompt. */
|
|
32
|
-
export interface SuiPiToolPromptSurface {
|
|
33
|
-
description: string;
|
|
34
|
-
promptSnippet: string;
|
|
35
|
-
promptGuidelines: string[];
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// ---------------------------------------------------------------------------
|
|
39
|
-
// Guidance derivation
|
|
40
|
-
// ---------------------------------------------------------------------------
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Static derivation: copies spec fields into a prompt surface.
|
|
44
|
-
*
|
|
45
|
-
* Packages that need dynamic guidance (e.g. server-coverage injection) should
|
|
46
|
-
* build their own surfaces, optionally starting from the output of this helper.
|
|
47
|
-
*/
|
|
48
|
-
export function derivePromptSurface(spec: SuiPiToolSpec): SuiPiToolPromptSurface {
|
|
49
|
-
return {
|
|
50
|
-
description: spec.description,
|
|
51
|
-
promptSnippet: spec.promptSnippet,
|
|
52
|
-
promptGuidelines: [...spec.promptGuidelines],
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Re-export prompt-surface types (implemented in config/prompt-surface.ts)
|
|
57
|
-
export {
|
|
58
|
-
notifyToolPromptSurfaceDiagnostics,
|
|
59
|
-
type ResolveToolPromptSurfaceOptions,
|
|
60
|
-
type ResolveToolPromptSurfaceResult,
|
|
61
|
-
resolveToolPromptSurface,
|
|
62
|
-
type ToolPromptSurfaceDiagnostic,
|
|
63
|
-
type ToolPromptSurfaceDiagnosticCode,
|
|
64
|
-
} from "./config/prompt-surface.ts";
|
|
65
|
-
|
|
66
|
-
// ---------------------------------------------------------------------------
|
|
67
|
-
// Registration
|
|
68
|
-
// ---------------------------------------------------------------------------
|
|
69
|
-
|
|
70
|
-
// biome-ignore lint/complexity/useMaxParams: matches pi ToolDefinition.execute signature
|
|
71
|
-
export type ToolExecuteFn = (
|
|
72
|
-
toolCallId: string,
|
|
73
|
-
params: unknown,
|
|
74
|
-
signal: AbortSignal | undefined,
|
|
75
|
-
onUpdate: AgentToolUpdateCallback<Record<string, unknown>> | undefined,
|
|
76
|
-
ctx: ExtensionContext,
|
|
77
|
-
) => Promise<AgentToolResult<Record<string, unknown>>>;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Register a set of tools from specs + pre-derived surfaces.
|
|
81
|
-
*
|
|
82
|
-
* `createExecute` receives the spec and returns a pi-compatible execute
|
|
83
|
-
* function. This keeps execute-logic package-local while the framework owns
|
|
84
|
-
* the declarative surface and registration boilerplate.
|
|
85
|
-
*/
|
|
86
|
-
export function registerSuiPiTools(
|
|
87
|
-
pi: ExtensionAPI,
|
|
88
|
-
specs: readonly SuiPiToolSpec[],
|
|
89
|
-
surfaces: Record<string, SuiPiToolPromptSurface>,
|
|
90
|
-
createExecute: (spec: SuiPiToolSpec) => ToolExecuteFn,
|
|
91
|
-
): void {
|
|
92
|
-
for (const spec of specs) {
|
|
93
|
-
const surface = surfaces[spec.name];
|
|
94
|
-
pi.registerTool({
|
|
95
|
-
name: spec.name,
|
|
96
|
-
label: spec.label,
|
|
97
|
-
description: surface?.description ?? spec.description,
|
|
98
|
-
promptSnippet: surface?.promptSnippet ?? spec.promptSnippet,
|
|
99
|
-
promptGuidelines: surface?.promptGuidelines ?? [...spec.promptGuidelines],
|
|
100
|
-
parameters: spec.parameters,
|
|
101
|
-
execute: createExecute(spec),
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// ---------------------------------------------------------------------------
|
|
107
|
-
// Shared parameter builders
|
|
108
|
-
// ---------------------------------------------------------------------------
|
|
109
|
-
|
|
110
|
-
/** File path (relative or absolute). */
|
|
111
|
-
export const FileParam = Type.String({ description: "File path (relative or absolute)" });
|
|
112
|
-
|
|
113
|
-
/** 1-based line number. */
|
|
114
|
-
export const LineParam = Type.Number({ description: "1-based line number", minimum: 1 });
|
|
115
|
-
|
|
116
|
-
/** 1-based character column (UTF-16). */
|
|
117
|
-
export const CharacterParam = Type.Number({
|
|
118
|
-
description: "1-based column number (UTF-16)",
|
|
119
|
-
minimum: 1,
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
/** Symbol name for discovery-based resolution. */
|
|
123
|
-
export const SymbolParam = Type.String({
|
|
124
|
-
description: "Symbol name for discovery-based resolution",
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
/** Maximum results to return. */
|
|
128
|
-
export const MaxResultsParam = Type.Number({ description: "Maximum results to return" });
|
|
129
|
-
|
|
130
|
-
// ---------------------------------------------------------------------------
|
|
131
|
-
// Progress widget runner
|
|
132
|
-
// ---------------------------------------------------------------------------
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Run an async operation with a live TUI progress widget.
|
|
136
|
-
*
|
|
137
|
-
* Automatically manages:
|
|
138
|
-
* - The {@link ProgressWidget} lifecycle
|
|
139
|
-
* - `supi:working:start` / `supi:working:end` events for tab-spinner integration
|
|
140
|
-
* - Abort signal handling
|
|
141
|
-
* - Error catching (returns `null` on failure)
|
|
142
|
-
*
|
|
143
|
-
* Falls back to running without a widget when `ctx.hasUI` is false.
|
|
144
|
-
*
|
|
145
|
-
* @param pi - The extension API (for event emission).
|
|
146
|
-
* @param ctx - The command context (for UI access and hasUI check).
|
|
147
|
-
* @param title - The progress widget title.
|
|
148
|
-
* @param runner - Async function that receives (signal, onProgress).
|
|
149
|
-
* @returns The runner result, or `null` on cancel/error.
|
|
150
|
-
*/
|
|
151
|
-
export async function runWithProgressWidget<T>(
|
|
152
|
-
pi: ExtensionAPI,
|
|
153
|
-
ctx: ExtensionCommandContext,
|
|
154
|
-
title: string,
|
|
155
|
-
runner: (signal: AbortSignal, onProgress: (p: WidgetProgress) => void) => Promise<T>,
|
|
156
|
-
): Promise<T | null> {
|
|
157
|
-
if (!ctx.hasUI) {
|
|
158
|
-
// No UI — run without progress widget but still emit working events
|
|
159
|
-
pi.events.emit("supi:working:start", { source: "supi-core" });
|
|
160
|
-
try {
|
|
161
|
-
return await runner(new AbortController().signal, () => {});
|
|
162
|
-
} catch {
|
|
163
|
-
return null;
|
|
164
|
-
} finally {
|
|
165
|
-
pi.events.emit("supi:working:end", { source: "supi-core" });
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return ctx.ui.custom<T | null>((tui, theme, _kb, done) => {
|
|
170
|
-
const widget = new ProgressWidget(tui, theme, title);
|
|
171
|
-
let finished = false;
|
|
172
|
-
|
|
173
|
-
const finish = (result: T | null) => {
|
|
174
|
-
if (finished) return;
|
|
175
|
-
finished = true;
|
|
176
|
-
pi.events.emit("supi:working:end", { source: "supi-core" });
|
|
177
|
-
widget.dispose();
|
|
178
|
-
done(result);
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
widget.onAbort = () => {
|
|
182
|
-
// Widget handles abort signal; runner resolves with cancel/error.
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
pi.events.emit("supi:working:start", { source: "supi-core" });
|
|
186
|
-
runner(widget.signal, (progress) => widget.updateProgress(progress))
|
|
187
|
-
.then((result) => finish(result))
|
|
188
|
-
.catch(() => finish(null));
|
|
189
|
-
|
|
190
|
-
return widget;
|
|
191
|
-
});
|
|
192
|
-
}
|