@christang/keel 5.84.0 → 5.86.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.
Files changed (37) hide show
  1. package/README.md +49 -5
  2. package/README.zh-CN.md +34 -0
  3. package/assets/bootstrap/AGENTS.md +2 -2
  4. package/assets/openspec/schemas/keel-spec-driven/schema.yaml +3 -3
  5. package/assets/openspec/schemas/keel-spec-driven/templates/tasks.md +3 -3
  6. package/bin/keel.js +60 -7
  7. package/npm-shrinkwrap.json +2 -2
  8. package/package.json +1 -1
  9. package/plugins/keel/.claude-plugin/plugin.json +1 -1
  10. package/plugins/keel/.codex-plugin/plugin.json +2 -1
  11. package/plugins/keel/agents/keel-single-task-goal-claude.md +1 -1
  12. package/plugins/keel/agents/keel-single-task-goal-codex.md +1 -1
  13. package/plugins/keel/hooks/codex.json +44 -0
  14. package/plugins/keel/scripts/codex-mail-hook.js +75 -0
  15. package/plugins/keel/scripts/mail-hook.js +11 -9
  16. package/plugins/keel/skills/keel-run-single-task-goal/SKILL.md +2 -2
  17. package/plugins/keel/skills/keel-run-single-task-goal/guidance.md +1 -1
  18. package/scripts/fake_slack.py +277 -0
  19. package/scripts/validate_codex_receiving.py +296 -0
  20. package/scripts/validate_plugin.py +1922 -227
  21. package/src/core/capabilities.js +2 -2
  22. package/src/core/chat/archive.js +234 -0
  23. package/src/core/chat/bridge.js +808 -0
  24. package/src/core/chat/cli.js +465 -0
  25. package/src/core/chat/config.js +64 -0
  26. package/src/core/chat/guards.js +96 -0
  27. package/src/core/chat/lifecycle.js +214 -0
  28. package/src/core/chat/migrate.js +142 -0
  29. package/src/core/chat/notice.js +216 -0
  30. package/src/core/chat/redact.js +37 -0
  31. package/src/core/chat/slack.js +104 -0
  32. package/src/core/chat/store.js +776 -0
  33. package/src/core/chat/view.js +169 -0
  34. package/src/core/config.js +36 -10
  35. package/src/core/mail.js +123 -433
  36. package/src/core/projection.js +43 -24
  37. package/src/core/task-contract.js +3 -3
@@ -2,13 +2,11 @@
2
2
 
3
3
  // Keel 4.1.0 one-way native projection contract.
4
4
 
5
- const fs = require("fs");
6
- const path = require("path");
7
-
8
5
  const { readDelegationPolicy } = require("./config");
9
6
  const { resolveContext } = require("./context");
10
7
  const { loadTaskContract } = require("./task-contract");
11
8
  const { probeCapabilities } = require("./capabilities");
9
+ const { guardStatus } = require("./guard");
12
10
 
13
11
  const EVENTS = new Set([
14
12
  "startup",
@@ -43,31 +41,44 @@ function blocked(target, event, reason, warnings = []) {
43
41
  // that wrote successfully under one proves nothing about having been checked —
44
42
  // there is no observable difference afterwards, which is why the condition has
45
43
  // to be answered here.
46
- function delegationRefusal(repo, delegation) {
44
+ function delegationRefusal(repo, capsule, change, taskId, fingerprint) {
47
45
  // The policy is read directly rather than through the capsule, because the
48
46
  // capsule cannot express the difference this refusal turns on. A tier outside
49
47
  // the vocabulary fails closed at the config layer and reaches the capsule as
50
48
  // no delegation at all — identical to a repository that declared nothing. One
51
49
  // of those should proceed silently and the other must be reported, so the
52
50
  // unresolved declaration has to be seen where it still exists.
53
- const { unknown, accepted } = readDelegationPolicy(repo);
51
+ const { unknown: configuredUnknown, accepted } = readDelegationPolicy(repo);
52
+ const declaredTier = capsule.delegation?.tier;
53
+ const unknown = declaredTier
54
+ ? (accepted.includes(declaredTier) ? [] : [declaredTier])
55
+ : configuredUnknown;
54
56
  if (unknown.length > 0) {
55
57
  return (
56
- `Delegation declares tier "${unknown.join(", ")}", which this target `
57
- + `does not provide. Accepted: ${accepted.join(", ")}. Keel refuses `
58
+ `Delegation declares invalid tier metadata "${unknown.join(", ")}". `
59
+ + `Accepted: ${accepted.join(", ")}. Keel refuses `
58
60
  + "rather than substituting a tier, because work would otherwise run at "
59
61
  + "a capability nobody declared while reporting success."
60
62
  );
61
63
  }
62
- if (!delegation) return null;
63
- if (!fs.existsSync(path.join(repo, "keel", "guard.json"))) {
64
+ if (capsule.mode !== "implementation" || capsule.touch.length === 0
65
+ || capsule.touch.includes("none")) {
66
+ return "Implementation delegation requires an implementation task with a Touch write boundary.";
67
+ }
68
+ const guard = guardStatus(repo);
69
+ if (guard.status !== "active") {
64
70
  return (
65
- "Delegation requires an active write guard, and keel/guard.json is "
66
- + "absent. Without it every write passes through unchecked and looks "
67
- + "identical to a write the guard allowed. Run `keel gate task-start` "
68
- + "for the selected task, then delegate."
71
+ `Delegation requires an active write guard; status is ${guard.status}. `
72
+ + guard.problems.map((item) => item.message).join(" ")
73
+ + " Run `keel gate task-start` for the selected task, then delegate."
69
74
  );
70
75
  }
76
+ const manifest = guard.manifest;
77
+ if (manifest.change !== change || manifest.task !== taskId
78
+ || manifest.fingerprint.value !== fingerprint.value
79
+ || JSON.stringify([...manifest.touch].sort()) !== JSON.stringify([...capsule.touch].sort())) {
80
+ return "Delegation requires a guard matching the selected task, fingerprint and Touch boundary.";
81
+ }
71
82
  return null;
72
83
  }
73
84
 
@@ -149,9 +160,7 @@ function projectRuntime(repo, options) {
149
160
  ? "goal"
150
161
  : event === "task-view"
151
162
  ? "task-view"
152
- : event.startsWith("subagent-")
153
- ? "subagent"
154
- : null;
163
+ : null;
155
164
  if (requiredAuthorization && !authorization.has(requiredAuthorization)) {
156
165
  return blocked(
157
166
  options.target,
@@ -163,6 +172,9 @@ function projectRuntime(repo, options) {
163
172
 
164
173
  const contract = loaded.contract;
165
174
  const capsule = contract.capsule;
175
+ const subagentMode = options.subagentMode
176
+ || (authorization.has("subagent") && (capsule.delegation || readDelegationPolicy(repo).declared)
177
+ ? "implementation" : "helper");
166
178
  const capabilities = probeCapabilities(repo, options.target);
167
179
  const capability = capabilities.capabilities[capabilityKey(event)];
168
180
  const warnings = [...context.warnings];
@@ -194,22 +206,29 @@ function projectRuntime(repo, options) {
194
206
  if (event === "subagent-stop") {
195
207
  projection.returnAuthority = "report-and-evidence-only";
196
208
  }
209
+ if (event.startsWith("subagent-")) {
210
+ projection.subagentMode = subagentMode;
211
+ projection.hostPolicy = "Host policy remains authoritative; projection does not spawn or prove enforcement.";
212
+ projection.prohibitions = [...projection.prohibitions,
213
+ "must not update task execution records or contract authority: checkbox, Contract, Evidence, Review, Covers, Touch, Verify or Acceptance"];
214
+ if (subagentMode === "helper") {
215
+ projection.prohibitions = [...projection.prohibitions, "must not write product or task record files"];
216
+ }
217
+ }
197
218
  // Delegation extends the brief Keel already publishes rather than adding a
198
219
  // carrier beside the host's own agent interface. The host spawns; this is the
199
220
  // one-way view of OpenSpec it is handed.
200
- if (event === "subagent-start") {
201
- const refusal = delegationRefusal(repo, capsule.delegation);
221
+ if (event === "subagent-start" && subagentMode === "implementation") {
222
+ const refusal = delegationRefusal(repo, capsule, change, taskId, contract.fingerprint);
202
223
  if (refusal) return blocked(options.target, event, refusal, warnings);
203
224
  }
204
- if (event === "subagent-start" && capsule.delegation) {
225
+ if (event === "subagent-start" && subagentMode === "implementation") {
205
226
  projection.delegation = {
206
- tier: capsule.delegation.tier,
207
- source: capsule.delegation.source,
227
+ tier: capsule.delegation?.tier || null,
228
+ source: capsule.delegation?.source || "selected-task-write-authority",
208
229
  writeBoundary: capsule.touch,
209
230
  note:
210
- "Keel carries the declared tier and does not select a model; the "
211
- + "target resolves it. Keel cannot observe which model executed, so "
212
- + "the tier is what is recorded and never a claim about what ran.",
231
+ "Keel carries an optional declared tier, never infers one, and does not select or observe a model. The current agent re-runs every M<n> check before recording Evidence.",
213
232
  };
214
233
  }
215
234
 
@@ -1436,7 +1436,7 @@ function compileTaskContract(repo, change, task) {
1436
1436
  if (!autonomy.some((item) => /^Pre-authorized fallback:/i.test(item))) {
1437
1437
  autonomy.push("Pre-authorized fallback: none");
1438
1438
  }
1439
- // Who runs this task, resolved exactly as the autonomy boundary above is: the
1439
+ // Optional capability metadata, resolved as the autonomy boundary above is: the
1440
1440
  // task keeps whatever it authored, the repository declaration supplies only
1441
1441
  // what the task left silent, and the entry names its source. A declaration
1442
1442
  // that could overwrite an authored tier would make the capsule unreadable on
@@ -1554,8 +1554,8 @@ function compileTaskContract(repo, change, task) {
1554
1554
  // change the compiled capsule for every task everywhere, moving every
1555
1555
  // recorded anchor and drifting every live change in every consumer repo on
1556
1556
  // upgrade — for repositories that declared nothing and asked for nothing.
1557
- // Omission keeps this release's invariant: no behavior change without a
1558
- // declaration. A repository that does declare gets a different capsule,
1557
+ // Omission preserves existing anchors without inventing a tier.
1558
+ // A repository that does declare gets a different capsule,
1559
1559
  // which is honest, because its execution genuinely differs.
1560
1560
  ...(delegation.tier ? { delegation } : {}),
1561
1561
  prohibitions: [