feat(sdk): Phase 1 typed query foundation (gsd-sdk query) (#2118)

* feat(sdk): add typed query foundation and gsd-sdk query (Phase 1)

Add sdk/src/query registry and handlers with tests, GSDQueryError, CLI query wiring, and supporting type/tool-scoping hooks. Update CHANGELOG. Vitest 4 constructor mock fixes in milestone-runner tests.

Made-with: Cursor

* chore: gitignore .cursor for local-only Cursor assets

Made-with: Cursor

* fix(sdk): harden query layer for PR review (paths, locks, CLI, ReDoS)

- resolvePathUnderProject: realpath + relative containment for frontmatter and key_links

- commitToSubrepo: path checks + sanitizeCommitMessage

- statePlannedPhase: readModifyWriteStateMd (lock); MUTATION_COMMANDS + events

- key_links: regexForKeyLinkPattern length/ReDoS guard; phase dirs: reject .. and separators

- gsd-sdk: strip --pick before parseArgs; strict parser; QueryRegistry.commands()

- progress: static GSDError import; tests updated

Made-with: Cursor

* feat(sdk): query follow-up — tests, QUERY-HANDLERS, registry, locks, intel depth

Made-with: Cursor

* docs(sdk): use ASCII punctuation in QUERY-HANDLERS.md

Made-with: Cursor
This commit is contained in:
Rezolv
2026-04-12 18:15:04 -04:00
committed by GitHub
parent 66a5f939b0
commit 6f79b1dd5e
36 changed files with 848 additions and 142 deletions

View File

@@ -17,7 +17,9 @@
* ```
*/
import { join } from 'node:path';
import { join, relative, resolve, isAbsolute, normalize } from 'node:path';
import { realpath } from 'node:fs/promises';
import { GSDError, ErrorClassification } from '../errors.js';
// ─── Types ──────────────────────────────────────────────────────────────────
@@ -322,3 +324,30 @@ export function planningPaths(projectDir: string): PlanningPaths {
requirements: toPosixPath(join(base, 'REQUIREMENTS.md')),
};
}
// ─── resolvePathUnderProject ───────────────────────────────────────────────
/**
* Resolve a user-supplied path against the project and ensure it cannot escape
* the real project root (prefix checks are insufficient; symlinks are handled
* via realpath).
*
* @param projectDir - Project root directory
* @param userPath - Relative or absolute path from user input
* @returns Canonical resolved path within the project
*/
export async function resolvePathUnderProject(projectDir: string, userPath: string): Promise<string> {
const projectReal = await realpath(projectDir);
const candidate = isAbsolute(userPath) ? normalize(userPath) : resolve(projectReal, userPath);
let realCandidate: string;
try {
realCandidate = await realpath(candidate);
} catch {
realCandidate = candidate;
}
const rel = relative(projectReal, realCandidate);
if (rel.startsWith('..') || (isAbsolute(rel) && rel.length > 0)) {
throw new GSDError('path escapes project directory', ErrorClassification.Validation);
}
return realCandidate;
}