gsd-pi 2.62.0-dev.f6ad485 → 2.62.1-dev.1ae2b74

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 (131) hide show
  1. package/dist/resources/extensions/ask-user-questions.js +47 -3
  2. package/dist/resources/extensions/gsd/auto/loop.js +8 -1
  3. package/dist/resources/extensions/gsd/auto/phases.js +10 -3
  4. package/dist/resources/extensions/gsd/auto-post-unit.js +6 -4
  5. package/dist/resources/extensions/gsd/auto-start.js +11 -6
  6. package/dist/resources/extensions/gsd/auto-timers.js +8 -2
  7. package/dist/resources/extensions/gsd/auto-verification.js +14 -3
  8. package/dist/resources/extensions/gsd/auto-worktree.js +19 -0
  9. package/dist/resources/extensions/gsd/auto.js +24 -0
  10. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +4 -0
  11. package/dist/resources/extensions/gsd/bootstrap/tool-call-loop-guard.js +11 -1
  12. package/dist/resources/extensions/gsd/db-writer.js +64 -28
  13. package/dist/resources/extensions/gsd/preferences-models.js +74 -0
  14. package/dist/resources/extensions/gsd/preferences-skills.js +6 -1
  15. package/dist/resources/extensions/gsd/prompts/guided-discuss-milestone.md +1 -1
  16. package/dist/resources/extensions/gsd/prompts/guided-discuss-slice.md +1 -1
  17. package/dist/resources/extensions/gsd/skill-catalog.js +6 -4
  18. package/dist/resources/extensions/gsd/skill-discovery.js +24 -6
  19. package/dist/resources/extensions/gsd/skill-health.js +7 -3
  20. package/dist/resources/extensions/gsd/skill-telemetry.js +5 -2
  21. package/dist/resources/extensions/gsd/state.js +1 -0
  22. package/dist/resources/extensions/gsd/tools/complete-slice.js +3 -3
  23. package/dist/resources/extensions/gsd/workflow-logger.js +13 -8
  24. package/dist/resources/extensions/gsd/workflow-reconcile.js +3 -1
  25. package/dist/web/standalone/.next/BUILD_ID +1 -1
  26. package/dist/web/standalone/.next/app-path-routes-manifest.json +20 -20
  27. package/dist/web/standalone/.next/build-manifest.json +2 -2
  28. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  29. package/dist/web/standalone/.next/server/app/_global-error.html +2 -2
  30. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  31. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  32. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  33. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  34. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  35. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  36. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  37. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  38. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  39. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  40. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  41. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  42. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  43. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  44. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  45. package/dist/web/standalone/.next/server/app/index.html +1 -1
  46. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  47. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  48. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  49. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  50. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  51. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  52. package/dist/web/standalone/.next/server/app-paths-manifest.json +20 -20
  53. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  54. package/dist/web/standalone/.next/server/pages/500.html +2 -2
  55. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  56. package/package.json +1 -1
  57. package/packages/mcp-server/src/cli.ts +1 -1
  58. package/packages/mcp-server/src/index.ts +15 -1
  59. package/packages/mcp-server/src/readers/captures.ts +119 -0
  60. package/packages/mcp-server/src/readers/doctor-lite.ts +225 -0
  61. package/packages/mcp-server/src/readers/index.ts +16 -0
  62. package/packages/mcp-server/src/readers/knowledge.ts +111 -0
  63. package/packages/mcp-server/src/readers/metrics.ts +118 -0
  64. package/packages/mcp-server/src/readers/paths.ts +217 -0
  65. package/packages/mcp-server/src/readers/readers.test.ts +509 -0
  66. package/packages/mcp-server/src/readers/roadmap.ts +263 -0
  67. package/packages/mcp-server/src/readers/state.ts +223 -0
  68. package/packages/mcp-server/src/server.ts +134 -3
  69. package/packages/pi-ai/dist/utils/repair-tool-json.d.ts +26 -6
  70. package/packages/pi-ai/dist/utils/repair-tool-json.d.ts.map +1 -1
  71. package/packages/pi-ai/dist/utils/repair-tool-json.js +67 -9
  72. package/packages/pi-ai/dist/utils/repair-tool-json.js.map +1 -1
  73. package/packages/pi-ai/dist/utils/tests/repair-tool-json.test.js +73 -1
  74. package/packages/pi-ai/dist/utils/tests/repair-tool-json.test.js.map +1 -1
  75. package/packages/pi-ai/src/utils/repair-tool-json.ts +74 -10
  76. package/packages/pi-ai/src/utils/tests/repair-tool-json.test.ts +94 -1
  77. package/packages/pi-coding-agent/dist/core/agent-session-model-switch.test.d.ts +2 -0
  78. package/packages/pi-coding-agent/dist/core/agent-session-model-switch.test.d.ts.map +1 -0
  79. package/packages/pi-coding-agent/dist/core/agent-session-model-switch.test.js +16 -0
  80. package/packages/pi-coding-agent/dist/core/agent-session-model-switch.test.js.map +1 -0
  81. package/packages/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
  82. package/packages/pi-coding-agent/dist/core/agent-session.js +4 -0
  83. package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
  84. package/packages/pi-coding-agent/dist/core/retry-handler.d.ts +3 -0
  85. package/packages/pi-coding-agent/dist/core/retry-handler.d.ts.map +1 -1
  86. package/packages/pi-coding-agent/dist/core/retry-handler.js +48 -16
  87. package/packages/pi-coding-agent/dist/core/retry-handler.js.map +1 -1
  88. package/packages/pi-coding-agent/dist/core/retry-handler.test.js +20 -3
  89. package/packages/pi-coding-agent/dist/core/retry-handler.test.js.map +1 -1
  90. package/packages/pi-coding-agent/package.json +1 -1
  91. package/packages/pi-coding-agent/src/core/agent-session-model-switch.test.ts +21 -0
  92. package/packages/pi-coding-agent/src/core/agent-session.ts +4 -0
  93. package/packages/pi-coding-agent/src/core/retry-handler.test.ts +30 -3
  94. package/packages/pi-coding-agent/src/core/retry-handler.ts +49 -16
  95. package/pkg/package.json +1 -1
  96. package/src/resources/extensions/ask-user-questions.ts +60 -4
  97. package/src/resources/extensions/gsd/auto/loop.ts +8 -1
  98. package/src/resources/extensions/gsd/auto/phases.ts +8 -6
  99. package/src/resources/extensions/gsd/auto-post-unit.ts +6 -3
  100. package/src/resources/extensions/gsd/auto-start.ts +11 -6
  101. package/src/resources/extensions/gsd/auto-timers.ts +8 -2
  102. package/src/resources/extensions/gsd/auto-verification.ts +14 -3
  103. package/src/resources/extensions/gsd/auto-worktree.ts +18 -0
  104. package/src/resources/extensions/gsd/auto.ts +25 -0
  105. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +4 -0
  106. package/src/resources/extensions/gsd/bootstrap/tool-call-loop-guard.ts +13 -1
  107. package/src/resources/extensions/gsd/db-writer.ts +67 -30
  108. package/src/resources/extensions/gsd/preferences-models.ts +78 -0
  109. package/src/resources/extensions/gsd/preferences-skills.ts +6 -1
  110. package/src/resources/extensions/gsd/prompts/guided-discuss-milestone.md +1 -1
  111. package/src/resources/extensions/gsd/prompts/guided-discuss-slice.md +1 -1
  112. package/src/resources/extensions/gsd/skill-catalog.ts +6 -3
  113. package/src/resources/extensions/gsd/skill-discovery.ts +23 -6
  114. package/src/resources/extensions/gsd/skill-health.ts +7 -3
  115. package/src/resources/extensions/gsd/skill-telemetry.ts +5 -2
  116. package/src/resources/extensions/gsd/state.ts +1 -0
  117. package/src/resources/extensions/gsd/tests/ask-user-questions-dedup.test.ts +120 -0
  118. package/src/resources/extensions/gsd/tests/auto-start-model-capture.test.ts +22 -2
  119. package/src/resources/extensions/gsd/tests/auto-wrapup-inflight-guard.test.ts +107 -0
  120. package/src/resources/extensions/gsd/tests/claude-skill-dirs.test.ts +51 -0
  121. package/src/resources/extensions/gsd/tests/db-writer.test.ts +41 -0
  122. package/src/resources/extensions/gsd/tests/model-isolation.test.ts +75 -1
  123. package/src/resources/extensions/gsd/tests/tool-call-loop-guard.test.ts +17 -4
  124. package/src/resources/extensions/gsd/tests/workflow-logger.test.ts +17 -41
  125. package/src/resources/extensions/gsd/tests/worktree-db-respawn-truncation.test.ts +81 -2
  126. package/src/resources/extensions/gsd/tools/complete-slice.ts +3 -5
  127. package/src/resources/extensions/gsd/workflow-logger.ts +13 -8
  128. package/src/resources/extensions/gsd/workflow-reconcile.ts +3 -1
  129. package/src/resources/extensions/shared/tests/ask-user-freetext.test.ts +6 -1
  130. /package/dist/web/standalone/.next/static/{fbkSIi4k8fmB8mi0Sq9sF → erQZ_8_1lkclnPJLJnCxG}/_buildManifest.js +0 -0
  131. /package/dist/web/standalone/.next/static/{fbkSIi4k8fmB8mi0Sq9sF → erQZ_8_1lkclnPJLJnCxG}/_ssgManifest.js +0 -0
@@ -15,7 +15,7 @@ const MCP_PKG = '@modelcontextprotocol/sdk';
15
15
  async function main(): Promise<void> {
16
16
  const sessionManager = new SessionManager();
17
17
 
18
- // Create the configured MCP server with all 6 tools
18
+ // Create the configured MCP server with all 12 tools (6 session + 6 read-only)
19
19
  const { server } = await createMcpServer(sessionManager);
20
20
 
21
21
  // Dynamic import for StdioServerTransport (same TS subpath workaround)
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @gsd-build/mcp-server — MCP server for GSD orchestration.
2
+ * @gsd-build/mcp-server — MCP server for GSD orchestration and project state.
3
3
  */
4
4
 
5
5
  export { SessionManager } from './session-manager.js';
@@ -12,3 +12,17 @@ export type {
12
12
  CostAccumulator,
13
13
  } from './types.js';
14
14
  export { MAX_EVENTS, INIT_TIMEOUT_MS } from './types.js';
15
+
16
+ // Read-only state readers (usable without a running session)
17
+ export { readProgress } from './readers/state.js';
18
+ export type { ProgressResult } from './readers/state.js';
19
+ export { readRoadmap } from './readers/roadmap.js';
20
+ export type { RoadmapResult, MilestoneInfo, SliceInfo, TaskInfo } from './readers/roadmap.js';
21
+ export { readHistory } from './readers/metrics.js';
22
+ export type { HistoryResult, MetricsUnit } from './readers/metrics.js';
23
+ export { readCaptures } from './readers/captures.js';
24
+ export type { CapturesResult, CaptureEntry } from './readers/captures.js';
25
+ export { readKnowledge } from './readers/knowledge.js';
26
+ export type { KnowledgeResult, KnowledgeEntry } from './readers/knowledge.js';
27
+ export { runDoctorLite } from './readers/doctor-lite.js';
28
+ export type { DoctorResult, DoctorIssue } from './readers/doctor-lite.js';
@@ -0,0 +1,119 @@
1
+ // GSD MCP Server — captures reader
2
+ // Copyright (c) 2026 Jeremy McSpadden <jeremy@fluxlabs.net>
3
+
4
+ import { readFileSync, existsSync } from 'node:fs';
5
+ import { resolveGsdRoot, resolveRootFile } from './paths.js';
6
+
7
+ // ---------------------------------------------------------------------------
8
+ // Types
9
+ // ---------------------------------------------------------------------------
10
+
11
+ export type CaptureStatus = 'pending' | 'triaged' | 'resolved';
12
+ export type CaptureClassification =
13
+ | 'quick-task' | 'inject' | 'defer' | 'replan' | 'note' | 'stop' | 'backtrack';
14
+
15
+ export interface CaptureEntry {
16
+ id: string;
17
+ text: string;
18
+ timestamp: string;
19
+ status: CaptureStatus;
20
+ classification: CaptureClassification | null;
21
+ resolution: string | null;
22
+ rationale: string | null;
23
+ resolvedAt: string | null;
24
+ milestone: string | null;
25
+ executed: string | null;
26
+ }
27
+
28
+ export interface CapturesResult {
29
+ captures: CaptureEntry[];
30
+ counts: {
31
+ total: number;
32
+ pending: number;
33
+ resolved: number;
34
+ actionable: number;
35
+ };
36
+ }
37
+
38
+ // ---------------------------------------------------------------------------
39
+ // Parser
40
+ // ---------------------------------------------------------------------------
41
+
42
+ function parseCapturesMarkdown(content: string): CaptureEntry[] {
43
+ const entries: CaptureEntry[] = [];
44
+
45
+ // Split on H3 headers: ### CAP-xxxxxxxx
46
+ const sections = content.split(/(?=^### CAP-)/m);
47
+
48
+ for (const section of sections) {
49
+ const idMatch = section.match(/^### (CAP-[\da-f]+)/);
50
+ if (!idMatch) continue;
51
+
52
+ const id = idMatch[1];
53
+ const field = (label: string): string | null => {
54
+ const re = new RegExp(`\\*\\*${label}:\\*\\*\\s*(.+)`, 'i');
55
+ const m = section.match(re);
56
+ return m ? m[1].trim() : null;
57
+ };
58
+
59
+ const status = (field('Status') ?? 'pending').toLowerCase() as CaptureStatus;
60
+ const classification = field('Classification') as CaptureClassification | null;
61
+
62
+ entries.push({
63
+ id,
64
+ text: field('Text') ?? '',
65
+ timestamp: field('Captured') ?? '',
66
+ status,
67
+ classification,
68
+ resolution: field('Resolution'),
69
+ rationale: field('Rationale'),
70
+ resolvedAt: field('Resolved'),
71
+ milestone: field('Milestone'),
72
+ executed: field('Executed'),
73
+ });
74
+ }
75
+
76
+ return entries;
77
+ }
78
+
79
+ // ---------------------------------------------------------------------------
80
+ // Public API
81
+ // ---------------------------------------------------------------------------
82
+
83
+ const ACTIONABLE_CLASSIFICATIONS = new Set<string>(['quick-task', 'inject', 'replan']);
84
+
85
+ export function readCaptures(
86
+ projectDir: string,
87
+ filter: 'all' | 'pending' | 'actionable' = 'all',
88
+ ): CapturesResult {
89
+ const gsd = resolveGsdRoot(projectDir);
90
+ const capturesPath = resolveRootFile(gsd, 'CAPTURES.md');
91
+
92
+ if (!existsSync(capturesPath)) {
93
+ return { captures: [], counts: { total: 0, pending: 0, resolved: 0, actionable: 0 } };
94
+ }
95
+
96
+ const content = readFileSync(capturesPath, 'utf-8');
97
+ let captures = parseCapturesMarkdown(content);
98
+
99
+ // Compute counts before filtering
100
+ const counts = {
101
+ total: captures.length,
102
+ pending: captures.filter((c) => c.status === 'pending').length,
103
+ resolved: captures.filter((c) => c.status === 'resolved').length,
104
+ actionable: captures.filter(
105
+ (c) => c.classification !== null && ACTIONABLE_CLASSIFICATIONS.has(c.classification),
106
+ ).length,
107
+ };
108
+
109
+ // Apply filter
110
+ if (filter === 'pending') {
111
+ captures = captures.filter((c) => c.status === 'pending');
112
+ } else if (filter === 'actionable') {
113
+ captures = captures.filter(
114
+ (c) => c.classification !== null && ACTIONABLE_CLASSIFICATIONS.has(c.classification),
115
+ );
116
+ }
117
+
118
+ return { captures, counts };
119
+ }
@@ -0,0 +1,225 @@
1
+ // GSD MCP Server — lightweight structural health checks
2
+ // Copyright (c) 2026 Jeremy McSpadden <jeremy@fluxlabs.net>
3
+
4
+ import { existsSync, readFileSync } from 'node:fs';
5
+ import {
6
+ resolveGsdRoot,
7
+ resolveRootFile,
8
+ findMilestoneIds,
9
+ resolveMilestoneFile,
10
+ resolveMilestoneDir,
11
+ findSliceIds,
12
+ resolveSliceFile,
13
+ findTaskFiles,
14
+ } from './paths.js';
15
+
16
+ // ---------------------------------------------------------------------------
17
+ // Types
18
+ // ---------------------------------------------------------------------------
19
+
20
+ export type Severity = 'info' | 'warning' | 'error';
21
+
22
+ export interface DoctorIssue {
23
+ severity: Severity;
24
+ code: string;
25
+ scope: 'project' | 'milestone' | 'slice' | 'task';
26
+ unitId: string;
27
+ message: string;
28
+ file?: string;
29
+ }
30
+
31
+ export interface DoctorResult {
32
+ ok: boolean;
33
+ issues: DoctorIssue[];
34
+ counts: { error: number; warning: number; info: number };
35
+ }
36
+
37
+ // ---------------------------------------------------------------------------
38
+ // Check implementations
39
+ // ---------------------------------------------------------------------------
40
+
41
+ function checkProjectLevel(gsdRoot: string, issues: DoctorIssue[]): void {
42
+ // PROJECT.md should exist
43
+ const projectPath = resolveRootFile(gsdRoot, 'PROJECT.md');
44
+ if (!existsSync(projectPath)) {
45
+ issues.push({
46
+ severity: 'warning',
47
+ code: 'missing_project_md',
48
+ scope: 'project',
49
+ unitId: '',
50
+ message: 'PROJECT.md is missing — project lacks a description',
51
+ file: projectPath,
52
+ });
53
+ }
54
+
55
+ // STATE.md should exist if milestones exist
56
+ const milestones = findMilestoneIds(gsdRoot);
57
+ if (milestones.length > 0) {
58
+ const statePath = resolveRootFile(gsdRoot, 'STATE.md');
59
+ if (!existsSync(statePath)) {
60
+ issues.push({
61
+ severity: 'warning',
62
+ code: 'missing_state_md',
63
+ scope: 'project',
64
+ unitId: '',
65
+ message: 'STATE.md is missing — run /gsd status to regenerate',
66
+ file: statePath,
67
+ });
68
+ }
69
+ }
70
+ }
71
+
72
+ function checkMilestoneLevel(gsdRoot: string, mid: string, issues: DoctorIssue[]): void {
73
+ const mDir = resolveMilestoneDir(gsdRoot, mid);
74
+ if (!mDir) {
75
+ issues.push({
76
+ severity: 'error',
77
+ code: 'missing_milestone_dir',
78
+ scope: 'milestone',
79
+ unitId: mid,
80
+ message: `Milestone directory for ${mid} not found`,
81
+ });
82
+ return;
83
+ }
84
+
85
+ // CONTEXT.md should exist
86
+ const ctxPath = resolveMilestoneFile(gsdRoot, mid, 'CONTEXT');
87
+ if (!ctxPath || !existsSync(ctxPath)) {
88
+ // Check for draft
89
+ const draftPath = resolveMilestoneFile(gsdRoot, mid, 'CONTEXT-DRAFT');
90
+ if (!draftPath || !existsSync(draftPath)) {
91
+ issues.push({
92
+ severity: 'warning',
93
+ code: 'missing_context',
94
+ scope: 'milestone',
95
+ unitId: mid,
96
+ message: `${mid} has no CONTEXT.md — milestone lacks defined scope`,
97
+ });
98
+ }
99
+ }
100
+
101
+ // ROADMAP.md should exist if slices exist
102
+ const sliceIds = findSliceIds(gsdRoot, mid);
103
+ if (sliceIds.length > 0) {
104
+ const roadmapPath = resolveMilestoneFile(gsdRoot, mid, 'ROADMAP');
105
+ if (!roadmapPath || !existsSync(roadmapPath)) {
106
+ issues.push({
107
+ severity: 'warning',
108
+ code: 'missing_roadmap',
109
+ scope: 'milestone',
110
+ unitId: mid,
111
+ message: `${mid} has ${sliceIds.length} slices but no ROADMAP.md`,
112
+ });
113
+ }
114
+ }
115
+
116
+ // Check if all slices done but no SUMMARY
117
+ if (sliceIds.length > 0) {
118
+ const allDone = sliceIds.every((sid) => {
119
+ const tasks = findTaskFiles(gsdRoot, mid, sid);
120
+ return tasks.length > 0 && tasks.every((t) => t.hasSummary);
121
+ });
122
+ const summaryPath = resolveMilestoneFile(gsdRoot, mid, 'SUMMARY');
123
+ if (allDone && (!summaryPath || !existsSync(summaryPath))) {
124
+ issues.push({
125
+ severity: 'error',
126
+ code: 'all_slices_done_missing_summary',
127
+ scope: 'milestone',
128
+ unitId: mid,
129
+ message: `${mid} has all slices completed but no SUMMARY.md`,
130
+ });
131
+ }
132
+ }
133
+ }
134
+
135
+ function checkSliceLevel(
136
+ gsdRoot: string, mid: string, sid: string, issues: DoctorIssue[],
137
+ ): void {
138
+ const unitId = `${mid}/${sid}`;
139
+
140
+ // PLAN.md should exist
141
+ const planPath = resolveSliceFile(gsdRoot, mid, sid, 'PLAN');
142
+ if (!planPath || !existsSync(planPath)) {
143
+ issues.push({
144
+ severity: 'error',
145
+ code: 'missing_slice_plan',
146
+ scope: 'slice',
147
+ unitId,
148
+ message: `${unitId} has no PLAN.md`,
149
+ });
150
+ }
151
+
152
+ // Tasks should have plans
153
+ const tasks = findTaskFiles(gsdRoot, mid, sid);
154
+ for (const task of tasks) {
155
+ const taskUnitId = `${unitId}/${task.id}`;
156
+ if (!task.hasPlan) {
157
+ issues.push({
158
+ severity: 'warning',
159
+ code: 'missing_task_plan',
160
+ scope: 'task',
161
+ unitId: taskUnitId,
162
+ message: `${taskUnitId} has a summary but no plan file`,
163
+ });
164
+ }
165
+ }
166
+
167
+ // Check for empty slice (directory exists but no tasks or plan)
168
+ if (tasks.length === 0 && (!planPath || !existsSync(planPath))) {
169
+ issues.push({
170
+ severity: 'warning',
171
+ code: 'empty_slice',
172
+ scope: 'slice',
173
+ unitId,
174
+ message: `${unitId} has no plan and no tasks — may be abandoned`,
175
+ });
176
+ }
177
+ }
178
+
179
+ // ---------------------------------------------------------------------------
180
+ // Public API
181
+ // ---------------------------------------------------------------------------
182
+
183
+ export function runDoctorLite(projectDir: string, scope?: string): DoctorResult {
184
+ const gsdRoot = resolveGsdRoot(projectDir);
185
+ const issues: DoctorIssue[] = [];
186
+
187
+ if (!existsSync(gsdRoot)) {
188
+ return {
189
+ ok: true,
190
+ issues: [{
191
+ severity: 'info',
192
+ code: 'no_gsd_directory',
193
+ scope: 'project',
194
+ unitId: '',
195
+ message: 'No .gsd/ directory found — project not initialized',
196
+ }],
197
+ counts: { error: 0, warning: 0, info: 1 },
198
+ };
199
+ }
200
+
201
+ // Project-level checks
202
+ checkProjectLevel(gsdRoot, issues);
203
+
204
+ // Milestone + slice checks
205
+ const milestoneIds = scope
206
+ ? findMilestoneIds(gsdRoot).filter((id) => id === scope)
207
+ : findMilestoneIds(gsdRoot);
208
+
209
+ for (const mid of milestoneIds) {
210
+ checkMilestoneLevel(gsdRoot, mid, issues);
211
+
212
+ const sliceIds = findSliceIds(gsdRoot, mid);
213
+ for (const sid of sliceIds) {
214
+ checkSliceLevel(gsdRoot, mid, sid, issues);
215
+ }
216
+ }
217
+
218
+ const counts = {
219
+ error: issues.filter((i) => i.severity === 'error').length,
220
+ warning: issues.filter((i) => i.severity === 'warning').length,
221
+ info: issues.filter((i) => i.severity === 'info').length,
222
+ };
223
+
224
+ return { ok: counts.error === 0, issues, counts };
225
+ }
@@ -0,0 +1,16 @@
1
+ // GSD MCP Server — readers barrel export
2
+ // Copyright (c) 2026 Jeremy McSpadden <jeremy@fluxlabs.net>
3
+
4
+ export { resolveGsdRoot, resolveRootFile } from './paths.js';
5
+ export { readProgress } from './state.js';
6
+ export type { ProgressResult } from './state.js';
7
+ export { readRoadmap } from './roadmap.js';
8
+ export type { RoadmapResult, MilestoneInfo, SliceInfo, TaskInfo } from './roadmap.js';
9
+ export { readHistory } from './metrics.js';
10
+ export type { HistoryResult, MetricsUnit } from './metrics.js';
11
+ export { readCaptures } from './captures.js';
12
+ export type { CapturesResult, CaptureEntry } from './captures.js';
13
+ export { readKnowledge } from './knowledge.js';
14
+ export type { KnowledgeResult, KnowledgeEntry } from './knowledge.js';
15
+ export { runDoctorLite } from './doctor-lite.js';
16
+ export type { DoctorResult, DoctorIssue } from './doctor-lite.js';
@@ -0,0 +1,111 @@
1
+ // GSD MCP Server — knowledge base reader
2
+ // Copyright (c) 2026 Jeremy McSpadden <jeremy@fluxlabs.net>
3
+
4
+ import { readFileSync, existsSync } from 'node:fs';
5
+ import { resolveGsdRoot, resolveRootFile } from './paths.js';
6
+
7
+ // ---------------------------------------------------------------------------
8
+ // Types
9
+ // ---------------------------------------------------------------------------
10
+
11
+ export type KnowledgeType = 'rule' | 'pattern' | 'lesson';
12
+
13
+ export interface KnowledgeEntry {
14
+ id: string;
15
+ type: KnowledgeType;
16
+ scope: string;
17
+ content: string;
18
+ addedAt: string;
19
+ }
20
+
21
+ export interface KnowledgeResult {
22
+ entries: KnowledgeEntry[];
23
+ counts: { rules: number; patterns: number; lessons: number };
24
+ }
25
+
26
+ // ---------------------------------------------------------------------------
27
+ // Parser
28
+ // ---------------------------------------------------------------------------
29
+
30
+ function parseTableRows(section: string, type: KnowledgeType): KnowledgeEntry[] {
31
+ const entries: KnowledgeEntry[] = [];
32
+ const lines = section.split('\n');
33
+
34
+ for (const line of lines) {
35
+ if (!line.includes('|')) continue;
36
+ const cells = line.split('|').map((c) => c.trim()).filter(Boolean);
37
+ if (cells.length < 3) continue;
38
+ // Skip header/separator
39
+ if (cells[0].startsWith('#') || cells[0].startsWith('-')) continue;
40
+
41
+ const id = cells[0];
42
+ if (!/^[KPL]\d+$/i.test(id)) continue;
43
+
44
+ if (type === 'rule' && cells.length >= 5) {
45
+ entries.push({
46
+ id, type, scope: cells[1], content: cells[2], addedAt: cells[4] ?? '',
47
+ });
48
+ } else if (type === 'pattern' && cells.length >= 4) {
49
+ entries.push({
50
+ id, type, scope: cells[2] ?? '', content: cells[1], addedAt: cells[3] ?? '',
51
+ });
52
+ } else if (type === 'lesson' && cells.length >= 5) {
53
+ entries.push({
54
+ id, type, scope: cells[4] ?? '',
55
+ content: `${cells[1]} — Root cause: ${cells[2]} — Fix: ${cells[3]}`,
56
+ addedAt: '',
57
+ });
58
+ }
59
+ }
60
+
61
+ return entries;
62
+ }
63
+
64
+ function parseKnowledgeMarkdown(content: string): KnowledgeEntry[] {
65
+ const entries: KnowledgeEntry[] = [];
66
+
67
+ // Find ## Rules section
68
+ const rulesMatch = content.match(/## Rules\s*\n([\s\S]*?)(?=\n## |$)/i);
69
+ if (rulesMatch) {
70
+ entries.push(...parseTableRows(rulesMatch[1], 'rule'));
71
+ }
72
+
73
+ // Find ## Patterns section
74
+ const patternsMatch = content.match(/## Patterns\s*\n([\s\S]*?)(?=\n## |$)/i);
75
+ if (patternsMatch) {
76
+ entries.push(...parseTableRows(patternsMatch[1], 'pattern'));
77
+ }
78
+
79
+ // Find ## Lessons Learned section
80
+ const lessonsMatch = content.match(/## Lessons Learned\s*\n([\s\S]*?)(?=\n## |$)/i);
81
+ if (lessonsMatch) {
82
+ entries.push(...parseTableRows(lessonsMatch[1], 'lesson'));
83
+ }
84
+
85
+ return entries;
86
+ }
87
+
88
+ // ---------------------------------------------------------------------------
89
+ // Public API
90
+ // ---------------------------------------------------------------------------
91
+
92
+ export function readKnowledge(projectDir: string): KnowledgeResult {
93
+ const gsd = resolveGsdRoot(projectDir);
94
+ const knowledgePath = resolveRootFile(gsd, 'KNOWLEDGE.md');
95
+
96
+ if (!existsSync(knowledgePath)) {
97
+ return { entries: [], counts: { rules: 0, patterns: 0, lessons: 0 } };
98
+ }
99
+
100
+ const content = readFileSync(knowledgePath, 'utf-8');
101
+ const entries = parseKnowledgeMarkdown(content);
102
+
103
+ return {
104
+ entries,
105
+ counts: {
106
+ rules: entries.filter((e) => e.type === 'rule').length,
107
+ patterns: entries.filter((e) => e.type === 'pattern').length,
108
+ lessons: entries.filter((e) => e.type === 'lesson').length,
109
+ },
110
+ };
111
+ }
@@ -0,0 +1,118 @@
1
+ // GSD MCP Server — metrics/history reader
2
+ // Copyright (c) 2026 Jeremy McSpadden <jeremy@fluxlabs.net>
3
+
4
+ import { readFileSync, existsSync } from 'node:fs';
5
+ import { resolveGsdRoot, resolveRootFile } from './paths.js';
6
+
7
+ // ---------------------------------------------------------------------------
8
+ // Types
9
+ // ---------------------------------------------------------------------------
10
+
11
+ export interface MetricsUnit {
12
+ type: string;
13
+ id: string;
14
+ model: string;
15
+ startedAt: number;
16
+ finishedAt: number;
17
+ tokens: {
18
+ input: number;
19
+ output: number;
20
+ cacheRead: number;
21
+ cacheWrite: number;
22
+ total: number;
23
+ };
24
+ cost: number;
25
+ toolCalls: number;
26
+ apiRequests: number;
27
+ }
28
+
29
+ export interface HistoryResult {
30
+ entries: MetricsUnit[];
31
+ totals: {
32
+ cost: number;
33
+ tokens: { input: number; output: number; total: number };
34
+ units: number;
35
+ durationMs: number;
36
+ };
37
+ }
38
+
39
+ // ---------------------------------------------------------------------------
40
+ // Parser
41
+ // ---------------------------------------------------------------------------
42
+
43
+ function parseMetricsJson(content: string): MetricsUnit[] {
44
+ try {
45
+ const data = JSON.parse(content);
46
+ if (!data.units || !Array.isArray(data.units)) return [];
47
+
48
+ return data.units.map((u: Record<string, unknown>) => ({
49
+ type: String(u.type ?? 'unknown'),
50
+ id: String(u.id ?? ''),
51
+ model: String(u.model ?? 'unknown'),
52
+ startedAt: Number(u.startedAt ?? 0),
53
+ finishedAt: Number(u.finishedAt ?? 0),
54
+ tokens: {
55
+ input: Number((u.tokens as Record<string, unknown>)?.input ?? 0),
56
+ output: Number((u.tokens as Record<string, unknown>)?.output ?? 0),
57
+ cacheRead: Number((u.tokens as Record<string, unknown>)?.cacheRead ?? 0),
58
+ cacheWrite: Number((u.tokens as Record<string, unknown>)?.cacheWrite ?? 0),
59
+ total: Number((u.tokens as Record<string, unknown>)?.total ?? 0),
60
+ },
61
+ cost: Number(u.cost ?? 0),
62
+ toolCalls: Number(u.toolCalls ?? 0),
63
+ apiRequests: Number(u.apiRequests ?? 0),
64
+ }));
65
+ } catch {
66
+ return [];
67
+ }
68
+ }
69
+
70
+ // ---------------------------------------------------------------------------
71
+ // Public API
72
+ // ---------------------------------------------------------------------------
73
+
74
+ export function readHistory(projectDir: string, limit?: number): HistoryResult {
75
+ const gsd = resolveGsdRoot(projectDir);
76
+
77
+ // metrics.json (primary)
78
+ const metricsPath = resolveRootFile(gsd, 'metrics.json');
79
+ let units: MetricsUnit[] = [];
80
+
81
+ if (existsSync(metricsPath)) {
82
+ const content = readFileSync(metricsPath, 'utf-8');
83
+ units = parseMetricsJson(content);
84
+ }
85
+
86
+ // Sort by startedAt descending (most recent first)
87
+ units.sort((a, b) => b.startedAt - a.startedAt);
88
+
89
+ // Apply limit
90
+ if (limit && limit > 0) {
91
+ units = units.slice(0, limit);
92
+ }
93
+
94
+ // Compute totals from ALL units (not just limited set)
95
+ const allUnits = existsSync(metricsPath)
96
+ ? parseMetricsJson(readFileSync(metricsPath, 'utf-8'))
97
+ : [];
98
+
99
+ const totals = {
100
+ cost: 0,
101
+ tokens: { input: 0, output: 0, total: 0 },
102
+ units: allUnits.length,
103
+ durationMs: 0,
104
+ };
105
+
106
+ for (const u of allUnits) {
107
+ totals.cost += u.cost;
108
+ totals.tokens.input += u.tokens.input;
109
+ totals.tokens.output += u.tokens.output;
110
+ totals.tokens.total += u.tokens.total;
111
+ totals.durationMs += (u.finishedAt - u.startedAt);
112
+ }
113
+
114
+ // Round cost to 4 decimal places
115
+ totals.cost = Math.round(totals.cost * 10000) / 10000;
116
+
117
+ return { entries: units, totals };
118
+ }