your-cto-jev 0.18.2 → 0.19.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/README.md +3 -2
- package/dist/brief.js +3 -2
- package/dist/i18n.js +2 -2
- package/dist/index.js +11 -0
- package/dist/skill.js +9 -9
- package/dist/tests.js +139 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -140,6 +140,7 @@ cto check # preview the commit checks on your cur
|
|
|
140
140
|
cto log # recent decisions with scores; cto report [n] flags a wrong one
|
|
141
141
|
cto index # regenerate docs/cto_jev/INDEX.md (brief does this too)
|
|
142
142
|
cto docs # suggest what to do with old planning markdown; changes nothing
|
|
143
|
+
cto tests # Jev screens test files against their SPEC and for repeats; changes nothing
|
|
143
144
|
```
|
|
144
145
|
|
|
145
146
|
`setup` appends marked blocks and merges JSON. It never overwrites your existing hooks or settings, and `--uninstall` puts them back exactly as they were. The one exception is the model split in global scope (the default): it is shared by every project, so uninstalling one project keeps the user-level split, the `cto-reviewer` agent and the SessionStart hook. Before removing cto, run `cto models scope local`, which clears them. It never touches your shell rc files.
|
|
@@ -264,9 +265,9 @@ The skill gives the agent seven named jobs, so they cannot be confused with anot
|
|
|
264
265
|
| `cto-jev init` | scans the repo, fills PRODUCT.md and ARCHITECTURE.md, asks you the rest a few questions at a time, walks you through the result until you say it is complete |
|
|
265
266
|
| `cto-jev feature` | talks the CONCEPT through first (who it is for, business rules, what the user sees when it works, what is out of scope, the simpler option it rejected), writes CONCEPT, then writes the SPEC itself (data migration and rollback, what other features may call, how a production failure gets noticed, the acceptance scenarios), has a zero-context reviewer check that a newcomer could build from them without making design decisions, that nothing unneeded or already in the code gets built and that every acceptance scenario has a result a script can check and a CONCEPT rule behind it, walks you through the CONCEPT, hands it over with a [Review handoff](#sign-off) and stops for your sign-off |
|
|
266
267
|
| `cto-jev tasks` | breaks a feature with a signed-off CONCEPT into parent/child tasks with files, dependencies and an acceptance command each |
|
|
267
|
-
| `cto-jev work` | dispatches Ready tasks to sub-agents with the narrowest brief, runs each acceptance command itself before ticking (only the wave's own tasks and the `e2e/<slug>/` tests of the features it touches; the whole suites run once per feature cleanup and at release; until a repo's e2e tests are split into `e2e/<slug>/`, each wave runs the whole e2e suite; `cto brief` flags tests outside every feature folder (the `e2e/` root or a flat `e2e/tests/`) and the final report asks whether to split them, `"e2e_folders": false` in `.cto.json` keeps them flat), never opens a question menu mid-run, has a zero-context reviewer read the diff **before every commit**: P1 findings are fixed first, then the whole change reviewed again by `cto-reviewer` (at most three rounds in all; P1s left after that go to you), P2 findings become tasks that wait until the feature has nothing else Ready and then run as one cleanup wave with one review (what that review finds below P1 is written into REVIEW.md and listed for you, not filed as tasks, so findings never chain), a finding is contested only with evidence the reviewer could read, then it commits the wave to the review branch and starts the next one, without asking, until nothing is Ready; tasks that need you (credentials, money, anything irreversible, a drop) are parked, not waited on; ends with one report of what is done and everything for you to look at. Never releases |
|
|
268
|
+
| `cto-jev work` | dispatches Ready tasks to sub-agents with the narrowest brief, runs each acceptance command itself before ticking (only the wave's own tasks and the `e2e/<slug>/` tests of the features it touches; the whole suites run once per feature cleanup and at release; until a repo's e2e tests are split into `e2e/<slug>/`, each wave runs the whole e2e suite; `cto brief` flags tests outside every feature folder (the `e2e/` root or a flat `e2e/tests/`) and the final report asks whether to split them, `"e2e_folders": false` in `.cto.json` keeps them flat), never opens a question menu mid-run, has a zero-context reviewer read the diff **before every commit**: P1 findings are fixed first, then the whole change reviewed again by `cto-reviewer` (at most three rounds in all; P1s left after that go to you), P2 findings become tasks that wait until the feature has nothing else Ready and then run as one cleanup wave with one review (what that review finds below P1 is written into REVIEW.md and listed for you, not filed as tasks, so findings never chain), a finding is contested only with evidence the reviewer could read; a review with no P1 left is committed with no code change in between, a fix made in conversation is reviewed and committed before new work, and no new wave starts while code waits for review; sub-agents and the reviewer never run a whole test suite; then it commits the wave to the review branch and starts the next one, without asking, until nothing is Ready; tasks that need you (credentials, money, anything irreversible, a drop) are parked, not waited on; ends with one report of what is done and everything for you to look at. Never releases |
|
|
268
269
|
| `cto-jev work all` | for a new project or a big batch: the same run on a `work-all` branch, every wave reviewed by a zero-context `cto-reviewer` before its commit, then hands over to `cto-jev release`, never merges. Never releases |
|
|
269
|
-
| `cto-jev release` | reviews the whole unreleased diff against the SPECs (looking hardest at waves marked `self-review`), files P1/P2/P3 tasks under the same findings rules, requires every P1 ticked and `cto check --base <release branch>` green, then prepares the merge, PR or tag for you to perform |
|
|
270
|
+
| `cto-jev release` | reviews the whole unreleased diff against the SPECs (looking hardest at waves marked `self-review`), files P1/P2/P3 tasks under the same findings rules, requires every P1 ticked and `cto check --base <release branch>` green, audits the tests (`cto tests` screens with Jev, an agent proposes keep, merge, delete or lighter for the flagged and slowest files, you decide), then prepares the merge, PR or tag for you to perform |
|
|
270
271
|
| `cto-jev docs` | runs `cto docs` and brings you the list; acts only on what you decide |
|
|
271
272
|
|
|
272
273
|
"Release" adapts to the branches you have. A solo repo with only `main`: the wave review before each commit is the gate, and a release is a tag. `main` plus feature branches: the PR is the release. `main` plus `review`/`develop`/`staging`: merging the integration branch into `main`. `staging` and `live`: promoting one to the other. In every case the branch that reaches users takes nothing without a release review, and that is the branch to put in `protected_branches`. Changes inside an existing feature only add tasks; only a new module gets a new folder. The first time it runs it scans the repo, fills PRODUCT.md and ARCHITECTURE.md with what it can prove, asks you the rest a few questions at a time, and walks you through the result until you say it is complete. `unknown` is an allowed answer.
|
package/dist/brief.js
CHANGED
|
@@ -4,7 +4,7 @@ import { join } from 'node:path';
|
|
|
4
4
|
import { freshErrors, loadBrain, loadConfig } from './brain.js';
|
|
5
5
|
import { FEATURE_FILES, FLOW_DIR, featureIndex, listFeatures, loadTasks, openTasks, parallelTasks, writeIndex } from './flow.js';
|
|
6
6
|
import { loadLessons, packageManager, rankLessons } from './lessons.js';
|
|
7
|
-
import { BOX } from './turn.js';
|
|
7
|
+
import { BOX, isManualAccept } from './turn.js';
|
|
8
8
|
// `cto brief`: what an agent should know before it starts working in this repo. Read by agents (Claude Code gets it
|
|
9
9
|
// at SessionStart), so it is English only and fits on one screen.
|
|
10
10
|
const git = (cwd, ...args) => {
|
|
@@ -147,7 +147,8 @@ export function flowIssues(root) {
|
|
|
147
147
|
headings(`features/${slug}/SPEC.md`, ['Interface', 'Constraints', 'Internals']);
|
|
148
148
|
headings(`features/${slug}/CONCEPT.md`, ['目的']);
|
|
149
149
|
// An open task accepted end to end or by eye has no scenario to test against without ## Acceptance, so its test gets invented.
|
|
150
|
-
|
|
150
|
+
// shortcut: `\be2e\b` also counts a unit test named e2e-helpers; keeping `test-e2e` and `e2e-ci` scripts matters more, and a false hit only lists this issue.
|
|
151
|
+
const userFacing = tasks.some((t) => t.feature === slug && !t.done && (/\be2e\b|playwright|cypress/i.test(t.accept ?? '') || isManualAccept(t.accept)));
|
|
151
152
|
let spec = '';
|
|
152
153
|
try {
|
|
153
154
|
spec = readFileSync(join(root, FLOW_DIR, 'features', slug, 'SPEC.md'), 'utf8');
|
package/dist/i18n.js
CHANGED
|
@@ -276,7 +276,7 @@ const messages = {
|
|
|
276
276
|
doc_bad: () => '[cto] 有問題需要處理:',
|
|
277
277
|
update_available: (v) => `[cto] 有新版 ${v.latest}(目前 ${v.current}),執行 cto update 更新`,
|
|
278
278
|
update_done: () => '[cto] 已更新。已設定過的專案不用重跑 cto setup。',
|
|
279
|
-
usage: () => '用法:cto brief | cto check [--base origin/main] | cto log | cto report [n] | cto doctor | cto index | cto docs | cto models | cto update | cto --version | cto setup [--refresh] [--agents claude,cursor,gemini,codex] [--flow|--no-flow] [--yes] [--uninstall] | cto --hook <git-commit|AGENT-pre|AGENT-post>',
|
|
279
|
+
usage: () => '用法:cto brief | cto check [--base origin/main] | cto log | cto report [n] | cto doctor | cto index | cto docs | cto tests | cto models | cto update | cto --version | cto setup [--refresh] [--agents claude,cursor,gemini,codex] [--flow|--no-flow] [--yes] [--uninstall] | cto --hook <git-commit|AGENT-pre|AGENT-post>',
|
|
280
280
|
prefs_broken: (v) => `[cto] ${v.path} 不是有效的 JSON,裡面有 API key,cto 不會覆寫它。修好或刪掉後再試一次。`,
|
|
281
281
|
models_unset: () => '(未設定)',
|
|
282
282
|
models_fixed: (v) => `${v.key} ${v.from} → ${v.to}(下次開 session 生效)`,
|
|
@@ -558,7 +558,7 @@ const messages = {
|
|
|
558
558
|
doc_bad: () => '[cto] Needs attention:',
|
|
559
559
|
update_available: (v) => `[cto] Version ${v.latest} is available (you have ${v.current}). Run cto update`,
|
|
560
560
|
update_done: () => '[cto] Updated. Projects already set up do not need cto setup again.',
|
|
561
|
-
usage: () => 'Usage: cto brief | cto check [--base origin/main] | cto log | cto report [n] | cto doctor | cto index | cto docs | cto models | cto update | cto --version | cto setup [--refresh] [--agents claude,cursor,gemini,codex] [--flow|--no-flow] [--yes] [--uninstall] | cto --hook <git-commit|AGENT-pre|AGENT-post>',
|
|
561
|
+
usage: () => 'Usage: cto brief | cto check [--base origin/main] | cto log | cto report [n] | cto doctor | cto index | cto docs | cto tests | cto models | cto update | cto --version | cto setup [--refresh] [--agents claude,cursor,gemini,codex] [--flow|--no-flow] [--yes] [--uninstall] | cto --hook <git-commit|AGENT-pre|AGENT-post>',
|
|
562
562
|
prefs_broken: (v) => `[cto] ${v.path} is not valid JSON and holds API keys, so cto will not overwrite it. Fix or delete it, then try again.`,
|
|
563
563
|
models_unset: () => '(unset)',
|
|
564
564
|
models_fixed: (v) => `${v.key} ${v.from} → ${v.to} (takes effect next session)`,
|
package/dist/index.js
CHANGED
|
@@ -283,6 +283,17 @@ else if (args[0] === 'brief') {
|
|
|
283
283
|
console.log(brief(root).join('\n'));
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
|
+
else if (args[0] === 'tests') {
|
|
287
|
+
const root = gitRoot(process.cwd());
|
|
288
|
+
if (!root) {
|
|
289
|
+
process.stderr.write(t(lang, 'setup_not_git') + '\n');
|
|
290
|
+
process.exitCode = 1;
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
const { runTests } = await import('./tests.js');
|
|
294
|
+
console.log((await runTests(root, lang)).join('\n'));
|
|
295
|
+
}
|
|
296
|
+
}
|
|
286
297
|
else if (args[0] === 'index' || args[0] === 'docs') {
|
|
287
298
|
const root = gitRoot(process.cwd());
|
|
288
299
|
if (!root) {
|
package/dist/skill.js
CHANGED
|
@@ -34,8 +34,8 @@ ${SKILL_HEAD}
|
|
|
34
34
|
You review changes you have never seen, with no context beyond the repository and the request. Do not trust the author's intent or the request's claims; check the code.
|
|
35
35
|
|
|
36
36
|
1. Run \`git status\` and \`git diff HEAD\` to see what changed, then read the changed files and the code that calls them.
|
|
37
|
-
2. Look for wrong logic, missed edge cases, broken callers, security holes, data loss, and tests that were skipped, deleted or loosened.
|
|
38
|
-
3. Never edit, write or delete anything. Use Bash only for read-only commands (git diff, git log, git show, running the
|
|
37
|
+
2. Look for wrong logic, missed edge cases, broken callers, security holes, data loss, and tests that were skipped, deleted or loosened. A new test that repeats what an existing test already checks, a new test file where the existing test file for that code would do, or a test heavier than it needs (a real database or server where a unit test would check the same thing) is a P2.
|
|
38
|
+
3. Never edit, write or delete anything. Use Bash only for read-only commands (git diff, git log, git show, running a single test file of the changed code). Never run a whole test suite: the author already ran the acceptance commands, and a whole suite run beside another one can share its test database and break both.
|
|
39
39
|
|
|
40
40
|
Output one finding per line, each starting with P1 (must fix: a bug, a security hole, data loss), P2 (should fix) or P3 (minor), then \`file:line\` and the problem in one sentence. A P1 or P2 about behaviour names the input or state that produces the wrong result; a behaviour concern you cannot tie to one is not reported. A test that was skipped, deleted or loosened, a broken Constraint or Interface, and code that does something the CONCEPT does not say need no such input: report them as they are. Nothing else before or after. No findings: write \`No findings.\`
|
|
41
41
|
`,
|
|
@@ -79,7 +79,7 @@ Read \`${FLOW_SKILL_PATH}\` in full, then do the job named here: $ARGUMENTS
|
|
|
79
79
|
No job named: run \`cto brief\`, say in two lines where this repo stands in the flow, and name the one job to run next.
|
|
80
80
|
`;
|
|
81
81
|
/** The one extra rule when `cto setup` chose the development flow: the plan lives in docs/cto_jev/. */
|
|
82
|
-
export const FLOW_RULE = `- **Work is planned in \`docs/cto_jev/\`.** Before planning, breaking down, dispatching or accepting work, read \`${FLOW_SKILL_PATH}\`; \`cto brief\` lists what is ready.`;
|
|
82
|
+
export const FLOW_RULE = `- **Work is planned in \`docs/cto_jev/\`.** Before planning, breaking down, dispatching or accepting work, read \`${FLOW_SKILL_PATH}\`; \`cto brief\` lists what is ready. A fix you make in conversation (the user reports a bug) gets a task line with an acceptance command and is reviewed and committed before the user moves on to other work, not left in the tree for the next run.`;
|
|
83
83
|
export const rulesBlock = (flow) => `${MD_START}
|
|
84
84
|
## Rules guarded by cto
|
|
85
85
|
|
|
@@ -283,12 +283,12 @@ Branches: work on an integration branch (\`review\`, or whatever the repo calls
|
|
|
283
283
|
|
|
284
284
|
Every wave, one after another, until nothing is Ready. Do not ask before a wave and do not stop between waves; the steps below are one wave.
|
|
285
285
|
|
|
286
|
-
1. If the tree holds uncommitted code from ticked tasks (a wave left for a Claude Code session): a Claude Code session reviews it with \`cto-reviewer\` and commits it (steps 5 and 6) before dispatching anything new. Any other agent stops here, reports that the wave is still waiting for a Claude Code session, and dispatches nothing new. Otherwise \`cto brief\`. Dispatch only Ready tasks, skipping the ones you parked (see "Where you stop"); the "run together" set is safe to run at once. P1 tasks go first. Review-finding tasks below P1 wait while their feature has any other Ready task you would dispatch, then run as that feature's cleanup wave (see "Review findings"). A cleanup wave runs alone: no other feature's tasks and no non-finding tasks join it. Say in one line what this wave runs, then run it.
|
|
287
|
-
2. One sub-agent per task. Give it only: the task line, the feature's SPEC.md, the \`## Interface\` of each feature it depends on, the list of files it may touch, and "do not edit anything else, write nothing outside this repo (no notes, no lesson logs), no git commands; report what you changed and what you found ambiguous". Each sub-agent writes its own new test file; nobody appends to a shared one. A task accepted by an end-to-end test also gets the Acceptance lines it covers: the test is written from them first and seen failing, then the code.
|
|
286
|
+
1. If the tree holds uncommitted code, from ticked tasks (a wave left for a Claude Code session) or from fixes made in conversation (add a task line for those, with an acceptance command like any task, and tick it once that passes, in the TASKS.md of the feature whose files they change, or \`platform\`'s when they span several features or none): a Claude Code session reviews it with \`cto-reviewer\` and commits it (steps 5 and 6) before dispatching anything new. Never dispatch a task of a new wave while a wave's code waits for its review or commit (that wave's own remaining tasks, its reviewer and the P1 fixes of step 5 still run): another agent's edit changes the tree that review covers, and the whole change has to be reviewed again. Any other agent stops here, reports that the wave is still waiting for a Claude Code session, and dispatches nothing new. Otherwise \`cto brief\`. Dispatch only Ready tasks, skipping the ones you parked (see "Where you stop"); the "run together" set is safe to run at once. P1 tasks go first. Review-finding tasks below P1 wait while their feature has any other Ready task you would dispatch, then run as that feature's cleanup wave (see "Review findings"). A cleanup wave runs alone: no other feature's tasks and no non-finding tasks join it. Say in one line what this wave runs, then run it.
|
|
287
|
+
2. One sub-agent per task. Give it only: the task line, the feature's SPEC.md, the \`## Interface\` of each feature it depends on, the list of files it may touch, and "do not edit anything else, write nothing outside this repo (no notes, no lesson logs), no git commands, run only your task's acceptance command and the test file you wrote, never a whole test suite (other agents run tests at the same time, and whole suites can share one test database); report what you changed and what you found ambiguous". Each sub-agent writes its own new test file; nobody appends to a shared one. A task accepted by an end-to-end test also gets the Acceptance lines it covers: the test is written from them first and seen failing, then the code.
|
|
288
288
|
3. When they return: \`git status\`; revert anything outside the union of their \`(files:)\`. Integrate the shared files yourself. Fix any existing test their change broke. A sub-agent's "the SPEC does not say" goes into the SPEC now, not into the code's comments.
|
|
289
289
|
4. Accept by running the task's acceptance command yourself; never trust the report. Tick only on a pass. A wave runs only its own tasks' acceptance commands plus the end-to-end tests of the features it touches (\`e2e/<slug>/\`); when it changes a \`platform\` file or a shared file you integrated (step 3), run the whole end-to-end suite instead. The whole unit and end-to-end suites run once in a feature's cleanup wave and once in the release, never in every wave. Like a wave that changes a \`platform\` or shared file, a wave that touches a feature whose end-to-end tests are not yet in \`e2e/<slug>/\` runs the whole end-to-end suite. When \`cto brief\` lists test files outside every feature folder (in the \`e2e/\` root or a flat folder such as \`e2e/tests/\`), do not move them on your own: put "split the end-to-end tests into feature folders?" in the run's final report menu, with how many files and how long the whole suite takes. If the user says yes, add a \`platform\` task for the split whose text starts exactly \`Split the end-to-end tests into feature folders\`, in English whatever language the rest of TASKS.md uses (brief knows it by that text and stops asking while it is open), tagged \`(seq)\`, whose \`(files:)\` hold \`e2e/\` plus each file that holds the test runner's file pattern (\`playwright.config.ts\`, \`package.json\`); it runs as a wave of its own, reviewed and committed alone. The split goes test by test, not file by file: a test goes into the folder of the feature whose task ids or Acceptance scenario it tests; a test that walks through several features goes to the feature whose SPEC holds its scenario; a check of the whole app (smoke, error page, layout of every page, the test harness) goes to \`e2e/platform/\`; shared helpers stay in the root. Update imports, the test runner's file pattern (a root-only glob such as \`e2e/*.test.ts\` finds nothing in subfolders) and open tasks' acceptance paths; the whole end-to-end suite must pass with as many tests as before. If the user says no, set \`"e2e_folders": false\` in \`.cto.json\`: brief stops listing them, and every wave keeps running the whole end-to-end suite. A failing end-to-end test means the code is wrong. If you think the expectation is wrong instead, the CONCEPT decides: where it backs the scenario, the code is wrong after all; where it says otherwise, fix the SPEC's Acceptance first, then the test, and note it in the wave's REVIEW.md entry; where it is silent, do the same and add an \`Assumed: ...\` line. Never change a test to match the code without changing the Acceptance line it came from. \`manual\` does not wait for the user: build it, run what can be run, take screenshots at each width the Acceptance names, and tick it. cto reminds the user with the text on its acceptance line, and your final report lists every manual task of the run with that text and the screenshot paths. A task the user decided not to do: add \`(dropped: <reason>)\` to its line, tick it, and say "<id> dropped" in your final message. Dropping is the user's call: a task you think is no longer needed (what it checks is gone) is parked and listed in your report with that reason, never dropped by you; never drop a task to get past a block. A dropped task counts as closed, so the tasks that wait on it (\`(after:)\`) become Ready: drop or re-plan them first. Tick the parent when its last child is ticked.
|
|
290
|
-
5. **Review before you commit.** Before dispatching, run the project's formatter, if any, so the review sees the final tree. Then dispatch \`subagent_type: "cto-reviewer"\` with no model parameter (it runs on Opus), with none of your context: it reads the feature's CONCEPT.md and SPEC.md and the whole uncommitted change of the wave, and returns findings each marked P1 (wrong, unsafe, breaks a Constraint or the Interface, does something the CONCEPT does not say or contradicts, or an acceptance test that would still pass with its scenario broken)
|
|
291
|
-
6. \`cto check\`, then commit the wave to the review branch.
|
|
290
|
+
5. **Review before you commit.** Before dispatching, run the project's formatter, if any, so the review sees the final tree. Then dispatch \`subagent_type: "cto-reviewer"\` with no model parameter (it runs on Opus), with none of your context: it reads the feature's CONCEPT.md and SPEC.md and the whole uncommitted change of the wave, and returns findings each marked P1 (wrong, unsafe, breaks a Constraint or the Interface, does something the CONCEPT does not say or contradicts, or an acceptance test that would still pass with its scenario broken), P2 (should improve, can wait) or P3 (minor). You wrote both the code and its tests, so the reviewer answers one question per acceptance test: if the scenario were not met, would this test fail. Handle them as under "Review findings": fix every P1 now and re-run acceptance; write every P2 and P3 as a task with its severity (\`(P2)\`, \`(P3)\`) in TASKS.md whose text starts with exactly \`Review finding (wave <ids>):\`, in English whatever language the rest of TASKS.md uses. A cleanup wave's review is the exception: its P2s and P3s become no task and go under \`Left for the user:\` instead (see "Review findings"). Append one entry to REVIEW.md: date, scope (the task ids of the wave), how many P1/P2, which task ids they became, what was contested or escalated. The dispatch prompt names the wave's task ids, every changed path, and the acceptance commands you ran with their results (the reviewer runs no whole suite, so it is never asked to run the verify command from \`cto brief\`); it never dictates the verdict and never drops a changed path. After fixing P1s, run the formatter again before every re-dispatch; then dispatch again on the whole change, never on the fix alone. Where Claude Code is wired and the review gate is on, only a Claude Code session can satisfy the gate, so other agents (with or without sub-agents) hand the wave over as below.
|
|
291
|
+
6. \`cto check\`, then commit the wave to the review branch. A review with no P1 left to fix (none found, or every one contested or escalated in REVIEW.md) is committed as it stands: change no code between it and the commit (REVIEW.md and TASKS.md are not code), since a change to any file the gate counts as code makes it ask for another whole review. A P2 or P3 is a task (in a cleanup wave, a line under \`Left for the user:\`), never a fix made now. Only when \`cto check\` or a git hook blocks the commit and its fix changes code is the whole change reviewed again; that review counts toward the three rounds under "Review findings". The same holds for fixes made in conversation (the user reports a bug and you fix it on the spot): give them a task line with an acceptance command as in step 1, then review and commit them before the user moves on to other work, not at the next run.
|
|
292
292
|
|
|
293
293
|
Without sub-agents: do the Ready tasks yourself in brief's order, one at a time, accepting each before the next; review your own diff against the SPEC before each commit. That is not a review by a fresh reader: write \`self-review\` in its REVIEW.md entry, so the release review looks harder at those waves. Where Claude Code is wired and the review gate is on, a self-review cannot pass the commit gate (the gate needs a cto-reviewer review of the exact tree): keep the wave's tasks ticked, leave the tree uncommitted, stop the run, and say in the final report that the wave is waiting for a cto-reviewer review in a Claude Code session.
|
|
294
294
|
|
|
@@ -299,7 +299,7 @@ Without sub-agents: do the Ready tasks yourself in brief's order, one at a time,
|
|
|
299
299
|
**When:** the user says "cto-jev work all" (\`/cto-jev work all\`), typically on a new project: the same run as \`cto-jev work\` on a branch, every wave reviewed as it is in \`cto-jev work\`; at the end the run hands over to release. Only on request.
|
|
300
300
|
|
|
301
301
|
1. Branch: in a repo with only \`main\`, create a branch \`work-all\` from \`main\` and work there; every other repo uses its integration branch as usual. Note the commit you start from.
|
|
302
|
-
2. Loop until no task is left to run: first, if the tree holds uncommitted code from ticked tasks, a Claude Code session reviews it with \`cto-reviewer\` and commits it before dispatching anything new; any other agent stops there and reports that the wave is still waiting for a Claude Code session. Then re-read \`cto brief\` and the TASKS.md files each round, then run steps 1 to 6 of \`cto-jev work\` (dispatch, integrate, accept, review, commit) for the Ready tasks, skipping tasks you parked (below) and every task of a feature whose CONCEPT is not \`Status: approved\` (cto blocks those commits; list the feature instead). Every wave is reviewed before its commit: after the wave's tasks are accepted, the \`cto-reviewer\` review of step 5 runs, P1s are fixed, the whole change is re-reviewed, then the wave is committed and the run continues. \`cto check\` and the git hooks still run on every commit. Without sub-agents, do the tasks yourself in brief's order; each wave's review is then a \`self-review\`. Where Claude Code is wired and the review gate is on, a self-review cannot pass the commit gate (the gate needs a cto-reviewer review of the exact tree): keep the wave's tasks ticked, leave the tree uncommitted, stop the run, and say in the final report that the wave is waiting for a cto-reviewer review in a Claude Code session.
|
|
302
|
+
2. Loop until no task is left to run: first, if the tree holds uncommitted code from ticked tasks or from fixes made in conversation (step 1 of \`cto-jev work\`), a Claude Code session reviews it with \`cto-reviewer\` and commits it before dispatching anything new; any other agent stops there and reports that the wave is still waiting for a Claude Code session. Then re-read \`cto brief\` and the TASKS.md files each round, then run steps 1 to 6 of \`cto-jev work\` (dispatch, integrate, accept, review, commit) for the Ready tasks, skipping tasks you parked (below) and every task of a feature whose CONCEPT is not \`Status: approved\` (cto blocks those commits; list the feature instead). Every wave is reviewed before its commit: after the wave's tasks are accepted, the \`cto-reviewer\` review of step 5 runs, P1s are fixed, the whole change is re-reviewed, then the wave is committed and the run continues. \`cto check\` and the git hooks still run on every commit. Without sub-agents, do the tasks yourself in brief's order; each wave's review is then a \`self-review\`. Where Claude Code is wired and the review gate is on, a self-review cannot pass the commit gate (the gate needs a cto-reviewer review of the exact tree): keep the wave's tasks ticked, leave the tree uncommitted, stop the run, and say in the final report that the wave is waiting for a cto-reviewer review in a Claude Code session.
|
|
303
303
|
3. Fix along the way: a failing acceptance or a broken test is yours to fix before moving on. The same failure twice means a different approach, not a third try.
|
|
304
304
|
4. Never stop for the user mid-run: park the task instead. Parked means unticked, never dispatched again in this run, and its dependants wait too (they are not Ready while it is unticked). The parked ids live only in this conversation; the final report lists them, and the next run starts without them. Park a task when:
|
|
305
305
|
- it needs a decision that would contradict the signed CONCEPT. Do not edit the CONCEPT or its \`Status:\` line in this run. A gap the CONCEPT leaves open you decide yourself, in any SPEC section (\`## Interface\`, \`## Constraints\`, \`## Acceptance\`, \`## Internals\`): write it there as \`Assumed: ...\`;
|
|
@@ -343,7 +343,7 @@ Whatever the row, one rule holds: the branch that reaches users receives nothing
|
|
|
343
343
|
1. Everything to be released is on the work branch and every P1 task is ticked. If not, run \`cto-jev work\` first; what it parks goes into this release's report. If a P1 is still open after that (parked), the release ends here: report it with the parked list, no merge.
|
|
344
344
|
2. Dispatch \`subagent_type: "cto-reviewer"\` with no model parameter and none of your context over the whole unreleased diff (the review scope above) plus the SPECs of every feature it touches; point it at the waves marked \`self-review\` in REVIEW.md. Findings get P1, P2 or P3, handled as under "Review findings", written into TASKS.md.
|
|
345
345
|
3. P1 findings are fixed (through \`cto-jev work\`, whose wave review counts as the re-review) before anything else; P2 and P3 stay as tasks for after the release. Tell the user both lists and let them decide which P2 should move up. With them, everything collected since the last release that only the user can judge, grouped by feature: every \`Assumed:\` line added, every \`manual\` task ticked (what to look at and where, from its acceptance line), every finding left unfixed for their decision. This is the one place the user reads them.
|
|
346
|
-
4. The whole unit and end-to-end suites and \`cto check --base <release branch>\` must pass. Then prepare the merge, PR or tag; the user performs it. Append one REVIEW.md entry per feature released: date, "release", counts, task ids, what was contested or escalated.
|
|
346
|
+
4. The whole unit and end-to-end suites and \`cto check --base <release branch>\` must pass; note each test file's time from the runner's per-file output. Then audit the tests: \`cto tests\` has Jev screen every feature test file against its SPEC and every pair such as \`windows\` / \`windows-hardening\` for repeats. Dispatch one agent with none of your context over the files it flags plus the ten slowest files; for each it answers keep, merge into another file (which), delete, or make lighter (a unit test where a database or server is not needed), naming the SPEC line the test traces to or saying that none does. Its list goes into the release report as one decision for the user; nothing is merged, deleted or rewritten until the user picks it, and a test that backs an Acceptance line goes only after that line is changed. Then prepare the merge, PR or tag; the user performs it. Append one REVIEW.md entry per feature released: date, "release", counts, task ids, what was contested or escalated.
|
|
347
347
|
|
|
348
348
|
**Stop:** before the merge, with the P1/P2/P3 lists in front of the user.
|
|
349
349
|
|
package/dist/tests.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { basename, dirname, join } from 'node:path';
|
|
4
|
+
import { evaluate } from './api.js';
|
|
5
|
+
import { loadBrain, saveKeeping } from './brain.js';
|
|
6
|
+
import { estimateTokens } from './diff.js';
|
|
7
|
+
import { FLOW_DIR } from './flow.js';
|
|
8
|
+
import { maskSensitiveState } from './masker.js';
|
|
9
|
+
// `cto tests`: Jev screens test files for the release's test audit. It only flags files; an agent reads the flagged
|
|
10
|
+
// ones and the user decides what goes (cto's test_tampering blocks an agent deleting tests on its own).
|
|
11
|
+
// shortcut: thresholds are uncalibrated guesses; set them from the first audits' agent verdicts.
|
|
12
|
+
const UNTRACED_MIN = 0.6;
|
|
13
|
+
const REPEATS_MIN = 0.6;
|
|
14
|
+
const PART_TOKENS = 7000; // a test file; two of them for a pair
|
|
15
|
+
const SPEC_TOKENS = 12000; // with a test file, inside Jev's 24k chunk
|
|
16
|
+
const TEST_FILE = /\.(test|spec|cy)\.[cm]?[jt]sx?$/;
|
|
17
|
+
const UNTRACED = {
|
|
18
|
+
untraced: { type: 'noul', instructions: 'Do several tests in this test file check behaviour that no line of this SPEC (Interface, Constraints, Acceptance) asks for?' },
|
|
19
|
+
};
|
|
20
|
+
const REPEATS = {
|
|
21
|
+
repeats: { type: 'noul', instructions: 'Do most tests in the second test file check what tests in the first test file already check?' },
|
|
22
|
+
};
|
|
23
|
+
function clip(s, tokens = PART_TOKENS) {
|
|
24
|
+
let n = s.length;
|
|
25
|
+
while (n > 0 && estimateTokens(s.slice(0, n)) > tokens)
|
|
26
|
+
n = Math.floor(n * 0.8);
|
|
27
|
+
return s.slice(0, n);
|
|
28
|
+
}
|
|
29
|
+
const read = (root, f) => { try {
|
|
30
|
+
return readFileSync(join(root, f), 'utf8');
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return '';
|
|
34
|
+
} };
|
|
35
|
+
/** Tracked test files, each with the feature whose slug is one of its folder names (none when no folder matches). */
|
|
36
|
+
export function testFiles(root) {
|
|
37
|
+
let files = [];
|
|
38
|
+
try {
|
|
39
|
+
files = execFileSync('git', ['ls-files', '-z'], { cwd: root, encoding: 'utf8', maxBuffer: 64 << 20 }).split('\0');
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
const dir = join(root, FLOW_DIR, 'features');
|
|
45
|
+
const features = new Set(existsSync(dir) ? readdirSync(dir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name) : []);
|
|
46
|
+
return files.filter((f) => TEST_FILE.test(f) && !f.split('/').includes('node_modules'))
|
|
47
|
+
.map((file) => ({ file, feature: file.split('/').slice(0, -1).find((s) => features.has(s)) }));
|
|
48
|
+
}
|
|
49
|
+
const terms = (s) => new Set([
|
|
50
|
+
...(s.match(/[A-Za-z_][\w/.-]{3,}/g) ?? []).map((w) => w.toLowerCase()),
|
|
51
|
+
...[...s.matchAll(/(?=([ -鿿]{2}))/g)].map((m) => m[1]),
|
|
52
|
+
]);
|
|
53
|
+
/**
|
|
54
|
+
* The SPEC sections a test should trace to. A big SPEC (meantte's chart: 22k tokens) does not fit beside the test, and a
|
|
55
|
+
* clipped one hides the lines the test traces to, so then only the lines sharing a word or a CJK pair with the test go,
|
|
56
|
+
* the most shared first, kept in SPEC order.
|
|
57
|
+
*/
|
|
58
|
+
export function specParts(spec, test, tokens = SPEC_TOKENS) {
|
|
59
|
+
const parts = spec.split(/^(?=## )/m).filter((s) => /^## (Interface|Constraints|Acceptance)\b/.test(s)).join('');
|
|
60
|
+
if (estimateTokens(parts) <= tokens)
|
|
61
|
+
return parts;
|
|
62
|
+
const want = terms(test);
|
|
63
|
+
const lines = parts.split('\n').map((line, i) => ({ line, i, hits: line.startsWith('## ') ? Infinity : [...terms(line)].filter((w) => want.has(w)).length }));
|
|
64
|
+
const keep = new Set();
|
|
65
|
+
let used = 0;
|
|
66
|
+
for (const l of [...lines].filter((l) => l.hits > 0).sort((a, b) => b.hits - a.hits)) {
|
|
67
|
+
const n = estimateTokens(l.line) + 1;
|
|
68
|
+
if (used + n > tokens)
|
|
69
|
+
continue;
|
|
70
|
+
keep.add(l.i);
|
|
71
|
+
used += n;
|
|
72
|
+
}
|
|
73
|
+
return lines.filter((l) => keep.has(l.i)).map((l) => l.line).join('\n');
|
|
74
|
+
}
|
|
75
|
+
/** Same folder, and one name is the other's stem plus a suffix: `windows` and `windows-hardening`, `auth` and `auth-language`. */
|
|
76
|
+
export function relatedPairs(files) {
|
|
77
|
+
const stem = (f) => basename(f).replace(TEST_FILE, '');
|
|
78
|
+
const out = [];
|
|
79
|
+
for (const a of files)
|
|
80
|
+
for (const b of files) {
|
|
81
|
+
if (a === b || dirname(a) !== dirname(b))
|
|
82
|
+
continue;
|
|
83
|
+
if (stem(b).startsWith(`${stem(a)}-`) || stem(b).startsWith(`${stem(a)}.`))
|
|
84
|
+
out.push([a, b]);
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
const noul = (r, k) => {
|
|
89
|
+
const a = r?.ok ? r.answers[k] : undefined;
|
|
90
|
+
return a?.type === 'noul' && typeof a.noul === 'number' ? a.noul : NaN;
|
|
91
|
+
};
|
|
92
|
+
/** One Jev request per test file of a feature and one per related pair, sequentially. A failed call is `unchecked`. */
|
|
93
|
+
export async function screenTests(root, ctx) {
|
|
94
|
+
const all = testFiles(root);
|
|
95
|
+
const flags = [];
|
|
96
|
+
let screened = 0;
|
|
97
|
+
for (const { file, feature } of all) {
|
|
98
|
+
if (!feature)
|
|
99
|
+
continue;
|
|
100
|
+
const test = clip(maskSensitiveState(read(root, file))); // mask before clipping: a key cut at the clip point no longer matches its pattern
|
|
101
|
+
const spec = specParts(read(root, `${FLOW_DIR}/features/${feature}/SPEC.md`), test);
|
|
102
|
+
// Headings alone (no section, or a big SPEC with no line sharing a word with the test): Jev would judge an empty SPEC.
|
|
103
|
+
if (!spec.split('\n').some((l) => l.trim() && !l.startsWith('## ')))
|
|
104
|
+
continue;
|
|
105
|
+
screened++;
|
|
106
|
+
const state = maskSensitiveState(`SPEC of feature ${feature} (Interface, Constraints, Acceptance):\n${spec}\n\nTest file ${file}:\n${test}`);
|
|
107
|
+
const p = noul(await evaluate({ state, questions: UNTRACED }, ctx).catch(() => null), 'untraced');
|
|
108
|
+
if (Number.isNaN(p))
|
|
109
|
+
flags.push({ file, kind: 'unchecked', score: 0 });
|
|
110
|
+
else if (p >= UNTRACED_MIN)
|
|
111
|
+
flags.push({ file, kind: 'untraced', score: p });
|
|
112
|
+
}
|
|
113
|
+
const pairs = relatedPairs(all.map((f) => f.file));
|
|
114
|
+
for (const [a, b] of pairs) {
|
|
115
|
+
const state = maskSensitiveState(`First test file ${a}:\n${clip(maskSensitiveState(read(root, a)))}\n\nSecond test file ${b}:\n${clip(maskSensitiveState(read(root, b)))}`);
|
|
116
|
+
const p = noul(await evaluate({ state, questions: REPEATS }, ctx).catch(() => null), 'repeats');
|
|
117
|
+
if (Number.isNaN(p))
|
|
118
|
+
flags.push({ file: b, kind: 'unchecked', score: 0, other: a });
|
|
119
|
+
else if (p >= REPEATS_MIN)
|
|
120
|
+
flags.push({ file: b, kind: 'repeats', score: p, other: a });
|
|
121
|
+
}
|
|
122
|
+
return { flags, files: screened, pairs: pairs.length };
|
|
123
|
+
}
|
|
124
|
+
export function renderTests(r, lang = 'en') {
|
|
125
|
+
const zh = lang === 'zh-TW';
|
|
126
|
+
const head = zh ? `[cto] 測試篩檢:${r.files} 個 feature 測試檔、${r.pairs} 組相近檔,Jev 標出 ${r.flags.filter((f) => f.kind !== 'unchecked').length} 個(只是篩選,交給 agent 細看、由使用者決定)`
|
|
127
|
+
: `[cto] Test screen: ${r.files} feature test files, ${r.pairs} related pairs; Jev flagged ${r.flags.filter((f) => f.kind !== 'unchecked').length} (a screen only: an agent reads them, the user decides)`;
|
|
128
|
+
const rows = [...r.flags].sort((a, b) => b.score - a.score).map((f) => f.kind === 'untraced' ? ` ${f.file} ${zh ? '有測試對不到 SPEC' : 'tests no SPEC line asks for'} (${f.score.toFixed(2)})`
|
|
129
|
+
: f.kind === 'repeats' ? ` ${f.file} ${zh ? '大多重複' : 'mostly repeats'} ${f.other} (${f.score.toFixed(2)})`
|
|
130
|
+
: ` ${f.file} ${zh ? 'Jev 無法判斷,請人工看' : 'Jev unavailable; check by hand'}${f.other ? ` (vs ${f.other})` : ''}`);
|
|
131
|
+
return [head, ...rows];
|
|
132
|
+
}
|
|
133
|
+
/** `cto tests`: the screen, then the brain saved with provider cooldowns, as `cto docs` does. */
|
|
134
|
+
export async function runTests(root, lang) {
|
|
135
|
+
const brain = loadBrain(root);
|
|
136
|
+
const r = await screenTests(root, { brain, lang, timeoutMs: 5000, notices: new Set() });
|
|
137
|
+
saveKeeping(root, brain);
|
|
138
|
+
return renderTests(r, lang);
|
|
139
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "your-cto-jev",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "A sharp-tongued CTO gatekeeper for AI coding agents: blocks leaked secrets in git commits and destructive shell commands in Claude Code, Cursor, Gemini CLI and Codex, using TypeSafe Jev.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude-code",
|