@lune_99/pi-lune-extensions-core 0.1.0 → 0.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 (62) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +100 -34
  3. package/dist/dock/registry.js +1 -0
  4. package/dist/extension.js +6 -2
  5. package/dist/mention/autocomplete.d.ts +23 -0
  6. package/dist/mention/autocomplete.js +135 -0
  7. package/dist/mention/catalog.d.ts +26 -0
  8. package/dist/mention/catalog.js +76 -0
  9. package/dist/mention/claude.d.ts +2 -0
  10. package/dist/mention/claude.js +118 -0
  11. package/dist/mention/codex.d.ts +3 -0
  12. package/dist/mention/codex.js +135 -0
  13. package/dist/mention/external.d.ts +15 -0
  14. package/dist/mention/external.js +151 -0
  15. package/dist/mention/index.d.ts +8 -0
  16. package/dist/mention/index.js +150 -0
  17. package/dist/mention/jsonl.d.ts +9 -0
  18. package/dist/mention/jsonl.js +54 -0
  19. package/dist/mention/mention.d.ts +19 -0
  20. package/dist/mention/mention.js +60 -0
  21. package/dist/mention/session.d.ts +18 -0
  22. package/dist/mention/session.js +8 -0
  23. package/dist/mention/text.d.ts +12 -0
  24. package/dist/mention/text.js +47 -0
  25. package/dist/mention/transcript.d.ts +10 -0
  26. package/dist/mention/transcript.js +129 -0
  27. package/dist/panel/defined-section.js +34 -8
  28. package/dist/panel/definition.d.ts +26 -1
  29. package/dist/panel/definition.js +32 -2
  30. package/dist/panel/index.d.ts +3 -2
  31. package/dist/panel/index.js +1 -0
  32. package/dist/panel/panel.js +100 -24
  33. package/dist/panel/section.d.ts +49 -3
  34. package/dist/panel/section.js +59 -12
  35. package/dist/resources/scoped-extension.js +1 -0
  36. package/dist/settings/file-store.js +1 -0
  37. package/docs/dock.md +9 -3
  38. package/docs/panel.md +69 -2
  39. package/docs/public-api-design.md +9 -9
  40. package/docs/recipes.md +3 -8
  41. package/docs/settings.md +1 -1
  42. package/package.json +4 -4
  43. package/src/dock/registry.ts +1 -0
  44. package/src/extension.ts +6 -2
  45. package/src/mention/autocomplete.ts +173 -0
  46. package/src/mention/catalog.ts +84 -0
  47. package/src/mention/claude.ts +127 -0
  48. package/src/mention/codex.ts +144 -0
  49. package/src/mention/external.ts +191 -0
  50. package/src/mention/index.ts +173 -0
  51. package/src/mention/jsonl.ts +56 -0
  52. package/src/mention/mention.ts +90 -0
  53. package/src/mention/session.ts +27 -0
  54. package/src/mention/text.ts +52 -0
  55. package/src/mention/transcript.ts +155 -0
  56. package/src/panel/defined-section.ts +40 -7
  57. package/src/panel/definition.ts +67 -2
  58. package/src/panel/index.ts +4 -0
  59. package/src/panel/panel.ts +105 -23
  60. package/src/panel/section.ts +111 -15
  61. package/src/resources/scoped-extension.ts +1 -0
  62. package/src/settings/file-store.ts +1 -0
@@ -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,7 +683,7 @@ 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;
@@ -629,6 +701,10 @@ class SettingsPanel {
629
701
  "",
630
702
  this.theme.fg("muted", "Fix the problem, then press Ctrl+S to retry."),
631
703
  ];
704
+ else if (this.menus.length && !this.fields.length)
705
+ body = [
706
+ this.theme.fg("muted", this.menus.at(-1).menu.emptyMessage ?? "This menu is empty."),
707
+ ];
632
708
  else if (!this.section?.fields.length)
633
709
  body = [this.theme.fg("muted", "No settings are available in this section yet.")];
634
710
  else if (!this.visibleFields)
@@ -673,13 +749,13 @@ class SettingsPanel {
673
749
  else
674
750
  body.push("", rule, ...preview);
675
751
  }
676
- const errors = [this.error, ...this.visibilityErrors].filter(Boolean);
752
+ const errors = [this.error, this.menuError, ...this.visibilityErrors].filter(Boolean);
677
753
  if (errors.length)
678
754
  body.push("", ...errors.map((text) => this.theme.fg("error", text)));
679
755
  return [
680
756
  rule,
681
757
  this.theme.fg("accent", this.choiceEditor?.title ??
682
- `${this.editing ? this.editing.label : "Lune settings"} · ${this.scope}${this.busy ? " · Saving / loading…" : ""}`),
758
+ `${this.editing ? this.editing.label : ["Lune settings", ...this.menus.map(({ field }) => field.label)].join(" › ")} · ${this.scope}${this.busy ? " · Saving / loading…" : ""}`),
683
759
  tabs,
684
760
  rule,
685
761
  ...body,
@@ -692,8 +768,8 @@ class SettingsPanel {
692
768
  : this.input
693
769
  ? "Enter save · Ctrl+S save/reload · Esc back"
694
770
  : 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")),
771
+ ? "Tab/←→ section · Ctrl+S retry · Esc close"
772
+ : `↑↓ select · Enter change · Tab/←→ section · Ctrl+G scope · Ctrl+S reload section · Ctrl+R reset · ${this.menus.length ? "Esc back" : "Esc close"}`)),
697
773
  rule,
698
774
  ].map((line) => truncateToWidth(line, width));
699
775
  }
@@ -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);
package/docs/panel.md CHANGED
@@ -71,7 +71,12 @@ the error is shown; if `disabled` throws, editing is blocked and the error is sh
71
71
  ```ts
72
72
  fields: [
73
73
  { path: "enabled", label: "Enabled" },
74
- { path: "retries", label: "Retries", group: "Advanced", visible: ({ values }) => values.enabled },
74
+ {
75
+ path: "retries",
76
+ label: "Retries",
77
+ group: "Advanced",
78
+ visible: ({ values }) => values.enabled,
79
+ },
75
80
  {
76
81
  path: "level",
77
82
  label: "Level",
@@ -105,6 +110,65 @@ built for `/panel/host` (the `SettingsPanelField` type from `/panel`) gain the o
105
110
  `visible(ctx, scope)`, `disabled(ctx, scope)` and `customEditor(hostContext)`, where the
106
111
  host context omits `values`. See the [recipes](recipes.md) for complete examples.
107
112
 
113
+ ## Secondary menus
114
+
115
+ A secondary menu is a row that opens a nested page of fields inside the same frame. Use it for
116
+ entries that a fixed field list cannot hold, such as records kept in files. Declared panels
117
+ take `menus`, listed after the fields in the same group order rules:
118
+
119
+ ```ts
120
+ defineSettingsPanel(settings, {
121
+ label: "Agents",
122
+ fields: (field) => [field("enabled", { label: "Enabled" })],
123
+ menus: [
124
+ {
125
+ id: "files",
126
+ label: "Agent files",
127
+ summary: ({ scope }) => `${listFiles(scope).length} files`,
128
+ open: ({ scope }) => ({
129
+ fields: listFiles(scope).map((file) => fileField(file, scope)),
130
+ emptyMessage: "No agent files yet.",
131
+ }),
132
+ },
133
+ ],
134
+ });
135
+ ```
136
+
137
+ `open({ values, scope, context })` returns a `SettingsMenu`: host-level `SettingsPanelField`
138
+ objects, which the consumer builds with its own `inspect`, `set` and `reset`, and an optional
139
+ `emptyMessage`. A menu ID must not repeat a field ID (a path, or a nested path as JSON).
140
+
141
+ To move declared Settings fields onto a page, give the menu no `open` and name it in each
142
+ field's `inMenu`. The page lists those fields in their declared order, with the usual editors,
143
+ scopes and group rules, and the section no longer lists them:
144
+
145
+ ```ts
146
+ defineSettingsPanel(settings, {
147
+ label: "Routing",
148
+ fields: (field) => [
149
+ field("enabled", { label: "Enabled" }),
150
+ field(["tiers", "fast"], { label: "Fast", inMenu: "tiers" }),
151
+ field(["tiers", "strong"], { label: "Strong", inMenu: "tiers" }),
152
+ ],
153
+ menus: [{ id: "tiers", label: "Tiers", summary: ({ values }) => describe(values.tiers) }],
154
+ });
155
+ ```
156
+
157
+ A menu needs either `open` or at least one field that names it, not both, and `inMenu` must
158
+ name a menu of the same panel.
159
+ `summary`, `visible` and `disabled` work like the matching field options. Custom hosts build a
160
+ menu row with `createSettingsMenuField({ id, label, scopes, summary?, menu })`, and menu fields
161
+ may be menu rows themselves, so menus nest.
162
+
163
+ The renderer marks menu rows with `→` and shows the summary as the row value. Enter opens the
164
+ menu, Esc goes back one level, and the title shows the path, such as
165
+ `Lune settings › Agents › reviewer · global`. The open menu is kept as the IDs on its path and
166
+ built again from its rows on every refresh: after each save, scope switch (Ctrl+G) or reload.
167
+ Its fields therefore follow external data, and a menu whose row disappears closes; keep row IDs
168
+ stable when an entry changes. Switching sections closes every menu. A menu row has no value:
169
+ Ctrl+R on it reports that the settings inside it are reset there, and `set` and `reset` of a
170
+ `createSettingsMenuField` row reject.
171
+
108
172
  ## Opening and keyboard controls
109
173
 
110
174
  Import `openSettingsPanel` from `/panel/tui`, not `/panel`.
@@ -120,9 +184,12 @@ Equal labels are ordered by section ID using the same comparison. Membership cha
120
184
  reapply this order while preserving the selected section if it remains registered.
121
185
  The registry itself still returns registration order.
122
186
 
123
- - Main list: Tab/Shift+Tab switch sections; Ctrl+G switches global/project;
187
+ - Main list: Tab/Shift+Tab or Right/Left switch sections; Ctrl+G switches global/project;
124
188
  Ctrl+R resets the selected override; Ctrl+S reloads the active section (or retries one that failed to load).
189
+ Enter on a menu row opens it; Escape goes back one menu, then closes the panel.
125
190
  - Editor: Enter saves; Ctrl+S saves and then reloads; Escape discards the candidate.
191
+ Text inputs, choice lists and custom editors keep Left/Right, so arrows do not switch
192
+ sections while one is open.
126
193
  - Choice list: type to search; Tab switches candidate ranges; Ctrl+R explicitly refreshes
127
194
  supported sources; Space toggles multiple selections.
128
195
  - Preview choices render unsaved candidates; persistence occurs only on confirmation.
@@ -32,15 +32,15 @@ internal observer, without another lifecycle owner or public subscription API.
32
32
 
33
33
  ## Initialization and ownership
34
34
 
35
- | Resource | Owner | Retirement |
36
- | --- | --- | --- |
37
- | Static Settings/Panel definitions | Declaring plugin | No runtime resources |
38
- | Binding listeners and pending acquisition | SettingsBinding | Shutdown/explicit dispose |
39
- | View, subscriptions and backend token | Binding or explicit lease owner | Session retirement |
40
- | Shared namespaces and file queues | Core Host | Last reference/queue settlement |
41
- | Panel section and binding subscription | SettingsPanelRegistration | Dispose/binding retirement |
42
- | Editor, choices, preview and interaction subscriptions | Open Panel interaction | Close/section removal/view retirement |
43
- | Business timers, requests and local objects | Plugin | Its native lifecycle and business policy |
35
+ | Resource | Owner | Retirement |
36
+ | ------------------------------------------------------ | ------------------------------- | ---------------------------------------- |
37
+ | Static Settings/Panel definitions | Declaring plugin | No runtime resources |
38
+ | Binding listeners and pending acquisition | SettingsBinding | Shutdown/explicit dispose |
39
+ | View, subscriptions and backend token | Binding or explicit lease owner | Session retirement |
40
+ | Shared namespaces and file queues | Core Host | Last reference/queue settlement |
41
+ | Panel section and binding subscription | SettingsPanelRegistration | Dispose/binding retirement |
42
+ | Editor, choices, preview and interaction subscriptions | Open Panel interaction | Close/section removal/view retirement |
43
+ | Business timers, requests and local objects | Plugin | Its native lifecycle and business policy |
44
44
 
45
45
  `scopedExtension((pi, resources) => ...)` is the preferred wrapper: it creates the
46
46
  ResourceScope, registers its `session_shutdown` disposer first, runs setup, and disposes
package/docs/recipes.md CHANGED
@@ -86,9 +86,7 @@ reference with Pi when you use it:
86
86
 
87
87
  ```ts
88
88
  const reference = view.get("model");
89
- const model = reference
90
- ? ctx.modelRegistry.find(reference.provider, reference.id)
91
- : ctx.model; // "Follow session model"
89
+ const model = reference ? ctx.modelRegistry.find(reference.provider, reference.id) : ctx.model; // "Follow session model"
92
90
  ```
93
91
 
94
92
  ## React to changes
@@ -134,7 +132,7 @@ const settings = defineSettings({
134
132
 
135
133
  Rules of thumb:
136
134
 
137
- - The current version is `migrations.length + 1`. Stored data at version *n* passes through
135
+ - The current version is `migrations.length + 1`. Stored data at version _n_ passes through
138
136
  `migrations[n - 1]`, so append new migrations and never reorder or delete shipped ones.
139
137
  - A migration receives an isolated copy of one file's overrides (no defaults, no
140
138
  `$version`) and returns the overrides for the next version. Keep it synchronous and pure.
@@ -322,10 +320,7 @@ class ListEditor implements SettingsEditorComponent {
322
320
  readonly help = "Enter save · comma-separated";
323
321
  private readonly input = new Input();
324
322
 
325
- constructor(
326
- value: readonly string[],
327
- submit: (value: string[]) => void,
328
- ) {
323
+ constructor(value: readonly string[], submit: (value: string[]) => void) {
329
324
  this.input.setValue(value.join(", "));
330
325
  this.input.onSubmit = (text) =>
331
326
  submit(