specpilot 2.12.0 → 2.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.
- package/README.md +48 -9
- package/dist/cli.js +2 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/backfill.d.ts.map +1 -1
- package/dist/commands/backfill.js +24 -13
- package/dist/commands/backfill.js.map +1 -1
- package/dist/commands/serve.d.ts +8 -1
- package/dist/commands/serve.d.ts.map +1 -1
- package/dist/commands/serve.js +89 -3
- package/dist/commands/serve.js.map +1 -1
- package/dist/core/agentConfig.d.ts +10 -0
- package/dist/core/agentConfig.d.ts.map +1 -1
- package/dist/core/agentConfig.js +47 -3
- package/dist/core/agentConfig.js.map +1 -1
- package/dist/core/ideConfig.d.ts.map +1 -1
- package/dist/core/ideConfig.js +2 -1
- package/dist/core/ideConfig.js.map +1 -1
- package/dist/core/slashCommands.d.ts.map +1 -1
- package/dist/core/slashCommands.js +25 -16
- package/dist/core/slashCommands.js.map +1 -1
- package/dist/core/specFiles.js +3 -0
- package/dist/core/specFiles.js.map +1 -1
- package/dist/core/templateEngine.d.ts +5 -0
- package/dist/core/templateEngine.d.ts.map +1 -1
- package/dist/core/templateEngine.js +13 -1
- package/dist/core/templateEngine.js.map +1 -1
- package/dist/utils/addSpecsQuestions.d.ts.map +1 -1
- package/dist/utils/addSpecsQuestions.js +2 -0
- package/dist/utils/addSpecsQuestions.js.map +1 -1
- package/dist/utils/folderPicker.d.ts +28 -0
- package/dist/utils/folderPicker.d.ts.map +1 -0
- package/dist/utils/folderPicker.js +96 -0
- package/dist/utils/folderPicker.js.map +1 -0
- package/dist/utils/gitClone.d.ts +4 -1
- package/dist/utils/gitClone.d.ts.map +1 -1
- package/dist/utils/gitClone.js +35 -4
- package/dist/utils/gitClone.js.map +1 -1
- package/dist/utils/mcpLocal.d.ts +46 -0
- package/dist/utils/mcpLocal.d.ts.map +1 -0
- package/dist/utils/mcpLocal.js +220 -0
- package/dist/utils/mcpLocal.js.map +1 -0
- package/dist/utils/projectDetector.d.ts +15 -0
- package/dist/utils/projectDetector.d.ts.map +1 -1
- package/dist/utils/projectDetector.js +105 -4
- package/dist/utils/projectDetector.js.map +1 -1
- package/dist/utils/slashCommandGenerator.d.ts +21 -0
- package/dist/utils/slashCommandGenerator.d.ts.map +1 -1
- package/dist/utils/slashCommandGenerator.js +166 -0
- package/dist/utils/slashCommandGenerator.js.map +1 -1
- package/dist/utils/specArchiver.d.ts.map +1 -1
- package/dist/utils/specArchiver.js +2 -1
- package/dist/utils/specArchiver.js.map +1 -1
- package/dist/utils/specBackfiller.d.ts +9 -3
- package/dist/utils/specBackfiller.d.ts.map +1 -1
- package/dist/utils/specBackfiller.js +52 -48
- package/dist/utils/specBackfiller.js.map +1 -1
- package/dist/utils/specPaths.d.ts +3 -2
- package/dist/utils/specPaths.d.ts.map +1 -1
- package/dist/utils/specPaths.js +6 -4
- package/dist/utils/specPaths.js.map +1 -1
- package/dist/utils/specServer.d.ts +15 -3
- package/dist/utils/specServer.d.ts.map +1 -1
- package/dist/utils/specServer.js +220 -20
- package/dist/utils/specServer.js.map +1 -1
- package/dist/utils/specSetup.d.ts +11 -0
- package/dist/utils/specSetup.d.ts.map +1 -1
- package/dist/utils/specSetup.js +14 -1
- package/dist/utils/specSetup.js.map +1 -1
- package/package.json +5 -2
- package/ui/app.css +23 -17
- package/ui/app.js +159 -69
- package/ui/index.html +10 -8
- package/ui/route.js +56 -31
- package/dist/__tests__/fixtures/allFields.d.ts +0 -3
- package/dist/__tests__/fixtures/allFields.d.ts.map +0 -1
- package/dist/__tests__/fixtures/allFields.js +0 -31
- package/dist/__tests__/fixtures/allFields.js.map +0 -1
package/dist/utils/gitClone.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export declare const MAX_URL_LENGTH = 2048;
|
|
|
3
3
|
export declare const CLONE_TIMEOUT_MS: number;
|
|
4
4
|
/** Longest git message returned to the page. */
|
|
5
5
|
export declare const MAX_GIT_LINE = 300;
|
|
6
|
+
export type CloneStage = 'receiving' | 'resolving' | 'updating';
|
|
6
7
|
/** What is wrong with a repository URL, or null. Pure string checks: the URL is never parsed or rewritten. */
|
|
7
8
|
export declare function cloneUrlError(url: string): string | null;
|
|
8
9
|
/**
|
|
@@ -37,6 +38,8 @@ export interface CloneOptions {
|
|
|
37
38
|
timeoutMs?: number;
|
|
38
39
|
/** Aborting kills the clone: the page went away, or the server is closing. */
|
|
39
40
|
signal?: AbortSignal;
|
|
41
|
+
/** Called each time git's progress changes stage or whole percentage (BL-PM-009). */
|
|
42
|
+
onProgress?: (stage: CloneStage, percent: number) => void;
|
|
40
43
|
/** Tests only (a local bare repository needs `file`). The server never passes it and no request field maps to it. */
|
|
41
44
|
allowProtocols?: string;
|
|
42
45
|
}
|
|
@@ -48,7 +51,7 @@ export type CloneResult = {
|
|
|
48
51
|
error: string;
|
|
49
52
|
};
|
|
50
53
|
/**
|
|
51
|
-
* `git clone --no-recurse-submodules -- <url> <target>` in the target's parent, without a shell, with
|
|
54
|
+
* `git clone --progress --no-recurse-submodules -- <url> <target>` in the target's parent, without a shell, with
|
|
52
55
|
* stdin closed and, on POSIX, in its own session (no controlling terminal; one process group to kill).
|
|
53
56
|
* `spawn` and not `execFile`, which cannot start a detached child; both take an argument array.
|
|
54
57
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gitClone.d.ts","sourceRoot":"","sources":["../../src/utils/gitClone.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,cAAc,OAAO,CAAC;AACnC,4DAA4D;AAC5D,eAAO,MAAM,gBAAgB,QAAiB,CAAC;AAC/C,gDAAgD;AAChD,eAAO,MAAM,YAAY,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"gitClone.d.ts","sourceRoot":"","sources":["../../src/utils/gitClone.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,cAAc,OAAO,CAAC;AACnC,4DAA4D;AAC5D,eAAO,MAAM,gBAAgB,QAAiB,CAAC;AAC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EAAE,MAAM,EAAE,IAAI,GAAE,YAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CAmE1G;AAED;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAW1F"}
|
package/dist/utils/gitClone.js
CHANGED
|
@@ -34,6 +34,13 @@ const URL_FORMS = [
|
|
|
34
34
|
const SPACE_OR_CONTROL = /[\s\u0000-\u0020\u007f-\u00a0\u2028\u2029]/;
|
|
35
35
|
// eslint-disable-next-line no-control-regex
|
|
36
36
|
const ANSI_AND_CONTROL = /\u001b\[[0-9;?]*[ -/]*[@-~]|[\u0000-\u001f\u007f-\u009f\u2028\u2029]/g;
|
|
37
|
+
/** The stages of git's progress the page shows (BL-PM-009), by git's own words under `LC_MESSAGES=C`. */
|
|
38
|
+
const STAGES = { 'Receiving objects': 'receiving', 'Resolving deltas': 'resolving', 'Updating files': 'updating' };
|
|
39
|
+
const STAGE_LINE = /^(Receiving objects|Resolving deltas|Updating files): +([0-9]{1,3})% \(/;
|
|
40
|
+
/** Any progress line of git's: never shown as its error. */
|
|
41
|
+
const PROGRESS_LINE = /^[A-Z][A-Za-z ]+: +[0-9]{1,3}% \(/;
|
|
42
|
+
/** Longest run of stderr without a line break kept for the next read; a longer one is not progress. */
|
|
43
|
+
const MAX_CARRY = 300;
|
|
37
44
|
/** What is wrong with a repository URL, or null. Pure string checks: the URL is never parsed or rewritten. */
|
|
38
45
|
function cloneUrlError(url) {
|
|
39
46
|
if (!url.length || url.length > exports.MAX_URL_LENGTH)
|
|
@@ -127,7 +134,7 @@ function probeGit(home, platform = process.platform) {
|
|
|
127
134
|
* the last line left.
|
|
128
135
|
*/
|
|
129
136
|
function gitErrorLine(stderr) {
|
|
130
|
-
const lines = stderr.split(/\r?\n|\r/).map(line => line.replace(ANSI_AND_CONTROL, '').trim()).filter(l => l && !l.startsWith('remote:') && !l.startsWith('Cloning into '));
|
|
137
|
+
const lines = stderr.split(/\r?\n|\r/).map(line => line.replace(ANSI_AND_CONTROL, '').trim()).filter(l => l && !l.startsWith('remote:') && !l.startsWith('Cloning into ') && !PROGRESS_LINE.test(l));
|
|
131
138
|
if (!lines.length)
|
|
132
139
|
return null;
|
|
133
140
|
const fatal = lines.map(l => l.startsWith('fatal:')).lastIndexOf(true);
|
|
@@ -138,7 +145,7 @@ function gitErrorLine(stderr) {
|
|
|
138
145
|
return room > 0 ? `${lines[fatal - 1].slice(0, room)} ${last}` : last;
|
|
139
146
|
}
|
|
140
147
|
/**
|
|
141
|
-
* `git clone --no-recurse-submodules -- <url> <target>` in the target's parent, without a shell, with
|
|
148
|
+
* `git clone --progress --no-recurse-submodules -- <url> <target>` in the target's parent, without a shell, with
|
|
142
149
|
* stdin closed and, on POSIX, in its own session (no controlling terminal; one process group to kill).
|
|
143
150
|
* `spawn` and not `execFile`, which cannot start a detached child; both take an argument array.
|
|
144
151
|
*/
|
|
@@ -150,7 +157,7 @@ function cloneRepository(url, target, opts = {}) {
|
|
|
150
157
|
const env = gitEnv(opts.allowProtocols ?? 'https:ssh');
|
|
151
158
|
if (opts.batchSsh)
|
|
152
159
|
env.GIT_SSH_COMMAND = 'ssh -oBatchMode=yes';
|
|
153
|
-
const child = (0, child_process_1.spawn)('git', ['clone', '--no-recurse-submodules', '--', url, target], {
|
|
160
|
+
const child = (0, child_process_1.spawn)('git', ['clone', '--progress', '--no-recurse-submodules', '--', url, target], {
|
|
154
161
|
cwd: (0, path_1.dirname)(target), env, stdio: ['ignore', 'ignore', 'pipe'], detached: posix, windowsHide: true,
|
|
155
162
|
});
|
|
156
163
|
let stderr = '';
|
|
@@ -179,8 +186,32 @@ function cloneRepository(url, target, opts = {}) {
|
|
|
179
186
|
opts.signal?.removeEventListener('abort', onAbort);
|
|
180
187
|
done(result);
|
|
181
188
|
};
|
|
189
|
+
// git rewrites a progress line with `\r` and ends it with `\n`; a line cut between two reads is
|
|
190
|
+
// joined first. null: inside a run longer than MAX_CARRY, dropped up to the next line break.
|
|
191
|
+
let carry = '';
|
|
192
|
+
let last = '';
|
|
193
|
+
const readProgress = (text) => {
|
|
194
|
+
const lines = text.split(/\r|\n/);
|
|
195
|
+
const tail = lines.pop();
|
|
196
|
+
if (lines.length) {
|
|
197
|
+
lines[0] = carry === null ? '' : carry + lines[0];
|
|
198
|
+
carry = '';
|
|
199
|
+
}
|
|
200
|
+
if (carry !== null)
|
|
201
|
+
carry = carry.length + tail.length > MAX_CARRY ? null : carry + tail;
|
|
202
|
+
for (const line of lines) {
|
|
203
|
+
const m = STAGE_LINE.exec(line.replace(ANSI_AND_CONTROL, ''));
|
|
204
|
+
if (!m || +m[2] > 100 || `${m[1]} ${+m[2]}` === last)
|
|
205
|
+
continue;
|
|
206
|
+
last = `${m[1]} ${+m[2]}`;
|
|
207
|
+
opts.onProgress(STAGES[m[1]], +m[2]);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
182
210
|
child.stderr.on('data', (chunk) => {
|
|
183
|
-
|
|
211
|
+
const text = chunk.toString('utf-8');
|
|
212
|
+
stderr = (stderr + text).slice(-65536);
|
|
213
|
+
if (opts.onProgress && !finished && !stopped)
|
|
214
|
+
readProgress(text); // nothing once git is being stopped or has ended
|
|
184
215
|
});
|
|
185
216
|
child.on('error', err => {
|
|
186
217
|
const code = err.code;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gitClone.js","sourceRoot":"","sources":["../../src/utils/gitClone.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"gitClone.js","sourceRoot":"","sources":["../../src/utils/gitClone.ts"],"names":[],"mappings":";;;AAwCA,sCAMC;AAYD,0CAkBC;AA2BD,4BAUC;AAQD,oCAQC;AAqBD,0CAmEC;AAOD,kCAWC;AA3OD,iDAAgD;AAChD,2BAAoC;AACpC,+BAA4C;AAC5C,mDAAmD;AACnD,uDAAmD;AAEnD,qGAAqG;AACrG,sGAAsG;AACtG,gG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KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,OAAO,CAAC,CAAC;IACtD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** Protocol revisions served, newest first: the initialize-based ones without JSON-RPC batches. */
|
|
2
|
+
export declare const MCP_VERSIONS: string[];
|
|
3
|
+
/** The handshake-free revision: version, client and capabilities in every request's `_meta`. */
|
|
4
|
+
export declare const MCP_MODERN = "2026-07-28";
|
|
5
|
+
/** Every revision served, newest first, as `server/discover` and -32022 list them. */
|
|
6
|
+
export declare const MCP_ALL_VERSIONS: string[];
|
|
7
|
+
/** The request headers 2026-07-28 mirrors from the body, every value sent (Node joins repeats in `req.headers`). */
|
|
8
|
+
export type McpHeaders = Record<'mcp-protocol-version' | 'mcp-method' | 'mcp-name', string[]>;
|
|
9
|
+
export declare function mirroredHeaders(rawHeaders: string[]): McpHeaders;
|
|
10
|
+
/** A refused tool call: shown to the agent as a tool result with `isError: true`. */
|
|
11
|
+
export declare class ToolRefusal extends Error {
|
|
12
|
+
}
|
|
13
|
+
export interface McpTool {
|
|
14
|
+
name: string;
|
|
15
|
+
title: string;
|
|
16
|
+
description: string;
|
|
17
|
+
inputSchema: Record<string, unknown>;
|
|
18
|
+
annotations: Record<string, boolean>;
|
|
19
|
+
/** Writes a file: absent with `--read-only`. */
|
|
20
|
+
writes: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare const MCP_TOOLS: McpTool[];
|
|
23
|
+
export interface McpReply {
|
|
24
|
+
/** HTTP status; 202 has no body. */
|
|
25
|
+
status: number;
|
|
26
|
+
body?: unknown;
|
|
27
|
+
}
|
|
28
|
+
export declare const rpcError: (id: unknown, code: number, message: string) => {
|
|
29
|
+
jsonrpc: string;
|
|
30
|
+
id: {} | null;
|
|
31
|
+
error: {
|
|
32
|
+
code: number;
|
|
33
|
+
message: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
type Call = (name: string, args: Record<string, unknown>) => Promise<{
|
|
37
|
+
text: string;
|
|
38
|
+
data?: Record<string, unknown>;
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Answer one parsed JSON-RPC message. `headers` are the mirrored request headers, every value sent;
|
|
42
|
+
* `call` runs a tool and returns what it found, or throws ToolRefusal with the reason.
|
|
43
|
+
*/
|
|
44
|
+
export declare function answerMcp(msg: unknown, headers: McpHeaders, tools: McpTool[], version: string, call: Call): Promise<McpReply>;
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=mcpLocal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcpLocal.d.ts","sourceRoot":"","sources":["../../src/utils/mcpLocal.ts"],"names":[],"mappings":"AAMA,mGAAmG;AACnG,eAAO,MAAM,YAAY,UAA+B,CAAC;AACzD,gGAAgG;AAChG,eAAO,MAAM,UAAU,eAAe,CAAC;AACvC,sFAAsF;AACtF,eAAO,MAAM,gBAAgB,UAAgC,CAAC;AAG9D,oHAAoH;AACpH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,sBAAsB,GAAG,YAAY,GAAG,UAAU,EAAE,MAAM,EAAE,CAAC,CAAC;AAE9F,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,UAAU,CAOhE;AAwBD,qFAAqF;AACrF,qBAAa,WAAY,SAAQ,KAAK;CAAG;AAEzC,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,gDAAgD;IAChD,MAAM,EAAE,OAAO,CAAC;CACjB;AASD,eAAO,MAAM,SAAS,EAAE,OAAO,EAyD9B,CAAC;AAEF,MAAM,WAAW,QAAQ;IACvB,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,eAAO,MAAM,QAAQ,GAAI,IAAI,OAAO,EAAE,MAAM,MAAM,EAAE,SAAS,MAAM;;;;;;;CAAmE,CAAC;AAEvI,KAAK,IAAI,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,CAAC,CAAC;AAoBvH;;;GAGG;AACH,wBAAsB,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,CAkCnI"}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The local MCP endpoint of `specpilot serve --mcp` (BL-PM-007, REQ-002.H.33, ARCH-004.50, SEC-004.20):
|
|
3
|
+
// the protocol only. Stateless Streamable HTTP, JSON answers, written by hand so no SDK or schema library
|
|
4
|
+
// is added (SEC-004.4). The tools run the page's own functions; specServer.ts supplies them as `call`.
|
|
5
|
+
// Revision 2026-07-28 (BL-089, SEC-004.21) is served beside them: a request whose `_meta` names a protocol
|
|
6
|
+
// version is answered by its rules, every other message as before.
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.rpcError = exports.MCP_TOOLS = exports.ToolRefusal = exports.MCP_ALL_VERSIONS = exports.MCP_MODERN = exports.MCP_VERSIONS = void 0;
|
|
9
|
+
exports.mirroredHeaders = mirroredHeaders;
|
|
10
|
+
exports.answerMcp = answerMcp;
|
|
11
|
+
/** Protocol revisions served, newest first: the initialize-based ones without JSON-RPC batches. */
|
|
12
|
+
exports.MCP_VERSIONS = ['2025-11-25', '2025-06-18'];
|
|
13
|
+
/** The handshake-free revision: version, client and capabilities in every request's `_meta`. */
|
|
14
|
+
exports.MCP_MODERN = '2026-07-28';
|
|
15
|
+
/** Every revision served, newest first, as `server/discover` and -32022 list them. */
|
|
16
|
+
exports.MCP_ALL_VERSIONS = [exports.MCP_MODERN, ...exports.MCP_VERSIONS];
|
|
17
|
+
const META = 'io.modelcontextprotocol/';
|
|
18
|
+
function mirroredHeaders(rawHeaders) {
|
|
19
|
+
const out = { 'mcp-protocol-version': [], 'mcp-method': [], 'mcp-name': [] };
|
|
20
|
+
for (let i = 0; i + 1 < rawHeaders.length; i += 2) {
|
|
21
|
+
const name = rawHeaders[i].toLowerCase();
|
|
22
|
+
if (name in out)
|
|
23
|
+
out[name].push(rawHeaders[i + 1]);
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
/** An `Mcp-Name` value: `=?base64?…?=` decoded as UTF-8, undefined when that cannot be done exactly. */
|
|
28
|
+
function decodeName(value) {
|
|
29
|
+
const m = /^=\?base64\?(.*)\?=$/.exec(value);
|
|
30
|
+
if (!m)
|
|
31
|
+
return value;
|
|
32
|
+
if (Buffer.from(m[1], 'base64').toString('base64') !== m[1])
|
|
33
|
+
return undefined;
|
|
34
|
+
try {
|
|
35
|
+
return new TextDecoder('utf-8', { fatal: true }).decode(Buffer.from(m[1], 'base64'));
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** Why a mirrored header does not stand for the body's value, or undefined when it does. */
|
|
42
|
+
function headerMismatch(header, sent, body, decode = (v) => v) {
|
|
43
|
+
if (sent.length === 0)
|
|
44
|
+
return `Header mismatch: ${header} header is missing`;
|
|
45
|
+
if (sent.length > 1)
|
|
46
|
+
return `Header mismatch: ${header} header was sent ${sent.length} times`;
|
|
47
|
+
const value = decode(sent[0]);
|
|
48
|
+
if (value === undefined)
|
|
49
|
+
return `Header mismatch: ${header} header value '${sent[0]}' could not be decoded`;
|
|
50
|
+
if (value !== body)
|
|
51
|
+
return `Header mismatch: ${header} header value '${sent[0]}' does not match body value '${String(body)}'`;
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
/** A refused tool call: shown to the agent as a tool result with `isError: true`. */
|
|
55
|
+
class ToolRefusal extends Error {
|
|
56
|
+
}
|
|
57
|
+
exports.ToolRefusal = ToolRefusal;
|
|
58
|
+
const project = { type: 'integer', minimum: 0, description: 'Index of the served project, as specpilot_list_projects gives it. Default 0.' };
|
|
59
|
+
const sha256 = { type: 'string', description: 'The tasks.md hash specpilot_list_tasks returned. A stale hash is refused and nothing is written.' };
|
|
60
|
+
const section = { type: 'string', enum: ['backlog', 'currentSprint'] };
|
|
61
|
+
const READ = { readOnlyHint: true, idempotentHint: true, destructiveHint: false, openWorldHint: false };
|
|
62
|
+
const WRITE = { readOnlyHint: false, idempotentHint: false, destructiveHint: false, openWorldHint: false };
|
|
63
|
+
const schema = (properties, required = []) => ({ type: 'object', properties: { project, ...properties }, required, additionalProperties: false });
|
|
64
|
+
exports.MCP_TOOLS = [
|
|
65
|
+
{
|
|
66
|
+
name: 'specpilot_list_projects',
|
|
67
|
+
title: 'SpecPilot: list served projects',
|
|
68
|
+
description: 'The projects this specpilot serve shows: index, name, folder, git branch, whether .specs/ exists, and the spec file paths specpilot_read_spec accepts.',
|
|
69
|
+
inputSchema: { type: 'object', properties: {}, additionalProperties: false },
|
|
70
|
+
annotations: READ,
|
|
71
|
+
writes: false,
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: 'specpilot_read_spec',
|
|
75
|
+
title: 'SpecPilot: read a spec file',
|
|
76
|
+
description: 'The text of one file, verbatim: a .specs/ file, or an instruction, command or skill file the page also shows (e.g. CLAUDE.md).',
|
|
77
|
+
inputSchema: schema({ path: { type: 'string', description: 'Project-relative path, e.g. .specs/project/requirements.md' } }, ['path']),
|
|
78
|
+
annotations: READ,
|
|
79
|
+
writes: false,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: 'specpilot_list_tasks',
|
|
83
|
+
title: 'SpecPilot: list tasks',
|
|
84
|
+
description: 'The rows of .specs/planning/tasks.md by section (Backlog, Current Sprint, Completed), verbatim, and the file hash (sha256) the task writes need.',
|
|
85
|
+
inputSchema: schema({}),
|
|
86
|
+
annotations: READ,
|
|
87
|
+
writes: false,
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: 'specpilot_new_task',
|
|
91
|
+
title: 'SpecPilot: add a task',
|
|
92
|
+
description: 'Add one row to Backlog (BL-###) or Current Sprint (CS-###) in .specs/planning/tasks.md, with the next free ID. The description is one line, without |.',
|
|
93
|
+
inputSchema: schema({ description: { type: 'string' }, section, sha256 }, ['description', 'section', 'sha256']),
|
|
94
|
+
annotations: WRITE,
|
|
95
|
+
writes: true,
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: 'specpilot_move_task',
|
|
99
|
+
title: 'SpecPilot: move a task',
|
|
100
|
+
description: 'Move one row of .specs/planning/tasks.md to Backlog or Current Sprint at a 0-based position. The row itself is not changed.',
|
|
101
|
+
inputSchema: schema({ id: { type: 'string' }, toSection: section, toIndex: { type: 'integer', minimum: 0 }, sha256 }, ['id', 'toSection', 'toIndex', 'sha256']),
|
|
102
|
+
annotations: WRITE,
|
|
103
|
+
writes: true,
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
name: 'specpilot_validate_specs',
|
|
107
|
+
title: 'SpecPilot: validate specs',
|
|
108
|
+
description: 'The checks of specpilot validate, without --fix: errors and warnings as it words them. Writes nothing.',
|
|
109
|
+
inputSchema: schema({}),
|
|
110
|
+
annotations: READ,
|
|
111
|
+
writes: false,
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
name: 'specpilot_regenerate_commands',
|
|
115
|
+
title: 'SpecPilot: regenerate commands',
|
|
116
|
+
description: "specpilot backfill's command step: adds missing specpilot-* command files and updates unedited ones for each IDE in use; everything else is kept and listed.",
|
|
117
|
+
inputSchema: schema({}),
|
|
118
|
+
annotations: WRITE,
|
|
119
|
+
writes: true,
|
|
120
|
+
},
|
|
121
|
+
];
|
|
122
|
+
const rpcError = (id, code, message) => ({ jsonrpc: '2.0', id: id ?? null, error: { code, message } });
|
|
123
|
+
exports.rpcError = rpcError;
|
|
124
|
+
const listTools = (tools) => tools.map(t => ({ name: t.name, title: t.title, description: t.description, inputSchema: t.inputSchema, annotations: t.annotations }));
|
|
125
|
+
/** tools/call, the same in both eras: an unknown tool or arguments that are not an object are -32602 with 200. */
|
|
126
|
+
async function runTool(id, params, tools, call) {
|
|
127
|
+
const ok = (result) => ({ status: 200, body: { jsonrpc: '2.0', id, result } });
|
|
128
|
+
const tool = tools.find(t => t.name === params.name);
|
|
129
|
+
if (!tool)
|
|
130
|
+
return { status: 200, body: (0, exports.rpcError)(id, -32602, `Unknown tool: ${String(params.name)}`) };
|
|
131
|
+
const args = params.arguments === undefined ? {} : params.arguments;
|
|
132
|
+
if (typeof args !== 'object' || args === null || Array.isArray(args))
|
|
133
|
+
return { status: 200, body: (0, exports.rpcError)(id, -32602, 'Tool arguments must be an object.') };
|
|
134
|
+
try {
|
|
135
|
+
const out = await call(tool.name, args);
|
|
136
|
+
return ok({ content: [{ type: 'text', text: out.text }], ...(out.data ? { structuredContent: out.data } : {}) });
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
if (err instanceof ToolRefusal)
|
|
140
|
+
return ok({ content: [{ type: 'text', text: err.message }], isError: true });
|
|
141
|
+
throw err;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Answer one parsed JSON-RPC message. `headers` are the mirrored request headers, every value sent;
|
|
146
|
+
* `call` runs a tool and returns what it found, or throws ToolRefusal with the reason.
|
|
147
|
+
*/
|
|
148
|
+
async function answerMcp(msg, headers, tools, version, call) {
|
|
149
|
+
if (Array.isArray(msg))
|
|
150
|
+
return { status: 400, body: (0, exports.rpcError)(null, -32600, 'Batches are not supported: send one JSON-RPC message per request.') };
|
|
151
|
+
const m = msg;
|
|
152
|
+
if (!m || typeof m !== 'object' || m.jsonrpc !== '2.0' || typeof m.method !== 'string') {
|
|
153
|
+
return { status: 400, body: (0, exports.rpcError)(m && typeof m === 'object' ? m.id : null, -32600, 'Not a JSON-RPC 2.0 request.') };
|
|
154
|
+
}
|
|
155
|
+
const params = (m.params && typeof m.params === 'object' ? m.params : {});
|
|
156
|
+
const meta = params._meta && typeof params._meta === 'object' ? params._meta : {};
|
|
157
|
+
if (`${META}protocolVersion` in meta) {
|
|
158
|
+
if (m.id === undefined)
|
|
159
|
+
return { status: 202 }; // 2026-07-28 defines no client notification over HTTP
|
|
160
|
+
return answerModern(m.id, m.method, params, meta, headers, tools, version, call);
|
|
161
|
+
}
|
|
162
|
+
// After initialize the client names the agreed revision on every request; a missing header is the
|
|
163
|
+
// spec's backwards-compatible case and is served the same way.
|
|
164
|
+
const sent = headers['mcp-protocol-version'];
|
|
165
|
+
const header = sent.length ? sent.join(', ') : undefined;
|
|
166
|
+
if (m.method !== 'initialize' && header !== undefined && !exports.MCP_VERSIONS.includes(header)) {
|
|
167
|
+
return { status: 400, body: (0, exports.rpcError)(m.id, -32000, `Bad Request: Unsupported protocol version: ${header} (supported versions: ${exports.MCP_VERSIONS.join(', ')})`) };
|
|
168
|
+
}
|
|
169
|
+
if (m.id === undefined)
|
|
170
|
+
return { status: 202 }; // a notification, e.g. notifications/initialized
|
|
171
|
+
const ok = (result) => ({ status: 200, body: { jsonrpc: '2.0', id: m.id, result } });
|
|
172
|
+
if (m.method === 'initialize') {
|
|
173
|
+
const asked = params.protocolVersion;
|
|
174
|
+
return ok({
|
|
175
|
+
protocolVersion: typeof asked === 'string' && exports.MCP_VERSIONS.includes(asked) ? asked : exports.MCP_VERSIONS[0],
|
|
176
|
+
capabilities: { tools: {} },
|
|
177
|
+
serverInfo: { name: 'specpilot-local', version },
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
if (m.method === 'ping')
|
|
181
|
+
return ok({});
|
|
182
|
+
if (m.method === 'tools/list')
|
|
183
|
+
return ok({ tools: listTools(tools) });
|
|
184
|
+
if (m.method === 'tools/call')
|
|
185
|
+
return runTool(m.id, params, tools, call);
|
|
186
|
+
return { status: 200, body: (0, exports.rpcError)(m.id, -32601, `Method not found: ${m.method}`) };
|
|
187
|
+
}
|
|
188
|
+
/** A 2026-07-28 request: version, mirrored headers and capabilities checked, in that order, before any dispatch. */
|
|
189
|
+
async function answerModern(id, method, params, meta, headers, tools, version, call) {
|
|
190
|
+
const fail = (status, code, message, data) => ({
|
|
191
|
+
status,
|
|
192
|
+
body: { jsonrpc: '2.0', id, error: { code, message, ...(data === undefined ? {} : { data }) } },
|
|
193
|
+
});
|
|
194
|
+
const asked = meta[`${META}protocolVersion`];
|
|
195
|
+
if (asked !== exports.MCP_MODERN)
|
|
196
|
+
return fail(400, -32022, 'Unsupported protocol version', { supported: exports.MCP_ALL_VERSIONS, requested: asked });
|
|
197
|
+
const mismatch = headerMismatch('MCP-Protocol-Version', headers['mcp-protocol-version'], asked) ??
|
|
198
|
+
headerMismatch('Mcp-Method', headers['mcp-method'], method) ??
|
|
199
|
+
(method === 'tools/call' ? headerMismatch('Mcp-Name', headers['mcp-name'], params.name, decodeName) : undefined);
|
|
200
|
+
if (mismatch)
|
|
201
|
+
return fail(400, -32020, mismatch);
|
|
202
|
+
const caps = meta[`${META}clientCapabilities`];
|
|
203
|
+
if (!caps || typeof caps !== 'object' || Array.isArray(caps))
|
|
204
|
+
return fail(400, -32602, `Invalid params: _meta ${META}clientCapabilities is required.`);
|
|
205
|
+
const serverInfo = { [`${META}serverInfo`]: { name: 'specpilot-local', version } };
|
|
206
|
+
// ttlMs 0 and private: the list holds for one run of serve only, and comes from a token-guarded endpoint.
|
|
207
|
+
const cache = { ttlMs: 0, cacheScope: 'private' };
|
|
208
|
+
const ok = (result) => ({ status: 200, body: { jsonrpc: '2.0', id, result: { resultType: 'complete', ...result, _meta: serverInfo } } });
|
|
209
|
+
if (method === 'server/discover')
|
|
210
|
+
return ok({ supportedVersions: exports.MCP_ALL_VERSIONS, capabilities: { tools: {} }, ...cache });
|
|
211
|
+
if (method === 'tools/list')
|
|
212
|
+
return ok({ tools: listTools(tools), ...cache });
|
|
213
|
+
if (method === 'tools/call') {
|
|
214
|
+
const reply = await runTool(id, params, tools, call);
|
|
215
|
+
const body = reply.body;
|
|
216
|
+
return body.result ? ok(body.result) : reply;
|
|
217
|
+
}
|
|
218
|
+
return fail(404, -32601, `Method not found: ${method}`);
|
|
219
|
+
}
|
|
220
|
+
//# sourceMappingURL=mcpLocal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcpLocal.js","sourceRoot":"","sources":["../../src/utils/mcpLocal.ts"],"names":[],"mappings":";AAAA,wGAAwG;AACxG,0GAA0G;AAC1G,uGAAuG;AACvG,2GAA2G;AAC3G,mEAAmE;;;AAanE,0CAOC;AAuID,8BAkCC;AA3LD,mGAAmG;AACtF,QAAA,YAAY,GAAG,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;AACzD,gGAAgG;AACnF,QAAA,UAAU,GAAG,YAAY,CAAC;AACvC,sFAAsF;AACzE,QAAA,gBAAgB,GAAG,CAAC,kBAAU,EAAE,GAAG,oBAAY,CAAC,CAAC;AAC9D,MAAM,IAAI,GAAG,0BAA0B,CAAC;AAKxC,SAAgB,eAAe,CAAC,UAAoB;IAClD,MAAM,GAAG,GAAe,EAAE,sBAAsB,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC;IACzF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAClD,MA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MAAM,EAAE,GAAG,CAAC,MAA+B,EAAY,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC;IAC5K,IAAI,MAAM,KAAK,iBAAiB;QAAE,OAAO,EAAE,CAAC,EAAE,iBAAiB,EAAE,wBAAgB,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;IAC5H,IAAI,MAAM,KAAK,YAAY;QAAE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;IAC9E,IAAI,MAAM,KAAK,YAAY,EAAE,CAAC;QAC5B,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QACrD,MAAM,IAAI,GAAG,KAAK,CAAC,IAA4C,CAAC;QAChE,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC/C,CAAC;IACD,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,qBAAqB,MAAM,EAAE,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -6,10 +6,25 @@ export interface ProjectInfo {
|
|
|
6
6
|
author?: string;
|
|
7
7
|
description?: string;
|
|
8
8
|
dependencies: string[];
|
|
9
|
+
/** A platform id of the setup chat, from direct evidence only (BL-PM-016); the CLI does not read it. */
|
|
10
|
+
platform?: string;
|
|
11
|
+
/** BL-095 (REQ-002.H.39): from files only, each absent without direct evidence. */
|
|
12
|
+
packageManager?: string;
|
|
13
|
+
testFramework?: string;
|
|
14
|
+
repository?: string;
|
|
15
|
+
license?: string;
|
|
9
16
|
}
|
|
10
17
|
export declare class ProjectDetector {
|
|
11
18
|
detectProject(projectDir?: string): Promise<ProjectInfo | null>;
|
|
19
|
+
/**
|
|
20
|
+
* BL-095 (REQ-002.H.39): package manager, test framework, repository URL and license, each from direct
|
|
21
|
+
* evidence at the folder's root only; files are read, no process is started.
|
|
22
|
+
*/
|
|
23
|
+
private detectMore;
|
|
24
|
+
private detectBase;
|
|
12
25
|
private detectNodeProject;
|
|
26
|
+
/** The platform a package.json shows directly (REQ-002.H.35): nothing for react alone. */
|
|
27
|
+
private detectNodePlatform;
|
|
13
28
|
private detectPythonProject;
|
|
14
29
|
private detectLanguage;
|
|
15
30
|
private detectFramework;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projectDetector.d.ts","sourceRoot":"","sources":["../../src/utils/projectDetector.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"projectDetector.d.ts","sourceRoot":"","sources":["../../src/utils/projectDetector.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,wGAAwG;IACxG,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mFAAmF;IACnF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAmDD,qBAAa,eAAe;IACpB,aAAa,CAAC,UAAU,GAAE,MAAsB,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAKpF;;;OAGG;IACH,OAAO,CAAC,UAAU;IAsBlB,OAAO,CAAC,UAAU;IA0ClB,OAAO,CAAC,iBAAiB;IAezB,0FAA0F;IAC1F,OAAO,CAAC,kBAAkB;IAS1B,OAAO,CAAC,mBAAmB;IA0C3B,OAAO,CAAC,cAAc;IAetB,OAAO,CAAC,eAAe;IAwBvB,OAAO,CAAC,qBAAqB;IAW7B,OAAO,CAAC,aAAa;IASrB,OAAO,CAAC,mBAAmB;IAyC3B,OAAO,CAAC,qBAAqB;IAS7B,OAAO,CAAC,kBAAkB;IA2B1B,OAAO,CAAC,oBAAoB;IAO5B,OAAO,CAAC,yBAAyB;CAiBlC"}
|
|
@@ -3,8 +3,94 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ProjectDetector = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const path_1 = require("path");
|
|
6
|
+
const gitClone_1 = require("./gitClone");
|
|
7
|
+
/** Largest `.git/config` or LICENSE file read for detection (REQ-002.H.39). */
|
|
8
|
+
const MAX_DETECT_BYTES = 64 * 1024;
|
|
9
|
+
const LICENSE_SHAPE = /^[A-Za-z0-9.+()\- ]{1,64}$/;
|
|
10
|
+
const NODE_LOCKS = [['pnpm-lock.yaml', 'pnpm'], ['yarn.lock', 'yarn'], ['bun.lock', 'bun'], ['bun.lockb', 'bun'], ['package-lock.json', 'npm']];
|
|
11
|
+
const PYTHON_LOCKS = [['uv.lock', 'uv'], ['poetry.lock', 'poetry'], ['Pipfile.lock', 'pipenv']];
|
|
12
|
+
const NODE_TESTS = [['vitest', 'vitest'], ['jest', 'jest'], ['mocha', 'mocha'], ['@playwright/test', 'playwright'], ['cypress', 'cypress']];
|
|
13
|
+
const LICENSE_FILES = ['LICENSE', 'LICENSE.md', 'LICENSE.txt', 'LICENCE'];
|
|
14
|
+
const LICENSE_LINES = [[/^MIT License$/i, 'MIT'], [/^Apache License$/i, 'Apache-2.0'], [/^GNU GENERAL PUBLIC LICENSE$/i, 'GPL'], [/^ISC License$/i, 'ISC'], [/^BSD .*License$/i, 'BSD']];
|
|
15
|
+
/** A file's text when `lstat` shows a regular file of at most MAX_DETECT_BYTES, else null: no link is followed. */
|
|
16
|
+
function readSmall(path) {
|
|
17
|
+
try {
|
|
18
|
+
const st = (0, fs_1.lstatSync)(path);
|
|
19
|
+
return st.isFile() && st.size <= MAX_DETECT_BYTES ? (0, fs_1.readFileSync)(path, 'utf-8') : null;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** The first `url =` of `[remote "origin"]` in `.git/config`, when `.git` is a real folder and the clone check accepts it. */
|
|
26
|
+
function originUrl(dir) {
|
|
27
|
+
try {
|
|
28
|
+
if (!(0, fs_1.lstatSync)((0, path_1.join)(dir, '.git')).isDirectory())
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
const lines = (readSmall((0, path_1.join)(dir, '.git', 'config')) ?? '').split(/\r?\n/);
|
|
35
|
+
const start = lines.findIndex(l => /^\s*\[remote "origin"\]\s*$/.test(l));
|
|
36
|
+
if (start < 0)
|
|
37
|
+
return undefined;
|
|
38
|
+
for (const line of lines.slice(start + 1)) {
|
|
39
|
+
if (/^\s*\[/.test(line))
|
|
40
|
+
return undefined;
|
|
41
|
+
const m = /^\s*url\s*=\s*(.*?)\s*$/.exec(line);
|
|
42
|
+
if (m)
|
|
43
|
+
return (0, gitClone_1.cloneUrlError)(m[1]) === null ? m[1] : undefined;
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
/** `package.json`'s license string verbatim, else the first LICENSE file's first line matched to one of five families. */
|
|
48
|
+
function licenseOf(dir, pkgLicense) {
|
|
49
|
+
let value;
|
|
50
|
+
if (typeof pkgLicense === 'string')
|
|
51
|
+
value = pkgLicense;
|
|
52
|
+
else {
|
|
53
|
+
const file = LICENSE_FILES.map(f => readSmall((0, path_1.join)(dir, f))).find(t => t !== null);
|
|
54
|
+
const first = file?.replace(/^\uFEFF/, '').split(/\r?\n/).map(l => l.trim()).find(l => l !== '');
|
|
55
|
+
value = first ? LICENSE_LINES.find(([re]) => re.test(first))?.[1] : undefined;
|
|
56
|
+
}
|
|
57
|
+
return value && LICENSE_SHAPE.test(value) ? value : undefined;
|
|
58
|
+
}
|
|
6
59
|
class ProjectDetector {
|
|
7
60
|
async detectProject(projectDir = process.cwd()) {
|
|
61
|
+
const info = this.detectBase(projectDir);
|
|
62
|
+
return info && { ...info, ...this.detectMore(projectDir, info) };
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* BL-095 (REQ-002.H.39): package manager, test framework, repository URL and license, each from direct
|
|
66
|
+
* evidence at the folder's root only; files are read, no process is started.
|
|
67
|
+
*/
|
|
68
|
+
detectMore(dir, info) {
|
|
69
|
+
const pkgPath = (0, path_1.join)(dir, 'package.json');
|
|
70
|
+
const node = (0, fs_1.existsSync)(pkgPath); // a package.json makes it a Node project (detectBase)
|
|
71
|
+
const pkg = node ? JSON.parse((0, fs_1.readFileSync)(pkgPath, 'utf-8')) : {};
|
|
72
|
+
const locks = node ? NODE_LOCKS : info.language === 'python' ? PYTHON_LOCKS : [];
|
|
73
|
+
const packageManager = locks.find(([file]) => (0, fs_1.existsSync)((0, path_1.join)(dir, file)))?.[1];
|
|
74
|
+
let testFramework;
|
|
75
|
+
if (node) {
|
|
76
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
77
|
+
testFramework = NODE_TESTS.find(([name]) => deps[name])?.[1];
|
|
78
|
+
}
|
|
79
|
+
else if (info.language === 'python') {
|
|
80
|
+
const text = ['pyproject.toml', 'setup.py', 'requirements.txt'].map(f => (0, path_1.join)(dir, f)).filter(f => (0, fs_1.existsSync)(f)).map(f => (0, fs_1.readFileSync)(f, 'utf-8'))[0] ?? '';
|
|
81
|
+
if (/(^|[^A-Za-z0-9_.-])pytest(?![A-Za-z0-9_-])/m.test(text))
|
|
82
|
+
testFramework = 'pytest';
|
|
83
|
+
}
|
|
84
|
+
else if (info.language === 'kotlin') {
|
|
85
|
+
const gradle = ['build.gradle.kts', 'build.gradle'].map(f => (0, path_1.join)(dir, f)).filter(f => (0, fs_1.existsSync)(f)).map(f => (0, fs_1.readFileSync)(f, 'utf-8')).join('\n');
|
|
86
|
+
if (/junit/i.test(gradle))
|
|
87
|
+
testFramework = 'junit';
|
|
88
|
+
}
|
|
89
|
+
const repository = originUrl(dir);
|
|
90
|
+
const license = licenseOf(dir, node ? pkg.license : undefined);
|
|
91
|
+
return { ...(packageManager ? { packageManager } : {}), ...(testFramework ? { testFramework } : {}), ...(repository ? { repository } : {}), ...(license ? { license } : {}) };
|
|
92
|
+
}
|
|
93
|
+
detectBase(projectDir) {
|
|
8
94
|
// Try to detect Node.js/TypeScript project
|
|
9
95
|
const packageJsonPath = (0, path_1.join)(projectDir, 'package.json');
|
|
10
96
|
if ((0, fs_1.existsSync)(packageJsonPath)) {
|
|
@@ -51,9 +137,23 @@ class ProjectDetector {
|
|
|
51
137
|
framework: this.detectFramework(pkg),
|
|
52
138
|
author: this.extractAuthor(pkg.author),
|
|
53
139
|
description: pkg.description || '',
|
|
54
|
-
dependencies: Object.keys(pkg.dependencies || {})
|
|
140
|
+
dependencies: Object.keys(pkg.dependencies || {}),
|
|
141
|
+
platform: this.detectNodePlatform(pkg),
|
|
55
142
|
};
|
|
56
143
|
}
|
|
144
|
+
/** The platform a package.json shows directly (REQ-002.H.35): nothing for react alone. */
|
|
145
|
+
detectNodePlatform(pkg) {
|
|
146
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
147
|
+
if (deps['react-native'] || deps.expo)
|
|
148
|
+
return 'rn';
|
|
149
|
+
if (deps.next)
|
|
150
|
+
return 'nextjs';
|
|
151
|
+
if ((deps.vite || deps['react-scripts']) && deps.react)
|
|
152
|
+
return 'react';
|
|
153
|
+
if (deps.vite && deps.vue)
|
|
154
|
+
return 'vue';
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
57
157
|
detectPythonProject(filePath, fileType) {
|
|
58
158
|
const content = (0, fs_1.readFileSync)(filePath, 'utf-8');
|
|
59
159
|
if (fileType === 'pyproject.toml') {
|
|
@@ -206,6 +306,7 @@ class ProjectDetector {
|
|
|
206
306
|
let projectName = 'unknown-project';
|
|
207
307
|
let version = '1.0.0';
|
|
208
308
|
let content = '';
|
|
309
|
+
const xcEntry = (0, fs_1.readdirSync)(projectDir).find(e => e.endsWith('.xcodeproj') || e.endsWith('.xcworkspace'));
|
|
209
310
|
if (packageSwiftPath && (0, fs_1.existsSync)(packageSwiftPath)) {
|
|
210
311
|
content = (0, fs_1.readFileSync)(packageSwiftPath, 'utf-8');
|
|
211
312
|
const nameMatch = content.match(/name:\s*["']([^"']+)["']/);
|
|
@@ -214,18 +315,18 @@ class ProjectDetector {
|
|
|
214
315
|
}
|
|
215
316
|
else {
|
|
216
317
|
// Derive name from .xcodeproj or .xcworkspace filename
|
|
217
|
-
const entries = (0, fs_1.readdirSync)(projectDir);
|
|
218
|
-
const xcEntry = entries.find(e => e.endsWith('.xcodeproj') || e.endsWith('.xcworkspace'));
|
|
219
318
|
if (xcEntry)
|
|
220
319
|
projectName = xcEntry.replace(/\.(xcodeproj|xcworkspace)$/, '');
|
|
221
320
|
}
|
|
321
|
+
// An Xcode project, also beside a Package.swift, is the only evidence of iOS (REQ-002.H.35).
|
|
222
322
|
return {
|
|
223
323
|
name: projectName,
|
|
224
324
|
version,
|
|
225
325
|
language: 'swift',
|
|
226
326
|
framework: this.detectSwiftFramework(content),
|
|
227
327
|
description: '',
|
|
228
|
-
dependencies: []
|
|
328
|
+
dependencies: [],
|
|
329
|
+
...(xcEntry ? { platform: 'ios' } : {}),
|
|
229
330
|
};
|
|
230
331
|
}
|
|
231
332
|
detectSwiftFramework(content) {
|