28 lines
1.2 KiB
TypeScript
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));
|
|
}
|