@hegemonart/get-design-done 1.31.0 → 1.31.5

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 (163) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +44 -0
  4. package/NOTICE +224 -0
  5. package/README.md +1 -1
  6. package/agents/design-authority-watcher.md +1 -1
  7. package/agents/perf-analyzer.md +2 -2
  8. package/bin/gdd-mcp +78 -0
  9. package/bin/gdd-sdk +34 -24
  10. package/bin/gdd-state-mcp +78 -0
  11. package/{README.de.md → docs/i18n/README.de.md} +1 -1
  12. package/{README.fr.md → docs/i18n/README.fr.md} +1 -1
  13. package/{README.it.md → docs/i18n/README.it.md} +1 -1
  14. package/{README.ja.md → docs/i18n/README.ja.md} +1 -1
  15. package/{README.ko.md → docs/i18n/README.ko.md} +1 -1
  16. package/{README.zh-CN.md → docs/i18n/README.zh-CN.md} +1 -1
  17. package/hooks/_hook-emit.js +1 -1
  18. package/hooks/budget-enforcer.ts +5 -5
  19. package/hooks/context-exhaustion.ts +2 -2
  20. package/hooks/gdd-precompact-snapshot.js +3 -3
  21. package/hooks/gdd-read-injection-scanner.ts +2 -2
  22. package/hooks/gdd-sessionstart-recap.js +1 -1
  23. package/hooks/gdd-turn-closeout.js +1 -1
  24. package/package.json +20 -9
  25. package/recipes/.gitkeep +0 -0
  26. package/reference/schemas/recipe.schema.json +33 -0
  27. package/scripts/cli/gdd-events.mjs +5 -5
  28. package/scripts/lib/cache/gdd-cache-manager.cjs +1 -1
  29. package/scripts/lib/cli/index.ts +22 -160
  30. package/scripts/lib/connection-probe/index.cjs +1 -1
  31. package/scripts/lib/discuss-parallel-runner/aggregator.ts +1 -1
  32. package/scripts/lib/discuss-parallel-runner/index.ts +1 -1
  33. package/scripts/lib/error-classifier.cjs +24 -227
  34. package/scripts/lib/event-stream/index.ts +25 -193
  35. package/scripts/lib/gdd-errors/index.ts +24 -213
  36. package/scripts/lib/gdd-state/index.ts +23 -161
  37. package/scripts/lib/iteration-budget.cjs +23 -199
  38. package/scripts/lib/jittered-backoff.cjs +24 -107
  39. package/scripts/lib/lockfile.cjs +23 -195
  40. package/scripts/lib/logger/index.ts +1 -1
  41. package/scripts/lib/parallelism-engine/concurrency-tuner.cjs +1 -1
  42. package/scripts/lib/perf-analyzer/index.cjs +1 -1
  43. package/scripts/lib/pipeline-runner/index.ts +4 -4
  44. package/scripts/lib/pipeline-runner/state-machine.ts +1 -1
  45. package/scripts/lib/prompt-dedup/index.cjs +1 -1
  46. package/scripts/lib/rate-guard.cjs +2 -2
  47. package/scripts/lib/recipe-loader.cjs +142 -0
  48. package/scripts/lib/session-runner/errors.ts +3 -3
  49. package/scripts/lib/session-runner/index.ts +3 -3
  50. package/scripts/lib/session-runner/transcript.ts +1 -1
  51. package/scripts/lib/tool-scoping/index.ts +1 -1
  52. package/scripts/mcp-servers/gdd-mcp/server.ts +29 -311
  53. package/scripts/mcp-servers/gdd-state/server.ts +28 -282
  54. package/sdk/README.md +45 -0
  55. package/{scripts/lib → sdk}/cli/commands/audit.ts +3 -3
  56. package/{scripts/lib → sdk}/cli/commands/init.ts +3 -3
  57. package/{scripts/lib → sdk}/cli/commands/query.ts +4 -4
  58. package/{scripts/lib → sdk}/cli/commands/run.ts +5 -5
  59. package/{scripts/lib → sdk}/cli/commands/stage.ts +5 -5
  60. package/sdk/cli/index.js +8091 -0
  61. package/sdk/cli/index.ts +172 -0
  62. package/{scripts/lib → sdk}/cli/parse-args.ts +2 -2
  63. package/{scripts/lib/gdd-errors → sdk/errors}/classification.ts +1 -1
  64. package/sdk/errors/index.ts +218 -0
  65. package/{scripts/lib → sdk}/event-stream/emitter.ts +1 -1
  66. package/sdk/event-stream/index.ts +197 -0
  67. package/{scripts/lib → sdk}/event-stream/reader.ts +1 -1
  68. package/{scripts/lib → sdk}/event-stream/types.ts +2 -2
  69. package/{scripts/lib → sdk}/event-stream/writer.ts +1 -1
  70. package/sdk/index.ts +19 -0
  71. package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/README.md +3 -3
  72. package/sdk/mcp/gdd-mcp/server.js +1924 -0
  73. package/sdk/mcp/gdd-mcp/server.ts +325 -0
  74. package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/tools/gdd_cycle_recap.ts +3 -3
  75. package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/tools/gdd_decisions_list.ts +2 -2
  76. package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/tools/gdd_events_tail.ts +3 -3
  77. package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/tools/gdd_health.ts +2 -2
  78. package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/tools/gdd_intel_get.ts +2 -2
  79. package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/tools/gdd_learnings_digest.ts +2 -2
  80. package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/tools/gdd_phase_current.ts +2 -2
  81. package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/tools/gdd_phases_list.ts +2 -2
  82. package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/tools/gdd_plans_list.ts +2 -2
  83. package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/tools/gdd_reflections_latest.ts +2 -2
  84. package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/tools/gdd_status.ts +3 -3
  85. package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/tools/gdd_telemetry_query.ts +3 -3
  86. package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/tools/index.ts +2 -2
  87. package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/tools/shared.ts +3 -3
  88. package/sdk/mcp/gdd-state/server.js +2790 -0
  89. package/sdk/mcp/gdd-state/server.ts +294 -0
  90. package/{scripts/mcp-servers → sdk/mcp}/gdd-state/tools/add_blocker.ts +3 -3
  91. package/{scripts/mcp-servers → sdk/mcp}/gdd-state/tools/add_decision.ts +3 -3
  92. package/{scripts/mcp-servers → sdk/mcp}/gdd-state/tools/add_must_have.ts +3 -3
  93. package/{scripts/mcp-servers → sdk/mcp}/gdd-state/tools/checkpoint.ts +2 -2
  94. package/{scripts/mcp-servers → sdk/mcp}/gdd-state/tools/frontmatter_update.ts +2 -2
  95. package/{scripts/mcp-servers → sdk/mcp}/gdd-state/tools/get.ts +3 -3
  96. package/{scripts/mcp-servers → sdk/mcp}/gdd-state/tools/index.ts +1 -1
  97. package/{scripts/mcp-servers → sdk/mcp}/gdd-state/tools/probe_connections.ts +3 -3
  98. package/{scripts/mcp-servers → sdk/mcp}/gdd-state/tools/resolve_blocker.ts +3 -3
  99. package/{scripts/mcp-servers → sdk/mcp}/gdd-state/tools/set_status.ts +2 -2
  100. package/{scripts/mcp-servers → sdk/mcp}/gdd-state/tools/shared.ts +8 -8
  101. package/{scripts/mcp-servers → sdk/mcp}/gdd-state/tools/transition_stage.ts +4 -4
  102. package/{scripts/mcp-servers → sdk/mcp}/gdd-state/tools/update_progress.ts +2 -2
  103. package/sdk/primitives/error-classifier.cjs +232 -0
  104. package/sdk/primitives/iteration-budget.cjs +205 -0
  105. package/sdk/primitives/jittered-backoff.cjs +112 -0
  106. package/sdk/primitives/lockfile.cjs +201 -0
  107. package/{scripts/lib/gdd-state → sdk/state}/gates.ts +1 -1
  108. package/sdk/state/index.ts +167 -0
  109. package/{scripts/lib/gdd-state → sdk/state}/lockfile.ts +1 -1
  110. package/{scripts/lib/gdd-state → sdk/state}/mutator.ts +1 -1
  111. package/{scripts/lib/gdd-state → sdk/state}/parser.ts +1 -1
  112. package/{scripts/lib/gdd-state → sdk/state}/types.ts +4 -4
  113. package/skills/quality-gate/SKILL.md +2 -2
  114. package/scripts/aggregate-agent-metrics.ts +0 -282
  115. package/scripts/bootstrap-manifest.txt +0 -3
  116. package/scripts/bootstrap.sh +0 -80
  117. package/scripts/build-distribution-bundles.cjs +0 -549
  118. package/scripts/build-intel.cjs +0 -486
  119. package/scripts/codegen-schema-types.ts +0 -149
  120. package/scripts/detect-stale-refs.cjs +0 -107
  121. package/scripts/e2e/run-headless.ts +0 -514
  122. package/scripts/extract-changelog-section.cjs +0 -58
  123. package/scripts/gsd-cleanup-incubator.cjs +0 -367
  124. package/scripts/injection-patterns.cjs +0 -58
  125. package/scripts/lint-agentskills-spec.cjs +0 -457
  126. package/scripts/release-smoke-test.cjs +0 -200
  127. package/scripts/rollback-release.sh +0 -42
  128. package/scripts/run-injection-scanner-ci.cjs +0 -83
  129. package/scripts/tests/test-authority-rejected-kinds.sh +0 -58
  130. package/scripts/tests/test-authority-watcher-diff.sh +0 -113
  131. package/scripts/tests/test-motion-provenance.sh +0 -64
  132. package/scripts/validate-frontmatter.ts +0 -409
  133. package/scripts/validate-incubator-scope.cjs +0 -133
  134. package/scripts/validate-schemas.ts +0 -401
  135. package/scripts/validate-skill-length.cjs +0 -283
  136. package/scripts/verify-version-sync.cjs +0 -30
  137. /package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/schemas/gdd_cycle_recap.schema.json +0 -0
  138. /package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/schemas/gdd_decisions_list.schema.json +0 -0
  139. /package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/schemas/gdd_events_tail.schema.json +0 -0
  140. /package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/schemas/gdd_health.schema.json +0 -0
  141. /package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/schemas/gdd_intel_get.schema.json +0 -0
  142. /package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/schemas/gdd_learnings_digest.schema.json +0 -0
  143. /package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/schemas/gdd_phase_current.schema.json +0 -0
  144. /package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/schemas/gdd_phases_list.schema.json +0 -0
  145. /package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/schemas/gdd_plans_list.schema.json +0 -0
  146. /package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/schemas/gdd_reflections_latest.schema.json +0 -0
  147. /package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/schemas/gdd_status.schema.json +0 -0
  148. /package/{scripts/mcp-servers → sdk/mcp}/gdd-mcp/schemas/gdd_telemetry_query.schema.json +0 -0
  149. /package/{scripts/mcp-servers → sdk/mcp}/gdd-state/schemas/add_blocker.schema.json +0 -0
  150. /package/{scripts/mcp-servers → sdk/mcp}/gdd-state/schemas/add_decision.schema.json +0 -0
  151. /package/{scripts/mcp-servers → sdk/mcp}/gdd-state/schemas/add_must_have.schema.json +0 -0
  152. /package/{scripts/mcp-servers → sdk/mcp}/gdd-state/schemas/checkpoint.schema.json +0 -0
  153. /package/{scripts/mcp-servers → sdk/mcp}/gdd-state/schemas/frontmatter_update.schema.json +0 -0
  154. /package/{scripts/mcp-servers → sdk/mcp}/gdd-state/schemas/get.schema.json +0 -0
  155. /package/{scripts/mcp-servers → sdk/mcp}/gdd-state/schemas/probe_connections.schema.json +0 -0
  156. /package/{scripts/mcp-servers → sdk/mcp}/gdd-state/schemas/resolve_blocker.schema.json +0 -0
  157. /package/{scripts/mcp-servers → sdk/mcp}/gdd-state/schemas/set_status.schema.json +0 -0
  158. /package/{scripts/mcp-servers → sdk/mcp}/gdd-state/schemas/transition_stage.schema.json +0 -0
  159. /package/{scripts/mcp-servers → sdk/mcp}/gdd-state/schemas/update_progress.schema.json +0 -0
  160. /package/{scripts/lib → sdk/primitives}/error-classifier.d.cts +0 -0
  161. /package/{scripts/lib → sdk/primitives}/iteration-budget.d.cts +0 -0
  162. /package/{scripts/lib → sdk/primitives}/jittered-backoff.d.cts +0 -0
  163. /package/{scripts/lib → sdk/primitives}/lockfile.d.cts +0 -0
@@ -1,317 +1,35 @@
1
- #!/usr/bin/env -S node --experimental-strip-types
2
- // scripts/mcp-servers/gdd-mcp/server.ts
1
+ // scripts/mcp-servers/gdd-mcp/server.ts — GDD-DEPRECATION-SHIM (Plan 31-5-06, SDK-05, D-02).
3
2
  //
4
- // MCP server `gdd-mcp` read-mostly project-state surface (Phase 27.7).
5
- // Exposes STATE.md sections, phases, decisions, plans, telemetry, intel
6
- // slices, and the latest reflection as typed MCP tools backed by the
7
- // same `scripts/lib/*` modules the CLI uses.
3
+ // Thin deprecation shim. The real MCP `gdd-mcp` server moved to
4
+ // sdk/mcp/gdd-mcp/server.ts in Plan 31-5-05 (SDK consolidation, D-08). This
5
+ // file is re-created at the OLD path so undocumented EXTERNAL importers /
6
+ // invokers (anyone who reached into node_modules/@hegemonart/get-design-done/
7
+ // scripts/mcp-servers/gdd-mcp/server.ts directly) keep working for one minor
8
+ // grace window.
8
9
  //
9
- // Lifecycle (mirrors Phase 20 `gdd-state` server):
10
- // 1. Construct a low-level Server (we use the low-level surface so we
11
- // can speak JSON Schema directly the high-level McpServer wants
12
- // Zod shapes, and our per-tool schemas are Draft-07 JSON.)
13
- // 2. Register `tools/list` returns the registered tools with their
14
- // input JSON Schemas loaded from disk. Scaffold ships with 0
15
- // tools; Plan 27.7-02 populates `TOOL_MODULES` with 12 entries.
16
- // 3. Register `tools/call` — dispatches by name to the matching
17
- // handler. Each handler returns a typed ToolResponse; the server
18
- // wraps it into the MCP CallToolResult shape. Unknown tool names
19
- // return `isError: true` with a structured payload.
20
- // 4. Attach StdioServerTransport; await connect. NO port allocation
21
- // (D-05 stdio-only).
22
- // 5. On SIGINT / SIGTERM: close the transport, exit 0. Re-entrant
23
- // shutdown is guarded with a module-level `SHUTTING_DOWN` flag.
10
+ // REMOVED IN v1.33.0 (D-02). Grace window: 1.31.5 ships with shims →
11
+ // 1.32.0 still has them 1.33.0 removes them. The canonical invocation is
12
+ // now the `bin/gdd-mcp` trampoline (Plan 31-5-05); internal callers already
13
+ // use the sdk/ path. This shim is external-only; 31-5-10's
14
+ // no-stale-internal-refs guard excludes files carrying the
15
+ // GDD-DEPRECATION-SHIM marker above.
24
16
  //
25
- // Project-root discovery (D-05): `resolveProjectRoot()` lives in
26
- // `./tools/shared.ts` and walks up from `process.cwd()` looking for
27
- // `.design/` OR `.planning/` OR `.claude-plugin/plugin.json`. Server
28
- // infrastructure is allowed to import `node:fs`/`node:path` directly;
29
- // only individual TOOL files are bound by the thin-wrapper rule (D-06).
30
- //
31
- // Invariant: handler throws are contained. The dispatcher wraps every
32
- // call in a try/catch that funnels through `toToolError()` — the MCP
33
- // harness never sees an uncaught throw from our tools.
34
-
35
- import { readFileSync, existsSync } from 'node:fs';
36
- import { dirname, join, resolve } from 'node:path';
37
-
38
- import { Server } from '@modelcontextprotocol/sdk/server/index.js';
39
- import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
40
- import {
41
- CallToolRequestSchema,
42
- ListToolsRequestSchema,
43
- } from '@modelcontextprotocol/sdk/types.js';
44
-
45
- import { toToolError } from '../../lib/gdd-errors/classification.ts';
46
- import { TOOL_MODULES, type ToolModule } from './tools/index.ts';
47
-
48
- /** Server metadata advertised on initialize. */
49
- export const SERVER_NAME = 'gdd-mcp';
50
- export const SERVER_VERSION = '1.27.7';
51
-
52
- /**
53
- * Resolve this module's directory. We deliberately avoid `import.meta.url`
54
- * (not permitted by our tsconfig's Node16+CommonJS-compatible module
55
- * resolution) and `__dirname` (not portable under strip-types ESM).
56
- *
57
- * Strategy: when this module is invoked as a script, `process.argv[1]`
58
- * points at this file; resolve its dirname. When it is imported for
59
- * tests, we fall back to walking from `process.cwd()` — tests run
60
- * from the repo root by convention, so `scripts/mcp-servers/gdd-mcp`
61
- * resolves reliably. Both branches are canonicalized against the
62
- * on-disk tools directory.
63
- */
64
- function here(): string {
65
- const expectedRel = join('scripts', 'mcp-servers', 'gdd-mcp');
66
- // Script invocation: process.argv[1] === .../server.ts (or a shim).
67
- const entry = process.argv[1];
68
- if (typeof entry === 'string' && entry.length > 0) {
69
- const entryDir = dirname(resolve(entry));
70
- if (existsSync(join(entryDir, 'tools', 'index.ts'))) {
71
- return entryDir;
72
- }
73
- }
74
- // Library-import path (tests): walk cwd forward.
75
- const candidate = resolve(process.cwd(), expectedRel);
76
- if (existsSync(join(candidate, 'tools', 'index.ts'))) {
77
- return candidate;
78
- }
79
- // Last-resort: return the expected path even if it does not exist —
80
- // the subsequent readFileSync() call will produce a clear error.
81
- return candidate;
82
- }
83
-
84
- /** Eager cache of input schemas keyed by tool name. We load them once at
85
- * startup so a tool-call handler never hits the filesystem in the hot
86
- * path; subsequent schema edits (JSON file on disk) require a server
87
- * restart, which matches every other part of the pipeline.
88
- *
89
- * Scaffold ships with 0 tools — loadTools() returns []. Plan 27.7-02
90
- * adds 12 tool modules, each with its own `schemaPath` pointing into
91
- * `scripts/mcp-servers/gdd-mcp/schemas/`. */
92
- interface LoadedTool extends ToolModule {
93
- inputSchema: Record<string, unknown>;
94
- }
95
-
96
- function loadTools(): LoadedTool[] {
97
- const baseDir = here();
98
- return TOOL_MODULES.map((m) => {
99
- const absPath = join(baseDir, 'tools', m.schemaPath);
100
- const raw = readFileSync(absPath, 'utf8');
101
- const parsed = JSON.parse(raw) as {
102
- properties?: {
103
- input?: { type?: string; properties?: Record<string, unknown> };
104
- };
105
- };
106
- // The per-tool schema files are Draft-07 wrappers shaped as:
107
- // { type: "object", properties: { input: {...}, output: {...} } }
108
- // MCP's tools/list advertises only the INPUT half. We project
109
- // `properties.input` here; when the schema is malformed we fall
110
- // back to an open object so the tool is still listable.
111
- const rawInput = parsed.properties?.input;
112
- const inputSchema: Record<string, unknown> =
113
- rawInput !== undefined && typeof rawInput === 'object'
114
- ? (rawInput as Record<string, unknown>)
115
- : { type: 'object' };
116
- if (!('type' in inputSchema)) inputSchema['type'] = 'object';
117
- return { ...m, inputSchema };
118
- });
119
- }
120
-
121
- /**
122
- * Tool descriptions — short, scannable, lifted from the plan. Skill
123
- * prose uses these verbatim when suggesting a tool to the model.
124
- *
125
- * Plan 27.7-02 populates 12 entries — one per tool name in the canonical
126
- * 12-tool list.
127
- */
128
- export const TOOL_DESCRIPTIONS: Record<string, string> = {
129
- gdd_status:
130
- 'gdd_status: current cycle phase, branch, last-3 decisions, last-3 completed plans, blocker count.',
131
- gdd_phase_current:
132
- 'gdd_phase_current: STATE.md <position> block (phase, stage, task_progress, status).',
133
- gdd_phases_list:
134
- 'gdd_phases_list: parsed ROADMAP.md overview (phase number, name, target version, shipped/planned).',
135
- gdd_plans_list:
136
- 'gdd_plans_list: plans tracked in STATE.md must_haves (optionally filtered by input.phase).',
137
- gdd_decisions_list:
138
- 'gdd_decisions_list: decisions from STATE.md (optionally filtered by input.status).',
139
- gdd_intel_get:
140
- 'gdd_intel_get: read a slice from .design/intel/ (input.slice_id required); directory_not_found if absent.',
141
- gdd_telemetry_query:
142
- 'gdd_telemetry_query: typed reader over .design/telemetry/*.jsonl with type/since/limit filters.',
143
- gdd_cycle_recap:
144
- 'gdd_cycle_recap: diff current STATE against latest .design/snapshots/ snapshot; directory_not_found if absent.',
145
- gdd_reflections_latest:
146
- 'gdd_reflections_latest: newest .design/reflections/ file (excerpt <= 4 KB); directory_not_found if absent.',
147
- gdd_learnings_digest:
148
- 'gdd_learnings_digest: aggregate last N reflections into a compact digest (<= 5 KB).',
149
- gdd_events_tail:
150
- 'gdd_events_tail: last-N events from .design/telemetry/events.jsonl with optional type filter.',
151
- gdd_health:
152
- 'gdd_health: read-only mirror of gdd-health SKILL — 4 checks (CLAUDE.md, .planning/, .design/, package.json).',
153
- };
154
-
155
- /** Human-readable annotation hints (MCP clients use these to style the
156
- * tool in UI). `readOnlyHint: true` — tells clients this tool does NOT
157
- * modify disk. v1 is read-only (D-04) so every entry is `true`. */
158
- export const TOOL_READONLY: Record<string, boolean> = {
159
- gdd_status: true,
160
- gdd_phase_current: true,
161
- gdd_phases_list: true,
162
- gdd_plans_list: true,
163
- gdd_decisions_list: true,
164
- gdd_intel_get: true,
165
- gdd_telemetry_query: true,
166
- gdd_cycle_recap: true,
167
- gdd_reflections_latest: true,
168
- gdd_learnings_digest: true,
169
- gdd_events_tail: true,
170
- gdd_health: true,
171
- };
172
-
173
- /**
174
- * Build the MCP server. The tools list and call handlers are the only
175
- * two request handlers we register; everything else (initialize, ping,
176
- * cancellation, shutdown) is handled internally by the Protocol class.
177
- */
178
- export function buildServer(): Server {
179
- const tools = loadTools();
180
- const byName: Map<string, LoadedTool> = new Map();
181
- for (const t of tools) byName.set(t.name, t);
182
-
183
- const server = new Server(
184
- { name: SERVER_NAME, version: SERVER_VERSION },
185
- {
186
- capabilities: { tools: {} },
187
- },
17
+ // Re-exporting the sdk/ server keeps the library surface (buildServer,
18
+ // runStdio, SERVER_NAME, SERVER_VERSION, TOOL_DESCRIPTIONS, TOOL_READONLY)
19
+ // reachable via the old path. The sdk/ server's own isMain() entry guard
20
+ // keys off process.argv[1] ending with its own sdk/ path, so a re-export
21
+ // does NOT auto-start the server direct execution should go through the
22
+ // bin trampoline. Runs under --experimental-strip-types.
23
+
24
+ import { emitWarning } from 'node:process';
25
+
26
+ let warned = false;
27
+ if (!warned) {
28
+ warned = true;
29
+ emitWarning(
30
+ 'scripts/mcp-servers/gdd-mcp/server.ts is deprecated; use the bin/gdd-mcp trampoline or import sdk/mcp/gdd-mcp instead. Removed in v1.33.0.',
31
+ 'DeprecationWarning',
188
32
  );
189
-
190
- server.setRequestHandler(ListToolsRequestSchema, async () => {
191
- return {
192
- tools: tools.map((t) => {
193
- const description = TOOL_DESCRIPTIONS[t.name] ?? t.name;
194
- const readOnly = TOOL_READONLY[t.name] ?? true;
195
- return {
196
- name: t.name,
197
- description,
198
- inputSchema: t.inputSchema as {
199
- type: 'object';
200
- properties?: Record<string, unknown>;
201
- required?: string[];
202
- },
203
- annotations: {
204
- readOnlyHint: readOnly,
205
- destructiveHint: !readOnly,
206
- idempotentHint: false,
207
- },
208
- };
209
- }),
210
- };
211
- });
212
-
213
- server.setRequestHandler(CallToolRequestSchema, async (req) => {
214
- const { name: toolName, arguments: args } = req.params;
215
- const tool = byName.get(toolName);
216
- if (tool === undefined) {
217
- // Unknown tool — return as CallToolResult isError=true so the
218
- // client gets a structured error rather than a JSON-RPC error.
219
- const payload = toToolError(
220
- new Error(`unknown tool: ${toolName}`),
221
- );
222
- return {
223
- isError: true,
224
- content: [
225
- {
226
- type: 'text' as const,
227
- text: JSON.stringify({ success: false, error: payload.error }),
228
- },
229
- ],
230
- structuredContent: { success: false, error: payload.error },
231
- };
232
- }
233
-
234
- let response;
235
- try {
236
- response = await tool.handle(args ?? {});
237
- } catch (err) {
238
- // Defensive catch — handlers shouldn't throw, but if one does
239
- // we translate rather than crashing the server.
240
- const payload = toToolError(err);
241
- response = { success: false as const, error: payload.error };
242
- }
243
-
244
- const text = JSON.stringify(response);
245
- if (response.success === true) {
246
- return {
247
- content: [{ type: 'text' as const, text }],
248
- structuredContent: response as unknown as Record<string, unknown>,
249
- };
250
- }
251
- return {
252
- isError: true,
253
- content: [{ type: 'text' as const, text }],
254
- structuredContent: response as unknown as Record<string, unknown>,
255
- };
256
- });
257
-
258
- return server;
259
- }
260
-
261
- /**
262
- * Run the server against stdio and block until the transport closes.
263
- * Called from CLI when this file is invoked as a script.
264
- */
265
- export async function runStdio(): Promise<void> {
266
- const server = buildServer();
267
- const transport = new StdioServerTransport();
268
-
269
- const shutdown = async (signal: string): Promise<void> => {
270
- // Re-entrant: signal handlers can fire more than once on flaky
271
- // shells. Guard with a module-level flag.
272
- if (SHUTTING_DOWN) return;
273
- SHUTTING_DOWN = true;
274
- try {
275
- await server.close();
276
- } catch {
277
- // best-effort; we're exiting anyway.
278
- }
279
- // SIGTERM / SIGINT convention: exit(0) — orderly shutdown.
280
- process.exit(signal === 'SIGTERM' ? 0 : 0);
281
- };
282
-
283
- process.on('SIGINT', () => {
284
- void shutdown('SIGINT');
285
- });
286
- process.on('SIGTERM', () => {
287
- void shutdown('SIGTERM');
288
- });
289
-
290
- await server.connect(transport);
291
33
  }
292
34
 
293
- /** Re-entrancy guard for `shutdown()`. */
294
- let SHUTTING_DOWN = false;
295
-
296
- /**
297
- * Are we being invoked as a script? We compare the argv[1] file path's
298
- * basename to `server.ts` — test imports never match this because
299
- * `node --test tests/*.ts` sets argv[1] to the test runner entry, not
300
- * our file. A direct `node scripts/mcp-servers/gdd-mcp/server.ts`
301
- * invocation DOES match. The Windows-safe path normalization uses
302
- * `.replace(/\\/g, '/')` before the endsWith check.
303
- */
304
- function isMain(): boolean {
305
- const entry = process.argv[1];
306
- if (typeof entry !== 'string' || entry.length === 0) return false;
307
- return entry.replace(/\\/g, '/').endsWith('scripts/mcp-servers/gdd-mcp/server.ts');
308
- }
309
-
310
- if (isMain()) {
311
- runStdio().catch((err) => {
312
- const msg = err instanceof Error ? err.message : String(err);
313
- // eslint-disable-next-line no-console
314
- console.error(`[gdd-mcp] fatal: ${msg}`);
315
- process.exit(1);
316
- });
317
- }
35
+ export * from '../../../sdk/mcp/gdd-mcp/server.ts';
@@ -1,288 +1,34 @@
1
- #!/usr/bin/env -S node --experimental-strip-types
2
- // scripts/mcp-servers/gdd-state/server.ts
1
+ // scripts/mcp-servers/gdd-state/server.ts — GDD-DEPRECATION-SHIM (Plan 31-5-06, SDK-05, D-02).
3
2
  //
4
- // MCP server `gdd-state` exposes the 11 typed STATE.md tools implemented
5
- // under `./tools/` via stdio transport. Plan 20-05 (SDK-06/07).
3
+ // Thin deprecation shim. The real MCP `gdd-state` server moved to
4
+ // sdk/mcp/gdd-state/server.ts in Plan 31-5-04 (SDK consolidation). This file
5
+ // is re-created at the OLD path so undocumented EXTERNAL importers / invokers
6
+ // (anyone who reached into node_modules/@hegemonart/get-design-done/scripts/
7
+ // mcp-servers/gdd-state/server.ts directly) keep working for one minor grace
8
+ // window.
6
9
  //
7
- // Lifecycle:
8
- // 1. Construct a low-level Server (we use the low-level surface so we
9
- // can speak JSON Schema directly the high-level McpServer wants
10
- // Zod shapes, and our per-tool schemas are Draft-07 JSON.)
11
- // 2. Register `tools/list` returns all 11 tools with their input
12
- // JSON Schemas loaded from disk.
13
- // 3. Register `tools/call` — dispatches by name to the matching
14
- // handler. Each handler returns a typed ToolResponse; the server
15
- // wraps it into the MCP CallToolResult shape (one text content
16
- // item, JSON-stringified response; plus `structuredContent` for
17
- // richer clients; `isError: true` when `success:false`).
18
- // 4. Attach StdioServerTransport; await connect.
19
- // 5. On SIGINT / SIGTERM: close the transport, flush nothing (the
20
- // event writer uses `appendFileSync` so every write is already
21
- // durable), and exit 0.
10
+ // REMOVED IN v1.33.0 (D-02). Grace window: 1.31.5 ships with shims →
11
+ // 1.32.0 still has them 1.33.0 removes them. The canonical invocation is
12
+ // now the `bin/gdd-state-mcp` trampoline (Plan 31-5-05); internal callers
13
+ // already use the sdk/ path. This shim is external-only; 31-5-10's
14
+ // no-stale-internal-refs guard excludes files carrying the
15
+ // GDD-DEPRECATION-SHIM marker above.
22
16
  //
23
- // Invariant: handler throws are contained. The dispatcher wraps every
24
- // call in a try/catch that funnels through toToolError() the MCP
25
- // harness never sees an uncaught throw from our tools.
26
-
27
- import { readFileSync, existsSync } from 'node:fs';
28
- import { dirname, join, resolve } from 'node:path';
29
-
30
- import { Server } from '@modelcontextprotocol/sdk/server/index.js';
31
- import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
32
- import {
33
- CallToolRequestSchema,
34
- ListToolsRequestSchema,
35
- } from '@modelcontextprotocol/sdk/types.js';
36
-
37
- import { toToolError } from '../../lib/gdd-errors/classification.ts';
38
- import { TOOL_MODULES, type ToolModule } from './tools/index.ts';
39
-
40
- /** Server metadata advertised on initialize. */
41
- const SERVER_NAME = 'gdd-state';
42
- const SERVER_VERSION = '1.20.0';
43
-
44
- /**
45
- * Resolve this module's directory. We deliberately avoid `import.meta.url`
46
- * (not permitted by our tsconfig's Node16+CommonJS-compatible module
47
- * resolution) and `__dirname` (not portable under strip-types ESM).
48
- *
49
- * Strategy: when this module is invoked as a script, `process.argv[1]`
50
- * points at this file; resolve its dirname. When it is imported for
51
- * tests, we fall back to walking from `process.cwd()` — tests run
52
- * from the repo root by convention, so `scripts/mcp-servers/gdd-state`
53
- * resolves reliably. Both branches are canonicalized against the
54
- * on-disk tools directory.
55
- */
56
- function here(): string {
57
- const expectedRel = join('scripts', 'mcp-servers', 'gdd-state');
58
- // Script invocation: process.argv[1] === .../server.ts (or a shim).
59
- const entry = process.argv[1];
60
- if (typeof entry === 'string' && entry.length > 0) {
61
- const entryDir = dirname(resolve(entry));
62
- if (existsSync(join(entryDir, 'tools', 'index.ts'))) {
63
- return entryDir;
64
- }
65
- }
66
- // Library-import path (tests): walk cwd forward.
67
- const candidate = resolve(process.cwd(), expectedRel);
68
- if (existsSync(join(candidate, 'tools', 'index.ts'))) {
69
- return candidate;
70
- }
71
- // Last-resort: return the expected path even if it does not exist —
72
- // the subsequent readFileSync() call will produce a clear error.
73
- return candidate;
74
- }
75
-
76
- /** Eager cache of input schemas keyed by tool name. We load them once at
77
- * startup so a tool-call handler never hits the filesystem in the hot
78
- * path; subsequent schema edits (JSON file on disk) require a server
79
- * restart, which matches every other part of the pipeline. */
80
- interface LoadedTool extends ToolModule {
81
- inputSchema: Record<string, unknown>;
82
- }
83
-
84
- function loadTools(): LoadedTool[] {
85
- const baseDir = here();
86
- return TOOL_MODULES.map((m) => {
87
- const absPath = join(baseDir, 'tools', m.schemaPath);
88
- const raw = readFileSync(absPath, 'utf8');
89
- const parsed = JSON.parse(raw) as {
90
- properties?: {
91
- input?: { type?: string; properties?: Record<string, unknown> };
92
- };
93
- };
94
- // The per-tool schema files are Draft-07 wrappers shaped as:
95
- // { type: "object", properties: { input: {...}, output: {...} } }
96
- // MCP's tools/list advertises only the INPUT half. We project
97
- // `properties.input` here; when the schema is malformed we fall
98
- // back to an open object so the tool is still listable.
99
- const rawInput = parsed.properties?.input;
100
- const inputSchema: Record<string, unknown> =
101
- rawInput !== undefined && typeof rawInput === 'object'
102
- ? (rawInput as Record<string, unknown>)
103
- : { type: 'object' };
104
- // MCP clients require inputSchema.type === "object" for tools/list.
105
- // Our per-tool inputs are already objects; defensively stamp the
106
- // field when absent.
107
- if (!('type' in inputSchema)) inputSchema['type'] = 'object';
108
- return { ...m, inputSchema };
109
- });
110
- }
111
-
112
- /**
113
- * Tool descriptions — short, scannable, lifted from the plan. Skill
114
- * prose uses these verbatim when suggesting a tool to the model.
115
- */
116
- const TOOL_DESCRIPTIONS: Record<string, string> = {
117
- gdd_state__get:
118
- 'Read current STATE.md (parsed). Read-only; no event emitted. Optionally projects a subset of fields.',
119
- gdd_state__update_progress:
120
- 'Update <position>.task_progress and/or status. Emits state.mutation.',
121
- gdd_state__transition_stage:
122
- 'Run gate and advance <position>.stage on pass. Gate vetoes return {success:false, error:{context:{blockers:[...]}}}; never crashes the server. Emits state.transition.',
123
- gdd_state__add_blocker:
124
- 'Append one entry to <blockers>. Defaults stage to current position.stage and date to today (UTC). Emits state.mutation.',
125
- gdd_state__resolve_blocker:
126
- 'Remove one <blockers> entry by 0-based index or exact text match. Returns operation_failed when no row matches. Emits state.mutation on removal.',
127
- gdd_state__add_decision:
128
- 'Append one entry to <decisions>. Auto-allocates D-N id when not supplied. Emits state.mutation.',
129
- gdd_state__add_must_have:
130
- 'Append one entry to <must_haves>. Auto-allocates M-N id when not supplied. Emits state.mutation.',
131
- gdd_state__set_status:
132
- 'Update <position>.status. Emits state.mutation.',
133
- gdd_state__checkpoint:
134
- 'Update frontmatter.last_checkpoint and append a <timestamps> entry. Emits state.mutation.',
135
- gdd_state__probe_connections:
136
- 'Merge probe results into <connections>. Overwrites keys present in the input; does NOT delete keys not in the input. Emits state.mutation.',
137
- gdd_state__frontmatter_update:
138
- 'Patch one or more frontmatter fields. Rejects pipeline_state_version and stage (use transition_stage). Emits state.mutation.',
139
- };
140
-
141
- /** Human-readable annotation hints (MCP clients use these to style the
142
- * tool in UI). `readOnlyHint: true` — tells clients this tool does NOT
143
- * modify disk; `false` — tells them it does. */
144
- const TOOL_READONLY: Record<string, boolean> = {
145
- gdd_state__get: true,
146
- };
147
-
148
- /**
149
- * Build the MCP server. The tools list and call handlers are the only
150
- * two request handlers we register; everything else (initialize, ping,
151
- * cancellation, shutdown) is handled internally by the Protocol class.
152
- */
153
- export function buildServer(): Server {
154
- const tools = loadTools();
155
- const byName: Map<string, LoadedTool> = new Map();
156
- for (const t of tools) byName.set(t.name, t);
157
-
158
- const server = new Server(
159
- { name: SERVER_NAME, version: SERVER_VERSION },
160
- {
161
- capabilities: { tools: {} },
162
- },
17
+ // Re-exporting the sdk/ server keeps the library surface (buildServer,
18
+ // runStdio) reachable via the old path. The sdk/ server's own isMain()
19
+ // entry guard keys off process.argv[1] ending with its own sdk/ path, so a
20
+ // re-export does NOT auto-start the server — direct execution should go
21
+ // through the bin trampoline. Runs under --experimental-strip-types.
22
+
23
+ import { emitWarning } from 'node:process';
24
+
25
+ let warned = false;
26
+ if (!warned) {
27
+ warned = true;
28
+ emitWarning(
29
+ 'scripts/mcp-servers/gdd-state/server.ts is deprecated; use the bin/gdd-state-mcp trampoline or import sdk/mcp/gdd-state instead. Removed in v1.33.0.',
30
+ 'DeprecationWarning',
163
31
  );
164
-
165
- server.setRequestHandler(ListToolsRequestSchema, async () => {
166
- return {
167
- tools: tools.map((t) => {
168
- const description = TOOL_DESCRIPTIONS[t.name] ?? t.name;
169
- const readOnly = TOOL_READONLY[t.name] ?? false;
170
- return {
171
- name: t.name,
172
- description,
173
- inputSchema: t.inputSchema as {
174
- type: 'object';
175
- properties?: Record<string, unknown>;
176
- required?: string[];
177
- },
178
- annotations: {
179
- readOnlyHint: readOnly,
180
- destructiveHint: !readOnly,
181
- idempotentHint: false,
182
- },
183
- };
184
- }),
185
- };
186
- });
187
-
188
- server.setRequestHandler(CallToolRequestSchema, async (req) => {
189
- const { name: toolName, arguments: args } = req.params;
190
- const tool = byName.get(toolName);
191
- if (tool === undefined) {
192
- // Unknown tool — return as CallToolResult isError=true so the
193
- // client gets a structured error rather than a JSON-RPC error.
194
- const payload = toToolError(
195
- new Error(`unknown tool: ${toolName}`),
196
- );
197
- return {
198
- isError: true,
199
- content: [
200
- { type: 'text' as const, text: JSON.stringify({ success: false, error: payload.error }) },
201
- ],
202
- structuredContent: { success: false, error: payload.error },
203
- };
204
- }
205
-
206
- let response;
207
- try {
208
- response = await tool.handle(args ?? {});
209
- } catch (err) {
210
- // Defensive catch — handlers shouldn't throw, but if one does
211
- // we translate rather than crashing the server.
212
- const payload = toToolError(err);
213
- response = { success: false as const, error: payload.error };
214
- }
215
-
216
- const text = JSON.stringify(response);
217
- if (response.success === true) {
218
- return {
219
- content: [{ type: 'text' as const, text }],
220
- structuredContent: response as unknown as Record<string, unknown>,
221
- };
222
- }
223
- return {
224
- isError: true,
225
- content: [{ type: 'text' as const, text }],
226
- structuredContent: response as unknown as Record<string, unknown>,
227
- };
228
- });
229
-
230
- return server;
231
- }
232
-
233
- /**
234
- * Run the server against stdio and block until the transport closes.
235
- * Called from CLI when this file is invoked as a script.
236
- */
237
- export async function runStdio(): Promise<void> {
238
- const server = buildServer();
239
- const transport = new StdioServerTransport();
240
-
241
- const shutdown = async (signal: string): Promise<void> => {
242
- // Re-entrant: signal handlers can fire more than once on flaky
243
- // shells. Guard with a module-level flag.
244
- if (SHUTTING_DOWN) return;
245
- SHUTTING_DOWN = true;
246
- try {
247
- await server.close();
248
- } catch {
249
- // best-effort; we're exiting anyway.
250
- }
251
- // SIGTERM / SIGINT convention: exit(0) — orderly shutdown.
252
- process.exit(signal === 'SIGTERM' ? 0 : 0);
253
- };
254
-
255
- process.on('SIGINT', () => {
256
- void shutdown('SIGINT');
257
- });
258
- process.on('SIGTERM', () => {
259
- void shutdown('SIGTERM');
260
- });
261
-
262
- await server.connect(transport);
263
32
  }
264
33
 
265
- /** Re-entrancy guard for `shutdown()`. */
266
- let SHUTTING_DOWN = false;
267
-
268
- /**
269
- * Are we being invoked as a script? We compare the argv[1] file path's
270
- * basename to `server.ts` — test imports never match this because
271
- * `node --test tests/*.ts` sets argv[1] to the test runner entry, not
272
- * our file. A direct `node scripts/mcp-servers/gdd-state/server.ts`
273
- * invocation DOES match.
274
- */
275
- function isMain(): boolean {
276
- const entry = process.argv[1];
277
- if (typeof entry !== 'string' || entry.length === 0) return false;
278
- return entry.replace(/\\/g, '/').endsWith('scripts/mcp-servers/gdd-state/server.ts');
279
- }
280
-
281
- if (isMain()) {
282
- runStdio().catch((err) => {
283
- const msg = err instanceof Error ? err.message : String(err);
284
- // eslint-disable-next-line no-console
285
- console.error(`[gdd-state] fatal: ${msg}`);
286
- process.exit(1);
287
- });
288
- }
34
+ export * from '../../../sdk/mcp/gdd-state/server.ts';