@rsaglobaltech/specgate 0.12.1 → 0.14.0

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/CHANGELOG.md +164 -0
  2. package/README.md +66 -58
  3. package/bin/specgate.ts +35 -0
  4. package/dist/bin/specgate.js +31 -0
  5. package/dist/bin/specgate.js.map +1 -1
  6. package/dist/packages/core/src/application/ArchiveChangeUseCase.js +22 -0
  7. package/dist/packages/core/src/application/ArchiveChangeUseCase.js.map +1 -1
  8. package/dist/packages/core/src/application/ValidateProjectUseCase.js +12 -5
  9. package/dist/packages/core/src/application/ValidateProjectUseCase.js.map +1 -1
  10. package/dist/packages/core/src/domain/AgentPrompt.js +2 -1
  11. package/dist/packages/core/src/domain/AgentPrompt.js.map +1 -1
  12. package/dist/packages/core/src/domain/DeltaFeature.js +39 -0
  13. package/dist/packages/core/src/domain/DeltaFeature.js.map +1 -0
  14. package/dist/packages/core/src/domain/DerivedMatrix.js +25 -19
  15. package/dist/packages/core/src/domain/DerivedMatrix.js.map +1 -1
  16. package/dist/packages/core/src/domain/RequirementReadiness.js +7 -2
  17. package/dist/packages/core/src/domain/RequirementReadiness.js.map +1 -1
  18. package/dist/packages/core/src/domain/SpecSections.js +1 -1
  19. package/dist/packages/core/src/domain/SpecSections.js.map +1 -1
  20. package/dist/packages/core/test/unit/delta-feature.test.js +74 -0
  21. package/dist/packages/core/test/unit/delta-feature.test.js.map +1 -0
  22. package/dist/packages/mcp-spec-driven/src/native-tools.js +256 -0
  23. package/dist/packages/mcp-spec-driven/src/native-tools.js.map +1 -0
  24. package/dist/packages/mcp-spec-driven/src/server.js +276 -0
  25. package/dist/packages/mcp-spec-driven/src/server.js.map +1 -0
  26. package/dist/packages/mcp-spec-driven/src/tools.js +684 -0
  27. package/dist/packages/mcp-spec-driven/src/tools.js.map +1 -0
  28. package/dist/scripts/agents/init.js +1 -1
  29. package/dist/scripts/agents/init.js.map +1 -1
  30. package/dist/scripts/alm/cli.js +4 -0
  31. package/dist/scripts/alm/cli.js.map +1 -1
  32. package/dist/scripts/change/instructions.js +5 -4
  33. package/dist/scripts/change/instructions.js.map +1 -1
  34. package/dist/scripts/cli/commands/config/CiInitCommand.js +47 -3
  35. package/dist/scripts/cli/commands/config/CiInitCommand.js.map +1 -1
  36. package/dist/scripts/cli/commands/harness/RunCommand.js +3 -2
  37. package/dist/scripts/cli/commands/harness/RunCommand.js.map +1 -1
  38. package/dist/scripts/cli/commands/mcp/McpInstallCommand.js +8 -2
  39. package/dist/scripts/cli/commands/mcp/McpInstallCommand.js.map +1 -1
  40. package/dist/scripts/cli/commands/mcp/index.js +52 -0
  41. package/dist/scripts/cli/commands/mcp/index.js.map +1 -1
  42. package/dist/scripts/cli/commands/pack/ExpandDomainPackCommand.js +38 -0
  43. package/dist/scripts/cli/commands/pack/ExpandDomainPackCommand.js.map +1 -1
  44. package/dist/scripts/cli/commands/project/OnboardCommand.js +1 -1
  45. package/dist/scripts/cli/commands/project/OnboardCommand.js.map +1 -1
  46. package/dist/scripts/cli/commands/quality/DoctorCommand.js +4 -2
  47. package/dist/scripts/cli/commands/quality/DoctorCommand.js.map +1 -1
  48. package/dist/scripts/cli/commands/quality/ValidateSpecsCommand.js +27 -10
  49. package/dist/scripts/cli/commands/quality/ValidateSpecsCommand.js.map +1 -1
  50. package/dist/scripts/cli/commands/spec/DoneCommand.js +39 -7
  51. package/dist/scripts/cli/commands/spec/DoneCommand.js.map +1 -1
  52. package/dist/scripts/cli/commands/spec/StatusCommand.js +27 -6
  53. package/dist/scripts/cli/commands/spec/StatusCommand.js.map +1 -1
  54. package/dist/scripts/docs/blocks.js +4 -1
  55. package/dist/scripts/docs/blocks.js.map +1 -1
  56. package/dist/scripts/docs/build-site.js +1 -1
  57. package/dist/scripts/docs/nav.js +23 -3
  58. package/dist/scripts/docs/nav.js.map +1 -1
  59. package/dist/scripts/gen_mcp_tools.js +20 -4
  60. package/dist/scripts/gen_mcp_tools.js.map +1 -1
  61. package/dist/scripts/lib/derived-writes.js +21 -6
  62. package/dist/scripts/lib/derived-writes.js.map +1 -1
  63. package/dist/scripts/lib/surface.js +15 -12
  64. package/dist/scripts/lib/surface.js.map +1 -1
  65. package/package.json +12 -3
  66. package/templates/adopt/spec.md.tpl +5 -6
@@ -0,0 +1,256 @@
1
+ "use strict";
2
+ /**
3
+ * The three MCP tools that are not a CLI command behind a shell.
4
+ *
5
+ * Everything else in `tools.ts` is generated from `scripts/lib/surface.ts` — one
6
+ * definition, one tool per command. These three are not: `read_spec` and
7
+ * `list_requirements` read files the CLI has no read-only command for, and
8
+ * `update_traceability` appends a matrix row. #138 replaced the hand-written
9
+ * registry with the generated one and dropped them, which broke every agent
10
+ * configured against the published seven-tool surface and left this package's
11
+ * own tests red. An MCP tool id lives in someone else's agent config, so it is
12
+ * removed on purpose or not at all.
13
+ *
14
+ * They live here rather than in `tools.ts` because that file is regenerated:
15
+ * anything hand-written inside it is deleted the next time the generator runs.
16
+ */
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
24
+ }) : (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ }));
28
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
30
+ }) : function(o, v) {
31
+ o["default"] = v;
32
+ });
33
+ var __importStar = (this && this.__importStar) || (function () {
34
+ var ownKeys = function(o) {
35
+ ownKeys = Object.getOwnPropertyNames || function (o) {
36
+ var ar = [];
37
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
38
+ return ar;
39
+ };
40
+ return ownKeys(o);
41
+ };
42
+ return function (mod) {
43
+ if (mod && mod.__esModule) return mod;
44
+ var result = {};
45
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
46
+ __setModuleDefault(result, mod);
47
+ return result;
48
+ };
49
+ })();
50
+ Object.defineProperty(exports, "__esModule", { value: true });
51
+ exports.UpdateTraceabilityTool = exports.ListRequirementsTool = exports.ReadSpecTool = void 0;
52
+ exports.hasOpenChange = hasOpenChange;
53
+ exports.contractEditsAllowed = contractEditsAllowed;
54
+ exports.assertContractEditable = assertContractEditable;
55
+ const fs = __importStar(require("node:fs"));
56
+ const path = __importStar(require("node:path"));
57
+ /**
58
+ * The change cycle is the reviewable way to edit a specification (C10-04).
59
+ *
60
+ * `docs/specs/changes/<id>/` is an open change; `archive/` is not one. Read
61
+ * from disk on every call rather than cached, because the agent may have opened
62
+ * the change through the CLI in another terminal.
63
+ */
64
+ function hasOpenChange(projectDir) {
65
+ const dir = path.join(projectDir, "docs", "specs", "changes");
66
+ try {
67
+ return fs
68
+ .readdirSync(dir, { withFileTypes: true })
69
+ .some((e) => e.isDirectory() && e.name !== "archive");
70
+ }
71
+ catch {
72
+ return false;
73
+ }
74
+ }
75
+ /**
76
+ * An escape hatch that has to be written down, never passed by the caller.
77
+ *
78
+ * If the agent could send `allowContractEdits: true` with the call, the guard
79
+ * would protect nothing — it would be one more sentence for the agent to
80
+ * ignore, which is what this guard exists to replace. A person puts this in
81
+ * `.csda/config.json`, and it is visible in the repository afterwards.
82
+ */
83
+ function contractEditsAllowed(projectDir) {
84
+ try {
85
+ const raw = fs.readFileSync(path.join(projectDir, ".csda", "config.json"), "utf8");
86
+ return JSON.parse(raw).mcpAllowContractEdits === true;
87
+ }
88
+ catch {
89
+ return false;
90
+ }
91
+ }
92
+ /** Refuse a contract-editing call outside the change cycle. */
93
+ function assertContractEditable(toolName, projectDir) {
94
+ if (hasOpenChange(projectDir) || contractEditsAllowed(projectDir))
95
+ return;
96
+ throw new Error(toolName +
97
+ " writes files the specification contract protects, and no change is open." +
98
+ " Open one first: specgate change new <id>." +
99
+ ' To allow it permanently, set "mcpAllowContractEdits": true in .csda/config.json.');
100
+ }
101
+ class ProjectHelper {
102
+ static ensureProjectDir(projectDir) {
103
+ if (!projectDir || typeof projectDir !== "string") {
104
+ throw new Error("projectDir is required (absolute path to a spec-driven project)");
105
+ }
106
+ if (!fs.existsSync(projectDir)) {
107
+ throw new Error(`projectDir does not exist: ${projectDir}`);
108
+ }
109
+ const specFile = path.join(projectDir, "spec.md");
110
+ if (!fs.existsSync(specFile)) {
111
+ throw new Error(`Not a spec-driven project (no spec.md): ${projectDir}`);
112
+ }
113
+ return projectDir;
114
+ }
115
+ }
116
+ class ReadSpecTool {
117
+ name = "read_spec";
118
+ description = "Read the spec.md file (and list other spec markdown) of a spec-driven project.";
119
+ inputSchema = {
120
+ type: "object",
121
+ properties: {
122
+ projectDir: {
123
+ type: "string",
124
+ description: "Absolute path to the spec-driven project root.",
125
+ },
126
+ },
127
+ required: ["projectDir"],
128
+ };
129
+ handler(args) {
130
+ const dir = ProjectHelper.ensureProjectDir(args.projectDir);
131
+ const specMd = fs.readFileSync(path.join(dir, "spec.md"), "utf8");
132
+ const docsSpecsDir = path.join(dir, "docs", "specs");
133
+ const files = [];
134
+ if (fs.existsSync(docsSpecsDir)) {
135
+ for (const entry of fs.readdirSync(docsSpecsDir, { withFileTypes: true })) {
136
+ if (entry.isFile() && entry.name.endsWith(".md")) {
137
+ files.push(path.join("docs/specs", entry.name));
138
+ }
139
+ }
140
+ }
141
+ return { specMd, files: files.sort() };
142
+ }
143
+ }
144
+ exports.ReadSpecTool = ReadSpecTool;
145
+ class ListRequirementsTool {
146
+ name = "list_requirements";
147
+ description = "List every REQ-NNN in the project with its title, source file, and line number.";
148
+ inputSchema = {
149
+ type: "object",
150
+ properties: {
151
+ projectDir: {
152
+ type: "string",
153
+ description: "Absolute path to the spec-driven project root.",
154
+ },
155
+ },
156
+ required: ["projectDir"],
157
+ };
158
+ static REQ_LINE = /\bREQ-(\d{3,})\b/g;
159
+ static REQ_HEADING = /^(##+)\s*(REQ-\d{3,})\b\s*[:\-—]?\s*(.*)$/m;
160
+ handler(args) {
161
+ const dir = ProjectHelper.ensureProjectDir(args.projectDir);
162
+ const sources = [
163
+ { file: "spec.md", path: path.join(dir, "spec.md") },
164
+ { file: "docs/specs/traceability.md", path: path.join(dir, "docs/specs/traceability.md") },
165
+ ];
166
+ const requirements = new Map();
167
+ for (const source of sources) {
168
+ if (!fs.existsSync(source.path))
169
+ continue;
170
+ const lines = fs.readFileSync(source.path, "utf8").split("\n");
171
+ for (let i = 0; i < lines.length; i++) {
172
+ const line = lines[i];
173
+ ListRequirementsTool.REQ_LINE.lastIndex = 0;
174
+ let match;
175
+ while ((match = ListRequirementsTool.REQ_LINE.exec(line)) !== null) {
176
+ const id = `REQ-${match[1]}`;
177
+ if (!requirements.has(id)) {
178
+ let title = "";
179
+ const headingMatch = line.match(ListRequirementsTool.REQ_HEADING);
180
+ if (headingMatch && headingMatch[2] === id) {
181
+ title = (headingMatch[3] || "").trim();
182
+ }
183
+ else {
184
+ const idx = line.indexOf(id);
185
+ title = line
186
+ .slice(idx + id.length)
187
+ .replace(/^[\s:\-—|]+/, "")
188
+ .replace(/\|.*$/, "")
189
+ .trim();
190
+ }
191
+ requirements.set(id, { id, title, file: source.file, line: i });
192
+ }
193
+ }
194
+ }
195
+ }
196
+ return {
197
+ requirements: Array.from(requirements.values()).sort((a, b) => a.id.localeCompare(b.id)),
198
+ };
199
+ }
200
+ }
201
+ exports.ListRequirementsTool = ListRequirementsTool;
202
+ class UpdateTraceabilityTool {
203
+ name = "update_traceability";
204
+ description = "Append a row to the traceability matrix. Idempotent.";
205
+ inputSchema = {
206
+ type: "object",
207
+ properties: {
208
+ projectDir: { type: "string" },
209
+ requirement: { type: "string", description: "e.g. REQ-001" },
210
+ scenario: { type: "string", description: "e.g. SCN-005 (optional)" },
211
+ feature: {
212
+ type: "string",
213
+ description: "Path to the .feature file (relative to project root)",
214
+ },
215
+ status: { type: "string", enum: ["Draft", "Approved", "Implemented", "Verified"] },
216
+ },
217
+ required: ["projectDir", "requirement", "feature", "status"],
218
+ };
219
+ handler(args) {
220
+ const dir = ProjectHelper.ensureProjectDir(args.projectDir);
221
+ // Deliberately *not* behind `assertContractEditable`, and the reason is the
222
+ // same one `WriteScope` gives for exempting new files: this tool appends a
223
+ // row and returns `{ updated: false }` when a matching one already exists.
224
+ // It cannot loosen a term of the contract, only add one — and a requirement
225
+ // in `NEEDS_FEATURE` is supposed to get its row. `req link`, which rewrites
226
+ // an existing row, is guarded.
227
+ const tracePath = path.join(dir, "docs/specs/traceability.md");
228
+ if (!fs.existsSync(tracePath)) {
229
+ throw new Error("docs/specs/traceability.md not found in this project");
230
+ }
231
+ const required = ["requirement", "feature", "status"];
232
+ for (const k of required) {
233
+ if (!args[k])
234
+ throw new Error(`Missing argument: ${k}`);
235
+ }
236
+ const content = fs.readFileSync(tracePath, "utf8");
237
+ // A generated matrix is rebuilt from spec.md and the feature tags; a row
238
+ // appended here would vanish on the next regeneration.
239
+ if (content.includes("<!-- specgate:derived")) {
240
+ throw new Error("docs/specs/traceability.md is generated. Add the requirement with `specgate new`, " +
241
+ "or tag its scenario @REQ-NNN @SCN-NNN, then run `specgate matrix`.");
242
+ }
243
+ const tag = `${args.requirement}.*${args.feature}`;
244
+ if (new RegExp(tag).test(content)) {
245
+ return { updated: false, rowsAdded: 0 };
246
+ }
247
+ const isRich = content.includes("| Requirement | Scenario ID | Feature file | Use Case | Command/Query | Aggregate | Event | Technical artifact | Test artifact | Status |");
248
+ const row = isRich
249
+ ? `| ${args.requirement} | ${args.scenario || "TBD"} | \`${args.feature}\` | TBD | TBD | TBD | TBD | TBD | TBD | ${args.status} |`
250
+ : `| \`${args.feature}\` | ${args.requirement} | ${args.scenario || "TBD"} | ${args.status} |`;
251
+ fs.appendFileSync(tracePath, `\n${row}\n`, "utf8");
252
+ return { updated: true, rowsAdded: 1 };
253
+ }
254
+ }
255
+ exports.UpdateTraceabilityTool = UpdateTraceabilityTool;
256
+ //# sourceMappingURL=native-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-tools.js","sourceRoot":"","sources":["../../../../packages/mcp-spec-driven/src/native-tools.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBH,sCASC;AAUD,oDAOC;AAGD,wDAQC;AAvDD,4CAA8B;AAC9B,gDAAkC;AAUlC;;;;;;GAMG;AACH,SAAgB,aAAa,CAAC,UAAkB;IAC9C,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAC9D,IAAI,CAAC;QACH,OAAO,EAAE;aACN,WAAW,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;aACzC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;IAC1D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,oBAAoB,CAAC,UAAkB;IACrD,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,EAAE,aAAa,CAAC,EAAE,MAAM,CAAC,CAAC;QACnF,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,qBAAqB,KAAK,IAAI,CAAC;IACxD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,+DAA+D;AAC/D,SAAgB,sBAAsB,CAAC,QAAg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AAC,OAAO,CAAC,EAAE,CAAC;YAClC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;QAC1C,CAAC;QAED,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAC7B,2IAA2I,CAC5I,CAAC;QACF,MAAM,GAAG,GAAG,MAAM;YAChB,CAAC,CAAC,KAAK,IAAI,CAAC,WAAW,MAAM,IAAI,CAAC,QAAQ,IAAI,KAAK,QAAQ,IAAI,CAAC,OAAO,4CAA4C,IAAI,CAAC,MAAM,IAAI;YAClI,CAAC,CAAC,OAAO,IAAI,CAAC,OAAO,QAAQ,IAAI,CAAC,WAAW,MAAM,IAAI,CAAC,QAAQ,IAAI,KAAK,MAAM,IAAI,CAAC,MAAM,IAAI,CAAC;QAEjG,EAAE,CAAC,cAAc,CAAC,SAAS,EAAE,KAAK,GAAG,IAAI,EAAE,MAAM,CAAC,CAAC;QACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IACzC,CAAC;CACF;AA5DD,wDA4DC"}
@@ -0,0 +1,276 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.writeMessage = exports.readMessage = exports.handleMessage = exports.defaultServer = exports.McpServer = void 0;
38
+ /**
39
+ * MCP server for create-spec-driven-app projects.
40
+ *
41
+ * Implements the Model Context Protocol over stdio (JSON-RPC 2.0).
42
+ * Supported methods: initialize, tools/list, tools/call.
43
+ *
44
+ * This is a minimal hand-rolled implementation — no @modelcontextprotocol/sdk
45
+ * dependency — to keep the install footprint small. It implements the subset
46
+ * required by Claude Desktop, Cursor, Aider, and other MCP-aware clients.
47
+ */
48
+ const tools_1 = require("./tools");
49
+ const fs = __importStar(require("node:fs"));
50
+ const path = __importStar(require("node:path"));
51
+ const PROTOCOL_VERSION = "2024-11-05";
52
+ /**
53
+ * This file is compiled into two layouts: the repository's root `dist/` for the
54
+ * test suite, and the package's own `dist/` for publishing. A fixed relative
55
+ * path to package.json resolves in one and not the other, so walk up for it.
56
+ */
57
+ function packageVersion() {
58
+ let dir = __dirname;
59
+ for (let i = 0; i < 6; i++) {
60
+ const candidate = path.join(dir, "package.json");
61
+ if (fs.existsSync(candidate)) {
62
+ try {
63
+ const pkg = JSON.parse(fs.readFileSync(candidate, "utf8"));
64
+ // This package's own manifest, whatever it is called. Matching on an
65
+ // exact name is what made this announce 0.0.0 twice: once when a path
66
+ // assumption broke, and again when the CLI package became
67
+ // `@rsaglobaltech/specgate` and a hard-coded `"specgate"` stopped matching.
68
+ // The shape of the tree is the stable signal, not the spelling.
69
+ const sibling = path.join(dir, "packages", "mcp-spec-driven", "package.json");
70
+ if (fs.existsSync(sibling)) {
71
+ // Reached the repository root: the manifest is beside it, not above
72
+ // the compiled file, because the root build flattens into dist/.
73
+ return JSON.parse(fs.readFileSync(sibling, "utf8")).version;
74
+ }
75
+ // Shipped inside the CLI package and started by `specgate mcp serve`:
76
+ // the server is that package's version.
77
+ if (typeof pkg.name === "string" &&
78
+ (pkg.name.endsWith("/mcp-server") || pkg.name === "@rsaglobaltech/specgate")) {
79
+ return pkg.version;
80
+ }
81
+ }
82
+ catch {
83
+ // Keep walking — a malformed manifest above us is not ours.
84
+ }
85
+ }
86
+ const parent = path.dirname(dir);
87
+ if (parent === dir)
88
+ break;
89
+ dir = parent;
90
+ }
91
+ return "0.0.0";
92
+ }
93
+ const SERVER_INFO = {
94
+ name: "mcp-spec-driven",
95
+ version: packageVersion(),
96
+ };
97
+ // ── JSON-RPC framing over stdio ──────────────────────────────────────────────────
98
+ class McpServer {
99
+ buffer = "";
100
+ start() {
101
+ process.stdin.setEncoding("utf8");
102
+ process.stdin.on("data", (chunk) => {
103
+ const messages = this.readMessage(chunk);
104
+ for (const msg of messages) {
105
+ this.handleMessage(msg);
106
+ }
107
+ });
108
+ process.stdin.on("end", () => {
109
+ this.stop();
110
+ });
111
+ // Log activation to stderr so clients see it (stdout is reserved for JSON-RPC)
112
+ process.stderr.write(`mcp-spec-driven ${SERVER_INFO.version} ready\n`);
113
+ }
114
+ stop() {
115
+ process.exit(0);
116
+ }
117
+ readMessage(chunk) {
118
+ this.buffer += chunk.toString();
119
+ const messages = [];
120
+ // Try Content-Length framing first (per LSP/MCP convention)
121
+ while (true) {
122
+ const headerEnd = this.buffer.indexOf("\r\n\r\n");
123
+ if (headerEnd === -1)
124
+ break;
125
+ const headers = this.buffer.slice(0, headerEnd);
126
+ const lengthMatch = headers.match(/Content-Length:\s*(\d+)/i);
127
+ if (!lengthMatch) {
128
+ // Bad header — drop until next \r\n\r\n
129
+ this.buffer = this.buffer.slice(headerEnd + 4);
130
+ continue;
131
+ }
132
+ const length = parseInt(lengthMatch[1], 10);
133
+ const messageStart = headerEnd + 4;
134
+ if (this.buffer.length < messageStart + length)
135
+ break;
136
+ const body = this.buffer.slice(messageStart, messageStart + length);
137
+ this.buffer = this.buffer.slice(messageStart + length);
138
+ try {
139
+ messages.push(JSON.parse(body));
140
+ }
141
+ catch (err) {
142
+ const error = err;
143
+ this.writeError(null, -32700, `Parse error: ${error.message}`);
144
+ }
145
+ }
146
+ // Also try newline-delimited JSON (used by some clients)
147
+ if (messages.length === 0 && this.buffer.includes("\n")) {
148
+ const lines = this.buffer.split("\n");
149
+ this.buffer = lines.pop() || "";
150
+ for (const line of lines) {
151
+ const trimmed = line.trim();
152
+ if (!trimmed)
153
+ continue;
154
+ try {
155
+ messages.push(JSON.parse(trimmed));
156
+ }
157
+ catch {
158
+ // not JSON — ignore (probably a Content-Length header fragment)
159
+ }
160
+ }
161
+ }
162
+ return messages;
163
+ }
164
+ writeMessage(message) {
165
+ const body = JSON.stringify(message);
166
+ const out = `Content-Length: ${Buffer.byteLength(body, "utf8")}\r\n\r\n${body}`;
167
+ process.stdout.write(out);
168
+ }
169
+ writeError(id, code, message, data) {
170
+ this.writeMessage({
171
+ jsonrpc: "2.0",
172
+ id,
173
+ error: { code, message, ...(data !== undefined ? { data } : {}) },
174
+ });
175
+ }
176
+ writeResult(id, result) {
177
+ this.writeMessage({ jsonrpc: "2.0", id, result });
178
+ }
179
+ // ── Method dispatch ──────────────────────────────────────────────────────────────────────
180
+ handleMessage(msg) {
181
+ if (msg.jsonrpc !== "2.0") {
182
+ this.writeError(msg.id || null, -32600, "Invalid request: missing jsonrpc=2.0");
183
+ return;
184
+ }
185
+ const { id = null, method, params } = msg;
186
+ try {
187
+ switch (method) {
188
+ case "initialize":
189
+ this.writeResult(id, {
190
+ protocolVersion: PROTOCOL_VERSION,
191
+ serverInfo: SERVER_INFO,
192
+ capabilities: { tools: {} },
193
+ });
194
+ break;
195
+ case "initialized":
196
+ case "notifications/initialized":
197
+ // Notification — no response
198
+ break;
199
+ case "tools/list":
200
+ this.writeResult(id, {
201
+ tools: Object.entries(tools_1.TOOLS).map(([name, t]) => ({
202
+ name,
203
+ description: t.description,
204
+ inputSchema: t.inputSchema,
205
+ })),
206
+ });
207
+ break;
208
+ case "tools/call": {
209
+ const toolName = params && params.name;
210
+ const args = (params && params.arguments) || {};
211
+ // `csda_*` was the generated prefix until 0.12: an agent config
212
+ // that allow-lists a tool by that name keeps resolving. The old
213
+ // names are accepted here and never listed.
214
+ const tool = tools_1.TOOLS[toolName] ||
215
+ (typeof toolName === "string" && toolName.startsWith("csda_")
216
+ ? tools_1.TOOLS[`specgate_${toolName.slice("csda_".length)}`]
217
+ : undefined);
218
+ if (!tool) {
219
+ this.writeError(id, -32601, `Unknown tool: ${toolName}`);
220
+ break;
221
+ }
222
+ try {
223
+ const result = tool.handler(args);
224
+ this.writeResult(id, {
225
+ content: [
226
+ {
227
+ type: "text",
228
+ text: JSON.stringify(result, null, 2),
229
+ },
230
+ ],
231
+ isError: false,
232
+ });
233
+ }
234
+ catch (err) {
235
+ const error = err;
236
+ this.writeResult(id, {
237
+ content: [{ type: "text", text: `Error: ${error.message}` }],
238
+ isError: true,
239
+ });
240
+ }
241
+ break;
242
+ }
243
+ case "ping":
244
+ this.writeResult(id, {});
245
+ break;
246
+ case "shutdown":
247
+ this.writeResult(id, null);
248
+ this.stop();
249
+ break;
250
+ default:
251
+ if (id !== undefined && id !== null) {
252
+ this.writeError(id, -32601, `Method not found: ${method}`);
253
+ }
254
+ // else: notification — ignore unknown notifications
255
+ }
256
+ }
257
+ catch (err) {
258
+ const error = err;
259
+ this.writeError(id, -32603, `Internal error: ${error.message}`);
260
+ }
261
+ }
262
+ }
263
+ exports.McpServer = McpServer;
264
+ if (require.main === module) {
265
+ const server = new McpServer();
266
+ server.start();
267
+ }
268
+ // Export a default instance for tests to bind to
269
+ exports.defaultServer = new McpServer();
270
+ const handleMessage = (msg) => exports.defaultServer.handleMessage(msg);
271
+ exports.handleMessage = handleMessage;
272
+ const readMessage = (chunk) => exports.defaultServer.readMessage(chunk);
273
+ exports.readMessage = readMessage;
274
+ const writeMessage = (msg) => exports.defaultServer.writeMessage(msg);
275
+ exports.writeMessage = writeMessage;
276
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../../../packages/mcp-spec-driven/src/server.ts"],"names":[],"mappings":";AACA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEb;;;;;;;;;GASG;AAEH,mCAAgC;AAChC,4CAA8B;AAC9B,gDAAkC;AAElC,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAoBtC;;;;GAIG;AACH,SAAS,cAAc;IACrB,IAAI,GAAG,GAAG,SAAS,CAAC;IACpB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;QACjD,IAAI,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YAC7B,IAAI,CAAC;gBACH,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;gBAC3D,qEAAqE;gBACrE,sEAAsE;gBACtE,0DAA0D;gBAC1D,4EAA4E;gBAC5E,gEAAgE;gBAChE,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,iBAAiB,EAAE,cAAc,CAAC,CAAC;gBAC9E,IAAI,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;oBAC3B,oEAAoE;oBACpE,iEAAiE;oBACjE,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC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