@mrclrchtr/supi-debug 4.7.0 → 4.9.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 (26) hide show
  1. package/node_modules/@mrclrchtr/supi-core/README.md +29 -35
  2. package/node_modules/@mrclrchtr/supi-core/package.json +4 -7
  3. package/node_modules/@mrclrchtr/supi-core/src/api.ts +4 -6
  4. package/node_modules/@mrclrchtr/supi-core/src/config/config.ts +0 -20
  5. package/node_modules/@mrclrchtr/supi-core/src/config/prompt-surface.ts +7 -1
  6. package/node_modules/@mrclrchtr/supi-core/src/config.ts +0 -1
  7. package/node_modules/@mrclrchtr/supi-core/src/context.ts +1 -9
  8. package/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +8 -0
  9. package/node_modules/@mrclrchtr/supi-core/src/debug-timing.ts +107 -0
  10. package/node_modules/@mrclrchtr/supi-core/src/index.ts +4 -6
  11. package/node_modules/@mrclrchtr/supi-core/src/settings/settings-registry.ts +54 -28
  12. package/node_modules/@mrclrchtr/supi-core/src/settings/settings-schema.ts +91 -125
  13. package/node_modules/@mrclrchtr/supi-core/src/settings.ts +10 -7
  14. package/package.json +2 -4
  15. package/src/debug.ts +34 -33
  16. package/node_modules/@mrclrchtr/supi-core/src/context/context-messages.ts +0 -119
  17. package/node_modules/@mrclrchtr/supi-core/src/progress-widget.ts +0 -189
  18. package/node_modules/@mrclrchtr/supi-core/src/settings/scoped-settings-list.ts +0 -373
  19. package/node_modules/@mrclrchtr/supi-core/src/settings/settings-action-menu.ts +0 -102
  20. package/node_modules/@mrclrchtr/supi-core/src/settings/settings-command.ts +0 -15
  21. package/node_modules/@mrclrchtr/supi-core/src/settings/settings-submenus.ts +0 -141
  22. package/node_modules/@mrclrchtr/supi-core/src/settings/settings-ui.ts +0 -118
  23. package/node_modules/@mrclrchtr/supi-core/src/settings-ui.ts +0 -3
  24. package/node_modules/@mrclrchtr/supi-core/src/tool-framework.ts +0 -192
  25. package/src/api.ts +0 -1
  26. package/src/index.ts +0 -1
@@ -1,141 +0,0 @@
1
- // Submenu helpers for SuPi settings.
2
- //
3
- // Reusable pi-tui submenu components shared across the settings overlay
4
- // and available to extensions for custom settings controls.
5
-
6
- import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
7
- import {
8
- Container,
9
- Input,
10
- Key,
11
- matchesKey,
12
- type SelectItem,
13
- SelectList,
14
- Text,
15
- } from "@earendil-works/pi-tui";
16
- import { getSelectableModels } from "../model-selection.ts";
17
- import type { ModelPickerField } from "./settings-schema.ts";
18
-
19
- /**
20
- * Creates a pi-tui Input-backed submenu component with enter-to-confirm
21
- * and escape-to-cancel handling.
22
- */
23
- export function createInputSubmenu(
24
- currentValue: string,
25
- label: string,
26
- done: (selectedValue?: string) => void,
27
- ): {
28
- render: (width: number) => string[];
29
- invalidate: () => void;
30
- handleInput: (data: string) => boolean;
31
- } {
32
- const input = new Input();
33
- input.setValue(currentValue);
34
-
35
- return {
36
- render: (_width: number) => {
37
- const lines = [` ${label}`];
38
- lines.push(...input.render(_width));
39
- lines.push(" enter confirm • esc cancel");
40
- return lines;
41
- },
42
- invalidate: () => {
43
- input.invalidate();
44
- },
45
- handleInput: (data: string) => {
46
- if (matchesKey(data, Key.escape)) {
47
- done();
48
- return true;
49
- }
50
- if (matchesKey(data, Key.enter)) {
51
- done(input.getValue());
52
- return true;
53
- }
54
- input.handleInput(data);
55
- return true;
56
- },
57
- };
58
- }
59
-
60
- /**
61
- * Creates a model picker submenu backed by the scoped model set.
62
- *
63
- * The built-in `disabled` choice remains enabled by default. Callers can add
64
- * host-owned static choices or omit `disabled` through the field options.
65
- */
66
- export function createModelPickerSubmenu(
67
- currentValue: string,
68
- done: (selectedValue?: string) => void,
69
- ctx?: ExtensionContext,
70
- options: Pick<ModelPickerField, "includeDisabled" | "staticOptions"> = {},
71
- ): {
72
- render: (width: number) => string[];
73
- invalidate: () => void;
74
- handleInput: (data: string) => boolean;
75
- } {
76
- const items = buildModelItems(ctx, options);
77
- const initialIndex = Math.max(
78
- 0,
79
- items.findIndex((item) => item.value === currentValue),
80
- );
81
-
82
- const container = new Container();
83
- container.addChild(new Text(" Select model", 1, 0));
84
- container.addChild(new Text("", 1, 0));
85
-
86
- const selectList = new SelectList(items, Math.min(items.length, 15), {
87
- selectedPrefix: (t) => `› ${t}`,
88
- selectedText: (t) => t,
89
- description: (t) => t,
90
- scrollInfo: (t) => t,
91
- noMatch: (t) => t,
92
- });
93
- if (initialIndex >= 0) selectList.setSelectedIndex(initialIndex);
94
- selectList.onSelect = (item) => done(item.value);
95
- selectList.onCancel = () => done();
96
-
97
- container.addChild(selectList);
98
- container.addChild(new Text(" ↑↓ navigate • enter select • esc cancel", 1, 0));
99
-
100
- return {
101
- render: (width: number) => container.render(width),
102
- invalidate: () => container.invalidate(),
103
- handleInput: (data: string) => {
104
- selectList.handleInput(data);
105
- return true;
106
- },
107
- };
108
- }
109
-
110
- /** Build static choices followed by the selectable scoped models. */
111
- function buildModelItems(
112
- ctx: ExtensionContext | undefined,
113
- options: Pick<ModelPickerField, "includeDisabled" | "staticOptions">,
114
- ): SelectItem[] {
115
- const items: SelectItem[] = [];
116
- const seen = new Set<string>();
117
- for (const option of options.staticOptions ?? []) {
118
- if (seen.has(option.value)) continue;
119
- items.push({ ...option });
120
- seen.add(option.value);
121
- }
122
-
123
- if (options.includeDisabled !== false && !seen.has("disabled")) {
124
- items.push({ value: "disabled", label: "disabled", description: "No model selected" });
125
- seen.add("disabled");
126
- }
127
-
128
- if (!ctx) return items;
129
- const models = getSelectableModels(ctx);
130
- for (const model of models) {
131
- if (seen.has(model.canonicalId)) continue;
132
- const suffix = model.isCurrent ? " [current]" : "";
133
- items.push({
134
- value: model.canonicalId,
135
- label: `${model.canonicalId}${suffix}`,
136
- description: model.label !== model.canonicalId ? model.label : undefined,
137
- });
138
- seen.add(model.canonicalId);
139
- }
140
- return items;
141
- }
@@ -1,118 +0,0 @@
1
- // Declarative settings overlay for SuPi extensions.
2
- //
3
- // Thin orchestration layer that collects settings contributions and opens the
4
- // scoped settings list inside a pi-tui custom component overlay.
5
-
6
- import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
7
- import { Container, Key, matchesKey, Text } from "@earendil-works/pi-tui";
8
- import { ScopedSettingsList } from "./scoped-settings-list.ts";
9
- import type { SettingsCollectionDiagnostic, SettingsScope } from "./settings-registry.ts";
10
- import {
11
- createSettingsContributionCollector,
12
- SUPI_SETTINGS_COLLECT_EVENT,
13
- } from "./settings-registry.ts";
14
-
15
- // Re-export submenu helpers
16
- export { createInputSubmenu, createModelPickerSubmenu } from "./settings-submenus.ts";
17
-
18
- // ── Overlay ────────────────────────────────────────────────────────────────
19
-
20
- interface OverlayStatus {
21
- kind: "warning" | "error";
22
- message: string;
23
- }
24
-
25
- interface OverlayState {
26
- scope: SettingsScope;
27
- cwd: string;
28
- status?: OverlayStatus;
29
- }
30
-
31
- function getScopeLabel(scope: SettingsScope): string {
32
- return scope === "project" ? "Project" : "Global";
33
- }
34
-
35
- function collectSettingsSections(pi: ExtensionAPI) {
36
- const collector = createSettingsContributionCollector();
37
- pi.events.emit(SUPI_SETTINGS_COLLECT_EVENT, collector);
38
- return collector.result();
39
- }
40
-
41
- function latestStatus(diagnostics: SettingsCollectionDiagnostic[]): OverlayStatus | undefined {
42
- const latest = diagnostics.at(-1);
43
- return latest ? { kind: latest.kind, message: latest.message } : undefined;
44
- }
45
-
46
- export function openSettingsOverlay(pi: ExtensionAPI, ctx: ExtensionContext): void {
47
- const collection = collectSettingsSections(pi);
48
- if (collection.sections.length === 0) {
49
- ctx.ui.notify("No settings registered by SuPi extensions", "info");
50
- return;
51
- }
52
-
53
- void ctx.ui.custom<void>((tui, theme, _kb, done) => {
54
- const state: OverlayState = {
55
- scope: "project",
56
- cwd: ctx.cwd,
57
- status: latestStatus(collection.diagnostics),
58
- };
59
-
60
- const container = new Container();
61
- const scopedList = new ScopedSettingsList(
62
- collection.sections,
63
- state.scope,
64
- state.cwd,
65
- ctx,
66
- theme,
67
- tui,
68
- done,
69
- (message) => {
70
- state.status = { kind: "error", message };
71
- rebuildOverlay();
72
- tui.requestRender();
73
- },
74
- );
75
- scopedList.enableSearch();
76
-
77
- const rebuildOverlay = () => {
78
- container.clear();
79
- const scopeLabel = getScopeLabel(state.scope);
80
- const otherScope = state.scope === "project" ? "Global" : "Project";
81
- container.addChild(
82
- new Text(
83
- `${theme.fg("accent", theme.bold("SuPi Settings"))} ${theme.fg("text", `Scope: ${scopeLabel}`)} ${theme.fg("dim", `(tab → ${otherScope})`)}`,
84
- 0,
85
- 0,
86
- ),
87
- );
88
- if (state.status) {
89
- container.addChild(new Text(theme.fg(state.status.kind, state.status.message), 0, 0));
90
- }
91
- };
92
-
93
- rebuildOverlay();
94
-
95
- const component = {
96
- render: (width: number) => [...container.render(width), ...scopedList.render(width)],
97
- invalidate: () => {
98
- container.invalidate();
99
- scopedList.invalidate();
100
- },
101
- handleInput: (data: string) => {
102
- if (matchesKey(data, Key.tab)) {
103
- state.scope = state.scope === "project" ? "global" : "project";
104
- state.status = undefined;
105
- scopedList.reload(state.scope, state.cwd, ctx);
106
- rebuildOverlay();
107
- tui.requestRender();
108
- return true;
109
- }
110
- scopedList.handleInput(data);
111
- tui.requestRender();
112
- return true;
113
- },
114
- };
115
-
116
- return component;
117
- });
118
- }
@@ -1,3 +0,0 @@
1
- // supi-core settings-ui domain — settings TUI components (imports pi-tui at runtime, heavy).
2
- export { createInputSubmenu, createModelPickerSubmenu } from "./settings/settings-submenus.ts";
3
- export { openSettingsOverlay } from "./settings/settings-ui.ts";
@@ -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
- }
package/src/api.ts DELETED
@@ -1 +0,0 @@
1
- export { default } from "./debug.ts";
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export { default } from "./debug.ts";