@openora/create 0.4.1-canary.44 → 0.4.1-canary.441
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/README.md +4 -4
- package/dist/.tsbuildinfo +1 -1
- package/dist/generated/versions.d.ts +11 -0
- package/dist/generated/versions.d.ts.map +1 -0
- package/dist/generated/versions.js +11 -0
- package/dist/generated/versions.js.map +1 -0
- package/dist/index.js +50 -96
- package/dist/index.js.map +1 -1
- package/dist/render.d.ts +12 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +125 -0
- package/dist/render.js.map +1 -0
- package/package.json +8 -6
- package/template/Dockerfile +11 -0
- package/template/README.md.tpl +44 -10
- package/template/__dot__claude/settings.json.tpl +39 -12
- package/template/__dot__dockerignore +8 -0
- package/template/__dot__env.example +42 -2
- package/template/__dot__gitignore +5 -5
- package/template/__dot__rulesync/commands/check.md +11 -10
- package/template/__dot__rulesync/commands/doctor.md.tpl +17 -0
- package/template/__dot__rulesync/commands/scaffold-module.md +3 -2
- package/template/__dot__rulesync/commands/scaffold-plugin.md +23 -4
- package/template/__dot__rulesync/commands/scaffold-route.md +1 -0
- package/template/__dot__rulesync/commands/start.md +3 -3
- package/template/__dot__rulesync/hooks/_shared.mjs +25 -34
- package/template/__dot__rulesync/hooks/guard-comments.mjs +82 -0
- package/template/__dot__rulesync/hooks/guard-core.mjs.tpl +98 -28
- package/template/__dot__rulesync/hooks/guard-generated.mjs +15 -16
- package/template/__dot__rulesync/hooks/guard-mr.mjs +199 -0
- package/template/__dot__rulesync/hooks/guard-review.mjs +280 -0
- package/template/__dot__rulesync/hooks/guard-stack.mjs +35 -0
- package/template/__dot__rulesync/hooks/guard-subagent.mjs +22 -6
- package/template/__dot__rulesync/hooks/post-edit.mjs.tpl +116 -0
- package/template/__dot__rulesync/hooks.json +42 -4
- package/template/__dot__rulesync/rules/conventions.md +100 -119
- package/template/__dot__rulesync/rules/db-conventions.md +6 -72
- package/template/__dot__rulesync/rules/e2e-conventions.md +41 -7
- package/template/__dot__rulesync/rules/frontend-conventions.md.tpl +35 -0
- package/template/__dot__rulesync/rules/oss-boundaries.md.tpl +78 -0
- package/template/__dot__rulesync/rules/overview.md +20 -82
- package/template/__dot__rulesync/skills/agent-retro/SKILL.md.tpl +81 -0
- package/template/__dot__rulesync/skills/agent-retro/scan.mjs +420 -0
- package/template/__dot__rulesync/skills/babysit/SKILL.md.tpl +48 -0
- package/template/__dot__rulesync/skills/babysit/babysit.mjs +290 -0
- package/template/__dot__rulesync/skills/create-plugin/{SKILL.md → SKILL.md.tpl} +12 -23
- package/template/__dot__rulesync/skills/create-pr/SKILL.md.tpl +39 -0
- package/template/__dot__rulesync/skills/create-task/SKILL.md.tpl +96 -0
- package/template/__dot__rulesync/skills/create-ui-module/{SKILL.md → SKILL.md.tpl} +12 -10
- package/template/__dot__rulesync/skills/enhance-prompt/{SKILL.md → SKILL.md.tpl} +4 -4
- package/template/__dot__rulesync/skills/handoff/SKILL.md +4 -3
- package/template/__dot__rulesync/skills/review/SKILL.md.tpl +276 -0
- package/template/__dot__rulesync/skills/ship/SKILL.md.tpl +157 -0
- package/template/__dot__rulesync/skills/ship/handoff.md.tpl +48 -0
- package/template/__dot__rulesync/skills/ui-verify/SKILL.md.tpl +123 -0
- package/template/__dot__rulesync/skills/ui-verify/layout-check.check.sh +58 -0
- package/template/__dot__rulesync/skills/ui-verify/layout-check.js +163 -0
- package/template/__dot__rulesync/subagents/builder.md.tpl +116 -0
- package/template/__dot__rulesync/subagents/compliance-reviewer.md +78 -0
- package/template/__dot__rulesync/subagents/debugger.md.tpl +89 -0
- package/template/__dot__rulesync/subagents/deployer.md.tpl +53 -0
- package/template/__dot__rulesync/subagents/expert.md +29 -34
- package/template/__dot__rulesync/subagents/planner.md.tpl +47 -0
- package/template/__dot__rulesync/subagents/quality-reviewer.md.tpl +113 -0
- package/template/__dot__rulesync/subagents/security-reviewer.md.tpl +85 -0
- package/template/__dot__rulesync/subagents/tester.md.tpl +103 -0
- package/template/__dot__rulesync/sync.json.tpl +26 -0
- package/template/apps/api/package.json.tpl +2 -2
- package/template/apps/api/src/extensions.config.ts.tpl +12 -0
- package/template/apps/api/src/main.ts.tpl +1 -4
- package/template/apps/api/src/seed.ts.tpl +24 -18
- package/template/compose.prod.yml +63 -0
- package/template/docker-compose.yml +15 -3
- package/template/docs/agents/cross-repo.md.tpl +36 -0
- package/template/docs/agents/forge.md.tpl +56 -0
- package/template/docs/agents/issue-tracker.md.tpl +42 -0
- package/template/docs/standards/comments.md +16 -0
- package/template/docs/standards/database.md +77 -0
- package/template/docs/standards/enforcement.md +12 -0
- package/template/docs/standards/errors.md +30 -0
- package/template/docs/standards/frontend.md +60 -0
- package/template/docs/standards/functions.md +38 -0
- package/template/docs/standards/git-delivery.md +31 -0
- package/template/docs/standards/module-structure.md +37 -0
- package/template/docs/standards/testing.md +93 -0
- package/template/docs/standards/types.md +31 -0
- package/template/package.json.tpl +17 -10
- package/template/pnpm-workspace.yaml.tpl +6 -0
- package/template/rulesync.jsonc +4 -5
- package/template/tools/bootstrap.mjs +73 -0
- package/template/tools/oss-worktree.mjs.tpl +105 -0
- package/template/tools/review-precheck.mjs +622 -0
- package/template/tools/sync-agents.mjs +279 -0
- package/dist/generated/core-version.d.ts +0 -2
- package/dist/generated/core-version.d.ts.map +0 -1
- package/dist/generated/core-version.js +0 -2
- package/dist/generated/core-version.js.map +0 -1
- package/template/__dot__rulesync/commands/doctor.md +0 -16
- package/template/__dot__rulesync/hooks/post-edit.mjs +0 -57
- package/template/__dot__rulesync/rules/oss-boundaries.md +0 -31
- package/template/__dot__rulesync/skills/add-feature/SKILL.md +0 -113
- package/template/__dot__rulesync/skills/add-feature/handoff.md +0 -58
- package/template/__dot__rulesync/skills/create-pr/SKILL.md +0 -55
- package/template/__dot__rulesync/skills/create-task/SKILL.md +0 -77
- package/template/__dot__rulesync/skills/review/SKILL.md +0 -110
- package/template/__dot__rulesync/subagents/builder.md +0 -93
- package/template/__dot__rulesync/subagents/debugger.md +0 -82
- package/template/__dot__rulesync/subagents/deployer.md +0 -66
- package/template/__dot__rulesync/subagents/qa.md +0 -88
- package/template/__dot__rulesync/subagents/quality-reviewer.md +0 -67
- package/template/__dot__rulesync/subagents/security-reviewer.md +0 -54
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// PreToolUse guard: no push and no new merge/pull request until the `review` skill approved HEAD.
|
|
3
|
+
// `review` (and `ship`, which runs it) saves `.claude/reviews/<pr or branch>.json` in the main
|
|
4
|
+
// checkout with the reviewed `sha` and the `verdict`. A push, `gh stack submit|push`, or a new
|
|
5
|
+
// MR/PR is denied unless one of those files records the current HEAD as APPROVED (or GO). A
|
|
6
|
+
// PR/MR that names two different source branches is denied.
|
|
7
|
+
// Each command in a chain is judged on its own: a branch delete or a tag-only push passes, and
|
|
8
|
+
// so does a PR/MR opened from a shared branch (a promotion, which no branch review covers). A
|
|
9
|
+
// push to a shared branch and a hand merge (`gh pr|stack merge`, `glab mr merge`) are denied
|
|
10
|
+
// outright: the merge bot merges. Git errors fail open, like every other guard.
|
|
11
|
+
//
|
|
12
|
+
// ponytail: trusts the state file, which an agent could write by hand, and checks the checked-out
|
|
13
|
+
// HEAD (or a PR/MR's named source branch), not a different ref named in a push refspec. It stops
|
|
14
|
+
// a forgotten review, not a hostile one; the forge's own AI review is the gate an agent cannot write.
|
|
15
|
+
|
|
16
|
+
import { execFileSync } from 'node:child_process';
|
|
17
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
18
|
+
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
19
|
+
import { deny, extractCommand, readPayload } from './_shared.mjs';
|
|
20
|
+
|
|
21
|
+
const SHARED = /^(?:origin\/)?(?:main|master|dev|develop|stage|staging|prod|production)$/;
|
|
22
|
+
const PREFIX = String.raw`^(?:(?:env\s+)?\w+=\S*\s+)*(?:(?:command|env|time|nohup)\s+)?(?:\S*/)?`;
|
|
23
|
+
const GIT_PUSH = new RegExp(`${PREFIX}git((?:\\s+(?:-[cC]\\s+\\S+|--\\S+))*)\\s+push\\b(.*)$`);
|
|
24
|
+
// `-R <repo>` goes before or after `pr`/`mr`; `new` is an alias of `create`.
|
|
25
|
+
const REPO = String.raw`(?:\s+(?:-R\s*|--repo(?:=|\s+))\S+)?`;
|
|
26
|
+
const OPENS_REVIEW = new RegExp(
|
|
27
|
+
`${PREFIX}(?:(gh)${REPO}\\s+(?:pr${REPO}\\s+(?:create|new)|stack\\s+(?:submit|push))|(glab)${REPO}\\s+mr${REPO}\\s+(?:create|new))\\b(.*)$`,
|
|
28
|
+
);
|
|
29
|
+
// A forge CLI (`gh`/`glab`, bare, by path or behind `command`) and its words after that prefix.
|
|
30
|
+
const FORGE_CLI = new RegExp(`${PREFIX}(gh|glab)\\s+(.*)$`);
|
|
31
|
+
const MERGE_API = /\/merge(?=$|[?\s"'])/;
|
|
32
|
+
const API_WRITES =
|
|
33
|
+
/\s(?:(?:-X\s*|--method[=\s]+)(?:PUT|POST)\b|(?:-f|-F|--field|--raw-field|--input)\b)/i;
|
|
34
|
+
// GraphQL merges live in a quoted query, which `segments` blanks, so the raw command is checked.
|
|
35
|
+
const GRAPHQL_MERGE =
|
|
36
|
+
/\b(?:mergePullRequest|mergeRequestAccept|enqueuePullRequest|enablePullRequestAutoMerge)\b/;
|
|
37
|
+
const isHandMerge = (segment) => {
|
|
38
|
+
const cli = FORGE_CLI.exec(segment);
|
|
39
|
+
if (!cli) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
const words = cli[2].split(/\s+/);
|
|
43
|
+
const command = words.findIndex((word) => /^(?:pr|stack|mr)$/.test(word));
|
|
44
|
+
// The subcommand is the first word after `pr|stack|mr` that is no flag and no `-R` value.
|
|
45
|
+
const subcommand = words
|
|
46
|
+
.slice(command + 1)
|
|
47
|
+
.find((word, i, rest) => !word.startsWith('-') && !/^(?:-R|--repo)$/.test(rest[i - 1]));
|
|
48
|
+
return (
|
|
49
|
+
(command >= 0 && /^(?:merge|accept)$/.test(subcommand ?? '')) ||
|
|
50
|
+
(words.includes('api') && MERGE_API.test(cli[2]) && API_WRITES.test(` ${cli[2]}`))
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
// The source branch flag, glued (`-Hfeat/x`, `-dH x`) or not. glab's `-H` names the head repository.
|
|
54
|
+
const SOURCE_FLAG = {
|
|
55
|
+
gh: /\s(?:--head(?:=|\s+)|-[defw]*H(?:=|\s*))(\S+)/g,
|
|
56
|
+
glab: /\s(?:--source-branch(?:=|\s+)|-[fwy]*s(?:=|\s*))(\S+)/g,
|
|
57
|
+
};
|
|
58
|
+
// A command that can move HEAD. The hook runs before the whole command, so a push chained after
|
|
59
|
+
// one would be judged on the commit it starts from, not the one it sends. A stash listing and a
|
|
60
|
+
// new feature branch at HEAD move nothing; a new or renamed shared branch counts, since a push
|
|
61
|
+
// after it would be judged against the branch checked out before it.
|
|
62
|
+
const MOVES_HEAD = new RegExp(
|
|
63
|
+
`${PREFIX}(?:git(?:\\s+(?:-[cC]\\s+\\S+|--\\S+))*\\s+(?:commit|merge|rebase|reset|checkout|switch|cherry-pick|revert|pull|am|stash|update-ref|symbolic-ref\\s+(?:-m\\s+\\S+\\s+)?HEAD\\s+\\S+|bisect\\s+(?:start|good|bad|new|old|skip|reset|run|replay)|branch\\s+(?:-[mM]|--move))|gh${REPO}\\s+pr${REPO}\\s+checkout|glab${REPO}\\s+mr${REPO}\\s+checkout)\\b`,
|
|
64
|
+
);
|
|
65
|
+
const NEW_BRANCH = /\s(?:checkout\s+-[bB]|switch\s+-[cC])\s+(\S+)\s*$/;
|
|
66
|
+
const movesNothing = (segment) => {
|
|
67
|
+
const created = NEW_BRANCH.exec(segment);
|
|
68
|
+
return created
|
|
69
|
+
? !SHARED.test(created[1].replace(/['"\\]/g, ''))
|
|
70
|
+
: /\sstash\s+(?:list|show)\b/.test(segment);
|
|
71
|
+
};
|
|
72
|
+
const DIR_FLAG = /\s-C\s+(\S+)/;
|
|
73
|
+
|
|
74
|
+
const git = (cwd, ...args) => {
|
|
75
|
+
try {
|
|
76
|
+
return execFileSync('git', ['-C', cwd, ...args], {
|
|
77
|
+
encoding: 'utf8',
|
|
78
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
79
|
+
}).trim();
|
|
80
|
+
} catch {
|
|
81
|
+
return '';
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const unquote = (path) =>
|
|
86
|
+
path.replace(/^['"]|['"]$/g, '').replace(/^~(?=\/)/, process.env.HOME ?? '~');
|
|
87
|
+
const within = (cwd, path) => {
|
|
88
|
+
const dir = unquote(path);
|
|
89
|
+
return isAbsolute(dir) ? dir : resolve(cwd, dir);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// Quoted prose (commit messages, PR bodies) is blanked so a flag or command inside it never
|
|
93
|
+
// counts; a quoted single word (a path, a branch) is kept.
|
|
94
|
+
const segments = (command) =>
|
|
95
|
+
command
|
|
96
|
+
.replace(/'[^']*'|"(?:[^"\\]|\\.)*"/g, (quoted) => (/[\s;&|(){}]/.test(quoted) ? '""' : quoted))
|
|
97
|
+
.split(/&&|\|\||(?<![>&])&(?![>&])|[;|\n(){}]/)
|
|
98
|
+
.map((part) => part.replace(/(?:^|\s)#.*$/, '').trim())
|
|
99
|
+
.filter(Boolean);
|
|
100
|
+
|
|
101
|
+
// The flags and refspecs of a push. A flag's separate value (`-o ci.skip`) is no remote, and with
|
|
102
|
+
// `--repo <remote>` every positional word is a refspec.
|
|
103
|
+
const VALUED = /^(?:-o|--push-option|--repo|--receive-pack|--exec)$/;
|
|
104
|
+
const pushWords = (pushArgs) => {
|
|
105
|
+
const args = pushArgs.trim().split(/\s+/).filter(Boolean);
|
|
106
|
+
const positional = args.filter((arg, i) => !arg.startsWith('-') && !VALUED.test(args[i - 1]));
|
|
107
|
+
const hasRepo = args.some((arg) => /^--repo(?:=|$)/.test(arg));
|
|
108
|
+
return { args, refs: hasRepo ? positional : positional.slice(1) };
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const sendsNothingNew = (pushArgs) => {
|
|
112
|
+
const { args, refs } = pushWords(pushArgs);
|
|
113
|
+
return (
|
|
114
|
+
args.some((arg) => arg === '--delete' || arg === '-d') ||
|
|
115
|
+
(refs.length > 0 && refs.every((ref) => ref.startsWith(':'))) ||
|
|
116
|
+
(args.includes('--tags') && refs.length === 0)
|
|
117
|
+
);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// The directory to check and whether the segment opens a PR/MR, or null when it sends nothing
|
|
121
|
+
// that needs a review. A PR/MR opened from a shared branch is a promotion and needs none; a push
|
|
122
|
+
// from one does.
|
|
123
|
+
const reviewTarget = (segment, cwd) => {
|
|
124
|
+
if (/^cd\s/.test(segment)) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
const push = GIT_PUSH.exec(segment);
|
|
128
|
+
if (push) {
|
|
129
|
+
const dir = DIR_FLAG.exec(push[1]);
|
|
130
|
+
return {
|
|
131
|
+
dir: dir ? within(cwd, dir[1]) : cwd,
|
|
132
|
+
opensReview: false,
|
|
133
|
+
pushArgs: push[2],
|
|
134
|
+
sendsNothingNew: sendsNothingNew(push[2]),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
const opens = OPENS_REVIEW.exec(segment);
|
|
138
|
+
if (!opens) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
// Every source branch it names; `gh pr create --head owner:branch` names the fork too.
|
|
142
|
+
const sources = [
|
|
143
|
+
...new Set(
|
|
144
|
+
[...opens[3].matchAll(SOURCE_FLAG[opens[1] ?? opens[2]])].map((flag) =>
|
|
145
|
+
unquote(flag[1]).replace(/^[^:]+:/, ''),
|
|
146
|
+
),
|
|
147
|
+
),
|
|
148
|
+
];
|
|
149
|
+
if (sources.length > 1) {
|
|
150
|
+
deny(
|
|
151
|
+
`Blocked: this command names more than one source branch (${sources.join(', ')}); name one.`,
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
const [source] = sources;
|
|
155
|
+
if (source && SHARED.test(source)) {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
return { dir: cwd, opensReview: true, source };
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// The commit a PR/MR sends: its named source branch (local, else the fetched remote one), or HEAD.
|
|
162
|
+
const sentCommit = (dir, source) =>
|
|
163
|
+
source
|
|
164
|
+
? git(dir, 'rev-parse', '--verify', '-q', `refs/heads/${source}^{commit}`) ||
|
|
165
|
+
git(dir, 'rev-parse', '--verify', '-q', `refs/remotes/origin/${source}^{commit}`)
|
|
166
|
+
: git(dir, 'rev-parse', 'HEAD');
|
|
167
|
+
|
|
168
|
+
const isApproved = (dirs, head) =>
|
|
169
|
+
dirs.some((dir) => {
|
|
170
|
+
try {
|
|
171
|
+
const reviews = join(dir, '.claude', 'reviews');
|
|
172
|
+
if (!existsSync(reviews)) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
return readdirSync(reviews)
|
|
176
|
+
.filter((name) => name.endsWith('.json'))
|
|
177
|
+
.some((name) => {
|
|
178
|
+
try {
|
|
179
|
+
const state = JSON.parse(readFileSync(join(reviews, name), 'utf8'));
|
|
180
|
+
// The full SHA: an abbreviation could match an older reviewed commit.
|
|
181
|
+
return (
|
|
182
|
+
String(state.sha ?? '').toLowerCase() === head &&
|
|
183
|
+
/^(?:APPROVED|GO\b)/i.test(String(state.verdict ?? ''))
|
|
184
|
+
);
|
|
185
|
+
} catch {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
} catch {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
// The branches a push writes or deletes: each refspec's destination (`HEAD`/`@` is the checked-out
|
|
195
|
+
// branch, a glob may be any branch), or with no refspec where git sends this branch (`@{push}`,
|
|
196
|
+
// which follows push.default and remote.<name>.push). `--all` and `--mirror` write every branch.
|
|
197
|
+
const pushesShared = (dir, pushArgs, branch) => {
|
|
198
|
+
if (/\s--(?:all|mirror)\b/.test(pushArgs)) {
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
const { args, refs: specs } = pushWords(pushArgs);
|
|
202
|
+
// The shell drops every quote and backslash, and git reads `heads/dev` as `refs/heads/dev`.
|
|
203
|
+
const refs = specs.map((spec) => spec.replace(/['"\\]/g, ''));
|
|
204
|
+
if (refs.length === 0) {
|
|
205
|
+
if (args.includes('--tags')) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
const destination = git(dir, 'rev-parse', '--abbrev-ref', '@{push}').replace(/^[^/]+\//, '');
|
|
209
|
+
return SHARED.test(destination || branch);
|
|
210
|
+
}
|
|
211
|
+
return refs.some((spec) => {
|
|
212
|
+
const destination = spec.replace(/^\+/, '').split(':').pop();
|
|
213
|
+
return (
|
|
214
|
+
destination.includes('*') ||
|
|
215
|
+
SHARED.test(
|
|
216
|
+
(/^(?:HEAD|@)$/.test(destination) ? branch : destination).replace(
|
|
217
|
+
/^(?:refs\/)?(?:heads\/)?/,
|
|
218
|
+
'',
|
|
219
|
+
),
|
|
220
|
+
)
|
|
221
|
+
);
|
|
222
|
+
});
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
const check = ({ dir, opensReview, pushArgs, sendsNothingNew, source }) => {
|
|
226
|
+
const branch = git(dir, 'rev-parse', '--abbrev-ref', 'HEAD');
|
|
227
|
+
if (pushArgs !== undefined && branch && pushesShared(dir, pushArgs, branch)) {
|
|
228
|
+
deny(
|
|
229
|
+
'Blocked: nobody pushes to or deletes a shared branch by hand. Push a topic branch and open a merge/pull request; the merge bot merges it. A person can still push from their own terminal.',
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
if (sendsNothingNew) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const top = git(dir, 'rev-parse', '--show-toplevel');
|
|
236
|
+
const common = git(dir, 'rev-parse', '--git-common-dir');
|
|
237
|
+
const head = sentCommit(dir, source);
|
|
238
|
+
if (!top || !common || (opensReview && !source && SHARED.test(branch))) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
if (!head) {
|
|
242
|
+
if (source) {
|
|
243
|
+
deny(`Blocked: \`${source}\` is not a local or fetched branch here; fetch it, then retry.`);
|
|
244
|
+
}
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const mainCheckout = dirname(isAbsolute(common) ? common : resolve(dir, common));
|
|
248
|
+
if (!isApproved([...new Set([top, mainCheckout])], head)) {
|
|
249
|
+
deny(
|
|
250
|
+
`Blocked: no APPROVED review of HEAD ${head.slice(0, 9)}. Run \`ship\` for a ticket, or the \`review\` skill on this branch until it says APPROVED, then push. A person can still push from their own terminal.`,
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
const payload = readPayload();
|
|
256
|
+
const rawCommand = extractCommand(payload);
|
|
257
|
+
let cwd = payload.cwd ?? process.cwd();
|
|
258
|
+
let headMoved = false;
|
|
259
|
+
for (const segment of segments(rawCommand)) {
|
|
260
|
+
const cd = /^cd\s+(\S+)$/.exec(segment);
|
|
261
|
+
if (cd) {
|
|
262
|
+
cwd = within(cwd, cd[1]);
|
|
263
|
+
}
|
|
264
|
+
if (isHandMerge(segment) || (/\b(?:gh|glab)\s/.test(segment) && GRAPHQL_MERGE.test(rawCommand))) {
|
|
265
|
+
deny(
|
|
266
|
+
'Blocked: the merge bot merges, never an agent. Leave the merge/pull request to it; a person who has to merge by hand runs it from their own terminal (`! <command>` in Claude Code).',
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
const target = reviewTarget(segment, cwd);
|
|
270
|
+
if (target && headMoved && !target.sendsNothingNew) {
|
|
271
|
+
deny(
|
|
272
|
+
'Blocked: an earlier command in this chain can move HEAD, and this check runs before any of it. Commit first, get the `review` skill to approve that commit, then push or open the merge/pull request as its own command.',
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
if (target) {
|
|
276
|
+
check(target);
|
|
277
|
+
}
|
|
278
|
+
headMoved ||= MOVES_HEAD.test(segment) && !movesNothing(segment);
|
|
279
|
+
}
|
|
280
|
+
process.exit(0);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// PreToolUse guard: a GitHub pull request that builds on another feature branch goes up as a
|
|
3
|
+
// native stacked PR (`gh stack`, the github/gh-stack extension), not as a plain PR whose base is
|
|
4
|
+
// that branch. `gh pr create|new|edit --base <b>` is denied when <b> is not a
|
|
5
|
+
// shared branch. Without `--base` the PR targets the default branch and passes.
|
|
6
|
+
//
|
|
7
|
+
// ponytail: shared branches are a fixed list; a repo with another trunk name adds it here.
|
|
8
|
+
|
|
9
|
+
import { deny, extractCommand, readPayload } from './_shared.mjs';
|
|
10
|
+
|
|
11
|
+
const SHARED = /^(?:origin\/)?(?:main|master|dev|develop|stage|staging|prod|production)$/;
|
|
12
|
+
// Every `--base`/`-B` is judged, glued (`-Bfeat/x`) or not: a repeated flag must not hide a
|
|
13
|
+
// feature base behind a shared one. `-R <repo>` goes before or after `pr`; `new` aliases `create`.
|
|
14
|
+
const REPO = String.raw`(?:\s+(?:-R\s*|--repo(?:=|\s+))\S+)?`;
|
|
15
|
+
const PR_COMMAND = new RegExp(
|
|
16
|
+
String.raw`(?:^|[;&|\n(])\s*(?:(?:env\s+)?\w+=\S*\s+)*(?:(?:command|env|time|nohup)\s+)?(?:\S*\/)?gh${REPO}\s+pr${REPO}\s+(?:create|new|edit)\b([^;&|\n]*)`,
|
|
17
|
+
'g',
|
|
18
|
+
);
|
|
19
|
+
const BASE_FLAG = /\s(?:--base(?:=|\s+)|-[defw]*B(?:=|\s*))['"]?([^\s'"]+)/g;
|
|
20
|
+
|
|
21
|
+
// Quoted prose (a title or body) or a quoted separator is blanked so a `--base` inside it never
|
|
22
|
+
// counts and never cuts a flag list short.
|
|
23
|
+
const command = extractCommand(readPayload()).replace(/'[^']*'|"(?:[^"\\]|\\.)*"/g, (quoted) =>
|
|
24
|
+
/[\s;&|(){}]/.test(quoted) ? '""' : quoted,
|
|
25
|
+
);
|
|
26
|
+
// Every PR command in a chain is judged, not only the first.
|
|
27
|
+
const base = [...command.matchAll(PR_COMMAND)]
|
|
28
|
+
.flatMap((pr) => [...pr[1].matchAll(BASE_FLAG)].map((flag) => flag[1]))
|
|
29
|
+
.find((name) => !SHARED.test(name));
|
|
30
|
+
if (base) {
|
|
31
|
+
deny(
|
|
32
|
+
`Blocked: a PR based on \`${base}\` is a stack. Use \`gh stack\` (gh extension install github/gh-stack): \`gh stack init\` or \`gh stack init <branches...>\`, \`gh stack add <branch>\`, then \`gh stack submit --auto\` (layers open as drafts). Review each layer on its own; the merge bot merges.`,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
process.exit(0);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// PreToolUse(Task) guard: keep the orchestrator from spawning a GENERIC subagent
|
|
3
3
|
// (general-purpose / claude) for work a roster agent is purpose-built for. The
|
|
4
|
-
// Agent roster in
|
|
5
|
-
// is the deterministic backstop.
|
|
4
|
+
// Agent roster in the workflow rule is prose the model sometimes skips out of
|
|
5
|
+
// habit; this is the deterministic backstop.
|
|
6
6
|
//
|
|
7
7
|
// Conservative by design: it acts ONLY when (a) the chosen subagent is generic AND
|
|
8
8
|
// (b) the task text contains a HIGH-SIGNAL phrase that maps unambiguously to one
|
|
@@ -16,14 +16,16 @@ const ti = payload.tool_input ?? {};
|
|
|
16
16
|
const sub = String(ti.subagent_type ?? '').toLowerCase();
|
|
17
17
|
|
|
18
18
|
const GENERIC = new Set(['general-purpose', 'claude', '']);
|
|
19
|
-
if (!GENERIC.has(sub))
|
|
19
|
+
if (!GENERIC.has(sub)) {
|
|
20
|
+
process.exit(0);
|
|
21
|
+
}
|
|
20
22
|
|
|
21
23
|
const text = `${ti.description ?? ''}\n${ti.prompt ?? ''}`.toLowerCase();
|
|
22
24
|
|
|
23
25
|
// High-signal phrase -> the roster agent that owns it. Keep each pattern SPECIFIC;
|
|
24
26
|
// err toward missing a case over false-blocking a generic task.
|
|
25
27
|
const ROUTES = [
|
|
26
|
-
{ agent: '
|
|
28
|
+
{ agent: 'tester', re: /\b(playwright|e2e test|end-to-end test|e2e coverage)\b/ },
|
|
27
29
|
{
|
|
28
30
|
agent: 'debugger',
|
|
29
31
|
re: /\b(build (failure|error)|turbopack|tsc error|module resolution|runtime error|stack trace)\b/,
|
|
@@ -40,14 +42,28 @@ const ROUTES = [
|
|
|
40
42
|
agent: 'deployer',
|
|
41
43
|
re: /\b(dockerfile|containerize|deploy pipeline|deploy to (ecs|kubernetes|fly|railway|render)|ci\/cd deploy|helm chart)\b/,
|
|
42
44
|
},
|
|
45
|
+
{
|
|
46
|
+
agent: 'compliance-reviewer',
|
|
47
|
+
re: /\b(compliance|responsible gambling|ledger|audit trail) review\b/,
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
agent: 'quality-reviewer',
|
|
51
|
+
re: /\b(quality review|code quality|over-engineer(ed|ing)?|simplification review|duplication review)\b|\breview (the )?(mr|pr|diff|changed files)\b/,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
agent: 'security-reviewer',
|
|
55
|
+
re: /\bsecurity (review|audit)\b|\baudit\b[^.]*\bvulnerabilit|\b(authz|owasp)\b/,
|
|
56
|
+
},
|
|
43
57
|
];
|
|
44
58
|
|
|
45
59
|
const hit = ROUTES.find((r) => r.re.test(text));
|
|
46
|
-
if (!hit)
|
|
60
|
+
if (!hit) {
|
|
61
|
+
process.exit(0);
|
|
62
|
+
}
|
|
47
63
|
|
|
48
64
|
process.stderr.write(
|
|
49
65
|
`Use the \`${hit.agent}\` subagent for this task, not \`${sub || 'general-purpose'}\`. ` +
|
|
50
|
-
`It is pre-scoped for this work (tools + model + brief) - see the
|
|
66
|
+
`It is pre-scoped for this work (tools + model + brief) - see the Agents list in the workflow rule. ` +
|
|
51
67
|
`Re-issue the Task with subagent_type: "${hit.agent}". ` +
|
|
52
68
|
`If it genuinely does not fit ${hit.agent}, rephrase the description to say why.\n`,
|
|
53
69
|
);
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// PostToolUse hook (Claude / Codex CLI / Gemini CLI).
|
|
3
|
+
// Lint-fixes the edited files, then typechecks the apps that own them and reports
|
|
4
|
+
// (exit 2) only if the error is in a file just edited. Output is capped so a
|
|
5
|
+
// failure can't balloon the model context. Fail-open on anything unexpected.
|
|
6
|
+
|
|
7
|
+
import { execFileSync } from 'node:child_process';
|
|
8
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
9
|
+
import { basename, join, isAbsolute } from 'node:path';
|
|
10
|
+
import { extractFilePaths, readPayload } from './_shared.mjs';
|
|
11
|
+
|
|
12
|
+
const CAP_LINES = 40;
|
|
13
|
+
const CAP_CHARS = 2000;
|
|
14
|
+
|
|
15
|
+
const filePaths = extractFilePaths(readPayload()).filter(
|
|
16
|
+
(filePath) =>
|
|
17
|
+
/\.(ts|tsx)$/.test(filePath) &&
|
|
18
|
+
!filePath.endsWith('.d.ts') &&
|
|
19
|
+
!filePath.includes('/templates/') &&
|
|
20
|
+
!filePath.includes('/generated/') &&
|
|
21
|
+
existsSync(filePath),
|
|
22
|
+
);
|
|
23
|
+
if (filePaths.length === 0) {
|
|
24
|
+
process.exit(0);
|
|
25
|
+
}
|
|
26
|
+
const edited = filePaths.join(', ');
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* node_modules/.bin/<name> when it exists, else the bare name off PATH. `pnpm exec`
|
|
30
|
+
* costs ~2.2s of package-manager startup per call against ~0.12s for the binary, and
|
|
31
|
+
* this hook runs on every edit.
|
|
32
|
+
*/
|
|
33
|
+
function bin(name) {
|
|
34
|
+
const local = join(process.env.CLAUDE_PROJECT_DIR ?? process.cwd(), 'node_modules/.bin', name);
|
|
35
|
+
return existsSync(local) ? local : name;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function cap(text) {
|
|
39
|
+
const out = text.split('\n').slice(0, CAP_LINES).join('\n').slice(0, CAP_CHARS);
|
|
40
|
+
return out.length < text.length ? `${out}\n... (truncated)` : out;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Lint-fix (best effort - never block on the linter).
|
|
44
|
+
try {
|
|
45
|
+
execFileSync(bin('oxlint'), ['--fix', ...filePaths], { stdio: 'pipe' });
|
|
46
|
+
} catch {
|
|
47
|
+
/* oxlint unavailable or errored - fall through to the re-lint / typecheck */
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Re-lint WITHOUT --fix to surface UNFIXABLE errors the agent must resolve by
|
|
51
|
+
// hand - import/no-cycle and the no-restricted-imports boundary rules (deep @openora
|
|
52
|
+
// or {{scope}}/ui imports, app-to-app imports). oxlint exits non-zero on errors
|
|
53
|
+
// only (warnings don't fail), so this blocks on a real boundary/cycle violation
|
|
54
|
+
// in an edited file and feeds the message back. Fail-open on anything else.
|
|
55
|
+
try {
|
|
56
|
+
execFileSync(bin('oxlint'), filePaths, { stdio: 'pipe' });
|
|
57
|
+
} catch (e) {
|
|
58
|
+
const out = (e.stdout?.toString() ?? '') + (e.stderr?.toString() ?? '');
|
|
59
|
+
if (/\berror\b/.test(out)) {
|
|
60
|
+
process.stderr.write(`Boundary/lint error in ${edited} - fix before continuing:\n${cap(out)}`);
|
|
61
|
+
process.exit(2);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Resolve the owning workspace app (apps/<x> or packages/<x>).
|
|
66
|
+
function packageNameFor(fp) {
|
|
67
|
+
const m = fp.match(/(.*?\/(?:apps|packages)\/[^/]+)\//);
|
|
68
|
+
if (!m) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
const pkg = JSON.parse(readFileSync(join(m[1], 'package.json'), 'utf8'));
|
|
73
|
+
if (!pkg.name || !pkg.scripts?.['check:types']) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
return pkg.name;
|
|
77
|
+
} catch {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const owners = [
|
|
83
|
+
...new Set(
|
|
84
|
+
filePaths
|
|
85
|
+
.map((filePath) => packageNameFor(isAbsolute(filePath) ? filePath : join(process.cwd(), filePath)))
|
|
86
|
+
.filter(Boolean),
|
|
87
|
+
),
|
|
88
|
+
];
|
|
89
|
+
if (owners.length === 0) {
|
|
90
|
+
process.exit(0);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
execFileSync(
|
|
95
|
+
bin('turbo'),
|
|
96
|
+
[
|
|
97
|
+
'run',
|
|
98
|
+
'check:types',
|
|
99
|
+
...owners.flatMap((owner) => ['--filter', owner]),
|
|
100
|
+
'--output-logs=errors-only',
|
|
101
|
+
'--ui=stream',
|
|
102
|
+
],
|
|
103
|
+
{ stdio: 'pipe' },
|
|
104
|
+
);
|
|
105
|
+
process.exit(0);
|
|
106
|
+
} catch (e) {
|
|
107
|
+
const output = (e.stdout?.toString() ?? '') + (e.stderr?.toString() ?? '');
|
|
108
|
+
const failing = filePaths.map((filePath) => basename(filePath)).filter((name) => output.includes(name));
|
|
109
|
+
if (failing.length > 0) {
|
|
110
|
+
process.stderr.write(
|
|
111
|
+
`Typecheck failed for ${owners.join(', ')} after editing ${failing.join(', ')}:\n${cap(output)}`,
|
|
112
|
+
);
|
|
113
|
+
process.exit(2);
|
|
114
|
+
}
|
|
115
|
+
process.exit(0);
|
|
116
|
+
}
|
|
@@ -2,10 +2,48 @@
|
|
|
2
2
|
"version": 1,
|
|
3
3
|
"hooks": {
|
|
4
4
|
"preToolUse": [
|
|
5
|
-
{
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
{
|
|
6
|
+
"type": "command",
|
|
7
|
+
"matcher": "Bash|Edit|Write|MultiEdit|NotebookEdit",
|
|
8
|
+
"command": "node \"${CLAUDE_PROJECT_DIR:-.}/.rulesync/hooks/guard-core.mjs\""
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"type": "command",
|
|
12
|
+
"matcher": "Bash|Edit|Write|MultiEdit|NotebookEdit",
|
|
13
|
+
"command": "node \"${CLAUDE_PROJECT_DIR:-.}/.rulesync/hooks/guard-generated.mjs\""
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"type": "command",
|
|
17
|
+
"matcher": "Bash",
|
|
18
|
+
"command": "node \"${CLAUDE_PROJECT_DIR:-.}/.rulesync/hooks/guard-mr.mjs\""
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"type": "command",
|
|
22
|
+
"matcher": "Bash",
|
|
23
|
+
"command": "node \"${CLAUDE_PROJECT_DIR:-.}/.rulesync/hooks/guard-review.mjs\""
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"type": "command",
|
|
27
|
+
"matcher": "Bash",
|
|
28
|
+
"command": "node \"${CLAUDE_PROJECT_DIR:-.}/.rulesync/hooks/guard-stack.mjs\""
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"type": "command",
|
|
32
|
+
"matcher": "Bash",
|
|
33
|
+
"command": "node \"${CLAUDE_PROJECT_DIR:-.}/.rulesync/hooks/guard-comments.mjs\""
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"type": "command",
|
|
37
|
+
"matcher": "Task|Agent",
|
|
38
|
+
"command": "node \"${CLAUDE_PROJECT_DIR:-.}/.rulesync/hooks/guard-subagent.mjs\""
|
|
39
|
+
}
|
|
8
40
|
],
|
|
9
|
-
"postToolUse": [
|
|
41
|
+
"postToolUse": [
|
|
42
|
+
{
|
|
43
|
+
"type": "command",
|
|
44
|
+
"matcher": "Edit|Write|MultiEdit|NotebookEdit",
|
|
45
|
+
"command": "node \"${CLAUDE_PROJECT_DIR:-.}/.rulesync/hooks/post-edit.mjs\""
|
|
46
|
+
}
|
|
47
|
+
]
|
|
10
48
|
}
|
|
11
49
|
}
|