The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
Merge PR #3444: track OpenCode skill runs and report measurement gaps
haelyra27875bfd0260
diff --cc scripts/hooks/stop-format-typecheck.jsindex 0bab7d09c,8ae580db5..2ac6ae5b6--- a/scripts/hooks/stop-format-typecheck.js+++ b/scripts/hooks/stop-format-typecheck.js@@@ -273,12 -248,4 +273,11 @@@ if (require.main === module)});}-module.exports = { run, parseAccumulator, isPluginClonePath };+module.exports = {+ diagnosticMatchesFile,+ run,+ parseAccumulator,+ isPluginClonePath,+ getTotalBudgetMs,+ getPerBatchBudgetMs,+};-diff --cc tests/opencode-plugin-hooks.test.jsindex a6c3ed2ae,e327f6ebf..421f38113--- a/tests/opencode-plugin-hooks.test.js+++ b/tests/opencode-plugin-hooks.test.js@@@ -381,6 -465,232 +465,232 @@@ async function main()}),],+ [+ "skill telemetry records a run through the shared tracker (#2463)",+ async () => withTempProject([], async (projectDir) => {+ const homeDir = fs.mkdtempSync(path.join(os.tmpdir(), "ecc-opencode-skill-home-"))+ const previousHome = process.env.HOME+ const previousUserProfile = process.env.USERPROFILE+ process.env.HOME = homeDir+ process.env.USERPROFILE = homeDir+ try {+ const client = createClient()+ const $ = createFailingShell()+ const hooks = await ECCHooksPlugin({ client, $, directory: projectDir })++ assert.ok(+ !client.logs.some(+ (entry) =>+ entry.level === "warn" && entry.message.includes("skill-run telemetry disabled")+ ),+ "Did not expect telemetry to be disabled when scripts/hooks/skill-run-tracker.js is present"+ )++ // OpenCode names the tool `skill`; the id arrives on `name`.+ await hooks["tool.execute.after"]({ tool: "skill", args: { name: "code-review" } }, {})++ const records = readRecordedRuns(homeDir)++ assert.strictEqual(records.length, 1, "Expected exactly one recorded skill run")+ assert.strictEqual(records[0].skill_id, "code-review")+ assert.strictEqual(records[0].outcome, "success")+ } finally {+ restoreEnv({ HOME: previousHome, USERPROFILE: previousUserProfile })+ fs.rmSync(homeDir, { recursive: true, force: true })+ }+ }),+ ],+ [+ "skill telemetry records nothing for other tools",+ async () => withTempProject([], async (projectDir) => {+ const homeDir = fs.mkdtempSync(path.join(os.tmpdir(), "ecc-opencode-skill-home-"))+ const previousHome = process.env.HOME+ const previousUserProfile = process.env.USERPROFILE+ process.env.HOME = homeDir+ process.env.USERPROFILE = homeDir+ try {+ const client = createClient()+ const $ = createFailingShell()+ const hooks = await ECCHooksPlugin({ client, $, directory: projectDir })++ await hooks["tool.execute.after"]({ tool: "edit", args: { path: "src/a.ts" } }, {})+ await hooks["tool.execute.after"]({ tool: "bash", args: { command: "ls" } }, {})++ assert.strictEqual(readRecordedRuns(homeDir).length, 0)+ } finally {+ restoreEnv({ HOME: previousHome, USERPROFILE: previousUserProfile })+ fs.rmSync(homeDir, { recursive: true, force: true })+ }+ }),+ ],+ [+ "skill telemetry respects the minimal hook profile",+ async () => withTempProject([], async (projectDir) => {+ const homeDir = fs.mkdtempSync(path.join(os.tmpdir(), "ecc-opencode-skill-home-"))+ const previousHome = process.env.HOME+ const previousUserProfile = process.env.USERPROFILE+ const previousProfile = process.env.ECC_HOOK_PROFILE+ process.env.HOME = homeDir+ process.env.USERPROFILE = homeDir+ process.env.ECC_HOOK_PROFILE = "minimal"+ try {+ const client = createClient()+ const $ = createFailingShell()+ const hooks = await ECCHooksPlugin({ client, $, directory: projectDir })++ await hooks["tool.execute.after"]({ tool: "skill", args: { name: "code-review" } }, {})++ assert.strictEqual(readRecordedRuns(homeDir).length, 0)+ } finally {+ restoreEnv({+ HOME: previousHome,+ USERPROFILE: previousUserProfile,+ ECC_HOOK_PROFILE: previousProfile,+ })+ fs.rmSync(homeDir, { recursive: true, force: true })+ }+ }),+ ],+ [+ "shell.env exports CLAUDE_PLUGIN_ROOT so commands can resolve the ECC root",+ async () => withTempProject([], async (projectDir) => {+ const previousRoot = process.env.CLAUDE_PLUGIN_ROOT+ delete process.env.CLAUDE_PLUGIN_ROOT+ try {+ const client = createClient()+ const $ = createFailingShell()+ const hooks = await ECCHooksPlugin({ client, $, directory: projectDir })++ const output = { env: {} }+ await hooks["shell.env"]({ cwd: projectDir }, output)++ assert.deepStrictEqual($.calls, [], `Unexpected shell probes: ${$.calls.join(", ")}`)+ assert.ok(output.env.CLAUDE_PLUGIN_ROOT, "Expected CLAUDE_PLUGIN_ROOT to be exported")++ // The resolver consumes this variable verbatim, so it must be a+ // directory that actually carries the ECC script tree.+ const root = output.env.CLAUDE_PLUGIN_ROOT+ assert.ok(+ fs.existsSync(path.join(root, "scripts", "lib", "resolve-ecc-root.js")),+ `Expected ${root} to contain scripts/lib/resolve-ecc-root.js`+ )+ } finally {+ restoreEnv({ CLAUDE_PLUGIN_ROOT: previousRoot })+ }+ }),+ ],+ [+ "shell.env does not override a CLAUDE_PLUGIN_ROOT the user set",+ async () => withTempProject([], async (projectDir) => {+ const explicitRoot = path.join(projectDir, "explicit-root")+ const previousRoot = process.env.CLAUDE_PLUGIN_ROOT+ process.env.CLAUDE_PLUGIN_ROOT = explicitRoot+ try {+ const client = createClient()+ const $ = createFailingShell()+ const hooks = await ECCHooksPlugin({ client, $, directory: projectDir })++ const output = { env: {} }+ await hooks["shell.env"]({ cwd: projectDir }, output)++ assert.strictEqual(+ output.env.CLAUDE_PLUGIN_ROOT,+ undefined,+ "the plugin must not inject its own root over one the user set"+ )+ assert.strictEqual(+ process.env.CLAUDE_PLUGIN_ROOT,+ explicitRoot,+ "the user's value must survive untouched"+ )+ } finally {+ restoreEnv({ CLAUDE_PLUGIN_ROOT: previousRoot })+ }+ }),+ ],+ [+ "shell.env does not clobber a root another plugin already put in output.env",+ async () => withTempProject([], async (projectDir) => {+ const previousRoot = process.env.CLAUDE_PLUGIN_ROOT+ delete process.env.CLAUDE_PLUGIN_ROOT+ try {+ const client = createClient()+ const $ = createFailingShell()+ const hooks = await ECCHooksPlugin({ client, $, directory: projectDir })++ // An earlier plugin chose a root. The final merge below spreads our env+ // over output.env, so a guard that only checked process.env would+ // replace this value.+ const output = { env: { CLAUDE_PLUGIN_ROOT: path.join(projectDir, "other-plugin-root") } }+ await hooks["shell.env"]({ cwd: projectDir }, output)++ assert.strictEqual(+ output.env.CLAUDE_PLUGIN_ROOT,+ path.join(projectDir, "other-plugin-root"),+ "an existing output.env root must be preserved"+ )+ } finally {+ restoreEnv({ CLAUDE_PLUGIN_ROOT: previousRoot })+ }+ }),+ ],+ [+ "telemetry and root export work in a modular install without optional skills",+ async () => {+ // Regression: root detection probed skills/continuous-learning-v2, which+ // belongs to the optional workflow-quality module. An install with+ // platform-configs + hooks-runtime but without workflow-quality still+ // ships the plugin and the tracker, and it lost both fixes.+ const root = createModularInstallRoot()+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ecc-opencode-modular-"))+ const homeDir = fs.mkdtempSync(path.join(os.tmpdir(), "ecc-opencode-skill-home-"))+ const previousHome = process.env.HOME+ const previousUserProfile = process.env.USERPROFILE+ const previousRoot = process.env.CLAUDE_PLUGIN_ROOT+ process.env.HOME = homeDir+ process.env.USERPROFILE = homeDir+ delete process.env.CLAUDE_PLUGIN_ROOT+ try {+ assert.ok(+ !fs.existsSync(path.join(root, "skills")),+ "the fixture must not contain skills/, or it would not test the modular case"+ )++ const { ECCHooksPlugin: modularPlugin } = await loadPluginFrom(root)+ const client = createClient()+ const hooks = await modularPlugin({+ client,+ $: createFailingShell(),+ directory: projectDir,+ })++ assert.ok(+ !client.logs.some(+ (entry) =>+ entry.level === "warn" && entry.message.includes("skill-run telemetry disabled")+ ),+ "telemetry must stay enabled when the optional skills module is absent"+ )++ await hooks["tool.execute.after"]({ tool: "skill", args: { name: "code-review" } }, {})+ assert.strictEqual(readRecordedRuns(homeDir).length, 1, "expected the run to be recorded")++ const output = { env: {} }+ await hooks["shell.env"]({ cwd: projectDir }, output)- assert.strictEqual(output.env.CLAUDE_PLUGIN_ROOT, root)++ assert.strictEqual(output.env.CLAUDE_PLUGIN_ROOT, fs.realpathSync(root))+ assert.strictEqual(output.env.ECC_VERSION, "0.0.0-test")+ } finally {+ restoreEnv({+ HOME: previousHome,+ USERPROFILE: previousUserProfile,+ CLAUDE_PLUGIN_ROOT: previousRoot,+ })+ fs.rmSync(root, { recursive: true, force: true })+ fs.rmSync(projectDir, { recursive: true, force: true })+ fs.rmSync(homeDir, { recursive: true, force: true })+ }+ },+ ],]let passed = 0