feat(#972): graphify command cutover — first capability owning a command family (ADR-857 phase 4d-impl-2) (#975)
Migrate graphify into a Capability that owns its `graphify` command family, dispatched via the registry (#961 mechanism) instead of a hardcoded case. graphify is now an enable/disable plug-in. - src/graphify-command-router.cts: routeGraphifyCommand (standard route*Command), reproduces the removed case EXACTLY (query +--budget, status, diff, build, hidden build snapshot, usage/unknown errors); injectable _graphify test seam. - capabilities/graphify/capability.json: role feature, tier:full, skills:[graphify], config:{graphify.enabled default false}, commands:[{family:graphify, module, router:routeGraphifyCommand}]. - removed case 'graphify' from gsd-tools.cjs; graphify now flows default -> dispatchCapabilityCommand -> commandFamilies.graphify -> router. - regenerated registry (commandFamilies/bySkill/configSchema/profileMembership/ capabilityClusters for graphify); tier:full keeps 4c install/surface a no-op. Equivalence-proven: 8 recording-mock unit tests assert the exact fn+args per subcommand (budget, snapshot-vs-build); 9 subprocess tests assert distinguishing output shapes; existing graphify tests pass unchanged through the new path. Surfaced (not silently accepted): the pre-existing --budget-no-value NaN no-op quirk, preserved for equivalence, filed separately. Closes #972 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
89
src/graphify-command-router.cts
Normal file
89
src/graphify-command-router.cts
Normal file
@@ -0,0 +1,89 @@
|
||||
'use strict';
|
||||
/**
|
||||
* Graphify command router — CLI subcommand dispatcher for `gsd-tools graphify`.
|
||||
*
|
||||
* ADR-959 (phase 4d-impl-2) pilot: first real capability command cutover.
|
||||
* Extracted from the hardcoded `case 'graphify':` arm in gsd-tools.cjs.
|
||||
* Behaviour is preserved byte-for-behaviour from the prior inline case;
|
||||
* the dispatch path now flows: default → dispatchCapabilityCommand →
|
||||
* require(graphify-command-router.cjs) → routeGraphifyCommand.
|
||||
*
|
||||
* Router signature: { args, cwd, raw, error } — identical to the 12 existing
|
||||
* host routers. No new handler/arg convention; the capability registry
|
||||
* discovers this router by name.
|
||||
*
|
||||
* Arg indexing (preserved exactly from the original case):
|
||||
* args[0] = 'graphify' (family — matched by dispatchCapabilityCommand)
|
||||
* args[1] = subcommand (query | status | diff | build)
|
||||
* args[2] = term (query) | 'snapshot' (build snapshot)
|
||||
* args.indexOf('--budget') + 1 = budget value
|
||||
*
|
||||
* Test seam: pass `_graphify` in the options object to inject a recording mock
|
||||
* instead of the real graphify module. The `_`-prefix follows the repo's
|
||||
* established seam convention (see other routers). Production callers omit it.
|
||||
*/
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
import graphify = require('./graphify.cjs');
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
import core = require('./core.cjs');
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
import io = require('./io.cjs');
|
||||
|
||||
const { ERROR_REASON } = io;
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
interface GraphifyModule {
|
||||
graphifyQuery(cwd: string, term: string, opts: { budget: number | null }): unknown;
|
||||
graphifyStatus(cwd: string): unknown;
|
||||
graphifyDiff(cwd: string): unknown;
|
||||
graphifyBuild(cwd: string): unknown;
|
||||
writeSnapshot(cwd: string): unknown;
|
||||
}
|
||||
|
||||
interface RouteGraphifyCommandOptions {
|
||||
args: string[];
|
||||
cwd: string;
|
||||
raw: boolean;
|
||||
error: (message: string, reason?: string) => void;
|
||||
/** Test seam: inject a mock graphify module. Defaults to the real module. */
|
||||
_graphify?: GraphifyModule;
|
||||
}
|
||||
|
||||
// ─── Implementation ───────────────────────────────────────────────────────────
|
||||
|
||||
function routeGraphifyCommand({ args, cwd, raw, error, _graphify }: RouteGraphifyCommandOptions): void {
|
||||
const subcommand = args[1];
|
||||
const g: GraphifyModule = _graphify ?? graphify;
|
||||
|
||||
if (subcommand === 'query') {
|
||||
const term = args[2];
|
||||
if (!term) {
|
||||
error('Usage: gsd-tools graphify query <term>', ERROR_REASON.USAGE);
|
||||
return;
|
||||
}
|
||||
const budgetIdx = args.indexOf('--budget');
|
||||
const budget = budgetIdx !== -1 ? parseInt(args[budgetIdx + 1], 10) : null;
|
||||
core.output(g.graphifyQuery(cwd, term, { budget }), raw);
|
||||
} else if (subcommand === 'status') {
|
||||
core.output(g.graphifyStatus(cwd), raw);
|
||||
} else if (subcommand === 'diff') {
|
||||
core.output(g.graphifyDiff(cwd), raw);
|
||||
} else if (subcommand === 'build') {
|
||||
if (args[2] === 'snapshot') {
|
||||
core.output(g.writeSnapshot(cwd), raw);
|
||||
} else {
|
||||
core.output(g.graphifyBuild(cwd), raw);
|
||||
}
|
||||
} else {
|
||||
error(
|
||||
'Unknown graphify subcommand. Available: build, query, status, diff',
|
||||
ERROR_REASON.SDK_UNKNOWN_COMMAND,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export = {
|
||||
routeGraphifyCommand,
|
||||
};
|
||||
Reference in New Issue
Block a user