@christang/keel 5.91.0 → 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/validate_plugin.py +375 -2
- package/src/core/agents.js +590 -0
- package/src/core/config.js +78 -0
package/README.md
CHANGED
|
@@ -646,6 +646,44 @@ This changes only what Keel *recommends*. No gate, the write guard, and completi
|
|
|
646
646
|
exactly as they would without it, and `keel context --change <paused>` still selects it — you asked
|
|
647
647
|
for it by name. Keel never pauses a change on its own.
|
|
648
648
|
|
|
649
|
+
## External model CLIs
|
|
650
|
+
|
|
651
|
+
A session can hand work to an external model CLI — codex, DeepSeek Harness's `dsh`, or one you
|
|
652
|
+
register — as a delegate. Whether to call one is the model's choice; Keel's part is the interface,
|
|
653
|
+
the gates, and the pitfalls others already hit. A host's own subagents are not involved: the model
|
|
654
|
+
knows those better.
|
|
655
|
+
|
|
656
|
+
```bash
|
|
657
|
+
keel agents # the catalog: where each executable resolves, and whether this project allows it
|
|
658
|
+
keel agents codex # its template, sandboxes, where it sends data, dated pitfalls
|
|
659
|
+
keel agents brief codex --mode helper --dir . --out /tmp/brief.md --change <c> --task <t>
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
`keel agents brief` compiles the same brief `keel project --event subagent-start` publishes, writes
|
|
663
|
+
it to a file, and prints the command to run. **Keel launches nothing**; the session runs it, and
|
|
664
|
+
re-runs every check before anything counts as evidence. It refuses:
|
|
665
|
+
|
|
666
|
+
- an agent the project has not allowed — with no declaration, none is;
|
|
667
|
+
- a Read or Touch path the project said must not leave;
|
|
668
|
+
- a write-capable run in the session's own checkout. The host's write guard never sees an external
|
|
669
|
+
process, so implementation (and a helper whose CLI has no read-only sandbox, like `dsh`) needs a
|
|
670
|
+
separate `git worktree add`.
|
|
671
|
+
|
|
672
|
+
```yaml
|
|
673
|
+
external_agents:
|
|
674
|
+
allow:
|
|
675
|
+
- codex
|
|
676
|
+
egress_deny:
|
|
677
|
+
- secrets/**: vendor keys under NDA
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
The catalog records facts only — template, sandboxes, destination, and pitfalls each with a date and
|
|
681
|
+
a source — and never what an agent is good at, because a judgement sitting in the session steers it
|
|
682
|
+
and goes stale with the next model. Which work suits an external agent is yours to write. Tool paths
|
|
683
|
+
are machine facts: `~/.keel/agents.json` adds an agent or overrides a field, such as
|
|
684
|
+
`{"agents": {"dsh": {"executable": "/path/to/dsh"}}}`. Keel cannot see what an agent reads beyond
|
|
685
|
+
the brief, so `egress_deny` guards what is handed over, not what it can open.
|
|
686
|
+
|
|
649
687
|
## Group chat between sessions
|
|
650
688
|
|
|
651
689
|
Sessions working the same repository — a Claude Code session, a Codex session, an unattended runner, and you — share a work group with `keel chat`. Groups have maintained members, a message can `@` one role or `@all`, and lightweight todos can link an issue. Each member has its own unread state, and history is kept. Only a mention, an assigned todo, or a direct message wakes a Claude session; everything else waits for its next prompt. A message is data from another agent and never authorization. Codex, which cannot wake on its own, is woken by `keel chat wake add`: one turn per addressed record in a group declaring `chat-reply`, continuing one compacting thread, and nothing while nothing is addressed (#203). Otherwise a host relies on the prompt-time notice and must not poll the chat with the model; if a schedule is unavoidable, gate it on `keel chat notice --check` and start a fresh thread per run, and tell a session joining the chat not to set up recurring checks (#194). With one Slack app and one bridge process per machine, the same groups reach sessions on other machines and your phone in real time, and an orphan `keel-chat` branch keeps the history past Slack's retention: see [the Slack setup guide](docs/chat-slack-setup.md). The 5.83 `keel mail` commands keep working on direct groups.
|
|
@@ -684,6 +722,10 @@ keel chat archive sync | pull
|
|
|
684
722
|
# Keel never fetches the issue; pass what gh returned. At least one of the two.
|
|
685
723
|
keel triage [--labels <l1,l2>] [--issue <n>] [--json]
|
|
686
724
|
|
|
725
|
+
# External model CLIs — catalog, and the brief Keel compiles (it launches nothing)
|
|
726
|
+
keel agents [name] [--json]
|
|
727
|
+
keel agents brief <name> --mode helper|implementation --dir <path> --out <file>
|
|
728
|
+
|
|
687
729
|
# Install / maintenance
|
|
688
730
|
keel --init | --install | --check | --doctor | --uninstall [--target <t>] [--dry-run]
|
|
689
731
|
keel --update [--dry-run]
|
package/README.zh-CN.md
CHANGED
|
@@ -185,6 +185,40 @@ keel --uninstall # 当 core.hooksPath 由 Keel 设置时回退
|
|
|
185
185
|
|
|
186
186
|
`--with-git-hooks` 是显式 opt-in:普通 `keel --install` 绝不碰 git config,且这个覆盖仅限本仓、可逆。
|
|
187
187
|
|
|
188
|
+
## 外部模型 CLI
|
|
189
|
+
|
|
190
|
+
会话可以把活交给外部模型 CLI 当委派对象,比如 codex、DeepSeek Harness 的 `dsh`,或你自己注册的。
|
|
191
|
+
调不调由模型自己判断;Keel 只提供调用接口、门控,以及大家踩过的坑。宿主自带的 subagent 不归 Keel 管,
|
|
192
|
+
模型自己更懂。
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
keel agents # 事实目录:可执行文件在哪、本项目是否允许
|
|
196
|
+
keel agents codex # 命令模板、沙箱、数据发往哪里、带日期的坑
|
|
197
|
+
keel agents brief codex --mode helper --dir . --out /tmp/brief.md --change <c> --task <t>
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
`keel agents brief` 编译的就是 `keel project --event subagent-start` 给出的那份任务说明,写成文件,
|
|
201
|
+
再打印要跑的命令。**Keel 不启动任何进程**:命令由会话自己跑,对方交回的结果要由会话复跑每个检查后才算证据。
|
|
202
|
+
以下情况会被拒绝:
|
|
203
|
+
|
|
204
|
+
- 项目没允许的 agent(没写声明就一个都不允许);
|
|
205
|
+
- 任务要读或要改的路径命中了禁止外发的清单;
|
|
206
|
+
- 在会话自己的 checkout 里做会写入的调用。宿主的写入守卫看不到外部进程,所以实现类任务,以及没有只读
|
|
207
|
+
沙箱的 CLI(如 `dsh`)即使只做评审,都要用 `git worktree add` 建的独立 worktree。
|
|
208
|
+
|
|
209
|
+
```yaml
|
|
210
|
+
external_agents:
|
|
211
|
+
allow:
|
|
212
|
+
- codex
|
|
213
|
+
egress_deny:
|
|
214
|
+
- secrets/**: 受 NDA 约束的厂商密钥
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
事实目录只记事实:命令模板、沙箱、数据去向,以及每条都带日期和出处的坑;不写「擅长什么」,因为这种评价
|
|
218
|
+
常驻在会话里会左右主 agent 的判断,换个模型版本就过时。哪些活适合交出去由你自己写。工具路径属于本机事实:
|
|
219
|
+
`~/.keel/agents.json` 可以新增 agent 或覆盖某个字段,比如 `{"agents": {"dsh": {"executable": "/path/to/dsh"}}}`。
|
|
220
|
+
Keel 看不到对方在任务说明之外还读了什么,所以 `egress_deny` 防的是主动交出去的内容,管不住对方自己能打开的文件。
|
|
221
|
+
|
|
188
222
|
## 会话之间的群聊
|
|
189
223
|
|
|
190
224
|
在同一个仓库里干活的各个会话——Claude Code、Codex、无人值守的执行器,还有你——用 `keel chat` 组成一个工作群:
|
|
@@ -228,6 +262,10 @@ keel chat unread | read | notice | search <文本>
|
|
|
228
262
|
keel chat bridge add | install | status | pause <2h> | stop | start | uninstall
|
|
229
263
|
keel chat archive sync | pull
|
|
230
264
|
|
|
265
|
+
# 外部模型 CLI —— 事实目录,以及 Keel 编译的任务说明(Keel 不启动进程)
|
|
266
|
+
keel agents [name] [--json]
|
|
267
|
+
keel agents brief <name> --mode helper|implementation --dir <path> --out <file>
|
|
268
|
+
|
|
231
269
|
# 安装 / 维护
|
|
232
270
|
keel --init | --install | --check | --doctor | --uninstall [--target <t>] [--dry-run]
|
|
233
271
|
keel --update [--dry-run]
|
package/bin/keel.js
CHANGED
|
@@ -105,6 +105,7 @@ Usage:
|
|
|
105
105
|
keel chat role|group|post|dm|unread|read|show|<group> ... [--repo path] (group chat between sessions; see keel chat help)
|
|
106
106
|
keel mail role|send|list|read|hook [repo] ... (cross-host mailbox; see keel mail help)
|
|
107
107
|
keel triage [repo] [--labels <l1,l2>] [--issue <n>] [--json]
|
|
108
|
+
keel agents [name] [--repo path] [--json] (external model CLIs, read on demand; Keel launches none)
|
|
108
109
|
keel openspec [args...]
|
|
109
110
|
keel --init [repo] [--target claude|codex|opencode] [--dry-run] [--force-template-update]
|
|
110
111
|
keel --install [repo] [--target claude|codex|opencode] [--dry-run] [--force-template-update] [--with-git-hooks]
|
|
@@ -2848,6 +2849,10 @@ function main() {
|
|
|
2848
2849
|
if (process.argv[2] === "chat") {
|
|
2849
2850
|
return require("../src/core/chat/cli").runChat(process.argv.slice(3));
|
|
2850
2851
|
}
|
|
2852
|
+
// `keel agents` likewise: the external model CLI catalog (#219).
|
|
2853
|
+
if (process.argv[2] === "agents") {
|
|
2854
|
+
return require("../src/core/agents").runAgents(process.argv.slice(3));
|
|
2855
|
+
}
|
|
2851
2856
|
const options = parseArgs(process.argv.slice(2));
|
|
2852
2857
|
if (options.help || (!options.action && !options.version)) {
|
|
2853
2858
|
printHelp();
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@christang/keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.92.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@christang/keel",
|
|
9
|
-
"version": "5.
|
|
9
|
+
"version": "5.92.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@fission-ai/openspec": "^1.4.1"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.92.0",
|
|
4
4
|
"description": "Keel OpenSpec execution discipline: stateless continuity, task capsules, deterministic gates, and expectation alignment for Codex and Claude Code.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "TanglmChris",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.92.0",
|
|
4
4
|
"description": "Keel OpenSpec execution discipline: stateless continuity, task capsules, deterministic gates, and expectation alignment for Codex and Claude Code.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "TanglmChris",
|
|
@@ -47,8 +47,8 @@ REQUIRED_SCRIPTS = [
|
|
|
47
47
|
"scripts/validate_plugin.py",
|
|
48
48
|
]
|
|
49
49
|
|
|
50
|
-
PACKAGE_VERSION = "5.
|
|
51
|
-
PROTOCOL_VERSION = "5.
|
|
50
|
+
PACKAGE_VERSION = "5.92.0"
|
|
51
|
+
PROTOCOL_VERSION = "5.92.0"
|
|
52
52
|
LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
|
|
53
53
|
OPENSPEC_SCHEMA_NAME = "keel-spec-driven"
|
|
54
54
|
# Mirrors KEEL_PACKAGE_NAME in scripts/install_to_repo.py, one of the two
|
|
@@ -35250,6 +35250,376 @@ def validate_codex_receiving_scenario() -> int:
|
|
|
35250
35250
|
return result.returncode
|
|
35251
35251
|
|
|
35252
35252
|
|
|
35253
|
+
EXTERNAL_AGENT_FACT_FIELDS = {
|
|
35254
|
+
"name", "source", "executable", "resolved", "allowed",
|
|
35255
|
+
"command", "sandbox", "sendsTo", "pitfalls",
|
|
35256
|
+
}
|
|
35257
|
+
|
|
35258
|
+
|
|
35259
|
+
def _external_agents_env(base: Path) -> tuple[dict[str, str], Path]:
|
|
35260
|
+
"""An environment whose Keel home and PATH belong to the fixture.
|
|
35261
|
+
|
|
35262
|
+
The stub `codex` stands in for the real one so resolution is checked against
|
|
35263
|
+
a path the scenario controls; it records any invocation, because a catalog
|
|
35264
|
+
or a brief that launched the agent would be the one thing Keel promised not
|
|
35265
|
+
to do.
|
|
35266
|
+
"""
|
|
35267
|
+
home = base / "home"
|
|
35268
|
+
home.mkdir()
|
|
35269
|
+
stub_bin = base / "bin"
|
|
35270
|
+
stub_bin.mkdir()
|
|
35271
|
+
calls = base / "calls.log"
|
|
35272
|
+
for name in ("codex", "dsh"):
|
|
35273
|
+
stub = stub_bin / name
|
|
35274
|
+
stub.write_text(f"#!/bin/sh\necho {name} \"$@\" >> '{calls}'\n", encoding="utf-8")
|
|
35275
|
+
stub.chmod(0o755)
|
|
35276
|
+
env = dict(os.environ)
|
|
35277
|
+
env["KEEL_HOME"] = str(home)
|
|
35278
|
+
env["PATH"] = f"{stub_bin}{os.pathsep}{env.get('PATH', '')}"
|
|
35279
|
+
return env, calls
|
|
35280
|
+
|
|
35281
|
+
|
|
35282
|
+
def validate_external_agent_catalog_scenario() -> int:
|
|
35283
|
+
"""The catalog records facts, merges the machine file, and stays on demand.
|
|
35284
|
+
|
|
35285
|
+
#219: an external model CLI writes outside the host's write guard and sends
|
|
35286
|
+
the repository to another provider. What Keel offers about one is facts a
|
|
35287
|
+
reader can check — template, sandboxes, destination, dated pitfalls — and
|
|
35288
|
+
never a judgement of what it is good at, because a judgement resident in the
|
|
35289
|
+
session steers the agent that reads it (owner, 2026-10-04).
|
|
35290
|
+
"""
|
|
35291
|
+
label = "external-agent-catalog:"
|
|
35292
|
+
with tempfile.TemporaryDirectory(prefix="keel-agents-") as raw:
|
|
35293
|
+
base = Path(raw)
|
|
35294
|
+
env, calls = _external_agents_env(base)
|
|
35295
|
+
repo = base / "repo"
|
|
35296
|
+
repo.mkdir()
|
|
35297
|
+
write_gate_fixture(repo, standing_authorization_task())
|
|
35298
|
+
write_authorize_config(repo, "external_agents:\n allow:\n - codex\n")
|
|
35299
|
+
|
|
35300
|
+
def listing() -> dict | None:
|
|
35301
|
+
result = run_keel(repo, "agents", "--json", env=env)
|
|
35302
|
+
try:
|
|
35303
|
+
return json.loads(result.stdout)
|
|
35304
|
+
except json.JSONDecodeError:
|
|
35305
|
+
report(f"{label} `keel agents --json` printed no JSON: "
|
|
35306
|
+
f"{(result.stdout + result.stderr).strip()[:400]}")
|
|
35307
|
+
return None
|
|
35308
|
+
|
|
35309
|
+
payload = listing()
|
|
35310
|
+
if payload is None:
|
|
35311
|
+
return 1
|
|
35312
|
+
agents = {item.get("name"): item for item in payload.get("agents") or []}
|
|
35313
|
+
for name in ("codex", "dsh"):
|
|
35314
|
+
if agents.get(name, {}).get("source") != "bundled":
|
|
35315
|
+
report(f"{label} {name} is not listed as a bundled entry: {agents.get(name)}")
|
|
35316
|
+
return 1
|
|
35317
|
+
stub = str(base / "bin" / "codex")
|
|
35318
|
+
if agents["codex"].get("resolved") != stub:
|
|
35319
|
+
report(f"{label} codex resolved to {agents['codex'].get('resolved')!r}, not the stub on PATH.")
|
|
35320
|
+
return 1
|
|
35321
|
+
dsh_path = agents["dsh"].get("executable")
|
|
35322
|
+
expected = dsh_path if dsh_path and Path(dsh_path).exists() else None
|
|
35323
|
+
if agents["dsh"].get("resolved") != expected:
|
|
35324
|
+
report(f"{label} dsh resolution {agents['dsh'].get('resolved')!r} disagrees with "
|
|
35325
|
+
f"whether {dsh_path!r} exists.")
|
|
35326
|
+
return 1
|
|
35327
|
+
if agents["codex"].get("allowed") is not True or agents["dsh"].get("allowed") is not False:
|
|
35328
|
+
report(f"{label} allowance is not read from external_agents: allow: "
|
|
35329
|
+
f"codex={agents['codex'].get('allowed')!r} dsh={agents['dsh'].get('allowed')!r}")
|
|
35330
|
+
return 1
|
|
35331
|
+
for name, item in agents.items():
|
|
35332
|
+
extra = set(item) - EXTERNAL_AGENT_FACT_FIELDS
|
|
35333
|
+
if extra:
|
|
35334
|
+
report(f"{label} {name} carries fields outside the fact fields: {sorted(extra)}. "
|
|
35335
|
+
"The catalog records facts, not a judgement of what an agent suits.")
|
|
35336
|
+
return 1
|
|
35337
|
+
pitfalls = item.get("pitfalls") or []
|
|
35338
|
+
if not pitfalls:
|
|
35339
|
+
report(f"{label} {name} records no pitfall.")
|
|
35340
|
+
return 1
|
|
35341
|
+
for pitfall in pitfalls:
|
|
35342
|
+
if not re.fullmatch(r"\d{4}-\d{2}-\d{2}", str(pitfall.get("date", ""))) \
|
|
35343
|
+
or not str(pitfall.get("source", "")).strip():
|
|
35344
|
+
report(f"{label} {name} has a pitfall without a date and a source: {pitfall}")
|
|
35345
|
+
return 1
|
|
35346
|
+
|
|
35347
|
+
shown = run_keel(repo, "agents", "codex", env=env)
|
|
35348
|
+
text = shown.stdout
|
|
35349
|
+
codex = agents["codex"]
|
|
35350
|
+
for needle in (codex.get("command"), "read-only", "workspace-write", codex.get("sendsTo"),
|
|
35351
|
+
*[p["text"] for p in codex["pitfalls"]],
|
|
35352
|
+
*[p["date"] for p in codex["pitfalls"]]):
|
|
35353
|
+
if not needle:
|
|
35354
|
+
report(f"{label} the codex entry has an empty command, destination, or pitfall.")
|
|
35355
|
+
return 1
|
|
35356
|
+
if needle not in text:
|
|
35357
|
+
report(f"{label} `keel agents codex` does not print {needle!r}.")
|
|
35358
|
+
return 1
|
|
35359
|
+
|
|
35360
|
+
# A machine entry declaring one field overrides that field only.
|
|
35361
|
+
custom = base / "bin" / "dsh"
|
|
35362
|
+
(base / "home" / "agents.json").write_text(
|
|
35363
|
+
json.dumps({"agents": {"dsh": {"executable": str(custom)}}}), encoding="utf-8")
|
|
35364
|
+
payload = listing()
|
|
35365
|
+
if payload is None:
|
|
35366
|
+
return 1
|
|
35367
|
+
dsh = {item.get("name"): item for item in payload.get("agents") or []}.get("dsh") or {}
|
|
35368
|
+
if dsh.get("source") != "machine" or dsh.get("executable") != str(custom):
|
|
35369
|
+
report(f"{label} the machine entry did not override dsh: {dsh}")
|
|
35370
|
+
return 1
|
|
35371
|
+
if dsh.get("command") != agents["dsh"].get("command"):
|
|
35372
|
+
report(f"{label} a machine entry declaring only an executable replaced the bundled template.")
|
|
35373
|
+
return 1
|
|
35374
|
+
|
|
35375
|
+
# A malformed machine file is named and none of it is used.
|
|
35376
|
+
(base / "home" / "agents.json").write_text("{not json", encoding="utf-8")
|
|
35377
|
+
payload = listing()
|
|
35378
|
+
if payload is None:
|
|
35379
|
+
return 1
|
|
35380
|
+
problems = " ".join(payload.get("problems") or [])
|
|
35381
|
+
if "agents.json" not in problems:
|
|
35382
|
+
report(f"{label} a malformed agents.json was not reported: {payload.get('problems')}")
|
|
35383
|
+
return 1
|
|
35384
|
+
sources = {item.get("source") for item in payload.get("agents") or []}
|
|
35385
|
+
if sources != {"bundled"}:
|
|
35386
|
+
report(f"{label} a malformed agents.json still contributed entries: {sources}")
|
|
35387
|
+
return 1
|
|
35388
|
+
|
|
35389
|
+
# Session start carries no catalog.
|
|
35390
|
+
context = run_keel(repo, "context", env=env)
|
|
35391
|
+
for needle in ("dsh", "DeepSeek", "/dev/null", "workspace-write"):
|
|
35392
|
+
if needle in context.stdout:
|
|
35393
|
+
report(f"{label} `keel context` carries catalog text {needle!r}.")
|
|
35394
|
+
return 1
|
|
35395
|
+
if calls.exists():
|
|
35396
|
+
report(f"{label} an agent was launched: {calls.read_text(encoding='utf-8').strip()}")
|
|
35397
|
+
return 1
|
|
35398
|
+
|
|
35399
|
+
report("external-agent-catalog scenario passed.")
|
|
35400
|
+
return 0
|
|
35401
|
+
|
|
35402
|
+
|
|
35403
|
+
def external_agent_brief_task() -> str:
|
|
35404
|
+
return (
|
|
35405
|
+
"- [ ] 1.1 Speed up the parser\n"
|
|
35406
|
+
" - Covers:\n"
|
|
35407
|
+
" - E1: public behavior\n"
|
|
35408
|
+
" - Read:\n"
|
|
35409
|
+
" - docs/spec.md\n"
|
|
35410
|
+
" - secrets/vendor.key\n"
|
|
35411
|
+
" - Touch:\n"
|
|
35412
|
+
" - src/feature.js\n"
|
|
35413
|
+
" - Verify:\n"
|
|
35414
|
+
" - Strategy: evidence-first\n"
|
|
35415
|
+
" - Reason: this is a gate fixture; it exercises contract structure and has no executable behavior that can fail first\n"
|
|
35416
|
+
" - M1: node test.js proves the parser is faster\n"
|
|
35417
|
+
" - Evidence:\n"
|
|
35418
|
+
" - Contract: pending\n"
|
|
35419
|
+
" - M1: pending\n"
|
|
35420
|
+
" - Review:\n"
|
|
35421
|
+
" - Status: pending\n"
|
|
35422
|
+
" - Acceptance check: pending\n"
|
|
35423
|
+
" - Scope check: pending\n"
|
|
35424
|
+
" - Findings: pending\n"
|
|
35425
|
+
" - Blocker: none\n"
|
|
35426
|
+
)
|
|
35427
|
+
|
|
35428
|
+
|
|
35429
|
+
def validate_external_agent_brief_scenario() -> int:
|
|
35430
|
+
"""The brief is the delegation brief, checked for egress and write boundary.
|
|
35431
|
+
|
|
35432
|
+
#219: Keel compiles what the external agent is handed and prints the command;
|
|
35433
|
+
the session runs it. The brief refuses what the project has not allowed, a
|
|
35434
|
+
path the project said must not leave, and any write into the session's own
|
|
35435
|
+
checkout, because the host's write guard never sees an external process.
|
|
35436
|
+
"""
|
|
35437
|
+
label = "external-agent-brief:"
|
|
35438
|
+
with tempfile.TemporaryDirectory(prefix="keel-agent-brief-") as raw:
|
|
35439
|
+
base = Path(raw)
|
|
35440
|
+
env, calls = _external_agents_env(base)
|
|
35441
|
+
repo = base / "repo"
|
|
35442
|
+
repo.mkdir()
|
|
35443
|
+
write_gate_fixture(repo, external_agent_brief_task())
|
|
35444
|
+
write_text(repo / "docs/spec.md", "spec\n")
|
|
35445
|
+
write_text(repo / "secrets/vendor.key", "key\n")
|
|
35446
|
+
write_text(repo / "src/feature.js", "// feature\n")
|
|
35447
|
+
for command in (["init", "-q"], ["add", "-A"],
|
|
35448
|
+
["-c", "user.email=k@example.com", "-c", "user.name=k",
|
|
35449
|
+
"commit", "-q", "-m", "fixture"]):
|
|
35450
|
+
subprocess.run(["git", *command], cwd=repo, check=True, capture_output=True)
|
|
35451
|
+
prompt = base / "brief.md"
|
|
35452
|
+
|
|
35453
|
+
def brief(name: str, mode: str, directory: Path) -> tuple[dict, str]:
|
|
35454
|
+
if prompt.exists():
|
|
35455
|
+
prompt.unlink()
|
|
35456
|
+
result = run_keel(repo, "agents", "brief", name, "--mode", mode,
|
|
35457
|
+
"--dir", str(directory), "--out", str(prompt),
|
|
35458
|
+
"--change", "demo", "--task", "1.1", "--json", env=env)
|
|
35459
|
+
try:
|
|
35460
|
+
return json.loads(result.stdout), result.stdout + result.stderr
|
|
35461
|
+
except json.JSONDecodeError:
|
|
35462
|
+
return {}, result.stdout + result.stderr
|
|
35463
|
+
|
|
35464
|
+
def refused(payload: dict, output: str, *needles: str, what: str) -> bool:
|
|
35465
|
+
reasons = " ".join(payload.get("reasons") or [])
|
|
35466
|
+
if payload.get("status") != "blocked":
|
|
35467
|
+
report(f"{label} {what} was not refused: {output.strip()[:400]}")
|
|
35468
|
+
return False
|
|
35469
|
+
for needle in needles:
|
|
35470
|
+
if needle not in reasons:
|
|
35471
|
+
report(f"{label} {what} was refused without naming {needle!r}: {reasons}")
|
|
35472
|
+
return False
|
|
35473
|
+
if prompt.exists():
|
|
35474
|
+
report(f"{label} {what} was refused but still wrote a prompt file.")
|
|
35475
|
+
return False
|
|
35476
|
+
return True
|
|
35477
|
+
|
|
35478
|
+
# Absent declaration allows nothing, and says how to declare.
|
|
35479
|
+
payload, out = brief("codex", "helper", repo)
|
|
35480
|
+
if not refused(payload, out, "external_agents:", "allow:", what="an undeclared project"):
|
|
35481
|
+
return 1
|
|
35482
|
+
# An agent outside allow.
|
|
35483
|
+
write_authorize_config(repo, "external_agents:\n allow:\n - codex\n")
|
|
35484
|
+
payload, out = brief("dsh", "helper", repo)
|
|
35485
|
+
if not refused(payload, out, "dsh", "codex", what="an agent outside allow"):
|
|
35486
|
+
return 1
|
|
35487
|
+
# A deny entry without a reason refuses every brief.
|
|
35488
|
+
write_authorize_config(repo, "external_agents:\n allow:\n - codex\n"
|
|
35489
|
+
" egress_deny:\n - secrets/**\n")
|
|
35490
|
+
payload, out = brief("codex", "helper", repo)
|
|
35491
|
+
if not refused(payload, out, "secrets/**", what="a deny entry without a reason"):
|
|
35492
|
+
return 1
|
|
35493
|
+
# A denied Read path refuses, naming path, pattern and reason.
|
|
35494
|
+
write_authorize_config(repo, "external_agents:\n allow: [codex, dsh]\n"
|
|
35495
|
+
" egress_deny:\n - secrets/**: vendor NDA keys\n")
|
|
35496
|
+
payload, out = brief("codex", "helper", repo)
|
|
35497
|
+
if not refused(payload, out, "secrets/vendor.key", "secrets/**", "vendor NDA keys",
|
|
35498
|
+
what="a denied Read path"):
|
|
35499
|
+
return 1
|
|
35500
|
+
# A clean helper brief.
|
|
35501
|
+
write_authorize_config(repo, "external_agents:\n allow: [codex, dsh]\n"
|
|
35502
|
+
" egress_deny:\n - private/**: customer data\n")
|
|
35503
|
+
payload, out = brief("codex", "helper", repo)
|
|
35504
|
+
if payload.get("status") != "ready":
|
|
35505
|
+
report(f"{label} a clean helper brief was refused: {out.strip()[:600]}")
|
|
35506
|
+
return 1
|
|
35507
|
+
if not prompt.exists():
|
|
35508
|
+
report(f"{label} a clean helper brief reported ready but wrote no prompt file.")
|
|
35509
|
+
return 1
|
|
35510
|
+
text = prompt.read_text(encoding="utf-8")
|
|
35511
|
+
for needle in ("Speed up the parser", "docs/spec.md", "secrets/vendor.key",
|
|
35512
|
+
"M1: node test.js", "commit", "push", "OpenSpec"):
|
|
35513
|
+
if needle not in text:
|
|
35514
|
+
report(f"{label} the prompt file does not carry {needle!r}.")
|
|
35515
|
+
return 1
|
|
35516
|
+
command = payload.get("run") or ""
|
|
35517
|
+
for needle in ("read-only", str(repo), str(prompt)):
|
|
35518
|
+
if needle not in command:
|
|
35519
|
+
report(f"{label} the printed command does not name {needle!r}: {command}")
|
|
35520
|
+
return 1
|
|
35521
|
+
if "cannot observe" not in " ".join(payload.get("warnings") or []):
|
|
35522
|
+
report(f"{label} the brief does not say Keel cannot observe what the agent reads.")
|
|
35523
|
+
return 1
|
|
35524
|
+
# A helper with no sandbox over the session's own checkout.
|
|
35525
|
+
payload, out = brief("dsh", "helper", repo)
|
|
35526
|
+
if not refused(payload, out, "sandbox", "worktree", what="a dsh helper over the checkout"):
|
|
35527
|
+
return 1
|
|
35528
|
+
# Implementation with no guard: the projection's own reason.
|
|
35529
|
+
projected = run_keel(repo, "project", "--target", "claude", "--event", "subagent-start",
|
|
35530
|
+
"--subagent-mode", "implementation", "--change", "demo",
|
|
35531
|
+
"--task", "1.1", "--json", env=env)
|
|
35532
|
+
expected = " ".join(json.loads(projected.stdout).get("reasons") or [])
|
|
35533
|
+
payload, out = brief("codex", "implementation", repo)
|
|
35534
|
+
if not expected:
|
|
35535
|
+
report(f"{label} the projection gave no reason to compare against: {projected.stdout[:400]}")
|
|
35536
|
+
return 1
|
|
35537
|
+
if not refused(payload, out, expected, what="an unguarded implementation"):
|
|
35538
|
+
return 1
|
|
35539
|
+
started = run_keel(repo, "gate", "task-start", "--change", "demo", "--task", "1.1",
|
|
35540
|
+
"--record", "--json", env=env)
|
|
35541
|
+
if json.loads(started.stdout).get("status") != "pass":
|
|
35542
|
+
report(f"{label} the fixture task did not start: {started.stdout[:400]}")
|
|
35543
|
+
return 1
|
|
35544
|
+
payload, out = brief("codex", "implementation", repo)
|
|
35545
|
+
if not refused(payload, out, "worktree", what="an implementation over the checkout"):
|
|
35546
|
+
return 1
|
|
35547
|
+
worktree = base / "agent-wt"
|
|
35548
|
+
subprocess.run(["git", "worktree", "add", "-q", "--detach", str(worktree)],
|
|
35549
|
+
cwd=repo, check=True, capture_output=True)
|
|
35550
|
+
payload, out = brief("codex", "implementation", worktree)
|
|
35551
|
+
if payload.get("status") != "ready":
|
|
35552
|
+
report(f"{label} an implementation brief over a separate worktree was refused: "
|
|
35553
|
+
f"{out.strip()[:600]}")
|
|
35554
|
+
return 1
|
|
35555
|
+
if not prompt.exists():
|
|
35556
|
+
report(f"{label} an implementation brief reported ready but wrote no prompt file.")
|
|
35557
|
+
return 1
|
|
35558
|
+
command = payload.get("run") or ""
|
|
35559
|
+
for needle in ("workspace-write", str(worktree)):
|
|
35560
|
+
if needle not in command:
|
|
35561
|
+
report(f"{label} the implementation command does not name {needle!r}: {command}")
|
|
35562
|
+
return 1
|
|
35563
|
+
if calls.exists():
|
|
35564
|
+
report(f"{label} an agent was launched: {calls.read_text(encoding='utf-8').strip()}")
|
|
35565
|
+
return 1
|
|
35566
|
+
|
|
35567
|
+
report("external-agent-brief scenario passed.")
|
|
35568
|
+
return 0
|
|
35569
|
+
|
|
35570
|
+
|
|
35571
|
+
def validate_external_agents_are_documented_scenario() -> int:
|
|
35572
|
+
"""The command reaches the protocol, the READMEs, and the privacy policy.
|
|
35573
|
+
|
|
35574
|
+
#219: an agent that never reads the README must still learn that external
|
|
35575
|
+
model CLIs are delegates with a compiled brief, so the bootstrap block and
|
|
35576
|
+
this repository's protocol name it. The privacy policy lists what leaves the
|
|
35577
|
+
machine, and handing a repository to codex or dsh is now one of those ways.
|
|
35578
|
+
"""
|
|
35579
|
+
label = "external-agents-are-documented:"
|
|
35580
|
+
|
|
35581
|
+
def flat(path: Path) -> str:
|
|
35582
|
+
return re.sub(r"\s+", " ", path.read_text(encoding="utf-8"))
|
|
35583
|
+
|
|
35584
|
+
protocol = flat(ROOT / "AGENTS.md")
|
|
35585
|
+
if "keel agents brief" not in protocol:
|
|
35586
|
+
report(f"{label} AGENTS.md does not name `keel agents brief`.")
|
|
35587
|
+
return 1
|
|
35588
|
+
if "launches nothing" not in protocol:
|
|
35589
|
+
report(f"{label} AGENTS.md does not say Keel launches nothing.")
|
|
35590
|
+
return 1
|
|
35591
|
+
# The installed bootstrap spends its byte budget only on rules every session
|
|
35592
|
+
# uses; `external_agents:` is inert until declared, as delegation is, so it
|
|
35593
|
+
# reaches an agent where it is declared instead (D9).
|
|
35594
|
+
if "keel agents" in flat(ROOT / "assets/bootstrap/AGENTS.md"):
|
|
35595
|
+
report(f"{label} the bootstrap block names `keel agents`, spending its budget on a "
|
|
35596
|
+
"declaration that is inert until a project makes it.")
|
|
35597
|
+
return 1
|
|
35598
|
+
for path in (ROOT / "README.md", ROOT / "README.zh-CN.md"):
|
|
35599
|
+
text = path.read_text(encoding="utf-8")
|
|
35600
|
+
blocks = re.findall(r"```bash\n(.*?)```", text, re.S)
|
|
35601
|
+
if not any("keel agents" in block for block in blocks):
|
|
35602
|
+
report(f"{label} {path.name} lists no `keel agents` in a command block.")
|
|
35603
|
+
return 1
|
|
35604
|
+
yaml_blocks = re.findall(r"```yaml\n(.*?)```", text, re.S)
|
|
35605
|
+
example = next((block for block in yaml_blocks if "external_agents:" in block), "")
|
|
35606
|
+
if not example:
|
|
35607
|
+
report(f"{label} {path.name} shows no `external_agents:` example.")
|
|
35608
|
+
return 1
|
|
35609
|
+
for key in ("allow:", "egress_deny:"):
|
|
35610
|
+
if key not in example:
|
|
35611
|
+
report(f"{label} {path.name}'s external_agents example has no {key}.")
|
|
35612
|
+
return 1
|
|
35613
|
+
privacy = (ROOT / "PRIVACY.md").read_text(encoding="utf-8")
|
|
35614
|
+
leaves = privacy.split("## What leaves your machine", 1)[-1].split("\n## ", 1)[0]
|
|
35615
|
+
if "External model CLIs" not in leaves:
|
|
35616
|
+
report(f"{label} PRIVACY.md does not list external model CLIs under what leaves the machine.")
|
|
35617
|
+
return 1
|
|
35618
|
+
|
|
35619
|
+
report("external-agents-are-documented scenario passed.")
|
|
35620
|
+
return 0
|
|
35621
|
+
|
|
35622
|
+
|
|
35253
35623
|
SCENARIOS: tuple = (
|
|
35254
35624
|
("stateless-continuity", validate_stateless_continuity_scenario),
|
|
35255
35625
|
("core-gates", validate_core_gates_scenario),
|
|
@@ -35694,6 +36064,9 @@ SCENARIOS: tuple = (
|
|
|
35694
36064
|
"a-task-field-cites-its-provenance",
|
|
35695
36065
|
validate_a_task_field_cites_its_provenance_scenario,
|
|
35696
36066
|
),
|
|
36067
|
+
("external-agent-catalog", validate_external_agent_catalog_scenario),
|
|
36068
|
+
("external-agent-brief", validate_external_agent_brief_scenario),
|
|
36069
|
+
("external-agents-are-documented", validate_external_agents_are_documented_scenario),
|
|
35697
36070
|
("validation-runner", validate_validation_runner_scenario),
|
|
35698
36071
|
("section-boundary", validate_section_boundary_scenario),
|
|
35699
36072
|
("review-entry-extent", validate_review_entry_extent_scenario),
|
|
@@ -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,
|