pi-subagent-manager 1.10.0 → 1.11.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 (186) hide show
  1. package/dist/index.d.ts +3 -0
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +836 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/orch/checklist-integration.d.ts +48 -0
  6. package/dist/orch/checklist-integration.d.ts.map +1 -0
  7. package/dist/orch/checklist-integration.js +204 -0
  8. package/dist/orch/checklist-integration.js.map +1 -0
  9. package/dist/orch/context-entries.d.ts +8 -0
  10. package/dist/orch/context-entries.d.ts.map +1 -0
  11. package/dist/orch/context-entries.js +8 -0
  12. package/dist/orch/context-entries.js.map +1 -0
  13. package/dist/orch/cost-ledger.d.ts +16 -0
  14. package/dist/orch/cost-ledger.d.ts.map +1 -0
  15. package/dist/orch/cost-ledger.js +43 -0
  16. package/dist/orch/cost-ledger.js.map +1 -0
  17. package/dist/orch/diagnostics.d.ts +13 -0
  18. package/dist/orch/diagnostics.d.ts.map +1 -0
  19. package/dist/orch/diagnostics.js +95 -0
  20. package/dist/orch/diagnostics.js.map +1 -0
  21. package/dist/orch/extensions.d.ts +15 -0
  22. package/dist/orch/extensions.d.ts.map +1 -0
  23. package/dist/orch/extensions.js +80 -0
  24. package/dist/orch/extensions.js.map +1 -0
  25. package/dist/orch/housekeeping-usage.d.ts +14 -0
  26. package/dist/orch/housekeeping-usage.d.ts.map +1 -0
  27. package/dist/orch/housekeeping-usage.js +27 -0
  28. package/dist/orch/housekeeping-usage.js.map +1 -0
  29. package/dist/orch/housekeeping.d.ts +89 -0
  30. package/dist/orch/housekeeping.d.ts.map +1 -0
  31. package/dist/orch/housekeeping.js +281 -0
  32. package/dist/orch/housekeeping.js.map +1 -0
  33. package/dist/orch/inherited-tools.d.ts +18 -0
  34. package/dist/orch/inherited-tools.d.ts.map +1 -0
  35. package/dist/orch/inherited-tools.js +71 -0
  36. package/dist/orch/inherited-tools.js.map +1 -0
  37. package/dist/orch/mailbox.d.ts +59 -0
  38. package/dist/orch/mailbox.d.ts.map +1 -0
  39. package/dist/orch/mailbox.js +196 -0
  40. package/dist/orch/mailbox.js.map +1 -0
  41. package/dist/orch/manager.d.ts +82 -0
  42. package/dist/orch/manager.d.ts.map +1 -0
  43. package/dist/orch/manager.js +1010 -0
  44. package/dist/orch/manager.js.map +1 -0
  45. package/dist/orch/paths.d.ts +7 -0
  46. package/dist/orch/paths.d.ts.map +1 -0
  47. package/dist/orch/paths.js +73 -0
  48. package/dist/orch/paths.js.map +1 -0
  49. package/dist/orch/prompt.d.ts +7 -0
  50. package/dist/orch/prompt.d.ts.map +1 -0
  51. package/dist/orch/prompt.js +34 -0
  52. package/dist/orch/prompt.js.map +1 -0
  53. package/dist/orch/registry.d.ts +49 -0
  54. package/dist/orch/registry.d.ts.map +1 -0
  55. package/dist/orch/registry.js +134 -0
  56. package/dist/orch/registry.js.map +1 -0
  57. package/dist/orch/runtime.d.ts +11 -0
  58. package/dist/orch/runtime.d.ts.map +1 -0
  59. package/dist/orch/runtime.js +882 -0
  60. package/dist/orch/runtime.js.map +1 -0
  61. package/dist/orch/tools.d.ts +6 -0
  62. package/dist/orch/tools.d.ts.map +1 -0
  63. package/dist/orch/tools.js +114 -0
  64. package/dist/orch/tools.js.map +1 -0
  65. package/dist/orch/transcript.d.ts +28 -0
  66. package/dist/orch/transcript.d.ts.map +1 -0
  67. package/dist/orch/transcript.js +176 -0
  68. package/dist/orch/transcript.js.map +1 -0
  69. package/dist/prefs/agent-import.d.ts +37 -0
  70. package/dist/prefs/agent-import.d.ts.map +1 -0
  71. package/dist/prefs/agent-import.js +196 -0
  72. package/dist/prefs/agent-import.js.map +1 -0
  73. package/dist/prefs/config.d.ts +108 -0
  74. package/dist/prefs/config.d.ts.map +1 -0
  75. package/dist/prefs/config.js +926 -0
  76. package/dist/prefs/config.js.map +1 -0
  77. package/dist/prefs/import-discovery.d.ts +28 -0
  78. package/dist/prefs/import-discovery.d.ts.map +1 -0
  79. package/dist/prefs/import-discovery.js +562 -0
  80. package/dist/prefs/import-discovery.js.map +1 -0
  81. package/dist/prefs/import-instructions.d.ts +3 -0
  82. package/dist/prefs/import-instructions.d.ts.map +1 -0
  83. package/{src/prefs/import-instructions.ts → dist/prefs/import-instructions.js} +1 -0
  84. package/dist/prefs/import-instructions.js.map +1 -0
  85. package/dist/prefs/models.d.ts +24 -0
  86. package/dist/prefs/models.d.ts.map +1 -0
  87. package/dist/prefs/models.js +57 -0
  88. package/dist/prefs/models.js.map +1 -0
  89. package/dist/prefs/settings.d.ts +89 -0
  90. package/dist/prefs/settings.d.ts.map +1 -0
  91. package/dist/prefs/settings.js +505 -0
  92. package/dist/prefs/settings.js.map +1 -0
  93. package/dist/types.d.ts +293 -0
  94. package/dist/types.d.ts.map +1 -0
  95. package/dist/types.js +2 -0
  96. package/dist/types.js.map +1 -0
  97. package/dist/ui/agent-loader.d.ts +21 -0
  98. package/dist/ui/agent-loader.d.ts.map +1 -0
  99. package/dist/ui/agent-loader.js +73 -0
  100. package/dist/ui/agent-loader.js.map +1 -0
  101. package/dist/ui/agent-navigation-editor.d.ts +46 -0
  102. package/dist/ui/agent-navigation-editor.d.ts.map +1 -0
  103. package/dist/ui/agent-navigation-editor.js +189 -0
  104. package/dist/ui/agent-navigation-editor.js.map +1 -0
  105. package/dist/ui/cost-footer.d.ts +37 -0
  106. package/dist/ui/cost-footer.d.ts.map +1 -0
  107. package/dist/ui/cost-footer.js +215 -0
  108. package/dist/ui/cost-footer.js.map +1 -0
  109. package/dist/ui/dialog.d.ts +135 -0
  110. package/dist/ui/dialog.d.ts.map +1 -0
  111. package/dist/ui/dialog.js +533 -0
  112. package/dist/ui/dialog.js.map +1 -0
  113. package/dist/ui/import-picker.d.ts +38 -0
  114. package/dist/ui/import-picker.d.ts.map +1 -0
  115. package/dist/ui/import-picker.js +211 -0
  116. package/dist/ui/import-picker.js.map +1 -0
  117. package/dist/ui/live-agent-view.d.ts +82 -0
  118. package/dist/ui/live-agent-view.d.ts.map +1 -0
  119. package/dist/ui/live-agent-view.js +546 -0
  120. package/dist/ui/live-agent-view.js.map +1 -0
  121. package/dist/ui/model-picker.d.ts +109 -0
  122. package/dist/ui/model-picker.d.ts.map +1 -0
  123. package/dist/ui/model-picker.js +549 -0
  124. package/dist/ui/model-picker.js.map +1 -0
  125. package/dist/ui/settings-ui.d.ts +17 -0
  126. package/dist/ui/settings-ui.d.ts.map +1 -0
  127. package/dist/ui/settings-ui.js +679 -0
  128. package/dist/ui/settings-ui.js.map +1 -0
  129. package/dist/ui/status-ui.d.ts +67 -0
  130. package/dist/ui/status-ui.d.ts.map +1 -0
  131. package/dist/ui/status-ui.js +487 -0
  132. package/dist/ui/status-ui.js.map +1 -0
  133. package/dist/ui/thread-tree.d.ts +22 -0
  134. package/dist/ui/thread-tree.d.ts.map +1 -0
  135. package/dist/ui/thread-tree.js +153 -0
  136. package/dist/ui/thread-tree.js.map +1 -0
  137. package/dist/ui/tool-picker.d.ts +46 -0
  138. package/dist/ui/tool-picker.d.ts.map +1 -0
  139. package/dist/ui/tool-picker.js +334 -0
  140. package/dist/ui/tool-picker.js.map +1 -0
  141. package/dist/ui/transcript-tool.d.ts +2 -0
  142. package/dist/ui/transcript-tool.d.ts.map +1 -0
  143. package/dist/ui/transcript-tool.js +100 -0
  144. package/dist/ui/transcript-tool.js.map +1 -0
  145. package/dist/ui/ui.d.ts +41 -0
  146. package/dist/ui/ui.d.ts.map +1 -0
  147. package/dist/ui/ui.js +1047 -0
  148. package/dist/ui/ui.js.map +1 -0
  149. package/docs/development.md +2 -1
  150. package/package.json +16 -4
  151. package/src/index.ts +0 -920
  152. package/src/orch/checklist-integration.ts +0 -230
  153. package/src/orch/context-entries.ts +0 -15
  154. package/src/orch/cost-ledger.ts +0 -56
  155. package/src/orch/diagnostics.ts +0 -95
  156. package/src/orch/extensions.ts +0 -83
  157. package/src/orch/housekeeping-usage.ts +0 -47
  158. package/src/orch/housekeeping.ts +0 -348
  159. package/src/orch/inherited-tools.ts +0 -84
  160. package/src/orch/mailbox.ts +0 -261
  161. package/src/orch/manager.ts +0 -1084
  162. package/src/orch/paths.ts +0 -73
  163. package/src/orch/prompt.ts +0 -39
  164. package/src/orch/registry.ts +0 -168
  165. package/src/orch/runtime.ts +0 -1041
  166. package/src/orch/tools.ts +0 -190
  167. package/src/orch/transcript.ts +0 -186
  168. package/src/prefs/agent-import.ts +0 -245
  169. package/src/prefs/config.ts +0 -1017
  170. package/src/prefs/import-discovery.ts +0 -643
  171. package/src/prefs/models.ts +0 -74
  172. package/src/prefs/settings.ts +0 -614
  173. package/src/types.ts +0 -271
  174. package/src/ui/agent-loader.ts +0 -98
  175. package/src/ui/agent-navigation-editor.ts +0 -233
  176. package/src/ui/cost-footer.ts +0 -230
  177. package/src/ui/dialog.ts +0 -678
  178. package/src/ui/import-picker.ts +0 -231
  179. package/src/ui/live-agent-view.ts +0 -600
  180. package/src/ui/model-picker.ts +0 -701
  181. package/src/ui/settings-ui.ts +0 -830
  182. package/src/ui/status-ui.ts +0 -628
  183. package/src/ui/thread-tree.ts +0 -173
  184. package/src/ui/tool-picker.ts +0 -398
  185. package/src/ui/transcript-tool.ts +0 -142
  186. package/src/ui/ui.ts +0 -1407
@@ -0,0 +1,109 @@
1
+ import type { Api, Model } from "@earendil-works/pi-ai";
2
+ import { type ExtensionCommandContext, type ScopedModel, type Theme } from "@earendil-works/pi-coding-agent";
3
+ import { Container, Input, SelectList, type SelectItem } from "@earendil-works/pi-tui";
4
+ export declare const MODEL_EDITOR_CANCEL: unique symbol;
5
+ type AvailableModel = Pick<Model<Api>, "provider" | "id" | "name">;
6
+ interface OrderedModelEditorComponentOptions {
7
+ tui: {
8
+ requestRender(force?: boolean): void;
9
+ terminal?: {
10
+ rows: number;
11
+ };
12
+ };
13
+ theme: Theme;
14
+ availableModels: readonly AvailableModel[];
15
+ scopedModels: readonly ScopedModel[];
16
+ initialModels?: readonly string[];
17
+ modelSuggestions?: readonly string[];
18
+ onDone(models: string[]): void;
19
+ onCancel(): void;
20
+ }
21
+ export declare class OrderedModelEditorComponent extends Container {
22
+ private readonly tui;
23
+ private readonly theme;
24
+ private readonly allModels;
25
+ private readonly modelSearch;
26
+ private readonly suggestedScores;
27
+ private readonly modelsByIdentity;
28
+ private readonly scopedIdentities;
29
+ private readonly onDone;
30
+ private readonly onCancel;
31
+ private readonly titleText;
32
+ private readonly subtitleText;
33
+ private readonly footerText;
34
+ private readonly searchInput;
35
+ private draft;
36
+ private pickerQuery;
37
+ private searching;
38
+ private currentItems;
39
+ private selectList;
40
+ private _focused;
41
+ constructor(options: OrderedModelEditorComponentOptions);
42
+ get focused(): boolean;
43
+ set focused(value: boolean);
44
+ getMode(): "picker";
45
+ getDraftModels(): readonly string[];
46
+ getCurrentItems(): readonly SelectItem[];
47
+ getSelectList(): SelectList;
48
+ getSearchInput(): Input;
49
+ render(width: number): string[];
50
+ handleInput(keyData: string): void;
51
+ private setSearching;
52
+ private updateFooter;
53
+ private refreshPickerList;
54
+ private searchScores;
55
+ private getPickerItems;
56
+ private describeDraftIdentity;
57
+ private withScopeWarning;
58
+ }
59
+ export declare function editModelPreferences(ctx: ExtensionCommandContext, currentModels?: readonly string[], modelSuggestions?: readonly string[]): Promise<readonly string[] | typeof MODEL_EDITOR_CANCEL>;
60
+ export declare const HOUSEKEEPING_PICKER_CANCEL: unique symbol;
61
+ interface HousekeepingRow {
62
+ /** `provider/model-id`; empty string clears the selection. */
63
+ value: string;
64
+ label: string;
65
+ description: string;
66
+ group: string;
67
+ }
68
+ /**
69
+ * Single-select picker over available models, scoped models listed first.
70
+ * Typing searches; Enter selects; Esc cancels. "No model" clears the selection.
71
+ */
72
+ export declare class HousekeepingModelPickerComponent extends Container {
73
+ private readonly tui;
74
+ private readonly theme;
75
+ private readonly allModels;
76
+ private readonly modelSearch;
77
+ private readonly scopedIdentities;
78
+ private readonly current;
79
+ private readonly onDone;
80
+ private readonly onCancel;
81
+ private readonly searchInput;
82
+ private rows;
83
+ private selected;
84
+ private _focused;
85
+ constructor(options: {
86
+ tui: {
87
+ requestRender(force?: boolean): void;
88
+ terminal?: {
89
+ rows: number;
90
+ };
91
+ };
92
+ theme: Theme;
93
+ availableModels: readonly AvailableModel[];
94
+ scopedModels: readonly ScopedModel[];
95
+ current?: string;
96
+ onDone(identity: string): void;
97
+ onCancel(): void;
98
+ });
99
+ get focused(): boolean;
100
+ set focused(value: boolean);
101
+ getRows(): readonly HousekeepingRow[];
102
+ getSelectedValue(): string | undefined;
103
+ render(width: number): string[];
104
+ handleInput(keyData: string): void;
105
+ private refresh;
106
+ }
107
+ export declare function pickHousekeepingModel(ctx: ExtensionCommandContext, current: string): Promise<string | typeof HOUSEKEEPING_PICKER_CANCEL>;
108
+ export {};
109
+ //# sourceMappingURL=model-picker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-picker.d.ts","sourceRoot":"","sources":["../../src/ui/model-picker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAEL,KAAK,uBAAuB,EAC5B,KAAK,WAAW,EAChB,KAAK,KAAK,EACX,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,SAAS,EAET,KAAK,EAGL,UAAU,EAIV,KAAK,UAAU,EAChB,MAAM,wBAAwB,CAAC;AAahC,eAAO,MAAM,mBAAmB,eAAgC,CAAC;AAEjE,KAAK,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,UAAU,GAAG,IAAI,GAAG,MAAM,CAAC,CAAC;AAMnE,UAAU,kCAAkC;IAC1C,GAAG,EAAE;QAAE,aAAa,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;QAAC,QAAQ,CAAC,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;IAC3E,KAAK,EAAE,KAAK,CAAC;IAC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ACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA+C;IAC3E,OAAO,CAAC,IAAI,CAAyB;IACrC,OAAO,CAAC,QAAQ,CAAK;IACrB,OAAO,CAAC,QAAQ,CAAS;gBAEb,OAAO,EAAE;QACnB,GAAG,EAAE;YAAE,aAAa,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;YAAC,QAAQ,CAAC,EAAE;gBAAE,IAAI,EAAE,MAAM,CAAA;aAAE,CAAA;SAAE,CAAC;QAC3E,KAAK,EAAE,KAAK,CAAC;QACb,eAAe,EAAE,SAAS,cAAc,EAAE,CAAC;QAC3C,YAAY,EAAE,SAAS,WAAW,EAAE,CAAC;QACrC,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;QAC/B,QAAQ,IAAI,IAAI,CAAC;KAClB;IAoBD,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,EAGzB;IAED,OAAO,IAAI,SAAS,eAAe,EAAE;IAIrC,gBAAgB,IAAI,MAAM,GAAG,SAAS;IAItC,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE;IAuC/B,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAsBlC,OAAO,CAAC,OAAO;CA0DhB;AAED,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,uBAAuB,EAC5B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,GAAG,OAAO,0BAA0B,CAAC,CAwBrD"}
@@ -0,0 +1,549 @@
1
+ import fuzzysort from "fuzzysort";
2
+ import { getSelectListTheme, } from "@earendil-works/pi-coding-agent";
3
+ import { Container, getKeybindings, Input, Key, matchesKey, SelectList, stripTerminalSequences, truncateToWidth, Text, } from "@earendil-works/pi-tui";
4
+ import { modelIdentity } from "../prefs/models.js";
5
+ import { dialogHeight, frameDialog, DIALOG_OPTIONS } from "./dialog.js";
6
+ const MODEL_EDITOR_LAYOUT = {
7
+ minPrimaryColumnWidth: 24,
8
+ maxPrimaryColumnWidth: 52,
9
+ };
10
+ const PICKER_TITLE = "Preferred models";
11
+ const SELECTED_GROUP = "Selected models · ordered fallback";
12
+ const ACTIONS_GROUP = "Actions";
13
+ export const MODEL_EDITOR_CANCEL = Symbol("model-editor-cancel");
14
+ function sanitizeModelText(text) {
15
+ return stripTerminalSequences(text).replace(/[\x00-\x1f\x7f-\x9f]/g, " ");
16
+ }
17
+ function renderModelIdentity(identity) {
18
+ return sanitizeModelText(identity);
19
+ }
20
+ function modelSearchText(text) {
21
+ // Providers spell the same version differently (sonnet-5.5 vs sonnet-5-5).
22
+ // Strip separators rather than splitting them into repeated numeric terms;
23
+ // raw identities and labels remain untouched.
24
+ return sanitizeModelText(text).replace(/[._:/-]+/g, "");
25
+ }
26
+ function sortModels(models) {
27
+ const unique = new Map();
28
+ for (const model of models)
29
+ unique.set(modelIdentity(model), model);
30
+ return [...unique.values()].sort((a, b) => a.provider.localeCompare(b.provider) ||
31
+ a.id.localeCompare(b.id) ||
32
+ sanitizeModelText(a.name).localeCompare(sanitizeModelText(b.name)));
33
+ }
34
+ function describeModel(model, scopedIdentities) {
35
+ const annotation = scopedIdentities.has(modelIdentity(model))
36
+ ? "scoped in this session"
37
+ : "portable preference · not scoped in this session";
38
+ const name = sanitizeModelText(model.name);
39
+ return [name, annotation].filter(Boolean).join(" · ");
40
+ }
41
+ export class OrderedModelEditorComponent extends Container {
42
+ tui;
43
+ theme;
44
+ allModels;
45
+ modelSearch;
46
+ suggestedScores;
47
+ modelsByIdentity = new Map();
48
+ scopedIdentities;
49
+ onDone;
50
+ onCancel;
51
+ titleText = new Text();
52
+ subtitleText = new Text();
53
+ footerText = new Text();
54
+ searchInput = new Input({ placeholder: "Search models" });
55
+ draft;
56
+ pickerQuery = "";
57
+ searching = false;
58
+ currentItems = [];
59
+ selectList = new SelectList([], 1, getSelectListTheme(), MODEL_EDITOR_LAYOUT);
60
+ _focused = false;
61
+ constructor(options) {
62
+ super();
63
+ this.tui = options.tui;
64
+ this.theme = options.theme;
65
+ this.allModels = sortModels(options.availableModels);
66
+ // The registry is fixed for this dialog; prepare searchable fields once.
67
+ // Scope annotations deliberately aren't searchable model metadata.
68
+ this.modelSearch = fuzzysort.snapshot(this.allModels, {
69
+ keys: [
70
+ (model) => modelSearchText(modelIdentity(model)),
71
+ (model) => modelSearchText(model.name),
72
+ ],
73
+ });
74
+ this.suggestedScores = this.searchScores(options.modelSuggestions ?? []);
75
+ this.onDone = options.onDone;
76
+ this.onCancel = options.onCancel;
77
+ for (const model of this.allModels)
78
+ this.modelsByIdentity.set(modelIdentity(model), model);
79
+ this.scopedIdentities = new Set(options.scopedModels.map((entry) => modelIdentity(entry.model)));
80
+ this.draft = [...new Set(options.initialModels ?? [])];
81
+ this.titleText.setText(this.theme.fg("accent", PICKER_TITLE));
82
+ this.subtitleText.setText(this.theme.fg("muted", this.withScopeWarning(this.suggestedScores.size
83
+ ? "Selected first; suggested matches scoped first, then other models; the rest A–Z. / to search."
84
+ : "Selected first. / to search by provider/id or model name; other models A–Z.")));
85
+ this.updateFooter();
86
+ this.addChild(this.searchInput);
87
+ this.refreshPickerList();
88
+ }
89
+ get focused() {
90
+ return this._focused;
91
+ }
92
+ set focused(value) {
93
+ this._focused = value;
94
+ this.searchInput.focused = value && this.searching;
95
+ }
96
+ getMode() {
97
+ return "picker";
98
+ }
99
+ getDraftModels() {
100
+ return this.draft;
101
+ }
102
+ getCurrentItems() {
103
+ return this.currentItems;
104
+ }
105
+ getSelectList() {
106
+ return this.selectList;
107
+ }
108
+ getSearchInput() {
109
+ return this.searchInput;
110
+ }
111
+ render(width) {
112
+ const height = dialogHeight(this.tui);
113
+ const inner = Math.max(1, width - 4);
114
+ const header = [
115
+ truncateToWidth(this.subtitleText
116
+ .render(1000)
117
+ .map((line) => line.trim())
118
+ .filter(Boolean)
119
+ .join(" "), inner, ""),
120
+ ...this.searchInput.render(inner),
121
+ ];
122
+ const budget = Math.max(1, height - 4 - header.length);
123
+ const selected = this.selectList.getSelectedItem()?.value;
124
+ // Headings are visual rows only: keyboard navigation selects models, not groups.
125
+ const displayRows = [];
126
+ let previousGroup;
127
+ const hasResults = this.currentItems.some((item) => item.group !== SELECTED_GROUP && item.group !== ACTIONS_GROUP);
128
+ for (const item of this.currentItems) {
129
+ if (item.group !== previousGroup) {
130
+ if (item.group === ACTIONS_GROUP && !hasResults)
131
+ displayRows.push("No matching models");
132
+ displayRows.push(item.group);
133
+ }
134
+ previousGroup = item.group;
135
+ displayRows.push(item);
136
+ }
137
+ const index = Math.max(0, displayRows.findIndex((row) => typeof row !== "string" && row.value === selected));
138
+ const start = Math.max(0, Math.min(index - budget + 1, displayRows.length - budget));
139
+ // Only format visible rows; a registry can contain thousands of models.
140
+ const rows = displayRows.slice(start, start + budget).map((row) => {
141
+ if (typeof row === "string")
142
+ return this.theme.fg("muted", row);
143
+ const text = `${row.value === selected ? "›" : " "} ${row.label} ${this.theme.fg("muted", row.description ?? "")}`;
144
+ return row.value === selected ? this.theme.fg("accent", text) : text;
145
+ });
146
+ return frameDialog(this.theme, width, height, this.titleText.render(1000).join(" ").trim(), [...header, ...rows].map((line) => ` ${line}`), this.footerText
147
+ .render(1000)
148
+ .map((line) => line.trim())
149
+ .filter(Boolean)
150
+ .join(" "));
151
+ }
152
+ handleInput(keyData) {
153
+ if (matchesKey(keyData, Key.ctrl("s"))) {
154
+ this.onDone([...this.draft]);
155
+ return;
156
+ }
157
+ if (matchesKey(keyData, Key.tab) || (!this.searching && keyData === "/")) {
158
+ this.setSearching(!this.searching);
159
+ this.tui.requestRender();
160
+ return;
161
+ }
162
+ const earlier = !this.searching && (keyData === "w" || matchesKey(keyData, Key.ctrl("up")));
163
+ const later = !this.searching && (keyData === "s" || matchesKey(keyData, Key.ctrl("down")));
164
+ if (earlier || later) {
165
+ const selected = this.selectList.getSelectedItem()?.value;
166
+ const index = selected === undefined ? -1 : this.draft.indexOf(selected);
167
+ const next = index + (earlier ? -1 : 1);
168
+ // Consume reorder keys even on unselected models or at a list boundary.
169
+ if (index >= 0 && next >= 0 && next < this.draft.length) {
170
+ [this.draft[index], this.draft[next]] = [this.draft[next], this.draft[index]];
171
+ this.refreshPickerList(selected);
172
+ this.tui.requestRender();
173
+ }
174
+ return;
175
+ }
176
+ const kb = getKeybindings();
177
+ const isNav = kb.matches(keyData, "tui.select.up") ||
178
+ kb.matches(keyData, "tui.select.down") ||
179
+ kb.matches(keyData, "tui.select.confirm") ||
180
+ kb.matches(keyData, "tui.select.cancel");
181
+ if (isNav) {
182
+ this.selectList.handleInput(keyData);
183
+ }
184
+ else {
185
+ this.searchInput.handleInput(keyData);
186
+ const nextQuery = this.searchInput.getValue();
187
+ if (nextQuery !== this.pickerQuery) {
188
+ this.setSearching(true);
189
+ this.pickerQuery = nextQuery;
190
+ // Keep selected preferences visible, but focus the first search result
191
+ // so typing a query and pressing Enter still adds the matching model.
192
+ this.refreshPickerList(undefined, true);
193
+ }
194
+ }
195
+ this.tui.requestRender();
196
+ }
197
+ setSearching(value) {
198
+ this.searching = value;
199
+ this.searchInput.focused = this._focused && value;
200
+ this.updateFooter();
201
+ }
202
+ updateFooter() {
203
+ this.footerText.setText(this.theme.fg("dim", this.searching
204
+ ? "↑↓ select · Enter toggle · Tab browse · Ctrl+S done · Esc cancel"
205
+ : "↑↓ · Enter toggle · w/s | Ctrlꜛꜜ reorder · / search · Ctrl+S done · Esc cancel"));
206
+ }
207
+ refreshPickerList(selectedValue, focusSearchResult = false) {
208
+ const previousIndex = this.currentItems.findIndex((item) => item.value === this.selectList.getSelectedItem()?.value);
209
+ this.currentItems = [
210
+ ...this.draft.map((identity, index) => ({
211
+ value: identity,
212
+ label: `[x] ${index + 1}. ${renderModelIdentity(identity)}`,
213
+ description: this.describeDraftIdentity(identity),
214
+ group: SELECTED_GROUP,
215
+ })),
216
+ ...this.getPickerItems(),
217
+ {
218
+ value: "action:done",
219
+ label: "Done",
220
+ description: "Commit this ordered model preference list",
221
+ group: ACTIONS_GROUP,
222
+ },
223
+ {
224
+ value: "action:clear",
225
+ label: "Use inherited default",
226
+ description: "Clear explicit preferences and inherit the default model",
227
+ group: ACTIONS_GROUP,
228
+ },
229
+ {
230
+ value: "action:cancel",
231
+ label: "Cancel",
232
+ description: "Discard unsaved model preference changes",
233
+ group: ACTIONS_GROUP,
234
+ },
235
+ ];
236
+ const list = new SelectList(this.currentItems, Math.min(this.currentItems.length, 10), getSelectListTheme(), MODEL_EDITOR_LAYOUT);
237
+ const preferredIndex = focusSearchResult
238
+ ? this.currentItems.findIndex((item) => item.group !== SELECTED_GROUP && item.group !== ACTIONS_GROUP)
239
+ : this.currentItems.findIndex((item) => item.value === selectedValue);
240
+ list.setSelectedIndex(preferredIndex >= 0
241
+ ? preferredIndex
242
+ : focusSearchResult
243
+ ? 0
244
+ : Math.max(0, Math.min(previousIndex, this.currentItems.length - 1)));
245
+ list.onSelect = (item) => {
246
+ if (this.currentItems.find((row) => row.value === item.value)?.group === ACTIONS_GROUP) {
247
+ if (item.value === "action:done")
248
+ this.onDone([...this.draft]);
249
+ else if (item.value === "action:cancel")
250
+ this.onCancel();
251
+ else {
252
+ this.draft = [];
253
+ this.refreshPickerList("action:done");
254
+ this.tui.requestRender();
255
+ }
256
+ return;
257
+ }
258
+ const index = this.draft.indexOf(item.value);
259
+ if (index >= 0)
260
+ this.draft.splice(index, 1);
261
+ else
262
+ this.draft.push(item.value);
263
+ this.refreshPickerList(item.value);
264
+ this.tui.requestRender();
265
+ };
266
+ list.onSelectionChange = () => this.tui.requestRender();
267
+ list.onCancel = () => this.onCancel();
268
+ this.selectList = list;
269
+ if (this.children[1])
270
+ this.children[1] = list;
271
+ else
272
+ this.addChild(list);
273
+ }
274
+ searchScores(queries) {
275
+ const scores = new Map();
276
+ const uniqueQueries = new Set(queries.map((query) => modelSearchText(query).trim()).filter(Boolean));
277
+ for (const query of uniqueQueries) {
278
+ // Both defaults are restrictive (10 results, score >= .5); collect every
279
+ // fuzzy match so suggestions aren't silently capped or omitted.
280
+ for (const result of fuzzysort.go(query, this.modelSearch, {
281
+ limit: 0,
282
+ threshold: 0,
283
+ })) {
284
+ const identity = modelIdentity(result.obj);
285
+ scores.set(identity, Math.max(scores.get(identity) ?? 0, result.score));
286
+ }
287
+ }
288
+ return scores;
289
+ }
290
+ getPickerItems() {
291
+ const excluded = new Set(this.draft);
292
+ const query = this.pickerQuery.trim();
293
+ const queryScores = query ? this.searchScores([query]) : undefined;
294
+ const scoped = [];
295
+ const other = [];
296
+ const remaining = [];
297
+ for (const model of this.allModels) {
298
+ const identity = modelIdentity(model);
299
+ if (excluded.has(identity) || (queryScores && !queryScores.has(identity)))
300
+ continue;
301
+ if (this.suggestedScores.has(identity)) {
302
+ (this.scopedIdentities.has(identity) ? scoped : other).push(model);
303
+ }
304
+ else {
305
+ remaining.push(model);
306
+ }
307
+ }
308
+ const bySuggestionScore = (a, b) => this.suggestedScores.get(modelIdentity(b)) - this.suggestedScores.get(modelIdentity(a));
309
+ // Stable score sorting preserves alphabetical order for ties. The last
310
+ // tier retains the registry's alphabetical order, irrespective of scope.
311
+ scoped.sort(bySuggestionScore);
312
+ other.sort(bySuggestionScore);
313
+ const items = (models, group) => models.map((model) => ({
314
+ value: modelIdentity(model),
315
+ label: `[ ] ${renderModelIdentity(modelIdentity(model))}`,
316
+ description: describeModel(model, this.scopedIdentities),
317
+ group,
318
+ }));
319
+ return [
320
+ ...items(scoped, "Suggested matches · scoped models"),
321
+ ...items(other, "Suggested matches · other models"),
322
+ ...items(remaining, scoped.length || other.length ? "All other models · A–Z" : "All models · A–Z"),
323
+ ];
324
+ }
325
+ describeDraftIdentity(identity) {
326
+ const model = this.modelsByIdentity.get(identity);
327
+ if (!model)
328
+ return "unavailable in current model registry";
329
+ return describeModel(model, this.scopedIdentities);
330
+ }
331
+ withScopeWarning(text) {
332
+ if (this.scopedIdentities.size === 0) {
333
+ return `No scope restriction: Pick First (scoped) uses all available models. ${text}`;
334
+ }
335
+ return text;
336
+ }
337
+ }
338
+ export async function editModelPreferences(ctx, currentModels, modelSuggestions) {
339
+ if (ctx.mode !== "tui") {
340
+ if (ctx.hasUI) {
341
+ ctx.ui.notify("Ordered model preferences require interactive TUI mode; draft unchanged.", "warning");
342
+ }
343
+ return MODEL_EDITOR_CANCEL;
344
+ }
345
+ const availableModels = ctx.modelRegistry.getAvailable().map((model) => ({
346
+ provider: model.provider,
347
+ id: model.id,
348
+ name: model.name,
349
+ }));
350
+ return ctx.ui.custom((tui, theme, _keys, done) => new OrderedModelEditorComponent({
351
+ tui,
352
+ theme,
353
+ availableModels,
354
+ scopedModels: ctx.scopedModels,
355
+ initialModels: currentModels,
356
+ modelSuggestions,
357
+ onDone: (models) => done(models),
358
+ onCancel: () => done(MODEL_EDITOR_CANCEL),
359
+ }), DIALOG_OPTIONS);
360
+ }
361
+ export const HOUSEKEEPING_PICKER_CANCEL = Symbol("housekeeping-picker-cancel");
362
+ const HOUSEKEEPING_TITLE = "[lab] Housekeeping model";
363
+ const CLEAR_GROUP = "Selection";
364
+ const SCOPED_GROUP = "Scoped models";
365
+ const OTHER_GROUP = "Other available models";
366
+ /**
367
+ * Single-select picker over available models, scoped models listed first.
368
+ * Typing searches; Enter selects; Esc cancels. "No model" clears the selection.
369
+ */
370
+ export class HousekeepingModelPickerComponent extends Container {
371
+ tui;
372
+ theme;
373
+ allModels;
374
+ modelSearch;
375
+ scopedIdentities;
376
+ current;
377
+ onDone;
378
+ onCancel;
379
+ searchInput = new Input({ placeholder: "Search models" });
380
+ rows = [];
381
+ selected = 0;
382
+ _focused = false;
383
+ constructor(options) {
384
+ super();
385
+ this.tui = options.tui;
386
+ this.theme = options.theme;
387
+ this.allModels = sortModels(options.availableModels);
388
+ this.modelSearch = fuzzysort.snapshot(this.allModels, {
389
+ keys: [
390
+ (model) => modelSearchText(modelIdentity(model)),
391
+ (model) => modelSearchText(model.name),
392
+ ],
393
+ });
394
+ this.scopedIdentities = new Set(options.scopedModels.map((entry) => modelIdentity(entry.model)));
395
+ this.current = options.current ?? "";
396
+ this.onDone = options.onDone;
397
+ this.onCancel = options.onCancel;
398
+ this.refresh();
399
+ }
400
+ get focused() {
401
+ return this._focused;
402
+ }
403
+ set focused(value) {
404
+ this._focused = value;
405
+ this.searchInput.focused = value;
406
+ }
407
+ getRows() {
408
+ return this.rows;
409
+ }
410
+ getSelectedValue() {
411
+ return this.rows[this.selected]?.value;
412
+ }
413
+ render(width) {
414
+ const height = dialogHeight(this.tui);
415
+ const inner = Math.max(1, width - 4);
416
+ const hint = this.scopedIdentities.size
417
+ ? "Scoped models first, then every other available model. Type to search."
418
+ : "No scoped models in this session; all available models are listed. Type to search.";
419
+ const header = [
420
+ truncateToWidth(this.theme.fg("muted", hint), inner, ""),
421
+ ...this.searchInput.render(inner),
422
+ ];
423
+ const budget = Math.max(1, height - 4 - header.length);
424
+ const display = [];
425
+ let previous;
426
+ for (const row of this.rows) {
427
+ if (row.group !== previous)
428
+ display.push(row.group);
429
+ previous = row.group;
430
+ display.push(row);
431
+ }
432
+ const selectedRow = this.rows[this.selected];
433
+ const index = Math.max(0, display.findIndex((row) => row === selectedRow));
434
+ const start = Math.max(0, Math.min(index - budget + 1, display.length - budget));
435
+ const lines = display.slice(start, start + budget).map((row) => {
436
+ if (typeof row === "string")
437
+ return this.theme.fg("muted", row);
438
+ const text = `${row === selectedRow ? "›" : " "} ${row.label} ${this.theme.fg("muted", row.description)}`;
439
+ return row === selectedRow ? this.theme.fg("accent", text) : text;
440
+ });
441
+ return frameDialog(this.theme, width, height, this.theme.fg("accent", HOUSEKEEPING_TITLE), [...header, ...lines].map((line) => ` ${line}`), this.theme.fg("dim", "↑↓ select · Enter choose · Esc cancel"));
442
+ }
443
+ handleInput(keyData) {
444
+ const kb = getKeybindings();
445
+ if (kb.matches(keyData, "tui.select.cancel"))
446
+ return this.onCancel();
447
+ if (kb.matches(keyData, "tui.select.confirm")) {
448
+ const row = this.rows[this.selected];
449
+ if (row)
450
+ this.onDone(row.value);
451
+ return;
452
+ }
453
+ if (kb.matches(keyData, "tui.select.up"))
454
+ this.selected = Math.max(0, this.selected - 1);
455
+ else if (kb.matches(keyData, "tui.select.down"))
456
+ this.selected = Math.min(this.rows.length - 1, this.selected + 1);
457
+ else if (matchesKey(keyData, Key.pageUp))
458
+ this.selected = Math.max(0, this.selected - 10);
459
+ else if (matchesKey(keyData, Key.pageDown))
460
+ this.selected = Math.min(this.rows.length - 1, this.selected + 10);
461
+ else {
462
+ const before = this.searchInput.getValue();
463
+ this.searchInput.handleInput(keyData);
464
+ if (this.searchInput.getValue() !== before)
465
+ this.refresh(true);
466
+ }
467
+ this.tui.requestRender();
468
+ }
469
+ refresh(resetSelection = false) {
470
+ const query = modelSearchText(this.searchInput.getValue()).trim();
471
+ let matches = [...this.allModels];
472
+ if (query) {
473
+ const scores = new Map();
474
+ for (const result of fuzzysort.go(query, this.modelSearch, { limit: 0, threshold: 0 }))
475
+ scores.set(modelIdentity(result.obj), result.score);
476
+ matches = matches
477
+ .filter((model) => scores.has(modelIdentity(model)))
478
+ .sort((a, b) => scores.get(modelIdentity(b)) - scores.get(modelIdentity(a)));
479
+ }
480
+ const describe = (model) => [sanitizeModelText(model.name), modelIdentity(model) === this.current ? "current" : ""]
481
+ .filter(Boolean)
482
+ .join(" · ");
483
+ const row = (model, group) => ({
484
+ value: modelIdentity(model),
485
+ label: renderModelIdentity(modelIdentity(model)),
486
+ description: describe(model),
487
+ group,
488
+ });
489
+ const known = this.allModels.some((model) => modelIdentity(model) === this.current);
490
+ const rows = [
491
+ {
492
+ value: "",
493
+ label: "No model",
494
+ description: "Leave housekeeping without a model (summaries stay inactive)",
495
+ group: CLEAR_GROUP,
496
+ },
497
+ ...(this.current && !known
498
+ ? [
499
+ {
500
+ value: this.current,
501
+ label: renderModelIdentity(this.current),
502
+ description: "current · unavailable in current model registry",
503
+ group: CLEAR_GROUP,
504
+ },
505
+ ]
506
+ : []),
507
+ ...matches
508
+ .filter((m) => this.scopedIdentities.has(modelIdentity(m)))
509
+ .map((m) => row(m, SCOPED_GROUP)),
510
+ ...matches
511
+ .filter((m) => !this.scopedIdentities.has(modelIdentity(m)))
512
+ .map((m) => row(m, OTHER_GROUP)),
513
+ ];
514
+ const previous = this.rows[this.selected]?.value;
515
+ this.rows = rows;
516
+ if (resetSelection) {
517
+ // Land on the best matching available model, never the clear row or an unavailable saved one.
518
+ const first = query ? rows.findIndex((r) => r.group !== CLEAR_GROUP) : -1;
519
+ this.selected = Math.max(0, first);
520
+ }
521
+ else {
522
+ const kept = rows.findIndex((r) => r.value === previous);
523
+ const initial = rows.findIndex((r) => r.value === this.current && this.current !== "");
524
+ this.selected = kept >= 0 ? kept : Math.max(0, initial);
525
+ }
526
+ }
527
+ }
528
+ export async function pickHousekeepingModel(ctx, current) {
529
+ if (ctx.mode !== "tui") {
530
+ if (ctx.hasUI)
531
+ ctx.ui.notify("The housekeeping model picker requires interactive TUI mode.", "warning");
532
+ return HOUSEKEEPING_PICKER_CANCEL;
533
+ }
534
+ const availableModels = ctx.modelRegistry.getAvailable().map((model) => ({
535
+ provider: model.provider,
536
+ id: model.id,
537
+ name: model.name,
538
+ }));
539
+ return ctx.ui.custom((tui, theme, _keys, done) => new HousekeepingModelPickerComponent({
540
+ tui,
541
+ theme,
542
+ availableModels,
543
+ scopedModels: ctx.scopedModels,
544
+ current,
545
+ onDone: (identity) => done(identity),
546
+ onCancel: () => done(HOUSEKEEPING_PICKER_CANCEL),
547
+ }), DIALOG_OPTIONS);
548
+ }
549
+ //# sourceMappingURL=model-picker.js.map