codehere 2.0.0 → 2.0.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.
package/README.md CHANGED
@@ -140,7 +140,7 @@ npm test # end-to-end checks
140
140
  ## Known limits
141
141
 
142
142
  - Claude Code, Codex CLI and Copilot CLI. OpenCode is next. Copilot in VS Code reads the same hook files but has not been checked, and Copilot's cloud agent is not supported. See [Which agents](#which-agents) for what works on each.
143
- - Lessons match by error text. Very generic errors can bring up a lesson that doesn't fit, which is why the agent gets it as reference, not as an instruction.
143
+ - Lessons match by error text. When both the failure and the lesson name a failing test, the names must be the same, so a lesson for a failed `assert.equal` reaches only a failing test with the same name. Two tests with the same name in different files or suites still share lessons. A generic error outside a test can bring up a lesson that doesn't fit, which is why the agent gets it as reference, not as an instruction.
144
144
  - Redaction catches common keys, tokens and emails. Always read a help card before sharing it.
145
145
  - The "done" check needs a test command. Without one, only the tampering check runs.
146
146
  - Approvals are per folder. Each git worktree or extra clone needs its own `codehere approve`.
package/bin/codehere.js CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import fs from 'node:fs';
2
3
  import { runHook } from '../src/hooks.js';
3
4
  import * as cmd from '../src/commands.js';
4
5
 
@@ -83,6 +84,9 @@ const run = async () => {
83
84
  case 'stats':
84
85
  return cmd.stats();
85
86
  default:
87
+ if (flags.version || command === '-v') {
88
+ return console.log(`codehere ${JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version}`);
89
+ }
86
90
  if (!command || command === '-h') return console.log(USAGE);
87
91
  // stderr only: a hook's stdout can land in the agent's context (e.g. a codehere 1.x
88
92
  // user-level hook such as `codehere scan-tool`). Exit 0 when a hook called us.
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "codehere",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "A git-native team brain for vibe coders. Silent fixes for AI coding agents: breaks doom loops, verifies 'done', blocks test tampering, and shares what your team learned.",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/muhammadegaa/codehere.git",
8
8
  "directory": "v2"
9
9
  },
10
- "homepage": "https://github.com/muhammadegaa/codehere/tree/v2-team-brain/v2#readme",
10
+ "homepage": "https://github.com/muhammadegaa/codehere/tree/main/v2#readme",
11
11
  "type": "module",
12
12
  "bin": {
13
13
  "codehere": "bin/codehere.js"
package/src/commands.js CHANGED
@@ -440,7 +440,10 @@ function repeatedErrors(s) {
440
440
  return Object.entries(s.errors || {})
441
441
  .sort((a, b) => b[1] - a[1])
442
442
  .slice(0, 3)
443
- .map(([sig, n]) => ({ sig, n, raw: (s.rawErrors || {})[sig] || [] }));
443
+ .map(([sig, n]) => {
444
+ const test = s.tests && s.tests[sig];
445
+ return { sig, n, raw: (s.rawErrors || {})[sig] || [], test: typeof test === 'string' ? test : '' };
446
+ });
444
447
  }
445
448
 
446
449
  function gitSummary(root, base) {
@@ -552,7 +555,7 @@ export async function help(question, flags) {
552
555
  fs.writeFileSync(
553
556
  file,
554
557
  renderDoc(
555
- { id, author: me(root), date: today(), status: 'open', signature: errs[0] ? errs[0].sig : '' },
558
+ { id, author: me(root), date: today(), status: 'open', signature: errs[0] ? errs[0].sig : '', ...(errs[0]?.test ? { test: redact(errs[0].test).slice(0, 120) } : {}) },
556
559
  text
557
560
  )
558
561
  );
@@ -614,7 +617,7 @@ export function reply(id, text, flags) {
614
617
  fs.writeFileSync(
615
618
  lessonFile,
616
619
  renderDoc(
617
- { title: q, signature: meta.signature || q, author: who, date: today(), from: `help/${d.id}` },
620
+ { title: q, signature: meta.signature || q, ...(meta.test ? { test: meta.test } : {}), author: who, date: today(), from: `help/${d.id}` },
618
621
  `## Fix\n- ${text}\n`
619
622
  )
620
623
  );
package/src/hooks.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  removedAt,
12
12
  } from './brain.js';
13
13
  import {
14
- responseText, signature, errorLines, similarity, tamperFindings, failingTest, lowInfoPrompt, vagueFeature, testCounts,
14
+ responseText, signature, errorLines, similarity, tamperFindings, failingTest, lowInfoPrompt, vagueFeature, testCounts, redact,
15
15
  } from './signals.js';
16
16
 
17
17
  function readStdin() {
@@ -251,10 +251,12 @@ export function readOnly(command) {
251
251
  return bare.split(/&&|\|\||\|&|[;|\n]/).every((part) => !part.trim() || READ_ONLY.test(part));
252
252
  }
253
253
 
254
- function matchLesson(root, sig, shown) {
254
+ function matchLesson(root, sig, shown, test) {
255
255
  let best = null;
256
256
  for (const doc of listDocs(paths(root).lessons)) {
257
257
  if (shown.includes(doc.id) || doc.body.includes('- Fix: <one line>')) continue; // not filled in yet
258
+ // Every failed assert.equal shares one first line, so when both name the failing test, it must be the same test.
259
+ if (test && doc.meta.test && doc.meta.test !== test) continue;
258
260
  const score = Math.max(
259
261
  similarity(sig, doc.meta.signature || ''),
260
262
  similarity(sig, doc.meta.title || '') * 0.8
@@ -328,13 +330,13 @@ function lessonLine(doc) {
328
330
  }
329
331
 
330
332
  // Codehere writes the proof fields itself; the agent fills in the title, cause and fix.
331
- function writeLesson(root, sig, proofCommand, changed) {
333
+ function writeLesson(root, sig, proofCommand, changed, test) {
332
334
  const dir = paths(root).lessons;
333
335
  fs.mkdirSync(dir, { recursive: true });
334
336
  const name = `${today()}-${slug(sig, 30)}`;
335
337
  let file = path.join(dir, `${name}.md`);
336
338
  for (let i = 2; fs.existsSync(file); i++) file = path.join(dir, `${name}-${i}.md`);
337
- const meta = { title: PLACEHOLDERS[0], signature: sig, author: me(root), date: today(), state: proofCommand ? 'verified' : 'unverified' };
339
+ const meta = { title: PLACEHOLDERS[0], signature: sig, ...(test ? { test: redact(test).slice(0, 120) } : {}), author: me(root), date: today(), state: proofCommand ? 'verified' : 'unverified' };
338
340
  if (proofCommand) {
339
341
  Object.assign(meta, {
340
342
  proof_command: proofCommand,
@@ -371,10 +373,14 @@ function postTool(root, input, agent) {
371
373
  const s = session(state, input.session_id);
372
374
  s.errors[sig] = (s.errors[sig] || 0) + 1;
373
375
  s.rawErrors[sig] = errorLines(text, 8);
374
- s.lastFailure = { sig, command, test: failingTest(text), lines: errorLines(text, 3), prompt: s.prompts || 0 };
376
+ const test = failingTest(text);
377
+ // A lesson names the failing test only if every failure on this line was that test.
378
+ const tests = s.tests && typeof s.tests === 'object' ? s.tests : {};
379
+ s.tests = { ...tests, [sig]: Object.hasOwn(tests, sig) && tests[sig] !== test ? '' : test || '' };
380
+ s.lastFailure = { sig, command, test, lines: errorLines(text, 3), prompt: s.prompts || 0 };
375
381
  const count = s.errors[sig];
376
382
 
377
- const lesson = matchLesson(root, sig, s.shownLessons);
383
+ const lesson = matchLesson(root, sig, s.shownLessons, test);
378
384
  if (lesson) s.shownLessons.push(lesson.id);
379
385
  writeState(root, state);
380
386
 
@@ -685,7 +691,8 @@ function stop(root, input) {
685
691
  if (solved.length && !s.lessonAsked) {
686
692
  s.lessonAsked = true;
687
693
  const [sig] = solved.sort((a, b) => b[1] - a[1])[0];
688
- const file = writeLesson(root, sig, proven ? cfg.testCommand : null, changed);
694
+ const named = s.tests && s.tests[sig];
695
+ const file = writeLesson(root, sig, proven ? cfg.testCommand : null, changed, typeof named === 'string' ? named : '');
689
696
  if (mayBlock) {
690
697
  s.stopBlocks++;
691
698
  writeState(root, state);
package/src/signals.js CHANGED
@@ -57,7 +57,7 @@ export function failingTest(text) {
57
57
  const t = stripAnsi(text);
58
58
  const m =
59
59
  t.match(/^\s*(?:✖|×|✗|not ok \d+ -)\s+(?!failing tests)(.+?)(?:\s+\(?\d[\d.]*\s?m?s\)?)?\s*$/m) ||
60
- t.match(/^\s*●\s+(.+?)\s*$/m) ||
60
+ t.match(/^\s*●\s+(?!Console\s*$)(.+?)\s*$/m) ||
61
61
  t.match(/^FAILED\s+(\S+)/m) ||
62
62
  t.match(/^--- FAIL:\s+(\S+)/m);
63
63
  return m ? m[1].trim().slice(0, 120) : null;
@@ -82,7 +82,7 @@ export function lowInfoPrompt(p) {
82
82
  }
83
83
 
84
84
  const BUILD_START =
85
- /^\s*(please\s+|tolong\s+|can you\s+|could you\s+)?(build|create|make|add|implement|develop|design|set up|setup|buat|buatkan|bikin|bikinin|tambah|tambahkan|bangun)\b/i;
85
+ /^\s*(please\s+|tolong\s+|can you\s+|could you\s+)?(build|create|make|add|implement|develop|design|set up|setup|buat|buatkan|buatin|bikin|bikinin|tambah|tambahkan|tambahin|bangun)\b/i;
86
86
  const BIG = /\b(app|application|feature|system|platform|website|site|dashboard|service|bot|game|aplikasi|fitur|sistem|situs|web)\b/i;
87
87
  const SMALL = /\b(make sure|pastikan|instead|still|again|fix|bug|error|rename|change|ubah|ganti|refactor|button|color|colour|font|style)\b/i;
88
88
  const CHECKABLE =