@rackrot/pi-council 0.2.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/package.json +2 -2
- package/src/edit.ts +52 -59
- package/src/ui.ts +19 -73
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rackrot/pi-council",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Second-opinion and multi-model council tools for pi",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
]
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@rackrot/pi-core": "0.
|
|
21
|
+
"@rackrot/pi-core": "0.4.0"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"@earendil-works/pi-coding-agent": "*",
|
package/src/edit.ts
CHANGED
|
@@ -9,6 +9,8 @@ const NONE = "(none)";
|
|
|
9
9
|
/** One editable line in the settings screen. `apply` mutates the raw `council` object of one settings file. */
|
|
10
10
|
export interface Row {
|
|
11
11
|
id: string;
|
|
12
|
+
/** Screen partition the row is shown under. */
|
|
13
|
+
group: string;
|
|
12
14
|
label: string;
|
|
13
15
|
description: string;
|
|
14
16
|
current: string;
|
|
@@ -55,6 +57,7 @@ const TOKENS = ["2000", "4000", "8000", "16000", "32000"];
|
|
|
55
57
|
/** Builds every row for one settings layer (`layer` is its raw `council` object); `eff` is the merged result. */
|
|
56
58
|
export function buildRows(layer: Obj, eff: Config): Row[] {
|
|
57
59
|
const rows: Row[] = [];
|
|
60
|
+
let group = "";
|
|
58
61
|
const so = isObj(layer.secondOpinion) ? layer.secondOpinion : {};
|
|
59
62
|
const co = isObj(layer.council) ? layer.council : {};
|
|
60
63
|
const syn = isObj(co.synthesizer) ? co.synthesizer : {};
|
|
@@ -68,6 +71,7 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
|
|
|
68
71
|
) =>
|
|
69
72
|
rows.push({
|
|
70
73
|
id,
|
|
74
|
+
group,
|
|
71
75
|
label,
|
|
72
76
|
description: `Effective: ${effective ? "on" : "off"}. Saving writes an explicit value to this scope.`,
|
|
73
77
|
current: typeof raw === "boolean" ? (raw ? "on" : "off") : effective ? "on" : "off",
|
|
@@ -86,6 +90,7 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
|
|
|
86
90
|
const current = raw === undefined ? UNSET : String(raw);
|
|
87
91
|
rows.push({
|
|
88
92
|
id,
|
|
93
|
+
group,
|
|
89
94
|
label,
|
|
90
95
|
description: `${desc} "${UNSET}" clears the value in this scope.`,
|
|
91
96
|
current,
|
|
@@ -103,6 +108,7 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
|
|
|
103
108
|
) =>
|
|
104
109
|
rows.push({
|
|
105
110
|
id,
|
|
111
|
+
group,
|
|
106
112
|
label,
|
|
107
113
|
description: `${desc} Empty clears the value.`,
|
|
108
114
|
current:
|
|
@@ -120,6 +126,7 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
|
|
|
120
126
|
) =>
|
|
121
127
|
rows.push({
|
|
122
128
|
id,
|
|
129
|
+
group,
|
|
123
130
|
label,
|
|
124
131
|
description: desc,
|
|
125
132
|
current: firstModel(raw) ?? UNSET,
|
|
@@ -130,6 +137,7 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
|
|
|
130
137
|
const action = (id: string, label: string, desc: string, run: (c: Obj) => void) =>
|
|
131
138
|
rows.push({
|
|
132
139
|
id,
|
|
140
|
+
group,
|
|
133
141
|
label,
|
|
134
142
|
description: desc,
|
|
135
143
|
current: "…",
|
|
@@ -145,31 +153,25 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
|
|
|
145
153
|
) => cycle(id, label, raw, [...THINKING], "Reasoning effort; unset uses the model default.", set);
|
|
146
154
|
|
|
147
155
|
// second_opinion
|
|
156
|
+
group = "second_opinion";
|
|
148
157
|
const sc = (c: Obj) => child(c, "secondOpinion");
|
|
149
|
-
toggle("so.enabled", "
|
|
158
|
+
toggle("so.enabled", "enabled", so.enabled, eff.secondOpinion.enabled, (c, v) =>
|
|
150
159
|
put(sc(c), "enabled", v),
|
|
151
160
|
);
|
|
152
161
|
model(
|
|
153
162
|
"so.model",
|
|
154
|
-
"
|
|
163
|
+
"default model",
|
|
155
164
|
so.model,
|
|
156
165
|
"Model used when the agent passes none. Unset uses the session's model.",
|
|
157
166
|
(c, v) => setFirstModel(sc(c), "model", v),
|
|
158
167
|
);
|
|
159
|
-
thinking("so.thinking", "
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
cycle(
|
|
163
|
-
"so.maxTokens",
|
|
164
|
-
"second_opinion · max tokens",
|
|
165
|
-
so.maxTokens,
|
|
166
|
-
TOKENS,
|
|
167
|
-
"Output cap per call.",
|
|
168
|
-
(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)),
|
|
169
171
|
);
|
|
170
172
|
cycle(
|
|
171
173
|
"so.timeout",
|
|
172
|
-
"
|
|
174
|
+
"timeout (s)",
|
|
173
175
|
so.timeoutSeconds,
|
|
174
176
|
TIMEOUTS,
|
|
175
177
|
`Per call. Effective: ${eff.secondOpinion.timeoutSeconds}.`,
|
|
@@ -177,7 +179,7 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
|
|
|
177
179
|
);
|
|
178
180
|
text(
|
|
179
181
|
"so.prompt",
|
|
180
|
-
"
|
|
182
|
+
"extra prompt",
|
|
181
183
|
so.systemPrompt,
|
|
182
184
|
"Appended to the reviewer's system prompt.",
|
|
183
185
|
(c, v) => put(sc(c), "systemPrompt", v),
|
|
@@ -185,40 +187,40 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
|
|
|
185
187
|
const opts = Array.isArray(so.models) ? so.models : [];
|
|
186
188
|
opts.forEach((entry, i) => {
|
|
187
189
|
const e = isObj(entry) ? entry : {};
|
|
188
|
-
|
|
190
|
+
group = `second_opinion option ${typeof e.id === "string" ? e.id : (firstModel(e) ?? i + 1)}`;
|
|
189
191
|
const at = (c: Obj) => {
|
|
190
192
|
const list = sc(c).models as unknown[];
|
|
191
193
|
if (!isObj(list[i])) list[i] = {};
|
|
192
194
|
return list[i] as Obj;
|
|
193
195
|
};
|
|
194
196
|
const p = `so.opt.${i}`;
|
|
195
|
-
model(`${p}.model`,
|
|
197
|
+
model(`${p}.model`, "model", e.model, "Model the agent can switch to.", (c, v) =>
|
|
196
198
|
setFirstModel(at(c), "model", v),
|
|
197
199
|
);
|
|
198
200
|
text(
|
|
199
201
|
`${p}.id`,
|
|
200
|
-
|
|
202
|
+
"id",
|
|
201
203
|
e.id,
|
|
202
204
|
"Name the agent passes as 'model'. Defaults to the model string.",
|
|
203
205
|
(c, v) => put(at(c), "id", v),
|
|
204
206
|
);
|
|
205
207
|
text(
|
|
206
208
|
`${p}.useWhen`,
|
|
207
|
-
|
|
209
|
+
"use when",
|
|
208
210
|
e.useWhen,
|
|
209
211
|
"Tells the agent when to pick this model over the default.",
|
|
210
212
|
(c, v) => put(at(c), "useWhen", v),
|
|
211
213
|
);
|
|
212
|
-
thinking(`${p}.thinking`,
|
|
213
|
-
|
|
214
|
-
);
|
|
215
|
-
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) =>
|
|
216
216
|
(sc(c).models as unknown[]).splice(i, 1),
|
|
217
217
|
);
|
|
218
218
|
});
|
|
219
|
+
group = "second_opinion";
|
|
219
220
|
rows.push({
|
|
220
221
|
id: "so.add",
|
|
221
|
-
|
|
222
|
+
group,
|
|
223
|
+
label: "add option",
|
|
222
224
|
description: "Pick a model to add as an override option, then set its 'use when'.",
|
|
223
225
|
current: "pick…",
|
|
224
226
|
submenu: "model",
|
|
@@ -230,13 +232,14 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
|
|
|
230
232
|
});
|
|
231
233
|
|
|
232
234
|
// council
|
|
235
|
+
group = "council";
|
|
233
236
|
const cc = (c: Obj) => child(c, "council");
|
|
234
|
-
toggle("co.enabled", "
|
|
237
|
+
toggle("co.enabled", "enabled", co.enabled, eff.council.enabled, (c, v) =>
|
|
235
238
|
put(cc(c), "enabled", v),
|
|
236
239
|
);
|
|
237
240
|
cycle(
|
|
238
241
|
"co.default",
|
|
239
|
-
"
|
|
242
|
+
"default preset",
|
|
240
243
|
co.defaultPreset,
|
|
241
244
|
Object.keys(eff.council.presets),
|
|
242
245
|
`Effective: ${eff.council.defaultPreset}.`,
|
|
@@ -244,7 +247,7 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
|
|
|
244
247
|
);
|
|
245
248
|
cycle(
|
|
246
249
|
"co.maxTokens",
|
|
247
|
-
"
|
|
250
|
+
"max tokens",
|
|
248
251
|
co.maxTokens,
|
|
249
252
|
TOKENS,
|
|
250
253
|
"Output cap per councillor and synthesizer call.",
|
|
@@ -252,7 +255,7 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
|
|
|
252
255
|
);
|
|
253
256
|
cycle(
|
|
254
257
|
"co.timeout",
|
|
255
|
-
"
|
|
258
|
+
"timeout (s)",
|
|
256
259
|
co.timeoutSeconds,
|
|
257
260
|
TIMEOUTS,
|
|
258
261
|
`Per call. Effective: ${eff.council.timeoutSeconds}.`,
|
|
@@ -260,52 +263,40 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
|
|
|
260
263
|
);
|
|
261
264
|
text(
|
|
262
265
|
"co.prompt",
|
|
263
|
-
"
|
|
266
|
+
"councillor prompt",
|
|
264
267
|
co.councillorPrompt,
|
|
265
268
|
"Appended to every councillor's system prompt.",
|
|
266
269
|
(c, v) => put(cc(c), "councillorPrompt", v),
|
|
267
270
|
);
|
|
271
|
+
group = "council synthesizer";
|
|
268
272
|
const sy = (c: Obj) => child(cc(c), "synthesizer");
|
|
269
|
-
toggle(
|
|
270
|
-
"
|
|
271
|
-
"council · synthesizer enabled",
|
|
272
|
-
syn.enabled,
|
|
273
|
-
eff.council.synthesizer.enabled,
|
|
274
|
-
(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),
|
|
275
275
|
);
|
|
276
|
-
model(
|
|
277
|
-
"
|
|
278
|
-
"council · synthesizer model",
|
|
279
|
-
syn.model,
|
|
280
|
-
"Unset uses the session's model.",
|
|
281
|
-
(c, v) => setFirstModel(sy(c), "model", v),
|
|
282
|
-
);
|
|
283
|
-
thinking("syn.thinking", "council · synthesizer thinking", syn.thinking, (c, v) =>
|
|
284
|
-
put(sy(c), "thinking", v),
|
|
276
|
+
model("syn.model", "model", syn.model, "Unset uses the session's model.", (c, v) =>
|
|
277
|
+
setFirstModel(sy(c), "model", v),
|
|
285
278
|
);
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
"
|
|
289
|
-
syn.prompt,
|
|
290
|
-
"Appended to the synthesizer's system prompt.",
|
|
291
|
-
(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),
|
|
292
282
|
);
|
|
293
283
|
|
|
294
284
|
const presets = isObj(co.presets) ? co.presets : {};
|
|
295
285
|
for (const [pn, praw] of Object.entries(presets)) {
|
|
296
286
|
const pr = isObj(praw) ? praw : {};
|
|
297
287
|
const pat = (c: Obj) => child(child(cc(c), "presets"), pn);
|
|
298
|
-
|
|
288
|
+
group = `preset ${pn}`;
|
|
299
289
|
text(
|
|
300
290
|
`pr.${pn}.useWhen`,
|
|
301
|
-
|
|
291
|
+
"use when",
|
|
302
292
|
pr.useWhen,
|
|
303
293
|
"Tells the agent when to pick this preset.",
|
|
304
294
|
(c, v) => put(pat(c), "useWhen", v),
|
|
305
295
|
);
|
|
306
296
|
rows.push({
|
|
307
297
|
id: `pr.${pn}.add`,
|
|
308
|
-
|
|
298
|
+
group,
|
|
299
|
+
label: "add councillor",
|
|
309
300
|
description:
|
|
310
301
|
"Pick a model; the councillor is named after it. Rename by editing settings.json.",
|
|
311
302
|
current: "pick…",
|
|
@@ -320,42 +311,44 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
|
|
|
320
311
|
});
|
|
321
312
|
action(
|
|
322
313
|
`pr.${pn}.remove`,
|
|
323
|
-
|
|
314
|
+
"remove",
|
|
324
315
|
"Delete this preset.",
|
|
325
316
|
(c) => delete child(cc(c), "presets")[pn],
|
|
326
317
|
);
|
|
327
318
|
for (const [cn, craw] of Object.entries(isObj(pr.councillors) ? pr.councillors : {})) {
|
|
328
319
|
const cr = isObj(craw) ? craw : {};
|
|
329
320
|
const cat = (c: Obj) => child(child(pat(c), "councillors"), cn);
|
|
330
|
-
|
|
321
|
+
group = `preset ${pn} / ${cn}`;
|
|
331
322
|
model(
|
|
332
323
|
`pr.${pn}.${cn}.model`,
|
|
333
|
-
|
|
324
|
+
"model",
|
|
334
325
|
cr.model,
|
|
335
326
|
"First model of the chain; add fallbacks in settings.json.",
|
|
336
327
|
(c, v) => setFirstModel(cat(c), "model", v),
|
|
337
328
|
);
|
|
338
|
-
thinking(`pr.${pn}.${cn}.thinking`,
|
|
329
|
+
thinking(`pr.${pn}.${cn}.thinking`, "thinking", cr.thinking, (c, v) =>
|
|
339
330
|
put(cat(c), "thinking", v),
|
|
340
331
|
);
|
|
341
332
|
text(
|
|
342
333
|
`pr.${pn}.${cn}.prompt`,
|
|
343
|
-
|
|
334
|
+
"role prompt",
|
|
344
335
|
cr.prompt,
|
|
345
336
|
"Role guidance appended to this councillor's system prompt.",
|
|
346
337
|
(c, v) => put(cat(c), "prompt", v),
|
|
347
338
|
);
|
|
348
339
|
action(
|
|
349
340
|
`pr.${pn}.${cn}.remove`,
|
|
350
|
-
|
|
341
|
+
"remove",
|
|
351
342
|
"Delete this councillor.",
|
|
352
343
|
(c) => delete child(pat(c), "councillors")[cn],
|
|
353
344
|
);
|
|
354
345
|
}
|
|
355
346
|
}
|
|
347
|
+
group = "council";
|
|
356
348
|
rows.push({
|
|
357
349
|
id: "co.addPreset",
|
|
358
|
-
|
|
350
|
+
group,
|
|
351
|
+
label: "add preset",
|
|
359
352
|
description: "Type a name, then add councillors to it.",
|
|
360
353
|
current: "name…",
|
|
361
354
|
submenu: "text",
|
package/src/ui.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
getSettingsListTheme,
|
|
4
|
-
} from "@earendil-works/pi-coding-agent";
|
|
5
|
-
import { type Component, Container, Input, type SettingItem, Text } 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";
|
|
6
3
|
import { configPath } from "@rackrot/pi-core/config";
|
|
7
|
-
import {
|
|
4
|
+
import { type ConfigRow, filterPicker, openConfigScreen } from "@rackrot/pi-core/config-ui";
|
|
8
5
|
import { loadConfig } from "./config.ts";
|
|
9
6
|
import { buildRows, type Row, readLayer, saveLayer, UNSET } from "./edit.ts";
|
|
10
7
|
|
|
@@ -26,7 +23,7 @@ function textEditor(initial: string, done: (v?: string) => void): Component {
|
|
|
26
23
|
return input;
|
|
27
24
|
}
|
|
28
25
|
|
|
29
|
-
/** Opens the council settings screen. Resolves
|
|
26
|
+
/** Opens the council settings screen. Resolves true when anything was saved. */
|
|
30
27
|
export async function openSettings(ctx: ExtensionCommandContext): Promise<boolean> {
|
|
31
28
|
let dirty = false;
|
|
32
29
|
const cwd = ctx.cwd;
|
|
@@ -41,12 +38,9 @@ export async function openSettings(ctx: ExtensionCommandContext): Promise<boolea
|
|
|
41
38
|
),
|
|
42
39
|
].sort();
|
|
43
40
|
|
|
44
|
-
|
|
45
|
-
const rebuild = () => {
|
|
46
|
-
rows = buildRows(readLayer(pathOf(scope)), loadConfig(cwd));
|
|
47
|
-
};
|
|
48
|
-
const toItem = (r: Row): SettingItem => ({
|
|
41
|
+
const toItem = (r: Row): ConfigRow => ({
|
|
49
42
|
id: r.id,
|
|
43
|
+
group: r.group,
|
|
50
44
|
label: r.label,
|
|
51
45
|
description: r.description,
|
|
52
46
|
currentValue: r.current,
|
|
@@ -58,68 +52,20 @@ export async function openSettings(ctx: ExtensionCommandContext): Promise<boolea
|
|
|
58
52
|
? (cur, done) => textEditor(cur === UNSET || cur === "name…" ? "" : cur, done)
|
|
59
53
|
: undefined,
|
|
60
54
|
});
|
|
55
|
+
const build = (scope: Scope) => buildRows(readLayer(pathOf(scope)), loadConfig(cwd));
|
|
61
56
|
|
|
62
|
-
await ctx
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
file.setText(theme.fg("muted", ` ${pathOf(scope)} · pi reloads on close to apply changes`));
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
let list: CycleSettingsList;
|
|
78
|
-
const makeList = () => {
|
|
79
|
-
rebuild();
|
|
80
|
-
list = new CycleSettingsList(
|
|
81
|
-
rows.map(toItem),
|
|
82
|
-
Math.max(5, Math.min(tui.terminal.rows - 10, rows.length)),
|
|
83
|
-
getSettingsListTheme(),
|
|
84
|
-
(id, next) => {
|
|
85
|
-
const row = rows.find((r) => r.id === id);
|
|
86
|
-
try {
|
|
87
|
-
if (row) {
|
|
88
|
-
saveLayer(pathOf(scope), (c) => row.apply(c, next));
|
|
89
|
-
dirty = true;
|
|
90
|
-
}
|
|
91
|
-
status.setText("");
|
|
92
|
-
} catch (e) {
|
|
93
|
-
status.setText(theme.fg("error", ` ${e instanceof Error ? e.message : String(e)}`));
|
|
94
|
-
}
|
|
95
|
-
makeList();
|
|
96
|
-
list.selectItem(id);
|
|
97
|
-
renderHeader();
|
|
98
|
-
},
|
|
99
|
-
() => done(),
|
|
100
|
-
{ enableSearch: true },
|
|
101
|
-
);
|
|
102
|
-
};
|
|
103
|
-
makeList();
|
|
104
|
-
renderHeader();
|
|
105
|
-
|
|
106
|
-
const component: Component = {
|
|
107
|
-
render: (w) => [...header.render(w), "", ...list.render(w), ...status.render(w)],
|
|
108
|
-
invalidate: () => {
|
|
109
|
-
header.invalidate();
|
|
110
|
-
list.invalidate();
|
|
111
|
-
},
|
|
112
|
-
handleInput: (data) => {
|
|
113
|
-
if (kb.matches(data, "tui.input.tab")) {
|
|
114
|
-
scope = scope === "global" ? "project" : "global";
|
|
115
|
-
makeList();
|
|
116
|
-
renderHeader();
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
list.handleInput(data);
|
|
120
|
-
},
|
|
121
|
-
};
|
|
122
|
-
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
|
+
},
|
|
123
69
|
});
|
|
124
70
|
return dirty;
|
|
125
71
|
}
|