arkaik 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/skill/references/schema.md +60 -53
- package/dist/assets/skill/scripts/validate-bundle.js +4 -4
- package/dist/assets/skill/skill.md +3 -0
- package/dist/index.js +3161 -826
- package/dist/io.js +219 -28
- package/package.json +1 -1
|
@@ -78,6 +78,8 @@ interface NodeMetadata extends Record<string, unknown> {
|
|
|
78
78
|
platformNotes?: PlatformNotesMap;
|
|
79
79
|
platformStatuses?: PlatformStatusMap;
|
|
80
80
|
platformScreenshots?: PlatformScreenshotsMap;
|
|
81
|
+
/** Provenance of each current screenshot plus the CI order watermark; written by the screenshot ops only. */
|
|
82
|
+
platformScreenshotMeta?: PlatformScreenshotMetaMap;
|
|
81
83
|
refs?: Ref[];
|
|
82
84
|
/** Acceptance nodes: one Given/When/Then scenario — the How (spec §3.1). */
|
|
83
85
|
gherkin?: string;
|
|
@@ -95,27 +97,18 @@ interface NodeMetadata extends Record<string, unknown> {
|
|
|
95
97
|
decided_at?: string;
|
|
96
98
|
}
|
|
97
99
|
|
|
98
|
-
interface
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
platforms: PlatformId[];
|
|
106
|
-
metadata?: NodeMetadata;
|
|
100
|
+
interface PlatformScreenshotMeta {
|
|
101
|
+
ts?: string;
|
|
102
|
+
source?: ScreenshotSource;
|
|
103
|
+
form?: ScreenshotForm;
|
|
104
|
+
commit?: string;
|
|
105
|
+
order?: number;
|
|
106
|
+
ci_order?: number;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
|
|
110
|
-
id: string;
|
|
111
|
-
project_id: string;
|
|
112
|
-
source_id: string;
|
|
113
|
-
target_id: string;
|
|
114
|
-
edge_type: EdgeTypeId;
|
|
115
|
-
metadata?: Record<string, unknown>;
|
|
116
|
-
}
|
|
109
|
+
type PlatformScreenshotMetaMap = Partial<Record<PlatformId, PlatformScreenshotMeta>>;
|
|
117
110
|
|
|
118
|
-
type MapKind = "journey" | "system";
|
|
111
|
+
type MapKind = "journey" | "system" | "screens";
|
|
119
112
|
|
|
120
113
|
interface MapLayoutHints extends Record<string, unknown> {
|
|
121
114
|
direction?: "DOWN" | "RIGHT" | (string & {});
|
|
@@ -164,36 +157,24 @@ interface MapDefinition extends Record<string, unknown> {
|
|
|
164
157
|
display?: MapDisplayOptions;
|
|
165
158
|
}
|
|
166
159
|
|
|
167
|
-
interface
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
/** Per-map display overrides keyed by map id — built-ins included. */
|
|
175
|
-
map_display?: Record<string, MapDisplayOptions>;
|
|
176
|
-
products?: ProductDefinition[];
|
|
177
|
-
/** Federation (pollen) settings for hosted serving; `plant` is the ariko plant slug this project anchors to. */
|
|
178
|
-
pollen?: { plant?: string } & Record<string, unknown>;
|
|
160
|
+
interface Edge {
|
|
161
|
+
id: string;
|
|
162
|
+
project_id: string;
|
|
163
|
+
source_id: string;
|
|
164
|
+
target_id: string;
|
|
165
|
+
edge_type: EdgeTypeId;
|
|
166
|
+
metadata?: Record<string, unknown>;
|
|
179
167
|
}
|
|
180
168
|
|
|
181
|
-
interface
|
|
169
|
+
interface Node {
|
|
182
170
|
id: string;
|
|
171
|
+
project_id: string;
|
|
172
|
+
species: SpeciesId;
|
|
183
173
|
title: string;
|
|
184
174
|
description?: string;
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
root_node_id?: string;
|
|
189
|
-
/** Optional project-level UI settings and preferences. */
|
|
190
|
-
metadata?: ProjectMetadata;
|
|
191
|
-
/** ISO 8601 timestamp, e.g. "2024-01-01T00:00:00.000Z" */
|
|
192
|
-
created_at: string;
|
|
193
|
-
/** ISO 8601 timestamp, e.g. "2024-01-01T00:00:00.000Z" */
|
|
194
|
-
updated_at: string;
|
|
195
|
-
/** ISO 8601 timestamp when archived; null/undefined means active. */
|
|
196
|
-
archived_at?: string | null;
|
|
175
|
+
status: StatusId;
|
|
176
|
+
platforms: PlatformId[];
|
|
177
|
+
metadata?: NodeMetadata;
|
|
197
178
|
}
|
|
198
179
|
|
|
199
180
|
interface JournalEvent extends Record<string, unknown> {
|
|
@@ -301,6 +282,24 @@ interface RefStatusChangedEvent extends JournalEvent {
|
|
|
301
282
|
synced_at: string;
|
|
302
283
|
}
|
|
303
284
|
|
|
285
|
+
interface ScreenshotRecordedEvent extends JournalEvent {
|
|
286
|
+
type: "screenshot.recorded";
|
|
287
|
+
node_id: string;
|
|
288
|
+
platform: PlatformId;
|
|
289
|
+
source: ScreenshotSource;
|
|
290
|
+
form: ScreenshotForm;
|
|
291
|
+
url?: string;
|
|
292
|
+
commit?: string;
|
|
293
|
+
order?: number;
|
|
294
|
+
detail?: string;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
interface ScreenshotRemovedEvent extends JournalEvent {
|
|
298
|
+
type: "screenshot.removed";
|
|
299
|
+
node_id: string;
|
|
300
|
+
platform: PlatformId;
|
|
301
|
+
}
|
|
302
|
+
|
|
304
303
|
type KnownJournalEvent =
|
|
305
304
|
| NodeCreatedEvent
|
|
306
305
|
| NodeUpdatedEvent
|
|
@@ -316,6 +315,8 @@ type KnownJournalEvent =
|
|
|
316
315
|
| RefAddedEvent
|
|
317
316
|
| RefRemovedEvent
|
|
318
317
|
| RefStatusChangedEvent
|
|
318
|
+
| ScreenshotRecordedEvent
|
|
319
|
+
| ScreenshotRemovedEvent
|
|
319
320
|
| JournalBaselineEvent
|
|
320
321
|
| QualityAuditCompletedEvent
|
|
321
322
|
| QualityFindingOpenedEvent
|
|
@@ -323,16 +324,22 @@ type KnownJournalEvent =
|
|
|
323
324
|
| QualityFindingAcceptedEvent
|
|
324
325
|
| QualitySignalTrippedEvent;
|
|
325
326
|
|
|
326
|
-
interface
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
/** Optional
|
|
333
|
-
|
|
334
|
-
/** Optional
|
|
335
|
-
|
|
327
|
+
interface Project {
|
|
328
|
+
id: string;
|
|
329
|
+
title: string;
|
|
330
|
+
description?: string;
|
|
331
|
+
/** v2: current version label, free-form (semver recommended, not required), e.g. "1.4.0" or "2026-07". Version history lives in the journal. */
|
|
332
|
+
version?: string;
|
|
333
|
+
/** Optional node id used as the primary canvas anchor/root. */
|
|
334
|
+
root_node_id?: string;
|
|
335
|
+
/** Optional project-level UI settings and preferences. */
|
|
336
|
+
metadata?: ProjectMetadata;
|
|
337
|
+
/** ISO 8601 timestamp, e.g. "2024-01-01T00:00:00.000Z" */
|
|
338
|
+
created_at: string;
|
|
339
|
+
/** ISO 8601 timestamp, e.g. "2024-01-01T00:00:00.000Z" */
|
|
340
|
+
updated_at: string;
|
|
341
|
+
/** ISO 8601 timestamp when archived; null/undefined means active. */
|
|
342
|
+
archived_at?: string | null;
|
|
336
343
|
}
|
|
337
344
|
```
|
|
338
345
|
<!-- GENERATED:SCHEMA:END -->
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
*
|
|
11
11
|
* Usage: node validate-bundle.js <path-to-bundle.json>
|
|
12
12
|
*/
|
|
13
|
-
"use strict";var G=require("node:fs"),Q=require("node:path");var H=["flow","view","data-model","api-endpoint","acceptance","decision"],K=["idea","discovery","backlog","development","releasing","live","archived"],B=["web","ios","android"],ne=["composes","calls","displays","queries","covers","supersedes","generates","impacts"],me={composes:[["flow","view"],["flow","flow"],["view","flow"],["view","view"]],calls:[["view","api-endpoint"],["flow","api-endpoint"],["api-endpoint","api-endpoint"],["api-endpoint","view"]],displays:[["view","data-model"]],queries:[["api-endpoint","data-model"]],covers:[["acceptance","view"],["acceptance","flow"]],supersedes:[["decision","decision"]],generates:[["decision","acceptance"]],impacts:[["decision","flow"],["decision","view"],["decision","data-model"],["decision","api-endpoint"]]};var he=["saves-time","simplifies","makes-money","reduces-risk","organizes","integrates","connects","reduces-effort","avoids-hassles","reduces-cost","quality","variety","sensory-appeal","informs","reduces-anxiety","rewards-me","nostalgia","design-aesthetics","badge-value","wellness","therapeutic-value","fun-entertainment","attractiveness","provides-access","provides-hope","self-actualization","motivation","heirloom","affiliation-belonging","self-transcendence"];var _e={flow:"F-",view:"V-","data-model":"DM-","api-endpoint":"API-",acceptance:"AC-",decision:"DEC-"};var De=["proposed","approved","enacted","rejected","deprecated","superseded"];function ve(f){switch(f){case"proposed":return"discovery";case"approved":return"backlog";case"enacted":return"live";case"rejected":case"deprecated":case"superseded":return"archived"}}function we(f){let p=f.metadata?.decision_status;return De.includes(p)?p:"proposed"}var ie={prioritized:"backlog",blocked:"development"};function se(f){return K.includes(f)?f:ie[f]}var Be={...ie},Ye={backlog:"idea",...ie};function Ne(f){let p=t=>typeof t=="string"?t:"";return[...f].sort((t,s)=>{let $=p(t.ts),w=p(s.ts);if($<w)return-1;if($>w)return 1;let m=p(t.id),R=p(s.id);return m<R?-1:m>R?1:0})}function re(f){let p=[],t=[];return f.split(/\r?\n/).forEach(($,w)=>{let m=w+1;if($.trim()==="")return;let R;try{R=JSON.parse($)}catch(L){t.push({line:m,rule:"journal-line-parse",message:`Line ${m}: not valid JSON \u2014 ${L.message}`,severity:"error"});return}if(typeof R!="object"||R===null||Array.isArray(R)){t.push({line:m,rule:"journal-line-shape",message:`Line ${m}: each journal line must be a single JSON event object.`,severity:"error"});return}let T=R,E=[];if(typeof T.id!="string"&&E.push("id"),typeof T.ts!="string"&&E.push("ts"),typeof T.type!="string"&&E.push("type"),E.length>0){t.push({line:m,rule:"journal-line-shape",message:`Line ${m}: event is missing required envelope field(s): ${E.join(", ")}.`,severity:"error"});return}p.push(T)}),{events:p,findings:t}}var Te={"node.updated":["node_id"],"node.status_changed":["node_id"],"decision.status_changed":["node_id"],"node.deleted":["node_id"],"edge.added":["source_id","target_id"],"ref.added":["node_id"],"ref.removed":["node_id"],"ref.status_changed":["node_id"],"idea.proposed":["node_id"],"request.filed":["node_id"]};function Fe(f,p){return f===p?!0:typeof p!="string"?!1:f==="backlog"&&p==="idea"?!0:(se(f)??f)===(se(p)??p)}function Se(f){let p=[],t=f.journal;if(t===void 0)return p;if(!Array.isArray(t))return p.push({path:"journal",rule:"journal-shape",message:"journal must be an array of events when present.",severity:"error"}),p;if(t.length===0)return p;let s=c=>typeof c=="string"?c:void 0,$=Array.isArray(f.nodes)?f.nodes:[],w=Array.isArray(f.edges)?f.edges:[],m=new Map,R=new Map;for(let c of $){let g=s(c?.id);if(g!==void 0){m.set(g,c.status);let v=c.metadata,x=v&&typeof v=="object"&&!Array.isArray(v)?v.decision_status:void 0;R.set(g,x??"proposed")}}let T=new Set;for(let c of w){let g=s(c?.id);g!==void 0&&T.add(g)}let E=[];t.forEach((c,g)=>{let v=`journal[${g}]`;if(typeof c!="object"||c===null||Array.isArray(c)){p.push({path:v,rule:"journal-event-shape",message:`journal[${g}]: each event must be a JSON object.`,severity:"error"});return}let x=c,j=[];if(s(x.id)===void 0&&j.push("id"),s(x.ts)===void 0&&j.push("ts"),s(x.type)===void 0&&j.push("type"),j.length>0){p.push({path:v,rule:"journal-event-envelope",message:`journal[${g}]: event is missing required envelope field(s): ${j.join(", ")}.`,severity:"error"});return}E.push({ev:x,index:g})});let L=new Set(m.keys()),k=new Set(T),F=new Set;for(let{ev:c}of E)if(c.type==="node.created"){let g=s(c.node_id);g&&L.add(g)}else if(c.type==="edge.added"){let g=s(c.edge_id);g&&k.add(g)}else if(c.type==="journal.baseline"&&Array.isArray(c.node_ids))for(let g of c.node_ids){let v=s(g);v&&(F.add(v),L.add(v))}let O=Ne(E.map(c=>c.ev)),q=new Set,U=new Map,J=new Map;for(let c of O)if(c.type==="node.created"){let g=s(c.node_id);g&&q.add(g)}else if(c.type==="node.status_changed"){let g=s(c.node_id);if(g&&c.platform===void 0){let v=s(c.to);v!==void 0&&U.set(g,v)}}else if(c.type==="decision.status_changed"){let g=s(c.node_id);if(g){let v=s(c.to);v!==void 0&&J.set(g,v)}}for(let{ev:c,index:g}of E){let v=Te[c.type];if(v)for(let x of v){let j=s(c[x]);j!==void 0&&!L.has(j)&&p.push({path:`journal[${g}].${x}`,rule:"journal-dangling-node-ref",message:`journal[${g}] (${c.type}): references node "${j}" that never existed in the snapshot or journal.`,severity:"error"})}if(c.type==="deliverable.shipped"&&Array.isArray(c.node_ids)&&c.node_ids.forEach((x,j)=>{let V=s(x);V!==void 0&&!L.has(V)&&p.push({path:`journal[${g}].node_ids[${j}]`,rule:"journal-dangling-node-ref",message:`journal[${g}] (${c.type}): references node "${V}" that never existed in the snapshot or journal.`,severity:"error"})}),c.type==="edge.removed"){let x=s(c.edge_id);x!==void 0&&!k.has(x)&&p.push({path:`journal[${g}].edge_id`,rule:"journal-dangling-edge-ref",message:`journal[${g}] (edge.removed): references edge "${x}" that never existed in the snapshot or journal.`,severity:"error"})}}for(let[c,g]of m){!q.has(c)&&!F.has(c)&&p.push({path:"journal",rule:"journal-missing-node-created",message:`Node "${c}" is present in the snapshot but has no node.created event in the journal.`,severity:"error"});let v=U.get(c);v!==void 0&&!Fe(v,g)&&p.push({path:"journal",rule:"journal-status-mismatch",message:`Node "${c}": journal's last node.status_changed.to "${v}" disagrees with snapshot status "${String(g)}".`,severity:"error"})}for(let[c,g]of J){if(!R.has(c))continue;let v=R.get(c)??"proposed";g!==v&&p.push({path:"journal",rule:"journal-decision-status-mismatch",message:`Node "${c}": journal's last decision.status_changed.to "${g}" disagrees with snapshot decision_status "${String(v)}".`,severity:"error"})}return p}var $e=["flow","view","acceptance"];function be(f){let p=f?.metadata?.products;if(!Array.isArray(p))return[];let t=new Set,s=[];for(let $ of p){if(typeof $!="object"||$===null||Array.isArray($))continue;let w=$;typeof w.id!="string"||w.id.trim()===""||t.has(w.id)||(t.add(w.id),s.push(w))}return s}var Ee=["rings","bars"],Ae=["chips","rows"],ke=["status","species"];var Le=["journey","system"];function xe(f){return Le.includes(f)}var X="cross-surface";var Oe=["beta","monitoring","deprecated"],Ie=["compact","large"],Re=2*1024*1024;function Ce(f){let p=f.indexOf(",");if(p===-1)return 0;let t=f.slice(p+1),s=t.endsWith("==")?2:t.endsWith("=")?1:0;return Math.floor(t.length*3/4)-s}function Me(f){return typeof f=="string"&&!Number.isNaN(Date.parse(f))}function Pe(f){let p=[],t=(e,r,n)=>p.push({path:e,rule:r,message:n,severity:"error"}),s=(e,r,n)=>p.push({path:e,rule:r,message:n,severity:"warning"}),$=()=>{let e=p.filter(n=>n.severity==="error"),r=p.filter(n=>n.severity==="warning");return{valid:e.length===0,findings:p,errors:e,warnings:r}};if(typeof f!="object"||f===null||Array.isArray(f))return t("","bundle-shape","Bundle must be an object with project, nodes, and edges."),$();let w=f,m=w.project,R=w.nodes,T=w.edges;if(!m||!R||!T)return t("","bundle-shape","Missing top-level keys (project, nodes, edges)."),$();if(!Array.isArray(R))return t("nodes","bundle-shape","nodes must be an array."),$();if(!Array.isArray(T))return t("edges","bundle-shape","edges must be an array."),$();let E=R,L=T,k=new Map,F=new Set;m.id||t("project.id","project-id-required","project.id is missing"),(typeof m.title!="string"||!m.title.trim())&&t("project.title","title-non-empty","project.title is missing or empty"),m.created_at||t("project.created_at","timestamp-required","project.created_at is missing"),m.updated_at||t("project.updated_at","timestamp-required","project.updated_at is missing"),m.created_at&&!Me(m.created_at)&&s("project.created_at","iso-timestamp","project.created_at is not a valid ISO 8601 timestamp"),m.updated_at&&!Me(m.updated_at)&&s("project.updated_at","iso-timestamp","project.updated_at is not a valid ISO 8601 timestamp");let O=m.metadata;O&&O.view_card_variant!==void 0&&!Ie.includes(O.view_card_variant)&&t("project.metadata.view_card_variant","view-card-variant",`project.metadata.view_card_variant must be one of ${Ie.join(", ")} (import rejects other values)`),E.forEach((e,r)=>{let n=`nodes[${r}]`,i=e.id;F.has(i)&&t(`${n}.id`,"duplicate-node-id",`Duplicate node ID: ${i}`),F.add(i),k.set(i,e),(typeof e.title!="string"||!e.title.trim())&&t(`${n}.title`,"title-non-empty",`Node ${i}: title is missing or empty`);let a=e.species,o=_e[a];o&&!(typeof i=="string"&&i.startsWith(o))&&t(`${n}.id`,"species-prefix",`Node ${i}: species "${a}" should have prefix "${o}"`),H.includes(a)||t(`${n}.species`,"valid-species",`Node ${i}: invalid species "${a}"`),e.project_id!==m.id&&t(`${n}.project_id`,"project-id-match",`Node ${i}: project_id "${e.project_id}" does not match project.id "${m.id}"`),K.includes(e.status)||t(`${n}.status`,"valid-status",`Node ${i}: invalid status "${e.status}"`);let l=e.platforms;if(!l||l.length===0)a!=="decision"&&t(`${n}.platforms`,"platforms-non-empty",`Node ${i}: platforms array is empty or missing`);else for(let d of l)B.includes(d)||t(`${n}.platforms`,"valid-platform",`Node ${i}: invalid platform "${d}"`);let u=e.metadata||{};u.stage!==void 0&&!Oe.includes(u.stage)&&t(`${n}.metadata.stage`,"valid-stage",`Node ${i}: invalid metadata.stage "${u.stage}"`);let S=u.platformNotes;if(S)for(let d of Object.keys(S))B.includes(d)||t(`${n}.metadata.platformNotes`,"valid-platform",`Node ${i}: platformNotes has invalid platform "${d}"`);let b=u.platformStatuses;if(b)for(let[d,y]of Object.entries(b))B.includes(d)?Array.isArray(l)&&!l.includes(d)&&s(`${n}.metadata.platformStatuses`,"platform-statuses-subset",`Node ${i}: platformStatuses covers platform "${d}" not in node.platforms`):t(`${n}.metadata.platformStatuses`,"valid-platform",`Node ${i}: platformStatuses has invalid platform "${d}"`),K.includes(y)||t(`${n}.metadata.platformStatuses`,"valid-status",`Node ${i}: platformStatuses has invalid status "${y}" for platform "${d}"`);let I=u.platformScreenshots;if(I){for(let[d,y]of Object.entries(I))if(typeof y=="string"&&y.startsWith("data:")){let P=Ce(y);P>Re&&s(`${n}.metadata.platformScreenshots`,"screenshot-data-uri-size",`Node ${i}: platformScreenshots.${d} is a ${(P/(1024*1024)).toFixed(1)}MB data URI, above the ${Re/(1024*1024)}MB guidance (docs/spec/bundle-format.md \xA7 Asset Values) \u2014 consider a relative path or hosted URL instead`)}}let M=u.gherkin,C=u.values;if(a==="acceptance"?((typeof M!="string"||!M.trim())&&s(`${n}.metadata.gherkin`,"acceptance-gherkin-missing",`Acceptance ${i}: metadata.gherkin is missing or empty (one Given/When/Then scenario expected)`),(!Array.isArray(C)||C.length===0)&&s(`${n}.metadata.values`,"acceptance-values-missing",`Acceptance ${i}: metadata.values is missing or empty (assign 1-3 value elements)`)):(M!==void 0&&s(`${n}.metadata.gherkin`,"gherkin-species",`Node ${i}: metadata.gherkin is only meaningful on acceptance nodes`),C!==void 0&&s(`${n}.metadata.values`,"values-species",`Node ${i}: metadata.values is only meaningful on acceptance nodes`)),Array.isArray(C))for(let d of C)he.includes(d)||t(`${n}.metadata.values`,"valid-value",`Node ${i}: invalid value element "${d}"`);let h=u.refs;if(Array.isArray(h)){let d=new Set;h.forEach((y,P)=>{let A=y??{},D=`${n}.metadata.refs[${P}]`,N=A.id;typeof N!="string"||!N.trim()?t(`${D}.id`,"ref-id-required",`Node ${i}: ref is missing an id`):d.has(N)?t(`${D}.id`,"duplicate-ref-id",`Node ${i}: duplicate ref id "${N}"`):d.add(N),(typeof A.url!="string"||!A.url.trim())&&t(`${D}.url`,"ref-url-required",`Node ${i}: ref "${N}" is missing a url`),A.status_mapped!==void 0&&!K.includes(A.status_mapped)&&t(`${D}.status_mapped`,"valid-status",`Node ${i}: ref "${N}" has invalid status_mapped "${A.status_mapped}"`)})}if(u.decision_status!==void 0&&a!=="decision"&&s(`${n}.metadata.decision_status`,"decision-status-wrong-species",`decision_status is meaningful on decision nodes only; "${i}" is a ${a}.`),a==="decision"){let d=we({metadata:e.metadata}),y=ve(d);e.status!==y&&s(`${n}.status`,"decision-lifecycle-mismatch",`Decision "${i}" is ${d}, whose lifecycle status should be "${y}", but status is "${e.status}" (spec \xA72).`)}if(a==="flow"){let d=u.playlist;!e.metadata||!d||!d.entries?t(`${n}.metadata.playlist`,"flow-playlist-required",`Flow ${i}: missing metadata.playlist.entries`):d.entries.length===0&&s(`${n}.metadata.playlist`,"flow-playlist-empty",`Flow ${i}: playlist is empty`)}});let q=m.root_node_id;q&&!F.has(q)&&t("project.root_node_id","root-node-exists",`project.root_node_id "${q}" does not reference an existing node`);let U=(e,r,n)=>{if(typeof e!="object"||e===null||Array.isArray(e))return;let i=e,a=[["flow_platforms",Ee],["view_platforms",Ae],["minimap_color",ke]];for(let[o,l]of a){let u=i[o];u!==void 0&&(typeof u!="string"||!l.includes(u))&&s(`${r}.${o}`,"map-unknown-display",`${n} sets ${o} to "${String(u)}"; expected one of ${l.join(", ")} (renderers fall back to the default)`)}i.images!==void 0&&typeof i.images!="boolean"&&s(`${r}.images`,"map-unknown-display",`${n} sets images to a non-boolean value (renderers fall back to the default)`)},J=O?.map_display;if(typeof J=="object"&&J!==null&&!Array.isArray(J))for(let[e,r]of Object.entries(J))U(r,`project.metadata.map_display.${e}`,`Map "${e}"`);let c=O?.maps;if(Array.isArray(c)){let e=new Set;c.forEach((r,n)=>{if(typeof r!="object"||r===null||Array.isArray(r))return;let i=r,a=`project.metadata.maps[${n}]`,o=typeof i.id=="string"?i.id:void 0;o!==void 0&&(e.has(o)&&s(`${a}.id`,"map-duplicate-id",`Duplicate map id "${o}"`),e.add(o),xe(o)&&s(`${a}.id`,"map-shadows-built-in",`Map id "${o}" shadows a built-in map and will be ignored`));let l=i.root_node_id;typeof l=="string"&&!F.has(l)&&s(`${a}.root_node_id`,"map-unknown-root",`Map "${o??n}" anchors on "${l}" which does not reference an existing node`),Array.isArray(i.species)&&i.species.forEach((u,S)=>{typeof u=="string"&&!H.includes(u)&&s(`${a}.species[${S}]`,"map-unknown-species",`Map "${o??n}" filters on unknown species "${u}"`)}),Array.isArray(i.edge_types)&&i.edge_types.forEach((u,S)=>{typeof u=="string"&&!ne.includes(u)&&s(`${a}.edge_types[${S}]`,"map-unknown-edge-type",`Map "${o??n}" filters on unknown edge type "${u}"`)}),U(i.display,`${a}.display`,`Map "${o??n}"`)})}let g=O?.products,v=new Set;if(Array.isArray(g)){let e=new Set;g.forEach((r,n)=>{if(typeof r!="object"||r===null||Array.isArray(r))return;let i=r,a=`project.metadata.products[${n}]`,o=typeof i.id=="string"?i.id:void 0;o!==void 0&&(e.has(o)?s(`${a}.id`,"product-duplicate-id",`Duplicate product id "${o}" \u2014 the first wins`):(e.add(o),o.trim()!==""&&v.add(o)),/^[a-z0-9]+(-[a-z0-9]+)*$/.test(o)||s(`${a}.id`,"product-invalid-id",`Product id "${o}" is not kebab-case`))})}let x=v.size>0,j=new Map;for(let e of L){if(e.edge_type!=="covers")continue;let r=typeof e.source_id=="string"?e.source_id:void 0,n=typeof e.target_id=="string"?e.target_id:void 0;if(r===void 0||n===void 0)continue;let i=j.get(r)??[];i.push(n),j.set(r,i)}let V=new Map;if(x)for(let e of be({metadata:O}))V.set(e.id,new Set(Array.isArray(e.platforms)?e.platforms:[]));let oe=new Map,ae=new Map;if(E.forEach((e,r)=>{let n=typeof e.id=="string"?e.id:`#${r}`,i=e.species,a=`nodes[${r}]`;ae.set(n,r);let o=e.metadata??{},l=typeof o.product=="string"?o.product:void 0,u=i!==void 0&&$e.includes(i);if(l!==void 0&&!u){let I=H.includes(i)?`${i} membership is derived from consumers and must not be stored`:"metadata.product is only meaningful on flow, view, and acceptance nodes";s(`${a}.metadata.product`,"product-membership-wrong-species",`Node ${n}: ${I}`);return}if(!u)return;if(l===void 0){if(!x)return;i==="acceptance"?j.has(n)||s(`${a}.metadata.product`,"acceptance-product-unassigned",`Acceptance ${n} covers nothing and names no product \u2014 it will show only under "All products"`):s(`${a}.metadata.product`,"unassigned-membership",`Node ${n}: no product membership \u2014 it will show only under "All products"`);return}if(oe.set(n,l),!v.has(l)){s(`${a}.metadata.product`,"product-unknown-reference",`Node ${n}: product "${l}" is not declared on the project`);return}let S=V.get(l),b=Array.isArray(e.platforms)?e.platforms:[];if(S)for(let I of b)typeof I=="string"&&!S.has(I)&&s(`${a}.platforms`,"product-platform-not-in-menu",`Node ${n}: platform "${I}" is not in product "${l}"'s menu`)}),x)for(let[e,r]of j){let n=ae.get(e);if(n===void 0)continue;let i=new Set(r.map(a=>oe.get(a)).filter(a=>!!a));i.size>1&&s(`nodes[${n}].metadata.product`,"acceptance-covers-span-products",`Acceptance ${e} covers anchors in ${[...i].sort().join(" and ")} \u2014 statuses may conflate products`)}let de=new Set,ce=new Set,le=new Set;L.forEach((e,r)=>{let n=`edges[${r}]`,i=e.id,a=e.source_id,o=e.target_id,l=e.edge_type;de.has(i)&&t(`${n}.id`,"duplicate-edge-id",`Duplicate edge ID: ${i}`),de.add(i);let u=`e-${a}-${o}`;i!==u&&s(`${n}.id`,"edge-id-convention",`Edge ${i}: id does not match convention "${u}" (stale after a rename?)`);let S=`${a}->${o}:${l}`;ce.has(S)&&s(`${n}`,"duplicate-edge-relationship",`Duplicate edge relationship: ${S}`),ce.add(S),e.project_id!==m.id&&t(`${n}.project_id`,"project-id-match",`Edge ${i}: project_id does not match project.id`),F.has(a)||t(`${n}.source_id`,"dangling-edge",`Edge ${i}: source_id "${a}" not found in nodes`),F.has(o)||t(`${n}.target_id`,"dangling-edge",`Edge ${i}: target_id "${o}" not found in nodes`),ne.includes(l)||t(`${n}.edge_type`,"valid-edge-type",`Edge ${i}: invalid edge_type "${l}"`);let b=k.get(a),I=k.get(o),M=me[l];b&&I&&M&&(M.some(([h,_])=>h===b.species&&_===I.species)||t(`${n}.edge_type`,"edge-semantics",`Edge ${i}: "${l}" not valid from ${b.species} to ${I.species}`)),l==="composes"&&le.add(`${a}->${o}`)});let ue=["view","flow","condition","junction"],Z=(e,r,n,i=0)=>{if(!(i>50)){if(!Array.isArray(e)){t(n,"playlist-entry-shape",`Flow ${r}: ${n} must be an array of playlist entries`);return}e.forEach((a,o)=>{let l=`${n}[${o}]`;if(typeof a!="object"||a===null||Array.isArray(a)){t(l,"playlist-entry-shape",`Flow ${r}: ${l} must be a playlist entry object`);return}let u=a,S=u.type;if(typeof S!="string"||!ue.includes(S)){t(`${l}.type`,"playlist-entry-shape",`Flow ${r}: ${l}.type must be one of ${ue.join(", ")} (got ${JSON.stringify(S)})`);return}if(S==="view")typeof u.view_id!="string"&&t(`${l}.view_id`,"playlist-entry-shape",`Flow ${r}: ${l} is a view entry with no view_id string`);else if(S==="flow")typeof u.flow_id!="string"&&t(`${l}.flow_id`,"playlist-entry-shape",`Flow ${r}: ${l} is a flow entry with no flow_id string`);else if(S==="condition"){typeof u.label!="string"&&t(`${l}.label`,"playlist-entry-shape",`Flow ${r}: ${l} is a condition with no label string`);for(let b of["if_true","if_false"])Array.isArray(u[b])?Z(u[b],r,`${l}.${b}`,i+1):t(`${l}.${b}`,"playlist-entry-shape",`Flow ${r}: ${l}.${b} must be an array of playlist entries (both branches are required, use [] for an empty one)`)}else{if(typeof u.label!="string"&&t(`${l}.label`,"playlist-entry-shape",`Flow ${r}: ${l} is a junction with no label string`),!Array.isArray(u.cases)){t(`${l}.cases`,"playlist-entry-shape",`Flow ${r}: ${l}.cases must be an array of junction cases`);return}u.cases.forEach((b,I)=>{let M=`${l}.cases[${I}]`;if(typeof b!="object"||b===null||Array.isArray(b)){t(M,"playlist-entry-shape",`Flow ${r}: ${M} must be a junction case object`);return}let C=b;typeof C.label!="string"&&t(`${M}.label`,"playlist-entry-shape",`Flow ${r}: ${M} has no label string`),Array.isArray(C.entries)?Z(C.entries,r,`${M}.entries`,i+1):t(`${M}.entries`,"playlist-entry-shape",`Flow ${r}: ${M}.entries must be an array of playlist entries \u2014 a junction case holds its own entries, not a bare view_id/flow_id`)})}})}};E.forEach((e,r)=>{let n=e.metadata;e.species==="flow"&&n?.playlist?.entries&&Z(n.playlist.entries,e.id,`nodes[${r}].metadata.playlist.entries`)});let z=(e,r,n,i=0)=>{if(i>50)return t(n,"playlist-depth",`Flow ${r}: playlist nesting too deep (possible cycle)`),[];let a=[];if(!Array.isArray(e))return a;for(let o of e)if(!(typeof o!="object"||o===null)){if(o.type==="view")F.has(o.view_id)||t(n,"playlist-ref-exists",`Flow ${r}: playlist references non-existent view "${o.view_id}"`),a.push(o.view_id);else if(o.type==="flow")F.has(o.flow_id)||t(n,"playlist-ref-exists",`Flow ${r}: playlist references non-existent flow "${o.flow_id}"`),o.flow_id===r&&t(n,"playlist-self-cycle",`Flow ${r}: playlist contains itself (direct cycle)`),a.push(o.flow_id);else if(o.type==="condition")o.if_true&&a.push(...z(o.if_true,r,n,i+1)),o.if_false&&a.push(...z(o.if_false,r,n,i+1));else if(o.type==="junction"&&o.cases)for(let l of o.cases)a.push(...z(l.entries||[],r,n,i+1))}return a};E.forEach((e,r)=>{let n=e.metadata;if(e.species==="flow"&&n?.playlist?.entries){let i=`nodes[${r}].metadata.playlist`,a=e.id,o=z(n.playlist.entries,a,i);for(let l of o)le.has(`${a}->${l}`)||t(i,"playlist-composes-coherence",`Flow ${a}: playlist references "${l}" but no composes edge exists`)}});let ee=new Map,pe=new Map;E.forEach((e,r)=>{let n=e.metadata;if(e.species==="flow"&&n?.playlist?.entries){let i=e.id,a=[],o=l=>{if(Array.isArray(l)){for(let u of l)if(!(typeof u!="object"||u===null)&&(u.type==="flow"&&a.push(u.flow_id),u.type==="condition"&&(u.if_true&&o(u.if_true),u.if_false&&o(u.if_false)),u.type==="junction"&&u.cases))for(let S of u.cases)o(S.entries||[])}};o(n.playlist.entries),ee.set(i,a),pe.set(i,`nodes[${r}].metadata.playlist`)}});let fe=new Set,te=new Set,ge=e=>{if(te.has(e))return!0;if(fe.has(e))return!1;fe.add(e),te.add(e);for(let r of ee.get(e)||[])if(ge(r))return t(pe.get(e)??"","flow-cycle",`Cycle detected: flow "${e}" -> "${r}"`),!0;return te.delete(e),!1};for(let e of ee.keys())ge(e);let W=w.quality;if(typeof W=="object"&&W!==null&&!Array.isArray(W)){let e=W,r=Array.isArray(e.assessments)?e.assessments:[],n=Array.isArray(e.findings)?e.findings:[],i=typeof e.profile=="object"&&e.profile!==null?e.profile:void 0,a=new Set;Array.isArray(i?.surfaces)&&i.surfaces.forEach((h,_)=>{if(typeof h!="object"||h===null||Array.isArray(h))return;let d=h,y=typeof d.id=="string"?d.id:void 0;y===void 0||y.trim()===""||(a.has(y)&&s(`quality.profile.surfaces[${_}].id`,"quality-duplicate-surface",`Duplicate surface id "${y}" \u2014 the first wins`),a.add(y))}),a.size===0&&(r.length>0||n.length>0)&&s("quality.profile.surfaces","quality-no-surfaces","Quality data is stored but the profile declares no surfaces \u2014 the matrix falls back to the surfaces the assessments name");let o=typeof e.library=="object"&&e.library!==null?e.library:void 0,l=new Set,u=new Map;if(Array.isArray(o?.criteria))for(let h of o.criteria){if(typeof h!="object"||h===null)continue;let _=h;typeof _.id=="string"&&(l.add(_.id),typeof _.superseded_by=="string"&&_.superseded_by!==""&&u.set(_.id,_.superseded_by))}else(r.length>0||n.length>0)&&s("quality.library","quality-library-missing","No criteria pack is embedded \u2014 criterion ids cannot be resolved to domains or weights; the matrix uses a synthesized library");(typeof e.framework_version!="string"||e.framework_version==="")&&s("quality.framework_version","quality-framework-version-missing","Quality section has no framework_version \u2014 scores are not comparable across audits without one");let S=(h,_,d)=>{let y=typeof h.criterion_id=="string"?h.criterion_id:void 0;y!==void 0&&l.size>0&&!l.has(y)&&s(`${_}.criterion_id`,"quality-unknown-criterion",`${d}: criterion "${y}" is not in the pinned library`);let P=y!==void 0?u.get(y):void 0;P!==void 0&&s(`${_}.criterion_id`,"quality-retired-criterion",`${d}: criterion "${y}" is retired \u2014 superseded by "${P}"`);let A=typeof h.surface=="string"?h.surface:void 0;A!==void 0&&A!==X&&a.size>0&&!a.has(A)&&s(`${_}.surface`,"quality-unknown-surface",`${d}: surface "${A}" is not declared in the profile`)},b=new Set;r.forEach((h,_)=>{if(typeof h!="object"||h===null||Array.isArray(h))return;let d=h,y=`quality.assessments[${_}]`,P=`Assessment ${_}`;S(d,y,P);let A=d.level;(typeof A!="number"||!Number.isInteger(A)||A<0||A>4)&&s(`${y}.level`,"quality-level-range",`${P}: level must be an integer 0-4 (N/A is the absence of the row, not a level)`),d.surface===X&&s(`${y}.surface`,"quality-cross-surface-assessment",`${P}: "${X}" is a findings-only lens \u2014 it carries no matrix column, so this score would render nowhere`),(typeof d.evidence!="string"||d.evidence.trim()==="")&&s(`${y}.evidence`,"quality-assessment-no-evidence",`${P}: scored with no evidence \u2014 a score without a citation is an opinion, not an assessment`);let D=typeof d.criterion_id=="string"?d.criterion_id:void 0,N=typeof d.surface=="string"?d.surface:void 0;if(D!==void 0&&N!==void 0){let ye=`${D}\0${N}`;b.has(ye)&&s(`${y}`,"quality-duplicate-assessment",`${P}: a second score for (${D} x ${N}) \u2014 the section stores latest-per-cell, so this cell is ambiguous`),b.add(ye)}});let I=new Set;n.forEach((h,_)=>{if(typeof h!="object"||h===null||Array.isArray(h))return;let d=h,y=`quality.findings[${_}]`,P=`Finding ${_}`;S(d,y,P);let A=typeof d.id=="string"?d.id:void 0;A!==void 0&&(I.has(A)&&s(`${y}.id`,"quality-duplicate-finding-id",`Duplicate finding id "${A}"`),I.add(A));for(let D of["impact","likelihood"]){let N=d[D];(typeof N!="number"||!Number.isInteger(N)||N<1||N>5)&&s(`${y}.${D}`,"quality-risk-range",`${P}: ${D} must be an integer 1-5 \u2014 severity is derived from impact x likelihood`)}for(let D of["severity","priority"])D in d&&s(`${y}.${D}`,"quality-derived-field-stored",`${P}: ${D} is derived from impact, likelihood and cost \u2014 storing it lets it drift from the numbers behind it`);d.status==="accepted-risk"&&(typeof d.detail!="string"||d.detail.trim()==="")&&s(`${y}.detail`,"quality-accepted-risk-no-note",`${P}: accepted-risk with no note \u2014 an accepted risk is a decision and reads like one`)});let M=new Set,C=Array.isArray(w.journal)?w.journal:[];C.forEach(h=>{if(typeof h!="object"||h===null)return;let _=h;_.type==="quality.finding.opened"&&typeof _.finding_id=="string"&&M.add(_.finding_id)}),C.forEach((h,_)=>{if(typeof h!="object"||h===null)return;let d=h,y=typeof d.type=="string"?d.type:"";y.startsWith("quality.")&&((typeof d.actor!="string"||d.actor.trim()==="")&&s(`journal[${_}].actor`,"quality-event-no-actor",`Journal event ${_}: ${y} has no actor \u2014 human, agent and CI scores become indistinguishable`),y==="quality.finding.resolved"&&typeof d.finding_id=="string"&&!M.has(d.finding_id)&&!I.has(d.finding_id)&&s(`journal[${_}].finding_id`,"quality-resolved-never-opened",`Journal event ${_}: resolves finding "${d.finding_id}", which no quality.finding.opened event or stored finding ever declared`),y==="quality.finding.accepted"&&typeof d.finding_id=="string"&&!M.has(d.finding_id)&&!I.has(d.finding_id)&&s(`journal[${_}].finding_id`,"quality-accepted-never-opened",`Journal event ${_}: accepts finding "${d.finding_id}", which no quality.finding.opened event or stored finding ever declared`))})}for(let e of Se(w))p.push(e);return $()}var je="journal.jsonl",qe="journal";function Je(f){let p=(0,Q.join)(f,qe);return(0,G.existsSync)(p)?(0,G.readdirSync)(p).filter(t=>t.startsWith("archive-")&&t.endsWith(".jsonl")).sort().map(t=>(0,Q.join)(p,t)):[]}function Y(f,p){return f.filter(t=>t?.species===p).length}function Ue(){let f=process.argv[2];f||(console.error("Usage: node validate-bundle.js <path-to-bundle.json>"),process.exit(1)),(0,G.existsSync)(f)||(console.error(`File not found: ${f}`),process.exit(1));let p;try{p=JSON.parse((0,G.readFileSync)(f,"utf8"))}catch(k){console.error(`FATAL: Cannot parse JSON \u2014 ${k.message}`),process.exit(1)}let t=p;(typeof t!="object"||t===null||!t.project||!t.nodes||!t.edges)&&(console.error("FATAL: Missing top-level keys (project, nodes, edges)."),process.exit(1));let s=[],$=!1,w=[];if(t.journal===void 0){let k=(0,Q.dirname)(f),F=(0,Q.join)(k,je),O=[];if((0,G.existsSync)(F)){let{events:q,findings:U}=re((0,G.readFileSync)(F,"utf8"));for(let J of U)s.push(J.message);$=!0,O.push(...q)}for(let q of Je(k)){let U=(0,Q.basename)(q),{events:J,findings:c}=re((0,G.readFileSync)(q,"utf8"));for(let g of c)s.push(`${U} \u2014 ${g.message}`);w.push(U),O.push(...J)}($||w.length>0)&&(t.journal=O)}let m=Array.isArray(t.nodes)?t.nodes:[],R=Array.isArray(t.edges)?t.edges:[],T=Array.isArray(t.journal)?t.journal:[],E=Pe(p);if(console.log(`
|
|
13
|
+
"use strict";var Q=require("node:fs"),Y=require("node:path");var se=["flow","view","data-model","api-endpoint","acceptance","decision"],Z=["idea","discovery","backlog","development","releasing","live","archived"],ee=["web","ios","android"],de=["composes","calls","displays","queries","covers","supersedes","generates","impacts"],me={composes:[["flow","view"],["flow","flow"],["view","flow"],["view","view"]],calls:[["view","api-endpoint"],["flow","api-endpoint"],["api-endpoint","api-endpoint"],["api-endpoint","view"]],displays:[["view","data-model"]],queries:[["api-endpoint","data-model"]],covers:[["acceptance","view"],["acceptance","flow"]],supersedes:[["decision","decision"]],generates:[["decision","acceptance"]],impacts:[["decision","flow"],["decision","view"],["decision","data-model"],["decision","api-endpoint"]]};var he=["saves-time","simplifies","makes-money","reduces-risk","organizes","integrates","connects","reduces-effort","avoids-hassles","reduces-cost","quality","variety","sensory-appeal","informs","reduces-anxiety","rewards-me","nostalgia","design-aesthetics","badge-value","wellness","therapeutic-value","fun-entertainment","attractiveness","provides-access","provides-hope","self-actualization","motivation","heirloom","affiliation-belonging","self-transcendence"];var _e={flow:"F-",view:"V-","data-model":"DM-","api-endpoint":"API-",acceptance:"AC-",decision:"DEC-"};var Fe=["proposed","approved","enacted","rejected","deprecated","superseded"];function ve(f){switch(f){case"proposed":return"discovery";case"approved":return"backlog";case"enacted":return"live";case"rejected":case"deprecated":case"superseded":return"archived"}}function Se(f){let l=f.metadata?.decision_status;return Fe.includes(l)?l:"proposed"}var ce={prioritized:"backlog",blocked:"development"};function le(f){return Z.includes(f)?f:ce[f]}var Ye={...ce},We={backlog:"idea",...ce};function we(f){let l=new Map;for(let e of f){if(e.type!=="screenshot.recorded"&&e.type!=="screenshot.removed"||typeof e.node_id!="string"||typeof e.platform!="string")continue;let s=l.get(e.node_id);s||(s=new Map,l.set(e.node_id,s)),s.set(e.platform,e.type==="screenshot.removed"?null:e)}return l}function $e(f){let l=e=>typeof e=="string"?e:"";return[...f].sort((e,s)=>{let $=l(e.ts),S=l(s.ts);if($<S)return-1;if($>S)return 1;let m=l(e.id),R=l(s.id);return m<R?-1:m>R?1:0})}function ue(f){let l=[],e=[];return f.split(/\r?\n/).forEach(($,S)=>{let m=S+1;if($.trim()==="")return;let R;try{R=JSON.parse($)}catch(L){e.push({line:m,rule:"journal-line-parse",message:`Line ${m}: not valid JSON \u2014 ${L.message}`,severity:"error"});return}if(typeof R!="object"||R===null||Array.isArray(R)){e.push({line:m,rule:"journal-line-shape",message:`Line ${m}: each journal line must be a single JSON event object.`,severity:"error"});return}let T=R,k=[];if(typeof T.id!="string"&&k.push("id"),typeof T.ts!="string"&&k.push("ts"),typeof T.type!="string"&&k.push("type"),k.length>0){e.push({line:m,rule:"journal-line-shape",message:`Line ${m}: event is missing required envelope field(s): ${k.join(", ")}.`,severity:"error"});return}l.push(T)}),{events:l,findings:e}}var Oe={"node.updated":["node_id"],"node.status_changed":["node_id"],"decision.status_changed":["node_id"],"node.deleted":["node_id"],"edge.added":["source_id","target_id"],"ref.added":["node_id"],"ref.removed":["node_id"],"ref.status_changed":["node_id"],"screenshot.recorded":["node_id"],"screenshot.removed":["node_id"],"idea.proposed":["node_id"],"request.filed":["node_id"]};function be(f){return typeof f=="object"&&f!==null&&!Array.isArray(f)}function Le(f,l){return f===l?!0:typeof l!="string"?!1:f==="backlog"&&l==="idea"?!0:(le(f)??f)===(le(l)??l)}function Ee(f){let l=[],e=f.journal;if(e===void 0)return l;if(!Array.isArray(e))return l.push({path:"journal",rule:"journal-shape",message:"journal must be an array of events when present.",severity:"error"}),l;if(e.length===0)return l;let s=c=>typeof c=="string"?c:void 0,$=Array.isArray(f.nodes)?f.nodes:[],S=Array.isArray(f.edges)?f.edges:[],m=new Map,R=new Map;for(let c of $){let g=s(c?.id);if(g!==void 0){m.set(g,c.status);let _=c.metadata,b=_&&typeof _=="object"&&!Array.isArray(_)?_.decision_status:void 0;R.set(g,b??"proposed")}}let T=new Set;for(let c of S){let g=s(c?.id);g!==void 0&&T.add(g)}let k=[];e.forEach((c,g)=>{let _=`journal[${g}]`;if(typeof c!="object"||c===null||Array.isArray(c)){l.push({path:_,rule:"journal-event-shape",message:`journal[${g}]: each event must be a JSON object.`,severity:"error"});return}let b=c,M=[];if(s(b.id)===void 0&&M.push("id"),s(b.ts)===void 0&&M.push("ts"),s(b.type)===void 0&&M.push("type"),M.length>0){l.push({path:_,rule:"journal-event-envelope",message:`journal[${g}]: event is missing required envelope field(s): ${M.join(", ")}.`,severity:"error"});return}k.push({ev:b,index:g})});let L=new Set(m.keys()),x=new Set(T),F=new Set;for(let{ev:c}of k)if(c.type==="node.created"){let g=s(c.node_id);g&&L.add(g)}else if(c.type==="edge.added"){let g=s(c.edge_id);g&&x.add(g)}else if(c.type==="journal.baseline"&&Array.isArray(c.node_ids))for(let g of c.node_ids){let _=s(g);_&&(F.add(_),L.add(_))}let O=$e(k.map(c=>c.ev)),J=new Set,U=new Map,q=new Map;for(let c of O)if(c.type==="node.created"){let g=s(c.node_id);g&&J.add(g)}else if(c.type==="node.status_changed"){let g=s(c.node_id);if(g&&c.platform===void 0){let _=s(c.to);_!==void 0&&U.set(g,_)}}else if(c.type==="decision.status_changed"){let g=s(c.node_id);if(g){let _=s(c.to);_!==void 0&&q.set(g,_)}}for(let{ev:c,index:g}of k){let _=Oe[c.type];if(_)for(let b of _){let M=s(c[b]);M!==void 0&&!L.has(M)&&l.push({path:`journal[${g}].${b}`,rule:"journal-dangling-node-ref",message:`journal[${g}] (${c.type}): references node "${M}" that never existed in the snapshot or journal.`,severity:"error"})}if(c.type==="deliverable.shipped"&&Array.isArray(c.node_ids)&&c.node_ids.forEach((b,M)=>{let G=s(b);G!==void 0&&!L.has(G)&&l.push({path:`journal[${g}].node_ids[${M}]`,rule:"journal-dangling-node-ref",message:`journal[${g}] (${c.type}): references node "${G}" that never existed in the snapshot or journal.`,severity:"error"})}),c.type==="edge.removed"){let b=s(c.edge_id);b!==void 0&&!x.has(b)&&l.push({path:`journal[${g}].edge_id`,rule:"journal-dangling-edge-ref",message:`journal[${g}] (edge.removed): references edge "${b}" that never existed in the snapshot or journal.`,severity:"error"})}}for(let[c,g]of m){!J.has(c)&&!F.has(c)&&l.push({path:"journal",rule:"journal-missing-node-created",message:`Node "${c}" is present in the snapshot but has no node.created event in the journal.`,severity:"error"});let _=U.get(c);_!==void 0&&!Le(_,g)&&l.push({path:"journal",rule:"journal-status-mismatch",message:`Node "${c}": journal's last node.status_changed.to "${_}" disagrees with snapshot status "${String(g)}".`,severity:"error"})}for(let[c,g]of q){if(!R.has(c))continue;let _=R.get(c)??"proposed";g!==_&&l.push({path:"journal",rule:"journal-decision-status-mismatch",message:`Node "${c}": journal's last decision.status_changed.to "${g}" disagrees with snapshot decision_status "${String(_)}".`,severity:"error"})}let X=we(O);return $.forEach((c,g)=>{let _=s(c?.id);if(_===void 0)return;let b=be(c.metadata)?c.metadata:{},M=be(b.platformScreenshots)?b.platformScreenshots:{},G=X.get(_),ne=new Set([...Object.keys(M),...G?G.keys():[]]);for(let V of ne){let W=G?.get(V);if(W===void 0)continue;let K=typeof M[V]=="string"?M[V]:void 0,H,B;if(W===null)B=K===void 0,H="it was removed";else if(W.form==="data")B=K!==void 0,H="a data URI was recorded";else{let z=s(W.url);B=K===z,H=z===void 0?"an unknown value was recorded":`"${z}" was recorded`}B||l.push({path:`nodes[${g}].metadata.platformScreenshots.${V}`,rule:"screenshot-untracked",message:`Node "${_}": platformScreenshots.${V} is ${K===void 0?"empty":`"${K}"`} but the journal's last screenshot event says ${H} \u2014 write screenshots through record_screenshot, not update_node.`,severity:"warning"})}}),l}var ke=["flow","view","acceptance"];function Ae(f){let l=f?.metadata?.products;if(!Array.isArray(l))return[];let e=new Set,s=[];for(let $ of l){if(typeof $!="object"||$===null||Array.isArray($))continue;let S=$;typeof S.id!="string"||S.id.trim()===""||e.has(S.id)||(e.add(S.id),s.push(S))}return s}var xe=["rings","bars"],Ie=["chips","rows"],Re=["status","species"];var Ce=["journey","system","screens"];function Me(f){return Ce.includes(f)}var re="cross-surface";var Je=["beta","monitoring","deprecated"],Pe=["compact","large"],je=2*1024*1024;function qe(f){let l=f.indexOf(",");if(l===-1)return 0;let e=f.slice(l+1),s=e.endsWith("==")?2:e.endsWith("=")?1:0;return Math.floor(e.length*3/4)-s}function De(f){return typeof f=="string"&&!Number.isNaN(Date.parse(f))}function Ne(f){let l=[],e=(t,r,n)=>l.push({path:t,rule:r,message:n,severity:"error"}),s=(t,r,n)=>l.push({path:t,rule:r,message:n,severity:"warning"}),$=()=>{let t=l.filter(n=>n.severity==="error"),r=l.filter(n=>n.severity==="warning");return{valid:t.length===0,findings:l,errors:t,warnings:r}};if(typeof f!="object"||f===null||Array.isArray(f))return e("","bundle-shape","Bundle must be an object with project, nodes, and edges."),$();let S=f,m=S.project,R=S.nodes,T=S.edges;if(!m||!R||!T)return e("","bundle-shape","Missing top-level keys (project, nodes, edges)."),$();if(!Array.isArray(R))return e("nodes","bundle-shape","nodes must be an array."),$();if(!Array.isArray(T))return e("edges","bundle-shape","edges must be an array."),$();let k=R,L=T,x=new Map,F=new Set;m.id||e("project.id","project-id-required","project.id is missing"),(typeof m.title!="string"||!m.title.trim())&&e("project.title","title-non-empty","project.title is missing or empty"),m.created_at||e("project.created_at","timestamp-required","project.created_at is missing"),m.updated_at||e("project.updated_at","timestamp-required","project.updated_at is missing"),m.created_at&&!De(m.created_at)&&s("project.created_at","iso-timestamp","project.created_at is not a valid ISO 8601 timestamp"),m.updated_at&&!De(m.updated_at)&&s("project.updated_at","iso-timestamp","project.updated_at is not a valid ISO 8601 timestamp");let O=m.metadata;O&&O.view_card_variant!==void 0&&!Pe.includes(O.view_card_variant)&&e("project.metadata.view_card_variant","view-card-variant",`project.metadata.view_card_variant must be one of ${Pe.join(", ")} (import rejects other values)`),k.forEach((t,r)=>{let n=`nodes[${r}]`,i=t.id;F.has(i)&&e(`${n}.id`,"duplicate-node-id",`Duplicate node ID: ${i}`),F.add(i),x.set(i,t),(typeof t.title!="string"||!t.title.trim())&&e(`${n}.title`,"title-non-empty",`Node ${i}: title is missing or empty`);let a=t.species,o=_e[a];o&&!(typeof i=="string"&&i.startsWith(o))&&e(`${n}.id`,"species-prefix",`Node ${i}: species "${a}" should have prefix "${o}"`),se.includes(a)||e(`${n}.species`,"valid-species",`Node ${i}: invalid species "${a}"`),t.project_id!==m.id&&e(`${n}.project_id`,"project-id-match",`Node ${i}: project_id "${t.project_id}" does not match project.id "${m.id}"`),Z.includes(t.status)||e(`${n}.status`,"valid-status",`Node ${i}: invalid status "${t.status}"`);let u=t.platforms;if(!u||u.length===0)a!=="decision"&&e(`${n}.platforms`,"platforms-non-empty",`Node ${i}: platforms array is empty or missing`);else for(let d of u)ee.includes(d)||e(`${n}.platforms`,"valid-platform",`Node ${i}: invalid platform "${d}"`);let p=t.metadata||{};p.stage!==void 0&&!Je.includes(p.stage)&&e(`${n}.metadata.stage`,"valid-stage",`Node ${i}: invalid metadata.stage "${p.stage}"`);let w=p.platformNotes;if(w)for(let d of Object.keys(w))ee.includes(d)||e(`${n}.metadata.platformNotes`,"valid-platform",`Node ${i}: platformNotes has invalid platform "${d}"`);let E=p.platformStatuses;if(E)for(let[d,y]of Object.entries(E))ee.includes(d)?Array.isArray(u)&&!u.includes(d)&&s(`${n}.metadata.platformStatuses`,"platform-statuses-subset",`Node ${i}: platformStatuses covers platform "${d}" not in node.platforms`):e(`${n}.metadata.platformStatuses`,"valid-platform",`Node ${i}: platformStatuses has invalid platform "${d}"`),Z.includes(y)||e(`${n}.metadata.platformStatuses`,"valid-status",`Node ${i}: platformStatuses has invalid status "${y}" for platform "${d}"`);let I=p.platformScreenshots;if(I){for(let[d,y]of Object.entries(I))if(typeof y=="string"&&y.startsWith("data:")){let j=qe(y);j>je&&s(`${n}.metadata.platformScreenshots`,"screenshot-data-uri-size",`Node ${i}: platformScreenshots.${d} is a ${(j/(1024*1024)).toFixed(1)}MB data URI, above the ${je/(1024*1024)}MB guidance (docs/spec/bundle-format.md \xA7 Asset Values) \u2014 consider a relative path or hosted URL instead`)}}let P=p.gherkin,C=p.values;if(a==="acceptance"?((typeof P!="string"||!P.trim())&&s(`${n}.metadata.gherkin`,"acceptance-gherkin-missing",`Acceptance ${i}: metadata.gherkin is missing or empty (one Given/When/Then scenario expected)`),(!Array.isArray(C)||C.length===0)&&s(`${n}.metadata.values`,"acceptance-values-missing",`Acceptance ${i}: metadata.values is missing or empty (assign 1-3 value elements)`)):(P!==void 0&&s(`${n}.metadata.gherkin`,"gherkin-species",`Node ${i}: metadata.gherkin is only meaningful on acceptance nodes`),C!==void 0&&s(`${n}.metadata.values`,"values-species",`Node ${i}: metadata.values is only meaningful on acceptance nodes`)),Array.isArray(C))for(let d of C)he.includes(d)||e(`${n}.metadata.values`,"valid-value",`Node ${i}: invalid value element "${d}"`);let h=p.refs;if(Array.isArray(h)){let d=new Set;h.forEach((y,j)=>{let A=y??{},D=`${n}.metadata.refs[${j}]`,N=A.id;typeof N!="string"||!N.trim()?e(`${D}.id`,"ref-id-required",`Node ${i}: ref is missing an id`):d.has(N)?e(`${D}.id`,"duplicate-ref-id",`Node ${i}: duplicate ref id "${N}"`):d.add(N),(typeof A.url!="string"||!A.url.trim())&&e(`${D}.url`,"ref-url-required",`Node ${i}: ref "${N}" is missing a url`),A.status_mapped!==void 0&&!Z.includes(A.status_mapped)&&e(`${D}.status_mapped`,"valid-status",`Node ${i}: ref "${N}" has invalid status_mapped "${A.status_mapped}"`)})}if(p.decision_status!==void 0&&a!=="decision"&&s(`${n}.metadata.decision_status`,"decision-status-wrong-species",`decision_status is meaningful on decision nodes only; "${i}" is a ${a}.`),a==="decision"){let d=Se({metadata:t.metadata}),y=ve(d);t.status!==y&&s(`${n}.status`,"decision-lifecycle-mismatch",`Decision "${i}" is ${d}, whose lifecycle status should be "${y}", but status is "${t.status}" (spec \xA72).`)}if(a==="flow"){let d=p.playlist;!t.metadata||!d||!d.entries?e(`${n}.metadata.playlist`,"flow-playlist-required",`Flow ${i}: missing metadata.playlist.entries`):d.entries.length===0&&s(`${n}.metadata.playlist`,"flow-playlist-empty",`Flow ${i}: playlist is empty`)}});let J=m.root_node_id;J&&!F.has(J)&&e("project.root_node_id","root-node-exists",`project.root_node_id "${J}" does not reference an existing node`);let U=(t,r,n)=>{if(typeof t!="object"||t===null||Array.isArray(t))return;let i=t,a=[["flow_platforms",xe],["view_platforms",Ie],["minimap_color",Re]];for(let[o,u]of a){let p=i[o];p!==void 0&&(typeof p!="string"||!u.includes(p))&&s(`${r}.${o}`,"map-unknown-display",`${n} sets ${o} to "${String(p)}"; expected one of ${u.join(", ")} (renderers fall back to the default)`)}i.images!==void 0&&typeof i.images!="boolean"&&s(`${r}.images`,"map-unknown-display",`${n} sets images to a non-boolean value (renderers fall back to the default)`)},q=O?.map_display;if(typeof q=="object"&&q!==null&&!Array.isArray(q))for(let[t,r]of Object.entries(q))U(r,`project.metadata.map_display.${t}`,`Map "${t}"`);let X=O?.maps;if(Array.isArray(X)){let t=new Set;X.forEach((r,n)=>{if(typeof r!="object"||r===null||Array.isArray(r))return;let i=r,a=`project.metadata.maps[${n}]`,o=typeof i.id=="string"?i.id:void 0;o!==void 0&&(t.has(o)&&s(`${a}.id`,"map-duplicate-id",`Duplicate map id "${o}"`),t.add(o),Me(o)&&s(`${a}.id`,"map-shadows-built-in",`Map id "${o}" shadows a built-in map and will be ignored`));let u=i.root_node_id;typeof u=="string"&&!F.has(u)&&s(`${a}.root_node_id`,"map-unknown-root",`Map "${o??n}" anchors on "${u}" which does not reference an existing node`),Array.isArray(i.species)&&i.species.forEach((p,w)=>{typeof p=="string"&&!se.includes(p)&&s(`${a}.species[${w}]`,"map-unknown-species",`Map "${o??n}" filters on unknown species "${p}"`)}),Array.isArray(i.edge_types)&&i.edge_types.forEach((p,w)=>{typeof p=="string"&&!de.includes(p)&&s(`${a}.edge_types[${w}]`,"map-unknown-edge-type",`Map "${o??n}" filters on unknown edge type "${p}"`)}),U(i.display,`${a}.display`,`Map "${o??n}"`)})}let c=O?.products,g=new Set;if(Array.isArray(c)){let t=new Set;c.forEach((r,n)=>{if(typeof r!="object"||r===null||Array.isArray(r))return;let i=r,a=`project.metadata.products[${n}]`,o=typeof i.id=="string"?i.id:void 0;o!==void 0&&(t.has(o)?s(`${a}.id`,"product-duplicate-id",`Duplicate product id "${o}" \u2014 the first wins`):(t.add(o),o.trim()!==""&&g.add(o)),/^[a-z0-9]+(-[a-z0-9]+)*$/.test(o)||s(`${a}.id`,"product-invalid-id",`Product id "${o}" is not kebab-case`))})}let _=g.size>0,b=new Map;for(let t of L){if(t.edge_type!=="covers")continue;let r=typeof t.source_id=="string"?t.source_id:void 0,n=typeof t.target_id=="string"?t.target_id:void 0;if(r===void 0||n===void 0)continue;let i=b.get(r)??[];i.push(n),b.set(r,i)}let M=new Map;if(_)for(let t of Ae({metadata:O}))M.set(t.id,new Set(Array.isArray(t.platforms)?t.platforms:[]));let G=new Map,ne=new Map;if(k.forEach((t,r)=>{let n=typeof t.id=="string"?t.id:`#${r}`,i=t.species,a=`nodes[${r}]`;ne.set(n,r);let o=t.metadata??{},u=typeof o.product=="string"?o.product:void 0,p=i!==void 0&&ke.includes(i);if(u!==void 0&&!p){let I=se.includes(i)?`${i} membership is derived from consumers and must not be stored`:"metadata.product is only meaningful on flow, view, and acceptance nodes";s(`${a}.metadata.product`,"product-membership-wrong-species",`Node ${n}: ${I}`);return}if(!p)return;if(u===void 0){if(!_)return;i==="acceptance"?b.has(n)||s(`${a}.metadata.product`,"acceptance-product-unassigned",`Acceptance ${n} covers nothing and names no product \u2014 it will show only under "All products"`):s(`${a}.metadata.product`,"unassigned-membership",`Node ${n}: no product membership \u2014 it will show only under "All products"`);return}if(G.set(n,u),!g.has(u)){s(`${a}.metadata.product`,"product-unknown-reference",`Node ${n}: product "${u}" is not declared on the project`);return}let w=M.get(u),E=Array.isArray(t.platforms)?t.platforms:[];if(w)for(let I of E)typeof I=="string"&&!w.has(I)&&s(`${a}.platforms`,"product-platform-not-in-menu",`Node ${n}: platform "${I}" is not in product "${u}"'s menu`)}),_)for(let[t,r]of b){let n=ne.get(t);if(n===void 0)continue;let i=new Set(r.map(a=>G.get(a)).filter(a=>!!a));i.size>1&&s(`nodes[${n}].metadata.product`,"acceptance-covers-span-products",`Acceptance ${t} covers anchors in ${[...i].sort().join(" and ")} \u2014 statuses may conflate products`)}let V=new Set,W=new Set,K=new Set;L.forEach((t,r)=>{let n=`edges[${r}]`,i=t.id,a=t.source_id,o=t.target_id,u=t.edge_type;V.has(i)&&e(`${n}.id`,"duplicate-edge-id",`Duplicate edge ID: ${i}`),V.add(i);let p=`e-${a}-${o}`;i!==p&&s(`${n}.id`,"edge-id-convention",`Edge ${i}: id does not match convention "${p}" (stale after a rename?)`);let w=`${a}->${o}:${u}`;W.has(w)&&s(`${n}`,"duplicate-edge-relationship",`Duplicate edge relationship: ${w}`),W.add(w),t.project_id!==m.id&&e(`${n}.project_id`,"project-id-match",`Edge ${i}: project_id does not match project.id`),F.has(a)||e(`${n}.source_id`,"dangling-edge",`Edge ${i}: source_id "${a}" not found in nodes`),F.has(o)||e(`${n}.target_id`,"dangling-edge",`Edge ${i}: target_id "${o}" not found in nodes`),de.includes(u)||e(`${n}.edge_type`,"valid-edge-type",`Edge ${i}: invalid edge_type "${u}"`);let E=x.get(a),I=x.get(o),P=me[u];E&&I&&P&&(P.some(([h,v])=>h===E.species&&v===I.species)||e(`${n}.edge_type`,"edge-semantics",`Edge ${i}: "${u}" not valid from ${E.species} to ${I.species}`)),u==="composes"&&K.add(`${a}->${o}`)});let H=["view","flow","condition","junction"],B=(t,r,n,i=0)=>{if(!(i>50)){if(!Array.isArray(t)){e(n,"playlist-entry-shape",`Flow ${r}: ${n} must be an array of playlist entries`);return}t.forEach((a,o)=>{let u=`${n}[${o}]`;if(typeof a!="object"||a===null||Array.isArray(a)){e(u,"playlist-entry-shape",`Flow ${r}: ${u} must be a playlist entry object`);return}let p=a,w=p.type;if(typeof w!="string"||!H.includes(w)){e(`${u}.type`,"playlist-entry-shape",`Flow ${r}: ${u}.type must be one of ${H.join(", ")} (got ${JSON.stringify(w)})`);return}if(w==="view")typeof p.view_id!="string"&&e(`${u}.view_id`,"playlist-entry-shape",`Flow ${r}: ${u} is a view entry with no view_id string`);else if(w==="flow")typeof p.flow_id!="string"&&e(`${u}.flow_id`,"playlist-entry-shape",`Flow ${r}: ${u} is a flow entry with no flow_id string`);else if(w==="condition"){typeof p.label!="string"&&e(`${u}.label`,"playlist-entry-shape",`Flow ${r}: ${u} is a condition with no label string`);for(let E of["if_true","if_false"])Array.isArray(p[E])?B(p[E],r,`${u}.${E}`,i+1):e(`${u}.${E}`,"playlist-entry-shape",`Flow ${r}: ${u}.${E} must be an array of playlist entries (both branches are required, use [] for an empty one)`)}else{if(typeof p.label!="string"&&e(`${u}.label`,"playlist-entry-shape",`Flow ${r}: ${u} is a junction with no label string`),!Array.isArray(p.cases)){e(`${u}.cases`,"playlist-entry-shape",`Flow ${r}: ${u}.cases must be an array of junction cases`);return}p.cases.forEach((E,I)=>{let P=`${u}.cases[${I}]`;if(typeof E!="object"||E===null||Array.isArray(E)){e(P,"playlist-entry-shape",`Flow ${r}: ${P} must be a junction case object`);return}let C=E;typeof C.label!="string"&&e(`${P}.label`,"playlist-entry-shape",`Flow ${r}: ${P} has no label string`),Array.isArray(C.entries)?B(C.entries,r,`${P}.entries`,i+1):e(`${P}.entries`,"playlist-entry-shape",`Flow ${r}: ${P}.entries must be an array of playlist entries \u2014 a junction case holds its own entries, not a bare view_id/flow_id`)})}})}};k.forEach((t,r)=>{let n=t.metadata;t.species==="flow"&&n?.playlist?.entries&&B(n.playlist.entries,t.id,`nodes[${r}].metadata.playlist.entries`)});let z=(t,r,n,i=0)=>{if(i>50)return e(n,"playlist-depth",`Flow ${r}: playlist nesting too deep (possible cycle)`),[];let a=[];if(!Array.isArray(t))return a;for(let o of t)if(!(typeof o!="object"||o===null)){if(o.type==="view")F.has(o.view_id)||e(n,"playlist-ref-exists",`Flow ${r}: playlist references non-existent view "${o.view_id}"`),a.push(o.view_id);else if(o.type==="flow")F.has(o.flow_id)||e(n,"playlist-ref-exists",`Flow ${r}: playlist references non-existent flow "${o.flow_id}"`),o.flow_id===r&&e(n,"playlist-self-cycle",`Flow ${r}: playlist contains itself (direct cycle)`),a.push(o.flow_id);else if(o.type==="condition")o.if_true&&a.push(...z(o.if_true,r,n,i+1)),o.if_false&&a.push(...z(o.if_false,r,n,i+1));else if(o.type==="junction"&&o.cases)for(let u of o.cases)a.push(...z(u.entries||[],r,n,i+1))}return a};k.forEach((t,r)=>{let n=t.metadata;if(t.species==="flow"&&n?.playlist?.entries){let i=`nodes[${r}].metadata.playlist`,a=t.id,o=z(n.playlist.entries,a,i);for(let u of o)K.has(`${a}->${u}`)||e(i,"playlist-composes-coherence",`Flow ${a}: playlist references "${u}" but no composes edge exists`)}});let oe=new Map,pe=new Map;k.forEach((t,r)=>{let n=t.metadata;if(t.species==="flow"&&n?.playlist?.entries){let i=t.id,a=[],o=u=>{if(Array.isArray(u)){for(let p of u)if(!(typeof p!="object"||p===null)&&(p.type==="flow"&&a.push(p.flow_id),p.type==="condition"&&(p.if_true&&o(p.if_true),p.if_false&&o(p.if_false)),p.type==="junction"&&p.cases))for(let w of p.cases)o(w.entries||[])}};o(n.playlist.entries),oe.set(i,a),pe.set(i,`nodes[${r}].metadata.playlist`)}});let fe=new Set,ae=new Set,ge=t=>{if(ae.has(t))return!0;if(fe.has(t))return!1;fe.add(t),ae.add(t);for(let r of oe.get(t)||[])if(ge(r))return e(pe.get(t)??"","flow-cycle",`Cycle detected: flow "${t}" -> "${r}"`),!0;return ae.delete(t),!1};for(let t of oe.keys())ge(t);let ie=S.quality;if(typeof ie=="object"&&ie!==null&&!Array.isArray(ie)){let t=ie,r=Array.isArray(t.assessments)?t.assessments:[],n=Array.isArray(t.findings)?t.findings:[],i=typeof t.profile=="object"&&t.profile!==null?t.profile:void 0,a=new Set;Array.isArray(i?.surfaces)&&i.surfaces.forEach((h,v)=>{if(typeof h!="object"||h===null||Array.isArray(h))return;let d=h,y=typeof d.id=="string"?d.id:void 0;y===void 0||y.trim()===""||(a.has(y)&&s(`quality.profile.surfaces[${v}].id`,"quality-duplicate-surface",`Duplicate surface id "${y}" \u2014 the first wins`),a.add(y))}),a.size===0&&(r.length>0||n.length>0)&&s("quality.profile.surfaces","quality-no-surfaces","Quality data is stored but the profile declares no surfaces \u2014 the matrix falls back to the surfaces the assessments name");let o=typeof t.library=="object"&&t.library!==null?t.library:void 0,u=new Set,p=new Map;if(Array.isArray(o?.criteria))for(let h of o.criteria){if(typeof h!="object"||h===null)continue;let v=h;typeof v.id=="string"&&(u.add(v.id),typeof v.superseded_by=="string"&&v.superseded_by!==""&&p.set(v.id,v.superseded_by))}else(r.length>0||n.length>0)&&s("quality.library","quality-library-missing","No criteria pack is embedded \u2014 criterion ids cannot be resolved to domains or weights; the matrix uses a synthesized library");(typeof t.framework_version!="string"||t.framework_version==="")&&s("quality.framework_version","quality-framework-version-missing","Quality section has no framework_version \u2014 scores are not comparable across audits without one");let w=(h,v,d)=>{let y=typeof h.criterion_id=="string"?h.criterion_id:void 0;y!==void 0&&u.size>0&&!u.has(y)&&s(`${v}.criterion_id`,"quality-unknown-criterion",`${d}: criterion "${y}" is not in the pinned library`);let j=y!==void 0?p.get(y):void 0;j!==void 0&&s(`${v}.criterion_id`,"quality-retired-criterion",`${d}: criterion "${y}" is retired \u2014 superseded by "${j}"`);let A=typeof h.surface=="string"?h.surface:void 0;A!==void 0&&A!==re&&a.size>0&&!a.has(A)&&s(`${v}.surface`,"quality-unknown-surface",`${d}: surface "${A}" is not declared in the profile`)},E=new Set;r.forEach((h,v)=>{if(typeof h!="object"||h===null||Array.isArray(h))return;let d=h,y=`quality.assessments[${v}]`,j=`Assessment ${v}`;w(d,y,j);let A=d.level;(typeof A!="number"||!Number.isInteger(A)||A<0||A>4)&&s(`${y}.level`,"quality-level-range",`${j}: level must be an integer 0-4 (N/A is the absence of the row, not a level)`),d.surface===re&&s(`${y}.surface`,"quality-cross-surface-assessment",`${j}: "${re}" is a findings-only lens \u2014 it carries no matrix column, so this score would render nowhere`),(typeof d.evidence!="string"||d.evidence.trim()==="")&&s(`${y}.evidence`,"quality-assessment-no-evidence",`${j}: scored with no evidence \u2014 a score without a citation is an opinion, not an assessment`);let D=typeof d.criterion_id=="string"?d.criterion_id:void 0,N=typeof d.surface=="string"?d.surface:void 0;if(D!==void 0&&N!==void 0){let ye=`${D}\0${N}`;E.has(ye)&&s(`${y}`,"quality-duplicate-assessment",`${j}: a second score for (${D} x ${N}) \u2014 the section stores latest-per-cell, so this cell is ambiguous`),E.add(ye)}});let I=new Set;n.forEach((h,v)=>{if(typeof h!="object"||h===null||Array.isArray(h))return;let d=h,y=`quality.findings[${v}]`,j=`Finding ${v}`;w(d,y,j);let A=typeof d.id=="string"?d.id:void 0;A!==void 0&&(I.has(A)&&s(`${y}.id`,"quality-duplicate-finding-id",`Duplicate finding id "${A}"`),I.add(A));for(let D of["impact","likelihood"]){let N=d[D];(typeof N!="number"||!Number.isInteger(N)||N<1||N>5)&&s(`${y}.${D}`,"quality-risk-range",`${j}: ${D} must be an integer 1-5 \u2014 severity is derived from impact x likelihood`)}for(let D of["severity","priority"])D in d&&s(`${y}.${D}`,"quality-derived-field-stored",`${j}: ${D} is derived from impact, likelihood and cost \u2014 storing it lets it drift from the numbers behind it`);d.status==="accepted-risk"&&(typeof d.detail!="string"||d.detail.trim()==="")&&s(`${y}.detail`,"quality-accepted-risk-no-note",`${j}: accepted-risk with no note \u2014 an accepted risk is a decision and reads like one`)});let P=new Set,C=Array.isArray(S.journal)?S.journal:[];C.forEach(h=>{if(typeof h!="object"||h===null)return;let v=h;v.type==="quality.finding.opened"&&typeof v.finding_id=="string"&&P.add(v.finding_id)}),C.forEach((h,v)=>{if(typeof h!="object"||h===null)return;let d=h,y=typeof d.type=="string"?d.type:"";y.startsWith("quality.")&&((typeof d.actor!="string"||d.actor.trim()==="")&&s(`journal[${v}].actor`,"quality-event-no-actor",`Journal event ${v}: ${y} has no actor \u2014 human, agent and CI scores become indistinguishable`),y==="quality.finding.resolved"&&typeof d.finding_id=="string"&&!P.has(d.finding_id)&&!I.has(d.finding_id)&&s(`journal[${v}].finding_id`,"quality-resolved-never-opened",`Journal event ${v}: resolves finding "${d.finding_id}", which no quality.finding.opened event or stored finding ever declared`),y==="quality.finding.accepted"&&typeof d.finding_id=="string"&&!P.has(d.finding_id)&&!I.has(d.finding_id)&&s(`journal[${v}].finding_id`,"quality-accepted-never-opened",`Journal event ${v}: accepts finding "${d.finding_id}", which no quality.finding.opened event or stored finding ever declared`))})}for(let t of Ee(S))l.push(t);return $()}var Te="journal.jsonl",Ue="journal";function Ge(f){let l=(0,Y.join)(f,Ue);return(0,Q.existsSync)(l)?(0,Q.readdirSync)(l).filter(e=>e.startsWith("archive-")&&e.endsWith(".jsonl")).sort().map(e=>(0,Y.join)(l,e)):[]}function te(f,l){return f.filter(e=>e?.species===l).length}function Qe(){let f=process.argv[2];f||(console.error("Usage: node validate-bundle.js <path-to-bundle.json>"),process.exit(1)),(0,Q.existsSync)(f)||(console.error(`File not found: ${f}`),process.exit(1));let l;try{l=JSON.parse((0,Q.readFileSync)(f,"utf8"))}catch(x){console.error(`FATAL: Cannot parse JSON \u2014 ${x.message}`),process.exit(1)}let e=l;(typeof e!="object"||e===null||!e.project||!e.nodes||!e.edges)&&(console.error("FATAL: Missing top-level keys (project, nodes, edges)."),process.exit(1));let s=[],$=!1,S=[];if(e.journal===void 0){let x=(0,Y.dirname)(f),F=(0,Y.join)(x,Te),O=[];if((0,Q.existsSync)(F)){let{events:J,findings:U}=ue((0,Q.readFileSync)(F,"utf8"));for(let q of U)s.push(q.message);$=!0,O.push(...J)}for(let J of Ge(x)){let U=(0,Y.basename)(J),{events:q,findings:X}=ue((0,Q.readFileSync)(J,"utf8"));for(let c of X)s.push(`${U} \u2014 ${c.message}`);S.push(U),O.push(...q)}($||S.length>0)&&(e.journal=O)}let m=Array.isArray(e.nodes)?e.nodes:[],R=Array.isArray(e.edges)?e.edges:[],T=Array.isArray(e.journal)?e.journal:[],k=Ne(l);if(console.log(`
|
|
14
14
|
Arkaik Bundle Validation`),console.log(` =======================
|
|
15
|
-
`),console.log(` Nodes: ${m.length} (${
|
|
16
|
-
`),process.exit(0)),console.log(` Errors: ${L.length}`),L.forEach(
|
|
15
|
+
`),console.log(` Nodes: ${m.length} (${te(m,"view")} views, ${te(m,"flow")} flows, ${te(m,"data-model")} data-models, ${te(m,"api-endpoint")} api-endpoints, ${te(m,"acceptance")} acceptances)`),console.log(` Edges: ${R.length}`),$||S.length>0){let x=[...$?[`${Te} sidecar`]:[],...S.length>0?[`${S.length} archive(s)`]:[]].join(" + ");console.log(` Journal: ${T.length} event(s) from ${x}`)}else T.length>0&&console.log(` Journal: ${T.length} embedded event(s)`);console.log(""),k.warnings.length>0&&(console.log(` Warnings: ${k.warnings.length}`),k.warnings.forEach(x=>console.log(` WARN: ${x.message}`)),console.log(""));let L=[...s,...k.errors.map(x=>x.message)];L.length===0&&(console.log(` Result: VALID
|
|
16
|
+
`),process.exit(0)),console.log(` Errors: ${L.length}`),L.forEach(x=>console.log(` ERROR: ${x}`)),console.log(`
|
|
17
17
|
Result: INVALID
|
|
18
|
-
`),process.exit(1)}
|
|
18
|
+
`),process.exit(1)}Qe();
|
|
@@ -108,6 +108,8 @@ Each graph operation has a matching event. Append one line per operation:
|
|
|
108
108
|
| Remove a node | `node.deleted` (`node_id`) — **implies** cascade removal of its edges; do NOT also emit `edge.removed` for those |
|
|
109
109
|
| Remove an edge on its own (node stays) | `edge.removed` (`edge_id`) |
|
|
110
110
|
| Attach / detach an external reference | `ref.added` / `ref.removed` |
|
|
111
|
+
| Record a screenshot for one platform | `screenshot.recorded` (`node_id`, `platform`, `source`, `form`, `url?`, `commit?`, `order?`) — through the `record_screenshot` tool/op, never by patching `metadata.platformScreenshots` (a slot patched through `update_node` is the legacy path and the validator warns `screenshot-untracked`) |
|
|
112
|
+
| Clear a screenshot | `screenshot.removed` (`node_id`, `platform`) — through `remove_screenshot` |
|
|
111
113
|
|
|
112
114
|
Other event types you may append when the change warrants it: `release.tagged`
|
|
113
115
|
(a version shipped), `idea.proposed` (an idea, before or linked to a node),
|
|
@@ -154,6 +156,7 @@ Map your code change to graph operations (and the events they pair with):
|
|
|
154
156
|
| Rename (label only) | Update the node's `title`; keep the `id` stable so edges stay intact | `node.updated` (`fields: ["title"]`, with `from`/`to`) |
|
|
155
157
|
| Rename (id must change) | Update the `id`, then repoint every edge's `source_id`/`target_id` **and** the edge `id` (`e-{source}-{target}`), plus any playlist `view_id`/`flow_id` and `root_node_id` | `node.updated` + `edge.removed`/`edge.added` for each repointed edge |
|
|
156
158
|
| Ship/add user-visible behavior on a platform | Find or create the covering `AC-` acceptance + `covers` edge to the view/flow; set `metadata.platformStatuses.<platform>` on the acceptance | `node.created` + `edge.added` (new acceptance) + `node.status_changed` (`platform`) |
|
|
159
|
+
| A screenshot of a view or acceptance on a platform | `record_screenshot` (`node_id`, `platform`, `source: manual`, `form`, `value`) — writes the slot, its meta and the event in one op | `screenshot.recorded` |
|
|
157
160
|
|
|
158
161
|
### 3. Apply the change
|
|
159
162
|
|