arkaik 0.4.0 → 0.6.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/scripts/validate-bundle.js +2 -2
- package/dist/index.js +707 -20
- package/dist/io.js +8 -0
- package/package.json +1 -1
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
*
|
|
11
11
|
* Usage: node validate-bundle.js <path-to-bundle.json>
|
|
12
12
|
*/
|
|
13
|
-
"use strict";var Q=require("node:fs"),U=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,G=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&&G.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=G.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 G=(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))G(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}"`)}),G(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,U.join)(f,qe);return(0,Q.existsSync)(p)?(0,Q.readdirSync)(p).filter(t=>t.startsWith("archive-")&&t.endsWith(".jsonl")).sort().map(t=>(0,U.join)(p,t)):[]}function Y(f,p){return f.filter(t=>t?.species===p).length}function Ge(){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 p;try{p=JSON.parse((0,Q.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,U.dirname)(f),F=(0,U.join)(k,je),O=[];if((0,Q.existsSync)(F)){let{events:q,findings:G}=re((0,Q.readFileSync)(F,"utf8"));for(let J of G)s.push(J.message);$=!0,O.push(...q)}for(let q of Je(k)){let G=(0,U.basename)(q),{events:J,findings:c}=re((0,Q.readFileSync)(q,"utf8"));for(let g of c)s.push(`${G} \u2014 ${g.message}`);w.push(G),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 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(`
|
|
14
14
|
Arkaik Bundle Validation`),console.log(` =======================
|
|
15
15
|
`),console.log(` Nodes: ${m.length} (${Y(m,"view")} views, ${Y(m,"flow")} flows, ${Y(m,"data-model")} data-models, ${Y(m,"api-endpoint")} api-endpoints, ${Y(m,"acceptance")} acceptances)`),console.log(` Edges: ${R.length}`),$||w.length>0){let k=[...$?[`${je} sidecar`]:[],...w.length>0?[`${w.length} archive(s)`]:[]].join(" + ");console.log(` Journal: ${T.length} event(s) from ${k}`)}else T.length>0&&console.log(` Journal: ${T.length} embedded event(s)`);console.log(""),E.warnings.length>0&&(console.log(` Warnings: ${E.warnings.length}`),E.warnings.forEach(k=>console.log(` WARN: ${k.message}`)),console.log(""));let L=[...s,...E.errors.map(k=>k.message)];L.length===0&&(console.log(` Result: VALID
|
|
16
16
|
`),process.exit(0)),console.log(` Errors: ${L.length}`),L.forEach(k=>console.log(` ERROR: ${k}`)),console.log(`
|
|
17
17
|
Result: INVALID
|
|
18
|
-
`),process.exit(1)}
|
|
18
|
+
`),process.exit(1)}Ue();
|
package/dist/index.js
CHANGED
|
@@ -15195,6 +15195,13 @@ var QualityAuditCompletedEventSchema = external_exports.object({
|
|
|
15195
15195
|
medium: external_exports.number().optional(),
|
|
15196
15196
|
low: external_exports.number().optional(),
|
|
15197
15197
|
info: external_exports.number().optional()
|
|
15198
|
+
}).catchall(external_exports.unknown()).optional(),
|
|
15199
|
+
// A scoped re-audit (issue #443). Optional and catchall like `counts`:
|
|
15200
|
+
// older readers ignore it, and its `scores` stay the same shape either way.
|
|
15201
|
+
scope: external_exports.object({
|
|
15202
|
+
partial: external_exports.boolean().optional(),
|
|
15203
|
+
cells: external_exports.number().optional(),
|
|
15204
|
+
since: external_exports.string().optional()
|
|
15198
15205
|
}).catchall(external_exports.unknown()).optional()
|
|
15199
15206
|
}).catchall(external_exports.unknown());
|
|
15200
15207
|
var QualityFindingOpenedEventSchema = external_exports.object({
|
|
@@ -15229,6 +15236,7 @@ var QualitySignalTrippedEventSchema = external_exports.object({
|
|
|
15229
15236
|
criterion_id: external_exports.string(),
|
|
15230
15237
|
surface: external_exports.string(),
|
|
15231
15238
|
signal: external_exports.string(),
|
|
15239
|
+
commit: external_exports.string().optional(),
|
|
15232
15240
|
detail: external_exports.string().optional()
|
|
15233
15241
|
}).catchall(external_exports.unknown());
|
|
15234
15242
|
var JOURNAL_EVENT_SCHEMAS = {
|
|
@@ -15686,6 +15694,18 @@ function capGrade(grade, cap) {
|
|
|
15686
15694
|
function isOpenFinding(finding) {
|
|
15687
15695
|
return (finding.status ?? "open") === "open";
|
|
15688
15696
|
}
|
|
15697
|
+
function rollUpSurface(scores, weights) {
|
|
15698
|
+
let weighted = 0;
|
|
15699
|
+
let total = 0;
|
|
15700
|
+
for (const domain2 of Object.keys(scores)) {
|
|
15701
|
+
const score = scores[domain2];
|
|
15702
|
+
if (typeof score !== "number" || !Number.isFinite(score)) continue;
|
|
15703
|
+
const weight = typeof weights?.[domain2] === "number" ? weights[domain2] : 1;
|
|
15704
|
+
weighted += score * weight;
|
|
15705
|
+
total += weight;
|
|
15706
|
+
}
|
|
15707
|
+
return total > 0 ? Math.round(weighted / total) : null;
|
|
15708
|
+
}
|
|
15689
15709
|
function resolveKritikLibrary(section, library) {
|
|
15690
15710
|
const explicit = library ?? section?.library;
|
|
15691
15711
|
if (explicit && Array.isArray(explicit.criteria) && Array.isArray(explicit.domains)) return explicit;
|
|
@@ -15761,16 +15781,12 @@ function deriveQualityMatrix(bundle, library) {
|
|
|
15761
15781
|
}
|
|
15762
15782
|
const overall = {};
|
|
15763
15783
|
for (const surface of surfaces) {
|
|
15764
|
-
|
|
15765
|
-
let total = 0;
|
|
15784
|
+
const bySurface = {};
|
|
15766
15785
|
for (const domain2 of domains) {
|
|
15767
15786
|
const cell = matrix[domain2]?.[surface];
|
|
15768
|
-
if (
|
|
15769
|
-
const weight = typeof weights?.[domain2] === "number" ? weights[domain2] : 1;
|
|
15770
|
-
weighted += cell.score * weight;
|
|
15771
|
-
total += weight;
|
|
15787
|
+
if (cell) bySurface[domain2] = cell.score;
|
|
15772
15788
|
}
|
|
15773
|
-
overall[surface] =
|
|
15789
|
+
overall[surface] = rollUpSurface(bySurface, weights);
|
|
15774
15790
|
}
|
|
15775
15791
|
const finding_counts = { critical: 0, high: 0, medium: 0, low: 0, info: 0 };
|
|
15776
15792
|
for (const finding of openFindings) finding_counts[severityOf(finding, pack)]++;
|
|
@@ -17193,7 +17209,8 @@ function auditCompletedInput(matrix, meta3) {
|
|
|
17193
17209
|
framework_version: meta3.framework_version,
|
|
17194
17210
|
...meta3.commit !== void 0 ? { commit: meta3.commit } : {},
|
|
17195
17211
|
scores,
|
|
17196
|
-
counts: matrix.finding_counts
|
|
17212
|
+
counts: matrix.finding_counts,
|
|
17213
|
+
...meta3.scope !== void 0 ? { scope: meta3.scope } : {}
|
|
17197
17214
|
}
|
|
17198
17215
|
};
|
|
17199
17216
|
}
|
|
@@ -17229,6 +17246,7 @@ function signalTrippedInput(trip) {
|
|
|
17229
17246
|
criterion_id: trip.criterion_id,
|
|
17230
17247
|
surface: trip.surface,
|
|
17231
17248
|
signal: trip.signal,
|
|
17249
|
+
...trip.commit !== void 0 ? { commit: trip.commit } : {},
|
|
17232
17250
|
...trip.detail !== void 0 ? { detail: trip.detail } : {}
|
|
17233
17251
|
}
|
|
17234
17252
|
};
|
|
@@ -17311,6 +17329,315 @@ function detectRegressions(previous, next, library) {
|
|
|
17311
17329
|
return regressions;
|
|
17312
17330
|
}
|
|
17313
17331
|
|
|
17332
|
+
// ../schema/src/quality-trend.ts
|
|
17333
|
+
var NO_DELTA = { previous: null, delta: null };
|
|
17334
|
+
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17335
|
+
function frameworkMajor(version2) {
|
|
17336
|
+
if (typeof version2 !== "string") return null;
|
|
17337
|
+
const match = /^\s*v?(\d+)/.exec(version2);
|
|
17338
|
+
return match ? Number(match[1]) : null;
|
|
17339
|
+
}
|
|
17340
|
+
function sameFrameworkMajor(a, b) {
|
|
17341
|
+
const left = frameworkMajor(a);
|
|
17342
|
+
const right = frameworkMajor(b);
|
|
17343
|
+
return left === null || right === null || left === right;
|
|
17344
|
+
}
|
|
17345
|
+
function cleanScores(raw) {
|
|
17346
|
+
const scores = {};
|
|
17347
|
+
if (!isRecord(raw)) return scores;
|
|
17348
|
+
for (const surface of Object.keys(raw)) {
|
|
17349
|
+
const bySurface = raw[surface];
|
|
17350
|
+
if (!isRecord(bySurface)) continue;
|
|
17351
|
+
const cleaned = {};
|
|
17352
|
+
for (const domain2 of Object.keys(bySurface)) {
|
|
17353
|
+
const score = bySurface[domain2];
|
|
17354
|
+
if (typeof score === "number" && Number.isFinite(score)) cleaned[domain2] = score;
|
|
17355
|
+
}
|
|
17356
|
+
scores[surface] = cleaned;
|
|
17357
|
+
}
|
|
17358
|
+
return scores;
|
|
17359
|
+
}
|
|
17360
|
+
function cleanCounts(raw) {
|
|
17361
|
+
const counts = { critical: 0, high: 0, medium: 0, low: 0, info: 0 };
|
|
17362
|
+
if (!isRecord(raw)) return counts;
|
|
17363
|
+
for (const severity of Object.keys(counts)) {
|
|
17364
|
+
const value = raw[severity];
|
|
17365
|
+
if (typeof value === "number" && Number.isFinite(value)) counts[severity] = value;
|
|
17366
|
+
}
|
|
17367
|
+
return counts;
|
|
17368
|
+
}
|
|
17369
|
+
function cellSet(scores) {
|
|
17370
|
+
const cells = /* @__PURE__ */ new Map();
|
|
17371
|
+
for (const surface of Object.keys(scores)) {
|
|
17372
|
+
for (const domain2 of Object.keys(scores[surface])) cells.set(`${surface}::${domain2}`, scores[surface][domain2]);
|
|
17373
|
+
}
|
|
17374
|
+
return cells;
|
|
17375
|
+
}
|
|
17376
|
+
function liveScores(live) {
|
|
17377
|
+
const scores = {};
|
|
17378
|
+
for (const domain2 of Object.keys(live.matrix ?? {})) {
|
|
17379
|
+
const row = live.matrix[domain2];
|
|
17380
|
+
if (!isRecord(row)) continue;
|
|
17381
|
+
for (const surface of Object.keys(row)) {
|
|
17382
|
+
const cell = row[surface];
|
|
17383
|
+
if (!cell || typeof cell.score !== "number") continue;
|
|
17384
|
+
(scores[surface] ??= {})[domain2] = cell.score;
|
|
17385
|
+
}
|
|
17386
|
+
}
|
|
17387
|
+
return scores;
|
|
17388
|
+
}
|
|
17389
|
+
function sameCells(a, b) {
|
|
17390
|
+
if (a.size !== b.size) return false;
|
|
17391
|
+
for (const [key, value] of a) {
|
|
17392
|
+
if (b.get(key) !== value) return false;
|
|
17393
|
+
}
|
|
17394
|
+
return true;
|
|
17395
|
+
}
|
|
17396
|
+
function deriveQualityTrend(events, profile, live) {
|
|
17397
|
+
const weights = profile?.domain_weights;
|
|
17398
|
+
const byAudit = /* @__PURE__ */ new Map();
|
|
17399
|
+
const audits = (Array.isArray(events) ? events : []).filter(
|
|
17400
|
+
(event) => isRecord(event) && event.type === "quality.audit.completed"
|
|
17401
|
+
);
|
|
17402
|
+
for (const event of orderEvents(audits)) {
|
|
17403
|
+
const auditId = typeof event.audit_id === "string" ? event.audit_id : typeof event.id === "string" ? event.id : "";
|
|
17404
|
+
const scores = cleanScores(event.scores);
|
|
17405
|
+
const overall = {};
|
|
17406
|
+
for (const surface of Object.keys(scores)) overall[surface] = rollUpSurface(scores[surface], weights);
|
|
17407
|
+
const snapshot = {
|
|
17408
|
+
audit_id: auditId,
|
|
17409
|
+
ts: typeof event.ts === "string" ? event.ts : "",
|
|
17410
|
+
...typeof event.commit === "string" && event.commit !== "" ? { commit: event.commit } : {},
|
|
17411
|
+
...typeof event.framework_version === "string" ? { framework_version: event.framework_version } : {},
|
|
17412
|
+
comparable: true,
|
|
17413
|
+
scores,
|
|
17414
|
+
overall,
|
|
17415
|
+
counts: cleanCounts(event.counts)
|
|
17416
|
+
};
|
|
17417
|
+
byAudit.delete(auditId);
|
|
17418
|
+
byAudit.set(auditId, snapshot);
|
|
17419
|
+
}
|
|
17420
|
+
const snapshots = [...byAudit.values()];
|
|
17421
|
+
for (let i = 1; i < snapshots.length; i++) {
|
|
17422
|
+
snapshots[i].comparable = sameFrameworkMajor(snapshots[i - 1].framework_version, snapshots[i].framework_version);
|
|
17423
|
+
}
|
|
17424
|
+
const latest = snapshots.length > 0 ? snapshots[snapshots.length - 1] : null;
|
|
17425
|
+
let previous = latest;
|
|
17426
|
+
if (live && latest !== null && sameCells(cellSet(latest.scores), cellSet(liveScores(live)))) {
|
|
17427
|
+
previous = snapshots.length > 1 ? snapshots[snapshots.length - 2] : null;
|
|
17428
|
+
}
|
|
17429
|
+
const comparable = previous !== null && live ? sameFrameworkMajor(previous.framework_version, live.framework_version) : false;
|
|
17430
|
+
const against = (prev, current) => {
|
|
17431
|
+
if (previous === null || typeof prev !== "number") return NO_DELTA;
|
|
17432
|
+
const delta = comparable && typeof current === "number" ? current - prev : null;
|
|
17433
|
+
return { previous: prev, delta, audit_id: previous.audit_id };
|
|
17434
|
+
};
|
|
17435
|
+
return {
|
|
17436
|
+
snapshots,
|
|
17437
|
+
latest,
|
|
17438
|
+
previous,
|
|
17439
|
+
deltaCell: (domain2, surface) => against(previous?.scores[surface]?.[domain2], live?.matrix?.[domain2]?.[surface]?.score),
|
|
17440
|
+
deltaOverall: (surface) => against(previous?.overall[surface], live?.overall?.[surface])
|
|
17441
|
+
};
|
|
17442
|
+
}
|
|
17443
|
+
function trendRows(trend, filter = {}) {
|
|
17444
|
+
const surfaces = [];
|
|
17445
|
+
for (const snapshot of trend.snapshots) {
|
|
17446
|
+
for (const surface of Object.keys(snapshot.scores)) {
|
|
17447
|
+
if (filter.surface !== void 0 && surface !== filter.surface) continue;
|
|
17448
|
+
if (!surfaces.includes(surface)) surfaces.push(surface);
|
|
17449
|
+
}
|
|
17450
|
+
}
|
|
17451
|
+
const valueOf = (snapshot, surface) => {
|
|
17452
|
+
if (filter.domain !== void 0) return snapshot.scores[surface]?.[filter.domain] ?? null;
|
|
17453
|
+
return snapshot.overall[surface] ?? null;
|
|
17454
|
+
};
|
|
17455
|
+
const rows = [];
|
|
17456
|
+
trend.snapshots.forEach((snapshot, index) => {
|
|
17457
|
+
const above = index > 0 ? trend.snapshots[index - 1] : null;
|
|
17458
|
+
const cells = {};
|
|
17459
|
+
for (const surface of surfaces) {
|
|
17460
|
+
const score = valueOf(snapshot, surface);
|
|
17461
|
+
const before = above === null ? null : valueOf(above, surface);
|
|
17462
|
+
const delta = snapshot.comparable && score !== null && before !== null ? score - before : null;
|
|
17463
|
+
cells[surface] = { score, delta };
|
|
17464
|
+
}
|
|
17465
|
+
rows.push({
|
|
17466
|
+
audit_id: snapshot.audit_id,
|
|
17467
|
+
ts: snapshot.ts,
|
|
17468
|
+
...snapshot.commit !== void 0 ? { commit: snapshot.commit } : {},
|
|
17469
|
+
...snapshot.framework_version !== void 0 ? { framework_version: snapshot.framework_version } : {},
|
|
17470
|
+
comparable: snapshot.comparable,
|
|
17471
|
+
cells
|
|
17472
|
+
});
|
|
17473
|
+
});
|
|
17474
|
+
return { surfaces, rows };
|
|
17475
|
+
}
|
|
17476
|
+
function formatDelta(delta) {
|
|
17477
|
+
if (typeof delta !== "number" || !Number.isFinite(delta)) return null;
|
|
17478
|
+
if (delta > 0) return `\u25B2 +${delta}`;
|
|
17479
|
+
if (delta < 0) return `\u25BC \u2212${Math.abs(delta)}`;
|
|
17480
|
+
return "=";
|
|
17481
|
+
}
|
|
17482
|
+
|
|
17483
|
+
// ../schema/src/quality-scope.ts
|
|
17484
|
+
var rowsOf2 = (value) => Array.isArray(value) ? value : [];
|
|
17485
|
+
var isString = (value) => typeof value === "string" && value !== "";
|
|
17486
|
+
var stringsOf = (value) => rowsOf2(value).filter(isString);
|
|
17487
|
+
var cellKey2 = (criterionId, surface) => `${criterionId}::${surface}`;
|
|
17488
|
+
function recordedAuditIds(events) {
|
|
17489
|
+
const ids = [];
|
|
17490
|
+
for (const event of orderEvents(rowsOf2(events))) {
|
|
17491
|
+
if (event?.type !== "quality.audit.completed") continue;
|
|
17492
|
+
const id = event.audit_id;
|
|
17493
|
+
if (isString(id) && !ids.includes(id)) ids.push(id);
|
|
17494
|
+
}
|
|
17495
|
+
return ids;
|
|
17496
|
+
}
|
|
17497
|
+
function deriveAuditScope(events, section, library, options = {}) {
|
|
17498
|
+
const ordered = orderEvents(rowsOf2(events).filter((event) => typeof event === "object" && event !== null));
|
|
17499
|
+
let sinceIndex = -1;
|
|
17500
|
+
for (let i = ordered.length - 1; i >= 0; i--) {
|
|
17501
|
+
const event = ordered[i];
|
|
17502
|
+
if (event.type !== "quality.audit.completed") continue;
|
|
17503
|
+
const id = event.audit_id;
|
|
17504
|
+
if (options.since !== void 0 && id !== options.since) continue;
|
|
17505
|
+
sinceIndex = i;
|
|
17506
|
+
break;
|
|
17507
|
+
}
|
|
17508
|
+
const empty = {
|
|
17509
|
+
since: options.since ?? null,
|
|
17510
|
+
since_ts: null,
|
|
17511
|
+
cells: [],
|
|
17512
|
+
findings: [],
|
|
17513
|
+
resolved_by: {},
|
|
17514
|
+
unknown: [],
|
|
17515
|
+
unscorable: [],
|
|
17516
|
+
widened: 0
|
|
17517
|
+
};
|
|
17518
|
+
if (sinceIndex === -1) return empty;
|
|
17519
|
+
const anchor = ordered[sinceIndex];
|
|
17520
|
+
const anchorId = anchor.audit_id;
|
|
17521
|
+
const since = isString(anchorId) ? anchorId : null;
|
|
17522
|
+
const sinceTs = isString(anchor.ts) ? anchor.ts : null;
|
|
17523
|
+
const resolutions = /* @__PURE__ */ new Map();
|
|
17524
|
+
for (const event of ordered.slice(sinceIndex + 1)) {
|
|
17525
|
+
if (event.type !== "quality.finding.resolved") continue;
|
|
17526
|
+
const findingId = event.finding_id;
|
|
17527
|
+
if (!isString(findingId)) continue;
|
|
17528
|
+
const entry = resolutions.get(findingId) ?? { node_ids: /* @__PURE__ */ new Set() };
|
|
17529
|
+
const by = event.resolved_by;
|
|
17530
|
+
if (isString(by)) entry.resolved_by = by;
|
|
17531
|
+
for (const node of stringsOf(event.node_ids)) entry.node_ids.add(node);
|
|
17532
|
+
resolutions.set(findingId, entry);
|
|
17533
|
+
}
|
|
17534
|
+
if (resolutions.size === 0) return { ...empty, since, since_ts: sinceTs };
|
|
17535
|
+
const findings = rowsOf2(section?.findings).filter(
|
|
17536
|
+
(finding) => isString(finding?.id) && isString(finding?.criterion_id) && isString(finding?.surface)
|
|
17537
|
+
);
|
|
17538
|
+
const findingById = /* @__PURE__ */ new Map();
|
|
17539
|
+
for (const finding of findings) findingById.set(finding.id, finding);
|
|
17540
|
+
const criterionById = /* @__PURE__ */ new Map();
|
|
17541
|
+
for (const criterion of rowsOf2(library?.criteria)) {
|
|
17542
|
+
if (isString(criterion?.id)) criterionById.set(criterion.id, criterion);
|
|
17543
|
+
}
|
|
17544
|
+
const assessmentByCell = /* @__PURE__ */ new Map();
|
|
17545
|
+
for (const assessment of rowsOf2(section?.assessments)) {
|
|
17546
|
+
if (!isString(assessment?.criterion_id) || !isString(assessment?.surface)) continue;
|
|
17547
|
+
assessmentByCell.set(cellKey2(assessment.criterion_id, assessment.surface), assessment);
|
|
17548
|
+
}
|
|
17549
|
+
const declared = rowsOf2(section?.profile?.surfaces).map((surface) => surface?.id).filter((id) => isString(id) && id !== CROSS_SURFACE_ID);
|
|
17550
|
+
const surfaces = declared.length > 0 ? [...new Set(declared)] : [...new Set([...assessmentByCell.values()].map((assessment) => assessment.surface))].filter((id) => id !== CROSS_SURFACE_ID).sort();
|
|
17551
|
+
const appliesTo = (criterion, surface) => criterion === void 0 || !Array.isArray(criterion.applies_to) || criterion.applies_to.includes(surface);
|
|
17552
|
+
const scorable = (criterionId, surface) => {
|
|
17553
|
+
const criterion = criterionById.get(criterionId);
|
|
17554
|
+
if (criterion !== void 0 && isString(criterion.superseded_by)) return false;
|
|
17555
|
+
if (declared.length > 0 && !surfaces.includes(surface)) return false;
|
|
17556
|
+
return appliesTo(criterion, surface);
|
|
17557
|
+
};
|
|
17558
|
+
const cells = /* @__PURE__ */ new Map();
|
|
17559
|
+
const addDirect = (criterionId, surface, findingId) => {
|
|
17560
|
+
const key = cellKey2(criterionId, surface);
|
|
17561
|
+
const existing = cells.get(key);
|
|
17562
|
+
if (existing === void 0) cells.set(key, { criterion_id: criterionId, surface, kind: "direct", because: [findingId] });
|
|
17563
|
+
else if (!existing.because.includes(findingId)) existing.because.push(findingId);
|
|
17564
|
+
};
|
|
17565
|
+
const drivers = [];
|
|
17566
|
+
const unknown2 = [];
|
|
17567
|
+
const unscorable = [];
|
|
17568
|
+
const resolvedBy = {};
|
|
17569
|
+
const resolvedNodes = /* @__PURE__ */ new Set();
|
|
17570
|
+
for (const [findingId, resolution] of resolutions) {
|
|
17571
|
+
const finding = findingById.get(findingId);
|
|
17572
|
+
if (finding === void 0) {
|
|
17573
|
+
unknown2.push(findingId);
|
|
17574
|
+
continue;
|
|
17575
|
+
}
|
|
17576
|
+
if (finding.status === "accepted-risk" || finding.status === "refuted") continue;
|
|
17577
|
+
const targets = (finding.surface === CROSS_SURFACE_ID ? surfaces : [finding.surface]).filter(
|
|
17578
|
+
(surface) => scorable(finding.criterion_id, surface)
|
|
17579
|
+
);
|
|
17580
|
+
for (const node of stringsOf(finding.node_ids)) resolvedNodes.add(node);
|
|
17581
|
+
for (const node of resolution.node_ids) resolvedNodes.add(node);
|
|
17582
|
+
if (targets.length === 0) {
|
|
17583
|
+
unscorable.push(findingId);
|
|
17584
|
+
continue;
|
|
17585
|
+
}
|
|
17586
|
+
drivers.push(findingId);
|
|
17587
|
+
if (resolution.resolved_by !== void 0) resolvedBy[findingId] = resolution.resolved_by;
|
|
17588
|
+
for (const surface of targets) addDirect(finding.criterion_id, surface, findingId);
|
|
17589
|
+
}
|
|
17590
|
+
let widened = 0;
|
|
17591
|
+
if (options.widen !== false && resolvedNodes.size > 0) {
|
|
17592
|
+
const nodesByCell = /* @__PURE__ */ new Map();
|
|
17593
|
+
const noteNodes = (criterionId, surface, nodes) => {
|
|
17594
|
+
const key = cellKey2(criterionId, surface);
|
|
17595
|
+
const bucket = nodesByCell.get(key) ?? /* @__PURE__ */ new Set();
|
|
17596
|
+
for (const node of nodes) bucket.add(node);
|
|
17597
|
+
nodesByCell.set(key, bucket);
|
|
17598
|
+
};
|
|
17599
|
+
for (const finding of findings) {
|
|
17600
|
+
const nodes = stringsOf(finding.node_ids);
|
|
17601
|
+
if (nodes.length === 0) continue;
|
|
17602
|
+
if (finding.surface === CROSS_SURFACE_ID) {
|
|
17603
|
+
for (const surface of surfaces) noteNodes(finding.criterion_id, surface, nodes);
|
|
17604
|
+
} else {
|
|
17605
|
+
noteNodes(finding.criterion_id, finding.surface, nodes);
|
|
17606
|
+
}
|
|
17607
|
+
}
|
|
17608
|
+
for (const [key, assessment] of assessmentByCell) {
|
|
17609
|
+
if (cells.has(key)) continue;
|
|
17610
|
+
if (!criterionById.has(assessment.criterion_id)) continue;
|
|
17611
|
+
if (!surfaces.includes(assessment.surface) || !scorable(assessment.criterion_id, assessment.surface)) continue;
|
|
17612
|
+
const shared = [...nodesByCell.get(key) ?? []].filter((node) => resolvedNodes.has(node)).sort();
|
|
17613
|
+
if (shared.length === 0) continue;
|
|
17614
|
+
cells.set(key, { criterion_id: assessment.criterion_id, surface: assessment.surface, kind: "widened", because: shared });
|
|
17615
|
+
widened++;
|
|
17616
|
+
}
|
|
17617
|
+
}
|
|
17618
|
+
for (const [key, cell] of cells) {
|
|
17619
|
+
const assessment = assessmentByCell.get(key);
|
|
17620
|
+
if (assessment !== void 0 && typeof assessment.level === "number" && isString(assessment.audit_id)) {
|
|
17621
|
+
cell.current = { level: assessment.level, audit_id: assessment.audit_id };
|
|
17622
|
+
}
|
|
17623
|
+
}
|
|
17624
|
+
const column = (surface) => {
|
|
17625
|
+
const at2 = surfaces.indexOf(surface);
|
|
17626
|
+
return at2 === -1 ? surfaces.length : at2;
|
|
17627
|
+
};
|
|
17628
|
+
const sorted = [...cells.values()].sort(
|
|
17629
|
+
(a, b) => column(a.surface) - column(b.surface) || (a.surface < b.surface ? -1 : a.surface > b.surface ? 1 : 0) || (a.criterion_id < b.criterion_id ? -1 : a.criterion_id > b.criterion_id ? 1 : 0)
|
|
17630
|
+
);
|
|
17631
|
+
return { since, since_ts: sinceTs, cells: sorted, findings: drivers, resolved_by: resolvedBy, unknown: unknown2, unscorable, widened };
|
|
17632
|
+
}
|
|
17633
|
+
function scopeSummary(scope) {
|
|
17634
|
+
const direct = scope.cells.length - scope.widened;
|
|
17635
|
+
const cells = `${scope.cells.length} cell${scope.cells.length === 1 ? "" : "s"} to re-score`;
|
|
17636
|
+
const split = scope.widened > 0 ? ` (${direct} direct, ${scope.widened} widened)` : "";
|
|
17637
|
+
const from = `${scope.findings.length} resolved finding${scope.findings.length === 1 ? "" : "s"}`;
|
|
17638
|
+
return `${cells}${split} from ${from}${scope.since !== null ? ` since ${scope.since}` : ""}`;
|
|
17639
|
+
}
|
|
17640
|
+
|
|
17314
17641
|
// src/commands/init.ts
|
|
17315
17642
|
var DEFAULT_BUNDLE_PATH = "docs/arkaik/bundle.json";
|
|
17316
17643
|
var DEFAULT_JOURNAL_PATH = "docs/arkaik/journal.jsonl";
|
|
@@ -18796,6 +19123,14 @@ function loadCurrentQualitySection(root, library) {
|
|
|
18796
19123
|
if (auditIds.length === 0) return void 0;
|
|
18797
19124
|
const profile = loadProfile(root);
|
|
18798
19125
|
if (!profile) return void 0;
|
|
19126
|
+
return mergeAudits(root, auditIds, library, profile);
|
|
19127
|
+
}
|
|
19128
|
+
function loadQualitySectionThrough(root, auditId, library) {
|
|
19129
|
+
requireAudit(root, auditId);
|
|
19130
|
+
const auditIds = listAuditIds(root);
|
|
19131
|
+
return mergeAudits(root, auditIds.slice(0, auditIds.indexOf(auditId) + 1), library, requireProfile(root));
|
|
19132
|
+
}
|
|
19133
|
+
function mergeAudits(root, auditIds, library, profile) {
|
|
18799
19134
|
const cells = /* @__PURE__ */ new Map();
|
|
18800
19135
|
const findings = [];
|
|
18801
19136
|
let frameworkVersion;
|
|
@@ -18815,6 +19150,57 @@ function loadCurrentQualitySection(root, library) {
|
|
|
18815
19150
|
findings
|
|
18816
19151
|
};
|
|
18817
19152
|
}
|
|
19153
|
+
function scopedAuditTarget(root, since, month, requested, recorded = []) {
|
|
19154
|
+
const existing = listAuditIds(root);
|
|
19155
|
+
const newest = existing[existing.length - 1];
|
|
19156
|
+
if (requested !== void 0) {
|
|
19157
|
+
if (requested === since) {
|
|
19158
|
+
throw new Error(
|
|
19159
|
+
`"${requested}" is the audit this scope is measured from \u2014 its recorded reading is history. Re-score into a new audit (e.g. \`--audit ${month}-scoped\`); every other cell keeps its score through the merge.`
|
|
19160
|
+
);
|
|
19161
|
+
}
|
|
19162
|
+
if (newest !== void 0 && requested < newest) {
|
|
19163
|
+
throw new Error(
|
|
19164
|
+
`"${requested}" sorts before "${newest}", and audits merge latest-wins in lexical order \u2014 its scores would be outvoted by the older ones they replace. Name one that sorts last (e.g. \`${month}-scoped\`).`
|
|
19165
|
+
);
|
|
19166
|
+
}
|
|
19167
|
+
return requested;
|
|
19168
|
+
}
|
|
19169
|
+
if (newest !== void 0 && newest !== since && !recorded.includes(newest) && loadScoresOrEmpty(root, newest).scope?.since === since) {
|
|
19170
|
+
return newest;
|
|
19171
|
+
}
|
|
19172
|
+
for (let n = 1; n < 100; n++) {
|
|
19173
|
+
const candidate = n === 1 ? `${month}-scoped` : `${month}-scoped-${String(n).padStart(2, "0")}`;
|
|
19174
|
+
if (existing.includes(candidate)) continue;
|
|
19175
|
+
if (newest !== void 0 && candidate < newest) {
|
|
19176
|
+
throw new Error(
|
|
19177
|
+
`"${candidate}" would sort before "${newest}", so its scores would lose the latest-wins merge. Name the scoped audit yourself with --audit, one that sorts after "${newest}".`
|
|
19178
|
+
);
|
|
19179
|
+
}
|
|
19180
|
+
return candidate;
|
|
19181
|
+
}
|
|
19182
|
+
throw new Error(`99 scoped audits in ${month} \u2014 name the next one with --audit.`);
|
|
19183
|
+
}
|
|
19184
|
+
function declaredScopeSince(auditId, recorded) {
|
|
19185
|
+
if (recorded.includes(auditId)) {
|
|
19186
|
+
throw new Error(
|
|
19187
|
+
`"${auditId}" is already recorded, so declaring it scoped would re-record that reading as a partial one. If you re-scored inside the audit a scope was measured from, move those scores into an audit of their own. If "${auditId}" really is a scoped re-audit recorded without its marker, add "scope": { "since": "<the audit it followed>" } to its scores.json and record it again.`
|
|
19188
|
+
);
|
|
19189
|
+
}
|
|
19190
|
+
const before = recorded.filter((id) => id < auditId).sort();
|
|
19191
|
+
const since = before[before.length - 1];
|
|
19192
|
+
if (since === void 0) {
|
|
19193
|
+
throw new Error(
|
|
19194
|
+
`no recorded audit sorts before "${auditId}" \u2014 a scoped re-audit is measured from one, and audits merge latest-wins in id order.`
|
|
19195
|
+
);
|
|
19196
|
+
}
|
|
19197
|
+
return since;
|
|
19198
|
+
}
|
|
19199
|
+
function auditOrderNote(root, auditId) {
|
|
19200
|
+
const later = listAuditIds(root).filter((id) => id > auditId);
|
|
19201
|
+
if (later.length === 0) return void 0;
|
|
19202
|
+
return `"${auditId}" sorts before ${later.map((id) => `"${id}"`).join(", ")} \u2014 audits merge latest-wins in id order, so for any cell ${later.length === 1 ? "that audit" : "those audits"} also hold${later.length === 1 ? "s" : ""}, the later score wins. Name a new audit so it sorts last.`;
|
|
19203
|
+
}
|
|
18818
19204
|
function loadAuditQualitySection(root, auditId, library) {
|
|
18819
19205
|
requireAudit(root, auditId);
|
|
18820
19206
|
const section = loadQualitySection(root, auditId, library, loadScoresOrEmpty(root, auditId));
|
|
@@ -21705,6 +22091,8 @@ Subcommands:
|
|
|
21705
22091
|
matrix [audit-id] Roll an audit up (writes matrix.json).
|
|
21706
22092
|
signals The signal pack, and what has tripped since the last audit.
|
|
21707
22093
|
regressions What got worse between two audits.
|
|
22094
|
+
trend Every recorded audit's scores, and which way each moved.
|
|
22095
|
+
scope The cells your resolved findings made stale since the last audit.
|
|
21708
22096
|
issue <criterion> Print the prefilled GitHub issue skeleton.
|
|
21709
22097
|
criterion add ... Add a project-specific criterion to the overlay.
|
|
21710
22098
|
|
|
@@ -21732,6 +22120,10 @@ Options:
|
|
|
21732
22120
|
Required: a score without a citation is an opinion.
|
|
21733
22121
|
--audit <id> The audit run (default: the newest, or the current YYYY-MM).
|
|
21734
22122
|
--commit <sha> The commit the evidence is pinned to.
|
|
22123
|
+
--scope This is a scoped re-audit: refuse a cell \`arkaik kritik scope\`
|
|
22124
|
+
does not list, and write into a scoped audit of its own
|
|
22125
|
+
(default <YYYY-MM>-scoped, never the audit it was scoped
|
|
22126
|
+
from). Leave it off to re-score an out-of-scope cell on purpose.
|
|
21735
22127
|
|
|
21736
22128
|
Writes docs/quality/audits/<id>/scores.json`;
|
|
21737
22129
|
var FINDING_USAGE = `arkaik kritik finding <open|resolve|accept> [options]
|
|
@@ -21755,7 +22147,7 @@ var FINDING_USAGE = `arkaik kritik finding <open|resolve|accept> [options]
|
|
|
21755
22147
|
Records it as a known, owned risk. The note is required \u2014 an accepted risk is a
|
|
21756
22148
|
decision and reads like one. No journal event: acceptance is a state of the
|
|
21757
22149
|
finding, not something that happened to the product.`;
|
|
21758
|
-
var MATRIX_USAGE = `arkaik kritik matrix [audit-id] [--json] [--record]
|
|
22150
|
+
var MATRIX_USAGE = `arkaik kritik matrix [audit-id] [--json] [--record] [--scope]
|
|
21759
22151
|
|
|
21760
22152
|
Roll one audit up into its comparative matrix and write matrix.json \u2014 the only
|
|
21761
22153
|
thing that may write that file.
|
|
@@ -21763,7 +22155,14 @@ thing that may write that file.
|
|
|
21763
22155
|
audit-id The audit under docs/quality/audits/ (default: the newest).
|
|
21764
22156
|
--json Print matrix.json instead of the markdown table.
|
|
21765
22157
|
--record Also append quality.audit.completed, carrying these scores
|
|
21766
|
-
and counts. Do this once per finished audit
|
|
22158
|
+
and counts. Do this once per finished audit.
|
|
22159
|
+
--scope Treat the audit as a scoped re-audit even though it was
|
|
22160
|
+
scored without \`score --scope\` (which marks it for you).
|
|
22161
|
+
|
|
22162
|
+
A scoped re-audit holds only the cells it re-scored, so matrix.json shows just
|
|
22163
|
+
those ("how did this audit go"), while --record carries the merged matrix
|
|
22164
|
+
through this audit ("where does the product stand") \u2014 the reading the trend
|
|
22165
|
+
replays. Everything else keeps its last score.`;
|
|
21767
22166
|
var SIGNALS_USAGE = `arkaik kritik signals [--surface <s>] [--criterion <c>] [--domain <CODE>] [--json]
|
|
21768
22167
|
arkaik kritik signals --trip <criterion> --surface <s> --signal <index|text> [--detail <d>]
|
|
21769
22168
|
|
|
@@ -21782,8 +22181,10 @@ var REGRESSIONS_USAGE = `arkaik kritik regressions [--from <audit>] [--to <audit
|
|
|
21782
22181
|
|
|
21783
22182
|
What got worse between two audits: a cell whose maturity dropped, a cell that
|
|
21784
22183
|
gained an open Critical or High finding, a finding that was resolved and is open
|
|
21785
|
-
again.
|
|
21786
|
-
|
|
22184
|
+
again. Each side is every audit through it, merged latest-wins \u2014 so a scoped
|
|
22185
|
+
re-audit's cells are compared with their last reading, wherever it was taken.
|
|
22186
|
+
Cells with no reading on one side are not compared \u2014 a half-finished audit is
|
|
22187
|
+
not a regression.
|
|
21787
22188
|
|
|
21788
22189
|
Exits 1 when anything regressed, which is what makes it usable as a CI step or a
|
|
21789
22190
|
scheduled routine.
|
|
@@ -21792,6 +22193,42 @@ scheduled routine.
|
|
|
21792
22193
|
--to <audit> The newer reading (default: the newest on disk).
|
|
21793
22194
|
--record Append one quality.signal.tripped per regression.
|
|
21794
22195
|
--json The full list as JSON.`;
|
|
22196
|
+
var TREND_USAGE = `arkaik kritik trend [--surface <s>] [--domain <CODE>] [--json]
|
|
22197
|
+
|
|
22198
|
+
Where the product stood at each recorded audit, oldest first \u2014 one row per
|
|
22199
|
+
quality.audit.completed in the journal, the overall score per surface, and
|
|
22200
|
+
how each moved against the row above (\u25B2 +6 / \u25BC \u22123 / =). The score, not the
|
|
22201
|
+
findings: "from where we started to where we are now".
|
|
22202
|
+
|
|
22203
|
+
--surface <s> One column only.
|
|
22204
|
+
--domain <CODE> That domain's score per surface instead of the roll-up.
|
|
22205
|
+
--json Print the snapshots and rows as JSON.
|
|
22206
|
+
|
|
22207
|
+
Reads the journal, so it needs a bundle (--bundle, default docs/arkaik/bundle.json)
|
|
22208
|
+
and audits recorded with \`arkaik kritik matrix --record\`. A framework major
|
|
22209
|
+
bump between two audits breaks the comparison there (SPEC \xA7 8): the row still
|
|
22210
|
+
prints, without an arrow.`;
|
|
22211
|
+
var SCOPE_USAGE = `arkaik kritik scope [--since <audit>] [--no-widen] [--json]
|
|
22212
|
+
|
|
22213
|
+
The cells a batch of fixes made stale. A score is an assessment, so closing
|
|
22214
|
+
findings moves nothing until the cells they lived on are re-scored \u2014 and a
|
|
22215
|
+
comprehensive audit is a lot of audit for twenty fixes. Every finding resolved
|
|
22216
|
+
since the last recorded audit names its (criterion x surface) cell; one hop
|
|
22217
|
+
over node_ids adds the neighbours a fix in a shared view plausibly moved.
|
|
22218
|
+
|
|
22219
|
+
This is a work list, not a score: re-score each cell with evidence
|
|
22220
|
+
(\`arkaik kritik score \u2026 --scope\`, which writes into an audit of its own,
|
|
22221
|
+
<YYYY-MM>-scoped, and refuses a cell this list does not hold), then
|
|
22222
|
+
\`arkaik kritik matrix --record\`. Every other cell keeps its last score.
|
|
22223
|
+
Recording closes the window: a cell left unscored drops out of the next scope.
|
|
22224
|
+
|
|
22225
|
+
--since <audit> Measure from this recorded audit (default: the newest
|
|
22226
|
+
quality.audit.completed in the journal).
|
|
22227
|
+
--no-widen Only the resolved findings' own cells, no neighbours.
|
|
22228
|
+
--json The scope as JSON (what an agent should read).
|
|
22229
|
+
|
|
22230
|
+
Reads the journal, so it needs a bundle (--bundle, default docs/arkaik/bundle.json)
|
|
22231
|
+
and an audit recorded with \`arkaik kritik matrix --record\` to measure from.`;
|
|
21795
22232
|
var ISSUE_USAGE = `arkaik kritik issue <criterion> --surface <s> [--level <n>] [--finding <id>]
|
|
21796
22233
|
|
|
21797
22234
|
Print the criterion's GitHub issue skeleton, filled as far as what we know
|
|
@@ -22014,7 +22451,7 @@ Pass --force if that is genuinely what you want.`
|
|
|
22014
22451
|
process.exit(0);
|
|
22015
22452
|
}
|
|
22016
22453
|
function runScore(args, common) {
|
|
22017
|
-
const { single, flags, positionals } = collect(args);
|
|
22454
|
+
const { single, flags, positionals } = collect(args, [], ["scope"]);
|
|
22018
22455
|
if (flags.has("help")) {
|
|
22019
22456
|
console.log(SCORE_USAGE);
|
|
22020
22457
|
process.exit(0);
|
|
@@ -22043,7 +22480,39 @@ Scoring it there would produce a cell nothing rolls up.`
|
|
|
22043
22480
|
${SCORE_USAGE}`);
|
|
22044
22481
|
}
|
|
22045
22482
|
const evidence = textOrFile(single.evidence);
|
|
22046
|
-
|
|
22483
|
+
let scopedFrom;
|
|
22484
|
+
let auditId;
|
|
22485
|
+
if (flags.has("scope")) {
|
|
22486
|
+
const { scope, recorded } = currentScope(common, library, profile);
|
|
22487
|
+
if (scope.since === null) {
|
|
22488
|
+
fail12(`kritik: --scope needs a recorded audit to measure from \u2014 \`arkaik kritik matrix --record\` writes one.`);
|
|
22489
|
+
}
|
|
22490
|
+
if (!scope.cells.some((cell) => cell.criterion_id === criterionId && cell.surface === surface)) {
|
|
22491
|
+
fail12(
|
|
22492
|
+
`kritik: ${criterionId} x ${surface} is not in the current scope (${scopeSummary(scope)}).
|
|
22493
|
+
\`arkaik kritik scope\` lists the cells; drop --scope to re-score this one on purpose.`
|
|
22494
|
+
);
|
|
22495
|
+
}
|
|
22496
|
+
try {
|
|
22497
|
+
auditId = scopedAuditTarget(common.root, scope.since, currentAuditId(), single.audit, recorded);
|
|
22498
|
+
} catch (error51) {
|
|
22499
|
+
return fail12(`kritik: ${error51.message}`);
|
|
22500
|
+
}
|
|
22501
|
+
scopedFrom = scope.since;
|
|
22502
|
+
} else {
|
|
22503
|
+
auditId = auditForWrite(common.root, single.audit);
|
|
22504
|
+
}
|
|
22505
|
+
const notes = [];
|
|
22506
|
+
if (scopedFrom === void 0) {
|
|
22507
|
+
const journal = resolveJournal(common.root, common.bundlePath);
|
|
22508
|
+
if (journal.present && recordedAuditIds(readFullJournalEvents(journal.journalPath)).includes(auditId)) {
|
|
22509
|
+
notes.push(
|
|
22510
|
+
`${auditId} is already recorded \u2014 a re-score here rewrites that reading. For a re-audit after fixes, \`arkaik kritik score \u2026 --scope\` writes into an audit of its own.`
|
|
22511
|
+
);
|
|
22512
|
+
}
|
|
22513
|
+
const order = auditOrderNote(common.root, auditId);
|
|
22514
|
+
if (order !== void 0) notes.push(order);
|
|
22515
|
+
}
|
|
22047
22516
|
const file2 = loadScoresOrEmpty(common.root, auditId);
|
|
22048
22517
|
const assessment = {
|
|
22049
22518
|
criterion_id: criterionId,
|
|
@@ -22060,14 +22529,17 @@ ${SCORE_USAGE}`);
|
|
|
22060
22529
|
audit_id: auditId,
|
|
22061
22530
|
framework_version: file2.framework_version ?? library.version,
|
|
22062
22531
|
...single.commit !== void 0 ? { commit: single.commit } : {},
|
|
22532
|
+
...scopedFrom !== void 0 ? { scope: { since: scopedFrom } } : {},
|
|
22063
22533
|
assessments
|
|
22064
22534
|
});
|
|
22065
22535
|
const anchor = criterion.level_anchors?.[`l${level}`];
|
|
22066
22536
|
console.log(
|
|
22067
22537
|
`
|
|
22068
22538
|
${replaced ? `re-scored ${criterionId} x ${surface}: ${replaced.level} -> ${level}` : `scored ${criterionId} x ${surface} at ${level}`}${anchor ? ` \u2014 ${anchor}` : ""}
|
|
22069
|
-
${assessments.length} assessment${assessments.length === 1 ? "" : "s"} in ${auditId} -> ${scoresPath(common.root, auditId)}`
|
|
22539
|
+
${assessments.length} assessment${assessments.length === 1 ? "" : "s"} in ${auditId} -> ${scoresPath(common.root, auditId)}` + (scopedFrom !== void 0 ? `
|
|
22540
|
+
scoped re-audit since ${scopedFrom} \u2014 every cell it does not re-score keeps its last score` : "")
|
|
22070
22541
|
);
|
|
22542
|
+
for (const note of notes) console.log(` note: ${note}`);
|
|
22071
22543
|
if (level < DEFAULT_TARGET_LEVEL) {
|
|
22072
22544
|
console.log(
|
|
22073
22545
|
` below the level-${DEFAULT_TARGET_LEVEL} target \u2014 open a finding, or say in the evidence why this surface should not reach it.`
|
|
@@ -22224,8 +22696,31 @@ ${FINDING_USAGE}`);
|
|
|
22224
22696
|
);
|
|
22225
22697
|
process.exit(0);
|
|
22226
22698
|
}
|
|
22699
|
+
function scopedSince(common, auditId, stamped, declared) {
|
|
22700
|
+
if (stamped !== void 0) return stamped;
|
|
22701
|
+
if (!declared) return void 0;
|
|
22702
|
+
const journal = resolveJournal(common.root, common.bundlePath);
|
|
22703
|
+
if (!journal.present) {
|
|
22704
|
+
fail12(`kritik: --scope needs the audit this one was scoped from, and there is no journal at ${journal.bundlePath}.`);
|
|
22705
|
+
}
|
|
22706
|
+
try {
|
|
22707
|
+
return declaredScopeSince(auditId, recordedAuditIds(readFullJournalEvents(journal.journalPath)));
|
|
22708
|
+
} catch (error51) {
|
|
22709
|
+
return fail12(`kritik: --scope refused \u2014 ${error51.message}`);
|
|
22710
|
+
}
|
|
22711
|
+
}
|
|
22712
|
+
function unscoredScopeCells(common, library, since, assessed) {
|
|
22713
|
+
const journal = resolveJournal(common.root, common.bundlePath);
|
|
22714
|
+
const profile = loadProfile(common.root);
|
|
22715
|
+
if (!journal.present || !profile) return [];
|
|
22716
|
+
const section = loadCurrentQualitySection(common.root, library) ?? { profile, assessments: [], findings: [] };
|
|
22717
|
+
const scope = deriveAuditScope(readFullJournalEvents(journal.journalPath), section, library);
|
|
22718
|
+
if (scope.since !== since) return [];
|
|
22719
|
+
const done = new Set(assessed.map((a) => `${a.criterion_id}::${a.surface}`));
|
|
22720
|
+
return scope.cells.filter((cell) => !done.has(`${cell.criterion_id}::${cell.surface}`));
|
|
22721
|
+
}
|
|
22227
22722
|
function runMatrix(args, common) {
|
|
22228
|
-
const { flags, positionals } = collect(args, [], ["json", "record"]);
|
|
22723
|
+
const { flags, positionals } = collect(args, [], ["json", "record", "scope"]);
|
|
22229
22724
|
if (flags.has("help")) {
|
|
22230
22725
|
console.log(MATRIX_USAGE);
|
|
22231
22726
|
process.exit(0);
|
|
@@ -22244,8 +22739,21 @@ function runMatrix(args, common) {
|
|
|
22244
22739
|
return fail12(`kritik: ${error51.message}`);
|
|
22245
22740
|
}
|
|
22246
22741
|
const { section, matrix, file: file2 } = computed;
|
|
22742
|
+
const since = scopedSince(common, auditId, loadScoresOrEmpty(common.root, auditId).scope?.since, flags.has("scope"));
|
|
22743
|
+
const scope = since !== void 0 ? { partial: true, cells: section.assessments.length, since } : void 0;
|
|
22744
|
+
const unscored = scope !== void 0 ? unscoredScopeCells(common, library, scope.since, section.assessments) : [];
|
|
22745
|
+
const reportUnscored = (log) => {
|
|
22746
|
+
if (unscored.length === 0) return;
|
|
22747
|
+
log(
|
|
22748
|
+
flags.has("record") ? `
|
|
22749
|
+
! ${unscored.length} cell${unscored.length === 1 ? "" : "s"} in the scope ${unscored.length === 1 ? "was" : "were"} left unscored \u2014 recording closes the window, so ${unscored.length === 1 ? "it drops" : "they drop"} out of the next \`scope\`:` : `
|
|
22750
|
+
${unscored.length} cell${unscored.length === 1 ? "" : "s"} in the scope not re-scored yet (a widened cell that did not move is re-scored at its current level, saying so):`
|
|
22751
|
+
);
|
|
22752
|
+
for (const cell of unscored) log(` ${cell.surface} \xB7 ${cell.criterion_id} (${cell.kind})`);
|
|
22753
|
+
};
|
|
22247
22754
|
if (flags.has("json")) {
|
|
22248
22755
|
console.log(JSON.stringify(file2, null, 2));
|
|
22756
|
+
reportUnscored((line2) => console.error(line2));
|
|
22249
22757
|
} else {
|
|
22250
22758
|
const domainNames = new Map((library.domains ?? []).map((d) => [d.code, d.name]));
|
|
22251
22759
|
console.log(`
|
|
@@ -22269,11 +22777,33 @@ P0 \u2014 fix first:`);
|
|
|
22269
22777
|
}
|
|
22270
22778
|
console.log(`
|
|
22271
22779
|
wrote ${matrixPath(common.root, auditId)}`);
|
|
22780
|
+
if (scope !== void 0) {
|
|
22781
|
+
reportUnscored((line2) => console.log(line2));
|
|
22782
|
+
console.log(
|
|
22783
|
+
`
|
|
22784
|
+
scoped re-audit: ${scope.cells} cell${scope.cells === 1 ? "" : "s"} re-scored since ${scope.since}. The table is this audit alone; ${flags.has("record") ? "the recorded event carries" : "--record records"} the merged matrix through it \u2014 every other cell at its last score.`
|
|
22785
|
+
);
|
|
22786
|
+
}
|
|
22272
22787
|
}
|
|
22273
22788
|
if (flags.has("record")) {
|
|
22789
|
+
let recorded = matrix;
|
|
22790
|
+
if (scope !== void 0) {
|
|
22791
|
+
try {
|
|
22792
|
+
recorded = deriveQualityMatrix({ quality: loadQualitySectionThrough(common.root, auditId, library) }, library);
|
|
22793
|
+
} catch (error51) {
|
|
22794
|
+
return fail12(`kritik: ${error51.message}`);
|
|
22795
|
+
}
|
|
22796
|
+
}
|
|
22274
22797
|
reportJournal(
|
|
22275
22798
|
common.root,
|
|
22276
|
-
[
|
|
22799
|
+
[
|
|
22800
|
+
auditCompletedInput(recorded, {
|
|
22801
|
+
audit_id: auditId,
|
|
22802
|
+
framework_version: file2.framework_version,
|
|
22803
|
+
...file2.commit !== void 0 ? { commit: file2.commit } : {},
|
|
22804
|
+
...scope !== void 0 ? { scope } : {}
|
|
22805
|
+
})
|
|
22806
|
+
],
|
|
22277
22807
|
common
|
|
22278
22808
|
);
|
|
22279
22809
|
}
|
|
@@ -22399,8 +22929,8 @@ function runRegressions(args, common) {
|
|
|
22399
22929
|
let regressions;
|
|
22400
22930
|
try {
|
|
22401
22931
|
regressions = detectRegressions(
|
|
22402
|
-
|
|
22403
|
-
|
|
22932
|
+
loadQualitySectionThrough(common.root, from, library),
|
|
22933
|
+
loadQualitySectionThrough(common.root, to, library),
|
|
22404
22934
|
library
|
|
22405
22935
|
);
|
|
22406
22936
|
} catch (error51) {
|
|
@@ -22439,6 +22969,159 @@ function runRegressions(args, common) {
|
|
|
22439
22969
|
}
|
|
22440
22970
|
process.exit(regressions.length > 0 ? 1 : 0);
|
|
22441
22971
|
}
|
|
22972
|
+
function runTrend(args, common) {
|
|
22973
|
+
const { single, flags } = collect(args, [], ["json"]);
|
|
22974
|
+
if (flags.has("help")) {
|
|
22975
|
+
console.log(TREND_USAGE);
|
|
22976
|
+
process.exit(0);
|
|
22977
|
+
}
|
|
22978
|
+
const journal = resolveJournal(common.root, common.bundlePath);
|
|
22979
|
+
if (!journal.present) {
|
|
22980
|
+
fail12(
|
|
22981
|
+
`kritik: no bundle at ${journal.bundlePath} \u2014 the trend is read from the journal's quality.audit.completed events, and there is no journal without a bundle.`
|
|
22982
|
+
);
|
|
22983
|
+
}
|
|
22984
|
+
const events = readFullJournalEvents(journal.journalPath);
|
|
22985
|
+
const profile = loadProfile(common.root);
|
|
22986
|
+
const trend = deriveQualityTrend(events, profile ?? void 0);
|
|
22987
|
+
const filter = {
|
|
22988
|
+
...single.surface !== void 0 ? { surface: single.surface } : {},
|
|
22989
|
+
...single.domain !== void 0 ? { domain: single.domain } : {}
|
|
22990
|
+
};
|
|
22991
|
+
const { surfaces, rows } = trendRows(trend, filter);
|
|
22992
|
+
if (flags.has("json")) {
|
|
22993
|
+
console.log(JSON.stringify({ total: trend.snapshots.length, surfaces, rows, snapshots: trend.snapshots }, null, 2));
|
|
22994
|
+
process.exit(0);
|
|
22995
|
+
}
|
|
22996
|
+
if (rows.length === 0) {
|
|
22997
|
+
console.log(`
|
|
22998
|
+
no recorded audits yet \u2014 \`arkaik kritik matrix --record\` writes one.
|
|
22999
|
+
`);
|
|
23000
|
+
process.exit(0);
|
|
23001
|
+
}
|
|
23002
|
+
if (surfaces.length === 0) {
|
|
23003
|
+
console.log(
|
|
23004
|
+
`
|
|
23005
|
+
${rows.length} recorded audit${rows.length === 1 ? "" : "s"}, none scoring ` + (single.surface !== void 0 ? `"${single.surface}"` : "any surface") + `.
|
|
23006
|
+
`
|
|
23007
|
+
);
|
|
23008
|
+
process.exit(0);
|
|
23009
|
+
}
|
|
23010
|
+
const cellText = (row, surface) => {
|
|
23011
|
+
const cell = row.cells[surface];
|
|
23012
|
+
if (cell.score === null) return "\u2014";
|
|
23013
|
+
const arrow = formatDelta(cell.delta);
|
|
23014
|
+
return arrow === null ? String(cell.score) : `${cell.score} ${arrow}`;
|
|
23015
|
+
};
|
|
23016
|
+
const header = ["audit", "recorded", ...surfaces];
|
|
23017
|
+
const table = rows.map((row) => [row.audit_id, row.ts.slice(0, 10), ...surfaces.map((surface) => cellText(row, surface))]);
|
|
23018
|
+
const widths = header.map((title2, column) => Math.max(title2.length, ...table.map((line3) => line3[column].length)));
|
|
23019
|
+
const line2 = (cells) => ` ${cells.map((cell, column) => cell.padEnd(widths[column])).join(" ")}`;
|
|
23020
|
+
console.log("");
|
|
23021
|
+
console.log(line2(header));
|
|
23022
|
+
for (const [index, cells] of table.entries()) {
|
|
23023
|
+
console.log(line2(cells));
|
|
23024
|
+
const row = rows[index];
|
|
23025
|
+
if (!row.comparable) {
|
|
23026
|
+
console.log(` ${"".padEnd(widths[0])} framework ${row.framework_version ?? "?"} \u2014 not comparable to the audit above`);
|
|
23027
|
+
}
|
|
23028
|
+
}
|
|
23029
|
+
console.log(
|
|
23030
|
+
`
|
|
23031
|
+
${rows.length} recorded audit${rows.length === 1 ? "" : "s"} \xB7 ` + (single.domain !== void 0 ? `${single.domain} score per surface` : "overall score per surface") + ` \xB7 arrows against the row above
|
|
23032
|
+
`
|
|
23033
|
+
);
|
|
23034
|
+
process.exit(0);
|
|
23035
|
+
}
|
|
23036
|
+
function scopeReason(cell, resolvedBy) {
|
|
23037
|
+
if (cell.kind === "widened") return `widened via ${cell.because.join(", ")}`;
|
|
23038
|
+
const findings = cell.because.map((id) => resolvedBy[id] !== void 0 ? `${id} (resolved by ${resolvedBy[id]})` : id);
|
|
23039
|
+
return `because ${findings.join(", ")}`;
|
|
23040
|
+
}
|
|
23041
|
+
function currentScope(common, library, profile, options = {}) {
|
|
23042
|
+
const journal = resolveJournal(common.root, common.bundlePath);
|
|
23043
|
+
if (!journal.present) {
|
|
23044
|
+
fail12(
|
|
23045
|
+
`kritik: no bundle at ${journal.bundlePath} \u2014 the scope is measured from the journal's quality.audit.completed and quality.finding.resolved events, and there is no journal without a bundle.`
|
|
23046
|
+
);
|
|
23047
|
+
}
|
|
23048
|
+
const events = readFullJournalEvents(journal.journalPath);
|
|
23049
|
+
const recorded = recordedAuditIds(events);
|
|
23050
|
+
if (options.since !== void 0) {
|
|
23051
|
+
if (!recorded.includes(options.since)) {
|
|
23052
|
+
fail12(
|
|
23053
|
+
`kritik: no recorded audit "${options.since}" in ${journal.journalPath} (recorded: ${recorded.join(", ") || "none \u2014 `arkaik kritik matrix --record` writes one"}).
|
|
23054
|
+
A scope is measured from a recorded reading; an audit directory that was never recorded is not one.`
|
|
23055
|
+
);
|
|
23056
|
+
}
|
|
23057
|
+
}
|
|
23058
|
+
let section;
|
|
23059
|
+
try {
|
|
23060
|
+
section = loadCurrentQualitySection(common.root, library) ?? { profile, assessments: [], findings: [] };
|
|
23061
|
+
} catch (error51) {
|
|
23062
|
+
return fail12(`kritik: ${error51.message}`);
|
|
23063
|
+
}
|
|
23064
|
+
return { scope: deriveAuditScope(events, section, library, options), journalPath: journal.journalPath, recorded };
|
|
23065
|
+
}
|
|
23066
|
+
function runScope(args, common) {
|
|
23067
|
+
const { single, flags } = collect(args, [], ["json", "no-widen"]);
|
|
23068
|
+
if (flags.has("help")) {
|
|
23069
|
+
console.log(SCOPE_USAGE);
|
|
23070
|
+
process.exit(0);
|
|
23071
|
+
}
|
|
23072
|
+
const library = loadLibraryOrFail(common.root);
|
|
23073
|
+
const profile = profileOrFail(common.root);
|
|
23074
|
+
const { scope } = currentScope(common, library, profile, {
|
|
23075
|
+
...single.since !== void 0 ? { since: single.since } : {},
|
|
23076
|
+
widen: !flags.has("no-widen")
|
|
23077
|
+
});
|
|
23078
|
+
if (flags.has("json")) {
|
|
23079
|
+
console.log(JSON.stringify({ ...scope, summary: scopeSummary(scope) }, null, 2));
|
|
23080
|
+
process.exit(0);
|
|
23081
|
+
}
|
|
23082
|
+
if (scope.since === null) {
|
|
23083
|
+
console.log(
|
|
23084
|
+
`
|
|
23085
|
+
no recorded audit yet \u2014 a scope is measured from one. \`arkaik kritik matrix --record\` writes it.
|
|
23086
|
+
`
|
|
23087
|
+
);
|
|
23088
|
+
process.exit(0);
|
|
23089
|
+
}
|
|
23090
|
+
console.log("");
|
|
23091
|
+
let surface = "";
|
|
23092
|
+
for (const cell of scope.cells) {
|
|
23093
|
+
if (cell.surface !== surface) {
|
|
23094
|
+
if (surface !== "") console.log("");
|
|
23095
|
+
surface = cell.surface;
|
|
23096
|
+
}
|
|
23097
|
+
const current = cell.current !== void 0 ? `at ${cell.current.level} (${cell.current.audit_id})` : "unscored";
|
|
23098
|
+
console.log(` ${cell.surface} \xB7 ${cell.criterion_id} \xB7 ${current} \xB7 ${scopeReason(cell, scope.resolved_by)}`);
|
|
23099
|
+
}
|
|
23100
|
+
if (scope.cells.length > 0) console.log("");
|
|
23101
|
+
console.log(` ${scopeSummary(scope)}`);
|
|
23102
|
+
if (scope.unknown.length > 0) {
|
|
23103
|
+
console.log(
|
|
23104
|
+
`
|
|
23105
|
+
! ${scope.unknown.length} resolved id${scope.unknown.length === 1 ? " names" : "s name"} no finding in any audit \u2014 something closed an id that does not exist:`
|
|
23106
|
+
);
|
|
23107
|
+
for (const id of scope.unknown) console.log(` ${id}`);
|
|
23108
|
+
}
|
|
23109
|
+
if (scope.unscorable.length > 0) {
|
|
23110
|
+
console.log(
|
|
23111
|
+
`
|
|
23112
|
+
! ${scope.unscorable.length} resolved finding${scope.unscorable.length === 1 ? " sits" : "s sit"} on a cell nothing can re-score (a retired criterion, or a surface no longer in the profile) \u2014 the fix still counts, but there is no score to move:`
|
|
23113
|
+
);
|
|
23114
|
+
for (const id of scope.unscorable) console.log(` ${id}`);
|
|
23115
|
+
}
|
|
23116
|
+
if (scope.cells.length > 0) {
|
|
23117
|
+
console.log(
|
|
23118
|
+
`
|
|
23119
|
+
re-score each with evidence \u2014 \`arkaik kritik score <criterion> <surface> <level> --evidence \u2026 --scope\` \u2014 then \`arkaik kritik matrix --record\`. --scope writes into an audit of its own, never ${scope.since}, whose recorded reading is history. Every other cell keeps its last score.`
|
|
23120
|
+
);
|
|
23121
|
+
}
|
|
23122
|
+
console.log("");
|
|
23123
|
+
process.exit(0);
|
|
23124
|
+
}
|
|
22442
23125
|
function runIssue(args, common) {
|
|
22443
23126
|
const { single, flags, positionals } = collect(args);
|
|
22444
23127
|
if (flags.has("help")) {
|
|
@@ -22580,6 +23263,10 @@ function runKritik(args) {
|
|
|
22580
23263
|
return runSignals(subArgs, common);
|
|
22581
23264
|
case "regressions":
|
|
22582
23265
|
return runRegressions(subArgs, common);
|
|
23266
|
+
case "trend":
|
|
23267
|
+
return runTrend(subArgs, common);
|
|
23268
|
+
case "scope":
|
|
23269
|
+
return runScope(subArgs, common);
|
|
22583
23270
|
case "issue":
|
|
22584
23271
|
return runIssue(subArgs, common);
|
|
22585
23272
|
case "criterion":
|
|
@@ -22619,7 +23306,7 @@ Options:
|
|
|
22619
23306
|
-v, --version Print the version.
|
|
22620
23307
|
|
|
22621
23308
|
Run "arkaik <command> --help" for command-specific help.`;
|
|
22622
|
-
var VERSION = "0.
|
|
23309
|
+
var VERSION = "0.6.0";
|
|
22623
23310
|
function main(argv) {
|
|
22624
23311
|
const [command, ...rest] = argv;
|
|
22625
23312
|
if (command === void 0 || command === "--help" || command === "-h" || command === "help") {
|
package/dist/io.js
CHANGED
|
@@ -15182,6 +15182,13 @@ var QualityAuditCompletedEventSchema = external_exports.object({
|
|
|
15182
15182
|
medium: external_exports.number().optional(),
|
|
15183
15183
|
low: external_exports.number().optional(),
|
|
15184
15184
|
info: external_exports.number().optional()
|
|
15185
|
+
}).catchall(external_exports.unknown()).optional(),
|
|
15186
|
+
// A scoped re-audit (issue #443). Optional and catchall like `counts`:
|
|
15187
|
+
// older readers ignore it, and its `scores` stay the same shape either way.
|
|
15188
|
+
scope: external_exports.object({
|
|
15189
|
+
partial: external_exports.boolean().optional(),
|
|
15190
|
+
cells: external_exports.number().optional(),
|
|
15191
|
+
since: external_exports.string().optional()
|
|
15185
15192
|
}).catchall(external_exports.unknown()).optional()
|
|
15186
15193
|
}).catchall(external_exports.unknown());
|
|
15187
15194
|
var QualityFindingOpenedEventSchema = external_exports.object({
|
|
@@ -15216,6 +15223,7 @@ var QualitySignalTrippedEventSchema = external_exports.object({
|
|
|
15216
15223
|
criterion_id: external_exports.string(),
|
|
15217
15224
|
surface: external_exports.string(),
|
|
15218
15225
|
signal: external_exports.string(),
|
|
15226
|
+
commit: external_exports.string().optional(),
|
|
15219
15227
|
detail: external_exports.string().optional()
|
|
15220
15228
|
}).catchall(external_exports.unknown());
|
|
15221
15229
|
var JOURNAL_EVENT_SCHEMAS = {
|