Files
gstack/test/skill-triggers.test.ts
T
Garry Tanandcapy-ai[bot] ab114c5308 Say when to use each gstack skill in Claude Code's skill list (GST-2774) (#4387)
* Say when to use each gstack skill in Claude Code's skill list (GST-2774)

Claude Code's listing of each gstack skill now keeps a short when-to-use
clause after its first sentence, so Opus 5.5 loads /review on "review my
changes" and /plan-eng-review on "plan this feature" (GSTA-558).

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Keep /review and /plan-eng-review within their size pins and refresh budgets

CI on the first head found five size and fact checks the new catalog
clause moved: the per-host SKILL.md size pins, the context-budget
ceilings, the deslop-shared-libs catalog byte pin, the Claude ship golden
and the catalog ceiling CLAUDE.md states. /review's and /plan-eng-review's
full descriptions are now shorter than before, so their pins go down, and
/plan-eng-review's scope gate is unchanged from main.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Say which skills keep no when-to-use clause in the changelog entry

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Update the catalog budget and voice-trigger docs for the when-to-use clause

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Drop "deploy this" from /ship's Claude Code skill list line

Deploying belongs to /land-and-deploy, so /ship's when-to-use clause keeps
"ship it, create a pr, push to main" only. Budgets, the size ledger and the
Claude ship golden are re-measured.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix: pre-landing review fixes

Review-Finding: p1/specialist-batched#1 reader=specialist-batched
Review-Finding: p1/red-team#1 reader=red-team
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Re-measure the setup-gbrain size cap after merging main

Main grew setup-gbrain's always-loaded part to 38,621 bytes, and this
branch's when-to-use clause adds 55 more, so the cap measured on the old
base (38,637) is stale. The cap is now the merged measurement, 38,676.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

---------

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
2026-11-17 12:23:35 +00:00

71 lines
4.4 KiB
TypeScript

/**
* lib/skill-triggers.ts: the trigger-first wording rule for harness listings
* (Hermes description leads, router lines), on its branches the full-catalog
* render tests in test/harness-register.test.ts never reach because every
* current skill has a trigger sentence and a triggers list.
*
* Value: protects=Hermes descriptions keep every non-trigger sentence and the (gstack) tag; router/lead fallbacks stay trigger-first and within max;
* fails_when=withTriggerLead drops the wrong sentence or the tag, or a fallback branch (no trigger sentence, no triggers, overlong entry) exceeds max or loses its lead;
* why_new=the render tests check only the lead's prefix and length over skills that all take the triggers-list branch; seam=none;
* no_claim=how any harness ranks or shows the text (pure string functions; synthetic descriptions)
*/
import { describe, expect, test } from 'bun:test';
import { frontmatterList, routerLine, triggerList, withTriggerLead } from '../lib/skill-triggers';
const DESC = 'Pre-landing PR review. Analyzes the diff for structural issues. Use when asked to "review this PR" or "check my diff". Proactively suggest before a merge. (gstack)';
const TRIGGERS = ['review this pr', 'code review', 'check my diff', 'pre-landing review'];
describe('withTriggerLead (Hermes descriptions)', () => {
test('a triggers-list lead replaces the trigger sentence; every other sentence and the (gstack) tag stay, once', () => {
const [lead, rest, ...more] = withTriggerLead(DESC, TRIGGERS, 57).split('\n');
expect(more).toEqual([]);
expect(lead).toStartWith('Use for: review this pr');
expect(lead.length).toBeLessThanOrEqual(57);
expect(rest).toBe('Pre-landing PR review. Analyzes the diff for structural issues. Proactively suggest before a merge. (gstack)');
});
test('without triggers the lead is the trigger sentence cut at a word, and the whole description follows unchanged', () => {
const [lead, ...rest] = withTriggerLead(DESC, [], 40).split('\n');
expect(lead).toStartWith('Use when asked to');
expect(lead).toEndWith('...');
expect(lead.length).toBeLessThanOrEqual(40);
expect(rest.join('\n')).toBe(DESC);
});
});
describe('routerLine (router-mode targets)', () => {
const cases: Array<[string, string, string[], number, (line: string) => void]> = [
['trigger sentence and first sentence both fit', 'Debug a crash. Use to find the root cause.', [], 160,
l => expect(l).toBe('Use to find the root cause. Debug a crash.')],
['trigger sentence alone when both do not fit', DESC, [], 60,
l => { expect(l).toStartWith('Use when asked to'); expect(l).not.toContain('Pre-landing'); }],
['no trigger sentence: the triggers list leads', 'Pre-landing PR review. Analyzes the diff.', TRIGGERS, 160,
l => expect(l).toStartWith('Use for: review this pr, code review')],
['the catalog-trimmed "Use for:" clause gives way to the full triggers list', 'Pre-landing PR review. Use for: review this pr, code review. (gstack)', TRIGGERS, 160,
l => expect(l).toBe('Use for: review this pr, code review, check my diff, pre-landing review. Pre-landing PR review.')],
['neither: the first sentence, cut at a word', 'A very long first sentence about a workflow that goes on and on and on.', [], 40,
l => { expect(l).toStartWith('A very long first sentence'); expect(l).toEndWith('...'); }],
];
for (const [name, desc, triggers, max, check] of cases) {
test(name, () => {
const line = routerLine(desc, triggers, max);
expect(line.length).toBeLessThanOrEqual(max);
check(line);
});
}
});
test('triggerList: an entry longer than max is cut to fit instead of overflowing', () => {
const lead = triggerList(['find out why the nightly deploy pipeline keeps failing on the staging cluster'], 57);
expect(lead).toStartWith('Use for: find out why');
expect(lead).toEndWith('...');
expect(lead.length).toBeLessThanOrEqual(57);
});
test('frontmatterList reads one block list, unquoting values and stopping at the next field', () => {
const md = '---\nname: x\ntriggers:\n - "quoted one"\n - \'single\'\n - plain\nallowed-tools:\n - Bash\n---\nbody\n - not frontmatter\n';
expect(frontmatterList(md, 'triggers')).toEqual(['quoted one', 'single', 'plain']);
expect(frontmatterList(md, 'voice-triggers')).toEqual([]);
expect(frontmatterList('no frontmatter\ntriggers:\n - x\n', 'triggers')).toEqual([]);
});