architecture-harness 0.14.0 → 0.15.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 +1 -1
- package/src/cli/dispatch-guard.test.mjs +46 -0
- package/src/cli/dispatch-reminder.mjs +39 -9
- package/src/cli/dispatch-reminder.test.mjs +55 -2
- package/src/cli/dispatch.mjs +80 -3
- package/src/cli/dispatch.test.mjs +65 -1
- package/src/cli/explore-guard.mjs +211 -0
- package/src/cli/explore-guard.test.mjs +193 -0
- package/src/cli/explore-hint.mjs +85 -0
- package/src/cli/explore-hint.test.mjs +134 -0
- package/src/cli/plugin-agents.test.mjs +11 -5
- package/src/config.mjs +30 -1
package/package.json
CHANGED
|
@@ -117,6 +117,52 @@ test("a planner and a reviewer run beside an implementer", (t) => {
|
|
|
117
117
|
assert.equal(decide(agentCall(ws.on, { subagent_type: "architecture:sdd-planner", prompt: "p" }), ws.tmp), null);
|
|
118
118
|
});
|
|
119
119
|
|
|
120
|
+
test("the tier guard refuses a type on the wrong family, naming the type, the model and the allowed families", (t) => {
|
|
121
|
+
const ws = workspace(t);
|
|
122
|
+
const refused = (input) => reasonOf(decide(agentCall(ws.on, input), ws.tmp)) ?? "";
|
|
123
|
+
assert.match(refused({ subagent_type: "architecture:sdd-planner", model: "sonnet", prompt: "p" }), /architecture:sdd-planner/);
|
|
124
|
+
assert.match(refused({ subagent_type: "architecture:sdd-implementer", model: "opus", prompt: "p" }), /architecture:sdd-implementer/);
|
|
125
|
+
assert.match(refused({ model: "opus", prompt: "p" }), /general-purpose/);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("each allowed pair passes, including a full model id and a branch reviewer on opus", (t) => {
|
|
129
|
+
const ws = workspace(t);
|
|
130
|
+
assert.equal(decide(agentCall(ws.on, { subagent_type: "architecture:sdd-planner", model: "opus", prompt: "p" }), ws.tmp), null);
|
|
131
|
+
assert.equal(
|
|
132
|
+
decide(agentCall(ws.on, { subagent_type: "architecture:sdd-branch-reviewer", model: "opus", prompt: "p" }), ws.tmp),
|
|
133
|
+
null,
|
|
134
|
+
);
|
|
135
|
+
assert.equal(
|
|
136
|
+
decide(agentCall(ws.on, { subagent_type: "architecture:sdd-reviewer", model: "sonnet", prompt: "p" }), ws.tmp),
|
|
137
|
+
null,
|
|
138
|
+
);
|
|
139
|
+
assert.equal(decide(agentCall(ws.on, { model: "haiku", prompt: "p" }), ws.tmp), null);
|
|
140
|
+
assert.equal(
|
|
141
|
+
decide(agentCall(ws.on, { subagent_type: "architecture:sdd-implementer", model: "sonnet", prompt: "p" }), ws.tmp),
|
|
142
|
+
null,
|
|
143
|
+
);
|
|
144
|
+
decide(subagentEvent(ws.on, "architecture:sdd-implementer"), ws.tmp);
|
|
145
|
+
assert.equal(
|
|
146
|
+
decide(
|
|
147
|
+
agentCall(ws.on, { subagent_type: "architecture:sdd-implementer", model: "claude-sonnet-5", prompt: "p" }),
|
|
148
|
+
ws.tmp,
|
|
149
|
+
),
|
|
150
|
+
null,
|
|
151
|
+
);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("a repository's models override replaces one type's families and leaves the rest at default", (t) => {
|
|
155
|
+
const ws = workspace(t, { maxPromptChars: 80, models: { "architecture:sdd-planner": ["sonnet"] } });
|
|
156
|
+
assert.equal(
|
|
157
|
+
decide(agentCall(ws.on, { subagent_type: "architecture:sdd-planner", model: "sonnet", prompt: "p" }), ws.tmp),
|
|
158
|
+
null,
|
|
159
|
+
);
|
|
160
|
+
assert.match(
|
|
161
|
+
reasonOf(decide(agentCall(ws.on, { subagent_type: "architecture:sdd-implementer", model: "opus", prompt: "p" }), ws.tmp)) ?? "",
|
|
162
|
+
/architecture:sdd-implementer/,
|
|
163
|
+
);
|
|
164
|
+
});
|
|
165
|
+
|
|
120
166
|
test("a slot with no stop expires after slotMinutes", (t) => {
|
|
121
167
|
const ws = workspace(t);
|
|
122
168
|
decide(agentCall(ws.on, implementer), ws.tmp);
|
|
@@ -3,25 +3,55 @@
|
|
|
3
3
|
// and fork, because a rule held only in the conversation is lost to a compaction.
|
|
4
4
|
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
|
-
import { dispatchSettingsAt } from "./dispatch.mjs";
|
|
6
|
+
import { dispatchSettingsAt, exploreSettingsAt } from "./dispatch.mjs";
|
|
7
7
|
|
|
8
8
|
export const REMINDER =
|
|
9
9
|
"Subagent workflow (swarm.dispatch in qc.config.json): run a plan with superpowers:subagent-driven-development. " +
|
|
10
10
|
"Dispatch architecture:sdd-planner to write a plan, architecture:sdd-implementer for one task, and " +
|
|
11
|
-
"architecture:sdd-reviewer to review it
|
|
12
|
-
"
|
|
11
|
+
"architecture:sdd-reviewer to review it; before merge, dispatch architecture:sdd-branch-reviewer to review the " +
|
|
12
|
+
"whole branch. The planner and the branch reviewer run on opus, the implementer and the task reviewer on sonnet. " +
|
|
13
|
+
"Run one implementer at a time: a hook refuses a second while one runs. Name a model on any other dispatch, and " +
|
|
14
|
+
"pass each brief as a file path.";
|
|
13
15
|
|
|
14
|
-
const context = (text) => ({ hookSpecificOutput: { hookEventName:
|
|
16
|
+
const context = (eventName, text) => ({ hookSpecificOutput: { hookEventName: eventName, additionalContext: text } });
|
|
15
17
|
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
+
/** One added line naming `swarm.explore`'s tools, or "" when the section is off or names none. */
|
|
19
|
+
function exploreLine(cwd) {
|
|
18
20
|
let settings;
|
|
19
21
|
try {
|
|
20
|
-
settings =
|
|
22
|
+
settings = exploreSettingsAt(cwd);
|
|
23
|
+
} catch {
|
|
24
|
+
// The explore guard and hint each report their own config error; the dispatch note stays unaffected.
|
|
25
|
+
return "";
|
|
26
|
+
}
|
|
27
|
+
if (!settings || settings.tools.length === 0) return "";
|
|
28
|
+
return ` The repository's own explore tools: ${settings.tools.map((tool) => tool.name).join(", ")}.`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** @returns the hook output for a subagent's own start, or null when `swarm.explore` names no tools. */
|
|
32
|
+
function decideSubagentStart(cwd) {
|
|
33
|
+
const line = exploreLine(cwd).trim();
|
|
34
|
+
return line === "" ? null : context("SubagentStart", line);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** @returns the hook output, or null when the checkout turns on neither `swarm.dispatch` nor `swarm.explore`. */
|
|
38
|
+
function decideSessionStart(call) {
|
|
39
|
+
const cwd = call.cwd ?? process.cwd();
|
|
40
|
+
let dispatch;
|
|
41
|
+
try {
|
|
42
|
+
dispatch = dispatchSettingsAt(cwd);
|
|
21
43
|
} catch (error) {
|
|
22
|
-
return context(`Dispatch guard is off: ${error.message}`);
|
|
44
|
+
return context("SessionStart", `Dispatch guard is off: ${error.message}`);
|
|
23
45
|
}
|
|
24
|
-
|
|
46
|
+
const explore = exploreLine(cwd);
|
|
47
|
+
if (!dispatch) return explore === "" ? null : context("SessionStart", explore.trim());
|
|
48
|
+
return context("SessionStart", `${REMINDER}${explore}`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** @returns the hook output, or null when there is nothing to add for this event. */
|
|
52
|
+
export function decide(call) {
|
|
53
|
+
if (call.hook_event_name === "SubagentStart") return decideSubagentStart(call.cwd ?? process.cwd());
|
|
54
|
+
return decideSessionStart(call);
|
|
25
55
|
}
|
|
26
56
|
|
|
27
57
|
async function readStdin() {
|
|
@@ -24,6 +24,7 @@ function checkouts(t, configs) {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
const start = (cwd, source) => ({ session_id: "s", cwd, hook_event_name: "SessionStart", source });
|
|
27
|
+
const subagentStart = (cwd) => ({ session_id: "s", cwd, hook_event_name: "SubagentStart", agent_type: "sonnet-implementer" });
|
|
27
28
|
|
|
28
29
|
test("a checkout with no config, or no dispatch section, gets no note", (t) => {
|
|
29
30
|
const [plain, off] = checkouts(t, [null, { swarm: { toolCallBudget: 50 } }]);
|
|
@@ -40,17 +41,58 @@ test("with the section on, every start adds the note, a compaction included", (t
|
|
|
40
41
|
}
|
|
41
42
|
});
|
|
42
43
|
|
|
43
|
-
test("the note names the workflow, the
|
|
44
|
+
test("the note names the workflow, the four types, the model tiers, and the one-implementer rule, in a short text", () => {
|
|
44
45
|
for (const word of [
|
|
45
46
|
"superpowers:subagent-driven-development",
|
|
46
47
|
"architecture:sdd-planner",
|
|
47
48
|
"architecture:sdd-implementer",
|
|
48
49
|
"architecture:sdd-reviewer",
|
|
50
|
+
"architecture:sdd-branch-reviewer",
|
|
49
51
|
"one implementer at a time",
|
|
50
52
|
]) {
|
|
51
53
|
assert.ok(REMINDER.includes(word), word);
|
|
52
54
|
}
|
|
53
|
-
assert.ok(REMINDER.length <
|
|
55
|
+
assert.ok(REMINDER.length < 800, `${REMINDER.length} characters`);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test("with swarm.explore also on, the note names its tools", (t) => {
|
|
59
|
+
const [on] = checkouts(t, [
|
|
60
|
+
{ swarm: { dispatch: {}, explore: { tools: [{ name: "slm-rerank", use: "u", how: "h" }, { name: "GitNexus", use: "u", how: "h" }] } } },
|
|
61
|
+
]);
|
|
62
|
+
const text = decide(start(on, "startup")).hookSpecificOutput.additionalContext;
|
|
63
|
+
assert.ok(text.startsWith(REMINDER));
|
|
64
|
+
assert.match(text, /slm-rerank, GitNexus/);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("with swarm.explore off, or naming no tools, the note is exactly REMINDER", (t) => {
|
|
68
|
+
const [off, empty] = checkouts(t, [
|
|
69
|
+
{ swarm: { dispatch: {} } },
|
|
70
|
+
{ swarm: { dispatch: {}, explore: { tools: [] } } },
|
|
71
|
+
]);
|
|
72
|
+
assert.equal(decide(start(off, "startup")).hookSpecificOutput.additionalContext, REMINDER);
|
|
73
|
+
assert.equal(decide(start(empty, "startup")).hookSpecificOutput.additionalContext, REMINDER);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("with swarm.explore on and swarm.dispatch off, the SessionStart note still names the tools", (t) => {
|
|
77
|
+
const [on] = checkouts(t, [{ swarm: { explore: { tools: [{ name: "slm-rerank", use: "u", how: "h" }] } } }]);
|
|
78
|
+
const output = decide(start(on, "startup"));
|
|
79
|
+
assert.equal(output.hookSpecificOutput.hookEventName, "SessionStart");
|
|
80
|
+
assert.match(output.hookSpecificOutput.additionalContext, /slm-rerank/);
|
|
81
|
+
assert.ok(!output.hookSpecificOutput.additionalContext.startsWith(" "));
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("SubagentStart names the tools when swarm.explore is on, independent of swarm.dispatch", (t) => {
|
|
85
|
+
const [on] = checkouts(t, [{ swarm: { explore: { tools: [{ name: "slm-rerank", use: "u", how: "h" }] } } }]);
|
|
86
|
+
const output = decide(subagentStart(on));
|
|
87
|
+
assert.equal(output.hookSpecificOutput.hookEventName, "SubagentStart");
|
|
88
|
+
assert.match(output.hookSpecificOutput.additionalContext, /slm-rerank/);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("SubagentStart with no swarm.explore section, or none naming tools, is a no-op", (t) => {
|
|
92
|
+
const [plain, off, empty] = checkouts(t, [null, { swarm: { dispatch: {} } }, { swarm: { explore: { tools: [] } } }]);
|
|
93
|
+
assert.equal(decide(subagentStart(plain)), null);
|
|
94
|
+
assert.equal(decide(subagentStart(off)), null);
|
|
95
|
+
assert.equal(decide(subagentStart(empty)), null);
|
|
54
96
|
});
|
|
55
97
|
|
|
56
98
|
test("a config error reaches the session as context", (t) => {
|
|
@@ -76,3 +118,14 @@ test("hooks.json runs the note on every SessionStart source", () => {
|
|
|
76
118
|
);
|
|
77
119
|
assert.deepEqual(entries.map((entry) => entry.matcher), [undefined]);
|
|
78
120
|
});
|
|
121
|
+
|
|
122
|
+
test("hooks.json also runs the note on SubagentStart, all matchers, beside the existing entry", () => {
|
|
123
|
+
const { hooks } = JSON.parse(readFileSync(HOOKS, "utf8"));
|
|
124
|
+
const entries = hooks.SubagentStart ?? [];
|
|
125
|
+
const noteEntries = entries.filter((entry) => entry.hooks.some((hook) => hook.command.includes("dispatch-reminder.mjs")));
|
|
126
|
+
assert.deepEqual(noteEntries.map((entry) => entry.matcher), [undefined]);
|
|
127
|
+
assert.ok(
|
|
128
|
+
entries.some((entry) => entry.hooks.some((hook) => hook.command.includes("dispatch-guard.mjs"))),
|
|
129
|
+
"the existing dispatch-guard.mjs SubagentStart entry stays",
|
|
130
|
+
);
|
|
131
|
+
});
|
package/src/cli/dispatch.mjs
CHANGED
|
@@ -3,17 +3,36 @@
|
|
|
3
3
|
|
|
4
4
|
import { existsSync } from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
6
|
-
import { CONFIG_FILE, dispatchDefaults, load, merge } from "../config.mjs";
|
|
6
|
+
import { CONFIG_FILE, MODEL_FAMILIES, dispatchDefaults, exploreDefaults, load, merge } from "../config.mjs";
|
|
7
7
|
import { checkoutRootOf } from "./checkout-root.mjs";
|
|
8
8
|
|
|
9
9
|
const KEY = "swarm.dispatch";
|
|
10
|
+
const EXPLORE_KEY = "swarm.explore";
|
|
10
11
|
const DEFAULT_TYPE = "general-purpose";
|
|
11
12
|
const FORK = "fork";
|
|
13
|
+
const WILDCARD_TYPE = "*";
|
|
12
14
|
|
|
13
15
|
const isNameList = (value) => Array.isArray(value) && value.every((name) => typeof name === "string" && name !== "");
|
|
16
|
+
const isFamilyList = (value) => Array.isArray(value) && value.length > 0 && value.every((name) => MODEL_FAMILIES.includes(name));
|
|
14
17
|
const wrong = (key, value, want) =>
|
|
15
18
|
new Error(`${KEY}.${key} in qc.config.json must be ${want}, got ${JSON.stringify(value)}`);
|
|
16
19
|
|
|
20
|
+
function checkModels(models) {
|
|
21
|
+
const wantFamilies = `a non-empty list of known families (${MODEL_FAMILIES.join(", ")})`;
|
|
22
|
+
if (typeof models !== "object" || models === null || Array.isArray(models)) {
|
|
23
|
+
throw wrong("models", models, "an object mapping an agent type to its model families");
|
|
24
|
+
}
|
|
25
|
+
for (const [type, families] of Object.entries(models)) {
|
|
26
|
+
if (!isFamilyList(families)) throw wrong(`models.${type}`, families, wantFamilies);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The first family name a model string contains, lower-cased. Null when it names none the guard knows. */
|
|
31
|
+
export function familyOf(model) {
|
|
32
|
+
const lower = model.toLowerCase();
|
|
33
|
+
return MODEL_FAMILIES.find((family) => lower.includes(family)) ?? null;
|
|
34
|
+
}
|
|
35
|
+
|
|
17
36
|
/** @returns the dispatch settings, or null when the section is absent; throws naming the key a repository got wrong. */
|
|
18
37
|
export function dispatchSettings(swarm = {}) {
|
|
19
38
|
const raw = swarm.dispatch;
|
|
@@ -21,14 +40,15 @@ export function dispatchSettings(swarm = {}) {
|
|
|
21
40
|
if (typeof raw !== "object" || Array.isArray(raw)) {
|
|
22
41
|
throw new Error(`${KEY} in qc.config.json must be an object, got ${JSON.stringify(raw)}`);
|
|
23
42
|
}
|
|
24
|
-
const { allowedTypes, implementerTypes, maxPromptChars, slotMinutes } = merge(dispatchDefaults, raw);
|
|
43
|
+
const { allowedTypes, implementerTypes, maxPromptChars, slotMinutes, models } = merge(dispatchDefaults, raw);
|
|
25
44
|
if (!isNameList(allowedTypes)) throw wrong("allowedTypes", allowedTypes, "a list of agent types");
|
|
26
45
|
if (!isNameList(implementerTypes)) throw wrong("implementerTypes", implementerTypes, "a list of agent types");
|
|
27
46
|
if (!Number.isInteger(maxPromptChars) || maxPromptChars < 1) {
|
|
28
47
|
throw wrong("maxPromptChars", maxPromptChars, "a positive whole number");
|
|
29
48
|
}
|
|
30
49
|
if (typeof slotMinutes !== "number" || !(slotMinutes > 0)) throw wrong("slotMinutes", slotMinutes, "a positive number");
|
|
31
|
-
|
|
50
|
+
checkModels(models);
|
|
51
|
+
return { allowedTypes, implementerTypes, maxPromptChars, slotMinutes, models };
|
|
32
52
|
}
|
|
33
53
|
|
|
34
54
|
/** @returns the settings of the checkout that holds `cwd`, or null when it has no config or no section. */
|
|
@@ -38,6 +58,44 @@ export function dispatchSettingsAt(cwd) {
|
|
|
38
58
|
return dispatchSettings(load(root).swarm);
|
|
39
59
|
}
|
|
40
60
|
|
|
61
|
+
const isToolEntry = (entry) =>
|
|
62
|
+
isPlainRecord(entry) && ["name", "use", "how"].every((key) => typeof entry[key] === "string" && entry[key] !== "");
|
|
63
|
+
const isPlainRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
64
|
+
const wrongExplore = (key, value, want) =>
|
|
65
|
+
new Error(`${EXPLORE_KEY}.${key} in qc.config.json must be ${want}, got ${JSON.stringify(value)}`);
|
|
66
|
+
|
|
67
|
+
/** @returns the explore settings, or null when the section is absent; throws naming the key a repository got wrong. */
|
|
68
|
+
export function exploreSettings(swarm = {}) {
|
|
69
|
+
const raw = swarm.explore;
|
|
70
|
+
if (raw === undefined || raw === null || raw === false) return null;
|
|
71
|
+
if (typeof raw !== "object" || Array.isArray(raw)) {
|
|
72
|
+
throw new Error(`${EXPLORE_KEY} in qc.config.json must be an object, got ${JSON.stringify(raw)}`);
|
|
73
|
+
}
|
|
74
|
+
const { tools, summarizer, maxReadLines, maxGrepLines, maxOutputChars, exempt } = merge(exploreDefaults, raw);
|
|
75
|
+
if (!Array.isArray(tools) || !tools.every(isToolEntry)) {
|
|
76
|
+
throw wrongExplore("tools", tools, 'a list of { "name", "use", "how" } strings');
|
|
77
|
+
}
|
|
78
|
+
if (summarizer !== null && (typeof summarizer !== "string" || summarizer === "")) {
|
|
79
|
+
throw wrongExplore("summarizer", summarizer, "a non-empty string or null");
|
|
80
|
+
}
|
|
81
|
+
for (const [key, value] of [
|
|
82
|
+
["maxReadLines", maxReadLines],
|
|
83
|
+
["maxGrepLines", maxGrepLines],
|
|
84
|
+
["maxOutputChars", maxOutputChars],
|
|
85
|
+
]) {
|
|
86
|
+
if (!Number.isInteger(value) || value < 1) throw wrongExplore(key, value, "a positive whole number");
|
|
87
|
+
}
|
|
88
|
+
if (!isNameList(exempt)) throw wrongExplore("exempt", exempt, "a list of globs");
|
|
89
|
+
return { tools, summarizer, maxReadLines, maxGrepLines, maxOutputChars, exempt };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** @returns the explore settings of the checkout that holds `cwd`, or null when it has no config or no section. */
|
|
93
|
+
export function exploreSettingsAt(cwd) {
|
|
94
|
+
const root = checkoutRootOf(cwd);
|
|
95
|
+
if (!root || !existsSync(path.join(root, CONFIG_FILE))) return null;
|
|
96
|
+
return exploreSettings(load(root).swarm);
|
|
97
|
+
}
|
|
98
|
+
|
|
41
99
|
/** The type a dispatch names, trimmed. The Agent tool runs general-purpose when it names none. */
|
|
42
100
|
export const typeOf = (input) =>
|
|
43
101
|
typeof input.subagent_type === "string" && input.subagent_type.trim() !== "" ? input.subagent_type.trim() : DEFAULT_TYPE;
|
|
@@ -63,12 +121,31 @@ const promptRefusal = (length, max) =>
|
|
|
63
121
|
`Dispatch guard: the prompt has ${length} characters, over ${KEY}.maxPromptChars (${max}) in qc.config.json. ` +
|
|
64
122
|
"Write the brief to a file, and send a short prompt that names the brief and the report file.";
|
|
65
123
|
|
|
124
|
+
function tierRefusal(type, model, families) {
|
|
125
|
+
return (
|
|
126
|
+
`Dispatch guard: ${type} may run only on ${families.join(", ")}, so it refuses model "${model}". ` +
|
|
127
|
+
`Name a model of one of those families, or dispatch a type in ${KEY}.models with one that fits.`
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** @returns the reason a named model breaks its type's tier, or null when it fits. */
|
|
132
|
+
function tierRefusalFor(type, model, settings) {
|
|
133
|
+
const families = settings.models[type] ?? settings.models[WILDCARD_TYPE];
|
|
134
|
+
const family = familyOf(model);
|
|
135
|
+
if (family && families.includes(family)) return null;
|
|
136
|
+
return tierRefusal(type, model, families);
|
|
137
|
+
}
|
|
138
|
+
|
|
66
139
|
/** @returns the reason the dispatch breaks a rule that needs no state, or null to let it through. */
|
|
67
140
|
export function dispatchRefusal(input, settings) {
|
|
68
141
|
const type = typeOf(input);
|
|
69
142
|
const model = typeof input.model === "string" ? input.model.trim() : "";
|
|
70
143
|
const allowed = settings.allowedTypes.includes(type);
|
|
71
144
|
if (!allowed && (type === FORK || model === "")) return modelRefusal(type, settings);
|
|
145
|
+
if (model !== "" && type !== FORK) {
|
|
146
|
+
const refusal = tierRefusalFor(type, model, settings);
|
|
147
|
+
if (refusal) return refusal;
|
|
148
|
+
}
|
|
72
149
|
const length = typeof input.prompt === "string" ? input.prompt.length : 0;
|
|
73
150
|
if (length > settings.maxPromptChars) return promptRefusal(length, settings.maxPromptChars);
|
|
74
151
|
return null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { strict as assert } from "node:assert";
|
|
2
2
|
import { test } from "node:test";
|
|
3
3
|
import { defaults, dispatchDefaults, merge } from "../config.mjs";
|
|
4
|
-
import { dispatchRefusal, dispatchSettings, isImplementer, slotRefusal, typeOf } from "./dispatch.mjs";
|
|
4
|
+
import { dispatchRefusal, dispatchSettings, familyOf, isImplementer, slotRefusal, typeOf } from "./dispatch.mjs";
|
|
5
5
|
|
|
6
6
|
test("a swarm section with no dispatch key keeps the guard off", () => {
|
|
7
7
|
assert.equal(dispatchSettings({}), null);
|
|
@@ -28,11 +28,29 @@ test("a wrong value names its key", () => {
|
|
|
28
28
|
[{ implementerTypes: [""] }, /swarm\.dispatch\.implementerTypes/],
|
|
29
29
|
[{ maxPromptChars: 0 }, /swarm\.dispatch\.maxPromptChars/],
|
|
30
30
|
[{ slotMinutes: -1 }, /swarm\.dispatch\.slotMinutes/],
|
|
31
|
+
[{ models: "opus" }, /swarm\.dispatch\.models\b/],
|
|
32
|
+
[{ models: ["opus"] }, /swarm\.dispatch\.models\b/],
|
|
33
|
+
[{ models: { "sdd-planner": [] } }, /swarm\.dispatch\.models\.sdd-planner/],
|
|
34
|
+
[{ models: { "sdd-planner": ["gpt"] } }, /swarm\.dispatch\.models\.sdd-planner/],
|
|
31
35
|
]) {
|
|
32
36
|
assert.throws(() => dispatchSettings({ dispatch }), key, JSON.stringify(dispatch));
|
|
33
37
|
}
|
|
34
38
|
});
|
|
35
39
|
|
|
40
|
+
test("a repository's models merges key by key with the defaults", () => {
|
|
41
|
+
const settings = dispatchSettings({ dispatch: { models: { "architecture:sdd-planner": ["sonnet"] } } });
|
|
42
|
+
assert.deepEqual(settings.models["architecture:sdd-planner"], ["sonnet"]);
|
|
43
|
+
assert.deepEqual(settings.models["architecture:sdd-implementer"], dispatchDefaults.models["architecture:sdd-implementer"]);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("familyOf finds the first known family a model string contains, lower-cased", () => {
|
|
47
|
+
assert.equal(familyOf("sonnet"), "sonnet");
|
|
48
|
+
assert.equal(familyOf("claude-sonnet-5"), "sonnet");
|
|
49
|
+
assert.equal(familyOf("opus[1m]"), "opus");
|
|
50
|
+
assert.equal(familyOf("OPUS"), "opus");
|
|
51
|
+
assert.equal(familyOf("gpt-4"), null);
|
|
52
|
+
});
|
|
53
|
+
|
|
36
54
|
const on = dispatchSettings({ dispatch: { maxPromptChars: 20 } });
|
|
37
55
|
|
|
38
56
|
test("a dispatch with neither a model nor an allowed type is refused, and the reason names both fixes", () => {
|
|
@@ -68,6 +86,52 @@ test("the model rule comes before the length rule", () => {
|
|
|
68
86
|
assert.match(dispatchRefusal({ prompt: "x".repeat(21) }, on) ?? "", /names no model/);
|
|
69
87
|
});
|
|
70
88
|
|
|
89
|
+
test("a planner on sonnet is refused, and an implementer on opus is refused", () => {
|
|
90
|
+
const planner = dispatchRefusal({ subagent_type: "architecture:sdd-planner", model: "sonnet" }, on) ?? "";
|
|
91
|
+
assert.match(planner, /architecture:sdd-planner/);
|
|
92
|
+
assert.match(planner, /"sonnet"/);
|
|
93
|
+
assert.match(planner, /opus/);
|
|
94
|
+
const implementer = dispatchRefusal({ subagent_type: "architecture:sdd-implementer", model: "opus" }, on) ?? "";
|
|
95
|
+
assert.match(implementer, /architecture:sdd-implementer/);
|
|
96
|
+
assert.match(implementer, /"opus"/);
|
|
97
|
+
assert.match(implementer, /sonnet/);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("a general-purpose dispatch on opus is refused, naming the wildcard's families", () => {
|
|
101
|
+
const reason = dispatchRefusal({ model: "opus" }, on) ?? "";
|
|
102
|
+
assert.match(reason, /general-purpose/);
|
|
103
|
+
assert.match(reason, /sonnet, haiku/);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("a model string with no known family is refused", () => {
|
|
107
|
+
assert.match(dispatchRefusal({ model: "gpt-4" }, on) ?? "", /general-purpose/);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("each allowed pair passes, including a full model id that resolves to its family", () => {
|
|
111
|
+
assert.equal(dispatchRefusal({ subagent_type: "architecture:sdd-planner", model: "opus" }, on), null);
|
|
112
|
+
assert.equal(dispatchRefusal({ subagent_type: "architecture:sdd-branch-reviewer", model: "opus" }, on), null);
|
|
113
|
+
assert.equal(dispatchRefusal({ subagent_type: "architecture:sdd-implementer", model: "sonnet" }, on), null);
|
|
114
|
+
assert.equal(dispatchRefusal({ subagent_type: "architecture:sdd-reviewer", model: "sonnet" }, on), null);
|
|
115
|
+
assert.equal(dispatchRefusal({ model: "haiku" }, on), null);
|
|
116
|
+
assert.equal(dispatchRefusal({ subagent_type: "architecture:sdd-implementer", model: "claude-sonnet-5" }, on), null);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test("a fork keeps its current rule and never reaches the tier check", () => {
|
|
120
|
+
assert.match(
|
|
121
|
+
dispatchRefusal({ subagent_type: "fork", model: "gpt-4" }, on) ?? "",
|
|
122
|
+
/`fork` is in swarm\.dispatch\.allowedTypes/,
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("a repository override replaces one type's families and leaves the rest at default", () => {
|
|
127
|
+
const withOverride = dispatchSettings({ dispatch: { models: { "architecture:sdd-planner": ["sonnet"] } } });
|
|
128
|
+
assert.equal(dispatchRefusal({ subagent_type: "architecture:sdd-planner", model: "sonnet" }, withOverride), null);
|
|
129
|
+
assert.match(
|
|
130
|
+
dispatchRefusal({ subagent_type: "architecture:sdd-implementer", model: "opus" }, withOverride) ?? "",
|
|
131
|
+
/architecture:sdd-implementer/,
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
|
|
71
135
|
test("an omitted type is general-purpose, and only a listed type is an implementer", () => {
|
|
72
136
|
assert.equal(typeOf({}), "general-purpose");
|
|
73
137
|
assert.equal(typeOf({ subagent_type: "" }), "general-purpose");
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The trigger for `swarm.explore`'s read budget: PreToolUse on Read refuses a whole-file read of a
|
|
3
|
+
// long text file and names the repository's own tools. The same file read the same way passes on
|
|
4
|
+
// a second attempt, so a real need for the whole file costs one retry, never a standing exemption.
|
|
5
|
+
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
import {
|
|
8
|
+
closeSync,
|
|
9
|
+
existsSync,
|
|
10
|
+
mkdirSync,
|
|
11
|
+
openSync,
|
|
12
|
+
readdirSync,
|
|
13
|
+
readSync,
|
|
14
|
+
realpathSync,
|
|
15
|
+
statSync,
|
|
16
|
+
unlinkSync,
|
|
17
|
+
writeFileSync,
|
|
18
|
+
} from "node:fs";
|
|
19
|
+
import os from "node:os";
|
|
20
|
+
import path from "node:path";
|
|
21
|
+
import { fileURLToPath } from "node:url";
|
|
22
|
+
import { globMatcher } from "../glob.mjs";
|
|
23
|
+
import { checkoutRootOf } from "./checkout-root.mjs";
|
|
24
|
+
import { exploreSettingsAt } from "./dispatch.mjs";
|
|
25
|
+
import { slotDirOf } from "./dispatch-slot.mjs";
|
|
26
|
+
|
|
27
|
+
const BINARY_EXTENSIONS = new Set(["png", "jpg", "jpeg", "gif", "webp", "svg", "pdf", "ipynb"]);
|
|
28
|
+
const SNIFF_BYTES = 8192;
|
|
29
|
+
const REFUSED_SUFFIX = ".refused";
|
|
30
|
+
const MAX_REFUSED = 200;
|
|
31
|
+
|
|
32
|
+
const output = (fields) => ({ hookSpecificOutput: { hookEventName: "PreToolUse", ...fields } });
|
|
33
|
+
const deny = (reason) => output({ permissionDecision: "deny", permissionDecisionReason: reason });
|
|
34
|
+
const context = (text) => output({ additionalContext: text });
|
|
35
|
+
|
|
36
|
+
/** The real path of `resolved`, so two spellings of one file or folder (a `..` segment, a
|
|
37
|
+
* case-folded drive letter, a symlink) resolve to one, everywhere this guard compares or hashes a
|
|
38
|
+
* path; falls back to `resolved` itself when the real path cannot be read. */
|
|
39
|
+
function realOf(resolved) {
|
|
40
|
+
try {
|
|
41
|
+
return realpathSync.native(resolved);
|
|
42
|
+
} catch {
|
|
43
|
+
return resolved;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// One marker file per refused path, named by its hash, never a shared list: two Read hooks of one
|
|
48
|
+
// batch each create their own marker, so neither call can lose the other's write.
|
|
49
|
+
const markerFileOf = (dir, realAbsolute) => path.join(dir, `${createHash("sha256").update(realAbsolute).digest("hex")}${REFUSED_SUFFIX}`);
|
|
50
|
+
|
|
51
|
+
/** Records one refusal. An existing marker (a concurrent refusal of the same path) is left as is. */
|
|
52
|
+
function recordRefusal(dir, realAbsolute) {
|
|
53
|
+
try {
|
|
54
|
+
mkdirSync(dir, { recursive: true });
|
|
55
|
+
writeFileSync(markerFileOf(dir, realAbsolute), "", { flag: "wx" });
|
|
56
|
+
} catch (error) {
|
|
57
|
+
if (error.code !== "EEXIST") return; // No memory of this refusal just refuses the next read again too.
|
|
58
|
+
}
|
|
59
|
+
capMarkers(dir);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** True and consumed when `realAbsolute` was refused before: a second attempt passes, a third is refused anew. */
|
|
63
|
+
function consumeRefusal(dir, realAbsolute) {
|
|
64
|
+
try {
|
|
65
|
+
unlinkSync(markerFileOf(dir, realAbsolute));
|
|
66
|
+
return true;
|
|
67
|
+
} catch {
|
|
68
|
+
return false; // ENOENT (never refused), or a race that already consumed it — either way, not refused now.
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Keeps at most `MAX_REFUSED` markers, dropping the oldest by mtime. Ignores a concurrent unlink of the same file. */
|
|
73
|
+
function capMarkers(dir) {
|
|
74
|
+
let names;
|
|
75
|
+
try {
|
|
76
|
+
names = readdirSync(dir).filter((name) => name.endsWith(REFUSED_SUFFIX));
|
|
77
|
+
} catch {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const dated = names
|
|
81
|
+
.map((name) => {
|
|
82
|
+
try {
|
|
83
|
+
return { name, mtimeMs: statSync(path.join(dir, name)).mtimeMs };
|
|
84
|
+
} catch {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
.filter((entry) => entry !== null)
|
|
89
|
+
.sort((a, b) => a.mtimeMs - b.mtimeMs);
|
|
90
|
+
for (const { name } of dated.slice(0, dated.length - MAX_REFUSED)) {
|
|
91
|
+
try {
|
|
92
|
+
unlinkSync(path.join(dir, name));
|
|
93
|
+
} catch {
|
|
94
|
+
// Already gone — another call raced this same cleanup, and the cap still holds.
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function isBinaryByExtension(file) {
|
|
100
|
+
const ext = path.extname(file).slice(1).toLowerCase();
|
|
101
|
+
return BINARY_EXTENSIONS.has(ext);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** A NUL byte in the first 8 KB, cheaply, the same signal `file`-type tools use. False on a read error. */
|
|
105
|
+
function isBinaryByContent(file) {
|
|
106
|
+
let fd;
|
|
107
|
+
try {
|
|
108
|
+
fd = openSync(file, "r");
|
|
109
|
+
} catch {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
const buf = Buffer.alloc(SNIFF_BYTES);
|
|
114
|
+
const read = readSync(fd, buf, 0, buf.length, null);
|
|
115
|
+
return buf.subarray(0, read).includes(0);
|
|
116
|
+
} catch {
|
|
117
|
+
return false;
|
|
118
|
+
} finally {
|
|
119
|
+
closeSync(fd);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** True once more than `maxLines` newlines are seen, reading in chunks and stopping early. False on a read error. */
|
|
124
|
+
function exceedsLineBudget(file, maxLines) {
|
|
125
|
+
let fd;
|
|
126
|
+
try {
|
|
127
|
+
fd = openSync(file, "r");
|
|
128
|
+
} catch {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
const buf = Buffer.alloc(64 * 1024);
|
|
133
|
+
let count = 0;
|
|
134
|
+
for (;;) {
|
|
135
|
+
const read = readSync(fd, buf, 0, buf.length, null);
|
|
136
|
+
if (read === 0) return false;
|
|
137
|
+
for (let i = 0; i < read; i += 1) {
|
|
138
|
+
if (buf[i] === 10) {
|
|
139
|
+
count += 1;
|
|
140
|
+
if (count > maxLines) return true;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
} catch {
|
|
145
|
+
return false;
|
|
146
|
+
} finally {
|
|
147
|
+
closeSync(fd);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function refusalMessage(tools) {
|
|
152
|
+
const lines = tools.map((tool) => `- ${tool.name}: ${tool.use} (${tool.how})`);
|
|
153
|
+
lines.push("Read a range with offset and limit, or read the same file again to read it whole.");
|
|
154
|
+
return lines.join("\n");
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** The verdict on one Read call. @returns the hook output, or null to let the call run with no message. */
|
|
158
|
+
export function decide(call, tmp = os.tmpdir()) {
|
|
159
|
+
if (call.hook_event_name !== "PreToolUse" || call.tool_name !== "Read") return null;
|
|
160
|
+
const input = call.tool_input ?? {};
|
|
161
|
+
const filePath = input.file_path;
|
|
162
|
+
if (typeof filePath !== "string" || filePath === "") return null;
|
|
163
|
+
|
|
164
|
+
let settings;
|
|
165
|
+
try {
|
|
166
|
+
settings = exploreSettingsAt(call.cwd ?? process.cwd());
|
|
167
|
+
} catch (error) {
|
|
168
|
+
// A config typo must not stop every read; the session sees the error and reports it.
|
|
169
|
+
return context(`Explore guard is off: ${error.message}`);
|
|
170
|
+
}
|
|
171
|
+
if (!settings) return null;
|
|
172
|
+
|
|
173
|
+
const cwd = call.cwd ?? process.cwd();
|
|
174
|
+
const absolute = path.resolve(cwd, filePath);
|
|
175
|
+
if (!existsSync(absolute)) return null;
|
|
176
|
+
const realAbsolute = realOf(absolute);
|
|
177
|
+
|
|
178
|
+
const root = checkoutRootOf(path.dirname(realAbsolute));
|
|
179
|
+
// A file in no checkout, or in a checkout other than the session's own, is not this one to judge.
|
|
180
|
+
if (!root || root !== checkoutRootOf(realOf(cwd))) return null;
|
|
181
|
+
const rel = path.relative(root, realAbsolute).split(path.sep).join("/");
|
|
182
|
+
if (globMatcher(settings.exempt)(rel)) return null;
|
|
183
|
+
|
|
184
|
+
if (input.offset !== undefined || input.limit !== undefined) return null;
|
|
185
|
+
if (isBinaryByExtension(realAbsolute) || isBinaryByContent(realAbsolute)) return null;
|
|
186
|
+
if (!exceedsLineBudget(realAbsolute, settings.maxReadLines)) return null;
|
|
187
|
+
|
|
188
|
+
const dir = slotDirOf(call.session_id ?? "session", tmp);
|
|
189
|
+
if (consumeRefusal(dir, realAbsolute)) return null;
|
|
190
|
+
|
|
191
|
+
recordRefusal(dir, realAbsolute);
|
|
192
|
+
return deny(refusalMessage(settings.tools));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async function readStdin() {
|
|
196
|
+
let data = "";
|
|
197
|
+
for await (const chunk of process.stdin) data += chunk;
|
|
198
|
+
return data;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const isEntryPoint = process.argv[1] !== undefined && fileURLToPath(import.meta.url) === process.argv[1];
|
|
202
|
+
if (isEntryPoint) {
|
|
203
|
+
let call = null;
|
|
204
|
+
try {
|
|
205
|
+
call = JSON.parse(await readStdin());
|
|
206
|
+
} catch {
|
|
207
|
+
// Not hook input, so there is nothing to judge.
|
|
208
|
+
}
|
|
209
|
+
const result = call ? decide(call) : null;
|
|
210
|
+
if (result) process.stdout.write(JSON.stringify(result));
|
|
211
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { strict as assert } from "node:assert";
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { existsSync, mkdirSync, mkdtempSync, readdirSync, realpathSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
5
|
+
import os from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { test } from "node:test";
|
|
8
|
+
import { decide } from "./explore-guard.mjs";
|
|
9
|
+
import { slotDirOf } from "./dispatch-slot.mjs";
|
|
10
|
+
|
|
11
|
+
const TOOLS = [{ name: "slm-rerank", use: "find the files for a concept", how: 'slm-rerank -q "<question>" --stub -k 5' }];
|
|
12
|
+
const markerNameOf = (absolute) => `${createHash("sha256").update(absolute).digest("hex")}.refused`;
|
|
13
|
+
|
|
14
|
+
/** A checkout with `swarm.explore` on, one with no config, and a temp folder for the guard's own state. */
|
|
15
|
+
function workspace(t, explore = { tools: TOOLS, maxReadLines: 5 }) {
|
|
16
|
+
const base = realpathSync.native(mkdtempSync(path.join(os.tmpdir(), "qc-explore-")));
|
|
17
|
+
t.after(() => rmSync(base, { recursive: true, force: true }));
|
|
18
|
+
const on = path.join(base, "on");
|
|
19
|
+
const plain = path.join(base, "plain");
|
|
20
|
+
const tmp = path.join(base, "tmp");
|
|
21
|
+
for (const dir of [on, plain]) {
|
|
22
|
+
mkdirSync(dir);
|
|
23
|
+
execFileSync("git", ["init", "-q"], { cwd: dir, stdio: "pipe" });
|
|
24
|
+
}
|
|
25
|
+
writeFileSync(path.join(on, "qc.config.json"), JSON.stringify({ swarm: { explore } }));
|
|
26
|
+
return { on, plain, tmp };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const readCall = (cwd, file_path, extra = {}) => ({
|
|
30
|
+
session_id: "session-aaaa",
|
|
31
|
+
cwd,
|
|
32
|
+
hook_event_name: "PreToolUse",
|
|
33
|
+
tool_name: "Read",
|
|
34
|
+
tool_input: { file_path, ...extra },
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const longFile = (dir, name = "long.txt", lines = 20) => {
|
|
38
|
+
const file = path.join(dir, name);
|
|
39
|
+
writeFileSync(file, Array.from({ length: lines }, (_, i) => `line ${i}`).join("\n") + "\n");
|
|
40
|
+
return file;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const reasonOf = (result) =>
|
|
44
|
+
result?.hookSpecificOutput?.permissionDecision === "deny" ? result.hookSpecificOutput.permissionDecisionReason : null;
|
|
45
|
+
|
|
46
|
+
test("a whole-file read of a long text file is refused, naming the tool and the retry", (t) => {
|
|
47
|
+
const ws = workspace(t);
|
|
48
|
+
const file = longFile(ws.on);
|
|
49
|
+
const reason = reasonOf(decide(readCall(ws.on, file), ws.tmp));
|
|
50
|
+
assert.match(reason, /slm-rerank: find the files for a concept \(slm-rerank -q/);
|
|
51
|
+
assert.match(reason, /Read a range with offset and limit, or read the same file again to read it whole\./);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("the same file read the same way passes on the second attempt", (t) => {
|
|
55
|
+
const ws = workspace(t);
|
|
56
|
+
const file = longFile(ws.on);
|
|
57
|
+
assert.notEqual(decide(readCall(ws.on, file), ws.tmp), null);
|
|
58
|
+
assert.equal(decide(readCall(ws.on, file), ws.tmp), null);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("a ranged read passes even on the first attempt", (t) => {
|
|
62
|
+
const ws = workspace(t);
|
|
63
|
+
const file = longFile(ws.on);
|
|
64
|
+
assert.equal(decide(readCall(ws.on, file, { offset: 1, limit: 5 }), ws.tmp), null);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("an exempt path passes", (t) => {
|
|
68
|
+
const ws = workspace(t, { tools: TOOLS, maxReadLines: 5, exempt: ["**/long.txt"] });
|
|
69
|
+
const file = longFile(ws.on);
|
|
70
|
+
assert.equal(decide(readCall(ws.on, file), ws.tmp), null);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("a file within the line budget passes", (t) => {
|
|
74
|
+
const ws = workspace(t);
|
|
75
|
+
const file = longFile(ws.on, "short.txt", 3);
|
|
76
|
+
assert.equal(decide(readCall(ws.on, file), ws.tmp), null);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test("a binary file by extension passes with no line count", (t) => {
|
|
80
|
+
const ws = workspace(t);
|
|
81
|
+
const file = path.join(ws.on, "image.png");
|
|
82
|
+
writeFileSync(file, Buffer.from(Array.from({ length: 20 }, (_, i) => `line ${i}\n`).join(""), "utf8"));
|
|
83
|
+
assert.equal(decide(readCall(ws.on, file), ws.tmp), null);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("a binary file by a NUL byte passes even with an unlisted extension", (t) => {
|
|
87
|
+
const ws = workspace(t);
|
|
88
|
+
const file = path.join(ws.on, "data.bin");
|
|
89
|
+
const body = Array.from({ length: 20 }, (_, i) => `line ${i}\n`).join("");
|
|
90
|
+
writeFileSync(file, Buffer.concat([Buffer.from(body, "utf8"), Buffer.from([0])]));
|
|
91
|
+
assert.equal(decide(readCall(ws.on, file), ws.tmp), null);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("a checkout with no swarm.explore section sees no change", (t) => {
|
|
95
|
+
const ws = workspace(t);
|
|
96
|
+
const file = longFile(ws.plain);
|
|
97
|
+
assert.equal(decide(readCall(ws.plain, file), ws.tmp), null);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("a bad key reports the error as context instead of refusing", (t) => {
|
|
101
|
+
const ws = workspace(t, { maxReadLines: "many" });
|
|
102
|
+
const file = longFile(ws.on);
|
|
103
|
+
const result = decide(readCall(ws.on, file), ws.tmp);
|
|
104
|
+
assert.match(result.hookSpecificOutput.additionalContext, /swarm\.explore\.maxReadLines/);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("a refusal leaves one marker file named by the sha256 of the absolute path, nothing else", (t) => {
|
|
108
|
+
const ws = workspace(t);
|
|
109
|
+
const file = longFile(ws.on);
|
|
110
|
+
assert.notEqual(decide(readCall(ws.on, file), ws.tmp), null);
|
|
111
|
+
const dir = slotDirOf("session-aaaa", ws.tmp);
|
|
112
|
+
assert.deepEqual(readdirSync(dir), [markerNameOf(file)]);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test("two refusals of different files each leave their own marker; consuming one leaves the other", (t) => {
|
|
116
|
+
const ws = workspace(t);
|
|
117
|
+
const fileA = longFile(ws.on, "a.txt");
|
|
118
|
+
const fileB = longFile(ws.on, "b.txt");
|
|
119
|
+
assert.notEqual(decide(readCall(ws.on, fileA), ws.tmp), null);
|
|
120
|
+
assert.notEqual(decide(readCall(ws.on, fileB), ws.tmp), null);
|
|
121
|
+
const dir = slotDirOf("session-aaaa", ws.tmp);
|
|
122
|
+
assert.deepEqual(new Set(readdirSync(dir)), new Set([markerNameOf(fileA), markerNameOf(fileB)]));
|
|
123
|
+
|
|
124
|
+
assert.equal(decide(readCall(ws.on, fileA), ws.tmp), null);
|
|
125
|
+
assert.deepEqual(readdirSync(dir), [markerNameOf(fileB)]);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("the session state folder holds only marker files, never a shared list file", (t) => {
|
|
129
|
+
const ws = workspace(t);
|
|
130
|
+
const fileA = longFile(ws.on, "a.txt");
|
|
131
|
+
const fileB = longFile(ws.on, "b.txt");
|
|
132
|
+
decide(readCall(ws.on, fileA), ws.tmp);
|
|
133
|
+
decide(readCall(ws.on, fileB), ws.tmp);
|
|
134
|
+
const dir = slotDirOf("session-aaaa", ws.tmp);
|
|
135
|
+
for (const name of readdirSync(dir)) assert.match(name, /^[0-9a-f]{64}\.refused$/);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("a third whole read after a consumed marker is refused again", (t) => {
|
|
139
|
+
const ws = workspace(t);
|
|
140
|
+
const file = longFile(ws.on);
|
|
141
|
+
assert.notEqual(decide(readCall(ws.on, file), ws.tmp), null); // first: refused, marker recorded
|
|
142
|
+
assert.equal(decide(readCall(ws.on, file), ws.tmp), null); // second: passes, marker consumed
|
|
143
|
+
const dir = slotDirOf("session-aaaa", ws.tmp);
|
|
144
|
+
assert.equal(existsSync(path.join(dir, markerNameOf(file))), false);
|
|
145
|
+
assert.notEqual(decide(readCall(ws.on, file), ws.tmp), null); // third: refused again
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test("a file outside the checkout passes with no judgment", (t) => {
|
|
149
|
+
const ws = workspace(t);
|
|
150
|
+
const outside = mkdtempSync(path.join(os.tmpdir(), "qc-outside-"));
|
|
151
|
+
t.after(() => rmSync(outside, { recursive: true, force: true }));
|
|
152
|
+
const file = longFile(outside);
|
|
153
|
+
assert.equal(decide(readCall(ws.on, file), ws.tmp), null);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test("a respelled path is refused on the first whole read, then a respelled retry consumes the marker", (t) => {
|
|
157
|
+
const ws = workspace(t);
|
|
158
|
+
const file = longFile(ws.on);
|
|
159
|
+
|
|
160
|
+
let respelled;
|
|
161
|
+
if (os.platform() === "win32") {
|
|
162
|
+
const drive = file[0];
|
|
163
|
+
respelled = (drive === drive.toUpperCase() ? drive.toLowerCase() : drive.toUpperCase()) + file.slice(1);
|
|
164
|
+
} else {
|
|
165
|
+
const link = path.join(path.dirname(ws.on), "link-to-on");
|
|
166
|
+
try {
|
|
167
|
+
symlinkSync(ws.on, link, "dir");
|
|
168
|
+
} catch (error) {
|
|
169
|
+
if (error.code === "EPERM") return t.skip("no permission to create a symlink");
|
|
170
|
+
throw error;
|
|
171
|
+
}
|
|
172
|
+
t.after(() => rmSync(link, { force: true }));
|
|
173
|
+
respelled = path.join(link, path.basename(file));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
assert.notEqual(decide(readCall(ws.on, file), ws.tmp), null); // first, as spelled: refused, marker recorded under the real path
|
|
177
|
+
assert.equal(decide(readCall(ws.on, respelled), ws.tmp), null); // retry, respelled: passes, marker consumed
|
|
178
|
+
|
|
179
|
+
const dir = slotDirOf("session-aaaa", ws.tmp);
|
|
180
|
+
assert.deepEqual(readdirSync(dir), []); // nothing left behind, real or respelled
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test("a file in a different checkout passes even though the session's own checkout turns the guard on", (t) => {
|
|
184
|
+
const ws = workspace(t);
|
|
185
|
+
const file = longFile(ws.plain);
|
|
186
|
+
assert.equal(decide(readCall(ws.on, file), ws.tmp), null);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test("a non-Read call, or a Read with no file_path, sees no change", (t) => {
|
|
190
|
+
const ws = workspace(t);
|
|
191
|
+
assert.equal(decide({ hook_event_name: "PreToolUse", tool_name: "Edit", tool_input: {} }, ws.tmp), null);
|
|
192
|
+
assert.equal(decide({ hook_event_name: "PreToolUse", tool_name: "Read", tool_input: {}, cwd: ws.on }, ws.tmp), null);
|
|
193
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The trigger for `swarm.explore`'s search and output hints: PostToolUse on Grep adds context naming
|
|
3
|
+
// the repository's own tools when the answer runs long, and PostToolUse on Bash or PowerShell adds
|
|
4
|
+
// context naming the summarizer when the output runs long. Neither refuses anything; both are a
|
|
5
|
+
// nudge the model can take or leave.
|
|
6
|
+
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { exploreSettingsAt } from "./dispatch.mjs";
|
|
9
|
+
|
|
10
|
+
const context = (text) => ({ hookSpecificOutput: { hookEventName: "PostToolUse", additionalContext: text } });
|
|
11
|
+
|
|
12
|
+
/** The tool's own answer, as plain text, from whatever shape `tool_response` carries. */
|
|
13
|
+
function textOf(response) {
|
|
14
|
+
if (typeof response === "string") return response;
|
|
15
|
+
if (response === null || response === undefined) return "";
|
|
16
|
+
if (typeof response.content === "string") return response.content;
|
|
17
|
+
if (Array.isArray(response.content)) {
|
|
18
|
+
return response.content.map((block) => (typeof block?.text === "string" ? block.text : "")).join("\n");
|
|
19
|
+
}
|
|
20
|
+
if (typeof response.stdout === "string" || typeof response.stderr === "string") {
|
|
21
|
+
return `${response.stdout ?? ""}${response.stderr ?? ""}`;
|
|
22
|
+
}
|
|
23
|
+
if (typeof response.output === "string") return response.output;
|
|
24
|
+
try {
|
|
25
|
+
return JSON.stringify(response, null, 1);
|
|
26
|
+
} catch {
|
|
27
|
+
return "";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Real newlines plus escaped `\n` sequences, the way a pretty-printed fallback hides them. */
|
|
32
|
+
function lineCountOf(text) {
|
|
33
|
+
if (text === "") return 0;
|
|
34
|
+
const realNewlines = (text.match(/\n/g) ?? []).length;
|
|
35
|
+
const escapedNewlines = (text.match(/\\n/g) ?? []).length;
|
|
36
|
+
return realNewlines + escapedNewlines + 1;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const grepHint = (tools) =>
|
|
40
|
+
`Explore hint: this Grep answer runs long. The repository's own tools may answer faster: ` +
|
|
41
|
+
`${tools.map((tool) => tool.name).join(", ")}.`;
|
|
42
|
+
|
|
43
|
+
const outputHint = (summarizer) => `Explore hint: this output runs long. Pipe it through the summarizer instead: ${summarizer}`;
|
|
44
|
+
|
|
45
|
+
/** The verdict on one finished Grep, Bash, or PowerShell call. @returns the hook output, or null for no change. */
|
|
46
|
+
export function decide(call) {
|
|
47
|
+
if (call.hook_event_name !== "PostToolUse") return null;
|
|
48
|
+
const tool = call.tool_name;
|
|
49
|
+
if (tool !== "Grep" && tool !== "Bash" && tool !== "PowerShell") return null;
|
|
50
|
+
|
|
51
|
+
let settings;
|
|
52
|
+
try {
|
|
53
|
+
settings = exploreSettingsAt(call.cwd ?? process.cwd());
|
|
54
|
+
} catch (error) {
|
|
55
|
+
// A config typo must not stop every call; the session sees the error and reports it.
|
|
56
|
+
return context(`Explore guard is off: ${error.message}`);
|
|
57
|
+
}
|
|
58
|
+
if (!settings) return null;
|
|
59
|
+
|
|
60
|
+
const text = textOf(call.tool_response);
|
|
61
|
+
if (tool === "Grep") {
|
|
62
|
+
return lineCountOf(text) > settings.maxGrepLines ? context(grepHint(settings.tools)) : null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (settings.summarizer === null) return null;
|
|
66
|
+
return text.length > settings.maxOutputChars ? context(outputHint(settings.summarizer)) : null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function readStdin() {
|
|
70
|
+
let data = "";
|
|
71
|
+
for await (const chunk of process.stdin) data += chunk;
|
|
72
|
+
return data;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const isEntryPoint = process.argv[1] !== undefined && fileURLToPath(import.meta.url) === process.argv[1];
|
|
76
|
+
if (isEntryPoint) {
|
|
77
|
+
let call = null;
|
|
78
|
+
try {
|
|
79
|
+
call = JSON.parse(await readStdin());
|
|
80
|
+
} catch {
|
|
81
|
+
// Not hook input, so there is nothing to judge.
|
|
82
|
+
}
|
|
83
|
+
const result = call ? decide(call) : null;
|
|
84
|
+
if (result) process.stdout.write(JSON.stringify(result));
|
|
85
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { strict as assert } from "node:assert";
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
|
+
import { mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { test } from "node:test";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { decide } from "./explore-hint.mjs";
|
|
9
|
+
|
|
10
|
+
const HOOKS = fileURLToPath(new URL("../../../../hooks/hooks.json", import.meta.url));
|
|
11
|
+
|
|
12
|
+
const TOOLS = [{ name: "slm-rerank", use: "find the files for a concept", how: 'slm-rerank -q "<question>" --stub -k 5' }];
|
|
13
|
+
|
|
14
|
+
/** A checkout with `swarm.explore` on, and one with no config. */
|
|
15
|
+
function workspace(t, explore = { tools: TOOLS, maxGrepLines: 5, maxOutputChars: 20, summarizer: "lfm-ask" }) {
|
|
16
|
+
const base = realpathSync.native(mkdtempSync(path.join(os.tmpdir(), "qc-explore-hint-")));
|
|
17
|
+
t.after(() => rmSync(base, { recursive: true, force: true }));
|
|
18
|
+
const on = path.join(base, "on");
|
|
19
|
+
const plain = path.join(base, "plain");
|
|
20
|
+
for (const dir of [on, plain]) {
|
|
21
|
+
mkdirSync(dir);
|
|
22
|
+
execFileSync("git", ["init", "-q"], { cwd: dir, stdio: "pipe" });
|
|
23
|
+
}
|
|
24
|
+
writeFileSync(path.join(on, "qc.config.json"), JSON.stringify({ swarm: { explore } }));
|
|
25
|
+
return { on, plain };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const call = (cwd, tool_name, tool_response) => ({
|
|
29
|
+
cwd,
|
|
30
|
+
hook_event_name: "PostToolUse",
|
|
31
|
+
tool_name,
|
|
32
|
+
tool_input: {},
|
|
33
|
+
tool_response,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const contextOf = (result) => result?.hookSpecificOutput?.additionalContext ?? null;
|
|
37
|
+
|
|
38
|
+
const lines = (n) => Array.from({ length: n }, (_, i) => `match ${i}`).join("\n");
|
|
39
|
+
|
|
40
|
+
test("a Grep answer over maxGrepLines adds context naming the tools", (t) => {
|
|
41
|
+
const ws = workspace(t);
|
|
42
|
+
const text = contextOf(decide(call(ws.on, "Grep", lines(10))));
|
|
43
|
+
assert.match(text, /slm-rerank/);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("a Grep answer at or under maxGrepLines sees no change", (t) => {
|
|
47
|
+
const ws = workspace(t);
|
|
48
|
+
assert.equal(decide(call(ws.on, "Grep", lines(3))), null);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("a command output over maxOutputChars adds context naming the summarizer", (t) => {
|
|
52
|
+
const ws = workspace(t);
|
|
53
|
+
const text = contextOf(decide(call(ws.on, "Bash", "x".repeat(30))));
|
|
54
|
+
assert.match(text, /lfm-ask/);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("PowerShell is judged the same way as Bash", (t) => {
|
|
58
|
+
const ws = workspace(t);
|
|
59
|
+
const text = contextOf(decide(call(ws.on, "PowerShell", "x".repeat(30))));
|
|
60
|
+
assert.match(text, /lfm-ask/);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("a command output at or under maxOutputChars sees no change", (t) => {
|
|
64
|
+
const ws = workspace(t);
|
|
65
|
+
assert.equal(decide(call(ws.on, "Bash", "x".repeat(10))), null);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("no summarizer configured means no output hint even over the limit", (t) => {
|
|
69
|
+
const ws = workspace(t, { tools: TOOLS, maxGrepLines: 5, maxOutputChars: 20, summarizer: null });
|
|
70
|
+
assert.equal(decide(call(ws.on, "Bash", "x".repeat(30))), null);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("a checkout with no swarm.explore section sees no change", (t) => {
|
|
74
|
+
const ws = workspace(t);
|
|
75
|
+
assert.equal(decide(call(ws.plain, "Grep", lines(10))), null);
|
|
76
|
+
assert.equal(decide(call(ws.plain, "Bash", "x".repeat(30))), null);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test("a non-Grep, non-Bash, non-PowerShell tool, or a non-PostToolUse call, sees no change", (t) => {
|
|
80
|
+
const ws = workspace(t);
|
|
81
|
+
assert.equal(decide(call(ws.on, "Read", "x".repeat(30))), null);
|
|
82
|
+
assert.equal(decide({ ...call(ws.on, "Grep", lines(10)), hook_event_name: "PreToolUse" }), null);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("a bad key reports the error as context instead of a hint", (t) => {
|
|
86
|
+
const ws = workspace(t, { maxGrepLines: "many" });
|
|
87
|
+
const text = contextOf(decide(call(ws.on, "Grep", lines(10))));
|
|
88
|
+
assert.match(text, /swarm\.explore\.maxGrepLines/);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("a Grep { content } shaped answer over maxGrepLines adds context naming the tools", (t) => {
|
|
92
|
+
const ws = workspace(t);
|
|
93
|
+
const text = contextOf(decide(call(ws.on, "Grep", { content: lines(10) })));
|
|
94
|
+
assert.match(text, /slm-rerank/);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("a Grep { matches } shaped answer over maxGrepLines adds context naming the tools", (t) => {
|
|
98
|
+
const ws = workspace(t);
|
|
99
|
+
const matches = Array.from({ length: 10 }, (_, i) => `match ${i}`);
|
|
100
|
+
const text = contextOf(decide(call(ws.on, "Grep", { matches })));
|
|
101
|
+
assert.match(text, /slm-rerank/);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("a Grep answer of unknown shape counts real newlines and escaped \\n sequences", (t) => {
|
|
105
|
+
const ws = workspace(t);
|
|
106
|
+
const text = contextOf(decide(call(ws.on, "Grep", { blob: lines(10) })));
|
|
107
|
+
assert.match(text, /slm-rerank/);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("a Bash { stdout, stderr } shaped answer over maxOutputChars adds context naming the summarizer", (t) => {
|
|
111
|
+
const ws = workspace(t);
|
|
112
|
+
const text = contextOf(decide(call(ws.on, "Bash", { stdout: "x".repeat(15), stderr: "y".repeat(15) })));
|
|
113
|
+
assert.match(text, /lfm-ask/);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("a Bash answer of unknown shape over maxOutputChars adds context naming the summarizer", (t) => {
|
|
117
|
+
const ws = workspace(t);
|
|
118
|
+
const text = contextOf(decide(call(ws.on, "Bash", { info: "x".repeat(30) })));
|
|
119
|
+
assert.match(text, /lfm-ask/);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("a null tool_response sees no change", (t) => {
|
|
123
|
+
const ws = workspace(t);
|
|
124
|
+
assert.equal(decide(call(ws.on, "Grep", null)), null);
|
|
125
|
+
assert.equal(decide(call(ws.on, "Bash", null)), null);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("hooks.json runs the hint on PostToolUse Grep and Bash|PowerShell", () => {
|
|
129
|
+
const { hooks } = JSON.parse(readFileSync(HOOKS, "utf8"));
|
|
130
|
+
const matchers = (hooks.PostToolUse ?? [])
|
|
131
|
+
.filter((entry) => entry.hooks.some((hook) => hook.command.includes("explore-hint.mjs")))
|
|
132
|
+
.map((entry) => entry.matcher);
|
|
133
|
+
assert.deepEqual(matchers.sort(), ["Bash|PowerShell", "Grep"]);
|
|
134
|
+
});
|
|
@@ -4,14 +4,17 @@ import path from "node:path";
|
|
|
4
4
|
import { test } from "node:test";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { dispatchDefaults } from "../config.mjs";
|
|
7
|
+
import { familyOf } from "./dispatch.mjs";
|
|
7
8
|
import { REMINDER } from "./dispatch-reminder.mjs";
|
|
8
9
|
|
|
9
10
|
const AGENTS = fileURLToPath(new URL("../../../../agents/", import.meta.url));
|
|
10
11
|
const PLUGIN = "architecture";
|
|
12
|
+
const READ_ONLY_TOOLS = ["Agent", "Write", "Edit", "MultiEdit", "NotebookEdit"];
|
|
11
13
|
const EXPECTED = {
|
|
12
|
-
"sdd-implementer": { effort: "
|
|
13
|
-
"sdd-planner": { effort: "high", disallowedTools: ["Agent"] },
|
|
14
|
-
"sdd-reviewer": {
|
|
14
|
+
"sdd-implementer": { model: "sonnet", effort: "high", disallowedTools: ["Agent"] },
|
|
15
|
+
"sdd-planner": { model: "opus", effort: "high", disallowedTools: ["Agent"] },
|
|
16
|
+
"sdd-reviewer": { model: "sonnet", effort: "high", disallowedTools: READ_ONLY_TOOLS },
|
|
17
|
+
"sdd-branch-reviewer": { model: "opus", effort: "high", disallowedTools: READ_ONLY_TOOLS },
|
|
15
18
|
};
|
|
16
19
|
|
|
17
20
|
/** The `key: value` lines between the two `---` fences. A checkout on Windows can carry CRLF. */
|
|
@@ -26,7 +29,7 @@ function frontmatterOf(file) {
|
|
|
26
29
|
);
|
|
27
30
|
}
|
|
28
31
|
|
|
29
|
-
test("each subagent type runs on
|
|
32
|
+
test("each subagent type runs on its model tier at its effort, and none can dispatch a subagent", () => {
|
|
30
33
|
assert.deepEqual(
|
|
31
34
|
readdirSync(AGENTS).sort(),
|
|
32
35
|
Object.keys(EXPECTED).map((name) => `${name}.md`).sort(),
|
|
@@ -35,10 +38,13 @@ test("each subagent type runs on opus at its effort, and none can dispatch a sub
|
|
|
35
38
|
for (const [name, want] of Object.entries(EXPECTED)) {
|
|
36
39
|
const front = frontmatterOf(path.join(AGENTS, `${name}.md`));
|
|
37
40
|
assert.equal(front.name, name);
|
|
38
|
-
assert.equal(front.model,
|
|
41
|
+
assert.equal(front.model, want.model, name);
|
|
39
42
|
assert.equal(front.effort, want.effort, name);
|
|
40
43
|
assert.ok(front.description.length > 0, name);
|
|
41
44
|
assert.deepEqual(front.disallowedTools.split(",").map((tool) => tool.trim()), want.disallowedTools, name);
|
|
45
|
+
const family = familyOf(front.model);
|
|
46
|
+
assert.ok(dispatchDefaults.models[name]?.includes(family), name);
|
|
47
|
+
assert.ok(dispatchDefaults.models[`${PLUGIN}:${name}`]?.includes(family), name);
|
|
42
48
|
}
|
|
43
49
|
});
|
|
44
50
|
|
package/src/config.mjs
CHANGED
|
@@ -414,14 +414,16 @@ export const defaults = {
|
|
|
414
414
|
|
|
415
415
|
// What each key of `swarm.dispatch` means when a repository omits it. A list replaces its default.
|
|
416
416
|
export const dispatchDefaults = {
|
|
417
|
-
// Types that may omit `model`: the plugin's
|
|
417
|
+
// Types that may omit `model`: the plugin's four, and the bare names of a user-level copy.
|
|
418
418
|
allowedTypes: [
|
|
419
419
|
"sdd-implementer",
|
|
420
420
|
"sdd-planner",
|
|
421
421
|
"sdd-reviewer",
|
|
422
|
+
"sdd-branch-reviewer",
|
|
422
423
|
"architecture:sdd-implementer",
|
|
423
424
|
"architecture:sdd-planner",
|
|
424
425
|
"architecture:sdd-reviewer",
|
|
426
|
+
"architecture:sdd-branch-reviewer",
|
|
425
427
|
],
|
|
426
428
|
// Types that share one slot per session.
|
|
427
429
|
implementerTypes: ["sdd-implementer", "architecture:sdd-implementer"],
|
|
@@ -429,6 +431,33 @@ export const dispatchDefaults = {
|
|
|
429
431
|
maxPromptChars: 12000,
|
|
430
432
|
// A slot with no stop expires after this many minutes.
|
|
431
433
|
slotMinutes: 60,
|
|
434
|
+
// The model families each type's named `model` may carry. `"*"` covers every other type.
|
|
435
|
+
models: {
|
|
436
|
+
"sdd-planner": ["opus"],
|
|
437
|
+
"architecture:sdd-planner": ["opus"],
|
|
438
|
+
"sdd-branch-reviewer": ["opus"],
|
|
439
|
+
"architecture:sdd-branch-reviewer": ["opus"],
|
|
440
|
+
"sdd-implementer": ["sonnet"],
|
|
441
|
+
"architecture:sdd-implementer": ["sonnet"],
|
|
442
|
+
"sdd-reviewer": ["sonnet"],
|
|
443
|
+
"architecture:sdd-reviewer": ["sonnet"],
|
|
444
|
+
"*": ["sonnet", "haiku"],
|
|
445
|
+
},
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
// The model families the guard knows. A model string's family is the first of these it
|
|
449
|
+
// contains, lower-cased, so a new release under an existing family needs no kit change.
|
|
450
|
+
export const MODEL_FAMILIES = ["opus", "sonnet", "haiku", "fable"];
|
|
451
|
+
|
|
452
|
+
// What each key of `swarm.explore` means when a repository omits it. The kit names no tool; a
|
|
453
|
+
// repository lists its own index, call graph or summarizer in `tools` and `summarizer`.
|
|
454
|
+
export const exploreDefaults = {
|
|
455
|
+
tools: [],
|
|
456
|
+
summarizer: null,
|
|
457
|
+
maxReadLines: 300,
|
|
458
|
+
maxGrepLines: 80,
|
|
459
|
+
maxOutputChars: 20000,
|
|
460
|
+
exempt: [],
|
|
432
461
|
};
|
|
433
462
|
|
|
434
463
|
function isPlainObject(value) {
|