@warren-dean/code-kit 0.30.1 → 0.31.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 +29 -0
- package/README.md +38 -32
- package/bin/code-kit.mjs +77 -15
- package/hooks/guard-bash.mjs +94 -27
- package/hooks/guard-paths.mjs +2 -1
- package/hooks/lib/adapters/context-graph.mjs +3 -0
- package/hooks/lib/adapters/index.mjs +1 -0
- package/hooks/lib/checkout.mjs +20 -4
- package/hooks/lib/config.mjs +36 -2
- package/hooks/lib/dependencies.mjs +4 -1
- package/hooks/lib/harness.mjs +13 -2
- package/hooks/lib/instructions.mjs +3 -0
- package/hooks/lib/next.mjs +9 -4
- package/hooks/lib/plan.mjs +12 -6
- package/hooks/lib/queue.mjs +97 -12
- package/hooks/lib/regression.mjs +14 -1
- package/hooks/lib/rules.mjs +52 -7
- package/hooks/lib/shell.mjs +40 -0
- package/hooks/lib/worktrees.mjs +5 -3
- package/hooks/mod/view.mjs +2 -2
- package/package.json +1 -1
- package/skills/decide/SKILL.md +2 -0
- package/skills/design/SKILL.md +2 -0
- package/skills/init/SKILL.md +3 -3
- package/skills/next/SKILL.md +2 -0
- package/skills/review/SKILL.md +2 -2
- package/skills/spec-design/SKILL.md +2 -0
- package/templates/claude-md.md +5 -2
package/hooks/guard-bash.mjs
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
codeOf,
|
|
21
21
|
commandsOf,
|
|
22
22
|
readsOnly,
|
|
23
|
+
unreadNames,
|
|
23
24
|
ruleMatches,
|
|
24
25
|
runs,
|
|
25
26
|
withoutHarmlessRedirects,
|
|
@@ -30,7 +31,7 @@ import { laneOfBranch, storyOfBranch, teamOf, teamProvider, whoami } from './lib
|
|
|
30
31
|
import { entryProblems, freshEntries, readRegister } from './lib/designs.mjs';
|
|
31
32
|
import { globToRegExp, matchesAny } from './lib/glob.mjs';
|
|
32
33
|
import { noteBefore } from './lane-audit.mjs';
|
|
33
|
-
import { storyMerges } from './lib/queue.mjs';
|
|
34
|
+
import { historyWrites, storyMerges } from './lib/queue.mjs';
|
|
34
35
|
import { approverOf } from './lib/journal.mjs';
|
|
35
36
|
import { loginHere } from './lib/sessions.mjs';
|
|
36
37
|
import { TESTS_APPROVAL, commitWeakenings } from './lib/regression.mjs';
|
|
@@ -57,6 +58,7 @@ import {
|
|
|
57
58
|
owns,
|
|
58
59
|
protectedEntry,
|
|
59
60
|
leadNeedsApproval,
|
|
61
|
+
beforeSetup,
|
|
60
62
|
approvalEnded,
|
|
61
63
|
recordRequest,
|
|
62
64
|
sessionRoot,
|
|
@@ -96,8 +98,8 @@ const ALWAYS = [
|
|
|
96
98
|
],
|
|
97
99
|
[
|
|
98
100
|
/approval-log\.jsonl/,
|
|
99
|
-
"The approval audit log is appended only by the commit hook; nobody edits it. A shell command may name it only to read it: git diff, log, show or blame, or cat, head, tail, grep, wc, jq, cut, sort, uniq, awk or sed -n printing lines,
|
|
100
|
-
|
|
101
|
+
"The approval audit log is appended only by the commit hook; nobody edits it. A shell command may name it only to read it: git diff, log, show or blame, or cat, head, tail, grep, wc, jq, cut, sort, uniq, awk or sed -n printing lines, piped only into each other, with no redirect but 2>&1 or into /dev/null, no command's output in its arguments ($(…) or backticks) and no variable set before a command; other commands may come before or after it with ; or &&, if none defines a function or alias or sets a variable. Run the read in that form, or read the file with the Read tool, which can't write.",
|
|
102
|
+
unreadNames(cmd, /approval-log\.jsonl/).join('\n'),
|
|
101
103
|
],
|
|
102
104
|
];
|
|
103
105
|
for (const [re, why, text] of ALWAYS) {
|
|
@@ -127,9 +129,6 @@ if (error) {
|
|
|
127
129
|
const branches = config.branches.protected
|
|
128
130
|
.map((b) => b.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
|
|
129
131
|
.join('|');
|
|
130
|
-
// The branch is read before the command runs, so a command that switches to a protected branch and then
|
|
131
|
-
// commits or merges in the same breath is judged by what it does, not by where it starts. Moving a
|
|
132
|
-
// protected branch directly (branch -f, update-ref) is a commit on it by another name.
|
|
133
132
|
/** Whether `file` is committed at HEAD in the repository at `root`. */
|
|
134
133
|
function committedOnHead(root, file) {
|
|
135
134
|
return (
|
|
@@ -138,16 +137,7 @@ function committedOnHead(root, file) {
|
|
|
138
137
|
);
|
|
139
138
|
}
|
|
140
139
|
|
|
141
|
-
|
|
142
|
-
cmd,
|
|
143
|
-
new RegExp(String.raw`^${GIT}(commit|merge|cherry-pick|rebase|revert|am)(?![\w-])`),
|
|
144
|
-
);
|
|
145
|
-
const switchesToProtected = runs(
|
|
146
|
-
cmd,
|
|
147
|
-
new RegExp(
|
|
148
|
-
String.raw`^${GIT}(?:switch|checkout)\s+(?:-[^\s]+\s+)*(${branches})(?![\w./-])(?!\s+--)`,
|
|
149
|
-
),
|
|
150
|
-
);
|
|
140
|
+
// Moving a protected branch directly (branch -f, update-ref) is a commit on it by another name.
|
|
151
141
|
const movesProtected =
|
|
152
142
|
runs(
|
|
153
143
|
cmd,
|
|
@@ -161,7 +151,7 @@ const movesProtected =
|
|
|
161
151
|
String.raw`^${GIT}update-ref\s+(?:-\S+\s+)*(?:refs/heads/)?(${branches})(?![\w./-])`,
|
|
162
152
|
),
|
|
163
153
|
);
|
|
164
|
-
if (
|
|
154
|
+
if (movesProtected) {
|
|
165
155
|
block(
|
|
166
156
|
`Blocked: never commit to, merge into or move ${config.branches.protected.join(' or ')}, even by switching to it first. Work on a branch; a person merges after review${config.approvals.delegate?.merge ? ', or the lead merges a verified branch with `code-kit merge <branch> --delegated`' : ''}.\nCommand: ${cmd}`,
|
|
167
157
|
);
|
|
@@ -396,16 +386,41 @@ const settingUp =
|
|
|
396
386
|
runs(cmd, new RegExp(String.raw`^${GIT}commit(?![\w-])`)) &&
|
|
397
387
|
!runs(cmd, new RegExp(String.raw`^${GIT}(merge|cherry-pick|rebase|revert|am)(?![\w-])`)) &&
|
|
398
388
|
!committedOnHead(root, CONFIG_FILE);
|
|
399
|
-
|
|
389
|
+
// A merge in another checkout the command moves to lands on that checkout's branch; one in another
|
|
390
|
+
// repository, or on a detached HEAD (a throwaway merge to try the branches together), lands on none.
|
|
391
|
+
const branchAt = (dir) => {
|
|
392
|
+
if (!existsSync(dir)) return undefined;
|
|
393
|
+
const there = sessionRoot({ cwd: dir }, project);
|
|
394
|
+
if (!there) return null;
|
|
395
|
+
try {
|
|
396
|
+
const b = currentBranch(there);
|
|
397
|
+
return b === 'HEAD' ? null : b;
|
|
398
|
+
} catch {
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
const at = { cwd: input.cwd || project, branchAt };
|
|
403
|
+
// Each commit or merge is judged on the branch it lands on, following the command's switches, `cd`s and
|
|
404
|
+
// `git -C`s in order: switching to a protected branch after committing elsewhere writes nothing to it.
|
|
405
|
+
const startsOn = branchAt(input.cwd || project) ?? (gitDir ? null : branch || null);
|
|
406
|
+
const onProtected = historyWrites(cmd, startsOn, at).find(
|
|
407
|
+
(w) => config.branches.protected.includes(w.on) && !(settingUp && w.on === branch && !w.moved),
|
|
408
|
+
);
|
|
409
|
+
if (onProtected?.moved) {
|
|
400
410
|
block(
|
|
401
|
-
`Blocked: never commit
|
|
411
|
+
`Blocked: never commit to, merge into or move ${onProtected.on}, even by switching to it first. Work on a branch; a person merges after review${config.approvals.delegate?.merge ? ', or the lead merges a verified branch with `code-kit merge <branch> --delegated`' : ''}.\nCommand: ${cmd}`,
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
if (onProtected) {
|
|
415
|
+
block(
|
|
416
|
+
`Blocked: never commit or merge on ${onProtected.on}. Work on a branch; the lead merges it after review (or the person, where merges aren't delegated).`,
|
|
402
417
|
);
|
|
403
418
|
}
|
|
404
419
|
// MQ-5: a story's branch merges only into the base, through the merge queue. Merged with git into any
|
|
405
420
|
// other branch (an integration branch such as lead/next), it looks unmerged to the queue, the trail and
|
|
406
421
|
// worktree cleanup, and that branch becomes a second base. A lane merging another story into its own
|
|
407
422
|
// story's branch, or its base into it (MQ-3), is still its own work.
|
|
408
|
-
const elsewhere = storyMerges(cmd,
|
|
423
|
+
const elsewhere = storyMerges(cmd, startsOn, at).find(
|
|
409
424
|
({ into }) => !storyOfBranch(into) && !config.branches.protected.includes(into),
|
|
410
425
|
);
|
|
411
426
|
if (elsewhere) {
|
|
@@ -609,7 +624,8 @@ function recordApprovals() {
|
|
|
609
624
|
}),
|
|
610
625
|
);
|
|
611
626
|
// STD-5: removing a standard, or weakening a required one, is the person's own call, never the lead's,
|
|
612
|
-
// delegated or not. The commit waits for their `standards` approval,
|
|
627
|
+
// delegated or not (VIBE-2: under vibe, the lead's). The commit waits for their `standards` approval,
|
|
628
|
+
// which records what it weakened.
|
|
613
629
|
const stdFile = standardsFile(config);
|
|
614
630
|
const stdWeak =
|
|
615
631
|
files.includes(stdFile) && !arrivesWithMerge(root, stdFile, { staged: true })
|
|
@@ -620,7 +636,8 @@ function recordApprovals() {
|
|
|
620
636
|
: [];
|
|
621
637
|
if (stdWeak.length) {
|
|
622
638
|
const granted = approval(root, STANDARDS_APPROVAL, actor);
|
|
623
|
-
|
|
639
|
+
const vibe = config.approvals.delegate?.vibe === true;
|
|
640
|
+
if (!granted || (!vibe && granted.reason.includes(delegatedMark('').slice(0, -1)))) {
|
|
624
641
|
recordRequest(
|
|
625
642
|
root,
|
|
626
643
|
actor,
|
|
@@ -629,11 +646,17 @@ function recordApprovals() {
|
|
|
629
646
|
`Standards weakened: ${stdWeak.join('; ')}.`,
|
|
630
647
|
);
|
|
631
648
|
const personOnly = { ...config, approvals: { ...config.approvals, delegate: null } };
|
|
649
|
+
if (vibe)
|
|
650
|
+
block(
|
|
651
|
+
`Blocked: this commit weakens the project's standards in ${stdFile}: ${stdWeak.join('; ')}. Under vibe the standards are yours to change, as the lead: weaken one only when what it costs the project outweighs what it guards, and record why. ${askHowTo(STANDARDS_APPROVAL, actor, root, config, { allows: 'weakening the standards in one commit', need: 'the standard, what it costs the story, and why weakening it is right' })}`,
|
|
652
|
+
);
|
|
632
653
|
block(
|
|
633
654
|
`Blocked: this commit weakens the project's standards in ${stdFile}: ${stdWeak.join('; ')}. Removing a standard, or weakening a required one, is the person's call, never the lead's. Ask them, with what the standard costs the project and your recommendation; they approve it with\n${approvalHowTo(STANDARDS_APPROVAL, actor, root, 'weakening the standards in one commit', personOnly)}`,
|
|
634
655
|
);
|
|
635
656
|
}
|
|
636
657
|
}
|
|
658
|
+
// The commit that switches code-kit on: the person approved the setup it holds as init showed it.
|
|
659
|
+
const setup = settingUp && files.includes(CONFIG_FILE) && beforeSetup(root);
|
|
637
660
|
for (const file of files) {
|
|
638
661
|
// Concluding a merge: what arrives as the other branch has it was logged there, with its approvals.
|
|
639
662
|
if (arrivesWithMerge(root, file, { staged: true })) continue;
|
|
@@ -646,6 +669,14 @@ function recordApprovals() {
|
|
|
646
669
|
const granted = entry && approval(root, entry.approval, actor);
|
|
647
670
|
const byDependency = actor.kind === 'lane' && dependencyChange(actor, file, root, config);
|
|
648
671
|
const leadFree = actor.kind === 'lead' && !leadNeedsApproval(entry?.approval, config);
|
|
672
|
+
if (entry && !granted && setup) {
|
|
673
|
+
record(file, {
|
|
674
|
+
approval: entry.approval,
|
|
675
|
+
reason: 'The setup that switches code-kit on, as the person approved it in init.',
|
|
676
|
+
setup: true,
|
|
677
|
+
});
|
|
678
|
+
continue;
|
|
679
|
+
}
|
|
649
680
|
if (entry && !granted && !leadFree && !byDependency) {
|
|
650
681
|
recordRequest(root, actor, entry.approval, file, entry.why);
|
|
651
682
|
block(
|
|
@@ -762,18 +793,54 @@ ${approvalHowTo(TESTS_APPROVAL, actor, root, 'weakening tests in one commit', pe
|
|
|
762
793
|
|
|
763
794
|
// The commit hook judges what the commit holds before the command runs, so a file a command earlier in
|
|
764
795
|
// the chain writes (a formatter, a script, a heredoc) can't be seen, and would go in unjudged and
|
|
765
|
-
// unlogged. Before the commit, a chain may only move into the checkout,
|
|
766
|
-
//
|
|
767
|
-
//
|
|
796
|
+
// unlogged. Before the commit, a chain may only move into the checkout, make a branch where it stands
|
|
797
|
+
// (no start point, so no file changes), stage or unstage, make folders, take away a worktree (keepsFiles)
|
|
798
|
+
// and run commands that only read (lib/shell.mjs readsOnly: git's status, diff, log and show among them,
|
|
799
|
+
// with no output file). Errors sent into the output or /dev/null write no file.
|
|
768
800
|
const BEFORE_COMMIT = new RegExp(
|
|
769
|
-
String.raw`^(?:cd\s|${GIT}(?:add|rm|mv|restore\s+--staged|reset\s+--soft)(?![\w-]))`,
|
|
801
|
+
String.raw`^(?:cd\s|${GIT}(?:add|rm|mv|restore\s+--staged|reset\s+--soft)(?![\w-])|${GIT}(?:switch\s+(?:-q\s+|--quiet\s+)*(?:-c|--create)|checkout\s+(?:-q\s+|--quiet\s+)*-b)\s+[^\s-]\S*\s*$)`,
|
|
770
802
|
);
|
|
803
|
+
// Setting shell variables (`f=docs/x.md`, `export MSG="…"`) writes no file, unless a value runs a
|
|
804
|
+
// command. What a later `git add "$f"` stages can't be read, so it counts as every changed file.
|
|
805
|
+
const ASSIGNS_ONLY = /^(?:export\s+)?[A-Za-z_]\w*=\S*(?:\s+[A-Za-z_]\w*=\S*)*$/;
|
|
806
|
+
const assignsOnly = (c) => ASSIGNS_ONLY.test(c.code) && !/`|\$\(|<\(/.test(c.text);
|
|
807
|
+
// A tool's command that writes only the tool's own records (an adapter's `shell.records`), which any
|
|
808
|
+
// actor may write and no check covers, with no redirect of its own.
|
|
809
|
+
const recordsOnly = (c) =>
|
|
810
|
+
!/[<>]/.test(c.code) && (config.shell.records ?? []).some((re) => new RegExp(re).test(c.text));
|
|
811
|
+
// What changes no file a commit could take: making folders (git keeps no empty folder), taking away a
|
|
812
|
+
// worktree, which is a checkout of its own, and unstaging (`git reset [HEAD] [--] [<paths>]`, which
|
|
813
|
+
// leaves the files as they are). A reset to another commit with no paths moves HEAD, so it counts.
|
|
814
|
+
const KEEPS_FILES = new RegExp(String.raw`^(?:mkdir\s|${GIT}worktree\s+(?:remove|prune)(?![\w-]))`);
|
|
815
|
+
const RESETS = new RegExp(String.raw`^${GIT}reset((?:\s+\S+)*)\s*$`);
|
|
816
|
+
const isCommit = (w) =>
|
|
817
|
+
spawnSync('git', ['-C', root, 'rev-parse', '--verify', '--quiet', `${w}^{commit}`]).status === 0;
|
|
818
|
+
function keepsFiles(c) {
|
|
819
|
+
if (/[<>]/.test(c.code)) return false;
|
|
820
|
+
if (KEEPS_FILES.test(c.text)) return true;
|
|
821
|
+
const reset = c.text.match(RESETS);
|
|
822
|
+
if (!reset) return false;
|
|
823
|
+
const words = reset[1].trim().split(/\s+/).filter(Boolean);
|
|
824
|
+
const paths = words.indexOf('--');
|
|
825
|
+
const before = paths >= 0 ? words.slice(0, paths) : words;
|
|
826
|
+
const flags = before.filter((w) => w.startsWith('-'));
|
|
827
|
+
if (flags.some((f) => f !== '-q' && f !== '--quiet')) return false;
|
|
828
|
+
const named = before.filter((w) => !w.startsWith('-'));
|
|
829
|
+
return !(paths < 0 && named.length === 1 && named[0] !== 'HEAD' && isCommit(named[0]));
|
|
830
|
+
}
|
|
771
831
|
function writesBeforeCommit() {
|
|
772
832
|
const pieces = commandsOf(withoutHarmlessRedirects(cmd));
|
|
773
833
|
const at = pieces.findIndex((c) => new RegExp(String.raw`^${GIT}commit(?![\w-])`).test(c.text));
|
|
774
834
|
return pieces
|
|
775
835
|
.slice(0, Math.max(at, 0))
|
|
776
|
-
.find(
|
|
836
|
+
.find(
|
|
837
|
+
(c) =>
|
|
838
|
+
(!BEFORE_COMMIT.test(c.text) || /[<>]/.test(c.code)) &&
|
|
839
|
+
!readsOnly(c.whole) &&
|
|
840
|
+
!assignsOnly(c) &&
|
|
841
|
+
!recordsOnly(c) &&
|
|
842
|
+
!keepsFiles(c),
|
|
843
|
+
);
|
|
777
844
|
}
|
|
778
845
|
|
|
779
846
|
if (commits) {
|
package/hooks/guard-paths.mjs
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
projectWorktrees,
|
|
18
18
|
relativeTo,
|
|
19
19
|
worktreeRoot,
|
|
20
|
+
subagentOf,
|
|
20
21
|
writeProblem,
|
|
21
22
|
} from './lib/rules.mjs';
|
|
22
23
|
|
|
@@ -30,7 +31,7 @@ const rel = relativeTo(root, target);
|
|
|
30
31
|
|
|
31
32
|
if (error) {
|
|
32
33
|
// The rules can't be read, so nothing is allowed except the lead repairing them.
|
|
33
|
-
if (rel === CONFIG_FILE && !input
|
|
34
|
+
if (rel === CONFIG_FILE && !subagentOf(input)) process.exit(0);
|
|
34
35
|
block(
|
|
35
36
|
`Blocked: ${error}\nThe lead fixes ${CONFIG_FILE} first; nothing else can be written until it is valid.`,
|
|
36
37
|
);
|
|
@@ -68,6 +68,9 @@ export default {
|
|
|
68
68
|
why: "Ratifying a Context Graph proposal with --commit, dropping one, and changing Context Graph's harness settings are the person's own acts: they run them themselves, with a `!` command, or from the Context Graph pane.",
|
|
69
69
|
},
|
|
70
70
|
],
|
|
71
|
+
// Recording a decision or writing a card writes only ctx's own records (anyActor above), so a commit
|
|
72
|
+
// may follow it in the same command.
|
|
73
|
+
records: [String.raw`^${CTX}\s+(?:record|card)\b`],
|
|
71
74
|
restricted: [
|
|
72
75
|
{
|
|
73
76
|
pattern: 'Ctx-Ratified-By\\s*[:=][^\\n"\']*\\(delegated\\)',
|
|
@@ -99,6 +99,7 @@ export function applyAdapters(config, raw, root) {
|
|
|
99
99
|
merged.protected.push(...(c.protected ?? []));
|
|
100
100
|
merged.shell.block.push(...(a.shell?.block ?? []));
|
|
101
101
|
merged.shell.restricted.push(...(a.shell?.restricted ?? []));
|
|
102
|
+
(merged.shell.records ??= []).push(...(a.shell?.records ?? []));
|
|
102
103
|
}
|
|
103
104
|
merged.adapters = active.map((a) => a.name);
|
|
104
105
|
return merged;
|
package/hooks/lib/checkout.mjs
CHANGED
|
@@ -140,6 +140,7 @@ const JS = [
|
|
|
140
140
|
'npm-shrinkwrap.json',
|
|
141
141
|
'yarn.lock',
|
|
142
142
|
];
|
|
143
|
+
const shellQuote = (s) => `'${s.replace(/'/g, `'\\''`)}'`;
|
|
143
144
|
const INSTALLERS = [
|
|
144
145
|
['pnpm-lock.yaml', 'pnpm install --frozen-lockfile --prefer-offline', JS],
|
|
145
146
|
['package-lock.json', 'npm ci --prefer-offline --no-audit --no-fund', JS],
|
|
@@ -163,10 +164,25 @@ const INSTALLERS = [
|
|
|
163
164
|
export function matchInstalls(dir, from, { prepare = null, timeout = 900000 } = {}) {
|
|
164
165
|
const differ = dependencyDifferences(from, dir);
|
|
165
166
|
const copied = installsOf(dir).length > 0;
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const
|
|
169
|
-
const
|
|
167
|
+
// Each file that differs is installed by the nearest lockfile of its ecosystem at or above its folder
|
|
168
|
+
// (a service in a subfolder with its own lockfile, a workspace package under the top one's), run there.
|
|
169
|
+
const installs = [];
|
|
170
|
+
for (const f of differ) {
|
|
171
|
+
for (let folder = dirname(f); ; folder = dirname(folder)) {
|
|
172
|
+
const found = INSTALLERS.find(
|
|
173
|
+
([lock, , files]) => files.includes(basename(f)) && existsSync(join(dir, folder, lock)),
|
|
174
|
+
);
|
|
175
|
+
if (found) {
|
|
176
|
+
const run = folder === '.' ? found[1] : `(cd ${shellQuote(folder)} && ${found[1]})`;
|
|
177
|
+
if (!installs.includes(run)) installs.push(run);
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
if (folder === '.') break;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const present = INSTALLERS.some(([lock]) => existsSync(join(dir, lock))) || installs.length > 0;
|
|
184
|
+
const command = differ.length ? (prepare ?? (installs.join(' && ') || null)) : null;
|
|
185
|
+
const facts = { differ, copied, lockfile: present };
|
|
170
186
|
if (!command) return { ...facts, command: null, failed: null };
|
|
171
187
|
const res = spawnSync(command, { cwd: dir, shell: true, encoding: 'utf8', timeout });
|
|
172
188
|
if (res.status === 0) return { ...facts, command, failed: null };
|
package/hooks/lib/config.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// was opened in; a project without one is not governed by the kit, and an invalid one fails closed.
|
|
3
3
|
import { execFileSync } from 'node:child_process';
|
|
4
4
|
import { existsSync, readFileSync } from 'node:fs';
|
|
5
|
-
import { harnessProblems, harnessSettings } from './harness.mjs';
|
|
5
|
+
import { VIBE, harnessProblems, harnessSettings } from './harness.mjs';
|
|
6
6
|
import { teamProblems } from './team.mjs';
|
|
7
7
|
import { join } from 'node:path';
|
|
8
8
|
import { ADAPTERS, applyAdapters } from './adapters/index.mjs';
|
|
@@ -102,7 +102,10 @@ export function withDefaults(c) {
|
|
|
102
102
|
},
|
|
103
103
|
approvals: {
|
|
104
104
|
lead: c.approvals?.lead === true,
|
|
105
|
-
delegate:
|
|
105
|
+
delegate:
|
|
106
|
+
c.harness?.autonomy === VIBE
|
|
107
|
+
? vibeRules(c.approvals?.delegate, c.protected ?? [])
|
|
108
|
+
: delegateRules(c.approvals?.delegate, c.protected ?? []),
|
|
106
109
|
},
|
|
107
110
|
harness: harnessSettings(c.harness),
|
|
108
111
|
};
|
|
@@ -167,6 +170,37 @@ const isRegExp = (v) => {
|
|
|
167
170
|
}
|
|
168
171
|
};
|
|
169
172
|
|
|
173
|
+
/**
|
|
174
|
+
* VIBE-2: under vibe the lead decides everything: every protected approval (the kit and the standards
|
|
175
|
+
* among them), merges, pushes, weakened tests on its own branches too (`own`), and packages, within the
|
|
176
|
+
* dependency rules the config gives (or the defaults), and beyond them on its judgement (`overRules`).
|
|
177
|
+
* Whatever `approvals.delegate` says is set aside.
|
|
178
|
+
*/
|
|
179
|
+
function vibeRules(given, protectedPaths = []) {
|
|
180
|
+
const deps = given && typeof given === 'object' ? given.dependencies : undefined;
|
|
181
|
+
return {
|
|
182
|
+
...delegateRules(
|
|
183
|
+
{
|
|
184
|
+
protected: [
|
|
185
|
+
...new Set([
|
|
186
|
+
'kit',
|
|
187
|
+
'standards',
|
|
188
|
+
...protectedPaths.map((p) => p.approval).filter(Boolean),
|
|
189
|
+
]),
|
|
190
|
+
],
|
|
191
|
+
merge: true,
|
|
192
|
+
push: true,
|
|
193
|
+
tests: true,
|
|
194
|
+
dependencies: deps && typeof deps === 'object' ? deps : {},
|
|
195
|
+
},
|
|
196
|
+
protectedPaths,
|
|
197
|
+
),
|
|
198
|
+
own: true,
|
|
199
|
+
overRules: true,
|
|
200
|
+
vibe: true,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
170
204
|
/**
|
|
171
205
|
* ONB-5: the version of init's setup. 2 adds project skills with the lane agents, the design gate for
|
|
172
206
|
* lanes with screens, a QA lane for end-to-end tests, and companions set up before coding; 3 adds the
|
|
@@ -33,7 +33,10 @@ export const DEPENDENCY_APPROVAL = 'dep-';
|
|
|
33
33
|
export const dependencyApproval = (pkg) =>
|
|
34
34
|
`${DEPENDENCY_APPROVAL}${pkg.replace(/\//g, '+').replace(/[^\w.@+-]/g, '_')}`;
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
// lodash@4, @scope/pkg@^1; one of the project's own packages (`@scope/pkg@workspace:*`, a `link:` or
|
|
37
|
+
// `file:` path) comes from no registry, so it's no new dependency.
|
|
38
|
+
const js = (name) =>
|
|
39
|
+
/(?<=.)@(?:workspace|link|file|portal):/.test(name) ? '' : name.replace(/(?<=.)@.*$/, '');
|
|
37
40
|
const py = (name) => name.split(/[[<>=!~;\s]/)[0]; // httpx>=0.27, requests[socks]
|
|
38
41
|
const at = (name) => name.replace(/@.*$/, ''); // serde@1, example.com/m@v1
|
|
39
42
|
|
package/hooks/lib/harness.mjs
CHANGED
|
@@ -2,7 +2,17 @@
|
|
|
2
2
|
// what the mod's loop, hold, reviewer and usage read. Defaults fill what the section leaves out; a value
|
|
3
3
|
// out of range is a config problem like any other.
|
|
4
4
|
|
|
5
|
-
export const AUTONOMY = ['autonomous', 'propose', 'off'];
|
|
5
|
+
export const AUTONOMY = ['autonomous', 'propose', 'off', 'vibe'];
|
|
6
|
+
/**
|
|
7
|
+
* VIBE-1: vibe is autonomous, and more: the lead decides everything the person would (the specs, the
|
|
8
|
+
* designs, CI, the kit, the standards, every test, merges and pushes), and the person is asked only for
|
|
9
|
+
* what nobody else can give: an account, a key, a payment, an act outside the repository.
|
|
10
|
+
*/
|
|
11
|
+
export const VIBE = 'vibe';
|
|
12
|
+
/** Whether the loop acts on its own: autonomous, or vibe. */
|
|
13
|
+
export const actsAlone = (autonomy) => autonomy === 'autonomous' || autonomy === VIBE;
|
|
14
|
+
/** VIBE-4: what a question for the person under vibe may be for: only what the lead can't give itself. */
|
|
15
|
+
export const VIBE_ASKS = ['account', 'key', 'payment', 'outside'];
|
|
6
16
|
export const MODELS = ['haiku', 'sonnet', 'opus'];
|
|
7
17
|
|
|
8
18
|
/** Each setting by its dotted key: its default, and why a value is wrong (or null when it's right). */
|
|
@@ -15,7 +25,8 @@ export const SETTINGS = {
|
|
|
15
25
|
autonomy: {
|
|
16
26
|
default: 'autonomous',
|
|
17
27
|
problem: (v) => (AUTONOMY.includes(v) ? null : `must be one of ${AUTONOMY.join(', ')}`),
|
|
18
|
-
about:
|
|
28
|
+
about:
|
|
29
|
+
"How the lead loop acts: on its own, by proposing each step, or not at all; vibe is on its own with every decision the lead's, and you only asked for accounts, keys and payments",
|
|
19
30
|
},
|
|
20
31
|
'hold.minutes': {
|
|
21
32
|
default: 2,
|
|
@@ -59,6 +59,9 @@ function factsOf(root, config, lane = null) {
|
|
|
59
59
|
? kept.map((p) => `\`${p.approval}\` (${p.why})`).join(', ')
|
|
60
60
|
: 'changes to the rules themselves',
|
|
61
61
|
'approvals.lead': Boolean(config.approvals?.lead),
|
|
62
|
+
// VIBE-1: under vibe the lead is the product owner too.
|
|
63
|
+
vibe: config.harness?.autonomy === 'vibe',
|
|
64
|
+
notVibe: config.harness?.autonomy !== 'vibe',
|
|
62
65
|
'harness.report.on': Boolean(config.harness?.report?.on),
|
|
63
66
|
ci: existsSync(join(root, CI_WORKFLOW)),
|
|
64
67
|
'docs.specs': config.docs?.specs ?? 'the specs',
|
package/hooks/lib/next.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { execFileSync, spawnSync } from 'node:child_process';
|
|
|
5
5
|
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
6
6
|
import { join, posix } from 'node:path';
|
|
7
7
|
import { loadConfig, mergeDelegation } from './config.mjs';
|
|
8
|
+
import { actsAlone } from './harness.mjs';
|
|
8
9
|
import { buildStatus, readStories, DESIGN, LEAD } from './plan.mjs';
|
|
9
10
|
import { pendingSetup } from './adapters/index.mjs';
|
|
10
11
|
import { CONFIG_FILE, SETUP_VERSION } from './config.mjs';
|
|
@@ -131,9 +132,13 @@ export function nextStep(root, base) {
|
|
|
131
132
|
);
|
|
132
133
|
const brief = readBrief(root, config);
|
|
133
134
|
if (brief?.openQuestions.length) {
|
|
134
|
-
|
|
135
|
+
const vibe = config?.harness.autonomy === 'vibe';
|
|
136
|
+
attention.push(
|
|
137
|
+
`${brief.openQuestions.length} open question(s) in ${brief.path}.${vibe ? ' Under vibe they are yours to settle: decide each, and record it in the decision log.' : ''}`,
|
|
138
|
+
);
|
|
139
|
+
// VIBE-3: under vibe the brief's questions are the lead's, not the person's.
|
|
135
140
|
// A question the brief gives to the lead alone (Owner: Lead) is the lead's to settle, not the person's.
|
|
136
|
-
briefQuestions = brief.open
|
|
141
|
+
briefQuestions = (vibe ? [] : brief.open)
|
|
137
142
|
.filter(
|
|
138
143
|
(q) =>
|
|
139
144
|
!q.owner ||
|
|
@@ -415,7 +420,7 @@ export function nextStep(root, base) {
|
|
|
415
420
|
// committed rules delegate merges, the lead merges the head first, so dependents see it; otherwise
|
|
416
421
|
// the person does, and always the first merge, which brings code-kit's rules onto the base.
|
|
417
422
|
const delegation = queued.length ? mergeDelegation(root, config) : { delegated: false };
|
|
418
|
-
const leadMerges = delegation.delegated && config.harness.autonomy
|
|
423
|
+
const leadMerges = delegation.delegated && actsAlone(config.harness.autonomy);
|
|
419
424
|
// SETUP-2: a base with no rules committed (a project set up before setup committed them there): the
|
|
420
425
|
// lead puts the approved rules onto it, and the queue merges under them from then on.
|
|
421
426
|
if (queued.length && delegation.first && !queuePaused)
|
|
@@ -524,7 +529,7 @@ export function nextStep(root, base) {
|
|
|
524
529
|
if (forDesign.length)
|
|
525
530
|
return result(
|
|
526
531
|
'design',
|
|
527
|
-
`${forDesign.join(', ')} ${forDesign.length === 1 ? 'designs' : 'design'} the screens before any code is written for them; the person approves each design.`,
|
|
532
|
+
`${forDesign.join(', ')} ${forDesign.length === 1 ? 'designs' : 'design'} the screens before any code is written for them; ${config.harness.autonomy === 'vibe' ? 'you approve each design yourself, under vibe' : 'the person approves each design'}.`,
|
|
528
533
|
{
|
|
529
534
|
args: forDesign.join(' '),
|
|
530
535
|
then: [
|
package/hooks/lib/plan.mjs
CHANGED
|
@@ -93,12 +93,18 @@ export const screenKey = (name) =>
|
|
|
93
93
|
.toLowerCase();
|
|
94
94
|
|
|
95
95
|
/** The states a `**States:**` line or a States cell lists, in lower case. */
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
.
|
|
96
|
+
// A state's own brackets keep their commas: `error (timed out, offline)` is one state.
|
|
97
|
+
const statesOf = (text) => {
|
|
98
|
+
const states = [''];
|
|
99
|
+
let depth = 0;
|
|
100
|
+
for (const ch of String(text).replace(/<br\s*\/?>/gi, ',')) {
|
|
101
|
+
if ('([{'.includes(ch)) depth++;
|
|
102
|
+
else if (')]}'.includes(ch)) depth = Math.max(0, depth - 1);
|
|
103
|
+
if (depth === 0 && ',;/'.includes(ch)) states.push('');
|
|
104
|
+
else states[states.length - 1] += ch;
|
|
105
|
+
}
|
|
106
|
+
return states.map((s) => screenKey(s).replace(/\.$/, '')).filter(Boolean);
|
|
107
|
+
};
|
|
102
108
|
|
|
103
109
|
/** A `- **Name** …` bullet that lists a screen: { indent, title }, or null (a field such as `**States:**`). */
|
|
104
110
|
function screenBullet(line) {
|
package/hooks/lib/queue.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// a time in the order they passed, each verified against the base as it is then. Kept in the main
|
|
3
3
|
// checkout, beside the requests and reviews, so every worktree and a restarted session see the same.
|
|
4
4
|
import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
5
|
-
import { dirname, join } from 'node:path';
|
|
5
|
+
import { dirname, join, resolve } from 'node:path';
|
|
6
6
|
import { projectWorktrees } from './rules.mjs';
|
|
7
7
|
import { GIT, commandsOf } from './shell.mjs';
|
|
8
8
|
import { storyOfBranch } from './teamfacts.mjs';
|
|
@@ -233,25 +233,110 @@ export function lastMerged(entries) {
|
|
|
233
233
|
const local = (ref) => ref.replace(/^[\w.-]+\/(?=[^/]+\/[^/]+$)/, '');
|
|
234
234
|
|
|
235
235
|
/**
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
* [{
|
|
236
|
+
* Each git command in `cmd`, with the branch it acts on: the one a `git switch` or `git checkout` earlier
|
|
237
|
+
* in the command moves to (`-c`, `-b` and the like: the branch it makes), else `branch`, the one checked
|
|
238
|
+
* out. [{ text, code, on, moved }], `moved` where a switch or a `cd` took it off `branch`. With `at`, a
|
|
239
|
+
* `cd` in the command, or a command's own `git -C dir`, moves to another checkout: `at.branchAt(dir)` is
|
|
240
|
+
* the branch checked out there, null where nothing lands on a branch of this project (another
|
|
241
|
+
* repository, a detached HEAD), or undefined where there's no such folder; a worktree the command adds is
|
|
242
|
+
* on the branch it names, or none with --detach.
|
|
239
243
|
*/
|
|
240
|
-
export function
|
|
241
|
-
const
|
|
244
|
+
export function gitSteps(cmd, branch, at = null) {
|
|
245
|
+
const steps = [];
|
|
242
246
|
let on = branch;
|
|
247
|
+
let moved = false;
|
|
248
|
+
let cwd = at?.cwd ?? null;
|
|
249
|
+
const vars = new Map();
|
|
250
|
+
const added = new Map();
|
|
243
251
|
const switches = new RegExp(
|
|
244
|
-
String.raw`^${GIT}(?:switch|checkout)\s+((
|
|
252
|
+
String.raw`^${GIT}(?:switch|checkout)\s+((?:-(?!-\s)\S+\s+)*)([^\s-]\S*)\s*$`,
|
|
245
253
|
);
|
|
246
|
-
const
|
|
254
|
+
const creates = new RegExp(
|
|
255
|
+
String.raw`^${GIT}(?:switch\s+(?:-\S+\s+)*(?:-[cC]|--create|--force-create)|checkout\s+(?:-\S+\s+)*-[bB])\s+([^\s-]\S*)`,
|
|
256
|
+
);
|
|
257
|
+
const detaches = new RegExp(String.raw`^${GIT}(?:switch|checkout)\s+(?:-\S+\s+)*--detach\b`);
|
|
258
|
+
const worktreeAdd = new RegExp(String.raw`^${GIT}worktree\s+add\s+(.*)$`);
|
|
259
|
+
const expand = (w) =>
|
|
260
|
+
w
|
|
261
|
+
.replace(/^["']|["']$/g, '')
|
|
262
|
+
.replace(/\$\{?(\w+)\}?/g, (m, n) => (vars.has(n) ? vars.get(n) : m));
|
|
263
|
+
const branchIn = (dir) => (added.has(dir) ? added.get(dir) : at.branchAt(dir));
|
|
247
264
|
for (const { text, code } of commandsOf(cmd)) {
|
|
248
|
-
const
|
|
249
|
-
if (
|
|
250
|
-
|
|
265
|
+
const assigned = text.match(/^\s*(\w+)=("[^"]*"|'[^']*'|[^\s;&|]+)\s*$/);
|
|
266
|
+
if (assigned) {
|
|
267
|
+
vars.set(assigned[1], expand(assigned[2]));
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
const cd = at && text.match(/^\s*cd\s+("[^"]+"|'[^']+'|\S+)\s*$/);
|
|
271
|
+
if (cd) {
|
|
272
|
+
const dir = expand(cd[1]);
|
|
273
|
+
if (/\$/.test(dir)) continue; // a variable it can't read: the branch stays the one it knows
|
|
274
|
+
cwd = resolve(cwd, dir);
|
|
275
|
+
// A folder that isn't there leaves the shell where it was (`cd x; git merge …` merges here).
|
|
276
|
+
const there = branchIn(cwd);
|
|
277
|
+
if (there !== undefined) [on, moved] = [there, true];
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
if (!/^git\b/.test(code)) continue;
|
|
281
|
+
// `git -C dir …` acts there, for that command alone.
|
|
282
|
+
const elsewhere = at && text.match(/^git\s+-C\s+("[^"]+"|'[^']+'|\S+)/);
|
|
283
|
+
const there =
|
|
284
|
+
elsewhere && !/\$/.test(expand(elsewhere[1]))
|
|
285
|
+
? branchIn(resolve(cwd, expand(elsewhere[1])))
|
|
286
|
+
: undefined;
|
|
287
|
+
const here = there === undefined ? on : there;
|
|
288
|
+
const made = code.match(creates);
|
|
289
|
+
const switched = !made && code.match(switches);
|
|
290
|
+
if (code.match(detaches)) {
|
|
291
|
+
if (there === undefined) [on, moved] = [null, true];
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
if (made || switched) {
|
|
295
|
+
if (there === undefined) [on, moved] = [(made ?? switched)[made ? 1 : 2], true];
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
const add = at && text.match(worktreeAdd);
|
|
299
|
+
if (add) {
|
|
300
|
+
// git worktree add [-b <new>] [--detach] <path> [<commit-ish>]
|
|
301
|
+
const words = add[1].trim().split(/\s+/);
|
|
302
|
+
let name = null;
|
|
303
|
+
let detach = false;
|
|
304
|
+
const rest = [];
|
|
305
|
+
for (let i = 0; i < words.length; i++) {
|
|
306
|
+
if (words[i] === '-b' || words[i] === '-B') name = words[++i];
|
|
307
|
+
else if (words[i] === '--detach') detach = true;
|
|
308
|
+
else if (!words[i].startsWith('-')) rest.push(words[i]);
|
|
309
|
+
}
|
|
310
|
+
if (rest[0])
|
|
311
|
+
added.set(resolve(cwd, expand(rest[0])), detach ? null : (name ?? rest[1] ?? null));
|
|
251
312
|
continue;
|
|
252
313
|
}
|
|
314
|
+
steps.push({ text, code, on: here, moved: moved || there !== undefined });
|
|
315
|
+
}
|
|
316
|
+
return steps;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/** What `cmd` writes to a branch's history with git (a commit, merge, rebase, cherry-pick, revert or am), each with the branch it lands on. */
|
|
320
|
+
export function historyWrites(cmd, branch, at = null) {
|
|
321
|
+
const writes = new RegExp(
|
|
322
|
+
String.raw`^${GIT}(commit|merge|cherry-pick|rebase|revert|am)(?![\w-])`,
|
|
323
|
+
);
|
|
324
|
+
return gitSteps(cmd, branch, at)
|
|
325
|
+
.filter((s) => writes.test(s.code))
|
|
326
|
+
.map(({ code, on, moved }) => ({ verb: code.match(writes)[1], on, moved }));
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* MQ-5: the story branches `cmd` merges with git, each with the branch it lands on (see gitSteps).
|
|
331
|
+
* [{ story: 'web/st-4', into: 'lead/next' }]. A merge that lands on no branch is left out: nobody's
|
|
332
|
+
* branch takes the story.
|
|
333
|
+
*/
|
|
334
|
+
export function storyMerges(cmd, branch, at = null) {
|
|
335
|
+
const found = [];
|
|
336
|
+
const merges = new RegExp(String.raw`^${GIT}merge(?![\w-])(.*)$`);
|
|
337
|
+
for (const { text, code, on } of gitSteps(cmd, branch, at)) {
|
|
253
338
|
const merged = code.match(merges);
|
|
254
|
-
if (!merged) continue;
|
|
339
|
+
if (!merged || on === null) continue;
|
|
255
340
|
// Its words as written, found in the masked code, so quoted text (a message) never reads as a branch.
|
|
256
341
|
const from = code.length - merged[1].length;
|
|
257
342
|
for (const w of merged[1].matchAll(/\S+/g)) {
|