@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.
- package/README.md +49 -5
- package/README.zh-CN.md +34 -0
- package/assets/bootstrap/AGENTS.md +2 -2
- package/assets/openspec/schemas/keel-spec-driven/schema.yaml +3 -3
- package/assets/openspec/schemas/keel-spec-driven/templates/tasks.md +3 -3
- package/bin/keel.js +60 -7
- 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/agents/keel-single-task-goal-claude.md +1 -1
- package/plugins/keel/agents/keel-single-task-goal-codex.md +1 -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/plugins/keel/skills/keel-run-single-task-goal/SKILL.md +2 -2
- package/plugins/keel/skills/keel-run-single-task-goal/guidance.md +1 -1
- package/scripts/fake_slack.py +277 -0
- package/scripts/validate_codex_receiving.py +296 -0
- package/scripts/validate_plugin.py +1922 -227
- package/src/core/capabilities.js +2 -2
- package/src/core/chat/archive.js +234 -0
- package/src/core/chat/bridge.js +808 -0
- package/src/core/chat/cli.js +465 -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 +216 -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 +169 -0
- package/src/core/config.js +36 -10
- package/src/core/mail.js +123 -433
- package/src/core/projection.js +43 -24
- package/src/core/task-contract.js +3 -3
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// The Slack Web API client the bridge uses (issue #187, design D15–D17). It
|
|
4
|
+
// uses Node's built-in `fetch`, so the bridge adds no dependency.
|
|
5
|
+
//
|
|
6
|
+
// Write methods take a JSON body; read methods and connection setup take a
|
|
7
|
+
// form body, which every Web API method accepts. `KEEL_SLACK_API_BASE` points
|
|
8
|
+
// the client at a test server. A token is sent only in the Authorization
|
|
9
|
+
// header and is never part of an error message.
|
|
10
|
+
|
|
11
|
+
const DEFAULT_BASE = "https://slack.com/api";
|
|
12
|
+
const FORM_METHODS = new Set([
|
|
13
|
+
"auth.test",
|
|
14
|
+
"apps.connections.open",
|
|
15
|
+
"conversations.history",
|
|
16
|
+
"conversations.replies",
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
class SlackError extends Error {
|
|
20
|
+
constructor(method, error, { retryAfter = null, status = null } = {}) {
|
|
21
|
+
super(`Slack ${method} failed: ${error}${status ? ` (HTTP ${status})` : ""}`);
|
|
22
|
+
this.method = method;
|
|
23
|
+
this.error = error;
|
|
24
|
+
this.retryAfter = retryAfter;
|
|
25
|
+
this.status = status;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function apiBase() {
|
|
30
|
+
return (process.env.KEEL_SLACK_API_BASE || DEFAULT_BASE).replace(/\/+$/, "");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function sleep(ms) {
|
|
34
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function call(method, params, token) {
|
|
38
|
+
const headers = { Authorization: `Bearer ${token}` };
|
|
39
|
+
let body;
|
|
40
|
+
if (FORM_METHODS.has(method)) {
|
|
41
|
+
const form = new URLSearchParams();
|
|
42
|
+
for (const [key, value] of Object.entries(params || {})) {
|
|
43
|
+
if (value === undefined || value === null) continue;
|
|
44
|
+
form.set(key, typeof value === "object" ? JSON.stringify(value) : String(value));
|
|
45
|
+
}
|
|
46
|
+
headers["Content-Type"] = "application/x-www-form-urlencoded";
|
|
47
|
+
body = form.toString();
|
|
48
|
+
} else {
|
|
49
|
+
headers["Content-Type"] = "application/json; charset=utf-8";
|
|
50
|
+
body = JSON.stringify(params || {});
|
|
51
|
+
}
|
|
52
|
+
let response;
|
|
53
|
+
try {
|
|
54
|
+
response = await fetch(`${apiBase()}/${method}`, { method: "POST", headers, body });
|
|
55
|
+
} catch (error) {
|
|
56
|
+
throw new SlackError(method, `network error: ${error.cause ? error.cause.code || error.cause.message : error.message}`);
|
|
57
|
+
}
|
|
58
|
+
if (response.status === 429) {
|
|
59
|
+
const retryAfter = Number(response.headers.get("retry-after")) || 1;
|
|
60
|
+
throw new SlackError(method, "ratelimited", { retryAfter, status: 429 });
|
|
61
|
+
}
|
|
62
|
+
let parsed = null;
|
|
63
|
+
try {
|
|
64
|
+
parsed = await response.json();
|
|
65
|
+
} catch {
|
|
66
|
+
throw new SlackError(method, "response was not JSON", { status: response.status });
|
|
67
|
+
}
|
|
68
|
+
if (!parsed || parsed.ok !== true) {
|
|
69
|
+
throw new SlackError(method, (parsed && parsed.error) || "unknown_error", { status: response.status });
|
|
70
|
+
}
|
|
71
|
+
return parsed;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Waits out a 429 for as long as Slack asks; other failures retry with
|
|
75
|
+
// backoff up to `attempts` times and then throw.
|
|
76
|
+
async function callWithRetry(method, params, token, { attempts = 4, onWait = null } = {}) {
|
|
77
|
+
let failures = 0;
|
|
78
|
+
let backoff = 1000;
|
|
79
|
+
for (;;) {
|
|
80
|
+
try {
|
|
81
|
+
return await call(method, params, token);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
if (!(error instanceof SlackError)) throw error;
|
|
84
|
+
if (error.retryAfter !== null) {
|
|
85
|
+
if (onWait) onWait(method, error.retryAfter);
|
|
86
|
+
await sleep(error.retryAfter * 1000);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
failures += 1;
|
|
90
|
+
if (failures >= attempts || ["invalid_auth", "not_authed", "channel_not_found", "missing_scope", "account_inactive"].includes(error.error)) {
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
await sleep(backoff);
|
|
94
|
+
backoff = Math.min(backoff * 2, 5 * 60 * 1000);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
module.exports = {
|
|
100
|
+
SlackError,
|
|
101
|
+
call,
|
|
102
|
+
callWithRetry,
|
|
103
|
+
sleep,
|
|
104
|
+
};
|