@rackrot/pi-council 0.0.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +5 -3
- package/package.json +37 -34
- package/src/config.ts +3 -15
- package/src/edit.ts +9 -26
- package/src/index.ts +36 -11
- package/src/ui.ts +8 -36
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
|
-
`/
|
|
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
|
|
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/
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
2
|
+
"name": "@rackrot/pi-council",
|
|
3
|
+
"version": "0.2.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
|
+
"pi": {
|
|
16
|
+
"extensions": [
|
|
17
|
+
"./src/index.ts"
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@rackrot/pi-core": "0.3.1"
|
|
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 {
|
|
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
|
-
|
|
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 =
|
|
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 {
|
|
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>;
|
|
@@ -368,32 +367,16 @@ export function buildRows(layer: Obj, eff: Config): Row[] {
|
|
|
368
367
|
return rows;
|
|
369
368
|
}
|
|
370
369
|
|
|
371
|
-
|
|
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. */
|
|
370
|
+
/** The raw `council` object of one config file; `{}` when missing or unreadable. */
|
|
381
371
|
export function readLayer(path: string): Obj {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
return isObj(c) ? c : {};
|
|
385
|
-
} catch {
|
|
386
|
-
return {};
|
|
387
|
-
}
|
|
372
|
+
const c = readConfig(path).council;
|
|
373
|
+
return isObj(c) ? c : {};
|
|
388
374
|
}
|
|
389
375
|
|
|
390
|
-
/** Applies `fn` to the file's `council` object and writes it back atomically, keeping other
|
|
376
|
+
/** Applies `fn` to the file's `council` object and writes it back atomically, keeping other keys and comments. */
|
|
391
377
|
export function saveLayer(path: string, fn: (council: Obj) => void) {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
const tmp = `${path}.tmp-${process.pid}`;
|
|
397
|
-
writeFileSync(tmp, `${JSON.stringify(data, null, indent)}\n`);
|
|
398
|
-
renameSync(tmp, path);
|
|
378
|
+
editConfig(path, (data) => {
|
|
379
|
+
fn(child(data, "council"));
|
|
380
|
+
return data;
|
|
381
|
+
});
|
|
399
382
|
}
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
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,21 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
1
|
import {
|
|
3
2
|
type ExtensionCommandContext,
|
|
4
|
-
getAgentDir,
|
|
5
|
-
getSelectListTheme,
|
|
6
3
|
getSettingsListTheme,
|
|
7
4
|
} from "@earendil-works/pi-coding-agent";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Input,
|
|
12
|
-
SelectList,
|
|
13
|
-
type SettingItem,
|
|
14
|
-
SettingsList,
|
|
15
|
-
Text,
|
|
16
|
-
} from "@earendil-works/pi-tui";
|
|
5
|
+
import { type Component, Container, Input, type SettingItem, Text } from "@earendil-works/pi-tui";
|
|
6
|
+
import { configPath } from "@rackrot/pi-core/config";
|
|
7
|
+
import { CycleSettingsList, filterPicker } from "@rackrot/pi-core/config-ui";
|
|
17
8
|
import { loadConfig } from "./config.ts";
|
|
18
9
|
import { buildRows, type Row, readLayer, saveLayer, UNSET } from "./edit.ts";
|
|
19
10
|
|
|
20
11
|
type Scope = "global" | "project";
|
|
21
12
|
|
|
22
|
-
/** Filterable model list: type to narrow, arrows to move, enter to pick, escape to cancel. */
|
|
23
13
|
function modelPicker(models: string[], current: string, done: (v?: string) => void): Component {
|
|
24
14
|
const items = [UNSET, ...models].map((value) => ({
|
|
25
15
|
value,
|
|
26
16
|
label: value === UNSET ? "unset (use the session's model)" : value,
|
|
27
17
|
}));
|
|
28
|
-
|
|
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;
|
|
18
|
+
return filterPicker(items, done, current);
|
|
47
19
|
}
|
|
48
20
|
|
|
49
21
|
function textEditor(initial: string, done: (v?: string) => void): Component {
|
|
@@ -59,8 +31,7 @@ export async function openSettings(ctx: ExtensionCommandContext): Promise<boolea
|
|
|
59
31
|
let dirty = false;
|
|
60
32
|
const cwd = ctx.cwd;
|
|
61
33
|
let scope: Scope = "global";
|
|
62
|
-
const pathOf = (s: Scope) =>
|
|
63
|
-
s === "global" ? join(getAgentDir(), "settings.json") : join(cwd, ".pi", "settings.json");
|
|
34
|
+
const pathOf = (s: Scope) => configPath(s, cwd);
|
|
64
35
|
const models = [
|
|
65
36
|
...new Set(
|
|
66
37
|
ctx.modelRegistry
|
|
@@ -103,10 +74,10 @@ export async function openSettings(ctx: ExtensionCommandContext): Promise<boolea
|
|
|
103
74
|
file.setText(theme.fg("muted", ` ${pathOf(scope)} · pi reloads on close to apply changes`));
|
|
104
75
|
};
|
|
105
76
|
|
|
106
|
-
let list:
|
|
77
|
+
let list: CycleSettingsList;
|
|
107
78
|
const makeList = () => {
|
|
108
79
|
rebuild();
|
|
109
|
-
list = new
|
|
80
|
+
list = new CycleSettingsList(
|
|
110
81
|
rows.map(toItem),
|
|
111
82
|
Math.max(5, Math.min(tui.terminal.rows - 10, rows.length)),
|
|
112
83
|
getSettingsListTheme(),
|
|
@@ -122,6 +93,7 @@ export async function openSettings(ctx: ExtensionCommandContext): Promise<boolea
|
|
|
122
93
|
status.setText(theme.fg("error", ` ${e instanceof Error ? e.message : String(e)}`));
|
|
123
94
|
}
|
|
124
95
|
makeList();
|
|
96
|
+
list.selectItem(id);
|
|
125
97
|
renderHeader();
|
|
126
98
|
},
|
|
127
99
|
() => done(),
|