@warren-dean/code-kit 0.24.0 → 0.26.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/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +25 -0
- package/README.md +74 -60
- package/bin/code-kit.mjs +188 -3
- package/hooks/act.mjs +96 -0
- package/hooks/guard-bash.mjs +27 -1
- package/hooks/hooks.json +42 -1
- package/hooks/lib/ci.mjs +407 -0
- package/hooks/lib/config.mjs +26 -2
- package/hooks/lib/events.mjs +626 -0
- package/hooks/lib/harness.mjs +8 -0
- package/hooks/lib/instructions.mjs +1 -1
- package/hooks/lib/next.mjs +31 -0
- package/hooks/lib/plan.mjs +17 -2
- package/hooks/lib/publish.mjs +144 -0
- package/hooks/lib/queue.mjs +36 -0
- package/hooks/lib/snapshot.mjs +33 -3
- package/hooks/lib/worktrees.mjs +19 -11
- package/hooks/mod/art.mjs +0 -81
- package/hooks/mod/board.mjs +1743 -0
- package/hooks/mod/characters.mjs +516 -0
- package/hooks/mod/loop.mjs +17 -3
- package/hooks/mod/mission.mjs +2 -93
- package/hooks/mod/panes.mjs +111 -422
- package/hooks/mod/register.mjs +473 -182
- package/hooks/mod/surface/character.mjs +79 -0
- package/hooks/mod/surface/clock.mjs +37 -0
- package/hooks/mod/surface/rail.mjs +33 -0
- package/hooks/mod/view.mjs +30 -602
- package/hooks/session.mjs +14 -11
- package/package.json +2 -1
- package/skills/decide/SKILL.md +1 -1
- package/skills/dispatch/SKILL.md +1 -1
- package/skills/init/SKILL.md +4 -3
- package/skills/next/SKILL.md +1 -1
- package/skills/review/SKILL.md +1 -1
- package/templates/agent.md +1 -1
- package/templates/claude-md.md +3 -1
- package/templates/github-workflow.yml +10 -3
- package/hooks/mod/register.test.ts +0 -4932
package/hooks/lib/next.mjs
CHANGED
|
@@ -14,8 +14,10 @@ import { instructionsState } from './instructions.mjs';
|
|
|
14
14
|
import { SECURITY_AGENT_FILE } from './security.mjs';
|
|
15
15
|
import { laneClaims } from './laneclaims.mjs';
|
|
16
16
|
import { keptBecause, worktrees } from './worktrees.mjs';
|
|
17
|
+
import { ciFindings } from './ci.mjs';
|
|
17
18
|
import { storyModels } from './dispatches.mjs';
|
|
18
19
|
import { pickPerLane } from './schedule.mjs';
|
|
20
|
+
import { reconcileAll } from './events.mjs';
|
|
19
21
|
|
|
20
22
|
export const DRAFT_FILE = '.claude/code-kit.draft.json';
|
|
21
23
|
export const BRIEF_STATES = ['framed', 'explored', 'scoped', 'specified', 'planned', 'ready'];
|
|
@@ -232,6 +234,27 @@ export function nextStep(root, base) {
|
|
|
232
234
|
const from = base(config);
|
|
233
235
|
if (!from)
|
|
234
236
|
attention.push('The base branch has no commits yet, so story branches are read against HEAD.');
|
|
237
|
+
// DUR-4: every act an agent left open when it stopped is checked against git before any work is
|
|
238
|
+
// chosen; what git can't settle, the lead decides before anything else on that story.
|
|
239
|
+
let unsettled = [];
|
|
240
|
+
try {
|
|
241
|
+
const { reconciled, unknowns } = reconcileAll(root, config, { base: from });
|
|
242
|
+
unsettled = unknowns;
|
|
243
|
+
for (const r of reconciled)
|
|
244
|
+
attention.push(
|
|
245
|
+
`${r.story}: an interrupted ${r.kind} was reconciled as ${r.found} (${r.how}).`,
|
|
246
|
+
);
|
|
247
|
+
} catch {
|
|
248
|
+
// an unreadable log: recovery falls back to git, as before
|
|
249
|
+
}
|
|
250
|
+
if (unsettled.length) {
|
|
251
|
+
const stories = [...new Set(unsettled.map((u) => u.story))];
|
|
252
|
+
return result(
|
|
253
|
+
'reconcile',
|
|
254
|
+
`${unsettled.map((u) => `${u.story}'s agent stopped during ${u.kind === 'unrepeatable' ? "a command that can't safely run twice" : `a ${u.kind}`} (\`${u.target}\`), and git can't say whether it ran`).join('; ')}. Find out before anything else on ${stories.length === 1 ? 'that story' : 'those stories'}.`,
|
|
255
|
+
{ args: stories.join(' '), acts: unsettled },
|
|
256
|
+
);
|
|
257
|
+
}
|
|
235
258
|
const status = buildStatus(root, config, from ?? 'HEAD', files);
|
|
236
259
|
if (status.problems.length)
|
|
237
260
|
attention.push(
|
|
@@ -288,6 +311,14 @@ export function nextStep(root, base) {
|
|
|
288
311
|
);
|
|
289
312
|
// ONB-8: code-kit's own instructions to the lead and the lanes, brought up to date before the next step:
|
|
290
313
|
// a newer code-kit's rules reach the agents only through them.
|
|
314
|
+
// CIC-2: what in the project's workflows runs per story, or with no time limit.
|
|
315
|
+
const ci = ciFindings(root, config.branches.protected[0]);
|
|
316
|
+
if (ci.length) {
|
|
317
|
+
const files = [...new Set(ci.map((f) => f.file))];
|
|
318
|
+
attention.push(
|
|
319
|
+
`${ci.length} thing${ci.length === 1 ? '' : 's'} in the project's CI (${files.join(', ')}) ${ci.length === 1 ? 'runs' : 'run'} once per story or without a time limit; \`code-kit ci check\` says what, and the fix for the person to approve.`,
|
|
320
|
+
);
|
|
321
|
+
}
|
|
291
322
|
const instructions = instructionsState(root, config);
|
|
292
323
|
const behind = instructions.filter((f) => ['stale', 'legacy'].includes(f.state));
|
|
293
324
|
// A file with no code-kit part may be one the project keeps without it: said, not insisted on.
|
package/hooks/lib/plan.mjs
CHANGED
|
@@ -51,9 +51,23 @@ const field = (lines, name) =>
|
|
|
51
51
|
.find(Boolean)?.[1]
|
|
52
52
|
.trim() ?? '';
|
|
53
53
|
|
|
54
|
+
/** The first paragraph under a story's `**Field:**` lines, on one line, or null. */
|
|
55
|
+
function summaryOf(body) {
|
|
56
|
+
const start = body.findIndex((l) => l.trim() && !/^\*\*[^*]+:\*\*/.test(l.trim()));
|
|
57
|
+
if (start < 0) return null;
|
|
58
|
+
const end = body.findIndex((l, j) => j > start && !l.trim());
|
|
59
|
+
const text = body
|
|
60
|
+
.slice(start, end < 0 ? undefined : end)
|
|
61
|
+
.join(' ')
|
|
62
|
+
.replace(/\s+/g, ' ')
|
|
63
|
+
.trim();
|
|
64
|
+
return text || null;
|
|
65
|
+
}
|
|
66
|
+
|
|
54
67
|
/**
|
|
55
|
-
* Every story in the plan: [{ id, title, lane, requirements, dependsOn, status, fixes, milestone, slice, size }].
|
|
56
|
-
* milestone is the `## ` heading above it ("Milestone 5: Your own key"), or null
|
|
68
|
+
* Every story in the plan: [{ id, title, lane, requirements, dependsOn, status, fixes, milestone, slice, size, summary }].
|
|
69
|
+
* A story's milestone is the `## ` heading above it ("Milestone 5: Your own key"), or null; its summary the
|
|
70
|
+
* paragraph under its fields, on one line, or null.
|
|
57
71
|
*/
|
|
58
72
|
export function readStories(root, planPath) {
|
|
59
73
|
const stories = [];
|
|
@@ -87,6 +101,7 @@ export function readStories(root, planPath) {
|
|
|
87
101
|
field(body, 'Size')
|
|
88
102
|
.toLowerCase()
|
|
89
103
|
.match(/^(small|medium|large)\b/)?.[1] ?? null,
|
|
104
|
+
summary: summaryOf(body),
|
|
90
105
|
});
|
|
91
106
|
});
|
|
92
107
|
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// What the merge queue merged into the local base, put onto the remote's (spec 09, MQ-6). code-kit
|
|
2
|
+
// merges each story locally, verified; where the base only moves through pull requests (GitHub's branch
|
|
3
|
+
// protection), pushing it is refused, so the merged work goes up as a pull request of its own instead of
|
|
4
|
+
// through an integration branch an agent invents. `branches.publish` says which: `push` or `pull-request`.
|
|
5
|
+
import { spawnSync } from 'node:child_process';
|
|
6
|
+
|
|
7
|
+
/** The branch a pull request publishes the base from: code-kit's own, short-lived. */
|
|
8
|
+
export const publishBranch = (base) => `code-kit/publish-${base}`;
|
|
9
|
+
|
|
10
|
+
/** The stories merged into `base` and not yet on the remote's, from the queue's merge commits. */
|
|
11
|
+
export function unpublished(root, base) {
|
|
12
|
+
const run = spawnSync(
|
|
13
|
+
'git',
|
|
14
|
+
['-C', root, 'log', '--first-parent', '--format=%s', `origin/${base}..${base}`],
|
|
15
|
+
{ encoding: 'utf8' },
|
|
16
|
+
);
|
|
17
|
+
if (run.status !== 0) return [];
|
|
18
|
+
return run.stdout
|
|
19
|
+
.split('\n')
|
|
20
|
+
.map((s) => s.match(/^Merge (\S+) into /)?.[1])
|
|
21
|
+
.filter(Boolean)
|
|
22
|
+
.reverse();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** A pull request's title for the branches it publishes. */
|
|
26
|
+
export function publishTitle(branches, count) {
|
|
27
|
+
const stories = branches.map((b) => b.split('/').at(-1).toUpperCase());
|
|
28
|
+
if (!stories.length) return `${count} commit${count === 1 ? '' : 's'} from code-kit`;
|
|
29
|
+
if (stories.length === 1) return `${stories[0]} from the code-kit queue`;
|
|
30
|
+
if (stories.length <= 3)
|
|
31
|
+
return `${stories.slice(0, -1).join(', ')} and ${stories.at(-1)} from the code-kit queue`;
|
|
32
|
+
return `${stories.slice(0, 2).join(', ')} and ${stories.length - 2} more from the code-kit queue`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Puts the local `base`'s merges onto `origin`. `mode` is `push` or `pull-request`; `mayMove` is whether
|
|
37
|
+
* the caller may move the remote's base (the person, or the lead with `approvals.delegate.push`): without
|
|
38
|
+
* it a push isn't made and a pull request is opened but left for the person. `run(cmd, args)` runs git
|
|
39
|
+
* and gh (spawnSync by default, so tests can stand in for GitHub). Returns { state, message, url? }:
|
|
40
|
+
* `current` (nothing to publish), `pushed`, `merged`, `waiting` (for the person, or for GitHub) or
|
|
41
|
+
* `failed`. It never force-pushes, and never moves the local base except to fast-forward it.
|
|
42
|
+
*/
|
|
43
|
+
export function publishBase(root, base, { mode, mayMove, run = defaultRun }) {
|
|
44
|
+
const git = (...a) => run('git', ['-C', root, ...a]);
|
|
45
|
+
const gh = (...a) => run('gh', a);
|
|
46
|
+
const first = (r) =>
|
|
47
|
+
String(r.stderr || r.stdout || '')
|
|
48
|
+
.trim()
|
|
49
|
+
.split('\n')[0];
|
|
50
|
+
if (git('remote', 'get-url', 'origin').status !== 0)
|
|
51
|
+
return { state: 'failed', message: `There's no remote named origin to publish ${base} to.` };
|
|
52
|
+
git('fetch', '--quiet', 'origin', base);
|
|
53
|
+
const remote = `origin/${base}`;
|
|
54
|
+
if (git('rev-parse', '--verify', '--quiet', remote).status !== 0)
|
|
55
|
+
return {
|
|
56
|
+
state: 'failed',
|
|
57
|
+
message: `origin has no ${base} yet. Push it once yourself (\`git push -u origin ${base}\`); code-kit publishes merges onto it from then on.`,
|
|
58
|
+
};
|
|
59
|
+
const ahead = Number(git('rev-list', '--count', `${remote}..${base}`).stdout.trim() || 0);
|
|
60
|
+
if (!ahead) return { state: 'current', message: `${base} is already on origin.` };
|
|
61
|
+
const branches = unpublished(root, base);
|
|
62
|
+
const what = branches.length
|
|
63
|
+
? `${branches.length} merge${branches.length === 1 ? '' : 's'} (${branches.join(', ')})`
|
|
64
|
+
: `${ahead} commit${ahead === 1 ? '' : 's'}`;
|
|
65
|
+
|
|
66
|
+
if (mode === 'push') {
|
|
67
|
+
if (!mayMove)
|
|
68
|
+
return {
|
|
69
|
+
state: 'waiting',
|
|
70
|
+
message: `${what} on ${base} aren't on origin yet. Pushing ${base} is the person's, unless they delegate it ("approvals.delegate.push": true, committed on ${base}).`,
|
|
71
|
+
};
|
|
72
|
+
const pushed = git('push', '--quiet', 'origin', `${base}:refs/heads/${base}`);
|
|
73
|
+
if (pushed.status !== 0)
|
|
74
|
+
return {
|
|
75
|
+
state: 'failed',
|
|
76
|
+
message: `Pushing ${base} was refused: ${first(pushed)}${/protected|GH006|pull request/i.test(`${pushed.stderr}`) ? `\norigin requires a pull request to change ${base}: set "branches.publish": "pull-request" in the config.` : ''}`,
|
|
77
|
+
};
|
|
78
|
+
return { state: 'pushed', message: `Pushed ${base} to origin with ${what}.` };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// A pull request from code-kit's own branch, which holds exactly the base's head.
|
|
82
|
+
const head = publishBranch(base);
|
|
83
|
+
const pushed = git('push', '--quiet', 'origin', `${base}:refs/heads/${head}`);
|
|
84
|
+
if (pushed.status !== 0)
|
|
85
|
+
return {
|
|
86
|
+
state: 'failed',
|
|
87
|
+
message: `Pushing ${base} to ${head} for its pull request was refused: ${first(pushed)}`,
|
|
88
|
+
};
|
|
89
|
+
const open = gh(
|
|
90
|
+
...['pr', 'list', '--head', head, '--base', base, '--state', 'open'],
|
|
91
|
+
...['--json', 'url', '--jq', '.[0].url'],
|
|
92
|
+
);
|
|
93
|
+
let url = open.status === 0 ? open.stdout.trim() : '';
|
|
94
|
+
if (!url) {
|
|
95
|
+
const body = [
|
|
96
|
+
`Merged into ${base} by \`code-kit merge\`, each verified against ${base} first:`,
|
|
97
|
+
'',
|
|
98
|
+
...(branches.length ? branches.map((b) => `- ${b}`) : [`- ${what}`]),
|
|
99
|
+
'',
|
|
100
|
+
'Each merge commit says what was verified, and any checks not run.',
|
|
101
|
+
].join('\n');
|
|
102
|
+
const made = gh(
|
|
103
|
+
...['pr', 'create', '--base', base, '--head', head],
|
|
104
|
+
...['--title', publishTitle(branches, ahead), '--body', body],
|
|
105
|
+
);
|
|
106
|
+
if (made.status !== 0)
|
|
107
|
+
return { state: 'failed', message: `Opening the pull request failed: ${first(made)}` };
|
|
108
|
+
url = made.stdout.trim().split('\n').at(-1);
|
|
109
|
+
}
|
|
110
|
+
if (!mayMove)
|
|
111
|
+
return {
|
|
112
|
+
state: 'waiting',
|
|
113
|
+
url,
|
|
114
|
+
message: `${what} wait to reach origin in ${url}. Merging it is the person's, unless they delegate pushing ${base} ("approvals.delegate.push": true, committed on ${base}).`,
|
|
115
|
+
};
|
|
116
|
+
const merged = gh('pr', 'merge', url, '--merge');
|
|
117
|
+
if (merged.status !== 0)
|
|
118
|
+
return {
|
|
119
|
+
state: 'waiting',
|
|
120
|
+
url,
|
|
121
|
+
message: `${what} wait in ${url}: GitHub didn't merge it (${first(merged)}). It merges once GitHub allows it; run \`code-kit publish\` again then.`,
|
|
122
|
+
};
|
|
123
|
+
git('push', '--quiet', 'origin', '--delete', head);
|
|
124
|
+
// The local base catches up with the merge GitHub made, so the next pull request holds only what's new.
|
|
125
|
+
git('fetch', '--quiet', 'origin', base);
|
|
126
|
+
const where = git('worktree', 'list', '--porcelain')
|
|
127
|
+
.stdout.split('\n\n')
|
|
128
|
+
.find((w) => w.includes(`\nbranch refs/heads/${base}`))
|
|
129
|
+
?.match(/^worktree (.+)$/m)?.[1];
|
|
130
|
+
const caught = where
|
|
131
|
+
? run('git', ['-C', where, 'merge', '--quiet', '--ff-only', remote])
|
|
132
|
+
: git('merge-base', '--is-ancestor', base, remote).status === 0
|
|
133
|
+
? git('update-ref', `refs/heads/${base}`, remote)
|
|
134
|
+
: { status: 1 };
|
|
135
|
+
return {
|
|
136
|
+
state: 'merged',
|
|
137
|
+
url,
|
|
138
|
+
message: `Published ${what} to origin's ${base} through ${url}.${caught.status === 0 ? '' : ` The local ${base} couldn't fast-forward to origin's; pull it when it's free.`}`,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function defaultRun(cmd, args) {
|
|
143
|
+
return spawnSync(cmd, args, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] });
|
|
144
|
+
}
|
package/hooks/lib/queue.mjs
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
5
5
|
import { dirname, join } from 'node:path';
|
|
6
6
|
import { projectWorktrees } from './rules.mjs';
|
|
7
|
+
import { GIT, commandsOf } from './shell.mjs';
|
|
8
|
+
import { storyOfBranch } from './teamfacts.mjs';
|
|
7
9
|
|
|
8
10
|
export const QUEUE_FILE = '.claude/state/merge-queue.json';
|
|
9
11
|
/** Merged and sent-back entries kept for the pane, newest last. */
|
|
@@ -92,3 +94,37 @@ export function settle(root, branch, state, reason = null, now = Date.now()) {
|
|
|
92
94
|
export function lastMerged(entries) {
|
|
93
95
|
return [...entries].reverse().find((e) => e.state === 'merged')?.branch ?? null;
|
|
94
96
|
}
|
|
97
|
+
|
|
98
|
+
/** A ref as a local branch's name: `origin/web/st-4` → `web/st-4`; others as they are. */
|
|
99
|
+
const local = (ref) => ref.replace(/^[\w.-]+\/(?=[^/]+\/[^/]+$)/, '');
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* MQ-5: the story branches `cmd` merges with git, each with the branch it lands on: the one a
|
|
103
|
+
* `git switch` or `git checkout` earlier in the command moves to, else `branch`, the one checked out.
|
|
104
|
+
* [{ story: 'web/st-4', into: 'lead/next' }].
|
|
105
|
+
*/
|
|
106
|
+
export function storyMerges(cmd, branch) {
|
|
107
|
+
const found = [];
|
|
108
|
+
let on = branch;
|
|
109
|
+
const switches = new RegExp(
|
|
110
|
+
String.raw`^${GIT}(?:switch|checkout)\s+((?:-\S+\s+)*)([^\s-]\S*)\s*$`,
|
|
111
|
+
);
|
|
112
|
+
const merges = new RegExp(String.raw`^${GIT}merge\b(.*)$`);
|
|
113
|
+
for (const { text, code } of commandsOf(cmd)) {
|
|
114
|
+
const moved = code.match(switches);
|
|
115
|
+
if (moved) {
|
|
116
|
+
on = moved[2];
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const merged = code.match(merges);
|
|
120
|
+
if (!merged) continue;
|
|
121
|
+
// Its words as written, found in the masked code, so quoted text (a message) never reads as a branch.
|
|
122
|
+
const from = code.length - merged[1].length;
|
|
123
|
+
for (const w of merged[1].matchAll(/\S+/g)) {
|
|
124
|
+
if (w[0].startsWith('-') || /["']/.test(w[0])) continue;
|
|
125
|
+
const ref = local(text.slice(from + w.index, from + w.index + w[0].length));
|
|
126
|
+
if (storyOfBranch(ref)) found.push({ story: ref, into: on });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return found;
|
|
130
|
+
}
|
package/hooks/lib/snapshot.mjs
CHANGED
|
@@ -26,8 +26,11 @@ import {
|
|
|
26
26
|
|
|
27
27
|
import { slicesOf } from './schedule.mjs';
|
|
28
28
|
|
|
29
|
-
/**
|
|
30
|
-
|
|
29
|
+
/**
|
|
30
|
+
* 2 adds the project's standards (code-kit spec 22); 3 the plan's slices (spec 23, SCHED-2); 4 each
|
|
31
|
+
* story's summary and each requirement's title.
|
|
32
|
+
*/
|
|
33
|
+
export const SNAPSHOT_VERSION = 4;
|
|
31
34
|
|
|
32
35
|
/** A story's stage, as a report names it. */
|
|
33
36
|
export const STAGES = [
|
|
@@ -45,7 +48,8 @@ export const AGENT_KINDS = ['lead', 'lane', 'reviewer', 'security-reviewer', 'ba
|
|
|
45
48
|
/**
|
|
46
49
|
* The allow-list. A leaf is a kind: `id` (ST-4, API-2), `handle` (a GitHub login), `name` (a lane, a
|
|
47
50
|
* layer, a milestone, an approval: one line, at most 120 characters), `title` (one line, at most 200),
|
|
48
|
-
* `line` (a send-back's reason: one line, at most 200), `
|
|
51
|
+
* `line` (a send-back's reason: one line, at most 200), `summary` (a story's summary: one line, at most
|
|
52
|
+
* 600), `path` (a file path or glob: one line, at most
|
|
49
53
|
* 300), `ms` (a time in milliseconds), `date` (YYYY-MM-DD), `count` (a whole number, 0 or more),
|
|
50
54
|
* `bool`, `enum:a|b`. A trailing `?` allows null. An array holds one shape; an object holds only the
|
|
51
55
|
* keys it lists.
|
|
@@ -73,12 +77,16 @@ export const SNAPSHOT_SCHEMA = {
|
|
|
73
77
|
merged: 'ms?',
|
|
74
78
|
},
|
|
75
79
|
claimedBy: 'handle?',
|
|
80
|
+
// Added in version 4.
|
|
81
|
+
summary: 'summary?',
|
|
76
82
|
},
|
|
77
83
|
],
|
|
78
84
|
sendBacks: [{ story: 'id', at: 'ms', reason: 'line?' }],
|
|
79
85
|
requirements: [
|
|
80
86
|
{
|
|
81
87
|
id: 'id',
|
|
88
|
+
// Added in version 4.
|
|
89
|
+
title: 'title?',
|
|
82
90
|
stories: ['id'],
|
|
83
91
|
built: ['path'],
|
|
84
92
|
tested: ['path'],
|
|
@@ -123,6 +131,25 @@ export const SNAPSHOT_SCHEMA = {
|
|
|
123
131
|
/** Parts a report from an older code-kit doesn't have yet: valid when missing, checked when there. */
|
|
124
132
|
export const LATER_PARTS = ['standards', 'slices'];
|
|
125
133
|
|
|
134
|
+
export const SUMMARY_MAX = 600;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* A story's summary as a report holds it: on one line, and when longer than 600 characters, cut after
|
|
138
|
+
* the last sentence that fits (or, with no sentence ending in reach, at the last word, with an ellipsis).
|
|
139
|
+
*/
|
|
140
|
+
export function reportedSummary(text) {
|
|
141
|
+
const s = String(text ?? '')
|
|
142
|
+
.replace(/\s+/g, ' ')
|
|
143
|
+
.trim();
|
|
144
|
+
if (!s) return null;
|
|
145
|
+
if (s.length <= SUMMARY_MAX) return s;
|
|
146
|
+
const head = s.slice(0, SUMMARY_MAX + 1);
|
|
147
|
+
const ends = [...head.matchAll(/[.!?](?=\s)/g)].map((m) => m.index + 1);
|
|
148
|
+
if (ends.length) return s.slice(0, ends.at(-1));
|
|
149
|
+
const word = s.slice(0, SUMMARY_MAX).lastIndexOf(' ');
|
|
150
|
+
return `${s.slice(0, word > 0 ? word : SUMMARY_MAX - 1).trimEnd()}…`;
|
|
151
|
+
}
|
|
152
|
+
|
|
126
153
|
const ONE_LINE = (max) => (v) => typeof v === 'string' && v.length <= max && !/[\r\n]/.test(v);
|
|
127
154
|
const KINDS = {
|
|
128
155
|
id: (v) => typeof v === 'string' && /^[A-Za-z][A-Za-z0-9]*-\d+$/.test(v),
|
|
@@ -130,6 +157,7 @@ const KINDS = {
|
|
|
130
157
|
name: ONE_LINE(120),
|
|
131
158
|
title: ONE_LINE(200),
|
|
132
159
|
line: ONE_LINE(200),
|
|
160
|
+
summary: ONE_LINE(SUMMARY_MAX),
|
|
133
161
|
path: ONE_LINE(300),
|
|
134
162
|
ms: (v) => Number.isInteger(v) && v > 0,
|
|
135
163
|
date: (v) => typeof v === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(v),
|
|
@@ -303,6 +331,7 @@ export function buildSnapshot({
|
|
|
303
331
|
merged: ms(t.merged),
|
|
304
332
|
},
|
|
305
333
|
claimedBy: claimed.get(s.id) ?? null,
|
|
334
|
+
summary: reportedSummary(s.summary),
|
|
306
335
|
};
|
|
307
336
|
});
|
|
308
337
|
|
|
@@ -329,6 +358,7 @@ export function buildSnapshot({
|
|
|
329
358
|
if (CHECKS.includes(row.status)) checks.set(row.requirement, row.status);
|
|
330
359
|
const requirements = trail(root, status, base).map((r) => ({
|
|
331
360
|
id: r.id,
|
|
361
|
+
title: line(r.title),
|
|
332
362
|
stories: r.stories.map((s) => s.id),
|
|
333
363
|
built: r.files.filter((f) => KINDS.path(f)),
|
|
334
364
|
tested: r.tests.filter((f) => KINDS.path(f)),
|
package/hooks/lib/worktrees.mjs
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
} from 'node:fs';
|
|
20
20
|
import { tmpdir } from 'node:os';
|
|
21
21
|
import { basename, dirname, join } from 'node:path';
|
|
22
|
+
import { pruneLogs } from './events.mjs';
|
|
22
23
|
import { laneClaims } from './laneclaims.mjs';
|
|
23
24
|
import { storyOfBranch } from './teamfacts.mjs';
|
|
24
25
|
|
|
@@ -45,14 +46,16 @@ const alive = (pid) => {
|
|
|
45
46
|
}
|
|
46
47
|
};
|
|
47
48
|
|
|
48
|
-
/**
|
|
49
|
-
|
|
49
|
+
/**
|
|
50
|
+
* The base branch's refs a worktree's branch is merged into: the first protected branch here and on its
|
|
51
|
+
* remote, each that exists. A local base can fall weeks behind the remote's where the base only moves
|
|
52
|
+
* through pull requests, so a branch merged into either counts as merged.
|
|
53
|
+
*/
|
|
54
|
+
export function baseRefs(root, config) {
|
|
50
55
|
const name = config.branches?.protected?.[0];
|
|
51
|
-
if (!name) return
|
|
52
|
-
return (
|
|
53
|
-
|
|
54
|
-
(r) => git(root, 'rev-parse', '--verify', '--quiet', r).status === 0,
|
|
55
|
-
) ?? null
|
|
56
|
+
if (!name) return [];
|
|
57
|
+
return [name, `origin/${name}`].filter(
|
|
58
|
+
(r) => git(root, 'rev-parse', '--verify', '--quiet', r).status === 0,
|
|
56
59
|
);
|
|
57
60
|
}
|
|
58
61
|
|
|
@@ -80,7 +83,7 @@ export function worktrees(root, config, now = Date.now()) {
|
|
|
80
83
|
if (list.status !== 0) return [];
|
|
81
84
|
const main = list.stdout.split('\n\n')[0];
|
|
82
85
|
const mainPath = /^worktree (.+)$/m.exec(main)?.[1] ?? root;
|
|
83
|
-
const from =
|
|
86
|
+
const from = baseRefs(root, config);
|
|
84
87
|
const claims = laneClaims(mainPath, now).filter((c) => !c.stale);
|
|
85
88
|
const agents = real(join(mainPath, WORKTREES_DIR));
|
|
86
89
|
const temp = real(tmpdir());
|
|
@@ -103,9 +106,11 @@ export function worktrees(root, config, now = Date.now()) {
|
|
|
103
106
|
const story = branch ? storyOfBranch(branch) : null;
|
|
104
107
|
const merged = Boolean(
|
|
105
108
|
branch &&
|
|
106
|
-
from
|
|
107
|
-
|
|
108
|
-
|
|
109
|
+
from.some(
|
|
110
|
+
(ref) =>
|
|
111
|
+
spawnSync('git', ['merge-base', '--is-ancestor', branch, ref], { cwd: root }).status ===
|
|
112
|
+
0,
|
|
113
|
+
) &&
|
|
109
114
|
hasOwnCommits(root, branch),
|
|
110
115
|
);
|
|
111
116
|
// Read only where it decides anything: an unmerged worktree stays whatever it holds.
|
|
@@ -246,6 +251,9 @@ export function pruneWorktrees(root, config, now = Date.now()) {
|
|
|
246
251
|
rmSync(p, { recursive: true, force: true });
|
|
247
252
|
removed.push(`${p.slice(root.length + 1)} (left behind, not a worktree)`);
|
|
248
253
|
}
|
|
254
|
+
// DUR-6: the event logs of stories merged more than 30 days ago go with them.
|
|
255
|
+
for (const base of baseRefs(root, config))
|
|
256
|
+
for (const story of pruneLogs(root, { base, now })) removed.push(`${story}'s event log`);
|
|
249
257
|
return { removed, kept };
|
|
250
258
|
}
|
|
251
259
|
|
package/hooks/mod/art.mjs
CHANGED
|
@@ -5,49 +5,6 @@
|
|
|
5
5
|
|
|
6
6
|
// --- the characters (VIEW-3) ---------------------------------------------------------------------
|
|
7
7
|
|
|
8
|
-
/** Each pose, 6 by 6 pixels: H the lane's tint, E eyes, X stalled eyes, L closed eyes, C a crown. */
|
|
9
|
-
const POSES = {
|
|
10
|
-
working: [
|
|
11
|
-
['..HH..', '.HEEH.', '..HH..', '.HHHH.', 'H.HH.H', '.H..H.'],
|
|
12
|
-
['..HH..', '.HEEH.', '..HH..', 'HHHHHH', '..HH..', '..HH..'],
|
|
13
|
-
],
|
|
14
|
-
waiting: [['..HH.H', '.HEEHH', '..HH..', '.HHH..', '..HH..', '.H..H.']],
|
|
15
|
-
quiet: [['......', '..HH..', '.HLLH.', '..HH..', '.HHHH.', '.H..H.']],
|
|
16
|
-
stalled: [['..HH..', '.HXXH.', '..HH..', '.HHHH.', '..HH..', '.H..H.']],
|
|
17
|
-
done: [['H.HH.H', 'HHEEHH', '..HH..', '..HH..', '..HH..', '.H..H.']],
|
|
18
|
-
idle: [['......', '..HH..', '.HLLH.', '..HH..', '.HHHH.', '.H..H.']],
|
|
19
|
-
};
|
|
20
|
-
/** What a pose reads as without its picture, and in words. */
|
|
21
|
-
export const POSE_GLYPH = {
|
|
22
|
-
working: '⚙',
|
|
23
|
-
waiting: '?',
|
|
24
|
-
quiet: '…',
|
|
25
|
-
stalled: '✗',
|
|
26
|
-
done: '✓',
|
|
27
|
-
idle: '·',
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/** Each lane's tint, fixed by its place in the config so the person learns them; the lead's is gold. */
|
|
31
|
-
const TINTS = [0x4aa3ff, 0x5cc85c, 0xd070e0, 0x40c8c8, 0xff9a40, 0xff6070, 0xa0a0ff];
|
|
32
|
-
export function tintOf(lane, lanes) {
|
|
33
|
-
if (lane === 'lead') return 0xd8a840;
|
|
34
|
-
const i = lanes.filter((l) => l !== 'lead').indexOf(lane);
|
|
35
|
-
return TINTS[(i < 0 ? 0 : i) % TINTS.length];
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const dim = (rgb) =>
|
|
39
|
-
(((rgb >> 16) & 0xff) >> 1) * 0x10000 + (((rgb >> 8) & 0xff) >> 1) * 0x100 + ((rgb & 0xff) >> 1);
|
|
40
|
-
|
|
41
|
-
/** The pose's frame as a grid of colours (null for none), the lead crowned. */
|
|
42
|
-
export function sprite(pose, frame, tint, { lead = false } = {}) {
|
|
43
|
-
const frames = POSES[pose] ?? POSES.idle;
|
|
44
|
-
const rows = frames[frame % frames.length].map((r) => [...r]);
|
|
45
|
-
if (lead) rows[0] = [...'C.CC.C'];
|
|
46
|
-
const body = pose === 'quiet' || pose === 'idle' ? dim(tint) : tint;
|
|
47
|
-
const colour = { H: body, E: 0x202020, X: 0xff3030, L: 0x707070, C: 0xffcc00 };
|
|
48
|
-
return rows.map((r) => r.map((c) => colour[c] ?? null));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
8
|
const DEFAULT = 0x01000000;
|
|
52
9
|
const B64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
53
10
|
function base64(bytes) {
|
|
@@ -84,44 +41,6 @@ export function rasterCells(grid) {
|
|
|
84
41
|
|
|
85
42
|
const hex = (rgb) => `#${rgb.toString(16).padStart(6, '0')}`;
|
|
86
43
|
|
|
87
|
-
/** A sprite as SVG for Desktop, the working pose's frames alternating (SMIL), 4 px a pixel. */
|
|
88
|
-
export function spriteSvg(pose, tint, { lead = false } = {}) {
|
|
89
|
-
const frames = (POSES[pose] ?? POSES.idle).map((_, f) => sprite(pose, f, tint, { lead }));
|
|
90
|
-
const rects = (grid) =>
|
|
91
|
-
grid
|
|
92
|
-
.flatMap((row, y) =>
|
|
93
|
-
row.map((c, x) =>
|
|
94
|
-
c === null
|
|
95
|
-
? ''
|
|
96
|
-
: `<rect x="${x * 4}" y="${y * 4}" width="4" height="4" fill="${hex(c)}"/>`,
|
|
97
|
-
),
|
|
98
|
-
)
|
|
99
|
-
.join('');
|
|
100
|
-
const groups = frames.map((g, f) =>
|
|
101
|
-
frames.length > 1
|
|
102
|
-
? `<g visibility="${f ? 'hidden' : 'visible'}"><animate attributeName="visibility" values="${f ? 'hidden;visible' : 'visible;hidden'}" dur="0.8s" repeatCount="indefinite" calcMode="discrete"/>${rects(g)}</g>`
|
|
103
|
-
: `<g>${rects(g)}</g>`,
|
|
104
|
-
);
|
|
105
|
-
return `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" shape-rendering="crispEdges">${groups.join('')}</svg>`;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* A lane's pose (VIEW-3): stalled when flagged or quiet past the restart time, waiting while a call
|
|
110
|
-
* of its is held, its request is open or its story waits on the person's answer, working while its agent is at work, quiet when it has
|
|
111
|
-
* gone quiet, done once its branch is finished, idle otherwise.
|
|
112
|
-
*/
|
|
113
|
-
export function poseOf(
|
|
114
|
-
lane,
|
|
115
|
-
{ live = null, waiting = false, flagged = false, shown = lane.state } = {},
|
|
116
|
-
) {
|
|
117
|
-
if (flagged || live?.level === 'stalled') return 'stalled';
|
|
118
|
-
if (waiting || shown === 'waiting on you') return 'waiting';
|
|
119
|
-
if (live?.level === 'quiet') return 'quiet';
|
|
120
|
-
if (lane.active) return 'working';
|
|
121
|
-
if (['in review', 'queued'].includes(shown)) return 'done';
|
|
122
|
-
return 'idle';
|
|
123
|
-
}
|
|
124
|
-
|
|
125
44
|
// --- the timelines (VIEW-2) ----------------------------------------------------------------------
|
|
126
45
|
|
|
127
46
|
/** Each cell kind's glyph and colour: the glyph alone reads in a terminal without colour. */
|