graphitect 0.2.0__py3-none-any.whl
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.
- graphify/__init__.py +30 -0
- graphify/__main__.py +757 -0
- graphify/_minhash.py +107 -0
- graphify/affected.py +318 -0
- graphify/always_on/agents-md.md +12 -0
- graphify/always_on/antigravity-rules.md +14 -0
- graphify/always_on/claude-md.md +9 -0
- graphify/always_on/gemini-md.md +9 -0
- graphify/always_on/kiro-steering.md +5 -0
- graphify/always_on/vscode-instructions.md +17 -0
- graphify/analyze.py +769 -0
- graphify/benchmark.py +152 -0
- graphify/build.py +2300 -0
- graphify/cache.py +1746 -0
- graphify/callflow_html.py +2051 -0
- graphify/cargo_introspect.py +109 -0
- graphify/cli.py +4745 -0
- graphify/cluster.py +409 -0
- graphify/command-kilo.md +15 -0
- graphify/cross_repo_calls.py +216 -0
- graphify/cross_repo_types.py +75 -0
- graphify/csharp_dispatch.py +154 -0
- graphify/dedup.py +1213 -0
- graphify/detect.py +2566 -0
- graphify/diagnostics.py +406 -0
- graphify/export.py +1349 -0
- graphify/exporters/__init__.py +1 -0
- graphify/exporters/base.py +14 -0
- graphify/exporters/graphdb.py +173 -0
- graphify/exporters/html.py +637 -0
- graphify/extract.py +7856 -0
- graphify/extractors/MIGRATION.md +107 -0
- graphify/extractors/__init__.py +66 -0
- graphify/extractors/apex.py +215 -0
- graphify/extractors/base.py +85 -0
- graphify/extractors/bash.py +579 -0
- graphify/extractors/blade.py +53 -0
- graphify/extractors/commonlisp.py +540 -0
- graphify/extractors/csharp.py +448 -0
- graphify/extractors/dart.py +564 -0
- graphify/extractors/dm.py +494 -0
- graphify/extractors/elixir.py +241 -0
- graphify/extractors/engine.py +6509 -0
- graphify/extractors/fortran.py +311 -0
- graphify/extractors/go.py +527 -0
- graphify/extractors/json_config.py +240 -0
- graphify/extractors/julia.py +289 -0
- graphify/extractors/markdown.py +408 -0
- graphify/extractors/models.py +131 -0
- graphify/extractors/objc.py +566 -0
- graphify/extractors/ocaml.py +289 -0
- graphify/extractors/pascal.py +688 -0
- graphify/extractors/pascal_forms.py +196 -0
- graphify/extractors/powershell.py +522 -0
- graphify/extractors/razor.py +192 -0
- graphify/extractors/resolution.py +3584 -0
- graphify/extractors/robot.py +296 -0
- graphify/extractors/rust.py +470 -0
- graphify/extractors/sln.py +92 -0
- graphify/extractors/sql.py +720 -0
- graphify/extractors/terraform.py +181 -0
- graphify/extractors/verilog.py +329 -0
- graphify/extractors/zig.py +181 -0
- graphify/file_slice.py +246 -0
- graphify/global_graph.py +194 -0
- graphify/google_workspace.py +237 -0
- graphify/hooks.py +933 -0
- graphify/ids.py +93 -0
- graphify/ingest.py +358 -0
- graphify/install.py +2366 -0
- graphify/llm.py +3544 -0
- graphify/manifest.py +4 -0
- graphify/manifest_ingest.py +311 -0
- graphify/mcp_ingest.py +386 -0
- graphify/multigraph_compat.py +212 -0
- graphify/pascal_resolution.py +129 -0
- graphify/paths.py +436 -0
- graphify/pg_introspect.py +165 -0
- graphify/prs.py +770 -0
- graphify/querylog.py +80 -0
- graphify/reflect.py +882 -0
- graphify/report.py +346 -0
- graphify/resolver_registry.py +85 -0
- graphify/ruby_resolution.py +242 -0
- graphify/scip_ingest.py +363 -0
- graphify/security.py +460 -0
- graphify/semantic_cleanup.py +336 -0
- graphify/serve.py +2608 -0
- graphify/skill-agents.md +710 -0
- graphify/skill-aider.md +1283 -0
- graphify/skill-amp.md +710 -0
- graphify/skill-claw.md +713 -0
- graphify/skill-codex.md +710 -0
- graphify/skill-copilot.md +713 -0
- graphify/skill-devin.md +1410 -0
- graphify/skill-droid.md +710 -0
- graphify/skill-kilo.md +722 -0
- graphify/skill-kiro.md +713 -0
- graphify/skill-opencode.md +705 -0
- graphify/skill-pi.md +713 -0
- graphify/skill-trae.md +711 -0
- graphify/skill-vscode.md +709 -0
- graphify/skill-windows.md +755 -0
- graphify/skill.md +713 -0
- graphify/skills/agents/references/add-watch.md +56 -0
- graphify/skills/agents/references/exports.md +87 -0
- graphify/skills/agents/references/extraction-spec.md +70 -0
- graphify/skills/agents/references/github-and-merge.md +46 -0
- graphify/skills/agents/references/hooks.md +33 -0
- graphify/skills/agents/references/query.md +311 -0
- graphify/skills/agents/references/transcribe.md +52 -0
- graphify/skills/agents/references/update.md +210 -0
- graphify/skills/amp/references/add-watch.md +56 -0
- graphify/skills/amp/references/exports.md +87 -0
- graphify/skills/amp/references/extraction-spec.md +70 -0
- graphify/skills/amp/references/github-and-merge.md +46 -0
- graphify/skills/amp/references/hooks.md +33 -0
- graphify/skills/amp/references/query.md +311 -0
- graphify/skills/amp/references/transcribe.md +52 -0
- graphify/skills/amp/references/update.md +210 -0
- graphify/skills/claude/references/add-watch.md +56 -0
- graphify/skills/claude/references/exports.md +87 -0
- graphify/skills/claude/references/extraction-spec.md +70 -0
- graphify/skills/claude/references/github-and-merge.md +46 -0
- graphify/skills/claude/references/hooks.md +33 -0
- graphify/skills/claude/references/query.md +311 -0
- graphify/skills/claude/references/transcribe.md +52 -0
- graphify/skills/claude/references/update.md +210 -0
- graphify/skills/claw/references/add-watch.md +56 -0
- graphify/skills/claw/references/exports.md +87 -0
- graphify/skills/claw/references/extraction-spec.md +31 -0
- graphify/skills/claw/references/github-and-merge.md +46 -0
- graphify/skills/claw/references/hooks.md +33 -0
- graphify/skills/claw/references/query.md +311 -0
- graphify/skills/claw/references/transcribe.md +52 -0
- graphify/skills/claw/references/update.md +210 -0
- graphify/skills/codex/references/add-watch.md +56 -0
- graphify/skills/codex/references/exports.md +87 -0
- graphify/skills/codex/references/extraction-spec.md +31 -0
- graphify/skills/codex/references/github-and-merge.md +46 -0
- graphify/skills/codex/references/hooks.md +33 -0
- graphify/skills/codex/references/query.md +311 -0
- graphify/skills/codex/references/transcribe.md +52 -0
- graphify/skills/codex/references/update.md +210 -0
- graphify/skills/copilot/references/add-watch.md +56 -0
- graphify/skills/copilot/references/exports.md +87 -0
- graphify/skills/copilot/references/extraction-spec.md +70 -0
- graphify/skills/copilot/references/github-and-merge.md +46 -0
- graphify/skills/copilot/references/hooks.md +33 -0
- graphify/skills/copilot/references/query.md +311 -0
- graphify/skills/copilot/references/transcribe.md +52 -0
- graphify/skills/copilot/references/update.md +210 -0
- graphify/skills/droid/references/add-watch.md +56 -0
- graphify/skills/droid/references/exports.md +87 -0
- graphify/skills/droid/references/extraction-spec.md +70 -0
- graphify/skills/droid/references/github-and-merge.md +46 -0
- graphify/skills/droid/references/hooks.md +33 -0
- graphify/skills/droid/references/query.md +311 -0
- graphify/skills/droid/references/transcribe.md +52 -0
- graphify/skills/droid/references/update.md +210 -0
- graphify/skills/kilo/references/add-watch.md +56 -0
- graphify/skills/kilo/references/exports.md +87 -0
- graphify/skills/kilo/references/extraction-spec.md +70 -0
- graphify/skills/kilo/references/github-and-merge.md +46 -0
- graphify/skills/kilo/references/hooks.md +33 -0
- graphify/skills/kilo/references/query.md +311 -0
- graphify/skills/kilo/references/transcribe.md +52 -0
- graphify/skills/kilo/references/update.md +210 -0
- graphify/skills/kiro/references/add-watch.md +56 -0
- graphify/skills/kiro/references/exports.md +87 -0
- graphify/skills/kiro/references/extraction-spec.md +31 -0
- graphify/skills/kiro/references/github-and-merge.md +46 -0
- graphify/skills/kiro/references/hooks.md +33 -0
- graphify/skills/kiro/references/query.md +311 -0
- graphify/skills/kiro/references/transcribe.md +52 -0
- graphify/skills/kiro/references/update.md +210 -0
- graphify/skills/opencode/references/add-watch.md +56 -0
- graphify/skills/opencode/references/exports.md +87 -0
- graphify/skills/opencode/references/extraction-spec.md +70 -0
- graphify/skills/opencode/references/github-and-merge.md +46 -0
- graphify/skills/opencode/references/hooks.md +33 -0
- graphify/skills/opencode/references/query.md +311 -0
- graphify/skills/opencode/references/transcribe.md +52 -0
- graphify/skills/opencode/references/update.md +210 -0
- graphify/skills/pi/references/add-watch.md +56 -0
- graphify/skills/pi/references/exports.md +87 -0
- graphify/skills/pi/references/extraction-spec.md +31 -0
- graphify/skills/pi/references/github-and-merge.md +46 -0
- graphify/skills/pi/references/hooks.md +33 -0
- graphify/skills/pi/references/query.md +311 -0
- graphify/skills/pi/references/transcribe.md +52 -0
- graphify/skills/pi/references/update.md +210 -0
- graphify/skills/trae/references/add-watch.md +56 -0
- graphify/skills/trae/references/exports.md +87 -0
- graphify/skills/trae/references/extraction-spec.md +70 -0
- graphify/skills/trae/references/github-and-merge.md +46 -0
- graphify/skills/trae/references/hooks.md +35 -0
- graphify/skills/trae/references/query.md +311 -0
- graphify/skills/trae/references/transcribe.md +52 -0
- graphify/skills/trae/references/update.md +210 -0
- graphify/skills/vscode/references/add-watch.md +56 -0
- graphify/skills/vscode/references/exports.md +87 -0
- graphify/skills/vscode/references/extraction-spec.md +70 -0
- graphify/skills/vscode/references/github-and-merge.md +46 -0
- graphify/skills/vscode/references/hooks.md +33 -0
- graphify/skills/vscode/references/query.md +311 -0
- graphify/skills/vscode/references/transcribe.md +52 -0
- graphify/skills/vscode/references/update.md +210 -0
- graphify/skills/windows/references/add-watch.md +56 -0
- graphify/skills/windows/references/exports.md +87 -0
- graphify/skills/windows/references/extraction-spec.md +70 -0
- graphify/skills/windows/references/github-and-merge.md +46 -0
- graphify/skills/windows/references/hooks.md +33 -0
- graphify/skills/windows/references/query.md +311 -0
- graphify/skills/windows/references/transcribe.md +52 -0
- graphify/skills/windows/references/update.md +210 -0
- graphify/symbol_resolution.py +556 -0
- graphify/transcribe.py +186 -0
- graphify/tree_html.py +603 -0
- graphify/validate.py +95 -0
- graphify/watch.py +2280 -0
- graphify/wiki.py +405 -0
- graphitect/__init__.py +28 -0
- graphitect/__main__.py +4 -0
- graphitect/_vendor/__init__.py +2 -0
- graphitect/_vendor/archify/LICENSE +22 -0
- graphitect/_vendor/archify/SKILL.md +137 -0
- graphitect/_vendor/archify/THIRD_PARTY_NOTICES.md +69 -0
- graphitect/_vendor/archify/assets/JetBrainsMono-OFL.txt +93 -0
- graphitect/_vendor/archify/assets/template.html +14935 -0
- graphitect/_vendor/archify/bin/archify.mjs +2091 -0
- graphitect/_vendor/archify/bin/open-artifact.mjs +86 -0
- graphitect/_vendor/archify/bin/preview.mjs +653 -0
- graphitect/_vendor/archify/bin/visual-check.mjs +829 -0
- graphitect/_vendor/archify/brand-marks/README.md +31 -0
- graphitect/_vendor/archify/brand-marks/catalog.json +131 -0
- graphitect/_vendor/archify/delta/architecture-delta.mjs +1221 -0
- graphitect/_vendor/archify/examples/agent-run.lifecycle.json +60 -0
- graphitect/_vendor/archify/examples/agent-tool-call.workflow.json +94 -0
- graphitect/_vendor/archify/examples/async-job-roundtrip.sequence.json +61 -0
- graphitect/_vendor/archify/examples/brand-aware-delivery.architecture.json +47 -0
- graphitect/_vendor/archify/examples/cache-miss-request.sequence.json +82 -0
- graphitect/_vendor/archify/examples/checkout-platform.base.architecture.json +31 -0
- graphitect/_vendor/archify/examples/checkout-platform.head.architecture.json +31 -0
- graphitect/_vendor/archify/examples/dataflow-product-analytics.html +15045 -0
- graphitect/_vendor/archify/examples/deployment-release.lifecycle.json +49 -0
- graphitect/_vendor/archify/examples/event-stream.dataflow.json +57 -0
- graphitect/_vendor/archify/examples/incident-response.workflow.json +64 -0
- graphitect/_vendor/archify/examples/lifecycle-agent-run.html +14980 -0
- graphitect/_vendor/archify/examples/product-analytics.dataflow.json +76 -0
- graphitect/_vendor/archify/examples/production-deployment.architecture.json +71 -0
- graphitect/_vendor/archify/examples/release-delivery.workflow.json +62 -0
- graphitect/_vendor/archify/examples/sequence-cache-miss-request.html +15060 -0
- graphitect/_vendor/archify/examples/web-app-rendered.html +15009 -0
- graphitect/_vendor/archify/examples/web-app.architecture.json +46 -0
- graphitect/_vendor/archify/examples/workflow-agent-tool-call-rendered.html +15051 -0
- graphitect/_vendor/archify/migrations/workflow-v2.mjs +279 -0
- graphitect/_vendor/archify/package-lock.json +149 -0
- graphitect/_vendor/archify/package.json +39 -0
- graphitect/_vendor/archify/recipes/scenarios.mjs +391 -0
- graphitect/_vendor/archify/references/authoring-contract.md +243 -0
- graphitect/_vendor/archify/references/brand-marks.md +65 -0
- graphitect/_vendor/archify/references/delivery-contract.md +120 -0
- graphitect/_vendor/archify/references/viewer-runtime.md +45 -0
- graphitect/_vendor/archify/renderers/architecture/grid.mjs +62 -0
- graphitect/_vendor/archify/renderers/architecture/render-architecture.mjs +1078 -0
- graphitect/_vendor/archify/renderers/dataflow/README.md +104 -0
- graphitect/_vendor/archify/renderers/dataflow/render-dataflow.mjs +483 -0
- graphitect/_vendor/archify/renderers/lifecycle/README.md +115 -0
- graphitect/_vendor/archify/renderers/lifecycle/render-lifecycle.mjs +561 -0
- graphitect/_vendor/archify/renderers/sequence/README.md +114 -0
- graphitect/_vendor/archify/renderers/sequence/render-sequence.mjs +464 -0
- graphitect/_vendor/archify/renderers/shared/brand-marks.mjs +563 -0
- graphitect/_vendor/archify/renderers/shared/cli.mjs +218 -0
- graphitect/_vendor/archify/renderers/shared/desktop-readability.mjs +26 -0
- graphitect/_vendor/archify/renderers/shared/diagnostics.mjs +127 -0
- graphitect/_vendor/archify/renderers/shared/engineering-profiles.mjs +157 -0
- graphitect/_vendor/archify/renderers/shared/generated-brand-marks.mjs +2003 -0
- graphitect/_vendor/archify/renderers/shared/generated-validators.mjs +13 -0
- graphitect/_vendor/archify/renderers/shared/geometry.mjs +1423 -0
- graphitect/_vendor/archify/renderers/shared/i18n.mjs +595 -0
- graphitect/_vendor/archify/renderers/shared/layout-report.mjs +40 -0
- graphitect/_vendor/archify/renderers/shared/legend.mjs +217 -0
- graphitect/_vendor/archify/renderers/shared/output-path.mjs +340 -0
- graphitect/_vendor/archify/renderers/shared/repository-evidence.mjs +238 -0
- graphitect/_vendor/archify/renderers/shared/repository-location.mjs +58 -0
- graphitect/_vendor/archify/renderers/shared/text-fit.mjs +49 -0
- graphitect/_vendor/archify/renderers/shared/utils.mjs +232 -0
- graphitect/_vendor/archify/renderers/shared/validator.mjs +86 -0
- graphitect/_vendor/archify/renderers/workflow/README.md +223 -0
- graphitect/_vendor/archify/renderers/workflow/render-workflow.mjs +35 -0
- graphitect/_vendor/archify/renderers/workflow/workflow-compiler.mjs +4400 -0
- graphitect/_vendor/archify/renderers/workflow/workflow-migration-geometry.mjs +144 -0
- graphitect/_vendor/archify/schemas/README.md +211 -0
- graphitect/_vendor/archify/schemas/architecture.schema.json +178 -0
- graphitect/_vendor/archify/schemas/common.schema.json +115 -0
- graphitect/_vendor/archify/schemas/dataflow.schema.json +243 -0
- graphitect/_vendor/archify/schemas/lifecycle.schema.json +266 -0
- graphitect/_vendor/archify/schemas/sequence.schema.json +223 -0
- graphitect/_vendor/archify/schemas/workflow.schema.json +428 -0
- graphitect/_vendor/archify/scripts/check-render-output.mjs +836 -0
- graphitect/_vendor/archify/scripts/check-update.mjs +1667 -0
- graphitect/_vendor/archify/scripts/generate-brand-marks.mjs +141 -0
- graphitect/_vendor/archify/scripts/generate-validators.mjs +66 -0
- graphitect/_vendor/archify/scripts/render-examples.mjs +26 -0
- graphitect/_vendor/archify/scripts/update-contract.mjs +182 -0
- graphitect/_vendor/archify/skill-release.json +10 -0
- graphitect/cli.py +981 -0
- graphitect/deliver/__init__.py +5 -0
- graphitect/deliver/archify_adapter.py +1877 -0
- graphitect/deliver/archify_ir.py +160 -0
- graphitect/deliver/archify_repair.py +135 -0
- graphitect/deliver/doc_compiler.py +916 -0
- graphitect/ground/__init__.py +5 -0
- graphitect/ground/describe_source.py +27 -0
- graphitect/ground/fullread_source.py +56 -0
- graphitect/ground/graphify_source.py +107 -0
- graphitect/models.py +118 -0
- graphitect/skill/SKILL.md +80 -0
- graphitect/skill/agents/openai.yaml +4 -0
- graphitect/synthesize/__init__.py +5 -0
- graphitect/synthesize/engine.py +281 -0
- graphitect/synthesize/llm_backend.py +331 -0
- graphitect/synthesize/questions.py +139 -0
- graphitect/synthesize/rubric.py +104 -0
- graphitect-0.2.0.dist-info/METADATA +284 -0
- graphitect-0.2.0.dist-info/RECORD +336 -0
- graphitect-0.2.0.dist-info/WHEEL +5 -0
- graphitect-0.2.0.dist-info/entry_points.txt +2 -0
- graphitect-0.2.0.dist-info/licenses/LICENSE +21 -0
- graphitect-0.2.0.dist-info/licenses/LICENSE-ARCHIFY-MIT +22 -0
- graphitect-0.2.0.dist-info/licenses/LICENSE-GRAPHIFY-APACHE-2.0 +202 -0
- graphitect-0.2.0.dist-info/licenses/LICENSE-GRAPHIFY-MIT +21 -0
- graphitect-0.2.0.dist-info/licenses/NOTICE-ARCHIFY-THIRD-PARTY.md +69 -0
- graphitect-0.2.0.dist-info/licenses/NOTICE-GRAPHIFY +8 -0
- graphitect-0.2.0.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1,653 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import http from 'node:http';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
|
|
8
|
+
import { openLoopbackUrl } from './open-artifact.mjs';
|
|
9
|
+
import { resolveOutputPath } from '../renderers/shared/output-path.mjs';
|
|
10
|
+
|
|
11
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
const cliPath = path.join(here, 'archify.mjs');
|
|
13
|
+
const loopbackHost = '127.0.0.1';
|
|
14
|
+
const defaultDebounceMs = 400;
|
|
15
|
+
const defaultPollMs = 800;
|
|
16
|
+
const defaultStopGraceMs = 3000;
|
|
17
|
+
const defaultStopKillMs = 750;
|
|
18
|
+
const diagramTypes = new Set(['architecture', 'workflow', 'sequence', 'dataflow', 'lifecycle']);
|
|
19
|
+
|
|
20
|
+
function sha256(value) {
|
|
21
|
+
return createHash('sha256').update(value).digest('hex');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function sourceDigest(inputPath) {
|
|
25
|
+
try {
|
|
26
|
+
const bytes = fs.readFileSync(inputPath);
|
|
27
|
+
return { hash: sha256(bytes), bytes, missing: false };
|
|
28
|
+
} catch (error) {
|
|
29
|
+
return { hash: `unreadable:${error.code || 'unknown'}`, bytes: null, missing: true };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function initialAuthoredOutput(inputPath) {
|
|
34
|
+
try {
|
|
35
|
+
const source = JSON.parse(fs.readFileSync(inputPath, 'utf8'));
|
|
36
|
+
if (typeof source?.meta?.output === 'string' && source.meta.output) {
|
|
37
|
+
return source.meta.output;
|
|
38
|
+
}
|
|
39
|
+
} catch {
|
|
40
|
+
// An invalid initial source still gets a status shell. Its output target is
|
|
41
|
+
// fixed to the same fallback that `deliver` would use after repair.
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function previewPage() {
|
|
47
|
+
return `<!doctype html>
|
|
48
|
+
<html lang="en">
|
|
49
|
+
<head>
|
|
50
|
+
<meta charset="utf-8">
|
|
51
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
52
|
+
<title>Archify Live Preview</title>
|
|
53
|
+
<style>
|
|
54
|
+
:root { color-scheme: light dark; font-family: Inter, ui-sans-serif, system-ui, sans-serif; }
|
|
55
|
+
* { box-sizing: border-box; }
|
|
56
|
+
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #0b111b; }
|
|
57
|
+
body { display: grid; grid-template-rows: auto minmax(0, 1fr); color: #e8edf5; }
|
|
58
|
+
header { position: relative; z-index: 2; display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 7px 12px; border-bottom: 1px solid #253248; background: rgba(11, 17, 27, .96); box-shadow: 0 8px 22px rgba(0,0,0,.18); }
|
|
59
|
+
.brand { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #9cadc6; }
|
|
60
|
+
#status { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; min-height: 30px; padding: 5px 10px; border: 1px solid #33435d; border-radius: 999px; background: #111b2a; font-size: 12px; white-space: nowrap; }
|
|
61
|
+
#status::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: #6f819d; }
|
|
62
|
+
body[data-state="checking"] #status::before { background: #f3b44b; box-shadow: 0 0 0 4px rgba(243,180,75,.12); }
|
|
63
|
+
body[data-state="verified"] #status::before { background: #45d6a8; box-shadow: 0 0 0 4px rgba(69,214,168,.12); }
|
|
64
|
+
body[data-state="needs-fix"] #status::before { background: #ff6f78; box-shadow: 0 0 0 4px rgba(255,111,120,.12); }
|
|
65
|
+
details { max-width: min(62vw, 760px); }
|
|
66
|
+
summary { cursor: pointer; color: #ffbdc2; font-size: 12px; }
|
|
67
|
+
.diagnostic { position: absolute; top: 38px; right: 12px; width: min(760px, calc(100vw - 24px)); max-height: min(44vh, 360px); overflow: auto; padding: 14px; border: 1px solid #6a3440; border-radius: 10px; background: #17131b; box-shadow: 0 14px 48px rgba(0,0,0,.42); }
|
|
68
|
+
pre { margin: 0 0 10px; white-space: pre-wrap; overflow-wrap: anywhere; font: 11px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; color: #f2dfe2; }
|
|
69
|
+
button { min-height: 32px; padding: 5px 10px; border: 1px solid #4a5d79; border-radius: 7px; background: #1a273a; color: #eef4ff; cursor: pointer; }
|
|
70
|
+
main { position: relative; min-height: 0; }
|
|
71
|
+
iframe { display: none; width: 100%; height: 100%; border: 0; background: #fff; }
|
|
72
|
+
body[data-has-artifact="true"] iframe { display: block; }
|
|
73
|
+
#empty { position: absolute; inset: 0; display: grid; place-items: center; padding: 32px; color: #91a2bc; text-align: center; background: radial-gradient(circle at 50% 38%, #15233a 0, #0b111b 55%); }
|
|
74
|
+
body[data-has-artifact="true"] #empty { display: none; }
|
|
75
|
+
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
|
|
76
|
+
</style>
|
|
77
|
+
</head>
|
|
78
|
+
<body data-state="checking" data-has-artifact="false">
|
|
79
|
+
<header>
|
|
80
|
+
<span class="brand">Archify Preview</span>
|
|
81
|
+
<details id="failure" hidden>
|
|
82
|
+
<summary role="button" aria-controls="diagnostic-panel">View diagnostic</summary>
|
|
83
|
+
<div class="diagnostic" id="diagnostic-panel"><pre id="diagnostic"></pre><button id="copy" type="button">Copy diagnostic</button></div>
|
|
84
|
+
</details>
|
|
85
|
+
<span id="status" role="status" aria-live="polite">Checking · generation 1</span>
|
|
86
|
+
</header>
|
|
87
|
+
<main>
|
|
88
|
+
<div id="empty">Waiting for the first verified diagram. Invalid input will stay here with an exact diagnostic.</div>
|
|
89
|
+
<iframe id="artifact" title="Verified Archify diagram"></iframe>
|
|
90
|
+
</main>
|
|
91
|
+
<script>
|
|
92
|
+
(function () {
|
|
93
|
+
'use strict';
|
|
94
|
+
var body = document.body;
|
|
95
|
+
var status = document.getElementById('status');
|
|
96
|
+
var failure = document.getElementById('failure');
|
|
97
|
+
var diagnostic = document.getElementById('diagnostic');
|
|
98
|
+
var artifact = document.getElementById('artifact');
|
|
99
|
+
var lastRevision = 0;
|
|
100
|
+
|
|
101
|
+
function render(state) {
|
|
102
|
+
body.dataset.state = state.status;
|
|
103
|
+
if (state.status === 'verified') {
|
|
104
|
+
status.textContent = 'Verified · rev ' + state.revision;
|
|
105
|
+
failure.hidden = true;
|
|
106
|
+
failure.open = false;
|
|
107
|
+
if (state.revision !== lastRevision) {
|
|
108
|
+
lastRevision = state.revision;
|
|
109
|
+
artifact.src = '/artifact.html?revision=' + encodeURIComponent(state.revision) + '&sha=' + encodeURIComponent(state.lastVerified.sha256.slice(0, 12));
|
|
110
|
+
body.dataset.hasArtifact = 'true';
|
|
111
|
+
}
|
|
112
|
+
} else if (state.status === 'needs-fix') {
|
|
113
|
+
status.textContent = 'Needs fix · ' + (state.revision ? 'showing rev ' + state.revision : 'no verified revision');
|
|
114
|
+
diagnostic.textContent = 'Generation ' + state.generation + ' · ' + state.failure.stage + '\\n\\n' + state.failure.message;
|
|
115
|
+
failure.hidden = false;
|
|
116
|
+
} else {
|
|
117
|
+
status.textContent = 'Checking · generation ' + state.generation;
|
|
118
|
+
failure.hidden = true;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
document.getElementById('copy').addEventListener('click', function () {
|
|
123
|
+
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
124
|
+
navigator.clipboard.writeText(diagnostic.textContent).catch(function () {});
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
var events = new EventSource('/events');
|
|
129
|
+
events.addEventListener('state', function (event) {
|
|
130
|
+
try { render(JSON.parse(event.data)); } catch (_) {}
|
|
131
|
+
});
|
|
132
|
+
}());
|
|
133
|
+
</script>
|
|
134
|
+
</body>
|
|
135
|
+
</html>`;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function compactMessage(value) {
|
|
139
|
+
let text = String(value || 'Preview build failed without a diagnostic.').trim();
|
|
140
|
+
const lines = text.split(/\r?\n/);
|
|
141
|
+
const errorLine = lines.findIndex((line) => /^Error:\s/.test(line));
|
|
142
|
+
if (errorLine > 0) text = lines.slice(errorLine).join('\n');
|
|
143
|
+
const relevant = text.split(/\r?\n/);
|
|
144
|
+
const stackLine = relevant.findIndex((line, index) => index > 0 && /^\s*at\s/.test(line));
|
|
145
|
+
if (stackLine > 0) text = relevant.slice(0, stackLine).join('\n');
|
|
146
|
+
return text.length > 6000 ? `${text.slice(0, 6000)}\n… diagnostic truncated` : text;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function redactDiagnostic(value, paths) {
|
|
150
|
+
let text = compactMessage(value);
|
|
151
|
+
for (const [absolutePath, replacement] of paths) {
|
|
152
|
+
if (!absolutePath) continue;
|
|
153
|
+
text = text.split(absolutePath).join(replacement);
|
|
154
|
+
}
|
|
155
|
+
return text;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function safeJson(value) {
|
|
159
|
+
return JSON.stringify(value).replace(/</g, '\\u003c');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function responseHeaders(contentType) {
|
|
163
|
+
return {
|
|
164
|
+
'Cache-Control': 'no-store',
|
|
165
|
+
'Content-Type': contentType,
|
|
166
|
+
'Cross-Origin-Resource-Policy': 'same-origin',
|
|
167
|
+
'Referrer-Policy': 'no-referrer',
|
|
168
|
+
'X-Content-Type-Options': 'nosniff',
|
|
169
|
+
'X-Frame-Options': 'SAMEORIGIN',
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function parseReceipt(stdout) {
|
|
174
|
+
try {
|
|
175
|
+
return JSON.parse(stdout);
|
|
176
|
+
} catch {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export async function startPreview(options) {
|
|
182
|
+
const type = options.type;
|
|
183
|
+
if (!diagramTypes.has(type)) throw new Error(`Unknown diagram type "${type}".`);
|
|
184
|
+
if (options.quality && !['standard', 'showcase'].includes(options.quality)) {
|
|
185
|
+
throw new Error(`Unknown quality profile "${options.quality}".`);
|
|
186
|
+
}
|
|
187
|
+
const inputPath = path.resolve(options.input);
|
|
188
|
+
const outputRequest = {
|
|
189
|
+
requestedOutput: options.output,
|
|
190
|
+
authoredOutput: initialAuthoredOutput(inputPath),
|
|
191
|
+
defaultOutput: `${type}.html`,
|
|
192
|
+
inputPaths: [inputPath],
|
|
193
|
+
inputDescription: 'its JSON input',
|
|
194
|
+
cwd: options.cwd || process.cwd(),
|
|
195
|
+
};
|
|
196
|
+
const { outputPath } = resolveOutputPath(outputRequest);
|
|
197
|
+
const outputDirectory = path.dirname(outputPath);
|
|
198
|
+
const debounceMs = Number.isFinite(options.debounceMs) ? options.debounceMs : defaultDebounceMs;
|
|
199
|
+
const pollMs = Number.isFinite(options.pollMs) ? options.pollMs : defaultPollMs;
|
|
200
|
+
const stopGraceMs = Number.isFinite(options.stopGraceMs) ? Math.max(0, options.stopGraceMs) : defaultStopGraceMs;
|
|
201
|
+
const stopKillMs = Number.isFinite(options.stopKillMs) ? Math.max(0, options.stopKillMs) : defaultStopKillMs;
|
|
202
|
+
const shouldOpen = options.open !== false;
|
|
203
|
+
|
|
204
|
+
fs.mkdirSync(outputDirectory, { recursive: true });
|
|
205
|
+
const stagingDirectory = fs.mkdtempSync(path.join(outputDirectory, '.archify-preview-'));
|
|
206
|
+
|
|
207
|
+
let port = 0;
|
|
208
|
+
let watcher;
|
|
209
|
+
let debounceTimer;
|
|
210
|
+
let pollTimer;
|
|
211
|
+
let stopGraceTimer;
|
|
212
|
+
let stopKillTimer;
|
|
213
|
+
let child;
|
|
214
|
+
let stopping = false;
|
|
215
|
+
let stopped = false;
|
|
216
|
+
let serverClosing = false;
|
|
217
|
+
let serverClosed = false;
|
|
218
|
+
let queuedHash = null;
|
|
219
|
+
let activeHash = null;
|
|
220
|
+
let lastGoodSourceHash = null;
|
|
221
|
+
let sourceEpoch = 0;
|
|
222
|
+
let activeEpoch = 0;
|
|
223
|
+
let pendingBuild = false;
|
|
224
|
+
let artifactBuffer = null;
|
|
225
|
+
const clients = new Set();
|
|
226
|
+
const state = {
|
|
227
|
+
schemaVersion: 1,
|
|
228
|
+
status: 'checking',
|
|
229
|
+
generation: 0,
|
|
230
|
+
revision: 0,
|
|
231
|
+
lastVerified: null,
|
|
232
|
+
failure: null,
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
let resolveClosed;
|
|
236
|
+
const closed = new Promise((resolve) => { resolveClosed = resolve; });
|
|
237
|
+
|
|
238
|
+
function publicState() {
|
|
239
|
+
return JSON.parse(JSON.stringify(state));
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function sendState(res) {
|
|
243
|
+
res.write(`event: state\ndata: ${safeJson(publicState())}\n\n`);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function broadcast() {
|
|
247
|
+
for (const res of clients) sendState(res);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const page = Buffer.from(previewPage());
|
|
251
|
+
const server = http.createServer((req, res) => {
|
|
252
|
+
const expectedHost = `${loopbackHost}:${port}`;
|
|
253
|
+
if (req.headers.host !== expectedHost) {
|
|
254
|
+
res.writeHead(403, responseHeaders('text/plain; charset=utf-8'));
|
|
255
|
+
res.end('Forbidden host');
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
|
259
|
+
res.writeHead(405, { ...responseHeaders('text/plain; charset=utf-8'), Allow: 'GET, HEAD' });
|
|
260
|
+
res.end('Method not allowed');
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
let url;
|
|
265
|
+
try {
|
|
266
|
+
url = new URL(req.url, `http://${expectedHost}`);
|
|
267
|
+
} catch {
|
|
268
|
+
res.writeHead(400, responseHeaders('text/plain; charset=utf-8'));
|
|
269
|
+
res.end('Bad request');
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (url.pathname === '/') {
|
|
274
|
+
res.writeHead(200, {
|
|
275
|
+
...responseHeaders('text/html; charset=utf-8'),
|
|
276
|
+
'Content-Security-Policy': "default-src 'none'; frame-src 'self'; connect-src 'self'; script-src 'unsafe-inline'; style-src 'unsafe-inline'",
|
|
277
|
+
'Content-Length': page.byteLength,
|
|
278
|
+
});
|
|
279
|
+
if (req.method === 'HEAD') res.end();
|
|
280
|
+
else res.end(page);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
if (url.pathname === '/state') {
|
|
284
|
+
const body = Buffer.from(`${safeJson(publicState())}\n`);
|
|
285
|
+
res.writeHead(200, { ...responseHeaders('application/json; charset=utf-8'), 'Content-Length': body.byteLength });
|
|
286
|
+
if (req.method === 'HEAD') res.end();
|
|
287
|
+
else res.end(body);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
if (url.pathname === '/artifact.html') {
|
|
291
|
+
if (!artifactBuffer) {
|
|
292
|
+
res.writeHead(404, responseHeaders('text/plain; charset=utf-8'));
|
|
293
|
+
res.end('No verified artifact yet');
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
res.writeHead(200, { ...responseHeaders('text/html; charset=utf-8'), 'Content-Length': artifactBuffer.byteLength });
|
|
297
|
+
if (req.method === 'HEAD') res.end();
|
|
298
|
+
else res.end(artifactBuffer);
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
if (url.pathname === '/events' && req.method === 'GET') {
|
|
302
|
+
res.writeHead(200, {
|
|
303
|
+
...responseHeaders('text/event-stream; charset=utf-8'),
|
|
304
|
+
Connection: 'keep-alive',
|
|
305
|
+
});
|
|
306
|
+
res.write('retry: 1000\n\n');
|
|
307
|
+
clients.add(res);
|
|
308
|
+
sendState(res);
|
|
309
|
+
req.on('close', () => clients.delete(res));
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
res.writeHead(404, responseHeaders('text/plain; charset=utf-8'));
|
|
314
|
+
res.end('Not found');
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
try {
|
|
318
|
+
await new Promise((resolve, reject) => {
|
|
319
|
+
server.once('error', reject);
|
|
320
|
+
server.listen(0, loopbackHost, () => {
|
|
321
|
+
server.off('error', reject);
|
|
322
|
+
port = server.address().port;
|
|
323
|
+
resolve();
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
} catch (error) {
|
|
327
|
+
try { server.close(); } catch {}
|
|
328
|
+
fs.rmSync(stagingDirectory, { recursive: true, force: true });
|
|
329
|
+
throw error;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const url = `http://${loopbackHost}:${port}/`;
|
|
333
|
+
|
|
334
|
+
function finishStop() {
|
|
335
|
+
if (stopped || child || !serverClosed) return;
|
|
336
|
+
stopped = true;
|
|
337
|
+
clearTimeout(debounceTimer);
|
|
338
|
+
clearInterval(pollTimer);
|
|
339
|
+
clearTimeout(stopGraceTimer);
|
|
340
|
+
clearTimeout(stopKillTimer);
|
|
341
|
+
try {
|
|
342
|
+
fs.rmSync(stagingDirectory, { recursive: true, force: true });
|
|
343
|
+
} finally {
|
|
344
|
+
resolveClosed();
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function signalActiveChild(signal) {
|
|
349
|
+
if (!child || child.exitCode !== null || child.signalCode !== null) return;
|
|
350
|
+
try {
|
|
351
|
+
if (process.platform !== 'win32' && child.pid) process.kill(-child.pid, signal);
|
|
352
|
+
else child.kill(signal);
|
|
353
|
+
} catch (error) {
|
|
354
|
+
if (error.code === 'ESRCH') return;
|
|
355
|
+
try { child.kill(signal); } catch {}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function closeServer() {
|
|
360
|
+
if (serverClosing) return;
|
|
361
|
+
serverClosing = true;
|
|
362
|
+
for (const res of clients) res.end();
|
|
363
|
+
clients.clear();
|
|
364
|
+
server.close(() => {
|
|
365
|
+
serverClosed = true;
|
|
366
|
+
finishStop();
|
|
367
|
+
});
|
|
368
|
+
server.closeIdleConnections?.();
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function startBoundedChildDrain() {
|
|
372
|
+
if (!child || stopGraceTimer || stopKillTimer) return;
|
|
373
|
+
stopGraceTimer = setTimeout(() => {
|
|
374
|
+
stopGraceTimer = undefined;
|
|
375
|
+
if (!child) return finishStop();
|
|
376
|
+
signalActiveChild('SIGTERM');
|
|
377
|
+
stopKillTimer = setTimeout(() => {
|
|
378
|
+
stopKillTimer = undefined;
|
|
379
|
+
signalActiveChild('SIGKILL');
|
|
380
|
+
}, stopKillMs);
|
|
381
|
+
}, stopGraceMs);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
async function stop({ force = false } = {}) {
|
|
385
|
+
if (!stopping) {
|
|
386
|
+
stopping = true;
|
|
387
|
+
clearTimeout(debounceTimer);
|
|
388
|
+
clearInterval(pollTimer);
|
|
389
|
+
watcher?.close();
|
|
390
|
+
closeServer();
|
|
391
|
+
}
|
|
392
|
+
if (child && force) {
|
|
393
|
+
clearTimeout(stopGraceTimer);
|
|
394
|
+
clearTimeout(stopKillTimer);
|
|
395
|
+
stopGraceTimer = undefined;
|
|
396
|
+
stopKillTimer = undefined;
|
|
397
|
+
signalActiveChild('SIGKILL');
|
|
398
|
+
} else if (child) {
|
|
399
|
+
startBoundedChildDrain();
|
|
400
|
+
} else {
|
|
401
|
+
finishStop();
|
|
402
|
+
}
|
|
403
|
+
return closed;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function publishFailure(receipt, stdout, stderr, candidatePath, snapshotPath) {
|
|
407
|
+
const repairDetails = receipt?.diagnostics
|
|
408
|
+
?.slice(0, 12)
|
|
409
|
+
.map((entry) => {
|
|
410
|
+
const fix = entry.supportedFixes?.length ? `\nFix: ${entry.supportedFixes.join('; ')}` : '';
|
|
411
|
+
return `[${entry.code}] ${entry.message}${fix}`;
|
|
412
|
+
}) || [];
|
|
413
|
+
const checkerDetails = receipt?.checker?.checks
|
|
414
|
+
?.filter((check) => !check.ok)
|
|
415
|
+
.flatMap((check) => check.details || [])
|
|
416
|
+
.filter(Boolean)
|
|
417
|
+
.slice(0, 12) || [];
|
|
418
|
+
const diagnostic = [
|
|
419
|
+
receipt?.error,
|
|
420
|
+
...(repairDetails.length ? repairDetails : checkerDetails),
|
|
421
|
+
].filter(Boolean).join('\n') || stderr || stdout;
|
|
422
|
+
state.status = 'needs-fix';
|
|
423
|
+
state.failure = {
|
|
424
|
+
stage: receipt?.stage || 'render',
|
|
425
|
+
message: redactDiagnostic(
|
|
426
|
+
diagnostic,
|
|
427
|
+
[
|
|
428
|
+
[inputPath, '<input.json>'],
|
|
429
|
+
[outputPath, '<output.html>'],
|
|
430
|
+
[snapshotPath, '<input.json>'],
|
|
431
|
+
[candidatePath, '<candidate.html>'],
|
|
432
|
+
[stagingDirectory, '<preview-staging>'],
|
|
433
|
+
[path.resolve(here, '..'), '<archify-skill>'],
|
|
434
|
+
[path.resolve(options.cwd || process.cwd()), '<working-directory>'],
|
|
435
|
+
...(options.repoRoot ? [[path.resolve(options.repoRoot), '<repo-root>']] : []),
|
|
436
|
+
],
|
|
437
|
+
),
|
|
438
|
+
};
|
|
439
|
+
broadcast();
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function commitCandidate(candidatePath, receipt, generationHash) {
|
|
443
|
+
let candidate;
|
|
444
|
+
try {
|
|
445
|
+
candidate = fs.readFileSync(candidatePath);
|
|
446
|
+
const digest = sha256(candidate);
|
|
447
|
+
if (digest !== receipt?.artifact?.sha256) {
|
|
448
|
+
throw new Error('Verified candidate bytes do not match the delivery receipt.');
|
|
449
|
+
}
|
|
450
|
+
resolveOutputPath(outputRequest);
|
|
451
|
+
const sameArtifact = state.lastVerified?.sha256 === digest;
|
|
452
|
+
let outputMatches = false;
|
|
453
|
+
if (sameArtifact) {
|
|
454
|
+
try { outputMatches = sha256(fs.readFileSync(outputPath)) === digest; } catch {}
|
|
455
|
+
}
|
|
456
|
+
const currentSource = sourceDigest(inputPath);
|
|
457
|
+
if (currentSource.hash !== generationHash) {
|
|
458
|
+
return { committed: false, supersededBy: currentSource };
|
|
459
|
+
}
|
|
460
|
+
if (!sameArtifact || !outputMatches) fs.renameSync(candidatePath, outputPath);
|
|
461
|
+
artifactBuffer = candidate;
|
|
462
|
+
lastGoodSourceHash = generationHash;
|
|
463
|
+
state.status = 'verified';
|
|
464
|
+
if (!sameArtifact) {
|
|
465
|
+
state.revision += 1;
|
|
466
|
+
state.lastVerified = {
|
|
467
|
+
sha256: digest,
|
|
468
|
+
bytes: candidate.byteLength,
|
|
469
|
+
checksPassed: receipt.validation.checksPassed,
|
|
470
|
+
checkCount: receipt.validation.checkCount,
|
|
471
|
+
compositionProfile: receipt.validation.compositionProfile,
|
|
472
|
+
compositionStatus: receipt.validation.compositionStatus,
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
state.failure = null;
|
|
476
|
+
broadcast();
|
|
477
|
+
return { committed: true, supersededBy: null };
|
|
478
|
+
} catch (error) {
|
|
479
|
+
publishFailure({ stage: 'commit', error: `Could not publish the verified preview: ${error.message}` }, '', '', candidatePath);
|
|
480
|
+
return { committed: false, supersededBy: null };
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
function beginBuild(digest, epoch) {
|
|
485
|
+
if (stopping || child) return;
|
|
486
|
+
activeHash = digest.hash;
|
|
487
|
+
activeEpoch = epoch;
|
|
488
|
+
state.generation += 1;
|
|
489
|
+
state.status = 'checking';
|
|
490
|
+
state.failure = null;
|
|
491
|
+
broadcast();
|
|
492
|
+
|
|
493
|
+
const candidatePath = path.join(stagingDirectory, `generation-${state.generation}.html`);
|
|
494
|
+
const snapshotPath = path.join(stagingDirectory, `generation-${state.generation}.json`);
|
|
495
|
+
if (digest.bytes !== null) {
|
|
496
|
+
try {
|
|
497
|
+
fs.writeFileSync(snapshotPath, digest.bytes, { flag: 'wx', mode: 0o600 });
|
|
498
|
+
} catch (error) {
|
|
499
|
+
publishFailure(
|
|
500
|
+
{ stage: 'prepare', error: `Could not snapshot the observed input: ${error.message}` },
|
|
501
|
+
'',
|
|
502
|
+
'',
|
|
503
|
+
candidatePath,
|
|
504
|
+
snapshotPath,
|
|
505
|
+
);
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
const args = [options.deliveryCli || cliPath, 'deliver', type, snapshotPath, candidatePath, '--json'];
|
|
510
|
+
if (options.quality) args.push('--quality', options.quality);
|
|
511
|
+
if (options.repoRoot) args.push('--repo-root', path.resolve(options.repoRoot));
|
|
512
|
+
let stdout = '';
|
|
513
|
+
let stderr = '';
|
|
514
|
+
child = spawn(process.execPath, args, {
|
|
515
|
+
cwd: options.cwd || process.cwd(),
|
|
516
|
+
env: process.env,
|
|
517
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
518
|
+
detached: process.platform !== 'win32',
|
|
519
|
+
});
|
|
520
|
+
child.stdout.setEncoding('utf8');
|
|
521
|
+
child.stderr.setEncoding('utf8');
|
|
522
|
+
child.stdout.on('data', (chunk) => { stdout += chunk; });
|
|
523
|
+
child.stderr.on('data', (chunk) => { stderr += chunk; });
|
|
524
|
+
child.on('error', (error) => { stderr += error.message; });
|
|
525
|
+
child.on('close', (code) => {
|
|
526
|
+
const receipt = parseReceipt(stdout);
|
|
527
|
+
const generationEpoch = activeEpoch;
|
|
528
|
+
const generationHash = activeHash;
|
|
529
|
+
const stale = generationEpoch !== sourceEpoch;
|
|
530
|
+
let supersededBy = null;
|
|
531
|
+
child = null;
|
|
532
|
+
clearTimeout(stopGraceTimer);
|
|
533
|
+
clearTimeout(stopKillTimer);
|
|
534
|
+
stopGraceTimer = undefined;
|
|
535
|
+
stopKillTimer = undefined;
|
|
536
|
+
if (!stopping && !stale && code === 0 && receipt?.ok) {
|
|
537
|
+
({ supersededBy } = commitCandidate(candidatePath, receipt, generationHash));
|
|
538
|
+
} else if (!stopping && !stale) {
|
|
539
|
+
publishFailure(receipt, stdout, stderr, candidatePath, snapshotPath);
|
|
540
|
+
}
|
|
541
|
+
try { fs.rmSync(candidatePath, { force: true }); } catch {}
|
|
542
|
+
try { fs.rmSync(snapshotPath, { force: true }); } catch {}
|
|
543
|
+
|
|
544
|
+
if (stopping) {
|
|
545
|
+
finishStop();
|
|
546
|
+
} else if (pendingBuild || stale || supersededBy) {
|
|
547
|
+
pendingBuild = false;
|
|
548
|
+
if (supersededBy && sourceEpoch === generationEpoch) sourceEpoch += 1;
|
|
549
|
+
const digest = supersededBy || sourceDigest(inputPath);
|
|
550
|
+
queueStableBuild(digest.hash, true);
|
|
551
|
+
}
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
function queueStableBuild(hash, immediate = false) {
|
|
556
|
+
queuedHash = hash;
|
|
557
|
+
clearTimeout(debounceTimer);
|
|
558
|
+
const launch = () => {
|
|
559
|
+
if (stopping) return;
|
|
560
|
+
const digest = sourceDigest(inputPath);
|
|
561
|
+
if (digest.hash !== queuedHash) {
|
|
562
|
+
queueStableBuild(digest.hash);
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
if (digest.hash === lastGoodSourceHash) {
|
|
566
|
+
if (state.status !== 'verified' && state.lastVerified) {
|
|
567
|
+
state.status = 'verified';
|
|
568
|
+
state.failure = null;
|
|
569
|
+
broadcast();
|
|
570
|
+
}
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
if (child) {
|
|
574
|
+
pendingBuild = true;
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
beginBuild(digest, sourceEpoch);
|
|
578
|
+
};
|
|
579
|
+
debounceTimer = setTimeout(launch, immediate ? 0 : debounceMs);
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
function observeSource({ immediate = false } = {}) {
|
|
583
|
+
const digest = sourceDigest(inputPath);
|
|
584
|
+
if (!immediate && digest.hash === queuedHash) return;
|
|
585
|
+
sourceEpoch += 1;
|
|
586
|
+
queueStableBuild(digest.hash, immediate);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
if (options.watch !== false) {
|
|
590
|
+
try {
|
|
591
|
+
watcher = fs.watch(path.dirname(inputPath), (event, filename) => {
|
|
592
|
+
if (!filename || filename.toString() === path.basename(inputPath)) observeSource();
|
|
593
|
+
});
|
|
594
|
+
watcher.on('error', () => {
|
|
595
|
+
const failedWatcher = watcher;
|
|
596
|
+
watcher = undefined;
|
|
597
|
+
failedWatcher?.close();
|
|
598
|
+
});
|
|
599
|
+
} catch (error) {
|
|
600
|
+
await stop();
|
|
601
|
+
throw new Error(`Could not watch the input directory: ${error.message}`);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
pollTimer = setInterval(() => observeSource(), pollMs);
|
|
605
|
+
|
|
606
|
+
let opener = null;
|
|
607
|
+
if (shouldOpen) {
|
|
608
|
+
try {
|
|
609
|
+
opener = openLoopbackUrl(url);
|
|
610
|
+
} catch {
|
|
611
|
+
opener = { requested: true, status: 'unsupported', target: url, method: null };
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
observeSource({ immediate: true });
|
|
616
|
+
|
|
617
|
+
return {
|
|
618
|
+
url,
|
|
619
|
+
input: inputPath,
|
|
620
|
+
output: outputPath,
|
|
621
|
+
opener,
|
|
622
|
+
state: publicState,
|
|
623
|
+
stop,
|
|
624
|
+
closed,
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
export async function runPreview(options) {
|
|
629
|
+
const preview = await startPreview(options);
|
|
630
|
+
console.log(`preview ${preview.url}`);
|
|
631
|
+
console.log(`watching ${preview.input}`);
|
|
632
|
+
console.log(`output ${preview.output}`);
|
|
633
|
+
if (preview.opener && preview.opener.status !== 'opened') {
|
|
634
|
+
console.error(`Could not open the preview (${preview.opener.status}). Open it manually: ${preview.url}`);
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
let signalCount = 0;
|
|
638
|
+
const stop = () => {
|
|
639
|
+
signalCount += 1;
|
|
640
|
+
if (signalCount === 1) {
|
|
641
|
+
console.log('\nstopping preview…');
|
|
642
|
+
preview.stop();
|
|
643
|
+
} else {
|
|
644
|
+
console.log('\nforcing preview shutdown…');
|
|
645
|
+
preview.stop({ force: true });
|
|
646
|
+
}
|
|
647
|
+
};
|
|
648
|
+
process.on('SIGINT', stop);
|
|
649
|
+
process.on('SIGTERM', stop);
|
|
650
|
+
await preview.closed;
|
|
651
|
+
process.off('SIGINT', stop);
|
|
652
|
+
process.off('SIGTERM', stop);
|
|
653
|
+
}
|