Skip to content

⛰️ LifeOS — The AI-powered Life Operating System that helps you hill climb to wherever you're going.

feat: Implement PRD creation — automatic via hook + CLI bootstrapping (closes #676)

Daniel Miessler7ae82dd22803
diff --git a/Releases/v3.0/.claude/hooks/AutoWorkCreation.hook.ts b/Releases/v3.0/.claude/hooks/AutoWorkCreation.hook.ts
index 39905e03..43459d0e 100755
--- a/Releases/v3.0/.claude/hooks/AutoWorkCreation.hook.ts
+++ b/Releases/v3.0/.claude/hooks/AutoWorkCreation.hook.ts
@@ -25,6 +25,7 @@
import { mkdirSync, existsSync, readFileSync, writeFileSync, symlinkSync, unlinkSync, lstatSync } from 'fs';
import { join } from 'path';
import { getPSTComponents, getISOTimestamp } from './lib/time';
+import { generatePRDTemplate, generatePRDFilename } from './lib/prd-template';
interface HookInput {
session_id: string;
prompt?: string;
@@ -38,6 +39,7 @@ interface CurrentWork {
task_title: string;
task_count: number;
created_at: string;
+ prd_path?: string;
}
interface PromptClassification {
@@ -141,7 +143,7 @@ function createTaskDirectory(
title: string,
effort: string,
prompt: string
-): string {
+): { taskDirName: string; prdPath: string } {
const taskId = String(taskNumber).padStart(3, '0');
const taskSlug = slugify(title);
const taskDirName = `${taskId}_${taskSlug}`;
@@ -213,6 +215,17 @@ _Important observations during execution..._
};
writeFileSync(join(taskPath, 'ISC.json'), JSON.stringify(isc, null, 2), 'utf-8');
+ // Task PRD file — stub for model to populate during Algorithm phases
+ const prdSlug = taskSlug.substring(0, 40);
+ const prdFilename = generatePRDFilename(prdSlug);
+ const prdContent = generatePRDTemplate({
+ title,
+ slug: prdSlug,
+ effortLevel: effort,
+ prompt,
+ });
+ writeFileSync(join(taskPath, prdFilename), prdContent, 'utf-8');
+
// Update 'current' symlink
const currentLink = join(sessionPath, 'tasks', 'current');
try {
@@ -223,7 +236,8 @@ _Important observations during execution..._
symlinkSync(taskDirName, currentLink);
console.error(`[AutoWork] Created task: ${taskPath}`);
- return taskDirName;
+ console.error(`[AutoWork] Created PRD: ${prdFilename}`);
+ return { taskDirName, prdPath: join(taskPath, prdFilename) };
}
/**
@@ -284,7 +298,7 @@ async function main() {
const sessionDirName = generateSessionDirName(title);
const sessionPath = createSessionDirectory(sessionDirName, sessionId, title);
- const taskDirName = createTaskDirectory(
+ const { taskDirName, prdPath } = createTaskDirectory(
sessionPath,
1,
title,
@@ -299,6 +313,7 @@ async function main() {
task_title: title,
task_count: 1,
created_at: getISOTimestamp(),
+ prd_path: prdPath,
};
writeCurrentWork(currentWork);
@@ -309,7 +324,7 @@ async function main() {
const newTaskNumber = currentWork!.task_count + 1;
const title = classification.title || prompt.substring(0, 50);
- const taskDirName = createTaskDirectory(
+ const { taskDirName, prdPath } = createTaskDirectory(
sessionPath,
newTaskNumber,
title,
@@ -320,6 +335,7 @@ async function main() {
currentWork!.current_task = taskDirName;
currentWork!.task_title = title;
currentWork!.task_count = newTaskNumber;
+ currentWork!.prd_path = prdPath;
writeCurrentWork(currentWork!);
console.error(`[AutoWork] New task in session: ${taskDirName}`);
diff --git a/Releases/v3.0/.claude/hooks/lib/prd-template.ts b/Releases/v3.0/.claude/hooks/lib/prd-template.ts
new file mode 100644
index 00000000..b97ccbfd
--- /dev/null
+++ b/Releases/v3.0/.claude/hooks/lib/prd-template.ts
@@ -0,0 +1,113 @@
+/**
+ * PRD Template Generator
+ *
+ * Shared PRD template used by AutoWorkCreation hook and algorithm.ts CLI.
+ * Generates PRD files matching the frontmatter schema expected by algorithm.ts readPRD().
+ *
+ * Used by: AutoWorkCreation.hook.ts, algorithm.ts
+ */
+
+interface PRDOptions {
+ title: string;
+ slug: string;
+ effortLevel?: string;
+ mode?: "interactive" | "loop";
+ prompt?: string;
+}
+
+/**
+ * Generate a PRD filename: PRD-{YYYYMMDD}-{slug}.md
+ */
+export function generatePRDFilename(slug: string): string {
+ const now = new Date();
+ const y = now.getFullYear();
+ const m = String(now.getMonth() + 1).padStart(2, "0");
+ const d = String(now.getDate()).padStart(2, "0");
+ return `PRD-${y}${m}${d}-${slug}.md`;
+}
+
+/**
+ * Generate a PRD ID: PRD-{YYYYMMDD}-{slug}
+ */
+export function generatePRDId(slug: string): string {
+ const now = new Date();
+ const y = now.getFullYear();
+ const m = String(now.getMonth() + 1).padStart(2, "0");
+ const d = String(now.getDate()).padStart(2, "0");
+ return `PRD-${y}${m}${d}-${slug}`;
+}
+
+/**
+ * Generate a complete PRD file with frontmatter and sections.
+ * Frontmatter fields match algorithm.ts readPRD() parser exactly.
+ */
+export function generatePRDTemplate(opts: PRDOptions): string {
+ const today = new Date().toISOString().split("T")[0];
+ const id = generatePRDId(opts.slug);
+ const effort = opts.effortLevel || "Standard";
+ const mode = opts.mode || "interactive";
+ const promptSection = opts.prompt
+ ? `### Problem Space\n${opts.prompt.substring(0, 500)}\n`
+ : `### Problem Space\n_To be populated during OBSERVE phase._\n`;
+
+ return `---
+prd: true
+id: ${id}
+status: DRAFT
+mode: ${mode}
+effort_level: ${effort}
+created: ${today}
+updated: ${today}
+iteration: 0
+maxIterations: 128
+loopStatus: null
+last_phase: null
+failing_criteria: []
+verification_summary: "0/0"
+parent: null
+children: []
+---
+
+# ${opts.title}
+
+> _To be populated: what this achieves and why it matters._
+
+## STATUS
+
+| What | State |
+|------|-------|
+| Progress | 0/0 criteria passing |
+| Phase | DRAFT |
+| Next action | OBSERVE phase — create ISC |
+| Blocked by | nothing |
+
+## CONTEXT
+
+${promptSection}
+### Key Files
+_To be populated during exploration._
+
+### Constraints
+_To be populated during OBSERVE/PLAN._
+
+### Decisions Made
+_None yet._
+
+## PLAN
+
+_To be populated during PLAN phase._
+
+## IDEAL STATE CRITERIA (Verification Criteria)
+
+_Criteria will be added during OBSERVE phase via TaskCreate._
+_Format: ISC-C{N}: {8-12 word state criterion} | Verify: {method}_
+
+## DECISIONS
+
+_Non-obvious technical decisions logged here during BUILD/EXECUTE._
+
+## LOG
+
+_Session entries appended during LEARN phase._
+`;
+}
diff --git a/Releases/v3.0/.claude/skills/PAI/Tools/algorithm.ts b/Releases/v3.0/.claude/skills/PAI/Tools/algorithm.ts
index 71890304..a69cd609 100644
--- a/Releases/v3.0/.claude/skills/PAI/Tools/algorithm.ts
+++ b/Releases/v3.0/.claude/skills/PAI/Tools/algorithm.ts
@@ -22,6 +22,7 @@
* USAGE:
* algorithm -m loop -p <PRD> [-n 128] Autonomous loop execution
* algorithm -m interactive -p <PRD> Interactive claude session
+ * algorithm new -t <title> [-e <effort>] Create a new PRD
* algorithm status [-p <PRD>] Show PRD status
* algorithm pause -p <PRD> Pause a running loop
* algorithm resume -p <PRD> Resume a paused loop
@@ -31,6 +32,7 @@
* algorithm -m loop -p ~/.claude/MEMORY/WORK/auth/PRD-20260207-auth.md
* algorithm -m loop -p /path/to/project/.prd/PRD-20260213-feature.md -n 20
* algorithm -m interactive -p PRD-20260213-surface
+ * algorithm new -t "Build auth system" -e Extended
* algorithm status
* algorithm pause -p PRD-20260207-auth
*/
@@ -48,7 +50,7 @@ const ALGORITHMS_DIR = join(BASE_DIR, "MEMORY", "STATE", "algorithms");
const SESSION_NAMES_PATH = join(BASE_DIR, "MEMORY", "STATE", "session-names.json");
const PROJECTS_DIR = process.env.PROJECTS_DIR || join(HOME, "Projects");
const VOICE_URL = "http://localhost:8888/notify";
-const VOICE_ID = "YOUR_VOICE_ID_HERE";
+const VOICE_ID = "fTtv3eikoepIosk8dTZ5";
// ─── Types ──────────────────────────────────────────────────────────────────
@@ -133,19 +135,21 @@ interface LoopAlgorithmState {
// ─── CLI Argument Parsing ────────────────────────────────────────────────────
interface ParsedArgs {
- subcommand: string | null; // status, pause, resume, stop, or null (= run)
+ subcommand: string | null; // status, pause, resume, stop, new, or null (= run)
mode: string | null; // loop, interactive
prdPath: string | null; // -p value
maxIterations: number | null; // -n value
agentCount: number; // -a value (default 1)
+ title: string | null; // -t value (for 'new' subcommand)
+ effortLevel: string | null; // -e value (for 'new' subcommand)
}
function parseArgs(argv: string[]): ParsedArgs {
const args = argv.slice(2);
- const result: ParsedArgs = { subcommand: null, mode: null, prdPath: null, maxIterations: null, agentCount: 1 };
+ const result: ParsedArgs = { subcommand: null, mode: null, prdPath: null, maxIterations: null, agentCount: 1, title: null, effortLevel: null };
// Check for subcommand (first arg that isn't a flag)
- const subcommands = ["status", "pause", "resume", "stop"];
+ const subcommands = ["status", "pause", "resume", "stop", "new"];
if (args.length > 0 && subcommands.includes(args[0])) {
result.subcommand = args[0];
}
@@ -161,6 +165,10 @@ function parseArgs(argv: string[]): ParsedArgs {
result.maxIterations = parseInt(args[++i], 10);
} else if ((arg === "-a" || arg === "--agents") && i + 1 < args.length) {
result.agentCount = parseInt(args[++i], 10);
+ } else if ((arg === "-t" || arg === "--title") && i + 1 < args.length) {
+ result.title = args[++i];
+ } else if ((arg === "-e" || arg === "--effort") && i + 1 < args.length) {
+ result.effortLevel = args[++i];
} else if (arg === "-h" || arg === "--help") {
printHelp();
process.exit(0);
@@ -182,6 +190,7 @@ function printHelp(): void {
Usage:
algorithm -m <mode> -p <PRD> [-n N] [-a N] Run the Algorithm against a PRD
+ algorithm new -t <title> [-e <effort>] [-p <dir>] Create a new PRD
algorithm status [-p <PRD>] Show PRD status
algorithm pause -p <PRD> Pause a running loop
algorithm resume -p <PRD> Resume a paused loop
@@ -193,9 +202,11 @@ Modes:
Flags:
-m, --mode <mode> Execution mode: loop or interactive
- -p, --prd <path> PRD file path or PRD ID
+ -p, --prd <path> PRD file path or PRD ID (or output dir for 'new')
-n, --max <N> Max iterations (loop mode only, default: 128)
-a, --agents <N> Parallel agents per iteration (1-16, default: 1)
+ -t, --title <title> PRD title (required for 'new')
+ -e, --effort <level> Effort level: Standard, Extended, etc. (default: Standard)
-h, --help Show this help
PRD Resolution:
@@ -204,6 +215,8 @@ PRD Resolution:
Project path /path/to/project/.prd/PRD-20260213-feature.md
Examples:
+ algorithm new -t "Build authentication system" -e Extended
+ algorithm new -t "Fix login bug" -p ./project/.prd/
algorithm -m loop -p PRD-20260213-surface -n 20
algorithm -m loop -p PRD-20260213-surface -n 20 -a 4 # 4 parallel agents
algorithm -m interactive -p PRD-20260213-surface
@@ -1128,21 +1141,135 @@ function runInteractive(prdPath: string): void {
});
}
+// ─── PRD Creation ───────────────────────────────────────────────────────────
+
+function createNewPRD(title: string, effortLevel: string = "Standard", outputDir?: string): string {
+ const slug = title
+ .toLowerCase()
+ .replace(/[^a-z0-9\s-]/g, "")
+ .replace(/\s+/g, "-")
+ .replace(/-+/g, "-")
+ .substring(0, 40)
+ .replace(/-$/, "") || "task";
+
+ const now = new Date();
+ const y = now.getFullYear();
+ const m = String(now.getMonth() + 1).padStart(2, "0");
+ const d = String(now.getDate()).padStart(2, "0");
+ const today = `${y}-${m}-${d}`;
+ const id = `PRD-${y}${m}${d}-${slug}`;
+ const filename = `${id}.md`;
+
+ // Determine output directory
+ let targetDir: string;
+ if (outputDir) {
+ targetDir = resolve(outputDir);
+ } else {
+ // Default: create in MEMORY/WORK session directory
+ const sessionSlug = `${y}${m}${d}-${String(now.getHours()).padStart(2, "0")}${String(now.getMinutes()).padStart(2, "0")}${String(now.getSeconds()).padStart(2, "0")}_${slug}`;
+ targetDir = join(BASE_DIR, "MEMORY", "WORK", sessionSlug);
+ }
+ mkdirSync(targetDir, { recursive: true });
+
+ const prdContent = `---
+prd: true
+id: ${id}
+status: DRAFT
+mode: interactive
+effort_level: ${effortLevel}
+created: ${today}
+updated: ${today}
+iteration: 0
+maxIterations: 128
+loopStatus: null
+last_phase: null
+failing_criteria: []
+verification_summary: "0/0"
+parent: null
+children: []
+---
+
+# ${title}
+
+> _To be populated: what this achieves and why it matters._
+
+## STATUS
+
+| What | State |
+|------|-------|
+| Progress | 0/0 criteria passing |
+| Phase | DRAFT |
+| Next action | OBSERVE phase — create ISC |
+| Blocked by | nothing |
+
+## CONTEXT
+
+### Problem Space
+_To be populated during OBSERVE phase._
+
+### Key Files
+_To be populated during exploration._
+
+### Constraints
+_To be populated during OBSERVE/PLAN._
+
+### Decisions Made
+_None yet._
+
+## PLAN
+
+_To be populated during PLAN phase._
+
+## IDEAL STATE CRITERIA (Verification Criteria)
+
+_Criteria will be added during OBSERVE phase via TaskCreate._
+_Format: ISC-C{N}: {8-12 word state criterion} | Verify: {method}_
+
+## DECISIONS
+
+_Non-obvious technical decisions logged here during BUILD/EXECUTE._
+
+## LOG
+
+_Session entries appended during LEARN phase._
+`;
+
+ const fullPath = join(targetDir, filename);
+ writeFileSync(fullPath, prdContent, "utf-8");
+ return fullPath;
+}
+
// ─── PRD Discovery ──────────────────────────────────────────────────────────
function findAllPRDs(): string[] {
const files: string[] = [];
- // 1. Scan MEMORY/WORK directory
+ // 1. Scan MEMORY/WORK directory (session-level and task-level PRDs)
const workDir = join(BASE_DIR, "MEMORY", "WORK");
if (existsSync(workDir)) {
try {
- for (const sub of readdirSync(workDir)) {
- const subPath = join(workDir, sub);
+ for (const session of readdirSync(workDir)) {
+ const sessionPath = join(workDir, session);
try {
- for (const f of readdirSync(subPath)) {
+ // Session-level PRDs
+ for (const f of readdirSync(sessionPath)) {
if (f.startsWith("PRD-") && f.endsWith(".md")) {
- files.push(join(subPath, f));
+ files.push(join(sessionPath, f));
+ }
+ }
+ // Task-level PRDs (WORK/{session}/tasks/{task}/PRD-*.md)
+ const tasksDir = join(sessionPath, "tasks");
+ if (existsSync(tasksDir)) {
+ for (const task of readdirSync(tasksDir)) {
+ if (task === "current") continue; // skip symlink
+ const taskPath = join(tasksDir, task);
+ try {
+ for (const f of readdirSync(taskPath)) {
+ if (f.startsWith("PRD-") && f.endsWith(".md")) {
+ files.push(join(taskPath, f));
+ }
+ }
+ } catch { /* not a directory */ }
}
}
} catch { /* not a directory */ }
@@ -1297,6 +1424,17 @@ if (parsed.subcommand) {
case "status":
showStatus(prdRef ? resolvePRDPath(prdRef) : undefined);
break;
+ case "new": {
+ if (!parsed.title) {
+ console.error("Usage: algorithm new -t <title> [-e <effort>] [-p <output-dir>]");
+ process.exit(1);
+ }
+ const prdPath = createNewPRD(parsed.title, parsed.effortLevel || "Standard", prdRef || undefined);
+ console.log(`\x1b[32m✓\x1b[0m Created PRD: ${prdPath}`);
+ console.log(`\n Run with: algorithm -m interactive -p ${prdPath}`);
+ console.log(` Or loop: algorithm -m loop -p ${prdPath} -n 20`);
+ break;
+ }
case "pause":
if (!prdRef) { console.error("Usage: algorithm pause -p <PRD>"); process.exit(1); }
pauseLoop(resolvePRDPath(prdRef));