@christang/keel 5.90.2 → 5.92.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/README.md +42 -0
- package/README.zh-CN.md +38 -0
- package/assets/bootstrap/AGENTS.md +1 -1
- package/bin/keel.js +5 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/plugins/keel/.claude-plugin/plugin.json +1 -1
- package/plugins/keel/.codex-plugin/plugin.json +1 -1
- package/scripts/install_to_repo.py +52 -2
- package/scripts/validate_plugin.py +463 -2
- package/src/core/agents.js +590 -0
- package/src/core/config.js +78 -0
|
@@ -0,0 +1,590 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// External model CLIs as delegates (#219).
|
|
4
|
+
//
|
|
5
|
+
// Keel describes an external agent and compiles the brief it is handed; it never
|
|
6
|
+
// launches one. The session's own shell runs the command, which keeps Keel the
|
|
7
|
+
// tool that starts no process and sends nothing, as everywhere else in it.
|
|
8
|
+
//
|
|
9
|
+
// The catalog records facts a reader can check — the command template, the
|
|
10
|
+
// sandbox offered per mode, where data goes, and pitfalls each stamped with a
|
|
11
|
+
// date and a source. It carries no field saying what an agent is good at: a
|
|
12
|
+
// judgement resident in the session steers the agent that reads it, and goes
|
|
13
|
+
// stale with the next model version (owner, 2026-10-04). Which work suits an
|
|
14
|
+
// external agent is the project's to write, the way lenses are.
|
|
15
|
+
|
|
16
|
+
const childProcess = require("child_process");
|
|
17
|
+
const fs = require("fs");
|
|
18
|
+
const os = require("os");
|
|
19
|
+
const path = require("path");
|
|
20
|
+
|
|
21
|
+
const { readExternalAgents } = require("./config");
|
|
22
|
+
|
|
23
|
+
const FIELDS = ["executable", "command", "sandbox", "sendsTo", "pitfalls"];
|
|
24
|
+
const MODES = ["helper", "implementation"];
|
|
25
|
+
|
|
26
|
+
const RTL_TOOLCHAIN = "rtl_ppa_prj docs/toolchain.md (main 632ad85)";
|
|
27
|
+
|
|
28
|
+
const BUNDLED = {
|
|
29
|
+
codex: {
|
|
30
|
+
executable: "codex",
|
|
31
|
+
command: "{executable} exec -s {sandbox} -C {dir} -o {out} - < {prompt}",
|
|
32
|
+
sandbox: { helper: "read-only", implementation: "workspace-write" },
|
|
33
|
+
sendsTo: "OpenAI, under the account codex is signed in with",
|
|
34
|
+
pitfalls: [
|
|
35
|
+
{
|
|
36
|
+
date: "2026-10-04",
|
|
37
|
+
source: RTL_TOOLCHAIN,
|
|
38
|
+
text: "Given a prompt argument and no stdin, it waits on stdin forever. Pass the prompt on stdin with `-`, or redirect `< /dev/null`.",
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
date: "2026-10-01",
|
|
42
|
+
source: RTL_TOOLCHAIN,
|
|
43
|
+
text: "`codex exec resume` against a Codex Desktop thread breaks on version, write lock, and session format. Start a fresh `codex exec` and put the context in the prompt file.",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
date: "2026-10-04",
|
|
47
|
+
source: RTL_TOOLCHAIN,
|
|
48
|
+
text: "It has a usage quota. When the quota is hit it names the time it can retry.",
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
date: "2026-10-02",
|
|
52
|
+
source: "https://github.com/TanglmChris/keel/issues/194",
|
|
53
|
+
text: "A recurring check that asks the model to poll for messages burned the whole quota. Never have it poll with the model.",
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
date: "2026-10-04",
|
|
57
|
+
source: "codex exec --help, codex-cli 0.159.3",
|
|
58
|
+
text: "`-s` takes read-only, workspace-write, or danger-full-access. `-C` sets the directory it works in and `-o` the file its last message is written to.",
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
dsh: {
|
|
63
|
+
executable: "/Applications/DeepSeek Harness.app/Contents/Resources/runtime/cli/bin/dsh",
|
|
64
|
+
command: "cd {dir} && {executable} --profile headless - < {prompt} > {out}",
|
|
65
|
+
sandbox: { helper: null, implementation: null },
|
|
66
|
+
sendsTo: "DeepSeek, through the provider the profile configures (by default deepseek-official, model deepseek-flash)",
|
|
67
|
+
pitfalls: [
|
|
68
|
+
{
|
|
69
|
+
date: "2026-10-04",
|
|
70
|
+
source: "dsh --version, 0.2.0-rc.2",
|
|
71
|
+
text: "The CLI lives inside the app bundle and is not on PATH.",
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
date: "2026-10-04",
|
|
75
|
+
source: "dsh headless --help, 0.2.0-rc.2",
|
|
76
|
+
text: "It offers no sandbox flag and no working-directory flag. It reads and writes wherever it is started, so start it in a separate worktree.",
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
date: "2026-10-04",
|
|
80
|
+
source: "dsh headless --help, 0.2.0-rc.2",
|
|
81
|
+
text: "`--json` writes newline-delimited run events instead of the final message, and `--session-id <id>` adopts an existing session.",
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// Pitfalls of handing work to any external process, whichever CLI it is.
|
|
88
|
+
const GENERAL_PITFALLS = [
|
|
89
|
+
{
|
|
90
|
+
date: "2026-10-04",
|
|
91
|
+
source: RTL_TOOLCHAIN,
|
|
92
|
+
text: "Never share a branch or worktree with it. A delegate committed on the branch another session had checked out, staled that session's index, and nearly overwrote its commits.",
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
date: "2026-10-04",
|
|
96
|
+
source: RTL_TOOLCHAIN,
|
|
97
|
+
text: "Its shell does not inherit your environment script. Write the PATH it needs into the brief.",
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
date: "2026-10-04",
|
|
101
|
+
source: "https://github.com/TanglmChris/rtl_ppa_prj/issues/104",
|
|
102
|
+
text: "Bound the run and name its product. A verification handed over to run on its own for ten hours spent most of it packaging and uploading about 1.9 GB of evidence.",
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
date: "2026-10-04",
|
|
106
|
+
source: RTL_TOOLCHAIN,
|
|
107
|
+
text: "macOS has no `timeout`. Run it in the background and watch it yourself.",
|
|
108
|
+
},
|
|
109
|
+
];
|
|
110
|
+
|
|
111
|
+
function keelHome() {
|
|
112
|
+
return process.env.KEEL_HOME || path.join(os.homedir(), ".keel");
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function machineFile() {
|
|
116
|
+
return path.join(keelHome(), "agents.json");
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function clone(value) {
|
|
120
|
+
return JSON.parse(JSON.stringify(value));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// The machine file adds entries and overrides fields. A field it declares
|
|
124
|
+
// outside the fact fields is reported and dropped, so the file cannot carry the
|
|
125
|
+
// judgement the bundle leaves out. A file Keel cannot parse contributes nothing:
|
|
126
|
+
// half of a file is a catalog nobody wrote.
|
|
127
|
+
function readMachineEntries(problems) {
|
|
128
|
+
const file = machineFile();
|
|
129
|
+
if (!fs.existsSync(file)) return {};
|
|
130
|
+
let parsed;
|
|
131
|
+
try {
|
|
132
|
+
parsed = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
133
|
+
} catch (error) {
|
|
134
|
+
problems.push(`${file} is not valid JSON (${error.message}); none of its entries are used.`);
|
|
135
|
+
return {};
|
|
136
|
+
}
|
|
137
|
+
const agents = parsed && typeof parsed === "object" ? parsed.agents : null;
|
|
138
|
+
if (!agents || typeof agents !== "object" || Array.isArray(agents)) {
|
|
139
|
+
problems.push(`${file} has no "agents" object; none of its entries are used.`);
|
|
140
|
+
return {};
|
|
141
|
+
}
|
|
142
|
+
return agents;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function loadCatalog() {
|
|
146
|
+
const problems = [];
|
|
147
|
+
const entries = {};
|
|
148
|
+
for (const [name, entry] of Object.entries(BUNDLED)) {
|
|
149
|
+
entries[name] = { name, source: "bundled", ...clone(entry) };
|
|
150
|
+
}
|
|
151
|
+
for (const [name, declared] of Object.entries(readMachineEntries(problems))) {
|
|
152
|
+
if (!declared || typeof declared !== "object" || Array.isArray(declared)) {
|
|
153
|
+
problems.push(`agents.json entry ${name} is not an object; it is not used.`);
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
const unknown = Object.keys(declared).filter((key) => !FIELDS.includes(key));
|
|
157
|
+
if (unknown.length > 0) {
|
|
158
|
+
problems.push(
|
|
159
|
+
`agents.json entry ${name} declares ${unknown.join(", ")}, outside the fact fields `
|
|
160
|
+
+ `(${FIELDS.join(", ")}); ${unknown.length === 1 ? "it was" : "they were"} dropped.`
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
const base = entries[name] || { name, sandbox: { helper: null, implementation: null }, pitfalls: [] };
|
|
164
|
+
const merged = { ...base, source: "machine" };
|
|
165
|
+
for (const key of FIELDS) {
|
|
166
|
+
if (key in declared) merged[key] = clone(declared[key]);
|
|
167
|
+
}
|
|
168
|
+
if (!merged.executable || !merged.command) {
|
|
169
|
+
problems.push(`agents.json entry ${name} names no executable or no command; it is not used.`);
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
merged.sandbox = { helper: null, implementation: null, ...(merged.sandbox || {}) };
|
|
173
|
+
merged.pitfalls = Array.isArray(merged.pitfalls) ? merged.pitfalls : [];
|
|
174
|
+
entries[name] = merged;
|
|
175
|
+
}
|
|
176
|
+
return { entries, problems };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function isExecutable(file) {
|
|
180
|
+
try {
|
|
181
|
+
fs.accessSync(file, fs.constants.X_OK);
|
|
182
|
+
return fs.statSync(file).isFile();
|
|
183
|
+
} catch {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// An absolute path resolves when it exists; a bare name is looked up on PATH.
|
|
189
|
+
function resolveExecutable(executable) {
|
|
190
|
+
if (path.isAbsolute(executable)) return isExecutable(executable) ? executable : null;
|
|
191
|
+
for (const dir of (process.env.PATH || "").split(path.delimiter)) {
|
|
192
|
+
if (!dir) continue;
|
|
193
|
+
const candidate = path.join(dir, executable);
|
|
194
|
+
if (isExecutable(candidate)) return candidate;
|
|
195
|
+
}
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function describeAgents(repo) {
|
|
200
|
+
const { entries, problems } = loadCatalog();
|
|
201
|
+
const declaration = readExternalAgents(repo);
|
|
202
|
+
problems.push(...declaration.problems);
|
|
203
|
+
const agents = Object.values(entries)
|
|
204
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
205
|
+
.map((entry) => ({
|
|
206
|
+
name: entry.name,
|
|
207
|
+
source: entry.source,
|
|
208
|
+
executable: entry.executable,
|
|
209
|
+
resolved: resolveExecutable(entry.executable),
|
|
210
|
+
allowed: declaration.allow.includes(entry.name),
|
|
211
|
+
command: entry.command,
|
|
212
|
+
sandbox: entry.sandbox,
|
|
213
|
+
sendsTo: entry.sendsTo || null,
|
|
214
|
+
pitfalls: entry.pitfalls,
|
|
215
|
+
}));
|
|
216
|
+
return {
|
|
217
|
+
schemaVersion: 1,
|
|
218
|
+
command: "agents",
|
|
219
|
+
agents,
|
|
220
|
+
pitfalls: GENERAL_PITFALLS,
|
|
221
|
+
declaration: {
|
|
222
|
+
declared: declaration.declared,
|
|
223
|
+
allow: declaration.allow,
|
|
224
|
+
egressDeny: declaration.egressDeny,
|
|
225
|
+
},
|
|
226
|
+
problems,
|
|
227
|
+
note: "Keel launches no agent. It lists the catalog and compiles the brief; the session runs the command.",
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function sandboxLine(sandbox) {
|
|
232
|
+
return MODES.map((mode) => `${mode} ${sandbox[mode] || "none (needs a separate worktree)"}`).join("; ");
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function pitfallLines(pitfalls) {
|
|
236
|
+
return pitfalls.map((item) => `- ${item.date} (${item.source}): ${item.text}`);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function renderListing(payload) {
|
|
240
|
+
const lines = ["External agents (read on demand; Keel launches none):"];
|
|
241
|
+
for (const agent of payload.agents) {
|
|
242
|
+
lines.push(
|
|
243
|
+
`- ${agent.name} [${agent.source}] ${agent.resolved || "not found"} — `
|
|
244
|
+
+ (agent.allowed ? "allowed here" : "not allowed here")
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
if (!payload.declaration.declared) {
|
|
248
|
+
lines.push("This project declares no external_agents: block, so it allows none.");
|
|
249
|
+
}
|
|
250
|
+
lines.push("", "General pitfalls:", ...pitfallLines(payload.pitfalls));
|
|
251
|
+
for (const problem of payload.problems) lines.push(`Problem: ${problem}`);
|
|
252
|
+
lines.push("", "Show one: keel agents <name>");
|
|
253
|
+
return `${lines.join("\n")}\n`;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function renderAgent(payload, agent) {
|
|
257
|
+
const lines = [
|
|
258
|
+
`${agent.name} [${agent.source}]`,
|
|
259
|
+
`Executable: ${agent.executable} → ${agent.resolved || "not found"}`,
|
|
260
|
+
`Command: ${agent.command}`,
|
|
261
|
+
`Sandbox: ${sandboxLine(agent.sandbox)}`,
|
|
262
|
+
`Sends to: ${agent.sendsTo || "not recorded"}`,
|
|
263
|
+
`Allowed here: ${agent.allowed ? "yes" : "no"}`,
|
|
264
|
+
"",
|
|
265
|
+
"Pitfalls:",
|
|
266
|
+
...pitfallLines(agent.pitfalls),
|
|
267
|
+
"",
|
|
268
|
+
"General pitfalls:",
|
|
269
|
+
...pitfallLines(payload.pitfalls),
|
|
270
|
+
];
|
|
271
|
+
for (const problem of payload.problems) lines.push(`Problem: ${problem}`);
|
|
272
|
+
return `${lines.join("\n")}\n`;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// --- the brief -------------------------------------------------------------------
|
|
276
|
+
|
|
277
|
+
// A glob over repo-relative paths: `**` crosses directories, `*` and `?` do not.
|
|
278
|
+
// A pattern ending in `/` names everything under that directory.
|
|
279
|
+
function globToRegExp(pattern) {
|
|
280
|
+
const source = pattern.endsWith("/") ? `${pattern}**` : pattern;
|
|
281
|
+
let out = "";
|
|
282
|
+
for (let index = 0; index < source.length; index += 1) {
|
|
283
|
+
const char = source[index];
|
|
284
|
+
if (char === "*" && source[index + 1] === "*") {
|
|
285
|
+
out += ".*";
|
|
286
|
+
index += 1;
|
|
287
|
+
if (source[index + 1] === "/") index += 1;
|
|
288
|
+
} else if (char === "*") out += "[^/]*";
|
|
289
|
+
else if (char === "?") out += "[^/]";
|
|
290
|
+
else out += char.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
291
|
+
}
|
|
292
|
+
return new RegExp(`^${out}$`);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function egressHits(paths, egressDeny) {
|
|
296
|
+
const hits = [];
|
|
297
|
+
for (const raw of paths) {
|
|
298
|
+
const candidate = String(raw).replace(/^\.\//, "");
|
|
299
|
+
if (!candidate || candidate === "none") continue;
|
|
300
|
+
for (const entry of egressDeny) {
|
|
301
|
+
if (globToRegExp(entry.pattern).test(candidate)) hits.push({ path: candidate, ...entry });
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return hits;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function git(dir, ...args) {
|
|
308
|
+
const result = childProcess.spawnSync("git", ["-C", dir, ...args], { encoding: "utf8" });
|
|
309
|
+
return result.status === 0 ? result.stdout.trim() : null;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function realpath(file) {
|
|
313
|
+
try {
|
|
314
|
+
return fs.realpathSync(file);
|
|
315
|
+
} catch {
|
|
316
|
+
return path.resolve(file);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// A separate worktree of the same repository: a different top level, the same
|
|
321
|
+
// git common directory. The host's write guard is a hook on the host's own tool
|
|
322
|
+
// calls, so a process the session launches writes past it; the checkout it runs
|
|
323
|
+
// in is then the only write boundary there is.
|
|
324
|
+
function worktreeRefusal(repo, dir) {
|
|
325
|
+
const top = git(dir, "rev-parse", "--show-toplevel");
|
|
326
|
+
const common = git(dir, "rev-parse", "--path-format=absolute", "--git-common-dir");
|
|
327
|
+
const ownTop = git(repo, "rev-parse", "--show-toplevel");
|
|
328
|
+
const ownCommon = git(repo, "rev-parse", "--path-format=absolute", "--git-common-dir");
|
|
329
|
+
const how = "Create one with `git worktree add <path>` and pass it as --dir.";
|
|
330
|
+
if (!top || !common || !ownTop || !ownCommon) {
|
|
331
|
+
return `--dir ${dir} is not a git worktree of this repository. ${how}`;
|
|
332
|
+
}
|
|
333
|
+
if (realpath(common) !== realpath(ownCommon)) {
|
|
334
|
+
return `--dir ${dir} belongs to a different repository. ${how}`;
|
|
335
|
+
}
|
|
336
|
+
if (realpath(top) === realpath(ownTop)) {
|
|
337
|
+
return (
|
|
338
|
+
`--dir ${dir} is this session's own checkout. The write guard does not reach an external `
|
|
339
|
+
+ `process, so it needs a separate worktree of this repository. ${how}`
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
return null;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function shellQuote(value) {
|
|
346
|
+
const text = String(value);
|
|
347
|
+
return /^[A-Za-z0-9_./:=@%+-]+$/.test(text) ? text : `'${text.replace(/'/g, "'\\''")}'`;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function fillCommand(template, values) {
|
|
351
|
+
return template.replace(/\{(executable|sandbox|dir|prompt|out)\}/g, (_, key) => shellQuote(values[key]));
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const BRIEF_PROHIBITIONS = [
|
|
355
|
+
"Do not commit, push, merge, rebase, or switch branches.",
|
|
356
|
+
"Do not open, close, label, or comment on issues or pull requests.",
|
|
357
|
+
"Do not edit OpenSpec or Keel state: nothing under openspec/ or keel/, and no AGENTS.md or CLAUDE.md.",
|
|
358
|
+
"Do not update a task's checkbox, Contract, Evidence, or Review.",
|
|
359
|
+
];
|
|
360
|
+
|
|
361
|
+
function renderBrief({ agent, mode, dir, projection, source, result }) {
|
|
362
|
+
const list = (items) => (items.length ? items.map((item) => `- ${item}`) : ["- none"]);
|
|
363
|
+
const lines = [
|
|
364
|
+
`# Brief for ${agent.name}: ${source.change}#${source.task}`,
|
|
365
|
+
"",
|
|
366
|
+
`Mode: ${mode}${agent.sandbox[mode] ? ` (sandbox ${agent.sandbox[mode]})` : ""}`,
|
|
367
|
+
`Working directory: ${dir}`,
|
|
368
|
+
`Write your final report to: ${result}`,
|
|
369
|
+
"",
|
|
370
|
+
"## Task",
|
|
371
|
+
"",
|
|
372
|
+
projection.objective,
|
|
373
|
+
"",
|
|
374
|
+
"## Acceptance",
|
|
375
|
+
"",
|
|
376
|
+
...list(projection.acceptance || []),
|
|
377
|
+
"",
|
|
378
|
+
"## Read",
|
|
379
|
+
"",
|
|
380
|
+
...list(projection.read || []),
|
|
381
|
+
"",
|
|
382
|
+
];
|
|
383
|
+
if (mode === "implementation") {
|
|
384
|
+
lines.push("## Touch: change only these files", "", ...list(projection.touch || []), "");
|
|
385
|
+
} else {
|
|
386
|
+
lines.push("## Writes", "", "- Write nothing in the repository. Report only.", "");
|
|
387
|
+
}
|
|
388
|
+
lines.push(
|
|
389
|
+
"## Verification checks",
|
|
390
|
+
"",
|
|
391
|
+
...list(projection.evidenceContract || []),
|
|
392
|
+
"",
|
|
393
|
+
"## Prohibitions",
|
|
394
|
+
"",
|
|
395
|
+
...list([
|
|
396
|
+
...BRIEF_PROHIBITIONS,
|
|
397
|
+
`Stay inside ${dir}; read and write nothing outside it.`,
|
|
398
|
+
...(mode === "helper" ? ["Write no file in the repository."] : []),
|
|
399
|
+
...(projection.prohibitions || []),
|
|
400
|
+
]),
|
|
401
|
+
"",
|
|
402
|
+
"## Return",
|
|
403
|
+
"",
|
|
404
|
+
"Report what you changed and the output of each verification check you ran. Your report is "
|
|
405
|
+
+ "a claim: the calling session re-runs every check before anything counts as evidence.",
|
|
406
|
+
"",
|
|
407
|
+
`Contract: ${projection.fingerprint?.schema || "keel-task-capsule/v1"} ${projection.fingerprint?.value || ""}`.trim(),
|
|
408
|
+
""
|
|
409
|
+
);
|
|
410
|
+
return lines.join("\n");
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
function compileBrief(repo, options) {
|
|
414
|
+
const blocked = (reasons, warnings = []) => ({
|
|
415
|
+
schemaVersion: 1, command: "agents brief", status: "blocked",
|
|
416
|
+
agent: options.name, mode: options.mode, reasons, warnings,
|
|
417
|
+
});
|
|
418
|
+
const declaration = readExternalAgents(repo);
|
|
419
|
+
if (declaration.unreadable.length > 0) {
|
|
420
|
+
return blocked([
|
|
421
|
+
...declaration.problems,
|
|
422
|
+
"Every brief is refused until keel/config.yaml external_agents: reads cleanly.",
|
|
423
|
+
]);
|
|
424
|
+
}
|
|
425
|
+
const example = "external_agents:\n allow:\n - codex\n egress_deny:\n - secrets/**: <reason>";
|
|
426
|
+
if (!declaration.declared) {
|
|
427
|
+
return blocked([
|
|
428
|
+
"This project declares no external_agents: block, so it allows no external agent. "
|
|
429
|
+
+ `Declare the agents it allows in keel/config.yaml:\n${example}`,
|
|
430
|
+
]);
|
|
431
|
+
}
|
|
432
|
+
const { entries } = loadCatalog();
|
|
433
|
+
const entry = entries[options.name];
|
|
434
|
+
if (!declaration.allow.includes(options.name)) {
|
|
435
|
+
return blocked([
|
|
436
|
+
`external_agents: allow: does not name ${options.name}; allowed: `
|
|
437
|
+
+ `${declaration.allow.join(", ") || "none"}.`,
|
|
438
|
+
]);
|
|
439
|
+
}
|
|
440
|
+
if (!entry) {
|
|
441
|
+
return blocked([
|
|
442
|
+
`No catalog entry named ${options.name}; known: ${Object.keys(entries).join(", ")}. `
|
|
443
|
+
+ "Add one to agents.json under the Keel home directory.",
|
|
444
|
+
]);
|
|
445
|
+
}
|
|
446
|
+
// The brief is the delegation brief: every refusal the projection applies,
|
|
447
|
+
// including the matching guard for implementation, applies here unchanged.
|
|
448
|
+
const { projectRuntime } = require("./projection");
|
|
449
|
+
const projected = projectRuntime(repo, {
|
|
450
|
+
projectionEvent: "subagent-start",
|
|
451
|
+
target: "claude",
|
|
452
|
+
subagentMode: options.mode,
|
|
453
|
+
change: options.change,
|
|
454
|
+
task: options.task,
|
|
455
|
+
authorizations: [],
|
|
456
|
+
});
|
|
457
|
+
if (projected.status !== "ready") return blocked(projected.reasons, projected.warnings);
|
|
458
|
+
const projection = projected.projection;
|
|
459
|
+
const hits = egressHits([...(projection.read || []), ...(projection.touch || [])],
|
|
460
|
+
declaration.egressDeny);
|
|
461
|
+
if (hits.length > 0) {
|
|
462
|
+
return blocked(hits.map((hit) =>
|
|
463
|
+
`${hit.path} matches egress_deny ${hit.pattern} (${hit.reason}); it must not be handed to ${entry.name}.`));
|
|
464
|
+
}
|
|
465
|
+
const dir = path.resolve(options.dir);
|
|
466
|
+
const needsWorktree = options.mode === "implementation" || !entry.sandbox.helper;
|
|
467
|
+
if (needsWorktree) {
|
|
468
|
+
const refusal = worktreeRefusal(repo, dir);
|
|
469
|
+
if (refusal) {
|
|
470
|
+
const why = options.mode === "implementation" ? ""
|
|
471
|
+
: `${entry.name} offers no read-only sandbox, so even a helper run needs a separate worktree. `;
|
|
472
|
+
return blocked([why + refusal]);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
const out = path.resolve(options.out);
|
|
476
|
+
const result = out.replace(/(\.md)?$/, ".result.md");
|
|
477
|
+
fs.mkdirSync(path.dirname(out), { recursive: true });
|
|
478
|
+
fs.writeFileSync(out, renderBrief({
|
|
479
|
+
agent: entry, mode: options.mode, dir, projection, source: projected.source, result,
|
|
480
|
+
}));
|
|
481
|
+
const run = fillCommand(entry.command, {
|
|
482
|
+
executable: resolveExecutable(entry.executable) || entry.executable,
|
|
483
|
+
sandbox: entry.sandbox[options.mode] || "",
|
|
484
|
+
dir,
|
|
485
|
+
prompt: out,
|
|
486
|
+
out: result,
|
|
487
|
+
});
|
|
488
|
+
return {
|
|
489
|
+
schemaVersion: 1,
|
|
490
|
+
command: "agents brief",
|
|
491
|
+
status: "ready",
|
|
492
|
+
agent: entry.name,
|
|
493
|
+
mode: options.mode,
|
|
494
|
+
prompt: out,
|
|
495
|
+
result,
|
|
496
|
+
run,
|
|
497
|
+
source: projected.source,
|
|
498
|
+
reasons: [],
|
|
499
|
+
warnings: [
|
|
500
|
+
...projected.warnings,
|
|
501
|
+
"Keel cannot observe what the agent reads beyond the brief; egress_deny guards what is handed over, not what it can open.",
|
|
502
|
+
"Keel launched nothing. Run the command yourself, then re-run every check before recording Evidence.",
|
|
503
|
+
],
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
function runBrief(argv) {
|
|
508
|
+
const options = { name: null, mode: null, dir: null, out: null, change: null, task: null };
|
|
509
|
+
let json = false;
|
|
510
|
+
let repo = process.cwd();
|
|
511
|
+
const flags = { "--mode": "mode", "--dir": "dir", "--out": "out", "--change": "change", "--task": "task" };
|
|
512
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
513
|
+
const arg = argv[index];
|
|
514
|
+
if (arg === "--json") json = true;
|
|
515
|
+
else if (arg === "--repo") repo = argv[++index] || "";
|
|
516
|
+
else if (flags[arg]) options[flags[arg]] = argv[++index] || "";
|
|
517
|
+
else if (options.name === null && !arg.startsWith("-")) options.name = arg;
|
|
518
|
+
else {
|
|
519
|
+
process.stderr.write(`keel agents brief: unexpected argument ${arg}\n${BRIEF_USAGE}\n`);
|
|
520
|
+
return 2;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
if (!options.name || !MODES.includes(options.mode) || !options.dir || !options.out) {
|
|
524
|
+
process.stderr.write(`${BRIEF_USAGE}\n`);
|
|
525
|
+
return 2;
|
|
526
|
+
}
|
|
527
|
+
const payload = compileBrief(path.resolve(repo), options);
|
|
528
|
+
if (json) process.stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
|
|
529
|
+
else if (payload.status === "ready") {
|
|
530
|
+
process.stdout.write(
|
|
531
|
+
`Brief: ${payload.prompt}\nRun: ${payload.run}\n`
|
|
532
|
+
+ payload.warnings.map((item) => `Warning: ${item}\n`).join("")
|
|
533
|
+
);
|
|
534
|
+
} else {
|
|
535
|
+
process.stdout.write(
|
|
536
|
+
`Brief: blocked\n${payload.reasons.map((item) => `Reason: ${item}\n`).join("")}`
|
|
537
|
+
);
|
|
538
|
+
}
|
|
539
|
+
return payload.status === "ready" ? 0 : 3;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
const BRIEF_USAGE = "usage: keel agents brief <name> --mode helper|implementation --dir <path> --out <file> "
|
|
543
|
+
+ "[--change name] [--task id] [--repo path] [--json]";
|
|
544
|
+
|
|
545
|
+
const USAGE = "usage: keel agents [name] [--repo path] [--json]\n keel agents brief <name> --mode helper|implementation --dir <path> --out <file>";
|
|
546
|
+
|
|
547
|
+
function runAgents(argv) {
|
|
548
|
+
let json = false;
|
|
549
|
+
let repo = process.cwd();
|
|
550
|
+
let name = null;
|
|
551
|
+
if (argv[0] === "brief") return runBrief(argv.slice(1));
|
|
552
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
553
|
+
const arg = argv[index];
|
|
554
|
+
if (arg === "--json") json = true;
|
|
555
|
+
else if (arg === "--repo") repo = argv[++index] || "";
|
|
556
|
+
else if (arg === "--help" || arg === "-h") {
|
|
557
|
+
process.stdout.write(`${USAGE}\n`);
|
|
558
|
+
return 0;
|
|
559
|
+
} else if (name === null && !arg.startsWith("-")) name = arg;
|
|
560
|
+
else {
|
|
561
|
+
process.stderr.write(`keel agents: unexpected argument ${arg}\n${USAGE}\n`);
|
|
562
|
+
return 2;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
const payload = describeAgents(path.resolve(repo));
|
|
566
|
+
if (name !== null) {
|
|
567
|
+
const agent = payload.agents.find((item) => item.name === name);
|
|
568
|
+
if (!agent) {
|
|
569
|
+
process.stderr.write(
|
|
570
|
+
`keel agents: no agent named ${name}; known: ${payload.agents.map((item) => item.name).join(", ")}\n`
|
|
571
|
+
);
|
|
572
|
+
return 1;
|
|
573
|
+
}
|
|
574
|
+
process.stdout.write(json ? `${JSON.stringify({ ...payload, agents: [agent] }, null, 2)}\n`
|
|
575
|
+
: renderAgent(payload, agent));
|
|
576
|
+
return 0;
|
|
577
|
+
}
|
|
578
|
+
process.stdout.write(json ? `${JSON.stringify(payload, null, 2)}\n` : renderListing(payload));
|
|
579
|
+
return 0;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
module.exports = {
|
|
583
|
+
BUNDLED,
|
|
584
|
+
compileBrief,
|
|
585
|
+
GENERAL_PITFALLS,
|
|
586
|
+
describeAgents,
|
|
587
|
+
loadCatalog,
|
|
588
|
+
resolveExecutable,
|
|
589
|
+
runAgents,
|
|
590
|
+
};
|
package/src/core/config.js
CHANGED
|
@@ -97,6 +97,7 @@ const CONFIG_DECLARATIONS = [
|
|
|
97
97
|
"full_mode_paths",
|
|
98
98
|
"executor_tier",
|
|
99
99
|
"merge",
|
|
100
|
+
"external_agents",
|
|
100
101
|
];
|
|
101
102
|
|
|
102
103
|
const CONFIG_RELATIVE_PATH = path.join("keel", "config.yaml");
|
|
@@ -434,6 +435,82 @@ function readDelegationPolicy(repo) {
|
|
|
434
435
|
return { declared: true, tier, unknown: [], accepted };
|
|
435
436
|
}
|
|
436
437
|
|
|
438
|
+
// `external_agents:` — which external model CLIs this project allows, and the
|
|
439
|
+
// paths that must not be handed to one (#219). Absent allows nothing: every
|
|
440
|
+
// other declaration here authorizes nothing when absent, and sending the
|
|
441
|
+
// repository to another provider is the decision a project makes once,
|
|
442
|
+
// explicitly. The block is two sub-keys, so it is read with configBlockLines
|
|
443
|
+
// and classified here rather than loosening the flat readers.
|
|
444
|
+
//
|
|
445
|
+
// An `egress_deny` entry carries its reason, the same shape as
|
|
446
|
+
// `full_mode_paths`. An entry Keel cannot read is reported by name and the
|
|
447
|
+
// caller refuses every brief until it is corrected: a deny list that silently
|
|
448
|
+
// dropped an entry would send exactly what it was written to keep.
|
|
449
|
+
const EXTERNAL_AGENT_KEYS = ["allow", "egress_deny"];
|
|
450
|
+
|
|
451
|
+
function readExternalAgents(repo) {
|
|
452
|
+
const result = { declared: false, allow: [], egressDeny: [], problems: [], unreadable: [] };
|
|
453
|
+
const block = configBlockLines(repo, "external_agents");
|
|
454
|
+
if (block === null) return result;
|
|
455
|
+
result.declared = true;
|
|
456
|
+
if (block.inline !== null) {
|
|
457
|
+
result.problems.push(
|
|
458
|
+
`keel/config.yaml declares external_agents: inline (${block.inline}); write allow: and egress_deny: on their own lines.`
|
|
459
|
+
);
|
|
460
|
+
result.unreadable.push(block.inline);
|
|
461
|
+
return result;
|
|
462
|
+
}
|
|
463
|
+
let key = null;
|
|
464
|
+
for (const line of block.lines) {
|
|
465
|
+
const sub = line.match(/^ {1,3}(\w+)\s*:\s*(.*?)\s*$/);
|
|
466
|
+
if (sub) {
|
|
467
|
+
key = sub[1];
|
|
468
|
+
if (!EXTERNAL_AGENT_KEYS.includes(key)) {
|
|
469
|
+
result.problems.push(
|
|
470
|
+
`keel/config.yaml external_agents: declares ${key}, which Keel does not read; accepted: ${EXTERNAL_AGENT_KEYS.join(", ")}.`
|
|
471
|
+
);
|
|
472
|
+
result.unreadable.push(key);
|
|
473
|
+
key = null;
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
// `allow: [codex, dsh]` is the one flow form read, because a one-line
|
|
477
|
+
// allowance is the common declaration.
|
|
478
|
+
const flow = sub[2].match(/^\[(.*)\]$/);
|
|
479
|
+
if (key === "allow" && flow) {
|
|
480
|
+
result.allow.push(...flow[1].split(",").map((item) => item.trim()).filter(Boolean));
|
|
481
|
+
} else if (sub[2] !== "") {
|
|
482
|
+
result.problems.push(`keel/config.yaml external_agents: ${key}: holds ${sub[2]}; write its entries as a list.`);
|
|
483
|
+
result.unreadable.push(`${key}: ${sub[2]}`);
|
|
484
|
+
}
|
|
485
|
+
continue;
|
|
486
|
+
}
|
|
487
|
+
const item = line.match(/^\s+-\s*(.*?)\s*$/);
|
|
488
|
+
if (!item || key === null) {
|
|
489
|
+
result.problems.push(`keel/config.yaml external_agents: line Keel could not read: ${line.trim()}`);
|
|
490
|
+
result.unreadable.push(line.trim());
|
|
491
|
+
continue;
|
|
492
|
+
}
|
|
493
|
+
if (key === "allow") {
|
|
494
|
+
if (/^[A-Za-z0-9._-]+$/.test(item[1])) result.allow.push(item[1]);
|
|
495
|
+
else {
|
|
496
|
+
result.problems.push(`keel/config.yaml external_agents: allow entry ${item[1]} is not an agent name.`);
|
|
497
|
+
result.unreadable.push(item[1]);
|
|
498
|
+
}
|
|
499
|
+
continue;
|
|
500
|
+
}
|
|
501
|
+
const entry = item[1].match(/^(\S+?)\s*:\s+(\S.*)$/);
|
|
502
|
+
if (!entry) {
|
|
503
|
+
result.problems.push(
|
|
504
|
+
`keel/config.yaml external_agents: egress_deny entry ${item[1]} has no reason; write it as \`- <glob>: <reason>\`. Every brief is refused until it is corrected, because a deny list that dropped an entry would send what it was written to keep.`
|
|
505
|
+
);
|
|
506
|
+
result.unreadable.push(item[1]);
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
result.egressDeny.push({ pattern: entry[1], reason: entry[2] });
|
|
510
|
+
}
|
|
511
|
+
return result;
|
|
512
|
+
}
|
|
513
|
+
|
|
437
514
|
// Which guidance an executor loads, declared by the repository rather than
|
|
438
515
|
// judged by the executor. #135's argument is that "do I need this help?" is the
|
|
439
516
|
// judgement a weak executor gets most wrong, so the skip is written down; the
|
|
@@ -664,6 +741,7 @@ function triageIssue(repo, labels, issue = null) {
|
|
|
664
741
|
}
|
|
665
742
|
|
|
666
743
|
module.exports = {
|
|
744
|
+
readExternalAgents,
|
|
667
745
|
CONFIG_RELATIVE_PATH,
|
|
668
746
|
DELEGATION_TIERS,
|
|
669
747
|
EXECUTOR_TIERS,
|