peppa/packages/core/src/specs.ts
Асель 328900e254 PEP-66: epics (goals as story labels), tabs Код/Спеки/PR, bug settings in ⋯
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 03:28:34 +05:00

28 lines
1.2 KiB
TypeScript

// «Спеки» tab (PEP-66): what the system can do now — openspec/specs/*/spec.md of the
// project's working copy.
import { existsSync, readdirSync, readFileSync } from "node:fs";
import { join } from "node:path";
import type { Project } from "./projects.ts";
export interface SpecSummary {
/** Capability name: the folder under openspec/specs. */
name: string;
purpose: string;
requirements: number;
text: string;
}
export function parseSpec(name: string, text: string): SpecSummary {
const purpose = text.match(/^## Purpose\s*\n([\s\S]*?)(?=^## |(?![\s\S]))/m)?.[1]?.trim() ?? "";
return { name, purpose: /^TBD\b/.test(purpose) ? "" : purpose, requirements: (text.match(/^### Requirement:/gm) ?? []).length, text };
}
export function listSpecs(project: Pick<Project, "workspacePath">): SpecSummary[] {
const dir = join(project.workspacePath, "openspec", "specs");
if (!existsSync(dir)) return [];
return readdirSync(dir, { withFileTypes: true })
.filter((d) => d.isDirectory() && existsSync(join(dir, d.name, "spec.md")))
.map((d) => parseSpec(d.name, readFileSync(join(dir, d.name, "spec.md"), "utf8")))
.sort((a, b) => a.name.localeCompare(b.name));
}