feat(sdk): add --ws flag for workstream-aware execution (#1884)

Add a --ws <name> CLI flag that routes all .planning/ paths to
.planning/workstreams/<name>/, enabling multi-workstream projects
without directory conflicts.

Changes:
- workstream-utils.ts: validateWorkstreamName() and relPlanningPath() helpers
- cli.ts: Parse --ws flag with input validation
- types.ts: Add workstream? to GSDOptions
- gsd-tools.ts: Inject --ws <name> into all gsd-tools.cjs invocations
- config.ts: Resolve workstream-aware config path with root fallback
- context-engine.ts: Constructor accepts workstream via positional param
- index.ts: GSD class propagates workstream to all subsystems
- ws-flag.test.ts: 22 tests covering all workstream functionality

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Tom Boucher
2026-04-11 09:33:34 -04:00
parent 72e789432e
commit 868e3d488f
8 changed files with 369 additions and 11 deletions

View File

@@ -7,6 +7,7 @@
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
import { relPlanningPath } from './workstream-utils.js';
// ─── Types ───────────────────────────────────────────────────────────────────
@@ -99,15 +100,25 @@ export const CONFIG_DEFAULTS: GSDConfig = {
* Returns full defaults when file is missing or empty.
* Throws on malformed JSON with a helpful error message.
*/
export async function loadConfig(projectDir: string): Promise<GSDConfig> {
const configPath = join(projectDir, '.planning', 'config.json');
export async function loadConfig(projectDir: string, workstream?: string): Promise<GSDConfig> {
const configPath = join(projectDir, relPlanningPath(workstream), 'config.json');
const rootConfigPath = join(projectDir, '.planning', 'config.json');
let raw: string;
try {
raw = await readFile(configPath, 'utf-8');
} catch {
// File missing — normal for new projects
return structuredClone(CONFIG_DEFAULTS);
// If workstream config missing, fall back to root config
if (workstream) {
try {
raw = await readFile(rootConfigPath, 'utf-8');
} catch {
return structuredClone(CONFIG_DEFAULTS);
}
} else {
// File missing — normal for new projects
return structuredClone(CONFIG_DEFAULTS);
}
}
const trimmed = raw.trim();