Replace the single 747-line /gsd-help reference with a progressive-disclosure dispatcher (#2551 pattern). Newcomers get a one-page tour; returning users get a 10-line refresher with --brief; the complete reference stays available behind --full; /gsd-help <topic> emits one section; and /gsd-help --brief <topic> is a compact scoped lookup (signature + one-line summary). - workflows/help.md becomes a small dispatcher routing on $ARGUMENTS - workflows/help/modes/{brief,default,full,topic}.md hold the tier bodies - commands/gsd/help.md passes $ARGUMENTS through, advertises composable form - docs/COMMANDS.md documents the new flags and topic form - existing tests that read help.md repointed at help/modes/full.md (bug-2836, bug-2950, bug-2954, cursor-reviewer, execute-phase-wave) - new feat-3039-help-tiered test enforces structure, size budgets, dispatcher routing, shim arg passthrough, topic→section coverage, orphan-heading detection, conflict-resolution rules, routing preamble, and compact-scope rule Trek-e review fixes (PR #3040): - topic.md output rules split into 5a/5b/5c — explicit handling for single sections, multi-section "plus" joins, and bold-line sub-block anchors; each rule also takes scope (full vs compact) into account - explicit resolved-routing preamble line emitted by topic.md before content ("**Topic:** `<alias>` → `<heading>` *(scope: full | compact)*") so the user sees which alias matched at which scope (review finding #3) - composable `--brief <topic>` invokes topic.md in compact scope: heading + first `**/gsd:*`** signature line + one-line summary. Dispatcher and topic.md cooperate via $ARGUMENTS pass-through (review finding #4) - full.md capped at LARGE-tier budget (FULL_BUDGET = 1500); the non-recursive workflow-size-budget test does not reach modes/ subdirs - structural <progressive_disclosure> table parse (5-row assertion) replaces substring-soup regex matching — 5 rows = 4 base tiers + composable scope - forward /gsd:* sub-block token coverage + reverse orphan-heading allowlist catch alias-table drift in both directions - four conflict-resolution tests guard dispatcher promises (--brief+--full without topic → --full; --brief <topic> → compact; --full <topic> or bare → full; dispatcher retains --brief when delegating to topic.md) - hardcoded topic lists removed from docs/COMMANDS.md and full.md (drift surfaces reduced from 5 to 2) - topic.md alias bloat trimmed (~75 → ~25 rows); cleanup/update split into distinct sub-block rows under ### Utility Commands - comment-rot ("~750 lines") removed from default.md and full.md - dispatcher size guard tightened from < 100 to <= 40 lines - commands/gsd/help.md <process> block trimmed to one line - MD040 fence languages added to all plain code blocks across mode files Main-merge conflict resolution: - workflows/help.md kept as dispatcher (body lives in help/modes/full.md) - /gsd-<cmd> → /gsd:<cmd> rename from #3452 reapplied to the mode files (full.md, default.md, brief.md, topic.md) — the six namespace routers (/gsd-context, /gsd-ideate, /gsd-manage, /gsd-project, /gsd-quality, /gsd-workflow) and wildcards (/gsd-*) preserved in hyphen form per main's convention - bug-2950 test combines branch's path repointing with main's namespaced replacement strings
179 lines
7.0 KiB
JavaScript
179 lines
7.0 KiB
JavaScript
'use strict';
|
|
|
|
// allow-test-rule: pending-migration-to-typed-ir [#2974]
|
|
// Tracked in #2974 for migration to typed-IR assertions per CONTRIBUTING.md
|
|
// "Prohibited: Raw Text Matching on Test Outputs". Per-file review may
|
|
// reclassify some entries as source-text-is-the-product during migration.
|
|
|
|
process.env.GSD_TEST_MODE = '1';
|
|
|
|
/**
|
|
* Bug #2954: keep `help.md` and the live `commands/gsd/*` slash surface
|
|
* in lockstep. Two regression tests:
|
|
*
|
|
* 1. help.md must not advertise any /gsd[-:]<name> that has no shipped
|
|
* slash command. (Caught the original #2954 regression: #2824 deleted
|
|
* 31 stubs without updating help.md.)
|
|
*
|
|
* 2. Every shipped /gsd[-:]<name> command must appear in help.md. (Caught
|
|
* the inverse: a command lands without docs, so users never discover it.)
|
|
*
|
|
* The shipped slash name is parsed from frontmatter `name:` (which can be
|
|
* either `gsd:foo` or `gsd-foo` — Claude Code surfaces both as `/gsd-foo`),
|
|
* NOT from the filename, because some files (e.g. `ns-context.md`) ship a
|
|
* different slash name (`gsd-context`) than their filename suggests.
|
|
*
|
|
* Also covers `do.md`, the dispatcher invoked at runtime by
|
|
* `/gsd:progress --do`: any `/gsd[-:]<name>` token in its routing table must
|
|
* resolve to a live command, otherwise the dispatcher emits "Unknown command".
|
|
*/
|
|
|
|
const { test, describe } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const ROOT = path.join(__dirname, '..');
|
|
const COMMANDS_DIR = path.join(ROOT, 'commands', 'gsd');
|
|
// After #3039, the canonical command reference is the `--full` mode file.
|
|
// `workflows/help.md` is now a small dispatcher; the bidirectional parity
|
|
// invariant lives with the comprehensive reference body.
|
|
const HELP_MD = path.join(ROOT, 'get-shit-done', 'workflows', 'help', 'modes', 'full.md');
|
|
const DO_MD = path.join(ROOT, 'get-shit-done', 'workflows', 'do.md');
|
|
|
|
function parseFrontmatter(content) {
|
|
const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
if (!match) return null;
|
|
const fields = {};
|
|
for (const line of match[1].split(/\r?\n/)) {
|
|
const fieldMatch = line.match(/^([a-zA-Z0-9_-]+):\s*(.*)$/);
|
|
if (!fieldMatch) continue;
|
|
const value = fieldMatch[2].trim().replace(/^["']|["']$/g, '');
|
|
fields[fieldMatch[1]] = value;
|
|
}
|
|
return fields;
|
|
}
|
|
|
|
/**
|
|
* Returns the set of slash-base-names actually shipped under commands/gsd/.
|
|
* A "slash-base-name" is the part after `/gsd-` — e.g. for frontmatter
|
|
* `name: gsd:foo` or `name: gsd-foo`, the slash-base-name is `foo`.
|
|
*/
|
|
function listShippedSlashBaseNames() {
|
|
const names = new Set();
|
|
for (const entry of fs.readdirSync(COMMANDS_DIR, { withFileTypes: true })) {
|
|
if (!entry.isFile() || !entry.name.endsWith('.md')) continue;
|
|
const content = fs.readFileSync(path.join(COMMANDS_DIR, entry.name), 'utf8');
|
|
const fm = parseFrontmatter(content);
|
|
if (!fm || !fm.name) continue;
|
|
const fmName = fm.name;
|
|
let base = null;
|
|
if (fmName.startsWith('gsd:')) base = fmName.slice(4);
|
|
else if (fmName.startsWith('gsd-')) base = fmName.slice(4);
|
|
if (base && /^[a-z][a-z0-9-]*$/.test(base)) names.add(base);
|
|
}
|
|
return names;
|
|
}
|
|
|
|
function extractSlashReferences(contents) {
|
|
const names = new Set();
|
|
const tokenRe = /\/gsd[:-]([a-z][a-z0-9-]*)/g;
|
|
let match;
|
|
while ((match = tokenRe.exec(contents)) !== null) {
|
|
names.add(match[1]);
|
|
}
|
|
return names;
|
|
}
|
|
|
|
/**
|
|
* For every shipped command with an `argument-hint:` frontmatter entry,
|
|
* collect the `--flag` tokens it advertises. Returns a Map<slashBaseName,
|
|
* Set<flagName>>. Flags are recorded without their leading `--`.
|
|
*/
|
|
function listShippedFlagsByCommand() {
|
|
const out = new Map();
|
|
for (const entry of fs.readdirSync(COMMANDS_DIR, { withFileTypes: true })) {
|
|
if (!entry.isFile() || !entry.name.endsWith('.md')) continue;
|
|
const content = fs.readFileSync(path.join(COMMANDS_DIR, entry.name), 'utf8');
|
|
const fm = parseFrontmatter(content);
|
|
if (!fm || !fm.name || !fm['argument-hint']) continue;
|
|
const fmName = fm.name;
|
|
let base = null;
|
|
if (fmName.startsWith('gsd:')) base = fmName.slice(4);
|
|
else if (fmName.startsWith('gsd-')) base = fmName.slice(4);
|
|
if (!base || !/^[a-z][a-z0-9-]*$/.test(base)) continue;
|
|
const flags = new Set();
|
|
for (const m of fm['argument-hint'].matchAll(/--([a-z][a-z0-9-]*)/g)) {
|
|
flags.add(m[1]);
|
|
}
|
|
if (flags.size) out.set(base, flags);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
describe('Bug #2954: help.md ↔ commands/gsd/ bidirectional parity', () => {
|
|
test('every /gsd[-:]<name> referenced in help.md is a shipped command', () => {
|
|
const helpContents = fs.readFileSync(HELP_MD, 'utf8');
|
|
const referenced = extractSlashReferences(helpContents);
|
|
const shipped = listShippedSlashBaseNames();
|
|
const dangling = [...referenced].filter((n) => !shipped.has(n)).sort();
|
|
assert.deepEqual(
|
|
dangling,
|
|
[],
|
|
`help.md advertises /gsd[-:]<name> commands that are not shipped: ${dangling.join(', ')}`,
|
|
);
|
|
});
|
|
|
|
test('every shipped /gsd[-:]<name> command is documented in help.md', () => {
|
|
const helpContents = fs.readFileSync(HELP_MD, 'utf8');
|
|
const referenced = extractSlashReferences(helpContents);
|
|
const shipped = listShippedSlashBaseNames();
|
|
const undocumented = [...shipped].filter((n) => !referenced.has(n)).sort();
|
|
assert.deepEqual(
|
|
undocumented,
|
|
[],
|
|
`commands shipped under commands/gsd/ with no /gsd[-:]<name> reference in help.md: ${undocumented.join(', ')}`,
|
|
);
|
|
});
|
|
|
|
test('every /gsd[-:]<name> in do.md (live dispatcher) is a shipped command', () => {
|
|
const doContents = fs.readFileSync(DO_MD, 'utf8');
|
|
const referenced = extractSlashReferences(doContents);
|
|
const shipped = listShippedSlashBaseNames();
|
|
const dangling = [...referenced].filter((n) => !shipped.has(n)).sort();
|
|
assert.deepEqual(
|
|
dangling,
|
|
[],
|
|
`do.md routing table references /gsd[-:]<name> that is not shipped: ${dangling.join(', ')}`,
|
|
);
|
|
});
|
|
|
|
test('every --flag in a command\'s argument-hint appears in help.md', () => {
|
|
const helpContents = fs.readFileSync(HELP_MD, 'utf8');
|
|
const flagsByCommand = listShippedFlagsByCommand();
|
|
const gaps = [];
|
|
for (const [command, flags] of flagsByCommand) {
|
|
for (const flag of flags) {
|
|
// Accept `/gsd-<command> --<flag>` (precise) OR a bare `--<flag>` token
|
|
// anywhere in help.md (good enough for shared flags like `--force` that
|
|
// appear under multiple commands' descriptions).
|
|
const preciseDash = `/gsd-${command} --${flag}`;
|
|
const preciseColon = `/gsd:${command} --${flag}`;
|
|
const flagToken = `--${flag}`;
|
|
if (
|
|
!helpContents.includes(preciseDash) &&
|
|
!helpContents.includes(preciseColon) &&
|
|
!helpContents.includes(flagToken)
|
|
) {
|
|
gaps.push(`/gsd:${command} --${flag}`);
|
|
}
|
|
}
|
|
}
|
|
assert.deepEqual(
|
|
gaps.sort(),
|
|
[],
|
|
`commands ship --flag(s) in argument-hint that are absent from help.md: ${gaps.join(', ')}`,
|
|
);
|
|
});
|
|
});
|