your-cto-jev 0.9.7 → 0.9.9

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/dist/brief.js CHANGED
@@ -161,7 +161,7 @@ export function flowLines(root) {
161
161
  : `Ready · none${tasks.length ? '' : ` · add tasks to ${FLOW_DIR}/features/<slug>/TASKS.md`}`);
162
162
  for (const t of ready) {
163
163
  const first = together.includes(t) ? undefined : together.find((o) => overlaps(o.files, t.files));
164
- const note = t.seq ? ' (seq: runs alone)' : first ? ` (overlaps ${first.id}: run after)` : '';
164
+ const note = t.seq ? ' (seq: runs alone)' : !t.files.length ? ' (no files: runs alone; add (files:))' : first ? ` (overlaps ${first.id}: run after)` : '';
165
165
  L.push(line(t, `files ${t.files.join(', ') || '-'} accept: ${t.accept ?? '-'}${note}`));
166
166
  }
167
167
  if (blocked.length) {
package/dist/doctor.js CHANGED
@@ -7,7 +7,7 @@ import { loadBrain, loadConfig, loadCredentials } from './brain.js';
7
7
  import { flowIssues, issueTotal } from './brief.js';
8
8
  import { AGENT_TIMEOUT_MS } from './hooks.js';
9
9
  import { t } from './i18n.js';
10
- import { GIT_HOOKS, conflictLines, ignoredByGit, missingHooks, wiredAgents } from './setup.js';
10
+ import { GIT_HOOKS, conflictLines, hooksDir, ignoredByGit, missingHooks, wiredAgents } from './setup.js';
11
11
  import { guidancePaths, staleGuidance } from './skill.js';
12
12
  import { checkUpdate, currentVersion } from './update.js';
13
13
  function hint(provider, status) {
@@ -82,16 +82,21 @@ export async function doctor(cwd, lang, slowMs = AGENT_TIMEOUT_MS) {
82
82
  }
83
83
  else {
84
84
  L.push('', t(lang, 'doc_repo', { root }));
85
- const hooksDir = execFileSync('git', ['rev-parse', '--path-format=absolute', '--git-path', 'hooks'], { cwd: root, encoding: 'utf8' }).trim();
86
- for (const [name] of GIT_HOOKS) {
87
- const hookPath = join(hooksDir, name);
88
- const hook = existsSync(hookPath) ? readFileSync(hookPath, 'utf8') : '';
89
- if (hook.includes('YOUR CTO JEV START'))
90
- L.push(` OK ${t(lang, 'doc_hook_ok', { name, path: hookPath })}`);
91
- else {
85
+ const dir = hooksDir(root);
86
+ const staleHooks = [];
87
+ for (const [name, body] of GIT_HOOKS) {
88
+ const hookPath = join(dir, name);
89
+ const hook = existsSync(hookPath) ? readFileSync(hookPath, 'utf8').replace(/\r\n/g, '\n') : '';
90
+ if (!hook.includes('YOUR CTO JEV START')) {
92
91
  L.push(` !! ${t(lang, 'doc_hook_missing', { name })}`);
93
92
  problems.push(t(lang, 'doc_hook_missing', { name }));
93
+ continue;
94
94
  }
95
+ // An older block (e.g. ≤0.9.8 without the exit-status guard) still has the marker but behaves differently.
96
+ const current = hook.includes(`# >>> YOUR CTO JEV START >>>\n${body}# <<< YOUR CTO JEV END <<<`);
97
+ if (!current)
98
+ staleHooks.push(`${name} hook`);
99
+ L.push(` ${current ? 'OK' : '!!'} ${t(lang, 'doc_hook_ok', { name, path: hookPath })}`);
95
100
  }
96
101
  const wired = wiredAgents(root);
97
102
  L.push(` ${wired.length ? 'OK' : '--'} ${t(lang, 'doc_agents', { list: wired.map((n) => agents[n].label).join(', ') || t(lang, 'doc_none') })}`);
@@ -99,7 +104,7 @@ export async function doctor(cwd, lang, slowMs = AGENT_TIMEOUT_MS) {
99
104
  const hidden = ignoredByGit(root, guidancePaths(wired)).filter((p) => !isTracked(root, p));
100
105
  if (hidden.length)
101
106
  L.push(` -- ${t(lang, 'doc_ignored', { list: hidden.join(', '), cmd: `git add -f ${hidden.join(' ')}` })}`);
102
- const stale = [...missingHooks(root), ...staleGuidance(root, wired)];
107
+ const stale = [...staleHooks, ...missingHooks(root), ...staleGuidance(root, wired)];
103
108
  if (stale.length) {
104
109
  L.push(` !! ${t(lang, 'doc_stale', { list: stale.join(', ') })}`);
105
110
  problems.push(t(lang, 'doc_stale', { list: stale.join(', ') }));
package/dist/flow.js CHANGED
@@ -99,12 +99,13 @@ export function openTasks(tasks) {
99
99
  }
100
100
  /**
101
101
  * Ready tasks that can run at the same time: taken in the given order, skipping any whose files overlap one already
102
- * taken and any marked (seq), which always runs on its own.
102
+ * taken and any that runs alone: marked (seq), or with no (files:), whose reach is unknown.
103
103
  */
104
+ export const runsAlone = (t) => !!t.seq || !t.files.length;
104
105
  export function parallelTasks(ready) {
105
106
  const out = [];
106
107
  for (const t of ready)
107
- if (!t.seq && !out.some((o) => overlaps(o.files, t.files)))
108
+ if (!runsAlone(t) && !out.some((o) => overlaps(o.files, t.files)))
108
109
  out.push(t);
109
110
  return out;
110
111
  }
package/dist/i18n.js CHANGED
@@ -75,7 +75,7 @@ const messages = {
75
75
  setup_bad_json: (v) => `[cto] ${v.path} 不是合法 JSON 或 hooks 格式不符,未修改任何檔案。請先修正該檔。`,
76
76
  setup_hook: (v) => `[cto] ${v.name} 區塊已寫入 ${v.path}`,
77
77
  setup_hook_exit: (v) => `[cto] 警告:${v.path} 在 cto 區塊之前有 exit 0,cto 檢查不會執行。請調整該 hook。`,
78
- setup_gitignore: () => '[cto] .gitignore 已加入 .cto-brain.json 與 debug_stdin.json',
78
+ setup_gitignore: () => '[cto] .gitignore 已加入 .cto-brain.json、debug_stdin.json 與 .claude/settings.local.json',
79
79
  setup_config: () => '[cto] 已建立 .cto.json(請 commit 給團隊共用)',
80
80
  setup_sprint: () => '[cto] 提示:在 .cto.json 填入 sprint_goal 以啟用架構對齊檢查。',
81
81
  setup_done: () => '[cto] 安裝完成。',
@@ -259,7 +259,7 @@ const messages = {
259
259
  setup_bad_json: (v) => `[cto] ${v.path} is not valid JSON or has an unexpected hooks shape. Nothing was changed. Fix it first.`,
260
260
  setup_hook: (v) => `[cto] ${v.name} block written to ${v.path}`,
261
261
  setup_hook_exit: (v) => `[cto] Warning: ${v.path} has an exit 0 before the cto block, so cto will never run. Adjust that hook.`,
262
- setup_gitignore: () => '[cto] Added .cto-brain.json and debug_stdin.json to .gitignore',
262
+ setup_gitignore: () => '[cto] Added .cto-brain.json, debug_stdin.json and .claude/settings.local.json to .gitignore',
263
263
  setup_config: () => '[cto] Created .cto.json (commit it for the team)',
264
264
  setup_sprint: () => '[cto] Tip: set sprint_goal in .cto.json to enable the architecture alignment check.',
265
265
  setup_done: () => '[cto] Setup complete.',
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, setup, wiredAgents } from './setup.js';
13
+ import { detectAgents, gitRoot, isSetUp, planSetup, setup, wiredAgents } from './setup.js';
14
14
  async function readStdin() {
15
15
  if (process.stdin.isTTY)
16
16
  return '';
@@ -114,7 +114,7 @@ else if (args[0] === 'setup') {
114
114
  if (args.includes('--refresh')) {
115
115
  // Re-write everything cto manages for the agents already wired here; choices stay as they are.
116
116
  chosen = root ? wiredAgents(root) : [];
117
- if (root && !chosen.length) {
117
+ if (root && !isSetUp(root)) {
118
118
  console.log(t(lang, 'refresh_none'));
119
119
  process.exit(0);
120
120
  }
@@ -161,7 +161,7 @@ else if (args[0] === 'update') {
161
161
  console.log(t(lang, 'update_done'));
162
162
  // The new version refreshes this repo's managed hooks and rules, so changes reach it without re-running setup.
163
163
  const root = gitRoot(process.cwd());
164
- if (root && wiredAgents(root).length) {
164
+ if (root && isSetUp(root)) {
165
165
  console.log(t(lang, 'refresh_after_update'));
166
166
  spawnSync('cto setup --refresh', { stdio: 'inherit', shell: true, cwd: root });
167
167
  }
package/dist/setup.js CHANGED
@@ -11,16 +11,21 @@ import { FLOW_DIR } from './flow.js';
11
11
  const START = '# >>> YOUR CTO JEV START >>>';
12
12
  const END = '# <<< YOUR CTO JEV END <<<';
13
13
  // Keep the block minimal: all logic (including the git diff call) lives in the package, so npm update upgrades every repo.
14
- const HOOK_BODY = 'if command -v cto >/dev/null 2>&1; then\n cto --hook git-commit || exit 1\nfi\n';
14
+ // A hook's result is its last command's; once our block is last, a failing line above it (biome, lint) would be ignored.
15
+ const KEEP_FAIL = 's=$?; [ $s -eq 0 ] || exit $s\n';
16
+ const HOOK_BODY = KEEP_FAIL + 'if command -v cto >/dev/null 2>&1; then\n cto --hook git-commit || exit 1\nfi\n';
15
17
  // pre-push gets git's ref lines on stdin; they are passed straight through.
16
- const PUSH_BODY = 'if command -v cto >/dev/null 2>&1; then\n cto --hook git-push || exit 1\nfi\n';
18
+ const PUSH_BODY = KEEP_FAIL + 'if command -v cto >/dev/null 2>&1; then\n cto --hook git-push || exit 1\nfi\n';
17
19
  export const GIT_HOOKS = [['pre-commit', HOOK_BODY], ['pre-push', PUSH_BODY]];
18
- const IGNORE_BODY = '.cto-brain.json\n.cto-brain.json.*tmp\ndebug_stdin.json\n';
20
+ // settings.local.json is Claude Code's per-machine file; often only the global gitignore covers it, which linters like biome never read.
21
+ const IGNORE_BODY = '.cto-brain.json\n.cto-brain.json.*tmp\ndebug_stdin.json\n.claude/settings.local.json\n';
19
22
  const OURS = (cmd) => typeof cmd === 'string' && cmd.startsWith('cto --hook ');
20
23
  const block = (body) => `${START}\n${body}${END}\n`;
21
- const blockRe = /\n?# >>> YOUR CTO JEV START >>>\n[\s\S]*?# <<< YOUR CTO JEV END <<<\n?/;
24
+ // \r?\n: an editor or core.autocrlf may have turned the file CRLF; the block must still be found, or setup appends a second one.
25
+ const blockRe = /(\r?\n)?# >>> YOUR CTO JEV START >>>\r?\n[\s\S]*?# <<< YOUR CTO JEV END <<<(\r?\n)?/;
22
26
  export function removeBlock(content) {
23
- return content.replace(blockRe, (m) => (m.startsWith('\n') && m.endsWith('\n') ? '\n' : ''));
27
+ // Keep the user's own newline before the block, in the user's line ending.
28
+ return content.replace(blockRe, (_m, lead, trail) => (lead && trail ? lead : ''));
24
29
  }
25
30
  export function appendBlock(content, body) {
26
31
  const base = removeBlock(content);
@@ -31,6 +36,30 @@ export function hasEarlyExit(content) {
31
36
  return /^\s*exit\s+0\b/m.test(removeBlock(content));
32
37
  }
33
38
  const git = (cwd, ...args) => execFileSync('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
39
+ /**
40
+ * IGNORE_BODY entries the repo's own .gitignore does not already cover outside our block: an exact line, or any rule there
41
+ * git says matches (`.claude/` covers `.claude/settings.local.json`). Global excludesFile and .git/info/exclude do not
42
+ * count; linters like biome never read them. shortcut: a rule in a nested .gitignore does not count either.
43
+ */
44
+ function missingIgnores(root, text) {
45
+ const lines = text.split(/\r?\n/);
46
+ const have = new Set(removeBlock(text).split(/\r?\n/).map((l) => l.trim()));
47
+ const [start, end] = [lines.findIndex((l) => l.trim() === START), lines.findIndex((l) => l.trim() === END)];
48
+ const inBlock = (n) => start >= 0 && n - 1 >= start && n - 1 <= (end >= 0 ? end : lines.length);
49
+ const entries = IGNORE_BODY.split('\n').filter((l) => l && !have.has(l));
50
+ let out = '';
51
+ // Exit 1 means nothing matched; a git failure leaves the exact-line answer.
52
+ try {
53
+ if (entries.length)
54
+ out = execFileSync('git', ['check-ignore', '--no-index', '-v', ...entries], { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
55
+ }
56
+ catch { /* none covered */ }
57
+ const covered = new Set(out.split('\n').flatMap((l) => {
58
+ const m = /^\.gitignore:(\d+):([^\t]*)\t(.*)$/.exec(l);
59
+ return m && !m[2].startsWith('!') && !inBlock(+m[1]) ? [m[3]] : [];
60
+ }));
61
+ return entries.filter((e) => !covered.has(e));
62
+ }
34
63
  /** Hooks dir honoring core.hooksPath (via --git-path). Husky's generated .husky/_ is replaced on install, so use .husky. */
35
64
  export function hooksDir(root) {
36
65
  const dir = git(root, 'rev-parse', '--path-format=absolute', '--git-path', 'hooks');
@@ -190,8 +219,7 @@ export function planSetup(root, chosenAgents, flow, goal) {
190
219
  at(p, 'write');
191
220
  const ignore = join(root, '.gitignore');
192
221
  const ignoreText = existsSync(ignore) ? readFileSync(ignore, 'utf8') : '';
193
- const have = new Set(removeBlock(ignoreText).split(/\r?\n/).map((l) => l.trim()));
194
- const missing = IGNORE_BODY.split('\n').filter((l) => l && !have.has(l));
222
+ const missing = missingIgnores(root, ignoreText);
195
223
  if (missing.length && appendBlock(ignoreText, missing.join('\n') + '\n') !== ignoreText)
196
224
  at('.gitignore', 'write');
197
225
  const cfg = loadConfig(root);
@@ -323,8 +351,7 @@ export function setup(cwd, lang, opts = {}) {
323
351
  // 3. .gitignore block.
324
352
  // Only the entries the file lacks outside our block; a repo that already ignores them all gets no block.
325
353
  const ignoreText = existsSync(ignorePath) ? readFileSync(ignorePath, 'utf8') : '';
326
- const have = new Set(removeBlock(ignoreText).split(/\r?\n/).map((l) => l.trim()));
327
- const missing = IGNORE_BODY.split('\n').filter((l) => l && !have.has(l));
354
+ const missing = missingIgnores(root, ignoreText);
328
355
  if (missing.length) {
329
356
  writeFileSync(ignorePath, appendBlock(ignoreText, missing.join('\n') + '\n'));
330
357
  lines.push(t(lang, 'setup_gitignore'));
@@ -415,6 +442,16 @@ export function wiredAgents(root) {
415
442
  return existsSync(p) && readFileSync(p, 'utf8').includes('cto --hook ');
416
443
  });
417
444
  }
445
+ /** cto was set up here: an agent is wired, or only the git hooks are (setup with no agents). */
446
+ export function isSetUp(root) {
447
+ if (wiredAgents(root).length)
448
+ return true;
449
+ // A global core.hooksPath is shared by every repo; .cto.json (always written by setup) says it was this one.
450
+ if (!existsSync(join(root, '.cto.json')))
451
+ return false;
452
+ const dir = hooksDir(root);
453
+ return GIT_HOOKS.some(([name]) => existsSync(join(dir, name)) && blockRe.test(readFileSync(join(dir, name), 'utf8')));
454
+ }
418
455
  /** Repo root, or undefined outside a git repo. */
419
456
  export function gitRoot(cwd) {
420
457
  try {
package/dist/skill.js CHANGED
@@ -11,7 +11,8 @@ export const SKILL_PATH = '.agents/skills/cto/SKILL.md';
11
11
  const LEGACY_SKILL = '.claude/skills/cto/SKILL.md'; // 0.5.0 pre-release layout, cleaned up on sync
12
12
  const MD_START = '<!-- >>> YOUR CTO JEV START >>> -->';
13
13
  const MD_END = '<!-- <<< YOUR CTO JEV END <<< -->';
14
- const mdBlockRe = /\n?<!-- >>> YOUR CTO JEV START >>> -->\n[\s\S]*?<!-- <<< YOUR CTO JEV END <<< -->\n?/;
14
+ // \r?\n: a CLAUDE.md turned CRLF (editor, core.autocrlf) must still match, or setup appends a second rules block.
15
+ const mdBlockRe = /(?:\r?\n)?<!-- >>> YOUR CTO JEV START >>> -->\r?\n[\s\S]*?<!-- <<< YOUR CTO JEV END <<< -->(?:\r?\n)?/;
15
16
  export const MEMORY_FILES = [
16
17
  { path: 'CLAUDE.md', agents: ['claude'] },
17
18
  { path: 'AGENTS.md', agents: ['codex', 'cursor'] },
@@ -178,7 +179,7 @@ IDs: \`<PREFIX>-<n>\`, children \`<n>.<m>\`, prefix uppercase and unique across
178
179
 
179
180
  Two more tags, on any task:
180
181
  - **Priority** \`(P1)\` / \`(P2)\` / \`(P3)\`. P1: do first, and nothing releases while one is open (blockers, review findings that are wrong or unsafe). P2: normal work; the default when the tag is absent. P3: when nothing else is left (polish, nice-to-have). brief lists Ready as P1, then P2, then P3.
181
- - **Sync** \`(seq)\`: this task runs alone, whatever its \`(files:)\` say. Use it for migrations, shared types, route tables, anything that touches state every other task reads. Without the tag a task may run together with any Ready task whose \`(files:)\` do not overlap its own; brief computes that and shows the "run together" set.
182
+ - **Sync** \`(seq)\`: this task runs alone, whatever its \`(files:)\` say. Use it for migrations, shared types, route tables, anything that touches state every other task reads. Without the tag a task may run together with any Ready task whose \`(files:)\` do not overlap its own; brief computes that and shows the "run together" set. A task with no \`(files:)\` also runs alone, since its reach is unknown.
182
183
 
183
184
  \`\`\`md
184
185
  - [ ] CUST-3 Add customer_tier column (P1) (seq) (files: db/migrations/)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "your-cto-jev",
3
- "version": "0.9.7",
3
+ "version": "0.9.9",
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",