codehere 2.1.0-rc.2 → 2.1.0-rc.4
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 +7 -6
- package/package.json +2 -2
- package/src/audit.js +64 -21
- package/src/brain.js +172 -47
- package/src/commands.js +24 -2
- package/src/gitpath.js +47 -0
- package/src/hooks.js +489 -45
- package/src/noskip.js +590 -0
- package/src/signals.js +651 -23
package/src/commands.js
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
readRules, listDocs, parseDoc, renderDoc, slug, stamp, today, git, isGitRepo, me,
|
|
9
9
|
readApprovals, isApproved, addApproval, removeApprovals, markRemoved, printable, noTick, commitId,
|
|
10
10
|
saveRecord, writeDraft, readPlain, writePlain, removePlain, ownPath, teamSnapshot, teamMark, keepSaved,
|
|
11
|
+
hasGit,
|
|
11
12
|
} from './brain.js';
|
|
12
13
|
import { redact } from './signals.js';
|
|
13
14
|
import { summarize } from './gemma.js';
|
|
@@ -241,7 +242,8 @@ function saveOrExit(root, rec) {
|
|
|
241
242
|
// typed by the person, so not the agent's change in a session that is open now
|
|
242
243
|
const after = teamSnapshot(root);
|
|
243
244
|
const state = readState(root);
|
|
244
|
-
|
|
245
|
+
const moved = Object.entries(state.sessions || {}).filter(([, x]) => keepSaved(x, before, after)).map(([k]) => k);
|
|
246
|
+
if (moved.length) writeState(root, state, moved, []);
|
|
245
247
|
return saved;
|
|
246
248
|
}
|
|
247
249
|
|
|
@@ -304,6 +306,10 @@ export async function init(flags) {
|
|
|
304
306
|
console.error(`Unknown agent "${printable(flags.agent === true ? '' : flags.agent)}". Use --agent with claude, codex or copilot, or several: --agent claude,codex,copilot.`);
|
|
305
307
|
process.exit(1);
|
|
306
308
|
}
|
|
309
|
+
if (!hasGit()) {
|
|
310
|
+
console.error('codehere init: git was not found on PATH. Codehere reads what the agent changed through git, so nothing was set up.');
|
|
311
|
+
process.exit(1);
|
|
312
|
+
}
|
|
307
313
|
const agents = [...new Set(names)].map((n) => AGENTS[n]);
|
|
308
314
|
const root = process.cwd();
|
|
309
315
|
// Everything init writes, checked before anything is written: a committed link anywhere on these
|
|
@@ -368,10 +374,26 @@ export async function init(flags) {
|
|
|
368
374
|
console.log("Copilot runs a repo's hooks only in a folder you trust. Answer yes when Copilot asks on its first start here.");
|
|
369
375
|
console.log('');
|
|
370
376
|
}
|
|
377
|
+
const onPath = hooksCodehere();
|
|
378
|
+
if (onPath) console.log(`${onPath}\n`);
|
|
371
379
|
console.log(`Next: commit .codehere/ and ${agents.map((a) => a.file).join(' and ')} so your team gets it too.`);
|
|
372
380
|
console.log(`Then just use ${agents.map((a) => a.name).join(' or ')} as usual. Codehere stays quiet unless it helps.`);
|
|
373
381
|
}
|
|
374
382
|
|
|
383
|
+
// The hooks call `codehere` from PATH. Set up through npx, or beside an older global install, they would fail
|
|
384
|
+
// with "command not found" or run another version, and the finish check would not be this one.
|
|
385
|
+
function hooksCodehere() {
|
|
386
|
+
const own = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
|
|
387
|
+
let found = '';
|
|
388
|
+
try {
|
|
389
|
+
found = execFileSync('codehere', ['--version'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], timeout: 10000 }).trim().replace(/^codehere /, '');
|
|
390
|
+
} catch {}
|
|
391
|
+
if (found === own) return null;
|
|
392
|
+
return found
|
|
393
|
+
? `The hooks run the codehere on PATH, which is ${printable(found)}, not this ${own}. To use ${own}: npm install -g codehere@${own}`
|
|
394
|
+
: `The hooks call codehere, which is not on PATH here, so they cannot run. Install it: npm install -g codehere@${own}`;
|
|
395
|
+
}
|
|
396
|
+
|
|
375
397
|
// ---------- uninstall ----------
|
|
376
398
|
|
|
377
399
|
function removeGitignoreLine(root) {
|
|
@@ -615,7 +637,7 @@ export async function brief(flags) {
|
|
|
615
637
|
const file = path.join(paths(root).briefs, `${stamp()}.md`);
|
|
616
638
|
writePlain(root, file, text + '\n'); // briefs/ may be a committed link
|
|
617
639
|
state.pendingBrief = file;
|
|
618
|
-
writeState(root, state);
|
|
640
|
+
writeState(root, state, [], ['pendingBrief']); // no session changed here: every session is kept as it is on disk
|
|
619
641
|
console.log(text);
|
|
620
642
|
console.log('');
|
|
621
643
|
console.log(`Saved to ${path.relative(root, file)}.`);
|
package/src/gitpath.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Git writes a path that holds a tab, newline, quote, backslash or (by default) a non-ASCII character
|
|
2
|
+
// C-quoted and escaped: "test/caf\303\251.test.js". This gives the path back as it is on disk.
|
|
3
|
+
export function unquotePath(p) {
|
|
4
|
+
if (p.length < 2 || p[0] !== '"' || p.at(-1) !== '"') return p;
|
|
5
|
+
const s = p.slice(1, -1);
|
|
6
|
+
const named = { a: 7, b: 8, t: 9, n: 10, v: 11, f: 12, r: 13 };
|
|
7
|
+
const parts = [];
|
|
8
|
+
const re = /\\([0-7]{3}|.)/g;
|
|
9
|
+
let at = 0;
|
|
10
|
+
for (let m; (m = re.exec(s)); at = re.lastIndex) {
|
|
11
|
+
parts.push(Buffer.from(s.slice(at, m.index)));
|
|
12
|
+
const c = m[1];
|
|
13
|
+
parts.push(Buffer.from([c.length === 3 ? parseInt(c, 8) : (named[c] ?? c.charCodeAt(0))]));
|
|
14
|
+
}
|
|
15
|
+
parts.push(Buffer.from(s.slice(at)));
|
|
16
|
+
return Buffer.concat(parts).toString('utf8');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Reads a unified diff one line at a time and says whether the line is in a hunk, counting the lines its
|
|
20
|
+
// header announced (@@ -3,2 +3,0 @@). In a hunk, an added "++ n;" reads "+++ n;" and a removed "-- seed"
|
|
21
|
+
// reads "--- seed": they are lines of the file, never the next file's header (cold review, L13 round 5).
|
|
22
|
+
export function hunkReader() {
|
|
23
|
+
let old = 0;
|
|
24
|
+
let now = 0;
|
|
25
|
+
return (line) => {
|
|
26
|
+
if (old > 0 || now > 0) {
|
|
27
|
+
const c = line[0];
|
|
28
|
+
if (c === '\\') return true;
|
|
29
|
+
if (c === '-' && old > 0) return old--, true;
|
|
30
|
+
if (c === '+' && now > 0) return now--, true;
|
|
31
|
+
// an empty line is a blank context line written without its space (diff.suppressBlankEmpty)
|
|
32
|
+
if ((c === ' ' || line === '') && old > 0 && now > 0) return old--, now--, true;
|
|
33
|
+
old = now = 0; // the line does not fit the counts: the hunk has ended
|
|
34
|
+
}
|
|
35
|
+
const m = /^@@ -\d+(?:,(\d+))? \+\d+(?:,(\d+))? @@/.exec(line);
|
|
36
|
+
if (m) [old, now] = [m[1] === undefined ? 1 : +m[1], m[2] === undefined ? 1 : +m[2]];
|
|
37
|
+
return false;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// A path as git writes it in a diff: quoted, with C escapes, when it holds a quote, a backslash or a control
|
|
42
|
+
// character, so unquotePath gives it back whole.
|
|
43
|
+
export function quotePath(p) {
|
|
44
|
+
if (!/["\\\x00-\x1f\x7f]/.test(p)) return p;
|
|
45
|
+
const esc = (b) => (b === 34 || b === 92 ? `\\${String.fromCharCode(b)}` : b < 32 || b >= 127 ? `\\${b.toString(8).padStart(3, '0')}` : String.fromCharCode(b));
|
|
46
|
+
return `"${[...Buffer.from(p)].map(esc).join('')}"`;
|
|
47
|
+
}
|