geneseed 5.4.0 → 5.5.0
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/CHANGELOG.md +34 -0
- package/README.md +30 -0
- package/SHIPPED.md +1 -1
- package/adapters/bob/README.md +12 -1
- package/adapters/opencode/README.md +2 -1
- package/adapters/opencode/plugins/geneseed-context.js +71 -10
- package/adapters/opencode/plugins/geneseed-guard.js +101 -19
- package/adapters/opencode/plugins/geneseed-learn.js +641 -6
- package/bin/geneseed-cli.mjs +3 -0
- package/bin/geneseed-hook.mjs +2 -1
- package/docs/concepts/agents.md +13 -1
- package/docs/concepts/enforcement-table.md +1 -1
- package/docs/concepts/foreman-mode.md +22 -3
- package/docs/concepts/hook-gates.md +1 -1
- package/docs/concepts/hooks.md +22 -5
- package/docs/concepts/host-matrix.md +2 -2
- package/docs/concepts/hosts.md +1 -1
- package/docs/concepts/shared-tier.md +1 -1
- package/docs/concepts/skills.md +21 -1
- package/docs/concepts/themes.md +1 -1
- package/docs/extending.md +10 -1
- package/docs/guides/install-clone.md +18 -0
- package/docs/guides/install-scripted.md +8 -2
- package/docs/guides/install.md +19 -1
- package/docs/guides/upgrade.md +1 -1
- package/docs/reference/env-context.md +1 -1
- package/docs/reference/environment.md +1 -1
- package/docs/reference/plugin-learn.md +4 -0
- package/docs/reference/profiles.md +142 -0
- package/docs/token-footprint.md +9 -4
- package/docs/understand/design-choices-engineering.md +1 -1
- package/docs/web-ui.md +3 -1
- package/harness.config.json +1 -1
- package/js/README.md +9 -2
- package/js/build/args.mjs +4 -3
- package/js/build/catalog.mjs +11 -1
- package/js/build/driver.mjs +42 -11
- package/js/build/emit-claude.mjs +24 -1
- package/js/build/emit-opencode.mjs +3 -0
- package/js/build/export.mjs +1 -1
- package/js/build/generate.mjs +2 -1
- package/js/build/notes-migrate.mjs +99 -0
- package/js/build/profile.mjs +14 -6
- package/js/build/render.mjs +34 -10
- package/js/build/source.mjs +85 -2
- package/js/cli-table.json +164 -4
- package/js/hosts/agent-runs.mjs +205 -0
- package/js/hosts/done-checks.mjs +3 -1
- package/js/hosts/hooks-done.mjs +91 -16
- package/js/hosts/hooks-learn.mjs +85 -0
- package/js/hosts/hooks-prims.mjs +39 -1
- package/js/hosts/hooks.mjs +6 -3
- package/js/hosts/hosts.mjs +10 -0
- package/js/hosts/installs.mjs +25 -1
- package/js/hosts/link.mjs +45 -10
- package/js/hosts/native.mjs +42 -5
- package/js/hosts/opencode.mjs +1 -1
- package/js/hosts/settings.mjs +72 -0
- package/js/hosts/spec-feedback.mjs +538 -0
- package/js/hosts/usage.mjs +67 -8
- package/js/inspect/agent-scores.mjs +118 -0
- package/js/inspect/checks-authoring.mjs +2 -1
- package/js/inspect/checks-build.mjs +20 -4
- package/js/inspect/checks-repo.mjs +27 -2
- package/js/inspect/cost.mjs +6 -5
- package/js/inspect/diff.mjs +25 -5
- package/js/inspect/doctor.mjs +4 -0
- package/js/inspect/status.mjs +3 -1
- package/js/inspect/validate.mjs +1 -0
- package/js/lib/machine-dir.mjs +8 -0
- package/js/lib/paths.mjs +4 -1
- package/js/maintain/profile-scope.mjs +145 -0
- package/js/maintain/profiles.mjs +486 -0
- package/js/maintain/setup.mjs +409 -15
- package/js/maintain/uninstall.mjs +4 -1
- package/js/maintain/update.mjs +1 -1
- package/js/web/actions.mjs +28 -38
- package/js/web/api.mjs +7 -2
- package/js/web/handler.mjs +8 -0
- package/js/web/jobs.mjs +5 -4
- package/js/web/profiles-api.mjs +201 -0
- package/js/web/routes.mjs +5 -0
- package/package.json +2 -1
- package/profiles/guillaume-claude-global.json +16 -0
- package/profiles/starter.json +14 -0
- package/src/AGENT.md.tmpl +1 -1
- package/src/agents/_self-improvement.md +15 -7
- package/src/agents/_template.md +4 -2
- package/src/agents/advocate.md +1 -1
- package/src/agents/architect.md +1 -1
- package/src/agents/developer.md +10 -3
- package/src/agents/devops-engineer.md +1 -1
- package/src/agents/docker-expert.md +1 -1
- package/src/agents/docs.md +1 -1
- package/src/agents/empiricist.md +1 -1
- package/src/agents/explorer.md +4 -2
- package/src/agents/framer.md +1 -1
- package/src/agents/historian.md +1 -1
- package/src/agents/kubernetes-specialist.md +1 -1
- package/src/agents/memory-curator.md +1 -1
- package/src/agents/operator.md +1 -1
- package/src/agents/performance.md +1 -1
- package/src/agents/pragmatist.md +1 -1
- package/src/agents/react-engineer.md +1 -1
- package/src/agents/react-reviewer.md +1 -1
- package/src/agents/researcher.md +1 -1
- package/src/agents/reviewer.md +10 -3
- package/src/agents/security.md +1 -1
- package/src/agents/skeptic.md +1 -1
- package/src/agents/spring-boot-engineer.md +1 -1
- package/src/agents/spring-reviewer.md +1 -1
- package/src/agents/spring-security.md +1 -1
- package/src/agents/steward.md +1 -1
- package/src/agents/tester.md +4 -2
- package/src/agents/user-advocate.md +1 -1
- package/src/agents/visionary.md +1 -1
- package/src/memory/README.md +12 -2
- package/src/modes/foreman.md +23 -10
- package/src/skill-descriptions.json +63 -0
- package/src/skills/_self-improvement.md +42 -26
- package/src/skills/_template.md +3 -1
- package/src/skills/brainstorm.md +35 -22
- package/src/skills/daydream/VENDOR.md +6 -0
- package/src/skills/diagram-design/VENDOR.md +4 -0
- package/src/skills/explain-changes/VENDOR.md +5 -1
- package/src/skills/parallel-agents.md +11 -0
- package/src/skills/pipeline.md +3 -3
- package/src/skills/plan.md +5 -4
- package/src/skills/react-view-transitions/VENDOR.md +7 -1
- package/src/skills/release.md +7 -2
- package/src/skills/rule/approve.md +2 -1
- package/src/skills/skill-forge.md +5 -3
- package/src/skills/token-report/VENDOR.md +5 -1
- package/src/upstreams.json +2 -2
- package/themes/README.md +3 -1
- package/web/dist/assets/{ActiveLoops-BJJN3P-V.js → ActiveLoops-DOJCPPPc.js} +1 -1
- package/web/dist/assets/{Activity-D2kOc3yi.js → Activity-LKsDzsnK.js} +1 -1
- package/web/dist/assets/{ActivityDetail-By3xOr21.js → ActivityDetail-DhwTfPm6.js} +1 -1
- package/web/dist/assets/{Bonsai-CBWDTBA4.js → Bonsai-CePMLrpr.js} +1 -1
- package/web/dist/assets/{CopyButton-BVbpriMB.js → CopyButton-CuoaJ6k7.js} +1 -1
- package/web/dist/assets/{Dashboard-CIJLPHM9.js → Dashboard-D1VKuvLe.js} +2 -2
- package/web/dist/assets/{Docs-CiRRIELs.js → Docs-CUrHJKaU.js} +1 -1
- package/web/dist/assets/{Factories-DhyK0O8d.js → Factories-Ci1XfmSy.js} +1 -1
- package/web/dist/assets/{GreenhouseView-DW3PgTPy.js → GreenhouseView-CNfH2lPK.js} +1 -1
- package/web/dist/assets/Installs-ZHQZM1iS.js +3 -0
- package/web/dist/assets/{JournalView-O65qEWfp.js → JournalView-CMsWahkS.js} +1 -1
- package/web/dist/assets/{Kits-C5U-yT6Z.js → Kits-CkliyK0n.js} +1 -1
- package/web/dist/assets/{Laws-CuTw_XNf.js → Laws-hh4O3HZ4.js} +1 -1
- package/web/dist/assets/{LibRows-D6-CVa3K.js → LibRows-Brv0Hmkr.js} +1 -1
- package/web/dist/assets/{Library-CzPlerd6.js → Library-BYmiLjJr.js} +1 -1
- package/web/dist/assets/{Loops-CqNF_-nS.js → Loops-ytm-xJ68.js} +1 -1
- package/web/dist/assets/{OperatorHudView-BNr8K5qj.js → OperatorHudView-KaqCx_HP.js} +1 -1
- package/web/dist/assets/{Personal-DeDb9e8O.js → Personal-CmcnRKYE.js} +1 -1
- package/web/dist/assets/{Settings-B8MPN_AD.js → Settings-tUrpdOfq.js} +1 -1
- package/web/dist/assets/{Tabs-DJzAez4h.js → Tabs-CD7etcGD.js} +1 -1
- package/web/dist/assets/api-CZ-x0iWG.js +1 -0
- package/web/dist/assets/{controls-D4wmg_pl.js → controls-CK7qHA8H.js} +1 -1
- package/web/dist/assets/{index-CRWqKxfY.css → index-Ba_Kg3Af.css} +1 -1
- package/web/dist/assets/{index-BL3P-9Rg.js → index-COKbhFNo.js} +3 -3
- package/web/dist/index.html +3 -3
- package/web/dist/assets/Installs-B6nlo-Ly.js +0 -3
- package/web/dist/assets/api-DLDVY3K-.js +0 -1
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE AGENT OUTCOME LEDGER — did a spec refinement make an agent better? One line per finished
|
|
3
|
+
* sub-agent, appended to `<install>/notebook/agent-runs.jsonl` beside `usage.jsonl`:
|
|
4
|
+
* `{"ts":"2026-11-14","agent":"developer","spec":"56510da85fb8","done":"ended","blocks":0,
|
|
5
|
+
* "tools":42,"refused":1,"feedback":0,"report":true}`. `spec` is a short hash of the agent's
|
|
6
|
+
* rendered spec, so the runs before and after a spec edit fall into two rows of
|
|
7
|
+
* `geneseed catalog agents --scores` (js/inspect/agent-scores.mjs).
|
|
8
|
+
*
|
|
9
|
+
* MECHANICAL ONLY (user decision 2026-11-14, "v1 mechanical only"). Every field is a fact the hook
|
|
10
|
+
* reads off the transcript, the install or the done gate's own state, never a score the agent gives
|
|
11
|
+
* itself, and nothing waits on a model remembering a step: that is what kept the spec-feedback loop
|
|
12
|
+
* empty until the hook captured it (./spec-feedback.mjs).
|
|
13
|
+
*
|
|
14
|
+
* WHAT `done` CAN SAY. On SubagentStop, `doneGate` (./hooks-done.mjs) returns 'block' or null, and
|
|
15
|
+
* a block returns before this runs, so a line is written only for a stop that ended the turn.
|
|
16
|
+
* Pass, advisory, cap reached and a skipped gate all return null, so they cannot be told apart
|
|
17
|
+
* here: `done` is "ended" (the gate ran over a transcript and let the turn end), "not-judged" (the
|
|
18
|
+
* gate ran with no transcript to read, or on Bob) or null (the gate did not run: switched off, or a
|
|
19
|
+
* manual `--file` run). `blocks` is how many times the gate blocked this turn before it ended, read
|
|
20
|
+
* from the cap state the gate itself wrote (`blocksOf`). A richer verdict needs a richer `doneGate`
|
|
21
|
+
* return, which is that file's change to make.
|
|
22
|
+
*
|
|
23
|
+
* The same privacy rules as `usage.jsonl` (./usage.mjs): counts only, the day not the instant,
|
|
24
|
+
* never a prompt, an argument or a path. Off when `GENESEED_NO_USAGE` is set or `.usage-off` exists,
|
|
25
|
+
* and only when `<install>/notebook` exists (never created here).
|
|
26
|
+
*
|
|
27
|
+
* ON THE HOOK PATH: builtins and sibling hook modules only, no spawn, nothing printed, and every
|
|
28
|
+
* error swallowed. Parallel sub-agents end together; each line is one `appendFileSync` of well
|
|
29
|
+
* under a page, as `usage.jsonl` is written, so each lands whole without a lock.
|
|
30
|
+
*/
|
|
31
|
+
import { createHash } from 'node:crypto';
|
|
32
|
+
import { appendFileSync, existsSync, readFileSync, statSync } from 'node:fs';
|
|
33
|
+
import path from 'node:path';
|
|
34
|
+
import { GLOBAL_MANIFEST } from './hosts.mjs';
|
|
35
|
+
import { SECRET_RE, splitLines } from './hooks-prims.mjs';
|
|
36
|
+
import { specFeedbackOf } from './spec-feedback.mjs';
|
|
37
|
+
import { capFile, isPrompt } from './hooks-done.mjs';
|
|
38
|
+
import { RUNS_LEDGER, USAGE_OFF } from './usage.mjs';
|
|
39
|
+
|
|
40
|
+
export { RUNS_LEDGER };
|
|
41
|
+
|
|
42
|
+
// ---- agent-runs twin: BEGIN — adapters/opencode/plugins/geneseed-learn.js carries everything down
|
|
43
|
+
// to the END marker verbatim, with `export ` dropped (`node tests/twins.mjs --write` after a change).
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* A refused tool call: the result text a host or a gate gives a call it did not run. Only the
|
|
47
|
+
* result's FIRST line is read, and every marker is anchored at its start (a host prefix of at most
|
|
48
|
+
* 80 characters allowed for Geneseed's own words): a red test or a search that QUOTES a gate's text
|
|
49
|
+
* further down its output is an error, not a refusal. One row each, with where its text comes from:
|
|
50
|
+
* - Geneseed's own refusal (`gateText` mode `refused`, js/hosts/hooks-prims.mjs), and the text
|
|
51
|
+
* said when that text fails (`GATE_UNSAID`), behind a host's prefix ("PreToolUse:Bash hook …").
|
|
52
|
+
* - The OpenCode guard: V1 throws `[geneseed-guard] blocked: …`; V2 renames the call, and core
|
|
53
|
+
* answers `No tool named "BLOCKED, not a missing tool: …"` (geneseed-guard.js, seen on 2.2.6).
|
|
54
|
+
* - Claude Code's auto-mode classifier, seen live 2026-11-14: "Permission for this action was
|
|
55
|
+
* denied by the Claude Code auto mode classifier."
|
|
56
|
+
* - Claude Code's worktree isolation, seen live 2026-11-14: "This agent is isolated in the
|
|
57
|
+
* worktree …, but this command … Refusing to run it — …".
|
|
58
|
+
* - Claude Code's permission rule deny and a user's "no" to an ask: UNVERIFIED wording.
|
|
59
|
+
*/
|
|
60
|
+
export const REFUSAL_MARKERS = [
|
|
61
|
+
/^.{0,80}?Tell the user this, word for word:/,
|
|
62
|
+
/^.{0,80}?Geneseed could not describe this call\./,
|
|
63
|
+
/^\[geneseed-guard\] blocked:/,
|
|
64
|
+
/^No tool named "BLOCKED, not a missing tool:/,
|
|
65
|
+
/^Permission for this action was denied\b/,
|
|
66
|
+
/^This agent is isolated in the worktree .{1,600}? Refusing to run it\b/,
|
|
67
|
+
/^Permission to use \S.{0,300}? has been denied\b/,
|
|
68
|
+
/^The user doesn't want to (?:proceed with|take) this/,
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* True when the first line of `text` (a tool result) says the call was refused. Each marker is
|
|
73
|
+
* anchored with `^` (no `m` flag) and its `.` never crosses a line break, so a marker can only
|
|
74
|
+
* match on the first line.
|
|
75
|
+
*/
|
|
76
|
+
export function isRefusal(text) {
|
|
77
|
+
const t = String(text ?? '').trimStart();
|
|
78
|
+
return REFUSAL_MARKERS.some((re) => re.test(t));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The short hash of a rendered spec: sha256 of its text with line endings folded to LF, 12 hex. */
|
|
82
|
+
export function specHashOf(text) {
|
|
83
|
+
return createHash('sha256').update(String(text).replace(/\r\n?/g, '\n'), 'utf8').digest('hex').slice(0, 12);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The ledger line, field order fixed. `ts` is the UTC day, as `usage.jsonl` stamps it. */
|
|
87
|
+
export function agentRunLine(run, now = new Date()) {
|
|
88
|
+
return `${JSON.stringify({
|
|
89
|
+
ts: now.toISOString().slice(0, 10), agent: run.agent, spec: run.spec ?? null, done: run.done ?? null,
|
|
90
|
+
blocks: run.blocks ?? null, tools: run.tools ?? null, refused: run.refused ?? null,
|
|
91
|
+
feedback: run.feedback ?? 0, report: Boolean(run.report),
|
|
92
|
+
})}\n`;
|
|
93
|
+
}
|
|
94
|
+
// ---- agent-runs twin: END
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* `<install>/agents/<agent>.md`'s hash when Geneseed ships it there (its manifest's `owned` names
|
|
98
|
+
* it), else null: general-purpose, Explore and a user's own agent have no rendered spec to compare.
|
|
99
|
+
*/
|
|
100
|
+
export function specOf(install, agent) {
|
|
101
|
+
try {
|
|
102
|
+
const owned = JSON.parse(readFileSync(path.join(install, GLOBAL_MANIFEST), 'utf8')).owned;
|
|
103
|
+
const rel = `agents/${agent}.md`;
|
|
104
|
+
if (!Array.isArray(owned) || !owned.includes(rel)) return null;
|
|
105
|
+
return specHashOf(readFileSync(path.join(install, 'agents', `${agent}.md`), 'utf8'));
|
|
106
|
+
} catch { return null; }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** A tool result's text: a string, or its text blocks joined. */
|
|
110
|
+
function resultText(b) {
|
|
111
|
+
if (typeof b.content === 'string') return b.content;
|
|
112
|
+
if (!Array.isArray(b.content)) return '';
|
|
113
|
+
return b.content.filter((x) => x && x.type === 'text' && typeof x.text === 'string').map((x) => x.text).join('\n');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* `{ tools, refused, opening }` for the current turn of a sub-agent transcript's TEXT, or null when
|
|
118
|
+
* `whole` is false and the text holds no prompt (the tail reader then reads further back).
|
|
119
|
+
* `opening` is the gate's key for the turn (`turnOf`): the prompt line's `uuid`, else its content.
|
|
120
|
+
*/
|
|
121
|
+
export function runCounts(raw, whole = true) {
|
|
122
|
+
const entries = [];
|
|
123
|
+
for (const line of splitLines(raw)) {
|
|
124
|
+
if (!line.trim()) continue;
|
|
125
|
+
try { entries.push(JSON.parse(line)); } catch { /* a torn line is no call */ }
|
|
126
|
+
}
|
|
127
|
+
let start = -1;
|
|
128
|
+
// The gate's own rule (./hooks-done.mjs `isPrompt`, sidechain mode). A resumed sub-agent appends
|
|
129
|
+
// its next turn to the same file, so the counts are the CURRENT turn's, as the gate judges it.
|
|
130
|
+
for (let i = entries.length - 1; i >= 0; i -= 1) if (entries[i] && isPrompt(entries[i], true)) { start = i + 1; break; }
|
|
131
|
+
if (start === -1) {
|
|
132
|
+
if (!whole) return null;
|
|
133
|
+
start = 0;
|
|
134
|
+
}
|
|
135
|
+
const first = entries[start - 1];
|
|
136
|
+
const opening = !first ? '' : typeof first.uuid === 'string' ? first.uuid
|
|
137
|
+
: JSON.stringify(first.message && first.message.content).slice(0, 300);
|
|
138
|
+
let tools = 0;
|
|
139
|
+
let refused = 0;
|
|
140
|
+
for (const obj of entries.slice(start)) {
|
|
141
|
+
const content = obj.message && obj.message.content;
|
|
142
|
+
if (!Array.isArray(content)) continue;
|
|
143
|
+
for (const b of content) {
|
|
144
|
+
if (!b || typeof b !== 'object') continue;
|
|
145
|
+
if (b.type === 'tool_use') tools += 1;
|
|
146
|
+
else if (b.type === 'tool_result' && b.is_error === true && isRefusal(resultText(b))) refused += 1;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return { tools, refused, opening };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* How many times the done gate blocked this sub-agent's turn: `total` in the cap state it saved
|
|
154
|
+
* (./hooks-done.mjs `capFile`), when that state is this turn's (same `opening`); 0 with no state,
|
|
155
|
+
* or another turn's.
|
|
156
|
+
*/
|
|
157
|
+
export function blocksOf(install, meta, opening) {
|
|
158
|
+
const file = install ? capFile(install, { ...meta, hook_event_name: 'SubagentStop' }) : null;
|
|
159
|
+
if (!file) return 0;
|
|
160
|
+
try {
|
|
161
|
+
const state = JSON.parse(readFileSync(file, 'utf8'));
|
|
162
|
+
if (!state || state.opening !== opening) return 0;
|
|
163
|
+
return Number.isInteger(state.total) ? state.total : Number.isInteger(state.blocks) ? state.blocks : 0;
|
|
164
|
+
} catch { return 0; }
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** True when the ledger is switched off for `install`, or has nowhere to go. */
|
|
168
|
+
function ledgerOff(install) {
|
|
169
|
+
if (!install || process.env.GENESEED_NO_USAGE) return true;
|
|
170
|
+
if (existsSync(path.join(install, USAGE_OFF))) return true;
|
|
171
|
+
try { return !statSync(path.join(install, 'notebook')).isDirectory(); } catch { return true; }
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* The SubagentStop write: one line for `agent`'s finished turn. `done` is `cmdLearn`'s reading of
|
|
176
|
+
* the gate (see the header), `report` the sub-agent's final report text (`subagentReport`), `read`
|
|
177
|
+
* the Stop's shared transcript reader. Returns the line written, or null. Never throws.
|
|
178
|
+
* @param {string | null} install
|
|
179
|
+
* @param {string | null} agent
|
|
180
|
+
* @param {Record<string, any>} meta
|
|
181
|
+
* @param {{ done?: string | null, report?: string, read?: Function | null }} [opts]
|
|
182
|
+
* @param {Date} [now]
|
|
183
|
+
*/
|
|
184
|
+
export function recordAgentRun(install, agent, meta, { done = null, report = '', read } = {}, now = new Date()) {
|
|
185
|
+
try {
|
|
186
|
+
if (!agent || ledgerOff(install)) return null;
|
|
187
|
+
const tp = typeof meta.agent_transcript_path === 'string' && meta.agent_transcript_path ? meta.agent_transcript_path : null;
|
|
188
|
+
let counts = null;
|
|
189
|
+
if (tp && read) {
|
|
190
|
+
try { counts = read(tp, (raw, whole) => runCounts(raw, whole)); } catch { counts = null; }
|
|
191
|
+
}
|
|
192
|
+
const line = agentRunLine({
|
|
193
|
+
agent, spec: specOf(install, agent), done,
|
|
194
|
+
blocks: done === 'ended' && counts ? blocksOf(install, meta, counts.opening) : null,
|
|
195
|
+
tools: counts ? counts.tools : null, refused: counts ? counts.refused : null,
|
|
196
|
+
// The agent's own lines: a `[skill:…]` line it relays is about a skill, not its spec.
|
|
197
|
+
feedback: specFeedbackOf(report, SECRET_RE).filter((f) => !f.skill).length, report: Boolean(String(report || '').trim()),
|
|
198
|
+
}, now);
|
|
199
|
+
const file = path.join(install, RUNS_LEDGER);
|
|
200
|
+
// One line in one `appendFileSync` (O_APPEND), as usage.jsonl is written: parallel stops each
|
|
201
|
+
// land a whole line, so there is no lock to wait on.
|
|
202
|
+
appendFileSync(file, line);
|
|
203
|
+
return line;
|
|
204
|
+
} catch { return null; }
|
|
205
|
+
}
|
package/js/hosts/done-checks.mjs
CHANGED
|
@@ -82,7 +82,9 @@ export const INFERRED_FROM = ['package.json', ...MANIFEST_CHECKS.map(([f]) => /*
|
|
|
82
82
|
* - the git root's manifests only — a monorepo's subprojects (`pnpm -r test`,
|
|
83
83
|
* `./gradlew :app:test`, `mvn -pl core test`) are neither inferred nor matched;
|
|
84
84
|
* - a sibling script (`npm run test:unit`) or a runner called directly (`npx vitest`);
|
|
85
|
-
* - a prefix before the command (`CI=1 npm test`, `mvn -q test`): forms match verbatim
|
|
85
|
+
* - a prefix before the command (`CI=1 npm test`, `mvn -q test`): forms match verbatim, save
|
|
86
|
+
* for `npm --prefix <project>`, `git -C <project>` and `--test-concurrency N`, which
|
|
87
|
+
* `normalizeRun` (`./hooks-done.mjs`) takes off both sides.
|
|
86
88
|
*/
|
|
87
89
|
export function inferDoneChecks(root) {
|
|
88
90
|
const has = (f) => existsSync(path.join(root, f));
|
package/js/hosts/hooks-done.mjs
CHANGED
|
@@ -48,7 +48,8 @@
|
|
|
48
48
|
* whose result is not an error (a denied write changed nothing);
|
|
49
49
|
* - a pass is a Bash/PowerShell call whose command contains one of the check's forms UNPIPED (a pipe
|
|
50
50
|
* takes the exit code of its last stage: `npm test | tail` exits 0 on a red suite), not MASKED
|
|
51
|
-
* after it (`|| true`, `; exit 0` — see `runsUnpiped`),
|
|
51
|
+
* after it (`|| true`, `; exit 0` — see `runsUnpiped`), compared after `normalizeRun` takes
|
|
52
|
+
* `npm --prefix <project>`, `git -C <project>` and `--test-concurrency N` off both sides, and whose
|
|
52
53
|
* result is not `is_error` — every non-zero exit, denial and timeout carries it (checked on
|
|
53
54
|
* 14 000+ real Claude Code results, 2026-10-17);
|
|
54
55
|
* - a BACKGROUND run (`run_in_background: true`, or moved there after its foreground timeout)
|
|
@@ -81,7 +82,7 @@
|
|
|
81
82
|
* stderr line says the total ceiling was reached. The count lives in a per-session file under the install; without one,
|
|
82
83
|
* `stop_hook_active` (true when this Stop follows a block) ends the turn at once.
|
|
83
84
|
*/
|
|
84
|
-
import { mkdirSync, readdirSync, readFileSync, statSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
85
|
+
import { mkdirSync, readdirSync, readFileSync, realpathSync, statSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
85
86
|
import path from 'node:path';
|
|
86
87
|
import { printOut as out, printErr as err } from '../lib/fs.mjs';
|
|
87
88
|
import { within } from '../lib/paths.mjs';
|
|
@@ -149,19 +150,87 @@ export function runsUnpiped(command, line) {
|
|
|
149
150
|
return false;
|
|
150
151
|
}
|
|
151
152
|
|
|
153
|
+
/**
|
|
154
|
+
* `command` with the flags that name WHERE a check runs, or how many workers run it, taken out,
|
|
155
|
+
* so a check line and the command that proves it compare on what is tested (user decision
|
|
156
|
+
* 2026-11-14: workers in worktrees ran `npm --prefix <worktree> run lint` and the suite at the
|
|
157
|
+
* default concurrency, all green, and the gate blocked them). Applied to both sides before the
|
|
158
|
+
* prefix match (`groupPasses`). Removed, and nothing else:
|
|
159
|
+
* - `--prefix <dir>` / `--prefix=<dir>` in a segment opened by `npm`, before any `--`;
|
|
160
|
+
* - `-C <dir>` right after `git` (its global options only, so `make -C` and `tar -C` stay);
|
|
161
|
+
* - `--test-concurrency=N` / `--test-concurrency N` (N digits) in a `node` segment holding `--test`.
|
|
162
|
+
* A `<dir>` is removed only when `sameProject(dir)` says it names the judged project (`projectDir`):
|
|
163
|
+
* a check run in another project still counts as not run. Separators (`&&`, `||`, `|`, `;`,
|
|
164
|
+
* newlines) are kept as they stand, so the piping and masking rules of `runsUnpiped` read the
|
|
165
|
+
* same line. shortcut: a segment is tokenized on spaces with quoted runs kept whole; a segment
|
|
166
|
+
* left unchanged keeps its text byte for byte. Pure: the plugin twin is a copy.
|
|
167
|
+
*/
|
|
168
|
+
export function normalizeRun(command, sameProject) {
|
|
169
|
+
const cmd = String(command).replace(/[ \t]+/g, ' ');
|
|
170
|
+
return cmd.split(/(&&|\|\||[|;\n])/).map((seg, k) => {
|
|
171
|
+
if (k % 2) return seg;
|
|
172
|
+
const toks = seg.trim().match(/(?:"[^"]*"|'[^']*'|[^ "']|["'])+/g);
|
|
173
|
+
if (!toks) return seg;
|
|
174
|
+
const [tool] = toks;
|
|
175
|
+
const test = tool === 'node' && toks.includes('--test');
|
|
176
|
+
const out = [tool];
|
|
177
|
+
let opts = true;
|
|
178
|
+
for (let i = 1; i < toks.length; i += 1) {
|
|
179
|
+
const t = toks[i];
|
|
180
|
+
if (t === '--') opts = false;
|
|
181
|
+
if (opts && tool === 'npm') {
|
|
182
|
+
if (t === '--prefix' && i + 1 < toks.length && sameProject(toks[i + 1])) { i += 1; continue; }
|
|
183
|
+
if (t.startsWith('--prefix=') && sameProject(t.slice(9))) continue;
|
|
184
|
+
}
|
|
185
|
+
if (tool === 'git' && out.length === 1 && t === '-C' && i + 1 < toks.length && sameProject(toks[i + 1])) { i += 1; continue; }
|
|
186
|
+
if (opts && test) {
|
|
187
|
+
if (/^--test-concurrency=\d+$/.test(t)) continue;
|
|
188
|
+
if (t === '--test-concurrency' && /^\d+$/.test(toks[i + 1] ?? '')) { i += 1; continue; }
|
|
189
|
+
}
|
|
190
|
+
out.push(t);
|
|
191
|
+
}
|
|
192
|
+
if (out.length === toks.length) return seg;
|
|
193
|
+
return `${seg.startsWith(' ') ? ' ' : ''}${out.join(' ')}${seg.endsWith(' ') ? ' ' : ''}`;
|
|
194
|
+
}).join('');
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* The `sameProject` of `normalizeRun` for the project at `root`, a dir resolved against `cwd`:
|
|
199
|
+
* true only when it is the judged root ITSELF (real paths, so a junction or symlink to it counts;
|
|
200
|
+
* case-blind on Windows). The root may be a linked worktree. A sibling worktree or the main checkout
|
|
201
|
+
* of the same repository is false (user ruling 2026-11-14): a run there never saw this tree's
|
|
202
|
+
* edits. So are a subfolder, another repository, and a dir that does not exist. shortcut: a Git
|
|
203
|
+
* Bash path (`/c/Users/...`) does not resolve to a drive path here, so it reads as another
|
|
204
|
+
* project — the closed direction.
|
|
205
|
+
*/
|
|
206
|
+
export function projectDir(root, cwd) {
|
|
207
|
+
const key = (p) => (process.platform === 'win32' ? p.toLowerCase() : p);
|
|
208
|
+
let me;
|
|
209
|
+
try { me = key(realpathSync(root)); } catch { return () => false; }
|
|
210
|
+
return (dir) => {
|
|
211
|
+
const bare = /^(["'])(.*)\1$/.exec(dir)?.[2] ?? dir;
|
|
212
|
+
if (!bare) return false;
|
|
213
|
+
try { return key(realpathSync(path.resolve(cwd, bare))) === me; } catch { return false; }
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
152
217
|
/**
|
|
153
218
|
* True when `command` proves the check group `g`: one of its forms runs unpiped and unmasked
|
|
154
219
|
* (`runsUnpiped`), and — when the group names `refuse`, the flags that skip the tests
|
|
155
220
|
* (`mvn install -DskipTests`, `gradle build -x test`, `cargo test --no-run`) — some unpiped
|
|
156
|
-
* segment opening with a form carries none of them.
|
|
157
|
-
*
|
|
221
|
+
* segment opening with a form carries none of them. Both sides go through `normalizeRun` first;
|
|
222
|
+
* without `sameProject` no `--prefix`/`-C` dir counts, so only the concurrency flag goes.
|
|
223
|
+
* shortcut: segments split on `&&`, `||`, `;` and newlines without reading quotes; a quoted
|
|
224
|
+
* separator only makes a refusal more likely.
|
|
158
225
|
*/
|
|
159
|
-
export function groupPasses(command, g) {
|
|
160
|
-
|
|
226
|
+
export function groupPasses(command, g, sameProject = () => false) {
|
|
227
|
+
const run = normalizeRun(command, sameProject);
|
|
228
|
+
const forms = g.forms.map((f) => normalizeRun(f, sameProject));
|
|
229
|
+
if (!forms.some((f) => runsUnpiped(run, f))) return false;
|
|
161
230
|
if (!g.refuse) return true;
|
|
162
|
-
return
|
|
231
|
+
return run.split(/&&|\|\||;|\n/).map((s) => s.trim())
|
|
163
232
|
.some((s) => !s.includes('|') && !g.refuse.test(s)
|
|
164
|
-
&&
|
|
233
|
+
&& forms.some((f) => s === f || s.startsWith(`${f} `)));
|
|
165
234
|
}
|
|
166
235
|
|
|
167
236
|
const NOTE_OPEN = '<task-notification>';
|
|
@@ -222,8 +291,11 @@ const BACKGROUNDED = /^(?:Command running in background with ID: |Command was mo
|
|
|
222
291
|
const resultText = (b) => (typeof b.content === 'string' ? b.content
|
|
223
292
|
: Array.isArray(b.content) && b.content[0] && typeof b.content[0].text === 'string' ? b.content[0].text : '');
|
|
224
293
|
|
|
225
|
-
/**
|
|
226
|
-
|
|
294
|
+
/**
|
|
295
|
+
* A user line that opens a turn: the user typed it, it is not a tool result, a meta note or a task notification.
|
|
296
|
+
* Exported for ./agent-runs.mjs, which counts the same turn the gate judges.
|
|
297
|
+
*/
|
|
298
|
+
export function isPrompt(obj, sidechain = false) {
|
|
227
299
|
if (obj.type !== 'user' || obj.isMeta || (obj.isSidechain && !sidechain)) return false;
|
|
228
300
|
if (notificationText(obj)) return false;
|
|
229
301
|
const c = obj.message && obj.message.content;
|
|
@@ -367,13 +439,14 @@ function missingChecks({ calls, results, background, finished }, checks, root, c
|
|
|
367
439
|
calls.forEach((c, i) => { if (editTarget(c, results, root, cwd)) lastEdit = i; });
|
|
368
440
|
if (lastEdit === -1) return [];
|
|
369
441
|
const passed = new Set();
|
|
442
|
+
const same = projectDir(root, cwd);
|
|
370
443
|
calls.slice(lastEdit + 1).forEach((c) => {
|
|
371
444
|
const command = SHELL_TOOLS.has(c.name) && c.input && c.input.command;
|
|
372
445
|
// A call with no result yet (the host has not flushed it) is not a pass.
|
|
373
446
|
if (typeof command !== 'string' || results.get(c.id) !== false) return;
|
|
374
447
|
// A background launch's result only says it started: its notification is the verdict.
|
|
375
448
|
if (background.has(c.id) && finished.get(c.id) !== true) return;
|
|
376
|
-
for (const g of groups) if (groupPasses(command, g)) passed.add(g.label);
|
|
449
|
+
for (const g of groups) if (groupPasses(command, g, same)) passed.add(g.label);
|
|
377
450
|
});
|
|
378
451
|
return groups.map((g) => g.label).filter((l) => !passed.has(l));
|
|
379
452
|
}
|
|
@@ -438,15 +511,16 @@ export const turnCeilingReached = (state, opening) =>
|
|
|
438
511
|
* the last background run of one of its forms, launched with no completion seen, or completed with
|
|
439
512
|
* anything but exit 0. A check never run in the background has no entry.
|
|
440
513
|
*/
|
|
441
|
-
function backgroundOwed({ calls, results, background, finished }, checks, owedLabels, lastEdit) {
|
|
514
|
+
function backgroundOwed({ calls, results, background, finished }, checks, owedLabels, lastEdit, root, cwd) {
|
|
442
515
|
const states = new Map();
|
|
516
|
+
const same = projectDir(root, cwd);
|
|
443
517
|
let after = lastEdit === null;
|
|
444
518
|
for (const c of calls) {
|
|
445
519
|
if (!after) { after = c.id === lastEdit; continue; }
|
|
446
520
|
const command = SHELL_TOOLS.has(c.name) && c.input && c.input.command;
|
|
447
521
|
if (typeof command !== 'string' || results.get(c.id) !== false || !background.has(c.id)) continue;
|
|
448
522
|
for (const g of checks) {
|
|
449
|
-
if (!owedLabels.has(g.label) || !groupPasses(command, g)) continue;
|
|
523
|
+
if (!owedLabels.has(g.label) || !groupPasses(command, g, same)) continue;
|
|
450
524
|
states.set(g.label, finished.has(c.id) ? (finished.get(c.id) ? 'passed' : 'failed') : 'pending');
|
|
451
525
|
}
|
|
452
526
|
}
|
|
@@ -457,9 +531,10 @@ function backgroundOwed({ calls, results, background, finished }, checks, owedLa
|
|
|
457
531
|
/**
|
|
458
532
|
* The cap's state file, one per session (and sub-agent), under the install's notebook — the
|
|
459
533
|
* store-watch baseline pattern (`./store-watch.mjs`). Read and written only on a Stop with owed
|
|
460
|
-
* checks, so an allowed Stop costs nothing here. Unreadable reads as none.
|
|
534
|
+
* checks, so an allowed Stop costs nothing here. Unreadable reads as none. Exported for
|
|
535
|
+
* ./agent-runs.mjs, which reads a finished sub-agent's block count back from it.
|
|
461
536
|
*/
|
|
462
|
-
function capFile(install, meta) {
|
|
537
|
+
export function capFile(install, meta) {
|
|
463
538
|
const key = [meta.session_id, meta.hook_event_name === 'SubagentStop' ? meta.agent_id : null]
|
|
464
539
|
.filter((k) => typeof k === 'string' && k).join('~');
|
|
465
540
|
return key ? path.join(install, CAP_DIR, `${key.replace(/[^\w.~-]/g, '_').slice(0, 160)}.json`) : null;
|
|
@@ -571,7 +646,7 @@ export function doneGate(meta, args, install, read = tailReader()) {
|
|
|
571
646
|
const active = meta.stop_hook_active === true;
|
|
572
647
|
const capPath = install ? capFile(install, meta) : null;
|
|
573
648
|
// The owed checks whose proof is a background run still pending, or one that reported a failure.
|
|
574
|
-
const bg = owed.flatMap((r) => [...backgroundOwed(turn, r.checks, new Set(r.missing), lastEditId(turn, [r.root], at))]
|
|
649
|
+
const bg = owed.flatMap((r) => [...backgroundOwed(turn, r.checks, new Set(r.missing), lastEditId(turn, [r.root], at), r.root, at)]
|
|
575
650
|
.map(([l, st]) => [`${tag(r)}${l}`, st]));
|
|
576
651
|
const verdict = bg.map(([l, st]) => `${l}=${st}`).sort().join('\n');
|
|
577
652
|
// Without an install or a session id there is nowhere to count: one block per turn, as before.
|
package/js/hosts/hooks-learn.mjs
CHANGED
|
@@ -19,6 +19,9 @@ import { recordOwnWrites, storeReport } from './store-watch.mjs';
|
|
|
19
19
|
import {
|
|
20
20
|
existingSlugs, readFacts, writeMemories, consolidateMemory, appendAgentLesson,
|
|
21
21
|
} from './memory-files.mjs';
|
|
22
|
+
import { captureSpecFeedback, projectNotesDir, subagentReport, turnReply } from './spec-feedback.mjs';
|
|
23
|
+
import { gitRootOf } from './gitref.mjs';
|
|
24
|
+
import { recordAgentRun } from './agent-runs.mjs';
|
|
22
25
|
|
|
23
26
|
const ROOT = path.resolve(import.meta.dirname, '../..');
|
|
24
27
|
|
|
@@ -321,6 +324,71 @@ function sharedStoreFor(install, args) {
|
|
|
321
324
|
} catch { return args.memory; }
|
|
322
325
|
}
|
|
323
326
|
|
|
327
|
+
/**
|
|
328
|
+
* The two notes roots a line can go to (./spec-feedback.mjs `feedbackTargets`), as the render
|
|
329
|
+
* names them: MACHINE is the tier's `notes/` (`{{PATH_NOTES}}`) for every host and install kind;
|
|
330
|
+
* PROJECT is `<project>/notebook` (`{{PATH_PROJECT_NOTES}}`), one folder for every host.
|
|
331
|
+
*
|
|
332
|
+
* The project is the install's parent for a project install (`<repo>/.claude`, `.bob`,
|
|
333
|
+
* `.openclaude`), and for a global install the git root of the session's project
|
|
334
|
+
* (`hookProjectDir`); either way a linked worktree's main checkout, since a worktree and its notes
|
|
335
|
+
* go when it is removed. A global session outside any repo (home, a temp folder) has no project:
|
|
336
|
+
* its project lines are dropped, never sent to the machine notes, where every repo would read them.
|
|
337
|
+
*
|
|
338
|
+
* The machine notes need the tier's folder to exist; it does on any machine an emit has run on
|
|
339
|
+
* (the install registry lives there), and only `notes/<sub>/` is ever created under it, never
|
|
340
|
+
* `memory/`, whose presence is what `sharedStoreFor` reads as "the tier is seeded".
|
|
341
|
+
*/
|
|
342
|
+
export function notesRootsOf(install, host, payloadCwd) {
|
|
343
|
+
if (!install) return { machine: null, project: null };
|
|
344
|
+
let machine = null;
|
|
345
|
+
try { machine = sharedPaths().notes; } catch { /* no home directory: no tier */ }
|
|
346
|
+
let base = null;
|
|
347
|
+
try {
|
|
348
|
+
base = isGlobalInstall(host ?? null, install) ? gitRootOf(hookProjectDir(payloadCwd)) : path.dirname(install);
|
|
349
|
+
} catch { base = null; }
|
|
350
|
+
return { machine, project: projectNotesDir(base) };
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* SubagentStop: the `spec-feedback:` lines of the sub-agent's final report into the notes its next
|
|
355
|
+
* dispatch reads (./spec-feedback.mjs). Stop: the `[skill:<name>]` lines of the main session's
|
|
356
|
+
* final reply into the notes that skill reads (`agent` null). Skill lines are checked against
|
|
357
|
+
* `<install>/skills/`. No model, so `$GENESEED_LLM` does not gate it. Silent on stdout, which an
|
|
358
|
+
* advisory verdict or the change report may hold, and a failure costs only the capture.
|
|
359
|
+
*/
|
|
360
|
+
function captureFeedback(agent, report, args, install, meta) {
|
|
361
|
+
// Most replies hold no feedback line: then the two roots are never resolved (two fs walks).
|
|
362
|
+
if (!/spec-feedback/i.test(report || '')) return;
|
|
363
|
+
try {
|
|
364
|
+
const skills = install ? path.join(install, 'skills') : null;
|
|
365
|
+
const written = captureSpecFeedback(agent, report, notesRootsOf(install, args.host, meta.cwd), undefined, skills);
|
|
366
|
+
if (written.length) err(`[learn] spec-feedback -> ${written.join(', ')}\n`);
|
|
367
|
+
} catch { /* a note never fails the hook */ }
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* SubagentStop: the report's feedback lines into the notes at every stop (`subagentFeedback`, a
|
|
372
|
+
* blocked one included), then, past the done gate, the turn's line into the outcome ledger
|
|
373
|
+
* (./agent-runs.mjs, `subagentEnded`), both off ONE read of the report. `done` is what
|
|
374
|
+
* the gate can say through its return (that file's header): null when it did not run, 'not-judged'
|
|
375
|
+
* when it had no transcript to judge, else 'ended'. Unnamed agents get neither. (Bob sends no
|
|
376
|
+
* SubagentStop, so no Bob case reaches this.)
|
|
377
|
+
*/
|
|
378
|
+
function subagentFeedback(meta, args, read, install) {
|
|
379
|
+
const agent = subagentNameOf(meta);
|
|
380
|
+
if (!agent) return null;
|
|
381
|
+
let report = '';
|
|
382
|
+
try { report = subagentReport(meta, read); } catch { /* no report: nothing to capture */ }
|
|
383
|
+
captureFeedback(agent, report, args, install, meta);
|
|
384
|
+
return { agent, report };
|
|
385
|
+
}
|
|
386
|
+
function subagentEnded(meta, args, read, install, { agent, report }) {
|
|
387
|
+
const ran = !args.file && !args.noDoneGate;
|
|
388
|
+
const judged = typeof meta.agent_transcript_path === 'string' && meta.agent_transcript_path;
|
|
389
|
+
recordAgentRun(install, agent, meta, { done: !ran ? null : judged ? 'ended' : 'not-judged', report, read });
|
|
390
|
+
}
|
|
391
|
+
|
|
324
392
|
export function cmdLearn(args) {
|
|
325
393
|
// B2: stand straight down inside a model-CLI child `runLlm` just spawned (see its comment).
|
|
326
394
|
// Checked before anything else — a child never gets as far as reading its own stdin, let
|
|
@@ -377,8 +445,25 @@ export function cmdLearn(args) {
|
|
|
377
445
|
// An advisory verdict already holds stdout: nothing below may print there after it.
|
|
378
446
|
const verdict = (hookEvent === 'Stop' || hookEvent === 'SubagentStop') && !args.file && !args.noDoneGate
|
|
379
447
|
? doneGate(meta, args, install, read) : null;
|
|
448
|
+
|
|
449
|
+
// The feedback lines are kept at EVERY stop, a blocked one included, model or none: the reply a
|
|
450
|
+
// block sends back to work is the one that carries the line, and the reply that finally ends the
|
|
451
|
+
// turn ("lint and suite green") does not repeat it, so capturing only after the block lost it for
|
|
452
|
+
// good. Silent on stdout, so the verdict stays the one document there; a line seen again at the
|
|
453
|
+
// next stop adds no note. A sub-agent's lines come from its report, a skill's `[skill:<name>]`
|
|
454
|
+
// lines (it runs in the main context) from the turn's final reply.
|
|
455
|
+
const sub = hookEvent === 'SubagentStop' ? subagentFeedback(meta, args, read, install) : null;
|
|
456
|
+
if (hookEvent === 'Stop') {
|
|
457
|
+
let reply = '';
|
|
458
|
+
try { reply = turnReply(meta, read); } catch { /* no reply: nothing to capture */ }
|
|
459
|
+
if (reply) captureFeedback(null, reply, args, install, meta);
|
|
460
|
+
}
|
|
380
461
|
if (verdict === 'block') return 0;
|
|
381
462
|
|
|
463
|
+
// The sub-agent's turn is over: its outcome line is written. A blocked turn returned above, so a
|
|
464
|
+
// ledger line is one finished turn.
|
|
465
|
+
if (sub) subagentEnded(meta, args, read, install, sub);
|
|
466
|
+
|
|
382
467
|
// The change report, at the turn's real end (./store-watch.mjs). One JSON document on stdout, so an
|
|
383
468
|
// advisory already there keeps it, and Bob reads no stdout here at all: those go to stderr.
|
|
384
469
|
if (hookEvent === 'Stop' && !args.file && install) {
|
package/js/hosts/hooks-prims.mjs
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { statSync, readFileSync, readdirSync } from 'node:fs';
|
|
12
12
|
import path from 'node:path';
|
|
13
|
+
import { isatty } from 'node:tty';
|
|
13
14
|
import { comparePaths } from '../lib/paths.mjs';
|
|
14
15
|
import { readTail } from '../lib/fs.mjs';
|
|
15
16
|
|
|
@@ -546,8 +547,45 @@ export function activityOn(root) {
|
|
|
546
547
|
* The `activity` verb, wired to the events no other verb runs on (UserPromptSubmit; SessionEnd
|
|
547
548
|
* on Claude and OpenClaude; SubagentStart runs `context` since the agent loadout). It decides nothing and prints nothing: the entry's
|
|
548
549
|
* `trackActivity` records the payload after every verb alike, this one included.
|
|
550
|
+
*
|
|
551
|
+
* Its one act of its own: a prompt typed as `/<skill>` is counted (`recordSlash`, ./usage.mjs).
|
|
552
|
+
* The test before the parse is a regex over the raw stdin, so a plain prompt costs no import;
|
|
553
|
+
* only a slash prompt loads the counter and `./hosts.mjs`. It stands down where the tool counter
|
|
554
|
+
* does: an excluded folder, a model-CLI child `learn` spawned, a terminal, and beside a live
|
|
555
|
+
* project install of the same host (`globalHookStandingDown` on `activity`, the verb that
|
|
556
|
+
* install's own UserPromptSubmit runs). Skills resolve in the install's `skills/`, the host's
|
|
557
|
+
* global config dir's `skills/`, and the project's own `<marker>/skills/`. Bob: its UserPromptSubmit payload is read as Claude's
|
|
558
|
+
* (`prompt`), unverified on a live Bob. Always 0: on UserPromptSubmit exit 2 erases the prompt.
|
|
549
559
|
*/
|
|
550
|
-
|
|
560
|
+
// Leading blanks as `slashSkillOf` takes them (`^\s*`), spelled as JSON spells them: a raw blank,
|
|
561
|
+
// or an escaped `\n`, `\r`, `\t`. Narrower than that and a prompt it would count is never parsed.
|
|
562
|
+
const SLASH_PROMPT_RE = /"prompt"\s*:\s*"(?:\s|\\[nrt])*\//;
|
|
563
|
+
export async function cmdActivity(args) {
|
|
564
|
+
try {
|
|
565
|
+
if (!args || !args.root || process.env.GENESEED_NO_USAGE || process.env.GENESEED_LEARN_CHILD
|
|
566
|
+
|| isatty(0)) return 0;
|
|
567
|
+
const raw = readStdin();
|
|
568
|
+
if (!SLASH_PROMPT_RE.test(raw)) return 0;
|
|
569
|
+
const payload = JSON.parse(raw);
|
|
570
|
+
if (payload.hook_event_name && payload.hook_event_name !== 'UserPromptSubmit') return 0;
|
|
571
|
+
const [{ recordSlash }, hosts] = await Promise.all([import('./usage.mjs'), import('./hosts.mjs')]);
|
|
572
|
+
if (hosts.sovereignBypass(args.root)) return 0;
|
|
573
|
+
const projectDir = hosts.hookProjectDir(payload.cwd);
|
|
574
|
+
const row = hosts.HOSTS.find((h) => h.host === (args.host || 'claude'));
|
|
575
|
+
const skillDirs = [path.join(args.root, 'skills')];
|
|
576
|
+
if (row) {
|
|
577
|
+
// The host's global skills too: beside a project install the global hook stands down, so a
|
|
578
|
+
// skill only the global holds (the user's own, say) would otherwise be counted by neither.
|
|
579
|
+
try { skillDirs.push(path.join(row.configDir(), 'skills')); } catch { /* no resolvable global */ }
|
|
580
|
+
skillDirs.push(path.join(projectDir, row.projectMarker, 'skills'));
|
|
581
|
+
}
|
|
582
|
+
recordSlash(args.root, payload, {
|
|
583
|
+
skillDirs,
|
|
584
|
+
standingDown: () => hosts.usageStandingDown(args.root, projectDir, args.host, 'activity'),
|
|
585
|
+
});
|
|
586
|
+
} catch { /* a counter never fails a prompt */ }
|
|
587
|
+
return 0;
|
|
588
|
+
}
|
|
551
589
|
|
|
552
590
|
// The two output funnels, with Python's newline translation reproduced, are `printOut`/`printErr`
|
|
553
591
|
// in `js/lib/fs.mjs` — they moved there in P5c, beside `writeText`, which is the same rule for
|
package/js/hosts/hooks.mjs
CHANGED
|
@@ -60,7 +60,7 @@ import { markerLines } from '../lib/managed-block.mjs';
|
|
|
60
60
|
import { isDict, isTruthy, parseJson, readJsonc } from '../lib/json.mjs';
|
|
61
61
|
import {
|
|
62
62
|
GATE_LEDGER, HOSTS, carrierBlock, carrierName, globalHookStandingDown, hookProjectDir, isSharedCarrier,
|
|
63
|
-
resolvePath, sovereignBypass,
|
|
63
|
+
resolvePath, sovereignBypass, usageStandingDown,
|
|
64
64
|
} from './hosts.mjs';
|
|
65
65
|
import {
|
|
66
66
|
currentBranch, gitCommonDirOf, gitRootOf, loopLaunched, mainWorktreeOf, protectedBranches,
|
|
@@ -1611,8 +1611,11 @@ function toolGate(args) {
|
|
|
1611
1611
|
if (sovereignBypass(args.root)) return 0;
|
|
1612
1612
|
const payload = normaliseBobPayload(readPayload());
|
|
1613
1613
|
// Count a skill or subagent call before judging it: Bob runs this verb on every tool and
|
|
1614
|
-
// Claude/OpenClaude route their `Skill|Agent|Task` matcher here (js/hosts/usage.mjs).
|
|
1615
|
-
|
|
1614
|
+
// Claude/OpenClaude route their `Skill|Agent|Task` matcher here (js/hosts/usage.mjs). Only the
|
|
1615
|
+
// COUNT stands down beside a live project install, whose own tool-gate counts the call; the
|
|
1616
|
+
// gates below still run once per install, as before.
|
|
1617
|
+
recordUse(args.root, payload, undefined, () => usageStandingDown(args.root,
|
|
1618
|
+
hookProjectDir(payload && payload.cwd), args.host, 'tool-gate'));
|
|
1616
1619
|
const ti = (payload && payload.tool_input) || {};
|
|
1617
1620
|
return typeof ti.command === 'string' ? gitDecide(args, payload) : ruleDecide(args, payload);
|
|
1618
1621
|
}
|
package/js/hosts/hosts.mjs
CHANGED
|
@@ -197,6 +197,16 @@ export function globalHookStandingDown(hookRoot, projectDir, host, verb) {
|
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
+
/**
|
|
201
|
+
* The usage counter's stand-down (js/hosts/usage.mjs): the same test, for the COUNT only. Not a
|
|
202
|
+
* `globalHookStandingDown` call with a literal verb, so `STAND_DOWN_VERBS`
|
|
203
|
+
* (js/maintain/profile-scope.mjs) stays the verbs whose whole hook stands down: `tool-gate` still
|
|
204
|
+
* judges every call on Bob beside a project install, and `activity` still records the turn.
|
|
205
|
+
*/
|
|
206
|
+
export function usageStandingDown(hookRoot, projectDir, host, verb) {
|
|
207
|
+
return globalHookStandingDown(hookRoot, projectDir, host, verb);
|
|
208
|
+
}
|
|
209
|
+
|
|
200
210
|
// The marker lives in the shim's FILENAME, not its directory: GENESEED_HOME relocates the dir,
|
|
201
211
|
// and a relocated install's hooks must stay recognisable to `GENESEED_HOOK_SNIFF`. Declared here
|
|
202
212
|
// rather than in ./shim.mjs because `ownHookVerb` below reads it, and shim.mjs imports this module.
|