sdtk-spec-kit 0.4.15 → 0.5.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/assets/manifest/toolkit-bundle.manifest.json +4 -4
- package/assets/manifest/toolkit-bundle.sha256.txt +1 -1
- package/assets/toolkit/toolkit/sdtk-spec.config.json +11 -1
- package/bin/sdtk.js +0 -0
- package/package.json +1 -1
- package/src/commands/help.js +16 -1
- package/src/commands/init.js +36 -1
- package/src/commands/project.js +6 -2
- package/src/lib/project-audit.js +3 -0
- package/src/lib/project-config.js +36 -1
- package/src/lib/project-ingest.js +3 -0
- package/src/lib/project-promote.js +137 -0
- package/src/lib/project-refresh.js +3 -0
- package/src/lib/stack-detector.js +289 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
3
|
-
"sourceCommit": "
|
|
2
|
+
"version": "0.5.0",
|
|
3
|
+
"sourceCommit": "01ff4cea59c8d0757e9136945145ef98d6a83914",
|
|
4
4
|
"fileCount": 98,
|
|
5
5
|
"files": [
|
|
6
6
|
{
|
|
@@ -80,8 +80,8 @@
|
|
|
80
80
|
},
|
|
81
81
|
{
|
|
82
82
|
"path": "toolkit/sdtk-spec.config.json",
|
|
83
|
-
"sha256": "
|
|
84
|
-
"size":
|
|
83
|
+
"sha256": "ce760f639a09913b236be6dde6c692ea19ee92eb1d9e63d10dcdeb398e7ed2fb",
|
|
84
|
+
"size": 1209
|
|
85
85
|
},
|
|
86
86
|
{
|
|
87
87
|
"path": "toolkit/sdtk-spec.config.profiles.example.json",
|
|
@@ -13,7 +13,7 @@ b9bdb2489c2881d03e965c7dd849468f797e2070d30e6730ab9ddf37b54b7879 toolkit/script
|
|
|
13
13
|
f925a58e0cc92addc542762c2bf5f60be2d538dcca88e15de0b628b3a57048b1 toolkit/scripts/uninstall-claude-skills.ps1
|
|
14
14
|
db0e580a20b43bb0af399ff3e4f7f2d826423d67bd2fa9a8121a384337a47de1 toolkit/scripts/uninstall-codex-skills.ps1
|
|
15
15
|
dec335148e1bc721eee6ddae82417f344cc74345771da1328c7af54deee0c812 toolkit/SDTK_TOOLKIT.md
|
|
16
|
-
|
|
16
|
+
ce760f639a09913b236be6dde6c692ea19ee92eb1d9e63d10dcdeb398e7ed2fb toolkit/sdtk-spec.config.json
|
|
17
17
|
e04ea5e3f72510e569ab849ebef3dea4a8728c2996c485e997d3e13a6c4f1f86 toolkit/sdtk-spec.config.profiles.example.json
|
|
18
18
|
ab376df00d0fe92307ff862bac0ffe431254903cf9ccac00117d979ddc9c7f88 toolkit/session/SDTK_ACTIVE_BOOTSTRAP.md
|
|
19
19
|
fba56394ff7cae3ab8cd510b4bfb5b299df9f4f1a3e59be9bbcd573e3df477ae toolkit/session/SDTK_AGENT_WORKING_RULES.md
|
|
@@ -15,7 +15,17 @@
|
|
|
15
15
|
"frontend": "Set your frontend stack (example: React + Vite)",
|
|
16
16
|
"mobile": "N/A",
|
|
17
17
|
"database": "Set your database (example: PostgreSQL 15)",
|
|
18
|
-
"auth": "Set your auth strategy (example: JWT/OAuth2)"
|
|
18
|
+
"auth": "Set your auth strategy (example: JWT/OAuth2)",
|
|
19
|
+
"detection": {
|
|
20
|
+
"language": null,
|
|
21
|
+
"framework": null,
|
|
22
|
+
"frameworkVersion": null,
|
|
23
|
+
"packageManager": null,
|
|
24
|
+
"confidence": "low",
|
|
25
|
+
"evidence": [],
|
|
26
|
+
"detectedAt": null,
|
|
27
|
+
"method": "static"
|
|
28
|
+
}
|
|
19
29
|
},
|
|
20
30
|
"commands": {
|
|
21
31
|
"backendTests": "UPDATE_ME: set backend test command",
|
package/bin/sdtk.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
package/src/commands/help.js
CHANGED
|
@@ -110,10 +110,11 @@ function cmdHelp() {
|
|
|
110
110
|
" sdtk-spec atlas watch Watch for markdown changes and rebuild automatically",
|
|
111
111
|
" sdtk-spec atlas status Show initialization state and last build summary",
|
|
112
112
|
"",
|
|
113
|
-
"Project subcommands
|
|
113
|
+
"Project subcommands:",
|
|
114
114
|
" sdtk-spec project ingest Build reusable project census and profile foundation from an existing repo (Pro)",
|
|
115
115
|
" sdtk-spec project audit Read-only audit: readiness score, gap list, risk list, next steps (Pro)",
|
|
116
116
|
" sdtk-spec project refresh Incremental managed refresh of .sdtk/project/ artifacts (Pro)",
|
|
117
|
+
" sdtk-spec project promote Publish reviewed staged docs into /docs/ for sdtk-wiki (free; dry-run by default)",
|
|
117
118
|
"",
|
|
118
119
|
"Atlas options (init):",
|
|
119
120
|
" --project-path <path> Target project directory (default: cwd)",
|
|
@@ -202,6 +203,20 @@ function cmdHelp() {
|
|
|
202
203
|
" - project refresh does not perform a read-only audit; use 'project audit' for that.",
|
|
203
204
|
" - Maintainer-root guard: project refresh refuses the SDTK maintainer monorepo root as a refresh target.",
|
|
204
205
|
"",
|
|
206
|
+
"Project promote options (free):",
|
|
207
|
+
" --project-path <path> Target project directory (default: cwd)",
|
|
208
|
+
" --output-dir <path> Foundation read path (default: <project>/.sdtk/project)",
|
|
209
|
+
" --apply Perform the copy (default is a dry-run plan only)",
|
|
210
|
+
" --force Overwrite existing live docs (default: skip existing)",
|
|
211
|
+
" --json Print the promote plan/result as JSON",
|
|
212
|
+
"",
|
|
213
|
+
"Project promote notes:",
|
|
214
|
+
" - project promote is free; it publishes reviewed staged docs into <project>/docs/.",
|
|
215
|
+
" - Source: <project>/.sdtk/project/DOC_SYNTHESIS_BASELINE/docs/ (run 'project ingest' first).",
|
|
216
|
+
" - Default is a dry-run that prints the plan and writes nothing; add --apply to publish.",
|
|
217
|
+
" - Existing live docs are skipped unless --force is given (human-review-first).",
|
|
218
|
+
" - After promote, run 'sdtk-wiki atlas build' to index the docs into the knowledge graph.",
|
|
219
|
+
"",
|
|
205
220
|
"Generate behavior:",
|
|
206
221
|
" The generate command creates the standard 17-file scaffold with TBD placeholders.",
|
|
207
222
|
" Scaffolds define document structure for each SDLC phase.",
|
package/src/commands/init.js
CHANGED
|
@@ -7,6 +7,7 @@ const { runScript } = require("../lib/powershell");
|
|
|
7
7
|
const { ValidationError } = require("../lib/errors");
|
|
8
8
|
const { VALID_SCOPES, defaultScope, isProjectScopeSupported } = require("../lib/scope");
|
|
9
9
|
const { assertProjectRefreshTargetAllowed } = require("../lib/project-target-guard");
|
|
10
|
+
const { detectAndMergeConfig } = require("../lib/stack-detector");
|
|
10
11
|
|
|
11
12
|
const FLAG_DEFS = {
|
|
12
13
|
runtime: { type: "string" },
|
|
@@ -15,6 +16,7 @@ const FLAG_DEFS = {
|
|
|
15
16
|
force: { type: "boolean" },
|
|
16
17
|
"skip-skills": { type: "boolean" },
|
|
17
18
|
"skip-runtime-assets": { type: "boolean" },
|
|
19
|
+
"skip-stack-detect": { type: "boolean" },
|
|
18
20
|
verbose: { type: "boolean" },
|
|
19
21
|
};
|
|
20
22
|
|
|
@@ -90,6 +92,20 @@ async function cmdInit(args) {
|
|
|
90
92
|
);
|
|
91
93
|
}
|
|
92
94
|
|
|
95
|
+
// Static stack detection: populate sdtk-spec.config.json so downstream
|
|
96
|
+
// commands (project ingest/audit/refresh) and the 17-file scaffold know the
|
|
97
|
+
// project stack without manual entry. Best-effort: never fail init.
|
|
98
|
+
let stackSummary = null;
|
|
99
|
+
if (!flags["skip-stack-detect"]) {
|
|
100
|
+
try {
|
|
101
|
+
stackSummary = detectAndMergeConfig(projectPath);
|
|
102
|
+
} catch (err) {
|
|
103
|
+
if (flags.verbose) {
|
|
104
|
+
console.warn(`Warning: stack detection skipped: ${err.message}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
93
109
|
console.log("");
|
|
94
110
|
console.log("SDTK-SPEC workspace initialized successfully.");
|
|
95
111
|
if (runtime === "codex" && scope === "project") {
|
|
@@ -97,8 +113,27 @@ async function cmdInit(args) {
|
|
|
97
113
|
console.log("Launch Codex with CODEX_HOME=<project>/.codex to activate that local runtime home.");
|
|
98
114
|
}
|
|
99
115
|
console.log("");
|
|
116
|
+
if (stackSummary && stackSummary.written && stackSummary.summary) {
|
|
117
|
+
const d = stackSummary.detected.detection;
|
|
118
|
+
const s = stackSummary.summary;
|
|
119
|
+
const fw = d.framework
|
|
120
|
+
? `${d.framework}${d.frameworkVersion ? " " + d.frameworkVersion : ""}`
|
|
121
|
+
: d.language || "unknown";
|
|
122
|
+
console.log(`Detected stack: ${fw} (confidence: ${d.confidence}).`);
|
|
123
|
+
if (s.written.length) {
|
|
124
|
+
console.log(` Auto-filled in sdtk-spec.config.json: ${s.written.join(", ")}.`);
|
|
125
|
+
}
|
|
126
|
+
if (s.preserved.length) {
|
|
127
|
+
console.log(` Kept your existing values: ${s.preserved.join(", ")}.`);
|
|
128
|
+
}
|
|
129
|
+
if (s.unknown.length) {
|
|
130
|
+
console.log(` Could not detect (please set manually): ${s.unknown.join(", ")}.`);
|
|
131
|
+
}
|
|
132
|
+
console.log("");
|
|
133
|
+
}
|
|
134
|
+
|
|
100
135
|
console.log("Next steps:");
|
|
101
|
-
console.log(" 1. Review
|
|
136
|
+
console.log(" 1. Review sdtk-spec.config.json (stack auto-detected where possible; fill any remaining placeholders).");
|
|
102
137
|
console.log(" 2. Review bootstrap guidance:");
|
|
103
138
|
console.log(` ${path.join(projectPath, "AGENTS.md")}`);
|
|
104
139
|
if (runtime === "claude") {
|
package/src/commands/project.js
CHANGED
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
const { runProjectIngest } = require("../lib/project-ingest");
|
|
4
4
|
const { runProjectAudit } = require("../lib/project-audit");
|
|
5
5
|
const { runProjectRefresh } = require("../lib/project-refresh");
|
|
6
|
+
const { runProjectPromote } = require("../lib/project-promote");
|
|
6
7
|
const { ValidationError } = require("../lib/errors");
|
|
7
8
|
|
|
8
|
-
const PROJECT_SUBCOMMANDS = new Set(["ingest", "audit", "refresh"]);
|
|
9
|
+
const PROJECT_SUBCOMMANDS = new Set(["ingest", "audit", "refresh", "promote"]);
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Top-level dispatcher for `sdtk-spec project <subcommand>`.
|
|
@@ -26,6 +27,7 @@ async function cmdProject(args) {
|
|
|
26
27
|
if (!args || args.length === 0) {
|
|
27
28
|
console.error("[project] Usage: sdtk-spec project <subcommand> [options]");
|
|
28
29
|
console.error(" Premium subcommands: ingest, audit, refresh (requires Pro entitlement)");
|
|
30
|
+
console.error(" Free subcommand: promote (publish reviewed staged docs into /docs/)");
|
|
29
31
|
console.error(" Run 'sdtk-spec --help' for full usage.");
|
|
30
32
|
return 1;
|
|
31
33
|
}
|
|
@@ -34,7 +36,7 @@ async function cmdProject(args) {
|
|
|
34
36
|
|
|
35
37
|
if (!PROJECT_SUBCOMMANDS.has(subcommand)) {
|
|
36
38
|
throw new ValidationError(
|
|
37
|
-
`Unknown project subcommand: "${subcommand}". Valid subcommands: ingest, audit, refresh.`
|
|
39
|
+
`Unknown project subcommand: "${subcommand}". Valid subcommands: ingest, audit, refresh, promote.`
|
|
38
40
|
);
|
|
39
41
|
}
|
|
40
42
|
|
|
@@ -45,6 +47,8 @@ async function cmdProject(args) {
|
|
|
45
47
|
return runProjectAudit(rest);
|
|
46
48
|
case "refresh":
|
|
47
49
|
return runProjectRefresh(rest);
|
|
50
|
+
case "promote":
|
|
51
|
+
return runProjectPromote(rest);
|
|
48
52
|
}
|
|
49
53
|
}
|
|
50
54
|
|
package/src/lib/project-audit.js
CHANGED
|
@@ -295,6 +295,9 @@ async function runProjectAudit(args) {
|
|
|
295
295
|
docBaselineDir: config.docBaselineDir,
|
|
296
296
|
docBaselineDocsRoot: config.docBaselineDocsRoot,
|
|
297
297
|
docSynthesisStatePath: config.docSynthesisStatePath,
|
|
298
|
+
excludes: config.excludes,
|
|
299
|
+
stack: config.stack,
|
|
300
|
+
commands: config.commands,
|
|
298
301
|
hasCachedFoundation,
|
|
299
302
|
hasStagedDocsBaseline,
|
|
300
303
|
json: !!flags.json,
|
|
@@ -22,11 +22,39 @@ const DEFAULT_EXCLUDES = [
|
|
|
22
22
|
"target",
|
|
23
23
|
];
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Best-effort read of the project's sdtk-spec.config.json `stack` and
|
|
27
|
+
* `commands` blocks. Returns nulls when the file is missing or unparseable —
|
|
28
|
+
* never throws, so ingest/audit/refresh keep working without a config.
|
|
29
|
+
*
|
|
30
|
+
* @param {string} projectPath
|
|
31
|
+
* @returns {{ stack: object|null, commands: object|null }}
|
|
32
|
+
*/
|
|
33
|
+
function readSpecConfig(projectPath) {
|
|
34
|
+
const specConfigPath = path.join(projectPath, "sdtk-spec.config.json");
|
|
35
|
+
try {
|
|
36
|
+
const parsed = JSON.parse(fs.readFileSync(specConfigPath, "utf8"));
|
|
37
|
+
if (!parsed || typeof parsed !== "object") {
|
|
38
|
+
return { stack: null, commands: null };
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
stack: parsed.stack && typeof parsed.stack === "object" ? parsed.stack : null,
|
|
42
|
+
commands:
|
|
43
|
+
parsed.commands && typeof parsed.commands === "object"
|
|
44
|
+
? parsed.commands
|
|
45
|
+
: null,
|
|
46
|
+
};
|
|
47
|
+
} catch (_e) {
|
|
48
|
+
return { stack: null, commands: null };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
25
52
|
/**
|
|
26
53
|
* Resolve and validate project path and output directory from parsed flags.
|
|
27
54
|
*
|
|
28
55
|
* Returns the canonical set of output paths for the .sdtk/project foundation
|
|
29
|
-
* and the BK-084 staged doc synthesis workspace
|
|
56
|
+
* and the BK-084 staged doc synthesis workspace, plus the project's declared
|
|
57
|
+
* stack/commands (best-effort) so premium handlers can use them.
|
|
30
58
|
*
|
|
31
59
|
* @param {{ "project-path"?: string, "output-dir"?: string }} flags
|
|
32
60
|
* @returns {{
|
|
@@ -45,6 +73,8 @@ const DEFAULT_EXCLUDES = [
|
|
|
45
73
|
* docBaselineDocsRoot: string,
|
|
46
74
|
* docSynthesisStatePath: string,
|
|
47
75
|
* excludes: string[],
|
|
76
|
+
* stack: object|null,
|
|
77
|
+
* commands: object|null,
|
|
48
78
|
* }}
|
|
49
79
|
*/
|
|
50
80
|
function resolveProjectConfig(flags) {
|
|
@@ -64,9 +94,13 @@ function resolveProjectConfig(flags) {
|
|
|
64
94
|
|
|
65
95
|
const docBaselineDir = path.join(outputDir, "DOC_SYNTHESIS_BASELINE");
|
|
66
96
|
|
|
97
|
+
const { stack, commands } = readSpecConfig(projectPath);
|
|
98
|
+
|
|
67
99
|
return {
|
|
68
100
|
projectPath,
|
|
69
101
|
outputDir,
|
|
102
|
+
stack,
|
|
103
|
+
commands,
|
|
70
104
|
configPath: path.join(outputDir, "config.json"),
|
|
71
105
|
statePath: path.join(outputDir, "INGEST_STATE.json"),
|
|
72
106
|
refreshStatePath: path.join(outputDir, "REFRESH_STATE.json"),
|
|
@@ -104,5 +138,6 @@ function writeProjectConfig(config) {
|
|
|
104
138
|
module.exports = {
|
|
105
139
|
resolveProjectConfig,
|
|
106
140
|
writeProjectConfig,
|
|
141
|
+
readSpecConfig,
|
|
107
142
|
DEFAULT_EXCLUDES,
|
|
108
143
|
};
|
|
@@ -280,6 +280,9 @@ async function runProjectIngest(args) {
|
|
|
280
280
|
docBaselineDir: config.docBaselineDir,
|
|
281
281
|
docBaselineDocsRoot: config.docBaselineDocsRoot,
|
|
282
282
|
docSynthesisStatePath: config.docSynthesisStatePath,
|
|
283
|
+
excludes: config.excludes,
|
|
284
|
+
stack: config.stack,
|
|
285
|
+
commands: config.commands,
|
|
283
286
|
json: !!flags.json,
|
|
284
287
|
argv: args,
|
|
285
288
|
};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { parseFlags } = require("./args");
|
|
6
|
+
const { resolveProjectConfig } = require("./project-config");
|
|
7
|
+
|
|
8
|
+
const PROMOTE_FLAG_DEFS = {
|
|
9
|
+
"project-path": { type: "string" },
|
|
10
|
+
"output-dir": { type: "string" },
|
|
11
|
+
apply: { type: "boolean" },
|
|
12
|
+
force: { type: "boolean" },
|
|
13
|
+
json: { type: "boolean" },
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Recursively list files under root, returning paths relative to root (posix).
|
|
18
|
+
*/
|
|
19
|
+
function listFilesRel(root) {
|
|
20
|
+
const out = [];
|
|
21
|
+
const stack = [root];
|
|
22
|
+
while (stack.length) {
|
|
23
|
+
const dir = stack.pop();
|
|
24
|
+
let entries;
|
|
25
|
+
try {
|
|
26
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
27
|
+
} catch (_e) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
for (const ent of entries) {
|
|
31
|
+
const abs = path.join(dir, ent.name);
|
|
32
|
+
if (ent.isDirectory()) stack.push(abs);
|
|
33
|
+
else if (ent.isFile()) out.push(path.relative(root, abs).split(path.sep).join("/"));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
out.sort();
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Promote reviewed staged docs (.sdtk/project/DOC_SYNTHESIS_BASELINE/docs/**)
|
|
42
|
+
* into the live <project>/docs/** tree so sdtk-wiki can index them.
|
|
43
|
+
*
|
|
44
|
+
* Safety model (human-review-first):
|
|
45
|
+
* - Default is a dry-run: prints the plan, writes nothing.
|
|
46
|
+
* - --apply performs the copy of NEW files only.
|
|
47
|
+
* - --force additionally overwrites existing live docs.
|
|
48
|
+
*
|
|
49
|
+
* @param {string[]} args - Remaining argv after "project promote"
|
|
50
|
+
* @returns {Promise<number>} CLI exit code
|
|
51
|
+
*/
|
|
52
|
+
async function runProjectPromote(args) {
|
|
53
|
+
const { flags } = parseFlags(args, PROMOTE_FLAG_DEFS);
|
|
54
|
+
|
|
55
|
+
let config;
|
|
56
|
+
try {
|
|
57
|
+
config = resolveProjectConfig(flags);
|
|
58
|
+
} catch (err) {
|
|
59
|
+
console.error(`[project promote] ${err.message}`);
|
|
60
|
+
return 1;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const stagedDocsRoot = config.docBaselineDocsRoot;
|
|
64
|
+
if (!fs.existsSync(stagedDocsRoot) || !fs.statSync(stagedDocsRoot).isDirectory()) {
|
|
65
|
+
console.error(
|
|
66
|
+
`[project promote] No staged docs found at ${stagedDocsRoot}. ` +
|
|
67
|
+
`Run "sdtk-spec project ingest" first.`
|
|
68
|
+
);
|
|
69
|
+
return 1;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const liveDocsRoot = path.join(config.projectPath, "docs");
|
|
73
|
+
const relFiles = listFilesRel(stagedDocsRoot);
|
|
74
|
+
|
|
75
|
+
const plan = { create: [], overwrite: [], skipExisting: [] };
|
|
76
|
+
for (const rel of relFiles) {
|
|
77
|
+
const target = path.join(liveDocsRoot, rel);
|
|
78
|
+
if (!fs.existsSync(target)) plan.create.push(rel);
|
|
79
|
+
else if (flags.force) plan.overwrite.push(rel);
|
|
80
|
+
else plan.skipExisting.push(rel);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const apply = !!flags.apply;
|
|
84
|
+
const written = [];
|
|
85
|
+
if (apply) {
|
|
86
|
+
const toWrite = plan.create.concat(plan.overwrite);
|
|
87
|
+
for (const rel of toWrite) {
|
|
88
|
+
const src = path.join(stagedDocsRoot, rel);
|
|
89
|
+
const dest = path.join(liveDocsRoot, rel);
|
|
90
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
91
|
+
fs.copyFileSync(src, dest);
|
|
92
|
+
written.push(rel);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (flags.json) {
|
|
97
|
+
console.log(
|
|
98
|
+
JSON.stringify({
|
|
99
|
+
stagedDocsRoot,
|
|
100
|
+
liveDocsRoot,
|
|
101
|
+
applied: apply,
|
|
102
|
+
plan,
|
|
103
|
+
written,
|
|
104
|
+
})
|
|
105
|
+
);
|
|
106
|
+
return 0;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Human-readable report
|
|
110
|
+
console.log(`Project promote — staged → live docs`);
|
|
111
|
+
console.log(` Staged: ${stagedDocsRoot}`);
|
|
112
|
+
console.log(` Live: ${liveDocsRoot}`);
|
|
113
|
+
console.log("");
|
|
114
|
+
console.log(` New files: ${plan.create.length}`);
|
|
115
|
+
plan.create.forEach((r) => console.log(` + docs/${r}`));
|
|
116
|
+
if (plan.skipExisting.length) {
|
|
117
|
+
console.log(` Existing (skipped, use --force to overwrite): ${plan.skipExisting.length}`);
|
|
118
|
+
plan.skipExisting.forEach((r) => console.log(` = docs/${r}`));
|
|
119
|
+
}
|
|
120
|
+
if (flags.force && plan.overwrite.length) {
|
|
121
|
+
console.log(` Will overwrite: ${plan.overwrite.length}`);
|
|
122
|
+
plan.overwrite.forEach((r) => console.log(` ~ docs/${r}`));
|
|
123
|
+
}
|
|
124
|
+
console.log("");
|
|
125
|
+
|
|
126
|
+
if (!apply) {
|
|
127
|
+
console.log("Dry run only — nothing was written.");
|
|
128
|
+
console.log("Re-run with --apply to publish (add --force to overwrite existing docs).");
|
|
129
|
+
return 0;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
console.log(`Promoted ${written.length} file(s) into ${liveDocsRoot}.`);
|
|
133
|
+
console.log('Next: run "sdtk-wiki atlas build" to index the docs into the knowledge graph.');
|
|
134
|
+
return 0;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
module.exports = { runProjectPromote };
|
|
@@ -494,6 +494,9 @@ async function runProjectRefresh(args) {
|
|
|
494
494
|
docBaselineDir: config.docBaselineDir,
|
|
495
495
|
docBaselineDocsRoot: config.docBaselineDocsRoot,
|
|
496
496
|
docSynthesisStatePath: config.docSynthesisStatePath,
|
|
497
|
+
excludes: config.excludes,
|
|
498
|
+
stack: config.stack,
|
|
499
|
+
commands: config.commands,
|
|
497
500
|
json: !!flags.json,
|
|
498
501
|
argv: args,
|
|
499
502
|
};
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Deterministic, static project stack detection (free; no network, no AI).
|
|
5
|
+
*
|
|
6
|
+
* v1 is Laravel-first: it recognises PHP/Laravel projects with high confidence
|
|
7
|
+
* and makes a best-effort attempt at the JS frontend toolchain and database.
|
|
8
|
+
* Other ecosystems are recognised at lower confidence or left for v2.
|
|
9
|
+
*
|
|
10
|
+
* The result feeds two consumers:
|
|
11
|
+
* 1. sdtk init -> merge into sdtk-spec.config.json (human strings + detection block)
|
|
12
|
+
* 2. sdtk-spec project ingest -> passed into the premium pack context (PART E)
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const fs = require("fs");
|
|
16
|
+
const path = require("path");
|
|
17
|
+
|
|
18
|
+
function readJsonSafe(filePath) {
|
|
19
|
+
try {
|
|
20
|
+
return JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
21
|
+
} catch (_e) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function fileExists(p) {
|
|
27
|
+
try {
|
|
28
|
+
return fs.existsSync(p);
|
|
29
|
+
} catch (_e) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Strip composer/npm version range operators to a readable version string.
|
|
36
|
+
* "^11.9" -> "11.9", ">=8.2" -> "8.2", "~5.0" -> "5.0".
|
|
37
|
+
*/
|
|
38
|
+
function normalizeVersion(raw) {
|
|
39
|
+
if (typeof raw !== "string") return null;
|
|
40
|
+
const m = raw.match(/(\d+(?:\.\d+)*)/);
|
|
41
|
+
return m ? m[1] : null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Detect the JS frontend framework from a merged dependency map.
|
|
46
|
+
* Returns { label, evidence[] } or null.
|
|
47
|
+
*/
|
|
48
|
+
function detectFrontend(deps) {
|
|
49
|
+
if (!deps || typeof deps !== "object") return null;
|
|
50
|
+
const checks = [
|
|
51
|
+
{ dep: "next", label: "Next.js" },
|
|
52
|
+
{ dep: "nuxt", label: "Nuxt" },
|
|
53
|
+
{ dep: "@angular/core", label: "Angular" },
|
|
54
|
+
{ dep: "react", label: "React" },
|
|
55
|
+
{ dep: "vue", label: "Vue" },
|
|
56
|
+
{ dep: "svelte", label: "Svelte" },
|
|
57
|
+
{ dep: "alpinejs", label: "Alpine.js" },
|
|
58
|
+
];
|
|
59
|
+
for (const c of checks) {
|
|
60
|
+
if (deps[c.dep]) {
|
|
61
|
+
const ver = normalizeVersion(deps[c.dep]);
|
|
62
|
+
return {
|
|
63
|
+
label: ver ? `${c.label} ${ver}` : c.label,
|
|
64
|
+
evidence: [`package.json:dependencies.${c.dep}`],
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Detect database from Laravel .env (DB_CONNECTION). Best-effort, v1.
|
|
73
|
+
* Returns { label, evidence[] } or null.
|
|
74
|
+
*/
|
|
75
|
+
function detectDatabase(projectPath) {
|
|
76
|
+
const envPath = path.join(projectPath, ".env");
|
|
77
|
+
let content;
|
|
78
|
+
try {
|
|
79
|
+
content = fs.readFileSync(envPath, "utf8");
|
|
80
|
+
} catch (_e) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
const m = content.match(/^\s*DB_CONNECTION\s*=\s*(.+)\s*$/m);
|
|
84
|
+
if (!m) return null;
|
|
85
|
+
const value = m[1].trim().replace(/^["']|["']$/g, "").toLowerCase();
|
|
86
|
+
const map = {
|
|
87
|
+
mysql: "MySQL",
|
|
88
|
+
mariadb: "MariaDB",
|
|
89
|
+
pgsql: "PostgreSQL",
|
|
90
|
+
postgres: "PostgreSQL",
|
|
91
|
+
sqlite: "SQLite",
|
|
92
|
+
sqlsrv: "SQL Server",
|
|
93
|
+
};
|
|
94
|
+
const label = map[value] || value;
|
|
95
|
+
return { label, evidence: [".env:DB_CONNECTION"] };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Detect the project stack from static signals under projectPath.
|
|
100
|
+
*
|
|
101
|
+
* @param {string} projectPath - absolute path to the project root
|
|
102
|
+
* @returns {{
|
|
103
|
+
* stack: { backend: string|null, frontend: string|null, database: string|null },
|
|
104
|
+
* detection: {
|
|
105
|
+
* language: string|null, framework: string|null, frameworkVersion: string|null,
|
|
106
|
+
* packageManager: string|null, confidence: "low"|"medium"|"high",
|
|
107
|
+
* evidence: string[], detectedAt: string, method: "static"
|
|
108
|
+
* }
|
|
109
|
+
* }}
|
|
110
|
+
*/
|
|
111
|
+
function detectStack(projectPath) {
|
|
112
|
+
const evidence = [];
|
|
113
|
+
let language = null;
|
|
114
|
+
let framework = null;
|
|
115
|
+
let frameworkVersion = null;
|
|
116
|
+
let packageManager = null;
|
|
117
|
+
let backend = null;
|
|
118
|
+
let frontend = null;
|
|
119
|
+
let database = null;
|
|
120
|
+
let confidence = "low";
|
|
121
|
+
|
|
122
|
+
const composer = readJsonSafe(path.join(projectPath, "composer.json"));
|
|
123
|
+
const hasArtisan = fileExists(path.join(projectPath, "artisan"));
|
|
124
|
+
|
|
125
|
+
// --- PHP / Laravel (primary v1 target) ---------------------------------
|
|
126
|
+
if (composer) {
|
|
127
|
+
language = "php";
|
|
128
|
+
packageManager = "composer";
|
|
129
|
+
const req = Object.assign({}, composer.require, composer["require-dev"]);
|
|
130
|
+
const laravelVer = req["laravel/framework"];
|
|
131
|
+
const phpVer =
|
|
132
|
+
(composer.require && composer.require.php) ||
|
|
133
|
+
(composer.config &&
|
|
134
|
+
composer.config.platform &&
|
|
135
|
+
composer.config.platform.php);
|
|
136
|
+
|
|
137
|
+
if (laravelVer) {
|
|
138
|
+
framework = "laravel";
|
|
139
|
+
frameworkVersion = normalizeVersion(laravelVer);
|
|
140
|
+
confidence = "high";
|
|
141
|
+
evidence.push("composer.json:require.laravel/framework");
|
|
142
|
+
if (hasArtisan) evidence.push("artisan");
|
|
143
|
+
} else {
|
|
144
|
+
confidence = "medium";
|
|
145
|
+
evidence.push("composer.json");
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const phpLabel = phpVer ? `PHP ${normalizeVersion(phpVer)}` : "PHP";
|
|
149
|
+
if (phpVer) evidence.push("composer.json:require.php");
|
|
150
|
+
backend =
|
|
151
|
+
framework === "laravel"
|
|
152
|
+
? `${phpLabel} + Laravel${frameworkVersion ? " " + frameworkVersion : ""}`
|
|
153
|
+
: `${phpLabel} (composer project)`;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// --- JS toolchain / frontend ------------------------------------------
|
|
157
|
+
const pkg = readJsonSafe(path.join(projectPath, "package.json"));
|
|
158
|
+
if (pkg) {
|
|
159
|
+
const deps = Object.assign({}, pkg.dependencies, pkg.devDependencies);
|
|
160
|
+
const fe = detectFrontend(deps);
|
|
161
|
+
if (fe) {
|
|
162
|
+
frontend = fe.label;
|
|
163
|
+
evidence.push(...fe.evidence);
|
|
164
|
+
}
|
|
165
|
+
if (!packageManager) {
|
|
166
|
+
packageManager = fileExists(path.join(projectPath, "package-lock.json"))
|
|
167
|
+
? "npm"
|
|
168
|
+
: "node";
|
|
169
|
+
}
|
|
170
|
+
if (!language) language = "javascript";
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Blade fallback when Laravel project has no JS framework
|
|
174
|
+
if (framework === "laravel" && !frontend) {
|
|
175
|
+
if (fileExists(path.join(projectPath, "resources", "views"))) {
|
|
176
|
+
frontend = "Blade (Laravel views)";
|
|
177
|
+
evidence.push("resources/views");
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// --- Database ----------------------------------------------------------
|
|
182
|
+
const db = detectDatabase(projectPath);
|
|
183
|
+
if (db) {
|
|
184
|
+
database = db.label;
|
|
185
|
+
evidence.push(...db.evidence);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
stack: { backend, frontend, database },
|
|
190
|
+
detection: {
|
|
191
|
+
language,
|
|
192
|
+
framework,
|
|
193
|
+
frameworkVersion,
|
|
194
|
+
packageManager,
|
|
195
|
+
confidence,
|
|
196
|
+
evidence,
|
|
197
|
+
detectedAt: new Date().toISOString(),
|
|
198
|
+
method: "static",
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ---------------------------------------------------------------------------
|
|
204
|
+
// Config merge
|
|
205
|
+
// ---------------------------------------------------------------------------
|
|
206
|
+
|
|
207
|
+
const PLACEHOLDER_RE = /^(set your |update_me|n\/a$|tbd$)/i;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* A stack string field is "replaceable" when empty or still a template
|
|
211
|
+
* placeholder. User-authored values are preserved.
|
|
212
|
+
*/
|
|
213
|
+
function isPlaceholder(value) {
|
|
214
|
+
if (value === null || value === undefined) return true;
|
|
215
|
+
if (typeof value !== "string") return false;
|
|
216
|
+
const t = value.trim();
|
|
217
|
+
if (t === "") return true;
|
|
218
|
+
return PLACEHOLDER_RE.test(t);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Merge a detection result into a parsed sdtk-spec.config.json object.
|
|
223
|
+
*
|
|
224
|
+
* - Human-readable stack strings (backend/frontend/database) are filled only
|
|
225
|
+
* when missing or placeholder (never clobber user edits).
|
|
226
|
+
* - The machine-readable stack.detection block is always (re)written.
|
|
227
|
+
*
|
|
228
|
+
* @returns {{ config: object, summary: { written: string[], preserved: string[], unknown: string[] } }}
|
|
229
|
+
*/
|
|
230
|
+
function mergeStackIntoConfig(config, detected) {
|
|
231
|
+
const next = config && typeof config === "object" ? config : {};
|
|
232
|
+
if (!next.stack || typeof next.stack !== "object") next.stack = {};
|
|
233
|
+
|
|
234
|
+
const summary = { written: [], preserved: [], unknown: [] };
|
|
235
|
+
const fields = ["backend", "frontend", "database"];
|
|
236
|
+
|
|
237
|
+
for (const field of fields) {
|
|
238
|
+
const detectedValue = detected.stack[field];
|
|
239
|
+
const currentValue = next.stack[field];
|
|
240
|
+
if (detectedValue) {
|
|
241
|
+
if (isPlaceholder(currentValue)) {
|
|
242
|
+
next.stack[field] = detectedValue;
|
|
243
|
+
summary.written.push(field);
|
|
244
|
+
} else {
|
|
245
|
+
summary.preserved.push(field);
|
|
246
|
+
}
|
|
247
|
+
} else if (isPlaceholder(currentValue)) {
|
|
248
|
+
summary.unknown.push(field);
|
|
249
|
+
} else {
|
|
250
|
+
summary.preserved.push(field);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
next.stack.detection = detected.detection;
|
|
255
|
+
return { config: next, summary };
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Detect the stack and merge into sdtk-spec.config.json on disk.
|
|
260
|
+
* No-op-safe: if the config file is missing it is left untouched and the
|
|
261
|
+
* detection is still returned for callers that want to act on it.
|
|
262
|
+
*
|
|
263
|
+
* @param {string} projectPath
|
|
264
|
+
* @param {{ configPath?: string }} [opts]
|
|
265
|
+
* @returns {{ detected: object, summary: object|null, configPath: string, written: boolean }}
|
|
266
|
+
*/
|
|
267
|
+
function detectAndMergeConfig(projectPath, opts) {
|
|
268
|
+
const configPath =
|
|
269
|
+
(opts && opts.configPath) ||
|
|
270
|
+
path.join(projectPath, "sdtk-spec.config.json");
|
|
271
|
+
const detected = detectStack(projectPath);
|
|
272
|
+
|
|
273
|
+
const config = readJsonSafe(configPath);
|
|
274
|
+
if (config === null) {
|
|
275
|
+
return { detected, summary: null, configPath, written: false };
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const { config: merged, summary } = mergeStackIntoConfig(config, detected);
|
|
279
|
+
fs.writeFileSync(configPath, JSON.stringify(merged, null, 2) + "\n", "utf8");
|
|
280
|
+
return { detected, summary, configPath, written: true };
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
module.exports = {
|
|
284
|
+
detectStack,
|
|
285
|
+
mergeStackIntoConfig,
|
|
286
|
+
detectAndMergeConfig,
|
|
287
|
+
isPlaceholder,
|
|
288
|
+
normalizeVersion,
|
|
289
|
+
};
|