pi-gsd 2.0.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dist/pi-gsd-hooks.js +1533 -0
  2. package/dist/pi-gsd-tools.js +53 -52
  3. package/package.json +3 -5
  4. package/.gsd/extensions/pi-gsd-hooks.ts +0 -973
  5. package/src/cli.ts +0 -644
  6. package/src/commands/base.ts +0 -67
  7. package/src/commands/commit.ts +0 -22
  8. package/src/commands/config.ts +0 -71
  9. package/src/commands/frontmatter.ts +0 -51
  10. package/src/commands/index.ts +0 -76
  11. package/src/commands/init.ts +0 -43
  12. package/src/commands/milestone.ts +0 -37
  13. package/src/commands/phase.ts +0 -92
  14. package/src/commands/progress.ts +0 -71
  15. package/src/commands/roadmap.ts +0 -40
  16. package/src/commands/scaffold.ts +0 -19
  17. package/src/commands/state.ts +0 -102
  18. package/src/commands/template.ts +0 -52
  19. package/src/commands/verify.ts +0 -70
  20. package/src/commands/workstream.ts +0 -98
  21. package/src/commands/wxp.ts +0 -65
  22. package/src/lib/commands.ts +0 -1040
  23. package/src/lib/config.ts +0 -385
  24. package/src/lib/core.ts +0 -1167
  25. package/src/lib/frontmatter.ts +0 -462
  26. package/src/lib/init.ts +0 -517
  27. package/src/lib/milestone.ts +0 -290
  28. package/src/lib/model-profiles.ts +0 -272
  29. package/src/lib/phase.ts +0 -1012
  30. package/src/lib/profile-output.ts +0 -237
  31. package/src/lib/profile-pipeline.ts +0 -556
  32. package/src/lib/roadmap.ts +0 -378
  33. package/src/lib/schemas.ts +0 -290
  34. package/src/lib/security.ts +0 -176
  35. package/src/lib/state.ts +0 -1175
  36. package/src/lib/template.ts +0 -246
  37. package/src/lib/uat.ts +0 -289
  38. package/src/lib/verify.ts +0 -879
  39. package/src/lib/workstream.ts +0 -524
  40. package/src/output.ts +0 -45
  41. package/src/schemas/pi-gsd-settings.schema.json +0 -80
  42. package/src/schemas/wxp.xsd +0 -619
  43. package/src/schemas/wxp.zod.ts +0 -318
  44. package/src/wxp/__tests__/arguments.test.ts +0 -86
  45. package/src/wxp/__tests__/conditions.test.ts +0 -106
  46. package/src/wxp/__tests__/executor.test.ts +0 -95
  47. package/src/wxp/__tests__/helpers.ts +0 -26
  48. package/src/wxp/__tests__/integration.test.ts +0 -166
  49. package/src/wxp/__tests__/new-features.test.ts +0 -222
  50. package/src/wxp/__tests__/parser.test.ts +0 -159
  51. package/src/wxp/__tests__/paste.test.ts +0 -66
  52. package/src/wxp/__tests__/schema.test.ts +0 -120
  53. package/src/wxp/__tests__/security.test.ts +0 -87
  54. package/src/wxp/__tests__/shell.test.ts +0 -85
  55. package/src/wxp/__tests__/string-ops.test.ts +0 -25
  56. package/src/wxp/__tests__/variables.test.ts +0 -65
  57. package/src/wxp/arguments.ts +0 -89
  58. package/src/wxp/conditions.ts +0 -78
  59. package/src/wxp/executor.ts +0 -191
  60. package/src/wxp/index.ts +0 -191
  61. package/src/wxp/parser.ts +0 -198
  62. package/src/wxp/paste.ts +0 -51
  63. package/src/wxp/security.ts +0 -102
  64. package/src/wxp/shell.ts +0 -81
  65. package/src/wxp/string-ops.ts +0 -44
  66. package/src/wxp/variables.ts +0 -109
@@ -1,246 +0,0 @@
1
- /**
2
- * template.ts - Template selection and fill operations.
3
- */
4
-
5
- import fs from "fs";
6
- import path from "path";
7
- import {
8
- findPhaseInternal,
9
- generateSlugInternal,
10
- gsdError,
11
- normalizeMd,
12
- normalizePhaseName,
13
- output,
14
- toPosixPath,
15
- } from "./core.js";
16
- import { reconstructFrontmatter, type FrontmatterObject } from "./frontmatter.js";
17
-
18
- export function cmdTemplateSelect(
19
- cwd: string,
20
- planPath: string | undefined,
21
- raw: boolean,
22
- ): void {
23
- if (!planPath) gsdError("plan-path required");
24
- try {
25
- const fullPath = path.join(cwd, planPath!);
26
- const content = fs.readFileSync(fullPath, "utf-8");
27
- const taskCount = (content.match(/###\s*Task\s*\d+/g) || []).length;
28
- const hasDecisions = (content.match(/decision/gi) || []).length > 0;
29
- const fileMentions = new Set<string>();
30
- const filePattern = /`([^`]+\.[a-zA-Z]+)`/g;
31
- let m: RegExpExecArray | null;
32
- while ((m = filePattern.exec(content)) !== null) {
33
- if (m[1].includes("/") && !m[1].startsWith("http"))
34
- fileMentions.add(m[1]);
35
- }
36
- const fileCount = fileMentions.size;
37
- let template = "templates/summary-standard.md",
38
- type = "standard";
39
- if (taskCount <= 2 && fileCount <= 3 && !hasDecisions) {
40
- template = "templates/summary-minimal.md";
41
- type = "minimal";
42
- } else if (hasDecisions || fileCount > 6 || taskCount > 5) {
43
- template = "templates/summary-complex.md";
44
- type = "complex";
45
- }
46
- output(
47
- { template, type, taskCount, fileCount, hasDecisions },
48
- raw,
49
- template,
50
- );
51
- } catch (e) {
52
- output(
53
- {
54
- template: "templates/summary-standard.md",
55
- type: "standard",
56
- error: (e as Error).message,
57
- },
58
- raw,
59
- "templates/summary-standard.md",
60
- );
61
- }
62
- }
63
-
64
- export function cmdTemplateFill(
65
- cwd: string,
66
- templateType: string | undefined,
67
- options: {
68
- phase?: string | null;
69
- plan?: string | null;
70
- name?: string | null;
71
- type?: string;
72
- wave?: string;
73
- fields?: Record<string, unknown>;
74
- },
75
- raw: boolean,
76
- ): void {
77
- if (!templateType)
78
- gsdError("template type required: summary, plan, or verification");
79
- if (!options.phase) gsdError("--phase required");
80
- const phaseInfo = findPhaseInternal(cwd, options.phase!);
81
- if (!phaseInfo || !phaseInfo.found) {
82
- output({ error: "Phase not found", phase: options.phase }, raw);
83
- return;
84
- }
85
- const padded = normalizePhaseName(options.phase!);
86
- const today = new Date().toISOString().split("T")[0];
87
- const phaseName = options.name || phaseInfo.phase_name || "Unnamed";
88
- const phaseSlug = phaseInfo.phase_slug || generateSlugInternal(phaseName);
89
- const phaseId = `${padded}-${phaseSlug}`;
90
- const planNum = (options.plan || "01").padStart(2, "0");
91
- const fields = options.fields || {};
92
- let frontmatter: FrontmatterObject, body: string, fileName: string;
93
-
94
- switch (templateType) {
95
- case "summary":
96
- frontmatter = {
97
- phase: phaseId,
98
- plan: planNum,
99
- subsystem: "[primary category]",
100
- tags: [],
101
- provides: [],
102
- affects: [],
103
- "tech-stack": { added: [], patterns: [] },
104
- "key-files": { created: [], modified: [] },
105
- "key-decisions": [],
106
- "patterns-established": [],
107
- duration: "[X]min",
108
- completed: today,
109
- ...fields,
110
- };
111
- body = [
112
- `# Phase ${options.phase}: ${phaseName} Summary`,
113
- "",
114
- "**[Substantive one-liner describing outcome]**",
115
- "",
116
- "## Performance",
117
- "- **Duration:** [time]",
118
- "- **Tasks:** [count completed]",
119
- "- **Files modified:** [count]",
120
- "",
121
- "## Accomplishments",
122
- "- [Key outcome 1]",
123
- "- [Key outcome 2]",
124
- "",
125
- "## Task Commits",
126
- "1. **Task 1: [task name]** - `hash`",
127
- "",
128
- "## Files Created/Modified",
129
- "- `path/to/file.ts` - What it does",
130
- "",
131
- "## Decisions & Deviations",
132
- '[Key decisions or "None - followed plan as specified"]',
133
- "",
134
- "## Next Phase Readiness",
135
- "[What's ready for next phase]",
136
- ].join("\n");
137
- fileName = `${padded}-${planNum}-SUMMARY.md`;
138
- break;
139
- case "plan":
140
- frontmatter = {
141
- phase: phaseId,
142
- plan: planNum,
143
- type: options.type || "execute",
144
- wave: parseInt(options.wave || "1"),
145
- depends_on: [],
146
- files_modified: [],
147
- autonomous: true,
148
- user_setup: [],
149
- must_haves: { truths: [], artifacts: [], key_links: [] },
150
- ...fields,
151
- };
152
- body = [
153
- `# Phase ${options.phase} Plan ${planNum}: [Title]`,
154
- "",
155
- "## Objective",
156
- "- **What:** [What this plan builds]",
157
- "- **Why:** [Why it matters for the phase goal]",
158
- "- **Output:** [Concrete deliverable]",
159
- "",
160
- "## Context",
161
- "@.planning/PROJECT.md",
162
- "@.planning/ROADMAP.md",
163
- "@.planning/STATE.md",
164
- "",
165
- "## Tasks",
166
- "",
167
- '<task type="code">',
168
- " <name>[Task name]</name>",
169
- " <files>[file paths]</files>",
170
- " <action>[What to do]</action>",
171
- " <verify>[How to verify]</verify>",
172
- " <done>[Definition of done]</done>",
173
- "</task>",
174
- "",
175
- "## Verification",
176
- "[How to verify this plan achieved its objective]",
177
- "",
178
- "## Success Criteria",
179
- "- [ ] [Criterion 1]",
180
- "- [ ] [Criterion 2]",
181
- ].join("\n");
182
- fileName = `${padded}-${planNum}-PLAN.md`;
183
- break;
184
- case "verification":
185
- frontmatter = {
186
- phase: phaseId,
187
- verified: new Date().toISOString(),
188
- status: "pending",
189
- score: "0/0 must-haves verified",
190
- ...fields,
191
- };
192
- body = [
193
- `# Phase ${options.phase}: ${phaseName} - Verification`,
194
- "",
195
- "## Observable Truths",
196
- "| # | Truth | Status | Evidence |",
197
- "|---|-------|--------|----------|",
198
- "| 1 | [Truth] | pending | |",
199
- "",
200
- "## Required Artifacts",
201
- "| Artifact | Expected | Status | Details |",
202
- "|----------|----------|--------|---------|",
203
- "| [path] | [what] | pending | |",
204
- "",
205
- "## Key Link Verification",
206
- "| From | To | Via | Status | Details |",
207
- "|------|----|----|--------|---------|",
208
- "| [source] | [target] | [connection] | pending | |",
209
- "",
210
- "## Requirements Coverage",
211
- "| Requirement | Status | Blocking Issue |",
212
- "|-------------|--------|----------------|",
213
- "| [req] | pending | |",
214
- "",
215
- "## Result",
216
- "[Pending verification]",
217
- ].join("\n");
218
- fileName = `${padded}-VERIFICATION.md`;
219
- break;
220
- default:
221
- gsdError(
222
- `Unknown template type: ${templateType}. Available: summary, plan, verification`,
223
- );
224
- return;
225
- }
226
-
227
- const fullContent = `---\n${reconstructFrontmatter(frontmatter)}\n---\n\n${body}\n`;
228
- const outPath = path.join(cwd, phaseInfo.directory, fileName);
229
- if (fs.existsSync(outPath)) {
230
- output(
231
- {
232
- error: "File already exists",
233
- path: toPosixPath(path.relative(cwd, outPath)),
234
- },
235
- raw,
236
- );
237
- return;
238
- }
239
- fs.writeFileSync(outPath, normalizeMd(fullContent), "utf-8");
240
- const relPath = toPosixPath(path.relative(cwd, outPath));
241
- output(
242
- { created: true, path: relPath, template: templateType },
243
- raw,
244
- relPath,
245
- );
246
- }
package/src/lib/uat.ts DELETED
@@ -1,289 +0,0 @@
1
- /**
2
- * uat.ts - UAT Audit cross-phase scanner + checkpoint renderer.
3
- */
4
-
5
- import fs from "fs";
6
- import path from "path";
7
- import {
8
- getMilestonePhaseFilter,
9
- gsdError,
10
- output,
11
- planningDir,
12
- toPosixPath,
13
- } from "./core.js";
14
- import { extractFrontmatter } from "./frontmatter.js";
15
- import { requireSafePath, sanitizeForDisplay } from "./security.js";
16
-
17
- // ─── Item type ────────────────────────────────────────────────────────────────
18
-
19
- interface UatItem {
20
- test?: number;
21
- name: string;
22
- expected?: string;
23
- result: string;
24
- category: string;
25
- reason?: string;
26
- blocked_by?: string;
27
- }
28
-
29
- // ─── Commands ─────────────────────────────────────────────────────────────────
30
-
31
- export function cmdAuditUat(cwd: string, raw: boolean): void {
32
- const phasesDir = path.join(planningDir(cwd), "phases");
33
- if (!fs.existsSync(phasesDir))
34
- gsdError("No phases directory found in planning directory");
35
- const isDirInMilestone = getMilestonePhaseFilter(cwd);
36
- const results: unknown[] = [];
37
- const dirs = fs
38
- .readdirSync(phasesDir, { withFileTypes: true })
39
- .filter((e) => e.isDirectory())
40
- .map((e) => e.name)
41
- .filter(isDirInMilestone)
42
- .sort();
43
- for (const dir of dirs) {
44
- const phaseMatch = dir.match(/^(\d+[A-Z]?(?:\.\d+)*)/i);
45
- const phaseNum = phaseMatch ? phaseMatch[1] : dir;
46
- const phaseDir = path.join(phasesDir, dir);
47
- const files = fs.readdirSync(phaseDir);
48
- for (const file of files.filter(
49
- (f) => f.includes("-UAT") && f.endsWith(".md"),
50
- )) {
51
- const content = fs.readFileSync(path.join(phaseDir, file), "utf-8");
52
- const items = parseUatItems(content);
53
- if (items.length > 0)
54
- results.push({
55
- phase: phaseNum,
56
- phase_dir: dir,
57
- file,
58
- file_path: toPosixPath(path.relative(cwd, path.join(phaseDir, file))),
59
- type: "uat",
60
- status: extractFrontmatter(content).status || "unknown",
61
- items,
62
- });
63
- }
64
- for (const file of files.filter(
65
- (f) => f.includes("-VERIFICATION") && f.endsWith(".md"),
66
- )) {
67
- const content = fs.readFileSync(path.join(phaseDir, file), "utf-8");
68
- const status =
69
- (extractFrontmatter(content).status as string) || "unknown";
70
- if (status === "human_needed" || status === "gaps_found") {
71
- const items = parseVerificationItems(content, status);
72
- if (items.length > 0)
73
- results.push({
74
- phase: phaseNum,
75
- phase_dir: dir,
76
- file,
77
- file_path: toPosixPath(
78
- path.relative(cwd, path.join(phaseDir, file)),
79
- ),
80
- type: "verification",
81
- status,
82
- items,
83
- });
84
- }
85
- }
86
- }
87
- const summary: {
88
- total_files: number;
89
- total_items: number;
90
- by_category: Record<string, number>;
91
- by_phase: Record<string, number>;
92
- } = {
93
- total_files: results.length,
94
- total_items: (results as { items: unknown[] }[]).reduce(
95
- (s, r) => s + r.items.length,
96
- 0,
97
- ),
98
- by_category: {},
99
- by_phase: {},
100
- };
101
- for (const r of results as { phase: string; items: UatItem[] }[]) {
102
- if (!summary.by_phase[r.phase]) summary.by_phase[r.phase] = 0;
103
- for (const item of r.items) {
104
- summary.by_phase[r.phase]++;
105
- summary.by_category[item.category] =
106
- (summary.by_category[item.category] || 0) + 1;
107
- }
108
- }
109
- output({ results, summary }, raw);
110
- }
111
-
112
- export function cmdRenderCheckpoint(
113
- cwd: string,
114
- options: { file?: string | null },
115
- raw: boolean,
116
- ): void {
117
- const filePath = options.file;
118
- if (!filePath)
119
- gsdError("UAT file required: use uat render-checkpoint --file <path>");
120
- const resolvedPath = requireSafePath(filePath!, cwd, "UAT file", {
121
- allowAbsolute: true,
122
- });
123
- if (!fs.existsSync(resolvedPath)) gsdError(`UAT file not found: ${filePath}`);
124
- const content = fs.readFileSync(resolvedPath, "utf-8");
125
- const currentTest = parseCurrentTest(content);
126
- if (currentTest.complete)
127
- gsdError(
128
- "UAT session is already complete; no pending checkpoint to render",
129
- );
130
- const checkpoint = buildCheckpoint(currentTest);
131
- output(
132
- {
133
- file_path: toPosixPath(path.relative(cwd, resolvedPath)),
134
- test_number: currentTest.number,
135
- test_name: currentTest.name,
136
- checkpoint,
137
- },
138
- raw,
139
- checkpoint,
140
- );
141
- }
142
-
143
- // ─── Internal helpers ─────────────────────────────────────────────────────────
144
-
145
- interface CurrentTest { complete: boolean; number?: number; name?: string; expected?: string; }
146
-
147
- export function parseCurrentTest(content: string): CurrentTest {
148
- const currentTestMatch = content.match(
149
- /##\s*Current Test\s*(?:\n<!--[\s\S]*?-->)?\n([\s\S]*?)(?=\n##\s|$)/i,
150
- );
151
- if (!currentTestMatch) gsdError("UAT file is missing a Current Test section");
152
- const section = currentTestMatch![1].trimEnd();
153
- if (!section.trim()) gsdError("Current Test section is empty");
154
- if (/\[testing complete\]/i.test(section)) return { complete: true };
155
- const numberMatch = section.match(/^number:\s*(\d+)\s*$/m);
156
- const nameMatch = section.match(/^name:\s*(.+)\s*$/m);
157
- const expectedBlockMatch =
158
- section.match(/^expected:\s*\|\n([\s\S]*?)(?=^\w[\w-]*:\s)/m) ||
159
- section.match(/^expected:\s*\|\n([\s\S]+)/m);
160
- const expectedInlineMatch = section.match(/^expected:\s*(.+)\s*$/m);
161
- if (
162
- !numberMatch ||
163
- !nameMatch ||
164
- (!expectedBlockMatch && !expectedInlineMatch)
165
- )
166
- gsdError("Current Test section is malformed");
167
- let expected: string;
168
- if (expectedBlockMatch)
169
- expected = expectedBlockMatch[1]
170
- .split("\n")
171
- .map((l) => l.replace(/^ {2}/, ""))
172
- .join("\n")
173
- .trim();
174
- else expected = expectedInlineMatch![1].trim();
175
- return {
176
- complete: false,
177
- number: parseInt(numberMatch![1], 10),
178
- name: sanitizeForDisplay(nameMatch![1].trim()),
179
- expected: sanitizeForDisplay(expected),
180
- };
181
- }
182
-
183
- export function buildCheckpoint(currentTest: CurrentTest): string {
184
- return [
185
- "╔══════════════════════════════════════════════════════════════╗",
186
- "║ CHECKPOINT: Verification Required ║",
187
- "╚══════════════════════════════════════════════════════════════╝",
188
- "",
189
- `**Test ${currentTest.number}: ${currentTest.name}**`,
190
- "",
191
- currentTest.expected,
192
- "",
193
- "──────────────────────────────────────────────────────────────",
194
- "Type `pass` or describe what's wrong.",
195
- "──────────────────────────────────────────────────────────────",
196
- ].join("\n");
197
- }
198
-
199
- function parseUatItems(content: string): UatItem[] {
200
- const items: UatItem[] = [];
201
- const testPattern =
202
- /###\s*(\d+)\.\s*([^\n]+)\nexpected:\s*([^\n]+)\nresult:\s*(\w+)(?:\n(?:reported|reason|blocked_by):\s*[^\n]*)?/g;
203
- let match: RegExpExecArray | null;
204
- while ((match = testPattern.exec(content)) !== null) {
205
- const [, num, name, expected, result] = match;
206
- if (result === "pending" || result === "skipped" || result === "blocked") {
207
- const afterMatch = content.slice(match.index);
208
- const nextHeading = afterMatch.indexOf("\n###", 1);
209
- const blockText =
210
- nextHeading > 0 ? afterMatch.slice(0, nextHeading) : afterMatch;
211
- const reasonMatch = blockText.match(/reason:\s*(.+)/);
212
- const blockedByMatch = blockText.match(/blocked_by:\s*(.+)/);
213
- const item: UatItem = {
214
- test: parseInt(num, 10),
215
- name: name.trim(),
216
- expected: expected.trim(),
217
- result,
218
- category: categorizeItem(result, reasonMatch?.[1], blockedByMatch?.[1]),
219
- };
220
- if (reasonMatch) item.reason = reasonMatch[1].trim();
221
- if (blockedByMatch) item.blocked_by = blockedByMatch[1].trim();
222
- items.push(item);
223
- }
224
- }
225
- return items;
226
- }
227
-
228
- function parseVerificationItems(content: string, status: string): UatItem[] {
229
- const items: UatItem[] = [];
230
- if (status === "human_needed") {
231
- const hvSection = content.match(
232
- /##\s*Human Verification.*?\n([\s\S]*?)(?=\n##\s|\n---\s|$)/i,
233
- );
234
- if (hvSection) {
235
- for (const line of hvSection[1].split("\n")) {
236
- const tableMatch = line.match(/\|\s*(\d+)\s*\|\s*([^|]+)/);
237
- const bulletMatch = line.match(/^[-*]\s+(.+)/);
238
- const numberedMatch = line.match(/^(\d+)\.\s+(.+)/);
239
- if (tableMatch)
240
- items.push({
241
- test: parseInt(tableMatch[1], 10),
242
- name: tableMatch[2].trim(),
243
- result: "human_needed",
244
- category: "human_uat",
245
- });
246
- else if (numberedMatch)
247
- items.push({
248
- test: parseInt(numberedMatch[1], 10),
249
- name: numberedMatch[2].trim(),
250
- result: "human_needed",
251
- category: "human_uat",
252
- });
253
- else if (bulletMatch && bulletMatch[1].length > 10)
254
- items.push({
255
- name: bulletMatch[1].trim(),
256
- result: "human_needed",
257
- category: "human_uat",
258
- });
259
- }
260
- }
261
- }
262
- return items;
263
- }
264
-
265
- function categorizeItem(
266
- result: string,
267
- reason?: string,
268
- blockedBy?: string,
269
- ): string {
270
- if (result === "blocked" || blockedBy) {
271
- if (blockedBy) {
272
- if (/server/i.test(blockedBy)) return "server_blocked";
273
- if (/device|physical/i.test(blockedBy)) return "device_needed";
274
- if (/build|release|preview/i.test(blockedBy)) return "build_needed";
275
- if (/third.party|twilio|stripe/i.test(blockedBy)) return "third_party";
276
- }
277
- return "blocked";
278
- }
279
- if (result === "skipped" && reason) {
280
- if (/server|not running|not available/i.test(reason))
281
- return "server_blocked";
282
- if (/simulator|physical|device/i.test(reason)) return "device_needed";
283
- if (/build|release|preview/i.test(reason)) return "build_needed";
284
- return "skipped_unresolved";
285
- }
286
- if (result === "pending") return "pending";
287
- if (result === "human_needed") return "human_uat";
288
- return "unknown";
289
- }