sdtk-spec-kit 0.4.14 → 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 +10 -10
- package/assets/manifest/toolkit-bundle.sha256.txt +4 -4
- package/assets/toolkit/toolkit/AGENTS.md +11 -11
- package/assets/toolkit/toolkit/sdtk-spec.config.json +11 -1
- package/assets/toolkit/toolkit/skills/sdtk-orchestrator/SKILL.md +1 -1
- package/assets/toolkit/toolkit/skills-claude/orchestrator/SKILL.md +1 -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,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
3
|
-
"sourceCommit": "
|
|
2
|
+
"version": "0.5.0",
|
|
3
|
+
"sourceCommit": "01ff4cea59c8d0757e9136945145ef98d6a83914",
|
|
4
4
|
"fileCount": 98,
|
|
5
5
|
"files": [
|
|
6
6
|
{
|
|
7
7
|
"path": "toolkit/AGENTS.md",
|
|
8
|
-
"sha256": "
|
|
9
|
-
"size":
|
|
8
|
+
"sha256": "0387e747b9eb4500f810b338b28d795841e796fdaa40c4002e07b0d88b724167",
|
|
9
|
+
"size": 11053
|
|
10
10
|
},
|
|
11
11
|
{
|
|
12
12
|
"path": "toolkit/install.ps1",
|
|
@@ -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",
|
|
@@ -145,8 +145,8 @@
|
|
|
145
145
|
},
|
|
146
146
|
{
|
|
147
147
|
"path": "toolkit/skills-claude/orchestrator/SKILL.md",
|
|
148
|
-
"sha256": "
|
|
149
|
-
"size":
|
|
148
|
+
"sha256": "aa086be1038e34b1b29f7f65bacf254b5c1bfdc1203bd3e643c27acca4f9c2fa",
|
|
149
|
+
"size": 5359
|
|
150
150
|
},
|
|
151
151
|
{
|
|
152
152
|
"path": "toolkit/skills-claude/pm/SKILL.md",
|
|
@@ -240,8 +240,8 @@
|
|
|
240
240
|
},
|
|
241
241
|
{
|
|
242
242
|
"path": "toolkit/skills/sdtk-orchestrator/SKILL.md",
|
|
243
|
-
"sha256": "
|
|
244
|
-
"size":
|
|
243
|
+
"sha256": "66ddb66fee3b12b008ea269baa57acde77f8614ac15a9f87cc994eae64ca63dc",
|
|
244
|
+
"size": 12586
|
|
245
245
|
},
|
|
246
246
|
{
|
|
247
247
|
"path": "toolkit/skills/sdtk-pm/SKILL.md",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
0387e747b9eb4500f810b338b28d795841e796fdaa40c4002e07b0d88b724167 toolkit/AGENTS.md
|
|
2
2
|
52bdc750984ee3c3598c1f1838cf3d72b2fc0ed06fca173ec3da79929b10f20c toolkit/install.ps1
|
|
3
3
|
0218dea84f0f9a25ddd2e68c6ae9995685ec471ff0950bd17d1eddcaa99f3e0e toolkit/README.md
|
|
4
4
|
42032999114addad5a664ee5dd891c521cfec87e8fadad6189f331a878156046 toolkit/runtimes/claude/CLAUDE_TEMPLATE.md
|
|
@@ -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
|
|
@@ -26,7 +26,7 @@ b4de86bc4730c4fcfe4f1bde8f9f64f03fd517825bb699e911199825cc3d4249 toolkit/skills
|
|
|
26
26
|
37b3ae11db18bc3f64a76b22bca95cea778d6cfbb8b038d46851bd44ff8ff8f1 toolkit/skills-claude/dev-frontend/SKILL.md
|
|
27
27
|
a4f326e2cafff865aaaed8f8de9407f3baa3cfebe33979528a15eb26d2e8482b toolkit/skills-claude/dev/SKILL.md
|
|
28
28
|
6fa2283aa1ebb7bf5b6e84d5d5d9d9ddf71082091b108bd46895923a5fca3e09 toolkit/skills-claude/mailbox-dispatch/SKILL.md
|
|
29
|
-
|
|
29
|
+
aa086be1038e34b1b29f7f65bacf254b5c1bfdc1203bd3e643c27acca4f9c2fa toolkit/skills-claude/orchestrator/SKILL.md
|
|
30
30
|
e9e346ff0e1fc66236ceabf64a043c9a28926e7ff06296b26dd5836cf045802a toolkit/skills-claude/pm/SKILL.md
|
|
31
31
|
a94b06194dd120f959082e3bcded91573e8c7b2ee350ab5bbad63a9c3cc331ab toolkit/skills-claude/qa/SKILL.md
|
|
32
32
|
320263e423dff2e9748b373aa9286b97721379ded62fde4e8a4dc5435a5f0048 toolkit/skills-claude/screen-design-spec/SKILL.md
|
|
@@ -45,7 +45,7 @@ ce5af79e5c4902b9c8ceb7e8dae848a6a5a26d5b845eee94ee8aafff88990256 toolkit/skills
|
|
|
45
45
|
55dd53b1ccbedd271ad23ca8df01afc317eced27ee17af3b37f31f0b9176ca8b toolkit/skills/sdtk-dev/prompts/spec-reviewer.md
|
|
46
46
|
749f0ff0865d8940cec9b16859706fd46f111a4d9bf54b6ccba381fe9db7a90e toolkit/skills/sdtk-dev/SKILL.md
|
|
47
47
|
df593d5ab4e7c5f4b05ac9ddb5078189b25bd954e546ab65c0147d024e4f4d59 toolkit/skills/sdtk-mailbox-dispatch/SKILL.md
|
|
48
|
-
|
|
48
|
+
66ddb66fee3b12b008ea269baa57acde77f8614ac15a9f87cc994eae64ca63dc toolkit/skills/sdtk-orchestrator/SKILL.md
|
|
49
49
|
ae53d96b6a4fb4ea60fb5de6578b2620c3adb43e1d722a0469cdfa5a90b92903 toolkit/skills/sdtk-pm/SKILL.md
|
|
50
50
|
e2c7fa172483ad6f1401ef831cd890c0bd9289f62ddc898335a4b8ac32bd6f7f toolkit/skills/sdtk-qa/SKILL.md
|
|
51
51
|
0702605f4c3a42cd06eb35ef61ca4b64f928c6b89dfb1204bcc978fb3ce033f9 toolkit/skills/sdtk-screen-design-spec/references/commerce-profile-screens.md
|
|
@@ -7,7 +7,7 @@ Goal: use the SDTK Suite as a coordinated operating model:
|
|
|
7
7
|
|
|
8
8
|
Orchestrator Intake is the always-winning front door for every unprefixed request.
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## 1) Default Rules
|
|
11
11
|
- If role is not specified, default to Orchestrator Intake, not PM.
|
|
12
12
|
- Orchestrator first classifies the user request intent, then routes to the smallest sufficient SDTK product, role, and skill.
|
|
13
13
|
- PM starts only when the request is ready for formal SDTK-SPEC product initiation after discovery readiness is confirmed.
|
|
@@ -22,7 +22,7 @@ Orchestrator Intake is the always-winning front door for every unprefixed reques
|
|
|
22
22
|
- Verification-before-completion: no phase may declare done, pass, or handoff-ready without fresh command evidence per `governance/ai/core/SDTK_VERIFICATION_BEFORE_COMPLETION_POLICY.md`.
|
|
23
23
|
- `toolkit/skills/skills.catalog.yaml` is the inventory source of truth for the 14 core SDTK-SPEC skills, including the bounded `mailbox-dispatch` controller skill.
|
|
24
24
|
|
|
25
|
-
##
|
|
25
|
+
## 2) Session Bootstrap Protocol
|
|
26
26
|
When starting a new session, read context in this order when the files exist:
|
|
27
27
|
1. `AGENTS.md`
|
|
28
28
|
2. `governance/ai/session/SDTK_ACTIVE_BOOTSTRAP.md`
|
|
@@ -32,7 +32,7 @@ When starting a new session, read context in this order when the files exist:
|
|
|
32
32
|
|
|
33
33
|
Do not read the entire historical session archive by default. Use `SDTK_SESSION_MEMORY_*.md` only when chronology or past acceptance details are required.
|
|
34
34
|
|
|
35
|
-
##
|
|
35
|
+
## 3) Orchestrator-First Intake Protocol
|
|
36
36
|
For every unprefixed user request:
|
|
37
37
|
1. Classify the request intent before selecting PM/BA/ARCH/DEV/QA or a downstream product lane.
|
|
38
38
|
2. Route to the smallest sufficient workflow:
|
|
@@ -48,7 +48,7 @@ For every unprefixed user request:
|
|
|
48
48
|
4. Do not force raw ideas directly into PM Phase 1. Clarify the requirement first in `docs/discovery/REQUIREMENT_[FEATURE_KEY].md`, then start PM initiation only after the artifact is marked `READY_FOR_PM_INITIATION`.
|
|
49
49
|
5. When routing creates artifacts, record decisions and open questions in the correct SDTK artifact.
|
|
50
50
|
|
|
51
|
-
##
|
|
51
|
+
## 4) Intent-To-Skill Routing Matrix
|
|
52
52
|
Use this compact matrix during intake so the agent picks the smallest sufficient workflow instead of defaulting everything to PM:
|
|
53
53
|
|
|
54
54
|
| User intent | Primary route | Output expectation |
|
|
@@ -71,7 +71,7 @@ Guardrails:
|
|
|
71
71
|
- Do not claim SDTK-WIKI Ask, project ingest, project refresh, project audit, web discover, compile, or query-history availability unless the runtime and entitlement preconditions are actually present.
|
|
72
72
|
- Ambiguous intent: ask, do not guess. Cap re-routes at 2 to avoid bouncing between products. Escalate to the user when intent cannot be classified or when the re-route limit is hit.
|
|
73
73
|
|
|
74
|
-
##
|
|
74
|
+
## 5) Proceed-Vs-Ask Decision Rules
|
|
75
75
|
Ask clarification when:
|
|
76
76
|
1. the requested outcome is ambiguous
|
|
77
77
|
2. safety, security, or release impact is unclear
|
|
@@ -85,7 +85,7 @@ Proceed when:
|
|
|
85
85
|
3. the user already approved the relevant plan or spec
|
|
86
86
|
4. the requested change is bounded and verifiable
|
|
87
87
|
|
|
88
|
-
##
|
|
88
|
+
## 6) Clarification Protocol
|
|
89
89
|
Apply for all roles (`/pm`, `/ba`, `/arch`, `/dev`, `/qa`):
|
|
90
90
|
1. If there is ambiguity or missing data, log `Open Questions` as `OQ-xx` in the current phase artifact.
|
|
91
91
|
2. Do not guess for behavior, API contracts, UI/UX, data model, security, or release criteria.
|
|
@@ -100,7 +100,7 @@ For raw ideas before PM initiation:
|
|
|
100
100
|
2. Record scope, non-goals, assumptions, constraints, open questions, and readiness there before opening `PROJECT_INITIATION`.
|
|
101
101
|
3. Treat the discovery artifact as a bridge into PM initiation, not as a PRD replacement.
|
|
102
102
|
|
|
103
|
-
##
|
|
103
|
+
## 7) Role Selection In One Message
|
|
104
104
|
When the user prefixes a message, execute that role:
|
|
105
105
|
- `/orchestrator` (default intake + routing)
|
|
106
106
|
- `/pm` (formal product initiation + planning)
|
|
@@ -114,7 +114,7 @@ Notes:
|
|
|
114
114
|
- Supported delivery roles are PM/BA/ARCH/DEV/QA.
|
|
115
115
|
- There is no separate `/tester` role. Test-case design belongs to QA with `sdtk-test-case-spec`.
|
|
116
116
|
|
|
117
|
-
##
|
|
117
|
+
## 8) Suite Product Routing
|
|
118
118
|
Use the suite products according to task intent:
|
|
119
119
|
|
|
120
120
|
- `SDTK-SPEC`
|
|
@@ -143,7 +143,7 @@ If the current project only has `SDTK-SPEC` runtime assets installed:
|
|
|
143
143
|
- do not overclaim that SDTK-CODE or SDTK-OPS runtime assets are already installed
|
|
144
144
|
- still describe the correct downstream suite path in guidance and handoffs
|
|
145
145
|
|
|
146
|
-
##
|
|
146
|
+
## 9) Shared State And Quality Gates
|
|
147
147
|
- `SHARED_PLANNING.md`: phase status, owners, artifacts, blockers, handoff notes.
|
|
148
148
|
- `QUALITY_CHECKLIST.md`: gate checklist by phase.
|
|
149
149
|
- No handoff to next phase while current gate is not PASS.
|
|
@@ -151,13 +151,13 @@ If the current project only has `SDTK-SPEC` runtime assets installed:
|
|
|
151
151
|
- QA cannot approve until `OPS_HANDOFF` and downstream OPS evidence are present and aligned.
|
|
152
152
|
- QA accepts downstream implementation evidence from SDTK-CODE as the default handoff bridge, plus `OPS_HANDOFF + OPS evidence` in the current formal suite flow.
|
|
153
153
|
|
|
154
|
-
##
|
|
154
|
+
## 10) Runtime Availability Rules
|
|
155
155
|
- Route only to products whose runtime assets are installed; do not overclaim.
|
|
156
156
|
- For SDTK-SPEC-only installs: keep `/dev` bounded to planning and `CODE_HANDOFF`; do not claim SDTK-CODE or SDTK-OPS are installed.
|
|
157
157
|
- For Codex runtimes: project-local skills require the explicit local `CODEX_HOME=<project>/.codex` contract; native `.codex/skills` auto-discovery is not claimed.
|
|
158
158
|
- Use `ops-parallel` or `code-parallel` only for truly independent slices. If parallel dispatch is unavailable in the active runtime, execute them sequentially in one controller session.
|
|
159
159
|
|
|
160
|
-
##
|
|
160
|
+
## 11) Discovery And PM Readiness
|
|
161
161
|
- PM initiation starts only after `docs/discovery/REQUIREMENT_[FEATURE_KEY].md` is marked `READY_FOR_PM_INITIATION`.
|
|
162
162
|
- Use `NEEDS_MORE_DISCOVERY` or `NOT_ACTIONABLE_YET` when the request is not ready.
|
|
163
163
|
- The discovery artifact is a pre-PM clarification bridge, not a PRD or BA replacement.
|
|
@@ -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",
|
|
@@ -51,7 +51,7 @@ After classifying intent, pick the **product** first, then the **skill within**
|
|
|
51
51
|
| User request | Classified route | Handoff |
|
|
52
52
|
|---|---|---|
|
|
53
53
|
| "Analyze why the auth module is slow" | `code-brainstorm` | Route: SDTK-CODE · Reason: investigation before code; Skill: `/code-brainstorm` |
|
|
54
|
-
| "Fix the login bug
|
|
54
|
+
| "Fix the login validation bug" | `sdtk-code` / `bugfix` | Route: SDTK-CODE · Reason: bounded fix with known scope; Skill: `start -> build -> verify -> ship` |
|
|
55
55
|
| "Design and spec the notification feature" | `sdtk-spec` | Route: SDTK-SPEC · Reason: upstream planning required; Skill: PM → BA → ARCH → DEV |
|
|
56
56
|
| "Deploy the v2 release to production" | `sdtk-ops` | Route: SDTK-OPS · Reason: operational rollout; Skill: `ops-plan -> ops-deploy -> ops-verify` |
|
|
57
57
|
| "What should we work on next?" | `orchestrator-state-review` | Route: Orchestrator review · Reason: state check; Skill: read SHARED_PLANNING + backlog |
|
|
@@ -47,7 +47,7 @@ After classifying intent, pick the **product** first, then the **skill within**
|
|
|
47
47
|
| User request | Chosen route |
|
|
48
48
|
|---|---|
|
|
49
49
|
| "Analyze why the auth module is slow" | SDTK-CODE · `/code-brainstorm` |
|
|
50
|
-
| "Fix the login bug
|
|
50
|
+
| "Fix the login validation bug" | SDTK-CODE · `start -> build -> verify -> ship` |
|
|
51
51
|
| "Design and spec the notification feature" | SDTK-SPEC · PM → BA → ARCH → DEV |
|
|
52
52
|
| "Deploy the v2 release to production" | SDTK-OPS · `ops-plan -> ops-deploy -> ops-verify` |
|
|
53
53
|
|
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
|
+
};
|