@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
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+
3
+ // How chat records read to a person or an agent (issue #187, design D8, D20).
4
+ // Stored times carry the writer's UTC offset; every display converts to the
5
+ // viewer's local time and never prints the raw stamp. Edits and retractions
6
+ // are records of their own: a view applies them to the message they target
7
+ // and leaves the original file untouched.
8
+
9
+ function pad(value) {
10
+ return String(value).padStart(2, "0");
11
+ }
12
+
13
+ function parseTime(created) {
14
+ const time = Date.parse(created);
15
+ return Number.isNaN(time) ? null : new Date(time);
16
+ }
17
+
18
+ // `YYYY-MM-DD HH:MM` in the viewer's local time zone.
19
+ function localStamp(created) {
20
+ const date = parseTime(created);
21
+ if (!date) return "????-??-?? ??:??";
22
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} `
23
+ + `${pad(date.getHours())}:${pad(date.getMinutes())}`;
24
+ }
25
+
26
+ function localDay(created) {
27
+ return localStamp(created).slice(0, 10);
28
+ }
29
+
30
+ function localClock(created) {
31
+ return localStamp(created).slice(11);
32
+ }
33
+
34
+ // `3h ago`, for agent notices, where the absolute time costs a reader a
35
+ // conversion it does not need.
36
+ function relativeAge(created, now = Date.now()) {
37
+ const date = parseTime(created);
38
+ if (!date) return "at an unknown time";
39
+ const seconds = Math.max(0, Math.round((now - date.getTime()) / 1000));
40
+ if (seconds < 60) return "just now";
41
+ const minutes = Math.round(seconds / 60);
42
+ if (minutes < 60) return `${minutes}m ago`;
43
+ const hours = Math.round(minutes / 60);
44
+ if (hours < 48) return `${hours}h ago`;
45
+ return `${Math.round(hours / 24)}d ago`;
46
+ }
47
+
48
+ // The records a reader sees: edits and retractions applied to their targets
49
+ // and dropped as lines of their own; a todo knows whether it was closed.
50
+ function displayRecords(records) {
51
+ const byId = new Map();
52
+ const shown = [];
53
+ for (const record of records) {
54
+ if (record.kind === "edit" || record.kind === "retract") {
55
+ const target = byId.get(record.target);
56
+ if (!target || target.from !== record.from) continue;
57
+ if (record.kind === "edit") {
58
+ target.text = record.text;
59
+ target.edited = true;
60
+ } else {
61
+ target.retracted = true;
62
+ }
63
+ continue;
64
+ }
65
+ const copy = { ...record };
66
+ if (copy.kind === "done") {
67
+ const todo = byId.get(copy.target);
68
+ if (todo) todo.done = true;
69
+ }
70
+ byId.set(copy.id, copy);
71
+ shown.push(copy);
72
+ }
73
+ return shown;
74
+ }
75
+
76
+ function markers(record) {
77
+ const parts = [];
78
+ if (record.kind === "todo") {
79
+ parts.push(`[todo → ${record.assignee || "?"}${record.issue ? ` ${record.issue}` : ""}${record.done ? ", done" : ""}]`);
80
+ }
81
+ if (record.reply_to) parts.push(`↳ ${record.reply_to}`);
82
+ // A mention the text already spells out is not repeated; one written as an
83
+ // alias (`@cb`) still shows the role it resolved to (#196).
84
+ const text = String(record.text || "").toLowerCase();
85
+ const unseen = (record.mentions || []).filter((m) => !new RegExp(`(^|[^\\w@/])@${m.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?![\\w/-])`, "i").test(text));
86
+ if (unseen.length) parts.push(unseen.map((m) => `@${m}`).join(" "));
87
+ if (record.edited) parts.push("(edited)");
88
+ return parts.length ? ` ${parts.join(" ")}` : "";
89
+ }
90
+
91
+ function describe(record) {
92
+ switch (record.kind) {
93
+ case "join":
94
+ return `${record.from} added ${record.target}`;
95
+ case "leave":
96
+ return `${record.from} removed ${record.target}`;
97
+ case "archive":
98
+ return `${record.from} archived the group`;
99
+ case "done":
100
+ return `${record.from} closed todo ${record.target}`;
101
+ default:
102
+ if (record.retracted) return `${record.from}: (retracted)`;
103
+ return `${record.from}:${markers(record)} ${record.text}`;
104
+ }
105
+ }
106
+
107
+ function formatLine(record, { clock = false } = {}) {
108
+ const when = clock ? localClock(record.created) : localStamp(record.created);
109
+ return `${when} ${describe(record)} [${record.id}]`;
110
+ }
111
+
112
+ // `--since`: a duration back from now (`90s`, `15m`, `2h`, `3d`) or a date or
113
+ // time (`2026-10-01` is local midnight). Returns epoch milliseconds or null.
114
+ function parseSince(value, now = Date.now()) {
115
+ const text = String(value || "").trim();
116
+ const duration = text.match(/^(\d+)([smhd])$/);
117
+ if (duration) {
118
+ const unit = { s: 1e3, m: 60e3, h: 3600e3, d: 86400e3 }[duration[2]];
119
+ return now - Number(duration[1]) * unit;
120
+ }
121
+ const day = text.match(/^(\d{4})-(\d\d)-(\d\d)$/);
122
+ if (day) return new Date(Number(day[1]), Number(day[2]) - 1, Number(day[3])).getTime();
123
+ const time = Date.parse(text);
124
+ return Number.isNaN(time) ? null : time;
125
+ }
126
+
127
+ function since(records, threshold) {
128
+ if (threshold === null || threshold === undefined) return records;
129
+ return records.filter((record) => {
130
+ const time = Date.parse(record.created);
131
+ return Number.isNaN(time) || time >= threshold;
132
+ });
133
+ }
134
+
135
+ // The per-group Markdown transcript a person opens in any editor (D20): one
136
+ // heading per local day, then `HH:MM sender: text` per record.
137
+ function renderTranscript(group, records) {
138
+ const shown = displayRecords(records).slice().sort((a, b) => {
139
+ const left = Date.parse(a.created);
140
+ const right = Date.parse(b.created);
141
+ return (Number.isNaN(left) ? 0 : left) - (Number.isNaN(right) ? 0 : right) || (a.id < b.id ? -1 : 1);
142
+ });
143
+ const lines = [`# ${group}`, "", "Generated by keel chat after every write; edit the group, not this file.", ""];
144
+ let day = null;
145
+ for (const record of shown) {
146
+ const recordDay = localDay(record.created);
147
+ if (recordDay !== day) {
148
+ if (day !== null) lines.push("");
149
+ lines.push(`## ${recordDay}`, "");
150
+ day = recordDay;
151
+ }
152
+ const text = describe(record).replace(/\n/g, " / ");
153
+ lines.push(`${localClock(record.created)} ${text.startsWith(`${record.from}:`) ? text : `${record.from}: ${text}`}`);
154
+ }
155
+ return `${lines.join("\n")}\n`;
156
+ }
157
+
158
+ module.exports = {
159
+ describe,
160
+ parseSince,
161
+ renderTranscript,
162
+ since,
163
+ displayRecords,
164
+ formatLine,
165
+ localClock,
166
+ localDay,
167
+ localStamp,
168
+ relativeAge,
169
+ };
@@ -18,6 +18,9 @@ const STANDING_AUTHORIZATION_ACTIONS = [
18
18
  // older than the running Keel (#164). It acts on this checkout, so it takes
19
19
  // no scope, and it never covers committing what the refresh wrote.
20
20
  "protocol-refresh",
21
+ // Answering, in the named chat group, a record addressed to the session's
22
+ // role (#195). Scoped: in a Slack-enabled group a reply leaves the machine.
23
+ "chat-reply",
21
24
  ];
22
25
 
23
26
  // The actions whose credential reaches further than the checkout the
@@ -27,7 +30,7 @@ const STANDING_AUTHORIZATION_ACTIONS = [
27
30
  // actions are declared with the resource they may reach and refused bare —
28
31
  // accepting the bare form as a convenience would make the narrow form optional
29
32
  // and the wide one the default, which is the decision inverted.
30
- const SCOPED_AUTHORIZATION_ACTIONS = new Set(["issue"]);
33
+ const SCOPED_AUTHORIZATION_ACTIONS = new Set(["issue", "chat-reply"]);
31
34
 
32
35
  // `<owner>/<repo>`: two non-empty segments and nothing else. The shape is
33
36
  // checked and the existence is not, for the reason `triage` never fetches an
@@ -35,12 +38,19 @@ const SCOPED_AUTHORIZATION_ACTIONS = new Set(["issue"]);
35
38
  // deterministic evaluation its verdict rests on.
36
39
  const AUTHORIZATION_SCOPE_PATTERN = /^[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+$/;
37
40
 
41
+ // Each scoped action's form and shape. `chat-reply` names a chat group, whose
42
+ // names follow the chat's own pattern (src/core/chat/store.js).
43
+ const AUTHORIZATION_SCOPES = {
44
+ issue: { form: "<owner>/<repo>", pattern: AUTHORIZATION_SCOPE_PATTERN },
45
+ "chat-reply": { form: "<group>", pattern: /^[a-z0-9][a-z0-9-]{0,31}$/ },
46
+ };
47
+
38
48
  // How the accepted names are spelled back to an author: the scoped ones carry
39
49
  // their form, so the list is copyable rather than a name the next message
40
50
  // refuses.
41
51
  const STANDING_AUTHORIZATION_ACCEPTED_FORMS = STANDING_AUTHORIZATION_ACTIONS.map(
42
52
  (action) =>
43
- SCOPED_AUTHORIZATION_ACTIONS.has(action) ? `${action}:<owner>/<repo>` : action
53
+ SCOPED_AUTHORIZATION_ACTIONS.has(action) ? `${action}:${AUTHORIZATION_SCOPES[action].form}` : action
44
54
  );
45
55
 
46
56
  // One declared entry, split into the action and the resource it names. Returns
@@ -58,7 +68,7 @@ function classifyAuthorizationEntry(entry) {
58
68
  return { ok: true, entry, action, scope: null };
59
69
  }
60
70
  if (scope === null) return { ok: false, entry, action, reason: "missing-scope" };
61
- if (!AUTHORIZATION_SCOPE_PATTERN.test(scope)) {
71
+ if (!AUTHORIZATION_SCOPES[action].pattern.test(scope)) {
62
72
  return { ok: false, entry, action, reason: "malformed-scope" };
63
73
  }
64
74
  return { ok: true, entry, action, scope };
@@ -246,7 +256,18 @@ function standingAuthorizationUnknownMessage(unknown, problems = []) {
246
256
  // names are ... issue" beside "unrecognized action: issue" would contradict
247
257
  // itself. Name what is missing instead, and why this one name carries it.
248
258
  for (const problem of problems) {
249
- if (problem.reason === "missing-scope") {
259
+ if (problem.reason === "missing-scope" && problem.action === "chat-reply") {
260
+ notes.push(
261
+ "`chat-reply` names no chat group; write it as `chat-reply:<group>`, "
262
+ + "one entry per group. In a Slack-enabled group a reply leaves the "
263
+ + "machine, so each group whose replies may go out is named."
264
+ );
265
+ } else if (problem.reason === "malformed-scope" && problem.action === "chat-reply") {
266
+ notes.push(
267
+ `\`${problem.entry}\` does not name a chat group as \`<group>\` — `
268
+ + "lowercase letters, digits, and hyphens, starting with a letter or digit."
269
+ );
270
+ } else if (problem.reason === "missing-scope") {
250
271
  notes.push(
251
272
  `\`${problem.action}\` names no repository; write it as `
252
273
  + `\`${problem.action}:<owner>/<repo>\`. The credentials that open an `
@@ -277,11 +298,17 @@ function readStandingAuthorization(repo) {
277
298
  // Additive: `declared` stays the entries as written, so the capsule's
278
299
  // inherited autonomy line reads back what the file says.
279
300
  const scopes = new Map();
301
+ // `chat-reply` may be declared once per group, so its scopes are kept as a
302
+ // list, and `scopes` carries them joined for the surfaces that print one.
303
+ const chatReplyGroups = [];
280
304
  for (const entry of configList(repo, "authorize")) {
281
305
  const classified = classifyAuthorizationEntry(entry);
282
306
  if (classified.ok) {
283
307
  declared.push(entry);
284
- scopes.set(classified.action, classified.scope);
308
+ if (!scopes.has(classified.action)) scopes.set(classified.action, classified.scope);
309
+ if (classified.action === "chat-reply" && !chatReplyGroups.includes(classified.scope)) {
310
+ chatReplyGroups.push(classified.scope);
311
+ }
285
312
  continue;
286
313
  }
287
314
  unknown.push(entry);
@@ -294,11 +321,13 @@ function readStandingAuthorization(repo) {
294
321
  return {
295
322
  declared: [],
296
323
  scopes: new Map(),
324
+ chatReplyGroups: [],
297
325
  unknown,
298
326
  message: standingAuthorizationUnknownMessage(unknown, problems),
299
327
  };
300
328
  }
301
- return { declared, scopes, unknown, message: null };
329
+ if (chatReplyGroups.length) scopes.set("chat-reply", chatReplyGroups.join(", "));
330
+ return { declared, scopes, chatReplyGroups, unknown, message: null };
302
331
  }
303
332
 
304
333
  // `full_mode_paths:` — the paths whose change always routes Full, whatever the
@@ -386,10 +415,7 @@ function configMap(repo, key) {
386
415
  return entries;
387
416
  }
388
417
 
389
- // Who runs a task. Declaring a tier is what permits delegation at that tier —
390
- // there is no separate on/off entry, because a tier with no permission and a
391
- // permission with no tier are both incomplete, and one field cannot disagree
392
- // with itself. An absent declaration delegates nothing, which is the default.
418
+ // Optional capability metadata; absence does not forbid model-chosen delegation.
393
419
  function readDelegationPolicy(repo) {
394
420
  const block = configMap(repo, "delegation");
395
421
  const tier = block.tier;