@christang/keel 5.84.0 → 5.85.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 +22 -0
- package/README.zh-CN.md +21 -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 +2 -1
- package/plugins/keel/hooks/codex.json +44 -0
- package/plugins/keel/scripts/codex-mail-hook.js +75 -0
- package/plugins/keel/scripts/mail-hook.js +11 -9
- package/scripts/fake_slack.py +277 -0
- package/scripts/validate_codex_receiving.py +296 -0
- package/scripts/validate_plugin.py +1476 -178
- package/src/core/chat/archive.js +234 -0
- package/src/core/chat/bridge.js +808 -0
- package/src/core/chat/cli.js +453 -0
- package/src/core/chat/config.js +64 -0
- package/src/core/chat/guards.js +96 -0
- package/src/core/chat/lifecycle.js +214 -0
- package/src/core/chat/migrate.js +142 -0
- package/src/core/chat/notice.js +179 -0
- package/src/core/chat/redact.js +37 -0
- package/src/core/chat/slack.js +104 -0
- package/src/core/chat/store.js +776 -0
- package/src/core/chat/view.js +165 -0
- package/src/core/mail.js +123 -433
|
@@ -0,0 +1,165 @@
|
|
|
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
|
+
if (record.mentions && record.mentions.length) parts.push(record.mentions.map((m) => `@${m}`).join(" "));
|
|
83
|
+
if (record.edited) parts.push("(edited)");
|
|
84
|
+
return parts.length ? ` ${parts.join(" ")}` : "";
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function describe(record) {
|
|
88
|
+
switch (record.kind) {
|
|
89
|
+
case "join":
|
|
90
|
+
return `${record.from} added ${record.target}`;
|
|
91
|
+
case "leave":
|
|
92
|
+
return `${record.from} removed ${record.target}`;
|
|
93
|
+
case "archive":
|
|
94
|
+
return `${record.from} archived the group`;
|
|
95
|
+
case "done":
|
|
96
|
+
return `${record.from} closed todo ${record.target}`;
|
|
97
|
+
default:
|
|
98
|
+
if (record.retracted) return `${record.from}: (retracted)`;
|
|
99
|
+
return `${record.from}:${markers(record)} ${record.text}`;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function formatLine(record, { clock = false } = {}) {
|
|
104
|
+
const when = clock ? localClock(record.created) : localStamp(record.created);
|
|
105
|
+
return `${when} ${describe(record)} [${record.id}]`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// `--since`: a duration back from now (`90s`, `15m`, `2h`, `3d`) or a date or
|
|
109
|
+
// time (`2026-10-01` is local midnight). Returns epoch milliseconds or null.
|
|
110
|
+
function parseSince(value, now = Date.now()) {
|
|
111
|
+
const text = String(value || "").trim();
|
|
112
|
+
const duration = text.match(/^(\d+)([smhd])$/);
|
|
113
|
+
if (duration) {
|
|
114
|
+
const unit = { s: 1e3, m: 60e3, h: 3600e3, d: 86400e3 }[duration[2]];
|
|
115
|
+
return now - Number(duration[1]) * unit;
|
|
116
|
+
}
|
|
117
|
+
const day = text.match(/^(\d{4})-(\d\d)-(\d\d)$/);
|
|
118
|
+
if (day) return new Date(Number(day[1]), Number(day[2]) - 1, Number(day[3])).getTime();
|
|
119
|
+
const time = Date.parse(text);
|
|
120
|
+
return Number.isNaN(time) ? null : time;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function since(records, threshold) {
|
|
124
|
+
if (threshold === null || threshold === undefined) return records;
|
|
125
|
+
return records.filter((record) => {
|
|
126
|
+
const time = Date.parse(record.created);
|
|
127
|
+
return Number.isNaN(time) || time >= threshold;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// The per-group Markdown transcript a person opens in any editor (D20): one
|
|
132
|
+
// heading per local day, then `HH:MM sender: text` per record.
|
|
133
|
+
function renderTranscript(group, records) {
|
|
134
|
+
const shown = displayRecords(records).slice().sort((a, b) => {
|
|
135
|
+
const left = Date.parse(a.created);
|
|
136
|
+
const right = Date.parse(b.created);
|
|
137
|
+
return (Number.isNaN(left) ? 0 : left) - (Number.isNaN(right) ? 0 : right) || (a.id < b.id ? -1 : 1);
|
|
138
|
+
});
|
|
139
|
+
const lines = [`# ${group}`, "", "Generated by keel chat after every write; edit the group, not this file.", ""];
|
|
140
|
+
let day = null;
|
|
141
|
+
for (const record of shown) {
|
|
142
|
+
const recordDay = localDay(record.created);
|
|
143
|
+
if (recordDay !== day) {
|
|
144
|
+
if (day !== null) lines.push("");
|
|
145
|
+
lines.push(`## ${recordDay}`, "");
|
|
146
|
+
day = recordDay;
|
|
147
|
+
}
|
|
148
|
+
const text = describe(record).replace(/\n/g, " / ");
|
|
149
|
+
lines.push(`${localClock(record.created)} ${text.startsWith(`${record.from}:`) ? text : `${record.from}: ${text}`}`);
|
|
150
|
+
}
|
|
151
|
+
return `${lines.join("\n")}\n`;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
module.exports = {
|
|
155
|
+
describe,
|
|
156
|
+
parseSince,
|
|
157
|
+
renderTranscript,
|
|
158
|
+
since,
|
|
159
|
+
displayRecords,
|
|
160
|
+
formatLine,
|
|
161
|
+
localClock,
|
|
162
|
+
localDay,
|
|
163
|
+
localStamp,
|
|
164
|
+
relativeAge,
|
|
165
|
+
};
|