@archangel70/cosmo 1.9.0 → 1.11.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 +17 -0
- package/README.md +32 -4
- package/docs/ARCHITECTURE.md +3 -0
- package/docs/DELIVERY.md +2 -1
- package/docs/ENTITY-MAP.md +87 -0
- package/docs/ROADMAP.md +9 -0
- package/package.json +5 -2
- package/packages/cli/bin/cosmo.mjs +97 -4
- package/packages/cli/lib/adoption.mjs +3 -0
- package/packages/cli/lib/audit.mjs +16 -0
- package/packages/cli/lib/browser-audit.mjs +1 -0
- package/packages/cli/lib/claude-plugin.mjs +2 -1
- package/packages/cli/lib/delivery.mjs +3 -2
- package/packages/cli/lib/entity-map.mjs +408 -0
- package/packages/cli/lib/integrity.mjs +6 -0
- package/packages/cli/lib/launcher.mjs +111 -0
- package/packages/cli/lib/project.mjs +2 -0
- package/packages/cli/lib/status.mjs +3 -1
- package/plugins/agent-skills/cosmo/.cosmo-agent.json +1 -1
- package/plugins/agent-skills/cosmo/SKILL.md +14 -3
- package/plugins/antigravity/cosmo.md +4 -1
- package/plugins/claude-code/cosmo/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/cosmo/agents/cosmo.md +47 -0
- package/plugins/claude-code/cosmo/skills/cosmo/SKILL.md +16 -4
- package/plugins/claude-code/cosmo/skills/cosmo-help/SKILL.md +20 -6
- package/templates/astro-site/.agents/skills/cosmo/SKILL.md +3 -1
- package/templates/astro-site/.cosmo/capabilities/registry.json +2 -1
- package/templates/astro-site/.cosmo/entities/candidates.json +5 -0
- package/templates/astro-site/.cosmo/entities/config.json +28 -0
- package/templates/astro-site/.env.example +6 -0
- package/templates/astro-site/AGENTS.md +3 -2
- package/templates/astro-site/CLAUDE.md +3 -2
- package/templates/astro-site/astro.config.mjs +5 -1
- package/templates/astro-site/package.json +1 -1
- package/templates/astro-site/src/layouts/BaseLayout.astro +3 -0
- package/templates/astro-site/src/pages/robots.txt.ts +2 -1
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import matter from 'gray-matter';
|
|
5
|
+
import { readProject, slugify, writeJson } from './project.mjs';
|
|
6
|
+
|
|
7
|
+
const SPEC = 'https://entitymap.org/spec/v1.0';
|
|
8
|
+
const TYPES = new Set(['Concept', 'ProprietaryTerm', 'Methodology', 'Metric', 'Taxonomy', 'Person', 'Organization', 'SoftwareProduct', 'PhysicalProduct', 'Service', 'Platform', 'Place', 'Event', 'Standard', 'Regulation']);
|
|
9
|
+
const PREDICATES = new Set(['INSTANCE_OF', 'PART_OF', 'INCLUDES', 'DEPENDS_ON', 'REQUIRES', 'MEASURES', 'PRODUCED_BY', 'REGULATED_BY', 'AUTHORED_BY', 'AFFILIATED_WITH', 'COVERS', 'RELATES_TO', 'PRECEDES', 'ENABLES', 'PREVENTS', 'CONFLICTS_WITH', 'DESCRIBED_BY', 'OFFERS', 'IMPROVES', 'DEGRADES', 'LEADS_TO', 'SUITED_FOR', 'TARGETS', 'ACHIEVES']);
|
|
10
|
+
const TIER_THREE = new Set(['IMPROVES', 'DEGRADES', 'LEADS_TO', 'SUITED_FOR', 'TARGETS', 'ACHIEVES']);
|
|
11
|
+
|
|
12
|
+
export const DEFAULT_ENTITY_MAP_CONFIG = {
|
|
13
|
+
version: 1,
|
|
14
|
+
enabled: false,
|
|
15
|
+
includeNoindex: false,
|
|
16
|
+
verificationStatus: 'generator-draft',
|
|
17
|
+
review: { reviewedBy: null, reviewedAt: null },
|
|
18
|
+
approvedMatches: [],
|
|
19
|
+
providers: {
|
|
20
|
+
wikidata: { enabled: true },
|
|
21
|
+
googleKnowledgeGraph: { enabled: false, apiKeyEnv: 'COSMO_GOOGLE_KG_API_KEY' },
|
|
22
|
+
googlePlaces: { enabled: false, apiKeyEnv: 'COSMO_GOOGLE_PLACES_API_KEY' },
|
|
23
|
+
textRazor: { enabled: false, apiKeyEnv: 'COSMO_TEXTRAZOR_API_KEY' },
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function readJson(file, label) {
|
|
28
|
+
if (!fs.existsSync(file)) throw new Error(`${label} not found: ${file}`);
|
|
29
|
+
try { return JSON.parse(fs.readFileSync(file, 'utf8')); }
|
|
30
|
+
catch { throw new Error(`${label} is not valid JSON: ${file}`); }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function configFile(projectDir) {
|
|
34
|
+
return path.join(projectDir, '.cosmo', 'entities', 'config.json');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function candidatesFile(projectDir) {
|
|
38
|
+
return path.join(projectDir, '.cosmo', 'entities', 'candidates.json');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function readEntityMapConfig(projectDir, { required = true } = {}) {
|
|
42
|
+
readProject(projectDir);
|
|
43
|
+
const file = configFile(projectDir);
|
|
44
|
+
if (!fs.existsSync(file)) {
|
|
45
|
+
if (!required) return { file, data: null };
|
|
46
|
+
throw new Error(`EntityMap configuration not found: ${file}. Run cosmo entity init first.`);
|
|
47
|
+
}
|
|
48
|
+
const data = readJson(file, 'EntityMap configuration');
|
|
49
|
+
if (data.version !== 1) throw new Error('EntityMap configuration version must be 1.');
|
|
50
|
+
if (typeof data.enabled !== 'boolean') throw new Error('EntityMap enabled must be true or false.');
|
|
51
|
+
if (!['generator-draft', 'self-declared'].includes(data.verificationStatus)) throw new Error('EntityMap verificationStatus must be generator-draft or self-declared.');
|
|
52
|
+
if (data.verificationStatus === 'self-declared' && (!data.review?.reviewedBy || !data.review?.reviewedAt)) throw new Error('A self-declared EntityMap requires an explicit human review record.');
|
|
53
|
+
if (!Array.isArray(data.approvedMatches)) throw new Error('EntityMap approvedMatches must be an array.');
|
|
54
|
+
return { file, data };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function updateCapability(projectDir, enabled) {
|
|
58
|
+
const file = path.join(projectDir, '.cosmo', 'capabilities', 'registry.json');
|
|
59
|
+
if (!fs.existsSync(file)) return;
|
|
60
|
+
const registry = readJson(file, 'Capability registry');
|
|
61
|
+
const capability = { id: 'entity-map', version: 1, status: enabled ? 'active' : 'optional', stages: ['brand', 'research', 'plan', 'generate', 'qa', 'release'] };
|
|
62
|
+
const index = registry.capabilities.findIndex((item) => item.id === capability.id);
|
|
63
|
+
if (index >= 0) registry.capabilities[index] = capability;
|
|
64
|
+
else registry.capabilities.push(capability);
|
|
65
|
+
writeJson(file, registry);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function scaffoldEntityMap(projectDir, { enabled = false, replace = false } = {}) {
|
|
69
|
+
readProject(projectDir);
|
|
70
|
+
const file = configFile(projectDir);
|
|
71
|
+
if (fs.existsSync(file) && !replace) {
|
|
72
|
+
const current = readEntityMapConfig(projectDir).data;
|
|
73
|
+
if (enabled && !current.enabled) {
|
|
74
|
+
current.enabled = true;
|
|
75
|
+
writeJson(file, current);
|
|
76
|
+
updateCapability(projectDir, true);
|
|
77
|
+
}
|
|
78
|
+
return { file, data: current, created: false };
|
|
79
|
+
}
|
|
80
|
+
const data = structuredClone(DEFAULT_ENTITY_MAP_CONFIG);
|
|
81
|
+
data.enabled = Boolean(enabled);
|
|
82
|
+
writeJson(file, data);
|
|
83
|
+
writeJson(candidatesFile(projectDir), { version: 1, updatedAt: null, candidates: [] });
|
|
84
|
+
updateCapability(projectDir, data.enabled);
|
|
85
|
+
return { file, data, created: true };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function walkMarkdown(directory) {
|
|
89
|
+
if (!fs.existsSync(directory)) return [];
|
|
90
|
+
return fs.readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
|
|
91
|
+
const file = path.join(directory, entry.name);
|
|
92
|
+
return entry.isDirectory() ? walkMarkdown(file) : file.endsWith('.md') ? [file] : [];
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function contentPages(projectDir, includeNoindex) {
|
|
97
|
+
const root = path.join(projectDir, 'src', 'content', 'pages');
|
|
98
|
+
return walkMarkdown(root).map((file) => {
|
|
99
|
+
const parsed = matter(fs.readFileSync(file, 'utf8'));
|
|
100
|
+
return { id: slugify(path.relative(root, file).replace(/\.md$/, '')), file, data: parsed.data };
|
|
101
|
+
}).filter((page) => page.data.path && page.data.title && page.data.description && (includeNoindex || page.data.indexability !== 'noindex'));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function strings(value, key = '') {
|
|
105
|
+
if (typeof value === 'string') return ['href', 'label', 'heading', 'eyebrow', 'title'].includes(key) ? [] : [value.trim()].filter(Boolean);
|
|
106
|
+
if (Array.isArray(value)) return value.flatMap((item) => strings(item, key));
|
|
107
|
+
if (value && typeof value === 'object') return Object.entries(value).flatMap(([childKey, item]) => strings(item, childKey));
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function chunkText(page) {
|
|
112
|
+
const candidates = [page.data.answer?.shortAnswer, ...strings(page.data.sections ?? []), page.data.description].filter((value) => typeof value === 'string' && value.trim());
|
|
113
|
+
const selected = candidates.find((value) => value.length >= 40 && value.length <= 600) ?? page.data.description;
|
|
114
|
+
return selected.trim();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function entityIdentity(page, publisher) {
|
|
118
|
+
if ((['home', 'standard'].includes(page.data.pageType) && page.data.path === '/') || page.data.schemaType === 'AboutPage') {
|
|
119
|
+
return { entityId: publisher.id, '@type': 'Organization', name: publisher.officialName, description: publisher.descriptions.short };
|
|
120
|
+
}
|
|
121
|
+
if (page.data.pageType === 'service') {
|
|
122
|
+
const name = page.data.service?.name ?? page.data.primaryTopic;
|
|
123
|
+
return { entityId: `service-${slugify(name)}`, '@type': 'Service', name, description: page.data.description };
|
|
124
|
+
}
|
|
125
|
+
if (page.data.pageType === 'location') {
|
|
126
|
+
const name = page.data.location?.name ?? page.data.primaryTopic;
|
|
127
|
+
return { entityId: `place-${slugify(name)}`, '@type': 'Place', name, description: page.data.description };
|
|
128
|
+
}
|
|
129
|
+
const name = page.data.primaryTopic || page.data.h1;
|
|
130
|
+
return { entityId: `topic-${slugify(name)}`, '@type': 'Concept', name, description: page.data.description };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function publicSameAs(config, entityId) {
|
|
134
|
+
const match = config.approvedMatches.find((item) => item.entityId === entityId && item.status === 'accepted' && /^https:\/\/(?:www\.)?(?:wikidata\.org\/wiki\/Q\d+|[^/]*wikipedia\.org\/wiki\/)/i.test(item.uri ?? ''));
|
|
135
|
+
return match?.uri ?? null;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function stableGenerated(previous, next) {
|
|
139
|
+
if (!previous) return new Date().toISOString();
|
|
140
|
+
const left = { ...previous, generated: null };
|
|
141
|
+
const right = { ...next, generated: null };
|
|
142
|
+
return JSON.stringify(left) === JSON.stringify(right) ? previous.generated : new Date().toISOString();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function compileEntityMap(projectDir) {
|
|
146
|
+
const project = readProject(projectDir).data;
|
|
147
|
+
const config = readEntityMapConfig(projectDir).data;
|
|
148
|
+
if (!config.enabled) throw new Error('EntityMap is disabled for this project. Run cosmo entity init . --enable.');
|
|
149
|
+
const publisher = readJson(path.join(projectDir, '.cosmo', 'brand', 'entity-canon.json'), 'Entity Canon');
|
|
150
|
+
const pages = contentPages(projectDir, config.includeNoindex === true);
|
|
151
|
+
const grouped = new Map();
|
|
152
|
+
for (const page of pages) {
|
|
153
|
+
const identity = entityIdentity(page, publisher);
|
|
154
|
+
const sourceUrl = new URL(page.data.path, project.site).toString();
|
|
155
|
+
const chunk = { chunkId: `c-${page.id}`, text: chunkText(page), sourceUrl, pageTitle: page.data.title, publisher: publisher.officialName };
|
|
156
|
+
if (page.data.editorial?.updatedAt || page.data.editorial?.publishedAt) chunk.retrieved = page.data.editorial.updatedAt ?? page.data.editorial.publishedAt;
|
|
157
|
+
const current = grouped.get(identity.entityId) ?? { ...identity, hasChunks: [] };
|
|
158
|
+
if (!current.hasChunks.some((item) => item.chunkId === chunk.chunkId) && current.hasChunks.length < 5) current.hasChunks.push(chunk);
|
|
159
|
+
grouped.set(identity.entityId, current);
|
|
160
|
+
}
|
|
161
|
+
const entities = [...grouped.values()];
|
|
162
|
+
const organization = entities.find((item) => item.entityId === publisher.id);
|
|
163
|
+
if (organization) {
|
|
164
|
+
const offered = entities.filter((item) => item['@type'] === 'Service');
|
|
165
|
+
if (offered.length) organization.relations = offered.map((item) => ({ predicate: 'OFFERS', targetId: item.entityId, targetName: item.name }));
|
|
166
|
+
}
|
|
167
|
+
for (const entity of entities) {
|
|
168
|
+
const sameAs = publicSameAs(config, entity.entityId);
|
|
169
|
+
if (sameAs) entity.sameAs = sameAs;
|
|
170
|
+
}
|
|
171
|
+
const rootSameAs = publicSameAs(config, publisher.id);
|
|
172
|
+
const map = {
|
|
173
|
+
version: '1.0', schema: SPEC,
|
|
174
|
+
publisher: { name: publisher.officialName, url: publisher.domain || project.site, ...(rootSameAs ? { sameAs: rootSameAs } : {}) },
|
|
175
|
+
generated: null,
|
|
176
|
+
entities,
|
|
177
|
+
profile: 'core',
|
|
178
|
+
verificationStatus: config.verificationStatus,
|
|
179
|
+
};
|
|
180
|
+
const output = path.join(projectDir, 'public', 'entitymap.json');
|
|
181
|
+
let previous = null;
|
|
182
|
+
try { previous = JSON.parse(fs.readFileSync(output, 'utf8')); } catch {}
|
|
183
|
+
map.generated = stableGenerated(previous, map);
|
|
184
|
+
return { map, config, pages };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function issue(findings, severity, code, message, fix) {
|
|
188
|
+
findings.push({ severity, code, message, fix });
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function evaluateEntityMap(projectDir, compiled = null) {
|
|
192
|
+
const config = readEntityMapConfig(projectDir, { required: false }).data;
|
|
193
|
+
if (!config || !config.enabled) return { version: 1, passed: true, enabled: false, checkedAt: new Date().toISOString(), summary: { entities: 0, chunks: 0, blocking: 0, warnings: 0 }, findings: [] };
|
|
194
|
+
const { map, pages } = compiled ?? compileEntityMap(projectDir);
|
|
195
|
+
const findings = [];
|
|
196
|
+
if (map.version !== '1.0' || map.schema !== SPEC) issue(findings, 'blocking', 'invalid-root', 'The EntityMap root version or schema is invalid.', 'Restore the v1.0 root contract.');
|
|
197
|
+
const generatedAt = Date.parse(map.generated);
|
|
198
|
+
if (!Number.isFinite(generatedAt)) issue(findings, 'blocking', 'generated-invalid', 'EntityMap generated must be an ISO 8601 timestamp.', 'Rebuild the EntityMap.');
|
|
199
|
+
else if (Date.now() - generatedAt > 30 * 24 * 60 * 60 * 1000) issue(findings, 'warning', 'entitymap-stale', 'The EntityMap is more than 30 days old.', 'Rebuild and review it against current site content.');
|
|
200
|
+
if (!map.publisher?.name || !map.publisher?.url) issue(findings, 'blocking', 'publisher-missing', 'Publisher name and URL are required.', 'Complete the Entity Canon before publishing.');
|
|
201
|
+
try { new URL(map.publisher.url); } catch { issue(findings, 'blocking', 'publisher-url-invalid', 'Publisher URL is invalid.', 'Set the production canonical URL.'); }
|
|
202
|
+
if (/example\.com/i.test(map.publisher?.url ?? '')) issue(findings, 'blocking', 'publisher-placeholder', 'Publisher URL is still a placeholder.', 'Set the production canonical URL.');
|
|
203
|
+
if (!map.entities.length) issue(findings, 'blocking', 'no-entities', 'No eligible public pages produced an entity.', 'Complete at least one public, indexable page or explicitly allow noindex sources.');
|
|
204
|
+
const ids = new Set();
|
|
205
|
+
for (const entity of map.entities) {
|
|
206
|
+
if (ids.has(entity.entityId)) issue(findings, 'blocking', 'duplicate-entity-id', `Duplicate entity id ${entity.entityId}.`, 'Give every entity a stable unique id.');
|
|
207
|
+
ids.add(entity.entityId);
|
|
208
|
+
if (!TYPES.has(entity['@type'])) issue(findings, 'blocking', 'invalid-entity-type', `${entity.entityId} has an unsupported type.`, 'Use an EntityMap v1.0 core type.');
|
|
209
|
+
if (!entity.name || !entity.description) issue(findings, 'blocking', 'entity-incomplete', `${entity.entityId} lacks a name or description.`, 'Complete its approved canonical identity.');
|
|
210
|
+
if (!Array.isArray(entity.hasChunks) || entity.hasChunks.length < 1 || entity.hasChunks.length > 5) issue(findings, 'blocking', 'chunk-count', `${entity.entityId} must have 1–5 chunks.`, 'Select concise passages from public source pages.');
|
|
211
|
+
for (const chunk of entity.hasChunks ?? []) {
|
|
212
|
+
if (!chunk.text || chunk.text.length > 600) issue(findings, 'blocking', 'chunk-length', `${chunk.chunkId} must contain 1–600 characters.`, 'Use a concise extractive passage.');
|
|
213
|
+
if (chunk.publisher !== map.publisher.name) issue(findings, 'blocking', 'publisher-mismatch', `${chunk.chunkId} publisher does not exactly match the root publisher.`, 'Use the canonical publisher name verbatim.');
|
|
214
|
+
if (!pages.some((page) => new URL(page.data.path, map.publisher.url).toString() === chunk.sourceUrl)) issue(findings, 'blocking', 'unknown-source', `${chunk.chunkId} does not resolve to an eligible project page.`, 'Use a canonical public page URL.');
|
|
215
|
+
}
|
|
216
|
+
if (entity['@type'] === 'Concept' && !entity.sameAs) issue(findings, 'warning', 'concept-sameas-missing', `${entity.name} has no approved Wikidata or Wikipedia match.`, 'Review an enrichment candidate; do not guess a match.');
|
|
217
|
+
for (const relation of entity.relations ?? []) {
|
|
218
|
+
if (!PREDICATES.has(relation.predicate)) issue(findings, 'blocking', 'invalid-predicate', `${entity.entityId} uses unknown predicate ${relation.predicate}.`, 'Use the v1.0 predicate vocabulary.');
|
|
219
|
+
if (!relation.targetName) issue(findings, 'blocking', 'relation-target-missing', `${entity.entityId} has a relation without targetName.`, 'Add the human-readable target name.');
|
|
220
|
+
if (relation.targetId && !ids.has(relation.targetId) && !map.entities.some((item) => item.entityId === relation.targetId)) issue(findings, 'blocking', 'relation-target-unknown', `${entity.entityId} points to unknown target ${relation.targetId}.`, 'Use a known internal entity id or an external target URI.');
|
|
221
|
+
if (TIER_THREE.has(relation.predicate) && !['declared', 'inferred'].includes(relation.confidence)) issue(findings, 'blocking', 'relation-confidence-missing', `${relation.predicate} requires confidence.`, 'Record declared or inferred confidence.');
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (map.verificationStatus === 'generator-draft') issue(findings, 'warning', 'human-review-needed', 'The generated EntityMap has not been explicitly reviewed.', 'Review it before changing status to self-declared.');
|
|
225
|
+
return {
|
|
226
|
+
version: 1, passed: findings.every((item) => item.severity !== 'blocking'), enabled: true, checkedAt: new Date().toISOString(),
|
|
227
|
+
summary: { entities: map.entities.length, chunks: map.entities.reduce((count, item) => count + item.hasChunks.length, 0), blocking: findings.filter((item) => item.severity === 'blocking').length, warnings: findings.filter((item) => item.severity === 'warning').length },
|
|
228
|
+
findings,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function escapeHtml(value) {
|
|
233
|
+
return String(value).replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"').replaceAll("'", ''');
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function renderEntityMapHtml(map) {
|
|
237
|
+
const entities = map.entities.map((entity) => {
|
|
238
|
+
const relations = (entity.relations ?? []).map((relation) => `<li>${escapeHtml(relation.predicate)} → ${relation.targetId ? `<a href="#${escapeHtml(relation.targetId)}">${escapeHtml(relation.targetName)}</a>` : escapeHtml(relation.targetName)}</li>`).join('');
|
|
239
|
+
const chunks = entity.hasChunks.map((chunk) => `<blockquote data-publisher="${escapeHtml(chunk.publisher)}"><p>${escapeHtml(chunk.text)}</p><cite><a href="${escapeHtml(chunk.sourceUrl)}">${escapeHtml(chunk.pageTitle)}</a> — published by ${escapeHtml(chunk.publisher)}</cite></blockquote>`).join('\n');
|
|
240
|
+
const schemaTypes = { Concept: 'DefinedTerm', ProprietaryTerm: 'DefinedTerm', Methodology: 'HowTo', Metric: 'PropertyValue', Taxonomy: 'DefinedTermSet', Platform: 'SoftwareApplication', Standard: 'CreativeWork', Regulation: 'Legislation' };
|
|
241
|
+
const schema = { '@context': 'https://schema.org', '@type': schemaTypes[entity['@type']] ?? entity['@type'], name: entity.name, description: entity.description, url: entity.hasChunks[0].sourceUrl, ...(entity.sameAs ? { sameAs: entity.sameAs } : {}) };
|
|
242
|
+
return `<article id="${escapeHtml(entity.entityId)}"><h2>${escapeHtml(entity.name)}</h2><p>${escapeHtml(entity.description)}</p>${relations ? `<ul>${relations}</ul>` : ''}${chunks}<script type="application/ld+json">${JSON.stringify(schema).replaceAll('<', '\\u003c')}</script></article>`;
|
|
243
|
+
}).join('\n');
|
|
244
|
+
return `<!doctype html>\n<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>EntityMap — ${escapeHtml(map.publisher.name)}</title><meta name="description" content="AI-readable entity and evidence index for ${escapeHtml(map.publisher.name)}."><link rel="canonical" href="${escapeHtml(new URL('/entitymap.html', map.publisher.url).toString())}"><link rel="alternate" type="application/json" href="/entitymap.json"><style>body{font:16px/1.6 system-ui,sans-serif;max-width:72rem;margin:auto;padding:2rem}article{border-top:1px solid #ccc;padding:1rem 0}blockquote{border-left:3px solid #777;margin:1rem 0;padding-left:1rem}cite{display:block}</style></head><body><main><h1>EntityMap</h1><p>Published by ${escapeHtml(map.publisher.name)}. Generated ${escapeHtml(map.generated)}.</p>${entities}</main></body></html>\n`;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export function writeEntityMap(projectDir) {
|
|
248
|
+
const jsonFile = path.join(projectDir, 'public', 'entitymap.json');
|
|
249
|
+
const htmlFile = path.join(projectDir, 'public', 'entitymap.html');
|
|
250
|
+
const distJsonFile = path.join(projectDir, 'dist', 'entitymap.json');
|
|
251
|
+
const distHtmlFile = path.join(projectDir, 'dist', 'entitymap.html');
|
|
252
|
+
const reportFile = path.join(projectDir, '.cosmo', 'reports', 'entity-check.json');
|
|
253
|
+
const config = readEntityMapConfig(projectDir, { required: false }).data;
|
|
254
|
+
if (!config) {
|
|
255
|
+
const report = evaluateEntityMap(projectDir);
|
|
256
|
+
writeJson(reportFile, report);
|
|
257
|
+
return { report, jsonFile: null, htmlFile: null, reportFile };
|
|
258
|
+
}
|
|
259
|
+
if (!config.enabled) {
|
|
260
|
+
for (const file of [jsonFile, htmlFile, distJsonFile, distHtmlFile]) if (fs.existsSync(file)) fs.rmSync(file);
|
|
261
|
+
const report = evaluateEntityMap(projectDir);
|
|
262
|
+
writeJson(reportFile, report);
|
|
263
|
+
return { report, jsonFile: null, htmlFile: null, reportFile };
|
|
264
|
+
}
|
|
265
|
+
const compiled = compileEntityMap(projectDir);
|
|
266
|
+
const report = evaluateEntityMap(projectDir, compiled);
|
|
267
|
+
if (!report.passed) {
|
|
268
|
+
writeJson(reportFile, report);
|
|
269
|
+
return { report, jsonFile: null, htmlFile: null, reportFile };
|
|
270
|
+
}
|
|
271
|
+
const json = `${JSON.stringify(compiled.map, null, 2)}\n`;
|
|
272
|
+
const html = renderEntityMapHtml(compiled.map);
|
|
273
|
+
fs.mkdirSync(path.dirname(jsonFile), { recursive: true });
|
|
274
|
+
if (!fs.existsSync(jsonFile) || fs.readFileSync(jsonFile, 'utf8') !== json) fs.writeFileSync(jsonFile, json);
|
|
275
|
+
if (!fs.existsSync(htmlFile) || fs.readFileSync(htmlFile, 'utf8') !== html) fs.writeFileSync(htmlFile, html);
|
|
276
|
+
if (fs.existsSync(path.join(projectDir, 'dist'))) {
|
|
277
|
+
if (!fs.existsSync(distJsonFile) || fs.readFileSync(distJsonFile, 'utf8') !== json) fs.writeFileSync(distJsonFile, json);
|
|
278
|
+
if (!fs.existsSync(distHtmlFile) || fs.readFileSync(distHtmlFile, 'utf8') !== html) fs.writeFileSync(distHtmlFile, html);
|
|
279
|
+
}
|
|
280
|
+
writeJson(reportFile, report);
|
|
281
|
+
return { report, jsonFile, htmlFile, reportFile };
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function candidateId(value) {
|
|
285
|
+
return `candidate-${crypto.createHash('sha256').update([value.provider, value.entityId, value.externalId, value.uri].join('|')).digest('hex').slice(0, 16)}`;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function entitySubjects(projectDir) {
|
|
289
|
+
const publisher = readJson(path.join(projectDir, '.cosmo', 'brand', 'entity-canon.json'), 'Entity Canon');
|
|
290
|
+
const config = readEntityMapConfig(projectDir).data;
|
|
291
|
+
const pages = contentPages(projectDir, config.includeNoindex === true);
|
|
292
|
+
const subjects = new Map([[publisher.id, { entityId: publisher.id, name: publisher.officialName, type: 'Organization' }]]);
|
|
293
|
+
for (const page of pages) {
|
|
294
|
+
const identity = entityIdentity(page, publisher);
|
|
295
|
+
subjects.set(identity.entityId, { entityId: identity.entityId, name: identity.name, type: identity['@type'] });
|
|
296
|
+
}
|
|
297
|
+
return { subjects: [...subjects.values()], pages, config };
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
async function enrichWikidata(subjects, fetchImpl) {
|
|
301
|
+
const values = [];
|
|
302
|
+
for (const subject of subjects) {
|
|
303
|
+
const url = new URL('https://www.wikidata.org/w/api.php');
|
|
304
|
+
for (const [key, value] of Object.entries({ action: 'wbsearchentities', search: subject.name, language: 'en', uselang: 'en', format: 'json', limit: '5', origin: '*' })) url.searchParams.set(key, value);
|
|
305
|
+
const response = await fetchImpl(url, { headers: { 'user-agent': 'Cosmo EntityMap Builder/1.0' } });
|
|
306
|
+
if (!response.ok) throw new Error(`Wikidata returned HTTP ${response.status}.`);
|
|
307
|
+
const body = await response.json();
|
|
308
|
+
for (const item of body.search ?? []) values.push({ provider: 'wikidata', entityId: subject.entityId, matchedName: item.label, externalId: item.id, uri: item.concepturi ?? `https://www.wikidata.org/wiki/${item.id}`, description: item.description ?? '', score: null });
|
|
309
|
+
}
|
|
310
|
+
return values;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
async function enrichGoogleKnowledgeGraph(subjects, key, fetchImpl) {
|
|
314
|
+
const values = [];
|
|
315
|
+
for (const subject of subjects) {
|
|
316
|
+
const url = new URL('https://kgsearch.googleapis.com/v1/entities:search');
|
|
317
|
+
for (const [name, value] of Object.entries({ query: subject.name, limit: '5', indent: 'false', key })) url.searchParams.set(name, value);
|
|
318
|
+
const response = await fetchImpl(url);
|
|
319
|
+
if (!response.ok) throw new Error(`Google Knowledge Graph returned HTTP ${response.status}.`);
|
|
320
|
+
const body = await response.json();
|
|
321
|
+
for (const item of body.itemListElement ?? []) {
|
|
322
|
+
const result = item.result ?? {};
|
|
323
|
+
values.push({ provider: 'googleKnowledgeGraph', entityId: subject.entityId, matchedName: result.name, externalId: result['@id'], uri: result.detailedDescription?.url ?? result.url ?? null, description: result.description ?? '', score: item.resultScore ?? null });
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return values;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
async function enrichGooglePlaces(subjects, key, fetchImpl) {
|
|
330
|
+
const values = [];
|
|
331
|
+
for (const subject of subjects.filter((item) => ['Organization', 'Place'].includes(item.type))) {
|
|
332
|
+
const response = await fetchImpl('https://places.googleapis.com/v1/places:searchText', { method: 'POST', headers: { 'content-type': 'application/json', 'X-Goog-Api-Key': key, 'X-Goog-FieldMask': 'places.id,places.displayName,places.formattedAddress,places.primaryType,places.googleMapsUri,places.websiteUri' }, body: JSON.stringify({ textQuery: subject.name }) });
|
|
333
|
+
if (!response.ok) throw new Error(`Google Places returned HTTP ${response.status}.`);
|
|
334
|
+
const body = await response.json();
|
|
335
|
+
for (const item of body.places ?? []) values.push({ provider: 'googlePlaces', entityId: subject.entityId, matchedName: item.displayName?.text, externalId: item.id, uri: item.googleMapsUri ?? item.websiteUri ?? null, description: [item.primaryType, item.formattedAddress].filter(Boolean).join(' — '), score: null });
|
|
336
|
+
}
|
|
337
|
+
return values;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
async function enrichTextRazor(subjects, pages, key, fetchImpl) {
|
|
341
|
+
const text = pages.flatMap((page) => [page.data.title, page.data.description, ...strings(page.data.sections ?? [])]).join('\n').slice(0, 200000);
|
|
342
|
+
const body = new URLSearchParams({ text, extractors: 'entities,topics' });
|
|
343
|
+
const response = await fetchImpl('https://api.textrazor.com/', { method: 'POST', headers: { 'x-textrazor-key': key, 'content-type': 'application/x-www-form-urlencoded' }, body });
|
|
344
|
+
if (!response.ok) throw new Error(`TextRazor returned HTTP ${response.status}.`);
|
|
345
|
+
const result = (await response.json()).response ?? {};
|
|
346
|
+
const values = [];
|
|
347
|
+
for (const item of [...(result.entities ?? []), ...(result.topics ?? [])]) {
|
|
348
|
+
const name = item.entityId ?? item.label ?? item.matchedText;
|
|
349
|
+
if (!name) continue;
|
|
350
|
+
const subject = subjects.find((candidate) => candidate.name.toLowerCase() === String(item.matchedText ?? name).toLowerCase());
|
|
351
|
+
values.push({ provider: 'textRazor', entityId: subject?.entityId ?? `topic-${slugify(name)}`, matchedName: name, externalId: item.wikidataId ?? item.entityId ?? String(item.id ?? name), uri: item.wikidataId ? `https://www.wikidata.org/wiki/${item.wikidataId}` : item.wikiLink ?? null, description: '', score: item.relevanceScore ?? item.score ?? item.confidenceScore ?? null });
|
|
352
|
+
}
|
|
353
|
+
return values;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
export async function enrichEntityMap(projectDir, provider, { fetchImpl = fetch } = {}) {
|
|
357
|
+
const { subjects, pages, config } = entitySubjects(projectDir);
|
|
358
|
+
const providerConfig = config.providers?.[provider];
|
|
359
|
+
if (!providerConfig) throw new Error(`Unknown EntityMap provider: ${provider}`);
|
|
360
|
+
if (!providerConfig.enabled) throw new Error(`${provider} is disabled in .cosmo/entities/config.json.`);
|
|
361
|
+
const key = providerConfig.apiKeyEnv ? process.env[providerConfig.apiKeyEnv] : null;
|
|
362
|
+
if (providerConfig.apiKeyEnv && !key) throw new Error(`Missing ${providerConfig.apiKeyEnv}. Put it in a local environment file; never commit it.`);
|
|
363
|
+
let raw = [];
|
|
364
|
+
if (provider === 'wikidata') raw = await enrichWikidata(subjects, fetchImpl);
|
|
365
|
+
if (provider === 'googleKnowledgeGraph') raw = await enrichGoogleKnowledgeGraph(subjects, key, fetchImpl);
|
|
366
|
+
if (provider === 'googlePlaces') raw = await enrichGooglePlaces(subjects, key, fetchImpl);
|
|
367
|
+
if (provider === 'textRazor') raw = await enrichTextRazor(subjects, pages, key, fetchImpl);
|
|
368
|
+
const file = candidatesFile(projectDir);
|
|
369
|
+
const previous = fs.existsSync(file) ? readJson(file, 'EntityMap candidates') : { candidates: [] };
|
|
370
|
+
const statuses = new Map((previous.candidates ?? []).map((item) => [item.id, { status: item.status, reviewedBy: item.reviewedBy, reviewedAt: item.reviewedAt }]));
|
|
371
|
+
const retrievedAt = new Date().toISOString();
|
|
372
|
+
const additions = raw.filter((item) => item.matchedName && item.externalId).map((item) => {
|
|
373
|
+
const candidate = { ...item, id: candidateId(item), status: 'needs-review', retrievedAt };
|
|
374
|
+
return { ...candidate, ...(statuses.get(candidate.id) ?? {}) };
|
|
375
|
+
});
|
|
376
|
+
const retained = (previous.candidates ?? []).filter((item) => item.provider !== provider);
|
|
377
|
+
const data = { version: 1, updatedAt: retrievedAt, candidates: [...retained, ...additions] };
|
|
378
|
+
writeJson(file, data);
|
|
379
|
+
return { file, provider, candidates: additions };
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export function acceptEntityCandidate(projectDir, id, reviewedBy) {
|
|
383
|
+
if (!reviewedBy) throw new Error('Candidate acceptance requires --by with the reviewer name.');
|
|
384
|
+
const file = candidatesFile(projectDir);
|
|
385
|
+
const data = readJson(file, 'EntityMap candidates');
|
|
386
|
+
const candidate = data.candidates.find((item) => item.id === id);
|
|
387
|
+
if (!candidate) throw new Error(`Unknown EntityMap candidate: ${id}`);
|
|
388
|
+
const reviewedAt = new Date().toISOString();
|
|
389
|
+
Object.assign(candidate, { status: 'accepted', reviewedBy, reviewedAt });
|
|
390
|
+
writeJson(file, data);
|
|
391
|
+
const config = readEntityMapConfig(projectDir).data;
|
|
392
|
+
config.approvedMatches = config.approvedMatches.filter((item) => !(item.entityId === candidate.entityId && item.provider === candidate.provider));
|
|
393
|
+
config.approvedMatches.push({ entityId: candidate.entityId, provider: candidate.provider, externalId: candidate.externalId, uri: candidate.uri, status: 'accepted', reviewedBy, reviewedAt });
|
|
394
|
+
writeJson(configFile(projectDir), config);
|
|
395
|
+
return candidate;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
export function approveEntityMap(projectDir, reviewedBy) {
|
|
399
|
+
if (!reviewedBy) throw new Error('EntityMap approval requires --by with the reviewer name.');
|
|
400
|
+
const record = readEntityMapConfig(projectDir);
|
|
401
|
+
const report = evaluateEntityMap(projectDir);
|
|
402
|
+
if (!report.passed) throw new Error('EntityMap cannot be approved while blocking findings remain.');
|
|
403
|
+
record.data.verificationStatus = 'self-declared';
|
|
404
|
+
record.data.review = { reviewedBy, reviewedAt: new Date().toISOString() };
|
|
405
|
+
writeJson(record.file, record.data);
|
|
406
|
+
writeEntityMap(projectDir);
|
|
407
|
+
return record.data.review;
|
|
408
|
+
}
|
|
@@ -278,6 +278,7 @@ export function scaffoldIntegrity(projectDir, { replace = false } = {}) {
|
|
|
278
278
|
{ id: 'bounded-repair', version: 1, status: 'active', stages: ['generate', 'qa'] },
|
|
279
279
|
{ id: 'semantic-content-qa', version: 1, status: 'active', stages: ['qa'] },
|
|
280
280
|
{ id: 'noncommodity-gate', version: 1, status: 'active', stages: ['generate', 'qa'] },
|
|
281
|
+
{ id: 'entity-map', version: 1, status: 'optional', stages: ['brand', 'research', 'plan', 'generate', 'qa', 'release'] },
|
|
281
282
|
],
|
|
282
283
|
}],
|
|
283
284
|
['intelligence/selection.json', { version: 1, profile: 'lean', packs: [] }],
|
|
@@ -303,6 +304,11 @@ export function scaffoldIntegrity(projectDir, { replace = false } = {}) {
|
|
|
303
304
|
sentenceStyle: [], preferredVocabulary: [], bannedVocabulary: [], examples: [], appliesTo: ['website'], exceptions: [],
|
|
304
305
|
}],
|
|
305
306
|
['evidence.json', { version: 1, entityId, claims: [], proofs: [] }],
|
|
307
|
+
['entities/config.json', {
|
|
308
|
+
version: 1, enabled: false, includeNoindex: false, verificationStatus: 'generator-draft', review: { reviewedBy: null, reviewedAt: null }, approvedMatches: [],
|
|
309
|
+
providers: { wikidata: { enabled: true }, googleKnowledgeGraph: { enabled: false, apiKeyEnv: 'COSMO_GOOGLE_KG_API_KEY' }, googlePlaces: { enabled: false, apiKeyEnv: 'COSMO_GOOGLE_PLACES_API_KEY' }, textRazor: { enabled: false, apiKeyEnv: 'COSMO_TEXTRAZOR_API_KEY' } },
|
|
310
|
+
}],
|
|
311
|
+
['entities/candidates.json', { version: 1, updatedAt: null, candidates: [] }],
|
|
306
312
|
];
|
|
307
313
|
const files = [];
|
|
308
314
|
for (const [relative, value] of definitions) {
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { loadWorkflow, readWorkflowState } from './workflow.mjs';
|
|
4
|
+
|
|
5
|
+
const FRIENDLY_IGNORED_FILES = new Set(['.DS_Store', '.git']);
|
|
6
|
+
|
|
7
|
+
function hasAstroDependency(projectDir) {
|
|
8
|
+
const packageFile = path.join(projectDir, 'package.json');
|
|
9
|
+
if (!fs.existsSync(packageFile)) return false;
|
|
10
|
+
try {
|
|
11
|
+
const packageJson = JSON.parse(fs.readFileSync(packageFile, 'utf8'));
|
|
12
|
+
return Boolean(packageJson.dependencies?.astro || packageJson.devDependencies?.astro);
|
|
13
|
+
} catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function hasAstroConfig(projectDir) {
|
|
19
|
+
if (!fs.existsSync(projectDir)) return false;
|
|
20
|
+
return fs.readdirSync(projectDir).some((entry) => /^astro\.config\.(?:js|mjs|cjs|ts)$/.test(entry));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function classifyWorkspace(projectDir) {
|
|
24
|
+
const target = path.resolve(projectDir);
|
|
25
|
+
if (fs.existsSync(path.join(target, '.cosmo', 'project.json'))) return 'cosmo';
|
|
26
|
+
if (hasAstroDependency(target) || hasAstroConfig(target)) return 'astro';
|
|
27
|
+
if (!fs.existsSync(target)) return 'missing';
|
|
28
|
+
const visibleEntries = fs.readdirSync(target).filter((entry) => !FRIENDLY_IGNORED_FILES.has(entry));
|
|
29
|
+
return visibleEntries.length === 0 ? 'empty' : 'other';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function currentCosmoStep(projectDir) {
|
|
33
|
+
const stateRecord = readWorkflowState(projectDir, { required: false });
|
|
34
|
+
if (!stateRecord) {
|
|
35
|
+
return {
|
|
36
|
+
found: 'I found a Cosmo site that has not started its guided workflow yet.',
|
|
37
|
+
next: 'Tell your assistant: “Start the guided Cosmo workflow for this site.”',
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const state = stateRecord.data;
|
|
42
|
+
if (state.status === 'complete') {
|
|
43
|
+
return {
|
|
44
|
+
found: 'I found a completed Cosmo build.',
|
|
45
|
+
next: 'Tell your assistant what you want to change, or ask: “Check whether this site is ready to publish.”',
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const workflow = loadWorkflow(projectDir, state.workflowId).data;
|
|
50
|
+
const stage = workflow.stages.find((item) => item.id === state.currentStage);
|
|
51
|
+
const position = workflow.stages.findIndex((item) => item.id === state.currentStage) + 1;
|
|
52
|
+
const status = state.stages[state.currentStage]?.status;
|
|
53
|
+
if (status === 'awaiting_approval') {
|
|
54
|
+
return {
|
|
55
|
+
found: `I found an active build at step ${position} of ${workflow.stages.length}: ${stage.title}.`,
|
|
56
|
+
next: `Review the ${stage.title.toLowerCase()} work with your assistant. Ask for changes, or approve it so Cosmo can continue.`,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
found: `I found an active build at step ${position} of ${workflow.stages.length}: ${stage.title}.`,
|
|
61
|
+
next: `Tell your assistant: “Continue my Cosmo site.” It will pick up ${stage.title.toLowerCase()} from the saved project.`,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function launcherGuide(projectDir = process.cwd(), version = 'unknown') {
|
|
66
|
+
const target = path.resolve(projectDir);
|
|
67
|
+
const kind = classifyWorkspace(target);
|
|
68
|
+
let context;
|
|
69
|
+
|
|
70
|
+
if (kind === 'cosmo') context = currentCosmoStep(target);
|
|
71
|
+
if (kind === 'astro') context = {
|
|
72
|
+
found: 'I found an existing Astro website in this folder.',
|
|
73
|
+
next: 'Tell your assistant: “Use Cosmo to improve this existing Astro site.” Cosmo will inspect it before changing anything.',
|
|
74
|
+
};
|
|
75
|
+
if (kind === 'empty') context = {
|
|
76
|
+
found: 'This empty folder is ready for a new website.',
|
|
77
|
+
next: 'Tell your assistant: “Use Cosmo to build a new website here.” It will begin by asking about the business and its customers.',
|
|
78
|
+
};
|
|
79
|
+
if (kind === 'missing') context = {
|
|
80
|
+
found: 'This folder does not exist yet.',
|
|
81
|
+
next: 'Open or create the folder where you want the website, then ask your assistant to use Cosmo.',
|
|
82
|
+
};
|
|
83
|
+
if (kind === 'other') context = {
|
|
84
|
+
found: 'This folder contains files, but it is not currently a Cosmo or Astro website.',
|
|
85
|
+
next: 'Tell your assistant what the files are, or ask it to create a new Cosmo website in a separate folder.',
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
return `
|
|
89
|
+
Cosmo ${version} — your guided Astro website builder
|
|
90
|
+
|
|
91
|
+
You do not need to learn Cosmo commands or decide which tool comes next.
|
|
92
|
+
Your AI assistant will guide the work, save progress, and stop when it needs your approval.
|
|
93
|
+
|
|
94
|
+
${context.found}
|
|
95
|
+
|
|
96
|
+
NEXT STEP
|
|
97
|
+
${context.next}
|
|
98
|
+
|
|
99
|
+
THE WEBSITE JOURNEY
|
|
100
|
+
1. Understand the business, audience, goals, and real-world evidence
|
|
101
|
+
2. Define the brand, positioning, voice, and creative direction
|
|
102
|
+
3. Explore and approve a distinctive visual design
|
|
103
|
+
4. Plan the pages and write evidence-grounded copy
|
|
104
|
+
5. Build the Astro website one approved pattern at a time
|
|
105
|
+
6. Test accessibility, content, SEO, performance, and release readiness
|
|
106
|
+
7. Preview, approve, and deploy
|
|
107
|
+
|
|
108
|
+
At any time, simply say “Cosmo” or “Continue my Cosmo site.”
|
|
109
|
+
For the developer command reference only, run: cosmo help
|
|
110
|
+
`;
|
|
111
|
+
}
|
|
@@ -73,6 +73,8 @@ export function copyStarter(templateDir, targetDir) {
|
|
|
73
73
|
|| portable === '.cosmo/project.json'
|
|
74
74
|
|| portable === '.cosmo/build-plan.json'
|
|
75
75
|
|| portable === '.cosmo/evidence.json'
|
|
76
|
+
|| portable === '.cosmo/entities'
|
|
77
|
+
|| portable.startsWith('.cosmo/entities/')
|
|
76
78
|
|| portable === '.cosmo/brand'
|
|
77
79
|
|| portable.startsWith('.cosmo/brand/')
|
|
78
80
|
|| portable === '.cosmo/copy'
|
|
@@ -16,7 +16,8 @@ export function collectProjectStatus(projectDir) {
|
|
|
16
16
|
const lock = readIntelligenceLock(projectDir).data;
|
|
17
17
|
const plan = json(path.join(projectDir, '.cosmo', 'build-plan.json'));
|
|
18
18
|
const progress = json(path.join(projectDir, '.cosmo', 'progress.json'));
|
|
19
|
-
const
|
|
19
|
+
const entityMapEnabled = json(path.join(projectDir, '.cosmo', 'entities', 'config.json'))?.enabled === true;
|
|
20
|
+
const reportNames = ['integrity-check', 'content-check', 'intelligence-check', 'site-check', 'browser-check', ...(fs.existsSync(path.join(projectDir, '.cosmo', 'copy', 'strategy.json')) ? ['copy-check'] : []), ...(entityMapEnabled ? ['entity-check'] : [])];
|
|
20
21
|
const qa = Object.fromEntries(reportNames.map((name) => {
|
|
21
22
|
const report = json(path.join(projectDir, '.cosmo', 'reports', `${name}.json`));
|
|
22
23
|
return [name, report ? { passed: report.passed, checkedAt: report.checkedAt ?? report.auditedAt ?? null } : null];
|
|
@@ -40,6 +41,7 @@ export function collectProjectStatus(projectDir) {
|
|
|
40
41
|
intelligence: { profile: intelligence.data.profile, packs: intelligence.data.packs, installedPackages: lock.packages.map((item) => ({ id: item.id, version: item.version })) },
|
|
41
42
|
plan: plan ? { version: plan.version, approved: plan.approved, pages: plan.pages?.length ?? 0 } : null,
|
|
42
43
|
generation: progress ? { complete: progress.complete, pages: Array.isArray(progress.pages) ? progress.pages.length : Object.keys(progress.pages ?? {}).length } : null,
|
|
44
|
+
entityMap: { enabled: entityMapEnabled },
|
|
43
45
|
qa, release,
|
|
44
46
|
deployment: deployment ? { provider: deployment.provider, latest: latestDeployment } : null,
|
|
45
47
|
};
|
|
@@ -17,6 +17,17 @@ Act as the conversational front door to Cosmo. The user should not need to know
|
|
|
17
17
|
- Explain the immediate decision in plain language instead of exposing the whole internal pipeline.
|
|
18
18
|
- Treat design as an independent creative problem. Claude Design may be used when available, but is never required; another design authority or the current agent can satisfy the same repository-owned contract.
|
|
19
19
|
|
|
20
|
+
## First response to `cosmo`
|
|
21
|
+
|
|
22
|
+
When the user's request is only `cosmo`, do not execute bare `cosmo` and paste its developer command list. Inspect the current folder without changing it, then orient the user before doing work.
|
|
23
|
+
|
|
24
|
+
- Empty folder: explain that Cosmo will guide discovery, brand, design, copy, Astro development, QA, and launch. Ask only for the business/project name and what it does.
|
|
25
|
+
- Existing Cosmo project: recover the saved stage, summarize completed approvals, and state the single next decision or action.
|
|
26
|
+
- Existing Astro site: explain that Cosmo can inspect and adopt it without replacing working source, then offer that inspection.
|
|
27
|
+
- Other non-empty folder: explain that a new website needs a separate child folder and ask what it should be called.
|
|
28
|
+
|
|
29
|
+
Use a progress line at every transition: `Step N of 7 — <plain-language phase>`, followed by what was completed and what happens next. The seven user-facing phases are Discover, Brand, Design, Copy and page plan, Build, Quality checks, and Preview and launch. Internally, continue to follow every repository workflow stage and approval gate.
|
|
30
|
+
|
|
20
31
|
## Verify and classify
|
|
21
32
|
|
|
22
33
|
Run `cosmo --version`, then inspect the current directory without changing it:
|
|
@@ -41,7 +52,7 @@ Inventory the existing Astro configuration, routes, content, source, public file
|
|
|
41
52
|
|
|
42
53
|
## Create a new site
|
|
43
54
|
|
|
44
|
-
Collect the target, brand, known URL, business, audience, goal, genuine location scope, justified page count, capability profile, and
|
|
55
|
+
Collect the target, brand, known URL, business, audience, goal, genuine location scope, justified page count, capability profile, design mode, and whether the user wants an AI-readable EntityMap. Explain that EntityMap is optional, uses no paid API by default, and requires human review; pass `--entity-map` during initialization when selected. Recommend `growth-site` for a typical lead-generation site; use a specialist profile only when the project warrants it. Confirm the summary before initialization, then run `cosmo init`, install dependencies, diagnose the project, start the workflow, and conduct brand and copy discovery.
|
|
45
56
|
|
|
46
57
|
Do not mark discovery, strategy, plan, copy briefs, design, or final review approved until the user explicitly approves the presented artifact. Use Cosmo workflow commands to record submission and approval.
|
|
47
58
|
|
|
@@ -57,7 +68,7 @@ For every stage:
|
|
|
57
68
|
|
|
58
69
|
Before page writing, run `cosmo copy guide <page-id> .`. Keep supplied, observed, inferred, and unknown information distinct. Do not imitate living writers, reproduce source language, fabricate reader psychology, or make unsupported attacks on alternatives. Explore at least three genuinely different visual directions and store the approved choice in `DESIGN-DIRECTION.md`, tokens, components, and Cosmo design artifacts.
|
|
59
70
|
|
|
60
|
-
Advance generation one state at a time. After two failed repair cycles, leave the page for human review. For release, run the build plus Copy Studio, content, intelligence, integrity, static, browser, and release checks. Deploy production only when the exact current release reports READY.
|
|
71
|
+
Advance generation one state at a time. After two failed repair cycles, leave the page for human review. For release, run the build plus Copy Studio, content, intelligence, integrity, EntityMap when enabled, static, browser, and release checks. Deploy production only when the exact current release reports READY.
|
|
61
72
|
|
|
62
73
|
## Switching agents
|
|
63
74
|
|
|
@@ -65,4 +76,4 @@ Any supported agent may continue the project. Before switching, run appropriate
|
|
|
65
76
|
|
|
66
77
|
## Help
|
|
67
78
|
|
|
68
|
-
When asked what Cosmo can do,
|
|
79
|
+
When asked what Cosmo can do, lead with four choices: build a new website, continue a Cosmo website, improve an existing Astro website, or review/publish a website. Show the simple journey `Discover → Brand → Design → Copy and page plan → Build → Quality checks → Preview and launch`. Mention advanced capabilities only if relevant or requested, and end with one clear question.
|