@yeison.restrepo.r/code-conductor 1.39.0 → 1.39.2

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.
@@ -3,7 +3,7 @@ import { readFileSync, realpathSync } from 'node:fs';
3
3
  import { join } from 'node:path';
4
4
  import { pathToFileURL } from 'node:url';
5
5
  import { resolveAssetRoot, resolveHome, nodeMajorAtLeast } from '../lib/installer/env.mjs';
6
- import { assertAssets, assertMergeTargets, deployGlobal, deployProject, chmodHooks } from '../lib/installer/deploy.mjs';
6
+ import { assertAssets, assertMergeTargets, assertNotSelfInstall, deployGlobal, deployProject, chmodHooks } from '../lib/installer/deploy.mjs';
7
7
  import { verbosityHookCommand, mergeVerbosityHook } from '../lib/installer/settings.mjs';
8
8
  import { healGraphifyHook } from '../lib/installer/heal.mjs';
9
9
  import { writeVerbosity, writeVersionFile } from '../lib/installer/config.mjs';
@@ -52,13 +52,15 @@ function pkgVersion(assetRoot) {
52
52
  }
53
53
 
54
54
  // log(stream, msg) is injected so tests capture output without spawning a process.
55
- export function run(argv, env = process.env, { cwd = process.cwd(), log } = {}) {
55
+ export function run(argv, env = process.env, { cwd = process.cwd(), log, nodeVersion = process.versions.node } = {}) {
56
56
  const emit = log || ((stream, msg) => process[stream].write(`${msg}\n`));
57
57
 
58
58
  // Hard runtime floor: refuse to run on Node < 20 with a clear message rather than
59
- // failing obscurely inside cpSync/ESM later. env.node lets tests inject a version.
60
- if (!nodeMajorAtLeast(20, env.node)) {
61
- emit('stderr', `code-conductor: Node >=20 required, found ${env.node || process.versions.node}`);
59
+ // failing obscurely inside cpSync/ESM later. The version comes from options, never env:
60
+ // on Windows env lookups are case-insensitive and npm sets NODE to node.exe's path,
61
+ // so a lowercase node key read that path (BUG-060).
62
+ if (!nodeMajorAtLeast(20, nodeVersion)) {
63
+ emit('stderr', `code-conductor: Node >=20 required, found ${nodeVersion}`);
62
64
  return 1;
63
65
  }
64
66
 
@@ -90,6 +92,7 @@ export function run(argv, env = process.env, { cwd = process.cwd(), log } = {})
90
92
  try {
91
93
  assertAssets(assetRoot, ['global', 'skills', 'scripts', 'project-template']); // pre-flight
92
94
  assertMergeTargets(home, cwd, opts.project); // pre-flight
95
+ if (opts.project) assertNotSelfInstall(assetRoot, cwd); // pre-flight, BUG-052
93
96
  writing = true; // copy phase begins
94
97
  const claudeDir = deployGlobal(assetRoot, home, { warn: (m) => emit('stderr', m), report: (m) => emit('stdout', m) });
95
98
  chmodHooks(claudeDir);
@@ -113,7 +116,8 @@ export function run(argv, env = process.env, { cwd = process.cwd(), log } = {})
113
116
  }
114
117
  // Precondition conflict (--project target is a non-directory) → exit 1, not 2:
115
118
  // nothing was partially written for the project, the path is simply unusable.
116
- if (err.code === 'PROJECT_TARGET_NOT_DIR') { emit('stderr', `code-conductor: ${err.message}`); return 1; }
119
+ // SELF_INSTALL is caught in pre-flight; this mapping is the backstop should that ordering ever change.
120
+ if (err.code === 'PROJECT_TARGET_NOT_DIR' || err.code === 'SELF_INSTALL') { emit('stderr', `code-conductor: ${err.message}`); return 1; }
117
121
  // Environment errors that surface on the very first write are still exit 1.
118
122
  if (err.code === 'EROFS') { emit('stderr', `code-conductor: cannot write to ${err.path} (read-only file system) — remount writable or adjust permissions`); return 1; }
119
123
  if (err.code === 'EACCES' || err.code === 'EPERM') { emit('stderr', `code-conductor: permission denied writing ${err.path} — fix with chmod/chown`); return 1; }
package/global/CLAUDE.md CHANGED
@@ -23,7 +23,7 @@ Never write code without an approved spec. Never start implementing without an a
23
23
 
24
24
  Before reading any file or spawning any search, classify the task and walk this chain. Stop at the first step that answers the question.
25
25
 
26
- 1. **Memory**: check `.claude/memory/project.md`. If the answer is there, stop.
26
+ 1. **Memory**: check `.claude/memory/project.md` (project) and `~/.claude/memory/personal.md` (global preferences). If the answer is there, stop.
27
27
  2. **Grep / Glob** — pattern search? Use `Grep` or `Glob` inline. Stop.
28
28
  3. **Explore sub-agent** — need 3+ files to answer one question? Spawn an `Explore` sub-agent. It returns a ≤200-word summary. Main context receives only the summary. Stop.
29
29
  4. **Parallel agents** — 2+ independent implementation tasks? Spawn parallel agents in worktrees. Each returns a ≤200-word summary.
@@ -61,8 +61,10 @@ Auto-run `/cc-stack` at the start of every session. It runs the dynamic detector
61
61
 
62
62
  ## Memory
63
63
 
64
- - `project.md` — in git, shared with the team. Decisions, conventions, debt, workarounds.
65
- - `personal.md` — local only, never committed. Developer preferences, personal shortcuts.
64
+ - `project.md` — at `.claude/memory/project.md`, in git, shared with the team. Decisions, conventions, debt, workarounds.
65
+ - `personal.md` — local only, never committed. Developer preferences, personal shortcuts. Two files carry this name:
66
+ - `~/.claude/memory/personal.md` is the cross-project default. Read it at session start alongside project memory.
67
+ - `.claude/memory/personal.md` is this project's copy, written by `/cc-checkpoint` and read by `/cc-resume`. It wins on any clash, because the most specific layer wins, as in settings.
66
68
  - Run `/cc-checkpoint` before `/compact`, after feature completion, after key architectural decisions.
67
69
 
68
70
  ## Delegation
@@ -6,7 +6,7 @@ Detect the project stack dynamically and record it in the project's root `CLAUDE
6
6
 
7
7
  ## 1. Resolve the repository root
8
8
 
9
- Run `git rev-parse --show-toplevel`. If it fails (not a git repo), fall back to the directory that contains `scripts/detect-stack.mjs`. Run every command below from that root, and treat the root-level `CLAUDE.md` as the only write target regardless of the user's current subdirectory.
9
+ Run `git rev-parse --show-toplevel`. If it fails (not a git repo), fall back to the project root: the directory that contains `.claude/scripts/detect-stack.mjs` or, failing that, `scripts/detect-stack.mjs`. The root is the directory holding that relative path, never the scripts directory itself, so nothing runs from or writes into it. Run every command below from that root, and treat the root-level `CLAUDE.md` as the only write target regardless of the user's current subdirectory.
10
10
 
11
11
  ## 2. Verify Node is available
12
12
 
@@ -14,7 +14,13 @@ Probe with `node --version`. If it exits non-zero or reports "not found", stop t
14
14
 
15
15
  ## 3. Run the detector
16
16
 
17
- Run `node scripts/detect-stack.mjs` from the repo root, capture stdout, and parse it as JSON. Nothing executes the JSON; consume it as data.
17
+ Resolve the detector by presence, the deployed copy first:
18
+
19
+ ```bash
20
+ D=.claude/scripts/detect-stack.mjs; [ -f "$D" ] || D=scripts/detect-stack.mjs
21
+ ```
22
+
23
+ Run `node "$D"` from the repo root, capture stdout, and parse it as JSON. Nothing executes the JSON; consume it as data.
18
24
 
19
25
  Treat all of the following identically as "no stack detected" - announce it in one line and leave `CLAUDE.md` unmodified (surface stderr if any, but it is non-fatal):
20
26
  - non-zero exit code,
@@ -168,8 +168,37 @@ function warnIfProjectMemoryIsStub(templateClaude, target, emit) {
168
168
  return true;
169
169
  }
170
170
 
171
+ // [BUG-052] Self-install guard: refuse to deploy into the package's own source tree.
172
+ // The sweep heuristic matches by exact file list, which the dev repo satisfies by
173
+ // identity, so --project there would delete tracked source files.
174
+ export function assertNotSelfInstall(assetRoot, cwd) {
175
+ const selfName = packageName(join(assetRoot, 'package.json'));
176
+ if (!selfName || selfName !== packageName(join(cwd, 'package.json'))) return;
177
+ const err = new Error(
178
+ `cannot deploy --project into code-conductor's own source tree (${cwd}). ` +
179
+ `The sweep heuristic would delete tracked scripts/.`
180
+ );
181
+ err.code = 'SELF_INSTALL';
182
+ throw err;
183
+ }
184
+
185
+ // Absent or unparseable means "not this package". Any other read failure is suspect
186
+ // state, never a green light to sweep, so it is rethrown naming the path.
187
+ function packageName(path) {
188
+ let text;
189
+ try {
190
+ text = readFileSync(path, 'utf8');
191
+ } catch (e) {
192
+ if (e.code === 'ENOENT') return null;
193
+ throw new Error(`cannot read ${path} to rule out a self-install: ${e.message}`, { cause: e });
194
+ }
195
+ try { return JSON.parse(text).name ?? null; } catch { return null; }
196
+ }
197
+
171
198
  export function deployProject(assetRoot, cwd, { warn = toStderr, report = toStdout } = {}) {
172
199
  const emit = warn;
200
+ // Also run by the CLI's pre-flight; kept here for direct callers.
201
+ assertNotSelfInstall(assetRoot, cwd);
173
202
  const target = join(cwd, '.claude');
174
203
  const templateRoot = join(assetRoot, 'project-template');
175
204
  // If something already occupies ./.claude and it is NOT a directory, this is a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeison.restrepo.r/code-conductor",
3
- "version": "1.39.0",
3
+ "version": "1.39.2",
4
4
  "description": "A governance layer for Claude Code sessions: hooks that check an agent's commands before they run, a spec-first workflow, and project memory the next session reads.",
5
5
  "keywords": [
6
6
  "agentic-development",
@@ -105,6 +105,18 @@ Each step must include:
105
105
  plain `git add <path>` otherwise. Always generate an explicit path: bare `git add -u`
106
106
  stages every modified tracked file in the repository. The branch is on tracked-ness, never
107
107
  on habit, because `-u` exits 128 on an untracked path whether or not an ignore rule exists.
108
+ - **Plan file in staging steps.** Every commit group that ticks checkboxes in the plan file must
109
+ include a `git add -u <plan-file-path>` step after the checkbox edits so the ticked state
110
+ rides the commit. Ticks from a task's final commit ride the next task's first commit, and
111
+ the last task's ride the closeout commit. A tick made after a group's `git commit` step has
112
+ run, including the tick on that step itself, cannot ride that commit, so it belongs to the
113
+ next commit group that stages the plan file. Without this step, `cc-implement` marks
114
+ checkboxes `[X]` but the committed file still shows the previous state.
115
+ - **Filtered red-step predictions.** When a red step runs the suite through a runner filter
116
+ (`-t`, a file path or a name pattern), a filtered red-step prediction lists the filter's full
117
+ match set: every test the filter selects with its expected state, not only the new tests.
118
+ A filter that also matches already-green tests reads more passes than the new tests alone
119
+ predict, and the mismatch halts a run that is otherwise correct.
108
120
 
109
121
  ## Test List
110
122
  - [ ] Unit tests for [unit]
@@ -19,12 +19,18 @@ Read `CLAUDE.md`. Extract:
19
19
 
20
20
  Use `—` for any missing fields.
21
21
 
22
- **Auto-fill blank command fields (BUG-015):** After reading the identity fields, check if any of `Build`, `Test`, `Lint`, `Format`, `Setup` in CLAUDE.md are still `<command>` (any case) or blank after the colon. If at least one is blank AND `scripts/detect-stack.mjs` exists at `$PWD`:
22
+ **Auto-fill blank command fields (BUG-015):** After reading the identity fields, check if any of `Build`, `Test`, `Lint`, `Format`, `Setup` in CLAUDE.md are still `<command>` (any case) or blank after the colon. If at least one is blank, resolve the detector by presence, the deployed copy first:
23
23
 
24
- 1. Run `node scripts/detect-stack.mjs "$PWD"` and capture the JSON output.
24
+ ```bash
25
+ D=.claude/scripts/detect-stack.mjs; [ -f "$D" ] || D=scripts/detect-stack.mjs
26
+ ```
27
+
28
+ If neither file exists, skip this step silently.
29
+
30
+ 1. Run `node "$D" "$PWD"` and capture the JSON output.
25
31
  2. For each blank/placeholder command field, if the JSON contains a matching key (`build`, `test`, `lint`, `format`, `setup`), replace the placeholder with the detected value using a single `Edit` call.
26
32
  3. Never overwrite a field that already contains a non-placeholder value.
27
- 4. If all five fields are already populated, or if `scripts/detect-stack.mjs` does not exist, skip this step silently.
33
+ 4. If all five fields are already populated, skip this step silently.
28
34
  5. If the JSON is `{}` or node exits non-zero, skip silently.
29
35
 
30
36
  Re-read the updated CLAUDE.md fields after this step so the session resume report reflects the filled values.
@@ -642,20 +642,33 @@ function g3ReadAllowlist() {
642
642
  const g3EscapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
643
643
  const G3_BD = '(^|[ \\t\\n\\r\\f\\v|;()])';
644
644
  const G3_AD = '([ \\t\\n\\r\\f\\v|;()]|$)';
645
+ // The suffix a directory entry may cover: bare, and inside quotes the same class plus a
646
+ // space, because a space inside quotes is part of the path. Nothing wider: inside double
647
+ // quotes $( ) still executes, and the BUG-043 mask hides quoted text from every pattern
648
+ // check, so a quoted suffix admitting $ would let the allowlist cover a substitution
649
+ // alone. [BUG-045]
650
+ const G3_SUFFIX = '([A-Za-z0-9_./@%*?-]*)';
651
+ const G3_QSUFFIX = '([A-Za-z0-9_./@%*? -]*)';
652
+
653
+ // A path is covered bare or as ONE whole quoted token, opened right after a boundary and
654
+ // closed right before one. A quote mid-word is never a boundary, so a quote that splits a
655
+ // path cannot end the match before a ../ the traversal check must see. [BUG-045]
656
+ function g3EntryForms(e, dir) {
657
+ if (!dir) return [e, `"${e}"`, `'${e}'`];
658
+ return [e + G3_SUFFIX, `"${e}${G3_QSUFFIX}"`, `'${e}${G3_QSUFFIX}'`];
659
+ }
645
660
 
646
661
  function g3AllowlistCovers(s, entries) {
647
662
  if (entries.length === 0) return false;
648
663
  for (const entry of entries) {
649
- if (entry.endsWith('/')) {
650
- const m = new RegExp(G3_BD + g3EscapeRe(entry) + '([A-Za-z0-9_./@%*?-]*)' + G3_AD).exec(s);
651
- if (m) {
652
- // G3_BD contributes group 1, so the suffix is group 2, matching the
653
- // authority's BASH_REMATCH[2]. A suffix that walks up the tree is not
654
- // covered: an allowlist entry must not become a path-traversal gift.
655
- if (/(^|\/)\.\.(\/|$)/.test(m[2])) continue;
656
- return true;
657
- }
658
- } else if (new RegExp(G3_BD + g3EscapeRe(entry) + G3_AD).test(s)) {
664
+ const dir = entry.endsWith('/');
665
+ for (const form of g3EntryForms(g3EscapeRe(entry), dir)) {
666
+ const m = new RegExp(G3_BD + form + G3_AD).exec(s);
667
+ if (!m) continue;
668
+ // G3_BD contributes group 1, so the suffix is group 2, matching the
669
+ // authority's BASH_REMATCH[2]. A suffix that walks up the tree is not
670
+ // covered: an allowlist entry must not become a path-traversal gift.
671
+ if (dir && /(^|\/)\.\.(\/|$)/.test(m[2])) break;
659
672
  return true;
660
673
  }
661
674
  }
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: memory-first
3
- description: "Lookup chain enforced before any file read or search: project memory, grep/glob, targeted read — stop at the first step that answers"
3
+ description: "Lookup chain enforced before any file read or search: project and global memory, grep/glob, targeted read — stop at the first step that answers"
4
4
  type: skill
5
5
  ---
6
6
 
@@ -10,13 +10,14 @@ Follow this lookup chain in strict order before reading any file, running any se
10
10
 
11
11
  ## Chain
12
12
 
13
- ### 1. Project Memory
14
- Check `.claude/memory/project.md`.
13
+ ### 1. Memory
14
+ Check `.claude/memory/project.md` (project) and `~/.claude/memory/personal.md` (global preferences).
15
15
 
16
- Use the Grep tool to check project.md first:
16
+ Use the Grep tool on both files:
17
17
 
18
18
  ```
19
19
  Grep pattern="<keyword>" path=".claude/memory/project.md"
20
+ Grep pattern="<keyword>" path="~/.claude/memory/personal.md"
20
21
  ```
21
22
 
22
23
  If Grep returns matches, use that information and stop. If no matches, proceed to step 2.