@alterset/alterspec-client 0.19.0 → 0.19.1
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/developer-guide.md +3 -1
- package/dist/cli.js +72 -10
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/developer-guide.md
CHANGED
|
@@ -205,7 +205,9 @@ server. Then talk to it in plain words; the skills do the rest.
|
|
|
205
205
|
```
|
|
206
206
|
|
|
207
207
|
`Alterspec-Covers` names the checklist items whose tests pass with that commit, never items that aren't tested yet.
|
|
208
|
-
After each commit a hook reports them in the background, and the task's progress on the dashboard moves.
|
|
208
|
+
After each commit a hook reports them in the background, and the task's progress on the dashboard moves. An
|
|
209
|
+
object named without its section (`RULE-002` where the checklist has `RULE-002#guards`) isn't counted: the hook
|
|
210
|
+
tells Claude the form to use, and a later commit naming it that way settles it.
|
|
209
211
|
|
|
210
212
|
4. Push your branch and type `/alterspec-task-done CHG-023/BE`: the task is done at that commit on that branch, and
|
|
211
213
|
the tasks waiting for it may start from it. Open the pull request into the main branch as usual; the dispatcher
|
package/dist/cli.js
CHANGED
|
@@ -3240,17 +3240,48 @@ function coveredItems(repo, task) {
|
|
|
3240
3240
|
return [...first].map(([item, commit]) => ({ item, commit })).sort((a, b) => a.item < b.item ? -1 : a.item > b.item ? 1 : 0);
|
|
3241
3241
|
}
|
|
3242
3242
|
var unknownOf = (e) => e.message.split("\n").slice(1).map((l) => l.trim()).filter(Boolean);
|
|
3243
|
+
async function checklistOf(session, task) {
|
|
3244
|
+
try {
|
|
3245
|
+
const answer = await callTool(session, "task", { id: task.id });
|
|
3246
|
+
return (answer.items ?? []).map((i) => ({
|
|
3247
|
+
item: i.item,
|
|
3248
|
+
covered: !!i.covered_commit
|
|
3249
|
+
}));
|
|
3250
|
+
} catch {
|
|
3251
|
+
return [];
|
|
3252
|
+
}
|
|
3253
|
+
}
|
|
3254
|
+
function sortRefused(refused, sent, checklist) {
|
|
3255
|
+
const sentSet = new Set(sent);
|
|
3256
|
+
const out = {
|
|
3257
|
+
unknown: [],
|
|
3258
|
+
misnamed: [],
|
|
3259
|
+
superseded: []
|
|
3260
|
+
};
|
|
3261
|
+
for (const item of refused) {
|
|
3262
|
+
const parts = item.includes("#") ? [] : checklist.filter((c) => c.item.startsWith(`${item}#`));
|
|
3263
|
+
if (!parts.length) out.unknown.push(item);
|
|
3264
|
+
else if (parts.some((p) => p.covered || sentSet.has(p.item))) out.superseded.push(item);
|
|
3265
|
+
else out.misnamed.push({ item, forms: parts.map((p) => p.item).sort() });
|
|
3266
|
+
}
|
|
3267
|
+
return out;
|
|
3268
|
+
}
|
|
3243
3269
|
async function reportProgress(session, task, covered) {
|
|
3244
3270
|
try {
|
|
3245
3271
|
const answer = await callTool(session, "report_progress", { id: task.id, covered });
|
|
3246
|
-
return { task: task.id, covered, unknown: [], answer };
|
|
3272
|
+
return { task: task.id, covered, unknown: [], misnamed: [], superseded: [], answer };
|
|
3247
3273
|
} catch (e) {
|
|
3248
3274
|
if (!(e instanceof DispatcherError) || e.code !== "UNKNOWN_ITEM") throw e;
|
|
3249
|
-
const
|
|
3250
|
-
const known = covered.filter((c) => !
|
|
3251
|
-
if (!
|
|
3275
|
+
const refused = unknownOf(e);
|
|
3276
|
+
const known = covered.filter((c) => !refused.includes(c.item));
|
|
3277
|
+
if (!refused.length || known.length === covered.length) throw e;
|
|
3252
3278
|
const answer = await callTool(session, "report_progress", { id: task.id, covered: known });
|
|
3253
|
-
|
|
3279
|
+
const sorted = sortRefused(
|
|
3280
|
+
refused,
|
|
3281
|
+
known.map((c) => c.item),
|
|
3282
|
+
await checklistOf(session, task)
|
|
3283
|
+
);
|
|
3284
|
+
return { task: task.id, covered: known, ...sorted, answer };
|
|
3254
3285
|
}
|
|
3255
3286
|
}
|
|
3256
3287
|
function progressText(r) {
|
|
@@ -3259,11 +3290,14 @@ function progressText(r) {
|
|
|
3259
3290
|
const eta = r.answer.eta;
|
|
3260
3291
|
const count = progress ? `${progress.covered} of ${progress.of} items covered (${progress.percent} %${weight ? `, ${weight.covered} of ${weight.total} weight` : ""})` : "no checklist (its export predates task items)";
|
|
3261
3292
|
const when = !eta ? "" : eta.by === "done" ? "; done" : eta.date ? `; ETA ${eta.at_least ? "at least " : ""}${eta.date}${eta.by === "developer" ? ` (yours; computed ${eta.computed?.date ?? "unknown"})` : ""}` : "; ETA unknown";
|
|
3262
|
-
|
|
3263
|
-
if (r.unknown.length) lines.unshift(unknownLine(r));
|
|
3264
|
-
return lines.join("\n") + "\n";
|
|
3293
|
+
return [...refusedLines(r), `${r.task}: ${count}${when}.`].join("\n") + "\n";
|
|
3265
3294
|
}
|
|
3295
|
+
var refusedLines = (r) => [
|
|
3296
|
+
...r.unknown.length ? [unknownLine(r)] : [],
|
|
3297
|
+
...r.misnamed.map(misnamedLine)
|
|
3298
|
+
];
|
|
3266
3299
|
var unknownLine = (r) => `${r.task} has no item ${r.unknown.join(", ")}; left out of the report: name only the task's items (context lists them).`;
|
|
3300
|
+
var misnamedLine = (m) => `${m.item} is named without its section; the checklist writes it as ${m.forms.join(m.forms.length > 2 ? ", " : " or ")}: name ${m.forms.length === 1 ? "that" : "the part you covered"} in Alterspec-Covers (left out of the report).`;
|
|
3267
3301
|
var THROTTLE_MS = 15 * 6e4;
|
|
3268
3302
|
var statePath = (repo, task) => join8(
|
|
3269
3303
|
git3(repo, ["rev-parse", "--path-format=absolute", "--git-common-dir"]),
|
|
@@ -3289,7 +3323,14 @@ async function progressHook(opts) {
|
|
|
3289
3323
|
const hash = hashOf(covered);
|
|
3290
3324
|
if (state?.reported === hash) return "unchanged";
|
|
3291
3325
|
if (state && now() - Date.parse(state.at) < THROTTLE_MS) return "throttled";
|
|
3292
|
-
await reportProgress(opts.session(), task, covered);
|
|
3326
|
+
const report = await reportProgress(opts.session(), task, covered);
|
|
3327
|
+
const named2 = new Set(headCovers(opts.repo, task));
|
|
3328
|
+
const wrong = refusedLines({
|
|
3329
|
+
task: report.task,
|
|
3330
|
+
unknown: report.unknown.filter((i) => named2.has(i)),
|
|
3331
|
+
misnamed: report.misnamed.filter((m) => named2.has(m.item))
|
|
3332
|
+
});
|
|
3333
|
+
if (wrong.length && opts.say) opts.say(hookContext(wrong.join("\n")));
|
|
3293
3334
|
mkdirSync4(join8(path, ".."), { recursive: true });
|
|
3294
3335
|
writeFileSync6(path, JSON.stringify({ reported: hash, at: new Date(now()).toISOString() }) + "\n");
|
|
3295
3336
|
return "reported";
|
|
@@ -3297,6 +3338,23 @@ async function progressHook(opts) {
|
|
|
3297
3338
|
return "failed";
|
|
3298
3339
|
}
|
|
3299
3340
|
}
|
|
3341
|
+
function headCovers(repo, task) {
|
|
3342
|
+
const trailer = (key) => `%(trailers:key=${key},valueonly,separator=%x1d)`;
|
|
3343
|
+
const [tasks = "", covers = ""] = git3(repo, [
|
|
3344
|
+
"log",
|
|
3345
|
+
"-1",
|
|
3346
|
+
`--format=${trailer(TRAILER)}%x1f${trailer(COVERS)}`,
|
|
3347
|
+
"HEAD"
|
|
3348
|
+
]).split("");
|
|
3349
|
+
if (!tasks.split("").some((t) => t.trim().toUpperCase() === task.id)) return [];
|
|
3350
|
+
return covers.replaceAll("", ",").split(/[,\s]+/).filter(Boolean);
|
|
3351
|
+
}
|
|
3352
|
+
var hookContext = (text) => JSON.stringify({
|
|
3353
|
+
hookSpecificOutput: {
|
|
3354
|
+
hookEventName: "PostToolUse",
|
|
3355
|
+
additionalContext: `alterspec-client progress: ${text}`
|
|
3356
|
+
}
|
|
3357
|
+
}) + "\n";
|
|
3300
3358
|
async function hookCwd(input, waitMs = 1e3) {
|
|
3301
3359
|
if (input.isTTY) return void 0;
|
|
3302
3360
|
const text = await new Promise((resolve2) => {
|
|
@@ -3491,7 +3549,11 @@ program.command("progress").description("report the items the task\u2019s commit
|
|
|
3491
3549
|
if (opts.hook) {
|
|
3492
3550
|
setTimeout(() => process.exit(0), 3e4).unref();
|
|
3493
3551
|
const repo = await hookCwd(process.stdin) ?? process.cwd();
|
|
3494
|
-
await progressHook({
|
|
3552
|
+
await progressHook({
|
|
3553
|
+
repo,
|
|
3554
|
+
session: () => sessionOf(loadConfig(repo)),
|
|
3555
|
+
say: (text) => process.stdout.write(text)
|
|
3556
|
+
});
|
|
3495
3557
|
process.exit(0);
|
|
3496
3558
|
}
|
|
3497
3559
|
await run(async () => {
|