fix(sdk): register init.ingest-docs handler and add registry drift guard (#2442)
The ingest-docs workflow called `gsd-sdk query init.ingest-docs` with a
fallback to `init.default` — neither was registered in createRegistry(),
so the workflow proceeded with `{}` and tried to parse project_exists,
planning_exists, has_git, and project_path from empty.
- Add initIngestDocs handler; register dotted + space aliases
- Simplify workflow call; drop broken fallback
- Repo-wide drift guard scans commands/, agents/, get-shit-done/,
hooks/, bin/, scripts/, docs/ for `gsd-sdk query <cmd>` and fails
on any reference with no registered handler (file:line citations)
- Unit tests for the new handler
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -44,6 +44,7 @@ import {
|
||||
initExecutePhase, initPlanPhase, initNewMilestone, initQuick,
|
||||
initResume, initVerifyWork, initPhaseOp, initTodos, initMilestoneOp,
|
||||
initMapCodebase, initNewWorkspace, initListWorkspaces, initRemoveWorkspace,
|
||||
initIngestDocs,
|
||||
} from './init.js';
|
||||
import { initNewProject, initProgress, initManager } from './init-complex.js';
|
||||
import { agentSkills } from './skills.js';
|
||||
@@ -338,6 +339,7 @@ export function createRegistry(eventStream?: GSDEventStream): QueryRegistry {
|
||||
registry.register('init.new-workspace', initNewWorkspace);
|
||||
registry.register('init.list-workspaces', initListWorkspaces);
|
||||
registry.register('init.remove-workspace', initRemoveWorkspace);
|
||||
registry.register('init.ingest-docs', initIngestDocs);
|
||||
// Space-delimited aliases for CJS compatibility
|
||||
registry.register('init execute-phase', initExecutePhase);
|
||||
registry.register('init plan-phase', initPlanPhase);
|
||||
@@ -352,6 +354,7 @@ export function createRegistry(eventStream?: GSDEventStream): QueryRegistry {
|
||||
registry.register('init new-workspace', initNewWorkspace);
|
||||
registry.register('init list-workspaces', initListWorkspaces);
|
||||
registry.register('init remove-workspace', initRemoveWorkspace);
|
||||
registry.register('init ingest-docs', initIngestDocs);
|
||||
|
||||
// Complex init handlers
|
||||
registry.register('init.new-project', initNewProject);
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
initNewWorkspace,
|
||||
initListWorkspaces,
|
||||
initRemoveWorkspace,
|
||||
initIngestDocs,
|
||||
} from './init.js';
|
||||
|
||||
let tmpDir: string;
|
||||
@@ -498,3 +499,24 @@ describe('initRemoveWorkspace', () => {
|
||||
expect(data.error).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('initIngestDocs', () => {
|
||||
it('returns flat JSON with ingest-docs branching fields', async () => {
|
||||
const result = await initIngestDocs([], tmpDir);
|
||||
const data = result.data as Record<string, unknown>;
|
||||
expect(data.project_exists).toBe(false);
|
||||
expect(data.planning_exists).toBe(true);
|
||||
expect(typeof data.has_git).toBe('boolean');
|
||||
expect(data.project_path).toBe('.planning/PROJECT.md');
|
||||
expect(data.commit_docs).toBeDefined();
|
||||
expect(data.project_root).toBe(tmpDir);
|
||||
});
|
||||
|
||||
it('reports project_exists true when PROJECT.md is present', async () => {
|
||||
await writeFile(join(tmpDir, '.planning', 'PROJECT.md'), '# project');
|
||||
const result = await initIngestDocs([], tmpDir);
|
||||
const data = result.data as Record<string, unknown>;
|
||||
expect(data.project_exists).toBe(true);
|
||||
expect(data.planning_exists).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -950,6 +950,26 @@ export const initRemoveWorkspace: QueryHandler = async (args, _projectDir) => {
|
||||
return { data: result };
|
||||
};
|
||||
|
||||
// ─── initIngestDocs ───────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Init handler for ingest-docs workflow.
|
||||
* Mirrors `initResume` shape but without current-agent-id lookup — the
|
||||
* ingest-docs workflow reads `project_exists`, `planning_exists`, `has_git`,
|
||||
* and `project_path` to branch between new-project vs merge-milestone modes.
|
||||
*/
|
||||
export const initIngestDocs: QueryHandler = async (_args, projectDir) => {
|
||||
const config = await loadConfig(projectDir);
|
||||
const result: Record<string, unknown> = {
|
||||
project_exists: pathExists(projectDir, '.planning/PROJECT.md'),
|
||||
planning_exists: pathExists(projectDir, '.planning'),
|
||||
has_git: pathExists(projectDir, '.git'),
|
||||
project_path: '.planning/PROJECT.md',
|
||||
commit_docs: config.commit_docs,
|
||||
};
|
||||
return { data: withProjectRoot(projectDir, result, config as Record<string, unknown>) };
|
||||
};
|
||||
|
||||
// ─── docsInit ────────────────────────────────────────────────────────────
|
||||
|
||||
export const docsInit: QueryHandler = async (_args, projectDir) => {
|
||||
|
||||
Reference in New Issue
Block a user