your-cto-jev 0.9.5 → 0.9.7

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 CHANGED
@@ -41,7 +41,7 @@ Jev judges meaning and answers with probabilities, not prose. It costs about $0.
41
41
 
42
42
  `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.
43
43
 
44
- `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. It blocks at most once per stop, so it cannot loop.
44
+ `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 `manual` task ticked without the final message saying the user accepted it is sent back without asking Jev at all. It blocks at most once per stop, so it cannot loop.
45
45
 
46
46
  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.
47
47
 
@@ -100,7 +100,7 @@ cto setup
100
100
 
101
101
  To update later, run `cto update`. Projects you already set up pick up the new version automatically: every hook only calls `cto`, and all the logic lives in the package. `cto` checks npm for a new version at most once a day and mentions it in its once-per-session notice, never on its own.
102
102
 
103
- `cto setup` walks you through five steps with arrow keys: coding agents, Jev providers, API keys, an optional sprint goal, and whether to use the [development flow](#the-development-flow-optional). Esc goes back a step. The agent list shows what is always installed (the git hooks, `.cto.json`) and the files each agent adds; before anything is written, setup lists every file it will create, update or remove and asks once. Providers are ticked in priority order, so the numbers you see are the failover order. Press a number to move the item under the cursor straight to that position:
103
+ `cto setup` walks you through four steps with arrow keys: coding agents, Jev providers, API keys, and whether to use the [development flow](#the-development-flow-optional). Esc goes back a step. The agent list shows what is always installed (the git hooks, `.cto.json`) and the files each agent adds; before anything is written, setup lists every file it will create, update or remove and asks once. Providers are ticked in priority order, so the numbers you see are the failover order. Press a number to move the item under the cursor straight to that position:
104
104
 
105
105
  ```text
106
106
  ◆ Which Jev providers should cto use?
@@ -362,7 +362,7 @@ Defaults: `credential_leak` 0.5, `destructive_command` 0.7, `infinite_loop` 0.6,
362
362
  - **`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.
363
363
  - **Thresholds**: Jev returns a probability from 0 to 1. `code_complexity` is the exception: it is a score from 0 (clean) to 4 (unmaintainable).
364
364
  - **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.
365
- - `done_unverified` (0.6) and `infinite_loop` (0.6) were calibrated the same way; the measurements are in the design spec.
365
+ - `done_unverified` (0.6) and `infinite_loop` (0.6) were calibrated the same way; the cases are in `calibration/`.
366
366
  - `architecture_violation` against a SPEC: on 11 hand-written diffs for one feature (three constraints, two non-goals), every violation scored 0.94 or above and every legitimate change 0.30 or below, so the 0.85 default sits in the gap. `architecture_undocumented` shares that default and has no calibration set yet; treat its warnings as hints.
367
367
  - **When a call is wrong**: `cto log` lists the last 30 answered questions in this repo with their scores and thresholds. `cto report` (or `cto report <n>`) records that the last (or n-th) one was wrong and writes it, with the exact masked state Jev saw, as a calibration case to `reports/<signal>.jsonl` next to your credentials file. Nothing is sent anywhere; paste the line into `calibration/candidates/` in a PR or an issue and it joins the next measurement. That is how the thresholds get better from real use instead of hand-written diffs.
368
368
  - For `destructive_command`, the current question scores `git push --force` about 0.74 (blocked by default), `find -delete` about 0.65 and `git reset --hard` about 0.47 (both let through), and `rm -rf node_modules` about 0.12. Lower the threshold to about 0.45 to block all three; the calibration set is still small, so the default stays at 0.7.
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 { BOX } from './turn.js';
3
+ import { ACCEPT, 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';
@@ -9,7 +9,6 @@ const ID = /^([A-Z][A-Z0-9]*-\d+(?:\.\d+)*)\b\s*/;
9
9
  const TAG = /\s*\((after|files):\s*([^)]*)\)/g;
10
10
  const PRIORITY = /\s*\((P[123])\)/;
11
11
  const SEQ = /\s*\(seq\)/;
12
- const ACCEPT = /^\s*(?:驗收|accept)[::]\s*(.+?)\s*$/i;
13
12
  const list = (s) => s.split(/[,,]/).map((x) => x.trim()).filter(Boolean);
14
13
  /** Parses one TASKS.md. Items without an id are skipped (they are not tasks the flow can track). */
15
14
  export function parseTasks(text, feature, file) {
package/dist/hooks.js CHANGED
@@ -4,7 +4,7 @@ import { join } from 'node:path';
4
4
  import { FLOW_DIR, featureIndex } from './flow.js';
5
5
  import { styleText } from 'node:util';
6
6
  import { checkUpdate, currentVersion } from './update.js';
7
- import { isCodeFile, tickedItems, tickedKey, turnActions, turnState } from './turn.js';
7
+ import { isCodeFile, manualUnconfirmed, tickedItems, tickedKey, turnActions, turnState } from './turn.js';
8
8
  import { shellWrites } from './shellwrites.js';
9
9
  import { evaluate, providerOrder, providers } from './api.js';
10
10
  import { DECISIONS_KEPT, DECISION_STATE_CHARS, freshErrors, loadBrain, loadConfig, saveBrain } from './brain.js';
@@ -195,9 +195,22 @@ export const touchesTests = (diff) => TESTISH.test(diff);
195
195
  export const DIFF_ARGS = ['diff', '--cached', '--no-color', '--no-ext-diff', '--no-textconv', '--src-prefix=a/', '--dst-prefix=b/'];
196
196
  export const stagedDiff = (cwd) => execFileSync('git', DIFF_ARGS, { cwd, encoding: 'utf8', maxBuffer: 256 * 1024 * 1024, stdio: ['ignore', 'pipe', 'ignore'] });
197
197
  /** Uncommitted changes (staged and not) to tracked markdown files, for checklist ticks. Empty outside git or before the first commit. */
198
- export function planDiff(cwd) {
198
+ /** How long a recorded turn base stays valid: longer than any one agent turn, shorter than a gap between sessions. */
199
+ export const TURN_BASE_TTL_MS = 6 * 60 * 60 * 1000;
200
+ /** `commit` still exists and is an ancestor of HEAD (not amended or rebased away). */
201
+ function isAncestor(cwd, commit) {
199
202
  try {
200
- return execFileSync('git', ['diff', 'HEAD', ...DIFF_ARGS.slice(2), '--', '*.md', '*.mdx'], { cwd, encoding: 'utf8', maxBuffer: 32 * 1024 * 1024, stdio: ['ignore', 'pipe', 'ignore'] });
203
+ execFileSync('git', ['merge-base', '--is-ancestor', commit, 'HEAD'], { cwd, stdio: 'ignore' });
204
+ return true;
205
+ }
206
+ catch {
207
+ return false;
208
+ }
209
+ }
210
+ /** Markdown changes from `base` (default HEAD) to the working tree: committed since `base` and uncommitted alike. */
211
+ export function planDiff(cwd, base = 'HEAD') {
212
+ try {
213
+ return execFileSync('git', ['diff', base, ...DIFF_ARGS.slice(2), '--', '*.md', '*.mdx'], { cwd, encoding: 'utf8', maxBuffer: 32 * 1024 * 1024, stdio: ['ignore', 'pipe', 'ignore'] });
201
214
  }
202
215
  catch {
203
216
  return '';
@@ -344,6 +357,19 @@ export async function agentPre(agent, input, { root, lang, now }) {
344
357
  return { code: 0, stderr: [] };
345
358
  const cfg = loadConfig(root);
346
359
  const brain = loadBrain(root);
360
+ // The flow ticks a task and commits it in the same turn; the stop check diffs from here so those ticks are not missed.
361
+ const turnKey = input.sessionId ?? '';
362
+ const at = (now ?? Date.now)();
363
+ const kept = brain.turn_base?.[turnKey];
364
+ // A turn interrupted without a stop event leaves its base behind; one older than TURN_BASE_TTL_MS belongs to it.
365
+ if (/\bgit\b[^;&|]*\bcommit\b/.test(command) && (!kept || at - kept.at > TURN_BASE_TTL_MS)) {
366
+ try {
367
+ const head = execFileSync('git', ['rev-parse', 'HEAD'], { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
368
+ const others = Object.entries(brain.turn_base ?? {}).filter(([k, b]) => k !== turnKey && at - b.at <= TURN_BASE_TTL_MS);
369
+ brain.turn_base = Object.fromEntries([...others.slice(-20), [turnKey, { head, at }]]);
370
+ }
371
+ catch { /* no commit yet: the plain HEAD diff covers it */ }
372
+ }
347
373
  const questions = { destructive_command: Q.destructive_command };
348
374
  let state = maskSensitiveState(command);
349
375
  // A command that writes code files (sed -i, redirects, formatters) is a fix attempt, same as an edit tool. Marked
@@ -414,13 +440,21 @@ export async function agentStop(agent, input, { root, lang, now }) {
414
440
  const lessons = loadLessons(root);
415
441
  if (resolveFromTurn(lessons, actions, root, new Date((now ?? Date.now)())).length)
416
442
  saveLessons(root, lessons);
443
+ // Every stop ends the turn, so the recorded base is used once and cleared.
444
+ const turnKey = input.sessionId ?? '';
445
+ const recorded = brain.turn_base?.[turnKey];
446
+ if (recorded) {
447
+ delete brain.turn_base[turnKey];
448
+ saveBrain(root, brain);
449
+ }
450
+ const base = recorded && (now ?? Date.now)() - recorded.at <= TURN_BASE_TTL_MS && isAncestor(root, recorded.head) ? recorded.head : undefined;
417
451
  if (input.stopHookActive)
418
452
  return out;
419
453
  const lastMessage = input.lastMessage || logged?.reply || '';
420
454
  // ponytail: ticks are attributed to the turn that ends after they appear, so a box the user ticked by hand between
421
455
  // turns is judged against the agent's turn. Rare; per-turn snapshots of plan files would fix it.
422
456
  const judged = new Set(brain.judged_items ?? []);
423
- const ticked = tickedItems(planDiff(root), (f) => { try {
457
+ const ticked = tickedItems(planDiff(root, base), (f) => { try {
424
458
  return readFileSync(join(root, f), 'utf8');
425
459
  }
426
460
  catch {
@@ -429,20 +463,35 @@ export async function agentStop(agent, input, { root, lang, now }) {
429
463
  .filter((t) => !judged.has(tickedKey(t)));
430
464
  if (!ticked.length && !actions.some((a) => a.kind === 'edit' && isCodeFile(a.file)))
431
465
  return out;
466
+ // A manual task ticked without the user's confirmation is a text fact, not a judgement: cto blocks it itself. Jev
467
+ // still judges everything else in the turn, since this stop's block is the only one it gets.
468
+ const manual = manualUnconfirmed(ticked, lastMessage);
469
+ const manualLines = manual.slice(0, 5).map((m) => t(lang, 'done_manual', { detail: m.text.slice(0, 80) }));
470
+ const rest = ticked.filter((x) => !manual.includes(x));
471
+ if (!rest.length && !actions.some((a) => a.kind === 'edit' && isCodeFile(a.file))) {
472
+ brain.blocked_attempts++;
473
+ brain.judged_items = [...judged, ...manual.map(tickedKey)].slice(-300);
474
+ saveBrain(root, brain);
475
+ return agent.stopBlock(manualLines);
476
+ }
432
477
  const cfg = loadConfig(root);
433
- const state = turnState(lastMessage, actions, ticked);
478
+ const state = turnState(lastMessage, actions, rest);
434
479
  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 });
435
- if (!r.ok)
480
+ if (!r.ok) {
436
481
  brain.skipped_attempts++;
482
+ if (manual.length)
483
+ brain.judged_items = [...judged, ...manual.map(tickedKey)].slice(-300);
484
+ }
437
485
  else {
438
486
  countCheck(brain, now);
439
487
  logDecision(brain, 'stop', state, r.answers, cfg, now);
440
488
  brain.judged_items = [...judged, ...ticked.map(tickedKey)].slice(-300);
441
489
  }
442
490
  const v = r.ok ? exceeded(r.answers, 'done_unverified', cfg) : undefined;
443
- if (v !== undefined) {
491
+ const lines = [...manualLines, ...(v !== undefined ? verdict(lang, 'done_unverified', v, cfg, null) : [])];
492
+ if (lines.length) {
444
493
  brain.blocked_attempts++;
445
- out = agent.stopBlock(verdict(lang, 'done_unverified', v, cfg, null));
494
+ out = agent.stopBlock(lines);
446
495
  }
447
496
  saveBrain(root, brain);
448
497
  return out;
package/dist/i18n.js CHANGED
@@ -63,6 +63,7 @@ const messages = {
63
63
  local_flow_index_stale: (v) => `[cto] TASKS/CONCEPT/SPEC 改了,但 ${v.detail} 沒重新產生。跑 cto index 再 git add;這次不擋。`,
64
64
  local_flow_dangling_after: (v) => `[cto] ${v.detail}:這個 after: 指到的任務 ID 不存在。改對 ID,或把那個任務加進 TASKS.md;這次不擋。`,
65
65
  local_flow_duplicate_id: (v) => `[cto] ${v.detail}:這個任務 ID 在 TASKS.md 裡出現不只一次,after: 會指錯。改成唯一的 ID;這次不擋。`,
66
+ done_manual: (v) => `[cto] ${v.detail}:這是要使用者驗收的 task(manual),但你的最後訊息沒說使用者已經確認。先請使用者確認,確認後寫「accepted manually」再打勾;還沒確認就取消打勾,列給使用者。`,
66
67
  docs_none: () => 'docs/cto_jev/ 以外沒有過期的規劃文件。',
67
68
  docs_group_delete: () => '刪除',
68
69
  docs_group_merge: () => '併入某個 feature',
@@ -77,11 +78,10 @@ const messages = {
77
78
  setup_gitignore: () => '[cto] .gitignore 已加入 .cto-brain.json 與 debug_stdin.json',
78
79
  setup_config: () => '[cto] 已建立 .cto.json(請 commit 給團隊共用)',
79
80
  setup_sprint: () => '[cto] 提示:在 .cto.json 填入 sprint_goal 以啟用架構對齊檢查。',
80
- setup_goal_bad_json: () => '[cto] .cto.json 不是合法 JSON,sprint goal 沒有寫入,檔案保持原樣。請先修正該檔。',
81
81
  setup_done: () => '[cto] 安裝完成。',
82
82
  setup_flow_docs: (v) => `[cto] 已建立 docs/cto_jev/ 骨架:${v.list}`,
83
83
  setup_flow_bad_json: () => '[cto] .cto.json 不是合法 JSON,開發流程的選擇沒有寫入,檔案保持原樣。請先修正該檔。',
84
- setup_flow_next: () => '[cto] 下一步:打開你的 agent,跟它說「set up PRODUCT.md and ARCHITECTURE.md」,它會掃 repo 填好再問你剩下的。',
84
+ setup_flow_next: (v) => `[cto] 下一步:打開你的 agent,${v.claude ? '在 Claude Code 打 /cto-jev init,或' : ''}跟它說「set up PRODUCT.md and ARCHITECTURE.md」,它會掃 repo 填好再問你剩下的。`,
85
85
  setup_flow_publish: (v) => `[cto] 偵測到 ${v.file}:docs/cto_jev/ 不要跟著文件網站一起發布(PRODUCT.md 寫著定價和商業規則),請在 ${v.file} 把這個資料夾排除。`,
86
86
  uninstall_hook: (v) => `[cto] 已從 ${v.path} 移除 cto 區塊`,
87
87
  uninstall_gitignore: () => '[cto] 已從 .gitignore 移除 cto 區塊',
@@ -93,7 +93,7 @@ const messages = {
93
93
  wiz_ok: (v) => ` ${v.name} 驗證成功`,
94
94
  wiz_fail: (v) => ` ${v.name} 驗證失敗 (${v.status}) ${v.msg}`,
95
95
  ui_title: () => 'cto 設定',
96
- ui_first_run: () => '共五步:coding agent、Jev provider、API key、sprint goal、開發流程。↑↓ 移動,Enter 確認,Esc 回上一步。完成後會回到總覽,之後也能單獨修改任何一項。',
96
+ ui_first_run: () => '共四步:coding agent、Jev provider、API key、開發流程。↑↓ 移動,Enter 確認,Esc 回上一步。完成後會回到總覽,之後也能單獨修改任何一項。',
97
97
  ui_agents_q: () => '要攔截哪些 coding agent 的指令?',
98
98
  ui_agents_help: () => '↑↓ 移動 · 空白鍵勾選 · Enter 確認 · Esc 返回',
99
99
  ui_always: () => '一律安裝',
@@ -128,8 +128,6 @@ const messages = {
128
128
  ui_retry: () => '重新輸入',
129
129
  ui_save_anyway: () => '仍然儲存(之後用 cto doctor 再確認)',
130
130
  ui_drop: (v) => `不使用 ${v.name}`,
131
- ui_goal_q: () => 'Sprint goal(選填,填了才會檢查 commit 是否偏離目標)',
132
- ui_goal_ph: () => '例如:完成 Stripe 金流,不新增服務',
133
131
  ui_flow_q: () => '要用 cto 開發流程嗎?你的 agent 當 CTO:在 docs/cto_jev/ 規劃、派工、驗收;cto 檢查簽核和漂移。',
134
132
  ui_flow_yes: () => '要,寫入 cto-jev skill(/cto-jev)和 docs/cto_jev/ 骨架',
135
133
  ui_flow_no: () => '不用,只守關卡',
@@ -141,12 +139,10 @@ const messages = {
141
139
  ui_m_agents: () => 'Coding agents',
142
140
  ui_m_providers: () => 'Jev providers 與順序',
143
141
  ui_m_keys: () => '更換 API key',
144
- ui_m_goal: () => 'Sprint goal',
145
142
  ui_m_flow: () => '開發流程',
146
143
  ui_m_lang: () => '語言',
147
144
  ui_m_save: () => '儲存並完成',
148
145
  ui_m_quit: () => '不儲存離開',
149
- ui_unset: () => '未設定',
150
146
  ui_saved: () => '設定完成。之後執行 cto setup 可以回到這個總覽,cto doctor 可以確認是否正常運作。',
151
147
  ui_quit: () => '已離開,沒有修改任何設定。',
152
148
  check_nothing: () => '[cto] 沒有可檢查的改動。',
@@ -251,6 +247,7 @@ const messages = {
251
247
  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.`,
252
248
  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.`,
253
249
  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.`,
250
+ done_manual: (v) => `[cto] ${v.detail}: this task is accepted by the user (manual), but your final message does not say the user confirmed it. Ask the user; once they confirm, say "accepted manually" and tick it. Until then untick it and list it for them.`,
254
251
  docs_none: () => 'No stale planning documents outside docs/cto_jev/.',
255
252
  docs_group_delete: () => 'Delete',
256
253
  docs_group_merge: () => 'Merge into a feature',
@@ -265,11 +262,10 @@ const messages = {
265
262
  setup_gitignore: () => '[cto] Added .cto-brain.json and debug_stdin.json to .gitignore',
266
263
  setup_config: () => '[cto] Created .cto.json (commit it for the team)',
267
264
  setup_sprint: () => '[cto] Tip: set sprint_goal in .cto.json to enable the architecture alignment check.',
268
- setup_goal_bad_json: () => '[cto] .cto.json is not valid JSON, so the sprint goal was not saved and the file was left untouched. Fix it first.',
269
265
  setup_done: () => '[cto] Setup complete.',
270
266
  setup_flow_docs: (v) => `[cto] Created the docs/cto_jev/ skeleton: ${v.list}`,
271
267
  setup_flow_bad_json: () => '[cto] .cto.json is not valid JSON, so the development flow choice was not saved and the file was left untouched. Fix it first.',
272
- setup_flow_next: () => '[cto] Next: open your agent and say "set up PRODUCT.md and ARCHITECTURE.md". It scans the repo, fills what it can, and asks you the rest.',
268
+ setup_flow_next: (v) => `[cto] Next: open your agent and ${v.claude ? 'type /cto-jev init in Claude Code, or ' : ''}say "set up PRODUCT.md and ARCHITECTURE.md". It scans the repo, fills what it can, and asks you the rest.`,
273
269
  setup_flow_publish: (v) => `[cto] ${v.file} found: keep docs/cto_jev/ out of the published site (PRODUCT.md holds pricing and business rules); exclude the folder in ${v.file}.`,
274
270
  uninstall_hook: (v) => `[cto] Removed the cto block from ${v.path}`,
275
271
  uninstall_gitignore: () => '[cto] Removed the cto block from .gitignore',
@@ -281,7 +277,7 @@ const messages = {
281
277
  wiz_ok: (v) => ` ${v.name} OK`,
282
278
  wiz_fail: (v) => ` ${v.name} failed (${v.status}) ${v.msg}`,
283
279
  ui_title: () => 'cto setup',
284
- ui_first_run: () => 'Five steps: coding agents, Jev providers, API keys, sprint goal, development flow. Up/Down to move, Enter to confirm, Esc to go back. You land on an overview at the end and can change any single item later.',
280
+ ui_first_run: () => 'Four steps: coding agents, Jev providers, API keys, development flow. Up/Down to move, Enter to confirm, Esc to go back. You land on an overview at the end and can change any single item later.',
285
281
  ui_agents_q: () => 'Which coding agents should have their commands checked?',
286
282
  ui_agents_help: () => 'Up/Down move · Space toggles · Enter confirms · Esc goes back',
287
283
  ui_always: () => 'always installed',
@@ -316,8 +312,6 @@ const messages = {
316
312
  ui_retry: () => 'Enter it again',
317
313
  ui_save_anyway: () => 'Save anyway (check later with cto doctor)',
318
314
  ui_drop: (v) => `Do not use ${v.name}`,
319
- ui_goal_q: () => 'Sprint goal (optional; enables the check for commits that drift from it)',
320
- ui_goal_ph: () => 'e.g. Ship Stripe billing, no new services',
321
315
  ui_flow_q: () => 'Use the cto development flow? Your agent acts as CTO: plans in docs/cto_jev/, dispatches, accepts; cto checks sign-off and drift.',
322
316
  ui_flow_yes: () => 'Yes, write the cto-jev skill (/cto-jev) and a docs/cto_jev/ skeleton',
323
317
  ui_flow_no: () => 'No, gatekeeping only',
@@ -329,12 +323,10 @@ const messages = {
329
323
  ui_m_agents: () => 'Coding agents',
330
324
  ui_m_providers: () => 'Jev providers and order',
331
325
  ui_m_keys: () => 'Change API keys',
332
- ui_m_goal: () => 'Sprint goal',
333
326
  ui_m_flow: () => 'Development flow',
334
327
  ui_m_lang: () => 'Language',
335
328
  ui_m_save: () => 'Save and finish',
336
329
  ui_m_quit: () => 'Quit without saving',
337
- ui_unset: () => 'not set',
338
330
  ui_saved: () => 'Done. Run cto setup to come back to this overview, and cto doctor to check that it works.',
339
331
  ui_quit: () => 'Left without changing anything.',
340
332
  check_nothing: () => '[cto] Nothing to check.',
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import { checkUpdate, currentVersion, runUpdate } from './update.js';
10
10
  import { doctor } from './doctor.js';
11
11
  import { detectLang, t } from './i18n.js';
12
12
  import { maskDiff, maskSensitiveState } from './masker.js';
13
- import { detectAgents, gitRoot, planSetup, setSprintGoal, setup, wiredAgents } from './setup.js';
13
+ import { detectAgents, gitRoot, planSetup, setup, wiredAgents } from './setup.js';
14
14
  async function readStdin() {
15
15
  if (process.stdin.isTTY)
16
16
  return '';
@@ -107,7 +107,7 @@ if (args[0] === '--hook' && args[1]) {
107
107
  else if (args[0] === 'setup') {
108
108
  const uninstall = args.includes('--uninstall');
109
109
  let chosen;
110
- let goal;
110
+ let interactive = false; // the menu lists every agent, so what is left unticked loses its cto hooks (exact mode)
111
111
  let flow = args.includes('--flow') ? true : args.includes('--no-flow') ? false : undefined;
112
112
  const root = gitRoot(process.cwd());
113
113
  const list = flag('--agents');
@@ -142,16 +142,13 @@ else if (args[0] === 'setup') {
142
142
  saveCredentials(s.keys);
143
143
  savePrefs({ provider_order: s.providers, ...(s.lang && { lang: s.lang }) });
144
144
  chosen = s.agents;
145
- goal = s.goal;
145
+ interactive = true;
146
146
  flow = s.flow ?? false;
147
147
  }
148
148
  else if (!uninstall) {
149
149
  chosen = detectAgents();
150
150
  }
151
- const r = setup(process.cwd(), lang, { uninstall, agents: chosen, exact: goal !== undefined, flow });
152
- if (!r.code && root && goal !== undefined && goal !== loadConfig(root).sprint_goal && !setSprintGoal(root, goal)) {
153
- r.lines.push(t(lang, 'setup_goal_bad_json'));
154
- }
151
+ const r = setup(process.cwd(), lang, { uninstall, agents: chosen, exact: interactive, flow });
155
152
  const latest = r.code ? undefined : await checkUpdate();
156
153
  if (latest)
157
154
  r.lines.push(t(lang, 'update_available', { latest, current: currentVersion() }));
package/dist/setup.js CHANGED
@@ -357,7 +357,7 @@ export function setup(cwd, lang, opts = {}) {
357
357
  return true;
358
358
  } });
359
359
  if (flow && !savedFlow && owed)
360
- lines.push(t(lang, 'setup_flow_next'));
360
+ lines.push(t(lang, 'setup_flow_next', { claude: claude ? 1 : 0 }));
361
361
  // PRODUCT.md holds pricing and business rules: a docs site must not publish docs/cto_jev/. Warn only; config is the user's.
362
362
  const publisher = flow ? docsPublisher(root) : undefined;
363
363
  if (publisher)
package/dist/setupui.js CHANGED
@@ -14,7 +14,7 @@ const WIDE = /[\u1100-\u115f\u2e80-\ua4cf\uac00-\ud7a3\uf900-\ufaff\ufe30-\ufe4f
14
14
  export const displayWidth = (s) => [...s].reduce((w, ch) => w + (WIDE.test(ch) ? 2 : 1), 0);
15
15
  const pad = (s, w) => s + ' '.repeat(Math.max(0, w - displayWidth(s)));
16
16
  /**
17
- * Interactive setup. First run walks agents -> providers -> keys -> sprint goal -> flow (Esc goes back one step), then
17
+ * Interactive setup. First run walks agents -> providers -> keys -> flow (Esc goes back one step), then
18
18
  * shows the menu. Later runs open the menu directly, pre-filled with the current setup, so any single item can be
19
19
  * changed without touching the rest. Returns the final state, or null if the user quits without saving.
20
20
  */
@@ -120,10 +120,6 @@ export async function setupUI(initial, firstRun, lang, o = {}) {
120
120
  }
121
121
  return { ...s, keys: keys, providers: kept };
122
122
  };
123
- const goalStep = async (s) => {
124
- const r = await text({ ...io, message: t(lang, 'ui_goal_q'), placeholder: t(lang, 'ui_goal_ph'), initialValue: s.goal });
125
- return isCancel(r) ? BACK : { ...s, goal: (r ?? '').trim() };
126
- };
127
123
  const flowStep = async (s) => {
128
124
  const r = await select({
129
125
  ...io,
@@ -164,7 +160,7 @@ export async function setupUI(initial, firstRun, lang, o = {}) {
164
160
  intro(t(lang, 'ui_title'), io);
165
161
  if (firstRun) {
166
162
  log.info(t(lang, 'ui_first_run'), io);
167
- const r = await walk([agentsStep, providersStep, keysStepFor(initial.providers), goalStep, flowStep]);
163
+ const r = await walk([agentsStep, providersStep, keysStepFor(initial.providers), flowStep]);
168
164
  if (r === BACK) {
169
165
  outro(t(lang, 'ui_quit'), io);
170
166
  return null;
@@ -176,7 +172,6 @@ export async function setupUI(initial, firstRun, lang, o = {}) {
176
172
  ['agents', t(lang, 'ui_m_agents'), state.agents.map((n) => agents[n].label).join(', ') || t(lang, 'doc_none')],
177
173
  ['providers', t(lang, 'ui_m_providers'), state.providers.map((p, i) => `${i + 1}. ${providers[p].label}`).join(' ') || t(lang, 'doc_none')],
178
174
  ['keys', t(lang, 'ui_m_keys'), state.providers.map((p) => { const v = providers[p].keys.map((k) => state.keys[k] ?? env[k]).filter(Boolean).pop(); return v ? `${providers[p].label} ${tail(v)}` : ''; }).filter(Boolean).join(' ') || t(lang, 'doc_none')],
179
- ['goal', t(lang, 'ui_m_goal'), state.goal || t(lang, 'ui_unset')],
180
175
  ['flow', t(lang, 'ui_m_flow'), t(lang, state.flow ? 'ui_on' : 'ui_off')],
181
176
  ['lang', t(lang, 'ui_m_lang'), state.lang ?? t(lang, 'ui_lang_auto')],
182
177
  ];
@@ -206,7 +201,6 @@ export async function setupUI(initial, firstRun, lang, o = {}) {
206
201
  agents: [agentsStep],
207
202
  providers: [providersStep, keysStepFor(state.providers)],
208
203
  keys: [keysStepFor(null)],
209
- goal: [goalStep],
210
204
  flow: [flowStep],
211
205
  lang: [langStep],
212
206
  };
package/dist/turn.js CHANGED
@@ -84,6 +84,8 @@ export function turnActions(transcriptPath, cwd) {
84
84
  return actions;
85
85
  }
86
86
  export const BOX = /^(\s*)[-*+] \[([ xX])\]\s+(.*)$/;
87
+ /** A task's acceptance line (cto-flow TASKS.md): `驗收: <command>` or `accept: <command>`, or `manual`. */
88
+ export const ACCEPT = /^\s*(?:驗收|accept)[::]\s*(.+?)\s*$/i;
87
89
  const itemKey = (file, text) => `${file}:${text.replace(/\s+/g, ' ').trim().toLowerCase().slice(0, 60)}`;
88
90
  /**
89
91
  * Checklist items a unified diff of markdown files marks done: every added "[x]" line, except ones that were already
@@ -111,7 +113,69 @@ export function tickedItems(diff, read) {
111
113
  }
112
114
  // Already done before when one wording extends the other ("Fix X" -> "Fix X (see #12)").
113
115
  const wasDone = (k) => before.some((b) => k.startsWith(b) || b.startsWith(k));
114
- return added.filter((a) => !wasDone(itemKey(a.file, a.text))).map(({ line, ...a }) => ({ ...a, children: nested(read(a.file), line) }));
116
+ return added.filter((a) => !wasDone(itemKey(a.file, a.text))).map(({ line, ...a }) => {
117
+ const text = read(a.file);
118
+ // Only cto-flow TASKS.md carry acceptance lines; elsewhere "驗收:" is usually prose, not a command.
119
+ const accept = a.file.startsWith('docs/cto_jev/') ? acceptOf(text, line) : undefined;
120
+ return { ...a, children: nested(text, line), ...(accept && { accept }) };
121
+ });
122
+ }
123
+ /** The acceptance line indented under `item`, before any nested item or anything at the item's depth or lower. */
124
+ function acceptOf(text, item) {
125
+ const lines = text?.split(/\r?\n/) ?? [];
126
+ const at = lines.indexOf(item);
127
+ if (at < 0)
128
+ return undefined;
129
+ const indent = BOX.exec(item)[1].length;
130
+ for (const l of lines.slice(at + 1)) {
131
+ if (!l.trim())
132
+ continue;
133
+ if (l.length - l.trimStart().length <= indent || BOX.test(l))
134
+ return undefined; // next item, or a child's own line
135
+ const m = ACCEPT.exec(l);
136
+ if (m)
137
+ return m[1].replace(/^`+|`+$/g, '').trim() || undefined;
138
+ }
139
+ return undefined;
140
+ }
141
+ const squash = (s) => s.replace(/\s+/g, ' ').trim();
142
+ const MANUAL = /^manual\b/i;
143
+ const TASK_ID = /^[A-Z][A-Z0-9]*-\d+(?:\.\d+)*\b/;
144
+ /** The final message says this task was accepted manually: the phrase, not negated, in a line naming the task's id. */
145
+ function acceptedManually(t, lastMessage) {
146
+ const id = TASK_ID.exec(t.text)?.[0];
147
+ return lastMessage.split(/\r?\n|(?<=[.。;;])\s*/).some((s) => /accepted manually/i.test(s) && !/\bnot\s+(?:yet\s+)?accepted manually/i.test(s) && (!id || s.includes(id)));
148
+ }
149
+ /** Ticked `manual` tasks the final message does not report as accepted by the user: a text check, so no model judges it. */
150
+ export const manualUnconfirmed = (ticked, lastMessage) => ticked.filter((t) => MANUAL.test(squash(t.accept ?? '')) && !acceptedManually(t, lastMessage));
151
+ /** `cmd` run as a command of its own: at a command boundary, and not with its failure swallowed (`|| true`). */
152
+ const runsCommand = (command, cmd) => {
153
+ const esc = cmd.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
154
+ return new RegExp(`(?:^|[;&|(]\\s*)${esc}\\s*(?:$|&&|;|\\)|\\|(?!\\|))`).test(command);
155
+ };
156
+ /**
157
+ * Computed, not judged: for each ticked task with an acceptance line, whether that exact command ran and passed after
158
+ * the last code edit, or for `manual`, whether the final message says the user accepted it.
159
+ */
160
+ function acceptFacts(ticked, actions, lastEdit, lastMessage) {
161
+ const lines = ticked.filter((t) => t.accept).slice(0, 20).map((t) => {
162
+ const name = oneLine(t.text, 60);
163
+ const cmd = squash(t.accept);
164
+ if (MANUAL.test(cmd)) {
165
+ return acceptedManually(t, lastMessage)
166
+ ? `"${name}" is accepted by the user (manual), and the final message says it was accepted manually.`
167
+ : `"${name}" is accepted by the user (manual), but the final message does not say the user accepted it.`;
168
+ }
169
+ const runs = actions.flatMap((a, i) => (a.kind === 'run' && runsCommand(squash(a.command), cmd) ? [{ i, ok: a.ok }] : []));
170
+ if (runs.some((r) => r.i > lastEdit && r.ok))
171
+ return `"${name}": its acceptance command \`${cmd}\` ran after the last code edit and passed.`;
172
+ if (runs.some((r) => r.ok))
173
+ return `"${name}": its acceptance command \`${cmd}\` passed, but only before the last code edit.`;
174
+ if (runs.length)
175
+ return `"${name}": its acceptance command \`${cmd}\` ran this turn and failed.`;
176
+ return `"${name}": its acceptance command \`${cmd}\` did not run this turn.`;
177
+ });
178
+ return lines.length ? `\nFact: ${lines.join('\nFact: ')}` : '';
115
179
  }
116
180
  /** Checklist lines indented under `item` in `text` (at most 15). */
117
181
  function nested(text, item) {
@@ -158,7 +222,7 @@ export function turnState(lastMessage, actions, ticked = []) {
158
222
  : `${i + 1}. ran: ${oneLine(a.command, 200)} -> ${a.ok ? 'succeeded' : 'FAILED'}${a.tail ? `\n output tail: ${tailOf(a.tail, 200)}` : ''}`).join('\n')
159
223
  : '(none)';
160
224
  const plan = ticked.length
161
- ? `\n\nPlan checklist items marked done this turn:\n` + ticked.slice(0, 20).map((t) => `- ${t.file}: ${oneLine(t.text, 200)}${t.children.length ? `\n nested items: ${t.children.map((c) => oneLine(c, 80)).join('; ')}` : ''}`).join('\n') + openParents(ticked)
225
+ ? `\n\nPlan checklist items marked done this turn:\n` + ticked.slice(0, 20).map((t) => `- ${t.file}: ${oneLine(t.text, 200)}${t.children.length ? `\n nested items: ${t.children.map((c) => oneLine(c, 80)).join('; ')}` : ''}`).join('\n') + openParents(ticked) + acceptFacts(ticked, actions, lastEdit, lastMessage)
162
226
  : '';
163
227
  return maskSensitiveState(`The agent's final message to the user:\n"""\n${tailOf(lastMessage, 1500)}\n"""\n\nActions this turn, in order:\n${log}${plan}\n\nFact: ${fact}`);
164
228
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "your-cto-jev",
3
- "version": "0.9.5",
3
+ "version": "0.9.7",
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",