@t275005746/gse 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.yml +42 -42
  2. package/.github/ISSUE_TEMPLATE/change_request.yml +50 -50
  3. package/.github/ISSUE_TEMPLATE/config.yml +5 -5
  4. package/.github/PULL_REQUEST_TEMPLATE.md +38 -38
  5. package/.github/workflows/validate-gse.yml +33 -33
  6. package/.gse/README.md +18 -18
  7. package/.gse/gse-development-protocol.md +50 -50
  8. package/.gse/project-profile.md +29 -29
  9. package/.gse/quality-gates.md +25 -25
  10. package/.gse/releases/public-registry-publication-npm.md +49 -0
  11. package/.gse/releases/public-release-owner-required.md +65 -65
  12. package/.gse/releases/public-security-contact-owner-required.md +45 -45
  13. package/.gse/state.json +3 -4
  14. package/CHANGELOG.md +24 -24
  15. package/CONTRIBUTING.md +64 -64
  16. package/LICENSE +21 -21
  17. package/README.md +1 -1
  18. package/README.zh-CN.md +1 -1
  19. package/SECURITY.md +41 -41
  20. package/SUPPORT.md +38 -38
  21. package/assets/marketplace/README.md +7 -7
  22. package/assets/marketplace/gse-listing.json +75 -75
  23. package/assets/templates/acceptance-execution-packet.md +73 -73
  24. package/assets/templates/adr.md +14 -14
  25. package/assets/templates/change-brief.md +16 -16
  26. package/assets/templates/design.md +18 -18
  27. package/assets/templates/dispatch-packet.md +104 -104
  28. package/assets/templates/evidence.md +14 -14
  29. package/assets/templates/execution-quality-pack.md +65 -65
  30. package/assets/templates/goal-map.md +21 -21
  31. package/assets/templates/host-adapter.md +48 -48
  32. package/assets/templates/host-ui-invocation-record.md +42 -42
  33. package/assets/templates/incident-review.md +60 -60
  34. package/assets/templates/public-channel-publication-record.md +49 -49
  35. package/assets/templates/public-ci-run-record.md +53 -53
  36. package/assets/templates/public-release-record.md +65 -65
  37. package/assets/templates/public-repository-settings-record.md +59 -59
  38. package/assets/templates/public-security-contact-record.md +45 -45
  39. package/assets/templates/release-trust-record.md +32 -32
  40. package/assets/templates/review.md +18 -18
  41. package/assets/templates/spec.md +16 -16
  42. package/assets/templates/target-adoption-evidence.md +29 -29
  43. package/assets/templates/tasks.md +17 -17
  44. package/assets/templates/update-release-acceptance-record.md +58 -58
  45. package/examples/README.md +22 -22
  46. package/examples/agent-runtime-host/.claude/gse-adapter.md +6 -6
  47. package/examples/agent-runtime-host/.codex/gse-adapter.md +7 -7
  48. package/examples/agent-runtime-host/.gse/goal-map.md +7 -7
  49. package/examples/agent-runtime-host/.gse/project-profile.md +27 -27
  50. package/examples/agent-runtime-host/.gse/tooling.md +5 -5
  51. package/examples/agent-runtime-host/.mcp.json +9 -9
  52. package/examples/agent-runtime-host/AGENTS.md +5 -5
  53. package/examples/agent-runtime-host/README.md +10 -10
  54. package/examples/agent-runtime-host/docs/model-routing.md +5 -5
  55. package/examples/cli-tool/.gse/project-profile.md +21 -21
  56. package/examples/cli-tool/AGENTS.md +5 -5
  57. package/examples/cli-tool/README.md +12 -12
  58. package/examples/cli-tool/package.json +21 -21
  59. package/examples/small-app/.env.example +2 -2
  60. package/examples/small-app/.github/workflows/ci.yml +8 -8
  61. package/examples/small-app/AGENTS.md +5 -5
  62. package/examples/small-app/README.md +12 -12
  63. package/examples/small-app/package.json +26 -26
  64. package/examples/small-app/playwright.config.ts +4 -4
  65. package/package.json +53 -53
  66. package/references/adoption-recipes.md +171 -171
  67. package/references/agent-roles.md +49 -49
  68. package/references/architecture-health.md +101 -101
  69. package/references/benchmark-audit.md +73 -73
  70. package/references/community-channels.md +46 -46
  71. package/references/compatibility.md +70 -70
  72. package/references/design-basis.md +38 -38
  73. package/references/domain-model.md +129 -129
  74. package/references/domain-quality-gates.md +75 -75
  75. package/references/drift-audit.md +81 -81
  76. package/references/evidence-taxonomy.md +123 -123
  77. package/references/file-ownership.md +107 -107
  78. package/references/final-readiness.md +84 -84
  79. package/references/forward-test.md +133 -133
  80. package/references/goal-map.md +36 -36
  81. package/references/host-adapters.md +119 -119
  82. package/references/learning-system.md +35 -35
  83. package/references/marketplace-discovery.md +46 -46
  84. package/references/model-routing.md +103 -103
  85. package/references/open-source-defaults.md +39 -39
  86. package/references/operating-model.md +52 -52
  87. package/references/packaging.md +277 -277
  88. package/references/project-agent-workspace.md +89 -89
  89. package/references/project-bootstrap.md +122 -122
  90. package/references/project-profile.md +57 -57
  91. package/references/public-release.md +174 -174
  92. package/references/quality-gates.md +100 -100
  93. package/references/recovery.md +176 -176
  94. package/references/release-trust.md +43 -43
  95. package/references/release.md +126 -126
  96. package/references/review.md +141 -141
  97. package/references/router.md +90 -90
  98. package/references/spec-workflow.md +66 -66
  99. package/references/task-levels.md +81 -81
  100. package/references/tool-adapters.md +73 -73
  101. package/scripts/audit-acceptance-execution-packet.mjs +133 -133
  102. package/scripts/audit-adoption-recipes.mjs +99 -99
  103. package/scripts/audit-change-lifecycle.mjs +77 -77
  104. package/scripts/audit-change-system.mjs +134 -134
  105. package/scripts/audit-ci-readiness.mjs +107 -107
  106. package/scripts/audit-close-gate.mjs +323 -323
  107. package/scripts/audit-command-adapters.mjs +91 -91
  108. package/scripts/audit-command-execution.mjs +210 -210
  109. package/scripts/audit-compatibility.mjs +149 -149
  110. package/scripts/audit-completion-readiness.mjs +292 -292
  111. package/scripts/audit-distribution.mjs +251 -251
  112. package/scripts/audit-domain-quality-gates.mjs +108 -108
  113. package/scripts/audit-evidence-placeholders.mjs +126 -126
  114. package/scripts/audit-final-readiness-promotion.mjs +255 -255
  115. package/scripts/audit-final-readiness.mjs +226 -226
  116. package/scripts/audit-fixtures.mjs +154 -154
  117. package/scripts/audit-fresh-session-readiness.mjs +177 -177
  118. package/scripts/audit-host-runtime-evidence-handoff.mjs +159 -159
  119. package/scripts/audit-host-runtime-invocation-drill.mjs +240 -240
  120. package/scripts/audit-host-runtime-invocations.mjs +254 -254
  121. package/scripts/audit-host-ui-invocation.mjs +132 -132
  122. package/scripts/audit-marketplace-discovery.mjs +122 -122
  123. package/scripts/audit-npm-package-metadata.mjs +155 -155
  124. package/scripts/audit-npm-publish-dry-run.mjs +191 -169
  125. package/scripts/audit-npm-tarball-install.mjs +191 -191
  126. package/scripts/audit-open-source-defaults.mjs +92 -92
  127. package/scripts/audit-open-source-readiness.mjs +97 -97
  128. package/scripts/audit-project.mjs +138 -138
  129. package/scripts/audit-public-acceptance-command-dry-run-drill.mjs +203 -203
  130. package/scripts/audit-public-acceptance-readiness.mjs +224 -224
  131. package/scripts/audit-public-channel-publication.mjs +248 -248
  132. package/scripts/audit-public-ci-run.mjs +184 -184
  133. package/scripts/audit-public-collaboration-templates.mjs +98 -98
  134. package/scripts/audit-public-external-gate-probe.mjs +206 -206
  135. package/scripts/audit-public-release-decision.mjs +201 -201
  136. package/scripts/audit-public-release-metadata.mjs +176 -176
  137. package/scripts/audit-public-repository-settings.mjs +237 -237
  138. package/scripts/audit-public-security-contact.mjs +171 -171
  139. package/scripts/audit-readme-docs.mjs +6 -4
  140. package/scripts/audit-recovery-readiness.mjs +98 -98
  141. package/scripts/audit-release-readiness.mjs +106 -106
  142. package/scripts/audit-release-trust.mjs +62 -62
  143. package/scripts/audit-remote-distribution.mjs +266 -266
  144. package/scripts/audit-roadmap-consistency.mjs +235 -235
  145. package/scripts/audit-signing.mjs +147 -147
  146. package/scripts/audit-state-freshness.mjs +14 -9
  147. package/scripts/audit-target-adoption-evidence.mjs +117 -117
  148. package/scripts/audit-target-project.mjs +507 -507
  149. package/scripts/audit-update-release-acceptance.mjs +136 -136
  150. package/scripts/audit-v1-target-validation.mjs +269 -269
  151. package/scripts/audit-validation-profiles.mjs +125 -125
  152. package/scripts/close-change.mjs +116 -116
  153. package/scripts/discover-project-profile.mjs +307 -307
  154. package/scripts/generate-command-adapter.mjs +231 -231
  155. package/scripts/generate-final-acceptance-packet.mjs +181 -181
  156. package/scripts/generate-final-form-progress-report.mjs +205 -205
  157. package/scripts/generate-host-runtime-evidence-handoff.mjs +206 -206
  158. package/scripts/generate-owner-external-gate-kit.mjs +295 -295
  159. package/scripts/generate-public-acceptance-handoff.mjs +168 -168
  160. package/scripts/generate-public-release-checklist.mjs +207 -207
  161. package/scripts/generate-release-bundle.mjs +505 -505
  162. package/scripts/generate-release-owner-action-plan.mjs +172 -172
  163. package/scripts/generate-release-status-manifest.mjs +200 -200
  164. package/scripts/generate-session-prompt.mjs +188 -188
  165. package/scripts/gse.mjs +67 -67
  166. package/scripts/init-change.mjs +265 -265
  167. package/scripts/init-project.mjs +785 -785
  168. package/scripts/install-gse.mjs +234 -234
  169. package/scripts/lib/evidence-placeholders.mjs +28 -28
  170. package/scripts/package-gse.mjs +174 -174
  171. package/scripts/probe-public-external-gates.mjs +167 -167
  172. package/scripts/record-host-invocation.mjs +151 -151
  173. package/scripts/record-public-channel-publication.mjs +178 -178
  174. package/scripts/record-public-ci-run.mjs +180 -180
  175. package/scripts/record-public-release.mjs +175 -175
  176. package/scripts/record-public-repository-settings.mjs +209 -209
  177. package/scripts/record-public-security-contact.mjs +157 -157
  178. package/scripts/sign-gse-package.mjs +83 -83
  179. package/scripts/update-project-state.mjs +223 -223
  180. package/scripts/verify-gse-package.mjs +85 -85
@@ -1,507 +1,507 @@
1
- #!/usr/bin/env node
2
- import fs from 'node:fs'
3
- import os from 'node:os'
4
- import path from 'node:path'
5
- import { spawnSync } from 'node:child_process'
6
-
7
- const args = process.argv.slice(2)
8
-
9
- function readArg(name, fallback = null) {
10
- const index = args.indexOf(name)
11
- if (index === -1) return fallback
12
- return args[index + 1] ?? fallback
13
- }
14
-
15
- const jsonOnly = args.includes('--json')
16
- const selfTest = args.includes('--self-test') || !args.includes('--target')
17
- const targetArg = readArg('--target')
18
- const root = path.resolve(readArg('--root', path.join(import.meta.dirname, '..')))
19
-
20
- function slash(value) {
21
- return value.replace(/\\/g, '/')
22
- }
23
-
24
- function readText(filePath) {
25
- return fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf8').replace(/^\uFEFF/, '') : ''
26
- }
27
-
28
- function readJson(filePath) {
29
- if (!fs.existsSync(filePath)) return { exists: false, ok: false, data: null, error: 'missing' }
30
- try {
31
- return { exists: true, ok: true, data: JSON.parse(readText(filePath)), error: '' }
32
- } catch (error) {
33
- return { exists: true, ok: false, data: null, error: error.message }
34
- }
35
- }
36
-
37
- function readJsonl(filePath) {
38
- if (!fs.existsSync(filePath)) return { exists: false, ok: false, records: [], error: 'missing' }
39
- const lines = readText(filePath)
40
- .split(/\r?\n/)
41
- .map((line) => line.trim())
42
- .filter(Boolean)
43
- const records = []
44
- for (const [index, line] of lines.entries()) {
45
- try {
46
- records.push(JSON.parse(line))
47
- } catch (error) {
48
- return { exists: true, ok: false, records, error: `line ${index + 1}: ${error.message}` }
49
- }
50
- }
51
- return { exists: true, ok: true, records, error: '' }
52
- }
53
-
54
- function exists(target, relativePath) {
55
- return fs.existsSync(path.join(target, relativePath))
56
- }
57
-
58
- function listFiles(dir) {
59
- const files = []
60
- function visit(itemPath) {
61
- if (!fs.existsSync(itemPath)) return
62
- const stat = fs.statSync(itemPath)
63
- if (stat.isDirectory()) {
64
- for (const child of fs.readdirSync(itemPath)) visit(path.join(itemPath, child))
65
- return
66
- }
67
- if (stat.isFile()) files.push(itemPath)
68
- }
69
- visit(dir)
70
- return files
71
- }
72
-
73
- function runGit(target, commandArgs) {
74
- const result = spawnSync('git', commandArgs, {
75
- cwd: target,
76
- encoding: 'utf8',
77
- windowsHide: true,
78
- })
79
- return {
80
- status: result.status ?? 1,
81
- stdout: (result.stdout ?? '').trim(),
82
- stderr: (result.stderr ?? '').trim(),
83
- }
84
- }
85
-
86
- function statusFrom(ok, warn = false) {
87
- if (ok) return 'passed'
88
- if (warn) return 'warning'
89
- return 'failed'
90
- }
91
-
92
- function check(id, label, status, evidence, recommendation = '') {
93
- return { id, label, status, evidence, recommendation }
94
- }
95
-
96
- const requiredFiles = [
97
- '.gse/README.md',
98
- '.gse/project-profile.md',
99
- '.gse/goal-map.md',
100
- '.gse/goals/README.md',
101
- '.gse/quality-gates.md',
102
- '.gse/tooling.md',
103
- '.gse/templates/change-brief.md',
104
- '.gse/templates/evidence.md',
105
- ]
106
-
107
- const enterpriseFiles = [
108
- '.gse/agent-workspace.md',
109
- '.gse/agents/roles.md',
110
- '.gse/agents/dispatch.md',
111
- '.gse/skills/README.md',
112
- '.gse/lsp/README.md',
113
- '.gse/hooks/README.md',
114
- '.gse/mcp/README.md',
115
- '.gse/plugins/README.md',
116
- '.gse/release.md',
117
- '.gse/incident-review.md',
118
- '.gse/audit.md',
119
- ]
120
-
121
- function findCanonicalPlan(target) {
122
- const candidates = []
123
- const texts = [
124
- readText(path.join(target, '.gse', 'README.md')),
125
- readText(path.join(target, '.gse', 'project-profile.md')),
126
- readText(path.join(target, '.gse', 'goal-map.md')),
127
- ].join('\n')
128
-
129
- const regex = /docs\/[A-Za-z0-9._/-]*?(?:architecture|productization)[A-Za-z0-9._/-]*?\.md/g
130
- for (const match of texts.matchAll(regex)) {
131
- if (!candidates.includes(match[0])) candidates.push(match[0])
132
- }
133
-
134
- for (const fallback of [
135
- 'docs/aion-productization-architecture.md',
136
- 'docs/museflow-ai-film-productization-architecture.md',
137
- ]) {
138
- if (exists(target, fallback) && !candidates.includes(fallback)) candidates.push(fallback)
139
- }
140
-
141
- return candidates.map((relativePath) => ({ relativePath, exists: exists(target, relativePath) }))
142
- }
143
-
144
- function auditTarget(target) {
145
- const resolvedTarget = path.resolve(target)
146
- const gseDir = path.join(resolvedTarget, '.gse')
147
- const checks = []
148
-
149
- const hasGse = fs.existsSync(gseDir)
150
- checks.push(
151
- check(
152
- 'TPD01',
153
- '.gse directory exists',
154
- statusFrom(hasGse),
155
- hasGse ? '.gse exists' : '.gse missing',
156
- hasGse ? '' : 'Run GSE init/adopt before relying on project-local workflow files.',
157
- ),
158
- )
159
-
160
- const missingRequired = requiredFiles.filter((relativePath) => !exists(resolvedTarget, relativePath))
161
- checks.push(
162
- check(
163
- 'TPD02',
164
- 'required GSE files exist',
165
- statusFrom(missingRequired.length === 0),
166
- missingRequired.length === 0 ? `${requiredFiles.length}/${requiredFiles.length} required files present` : 'missing: ' + missingRequired.join(', '),
167
- missingRequired.length === 0 ? '' : 'Regenerate missing scaffold files or document why this project intentionally uses a smaller mode.',
168
- ),
169
- )
170
-
171
- const presentEnterprise = enterpriseFiles.filter((relativePath) => exists(resolvedTarget, relativePath))
172
- checks.push(
173
- check(
174
- 'TPD03',
175
- 'enterprise workspace files are visible when present',
176
- presentEnterprise.length === 0 ? 'warning' : 'passed',
177
- presentEnterprise.length === 0 ? 'no enterprise workspace files found' : `${presentEnterprise.length}/${enterpriseFiles.length} enterprise files present`,
178
- presentEnterprise.length === 0 ? 'Large or long-running projects should use standard/enterprise scaffold files.' : '',
179
- ),
180
- )
181
-
182
- const canonicalPlans = findCanonicalPlan(resolvedTarget)
183
- const existingCanonicalPlans = canonicalPlans.filter((item) => item.exists)
184
- checks.push(
185
- check(
186
- 'TPD04',
187
- 'canonical project plan is discoverable',
188
- statusFrom(existingCanonicalPlans.length > 0),
189
- canonicalPlans.length === 0 ? 'no canonical plan reference found' : canonicalPlans.map((item) => `${item.relativePath}:${item.exists ? 'exists' : 'missing'}`).join(', '),
190
- existingCanonicalPlans.length > 0 ? '' : 'Record the project canonical plan in .gse/README.md or .gse/goal-map.md.',
191
- ),
192
- )
193
-
194
- const qualityText = readText(path.join(resolvedTarget, '.gse', 'quality-gates.md'))
195
- const hasUniversalGate = qualityText.includes('Universal') || qualityText.includes('Universal Slice Gate')
196
- const hasDomainGate = /Identity|Chat|Canvas|UI|Browser|Media|Package|Encoding|Release|Recovery/i.test(qualityText)
197
- checks.push(
198
- check(
199
- 'TPD05',
200
- 'quality gates include universal and project/domain gates',
201
- statusFrom(hasUniversalGate && hasDomainGate, hasUniversalGate || hasDomainGate),
202
- `universal:${hasUniversalGate}, domain:${hasDomainGate}`,
203
- hasUniversalGate && hasDomainGate ? '' : 'Add project-specific quality gates instead of relying only on generic GSE wording.',
204
- ),
205
- )
206
-
207
- const evidenceDir = path.join(gseDir, 'evidence')
208
- const evidenceFiles = fs.existsSync(evidenceDir)
209
- ? listFiles(evidenceDir).filter((filePath) => /\.(md|json|jsonl)$/i.test(filePath))
210
- : []
211
- checks.push(
212
- check(
213
- 'TPD06',
214
- 'project-local GSE evidence exists',
215
- statusFrom(evidenceFiles.length > 0),
216
- evidenceFiles.length > 0 ? `${evidenceFiles.length} evidence file(s)` : 'no evidence files',
217
- evidenceFiles.length > 0 ? '' : 'Record adoption or slice evidence under .gse/evidence/.',
218
- ),
219
- )
220
-
221
- const gitRoot = runGit(resolvedTarget, ['rev-parse', '--show-toplevel'])
222
- const isGitRepo = gitRoot.status === 0
223
- checks.push(
224
- check(
225
- 'TPD07',
226
- 'target is inside a git repository',
227
- isGitRepo ? 'passed' : 'warning',
228
- isGitRepo ? slash(gitRoot.stdout) : gitRoot.stderr || 'not a git repository',
229
- isGitRepo ? '' : 'Git tracking checks are unavailable outside a git repository.',
230
- ),
231
- )
232
-
233
- let trackedGse = []
234
- if (isGitRepo) {
235
- const tracked = runGit(resolvedTarget, ['ls-files', '.gse'])
236
- trackedGse = tracked.status === 0 && tracked.stdout ? tracked.stdout.split(/\r?\n/).filter(Boolean) : []
237
- checks.push(
238
- check(
239
- 'TPD08',
240
- '.gse files are tracked by git',
241
- statusFrom(trackedGse.length > 0),
242
- trackedGse.length > 0 ? `${trackedGse.length} tracked .gse file(s)` : 'no tracked .gse files',
243
- trackedGse.length > 0 ? '' : 'Project-level .gse files should normally be committed; caches and host-local folders should not.',
244
- ),
245
- )
246
-
247
- const status = runGit(resolvedTarget, ['status', '--short', '.gse'])
248
- checks.push(
249
- check(
250
- 'TPD09',
251
- '.gse worktree is clean',
252
- status.status === 0 && status.stdout.length === 0 ? 'passed' : 'warning',
253
- status.stdout || 'clean',
254
- status.stdout ? 'Review and intentionally stage/commit or discard project-local GSE changes.' : '',
255
- ),
256
- )
257
-
258
- const sparse = runGit(resolvedTarget, ['sparse-checkout', 'list'])
259
- const sparseLines = sparse.status === 0 && sparse.stdout ? sparse.stdout.split(/\r?\n/).map((line) => slash(line.trim())).filter(Boolean) : []
260
- const sparseEnabled = sparse.status === 0 && sparseLines.length > 0
261
- const sparseIncludesGse = sparseLines.some((line) => line === '.gse' || line === '.gse/' || line.startsWith('.gse/') || line === '/*' || line === '*')
262
- checks.push(
263
- check(
264
- 'TPD10',
265
- 'sparse-checkout visibility for .gse is known',
266
- sparseEnabled && !sparseIncludesGse ? 'warning' : 'passed',
267
- sparseEnabled ? `sparse entries: ${sparseLines.join(', ') || '<empty>'}; includes .gse: ${sparseIncludesGse}` : 'sparse-checkout not enabled or no sparse list',
268
- sparseEnabled && !sparseIncludesGse ? 'Use git add --sparse for .gse updates or add .gse to sparse-checkout rules.' : '',
269
- ),
270
- )
271
- }
272
-
273
- const hostAdapterFindings = []
274
- for (const [hostDir, adapterPaths] of [
275
- ['.codex', ['.codex/gse-command.md', '.codex/gse-adapter.md']],
276
- ['.claude', ['.claude/commands/gse.md', '.claude/gse-adapter.md']],
277
- ]) {
278
- if (exists(resolvedTarget, hostDir)) {
279
- const candidates = adapterPaths.map((adapterPath) => {
280
- const text = readText(path.join(resolvedTarget, adapterPath))
281
- return {
282
- adapterPath,
283
- exists: exists(resolvedTarget, adapterPath),
284
- pointsToGse: text.includes('.gse/'),
285
- }
286
- })
287
- const matching = candidates.find((item) => item.exists && item.pointsToGse)
288
- hostAdapterFindings.push({
289
- hostDir,
290
- adapterPath: matching?.adapterPath ?? candidates[0].adapterPath,
291
- exists: Boolean(matching),
292
- pointsToGse: Boolean(matching),
293
- candidates,
294
- })
295
- }
296
- }
297
- const badAdapters = hostAdapterFindings.filter((item) => !item.exists || !item.pointsToGse)
298
- checks.push(
299
- check(
300
- 'TPD11',
301
- 'host adapters point back to .gse when host folders exist',
302
- hostAdapterFindings.length === 0 ? 'passed' : statusFrom(badAdapters.length === 0),
303
- hostAdapterFindings.length === 0 ? 'no Codex/Claude host folders detected' : hostAdapterFindings.map((item) => `${item.adapterPath}:exists=${item.exists},pointsToGse=${item.pointsToGse}`).join('; '),
304
- badAdapters.length === 0 ? '' : 'Generate or repair thin host adapters; do not duplicate policy outside .gse/.',
305
- ),
306
- )
307
-
308
- const state = readJson(path.join(gseDir, 'state.json'))
309
- const evidenceIndex = readJsonl(path.join(gseDir, 'evidence', 'index.jsonl'))
310
- const stateHasCoreFields =
311
- state.ok &&
312
- state.data?.schemaVersion === 1 &&
313
- typeof state.data?.mode === 'string' &&
314
- typeof state.data?.phase === 'string' &&
315
- typeof state.data?.currentSlice?.status === 'string' &&
316
- state.data?.toolStatuses &&
317
- typeof state.data.toolStatuses === 'object'
318
- const evidenceIndexHasCoreFields =
319
- evidenceIndex.ok &&
320
- evidenceIndex.records.length > 0 &&
321
- evidenceIndex.records.every(
322
- (record) =>
323
- typeof record.date === 'string' &&
324
- typeof record.recordType === 'string' &&
325
- typeof record.status === 'string' &&
326
- typeof record.summary === 'string' &&
327
- typeof record.evidenceFile === 'string' &&
328
- Array.isArray(record.commands) &&
329
- typeof record.nextAction === 'string',
330
- )
331
- const stateIndexOk = stateHasCoreFields && evidenceIndexHasCoreFields
332
- const stateIndexWarn = !state.exists || !evidenceIndex.exists
333
- checks.push(
334
- check(
335
- 'TPD12',
336
- 'machine-readable state and evidence index are present',
337
- statusFrom(stateIndexOk, stateIndexWarn),
338
- `state.json:${state.exists ? state.ok ? 'valid' : 'invalid ' + state.error : 'missing'}; evidence/index.jsonl:${evidenceIndex.exists ? evidenceIndex.ok ? `${evidenceIndex.records.length} record(s)` : 'invalid ' + evidenceIndex.error : 'missing'}`,
339
- stateIndexOk ? '' : 'Add or repair .gse/state.json and .gse/evidence/index.jsonl so future sessions can continue without parsing long Markdown.',
340
- ),
341
- )
342
-
343
- const failed = checks.filter((item) => item.status === 'failed').length
344
- const warnings = checks.filter((item) => item.status === 'warning').length
345
- const passed = checks.filter((item) => item.status === 'passed').length
346
- return {
347
- target: resolvedTarget,
348
- generatedAt: new Date().toISOString(),
349
- summary: {
350
- status: failed > 0 ? 'failed' : warnings > 0 ? 'warning' : 'passed',
351
- passed,
352
- warnings,
353
- failed,
354
- total: checks.length,
355
- },
356
- workflows: {
357
- targetProjectDoctor: failed > 0 ? 'not-ready' : warnings > 0 ? 'verified-with-warnings' : 'verified',
358
- },
359
- state: {
360
- exists: state.exists,
361
- valid: stateHasCoreFields,
362
- phase: state.data?.phase ?? null,
363
- currentSliceStatus: state.data?.currentSlice?.status ?? null,
364
- lastEvidence: state.data?.lastEvidence ?? null,
365
- },
366
- evidenceIndex: {
367
- exists: evidenceIndex.exists,
368
- valid: evidenceIndexHasCoreFields,
369
- records: evidenceIndex.records.length,
370
- },
371
- canonicalPlans,
372
- git: {
373
- isGitRepo,
374
- root: isGitRepo ? gitRoot.stdout : null,
375
- trackedGseCount: trackedGse.length,
376
- },
377
- checks,
378
- limits: [
379
- 'Target project doctor is read-only.',
380
- 'It checks project-local GSE adoption, git/sparse visibility, canonical plan discoverability, quality gates, evidence, and thin host adapter drift.',
381
- 'It does not run project tests, browser smokes, CI, MCP, LSP, subagents, or release gates.',
382
- ],
383
- }
384
- }
385
-
386
- function createFixture() {
387
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'gse-target-doctor-'))
388
- fs.mkdirSync(path.join(dir, '.gse', 'goals'), { recursive: true })
389
- fs.mkdirSync(path.join(dir, '.gse', 'templates'), { recursive: true })
390
- fs.mkdirSync(path.join(dir, '.gse', 'evidence'), { recursive: true })
391
- fs.mkdirSync(path.join(dir, '.gse', 'agents'), { recursive: true })
392
- fs.mkdirSync(path.join(dir, '.gse', 'skills'), { recursive: true })
393
- fs.mkdirSync(path.join(dir, '.gse', 'lsp'), { recursive: true })
394
- fs.mkdirSync(path.join(dir, '.gse', 'hooks'), { recursive: true })
395
- fs.mkdirSync(path.join(dir, '.gse', 'mcp'), { recursive: true })
396
- fs.mkdirSync(path.join(dir, '.gse', 'plugins'), { recursive: true })
397
- fs.mkdirSync(path.join(dir, 'docs'), { recursive: true })
398
-
399
- const files = {
400
- '.gse/README.md': '# GSE\n\nCanonical plan: `docs/productization-architecture.md`.\n',
401
- '.gse/state.json': JSON.stringify({
402
- schemaVersion: 1,
403
- projectName: 'fixture',
404
- mode: 'enterprise',
405
- canonicalPlan: 'docs/productization-architecture.md',
406
- phase: 'execute',
407
- currentSlice: {
408
- id: 'fixture-slice',
409
- outcome: 'fixture outcome',
410
- status: 'verified',
411
- nextAction: 'continue',
412
- },
413
- toolStatuses: {
414
- browser: 'unknown',
415
- lsp: 'unknown',
416
- mcp: 'unknown',
417
- subagents: 'unknown',
418
- ci: 'unknown',
419
- },
420
- lastEvidence: '.gse/evidence/index.jsonl',
421
- residualRisks: [],
422
- }, null, 2) + '\n',
423
- '.gse/project-profile.md': '# Project Profile\n\nProduct/system name: fixture.\n',
424
- '.gse/goal-map.md': '# Goal Map\n\nNext action: continue.\n',
425
- '.gse/goals/README.md': '# Goal Details\n',
426
- '.gse/quality-gates.md': '# Quality Gates\n\n## Universal\n\n## UI Gate\n',
427
- '.gse/tooling.md': '# Tooling\n',
428
- '.gse/templates/change-brief.md': '# Change Brief\n',
429
- '.gse/templates/evidence.md': '# Evidence\n',
430
- '.gse/evidence/2026-07-06.md': '# Evidence\n',
431
- '.gse/evidence/index.jsonl': JSON.stringify({
432
- date: '2026-07-06',
433
- recordType: 'audit',
434
- status: 'verified',
435
- summary: 'Fixture target doctor evidence.',
436
- evidenceFile: '.gse/evidence/2026-07-06.md',
437
- commands: ['node scripts/audit-target-project.mjs --self-test'],
438
- nextAction: 'continue',
439
- }) + '\n',
440
- '.gse/agent-workspace.md': '# Agent Workspace\n',
441
- '.gse/agents/roles.md': '# Roles\n',
442
- '.gse/agents/dispatch.md': '# Dispatch\n',
443
- '.gse/skills/README.md': '# Skills\n',
444
- '.gse/lsp/README.md': '# LSP\n',
445
- '.gse/hooks/README.md': '# Hooks\n',
446
- '.gse/mcp/README.md': '# MCP\n',
447
- '.gse/plugins/README.md': '# Plugins\n',
448
- '.gse/release.md': '# Release\n',
449
- '.gse/incident-review.md': '# Incident\n',
450
- '.gse/audit.md': '# Audit\n',
451
- 'docs/productization-architecture.md': '# Productization Architecture\n',
452
- }
453
- for (const [relativePath, content] of Object.entries(files)) {
454
- const fullPath = path.join(dir, relativePath)
455
- fs.mkdirSync(path.dirname(fullPath), { recursive: true })
456
- fs.writeFileSync(fullPath, content, 'utf8')
457
- }
458
-
459
- runGit(dir, ['init'])
460
- runGit(dir, ['config', 'user.email', 'gse-fixture@example.local'])
461
- runGit(dir, ['config', 'user.name', 'GSE Fixture'])
462
- runGit(dir, ['add', '.'])
463
- runGit(dir, ['commit', '-m', 'fixture'])
464
- return dir
465
- }
466
-
467
- function renderMarkdown(report) {
468
- const lines = []
469
- lines.push('# GSE Target Project Doctor')
470
- lines.push('')
471
- lines.push('Generated: ' + report.generatedAt)
472
- lines.push('Target: ' + report.target)
473
- lines.push('')
474
- lines.push('## Summary')
475
- lines.push('')
476
- lines.push('- Status: ' + report.summary.status)
477
- lines.push('- Checks: ' + report.summary.passed + ' passed, ' + report.summary.warnings + ' warnings, ' + report.summary.failed + ' failed, ' + report.summary.total + ' total')
478
- lines.push('- Workflow: ' + report.workflows.targetProjectDoctor)
479
- lines.push('')
480
- lines.push('## Checks')
481
- lines.push('')
482
- for (const item of report.checks) {
483
- const marker = item.status === 'passed' ? '[x]' : item.status === 'warning' ? '[!]' : '[ ]'
484
- lines.push('- ' + marker + ' ' + item.id + ' ' + item.label + ': ' + item.evidence)
485
- if (item.recommendation) lines.push(' - Recommendation: ' + item.recommendation)
486
- }
487
- lines.push('')
488
- lines.push('## Limits')
489
- lines.push('')
490
- for (const item of report.limits) lines.push('- ' + item)
491
- return lines.join('\n') + '\n'
492
- }
493
-
494
- let report
495
- let fixtureDir = null
496
- if (selfTest) {
497
- fixtureDir = createFixture()
498
- report = auditTarget(fixtureDir)
499
- report.selfTest = { fixtureDir }
500
- } else {
501
- report = auditTarget(targetArg)
502
- }
503
-
504
- if (jsonOnly) console.log(JSON.stringify(report, null, 2))
505
- else console.log(renderMarkdown(report))
506
-
507
- if (report.summary.failed > 0) process.exit(1)
1
+ #!/usr/bin/env node
2
+ import fs from 'node:fs'
3
+ import os from 'node:os'
4
+ import path from 'node:path'
5
+ import { spawnSync } from 'node:child_process'
6
+
7
+ const args = process.argv.slice(2)
8
+
9
+ function readArg(name, fallback = null) {
10
+ const index = args.indexOf(name)
11
+ if (index === -1) return fallback
12
+ return args[index + 1] ?? fallback
13
+ }
14
+
15
+ const jsonOnly = args.includes('--json')
16
+ const selfTest = args.includes('--self-test') || !args.includes('--target')
17
+ const targetArg = readArg('--target')
18
+ const root = path.resolve(readArg('--root', path.join(import.meta.dirname, '..')))
19
+
20
+ function slash(value) {
21
+ return value.replace(/\\/g, '/')
22
+ }
23
+
24
+ function readText(filePath) {
25
+ return fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf8').replace(/^\uFEFF/, '') : ''
26
+ }
27
+
28
+ function readJson(filePath) {
29
+ if (!fs.existsSync(filePath)) return { exists: false, ok: false, data: null, error: 'missing' }
30
+ try {
31
+ return { exists: true, ok: true, data: JSON.parse(readText(filePath)), error: '' }
32
+ } catch (error) {
33
+ return { exists: true, ok: false, data: null, error: error.message }
34
+ }
35
+ }
36
+
37
+ function readJsonl(filePath) {
38
+ if (!fs.existsSync(filePath)) return { exists: false, ok: false, records: [], error: 'missing' }
39
+ const lines = readText(filePath)
40
+ .split(/\r?\n/)
41
+ .map((line) => line.trim())
42
+ .filter(Boolean)
43
+ const records = []
44
+ for (const [index, line] of lines.entries()) {
45
+ try {
46
+ records.push(JSON.parse(line))
47
+ } catch (error) {
48
+ return { exists: true, ok: false, records, error: `line ${index + 1}: ${error.message}` }
49
+ }
50
+ }
51
+ return { exists: true, ok: true, records, error: '' }
52
+ }
53
+
54
+ function exists(target, relativePath) {
55
+ return fs.existsSync(path.join(target, relativePath))
56
+ }
57
+
58
+ function listFiles(dir) {
59
+ const files = []
60
+ function visit(itemPath) {
61
+ if (!fs.existsSync(itemPath)) return
62
+ const stat = fs.statSync(itemPath)
63
+ if (stat.isDirectory()) {
64
+ for (const child of fs.readdirSync(itemPath)) visit(path.join(itemPath, child))
65
+ return
66
+ }
67
+ if (stat.isFile()) files.push(itemPath)
68
+ }
69
+ visit(dir)
70
+ return files
71
+ }
72
+
73
+ function runGit(target, commandArgs) {
74
+ const result = spawnSync('git', commandArgs, {
75
+ cwd: target,
76
+ encoding: 'utf8',
77
+ windowsHide: true,
78
+ })
79
+ return {
80
+ status: result.status ?? 1,
81
+ stdout: (result.stdout ?? '').trim(),
82
+ stderr: (result.stderr ?? '').trim(),
83
+ }
84
+ }
85
+
86
+ function statusFrom(ok, warn = false) {
87
+ if (ok) return 'passed'
88
+ if (warn) return 'warning'
89
+ return 'failed'
90
+ }
91
+
92
+ function check(id, label, status, evidence, recommendation = '') {
93
+ return { id, label, status, evidence, recommendation }
94
+ }
95
+
96
+ const requiredFiles = [
97
+ '.gse/README.md',
98
+ '.gse/project-profile.md',
99
+ '.gse/goal-map.md',
100
+ '.gse/goals/README.md',
101
+ '.gse/quality-gates.md',
102
+ '.gse/tooling.md',
103
+ '.gse/templates/change-brief.md',
104
+ '.gse/templates/evidence.md',
105
+ ]
106
+
107
+ const enterpriseFiles = [
108
+ '.gse/agent-workspace.md',
109
+ '.gse/agents/roles.md',
110
+ '.gse/agents/dispatch.md',
111
+ '.gse/skills/README.md',
112
+ '.gse/lsp/README.md',
113
+ '.gse/hooks/README.md',
114
+ '.gse/mcp/README.md',
115
+ '.gse/plugins/README.md',
116
+ '.gse/release.md',
117
+ '.gse/incident-review.md',
118
+ '.gse/audit.md',
119
+ ]
120
+
121
+ function findCanonicalPlan(target) {
122
+ const candidates = []
123
+ const texts = [
124
+ readText(path.join(target, '.gse', 'README.md')),
125
+ readText(path.join(target, '.gse', 'project-profile.md')),
126
+ readText(path.join(target, '.gse', 'goal-map.md')),
127
+ ].join('\n')
128
+
129
+ const regex = /docs\/[A-Za-z0-9._/-]*?(?:architecture|productization)[A-Za-z0-9._/-]*?\.md/g
130
+ for (const match of texts.matchAll(regex)) {
131
+ if (!candidates.includes(match[0])) candidates.push(match[0])
132
+ }
133
+
134
+ for (const fallback of [
135
+ 'docs/aion-productization-architecture.md',
136
+ 'docs/museflow-ai-film-productization-architecture.md',
137
+ ]) {
138
+ if (exists(target, fallback) && !candidates.includes(fallback)) candidates.push(fallback)
139
+ }
140
+
141
+ return candidates.map((relativePath) => ({ relativePath, exists: exists(target, relativePath) }))
142
+ }
143
+
144
+ function auditTarget(target) {
145
+ const resolvedTarget = path.resolve(target)
146
+ const gseDir = path.join(resolvedTarget, '.gse')
147
+ const checks = []
148
+
149
+ const hasGse = fs.existsSync(gseDir)
150
+ checks.push(
151
+ check(
152
+ 'TPD01',
153
+ '.gse directory exists',
154
+ statusFrom(hasGse),
155
+ hasGse ? '.gse exists' : '.gse missing',
156
+ hasGse ? '' : 'Run GSE init/adopt before relying on project-local workflow files.',
157
+ ),
158
+ )
159
+
160
+ const missingRequired = requiredFiles.filter((relativePath) => !exists(resolvedTarget, relativePath))
161
+ checks.push(
162
+ check(
163
+ 'TPD02',
164
+ 'required GSE files exist',
165
+ statusFrom(missingRequired.length === 0),
166
+ missingRequired.length === 0 ? `${requiredFiles.length}/${requiredFiles.length} required files present` : 'missing: ' + missingRequired.join(', '),
167
+ missingRequired.length === 0 ? '' : 'Regenerate missing scaffold files or document why this project intentionally uses a smaller mode.',
168
+ ),
169
+ )
170
+
171
+ const presentEnterprise = enterpriseFiles.filter((relativePath) => exists(resolvedTarget, relativePath))
172
+ checks.push(
173
+ check(
174
+ 'TPD03',
175
+ 'enterprise workspace files are visible when present',
176
+ presentEnterprise.length === 0 ? 'warning' : 'passed',
177
+ presentEnterprise.length === 0 ? 'no enterprise workspace files found' : `${presentEnterprise.length}/${enterpriseFiles.length} enterprise files present`,
178
+ presentEnterprise.length === 0 ? 'Large or long-running projects should use standard/enterprise scaffold files.' : '',
179
+ ),
180
+ )
181
+
182
+ const canonicalPlans = findCanonicalPlan(resolvedTarget)
183
+ const existingCanonicalPlans = canonicalPlans.filter((item) => item.exists)
184
+ checks.push(
185
+ check(
186
+ 'TPD04',
187
+ 'canonical project plan is discoverable',
188
+ statusFrom(existingCanonicalPlans.length > 0),
189
+ canonicalPlans.length === 0 ? 'no canonical plan reference found' : canonicalPlans.map((item) => `${item.relativePath}:${item.exists ? 'exists' : 'missing'}`).join(', '),
190
+ existingCanonicalPlans.length > 0 ? '' : 'Record the project canonical plan in .gse/README.md or .gse/goal-map.md.',
191
+ ),
192
+ )
193
+
194
+ const qualityText = readText(path.join(resolvedTarget, '.gse', 'quality-gates.md'))
195
+ const hasUniversalGate = qualityText.includes('Universal') || qualityText.includes('Universal Slice Gate')
196
+ const hasDomainGate = /Identity|Chat|Canvas|UI|Browser|Media|Package|Encoding|Release|Recovery/i.test(qualityText)
197
+ checks.push(
198
+ check(
199
+ 'TPD05',
200
+ 'quality gates include universal and project/domain gates',
201
+ statusFrom(hasUniversalGate && hasDomainGate, hasUniversalGate || hasDomainGate),
202
+ `universal:${hasUniversalGate}, domain:${hasDomainGate}`,
203
+ hasUniversalGate && hasDomainGate ? '' : 'Add project-specific quality gates instead of relying only on generic GSE wording.',
204
+ ),
205
+ )
206
+
207
+ const evidenceDir = path.join(gseDir, 'evidence')
208
+ const evidenceFiles = fs.existsSync(evidenceDir)
209
+ ? listFiles(evidenceDir).filter((filePath) => /\.(md|json|jsonl)$/i.test(filePath))
210
+ : []
211
+ checks.push(
212
+ check(
213
+ 'TPD06',
214
+ 'project-local GSE evidence exists',
215
+ statusFrom(evidenceFiles.length > 0),
216
+ evidenceFiles.length > 0 ? `${evidenceFiles.length} evidence file(s)` : 'no evidence files',
217
+ evidenceFiles.length > 0 ? '' : 'Record adoption or slice evidence under .gse/evidence/.',
218
+ ),
219
+ )
220
+
221
+ const gitRoot = runGit(resolvedTarget, ['rev-parse', '--show-toplevel'])
222
+ const isGitRepo = gitRoot.status === 0
223
+ checks.push(
224
+ check(
225
+ 'TPD07',
226
+ 'target is inside a git repository',
227
+ isGitRepo ? 'passed' : 'warning',
228
+ isGitRepo ? slash(gitRoot.stdout) : gitRoot.stderr || 'not a git repository',
229
+ isGitRepo ? '' : 'Git tracking checks are unavailable outside a git repository.',
230
+ ),
231
+ )
232
+
233
+ let trackedGse = []
234
+ if (isGitRepo) {
235
+ const tracked = runGit(resolvedTarget, ['ls-files', '.gse'])
236
+ trackedGse = tracked.status === 0 && tracked.stdout ? tracked.stdout.split(/\r?\n/).filter(Boolean) : []
237
+ checks.push(
238
+ check(
239
+ 'TPD08',
240
+ '.gse files are tracked by git',
241
+ statusFrom(trackedGse.length > 0),
242
+ trackedGse.length > 0 ? `${trackedGse.length} tracked .gse file(s)` : 'no tracked .gse files',
243
+ trackedGse.length > 0 ? '' : 'Project-level .gse files should normally be committed; caches and host-local folders should not.',
244
+ ),
245
+ )
246
+
247
+ const status = runGit(resolvedTarget, ['status', '--short', '.gse'])
248
+ checks.push(
249
+ check(
250
+ 'TPD09',
251
+ '.gse worktree is clean',
252
+ status.status === 0 && status.stdout.length === 0 ? 'passed' : 'warning',
253
+ status.stdout || 'clean',
254
+ status.stdout ? 'Review and intentionally stage/commit or discard project-local GSE changes.' : '',
255
+ ),
256
+ )
257
+
258
+ const sparse = runGit(resolvedTarget, ['sparse-checkout', 'list'])
259
+ const sparseLines = sparse.status === 0 && sparse.stdout ? sparse.stdout.split(/\r?\n/).map((line) => slash(line.trim())).filter(Boolean) : []
260
+ const sparseEnabled = sparse.status === 0 && sparseLines.length > 0
261
+ const sparseIncludesGse = sparseLines.some((line) => line === '.gse' || line === '.gse/' || line.startsWith('.gse/') || line === '/*' || line === '*')
262
+ checks.push(
263
+ check(
264
+ 'TPD10',
265
+ 'sparse-checkout visibility for .gse is known',
266
+ sparseEnabled && !sparseIncludesGse ? 'warning' : 'passed',
267
+ sparseEnabled ? `sparse entries: ${sparseLines.join(', ') || '<empty>'}; includes .gse: ${sparseIncludesGse}` : 'sparse-checkout not enabled or no sparse list',
268
+ sparseEnabled && !sparseIncludesGse ? 'Use git add --sparse for .gse updates or add .gse to sparse-checkout rules.' : '',
269
+ ),
270
+ )
271
+ }
272
+
273
+ const hostAdapterFindings = []
274
+ for (const [hostDir, adapterPaths] of [
275
+ ['.codex', ['.codex/gse-command.md', '.codex/gse-adapter.md']],
276
+ ['.claude', ['.claude/commands/gse.md', '.claude/gse-adapter.md']],
277
+ ]) {
278
+ if (exists(resolvedTarget, hostDir)) {
279
+ const candidates = adapterPaths.map((adapterPath) => {
280
+ const text = readText(path.join(resolvedTarget, adapterPath))
281
+ return {
282
+ adapterPath,
283
+ exists: exists(resolvedTarget, adapterPath),
284
+ pointsToGse: text.includes('.gse/'),
285
+ }
286
+ })
287
+ const matching = candidates.find((item) => item.exists && item.pointsToGse)
288
+ hostAdapterFindings.push({
289
+ hostDir,
290
+ adapterPath: matching?.adapterPath ?? candidates[0].adapterPath,
291
+ exists: Boolean(matching),
292
+ pointsToGse: Boolean(matching),
293
+ candidates,
294
+ })
295
+ }
296
+ }
297
+ const badAdapters = hostAdapterFindings.filter((item) => !item.exists || !item.pointsToGse)
298
+ checks.push(
299
+ check(
300
+ 'TPD11',
301
+ 'host adapters point back to .gse when host folders exist',
302
+ hostAdapterFindings.length === 0 ? 'passed' : statusFrom(badAdapters.length === 0),
303
+ hostAdapterFindings.length === 0 ? 'no Codex/Claude host folders detected' : hostAdapterFindings.map((item) => `${item.adapterPath}:exists=${item.exists},pointsToGse=${item.pointsToGse}`).join('; '),
304
+ badAdapters.length === 0 ? '' : 'Generate or repair thin host adapters; do not duplicate policy outside .gse/.',
305
+ ),
306
+ )
307
+
308
+ const state = readJson(path.join(gseDir, 'state.json'))
309
+ const evidenceIndex = readJsonl(path.join(gseDir, 'evidence', 'index.jsonl'))
310
+ const stateHasCoreFields =
311
+ state.ok &&
312
+ state.data?.schemaVersion === 1 &&
313
+ typeof state.data?.mode === 'string' &&
314
+ typeof state.data?.phase === 'string' &&
315
+ typeof state.data?.currentSlice?.status === 'string' &&
316
+ state.data?.toolStatuses &&
317
+ typeof state.data.toolStatuses === 'object'
318
+ const evidenceIndexHasCoreFields =
319
+ evidenceIndex.ok &&
320
+ evidenceIndex.records.length > 0 &&
321
+ evidenceIndex.records.every(
322
+ (record) =>
323
+ typeof record.date === 'string' &&
324
+ typeof record.recordType === 'string' &&
325
+ typeof record.status === 'string' &&
326
+ typeof record.summary === 'string' &&
327
+ typeof record.evidenceFile === 'string' &&
328
+ Array.isArray(record.commands) &&
329
+ typeof record.nextAction === 'string',
330
+ )
331
+ const stateIndexOk = stateHasCoreFields && evidenceIndexHasCoreFields
332
+ const stateIndexWarn = !state.exists || !evidenceIndex.exists
333
+ checks.push(
334
+ check(
335
+ 'TPD12',
336
+ 'machine-readable state and evidence index are present',
337
+ statusFrom(stateIndexOk, stateIndexWarn),
338
+ `state.json:${state.exists ? state.ok ? 'valid' : 'invalid ' + state.error : 'missing'}; evidence/index.jsonl:${evidenceIndex.exists ? evidenceIndex.ok ? `${evidenceIndex.records.length} record(s)` : 'invalid ' + evidenceIndex.error : 'missing'}`,
339
+ stateIndexOk ? '' : 'Add or repair .gse/state.json and .gse/evidence/index.jsonl so future sessions can continue without parsing long Markdown.',
340
+ ),
341
+ )
342
+
343
+ const failed = checks.filter((item) => item.status === 'failed').length
344
+ const warnings = checks.filter((item) => item.status === 'warning').length
345
+ const passed = checks.filter((item) => item.status === 'passed').length
346
+ return {
347
+ target: resolvedTarget,
348
+ generatedAt: new Date().toISOString(),
349
+ summary: {
350
+ status: failed > 0 ? 'failed' : warnings > 0 ? 'warning' : 'passed',
351
+ passed,
352
+ warnings,
353
+ failed,
354
+ total: checks.length,
355
+ },
356
+ workflows: {
357
+ targetProjectDoctor: failed > 0 ? 'not-ready' : warnings > 0 ? 'verified-with-warnings' : 'verified',
358
+ },
359
+ state: {
360
+ exists: state.exists,
361
+ valid: stateHasCoreFields,
362
+ phase: state.data?.phase ?? null,
363
+ currentSliceStatus: state.data?.currentSlice?.status ?? null,
364
+ lastEvidence: state.data?.lastEvidence ?? null,
365
+ },
366
+ evidenceIndex: {
367
+ exists: evidenceIndex.exists,
368
+ valid: evidenceIndexHasCoreFields,
369
+ records: evidenceIndex.records.length,
370
+ },
371
+ canonicalPlans,
372
+ git: {
373
+ isGitRepo,
374
+ root: isGitRepo ? gitRoot.stdout : null,
375
+ trackedGseCount: trackedGse.length,
376
+ },
377
+ checks,
378
+ limits: [
379
+ 'Target project doctor is read-only.',
380
+ 'It checks project-local GSE adoption, git/sparse visibility, canonical plan discoverability, quality gates, evidence, and thin host adapter drift.',
381
+ 'It does not run project tests, browser smokes, CI, MCP, LSP, subagents, or release gates.',
382
+ ],
383
+ }
384
+ }
385
+
386
+ function createFixture() {
387
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'gse-target-doctor-'))
388
+ fs.mkdirSync(path.join(dir, '.gse', 'goals'), { recursive: true })
389
+ fs.mkdirSync(path.join(dir, '.gse', 'templates'), { recursive: true })
390
+ fs.mkdirSync(path.join(dir, '.gse', 'evidence'), { recursive: true })
391
+ fs.mkdirSync(path.join(dir, '.gse', 'agents'), { recursive: true })
392
+ fs.mkdirSync(path.join(dir, '.gse', 'skills'), { recursive: true })
393
+ fs.mkdirSync(path.join(dir, '.gse', 'lsp'), { recursive: true })
394
+ fs.mkdirSync(path.join(dir, '.gse', 'hooks'), { recursive: true })
395
+ fs.mkdirSync(path.join(dir, '.gse', 'mcp'), { recursive: true })
396
+ fs.mkdirSync(path.join(dir, '.gse', 'plugins'), { recursive: true })
397
+ fs.mkdirSync(path.join(dir, 'docs'), { recursive: true })
398
+
399
+ const files = {
400
+ '.gse/README.md': '# GSE\n\nCanonical plan: `docs/productization-architecture.md`.\n',
401
+ '.gse/state.json': JSON.stringify({
402
+ schemaVersion: 1,
403
+ projectName: 'fixture',
404
+ mode: 'enterprise',
405
+ canonicalPlan: 'docs/productization-architecture.md',
406
+ phase: 'execute',
407
+ currentSlice: {
408
+ id: 'fixture-slice',
409
+ outcome: 'fixture outcome',
410
+ status: 'verified',
411
+ nextAction: 'continue',
412
+ },
413
+ toolStatuses: {
414
+ browser: 'unknown',
415
+ lsp: 'unknown',
416
+ mcp: 'unknown',
417
+ subagents: 'unknown',
418
+ ci: 'unknown',
419
+ },
420
+ lastEvidence: '.gse/evidence/index.jsonl',
421
+ residualRisks: [],
422
+ }, null, 2) + '\n',
423
+ '.gse/project-profile.md': '# Project Profile\n\nProduct/system name: fixture.\n',
424
+ '.gse/goal-map.md': '# Goal Map\n\nNext action: continue.\n',
425
+ '.gse/goals/README.md': '# Goal Details\n',
426
+ '.gse/quality-gates.md': '# Quality Gates\n\n## Universal\n\n## UI Gate\n',
427
+ '.gse/tooling.md': '# Tooling\n',
428
+ '.gse/templates/change-brief.md': '# Change Brief\n',
429
+ '.gse/templates/evidence.md': '# Evidence\n',
430
+ '.gse/evidence/2026-07-06.md': '# Evidence\n',
431
+ '.gse/evidence/index.jsonl': JSON.stringify({
432
+ date: '2026-07-06',
433
+ recordType: 'audit',
434
+ status: 'verified',
435
+ summary: 'Fixture target doctor evidence.',
436
+ evidenceFile: '.gse/evidence/2026-07-06.md',
437
+ commands: ['node scripts/audit-target-project.mjs --self-test'],
438
+ nextAction: 'continue',
439
+ }) + '\n',
440
+ '.gse/agent-workspace.md': '# Agent Workspace\n',
441
+ '.gse/agents/roles.md': '# Roles\n',
442
+ '.gse/agents/dispatch.md': '# Dispatch\n',
443
+ '.gse/skills/README.md': '# Skills\n',
444
+ '.gse/lsp/README.md': '# LSP\n',
445
+ '.gse/hooks/README.md': '# Hooks\n',
446
+ '.gse/mcp/README.md': '# MCP\n',
447
+ '.gse/plugins/README.md': '# Plugins\n',
448
+ '.gse/release.md': '# Release\n',
449
+ '.gse/incident-review.md': '# Incident\n',
450
+ '.gse/audit.md': '# Audit\n',
451
+ 'docs/productization-architecture.md': '# Productization Architecture\n',
452
+ }
453
+ for (const [relativePath, content] of Object.entries(files)) {
454
+ const fullPath = path.join(dir, relativePath)
455
+ fs.mkdirSync(path.dirname(fullPath), { recursive: true })
456
+ fs.writeFileSync(fullPath, content, 'utf8')
457
+ }
458
+
459
+ runGit(dir, ['init'])
460
+ runGit(dir, ['config', 'user.email', 'gse-fixture@example.local'])
461
+ runGit(dir, ['config', 'user.name', 'GSE Fixture'])
462
+ runGit(dir, ['add', '.'])
463
+ runGit(dir, ['commit', '-m', 'fixture'])
464
+ return dir
465
+ }
466
+
467
+ function renderMarkdown(report) {
468
+ const lines = []
469
+ lines.push('# GSE Target Project Doctor')
470
+ lines.push('')
471
+ lines.push('Generated: ' + report.generatedAt)
472
+ lines.push('Target: ' + report.target)
473
+ lines.push('')
474
+ lines.push('## Summary')
475
+ lines.push('')
476
+ lines.push('- Status: ' + report.summary.status)
477
+ lines.push('- Checks: ' + report.summary.passed + ' passed, ' + report.summary.warnings + ' warnings, ' + report.summary.failed + ' failed, ' + report.summary.total + ' total')
478
+ lines.push('- Workflow: ' + report.workflows.targetProjectDoctor)
479
+ lines.push('')
480
+ lines.push('## Checks')
481
+ lines.push('')
482
+ for (const item of report.checks) {
483
+ const marker = item.status === 'passed' ? '[x]' : item.status === 'warning' ? '[!]' : '[ ]'
484
+ lines.push('- ' + marker + ' ' + item.id + ' ' + item.label + ': ' + item.evidence)
485
+ if (item.recommendation) lines.push(' - Recommendation: ' + item.recommendation)
486
+ }
487
+ lines.push('')
488
+ lines.push('## Limits')
489
+ lines.push('')
490
+ for (const item of report.limits) lines.push('- ' + item)
491
+ return lines.join('\n') + '\n'
492
+ }
493
+
494
+ let report
495
+ let fixtureDir = null
496
+ if (selfTest) {
497
+ fixtureDir = createFixture()
498
+ report = auditTarget(fixtureDir)
499
+ report.selfTest = { fixtureDir }
500
+ } else {
501
+ report = auditTarget(targetArg)
502
+ }
503
+
504
+ if (jsonOnly) console.log(JSON.stringify(report, null, 2))
505
+ else console.log(renderMarkdown(report))
506
+
507
+ if (report.summary.failed > 0) process.exit(1)