Archify Diagram Viewer 0.1.0

VS Code extension that previews Archify diagrams from their JSON sources
(live, as you type) and opens rendered Archify HTML in a viewer tab.
Bundles the Archify 3.0.1 renderer and runs it on VS Code's Node runtime.
Adds validation diagnostics, JSON schema help, source-link navigation,
export saving, render-to-file and open-in-browser commands.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-30 12:44:15 +03:00
co-authored by Claude Opus 5.5
commit 22815a9940
119 changed files with 66708 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { hasSourceEvidence, isArchifyHtml, readDiagramSource, stripSourceEvidence, typeFromFilename } from '../src/detect';
import { pointerSegments, rangeForPointer } from '../src/jsonPointer';
test('reads diagram_type from content', () => {
const source = readDiagramSource('{"schema_version":1,"diagram_type":"sequence","meta":{}}', 'plain.json');
assert.equal(source?.type, 'sequence');
});
test('falls back to the file name for unparseable sources', () => {
assert.equal(readDiagramSource('{"diagram_type": ', 'x.workflow.json')?.type, 'workflow');
assert.equal(readDiagramSource('{"name":"pkg"}', 'package.json'), undefined);
assert.equal(typeFromFilename('/a/b/Web.Architecture.json'), 'architecture');
});
test('recognizes Archify HTML by its generator meta', () => {
assert.ok(isArchifyHtml('<html><head><meta name="generator" content="archify 3.0.1"></head></html>'));
assert.ok(!isArchifyHtml('<html><head><meta name="generator" content="hugo"></head></html>'));
});
test('strips source evidence without touching the original', () => {
const diagram = {
meta: { title: 't', repository: { url: 'https://github.com/a/b', revision: 'x' } },
components: [{ id: 'a', sources: [{ path: 'src/a.ts' }] }, { id: 'b' }],
};
assert.ok(hasSourceEvidence('architecture', diagram));
const stripped = stripSourceEvidence('architecture', diagram);
assert.ok(!hasSourceEvidence('architecture', stripped));
assert.ok(diagram.meta.repository, 'original keeps its repository');
assert.deepEqual((stripped.components as unknown[])[1], { id: 'b' });
});
test('json pointer segments decode escapes and indexes', () => {
assert.deepEqual(pointerSegments('/components/0/a~1b~0c'), ['components', 0, 'a/b~c']);
assert.deepEqual(pointerSegments(''), []);
});
test('json pointer ranges point at keys for containers and values for leaves', () => {
const text = '{\n "meta": { "title": "x" },\n "components": [ { "id": "a" } ]\n}';
const meta = rangeForPointer(text, '/meta');
assert.equal(text.slice(meta.start, meta.end), '"meta"');
const title = rangeForPointer(text, '/meta/title');
assert.equal(text.slice(title.start, title.end), '"x"');
const item = rangeForPointer(text, '/components/0');
assert.equal(text.slice(item.start, item.end), '{');
const missing = rangeForPointer(text, '/components/0/label');
assert.equal(text.slice(missing.start, missing.end), '{', 'falls back to the nearest existing ancestor');
});
+55
View File
@@ -0,0 +1,55 @@
{
"schema_version": 1,
"diagram_type": "lifecycle",
"meta": {
"title": "Agent Run Lifecycle",
"output": "examples/lifecycle-agent-run.html",
"viewBox": [1030, 630],
"animation": "trace",
"quality_profile": "showcase"
},
"lanes": [
{ "id": "main", "label": "Lifecycle phases" },
{ "id": "waiting", "label": "Interruptions" },
{ "id": "exceptions", "label": "Recovery loop" },
{ "id": "terminal", "label": "Terminal exits" }
],
"states": [
{ "id": "queued", "type": "start", "label": "Queued", "sublabel": "request accepted", "lane": "main", "col": 0, "step": "01", "tag": "entry" },
{ "id": "planning", "type": "active", "label": "Planning", "sublabel": "build task graph", "lane": "main", "col": 1, "step": "02", "tag": "model" },
{ "id": "executing", "type": "active", "label": "Executing", "sublabel": "tool calls", "lane": "main", "col": 2, "step": "03", "tag": "work" },
{ "id": "reviewing", "type": "decision", "label": "Reviewing", "sublabel": "quality gate", "lane": "main", "col": 3, "step": "04", "tag": "check" },
{ "id": "completed", "type": "success", "label": "Completed", "sublabel": "final response", "lane": "main", "col": 4, "step": "05", "tag": "done" },
{ "id": "approval", "type": "waiting", "label": "Needs Approval", "sublabel": "human gate", "lane": "waiting", "col": 0, "tag": "pause" },
{ "id": "blocked", "type": "waiting", "label": "Blocked", "sublabel": "missing input", "lane": "waiting", "col": 1, "tag": "wait" },
{ "id": "failed", "type": "failure", "label": "Failed", "sublabel": "recoverable error", "lane": "exceptions", "col": 0, "yOffset": 78, "tag": "retryable" },
{ "id": "cancelled", "type": "failure", "label": "Cancelled", "sublabel": "user stopped", "lane": "terminal", "col": 0, "tag": "terminal" },
{ "id": "expired", "type": "failure", "label": "Expired", "sublabel": "timeout", "lane": "terminal", "col": 1, "tag": "terminal" }
],
"transitions": [
{ "id": "approval-needed", "from": "executing", "to": "approval", "variant": "security", "fromSide": "bottom", "toSide": "top", "route": "straight" },
{ "id": "review-blocked", "from": "reviewing", "to": "blocked", "variant": "default", "route": "drop" },
{ "id": "execution-failed", "from": "executing", "to": "failed", "variant": "security", "fromSide": "left", "toSide": "left", "via": [[320, 157], [320, 385]] },
{ "id": "failed-retry", "from": "failed", "to": "executing", "variant": "emphasis", "fromSide": "left", "toSide": "top", "via": [[20, 385], [20, 80], [402, 80]] },
{ "id": "block-expired", "from": "blocked", "to": "expired", "variant": "security", "fromSide": "bottom", "toSide": "top", "route": "straight" },
{ "id": "approval-cancelled", "from": "approval", "to": "cancelled", "variant": "security", "fromSide": "bottom", "toSide": "top", "via": [[480, 336], [480, 432], [402, 432]] }
],
"cards": [
{
"dot": "emerald",
"title": "Main Path + Waits",
"items": [
"The run has five ordered phases from queue to completion",
"Approval and missing input pause the run without ending it"
]
},
{
"dot": "rose",
"title": "Recovery + Terminal Exits",
"items": [
"Failed loops back while retry budget remains",
"Cancelled and Expired are terminal exits with no return path"
]
}
]
}
+74
View File
@@ -0,0 +1,74 @@
{
"schema_version": 2,
"diagram_type": "workflow",
"meta": {
"title": "Agent Tool Call Workflow",
"animation": "trace",
"visual_preset": "signal-flow",
"quality_profile": "showcase",
"output": "examples/workflow-agent-tool-call-rendered.html"
},
"lanes": [
{ "id": "ui", "label": "User Interface" },
{ "id": "agent", "label": "Agent Runtime" },
{ "id": "policy", "label": "Policy & Recovery", "variant": "exception" },
{ "id": "tools", "label": "Tool Execution & Evidence" }
],
"phases": [
{ "id": "intake", "label": "Intake", "fromCol": 0, "toCol": 1 },
{ "id": "reasoning", "label": "Plan + route", "fromCol": 2, "toCol": 3, "variant": "emphasis" },
{ "id": "execution", "label": "Execute + report", "fromCol": 4, "toCol": 5, "variant": "dashed" }
],
"groups": [
{ "id": "agent_loop", "label": "Planning loop", "lane": "agent", "fromCol": 2, "toCol": 3, "variant": "emphasis" },
{ "id": "exception_path", "label": "Human or policy stop", "lane": "policy", "fromCol": 3, "toCol": 5, "variant": "security" },
{ "id": "evidence_path", "label": "Evidence path", "lane": "tools", "fromCol": 1, "toCol": 2, "variant": "dashed" },
{ "id": "tool_work", "label": "Tool work", "lane": "tools", "fromCol": 4, "toCol": 5, "variant": "dashed" }
],
"mainPath": ["user", "chat", "planner", "router", "approval", "tool", "external", "final"],
"nodes": [
{ "id": "user", "lane": "ui", "col": 0, "type": "external", "label": "User", "sublabel": "asks for work", "width": 132 },
{ "id": "chat", "lane": "ui", "col": 1, "type": "frontend", "label": "Chat Surface", "sublabel": "thread + files", "width": 132 },
{ "id": "final", "lane": "ui", "col": 5, "type": "backend", "label": "Final Reply", "sublabel": "answer + changes", "width": 132 },
{ "id": "planner", "lane": "agent", "col": 2, "type": "backend", "label": "Agent Planner", "sublabel": "plan next step", "tag": "context aware", "width": 132 },
{ "id": "router", "lane": "agent", "col": 3, "type": "backend", "label": "Tool Router", "sublabel": "choose capability", "width": 132 },
{ "id": "approval", "lane": "policy", "col": 3, "type": "security", "label": "Approval Gate", "sublabel": "scope + consent", "tag": "block risky ops", "width": 132 },
{ "id": "blocked", "lane": "policy", "col": 4, "type": "security", "label": "Blocked", "sublabel": "wait or reject", "width": 132 },
{ "id": "retry", "lane": "policy", "col": 5, "type": "messagebus", "label": "Retry Path", "sublabel": "revise request", "width": 132 },
{ "id": "tool", "lane": "tools", "col": 4, "type": "messagebus", "label": "Tool Call", "sublabel": "shell / browser / MCP", "tag": "structured result", "width": 132 },
{ "id": "external", "lane": "tools", "col": 5, "type": "cloud", "label": "External API", "sublabel": "network service", "width": 132 },
{ "id": "store", "lane": "tools", "col": 1, "type": "database", "label": "Context Store", "sublabel": "repo + memory", "width": 132 },
{ "id": "trace", "lane": "tools", "col": 2, "type": "database", "label": "Trace Log", "sublabel": "events + output", "width": 132 }
],
"edges": [
{ "id": "request-chat", "from": "user", "to": "chat", "variant": "default" },
{ "id": "plan-request", "from": "chat", "to": "planner", "label": "plan", "variant": "emphasis" },
{ "id": "planner-route", "from": "planner", "to": "router", "variant": "default" },
{ "id": "approval-check", "from": "router", "to": "approval", "label": "needs approval?", "variant": "security" },
{ "id": "approved-tool", "from": "approval", "to": "tool", "variant": "emphasis" },
{ "id": "approval-denied", "from": "approval", "to": "blocked", "label": "denied", "variant": "security", "role": "error" },
{ "id": "retry-request", "from": "blocked", "to": "retry", "variant": "dashed", "role": "branch" },
{ "id": "tool-external-call", "from": "tool", "to": "external", "variant": "default" },
{ "id": "external-reply", "from": "external", "to": "final", "variant": "emphasis", "role": "return", "fromSide": "right", "toSide": "right", "route": "outside-right", "width": 1.2 },
{ "id": "record-result", "from": "external", "to": "trace", "label": "record result", "variant": "dashed", "fromSide": "bottom", "toSide": "bottom", "route": "bottom-channel", "labelSegment": 1 },
{ "id": "write-trace-memory", "from": "store", "to": "trace", "label": "trace + memory", "variant": "dashed" }
],
"cards": [
{
"dot": "cyan",
"title": "Compiler Contract",
"items": [
"Lanes and columns determine node placement",
"Labels reserve clearance; routes stay orthogonal"
]
},
{
"dot": "rose",
"title": "Runtime Semantics",
"items": [
"Approval gates risky work before tool execution",
"Evidence returns through isolated trace and memory"
]
}
]
}
+77
View File
@@ -0,0 +1,77 @@
{
"schema_version": 1,
"diagram_type": "sequence",
"meta": {
"title": "Cache Miss Request Sequence",
"output": "examples/sequence-cache-miss-request.html",
"viewBox": [1080, 580],
"column_fit": "spread",
"animation": "trace",
"quality_profile": "showcase"
},
"participants": [
{ "id": "user", "type": "external", "label": "User", "sublabel": "browser session" },
{ "id": "web", "type": "frontend", "label": "Web App", "sublabel": "React UI" },
{ "id": "api", "type": "backend", "label": "API", "sublabel": "request handler" },
{ "id": "auth", "type": "security", "label": "Auth", "sublabel": "JWT verify" },
{ "id": "redis", "type": "database", "label": "Redis", "sublabel": "cache" },
{ "id": "db", "type": "database", "label": "Postgres", "sublabel": "source of truth" },
{ "id": "trace", "type": "messagebus", "label": "Trace", "sublabel": "async event" }
],
"segments": [
{ "from": 150, "to": 250, "label": "Request" },
{ "from": 260, "to": 370, "label": "Fallback" },
{ "from": 380, "to": 480, "label": "Response + trace" }
],
"messages": [
{ "id": "open-page", "from": "user", "to": "web", "y": 160, "label": "open page", "variant": "default" },
{ "id": "dashboard-request", "from": "web", "to": "api", "y": 185, "label": "GET /dashboard", "variant": "emphasis" },
{ "id": "verify-jwt", "from": "api", "to": "auth", "y": 210, "label": "verify JWT", "variant": "security" },
{ "id": "auth-claims", "from": "auth", "to": "api", "y": 238, "label": "claims ok", "variant": "return" },
{ "id": "cache-read", "from": "api", "to": "redis", "y": 270, "label": "read cache", "variant": "default" },
{ "id": "cache-miss", "from": "redis", "to": "api", "y": 298, "label": "miss", "variant": "return" },
{ "id": "profile-query", "from": "api", "to": "db", "y": 330, "label": "query profile + metrics", "variant": "emphasis" },
{ "id": "profile-rows", "from": "db", "to": "api", "y": 358, "label": "rows", "variant": "return" },
{ "id": "cache-write", "from": "api", "to": "redis", "y": 390, "label": "set cache", "variant": "dashed" },
{ "id": "trace-emit", "from": "api", "to": "trace", "y": 418, "label": "emit trace", "variant": "dashed" },
{ "id": "dashboard-response", "from": "api", "to": "web", "y": 443, "label": "200 JSON", "variant": "return" },
{ "id": "page-render", "from": "web", "to": "user", "y": 468, "label": "render", "variant": "return" }
],
"activations": [
{ "participant": "web", "from": 180, "to": 474, "type": "frontend" },
{ "participant": "api", "from": 185, "to": 450, "type": "backend" },
{ "participant": "auth", "from": 205, "to": 244, "type": "security" },
{ "participant": "redis", "from": 265, "to": 304, "type": "database" },
{ "participant": "db", "from": 325, "to": 364, "type": "database" },
{ "participant": "trace", "from": 413, "to": 449, "type": "messagebus" }
],
"cards": [
{
"dot": "emerald",
"title": "Happy Path",
"items": [
"The main request is Web App -> API -> data source -> response",
"Return messages are quieter than forward calls",
"Activation bars make ownership duration visible"
]
},
{
"dot": "rose",
"title": "Policy + Fallback",
"items": [
"JWT verification is colored as a security interaction",
"Cache miss is visible without overpowering the main path",
"Database access only appears after cache fallback"
]
},
{
"dot": "orange",
"title": "Async Trace",
"items": [
"Trace emission is dashed and secondary",
"It does not block the response path",
"The diagram separates user-facing latency from observability"
]
}
]
}
+52
View File
@@ -0,0 +1,52 @@
{
"schema_version": 1,
"diagram_type": "dataflow",
"meta": {
"title": "Order Event-stream Topology",
"output": "examples/event-stream.html",
"viewBox": [1080, 780],
"animation": "trace",
"visual_preset": "signal-flow",
"quality_profile": "showcase"
},
"stages": [
{ "label": "Producers" },
{ "label": "Transit" },
{ "label": "Processors" },
{ "label": "State + recovery" },
{ "label": "Consumers" }
],
"nodes": [
{ "id": "checkout", "type": "frontend", "label": "Checkout API", "sublabel": "order producer", "stage": 0, "row": 0, "tag": "team commerce" },
{ "id": "billing", "type": "backend", "label": "Billing API", "sublabel": "payment producer", "stage": 0, "row": 2, "tag": "team money" },
{ "id": "orders", "type": "messagebus", "label": "orders.v1", "sublabel": "12 partitions", "stage": 1, "row": 0, "tag": "key: order_id" },
{ "id": "payments", "type": "messagebus", "label": "payments.v2", "sublabel": "8 partitions", "stage": 1, "row": 2, "tag": "key: order_id" },
{ "id": "validate", "type": "backend", "label": "Order Validate", "sublabel": "group fulfillment", "stage": 2, "row": 0, "tag": "ordered" },
{ "id": "enrich", "type": "backend", "label": "Payment Enrich", "sublabel": "group analytics", "stage": 2, "row": 2, "tag": "at-least-once" },
{ "id": "state", "type": "database", "label": "Order State", "sublabel": "materialized view", "stage": 3, "row": 1, "tag": "idempotent" },
{ "id": "dlq", "type": "messagebus", "label": "events.dlq", "sublabel": "poison events", "stage": 3, "row": 4, "tag": "7-day retention" },
{ "id": "fulfillment", "type": "backend", "label": "Fulfillment", "sublabel": "shipping workflow", "stage": 4, "row": 0, "tag": "consumer" },
{ "id": "analytics", "type": "database", "label": "Analytics", "sublabel": "streaming facts", "stage": 4, "row": 2, "tag": "consumer" },
{ "id": "replay", "type": "security", "label": "Replay Tool", "sublabel": "approved batch", "stage": 4, "row": 4, "tag": "operator gate" },
{ "id": "ops", "type": "external", "label": "On-call", "sublabel": "DLQ owner", "stage": 4, "row": 3, "yOffset": -18, "tag": "SRE" }
],
"flows": [
{ "from": "checkout", "to": "orders", "label": "OrderPlaced", "classification": "schema v1", "variant": "emphasis", "route": "straight" },
{ "from": "billing", "to": "payments", "label": "PaymentCaptured", "classification": "schema v2", "variant": "emphasis", "route": "straight" },
{ "from": "orders", "to": "validate", "label": "ordered orders", "classification": "consumer group", "variant": "emphasis", "route": "straight" },
{ "from": "payments", "to": "enrich", "label": "payment facts", "classification": "at-least-once", "variant": "emphasis", "route": "straight" },
{ "from": "validate", "to": "state", "label": "valid order", "classification": "idempotent", "variant": "emphasis", "route": "vertical-channel" },
{ "from": "enrich", "to": "state", "label": "enriched payment", "classification": "idempotent", "variant": "default", "route": "vertical-channel" },
{ "from": "state", "to": "fulfillment", "label": "ready orders", "classification": "read model", "variant": "emphasis", "route": "vertical-channel" },
{ "from": "state", "to": "analytics", "label": "order facts", "classification": "non-PII", "variant": "default", "route": "vertical-channel" },
{ "from": "validate", "to": "dlq", "label": "invalid event", "classification": "dead letter", "variant": "security", "fromSide": "top", "toSide": "top", "via": [[530, 80], [20, 80], [20, 550], [745, 550]], "labelAt": [300, 550] },
{ "from": "enrich", "to": "dlq", "label": "poison event", "classification": "dead letter", "variant": "security", "route": "bottom-channel", "labelDy": 30 },
{ "from": "dlq", "to": "ops", "label": "failure sample", "classification": "restricted", "variant": "security", "route": "vertical-channel" },
{ "from": "dlq", "to": "replay", "label": "approved replay", "classification": "audited batch", "variant": "dashed", "route": "straight", "labelDy": 30 }
],
"cards": [
{ "dot": "amber", "title": "Transit Contract", "items": ["Every event and topic is named", "Partition keys preserve per-order ordering", "Consumer groups expose processing ownership"] },
{ "dot": "emerald", "title": "State + Delivery", "items": ["Processors write an idempotent materialized view", "Fulfillment and analytics consume distinct assets", "At-least-once delivery never implies duplicate business effects"] },
{ "dot": "rose", "title": "Failure Ownership", "items": ["Poison events land in a retained dead-letter topic", "On-call inspects samples before replay", "Replay is gated, batched, and auditable"] }
]
}
+293
View File
@@ -0,0 +1,293 @@
{
"schema_version": 1,
"diagram_type": "architecture",
"meta": {
"title": "MCO Runtime Architecture",
"subtitle": "mco-org/mco · explicit provider policy · parallel invocation · durable raw answers",
"output": "docs/cases/mco-runtime.architecture.html",
"animation": "trace",
"visual_preset": "signal-flow",
"quality_profile": "showcase",
"repository": {
"url": "https://github.com/mco-org/mco",
"revision": "9f1a1cf1afdc04d7b5406782b40dfec76d9bc798"
}
},
"components": [
{
"id": "callers",
"type": "external",
"label": "Callers",
"sublabel": "human · coding agent",
"pos": [5, 250],
"size": [130, 60]
},
{
"id": "entry",
"type": "frontend",
"label": "Entry Surfaces",
"sublabel": "npm shim · Python CLI · MCP",
"pos": [175, 250],
"size": [160, 60],
"sources": [
{ "path": "bin/mco.js", "line": 1, "label": "npm entry" },
{ "path": "runtime/mcp_server.py", "line": 108, "end_line": 153, "label": "MCP entry" }
]
},
{
"id": "router",
"type": "backend",
"label": "Command Router",
"sublabel": "run · review · doctor · session",
"pos": [360, 250],
"size": [180, 60],
"sources": [
{ "path": "runtime/cli.py", "line": 1945, "label": "CLI main" }
]
},
{
"id": "config",
"type": "database",
"label": "Config + Selection",
"sublabel": "files · explicit provider team",
"pos": [565, 110],
"size": [175, 60],
"tag": "no silent team",
"sources": [
{ "path": "runtime/config.py", "line": 24, "label": "Review config" }
]
},
{
"id": "policy",
"type": "security",
"label": "Execution Policy",
"sublabel": "read_only · write · yolo",
"pos": [565, 250],
"size": [175, 60],
"tag": "explicit boundary",
"sources": [
{ "path": "runtime/policy.py", "line": 34, "label": "Provider policy" }
]
},
{
"id": "workflow",
"type": "backend",
"label": "Invocation Workflow",
"sublabel": "parallel · chain · debate · synthesize",
"pos": [765, 250],
"size": [220, 60],
"sources": [
{ "path": "runtime/invocation_runtime.py", "line": 696, "label": "Workflow entry" },
{ "path": "runtime/invocation_runtime.py", "line": 156, "label": "Single invocation" }
]
},
{
"id": "adapters",
"type": "messagebus",
"label": "Provider Adapters",
"sublabel": "shim / ACP · detect · run · poll · cancel",
"pos": [1010, 250],
"size": [230, 60],
"sources": [
{ "path": "runtime/adapters/__init__.py", "line": 57, "label": "Adapter registry" },
{ "path": "runtime/contracts.py", "line": 77, "label": "Provider contract" }
]
},
{
"id": "provider_clis",
"type": "external",
"label": "Provider CLIs",
"sublabel": "Claude · Codex · Pi · 7 more",
"pos": [1035, 0],
"size": [180, 60]
},
{
"id": "answer_transport",
"type": "messagebus",
"label": "Answer Transport",
"sublabel": "plain · JSON · JSONL · ACP events",
"pos": [765, 420],
"size": [190, 60],
"sources": [
{ "path": "runtime/answer_transport.py", "line": 79, "label": "Transport decoders" }
]
},
{
"id": "artifacts",
"type": "cloud",
"label": "Invocation Artifacts",
"sublabel": "answers · result.md · run.json",
"pos": [1010, 420],
"size": [170, 60],
"tag": "raw evidence",
"sources": [
{ "path": "runtime/invocation_artifacts.py", "line": 8, "label": "Artifact writer" }
]
},
{
"id": "consumers",
"type": "external",
"label": "Output Consumers",
"sublabel": "terminal · calling agent · CI",
"pos": [1005, 520],
"size": [180, 60]
},
{
"id": "session_daemon",
"type": "backend",
"label": "Session Daemon",
"sublabel": "detached worker · Unix socket",
"pos": [365, 420],
"size": [170, 60],
"sources": [
{ "path": "runtime/session/daemon.py", "line": 50, "label": "Daemon context" }
]
},
{
"id": "session_state",
"type": "database",
"label": "Session State",
"sublabel": "state.json · history.jsonl",
"pos": [565, 420],
"size": [170, 60],
"tag": ".mco/sessions",
"sources": [
{ "path": "runtime/session/state.py", "line": 25, "label": "Session state" }
]
}
],
"boundaries": [
{
"kind": "region",
"label": "mco local package / Python runtime",
"wraps": ["entry", "router", "config", "policy", "workflow", "adapters", "answer_transport", "artifacts", "session_daemon", "session_state"]
},
{
"kind": "security-group",
"label": "explicit execution-policy boundary",
"wraps": ["policy", "workflow", "adapters"]
}
],
"connections": [
{
"id": "caller-entry",
"from": "callers",
"to": "entry",
"variant": "emphasis"
},
{
"id": "entry-route",
"from": "entry",
"to": "router",
"variant": "emphasis"
},
{
"id": "route-policy",
"from": "router",
"to": "policy",
"variant": "security"
},
{
"id": "config-policy",
"from": "config",
"to": "policy",
"variant": "security",
"fromSide": "bottom",
"toSide": "top"
},
{
"id": "policy-workflow",
"from": "policy",
"to": "workflow",
"variant": "emphasis"
},
{
"id": "workflow-adapters",
"from": "workflow",
"to": "adapters",
"variant": "emphasis"
},
{
"id": "adapters-providers",
"from": "adapters",
"to": "provider_clis",
"label": "native CLI / ACP",
"variant": "emphasis",
"fromSide": "top",
"toSide": "bottom"
},
{
"id": "adapters-answer",
"from": "adapters",
"to": "answer_transport",
"label": "decode events",
"labelAt": [995, 365],
"fromSide": "bottom",
"toSide": "top"
},
{
"id": "answer-artifacts",
"from": "answer_transport",
"to": "artifacts",
"variant": "emphasis"
},
{
"id": "artifacts-consumers",
"from": "artifacts",
"to": "consumers",
"label": "raw answers",
"labelAt": [1095, 510],
"variant": "emphasis",
"fromSide": "bottom",
"toSide": "top"
},
{
"id": "router-session",
"from": "router",
"to": "session_daemon",
"label": "start · send · resume",
"labelAt": [450, 365],
"variant": "dashed",
"fromSide": "bottom",
"toSide": "top",
"route": "straight"
},
{
"id": "session-state",
"from": "session_daemon",
"to": "session_state",
"label": "persist",
"labelAt": [550, 406],
"variant": "dashed"
}
],
"cards": [
{
"dot": "cyan",
"title": "Source-backed dispatch",
"items": [
"runtime/cli.py requires an explicit provider or named agent team",
"runtime/policy.py validates models, context, permissions, and risk",
"runtime/invocation_runtime.py owns parallelism, timeouts, and cancellation"
]
},
{
"dot": "emerald",
"title": "Raw-answer contract",
"items": [
"Adapters keep each provider CLI behind one shared runtime contract",
"answer_transport.py decodes output without inventing findings or consensus",
"Artifacts persist answers and run metadata for terminal, agents, or CI"
]
},
{
"dot": "violet",
"title": "Real repository proof",
"items": [
"Repository: github.com/mco-org/mco",
"Source snapshot: main @ 9f1a1cf",
"Evidence read: README, CLI, policy, adapters, invocation runtime, sessions"
]
}
]
}
+51
View File
@@ -0,0 +1,51 @@
{
"schema_version": 1,
"diagram_type": "architecture",
"meta": {
"title": "Production Deployment Ownership",
"output": "examples/production-deployment.html",
"visual_preset": "blueprint",
"animation": "trace",
"quality_profile": "showcase",
"engineering_profile": "deployment-ownership"
},
"components": [
{ "id": "clients", "type": "external", "label": "Customers", "sublabel": "web + mobile", "pos": [38, 300], "size": [122, 60] },
{ "id": "edge", "type": "cloud", "label": "Global Edge", "sublabel": "CDN + WAF", "pos": [230, 300], "size": [126, 60], "tag": "edge team" },
{ "id": "gateway", "type": "security", "label": "API Gateway", "sublabel": "public :443", "pos": [430, 300], "size": [128, 60], "tag": "platform" },
{ "id": "api_a", "type": "backend", "label": "API Pods / AZ-a", "sublabel": "private subnet", "pos": [630, 195], "size": [136, 62], "tag": "app team" },
{ "id": "api_b", "type": "backend", "label": "API Pods / AZ-b", "sublabel": "private subnet", "pos": [630, 405], "size": [136, 62], "tag": "app team" },
{ "id": "redis", "type": "database", "label": "Redis", "sublabel": "multi-AZ cache", "pos": [840, 195], "size": [126, 62], "tag": "platform" },
{ "id": "postgres", "type": "database", "label": "PostgreSQL", "sublabel": "primary / encrypted", "pos": [840, 405], "size": [126, 62], "tag": "data team" },
{ "id": "events", "type": "messagebus", "label": "Event Bus", "sublabel": "orders.v1", "pos": [1040, 300], "size": [126, 60], "tag": "platform" },
{ "id": "worker", "type": "backend", "label": "Workers", "sublabel": "private workload", "pos": [1190, 300], "size": [126, 60], "tag": "app team" },
{ "id": "replica", "type": "database", "label": "DR Replica", "sublabel": "eu-west-1", "pos": [1040, 578], "size": [126, 62], "tag": "data team" },
{ "id": "audit", "type": "cloud", "label": "Audit Archive", "sublabel": "immutable objects", "pos": [1190, 450], "size": [126, 62], "tag": "security" },
{ "id": "observability", "type": "external", "label": "Observability", "sublabel": "metrics + traces", "pos": [1190, 85], "size": [126, 62], "tag": "SRE" }
],
"boundaries": [
{ "kind": "region", "label": "AWS us-east-1 / production", "wraps": ["edge", "gateway", "api_a", "api_b", "redis", "postgres", "events", "worker", "audit"], "pad": 20 },
{ "kind": "security-group", "label": "private application network", "wraps": ["api_a", "api_b", "redis", "postgres", "events", "worker"], "pad": 14 },
{ "kind": "region", "label": "AWS eu-west-1 / disaster recovery", "wraps": ["replica"] },
{ "kind": "security-group", "label": "DR private subnet", "wraps": ["replica"], "pad": 14 }
],
"connections": [
{ "from": "clients", "to": "edge", "label": "HTTPS", "variant": "emphasis" },
{ "from": "edge", "to": "gateway", "label": "mTLS", "variant": "security" },
{ "from": "gateway", "to": "api_a", "label": "VPC route", "variant": "emphasis", "route": "orthogonal-h", "labelAt": [594, 275] },
{ "from": "gateway", "to": "api_b", "label": "VPC route", "variant": "emphasis", "route": "orthogonal-h", "labelAt": [594, 385] },
{ "from": "api_a", "to": "redis", "label": "cache", "route": "straight" },
{ "from": "api_b", "to": "postgres", "label": "SQL", "route": "straight" },
{ "from": "api_a", "to": "events", "label": "publish", "variant": "dashed", "fromSide": "top", "toSide": "top", "via": [[698, 170], [1103, 170]] },
{ "from": "api_b", "to": "events", "variant": "dashed", "fromSide": "top", "toSide": "bottom", "via": [[698, 380], [1103, 380]] },
{ "from": "events", "to": "worker", "variant": "emphasis" },
{ "from": "postgres", "to": "replica", "label": "cross-region WAL", "variant": "security", "route": "orthogonal-v", "labelAt": [1003, 529] },
{ "from": "worker", "to": "audit", "label": "evidence", "variant": "dashed", "fromSide": "bottom", "toSide": "top", "labelDy": 58 },
{ "from": "worker", "to": "observability", "label": "OTLP", "variant": "dashed", "route": "orthogonal-v" }
],
"cards": [
{ "dot": "cyan", "title": "Runtime Ownership", "items": ["Platform owns the edge, gateway, cache, and event bus", "Application teams own API pods and workers", "Data owns primary and disaster-recovery state"] },
{ "dot": "rose", "title": "Named Crossings", "items": ["Public HTTPS terminates at the managed edge", "mTLS crosses into the application network", "Cross-region WAL is explicit and encrypted"] },
{ "dot": "emerald", "title": "Operational Evidence", "items": ["Workers emit traces to SRE-owned observability", "Audit evidence lands in immutable storage", "Unknown placement should remain marked, never invented"] }
]
}
+37
View File
@@ -0,0 +1,37 @@
// Runs the integration suite inside a real VS Code instance with a throwaway
// profile. Uses the locally installed VS Code when VSCODE_PATH is set or the
// default macOS location exists; otherwise downloads one.
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { runTests } from '@vscode/test-electron';
// When launched from a VS Code terminal this is inherited and would make the
// test instance start as plain Node.
delete process.env.ELECTRON_RUN_AS_NODE;
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..');
const macApp = '/Applications/Visual Studio Code.app/Contents/MacOS/Code';
const vscodeExecutablePath = process.env.VSCODE_PATH || (fs.existsSync(macApp) ? macApp : undefined);
const scratch = fs.mkdtempSync(path.join(os.tmpdir(), 'archify-ext-it-'));
const workspace = path.join(scratch, 'workspace');
fs.cpSync(path.join(root, 'test', 'fixtures'), workspace, { recursive: true });
try {
await runTests({
vscodeExecutablePath,
extensionDevelopmentPath: root,
extensionTestsPath: path.join(root, 'out', 'test', 'integration', 'suite.js'),
launchArgs: [
workspace,
'--disable-extensions',
'--disable-workspace-trust',
'--skip-welcome',
'--skip-release-notes',
`--user-data-dir=${path.join(scratch, 'user-data')}`,
],
});
} finally {
fs.rmSync(scratch, { recursive: true, force: true });
}
+121
View File
@@ -0,0 +1,121 @@
import assert from 'node:assert/strict';
import path from 'node:path';
import * as vscode from 'vscode';
const EXTENSION_ID = 'vscode-extensions.archify-vscode-ext';
function workspaceFile(name: string): vscode.Uri {
const folder = vscode.workspace.workspaceFolders?.[0];
assert.ok(folder, 'a workspace folder is open');
return vscode.Uri.joinPath(folder.uri, name);
}
async function waitFor<T>(what: string, probe: () => T | undefined | false, timeoutMs = 20_000): Promise<T> {
const start = Date.now();
for (;;) {
const value = probe();
if (value) return value;
if (Date.now() - start > timeoutMs) throw new Error(`Timed out waiting for ${what}`);
await new Promise((resolve) => setTimeout(resolve, 200));
}
}
function webviewTabs(viewTypeSuffix: string): vscode.Tab[] {
return vscode.window.tabGroups.all
.flatMap((group) => group.tabs)
.filter((tab) =>
(tab.input instanceof vscode.TabInputWebview && tab.input.viewType.endsWith(viewTypeSuffix)) ||
(tab.input instanceof vscode.TabInputCustom && tab.input.viewType === viewTypeSuffix));
}
async function check(name: string, body: () => Promise<void>): Promise<void> {
try {
await body();
console.log(` ✔ ${name}`);
} catch (error) {
console.log(` ✖ ${name}`);
throw error;
}
}
export async function run(): Promise<void> {
console.log('Archify extension integration suite');
await check('activates on a diagram source and sets the context key', async () => {
const doc = await vscode.workspace.openTextDocument(workspaceFile('production-deployment.architecture.json'));
await vscode.window.showTextDocument(doc);
const extension = vscode.extensions.getExtension(EXTENSION_ID);
assert.ok(extension, 'extension is installed');
await waitFor('activation', () => extension.isActive);
});
await check('opens a live preview beside the source', async () => {
await vscode.commands.executeCommand('archify.showPreviewToSide');
const tabs = await waitFor('preview tab', () => {
const found = webviewTabs('archify.preview');
return found.length > 0 && found;
});
assert.equal(tabs.length, 1);
assert.match(tabs[0].label, /Preview production-deployment\.architecture\.json/);
});
await check('reports validation problems in the Problems panel with JSON ranges', async () => {
const doc = await vscode.workspace.openTextDocument({
language: 'json',
content: JSON.stringify({ schema_version: 1, diagram_type: 'architecture', meta: { title: 'x' }, components: [{ id: 'a' }] }, null, 2),
});
await vscode.window.showTextDocument(doc);
const diagnostics = await waitFor('archify diagnostics', () => {
const found = vscode.languages.getDiagnostics(doc.uri).filter((d) => d.source === 'archify');
return found.length > 0 && found;
});
const component = diagnostics.find((d) => /components\/0/.test(d.message));
assert.ok(component, 'a diagnostic for /components/0');
assert.equal(doc.getText(component.range), '{', 'range points at the component object');
assert.equal(component.severity, vscode.DiagnosticSeverity.Error);
});
await check('clears problems once the document is fixed', async () => {
const good = await vscode.workspace.openTextDocument(workspaceFile('event-stream.dataflow.json'));
const doc = await vscode.workspace.openTextDocument({ language: 'json', content: good.getText() });
await vscode.window.showTextDocument(doc);
await new Promise((resolve) => setTimeout(resolve, 3000));
const errors = vscode.languages.getDiagnostics(doc.uri).filter((d) => d.source === 'archify' && d.severity === vscode.DiagnosticSeverity.Error);
assert.deepEqual(errors.map((d) => d.message), []);
});
await check('renders to an HTML file and opens it in the Archify viewer', async () => {
const source = workspaceFile('cache-miss-request.sequence.json');
const output = vscode.Uri.file(path.join(path.dirname(source.fsPath), 'cache-miss-request.sequence.html'));
// Stub the save dialog and the follow-up notification.
const window = vscode.window as unknown as Record<string, unknown>;
const originalSave = window.showSaveDialog;
const originalInfo = window.showInformationMessage;
window.showSaveDialog = async () => output;
window.showInformationMessage = async () => 'Open in Viewer';
try {
await vscode.commands.executeCommand('archify.renderToHtml', source);
} finally {
window.showSaveDialog = originalSave;
window.showInformationMessage = originalInfo;
}
const html = new TextDecoder().decode(await vscode.workspace.fs.readFile(output));
assert.match(html, /<meta name="generator" content="archify/);
await waitFor('custom editor tab', () => webviewTabs('archify.htmlViewer').length > 0);
});
await check('source-backed diagram previews with the evidence fallback', async () => {
const uri = workspaceFile('mco-runtime.architecture.json');
await vscode.commands.executeCommand('archify.showPreview', uri);
await waitFor('second preview tab', () => webviewTabs('archify.preview').length >= 2);
const doc = await vscode.workspace.openTextDocument(uri);
const diagnostics = await waitFor('evidence diagnostics', () => {
const found = vscode.languages.getDiagnostics(doc.uri).filter((d) => d.source === 'archify');
return found.length > 0 && found;
});
assert.ok(
diagnostics.every((d) => d.severity !== vscode.DiagnosticSeverity.Error),
'unverifiable evidence is a warning in fallback mode',
);
});
}
+76
View File
@@ -0,0 +1,76 @@
import assert from 'node:assert/strict';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { test } from 'node:test';
import { readDiagramSource } from '../src/detect';
import { renderDiagram, renderToFile, RuntimeOptions, validate } from '../src/renderer';
const root = path.resolve(__dirname, '..', '..');
const fixtures = path.join(root, 'test', 'fixtures');
const workDir = fs.mkdtempSync(path.join(os.tmpdir(), 'archify-ext-test-'));
function runtime(extra: Partial<RuntimeOptions> = {}): RuntimeOptions {
return {
cliPath: path.join(root, 'vendor', 'archify', 'bin', 'archify.mjs'),
nodePath: process.execPath,
runAsNode: false,
workDir,
...extra,
};
}
function load(name: string) {
const text = fs.readFileSync(path.join(fixtures, name), 'utf8');
const source = readDiagramSource(text, name);
assert.ok(source, `${name} is a diagram source`);
return { ...source, text };
}
for (const name of fs.readdirSync(fixtures).filter((file) => !file.startsWith('mco-'))) {
test(`renders ${name}`, async () => {
const result = await renderDiagram(runtime(), load(name), 'strict');
assert.equal(result.error, undefined);
assert.ok(result.ok);
assert.match(result.html ?? '', /<meta name="generator" content="archify/);
assert.equal(result.evidenceNotice, undefined);
});
}
test('reports schema problems with JSON pointer paths', async () => {
const text = JSON.stringify({ schema_version: 1, diagram_type: 'architecture', meta: { title: 'x' }, components: [{ id: 'a' }] });
const result = await validate(runtime(), 'architecture', text);
assert.equal(result.ok, false);
assert.ok(result.diagnostics.some((d) => d.subject?.path === '/components/0' && d.severity === 'error'));
});
test('render failure returns the CLI error', async () => {
const text = JSON.stringify({ schema_version: 1, diagram_type: 'architecture', meta: {}, components: [] });
const result = await renderDiagram(runtime(), { type: 'architecture', diagram: JSON.parse(text), text }, 'fallback');
assert.equal(result.ok, false);
assert.match(result.error ?? '', /schema validation failed/);
});
test('unverifiable source evidence falls back to a render without source links', async () => {
// This checkout's origin is not mco-org/mco, so verification must fail.
const source = load('mco-runtime.architecture.json');
const strict = await renderDiagram(runtime({ repoRoot: root }), source, 'strict');
assert.equal(strict.ok, false);
const fallback = await renderDiagram(runtime({ repoRoot: root }), source, 'fallback');
assert.ok(fallback.ok, fallback.error);
assert.match(fallback.evidenceNotice ?? '', /Source links are hidden/);
const noRoot = await renderDiagram(runtime(), source, 'fallback');
assert.ok(noRoot.ok);
assert.match(noRoot.evidenceNotice ?? '', /not inside a Git checkout/);
});
test('renders to a chosen file', async () => {
const output = path.join(workDir, 'exported.html');
const result = await renderToFile(runtime(), load('event-stream.dataflow.json'), output);
assert.ok(result.ok, result.error);
assert.ok(fs.statSync(output).size > 10_000);
});
test('scratch directories are cleaned up', () => {
assert.deepEqual(fs.readdirSync(workDir).filter((entry) => entry.startsWith('run-')), []);
});
+37
View File
@@ -0,0 +1,37 @@
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { prepareDiagramHtml } from '../src/webviewHtml';
const page = `<!DOCTYPE html><html><head>
<meta http-equiv="Content-Security-Policy" content="default-src *">
<script>var a = 1;</script>
<script id="data" type="application/json">{"x":1}</script>
</head><body><script>var b = 2;</script></body></html>`;
test('adds one CSP and nonces every inline script', () => {
const html = prepareDiagramHtml(page, { cspSource: 'vscode-resource:', nonce: 'N0NCE', theme: 'light' });
const csps = html.match(/Content-Security-Policy/g) ?? [];
assert.equal(csps.length, 1);
assert.match(html, /script-src (&#39;|')nonce-N0NCE/);
const scripts = html.match(/<script\b[^>]*>/g) ?? [];
assert.equal(scripts.length, 4, 'bridge plus the three page scripts');
for (const tag of scripts) assert.match(tag, /nonce="N0NCE"/);
});
test('bridge runs before the page scripts and pins the theme', () => {
const html = prepareDiagramHtml(page, { cspSource: 'x', nonce: 'n', theme: 'dark', hash: '#focus=api' });
const bridge = html.indexOf('acquireVsCodeApi');
assert.ok(bridge > 0 && bridge < html.indexOf('var a = 1'));
assert.match(html, /"theme":"dark"/);
assert.match(html, /"hash":"#focus=api"/);
});
test('embedded config cannot close the script element', () => {
const html = prepareDiagramHtml(page, {
cspSource: 'x',
nonce: 'n',
theme: undefined,
notice: { kind: 'warning', text: '</script><script>alert(1)</script>' },
});
assert.ok(!html.includes('</script><script>alert(1)'));
});