@christang/keel 5.221.0 → 5.223.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/.claude-plugin/plugin.json +1 -1
- package/README.md +16 -7
- package/README.zh-CN.md +12 -6
- package/assets/bootstrap/AGENTS.md +1 -1
- package/bin/keel.js +16 -1
- 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/plugins/keel/commands/feedback.md +38 -0
- package/plugins/keel/scripts/pretooluse-guard.js +63 -13
- package/scripts/validation/common.py +2 -2
- package/scripts/validation/docs.py +2 -2
- package/scripts/validation/feedback.py +324 -0
- package/scripts/validation/guard.py +177 -0
- package/scripts/validation/hosts.py +1 -1
- package/scripts/validation/registry.py +11 -0
- package/src/core/config.js +23 -2
- package/src/core/feedback.js +286 -0
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// `keel feedback "<one sentence>"` (#505): drafts a fixed-structure issue for
|
|
4
|
+
// the Keel repository from inside any project, redacted before anything is
|
|
5
|
+
// shown, and lists near-duplicates. It creates nothing here; that is a later
|
|
6
|
+
// step under a declaration or a confirmation.
|
|
7
|
+
|
|
8
|
+
const fs = require("fs");
|
|
9
|
+
const os = require("os");
|
|
10
|
+
const path = require("path");
|
|
11
|
+
const { spawnSync } = require("child_process");
|
|
12
|
+
|
|
13
|
+
const PACKAGE_JSON = require("../../package.json");
|
|
14
|
+
|
|
15
|
+
// The target is Keel itself, read from the package's own repository URL: the
|
|
16
|
+
// command is feedback to Keel, and a flag would make it a general issue filer.
|
|
17
|
+
const KEEL_REPO = (() => {
|
|
18
|
+
const url = typeof PACKAGE_JSON.repository === "string" ? PACKAGE_JSON.repository : PACKAGE_JSON.repository.url;
|
|
19
|
+
const match = String(url).match(/github\.com[:/]([^/]+\/[^/.]+)(?:\.git)?$/);
|
|
20
|
+
return match ? match[1] : "TanglmChris/keel";
|
|
21
|
+
})();
|
|
22
|
+
|
|
23
|
+
const USAGE = [
|
|
24
|
+
"keel feedback \"<one sentence>\" [--command <cmd>] [--output-file <file>] [--expected <text>] [--repro <text>] [--impact <text>] [--host <name>] [--doctor] [--create [--confirmed]]",
|
|
25
|
+
" Draft an issue for the Keel repository: the version, the command and its output, redacted. Creates nothing without --create;",
|
|
26
|
+
" --create needs `issue:TanglmChris/keel` in this project's authorize: or --confirmed (the user approved this draft).",
|
|
27
|
+
].join("\n");
|
|
28
|
+
|
|
29
|
+
// Redaction runs on everything shown. The order matters: block and token
|
|
30
|
+
// shapes first, then the looser key=value form, then paths.
|
|
31
|
+
const RULES = [
|
|
32
|
+
["private-key", /-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z ]*PRIVATE KEY-----|$)/g, "[private key]"],
|
|
33
|
+
["token", /\b(?:gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,}|sk-[A-Za-z0-9_-]{20,}|xox[abprs]-[A-Za-z0-9-]{10,}|xapp-[A-Za-z0-9-]{10,}|AKIA[0-9A-Z]{16})\b/g, "[token]"],
|
|
34
|
+
["token", /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{5,}/g, "[token]"],
|
|
35
|
+
["token", /\bBearer\s+[A-Za-z0-9._~+/=-]{8,}/g, "Bearer [token]"],
|
|
36
|
+
["url-credential", /([A-Za-z][A-Za-z0-9+.-]*:\/\/)[^\s/:@]+:[^\s/@]+@/g, "$1[credential]@"],
|
|
37
|
+
["secret", /\b([A-Za-z0-9_.-]*(?:token|secret|password|passwd|api[_-]?key|private[_-]?key|access[_-]?key)[A-Za-z0-9_.-]*)([ \t]*[=:][ \t]*)(["']?)(?!\[)[^\s"']{4,}/gi, "$1$2$3[redacted]"],
|
|
38
|
+
["slack-id", /\b[UWCDGTB](?=[A-Z0-9]*\d)[A-Z0-9]{8,11}\b/g, "[slack-id]"],
|
|
39
|
+
["email", /[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}/g, "[email]"],
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
function escapeRegExp(value) {
|
|
43
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Returns the text with every match replaced, and a count per kind. A value is
|
|
47
|
+
// never reported, only how many were.
|
|
48
|
+
function redact(text, context = {}) {
|
|
49
|
+
const counts = {};
|
|
50
|
+
let out = String(text);
|
|
51
|
+
for (const [kind, pattern, replacement] of RULES) {
|
|
52
|
+
out = out.replace(pattern, (...match) => {
|
|
53
|
+
counts[kind] = (counts[kind] || 0) + 1;
|
|
54
|
+
return replacement.replace(/\$(\d)/g, (_, n) => match[Number(n)] || "");
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const roots = [];
|
|
58
|
+
for (const [value, short] of [[context.project, "<project>"], [context.home || os.homedir(), "~"]]) {
|
|
59
|
+
if (!value) continue;
|
|
60
|
+
for (const variant of new Set([value, safeRealpath(value)])) {
|
|
61
|
+
if (variant && variant !== "/") roots.push([variant, short]);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
roots.sort((a, b) => b[0].length - a[0].length);
|
|
65
|
+
for (const [value, short] of roots) {
|
|
66
|
+
out = out.replace(new RegExp(`${escapeRegExp(value)}(?=$|[/\\s"'\`)\\]:,;])`, "gm"), () => {
|
|
67
|
+
counts.path = (counts.path || 0) + 1;
|
|
68
|
+
return short;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return { text: out, counts };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function safeRealpath(value) {
|
|
75
|
+
try {
|
|
76
|
+
return fs.realpathSync(value);
|
|
77
|
+
} catch {
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function merge(total, counts) {
|
|
83
|
+
for (const [kind, n] of Object.entries(counts)) total[kind] = (total[kind] || 0) + n;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function git(cwd, args) {
|
|
87
|
+
const result = spawnSync("git", ["-C", cwd, ...args], { encoding: "utf8", timeout: 5000 });
|
|
88
|
+
return result.status === 0 ? String(result.stdout || "").trim() : null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function parse(argv) {
|
|
92
|
+
const options = { words: [], unknown: null, missing: null };
|
|
93
|
+
const valued = { "--command": "command", "--output-file": "outputFile", "--expected": "expected", "--repro": "repro", "--impact": "impact", "--host": "host" };
|
|
94
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
95
|
+
const arg = argv[i];
|
|
96
|
+
if (arg === "--help" || arg === "-h") options.help = true;
|
|
97
|
+
else if (arg === "--doctor") options.doctor = true;
|
|
98
|
+
else if (arg === "--create") options.create = true;
|
|
99
|
+
else if (arg === "--confirmed") options.confirmed = true;
|
|
100
|
+
else if (valued[arg]) {
|
|
101
|
+
if (i + 1 >= argv.length) options.missing = arg;
|
|
102
|
+
else options[valued[arg]] = argv[++i];
|
|
103
|
+
} else if (arg.startsWith("--")) options.unknown = options.unknown || arg;
|
|
104
|
+
else options.words.push(arg);
|
|
105
|
+
}
|
|
106
|
+
return options;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// What is collected, and nothing else (#505 D4).
|
|
110
|
+
function environment(cwd, options) {
|
|
111
|
+
const host = options.host || (process.env.CLAUDECODE ? "claude" : "unknown");
|
|
112
|
+
const entry = path.join(__dirname, "..", "..", "bin", "keel.js");
|
|
113
|
+
const context = spawnSync(process.execPath, [entry, "context"], { cwd, encoding: "utf8", timeout: 20000 });
|
|
114
|
+
const lines = String(context.stdout || "").split(/\r?\n/)
|
|
115
|
+
.filter((line) => /^(Keel context|Next action):/.test(line));
|
|
116
|
+
const facts = [
|
|
117
|
+
`Keel: ${PACKAGE_JSON.version}`,
|
|
118
|
+
`Node: ${process.version}`,
|
|
119
|
+
`Platform: ${process.platform} ${process.arch}`,
|
|
120
|
+
`Host: ${host}`,
|
|
121
|
+
...lines,
|
|
122
|
+
];
|
|
123
|
+
if (options.doctor) {
|
|
124
|
+
const doctor = spawnSync(process.execPath, [entry, "--doctor"], { cwd, encoding: "utf8", timeout: 30000 });
|
|
125
|
+
facts.push("", "`keel --doctor`:", "```", String(doctor.stdout || "").trimEnd(), "```");
|
|
126
|
+
}
|
|
127
|
+
return facts;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function readOutput(cwd, file) {
|
|
131
|
+
if (!file) return null;
|
|
132
|
+
try {
|
|
133
|
+
const text = fs.readFileSync(path.resolve(cwd, file), "utf8");
|
|
134
|
+
const lines = text.split(/\r?\n/);
|
|
135
|
+
const kept = lines.length > 80 ? [...lines.slice(0, 80), `… (${lines.length - 80} more lines not included)`] : lines;
|
|
136
|
+
return kept.join("\n").slice(0, 8000);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
return `(could not read ${file}: ${error.code || error.message})`;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function build(cwd, options) {
|
|
143
|
+
const project = git(cwd, ["rev-parse", "--show-toplevel"]) || cwd;
|
|
144
|
+
const counts = {};
|
|
145
|
+
const clean = (text) => {
|
|
146
|
+
const result = redact(text, { project });
|
|
147
|
+
merge(counts, result.counts);
|
|
148
|
+
return result.text;
|
|
149
|
+
};
|
|
150
|
+
const summary = clean(options.words.join(" ").trim());
|
|
151
|
+
const placeholder = (value, text) => (value ? clean(value) : text);
|
|
152
|
+
const output = readOutput(cwd, options.outputFile);
|
|
153
|
+
const evidence = [];
|
|
154
|
+
if (options.command) evidence.push("命令:", "```", clean(options.command), "```");
|
|
155
|
+
if (output !== null) evidence.push("输出:", "```", clean(output), "```");
|
|
156
|
+
const body = [
|
|
157
|
+
"## 现象", "", summary, "",
|
|
158
|
+
"## 期望", "", placeholder(options.expected, "(未填写)"), "",
|
|
159
|
+
"## 复现", "", placeholder(options.repro, "(未填写)"), "",
|
|
160
|
+
"## 证据", "", evidence.length ? evidence.join("\n") : "(未提供命令或输出)", "",
|
|
161
|
+
"## 影响", "", placeholder(options.impact, "(未填写)"), "",
|
|
162
|
+
"## 环境", "", ...environment(cwd, options).map((line) => (line.startsWith("`") || line.startsWith("```") || line === "" ? clean(line) : `- ${clean(line)}`)), "",
|
|
163
|
+
"---",
|
|
164
|
+
"由 `keel feedback` 起草;未带任何准入标签,是否值得做由负责人决定。", "",
|
|
165
|
+
].join("\n");
|
|
166
|
+
return { title: summary.split(/\r?\n/)[0].slice(0, 120), body, counts };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// The three longest distinct ASCII words of at least four characters, else the
|
|
170
|
+
// first twelve characters (#505 D5).
|
|
171
|
+
function keywords(summary) {
|
|
172
|
+
const words = [...new Set((summary.match(/[A-Za-z0-9][A-Za-z0-9_.:-]{3,}/g) || []).map((w) => w.toLowerCase()))]
|
|
173
|
+
.sort((a, b) => b.length - a.length).slice(0, 3);
|
|
174
|
+
return words.length ? words.join(" ") : summary.slice(0, 12);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function ghAvailable() {
|
|
178
|
+
const result = spawnSync("gh", ["--version"], { encoding: "utf8", timeout: 10000 });
|
|
179
|
+
return !result.error && result.status === 0;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function duplicates(title) {
|
|
183
|
+
if (!ghAvailable()) return { searched: false, reason: "gh is not available", found: [] };
|
|
184
|
+
const result = spawnSync("gh", [
|
|
185
|
+
"issue", "list", "--repo", KEEL_REPO, "--state", "all", "--search", keywords(title),
|
|
186
|
+
"--limit", "5", "--json", "number,title,state,url",
|
|
187
|
+
], { encoding: "utf8", timeout: 30000 });
|
|
188
|
+
if (result.status !== 0) {
|
|
189
|
+
return { searched: false, reason: String(result.stderr || "gh failed").trim().split(/\r?\n/)[0], found: [] };
|
|
190
|
+
}
|
|
191
|
+
try {
|
|
192
|
+
return { searched: true, found: JSON.parse(result.stdout || "[]").slice(0, 5) };
|
|
193
|
+
} catch {
|
|
194
|
+
return { searched: false, reason: "gh printed something that is not JSON", found: [] };
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function shellQuote(value) {
|
|
199
|
+
return `'${String(value).replace(/'/g, `'\\''`)}'`;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function saveDraft(draft) {
|
|
203
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "keel-feedback-"));
|
|
204
|
+
const file = path.join(dir, "issue.md");
|
|
205
|
+
fs.writeFileSync(file, `# ${draft.title}\n\n${draft.body}`);
|
|
206
|
+
return file;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function describe(draft, file, dup) {
|
|
210
|
+
const lines = ["Keel feedback draft — nothing was created.", "", `Title: ${draft.title}`, "", draft.body];
|
|
211
|
+
const kinds = Object.entries(draft.counts).map(([kind, n]) => `${kind} ${n}`);
|
|
212
|
+
lines.push(`Redacted ${Object.values(draft.counts).reduce((a, b) => a + b, 0)} value(s)${kinds.length ? ` (${kinds.join(", ")})` : ""}; the values are not printed.`);
|
|
213
|
+
lines.push(`Saved: ${file}`, "");
|
|
214
|
+
if (!dup.searched) {
|
|
215
|
+
lines.push(`Similar issues: not searched (${dup.reason}).`);
|
|
216
|
+
} else if (!dup.found.length) {
|
|
217
|
+
lines.push("Similar issues: none found.");
|
|
218
|
+
} else {
|
|
219
|
+
lines.push("Similar issues (up to 5):");
|
|
220
|
+
for (const issue of dup.found) lines.push(` #${issue.number} ${issue.title} (${issue.state}) ${issue.url}`);
|
|
221
|
+
lines.push("To add to one yourself (Keel runs no comment):");
|
|
222
|
+
lines.push(` gh issue comment ${dup.found[0].number} --repo ${KEEL_REPO} --body-file ${file}`);
|
|
223
|
+
}
|
|
224
|
+
lines.push("To create it:", ` gh issue create --repo ${KEEL_REPO} --title ${shellQuote(draft.title)} --body-file ${file}`);
|
|
225
|
+
return lines.join("\n");
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// `issue:TanglmChris/keel` in the project's own `authorize:` waives the
|
|
229
|
+
// per-issue confirmation (#505 D6). A declaration Keel cannot read grants
|
|
230
|
+
// nothing, as everywhere else.
|
|
231
|
+
function authorized(project) {
|
|
232
|
+
try {
|
|
233
|
+
const { declared } = require("./config").readStandingAuthorization(project);
|
|
234
|
+
return declared.some((entry) => entry === `issue:${KEEL_REPO}` || entry.startsWith(`issue:${KEEL_REPO}@`));
|
|
235
|
+
} catch {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// No label, assignee or milestone is ever passed, and nothing else of any
|
|
241
|
+
// issue is touched (#505 D6).
|
|
242
|
+
function create(draft, file) {
|
|
243
|
+
const result = spawnSync("gh", ["issue", "create", "--repo", KEEL_REPO, "--title", draft.title, "--body-file", file], {
|
|
244
|
+
encoding: "utf8", timeout: 60000,
|
|
245
|
+
});
|
|
246
|
+
if (result.error || result.status !== 0) {
|
|
247
|
+
const why = result.error ? result.error.code || result.error.message : String(result.stderr || "gh failed").trim().split(/\r?\n/)[0];
|
|
248
|
+
return { ok: false, why };
|
|
249
|
+
}
|
|
250
|
+
const url = String(result.stdout || "").trim().split(/\r?\n/).pop();
|
|
251
|
+
return { ok: true, url };
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function runFeedback(argv) {
|
|
255
|
+
const options = parse(argv);
|
|
256
|
+
if (options.help) {
|
|
257
|
+
process.stdout.write(`${USAGE}\n`);
|
|
258
|
+
return 0;
|
|
259
|
+
}
|
|
260
|
+
if (options.unknown || options.missing || !options.words.length) {
|
|
261
|
+
const why = options.unknown ? `unknown option ${options.unknown}` : options.missing ? `${options.missing} needs a value` : "a one-sentence summary is required";
|
|
262
|
+
process.stderr.write(`keel feedback: ${why}\n${USAGE}\n`);
|
|
263
|
+
return 2;
|
|
264
|
+
}
|
|
265
|
+
const cwd = process.cwd();
|
|
266
|
+
const draft = build(cwd, options);
|
|
267
|
+
const file = saveDraft(draft);
|
|
268
|
+
process.stdout.write(`${describe(draft, file, duplicates(draft.title))}\n`);
|
|
269
|
+
if (!options.create) return 0;
|
|
270
|
+
if (!options.confirmed && !authorized(git(cwd, ["rev-parse", "--show-toplevel"]) || cwd)) {
|
|
271
|
+
process.stderr.write(
|
|
272
|
+
`keel feedback: not created. This project does not declare \`issue:${KEEL_REPO}\` in authorize:, so the user must approve this draft first; `
|
|
273
|
+
+ "rerun with --create --confirmed once they have.\n"
|
|
274
|
+
);
|
|
275
|
+
return 3;
|
|
276
|
+
}
|
|
277
|
+
const made = create(draft, file);
|
|
278
|
+
if (!made.ok) {
|
|
279
|
+
process.stderr.write(`keel feedback: not created (${made.why}). The draft is saved at ${file}; run the \`gh issue create\` command above when gh works.\n`);
|
|
280
|
+
return 4;
|
|
281
|
+
}
|
|
282
|
+
process.stdout.write(`Created: ${made.url}\n`);
|
|
283
|
+
return 0;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
module.exports = { KEEL_REPO, USAGE, redact, keywords, runFeedback };
|