@mrclrchtr/supi-extras 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.
Files changed (25) hide show
  1. package/README.md +1 -5
  2. package/node_modules/@mrclrchtr/supi-core/README.md +26 -34
  3. package/node_modules/@mrclrchtr/supi-core/package.json +4 -7
  4. package/node_modules/@mrclrchtr/supi-core/src/api.ts +4 -6
  5. package/node_modules/@mrclrchtr/supi-core/src/config/config.ts +0 -20
  6. package/node_modules/@mrclrchtr/supi-core/src/config/prompt-surface.ts +7 -1
  7. package/node_modules/@mrclrchtr/supi-core/src/config.ts +0 -1
  8. package/node_modules/@mrclrchtr/supi-core/src/context.ts +1 -9
  9. package/node_modules/@mrclrchtr/supi-core/src/index.ts +4 -6
  10. package/node_modules/@mrclrchtr/supi-core/src/settings/settings-registry.ts +54 -28
  11. package/node_modules/@mrclrchtr/supi-core/src/settings/settings-schema.ts +91 -125
  12. package/node_modules/@mrclrchtr/supi-core/src/settings.ts +10 -7
  13. package/package.json +2 -4
  14. package/src/index.ts +0 -2
  15. package/node_modules/@mrclrchtr/supi-core/src/context/context-messages.ts +0 -119
  16. package/node_modules/@mrclrchtr/supi-core/src/progress-widget.ts +0 -189
  17. package/node_modules/@mrclrchtr/supi-core/src/settings/scoped-settings-list.ts +0 -373
  18. package/node_modules/@mrclrchtr/supi-core/src/settings/settings-action-menu.ts +0 -102
  19. package/node_modules/@mrclrchtr/supi-core/src/settings/settings-command.ts +0 -15
  20. package/node_modules/@mrclrchtr/supi-core/src/settings/settings-submenus.ts +0 -141
  21. package/node_modules/@mrclrchtr/supi-core/src/settings/settings-ui.ts +0 -118
  22. package/node_modules/@mrclrchtr/supi-core/src/settings-ui.ts +0 -3
  23. package/node_modules/@mrclrchtr/supi-core/src/tool-framework.ts +0 -192
  24. package/src/api.ts +0 -1
  25. package/src/skill-shortcut.ts +0 -123
@@ -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 "./index.ts";
@@ -1,123 +0,0 @@
1
- import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
- import { fuzzyFilter } from "@earendil-works/pi-tui";
3
-
4
- /**
5
- * Extension: `$` as a shortcut prefix for skills.
6
- *
7
- * - `$agent-browser` expands to `/skill:agent-browser`
8
- * - Autocomplete triggers on `$` showing only skill names
9
- * - Works anywhere in the prompt (after space or at start)
10
- */
11
-
12
- const DELIMITERS = new Set([" ", "\t", "\n"]);
13
-
14
- /** Find the `$token` at the cursor, or null if not in one. */
15
- function extractDollarPrefix(textBeforeCursor: string): string | null {
16
- // Walk backwards to find the start of the current token
17
- for (let i = textBeforeCursor.length - 1; i >= 0; i--) {
18
- const char = textBeforeCursor[i];
19
- if (char && DELIMITERS.has(char)) {
20
- // Hit a delimiter — the token starts at i+1
21
- const token = textBeforeCursor.slice(i + 1);
22
- return token.startsWith("$") ? token : null;
23
- }
24
- }
25
- // Reached start of line
26
- return textBeforeCursor.startsWith("$") ? textBeforeCursor : null;
27
- }
28
-
29
- // ── Extension entry point ─────────────────────────────────────────
30
-
31
- /**
32
- * Register `$skill-name` → `/skill:skill-name` expansion and autocomplete.
33
- *
34
- * ## Behavior gotchas
35
- *
36
- * - Installed skill names are snapshotted at `session_start` via
37
- * `pi.getCommands()`; after adding or removing skills, use `/reload` or
38
- * start a new session before testing expansion behavior.
39
- * - Outside `$...` tokens, autocomplete must delegate back to the current
40
- * provider so built-in completion and file completion continue to work.
41
- *
42
- * ## Testing
43
- *
44
- * If behavior changes, test both:
45
- * - expansion inside `$...` tokens
46
- * - normal autocomplete everywhere else
47
- */
48
- export default function (pi: ExtensionAPI) {
49
- let skillNames: string[] = [];
50
- let skillCommands: { name: string; description?: string }[] = [];
51
-
52
- pi.on("session_start", (_event, ctx) => {
53
- const commands = pi.getCommands();
54
- skillCommands = commands
55
- .filter((c) => c.source === "skill")
56
- .map((c) => ({
57
- name: c.name.replace(/^skill:/, ""),
58
- description: c.description,
59
- }));
60
- skillNames = skillCommands.map((c) => c.name);
61
-
62
- // Stack skill autocomplete on top of the built-in provider.
63
- // addAutocompleteProvider takes a wrapper callback: (current) => provider.
64
- ctx.ui.addAutocompleteProvider((current) => ({
65
- triggerCharacters: ["$"],
66
- async getSuggestions(lines, cursorLine, cursorCol, options) {
67
- const textBeforeCursor = (lines[cursorLine] || "").slice(0, cursorCol);
68
- const dollarPrefix = extractDollarPrefix(textBeforeCursor);
69
-
70
- if (!dollarPrefix || dollarPrefix.includes(" ")) {
71
- return current.getSuggestions(lines, cursorLine, cursorCol, options);
72
- }
73
-
74
- const query = dollarPrefix.slice(1);
75
- const items = skillCommands.map((c) => ({
76
- name: c.name,
77
- description: c.description,
78
- }));
79
- const filtered = fuzzyFilter(items, query, (i) => i.name).map((i) => ({
80
- value: i.name,
81
- label: i.name,
82
- ...(i.description && { description: i.description }),
83
- }));
84
- return filtered.length
85
- ? { items: filtered, prefix: dollarPrefix }
86
- : current.getSuggestions(lines, cursorLine, cursorCol, options);
87
- },
88
- // biome-ignore lint/complexity/useMaxParams: AutocompleteProvider interface
89
- applyCompletion(lines, cursorLine, cursorCol, item, prefix) {
90
- if (prefix.startsWith("$")) {
91
- const line = lines[cursorLine] || "";
92
- const before = line.slice(0, cursorCol - prefix.length);
93
- const after = line.slice(cursorCol);
94
- const newLine = `${before}$${item.value} ${after}`;
95
- return {
96
- lines: [...lines.slice(0, cursorLine), newLine, ...lines.slice(cursorLine + 1)],
97
- cursorLine,
98
- cursorCol: before.length + 1 + item.value.length + 1,
99
- };
100
- }
101
- return current.applyCompletion(lines, cursorLine, cursorCol, item, prefix);
102
- },
103
- shouldTriggerFileCompletion(lines, cursorLine, cursorCol) {
104
- return current.shouldTriggerFileCompletion?.(lines, cursorLine, cursorCol) ?? true;
105
- },
106
- }));
107
- });
108
-
109
- // Transform $skill-name → /skill:skill-name before agent processing
110
- pi.on("input", (event) => {
111
- const text = event.text.trim();
112
-
113
- // Find all $skill-name tokens and replace them
114
- const transformed = text.replace(/(?:^|(?<=\s))\$([a-z0-9][-a-z0-9]*)/g, (_match, name) => {
115
- return skillNames.includes(name) ? `/skill:${name}` : _match;
116
- });
117
-
118
- if (transformed !== text) {
119
- return { action: "transform" as const, text: transformed };
120
- }
121
- return { action: "continue" as const };
122
- });
123
- }