@t275005746/gse 0.1.0 → 0.1.2

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 (228) 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 +147 -27
  14. package/CHANGELOG.md +31 -15
  15. package/CONTRIBUTING.md +64 -64
  16. package/LICENSE +21 -21
  17. package/README.md +14 -7
  18. package/README.zh-CN.md +14 -7
  19. package/SECURITY.md +41 -41
  20. package/SKILL.md +32 -12
  21. package/SUPPORT.md +38 -38
  22. package/assets/marketplace/README.md +7 -7
  23. package/assets/marketplace/gse-listing.json +75 -75
  24. package/assets/templates/acceptance-execution-packet.md +73 -73
  25. package/assets/templates/adr.md +14 -14
  26. package/assets/templates/change-brief.md +16 -16
  27. package/assets/templates/design.md +18 -18
  28. package/assets/templates/dispatch-packet.md +100 -92
  29. package/assets/templates/evidence.md +15 -9
  30. package/assets/templates/execution-quality-pack.md +65 -65
  31. package/assets/templates/goal-map.md +21 -21
  32. package/assets/templates/host-adapter.md +48 -48
  33. package/assets/templates/host-ui-invocation-record.md +42 -42
  34. package/assets/templates/incident-review.md +60 -60
  35. package/assets/templates/public-channel-publication-record.md +49 -49
  36. package/assets/templates/public-ci-run-record.md +53 -53
  37. package/assets/templates/public-release-record.md +65 -65
  38. package/assets/templates/public-repository-settings-record.md +59 -59
  39. package/assets/templates/public-security-contact-record.md +45 -45
  40. package/assets/templates/release-trust-record.md +32 -32
  41. package/assets/templates/review.md +18 -18
  42. package/assets/templates/role-fallback-packet.md +49 -0
  43. package/assets/templates/spec.md +16 -16
  44. package/assets/templates/target-adoption-evidence.md +29 -29
  45. package/assets/templates/tasks.md +17 -17
  46. package/assets/templates/update-release-acceptance-record.md +58 -58
  47. package/examples/README.md +22 -22
  48. package/examples/agent-runtime-host/.claude/gse-adapter.md +6 -6
  49. package/examples/agent-runtime-host/.codex/gse-adapter.md +7 -7
  50. package/examples/agent-runtime-host/.gse/goal-map.md +7 -7
  51. package/examples/agent-runtime-host/.gse/project-profile.md +27 -27
  52. package/examples/agent-runtime-host/.gse/tooling.md +5 -5
  53. package/examples/agent-runtime-host/.mcp.json +9 -9
  54. package/examples/agent-runtime-host/AGENTS.md +5 -5
  55. package/examples/agent-runtime-host/README.md +10 -10
  56. package/examples/agent-runtime-host/docs/model-routing.md +5 -5
  57. package/examples/cli-tool/.gse/project-profile.md +21 -21
  58. package/examples/cli-tool/AGENTS.md +5 -5
  59. package/examples/cli-tool/README.md +12 -12
  60. package/examples/cli-tool/package.json +21 -21
  61. package/examples/small-app/.env.example +2 -2
  62. package/examples/small-app/.github/workflows/ci.yml +8 -8
  63. package/examples/small-app/AGENTS.md +5 -5
  64. package/examples/small-app/README.md +12 -12
  65. package/examples/small-app/package.json +26 -26
  66. package/examples/small-app/playwright.config.ts +4 -4
  67. package/package.json +52 -44
  68. package/references/adoption-recipes.md +171 -171
  69. package/references/agent-roles.md +42 -21
  70. package/references/architecture-health.md +101 -101
  71. package/references/benchmark-audit.md +73 -73
  72. package/references/commands.md +74 -45
  73. package/references/community-channels.md +46 -46
  74. package/references/compatibility.md +70 -70
  75. package/references/design-basis.md +38 -38
  76. package/references/domain-model.md +129 -129
  77. package/references/domain-quality-gates.md +75 -75
  78. package/references/drift-audit.md +81 -80
  79. package/references/evidence-taxonomy.md +145 -108
  80. package/references/file-ownership.md +97 -93
  81. package/references/final-form-roadmap.md +201 -0
  82. package/references/final-readiness.md +84 -84
  83. package/references/forward-test.md +133 -133
  84. package/references/goal-map.md +36 -36
  85. package/references/host-adapters.md +129 -101
  86. package/references/learning-system.md +42 -26
  87. package/references/maintenance-cadence.md +51 -0
  88. package/references/marketplace-discovery.md +46 -46
  89. package/references/model-routing.md +103 -103
  90. package/references/open-source-defaults.md +39 -39
  91. package/references/operating-model.md +52 -52
  92. package/references/packaging.md +277 -277
  93. package/references/project-agent-workspace.md +89 -89
  94. package/references/project-bootstrap.md +122 -122
  95. package/references/project-guards.md +52 -0
  96. package/references/project-profile.md +57 -57
  97. package/references/public-release.md +174 -174
  98. package/references/quality-gates.md +96 -89
  99. package/references/recovery.md +176 -176
  100. package/references/release-trust.md +43 -43
  101. package/references/release.md +126 -126
  102. package/references/review.md +141 -141
  103. package/references/role-dispatch-fallback.md +54 -0
  104. package/references/router.md +90 -90
  105. package/references/spec-workflow.md +66 -66
  106. package/references/task-levels.md +81 -81
  107. package/references/tool-adapters.md +80 -70
  108. package/scripts/audit-acceptance-execution-packet.mjs +133 -133
  109. package/scripts/audit-adoption-recipes.mjs +99 -99
  110. package/scripts/audit-change-lifecycle.mjs +77 -77
  111. package/scripts/audit-change-system.mjs +134 -134
  112. package/scripts/audit-ci-readiness.mjs +107 -107
  113. package/scripts/audit-close-gate-hardening.mjs +188 -0
  114. package/scripts/audit-close-gate.mjs +448 -262
  115. package/scripts/audit-command-adapters.mjs +91 -91
  116. package/scripts/audit-command-execution.mjs +212 -199
  117. package/scripts/audit-commands.mjs +7 -5
  118. package/scripts/audit-compatibility.mjs +149 -149
  119. package/scripts/audit-completion-plan-drill.mjs +230 -0
  120. package/scripts/audit-completion-readiness.mjs +290 -287
  121. package/scripts/audit-continue-preflight.mjs +234 -0
  122. package/scripts/audit-distribution.mjs +251 -251
  123. package/scripts/audit-domain-quality-gates.mjs +108 -108
  124. package/scripts/audit-evidence-levels.mjs +217 -0
  125. package/scripts/audit-evidence-placeholders.mjs +126 -126
  126. package/scripts/audit-evidence-review-queue.mjs +206 -0
  127. package/scripts/audit-final-acceptance-packet.mjs +9 -9
  128. package/scripts/audit-final-form-progress-report.mjs +19 -18
  129. package/scripts/audit-final-form-roadmap.mjs +157 -0
  130. package/scripts/audit-final-form-stale-copy.mjs +2 -2
  131. package/scripts/audit-final-readiness-promotion.mjs +255 -255
  132. package/scripts/audit-final-readiness.mjs +226 -226
  133. package/scripts/audit-fixtures.mjs +154 -154
  134. package/scripts/audit-fresh-session-readiness.mjs +177 -177
  135. package/scripts/audit-host-capabilities.mjs +237 -0
  136. package/scripts/audit-host-runtime-evidence-handoff.mjs +159 -159
  137. package/scripts/audit-host-runtime-invocation-drill.mjs +240 -240
  138. package/scripts/audit-host-runtime-invocations.mjs +254 -254
  139. package/scripts/audit-host-ui-invocation.mjs +132 -132
  140. package/scripts/audit-installed-sync.mjs +203 -0
  141. package/scripts/audit-learning-drift.mjs +292 -0
  142. package/scripts/audit-learning-promotion.mjs +351 -0
  143. package/scripts/audit-learning-system.mjs +24 -14
  144. package/scripts/audit-local-final-form-completion.mjs +11 -10
  145. package/scripts/audit-maintenance-cadence.mjs +139 -0
  146. package/scripts/audit-maintenance-snapshot.mjs +181 -0
  147. package/scripts/audit-marketplace-discovery.mjs +122 -122
  148. package/scripts/audit-npm-package-metadata.mjs +160 -154
  149. package/scripts/audit-npm-publish-dry-run.mjs +194 -166
  150. package/scripts/audit-npm-tarball-install.mjs +195 -189
  151. package/scripts/audit-open-source-defaults.mjs +92 -92
  152. package/scripts/audit-open-source-readiness.mjs +97 -97
  153. package/scripts/audit-owner-external-gate-kit.mjs +12 -11
  154. package/scripts/audit-project-guards.mjs +189 -0
  155. package/scripts/audit-project.mjs +144 -141
  156. package/scripts/audit-public-acceptance-command-dry-run-drill.mjs +203 -203
  157. package/scripts/audit-public-acceptance-handoff.mjs +10 -10
  158. package/scripts/audit-public-acceptance-readiness.mjs +222 -222
  159. package/scripts/audit-public-channel-publication.mjs +248 -248
  160. package/scripts/audit-public-ci-run.mjs +184 -184
  161. package/scripts/audit-public-collaboration-templates.mjs +98 -98
  162. package/scripts/audit-public-external-gate-probe.mjs +206 -206
  163. package/scripts/audit-public-release-checklist.mjs +17 -15
  164. package/scripts/audit-public-release-decision.mjs +201 -201
  165. package/scripts/audit-public-release-metadata.mjs +176 -176
  166. package/scripts/audit-public-repository-settings.mjs +237 -237
  167. package/scripts/audit-public-security-contact.mjs +171 -171
  168. package/scripts/audit-readme-docs.mjs +6 -4
  169. package/scripts/audit-recovery-readiness.mjs +98 -98
  170. package/scripts/audit-release-bundle.mjs +13 -11
  171. package/scripts/audit-release-owner-action-plan-drill.mjs +5 -4
  172. package/scripts/audit-release-owner-action-plan.mjs +10 -10
  173. package/scripts/audit-release-readiness.mjs +106 -106
  174. package/scripts/audit-release-status-manifest.mjs +4 -4
  175. package/scripts/audit-release-trust.mjs +62 -62
  176. package/scripts/audit-remote-distribution.mjs +266 -266
  177. package/scripts/audit-roadmap-consistency.mjs +234 -230
  178. package/scripts/audit-role-dispatch-fallback.mjs +212 -0
  179. package/scripts/audit-session-sync.mjs +127 -0
  180. package/scripts/audit-signing.mjs +147 -147
  181. package/scripts/audit-state-freshness.mjs +20 -14
  182. package/scripts/audit-state-repair.mjs +360 -0
  183. package/scripts/audit-target-adoption-evidence.mjs +117 -117
  184. package/scripts/audit-target-hardening-drills.mjs +267 -0
  185. package/scripts/audit-target-project.mjs +507 -507
  186. package/scripts/audit-tool-fallback-policy.mjs +180 -0
  187. package/scripts/audit-ui-browser-evidence-policy.mjs +191 -0
  188. package/scripts/audit-update-release-acceptance.mjs +136 -136
  189. package/scripts/audit-v1-target-validation.mjs +269 -269
  190. package/scripts/audit-validation-profiles.mjs +125 -123
  191. package/scripts/backfill-evidence-levels.mjs +98 -0
  192. package/scripts/check-encoding.mjs +72 -0
  193. package/scripts/close-change.mjs +116 -116
  194. package/scripts/discover-project-profile.mjs +307 -307
  195. package/scripts/generate-command-adapter.mjs +231 -231
  196. package/scripts/generate-continue-packet.mjs +1214 -0
  197. package/scripts/generate-final-acceptance-packet.mjs +188 -173
  198. package/scripts/generate-final-form-progress-report.mjs +191 -189
  199. package/scripts/generate-host-runtime-evidence-handoff.mjs +198 -191
  200. package/scripts/generate-maintenance-snapshot.mjs +216 -0
  201. package/scripts/generate-owner-external-gate-kit.mjs +295 -295
  202. package/scripts/generate-public-acceptance-handoff.mjs +168 -156
  203. package/scripts/generate-public-release-checklist.mjs +207 -207
  204. package/scripts/generate-release-bundle.mjs +505 -505
  205. package/scripts/generate-release-owner-action-plan.mjs +172 -171
  206. package/scripts/generate-release-status-manifest.mjs +199 -198
  207. package/scripts/generate-session-prompt.mjs +188 -188
  208. package/scripts/gse.mjs +67 -67
  209. package/scripts/init-change.mjs +265 -265
  210. package/scripts/init-project.mjs +793 -712
  211. package/scripts/install-gse.mjs +234 -234
  212. package/scripts/lib/evidence-placeholders.mjs +28 -28
  213. package/scripts/package-gse.mjs +174 -174
  214. package/scripts/probe-public-external-gates.mjs +167 -167
  215. package/scripts/record-host-invocation.mjs +151 -151
  216. package/scripts/record-learning.mjs +37 -8
  217. package/scripts/record-public-channel-publication.mjs +178 -178
  218. package/scripts/record-public-ci-run.mjs +180 -180
  219. package/scripts/record-public-release.mjs +175 -175
  220. package/scripts/record-public-repository-settings.mjs +209 -209
  221. package/scripts/record-public-security-contact.mjs +157 -157
  222. package/scripts/record-session-sync.mjs +87 -0
  223. package/scripts/run-gse-command.mjs +79 -47
  224. package/scripts/run-validation-profile.mjs +24 -5
  225. package/scripts/sign-gse-package.mjs +83 -83
  226. package/scripts/update-project-state.mjs +223 -223
  227. package/scripts/validate-gse.mjs +216 -0
  228. package/scripts/verify-gse-package.mjs +85 -85
@@ -1,83 +1,83 @@
1
- #!/usr/bin/env node
2
- import fs from 'node:fs'
3
- import path from 'node:path'
4
- import crypto from 'node:crypto'
5
-
6
- const args = process.argv.slice(2)
7
-
8
- function readArg(name, fallback = null) {
9
- const index = args.indexOf(name)
10
- if (index === -1) return fallback
11
- return args[index + 1] ?? fallback
12
- }
13
-
14
- const packageDir = path.resolve(readArg('--package', process.cwd()))
15
- const privateKeyPath = path.resolve(readArg('--private-key', path.join(packageDir, 'gse-signing-private.pem')))
16
- const publicKeyPath = path.resolve(readArg('--public-key', path.join(packageDir, 'gse-signing-public.pem')))
17
- const out = path.resolve(readArg('--out', path.join(packageDir, 'gse-package-signature.json')))
18
- const generateKey = args.includes('--generate-key')
19
- const jsonOnly = args.includes('--json')
20
-
21
- function fail(message) {
22
- console.error(JSON.stringify({ packageDir, status: 'failed', error: message }, null, 2))
23
- process.exit(1)
24
- }
25
-
26
- function readManifest() {
27
- const manifestPath = path.join(packageDir, 'gse-package-manifest.json')
28
- if (!fs.existsSync(manifestPath)) fail('Missing gse-package-manifest.json.')
29
- return JSON.parse(fs.readFileSync(manifestPath, 'utf8').replace(/^\uFEFF/, ''))
30
- }
31
-
32
- function fingerprint(pem) {
33
- return crypto.createHash('sha256').update(pem).digest('hex')
34
- }
35
-
36
- if (generateKey && (!fs.existsSync(privateKeyPath) || !fs.existsSync(publicKeyPath))) {
37
- const { privateKey, publicKey } = crypto.generateKeyPairSync('ed25519')
38
- fs.mkdirSync(path.dirname(privateKeyPath), { recursive: true })
39
- fs.writeFileSync(privateKeyPath, privateKey.export({ type: 'pkcs8', format: 'pem' }), 'utf8')
40
- fs.writeFileSync(publicKeyPath, publicKey.export({ type: 'spki', format: 'pem' }), 'utf8')
41
- }
42
-
43
- if (!fs.existsSync(privateKeyPath)) fail('Missing --private-key. Use --generate-key for local audit keys.')
44
- if (!fs.existsSync(publicKeyPath)) fail('Missing --public-key. Use --generate-key for local audit keys.')
45
-
46
- const manifest = readManifest()
47
- if (!manifest?.integrity?.packageDigest) fail('Manifest is missing integrity.packageDigest.')
48
-
49
- const privateKeyPem = fs.readFileSync(privateKeyPath, 'utf8')
50
- const publicKeyPem = fs.readFileSync(publicKeyPath, 'utf8')
51
- const payload = {
52
- schemaVersion: 1,
53
- packageName: manifest.packageName,
54
- label: manifest.label,
55
- fileCount: manifest.fileCount,
56
- packageDigest: manifest.integrity.packageDigest,
57
- }
58
- const payloadText = JSON.stringify(payload)
59
- const signature = crypto.sign(null, Buffer.from(payloadText), privateKeyPem).toString('base64')
60
- const signatureRecord = {
61
- schemaVersion: 1,
62
- algorithm: 'ed25519',
63
- signedAt: new Date().toISOString(),
64
- publicKeyFingerprint: fingerprint(publicKeyPem),
65
- payload,
66
- signature,
67
- }
68
-
69
- fs.writeFileSync(out, JSON.stringify(signatureRecord, null, 2) + '\n', 'utf8')
70
-
71
- const report = {
72
- packageDir,
73
- privateKey: privateKeyPath,
74
- publicKey: publicKeyPath,
75
- signature: out,
76
- status: 'signed',
77
- algorithm: 'ed25519',
78
- publicKeyFingerprint: signatureRecord.publicKeyFingerprint,
79
- }
80
-
81
- if (jsonOnly) console.log(JSON.stringify(report, null, 2))
82
- else console.log(JSON.stringify(report, null, 2))
83
-
1
+ #!/usr/bin/env node
2
+ import fs from 'node:fs'
3
+ import path from 'node:path'
4
+ import crypto from 'node:crypto'
5
+
6
+ const args = process.argv.slice(2)
7
+
8
+ function readArg(name, fallback = null) {
9
+ const index = args.indexOf(name)
10
+ if (index === -1) return fallback
11
+ return args[index + 1] ?? fallback
12
+ }
13
+
14
+ const packageDir = path.resolve(readArg('--package', process.cwd()))
15
+ const privateKeyPath = path.resolve(readArg('--private-key', path.join(packageDir, 'gse-signing-private.pem')))
16
+ const publicKeyPath = path.resolve(readArg('--public-key', path.join(packageDir, 'gse-signing-public.pem')))
17
+ const out = path.resolve(readArg('--out', path.join(packageDir, 'gse-package-signature.json')))
18
+ const generateKey = args.includes('--generate-key')
19
+ const jsonOnly = args.includes('--json')
20
+
21
+ function fail(message) {
22
+ console.error(JSON.stringify({ packageDir, status: 'failed', error: message }, null, 2))
23
+ process.exit(1)
24
+ }
25
+
26
+ function readManifest() {
27
+ const manifestPath = path.join(packageDir, 'gse-package-manifest.json')
28
+ if (!fs.existsSync(manifestPath)) fail('Missing gse-package-manifest.json.')
29
+ return JSON.parse(fs.readFileSync(manifestPath, 'utf8').replace(/^\uFEFF/, ''))
30
+ }
31
+
32
+ function fingerprint(pem) {
33
+ return crypto.createHash('sha256').update(pem).digest('hex')
34
+ }
35
+
36
+ if (generateKey && (!fs.existsSync(privateKeyPath) || !fs.existsSync(publicKeyPath))) {
37
+ const { privateKey, publicKey } = crypto.generateKeyPairSync('ed25519')
38
+ fs.mkdirSync(path.dirname(privateKeyPath), { recursive: true })
39
+ fs.writeFileSync(privateKeyPath, privateKey.export({ type: 'pkcs8', format: 'pem' }), 'utf8')
40
+ fs.writeFileSync(publicKeyPath, publicKey.export({ type: 'spki', format: 'pem' }), 'utf8')
41
+ }
42
+
43
+ if (!fs.existsSync(privateKeyPath)) fail('Missing --private-key. Use --generate-key for local audit keys.')
44
+ if (!fs.existsSync(publicKeyPath)) fail('Missing --public-key. Use --generate-key for local audit keys.')
45
+
46
+ const manifest = readManifest()
47
+ if (!manifest?.integrity?.packageDigest) fail('Manifest is missing integrity.packageDigest.')
48
+
49
+ const privateKeyPem = fs.readFileSync(privateKeyPath, 'utf8')
50
+ const publicKeyPem = fs.readFileSync(publicKeyPath, 'utf8')
51
+ const payload = {
52
+ schemaVersion: 1,
53
+ packageName: manifest.packageName,
54
+ label: manifest.label,
55
+ fileCount: manifest.fileCount,
56
+ packageDigest: manifest.integrity.packageDigest,
57
+ }
58
+ const payloadText = JSON.stringify(payload)
59
+ const signature = crypto.sign(null, Buffer.from(payloadText), privateKeyPem).toString('base64')
60
+ const signatureRecord = {
61
+ schemaVersion: 1,
62
+ algorithm: 'ed25519',
63
+ signedAt: new Date().toISOString(),
64
+ publicKeyFingerprint: fingerprint(publicKeyPem),
65
+ payload,
66
+ signature,
67
+ }
68
+
69
+ fs.writeFileSync(out, JSON.stringify(signatureRecord, null, 2) + '\n', 'utf8')
70
+
71
+ const report = {
72
+ packageDir,
73
+ privateKey: privateKeyPath,
74
+ publicKey: publicKeyPath,
75
+ signature: out,
76
+ status: 'signed',
77
+ algorithm: 'ed25519',
78
+ publicKeyFingerprint: signatureRecord.publicKeyFingerprint,
79
+ }
80
+
81
+ if (jsonOnly) console.log(JSON.stringify(report, null, 2))
82
+ else console.log(JSON.stringify(report, null, 2))
83
+
@@ -1,223 +1,223 @@
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 dryRun = args.includes('--dry-run')
17
- const force = args.includes('--force')
18
- const selfTest = args.includes('--self-test') || !args.includes('--target')
19
- const targetArg = readArg('--target')
20
- const date = new Date().toISOString().slice(0, 10)
21
-
22
- function readText(filePath) {
23
- return fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf8').replace(/^\uFEFF/, '') : ''
24
- }
25
-
26
- function exists(target, relativePath) {
27
- return fs.existsSync(path.join(target, relativePath))
28
- }
29
-
30
- function readJson(filePath) {
31
- if (!fs.existsSync(filePath)) return { exists: false, ok: false, data: null, error: 'missing' }
32
- try {
33
- return { exists: true, ok: true, data: JSON.parse(readText(filePath)), error: '' }
34
- } catch (error) {
35
- return { exists: true, ok: false, data: null, error: error.message }
36
- }
37
- }
38
-
39
- function runGit(target, commandArgs) {
40
- const result = spawnSync('git', commandArgs, {
41
- cwd: target,
42
- encoding: 'utf8',
43
- windowsHide: true,
44
- })
45
- return {
46
- status: result.status ?? 1,
47
- stdout: (result.stdout ?? '').trim(),
48
- stderr: (result.stderr ?? '').trim(),
49
- }
50
- }
51
-
52
- function cleanInlineValue(value) {
53
- return String(value || '').trim().replace(/[.。::]+$/, '').trim()
54
- }
55
-
56
- function firstMatch(text, regex) {
57
- const match = text.match(regex)
58
- return match ? cleanInlineValue(match[1]) : ''
59
- }
60
-
61
- function findCanonicalPlan(target) {
62
- const texts = [
63
- readText(path.join(target, '.gse', 'README.md')),
64
- readText(path.join(target, '.gse', 'project-profile.md')),
65
- readText(path.join(target, '.gse', 'goal-map.md')),
66
- ].join('\n')
67
- const match = texts.match(/docs\/[A-Za-z0-9._/-]*?(?:architecture|productization)[A-Za-z0-9._/-]*?\.md/)
68
- if (match && exists(target, match[0])) return match[0]
69
- for (const fallback of [
70
- 'docs/aion-productization-architecture.md',
71
- 'docs/museflow-ai-film-productization-architecture.md',
72
- ]) {
73
- if (exists(target, fallback)) return fallback
74
- }
75
- return ''
76
- }
77
-
78
- function detectMode(target) {
79
- if (exists(target, '.gse/hooks/README.md') || exists(target, '.gse/mcp/README.md') || exists(target, '.gse/plugins/README.md')) return 'enterprise'
80
- if (exists(target, '.gse/agents/roles.md') || exists(target, '.gse/agent-workspace.md')) return 'standard'
81
- return 'lite'
82
- }
83
-
84
- function detectSparseWarning(target) {
85
- const sparse = runGit(target, ['sparse-checkout', 'list'])
86
- const sparseLines = sparse.status === 0 && sparse.stdout ? sparse.stdout.split(/\r?\n/).map((line) => line.trim().replace(/\\/g, '/')).filter(Boolean) : []
87
- const sparseEnabled = sparse.status === 0 && sparseLines.length > 0
88
- const sparseIncludesGse = sparseLines.some((line) => line === '.gse' || line === '.gse/' || line.startsWith('.gse/') || line === '/*' || line === '*')
89
- if (sparseEnabled && !sparseIncludesGse) {
90
- return `sparse-checkout excludes .gse; use git add --sparse for project-local GSE updates or add .gse to sparse rules.`
91
- }
92
- return ''
93
- }
94
-
95
- function writeFile(target, relativePath, content, results) {
96
- const fullPath = path.join(target, relativePath)
97
- const alreadyExists = fs.existsSync(fullPath)
98
- if (alreadyExists && !force) {
99
- results.push({ relativePath, status: 'skipped', reason: 'exists' })
100
- return
101
- }
102
- if (!dryRun) {
103
- fs.mkdirSync(path.dirname(fullPath), { recursive: true })
104
- fs.writeFileSync(fullPath, content.replace(/\n/g, '\r\n'), 'utf8')
105
- }
106
- results.push({ relativePath, status: dryRun ? (alreadyExists ? 'would-skip' : 'would-write') : alreadyExists ? 'overwritten' : 'written' })
107
- }
108
-
109
- function buildState(target) {
110
- const profile = readText(path.join(target, '.gse', 'project-profile.md'))
111
- const goalMap = readText(path.join(target, '.gse', 'goal-map.md'))
112
- const projectName = firstMatch(profile, /Product\/system name:\s*([^\n]+)/i) || firstMatch(profile, /Product\/system name\s*:\s*([^\n]+)/i) || path.basename(target)
113
- const canonicalPlan = findCanonicalPlan(target)
114
- const activeSlice = firstMatch(goalMap, /Active slice:\s*([^\n]+)/i) || 'Continue from the project goal map.'
115
- const nextAction = firstMatch(goalMap, /Next action:\s*([^\n]+)/i) || 'Pick the next verifiable slice.'
116
- return {
117
- schemaVersion: 1,
118
- projectName,
119
- mode: detectMode(target),
120
- canonicalPlan,
121
- phase: 'execute',
122
- currentSlice: {
123
- id: '',
124
- outcome: activeSlice,
125
- status: 'planned',
126
- nextAction,
127
- },
128
- toolStatuses: {
129
- browser: 'unknown',
130
- lsp: 'unknown',
131
- mcp: 'unknown',
132
- subagents: 'unknown',
133
- ci: 'unknown',
134
- },
135
- lastEvidence: '.gse/evidence/index.jsonl',
136
- residualRisks: [
137
- 'State/index was generated by GSE update; project-specific tool statuses remain unknown until verified.',
138
- ],
139
- }
140
- }
141
-
142
- function updateProject(target) {
143
- const resolvedTarget = path.resolve(target)
144
- const results = []
145
- const warnings = []
146
- if (!exists(resolvedTarget, '.gse')) {
147
- return {
148
- target: resolvedTarget,
149
- generatedAt: new Date().toISOString(),
150
- dryRun,
151
- force,
152
- summary: { status: 'failed', written: 0, skipped: 0, warnings: 0, total: 0 },
153
- results,
154
- warnings: ['missing .gse directory'],
155
- recommendation: 'Run init-project.mjs first or adopt GSE before updating state/index.',
156
- }
157
- }
158
-
159
- const state = readJson(path.join(resolvedTarget, '.gse', 'state.json'))
160
- if (state.exists && !state.ok && !force) warnings.push('existing .gse/state.json is invalid; rerun with --force only after backing up or reviewing it')
161
- const sparseWarning = detectSparseWarning(resolvedTarget)
162
- if (sparseWarning) warnings.push(sparseWarning)
163
-
164
- const stateContent = JSON.stringify(buildState(resolvedTarget), null, 2) + '\n'
165
- const evidenceIndexRecord = JSON.stringify({
166
- date,
167
- recordType: 'adoption',
168
- status: 'result',
169
- summary: 'Added GSE machine-readable state and evidence index for an existing project.',
170
- evidenceFile: `.gse/evidence/${date}.md`,
171
- commands: ['node <gse-skill>/scripts/update-project-state.mjs --target <project-root>'],
172
- nextAction: 'Run target doctor, generate-session-prompt, and close gate to verify project-local readiness.',
173
- }) + '\n'
174
-
175
- writeFile(resolvedTarget, '.gse/state.json', stateContent, results)
176
- writeFile(resolvedTarget, '.gse/evidence/index.jsonl', evidenceIndexRecord, results)
177
-
178
- const written = results.filter((item) => ['written', 'overwritten', 'would-write'].includes(item.status)).length
179
- const skipped = results.filter((item) => ['skipped', 'would-skip'].includes(item.status)).length
180
- return {
181
- target: resolvedTarget,
182
- generatedAt: new Date().toISOString(),
183
- dryRun,
184
- force,
185
- summary: {
186
- status: warnings.length ? 'warning' : 'passed',
187
- written,
188
- skipped,
189
- warnings: warnings.length,
190
- total: results.length,
191
- },
192
- results,
193
- warnings,
194
- recommendation: warnings.length ? 'Review warnings before staging project-local .gse changes.' : 'Run target doctor and close gate before claiming the project update is verified.',
195
- }
196
- }
197
-
198
- function createFixture() {
199
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'gse-state-update-'))
200
- fs.mkdirSync(path.join(dir, '.gse', 'evidence'), { recursive: true })
201
- fs.writeFileSync(path.join(dir, '.gse', 'README.md'), '# GSE\n\nCanonical plan: `docs/productization-architecture.md`.\n', 'utf8')
202
- fs.writeFileSync(path.join(dir, '.gse', 'project-profile.md'), '# Project Profile\n\n- Product/system name: Fixture Product.\n', 'utf8')
203
- fs.writeFileSync(path.join(dir, '.gse', 'goal-map.md'), '# Goal Map\n\n## Current Focus\n\n- Active slice: Fixture migration.\n- Next action: Verify fixture migration.\n', 'utf8')
204
- fs.writeFileSync(path.join(dir, '.gse', 'quality-gates.md'), '# Quality Gates\n\n## Universal\n', 'utf8')
205
- fs.mkdirSync(path.join(dir, 'docs'), { recursive: true })
206
- fs.writeFileSync(path.join(dir, 'docs', 'productization-architecture.md'), '# Plan\n', 'utf8')
207
- return dir
208
- }
209
-
210
- const target = selfTest ? createFixture() : targetArg
211
- const report = updateProject(target)
212
-
213
- if (jsonOnly) console.log(JSON.stringify(report, null, 2))
214
- else {
215
- console.log('# GSE Project State Update')
216
- console.log('')
217
- console.log('Target: ' + report.target)
218
- console.log('Status: ' + report.summary.status)
219
- for (const item of report.results) console.log('- ' + item.relativePath + ': ' + item.status + (item.reason ? ' (' + item.reason + ')' : ''))
220
- for (const warning of report.warnings) console.log('- warning: ' + warning)
221
- }
222
-
223
- if (report.summary.status === 'failed') 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 dryRun = args.includes('--dry-run')
17
+ const force = args.includes('--force')
18
+ const selfTest = args.includes('--self-test') || !args.includes('--target')
19
+ const targetArg = readArg('--target')
20
+ const date = new Date().toISOString().slice(0, 10)
21
+
22
+ function readText(filePath) {
23
+ return fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf8').replace(/^\uFEFF/, '') : ''
24
+ }
25
+
26
+ function exists(target, relativePath) {
27
+ return fs.existsSync(path.join(target, relativePath))
28
+ }
29
+
30
+ function readJson(filePath) {
31
+ if (!fs.existsSync(filePath)) return { exists: false, ok: false, data: null, error: 'missing' }
32
+ try {
33
+ return { exists: true, ok: true, data: JSON.parse(readText(filePath)), error: '' }
34
+ } catch (error) {
35
+ return { exists: true, ok: false, data: null, error: error.message }
36
+ }
37
+ }
38
+
39
+ function runGit(target, commandArgs) {
40
+ const result = spawnSync('git', commandArgs, {
41
+ cwd: target,
42
+ encoding: 'utf8',
43
+ windowsHide: true,
44
+ })
45
+ return {
46
+ status: result.status ?? 1,
47
+ stdout: (result.stdout ?? '').trim(),
48
+ stderr: (result.stderr ?? '').trim(),
49
+ }
50
+ }
51
+
52
+ function cleanInlineValue(value) {
53
+ return String(value || '').trim().replace(/[.。::]+$/, '').trim()
54
+ }
55
+
56
+ function firstMatch(text, regex) {
57
+ const match = text.match(regex)
58
+ return match ? cleanInlineValue(match[1]) : ''
59
+ }
60
+
61
+ function findCanonicalPlan(target) {
62
+ const texts = [
63
+ readText(path.join(target, '.gse', 'README.md')),
64
+ readText(path.join(target, '.gse', 'project-profile.md')),
65
+ readText(path.join(target, '.gse', 'goal-map.md')),
66
+ ].join('\n')
67
+ const match = texts.match(/docs\/[A-Za-z0-9._/-]*?(?:architecture|productization)[A-Za-z0-9._/-]*?\.md/)
68
+ if (match && exists(target, match[0])) return match[0]
69
+ for (const fallback of [
70
+ 'docs/aion-productization-architecture.md',
71
+ 'docs/museflow-ai-film-productization-architecture.md',
72
+ ]) {
73
+ if (exists(target, fallback)) return fallback
74
+ }
75
+ return ''
76
+ }
77
+
78
+ function detectMode(target) {
79
+ if (exists(target, '.gse/hooks/README.md') || exists(target, '.gse/mcp/README.md') || exists(target, '.gse/plugins/README.md')) return 'enterprise'
80
+ if (exists(target, '.gse/agents/roles.md') || exists(target, '.gse/agent-workspace.md')) return 'standard'
81
+ return 'lite'
82
+ }
83
+
84
+ function detectSparseWarning(target) {
85
+ const sparse = runGit(target, ['sparse-checkout', 'list'])
86
+ const sparseLines = sparse.status === 0 && sparse.stdout ? sparse.stdout.split(/\r?\n/).map((line) => line.trim().replace(/\\/g, '/')).filter(Boolean) : []
87
+ const sparseEnabled = sparse.status === 0 && sparseLines.length > 0
88
+ const sparseIncludesGse = sparseLines.some((line) => line === '.gse' || line === '.gse/' || line.startsWith('.gse/') || line === '/*' || line === '*')
89
+ if (sparseEnabled && !sparseIncludesGse) {
90
+ return `sparse-checkout excludes .gse; use git add --sparse for project-local GSE updates or add .gse to sparse rules.`
91
+ }
92
+ return ''
93
+ }
94
+
95
+ function writeFile(target, relativePath, content, results) {
96
+ const fullPath = path.join(target, relativePath)
97
+ const alreadyExists = fs.existsSync(fullPath)
98
+ if (alreadyExists && !force) {
99
+ results.push({ relativePath, status: 'skipped', reason: 'exists' })
100
+ return
101
+ }
102
+ if (!dryRun) {
103
+ fs.mkdirSync(path.dirname(fullPath), { recursive: true })
104
+ fs.writeFileSync(fullPath, content.replace(/\n/g, '\r\n'), 'utf8')
105
+ }
106
+ results.push({ relativePath, status: dryRun ? (alreadyExists ? 'would-skip' : 'would-write') : alreadyExists ? 'overwritten' : 'written' })
107
+ }
108
+
109
+ function buildState(target) {
110
+ const profile = readText(path.join(target, '.gse', 'project-profile.md'))
111
+ const goalMap = readText(path.join(target, '.gse', 'goal-map.md'))
112
+ const projectName = firstMatch(profile, /Product\/system name:\s*([^\n]+)/i) || firstMatch(profile, /Product\/system name\s*:\s*([^\n]+)/i) || path.basename(target)
113
+ const canonicalPlan = findCanonicalPlan(target)
114
+ const activeSlice = firstMatch(goalMap, /Active slice:\s*([^\n]+)/i) || 'Continue from the project goal map.'
115
+ const nextAction = firstMatch(goalMap, /Next action:\s*([^\n]+)/i) || 'Pick the next verifiable slice.'
116
+ return {
117
+ schemaVersion: 1,
118
+ projectName,
119
+ mode: detectMode(target),
120
+ canonicalPlan,
121
+ phase: 'execute',
122
+ currentSlice: {
123
+ id: '',
124
+ outcome: activeSlice,
125
+ status: 'planned',
126
+ nextAction,
127
+ },
128
+ toolStatuses: {
129
+ browser: 'unknown',
130
+ lsp: 'unknown',
131
+ mcp: 'unknown',
132
+ subagents: 'unknown',
133
+ ci: 'unknown',
134
+ },
135
+ lastEvidence: '.gse/evidence/index.jsonl',
136
+ residualRisks: [
137
+ 'State/index was generated by GSE update; project-specific tool statuses remain unknown until verified.',
138
+ ],
139
+ }
140
+ }
141
+
142
+ function updateProject(target) {
143
+ const resolvedTarget = path.resolve(target)
144
+ const results = []
145
+ const warnings = []
146
+ if (!exists(resolvedTarget, '.gse')) {
147
+ return {
148
+ target: resolvedTarget,
149
+ generatedAt: new Date().toISOString(),
150
+ dryRun,
151
+ force,
152
+ summary: { status: 'failed', written: 0, skipped: 0, warnings: 0, total: 0 },
153
+ results,
154
+ warnings: ['missing .gse directory'],
155
+ recommendation: 'Run init-project.mjs first or adopt GSE before updating state/index.',
156
+ }
157
+ }
158
+
159
+ const state = readJson(path.join(resolvedTarget, '.gse', 'state.json'))
160
+ if (state.exists && !state.ok && !force) warnings.push('existing .gse/state.json is invalid; rerun with --force only after backing up or reviewing it')
161
+ const sparseWarning = detectSparseWarning(resolvedTarget)
162
+ if (sparseWarning) warnings.push(sparseWarning)
163
+
164
+ const stateContent = JSON.stringify(buildState(resolvedTarget), null, 2) + '\n'
165
+ const evidenceIndexRecord = JSON.stringify({
166
+ date,
167
+ recordType: 'adoption',
168
+ status: 'result',
169
+ summary: 'Added GSE machine-readable state and evidence index for an existing project.',
170
+ evidenceFile: `.gse/evidence/${date}.md`,
171
+ commands: ['node <gse-skill>/scripts/update-project-state.mjs --target <project-root>'],
172
+ nextAction: 'Run target doctor, generate-session-prompt, and close gate to verify project-local readiness.',
173
+ }) + '\n'
174
+
175
+ writeFile(resolvedTarget, '.gse/state.json', stateContent, results)
176
+ writeFile(resolvedTarget, '.gse/evidence/index.jsonl', evidenceIndexRecord, results)
177
+
178
+ const written = results.filter((item) => ['written', 'overwritten', 'would-write'].includes(item.status)).length
179
+ const skipped = results.filter((item) => ['skipped', 'would-skip'].includes(item.status)).length
180
+ return {
181
+ target: resolvedTarget,
182
+ generatedAt: new Date().toISOString(),
183
+ dryRun,
184
+ force,
185
+ summary: {
186
+ status: warnings.length ? 'warning' : 'passed',
187
+ written,
188
+ skipped,
189
+ warnings: warnings.length,
190
+ total: results.length,
191
+ },
192
+ results,
193
+ warnings,
194
+ recommendation: warnings.length ? 'Review warnings before staging project-local .gse changes.' : 'Run target doctor and close gate before claiming the project update is verified.',
195
+ }
196
+ }
197
+
198
+ function createFixture() {
199
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'gse-state-update-'))
200
+ fs.mkdirSync(path.join(dir, '.gse', 'evidence'), { recursive: true })
201
+ fs.writeFileSync(path.join(dir, '.gse', 'README.md'), '# GSE\n\nCanonical plan: `docs/productization-architecture.md`.\n', 'utf8')
202
+ fs.writeFileSync(path.join(dir, '.gse', 'project-profile.md'), '# Project Profile\n\n- Product/system name: Fixture Product.\n', 'utf8')
203
+ fs.writeFileSync(path.join(dir, '.gse', 'goal-map.md'), '# Goal Map\n\n## Current Focus\n\n- Active slice: Fixture migration.\n- Next action: Verify fixture migration.\n', 'utf8')
204
+ fs.writeFileSync(path.join(dir, '.gse', 'quality-gates.md'), '# Quality Gates\n\n## Universal\n', 'utf8')
205
+ fs.mkdirSync(path.join(dir, 'docs'), { recursive: true })
206
+ fs.writeFileSync(path.join(dir, 'docs', 'productization-architecture.md'), '# Plan\n', 'utf8')
207
+ return dir
208
+ }
209
+
210
+ const target = selfTest ? createFixture() : targetArg
211
+ const report = updateProject(target)
212
+
213
+ if (jsonOnly) console.log(JSON.stringify(report, null, 2))
214
+ else {
215
+ console.log('# GSE Project State Update')
216
+ console.log('')
217
+ console.log('Target: ' + report.target)
218
+ console.log('Status: ' + report.summary.status)
219
+ for (const item of report.results) console.log('- ' + item.relativePath + ': ' + item.status + (item.reason ? ' (' + item.reason + ')' : ''))
220
+ for (const warning of report.warnings) console.log('- warning: ' + warning)
221
+ }
222
+
223
+ if (report.summary.status === 'failed') process.exit(1)