@mrclrchtr/supi-lsp 2.0.6 → 2.2.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 (39) hide show
  1. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/README.md +32 -23
  2. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/package.json +2 -1
  3. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/config/config.ts +22 -8
  4. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/config/prompt-surface.ts +357 -0
  5. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/config.ts +2 -3
  6. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +0 -5
  7. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/prompt-surface.ts +4 -0
  8. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/settings/scoped-settings-list.ts +372 -0
  9. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/settings/settings-action-menu.ts +101 -0
  10. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/settings/settings-command.ts +1 -1
  11. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/settings/settings-registry.ts +55 -27
  12. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/settings/settings-schema.ts +464 -0
  13. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/settings/settings-submenus.ts +124 -0
  14. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/settings/settings-ui.ts +72 -285
  15. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/settings-ui.ts +2 -5
  16. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/settings.ts +27 -5
  17. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/tool-framework.ts +10 -0
  18. package/node_modules/@mrclrchtr/supi-code-runtime/package.json +2 -2
  19. package/node_modules/@mrclrchtr/supi-core/README.md +32 -23
  20. package/node_modules/@mrclrchtr/supi-core/package.json +2 -1
  21. package/node_modules/@mrclrchtr/supi-core/src/config/config.ts +22 -8
  22. package/node_modules/@mrclrchtr/supi-core/src/config/prompt-surface.ts +357 -0
  23. package/node_modules/@mrclrchtr/supi-core/src/config.ts +2 -3
  24. package/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +0 -5
  25. package/node_modules/@mrclrchtr/supi-core/src/prompt-surface.ts +4 -0
  26. package/node_modules/@mrclrchtr/supi-core/src/settings/scoped-settings-list.ts +372 -0
  27. package/node_modules/@mrclrchtr/supi-core/src/settings/settings-action-menu.ts +101 -0
  28. package/node_modules/@mrclrchtr/supi-core/src/settings/settings-command.ts +1 -1
  29. package/node_modules/@mrclrchtr/supi-core/src/settings/settings-registry.ts +55 -27
  30. package/node_modules/@mrclrchtr/supi-core/src/settings/settings-schema.ts +464 -0
  31. package/node_modules/@mrclrchtr/supi-core/src/settings/settings-submenus.ts +124 -0
  32. package/node_modules/@mrclrchtr/supi-core/src/settings/settings-ui.ts +72 -285
  33. package/node_modules/@mrclrchtr/supi-core/src/settings-ui.ts +2 -5
  34. package/node_modules/@mrclrchtr/supi-core/src/settings.ts +27 -5
  35. package/node_modules/@mrclrchtr/supi-core/src/tool-framework.ts +10 -0
  36. package/package.json +3 -3
  37. package/src/config/lsp-settings.ts +1 -1
  38. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/config/config-settings.ts +0 -188
  39. package/node_modules/@mrclrchtr/supi-core/src/config/config-settings.ts +0 -188
@@ -1,327 +1,114 @@
1
- // Generic settings overlay for SuPi extensions.
1
+ // Declarative settings overlay for SuPi extensions.
2
2
  //
3
- // Uses pi-tui's SettingsList with scope toggle (Tab), extension grouping,
4
- // and search. Each extension declares its settings via registerSettings().
3
+ // Thin orchestration layer that collects settings contributions and opens the
4
+ // scoped settings list inside a pi-tui custom component overlay.
5
5
 
6
- import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
7
- import { getSettingsListTheme } from "@earendil-works/pi-coding-agent";
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";
8
10
  import {
9
- Container,
10
- Input,
11
- Key,
12
- matchesKey,
13
- type SelectItem,
14
- SelectList,
15
- type SelectListTheme,
16
- type SettingItem,
17
- SettingsList,
18
- Text,
19
- } from "@earendil-works/pi-tui";
20
- import { getSelectableModels } from "../model-selection.ts";
21
- import {
22
- getRegisteredSettings,
23
- type SettingsScope,
24
- type SettingsSection,
11
+ createSettingsContributionCollector,
12
+ SUPI_SETTINGS_COLLECT_EVENT,
25
13
  } from "./settings-registry.ts";
26
14
 
27
- // ── Input submenu component ──────────────────────────────────
15
+ // Re-export submenu helpers
16
+ export { createInputSubmenu, createModelPickerSubmenu } from "./settings-submenus.ts";
28
17
 
29
- /**
30
- * Creates a pi-tui Input-backed submenu component with enter-to-confirm
31
- * and escape-to-cancel handling.
32
- *
33
- * @param currentValue - Initial value for the text input.
34
- * @param label - Label text displayed above the input.
35
- * @param done - Callback invoked with the confirmed value, or undefined on cancel.
36
- */
37
- export function createInputSubmenu(
38
- currentValue: string,
39
- label: string,
40
- done: (selectedValue?: string) => void,
41
- ): {
42
- render: (width: number) => string[];
43
- invalidate: () => void;
44
- handleInput: (data: string) => boolean;
45
- } {
46
- const input = new Input();
47
- input.setValue(currentValue);
18
+ // ── Overlay ────────────────────────────────────────────────────────────────
48
19
 
49
- return {
50
- render: (_width: number) => {
51
- const lines = [` ${label}`];
52
- lines.push(...input.render(_width));
53
- lines.push(" enter confirm • esc cancel");
54
- return lines;
55
- },
56
- invalidate: () => {
57
- input.invalidate();
58
- },
59
- handleInput: (data: string) => {
60
- if (matchesKey(data, Key.escape)) {
61
- done();
62
- return true;
63
- }
64
- if (matchesKey(data, Key.enter)) {
65
- done(input.getValue());
66
- return true;
67
- }
68
- input.handleInput(data);
69
- return true;
70
- },
71
- };
20
+ interface OverlayStatus {
21
+ kind: "warning" | "error";
22
+ message: string;
72
23
  }
73
24
 
74
- // ── Types ────────────────────────────────────────────────────
75
-
76
25
  interface OverlayState {
77
26
  scope: SettingsScope;
78
27
  cwd: string;
28
+ status?: OverlayStatus;
79
29
  }
80
30
 
81
- // ── Pure helpers ─────────────────────────────────────────────
82
-
83
31
  function getScopeLabel(scope: SettingsScope): string {
84
32
  return scope === "project" ? "Project" : "Global";
85
33
  }
86
34
 
87
- function buildFlatItems(
88
- sections: SettingsSection[],
89
- scope: SettingsScope,
90
- cwd: string,
91
- ctx?: ExtensionContext,
92
- ): SettingItem[] {
93
- const items: SettingItem[] = [];
94
- for (const section of sections) {
95
- const sectionItems = section.loadValues(scope, cwd, ctx);
96
- for (const item of sectionItems) {
97
- items.push({
98
- ...item,
99
- id: `${section.id}.${item.id}`,
100
- label: `${section.label}: ${item.label}`,
101
- });
102
- }
103
- }
104
- return items;
105
- }
106
-
107
- function findSectionAndId(
108
- sections: SettingsSection[],
109
- flatId: string,
110
- ): { section: SettingsSection; itemId: string } | null {
111
- const dotIndex = flatId.indexOf(".");
112
- if (dotIndex === -1) return null;
113
- const sectionId = flatId.slice(0, dotIndex);
114
- const itemId = flatId.slice(dotIndex + 1);
115
- const section = sections.find((s) => s.id === sectionId);
116
- if (!section) return null;
117
- return { section, itemId };
118
- }
119
-
120
- // ── Component ────────────────────────────────────────────────
121
-
122
- interface SettingsOverlayDeps {
123
- ctx: ExtensionContext;
124
- state: OverlayState;
125
- container: Container;
126
- settingsList: SettingsList | null;
127
- tui: Parameters<Parameters<ExtensionContext["ui"]["custom"]>[0]>[0];
128
- theme: Parameters<Parameters<ExtensionContext["ui"]["custom"]>[0]>[1];
129
- done: () => void;
130
- }
131
-
132
- function createSettingsList(deps: SettingsOverlayDeps): SettingsList {
133
- const sections = getRegisteredSettings();
134
- const items = buildFlatItems(sections, deps.state.scope, deps.state.cwd, deps.ctx);
135
- const onChange = (flatId: string, newValue: string) => {
136
- const found = findSectionAndId(sections, flatId);
137
- if (found) {
138
- found.section.persistChange(
139
- deps.state.scope,
140
- deps.state.cwd,
141
- found.itemId,
142
- newValue,
143
- deps.ctx,
144
- );
145
- }
146
- // Re-read all values to reflect persisted changes, but keep the list
147
- // instance (and its selectedIndex) intact.
148
- const updatedItems = buildFlatItems(sections, deps.state.scope, deps.state.cwd, deps.ctx);
149
- for (const updated of updatedItems) {
150
- const existing = items.find((i) => i.id === updated.id);
151
- if (existing && existing.currentValue !== updated.currentValue) {
152
- settingsList.updateValue(updated.id, updated.currentValue);
153
- }
154
- }
155
- deps.tui.requestRender();
156
- };
157
- const settingsList = new SettingsList(
158
- items,
159
- Math.min(items.length + 4, 20),
160
- getSettingsListTheme(),
161
- onChange,
162
- () => deps.done(),
163
- { enableSearch: true },
164
- );
165
- return settingsList;
166
- }
167
-
168
- function rebuildSettingsList(deps: SettingsOverlayDeps): SettingsList {
169
- const settingsList = createSettingsList(deps);
170
- deps.settingsList = settingsList;
171
-
172
- deps.container.clear();
173
- deps.container.addChild(createHeaderComponent(deps));
174
- deps.container.addChild(settingsList);
175
-
176
- return settingsList;
177
- }
178
-
179
- function createHeaderComponent(deps: SettingsOverlayDeps): Text {
180
- const { theme, state } = deps;
181
- const scopeLabel = getScopeLabel(state.scope);
182
- const otherScope = state.scope === "project" ? "Global" : "Project";
183
- const headerText = new Text(
184
- `${theme.fg("accent", theme.bold("SuPi Settings"))} ${theme.fg("text", `Scope: ${scopeLabel}`)} ${theme.fg("dim", `(tab → ${otherScope})`)}`,
185
- 0,
186
- 0,
187
- );
188
- return headerText;
189
- }
190
-
191
- function handleScopeToggle(deps: SettingsOverlayDeps): void {
192
- deps.state.scope = deps.state.scope === "project" ? "global" : "project";
193
- rebuildSettingsList(deps);
194
- deps.tui.requestRender();
195
- }
196
-
197
- /** Minimal SelectList theme — uses identity so the parent SettingsList provides styling context. */
198
- const PASSTHROUGH_THEME: SelectListTheme = {
199
- selectedPrefix: (text) => `› ${text}`,
200
- selectedText: (text) => text,
201
- description: (text) => text,
202
- scrollInfo: (text) => text,
203
- noMatch: (text) => text,
204
- };
205
-
206
- /**
207
- * Create a model picker submenu for settings.
208
- *
209
- * Shows a scrollable list of selectable models from the scoped model set,
210
- * with the current session model annotated `[current]`. The first entry is
211
- * always `"disabled"`.
212
- *
213
- * @param currentValue - Currently configured canonical model id or `"disabled"`.
214
- * @param done - Callback invoked with the selected value, or undefined on cancel.
215
- * @param ctx - Extension context for model listing. When undefined, only
216
- * `"disabled"` is offered.
217
- */
218
- export function createModelPickerSubmenu(
219
- currentValue: string,
220
- done: (selectedValue?: string) => void,
221
- ctx?: ExtensionContext,
222
- ): {
223
- render: (width: number) => string[];
224
- invalidate: () => void;
225
- handleInput: (data: string) => boolean;
226
- } {
227
- const items = buildModelItems(ctx);
228
-
229
- const initialIndex =
230
- currentValue === "disabled"
231
- ? 0
232
- : Math.max(
233
- 0,
234
- items.findIndex((item) => item.value === currentValue),
235
- );
236
-
237
- const container = new Container();
238
- container.addChild(new Text(" Select suggestion model", 1, 0));
239
- container.addChild(new Text("", 1, 0));
240
-
241
- const selectList = new SelectList(items, Math.min(items.length, 15), PASSTHROUGH_THEME);
242
-
243
- if (initialIndex >= 0) {
244
- selectList.setSelectedIndex(initialIndex);
245
- }
246
-
247
- selectList.onSelect = (item) => done(item.value);
248
- selectList.onCancel = () => done();
249
-
250
- container.addChild(selectList);
251
- container.addChild(new Text(" ↑↓ navigate • enter select • esc cancel", 1, 0));
252
-
253
- return {
254
- render: (width: number) => container.render(width),
255
- invalidate: () => container.invalidate(),
256
- handleInput: (data: string) => {
257
- selectList.handleInput(data);
258
- return true;
259
- },
260
- };
35
+ function collectSettingsSections(pi: ExtensionAPI) {
36
+ const collector = createSettingsContributionCollector();
37
+ pi.events.emit(SUPI_SETTINGS_COLLECT_EVENT, collector);
38
+ return collector.result();
261
39
  }
262
40
 
263
- /** Build selectable model items with "disabled" first. */
264
- function buildModelItems(ctx?: ExtensionContext): SelectItem[] {
265
- const items: SelectItem[] = [
266
- {
267
- value: "disabled",
268
- label: "disabled",
269
- description: "No prompt suggestions",
270
- },
271
- ];
272
-
273
- if (!ctx) return items;
274
-
275
- const models = getSelectableModels(ctx);
276
-
277
- for (const model of models) {
278
- const suffix = model.isCurrent ? " [current]" : "";
279
- items.push({
280
- value: model.canonicalId,
281
- label: `${model.canonicalId}${suffix}`,
282
- description: model.label !== model.canonicalId ? model.label : undefined,
283
- });
284
- }
285
-
286
- return items;
41
+ function latestStatus(diagnostics: SettingsCollectionDiagnostic[]): OverlayStatus | undefined {
42
+ const latest = diagnostics.at(-1);
43
+ return latest ? { kind: latest.kind, message: latest.message } : undefined;
287
44
  }
288
45
 
289
- // ── Entry point ──────────────────────────────────────────────
290
-
291
- export function openSettingsOverlay(ctx: ExtensionContext): void {
292
- const sections = getRegisteredSettings();
293
- if (sections.length === 0) {
46
+ export function openSettingsOverlay(pi: ExtensionAPI, ctx: ExtensionContext): void {
47
+ const collection = collectSettingsSections(pi);
48
+ if (collection.sections.length === 0) {
294
49
  ctx.ui.notify("No settings registered by SuPi extensions", "info");
295
50
  return;
296
51
  }
297
52
 
298
53
  void ctx.ui.custom<void>((tui, theme, _kb, done) => {
299
- const state: OverlayState = { scope: "project", cwd: ctx.cwd };
300
- const container = new Container();
54
+ const state: OverlayState = {
55
+ scope: "project",
56
+ cwd: ctx.cwd,
57
+ status: latestStatus(collection.diagnostics),
58
+ };
301
59
 
302
- const deps: SettingsOverlayDeps = {
60
+ const container = new Container();
61
+ const scopedList = new ScopedSettingsList(
62
+ collection.sections,
63
+ state.scope,
64
+ state.cwd,
303
65
  ctx,
304
- state,
305
- container,
306
- settingsList: null,
307
- tui,
308
66
  theme,
67
+ tui,
309
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
+ }
310
91
  };
311
92
 
312
- rebuildSettingsList(deps);
93
+ rebuildOverlay();
313
94
 
314
95
  const component = {
315
- render: (width: number) => container.render(width),
316
- invalidate: () => container.invalidate(),
96
+ render: (width: number) => [...container.render(width), ...scopedList.render(width)],
97
+ invalidate: () => {
98
+ container.invalidate();
99
+ scopedList.invalidate();
100
+ },
317
101
  handleInput: (data: string) => {
318
102
  if (matchesKey(data, Key.tab)) {
319
- handleScopeToggle(deps);
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();
320
108
  return true;
321
109
  }
322
- // Delegate input to the settings list (always set after rebuildSettingsList)
323
- deps.settingsList?.handleInput?.(data);
324
- deps.tui.requestRender();
110
+ scopedList.handleInput(data);
111
+ tui.requestRender();
325
112
  return true;
326
113
  },
327
114
  };
@@ -1,6 +1,3 @@
1
1
  // supi-core settings-ui domain — settings TUI components (imports pi-tui at runtime, heavy).
2
- export {
3
- createInputSubmenu,
4
- createModelPickerSubmenu,
5
- openSettingsOverlay,
6
- } from "./settings/settings-ui.ts";
2
+ export { createInputSubmenu, createModelPickerSubmenu } from "./settings/settings-submenus.ts";
3
+ export { openSettingsOverlay } from "./settings/settings-ui.ts";
@@ -1,9 +1,31 @@
1
- // supi-core settings domain — settings registry (lightweight, type-only pi-tui import).
1
+ // supi-core settings domain — event-backed declarative settings contributions and command wiring.
2
2
 
3
3
  export { registerSettingsCommand } from "./settings/settings-command.ts";
4
- export type { SettingsScope, SettingsSection } from "./settings/settings-registry.ts";
4
+ export type {
5
+ SettingsCollectionDiagnostic,
6
+ SettingsCollectionResult,
7
+ SettingsContributionCollector,
8
+ SettingsScope,
9
+ SettingsSection,
10
+ } from "./settings/settings-registry.ts";
5
11
  export {
6
- clearRegisteredSettings,
7
- getRegisteredSettings,
8
- registerSettings,
12
+ createSettingsContributionCollector,
13
+ isSettingsContributionCollector,
14
+ SUPI_SETTINGS_COLLECT_EVENT,
9
15
  } from "./settings/settings-registry.ts";
16
+ export type {
17
+ BoolField,
18
+ ConfigHelpers,
19
+ CustomField,
20
+ DeclarativeSettingsOptions,
21
+ EnumField,
22
+ ModelPickerField,
23
+ NumberField,
24
+ ScopedFieldValue,
25
+ SettingsField,
26
+ SettingsFieldAction,
27
+ SettingsPersistedChange,
28
+ StringListField,
29
+ ValueSource,
30
+ } from "./settings/settings-schema.ts";
31
+ export { registerDeclarativeSettings } from "./settings/settings-schema.ts";
@@ -53,6 +53,16 @@ export function derivePromptSurface(spec: SuiPiToolSpec): SuiPiToolPromptSurface
53
53
  };
54
54
  }
55
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
+
56
66
  // ---------------------------------------------------------------------------
57
67
  // Registration
58
68
  // ---------------------------------------------------------------------------
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrclrchtr/supi-code-runtime",
3
- "version": "2.0.6",
3
+ "version": "2.2.0",
4
4
  "description": "SuPi code-runtime — shared workspace context, capability contracts, and canonical types for the code-understanding stack",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -29,7 +29,7 @@
29
29
  "!__tests__"
30
30
  ],
31
31
  "dependencies": {
32
- "@mrclrchtr/supi-core": "2.0.6"
32
+ "@mrclrchtr/supi-core": "2.2.0"
33
33
  },
34
34
  "bundledDependencies": [
35
35
  "@mrclrchtr/supi-core"
@@ -39,15 +39,17 @@ Config file locations:
39
39
 
40
40
  ### Settings helpers
41
41
 
42
- - `registerSettings()` — register an arbitrary settings section
43
- - `registerConfigSettings()` — register a config-backed settings section with scoped persistence helpers
44
- - `registerSettingsCommand()` — register `/supi-settings`
45
- - `openSettingsOverlay()` — open the shared settings UI directly
42
+ - `registerDeclarativeSettings(pi, options)` — contribute a config-backed declarative settings section with source-aware scoped persistence
43
+ - `registerSettingsCommand(pi)` — register `/supi-settings` (used by `@mrclrchtr/supi-settings`)
44
+ - `openSettingsOverlay(pi, ctx)` — open the shared settings UI directly
46
45
  - `createInputSubmenu()` — helper for simple text-entry submenus
46
+ - `createModelPickerSubmenu()` — helper for scoped model selection submenus
47
47
 
48
48
  The built-in settings UI supports:
49
49
 
50
50
  - project/global scope toggle
51
+ - source badges for project, global, and default values
52
+ - Inherit/Reset actions that delete scoped config keys
51
53
  - grouped extension sections
52
54
  - searchable setting lists
53
55
 
@@ -83,25 +85,32 @@ The built-in settings UI supports:
83
85
  ## Example
84
86
 
85
87
  ```ts
86
- import { loadSupiConfig, registerConfigSettings, wrapExtensionContext } from "@mrclrchtr/supi-core/api";
87
-
88
- const config = loadSupiConfig("my-extension", process.cwd(), {
89
- enabled: true,
90
- });
91
-
92
- registerConfigSettings({
93
- id: "my-extension",
94
- label: "My Extension",
95
- section: "my-extension",
96
- defaults: { enabled: true },
97
- buildItems: () => [],
98
- persistChange: () => {},
99
- });
100
-
101
- const message = wrapExtensionContext("my-extension", "hello", {
102
- file: "CLAUDE.md",
103
- turn: 1,
104
- });
88
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
89
+ import { loadSupiConfig, registerDeclarativeSettings, wrapExtensionContext } from "@mrclrchtr/supi-core/api";
90
+
91
+ export default function myExtension(pi: ExtensionAPI) {
92
+ const defaults = { enabled: true };
93
+ const config = loadSupiConfig("my-extension", process.cwd(), defaults);
94
+
95
+ registerDeclarativeSettings(pi, {
96
+ id: "my-extension",
97
+ label: "My Extension",
98
+ section: "my-extension",
99
+ defaults,
100
+ fields: [
101
+ {
102
+ kind: "boolean" as const,
103
+ key: "enabled",
104
+ label: "Enabled",
105
+ },
106
+ ],
107
+ });
108
+
109
+ const message = wrapExtensionContext("my-extension", "hello", {
110
+ enabled: config.enabled,
111
+ });
112
+ void message;
113
+ }
105
114
  ```
106
115
 
107
116
  ## Source
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrclrchtr/supi-core",
3
- "version": "2.0.6",
3
+ "version": "2.2.0",
4
4
  "description": "SuPi core — shared infrastructure for SuPi extensions (XML context tags, config system)",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -70,6 +70,7 @@
70
70
  "./status-spinner": "./src/status-spinner.ts",
71
71
  "./terminal": "./src/terminal.ts",
72
72
  "./tool-framework": "./src/tool-framework.ts",
73
+ "./prompt-surface": "./src/prompt-surface.ts",
73
74
  "./types": "./src/types.ts"
74
75
  }
75
76
  }
@@ -21,6 +21,15 @@ function getProjectConfigPath(cwd: string): string {
21
21
  return path.join(cwd, PROJECT_CONFIG_DIR, CONFIG_FILE);
22
22
  }
23
23
 
24
+ /** Return the SuPi config file path for one scope. */
25
+ export function getSupiConfigPath(
26
+ scope: "global" | "project",
27
+ cwd: string,
28
+ options?: SupiConfigOptions,
29
+ ): string {
30
+ return scope === "global" ? getGlobalConfigPath(options?.homeDir) : getProjectConfigPath(cwd);
31
+ }
32
+
24
33
  export function readJsonFile(filePath: string): Record<string, unknown> | null {
25
34
  let content: string;
26
35
  try {
@@ -95,15 +104,22 @@ export function loadSupiConfigForScope<T>(
95
104
  defaults: T,
96
105
  options: { scope: "global" | "project" } & SupiConfigOptions,
97
106
  ): T {
98
- const config =
99
- options.scope === "global"
100
- ? readJsonFile(getGlobalConfigPath(options.homeDir))
101
- : readJsonFile(getProjectConfigPath(cwd));
107
+ const config = readJsonFile(getSupiConfigPath(options.scope, cwd, { homeDir: options.homeDir }));
102
108
 
103
109
  const scopedSection = extractSection(config, section);
104
110
  return shallowMerge(defaults, scopedSection);
105
111
  }
106
112
 
113
+ /** Load the raw object for one config section and one scope. */
114
+ export function loadSupiConfigSectionForScope(
115
+ section: string,
116
+ cwd: string,
117
+ options: { scope: "global" | "project" } & SupiConfigOptions,
118
+ ): Record<string, unknown> | null {
119
+ const config = readJsonFile(getSupiConfigPath(options.scope, cwd, { homeDir: options.homeDir }));
120
+ return extractSection(config, section);
121
+ }
122
+
107
123
  export interface SupiConfigLocation {
108
124
  section: string;
109
125
  scope: "global" | "project";
@@ -118,8 +134,7 @@ export function writeSupiConfig(
118
134
  value: Record<string, unknown>,
119
135
  options?: SupiConfigOptions,
120
136
  ): void {
121
- const configPath =
122
- loc.scope === "global" ? getGlobalConfigPath(options?.homeDir) : getProjectConfigPath(loc.cwd);
137
+ const configPath = getSupiConfigPath(loc.scope, loc.cwd, options);
123
138
 
124
139
  const dir = path.dirname(configPath);
125
140
  fs.mkdirSync(dir, { recursive: true });
@@ -142,8 +157,7 @@ export function removeSupiConfigKey(
142
157
  key: string,
143
158
  options?: SupiConfigOptions,
144
159
  ): void {
145
- const configPath =
146
- loc.scope === "global" ? getGlobalConfigPath(options?.homeDir) : getProjectConfigPath(loc.cwd);
160
+ const configPath = getSupiConfigPath(loc.scope, loc.cwd, options);
147
161
 
148
162
  const existing = readJsonFile(configPath);
149
163
  if (!existing) return;