@adhd/dispatch-core-optimizer 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## 0.1.3 (2026-09-24)
2
+
3
+ This was a version bump only for dispatch-core-optimizer to align it with other projects, there were no code changes.
4
+
5
+ ## 0.1.2 (2026-08-08)
6
+
7
+
8
+ ### 🩹 Fixes
9
+
10
+ - **dispatch:** D-07 own-status eligibility guard (DEBT-DISPATCH-013) + formalize ICalibrationStore (DEBT-DISPATCH-018, BL-103)
11
+
12
+
13
+ ### ❤️ Thank You
14
+
15
+ - pseudosky
16
+
1
17
  ## 0.1.1 (2026-08-07)
2
18
 
3
19
 
package/index.js CHANGED
@@ -1,10 +1,10 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const de=new Set(["create","modify-signature","modify-body","add-export","remove-export","rename"]),me=new Set(["pending","pending-surfaced","in_progress","complete","failed","skipped"]),_e=new Set(["pending","in_progress","complete","failed","skipped"]);function T(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function S(e){return typeof e=="string"}function g(e,t,n){return{path:e,message:t,value:n}}function he(e){const t=[];if(!T(e))return{valid:!1,errors:[g("","root must be an object")]};for(const o of["snapshot_at","description"])S(e[o])||t.push(g(o,"required string field missing",e[o]));S(e.plan)||t.push(g("plan","required string",e.plan));const n=e.milestones;if(!T(n))t.push(g("milestones","must be an object",n));else{const o=Object.keys(n),i=new Set(o);for(const s of o){const r=n[s];if(!T(r)){t.push(g(`milestones.${s}`,"must be an object",r));continue}const a=r.eligible,u=r.pending;a===!0&&u!==null&&u!==void 0&&t.push(g(`milestones.${s}`,"D-07 violation: eligible=true but pending not null")),typeof a!="boolean"&&t.push(g(`milestones.${s}.eligible`,"must be boolean",a));const f=r.status;(!S(f)||!me.has(f))&&t.push(g(`milestones.${s}.status`,"invalid status",f));const _=r.wave;(typeof _!="number"||!Number.isInteger(_)||_<0)&&t.push(g(`milestones.${s}.wave`,"must be non-negative integer",_));const y=r.ki_estimate;y!=null&&typeof y!="number"&&t.push(g(`milestones.${s}.ki_estimate`,"must be number|null",y));for(const v of["tokens_estimated","tokens_actual"]){const b=r[v];b!=null&&typeof b!="number"&&t.push(g(`milestones.${s}.${v}`,"must be number|null",b))}Array.isArray(r.artifacts)||t.push(g(`milestones.${s}.artifacts`,"must be an array",r.artifacts)),typeof r.si_bytes!="number"&&t.push(g(`milestones.${s}.si_bytes`,"must be a number",r.si_bytes))}const l=e.operations;if(!Array.isArray(l))t.push(g("operations","must be an array",l));else for(const s of l){if(!T(s))continue;const r=S(s.id)?s.id:"?",a=s.milestone;S(a)&&!i.has(a)&&t.push(g(`operations[${r}].milestone`,`unknown milestone "${a}"`));const u=s.status;(!S(u)||!_e.has(u))&&t.push(g(`operations[${r}].status`,"invalid operation status",u)),Array.isArray(s.dispatch_ids)||t.push(g(`operations[${r}].dispatch_ids`,"must be an array",s.dispatch_ids)),typeof s.attempt_count!="number"&&t.push(g(`operations[${r}].attempt_count`,"must be a number",s.attempt_count)),Array.isArray(s.blast_radius)||t.push(g(`operations[${r}].blast_radius`,"must be an array",s.blast_radius))}const p=e.open_questions;if(!Array.isArray(p))t.push(g("open_questions","must be an array",p));else for(const s of p){if(!T(s))continue;const r=s.blocking;(!S(r)||!i.has(r))&&t.push(g("open_questions",`unknown blocking milestone "${r}"`)),typeof s.surfaced!="boolean"&&t.push(g(`open_questions[${s.id}]`,"surfaced must be boolean",s.surfaced)),typeof s.answered!="boolean"&&t.push(g(`open_questions[${s.id}]`,"answered must be boolean",s.answered))}const c=e.dispatch_units;if(c!==void 0)if(!Array.isArray(c))t.push(g("dispatch_units","must be an array if present",c));else for(const s of c){if(!T(s))continue;const r=s.fits_context_window;typeof r!="boolean"&&t.push(g(`dispatch_units[${s.id}]`,"fits_context_window must be boolean",r));const a=s.milestones;if(Array.isArray(a))for(const u of a)S(u)&&!i.has(u)&&t.push(g(`dispatch_units[${s.id}].milestones`,`unknown milestone "${u}"`))}T(e.pairwise_overlap)||t.push(g("pairwise_overlap","must be an object",e.pairwise_overlap))}return{valid:t.length===0,errors:t}}function ge(e){const t=he(e);if(!t.valid)throw new Error(`Snapshot validation failed:
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const de=new Set(["create","modify-signature","modify-body","add-export","remove-export","rename"]),me=new Set(["pending","pending-surfaced","in_progress","complete","failed","skipped"]),_e=new Set(["pending","in_progress","complete","failed","skipped"]);function T(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function S(e){return typeof e=="string"}function g(e,t,n){return{path:e,message:t,value:n}}function he(e){const t=[];if(!T(e))return{valid:!1,errors:[g("","root must be an object")]};for(const o of["snapshot_at","description"])S(e[o])||t.push(g(o,"required string field missing",e[o]));S(e.plan)||t.push(g("plan","required string",e.plan));const n=e.milestones;if(!T(n))t.push(g("milestones","must be an object",n));else{const o=Object.keys(n),i=new Set(o);for(const s of o){const r=n[s];if(!T(r)){t.push(g(`milestones.${s}`,"must be an object",r));continue}const a=r.eligible,u=r.pending;a===!0&&u!==null&&u!==void 0&&t.push(g(`milestones.${s}`,"D-07 violation: eligible=true but pending not null")),typeof a!="boolean"&&t.push(g(`milestones.${s}.eligible`,"must be boolean",a));const f=r.status;(!S(f)||!me.has(f))&&t.push(g(`milestones.${s}.status`,"invalid status",f)),a===!0&&f==="complete"&&t.push(g(`milestones.${s}`,"D-07 violation: eligible=true but status is complete"));const _=r.wave;(typeof _!="number"||!Number.isInteger(_)||_<0)&&t.push(g(`milestones.${s}.wave`,"must be non-negative integer",_));const y=r.ki_estimate;y!=null&&typeof y!="number"&&t.push(g(`milestones.${s}.ki_estimate`,"must be number|null",y));for(const v of["tokens_estimated","tokens_actual"]){const b=r[v];b!=null&&typeof b!="number"&&t.push(g(`milestones.${s}.${v}`,"must be number|null",b))}Array.isArray(r.artifacts)||t.push(g(`milestones.${s}.artifacts`,"must be an array",r.artifacts)),typeof r.si_bytes!="number"&&t.push(g(`milestones.${s}.si_bytes`,"must be a number",r.si_bytes))}const l=e.operations;if(!Array.isArray(l))t.push(g("operations","must be an array",l));else for(const s of l){if(!T(s))continue;const r=S(s.id)?s.id:"?",a=s.milestone;S(a)&&!i.has(a)&&t.push(g(`operations[${r}].milestone`,`unknown milestone "${a}"`));const u=s.status;(!S(u)||!_e.has(u))&&t.push(g(`operations[${r}].status`,"invalid operation status",u)),Array.isArray(s.dispatch_ids)||t.push(g(`operations[${r}].dispatch_ids`,"must be an array",s.dispatch_ids)),typeof s.attempt_count!="number"&&t.push(g(`operations[${r}].attempt_count`,"must be a number",s.attempt_count)),Array.isArray(s.blast_radius)||t.push(g(`operations[${r}].blast_radius`,"must be an array",s.blast_radius))}const p=e.open_questions;if(!Array.isArray(p))t.push(g("open_questions","must be an array",p));else for(const s of p){if(!T(s))continue;const r=s.blocking;(!S(r)||!i.has(r))&&t.push(g("open_questions",`unknown blocking milestone "${r}"`)),typeof s.surfaced!="boolean"&&t.push(g(`open_questions[${s.id}]`,"surfaced must be boolean",s.surfaced)),typeof s.answered!="boolean"&&t.push(g(`open_questions[${s.id}]`,"answered must be boolean",s.answered))}const c=e.dispatch_units;if(c!==void 0)if(!Array.isArray(c))t.push(g("dispatch_units","must be an array if present",c));else for(const s of c){if(!T(s))continue;const r=s.fits_context_window;typeof r!="boolean"&&t.push(g(`dispatch_units[${s.id}]`,"fits_context_window must be boolean",r));const a=s.milestones;if(Array.isArray(a))for(const u of a)S(u)&&!i.has(u)&&t.push(g(`dispatch_units[${s.id}].milestones`,`unknown milestone "${u}"`))}T(e.pairwise_overlap)||t.push(g("pairwise_overlap","must be an object",e.pairwise_overlap))}return{valid:t.length===0,errors:t}}function ge(e){const t=he(e);if(!t.valid)throw new Error(`Snapshot validation failed:
2
2
  ${t.errors.map(n=>` ${n.path}: ${n.message}`).join(`
3
- `)}`)}const U={prose:5.5,md:5.5,ts:6.3,tsx:6.3,py:6.3,default:4};function F(e,t){if(e<=0)return 0;const o=U[""]??U.default??4;return Math.ceil(e/o)}function Z(e,t){if(e.length===0||t.fileSizes===void 0)return new Map;try{return t.fileSizes(e)}catch{return new Map}}const ye={low:600,medium:1e3,high:2e3},be=de;function ve(e){const t=e.properties??{};return Object.keys(t).length||Object.keys(e).length}function we(e,t){if(e.type==="tool-call")return 0;const n=e.shape;if(!n||n.kind===null)return 0;const o=n.kind;if(o==="function"||o==="interface"||o==="type"||o==="class"||o==="enum"||o==="const"||o==="script")return("ops"in n&&Array.isArray(n.ops)?n.ops:[]).length*200;if(o==="config"||o==="env"||o==="schema"||o==="manifest")return("ops"in n&&Array.isArray(n.ops)?n.ops:[]).length*100;if(o==="doc")return ye[t??"medium"]??1e3;if(o==="structured-output"){const i="schema"in n&&n.schema?n.schema:{};return ve(i)*50}return 0}function ke(e,t){const n=new Set([...Object.keys(e),...Object.keys(t)]),o={};for(const i of n){const l=e[i];o[i]=l??t[i]??null}return o}function $e(e,t){const n=new Set([...Object.keys(e),...Object.keys(t)]),o={};for(const i of n){const l=e[i]??t[i];if(l===void 0)throw new TypeError(`Model tier "${i}" not found in dag or deps context_window_per_tier`);o[i]=l}return o}function ee(e){var c;const t=Object.keys(e),n=new Map,o=new Map;for(const s of t)n.has(s)||n.set(s,0),o.has(s)||o.set(s,[]);for(const s of t){const r=((c=e[s])==null?void 0:c.depends_on)??[];for(const a of r){const u=o.get(a);u!==void 0&&u.push(s),n.set(s,(n.get(s)??0)+1)}}const i=new Map,l=[];let p=t.filter(s=>(n.get(s)??0)===0).sort();for(const s of p)i.set(s,0);for(;p.length>0;){const s=[];for(const r of p){l.push(r);const a=(o.get(r)??[]).slice().sort();for(const u of a){const f=(n.get(u)??0)-1;n.set(u,f);const _=i.get(r)??0,y=i.get(u)??0;i.set(u,Math.max(y,_+1)),f===0&&s.push(u)}}p=s.sort()}if(l.length!==t.length){const s=new Set(l),r=t.filter(a=>!s.has(a));throw new Error(`snapshot(): cycle detected in milestone depends_on graph. Nodes involved: [${r.join(", ")}]`)}return{order:l,waves:i}}function te(e,t){if(t.length===0)return[];const n=new Set(t);return e.filter(o=>o.operations.some(i=>n.has(i)))}function ne(e,t){return e.filter(n=>n.operations.includes(t))}function Ae(e,t,n,o,i){const l=`${e}.guard`,p=[...n,l],c=te(o,p);for(const r of c)for(const a of r.results)if(a.op_id===l&&a.guard_result==="pass")return"complete";for(const r of c)for(const a of r.results)if(p.includes(a.op_id)&&a.status==="failed")return"failed";for(const r of c)for(const a of r.results)if(p.includes(a.op_id)&&a.status==="in_progress")return"in_progress";const s=i.length===0||i.every(r=>r==="complete");return t.pending!==null&&s?"pending-surfaced":"pending"}function Oe(e,t){const n=`${e}.guard`;let o=null,i=null,l=null;for(const p of t)if(p.operations.includes(n))for(const c of p.results)c.op_id===n&&c.guard_result!==null&&(o=c.guard_result,i=c.guard_output,c.guard_result==="pass"&&(l=c.guard_ran_at));return o!==null?{guard_result:o,guard_output:i,completed_at:l}:{guard_result:"pending",guard_output:null,completed_at:null}}function Se(e){const t=new Set;for(const n of e)n.action==="move"&&n.to_file?t.add(n.to_file):be.has(n.action)&&n.file&&t.add(n.file);return Array.from(t)}function Te(e,t,n){const o=ne(n,e.id),i=o.map(a=>a.id);let l=null,p=null,c=null;for(const a of o)for(const u of a.results)u.op_id===e.id&&u.guard_result!==null&&(l=u.guard_result,p=u.guard_output,c=u.guard_ran_at);const s=e.ki_estimate!==null&&e.ki_estimate!==void 0?e.ki_estimate:we(e,t),r=Me(e.shape);return{...e,ki_estimate:s,shape:r,dispatch_ids:i,attempt_count:0,guard_result:l,guard_output:p,guard_ran_at:c,blast_radius:[],conflict:{detected:!1,competing_op:null,op_key:null,resolution:null},tokens_actual:null}}function Me(e){if(!e)return null;if(e.kind===null)return e;const t=e.kind;if(t==="function"||t==="interface"||t==="type"||t==="class"||t==="enum"||t==="const"||t==="script"||t==="config"||t==="env"||t==="schema"||t==="manifest"){const n=("ops"in e&&Array.isArray(e.ops)?e.ops:[]).map(o=>({...o,from:null,breaking:null,severity:null}));return{...e,ops:n}}return e}function je(e,t,n,o){const i=`${e}.guard`,l=ne(o,i),p=l.map(a=>a.id);let c=null,s=null,r=null;for(const a of l)for(const u of a.results)u.op_id===i&&u.guard_result!==null&&(c=u.guard_result,s=u.guard_output,r=u.guard_ran_at);return{id:i,milestone:e,depends_on:n,type:"tool-call",action:"guard",file:null,symbol:null,provenance:null,confidence:null,audit_check:null,criteria:[],tool:null,args:null,guard:t.guard??null,to_file:null,to_symbol:null,ki_estimate:0,ki_source:null,authored_by:"synthesized",status:"pending",shape:null,dispatch_ids:p,attempt_count:0,guard_result:c,guard_output:s,guard_ran_at:r,blast_radius:[],conflict:{detected:!1,competing_op:null,op_key:null,resolution:null},tokens_actual:null}}function xe(e,t){const n={},{write_multiplier:o,read_multiplier:i,hit_probability:l}=t;for(const[p,c]of Object.entries(e))c===null?n[p]=null:n[p]=Math.round(c*((1-l)*o+l*i));return n}function Pe(e,t,n){const o=Array.from(e.keys()),i={};for(let l=0;l<o.length;l++)for(let p=l+1;p<o.length;p++){const c=o[l],s=o[p];if(c===void 0||s===void 0)continue;const[r,a]=c<s?[c,s]:[s,c],u=`${r}:${a}`,f=e.get(c)??[],_=e.get(s)??[],y=new Set(f.map(w=>w.file).filter(w=>w!==null)),v=new Set(_.map(w=>w.file).filter(w=>w!==null)),b=Array.from(y).filter(w=>v.has(w));if(b.length===0)continue;const A=t.get(c)??"pending",M=t.get(s)??"pending",k=A==="complete"&&M==="complete";let $=0;for(const w of b)$+=k?n(w):0;i[u]=$}return i}function Ie(e){return(Array.isArray(e)?e:Object.values(e)).map(n=>n.type===void 0?{...n,type:"generative"}:n)}function ze(e,t){const n=new Date().toISOString(),o=t.dispatchLog??e.dispatch_log,i=e.optimization.sentinel_fanout,l=ke(e.optimization.b_per_tier,t.bPerTier),p=$e(e.optimization.context_window_per_tier,t.contextWindowPerTier),c=xe(l,i),{waves:s}=ee(e.milestones),r=Ie(e.operations),a=new Map;for(const m of r){const d=a.get(m.milestone)??[];d.push(m),a.set(m.milestone,d)}const u=new Set;for(const m of r)m.file&&u.add(m.file),m.action==="move"&&m.to_file&&u.add(m.to_file);const f=Z(Array.from(u),t),_=m=>f.get(m)??0,y=new Map,v=Array.from(s.entries()).sort((m,d)=>m[1]-d[1]||m[0].localeCompare(d[0])).map(([m])=>m);for(const m of v){const d=e.milestones[m];if(d===void 0)continue;const j=(a.get(m)??[]).map(P=>P.id),x=d.depends_on.map(P=>y.get(P)??"pending"),I=Ae(m,d,j,o,x);y.set(m,I)}const b={},A=[];for(const m of v){const d=e.milestones[m];if(d===void 0)continue;const j=s.get(m)??0,x=a.get(m)??[],I=x.map(h=>h.id),P=y.get(m)??"pending",C=d.depends_on.map(h=>y.get(h)??"pending"),le=d.depends_on.length===0||C.every(h=>h==="complete"),ue=C.every(h=>h!=="failed"),ce=d.pending===null&&le&&ue,E=te(o,[...I,`${m}.guard`]),ae=E.length>0?E.map(h=>h.started_at).sort()[0]??null:null;let N,B,D;if(d.guard){const h=Oe(m,o);N=h.guard_result,B=h.guard_output,D=h.completed_at}else N=null,B=null,D=null;const R=Se(x),K=R.reduce((h,O)=>h+_(O),0),W=x.map(h=>Te(h,d.effort,o));let z=null,G=0,Y=!1;for(const h of W){if(h.ki_estimate===null){Y=!0;break}G+=h.ki_estimate}Y||(z=G);let H=null;const L=d.model;if(L!==null&&z!==null){const h=c[L]??null;if(h!==null){const O=F(K);H=h+O+z}}let V=null;const J=E.filter(h=>h.completed_at!==null&&h.results.length>0&&h.results.every(O=>O.status==="complete"||O.status==="skipped"));J.length>0&&(V=J.reduce((h,O)=>h+O.turns.reduce((fe,Q)=>fe+Q.input_tokens+Q.output_tokens,0),0));const pe=je(m,d,I,o);A.push(...W,pe),b[m]={description:d.description,...d.rationale!==void 0?{rationale:d.rationale}:{},authored_by:d.authored_by,pending:d.pending,triggered_by:d.triggered_by,phase:d.phase,depends_on:d.depends_on,agent:d.agent,model:d.model,effort:d.effort,two_stage:d.two_stage,read_only:d.read_only,guard:d.guard,context:`contexts/${m}.md`,wave:j,eligible:ce,status:P,started_at:ae,completed_at:D,guard_result:N,guard_output:B,artifacts:R,si_bytes:K,ki_estimate:z,tokens_estimated:H,tokens_actual:V}}const M=Pe(a,y,_),k=Ee(e,b),w={tokens_naive:(()=>{let m=0;for(const d of Object.values(b))if(d.eligible&&d.status==="pending"&&d.model!==null){const j=l[d.model]??t.bPerTier[d.model]??0;m+=j+(d.ki_estimate??0)}return m})(),sentinel_fanout:i,context_window_override:e.optimization.context_window_override,b_override:e.optimization.b_override,b_per_tier:l,b_eff_per_tier:c,context_window_per_tier:p},q={snapshot_at:n,snapshot_version:1,plan:"",schema_version:e.schema_version,plan_kind:e.plan_kind,description:e.description,problem:e.problem,approach:e.approach,executor:e.executor,...e.executor_model!==void 0?{executor_model:e.executor_model}:{},...e.executor_effort!==void 0?{executor_effort:e.executor_effort}:{},phases:[...e.phases],terminal:e.terminal,...e.assumed_baseline!==void 0?{assumed_baseline:e.assumed_baseline}:{},optimization:w,milestones:b,operations:A,pairwise_overlap:M,open_questions:k};return ge(q),q}function Ee(e,t){const n=[];for(const[o,i]of Object.entries(t)){const l=e.milestones[o];if(l===void 0||l.pending===null)continue;const p=i.status==="pending-surfaced";n.push({id:`q:${o}`,text:l.pending,blocking:o,surfaced:p,raised_at_dispatch:null,raised_at_turn:null,answered:!1,answer:null})}return n}const Ne="You are a dispatch-orchestrator worker agent executing one or more milestones from a dependency-DAG build plan. Each task turn gives you the full compiled instructions for this dispatch: milestone description, the operations to perform, and the guard command that defines done. Execute the operations precisely and produce real output (code, docs, or config) — never a plan or a summary in place of the work.";function oe(e){return Object.keys(e.milestones).filter(t=>{const n=e.milestones[t];return n!==void 0&&n.eligible===!0&&n.status==="pending"})}function Be(e){if(e.length===0||e.every(t=>t.type==="tool-call"))return"tool-call";for(const t of e){if(t.type!=="generative"||!t.shape||t.shape.kind===null)continue;const n=t.shape.kind;if(n==="function"||n==="interface"||n==="type"||n==="class"||n==="enum"||n==="const"||n==="script"||n==="config"||n==="env"||n==="schema"||n==="manifest")return"code-config";if(n==="doc")return"doc";if(n==="structured-output")return"structured"}return"code-config"}function De(e){if(!e)return"";const t=e.indexOf(":");return t>=0?e.slice(t+1):e}function Fe(e,t,n){let o=!0;const i=[];for(const l of e){const p=t[l];if(p===void 0)continue;const c=n.filter(r=>r.milestone===l&&r.action!=="guard");c.some(r=>r.type==="generative")&&(o=!1),i.push(`## Milestone: ${l}`),i.push(p.description),p.rationale&&i.push(`
3
+ `)}`)}const U={prose:5.5,md:5.5,ts:6.3,tsx:6.3,py:6.3,default:4};function F(e,t){if(e<=0)return 0;const o=U[""]??U.default??4;return Math.ceil(e/o)}function Z(e,t){if(e.length===0||t.fileSizes===void 0)return new Map;try{return t.fileSizes(e)}catch{return new Map}}const ye={low:600,medium:1e3,high:2e3},be=de;function ve(e){const t=e.properties??{};return Object.keys(t).length||Object.keys(e).length}function we(e,t){if(e.type==="tool-call")return 0;const n=e.shape;if(!n||n.kind===null)return 0;const o=n.kind;if(o==="function"||o==="interface"||o==="type"||o==="class"||o==="enum"||o==="const"||o==="script")return("ops"in n&&Array.isArray(n.ops)?n.ops:[]).length*200;if(o==="config"||o==="env"||o==="schema"||o==="manifest")return("ops"in n&&Array.isArray(n.ops)?n.ops:[]).length*100;if(o==="doc")return ye[t??"medium"]??1e3;if(o==="structured-output"){const i="schema"in n&&n.schema?n.schema:{};return ve(i)*50}return 0}function ke(e,t){const n=new Set([...Object.keys(e),...Object.keys(t)]),o={};for(const i of n){const l=e[i];o[i]=l??t[i]??null}return o}function $e(e,t){const n=new Set([...Object.keys(e),...Object.keys(t)]),o={};for(const i of n){const l=e[i]??t[i];if(l===void 0)throw new TypeError(`Model tier "${i}" not found in dag or deps context_window_per_tier`);o[i]=l}return o}function ee(e){var c;const t=Object.keys(e),n=new Map,o=new Map;for(const s of t)n.has(s)||n.set(s,0),o.has(s)||o.set(s,[]);for(const s of t){const r=((c=e[s])==null?void 0:c.depends_on)??[];for(const a of r){const u=o.get(a);u!==void 0&&u.push(s),n.set(s,(n.get(s)??0)+1)}}const i=new Map,l=[];let p=t.filter(s=>(n.get(s)??0)===0).sort();for(const s of p)i.set(s,0);for(;p.length>0;){const s=[];for(const r of p){l.push(r);const a=(o.get(r)??[]).slice().sort();for(const u of a){const f=(n.get(u)??0)-1;n.set(u,f);const _=i.get(r)??0,y=i.get(u)??0;i.set(u,Math.max(y,_+1)),f===0&&s.push(u)}}p=s.sort()}if(l.length!==t.length){const s=new Set(l),r=t.filter(a=>!s.has(a));throw new Error(`snapshot(): cycle detected in milestone depends_on graph. Nodes involved: [${r.join(", ")}]`)}return{order:l,waves:i}}function te(e,t){if(t.length===0)return[];const n=new Set(t);return e.filter(o=>o.operations.some(i=>n.has(i)))}function ne(e,t){return e.filter(n=>n.operations.includes(t))}function Ae(e,t,n,o,i){const l=`${e}.guard`,p=[...n,l],c=te(o,p);for(const r of c)for(const a of r.results)if(a.op_id===l&&a.guard_result==="pass")return"complete";for(const r of c)for(const a of r.results)if(p.includes(a.op_id)&&a.status==="failed")return"failed";for(const r of c)for(const a of r.results)if(p.includes(a.op_id)&&a.status==="in_progress")return"in_progress";const s=i.length===0||i.every(r=>r==="complete");return t.pending!==null&&s?"pending-surfaced":"pending"}function Oe(e,t){const n=`${e}.guard`;let o=null,i=null,l=null;for(const p of t)if(p.operations.includes(n))for(const c of p.results)c.op_id===n&&c.guard_result!==null&&(o=c.guard_result,i=c.guard_output,c.guard_result==="pass"&&(l=c.guard_ran_at));return o!==null?{guard_result:o,guard_output:i,completed_at:l}:{guard_result:"pending",guard_output:null,completed_at:null}}function Se(e){const t=new Set;for(const n of e)n.action==="move"&&n.to_file?t.add(n.to_file):be.has(n.action)&&n.file&&t.add(n.file);return Array.from(t)}function Te(e,t,n){const o=ne(n,e.id),i=o.map(a=>a.id);let l=null,p=null,c=null;for(const a of o)for(const u of a.results)u.op_id===e.id&&u.guard_result!==null&&(l=u.guard_result,p=u.guard_output,c=u.guard_ran_at);const s=e.ki_estimate!==null&&e.ki_estimate!==void 0?e.ki_estimate:we(e,t),r=Me(e.shape);return{...e,ki_estimate:s,shape:r,dispatch_ids:i,attempt_count:0,guard_result:l,guard_output:p,guard_ran_at:c,blast_radius:[],conflict:{detected:!1,competing_op:null,op_key:null,resolution:null},tokens_actual:null}}function Me(e){if(!e)return null;if(e.kind===null)return e;const t=e.kind;if(t==="function"||t==="interface"||t==="type"||t==="class"||t==="enum"||t==="const"||t==="script"||t==="config"||t==="env"||t==="schema"||t==="manifest"){const n=("ops"in e&&Array.isArray(e.ops)?e.ops:[]).map(o=>({...o,from:null,breaking:null,severity:null}));return{...e,ops:n}}return e}function je(e,t,n,o){const i=`${e}.guard`,l=ne(o,i),p=l.map(a=>a.id);let c=null,s=null,r=null;for(const a of l)for(const u of a.results)u.op_id===i&&u.guard_result!==null&&(c=u.guard_result,s=u.guard_output,r=u.guard_ran_at);return{id:i,milestone:e,depends_on:n,type:"tool-call",action:"guard",file:null,symbol:null,provenance:null,confidence:null,audit_check:null,criteria:[],tool:null,args:null,guard:t.guard??null,to_file:null,to_symbol:null,ki_estimate:0,ki_source:null,authored_by:"synthesized",status:"pending",shape:null,dispatch_ids:p,attempt_count:0,guard_result:c,guard_output:s,guard_ran_at:r,blast_radius:[],conflict:{detected:!1,competing_op:null,op_key:null,resolution:null},tokens_actual:null}}function xe(e,t){const n={},{write_multiplier:o,read_multiplier:i,hit_probability:l}=t;for(const[p,c]of Object.entries(e))c===null?n[p]=null:n[p]=Math.round(c*((1-l)*o+l*i));return n}function Pe(e,t,n){const o=Array.from(e.keys()),i={};for(let l=0;l<o.length;l++)for(let p=l+1;p<o.length;p++){const c=o[l],s=o[p];if(c===void 0||s===void 0)continue;const[r,a]=c<s?[c,s]:[s,c],u=`${r}:${a}`,f=e.get(c)??[],_=e.get(s)??[],y=new Set(f.map(w=>w.file).filter(w=>w!==null)),v=new Set(_.map(w=>w.file).filter(w=>w!==null)),b=Array.from(y).filter(w=>v.has(w));if(b.length===0)continue;const A=t.get(c)??"pending",j=t.get(s)??"pending",k=A==="complete"&&j==="complete";let $=0;for(const w of b)$+=k?n(w):0;i[u]=$}return i}function Ie(e){return(Array.isArray(e)?e:Object.values(e)).map(n=>n.type===void 0?{...n,type:"generative"}:n)}function ze(e,t){const n=new Date().toISOString(),o=t.dispatchLog??e.dispatch_log,i=e.optimization.sentinel_fanout,l=ke(e.optimization.b_per_tier,t.bPerTier),p=$e(e.optimization.context_window_per_tier,t.contextWindowPerTier),c=xe(l,i),{waves:s}=ee(e.milestones),r=Ie(e.operations),a=new Map;for(const m of r){const d=a.get(m.milestone)??[];d.push(m),a.set(m.milestone,d)}const u=new Set;for(const m of r)m.file&&u.add(m.file),m.action==="move"&&m.to_file&&u.add(m.to_file);const f=Z(Array.from(u),t),_=m=>f.get(m)??0,y=new Map,v=Array.from(s.entries()).sort((m,d)=>m[1]-d[1]||m[0].localeCompare(d[0])).map(([m])=>m);for(const m of v){const d=e.milestones[m];if(d===void 0)continue;const x=(a.get(m)??[]).map(M=>M.id),P=d.depends_on.map(M=>y.get(M)??"pending"),I=Ae(m,d,x,o,P);y.set(m,I)}const b={},A=[];for(const m of v){const d=e.milestones[m];if(d===void 0)continue;const x=s.get(m)??0,P=a.get(m)??[],I=P.map(h=>h.id),M=y.get(m)??"pending",C=d.depends_on.map(h=>y.get(h)??"pending"),le=d.depends_on.length===0||C.every(h=>h==="complete"),ue=C.every(h=>h!=="failed"),ce=d.pending===null&&le&&ue&&M!=="complete",E=te(o,[...I,`${m}.guard`]),ae=E.length>0?E.map(h=>h.started_at).sort()[0]??null:null;let D,N,B;if(d.guard){const h=Oe(m,o);D=h.guard_result,N=h.guard_output,B=h.completed_at}else D=null,N=null,B=null;const R=Se(P),K=R.reduce((h,O)=>h+_(O),0),W=P.map(h=>Te(h,d.effort,o));let z=null,G=0,Y=!1;for(const h of W){if(h.ki_estimate===null){Y=!0;break}G+=h.ki_estimate}Y||(z=G);let H=null;const L=d.model;if(L!==null&&z!==null){const h=c[L]??null;if(h!==null){const O=F(K);H=h+O+z}}let V=null;const J=E.filter(h=>h.completed_at!==null&&h.results.length>0&&h.results.every(O=>O.status==="complete"||O.status==="skipped"));J.length>0&&(V=J.reduce((h,O)=>h+O.turns.reduce((fe,Q)=>fe+Q.input_tokens+Q.output_tokens,0),0));const pe=je(m,d,I,o);A.push(...W,pe),b[m]={description:d.description,...d.rationale!==void 0?{rationale:d.rationale}:{},authored_by:d.authored_by,pending:d.pending,triggered_by:d.triggered_by,phase:d.phase,depends_on:d.depends_on,agent:d.agent,model:d.model,effort:d.effort,two_stage:d.two_stage,read_only:d.read_only,guard:d.guard,context:`contexts/${m}.md`,wave:x,eligible:ce,status:M,started_at:ae,completed_at:B,guard_result:D,guard_output:N,artifacts:R,si_bytes:K,ki_estimate:z,tokens_estimated:H,tokens_actual:V}}const j=Pe(a,y,_),k=Ee(e,b),w={tokens_naive:(()=>{let m=0;for(const d of Object.values(b))if(d.eligible&&d.status==="pending"&&d.model!==null){const x=l[d.model]??t.bPerTier[d.model]??0;m+=x+(d.ki_estimate??0)}return m})(),sentinel_fanout:i,context_window_override:e.optimization.context_window_override,b_override:e.optimization.b_override,b_per_tier:l,b_eff_per_tier:c,context_window_per_tier:p},q={snapshot_at:n,snapshot_version:1,plan:"",schema_version:e.schema_version,plan_kind:e.plan_kind,description:e.description,problem:e.problem,approach:e.approach,executor:e.executor,...e.executor_model!==void 0?{executor_model:e.executor_model}:{},...e.executor_effort!==void 0?{executor_effort:e.executor_effort}:{},phases:[...e.phases],terminal:e.terminal,...e.assumed_baseline!==void 0?{assumed_baseline:e.assumed_baseline}:{},optimization:w,milestones:b,operations:A,pairwise_overlap:j,open_questions:k};return ge(q),q}function Ee(e,t){const n=[];for(const[o,i]of Object.entries(t)){const l=e.milestones[o];if(l===void 0||l.pending===null)continue;const p=i.status==="pending-surfaced";n.push({id:`q:${o}`,text:l.pending,blocking:o,surfaced:p,raised_at_dispatch:null,raised_at_turn:null,answered:!1,answer:null})}return n}const De="You are a dispatch-orchestrator worker agent executing one or more milestones from a dependency-DAG build plan. Each task turn gives you the full compiled instructions for this dispatch: milestone description, the operations to perform, and the guard command that defines done. Execute the operations precisely and produce real output (code, docs, or config) — never a plan or a summary in place of the work.";function oe(e){return Object.keys(e.milestones).filter(t=>{const n=e.milestones[t];return n!==void 0&&n.eligible===!0&&n.status==="pending"})}function Ne(e){if(e.length===0||e.every(t=>t.type==="tool-call"))return"tool-call";for(const t of e){if(t.type!=="generative"||!t.shape||t.shape.kind===null)continue;const n=t.shape.kind;if(n==="function"||n==="interface"||n==="type"||n==="class"||n==="enum"||n==="const"||n==="script"||n==="config"||n==="env"||n==="schema"||n==="manifest")return"code-config";if(n==="doc")return"doc";if(n==="structured-output")return"structured"}return"code-config"}function Be(e){if(!e)return"";const t=e.indexOf(":");return t>=0?e.slice(t+1):e}function Fe(e,t,n){let o=!0;const i=[];for(const l of e){const p=t[l];if(p===void 0)continue;const c=n.filter(r=>r.milestone===l&&r.action!=="guard");c.some(r=>r.type==="generative")&&(o=!1),i.push(`## Milestone: ${l}`),i.push(p.description),p.rationale&&i.push(`
4
4
  *Rationale:* ${p.rationale}`),i.push(`
5
5
  ### Operations:`);for(const r of c){const a=r.file?` ${r.file}`:"",u=r.symbol?` (${r.symbol})`:"";if(i.push(`- [${r.id}] ${r.action}${a}${u}`),r.shape&&r.shape.kind!==null){const f=r.shape;if(f.kind==="doc")i.push(` Description: ${f.description}`),i.push(` Objective: ${f.objective}`),f.required_sections&&f.required_sections.length>0&&i.push(` Required sections: ${f.required_sections.join(", ")}`);else if(f.kind==="structured-output")i.push(` Schema:
6
6
  `+JSON.stringify(f.schema,null,2).split(`
7
7
  `).map(_=>` ${_}`).join(`
8
8
  `));else if("ops"in f&&Array.isArray(f.ops))for(const _ of f.ops){const y=_.to!==null?` → ${_.to}`:"",v=_.target!==null?` "${_.target}"`:"";if(i.push(` - ${_.op}${v}${y}`),_.type_spec)for(const[b,A]of Object.entries(_.type_spec))i.push(` - ${b}: ${A}`)}}}const s=p.guard;i.push(`
9
9
  ### Guard: ${s??"none"}`),i.push("")}return o?null:i.join(`
10
- `)}function se(e,t,n){if(e===null)return null;const o=t.optimization.b_eff_per_tier[e];if(o!=null)return o;const i=t.optimization.b_per_tier[e];if(i!=null)return i;const l=n.bPerTier[e];return l!==void 0?l:null}function ie(e,t,n){if(e===null)return Number.POSITIVE_INFINITY;const o=t.optimization.context_window_per_tier[e];if(o!==void 0)return o;const i=n.contextWindowPerTier[e];return i!==void 0?i:Number.POSITIVE_INFINITY}function re(e,t){const n=new Set;for(const o of e){const i=t.snapshot.milestones[o];if(i!==void 0){n.add(i.context);for(const l of i.read_only)n.add(l);for(const l of t.opsByMilestone.get(o)??[])l.file&&n.add(l.file)}}return Array.from(n)}function X(e,t,n){const o=se(t,n.snapshot,n.deps);if(o===null)return null;const l=re(e,n).reduce((s,r)=>s+(n.sizeMap.get(r)??0),0),p=F(l),c=e.reduce((s,r)=>{var a;return s+(((a=n.snapshot.milestones[r])==null?void 0:a.ki_estimate)??0)},0);return o+p+c}function qe(e,t,n){const o=ie(t,n.snapshot,n.deps),i=[...e].sort((c,s)=>{var u,f;const r=((u=n.snapshot.milestones[c])==null?void 0:u.ki_estimate)??0,a=((f=n.snapshot.milestones[s])==null?void 0:f.ki_estimate)??0;return r-a||c.localeCompare(s)}),l=[];let p=[];for(const c of i){const s=[...p,c],r=X(s,t,n);r!==null&&r>o&&p.length>0?(l.push(p),p=[c]):p=s}return p.length>0&&l.push(p),l.filter(c=>{const s=X(c,t,n);return s===null||s<=o})}function Ce(e,t,n,o){const i=e[0]??"",l=o.snapshot.milestones[i],p=(l==null?void 0:l.effort)??null,c=[];for(const k of e)for(const $ of o.opsByMilestone.get(k)??[])c.push($.id);const s=re(e,o),r=s.reduce((k,$)=>k+(o.sizeMap.get($)??0),0),a=se(n,o.snapshot,o.deps),u=e.reduce((k,$)=>{var w;return k+(((w=o.snapshot.milestones[$])==null?void 0:w.ki_estimate)??0)},0),f=a!==null?a+F(r)+u:null,_=ie(n,o.snapshot,o.deps),y=f!==null?f<=_:!0,v=De((l==null?void 0:l.agent)??null),b=Fe(e,o.snapshot.milestones,o.snapshot.operations),A=b!==null?"model-dispatch":"guard-only",M=b!==null?Ne:null;return{id:`${i}.dispatch.${t}`,milestones:e,operations:c,model:n,effort:p,two_stage:(l==null?void 0:l.two_stage)??!1,provider:null,agent_name:v,execution_mode:A,mcp_servers:null,resolved_max_tokens:null,background:!0,systemPrompt:M,prompt:b,context_files:s,si_bytes:r,tokens_estimated:f,fits_context_window:y,sentinel_role:null,dispatch_log_id:null,remote_task_id:null,result:null,status:"pending",started_at:null,completed_at:null,tokens_actual:null}}function Re(e,t){const n=oe(e);if(n.length===0)return[];const o=new Map;for(const u of e.operations){if(u.action==="guard")continue;const f=o.get(u.milestone)??[];f.push(u),o.set(u.milestone,f)}const i=new Map;for(const u of n){const f=e.milestones[u];if(f===void 0)continue;const _=Be(o.get(u)??[]),y=f.model??"_null",v=`${_}:${y}`,b=i.get(v)??[];b.push(u),i.set(v,b)}const l=new Set;for(const u of n){const f=e.milestones[u];if(f!==void 0){l.add(f.context);for(const _ of f.read_only)l.add(_);for(const _ of o.get(u)??[])_.file&&l.add(_.file)}}const p=Z(Array.from(l),t),c={snapshot:e,deps:t,sizeMap:p,opsByMilestone:o},s=[];let r=0;const a=Array.from(i.keys()).sort();for(const u of a){const f=i.get(u);if(f===void 0)continue;const _=u.slice(u.indexOf(":")+1),y=_!=="_null"?_:null,v=qe(f,y,c);for(const b of v)s.push(Ce(b,r++,y,c))}return s}function Ke(e,t){let n=0;for(const o of oe(e)){const i=e.milestones[o];if(i===void 0)continue;const l=We(i.model,e,t)??0;n+=l+(i.ki_estimate??0)}return n}function We(e,t,n){if(e===null)return null;const o=t.optimization.b_per_tier[e];if(o!=null)return o;const i=n.bPerTier[e];return i!==void 0?i:null}exports.computeTokensNaive=Ke;exports.optimize=Re;exports.snapshot=ze;exports.topoSortMilestones=ee;
10
+ `)}function se(e,t,n){if(e===null)return null;const o=t.optimization.b_eff_per_tier[e];if(o!=null)return o;const i=t.optimization.b_per_tier[e];if(i!=null)return i;const l=n.bPerTier[e];return l!==void 0?l:null}function ie(e,t,n){if(e===null)return Number.POSITIVE_INFINITY;const o=t.optimization.context_window_per_tier[e];if(o!==void 0)return o;const i=n.contextWindowPerTier[e];return i!==void 0?i:Number.POSITIVE_INFINITY}function re(e,t){const n=new Set;for(const o of e){const i=t.snapshot.milestones[o];if(i!==void 0){n.add(i.context);for(const l of i.read_only)n.add(l);for(const l of t.opsByMilestone.get(o)??[])l.file&&n.add(l.file)}}return Array.from(n)}function X(e,t,n){const o=se(t,n.snapshot,n.deps);if(o===null)return null;const l=re(e,n).reduce((s,r)=>s+(n.sizeMap.get(r)??0),0),p=F(l),c=e.reduce((s,r)=>{var a;return s+(((a=n.snapshot.milestones[r])==null?void 0:a.ki_estimate)??0)},0);return o+p+c}function qe(e,t,n){const o=ie(t,n.snapshot,n.deps),i=[...e].sort((c,s)=>{var u,f;const r=((u=n.snapshot.milestones[c])==null?void 0:u.ki_estimate)??0,a=((f=n.snapshot.milestones[s])==null?void 0:f.ki_estimate)??0;return r-a||c.localeCompare(s)}),l=[];let p=[];for(const c of i){const s=[...p,c],r=X(s,t,n);r!==null&&r>o&&p.length>0?(l.push(p),p=[c]):p=s}return p.length>0&&l.push(p),l.filter(c=>{const s=X(c,t,n);return s===null||s<=o})}function Ce(e,t,n,o){const i=e[0]??"",l=o.snapshot.milestones[i],p=(l==null?void 0:l.effort)??null,c=[];for(const k of e)for(const $ of o.opsByMilestone.get(k)??[])c.push($.id);const s=re(e,o),r=s.reduce((k,$)=>k+(o.sizeMap.get($)??0),0),a=se(n,o.snapshot,o.deps),u=e.reduce((k,$)=>{var w;return k+(((w=o.snapshot.milestones[$])==null?void 0:w.ki_estimate)??0)},0),f=a!==null?a+F(r)+u:null,_=ie(n,o.snapshot,o.deps),y=f!==null?f<=_:!0,v=Be((l==null?void 0:l.agent)??null),b=Fe(e,o.snapshot.milestones,o.snapshot.operations),A=b!==null?"model-dispatch":"guard-only",j=b!==null?De:null;return{id:`${i}.dispatch.${t}`,milestones:e,operations:c,model:n,effort:p,two_stage:(l==null?void 0:l.two_stage)??!1,provider:null,agent_name:v,execution_mode:A,mcp_servers:null,resolved_max_tokens:null,background:!0,systemPrompt:j,prompt:b,context_files:s,si_bytes:r,tokens_estimated:f,fits_context_window:y,sentinel_role:null,dispatch_log_id:null,remote_task_id:null,result:null,status:"pending",started_at:null,completed_at:null,tokens_actual:null}}function Re(e,t){const n=oe(e);if(n.length===0)return[];const o=new Map;for(const u of e.operations){if(u.action==="guard")continue;const f=o.get(u.milestone)??[];f.push(u),o.set(u.milestone,f)}const i=new Map;for(const u of n){const f=e.milestones[u];if(f===void 0)continue;const _=Ne(o.get(u)??[]),y=f.model??"_null",v=`${_}:${y}`,b=i.get(v)??[];b.push(u),i.set(v,b)}const l=new Set;for(const u of n){const f=e.milestones[u];if(f!==void 0){l.add(f.context);for(const _ of f.read_only)l.add(_);for(const _ of o.get(u)??[])_.file&&l.add(_.file)}}const p=Z(Array.from(l),t),c={snapshot:e,deps:t,sizeMap:p,opsByMilestone:o},s=[];let r=0;const a=Array.from(i.keys()).sort();for(const u of a){const f=i.get(u);if(f===void 0)continue;const _=u.slice(u.indexOf(":")+1),y=_!=="_null"?_:null,v=qe(f,y,c);for(const b of v)s.push(Ce(b,r++,y,c))}return s}function Ke(e,t){let n=0;for(const o of oe(e)){const i=e.milestones[o];if(i===void 0)continue;const l=We(i.model,e,t)??0;n+=l+(i.ki_estimate??0)}return n}function We(e,t,n){if(e===null)return null;const o=t.optimization.b_per_tier[e];if(o!=null)return o;const i=n.bPerTier[e];return i!==void 0?i:null}exports.computeTokensNaive=Ke;exports.optimize=Re;exports.snapshot=ze;exports.topoSortMilestones=ee;
package/index.mjs CHANGED
@@ -56,7 +56,12 @@ function _e(e) {
56
56
  g(`milestones.${s}.eligible`, "must be boolean", a)
57
57
  );
58
58
  const f = r.status;
59
- (!S(f) || !de.has(f)) && t.push(g(`milestones.${s}.status`, "invalid status", f));
59
+ (!S(f) || !de.has(f)) && t.push(g(`milestones.${s}.status`, "invalid status", f)), a === !0 && f === "complete" && t.push(
60
+ g(
61
+ `milestones.${s}`,
62
+ "D-07 violation: eligible=true but status is complete"
63
+ )
64
+ );
60
65
  const _ = r.wave;
61
66
  (typeof _ != "number" || !Number.isInteger(_) || _ < 0) && t.push(
62
67
  g(`milestones.${s}.wave`, "must be non-negative integer", _)
@@ -464,7 +469,7 @@ function Ie(e, t, n) {
464
469
  ), b = Array.from(y).filter((w) => v.has(w));
465
470
  if (b.length === 0)
466
471
  continue;
467
- const A = t.get(c) ?? "pending", M = t.get(s) ?? "pending", k = A === "complete" && M === "complete";
472
+ const A = t.get(c) ?? "pending", j = t.get(s) ?? "pending", k = A === "complete" && j === "complete";
468
473
  let $ = 0;
469
474
  for (const w of b)
470
475
  $ += k ? n(w) : 0;
@@ -494,14 +499,14 @@ function Re(e, t) {
494
499
  const d = e.milestones[m];
495
500
  if (d === void 0)
496
501
  continue;
497
- const j = (a.get(m) ?? []).map((I) => I.id), x = d.depends_on.map(
498
- (I) => y.get(I) ?? "pending"
502
+ const x = (a.get(m) ?? []).map((M) => M.id), I = d.depends_on.map(
503
+ (M) => y.get(M) ?? "pending"
499
504
  ), P = Ae(
500
505
  m,
501
506
  d,
502
- j,
507
+ x,
503
508
  o,
504
- x
509
+ I
505
510
  );
506
511
  y.set(m, P);
507
512
  }
@@ -510,19 +515,19 @@ function Re(e, t) {
510
515
  const d = e.milestones[m];
511
516
  if (d === void 0)
512
517
  continue;
513
- const j = s.get(m) ?? 0, x = a.get(m) ?? [], P = x.map((h) => h.id), I = y.get(m) ?? "pending", C = d.depends_on.map(
518
+ const x = s.get(m) ?? 0, I = a.get(m) ?? [], P = I.map((h) => h.id), M = y.get(m) ?? "pending", C = d.depends_on.map(
514
519
  (h) => y.get(h) ?? "pending"
515
- ), re = d.depends_on.length === 0 || C.every((h) => h === "complete"), le = C.every((h) => h !== "failed"), ue = d.pending === null && re && le, E = ee(o, [
520
+ ), re = d.depends_on.length === 0 || C.every((h) => h === "complete"), le = C.every((h) => h !== "failed"), ue = d.pending === null && re && le && M !== "complete", E = ee(o, [
516
521
  ...P,
517
522
  `${m}.guard`
518
523
  ]), ce = E.length > 0 ? E.map((h) => h.started_at).sort()[0] ?? null : null;
519
- let B, D, F;
524
+ let D, B, F;
520
525
  if (d.guard) {
521
526
  const h = Oe(m, o);
522
- B = h.guard_result, D = h.guard_output, F = h.completed_at;
527
+ D = h.guard_result, B = h.guard_output, F = h.completed_at;
523
528
  } else
524
- B = null, D = null, F = null;
525
- const R = Se(x), K = R.reduce((h, O) => h + _(O), 0), W = x.map(
529
+ D = null, B = null, F = null;
530
+ const R = Se(I), K = R.reduce((h, O) => h + _(O), 0), W = I.map(
526
531
  (h) => Te(h, d.effort, o)
527
532
  );
528
533
  let z = null, G = 0, Y = !1;
@@ -571,13 +576,13 @@ function Re(e, t) {
571
576
  read_only: d.read_only,
572
577
  guard: d.guard,
573
578
  context: `contexts/${m}.md`,
574
- wave: j,
579
+ wave: x,
575
580
  eligible: ue,
576
- status: I,
581
+ status: M,
577
582
  started_at: ce,
578
583
  completed_at: F,
579
- guard_result: B,
580
- guard_output: D,
584
+ guard_result: D,
585
+ guard_output: B,
581
586
  artifacts: R,
582
587
  si_bytes: K,
583
588
  ki_estimate: z,
@@ -585,7 +590,7 @@ function Re(e, t) {
585
590
  tokens_actual: V
586
591
  };
587
592
  }
588
- const M = Ie(
593
+ const j = Ie(
589
594
  a,
590
595
  y,
591
596
  _
@@ -594,8 +599,8 @@ function Re(e, t) {
594
599
  let m = 0;
595
600
  for (const d of Object.values(b))
596
601
  if (d.eligible && d.status === "pending" && d.model !== null) {
597
- const j = l[d.model] ?? t.bPerTier[d.model] ?? 0;
598
- m += j + (d.ki_estimate ?? 0);
602
+ const x = l[d.model] ?? t.bPerTier[d.model] ?? 0;
603
+ m += x + (d.ki_estimate ?? 0);
599
604
  }
600
605
  return m;
601
606
  })(),
@@ -625,7 +630,7 @@ function Re(e, t) {
625
630
  optimization: w,
626
631
  milestones: b,
627
632
  operations: A,
628
- pairwise_overlap: M,
633
+ pairwise_overlap: j,
629
634
  open_questions: k
630
635
  };
631
636
  return he(q), q;
@@ -658,7 +663,7 @@ function ne(e) {
658
663
  return n !== void 0 && n.eligible === !0 && n.status === "pending";
659
664
  });
660
665
  }
661
- function Be(e) {
666
+ function De(e) {
662
667
  if (e.length === 0 || e.every((t) => t.type === "tool-call"))
663
668
  return "tool-call";
664
669
  for (const t of e) {
@@ -674,7 +679,7 @@ function Be(e) {
674
679
  }
675
680
  return "code-config";
676
681
  }
677
- function De(e) {
682
+ function Be(e) {
678
683
  if (!e)
679
684
  return "";
680
685
  const t = e.indexOf(":");
@@ -805,7 +810,7 @@ function qe(e, t, n, o) {
805
810
  return k + (((w = o.snapshot.milestones[$]) == null ? void 0 : w.ki_estimate) ?? 0);
806
811
  },
807
812
  0
808
- ), f = a !== null ? a + N(r) + u : null, _ = se(n, o.snapshot, o.deps), y = f !== null ? f <= _ : !0, v = De((l == null ? void 0 : l.agent) ?? null), b = Fe(e, o.snapshot.milestones, o.snapshot.operations), A = b !== null ? "model-dispatch" : "guard-only", M = b !== null ? Ee : null;
813
+ ), f = a !== null ? a + N(r) + u : null, _ = se(n, o.snapshot, o.deps), y = f !== null ? f <= _ : !0, v = Be((l == null ? void 0 : l.agent) ?? null), b = Fe(e, o.snapshot.milestones, o.snapshot.operations), A = b !== null ? "model-dispatch" : "guard-only", j = b !== null ? Ee : null;
809
814
  return {
810
815
  id: `${i}.dispatch.${t}`,
811
816
  milestones: e,
@@ -819,7 +824,7 @@ function qe(e, t, n, o) {
819
824
  mcp_servers: null,
820
825
  resolved_max_tokens: null,
821
826
  background: !0,
822
- systemPrompt: M,
827
+ systemPrompt: j,
823
828
  prompt: b,
824
829
  context_files: s,
825
830
  si_bytes: r,
@@ -851,7 +856,7 @@ function Ke(e, t) {
851
856
  const f = e.milestones[u];
852
857
  if (f === void 0)
853
858
  continue;
854
- const _ = Be(o.get(u) ?? []), y = f.model ?? "_null", v = `${_}:${y}`, b = i.get(v) ?? [];
859
+ const _ = De(o.get(u) ?? []), y = f.model ?? "_null", v = `${_}:${y}`, b = i.get(v) ?? [];
855
860
  b.push(u), i.set(v, b);
856
861
  }
857
862
  const l = /* @__PURE__ */ new Set();
package/package.json CHANGED
@@ -1,10 +1,28 @@
1
1
  {
2
2
  "name": "@adhd/dispatch-core-optimizer",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "dependencies": {
5
- "@adhd/dispatch-base-spec": "^0.1.1"
5
+ "@adhd/dispatch-base-spec": "^0.1.3"
6
6
  },
7
7
  "main": "./index.js",
8
8
  "module": "./index.mjs",
9
- "typings": "./index.d.ts"
9
+ "typings": "./index.d.ts",
10
+ "description": "Optimizer for @adhd/dispatch task DAGs",
11
+ "keywords": [
12
+ "dag",
13
+ "optimizer",
14
+ "orchestration",
15
+ "task",
16
+ "typescript"
17
+ ],
18
+ "license": "MIT",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/PseudoSky/adhd.git",
22
+ "directory": "packages/dispatch/dispatch-core-optimizer"
23
+ },
24
+ "homepage": "https://github.com/PseudoSky/adhd/tree/main/packages/dispatch/dispatch-core-optimizer#readme",
25
+ "bugs": {
26
+ "url": "https://github.com/PseudoSky/adhd/issues"
27
+ }
10
28
  }