Files
msd-core/get-shit-done/bin/lib/phases-command-router.cjs

51 lines
2.0 KiB
JavaScript

'use strict';
const { PHASES_SUBCOMMANDS } = require('./command-aliases.cjs');
const { routeCjsCommandFamily } = require('./cjs-command-router-adapter.cjs');
/**
* Manifest-backed phases subcommand router.
* Keeps gsd-tools.cjs thin while preserving current CJS semantics.
*
* Phase 6: phases.list and phases.clear are dispatched via executeForCjs when
* the SDK is available. CJS fallback retained when:
* - GSD_WORKSTREAM is active (workstream-scoped requests fall through to CJS).
* - SDK is unavailable (build not present).
*
* SDK-only (not in CJS router, treated as unknown):
* - archive: `phases archive` is SDK-only (`phases.archive` handler in SDK
* query registry). CJS `gsd-tools phases` intentionally supports list/clear only.
* `archive` is excluded from the subcommands list so it falls through to the
* "unknown subcommand" error path (matching pre-Phase 6 behavior).
*
* CJS-only subcommands: none.
*/
function routePhasesCommand({ phase, milestone, args, cwd, raw, error }) {
routeCjsCommandFamily({
args,
// Exclude 'archive' — it's SDK-only and not supported in CJS. Excluding
// from this list causes it to hit the unknownMessage path, preserving the
// pre-Phase 6 error message for callers that pass 'archive'.
subcommands: PHASES_SUBCOMMANDS.filter((s) => s !== 'archive'),
error,
unknownMessage: (_subcommand, available) => `Unknown phases subcommand. Available: ${available.join(', ')}`,
handlers: {
list: () => {
const typeIndex = args.indexOf('--type');
const phaseIndex = args.indexOf('--phase');
const options = {
type: typeIndex !== -1 ? args[typeIndex + 1] : null,
phase: phaseIndex !== -1 ? args[phaseIndex + 1] : null,
includeArchived: args.includes('--include-archived'),
};
phase.cmdPhasesList(cwd, options, raw);
},
clear: () => milestone.cmdPhasesClear(cwd, raw, args.slice(2)),
},
});
}
module.exports = {
routePhasesCommand,
};