The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
feat(gateguard): build condensed code hints from the question ids
Jeffrey Montoya0301055327c1
diff --git a/docs/gateguard/design-notes.md b/docs/gateguard/design-notes.mdindex 76e74eb2e..a84c7f151 100644--- a/docs/gateguard/design-notes.md+++ b/docs/gateguard/design-notes.md@@ -390,9 +390,14 @@ never profiled, so they always get the full code questions. Instruction andconfig questions carry no change-dependent item, and the test and prose itemsdo not depend on what the change touches, so the profile leaves those classesalone. For a MultiEdit, the denied file's profile covers every entry for that-file (same canonical key); entries for other files do not count. The condensed-denial uses the local-callers hint when `local-callers` is asked, else the-original code hint.+file (same canonical key); entries for other files do not count.++A condensed code denial names the same ids as a full one, one short phrase per+id (`condensedQuestionPhrase`), so the data and duplicate checks follow the+profile there too. The one exception is an Edit with an unknown profile, which+keeps the original hint byte for byte ("importers/callers, affected API, data+schemas if any"); a Write with an unknown profile, sensitive Writes included,+names `callers`, `no-duplicate` and `data-schema` like its full denial.## Closest search that did not countdiff --git a/manifests/context-packs/[email protected] b/manifests/context-packs/[email protected]index fd48898b6..1376e77aa 100644--- a/manifests/context-packs/[email protected]+++ b/manifests/context-packs/[email protected]@@ -1 +1 @@-{"coverage":{"skills":293,"withTriggers":32},"generatedAt":"2026-09-24T23:51:22.784Z","id":"skill-triggers@1","model":{"effort":null,"id":"hand-seeded","source":"manual-curation-pending-regeneration"},"registryDigest":"e317b28aa98c37c96abc349b6a16a336db01bed47f9af25a240520c365a958d6","schemaVersion":1,"triggers":{"skill:api-connector-builder":["add api integration","new provider connector","match existing integration pattern"],"skill:api-design":["rest endpoint design","pagination api","status codes","api versioning","rate limiting api","resource naming","filtering api","api error responses","offset pagination","limit query parameter","pagination defaults"],"skill:backend-patterns":["express api","node backend architecture","nextjs api routes","server side patterns","data access layer","static file server","url path handling","file server"],"skill:browser-qa":["deployed feature test","visual regression screenshots","core web vitals check","axe accessibility audit","ship do not ship","staging verification"],"skill:canary-watch":["post deploy monitoring","smoke test url","production url check","console errors production","sse stream check","after deploy verification"],"skill:code-tour":["onboarding walkthrough","explain subsystem","architecture tour","pr walkthrough","rca tour"],"skill:coding-standards":["code review standards","naming conventions","readability review","immutability conventions","fix naming typo","export naming","consistent exports"],"skill:content-hash-cache-pattern":["cache file processing","content addressed cache","sha256 hash cache"],"skill:database-migrations":["zero downtime migration","schema change production","add column large table","backfill data","expand contract","concurrent index","migration rollback","prisma migration","django migration"],"skill:deployment-patterns":["ci cd setup","dockerize app","health checks","rollback strategy","production readiness","deploy pipeline","containerize application"],"skill:design-system":["design tokens","visual consistency audit","css custom properties","ui audit","design system bootstrap"],"skill:django-patterns":["django orm","drf api","django rest framework","django caching","django signals","django middleware"],"skill:django-security":["django authentication","csrf protection","sql injection prevention","xss prevention","django deployment security","role based access control","authorization middleware","permissions checks"],"skill:docker-patterns":["dockerfile review","docker compose setup","container security","multi service orchestration"],"skill:error-handling":["error types","retry logic","circuit breaker","user facing errors","exception handling patterns","typed errors","error boundaries","go error handling","custom error class","error codes","config validation"],"skill:evm-token-decimals":["token decimals","wei conversion","erc20 balance off","bridge token precision"],"skill:frontend-a11y":["aria attributes","screen reader support","focus management","semantic html","form labeling","keyboard navigation react","a11y lint errors"],"skill:git-workflow":["merge vs rebase","commit conventions","resolve merge conflict","branching strategy","clean up commits","pull request cleanup","git history tidy"],"skill:hexagonal-architecture":["ports and adapters","dependency injection boundaries","decouple domain from io"],"skill:kubernetes-patterns":["kubernetes manifests","kubectl debugging","pod probes","k8s rbac","autoscaling config","configmap secrets"],"skill:orch-fix-defect":["fix a bug","broken behavior","regression fix","reproduce bug","defect repair"],"skill:postgres-patterns":["slow postgres query","query optimization","index design","rls policies","supabase schema","postgres indexing","database performance","schema design postgres","postgres driver","node postgres","query planner"],"skill:python-patterns":["pythonic code","pep 8","type hints python","python code review","idiomatic python"],"skill:python-testing":["pytest fixtures","mocking python","parametrized tests","coverage python","tdd python"],"skill:redis-patterns":["cache aside pattern","distributed lock","redis rate limiting","cache invalidation"],"skill:regex-vs-llm-structured-text":["parse invoice","extract receipt data","text extraction pipeline","parse form fields","cheap document parser","extract table data","parse log lines","parse access logs","common log format","log line parsing"],"skill:rust-patterns":["rust ownership","borrow checker","rust error handling","traits rust","rust concurrency","idiomatic rust"],"skill:search-first":["find existing library","npm package research","before writing custom code","evaluate existing tools","add dependency research"],"skill:security-review":["security audit","authentication review","sanitize user input","secrets handling","payment security checklist","prevent injection attacks","secure api endpoints","authn authz review","vulnerability checklist","input validation security","parameterized queries","sql injection"],"skill:security-scan":["audit claude config","claudemd security","mcp server audit","agentshield scan","hook configuration audit","settings json security"],"skill:tdd-workflow":["write test first","failing test","red green refactor","test driven development","regression test first","write a regression test"],"skill:verification-loop":["pre pr checks","verification report","quality gates","build lint test coverage","before creating a pr"]},"triggersDigest":"25b97a9e06fc336c7cf95ab854ed1a41033a54bcd6e1fb1cf69dc906332462aa"}+{"coverage":{"skills":293,"withTriggers":32},"generatedAt":"2026-09-24T23:51:22.784Z","id":"skill-triggers@1","model":{"effort":null,"id":"hand-seeded","source":"manual-curation-pending-regeneration"},"registryDigest":"22a0db48cf2f099357d4ab90d78dcd7a882fa65e0d961d503fc641b7d36d14a5","schemaVersion":1,"triggers":{"skill:api-connector-builder":["add api integration","new provider connector","match existing integration pattern"],"skill:api-design":["rest endpoint design","pagination api","status codes","api versioning","rate limiting api","resource naming","filtering api","api error responses","offset pagination","limit query parameter","pagination defaults"],"skill:backend-patterns":["express api","node backend architecture","nextjs api routes","server side patterns","data access layer","static file server","url path handling","file server"],"skill:browser-qa":["deployed feature test","visual regression screenshots","core web vitals check","axe accessibility audit","ship do not ship","staging verification"],"skill:canary-watch":["post deploy monitoring","smoke test url","production url check","console errors production","sse stream check","after deploy verification"],"skill:code-tour":["onboarding walkthrough","explain subsystem","architecture tour","pr walkthrough","rca tour"],"skill:coding-standards":["code review standards","naming conventions","readability review","immutability conventions","fix naming typo","export naming","consistent exports"],"skill:content-hash-cache-pattern":["cache file processing","content addressed cache","sha256 hash cache"],"skill:database-migrations":["zero downtime migration","schema change production","add column large table","backfill data","expand contract","concurrent index","migration rollback","prisma migration","django migration"],"skill:deployment-patterns":["ci cd setup","dockerize app","health checks","rollback strategy","production readiness","deploy pipeline","containerize application"],"skill:design-system":["design tokens","visual consistency audit","css custom properties","ui audit","design system bootstrap"],"skill:django-patterns":["django orm","drf api","django rest framework","django caching","django signals","django middleware"],"skill:django-security":["django authentication","csrf protection","sql injection prevention","xss prevention","django deployment security","role based access control","authorization middleware","permissions checks"],"skill:docker-patterns":["dockerfile review","docker compose setup","container security","multi service orchestration"],"skill:error-handling":["error types","retry logic","circuit breaker","user facing errors","exception handling patterns","typed errors","error boundaries","go error handling","custom error class","error codes","config validation"],"skill:evm-token-decimals":["token decimals","wei conversion","erc20 balance off","bridge token precision"],"skill:frontend-a11y":["aria attributes","screen reader support","focus management","semantic html","form labeling","keyboard navigation react","a11y lint errors"],"skill:git-workflow":["merge vs rebase","commit conventions","resolve merge conflict","branching strategy","clean up commits","pull request cleanup","git history tidy"],"skill:hexagonal-architecture":["ports and adapters","dependency injection boundaries","decouple domain from io"],"skill:kubernetes-patterns":["kubernetes manifests","kubectl debugging","pod probes","k8s rbac","autoscaling config","configmap secrets"],"skill:orch-fix-defect":["fix a bug","broken behavior","regression fix","reproduce bug","defect repair"],"skill:postgres-patterns":["slow postgres query","query optimization","index design","rls policies","supabase schema","postgres indexing","database performance","schema design postgres","postgres driver","node postgres","query planner"],"skill:python-patterns":["pythonic code","pep 8","type hints python","python code review","idiomatic python"],"skill:python-testing":["pytest fixtures","mocking python","parametrized tests","coverage python","tdd python"],"skill:redis-patterns":["cache aside pattern","distributed lock","redis rate limiting","cache invalidation"],"skill:regex-vs-llm-structured-text":["parse invoice","extract receipt data","text extraction pipeline","parse form fields","cheap document parser","extract table data","parse log lines","parse access logs","common log format","log line parsing"],"skill:rust-patterns":["rust ownership","borrow checker","rust error handling","traits rust","rust concurrency","idiomatic rust"],"skill:search-first":["find existing library","npm package research","before writing custom code","evaluate existing tools","add dependency research"],"skill:security-review":["security audit","authentication review","sanitize user input","secrets handling","payment security checklist","prevent injection attacks","secure api endpoints","authn authz review","vulnerability checklist","input validation security","parameterized queries","sql injection"],"skill:security-scan":["audit claude config","claudemd security","mcp server audit","agentshield scan","hook configuration audit","settings json security"],"skill:tdd-workflow":["write test first","failing test","red green refactor","test driven development","regression test first","write a regression test"],"skill:verification-loop":["pre pr checks","verification report","quality gates","build lint test coverage","before creating a pr"]},"triggersDigest":"25b97a9e06fc336c7cf95ab854ed1a41033a54bcd6e1fb1cf69dc906332462aa"}diff --git a/scripts/dev/gateguard-eval.js b/scripts/dev/gateguard-eval.jsindex ec8886a53..9adba385d 100644--- a/scripts/dev/gateguard-eval.js+++ b/scripts/dev/gateguard-eval.js@@ -40,7 +40,7 @@ const QUESTION_IDS = Object.freeze(['quote-instruction']);-const CONDENSED_PHRASES = Object.freeze([+const LEGACY_CONDENSED_PHRASES = Object.freeze([{ phrase: 'call sites in this file or its module', ids: { edit: 'local-callers', creation: 'local-callers' } },{ phrase: 'importers/callers', ids: { edit: 'importers', creation: 'callers' } },{ phrase: 'affected API', ids: { edit: 'public-api', creation: 'public-api' } },@@ -301,8 +301,13 @@ async function runCorpus(hookFile, scenarios) {// --- question mapping ---function questionTextTable() {- const { questionText } = require(path.join(REPO_ROOT, 'scripts', 'lib', 'gateguard-target-class'));- return new Map(QUESTION_IDS.map(id => [questionText(id), id]));+ const { questionText, condensedQuestionPhrase } = require(path.join(REPO_ROOT, 'scripts', 'lib', 'gateguard-target-class'));+ const table = new Map(QUESTION_IDS.map(id => [questionText(id), id]));+ table.condensed = [+ ...QUESTION_IDS.filter(id => condensedQuestionPhrase(id)).map(id => ({ phrase: condensedQuestionPhrase(id), ids: { edit: id, creation: id } })),+ ...LEGACY_CONDENSED_PHRASES+ ];+ return table;}/** Question ids a denial asked, read from its numbered list or its condensed hint. */@@ -315,7 +320,8 @@ function questionsAsked(reason, table) {if (numbered.length > 0) return numbered;const condensed = reason.match(CONDENSED_PREFIX);if (!condensed) return [];- return CONDENSED_PHRASES.filter(({ phrase }) => reason.includes(phrase)).map(({ ids }) => ids[condensed[1]]);+ const phrases = table.condensed || LEGACY_CONDENSED_PHRASES;+ return [...new Set(phrases.filter(({ phrase }) => reason.includes(phrase)).map(({ ids }) => ids[condensed[1]]))];}// --- metrics ---diff --git a/scripts/lib/gateguard-target-class.js b/scripts/lib/gateguard-target-class.jsindex 4940f9bfa..17e03825d 100644--- a/scripts/lib/gateguard-target-class.js+++ b/scripts/lib/gateguard-target-class.js@@ -205,8 +205,26 @@ function questionText(id) {const CODE_CONDENSED_HINT ="briefly state importers/callers, affected API, data schemas if any, and the user's verbatim instruction, then retry.";-const LOCAL_CODE_CONDENSED_HINT =- "briefly state the call sites in this file or its module that rely on the change, data schemas if any, and the user's verbatim instruction, then retry.";++const CONDENSED_PHRASES = Object.freeze({+ importers: 'the files that import this file',+ 'public-api': 'the public functions/classes affected',+ 'local-callers': 'the call sites in this file or its module that rely on the change',+ callers: 'the file(s) and line(s) that will call it',+ 'no-duplicate': 'that no existing file serves the same purpose',+ 'data-schema': 'the data schemas it reads or writes',+ 'quote-instruction': "the user's verbatim instruction"+});++/** Condensed-hint phrase for a code question id, or '' when it has none. */+function condensedQuestionPhrase(id) {+ return Object.hasOwn(CONDENSED_PHRASES, id) ? CONDENSED_PHRASES[id] : '';+}++function joinPhrases(phrases) {+ if (phrases.length <= 2) return phrases.join(' and ');+ return `${phrases.slice(0, -1).join(', ')}, and ${phrases[phrases.length - 1]}`;+}const CLASS_CONDENSED_HINTS = {instruction: () =>@@ -224,7 +242,9 @@ const CLASS_CONDENSED_HINTS = {/** One-line condensed hint matching `questionIdsFor`. */function condensedHintFor(cls, isWrite, profile) {if (Object.hasOwn(CLASS_CONDENSED_HINTS, cls)) return CLASS_CONDENSED_HINTS[cls](Boolean(isWrite));- return questionIdsFor(cls, isWrite, profile).includes('local-callers') ? LOCAL_CODE_CONDENSED_HINT : CODE_CONDENSED_HINT;+ if (!isWrite && !(profile && profile.known === true)) return CODE_CONDENSED_HINT;+ const phrases = questionIdsFor(cls, isWrite, profile).map(condensedQuestionPhrase).filter(Boolean);+ return `briefly state ${joinPhrases(phrases)}, then retry.`;}// --- Sensitive targets ---@@ -372,6 +392,7 @@ module.exports = {questionIdsFor,questionText,condensedHintFor,+ condensedQuestionPhrase,resolveTargetPath,canonicalPathKey,classifyTarget,diff --git a/skills/gateguard/SKILL.md b/skills/gateguard/SKILL.mdindex 079675830..2150c283f 100644--- a/skills/gateguard/SKILL.md+++ b/skills/gateguard/SKILL.md@@ -161,7 +161,10 @@ and Write unless noted. Items marked *(search)* carry the suffix| config | Name which process/tool reads this file and when · Describe the effect of the change · Confirm no secrets or credentials are being written in plain text |Condensed denials (after `GATEGUARD_FACT_FORCE_FULL_DENIALS`) carry a-one-line hint for the same class. Besides the message text, the class only+one-line hint for the same class. For code targets the hint names the same+questions as the full denial, one short phrase each; an Edit whose change+cannot be read keeps the fixed hint (importers/callers, affected API, data+schemas if any). Besides the message text, the class onlydecides [sibling collapse](#same-turn-sibling-creation-collapse): which filesmay collapse, and that a sibling must share the first file's class.diff --git a/tests/hooks/gateguard-fact-force.test.js b/tests/hooks/gateguard-fact-force.test.jsindex 3e089c2a0..a1ce466a5 100644--- a/tests/hooks/gateguard-fact-force.test.js+++ b/tests/hooks/gateguard-fact-force.test.js@@ -4559,6 +4559,12 @@ function runTests() {const local = b2Reason('Edit', { file_path: 'src/c1.js', old_string: ' return 1;', new_string: ' return 2;' }, env);assert.ok(local.includes('the call sites in this file or its module that rely on the change'), local);assert.ok(!local.includes('importers/callers'), 'no importer hint for a local change');+ assert.ok(!local.includes('data schemas'), 'no data hint for a change without data');+ const created = b2Reason('Write', { file_path: 'src/c3.js', content: 'export const a = 1;\n' }, env);+ assert.ok(created.includes('that no existing file serves the same purpose'), created);+ assert.ok(created.includes('(denial #') && created.includes('parallel batch') && created.includes('ECC_GATEGUARD=off'), 'keeps ordinal and hints');+ const data = b2Reason('Edit', { file_path: 'src/c4.js', old_string: ' return 1;', new_string: ' return JSON.parse(raw);' }, env);+ assert.ok(data.includes('the data schemas it reads or writes'), data);const full = b2Reason('Edit', { file_path: 'src/c2.rb', old_string: 'a', new_string: 'b' }, env);assert.ok(full.includes('briefly state importers/callers, affected API, data schemas if any'), 'unknown profile keeps the hint');})diff --git a/tests/lib/gateguard-target-class.test.js b/tests/lib/gateguard-target-class.test.jsindex 4132a9c82..042019c9d 100644--- a/tests/lib/gateguard-target-class.test.js+++ b/tests/lib/gateguard-target-class.test.js@@ -20,6 +20,7 @@ const {questionIdsFor,questionText,condensedHintFor,+ condensedQuestionPhrase,COLLAPSIBLE_CLASSES,canonicalPathKey,classifyTarget,@@ -355,11 +356,71 @@ test('class question texts are unchanged by the ids', () => {test('condensedHintFor matches the question set', () => {const local = { known: true, touchesPublicSurface: false, touchesData: false };assert.ok(condensedHintFor('code', false, local).includes('call sites in this file or its module'));- assert.ok(condensedHintFor('code', false, null).startsWith('briefly state importers/callers'));- assert.ok(condensedHintFor('code', true, local).startsWith('briefly state importers/callers'));assert.strictEqual(condensedHintFor('test', false, local), CLASS_CONDENSED_HINTS.test(false));});+test('code condensed hints name exactly the questions of the change profile', () => {+ const known = (touchesPublicSurface, touchesData) => ({ known: true, language: 'js', touchesPublicSurface, touchesData, trivial: false });+ const ids = ['importers', 'public-api', 'local-callers', 'callers', 'no-duplicate', 'data-schema', 'quote-instruction'];+ for (const id of ids) assert.ok(condensedQuestionPhrase(id), `${id} has a phrase`);+ for (const isWrite of [false, true]) {+ for (const [s, d] of [[true, true], [true, false], [false, true], [false, false]]) {+ const profile = known(s, d);+ const hint = condensedHintFor('code', isWrite, profile);+ const asked = questionIdsFor('code', isWrite, profile);+ for (const id of ids) {+ assert.strictEqual(hint.includes(condensedQuestionPhrase(id)), asked.includes(id), `${isWrite ? 'Write' : 'Edit'} ${s}/${d} ${id}`);+ }+ assert.ok(hint.startsWith('briefly state ') && hint.endsWith(', then retry.'), hint);+ }+ }+});++test('code condensed hints read as one sentence', () => {+ const known = (touchesPublicSurface, touchesData) => ({ known: true, language: 'js', touchesPublicSurface, touchesData, trivial: false });+ assert.strictEqual(+ condensedHintFor('code', false, known(false, false)),+ "briefly state the call sites in this file or its module that rely on the change and the user's verbatim instruction, then retry."+ );+ assert.strictEqual(+ condensedHintFor('code', false, known(true, true)),+ "briefly state the files that import this file, the public functions/classes affected, the data schemas it reads or writes, and the user's verbatim instruction, then retry."+ );+ assert.strictEqual(+ condensedHintFor('code', true, known(true, false)),+ "briefly state the file(s) and line(s) that will call it, that no existing file serves the same purpose, and the user's verbatim instruction, then retry."+ );+});++test('code condensed hints keep the data and duplicate checks when the profile asks for them', () => {+ const known = (touchesPublicSurface, touchesData) => ({ known: true, language: 'py', touchesPublicSurface, touchesData, trivial: false });+ assert.ok(condensedHintFor('code', false, known(false, true)).includes(condensedQuestionPhrase('data-schema')));+ assert.ok(condensedHintFor('code', false, known(true, false)).includes(condensedQuestionPhrase('importers')));+ for (const profile of [known(false, false), known(true, true)]) {+ assert.ok(condensedHintFor('code', true, profile).includes(condensedQuestionPhrase('no-duplicate')), 'Write asks for duplicates');+ assert.ok(condensedHintFor('code', true, profile).includes(condensedQuestionPhrase('callers')), 'Write asks for callers');+ }+});++test('code condensed Edit hint for an unknown profile is unchanged', () => {+ const legacy = "briefly state importers/callers, affected API, data schemas if any, and the user's verbatim instruction, then retry.";+ for (const profile of [null, undefined, { known: false, touchesPublicSurface: false, touchesData: false }, 'x']) {+ assert.strictEqual(condensedHintFor('code', false, profile), legacy);+ assert.strictEqual(condensedHintFor('__proto__', false, profile), legacy);+ }+});++test('code condensed Write hint for an unknown profile asks every creation question', () => {+ for (const profile of [null, undefined, { known: false, touchesPublicSurface: false, touchesData: false }, 'x']) {+ assert.strictEqual(+ condensedHintFor('code', true, profile),+ "briefly state the file(s) and line(s) that will call it, that no existing file serves the same purpose, the data schemas it reads or writes, and the user's verbatim instruction, then retry."+ );+ }+ assert.strictEqual(condensedQuestionPhrase('constructor'), '');+ assert.strictEqual(condensedQuestionPhrase('loader'), '');+});+// ── isSensitiveTarget ──test('isSensitiveTarget matches every listed basename, segment and prefix rule', () => {