Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
node-version: 22
- name: Tests (guard, risk tier, verdict hook, shell parsing)
run: node --test "tests/*.test.mjs"
- name: Plugin structure, budgets and public-content check
- name: Plugin structure, markdown total and public-content check
env:
BSTACK_PRIVATE_NAMES: ${{ secrets.BSTACK_PRIVATE_NAMES }}
run: node tools/check-plugin.mjs
Expand Down
2 changes: 1 addition & 1 deletion evals/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A fixed set of cases that show whether bstack's rule text changes what an agent does. Each case runs twice through `claude plugin eval`: once with the plugin and once without it (the baseline arm). A case earns its place when the baseline fails it more often than the plugin does.

The suite lives here, outside `plugins/bstack`, so it does not ship with the plugin and does not count against the plugin's markdown budget.
The suite lives here, outside `plugins/bstack`, so it does not ship with the plugin and does not count in the plugin's markdown total that `tools/check-plugin.mjs` prints.

## When to run it

Expand Down
28 changes: 28 additions & 0 deletions tests/check-plugin.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,34 @@ test('#287: a guard hook that lets a failing call through still fails the check'
assert.match(out, /PreToolUse guard must set "onFailure": "block"/);
});

test('#319: markdown of any size passes and the total is still printed', () => {
const big = 'word '.repeat(40000);
const { root } = fixture({
'plugins/bstack/skills/mode/playbooks/long.md': big,
'plugins/bstack/rules/core.md': big,
});
const { code, out } = check(root);
assert.equal(code, 0, out);
assert.match(out, /^ok: \d+ markdown files, \d+ bytes$/m);
assert.ok(Number(/, (\d+) bytes/.exec(out)[1]) > 400000, out);
});

const skill = description => `---\nname: mode\ndescription: ${description}\n---\n`;

for (const [what, files, message] of [
['a skill without frontmatter', { 'plugins/bstack/skills/mode/SKILL.md': 'no frontmatter' }, /missing or without frontmatter/],
['a description over 400 characters', { 'plugins/bstack/skills/mode/SKILL.md': skill('x'.repeat(401)) }, /description over 400 characters/],
['a broken link', { 'plugins/bstack/rules/extra.md': '[x](nowhere.md)' }, /broken link nowhere\.md/],
['a missing plugin-root file', { 'plugins/bstack/rules/extra.md': '${CLAUDE_PLUGIN_ROOT}/scripts/nowhere.mjs' }, /references missing plugin file scripts\/nowhere\.mjs/],
]) {
test(`#319: ${what} still fails the check`, () => {
const { root } = fixture(files);
const { code, out } = check(root);
assert.equal(code, 1);
assert.match(out, message);
});
}

test('files under .claude/ (agent worktrees) are not scanned', () => {
const { root, namesFile } = fixture({ '.claude/worktrees/agent-x/notes.txt': 'acme-secret-co' });
const { code, out } = check(root, { args: ['--names', namesFile] });
Expand Down
23 changes: 3 additions & 20 deletions tools/check-plugin.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
// Structural checks for the plugin that `claude plugin validate` does not cover: skill and agent
// frontmatter, links and plugin-root references that resolve, size budgets that force subtraction,
// frontmatter, links and plugin-root references that resolve, the plugin's markdown total (reported, not capped),
// shell hooks that also cover PowerShell, PreToolUse guards that block when they fail, and no private name from the private list in this public repo.
// node tools/check-plugin.mjs [--names file]
// The private list loads as in check-public-text.mjs; without one the name check is skipped.
Expand All @@ -19,17 +19,9 @@ const walk = dir => fs.readdirSync(dir, { withFileTypes: true }).flatMap(e => {

const REPO = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');

const BUDGET = {
'plugins/bstack/skills/mode/SKILL.md': 8192,
'plugins/bstack/rules/core.md': 3072,
'plugins/bstack/rules/style.md': 2048,
};
// PreToolUse hooks that only ask a judge to restate its report: blocking on their failure would
// refuse every hand-back, so they let a failing call through.
const NOT_GUARDS = new Set(['${CLAUDE_PLUGIN_ROOT}/scripts/verdict.mjs handback']);
const PLAYBOOK_BUDGET = 3584;
const SKILL_BUDGET = 6144;
const TOTAL_TEXT_BUDGET = 64848;

function frontmatter(file) {
const m = /^---\r?\n([\s\S]*?)\r?\n---/.exec(fs.readFileSync(file, 'utf8'));
Expand Down Expand Up @@ -72,17 +64,8 @@ export function run({ repo = REPO, args = [], env = process.env, defaultFile = D
if (fm?.name && `${fm.name}.md` !== name) fail(`${rel(file)}: name "${fm.name}" must match the file name`);
}

// Size budgets
const md = walk(plugin).filter(f => f.endsWith('.md'));
let total = 0;
for (const f of md) {
const size = fs.statSync(f).size;
total += size;
const r = rel(f);
const budget = BUDGET[r] ?? (r.includes('/playbooks/') ? PLAYBOOK_BUDGET : r.endsWith('SKILL.md') ? SKILL_BUDGET : null);
if (budget && size > budget) fail(`${r}: ${size} bytes, budget ${budget}. Subtract before adding.`);
}
if (total > TOTAL_TEXT_BUDGET) fail(`plugin markdown totals ${total} bytes, budget ${TOTAL_TEXT_BUDGET}`);
const total = md.reduce((sum, f) => sum + fs.statSync(f).size, 0);

// Links and plugin-root references
for (const f of md) {
Expand Down Expand Up @@ -123,7 +106,7 @@ export function run({ repo = REPO, args = [], env = process.env, defaultFile = D
error(errors.map(e => `x ${e}`).join('\n'));
return 1;
}
log(`ok: ${md.length} markdown files, ${total} bytes of ${TOTAL_TEXT_BUDGET}`);
log(`ok: ${md.length} markdown files, ${total} bytes`);
return 0;
}

Expand Down
Loading