@rackrot/pi-council 0.0.1 → 0.3.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 rackrot
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -15,12 +15,12 @@ pi install npm:@rackrot/pi-council
15
15
 
16
16
  ## Configure and prompt injection
17
17
 
18
- `/council-config` opens a settings screen for both tools (Tab switches between global and project settings; type to search rows). It edits second_opinion's default model, options (model, id, use when, thinking), and the council's presets, councillors (model, thinking, role prompt), synthesizer and limits, and writes the same `council` settings shown below, then reloads pi. Fallback chains beyond the first model are edited in settings.json. `/council-config show` prints a summary.
18
+ `/rackrot-config council` opens a settings screen for both tools (Tab switches between global and project settings; type to search rows). It edits second_opinion's default model, options (model, id, use when, thinking), and the council's presets, councillors (model, thinking, role prompt), synthesizer and limits, and writes the same `council` config shown below, then reloads pi. Fallback chains beyond the first model are edited in the config file. `/rackrot-config show` prints a summary.
19
19
 
20
- Each tool's description carries its usage guidance, the default model and override options' `useWhen` text, or the preset rosters, and each adds a prompt snippet and guideline. These are fixed when pi loads the extension, so saving in the screen runs `/reload` for you; after editing settings.json by hand run `/reload` yourself. A disabled tool, or `council` with no presets, is not registered. Settings are still re-read on every call, so a model or prompt change takes effect even before the reload.
20
+ Each tool's description carries its usage guidance, the default model and override options' `useWhen` text, or the preset rosters, and each adds a prompt snippet and guideline. These are fixed when pi loads the extension, so saving in the screen runs `/reload` for you; after editing the config by hand run `/reload` yourself. A disabled tool, or `council` with no presets, is not registered. Settings are still re-read on every call, so a model or prompt change takes effect even before the reload.
21
21
 
22
22
  Models are `provider/model` strings of concrete models (not `alias/...` virtual models). Config goes under
23
- `council` in `~/.pi/agent/settings.json` or `.pi/settings.json` (project overrides global per section).
23
+ `council` in `~/.pi/agent/rackrot/config.json(c)` or `.pi/rackrot.json(c)` (project overrides global per section).
24
24
  Settings are re-read on every call; descriptions refresh on `/reload`.
25
25
 
26
26
  ```json
@@ -99,3 +99,5 @@ Settings are re-read on every call; descriptions refresh on `/reload`.
99
99
 
100
100
  If some councillors fail, the synthesizer works from the rest and the failures are listed. If every councillor fails the
101
101
  tool errors. If the synthesizer fails, the raw councillor answers are returned.
102
+
103
+ > Published with `pnpm publish` so the `workspace:` dependency ranges resolve to real versions; earlier releases were not installable from npm.
package/package.json CHANGED
@@ -1,35 +1,38 @@
1
1
  {
2
- "name": "@rackrot/pi-council",
3
- "version": "0.0.1",
4
- "description": "Second-opinion and multi-model council tools for pi",
5
- "type": "module",
6
- "keywords": [
7
- "pi-package",
8
- "pi-extension"
9
- ],
10
- "license": "MIT",
11
- "files": [
12
- "src",
13
- "README.md"
14
- ],
15
- "scripts": {
16
- "test": "node --test test/*.test.ts"
17
- },
18
- "pi": {
19
- "extensions": [
20
- "./src/index.ts"
21
- ]
22
- },
23
- "peerDependencies": {
24
- "@earendil-works/pi-coding-agent": "*",
25
- "typebox": "*"
26
- },
27
- "publishConfig": {
28
- "access": "public"
29
- },
30
- "repository": {
31
- "type": "git",
32
- "url": "git+https://github.com/rackrot/pi-tools.git",
33
- "directory": "packages/council"
34
- }
35
- }
2
+ "name": "@rackrot/pi-council",
3
+ "version": "0.3.0",
4
+ "description": "Second-opinion and multi-model council tools for pi",
5
+ "type": "module",
6
+ "keywords": [
7
+ "pi-package",
8
+ "pi-extension"
9
+ ],
10
+ "license": "MIT",
11
+ "files": [
12
+ "src",
13
+ "README.md"
14
+ ],
15
+ "pi": {
16
+ "extensions": [
17
+ "./src/index.ts"
18
+ ]
19
+ },
20
+ "dependencies": {
21
+ "@rackrot/pi-core": "0.4.0"
22
+ },
23
+ "peerDependencies": {
24
+ "@earendil-works/pi-coding-agent": "*",
25
+ "typebox": "*"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/rackrot/pi-tools.git",
33
+ "directory": "packages/council"
34
+ },
35
+ "scripts": {
36
+ "test": "node --test test/*.test.ts"
37
+ }
38
+ }
package/src/config.ts CHANGED
@@ -1,6 +1,4 @@
1
- import { existsSync, readFileSync } from "node:fs";
2
- import { join } from "node:path";
3
- import { getAgentDir } from "@earendil-works/pi-coding-agent";
1
+ import { readConfigLayers } from "@rackrot/pi-core/config";
4
2
 
5
3
  export const THINKING = ["minimal", "low", "medium", "high", "xhigh", "max"] as const;
6
4
  export type Thinking = (typeof THINKING)[number];
@@ -142,19 +140,9 @@ export function parseConfig(raw: unknown): Config {
142
140
  };
143
141
  }
144
142
 
145
- function readJson(path: string): Record<string, unknown> {
146
- if (!existsSync(path)) return {};
147
- try {
148
- return JSON.parse(readFileSync(path, "utf8")) as Record<string, unknown>;
149
- } catch {
150
- return {};
151
- }
152
- }
153
-
154
- /** Merges the `council` settings key: project over global, per top-level section. */
143
+ /** Merges the `council` config key: project over global, per top-level section. */
155
144
  export function loadConfig(cwd: string = process.cwd()): Config {
156
- const g = readJson(join(getAgentDir(), "settings.json")).council;
157
- const p = readJson(join(cwd, ".pi", "settings.json")).council;
145
+ const [g, p] = readConfigLayers("council", cwd);
158
146
  const gg = isObj(g) ? g : {};
159
147
  const pp = isObj(p) ? p : {};
160
148
  const merged: Record<string, unknown> = { ...gg, ...pp };
package/src/edit.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
2
- import { dirname } from "node:path";
1
+ import { editConfig, readConfig } from "@rackrot/pi-core/config";
3
2
  import { type Config, parseChain, THINKING } from "./config.ts";
4
3
 
5
4
  export type Obj = Record<string, unknown>;
@@ -10,6 +9,8 @@ const NONE = "(none)";
10
9
  /** One editable line in the settings screen. `apply` mutates the raw `council` object of one settings file. */
11
10
  export interface Row {
12
11
  id: string;
12
+ /** Screen partition the row is shown under. */
13
+ group: string;
13
14
  label: string;
14
15
  description: string;
15
16
  current: string;
@@ -56,6 +57,7 @@ const TOKENS = ["2000", "4000", "8000", "16000", "32000"];
56
57
  /** Builds every row for one settings layer (`layer` is its raw `council` object); `eff` is the merged result. */
57
58
  export function buildRows(layer: Obj, eff: Config): Row[] {
58
59
  const rows: Row[] = [];
60
+ let group = "";
59
61
  const so = isObj(layer.secondOpinion) ? layer.secondOpinion : {};
60
62
  const co = isObj(layer.council) ? layer.council : {};
61
63
  const syn = isObj(co.synthesizer) ? co.synthesizer : {};
@@ -69,6 +71,7 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
69
71
  ) =>
70
72
  rows.push({
71
73
  id,
74
+ group,
72
75
  label,
73
76
  description: `Effective: ${effective ? "on" : "off"}. Saving writes an explicit value to this scope.`,
74
77
  current: typeof raw === "boolean" ? (raw ? "on" : "off") : effective ? "on" : "off",
@@ -87,6 +90,7 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
87
90
  const current = raw === undefined ? UNSET : String(raw);
88
91
  rows.push({
89
92
  id,
93
+ group,
90
94
  label,
91
95
  description: `${desc} "${UNSET}" clears the value in this scope.`,
92
96
  current,
@@ -104,6 +108,7 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
104
108
  ) =>
105
109
  rows.push({
106
110
  id,
111
+ group,
107
112
  label,
108
113
  description: `${desc} Empty clears the value.`,
109
114
  current:
@@ -121,6 +126,7 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
121
126
  ) =>
122
127
  rows.push({
123
128
  id,
129
+ group,
124
130
  label,
125
131
  description: desc,
126
132
  current: firstModel(raw) ?? UNSET,
@@ -131,6 +137,7 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
131
137
  const action = (id: string, label: string, desc: string, run: (c: Obj) => void) =>
132
138
  rows.push({
133
139
  id,
140
+ group,
134
141
  label,
135
142
  description: desc,
136
143
  current: "…",
@@ -146,31 +153,25 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
146
153
  ) => cycle(id, label, raw, [...THINKING], "Reasoning effort; unset uses the model default.", set);
147
154
 
148
155
  // second_opinion
156
+ group = "second_opinion";
149
157
  const sc = (c: Obj) => child(c, "secondOpinion");
150
- toggle("so.enabled", "second_opinion · enabled", so.enabled, eff.secondOpinion.enabled, (c, v) =>
158
+ toggle("so.enabled", "enabled", so.enabled, eff.secondOpinion.enabled, (c, v) =>
151
159
  put(sc(c), "enabled", v),
152
160
  );
153
161
  model(
154
162
  "so.model",
155
- "second_opinion · default model",
163
+ "default model",
156
164
  so.model,
157
165
  "Model used when the agent passes none. Unset uses the session's model.",
158
166
  (c, v) => setFirstModel(sc(c), "model", v),
159
167
  );
160
- thinking("so.thinking", "second_opinion · thinking", so.thinking, (c, v) =>
161
- put(sc(c), "thinking", v),
162
- );
163
- cycle(
164
- "so.maxTokens",
165
- "second_opinion · max tokens",
166
- so.maxTokens,
167
- TOKENS,
168
- "Output cap per call.",
169
- (c, v) => put(sc(c), "maxTokens", v && Number(v)),
168
+ thinking("so.thinking", "thinking", so.thinking, (c, v) => put(sc(c), "thinking", v));
169
+ cycle("so.maxTokens", "max tokens", so.maxTokens, TOKENS, "Output cap per call.", (c, v) =>
170
+ put(sc(c), "maxTokens", v && Number(v)),
170
171
  );
171
172
  cycle(
172
173
  "so.timeout",
173
- "second_opinion · timeout (s)",
174
+ "timeout (s)",
174
175
  so.timeoutSeconds,
175
176
  TIMEOUTS,
176
177
  `Per call. Effective: ${eff.secondOpinion.timeoutSeconds}.`,
@@ -178,7 +179,7 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
178
179
  );
179
180
  text(
180
181
  "so.prompt",
181
- "second_opinion · extra prompt",
182
+ "extra prompt",
182
183
  so.systemPrompt,
183
184
  "Appended to the reviewer's system prompt.",
184
185
  (c, v) => put(sc(c), "systemPrompt", v),
@@ -186,40 +187,40 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
186
187
  const opts = Array.isArray(so.models) ? so.models : [];
187
188
  opts.forEach((entry, i) => {
188
189
  const e = isObj(entry) ? entry : {};
189
- const name = `option ${typeof e.id === "string" ? e.id : (firstModel(e) ?? i + 1)}`;
190
+ group = `second_opinion option ${typeof e.id === "string" ? e.id : (firstModel(e) ?? i + 1)}`;
190
191
  const at = (c: Obj) => {
191
192
  const list = sc(c).models as unknown[];
192
193
  if (!isObj(list[i])) list[i] = {};
193
194
  return list[i] as Obj;
194
195
  };
195
196
  const p = `so.opt.${i}`;
196
- model(`${p}.model`, ` ${name} · model`, e.model, "Model the agent can switch to.", (c, v) =>
197
+ model(`${p}.model`, "model", e.model, "Model the agent can switch to.", (c, v) =>
197
198
  setFirstModel(at(c), "model", v),
198
199
  );
199
200
  text(
200
201
  `${p}.id`,
201
- ` ${name} · id`,
202
+ "id",
202
203
  e.id,
203
204
  "Name the agent passes as 'model'. Defaults to the model string.",
204
205
  (c, v) => put(at(c), "id", v),
205
206
  );
206
207
  text(
207
208
  `${p}.useWhen`,
208
- ` ${name} · use when`,
209
+ "use when",
209
210
  e.useWhen,
210
211
  "Tells the agent when to pick this model over the default.",
211
212
  (c, v) => put(at(c), "useWhen", v),
212
213
  );
213
- thinking(`${p}.thinking`, ` ${name} · thinking`, e.thinking, (c, v) =>
214
- put(at(c), "thinking", v),
215
- );
216
- action(`${p}.remove`, ` ${name} · remove`, "Delete this option.", (c) =>
214
+ thinking(`${p}.thinking`, "thinking", e.thinking, (c, v) => put(at(c), "thinking", v));
215
+ action(`${p}.remove`, "remove", "Delete this option.", (c) =>
217
216
  (sc(c).models as unknown[]).splice(i, 1),
218
217
  );
219
218
  });
219
+ group = "second_opinion";
220
220
  rows.push({
221
221
  id: "so.add",
222
- label: "second_opinion · add option",
222
+ group,
223
+ label: "add option",
223
224
  description: "Pick a model to add as an override option, then set its 'use when'.",
224
225
  current: "pick…",
225
226
  submenu: "model",
@@ -231,13 +232,14 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
231
232
  });
232
233
 
233
234
  // council
235
+ group = "council";
234
236
  const cc = (c: Obj) => child(c, "council");
235
- toggle("co.enabled", "council · enabled", co.enabled, eff.council.enabled, (c, v) =>
237
+ toggle("co.enabled", "enabled", co.enabled, eff.council.enabled, (c, v) =>
236
238
  put(cc(c), "enabled", v),
237
239
  );
238
240
  cycle(
239
241
  "co.default",
240
- "council · default preset",
242
+ "default preset",
241
243
  co.defaultPreset,
242
244
  Object.keys(eff.council.presets),
243
245
  `Effective: ${eff.council.defaultPreset}.`,
@@ -245,7 +247,7 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
245
247
  );
246
248
  cycle(
247
249
  "co.maxTokens",
248
- "council · max tokens",
250
+ "max tokens",
249
251
  co.maxTokens,
250
252
  TOKENS,
251
253
  "Output cap per councillor and synthesizer call.",
@@ -253,7 +255,7 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
253
255
  );
254
256
  cycle(
255
257
  "co.timeout",
256
- "council · timeout (s)",
258
+ "timeout (s)",
257
259
  co.timeoutSeconds,
258
260
  TIMEOUTS,
259
261
  `Per call. Effective: ${eff.council.timeoutSeconds}.`,
@@ -261,52 +263,40 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
261
263
  );
262
264
  text(
263
265
  "co.prompt",
264
- "council · councillor prompt",
266
+ "councillor prompt",
265
267
  co.councillorPrompt,
266
268
  "Appended to every councillor's system prompt.",
267
269
  (c, v) => put(cc(c), "councillorPrompt", v),
268
270
  );
271
+ group = "council synthesizer";
269
272
  const sy = (c: Obj) => child(cc(c), "synthesizer");
270
- toggle(
271
- "syn.enabled",
272
- "council · synthesizer enabled",
273
- syn.enabled,
274
- eff.council.synthesizer.enabled,
275
- (c, v) => put(sy(c), "enabled", v),
273
+ toggle("syn.enabled", "enabled", syn.enabled, eff.council.synthesizer.enabled, (c, v) =>
274
+ put(sy(c), "enabled", v),
276
275
  );
277
- model(
278
- "syn.model",
279
- "council · synthesizer model",
280
- syn.model,
281
- "Unset uses the session's model.",
282
- (c, v) => setFirstModel(sy(c), "model", v),
276
+ model("syn.model", "model", syn.model, "Unset uses the session's model.", (c, v) =>
277
+ setFirstModel(sy(c), "model", v),
283
278
  );
284
- thinking("syn.thinking", "council · synthesizer thinking", syn.thinking, (c, v) =>
285
- put(sy(c), "thinking", v),
286
- );
287
- text(
288
- "syn.prompt",
289
- "council · synthesizer prompt",
290
- syn.prompt,
291
- "Appended to the synthesizer's system prompt.",
292
- (c, v) => put(sy(c), "prompt", v),
279
+ thinking("syn.thinking", "thinking", syn.thinking, (c, v) => put(sy(c), "thinking", v));
280
+ text("syn.prompt", "prompt", syn.prompt, "Appended to the synthesizer's system prompt.", (c, v) =>
281
+ put(sy(c), "prompt", v),
293
282
  );
294
283
 
295
284
  const presets = isObj(co.presets) ? co.presets : {};
296
285
  for (const [pn, praw] of Object.entries(presets)) {
297
286
  const pr = isObj(praw) ? praw : {};
298
287
  const pat = (c: Obj) => child(child(cc(c), "presets"), pn);
299
- const pl = `preset ${pn}`;
288
+ group = `preset ${pn}`;
300
289
  text(
301
290
  `pr.${pn}.useWhen`,
302
- `${pl} · use when`,
291
+ "use when",
303
292
  pr.useWhen,
304
293
  "Tells the agent when to pick this preset.",
305
294
  (c, v) => put(pat(c), "useWhen", v),
306
295
  );
307
296
  rows.push({
308
297
  id: `pr.${pn}.add`,
309
- label: `${pl} · add councillor`,
298
+ group,
299
+ label: "add councillor",
310
300
  description:
311
301
  "Pick a model; the councillor is named after it. Rename by editing settings.json.",
312
302
  current: "pick…",
@@ -321,42 +311,44 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
321
311
  });
322
312
  action(
323
313
  `pr.${pn}.remove`,
324
- `${pl} · remove`,
314
+ "remove",
325
315
  "Delete this preset.",
326
316
  (c) => delete child(cc(c), "presets")[pn],
327
317
  );
328
318
  for (const [cn, craw] of Object.entries(isObj(pr.councillors) ? pr.councillors : {})) {
329
319
  const cr = isObj(craw) ? craw : {};
330
320
  const cat = (c: Obj) => child(child(pat(c), "councillors"), cn);
331
- const cl = ` ${pn}/${cn}`;
321
+ group = `preset ${pn} / ${cn}`;
332
322
  model(
333
323
  `pr.${pn}.${cn}.model`,
334
- `${cl} · model`,
324
+ "model",
335
325
  cr.model,
336
326
  "First model of the chain; add fallbacks in settings.json.",
337
327
  (c, v) => setFirstModel(cat(c), "model", v),
338
328
  );
339
- thinking(`pr.${pn}.${cn}.thinking`, `${cl} · thinking`, cr.thinking, (c, v) =>
329
+ thinking(`pr.${pn}.${cn}.thinking`, "thinking", cr.thinking, (c, v) =>
340
330
  put(cat(c), "thinking", v),
341
331
  );
342
332
  text(
343
333
  `pr.${pn}.${cn}.prompt`,
344
- `${cl} · role prompt`,
334
+ "role prompt",
345
335
  cr.prompt,
346
336
  "Role guidance appended to this councillor's system prompt.",
347
337
  (c, v) => put(cat(c), "prompt", v),
348
338
  );
349
339
  action(
350
340
  `pr.${pn}.${cn}.remove`,
351
- `${cl} · remove`,
341
+ "remove",
352
342
  "Delete this councillor.",
353
343
  (c) => delete child(pat(c), "councillors")[cn],
354
344
  );
355
345
  }
356
346
  }
347
+ group = "council";
357
348
  rows.push({
358
349
  id: "co.addPreset",
359
- label: "council · add preset",
350
+ group,
351
+ label: "add preset",
360
352
  description: "Type a name, then add councillors to it.",
361
353
  current: "name…",
362
354
  submenu: "text",
@@ -368,32 +360,16 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
368
360
  return rows;
369
361
  }
370
362
 
371
- function readData(path: string): { data: Obj; indent: string } {
372
- if (!existsSync(path)) return { data: {}, indent: "\t" };
373
- const text = readFileSync(path, "utf8");
374
- if (!text.trim()) return { data: {}, indent: "\t" };
375
- const data = JSON.parse(text) as unknown;
376
- if (!isObj(data)) throw new Error(`${path} is not a JSON object`);
377
- return { data, indent: /^\{\r?\n(\t| +)/.exec(text)?.[1] ?? "\t" };
378
- }
379
-
380
- /** The raw `council` object of one settings file; `{}` when missing or unreadable. */
363
+ /** The raw `council` object of one config file; `{}` when missing or unreadable. */
381
364
  export function readLayer(path: string): Obj {
382
- try {
383
- const c = readData(path).data.council;
384
- return isObj(c) ? c : {};
385
- } catch {
386
- return {};
387
- }
365
+ const c = readConfig(path).council;
366
+ return isObj(c) ? c : {};
388
367
  }
389
368
 
390
- /** Applies `fn` to the file's `council` object and writes it back atomically, keeping other settings. */
369
+ /** Applies `fn` to the file's `council` object and writes it back atomically, keeping other keys and comments. */
391
370
  export function saveLayer(path: string, fn: (council: Obj) => void) {
392
- const { data, indent } = readData(path);
393
- const council = child(data, "council");
394
- fn(council);
395
- mkdirSync(dirname(path), { recursive: true });
396
- const tmp = `${path}.tmp-${process.pid}`;
397
- writeFileSync(tmp, `${JSON.stringify(data, null, indent)}\n`);
398
- renameSync(tmp, path);
371
+ editConfig(path, (data) => {
372
+ fn(child(data, "council"));
373
+ return data;
374
+ });
399
375
  }
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { type ExtensionAPI, type ExtensionContext } from "@earendil-works/pi-coding-agent";
2
+ import { registerConfigSection } from "@rackrot/pi-core/config-ui";
2
3
  import { Type } from "typebox";
3
4
  import { loadConfig, type ModelRef } from "./config.ts";
4
5
  import { embedFiles } from "./files.ts";
@@ -36,18 +37,42 @@ const CONTEXT_DESC =
36
37
  export default function (pi: ExtensionAPI) {
37
38
  const config = loadConfig();
38
39
 
39
- pi.registerCommand("council-config", {
40
- description: "Configure second_opinion and council. `show` prints the effective config.",
41
- handler: async (args, ctx) => {
42
- if (ctx.hasUI && args.trim() !== "show") {
43
- if (await openSettings(ctx)) await ctx.reload();
44
- return;
45
- }
40
+ registerConfigSection({
41
+ id: "council",
42
+ label: "Council & second opinion",
43
+ example: {
44
+ council: {
45
+ secondOpinion: {
46
+ enabled: true,
47
+ model: "provider/model-id",
48
+ thinking: "high",
49
+ models: [{ id: "big", model: "provider/big-model", useWhen: "hard design problems" }],
50
+ timeoutSeconds: 300,
51
+ },
52
+ council: {
53
+ enabled: true,
54
+ defaultPreset: "default",
55
+ presets: {
56
+ default: {
57
+ useWhen: "important decisions",
58
+ councillors: {
59
+ skeptic: {
60
+ model: ["provider/model-a", "provider/fallback"],
61
+ thinking: "medium",
62
+ prompt: "Look for flaws.",
63
+ },
64
+ },
65
+ },
66
+ },
67
+ synthesizer: { enabled: true, model: "provider/model-id" },
68
+ timeoutSeconds: 300,
69
+ },
70
+ },
71
+ },
72
+ open: (ctx) => openSettings(ctx),
73
+ summary: (ctx) => {
46
74
  const cfg = loadConfig(ctx.cwd);
47
- ctx.ui.notify(
48
- `second_opinion: ${cfg.secondOpinion.enabled ? "on" : "off"}, default ${cfg.secondOpinion.default?.model ?? "session model"}, ${cfg.secondOpinion.options.length} options\ncouncil: ${cfg.council.enabled ? "on" : "off"}, presets ${Object.keys(cfg.council.presets).join(", ") || "none"}`,
49
- "info",
50
- );
75
+ return `second_opinion ${cfg.secondOpinion.enabled ? "on" : "off"}, default ${cfg.secondOpinion.default?.model ?? "session model"}, ${cfg.secondOpinion.options.length} options; council ${cfg.council.enabled ? "on" : "off"}, presets ${Object.keys(cfg.council.presets).join(", ") || "none"}`;
51
76
  },
52
77
  });
53
78
 
package/src/ui.ts CHANGED
@@ -1,49 +1,18 @@
1
- import { join } from "node:path";
2
- import {
3
- type ExtensionCommandContext,
4
- getAgentDir,
5
- getSelectListTheme,
6
- getSettingsListTheme,
7
- } from "@earendil-works/pi-coding-agent";
8
- import {
9
- type Component,
10
- Container,
11
- Input,
12
- SelectList,
13
- type SettingItem,
14
- SettingsList,
15
- Text,
16
- } from "@earendil-works/pi-tui";
1
+ import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
2
+ import { type Component, Input } from "@earendil-works/pi-tui";
3
+ import { configPath } from "@rackrot/pi-core/config";
4
+ import { type ConfigRow, filterPicker, openConfigScreen } from "@rackrot/pi-core/config-ui";
17
5
  import { loadConfig } from "./config.ts";
18
6
  import { buildRows, type Row, readLayer, saveLayer, UNSET } from "./edit.ts";
19
7
 
20
8
  type Scope = "global" | "project";
21
9
 
22
- /** Filterable model list: type to narrow, arrows to move, enter to pick, escape to cancel. */
23
10
  function modelPicker(models: string[], current: string, done: (v?: string) => void): Component {
24
11
  const items = [UNSET, ...models].map((value) => ({
25
12
  value,
26
13
  label: value === UNSET ? "unset (use the session's model)" : value,
27
14
  }));
28
- const list = new SelectList(items, 12, getSelectListTheme());
29
- list.setSelectedIndex(
30
- Math.max(
31
- 0,
32
- items.findIndex((i) => i.value === current),
33
- ),
34
- );
35
- list.onSelect = (i) => done(i.value);
36
- list.onCancel = () => done();
37
- const input = new Input({ prompt: "filter: " });
38
- return {
39
- render: (w) => [...input.render(w), ...list.render(w)],
40
- invalidate: () => list.invalidate(),
41
- handleInput: (data) => {
42
- list.handleInput(data);
43
- input.handleInput(data);
44
- list.setFilter(input.getValue());
45
- },
46
- } as Component;
15
+ return filterPicker(items, done, current);
47
16
  }
48
17
 
49
18
  function textEditor(initial: string, done: (v?: string) => void): Component {
@@ -54,13 +23,12 @@ function textEditor(initial: string, done: (v?: string) => void): Component {
54
23
  return input;
55
24
  }
56
25
 
57
- /** Opens the council settings screen. Resolves when the user closes it; true when anything was saved. */
26
+ /** Opens the council settings screen. Resolves true when anything was saved. */
58
27
  export async function openSettings(ctx: ExtensionCommandContext): Promise<boolean> {
59
28
  let dirty = false;
60
29
  const cwd = ctx.cwd;
61
30
  let scope: Scope = "global";
62
- const pathOf = (s: Scope) =>
63
- s === "global" ? join(getAgentDir(), "settings.json") : join(cwd, ".pi", "settings.json");
31
+ const pathOf = (s: Scope) => configPath(s, cwd);
64
32
  const models = [
65
33
  ...new Set(
66
34
  ctx.modelRegistry
@@ -70,12 +38,9 @@ export async function openSettings(ctx: ExtensionCommandContext): Promise<boolea
70
38
  ),
71
39
  ].sort();
72
40
 
73
- let rows: Row[] = [];
74
- const rebuild = () => {
75
- rows = buildRows(readLayer(pathOf(scope)), loadConfig(cwd));
76
- };
77
- const toItem = (r: Row): SettingItem => ({
41
+ const toItem = (r: Row): ConfigRow => ({
78
42
  id: r.id,
43
+ group: r.group,
79
44
  label: r.label,
80
45
  description: r.description,
81
46
  currentValue: r.current,
@@ -87,67 +52,20 @@ export async function openSettings(ctx: ExtensionCommandContext): Promise<boolea
87
52
  ? (cur, done) => textEditor(cur === UNSET || cur === "name…" ? "" : cur, done)
88
53
  : undefined,
89
54
  });
55
+ const build = (scope: Scope) => buildRows(readLayer(pathOf(scope)), loadConfig(cwd));
90
56
 
91
- await ctx.ui.custom<void>((tui, theme, kb, done) => {
92
- const title = new Text("", 0, 0);
93
- const file = new Text("", 0, 0);
94
- const status = new Text("", 0, 0);
95
- const header = new Container();
96
- header.addChild(title);
97
- header.addChild(file);
98
- const tabKey = kb.getKeys("tui.input.tab")[0];
99
- const renderHeader = () => {
100
- title.setText(
101
- `⚙ Council · Saving to: ${scope === "global" ? "Global" : "Project"}${tabKey ? theme.fg("muted", ` · ${tabKey} to switch`) : ""}`,
102
- );
103
- file.setText(theme.fg("muted", ` ${pathOf(scope)} · pi reloads on close to apply changes`));
104
- };
105
-
106
- let list: SettingsList;
107
- const makeList = () => {
108
- rebuild();
109
- list = new SettingsList(
110
- rows.map(toItem),
111
- Math.max(5, Math.min(tui.terminal.rows - 10, rows.length)),
112
- getSettingsListTheme(),
113
- (id, next) => {
114
- const row = rows.find((r) => r.id === id);
115
- try {
116
- if (row) {
117
- saveLayer(pathOf(scope), (c) => row.apply(c, next));
118
- dirty = true;
119
- }
120
- status.setText("");
121
- } catch (e) {
122
- status.setText(theme.fg("error", ` ${e instanceof Error ? e.message : String(e)}`));
123
- }
124
- makeList();
125
- renderHeader();
126
- },
127
- () => done(),
128
- { enableSearch: true },
129
- );
130
- };
131
- makeList();
132
- renderHeader();
133
-
134
- const component: Component = {
135
- render: (w) => [...header.render(w), "", ...list.render(w), ...status.render(w)],
136
- invalidate: () => {
137
- header.invalidate();
138
- list.invalidate();
139
- },
140
- handleInput: (data) => {
141
- if (kb.matches(data, "tui.input.tab")) {
142
- scope = scope === "global" ? "project" : "global";
143
- makeList();
144
- renderHeader();
145
- return;
146
- }
147
- list.handleInput(data);
148
- },
149
- };
150
- return component;
57
+ await openConfigScreen(ctx, {
58
+ title: "Council",
59
+ pathOf,
60
+ reload: true,
61
+ rows: (scope) => build(scope).map(toItem),
62
+ apply: (scope, id, next) => {
63
+ const row = build(scope).find((r) => r.id === id);
64
+ if (row) {
65
+ saveLayer(pathOf(scope), (c) => row.apply(c, next));
66
+ dirty = true;
67
+ }
68
+ },
151
69
  });
152
70
  return dirty;
153
71
  }