grooph 0.4.0 → 0.5.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.
Files changed (58) hide show
  1. package/README.md +33 -31
  2. package/THIRD-PARTY-NOTICES.md +5 -1
  3. package/dist/app/assets/App-CT9KxzfQ.css +1 -0
  4. package/dist/app/assets/App-D1pDFbEY.js +5 -0
  5. package/dist/app/assets/EmbedApp-CTausQWY.js +1 -0
  6. package/dist/app/assets/ExportPanel-CbRH4C69.js +8 -0
  7. package/dist/app/assets/Import-DF0XLxRI.js +1 -0
  8. package/dist/app/assets/SketchView-BjeUHG4X.js +143 -0
  9. package/dist/app/assets/brakes-B9b3hDX8.js +1 -0
  10. package/dist/app/assets/{builtins-Cbs5iQtH.js → builtins-DzyPaYdd.js} +1 -1
  11. package/dist/app/assets/{compile-BAvi-rd0.js → compile-DL2budwP.js} +8 -8
  12. package/dist/app/assets/{front-BRl7rl-u.js → front-OxfL-OaD.js} +1 -1
  13. package/dist/app/assets/full-C0asYORc.js +1 -0
  14. package/dist/app/assets/graph-more-Dn_hNa20.js +2 -0
  15. package/dist/app/assets/graph-stage-CwNePnN4.js +4 -0
  16. package/dist/app/assets/graph-views-CmkQ41zC.js +2 -0
  17. package/dist/app/assets/{index-BoSi6XYh.js → index-B5ZkSF4L.js} +2 -2
  18. package/dist/app/assets/mermaid-read-cyqJ32v-.js +17 -0
  19. package/dist/app/assets/{plan-templates-BQu8G2sX.js → plan-templates-u2fF3GnS.js} +1 -1
  20. package/dist/app/assets/runs-BA5HKtsx.js +1 -0
  21. package/dist/app/assets/screens-CMMuexid.js +16 -0
  22. package/dist/app/assets/share-DV3wsAsJ.js +8 -0
  23. package/dist/app/assets/site-looks.v1.css +223 -0
  24. package/dist/app/assets/space-Cuy4YqyZ.js +1 -0
  25. package/dist/app/assets/styles-Dlp-yYlE.css +1 -0
  26. package/dist/app/assets/templates-DbAhWvP6.js +2 -0
  27. package/dist/app/assets/{themes-DtOBrLk0.js → themes-C34TrvOJ.js} +1 -1
  28. package/dist/app/assets/{units-DRaa5U2m.js → units-DlniUjfH.js} +1 -1
  29. package/dist/app/assets/{views-DCEDX6Qx.js → views-CFqRShXD.js} +2 -1
  30. package/dist/app/grooph-app.json +1 -1
  31. package/dist/app/index.html +14 -11
  32. package/dist/app/llms.txt +6 -7
  33. package/dist/app/manifest.webmanifest +1 -1
  34. package/dist/app/og.png +0 -0
  35. package/dist/app/routes.json +42 -33
  36. package/dist/app/sw.js +7 -2
  37. package/dist/browser/grooph.d.ts +44 -0
  38. package/dist/browser/grooph.global.js +7 -0
  39. package/dist/browser/grooph.js +7 -0
  40. package/dist/bundle/grooph.js +7082 -2606
  41. package/hooks/grooph-event.mjs +163 -14
  42. package/package.json +14 -6
  43. package/dist/app/assets/App-CFO6bPna.js +0 -5
  44. package/dist/app/assets/App-Cv1auMeh.css +0 -1
  45. package/dist/app/assets/EmbedApp-B5LWao3x.js +0 -1
  46. package/dist/app/assets/ExportPanel-VWus7GM3.js +0 -8
  47. package/dist/app/assets/Import-YEKofx4_.js +0 -1
  48. package/dist/app/assets/brakes-9E9PsV_Z.js +0 -1
  49. package/dist/app/assets/graph-more-BKW9C4-h.js +0 -2
  50. package/dist/app/assets/graph-stage-CWh3OWga.js +0 -4
  51. package/dist/app/assets/graph-views-tFUJK-be.js +0 -2
  52. package/dist/app/assets/runs-DcjRi7S6.js +0 -1
  53. package/dist/app/assets/screens-YUd2HaLm.js +0 -16
  54. package/dist/app/assets/share-BzIzB4EY.js +0 -8
  55. package/dist/app/assets/space-DWgrlnfB.js +0 -1
  56. package/dist/app/assets/styles-BA1aVO9R.css +0 -1
  57. package/dist/app/assets/templates-DvzLa5sE.js +0 -2
  58. package/dist/app/demo/run.txt +0 -1
@@ -0,0 +1,8 @@
1
+ var e=(e,t,n=[])=>({code:e,severity:`error`,message:t,at:n}),t=(e,t,n=[])=>({code:e,severity:`warning`,message:t,at:n}),n=e=>e.some(e=>e.severity===`error`),r=e=>`${e.severity===`error`?`error`:`warning`} ${e.code} ${e.message}${e.at.length>0?` [at: ${e.at.join(`, `)}]`:``}`,i={nodes:500,edges:2e3,loops:200,groups:200,loopMembers:2e3,groupMembers:2e3,loopStops:2e3},a={sessions:200,handoffs:1e3,lanes:100,people:100},o=e=>e.toLocaleString(`en`);function s(e,t){if(typeof e!=`object`||!e||Array.isArray(e))return;let n=e,r=(e,t)=>Array.isArray(n[e])?n[e].reduce((e,n)=>e+(typeof n==`object`&&n?c(n[t]):0),0):0,s=t===`graph`?[[`/nodes`,`nodes`,c(n.nodes),i.nodes],[`/edges`,`edges`,c(n.edges),i.edges],[`/loops`,`loops`,c(n.loops),i.loops],[`/groups`,`groups`,c(n.groups),i.groups],[`/loops`,`members of loops in all`,r(`loops`,`members`),i.loopMembers],[`/groups`,`members of groups in all`,r(`groups`,`members`),i.groupMembers],[`/loops`,`stops of loops in all`,r(`loops`,`stops`),i.loopStops]]:[[`/sessions`,`sessions`,c(n.sessions),a.sessions],[`/handoffs`,`handoffs`,c(n.handoffs),a.handoffs],[`/lanes`,`lanes`,c(n.lanes),a.lanes],[`/people`,`people`,c(n.people),a.people]];for(let[e,n,r,i]of s)if(!(r<=i))return{path:e,message:`${o(r)} ${n}, more than the ${o(i)} grooph draws in ${t===`graph`?`a graph`:`a map`}`}}var c=e=>Array.isArray(e)?e.length:0,l=e=>typeof e==`object`&&!!e&&!Array.isArray(e),u=e=>e===null?`null`:Array.isArray(e)?`array`:typeof e;function d(e,t){let n={describe:e,check:t.check,json:t.json,canon:t.canon??(e=>e),unknownKeys:t.unknownKeys??(()=>{}),accepts(e){let t=[];return n.check(e,``,t),t.length===0}};return n}function f(e){return{...e,__optional:!0}}function p(e={}){let t=e.patternName??`string`;return d(t,{check(n,r,i){if(typeof n!=`string`){i.push({path:r,message:`expected ${t}, got ${u(n)}`});return}if(e.minLength!==void 0&&n.length<e.minLength){i.push({path:r,message:`expected ${t} of at least ${e.minLength} character(s)`});return}e.pattern&&!e.pattern.test(n)&&i.push({path:r,message:`expected ${t} matching ${e.pattern.source}, got ${JSON.stringify(n)}`})},json(){let t={type:`string`};return e.pattern&&(t.pattern=e.pattern.source),e.minLength!==void 0&&(t.minLength=e.minLength),t}})}var m=/^[a-z][a-z0-9-]*$/;function h(){return p({pattern:m,patternName:`kebab-case id`})}function g(e={}){let t=e.integer?`integer`:`number`;return d(t,{check(n,r,i){if(typeof n!=`number`||Number.isNaN(n)||!Number.isFinite(n)){i.push({path:r,message:`expected ${t}, got ${u(n)}`});return}if(e.integer&&!Number.isInteger(n)){i.push({path:r,message:`expected ${t}, got ${n}`});return}e.minimum!==void 0&&n<e.minimum&&i.push({path:r,message:`expected ${t} >= ${e.minimum}, got ${n}`})},json(){let t={type:e.integer?`integer`:`number`};return e.minimum!==void 0&&(t.minimum=e.minimum),t}})}function _(){return d(`boolean`,{check(e,t,n){typeof e!=`boolean`&&n.push({path:t,message:`expected boolean, got ${u(e)}`})},json:()=>({type:`boolean`})})}function v(){return d(`null`,{check(e,t,n){e!==null&&n.push({path:t,message:`expected null, got ${u(e)}`})},json:()=>({type:`null`})})}function y(e,t){return{...e,json:()=>({$ref:t})}}function b(e){return d(JSON.stringify(e),{check(t,n,r){t!==e&&r.push({path:n,message:`expected ${JSON.stringify(e)}, got ${JSON.stringify(t)??u(t)}`})},json:()=>({const:e})})}function x(...e){let t=`one of ${e.join(` | `)}`;return d(t,{check(n,r,i){(typeof n!=`string`||!e.includes(n))&&i.push({path:r,message:`expected ${t}, got ${JSON.stringify(n)??u(n)}`})},json:()=>({enum:[...e]})})}var S=/^[^\u0000-\u001f\u007f\u0085\u2028\u2029]+$/,C=/^[A-Za-z0-9][A-Za-z0-9._:/[\]-]*$/;function w(e,t,n={}){return d(t,{check(e,r,i){if(typeof e!=`string`||e.length===0){i.push({path:r,message:`expected ${t} (non-empty string), got ${u(e)}`});return}n.pattern&&!n.pattern.test(e)&&i.push({path:r,message:`expected ${t} matching ${n.pattern.source}, got ${JSON.stringify(e)}`})},json:()=>({type:`string`,minLength:1,...n.pattern?{pattern:n.pattern.source}:{},examples:[...e]})})}function T(e,t={}){let n=`array of ${e.describe}`;return d(n,{check(r,i,a){if(!Array.isArray(r)){a.push({path:i,message:`expected ${n}, got ${u(r)}`});return}t.minItems!==void 0&&r.length<t.minItems&&a.push({path:i,message:`expected at least ${t.minItems} item(s), got ${r.length}`}),t.maxItems!==void 0&&r.length>t.maxItems&&a.push({path:i,message:`expected at most ${t.maxItems} item(s), got ${r.length}`}),r.forEach((t,n)=>e.check(t,`${i}/${n}`,a))},json(n){let r={type:`array`,items:e.json(n)};return t.minItems!==void 0&&(r.minItems=t.minItems),t.maxItems!==void 0&&(r.maxItems=t.maxItems),r},canon(t){return Array.isArray(t)?t.map(t=>e.canon(t)):t},unknownKeys(t,n,r){Array.isArray(t)&&t.forEach((t,i)=>e.unknownKeys(t,`${n}/${i}`,r))}})}function E(e=`any JSON value`){let t=d(e,{check:()=>{},json:()=>({}),canon(e){if(Array.isArray(e))return e.map(e=>t.canon(e));if(l(e)){let n={};for(let r of Object.keys(e).sort())O(n,r,t.canon(e[r]));return n}return e}});return t}function D(e,t={}){let n=`object of ${e.describe}`;return d(n,{check(r,i,a){if(!l(r)){a.push({path:i,message:`expected ${n}, got ${u(r)}`});return}for(let[n,o]of Object.entries(r))t.keyPattern&&!t.keyPattern.test(n)&&a.push({path:`${i}/${ee(n)}`,message:`expected ${t.keyName??`key`} matching ${t.keyPattern.source}, got ${JSON.stringify(n)}`}),e.check(o,`${i}/${ee(n)}`,a)},json(n){let r={type:`object`,additionalProperties:e.json(n)};return t.keyPattern&&(r.propertyNames={pattern:t.keyPattern.source}),r},canon(t){if(!l(t))return t;let n={};for(let r of Object.keys(t).sort())O(n,r,e.canon(t[r]));return n},unknownKeys(t,n,r){if(l(t))for(let[i,a]of Object.entries(t))e.unknownKeys(a,`${n}/${ee(i)}`,r)}})}function O(e,t,n){t===`__proto__`?Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0}):e[t]=n}function ee(e){return e.replace(/~/g,`~0`).replace(/\//g,`~1`)}var k=E();function A(e,t={}){let n=Object.keys(e),r=n.filter(t=>!(`__optional`in e[t])),i=t.describe??t.name??`object`;return d(i,{check(t,a,o){if(!l(t)){o.push({path:a,message:`expected ${i}, got ${u(t)}`});return}for(let e of r)(!(e in t)||t[e]===void 0)&&o.push({path:`${a}/${e}`,message:`missing required property "${e}"`});for(let r of n){let n=t[r];n!==void 0&&e[r].check(n,`${a}/${r}`,o)}},json(i){let a={};for(let t of n)a[t]=e[t].json(i);let o={type:`object`,properties:a,required:r};return r.length===0&&delete o.required,t.name?(i.defs[t.name]=o,{$ref:`#/$defs/${t.name}`}):o},canon(t){if(!l(t))return t;let r={};for(let i of n)t[i]!==void 0&&(r[i]=e[i].canon(t[i]));for(let e of Object.keys(t).sort())n.includes(e)||t[e]===void 0||O(r,e,k.canon(t[e]));return r},unknownKeys(t,r,i){if(l(t))for(let a of Object.keys(t)){if(t[a]===void 0)continue;let o=`${r}/${ee(a)}`;n.includes(a)?e[a].unknownKeys(t[a],o,i):i.push({path:o,key:a,known:n})}}})}function j(e,t,n={}){let r=Object.keys(t),i=`${n.label??`object`} with ${e} one of ${r.join(` | `)}`;return d(i,{check(n,a,o){if(!l(n)){o.push({path:a,message:`expected ${i}, got ${u(n)}`});return}let s=n[e];if(typeof s!=`string`||!Object.hasOwn(t,s)){o.push({path:`${a}/${e}`,message:`expected ${e} to be one of ${r.join(` | `)}, got ${JSON.stringify(s)??`nothing`}`});return}t[s].check(n,a,o)},json(e){let i={oneOf:r.map(n=>t[n].json(e))};return n.name?(e.defs[n.name]=i,{$ref:`#/$defs/${n.name}`}):i},canon(n){if(!l(n))return n;let r=n[e];return typeof r==`string`&&Object.hasOwn(t,r)?t[r].canon(n):k.canon(n)},unknownKeys(n,r,i){if(!l(n))return;let a=n[e];typeof a==`string`&&Object.hasOwn(t,a)&&t[a].unknownKeys(n,r,i)}})}function M(e,t,n,r={}){let i=r=>e(r)?t:n;return d(r.describe??`${t.describe} | ${n.describe}`,{check:(e,t,n)=>i(e).check(e,t,n),json:e=>({anyOf:[t.json(e),n.json(e)]}),canon:e=>i(e).canon(e),unknownKeys:(e,t,n)=>i(e).unknownKeys(e,t,n)})}function N(e,t={}){let n=t.describe??e.map(e=>e.describe).join(` | `);return d(n,{check(t,r,i){e.some(e=>e.accepts(t))||i.push({path:r,message:`expected ${n}, got ${JSON.stringify(t)??u(t)}`})},json(t){return{anyOf:e.map(e=>e.json(t))}},canon(t){let n=e.find(e=>e.accepts(t));return n?n.canon(t):k.canon(t)},unknownKeys(t,n,r){e.find(e=>e.accepts(t))?.unknownKeys(t,n,r)}})}var P=(e,t)=>p({pattern:e,patternName:t}),F=()=>h(),te=w([`claude-code`,`codex`],`harness id`),ne=w([`read-files`,`edit-files`,`write-outputs`,`run-commands`,`run-tests`,`web`,`spawn-agents`],`capability`,{pattern:S}),re=p({pattern:C,patternName:`model name`}),ie=p({pattern:C,patternName:`skill name`}),I=x(`frontier`,`strong`,`fast`),ae=x(`low`,`medium`,`high`,`max`),oe=x(`lead`,`planner`,`builder`,`critic`,`tester`,`researcher`,`red-team`,`judge`,`synthesizer`),se=e=>({id:h(),kind:b(e),name:p(),description:f(p()),coupled:f(_())}),ce=j(`kind`,{agent:A({...se(`agent`),by:f(x(`agent`,`person`)),role:N([oe,A({custom:p()})],{describe:`role name or { custom }`}),model:f(A({tier:I,pin:f(D(re,{keyName:`harness id`}))})),effort:f(ae),brief:p(),inputs:f(T(p())),outputs:T(p(),{minItems:1}),allow:f(T(ne)),deny:f(T(ne)),owns:f(T(p())),irreversible:f(T(p())),skills:f(T(ie))},{name:`AgentNode`}),"human-gate":A({...se(`human-gate`),prompt:p(),options:f(T(p()))},{name:`HumanGateNode`}),check:A({...se(`check`),check:A({kind:x(`command`,`tests`,`diff`,`metric`,`evidence`),run:f(p()),pass:p(),threshold:f(g())})},{name:`CheckNode`}),merge:A({...se(`merge`),merges:T(p()),strategy:f(p())},{name:`MergeNode`}),stop:A({...se(`stop`),outcome:f(x(`success`,`halt`))},{name:`StopNode`})},{name:`Node`,label:`node`}),le=A({id:h(),from:F(),to:F(),when:f(N([x(`always`,`pass`,`fail`),A({verdict:p()})],{describe:`always | pass | fail | { verdict }`})),isolation:f(x(`fresh`,`shared`)),concurrency:f(A({max:g({integer:!0,minimum:1})})),retry:f(A({max:g({integer:!0,minimum:0})})),evidence:f(T(p())),approval:f(_()),label:f(p())},{name:`Edge`}),ue=A({kind:x(`file`,`url`,`metric`,`checklist`,`answer-key`,`artifact`),ref:p(),note:f(p())},{name:`Evidence`}),de=A({name:p(),inspects:T(ue),acceptance:p(),aspiration:f(p()),answerKeyFrom:f(F())},{name:`Bar`}),fe=x(`dispatches`,`minutes`,`usd`,`turns`,`tokens`),pe=j(`kind`,{human:A({kind:b(`human`),every:f(g({integer:!0,minimum:1})),then:f(F())}),budget:A({kind:b(`budget`),measure:fe,limit:g({minimum:0}),then:f(F())}),"bar-passed":A({kind:b(`bar-passed`),then:f(F())}),"diminishing-returns":A({kind:b(`diminishing-returns`),rounds:g({integer:!0,minimum:1}),metric:f(p()),threshold:f(g()),then:f(F())}),"evidence-invalid":A({kind:b(`evidence-invalid`),rounds:g({integer:!0,minimum:1}),then:f(F())}),"max-iterations":A({kind:b(`max-iterations`),n:g({integer:!0,minimum:1}),then:f(F())})},{name:`Stop`,label:`stop`}),me=A({id:h(),name:p(),members:T(F()),back:T(F()),mode:f(x(`grind`,`judgment`)),bar:f(de),stops:T(pe)},{name:`Loop`}),he=A({id:h(),kind:N([x(`critic-isolation`,`no-self-grading`,`owner-per-artifact`,`concurrency-cap`,`no-live-graph-rewrite`,`evidence-required`),A({custom:p()})],{describe:`policy kind or { custom }`}),scope:P(/^(graph|loop:[a-z][a-z0-9-]*|node:[a-z][a-z0-9-]*|edge:[a-z][a-z0-9-]*)$/,`scope (graph | loop:<id> | node:<id> | edge:<id>)`),params:f(D(N([p(),g(),_()],{describe:`string | number | boolean`})))},{name:`Policy`}),ge=/^[a-z][a-z0-9-]*@[1-9][0-9]*$/,_e=A({id:h(),name:p(),members:T(F()),coupled:f(_()),description:f(p({pattern:S,patternName:`one line of text`})),from:f(P(ge,`<template id>@<version>`)),with:f(D(p(),{keyPattern:/^[^{}\s]+$/,keyName:`slot key`}))},{name:`Group`}),ve=A({cost:x(`low`,`medium`,`high`),speed:x(`fast`,`medium`,`slow`),rigor:x(`light`,`standard`,`high`)},{name:`Profile`}),ye=A({kind:x(`graph`,`fragment`),title:p(),summary:p(),whenToUse:p(),notFor:f(p()),profile:ve,slots:f(T(A({key:p(),ask:p(),example:p()},{name:`TemplateSlot`}))),tags:f(T(p())),demo:f(p()),credits:f(T(A({name:p(),url:p(),note:p()},{name:`TemplateCredit`})))},{name:`Template`}),be=A({id:h(),run:p(),at:P(/^(graph|node:[a-z][a-z0-9-]*|edge:[a-z][a-z0-9-]*|loop:[a-z][a-z0-9-]*)$/,`run-note location (graph | node:<id> | edge:<id> | loop:<id>)`),started:f(p()),ended:f(p()),outcome:f(w([`pass`,`fail`,`halt`,`invalid-evidence`,`started`,`ending`],`outcome`)),verdict:f(p()),round:f(g({integer:!0,minimum:0})),stop:f(p()),evidence:f(T(p())),cost:f(A({measure:fe,amount:g()})),gaps:f(T(p())),proposal:f(A({summary:p(),patch:f(E())})),amendment:f(A({summary:p(),reason:p(),patch:f(E())})),text:f(p())},{name:`RunNote`}),xe=A({grooph:b(0),id:h(),name:p(),version:g({integer:!0,minimum:0}),goal:f(p()),target:f(A({harness:te})),constraints:f(A({budget:f(p()),time:f(p()),other:f(p())})),adaptation:f(x(`adaptive`,`propose`,`fixed`)),lineage:f(A({pattern:f(p()),from:f(p())})),template:f(ye),description:f(p()),nodes:T(ce),edges:T(le),loops:T(me),policies:f(T(he)),groups:f(T(_e)),notes:f(T(be)),layout:f(D(A({x:g(),y:g(),w:f(g()),h:f(g())}),{keyPattern:m,keyName:`node id`}))},{describe:`graph document`}),Se=`https://grooph.dev/schema/grooph-0.schema.json`;function Ce(t){let n=s(t,`graph`);if(n)return{issues:[e(`E_SCHEMA`,`${n.path}: ${n.message}`,[])]};let r=[];return xe.check(t,``,r),r.length>0?{issues:r.map(n=>e(`E_SCHEMA`,`${n.path===``?`/`:n.path}: ${n.message}`,Te(t,n.path)))}:{doc:t,issues:[]}}function we(t){let n;try{n=JSON.parse(t)}catch(t){return{issues:[e(`E_SCHEMA`,`/: not valid JSON: ${t.message}`)]}}return Ce(n)}function Te(e,t){let n=t.split(`/`).filter(e=>e!==``),r=e,i;for(let e of n){if(typeof r!=`object`||!r)break;let t=e.replace(/~1/g,`/`).replace(/~0/g,`~`);if(r=r[t],typeof r==`object`&&r&&!Array.isArray(r)){let e=r.id;typeof e==`string`&&(i=e)}}return i===void 0?[]:[i]}function Ee(e){return`${JSON.stringify(xe.canon(e),null,2)}\n`}function De(e){let{layout:t,...n}=e;return Ee(n)}var Oe=e=>{let t=new Map;for(let n of e??[])t.has(n.id)||t.set(n.id,n);return t};function ke(e){let t=e.nodes??[],n=e.edges??[],r=[],i=(e,t)=>{(t??[]).forEach((t,n)=>r.push({kind:e,id:t.id,index:n}))};i(`graph`,[e]),i(`node`,t),i(`edge`,n),i(`loop`,e.loops),i(`group`,e.groups),i(`policy`,e.policies),i(`note`,e.notes);let a=new Map;t.forEach((e,t)=>{a.has(e.id)||a.set(e.id,t)});let o=new Map,s=new Map;for(let e of n)(o.get(e.from)??o.set(e.from,[]).get(e.from)).push(e),(s.get(e.to)??s.set(e.to,[]).get(e.to)).push(e);return{doc:e,nodes:Oe(t),edges:Oe(n),loops:Oe(e.loops),groups:Oe(e.groups),policies:Oe(e.policies),notes:Oe(e.notes),owners:r,nodeOrder:a,outgoing:o,incoming:s}}var Ae=e=>e?.kind===`agent`;function je(e,t){return[...t].sort((t,n)=>(e.nodeOrder.get(t)??0)-(e.nodeOrder.get(n)??0))}function Me(e,t){let n=[...e.nodes.keys()],r=new Map;for(let e of n)r.set(e,[]);let i=new Set;for(let n of t)e.nodes.has(n.from)&&e.nodes.has(n.to)&&(r.get(n.from).push(n.to),n.from===n.to&&i.add(n.from));let a=0,o=new Map,s=new Map,c=new Set,l=[],u=[],d=t=>{o.set(t,a),s.set(t,a),a+=1,l.push(t),c.add(t);for(let e of r.get(t)??[])o.has(e)?c.has(e)&&s.set(t,Math.min(s.get(t),o.get(e))):(d(e),s.set(t,Math.min(s.get(t),s.get(e))));if(s.get(t)===o.get(t)){let n=[];for(;;){let e=l.pop();if(c.delete(e),n.push(e),e===t)break}(n.length>1||i.has(n[0]))&&u.push(je(e,n))}};for(let e of n)o.has(e)||d(e);return u.sort((t,n)=>(e.nodeOrder.get(t[0])??0)-(e.nodeOrder.get(n[0])??0))}function Ne(e,t,n,r){if(!n.has(e)||!n.has(t))return!1;let i=new Set([e]),a=[e];for(;a.length>0;){let o=a.shift();if(o===t&&i.size>0&&o!==e)return!0;for(let e of r)if(e.from===o&&n.has(e.to)){if(e.to===t)return!0;i.has(e.to)||(i.add(e.to),a.push(e.to))}}return!1}var Pe={"claude-code":`Claude Code`,codex:`Codex`},Fe=Object.keys(Pe),Ie=e=>Object.prototype.hasOwnProperty.call(Pe,e),Le=e=>Ie(e)?Pe[e]:void 0,Re=[`critic`,`judge`,`red-team`],ze=[`builder`,`synthesizer`,`planner`],Be=e=>typeof e.role==`string`?e.role:e.role.custom,Ve=e=>typeof e.role!=`string`,He=e=>e.by===`person`?`person`:`agent`,L=e=>e?.kind===`agent`&&e.by===`person`,Ue={agent:`Agent`,person:`Person`},We=e=>e.kind===`agent`&&!Ve(e)&&Re.includes(e.role),Ge=e=>e.kind===`agent`?Ve(e)?(e.owns??[]).length>0:ze.includes(e.role):!1,Ke=e=>e.when??`always`,qe=e=>{let t=Ke(e);return typeof t==`string`?t:`verdict ${t.verdict}`},Je=e=>e.isolation??`fresh`;function Ye(e,t){if(t.mode)return t.mode;let n=(t.back??[]).map(t=>e.edges.get(t)).filter(e=>!!e);return n.length===0||n.every(t=>e.nodes.get(t.from)?.kind===`check`)?`grind`:`judgment`}function Xe(e,t){if(!t)return[];let n=t.answerKeyFrom!==void 0&&e.nodes.has(t.answerKeyFrom);return(t.inspects??[]).filter(e=>e.kind!==`answer-key`||n)}var Ze=(e,t)=>Xe(e,t.bar).length>0;function Qe(e){switch(e.kind){case`human`:return e.every===void 0?`human halt`:`human halt, asked every ${e.every} round(s)`;case`budget`:return`budget: ${e.limit} ${e.measure}`;case`bar-passed`:return`bar passed`;case`diminishing-returns`:return`diminishing returns over ${e.rounds} round(s)${e.metric?` on ${e.metric}`:``}${e.threshold===void 0?``:` (threshold ${e.threshold})`}`;case`evidence-invalid`:return`evidence invalid for ${e.rounds} round(s)`;case`max-iterations`:return`max iterations: ${e.n}`;default:return JSON.stringify(e)}}function $e(e,t=!1){return e.then===void 0?e.kind===`bar-passed`?`follow the loop's pass exit edges`:t?`stop here and decide`:`halt the run and report to the human`:`continue at node \`${e.then}\``}var et=e=>{if((e.nodes??[]).some(L))return!0;let t=e.target?.harness;return e.template===void 0&&(typeof t!=`string`||!Ie(t))},tt=e=>(e.stops??[]).flatMap(t=>t.then===void 0||(e.members??[]).includes(t.then)?[]:[t.then]);function nt(e){let t=e.doc.loops??[],n=new Set(t.flatMap(e=>e.back??[])),r=new Set(t.flatMap(tt));return(e.doc.nodes??[]).filter(t=>!r.has(t.id)&&(e.incoming.get(t.id)??[]).every(e=>n.has(e.id))).map(e=>e.id)}function rt(e,t){return(e.doc.loops??[]).filter(e=>(e.members??[]).includes(t))}function it(e,t){let n=new Set(t.filter(t=>e.nodes.has(t))),r=[...n];for(;r.length>0;){let t=r.shift(),i=(e.outgoing.get(t)??[]).map(e=>e.to);for(let n of e.doc.loops??[])(n.members??[]).includes(t)&&i.push(...tt(n));for(let t of i)e.nodes.has(t)&&!n.has(t)&&(n.add(t),r.push(t))}return n}function at(e,t,n){let r=t.scope;if(r===`graph`)return!0;let i=r.indexOf(`:`),a=r.slice(0,i),o=r.slice(i+1);return a===`edge`?o===n.id:a===`node`?o===n.from||o===n.to:a===`loop`&&(e.loops.get(o)?.members??[]).includes(n.to)}var ot=[`fixed`,`propose`,`adaptive`];function st(e){let t=[e.adaptation??`adaptive`];return(e.policies??[]).some(e=>e.kind===`no-live-graph-rewrite`&&e.scope===`graph`)&&t.push(`propose`),ot.find(e=>t.includes(e))}function ct(e,t){if(e===t)return 0;let n=[Array.from({length:t.length+1},(e,t)=>t)];for(let r=1;r<=e.length;r+=1){let i=[r];for(let a=1;a<=t.length;a+=1){let o=e[r-1]===t[a-1]?0:1;i[a]=Math.min(n[r-1][a]+1,i[a-1]+1,n[r-1][a-1]+o),r>1&&a>1&&e[r-1]===t[a-2]&&e[r-2]===t[a-1]&&(i[a]=Math.min(i[a],n[r-2][a-2]+1))}n.push(i)}return n[e.length][t.length]}function lt(e,t){let n=Math.max(1,Math.min(3,Math.floor(e.length/3))),r,i=1/0;for(let a of t){let t=ct(e.toLowerCase(),a.toLowerCase());t<i&&t<=n&&(r=a,i=t)}return r}var R=(e,t)=>{let n=lt(e,t);return n===void 0?``:`; did you mean "${n}"?`};function z(e,t=`item`){let n=e.normalize(`NFKD`).replace(/[̀-ͯ]/g,``).toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).replace(/^[^a-z]+/,``);return n===``?t:n}function ut(e,t){if(!t.has(e))return e;for(let n=2;;n++){let r=`${e}-${n}`;if(!t.has(r))return r}}function dt(e){let t=new Set([e.id]);for(let n of[e.nodes,e.edges,e.loops,e.groups,e.policies,e.notes])for(let e of n??[])t.add(e.id);return t}function ft(e,t){let n=z(t,``);return n===``||e===n||RegExp(`^${n}-\\d+$`).test(e)}var pt={agent:`Agent`,"human-gate":`Human gate`,check:`Check`,merge:`Merge`,stop:`Stop`};function mt(e,t,n){let r={...e};return n===void 0?delete r[t]:r[t]=n,r}var ht=e=>e.trim()===``?void 0:e,gt=e=>e.length===0?void 0:e,_t=e=>Math.round(e);function vt(e){let t={grooph:0,id:e.id??z(e.name,`graph`),name:e.name,version:1,nodes:[],edges:[],loops:[]};return e.goal!==void 0&&(t.goal=e.goal),e.target!==void 0&&(t.target={harness:e.target}),t}function yt(e,t,n){return mt(e,t,n)}function bt(e,t){return mt(e,`target`,t===void 0?void 0:{...e.target,harness:t})}function xt(e,t,n){let r=mt({...e.constraints},t,n);return mt(e,`constraints`,Object.keys(r).length===0?void 0:r)}function St(e,t){let n={...e,name:t};if(!ft(e.id,e.name))return n;let r=dt(e);return r.delete(e.id),{...n,id:ut(z(t,`graph`),r)}}function Ct(e,t,n){switch(e){case`agent`:return{id:t,kind:e,name:n,role:`builder`,brief:``,outputs:[]};case`human-gate`:return{id:t,kind:e,name:n,prompt:``};case`check`:return{id:t,kind:e,name:n,check:{kind:`tests`,pass:``}};case`merge`:return{id:t,kind:e,name:n,merges:[]};case`stop`:return{id:t,kind:e,name:n}}}function wt(e,t,n={}){let r=dt(e),i=pt[t],a,o;if(n.name!==void 0)o=n.name,a=n.id??ut(z(o,z(i)),r);else{a=n.id??ut(z(i),r);let e=a.slice(z(i).length);o=n.id!==void 0||e===``?i:`${i} ${e.slice(1)}`}let s={...e,nodes:[...e.nodes,Ct(t,a,o)]};return e.layout&&n.at&&(s=qt(s,{[a]:n.at})),{doc:s,id:a}}function Tt(e,t,n){return{...e,nodes:e.nodes.map(e=>e.id===t?n(e):e)}}function Et(e,t,n){let r=e.nodes.find(e=>e.id===t);if(!r)return{doc:e,id:t};let i=Tt(e,t,e=>({...e,name:n}));if(!ft(t,r.name))return{doc:i,id:t};let a=dt(i);a.delete(t);let o=ut(z(n,z(pt[r.kind])),a);return o===t?{doc:i,id:t}:(i=Jt(i,t,o),{doc:i,id:o})}function Dt(e,t){let n=e;for(let r of e.edges)(r.from===t||r.to===t)&&(n=jt(n,r.id));if(n={...n,nodes:n.nodes.filter(e=>e.id!==t),loops:n.loops.map(e=>{let n={...e,members:e.members.filter(e=>e!==t)};return n={...n,stops:n.stops.map(e=>e.then===t?mt(e,`then`,void 0):e)},n.bar?.answerKeyFrom===t&&(n={...n,bar:mt(n.bar,`answerKeyFrom`,void 0)}),n})},n.layout&&t in n.layout){let{[t]:e,...r}=n.layout;n={...n,layout:r}}return n.groups&&(n={...n,groups:n.groups.map(e=>({...e,members:e.members.filter(e=>e!==t)}))}),Yt(n,`node:${t}`)}var Ot=(e,t)=>`e-${e}-${t}`;function kt(e,t,n,r={}){let i=r.id??ut(Ot(t,n),dt(e));return{doc:{...e,edges:[...e.edges,{id:i,from:t,to:n}]},id:i}}function At(e,t,n){return{...e,edges:e.edges.map(e=>e.id===t?n(e):e)}}function jt(e,t){return Yt({...e,edges:e.edges.filter(e=>e.id!==t),loops:e.loops.map(e=>e.back.includes(t)?{...e,back:e.back.filter(e=>e!==t)}:e)},`edge:${t}`)}function Mt(e,t=[],n={}){let r=dt(e),i,a;n.name===void 0?(i=n.id??ut(`loop`,r),a=n.id!==void 0||i===`loop`?`Loop`:`Loop ${i.slice(5)}`):(a=n.name,i=n.id??ut(z(a,`loop`),r));let o={id:i,name:a,members:t,back:[],stops:[]};return{doc:{...e,loops:[...e.loops,o]},id:i}}function Nt(e,t,n){return{...e,loops:e.loops.map(e=>e.id===t?n(e):e)}}function Pt(e,t,n){let r=e.loops.find(e=>e.id===t);if(!r)return{doc:e,id:t};let i=Nt(e,t,e=>({...e,name:n}));if(!ft(t,r.name))return{doc:i,id:t};let a=dt(i);a.delete(t);let o=ut(z(n,`loop`),a);return o===t?{doc:i,id:t}:{doc:Jt(i,t,o),id:o}}function Ft(e,t){return Yt({...e,loops:e.loops.filter(e=>e.id!==t)},`loop:${t}`)}var It=(e,t,n)=>{let r=e.includes(t),i=n??!r;return i===r?e:i?[...e,t]:e.filter(e=>e!==t)};function Lt(e,t,n,r){let i=new Map(e.nodes.map((e,t)=>[e.id,t]));return Nt(e,t,e=>({...e,members:It(e.members,n,r).sort((e,t)=>(i.get(e)??1e9)-(i.get(t)??1e9))}))}function Rt(e,t,n,r){let i=new Map(e.edges.map((e,t)=>[e.id,t]));return Nt(e,t,e=>({...e,back:It(e.back,n,r).sort((e,t)=>(i.get(e)??1e9)-(i.get(t)??1e9))}))}function zt(e,t,n){return Nt(e,t,e=>mt(e,`bar`,n))}function Bt(e,t){let n=t?.then===void 0?{}:{then:t.then};switch(e){case`human`:return{kind:e,...n};case`budget`:return{kind:e,measure:`dispatches`,limit:12,...n};case`bar-passed`:return{kind:e,...n};case`diminishing-returns`:return{kind:e,rounds:2,...n};case`evidence-invalid`:return{kind:e,rounds:2,...n};case`max-iterations`:return{kind:e,n:4,...n}}}function Vt(e,t,n,r={}){let i={...Bt(n),...r,kind:n};return Nt(e,t,e=>({...e,stops:[...e.stops,i]}))}function Ht(e,t,n,r){return Nt(e,t,e=>({...e,stops:e.stops.map((e,t)=>t===n?r:e)}))}function Ut(e,t,n){return Nt(e,t,e=>({...e,stops:e.stops.filter((e,t)=>t!==n)}))}function Wt(e,t,n,r){return Nt(e,t,e=>{let t=n+r;if(t<0||t>=e.stops.length)return e;let i=[...e.stops];return[i[n],i[t]]=[i[t],i[n]],{...e,stops:i}})}function Gt(e,t){let n=typeof t.kind==`string`?t.kind:t.kind.custom,r=t.id??ut(`p-${z(n,`policy`)}`,dt(e)),i={id:r,kind:t.kind,scope:t.scope};return t.params!==void 0&&(i.params=t.params),{doc:{...e,policies:[...e.policies??[],i]},id:r}}function Kt(e,t){return e.policies?mt(e,`policies`,gt(e.policies.filter(e=>e.id!==t))):e}function qt(e,t){let n={...e.layout};for(let[e,r]of Object.entries(t))n[e]={...n[e],x:_t(r.x),y:_t(r.y)};return{...e,layout:n}}function Jt(e,t,n){if(t===n)return e;if(e.id===t)return{...e,id:n};let r=e=>e===t?n:e,i=e=>{let r=e.indexOf(`:`);return r>0&&e.slice(r+1)===t?`${e.slice(0,r)}:${n}`:e},a=e.nodes.some(e=>e.id===t),o={...e,nodes:e.nodes.map(e=>e.id===t?{...e,id:n}:e),edges:e.edges.map(e=>{let n={...e,id:r(e.id),from:r(e.from),to:r(e.to)};return e.id===t||e.from===t||e.to===t?n:e}),loops:e.loops.map(e=>{let i={...e,id:r(e.id),members:e.members.map(r),back:e.back.map(r),stops:e.stops.map(e=>e.then===t?{...e,then:n}:e)};return i.bar?.answerKeyFrom===t&&(i.bar={...i.bar,answerKeyFrom:n}),i})};if(e.policies&&(o.policies=e.policies.map(e=>({...e,id:r(e.id),scope:i(e.scope)}))),e.groups&&(o.groups=e.groups.map(e=>({...e,id:r(e.id),members:e.members.map(r)}))),e.layout&&t in e.layout){let t={};for(let[n,i]of Object.entries(e.layout))t[r(n)]=i;o.layout=t}if(a)for(let e of o.edges){if(e.from!==n&&e.to!==n)continue;let r=Ot(e.from===n?t:e.from,e.to===n?t:e.to);if(e.id!==r&&!RegExp(`^${r}-\\d+$`).test(e.id))continue;let i=dt(o);i.delete(e.id);let a=ut(Ot(e.from,e.to),i);a!==e.id&&(o=Jt(o,e.id,a))}return o}function Yt(e,t){return e.policies?.some(e=>e.scope===t)?{...e,policies:e.policies.filter(e=>e.scope!==t)}:e}var Xt=class extends Error{constructor(e){super(e),this.name=`TemplateError`}},Zt=/\{\{\s*([^{}\s]+)\s*\}\}/g,Qt=new Set([`nodes`,`edges`,`loops`,`policies`,`groups`,`notes`,`layout`,`template`]);function $t(e,t){if(typeof e==`string`)t(e);else if(Array.isArray(e))for(let n of e)$t(n,t);else if(typeof e==`object`&&e)for(let n of Object.values(e))$t(n,t)}function en(e,t){if(typeof e==`string`)return t(e);if(Array.isArray(e))return e.map(e=>en(e,t));if(typeof e==`object`&&e){let n={};for(let[r,i]of Object.entries(e))n[r]=en(i,t);return n}return e}function tn(e){let t={};for(let[n,r]of Object.entries(e))Qt.has(n)||(t[n]=r);let n=[e.nodes,e.edges,e.loops,e.policies,e.groups];return[{id:e.id,value:t},...n.flatMap(e=>(e??[]).map(e=>({id:e.id,value:e})))]}function nn(e){let t=new Map;for(let n of tn(e))$t(n.value,e=>{for(let r of e.matchAll(Zt)){let e=t.get(r[1])??[];e.includes(n.id)||e.push(n.id),t.set(r[1],e)}});return[...t].map(([e,t])=>({key:e,at:t}))}function rn(e,t){let n=e=>e.replace(Zt,(e,n)=>Object.hasOwn(t,n)?t[n]:e),r={};for(let[t,i]of Object.entries(e))r[t]=t===`template`||t===`notes`||t===`layout`?i:en(i,n);return r}function an(e){let t=(e.template?.slots??[]).map(e=>e.key);return[...new Set([...t,...nn(e).map(e=>e.key)])]}function on(e,t){let n=an(e);for(let r of Object.keys(t))if(!n.includes(r))throw new Xt(`template "${e.id}" has no slot "${r}"${R(r,n)}${n.length>0?`; its slots are ${n.join(`, `)}`:`; it has no slots`}`)}function sn(e){if(!e.template)throw new Xt(`"${e.id}" is not a template: it has no template block`);return e.template}function cn(e,t){if(sn(e).kind===`fragment`)throw new Xt(`"${e.id}" is a fragment, not a whole graph; insert it into a graph instead (insertFragment, grooph template insert)`);let n=t.values??{};on(e,n);let{template:r,notes:i,...a}=e,o=rn(a,n),s=dt(o);return s.delete(o.id),{...o,id:t.id??ut(z(t.name,`graph`),s),name:t.name,version:1,lineage:{pattern:e.id,from:`${e.id}@${e.version}`}}}var ln=e=>{let t=Ot(e.from,e.to);return e.id===t||RegExp(`^${t}-\\d+$`).test(e.id)},un=(e,t)=>JSON.stringify(e)===JSON.stringify(t);function dn(e,t,n={}){sn(t);let r=n.values??{};on(t,r);let i=``;if(n.prefix!==void 0&&n.prefix!==``&&(i=n.prefix.endsWith(`-`)?n.prefix:`${n.prefix}-`,!m.test(i)))throw new Xt(`prefix "${n.prefix}" must start with a letter and use only a-z, 0-9 and "-", so the ids it makes stay kebab-case`);let a=rn(t,r),o=dt(e),s={},c=(e,t)=>{let n=ut(t,o);return o.add(n),s[e]=n,n};for(let e of a.nodes)c(e.id,i+e.id);let l=e=>s[e]??e;for(let e of a.edges)c(e.id,ln(e)?Ot(l(e.from),l(e.to)):i+e.id);for(let e of a.loops)c(e.id,i+e.id);for(let e of a.groups??[])c(e.id,i+e.id);let u=e=>{if(e===`graph`)return e;let t=e.indexOf(`:`);return`${e.slice(0,t)}:${l(e.slice(t+1))}`},d=e.policies??[],f=[];for(let e of a.policies??[])e.scope===`graph`&&d.some(t=>t.scope===`graph`&&un(t.kind,e.kind)&&un(t.params,e.params))||f.push({...e,id:c(e.id,i+e.id),scope:u(e.scope)});let p=a.nodes.map(e=>({...e,id:l(e.id)})),h=a.edges.map(e=>({...e,id:l(e.id),from:l(e.from),to:l(e.to)})),g=a.loops.map(e=>{let t={...e,id:l(e.id),members:e.members.map(l),back:e.back.map(l),stops:e.stops.map(e=>e.then===void 0?e:{...e,then:l(e.then)})};return e.bar?.answerKeyFrom!==void 0&&(t.bar={...e.bar,answerKeyFrom:l(e.bar.answerKeyFrom)}),t}),_=(a.groups??[]).map(e=>({...e,id:l(e.id),members:e.members.map(l)})),v={...e,nodes:[...e.nodes,...p],edges:[...e.edges,...h],loops:[...e.loops,...g]};return f.length>0&&(v.policies=[...d,...f]),_.length>0&&(v.groups=[...e.groups??[],..._]),{doc:v,ids:s}}function fn(e,t){let{meta:n}=t;if(!m.test(n.id))throw new Xt(`template id "${n.id}" must be kebab-case, like "my-review-gate"`);let{notes:r,template:i,...a}=e,o=a;if(t.kind===`fragment`)o=pn(o,t.nodeIds??[]);else if(t.nodeIds!==void 0)throw new Xt(`nodeIds selects a fragment; pass kind: "fragment" with it`);let s=dt(o);if(s.delete(o.id),s.has(n.id))throw new Xt(`template id "${n.id}" is already the id of an object inside it; choose another`);let c=[...n.slots??[]];for(let e of nn(o))c.some(t=>t.key===e.key)||c.push({key:e.key,ask:`What should "${e.key}" be?`,example:e.key});let l={kind:t.kind,title:n.title,summary:n.summary,whenToUse:n.whenToUse,profile:n.profile??mn(o)};n.notFor!==void 0&&(l.notFor=n.notFor),c.length>0&&(l.slots=c),n.tags!==void 0&&n.tags.length>0&&(l.tags=n.tags),n.demo!==void 0&&(l.demo=n.demo),n.credits!==void 0&&n.credits.length>0&&(l.credits=n.credits.map(e=>({...e})));let u={from:`${e.id}@${e.version}`};return e.lineage?.pattern!==void 0&&(u.pattern=e.lineage.pattern),{...o,id:n.id,name:n.title,version:1,lineage:u,template:l}}function pn(e,t){if(t.length===0)throw new Xt(`a fragment needs at least one node id`);let n=e.nodes.map(e=>e.id);for(let r of t)if(!n.includes(r))throw new Xt(`no node "${r}" in "${e.id}"${R(r,n)}`);let r=new Set(t),i=e.edges.filter(e=>r.has(e.from)&&r.has(e.to)),a=new Set(i.map(e=>e.id)),o=e.loops.filter(e=>e.members.length>0&&e.members.every(e=>r.has(e))&&e.back.every(e=>a.has(e))).map(e=>{let t={...e,stops:e.stops.map(e=>{if(e.then===void 0||r.has(e.then))return e;let{then:t,...n}=e;return n})};if(e.bar?.answerKeyFrom!==void 0&&!r.has(e.bar.answerKeyFrom)){let{answerKeyFrom:n,...r}=e.bar;t.bar=r}return t}),s=new Set(o.map(e=>e.id)),c=new Set;for(let t=!0;t;){t=!1;for(let n of e.groups??[])c.has(n.id)||n.members.length===0||n.members.every(e=>r.has(e)||c.has(e))&&(c.add(n.id),t=!0)}let l=e=>{if(e===`graph`)return!1;let t=e.indexOf(`:`),n=e.slice(0,t),i=e.slice(t+1);return n===`node`&&r.has(i)||n===`edge`&&a.has(i)||n===`loop`&&s.has(i)},{goal:u,target:d,constraints:f,adaptation:p,description:m,layout:h,policies:g,groups:_,...v}=e,y={...v,nodes:e.nodes.filter(e=>r.has(e.id)),edges:i,loops:o},b=(g??[]).filter(e=>l(e.scope));b.length>0&&(y.policies=b);let x=(_??[]).filter(e=>c.has(e.id));return x.length>0&&(y.groups=x),y}function mn(e){let t=e.nodes.filter(e=>e.kind===`agent`),n=t.map(e=>e.model?.tier??`strong`),r=e.nodes.filter(We).length,i=e.nodes.filter(e=>e.kind===`human-gate`).length,a=e.loops.filter(e=>e.bar!==void 0).length,o=n.includes(`frontier`)||t.length>=6?`high`:n.length>0&&n.every(e=>e===`fast`)?`low`:`medium`,s=a>=2||t.length>=6?`slow`:a===0&&i===0&&t.length<=3?`fast`:`medium`,c=e.loops.some(e=>e.bar?.answerKeyFrom!==void 0);return{cost:o,speed:s,rigor:r+i===0?`light`:r>=2||c?`high`:`standard`}}var hn=[`E_CYCLE_NO_STOP`,`E_JUDGMENT_LOOP_NO_BAR`,`E_STOP_NOT_INSPECTABLE`,`W_LONG_LOOP_NO_BUDGET`,`W_ASPIRATION_AS_ACCEPTANCE`,`W_ONLY_MAX_ITERATIONS`],gn=24e3;function _n(e,t={}){let n=vn(e,t);return t.loops===`errors`?n:t.loops===`advice`?n.map(e=>hn.includes(e.code)?{...e,severity:`warning`}:e):n.filter(e=>!hn.includes(e.code))}function vn(e,t){let n=ke(e);return[...yn(n),...bn(n),...xn(n),...Cn(n),...wn(n),...Tn(n),...En(n),...Dn(n),...On(n),...t.forExport?kn(n):[],...Mn(n),...Nn(n),...Pn(n),...In(n),...Rn(n),...zn(n),...Vn(n),...Hn(n),...Un(n),...Wn(n),...Gn(n),...Kn(n),...qn(n),...Jn(n),...Yn(n)]}function yn(t){let n=new Map;for(let e of t.owners){let t=n.get(e.id)??[];t.push(e.kind===`graph`?`the graph's own id`:`${e.kind}s[${e.index}]`),n.set(e.id,t)}let r=[];for(let[t,i]of n)i.length>1&&r.push(e(`E_DUPLICATE_ID`,`id "${t}" is used ${i.length} times: ${i.join(`, `)}`,[t]));return r}function bn(t){let n=[],r=e=>!t.nodes.has(e);for(let i of t.doc.edges??[])r(i.from)&&n.push(e(`E_DANGLING_REF`,`edge "${i.id}" starts at unknown node "${i.from}"`,[i.id])),r(i.to)&&n.push(e(`E_DANGLING_REF`,`edge "${i.id}" ends at unknown node "${i.to}"`,[i.id]));for(let i of t.doc.loops??[]){for(let t of i.members??[])r(t)&&n.push(e(`E_DANGLING_REF`,`loop "${i.id}" lists unknown member "${t}"`,[i.id]));for(let r of i.back??[])t.edges.has(r)||n.push(e(`E_DANGLING_REF`,`loop "${i.id}" lists unknown back edge "${r}"`,[i.id]));i.bar?.answerKeyFrom!==void 0&&r(i.bar.answerKeyFrom)&&n.push(e(`E_DANGLING_REF`,`loop "${i.id}" takes its answer key from unknown node "${i.bar.answerKeyFrom}"`,[i.id])),(i.stops??[]).forEach((t,a)=>{t.then!==void 0&&r(t.then)&&n.push(e(`E_DANGLING_REF`,`loop "${i.id}" stop ${a} (${t.kind}) continues at unknown node "${t.then}"`,[i.id]))})}for(let r of t.doc.groups??[])for(let i of r.members??[])!t.nodes.has(i)&&!t.groups.has(i)&&n.push(e(`E_DANGLING_REF`,`group "${r.id}" lists unknown member "${i}"`,[r.id]));for(let r of t.doc.policies??[]){let i=r.scope;if(i===`graph`)continue;let a=i.indexOf(`:`),o=i.slice(0,a),s=i.slice(a+1);o===`node`&&t.nodes.has(s)||o===`loop`&&t.loops.has(s)||o===`edge`&&t.edges.has(s)||n.push(e(`E_DANGLING_REF`,`policy "${r.id}" is scoped to unknown ${o} "${s}"`,[r.id]))}return n}function xn(t){let n=[],r=t.doc.edges??[];for(let i of t.doc.loops??[]){let a=i.back??[];if(a.length===0){n.push(e(`E_LOOP_BACK_EDGE`,`loop "${i.id}" has no back edge`,[i.id]));continue}let o=new Set(i.members??[]);for(let s of a){let a=t.edges.get(s);if(a){if(!o.has(a.from)||!o.has(a.to)){n.push(e(`E_LOOP_BACK_EDGE`,`loop "${i.id}": back edge "${a.id}" runs ${a.from} → ${a.to}, which is not inside the loop's members`,[i.id,a.id]));continue}Ne(a.to,a.from,o,r)||n.push(e(`E_LOOP_BACK_EDGE`,`loop "${i.id}": back edge "${a.id}" returns to ${a.to}, but no path inside the loop's members leads from there to ${a.from}`,[i.id,a.id]))}}}return n}var Sn=(e,t)=>(t.members??[]).flatMap(t=>{let n=e.groups.get(t);return n?[n]:[]});function Cn(t){let n=[],r=new Set;for(let i of t.doc.groups??[]){let a=(o,s)=>{for(let c of Sn(t,o))if(c.id===i.id){let t=[...s].sort().join(` `);if(r.has(t))continue;r.add(t),n.push(e(`E_GROUP_CYCLE`,s.length===1?`group "${i.id}" lists itself as a member; a group cannot hold itself`:`group "${i.id}" holds itself: ${[...s,i.id].join(` → `)}; groups form a tree`,s))}else s.includes(c.id)||a(c,[...s,c.id])};a(i,[i.id])}return n}function wn(t){let n=An(t).filter(e=>e.role===`lead`);return n.length<2?[]:[e(`E_SECOND_LEAD`,`the graph has ${n.length} lead nodes (${jn(n.map(e=>e.id))}); a graph is one session and has at most one lead`,n.map(e=>e.id))]}function Tn(t){return An(t).filter(e=>e.role===`lead`&&L(e)).map(t=>e(`E_PERSON_LEAD`,`node "${t.id}" is the lead and is marked as a person's step; the lead is the harness's own session: give the step another role, or leave it an agent's`,[t.id]))}function En(t){let n=new Set;for(let e of t.doc.loops??[])if((e.stops??[]).length!==0)for(let t of e.back??[])n.add(t);return Me(t,(t.doc.edges??[]).filter(e=>!n.has(e.id))).map(n=>e(`E_CYCLE_NO_STOP`,`cycle with no stop: ${je(t,n).join(` → `)}. Cover it with a loop that has at least one stop.`,n))}function Dn(t){let n=[];for(let r of t.doc.loops??[])Ye(t,r)===`judgment`&&(Ze(t,r)||n.push(e(`E_JUDGMENT_LOOP_NO_BAR`,r.bar?`judgment loop "${r.id}" has a bar with nothing inspectable; give it at least one file, url, metric, checklist, artifact, or an answer key from a node in the graph`:`judgment loop "${r.id}" has no bar; name what stopping looks like and what the critic inspects`,[r.id])));return n}function On(t){let n=[];for(let r of t.doc.loops??[]){let i=r.stops??[];i.length!==0&&i.every(e=>e.kind===`bar-passed`)&&(Ze(t,r)||n.push(e(`E_STOP_NOT_INSPECTABLE`,`loop "${r.id}" stops only when its bar passes, but the bar names nothing a critic can inspect. An adjective is not a bar.`,[r.id])))}return n}function kn(t){let n=[],r=t.doc,i=r.target?.harness;if(i===void 0||i.trim()===``?n.push(e(`E_NO_TARGET`,`export needs a target harness; set target.harness`,[r.id])):Ie(i)||n.push(e(`E_NO_TARGET`,`grooph has no compiler for the harness "${i}", so no package can be written for it; the document is a plan as it is`,[r.id])),(r.goal===void 0||r.goal.trim()===``)&&n.push(e(`E_NO_GOAL`,`export needs a goal; the lead brief is built from it`,[r.id])),r.template!==void 0)n.push(e(`E_IS_TEMPLATE`,`"${r.id}" is a template; instantiate it first (grooph template use ${r.id} --name <graph name>)`,[r.id]));else{for(let t of nn(r))n.push(e(`E_UNFILLED_SLOT`,`slot {{${t.key}}} is still unfilled in ${jn(t.at)}; replace it with a real value before export`,t.at));let i=An(t).filter(L).map(e=>e.id);if(i.length>0){let[t,r]=i.length===1?[`is a person's step`,`it`]:[`are people's steps`,`each`];n.push(e(`E_PERSON_STEP_NOT_COMPILED`,`${jn(i)} ${t}, and grooph cannot yet hand a step to a person inside a harness, so no package is written; the plan exports as it is (PLAN.md, the picture, the file); make ${r} an agent's if the graph is to run`,i))}}return n}var An=e=>(e.doc.nodes??[]).filter(Ae),jn=e=>e.map(e=>`"${e}"`).join(`, `);function Mn(t){let n=(t.doc.policies??[]).filter(e=>e.kind===`critic-isolation`);if(n.length===0)return[];let r=[];for(let i of t.doc.edges??[]){let a=t.nodes.get(i.to);if(!a||!We(a)||L(a))continue;let o=n.find(e=>at(t,e,i));if(!o)continue;let s=t.nodes.get(i.from);Je(i)===`shared`?r.push(e(`E_CRITIC_NOT_ISOLATED`,`edge "${i.id}" hands critic "${a.id}" shared context, but policy "${o.id}" requires critic isolation; make the edge fresh and list the evidence the critic may inspect`,[i.id,a.id])):s&&Ge(s)&&(i.evidence??[]).length===0&&r.push(e(`E_CRITIC_NOT_ISOLATED`,`edge "${i.id}" runs from writer "${s.id}" to critic "${a.id}" with no evidence list, but policy "${o.id}" requires critic isolation; list what the critic may inspect`,[i.id,s.id,a.id]))}return r}function Nn(t){let n=new Map;for(let e of t.doc.nodes??[])if(Ge(e)&&e.kind===`agent`)for(let t of new Set(e.owns??[]))n.set(t,[...n.get(t)??[],e.id]);let r=new Set;for(let e of t.doc.nodes??[])if(e.kind===`merge`)for(let t of e.merges??[])r.add(t);let i=[];for(let[t,a]of n)a.length<2||r.has(t)||i.push(e(`E_OWNERSHIP_CONFLICT`,`artifact "${t}" is owned by writers ${jn(a)} and no merge node lists it in merges; give it one owner, or add a merge node that merges it`,a));return i}function Pn(t){let n=[],r=e=>e.approval===!0||t.nodes.get(e.from)?.kind===`human-gate`,i=new Set(nt(t));for(let a of An(t)){let o=a.irreversible??[];if(o.length===0||L(a))continue;let s=t.incoming.get(a.id)??[],c=s.filter(e=>!r(e)),l=(t.doc.loops??[]).flatMap(e=>(e.stops??[]).flatMap((t,n)=>t.then===a.id?[{loop:e,stop:t,i:n}]:[])),u=l.filter(({stop:e})=>e.kind!==`human`);if(i.has(a.id)&&s.length+l.length>0){n.push(e(`E_IRREVERSIBLE_NO_GATE`,`node "${a.id}" performs irreversible actions (${o.join(`, `)}) and is where the run starts: only ${s.length>0?`a loop's back edge (${jn(s.map(e=>e.id))})`:`a stop of its own loop`} leads to it, so no human decides before it runs the first time; put a human-gate node before it`,[a.id,...s.map(e=>e.id)]));continue}if(s.length+l.length>0&&c.length===0&&u.length===0)continue;let d=[...c.length>0?[jn(c.map(e=>e.id))]:[],...u.map(({loop:e,stop:t,i:n})=>`loop "${e.id}" stop ${n} (${t.kind}), which continues there`)],f=[...c.length>0?[`set approval: true on those edges, or start them at a human-gate node`]:[],...u.length>0?[`have the stop continue at a human-gate node that leads to it`]:[]];n.push(e(`E_IRREVERSIBLE_NO_GATE`,s.length+l.length===0?`node "${a.id}" performs irreversible actions (${o.join(`, `)}) and nothing leads to it, so no human decides before it runs; put a human-gate node before it`:`node "${a.id}" performs irreversible actions (${o.join(`, `)}) and can be reached without a human decision through ${d.join(` and `)}; every way in must pass a human: ${f.join(`, and `)}`,[a.id,...c.map(e=>e.id),...new Set(u.map(({loop:e})=>e.id))]))}return n}function Fn(e,t){let n=e.model?.pin;if(t!==void 0&&n?.[t]!==void 0)return`pin ${t}: ${n[t]}`;let r=n&&t===void 0?Object.keys(n).sort().map(e=>`${e}: ${n[e]}`):[];return[e.model?`tier ${e.model.tier}`:`the session default`,...r.map(e=>`pin ${e}`)].join(`, `)}function In(e){let n=new Set((e.doc.loops??[]).flatMap(e=>e.back??[])),r=An(e).filter(e=>Ge(e)&&!L(e)),i=e.doc.target?.harness,a=typeof i==`string`&&i.trim()!==``?i:void 0,o=[];for(let t of An(e).filter(e=>We(e)&&!L(e))){let i=Ln(e,t.id,n),s=r.filter(e=>e.id!==t.id&&i.has(e.id));if(s.length===0)continue;let c=Fn(t,a);s.every(e=>Fn(e,a)===c)&&o.push({critic:t,writers:s})}return o.length===0?[]:[t(`W_HOMOGENEOUS_CRITICS`,`${o.map(({critic:e,writers:t})=>`critic "${e.id}" judges ${jn(t.map(e=>e.id))} on the same model (${Fn(e,a)})`).join(`; `)}; a critic on a different tier or pin may catch different mistakes`,je(e,new Set(o.flatMap(({critic:e,writers:t})=>[e.id,...t.map(e=>e.id)]))))]}function Ln(e,t,n){let r=new Set([t]),i=new Set,a=[t];for(;a.length>0;){let t=a.shift();for(let o of e.incoming.get(t)??[]){if(n.has(o.id)||r.has(o.from))continue;r.add(o.from);let t=e.nodes.get(o.from);t&&Ge(t)?i.add(o.from):a.push(o.from)}}return i}function Rn(e){let n=[],r=(t,n=new Set)=>n.has(t)?[]:(n.add(t),(e.groups.get(t)?.members??[]).flatMap(t=>e.groups.has(t)?r(t,n):[t]));for(let i of e.doc.edges??[])if(!((i.concurrency?.max??1)<=1)){e.nodes.get(i.to)?.coupled===!0&&n.push(t(`W_FANOUT_ON_COUPLED`,`edge "${i.id}" fans out up to ${i.concurrency.max} at a time into "${i.to}", which is marked coupled; coupled work should run one at a time`,[i.id,i.to]));for(let a of e.doc.groups??[])a.coupled===!0&&r(a.id).includes(i.to)&&n.push(t(`W_FANOUT_ON_COUPLED`,`edge "${i.id}" fans out up to ${i.concurrency.max} at a time into "${i.to}", a member of coupled group "${a.id}"; coupled work should run one at a time`,[i.id,i.to,a.id]))}let i=new Map;for(let t of An(e))if(t.coupled===!0)for(let e of new Set(t.owns??[]))i.set(e,[...i.get(e)??[],t.id]);for(let[e,r]of i)r.length<2||n.push(t(`W_FANOUT_ON_COUPLED`,`coupled nodes ${jn(r)} both own "${e}"; coupled work on one artifact belongs in one node`,r));return n}function zn(e){let n=[];for(let r of e.doc.loops??[]){let e=r.stops??[];if(e.some(e=>e.kind===`budget`))continue;let i=e.flatMap(e=>e.kind===`max-iterations`?[e.n]:[]);i.some(e=>e<=5)||n.push(t(`W_LONG_LOOP_NO_BUDGET`,`loop "${r.id}" has no budget stop and ${i.length===0?`no max-iterations stop`:`its max-iterations stop allows ${Math.min(...i)} rounds`}; add a budget stop, or cap it at 5 rounds or fewer`,[r.id]))}return n}var Bn=(e,t)=>e.trim().replace(/\s+/g,` `).toLowerCase()===t.trim().replace(/\s+/g,` `).toLowerCase();function Vn(e){let n=[];for(let r of e.doc.loops??[]){let e=r.bar,i=e?.aspiration??``;if(!e||i.trim()===``)continue;let a=e.acceptance??``;a.trim()===``?n.push(t(`W_ASPIRATION_AS_ACCEPTANCE`,`loop "${r.id}" has an aspiration but a blank acceptance, so nothing says when the bar is met; write a reachable acceptance and keep the aspiration as direction`,[r.id])):Bn(i,a)&&n.push(t(`W_ASPIRATION_AS_ACCEPTANCE`,`loop "${r.id}" uses its aspiration as its acceptance; the acceptance must be reachable, the aspiration is only direction`,[r.id]))}return n}function Hn(e){return(e.doc.loops??[]).filter(e=>(e.stops??[]).length>0&&(e.stops??[]).every(e=>e.kind===`max-iterations`)).map(e=>t(`W_ONLY_MAX_ITERATIONS`,`loop "${e.id}" stops only on max-iterations, which is a safety backstop, not a definition of done; add a bar-passed, budget or human stop`,[e.id]))}function Un(e){let n=nt(e),r=it(e,n);return(e.doc.nodes??[]).filter(e=>!r.has(e.id)).map(e=>t(`W_UNREACHABLE_NODE`,n.length===0?`node "${e.id}" is not reachable: the graph has no entry node (every node has an inbound edge that is not a loop back edge, or a loop's stop that continues there)`:`node "${e.id}" is not reachable from any entry node (${jn(n)}); connect it or remove it`,[e.id]))}function Wn(e){let n=e.doc.nodes??[];if(n.length===0||e.doc.template?.kind===`fragment`)return[];let r=it(e,nt(e));return n.some(e=>e.kind===`stop`&&r.has(e.id))?[]:[t(`W_NO_TERMINAL`,n.some(e=>e.kind===`stop`)?`no stop node is reachable from an entry node, so the run ends only when no edge is left to take; connect a stop node`:`the graph has no stop node, so the run ends only when no edge is left to take; add one where the work is done`,[e.doc.id])]}function Gn(e){return An(e).filter(e=>e.role!==`lead`&&!L(e)&&(e.outputs??[]).length>0).filter(e=>!(e.allow??[]).some(e=>e===`edit-files`||e===`write-outputs`)).map(e=>t(`W_OUTPUT_NOT_WRITABLE`,`agent "${e.id}" must leave outputs behind but is allowed neither edit-files nor write-outputs, so it cannot write them itself; allow write-outputs`,[e.id]))}function Kn(e){return An(e).filter(L).flatMap(e=>{let n=[`model`,`effort`,`skills`,`allow`,`deny`].filter(t=>e[t]!==void 0&&!(Array.isArray(e[t])&&e[t].length===0));return n.length===0?[]:[t(`W_PERSON_FIELDS_NOT_READ`,`step "${e.id}" is a person's and sets ${n.join(`, `)}: ${n.length===1?`that is`:`those are`} an agent's, and ${n.length===1?`is`:`are`} not read; remove ${n.length===1?`it`:`them`}`,[e.id])]})}function qn(e){let n=e.doc.groups??[],r=(t,n,i=new Set)=>!i.has(t.id)&&(i.add(t.id),Sn(e,t).some(e=>e.id===n||r(e,n,i))),i=new Map;for(let e of n)for(let t of new Set(e.members??[]))t!==e.id&&i.set(t,[...i.get(t)??[],e]);let a=[];for(let[n,o]of i){let i=o.filter(e=>!o.some(t=>t.id!==e.id&&r(e,t.id)));if(i.length<2)continue;let s=e.groups.has(n)?`group`:`node`,c=i.map(e=>`"${e.id}"`);a.push(t(`W_GROUP_OVERLAP`,`${s} "${n}" is a member of groups ${c.slice(0,-1).join(`, `)} and ${c.at(-1)}, and ${c.length===2?`neither holds the other`:`none of them holds another`}; views draw it in "${i[0].id}"`,[n,...i.map(e=>e.id)]))}return a}function Jn(e){let n=[];return xe.unknownKeys(e.doc,``,n),n.map(({path:n,key:r,known:i})=>{let a=Te(e.doc,n.slice(0,n.lastIndexOf(`/`)));return t(`W_UNKNOWN_KEY`,`unknown key "${r}" at ${n}${R(r,i)}; it is kept, but grooph does not read it`,a.length>0?a:[e.doc.id])})}function Yn(e){let n=De(e.doc).length;return n<=24e3?[]:[t(`W_DOC_TOO_LARGE`,`canonical document without layout is ${n} characters, over the ${gn}-character budget for rewriting in one pass; split it or shorten the briefs`,[e.doc.id])]}var Xn={setGraphName:[`name`],setGraphField:[`key`,`value`],setTarget:[`harness`],setConstraint:[`key`,`value`],addNode:[`kind`,`name`,`id`,`at`,`set`],setNodeName:[`id`,`name`],updateNode:[`id`,`set`],removeNode:[`id`],connect:[`from`,`to`,`id`,`set`],updateEdge:[`id`,`set`],removeEdge:[`id`],addLoop:[`members`,`name`,`id`,`set`],setLoopName:[`id`,`name`],updateLoop:[`id`,`set`],removeLoop:[`id`],toggleLoopMember:[`loop`,`node`,`on`],toggleLoopBack:[`loop`,`edge`,`on`],setBar:[`loop`,`bar`],addStop:[`loop`,`kind`,`set`],setStop:[`loop`,`index`,`stop`],removeStop:[`loop`,`index`],moveStop:[`loop`,`index`,`delta`],addPolicy:[`kind`,`scope`,`params`,`id`],removePolicy:[`id`],setPositions:[`positions`],renameId:[`from`,`to`]},Zn=Object.keys(Xn),Qn=[`name`,`goal`,`description`,`adaptation`,`lineage`],$n=[`budget`,`time`,`other`],er=[`adaptive`,`propose`,`fixed`],tr=[`human`,`budget`,`bar-passed`,`diminishing-returns`,`evidence-invalid`,`max-iterations`],nr=Object.keys(pt),rr=/^(graph|loop:[a-z][a-z0-9-]*|node:[a-z][a-z0-9-]*|edge:[a-z][a-z0-9-]*)$/;function ir(e,t){let n=e,r=[];for(let[e,i]of t.entries()){let t=sr(i)&&typeof i.op==`string`?i.op:`?`;try{let e=cr(n,i);n=e.doc,r.push(e.id??null)}catch(n){if(n instanceof or)return{ok:!1,error:{index:e,op:t,message:n.message}};throw n}}return{ok:!0,doc:n,ids:r}}var ar=e=>`ops[${e.index}] ${e.op}: ${e.message}`,or=class extends Error{},B=e=>{throw new or(e)},sr=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function cr(e,t){if(!sr(t))return B(`an op must be an object like {"op": "addNode", ...}, got ${JSON.stringify(t)}`);let n=t.op;if(typeof n!=`string`)return B(`missing "op": the op's name, one of ${Zn.join(`, `)}`);if(!(n in Xn))return B(`unknown op "${n}"${R(n,Zn)}`);let r=new dr(e,t,Xn[n]);switch(n){case`setGraphName`:{let t=St(e,r.str(`name`));return{doc:t,id:t.id}}case`setGraphField`:{let t=r.oneOf(`key`,Qn);return r.raw(`value`)==null?{doc:yt(e,t,void 0)}:t===`adaptation`?{doc:yt(e,t,r.oneOf(`value`,er))}:t===`lineage`?{doc:yt(e,t,r.obj(`value`))}:{doc:yt(e,t,r.str(`value`))}}case`setTarget`:return{doc:bt(e,r.nullableStr(`harness`))};case`setConstraint`:return{doc:xt(e,r.oneOf(`key`,$n),r.nullableStr(`value`))};case`addNode`:{let t=wt(e,r.oneOf(`kind`,nr),{at:r.optPosition(`at`),name:r.optStr(`name`),id:r.optNewId(`id`)}),n=r.optPatch(`set`,[`id`,`kind`]);return{doc:n?Tt(t.doc,t.id,e=>lr(e,n)):t.doc,id:t.id}}case`setNodeName`:return Et(e,r.node(`id`),r.str(`name`));case`updateNode`:{let t=r.node(`id`),n=r.patch(`set`,[`id`,`kind`]);return{doc:Tt(e,t,e=>lr(e,n))}}case`removeNode`:return{doc:Dt(e,r.node(`id`))};case`connect`:{let t=kt(e,r.node(`from`),r.node(`to`),{id:r.optNewId(`id`)}),n=r.optPatch(`set`,[`id`]);return{doc:n?At(t.doc,t.id,e=>lr(e,n)):t.doc,id:t.id}}case`updateEdge`:{let t=r.edge(`id`),n=r.patch(`set`,[`id`]);return{doc:At(e,t,e=>lr(e,n))}}case`removeEdge`:return{doc:jt(e,r.edge(`id`))};case`addLoop`:{let t=Mt(e,r.optList(`members`,(e,t)=>r.existingNode(e,t))??[],{name:r.optStr(`name`),id:r.optNewId(`id`)}),n=r.optPatch(`set`,[`id`]);return{doc:n?Nt(t.doc,t.id,e=>lr(e,n)):t.doc,id:t.id}}case`setLoopName`:return Pt(e,r.loop(`id`),r.str(`name`));case`updateLoop`:{let t=r.loop(`id`),n=r.patch(`set`,[`id`]);return{doc:Nt(e,t,e=>lr(e,n))}}case`removeLoop`:return{doc:Ft(e,r.loop(`id`))};case`toggleLoopMember`:return{doc:Lt(e,r.loop(`loop`),r.node(`node`),r.optBool(`on`))};case`toggleLoopBack`:return{doc:Rt(e,r.loop(`loop`),r.edge(`edge`),r.optBool(`on`))};case`setBar`:return{doc:zt(e,r.loop(`loop`),r.raw(`bar`)==null?void 0:r.obj(`bar`))};case`addStop`:return{doc:Vt(e,r.loop(`loop`),r.oneOf(`kind`,tr),ur(r.optPatch(`set`,[`kind`])??{}))};case`setStop`:{let t=r.loop(`loop`),n=r.stopIndex(t,`index`),i=r.obj(`stop`);return tr.includes(i.kind)||B(`"stop.kind" must be one of ${tr.join(` | `)}, got ${JSON.stringify(i.kind)}`),{doc:Ht(e,t,n,i)}}case`removeStop`:{let t=r.loop(`loop`);return{doc:Ut(e,t,r.stopIndex(t,`index`))}}case`moveStop`:{let t=r.loop(`loop`),n=r.stopIndex(t,`index`),i=r.raw(`delta`);return i!==-1&&i!==1&&B(`"delta" must be -1 (earlier) or 1 (later), got ${JSON.stringify(i)}`),{doc:Wt(e,t,n,i)}}case`addPolicy`:{let t=r.raw(`kind`),n=typeof t==`string`&&t!==``?t:sr(t)&&typeof t.custom==`string`?{custom:t.custom}:B(`"kind" must be a policy kind (for example "critic-isolation") or {"custom": "..."}, got ${JSON.stringify(t)}`),i=r.str(`scope`);rr.test(i)||B(`"scope" must be graph, loop:<id>, node:<id> or edge:<id>, got ${JSON.stringify(i)}`);let a=r.raw(`params`)===void 0?void 0:r.obj(`params`);return Gt(e,{kind:n,scope:i,id:r.optNewId(`id`),...a?{params:a}:{}})}case`removePolicy`:return{doc:Kt(e,r.policy(`id`))};case`setPositions`:{let t=r.obj(`positions`),n={};for(let[e,i]of Object.entries(t))r.existingNode(e,`positions key`),n[e]=r.position(i,`positions.${e}`);return{doc:qt(e,n)}}case`renameId`:{let t=r.str(`from`),n=dt(e);for(let t of e.notes??[])n.delete(t.id);n.has(t)||B(`no object has id "${t}"${R(t,n)}`);let i=r.newId(`to`);return{doc:Jt(e,t,i),id:i}}default:return B(`unknown op "${n}"`)}}function lr(e,t){let n={...e};for(let[e,r]of Object.entries(t))r===null?delete n[e]:n[e]=r;return n}var ur=e=>Object.fromEntries(Object.entries(e).filter(([,e])=>e!==null)),dr=class{doc;op;constructor(e,t,n){this.doc=e,this.op=t;for(let e of Object.keys(t))e===`op`||n.includes(e)||B(`unknown argument "${e}"${R(e,n)}; this op takes ${n.map(e=>`"${e}"`).join(`, `)}`)}raw(e){return this.op[e]}str(e){let t=this.op[e];return typeof t!=`string`&&B(`"${e}" must be a string, got ${fr(t)}`),t}optStr(e){return this.op[e]===void 0?void 0:this.str(e)}nullableStr(e){return this.op[e]==null?void 0:this.str(e)}optBool(e){let t=this.op[e];if(t!==void 0)return typeof t!=`boolean`&&B(`"${e}" must be true or false, got ${fr(t)}`),t}oneOf(e,t){let n=this.op[e];return(typeof n!=`string`||!t.includes(n))&&B(`"${e}" must be one of ${t.join(` | `)}, got ${fr(n)}${typeof n==`string`?R(n,t):``}`),n}obj(e){let t=this.op[e];sr(t)||B(`"${e}" must be an object, got ${fr(t)}`);for(let n of[`__proto__`,`constructor`,`prototype`])Object.hasOwn(t,n)&&B(`"${e}" cannot hold the key "${n}"`);return t}optList(e,t){let n=this.op[e];if(n!==void 0)return Array.isArray(n)?n.map((n,r)=>t(n,`${e}[${r}]`)):B(`"${e}" must be a list, got ${fr(n)}`)}patch(e,t){let n=this.obj(e);for(let r of t)r in n&&B(r===`id`?`"${e}" cannot change the id; use renameId, which updates every reference`:`"${e}" cannot change "${r}"; remove the object and add a new one`);return n}optPatch(e,t){return this.op[e]===void 0?void 0:this.patch(e,t)}position(e,t){(!sr(e)||typeof e.x!=`number`||typeof e.y!=`number`)&&B(`"${t}" must be {"x": number, "y": number}, got ${fr(e)}`);let{x:n,y:r}=e;return{x:n,y:r}}optPosition(e){return this.op[e]===void 0?void 0:this.position(this.op[e],e)}newId(e){let t=this.str(e);return m.test(t)||B(`"${e}" must be a kebab-case id (${m.source}), got ${JSON.stringify(t)}`),dt(this.doc).has(t)&&B(`"${e}": id "${t}" is already used in this document`),t}optNewId(e){return this.op[e]===void 0?void 0:this.newId(e)}existingNode(e,t){if(typeof e!=`string`)return B(`"${t}" must be a node id, got ${fr(e)}`);let n=this.doc.nodes.map(e=>e.id);return n.includes(e)||B(`"${t}": no node "${e}"${R(e,n)}`),e}node(e){return this.existingNode(this.op[e],e)}edge(e){return this.existing(e,`edge`,this.doc.edges.map(e=>e.id))}loop(e){return this.existing(e,`loop`,this.doc.loops.map(e=>e.id))}policy(e){return this.existing(e,`policy`,(this.doc.policies??[]).map(e=>e.id))}stopIndex(e,t){let n=this.op[t],r=this.doc.loops.find(t=>t.id===e)?.stops??[];return(typeof n!=`number`||!Number.isInteger(n)||n<0||n>=r.length)&&B(r.length===0?`loop "${e}" has no stops yet`:`"${t}" must be a stop index from 0 to ${r.length-1} in loop "${e}", got ${fr(n)}`),n}existing(e,t,n){let r=this.str(e);return n.includes(r)||B(`"${e}": no ${t} "${r}"${R(r,n)}`),r}},fr=e=>e===void 0?`nothing`:Array.isArray(e)?`a list`:JSON.stringify(e),pr=()=>g({integer:!0,minimum:0}),mr=A({agents:pr(),people:f(pr()),checks:pr(),gates:pr(),loops:pr(),tiers:A({frontier:pr(),strong:pr(),fast:pr(),unset:pr()}),worstCaseRounds:N([pr(),v()],{describe:`integer or null`}),budgets:T(p())},{name:`Shape`}),hr=M(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`file`in e&&!(`grooph`in e),A({file:p({minLength:1})},{name:`CandidateFile`}),y(xe,Se),{describe:`graph document or { file }`}),gr=A({id:h(),label:p({minLength:1}),graph:hr,basedOn:f(p()),rationale:p(),pros:T(p()),cons:T(p()),profile:ve,shape:f(mr)},{name:`Candidate`}),_r=A({groophProposals:b(0),id:h(),title:p(),brief:p(),candidates:T(gr,{minItems:1,maxItems:4}),recommendation:f(A({candidate:h(),why:p()}))},{describe:`proposal set`}),vr=(e,t,n,r=[])=>({code:e,severity:t,message:n,at:r});function yr(e){let t=typeof e==`object`&&e&&Array.isArray(e.candidates)?e.candidates:[];for(let[e,n]of t.slice(0,16).entries()){let t=s(typeof n==`object`&&n?n.graph:void 0,`graph`);if(t)return{issues:[vr(`E_SCHEMA`,`error`,`/candidates/${e}/graph${t.path}: ${t.message}`,[])]}}let n=[];return _r.check(e,``,n),n.length>0?{issues:n.map(t=>vr(`E_SCHEMA`,`error`,`${t.path===``?`/`:t.path}: ${t.message}`,Te(e,t.path)))}:{set:e,issues:[]}}var br=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`groophProposals`in e,xr=e=>!(`grooph`in e)&&`file`in e;function Sr(e,t={}){let n=yr(e);if(!n.set)return n.issues;let r=e.candidates,i=[],a=new Map;a.set(e.id,[`the set's own id`]),r.forEach((e,t)=>a.set(e.id,[...a.get(e.id)??[],`candidates[${t}]`]));for(let[e,t]of a)t.length>1&&i.push(vr(`E_DUPLICATE_ID`,`error`,`id "${e}" is used ${t.length} times: ${t.join(`, `)}`,[e]));let o=new Map;for(let e of r){let t=Cr(e.label);o.set(t,[...o.get(t)??[],e])}for(let e of o.values())e.length<2||i.push(vr(`E_DUPLICATE_LABEL`,`error`,`candidates ${e.map(e=>`"${e.id}"`).join(`, `)} share the label "${e[0].label}"; labels are what the owner says back, so each must differ (case is ignored)`,e.map(e=>e.id)));let s=e.recommendation?.candidate;s!==void 0&&!r.some(e=>e.id===s)&&i.push(vr(`E_DANGLING_REF`,`error`,`the recommendation names candidate "${s}", which is not in the set${R(s,r.map(e=>e.id))}`,[e.id]));for(let e of r){if(xr(e.graph)){t.requireInline&&i.push(vr(`E_CANDIDATE_INVALID`,`error`,`candidate "${e.id}" (${e.label}) points at ${e.graph.file} instead of carrying its graph; grooph share inlines it`,[e.id]));continue}let n=_n(e.graph).filter(e=>e.severity===`error`);if(n.length===0)continue;let r=[...new Set(n.map(e=>e.code))];i.push(vr(`E_CANDIDATE_INVALID`,`error`,`candidate "${e.id}" (${e.label}) has errors: ${r.join(`, `)}. First: ${n[0].message}. Fix its graph and run grooph validate on it`,[e.id]))}let c=[];_r.unknownKeys(e,``,c);for(let{path:t,key:n,known:r}of c.filter(e=>!/^\/candidates\/\d+\/graph\//.test(e.path))){let a=Te(e,t.slice(0,t.lastIndexOf(`/`)));i.push(vr(`W_UNKNOWN_KEY`,`warning`,`unknown key "${n}" at ${t}${R(n,r)}; it is kept, but grooph does not read it`,a.length>0?a:[e.id]))}return i}var Cr=e=>e.trim().replace(/\s+/g,` `).toLowerCase(),wr=e=>{let t=(e.stops??[]).flatMap(e=>e.kind===`max-iterations`?[e.n]:[]);return t.length===0?void 0:Math.min(...t)};function Tr(e){let t=e.nodes??[],n=e.loops??[],r={frontier:0,strong:0,fast:0,unset:0};for(let e of t)e.kind===`agent`&&!L(e)&&(r[e.model?.tier??`unset`]+=1);let i=n.map(wr),a=null;if(i.every(e=>e!==void 0)){let e=n.map(e=>new Set(e.members??[])),t=(t,n)=>t!==n&&e[n].size<e[t].size&&[...e[n]].every(n=>e[t].has(n));a=i.reduce((e,n,r)=>e+i.reduce((e,n,i)=>t(i,r)?e*n:e,n),0)}let o=n.filter(e=>(e.stops??[]).some(e=>e.kind===`budget`)),s=o.flatMap(e=>(e.stops??[]).flatMap(t=>t.kind===`budget`?[`${o.length>1?`${e.name||e.id}: `:``}${Er(t.measure,t.limit)}`]:[]));return{agents:t.filter(e=>e.kind===`agent`&&!L(e)).length,...t.some(L)?{people:t.filter(L).length}:{},checks:t.filter(e=>e.kind===`check`).length,gates:t.filter(e=>e.kind===`human-gate`).length+(e.edges??[]).filter(e=>e.approval===!0).length,loops:n.length,tiers:r,worstCaseRounds:a,budgets:s}}var Er=(e,t)=>e===`usd`?`$${t}`:`${t} ${e}`,Dr=(e,t,n=`${t}s`)=>`${e} ${e===1?t:n}`;function Or(e){let t=e.people??0,n=t===0?[Dr(e.agents,`agent`)]:[t===1?`1 person's step`:`${t} people's steps`,...e.agents>0?[e.agents===1?`1 agent's step`:`${e.agents} agents' steps`]:[]];return e.checks>0&&n.push(Dr(e.checks,`check`)),e.gates>0&&n.push(Dr(e.gates,`gate`)),e.loops===0?n.push(`no loop`):(n.push(Dr(e.loops,`loop`)),n.push(e.worstCaseRounds===null?`no round cap`:`up to ${Dr(e.worstCaseRounds,`round`)}`)),n.push(...e.budgets),n.join(` · `)}function kr(e){return[`frontier`,`strong`,`fast`,`unset`].filter(t=>e.tiers[t]>0).map(t=>`${e.tiers[t]} ${t===`unset`?`session default`:t}`).join(` · `)}var Ar=A({id:h(),name:p(),machine:p({minLength:1}),place:f(x(`local`,`cloud`)),account:p({minLength:1}),description:f(p())},{name:`Lane`}),jr=A({id:h(),name:p(),role:f(p()),description:f(p())},{name:`Person`}),Mr=A({id:h(),name:p(),lane:h(),harness:w([`claude-code`,`codex`],`harness id`),model:f(p()),role:p({minLength:1}),lifetime:f(x(`long-lived`,`per-task`,`scheduled`)),count:f(g({integer:!0,minimum:1})),graph:f(p({minLength:1})),repo:f(p()),description:f(p())},{name:`Session`}),Nr=e=>b(e),Pr=j(`kind`,{branch:A({kind:Nr(`branch`),repo:f(p()),ref:f(p())}),"pull-request":A({kind:Nr(`pull-request`),repo:f(p())}),"session-message":A({kind:Nr(`session-message`)}),"scheduled-message":A({kind:Nr(`scheduled-message`),schedule:f(p())}),"review-page":A({kind:Nr(`review-page`),where:f(p())}),person:A({kind:Nr(`person`),who:f(p())}),notification:A({kind:Nr(`notification`),where:f(p())}),other:A({kind:Nr(`other`),name:f(p())})},{name:`Carrier`,label:`carrier`}),Fr=A({id:h(),from:h(),to:h(),carrier:f(Pr),what:f(p()),label:f(p())},{name:`Handoff`}),Ir=A({groophMap:b(0),id:h(),name:p(),version:g({integer:!0,minimum:0}),asOf:f(p({pattern:/^\d{4}-\d{2}-\d{2}$/,patternName:`date as YYYY-MM-DD`})),description:f(p()),lanes:T(Ar),people:f(T(jr)),sessions:T(Mr),handoffs:T(Fr)},{describe:`operation map`}),V=(e,t,n=[])=>({code:e,severity:e.startsWith(`E_`)?`error`:`warning`,message:t,at:n});function Lr(e){let t=s(e,`map`);if(t)return{issues:[V(`E_SCHEMA`,`${t.path}: ${t.message}`,[])]};let n=[];return Ir.check(e,``,n),n.length>0?{issues:n.map(t=>V(`E_SCHEMA`,`${t.path===``?`/`:t.path}: ${t.message}`,Te(e,t.path)))}:{map:e,issues:[]}}var Rr=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`groophMap`in e;function zr(e){return`${JSON.stringify(Ir.canon(e),null,2)}\n`}var Br={branch:`branch`,"pull-request":`pull request`,"session-message":`session message`,"scheduled-message":`scheduled message`,"review-page":`review page`,person:`person`,notification:`notification`,other:`other`},Vr=e=>e===void 0||e.trim()===``;function Hr(e){switch(e.kind){case`branch`:case`pull-request`:return{field:`repo`,value:e.repo};case`review-page`:return{field:`where`,value:e.where};case`person`:return{field:`who`,value:e.who};case`other`:return{field:`name`,value:e.name};case`session-message`:case`scheduled-message`:case`notification`:return{}}}function Ur(e,t){if(!e)return``;switch(e.kind){case`branch`:return Vr(e.repo)?``:`branch ${Vr(e.ref)?``:`${e.ref} `}on ${e.repo}`;case`pull-request`:return Vr(e.repo)?``:`pull request on ${e.repo}`;case`session-message`:return`session message`;case`scheduled-message`:return Vr(e.schedule)?`scheduled message`:`scheduled message, ${e.schedule}`;case`review-page`:return Vr(e.where)?``:`review page: ${e.where}`;case`person`:return Vr(e.who)?Vr(t)?``:`carried by ${t}`:`carried by ${e.who}`;case`notification`:return Vr(e.where)?`notification`:`notification, ${e.where}`;case`other`:return Vr(e.name)?``:e.name}}function Wr(e,t={}){let n=Lr(e);if(!n.map)return n.issues;let r=new Map(e.lanes.map(e=>[e.id,e])),i=new Map(e.sessions.map(e=>[e.id,e])),a=new Map((e.people??[]).map(e=>[e.id,e])),o=[],s=new Map,c=(e,t)=>s.set(e,[...s.get(e)??[],t]);c(e.id,`the map's own id`),e.lanes.forEach((e,t)=>c(e.id,`lanes[${t}]`)),(e.people??[]).forEach((e,t)=>c(e.id,`people[${t}]`)),e.sessions.forEach((e,t)=>c(e.id,`sessions[${t}]`)),e.handoffs.forEach((e,t)=>c(e.id,`handoffs[${t}]`));for(let[e,t]of s)t.length>1&&o.push(V(`E_DUPLICATE_ID`,`id "${e}" is used ${t.length} times: ${t.join(`, `)}`,[e]));for(let t of e.sessions)r.has(t.lane)||o.push(V(`E_DANGLING_REF`,`session "${t.id}" is in unknown lane "${t.lane}"${R(t.lane,[...r.keys()])}`,[t.id]));for(let t of e.handoffs)for(let[e,n]of[[`starts at`,t.from],[`ends at`,t.to]])if(!i.has(n)&&!a.has(n)){let r=a.size>0?`"${n}", which is neither a session nor a person`:`unknown session "${n}"`;o.push(V(`E_DANGLING_REF`,`handoff "${t.id}" ${e} ${r}${R(n,[...i.keys(),...a.keys()])}`,[t.id]))}for(let t of e.handoffs){let e=`"${t.from}" → "${t.to}"`;if(!t.carrier){o.push(V(`E_HANDOFF_NO_CARRIER`,`handoff "${t.id}" (${e}) names no carrier; say what moves the work across: a branch, a pull-request, a session-message, a scheduled-message, a review-page, a person, or other`,[t.id]));continue}let n=Hr(t.carrier);t.carrier.kind===`person`&&a.has(t.from)||n.field!==void 0&&Vr(n.value)&&o.push(V(`E_HANDOFF_NO_CARRIER`,`handoff "${t.id}" (${e}) is carried by a ${Br[t.carrier.kind]} that is not named; set carrier.${n.field}`,[t.id]))}for(let t of e.handoffs){let e=i.get(t.from),n=i.get(t.to);if(!t.carrier||!e||!n)continue;let a=r.get(e.lane),s=r.get(n.lane),c=a&&s&&a.account!==s.account?`accounts "${a.account}" and "${s.account}"`:void 0,l=e.harness===n.harness?void 0:`harnesses "${e.harness}" and "${n.harness}"`,u=t.carrier.kind,d=u===`session-message`||u===`scheduled-message`,f=d?c??l:u===`review-page`?c:void 0;if(f===void 0)continue;let p=d?`a ${Br[u]} stays inside one harness and one account`:`a published page belongs to the account that published it`;o.push(V(`W_CARRIER_CANNOT_CROSS`,`handoff "${t.id}" ("${t.from}" → "${t.to}") crosses ${f} by ${Br[u]}; ${p}, so something else carries this: a branch, a pull request, or a person`,[t.id,t.from,t.to]))}for(let t of e.handoffs)t.carrier?.kind===`notification`&&i.has(t.to)&&o.push(V(`W_NOTIFY_NOT_PERSON`,`handoff "${t.id}" sends a notification to session "${t.to}"; a notification reaches a person, and a session is reached by a message, a branch or a pull request. Name the person it reaches, or the carrier that reaches the session`,[t.id,t.to]));let l=new Set(e.handoffs.map(e=>e.from)),u=new Set(e.handoffs.map(e=>e.to));for(let t of e.sessions)!l.has(t.id)&&!u.has(t.id)&&o.push(V(`W_SESSION_ISLAND`,`session "${t.id}" has no handoff in or out: nothing reaches it and it reaches nothing`,[t.id]));let d=new Set(e.handoffs.filter(e=>e.from!==e.to).flatMap(e=>[e.from,e.to]));for(let t of e.people??[])d.has(t.id)||o.push(V(`W_SESSION_ISLAND`,`person "${t.id}" has no handoff in or out: nothing reaches them and they reach nothing`,[t.id]));for(let t of e.sessions)u.has(t.id)&&!l.has(t.id)&&o.push(V(`W_NO_RETURN`,`session "${t.id}" is handed work and hands nothing on: add the handoff its results leave by, and name the carrier`,[t.id]));if(t.resolveGraph)for(let n of e.sessions)n.graph!==void 0&&t.resolveGraph(n.graph,n)===!1&&o.push(V(`W_GRAPH_UNRESOLVED`,`session "${n.id}" points at graph "${n.graph}", which is not a graph document that could be read`,[n.id]));let f=[];Ir.unknownKeys(e,``,f);for(let t of f)o.push(V(`W_UNKNOWN_KEY`,`${t.path===``?`/`:t.path}: unknown key "${t.key}"${R(t.key,t.known)}`,Te(e,t.path)));let p=zr(e).length;return p>24e3&&o.push(V(`W_DOC_TOO_LARGE`,`the map is ${p.toLocaleString(`en`)} characters in canonical form, over the ${gn.toLocaleString(`en`)} a model rewrites in one pass; draw families as one session with a count, or split the map`,[e.id])),o}function Gr(e){let t=new Map(e.sessions.map(e=>[e.id,e])),n=new Map((e.people??[]).map(e=>[e.id,e])),r=e=>{let t=new Map;for(let[n,r]of e)t.set(n,(t.get(n)??0)+r);return Object.fromEntries(t)},i=r(e.handoffs.map(e=>[e.carrier?.kind??`none`,1])),a=r(e.sessions.map(e=>[e.harness,e.count??1]));return{lanes:e.lanes.length,sessions:e.sessions.length,sessionsCounted:e.sessions.reduce((e,t)=>e+(t.count??1),0),handoffs:e.handoffs.length,carriers:i,harnesses:a,crossLane:e.handoffs.filter(e=>{let n=t.get(e.from),r=t.get(e.to);return n!==void 0&&r!==void 0&&n.lane!==r.lane}).length,byHand:e.handoffs.flatMap(e=>{if(e.from===e.to&&n.has(e.from))return[];let t=n.get(e.from);return t?[{handoff:e.id,from:e.from,to:e.to,who:t.name||t.id,starts:!0}]:e.carrier?.kind===`person`?[{handoff:e.id,from:e.from,to:e.to,who:e.carrier.who??``}]:[]}),...n.size>0?{people:n.size}:{}}}function Kr(e){let t=(e,t)=>`${e} ${t}${e===1?``:`s`}`,n=e.sessionsCounted===e.sessions?``:` (${e.sessionsCounted} counting families)`,r=e.byHand.length,i=e.people?` · ${e.people} ${e.people===1?`person`:`people`}`:``,a=e.byHand.some(e=>e.starts)?`waiting on a person`:`carried by a person`;return`${t(e.lanes,`lane`)} · ${t(e.sessions,`session`)}${n}${i} · ${t(e.handoffs,`handoff`)}${r>0?`, ${r} ${a}`:``}`}function qr(e,t){return e.sessions.find(e=>e.id===t)?.name||(e.people??[]).find(e=>e.id===t)?.name||t}var Jr=(e,t)=>(e.people??[]).find(e=>e.id===t.from);function Yr(e,t){let n=Jr(e,t);return Ur(t.carrier,n?n.name||n.id:void 0)}function Xr(e,t){let n=e.handoffs.find(e=>e.from===t&&e.to===t&&e.carrier?.kind===`scheduled-message`);return n?n.carrier?.kind===`scheduled-message`?n.carrier.schedule??``:``:void 0}function Zr(e,t){return{out:e.handoffs.filter(e=>e.from===t),in:e.handoffs.filter(e=>e.to===t)}}var Qr=()=>y(xe,Se),$r=A({groophRun:b(0),run:p({minLength:1}),progress:f(p()),source:Qr(),working:Qr(),notes:T(y(be,`${Se}#/$defs/RunNote`)),issues:f(T(A({line:g({integer:!0,minimum:1}),message:p()},{name:`RunNoteIssue`})))},{describe:`run bundle`}),ei={pass:`passed`,fail:`failed`,"invalid-evidence":`failed`,halt:`halted`},ti=e=>e.outcome===`started`||e.outcome===`ending`;function ni(e){if(e.outcome===`started`)return{kind:`started`};if(e.outcome!==`ending`){if(e.outcome!==void 0)return{kind:`result`,state:ei[e.outcome]??`passed`};if(e.ended!==void 0)return{kind:`result`,state:`passed`};if(e.started!==void 0)return{kind:`started`}}}var ri=e=>{if(e===`graph`)return{kind:`graph`};let t=e.indexOf(`:`);return{kind:e.slice(0,t),id:e.slice(t+1)}},ii=e=>e.at===`graph`&&e.outcome!==void 0&&!ti(e),ai=(e,t,n)=>Object.hasOwn(e,t)?e[t]:e[t]=n();function oi(e,t){let n={};for(let e of t.nodes)n[e.id]={state:`pending`,runs:0};let r={};for(let e of t.loops)r[e.id]={round:null};let i=new Set,a={},o=si(t);for(let s of e){s.cost&&(a[s.cost.measure]=(a[s.cost.measure]??0)+s.cost.amount);let e=ri(s.at);if(e.kind===`node`&&e.id!==void 0){let t=ai(n,e.id,()=>({state:`pending`,runs:0})),a=ni(s);if(a?.kind===`started`?(t.runs+=1,t.state=`running`,i.add(e.id)):a?.kind===`result`&&(i.delete(e.id)||(t.runs+=1),t.state=a.state),s.outcome!==void 0&&!ti(s)&&(t.lastOutcome=s.outcome),s.verdict!==void 0&&(t.lastVerdict=s.verdict),s.round!==void 0){t.round=s.round;let n=o.get(e.id);n!==void 0&&(r[n].round=s.round)}t.lastNote=s.id}else if(e.kind===`loop`&&e.id!==void 0){let n=ai(r,e.id,()=>({round:null}));if(s.round===void 0&&s.outcome===void 0)continue;s.round!==void 0&&(n.round=s.round);let i=t.loops.find(t=>t.id===e.id),a=i?ui(s,i):void 0;n.lastStop={note:s.id,...s.round===void 0?{}:{round:s.round},...s.outcome===void 0?{}:{outcome:s.outcome},...a?{fired:a}:{},...s.text===void 0?{}:{text:s.text}}}}let s=`running`,c,l=di(e,ii);if(l>=0){c=e[l];let t=c.outcome===`halt`&&e.slice(l+1).some(e=>e.at.startsWith(`node:`)&&ni(e)!==void 0);s=t?`running`:c.outcome===`halt`?`halted`:`ended`,t&&(c=void 0)}else i.size===0&&Object.values(n).some(e=>e.state===`halted`)&&(c=e[di(e,e=>e.at.startsWith(`node:`)&&e.outcome===`halt`)],s=`halted`);if(s!==`running`)for(let e of i)n[e].state=`halted`;let u=e.find(e=>e.started!==void 0)?.started,d=s===`running`?void 0:c?.ended;return{run:e[0]?.run??``,state:s,...s!==`running`&&c?.outcome!==void 0?{outcome:c.outcome}:{},...u===void 0?{}:{started:u},...d===void 0?{}:{ended:d},nodes:n,loops:r,amendments:e.filter(e=>e.amendment!==void 0),proposals:e.filter(e=>e.proposal!==void 0),cost:a,timeline:[...e]}}function si(e){let t=new Map;for(let n of e.nodes){let r;for(let t of e.loops)t.members.includes(n.id)&&(r===void 0||t.members.length<r.members.length)&&(r=t);r&&t.set(n.id,r.id)}return t}var ci=[[`bar-passed`,/\bbar[ -]pass(?:ed|es)\b/i],[`max-iterations`,/\bmax[ -]iterations?\b/i],[`budget`,/\bbudget\b/i],[`diminishing-returns`,/\bdiminishing\b/i],[`evidence-invalid`,/\bevidence[ -]invalid\b|\binvalid[ -]evidence\b/i],[`human`,/\bhuman (?:stop|halt)\b/i]],li=[`human`,`budget`,`bar-passed`,`diminishing-returns`,`evidence-invalid`,`max-iterations`];function ui(e,t){if(e.stop!==void 0)return li.includes(e.stop)?e.stop:void 0;if(e.outcome!==`pass`&&e.outcome!==`halt`)return;let n=e.text??``,r=new Set(t.stops.map(e=>e.kind)),i=ci.filter(([e,t])=>r.has(e)&&t.test(n)),a=i.filter(([,e])=>RegExp(`${e.source}[^.;]{0,40}?\\bfire`,`i`).test(n));if(a.length===1)return a[0][0];if(i.length===1)return i[0][0];if(e.outcome===`pass`&&r.has(`bar-passed`)&&i.length===0)return`bar-passed`}function di(e,t){for(let n=e.length-1;n>=0;n--)if(t(e[n]))return n;return-1}var fi=e=>e.outcome===void 0||e.state===`halted`&&e.outcome===`halt`?e.state:`${e.state} · ${e.outcome}`,pi=(e,t)=>JSON.stringify(mi(e))===JSON.stringify(mi(t)),mi=e=>{if(Array.isArray(e))return e.map(mi);if(typeof e==`object`&&e){let t={};for(let n of Object.keys(e).sort())e[n]!==void 0&&(t[n]=mi(e[n]));return t}return e};function hi(e,t,n){let r={},i=[],a=[...new Set([...Object.keys(e),...Object.keys(t)])].filter(e=>!n.includes(e));for(let n of a)pi(e[n],t[n])||(r[n]=t[n]===void 0?null:t[n],i.push({key:n,...e[n]===void 0?{}:{before:e[n]},...t[n]===void 0?{}:{after:t[n]}}));return{set:r,fields:i}}var gi={brief:`brief`,outputs:`outputs`,inputs:`inputs`,allow:`allowed capabilities`,deny:`denied capabilities`,owns:`owned artifacts`,irreversible:`irreversible actions`,model:`model`,effort:`effort`,role:`role`,name:`name`,description:`description`,prompt:`question`,options:`options`,check:`check`,merges:`merged artifacts`,strategy:`merge strategy`,outcome:`outcome`,coupled:`coupling`,when:`condition`,isolation:`isolation`,concurrency:`concurrency`,retry:`retries`,evidence:`evidence`,approval:`approval`,label:`label`,from:`start`,to:`end`,members:`members`,back:`back edges`,mode:`mode`,bar:`bar`,stops:`stops`},_i=e=>{let t=e.map(e=>gi[e]??e);return t.length<=1?t[0]??``:`${t.slice(0,-1).join(`, `)} and ${t[t.length-1]}`},vi={budget:`budget`,time:`time limit`,other:`other limits`},yi=[`name`,`goal`,`description`,`adaptation`,`lineage`],bi=e=>`${e.name||e.id} (${e.id})`,xi=(e,t)=>{let n=e=>t.nodes.find(t=>t.id===e)?.name||e;return`edge ${n(e.from)} → ${n(e.to)} (${e.id})`},Si=e=>`loop ${e.name||e.id} (${e.id})`,Ci=e=>typeof e.kind==`string`?e.kind:`custom "${e.kind.custom}"`;function wi(e,t){let n=[],r=[],i=[],a=[],o=[],s=[];e.id!==t.id&&n.push({line:`Renamed the graph id from ${e.id} to ${t.id}`,op:{op:`renameId`,from:e.id,to:t.id},at:`graph`,fields:[{key:`id`,before:e.id,after:t.id}]});for(let r of yi){if(pi(e[r],t[r]))continue;let i=e[r],a=t[r],o=r===`name`?`Renamed the graph from "${String(i??``)}" to "${String(a??``)}"`:r===`adaptation`?`Adaptation: ${String(i??`adaptive (default)`)} → ${String(a??`adaptive (default)`)}`:`${a===void 0?`Removed`:i===void 0?`Added`:`Changed`} the graph's ${r}`;n.push({line:o,op:{op:`setGraphField`,key:r,value:a??null},at:`graph`,fields:[{key:r,...i===void 0?{}:{before:i},...a===void 0?{}:{after:a}}]})}if(!pi(e.target,t.target)){let r=e.target?.harness,i=t.target?.harness;n.push({line:i===void 0?`Removed the target harness`:`Target harness: ${r??`none`} → ${i}`,op:{op:`setTarget`,harness:i??null},at:`graph`,fields:[{key:`target`,...r?{before:r}:{},...i?{after:i}:{}}]})}for(let r of[`budget`,`time`,`other`]){let i=e.constraints?.[r],a=t.constraints?.[r];if(i===a)continue;let o=a===void 0?`Removed`:i===void 0?`Added`:`Changed`;n.push({line:`${o} the graph's ${vi[r]} (constraints.${r})`,op:{op:`setConstraint`,key:r,value:a??null},at:`graph`,fields:[{key:`constraints.${r}`,...i===void 0?{}:{before:i},...a===void 0?{}:{after:a}}]})}pi(e.template,t.template)||s.push({line:`${t.template?`Changed`:`Removed`} the template block; no op expresses this`,at:`graph`,fields:[{key:`template`,before:e.template,after:t.template}]}),pi(e.groups,t.groups)||s.push({line:`Changed the groups; no op expresses this`,at:`graph`,fields:[{key:`groups`,before:e.groups,after:t.groups}]});let c=new Set([`grooph`,`id`,`name`,`version`,`goal`,`target`,`constraints`,`adaptation`,`lineage`,`template`,`description`,`nodes`,`edges`,`loops`,`policies`,`groups`,`notes`,`layout`]);for(let n of new Set([...Object.keys(e),...Object.keys(t)])){if(c.has(n))continue;let r=e[n],i=t[n];pi(r,i)||s.push({line:`Changed the unknown key "${n}"; no op expresses this`,at:`graph`,fields:[{key:n,before:r,after:i}]})}let l=new Map(e.nodes.map(e=>[e.id,e])),u=new Map(t.nodes.map(e=>[e.id,e]));for(let e of t.nodes){let t=l.get(e.id);if(!t){let{id:t,kind:n,name:i,...a}=e,o={...a};for(let r of Object.keys(Ct(n,t,i)))!(r in e)&&![`id`,`kind`,`name`].includes(r)&&(o[r]=null);r.push({line:`Added ${n} node ${bi(e)}`,op:{op:`addNode`,kind:n,id:t,name:i,...Object.keys(o).length>0?{set:o}:{}},at:t,fields:[]});continue}if(t.kind!==e.kind){s.push({line:`${bi(e)} changed kind from ${t.kind} to ${e.kind}; no op expresses this`,at:e.id,fields:[{key:`kind`,before:t.kind,after:e.kind}]});continue}let{set:n,fields:a}=hi(t,e,[`id`,`kind`]);a.length>0&&i.push({line:`Changed the ${_i(a.map(e=>e.key))} of ${bi(e)}`,op:{op:`updateNode`,id:e.id,set:n},at:e.id,fields:a})}for(let t of e.nodes)u.has(t.id)||o.push({line:`Removed node ${bi(t)}`,op:{op:`removeNode`,id:t.id},at:t.id,fields:[]});let d=new Map(e.edges.map(e=>[e.id,e])),f=new Map(t.edges.map(e=>[e.id,e]));for(let e of t.edges){let n=d.get(e.id);if(!n){let{id:n,from:i,to:a,...o}=e;r.push({line:`Added ${xi(e,t)}`,op:{op:`connect`,from:i,to:a,id:n,...Object.keys(o).length>0?{set:o}:{}},at:n,fields:[]});continue}let{set:a,fields:o}=hi(n,e,[`id`]);o.length>0&&i.push({line:`Changed the ${_i(o.map(e=>e.key))} of ${xi(e,t)}`,op:{op:`updateEdge`,id:e.id,set:a},at:e.id,fields:o})}for(let t of e.edges)f.has(t.id)||o.push({line:`Removed ${xi(t,e)}`,op:{op:`removeEdge`,id:t.id},at:t.id,fields:[]});let p=new Map(e.loops.map(e=>[e.id,e])),m=new Map(t.loops.map(e=>[e.id,e]));for(let e of t.loops){let t=p.get(e.id);if(!t){let{id:t,name:n,members:i,...a}=e;r.push({line:`Added ${Si(e)}`,op:{op:`addLoop`,members:i,name:n,id:t,set:a},at:t,fields:[]});continue}let{set:n,fields:a}=hi(t,e,[`id`]);a.length>0&&i.push({line:`Changed the ${_i(a.map(e=>e.key))} of ${Si(e)}`,op:{op:`updateLoop`,id:e.id,set:n},at:e.id,fields:a})}for(let t of e.loops)m.has(t.id)||o.push({line:`Removed ${Si(t)}`,op:{op:`removeLoop`,id:t.id},at:t.id,fields:[]});let h=new Map((e.policies??[]).map(e=>[e.id,e])),g=new Map((t.policies??[]).map(e=>[e.id,e]));for(let t of e.policies??[]){let e=g.get(t.id);e&&pi(e,t)||a.push({line:`${e?`Replaced`:`Removed`} policy ${Ci(t)} on ${t.scope} (${t.id})`,op:{op:`removePolicy`,id:t.id},at:t.id,fields:[]})}for(let e of t.policies??[]){let t=h.get(e.id);if(t&&pi(t,e))continue;let n={line:`${t?`Now`:`Added`} policy ${Ci(e)} on ${e.scope} (${e.id})`,op:{op:`addPolicy`,kind:e.kind,scope:e.scope,id:e.id,...e.params?{params:e.params}:{}},at:e.id,fields:[]};if(t){let r=a.find(t=>t.at===e.id);r.line=`Changed policy ${Ci(e)} on ${e.scope} (${e.id})`,r.fields=[{key:`policy`,before:t,after:e}],a.push({...n,line:``})}else a.push(n)}let _={removeLoop:0,removeEdge:1,removeNode:2};o.sort((e,t)=>(_[e.op.op]??0)-(_[t.op.op]??0));let v=[...n,...r,...i,...a,...o],y=v.map(e=>e.op),b=[...v,...s].filter(e=>e.line!==``),x=ir(e,y);return{changes:b,ops:y,exact:s.length===0&&x.ok&&Ti(x.doc)===Ti(t)}}var Ti=e=>{let{layout:t,notes:n,...r}=e;return Ee({...r,version:0})};function Ei(e,t){let n=t.map(e=>ki(e.amendment?.patch)?e.amendment.patch:[]);return e.map(e=>{let r=t.filter((t,r)=>n[r].some(t=>Oi(t,e)));if(r.length>0)return r.map(e=>e.id);if(e.at!==`graph`){let n=RegExp(`(^|[^a-z0-9-])${e.at.replace(/[-]/g,`\\-`)}([^a-z0-9-]|$)`),r=t.filter(e=>n.test(`${e.amendment.summary} ${e.amendment.reason} ${JSON.stringify(e.amendment.patch??``)}`));if(r.length>0)return r.map(e=>e.id)}return t.length===1&&n[0].length===0?[t[0].id]:[]})}var Di={setGraphName:`graph`,setGraphField:`graph`,setTarget:`graph`,setConstraint:`graph`,renameId:`graph`,addNode:`id`,setNodeName:`id`,updateNode:`id`,removeNode:`id`,connect:`id`,updateEdge:`id`,removeEdge:`id`,addLoop:`id`,setLoopName:`id`,updateLoop:`id`,removeLoop:`id`,toggleLoopMember:`loop`,toggleLoopBack:`loop`,setBar:`loop`,addStop:`loop`,setStop:`loop`,removeStop:`loop`,moveStop:`loop`,addPolicy:`id`,removePolicy:`id`};function Oi(e,t){let n=Di[e.op];if(n===void 0)return!1;if(n===`graph`)return t.at===`graph`?e.op===`setConstraint`?t.fields.some(t=>t.key===`constraints.${String(e.key)}`):e.op===`setGraphField`?t.fields.some(t=>t.key===e.key):e.op===`setGraphName`?t.fields.some(e=>e.key===`name`):e.op===`setTarget`?t.fields.some(e=>e.key===`target`):e.op===`renameId`&&t.fields.some(e=>e.key===`id`):!1;if(e[n]!==t.at)return!1;let r=e.set;return t.op?.op.startsWith(`update`)&&typeof r==`object`&&r&&!Array.isArray(r)?Object.keys(r).some(e=>t.fields.some(t=>t.key===e)):!0}function ki(e){return Array.isArray(e)&&e.length>0&&e.every(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Zn.includes(e.op))}function Ai(e){return e==null?{kind:`none`}:ki(e)?{kind:`ops`,ops:e}:Array.isArray(e)&&e.some(e=>typeof e==`object`&&!!e&&`path`in e&&`op`in e)?{kind:`other`,why:`This patch uses index paths (JSON Patch), which grooph does not replay: paths like /nodes/2 point at whatever sits there now, so they break when anything is reordered. Read it and make the change by hand, or ask for it as grooph ops.`}:{kind:`other`,why:`This patch is not a list of grooph ops, so grooph cannot apply it. Read it and make the change by hand, or ask for it as grooph ops.`}}function ji(e,t,n={}){let i=`${e.id}@${e.version}`,{notes:a,layout:o,...s}=t,c=o??e.layout,l=new Set(t.nodes.map(e=>e.id)),u=c?Object.fromEntries(Object.entries(c).filter(([e])=>l.has(e))):void 0,d={...s,id:e.id,name:e.name,version:e.version+1,lineage:{...t.lineage,from:i},...e.notes&&e.notes.length>0?{notes:e.notes}:{},...u&&Object.keys(u).length>0?{layout:u}:{}},f=_n(d,{forExport:!0,loops:`errors`}).filter(e=>e.severity===`error`);return f.length>0?{ok:!1,message:`The working copy has ${f.length===1?`an error`:`${f.length} errors`} that ${f.length===1?`blocks`:`block`} export, so it cannot become version ${e.version+1} of ${e.id}. Discard it, or fix the working copy and adopt again. First: ${r(f[0])}`,issues:f}:{ok:!0,doc:d,from:i,...n.run===void 0?{}:{run:n.run}}}var Mi=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`groophRun`in e;function Ni(e){if(Mi(e)){let t=e.groophRun;if(typeof t==`number`&&t>0)return{issues:[`/groophRun: made by a newer grooph (run format ${t})`],newer:t}}for(let t of[`source`,`working`]){let n=s(typeof e==`object`&&e?e[t]:void 0,`graph`);if(n)return{issues:[`/${t}${n.path}: ${n.message}`]}}let t=[];return $r.check(e,``,t),t.length>0?{issues:t.map(e=>`${e.path===``?`/`:e.path}: ${e.message}`)}:{bundle:e,issues:[]}}function Pi(e){let t;try{t=JSON.parse(e)}catch(e){return{issues:[`/: not valid JSON: ${e.message}`]}}return Ni(t)}var Fi=32e3,Ii=4e6,Li=class extends Error{issues;constructor(e,t=[]){super(e),this.name=`ShareError`,this.issues=t}},Ri=e=>{let{notes:t,...n}=e;return n};function zi(e){if(Rr(e)){let t=Lr(e);if(!t.map)throw new Li(`this operation map does not match the map schema`,t.issues);return{v:1,kind:`map`,doc:Ir.canon(t.map)}}if(Mi(e)){let t=Ni(e);if(!t.bundle)throw new Li(`this run bundle does not match the run bundle schema`,t.issues.map(e=>({code:`E_SCHEMA`,severity:`error`,message:e,at:[]})));return{v:1,kind:`run`,doc:$r.canon(t.bundle)}}if(br(e)){let t=e,n=Sr(t,{requireInline:!0});if(n.some(e=>e.severity===`error`))throw new Li(`proposal set "${t.id??`?`}" cannot be shared until these are fixed`,n);let r=t.candidates.map(e=>{let t=Ri(e.graph);return{...e,graph:t,shape:Tr(t)}});return{v:1,kind:`proposals`,doc:_r.canon({...t,candidates:r})}}let t=e,n=Ce(t);if(!n.doc)throw new Li(`"${t.id??`?`}" is not a graph document`,n.issues);let r=_n(n.doc);if(r.some(e=>e.severity===`error`))throw new Li(`graph "${t.id}" cannot be shared until these are fixed`,r);return{v:1,kind:`graph`,doc:xe.canon(Ri(n.doc))}}var Bi=e=>JSON.stringify(e);function Vi(e,t){return Zi(t(new TextEncoder().encode(Bi(e))))}function Hi(e){let t=e.trim(),n=t.includes(`#`)?t.slice(t.indexOf(`#`)):t,r=/^#\/open\?(.*)$/.exec(n);if(!r)return/^[A-Za-z0-9_-]+$/.test(t)?t:void 0;for(let e of r[1].split(`&`)){let[t,n]=e.split(`=`);if(t===`d`)return n??``}}var H=(e,t=[])=>({ok:!1,message:e,details:t}),Ui=`The link is damaged: its data does not unpack. Links cut short or re-wrapped by a messenger look like this. Ask for the link again, or for the file (grooph share --out) and import it.`;function Wi(e,t){if(e.length===0)return H(`The link has nothing after d=, so there is no graph in it. It was probably cut off when it was sent.`);if(e.length>1e6)return H(`The link carries ${e.length.toLocaleString(`en`)} characters, far more than any graph needs, so it is not a grooph link. Nothing was unpacked.`);let n=Qi(e);if(!n)return/^[A-Za-z0-9_-]+$/.test(e)?H(Ui):H(`The link contains characters a grooph link never has, so part of it was changed or cut on the way. Ask for the link again, or for the file (grooph share --out).`);let r;try{r=t(n,Ii)}catch(e){return e instanceof RangeError?H(`The link unpacks to more than ${Ii/1e6} MB, far more than any graph, so it is not a grooph link. It was not opened.`):H(Ui)}let i;try{i=JSON.parse(new TextDecoder(`utf-8`,{fatal:!0}).decode(r))}catch{return H(Ui)}return Ki(i)}function Gi(e,t){let n=e=>typeof t==`object`&&t?t[e]:void 0,r=e===`graph`?[[`a graph`,t]]:e===`proposals`?(Array.isArray(n(`candidates`))?n(`candidates`):[]).slice(0,16).map(e=>[`a candidate graph`,typeof e==`object`&&e?e.graph:void 0]):e===`run`?[[`a run's graph`,n(`source`)],[`a run's graph`,n(`working`)]]:[];for(let[e,t]of r){let n=s(t,`graph`);if(n)return`${e} too large to draw: ${n.message}`}let i=e===`map`?s(t,`map`):void 0;return i?`an operation map too large to draw: ${i.message}`:void 0}function Ki(e){if(typeof e!=`object`||!e||Array.isArray(e))return H(`The link unpacks, but not to a grooph share, so there is nothing here to open.`);let t=e,n=t.v;if(typeof n==`number`&&n>1)return H(`The link was made by a newer grooph (share format ${n}; this app reads 1). Reload the app to update it, then open the link again.`);if(n!==1)return H(`The link unpacks, but not to a grooph share, so there is nothing here to open.`);let r=t.kind,i=t.doc,a=Gi(r,i);if(a)return H(`The link holds ${a}. It was not opened.`);if(r===`graph`){let e=Ce(i);if(!e.doc)return H(`The link holds a graph that does not match the graph document schema, so it was not opened.`,Ji(e.issues));let t=Ri(e.doc);return{ok:!0,envelope:{v:1,kind:`graph`,doc:t},issues:_n(t)}}if(r===`proposals`){let e=yr(i);if(!e.set)return H(`The link holds a proposal set that does not match its schema, so it was not opened.`,Ji(e.issues));let t=Sr(e.set,{requireInline:!0}),n=t.filter(t=>t.code===`E_DUPLICATE_ID`||t.code===`E_CANDIDATE_INVALID`&&qi(e.set,t.at));if(n.length>0)return H(`The link holds a proposal set grooph cannot show, so it was not opened.`,Ji(n));let r=e.set.candidates.map(e=>{let t=Ri(e.graph);return{...e,graph:t,shape:Tr(t)}});return{ok:!0,envelope:{v:1,kind:`proposals`,doc:{...e.set,candidates:r}},issues:t}}if(r===`run`){let e=Ni(i);return e.bundle?{ok:!0,envelope:{v:1,kind:`run`,doc:e.bundle},issues:_n(e.bundle.working)}:e.newer===void 0?H(`The link holds a run record that does not match the run bundle schema, so it was not opened.`,e.issues):H(`The link holds a run from a newer grooph (run format ${e.newer}). Reload the app to update it, then open the link again.`)}if(r===`map`){let e=Lr(i);return e.map?{ok:!0,envelope:{v:1,kind:`map`,doc:e.map},issues:Wr(e.map)}:H(`The link holds an operation map that does not match the map schema, so it was not opened.`,Ji(e.issues))}return H(typeof r==`string`?`The link holds a "${r}", which this version of grooph does not know how to show. Reload the app to update it.`:`The link unpacks, but not to a grooph share, so there is nothing here to open.`)}var qi=(e,t)=>e.candidates.some(e=>t.includes(e.id)&&xr(e.graph)),Ji=e=>e.map(r),Yi=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`,Xi=new Map([...Yi].map((e,t)=>[e,t]));function Zi(e){let t=``;for(let n=0;n<e.length;n+=3){let r=e[n],i=e[n+1],a=e[n+2];t+=Yi[r>>2]+Yi[(r&3)<<4|(i??0)>>4],i!==void 0&&(t+=Yi[(i&15)<<2|(a??0)>>6]),a!==void 0&&(t+=Yi[a&63])}return t}function Qi(e){if(e.length%4==1)return;let t=new Uint8Array(Math.floor(e.length*3/4)),n=0;for(let r=0;r<e.length;r+=4){let i=[];for(let t=r;t<Math.min(r+4,e.length);t++){let n=Xi.get(e[t]);if(n===void 0)return;i.push(n)}t[n++]=i[0]<<2|i[1]>>4,i.length>2&&(t[n++]=(i[1]&15)<<4|i[2]>>2),i.length>3&&(t[n++]=(i[2]&3)<<6|i[3])}return t}var $i={"bar-passed":`bar passed`,"max-iterations":`max iterations`,budget:`budget`,"diminishing-returns":`diminishing returns`,"evidence-invalid":`evidence invalid`,human:`human stop`},ea=e=>{if(e.at===`graph`)return{kind:`graph`};let t=e.at.indexOf(`:`);return{kind:e.at.slice(0,t),id:e.at.slice(t+1)}},ta=e=>e.round===void 0?``:` · round ${e.round}`;function na(e,t){let n=ea(e),r=e=>t.nodes.find(t=>t.id===e)?.name||e,i=e.outcome;if(n.kind===`graph`)return i===void 0?e.started!==void 0&&e.ended===void 0?`Run started`:`Run note`:i===`ending`?`Run ending`:i===`halt`?`Run halted`:`Run ended · ${i}`;if(n.kind===`node`){let t=r(n.id);return i===`started`?`${t} dispatched${ta(e)}`:i===`halt`?`${t} halted${ta(e)}`:i!==void 0&&i!==`ending`?`${t}: ${e.verdict&&e.verdict!==i?`${i} (${e.verdict})`:i}${ta(e)}`:e.amendment?`${t}: amendment${ta(e)}`:e.proposal?`${t}: proposal${ta(e)}`:`${t}${ta(e)}`}if(n.kind===`loop`){let r=t.loops.find(e=>e.id===n.id)?.name||n.id,a=e.stop&&Object.hasOwn($i,e.stop)?` · ${$i[e.stop]}`:``;return e.round!==void 0&&i!==void 0?`${r}: round ${e.round} ends, ${i}${a}`:e.proposal?`${r}: proposal`:`${r}${ta(e)}${a}`}let a=t.edges.find(e=>e.id===n.id);return a?`${r(a.from)} → ${r(a.to)}${ta(e)}`:`Edge ${n.id}`}function ra(e,t,n){let r=e=>{let n=e===void 0?void 0:t.nodes.find(t=>t.id===e);return n?{id:n.id,name:n.name||n.id,kind:n.kind}:void 0};if(n.state===`halted`)for(let t=e.length-1;t>=0;t--){let n=ea(e[t]);if(n.kind===`node`&&e[t].outcome===`halt`)return r(n.id)}for(let i=e.length-1;i>=0;i--){let a=ea(e[i]),o=r(a.kind===`node`?a.id:a.kind===`edge`?t.edges.find(e=>e.id===a.id)?.to:void 0);if(o?.kind===`stop`||o&&n.state===`halted`&&o.kind===`human-gate`)return o}}function ia(e,t){let n=e.loops.filter(e=>e.fired!==void 0).map(e=>`${e.name} stopped on ${$i[e.fired]}${e.round===void 0?``:` in round ${e.round}`}`),r=e.at?` at ${e.at.name}${e.at.kind===`human-gate`?` (a human gate)`:``}`:``,i=t?`The record stops while the run was still going.`:e.state===`halted`?`The run halted${r}.`:`The run ended${r}${e.outcome?`: ${e.outcome}`:``}.`;if(n.length===0){let t=e.loops.filter(e=>e.round!==void 0);return`${i}${t.length>0?` No loop stop fired; ${t.map(e=>`${e.name} ran to round ${e.round}`).join(`, `)}.`:``}`}return`${n.join(`. `)}. ${i}`}function aa(e,t){let n=[{index:0,summary:oi([],t),caption:`Before the run`}];e.forEach((r,i)=>{let a;n.push({index:i+1,note:r,get summary(){return a??=oi(e.slice(0,i+1),t)},focus:ea(r),caption:na(r,t)})});let r=n[n.length-1].summary,i=t.loops.filter(e=>r.loops[e.id]?.round!==null&&r.loops[e.id]!==void 0).map(e=>{let t=r.loops[e.id],n=t.lastStop;return{loop:e.id,name:e.name||e.id,...t.round===null?{}:{round:n?.round??t.round},...n?.outcome===void 0?{}:{outcome:n.outcome},...n?.fired===void 0?{}:{fired:n.fired}}}),a=e.length>0?ra(e,t,r):void 0,o={state:r.state,...r.outcome===void 0?{}:{outcome:r.outcome},loops:i,...a?{at:a}:{}};return{steps:n,end:{...o,line:e.length===0?`The run has no notes yet.`:ia(o,r.state===`running`)}}}var oa={width:200,height:84,gapX:36,gapY:76};function sa(e){let t=e.nodes.map(e=>e.id),n=new Set(t),r=new Set(e.loops.flatMap(e=>e.back)),i=ua(t,e.edges.filter(e=>!r.has(e.id)&&n.has(e.from)&&n.has(e.to)&&e.from!==e.to).map(e=>[e.from,e.to])),a=new Map(t.map(e=>[e,[]]));for(let[e,t]of i)a.get(t).push(e);let o=new Map,s=(e,t)=>{let n=o.get(e);if(n!==void 0)return n;t.add(e);let r=0;for(let n of a.get(e))t.has(n)||(r=Math.max(r,s(n,t)+1));return t.delete(e),o.set(e,r),r};for(let e of t)s(e,new Set);let c=[];for(let e of t)(c[o.get(e)]??=[]).push(e);let l=new Map(t.map(e=>[e,[]]));for(let[e,t]of i)l.get(e).push(t),l.get(t).push(e);let u=new Map(t.map((e,t)=>[e,t]));for(let e=0;e<2;e++){let e=new Map;c.forEach(t=>t?.forEach((t,n)=>e.set(t,n)));for(let t=1;t<c.length;t++){let n=c[t];if(!n)continue;let r=n=>{let r=l.get(n).filter(e=>o.get(e)===t-1);return r.length===0?e.get(n):r.reduce((t,n)=>t+e.get(n),0)/r.length};n.sort((e,t)=>r(e)-r(t)||u.get(e)-u.get(t)),n.forEach((t,n)=>e.set(t,n))}}return c.filter(e=>e!==void 0)}function ca(e,t=4,n=oa){let r={},i=0;for(let a of sa(e))for(let e=0;e<a.length;e+=t){let o=a.slice(e,e+t),s=o.length*n.width+(o.length-1)*n.gapX;o.forEach((e,t)=>{r[e]={x:Math.round(t*(n.width+n.gapX)-s/2),y:i}}),i+=n.height+n.gapY}return r}function la(e,t=4,n=oa){let r=e.layout??{},i=e.nodes.map(e=>e.id).filter(e=>!Object.hasOwn(r,e));if(i.length===0){let t={};for(let n of e.nodes)t[n.id]={x:r[n.id].x,y:r[n.id].y};return{positions:t,unplaced:i}}let a=ca(e,t,n),o=e.nodes.filter(e=>Object.hasOwn(r,e.id));if(o.length===0)return{positions:a,unplaced:i};let s={};for(let e of o)s[e.id]={x:r[e.id].x,y:r[e.id].y};let c=Math.min(...o.map(e=>r[e.id].x)),l=Math.max(...o.map(e=>r[e.id].y)),u=Math.min(...i.map(e=>a[e].x)),d=Math.min(...i.map(e=>a[e].y));for(let e of i)s[e]={x:c+a[e].x-u,y:l+n.height+n.gapY+a[e].y-d};return{positions:s,unplaced:i}}function ua(e,t){let n=new Map(e.map(e=>[e,[]]));for(let e of t)n.get(e[0]).push(e);let r=new Map,i=[],a=e=>{r.set(e,1);for(let t of n.get(e)){let e=r.get(t[1]);e!==1&&(i.push(t),e===void 0&&a(t[1]))}r.set(e,2)};for(let t of e)r.has(t)||a(t);return i}var da=e=>e.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g,``).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`),fa=60,pa=44,ma=40,ha=400,ga=4,_a=14,va=8,ya=8,ba=6,U={edge:`var(--edge, #5c6663)`,muted:`var(--ink-3, #6b7370)`,ink:`var(--ink, #2b302e)`,surface:`var(--surface, #ffffff)`,agentFill:`var(--accent-soft, #e3efe9)`,agent:`var(--kind-agent, #1f5f4a)`,gate:`var(--kind-human-gate, #b25e09)`,check:`var(--kind-check, #2b5f9e)`,merge:`var(--kind-merge, #6b4fa0)`,warning:`var(--warning, #955500)`,error:`var(--error, #b42318)`,loops:[`var(--loop-0, #7a4cc2)`,`var(--loop-1, #0f7c8c)`,`var(--loop-2, #c2410c)`,`var(--loop-3, #b5306e)`]},xa=e=>{switch(e.kind){case`agent`:return We(e)?`diamond`:Ge(e)?`square`:`rounded`;case`check`:return`hexagon`;case`human-gate`:return`octagon`;case`merge`:return`circle`;case`stop`:return`dot`}};function Sa(e,t,n){let r=Math.hypot(t,n)||1,i=Math.abs(t/r),a=Math.abs(n/r);switch(e){case`square`:case`rounded`:return Math.min(11/Math.max(i,a),11*Math.SQRT2-1);case`diamond`:return 14/(i+a);case`hexagon`:case`octagon`:return 13;case`circle`:return 11;case`dot`:return 6}}var Ca=(e,t)=>{let n=e===`diamond`||e===`hexagon`?14:e===`dot`?6:e===`octagon`?13:11,r=e===`diamond`?14:e===`dot`?6:e===`octagon`?13:e===`hexagon`?12:11;return{x:t?Math.max(n,13):n,top:r,bottom:t?19:r}},W=e=>{let t=Math.round(e*10)/10;return(Object.is(t,-0)?0:t).toString()},G=e=>`${W(e.x)},${W(e.y)}`,wa=()=>({minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}),Ta=(e,t,n,r=0)=>{e.minX=Math.min(e.minX,t-r),e.minY=Math.min(e.minY,n-r),e.maxX=Math.max(e.maxX,t+r),e.maxY=Math.max(e.maxY,n+r)};function Ea(e){let t={};if(!(e.layout!==void 0&&e.nodes.some(t=>t.id in e.layout))){let n=sa(e),r=(Math.max(1,...n.map(e=>e.length))-1)*pa/2;return n.forEach((e,n)=>{let i=r-(e.length-1)*pa/2;e.forEach((e,r)=>{t[e]={x:n*fa,y:i+r*pa}})}),{centers:t,vertical:!1}}let{positions:n}=la(e),r={};for(let t of e.nodes){let i=n[t.id],a=e.layout[t.id];r[t.id]={x:i.x+(a?.w??200)/2,y:i.y+(a?.h??84)/2}}let i=e.nodes.map(e=>e.id),a=1/0;for(let e=0;e<i.length;e++)for(let t=e+1;t<i.length;t++){let n=Math.hypot(r[i[e]].x-r[i[t]].x,r[i[e]].y-r[i[t]].y);n>0&&(a=Math.min(a,n))}let o=wa();for(let e of i)Ta(o,r[e].x,r[e].y);let s=o.maxX-o.minX,c=o.maxY-o.minY,l=a===1/0?1:ma/a;s*l>ha&&(l=ha/s),c*l>ha&&(l=ha/c);for(let e of i)t[e]={x:(r[e].x-o.minX)*l,y:(r[e].y-o.minY)*l};return{centers:t,vertical:c>s}}function Da(e,t={}){let n=t.scale??1,r=new Map(e.nodes.map(e=>[e.id,e])),i=new Map(e.nodes.map(e=>[e.id,xa(e)])),a=new Set(e.nodes.filter(e=>e.kind===`agent`&&(e.irreversible??[]).length>0).map(e=>e.id)),{centers:o,vertical:s}=Ea(e),c=e.edges.filter(e=>r.has(e.from)&&r.has(e.to)),l=new Map;e.loops.forEach((e,t)=>{for(let n of e.back)l.has(n)||l.set(n,t)});let u=wa(),d=[],f=e=>s?e.y:e.x,p=e=>s?e.x:e.y,m=(e,t)=>s?{x:t,y:e}:{x:e,y:t},h=e=>{let t=Ca(i.get(e),a.has(e));return p(o[e])+(s?t.x:t.bottom)},g=new Map,_=t=>Math.min(...e.loops.filter(e=>e.back.includes(t)).map(e=>e.members.length)),v=e=>Math.abs(f(o[e.from])-f(o[e.to]));c.filter(e=>l.has(e.id)).map((e,t)=>({e,i:t})).sort((e,t)=>_(e.e.id)-_(t.e.id)||v(e.e)-v(t.e)||e.i-t.i).forEach(({e},t)=>g.set(e.id,t));let y=(e,t)=>{let n=e[t],r=c.filter(e=>l.has(e.id)&&e.from!==e.to&&e[t]===n).sort((e,t)=>g.get(e.id)-g.get(t.id));return(r.findIndex(t=>t.id===e.id)-(r.length-1)/2)*6},b=e=>{let t=Math.min(f(o[e.from]),f(o[e.to])),n=Math.max(f(o[e.from]),f(o[e.to])),i=-1/0;for(let e of r.keys())f(o[e])>=t-1&&f(o[e])<=n+1&&(i=Math.max(i,h(e)));return i+_a+g.get(e.id)*va},x=e.loops.map(e=>new Set(e.members.filter(e=>r.has(e)))),S=(e,t)=>e!==t&&x[t].size>0&&x[t].size<x[e].size&&[...x[t]].every(t=>x[e].has(t)),C=e.loops.map((t,n)=>({loop:t,i:n,inside:e.loops.filter((e,t)=>S(n,t)).length})).filter(({i:e})=>x[e].size>0).sort((e,t)=>t.inside-e.inside||e.i-t.i);for(let{loop:e,i:t,inside:n}of C){let r=ya+n*ba,l=wa();for(let e of x[t]){let t=o[e],n=Ca(i.get(e),a.has(e));Ta(l,t.x-n.x,t.y-n.top),Ta(l,t.x+n.x,t.y+n.bottom)}for(let t of c){if(!e.back.includes(t.id)||!g.has(t.id))continue;let n=b(t);s?l.maxX=Math.max(l.maxX,n):l.maxY=Math.max(l.maxY,n)}let f=l.minX-r,p=l.minY-r,m=l.maxX-l.minX+2*r,h=l.maxY-l.minY+2*r;Ta(u,f,p),Ta(u,f+m,p+h),d.push(`<rect x="${W(f)}" y="${W(p)}" width="${W(m)}" height="${W(h)}" rx="10" stroke-width="1.3" stroke-dasharray="4 3" style="stroke:${U.loops[t%4]}"/>`)}let w=new Map;for(let e of c){if(l.has(e.id))continue;let t=[e.from,e.to].sort().join(`\0`);w.set(t,[...w.get(t)??[],e.id])}for(let e of c){let t=e.when??`always`,n=e.approval?U.gate:t===`fail`?U.warning:typeof t==`object`?U.muted:U.edge,r=t===`fail`?` stroke-dasharray="5 3"`:typeof t==`object`?` stroke-dasharray="1.5 3.5"`:``,c=o[e.from],h=o[e.to],g,_,v,x={x:0,y:0};if(l.has(e.id)&&e.from!==e.to){let t=b(e),n=Ca(i.get(e.from),a.has(e.from)),r=Ca(i.get(e.to),a.has(e.to)),o=f(c)+y(e,`from`),l=f(h)+y(e,`to`),d=m(o,p(c)+(s?n.x:n.bottom)+1),x=m(l,p(h)+(s?r.x:r.bottom)+3),S=m(o,t),C=m(l,t);g=`M${G(d)} C${G(S)} ${G(C)} ${G(x)}`,Ta(u,S.x,S.y,1),Ta(u,C.x,C.y,1),_=x,v=s?{x:-1,y:0}:{x:0,y:-1}}else if(e.from===e.to){let t=Ca(i.get(e.from),a.has(e.from)),n=p(c)+(s?t.x:t.bottom),r=m(f(c)+5,n+1),o=m(f(c)-5,n+3),l=m(f(c)+18,n+20),d=m(f(c)-18,n+20);g=`M${G(r)} C${G(l)} ${G(d)} ${G(o)}`,Ta(u,l.x,l.y,1),Ta(u,d.x,d.y,1),_=o,v=s?{x:-1,y:0}:{x:0,y:-1}}else{let t=h.x-c.x,n=h.y-c.y,r=Math.hypot(t,n)||1,a=t/r,o=n/r,s=w.get([e.from,e.to].sort().join(`\0`))??[e.id];if(s.length>1){let t=s.indexOf(e.id)-(s.length-1)/2;x={x:-o*t*5,y:a*t*5}}let l={x:c.x+a*(Sa(i.get(e.from),t,n)+1)+x.x,y:c.y+o*(Sa(i.get(e.from),t,n)+1)+x.y},u={x:h.x-a*(Sa(i.get(e.to),-t,-n)+3)+x.x,y:h.y-o*(Sa(i.get(e.to),-t,-n)+3)+x.y};g=`M${G(l)} L${G(u)}`,_=u,v={x:a,y:o}}let S=`<path d="${g}" stroke-width="1.6"${r} style="stroke:${n}"/>`;if(e.approval){let e=-v.y*1.7,t=v.x*1.7;d.push(`<g transform="translate(${W(e)} ${W(t)})">${S}</g>`),d.push(`<g transform="translate(${W(-e)} ${W(-t)})">${S}</g>`)}else d.push(S);let C=-v.y,T=v.x,E=[_,{x:_.x-v.x*7+C*7*.5,y:_.y-v.y*7+T*7*.5},{x:_.x-v.x*7-C*7*.5,y:_.y-v.y*7-T*7*.5}];d.push(`<path d="M${E.map(G).join(` L`)} Z" style="fill:${n}"/>`)}for(let t of e.nodes){let e=o[t.id],n=i.get(t.id),r=Ca(n,a.has(t.id));switch(Ta(u,e.x-r.x,e.y-r.top),Ta(u,e.x+r.x,e.y+r.bottom),n){case`square`:case`rounded`:d.push(`<rect x="${W(e.x-11)}" y="${W(e.y-11)}" width="22" height="22" rx="${n===`square`?2:7}" stroke-width="1.8" style="fill:${U.agentFill};stroke:${U.agent}"/>`);break;case`diamond`:d.push(`<path d="M${G({x:e.x,y:e.y-14})} L${G({x:e.x+14,y:e.y})} L${G({x:e.x,y:e.y+14})} L${G({x:e.x-14,y:e.y})} Z" stroke-width="1.8" style="fill:${U.agentFill};stroke:${U.agent}"/>`);break;case`hexagon`:d.push(`<path d="M${G({x:e.x-7,y:e.y-12})} L${G({x:e.x+7,y:e.y-12})} L${G({x:e.x+14,y:e.y})} L${G({x:e.x+7,y:e.y+12})} L${G({x:e.x-7,y:e.y+12})} L${G({x:e.x-14,y:e.y})} Z" stroke-width="1.8" style="fill:${U.surface};stroke:${U.check}"/>`);break;case`octagon`:{let t=[];for(let n=0;n<8;n++){let r=(22.5+n*45)*Math.PI/180;t.push({x:e.x+13*Math.cos(r),y:e.y+13*Math.sin(r)})}d.push(`<path d="M${t.map(G).join(` L`)} Z" stroke-width="2.4" style="fill:${U.surface};stroke:${U.gate}"/>`);break}case`circle`:d.push(`<circle cx="${W(e.x)}" cy="${W(e.y)}" r="11" stroke-width="1.8" style="fill:${U.surface};stroke:${U.merge}"/>`);break;case`dot`:d.push(`<circle cx="${W(e.x)}" cy="${W(e.y)}" r="6" style="fill:${t.kind===`stop`&&t.outcome===`halt`?U.warning:U.ink}"/>`)}a.has(t.id)&&d.push(`<path d="M${G({x:e.x-13,y:e.y+17})} L${G({x:e.x+13,y:e.y+17})}" stroke-width="3" style="stroke:${U.error}"/>`)}d.length===0&&Ta(u,0,0,12);let T=u.minX-ga,E=u.minY-ga,D=u.maxX-u.minX+8,O=u.maxY-u.minY+8,ee=da(e.name||e.id);return[`<svg xmlns="http://www.w3.org/2000/svg" viewBox="${W(T)} ${W(E)} ${W(D)} ${W(O)}" width="${W(D*n)}" height="${W(O*n)}" role="img" fill="none" stroke-linecap="round" stroke-linejoin="round" class="grooph-glyph">`,`<title>${ee}</title>`,...d,`</svg>`].join(`
2
+ `)}var Oa=e=>`n_${e.replace(/[^A-Za-z0-9_]/g,`_`)}`,ka=e=>e.replace(/[\r\n]+/g,` `).replace(/#/g,`#35;`).replace(/&/g,`#38;`).replace(/\\/g,`#92;`).replace(/"/g,`#quot;`).replace(/</g,`#lt;`).replace(/>/g,`#gt;`).replace(/`/g,`#96;`).replace(/%%/g,`#37;#37;`).replace(/direction/g,`#100;irection`).replace(/:(?=\S)/g,`#58;`),Aa=e=>ka(e.replace(/\s+/g,` `)),ja=e=>`"${ka(e).trim()===``?` `:ka(e)}"`;function Ma(e){let t=ja(`${e.name||e.id}${L(e)?` (a person)`:``}`);switch(e.kind){case`agent`:return We(e)?`${Oa(e.id)}{${t}}`:Ge(e)?`${Oa(e.id)}[${t}]`:`${Oa(e.id)}([${t}])`;case`check`:return`${Oa(e.id)}{{${t}}}`;case`human-gate`:return`${Oa(e.id)}[/${t}\\]`;case`merge`:return`${Oa(e.id)}((${t}))`;case`stop`:return`${Oa(e.id)}(((${t})))`}}function Na(e){let t=e.when??`always`,n=[];return t!==`always`&&n.push(typeof t==`string`?t:`verdict: ${t.verdict}`),e.approval&&n.push(`approval`),n.join(`, `)}function Pa(e){return`"${[`stops`,...Fa(e)].map(ka).join(`<br>`)}"`}var Fa=e=>e.stops.map(e=>`${Qe(e)}${e.then===void 0?``:` → ${e.then}`}`);function Ia(e){let t=new Map(e.nodes.map(e=>[e.id,e])),n=ke(e),r=e.loops.map((e,n)=>({loop:e,i:n,members:new Set(e.members.filter(e=>t.has(e)))})),i=(e,t)=>e!==t&&t.members.size>0&&t.members.size<e.members.size&&[...t.members].every(t=>e.members.has(t)),a=new Map;for(let e of r){let t=r.filter(t=>i(t,e)).sort((e,t)=>e.members.size-t.members.size);t[0]&&a.set(e.i,t[0].i)}let o=new Map,s=[];for(let t of e.nodes){let e=r.filter(e=>e.members.has(t.id)).sort((e,t)=>e.members.size-t.members.size||e.i-t.i);if(e.length!==0){o.set(t.id,e[0].i);for(let n of e.slice(1))i(n,e[0])||s.push(`%% ${t.id} is also a member of loop ${n.loop.id}`)}}let c=[`%% grooph mermaid: a projection of ${Aa(e.name||e.id)} (${e.id}@${e.version}).`,`%% grooph import reads back its nodes, edges, loops and stops; briefs, bars and brakes live in the graph document.`,`flowchart LR`],l=new Set(e.loops.flatMap(e=>e.back)),u=(t,i)=>{let{loop:s}=r[t],l=` `.repeat(i);c.push(`${l}subgraph ${Oa(s.id)}[${ja(`${s.name||s.id} · ${Ye(n,s)} loop`)}]`);for(let n of e.nodes)o.get(n.id)===t&&c.push(`${l} ${Ma(n)}`);s.stops.length>0&&c.push(`${l} stops_${s.id.replace(/[^A-Za-z0-9_]/g,`_`)}[${Pa(s)}]:::stop`);for(let e of r)a.get(e.i)===t&&u(e.i,i+1);c.push(`${l}end`)};for(let e of r)a.has(e.i)||u(e.i,1);for(let t of e.nodes)o.has(t.id)||c.push(` ${Ma(t)}`);c.push(...s.map(e=>` ${e}`));for(let n of e.edges){if(!t.has(n.from)||!t.has(n.to))continue;let e=Na(n),r=`${l.has(n.id)?`-.->`:`-->`}${e===``?``:`|${ja(e)}|`}`;c.push(` ${Oa(n.from)} ${r} ${Oa(n.to)}`)}return e.loops.some(e=>e.stops.length>0)&&c.push(` classDef stop fill:none,stroke-dasharray:3 3,font-size:12px`),`${c.join(`
3
+ `)}\n`}function La(e,t=!1){let n=e.agents.reduce((e,t)=>e+(t.count??1),0),r=e.agents.reduce((e,t)=>e+Math.min(t.started,t.count??1),0),i=e.agents.reduce((e,t)=>e+t.running,0),a=[...e.agents.filter(e=>e.started>(e.count??1)).map(e=>`${e.started-(e.count??1)} more ${e.type}`),...e.unplanned];return`${r} of ${n} started${i>0?`, ${i} ${t?`not seen to finish`:`running`}`:``}${a.length>0?`; not in the plan: ${a.join(`, `)}`:``}`}var Ra=(e,t)=>t!==void 0&&e.state!==`ended`&&za(e.lastAt,t)>=1800,za=(e,t)=>Math.max(0,Math.round((Date.parse(t)-Date.parse(e))/1e3));function Ba(e){return e<60?`${e} s`:e<3600?`${Math.floor(e/60)} min${e%60?` ${e%60} s`:``}`:`${Math.floor(e/3600)} h${Math.floor(e%3600/60)?` ${Math.floor(e%3600/60)} min`:``}`}function Va(e,t,n){let r=`${t.id}--`,i=new Set(t.nodes.map(e=>e.id)),a={};for(let t of e)for(let e of t.agents){if(!e.type.startsWith(r))continue;let t=e.type.slice(r.length);if(!i.has(t)||n!==void 0&&e.started<n&&(e.ended??e.lastAt)<n)continue;let o=a[t]??={running:0,runs:0};o.runs+=1,e.state===`running`&&(o.running+=1),(o.lastStarted===void 0||e.started>o.lastStarted)&&(o.lastStarted=e.started),e.ended!==void 0&&(o.lastEnded===void 0||e.ended>o.lastEnded)&&(o.lastEnded=e.ended)}return a}function Ha(e,t){let n={...e.nodes},r=!1;for(let[e,i]of Object.entries(t)){let t=n[e];t&&i.running!==0&&t.state!==`running`&&(n[e]={...t,state:`running`,runs:Math.max(t.runs,i.runs)},r=!0)}return r?{...e,nodes:n}:e}function Ua(e,t,n){let r=new Set(t.sessions.map(e=>e.id)),i=Object.create(null);for(let t of e){if(t.source===void 0||!r.has(t.source))continue;let e=i[t.source]??={sessions:0,working:0,waiting:0,ended:0,agentsRunning:0,agentsDone:0,lastAt:t.lastAt};e.sessions+=1;let a=Ra(t,n);a?(e.quiet=(e.quiet??0)+1,(e.quietLastAt===void 0||t.lastAt>e.quietLastAt)&&(e.quietLastAt=t.lastAt)):e[t.state]+=1;for(let n of t.agents)n.state===`running`&&!a?e.agentsRunning+=1:n.state!==`running`&&(e.agentsDone+=1);t.lastAt>e.lastAt&&(e.lastAt=t.lastAt)}return i}function Wa(e,t){let n=e.quiet??0,r=(t,n)=>e.sessions>1?`${t} of ${e.sessions} ${n}`:n,i=t===void 0?`gone quiet`:`last seen ${Ba(za(e.quietLastAt??e.lastAt,t))} ago`;return`${e.working>0?r(e.working,`working`):e.waiting>0?r(e.waiting,`waiting`):n>0?i:`ended`}${e.agentsRunning+e.agentsDone===0||n>0&&e.working+e.waiting===0?``:` · ${e.agentsRunning} running, ${e.agentsDone} done`}`}var Ga={bg:`#f1f4f3`,surface:`#fdfefe`,"surface-2":`#e8edeb`,ink:`#1a201e`,"ink-2":`#454c49`,"ink-3":`#5f6764`,line:`#dce1df`,"line-strong":`#b9c1be`,accent:`#1f5f4a`,"accent-soft":`#dcefe6`,gate:`#b25e09`,"gate-soft":`#fcf0d9`,check:`#2b5f9e`,merge:`#6b4fa0`,stop:`#5b5f66`,ok:`#1f7a4d`,"ok-soft":`#dff3e6`,warning:`#955500`,error:`#b42318`,"error-soft":`#fceae7`,"loop-0":`#7a4cc2`,"loop-1":`#0f7c8c`,"loop-2":`#c2410c`,"loop-3":`#b5306e`},Ka={bg:`#111514`,surface:`#1b201e`,"surface-2":`#242a27`,ink:`#ebefed`,"ink-2":`#c0c7c4`,"ink-3":`#99a19e`,line:`#2d3331`,"line-strong":`#4a524f`,accent:`#5dbb94`,"accent-soft":`#1e3a30`,gate:`#eb9a45`,"gate-soft":`#362a15`,check:`#6fa3e0`,merge:`#a88be0`,stop:`#9ba0a8`,ok:`#6fcf9d`,"ok-soft":`#1c3a2a`,warning:`#f0b35a`,error:`#ff8f80`,"error-soft":`#3a1e1b`,"loop-0":`#a883f0`,"loop-1":`#3cc0d0`,"loop-2":`#f0874f`,"loop-3":`#ee6fa6`},qa=`system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif`,Ja=`ui-monospace, 'SF Mono', Menlo, Consolas, 'Roboto Mono', monospace`;function Ya(e){return e===`light`?e=>Ga[e]:e===`dark`?e=>Ka[e]:e=>`var(--gp-${e})`}function Xa(e){if(e!==`auto`)return``;let t=e=>Object.keys(Ga).map(t=>`--gp-${t}:${e[t]}`).join(`;`);return`<style>:where(.grooph-picture){${t(Ga)}}@media (prefers-color-scheme:dark){:where(.grooph-picture:not([data-theme="light"])){${t(Ka)}}}:where(.grooph-picture[data-theme="dark"]){${t(Ka)}}</style>`}Object.keys(Ga);var K=e=>{let t=Math.round(e*10)/10;return(Object.is(t,-0)?0:t).toString()},Za=[352,394,459,818,636,1076,727,269,454,454,636,818,364,454,364,454,636,636,636,636,636,636,636,636,636,636,454,454,818,818,818,556,1015,684,686,722,771,667,611,778,751,421,500,693,557,843,748,787,667,787,722,684,616,732,684,989,685,667,685,454,454,454,818,636,636,601,623,521,623,596,352,623,633,274,344,592,274,973,633,607,623,623,427,521,394,633,592,818,592,592,525,635,454,635,818],Qa=[342,402,587,867,711,1272,862,332,543,543,711,867,361,480,361,689,711,711,711,711,711,711,711,711,711,711,402,402,867,867,867,617,975,776,762,724,830,683,650,811,837,546,556,771,637,948,847,850,733,850,782,710,682,812,764,1128,764,737,692,543,689,543,867,711,711,668,699,588,699,664,422,699,712,342,403,671,342,1058,712,687,699,699,497,593,456,712,650,980,669,651,597,711,543,711,867],$a={"·":[364,361],"→":[1e3,1e3],"×":[818,867],"…":[1e3,1049],"—":[1e3,1e3],"–":[636,711],"’":[269,332],"‘":[269,332],"“":[459,587],"”":[459,587]},eo=1.03;function to(e,t,n=`regular`){if(n===`mono`)return e.length*t*.62;let r=n===`bold`?Qa:Za,i=+(n===`bold`),a=0;for(let t of e){let e=t.codePointAt(0);e>=32&&e<=126?a+=r[e-32]:$a[t]?a+=$a[t][i]:a+=e>11904?1e3:n===`bold`?720:650}return a/1e3*t*eo}function no(e,t,n,r=`regular`){if(to(e,n,r)<=t)return e;let i=t-to(`…`,n,r),a=0,o=0;for(let t of e){let e=to(t,n,r);if(o>0&&a+e>i)break;a+=e,o+=t.length}return`${e.slice(0,o).trimEnd()}…`}function q(e,t,n,r,i=`regular`){let a=typeof t==`number`?()=>t:t,o=e.trim().split(/\s+/).filter(e=>e!==``),s=[],c=0;for(;c<o.length&&s.length<r;){let e=o[c++];for(;c<o.length&&to(`${e} ${o[c]}`,n,i)<=a(s.length);)e=`${e} ${o[c++]}`;s.push(e)}return s.length===0?[``]:(c<o.length&&(s[s.length-1]=`${s[s.length-1]} ${o.slice(c).join(` `)}`),s.map((e,t)=>no(e,a(t),n,i)))}function J(e,t,n,r){let i=r.weight===`mono`?` font-family="${Ja}"`:``,a=r.weight===`bold`?` font-weight="700"`:``,o=r.anchor&&r.anchor!==`start`?` text-anchor="${r.anchor}"`:``;return`<text x="${K(e)}" y="${K(t)}" font-size="${K(r.size)}"${i}${a}${o} style="fill:${r.fill}">${da(n)}</text>`}function Y(e,t,n,r,i){let a=[`fill:${i.fill??`none`}`,...i.stroke?[`stroke:${i.stroke}`]:[]].join(`;`);return`<rect${i.mark?` data-${i.mark}=""`:``} x="${K(e)}" y="${K(t)}" width="${K(n)}" height="${K(r)}"${i.rx?` rx="${K(i.rx)}"`:``}${i.stroke?` stroke-width="${K(i.width??1)}"`:``}${i.dash?` stroke-dasharray="${i.dash}"`:``} style="${a}"/>`}function ro(e,t,n,r){let i=r.size*.55,a=to(n,r.size,r.weight??`bold`)+i*2,o=r.size*1.55;return{svg:Y(e,t-r.size*1.08,a,o,{fill:r.fill,rx:o/2,...r.stroke?{stroke:r.stroke}:{}})+J(e+a/2,t,n,{size:r.size,fill:r.ink,weight:r.weight??`bold`,anchor:`middle`}),width:a}}function io(e,t,n,r,i,a,o){return`<svg xmlns="http://www.w3.org/2000/svg" class="grooph-picture" data-picture="${o}" viewBox="0 0 ${K(e)} ${K(t)}" width="${K(e)}" height="${K(t)}" role="img" font-family="${qa}"><title>${da(n)}</title>`+Xa(r)+Y(0,0,e,t,{fill:i(`bg`)})+a+`</svg>
4
+ `}function ao(e,t=0){let n=e.map((e,t)=>({i:t,lo:Math.min(e.from,e.to),hi:Math.max(e.from,e.to)})).sort((e,t)=>e.hi-e.lo-(t.hi-t.lo)||e.lo-t.lo||e.i-t.i),r=[],i=Array(e.length).fill(0);for(let e of n){let n=0;for(;r[n]?.some(n=>e.lo<=n.hi+t&&n.lo<=e.hi+t);)n++;(r[n]??=[]).push({lo:e.lo,hi:e.hi}),i[e.i]=n}return{tracks:i,count:r.length}}var oo=6.5,so=12,co={branch:{color:`accent`,width:1.6},"pull-request":{color:`check`,width:1.6},"session-message":{color:`ink-2`,dash:`5 3`,width:1.4},"scheduled-message":{color:`merge`,dash:`1.5 3`,width:1.8},"review-page":{color:`loop-3`,dash:`7 3 1.5 3`,width:1.4},person:{color:`gate`,width:2.4},notification:{color:`loop-1`,dash:`0.1 4.5`,width:2.6},other:{color:`ink-3`,dash:`3 3`,width:1.4},none:{color:`error`,dash:`2 2`,width:1.4}},lo=e=>co[e.carrier?.kind??`none`],uo=(e,t)=>`fill="none" stroke-width="${K(e.width)}" stroke-linecap="round"${e.dash?` stroke-dasharray="${e.dash}"`:``} style="stroke:${t}"`,fo={"claude-code":`Claude Code`,codex:`Codex`},po={"long-lived":`long-lived`,"per-task":`per task`,scheduled:`scheduled`};function mo(e){let t=new Set(e.lanes.map(e=>e.id)),n=e.sessions.filter(e=>t.has(e.lane)),r=e.people??[],i=new Set([...r,...n].map(e=>e.id));return{sessions:n,people:r,handoffs:e.handoffs.filter(e=>i.has(e.from)&&i.has(e.to)),numberOf:new Map(e.handoffs.map((e,t)=>[e.id,t+1]))}}function ho(e,t,n,r,i){let a=18;for(let n of q(e.name||e.id,t-24,17,2,`bold`))a+=17,i.push(J(12,a,n,{size:17,fill:r(`ink`),weight:`bold`})),a+=4;let o=[(n.live&&n.at?`live at ${n.at.slice(0,16).replace(`T`,` `)} UTC`:void 0)??(e.asOf?`as of ${e.asOf}`:void 0),Kr(Gr(e))].filter(Boolean).join(` · `);for(let e of q(o,t-24,11,2))a+=13,i.push(J(12,a,e,{size:11,fill:r(`ink-3`)}));return a+12}var go=7.2,_o=e=>e.length>1?(to(e,8.5,`bold`)+4.5)/2:go;function vo(e,t,n,r,i){let a=_o(n);return n.length>1?Y(e-a,t-go,a*2,go*2,{fill:i(`bg`),stroke:r,rx:go,width:1.3}):`<circle cx="${K(e)}" cy="${K(t)}" r="${go}" stroke-width="1.3" style="fill:${i(`bg`)};stroke:${r}"/>`}var yo=(e,t,n,r)=>J(e,t+3.3,n,{size:n.length>1?8.5:9.5,fill:r(`ink`),weight:`bold`,anchor:`middle`}),bo=(e,t,n,r,i)=>vo(e,t,n,r,i)+yo(e,t,n,i);function xo(e,t,n,r,i,a,o){let s=Math.min(t,n)+9,c=Math.max(t,n)-9,l=t=>{let n=1/0;for(let i of a)Math.abs(i.x-e)<=i.half+r+1&&(n=Math.min(n,Math.abs(i.y-t)-20.4));for(let a of o)a.of!==i&&!(a.to<e-r-1)&&!(a.from>e+r+1)&&(n=Math.min(n,Math.abs(a.y-t)-9.7));return n},u=(t+n)/2,d=u;if(l(u)<0&&c>s){let e={at:u,room:l(u)};for(let t=1;t*4<=c-s;t++){for(let n of[u+t*4,u-t*4]){if(n<s||n>c)continue;let t=l(n);(t>=0&&e.room<0||e.room<0&&t>e.room)&&(e={at:n,room:t})}if(e.room>=0)break}d=e.at}return a.push({x:e,y:d,half:r}),d}var So=e=>(e+1)*13+4;function Co(e,t,n,r,i=0){let a=t-20,o=q(e.name||e.id,a,13.5,2+i,`bold`),s=10+o.length*16+10-3,c=e.role?q(e.role,a,11,Math.max(so,Math.floor((So(n)-s-2)/13.5))):[],l=Math.max(s+(c.length?2+c.length*13.5:0),So(n));return{height:l,family:!1,draw(n,i,a=l){let s=[Y(n,i,t,a,{fill:r(`gate-soft`),stroke:r(`gate`),rx:14,width:1.4,mark:`card`})],u=i+10-5;for(let e of o)u+=16,s.push(J(n+10,u,e,{size:13.5,fill:r(`ink`),weight:`bold`}));u+=2;for(let e of c)u+=13.5,s.push(J(n+10,u,e,{size:11,fill:r(`ink-2`)}));return`<g data-person="${e.id}">${s.join(``)}</g>`}}}function wo(e,t,n,r,i,a,o=0){let s=n-20,c=(t.count??1)>1,l=c?`×${t.count}`:``,u=c?to(l,10.5,`bold`)+12:0,d=Object.hasOwn(fo,t.harness)?fo[t.harness]:t.harness,f=a.live?.[t.id],p=q(t.name||t.id,e=>s-(c&&e===0?u+6:0),13.5,2+o,`bold`),m=t.model?`${d} · ${t.model}`:d,h=!t.model||to(m,10.5,`bold`)<=s?[no(m,s,10.5,`bold`)]:[no(d,s,10.5,`bold`),...q(t.model,s,10.5,2+o,`bold`)],g=[t.lifetime?po[t.lifetime]:void 0,t.repo].filter(Boolean).join(` · `),_=g?q(g,s,10,3+o):[],v=Xr(e,t.id),y=v===void 0?[]:q(v===``?`wakes itself`:`wakes itself · ${v}`,s-13,10,2,`bold`),b=10+p.length*16+1+h.length*13+2+_.length*13+ +!!_.length+(y.length?2+y.length*13:0)+(t.graph?15:0)+(f?19:0)+10-3,x=q(t.role,s,11,Math.max(so,Math.floor((So(r)-b)/13.5))),S=Math.max(b+x.length*13.5,So(r));return{height:S,family:c,draw(e,r,o=S){let d=[];c&&(d.push(Y(e+6,r+6,n-6,o-2,{fill:i(`surface`),stroke:i(`line`),rx:9})),d.push(Y(e+3,r+3,n-3,o-1,{fill:i(`surface`),stroke:i(`line`),rx:9}))),d.push(Y(e,r,n,o,{fill:i(`surface`),stroke:i(`line-strong`),rx:9,mark:`card`}));let m=r+10-5;p.forEach((t,r)=>{m+=16,d.push(J(e+10,m,t,{size:13.5,fill:i(`ink`),weight:`bold`})),r===0&&c&&d.push(ro(e+n-10-u,m-.5,l,{size:10.5,fill:i(`accent-soft`),ink:i(`accent`)}).svg)}),m+=1;for(let n of h)m+=13,d.push(J(e+10,m,n,{size:10.5,fill:i(t.harness===`codex`?`check`:`accent`),weight:`bold`}));m+=2;for(let t of x)m+=13.5,d.push(J(e+10,m,t,{size:11,fill:i(`ink-2`)}));_.length&&(m+=1);for(let t of _)m+=13,d.push(J(e+10,m,t,{size:10,fill:i(`ink-3`)}));if(y.forEach((t,n)=>{m+=n===0?15:13,n===0&&d.push(`<circle data-wakes="" cx="${K(e+10+4.2)}" cy="${K(m-3.4)}" r="3.6" fill="none" stroke-width="1.8" stroke-dasharray="1.5 2.2" style="stroke:${i(`merge`)}"/>`),d.push(J(e+10+13,m,t,{size:10,fill:i(`merge`),weight:`bold`}))}),t.graph&&(m+=15,d.push(J(e+10,m,no(`graph: ${t.graph}`,s,10,`mono`),{size:10,fill:i(`loop-0`),weight:`mono`}))),f){m+=19;let t=f.working===0&&f.waiting===0&&(f.quiet??0)>0,n=f.working>0?`accent`:f.waiting>0?`warning`:`ink-3`,r=e+10+4.5;d.push(f.working>0?`<circle cx="${K(r)}" cy="${K(m-3.6)}" r="4.5" style="fill:${i(n)}"/>`:`<circle cx="${K(r)}" cy="${K(m-3.6)}" r="3.6" stroke-width="1.8" style="fill:${f.waiting>0||t?`none`:i(n)};stroke:${i(n)}"/>`),d.push(J(e+10+14,m,no(Wa(f,a.at),s-14,10.5,`bold`),{size:10.5,fill:i(n),weight:`bold`}))}return`<g data-session="${t.id}"${f?` data-live="${f.working>0?`working`:f.waiting>0?`waiting`:(f.quiet??0)>0?`quiet`:`ended`}"`:``}>${d.join(``)}</g>`}}}function To(e,t,n,r,i,a=0){let o=[],s=n-2,c=e.place??``,l=c?ro(0,0,c,{size:9.5,fill:i(`surface`),ink:i(`ink-2`),stroke:i(`line-strong`)}):void 0;q(e.name||e.id,s-(l?l.width+8:0),12.5,2+a,`bold`).forEach((e,a)=>{a>0&&(r+=15),o.push(J(t+2,r,e,{size:12.5,fill:i(`ink`),weight:`bold`})),a===0&&l&&o.push(ro(t+n-l.width,r-.5,c,{size:9.5,fill:i(`surface`),ink:i(`ink-2`),stroke:i(`line-strong`)}).svg)});for(let n of q(`${e.machine} · ${e.account}`,s,10.5,3+a))r+=13.5,o.push(J(t+2,r,n,{size:10.5,fill:i(`ink-3`)}));return{svg:o,cardsTop:r+9.5}}var Eo=(e,t)=>t.carrier?Yr(e,t)||`${Br[t.carrier.kind]} (not named)`:`no carrier named`;function Do(e,t,n,r,i,a,o,s=0){let c=lo(t),l=o(c.color),u=r+24,d=a-24,f=[],p=i+12;if(f.push(bo(r+8,p-4,String(n),l,o)),q(t.from===t.to?`${qr(e,t.from)} → itself`:`${qr(e,t.from)} → ${qr(e,t.to)}`,d,12,2+s,`bold`).forEach((e,t)=>{t>0&&(p+=14),f.push(J(u,p,e,{size:12,fill:o(`ink`),weight:`bold`}))}),p+=14,f.push(`<path d="M${K(u)},${K(p-3.5)} h18" ${uo(c,l)}/>`),q(Eo(e,t),d-24,11,2+s,`bold`).forEach((e,t)=>{t>0&&(p+=13.5),f.push(J(u+24,p,e,{size:11,fill:l,weight:`bold`}))}),t.what)for(let e of q(t.what,d,11,4+s))p+=13.5,f.push(J(u,p,e,{size:11,fill:o(`ink-2`)}));return p+=11,{svg:`<g data-handoff-row="${t.id}">${Y(r-4,i-2,a+8,p-i-3,{fill:`transparent`,rx:8,mark:`row`})}${f.join(``)}</g>`,bottom:p}}var Oo=16,ko=14;function Ao(e,t={}){let n=t.theme??`auto`,r=t.width??400,i=Ya(n),a=e.lanes,{sessions:o,people:s,handoffs:c,numberOf:l}=mo(e),u=new Map;for(let e of s)u.set(e.id,u.size);for(let e of a)for(let t of o)t.lane===e.id&&u.set(t.id,u.size);let d=new Map;for(let e of c)(d.get(e.from)??d.set(e.from,[]).get(e.from)).push({handoff:e.id,end:`from`,other:u.get(e.to)}),(d.get(e.to)??d.set(e.to,[]).get(e.to)).push({handoff:e.id,end:`to`,other:u.get(e.from)});for(let[e,t]of d){let n=u.get(e),r=e=>e.other<n?0:e.other===n?1:2;t.sort((e,t)=>r(e)-r(t)||(r(e)===0?t.other-e.other:e.other-t.other)||l.get(e.handoff)-l.get(t.handoff)||(e.end===`from`?-1:1))}let f=(e,t,n)=>u.get(e)*1e3+d.get(e).findIndex(e=>e.handoff===t&&e.end===n),{tracks:p,count:m}=ao(c.map(e=>({from:f(e.from,e.id,`from`),to:f(e.to,e.id,`to`)}))),h=r-24,g=h-16,_=e=>(e-Oo-ko)/(m-1),v=m<=1?13:Math.min(13,Math.max(oo,_(g*.43999999999999995)),Math.max(_(g-120),_(g*.43999999999999995))),y=c.length===0?0:Oo+(m-1)*v+ko,b=h-16-y,x=[],S=ho(e,r,t,i,x),C=new Map,w=[];if(s.length>0){let e=S,t=[],n=e+8+12;t.push(J(22,n,s.length===1?`Person`:`People`,{size:12.5,fill:i(`ink`),weight:`bold`})),n+=9.5;for(let e of s){let t=d.get(e.id)??[],r=Co(e,b,t.length,i);C.set(e.id,{height:r.height,y:n,slots:t}),w.push(r.draw(20,n)),n+=r.height+8}let r=n+8-8;x.push(`<g data-people="">${Y(12,e,h,r-e,{fill:i(`surface-2`),stroke:i(`line`),rx:12,dash:`5 4`})}${t.join(``)}</g>`),S=r+10}for(let n of a){let r=S,a=To(n,20,b,r+8+12,i),s=a.svg,c=a.cardsTop,l=o.filter(e=>e.lane===n.id);for(let n of l){let r=d.get(n.id)??[],a=wo(e,n,b,r.length,i,t);C.set(n.id,{height:a.height,y:c,slots:r}),w.push(a.draw(20,c)),c+=a.height+(a.family?14:8)}l.length===0&&(c+=12,s.push(J(22,c,`no sessions`,{size:10.5,fill:i(`ink-3`)})),c+=8);let u=c+8-8;x.push(`<g data-lane="${n.id}">${Y(12,r,h,u-r,{fill:i(`surface-2`),stroke:i(`line`),rx:12})}${s.join(``)}</g>`),S=u+10}x.push(...w);let T=20+b,E=(e,t,n)=>{let r=C.get(e),i=r.slots.findIndex(e=>e.handoff===t&&e.end===n);return r.y+r.height/2+(i-(r.slots.length-1)/2)*13},D=c.map((e,t)=>({y1:E(e.from,e.id,`from`),y2:E(e.to,e.id,`to`),x:T+Oo+p[t]*v})),O=D.flatMap((e,t)=>[e.y1,e.y2].map(n=>({y:n,from:-1/0,to:e.x,of:t}))),ee=[],k=[],A=[],j=[];if(c.forEach((e,t)=>{let n=lo(e),r=i(n.color),{y1:a,y2:o,x:s}=D[t],c=Math.min(6,Math.abs(o-a)/2),u=o>=a?1:-1,d=`<path d="M${K(T+.5)},${K(o)} l6.5,-3.6 v7.2 z" style="fill:${r}"/>`,f=`<circle cx="${K(T)}" cy="${K(a)}" r="2.2" style="fill:${r}"/>`,p=String(l.get(e.id)),m=xo(s,a,o,_o(p),t,ee,O),h=a+u*c,g=o-u*c,_=m-u*go,v=m+u*go,y=(_-h)*u>=0&&(g-v)*u>=0,b=y?`V${K(_)} M${K(s)},${K(v)} V${K(g)}`:`V${K(g)}`,x=`<path d="${`M${K(T)},${K(a)} H${K(s-c)} Q${K(s)},${K(a)} ${K(s)},${K(h)} ${b} Q${K(s)},${K(o)} ${K(s-c)},${K(o)} H${K(T+5.5)}`}" ${uo(n,r)}/>${f}${d}`,S=`<g data-plate="${e.id}">${vo(s,m,p,r,i)}</g>`;y&&k.push(S),A.push(`<g data-handoff="${e.id}">${x}</g>${y?``:S}`),j.push(`<g data-number="${e.id}">${yo(s,m,p,i)}</g>`)}),x.push(...k,...A,...j),e.handoffs.length>0){S+=6,x.push(J(12,S+11,`Handoffs`,{size:12.5,fill:i(`ink`),weight:`bold`})),S+=20;for(let t of e.handoffs){let n=Do(e,t,l.get(t.id),12,S,r-24,i);x.push(n.svg),S=n.bottom}}return io(r,S+12-6,e.name||e.id,n,i,x.join(``),`map`)}var jo=[go,12,8,13,13,oo,400,ao,_o,Eo,mo,K,io,Do,ho,Ya,To,bo,vo,yo,Co,xo,Y,wo,uo,lo,J,to,q],Mo=12,No=10,Po=30,Fo=13,Io=16,Lo=12,Ro=6,zo={agent:{label:`Agent`,color:`accent`},"human-gate":{label:`Human gate`,color:`gate`},check:{label:`Check`,color:`check`},merge:{label:`Merge`,color:`merge`},stop:{label:`Stop`,color:`stop`}},Bo={label:`Person`,color:`gate`},Vo=e=>L(e)?Bo:zo[e.kind];function Ho(e){switch(e.kind){case`agent`:{let t=typeof e.role==`string`?e.role:e.role.custom;return L(e)?t:[t,e.model?.tier,e.effort].filter(Boolean).join(` · `)}case`human-gate`:return e.options&&e.options.length>0?e.options.join(` / `):e.prompt;case`check`:return[e.check.kind,e.check.run].filter(Boolean).join(` · `);case`merge`:return[e.strategy,e.merges.length>0?`merges ${e.merges.join(`, `)}`:void 0].filter(Boolean).join(` · `);case`stop`:return e.outcome??`ends the run`}}function Uo(e){let t=e.when??`always`;return[typeof t==`object`?t.verdict:t===`always`?e.label??``:t,e.approval?`approval`:``].filter(e=>e!==``).join(` · `)}function Wo(e,t){if(t!==void 0)return{color:`loop-${t%4}`,dash:`5 3`,width:1.6};if(e.approval)return{color:`gate`,width:2};let n=e.when??`always`;return n===`fail`?{color:`warning`,dash:`5 3`,width:1.5}:typeof n==`object`?{color:`ink-3`,dash:`1.5 3`,width:1.7}:{color:`ink-2`,width:1.5}}function Go(e,t={},n){let r=et(n?.whole??e),i=t.theme??`auto`,a=t.width??400,o=Ya(i),s=ke(e),c=new Map(e.nodes.map(e=>[e.id,e])),l=n?.ranks??sa(e),u=l.flat(),d=new Map(u.map((e,t)=>[e,t])),f=new Map;l.forEach((e,t)=>e.forEach(e=>f.set(e,t)));let p=new Map;e.loops.forEach((e,t)=>{for(let n of e.back)p.has(n)||p.set(n,t)});let m=e.edges.filter(e=>c.has(e.from)&&c.has(e.to)),h=e=>p.has(e.id)||e.from===e.to?`right`:d.get(e.to)===d.get(e.from)+1?`next`:`left`,g=e=>{let t=new Map;m.forEach((n,r)=>{h(n)===e&&((t.get(n.from)??t.set(n.from,[]).get(n.from)).push({edge:n.id,end:`from`,other:d.get(n.to),n:r}),(t.get(n.to)??t.set(n.to,[]).get(n.to)).push({edge:n.id,end:`to`,other:d.get(n.from),n:r}))});for(let[e,n]of t){let t=d.get(e),r=e=>e.other<t?0:e.other===t?1:2;n.sort((e,t)=>r(e)-r(t)||(r(e)===0?t.other-e.other:e.other-t.other)||e.n-t.n||(e.end===`from`?-1:1))}return t},_={left:g(`left`),right:g(`right`)},v=(e,t,n,r)=>_[e].get(t).findIndex(e=>e.edge===n&&e.end===r),y=e=>{let t=m.filter(t=>h(t)===e),n=(t,n,r)=>d.get(t)*1e3+v(e,t,n.id,r),{tracks:r,count:i}=ao(t.map(e=>({from:n(e.from,e,`from`),to:n(e.to,e,`to`)})));return{list:t,tracks:r,margin:t.length===0?0:Io+(i-1)*Fo+12}},b=y(`left`),x=y(`right`),S=l.some(e=>e.length>1),C=Mo+b.margin+(S?Ro:0),w=a-24-b.margin-x.margin-(S?12:0),T=w-20,E=t=>e.loops.map((e,n)=>e.members.includes(t)?n:-1).filter(e=>e>=0),D=[],O=18;for(let t of q(e.name||e.id,a-24,17,2,`bold`))O+=17,D.push(J(Mo,O,t,{size:17,fill:o(`ink`),weight:`bold`})),O+=4;let ee=[e.target?.harness,e.nodes.length>0?Or(Tr(n?.whole??e)):`no nodes yet`].filter(Boolean).join(` · `);for(let e of q(ee,a-24,11,2))O+=13,D.push(J(Mo,O,e,{size:11,fill:o(`ink-3`)}));if(e.goal){O+=5;for(let t of q(e.goal,a-24,11.5,3))O+=14.5,D.push(J(Mo,O,t,{size:11.5,fill:o(`ink-2`)}))}O+=14;let k=new Map;for(let e of u){let t=c.get(e),r=q(t.name||t.id,T,13.5,2,`bold`),i=n?.faces.get(e),a=i?i.sub.flatMap(e=>q(e,T,10.5,2)):Ho(t)?q(Ho(t),T,10.5,2):[],o=i?i.extra:t.kind===`agent`&&(t.irreversible??[]).length>0?`irreversible: ${t.irreversible.join(`, `)}`:``,s=24+r.length*15.5+a.length*13+(o?14:0)+No-3+(i?.room??0),l=(_.left.get(e)??[]).map(e=>e.edge),u=(_.right.get(e)??[]).map(e=>e.edge);k.set(e,{node:t,name:r,sub:a,extra:o,height:Math.max(s,(Math.max(l.length,u.length)+1)*Lo+2),y:0,left:l,right:u})}let A=[];l.forEach((e,t)=>{O+=n?.gaps[t]??0;let r=O;e.forEach((t,n)=>{let r=k.get(t);r.y=O+(e.length>1&&n===0?16:0),O=r.y+r.height+(n<e.length-1?8:0)}),e.length>1&&A.push(Y(C-Ro,r-Ro+2,w+12,O-r+12-2,{fill:o(`surface-2`),stroke:o(`line`),rx:12})+J(C+2,r+9,`${e.length} side by side`,{size:9.5,fill:o(`ink-3`),weight:`bold`})),t<l.length-1&&(O+=Po)}),D.push(...A);let j=n?.draw(k,C,w,o);j&&D.push(j[0]);let M=[],N=m.filter(e=>h(e)===`next`);for(let e of N){let t=k.get(e.from),n=k.get(e.to),r=N.filter(t=>t.from===e.from&&t.to===e.to),i=C+w/2+(r.indexOf(e)-(r.length-1)/2)*64,a=t.y+t.height,s=n.y,c=Wo(e,void 0),l=o(c.color);D.push(`<g data-edge="${e.id}"><path d="M${K(i)},${K(a)} V${K(s-5.5)}" fill="none" stroke-width="${K(c.width)}" stroke-linecap="round"${c.dash?` stroke-dasharray="${c.dash}"`:``} style="stroke:${l}"/><path d="M${K(i)},${K(s-.5)} l-3.6,-6.5 h7.2 z" style="fill:${l}"/></g>`);let u=Uo(e);if(u){let e=to(u,9.5,`bold`)+10.5;M.push(ro(i-e/2,(a+s)/2+3.2,u,{size:9.5,fill:o(`bg`),ink:l,stroke:l}).svg)}}let P=(e,t)=>{let n=e===`right`?1:-1,r=e===`right`?C+w:C,i=[],a=(t,n,r)=>{let i=k.get(t),a=_[e].get(t);return i.y+i.height/2+(v(e,t,n,r)-(a.length-1)/2)*Lo};t.list.forEach((e,s)=>{let c=Wo(e,p.get(e.id)),l=o(c.color),u=a(e.from,e.id,`from`),d=a(e.to,e.id,`to`),f=r+n*(Io+t.tracks[s]*Fo),m=Math.min(6,Math.abs(d-u)/2),h=d>=u?1:-1,g=`M${K(r)},${K(u)} H${K(f-n*m)} Q${K(f)},${K(u)} ${K(f)},${K(u+h*m)} V${K(d-h*m)} Q${K(f)},${K(d)} ${K(f-n*m)},${K(d)} H${K(r+n*5.5)}`;D.push(`<g data-edge="${e.id}"><path d="${g}" fill="none" stroke-width="${K(c.width)}" stroke-linecap="round"${c.dash?` stroke-dasharray="${c.dash}"`:``} style="stroke:${l}"/><circle cx="${K(r)}" cy="${K(u)}" r="2.2" style="fill:${l}"/><path d="M${K(r+n*.5)},${K(d)} l${K(n*6.5)},-3.6 v7.2 z" style="fill:${l}"/></g>`);let _=Uo(e);if(!_)return;let v=to(_,9,`bold`)+9,y=Math.min(u,d)+v/2+2,b=Math.max(u,d)-v/2-2,x=e=>i.every(t=>Math.abs(t.x-f)>14||Math.abs(t.y-e)>(t.w+v)/2+2),S=(u+d)/2;for(let e=1;!x(S)&&e<60;e++){let t=(u+d)/2+(e%2==1?1:-1)*Math.ceil(e/2)*7;t>=y&&t<=b&&x(t)&&(S=t)}i.push({x:f,y:S,w:v}),M.push(`<g transform="rotate(-90 ${K(f)} ${K(S)})">`+Y(f-v/2,S-6.5,v,13,{fill:o(`bg`),stroke:l,rx:6.5})+J(f,S+3.2,_,{size:9,fill:l,weight:`bold`,anchor:`middle`})+`</g>`)})};P(`left`,b),P(`right`,x);for(let e of u){let t=k.get(e),{node:r}=t,i=n?.faces.get(e)??Vo(r),a=[],s=r.kind===`human-gate`;a.push(Y(C,t.y,w,t.height,{fill:o(`surface`),stroke:o(s?`gate`:`line-strong`),rx:r.kind===`stop`?16:9,width:s?1.8:1,mark:`card`}));let c=t.y+No+8;a.push(`<circle cx="${K(C+No+3.5)}" cy="${K(c-3.4)}" r="3.5" style="fill:${o(i.color)}"/>`),a.push(J(C+No+11,c,i.label,{size:9.5,fill:o(i.color),weight:`bold`})),E(e).forEach((e,t)=>{a.push(`<circle cx="${K(C+w-No-3.5-t*10)}" cy="${K(c-3.4)}" r="3.5" style="fill:${o(`loop-${e%4}`)}"/>`)}),c+=4;for(let e of t.name)c+=15.5,a.push(J(C+No,c,e,{size:13.5,fill:o(`ink`),weight:`bold`}));for(let e of t.sub)c+=13,a.push(J(C+No,c,e,{size:10.5,fill:o(`ink-2`)}));t.extra&&(c+=14,a.push(J(C+No,c,no(t.extra,T,10,`bold`),{size:10,fill:o(`gate`),weight:`bold`}))),D.push(`<g data-${i===Vo(r)?`node`:`group`}="${e}">${a.join(``)}</g>`)}if(j&&D.push(j[1]),D.push(...M),O+=14,e.loops.length>0){O+=4,D.push(J(Mo,O+11,e.loops.length===1?`Loop`:`Loops`,{size:12.5,fill:o(`ink`),weight:`bold`})),O+=20;let t=a-Mo-28,n=e=>c.get(e)?.name||e;e.loops.forEach((e,i)=>{let a=o(`loop-${i%4}`),c=[];O+=12,c.push(`<circle cx="${K(17)}" cy="${K(O-4)}" r="4.5" style="fill:${a}"/>`),c.push(J(28,O,no(e.name||e.id,t,12,`bold`),{size:12,fill:o(`ink`),weight:`bold`}));let l=(e,n,r=`ink-2`)=>{for(let i of q(e,t,11,n))O+=13.5,c.push(J(28,O,i,{size:11,fill:o(r)}))};l(`${Ye(s,e)} loop · ${e.members.map(n).join(`, `)}`,2,`ink-3`),e.bar&&l(`Bar: ${e.bar.name}. ${e.bar.acceptance}`,3),e.stops.forEach((e,t)=>l(`${t+1}. ${Qe(e)}: ${$e(e,r).replace(/`/g,``)}`,2)),O+=12,D.push(`<g data-loop="${e.id}">${c.join(``)}</g>`)})}return io(a,O+Mo-6,e.name||e.id,i,o,D.join(``),`graph`)}var Ko={agent:`Agent`,"human-gate":`Human gate`,check:`Check`,merge:`Merge`,stop:`Stop`},X=(e,t)=>t===void 0?[]:Array.isArray(t)?t.length>0?[{label:e,list:t}]:[]:t.trim()===``?[]:[{label:e,text:t}];function qo(e,t,n,r){let i=e.when??`always`,a=typeof i==`object`?`on verdict "${i.verdict}"`:i===`always`?`always`:`on ${i}`,o=[r?`back edge: starts the next round`:void 0,t===`to`?`${e.isolation??`fresh`} context`:void 0,e.evidence&&e.evidence.length>0?`sees ${e.evidence.join(`, `)}`:void 0,e.approval?`needs a person's approval`:void 0,e.concurrency?`at most ${e.concurrency.max} at once`:void 0,e.retry?`retry up to ${e.retry.max}`:void 0,e.label].filter(e=>e!==void 0&&e!==``);return`${a}, ${t} ${n(e[t])}${o.length>0?` (${o.join(`; `)})`:``}`}function Jo(e){let t=ke(e),n=new Map(e.nodes.map(e=>[e.id,e])),r=e=>n.get(e)?.name||e,i=new Set(e.loops.flatMap(e=>e.back)),a=[],o=e.groups??[],s=e=>o.find(t=>t.members.includes(e)),c=e=>{let t=s(e);for(let e=0;t&&!t.from&&e<o.length;e++)t=s(t.id);return t?.from?t:void 0},l=e=>c(e)?{inside:c(e).id}:{},u=Tr(e),d=et(e);a.push({id:e.id,kind:e.template?`Template`:`Graph`,title:e.name||e.id,items:[...X(`Goal`,e.goal),...X(`About`,e.description),...X(`Shape`,e.nodes.length>0?Or(u):void 0),...X(`Model tiers`,u.agents>0?kr(u):void 0),...X(`Runs in`,e.target?.harness),...X(`Budget`,e.constraints?.budget),...X(`Time`,e.constraints?.time),...X(`Other limits`,e.constraints?.other),...X(`If the graph turns out wrong`,e.adaptation===`fixed`?`fixed: the lead follows it exactly, or halts and asks`:e.adaptation===`propose`?`propose: the lead changes nothing and records proposals`:`adaptive: the lead may amend its working copy, visibly, and is told never to loosen a brake`),...X(`Version`,`${e.id}@${e.version}`)]});for(let t of sa(e).flat()){let o=n.get(t),s=e.edges.filter(e=>e.from===t&&n.has(e.to)).map(e=>qo(e,`to`,r,i.has(e.id))),u=e.edges.filter(e=>e.to===t&&n.has(e.from)).map(e=>qo(e,`from`,r,i.has(e.id))),d=e.loops.filter(e=>e.members.includes(t)).map(e=>e.name||e.id),f=(()=>{switch(o.kind){case`agent`:{let e=!L(o);return[...X(`Role`,typeof o.role==`string`?o.role:`${o.role.custom} (custom)`),...e?X(`Model`,[o.model?.tier??`session default`,...Object.entries(o.model?.pin??{}).map(([e,t])=>`${e}: ${t}`),o.effort?`${o.effort} effort`:``].filter(e=>e!==``).join(` · `)):[],...X(`Brief`,o.brief),...X(`Expects`,o.inputs),...X(`Leaves behind`,o.outputs),...e?[...X(`May`,o.allow),...X(`May not`,o.deny),...X(`Skills`,o.skills)]:[],...X(`Owns`,o.owns),...X(`Irreversible`,o.irreversible)]}case`human-gate`:return[...X(`Asks`,o.prompt),...X(`Answers`,o.options)];case`check`:return[...X(`Checks`,o.check.kind),...X(`Runs`,o.check.run),...X(`Passes when`,o.check.pass),...X(`Threshold`,o.check.threshold===void 0?void 0:String(o.check.threshold))];case`merge`:return[...X(`Merges`,o.merges),...X(`How`,o.strategy)];case`stop`:return[...X(`Ends the run with`,o.outcome??`its last result`)]}})();a.push({id:t,kind:L(o)?`Person`:Ko[o.kind],title:o.name||o.id,items:[...X(`About`,o.description),...X(`Part of`,c(t)?.name),...f,...X(`In loop`,d),...X(`Then`,s),...X(`Reached`,u)],...l(t)})}for(let t of o)t.from&&a.push({id:t.id,kind:`Subgrooph`,title:t.name,items:[...X(`About`,t.description),...X(`Placed from`,`the template ${t.from.replace(`@`,`, version `)}`),...X(`Filled with`,Object.entries(t.with??{}).map(([e,t])=>`${e}: ${t}`)),...X(`Part of`,c(t.id)?.name),...X(`Holds`,[...e.nodes,...o].filter(e=>c(e.id)===t&&(!(`members`in e)||e.from)).map(e=>e.name||e.id))],...l(t.id)});for(let n of e.loops)a.push({id:n.id,kind:`Loop`,title:n.name||n.id,items:[...X(`Kind`,`${Ye(t,n)} loop`),...X(`Members`,n.members.map(r)),...X(`Bar`,n.bar?.name),...X(`Good enough to stop`,n.bar?.acceptance),...X(`Aiming at`,n.bar?.aspiration),...X(`The critic inspects`,n.bar?.inspects.map(e=>`${e.kind}: ${e.ref}${e.note?` (${e.note})`:``}`)),...X(`Stops, in order`,n.stops.map(e=>`${Qe(e)}: ${$e(e,d).replace(/`/g,``)}`))]});for(let t of e.policies??[])a.push({id:t.id,kind:`Policy`,title:typeof t.kind==`string`?t.kind:t.kind.custom,items:[...X(`Applies to`,t.scope),...X(`Settings`,Object.entries(t.params??{}).map(([e,t])=>`${e}: ${String(t)}`))]});return a}function Yo(e){let t=t=>qr(e,t),n=e=>e===`claude-code`?`Claude Code`:e===`codex`?`Codex`:e,r=(n,r)=>`${r} ${n.from===n.to?`itself`:t(n[r])}, by ${Yr(e,n)||(n.carrier?`${Br[n.carrier.kind]} (not named)`:`no named carrier`)}${n.what?`: ${n.what}`:``}`,i=[{id:e.id,kind:`Operation map`,title:e.name||e.id,items:[...X(`As of`,e.asOf),...X(`Shape`,Kr(Gr(e))),...X(`About`,e.description),...X(`Version`,`${e.id}@${e.version}`)]}];for(let t of e.people??[])i.push({id:t.id,kind:`Person`,title:t.name||t.id,items:[...X(`Role`,t.role),...X(`About`,t.description),...X(`Hands work`,e.handoffs.filter(e=>e.from===t.id).map(e=>r(e,`to`))),...X(`Is handed work`,e.handoffs.filter(e=>e.to===t.id).map(e=>r(e,`from`)))]});for(let t of e.lanes){i.push({id:t.id,kind:`Lane`,title:t.name||t.id,items:[...X(`Machine`,`${t.machine}${t.place?` (${t.place})`:``}`),...X(`Account`,t.account),...X(`About`,t.description),...X(`Sessions`,e.sessions.filter(e=>e.lane===t.id).map(e=>e.name||e.id))]});for(let a of e.sessions.filter(e=>e.lane===t.id)){let t=Xr(e,a.id);i.push({id:a.id,kind:`Session`,title:a.name||a.id,items:[...X(`Role`,a.role),...X(`Runs on`,[n(a.harness),a.model].filter(Boolean).join(` · `)),...X(`How many`,a.count&&a.count>1?`${a.count} like sessions, drawn as one`:void 0),...X(`Lifetime`,a.lifetime===`per-task`?`per task`:a.lifetime),...X(`Wakes itself`,t===void 0?void 0:t===``?`on a schedule`:t),...X(`Repository`,a.repo),...X(`Its graph`,a.graph),...X(`About`,a.description),...X(`Hands work`,e.handoffs.filter(e=>e.from===a.id).map(e=>r(e,`to`))),...X(`Is handed work`,e.handoffs.filter(e=>e.to===a.id).map(e=>r(e,`from`)))]})}}return i}function Xo(e){let t=[];return e.forEach((e,n)=>{t.push(`${n===0?`#`:`##`} ${n===0?``:`${e.kind}: `}${e.title}`,``),n>0&&t.push(`\`${e.id}\``,``);for(let n of e.items)if(n.list){t.push(`**${n.label}**`,``);for(let e of n.list)t.push(`- ${e}`);t.push(``)}else(n.text??``).includes(`
5
+ `)||(n.text??``).length>90?t.push(`**${n.label}**`,``,n.text.trim(),``):t.push(`**${n.label}:** ${n.text}`,``)}),`${t.join(`
6
+ `).replace(/\n{3,}/g,`
7
+
8
+ `).trimEnd()}\n`}var Zo=[Ee,zr,da,r,Rr,Wa,Yo,Ao,Jo,Go,_n,Wr],Z=Uint8Array,Qo=Uint16Array,$o=Int32Array,es=new Z([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),ts=new Z([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),ns=new Z([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),rs=function(e,t){for(var n=new Qo(31),r=0;r<31;++r)n[r]=t+=1<<e[r-1];for(var i=new $o(n[30]),r=1;r<30;++r)for(var a=n[r];a<n[r+1];++a)i[a]=a-n[r]<<5|r;return{b:n,r:i}},is=rs(es,2),as=is.b,os=is.r;as[28]=258,os[258]=28;for(var ss=rs(ts,0),cs=ss.b,ls=ss.r,us=new Qo(32768),Q=0;Q<32768;++Q){var ds=(Q&43690)>>1|(Q&21845)<<1;ds=(ds&52428)>>2|(ds&13107)<<2,ds=(ds&61680)>>4|(ds&3855)<<4,us[Q]=((ds&65280)>>8|(ds&255)<<8)>>1}for(var fs=(function(e,t,n){for(var r=e.length,i=0,a=new Qo(t);i<r;++i)e[i]&&++a[e[i]-1];var o=new Qo(t);for(i=1;i<t;++i)o[i]=o[i-1]+a[i-1]<<1;var s;if(n){s=new Qo(1<<t);var c=15-t;for(i=0;i<r;++i)if(e[i])for(var l=i<<4|e[i],u=t-e[i],d=o[e[i]-1]++<<u,f=d|(1<<u)-1;d<=f;++d)s[us[d]>>c]=l}else for(s=new Qo(r),i=0;i<r;++i)e[i]&&(s[i]=us[o[e[i]-1]++]>>15-e[i]);return s}),ps=new Z(288),Q=0;Q<144;++Q)ps[Q]=8;for(var Q=144;Q<256;++Q)ps[Q]=9;for(var Q=256;Q<280;++Q)ps[Q]=7;for(var Q=280;Q<288;++Q)ps[Q]=8;for(var ms=new Z(32),Q=0;Q<32;++Q)ms[Q]=5;var hs=fs(ps,9,0),gs=fs(ps,9,1),_s=fs(ms,5,0),vs=fs(ms,5,1),ys=function(e){for(var t=e[0],n=1;n<e.length;++n)e[n]>t&&(t=e[n]);return t},bs=function(e,t,n){var r=t/8|0;return(e[r]|e[r+1]<<8)>>(t&7)&n},xs=function(e,t){var n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(t&7)},Ss=function(e){return(e+7)/8|0},Cs=function(e,t,n){return(t==null||t<0)&&(t=0),(n==null||n>e.length)&&(n=e.length),new Z(e.subarray(t,n))},ws=[`unexpected EOF`,`invalid block type`,`invalid length/literal`,`invalid distance`,`stream finished`,`no stream handler`,,`no callback`,`invalid UTF-8 data`,`extra field too long`,`date not in range 1980-2099`,`filename too long`,`stream finishing`,`invalid zip data`],Ts=function(e,t,n){var r=Error(t||ws[e]);if(r.code=e,Error.captureStackTrace&&Error.captureStackTrace(r,Ts),!n)throw r;return r},Es=function(e,t,n,r){var i=e.length,a=r?r.length:0;if(!i||t.f&&!t.l)return n||new Z(0);var o=!n,s=o||t.i!=2,c=t.i;o&&(n=new Z(i*3));var l=function(e){var t=n.length;if(e>t){var r=new Z(Math.max(t*2,e));r.set(n),n=r}},u=t.f||0,d=t.p||0,f=t.b||0,p=t.l,m=t.d,h=t.m,g=t.n,_=i*8;do{if(!p){u=bs(e,d,1);var v=bs(e,d+1,3);if(d+=3,!v){var y=Ss(d)+4,b=e[y-4]|e[y-3]<<8,x=y+b;if(x>i){c&&Ts(0);break}s&&l(f+b),n.set(e.subarray(y,x),f),t.b=f+=b,t.p=d=x*8,t.f=u;continue}if(v==1)p=gs,m=vs,h=9,g=5;else if(v==2){var S=bs(e,d,31)+257,C=bs(e,d+10,15)+4,w=S+bs(e,d+5,31)+1;d+=14;for(var T=new Z(w),E=new Z(19),D=0;D<C;++D)E[ns[D]]=bs(e,d+D*3,7);d+=C*3;for(var O=ys(E),ee=(1<<O)-1,k=fs(E,O,1),D=0;D<w;){var A=k[bs(e,d,ee)];d+=A&15;var y=A>>4;if(y<16)T[D++]=y;else{var j=0,M=0;for(y==16?(M=3+bs(e,d,3),d+=2,j=T[D-1]):y==17?(M=3+bs(e,d,7),d+=3):y==18&&(M=11+bs(e,d,127),d+=7);M--;)T[D++]=j}}var N=T.subarray(0,S),P=T.subarray(S);h=ys(N),g=ys(P),p=fs(N,h,1),m=fs(P,g,1)}else Ts(1);if(d>_){c&&Ts(0);break}}s&&l(f+131072);for(var F=(1<<h)-1,te=(1<<g)-1,ne=d;;ne=d){var j=p[xs(e,d)&F],re=j>>4;if(d+=j&15,d>_){c&&Ts(0);break}if(j||Ts(2),re<256)n[f++]=re;else if(re==256){ne=d,p=null;break}else{var ie=re-254;if(re>264){var D=re-257,I=es[D];ie=bs(e,d,(1<<I)-1)+as[D],d+=I}var ae=m[xs(e,d)&te],oe=ae>>4;ae||Ts(3),d+=ae&15;var P=cs[oe];if(oe>3){var I=ts[oe];P+=xs(e,d)&(1<<I)-1,d+=I}if(d>_){c&&Ts(0);break}s&&l(f+131072);var se=f+ie;if(f<P){var ce=a-P,le=Math.min(P,se);for(ce+f<0&&Ts(3);f<le;++f)n[f]=r[ce+f]}for(;f<se;++f)n[f]=n[f-P]}}t.l=p,t.p=ne,t.b=f,t.f=u,p&&(u=1,t.m=h,t.d=m,t.n=g)}while(!u);return f!=n.length&&o?Cs(n,0,f):n.subarray(0,f)},Ds=function(e,t,n){n<<=t&7;var r=t/8|0;e[r]|=n,e[r+1]|=n>>8},Os=function(e,t,n){n<<=t&7;var r=t/8|0;e[r]|=n,e[r+1]|=n>>8,e[r+2]|=n>>16},ks=function(e,t){for(var n=[],r=0;r<e.length;++r)e[r]&&n.push({s:r,f:e[r]});var i=n.length,a=n.slice();if(!i)return{t:Is,l:0};if(i==1){var o=new Z(n[0].s+1);return o[n[0].s]=1,{t:o,l:1}}n.sort(function(e,t){return e.f-t.f}),n.push({s:-1,f:25001});var s=n[0],c=n[1],l=0,u=1,d=2;for(n[0]={s:-1,f:s.f+c.f,l:s,r:c};u!=i-1;)s=n[n[l].f<n[d].f?l++:d++],c=n[l!=u&&n[l].f<n[d].f?l++:d++],n[u++]={s:-1,f:s.f+c.f,l:s,r:c};for(var f=a[0].s,r=1;r<i;++r)a[r].s>f&&(f=a[r].s);var p=new Qo(f+1),m=As(n[u-1],p,0);if(m>t){var r=0,h=0,g=m-t,_=1<<g;for(a.sort(function(e,t){return p[t.s]-p[e.s]||e.f-t.f});r<i;++r){var v=a[r].s;if(p[v]>t)h+=_-(1<<m-p[v]),p[v]=t;else break}for(h>>=g;h>0;){var y=a[r].s;p[y]<t?h-=1<<t-p[y]++-1:++r}for(;r>=0&&h;--r){var b=a[r].s;p[b]==t&&(--p[b],++h)}m=t}return{t:new Z(p),l:m}},As=function(e,t,n){return e.s==-1?Math.max(As(e.l,t,n+1),As(e.r,t,n+1)):t[e.s]=n},js=function(e){for(var t=e.length;t&&!e[--t];);for(var n=new Qo(++t),r=0,i=e[0],a=1,o=function(e){n[r++]=e},s=1;s<=t;++s)if(e[s]==i&&s!=t)++a;else{if(!i&&a>2){for(;a>138;a-=138)o(32754);a>2&&(o(a>10?a-11<<5|28690:a-3<<5|12305),a=0)}else if(a>3){for(o(i),--a;a>6;a-=6)o(8304);a>2&&(o(a-3<<5|8208),a=0)}for(;a--;)o(i);a=1,i=e[s]}return{c:n.subarray(0,r),n:t}},Ms=function(e,t){for(var n=0,r=0;r<t.length;++r)n+=e[r]*t[r];return n},Ns=function(e,t,n){var r=n.length,i=Ss(t+2);e[i]=r&255,e[i+1]=r>>8,e[i+2]=e[i]^255,e[i+3]=e[i+1]^255;for(var a=0;a<r;++a)e[i+a+4]=n[a];return(i+4+r)*8},Ps=function(e,t,n,r,i,a,o,s,c,l,u){Ds(t,u++,n),++i[256];for(var d=ks(i,15),f=d.t,p=d.l,m=ks(a,15),h=m.t,g=m.l,_=js(f),v=_.c,y=_.n,b=js(h),x=b.c,S=b.n,C=new Qo(19),w=0;w<v.length;++w)++C[v[w]&31];for(var w=0;w<x.length;++w)++C[x[w]&31];for(var T=ks(C,7),E=T.t,D=T.l,O=19;O>4&&!E[ns[O-1]];--O);var ee=l+5<<3,k=Ms(i,ps)+Ms(a,ms)+o,A=Ms(i,f)+Ms(a,h)+o+14+3*O+Ms(C,E)+2*C[16]+3*C[17]+7*C[18];if(c>=0&&ee<=k&&ee<=A)return Ns(t,u,e.subarray(c,c+l));var j,M,N,P;if(Ds(t,u,1+(A<k)),u+=2,A<k){j=fs(f,p,0),M=f,N=fs(h,g,0),P=h;var F=fs(E,D,0);Ds(t,u,y-257),Ds(t,u+5,S-1),Ds(t,u+10,O-4),u+=14;for(var w=0;w<O;++w)Ds(t,u+3*w,E[ns[w]]);u+=3*O;for(var te=[v,x],ne=0;ne<2;++ne)for(var re=te[ne],w=0;w<re.length;++w){var ie=re[w]&31;Ds(t,u,F[ie]),u+=E[ie],ie>15&&(Ds(t,u,re[w]>>5&127),u+=re[w]>>12)}}else j=hs,M=ps,N=_s,P=ms;for(var w=0;w<s;++w){var I=r[w];if(I>255){var ie=I>>18&31;Os(t,u,j[ie+257]),u+=M[ie+257],ie>7&&(Ds(t,u,I>>23&31),u+=es[ie]);var ae=I&31;Os(t,u,N[ae]),u+=P[ae],ae>3&&(Os(t,u,I>>5&8191),u+=ts[ae])}else Os(t,u,j[I]),u+=M[I]}return Os(t,u,j[256]),u+M[256]},Fs=new $o([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),Is=new Z(0),Ls=function(e,t,n,r,i,a){var o=a.z||e.length,s=new Z(r+o+5*(1+Math.ceil(o/7e3))+i),c=s.subarray(r,s.length-i),l=a.l,u=(a.r||0)&7;if(t){u&&(c[0]=a.r>>3);for(var d=Fs[t-1],f=d>>13,p=d&8191,m=(1<<n)-1,h=a.p||new Qo(32768),g=a.h||new Qo(m+1),_=Math.ceil(n/3),v=2*_,y=function(t){return(e[t]^e[t+1]<<_^e[t+2]<<v)&m},b=new $o(25e3),x=new Qo(288),S=new Qo(32),C=0,w=0,T=a.i||0,E=0,D=a.w||0,O=0;T+2<o;++T){var ee=y(T),k=T&32767,A=g[ee];if(h[k]=A,g[ee]=k,D<=T){var j=o-T;if((C>7e3||E>24576)&&(j>423||!l)){u=Ps(e,c,0,b,x,S,w,E,O,T-O,u),E=C=w=0,O=T;for(var M=0;M<286;++M)x[M]=0;for(var M=0;M<30;++M)S[M]=0}var N=2,P=0,F=p,te=k-A&32767;if(j>2&&ee==y(T-te))for(var ne=Math.min(f,j)-1,re=Math.min(32767,T),ie=Math.min(258,j);te<=re&&--F&&k!=A;){if(e[T+N]==e[T+N-te]){for(var I=0;I<ie&&e[T+I]==e[T+I-te];++I);if(I>N){if(N=I,P=te,I>ne)break;for(var ae=Math.min(te,I-2),oe=0,M=0;M<ae;++M){var se=T-te+M&32767,ce=se-h[se]&32767;ce>oe&&(oe=ce,A=se)}}}k=A,A=h[k],te+=k-A&32767}if(P){b[E++]=268435456|os[N]<<18|ls[P];var le=os[N]&31,ue=ls[P]&31;w+=es[le]+ts[ue],++x[257+le],++S[ue],D=T+N,++C}else b[E++]=e[T],++x[e[T]]}}for(T=Math.max(T,D);T<o;++T)b[E++]=e[T],++x[e[T]];u=Ps(e,c,l,b,x,S,w,E,O,T-O,u),l||(a.r=u&7|c[u/8|0]<<3,u-=7,a.h=g,a.p=h,a.i=T,a.w=D)}else{for(var T=a.w||0;T<o+l;T+=65535){var de=T+65535;de>=o&&(c[u/8|0]=l,de=o),u=Ns(c,u+1,e.subarray(T,de))}a.i=o}return Cs(s,0,r+Ss(u)+i)},Rs=(function(){for(var e=new Int32Array(256),t=0;t<256;++t){for(var n=t,r=9;--r;)n=(n&1&&-306674912)^n>>>1;e[t]=n}return e})(),zs=function(){var e=-1;return{p:function(t){for(var n=e,r=0;r<t.length;++r)n=Rs[n&255^t[r]]^n>>>8;e=n},d:function(){return~e}}},Bs=function(e,t,n,r,i){if(!i&&(i={l:1},t.dictionary)){var a=t.dictionary.subarray(-32768),o=new Z(a.length+e.length);o.set(a),o.set(e,a.length),e=o,i.w=a.length}return Ls(e,t.level==null?6:t.level,t.mem==null?i.l?Math.ceil(Math.max(8,Math.min(13,Math.log(e.length)))*1.5):20:12+t.mem,n,r,i)},Vs=function(e,t){var n={};for(var r in e)n[r]=e[r];for(var r in t)n[r]=t[r];return n},$=function(e,t,n){for(;n;++t)e[t]=n,n>>>=8};function Hs(e,t){return Bs(e,t||{},0,0)}function Us(e,t){return Es(e,{i:2},t&&t.out,t&&t.dictionary)}var Ws=function(e,t,n,r){for(var i in e){var a=e[i],o=t+i,s=r;Array.isArray(a)&&(s=Vs(r,a[1]),a=a[0]),ArrayBuffer.isView(a)?n[o]=[a,s]:(n[o+=`/`]=[new Z(0),s],Ws(a,o,n,r))}},Gs=typeof TextEncoder<`u`&&new TextEncoder,Ks=typeof TextDecoder<`u`&&new TextDecoder;try{Ks.decode(Is,{stream:!0})}catch{}function qs(e,t){if(t){for(var n=new Z(e.length),r=0;r<e.length;++r)n[r]=e.charCodeAt(r);return n}if(Gs)return Gs.encode(e);for(var i=e.length,a=new Z(e.length+(e.length>>1)),o=0,s=function(e){a[o++]=e},r=0;r<i;++r){if(o+5>a.length){var c=new Z(o+8+(i-r<<1));c.set(a),a=c}var l=e.charCodeAt(r);l<128||t?s(l):l<2048?(s(192|l>>6),s(128|l&63)):l>55295&&l<57344?(l=65536+(l&1047552)|e.charCodeAt(++r)&1023,s(240|l>>18),s(128|l>>12&63),s(128|l>>6&63),s(128|l&63)):(s(224|l>>12),s(128|l>>6&63),s(128|l&63))}return Cs(a,0,o)}var Js=function(e){var t=0;if(e)for(var n in e){var r=e[n].length;r>65535&&Ts(9),t+=r+4}return t},Ys=function(e,t,n,r,i,a,o,s){var c=r.length,l=n.extra,u=s&&s.length,d=Js(l);$(e,t,o==null?67324752:33639248),t+=4,o!=null&&(e[t++]=20,e[t++]=n.os),e[t]=20,t+=2,e[t++]=n.flag<<1|(a<0&&8),e[t++]=i&&8,e[t++]=n.compression&255,e[t++]=n.compression>>8;var f=new Date(n.mtime==null?Date.now():n.mtime),p=f.getFullYear()-1980;if((p<0||p>119)&&Ts(10),$(e,t,p<<25|f.getMonth()+1<<21|f.getDate()<<16|f.getHours()<<11|f.getMinutes()<<5|f.getSeconds()>>1),t+=4,a!=-1&&($(e,t,n.crc),$(e,t+4,a<0?-a-2:a),$(e,t+8,n.size)),$(e,t+12,c),$(e,t+14,d),t+=16,o!=null&&($(e,t,u),$(e,t+6,n.attrs),$(e,t+10,o),t+=14),e.set(r,t),t+=c,d)for(var m in l){var h=l[m],g=h.length;$(e,t,+m),$(e,t+2,g),e.set(h,t+4),t+=4+g}return u&&(e.set(s,t),t+=u),t},Xs=function(e,t,n,r,i){$(e,t,101010256),$(e,t+8,n),$(e,t+10,n),$(e,t+12,r),$(e,t+16,i)};function Zs(e,t){t||={};var n={},r=[];Ws(e,``,n,t);var i=0,a=0;for(var o in n){var s=n[o],c=s[0],l=s[1],u=l.level==0?0:8,d=qs(o),f=d.length,p=l.comment,m=p&&qs(p),h=m&&m.length,g=Js(l.extra);f>65535&&Ts(11);var _=u?Hs(c,l):c,v=_.length,y=zs();y.p(c),r.push(Vs(l,{size:c.length,crc:y.d(),c:_,f:d,m,u:f!=o.length||m&&p.length!=h,o:i,compression:u})),i+=30+f+g+v,a+=76+2*(f+g)+(h||0)+v}for(var b=new Z(a+22),x=i,S=a-i,C=0;C<r.length;++C){var d=r[C];Ys(b,d.o,d,d.f,d.u,d.c.length);var w=30+d.f.length+Js(d.extra);b.set(d.c,d.o+w),Ys(b,i,d,d.f,d.u,d.c.length,d.o,d.m),i+=16+w+(d.m?d.m.length:0)}return Xs(b,i,r.length,S,x),b}var Qs=e=>Hs(e,{level:9}),$s=(e,t)=>{let n=Us(e,{out:new Uint8Array(t+1)});if(n.length>t)throw RangeError(`unpacks to more than ${t} bytes`);return n},ec;function tc(e){return ec?.payload!==e&&(ec={payload:e,opened:Wi(e,$s)}),ec.opened}function nc(e){return`#/open?d=${Vi(zi(e),Qs)}`}export{br as $,Xe as $t,zi as A,St as At,fi as B,Tt as Bt,oa as C,Ft as Ct,aa as D,zt as Dt,$i as E,Jt as Et,wi as F,bt as Ft,Yr as G,ut as Gt,Br as H,dt as Ht,Ei as I,Rt as It,Gr as J,Je as Jt,Zr as K,Ue as Kt,Mi as L,Lt,Hi as M,Et as Mt,ji as N,qt as Nt,Fi as O,xt as Ot,Ai as P,Ht as Pt,Tr as Q,nt as Qt,Ni as R,At as Rt,da as S,jt as St,la as T,Ut as Tt,zr as U,ft as Ut,oi as V,mt as Vt,qr as W,z as Wt,Lr as X,qe as Xt,Kr as Y,Ke as Yt,Xr as Z,st as Zt,Ha as _,e as _n,Wt as _t,Zs as a,Be as an,ar as at,Ia as b,gt as bt,Xo as c,Fe as cn,fn as ct,Ao as d,ke as dn,an as dt,We as en,yr as et,co as f,Ee as fn,pt as ft,Va as g,s as gn,kt as gt,Ua as h,ge as hn,Vt as ht,qs as i,rt as in,ir as it,Vi as j,Pt as jt,Li as k,yt as kt,Go as l,Ie as ln,dn as lt,Ra as m,we as mn,wt as mt,nc as n,Ge as nn,kr as nt,Zo as o,He as on,_n as ot,Ba as p,Ce as pn,Mt as pt,Rr as q,Qe as qt,Hs as r,Ye as rn,Xn as rt,Jo as s,$e as sn,Xt as st,tc as t,L as tn,Or as tt,jo as u,Le as un,cn as ut,La as v,r as vn,vt,sa as w,Dt as wt,Da as x,ht as xt,za as y,n as yn,Bt as yt,Pi as z,Nt as zt};
@@ -0,0 +1,223 @@
1
+ /*
2
+ * The site's looks after the first (Grooph, which is apps/web/src/styles.css's :root), chosen in the header's Theme
3
+ * menu and kept in this browser. One file for the app and the document pages, fetched only by a visit that keeps or
4
+ * chooses one of them: the page's head writes its link before the first paint (apps/web/index.html,
5
+ * scripts/site/layout.mjs), and the menu fetches it the first time a look is chosen. Each sets the same variables
6
+ * :root does; the pictures keep their own colors in every look. Words on every ground here are at 4.5 to 1 or more.
7
+ * A change here is a new file name (v2): the app's worker keeps a file under assets/ by its name.
8
+ */
9
+
10
+ /* Meteor: Link Meteor's night, cool paper and lime. */
11
+ :root[data-theme="meteor"] {
12
+ --bg: #f2f4f9;
13
+ --surface: #fdfeff;
14
+ --surface-2: #e9ecf3;
15
+ --ink: #161d2b;
16
+ --ink-2: #3b4253;
17
+ --ink-3: #5d6371;
18
+ --line: #dbdee5;
19
+ --line-strong: #b9bec7;
20
+ --dots: #c3c7d1;
21
+ --accent: #2e6813;
22
+ --accent-soft: #dfefc4;
23
+ --focus: #357518;
24
+ --edge: #6c727e;
25
+ --night: #0e1526;
26
+ --night-2: #172034;
27
+ --night-line: #343d50;
28
+ --night-ink: #eff2f7;
29
+ --night-muted: #b1b7c5;
30
+ --bright: #c3f344;
31
+ --mark: #c3f3448c;
32
+ }
33
+ @media (prefers-color-scheme: dark) {
34
+ :root[data-theme="meteor"] {
35
+ --bg: #0c0f17;
36
+ --surface: #141924;
37
+ --surface-2: #1c222d;
38
+ --ink: #eef0f5;
39
+ --ink-2: #c0c4cc;
40
+ --ink-3: #989fab;
41
+ --line: #2b303c;
42
+ --line-strong: #464d5b;
43
+ --dots: #2b303c;
44
+ --accent: #bfeb56;
45
+ --accent-ink: #0e1526;
46
+ --accent-soft: #243014;
47
+ --focus: #c3f344;
48
+ --edge: #8c929f;
49
+ --mark: #c3f34452;
50
+ }
51
+ }
52
+
53
+ /* Harbor: a harbor at night: navy, cool paper and a clear blue. */
54
+ :root[data-theme="harbor"] {
55
+ --bg: #f2f5fa;
56
+ --surface: #fdfeff;
57
+ --surface-2: #e7ecf4;
58
+ --ink: #121a2b;
59
+ --ink-2: #36415a;
60
+ --ink-3: #55607a;
61
+ --line: #d7dee9;
62
+ --line-strong: #b3bdce;
63
+ --dots: #c1cad8;
64
+ --accent: #1d4fa8;
65
+ --accent-soft: #dde7f8;
66
+ --focus: #2a5fc0;
67
+ --edge: #66718a;
68
+ --night: #0a1428;
69
+ --night-2: #12203a;
70
+ --night-line: #2c3b58;
71
+ --night-ink: #edf2fb;
72
+ --night-muted: #aab6cc;
73
+ --bright: #7fb8ff;
74
+ --mark: #7fb8ff8c;
75
+ }
76
+ @media (prefers-color-scheme: dark) {
77
+ :root[data-theme="harbor"] {
78
+ --bg: #0b111d;
79
+ --surface: #121a29;
80
+ --surface-2: #192234;
81
+ --ink: #edf1f8;
82
+ --ink-2: #c1c9d8;
83
+ --ink-3: #95a1b6;
84
+ --line: #263045;
85
+ --line-strong: #3f4b63;
86
+ --dots: #263045;
87
+ --accent: #8ab8ff;
88
+ --accent-ink: #0a1428;
89
+ --accent-soft: #1b2a45;
90
+ --focus: #9cc4ff;
91
+ --edge: #8792a8;
92
+ --mark: #7fb8ff52;
93
+ }
94
+ }
95
+
96
+ /* Plum: a violet night, lilac-gray paper and plum. */
97
+ :root[data-theme="plum"] {
98
+ --bg: #f6f3f9;
99
+ --surface: #fefdff;
100
+ --surface-2: #ece6f3;
101
+ --ink: #1e1428;
102
+ --ink-2: #413852;
103
+ --ink-3: #625a72;
104
+ --line: #e1dae9;
105
+ --line-strong: #c2b7d0;
106
+ --dots: #ccc3d8;
107
+ --accent: #6a3d9f;
108
+ --accent-soft: #ebe0f7;
109
+ --focus: #7a4cbf;
110
+ --edge: #756b86;
111
+ --night: #1a0f24;
112
+ --night-2: #251733;
113
+ --night-line: #43325a;
114
+ --night-ink: #f4effa;
115
+ --night-muted: #bcb0cc;
116
+ --bright: #d4a8ff;
117
+ --mark: #d4a8ff8c;
118
+ }
119
+ @media (prefers-color-scheme: dark) {
120
+ :root[data-theme="plum"] {
121
+ --bg: #110c17;
122
+ --surface: #19121f;
123
+ --surface-2: #21182a;
124
+ --ink: #f2eef7;
125
+ --ink-2: #cbc3d6;
126
+ --ink-3: #a297b1;
127
+ --line: #2e2439;
128
+ --line-strong: #4a3d5a;
129
+ --dots: #2e2439;
130
+ --accent: #c9a3ff;
131
+ --accent-ink: #1a0f24;
132
+ --accent-soft: #2d1f40;
133
+ --focus: #d4b4ff;
134
+ --edge: #978aa8;
135
+ --mark: #d4a8ff52;
136
+ }
137
+ }
138
+
139
+ /* Ember: a warm charcoal night, warm paper and terracotta. */
140
+ :root[data-theme="ember"] {
141
+ --bg: #faf6f1;
142
+ --surface: #fffdfa;
143
+ --surface-2: #f1eae1;
144
+ --ink: #241a12;
145
+ --ink-2: #4a3d31;
146
+ --ink-3: #6a5b4d;
147
+ --line: #e6dccf;
148
+ --line-strong: #ccbead;
149
+ --dots: #d6c9b9;
150
+ --accent: #a33d16;
151
+ --accent-soft: #f7e2d6;
152
+ --focus: #b8481c;
153
+ --edge: #7c6d5f;
154
+ --night: #1c130d;
155
+ --night-2: #2a1d14;
156
+ --night-line: #4a382a;
157
+ --night-ink: #fbf4ec;
158
+ --night-muted: #ccbcaa;
159
+ --bright: #ffa564;
160
+ --mark: #ffa5648c;
161
+ }
162
+ @media (prefers-color-scheme: dark) {
163
+ :root[data-theme="ember"] {
164
+ --bg: #15100c;
165
+ --surface: #1d1712;
166
+ --surface-2: #261e18;
167
+ --ink: #f6efe7;
168
+ --ink-2: #d4c8ba;
169
+ --ink-3: #ac9e8e;
170
+ --line: #33291f;
171
+ --line-strong: #504334;
172
+ --dots: #33291f;
173
+ --accent: #ffa36b;
174
+ --accent-ink: #1c130d;
175
+ --accent-soft: #3a2416;
176
+ --focus: #ffb07d;
177
+ --edge: #a09080;
178
+ --mark: #ffa56452;
179
+ }
180
+ }
181
+
182
+ /* Graphite: near-black, neutral gray and ink, with no hue at all: it sits beside any picture theme. */
183
+ :root[data-theme="graphite"] {
184
+ --bg: #f4f4f5;
185
+ --surface: #ffffff;
186
+ --surface-2: #e9e9ec;
187
+ --ink: #18181b;
188
+ --ink-2: #3f3f46;
189
+ --ink-3: #5e5e67;
190
+ --line: #dedee2;
191
+ --line-strong: #bdbdc4;
192
+ --dots: #c8c8ce;
193
+ --accent: #27272a;
194
+ --accent-soft: #e4e4e7;
195
+ --focus: #52525b;
196
+ --edge: #6e6e77;
197
+ --night: #111113;
198
+ --night-2: #1b1b1e;
199
+ --night-line: #35353b;
200
+ --night-ink: #f4f4f5;
201
+ --night-muted: #b4b4bb;
202
+ --bright: #b8b8c0;
203
+ --mark: #b8b8c08c;
204
+ }
205
+ @media (prefers-color-scheme: dark) {
206
+ :root[data-theme="graphite"] {
207
+ --bg: #0f0f11;
208
+ --surface: #17171a;
209
+ --surface-2: #1f1f23;
210
+ --ink: #f2f2f3;
211
+ --ink-2: #c8c8cd;
212
+ --ink-3: #9d9da6;
213
+ --line: #2a2a2f;
214
+ --line-strong: #45454c;
215
+ --dots: #2a2a2f;
216
+ --accent: #e4e4e7;
217
+ --accent-ink: #111113;
218
+ --accent-soft: #2a2a2f;
219
+ --focus: #d4d4d8;
220
+ --edge: #8f8f98;
221
+ --mark: #e4e4e752;
222
+ }
223
+ }