your-cto-jev 0.11.0 → 0.12.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 +24 -16
- package/dist/agents.js +3 -1
- package/dist/brain.js +6 -0
- package/dist/brief.js +1 -2
- package/dist/flow.js +20 -6
- package/dist/hooks.js +123 -33
- package/dist/i18n.js +12 -6
- package/dist/local.js +9 -5
- package/dist/setup.js +5 -3
- package/dist/signoff.js +20 -22
- package/dist/skill.js +52 -39
- package/dist/turn.js +63 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@ Jev judges meaning and answers with probabilities, not prose. It costs about $0.
|
|
|
42
42
|
|
|
43
43
|
`test_tampering` catches the classic agent shortcut: making a red test green by skipping it, deleting its assertions, loosening the expectation, or lowering the coverage bar, instead of fixing the code. It lets through real fixes, new or tighter tests, refactors, and tests removed together with their feature.
|
|
44
44
|
|
|
45
|
-
`done_unverified` catches the other classic shortcut: "Done, all tests pass!" when nothing ran after the last edit, the last run failed, or the claim is not backed by anything the agent actually did. It lets through turns that ran a passing check after the last edit, turns that changed only docs or CI config, and turns where the agent honestly says what it could not verify. Checked-off items count even when the agent committed them in the same turn. For a task with an acceptance line (`accept:` or `驗收:`), cto itself works out whether that exact command ran and passed after the last edit and tells Jev, and a `
|
|
45
|
+
`done_unverified` catches the other classic shortcut: "Done, all tests pass!" when nothing ran after the last edit, the last run failed, or the claim is not backed by anything the agent actually did. It lets through turns that ran a passing check after the last edit, turns that changed only docs or CI config, and turns where the agent honestly says what it could not verify. Checked-off items count even when the agent committed them in the same turn. For a task with an acceptance line (`accept:` or `驗收:`), cto itself works out whether that exact command ran and passed after the last edit and tells Jev, and a `(dropped: ...)` task the final message does not report as dropped is sent back without asking Jev at all. A ticked `manual` task never blocks: cto shows you what to look at. A task whose acceptance was a command and is switched to `manual` in the turn it is ticked is judged against that old command (when cto recorded where the turn started; otherwise against the last commit). It blocks at most once per stop, so it cannot loop.
|
|
46
46
|
|
|
47
47
|
Checking off a plan item is the same claim. Whatever planning tool you use (spec-kit, GSD, Kiro, specOS, a hand-written `TODO.md`), plans end up as markdown checklists, so `cto` reads the uncommitted `- [ ]` to `- [x]` changes in tracked `.md` files and asks whether the turn backs them up. A phase or parent item counts as backed when everything nested under it is checked, or when the turn ran a passing check that covers it. Each tick is judged once. A turn that only ticks boxes, without doing the work, is checked too.
|
|
48
48
|
|
|
@@ -56,13 +56,15 @@ Some checks need no model at all. They run first, before anything is sent anywhe
|
|
|
56
56
|
| A `.env` file with values (not `.env.example`) | `git commit` | **Blocks** |
|
|
57
57
|
| A file over 5 MB | `git commit` | Warns |
|
|
58
58
|
| `package.json` dependencies changed, lock file not | `git commit` | Warns |
|
|
59
|
-
| Development flow: a feature with tasks whose CONCEPT
|
|
59
|
+
| Development flow: a feature with tasks whose CONCEPT is not `Status: approved` | `git commit` touching that feature | **Blocks** |
|
|
60
60
|
| Development flow: INDEX.md older than its inputs, an `(after:)` id nobody defines, a SPEC `## Interface` changed | `git commit` | Warns |
|
|
61
61
|
|
|
62
62
|
`protected_branches` is empty by default; set it in `.cto.json` (`["main"]`) and the whole team's agents stop committing to main by accident. A commit a local check blocks never reaches Jev.
|
|
63
63
|
|
|
64
64
|
Architecture and complexity only warn on purpose. They are subjective, and a gate that blocks too often teaches people to use `git commit --no-verify`, which switches off the secret check too.
|
|
65
65
|
|
|
66
|
+
A turn that runs long gets one reminder, never a block. When a turn passes 20 minutes, 150 tool calls or 4 sub-agents since your last message, the agent's next shell command carries `[cto] This turn has run 21 min, 160 tool calls, 2 sub-agents. Stop and tell the user where you are, what is stuck, and what you plan next, before going on.`, and you see `[cto] This turn has run 21 min, 160 tool calls, 2 sub-agents; the agent has been asked to stop and report.` A background agent finishing does not start a new turn. Set the limits in `turn_limits` in `.cto.json`.
|
|
67
|
+
|
|
66
68
|
When nothing crosses a threshold, `cto` prints nothing at all.
|
|
67
69
|
|
|
68
70
|
## How it works
|
|
@@ -233,15 +235,17 @@ A task is one checklist line, and everything else is computed from it:
|
|
|
233
235
|
- [ ] CUST-1.2 List UI (after: CUST-1.1) (files: src/customers/ui/, e2e/customers.spec.ts)
|
|
234
236
|
accept: npx playwright test e2e/customers.spec.ts
|
|
235
237
|
- [ ] CUST-1.3 List matches the brand (look) (after: CUST-1.2) (files: src/customers/ui/)
|
|
236
|
-
accept: manual
|
|
238
|
+
accept: manual: list page against the brand sheet, at 375px and 1280px @ http://localhost:3000/customers
|
|
237
239
|
```
|
|
238
240
|
|
|
239
|
-
You
|
|
241
|
+
You sign one document per feature, the CONCEPT: what it is for, the business rules, what the user sees when it works, what is out of scope. Until you sign it the agent talks with you (the CONCEPT questions); after that it waits for you in one place only: before the merge in `cto-jev release`. The SPEC is the agent's technical document, derived from the CONCEPT; nobody signs it and the agent may change it. Its `## Acceptance` lists each scenario as steps and a result a script can compare ("at 375px wide: no horizontal scroll"), each from a rule in the CONCEPT. A task you would see is accepted by the end-to-end test written from those lines before the code; if the agent thinks an expectation is wrong, the CONCEPT decides, and the Acceptance line changes before the test does. What the CONCEPT leaves open the agent decides and writes down as `Assumed:`; you read those in the release report. `manual` is left for taste (does it look right, does it match the brand) and blocks nothing: its line says what to look at and where (`manual: list page against the brand sheet @ http://localhost:3000/customers`), cto shows you that text when the turn ends, and the release report lists them all. A task that will not be done is closed with `(dropped: <reason>)` on its line, and the agent must say "<id> dropped" in its final message.
|
|
242
|
+
|
|
243
|
+
The trade: fewer stops, later discovery. A SPEC that drifted from what you meant shows up in the release review, not at a mid-way approval, and the agent writes both the code and its tests. The zero-context review before every commit is what stands in for you there: it checks the diff against the CONCEPT and asks of each acceptance test whether it would fail if its scenario broke.
|
|
240
244
|
|
|
241
245
|
`(after:)` says what must be ticked first, across features too; `(files:)` says what the task changes. Two optional tags: `(P1)`/`(P2)`/`(P3)` for priority (P1 first and nothing releases while one is open; no tag means P2; P3 last) and `(seq)` for a task that must run alone (migrations, shared types). From that, `cto brief` lists what is ready in priority order, what can run at the same time (no overlapping files, not `(seq)`), what is blocked and on whom:
|
|
242
246
|
|
|
243
247
|
```text
|
|
244
|
-
Features · 2 · 1 active · 1 planned · sign-off pending: billing (
|
|
248
|
+
Features · 2 · 1 active · 1 planned · sign-off pending: billing (concept draft)
|
|
245
249
|
|
|
246
250
|
Ready · 3 (run together: CUST-1.2, PERM-3)
|
|
247
251
|
CUST-1.2 P1 List UI files src/customers/ui/, e2e/customers.spec.ts accept: npx playwright test e2e/customers.spec.ts
|
|
@@ -257,10 +261,10 @@ The skill gives the agent seven named jobs, so they cannot be confused with anot
|
|
|
257
261
|
| Say | The agent |
|
|
258
262
|
|---|---|
|
|
259
263
|
| `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 |
|
|
260
|
-
| `cto-jev feature` | talks the
|
|
261
|
-
| `cto-jev tasks` | breaks
|
|
262
|
-
| `cto-jev work` | dispatches Ready tasks to sub-agents with the narrowest brief, runs each acceptance command itself before ticking, has a zero-context reviewer read the diff **before every commit**: P1 findings are fixed first (and only the fixes reviewed again, at most three rounds in all; P1s left after that go to you), P2 findings become tasks, a finding is contested only with evidence the reviewer could read, then it commits
|
|
263
|
-
| `cto-jev work all` | for a new project or a big batch:
|
|
264
|
+
| `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 |
|
|
265
|
+
| `cto-jev tasks` | breaks a feature with a signed-off CONCEPT into parent/child tasks with files, dependencies and an acceptance command each |
|
|
266
|
+
| `cto-jev work` | dispatches Ready tasks to sub-agents with the narrowest brief, runs each acceptance command itself before ticking, has a zero-context reviewer read the diff **before every commit**: P1 findings are fixed first (and only the fixes reviewed again, at most three rounds in all; P1s left after that go to you), P2 findings become tasks, 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 |
|
|
267
|
+
| `cto-jev work all` | for a new project or a big batch: the same run on a `work-all` branch with one zero-context review of everything at the end instead of one per wave. Never releases |
|
|
264
268
|
| `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 |
|
|
265
269
|
| `cto-jev docs` | runs `cto docs` and brings you the list; acts only on what you decide |
|
|
266
270
|
| `cto-jev decision` | writes an append-only decision record under `decisions/` |
|
|
@@ -271,9 +275,11 @@ What `cto` adds on top, all without a model call unless noted:
|
|
|
271
275
|
|
|
272
276
|
| Check | Where | What happens |
|
|
273
277
|
|---|---|---|
|
|
274
|
-
| A feature has tasks but its CONCEPT
|
|
278
|
+
| A feature has tasks but its CONCEPT is not approved | `git commit` touching that feature | **Blocks** |
|
|
275
279
|
| The agent sets `Status: approved` itself, or changes signed-off content without going back to draft | Claude Code edit tools and PowerShell | **Blocks** ([sign-off](#sign-off)) |
|
|
276
|
-
| A shell command writes CONCEPT,
|
|
280
|
+
| A shell command writes CONCEPT, PRODUCT or ARCHITECTURE under `docs/cto_jev/` | every agent's shell command | **Blocks** |
|
|
281
|
+
| A `manual` task is ticked | every agent, when the turn ends (Cursor may not display it) | **Tells you** what to look at and where, from the task's acceptance line; never blocks |
|
|
282
|
+
| An open task's acceptance line says only `manual` | `git commit` touching that TASKS.md | Warns: say what to look at |
|
|
277
283
|
| A sign-off doc became `approved` during the turn without your reply (however it was written) | Claude Code, when the turn ends | **Reverts** it to `draft` and tells the agent |
|
|
278
284
|
| `architecture_violation` judged against the feature's `## Constraints` and PRODUCT's non-goals instead of a one-line goal | `git commit` (Jev) | Warns |
|
|
279
285
|
| An architecture change with no new decision record | `git commit` (Jev) | Warns |
|
|
@@ -282,10 +288,10 @@ What `cto` adds on top, all without a model call unless noted:
|
|
|
282
288
|
|
|
283
289
|
### Sign-off
|
|
284
290
|
|
|
285
|
-
CONCEPT,
|
|
291
|
+
CONCEPT, PRODUCT and ARCHITECTURE are signed off when their `Status:` line says `approved`, and only you decide that. SPEC is not signed. Each time the agent wants you to read them it ends with a Review handoff:
|
|
286
292
|
|
|
287
293
|
```text
|
|
288
|
-
Review: docs/cto_jev/features/<slug>/CONCEPT.md
|
|
294
|
+
Review: docs/cto_jev/features/<slug>/CONCEPT.md
|
|
289
295
|
Key points: at most three lines
|
|
290
296
|
Might be missing: what the agent is unsure of, pointing to the `Assumed:` lines in the docs
|
|
291
297
|
Data: which tables or stores change, whether old data migrates; "none" if nothing
|
|
@@ -294,9 +300,9 @@ Data: which tables or stores change, whether old data migrates; "none" if nothin
|
|
|
294
300
|
- **Claude Code:** just agree in the chat. cto's `UserPromptSubmit` hook asks Jev whether your reply agrees to every listed file and, if so, sets the listed drafts to `Status: approved` and tells you which files it signed. "OK, but change X", a question or agreeing to only some files signs nothing. When Jev cannot sign, it signs nothing and says why: no API key yet (run `cto setup`), the service failed a moment ago and is paused (reply again later), or it is unreachable. In each case you can also edit the line yourself.
|
|
295
301
|
- **Codex, Cursor, Gemini CLI:** edit the `Status:` line yourself.
|
|
296
302
|
|
|
297
|
-
Agreeing covers what is written, `Assumed:` lines included. A signed-off CONCEPT, PRODUCT or ARCHITECTURE
|
|
303
|
+
Agreeing covers what is written, `Assumed:` lines included. A signed-off CONCEPT, PRODUCT or ARCHITECTURE can only change after going back to `Status: draft` and a new Review. In Claude Code cto blocks the agent from setting `approved` itself or skipping that step (Edit, Write, MultiEdit; PowerShell may not touch those files at all). For every agent, shell commands may not write them. As a backstop in Claude Code, when a turn ends cto puts any sign-off doc that became `approved` during the turn without your reply back to `draft` and tells the agent, however it was written (a glob, a variable, a script). Codex, Cursor and Gemini edit tools are not guarded yet; there only the skill's rules hold.
|
|
298
304
|
|
|
299
|
-
**Upgrading.** `cto update` refreshes the repo you run it from and adds the new Claude Code sign-off hooks; elsewhere run `cto setup --refresh` (`cto doctor` reports missing hooks).
|
|
305
|
+
**Upgrading.** `cto update` refreshes the repo you run it from and adds the new Claude Code sign-off hooks; elsewhere run `cto setup --refresh` (`cto doctor` reports missing hooks). From 0.12 only the CONCEPT is signed: a `Status:` line left in an old SPEC is ignored, the commit check reads CONCEPT alone, and INDEX.md's sign-off column holds one value (the first commit after upgrading asks for `cto index`). `manual` tasks no longer need "accepted manually" in the agent's message.
|
|
300
306
|
|
|
301
307
|
`cto docs` deals with the rest of the repo: it finds markdown outside `docs/cto_jev/` that looks like an old plan (tool output under `.planning/`, `specs/`, `.kiro/`, fully ticked `TODO.md`s, checklists untouched for a month), asks Jev about the ambiguous ones, and prints merge / archive / delete suggestions. It changes nothing; the agent acts only after you decide.
|
|
302
308
|
|
|
@@ -387,6 +393,7 @@ Defaults: `credential_leak` 0.5, `destructive_command` 0.7, `infinite_loop` 0.6,
|
|
|
387
393
|
- **`flow`**: `true` turns on the [development flow](#the-development-flow-optional). `cto setup --flow` / `--no-flow` set it; `cto setup --refresh` follows the saved value. `--no-flow` removes the cto-jev skill, `/cto-jev` and its rule but keeps `docs/cto_jev/`; while `docs/cto_jev/features/` exists, the sign-off, index and drift checks keep running. Delete or archive that folder to stop them.
|
|
388
394
|
- **`test_command`**: what `cto brief` tells the agent to verify with, for example `"pnpm test"`. Detected from the project when empty.
|
|
389
395
|
- **`protected_branches`**: for example `["main", "release"]`. Commits on them and pushes that delete or rewrite them are blocked locally, no key needed. Empty by default.
|
|
396
|
+
- **`turn_limits`**: `{ "minutes": 20, "tool_calls": 150, "agents": 4 }` by default; a turn past any one of them gets one reminder to stop and report. `0` turns that limit off; a key you leave out keeps its default.
|
|
390
397
|
- **Thresholds**: Jev returns a probability from 0 to 1. `code_complexity` is the exception: it is a score from 0 (clean) to 4 (unmaintainable).
|
|
391
398
|
- **Calibration**: on 32 hand-written diffs, every one scoring above 0.8 for `test_tampering` really weakened the tests, and no legitimate change scored above 0.37. The 0.8 default caught 13 of 16 weakening diffs; the misses were subtle ones such as a meaningless float tolerance or a skip hidden behind an env var. Lower it to 0.5 to catch 15 of 16, at a higher risk of blocking honest commits.
|
|
392
399
|
- `done_unverified` (0.6) and `infinite_loop` (0.6) were calibrated the same way; the cases are in `calibration/`.
|
|
@@ -411,7 +418,8 @@ Defaults: `credential_leak` 0.5, `destructive_command` 0.7, `infinite_loop` 0.6,
|
|
|
411
418
|
- **A lesson's fix is the edit between a failure and the next pass of a command with the same first two words.** A fix that was verified by a different command (`npm test` fails, `npx vitest run` passes) is not recorded, and a turn that edits files for other reasons in between credits them to the fix as well.
|
|
412
419
|
- **Loop detection knows about edits, but only through the agent's edit tools.** A first re-run after a code edit is a new attempt, while the same error coming back across repeated fixes still counts as a loop; each loop is blocked once, so the agent can still verify its next fix. A file changed only through a shell command is not seen as an edit, and failures expire after 15 minutes.
|
|
413
420
|
- **The development flow reads exact headings and prefixes.** `## Interface`, `## Constraints`, `Status: approved` and the PRODUCT/ARCHITECTURE field headings must match the skeleton as written; a reworded heading is "missing" in `cto brief` and silently skipped by the checks. A commit maps to a feature by `(files:)` prefix, so a task written as `src/` claims everything and `./src/x/` claims nothing. The two Jev questions look at the first diff chunk only.
|
|
414
|
-
- **The sign-off guard has gaps.** Shell writes it cannot resolve (paths in variables, scripts such as `node -e`, `git checkout --`, `git apply`) are not blocked up front; in Claude Code a self-approval made that way is put back to `draft` when the turn ends,
|
|
421
|
+
- **The sign-off guard has gaps.** Shell writes it cannot resolve (paths in variables, scripts such as `node -e`, `git checkout --`, `git apply`) are not blocked up front; in Claude Code a self-approval made that way is put back to `draft` when the turn ends, and so is a signed doc whose content changed during the turn (set to draft, edited, approved again). All of this catches an agent that takes a shortcut or makes a mistake. It is not a security boundary against one set on cheating: anything the agent can run can also rewrite the record that check keeps in `.cto-brain.json`, and the commit check reads only the Status line. Codex, Cursor and Gemini edit tools are not guarded. If you flip a Status to `approved` by hand while the agent is mid-turn, that end-of-turn check reverts it too; flip it again afterwards. The hook signs only the reply right after a Review handoff, and keeps no record: a hook sign-off and a hand edit look the same in git.
|
|
422
|
+
- **The long-turn reminder is checked only when the agent runs a shell command.** A turn that only reads and edits files is not reminded until its next command. It works in Claude Code only: the other agents have no hook that marks where a turn starts.
|
|
415
423
|
- **Each agent shell command waits for one Jev request.** OpenRouter answered in about 0.3 s in our tests, Cloudflare in about 0.9 s with occasional spikes past 3 s. Agent checks wait up to 5 s before failing open.
|
|
416
424
|
|
|
417
425
|
## Development
|
package/dist/agents.js
CHANGED
|
@@ -7,7 +7,7 @@ const cmdOf = (i) => String(i?.tool_input?.command ?? i?.command ?? '');
|
|
|
7
7
|
// For their stop events exit 2 also means "keep working", with stderr as the reason fed back to the agent.
|
|
8
8
|
const exit2Block = (lines) => ({ code: 2, stderr: lines });
|
|
9
9
|
const systemMessage = (msgs) => ({ code: 0, stdout: JSON.stringify({ systemMessage: msgs.join('\n') }), stderr: [] });
|
|
10
|
-
const nestedPre = (i) => ({ command: str(i?.tool_input?.command), sessionId: str(i?.session_id), cwd: str(i?.cwd) });
|
|
10
|
+
const nestedPre = (i) => ({ command: str(i?.tool_input?.command), sessionId: str(i?.session_id), cwd: str(i?.cwd), transcriptPath: str(i?.transcript_path), subagent: !!str(i?.agent_id) });
|
|
11
11
|
const sessionId = (i) => str(i?.session_id);
|
|
12
12
|
/** UserPromptSubmit reply: context reaches Claude, user reaches the user; nothing at all when both are absent. */
|
|
13
13
|
export function promptOutput(context, user) {
|
|
@@ -59,6 +59,8 @@ export const agents = {
|
|
|
59
59
|
block: exit2Block,
|
|
60
60
|
stopBlock: exit2Block,
|
|
61
61
|
notice: systemMessage,
|
|
62
|
+
// additionalContext reaches Claude next to the tool result; systemMessage reaches the user only.
|
|
63
|
+
preContext: (forAgent, forUser) => ({ code: 0, stdout: JSON.stringify({ systemMessage: forUser.join('\n'), hookSpecificOutput: { hookEventName: 'PreToolUse', additionalContext: forAgent } }), stderr: [] }),
|
|
62
64
|
},
|
|
63
65
|
cursor: {
|
|
64
66
|
label: 'Cursor',
|
package/dist/brain.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
3
|
import { dirname, join } from 'node:path';
|
|
4
|
+
const turnLimits = (raw) => {
|
|
5
|
+
const n = (k) => (typeof raw?.[k] === 'number' && raw[k] >= 0 ? raw[k] : DEFAULT_CONFIG.turn_limits[k]);
|
|
6
|
+
return { minutes: n('minutes'), tool_calls: n('tool_calls'), agents: n('agents') };
|
|
7
|
+
};
|
|
4
8
|
export const DECISIONS_KEPT = 30;
|
|
5
9
|
export const DECISION_STATE_CHARS = 12_000;
|
|
6
10
|
/** Sign-off writes approved for the user, so an agent editing .cto.json may raise this bar but never lower it. */
|
|
@@ -23,6 +27,7 @@ export const DEFAULT_CONFIG = {
|
|
|
23
27
|
signoff_approved: SIGNOFF_FLOOR,
|
|
24
28
|
code_complexity: 2,
|
|
25
29
|
},
|
|
30
|
+
turn_limits: { minutes: 20, tool_calls: 150, agents: 4 },
|
|
26
31
|
};
|
|
27
32
|
const emptyBrain = () => ({
|
|
28
33
|
recent_errors: [],
|
|
@@ -62,6 +67,7 @@ export function loadConfig(root) {
|
|
|
62
67
|
protected_branches: Array.isArray(raw.protected_branches) ? raw.protected_branches.filter((b) => typeof b === 'string') : [],
|
|
63
68
|
flow: raw.flow === true,
|
|
64
69
|
thresholds,
|
|
70
|
+
turn_limits: turnLimits(raw.turn_limits),
|
|
65
71
|
};
|
|
66
72
|
}
|
|
67
73
|
/** Corrupt or missing state rebuilds as empty: the gate must never crash on its own bookkeeping. */
|
package/dist/brief.js
CHANGED
|
@@ -153,8 +153,7 @@ export function flowLines(root) {
|
|
|
153
153
|
// Nothing truncated: the text and the acceptance command are what the agent dispatches and runs.
|
|
154
154
|
const line = (t, rest) => ` ${t.id.padEnd(idW)} ${(t.priority ? `${t.priority} ` : '') + t.text} ${rest}`;
|
|
155
155
|
const counts = ['active', 'planned', 'done'].filter((s) => rows.some((r) => r.status === s)).map((s) => `${rows.filter((r) => r.status === s).length} ${s}`);
|
|
156
|
-
const pending = rows.filter((r) => r.signoff
|
|
157
|
-
.map((r) => `${r.slug} (${['concept', 'spec'].filter((k) => r.signoff[k] !== 'approved').map((k) => `${k} ${r.signoff[k]}`).join(', ')})`);
|
|
156
|
+
const pending = rows.filter((r) => r.signoff !== 'approved').map((r) => `${r.slug} (concept ${r.signoff})`);
|
|
158
157
|
const L = ['', ['Features', String(rows.length), ...counts, ...(pending.length ? [`sign-off pending: ${pending.join(', ')}`] : [])].join(' · ')];
|
|
159
158
|
L.push('', ready.length
|
|
160
159
|
? `Ready · ${ready.length}${together.length > 1 ? ` (run together: ${together.map((t) => t.id).join(', ')})` : ''}`
|
package/dist/flow.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import { ACCEPT, BOX } from './turn.js';
|
|
3
|
+
import { ACCEPT, acceptValue, BOX } from './turn.js';
|
|
4
4
|
// docs/cto_jev/features/<slug>/TASKS.md: the one place the development flow keeps state. Everything else (INDEX,
|
|
5
5
|
// ready list, feature dependencies, code ownership) is computed from it. Format: FLOW_SKILL_TEXT in skill.ts.
|
|
6
6
|
export const FLOW_DIR = 'docs/cto_jev';
|
|
@@ -15,9 +15,14 @@ export function parseTasks(text, feature, file) {
|
|
|
15
15
|
const tasks = [];
|
|
16
16
|
const stack = [];
|
|
17
17
|
let fenced = false;
|
|
18
|
+
// The task whose acceptance line may still follow; the same boundaries as the stop check (turn.ts acceptOf): only the
|
|
19
|
+
// first acceptance line indented under the item, before the next item or anything at its depth or lower.
|
|
20
|
+
let open;
|
|
18
21
|
const lines = text.split(/\r?\n/);
|
|
19
22
|
lines.forEach((raw, i) => {
|
|
20
23
|
if (/^\s*(```|~~~)/.test(raw)) {
|
|
24
|
+
if (open && raw.length - raw.trimStart().length <= open.indent)
|
|
25
|
+
open = undefined; // a fence at the item's depth ends it, as any line does
|
|
21
26
|
fenced = !fenced;
|
|
22
27
|
return;
|
|
23
28
|
}
|
|
@@ -25,12 +30,20 @@ export function parseTasks(text, feature, file) {
|
|
|
25
30
|
return;
|
|
26
31
|
const m = BOX.exec(raw);
|
|
27
32
|
if (!m) {
|
|
33
|
+
if (!open || !raw.trim())
|
|
34
|
+
return;
|
|
35
|
+
if (raw.length - raw.trimStart().length <= open.indent) {
|
|
36
|
+
open = undefined;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
28
39
|
const a = ACCEPT.exec(raw);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
40
|
+
if (a) {
|
|
41
|
+
open.task.accept = acceptValue(a[1]);
|
|
42
|
+
open = undefined;
|
|
43
|
+
}
|
|
32
44
|
return;
|
|
33
45
|
}
|
|
46
|
+
open = undefined;
|
|
34
47
|
const indent = m[1].length;
|
|
35
48
|
const idm = ID.exec(m[3]);
|
|
36
49
|
if (!idm)
|
|
@@ -51,6 +64,7 @@ export function parseTasks(text, feature, file) {
|
|
|
51
64
|
if (parent)
|
|
52
65
|
tasks.find((p) => p.id === parent)?.children.push(t.id);
|
|
53
66
|
tasks.push(t);
|
|
67
|
+
open = { task: t, indent };
|
|
54
68
|
stack.push({ indent, id: t.id });
|
|
55
69
|
});
|
|
56
70
|
return tasks;
|
|
@@ -153,13 +167,13 @@ export function featureIndex(root) {
|
|
|
153
167
|
status: !mine.length ? 'planned' : leaves.every((t) => t.done) ? 'done' : 'active',
|
|
154
168
|
code: files.filter((f) => !files.some((o) => o !== f && f.startsWith(o))),
|
|
155
169
|
dependsOn: uniqSorted(mine.flatMap((t) => t.after).map((id) => featureOf.get(id)).filter((f) => !!f && f !== slug)),
|
|
156
|
-
signoff:
|
|
170
|
+
signoff: signoff(join(dir, 'CONCEPT.md')),
|
|
157
171
|
};
|
|
158
172
|
});
|
|
159
173
|
}
|
|
160
174
|
export function renderIndex(rows) {
|
|
161
175
|
const cell = (s) => s.replace(/\|/g, '\\|');
|
|
162
|
-
const line = (r) => `| ${r.slug} | ${r.status} | ${cell(r.purpose)} | ${r.code.join(', ')} | ${r.dependsOn.join(', ')} | ${r.signoff
|
|
176
|
+
const line = (r) => `| ${r.slug} | ${r.status} | ${cell(r.purpose)} | ${r.code.join(', ')} | ${r.dependsOn.join(', ')} | ${r.signoff} |`;
|
|
163
177
|
return [
|
|
164
178
|
'# INDEX',
|
|
165
179
|
'',
|
package/dist/hooks.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
2
3
|
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
4
|
import { join } from 'node:path';
|
|
4
|
-
import { FLOW_DIR, docStatus, featureIndex, listFeatures, setStatus } from './flow.js';
|
|
5
|
+
import { FLOW_DIR, docStatus, featureIndex, listFeatures, parseTasks, setStatus } from './flow.js';
|
|
5
6
|
import { styleText } from 'node:util';
|
|
6
7
|
import { checkUpdate, currentVersion } from './update.js';
|
|
7
8
|
import { promptOutput } from './agents.js';
|
|
8
|
-
import { ACCEPT, BOX, isCodeFile, isDropped,
|
|
9
|
+
import { ACCEPT, acceptValue, BOX, droppedUnreported, isCodeFile, isDropped, isManual, isManualAccept, lookText, taskName, reviewMessage, tickedItems, tickedKey, turnActions, turnCounts, turnState } from './turn.js';
|
|
9
10
|
import { shellWrites } from './shellwrites.js';
|
|
10
|
-
import { afterEdit, guardVerdict, powershellHitsSignoffDoc, reviewPaths, shellWritesSignoffDoc, signoffDoc, signoffState } from './signoff.js';
|
|
11
|
+
import { afterEdit, guardVerdict, powershellHitsSignoffDoc, protectedText, reviewPaths, shellWritesSignoffDoc, signoffDoc, signoffState } from './signoff.js';
|
|
11
12
|
import { evaluate, providerOrder, providers } from './api.js';
|
|
12
13
|
import { DECISIONS_KEPT, DECISION_STATE_CHARS, freshErrors, loadBrain, loadConfig, saveBrain } from './brain.js';
|
|
13
14
|
import { chunkDiff, filterDiff, pool } from './diff.js';
|
|
@@ -202,18 +203,26 @@ export function manualQuestion(files) {
|
|
|
202
203
|
// The task above an added `manual` line, whether the task line itself is added or unchanged context: switching an
|
|
203
204
|
// existing task from a command to manual is the change worth asking about.
|
|
204
205
|
let last = '';
|
|
206
|
+
let depth = 0;
|
|
205
207
|
for (const line of f.split(/\r?\n/)) {
|
|
206
208
|
if (line.startsWith('+++') || line.startsWith('---') || line.startsWith('@@')) {
|
|
207
209
|
last = '';
|
|
208
210
|
continue;
|
|
209
211
|
}
|
|
210
|
-
const
|
|
212
|
+
const body = line.slice(1);
|
|
213
|
+
const box = BOX.exec(body);
|
|
211
214
|
if (box) {
|
|
212
215
|
last = line[0] === '-' ? '' : box[3].trim();
|
|
216
|
+
depth = box[1].length;
|
|
213
217
|
continue;
|
|
214
218
|
}
|
|
215
|
-
|
|
216
|
-
if (
|
|
219
|
+
// As parseTasks reads it: an acceptance line counts only when indented under its item.
|
|
220
|
+
if (body.trim() && body.length - body.trimStart().length <= depth) {
|
|
221
|
+
last = '';
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
const acc = line[0] === '+' ? ACCEPT.exec(body) : null;
|
|
225
|
+
if (acc && last && isManualAccept(acceptValue(acc[1]))) {
|
|
217
226
|
tasks.push(last);
|
|
218
227
|
last = '';
|
|
219
228
|
}
|
|
@@ -414,13 +423,18 @@ export async function agentPre(agent, input, { root, lang, now }) {
|
|
|
414
423
|
const command = input.command;
|
|
415
424
|
if (!command?.trim())
|
|
416
425
|
return { code: 0, stderr: [] };
|
|
417
|
-
|
|
426
|
+
const written = shellWrites(command);
|
|
427
|
+
if (shellWritesSignoffDoc(root, input.cwd ?? root, written, command))
|
|
418
428
|
return agent.block([t(lang, 'signoff_guard')]);
|
|
419
429
|
const cfg = loadConfig(root);
|
|
420
430
|
const brain = loadBrain(root);
|
|
421
431
|
// The flow ticks a task and commits it in the same turn; the stop check diffs from here so those ticks are not missed.
|
|
422
432
|
const turnKey = input.sessionId ?? '';
|
|
423
433
|
const at = (now ?? Date.now)();
|
|
434
|
+
// Claimed before the Jev wait, so a parallel command in the same message finds the turn already warned.
|
|
435
|
+
const long = longTurn(brain, input, cfg, lang, at);
|
|
436
|
+
if (long)
|
|
437
|
+
saveBrain(root, brain);
|
|
424
438
|
const kept = brain.turn_base?.[turnKey];
|
|
425
439
|
// A turn interrupted without a stop event leaves its base behind; one older than TURN_BASE_TTL_MS belongs to it.
|
|
426
440
|
if (/\bgit\b[^;&|]*\bcommit\b/.test(command) && (!kept || at - kept.at > TURN_BASE_TTL_MS)) {
|
|
@@ -435,7 +449,6 @@ export async function agentPre(agent, input, { root, lang, now }) {
|
|
|
435
449
|
let state = maskSensitiveState(command);
|
|
436
450
|
// A command that writes code files (sed -i, redirects, formatters) is a fix attempt, same as an edit tool. Marked
|
|
437
451
|
// before it runs: pre hooks exist for every agent, so this also covers agents without a usable edit event.
|
|
438
|
-
const written = shellWrites(command);
|
|
439
452
|
if (input.sessionId && !agent.transcriptTurns && agent.stop) {
|
|
440
453
|
for (const f of written)
|
|
441
454
|
logAction(brain, input.sessionId, { kind: 'edit', file: f === '?' ? `(files written by: ${command.slice(0, 60)})` : f });
|
|
@@ -476,7 +489,12 @@ export async function agentPre(agent, input, { root, lang, now }) {
|
|
|
476
489
|
break;
|
|
477
490
|
}
|
|
478
491
|
}
|
|
479
|
-
|
|
492
|
+
// A long turn is told once, never blocked: on a block it rides along; otherwise it reaches the agent and the user.
|
|
493
|
+
if (long && out.code !== 0)
|
|
494
|
+
out = { ...out, stderr: [...out.stderr, long.agent] };
|
|
495
|
+
else if (long)
|
|
496
|
+
out = agent.preContext ? agent.preContext(long.agent, [long.user, ...notices]) : agent.notice([long.user, ...notices]);
|
|
497
|
+
else if (out.code === 0 && notices.size)
|
|
480
498
|
out = agent.notice([...notices]);
|
|
481
499
|
saveBrain(root, brain);
|
|
482
500
|
return out;
|
|
@@ -490,32 +508,72 @@ const approve = (text) => setStatus(text, 'draft', 'approved');
|
|
|
490
508
|
* approved. Fails closed (no sign-off) on anything uncertain; never blocks the prompt.
|
|
491
509
|
*/
|
|
492
510
|
export async function agentPrompt(input, env) {
|
|
511
|
+
// Recorded before the Jev call as well: a hook killed by its timeout mid-call still leaves this turn a baseline.
|
|
512
|
+
recordBaseline(input, env);
|
|
513
|
+
recordTurnStart(input, env);
|
|
493
514
|
const out = await signoffReply(input, env);
|
|
494
|
-
|
|
495
|
-
if (input.sessionId && existsSync(join(env.root, FLOW_DIR))) {
|
|
496
|
-
const brain = loadBrain(env.root);
|
|
497
|
-
const kept = Object.entries(brain.signoff_baseline ?? {}).filter(([k]) => k !== input.sessionId).slice(-20);
|
|
498
|
-
brain.signoff_baseline = Object.fromEntries([...kept, [input.sessionId, approvedDocs(env.root)]]);
|
|
499
|
-
saveBrain(env.root, brain);
|
|
500
|
-
}
|
|
515
|
+
recordBaseline(input, env);
|
|
501
516
|
return out;
|
|
502
517
|
}
|
|
518
|
+
/** The user's message starts a turn; a background agent's completion notice does not. */
|
|
519
|
+
function recordTurnStart(input, { root, now }) {
|
|
520
|
+
if (!input.sessionId || /^\s*<task-notification>/.test(input.prompt))
|
|
521
|
+
return;
|
|
522
|
+
const brain = loadBrain(root);
|
|
523
|
+
const kept = Object.entries(brain.turn_start ?? {}).filter(([k]) => k !== input.sessionId).slice(-20);
|
|
524
|
+
brain.turn_start = Object.fromEntries([...kept, [input.sessionId, { at: (now ?? Date.now)() }]]);
|
|
525
|
+
saveBrain(root, brain);
|
|
526
|
+
}
|
|
527
|
+
/** Once per turn: the reminder lines when this turn is past a limit, else undefined. Marks the turn warned. */
|
|
528
|
+
function longTurn(brain, input, cfg, lang, at) {
|
|
529
|
+
// A sub-agent's command shares the parent's session: the reminder is for the main agent, so a sub-agent never uses it up.
|
|
530
|
+
const turn = input.sessionId && !input.subagent ? brain.turn_start?.[input.sessionId] : undefined;
|
|
531
|
+
if (!turn || turn.warned)
|
|
532
|
+
return undefined;
|
|
533
|
+
const lim = cfg.turn_limits;
|
|
534
|
+
const minutes = Math.floor((at - turn.at) / 60000);
|
|
535
|
+
const counts = input.transcriptPath ? turnCounts(input.transcriptPath) : undefined;
|
|
536
|
+
const over = (v, limit) => limit > 0 && v !== undefined && v > limit;
|
|
537
|
+
if (!over(minutes, lim.minutes) && !over(counts?.tools, lim.tool_calls) && !over(counts?.agents, lim.agents))
|
|
538
|
+
return undefined;
|
|
539
|
+
turn.warned = true;
|
|
540
|
+
const v = { minutes, tools: counts?.tools ?? '?', agents: counts?.agents ?? '?' };
|
|
541
|
+
return { agent: t(lang, 'turn_long_agent', v), user: t(lang, 'turn_long_user', v) };
|
|
542
|
+
}
|
|
543
|
+
/** What the user has signed off as this turn starts; the stop check reverts anything approved beyond it. */
|
|
544
|
+
function recordBaseline(input, { root }) {
|
|
545
|
+
if (!input.sessionId || !existsSync(join(root, FLOW_DIR)))
|
|
546
|
+
return;
|
|
547
|
+
const brain = loadBrain(root);
|
|
548
|
+
const kept = Object.entries(brain.signoff_baseline ?? {}).filter(([k]) => k !== input.sessionId).slice(-20);
|
|
549
|
+
brain.signoff_baseline = Object.fromEntries([...kept, [input.sessionId, Object.fromEntries(approvedDocs(root).map((f) => [f, docHash(root, f)]))]]);
|
|
550
|
+
saveBrain(root, brain);
|
|
551
|
+
}
|
|
503
552
|
const signoffDocPaths = (root) => [
|
|
504
553
|
...['PRODUCT.md', 'ARCHITECTURE.md'].map((f) => `${FLOW_DIR}/${f}`),
|
|
505
|
-
...listFeatures(root).
|
|
554
|
+
...listFeatures(root).map((s) => `${FLOW_DIR}/features/${s}/CONCEPT.md`),
|
|
506
555
|
];
|
|
507
556
|
const approvedDocs = (root) => signoffDocPaths(root).filter((f) => docStatus(readOr(join(root, f))) === 'approved');
|
|
557
|
+
/** The signed content: everything but the Status line, which draft -> edit -> approved round trips change and restore. */
|
|
558
|
+
const docHash = (root, f) => createHash('sha256').update(protectedText(readOr(join(root, f)))).digest('hex');
|
|
508
559
|
/**
|
|
509
560
|
* At stop: a sign-off doc approved during the turn, but not by the sign-off hook (a glob, a variable, a script the
|
|
510
|
-
* guard could not see), goes back to draft
|
|
511
|
-
*
|
|
561
|
+
* guard could not see), goes back to draft; so does one still approved whose signed content changed during the turn
|
|
562
|
+
* (set to draft, edited, approved again). Returns the files reverted. Sessions without a baseline are skipped.
|
|
563
|
+
* This catches an agent taking a shortcut, not one set on cheating: whatever the agent can run can also rewrite or
|
|
564
|
+
* delete the baseline in .cto-brain.json. A boundary against that needs a record the agent cannot write.
|
|
565
|
+
* shortcut: a Status the user flips, or a signed doc they edit, by hand in their editor mid-turn is reverted too; they redo it after the turn.
|
|
566
|
+
* shortcut: so is a signed doc that a mid-turn `git checkout`, `pull` or `merge` replaces with another signed version (it
|
|
567
|
+
* fails safe: the doc is draft until the user signs it again); a baseline per HEAD would tell the two apart.
|
|
512
568
|
*/
|
|
513
569
|
function revertSelfSigned(root, sessionId) {
|
|
514
|
-
const
|
|
515
|
-
if (!
|
|
570
|
+
const raw = sessionId ? loadBrain(root).signoff_baseline?.[sessionId] : undefined;
|
|
571
|
+
if (!raw)
|
|
516
572
|
return [];
|
|
573
|
+
const baseline = Array.isArray(raw) ? Object.fromEntries(raw.map((f) => [f, ''])) : raw;
|
|
574
|
+
const changed = (f) => !(f in baseline) || (baseline[f] !== '' && baseline[f] !== docHash(root, f));
|
|
517
575
|
const reverted = [];
|
|
518
|
-
for (const f of approvedDocs(root).filter(
|
|
576
|
+
for (const f of approvedDocs(root).filter(changed)) {
|
|
519
577
|
try {
|
|
520
578
|
writeFileSync(join(root, f), setStatus(readOr(join(root, f)), 'approved', 'draft'));
|
|
521
579
|
reverted.push(f);
|
|
@@ -587,7 +645,7 @@ export function agentGuard(agent, input, { root, lang }) {
|
|
|
587
645
|
return SILENT;
|
|
588
646
|
const before = existsSync(join(root, file)) ? readFileSync(join(root, file), 'utf8') : undefined;
|
|
589
647
|
const after = afterEdit(before, tool, input.toolInput);
|
|
590
|
-
const verdict = after === undefined ? 'ok' : guardVerdict(
|
|
648
|
+
const verdict = after === undefined ? 'ok' : guardVerdict(before, after);
|
|
591
649
|
return verdict === 'ok' ? SILENT : agent.block([t(lang, verdict === 'self_approve' ? 'signoff_self_approve' : 'signoff_guard')]);
|
|
592
650
|
}
|
|
593
651
|
catch {
|
|
@@ -621,6 +679,11 @@ export async function agentStop(agent, input, { root, lang, now }) {
|
|
|
621
679
|
delete brain.turn_base[turnKey];
|
|
622
680
|
saveBrain(root, brain);
|
|
623
681
|
}
|
|
682
|
+
// A background agent's command after the turn ended is not this turn running long; only the user's next message reopens it.
|
|
683
|
+
if (brain.turn_start?.[turnKey]) {
|
|
684
|
+
delete brain.turn_start[turnKey];
|
|
685
|
+
saveBrain(root, brain);
|
|
686
|
+
}
|
|
624
687
|
const base = recorded && (now ?? Date.now)() - recorded.at <= TURN_BASE_TTL_MS && isAncestor(root, recorded.head) ? recorded.head : undefined;
|
|
625
688
|
const reverted = revertSelfSigned(root, input.sessionId);
|
|
626
689
|
if (reverted.length && !input.stopHookActive)
|
|
@@ -638,26 +701,51 @@ export async function agentStop(agent, input, { root, lang, now }) {
|
|
|
638
701
|
return undefined;
|
|
639
702
|
} })
|
|
640
703
|
.filter((t) => !judged.has(tickedKey(t)));
|
|
704
|
+
// A task whose acceptance was a command at the turn's base and is manual now is judged against that command: otherwise
|
|
705
|
+
// rewriting a failing `npm test` to `manual` would close it with no check at all.
|
|
706
|
+
// shortcut: with no recorded turn base, a switch committed mid-turn is already in HEAD and passes as manual; per-turn snapshots of plan files would close it.
|
|
707
|
+
const oldCommand = (x) => {
|
|
708
|
+
let old = '';
|
|
709
|
+
try {
|
|
710
|
+
old = execFileSync('git', ['show', `${base ?? 'HEAD'}:${x.file}`], { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
|
|
711
|
+
}
|
|
712
|
+
catch {
|
|
713
|
+
return undefined;
|
|
714
|
+
}
|
|
715
|
+
const accept = parseTasks(old, '', x.file).find((p) => p.id === taskName(x))?.accept;
|
|
716
|
+
return accept && !isManualAccept(accept) ? accept : undefined;
|
|
717
|
+
};
|
|
641
718
|
if (!ticked.length && !actions.some((a) => a.kind === 'edit' && isCodeFile(a.file)))
|
|
642
719
|
return out;
|
|
643
|
-
// A
|
|
720
|
+
// A dropped task the final message does not report is a text fact, not a judgement: cto blocks it itself. Jev
|
|
644
721
|
// still judges everything else in the turn, since this stop's block is the only one it gets.
|
|
645
|
-
const
|
|
646
|
-
const
|
|
647
|
-
|
|
722
|
+
const dropped = droppedUnreported(ticked, lastMessage);
|
|
723
|
+
const droppedLines = dropped.slice(0, 5).map((m) => t(lang, 'done_dropped', { detail: m.text.slice(0, 80), id: taskName(m) }));
|
|
724
|
+
// A manual task never blocks and has nothing for Jev to judge: the user is told what to look at, with the text, not just the id.
|
|
725
|
+
// shortcut: no reminder when this stop blocks for another reason (the tick is not reminded later); the release report lists them.
|
|
726
|
+
const switched = new Map(ticked.filter((x) => isManual(x) && !isDropped(x)).flatMap((x) => { const c = oldCommand(x); return c ? [[x, c]] : []; }));
|
|
727
|
+
const looks = ticked.filter((x) => isManual(x) && !isDropped(x) && !switched.has(x));
|
|
728
|
+
const lookLines = looks.slice(0, 5).map((m) => t(lang, 'manual_look', { detail: lookText(m).slice(0, 200), id: taskName(m) }));
|
|
729
|
+
// Every wave of a run can end in one stop: the ids past the fifth are still named, so none is silently skipped.
|
|
730
|
+
if (looks.length > 5)
|
|
731
|
+
lookLines.push(`[cto] … ${looks.slice(5).map(taskName).join(', ')}`);
|
|
732
|
+
const remind = () => (lookLines.length ? agent.notice(lookLines) : out);
|
|
733
|
+
const rest = ticked.filter((x) => !dropped.includes(x) && !looks.includes(x)).map((x) => (switched.has(x) ? { ...x, accept: switched.get(x) } : x));
|
|
734
|
+
const textOnly = [...dropped, ...looks].map(tickedKey);
|
|
648
735
|
if (!rest.length && !actions.some((a) => a.kind === 'edit' && isCodeFile(a.file))) {
|
|
649
|
-
|
|
650
|
-
|
|
736
|
+
if (dropped.length)
|
|
737
|
+
brain.blocked_attempts++;
|
|
738
|
+
brain.judged_items = [...judged, ...textOnly].slice(-300);
|
|
651
739
|
saveBrain(root, brain);
|
|
652
|
-
return agent.stopBlock(
|
|
740
|
+
return dropped.length ? agent.stopBlock(droppedLines) : remind();
|
|
653
741
|
}
|
|
654
742
|
const cfg = loadConfig(root);
|
|
655
743
|
const state = turnState(lastMessage, actions, rest);
|
|
656
744
|
const r = await evaluate({ state, questions: { done_unverified: Q.done_unverified }, ...(input.sessionId && { session_id: input.sessionId }) }, { brain, lang, timeoutMs: AGENT_TIMEOUT_MS, notices: new Set(), now });
|
|
657
745
|
if (!r.ok) {
|
|
658
746
|
brain.skipped_attempts++;
|
|
659
|
-
if (
|
|
660
|
-
brain.judged_items = [...judged, ...
|
|
747
|
+
if (textOnly.length)
|
|
748
|
+
brain.judged_items = [...judged, ...textOnly].slice(-300);
|
|
661
749
|
}
|
|
662
750
|
else {
|
|
663
751
|
countCheck(brain, now);
|
|
@@ -665,11 +753,13 @@ export async function agentStop(agent, input, { root, lang, now }) {
|
|
|
665
753
|
brain.judged_items = [...judged, ...ticked.map(tickedKey)].slice(-300);
|
|
666
754
|
}
|
|
667
755
|
const v = r.ok ? exceeded(r.answers, 'done_unverified', cfg) : undefined;
|
|
668
|
-
const lines = [...
|
|
756
|
+
const lines = [...droppedLines, ...(v !== undefined ? verdict(lang, 'done_unverified', v, cfg, null) : [])];
|
|
669
757
|
if (lines.length) {
|
|
670
758
|
brain.blocked_attempts++;
|
|
671
759
|
out = agent.stopBlock(lines);
|
|
672
760
|
}
|
|
761
|
+
else
|
|
762
|
+
out = remind();
|
|
673
763
|
saveBrain(root, brain);
|
|
674
764
|
return out;
|
|
675
765
|
}
|
package/dist/i18n.js
CHANGED
|
@@ -63,7 +63,7 @@ const messages = {
|
|
|
63
63
|
local_env_file: (v) => `[cto] 你正要把 ${v.detail} 連同值一起 commit。.env 不進 git,放進 .gitignore,要分享用 .env.example。`,
|
|
64
64
|
local_big_file: (v) => `[cto] ${v.detail} 太大了,確定是要進 git 的東西?不擋,但想清楚。`,
|
|
65
65
|
local_lock_drift: (v) => `[cto] package.json 改了相依套件,但 ${v.detail} 沒跟著改。先跑一次 install,不然隊友裝的會跟你不一樣。`,
|
|
66
|
-
local_flow_signoff: (v) =>
|
|
66
|
+
local_flow_signoff: (v) => `[cto] ${v.detail} 已經有 TASKS.md,但 CONCEPT.md 還不是 Status: approved。沒簽核就開工?先用「請你看」格式(Review: 行)交給使用者簽核,不然把 TASKS.md 拿掉。`,
|
|
67
67
|
local_flow_index_stale: (v) => `[cto] TASKS/CONCEPT/SPEC 改了,但 ${v.detail} 沒重新產生。跑 cto index 再 git add;這次不擋。`,
|
|
68
68
|
local_flow_dangling_after: (v) => `[cto] ${v.detail}:這個 after: 指到的任務 ID 不存在。改對 ID,或把那個任務加進 TASKS.md;這次不擋。`,
|
|
69
69
|
local_flow_duplicate_id: (v) => `[cto] ${v.detail}:這個任務 ID 在 TASKS.md 裡出現不只一次,after: 會指錯。改成唯一的 ID;這次不擋。`,
|
|
@@ -73,9 +73,12 @@ const messages = {
|
|
|
73
73
|
signoff_paused: () => '[cto] 沒有簽核:判斷服務剛才失敗,暫停中,稍後再回一次或手改 Status',
|
|
74
74
|
signoff_partial: (v) => `[cto] 簽核寫到一半失敗。已簽核:${v.signed};沒簽:${v.unsigned},可以手改 Status`,
|
|
75
75
|
signoff_guard: () => '[cto] 簽核由使用者決定。要改已簽核的內容,先用 Edit 把 Status 改成 draft,改完用「請你看」格式交給使用者;shell 不能寫簽核文件,請用 Read/Edit/Write',
|
|
76
|
-
signoff_reverted: (v) => `[cto] 這一輪有簽核文件被改成 approved
|
|
76
|
+
signoff_reverted: (v) => `[cto] 這一輪有簽核文件被改成 approved,或已簽的內容被改了,都不是使用者簽的,已經改回 draft:${v.files}。只有使用者能簽核:用「請你看」格式(Review: 行)交給使用者`,
|
|
77
77
|
signoff_self_approve: () => '[cto] 簽核由使用者決定,只有使用者能把 Status 設成 approved。用「請你看」格式(Review: 行)交給使用者,等他回覆',
|
|
78
|
-
|
|
78
|
+
manual_look: (v) => `[cto] 待你看:${v.detail}(${v.id})`,
|
|
79
|
+
turn_long_agent: (v) => `[cto] 這一輪已經 ${v.minutes} 分鐘、${v.tools} 次工具呼叫、${v.agents} 個 sub-agent。先停下來,告訴使用者做到哪裡、卡在哪裡、下一步打算怎麼做,再繼續。`,
|
|
80
|
+
turn_long_user: (v) => `[cto] 這一輪已經跑了 ${v.minutes} 分鐘、${v.tools} 次工具呼叫、${v.agents} 個 sub-agent,已請 agent 停下來回報。`,
|
|
81
|
+
local_flow_manual_bare: (v) => `[cto] ${v.detail}:驗收行只寫 manual,沒說要看什麼。改成「驗收: manual: <看什麼> @ <網址、指令或截圖路徑>」,提醒使用者時才看得懂;這次不擋。`,
|
|
79
82
|
done_dropped: (v) => `[cto] ${v.detail}:這個 task 標了 dropped,但你的最後訊息沒寫「${v.id} dropped」。在最後訊息寫出放棄了哪個 task、為什麼,讓使用者看得到。`,
|
|
80
83
|
docs_none: () => 'docs/cto_jev/ 以外沒有過期的規劃文件。',
|
|
81
84
|
docs_group_delete: () => '刪除',
|
|
@@ -259,7 +262,7 @@ const messages = {
|
|
|
259
262
|
local_env_file: (v) => `[cto] You are about to commit ${v.detail} with real values. .env files stay out of git: add it to .gitignore and share a .env.example.`,
|
|
260
263
|
local_big_file: (v) => `[cto] ${v.detail} is huge. Sure that belongs in git? Not blocking, but think.`,
|
|
261
264
|
local_lock_drift: (v) => `[cto] package.json changed dependencies but ${v.detail} did not. Run install first, or your teammates get a different tree.`,
|
|
262
|
-
local_flow_signoff: (v) =>
|
|
265
|
+
local_flow_signoff: (v) => `[cto] ${v.detail} has a TASKS.md but CONCEPT.md is not Status: approved. No sign-off, no work: send the user a Review handoff, or remove TASKS.md.`,
|
|
263
266
|
local_flow_index_stale: (v) => `[cto] TASKS/CONCEPT/SPEC changed but ${v.detail} was not regenerated. Run cto index and git add it; not blocking.`,
|
|
264
267
|
local_flow_dangling_after: (v) => `[cto] ${v.detail}: that after: id does not exist. Fix the id or add the task to TASKS.md; not blocking.`,
|
|
265
268
|
local_flow_duplicate_id: (v) => `[cto] ${v.detail}: this task id appears more than once in TASKS.md, so after: may point at the wrong one. Make it unique; not blocking.`,
|
|
@@ -269,9 +272,12 @@ const messages = {
|
|
|
269
272
|
signoff_paused: () => '[cto] Not signed off: the judging service failed a moment ago and is paused. Reply again later or edit the Status line by hand',
|
|
270
273
|
signoff_partial: (v) => `[cto] Sign-off failed partway. Signed off: ${v.signed}; not signed: ${v.unsigned}. You can edit the Status line by hand`,
|
|
271
274
|
signoff_guard: () => '[cto] Sign-off is the user\'s call. To change signed-off content, first use Edit to set Status to draft, then hand it to the user with a Review handoff. Shell commands cannot write sign-off docs: use Read, Edit or Write',
|
|
272
|
-
signoff_reverted: (v) => `[cto] A sign-off doc was set to approved this turn, but not by the user; it is back to draft: ${v.files}. Only the user signs off: hand it over with a Review handoff`,
|
|
275
|
+
signoff_reverted: (v) => `[cto] A sign-off doc was set to approved, or its signed content changed, this turn, but not by the user; it is back to draft: ${v.files}. Only the user signs off: hand it over with a Review handoff`,
|
|
273
276
|
signoff_self_approve: () => '[cto] Sign-off is the user\'s call: only the user can set Status to approved. Hand it to the user with a Review handoff and wait for their reply',
|
|
274
|
-
|
|
277
|
+
manual_look: (v) => `[cto] For you to look at: ${v.detail} (${v.id})`,
|
|
278
|
+
turn_long_agent: (v) => `[cto] This turn has run ${v.minutes} min, ${v.tools} tool calls, ${v.agents} sub-agents. Stop and tell the user where you are, what is stuck, and what you plan next, before going on.`,
|
|
279
|
+
turn_long_user: (v) => `[cto] This turn has run ${v.minutes} min, ${v.tools} tool calls, ${v.agents} sub-agents; the agent has been asked to stop and report.`,
|
|
280
|
+
local_flow_manual_bare: (v) => `[cto] ${v.detail}: its acceptance line says only manual, not what to look at. Write "accept: manual: <what to look at> @ <url, command or screenshot path>", so the reminder to the user makes sense; not blocking.`,
|
|
275
281
|
done_dropped: (v) => `[cto] ${v.detail}: this task is marked dropped, but your final message does not say "${v.id} dropped". Say which task you dropped and why in your final message, so the user sees it.`,
|
|
276
282
|
docs_none: () => 'No stale planning documents outside docs/cto_jev/.',
|
|
277
283
|
docs_group_delete: () => 'Delete',
|
package/dist/local.js
CHANGED
|
@@ -23,7 +23,8 @@ const inScope = (file, raw) => {
|
|
|
23
23
|
return file === scope || file.startsWith(scope.endsWith('/') ? scope : `${scope}/`);
|
|
24
24
|
};
|
|
25
25
|
/**
|
|
26
|
-
* Features whose TASKS.md has tasks but whose CONCEPT.md
|
|
26
|
+
* Features whose TASKS.md has tasks but whose CONCEPT.md is not `Status: approved`: no work without sign-off.
|
|
27
|
+
* SPEC.md is the CTO's own document and is not looked at.
|
|
27
28
|
* Only the features this diff touches (their docs folder or a task's `(files:)` scope); any read error means no finding.
|
|
28
29
|
*/
|
|
29
30
|
function flowSignoff(root, touched) {
|
|
@@ -41,10 +42,9 @@ function flowSignoff(root, touched) {
|
|
|
41
42
|
catch {
|
|
42
43
|
return '';
|
|
43
44
|
} };
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
out.push({ kind: 'flow_signoff', block: true, detail: `${slug}: ${unsigned.join(', ')}` });
|
|
45
|
+
// CONCEPT.md is the one signed doc of a feature, so the message names it and detail is just the slug.
|
|
46
|
+
if (docStatus(read('CONCEPT.md')) !== 'approved')
|
|
47
|
+
out.push({ kind: 'flow_signoff', block: true, detail: slug });
|
|
48
48
|
}
|
|
49
49
|
return out;
|
|
50
50
|
}
|
|
@@ -70,6 +70,10 @@ function flowIndex(root, touched) {
|
|
|
70
70
|
const dupIn = (id) => tasks.some((t) => t.id === id && touched.has(t.file));
|
|
71
71
|
for (const id of duplicateIds(tasks).filter(dupIn).slice(0, 5))
|
|
72
72
|
out.push({ kind: 'flow_duplicate_id', block: false, detail: id });
|
|
73
|
+
// The stop reminder prints what follows "manual:"; without it the user gets a task id and has to go look it up.
|
|
74
|
+
const bare = tasks.filter((t) => !t.done && touched.has(t.file) && /^manual\s*[::]?\s*$/i.test(t.accept ?? ''));
|
|
75
|
+
for (const t of bare.slice(0, 5))
|
|
76
|
+
out.push({ kind: 'flow_manual_bare', block: false, detail: t.id });
|
|
73
77
|
return out;
|
|
74
78
|
}
|
|
75
79
|
catch {
|
package/dist/setup.js
CHANGED
|
@@ -54,8 +54,9 @@ function missingIgnores(text) {
|
|
|
54
54
|
let out;
|
|
55
55
|
// check-ignore names only the last matching rule, which would be our block's own line, so ask a scratch repo whose
|
|
56
56
|
// .gitignore is the user's lines alone; it also honours a later `!` rule. Exit 1 means nothing matched.
|
|
57
|
-
|
|
57
|
+
let tmp; // an unwritable tmp dir falls back below instead of crashing setup
|
|
58
58
|
try {
|
|
59
|
+
tmp = mkdtempSync(join(tmpdir(), 'cto-ignore-'));
|
|
59
60
|
git(tmp, 'init', '-q');
|
|
60
61
|
writeFileSync(join(tmp, '.gitignore'), outside);
|
|
61
62
|
out = git(tmp, 'check-ignore', '--no-index', '-v', ...entries.map(sample));
|
|
@@ -65,7 +66,8 @@ function missingIgnores(text) {
|
|
|
65
66
|
out = '';
|
|
66
67
|
}
|
|
67
68
|
finally {
|
|
68
|
-
|
|
69
|
+
if (tmp)
|
|
70
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
69
71
|
}
|
|
70
72
|
// git failed: fall back to exact lines.
|
|
71
73
|
if (out === undefined)
|
|
@@ -183,7 +185,7 @@ export const FLOW_SKELETON = {
|
|
|
183
185
|
'docs/cto_jev/PRODUCT.md': `# PRODUCT\n\nStatus: draft\n\n${fields(['一句話', '使用者角色', '怎麼賺錢', '方案與限制', '不做的事', '設計約束'])}`,
|
|
184
186
|
'docs/cto_jev/ARCHITECTURE.md': `# ARCHITECTURE\n\nStatus: draft\n\n${fields(['技術棧', '目錄地圖', '外部服務與資料', '驗證指令', '不變的原則'])}`,
|
|
185
187
|
'docs/cto_jev/features/platform/CONCEPT.md': '# platform\n\nStatus: approved\n\n## 目的\n\nInfrastructure: CI, build, deploy, dependencies\n\n## 動機\n\n## 商業規則\n\n## 不做的事\n',
|
|
186
|
-
'docs/cto_jev/features/platform/SPEC.md': '# platform SPEC\n\
|
|
188
|
+
'docs/cto_jev/features/platform/SPEC.md': '# platform SPEC\n\n## Interface\n\n## Constraints\n\n## Internals\n',
|
|
187
189
|
'docs/cto_jev/features/platform/TASKS.md': '# platform TASKS\n',
|
|
188
190
|
'docs/cto_jev/features/platform/REVIEW.md': '# platform REVIEW\n\nNot reviewed yet.\n',
|
|
189
191
|
'docs/cto_jev/decisions/.gitkeep': '',
|
package/dist/signoff.js
CHANGED
|
@@ -4,8 +4,9 @@ import { existsSync, realpathSync, statSync } from 'node:fs';
|
|
|
4
4
|
import { posix } from 'node:path';
|
|
5
5
|
import { docStatus, FLOW_DIR } from './flow.js';
|
|
6
6
|
import { maskSensitiveState } from './masker.js';
|
|
7
|
-
|
|
8
|
-
const
|
|
7
|
+
// SPEC.md is not here: the CTO derives it from the signed CONCEPT, and tests and reviews judge it, not the user.
|
|
8
|
+
export const SIGNOFF_DOCS = ['CONCEPT.md', 'PRODUCT.md', 'ARCHITECTURE.md'];
|
|
9
|
+
const DOC_NAME = /\b(?:concept|product|architecture)\.md\b/i;
|
|
9
10
|
const REVIEW = /^[\s>*+\-_`]*Review[*_`]*\s*:[*_`]*\s*(.*)$/;
|
|
10
11
|
const lastReview = (lines) => lines.findLastIndex((l) => REVIEW.test(l));
|
|
11
12
|
/** Paths on the last `Review:` line of a message; tolerates bold, quotes, bullets, backticks and code fences. */
|
|
@@ -36,7 +37,7 @@ function absolute(cwd, p) {
|
|
|
36
37
|
const [, drive = '', rest] = /^([a-z]:)?(.*)$/is.exec(full);
|
|
37
38
|
return drive.toLowerCase() + posix.normalize(rest).replace(/\/+$/, '');
|
|
38
39
|
}
|
|
39
|
-
// An NTFS stream (`
|
|
40
|
+
// An NTFS stream (`CONCEPT.md::$DATA`, `CONCEPT.md:x`) is the same file. Only the last segment: `:` is legal in POSIX folder names.
|
|
40
41
|
const noStream = (full) => full.replace(/(\/[^/:]*):[^/]*$/, '$1');
|
|
41
42
|
// 8.3 short names (`ARCHIT~1.MD`) and symlinks: the deepest part that exists becomes its real long path.
|
|
42
43
|
function real(p) {
|
|
@@ -88,41 +89,38 @@ export function afterEdit(before, toolName, input) {
|
|
|
88
89
|
}
|
|
89
90
|
return text;
|
|
90
91
|
}
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const start = lines.findIndex((l) => /^##\s+Interface\b/.test(l));
|
|
96
|
-
const end = lines.findIndex((l) => /^##\s+Internals\b/.test(l));
|
|
97
|
-
lines = lines.slice(Math.max(start, 0), end < 0 ? undefined : end);
|
|
98
|
-
}
|
|
99
|
-
return lines.join('\n');
|
|
100
|
-
}
|
|
101
|
-
/** before undefined = new file. Demoting to draft is always ok. */
|
|
102
|
-
export function guardVerdict(file, before, after) {
|
|
92
|
+
// Everything but the Status line.
|
|
93
|
+
export const protectedText = (text) => text.replace(/\r\n/g, '\n').split('\n').filter((l) => docStatus(l) === 'missing').join('\n');
|
|
94
|
+
/** For a sign-off doc. before undefined = new file. Demoting to draft is always ok. */
|
|
95
|
+
export function guardVerdict(before, after) {
|
|
103
96
|
if (docStatus(after) !== 'approved')
|
|
104
97
|
return 'ok';
|
|
105
98
|
if (before === undefined || docStatus(before) !== 'approved')
|
|
106
99
|
return 'self_approve';
|
|
107
|
-
return protectedText(
|
|
100
|
+
return protectedText(before) === protectedText(after) ? 'ok' : 'protected_edit';
|
|
108
101
|
}
|
|
109
|
-
/**
|
|
102
|
+
/**
|
|
103
|
+
* PowerShell gets no write parser: any mention of a sign-off doc together with cto_jev blocks, reads too; with cwd
|
|
104
|
+
* inside docs/cto_jev, a sign-off doc name, a glob or a variable blocks.
|
|
105
|
+
*/
|
|
110
106
|
export function powershellHitsSignoffDoc(root, cwd, command) {
|
|
111
107
|
// git add/diff/log on a sign-off doc is how its changes get committed; only git, in every statement, passes.
|
|
112
108
|
// shortcut: git checkout/restore can still rewrite a doc this way; the pre-commit check is the backstop.
|
|
113
109
|
if (command.split(/;|&&|\|\||\|/).every((s) => /^\s*git\s/i.test(s)))
|
|
114
110
|
return false;
|
|
115
|
-
if (inFlow(relative(root, '/', cwd)))
|
|
116
|
-
return true;
|
|
117
111
|
const cmd = command.replace(/\\/g, '/').toLowerCase();
|
|
118
|
-
|
|
112
|
+
// Inside docs/cto_jev a bare name is enough, and a glob or variable may hide one; SPEC.md and listings pass.
|
|
113
|
+
if (inFlow(relative(root, '/', cwd)))
|
|
114
|
+
return DOC_NAME.test(cmd) || /[*?$\[]/.test(cmd);
|
|
115
|
+
// cto_jev, not docs/cto_jev: `Join-Path docs cto_jev\...` never writes the two together.
|
|
116
|
+
return DOC_NAME.test(cmd) && cmd.includes('cto_jev');
|
|
119
117
|
}
|
|
120
118
|
/**
|
|
121
119
|
* For the Bash rule: paths from shellWrites; `?` (target unknown) is let through. Targets resolve against cwd and
|
|
122
120
|
* every `cd` dir in the command (`cd docs/cto_jev/x && cp a .`). A bare doc name in a command that mentions cto_jev
|
|
123
121
|
* blocks (a `cd` this cannot follow), and so does a folder under docs/cto_jev as the target when the command names a
|
|
124
|
-
* sign-off doc (`cp
|
|
125
|
-
* shortcut: globs (`
|
|
122
|
+
* sign-off doc (`cp CONCEPT.md docs/cto_jev/features/x/`).
|
|
123
|
+
* shortcut: globs (`CONC*.md`), variables and `cd docs/cto_*` still get through; a post-Bash Status check would close them.
|
|
126
124
|
*/
|
|
127
125
|
export function shellWritesSignoffDoc(root, cwd, writtenPaths, command = '') {
|
|
128
126
|
const cmd = command.replace(/\\/g, '/').toLowerCase();
|
package/dist/skill.js
CHANGED
|
@@ -106,38 +106,47 @@ turns it into a calibration case; you do not run that yourself.
|
|
|
106
106
|
// `cto setup` chose the flow.
|
|
107
107
|
export const FLOW_SKILL_TEXT = `---
|
|
108
108
|
name: cto-jev
|
|
109
|
-
description: The development flow of this repo, kept in docs/cto_jev/. Invoked by saying the job's name (in Claude Code: /cto-jev <job>; in Codex: $cto-jev). Its jobs are named so they cannot be confused with another skill's steps - "cto-jev init" (first-time setup, also "set up PRODUCT.md and ARCHITECTURE.md"), "cto-jev feature" (a request bigger than one edit), "cto-jev tasks" (break
|
|
109
|
+
description: The development flow of this repo, kept in docs/cto_jev/. Invoked by saying the job's name (in Claude Code: /cto-jev <job>; in Codex: $cto-jev). Its jobs are named so they cannot be confused with another skill's steps - "cto-jev init" (first-time setup, also "set up PRODUCT.md and ARCHITECTURE.md"), "cto-jev feature" (a request bigger than one edit), "cto-jev tasks" (break a signed-off concept down), "cto-jev work" (dispatch, accept, review and commit every wave, without stopping in between), "cto-jev work all" (the same on a branch, one review at the end), "cto-jev release" (review everything unreleased, then merge to main), "cto-jev docs" (clean up old documents), "cto-jev decision" (record an architecture decision). Load it when the user names one of them, and whenever you are about to plan, dispatch, tick a task or commit.
|
|
110
110
|
---
|
|
111
111
|
${SKILL_MARK}
|
|
112
112
|
|
|
113
113
|
# cto-jev
|
|
114
114
|
|
|
115
|
-
You are the CTO of this repo. You plan, break down, dispatch, accept and review; sub-agents write the code. The plan lives in \`docs/cto_jev/\`; the only state is the checkboxes in TASKS.md. cto checks what you claim: a tick without a passing check is sent back, a commit on a feature
|
|
115
|
+
You are the CTO of this repo. You plan, break down, dispatch, accept and review; sub-agents write the code. The plan lives in \`docs/cto_jev/\`; the only state is the checkboxes in TASKS.md. cto checks what you claim: a tick without a passing check is sent back, a commit on a feature whose CONCEPT is not signed off is blocked.
|
|
116
116
|
|
|
117
|
-
Seven jobs, each named \`cto-jev <job>\`. When the user says the name (or types \`/cto-jev <job>\`), do that job
|
|
117
|
+
Seven jobs, each named \`cto-jev <job>\`. When the user says the name (or types \`/cto-jev <job>\`), do that job; go on to another only where the job's **Stop** says so. Each says when it applies, the steps, and where you stop. Invoked with no job: run \`cto brief\`, say in two lines where the repo stands, and name the one job to run next.
|
|
118
|
+
|
|
119
|
+
## Where you stop
|
|
120
|
+
|
|
121
|
+
The user decides what gets built and signs it once, in CONCEPT.md. While docs are written you talk with them: the CONCEPT interview, the questions of \`cto-jev docs\` and each sign-off (the CONCEPT at the end of \`cto-jev feature\`; PRODUCT.md and ARCHITECTURE.md in \`init\` and \`docs\`) wait for their answers. Once the CONCEPT is signed, building it (\`cto-jev tasks\`, \`work\`, \`release\`) waits for the user in one place only: before the merge in \`cto-jev release\`. Everywhere else you keep going:
|
|
122
|
+
|
|
123
|
+
- **SPEC.md is yours.** It is the technical document you derive from the signed CONCEPT. Nobody signs it and nothing protects it: change any section when the work shows it is wrong, and say so in the wave's REVIEW.md entry. Tests and reviews judge it, not the user. If a SPEC change would contradict the CONCEPT, that is a CONCEPT change and the user's to make: in the middle of a run, park the task (below) and leave the CONCEPT and its \`Status:\` line alone, since a draft CONCEPT blocks every later commit of the feature; outside a run it goes through \`cto-jev feature\` (draft, edit, \`Review:\`).
|
|
124
|
+
- **What the CONCEPT does not decide, you decide.** Write the decision into the SPEC as \`Assumed: ...\` and carry on. Every \`Assumed:\` goes into your final report and the release report, where the user reads them in one go.
|
|
125
|
+
- **Never ask "shall I start?".** Dispatch what is Ready; when a wave is committed, start the next one.
|
|
126
|
+
- **Park, do not stop,** when a task needs the user: a decision that would contradict the signed CONCEPT, credentials, money, an outside account, anything irreversible, a drop, or a failure that survived a second approach. Parked means unticked and not dispatched again in this run; its dependants wait with it. Go on with the rest and list parked tasks in the final report.
|
|
118
127
|
|
|
119
128
|
## Sign-off
|
|
120
129
|
|
|
121
|
-
CONCEPT.md,
|
|
130
|
+
CONCEPT.md, PRODUCT.md and ARCHITECTURE.md carry a \`Status: draft\` or \`Status: approved\` line. You write and stop; the user signs. SPEC.md carries no Status line; one left over from before 0.12 means nothing.
|
|
122
131
|
|
|
123
132
|
Every time you stop for the user to look at docs (the end of \`cto-jev init\` and \`cto-jev feature\`), send a review handoff. First write each open question or guess into the doc itself as \`Assumed: ...\`. Then:
|
|
124
133
|
|
|
125
134
|
\`\`\`
|
|
126
|
-
Review: docs/cto_jev/features/<slug>/CONCEPT.md
|
|
135
|
+
Review: docs/cto_jev/features/<slug>/CONCEPT.md
|
|
127
136
|
Key points: at most three lines
|
|
128
137
|
Might be missing: one line each, what you are unsure of, pointing to the \`Assumed:\` line in the doc
|
|
129
138
|
Data: which tables or stores change, whether old data migrates; "none" if nothing
|
|
130
139
|
\`\`\`
|
|
131
140
|
|
|
132
|
-
\`Review:\` is always this English word, on its own line, with repo-relative paths separated by commas.
|
|
141
|
+
\`Review:\` is always this English word, on its own line, with repo-relative paths separated by commas (\`cto-jev init\` lists two: \`Review: docs/cto_jev/PRODUCT.md, docs/cto_jev/ARCHITECTURE.md\`). List only sign-off docs; a SPEC.md there is ignored.
|
|
133
142
|
|
|
134
143
|
- In Claude Code the user agrees in the conversation and cto's hook sets \`Status: approved\` on the files in the \`Review:\` line. With other agents the user edits the line.
|
|
135
144
|
- In Claude Code, end every handoff with one line: reply "ok" to sign. Nothing else about signing.
|
|
136
145
|
- Only with another agent, after cto says it did not sign, or when the user asks how to approve: give this command with the real paths, for the user to type while you are not working (never run it yourself):
|
|
137
|
-
\`! sed -i 's/^Status: draft/Status: approved/' docs/cto_jev/features/<slug>/CONCEPT.md
|
|
146
|
+
\`! sed -i 's/^Status: draft/Status: approved/' docs/cto_jev/features/<slug>/CONCEPT.md\`
|
|
138
147
|
- Approval covers what is written, \`Assumed:\` lines included. Partial agreement signs nothing: fix and resend \`Review:\`, or resend it with only the agreed files.
|
|
139
|
-
- You never set approved (in Claude Code cto blocks it). To change approved CONCEPT, PRODUCT or ARCHITECTURE content,
|
|
140
|
-
- Shell commands may not write CONCEPT,
|
|
148
|
+
- You never set approved (in Claude Code cto blocks it). To change approved CONCEPT, PRODUCT or ARCHITECTURE content, first set \`Status: draft\` with the Edit tool, then make the change and resend \`Review:\`.
|
|
149
|
+
- Shell commands may not write CONCEPT, PRODUCT or ARCHITECTURE under \`docs/cto_jev/\` (no \`cp\`, \`mv\`, \`sed -i\` or redirects); use the Read, Edit and Write tools.
|
|
141
150
|
|
|
142
151
|
## cto-jev init
|
|
143
152
|
|
|
@@ -155,7 +164,7 @@ This is a conversation, not a form. The files are done when the user says so, no
|
|
|
155
164
|
|
|
156
165
|
PRODUCT.md headings: \`## 一句話\`, \`## 使用者角色\`, \`## 怎麼賺錢\`, \`## 方案與限制\`, \`## 不做的事\`, \`## 設計約束\`.
|
|
157
166
|
ARCHITECTURE.md headings: \`## 技術棧\`, \`## 目錄地圖\`, \`## 外部服務與資料\`, \`## 驗證指令\`, \`## 不變的原則\`.
|
|
158
|
-
Short bullets or a table per heading. \`## 不做的事\` and \`## 不變的原則\` feed the drift checks: one rule per line. In a repo with a UI, \`## 驗證指令\` names the end-to-end test command (Playwright or similar) that Acceptance scenarios run under, or says there is none yet
|
|
167
|
+
Short bullets or a table per heading. \`## 不做的事\` and \`## 不變的原則\` feed the drift checks: one rule per line. In a repo with a UI, \`## 驗證指令\` names the end-to-end test command (Playwright or similar) that Acceptance scenarios run under, or says there is none yet.
|
|
159
168
|
|
|
160
169
|
## cto-jev feature
|
|
161
170
|
|
|
@@ -164,32 +173,35 @@ Short bullets or a table per heading. \`## 不做的事\` and \`## 不變的原
|
|
|
164
173
|
1. Run \`cto-jev docs\` first when it has not run this session; bring its suggestions to the user before opening a feature.
|
|
165
174
|
2. Read \`docs/cto_jev/INDEX.md\` and classify:
|
|
166
175
|
- Inside an existing feature, within its Constraints: add tasks to its TASKS.md (\`cto-jev tasks\`). No new docs.
|
|
167
|
-
- Changes a
|
|
176
|
+
- Changes what the CONCEPT says (a business rule, the scope, what the user sees): edit its CONCEPT.md, set \`Status: draft\`, update the SPEC to match, run the docs review (step 5), stop for sign-off.
|
|
177
|
+
- Changes only the SPEC (\`## Interface\`, \`## Constraints\`, \`## Acceptance\`, \`## Internals\`) and still does what the CONCEPT says: edit the SPEC and add the tasks. No sign-off.
|
|
168
178
|
- A new module: \`features/<slug>/\` with the four files below.
|
|
169
|
-
- An existing module with no feature folder yet: create its folder describing what exists today (short CONCEPT
|
|
179
|
+
- An existing module with no feature folder yet: create its folder describing what exists today (short CONCEPT with \`Status: draft\`, SPEC with its sections; Acceptance lists what the code does today), before any task on it.
|
|
170
180
|
- Infrastructure (CI, build, deploy, dependency upgrades): a task under \`features/platform/\`.
|
|
171
|
-
3. Talk before you write. Restate the request in two sentences and ask until every question below has an answer or an explicit "not relevant". At most five questions per message, each with your best guess; an installed interview skill may run the rounds, the questions below are what must be answered. Do not write CONCEPT.md until
|
|
172
|
-
- For CONCEPT: who uses this and what changes for them; which business rules apply, including what happens on failure, limits, roles and paid tiers; what is explicitly out of scope; which existing features it touches; which simpler option was considered and why it was rejected (goes under \`## 動機\`).
|
|
173
|
-
- For SPEC: which data and tables change, and whether existing data must migrate and how it rolls back; what other features may call (the Interface) and what stays private; the error cases and what the user sees; how a failure in production gets noticed (migration, rollback and that go under \`## Internals\`); the hard rules the code must never break (the Constraints); how each part will be verified, and for what the user sees, the acceptance scenarios (the Acceptance): the steps, the expected result a script can compare, and the screen widths.
|
|
181
|
+
3. Talk before you write, about the CONCEPT only. Restate the request in two sentences and ask until every CONCEPT question below has an answer or an explicit "not relevant". At most five questions per message, each with your best guess; an installed interview skill may run the rounds, the questions below are what must be answered. Do not write CONCEPT.md until they are settled. The SPEC questions you answer yourself, from the CONCEPT and the code; what you cannot prove becomes an \`Assumed: ...\` line in the SPEC, not a question.
|
|
182
|
+
- For CONCEPT (ask the user): who uses this and what changes for them; which business rules apply, including what happens on failure, limits, roles and paid tiers; what the user sees when it works, concrete enough that a test could fail on it ("after a refund the order page says Refunded"); what is explicitly out of scope; which existing features it touches; which simpler option was considered and why it was rejected (goes under \`## 動機\`).
|
|
183
|
+
- For SPEC (answer yourself): which data and tables change, and whether existing data must migrate and how it rolls back; what other features may call (the Interface) and what stays private; the error cases and what the user sees; how a failure in production gets noticed (migration, rollback and that go under \`## Internals\`); the hard rules the code must never break (the Constraints); how each part will be verified, and for what the user sees, the acceptance scenarios (the Acceptance): the steps, the expected result a script can compare, and the screen widths. Each scenario comes from a rule in the CONCEPT, so a check you write later compares against what the user signed, not your guess.
|
|
174
184
|
4. Write CONCEPT.md, then SPEC.md. Constraints are testable rules ("a refund always writes an audit row"), not aspirations. Interface is only what other features may call. Acceptance is one line per scenario, step → expected result, measurable ("at 375px wide: no horizontal scroll, Save visible without scrolling"; "empty email: 'Email required' under the field, nothing sent"), never "looks right". What only taste can judge (is it pleasing, does it match the brand) is one line marked \`(look)\`; that line becomes a \`manual\` task.
|
|
175
|
-
5. **Review the docs before the user does.** Dispatch a reviewer with none of your context, which may read and search the code. It reads CONCEPT.md and SPEC.md and answers four questions: could an engineer new to this repo build it from these two files without making a design decision; does it build something not needed now, or something the code already has; which business rules, error cases, roles/permissions or data cases are missing; and does every Acceptance scenario have an expected result a script can check (a vague one, or a \`(look)\` line that could be measured, is a finding). Findings are P1 or P2; handle them as under "Review findings" below, fixing both P1 and P2 in the docs now (the docs are cheap to change). A
|
|
176
|
-
6. Walk the user through
|
|
185
|
+
5. **Review the docs before the user does.** Dispatch a reviewer with none of your context, which may read and search the code. It reads CONCEPT.md and SPEC.md and answers four questions: could an engineer new to this repo build it from these two files without making a design decision; does it build something not needed now, or something the code already has; which business rules, error cases, roles/permissions or data cases are missing; and does every Acceptance scenario have an expected result a script can check and a CONCEPT rule it comes from (a vague one, one the CONCEPT does not back, or a \`(look)\` line that could be measured, is a finding). Findings are P1 or P2; handle them as under "Review findings" below, fixing both P1 and P2 in the docs now (the docs are cheap to change). A CONCEPT gap only the user can settle goes into the CONCEPT as \`Assumed: ...\` and into the handoff's "might be missing". Append one REVIEW.md entry: date, "docs", counts, what was contested or escalated.
|
|
186
|
+
6. Walk the user through CONCEPT.md section by section, including what the review changed, and ask what is wrong or missing. Edit, walk through again, until they have nothing to add. Do not walk them through the SPEC.
|
|
177
187
|
|
|
178
|
-
**Stop:** when the user says the
|
|
188
|
+
**Stop:** when the user says the CONCEPT is complete: send a review handoff (see "Sign-off") for CONCEPT.md. Never write TASKS.md before the CONCEPT is approved; cto blocks the commit anyway. Once it is signed, go straight on to \`cto-jev tasks\` and \`cto-jev work\` unless the user said otherwise.
|
|
179
189
|
|
|
180
190
|
CONCEPT.md: \`Status:\` line, then \`## 目的\` (one sentence), \`## 動機\`, \`## 商業規則\`, \`## 不做的事\`.
|
|
181
|
-
SPEC.md: \`Status:\` line
|
|
191
|
+
SPEC.md: no \`Status:\` line; \`## Interface\`, \`## Constraints\`, \`## Acceptance\`, \`## Internals\`, in this order.
|
|
182
192
|
REVIEW.md: created empty with one line saying it is pending.
|
|
183
193
|
|
|
184
194
|
## cto-jev tasks
|
|
185
195
|
|
|
186
|
-
**When:** the user says "cto-jev tasks", or CONCEPT.md
|
|
196
|
+
**When:** the user says "cto-jev tasks", or CONCEPT.md is \`Status: approved\` and TASKS.md is empty or the request adds work.
|
|
187
197
|
|
|
188
198
|
1. One parent per deliverable, children small enough for one sub-agent and one acceptance command.
|
|
189
|
-
2. Every child gets \`(files:)\` (the directories it changes, never bare \`src/\`), \`(after:)\` for anything that must be ticked first (across features too), and an acceptance line: a runnable command. A task the user sees is accepted by the end-to-end test of the SPEC's Acceptance scenarios it covers (named in the task line), e.g. \`npx playwright test e2e/customers.spec.ts\`; driving a browser by hand is how you write that test, never how you accept. If ARCHITECTURE.md \`## 驗證指令\` names no end-to-end command,
|
|
199
|
+
2. Every child gets \`(files:)\` (the directories it changes, never bare \`src/\`), \`(after:)\` for anything that must be ticked first (across features too), and an acceptance line: a runnable command. A task the user sees is accepted by the end-to-end test of the SPEC's Acceptance scenarios it covers (named in the task line), e.g. \`npx playwright test e2e/customers.spec.ts\`; driving a browser by hand is how you write that test, never how you accept. If ARCHITECTURE.md \`## 驗證指令\` names no end-to-end command, do not ask: plan the harness as a \`(seq)\` task under \`features/platform/\` that the UI tasks wait on, write the choice into the SPEC as \`Assumed: ...\`, and say in your final report that ARCHITECTURE.md needs the new command (it is a signed doc: it changes only through sign-off). \`manual\` only for a \`(look)\` line: what taste must judge, not sizes or behaviour a script can measure. Write what to look at and where on the line itself, \`manual: <what to look at> @ <url, command or screenshot path>\`: cto shows the user that text, so they never have to open TASKS.md to learn what an id means.
|
|
190
200
|
3. Shared files (route tables, shared types, migrations, a single test file, the CLI entry point) get their own sequential task; take them out of the other tasks' \`(files:)\`.
|
|
191
201
|
4. Run \`cto index\` and read \`cto brief\`: Ready should list the first wave; nothing should be Blocked on a missing id.
|
|
192
202
|
|
|
203
|
+
**Stop:** none: go straight on to \`cto-jev work\`; what this job has to tell the user goes into that job's report.
|
|
204
|
+
|
|
193
205
|
\`\`\`md
|
|
194
206
|
- [ ] CUST-1 Customer list
|
|
195
207
|
- [ ] CUST-1.1 List API, filtered by role (after: PERM-2) (files: src/customers/api/)
|
|
@@ -197,7 +209,7 @@ REVIEW.md: created empty with one line saying it is pending.
|
|
|
197
209
|
- [ ] CUST-1.2 List UI: Acceptance "filter by role", "375px no horizontal scroll" (after: CUST-1.1) (files: src/customers/ui/, e2e/customers.spec.ts)
|
|
198
210
|
驗收: npx playwright test e2e/customers.spec.ts
|
|
199
211
|
- [ ] CUST-1.3 List matches the brand (look) (after: CUST-1.2) (files: src/customers/ui/)
|
|
200
|
-
驗收: manual
|
|
212
|
+
驗收: manual: list page colours and spacing against the brand sheet, at 375px and 1280px @ http://localhost:3000/customers
|
|
201
213
|
\`\`\`
|
|
202
214
|
|
|
203
215
|
IDs: \`<PREFIX>-<n>\`, children \`<n>.<m>\`, prefix uppercase and unique across the repo. A parent has no \`(files:)\` and no acceptance line; it is done when all children (at most 15) are ticked. \`accept:\` is accepted as a synonym for \`驗收:\`.
|
|
@@ -217,38 +229,37 @@ Two more tags, on any task:
|
|
|
217
229
|
|
|
218
230
|
**When:** the user says "cto-jev work" or "continue", or \`cto brief\` shows Ready tasks.
|
|
219
231
|
|
|
220
|
-
Branches: work on an integration branch (\`review\`, or whatever the repo calls it; see the table under \`cto-jev release\`). The release branch only receives \`cto-jev release\`. Never commit to it directly;
|
|
232
|
+
Branches: work on an integration branch (\`review\`, or whatever the repo calls it; see the table under \`cto-jev release\`). The release branch only receives \`cto-jev release\`. Never commit to it directly; if it is not in \`protected_branches\` in \`.cto.json\`, say so in your final report. The one exception is a repo with only \`main\` and one developer (the first row of that table): there you commit each reviewed wave to \`main\` (\`cto-jev work all\` uses a branch instead, below), and \`main\` stays out of \`protected_branches\`, or every commit would be blocked.
|
|
233
|
+
|
|
234
|
+
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.
|
|
221
235
|
|
|
222
|
-
1. \`cto brief\`. Dispatch only Ready tasks; the "run together" set is safe to run at once. P1 tasks go first.
|
|
236
|
+
1. \`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. Say in one line what this wave runs, then run it.
|
|
223
237
|
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.
|
|
224
238
|
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.
|
|
225
|
-
4. Accept by running the task's acceptance command yourself; never trust the report. Tick only on a pass. A failing end-to-end test means the code is wrong
|
|
226
|
-
5. **Review before you commit.** Dispatch a reviewer with none of your context: it reads the feature's CONCEPT.md and SPEC.md and the uncommitted diff, and returns findings each marked P1 (wrong, unsafe, breaks a Constraint or the Interface) or P2 (should improve, can wait). Handle them as under "Review findings": fix every P1 now and re-run acceptance; write every P2 as a \`(P2)\` task in TASKS.md. 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.
|
|
239
|
+
4. Accept by running the task's acceptance command yourself; never trust the report. Tick only on a pass. 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.
|
|
240
|
+
5. **Review before you commit.** Dispatch a reviewer with none of your context: it reads the feature's CONCEPT.md and SPEC.md and the uncommitted diff, 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) or P2 (should improve, can wait). 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 as a \`(P2)\` task in TASKS.md. 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.
|
|
227
241
|
6. \`cto check\`, then commit the wave to the review branch.
|
|
228
242
|
|
|
229
243
|
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.
|
|
230
244
|
|
|
231
|
-
**Stop:**
|
|
245
|
+
**Stop:** when no task is left to run (everything open is parked, or waits on a parked task). One report: tasks done (with commits); then what waits on the user, each with your best guess: parked tasks and why, \`manual\` tasks to look at (what and where), every \`Assumed:\` added, findings left unfixed because only the user can decide them. Never release.
|
|
232
246
|
|
|
233
247
|
### cto-jev work all
|
|
234
248
|
|
|
235
|
-
**When:** the user says "cto-jev work all" (\`/cto-jev work all\`), typically on a new project: run
|
|
249
|
+
**When:** the user says "cto-jev work all" (\`/cto-jev work all\`), typically on a new project: the same run as \`cto-jev work\`, but on a branch and with one review at the end instead of one per wave. Only on request.
|
|
236
250
|
|
|
237
|
-
0. Before anything runs, list the plan: every wave in order, its tasks, the files each changes and how each is accepted, and what will be parked (below) or skipped. Wait for the user to say go; that one go covers the whole run, so step 2 does not ask again per wave.
|
|
238
251
|
1. Branch: in a repo with only \`main\`, create a branch \`work-all\` from \`main\` and work there, since these waves are not reviewed one by one; every other repo uses its integration branch as usual. Note the commit you start from.
|
|
239
|
-
2. Loop until no task is left to run: re-read \`cto brief\` and the TASKS.md files each round, then run steps 1 to 4 and step 6 of \`cto-jev work\` (dispatch, integrate, accept, commit) for the Ready tasks, skipping tasks you parked (below) and every task of a feature whose CONCEPT
|
|
252
|
+
2. Loop until no task is left to run: re-read \`cto brief\` and the TASKS.md files each round, then run steps 1 to 4 and step 6 of \`cto-jev work\` (dispatch, integrate, accept, 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). There is no per-wave review: each wave's REVIEW.md entry says "work all, reviewed at the end". \`cto check\` and the git hooks still run on every commit. Without sub-agents, do the tasks yourself in brief's order; the end review is then a \`self-review\`.
|
|
240
253
|
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.
|
|
241
254
|
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:
|
|
242
|
-
- it needs a decision that would
|
|
243
|
-
- it is \`manual\`: build it, run what can be run, and list it for the user to accept with screenshots (do not tick it);
|
|
244
|
-
- its end-to-end test fails and you believe the expectation, not the code, is wrong;
|
|
255
|
+
- 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: ...\`;
|
|
245
256
|
- you think it should be dropped (never drop in this run; the user decides);
|
|
246
257
|
- it needs credentials, money, an outside account, or anything irreversible;
|
|
247
258
|
- it still fails after a second approach.
|
|
248
259
|
5. When no task is left to run, the review: a reviewer with none of your context reads \`git diff <start>..HEAD\` and the SPECs of every feature touched, findings P1/P2/P3, handled as under "Review findings" except that escalations and undecided contests go to the final report instead of stopping the run (a contested finding stays unfixed until the user decides). Fix every P1 (with re-reviews of the fixes, at most three rounds in all), write P2 and P3 as tasks, commit, and append one REVIEW.md entry: date, "work all", the task ids, counts.
|
|
249
260
|
6. In a repo with only \`main\`: once every P1 of the review is fixed, merge \`work-all\` into \`main\` (that is the reviewed commit) and delete the branch. If any P1 is contested or escalated, do not merge: leave \`work-all\` for the user and say so in the report.
|
|
250
261
|
|
|
251
|
-
**Stop:** after step 5 (and 6), never before the review. One report: tasks done (with commits); then everything waiting on the user, each as one question with your best guess: parked tasks and why, \`manual\` tasks to
|
|
262
|
+
**Stop:** after step 5 (and 6), never before the review. One report: tasks done (with commits); then everything waiting on the user, each as one question with your best guess: parked tasks and why, \`manual\` tasks to look at (what and where), features skipped for a draft CONCEPT, every \`Assumed:\` added, escalated findings and undecided contests. Never release; the next step is the user's answers, then \`cto-jev work\` or \`cto-jev release\`.
|
|
252
263
|
|
|
253
264
|
## Review findings
|
|
254
265
|
|
|
@@ -258,7 +269,7 @@ Every review (docs, wave, release) ends here. You wrote what was reviewed, so wa
|
|
|
258
269
|
- **Escalate** to the user when the evidence is outside anything the reviewer could read (a verbal decision, a team convention). Do not dismiss it yourself; if the user confirms, write the fact into the docs.
|
|
259
270
|
- A reviewer who could not follow the docs found missing context. Never contest that.
|
|
260
271
|
- Never change a severity yourself. A P1 that looks like a P2 is contested like any finding, with evidence, and the user decides.
|
|
261
|
-
- An escalated finding, or a contest the user has not decided,
|
|
272
|
+
- An escalated finding, or a contest the user has not decided, does not stop a run: leave that finding unfixed, write it into the REVIEW.md entry, go on, and list it in your final report and the release report. In a docs review it goes into the handoff's "might be missing" instead, since that job stops for sign-off anyway. Before escalating, read the CONCEPT: what it decides is not the user's to decide again.
|
|
262
273
|
- After fixing P1s, a new reviewer with none of your context reads only the fixes. At most three rounds per review: the first plus up to two re-reviews of only the fixes. If P1s remain after round three, stop fixing and hand them to the user (an escalation). Anything below P1 becomes a task with its severity (in a docs review, where no tasks may exist yet: fixed in the docs or put in the handoff's "might be missing").
|
|
263
274
|
- Without sub-agents every review here, the re-review included, is your own: say \`self-review\` in its REVIEW.md entry.
|
|
264
275
|
|
|
@@ -277,9 +288,9 @@ First decide what "release" means in this repo. Look at \`git branch -a\` and th
|
|
|
277
288
|
|
|
278
289
|
Whatever the row, one rule holds: the branch that reaches users receives nothing without a release review, and \`protected_branches\` in \`.cto.json\` names it. In the \`main\`-only row the wave review before each commit is that review, and \`main\` is not protected.
|
|
279
290
|
|
|
280
|
-
1. Everything to be released is on the work branch and every P1 task is ticked. If not,
|
|
291
|
+
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.
|
|
281
292
|
2. Dispatch a reviewer with 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.
|
|
282
|
-
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.
|
|
293
|
+
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.
|
|
283
294
|
4. \`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.
|
|
284
295
|
|
|
285
296
|
**Stop:** before the merge, with the P1/P2/P3 lists in front of the user.
|
|
@@ -302,6 +313,8 @@ Write \`docs/cto_jev/decisions/NNNN-<slug>.md\` (next number): \`# <NNNN>: <titl
|
|
|
302
313
|
|
|
303
314
|
- Set \`Status: approved\` yourself. The user signs: in Claude Code by agreeing to your \`Review:\` handoff (cto's hook sets it), elsewhere by editing the line.
|
|
304
315
|
- Change approved content without first setting \`Status: draft\` with the Edit tool, or write a signed-off doc from the shell.
|
|
316
|
+
- Stop to ask for a go-ahead, a SPEC approval or a \`manual\` confirmation. The user signs the CONCEPT and reads the release report; in between you work.
|
|
317
|
+
- Build something the signed CONCEPT does not say, or contradicts, by changing only the SPEC.
|
|
305
318
|
- Keep state anywhere but TASKS.md checkboxes: no side lists, no status files.
|
|
306
319
|
- Hand-edit INDEX.md; \`cto index\` and \`cto brief\` regenerate it.
|
|
307
320
|
- Guess a PRODUCT.md or ARCHITECTURE.md field.
|
|
@@ -317,8 +330,8 @@ docs/cto_jev/
|
|
|
317
330
|
ARCHITECTURE.md cto-jev init; user signs off
|
|
318
331
|
decisions/NNNN-<slug>.md cto-jev decision; append-only
|
|
319
332
|
features/<slug>/
|
|
320
|
-
CONCEPT.md why: 目的, 動機, 商業規則,
|
|
321
|
-
SPEC.md how: Interface, Constraints, Internals
|
|
333
|
+
CONCEPT.md why: 目的, 動機, 商業規則, 不做的事; user signs off
|
|
334
|
+
SPEC.md how: Interface, Constraints, Acceptance, Internals; yours, not signed
|
|
322
335
|
TASKS.md the only state; review findings carry (P1)/(P2)
|
|
323
336
|
REVIEW.md one entry per docs review, wave review and release
|
|
324
337
|
archive/<YYYYMM>-<name>/ cto-jev docs moves old documents here; nobody reads them
|
package/dist/turn.js
CHANGED
|
@@ -75,6 +75,30 @@ export function reviewMessage(transcriptPath, prompt) {
|
|
|
75
75
|
? j.message.content.filter((b) => b?.type === 'text').map((b) => String(b.text ?? ''))
|
|
76
76
|
: [])).join('\n');
|
|
77
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Tool calls, and sub-agents dispatched, since the user's last message. A background agent's completion notice is
|
|
80
|
+
* not the user, so it does not start a new count. Undefined when the transcript can't be read.
|
|
81
|
+
*/
|
|
82
|
+
export function turnCounts(transcriptPath) {
|
|
83
|
+
const lines = readTranscript(transcriptPath);
|
|
84
|
+
if (!lines)
|
|
85
|
+
return undefined;
|
|
86
|
+
let start = 0;
|
|
87
|
+
lines.forEach((j, i) => { if (isHumanTurn(j) && !/^\s*<task-notification>/.test(textOf(j.message?.content)))
|
|
88
|
+
start = i + 1; });
|
|
89
|
+
let tools = 0, agents = 0;
|
|
90
|
+
for (const j of lines.slice(start)) {
|
|
91
|
+
if (j?.type !== 'assistant' || !Array.isArray(j.message?.content))
|
|
92
|
+
continue;
|
|
93
|
+
for (const b of j.message.content)
|
|
94
|
+
if (b?.type === 'tool_use') {
|
|
95
|
+
tools++;
|
|
96
|
+
if (b.name === 'Agent' || b.name === 'Task')
|
|
97
|
+
agents++;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return { tools, agents };
|
|
101
|
+
}
|
|
78
102
|
/** Actions since the last human message, oldest first. Unreadable or partial transcripts give what could be parsed. */
|
|
79
103
|
export function turnActions(transcriptPath, cwd) {
|
|
80
104
|
const lines = readTranscript(transcriptPath);
|
|
@@ -164,23 +188,44 @@ export function tickedItems(diff, read) {
|
|
|
164
188
|
/** The acceptance line indented under `item`, before any nested item or anything at the item's depth or lower. */
|
|
165
189
|
function acceptOf(text, item) {
|
|
166
190
|
const lines = text?.split(/\r?\n/) ?? [];
|
|
167
|
-
|
|
191
|
+
// The item itself, not an identical line inside an earlier fenced example (parseTasks skips those).
|
|
192
|
+
let at = -1;
|
|
193
|
+
for (let i = 0, inFence = false; i < lines.length && at < 0; i++) {
|
|
194
|
+
if (/^\s*(```|~~~)/.test(lines[i]))
|
|
195
|
+
inFence = !inFence;
|
|
196
|
+
else if (!inFence && lines[i] === item)
|
|
197
|
+
at = i;
|
|
198
|
+
}
|
|
168
199
|
if (at < 0)
|
|
169
200
|
return undefined;
|
|
170
201
|
const indent = BOX.exec(item)[1].length;
|
|
202
|
+
let fenced = false; // as parseTasks: a fenced example under the item is not its acceptance line
|
|
171
203
|
for (const l of lines.slice(at + 1)) {
|
|
172
204
|
if (!l.trim())
|
|
173
205
|
continue;
|
|
174
|
-
|
|
206
|
+
const depth = l.length - l.trimStart().length;
|
|
207
|
+
if (/^\s*(```|~~~)/.test(l)) {
|
|
208
|
+
if (depth <= indent)
|
|
209
|
+
return undefined;
|
|
210
|
+
fenced = !fenced;
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (fenced)
|
|
214
|
+
continue;
|
|
215
|
+
if (depth <= indent || BOX.test(l))
|
|
175
216
|
return undefined; // next item, or a child's own line
|
|
176
217
|
const m = ACCEPT.exec(l);
|
|
177
218
|
if (m)
|
|
178
|
-
return m[1]
|
|
219
|
+
return acceptValue(m[1]);
|
|
179
220
|
}
|
|
180
221
|
return undefined;
|
|
181
222
|
}
|
|
223
|
+
/** What follows `驗收:` / `accept:`, without the backticks it may be wrapped in: the one reading for brief, commit and stop. */
|
|
224
|
+
export const acceptValue = (raw) => raw.replace(/^`+|`+$/g, '').trim() || undefined;
|
|
182
225
|
const squash = (s) => s.replace(/\s+/g, ' ').trim();
|
|
183
|
-
|
|
226
|
+
// `manual` as a word (`manual`, `manual: x`, `manual check x`); not a command that starts with it (`manual-check.sh`).
|
|
227
|
+
const MANUAL = /^manual(?![\w./-])/i;
|
|
228
|
+
export const isManualAccept = (accept) => MANUAL.test(squash(accept ?? ''));
|
|
184
229
|
const TASK_ID = /^[A-Z][A-Z0-9]*-\d+(?:\.\d+)*\b/;
|
|
185
230
|
const DROPPED = /[((]dropped[::]\s*[^))\s][^))]*[))]/i;
|
|
186
231
|
/** A task closed without doing it: `(dropped: reason)` on its line, then ticked. */
|
|
@@ -193,24 +238,24 @@ const ANY_ID = '[A-Z][A-Z0-9]*-\\d+(?:\\.\\d+)*';
|
|
|
193
238
|
// "never" or "n't" is none of these, so a negated report does not count, nor does one about the next task.
|
|
194
239
|
const JOIN = `(?:[ \\t,,、::*\`()()]|\\band\\b|和|與|${ANY_ID})*(?:\\b(?:was|were|is|are|has been|have been|both|now)\\s+)*`;
|
|
195
240
|
const LIST = `(?:[\\s,,、*\`()()-]|\\band\\b|${ANY_ID})*`;
|
|
241
|
+
/** A task only a person can judge: `驗收: manual`, or `manual: <what to look at> @ <where>`. */
|
|
242
|
+
export const isManual = (t) => isManualAccept(t.accept);
|
|
243
|
+
/** What the user is asked to look at: the text after `manual:`, or the task's own words when the line says nothing. */
|
|
244
|
+
export const lookText = (t) => squash(t.accept ?? '').replace(/^manual\s*[::]?\s*/i, '') || squash(t.text.replace(TASK_ID, ''));
|
|
196
245
|
/**
|
|
197
|
-
* The final message reports
|
|
198
|
-
*
|
|
199
|
-
* manually:\n- A-1"). Reported in the message so the user sees every drop.
|
|
246
|
+
* The final message reports a dropped task as "dropped". Either the task's name then the word ("A-1, A-2 dropped"),
|
|
247
|
+
* or the word then a list naming it ("Dropped:\n- A-1"). Reported in the message so the user sees every drop.
|
|
200
248
|
*/
|
|
201
|
-
function
|
|
249
|
+
function reportedDropped(t, lastMessage) {
|
|
202
250
|
const id = TASK_ID.exec(t.text)?.[0];
|
|
203
|
-
const word =
|
|
251
|
+
const word = 'dropped';
|
|
204
252
|
// The id as a whole token: "A-12" or "A-1.2" does not name A-1, while "A-1." at a sentence end does.
|
|
205
253
|
const me = id ? `(?<![\\w.-])${esc(id)}(?![\\w]|\\.\\d)` : esc(taskName(t));
|
|
206
254
|
return new RegExp(`${me}${JOIN}${word}`, 'i').test(lastMessage)
|
|
207
255
|
|| new RegExp(`(?<!\\bnot\\s|\\bnever\\s|n't\\s)${word}\\s*[::]${LIST}${me}`, 'i').test(lastMessage);
|
|
208
256
|
}
|
|
209
|
-
/**
|
|
210
|
-
|
|
211
|
-
* report as dropped: a text check, so no model judges it.
|
|
212
|
-
*/
|
|
213
|
-
export const manualUnconfirmed = (ticked, lastMessage) => ticked.filter((t) => (isDropped(t) || MANUAL.test(squash(t.accept ?? ''))) && !acceptedManually(t, lastMessage));
|
|
257
|
+
/** Ticked dropped tasks the final message does not report as dropped: a text check, so no model judges it. */
|
|
258
|
+
export const droppedUnreported = (ticked, lastMessage) => ticked.filter((t) => isDropped(t) && !reportedDropped(t, lastMessage));
|
|
214
259
|
/** `cmd` run as a command of its own: at a command boundary, and not with its failure swallowed (`|| true`). */
|
|
215
260
|
const runsCommand = (command, cmd) => {
|
|
216
261
|
const esc = cmd.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
@@ -218,22 +263,19 @@ const runsCommand = (command, cmd) => {
|
|
|
218
263
|
};
|
|
219
264
|
/**
|
|
220
265
|
* Computed, not judged: for each ticked task with an acceptance line, whether that exact command ran and passed after
|
|
221
|
-
* the last code edit
|
|
266
|
+
* the last code edit. A `manual` task has no command: the user looks at it later, and nothing waits on that.
|
|
222
267
|
*/
|
|
223
268
|
function acceptFacts(ticked, actions, lastEdit, lastMessage) {
|
|
224
269
|
const lines = ticked.filter((t) => t.accept).slice(0, 20).map((t) => {
|
|
225
270
|
const name = oneLine(t.text, 60);
|
|
226
271
|
const cmd = squash(t.accept);
|
|
227
272
|
if (isDropped(t)) {
|
|
228
|
-
return
|
|
273
|
+
return reportedDropped(t, lastMessage)
|
|
229
274
|
? `"${name}" is dropped (closed without doing it), and the final message reports it as dropped: nothing to accept.`
|
|
230
275
|
: `"${name}" is dropped (closed without doing it), but the final message does not report it as dropped.`;
|
|
231
276
|
}
|
|
232
|
-
if (MANUAL.test(cmd))
|
|
233
|
-
return
|
|
234
|
-
? `"${name}" is accepted by the user (manual), and the final message says it was accepted manually.`
|
|
235
|
-
: `"${name}" is accepted by the user (manual), but the final message does not say the user accepted it.`;
|
|
236
|
-
}
|
|
277
|
+
if (MANUAL.test(cmd))
|
|
278
|
+
return `"${name}" is for the user to look at later (manual): it has no acceptance command to run.`;
|
|
237
279
|
const runs = actions.flatMap((a, i) => (a.kind === 'run' && runsCommand(squash(a.command), cmd) ? [{ i, ok: a.ok }] : []));
|
|
238
280
|
if (runs.some((r) => r.i > lastEdit && r.ok))
|
|
239
281
|
return `"${name}": its acceptance command \`${cmd}\` ran after the last code edit and passed.`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "your-cto-jev",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.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",
|