@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,901 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import http from 'node:http';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { auditDist, writeAuditReport } from '../lib/audit.mjs';
|
|
7
|
+
import { auditBrowser, writeBrowserReport } from '../lib/browser-audit.mjs';
|
|
8
|
+
import { auditContent, writeContentReport } from '../lib/content-audit.mjs';
|
|
9
|
+
import { checkBrandDiscovery, scaffoldBrandDiscovery } from '../lib/brand.mjs';
|
|
10
|
+
import { adoptAstroProject } from '../lib/adoption.mjs';
|
|
11
|
+
import { claudePluginStatus, installClaudePlugin, uninstallClaudePlugin } from '../lib/claude-plugin.mjs';
|
|
12
|
+
import { evaluateDelivery, readDelivery, writeDeliveryReport } from '../lib/delivery.mjs';
|
|
13
|
+
import { diagnoseProject } from '../lib/doctor.mjs';
|
|
14
|
+
import { configureDeployment, deployProject, readDeploymentConfig, readDeploymentHistory } from '../lib/deployment.mjs';
|
|
15
|
+
import { evaluateIntelligence, writeIntelligenceReport } from '../lib/intelligence-audit.mjs';
|
|
16
|
+
import { createHandoff, readHandoff } from '../lib/handoff.mjs';
|
|
17
|
+
import { checkIntegrity, createPageBrief, scaffoldIntegrity } from '../lib/integrity.mjs';
|
|
18
|
+
import {
|
|
19
|
+
addIntelligencePack,
|
|
20
|
+
applyIntelligenceProfile,
|
|
21
|
+
intelligenceCatalog,
|
|
22
|
+
importIntelligencePack,
|
|
23
|
+
readIntelligence,
|
|
24
|
+
readIntelligenceLock,
|
|
25
|
+
removeIntelligencePack,
|
|
26
|
+
scaffoldIntelligenceArtifacts,
|
|
27
|
+
} from '../lib/intelligence.mjs';
|
|
28
|
+
import { scaffoldPageWorkspace } from '../lib/page-work.mjs';
|
|
29
|
+
import {
|
|
30
|
+
copyStarter,
|
|
31
|
+
ensureEmptyDirectory,
|
|
32
|
+
parseOptions,
|
|
33
|
+
readProject,
|
|
34
|
+
replaceInTextFiles,
|
|
35
|
+
slugify,
|
|
36
|
+
writeJson,
|
|
37
|
+
} from '../lib/project.mjs';
|
|
38
|
+
import { run } from '../lib/process.mjs';
|
|
39
|
+
import { captureResearchSource, checkResearchWorkbench, scaffoldResearchWorkbench } from '../lib/research.mjs';
|
|
40
|
+
import { collectProjectStatus } from '../lib/status.mjs';
|
|
41
|
+
import { planSummary, readPlan } from '../lib/plan.mjs';
|
|
42
|
+
import {
|
|
43
|
+
advancePage,
|
|
44
|
+
completePage,
|
|
45
|
+
failPage,
|
|
46
|
+
nextPage,
|
|
47
|
+
readProgress,
|
|
48
|
+
recordRepair,
|
|
49
|
+
retryPage,
|
|
50
|
+
startGeneration,
|
|
51
|
+
} from '../lib/generation.mjs';
|
|
52
|
+
import {
|
|
53
|
+
approveStage,
|
|
54
|
+
importWorkflow,
|
|
55
|
+
listWorkflows,
|
|
56
|
+
readWorkflowState,
|
|
57
|
+
startWorkflow,
|
|
58
|
+
submitStage,
|
|
59
|
+
workflowSummary,
|
|
60
|
+
} from '../lib/workflow.mjs';
|
|
61
|
+
|
|
62
|
+
const VERSION = '1.7.0';
|
|
63
|
+
const cliDirectory = path.dirname(fileURLToPath(import.meta.url));
|
|
64
|
+
const templateDirectory = path.resolve(cliDirectory, '../../../templates/astro-site');
|
|
65
|
+
const [command = 'help', ...rawArgs] = process.argv.slice(2);
|
|
66
|
+
|
|
67
|
+
function projectDirectory(value = '.') {
|
|
68
|
+
return path.resolve(process.cwd(), value);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function help() {
|
|
72
|
+
console.log(`
|
|
73
|
+
Cosmo ${VERSION} — local-first Astro site builder
|
|
74
|
+
|
|
75
|
+
Commands
|
|
76
|
+
cosmo setup
|
|
77
|
+
cosmo init [directory] [--name slug] [--brand name] [--site url] [--profile id]
|
|
78
|
+
cosmo adopt [directory] [--name slug] [--brand name] [--site url] [--profile id] [--design-mode mode]
|
|
79
|
+
cosmo claude install [--replace]
|
|
80
|
+
cosmo claude status
|
|
81
|
+
cosmo claude uninstall
|
|
82
|
+
cosmo dev [directory]
|
|
83
|
+
cosmo build [directory]
|
|
84
|
+
cosmo check [directory] [--no-build]
|
|
85
|
+
cosmo content check [directory]
|
|
86
|
+
cosmo browser check [directory] [--no-build] [--no-lighthouse]
|
|
87
|
+
cosmo status [directory] [--json]
|
|
88
|
+
cosmo doctor [directory] [--json]
|
|
89
|
+
cosmo intake [directory] --niche value --audience value --goal value [--location value] [--pages number]
|
|
90
|
+
cosmo design brief [directory]
|
|
91
|
+
cosmo design capture [directory]
|
|
92
|
+
cosmo integrity init [directory] [--replace]
|
|
93
|
+
cosmo integrity check [directory] [--allow-missing-briefs]
|
|
94
|
+
cosmo intelligence list
|
|
95
|
+
cosmo intelligence show [directory]
|
|
96
|
+
cosmo intelligence check [directory]
|
|
97
|
+
cosmo intelligence guide <stage> [directory]
|
|
98
|
+
cosmo intelligence apply <profile> [directory]
|
|
99
|
+
cosmo intelligence add <pack> [directory]
|
|
100
|
+
cosmo intelligence remove <pack> [directory]
|
|
101
|
+
cosmo intelligence scaffold [directory] [--replace]
|
|
102
|
+
cosmo intelligence import <cosmo-pack.json|directory> [project] [--replace]
|
|
103
|
+
cosmo intelligence installed [directory]
|
|
104
|
+
cosmo brand discover [directory] [--replace]
|
|
105
|
+
cosmo brand check [directory]
|
|
106
|
+
cosmo research init [directory] [--replace]
|
|
107
|
+
cosmo research capture <source-id> <snapshot> [directory] --kind type --location value [--captured-at date] [--replace]
|
|
108
|
+
cosmo research check [directory]
|
|
109
|
+
cosmo brief create <page-id> [directory] [--replace]
|
|
110
|
+
cosmo brief create --all [directory] [--replace]
|
|
111
|
+
cosmo workflow list [directory]
|
|
112
|
+
cosmo workflow start [directory] [--workflow id]
|
|
113
|
+
cosmo workflow show [directory]
|
|
114
|
+
cosmo workflow submit <stage> [directory]
|
|
115
|
+
cosmo workflow approve <stage> [directory] [--by name]
|
|
116
|
+
cosmo workflow import <workflow.json> [directory]
|
|
117
|
+
cosmo plan check [directory]
|
|
118
|
+
cosmo generate start [directory] [--max-pages number]
|
|
119
|
+
cosmo generate workspace <page-id> [directory] [--replace]
|
|
120
|
+
cosmo generate workspace --all [directory] [--replace]
|
|
121
|
+
cosmo generate next [directory]
|
|
122
|
+
cosmo generate advance <page-id> [directory]
|
|
123
|
+
cosmo generate complete <page-id> [directory]
|
|
124
|
+
cosmo generate repair <page-id> [directory] --reason value
|
|
125
|
+
cosmo generate fail <page-id> [directory] --reason value
|
|
126
|
+
cosmo generate retry <page-id> [directory]
|
|
127
|
+
cosmo generate status [directory]
|
|
128
|
+
cosmo handoff create [directory] [--from agent] [--to agent] [--note text]
|
|
129
|
+
cosmo handoff show [directory]
|
|
130
|
+
cosmo release check [directory]
|
|
131
|
+
cosmo release show [directory]
|
|
132
|
+
cosmo deploy configure cloudflare-pages [directory] --project name [--production-branch main]
|
|
133
|
+
cosmo deploy configure sftp|ftps|ftp [directory] --host name --remote-dir path [--preview-remote-dir path]
|
|
134
|
+
cosmo deploy local [directory] [--no-build]
|
|
135
|
+
cosmo deploy preview [directory] [--no-build] [--env-file path]
|
|
136
|
+
cosmo deploy production [directory] [--no-build] [--env-file path]
|
|
137
|
+
cosmo deploy status [directory]
|
|
138
|
+
cosmo deploy history [directory]
|
|
139
|
+
cosmo --version
|
|
140
|
+
`);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function init(args) {
|
|
144
|
+
const { options, positional } = parseOptions(args);
|
|
145
|
+
const target = projectDirectory(positional[0] ?? '.');
|
|
146
|
+
ensureEmptyDirectory(target);
|
|
147
|
+
copyStarter(templateDirectory, target);
|
|
148
|
+
|
|
149
|
+
const brand = String(options.brand ?? 'Cosmo Studio');
|
|
150
|
+
const name = slugify(options.name ?? path.basename(target));
|
|
151
|
+
const site = String(options.site ?? 'https://example.com').replace(/\/$/, '');
|
|
152
|
+
replaceInTextFiles(target, 'Cosmo Studio', brand);
|
|
153
|
+
const packageFile = path.join(target, 'package.json');
|
|
154
|
+
const packageJson = JSON.parse(fs.readFileSync(packageFile, 'utf8'));
|
|
155
|
+
packageJson.name = name;
|
|
156
|
+
packageJson.private = true;
|
|
157
|
+
writeJson(packageFile, packageJson);
|
|
158
|
+
|
|
159
|
+
const project = readProject(target);
|
|
160
|
+
writeJson(project.file, {
|
|
161
|
+
...project.data,
|
|
162
|
+
name,
|
|
163
|
+
brand,
|
|
164
|
+
site,
|
|
165
|
+
stage: 'foundation',
|
|
166
|
+
createdAt: new Date().toISOString(),
|
|
167
|
+
lastActivity: new Date().toISOString(),
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
const entityId = slugify(brand);
|
|
171
|
+
const entityFile = path.join(target, '.cosmo', 'brand', 'entity-canon.json');
|
|
172
|
+
const entity = JSON.parse(fs.readFileSync(entityFile, 'utf8'));
|
|
173
|
+
replaceInTextFiles(target, `entityId: ${entity.id}`, `entityId: ${entityId}`);
|
|
174
|
+
writeJson(entityFile, { ...entity, id: entityId, officialName: brand, domain: site });
|
|
175
|
+
const voiceFile = path.join(target, '.cosmo', 'brand', 'voice-profile.json');
|
|
176
|
+
const voice = JSON.parse(fs.readFileSync(voiceFile, 'utf8'));
|
|
177
|
+
writeJson(voiceFile, { ...voice, entityId });
|
|
178
|
+
const evidenceFile = path.join(target, '.cosmo', 'evidence.json');
|
|
179
|
+
const evidence = JSON.parse(fs.readFileSync(evidenceFile, 'utf8'));
|
|
180
|
+
writeJson(evidenceFile, { ...evidence, entityId });
|
|
181
|
+
const planFile = path.join(target, '.cosmo', 'build-plan.json');
|
|
182
|
+
const plan = JSON.parse(fs.readFileSync(planFile, 'utf8'));
|
|
183
|
+
for (const page of plan.pages) page.contract.strengthensEntity = entityId;
|
|
184
|
+
writeJson(planFile, plan);
|
|
185
|
+
for (const page of plan.pages) createPageBrief(target, page.id, { replace: true });
|
|
186
|
+
applyIntelligenceProfile(target, String(options.profile ?? 'lean'));
|
|
187
|
+
|
|
188
|
+
const configFile = path.join(target, 'cosmo.config.mjs');
|
|
189
|
+
const config = fs.readFileSync(configFile, 'utf8')
|
|
190
|
+
.replace("name: 'Cosmo Starter'", `name: ${JSON.stringify(name)}`)
|
|
191
|
+
.replace("brand: 'Cosmo Studio'", `brand: ${JSON.stringify(brand)}`)
|
|
192
|
+
.replace("site: 'https://example.com'", `site: ${JSON.stringify(site)}`);
|
|
193
|
+
fs.writeFileSync(configFile, config);
|
|
194
|
+
|
|
195
|
+
console.log(`Created ${brand} at ${target}`);
|
|
196
|
+
console.log('Next: npm install, then cosmo dev');
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function adopt(args) {
|
|
200
|
+
const { options, positional } = parseOptions(args);
|
|
201
|
+
const target = projectDirectory(positional[0] ?? '.');
|
|
202
|
+
const result = adoptAstroProject(templateDirectory, target, options);
|
|
203
|
+
console.log(`Adopted ${result.brand} at ${result.target}`);
|
|
204
|
+
console.log(`Profile: ${result.profile}`);
|
|
205
|
+
console.log('Existing Astro source, configuration, dependencies, and public files were preserved.');
|
|
206
|
+
console.log('Next: cosmo doctor ., then cosmo workflow start .');
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function claudeCommand(args) {
|
|
210
|
+
const [subcommand = 'status', ...rest] = args;
|
|
211
|
+
const { options } = parseOptions(rest);
|
|
212
|
+
if (subcommand === 'install') {
|
|
213
|
+
const result = installClaudePlugin({ replace: Boolean(options.replace) });
|
|
214
|
+
console.log(`Installed Cosmo for Claude Code at ${result.target}`);
|
|
215
|
+
if (result.validation.attempted) console.log('Claude plugin validation: passed');
|
|
216
|
+
console.log('Restart Claude Code, open a project folder, and type: cosmo');
|
|
217
|
+
console.log('Explicit fallback: /cosmo:cosmo');
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (subcommand === 'status') {
|
|
221
|
+
const status = claudePluginStatus();
|
|
222
|
+
console.log(status.installed ? `Cosmo for Claude Code ${status.version ?? ''} is installed at ${status.target}` : 'Cosmo for Claude Code is not installed. Run: cosmo setup');
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (subcommand === 'uninstall') {
|
|
226
|
+
const result = uninstallClaudePlugin();
|
|
227
|
+
console.log(result.removed ? `Removed Cosmo for Claude Code from ${result.target}` : `Cosmo for Claude Code is not installed at ${result.target}`);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
throw new Error(`Unknown claude command: ${subcommand}`);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function setup() {
|
|
234
|
+
const result = installClaudePlugin({ replace: true });
|
|
235
|
+
console.log(`Cosmo ${VERSION} is ready for Claude at ${result.target}`);
|
|
236
|
+
if (result.validation.attempted) console.log('Claude plugin validation: passed');
|
|
237
|
+
console.log('Restart Claude, open a website folder, and type: cosmo');
|
|
238
|
+
console.log('Explicit fallback: /cosmo:cosmo');
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
async function build(args) {
|
|
242
|
+
const { positional } = parseOptions(args);
|
|
243
|
+
const target = projectDirectory(positional[0] ?? '.');
|
|
244
|
+
readProject(target);
|
|
245
|
+
await run('npm', ['run', 'build'], { cwd: target });
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async function dev(args) {
|
|
249
|
+
const { positional } = parseOptions(args);
|
|
250
|
+
const target = projectDirectory(positional[0] ?? '.');
|
|
251
|
+
readProject(target);
|
|
252
|
+
await run('npm', ['run', 'dev'], { cwd: target });
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
async function check(args) {
|
|
256
|
+
const { options, positional } = parseOptions(args);
|
|
257
|
+
const target = projectDirectory(positional[0] ?? '.');
|
|
258
|
+
readProject(target);
|
|
259
|
+
if (!options['no-build']) await run('npm', ['run', 'build'], { cwd: target });
|
|
260
|
+
const report = auditDist(path.join(target, 'dist'));
|
|
261
|
+
const reportFile = writeAuditReport(target, report);
|
|
262
|
+
console.log(`Cosmo QA: ${report.summary.pages} pages, ${report.summary.critical} critical, ${report.summary.warnings} warnings`);
|
|
263
|
+
console.log(`Report: ${reportFile}`);
|
|
264
|
+
if (!report.passed) {
|
|
265
|
+
for (const issue of report.critical.slice(0, 10)) {
|
|
266
|
+
console.error(`- ${issue.route ?? 'site'}: ${issue.rule}${issue.detail ? ` (${JSON.stringify(issue.detail)})` : ''}`);
|
|
267
|
+
}
|
|
268
|
+
process.exitCode = 1;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function contentCheck(args) {
|
|
273
|
+
const { positional } = parseOptions(args);
|
|
274
|
+
const target = projectDirectory(positional[0] ?? '.');
|
|
275
|
+
const report = auditContent(target);
|
|
276
|
+
const reportFile = writeContentReport(target, report);
|
|
277
|
+
console.log(`Content QA: ${report.summary.pages} pages, ${report.summary.blocking} blocking, ${report.summary.warnings} warnings`);
|
|
278
|
+
console.log(`Substance: ${Object.entries(report.summary.bySubstanceTier).map(([tier, count]) => `${tier}=${count}`).join(', ')}`);
|
|
279
|
+
console.log(`Report: ${reportFile}`);
|
|
280
|
+
if (!report.passed) {
|
|
281
|
+
for (const page of report.pages) {
|
|
282
|
+
for (const finding of page.findings.filter((item) => item.severity === 'blocking').slice(0, 10)) console.error(`- ${page.pageId}: ${finding.code} (${finding.message})`);
|
|
283
|
+
}
|
|
284
|
+
process.exitCode = 1;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function staticServer(projectDir) {
|
|
289
|
+
const distDir = path.join(projectDir, 'dist');
|
|
290
|
+
const types = { '.css': 'text/css', '.html': 'text/html', '.js': 'text/javascript', '.json': 'application/json', '.png': 'image/png', '.svg': 'image/svg+xml', '.txt': 'text/plain', '.xml': 'application/xml' };
|
|
291
|
+
const server = http.createServer((request, response) => {
|
|
292
|
+
const pathname = decodeURIComponent(new URL(request.url, 'http://127.0.0.1').pathname);
|
|
293
|
+
let relative = pathname.replace(/^\/+/, '');
|
|
294
|
+
if (!relative || relative.endsWith('/')) relative += 'index.html';
|
|
295
|
+
let file = path.resolve(distDir, relative);
|
|
296
|
+
if (!file.startsWith(`${distDir}${path.sep}`) && file !== distDir) {
|
|
297
|
+
response.writeHead(403).end('Forbidden');
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (fs.existsSync(file) && fs.statSync(file).isDirectory()) file = path.join(file, 'index.html');
|
|
301
|
+
if (!fs.existsSync(file) || !fs.statSync(file).isFile()) {
|
|
302
|
+
response.writeHead(404).end('Not found');
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
response.writeHead(200, { 'content-type': `${types[path.extname(file)] ?? 'application/octet-stream'}; charset=utf-8` });
|
|
306
|
+
fs.createReadStream(file).pipe(response);
|
|
307
|
+
});
|
|
308
|
+
return new Promise((resolve, reject) => {
|
|
309
|
+
server.on('error', reject);
|
|
310
|
+
server.listen(0, '127.0.0.1', () => resolve(server));
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
async function browserCheck(args) {
|
|
315
|
+
const { options, positional } = parseOptions(args);
|
|
316
|
+
const target = projectDirectory(positional[0] ?? '.');
|
|
317
|
+
readProject(target);
|
|
318
|
+
if (!options['no-build']) await run('npm', ['run', 'build'], { cwd: target });
|
|
319
|
+
const server = await staticServer(target);
|
|
320
|
+
const port = server.address().port;
|
|
321
|
+
const baseUrl = `http://127.0.0.1:${port}/`;
|
|
322
|
+
try {
|
|
323
|
+
const report = await auditBrowser(target, { baseUrl, lighthouseEnabled: !options['no-lighthouse'] });
|
|
324
|
+
const reportFile = writeBrowserReport(target, report);
|
|
325
|
+
console.log(`Browser QA: ${report.summary.routes} routes × 3 viewports, ${report.summary.critical} critical, ${report.summary.warnings} warnings`);
|
|
326
|
+
if (report.lighthouse) {
|
|
327
|
+
console.log(`Lighthouse: ${Object.entries(report.lighthouse).map(([name, result]) => `${name} ${result.score}`).join(', ')}`);
|
|
328
|
+
}
|
|
329
|
+
console.log(`Report: ${reportFile}`);
|
|
330
|
+
if (!report.passed) {
|
|
331
|
+
for (const issue of report.critical.slice(0, 20)) console.error(`- ${issue.route}: ${issue.rule} at ${issue.viewport ?? 'site'}`);
|
|
332
|
+
process.exitCode = 1;
|
|
333
|
+
}
|
|
334
|
+
} finally {
|
|
335
|
+
await new Promise((resolve) => server.close(resolve));
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function status(args) {
|
|
340
|
+
const { options, positional } = parseOptions(args);
|
|
341
|
+
const target = projectDirectory(positional[0] ?? '.');
|
|
342
|
+
const result = collectProjectStatus(target);
|
|
343
|
+
if (options.json) return console.log(JSON.stringify(result, null, 2));
|
|
344
|
+
console.log(`${result.project.brand ?? result.project.name} — ${result.release?.ready ? 'READY' : 'BLOCKED'}`);
|
|
345
|
+
console.log(` project: ${result.project.name} · ${result.project.site}`);
|
|
346
|
+
console.log(` workflow: ${result.workflow ? `${result.workflow.status}${result.workflow.currentStage ? ` at ${result.workflow.currentStage}` : ''}` : 'not started'}`);
|
|
347
|
+
console.log(` brand: ${result.brandDiscovery}`);
|
|
348
|
+
console.log(` intelligence: ${result.intelligence.profile} · ${result.intelligence.packs.length ? result.intelligence.packs.join(', ') : 'no selected packs'}${result.intelligence.installedPackages.length ? ` · ${result.intelligence.installedPackages.length} imported` : ''}`);
|
|
349
|
+
console.log(` plan: ${result.plan ? `${result.plan.pages} pages · ${result.plan.approved ? 'approved' : 'draft'}` : 'missing'}`);
|
|
350
|
+
console.log(` generation: ${result.generation ? `${result.generation.pages} pages · ${result.generation.complete ? 'complete' : 'active'}` : 'not started'}`);
|
|
351
|
+
console.log(` qa: ${Object.entries(result.qa).map(([name, report]) => `${name.replace('-check', '')}=${report ? report.status ?? (report.passed ? 'passed' : 'failed') : 'missing'}`).join(' ')}`);
|
|
352
|
+
console.log(` release: ${result.release?.releaseId ?? 'unavailable'} · ${result.release?.ready ? 'ready' : `${result.release?.blocking ?? '?'} blocking`}`);
|
|
353
|
+
console.log(` deployment: ${result.deployment ? `${result.deployment.provider}${result.deployment.latest ? ` · last ${result.deployment.latest.status}` : ' · never deployed'}` : 'not configured'}`);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function doctorCommand(args) {
|
|
357
|
+
const { options, positional } = parseOptions(args);
|
|
358
|
+
const result = diagnoseProject(projectDirectory(positional[0] ?? '.'));
|
|
359
|
+
if (options.json) console.log(JSON.stringify(result, null, 2));
|
|
360
|
+
else {
|
|
361
|
+
console.log(`Cosmo doctor: ${result.summary.pass} pass, ${result.summary.warn} warning, ${result.summary.fail} fail`);
|
|
362
|
+
for (const item of result.checks) console.log(` ${item.status === 'pass' ? '✓' : item.status === 'warn' ? '!' : '✗'} ${item.id.padEnd(12)} ${item.message}${item.fix && item.status !== 'pass' ? ` Next: ${item.fix}` : ''}`);
|
|
363
|
+
}
|
|
364
|
+
if (!result.passed) process.exitCode = 1;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function brandCommand(args) {
|
|
368
|
+
const subcommand = args[0] ?? 'check';
|
|
369
|
+
const { options, positional } = parseOptions(args.slice(1));
|
|
370
|
+
const target = projectDirectory(positional[0] ?? '.');
|
|
371
|
+
if (subcommand === 'discover') {
|
|
372
|
+
const result = scaffoldBrandDiscovery(target, { replace: Boolean(options.replace) });
|
|
373
|
+
console.log(result.created ? `Created guided brand discovery: ${result.file}` : `Brand discovery already exists: ${result.file}`);
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
if (subcommand === 'check') {
|
|
377
|
+
const result = checkBrandDiscovery(target);
|
|
378
|
+
console.log(`Brand discovery approved: ${result.prompts} prompts and synthesis complete.`);
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
throw new Error(`Unknown brand command: ${subcommand}`);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function researchCommand(args) {
|
|
385
|
+
const subcommand = args[0] ?? 'check';
|
|
386
|
+
const { options, positional } = parseOptions(args.slice(1));
|
|
387
|
+
if (subcommand === 'init') {
|
|
388
|
+
const result = scaffoldResearchWorkbench(projectDirectory(positional[0] ?? '.'), { replace: Boolean(options.replace) });
|
|
389
|
+
console.log(result.created ? `Created research workbench: ${result.file}` : `Research workbench already exists: ${result.file}`);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
if (subcommand === 'capture') {
|
|
393
|
+
if (!positional[0] || !positional[1]) throw new Error('Usage: cosmo research capture <source-id> <snapshot> [directory] --kind type --location value');
|
|
394
|
+
const result = captureResearchSource(projectDirectory(positional[2] ?? '.'), positional[0], positional[1], { kind: options.kind, location: options.location, capturedAt: options['captured-at'], replace: Boolean(options.replace) });
|
|
395
|
+
console.log(`Captured ${result.source.id}: ${result.snapshot}`);
|
|
396
|
+
console.log(`SHA256: ${result.source.sha256}`);
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
if (subcommand === 'check') {
|
|
400
|
+
const result = checkResearchWorkbench(projectDirectory(positional[0] ?? '.'));
|
|
401
|
+
console.log(`Research workbench valid: ${result.summary.tasks} tasks, ${result.summary.sources} sources, ${result.summary.findings} findings, ${result.summary.candidates} page candidates`);
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
throw new Error(`Unknown research command: ${subcommand}`);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function intake(args) {
|
|
408
|
+
const { options, positional } = parseOptions(args);
|
|
409
|
+
const target = projectDirectory(positional[0] ?? '.');
|
|
410
|
+
const project = readProject(target);
|
|
411
|
+
const required = ['niche', 'audience', 'goal'].filter((key) => !options[key]);
|
|
412
|
+
if (required.length) throw new Error(`Missing intake options: ${required.map((key) => `--${key}`).join(', ')}`);
|
|
413
|
+
const pageTarget = Number(options.pages ?? 5);
|
|
414
|
+
if (!Number.isInteger(pageTarget) || pageTarget < 1) throw new Error('--pages must be a positive integer.');
|
|
415
|
+
const file = path.join(target, '.cosmo', 'intake.json');
|
|
416
|
+
if (fs.existsSync(file) && !options.replace) throw new Error(`Intake already exists: ${file}. Pass --replace to overwrite it.`);
|
|
417
|
+
writeJson(file, {
|
|
418
|
+
version: 1,
|
|
419
|
+
business: {
|
|
420
|
+
name: project.data.brand,
|
|
421
|
+
niche: String(options.niche),
|
|
422
|
+
location: String(options.location ?? ''),
|
|
423
|
+
},
|
|
424
|
+
audience: { summary: String(options.audience) },
|
|
425
|
+
goals: [String(options.goal)],
|
|
426
|
+
scope: {
|
|
427
|
+
pageTarget,
|
|
428
|
+
contentLanguage: String(options.language ?? 'en'),
|
|
429
|
+
output: project.data.output,
|
|
430
|
+
},
|
|
431
|
+
designMode: String(options['design-mode'] ?? project.data.designMode ?? 'hybrid'),
|
|
432
|
+
evidence: [],
|
|
433
|
+
constraints: [],
|
|
434
|
+
createdAt: new Date().toISOString(),
|
|
435
|
+
});
|
|
436
|
+
console.log(`Created structured intake: ${file}`);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
function designBrief(args) {
|
|
440
|
+
const { options, positional } = parseOptions(args);
|
|
441
|
+
const target = projectDirectory(positional[0] ?? '.');
|
|
442
|
+
const { data } = readProject(target);
|
|
443
|
+
const file = path.join(target, '.cosmo', 'design', 'creative-brief.md');
|
|
444
|
+
if (fs.existsSync(file) && !options.replace) {
|
|
445
|
+
throw new Error(`Design brief already exists: ${file}. Pass --replace to regenerate it.`);
|
|
446
|
+
}
|
|
447
|
+
const selectedDesignPacks = readIntelligence(target).manifests.filter((pack) => pack.stages.includes('design'));
|
|
448
|
+
const intelligenceSection = selectedDesignPacks.length
|
|
449
|
+
? `\n## Selected intelligence packs\n\n${selectedDesignPacks.map((pack) => `### ${pack.title}\n\n${pack.guidance.claude}\n\nQuestions:\n${pack.questions.map((question) => `- ${question}`).join('\n')}\n\nRequired handoff: \`${pack.artifact.path}\``).join('\n\n')}\n`
|
|
450
|
+
: '';
|
|
451
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
452
|
+
fs.writeFileSync(file, `# Creative Brief — ${data.brand}\n\n## Goal\n\nCreate a distinctive, conversion-aware visual direction for ${data.brand}. Explore at least three genuinely different compositions before selecting one.\n\n## Inputs to complete\n\n- Audience:\n- Primary conversion:\n- Desired first-five-seconds feeling:\n- Brand truths that must remain visible:\n- Real assets available:\n- Competitors and references:\n\n## Required page capabilities\n\n- Semantic hook, problem, proof, solution, evidence, and action sections\n- Mobile-first behavior at 320px, 768px, and 1440px\n- Keyboard-visible focus and reduced-motion support\n- Strong content hierarchy with exactly one H1\n- Components that can be reused without forcing identical page compositions\n\n## Creative freedom\n\nClaude Design owns composition, typography, palette, rhythm, texture, art direction, and signature interaction. Cosmo owns content structure, accessibility, SEO, and build integrity. Avoid treating the existing starter styling as a visual requirement.\n${intelligenceSection}\n## Deliverables\n\n1. Three visual directions with a short rationale for each\n2. One selected and refined homepage direction\n3. Mobile and desktop states\n4. Component inventory and design tokens\n5. Notes describing the distinctive element that should survive implementation\n`);
|
|
453
|
+
console.log(`Created Claude Design brief: ${file}`);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function designCapture(args) {
|
|
457
|
+
const { positional } = parseOptions(args);
|
|
458
|
+
const target = projectDirectory(positional[0] ?? '.');
|
|
459
|
+
const project = readProject(target);
|
|
460
|
+
const tokensFile = path.join(target, 'src', 'styles', 'tokens.css');
|
|
461
|
+
const directionFile = path.join(target, 'DESIGN-DIRECTION.md');
|
|
462
|
+
const componentsDir = path.join(target, 'src', 'components');
|
|
463
|
+
const missing = [tokensFile, directionFile, componentsDir].filter((entry) => !fs.existsSync(entry));
|
|
464
|
+
if (missing.length) throw new Error(`Design capture is missing:\n${missing.map((entry) => `- ${entry}`).join('\n')}`);
|
|
465
|
+
|
|
466
|
+
const tokens = [...fs.readFileSync(tokensFile, 'utf8').matchAll(/--([\w-]+)\s*:\s*([^;]+);/g)]
|
|
467
|
+
.map((match) => ({ name: match[1], value: match[2].trim() }));
|
|
468
|
+
const components = fs.readdirSync(componentsDir, { recursive: true })
|
|
469
|
+
.filter((entry) => String(entry).endsWith('.astro'))
|
|
470
|
+
.map(String)
|
|
471
|
+
.sort();
|
|
472
|
+
const file = path.join(target, '.cosmo', 'design', 'design-manifest.json');
|
|
473
|
+
writeJson(file, { capturedAt: new Date().toISOString(), mode: project.data.designMode, tokens, components });
|
|
474
|
+
const workflow = readWorkflowState(target, { required: false });
|
|
475
|
+
const stage = workflow?.data.status === 'active' ? workflow.data.currentStage : 'design-captured';
|
|
476
|
+
writeJson(project.file, { ...project.data, stage, lastActivity: new Date().toISOString() });
|
|
477
|
+
console.log(`Captured ${tokens.length} tokens and ${components.length} components: ${file}`);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
function integrityCommand(args) {
|
|
481
|
+
const subcommand = args[0] ?? 'check';
|
|
482
|
+
const { options, positional } = parseOptions(args.slice(1));
|
|
483
|
+
const target = projectDirectory(positional[0] ?? '.');
|
|
484
|
+
if (subcommand === 'init') {
|
|
485
|
+
const files = scaffoldIntegrity(target, { replace: Boolean(options.replace) });
|
|
486
|
+
console.log(files.length ? `Created ${files.length} integrity artifacts.` : 'Integrity artifacts already exist.');
|
|
487
|
+
for (const file of files) console.log(` ${path.relative(target, file)}`);
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
if (subcommand === 'check') {
|
|
491
|
+
const report = checkIntegrity(target, { requireBriefs: !options['allow-missing-briefs'] });
|
|
492
|
+
const file = path.join(target, '.cosmo', 'reports', 'integrity-check.json');
|
|
493
|
+
writeJson(file, report);
|
|
494
|
+
console.log(`Integrity valid: ${report.summary.capabilities} capabilities, ${report.summary.intelligencePacks} intelligence packs, ${report.summary.claims} claims, ${report.summary.proofs} proofs, ${report.summary.briefs} page briefs`);
|
|
495
|
+
for (const warning of report.warnings) console.log(` warning: ${warning}`);
|
|
496
|
+
console.log(`Report: ${file}`);
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
throw new Error(`Unknown integrity command: ${subcommand}`);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
function showIntelligence(target) {
|
|
503
|
+
const intelligence = readIntelligence(target);
|
|
504
|
+
console.log(`Intelligence profile: ${intelligence.data.profile}`);
|
|
505
|
+
if (!intelligence.manifests.length) {
|
|
506
|
+
console.log(' packs: none');
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
for (const pack of intelligence.manifests) console.log(` ${pack.id.padEnd(18)} gate=${pack.artifact.stage} artifact=${pack.artifact.path}`);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function intelligenceCommand(args) {
|
|
513
|
+
const subcommand = args[0] ?? 'show';
|
|
514
|
+
const rest = args.slice(1);
|
|
515
|
+
if (subcommand === 'list') {
|
|
516
|
+
const catalog = intelligenceCatalog();
|
|
517
|
+
console.log('Profiles');
|
|
518
|
+
for (const profile of catalog.profiles) console.log(` ${profile.id.padEnd(20)} ${profile.packs.length ? profile.packs.join(', ') : 'no optional packs'}`);
|
|
519
|
+
console.log('Packs');
|
|
520
|
+
for (const pack of catalog.packs) console.log(` ${pack.id.padEnd(20)} ${pack.description}`);
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
if (subcommand === 'show') {
|
|
524
|
+
const { positional } = parseOptions(rest);
|
|
525
|
+
showIntelligence(projectDirectory(positional[0] ?? '.'));
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
if (subcommand === 'installed') {
|
|
529
|
+
const { positional } = parseOptions(rest);
|
|
530
|
+
const lock = readIntelligenceLock(projectDirectory(positional[0] ?? '.')).data;
|
|
531
|
+
if (!lock.packages.length) console.log('No imported intelligence packages.');
|
|
532
|
+
for (const item of lock.packages) console.log(` ${item.id.padEnd(20)} ${item.version} sha256:${item.sha256.slice(0, 12)}`);
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
if (subcommand === 'import') {
|
|
536
|
+
const { options, positional } = parseOptions(rest);
|
|
537
|
+
if (!positional[0]) throw new Error('Usage: cosmo intelligence import <cosmo-pack.json|directory> [project] [--replace]');
|
|
538
|
+
const target = projectDirectory(positional[1] ?? '.');
|
|
539
|
+
const result = importIntelligencePack(target, positional[0], { replace: Boolean(options.replace) });
|
|
540
|
+
console.log(`Imported ${result.package.id}@${result.package.version}: ${result.destination}`);
|
|
541
|
+
showIntelligence(target);
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
if (subcommand === 'check') {
|
|
545
|
+
const { positional } = parseOptions(rest);
|
|
546
|
+
const target = projectDirectory(positional[0] ?? '.');
|
|
547
|
+
const report = evaluateIntelligence(target);
|
|
548
|
+
const reportFile = writeIntelligenceReport(target, report);
|
|
549
|
+
console.log(`Intelligence QA: ${report.summary.packs} packs, ${report.summary.blocking} blocking, ${report.summary.warnings} warnings`);
|
|
550
|
+
console.log(`Report: ${reportFile}`);
|
|
551
|
+
if (!report.passed) {
|
|
552
|
+
for (const pack of report.packs) for (const item of pack.findings.filter((finding) => finding.severity === 'blocking').slice(0, 10)) console.error(`- ${pack.id}: ${item.code} (${item.message})`);
|
|
553
|
+
process.exitCode = 1;
|
|
554
|
+
}
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
if (subcommand === 'guide') {
|
|
558
|
+
const { positional } = parseOptions(rest);
|
|
559
|
+
if (!positional[0]) throw new Error('Usage: cosmo intelligence guide <stage> [directory]');
|
|
560
|
+
const target = projectDirectory(positional[1] ?? '.');
|
|
561
|
+
const packs = readIntelligence(target).manifests.filter((pack) => pack.stages.includes(positional[0]));
|
|
562
|
+
if (!packs.length) return console.log(`No selected intelligence guidance for stage ${positional[0]}.`);
|
|
563
|
+
console.log(`Intelligence guidance — ${positional[0]}`);
|
|
564
|
+
for (const pack of packs) {
|
|
565
|
+
console.log(`\n${pack.title} (${pack.id})`);
|
|
566
|
+
console.log(` Claude: ${pack.guidance.claude}`);
|
|
567
|
+
console.log(` Codex: ${pack.guidance.codex}`);
|
|
568
|
+
console.log(' Questions:');
|
|
569
|
+
for (const question of pack.questions) console.log(` - ${question}`);
|
|
570
|
+
if (pack.artifact.stage === positional[0]) console.log(` Gate: ${pack.artifact.path}`);
|
|
571
|
+
}
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
if (subcommand === 'scaffold') {
|
|
575
|
+
const { options, positional } = parseOptions(rest);
|
|
576
|
+
const target = projectDirectory(positional[0] ?? '.');
|
|
577
|
+
const files = scaffoldIntelligenceArtifacts(target, { replace: Boolean(options.replace) });
|
|
578
|
+
console.log(files.length ? `Created ${files.length} intelligence artifacts.` : 'Intelligence artifacts already exist or no packs are selected.');
|
|
579
|
+
for (const file of files) console.log(` ${path.relative(target, file)}`);
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
if (['apply', 'add', 'remove'].includes(subcommand)) {
|
|
583
|
+
const { positional } = parseOptions(rest);
|
|
584
|
+
if (!positional[0]) throw new Error(`Usage: cosmo intelligence ${subcommand} <${subcommand === 'apply' ? 'profile' : 'pack'}> [directory]`);
|
|
585
|
+
const target = projectDirectory(positional[1] ?? '.');
|
|
586
|
+
if (subcommand === 'apply') applyIntelligenceProfile(target, positional[0]);
|
|
587
|
+
if (subcommand === 'add') addIntelligencePack(target, positional[0]);
|
|
588
|
+
if (subcommand === 'remove') removeIntelligencePack(target, positional[0]);
|
|
589
|
+
showIntelligence(target);
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
throw new Error(`Unknown intelligence command: ${subcommand}`);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
function briefCommand(args) {
|
|
596
|
+
const subcommand = args[0];
|
|
597
|
+
if (subcommand !== 'create') throw new Error('Usage: cosmo brief create <page-id> [directory] [--replace]');
|
|
598
|
+
const all = args.slice(1).includes('--all');
|
|
599
|
+
const parsedArgs = args.slice(1).filter((arg) => arg !== '--all');
|
|
600
|
+
const { options, positional } = parseOptions(parsedArgs);
|
|
601
|
+
const target = projectDirectory(all ? positional[0] ?? '.' : positional[1] ?? '.');
|
|
602
|
+
const plan = readPlan(target, { requireApproved: false }).data;
|
|
603
|
+
const pageIds = all ? plan.pages.map((page) => page.id) : [positional[0]];
|
|
604
|
+
if (!pageIds[0]) throw new Error('Usage: cosmo brief create <page-id> [directory] [--replace]');
|
|
605
|
+
for (const pageId of pageIds) {
|
|
606
|
+
const result = createPageBrief(target, pageId, { replace: Boolean(options.replace) });
|
|
607
|
+
console.log(`Created page brief: ${result.file}`);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
function showWorkflow(target) {
|
|
612
|
+
const { state, workflow, current, position } = workflowSummary(target);
|
|
613
|
+
console.log(`${workflow.name} — ${state.status}`);
|
|
614
|
+
for (const stage of workflow.stages) {
|
|
615
|
+
const marker = stage.id === state.currentStage ? '→' : state.stages[stage.id].status === 'completed' ? '✓' : '·';
|
|
616
|
+
console.log(` ${marker} ${stage.id.padEnd(10)} ${state.stages[stage.id].status.padEnd(17)} ${stage.title}`);
|
|
617
|
+
}
|
|
618
|
+
if (current) {
|
|
619
|
+
console.log(`\nStage ${position} of ${workflow.stages.length}: ${current.title}`);
|
|
620
|
+
console.log(current.instructions);
|
|
621
|
+
console.log(`Approval: ${current.approval ? 'required' : 'automatic after submission'}`);
|
|
622
|
+
console.log('Required artifacts:');
|
|
623
|
+
for (const artifact of current.expects) console.log(` - ${typeof artifact === 'string' ? artifact : artifact.path}`);
|
|
624
|
+
const packGates = readIntelligence(target).manifests.filter((pack) => pack.artifact.stage === current.id);
|
|
625
|
+
if (packGates.length) {
|
|
626
|
+
console.log('Selected intelligence gates:');
|
|
627
|
+
for (const pack of packGates) console.log(` - ${pack.title}: ${pack.artifact.path}`);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
function workflowCommand(args) {
|
|
633
|
+
const subcommand = args[0] ?? 'show';
|
|
634
|
+
const rest = args.slice(1);
|
|
635
|
+
if (subcommand === 'list') {
|
|
636
|
+
const { positional } = parseOptions(rest);
|
|
637
|
+
const target = projectDirectory(positional[0] ?? '.');
|
|
638
|
+
readProject(target);
|
|
639
|
+
for (const workflow of listWorkflows(target)) {
|
|
640
|
+
console.log(`${workflow.valid ? '✓' : '!'} ${workflow.id} — ${workflow.name}${workflow.valid ? ` (${workflow.stages} stages)` : `: ${workflow.error}`}`);
|
|
641
|
+
}
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
if (subcommand === 'start') {
|
|
645
|
+
const { options, positional } = parseOptions(rest);
|
|
646
|
+
const target = projectDirectory(positional[0] ?? '.');
|
|
647
|
+
startWorkflow(target, String(options.workflow ?? 'default'));
|
|
648
|
+
showWorkflow(target);
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
if (subcommand === 'show' || subcommand === 'resume') {
|
|
652
|
+
const { positional } = parseOptions(rest);
|
|
653
|
+
showWorkflow(projectDirectory(positional[0] ?? '.'));
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
if (subcommand === 'submit') {
|
|
657
|
+
const { positional } = parseOptions(rest);
|
|
658
|
+
if (!positional[0]) throw new Error('Usage: cosmo workflow submit <stage> [directory]');
|
|
659
|
+
const target = projectDirectory(positional[1] ?? '.');
|
|
660
|
+
submitStage(target, positional[0]);
|
|
661
|
+
showWorkflow(target);
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
if (subcommand === 'approve') {
|
|
665
|
+
const { options, positional } = parseOptions(rest);
|
|
666
|
+
if (!positional[0]) throw new Error('Usage: cosmo workflow approve <stage> [directory] [--by name]');
|
|
667
|
+
const target = projectDirectory(positional[1] ?? '.');
|
|
668
|
+
approveStage(target, positional[0], String(options.by ?? 'operator'));
|
|
669
|
+
showWorkflow(target);
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
if (subcommand === 'import') {
|
|
673
|
+
const { positional } = parseOptions(rest);
|
|
674
|
+
if (!positional[0]) throw new Error('Usage: cosmo workflow import <workflow.json> [directory]');
|
|
675
|
+
const target = projectDirectory(positional[1] ?? '.');
|
|
676
|
+
const result = importWorkflow(target, positional[0]);
|
|
677
|
+
console.log(`Imported ${result.workflow.name}: ${result.destination}`);
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
throw new Error(`Unknown workflow command: ${subcommand}`);
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
function planCommand(args) {
|
|
684
|
+
const subcommand = args[0] ?? 'check';
|
|
685
|
+
const { positional } = parseOptions(args.slice(1));
|
|
686
|
+
const target = projectDirectory(positional[0] ?? '.');
|
|
687
|
+
if (subcommand !== 'check') throw new Error(`Unknown plan command: ${subcommand}`);
|
|
688
|
+
const plan = readPlan(target, { requireApproved: false }).data;
|
|
689
|
+
const summary = planSummary(plan);
|
|
690
|
+
const status = plan.approved ? 'approved' : 'draft';
|
|
691
|
+
console.log(`Plan valid (${status}): ${summary.pages} pages, ${summary.links} graph edges, ${summary.evidenceRequirements} evidence requirements`);
|
|
692
|
+
for (const [type, count] of Object.entries(summary.byType)) console.log(` ${type}: ${count}`);
|
|
693
|
+
if (summary.version >= 3) {
|
|
694
|
+
console.log(` indexable: ${summary.indexable}/${summary.pages}`);
|
|
695
|
+
console.log(` intent boundaries: ${summary.intentBoundaries}`);
|
|
696
|
+
console.log(` archetypes: ${Object.entries(summary.byArchetype).map(([name, count]) => `${name}=${count}`).join(', ')}`);
|
|
697
|
+
console.log(` link roles: ${Object.entries(summary.byLinkRole).map(([name, count]) => `${name}=${count}`).join(', ')}`);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
function showGenerationStatus(target) {
|
|
702
|
+
const progress = readProgress(target).data;
|
|
703
|
+
console.log(`Generation: ${progress.complete ? 'complete' : progress.stoppedReason ? `stopped (${progress.stoppedReason})` : 'active'}`);
|
|
704
|
+
console.log(` done: ${progress.summary.done}/${progress.summary.total}`);
|
|
705
|
+
console.log(` pending: ${progress.summary.pending}`);
|
|
706
|
+
console.log(` failed: ${progress.summary.failed}`);
|
|
707
|
+
console.log(` streak: ${progress.failureStreak}`);
|
|
708
|
+
if (progress.version >= 2) {
|
|
709
|
+
const states = Object.entries(progress.summary.byState).filter(([, count]) => count > 0).map(([state, count]) => `${state}=${count}`).join(', ');
|
|
710
|
+
console.log(` states: ${states || 'none'}`);
|
|
711
|
+
}
|
|
712
|
+
if (progress.maxPages) console.log(` cap: ${progress.maxPages}`);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
function generateCommand(args) {
|
|
716
|
+
const subcommand = args[0] ?? 'status';
|
|
717
|
+
if (subcommand === 'workspace') {
|
|
718
|
+
const all = args.slice(1).includes('--all');
|
|
719
|
+
const parsedArgs = args.slice(1).filter((arg) => arg !== '--all');
|
|
720
|
+
const { options, positional } = parseOptions(parsedArgs);
|
|
721
|
+
const target = projectDirectory(all ? positional[0] ?? '.' : positional[1] ?? '.');
|
|
722
|
+
const plan = readPlan(target).data;
|
|
723
|
+
const pageIds = all ? plan.pages.map((page) => page.id) : [positional[0]];
|
|
724
|
+
if (!pageIds[0]) throw new Error('Usage: cosmo generate workspace <page-id> [directory] [--replace]');
|
|
725
|
+
for (const pageId of pageIds) {
|
|
726
|
+
const files = scaffoldPageWorkspace(target, pageId, { replace: Boolean(options.replace) });
|
|
727
|
+
console.log(files.length ? `Created ${files.length} workspace artifacts for ${pageId}.` : `Workspace artifacts already exist for ${pageId}.`);
|
|
728
|
+
}
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
const { options, positional } = parseOptions(args.slice(1));
|
|
732
|
+
if (subcommand === 'start') {
|
|
733
|
+
const target = projectDirectory(positional[0] ?? '.');
|
|
734
|
+
const maxPages = options['max-pages'] === undefined ? null : Number(options['max-pages']);
|
|
735
|
+
startGeneration(target, { maxPages });
|
|
736
|
+
showGenerationStatus(target);
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
if (subcommand === 'next') {
|
|
740
|
+
const target = projectDirectory(positional[0] ?? '.');
|
|
741
|
+
console.log(JSON.stringify(nextPage(target), null, 2));
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
if (subcommand === 'status') {
|
|
745
|
+
showGenerationStatus(projectDirectory(positional[0] ?? '.'));
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
if (['advance', 'complete', 'fail', 'repair', 'retry'].includes(subcommand)) {
|
|
749
|
+
if (!positional[0]) throw new Error(`Usage: cosmo generate ${subcommand} <page-id> [directory]`);
|
|
750
|
+
const pageId = positional[0];
|
|
751
|
+
const target = projectDirectory(positional[1] ?? '.');
|
|
752
|
+
if (subcommand === 'advance') advancePage(target, pageId);
|
|
753
|
+
if (subcommand === 'complete') completePage(target, pageId);
|
|
754
|
+
if (subcommand === 'fail') failPage(target, pageId, String(options.reason ?? ''));
|
|
755
|
+
if (subcommand === 'repair') recordRepair(target, pageId, String(options.reason ?? ''));
|
|
756
|
+
if (subcommand === 'retry') retryPage(target, pageId);
|
|
757
|
+
showGenerationStatus(target);
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
throw new Error(`Unknown generate command: ${subcommand}`);
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
function handoffCommand(args) {
|
|
764
|
+
const subcommand = args[0] ?? 'show';
|
|
765
|
+
const { options, positional } = parseOptions(args.slice(1));
|
|
766
|
+
const target = projectDirectory(positional[0] ?? '.');
|
|
767
|
+
if (subcommand === 'create') {
|
|
768
|
+
const result = createHandoff(target, {
|
|
769
|
+
from: options.from ?? 'claude',
|
|
770
|
+
to: options.to ?? 'codex',
|
|
771
|
+
note: options.note ?? '',
|
|
772
|
+
});
|
|
773
|
+
console.log(`Created ${result.data.from} → ${result.data.to} handoff: ${result.markdownFile}`);
|
|
774
|
+
console.log(`Next: ${result.data.nextAction}`);
|
|
775
|
+
return;
|
|
776
|
+
}
|
|
777
|
+
if (subcommand === 'show') {
|
|
778
|
+
console.log(readHandoff(target).markdown.trimEnd());
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
throw new Error(`Unknown handoff command: ${subcommand}`);
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
function releaseCommand(args) {
|
|
785
|
+
const subcommand = args[0] ?? 'check';
|
|
786
|
+
const { positional } = parseOptions(args.slice(1));
|
|
787
|
+
const target = projectDirectory(positional[0] ?? '.');
|
|
788
|
+
if (subcommand === 'check') {
|
|
789
|
+
const report = evaluateDelivery(target);
|
|
790
|
+
const files = writeDeliveryReport(target, report);
|
|
791
|
+
console.log(`Delivery: ${report.ready ? 'READY' : 'BLOCKED'}, release ${report.releaseId}, ${report.summary.blocking} blockers`);
|
|
792
|
+
console.log(`Manifest: ${files.markdownFile}`);
|
|
793
|
+
if (!report.ready) {
|
|
794
|
+
for (const item of report.findings.slice(0, 20)) console.error(`- ${item.code}: ${item.message}`);
|
|
795
|
+
process.exitCode = 1;
|
|
796
|
+
}
|
|
797
|
+
return;
|
|
798
|
+
}
|
|
799
|
+
if (subcommand === 'show') {
|
|
800
|
+
console.log(readDelivery(target).markdown.trimEnd());
|
|
801
|
+
return;
|
|
802
|
+
}
|
|
803
|
+
throw new Error(`Unknown release command: ${subcommand}`);
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
async function deployCommand(args) {
|
|
807
|
+
const subcommand = args[0] ?? 'status';
|
|
808
|
+
const rest = args.slice(1);
|
|
809
|
+
if (subcommand === 'configure') {
|
|
810
|
+
const { options, positional } = parseOptions(rest);
|
|
811
|
+
if (!positional[0]) throw new Error('Usage: cosmo deploy configure <cloudflare-pages|sftp|ftps|ftp> [directory] [provider options]');
|
|
812
|
+
const target = projectDirectory(positional[1] ?? '.');
|
|
813
|
+
const result = configureDeployment(target, positional[0], {
|
|
814
|
+
projectName: options.project,
|
|
815
|
+
productionBranch: options['production-branch'],
|
|
816
|
+
previewBranchPrefix: options['preview-prefix'],
|
|
817
|
+
outputDir: options.output,
|
|
818
|
+
host: options.host,
|
|
819
|
+
port: options.port,
|
|
820
|
+
usernameEnv: options['username-env'],
|
|
821
|
+
passwordEnv: options['no-password'] ? false : options['password-env'],
|
|
822
|
+
privateKeyEnv: options['private-key-env'],
|
|
823
|
+
passphraseEnv: options['passphrase-env'],
|
|
824
|
+
hostFingerprintEnv: options['host-fingerprint-env'],
|
|
825
|
+
remoteDir: options['remote-dir'],
|
|
826
|
+
previewRemoteDir: options['preview-remote-dir'],
|
|
827
|
+
implicitTls: options.implicit,
|
|
828
|
+
allowInsecure: options['allow-insecure'],
|
|
829
|
+
});
|
|
830
|
+
console.log(`Configured ${result.data.provider} target ${result.data.projectName ?? `${result.data.host}:${result.data.remoteDir}`}: ${result.file}`);
|
|
831
|
+
console.log('Credentials remain in provider authentication, environment variables, or a runtime --env-file.');
|
|
832
|
+
return;
|
|
833
|
+
}
|
|
834
|
+
if (subcommand === 'local') {
|
|
835
|
+
const { options, positional } = parseOptions(rest);
|
|
836
|
+
const target = projectDirectory(positional[0] ?? '.');
|
|
837
|
+
readProject(target);
|
|
838
|
+
if (!options['no-build']) await run('npm', ['run', 'build'], { cwd: target });
|
|
839
|
+
await run('npm', ['run', 'preview', '--', '--host', '127.0.0.1'], { cwd: target });
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
if (['preview', 'production'].includes(subcommand)) {
|
|
843
|
+
const { options, positional } = parseOptions(rest);
|
|
844
|
+
const target = projectDirectory(positional[0] ?? '.');
|
|
845
|
+
const record = await deployProject(target, subcommand, { build: !options['no-build'], envFile: options['env-file'] });
|
|
846
|
+
console.log(`${subcommand === 'production' ? 'Production' : 'Preview'} deployed: ${record.url ?? record.remoteDir ?? 'URL unavailable in provider output'}`);
|
|
847
|
+
console.log(`Release: ${record.releaseId}${record.releaseReady ? ' (READY)' : ' (preview of blocked release)'}`);
|
|
848
|
+
if (record.totalFiles !== undefined) console.log(`Files: ${record.uploaded} uploaded, ${record.skipped} unchanged, ${record.totalFiles} total`);
|
|
849
|
+
return;
|
|
850
|
+
}
|
|
851
|
+
if (['status', 'history'].includes(subcommand)) {
|
|
852
|
+
const { positional } = parseOptions(rest);
|
|
853
|
+
const target = projectDirectory(positional[0] ?? '.');
|
|
854
|
+
const config = readDeploymentConfig(target).data;
|
|
855
|
+
const history = readDeploymentHistory(target).records;
|
|
856
|
+
console.log(config.provider === 'cloudflare-pages'
|
|
857
|
+
? `${config.provider}: ${config.projectName} (production branch ${config.productionBranch})`
|
|
858
|
+
: `${config.provider}: ${config.host}:${config.port}${config.remoteDir}`);
|
|
859
|
+
const records = subcommand === 'status' ? history.slice(-1) : history;
|
|
860
|
+
if (!records.length) console.log('No deployments recorded.');
|
|
861
|
+
for (const record of records) console.log(`${record.completedAt} ${record.status.padEnd(8)} ${record.environment.padEnd(10)} ${record.releaseId} ${record.url ?? 'URL unavailable'}`);
|
|
862
|
+
return;
|
|
863
|
+
}
|
|
864
|
+
throw new Error(`Unknown deploy command: ${subcommand}`);
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
async function main() {
|
|
868
|
+
if (command === 'help' || command === '--help' || command === '-h') return help();
|
|
869
|
+
if (command === '--version' || command === '-v' || command === 'version') return console.log(VERSION);
|
|
870
|
+
if (command === 'setup') return setup();
|
|
871
|
+
if (command === 'init') return init(rawArgs);
|
|
872
|
+
if (command === 'adopt') return adopt(rawArgs);
|
|
873
|
+
if (command === 'claude') return claudeCommand(rawArgs);
|
|
874
|
+
if (command === 'dev') return dev(rawArgs);
|
|
875
|
+
if (command === 'build') return build(rawArgs);
|
|
876
|
+
if (command === 'check') return check(rawArgs);
|
|
877
|
+
if (command === 'content' && rawArgs[0] === 'check') return contentCheck(rawArgs.slice(1));
|
|
878
|
+
if (command === 'browser' && rawArgs[0] === 'check') return browserCheck(rawArgs.slice(1));
|
|
879
|
+
if (command === 'status') return status(rawArgs);
|
|
880
|
+
if (command === 'doctor') return doctorCommand(rawArgs);
|
|
881
|
+
if (command === 'brand') return brandCommand(rawArgs);
|
|
882
|
+
if (command === 'research') return researchCommand(rawArgs);
|
|
883
|
+
if (command === 'intake') return intake(rawArgs);
|
|
884
|
+
if (command === 'design' && rawArgs[0] === 'brief') return designBrief(rawArgs.slice(1));
|
|
885
|
+
if (command === 'design' && rawArgs[0] === 'capture') return designCapture(rawArgs.slice(1));
|
|
886
|
+
if (command === 'integrity') return integrityCommand(rawArgs);
|
|
887
|
+
if (command === 'intelligence') return intelligenceCommand(rawArgs);
|
|
888
|
+
if (command === 'brief') return briefCommand(rawArgs);
|
|
889
|
+
if (command === 'workflow') return workflowCommand(rawArgs);
|
|
890
|
+
if (command === 'plan') return planCommand(rawArgs);
|
|
891
|
+
if (command === 'generate') return generateCommand(rawArgs);
|
|
892
|
+
if (command === 'handoff') return handoffCommand(rawArgs);
|
|
893
|
+
if (command === 'release') return releaseCommand(rawArgs);
|
|
894
|
+
if (command === 'deploy') return deployCommand(rawArgs);
|
|
895
|
+
throw new Error(`Unknown command: ${[command, ...rawArgs].join(' ')}`);
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
main().catch((error) => {
|
|
899
|
+
console.error(`Cosmo: ${error.message}`);
|
|
900
|
+
process.exitCode = 1;
|
|
901
|
+
});
|