@warren-dean/code-kit 0.22.1 → 0.24.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 +26 -0
- package/README.md +6 -5
- package/bin/code-kit.mjs +105 -77
- package/hooks/guard-agent.mjs +42 -1
- package/hooks/guard-bash.mjs +62 -17
- package/hooks/lib/checks.mjs +3 -1
- package/hooks/lib/config.mjs +13 -2
- package/hooks/lib/dispatches.mjs +76 -0
- package/hooks/lib/harness.mjs +2 -2
- package/hooks/lib/instructions.mjs +2 -1
- package/hooks/lib/journal.mjs +16 -3
- package/hooks/lib/next.mjs +37 -27
- package/hooks/lib/plan.mjs +6 -1
- package/hooks/lib/registry.mjs +70 -3
- package/hooks/lib/report.mjs +76 -7
- package/hooks/lib/rules.mjs +12 -4
- package/hooks/lib/schedule.mjs +46 -0
- package/hooks/lib/verify.mjs +27 -8
- package/hooks/lib/worktrees.mjs +286 -0
- package/hooks/mod/decisions.mjs +27 -1
- package/hooks/mod/loop.mjs +11 -7
- package/hooks/mod/register.mjs +68 -10
- package/hooks/mod/register.test.ts +145 -2
- package/hooks/mod/view.mjs +14 -2
- package/hooks/session.mjs +20 -3
- package/package.json +1 -1
- package/skills/dispatch/SKILL.md +1 -1
- package/skills/init/SKILL.md +1 -1
- package/skills/spec-design/SKILL.md +1 -1
- package/templates/plan.md +2 -1
|
@@ -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.
|
|
12
|
+
"version": "0.24.0",
|
|
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.
|
|
3
|
+
"version": "0.24.0",
|
|
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,32 @@
|
|
|
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.24.0 (2026-10-25)
|
|
6
|
+
|
|
7
|
+
Each lane agent can run on the model its story needs, instead of one model for every lane.
|
|
8
|
+
|
|
9
|
+
- Set `harness.agents.lanes.model` to `story` (init now recommends it, and `/harness` offers it as "each story's size"). Each story in the plan gets a `**Size:**` line written by the lead: `small` runs on Haiku, `medium` on Sonnet and `large` on Opus. A story with no size runs on Sonnet.
|
|
10
|
+
- The model goes up where the story calls for it. A story citing a security requirement runs on Opus. A fix story runs on Sonnet at least, since it has to write the test that proves its bug. Each time a story's branch is sent back, the next agent runs one model higher, up to Opus.
|
|
11
|
+
- A lane's agent file that names its own model keeps it, and a model the lead names on the call still wins over all of this.
|
|
12
|
+
- `code-kit next` says each story's model and why (`Model: ST-3 on haiku (a small story)`), and `next --json` gives it in `models`. The dispatch skill passes it to the agent, and the mod sets it when the call leaves it out.
|
|
13
|
+
- Each lane agent's start is logged in `.claude/state/dispatches.jsonl` with its model. The journal says which model a story was handed out on, and which one it had run on when it was sent back, so you can see whether the smaller models are being sent back more often than they save.
|
|
14
|
+
|
|
15
|
+
## 0.23.0 (2026-10-23)
|
|
16
|
+
|
|
17
|
+
Worktrees no longer fill the disk, bug reports send once, and a batch of reported bugs is fixed.
|
|
18
|
+
|
|
19
|
+
- A worktree goes once it's done with: its branch's own commits are merged, it holds nothing uncommitted, and no agent of its lane still holds the story. This happens after each merge and, in the background, as each session starts, along with an interrupted merge's temporary checkout, worktrees whose folder is gone, and stray folders under `.claude/worktrees`. `code-kit worktrees` says why each one that stays is staying.
|
|
20
|
+
- A merged worktree that still holds uncommitted changes waits in the band for you, with what it holds. Keep leaves it; Discard removes it and keeps the changes as a patch under `.claude/state/discarded`. No agent can discard one.
|
|
21
|
+
- A branch made for an agent just dispatched, with no commits of its own, is no longer taken as merged (#61).
|
|
22
|
+
- Sending a bug report claims it first, so pressing Send again while GitHub is still filing it files nothing more. The report leaves the band at once, and the result is a toast; a pane opens only when it fails.
|
|
23
|
+
- `approvals.delegate.push` (or `code-kit settings set approvals.push lead`) lets the lead push the protected branch, read from the config committed there, never by force or delete. Left out, pushing stays yours (#63).
|
|
24
|
+
- A Python lane's packages are checked on PyPI for the delegated rules: licence, downloads, last release, and whether a release has wheels (#70).
|
|
25
|
+
- A check that runs out of time leaves its branch at the head of the merge queue instead of sending it back, and says how to give it longer with `timeoutSeconds` (#62). A failed check's output leaves out Node's warnings and leads with the lines that name the failure, and the queue records which check failed (#57).
|
|
26
|
+
- The commit hook logs a renamed protected file's old path (#74), and counts files staged in the same command by a brace list, a glob, a variable or a soft reset (#76), and a commit made with `cd <worktree> && git commit` in that worktree (#55). A branch's spec-check report is kept in the main checkout when its worktree goes (#55).
|
|
27
|
+
- No hand-back or restart prompt for a story that's merged and done (#59).
|
|
28
|
+
- `instructions --write` keeps the blank lines Prettier puts inside code-kit's markers (#77).
|
|
29
|
+
- `requests drop` drops requests that carry a session (#78).
|
|
30
|
+
|
|
5
31
|
## 0.22.1 (2026-10-23)
|
|
6
32
|
|
|
7
33
|
For projects on the hosted team provider, which is in preview:
|
package/README.md
CHANGED
|
@@ -133,7 +133,7 @@ Set it up at the start of a new build, straight from the architecture docs, or b
|
|
|
133
133
|
- **For the main session and every subagent**, including agents in worktrees under `.claude/worktrees/`.
|
|
134
134
|
- **In front of you, in the terminal and the Desktop app,** through the code-kit mod (Claude Code 2.1.287 or later; see [In the session](#in-the-session)). It shows and acts, and never enforces: the hooks above do that everywhere, the mod or not.
|
|
135
135
|
- **In CI**, through `code-kit verify` in a GitHub Actions workflow that init can install (`templates/github-workflow.yml`).
|
|
136
|
-
- **Locally, with Node 22 or later.** The CLI in `bin/` runs the same rules from a terminal. The rules themselves send nothing over the network. Three features do, and only when you use them: delegated dependency approvals read the package from the npm registry, the team features (`team`, `intend`) talk to GitHub through your `gh`, or to the team provider you configure, and a bug report you send goes to code-kit's GitHub through your `gh`.
|
|
136
|
+
- **Locally, with Node 22 or later.** The CLI in `bin/` runs the same rules from a terminal. The rules themselves send nothing over the network. Three features do, and only when you use them: delegated dependency approvals read the package from the npm registry or PyPI, the team features (`team`, `intend`) talk to GitHub through your `gh`, or to the team provider you configure, and a bug report you send goes to code-kit's GitHub through your `gh`.
|
|
137
137
|
|
|
138
138
|
## Install
|
|
139
139
|
|
|
@@ -452,7 +452,8 @@ code-kit verify [--base ref] [--branch name] [--no-checks] [--json] # a branch'
|
|
|
452
452
|
code-kit security [--base ref] [--branch name] [--json] # whether a branch needs the security review, and why: sign-in, permissions, outside input, personal data, payments, secrets, dependencies
|
|
453
453
|
code-kit status [--base ref] [--json] # stories and requirements against the spec
|
|
454
454
|
code-kit next [--base ref] [--json] # the step to take now, from the project's state
|
|
455
|
-
code-kit worktrees [--json] | worktrees release <branch> | worktrees prune # the project's worktrees; free one for a fresh agent on its story, or remove every
|
|
455
|
+
code-kit worktrees [--json] | worktrees release <branch> | worktrees prune [--quiet] # the project's worktrees and why each stays; free one for a fresh agent on its story, or remove every one that's done with, keeping their reports (also after each merge and as a session starts)
|
|
456
|
+
code-kit worktrees discard <branch> # the person's, from the band: remove a merged worktree that still holds changes, kept as a patch
|
|
456
457
|
code-kit instructions [--write] [--json] | instructions show lead|lane [<lane>] # code-kit's part of CLAUDE.md and the lane agents: where each stands, brought up to date, or printed
|
|
457
458
|
code-kit standards [--json] [--for <path>...] # the project's standards with any its organisation's provider supplies, and what's wrong with them; --for keeps the ones for those files' layers
|
|
458
459
|
code-kit trace <path>... [--json] # what a file is for: requirements, lane, layer rules
|
|
@@ -530,14 +531,14 @@ code-kit approve <name>... --reason "…" [--lane name] [--delegated [--story ST
|
|
|
530
531
|
| `postEdit[]` | no | `{ files, exclude?, run }`: after each edit of a matching file. `{file}` is the file. Exit 127 (tool not installed) is skipped. |
|
|
531
532
|
| `tests[]` | no | Globs naming the test files, for the weakened-test and fix rules. Default: the usual conventions (`*.test.*`, `*.spec.*`, `__tests__/`, `test/`, `tests/`, `e2e/`, `*_test.go`, `test_*.py`). |
|
|
532
533
|
| `regression.prepare` | no | A command run in a fresh checkout before a fix's tests run there without the fix, such as `npm ci`. Without it, the checkout's `node_modules` and virtualenvs are linked in. |
|
|
533
|
-
| `checks[]` | no | `{ name, files, exclude?, run[], each?, owners?, ifMissing?, timeoutSeconds? }`: before finishing, when matching files changed. `each` runs the commands in every changed folder matching that glob. `owners` limits who may change the files (the lead always may). `ifMissing: "fail"` makes a missing tool an error (the default is to skip the check, which `verify` and a merge list as not run).
|
|
534
|
+
| `checks[]` | no | `{ name, files, exclude?, run[], each?, owners?, ifMissing?, timeoutSeconds? }`: before finishing, when matching files changed. `each` runs the commands in every changed folder matching that glob. `owners` limits who may change the files (the lead always may). `ifMissing: "fail"` makes a missing tool an error (the default is to skip the check, which `verify` and a merge list as not run). `timeoutSeconds` (240 unless set) is how long each command may run; one that runs out of time leaves its branch at the head of the merge queue rather than sending it back. |
|
|
534
535
|
| `adapters` | no | `{ "<adapter>": false }` switches off an adapter that would otherwise be detected; `true` says the project wants that tool, so until it's set up here `next` gives its setup before any code. See [Adapters](#adapters). |
|
|
535
536
|
| `approvals.lead` | no | `true` lets the lead act on what the person says in chat, for when `!` isn't available (on a phone, say): it records their approvals with `code-kit approve`, and runs `shell.block` commands marked `person`. Default `false`. See [Approvals](#approvals). |
|
|
536
|
-
| `approvals.delegate` | no | `false`, or `{ protected?: [approval names], merge?: true, tests?: true, dependencies?: { licences?, minWeeklyDownloads?, maxMonthsSinceRelease?, allowInstallScripts?: true \| false \| [kinds] } }`: what the lead decides, inside the guardrails you keep: the protected approvals it grants, and packages it approves for a story, with `code-kit approve --delegated`; with `merge`, merges into a protected branch with `code-kit merge --delegated`; with `tests`, weakened tests on a lane's branch. Left out, the lead decides everything technical: every protected approval but `spec`, `design`, `ci` and `kit`, packages, merges and weakened tests (WHO-1); `false` keeps everything for you. Lanes ask the lead for these, never you. npm packages are also checked against the registry; the defaults are MIT, Apache-2.0, BSD and ISC, 10,000 weekly downloads, a release within 18 months, and no install scripts. See [Approvals](#approvals).
|
|
537
|
+
| `approvals.delegate` | no | `false`, or `{ protected?: [approval names], merge?: true, push?: true, tests?: true, dependencies?: { licences?, minWeeklyDownloads?, maxMonthsSinceRelease?, allowInstallScripts?: true \| false \| [kinds] } }`: what the lead decides, inside the guardrails you keep: the protected approvals it grants, and packages it approves for a story, with `code-kit approve --delegated`; with `merge`, merges into a protected branch with `code-kit merge --delegated`; with `push`, pushes the protected branch, never by force (yours unless you set it, since a push can deploy; read from the config committed on that branch); with `tests`, weakened tests on a lane's branch. Left out, the lead decides everything technical: every protected approval but `spec`, `design`, `ci` and `kit`, packages, merges and weakened tests (WHO-1); `false` keeps everything for you. Lanes ask the lead for these, never you. npm packages are also checked against the npm registry, and a Python lane's against PyPI; the defaults are MIT, Apache-2.0, BSD and ISC, 10,000 weekly downloads, a release within 18 months, and no install scripts. See [Approvals](#approvals). |
|
|
537
538
|
| `setup` | no | The version of init's setup the project has (3 now). Without it, or lower, `next` names what the project is missing (the design gate, design stories before screens, a QA lane, a security reviewer) and starts no new story until re-running init adds it |
|
|
538
539
|
| `team` | no | Preview. For several people in one repository: `{ techLead, staleDays?, intents?, board?, provider?, report? }`. `techLead` is the GitHub handle of the person who owns the plan, specs and contracts; `staleDays` is how many working days without a push make a claim stale (default 3); `intents` is the discussion category intents go in (default `Intents`; create it once in the repository's Settings › Discussions); `board` is `{ owner, number }`, a GitHub Project the plan is mirrored onto; `provider` is `"github"` (default), `{ command, fallback? }` for another team provider, or, in preview, a hosted provider's adapter as `{ "<name>": "<https address>" }`, which keeps the intents (Discussions only when `intents` is set) and has GitHub as its fallback; with `fallback: "github"`, claims go through GitHub whenever that provider can't be reached; `report` (default true) is whether the project reports its facts (stories' stages, send-backs, the requirement trail, approvals, token use and the rules; never code) to a provider that isn't GitHub. A provider may also supply an organisation's standards (`standards`, answering `{ standards, waivers, version }`, each standard in `docs.standards`' fields, each waiver `{ standard, paths?, expires?, reason?, approvedBy? }`): they apply as if in the project's file, which may extend or tighten one but weaken a required one only under a waiver. See docs/specs/16-teams.md, docs/specs/21-hub-adapter-and-reports.md and docs/specs/22-standards.md. |
|
|
539
540
|
| `branches.protected` | no | Default `["main", "master"]` |
|
|
540
|
-
| `harness` | no | What the mod's harness does in the session: `autonomy` (`autonomous`, `propose` or `off`; default `autonomous`), `hold.minutes` (how long a call waiting on your approval is held, 0 to 10; default 2), `stall.nudgeMinutes` and `stall.restartMinutes` (default 5 and 10), `stall.maxRestarts` (default 2), `agents.reviewer.on` (default `false`) and `agents.reviewer.model` (code-kit's reviewer and the security reviewer; default `sonnet`), `agents.lanes.model` (the model each lane agent starts on, unless the lead's call or the lane's agent file names one; default the session's), `slices.open` (how many of the plan's slices are in focus: a free lane builds an open slice's stories first; default 1), `background.pauseAtPercent` (default 80), `compact.at` (compact the lead's context between turns once it's past this share of its window; default 40, 0 for never), `compact.milestone` (when a milestone finishes, compact the lead's context: `ask`, `auto` or `off`; default `ask`), `agents.lanes.contextLimit` (the context a lane agent may reach before it hands its story to a fresh agent; default 250,000 tokens), `notify.on` (a system notification when something new needs you; default `true`) and `report.on` (agents draft bug reports for code-kit, which you send or discard; default `false`). Change them with `/harness` or `code-kit settings set`.
|
|
541
|
+
| `harness` | no | What the mod's harness does in the session: `autonomy` (`autonomous`, `propose` or `off`; default `autonomous`), `hold.minutes` (how long a call waiting on your approval is held, 0 to 10; default 2), `stall.nudgeMinutes` and `stall.restartMinutes` (default 5 and 10), `stall.maxRestarts` (default 2), `agents.reviewer.on` (default `false`) and `agents.reviewer.model` (code-kit's reviewer and the security reviewer; default `sonnet`), `agents.lanes.model` (the model each lane agent starts on, unless the lead's call or the lane's agent file names one: a model, or `story` for each story's `**Size:**` in the plan, raised for security requirements, fixes and send-backs; default the session's), `slices.open` (how many of the plan's slices are in focus: a free lane builds an open slice's stories first; default 1), `background.pauseAtPercent` (default 80), `compact.at` (compact the lead's context between turns once it's past this share of its window; default 40, 0 for never), `compact.milestone` (when a milestone finishes, compact the lead's context: `ask`, `auto` or `off`; default `ask`), `agents.lanes.contextLimit` (the context a lane agent may reach before it hands its story to a fresh agent; default 250,000 tokens), `notify.on` (a system notification when something new needs you; default `true`) and `report.on` (agents draft bug reports for code-kit, which you send or discard; default `false`). Change them with `/harness` or `code-kit settings set`. |
|
|
541
542
|
|
|
542
543
|
Add `.claude/approvals/`, `.claude/state/` and `.claude/code-kit.draft.json` to `.gitignore`, and `.claude/approval-log.jsonl merge=union` to `.gitattributes`, so merging branches that both logged changes keeps every entry. Commit `.claude/code-kit.baseline.json` if the project has one.
|
|
543
544
|
|
package/bin/code-kit.mjs
CHANGED
|
@@ -44,7 +44,6 @@
|
|
|
44
44
|
// --config <file> reads a draft (.claude/code-kit.draft.json) instead of .claude/code-kit.json.
|
|
45
45
|
import { execFileSync, spawnSync } from 'node:child_process';
|
|
46
46
|
import {
|
|
47
|
-
copyFileSync,
|
|
48
47
|
existsSync,
|
|
49
48
|
mkdirSync,
|
|
50
49
|
mkdtempSync,
|
|
@@ -138,7 +137,13 @@ import {
|
|
|
138
137
|
reviewerOf,
|
|
139
138
|
} from '../hooks/lib/rules.mjs';
|
|
140
139
|
import { DEPENDENCY_APPROVAL, dependencyApproval } from '../hooks/lib/dependencies.mjs';
|
|
141
|
-
import {
|
|
140
|
+
import {
|
|
141
|
+
PYPI_MANAGERS,
|
|
142
|
+
dependencyRuleProblems,
|
|
143
|
+
npmFacts,
|
|
144
|
+
packageOf,
|
|
145
|
+
pypiFacts,
|
|
146
|
+
} from '../hooks/lib/registry.mjs';
|
|
142
147
|
import { heldTo, laneOfBranch, verifyBranch } from '../hooks/lib/verify.mjs';
|
|
143
148
|
import { skippedLine } from '../hooks/lib/checks.mjs';
|
|
144
149
|
import { TESTS_APPROVAL } from '../hooks/lib/regression.mjs';
|
|
@@ -155,6 +160,14 @@ import {
|
|
|
155
160
|
takeTask,
|
|
156
161
|
} from '../hooks/lib/sessions.mjs';
|
|
157
162
|
import { globsOverlap } from '../hooks/lib/teamfacts.mjs';
|
|
163
|
+
import {
|
|
164
|
+
cleanOf,
|
|
165
|
+
discardWorktree,
|
|
166
|
+
keptBecause,
|
|
167
|
+
pruneWorktrees,
|
|
168
|
+
removeWorktree,
|
|
169
|
+
worktrees,
|
|
170
|
+
} from '../hooks/lib/worktrees.mjs';
|
|
158
171
|
import { decisionsFor, openDecisions } from '../hooks/lib/decisionstore.mjs';
|
|
159
172
|
import {
|
|
160
173
|
appliesTo,
|
|
@@ -575,12 +588,30 @@ const firstMerge = (into, branch) =>
|
|
|
575
588
|
|
|
576
589
|
/** Why a merge didn't happen: `refused` (the rules), `verify` (problems) or `conflict`. */
|
|
577
590
|
class MergeStop extends Error {
|
|
578
|
-
|
|
591
|
+
/** `first`: the first problem's first line, for the queue's record of why (#57). */
|
|
592
|
+
constructor(kind, message, first = null) {
|
|
579
593
|
super(message);
|
|
580
594
|
this.kind = kind;
|
|
595
|
+
this.first = first;
|
|
581
596
|
}
|
|
582
597
|
}
|
|
583
598
|
|
|
599
|
+
/**
|
|
600
|
+
* #70: the ecosystem a lane's packages come from, by the manifests in its paths: `uv` for a lane with a
|
|
601
|
+
* pyproject.toml, requirements file or uv.lock and no package.json, otherwise `npm`.
|
|
602
|
+
*/
|
|
603
|
+
function laneEcosystem(config, lane) {
|
|
604
|
+
const paths = lane ? (config.lanes[lane]?.paths ?? []) : (config.lead?.paths ?? []);
|
|
605
|
+
const tracked = (spawnSync('git', ['ls-files'], { encoding: 'utf8' }).stdout ?? '')
|
|
606
|
+
.split('\n')
|
|
607
|
+
.filter((f) => f && matchesAny(f, paths));
|
|
608
|
+
const named = (re) => tracked.some((f) => re.test(f.split('/').at(-1)));
|
|
609
|
+
return named(/^(pyproject\.toml|uv\.lock|requirements[\w.-]*\.txt|Pipfile)$/) &&
|
|
610
|
+
!named(/^package\.json$/)
|
|
611
|
+
? 'uv'
|
|
612
|
+
: 'npm';
|
|
613
|
+
}
|
|
614
|
+
|
|
584
615
|
/** Who merges, from the flags: the lead within the delegated rules, or the person. */
|
|
585
616
|
function mergeMode() {
|
|
586
617
|
const byPerson = flag('--person');
|
|
@@ -653,9 +684,9 @@ function mergeOne(branch, config, byPerson, commit = null) {
|
|
|
653
684
|
}
|
|
654
685
|
}
|
|
655
686
|
};
|
|
656
|
-
const fail = (message, kind = 'refused') => {
|
|
687
|
+
const fail = (message, kind = 'refused', first = null) => {
|
|
657
688
|
cleanup();
|
|
658
|
-
throw new MergeStop(kind, message);
|
|
689
|
+
throw new MergeStop(kind, message, first);
|
|
659
690
|
};
|
|
660
691
|
const worktree = (b, detach) => {
|
|
661
692
|
const dir = mkdtempSync(join(tmpdir(), 'code-kit-merge-'));
|
|
@@ -676,7 +707,7 @@ function mergeOne(branch, config, byPerson, commit = null) {
|
|
|
676
707
|
'moved',
|
|
677
708
|
);
|
|
678
709
|
const lane = laneOfBranch(branch, config);
|
|
679
|
-
const { changed, found, skipped } = verifyBranch({
|
|
710
|
+
const { changed, found, skipped, unfinished } = verifyBranch({
|
|
680
711
|
root: verifyIn,
|
|
681
712
|
base: into,
|
|
682
713
|
config,
|
|
@@ -687,10 +718,17 @@ function mergeOne(branch, config, byPerson, commit = null) {
|
|
|
687
718
|
const problems = Object.entries(VERIFY_GROUPS).flatMap(([key, title]) =>
|
|
688
719
|
found[key].map((p) => `${title}: ${p.split('\n').join('\n ')}`),
|
|
689
720
|
);
|
|
721
|
+
// #62: a check that only ran out of time says nothing against the branch: it's tried again.
|
|
722
|
+
if (problems.length === 1 && unfinished)
|
|
723
|
+
fail(
|
|
724
|
+
`Nothing was merged: a check on ${branch} didn't finish, which says nothing against the branch (checked in ${verifyIn}):\n ${problems[0]}\nIt stays at the head of the queue; merge again once fewer suites are running.`,
|
|
725
|
+
'unfinished',
|
|
726
|
+
);
|
|
690
727
|
if (problems.length)
|
|
691
728
|
fail(
|
|
692
729
|
`Nothing was merged. code-kit verify found ${problems.length} problem(s) on ${branch} (checked in ${verifyIn}):\n ${problems.join('\n ')}\nSend it back to its lane, or fix it, then merge again.`,
|
|
693
730
|
'verify',
|
|
731
|
+
problems[0].split('\n')[0],
|
|
694
732
|
);
|
|
695
733
|
const mergeIn = checkedOut(into) ?? worktree(into, false);
|
|
696
734
|
clean(mergeIn, into);
|
|
@@ -720,21 +758,11 @@ function mergeOne(branch, config, byPerson, commit = null) {
|
|
|
720
758
|
const team = teamOf(config);
|
|
721
759
|
const story = storyOfBranch(branch);
|
|
722
760
|
if (team && story) teamProvider(resolve('.'), team).release(story, { merged: true });
|
|
723
|
-
//
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
agentTree?.includes('/.claude/worktrees/') &&
|
|
729
|
-
!g(agentTree, 'status', '--porcelain').trim()
|
|
730
|
-
) {
|
|
731
|
-
try {
|
|
732
|
-
g(root, 'worktree', 'remove', agentTree);
|
|
733
|
-
removed = ` Removed its worktree, ${agentTree}.`;
|
|
734
|
-
} catch {
|
|
735
|
-
// in use, or locked: left as it is
|
|
736
|
-
}
|
|
737
|
-
}
|
|
761
|
+
// LEAN-8: the merged branch's worktree, and any other that's done with, go now.
|
|
762
|
+
const pruned = pruneWorktrees(root, config).removed;
|
|
763
|
+
const removed = pruned.length
|
|
764
|
+
? ` Removed ${pruned.length} worktree${pruned.length === 1 ? '' : 's'} that ${pruned.length === 1 ? 'was' : 'were'} done with.`
|
|
765
|
+
: '';
|
|
738
766
|
return {
|
|
739
767
|
into,
|
|
740
768
|
message: `Merged ${branch} into ${into}: verify passed on ${changed.length} file(s)${lane ? `, held to ${heldTo(lane)}` : ''}, at ${tip.slice(0, 7)}.${skipped.length ? ` ${notRun(skipped)}` : ''}${removed}`,
|
|
@@ -800,6 +828,7 @@ function queue() {
|
|
|
800
828
|
if (e.kind === 'refused') die(e.message);
|
|
801
829
|
// A branch that moved after its review leaves the queue for the lead to review it again; it
|
|
802
830
|
// isn't sent back, since nothing is wrong with it yet.
|
|
831
|
+
if (e.kind === 'unfinished') die(e.message);
|
|
803
832
|
if (e.kind === 'moved') {
|
|
804
833
|
settle(root, head.branch, 'moved', 'changed after its review');
|
|
805
834
|
die(`${e.message}\n${head.branch} leaves the queue until then.`);
|
|
@@ -809,7 +838,7 @@ function queue() {
|
|
|
809
838
|
const why =
|
|
810
839
|
e.kind === 'conflict'
|
|
811
840
|
? `conflicts with ${into}${after ? ` after ${after}` : ''}`
|
|
812
|
-
: `fails verify against ${into}${after ? ` after ${after}` : ''}`;
|
|
841
|
+
: `fails verify against ${into}${after ? ` after ${after}` : ''}${e.first ? `: ${e.first}` : ''}`;
|
|
813
842
|
const sha = execFileSync('git', ['rev-parse', '--verify', `${head.branch}^{commit}`], {
|
|
814
843
|
encoding: 'utf8',
|
|
815
844
|
}).trim();
|
|
@@ -1550,6 +1579,8 @@ function next() {
|
|
|
1550
1579
|
out(actionable ? `Next: ${command(step.step, step.args)}` : `Next: ${step.step}`);
|
|
1551
1580
|
out(`Why: ${step.why}`);
|
|
1552
1581
|
for (const t of step.then) out(`Then: ${command(t.step, t.args)}`);
|
|
1582
|
+
// SCHED-3: the model each story offered to a lane runs on.
|
|
1583
|
+
for (const m of step.models ?? []) out(`Model: ${m.story} on ${m.model} (${m.why})`);
|
|
1553
1584
|
for (const a of step.attention) out(`Note: ${a}`);
|
|
1554
1585
|
}
|
|
1555
1586
|
|
|
@@ -1669,19 +1700,23 @@ async function approve(given) {
|
|
|
1669
1700
|
continue;
|
|
1670
1701
|
}
|
|
1671
1702
|
const pkg = packageOf(name);
|
|
1672
|
-
// HELM-3: the registry rules are npm's; a package from another ecosystem is the
|
|
1673
|
-
|
|
1703
|
+
// HELM-3: the registry rules are npm's and PyPI's (#70); a package from another ecosystem is the
|
|
1704
|
+
// lead's judgement. Which one is the request's, or else the lane's own manifests'.
|
|
1705
|
+
const asked = new Set(
|
|
1674
1706
|
openRequests(resolve('.'))
|
|
1675
1707
|
.filter((r) => r.names.includes(name) && (r.lane ?? undefined) === laneName)
|
|
1676
1708
|
.map((r) => r.registries?.[pkg])
|
|
1677
1709
|
.filter(Boolean),
|
|
1678
1710
|
);
|
|
1679
|
-
const
|
|
1680
|
-
const
|
|
1711
|
+
const registries = asked.size ? asked : new Set([laneEcosystem(config, laneName)]);
|
|
1712
|
+
const npm = registries.has('npm');
|
|
1713
|
+
const pypi = !npm && [...registries].some((r) => PYPI_MANAGERS.has(r));
|
|
1714
|
+
const facts = npm ? await npmFacts(pkg) : pypi ? await pypiFacts(pkg) : null;
|
|
1715
|
+
const problems = facts ? dependencyRuleProblems(facts, rules.dependencies) : [];
|
|
1681
1716
|
if (problems.length) outside.push(`${name}: ${problems.join('; ')}`);
|
|
1682
1717
|
else
|
|
1683
1718
|
marks[name] = delegatedMark(
|
|
1684
|
-
`dependencies (${pkg}${npm ? '' : `, from ${[...registries].join(', ')}, judged by the lead`}) for ${story.id}`,
|
|
1719
|
+
`dependencies (${pkg}${npm ? '' : pypi ? ', from PyPI' : `, from ${[...registries].join(', ')}, judged by the lead`}) for ${story.id}`,
|
|
1685
1720
|
);
|
|
1686
1721
|
} else if (rules.protected.includes(name))
|
|
1687
1722
|
marks[name] = delegatedMark(`protected: ${name}${story ? ` for ${story.id}` : ''}`);
|
|
@@ -2335,78 +2370,71 @@ function instructionsCommand() {
|
|
|
2335
2370
|
);
|
|
2336
2371
|
}
|
|
2337
2372
|
|
|
2338
|
-
/** LEAN-6: a worktree
|
|
2339
|
-
function worktreeList(config) {
|
|
2340
|
-
const root = resolve('.');
|
|
2341
|
-
const run = (...a) => spawnSync('git', a, { cwd: root, encoding: 'utf8' }).stdout?.trim() ?? '';
|
|
2342
|
-
const from = findBase(config, false);
|
|
2343
|
-
const blocks = run('worktree', 'list', '--porcelain').split('\n\n').filter(Boolean);
|
|
2344
|
-
return blocks.slice(1).map((b) => {
|
|
2345
|
-
const path = /^worktree (.+)$/m.exec(b)?.[1];
|
|
2346
|
-
const branch = /^branch refs\/heads\/(.+)$/m.exec(b)?.[1] ?? null;
|
|
2347
|
-
const report = branch ? `.claude/state/reports/${branch.replace(/[^\w.-]+/g, '_')}.md` : null;
|
|
2348
|
-
const status = spawnSync('git', ['-C', path, 'status', '--porcelain'], { encoding: 'utf8' });
|
|
2349
|
-
return {
|
|
2350
|
-
path,
|
|
2351
|
-
branch,
|
|
2352
|
-
story: branch ? storyOfBranch(branch) : null,
|
|
2353
|
-
merged: Boolean(
|
|
2354
|
-
branch &&
|
|
2355
|
-
from &&
|
|
2356
|
-
spawnSync('git', ['merge-base', '--is-ancestor', branch, from], { cwd: root }).status === 0,
|
|
2357
|
-
),
|
|
2358
|
-
clean: status.status === 0 && !status.stdout.trim(),
|
|
2359
|
-
report: report && existsSync(join(path, report)) ? report : null,
|
|
2360
|
-
};
|
|
2361
|
-
});
|
|
2362
|
-
}
|
|
2363
|
-
|
|
2364
|
-
/** LEAN-6: releases a worktree: its report kept in the main checkout, the worktree removed, its branch kept. */
|
|
2373
|
+
/** LEAN-6: releases a worktree for a fresh agent: its report kept in the main checkout, its branch kept. */
|
|
2365
2374
|
function releaseWorktree(w) {
|
|
2366
|
-
if (!w
|
|
2375
|
+
if (!cleanOf(w))
|
|
2367
2376
|
die(
|
|
2368
2377
|
`${w.branch ?? w.path} has uncommitted changes; nothing was removed. Commit them on the branch, or have its agent do so, then release it.`,
|
|
2369
2378
|
);
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
copyFileSync(join(w.path, w.report), join(resolve('.'), w.report));
|
|
2373
|
-
}
|
|
2374
|
-
const removed = spawnSync('git', ['worktree', 'remove', w.path], {
|
|
2375
|
-
cwd: resolve('.'),
|
|
2376
|
-
encoding: 'utf8',
|
|
2377
|
-
});
|
|
2378
|
-
if (removed.status !== 0) die(`git worktree remove failed: ${removed.stderr.trim()}`);
|
|
2379
|
+
const r = removeWorktree(resolve('.'), w);
|
|
2380
|
+
if (!r.ok) die(`git worktree remove failed: ${r.why}`);
|
|
2379
2381
|
return `${w.branch ?? w.path}${w.report ? ` (its report kept at ${w.report})` : ''}`;
|
|
2380
2382
|
}
|
|
2381
2383
|
|
|
2382
2384
|
/**
|
|
2383
|
-
* LEAN-6: `worktrees` lists the project's worktrees; `release <branch>`
|
|
2384
|
-
* same story; `prune`
|
|
2385
|
+
* LEAN-6, LEAN-8: `worktrees` lists the project's worktrees and why each one stays; `release <branch>`
|
|
2386
|
+
* frees one for a fresh agent on the same story; `prune` takes away every one that's done with;
|
|
2387
|
+
* `discard <branch>`, the person's act, takes away a merged one that still holds changes, keeping them
|
|
2388
|
+
* as a patch.
|
|
2385
2389
|
*/
|
|
2386
2390
|
function worktreesCommand() {
|
|
2387
2391
|
const { config } = load();
|
|
2388
|
-
const
|
|
2392
|
+
const root = resolve('.');
|
|
2393
|
+
const list = worktrees(root, config);
|
|
2389
2394
|
if (rest[0] === 'release') {
|
|
2390
2395
|
const w = list.find((x) => x.branch === rest[1] || x.path === rest[1]);
|
|
2391
2396
|
if (!w) die(`No worktree has ${rest[1] ?? '<branch>'} checked out.`);
|
|
2392
2397
|
return out(`Released ${releaseWorktree(w)}. The branch and its commits stay.`);
|
|
2393
2398
|
}
|
|
2399
|
+
if (rest[0] === 'discard') {
|
|
2400
|
+
if (!rest[1]) die('code-kit worktrees discard <branch>');
|
|
2401
|
+
const r = discardWorktree(root, config, rest[1]);
|
|
2402
|
+
if (!r.ok) die(`${r.why} Nothing was removed.`);
|
|
2403
|
+
return out(
|
|
2404
|
+
`Removed ${rest[1]}'s worktree.${r.patch ? ` What it held is kept in ${r.patch}: \`git apply ${r.patch}\` on the branch brings it back.` : ''}${r.report ? ` Its report is kept at ${r.report}.` : ''}`,
|
|
2405
|
+
);
|
|
2406
|
+
}
|
|
2394
2407
|
if (rest[0] === 'prune') {
|
|
2395
|
-
const
|
|
2396
|
-
if (
|
|
2397
|
-
|
|
2408
|
+
const { removed, kept } = pruneWorktrees(root, config);
|
|
2409
|
+
if (flag('--quiet')) return;
|
|
2410
|
+
if (!removed.length) out('Nothing was done with; nothing was removed.');
|
|
2411
|
+
for (const r of removed) out(`Removed ${r}.`);
|
|
2412
|
+
const decide = kept.filter((k) => k.kind === 'agent' && /uncommitted/.test(k.why));
|
|
2413
|
+
if (decide.length)
|
|
2414
|
+
out(
|
|
2415
|
+
`\n${decide.length} merged worktree${decide.length === 1 ? ' still holds' : 's still hold'} uncommitted changes, so ${decide.length === 1 ? 'it stays' : 'they stay'} for the person to keep or discard: ${decide.map((k) => k.label).join(', ')}.`,
|
|
2416
|
+
);
|
|
2398
2417
|
return;
|
|
2399
2418
|
}
|
|
2400
|
-
if (flag('--json'))
|
|
2419
|
+
if (flag('--json'))
|
|
2420
|
+
return out(
|
|
2421
|
+
JSON.stringify(
|
|
2422
|
+
list.map((w) => ({ ...w, kept: keptBecause(w) })),
|
|
2423
|
+
null,
|
|
2424
|
+
2,
|
|
2425
|
+
),
|
|
2426
|
+
);
|
|
2401
2427
|
if (!list.length) return out('No worktrees besides the main checkout.');
|
|
2402
|
-
for (const w of list)
|
|
2428
|
+
for (const w of list) {
|
|
2429
|
+
const why = keptBecause(w);
|
|
2403
2430
|
out(
|
|
2404
|
-
` ${w.branch ?? '(detached)'}${w.story ? ` · ${w.story}` : ''}: ${
|
|
2431
|
+
` ${w.branch ?? '(detached)'}${w.story ? ` · ${w.story}` : ''}: ${why ? `stays, as ${why}` : 'done with'} ${w.path}`,
|
|
2405
2432
|
);
|
|
2406
|
-
|
|
2407
|
-
|
|
2433
|
+
}
|
|
2434
|
+
const done = list.filter((w) => !keptBecause(w)).length;
|
|
2435
|
+
if (done)
|
|
2408
2436
|
out(
|
|
2409
|
-
`\n${
|
|
2437
|
+
`\n${done} done with: \`code-kit worktrees prune\` removes ${done === 1 ? 'it' : 'them'}, keeping their reports. It runs by itself after each merge and as a session starts.`,
|
|
2410
2438
|
);
|
|
2411
2439
|
}
|
|
2412
2440
|
|
|
@@ -2526,7 +2554,7 @@ function usage() {
|
|
|
2526
2554
|
' | next [--base ref] [--json] | adapters | trace <path>... [--json]\n' +
|
|
2527
2555
|
' | instructions [--write] [--json] | instructions show lead|lane [<lane>]\n' +
|
|
2528
2556
|
' | standards [--json] [--for <path>...]\n' +
|
|
2529
|
-
' | worktrees [--json] | worktrees release <branch> | worktrees prune\n' +
|
|
2557
|
+
' | worktrees [--json] | worktrees release|discard <branch> | worktrees prune [--quiet]\n' +
|
|
2530
2558
|
' | approve <name>... --reason "…" [--lane name] [--config file]\n' +
|
|
2531
2559
|
' | merge <branch> --delegated|--person [--into branch] | requests [--json] | requests drop <n>|all\n' +
|
|
2532
2560
|
' | ask "<question>" [--story ST-n] [--blocks] [--why "…"] [--option "Label: effect"]... | ask [--json]\n' +
|
package/hooks/guard-agent.mjs
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// PreToolUse on Agent (docs/specs/23-the-team.md, SCHED-1): a lane runs one story at a time, across every
|
|
3
3
|
// session in the project. Starting a lane's agent claims the lane; a second agent for a claimed lane is
|
|
4
|
-
// refused, naming the story and the session that has it. Any other agent starts as before.
|
|
4
|
+
// refused, naming the story and the session that has it. Any other agent starts as before. A lane agent
|
|
5
|
+
// that starts is logged with the model it runs on, and why (SCHED-3).
|
|
6
|
+
import { readFileSync } from 'node:fs';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { recordDispatch, storyModels } from './lib/dispatches.mjs';
|
|
5
9
|
import { block, start } from './lib/hook.mjs';
|
|
6
10
|
import { CLI } from './lib/rules.mjs';
|
|
7
11
|
import { claimLane, shortSession } from './lib/laneclaims.mjs';
|
|
12
|
+
import { readStories, storyBranch } from './lib/plan.mjs';
|
|
13
|
+
import { agentFileModel } from './lib/schedule.mjs';
|
|
8
14
|
import { memberOf, readSession } from './lib/sessions.mjs';
|
|
9
15
|
|
|
10
16
|
const { input, project, config, error } = start();
|
|
@@ -34,3 +40,38 @@ if (!claimed.ok) {
|
|
|
34
40
|
`Start ${story ?? 'this story'} when ${c.story ?? 'that story'} is finished, or dispatch a ready story in another lane meanwhile. If that agent has stopped and the lane is free, release it first:\n node "${CLI}" lanes release ${lane}`,
|
|
35
41
|
);
|
|
36
42
|
}
|
|
43
|
+
|
|
44
|
+
// SCHED-3: what it runs on. The lead's call wins, then the lane's agent file, then the setting: `story` is
|
|
45
|
+
// the model the story's size gives, which the mod sets where the call names none (SET-4).
|
|
46
|
+
try {
|
|
47
|
+
const setting = config.harness.agents.lanes.model;
|
|
48
|
+
const planned =
|
|
49
|
+
story && config.docs?.plan
|
|
50
|
+
? (storyModels(
|
|
51
|
+
project,
|
|
52
|
+
config,
|
|
53
|
+
readStories(project, config.docs.plan).filter((s) => s.id === story),
|
|
54
|
+
)[story] ?? null)
|
|
55
|
+
: null;
|
|
56
|
+
let own = null;
|
|
57
|
+
try {
|
|
58
|
+
own = agentFileModel(
|
|
59
|
+
readFileSync(join(project, '.claude/agents', `${call.subagent_type}.md`), 'utf8'),
|
|
60
|
+
);
|
|
61
|
+
} catch {
|
|
62
|
+
// no agent file in the project: a plugin's agent
|
|
63
|
+
}
|
|
64
|
+
const ran = call.model
|
|
65
|
+
? { model: call.model, why: planned?.model === call.model ? planned.why : 'the lead chose it' }
|
|
66
|
+
: own && own !== 'inherit'
|
|
67
|
+
? { model: own, why: `its lane's agent file names ${own}` }
|
|
68
|
+
: setting === 'story'
|
|
69
|
+
? (planned ?? { model: null, why: "the session's model" })
|
|
70
|
+
: setting
|
|
71
|
+
? { model: setting, why: 'the lane model set' }
|
|
72
|
+
: { model: null, why: "the session's model" };
|
|
73
|
+
if (story)
|
|
74
|
+
recordDispatch(project, { story, lane, branch: storyBranch({ lane, id: story }), ...ran });
|
|
75
|
+
} catch {
|
|
76
|
+
// a read-only checkout: the dispatch goes unlogged, and the agent still starts
|
|
77
|
+
}
|