@lune_99/pi-lune-extensions-core 0.1.0 → 0.2.1

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 (77) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/README.md +117 -36
  3. package/dist/core/panel.d.ts +6 -1
  4. package/dist/core/panel.js +26 -1
  5. package/dist/core/settings.d.ts +9 -1
  6. package/dist/core/settings.js +36 -2
  7. package/dist/dock/registry.js +1 -0
  8. package/dist/extension.js +10 -2
  9. package/dist/mention/autocomplete.d.ts +25 -0
  10. package/dist/mention/autocomplete.js +140 -0
  11. package/dist/mention/budget.d.ts +8 -0
  12. package/dist/mention/budget.js +10 -0
  13. package/dist/mention/catalog.d.ts +43 -0
  14. package/dist/mention/catalog.js +117 -0
  15. package/dist/mention/claude.d.ts +2 -0
  16. package/dist/mention/claude.js +118 -0
  17. package/dist/mention/codex.d.ts +3 -0
  18. package/dist/mention/codex.js +135 -0
  19. package/dist/mention/external.d.ts +15 -0
  20. package/dist/mention/external.js +145 -0
  21. package/dist/mention/index.d.ts +17 -0
  22. package/dist/mention/index.js +151 -0
  23. package/dist/mention/jsonl.d.ts +9 -0
  24. package/dist/mention/jsonl.js +54 -0
  25. package/dist/mention/mention.d.ts +19 -0
  26. package/dist/mention/mention.js +60 -0
  27. package/dist/mention/pi.d.ts +11 -0
  28. package/dist/mention/pi.js +172 -0
  29. package/dist/mention/session-index.d.ts +66 -0
  30. package/dist/mention/session-index.js +303 -0
  31. package/dist/mention/session.d.ts +18 -0
  32. package/dist/mention/session.js +8 -0
  33. package/dist/mention/text.d.ts +12 -0
  34. package/dist/mention/text.js +47 -0
  35. package/dist/mention/transcript.d.ts +10 -0
  36. package/dist/mention/transcript.js +129 -0
  37. package/dist/panel/defined-section.js +34 -8
  38. package/dist/panel/definition.d.ts +26 -1
  39. package/dist/panel/definition.js +32 -2
  40. package/dist/panel/index.d.ts +3 -2
  41. package/dist/panel/index.js +1 -0
  42. package/dist/panel/panel.js +109 -29
  43. package/dist/panel/section.d.ts +49 -3
  44. package/dist/panel/section.js +59 -12
  45. package/dist/resources/scoped-extension.js +1 -0
  46. package/dist/settings/file-store.js +1 -0
  47. package/docs/dock.md +9 -3
  48. package/docs/panel.md +69 -2
  49. package/docs/public-api-design.md +9 -9
  50. package/docs/recipes.md +3 -8
  51. package/docs/settings.md +1 -1
  52. package/package.json +4 -4
  53. package/src/core/panel.ts +29 -1
  54. package/src/core/settings.ts +42 -2
  55. package/src/dock/registry.ts +1 -0
  56. package/src/extension.ts +11 -2
  57. package/src/mention/autocomplete.ts +177 -0
  58. package/src/mention/budget.ts +11 -0
  59. package/src/mention/catalog.ts +133 -0
  60. package/src/mention/claude.ts +127 -0
  61. package/src/mention/codex.ts +144 -0
  62. package/src/mention/external.ts +190 -0
  63. package/src/mention/index.ts +193 -0
  64. package/src/mention/jsonl.ts +56 -0
  65. package/src/mention/mention.ts +90 -0
  66. package/src/mention/pi.ts +192 -0
  67. package/src/mention/session-index.ts +356 -0
  68. package/src/mention/session.ts +27 -0
  69. package/src/mention/text.ts +52 -0
  70. package/src/mention/transcript.ts +155 -0
  71. package/src/panel/defined-section.ts +40 -7
  72. package/src/panel/definition.ts +67 -2
  73. package/src/panel/index.ts +4 -0
  74. package/src/panel/panel.ts +115 -29
  75. package/src/panel/section.ts +111 -15
  76. package/src/resources/scoped-extension.ts +1 -0
  77. package/src/settings/file-store.ts +1 -0
@@ -65,6 +65,36 @@ export function defineSettingsPanel(settings, options) {
65
65
  .every((key, offset) => key === path[offset])))
66
66
  throw new TypeError(`Overlapping settings panel path ${JSON.stringify(path)}`);
67
67
  }
68
- assertSettingsGroups(fields);
69
- return Object.freeze({ settings, id, label: options.label, fields: Object.freeze(fields) });
68
+ const menus = (options.menus ?? []).map((menu) => Object.freeze({ ...menu }));
69
+ // The same IDs createDefinedSettingsSection gives the fields.
70
+ const ids = new Set(fields.map(({ path }) => (typeof path === "string" ? path : JSON.stringify(path))));
71
+ for (const menu of menus) {
72
+ if (!menu.id.trim() || !menu.label.trim())
73
+ throw new TypeError("Settings menu id and label must not be empty");
74
+ if (ids.has(menu.id))
75
+ throw new TypeError(`Duplicate settings panel id "${menu.id}"`);
76
+ ids.add(menu.id);
77
+ const listed = fields.filter(({ inMenu }) => inMenu === menu.id);
78
+ if (menu.open !== undefined && typeof menu.open !== "function")
79
+ throw new TypeError(`Settings open for menu "${menu.id}" must be a function`);
80
+ if (menu.open && listed.length > 0)
81
+ throw new TypeError(`Settings menu "${menu.id}" has an open function and fields that name it; use one`);
82
+ if (!menu.open && listed.length === 0)
83
+ throw new TypeError(`Settings menu "${menu.id}" requires an open function or fields that name it in inMenu`);
84
+ for (const name of ["visible", "disabled", "summary"])
85
+ if (menu[name] !== undefined && typeof menu[name] !== "function")
86
+ throw new TypeError(`Settings ${name} for menu "${menu.id}" must be a function`);
87
+ assertSettingsGroups(listed);
88
+ }
89
+ for (const { path, inMenu } of fields)
90
+ if (inMenu !== undefined && !menus.some((menu) => menu.id === inMenu))
91
+ throw new TypeError(`Settings field ${JSON.stringify(path)} names unknown menu "${inMenu}"`);
92
+ assertSettingsGroups([...fields.filter(({ inMenu }) => inMenu === undefined), ...menus]);
93
+ return Object.freeze({
94
+ settings,
95
+ id,
96
+ label: options.label,
97
+ fields: Object.freeze(fields),
98
+ menus: Object.freeze(menus),
99
+ });
70
100
  }
@@ -9,9 +9,10 @@
9
9
  * renderer, or /panel/host to adapt/register a custom section against a live view.
10
10
  */
11
11
  export { defineSettingsPanel } from "./definition.ts";
12
- export type { SettingsPanelDefinition, SettingsPanelOptions, SettingsPanelFieldDefinition, SettingsFieldBuilder, } from "./definition.ts";
12
+ export type { SettingsPanelDefinition, SettingsPanelOptions, SettingsPanelFieldDefinition, SettingsFieldBuilder, SettingsMenuDefinition, } from "./definition.ts";
13
+ export { createSettingsMenuField } from "./section.ts";
13
14
  export { registerSettingsPanel } from "./registration.ts";
14
15
  export type { SettingsPanelRegistration } from "./registration.ts";
15
16
  export { modelChoices } from "./tools/model-choices.ts";
16
17
  export type { ModelReference, ModelChoiceScope, ModelChoicesOptions, } from "./tools/model-choices.ts";
17
- export type { SettingsEditor, SettingsPanelSchema, SettingsChoiceContext, SettingsChoiceSource, SettingsChoice, SettingsPreview, SettingsCustomEditor, SettingsCustomEditorContext, SettingsEditorComponent, SettingsFieldOptions, SettingsPanelField, SettingsSection, } from "./section.ts";
18
+ export type { SettingsEditor, SettingsPanelSchema, SettingsChoiceContext, SettingsChoiceSource, SettingsChoice, SettingsPreview, SettingsCustomEditor, SettingsCustomEditorContext, SettingsEditorComponent, SettingsFieldOptions, SettingsMenu, SettingsMenuFieldOptions, SettingsPanelField, SettingsSection, } from "./section.ts";
@@ -9,5 +9,6 @@
9
9
  * renderer, or /panel/host to adapt/register a custom section against a live view.
10
10
  */
11
11
  export { defineSettingsPanel } from "./definition.js";
12
+ export { createSettingsMenuField } from "./section.js";
12
13
  export { registerSettingsPanel } from "./registration.js";
13
14
  export { modelChoices } from "./tools/model-choices.js";
@@ -49,7 +49,9 @@ function message(error) {
49
49
  /**
50
50
  * Frame-level state machine: navigation -> text/number/JSON/secret input, choice editor
51
51
  * or custom editor -> navigation. The edited field is captured on entry because
52
- * conditional visibility may rebuild the list while an editor is open.
52
+ * conditional visibility may rebuild the list while an editor is open. Navigation can
53
+ * descend into secondary menus; the open path is kept as field IDs and resolved again
54
+ * on every refresh, so a menu whose row disappears closes instead of showing stale fields.
53
55
  * busy serializes accepted persistence operations; disposed prevents their completion
54
56
  * from refreshing a retired interaction. Dynamic membership follows stable ctx.ui,
55
57
  * not Settings IDs across runners. Child editors must not draw a second shared frame.
@@ -63,6 +65,10 @@ class SettingsPanel {
63
65
  choiceEditor;
64
66
  customEditor;
65
67
  editing;
68
+ // IDs of the open menu rows, outermost first, and the pages they resolved to.
69
+ menuPath = [];
70
+ menus = [];
71
+ menuError = "";
66
72
  // List rows that are group headings; navigation steps over them.
67
73
  headings = new Set();
68
74
  visibleFields = 0;
@@ -116,9 +122,12 @@ class SettingsPanel {
116
122
  return this.sections[this.activeSection];
117
123
  }
118
124
  // An unavailable section has no trustworthy fields to list or edit.
119
- get fields() {
125
+ get sectionFields() {
120
126
  return this.section?.unavailable === undefined ? (this.section?.fields ?? []) : [];
121
127
  }
128
+ get fields() {
129
+ return this.menus.at(-1)?.menu.fields ?? this.sectionFields;
130
+ }
122
131
  get field() {
123
132
  const id = this.list?.getSelectedItem()?.value;
124
133
  return this.fields.find((field) => field.id === id);
@@ -183,6 +192,7 @@ class SettingsPanel {
183
192
  this.activeSection = Math.max(0, index < 0 && previous ? this.sections.findIndex(({ id }) => id === previous.id) : index);
184
193
  if (previous && previous !== this.section) {
185
194
  this.list = undefined;
195
+ this.menuPath = [];
186
196
  this.input = undefined;
187
197
  this.editing = undefined;
188
198
  this.choiceEditor?.dispose();
@@ -191,11 +201,47 @@ class SettingsPanel {
191
201
  }
192
202
  this.refresh();
193
203
  }
204
+ // A menu is built again from its row, so the page follows values and files changed meanwhile.
205
+ resolveMenus() {
206
+ this.menus = [];
207
+ this.menuError = "";
208
+ let fields = this.sectionFields;
209
+ for (const id of this.menuPath) {
210
+ const field = fields.find((candidate) => candidate.id === id && candidate.menu);
211
+ if (!field)
212
+ break;
213
+ let menu;
214
+ try {
215
+ menu = field.menu(this.ctx, this.scope);
216
+ }
217
+ catch (error) {
218
+ this.menuError = `Could not open ${field.label}: ${message(error)}`;
219
+ break;
220
+ }
221
+ this.menus.push({ field, menu });
222
+ fields = menu.fields;
223
+ }
224
+ this.menuPath = this.menus.map(({ field }) => field.id);
225
+ }
226
+ openMenu(field) {
227
+ this.menuPath = [...this.menuPath, field.id];
228
+ this.list = undefined;
229
+ this.refresh();
230
+ }
231
+ // Back to the parent list with the menu's own row selected.
232
+ closeMenu() {
233
+ const id = this.menuPath.at(-1);
234
+ this.menuPath = this.menuPath.slice(0, -1);
235
+ this.list = undefined;
236
+ this.error = "";
237
+ this.refresh(id);
238
+ }
194
239
  // The list is rebuilt because values, visibility and registered sections change while it is open.
195
- refresh() {
240
+ refresh(select) {
196
241
  if (this.disposed)
197
242
  return;
198
- const selected = this.list?.getSelectedItem()?.value;
243
+ const selected = select ?? this.list?.getSelectedItem()?.value;
244
+ this.resolveMenus();
199
245
  this.visibilityErrors = [];
200
246
  const fields = this.fields.filter((field) => {
201
247
  try {
@@ -226,19 +272,11 @@ class SettingsPanel {
226
272
  });
227
273
  }
228
274
  group = field.group;
229
- const value = valueAtScope(field.inspect(), this.scope);
230
- // The mask length is fixed so it cannot leak the secret's length.
231
- const label = field.secret
232
- ? typeof value === "string" && value
233
- ? SECRET_MASK
234
- : "(not set)"
235
- : (field.choices?.find((choice) => isDeepStrictEqual(choice.value, value))?.label ??
236
- field.formatValue?.(value, this.ctx, this.scope) ??
237
- formatValue(value));
275
+ const label = this.rowValue(field);
238
276
  const globalOnly = !this.projectDisabled && !field.scopes.includes(this.scope);
239
277
  items.push({
240
278
  value: field.id,
241
- label: field.label,
279
+ label: field.menu ? `${field.label} →` : field.label,
242
280
  description: [label, globalOnly && "global only", this.disabledReason(field)]
243
281
  .filter(Boolean)
244
282
  .join(" · "),
@@ -260,10 +298,30 @@ class SettingsPanel {
260
298
  this.updatePreview();
261
299
  };
262
300
  this.list.onSelect = () => this.edit();
263
- this.list.onCancel = () => this.close();
301
+ this.list.onCancel = () => this.back();
264
302
  this.updatePreview();
265
303
  this.tui.requestRender();
266
304
  }
305
+ // A menu row has no value; its summary stands in, and a failing summary is shown, not thrown.
306
+ rowValue(field) {
307
+ if (field.menu) {
308
+ try {
309
+ return field.formatValue?.(undefined, this.ctx, this.scope) ?? "";
310
+ }
311
+ catch (error) {
312
+ return this.theme.fg("error", message(error));
313
+ }
314
+ }
315
+ const value = valueAtScope(field.inspect(), this.scope);
316
+ // The mask length is fixed so it cannot leak the secret's length.
317
+ return field.secret
318
+ ? typeof value === "string" && value
319
+ ? SECRET_MASK
320
+ : "(not set)"
321
+ : (field.choices?.find((choice) => isDeepStrictEqual(choice.value, value))?.label ??
322
+ field.formatValue?.(value, this.ctx, this.scope) ??
323
+ formatValue(value));
324
+ }
267
325
  // A failing preview must not close the panel; the error line replaces it.
268
326
  updatePreview() {
269
327
  this.preview?.dispose?.();
@@ -321,6 +379,10 @@ class SettingsPanel {
321
379
  this.openCustomEditor(field);
322
380
  return;
323
381
  }
382
+ if (editor === "menu") {
383
+ this.openMenu(field);
384
+ return;
385
+ }
324
386
  if (editor === "cycle" && field.choices?.length) {
325
387
  const current = valueAtScope(field.inspect(), this.scope);
326
388
  const index = field.choices.findIndex(({ value }) => isDeepStrictEqual(value, current));
@@ -474,7 +536,7 @@ class SettingsPanel {
474
536
  const message = error instanceof Error ? error.message : String(error);
475
537
  throw new Error(isSettingsNotificationError(error)
476
538
  ? `Reloaded; ${message}`
477
- : `Retry failed: ${message}`);
539
+ : `Retry failed: ${message}`, { cause: error });
478
540
  }
479
541
  });
480
542
  }
@@ -512,6 +574,7 @@ class SettingsPanel {
512
574
  * Route input to exactly one mode; persistence suppresses further actions.
513
575
  * Ctrl+G changes persistence scope only in navigation. Inside a selector, Tab
514
576
  * changes its candidate range and Ctrl+R refreshes discovery rather than reset.
577
+ * Left/Right switch sections only in navigation; open inputs and editors keep them.
515
578
  */
516
579
  handleInput(data) {
517
580
  // Key-release events would otherwise repeat the action on terminals that report them.
@@ -551,12 +614,13 @@ class SettingsPanel {
551
614
  this.updatePreview();
552
615
  }
553
616
  }
554
- else if (matchesKey(data, "tab") || matchesKey(data, "shift+tab")) {
617
+ else if (["tab", "shift+tab", "left", "right"].some((key) => matchesKey(data, key))) {
555
618
  if (this.sections.length) {
556
- const delta = matchesKey(data, "shift+tab") ? -1 : 1;
619
+ const delta = matchesKey(data, "shift+tab") || matchesKey(data, "left") ? -1 : 1;
557
620
  this.activeSection =
558
621
  (this.activeSection + delta + this.sections.length) % this.sections.length;
559
622
  this.list = undefined;
623
+ this.menuPath = [];
560
624
  this.error = "";
561
625
  this.refresh();
562
626
  }
@@ -575,11 +639,13 @@ class SettingsPanel {
575
639
  const blocked = field && this.scopeError(field);
576
640
  if (blocked)
577
641
  this.error = blocked;
642
+ else if (field?.menu)
643
+ this.error = `Open ${field.label} to reset the settings in it`;
578
644
  else if (field)
579
645
  void this.apply(() => this.commit(() => field.reset(this.scope)));
580
646
  }
581
647
  else if (matchesKey(data, "escape")) {
582
- this.close();
648
+ this.back();
583
649
  }
584
650
  else if (data === " ") {
585
651
  this.edit();
@@ -592,6 +658,12 @@ class SettingsPanel {
592
658
  }
593
659
  this.tui.requestRender();
594
660
  }
661
+ back() {
662
+ if (this.menuPath.length)
663
+ this.closeMenu();
664
+ else
665
+ this.close();
666
+ }
595
667
  isHeading(value) {
596
668
  return value !== undefined && this.headings.has(value);
597
669
  }
@@ -611,15 +683,19 @@ class SettingsPanel {
611
683
  : this.theme.fg(section.unavailable === undefined ? "dim" : "error", section.label))
612
684
  .join(this.theme.fg("dim", " / "));
613
685
  const field = this.editing ?? this.field;
614
- const inspection = field?.inspect();
686
+ const inspection = field && !field.menu ? field.inspect() : undefined;
615
687
  // Side-by-side preview needs room; below this width it is stacked under the list.
616
688
  const split = width >= 88 && !this.input && !!field?.preview;
617
689
  const bodyWidth = split ? Math.floor((width - 3) / 2) : width;
618
- let body = this.input
619
- ? this.input.render(bodyWidth)
620
- : this.customEditor
621
- ? this.renderCustomEditor(bodyWidth)
622
- : (this.choiceEditor?.renderBody(bodyWidth) ?? this.list?.render(bodyWidth) ?? []);
690
+ let body = [
691
+ ...(this.input
692
+ ? this.input.render(bodyWidth)
693
+ : this.customEditor
694
+ ? this.renderCustomEditor(bodyWidth)
695
+ : (this.choiceEditor?.renderBody(bodyWidth) ??
696
+ this.list?.render(bodyWidth) ??
697
+ [])),
698
+ ];
623
699
  if (!this.sections.length)
624
700
  body = [this.theme.fg("muted", "No extensions have registered settings.")];
625
701
  else if (this.section?.unavailable !== undefined)
@@ -629,6 +705,10 @@ class SettingsPanel {
629
705
  "",
630
706
  this.theme.fg("muted", "Fix the problem, then press Ctrl+S to retry."),
631
707
  ];
708
+ else if (this.menus.length && !this.fields.length)
709
+ body = [
710
+ this.theme.fg("muted", this.menus.at(-1).menu.emptyMessage ?? "This menu is empty."),
711
+ ];
632
712
  else if (!this.section?.fields.length)
633
713
  body = [this.theme.fg("muted", "No settings are available in this section yet.")];
634
714
  else if (!this.visibleFields)
@@ -673,13 +753,13 @@ class SettingsPanel {
673
753
  else
674
754
  body.push("", rule, ...preview);
675
755
  }
676
- const errors = [this.error, ...this.visibilityErrors].filter(Boolean);
756
+ const errors = [this.error, this.menuError, ...this.visibilityErrors].filter(Boolean);
677
757
  if (errors.length)
678
758
  body.push("", ...errors.map((text) => this.theme.fg("error", text)));
679
759
  return [
680
760
  rule,
681
761
  this.theme.fg("accent", this.choiceEditor?.title ??
682
- `${this.editing ? this.editing.label : "Lune settings"} · ${this.scope}${this.busy ? " · Saving / loading…" : ""}`),
762
+ `${this.editing ? this.editing.label : ["Lune settings", ...this.menus.map(({ field }) => field.label)].join(" › ")} · ${this.scope}${this.busy ? " · Saving / loading…" : ""}`),
683
763
  tabs,
684
764
  rule,
685
765
  ...body,
@@ -692,8 +772,8 @@ class SettingsPanel {
692
772
  : this.input
693
773
  ? "Enter save · Ctrl+S save/reload · Esc back"
694
774
  : this.section?.unavailable !== undefined
695
- ? "Tab section · Ctrl+S retry · Esc close"
696
- : "↑↓ select · Enter change · Tab section · Ctrl+G scope · Ctrl+S reload section · Ctrl+R reset · Esc close")),
775
+ ? "Tab/←→ section · Ctrl+S retry · Esc close"
776
+ : `↑↓ select · Enter change · Tab/←→ section · Ctrl+G scope · Ctrl+S reload section · Ctrl+R reset · ${this.menus.length ? "Esc back" : "Esc close"}`)),
697
777
  rule,
698
778
  ].map((line) => truncateToWidth(line, width));
699
779
  }
@@ -1,4 +1,4 @@
1
- import type { Static, TObject, TSchema } from "typebox";
1
+ import { type Static, type TObject, type TSchema } from "typebox";
2
2
  import type { ExtensionContext, Theme } from "@earendil-works/pi-coding-agent";
3
3
  import type { Component } from "@earendil-works/pi-tui";
4
4
  import type { SettingInspection, SettingsView, SettingsKey, SettingsScope } from "../settings/types.ts";
@@ -100,13 +100,25 @@ export interface SettingsEditorComponent extends Component {
100
100
  }
101
101
  /** Build the editor for one edit; it must not persist on its own, only through submit. */
102
102
  export type SettingsCustomEditor<T, TValues> = (context: SettingsCustomEditorContext<T, TValues>) => SettingsEditorComponent;
103
+ /**
104
+ * A secondary menu: a page of fields that one row opens inside the panel frame.
105
+ * Renderers build it again on every refresh, so its fields can follow changes made
106
+ * outside Settings, such as files the menu edits. Its fields may open further menus.
107
+ */
108
+ export interface SettingsMenu {
109
+ /** Unique IDs within the menu; a renderer keeps an open menu by the IDs on its path. */
110
+ readonly fields: readonly SettingsPanelField[];
111
+ /** Shown instead of the list when fields is empty. */
112
+ readonly emptyMessage?: string;
113
+ }
103
114
  /**
104
115
  * cycle commits static choices immediately; select confirms a candidate list.
105
116
  * text accepts raw strings only; number accepts one finite number for number/integer
106
117
  * schemas; json parses then validates complete JSON values; custom hands editing to
107
- * the field's customEditor. Preview availability does not determine the editor.
118
+ * the field's customEditor; menu opens the field's secondary menu. Preview
119
+ * availability does not determine the editor.
108
120
  */
109
- export type SettingsEditor = "cycle" | "select" | "text" | "number" | "json" | "custom";
121
+ export type SettingsEditor = "cycle" | "select" | "text" | "number" | "json" | "custom" | "menu";
110
122
  /**
111
123
  * Field presentation/editing metadata, not storage policy.
112
124
  * presentation=true requires a preview; explicit editors override inference.
@@ -121,6 +133,11 @@ export type SettingsFieldOptions<T, TValues> = {
121
133
  * ungrouped fields come before every group.
122
134
  */
123
135
  group?: string;
136
+ /**
137
+ * ID of a menu of the same panel that lists the field on its page instead of in the
138
+ * section. That menu declares no open function; see SettingsMenuDefinition.
139
+ */
140
+ inMenu?: string;
124
141
  /**
125
142
  * Hide the field while this returns false, e.g. options of a disabled feature.
126
143
  * Hidden fields keep their stored values. Runs on every refresh: keep it cheap and pure.
@@ -193,6 +210,12 @@ export interface SettingsPanelField {
193
210
  disabled?(context: ExtensionContext, scope: SettingsScope): string | undefined;
194
211
  /** Present exactly when editor is "custom"; the adapter adds the scoped values snapshot. */
195
212
  customEditor?(context: Omit<SettingsCustomEditorContext<unknown, unknown>, "values">): SettingsEditorComponent;
213
+ /**
214
+ * Present exactly when editor is "menu". A menu row holds no value: renderers show
215
+ * formatValue(undefined) as its summary and never inspect, set or reset it.
216
+ * createSettingsMenuField builds such a field.
217
+ */
218
+ menu?(context: ExtensionContext, scope: SettingsScope): SettingsMenu;
196
219
  /** Current precedence explanation; renderers use explicit scope overrides for editing. */
197
220
  inspect(): SettingInspection<unknown>;
198
221
  /** Validate/commit a candidate at this explicit persistence scope, not a candidate range. */
@@ -230,6 +253,7 @@ export declare function valueAtScope(inspection: SettingInspection<unknown>, sco
230
253
  */
231
254
  export declare function settingsEditor(field: Pick<SettingsPanelField, "editor" | "choiceSource" | "choices" | "schema"> & {
232
255
  customEditor?: unknown;
256
+ menu?: unknown;
233
257
  }): SettingsEditor;
234
258
  /**
235
259
  * Infer only unambiguous boolean/literal choices and reject impossible editor metadata.
@@ -245,6 +269,7 @@ export declare function resolveSettingsFieldOptions(id: string, schema: Settings
245
269
  visible?: unknown;
246
270
  disabled?: unknown;
247
271
  customEditor?: unknown;
272
+ menu?: unknown;
248
273
  }): {
249
274
  choices: readonly SettingsChoice<unknown>[] | undefined;
250
275
  editor: SettingsEditor;
@@ -257,6 +282,27 @@ export declare function resolveSettingsFieldOptions(id: string, schema: Settings
257
282
  export declare function assertSettingsGroups(fields: readonly {
258
283
  group?: string;
259
284
  }[]): void;
285
+ /** A row that opens a secondary menu; see createSettingsMenuField. */
286
+ export interface SettingsMenuFieldOptions {
287
+ /** Unique among the fields of the section or menu that lists the row. */
288
+ id: string;
289
+ label: string;
290
+ description?: string;
291
+ group?: string;
292
+ /** Scopes at which the menu can open; its own fields keep their own scopes. */
293
+ scopes: readonly SettingsScope[];
294
+ /** Text beside the label, such as a count of the menu's entries. */
295
+ summary?(context: ExtensionContext, scope: SettingsScope): string;
296
+ visible?(context: ExtensionContext, scope: SettingsScope): boolean;
297
+ disabled?(context: ExtensionContext, scope: SettingsScope): string | undefined;
298
+ /** Build the page; renderers call it again on every refresh while it is open. */
299
+ menu(context: ExtensionContext, scope: SettingsScope): SettingsMenu;
300
+ }
301
+ /**
302
+ * Build a field whose row opens a secondary menu. The row has no value of its own, so
303
+ * set and reset reject: the menu's fields hold the values.
304
+ */
305
+ export declare function createSettingsMenuField(options: SettingsMenuFieldOptions): SettingsPanelField;
260
306
  /**
261
307
  * Adapt top-level Settings keys to a custom section; no acquisition/hooks are installed.
262
308
  *
@@ -7,6 +7,7 @@
7
7
  * candidates only in clones. Validation/editor resolution stays usable without TUI.
8
8
  */
9
9
  import { Value } from "typebox/value";
10
+ import { Type } from "typebox";
10
11
  /** Only an absent override falls through; an explicit null, false, 0 or empty string wins. */
11
12
  export function valueAtScope(inspection, scope) {
12
13
  return scope === "global"
@@ -39,17 +40,19 @@ function schemaChoices(schema) {
39
40
  */
40
41
  export function settingsEditor(field) {
41
42
  return (field.editor ??
42
- (field.customEditor
43
- ? "custom"
44
- : field.choiceSource
45
- ? "select"
46
- : field.choices?.length
47
- ? "cycle"
48
- : field.schema.type === "string"
49
- ? "text"
50
- : field.schema.type === "number" || field.schema.type === "integer"
51
- ? "number"
52
- : "json"));
43
+ (field.menu
44
+ ? "menu"
45
+ : field.customEditor
46
+ ? "custom"
47
+ : field.choiceSource
48
+ ? "select"
49
+ : field.choices?.length
50
+ ? "cycle"
51
+ : field.schema.type === "string"
52
+ ? "text"
53
+ : field.schema.type === "number" || field.schema.type === "integer"
54
+ ? "number"
55
+ : "json"));
53
56
  }
54
57
  /**
55
58
  * Infer only unambiguous boolean/literal choices and reject impossible editor metadata.
@@ -64,9 +67,21 @@ export function resolveSettingsFieldOptions(id, schema, metadata) {
64
67
  if (metadata?.group !== undefined &&
65
68
  (typeof metadata.group !== "string" || !metadata.group.trim()))
66
69
  throw new TypeError(`Settings group for "${id}" must be a non-empty string`);
67
- for (const name of ["visible", "disabled", "customEditor"])
70
+ for (const name of ["visible", "disabled", "customEditor", "menu"])
68
71
  if (metadata?.[name] !== undefined && typeof metadata[name] !== "function")
69
72
  throw new TypeError(`Settings ${name} for "${id}" must be a function`);
73
+ if (metadata?.menu) {
74
+ if ((metadata.editor ?? "menu") !== "menu")
75
+ throw new TypeError(`Menu "${id}" conflicts with editor "${metadata.editor}"`);
76
+ if (metadata.customEditor ||
77
+ metadata.choices ||
78
+ metadata.choiceSource ||
79
+ metadata.secret ||
80
+ metadata.preview)
81
+ throw new TypeError(`Menu "${id}" cannot use a custom editor, choices, secret or a preview; it opens its own fields`);
82
+ }
83
+ else if (metadata?.editor === "menu")
84
+ throw new TypeError(`Editor "menu" requires a menu for "${id}"`);
70
85
  if (metadata?.customEditor) {
71
86
  if ((metadata.editor ?? "custom") !== "custom")
72
87
  throw new TypeError(`Custom editor for "${id}" conflicts with editor "${metadata.editor}"`);
@@ -87,6 +102,7 @@ export function resolveSettingsFieldOptions(id, schema, metadata) {
87
102
  const editor = settingsEditor({
88
103
  editor: metadata?.editor,
89
104
  customEditor: metadata?.customEditor,
105
+ menu: metadata?.menu,
90
106
  choiceSource: metadata?.choiceSource,
91
107
  choices,
92
108
  schema,
@@ -133,6 +149,37 @@ export function assertSettingsGroups(fields) {
133
149
  current = group;
134
150
  }
135
151
  }
152
+ /**
153
+ * Build a field whose row opens a secondary menu. The row has no value of its own, so
154
+ * set and reset reject: the menu's fields hold the values.
155
+ */
156
+ export function createSettingsMenuField(options) {
157
+ const schema = Type.Null();
158
+ resolveSettingsFieldOptions(options.id, schema, options);
159
+ const refuse = () => Promise.reject(new TypeError(`${options.label} is a menu; change the settings inside it instead`));
160
+ return {
161
+ id: options.id,
162
+ label: options.label,
163
+ description: options.description,
164
+ schema,
165
+ editor: "menu",
166
+ group: options.group,
167
+ scopes: options.scopes,
168
+ visible: options.visible,
169
+ disabled: options.disabled,
170
+ menu: options.menu,
171
+ formatValue: (_value, context, scope) => options.summary?.(context, scope) ?? "",
172
+ inspect: () => ({
173
+ defaultValue: null,
174
+ globalValue: undefined,
175
+ projectValue: undefined,
176
+ value: null,
177
+ source: "default",
178
+ }),
179
+ set: refuse,
180
+ reset: refuse,
181
+ };
182
+ }
136
183
  /**
137
184
  * Adapt top-level Settings keys to a custom section; no acquisition/hooks are installed.
138
185
  *
@@ -26,6 +26,7 @@ export function scopedExtension(setup) {
26
26
  await resources.dispose();
27
27
  }
28
28
  catch (cleanupError) {
29
+ // eslint-disable-next-line preserve-caught-error -- AggregateError.errors retains both failures.
29
30
  throw new AggregateError([error, cleanupError], "Extension setup and cleanup failed");
30
31
  }
31
32
  throw error;
@@ -109,6 +109,7 @@ async function writeStored(file, stored) {
109
109
  await fs.rm(tmpPath, { force: true });
110
110
  }
111
111
  catch (cleanupError) {
112
+ // eslint-disable-next-line preserve-caught-error -- AggregateError.errors retains both failures.
112
113
  throw new AggregateError([error, cleanupError], "Settings write and temporary file cleanup failed");
113
114
  }
114
115
  throw error;
package/docs/dock.md CHANGED
@@ -17,9 +17,15 @@ const definition: DockDefinition = {
17
17
  }),
18
18
  activate() {},
19
19
  standalone: {
20
- setCtx(ctx) { renderer.setContext(ctx); },
21
- render() { renderer.render(); },
22
- clear() { renderer.clear(); },
20
+ setCtx(ctx) {
21
+ renderer.setContext(ctx);
22
+ },
23
+ render() {
24
+ renderer.render();
25
+ },
26
+ clear() {
27
+ renderer.clear();
28
+ },
23
29
  },
24
30
  };
25
31
  const contribution = createDockContribution(definition);