@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,229 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { readProject } from './project.mjs';
|
|
4
|
+
|
|
5
|
+
export const PAGE_TYPES = ['home', 'service', 'location', 'guide', 'answer', 'comparison', 'standard'];
|
|
6
|
+
export const PAGE_ARCHETYPES = ['hub', 'service', 'location', 'guide', 'answer', 'comparison', 'trust', 'utility'];
|
|
7
|
+
export const LINK_ROLES = ['parent', 'sibling', 'supporting', 'conversion'];
|
|
8
|
+
const FUNNEL_STAGES = ['awareness', 'consideration', 'decision', 'retention'];
|
|
9
|
+
const AWARENESS_STAGES = ['unaware', 'problem-aware', 'solution-aware', 'product-aware', 'most-aware'];
|
|
10
|
+
const DEMAND_CONFIDENCE = ['observed', 'inferred', 'unknown'];
|
|
11
|
+
|
|
12
|
+
export class PlanError extends Error {}
|
|
13
|
+
|
|
14
|
+
function assert(condition, message) {
|
|
15
|
+
if (!condition) throw new PlanError(message);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function normalizedTopic(value) {
|
|
19
|
+
return String(value).toLowerCase().replace(/[^a-z0-9]+/g, ' ').trim();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function topicTokens(value) {
|
|
23
|
+
return new Set(normalizedTopic(value).split(' ').filter((token) => token.length > 2));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function topicSimilarity(a, b) {
|
|
27
|
+
const left = topicTokens(a);
|
|
28
|
+
const right = topicTokens(b);
|
|
29
|
+
const intersection = [...left].filter((token) => right.has(token)).length;
|
|
30
|
+
const union = new Set([...left, ...right]).size;
|
|
31
|
+
return union ? intersection / union : 0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function validateContentFile(file, pageId) {
|
|
35
|
+
assert(typeof file === 'string' && file.startsWith('src/content/pages/') && file.endsWith('.md'), `Page ${pageId} needs a Markdown contentFile under src/content/pages/.`);
|
|
36
|
+
assert(!path.isAbsolute(file) && !file.split(/[\\/]/).includes('..'), `Page ${pageId} has an unsafe contentFile.`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function validateTypeData(page) {
|
|
40
|
+
const data = page.data ?? {};
|
|
41
|
+
if (page.type === 'service') assert(typeof data.serviceName === 'string' && data.serviceName.trim(), `Service page ${page.id} needs data.serviceName.`);
|
|
42
|
+
if (page.type === 'location') {
|
|
43
|
+
assert(typeof data.locationName === 'string' && data.locationName.trim(), `Location page ${page.id} needs data.locationName.`);
|
|
44
|
+
assert(typeof data.region === 'string' && data.region.trim(), `Location page ${page.id} needs data.region.`);
|
|
45
|
+
}
|
|
46
|
+
if (page.type === 'guide') assert(typeof data.guideKind === 'string' && data.guideKind.trim(), `Guide page ${page.id} needs data.guideKind.`);
|
|
47
|
+
if (page.type === 'answer') assert(typeof data.question === 'string' && data.question.trim(), `Answer page ${page.id} needs data.question.`);
|
|
48
|
+
if (page.type === 'comparison') {
|
|
49
|
+
assert(typeof data.subjectA === 'string' && data.subjectA.trim(), `Comparison page ${page.id} needs data.subjectA.`);
|
|
50
|
+
assert(typeof data.subjectB === 'string' && data.subjectB.trim(), `Comparison page ${page.id} needs data.subjectB.`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function validatePageContract(page) {
|
|
55
|
+
const contract = page.contract;
|
|
56
|
+
assert(contract && typeof contract === 'object', `Page ${page.id} needs a four-question contract.`);
|
|
57
|
+
assert(typeof contract.strengthensEntity === 'string' && contract.strengthensEntity.trim(), `Page ${page.id} must declare which entity it strengthens.`);
|
|
58
|
+
assert(Array.isArray(contract.supportsClaims) && contract.supportsClaims.length > 0, `Page ${page.id} must declare at least one claim it supports.`);
|
|
59
|
+
assert(contract.supportsClaims.every((id) => typeof id === 'string' && /^[a-z0-9][a-z0-9-]*$/.test(id)), `Page ${page.id} supportsClaims must contain kebab-case claim ids.`);
|
|
60
|
+
assert(Array.isArray(contract.carriesProof) && contract.carriesProof.length > 0, `Page ${page.id} must declare at least one proof it carries.`);
|
|
61
|
+
assert(contract.carriesProof.every((id) => typeof id === 'string' && /^[a-z0-9][a-z0-9-]*$/.test(id)), `Page ${page.id} carriesProof must contain kebab-case proof ids.`);
|
|
62
|
+
assert(Array.isArray(contract.strengthensPages) && contract.strengthensPages.length > 0, `Page ${page.id} must declare at least one real page it strengthens.`);
|
|
63
|
+
assert(typeof contract.audienceNeed === 'string' && contract.audienceNeed.trim(), `Page ${page.id} must declare an audienceNeed.`);
|
|
64
|
+
assert(['visitor', 'business', 'both'].includes(contract.serves), `Page ${page.id} serves must be visitor, business, or both.`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function validateArchitecture(page) {
|
|
68
|
+
const architecture = page.architecture;
|
|
69
|
+
assert(architecture && typeof architecture === 'object', `Page ${page.id} needs architecture metadata.`);
|
|
70
|
+
assert(PAGE_ARCHETYPES.includes(architecture.archetype), `Page ${page.id} has unsupported archetype ${architecture.archetype}.`);
|
|
71
|
+
assert(['index', 'noindex'].includes(architecture.indexability), `Page ${page.id} indexability must be index or noindex.`);
|
|
72
|
+
const intent = architecture.intent;
|
|
73
|
+
assert(intent && typeof intent === 'object', `Page ${page.id} needs architecture.intent.`);
|
|
74
|
+
assert(typeof intent.primary === 'string' && intent.primary.trim(), `Page ${page.id} needs architecture.intent.primary.`);
|
|
75
|
+
assert(FUNNEL_STAGES.includes(intent.funnel), `Page ${page.id} has invalid funnel stage.`);
|
|
76
|
+
assert(AWARENESS_STAGES.includes(intent.awareness), `Page ${page.id} has invalid awareness stage.`);
|
|
77
|
+
assert(DEMAND_CONFIDENCE.includes(intent.demandConfidence), `Page ${page.id} has invalid demandConfidence.`);
|
|
78
|
+
assert(Array.isArray(intent.queryPatterns) && intent.queryPatterns.length > 0 && intent.queryPatterns.every((query) => typeof query === 'string' && query.trim()), `Page ${page.id} needs non-empty queryPatterns.`);
|
|
79
|
+
assert(Array.isArray(architecture.intentBoundaries), `Page ${page.id} needs an intentBoundaries array.`);
|
|
80
|
+
for (const boundary of architecture.intentBoundaries) {
|
|
81
|
+
assert(boundary && typeof boundary === 'object', `Page ${page.id} has an invalid intent boundary.`);
|
|
82
|
+
assert(typeof boundary.pageId === 'string' && boundary.pageId.trim(), `Page ${page.id} intent boundary needs pageId.`);
|
|
83
|
+
assert(typeof boundary.distinction === 'string' && boundary.distinction.trim(), `Page ${page.id} intent boundary for ${boundary.pageId} needs a distinction.`);
|
|
84
|
+
}
|
|
85
|
+
assert(Array.isArray(page.links), `Page ${page.id} needs a role-based links array.`);
|
|
86
|
+
for (const link of page.links) {
|
|
87
|
+
assert(link && typeof link === 'object', `Page ${page.id} has an invalid link.`);
|
|
88
|
+
assert(typeof link.target === 'string' && link.target.trim(), `Page ${page.id} link needs a target.`);
|
|
89
|
+
assert(LINK_ROLES.includes(link.role), `Page ${page.id} link to ${link.target} has invalid role ${link.role}.`);
|
|
90
|
+
assert(typeof link.reason === 'string' && link.reason.trim(), `Page ${page.id} link to ${link.target} needs a reason.`);
|
|
91
|
+
assert(typeof link.anchorIntent === 'string' && link.anchorIntent.trim(), `Page ${page.id} link to ${link.target} needs anchorIntent.`);
|
|
92
|
+
}
|
|
93
|
+
const parents = page.links.filter((link) => link.role === 'parent');
|
|
94
|
+
if (page.type === 'home') assert(parents.length === 0, `Home page ${page.id} cannot have a parent link.`);
|
|
95
|
+
else assert(parents.length === 1, `Page ${page.id} needs exactly one parent link.`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function pageParentId(plan, page) {
|
|
99
|
+
if (plan.version >= 3) return page.links.find((link) => link.role === 'parent')?.target ?? null;
|
|
100
|
+
return page.parent ?? null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function pageRelatedIds(plan, page) {
|
|
104
|
+
if (plan.version >= 3) return page.links.filter((link) => ['sibling', 'supporting'].includes(link.role)).map((link) => link.target);
|
|
105
|
+
return page.related;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function validatePlan(value, { requireApproved = true } = {}) {
|
|
109
|
+
assert(value && typeof value === 'object', 'Build plan must be a JSON object.');
|
|
110
|
+
assert([1, 2, 3].includes(value.version), 'Build plan version must be 1, 2, or 3.');
|
|
111
|
+
assert(typeof value.approved === 'boolean', 'Build plan approved must be a boolean.');
|
|
112
|
+
if (requireApproved) assert(value.approved === true, 'Build plan must be explicitly approved.');
|
|
113
|
+
assert(Array.isArray(value.pages) && value.pages.length > 0, 'Build plan must contain pages.');
|
|
114
|
+
|
|
115
|
+
const ids = new Set();
|
|
116
|
+
const paths = new Set();
|
|
117
|
+
const topics = new Map();
|
|
118
|
+
for (const page of value.pages) {
|
|
119
|
+
assert(page && typeof page === 'object', 'Every planned page must be an object.');
|
|
120
|
+
assert(typeof page.id === 'string' && /^[a-z0-9][a-z0-9-]*$/.test(page.id), 'Page ids must be kebab-case.');
|
|
121
|
+
assert(!ids.has(page.id), `Duplicate page id: ${page.id}`);
|
|
122
|
+
ids.add(page.id);
|
|
123
|
+
assert(PAGE_TYPES.includes(page.type), `Page ${page.id} has unsupported type ${page.type}.`);
|
|
124
|
+
assert(typeof page.path === 'string' && page.path.startsWith('/') && page.path.endsWith('/'), `Page ${page.id} needs a leading and trailing slash path.`);
|
|
125
|
+
assert(!paths.has(page.path), `Duplicate page path: ${page.path}`);
|
|
126
|
+
paths.add(page.path);
|
|
127
|
+
assert(typeof page.title === 'string' && page.title.trim(), `Page ${page.id} needs a title.`);
|
|
128
|
+
assert(typeof page.primaryTopic === 'string' && page.primaryTopic.trim(), `Page ${page.id} needs a primaryTopic.`);
|
|
129
|
+
const topic = normalizedTopic(page.primaryTopic);
|
|
130
|
+
assert(!topics.has(topic), `Duplicate primary topic between ${topics.get(topic)} and ${page.id}: ${page.primaryTopic}`);
|
|
131
|
+
topics.set(topic, page.id);
|
|
132
|
+
if (value.version < 3) assert(Array.isArray(page.related), `Page ${page.id} needs a related array.`);
|
|
133
|
+
if (value.version === 1) assert(Array.isArray(page.evidenceRequired), `Page ${page.id} needs an evidenceRequired array.`);
|
|
134
|
+
if (value.version >= 2) validatePageContract(page);
|
|
135
|
+
if (value.version >= 3) validateArchitecture(page);
|
|
136
|
+
validateContentFile(page.contentFile, page.id);
|
|
137
|
+
validateTypeData(page);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const homePages = value.pages.filter((page) => page.type === 'home');
|
|
141
|
+
assert(homePages.length === 1 && homePages[0].path === '/', 'Build plan needs exactly one home page at /.');
|
|
142
|
+
for (const page of value.pages) {
|
|
143
|
+
const parentId = pageParentId(value, page);
|
|
144
|
+
if (page.type !== 'home') {
|
|
145
|
+
assert(typeof parentId === 'string' && ids.has(parentId), `Page ${page.id} needs a valid parent id.`);
|
|
146
|
+
assert(parentId !== page.id, `Page ${page.id} cannot parent itself.`);
|
|
147
|
+
}
|
|
148
|
+
for (const related of pageRelatedIds(value, page)) {
|
|
149
|
+
assert(ids.has(related), `Page ${page.id} references unknown related page ${related}.`);
|
|
150
|
+
assert(related !== page.id, `Page ${page.id} cannot relate to itself.`);
|
|
151
|
+
}
|
|
152
|
+
if (value.version >= 2) {
|
|
153
|
+
for (const strengthened of page.contract.strengthensPages) {
|
|
154
|
+
assert(ids.has(strengthened), `Page ${page.id} strengthens unknown page ${strengthened}.`);
|
|
155
|
+
assert(strengthened !== page.id, `Page ${page.id} cannot list itself as a strengthened page.`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (value.version >= 3) {
|
|
159
|
+
const targets = new Set();
|
|
160
|
+
for (const link of page.links) {
|
|
161
|
+
assert(ids.has(link.target), `Page ${page.id} links to unknown page ${link.target}.`);
|
|
162
|
+
assert(link.target !== page.id, `Page ${page.id} cannot link to itself.`);
|
|
163
|
+
assert(!targets.has(link.target), `Page ${page.id} has duplicate governed links to ${link.target}.`);
|
|
164
|
+
targets.add(link.target);
|
|
165
|
+
}
|
|
166
|
+
for (const strengthened of page.contract.strengthensPages) {
|
|
167
|
+
assert(targets.has(strengthened), `Page ${page.id} must link to strengthened page ${strengthened}.`);
|
|
168
|
+
}
|
|
169
|
+
for (const boundary of page.architecture.intentBoundaries) {
|
|
170
|
+
assert(ids.has(boundary.pageId), `Page ${page.id} has an intent boundary for unknown page ${boundary.pageId}.`);
|
|
171
|
+
assert(boundary.pageId !== page.id, `Page ${page.id} cannot have an intent boundary with itself.`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
for (const page of value.pages) {
|
|
177
|
+
const visited = new Set([page.id]);
|
|
178
|
+
let cursor = page;
|
|
179
|
+
let parentId = pageParentId(value, cursor);
|
|
180
|
+
while (parentId) {
|
|
181
|
+
assert(!visited.has(parentId), `Parent cycle detected at ${parentId}.`);
|
|
182
|
+
visited.add(parentId);
|
|
183
|
+
cursor = value.pages.find((candidate) => candidate.id === parentId);
|
|
184
|
+
parentId = pageParentId(value, cursor);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (value.version >= 3) {
|
|
189
|
+
const queries = new Map();
|
|
190
|
+
for (const page of value.pages) {
|
|
191
|
+
for (const query of page.architecture.intent.queryPatterns) {
|
|
192
|
+
const normalized = normalizedTopic(query);
|
|
193
|
+
assert(!queries.has(normalized), `Intent collision: pages ${queries.get(normalized)} and ${page.id} share query pattern ${query}.`);
|
|
194
|
+
queries.set(normalized, page.id);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
for (let leftIndex = 0; leftIndex < value.pages.length; leftIndex += 1) {
|
|
198
|
+
for (let rightIndex = leftIndex + 1; rightIndex < value.pages.length; rightIndex += 1) {
|
|
199
|
+
const left = value.pages[leftIndex];
|
|
200
|
+
const right = value.pages[rightIndex];
|
|
201
|
+
const sameIntent = normalizedTopic(left.architecture.intent.primary) === normalizedTopic(right.architecture.intent.primary);
|
|
202
|
+
const nearTopic = topicSimilarity(left.primaryTopic, right.primaryTopic) >= 0.75;
|
|
203
|
+
if (!sameIntent && !nearTopic) continue;
|
|
204
|
+
const bounded = left.architecture.intentBoundaries.some((boundary) => boundary.pageId === right.id)
|
|
205
|
+
|| right.architecture.intentBoundaries.some((boundary) => boundary.pageId === left.id);
|
|
206
|
+
assert(bounded, `Potential intent collision between ${left.id} and ${right.id}; add an explicit intent boundary or merge them.`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return value;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export function readPlan(projectDir, { requireApproved = true } = {}) {
|
|
214
|
+
readProject(projectDir);
|
|
215
|
+
const file = path.join(projectDir, '.cosmo', 'build-plan.json');
|
|
216
|
+
assert(fs.existsSync(file), `Build plan not found: ${file}`);
|
|
217
|
+
return { file, data: validatePlan(JSON.parse(fs.readFileSync(file, 'utf8')), { requireApproved }) };
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export function planSummary(plan) {
|
|
221
|
+
const byType = Object.fromEntries(PAGE_TYPES.map((type) => [type, plan.pages.filter((page) => page.type === type).length]).filter(([, count]) => count));
|
|
222
|
+
const links = plan.pages.reduce((sum, page) => sum + (plan.version >= 3 ? page.links.length : page.related.length + (page.parent ? 1 : 0)), 0);
|
|
223
|
+
const evidenceRequirements = plan.pages.reduce((sum, page) => sum + (plan.version >= 2 ? page.contract.carriesProof.length : page.evidenceRequired.length), 0);
|
|
224
|
+
const byArchetype = plan.version >= 3 ? Object.fromEntries(PAGE_ARCHETYPES.map((archetype) => [archetype, plan.pages.filter((page) => page.architecture.archetype === archetype).length]).filter(([, count]) => count)) : {};
|
|
225
|
+
const byLinkRole = plan.version >= 3 ? Object.fromEntries(LINK_ROLES.map((role) => [role, plan.pages.flatMap((page) => page.links).filter((link) => link.role === role).length]).filter(([, count]) => count)) : {};
|
|
226
|
+
const indexable = plan.version >= 3 ? plan.pages.filter((page) => page.architecture.indexability === 'index').length : null;
|
|
227
|
+
const intentBoundaries = plan.version >= 3 ? plan.pages.reduce((sum, page) => sum + page.architecture.intentBoundaries.length, 0) : null;
|
|
228
|
+
return { version: plan.version, pages: plan.pages.length, byType, byArchetype, byLinkRole, links, evidenceRequirements, indexable, intentBoundaries };
|
|
229
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
|
|
3
|
+
export function run(command, args, options = {}) {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
const executable = process.platform === 'win32' && command === 'npm' ? 'npm.cmd' : command;
|
|
6
|
+
const child = spawn(executable, args, {
|
|
7
|
+
cwd: options.cwd,
|
|
8
|
+
env: { ...process.env, ...options.env },
|
|
9
|
+
stdio: options.stdio ?? 'inherit',
|
|
10
|
+
shell: false,
|
|
11
|
+
});
|
|
12
|
+
child.on('error', reject);
|
|
13
|
+
child.on('exit', (code) => {
|
|
14
|
+
if (code === 0) resolve(code);
|
|
15
|
+
else reject(new Error(`${command} ${args.join(' ')} exited with code ${code}`));
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function runCaptured(command, args, options = {}) {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
const executable = process.platform === 'win32' && ['npm', 'npx'].includes(command) ? `${command}.cmd` : command;
|
|
23
|
+
const child = spawn(executable, args, {
|
|
24
|
+
cwd: options.cwd,
|
|
25
|
+
env: { ...process.env, ...options.env },
|
|
26
|
+
stdio: ['inherit', 'pipe', 'pipe'],
|
|
27
|
+
shell: false,
|
|
28
|
+
});
|
|
29
|
+
let stdout = '';
|
|
30
|
+
let stderr = '';
|
|
31
|
+
child.stdout.on('data', (chunk) => {
|
|
32
|
+
stdout += chunk;
|
|
33
|
+
if (options.mirror !== false) process.stdout.write(chunk);
|
|
34
|
+
});
|
|
35
|
+
child.stderr.on('data', (chunk) => {
|
|
36
|
+
stderr += chunk;
|
|
37
|
+
if (options.mirror !== false) process.stderr.write(chunk);
|
|
38
|
+
});
|
|
39
|
+
child.on('error', reject);
|
|
40
|
+
child.on('exit', (code) => {
|
|
41
|
+
if (code === 0) resolve({ code, stdout, stderr });
|
|
42
|
+
else reject(new Error(`${command} ${args.join(' ')} exited with code ${code}${stderr.trim() ? `: ${stderr.trim()}` : ''}`));
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
export function slugify(value) {
|
|
5
|
+
return String(value)
|
|
6
|
+
.trim()
|
|
7
|
+
.toLowerCase()
|
|
8
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
9
|
+
.replace(/^-+|-+$/g, '') || 'cosmo-site';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function readProject(projectDir) {
|
|
13
|
+
const file = path.join(projectDir, '.cosmo', 'project.json');
|
|
14
|
+
if (!fs.existsSync(file)) {
|
|
15
|
+
throw new Error(`No Cosmo project found at ${projectDir}`);
|
|
16
|
+
}
|
|
17
|
+
return { file, data: JSON.parse(fs.readFileSync(file, 'utf8')) };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function writeJson(file, value) {
|
|
21
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
22
|
+
const temporary = `${file}.tmp-${process.pid}`;
|
|
23
|
+
fs.writeFileSync(temporary, `${JSON.stringify(value, null, 2)}\n`);
|
|
24
|
+
fs.renameSync(temporary, file);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function parseOptions(args) {
|
|
28
|
+
const options = {};
|
|
29
|
+
const positional = [];
|
|
30
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
31
|
+
const arg = args[index];
|
|
32
|
+
if (!arg.startsWith('--')) {
|
|
33
|
+
positional.push(arg);
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const [rawKey, inlineValue] = arg.slice(2).split('=', 2);
|
|
37
|
+
if (inlineValue !== undefined) {
|
|
38
|
+
options[rawKey] = inlineValue;
|
|
39
|
+
} else if (args[index + 1] && !args[index + 1].startsWith('--')) {
|
|
40
|
+
options[rawKey] = args[index + 1];
|
|
41
|
+
index += 1;
|
|
42
|
+
} else {
|
|
43
|
+
options[rawKey] = true;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return { options, positional };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function ensureEmptyDirectory(targetDir) {
|
|
50
|
+
if (!fs.existsSync(targetDir)) {
|
|
51
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const entries = fs.readdirSync(targetDir).filter((entry) => entry !== '.git');
|
|
55
|
+
if (entries.length > 0) {
|
|
56
|
+
throw new Error(`Target directory is not empty: ${targetDir}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function copyStarter(templateDir, targetDir) {
|
|
61
|
+
fs.cpSync(templateDir, targetDir, {
|
|
62
|
+
recursive: true,
|
|
63
|
+
filter(source) {
|
|
64
|
+
const relative = path.relative(templateDir, source);
|
|
65
|
+
if (!relative) return true;
|
|
66
|
+
const first = relative.split(path.sep)[0];
|
|
67
|
+
if (['node_modules', 'dist', '.astro', 'package-lock.json'].includes(first)) return false;
|
|
68
|
+
if (first === '.env' || (first.startsWith('.env.') && first !== '.env.example')) return false;
|
|
69
|
+
const portable = relative.split(path.sep).join('/');
|
|
70
|
+
if (portable === 'gitignore.template') return false;
|
|
71
|
+
if (first === '.cosmo') {
|
|
72
|
+
return portable === '.cosmo'
|
|
73
|
+
|| portable === '.cosmo/project.json'
|
|
74
|
+
|| portable === '.cosmo/build-plan.json'
|
|
75
|
+
|| portable === '.cosmo/evidence.json'
|
|
76
|
+
|| portable === '.cosmo/brand'
|
|
77
|
+
|| portable.startsWith('.cosmo/brand/')
|
|
78
|
+
|| portable === '.cosmo/capabilities'
|
|
79
|
+
|| portable.startsWith('.cosmo/capabilities/')
|
|
80
|
+
|| portable === '.cosmo/intelligence'
|
|
81
|
+
|| portable.startsWith('.cosmo/intelligence/')
|
|
82
|
+
|| portable === '.cosmo/policies'
|
|
83
|
+
|| portable.startsWith('.cosmo/policies/')
|
|
84
|
+
|| portable === '.cosmo/deploy'
|
|
85
|
+
|| portable === '.cosmo/deploy/config.json'
|
|
86
|
+
|| portable === '.cosmo/work'
|
|
87
|
+
|| portable.startsWith('.cosmo/work/')
|
|
88
|
+
|| portable === '.cosmo/workflows'
|
|
89
|
+
|| portable.startsWith('.cosmo/workflows/');
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
const gitignore = path.join(targetDir, '.gitignore');
|
|
95
|
+
if (!fs.existsSync(gitignore)) {
|
|
96
|
+
const fallback = path.join(templateDir, 'gitignore.template');
|
|
97
|
+
if (fs.existsSync(fallback)) fs.copyFileSync(fallback, gitignore);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function replaceInTextFiles(rootDir, search, replacement) {
|
|
102
|
+
const allowed = new Set(['.astro', '.css', '.html', '.js', '.json', '.md', '.mjs', '.ts', '.txt']);
|
|
103
|
+
for (const entry of fs.readdirSync(rootDir, { withFileTypes: true })) {
|
|
104
|
+
if (['.git', 'node_modules', 'dist', '.astro'].includes(entry.name)) continue;
|
|
105
|
+
const fullPath = path.join(rootDir, entry.name);
|
|
106
|
+
if (entry.isDirectory()) {
|
|
107
|
+
replaceInTextFiles(fullPath, search, replacement);
|
|
108
|
+
} else if (allowed.has(path.extname(entry.name))) {
|
|
109
|
+
const content = fs.readFileSync(fullPath, 'utf8');
|
|
110
|
+
if (content.includes(search)) fs.writeFileSync(fullPath, content.split(search).join(replacement));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { readProject, writeJson } from './project.mjs';
|
|
5
|
+
|
|
6
|
+
export class ResearchError extends Error {}
|
|
7
|
+
|
|
8
|
+
function assert(condition, message) {
|
|
9
|
+
if (!condition) throw new ResearchError(message);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function artifactFile(projectDir) {
|
|
13
|
+
return path.join(projectDir, '.cosmo', 'intelligence', 'artifacts', 'search-intelligence.json');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function scaffoldResearchWorkbench(projectDir, { replace = false } = {}) {
|
|
17
|
+
readProject(projectDir);
|
|
18
|
+
const file = artifactFile(projectDir);
|
|
19
|
+
if (fs.existsSync(file) && !replace) return { file, created: false };
|
|
20
|
+
writeJson(file, {
|
|
21
|
+
version: 1,
|
|
22
|
+
scope: { niche: '', geographyAppliedAfterSynthesis: true },
|
|
23
|
+
tasks: [
|
|
24
|
+
{ id: 'serp-landscape', kind: 'serp', query: '', status: 'pending', sourceIds: [] },
|
|
25
|
+
{ id: 'competitor-landscape', kind: 'competitor', query: '', status: 'pending', sourceIds: [] },
|
|
26
|
+
{ id: 'community-language', kind: 'community', query: '', status: 'pending', sourceIds: [] },
|
|
27
|
+
],
|
|
28
|
+
sources: [], findings: [], pageCandidates: [], limitations: [],
|
|
29
|
+
createdAt: new Date().toISOString(),
|
|
30
|
+
});
|
|
31
|
+
return { file, created: true };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function readResearchWorkbench(projectDir) {
|
|
35
|
+
readProject(projectDir);
|
|
36
|
+
const file = artifactFile(projectDir);
|
|
37
|
+
assert(fs.existsSync(file), `Research workbench not found: ${file}. Run cosmo research init.`);
|
|
38
|
+
let data;
|
|
39
|
+
try { data = JSON.parse(fs.readFileSync(file, 'utf8')); } catch { throw new ResearchError(`Research workbench is not valid JSON: ${file}`); }
|
|
40
|
+
return { file, data };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function captureResearchSource(projectDir, sourceId, inputFile, { kind, location, capturedAt, replace = false } = {}) {
|
|
44
|
+
assert(/^[a-z0-9][a-z0-9-]*$/.test(sourceId), 'Research source id must be kebab-case.');
|
|
45
|
+
assert(['serp', 'competitor', 'community', 'primary', 'secondary', 'owned', 'public'].includes(kind), 'Research source --kind is invalid.');
|
|
46
|
+
assert(typeof location === 'string' && location.trim(), 'Research source requires --location attribution.');
|
|
47
|
+
const source = path.resolve(inputFile);
|
|
48
|
+
assert(fs.existsSync(source) && fs.statSync(source).isFile(), `Research snapshot not found: ${source}`);
|
|
49
|
+
const workbench = readResearchWorkbench(projectDir);
|
|
50
|
+
const existing = (workbench.data.sources ?? []).find((item) => item.id === sourceId);
|
|
51
|
+
assert(!existing || replace, `Research source ${sourceId} already exists. Pass --replace to record a deliberate replacement.`);
|
|
52
|
+
const raw = fs.readFileSync(source);
|
|
53
|
+
const extension = path.extname(source).toLowerCase() || '.txt';
|
|
54
|
+
const snapshotRelative = `.cosmo/research/snapshots/${sourceId}${extension}`;
|
|
55
|
+
const destination = path.join(projectDir, snapshotRelative);
|
|
56
|
+
fs.mkdirSync(path.dirname(destination), { recursive: true });
|
|
57
|
+
fs.copyFileSync(source, destination);
|
|
58
|
+
const record = {
|
|
59
|
+
id: sourceId, type: kind, location, capturedAt: capturedAt ?? new Date().toISOString(),
|
|
60
|
+
snapshot: snapshotRelative, sha256: crypto.createHash('sha256').update(raw).digest('hex'),
|
|
61
|
+
};
|
|
62
|
+
writeJson(workbench.file, { ...workbench.data, sources: [...(workbench.data.sources ?? []).filter((item) => item.id !== sourceId), record].sort((a, b) => a.id.localeCompare(b.id)), updatedAt: new Date().toISOString() });
|
|
63
|
+
return { file: workbench.file, snapshot: destination, source: record };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function checkResearchWorkbench(projectDir) {
|
|
67
|
+
const { file, data } = readResearchWorkbench(projectDir);
|
|
68
|
+
const failures = [];
|
|
69
|
+
if (data.version !== 1) failures.push('version must be 1');
|
|
70
|
+
if (!data.scope?.niche?.trim()) failures.push('scope.niche must be completed');
|
|
71
|
+
if (data.scope?.geographyAppliedAfterSynthesis !== true) failures.push('geographyAppliedAfterSynthesis must be true');
|
|
72
|
+
if (!Array.isArray(data.tasks) || !data.tasks.length) failures.push('tasks must contain research recipes');
|
|
73
|
+
const sourceIds = new Set();
|
|
74
|
+
for (const source of data.sources ?? []) {
|
|
75
|
+
if (!source.id || sourceIds.has(source.id)) failures.push(`source id is missing or duplicated: ${source.id ?? 'unknown'}`);
|
|
76
|
+
sourceIds.add(source.id);
|
|
77
|
+
if (!source.location || !source.type || Number.isNaN(Date.parse(source.capturedAt))) failures.push(`source ${source.id ?? 'unknown'} lacks valid attribution, type, or date`);
|
|
78
|
+
const snapshot = path.resolve(projectDir, source.snapshot ?? '');
|
|
79
|
+
if (!source.snapshot || !snapshot.startsWith(`${path.resolve(projectDir)}${path.sep}`) || !fs.existsSync(snapshot)) failures.push(`source ${source.id ?? 'unknown'} snapshot is missing or unsafe`);
|
|
80
|
+
else if (crypto.createHash('sha256').update(fs.readFileSync(snapshot)).digest('hex') !== source.sha256) failures.push(`source ${source.id} snapshot hash drifted`);
|
|
81
|
+
}
|
|
82
|
+
for (const task of data.tasks ?? []) for (const sourceId of task.sourceIds ?? []) if (!sourceIds.has(sourceId)) failures.push(`task ${task.id} references unknown source ${sourceId}`);
|
|
83
|
+
if (failures.length) throw new ResearchError(`Research workbench is incomplete:\n${failures.map((item) => `- ${item}`).join('\n')}`);
|
|
84
|
+
return { file, data, summary: { tasks: data.tasks.length, sources: sourceIds.size, findings: data.findings?.length ?? 0, candidates: data.pageCandidates?.length ?? 0 } };
|
|
85
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { evaluateDelivery } from './delivery.mjs';
|
|
4
|
+
import { readIntelligence, readIntelligenceLock } from './intelligence.mjs';
|
|
5
|
+
import { readProject } from './project.mjs';
|
|
6
|
+
import { readWorkflowState } from './workflow.mjs';
|
|
7
|
+
|
|
8
|
+
function json(file) {
|
|
9
|
+
try { return JSON.parse(fs.readFileSync(file, 'utf8')); } catch { return null; }
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function collectProjectStatus(projectDir) {
|
|
13
|
+
const project = readProject(projectDir).data;
|
|
14
|
+
const workflow = readWorkflowState(projectDir, { required: false })?.data ?? null;
|
|
15
|
+
const intelligence = readIntelligence(projectDir);
|
|
16
|
+
const lock = readIntelligenceLock(projectDir).data;
|
|
17
|
+
const plan = json(path.join(projectDir, '.cosmo', 'build-plan.json'));
|
|
18
|
+
const progress = json(path.join(projectDir, '.cosmo', 'progress.json'));
|
|
19
|
+
const reportNames = ['integrity-check', 'content-check', 'intelligence-check', 'site-check', 'browser-check'];
|
|
20
|
+
const qa = Object.fromEntries(reportNames.map((name) => {
|
|
21
|
+
const report = json(path.join(projectDir, '.cosmo', 'reports', `${name}.json`));
|
|
22
|
+
return [name, report ? { passed: report.passed, checkedAt: report.checkedAt ?? report.auditedAt ?? null } : null];
|
|
23
|
+
}));
|
|
24
|
+
let release = null;
|
|
25
|
+
try {
|
|
26
|
+
const result = evaluateDelivery(projectDir);
|
|
27
|
+
release = { ready: result.ready, releaseId: result.releaseId, blocking: result.summary.blocking };
|
|
28
|
+
for (const report of result.reports) if (qa[report.name]) qa[report.name].status = report.status;
|
|
29
|
+
} catch (error) { release = { ready: false, error: error.message }; }
|
|
30
|
+
const deployment = json(path.join(projectDir, '.cosmo', 'deploy', 'config.json'));
|
|
31
|
+
const historyFile = path.join(projectDir, '.cosmo', 'deploy', 'history.jsonl');
|
|
32
|
+
let latestDeployment = null;
|
|
33
|
+
if (fs.existsSync(historyFile)) {
|
|
34
|
+
const records = fs.readFileSync(historyFile, 'utf8').trim().split('\n').filter(Boolean).flatMap((line) => { try { return [JSON.parse(line)]; } catch { return []; } });
|
|
35
|
+
latestDeployment = records.at(-1) ?? null;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
version: 1, project, workflow,
|
|
39
|
+
brandDiscovery: json(path.join(projectDir, '.cosmo', 'brand', 'discovery.json'))?.approved === true ? 'approved' : 'incomplete',
|
|
40
|
+
intelligence: { profile: intelligence.data.profile, packs: intelligence.data.packs, installedPackages: lock.packages.map((item) => ({ id: item.id, version: item.version })) },
|
|
41
|
+
plan: plan ? { version: plan.version, approved: plan.approved, pages: plan.pages?.length ?? 0 } : null,
|
|
42
|
+
generation: progress ? { complete: progress.complete, pages: Array.isArray(progress.pages) ? progress.pages.length : Object.keys(progress.pages ?? {}).length } : null,
|
|
43
|
+
qa, release,
|
|
44
|
+
deployment: deployment ? { provider: deployment.provider, latest: latestDeployment } : null,
|
|
45
|
+
};
|
|
46
|
+
}
|