geneseed 5.3.1 → 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 +102 -0
- package/README.md +51 -18
- package/SHIPPED.md +7 -7
- package/adapters/bob/README.md +12 -1
- package/adapters/opencode/README.md +5 -3
- package/adapters/opencode/plugins/geneseed-context.js +77 -10
- package/adapters/opencode/plugins/geneseed-guard.js +106 -22
- package/adapters/opencode/plugins/geneseed-learn.js +641 -6
- package/bin/geneseed-cli.mjs +10 -0
- package/bin/geneseed-hook.mjs +5 -4
- package/docs/PRD.md +1 -1
- package/docs/README.md +1 -0
- package/docs/concepts/agents.md +14 -2
- package/docs/concepts/collaboration.md +2 -2
- package/docs/concepts/enforcement-table.md +5 -2
- package/docs/concepts/exclusions.md +16 -2
- package/docs/concepts/footprint.md +1 -1
- package/docs/concepts/foreman-mode.md +23 -4
- package/docs/concepts/hook-gates.md +4 -4
- package/docs/concepts/hooks.md +25 -7
- package/docs/concepts/host-matrix.md +4 -4
- package/docs/concepts/hosts.md +1 -1
- package/docs/concepts/kits.md +12 -2
- package/docs/concepts/loop-bricks.md +3 -3
- package/docs/concepts/loops.md +6 -4
- package/docs/concepts/ownership.md +1 -1
- package/docs/concepts/rules.md +2 -2
- 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 +73 -29
- package/docs/guides/auto-merge.md +100 -0
- package/docs/guides/choose-your-setup.md +1 -1
- package/docs/guides/headless.md +1 -1
- package/docs/guides/install-clone.md +19 -1
- package/docs/guides/install-scripted.md +8 -2
- package/docs/guides/install.md +20 -2
- package/docs/guides/loop-finish.md +3 -3
- package/docs/guides/loop-running.md +4 -4
- package/docs/guides/project-context.md +1 -1
- package/docs/guides/run-a-factory.md +2 -2
- package/docs/guides/setup-doctrines.md +2 -2
- package/docs/guides/setup-footprint.md +1 -1
- package/docs/guides/uninstall.md +3 -3
- package/docs/guides/upgrade.md +2 -2
- package/docs/guides/worktree.md +1 -1
- package/docs/reference/env-context.md +1 -1
- package/docs/reference/environment.md +4 -2
- package/docs/reference/plugin-activity.md +1 -1
- package/docs/reference/plugin-guard.md +1 -1
- package/docs/reference/plugin-learn.md +5 -1
- package/docs/reference/plugin-workflow.md +1 -1
- package/docs/reference/profiles.md +142 -0
- package/docs/reference/troubleshoot-doctor.md +1 -1
- package/docs/reference/troubleshoot-hooks.md +2 -2
- package/docs/reference/troubleshoot-install.md +3 -3
- package/docs/reference/troubleshoot-tools.md +1 -1
- package/docs/token-footprint.md +11 -6
- package/docs/understand/design-choices-engineering.md +1 -1
- package/docs/understand/enforced-vs-asked.md +1 -1
- package/docs/understand/machine-claude.md +2 -2
- package/docs/understand/on-your-machine.md +1 -1
- package/docs/web-ui.md +8 -6
- package/harness.config.json +1 -1
- package/js/README.md +11 -3
- package/js/build/args.mjs +16 -4
- package/js/build/catalog.mjs +11 -1
- package/js/build/driver.mjs +74 -16
- package/js/build/emit-claude.mjs +32 -5
- package/js/build/emit-opencode.mjs +16 -9
- package/js/build/export.mjs +1 -1
- package/js/build/generate.mjs +12 -157
- package/js/build/notes-migrate.mjs +99 -0
- package/js/build/profile.mjs +326 -0
- package/js/build/render.mjs +110 -8
- package/js/build/retired-skills.mjs +60 -13
- package/js/build/source.mjs +100 -3
- package/js/build/stubs.mjs +4 -1
- package/js/cli-table.json +212 -7
- package/js/hosts/agent-runs.mjs +205 -0
- package/js/hosts/done-checks.mjs +3 -1
- package/js/hosts/hooks-done.mjs +428 -63
- package/js/hosts/hooks-learn.mjs +89 -3
- package/js/hosts/hooks-prims.mjs +44 -4
- package/js/hosts/hooks.mjs +159 -9
- package/js/hosts/hosts.mjs +10 -0
- package/js/hosts/installs.mjs +44 -2
- package/js/hosts/link.mjs +45 -10
- package/js/hosts/native.mjs +61 -7
- package/js/hosts/opencode.mjs +1 -1
- package/js/hosts/settings.mjs +101 -3
- 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-constitution.mjs +32 -0
- package/js/inspect/checks-repo.mjs +27 -2
- package/js/inspect/cost.mjs +6 -5
- package/js/inspect/diff.mjs +46 -8
- package/js/inspect/doctor.mjs +4 -0
- package/js/inspect/inventory.mjs +1 -1
- 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 +413 -15
- package/js/maintain/uninstall.mjs +4 -1
- package/js/maintain/update.mjs +4 -2
- package/js/web/actions.mjs +44 -41
- package/js/web/api.mjs +13 -3
- 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/registry.json +14 -0
- package/src/AGENT.md.tmpl +16 -18
- 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/bricks/pr-open.md +3 -2
- package/src/doctrines/ops.md +2 -2
- package/src/doctrines/process.md +40 -36
- package/src/factories/analysis-to-build.json +1 -1
- package/src/factories/bug-report-to-fix.json +1 -1
- package/src/factories/issue-to-pr.json +1 -1
- package/src/kits/terminal-tools/rules.md +10 -0
- package/src/kits/terminal-tools.json +13 -0
- package/src/licenses/herdr.txt +201 -0
- package/src/memory/README.md +12 -2
- package/src/modes/foreman.md +25 -9
- package/src/skill-descriptions.json +63 -0
- package/src/skills/_self-improvement.md +42 -24
- package/src/skills/_template.md +3 -1
- package/src/skills/brainstorm.md +35 -22
- package/src/skills/commit.md +17 -17
- package/src/skills/daydream/VENDOR.md +6 -0
- package/src/skills/debug/ci.md +1 -1
- package/src/skills/dependencies.md +3 -3
- package/src/skills/diagram-design/VENDOR.md +4 -0
- package/src/skills/document-project.md +3 -2
- package/src/skills/explain-changes/VENDOR.md +5 -1
- package/src/skills/factory.md +13 -4
- package/src/skills/geneseed.md +4 -2
- package/src/skills/git-history.md +5 -7
- package/src/skills/herdr.md +135 -0
- package/src/skills/loop.md +3 -2
- package/src/skills/opencode-cli.md +84 -0
- 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 +11 -9
- package/src/skills/review-response.md +4 -2
- package/src/skills/rule/approve.md +2 -1
- package/src/skills/rule.md +27 -1
- package/src/skills/ship.md +54 -7
- package/src/skills/skill-forge.md +5 -3
- package/src/skills/token-report/VENDOR.md +5 -1
- package/src/skills/worktree.md +2 -2
- package/src/upstreams.json +9 -2
- package/themes/README.md +3 -1
- package/themes/_TEMPLATE.json +2 -0
- package/themes/biker.json +2 -0
- package/themes/commentator.json +2 -0
- package/themes/cyberpunk.json +2 -0
- package/themes/gamer.json +2 -0
- package/themes/imperial.json +2 -0
- package/themes/joker.json +2 -0
- package/themes/marvin.json +2 -0
- package/themes/mean.json +2 -0
- package/themes/military.json +2 -0
- package/themes/neutral.json +2 -0
- package/themes/pirate.json +2 -0
- package/themes/sports.json +2 -0
- package/themes/verstappen.json +2 -0
- package/themes/wizard.json +2 -0
- package/web/dist/assets/{ActiveLoops-BJJN3P-V.js → ActiveLoops-DOJCPPPc.js} +1 -1
- package/web/dist/assets/Activity-LKsDzsnK.js +1 -0
- package/web/dist/assets/ActivityDetail-DhwTfPm6.js +1 -0
- package/web/dist/assets/{Bonsai-BBl4XXqs.js → Bonsai-CePMLrpr.js} +1 -1
- package/web/dist/assets/{CopyButton-Beven8yn.js → CopyButton-CuoaJ6k7.js} +1 -1
- package/web/dist/assets/Dashboard-D1VKuvLe.js +2 -0
- package/web/dist/assets/Docs-CUrHJKaU.js +5 -0
- package/web/dist/assets/Factories-Ci1XfmSy.js +1 -0
- package/web/dist/assets/{GreenhouseView-Bce212qd.js → GreenhouseView-CNfH2lPK.js} +1 -1
- package/web/dist/assets/Installs-ZHQZM1iS.js +3 -0
- package/web/dist/assets/{JournalView-CV4omyww.js → JournalView-CMsWahkS.js} +1 -1
- package/web/dist/assets/Kits-CkliyK0n.js +1 -0
- package/web/dist/assets/Laws-hh4O3HZ4.js +4 -0
- package/web/dist/assets/{LibRows-Dag1s0ZX.js → LibRows-Brv0Hmkr.js} +1 -1
- package/web/dist/assets/Library-BYmiLjJr.js +3 -0
- package/web/dist/assets/Loops-ytm-xJ68.js +2 -0
- package/web/dist/assets/{OperatorHudView-JmYY1pBR.js → OperatorHudView-KaqCx_HP.js} +1 -1
- package/web/dist/assets/Personal-CmcnRKYE.js +2 -0
- package/web/dist/assets/Settings-tUrpdOfq.js +1 -0
- package/web/dist/assets/{Tabs-8zsyEPSK.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-COKbhFNo.js +6 -0
- package/web/dist/index.html +3 -3
- package/web/dist/assets/Activity-WQ3ykgxU.js +0 -1
- package/web/dist/assets/ActivityDetail-7rt04SkS.js +0 -1
- package/web/dist/assets/Dashboard-BgLArtgu.js +0 -2
- package/web/dist/assets/Docs-B5aHp86J.js +0 -5
- package/web/dist/assets/Factories-BjqzXAw8.js +0 -1
- package/web/dist/assets/Installs-B1OsrHXF.js +0 -3
- package/web/dist/assets/Kits-CW1e7xNa.js +0 -1
- package/web/dist/assets/Laws-1Ckf1lbs.js +0 -4
- package/web/dist/assets/Library-B3FuFLel.js +0 -3
- package/web/dist/assets/Loops-CwqgnLNw.js +0 -2
- package/web/dist/assets/Personal-DKLgLa7Z.js +0 -2
- package/web/dist/assets/Settings-BwErnh-R.js +0 -1
- package/web/dist/assets/api-DLDVY3K-.js +0 -1
- package/web/dist/assets/index-Ce6qF2nG.js +0 -6
|
@@ -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));
|