@warren-dean/code-kit 0.26.0 → 0.26.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.
@@ -9,7 +9,7 @@
9
9
  "name": "code-kit",
10
10
  "source": "./",
11
11
  "description": "Keeps AI coding agents inside your project's rules, from idea to merged code: spec design, lanes, layer rules, protected paths with an approval log, spec-check and design gates, proof-before-finish checks, dispatch, review, build status and CI verification, configured per project from its docs",
12
- "version": "0.26.0",
12
+ "version": "0.26.1",
13
13
  "category": "development",
14
14
  "tags": ["guardrails", "architecture", "lanes", "layers", "spec-driven", "ci", "multi-agent"],
15
15
  "license": "MIT"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "code-kit",
3
- "version": "0.26.0",
3
+ "version": "0.26.1",
4
4
  "description": "Keeps AI coding agents inside your project's rules, from idea to merged code: spec design, lanes, layer rules, protected paths with an approval log, spec-check and design gates, proof-before-finish checks, dispatch, review, build status and CI verification, configured per project from its docs",
5
5
  "author": {
6
6
  "name": "Warren Langeveldt"
package/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  What changed in each release of code-kit, newest first. Versions follow the plugin manifest and the npm package `@warren-dean/code-kit`. Each release is also on [GitHub Releases](https://github.com/warrendeanlangeveldt/code-kit/releases).
4
4
 
5
+ ## 0.26.1 (2026-10-26)
6
+
7
+ `/lanes` opens in large projects again.
8
+
9
+ - In a project with hundreds of stories, `/lanes` failed to open: reading the project's state made a git call or more per story, and took longer than the 30 seconds Claude Code gives a mod's command. `code-kit status`, `timeline`, `journal` and `trail` now read every branch in a few git calls, and answer in a couple of seconds however many stories there are.
10
+ - A read that doesn't answer in time no longer stops the pane opening: the pane shows everything else.
11
+ - A story's start on the lanes' timelines is now when its branch was made, not the time of the commit it branched from.
12
+
5
13
  ## 0.26.0 (2026-10-26)
6
14
 
7
15
  The lanes pane is redesigned around what needs you, a lane's work survives its agent stopping, and merged work reaches the remote.
@@ -161,11 +161,28 @@ const git = (root, ...args) => {
161
161
  }
162
162
  };
163
163
 
164
+ /**
165
+ * Every local and origin branch in one read: { ref: { sha, ahead } }, `ahead` the commits it has that
166
+ * `base` hasn't. A project with hundreds of stories has hundreds of branches, and a git call each
167
+ * outlasts the mod's 30 seconds. Git before 2.41 can't count them in the same read: `ahead` is then
168
+ * null, and counted for each branch as it's asked for.
169
+ */
170
+ export function branchRefs(root, base) {
171
+ const read = (format) =>
172
+ git(root, 'for-each-ref', `--format=${format}`, 'refs/heads', 'refs/remotes/origin');
173
+ const counted = read(`%(refname)%09%(objectname)%09%(ahead-behind:${base})`);
174
+ const out = counted ?? read('%(refname)%09%(objectname)') ?? '';
175
+ const refs = {};
176
+ for (const line of out.split('\n').filter(Boolean)) {
177
+ const [ref, sha, aheadBehind] = line.split('\t');
178
+ refs[ref] = { sha, ahead: counted === null ? null : Number(aheadBehind.split(' ')[0]) };
179
+ }
180
+ return refs;
181
+ }
182
+
164
183
  /** The ref of a branch, local first, then on origin; null when neither exists. */
165
- function branchRef(root, branch) {
166
- for (const ref of [`refs/heads/${branch}`, `refs/remotes/origin/${branch}`])
167
- if (git(root, 'rev-parse', '--verify', '--quiet', ref) !== null) return ref;
168
- return null;
184
+ function branchRef(refs, branch) {
185
+ return [`refs/heads/${branch}`, `refs/remotes/origin/${branch}`].find((r) => refs[r]) ?? null;
169
186
  }
170
187
 
171
188
  /** Worktree path of each checked-out branch: { branch: path }. */
@@ -193,13 +210,16 @@ function worktrees(root) {
193
210
  export function storyStates(root, stories, base) {
194
211
  const trees = worktrees(root);
195
212
  const backs = sentBack(root);
213
+ const refs = branchRefs(root, base);
196
214
  const states = stories.map((story) => {
197
215
  const branch = storyBranch(story);
198
- const ref = story.lane ? branchRef(root, branch) : null;
199
- const ahead = ref ? Number(git(root, 'rev-list', '--count', `${base}..${ref}`) ?? 0) : 0;
216
+ const ref = story.lane ? branchRef(refs, branch) : null;
217
+ const ahead = !ref
218
+ ? 0
219
+ : (refs[ref].ahead ?? Number(git(root, 'rev-list', '--count', `${base}..${ref}`) ?? 0));
200
220
  let state = story.status;
201
221
  if (ref && story.status !== 'done') {
202
- const head = backs[branch] ? git(root, 'rev-parse', ref) : null;
222
+ const head = backs[branch] ? refs[ref].sha : null;
203
223
  if (head && head === backs[branch].sha) state = 'sent back';
204
224
  else if (ahead > 0) state = 'review';
205
225
  else state = story.status === 'review' ? 'done' : 'in progress';
@@ -208,6 +228,7 @@ export function storyStates(root, stories, base) {
208
228
  ...story,
209
229
  branch,
210
230
  branchExists: Boolean(ref),
231
+ ref,
211
232
  ahead,
212
233
  worktree: trees[branch] ?? null,
213
234
  state,
@@ -12,7 +12,7 @@ const git = (root, ...args) => {
12
12
  return execFileSync('git', ['-C', root, ...args], {
13
13
  encoding: 'utf8',
14
14
  stdio: ['ignore', 'pipe', 'ignore'],
15
- maxBuffer: 64 * 1024 * 1024,
15
+ maxBuffer: 256 * 1024 * 1024,
16
16
  });
17
17
  } catch {
18
18
  return '';
@@ -23,28 +23,64 @@ const git = (root, ...args) => {
23
23
  const KIT = /^(\.claude|\.ctx|\.github)\//;
24
24
  const isCode = (rel) => CODE.test(rel) && !KIT.test(rel);
25
25
 
26
+ /**
27
+ * Every story's files from one pass over the history: { id: Set of files }, from the commits on any
28
+ * branch whose message names it, as `storyFiles` finds them one story at a time. A project with hundreds
29
+ * of stories outlasts the mod's 30 seconds with a `git log --all` each.
30
+ */
31
+ export function namedFiles(root) {
32
+ const byStory = {};
33
+ const log = git(root, 'log', '--all', '--no-merges', '--format=%x1e%B%x1f', '--name-only');
34
+ for (const commit of log.split('\x1e')) {
35
+ const end = commit.indexOf('\x1f');
36
+ if (end < 0) continue;
37
+ // As storyFiles' grep: "ST-1" mustn't match "ST-12", nor "XST-1".
38
+ const ids = new Set(
39
+ [...commit.slice(0, end).matchAll(/(?:^|[^A-Za-z0-9-])(ST-\d+)(?!\d)/gm)].map((m) => m[1]),
40
+ );
41
+ if (!ids.size) continue;
42
+ const files = commit
43
+ .slice(end + 1)
44
+ .split('\n')
45
+ .filter(Boolean);
46
+ for (const id of ids) {
47
+ byStory[id] ??= new Set();
48
+ for (const f of files) byStory[id].add(f);
49
+ }
50
+ }
51
+ return byStory;
52
+ }
53
+
26
54
  /**
27
55
  * The code files a story changed: those in commits whose message names it (on any branch, so a merged
28
56
  * story still has its files) and, while its branch is open, its diff against the base. Only files that
29
- * still exist, in path order.
57
+ * still exist, in path order. `named` is `namedFiles`', where the caller reads every story.
30
58
  */
31
- export function storyFiles(root, story, from) {
59
+ export function storyFiles(root, story, from, named = null) {
32
60
  const found = new Set();
33
61
  const id = story.id;
34
- const log = git(
35
- root,
36
- 'log',
37
- '--all',
38
- '--no-merges',
39
- '-E',
40
- // POSIX ERE has no \b: "ST-1" mustn't match "ST-12".
41
- `--grep=(^|[^A-Za-z0-9-])${id}([^0-9]|$)`,
42
- '--format=',
43
- '--name-only',
44
- );
62
+ const log = named
63
+ ? [...(named[id] ?? [])].join('\n')
64
+ : git(
65
+ root,
66
+ 'log',
67
+ '--all',
68
+ '--no-merges',
69
+ '-E',
70
+ // POSIX ERE has no \b: "ST-1" mustn't match "ST-12".
71
+ `--grep=(^|[^A-Za-z0-9-])${id}([^0-9]|$)`,
72
+ '--format=',
73
+ '--name-only',
74
+ );
45
75
  for (const f of log.split('\n')) if (f) found.add(f);
46
- if (story.branchExists && story.branch)
47
- for (const f of git(root, 'diff', '--name-only', `${from}...${story.branch}`).split('\n'))
76
+ // A branch the base already holds has nothing of its own to diff.
77
+ if (story.branchExists && story.branch && story.ahead !== 0)
78
+ for (const f of git(
79
+ root,
80
+ 'diff',
81
+ '--name-only',
82
+ `${from}...${story.ref ?? story.branch}`,
83
+ ).split('\n'))
48
84
  if (f) found.add(f);
49
85
  return [...found].filter((f) => isCode(f) && existsSync(join(root, f))).sort();
50
86
  }
@@ -133,8 +169,9 @@ export function storyMap(root, story, config, from) {
133
169
  */
134
170
  export function trail(root, status, from) {
135
171
  const byStory = new Map();
172
+ const named = namedFiles(root);
136
173
  const filesOf = (s) => {
137
- if (!byStory.has(s.id)) byStory.set(s.id, storyFiles(root, s, from));
174
+ if (!byStory.has(s.id)) byStory.set(s.id, storyFiles(root, s, from, named));
138
175
  return byStory.get(s.id);
139
176
  };
140
177
  return status.requirements
@@ -2,11 +2,44 @@
2
2
  // records: when its branch was made, its commits, its merge into the base, its send-backs and the
3
3
  // approvals its commits logged. The mod draws these as a bar per lane on a shared time axis.
4
4
  import { execFileSync } from 'node:child_process';
5
+ import { readFileSync } from 'node:fs';
6
+ import { isAbsolute, join } from 'node:path';
5
7
  import { APPROVAL_LOG } from './rules.mjs';
6
8
  import { sendBacks } from './reviews.mjs';
7
9
 
8
10
  const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
9
11
 
12
+ /**
13
+ * Each object asked for, read by one `git cat-file --batch`: { name: text }, a missing one left out.
14
+ * One process for every branch's approval log, where a `git show` each outlasts the mod's 30 seconds.
15
+ */
16
+ export function readObjects(root, names) {
17
+ if (!names.length) return {};
18
+ let out;
19
+ try {
20
+ out = execFileSync('git', ['-C', root, 'cat-file', '--batch'], {
21
+ input: `${names.join('\n')}\n`,
22
+ stdio: ['pipe', 'pipe', 'ignore'],
23
+ maxBuffer: 256 * 1024 * 1024,
24
+ });
25
+ } catch {
26
+ return {};
27
+ }
28
+ const found = {};
29
+ let at = 0;
30
+ for (const name of names) {
31
+ const eol = out.indexOf(10, at);
32
+ if (eol < 0) break;
33
+ const header = out.subarray(at, eol).toString('utf8').split(' ');
34
+ at = eol + 1;
35
+ if (header[1] === 'missing' || header.length < 3) continue;
36
+ const size = Number(header[2]);
37
+ found[name] = out.subarray(at, at + size).toString('utf8');
38
+ at += size + 1;
39
+ }
40
+ return found;
41
+ }
42
+
10
43
  /**
11
44
  * For each story with a branch, or done: { id, lane, branch, state, started, lastCommit, merged,
12
45
  * sentBack: [ms], approvals: [{ at, names }] }, times in milliseconds or null.
@@ -29,49 +62,66 @@ export function storyTimes(root, stories, base) {
29
62
  return { at: Number(t) * 1000, subject: subject.join('\t') };
30
63
  });
31
64
  const backs = sendBacks(root);
32
- const logged = (ref) => new Set(lines(git('show', `${ref}:${APPROVAL_LOG}`)));
33
- const onBase = logged(base);
34
- return stories
35
- .filter((s) => s.branchExists || s.state === 'done')
36
- .map((s) => {
37
- const b = s.branch;
38
- // The reflog's oldest entry is the branch's making, when it's still there.
39
- const made = s.branchExists
40
- ? lines(git('reflog', 'show', '--format=%ct', `refs/heads/${b}`))
41
- : [];
42
- const commits = s.branchExists
43
- ? lines(git('log', '--format=%ct', `${base}..${b}`)).map((t) => Number(t) * 1000)
44
- : [];
45
- const named = new RegExp(`(^|[\\s'"])${escape(b)}($|[\\s'"])`);
46
- const merged = merges.find((m) => named.test(m.subject))?.at ?? null;
47
- const approvals = s.branchExists
48
- ? [...logged(b)]
49
- .filter((l) => !onBase.has(l))
50
- .flatMap((l) => {
51
- try {
52
- const e = JSON.parse(l);
53
- return e.grantedAt || e.at
54
- ? [{ at: Date.parse(e.grantedAt ?? e.at), names: [e.approval].filter(Boolean) }]
55
- : [];
56
- } catch {
57
- return [];
58
- }
59
- })
65
+ const onBase = new Set(lines(git('show', `${base}:${APPROVAL_LOG}`)));
66
+ const shown = stories.filter((s) => s.branchExists || s.state === 'done');
67
+ const refOf = (s) => s.ref ?? `refs/heads/${s.branch}`;
68
+ const logs = readObjects(
69
+ root,
70
+ shown.filter((s) => s.branchExists).map((s) => `${refOf(s)}:${APPROVAL_LOG}`),
71
+ );
72
+ const common = git('rev-parse', '--git-common-dir');
73
+ const reflogs = common ? (isAbsolute(common) ? common : join(root, common)) : null;
74
+ // When a branch was made: its reflog's oldest entry, read from the file git keeps it in (or from git,
75
+ // where the file isn't there), in milliseconds; null once the reflog is gone.
76
+ const madeAt = (b) => {
77
+ let first = null;
78
+ try {
79
+ first = readFileSync(join(reflogs, 'logs/refs/heads', b), 'utf8').split('\n')[0];
80
+ } catch {
81
+ const at = lines(git('reflog', 'show', '--date=unix', '--format=%gd', `refs/heads/${b}`))
82
+ .at(-1)
83
+ ?.match(/@\{(\d+)\}$/)?.[1];
84
+ return at ? Number(at) * 1000 : null;
85
+ }
86
+ const at = first?.split('\t')[0].match(/> (\d+) [+-]\d{4}$/)?.[1];
87
+ return at ? Number(at) * 1000 : null;
88
+ };
89
+ return shown.map((s) => {
90
+ const b = s.branch;
91
+ // A branch only on origin has no reflog here.
92
+ const local = s.branchExists && refOf(s).startsWith('refs/heads/');
93
+ const made = local && reflogs ? madeAt(b) : null;
94
+ // Only a branch ahead of the base has commits of its own.
95
+ const commits =
96
+ s.branchExists && s.ahead !== 0
97
+ ? lines(git('log', '--format=%ct', `${base}..${refOf(s)}`)).map((t) => Number(t) * 1000)
60
98
  : [];
61
- return {
62
- id: s.id,
63
- lane: s.lane,
64
- branch: b,
65
- state: s.state,
66
- started: made.length
67
- ? Number(made.at(-1)) * 1000
68
- : commits.length
69
- ? Math.min(...commits)
70
- : null,
71
- lastCommit: commits.length ? Math.max(...commits) : null,
72
- merged,
73
- sentBack: backs.filter((x) => x.branch === b).map((x) => Date.parse(x.at)),
74
- approvals,
75
- };
76
- });
99
+ const named = new RegExp(`(^|[\\s'"])${escape(b)}($|[\\s'"])`);
100
+ const merged = merges.find((m) => named.test(m.subject))?.at ?? null;
101
+ const approvals = s.branchExists
102
+ ? lines(logs[`${refOf(s)}:${APPROVAL_LOG}`] ?? '')
103
+ .filter((l) => !onBase.has(l))
104
+ .flatMap((l) => {
105
+ try {
106
+ const e = JSON.parse(l);
107
+ return e.grantedAt || e.at
108
+ ? [{ at: Date.parse(e.grantedAt ?? e.at), names: [e.approval].filter(Boolean) }]
109
+ : [];
110
+ } catch {
111
+ return [];
112
+ }
113
+ })
114
+ : [];
115
+ return {
116
+ id: s.id,
117
+ lane: s.lane,
118
+ branch: b,
119
+ state: s.state,
120
+ started: made ? made : commits.length ? Math.min(...commits) : null,
121
+ lastCommit: commits.length ? Math.max(...commits) : null,
122
+ merged,
123
+ sentBack: backs.filter((x) => x.branch === b).map((x) => Date.parse(x.at)),
124
+ approvals,
125
+ };
126
+ });
77
127
  }
@@ -297,9 +297,16 @@ export function register(on) {
297
297
  // The held call's answer, for the `code-kit hold` it waits in.
298
298
  const answerHeld = (id, answer) =>
299
299
  $.process.run(['node', cli, 'hold', id, '--answer', answer], { cwd });
300
+ // A read that fails or outlasts its time is null, like one that can't say: one slow read never
301
+ // takes the band or the pane down with it.
300
302
  const json = async (...args) => {
301
- const ran = await $.process.run(['node', cli, ...args, '--json'], { cwd });
302
- return ran.exitCode === 0 ? parseJson(ran.stdout) : null;
303
+ const ran = await $.process.run(['node', cli, ...args, '--json'], { cwd }).catch((err) => {
304
+ $.ui.log(`code-kit: \`code-kit ${args[0]}\` didn't answer: ${err?.message ?? err}`, {
305
+ to: 'debug',
306
+ });
307
+ return null;
308
+ });
309
+ return ran?.exitCode === 0 ? parseJson(ran.stdout) : null;
303
310
  };
304
311
  // What a CLI run said, in a line: why it refused, for a notice.
305
312
  const firstLine = (ran) => (ran.stderr || ran.stdout).trim().split('\n')[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@warren-dean/code-kit",
3
- "version": "0.26.0",
3
+ "version": "0.26.1",
4
4
  "description": "Keeps AI coding agents inside your project's rules: lanes, layer rules, protected paths and proof before finish, enforced by Claude Code hooks and in CI",
5
5
  "license": "MIT",
6
6
  "author": "Warren Langeveldt",