@t275005746/gse 0.1.1 → 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 (84) hide show
  1. package/.gse/state.json +147 -26
  2. package/CHANGELOG.md +19 -3
  3. package/README.md +13 -6
  4. package/README.zh-CN.md +13 -6
  5. package/SKILL.md +32 -12
  6. package/assets/templates/dispatch-packet.md +22 -14
  7. package/assets/templates/evidence.md +11 -5
  8. package/assets/templates/role-fallback-packet.md +49 -0
  9. package/package.json +18 -10
  10. package/references/agent-roles.md +41 -20
  11. package/references/commands.md +74 -45
  12. package/references/drift-audit.md +2 -1
  13. package/references/evidence-taxonomy.md +46 -9
  14. package/references/file-ownership.md +17 -13
  15. package/references/final-form-roadmap.md +201 -0
  16. package/references/final-readiness.md +3 -3
  17. package/references/host-adapters.md +38 -10
  18. package/references/learning-system.md +24 -8
  19. package/references/maintenance-cadence.md +51 -0
  20. package/references/project-guards.md +52 -0
  21. package/references/quality-gates.md +18 -11
  22. package/references/role-dispatch-fallback.md +54 -0
  23. package/references/tool-adapters.md +13 -3
  24. package/scripts/audit-close-gate-hardening.mjs +188 -0
  25. package/scripts/audit-close-gate.mjs +219 -33
  26. package/scripts/audit-command-execution.mjs +30 -17
  27. package/scripts/audit-commands.mjs +7 -5
  28. package/scripts/audit-completion-plan-drill.mjs +230 -0
  29. package/scripts/audit-completion-readiness.mjs +9 -6
  30. package/scripts/audit-continue-preflight.mjs +234 -0
  31. package/scripts/audit-evidence-levels.mjs +217 -0
  32. package/scripts/audit-evidence-review-queue.mjs +206 -0
  33. package/scripts/audit-final-acceptance-packet.mjs +9 -9
  34. package/scripts/audit-final-form-progress-report.mjs +19 -18
  35. package/scripts/audit-final-form-roadmap.mjs +157 -0
  36. package/scripts/audit-final-form-stale-copy.mjs +2 -2
  37. package/scripts/audit-final-readiness.mjs +3 -3
  38. package/scripts/audit-fresh-session-readiness.mjs +1 -1
  39. package/scripts/audit-host-capabilities.mjs +237 -0
  40. package/scripts/audit-installed-sync.mjs +203 -0
  41. package/scripts/audit-learning-drift.mjs +292 -0
  42. package/scripts/audit-learning-promotion.mjs +351 -0
  43. package/scripts/audit-learning-system.mjs +24 -14
  44. package/scripts/audit-local-final-form-completion.mjs +11 -10
  45. package/scripts/audit-maintenance-cadence.mjs +139 -0
  46. package/scripts/audit-maintenance-snapshot.mjs +181 -0
  47. package/scripts/audit-npm-package-metadata.mjs +8 -2
  48. package/scripts/audit-npm-publish-dry-run.mjs +10 -4
  49. package/scripts/audit-npm-tarball-install.mjs +9 -3
  50. package/scripts/audit-owner-external-gate-kit.mjs +12 -11
  51. package/scripts/audit-project-guards.mjs +189 -0
  52. package/scripts/audit-project.mjs +14 -11
  53. package/scripts/audit-public-acceptance-handoff.mjs +10 -10
  54. package/scripts/audit-public-acceptance-readiness.mjs +6 -6
  55. package/scripts/audit-public-release-checklist.mjs +17 -15
  56. package/scripts/audit-release-bundle.mjs +13 -11
  57. package/scripts/audit-release-owner-action-plan-drill.mjs +5 -4
  58. package/scripts/audit-release-owner-action-plan.mjs +10 -10
  59. package/scripts/audit-release-status-manifest.mjs +4 -4
  60. package/scripts/audit-roadmap-consistency.mjs +11 -7
  61. package/scripts/audit-role-dispatch-fallback.mjs +212 -0
  62. package/scripts/audit-session-sync.mjs +127 -0
  63. package/scripts/audit-state-freshness.mjs +6 -5
  64. package/scripts/audit-state-repair.mjs +360 -0
  65. package/scripts/audit-target-hardening-drills.mjs +267 -0
  66. package/scripts/audit-tool-fallback-policy.mjs +180 -0
  67. package/scripts/audit-ui-browser-evidence-policy.mjs +191 -0
  68. package/scripts/audit-validation-profiles.mjs +6 -4
  69. package/scripts/backfill-evidence-levels.mjs +98 -0
  70. package/scripts/check-encoding.mjs +72 -0
  71. package/scripts/generate-continue-packet.mjs +1214 -0
  72. package/scripts/generate-final-acceptance-packet.mjs +23 -8
  73. package/scripts/generate-final-form-progress-report.mjs +25 -23
  74. package/scripts/generate-host-runtime-evidence-handoff.mjs +23 -16
  75. package/scripts/generate-maintenance-snapshot.mjs +216 -0
  76. package/scripts/generate-public-acceptance-handoff.mjs +26 -14
  77. package/scripts/generate-release-owner-action-plan.mjs +4 -3
  78. package/scripts/generate-release-status-manifest.mjs +4 -3
  79. package/scripts/init-project.mjs +144 -63
  80. package/scripts/record-learning.mjs +37 -8
  81. package/scripts/record-session-sync.mjs +87 -0
  82. package/scripts/run-gse-command.mjs +79 -47
  83. package/scripts/run-validation-profile.mjs +24 -5
  84. package/scripts/validate-gse.mjs +216 -0
@@ -0,0 +1,267 @@
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
+ function readAllArgs(name) {
16
+ const values = []
17
+ for (let index = 0; index < args.length; index += 1) {
18
+ if (args[index] === name && args[index + 1]) values.push(args[index + 1])
19
+ }
20
+ return values
21
+ }
22
+
23
+ const root = path.resolve(readArg('--root', path.join(import.meta.dirname, '..')))
24
+ const jsonOnly = args.includes('--json')
25
+ const strictWarnings = args.includes('--strict-warnings')
26
+
27
+ function run(script, commandArgs, options = {}) {
28
+ const result = spawnSync(process.execPath, [path.join(root, 'scripts', script), ...commandArgs], {
29
+ cwd: root,
30
+ encoding: 'utf8',
31
+ windowsHide: true,
32
+ ...options,
33
+ })
34
+ const stdout = (result.stdout ?? '').trim()
35
+ let parsed = null
36
+ try {
37
+ parsed = JSON.parse(stdout)
38
+ } catch {
39
+ parsed = null
40
+ }
41
+ return {
42
+ script,
43
+ command: [process.execPath, path.join(root, 'scripts', script), ...commandArgs].join(' '),
44
+ status: result.status ?? 1,
45
+ stdout,
46
+ stderr: (result.stderr ?? '').trim(),
47
+ parsed,
48
+ }
49
+ }
50
+
51
+ function check(id, label, status, evidence, recommendation = '') {
52
+ return { id, label, status, evidence, recommendation }
53
+ }
54
+
55
+ function parseTargets() {
56
+ const explicitTargets = readAllArgs('--target')
57
+ const namedTargets = [
58
+ { id: 'aion', root: readArg('--aion-target', process.env.GSE_AION_TARGET || null) },
59
+ { id: 'museflow', root: readArg('--museflow-target', process.env.GSE_MUSEFLOW_TARGET || null) },
60
+ ].filter((item) => item.root)
61
+ const explicit = explicitTargets.map((target, index) => ({
62
+ id: `target-${index + 1}`,
63
+ root: target,
64
+ }))
65
+ return [...namedTargets, ...explicit].map((item) => ({
66
+ ...item,
67
+ root: path.resolve(item.root),
68
+ }))
69
+ }
70
+
71
+ function statusFromRun(runResult) {
72
+ if (!runResult.parsed) return runResult.status === 0 ? 'passed' : 'failed'
73
+ const summaryStatus = runResult.parsed.summary?.status
74
+ if (summaryStatus === 'failed' || summaryStatus === 'not-ready') return 'failed'
75
+ if (summaryStatus === 'warning' || summaryStatus === 'ready-with-warnings') return 'warning'
76
+ if ((runResult.parsed.summary?.failed ?? 0) > 0) return 'failed'
77
+ if ((runResult.parsed.summary?.warnings ?? 0) > 0) return 'warning'
78
+ return runResult.status === 0 ? 'passed' : 'failed'
79
+ }
80
+
81
+ function evidenceFromRun(runResult) {
82
+ const summary = runResult.parsed?.summary
83
+ if (!summary) return runResult.stderr || runResult.stdout.slice(0, 160) || `exit:${runResult.status}`
84
+ const parts = []
85
+ if (summary.status) parts.push(`status:${summary.status}`)
86
+ if (Number.isFinite(summary.passed) && Number.isFinite(summary.total)) parts.push(`checks:${summary.passed}/${summary.total}`)
87
+ if (Number.isFinite(summary.warnings)) parts.push(`warnings:${summary.warnings}`)
88
+ if (Number.isFinite(summary.failed)) parts.push(`failed:${summary.failed}`)
89
+ if (Number.isFinite(summary.blockedGates)) parts.push(`blockedGates:${summary.blockedGates}`)
90
+ if (Number.isFinite(summary.highUnenforced)) parts.push(`highUnenforced:${summary.highUnenforced}`)
91
+ return parts.join(', ') || `exit:${runResult.status}`
92
+ }
93
+
94
+ function createFixture(label) {
95
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), `gse-hardening-${label}-`))
96
+ const init = run('init-project.mjs', ['--target', dir, '--mode', 'enterprise', '--json'])
97
+ fs.mkdirSync(path.join(dir, 'docs'), { recursive: true })
98
+ fs.writeFileSync(path.join(dir, 'docs', 'productization-architecture.md'), `# ${label} Productization\n`, 'utf8')
99
+
100
+ const statePath = path.join(dir, '.gse', 'state.json')
101
+ const state = JSON.parse(fs.readFileSync(statePath, 'utf8'))
102
+ state.canonicalPlan = 'docs/productization-architecture.md'
103
+ state.phase = 'verify'
104
+ state.currentSlice = {
105
+ id: `${label}-hardening-fixture`,
106
+ outcome: `${label} hardening fixture.`,
107
+ status: 'verified',
108
+ nextAction: 'Continue target hardening drill.',
109
+ }
110
+ state.lastEvidence = '.gse/evidence/2026-07-09.md'
111
+ state.residualRisks = []
112
+ fs.writeFileSync(statePath, JSON.stringify(state, null, 2) + '\n', 'utf8')
113
+ fs.appendFileSync(path.join(dir, '.gse', 'README.md'), '\nCanonical plan: `docs/productization-architecture.md`.\n', 'utf8')
114
+ fs.writeFileSync(path.join(dir, '.gse', 'evidence', '2026-07-09.md'), '# Evidence\n\nFixture hardening evidence.\n', 'utf8')
115
+ fs.writeFileSync(path.join(dir, '.gse', 'evidence', 'index.jsonl'), JSON.stringify({
116
+ date: '2026-07-09',
117
+ recordType: 'slice',
118
+ status: 'verified',
119
+ evidenceLevel: 'verified-unit',
120
+ requiredEvidenceLevel: 'verified-unit',
121
+ summary: `${label} hardening fixture evidence.`,
122
+ evidenceFile: '.gse/evidence/2026-07-09.md',
123
+ commands: ['node scripts/audit-target-hardening-drills.mjs --self-test'],
124
+ nextAction: 'Continue target hardening drill.',
125
+ }) + '\n', 'utf8')
126
+ spawnSync('git', ['init'], { cwd: dir, encoding: 'utf8', windowsHide: true })
127
+ spawnSync('git', ['config', 'user.email', 'gse-fixture@example.local'], { cwd: dir, encoding: 'utf8', windowsHide: true })
128
+ spawnSync('git', ['config', 'user.name', 'GSE Fixture'], { cwd: dir, encoding: 'utf8', windowsHide: true })
129
+ spawnSync('git', ['add', '.'], { cwd: dir, encoding: 'utf8', windowsHide: true })
130
+ spawnSync('git', ['commit', '-m', 'fixture'], { cwd: dir, encoding: 'utf8', windowsHide: true })
131
+ return { dir, init }
132
+ }
133
+
134
+ function auditTarget(target) {
135
+ const commandRuns = {
136
+ doctor: run('audit-target-project.mjs', ['--root', root, '--target', target.root, '--json']),
137
+ continue: run('run-gse-command.mjs', ['--root', root, '--target', target.root, '--command', '/gse continue', '--json', '--compact']),
138
+ close: run('audit-close-gate.mjs', ['--target', target.root, '--json']),
139
+ hostCapabilities: run('audit-host-capabilities.mjs', ['--root', root, '--target', target.root, '--json']),
140
+ learningDrift: run('audit-learning-drift.mjs', ['--root', root, '--target', target.root, '--json']),
141
+ }
142
+ const checks = [
143
+ check(`${target.id}-doctor`, 'target project doctor has no hard failures', statusFromRun(commandRuns.doctor), evidenceFromRun(commandRuns.doctor), 'Repair target .gse adoption drift before claiming GSE-ready status.'),
144
+ check(`${target.id}-continue`, '/gse continue hard preflight returns a usable packet', statusFromRun(commandRuns.continue), evidenceFromRun(commandRuns.continue), 'Repair hard preflight failures before implementation starts.'),
145
+ check(`${target.id}-close`, 'close gate exposes close readiness and ownership state', statusFromRun(commandRuns.close), evidenceFromRun(commandRuns.close), 'Resolve close-gate failures before claiming the slice complete.'),
146
+ check(`${target.id}-host`, 'host capability records are audited with claim boundaries', statusFromRun(commandRuns.hostCapabilities), evidenceFromRun(commandRuns.hostCapabilities), 'Record missing host capability facts or keep unknown/external-required boundaries explicit.'),
147
+ check(`${target.id}-learning`, 'learning drift is audited for promoted guard candidates', statusFromRun(commandRuns.learningDrift), evidenceFromRun(commandRuns.learningDrift), 'Promote high-severity learning drift into guards, gates, or scripts before close.'),
148
+ ]
149
+ const failed = checks.filter((item) => item.status === 'failed')
150
+ const warnings = checks.filter((item) => item.status === 'warning')
151
+ return {
152
+ id: target.id,
153
+ root: target.root,
154
+ status: failed.length > 0 ? 'failed' : warnings.length > 0 ? 'warning' : 'passed',
155
+ checks,
156
+ commands: Object.values(commandRuns).map((item) => item.command),
157
+ summaries: Object.fromEntries(Object.entries(commandRuns).map(([key, value]) => [key, value.parsed?.summary ?? { exit: value.status }])),
158
+ }
159
+ }
160
+
161
+ function runConfiguredTargets() {
162
+ const targets = parseTargets()
163
+ if (targets.length === 0) return null
164
+ return {
165
+ targets,
166
+ cleanup: () => {},
167
+ }
168
+ }
169
+
170
+ function runSelfTestTargets() {
171
+ const primary = createFixture('primary')
172
+ const secondary = createFixture('secondary')
173
+ return {
174
+ targets: [
175
+ { id: 'fixture-primary', root: primary.dir },
176
+ { id: 'fixture-secondary', root: secondary.dir },
177
+ ],
178
+ cleanup: () => {
179
+ fs.rmSync(primary.dir, { recursive: true, force: true })
180
+ fs.rmSync(secondary.dir, { recursive: true, force: true })
181
+ },
182
+ }
183
+ }
184
+
185
+ function buildReport() {
186
+ const configured = runConfiguredTargets()
187
+ const targetSet = configured ?? runSelfTestTargets()
188
+ try {
189
+ const reports = targetSet.targets.map(auditTarget)
190
+ const checks = reports.flatMap((report) => report.checks)
191
+ const hardFailures = checks.filter((item) => item.status === 'failed')
192
+ const warnings = checks.filter((item) => item.status === 'warning')
193
+ const passed = checks.filter((item) => item.status === 'passed').length
194
+ const failed = hardFailures.length
195
+ const warningCount = warnings.length
196
+ const status = failed > 0 || (strictWarnings && warningCount > 0) ? 'failed' : warningCount > 0 ? 'warning' : 'passed'
197
+ return {
198
+ root,
199
+ generatedAt: new Date().toISOString(),
200
+ summary: {
201
+ status,
202
+ mode: configured ? 'configured-targets' : 'self-test',
203
+ passed,
204
+ warnings: warningCount,
205
+ failed,
206
+ hardFailures: failed,
207
+ total: checks.length,
208
+ targets: reports.length,
209
+ },
210
+ workflows: {
211
+ targetHardeningDrills: status === 'failed' ? 'failed' : 'verified',
212
+ closeGateHardening: hardFailures.length === 0 ? 'verified' : 'failed',
213
+ hostCapabilityBoundaries: hardFailures.length === 0 ? 'verified' : 'failed',
214
+ learningDriftCoverage: hardFailures.length === 0 ? 'verified' : 'failed',
215
+ },
216
+ targets: reports,
217
+ checks,
218
+ limits: [
219
+ 'Target hardening drills are read-only for target projects.',
220
+ 'They run GSE doctor, /gse continue, close gate, host capability audit, and learning drift audit.',
221
+ 'Warnings mean the project can continue only if the current slice accepts that residual risk; hard failures must be fixed before close.',
222
+ 'This drill does not run product tests, browser smokes, CI, or native host slash-command invocation.',
223
+ ],
224
+ }
225
+ } finally {
226
+ targetSet.cleanup()
227
+ }
228
+ }
229
+
230
+ function renderMarkdown(report) {
231
+ const lines = []
232
+ lines.push('# GSE Target Hardening Drills')
233
+ lines.push('')
234
+ lines.push('Generated: ' + report.generatedAt)
235
+ lines.push('Root: ' + report.root)
236
+ lines.push('')
237
+ lines.push('## Summary')
238
+ lines.push('')
239
+ lines.push('- Status: ' + report.summary.status)
240
+ lines.push('- Mode: ' + report.summary.mode)
241
+ lines.push('- Targets: ' + report.summary.targets)
242
+ lines.push('- Checks: ' + report.summary.passed + ' passed, ' + report.summary.warnings + ' warnings, ' + report.summary.hardFailures + ' hard failures, ' + report.summary.total + ' total')
243
+ lines.push('')
244
+ lines.push('## Targets')
245
+ lines.push('')
246
+ for (const target of report.targets) {
247
+ lines.push('- ' + target.id + ': ' + target.status + ' at ' + target.root)
248
+ }
249
+ lines.push('')
250
+ lines.push('## Checks')
251
+ lines.push('')
252
+ for (const item of report.checks) {
253
+ const marker = item.status === 'passed' ? '[x]' : item.status === 'warning' ? '[!]' : '[ ]'
254
+ lines.push('- ' + marker + ' ' + item.id + ' ' + item.label + ': ' + item.evidence)
255
+ }
256
+ lines.push('')
257
+ lines.push('## Limits')
258
+ lines.push('')
259
+ for (const item of report.limits) lines.push('- ' + item)
260
+ return lines.join('\n') + '\n'
261
+ }
262
+
263
+ const report = buildReport()
264
+ if (jsonOnly) console.log(JSON.stringify(report, null, 2))
265
+ else console.log(renderMarkdown(report))
266
+
267
+ if (report.summary.status === 'failed') process.exit(1)
@@ -0,0 +1,180 @@
1
+ #!/usr/bin/env node
2
+ import fs from 'node:fs'
3
+ import path from 'node:path'
4
+ import { fileURLToPath } from 'node:url'
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 root = path.resolve(readArg('--root', path.join(import.meta.dirname, '..')))
15
+ const targetArg = readArg('--target')
16
+ const jsonOnly = args.includes('--json')
17
+
18
+ function readText(filePath) {
19
+ return fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf8').replace(/^\uFEFF/, '') : ''
20
+ }
21
+
22
+ function exists(target, relativePath) {
23
+ return fs.existsSync(path.join(target, relativePath))
24
+ }
25
+
26
+ function check(id, label, ok, evidence, severity = 'hard', recommendation = '') {
27
+ return {
28
+ id,
29
+ label,
30
+ status: ok ? 'passed' : severity === 'soft' ? 'warning' : 'failed',
31
+ severity,
32
+ evidence,
33
+ recommendation,
34
+ }
35
+ }
36
+
37
+ function includesAll(text, phrases) {
38
+ const normalized = text.toLowerCase()
39
+ return phrases.every((phrase) => normalized.includes(phrase.toLowerCase()))
40
+ }
41
+
42
+ export function auditToolFallbackPolicy(target) {
43
+ const resolvedTarget = path.resolve(target)
44
+ const toolAdapters = readText(path.join(root, 'references', 'tool-adapters.md'))
45
+ const router = readText(path.join(root, 'references', 'router.md'))
46
+ const modelRouting = readText(path.join(root, 'references', 'model-routing.md'))
47
+ const hostAdapters = readText(path.join(root, 'references', 'host-adapters.md'))
48
+ const compatibility = readText(path.join(root, 'references', 'compatibility.md'))
49
+ const designBasis = readText(path.join(root, 'references', 'design-basis.md'))
50
+ const projectProfile = readText(path.join(root, 'references', 'project-profile.md'))
51
+ const initProject = readText(path.join(root, 'scripts', 'init-project.mjs'))
52
+ const updateProjectState = readText(path.join(root, 'scripts', 'update-project-state.mjs'))
53
+ const generateCommandAdapter = readText(path.join(root, 'scripts', 'generate-command-adapter.mjs'))
54
+ const generateContinuePacket = readText(path.join(root, 'scripts', 'generate-continue-packet.mjs'))
55
+
56
+ const checks = [
57
+ check(
58
+ 'TFP01',
59
+ 'tool adapters keep optional tools non-blocking and portable',
60
+ includesAll(toolAdapters, [
61
+ 'few hard requirements',
62
+ 'tools enhance the workflow when available',
63
+ 'use markdown fallback when optional tools are unavailable',
64
+ ]),
65
+ 'references/tool-adapters.md',
66
+ 'hard',
67
+ 'Keep markdown fallback available when a tool is missing.',
68
+ ),
69
+ check(
70
+ 'TFP02',
71
+ 'router keeps optional tools on the markdown fallback path',
72
+ includesAll(router, [
73
+ 'use markdown fallback when optional tools are unavailable',
74
+ 'do not treat optional tools as hard prerequisites',
75
+ ]),
76
+ 'references/router.md',
77
+ 'hard',
78
+ 'Route around missing tools instead of blocking the slice.',
79
+ ),
80
+ check(
81
+ 'TFP03',
82
+ 'model routing preserves a portable fallback path',
83
+ includesAll(modelRouting, [
84
+ 'preserve a portable fallback path',
85
+ 'fallback policy',
86
+ ]),
87
+ 'references/model-routing.md',
88
+ 'hard',
89
+ 'Keep provider and tool fallback policy in project profile docs.',
90
+ ),
91
+ check(
92
+ 'TFP04',
93
+ 'host adapters keep .gse as the source of truth and unknown capability claims explicit',
94
+ includesAll(hostAdapters, [
95
+ '.gse/` is the portable source of truth',
96
+ 'host-specific folders are adapters',
97
+ 'document it as `unknown`',
98
+ ]),
99
+ 'references/host-adapters.md',
100
+ 'hard',
101
+ 'Keep host/tool capability claims evidence-gated in the portable layer.',
102
+ ),
103
+ check(
104
+ 'TFP05',
105
+ 'project profile records fallback policy and model/tool ids',
106
+ includesAll(projectProfile, [
107
+ 'model routing',
108
+ 'fallback policy',
109
+ 'model/tool ids',
110
+ ]),
111
+ 'references/project-profile.md',
112
+ 'hard',
113
+ 'Keep the project-approved fallback path visible in profile docs.',
114
+ ),
115
+ check(
116
+ 'TFP06',
117
+ 'generated command adapters keep unsupported host claims unknown until evidence exists',
118
+ includesAll(generateCommandAdapter, [
119
+ 'unknown until',
120
+ 'current host records evidence',
121
+ 'skill/text-command pointer',
122
+ ]),
123
+ 'scripts/generate-command-adapter.mjs',
124
+ 'hard',
125
+ 'Do not let generated adapters become runtime proof.',
126
+ ),
127
+ check(
128
+ 'TFP07',
129
+ 'project bootstrap and state update keep commands and host tools unknown until verified',
130
+ includesAll(initProject, ['project commands and host tools are unknown until verified in this repository']) &&
131
+ includesAll(updateProjectState, ['project-specific tool statuses remain unknown until verified']),
132
+ 'scripts/init-project.mjs and scripts/update-project-state.mjs',
133
+ 'hard',
134
+ 'Leave capability status unknown until the project records it.',
135
+ ),
136
+ check(
137
+ 'TFP08',
138
+ 'continue packet surfaces fallback policy as a compact preflight concern',
139
+ includesAll(generateContinuePacket, [
140
+ 'toolfallbackpolicy',
141
+ 'host capabilities',
142
+ 'optional tools',
143
+ ]),
144
+ 'scripts/generate-continue-packet.mjs',
145
+ 'soft',
146
+ 'Expose the fallback policy in /gse continue so future sessions can see the boundary.',
147
+ ),
148
+ ]
149
+
150
+ const passed = checks.filter((item) => item.status === 'passed').length
151
+ const failed = checks.length - passed
152
+
153
+ return {
154
+ target: resolvedTarget,
155
+ generatedAt: new Date().toISOString(),
156
+ summary: {
157
+ status: failed === 0 ? 'passed' : 'failed',
158
+ passed,
159
+ failed,
160
+ total: checks.length,
161
+ },
162
+ workflows: {
163
+ optionalToolFallbackPolicy: failed === 0 ? 'verified' : 'failed',
164
+ },
165
+ checks,
166
+ limits: [
167
+ 'This audit verifies portable fallback policy and claim boundaries.',
168
+ 'It does not prove actual browser, MCP, LSP, subagent, or CI availability.',
169
+ ],
170
+ }
171
+ }
172
+
173
+ const isCli = process.argv[1] && fileURLToPath(import.meta.url) === path.resolve(process.argv[1])
174
+
175
+ if (isCli) {
176
+ const report = auditToolFallbackPolicy(targetArg ?? root)
177
+ if (jsonOnly) console.log(JSON.stringify(report, null, 2))
178
+ else console.log(JSON.stringify(report, null, 2))
179
+ if (report.summary.status === 'failed') process.exit(1)
180
+ }
@@ -0,0 +1,191 @@
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 { analyzeEvidenceLevels } from './audit-evidence-levels.mjs'
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 root = path.resolve(readArg('--root', path.join(import.meta.dirname, '..')))
16
+ const targetArg = readArg('--target')
17
+ const target = path.resolve(targetArg || root)
18
+ const jsonOnly = args.includes('--json')
19
+
20
+ function read(relativePath, base = root) {
21
+ const fullPath = path.join(base, relativePath)
22
+ return fs.existsSync(fullPath) ? fs.readFileSync(fullPath, 'utf8').replace(/^\uFEFF/, '') : ''
23
+ }
24
+
25
+ function readJsonl(filePath) {
26
+ if (!fs.existsSync(filePath)) return { exists: false, ok: false, records: [], error: 'missing' }
27
+ const lines = fs.readFileSync(filePath, 'utf8')
28
+ .replace(/^\uFEFF/, '')
29
+ .split(/\r?\n/)
30
+ .map((line) => line.trim())
31
+ .filter(Boolean)
32
+ const records = []
33
+ for (const [index, line] of lines.entries()) {
34
+ try {
35
+ records.push(JSON.parse(line))
36
+ } catch (error) {
37
+ return { exists: true, ok: false, records, error: `line ${index + 1}: ${error.message}` }
38
+ }
39
+ }
40
+ return { exists: true, ok: true, records, error: '' }
41
+ }
42
+
43
+ function check(id, label, ok, evidence, risk = '') {
44
+ return { id, label, status: ok ? 'passed' : 'failed', evidence, risk }
45
+ }
46
+
47
+ function createFixture() {
48
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'gse-ui-evidence-policy-'))
49
+ fs.mkdirSync(path.join(dir, '.gse', 'evidence'), { recursive: true })
50
+ const records = [
51
+ {
52
+ date: '2026-07-09',
53
+ recordType: 'slice',
54
+ status: 'verified',
55
+ evidenceLevel: 'verified-component',
56
+ requiredEvidenceLevel: 'verified-browser',
57
+ summary: 'Component-only proof for visible UI behavior.',
58
+ evidenceFile: '.gse/evidence/2026-07-09.md',
59
+ commands: ['pnpm test component'],
60
+ nextAction: 'Run browser smoke before release.',
61
+ },
62
+ {
63
+ date: '2026-07-09',
64
+ recordType: 'slice',
65
+ status: 'verified',
66
+ evidenceLevel: 'verified-browser',
67
+ requiredEvidenceLevel: 'verified-browser',
68
+ summary: 'Browser-backed proof for visible UI behavior.',
69
+ evidenceFile: '.gse/evidence/2026-07-09.md',
70
+ commands: ['pnpm smoke browser', 'playwright screenshot'],
71
+ nextAction: 'Close slice.',
72
+ },
73
+ ]
74
+ fs.writeFileSync(path.join(dir, '.gse', 'evidence', 'index.jsonl'), records.map((record) => JSON.stringify(record)).join('\n') + '\n', 'utf8')
75
+ fs.writeFileSync(path.join(dir, '.gse', 'evidence', '2026-07-09.md'), '# Evidence\n', 'utf8')
76
+ return dir
77
+ }
78
+
79
+ const qualityGates = read('references/quality-gates.md')
80
+ const taxonomy = read('references/evidence-taxonomy.md')
81
+ const template = read('assets/templates/evidence.md')
82
+ const continuePacket = read('scripts/generate-continue-packet.mjs')
83
+ const closeGate = read('scripts/audit-close-gate.mjs')
84
+ const validationProfile = read('scripts/run-validation-profile.mjs')
85
+ const validator = read('scripts/validate-gse.mjs')
86
+ const roadmap = read('references/final-form-roadmap.md')
87
+ const fixture = createFixture()
88
+ const fixtureAnalysis = analyzeEvidenceLevels(readJsonl(path.join(fixture, '.gse', 'evidence', 'index.jsonl')).records)
89
+ const targetEvidence = readJsonl(path.join(target, '.gse', 'evidence', 'index.jsonl'))
90
+ const targetAnalysis = analyzeEvidenceLevels(targetEvidence.records)
91
+
92
+ const checks = [
93
+ check(
94
+ 'UIE01',
95
+ 'quality gates distinguish component proof from browser proof',
96
+ qualityGates.includes('verified-component') &&
97
+ qualityGates.includes('verified-browser') &&
98
+ qualityGates.includes('Do not describe `verified-component` or `verified-api` as `verified-browser`') &&
99
+ qualityGates.includes('Screenshot or visual inspection for layout-sensitive work'),
100
+ 'references/quality-gates.md',
101
+ ),
102
+ check(
103
+ 'UIE02',
104
+ 'evidence taxonomy defines browser proof and downgrade examples',
105
+ taxonomy.includes('A UI component test can be `status: verified` with `evidenceLevel: verified-component`') &&
106
+ taxonomy.includes('A Playwright smoke can be `status: verified` with `evidenceLevel: verified-browser`') &&
107
+ taxonomy.includes('requiredEvidenceLevel'),
108
+ 'references/evidence-taxonomy.md',
109
+ ),
110
+ check(
111
+ 'UIE03',
112
+ 'evidence template requires status, level, and required level',
113
+ template.includes('Evidence status') &&
114
+ template.includes('Evidence level') &&
115
+ template.includes('Required evidence level'),
116
+ 'assets/templates/evidence.md',
117
+ ),
118
+ check(
119
+ 'UIE04',
120
+ 'continue preflight exposes evidence level downgrades before implementation',
121
+ continuePacket.includes('evidenceLevels') &&
122
+ continuePacket.includes('downgraded') &&
123
+ continuePacket.includes('verified-component') &&
124
+ continuePacket.includes('verified-browser'),
125
+ 'scripts/generate-continue-packet.mjs',
126
+ ),
127
+ check(
128
+ 'UIE05',
129
+ 'close gate surfaces evidence downgrade before close',
130
+ closeGate.includes('CG09') &&
131
+ closeGate.includes('evidence level') &&
132
+ closeGate.includes('downgrade'),
133
+ 'scripts/audit-close-gate.mjs',
134
+ ),
135
+ check(
136
+ 'UIE06',
137
+ 'fixture labels component proof downgrade from required browser proof',
138
+ fixtureAnalysis.downgraded.length === 1 &&
139
+ fixtureAnalysis.downgraded[0]?.evidenceLevel === 'verified-component' &&
140
+ fixtureAnalysis.downgraded[0]?.requiredEvidenceLevel === 'verified-browser',
141
+ `${fixtureAnalysis.downgraded.length} downgrade(s)`,
142
+ ),
143
+ check(
144
+ 'UIE07',
145
+ 'target evidence has no invalid evidence levels',
146
+ targetEvidence.ok && targetAnalysis.invalidLevel.length === 0,
147
+ targetEvidence.ok ? `${targetAnalysis.invalidLevel.length} invalid level(s), ${targetAnalysis.downgraded.length} downgrade(s)` : targetEvidence.error,
148
+ ),
149
+ check(
150
+ 'UIE08',
151
+ 'validation profiles include UI/browser evidence policy audit',
152
+ validationProfile.includes('audit-ui-browser-evidence-policy.mjs') &&
153
+ validator.includes('audit-ui-browser-evidence-policy.mjs'),
154
+ 'scripts/run-validation-profile.mjs + scripts/validate-gse.mjs',
155
+ ),
156
+ check(
157
+ 'UIE09',
158
+ 'final-form roadmap tracks browser UI evidence policy as Wave 4 capability',
159
+ roadmap.includes('Done: Browser/UI evidence policy') &&
160
+ roadmap.includes('verified-component') &&
161
+ roadmap.includes('verified-browser'),
162
+ 'references/final-form-roadmap.md',
163
+ ),
164
+ ]
165
+
166
+ fs.rmSync(fixture, { recursive: true, force: true })
167
+
168
+ const passed = checks.filter((item) => item.status === 'passed').length
169
+ const failed = checks.length - passed
170
+ const report = {
171
+ root,
172
+ target,
173
+ generatedAt: new Date().toISOString(),
174
+ summary: { status: failed === 0 ? 'passed' : 'failed', passed, failed, total: checks.length },
175
+ workflows: {
176
+ uiBrowserEvidencePolicy: failed === 0 ? 'verified' : 'failed',
177
+ targetDowngrades: targetAnalysis.downgraded.length,
178
+ targetInvalidLevels: targetAnalysis.invalidLevel.length,
179
+ },
180
+ checks,
181
+ limits: [
182
+ 'This audit verifies UI/browser evidence policy and gate wiring.',
183
+ 'It does not run a real browser, Playwright, screenshot, or visual inspection.',
184
+ 'Only a project-specific browser/screenshot smoke can justify evidenceLevel verified-browser for visible UI behavior.',
185
+ ],
186
+ }
187
+
188
+ if (jsonOnly) console.log(JSON.stringify(report, null, 2))
189
+ else console.log(JSON.stringify(report, null, 2))
190
+
191
+ if (failed > 0) process.exit(1)
@@ -48,8 +48,10 @@ const runnerSource = read('scripts/run-validation-profile.mjs')
48
48
  const skill = read('SKILL.md')
49
49
  const commands = read('references/commands.md')
50
50
  const qualityGates = read('references/quality-gates.md')
51
- const lite = run(['--root', root, '--target', root, '--profile', 'lite', '--json'])
52
- const standard = run(['--root', root, '--target', root, '--profile', 'standard', '--json'])
51
+ const lite = run(['--root', root, '--target', root, '--profile', 'lite', '--json'])
52
+ const standard = run(['--root', root, '--target', root, '--profile', 'standard', '--json'])
53
+ const liteScripts = new Set((lite.parsed?.results ?? []).map((item) => item.script))
54
+ const standardScripts = new Set((standard.parsed?.results ?? []).map((item) => item.script))
53
55
  const releaseProfileScripts = [
54
56
  'audit-command-execution.mjs',
55
57
  'audit-npm-package-metadata.mjs',
@@ -67,8 +69,8 @@ const releaseProfileScripts = [
67
69
  const checks = [
68
70
  check('VP01', 'validation profile runner exists', fs.existsSync(path.join(root, 'scripts', 'run-validation-profile.mjs')), 'scripts/run-validation-profile.mjs'),
69
71
  check('VP02', 'runner defines lite, standard, enterprise, and release profiles', ['lite', 'standard', 'enterprise', 'release'].every((item) => runnerSource.includes(`'${item}'`)), 'profile names'),
70
- check('VP03', 'lite profile avoids release/distribution heavy gates', lite.status === 0 && lite.parsed?.summary?.status === 'passed' && !lite.stdout.includes('audit-distribution.mjs') && !lite.stdout.includes('audit-release-bundle.mjs'), 'lite profile output'),
71
- check('VP04', 'standard profile passes without forcing close gate during in-progress work', standard.status === 0 && standard.parsed?.summary?.status === 'passed' && !standard.stdout.includes('audit-close-gate.mjs') && !standard.stdout.includes('audit-distribution.mjs'), 'standard profile output'),
72
+ check('VP03', 'lite profile avoids release/distribution heavy gates', lite.status === 0 && lite.parsed?.summary?.status === 'passed' && !liteScripts.has('audit-distribution.mjs') && !liteScripts.has('audit-release-bundle.mjs'), 'lite profile output'),
73
+ check('VP04', 'standard profile passes without forcing close gate during in-progress work', standard.status === 0 && standard.parsed?.summary?.status === 'passed' && !standardScripts.has('audit-close-gate.mjs') && !standardScripts.has('audit-distribution.mjs'), 'standard profile output'),
72
74
  check('VP05', 'quality gates document full validation as enterprise/release-grade work', qualityGates.includes('Full validation belongs here, not on every small product slice') && qualityGates.includes('Use the lightest gate profile'), 'references/quality-gates.md'),
73
75
  check('VP06', 'skill exposes validation profile runner', skill.includes('run-validation-profile.mjs'), 'SKILL.md'),
74
76
  check('VP07', 'command docs expose profile-based verify', commands.includes('/gse verify --profile lite') && commands.includes('run-validation-profile.mjs'), 'references/commands.md'),