specpilot 2.8.0 → 2.10.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 +4 -2
- package/dist/commands/add-specs.d.ts.map +1 -1
- package/dist/commands/add-specs.js +1 -3
- package/dist/commands/add-specs.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +32 -95
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/refine.d.ts.map +1 -1
- package/dist/commands/refine.js +1 -3
- package/dist/commands/refine.js.map +1 -1
- package/dist/commands/serve.d.ts +2 -0
- package/dist/commands/serve.d.ts.map +1 -1
- package/dist/commands/serve.js +29 -3
- package/dist/commands/serve.js.map +1 -1
- package/dist/core/agentConfig.d.ts +9 -0
- package/dist/core/agentConfig.d.ts.map +1 -0
- package/dist/{utils/agentConfigGenerator.js → core/agentConfig.js} +29 -44
- package/dist/core/agentConfig.js.map +1 -0
- package/dist/core/ideConfig.d.ts +35 -0
- package/dist/core/ideConfig.d.ts.map +1 -0
- package/dist/core/ideConfig.js +287 -0
- package/dist/core/ideConfig.js.map +1 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +22 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/render.d.ts +73 -0
- package/dist/core/render.d.ts.map +1 -0
- package/dist/core/render.js +99 -0
- package/dist/core/render.js.map +1 -0
- package/dist/core/slashCommands.d.ts +23 -0
- package/dist/core/slashCommands.d.ts.map +1 -0
- package/dist/core/slashCommands.js +524 -0
- package/dist/core/slashCommands.js.map +1 -0
- package/dist/core/specFiles.d.ts +18 -0
- package/dist/core/specFiles.d.ts.map +1 -0
- package/dist/{utils/specFileGenerator.js → core/specFiles.js} +223 -127
- package/dist/core/specFiles.js.map +1 -0
- package/dist/core/templateEngine.d.ts +69 -0
- package/dist/core/templateEngine.d.ts.map +1 -0
- package/dist/{utils → core}/templateEngine.js +108 -6
- package/dist/core/templateEngine.js.map +1 -0
- package/dist/utils/addSpecsQuestions.d.ts +16 -0
- package/dist/utils/addSpecsQuestions.d.ts.map +1 -1
- package/dist/utils/addSpecsQuestions.js +28 -1
- package/dist/utils/addSpecsQuestions.js.map +1 -1
- package/dist/utils/gitClone.d.ts +62 -0
- package/dist/utils/gitClone.d.ts.map +1 -0
- package/dist/utils/gitClone.js +222 -0
- package/dist/utils/gitClone.js.map +1 -0
- package/dist/utils/ideConfigGenerator.d.ts +5 -29
- package/dist/utils/ideConfigGenerator.d.ts.map +1 -1
- package/dist/utils/ideConfigGenerator.js +9 -282
- package/dist/utils/ideConfigGenerator.js.map +1 -1
- package/dist/utils/initQuestions.d.ts +57 -0
- package/dist/utils/initQuestions.d.ts.map +1 -0
- package/dist/utils/initQuestions.js +49 -0
- package/dist/utils/initQuestions.js.map +1 -0
- package/dist/utils/projectRegistry.d.ts +2 -0
- package/dist/utils/projectRegistry.d.ts.map +1 -1
- package/dist/utils/projectRegistry.js +4 -2
- package/dist/utils/projectRegistry.js.map +1 -1
- package/dist/utils/slashCommandGenerator.d.ts +3 -17
- package/dist/utils/slashCommandGenerator.d.ts.map +1 -1
- package/dist/utils/slashCommandGenerator.js +8 -514
- package/dist/utils/slashCommandGenerator.js.map +1 -1
- package/dist/utils/specGenerator.d.ts +16 -46
- package/dist/utils/specGenerator.d.ts.map +1 -1
- package/dist/utils/specGenerator.js +36 -62
- package/dist/utils/specGenerator.js.map +1 -1
- package/dist/utils/specServer.d.ts +5 -1
- package/dist/utils/specServer.d.ts.map +1 -1
- package/dist/utils/specServer.js +179 -27
- package/dist/utils/specServer.js.map +1 -1
- package/dist/utils/specSetup.d.ts +69 -4
- package/dist/utils/specSetup.d.ts.map +1 -1
- package/dist/utils/specSetup.js +228 -21
- package/dist/utils/specSetup.js.map +1 -1
- package/package.json +1 -1
- package/ui/app.css +94 -11
- package/ui/app.js +232 -74
- package/ui/index.html +39 -12
- package/ui/route.js +144 -11
- package/dist/utils/agentConfigGenerator.d.ts +0 -17
- package/dist/utils/agentConfigGenerator.d.ts.map +0 -1
- package/dist/utils/agentConfigGenerator.js.map +0 -1
- package/dist/utils/specFileGenerator.d.ts +0 -29
- package/dist/utils/specFileGenerator.d.ts.map +0 -1
- package/dist/utils/specFileGenerator.js.map +0 -1
- package/dist/utils/templateEngine.d.ts +0 -35
- package/dist/utils/templateEngine.d.ts.map +0 -1
- package/dist/utils/templateEngine.js.map +0 -1
|
@@ -1,63 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export interface SpecGeneratorOptions {
|
|
3
|
-
projectName: string;
|
|
4
|
-
language: string;
|
|
5
|
-
framework?: string;
|
|
1
|
+
import { RenderOptions } from '../core/render';
|
|
2
|
+
export interface SpecGeneratorOptions extends RenderOptions {
|
|
6
3
|
targetDir: string;
|
|
7
4
|
specsName: string;
|
|
8
|
-
author?: string;
|
|
9
|
-
description?: string;
|
|
10
|
-
ide?: string;
|
|
11
|
-
mode?: 'new' | 'existing';
|
|
12
|
-
projectType?: 'greenfield' | 'brownfield';
|
|
13
|
-
apiParadigm?: 'rest' | 'cli' | 'graphql' | 'none';
|
|
14
|
-
projectContext?: {
|
|
15
|
-
whatItDoes: string;
|
|
16
|
-
targetUsers: string;
|
|
17
|
-
expectedScale: string;
|
|
18
|
-
constraints: string;
|
|
19
|
-
};
|
|
20
|
-
analysis?: {
|
|
21
|
-
todos: Array<{
|
|
22
|
-
file: string;
|
|
23
|
-
line: number;
|
|
24
|
-
text: string;
|
|
25
|
-
type: string;
|
|
26
|
-
}>;
|
|
27
|
-
tests: {
|
|
28
|
-
framework?: string;
|
|
29
|
-
testFiles: string[];
|
|
30
|
-
testCount: number;
|
|
31
|
-
hasE2E: boolean;
|
|
32
|
-
hasUnit: boolean;
|
|
33
|
-
hasIntegration: boolean;
|
|
34
|
-
};
|
|
35
|
-
architecture: {
|
|
36
|
-
components: string[];
|
|
37
|
-
directories: string;
|
|
38
|
-
fileTypes: Record<string, number>;
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* The writer over the core's `render()` (BL-032): every file content comes from `src/core/`; this
|
|
8
|
+
* class only puts it on disk, the way `init`, `add-specs`, `refine --update` and `serve` always did.
|
|
9
|
+
*/
|
|
42
10
|
export declare class SpecGenerator {
|
|
43
|
-
private templateEngine;
|
|
44
|
-
private specFileGenerator;
|
|
45
11
|
private ideConfigGenerator;
|
|
46
|
-
private agentConfigGenerator;
|
|
47
|
-
private slashCommandGenerator;
|
|
48
|
-
constructor(templateEngine: TemplateEngine);
|
|
49
12
|
/**
|
|
50
|
-
* Writes `.specs/` and the IDE files.
|
|
51
|
-
*
|
|
13
|
+
* Writes `.specs/` and the IDE files. Inside `.specs/` a file is written as it is rendered (replaced
|
|
14
|
+
* when present, which `refine --update` relies on). Outside `.specs/` a file that already exists is
|
|
15
|
+
* never changed (BL-073): `kept` lists those paths in generator order; `appended` counts lines added
|
|
16
|
+
* to `.gitattributes`, which is the one file merged rather than created (REQ-002.B.8).
|
|
52
17
|
*/
|
|
53
18
|
generateSpecs(options: SpecGeneratorOptions): Promise<{
|
|
54
19
|
onboardingPrompt: string;
|
|
55
20
|
kept: string[];
|
|
56
21
|
appended: number;
|
|
57
22
|
}>;
|
|
23
|
+
/**
|
|
24
|
+
* The project-relative files `generateSpecs()` writes under `.specs/` for an API paradigm, in the
|
|
25
|
+
* order it writes them (BL-PM-004); `api.yaml` is absent for `none`.
|
|
26
|
+
*/
|
|
27
|
+
targetsInSpecs(apiParadigm: string, specsName?: string): string[];
|
|
58
28
|
/**
|
|
59
29
|
* The project-relative files `generateSpecs()` writes outside `.specs/` for an IDE choice, in the
|
|
60
|
-
* order it writes them (BL-055): read from the same tables the
|
|
30
|
+
* order it writes them (BL-055): read from the same tables the renders use, and pinned to the real
|
|
61
31
|
* output by a test, so `specpilot serve` can say which existing files it will keep before it runs.
|
|
62
32
|
*/
|
|
63
33
|
targetsOutsideSpecs(ide?: string): string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"specGenerator.d.ts","sourceRoot":"","sources":["../../src/utils/specGenerator.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"specGenerator.d.ts","sourceRoot":"","sources":["../../src/utils/specGenerator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAU,aAAa,EAAuC,MAAM,gBAAgB,CAAC;AAI5F,MAAM,WAAW,oBAAqB,SAAQ,aAAa;IACzD,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,kBAAkB,CAA4B;IAEtD;;;;;OAKG;IACG,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC;QAAE,gBAAgB,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IAiB3H;;;OAGG;IACH,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,SAAW,GAAG,MAAM,EAAE;IAInE;;;;OAIG;IACH,mBAAmB,CAAC,GAAG,SAAW,GAAG,MAAM,EAAE;CAG9C;AAED,4GAA4G;AAC5G,wBAAgB,UAAU,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,EAAE,CAK7F"}
|
|
@@ -4,81 +4,55 @@ exports.SpecGenerator = void 0;
|
|
|
4
4
|
exports.keepReport = keepReport;
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const fs_1 = require("fs");
|
|
7
|
-
const
|
|
7
|
+
const render_1 = require("../core/render");
|
|
8
|
+
const ideConfig_1 = require("../core/ideConfig");
|
|
8
9
|
const ideConfigGenerator_1 = require("./ideConfigGenerator");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const NO_API_FRAMEWORKS = new Set(['react', 'vue', 'angular', 'android', 'ios', 'swiftui', 'compose', 'streamlit']);
|
|
14
|
-
function inferApiParadigm(framework) {
|
|
15
|
-
if (!framework)
|
|
16
|
-
return 'rest';
|
|
17
|
-
const f = framework.toLowerCase();
|
|
18
|
-
if (REST_FRAMEWORKS.has(f))
|
|
19
|
-
return 'rest';
|
|
20
|
-
if (NO_API_FRAMEWORKS.has(f))
|
|
21
|
-
return 'none';
|
|
22
|
-
return 'rest';
|
|
23
|
-
}
|
|
10
|
+
/**
|
|
11
|
+
* The writer over the core's `render()` (BL-032): every file content comes from `src/core/`; this
|
|
12
|
+
* class only puts it on disk, the way `init`, `add-specs`, `refine --update` and `serve` always did.
|
|
13
|
+
*/
|
|
24
14
|
class SpecGenerator {
|
|
25
|
-
constructor(
|
|
26
|
-
this.templateEngine = templateEngine;
|
|
27
|
-
this.specFileGenerator = new specFileGenerator_1.SpecFileGenerator(templateEngine);
|
|
15
|
+
constructor() {
|
|
28
16
|
this.ideConfigGenerator = new ideConfigGenerator_1.IdeConfigGenerator();
|
|
29
|
-
this.agentConfigGenerator = new agentConfigGenerator_1.AgentConfigGenerator(templateEngine);
|
|
30
|
-
this.slashCommandGenerator = new slashCommandGenerator_1.SlashCommandGenerator();
|
|
31
17
|
}
|
|
32
18
|
/**
|
|
33
|
-
* Writes `.specs/` and the IDE files.
|
|
34
|
-
*
|
|
19
|
+
* Writes `.specs/` and the IDE files. Inside `.specs/` a file is written as it is rendered (replaced
|
|
20
|
+
* when present, which `refine --update` relies on). Outside `.specs/` a file that already exists is
|
|
21
|
+
* never changed (BL-073): `kept` lists those paths in generator order; `appended` counts lines added
|
|
22
|
+
* to `.gitattributes`, which is the one file merged rather than created (REQ-002.B.8).
|
|
35
23
|
*/
|
|
36
24
|
async generateSpecs(options) {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
projectType: options.projectType ?? (options.mode === 'existing' ? 'brownfield' : 'greenfield'),
|
|
53
|
-
apiParadigm: options.apiParadigm ?? inferApiParadigm(options.framework),
|
|
54
|
-
projectContext: options.projectContext,
|
|
55
|
-
};
|
|
56
|
-
const { onboardingPrompt } = await this.specFileGenerator.generateAll(specsDir, context);
|
|
57
|
-
const ide = (options.ide || 'vscode').toLowerCase();
|
|
58
|
-
const kept = AGENT_IDES.has(ide)
|
|
59
|
-
? await this.agentConfigGenerator.generate(options.targetDir, context, ide)
|
|
60
|
-
: await this.ideConfigGenerator.generate(options.targetDir, context, ide);
|
|
61
|
-
// Generate the IDE-native AI context file (routed per IDE choice)
|
|
62
|
-
kept.push(...this.ideConfigGenerator.generateAiContextFile(options.targetDir, context, ide));
|
|
63
|
-
// Generate per-IDE slash/workflow command files
|
|
64
|
-
kept.push(...this.slashCommandGenerator.generate(options.targetDir, ide));
|
|
65
|
-
// Generate .gitattributes with merge=union for append-heavy spec files
|
|
66
|
-
const appended = this.ideConfigGenerator.generateGitAttributes(options.targetDir);
|
|
25
|
+
const { files, onboardingPrompt } = (0, render_1.render)(options);
|
|
26
|
+
const kept = [];
|
|
27
|
+
let appended = 0;
|
|
28
|
+
for (const file of files) {
|
|
29
|
+
const target = (0, path_1.join)(options.targetDir, ...file.path.split('/'));
|
|
30
|
+
if (file.path === ideConfig_1.GITATTRIBUTES_FILE) {
|
|
31
|
+
appended = this.ideConfigGenerator.generateGitAttributes(options.targetDir);
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
(0, fs_1.mkdirSync)((0, path_1.dirname)(target), { recursive: true });
|
|
35
|
+
if (file.path.startsWith(`${options.specsName}/`))
|
|
36
|
+
(0, fs_1.writeFileSync)(target, file.content);
|
|
37
|
+
else if (!(0, ideConfigGenerator_1.writeNew)(target, file.content))
|
|
38
|
+
kept.push(file.path);
|
|
39
|
+
}
|
|
67
40
|
return { onboardingPrompt, kept, appended };
|
|
68
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* The project-relative files `generateSpecs()` writes under `.specs/` for an API paradigm, in the
|
|
44
|
+
* order it writes them (BL-PM-004); `api.yaml` is absent for `none`.
|
|
45
|
+
*/
|
|
46
|
+
targetsInSpecs(apiParadigm, specsName = '.specs') {
|
|
47
|
+
return (0, render_1.targetsInSpecs)(apiParadigm, specsName);
|
|
48
|
+
}
|
|
69
49
|
/**
|
|
70
50
|
* The project-relative files `generateSpecs()` writes outside `.specs/` for an IDE choice, in the
|
|
71
|
-
* order it writes them (BL-055): read from the same tables the
|
|
51
|
+
* order it writes them (BL-055): read from the same tables the renders use, and pinned to the real
|
|
72
52
|
* output by a test, so `specpilot serve` can say which existing files it will keep before it runs.
|
|
73
53
|
*/
|
|
74
54
|
targetsOutsideSpecs(ide = 'vscode') {
|
|
75
|
-
|
|
76
|
-
return [
|
|
77
|
-
...(AGENT_IDES.has(key) ? this.agentConfigGenerator.targets(key) : this.ideConfigGenerator.settingsTargets(key)),
|
|
78
|
-
this.ideConfigGenerator.aiContextTarget(key),
|
|
79
|
-
...this.slashCommandGenerator.targets(key),
|
|
80
|
-
ideConfigGenerator_1.GITATTRIBUTES_FILE,
|
|
81
|
-
];
|
|
55
|
+
return (0, render_1.targetsOutsideSpecs)(ide);
|
|
82
56
|
}
|
|
83
57
|
}
|
|
84
58
|
exports.SpecGenerator = SpecGenerator;
|
|
@@ -88,7 +62,7 @@ function keepReport({ kept, appended }) {
|
|
|
88
62
|
if (kept.length)
|
|
89
63
|
lines.push(`Kept as they were: ${kept.join(', ')}. Run specpilot backfill to add missing SpecPilot sections to the instruction and command files.`);
|
|
90
64
|
if (appended)
|
|
91
|
-
lines.push(`Appended ${appended} line${appended === 1 ? '' : 's'} to ${
|
|
65
|
+
lines.push(`Appended ${appended} line${appended === 1 ? '' : 's'} to ${ideConfig_1.GITATTRIBUTES_FILE}`);
|
|
92
66
|
return lines;
|
|
93
67
|
}
|
|
94
68
|
//# sourceMappingURL=specGenerator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"specGenerator.js","sourceRoot":"","sources":["../../src/utils/specGenerator.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"specGenerator.js","sourceRoot":"","sources":["../../src/utils/specGenerator.ts"],"names":[],"mappings":";;;AA4DA,gCAKC;AAjED,+BAAqC;AACrC,2BAA8C;AAC9C,2CAA4F;AAC5F,iDAAuD;AACvD,6DAAoE;AAOpE;;;GAGG;AACH,MAAa,aAAa;IAA1B;QACU,uBAAkB,GAAG,IAAI,uCAAkB,EAAE,CAAC;IAyCxD,CAAC;IAvCC;;;;;OAKG;IACH,KAAK,CAAC,aAAa,CAAC,OAA6B;QAC/C,MAAM,EAAE,KAAK,EAAE,gBAAgB,EAAE,GAAG,IAAA,eAAM,EAAC,OAAO,CAAC,CAAC;QACpD,MAAM,IAAI,GAAa,EAAE,CAAC;QAC1B,IAAI,QAAQ,GAAG,CAAC,CAAC;QACjB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,MAAM,GAAG,IAAA,WAAI,EAAC,OAAO,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;YAChE,IAAI,IAAI,CAAC,IAAI,KAAK,8BAAkB,EAAE,CAAC;gBACrC,QAAQ,GAAG,IAAI,CAAC,kBAAkB,CAAC,qBAAqB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;gBAC5E,SAAS;YACX,CAAC;YACD,IAAA,cAAS,EAAC,IAAA,cAAO,EAAC,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAChD,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,SAAS,GAAG,CAAC;gBAAE,IAAA,kBAAa,EAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;iBAClF,IAAI,CAAC,IAAA,6BAAQ,EAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC;gBAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjE,CAAC;QACD,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAC9C,CAAC;IAED;;;OAGG;IACH,cAAc,CAAC,WAAmB,EAAE,SAAS,GAAG,QAAQ;QACtD,OAAO,IAAA,uBAAc,EAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IAChD,CAAC;IAED;;;;OAIG;IACH,mBAAmB,CAAC,GAAG,GAAG,QAAQ;QAChC,OAAO,IAAA,4BAAmB,EAAC,GAAG,CAAC,CAAC;IAClC,CAAC;CACF;AA1CD,sCA0CC;AAED,4GAA4G;AAC5G,SAAgB,UAAU,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAwC;IACjF,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,IAAI,CAAC,MAAM;QAAE,KAAK,CAAC,IAAI,CAAC,sBAAsB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,kGAAkG,CAAC,CAAC;IACrK,IAAI,QAAQ;QAAE,KAAK,CAAC,IAAI,CAAC,YAAY,QAAQ,QAAQ,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,OAAO,8BAAkB,EAAE,CAAC,CAAC;IAC3G,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -58,12 +58,16 @@ export interface SpecServerOptions {
|
|
|
58
58
|
named?: boolean[];
|
|
59
59
|
/** The registry file (`~/.specpilot/projects.json`); the registry routes exist only when set and not read-only (BL-067). */
|
|
60
60
|
registry?: string;
|
|
61
|
+
/** Time limit of a clone in ms (tests shorten it; default `CLONE_TIMEOUT_MS`). */
|
|
62
|
+
cloneTimeoutMs?: number;
|
|
61
63
|
}
|
|
62
64
|
export interface SpecServer {
|
|
63
65
|
server: Server;
|
|
64
66
|
/** Open event streams right now. */
|
|
65
67
|
streams(): number;
|
|
66
|
-
/**
|
|
68
|
+
/** Kill a running clone and remove what it downloaded (BL-PM-002); resolves when that is done. */
|
|
69
|
+
stopClone(): Promise<void>;
|
|
70
|
+
/** Stop a running clone, end every event stream, clear every timer, then close the listener. */
|
|
67
71
|
close(): Promise<void>;
|
|
68
72
|
}
|
|
69
73
|
export declare function createSpecServer(initialRoots: string[], specpilotVersion: string, opts?: SpecServerOptions): SpecServer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"specServer.d.ts","sourceRoot":"","sources":["../../src/utils/specServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiC,MAAM,EAAkB,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"specServer.d.ts","sourceRoot":"","sources":["../../src/utils/specServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiC,MAAM,EAAkB,MAAM,MAAM,CAAC;AAgC7E,+EAA+E;AAC/E,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAG7E;AAED,kGAAkG;AAClG,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAetD;AAgBD,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;CAC5C;AAqCD,+FAA+F;AAC/F,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6BvE;AAED,kGAAkG;AAClG,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,SAAY,GAAG,MAAM,CAGlE;AAoCD,6EAA6E;AAC7E,eAAO,MAAM,aAAa,QAAY,CAAC;AAKvC,kFAAkF;AAClF,eAAO,MAAM,iBAAiB,IAAI,CAAC;AAEnC,MAAM,WAAW,iBAAiB;IAChC,kDAAkD;IAClD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gEAAgE;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2CAA2C;IAC3C,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,qEAAqE;IACrE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,yHAAyH;IACzH,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;IAClB,4HAA4H;IAC5H,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kFAAkF;IAClF,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,oCAAoC;IACpC,OAAO,IAAI,MAAM,CAAC;IAClB,kGAAkG;IAClG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,gGAAgG;IAChG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,gBAAgB,EAAE,MAAM,EAAE,IAAI,GAAE,iBAAsB,GAAG,UAAU,CA6a3H;AAED,iFAAiF;AACjF,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,IAAI,GAAE,iBAAsB,GAAG,OAAO,CAAC,UAAU,CAAC,CAS1I"}
|
package/dist/utils/specServer.js
CHANGED
|
@@ -51,10 +51,12 @@ const taskMover_1 = require("./taskMover");
|
|
|
51
51
|
const specPaths_1 = require("./specPaths");
|
|
52
52
|
const specPoller_1 = require("./specPoller");
|
|
53
53
|
const specSetup_1 = require("./specSetup");
|
|
54
|
+
const gitClone_1 = require("./gitClone");
|
|
54
55
|
const projectRegistry_1 = require("./projectRegistry");
|
|
55
56
|
// Local server behind `specpilot serve` (BL-051, ARCH-004.33, SEC-004.8). Every request re-reads disk;
|
|
56
57
|
// nothing is cached. The server writes nothing itself: task moves go through taskMover.ts (BL-053),
|
|
57
|
-
// guided setup through specSetup.ts (BL-055)
|
|
58
|
+
// guided setup and new projects through specSetup.ts (BL-055, BL-PM-003), the project registry through
|
|
59
|
+
// projectRegistry.ts (BL-067) and a clone through gitClone.ts, which runs the user's git (BL-PM-002).
|
|
58
60
|
/** Resolved from this module's own location, never from cwd: dist/utils → <package>/ui. */
|
|
59
61
|
const UI_DIR = (0, path_1.join)(__dirname, '..', '..', 'ui');
|
|
60
62
|
const UI_ROUTES = {
|
|
@@ -268,6 +270,7 @@ function createSpecServer(initialRoots, specpilotVersion, opts = {}) {
|
|
|
268
270
|
if (!res.headersSent)
|
|
269
271
|
sendJson(res, 500, { error: 'The server could not finish this request.' });
|
|
270
272
|
});
|
|
273
|
+
return writeLock;
|
|
271
274
|
};
|
|
272
275
|
/** The checks every write shares (SEC-004.10): Origin, token, content type, size. False = already answered. */
|
|
273
276
|
const writeAllowed = (req, res) => {
|
|
@@ -425,6 +428,28 @@ function createSpecServer(initialRoots, specpilotVersion, opts = {}) {
|
|
|
425
428
|
}
|
|
426
429
|
return null;
|
|
427
430
|
};
|
|
431
|
+
const TOO_MANY_PROJECTS = `This server already serves ${projectRegistry_1.MAX_PROJECTS} projects. Start another specpilot serve for more.`;
|
|
432
|
+
/**
|
|
433
|
+
* Serve `root` as the next index and record it in the registry: the success body of an open, or null
|
|
434
|
+
* after answering 422 because the folder's allowlisted files cannot be read (it is then not half-opened).
|
|
435
|
+
*/
|
|
436
|
+
const serveRoot = (res, root) => {
|
|
437
|
+
let specs;
|
|
438
|
+
try {
|
|
439
|
+
specs = buildSpecsPayload(root, specpilotVersion);
|
|
440
|
+
}
|
|
441
|
+
catch (err) {
|
|
442
|
+
sendJson(res, 422, { error: `This folder could not be read: ${err.message}` });
|
|
443
|
+
return null;
|
|
444
|
+
}
|
|
445
|
+
const project = projectFor(root); // built before anything is pushed, so the three lists never disagree
|
|
446
|
+
const n = roots.length;
|
|
447
|
+
roots.push(root);
|
|
448
|
+
namedFlags.push(true);
|
|
449
|
+
projects.push(project);
|
|
450
|
+
const error = changeRegistry(entries => (0, projectRegistry_1.upsertEntry)(entries, root, new Date()));
|
|
451
|
+
return { project: n, specs: { ...specs, projects: projectList(roots) }, registry: { ...registryBody(), ...(error ? { error } : {}) } };
|
|
452
|
+
};
|
|
428
453
|
const handleProjectAdd = (req, res) => {
|
|
429
454
|
if (!writeAllowed(req, res))
|
|
430
455
|
return;
|
|
@@ -436,23 +461,127 @@ function createSpecServer(initialRoots, specpilotVersion, opts = {}) {
|
|
|
436
461
|
const check = (0, projectRegistry_1.checkOpenPath)(body.path, roots, home);
|
|
437
462
|
if ('status' in check)
|
|
438
463
|
return sendJson(res, check.status, check.project === undefined ? { error: check.error } : { error: check.error, project: check.project });
|
|
439
|
-
if (
|
|
440
|
-
return sendJson(res, 409, { error:
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
464
|
+
if (cloningTarget && (check.root === cloningTarget || check.root.startsWith(cloningTarget + path_1.sep)))
|
|
465
|
+
return sendJson(res, 409, { error: `${cloningTarget} is being cloned. Wait for it to finish.` });
|
|
466
|
+
if (roots.length + (cloningTarget ? 1 : 0) >= projectRegistry_1.MAX_PROJECTS)
|
|
467
|
+
return sendJson(res, 409, { error: TOO_MANY_PROJECTS });
|
|
468
|
+
const body200 = serveRoot(res, check.root);
|
|
469
|
+
if (body200)
|
|
470
|
+
sendJson(res, 200, body200);
|
|
471
|
+
});
|
|
472
|
+
});
|
|
473
|
+
};
|
|
474
|
+
// ---- a new project (BL-PM-003): what `init` does in <parent>/<name>, then served like an opened folder
|
|
475
|
+
const handleProjectNewGet = (res) => {
|
|
476
|
+
try {
|
|
477
|
+
sendJson(res, 200, (0, specSetup_1.newProjectQuestions)());
|
|
478
|
+
}
|
|
479
|
+
catch (err) {
|
|
480
|
+
sendJson(res, 422, { error: `The OS username could not be read: ${err.message}` });
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
const handleProjectNew = (req, res) => {
|
|
484
|
+
if (!writeAllowed(req, res))
|
|
485
|
+
return;
|
|
486
|
+
readJson(req, res, body => {
|
|
487
|
+
const problem = (0, specSetup_1.newProjectShapeError)(body);
|
|
488
|
+
if (problem)
|
|
489
|
+
return sendJson(res, 422, { error: problem });
|
|
490
|
+
const { parent, name, ...answers } = body;
|
|
491
|
+
underLock(res, async () => {
|
|
492
|
+
if (roots.length + (cloningTarget ? 1 : 0) >= projectRegistry_1.MAX_PROJECTS)
|
|
493
|
+
return sendJson(res, 409, { error: TOO_MANY_PROJECTS }); // before anything is created
|
|
494
|
+
const out = await (0, specSetup_1.createProject)(parent, name, answers, roots, home, cloningTarget);
|
|
495
|
+
if (out.status !== 200)
|
|
496
|
+
return sendJson(res, out.status, out.project === undefined ? { error: out.error } : { error: out.error, project: out.project });
|
|
497
|
+
const body200 = serveRoot(res, out.root);
|
|
498
|
+
if (body200)
|
|
499
|
+
sendJson(res, 200, { ...body200, kept: out.kept, notice: out.notice });
|
|
500
|
+
});
|
|
501
|
+
});
|
|
502
|
+
};
|
|
503
|
+
// ---- clone a repository (BL-PM-002): the user's git fills <parent>/<name>, then served like an opened folder.
|
|
504
|
+
// One at a time, outside the write lock: the lock covers the checks and the mkdir, and serving the folder.
|
|
505
|
+
let cloneBusy = false;
|
|
506
|
+
let closing = false; // set by stopClone(): no clone starts once the server is being stopped
|
|
507
|
+
let cloningTarget = null; // reserved: counted in the cap, refused by the open and new routes
|
|
508
|
+
let cloneAbort = null;
|
|
509
|
+
let cloneDone = Promise.resolve();
|
|
510
|
+
const runClone = async (res, url, parent, name, signal) => {
|
|
511
|
+
const probe = await (0, gitClone_1.probeGit)(home); // before anything is created
|
|
512
|
+
if ('error' in probe)
|
|
513
|
+
return sendJson(res, 422, { error: probe.error });
|
|
514
|
+
let reserved;
|
|
515
|
+
await underLock(res, () => {
|
|
516
|
+
if (signal.aborted)
|
|
517
|
+
return;
|
|
518
|
+
if (roots.length >= projectRegistry_1.MAX_PROJECTS)
|
|
519
|
+
return sendJson(res, 409, { error: TOO_MANY_PROJECTS });
|
|
520
|
+
const r = (0, specSetup_1.reserveTarget)(parent, name, roots, home);
|
|
521
|
+
if (!('status' in r)) {
|
|
522
|
+
reserved = r;
|
|
523
|
+
cloningTarget = r.target;
|
|
524
|
+
}
|
|
525
|
+
else if (r.notEmpty)
|
|
526
|
+
sendJson(res, 409, { error: `${r.notEmpty} already exists and is not empty, so nothing was cloned.` });
|
|
527
|
+
else
|
|
528
|
+
sendJson(res, r.status, r.project === undefined ? { error: r.error } : { error: r.error, project: r.project });
|
|
529
|
+
});
|
|
530
|
+
if (!reserved)
|
|
531
|
+
return;
|
|
532
|
+
const { target, created } = reserved;
|
|
533
|
+
const cleanUp = async () => {
|
|
534
|
+
const code = await (0, gitClone_1.emptyTarget)(target, created);
|
|
535
|
+
return code ? ` ${target} could not be cleaned up (${code}).` : '';
|
|
536
|
+
};
|
|
537
|
+
const out = await (0, gitClone_1.cloneRepository)(url, target, { batchSsh: probe.batchSsh, timeoutMs: opts.cloneTimeoutMs, signal });
|
|
538
|
+
if (!out.ok) {
|
|
539
|
+
const note = await cleanUp();
|
|
540
|
+
if (!out.aborted)
|
|
541
|
+
sendJson(res, 422, { error: out.error + note });
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
await underLock(res, async () => {
|
|
545
|
+
if (signal.aborted)
|
|
546
|
+
return void (await cleanUp()); // cancelled just after git finished: nothing happened
|
|
547
|
+
const body200 = serveRoot(res, target);
|
|
548
|
+
if (body200)
|
|
549
|
+
sendJson(res, 200, body200);
|
|
550
|
+
});
|
|
551
|
+
};
|
|
552
|
+
const handleProjectClone = (req, res) => {
|
|
553
|
+
if (!writeAllowed(req, res))
|
|
554
|
+
return;
|
|
555
|
+
readJson(req, res, body => {
|
|
556
|
+
const problem = (0, gitClone_1.cloneShapeError)(body);
|
|
557
|
+
if (problem)
|
|
558
|
+
return sendJson(res, 422, { error: problem });
|
|
559
|
+
if (closing)
|
|
560
|
+
return sendJson(res, 503, { error: 'The server is stopping.' });
|
|
561
|
+
if (cloneBusy)
|
|
562
|
+
return sendJson(res, 409, { error: 'Another clone is running. Wait for it to finish.' });
|
|
563
|
+
cloneBusy = true;
|
|
564
|
+
const { url, parent, name } = body;
|
|
565
|
+
const abort = new AbortController();
|
|
566
|
+
cloneAbort = abort;
|
|
567
|
+
// The page went away before the answer (Cancel, a closed tab): the response closes unfinished.
|
|
568
|
+
const gone = () => {
|
|
569
|
+
if (!res.writableEnded)
|
|
570
|
+
abort.abort();
|
|
571
|
+
};
|
|
572
|
+
res.on('close', gone);
|
|
573
|
+
cloneDone = runClone(res, url, parent, name || (0, gitClone_1.repoNameFromUrl)(url), abort.signal)
|
|
574
|
+
.catch(() => {
|
|
575
|
+
if (!res.headersSent)
|
|
576
|
+
sendJson(res, 500, { error: 'The server could not finish this request.' });
|
|
577
|
+
})
|
|
578
|
+
.then(() => {
|
|
579
|
+
res.off('close', gone);
|
|
580
|
+
if (!res.writableEnded)
|
|
581
|
+
res.destroy(); // aborted: nothing was sent, and close() must not wait for this connection
|
|
582
|
+
cloneBusy = false;
|
|
583
|
+
cloningTarget = null;
|
|
584
|
+
cloneAbort = null;
|
|
456
585
|
});
|
|
457
586
|
});
|
|
458
587
|
};
|
|
@@ -485,6 +614,20 @@ function createSpecServer(initialRoots, specpilotVersion, opts = {}) {
|
|
|
485
614
|
res.setHeader('Allow', registry ? 'GET, POST' : '');
|
|
486
615
|
return send(res, 405, TEXT, 'Method Not Allowed\n');
|
|
487
616
|
}
|
|
617
|
+
if (url.pathname === '/api/projects/new') {
|
|
618
|
+
if (registry && req.method === 'GET')
|
|
619
|
+
return handleProjectNewGet(res);
|
|
620
|
+
if (registry && req.method === 'POST')
|
|
621
|
+
return handleProjectNew(req, res);
|
|
622
|
+
res.setHeader('Allow', registry ? 'GET, POST' : '');
|
|
623
|
+
return send(res, 405, TEXT, 'Method Not Allowed\n');
|
|
624
|
+
}
|
|
625
|
+
if (url.pathname === '/api/projects/clone') {
|
|
626
|
+
if (registry && req.method === 'POST')
|
|
627
|
+
return handleProjectClone(req, res);
|
|
628
|
+
res.setHeader('Allow', registry ? 'POST' : '');
|
|
629
|
+
return send(res, 405, TEXT, 'Method Not Allowed\n');
|
|
630
|
+
}
|
|
488
631
|
if (url.pathname === '/api/projects/remove') {
|
|
489
632
|
if (registry && req.method === 'POST')
|
|
490
633
|
return handleProjectRemove(req, res);
|
|
@@ -534,18 +677,27 @@ function createSpecServer(initialRoots, specpilotVersion, opts = {}) {
|
|
|
534
677
|
send(res, 500, TEXT, 'Internal Server Error\n');
|
|
535
678
|
}
|
|
536
679
|
});
|
|
680
|
+
const stopClone = () => {
|
|
681
|
+
closing = true;
|
|
682
|
+
cloneAbort?.abort();
|
|
683
|
+
return cloneDone;
|
|
684
|
+
};
|
|
537
685
|
return {
|
|
538
686
|
server,
|
|
539
687
|
streams: () => allStreams().length,
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
688
|
+
stopClone,
|
|
689
|
+
close: async () => {
|
|
690
|
+
await stopClone();
|
|
691
|
+
await new Promise(resolveClose => {
|
|
692
|
+
projects.forEach((p, i) => [...p.streams].forEach(res => {
|
|
693
|
+
res.end();
|
|
694
|
+
drop(i, res);
|
|
695
|
+
}));
|
|
696
|
+
projects.forEach(p => p.poller.stop());
|
|
697
|
+
server.close(() => resolveClose());
|
|
698
|
+
server.closeIdleConnections?.();
|
|
699
|
+
});
|
|
700
|
+
},
|
|
549
701
|
};
|
|
550
702
|
}
|
|
551
703
|
/** Listen on 127.0.0.1 only. Rejects with the listen error (e.g. EADDRINUSE). */
|