@archangel70/cosmo 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/README.md +792 -0
- package/SECURITY.md +15 -0
- package/docs/AGENT-HANDOFF.md +44 -0
- package/docs/ARCHITECTURE-INTELLIGENCE.md +64 -0
- package/docs/ARCHITECTURE.md +97 -0
- package/docs/BRAND-DISCOVERY.md +12 -0
- package/docs/BROWSER-QA.md +40 -0
- package/docs/CLAUDE-LAUNCHER.md +72 -0
- package/docs/CONTENT-QA.md +62 -0
- package/docs/DELIVERY.md +40 -0
- package/docs/DEPLOYMENT.md +119 -0
- package/docs/FIRST-PARTY-CAPABILITIES.md +54 -0
- package/docs/GENERATION.md +81 -0
- package/docs/INTEGRITY.md +75 -0
- package/docs/INTELLIGENCE-PACKS.md +122 -0
- package/docs/OPERATIONS.md +7 -0
- package/docs/PAGE-PRODUCTION.md +81 -0
- package/docs/ROADMAP.md +184 -0
- package/docs/WORKFLOWS.md +71 -0
- package/package.json +97 -0
- package/packages/cli/bin/cosmo.mjs +901 -0
- package/packages/cli/lib/adoption.mjs +72 -0
- package/packages/cli/lib/audit.mjs +145 -0
- package/packages/cli/lib/brand.mjs +60 -0
- package/packages/cli/lib/browser-audit.mjs +177 -0
- package/packages/cli/lib/claude-plugin.mjs +64 -0
- package/packages/cli/lib/content-audit.mjs +184 -0
- package/packages/cli/lib/delivery.mjs +140 -0
- package/packages/cli/lib/deployment.mjs +211 -0
- package/packages/cli/lib/doctor.mjs +42 -0
- package/packages/cli/lib/file-transfer.mjs +143 -0
- package/packages/cli/lib/generation.mjs +319 -0
- package/packages/cli/lib/handoff.mjs +109 -0
- package/packages/cli/lib/integrity.mjs +315 -0
- package/packages/cli/lib/intelligence-audit.mjs +445 -0
- package/packages/cli/lib/intelligence.mjs +331 -0
- package/packages/cli/lib/page-work.mjs +154 -0
- package/packages/cli/lib/plan.mjs +229 -0
- package/packages/cli/lib/process.mjs +45 -0
- package/packages/cli/lib/project.mjs +113 -0
- package/packages/cli/lib/research.mjs +85 -0
- package/packages/cli/lib/status.mjs +46 -0
- package/packages/cli/lib/workflow.mjs +294 -0
- package/plugins/claude-code/cosmo/.claude-plugin/plugin.json +10 -0
- package/plugins/claude-code/cosmo/README.md +25 -0
- package/plugins/claude-code/cosmo/bin/cosmo +11 -0
- package/plugins/claude-code/cosmo/skills/cosmo/SKILL.md +122 -0
- package/plugins/claude-code/cosmo/skills/cosmo-help/SKILL.md +16 -0
- package/scripts/postinstall.mjs +14 -0
- package/templates/astro-site/.cosmo/brand/discovery.json +19 -0
- package/templates/astro-site/.cosmo/brand/entity-canon.json +20 -0
- package/templates/astro-site/.cosmo/brand/voice-profile.json +16 -0
- package/templates/astro-site/.cosmo/build-plan.json +75 -0
- package/templates/astro-site/.cosmo/capabilities/registry.json +21 -0
- package/templates/astro-site/.cosmo/evidence.json +11 -0
- package/templates/astro-site/.cosmo/intelligence/selection.json +5 -0
- package/templates/astro-site/.cosmo/policies/content-integrity.json +22 -0
- package/templates/astro-site/.cosmo/project.json +10 -0
- package/templates/astro-site/.cosmo/work/pages/about/brief.json +49 -0
- package/templates/astro-site/.cosmo/work/pages/home/brief.json +51 -0
- package/templates/astro-site/.cosmo/workflows/default.json +146 -0
- package/templates/astro-site/.env.example +7 -0
- package/templates/astro-site/AGENTS.md +26 -0
- package/templates/astro-site/CLAUDE.md +28 -0
- package/templates/astro-site/DESIGN-DIRECTION.md +9 -0
- package/templates/astro-site/README.md +17 -0
- package/templates/astro-site/astro.config.mjs +16 -0
- package/templates/astro-site/cosmo.config.mjs +12 -0
- package/templates/astro-site/gitignore.template +9 -0
- package/templates/astro-site/package.json +23 -0
- package/templates/astro-site/public/favicon.svg +5 -0
- package/templates/astro-site/src/components/PageView.astro +20 -0
- package/templates/astro-site/src/components/sections/Action.astro +24 -0
- package/templates/astro-site/src/components/sections/Evidence.astro +19 -0
- package/templates/astro-site/src/components/sections/Hero.astro +41 -0
- package/templates/astro-site/src/components/sections/Problem.astro +19 -0
- package/templates/astro-site/src/components/sections/Proof.astro +15 -0
- package/templates/astro-site/src/components/sections/SectionRenderer.astro +22 -0
- package/templates/astro-site/src/components/sections/Solution.astro +19 -0
- package/templates/astro-site/src/components/seo/SeoHead.astro +41 -0
- package/templates/astro-site/src/content/pages/about.md +52 -0
- package/templates/astro-site/src/content/pages/home.md +48 -0
- package/templates/astro-site/src/content.config.ts +133 -0
- package/templates/astro-site/src/env.d.ts +1 -0
- package/templates/astro-site/src/layouts/BaseLayout.astro +57 -0
- package/templates/astro-site/src/pages/[...slug].astro +22 -0
- package/templates/astro-site/src/pages/index.astro +9 -0
- package/templates/astro-site/src/pages/robots.txt.ts +6 -0
- package/templates/astro-site/src/styles/global.css +540 -0
- package/templates/astro-site/src/styles/tokens.css +27 -0
- package/templates/astro-site/tsconfig.json +9 -0
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import crypto from 'node:crypto';
|
|
4
|
+
import matter from 'gray-matter';
|
|
5
|
+
import { readIntelligence } from './intelligence.mjs';
|
|
6
|
+
import { writeJson } from './project.mjs';
|
|
7
|
+
|
|
8
|
+
const RICH_OWNERSHIP = new Set(['measured', 'lived', 'originated', 'accessed', 'staked', 'first', 'corrected']);
|
|
9
|
+
|
|
10
|
+
function finding(packId, code, severity, message, fix) {
|
|
11
|
+
return { packId, code, severity, message, fix };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function normalized(value) {
|
|
15
|
+
return String(value ?? '').toLowerCase().replace(/[^a-z0-9]+/g, ' ').trim();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function nonEmpty(value) {
|
|
19
|
+
if (typeof value === 'string') return value.trim().length > 0;
|
|
20
|
+
if (Array.isArray(value)) return value.length > 0;
|
|
21
|
+
if (value && typeof value === 'object') return Object.keys(value).length > 0;
|
|
22
|
+
return value !== undefined && value !== null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function valueAtPath(value, keyPath) {
|
|
26
|
+
return keyPath.split('.').reduce((current, key) => current?.[key], value);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function readJson(file) {
|
|
30
|
+
try {
|
|
31
|
+
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
32
|
+
} catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function pageContent(projectDir, page) {
|
|
38
|
+
const file = path.resolve(projectDir, page.contentFile);
|
|
39
|
+
if (!fs.existsSync(file)) return { file, data: null, surface: '' };
|
|
40
|
+
const parsed = matter(fs.readFileSync(file, 'utf8'));
|
|
41
|
+
return { file, data: parsed.data, surface: `${JSON.stringify(parsed.data)}\n${parsed.content}` };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function artifactState(projectDir, pack) {
|
|
45
|
+
const file = path.resolve(projectDir, pack.artifact.path);
|
|
46
|
+
const findings = [];
|
|
47
|
+
if (!fs.existsSync(file)) {
|
|
48
|
+
findings.push(finding(pack.id, 'missing-pack-artifact', 'blocking', `Required pack artifact is missing: ${pack.artifact.path}`, 'Run cosmo intelligence scaffold, complete the artifact, and submit it for review.'));
|
|
49
|
+
return { file, data: null, findings };
|
|
50
|
+
}
|
|
51
|
+
const data = readJson(file);
|
|
52
|
+
if (!data) {
|
|
53
|
+
findings.push(finding(pack.id, 'invalid-pack-artifact', 'blocking', `Pack artifact is not valid JSON: ${pack.artifact.path}`, 'Repair the JSON without removing required fields.'));
|
|
54
|
+
return { file, data: null, findings };
|
|
55
|
+
}
|
|
56
|
+
for (const key of pack.artifact.requiredKeys ?? []) {
|
|
57
|
+
if (valueAtPath(data, key) === undefined) findings.push(finding(pack.id, 'pack-artifact-key-missing', 'blocking', `${pack.artifact.path} is missing ${key}.`, `Add the required ${key} field.`));
|
|
58
|
+
}
|
|
59
|
+
for (const key of pack.artifact.nonEmptyKeys ?? []) {
|
|
60
|
+
if (!nonEmpty(valueAtPath(data, key))) findings.push(finding(pack.id, 'pack-artifact-value-empty', 'blocking', `${pack.artifact.path} requires a non-empty ${key}.`, `Complete ${key} from approved project inputs.`));
|
|
61
|
+
}
|
|
62
|
+
return { file, data, findings };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function authorityFindings(context, artifact) {
|
|
66
|
+
const { plan, evidence, pack } = context;
|
|
67
|
+
const findings = [];
|
|
68
|
+
const indexable = plan.pages.filter((page) => page.architecture?.indexability === 'index');
|
|
69
|
+
if (!indexable.length) findings.push(finding(pack.id, 'authority-no-indexable-pages', 'warning', 'The authority pack is selected but no page is currently indexable.', 'Complete evidence and approve the pages that should represent the entity publicly.'));
|
|
70
|
+
const proofUsage = new Map();
|
|
71
|
+
for (const page of indexable) {
|
|
72
|
+
const proofs = page.contract?.carriesProof ?? [];
|
|
73
|
+
for (const proofId of proofs) proofUsage.set(proofId, (proofUsage.get(proofId) ?? 0) + 1);
|
|
74
|
+
const verified = proofs.map((id) => evidence.proofs.find((proof) => proof.id === id)).filter((proof) => proof?.status === 'verified');
|
|
75
|
+
if (!verified.length) findings.push(finding(pack.id, 'authority-page-without-verified-proof', 'blocking', `Indexable page ${page.id} carries no verified proof.`, 'Supply page-specific proof or keep the page noindex.'));
|
|
76
|
+
if (verified.length && !verified.some((proof) => RICH_OWNERSHIP.has(proof.ownership))) findings.push(finding(pack.id, 'authority-page-without-owned-distinction', 'warning', `Indexable page ${page.id} has verified proof but no differentiating ownership class.`, 'Add measured, lived, originated, accessed, staked, first, or corrected proof.'));
|
|
77
|
+
}
|
|
78
|
+
for (const [proofId, count] of proofUsage) if (indexable.length >= 3 && count / indexable.length > 0.66) findings.push(finding(pack.id, 'authority-proof-overused', 'warning', `Proof ${proofId} is reused on ${count}/${indexable.length} indexable pages.`, 'Add page-specific proof instead of making one generic artifact support most of the site.'));
|
|
79
|
+
if (artifact && (!Array.isArray(artifact.topicalBoundaries) || artifact.topicalBoundaries.some((item) => !nonEmpty(item)))) findings.push(finding(pack.id, 'authority-boundaries-invalid', 'blocking', 'Topical boundaries must be a non-empty list of explicit in-scope or out-of-scope statements.', 'Rewrite topicalBoundaries as reviewable boundary statements.'));
|
|
80
|
+
return findings;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function localFindings(context, artifact) {
|
|
84
|
+
const { plan, evidence, pack } = context;
|
|
85
|
+
const findings = [];
|
|
86
|
+
const pages = plan.pages.filter((page) => page.type === 'location');
|
|
87
|
+
if (!pages.length) findings.push(finding(pack.id, 'local-pack-unused', 'warning', 'The local pack is selected but the plan contains no location page.', 'Remove the pack if locality is not part of the approved strategy.'));
|
|
88
|
+
const proofIds = new Set(Array.isArray(artifact?.localProofIds) ? artifact.localProofIds : []);
|
|
89
|
+
for (const proofId of proofIds) if (!evidence.proofs.some((proof) => proof.id === proofId)) findings.push(finding(pack.id, 'unknown-local-proof', 'blocking', `Local-market artifact references unknown proof ${proofId}.`, 'Register the proof in the central evidence ledger or remove the reference.'));
|
|
90
|
+
for (const page of pages) {
|
|
91
|
+
const serviceArea = normalized(Array.isArray(artifact?.serviceArea) ? artifact.serviceArea.join(' ') : artifact?.serviceArea);
|
|
92
|
+
const locationName = normalized(page.data?.locationName);
|
|
93
|
+
if (locationName && !serviceArea.includes(locationName)) findings.push(finding(pack.id, 'location-outside-approved-service-area', 'blocking', `Location page ${page.id} is not represented in the approved serviceArea.`, 'Confirm genuine coverage in the local-market artifact or remove the route.'));
|
|
94
|
+
const carried = page.contract?.carriesProof ?? [];
|
|
95
|
+
if (!carried.some((id) => proofIds.has(id))) findings.push(finding(pack.id, 'location-page-not-backed-by-local-proof', 'blocking', `Location page ${page.id} carries none of the approved localProofIds.`, 'Connect the page to verified local evidence or remove the route.'));
|
|
96
|
+
if (page.architecture?.indexability === 'index') {
|
|
97
|
+
const rich = carried.map((id) => evidence.proofs.find((proof) => proof.id === id)).some((proof) => proof?.status === 'verified' && RICH_OWNERSHIP.has(proof.ownership));
|
|
98
|
+
if (!rich) findings.push(finding(pack.id, 'indexable-location-without-rich-proof', 'blocking', `Indexable location page ${page.id} lacks verified, project-owned local proof.`, 'Keep it noindex until genuine coverage or presence proof is verified.'));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const targets = new Map();
|
|
102
|
+
for (const page of pages) {
|
|
103
|
+
const target = normalized(page.contract?.answerFirstTarget);
|
|
104
|
+
if (!target) continue;
|
|
105
|
+
const owners = targets.get(target) ?? [];
|
|
106
|
+
owners.push(page.id);
|
|
107
|
+
targets.set(target, owners);
|
|
108
|
+
}
|
|
109
|
+
for (const owners of targets.values()) if (owners.length > 1) findings.push(finding(pack.id, 'location-doorway-pattern', 'blocking', `Location pages share the same answer target: ${owners.join(', ')}.`, 'Give each route distinct local utility or consolidate the pages.'));
|
|
110
|
+
return findings;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function editorialFindings(context) {
|
|
114
|
+
const { projectDir, plan, pack } = context;
|
|
115
|
+
const findings = [];
|
|
116
|
+
const editorialTypes = new Set(['guide', 'answer', 'standard']);
|
|
117
|
+
for (const page of plan.pages.filter((item) => item.architecture?.indexability === 'index' && editorialTypes.has(item.type))) {
|
|
118
|
+
const content = pageContent(projectDir, page).data;
|
|
119
|
+
for (const key of ['author', 'reviewedBy', 'publishedAt', 'correctionPolicy']) if (!nonEmpty(content?.editorial?.[key])) findings.push(finding(pack.id, 'editorial-metadata-missing', 'blocking', `Indexable editorial page ${page.id} is missing editorial.${key}.`, `Add approved ${key} metadata to the page.`));
|
|
120
|
+
for (const key of ['publishedAt', 'updatedAt']) if (content?.editorial?.[key] && Number.isNaN(Date.parse(content.editorial[key]))) findings.push(finding(pack.id, 'editorial-date-invalid', 'blocking', `Page ${page.id} has an invalid editorial.${key}.`, 'Use an ISO 8601 date.'));
|
|
121
|
+
}
|
|
122
|
+
return findings;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function regulatedFindings(context, artifact) {
|
|
126
|
+
const { projectDir, plan, evidence, pack } = context;
|
|
127
|
+
const findings = [];
|
|
128
|
+
const claims = new Map(evidence.claims.map((claim) => [claim.id, claim]));
|
|
129
|
+
for (const page of plan.pages) {
|
|
130
|
+
const highRisk = (page.contract?.supportsClaims ?? []).map((id) => claims.get(id)).filter((claim) => claim?.risk === 'high');
|
|
131
|
+
if (!highRisk.length) continue;
|
|
132
|
+
for (const claim of highRisk) {
|
|
133
|
+
const verified = claim.proofIds.some((id) => evidence.proofs.find((proof) => proof.id === id)?.status === 'verified');
|
|
134
|
+
if (!verified) findings.push(finding(pack.id, 'regulated-claim-unverified', 'blocking', `Page ${page.id} uses high-risk claim ${claim.id} without verified proof.`, 'Obtain reviewer-approved proof or remove the claim.'));
|
|
135
|
+
}
|
|
136
|
+
if (page.architecture?.indexability === 'index') {
|
|
137
|
+
const review = pageContent(projectDir, page).data?.regulatoryReview;
|
|
138
|
+
for (const key of ['reviewedBy', 'reviewedAt', 'jurisdiction']) if (!nonEmpty(review?.[key])) findings.push(finding(pack.id, 'regulatory-review-missing', 'blocking', `Indexable regulated page ${page.id} is missing regulatoryReview.${key}.`, 'Record the authorized review before indexing.'));
|
|
139
|
+
if (review?.status !== 'approved') findings.push(finding(pack.id, 'regulatory-review-not-approved', 'blocking', `Indexable regulated page ${page.id} does not have approved regulatory review.`, 'Set status to approved only after the named reviewer signs off.'));
|
|
140
|
+
const suppliedDisclaimers = new Set(review?.disclaimers ?? []);
|
|
141
|
+
for (const disclaimer of artifact?.requiredDisclaimers ?? []) if (!suppliedDisclaimers.has(disclaimer)) findings.push(finding(pack.id, 'required-disclaimer-missing', 'blocking', `Indexable regulated page ${page.id} is missing required disclaimer ${disclaimer}.`, 'Add the approved disclaimer id to regulatoryReview.disclaimers and render its reviewed text.'));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const prohibited = Array.isArray(artifact?.prohibitedClaims) ? artifact.prohibitedClaims.filter((item) => typeof item === 'string' && item.trim()) : [];
|
|
145
|
+
for (const page of plan.pages) {
|
|
146
|
+
const surface = normalized(pageContent(projectDir, page).surface);
|
|
147
|
+
for (const phrase of prohibited) if (surface.includes(normalized(phrase))) findings.push(finding(pack.id, 'prohibited-regulated-claim', 'blocking', `Page ${page.id} contains prohibited claim language: “${phrase}”.`, 'Remove the language and request regulated-content review.'));
|
|
148
|
+
}
|
|
149
|
+
return findings;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function researchFindings(context, artifact) {
|
|
153
|
+
const { plan, pack } = context;
|
|
154
|
+
const findings = [];
|
|
155
|
+
const records = Array.isArray(artifact?.findings) ? artifact.findings : [];
|
|
156
|
+
const valid = [];
|
|
157
|
+
for (const [index, record] of records.entries()) {
|
|
158
|
+
if (!record || typeof record !== 'object') {
|
|
159
|
+
findings.push(finding(pack.id, 'research-finding-unstructured', 'blocking', `Research finding ${index + 1} is not a structured record.`, 'Record id, statement, source, sourceType, observedAt, and status.'));
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
const missing = ['id', 'statement', 'source', 'sourceType', 'observedAt', 'status', 'supportsPageIds'].filter((key) => !nonEmpty(record[key]));
|
|
163
|
+
if (missing.length) findings.push(finding(pack.id, 'research-finding-incomplete', 'blocking', `Research finding ${record.id ?? index + 1} is missing ${missing.join(', ')}.`, 'Complete provenance before using the finding.'));
|
|
164
|
+
if (record.observedAt && Number.isNaN(Date.parse(record.observedAt))) findings.push(finding(pack.id, 'research-date-invalid', 'blocking', `Research finding ${record.id ?? index + 1} has an invalid observedAt date.`, 'Use an ISO 8601 date.'));
|
|
165
|
+
if (record.sourceType && !['primary', 'secondary', 'owned', 'public'].includes(record.sourceType)) findings.push(finding(pack.id, 'research-source-type-invalid', 'blocking', `Research finding ${record.id ?? index + 1} has unsupported sourceType ${record.sourceType}.`, 'Classify the source as primary, secondary, owned, or public.'));
|
|
166
|
+
for (const pageId of record.supportsPageIds ?? []) if (!plan.pages.some((page) => page.id === pageId)) findings.push(finding(pack.id, 'research-page-reference-unknown', 'blocking', `Research finding ${record.id ?? index + 1} supports unknown page ${pageId}.`, 'Use a real planned page id or remove the reference.'));
|
|
167
|
+
const maxAgeDays = Number(artifact?.sourcePolicy?.maxAgeDays);
|
|
168
|
+
if (record.observedAt && Number.isFinite(maxAgeDays) && maxAgeDays > 0 && !Number.isNaN(Date.parse(record.observedAt))) {
|
|
169
|
+
const ageDays = (Date.now() - Date.parse(record.observedAt)) / 86_400_000;
|
|
170
|
+
if (ageDays > maxAgeDays) findings.push(finding(pack.id, 'research-finding-stale', 'warning', `Research finding ${record.id ?? index + 1} is older than the ${maxAgeDays}-day source policy.`, 'Refresh the source or document why historical evidence remains appropriate.'));
|
|
171
|
+
}
|
|
172
|
+
if (record.status === 'conflicted') findings.push(finding(pack.id, 'research-conflict-unresolved', 'blocking', `Research finding ${record.id ?? index + 1} is marked conflicted.`, 'Resolve or explicitly exclude the disputed finding from planning.'));
|
|
173
|
+
if (record.status === 'limited') findings.push(finding(pack.id, 'research-limitation', 'warning', `Research finding ${record.id ?? index + 1} is marked limited.`, 'Keep the limitation visible wherever the finding informs a decision.'));
|
|
174
|
+
if (!missing.length && record.status === 'supported') valid.push(record);
|
|
175
|
+
}
|
|
176
|
+
for (const page of plan.pages.filter((item) => item.architecture?.intent?.demandConfidence === 'observed')) if (!valid.some((record) => record.supportsPageIds.includes(page.id))) findings.push(finding(pack.id, 'observed-demand-without-research', 'blocking', `Page ${page.id} declares observed demand without a supported research finding linked to it.`, 'Link observed planning confidence to structured, sourced findings or downgrade it to inferred.'));
|
|
177
|
+
return findings;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function audienceIntelligenceFindings(context, artifact) {
|
|
181
|
+
const { pack } = context;
|
|
182
|
+
const findings = [];
|
|
183
|
+
const states = new Set(['supplied', 'observed', 'inferred', 'unknown']);
|
|
184
|
+
for (const [index, segment] of (artifact?.segments ?? []).entries()) {
|
|
185
|
+
const label = segment?.id ?? index + 1;
|
|
186
|
+
for (const key of ['id', 'label', 'evidenceState', 'decisionImpact', 'needs', 'fears', 'language']) if (!nonEmpty(segment?.[key])) findings.push(finding(pack.id, 'audience-segment-incomplete', 'blocking', `Audience segment ${label} is missing ${key}.`, 'Complete the field from supplied inputs or mark the information unknown.'));
|
|
187
|
+
if (segment?.evidenceState && !states.has(segment.evidenceState)) findings.push(finding(pack.id, 'audience-evidence-state-invalid', 'blocking', `Audience segment ${label} has invalid evidenceState ${segment.evidenceState}.`, 'Use supplied, observed, inferred, or unknown.'));
|
|
188
|
+
if (['supplied', 'observed'].includes(segment?.evidenceState) && !nonEmpty(segment.sources)) findings.push(finding(pack.id, 'audience-evidence-source-missing', 'blocking', `Audience segment ${label} is ${segment.evidenceState} but has no sources.`, 'Add attributable source records or change the evidence state.'));
|
|
189
|
+
if (segment?.evidenceState === 'unknown' && !nonEmpty(segment.unknowns)) findings.push(finding(pack.id, 'audience-unknown-unrecorded', 'warning', `Audience segment ${label} is unknown without stating what remains unknown.`, 'Record the unresolved questions instead of filling them with persona theatre.'));
|
|
190
|
+
if (!nonEmpty(segment?.decisionImpact)) findings.push(finding(pack.id, 'audience-detail-without-decision', 'blocking', `Audience segment ${label} does not change a documented decision.`, 'Remove decorative persona detail or name the content, design, or conversion decision it changes.'));
|
|
191
|
+
}
|
|
192
|
+
return findings;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function differentiationFindings(context, artifact) {
|
|
196
|
+
const { evidence, pack } = context;
|
|
197
|
+
const findings = [];
|
|
198
|
+
const proofMap = new Map((evidence.proofs ?? []).map((proof) => [proof.id, proof]));
|
|
199
|
+
const claimMap = new Map((evidence.claims ?? []).map((claim) => [claim.id, claim]));
|
|
200
|
+
for (const [index, claim] of (artifact?.claims ?? []).entries()) {
|
|
201
|
+
const label = claim?.id ?? index + 1;
|
|
202
|
+
for (const key of ['id', 'statement', 'tier', 'claimId']) if (!nonEmpty(claim?.[key])) findings.push(finding(pack.id, 'differentiation-claim-incomplete', 'blocking', `Differentiation claim ${label} is missing ${key}.`, 'Complete the structured claim and its evidence relationship.'));
|
|
203
|
+
if (claim?.tier && !['commodity', 'premium-commodity', 'non-commodity'].includes(claim.tier)) findings.push(finding(pack.id, 'differentiation-tier-invalid', 'blocking', `Differentiation claim ${label} has invalid tier ${claim.tier}.`, 'Use commodity, premium-commodity, or non-commodity.'));
|
|
204
|
+
if (claim?.claimId && !claimMap.has(claim.claimId)) findings.push(finding(pack.id, 'differentiation-claim-unknown', 'blocking', `Differentiation claim ${label} references unknown claim ${claim.claimId}.`, 'Register it in the evidence ledger or remove the assertion.'));
|
|
205
|
+
if (claim?.tier === 'non-commodity') {
|
|
206
|
+
const verified = (claim.proofIds ?? []).map((id) => proofMap.get(id)).filter((proof) => proof?.status === 'verified' && RICH_OWNERSHIP.has(proof.ownership));
|
|
207
|
+
if (!verified.length) findings.push(finding(pack.id, 'noncommodity-without-owned-proof', 'blocking', `Differentiation claim ${label} is labelled non-commodity without verified owned proof.`, 'Downgrade the tier or add verified measured, lived, originated, accessed, staked, first, or corrected evidence.'));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
for (const [index, input] of (artifact?.ownedInputs ?? []).entries()) {
|
|
211
|
+
const label = input?.id ?? index + 1;
|
|
212
|
+
if (!RICH_OWNERSHIP.has(input?.verb)) findings.push(finding(pack.id, 'ownership-verb-invalid', 'blocking', `Owned input ${label} uses unsupported ownership verb ${input?.verb ?? 'none'}.`, 'Use a recognized ownership class and preserve its provenance.'));
|
|
213
|
+
const proof = proofMap.get(input?.proofId);
|
|
214
|
+
if (!proof || proof.status !== 'verified') findings.push(finding(pack.id, 'owned-input-unverified', 'blocking', `Owned input ${label} lacks verified proof ${input?.proofId ?? 'none'}.`, 'Connect the input to a verified evidence-ledger proof.'));
|
|
215
|
+
}
|
|
216
|
+
return findings;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function searchIntelligenceFindings(context, artifact) {
|
|
220
|
+
const { projectDir, plan, pack } = context;
|
|
221
|
+
const findings = [];
|
|
222
|
+
if (artifact?.scope?.geographyAppliedAfterSynthesis !== true) findings.push(finding(pack.id, 'search-geography-too-early', 'blocking', 'Search/community research does not confirm that geography is applied after niche-level synthesis.', 'Research the niche/problem first, then localize validated decisions.'));
|
|
223
|
+
const sources = new Map();
|
|
224
|
+
for (const [index, source] of (artifact?.sources ?? []).entries()) {
|
|
225
|
+
const label = source?.id ?? index + 1;
|
|
226
|
+
for (const key of ['id', 'type', 'location', 'capturedAt', 'snapshot', 'sha256']) if (!nonEmpty(source?.[key])) findings.push(finding(pack.id, 'search-source-incomplete', 'blocking', `Search source ${label} is missing ${key}.`, 'Store attribution, source type, location, capture date, and a hashed raw snapshot.'));
|
|
227
|
+
if (source?.capturedAt && Number.isNaN(Date.parse(source.capturedAt))) findings.push(finding(pack.id, 'search-source-date-invalid', 'blocking', `Search source ${label} has an invalid capturedAt date.`, 'Use an ISO 8601 date.'));
|
|
228
|
+
if (source?.snapshot) {
|
|
229
|
+
const snapshot = path.resolve(projectDir, source.snapshot);
|
|
230
|
+
const root = `${path.resolve(projectDir)}${path.sep}`;
|
|
231
|
+
if (!snapshot.startsWith(root) || !fs.existsSync(snapshot)) findings.push(finding(pack.id, 'search-snapshot-missing', 'blocking', `Search source ${label} snapshot is missing or unsafe.`, 'Capture the attributed raw source inside the project research workspace.'));
|
|
232
|
+
else if (source.sha256 && crypto.createHash('sha256').update(fs.readFileSync(snapshot)).digest('hex') !== source.sha256) findings.push(finding(pack.id, 'search-snapshot-drift', 'blocking', `Search source ${label} snapshot hash has drifted.`, 'Capture a new source record instead of silently changing research evidence.'));
|
|
233
|
+
}
|
|
234
|
+
if (source?.id) sources.set(source.id, source);
|
|
235
|
+
}
|
|
236
|
+
for (const [index, record] of (artifact?.findings ?? []).entries()) {
|
|
237
|
+
const label = record?.id ?? index + 1;
|
|
238
|
+
for (const key of ['id', 'statement', 'sourceIds', 'evidenceState']) if (!nonEmpty(record?.[key])) findings.push(finding(pack.id, 'search-finding-incomplete', 'blocking', `Search finding ${label} is missing ${key}.`, 'Complete its statement, evidence state, and source links.'));
|
|
239
|
+
for (const sourceId of record?.sourceIds ?? []) if (!sources.has(sourceId)) findings.push(finding(pack.id, 'search-source-reference-unknown', 'blocking', `Search finding ${label} references unknown source ${sourceId}.`, 'Use a recorded source id.'));
|
|
240
|
+
if (record?.evidenceState && !['observed', 'inferred', 'unknown'].includes(record.evidenceState)) findings.push(finding(pack.id, 'search-evidence-state-invalid', 'blocking', `Search finding ${label} has invalid evidenceState ${record.evidenceState}.`, 'Use observed, inferred, or unknown.'));
|
|
241
|
+
}
|
|
242
|
+
for (const [index, candidate] of (artifact?.pageCandidates ?? []).entries()) {
|
|
243
|
+
const label = candidate?.pageId ?? index + 1;
|
|
244
|
+
if (!plan.pages.some((page) => page.id === candidate?.pageId)) findings.push(finding(pack.id, 'search-page-candidate-unknown', 'blocking', `Search candidate ${label} does not reference a planned page.`, 'Add the reviewed page to the plan or remove the candidate.'));
|
|
245
|
+
if (!nonEmpty(candidate?.findingIds) || !nonEmpty(candidate?.distinctUtility)) findings.push(finding(pack.id, 'search-page-candidate-incomplete', 'blocking', `Search candidate ${label} lacks finding links or distinct utility.`, 'Prove the intent and unique visitor value before scaling the route.'));
|
|
246
|
+
}
|
|
247
|
+
return findings;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function conversionFindings(context, artifact) {
|
|
251
|
+
const { plan, evidence, pack } = context;
|
|
252
|
+
const findings = [];
|
|
253
|
+
if (!nonEmpty(artifact?.mobile?.behavior)) findings.push(finding(pack.id, 'conversion-mobile-behavior-missing', 'blocking', 'Conversion system has no documented mobile behavior.', 'Describe action visibility, form behavior, and interruption constraints on small screens.'));
|
|
254
|
+
const actions = new Map();
|
|
255
|
+
for (const [index, action] of (artifact?.actions ?? []).entries()) {
|
|
256
|
+
const label = action?.id ?? index + 1;
|
|
257
|
+
for (const key of ['id', 'label', 'href', 'expectation']) if (!nonEmpty(action?.[key])) findings.push(finding(pack.id, 'conversion-action-incomplete', 'blocking', `Conversion action ${label} is missing ${key}.`, 'Document an honest label, destination, and expectation.'));
|
|
258
|
+
if (action?.id) actions.set(action.id, action);
|
|
259
|
+
}
|
|
260
|
+
if (!actions.has(artifact?.primaryAction)) findings.push(finding(pack.id, 'conversion-primary-action-unknown', 'blocking', `Primary action ${artifact?.primaryAction || 'none'} is not defined.`, 'Reference an action from actions.'));
|
|
261
|
+
const proofIds = new Set((evidence.proofs ?? []).filter((proof) => proof.status === 'verified').map((proof) => proof.id));
|
|
262
|
+
const signals = new Map();
|
|
263
|
+
for (const signal of artifact?.trustSignals ?? []) {
|
|
264
|
+
if (!nonEmpty(signal?.id) || !nonEmpty(signal?.proofIds) || !nonEmpty(signal?.placement)) findings.push(finding(pack.id, 'conversion-trust-signal-incomplete', 'blocking', `Trust signal ${signal?.id ?? 'unknown'} lacks an id, proof ids, or placement.`, 'Tie the signal to verified proof and a decision-relevant placement.'));
|
|
265
|
+
for (const proofId of signal?.proofIds ?? []) if (!proofIds.has(proofId)) findings.push(finding(pack.id, 'conversion-trust-proof-unverified', 'blocking', `Trust signal ${signal?.id ?? 'unknown'} references unverified proof ${proofId}.`, 'Use a verified evidence-ledger proof or remove the trust claim.'));
|
|
266
|
+
if (signal?.id) signals.set(signal.id, signal);
|
|
267
|
+
}
|
|
268
|
+
const forms = new Map();
|
|
269
|
+
for (const form of artifact?.forms ?? []) {
|
|
270
|
+
if (!nonEmpty(form?.id) || !nonEmpty(form?.fields) || !nonEmpty(form?.successState)) findings.push(finding(pack.id, 'conversion-form-incomplete', 'blocking', `Form ${form?.id ?? 'unknown'} lacks fields or a success state.`, 'Document the minimum fields, labels, outcome, and failure behavior.'));
|
|
271
|
+
for (const [index, field] of (form?.fields ?? []).entries()) for (const key of ['id', 'label', 'type']) if (!nonEmpty(field?.[key])) findings.push(finding(pack.id, 'conversion-form-field-incomplete', 'blocking', `Field ${field?.id ?? index + 1} in form ${form?.id ?? 'unknown'} is missing ${key}.`, 'Give every field a stable id, visible label, and input type.'));
|
|
272
|
+
if (form?.collectsPersonalData === true && (!nonEmpty(form?.consent?.text) || !nonEmpty(form?.consent?.privacyHref))) findings.push(finding(pack.id, 'conversion-form-consent-missing', 'blocking', `Form ${form?.id ?? 'unknown'} collects personal data without a consent/privacy contract.`, 'Add reviewed consent text and a privacy destination.'));
|
|
273
|
+
if (form?.id) forms.set(form.id, form);
|
|
274
|
+
}
|
|
275
|
+
const events = new Set((artifact?.events ?? []).map((event) => event?.id).filter(Boolean));
|
|
276
|
+
for (const [index, event] of (artifact?.events ?? []).entries()) for (const key of ['id', 'trigger']) if (!nonEmpty(event?.[key])) findings.push(finding(pack.id, 'conversion-event-incomplete', 'blocking', `Analytics event ${event?.id ?? index + 1} is missing ${key}.`, 'Document a stable id and observable trigger without collecting unnecessary personal data.'));
|
|
277
|
+
for (const page of plan.pages) {
|
|
278
|
+
const mapping = (artifact?.pageMappings ?? []).find((item) => item.pageId === page.id);
|
|
279
|
+
if (!mapping) { findings.push(finding(pack.id, 'conversion-page-unmapped', 'blocking', `Planned page ${page.id} has no conversion mapping.`, 'Map its honest next action, trust needs, and analytics events.')); continue; }
|
|
280
|
+
if (!nonEmpty(mapping.actionIds)) findings.push(finding(pack.id, 'conversion-page-without-action', 'blocking', `Page ${page.id} has a conversion mapping but no action.`, 'Assign at least one honest next action.'));
|
|
281
|
+
for (const actionId of mapping.actionIds ?? []) if (!actions.has(actionId)) findings.push(finding(pack.id, 'conversion-action-reference-unknown', 'blocking', `Page ${page.id} references unknown action ${actionId}.`, 'Use a defined conversion action.'));
|
|
282
|
+
for (const signalId of mapping.trustSignalIds ?? []) if (!signals.has(signalId)) findings.push(finding(pack.id, 'conversion-signal-reference-unknown', 'blocking', `Page ${page.id} references unknown trust signal ${signalId}.`, 'Use a defined trust signal.'));
|
|
283
|
+
if (mapping.formId && !forms.has(mapping.formId)) findings.push(finding(pack.id, 'conversion-form-reference-unknown', 'blocking', `Page ${page.id} references unknown form ${mapping.formId}.`, 'Use a defined form contract.'));
|
|
284
|
+
for (const eventId of mapping.eventIds ?? []) if (!events.has(eventId)) findings.push(finding(pack.id, 'conversion-event-reference-unknown', 'blocking', `Page ${page.id} references unknown analytics event ${eventId}.`, 'Use a stable event id from events.'));
|
|
285
|
+
}
|
|
286
|
+
return findings;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const NATURALNESS_PATTERNS = [
|
|
290
|
+
{ id: 'significance', pattern: /\b(testament to|pivotal moment|broader landscape|ever-evolving)\b/gi },
|
|
291
|
+
{ id: 'generic-promotion', pattern: /\b(unlock|game-changing|cutting-edge|seamless|revolutionize)\b/gi },
|
|
292
|
+
{ id: 'vague-attribution', pattern: /\b(experts say|studies show|many believe|it is widely recognized)\b/gi },
|
|
293
|
+
{ id: 'announcement', pattern: /\b(in this (?:article|guide)|let's (?:explore|dive|delve)|it is important to note)\b/gi },
|
|
294
|
+
{ id: 'not-just-but', pattern: /\bnot (?:just|only)\b.{0,100}\bbut\b/gi },
|
|
295
|
+
{ id: 'generic-conclusion', pattern: /\b(the future (?:looks|is) bright|exciting times lie ahead|the possibilities are endless)\b/gi },
|
|
296
|
+
];
|
|
297
|
+
|
|
298
|
+
function editorialNaturalnessFindings(context, artifact) {
|
|
299
|
+
const { projectDir, plan, pack } = context;
|
|
300
|
+
const findings = [];
|
|
301
|
+
if (artifact?.preserveFacts !== true) findings.push(finding(pack.id, 'naturalness-fact-preservation-disabled', 'blocking', 'Editorial naturalness does not explicitly preserve facts.', 'Set preserveFacts to true; style review must never alter evidence.'));
|
|
302
|
+
const threshold = Number(artifact?.clusterThreshold);
|
|
303
|
+
if (!Number.isInteger(threshold) || threshold < 2 || threshold > 20) findings.push(finding(pack.id, 'naturalness-threshold-invalid', 'blocking', 'clusterThreshold must be an integer from 2 to 20.', 'Choose a contextual cluster threshold that limits false positives.'));
|
|
304
|
+
for (const samplePath of artifact?.voiceSamplePaths ?? []) {
|
|
305
|
+
const file = path.resolve(projectDir, samplePath);
|
|
306
|
+
const root = `${path.resolve(projectDir)}${path.sep}`;
|
|
307
|
+
if (!file.startsWith(root) || !fs.existsSync(file)) findings.push(finding(pack.id, 'voice-sample-missing', 'blocking', `Voice sample is missing or unsafe: ${samplePath}`, 'Use an existing project-relative owned sample.'));
|
|
308
|
+
}
|
|
309
|
+
const allowed = new Set((artifact?.allowedPatterns ?? []).map(String));
|
|
310
|
+
for (const page of plan.pages) {
|
|
311
|
+
const surface = pageContent(projectDir, page).surface;
|
|
312
|
+
const hits = [];
|
|
313
|
+
for (const item of NATURALNESS_PATTERNS) {
|
|
314
|
+
const count = [...surface.matchAll(new RegExp(item.pattern.source, item.pattern.flags))].length;
|
|
315
|
+
if (count && !allowed.has(item.id)) hits.push({ id: item.id, count });
|
|
316
|
+
}
|
|
317
|
+
for (const phrase of artifact?.bannedPatterns ?? []) {
|
|
318
|
+
if (!nonEmpty(phrase)) continue;
|
|
319
|
+
const count = normalized(surface).split(normalized(phrase)).length - 1;
|
|
320
|
+
if (count > 0 && !allowed.has(phrase)) hits.push({ id: `project:${phrase}`, count });
|
|
321
|
+
}
|
|
322
|
+
const total = hits.reduce((sum, hit) => sum + hit.count, 0);
|
|
323
|
+
if (Number.isInteger(threshold) && total >= threshold) findings.push(finding(pack.id, 'synthetic-pattern-cluster', 'warning', `Page ${page.id} has ${total} naturalness-pattern hits (${hits.map((hit) => `${hit.id}:${hit.count}`).join(', ')}).`, 'Review the cluster against approved voice samples; do not automatically rewrite facts or intentional voice.'));
|
|
324
|
+
}
|
|
325
|
+
return findings;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function brandedLanguageFindings(context, artifact) {
|
|
329
|
+
const { evidence, pack } = context;
|
|
330
|
+
const findings = [];
|
|
331
|
+
const proofIds = new Set((evidence.proofs ?? []).filter((proof) => proof.status === 'verified').map((proof) => proof.id));
|
|
332
|
+
const terms = new Set();
|
|
333
|
+
for (const [index, term] of (artifact?.terms ?? []).entries()) {
|
|
334
|
+
const label = term?.id ?? index + 1;
|
|
335
|
+
for (const key of ['id', 'term', 'definition', 'origin', 'usage', 'status']) if (!nonEmpty(term?.[key])) findings.push(finding(pack.id, 'branded-term-incomplete', 'blocking', `Branded term ${label} is missing ${key}.`, 'Complete its definition, origin, usage boundary, and approval status.'));
|
|
336
|
+
const key = normalized(term?.term);
|
|
337
|
+
if (key && terms.has(key)) findings.push(finding(pack.id, 'branded-term-duplicate', 'blocking', `Branded term ${term.term} is duplicated.`, 'Keep one canonical term record.'));
|
|
338
|
+
terms.add(key);
|
|
339
|
+
if (term?.status === 'approved' && term?.origin === 'original') {
|
|
340
|
+
if (!(term.proofIds ?? []).some((id) => proofIds.has(id))) findings.push(finding(pack.id, 'original-term-without-proof', 'blocking', `Term ${term.term ?? label} claims original ownership without verified proof.`, 'Add evidence of genuine intellectual contribution or change the origin classification.'));
|
|
341
|
+
}
|
|
342
|
+
if (term?.status && !['draft', 'approved', 'retired'].includes(term.status)) findings.push(finding(pack.id, 'branded-term-status-invalid', 'blocking', `Term ${term.term ?? label} has invalid status ${term.status}.`, 'Use draft, approved, or retired.'));
|
|
343
|
+
}
|
|
344
|
+
return findings;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function imageDirectionFindings(context, artifact) {
|
|
348
|
+
const { projectDir, pack } = context;
|
|
349
|
+
const findings = [];
|
|
350
|
+
const assets = artifact?.assets;
|
|
351
|
+
if (!Array.isArray(assets) || !assets.length) return [finding(pack.id, 'image-inventory-missing', 'blocking', 'Image direction has no governed asset inventory.', 'Add assets with source, rights, role, alt intent, and responsive focal guidance.')];
|
|
352
|
+
for (const [index, asset] of assets.entries()) {
|
|
353
|
+
const label = asset?.id ?? index + 1;
|
|
354
|
+
for (const key of ['id', 'source', 'rights', 'role', 'altIntent', 'focalPoint', 'responsiveCrops']) if (!nonEmpty(asset?.[key])) findings.push(finding(pack.id, 'image-asset-incomplete', 'blocking', `Image asset ${label} is missing ${key}.`, 'Complete the asset provenance, responsive treatment, and usage contract.'));
|
|
355
|
+
if (asset?.source?.startsWith('/')) {
|
|
356
|
+
const local = path.join(projectDir, 'public', asset.source.replace(/^\/+/, ''));
|
|
357
|
+
if (!fs.existsSync(local)) findings.push(finding(pack.id, 'image-asset-missing', 'blocking', `Local image asset does not exist: ${asset.source}`, 'Add the approved file or correct the source path.'));
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return findings;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function claudeDesignFindings(context, artifact) {
|
|
364
|
+
const { projectDir, pack } = context;
|
|
365
|
+
const findings = [];
|
|
366
|
+
if (!Array.isArray(artifact?.directionsExplored) || artifact.directionsExplored.length < 3) findings.push(finding(pack.id, 'design-exploration-too-narrow', 'blocking', 'Claude Design handoff records fewer than three genuinely different directions.', 'Explore and record at least three distinct compositions before selection.'));
|
|
367
|
+
const widths = new Set((artifact?.responsiveStates ?? []).map((state) => Number(typeof state === 'object' ? state.width : state)));
|
|
368
|
+
for (const width of [320, 768, 1440]) if (!widths.has(width)) findings.push(finding(pack.id, 'design-responsive-state-missing', 'blocking', `Claude Design handoff is missing the ${width}px state.`, 'Record the approved responsive state and implementation behavior.'));
|
|
369
|
+
const renders = artifact?.referenceRenders;
|
|
370
|
+
if (!Array.isArray(renders) || !renders.length) findings.push(finding(pack.id, 'design-reference-renders-missing', 'blocking', 'Claude Design handoff has no reference renders.', 'Store project-relative approved reference renders for implementation review.'));
|
|
371
|
+
else for (const render of renders) {
|
|
372
|
+
const file = path.resolve(projectDir, render);
|
|
373
|
+
const root = `${path.resolve(projectDir)}${path.sep}`;
|
|
374
|
+
if (!file.startsWith(root) || !fs.existsSync(file)) findings.push(finding(pack.id, 'design-reference-render-missing', 'blocking', `Reference render is missing or unsafe: ${render}`, 'Use an existing project-relative reference render.'));
|
|
375
|
+
}
|
|
376
|
+
const directionFile = path.join(projectDir, 'DESIGN-DIRECTION.md');
|
|
377
|
+
if (!fs.existsSync(directionFile) || /status:\s*unselected/i.test(fs.readFileSync(directionFile, 'utf8'))) findings.push(finding(pack.id, 'design-direction-unapproved', 'blocking', 'DESIGN-DIRECTION.md is missing or still marked unselected.', 'Record the approved direction before design-stage submission.'));
|
|
378
|
+
const manifest = readJson(path.join(projectDir, '.cosmo', 'design', 'design-manifest.json'));
|
|
379
|
+
if (!manifest || !nonEmpty(manifest.tokens) || !nonEmpty(manifest.components)) findings.push(finding(pack.id, 'design-capture-incomplete', 'blocking', 'The repository-owned design manifest has no captured tokens or components.', 'Implement the selected direction and run cosmo design capture.'));
|
|
380
|
+
return findings;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
const EVALUATORS = {
|
|
384
|
+
authority: authorityFindings,
|
|
385
|
+
local: localFindings,
|
|
386
|
+
editorial: editorialFindings,
|
|
387
|
+
regulated: regulatedFindings,
|
|
388
|
+
research: researchFindings,
|
|
389
|
+
'audience-intelligence': audienceIntelligenceFindings,
|
|
390
|
+
differentiation: differentiationFindings,
|
|
391
|
+
'search-intelligence': searchIntelligenceFindings,
|
|
392
|
+
conversion: conversionFindings,
|
|
393
|
+
'editorial-naturalness': editorialNaturalnessFindings,
|
|
394
|
+
'branded-language': brandedLanguageFindings,
|
|
395
|
+
'image-direction': imageDirectionFindings,
|
|
396
|
+
'claude-design': claudeDesignFindings,
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
function declarativeFindings(pack, artifact) {
|
|
400
|
+
if (!artifact) return [];
|
|
401
|
+
const results = [];
|
|
402
|
+
for (const check of pack.checks ?? []) {
|
|
403
|
+
const value = valueAtPath(artifact, check.path);
|
|
404
|
+
let passed = true;
|
|
405
|
+
if (check.rule === 'non-empty') passed = nonEmpty(value);
|
|
406
|
+
if (check.rule === 'equals') passed = Object.is(value, check.value);
|
|
407
|
+
if (check.rule === 'min-items') passed = Array.isArray(value) && value.length >= check.min;
|
|
408
|
+
if (check.rule === 'contains') passed = Array.isArray(value) ? value.includes(check.value) : typeof value === 'string' && value.includes(String(check.value));
|
|
409
|
+
if (!passed) results.push(finding(pack.id, check.id, check.severity, check.message, check.fix ?? `Update ${pack.artifact.path} at ${check.path}.`));
|
|
410
|
+
}
|
|
411
|
+
return results;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
export function evaluateIntelligence(projectDir) {
|
|
415
|
+
const intelligence = readIntelligence(projectDir);
|
|
416
|
+
const plan = readJson(path.join(projectDir, '.cosmo', 'build-plan.json')) ?? { pages: [] };
|
|
417
|
+
const evidence = readJson(path.join(projectDir, '.cosmo', 'evidence.json')) ?? { claims: [], proofs: [] };
|
|
418
|
+
const packs = intelligence.manifests.map((pack) => {
|
|
419
|
+
const artifact = artifactState(projectDir, pack);
|
|
420
|
+
const context = { projectDir, plan, evidence, pack };
|
|
421
|
+
const specialized = artifact.data ? (EVALUATORS[pack.id]?.(context, artifact.data) ?? []) : [];
|
|
422
|
+
const findings = [...artifact.findings, ...declarativeFindings(pack, artifact.data), ...specialized];
|
|
423
|
+
const blocking = findings.filter((item) => item.severity === 'blocking').length;
|
|
424
|
+
const warnings = findings.filter((item) => item.severity === 'warning').length;
|
|
425
|
+
return { id: pack.id, title: pack.title, passed: blocking === 0, artifact: pack.artifact.path, summary: { blocking, warnings }, findings };
|
|
426
|
+
});
|
|
427
|
+
const findings = packs.flatMap((pack) => pack.findings);
|
|
428
|
+
const blocking = findings.filter((item) => item.severity === 'blocking').length;
|
|
429
|
+
const warnings = findings.filter((item) => item.severity === 'warning').length;
|
|
430
|
+
return {
|
|
431
|
+
version: 1,
|
|
432
|
+
passed: blocking === 0,
|
|
433
|
+
checkedAt: new Date().toISOString(),
|
|
434
|
+
profile: intelligence.data.profile,
|
|
435
|
+
selectedPacks: intelligence.data.packs,
|
|
436
|
+
summary: { packs: packs.length, passed: packs.filter((pack) => pack.passed).length, blocking, warnings },
|
|
437
|
+
packs,
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
export function writeIntelligenceReport(projectDir, report) {
|
|
442
|
+
const file = path.join(projectDir, '.cosmo', 'reports', 'intelligence-check.json');
|
|
443
|
+
writeJson(file, report);
|
|
444
|
+
return file;
|
|
445
|
+
}
|