@adhd/dispatch-core-optimizer 0.1.0 → 0.1.2
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 +30 -0
- package/index.js +7 -7
- package/index.mjs +282 -272
- package/lib/optimize.d.ts +7 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
+
## 0.1.2 (2026-08-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### 🩹 Fixes
|
|
5
|
+
|
|
6
|
+
- **dispatch:** D-07 own-status eligibility guard (DEBT-DISPATCH-013) + formalize ICalibrationStore (DEBT-DISPATCH-018, BL-103)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### ❤️ Thank You
|
|
10
|
+
|
|
11
|
+
- pseudosky
|
|
12
|
+
|
|
13
|
+
## 0.1.1 (2026-08-07)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### 🚀 Features
|
|
17
|
+
|
|
18
|
+
- **dispatch-core-optimizer:** assemble DispatchUnit.systemPrompt/execution_mode, inline type_spec
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### 🩹 Fixes
|
|
22
|
+
|
|
23
|
+
- **apigen-cli:** restore 2768 files mass-deleted by 0117eb22 (BUG-APIGEN-052)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### ❤️ Thank You
|
|
27
|
+
|
|
28
|
+
- parity-harness-self-test
|
|
29
|
+
- pseudosky
|
|
30
|
+
|
|
1
31
|
## 0.0.6 (2026-07-25)
|
|
2
32
|
|
|
3
33
|
|
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
|
|
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 N(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 be={low:600,medium:1e3,high:2e3},ye=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 be[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 a;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=((a=e[s])==null?void 0:a.depends_on)??[];for(const c of r){const u=o.get(c);u!==void 0&&u.push(s),n.set(s,(n.get(s)??0)+1)}}const i=new Map,l=[];let f=t.filter(s=>(n.get(s)??0)===0).sort();for(const s of f)i.set(s,0);for(;f.length>0;){const s=[];for(const r of f){l.push(r);const c=(o.get(r)??[]).slice().sort();for(const u of c){const p=(n.get(u)??0)-1;n.set(u,p);const _=i.get(r)??0,b=i.get(u)??0;i.set(u,Math.max(b,_+1)),p===0&&s.push(u)}}f=s.sort()}if(l.length!==t.length){const s=new Set(l),r=t.filter(c=>!s.has(c));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`,f=[...n,l],a=te(o,f);for(const r of a)for(const c of r.results)if(c.op_id===l&&c.guard_result==="pass")return"complete";for(const r of a)for(const c of r.results)if(f.includes(c.op_id)&&c.status==="failed")return"failed";for(const r of a)for(const c of r.results)if(f.includes(c.op_id)&&c.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 f of t)if(f.operations.includes(n))for(const a of f.results)a.op_id===n&&a.guard_result!==null&&(o=a.guard_result,i=a.guard_output,a.guard_result==="pass"&&(l=a.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):ye.has(n.action)&&n.file&&t.add(n.file);return Array.from(t)}function Me(e,t,n){const o=ne(n,e.id),i=o.map(c=>c.id);let l=null,f=null,a=null;for(const c of o)for(const u of c.results)u.op_id===e.id&&u.guard_result!==null&&(l=u.guard_result,f=u.guard_output,a=u.guard_ran_at);const s=e.ki_estimate!==null&&e.ki_estimate!==void 0?e.ki_estimate:we(e,t),r=je(e.shape);return{...e,ki_estimate:s,shape:r,dispatch_ids:i,attempt_count:0,guard_result:l,guard_output:f,guard_ran_at:a,blast_radius:[],conflict:{detected:!1,competing_op:null,op_key:null,resolution:null},tokens_actual:null}}function je(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 Te(e,t,n,o){const i=`${e}.guard`,l=ne(o,i),f=l.map(c=>c.id);let a=null,s=null,r=null;for(const c of l)for(const u of c.results)u.op_id===i&&u.guard_result!==null&&(a=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:f,attempt_count:0,guard_result:a,guard_output:s,guard_ran_at:r,blast_radius:[],conflict:{detected:!1,competing_op:null,op_key:null,resolution:null},tokens_actual:null}}function Ie(e,t){const n={},{write_multiplier:o,read_multiplier:i,hit_probability:l}=t;for(const[f,a]of Object.entries(e))a===null?n[f]=null:n[f]=Math.round(a*((1-l)*o+l*i));return n}function xe(e,t,n){const o=Array.from(e.keys()),i={};for(let l=0;l<o.length;l++)for(let f=l+1;f<o.length;f++){const a=o[l],s=o[f];if(a===void 0||s===void 0)continue;const[r,c]=a<s?[a,s]:[s,a],u=`${r}:${c}`,p=e.get(a)??[],_=e.get(s)??[],b=new Set(p.map(w=>w.file).filter(w=>w!==null)),v=new Set(_.map(w=>w.file).filter(w=>w!==null)),y=Array.from(b).filter(w=>v.has(w));if(y.length===0)continue;const k=t.get(a)??"pending",$=t.get(s)??"pending",M=k==="complete"&&$==="complete";let P=0;for(const w of y)P+=M?n(w):0;i[u]=P}return i}function ze(e){return(Array.isArray(e)?e:Object.values(e)).map(n=>n.type===void 0?{...n,type:"generative"}:n)}function Pe(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),f=$e(e.optimization.context_window_per_tier,t.contextWindowPerTier),a=Ie(l,i),{waves:s}=ee(e.milestones),r=ze(e.operations),c=new Map;for(const m of r){const d=c.get(m.milestone)??[];d.push(m),c.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 p=Z(Array.from(u),t),_=m=>p.get(m)??0,b=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=(c.get(m)??[]).map(I=>I.id),T=d.depends_on.map(I=>b.get(I)??"pending"),x=Ae(m,d,j,o,T);b.set(m,x)}const y={},k=[];for(const m of v){const d=e.milestones[m];if(d===void 0)continue;const j=s.get(m)??0,T=c.get(m)??[],x=T.map(g=>g.id),I=b.get(m)??"pending",D=d.depends_on.map(g=>b.get(g)??"pending"),le=d.depends_on.length===0||D.every(g=>g==="complete"),ue=D.every(g=>g!=="failed"),ae=d.pending===null&&le&&ue,E=te(o,[...x,`${m}.guard`]),ce=E.length>0?E.map(g=>g.started_at).sort()[0]??null:null;let F,q,B;if(d.guard){const g=Oe(m,o);F=g.guard_result,q=g.guard_output,B=g.completed_at}else F=null,q=null,B=null;const R=Se(T),K=R.reduce((g,A)=>g+_(A),0),W=T.map(g=>Me(g,d.effort,o));let z=null,G=0,L=!1;for(const g of W){if(g.ki_estimate===null){L=!0;break}G+=g.ki_estimate}L||(z=G);let V=null;const Y=d.model;if(Y!==null&&z!==null){const g=a[Y]??null;if(g!==null){const A=N(K);V=g+A+z}}let H=null;const J=E.filter(g=>g.completed_at!==null&&g.results.length>0&&g.results.every(A=>A.status==="complete"||A.status==="skipped"));J.length>0&&(H=J.reduce((g,A)=>g+A.turns.reduce((pe,Q)=>pe+Q.input_tokens+Q.output_tokens,0),0));const fe=Te(m,d,x,o);k.push(...W,fe),y[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:ae,status:I,started_at:ce,completed_at:B,guard_result:F,guard_output:q,artifacts:R,si_bytes:K,ki_estimate:z,tokens_estimated:V,tokens_actual:H}}const $=xe(c,b,_),M=Ee(e,y),w={tokens_naive:(()=>{let m=0;for(const d of Object.values(y))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:a,context_window_per_tier:f},C={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:y,operations:k,pairwise_overlap:$,open_questions:M};return he(C),C}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 f=i.status==="pending-surfaced";n.push({id:`q:${o}`,text:l.pending,blocking:o,surfaced:f,raised_at_dispatch:null,raised_at_turn:null,answered:!1,answer:null})}return n}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 Fe(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 qe(e){if(!e)return"";const t=e.indexOf(":");return t>=0?e.slice(t+1):e}function Be(e,t,n){let o=!0;const i=[];for(const l of e){const f=t[l];if(f===void 0)continue;const a=n.filter(r=>r.milestone===l&&r.action!=="guard");a.some(r=>r.type==="generative")&&(o=!1),i.push(`## Milestone: ${l}`),i.push(f.description),f.rationale&&i.push(`
|
|
4
|
-
*Rationale:* ${
|
|
5
|
-
### Operations:`);for(const r of
|
|
6
|
-
`+JSON.stringify(
|
|
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
|
+
*Rationale:* ${p.rationale}`),i.push(`
|
|
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
|
+
`+JSON.stringify(f.schema,null,2).split(`
|
|
7
7
|
`).map(_=>` ${_}`).join(`
|
|
8
|
-
`));else if("ops"in
|
|
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),
|
|
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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const fe = /* @__PURE__ */ new Set([
|
|
2
2
|
"create",
|
|
3
3
|
"modify-signature",
|
|
4
4
|
"modify-body",
|
|
@@ -12,62 +12,67 @@ const pe = /* @__PURE__ */ new Set([
|
|
|
12
12
|
"complete",
|
|
13
13
|
"failed",
|
|
14
14
|
"skipped"
|
|
15
|
-
]),
|
|
15
|
+
]), me = /* @__PURE__ */ new Set([
|
|
16
16
|
"pending",
|
|
17
17
|
"in_progress",
|
|
18
18
|
"complete",
|
|
19
19
|
"failed",
|
|
20
20
|
"skipped"
|
|
21
21
|
]);
|
|
22
|
-
function
|
|
22
|
+
function T(e) {
|
|
23
23
|
return typeof e == "object" && e !== null && !Array.isArray(e);
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function S(e) {
|
|
26
26
|
return typeof e == "string";
|
|
27
27
|
}
|
|
28
28
|
function g(e, t, n) {
|
|
29
29
|
return { path: e, message: t, value: n };
|
|
30
30
|
}
|
|
31
|
-
function
|
|
31
|
+
function _e(e) {
|
|
32
32
|
const t = [];
|
|
33
|
-
if (!
|
|
33
|
+
if (!T(e))
|
|
34
34
|
return { valid: !1, errors: [g("", "root must be an object")] };
|
|
35
35
|
for (const o of ["snapshot_at", "description"])
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
S(e[o]) || t.push(g(o, "required string field missing", e[o]));
|
|
37
|
+
S(e.plan) || t.push(g("plan", "required string", e.plan));
|
|
38
38
|
const n = e.milestones;
|
|
39
|
-
if (!
|
|
39
|
+
if (!T(n))
|
|
40
40
|
t.push(g("milestones", "must be an object", n));
|
|
41
41
|
else {
|
|
42
42
|
const o = Object.keys(n), i = new Set(o);
|
|
43
43
|
for (const s of o) {
|
|
44
44
|
const r = n[s];
|
|
45
|
-
if (!
|
|
45
|
+
if (!T(r)) {
|
|
46
46
|
t.push(g(`milestones.${s}`, "must be an object", r));
|
|
47
47
|
continue;
|
|
48
48
|
}
|
|
49
|
-
const
|
|
50
|
-
|
|
49
|
+
const a = r.eligible, u = r.pending;
|
|
50
|
+
a === !0 && u !== null && u !== void 0 && t.push(
|
|
51
51
|
g(
|
|
52
52
|
`milestones.${s}`,
|
|
53
53
|
"D-07 violation: eligible=true but pending not null"
|
|
54
54
|
)
|
|
55
|
-
), typeof
|
|
56
|
-
g(`milestones.${s}.eligible`, "must be boolean",
|
|
55
|
+
), typeof a != "boolean" && t.push(
|
|
56
|
+
g(`milestones.${s}.eligible`, "must be boolean", a)
|
|
57
|
+
);
|
|
58
|
+
const f = r.status;
|
|
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
|
+
)
|
|
57
64
|
);
|
|
58
|
-
const
|
|
59
|
-
(
|
|
60
|
-
|
|
61
|
-
(typeof m != "number" || !Number.isInteger(m) || m < 0) && t.push(
|
|
62
|
-
g(`milestones.${s}.wave`, "must be non-negative integer", m)
|
|
65
|
+
const _ = r.wave;
|
|
66
|
+
(typeof _ != "number" || !Number.isInteger(_) || _ < 0) && t.push(
|
|
67
|
+
g(`milestones.${s}.wave`, "must be non-negative integer", _)
|
|
63
68
|
);
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
g(`milestones.${s}.ki_estimate`, "must be number|null",
|
|
69
|
+
const y = r.ki_estimate;
|
|
70
|
+
y != null && typeof y != "number" && t.push(
|
|
71
|
+
g(`milestones.${s}.ki_estimate`, "must be number|null", y)
|
|
67
72
|
);
|
|
68
73
|
for (const v of ["tokens_estimated", "tokens_actual"]) {
|
|
69
|
-
const
|
|
70
|
-
|
|
74
|
+
const b = r[v];
|
|
75
|
+
b != null && typeof b != "number" && t.push(g(`milestones.${s}.${v}`, "must be number|null", b));
|
|
71
76
|
}
|
|
72
77
|
Array.isArray(r.artifacts) || t.push(
|
|
73
78
|
g(
|
|
@@ -84,17 +89,17 @@ function me(e) {
|
|
|
84
89
|
t.push(g("operations", "must be an array", l));
|
|
85
90
|
else
|
|
86
91
|
for (const s of l) {
|
|
87
|
-
if (!
|
|
92
|
+
if (!T(s))
|
|
88
93
|
continue;
|
|
89
|
-
const r =
|
|
90
|
-
|
|
94
|
+
const r = S(s.id) ? s.id : "?", a = s.milestone;
|
|
95
|
+
S(a) && !i.has(a) && t.push(
|
|
91
96
|
g(
|
|
92
97
|
`operations[${r}].milestone`,
|
|
93
|
-
`unknown milestone "${
|
|
98
|
+
`unknown milestone "${a}"`
|
|
94
99
|
)
|
|
95
100
|
);
|
|
96
101
|
const u = s.status;
|
|
97
|
-
(!
|
|
102
|
+
(!S(u) || !me.has(u)) && t.push(
|
|
98
103
|
g(
|
|
99
104
|
`operations[${r}].status`,
|
|
100
105
|
"invalid operation status",
|
|
@@ -120,15 +125,15 @@ function me(e) {
|
|
|
120
125
|
)
|
|
121
126
|
);
|
|
122
127
|
}
|
|
123
|
-
const
|
|
124
|
-
if (!Array.isArray(
|
|
125
|
-
t.push(g("open_questions", "must be an array",
|
|
128
|
+
const p = e.open_questions;
|
|
129
|
+
if (!Array.isArray(p))
|
|
130
|
+
t.push(g("open_questions", "must be an array", p));
|
|
126
131
|
else
|
|
127
|
-
for (const s of
|
|
128
|
-
if (!
|
|
132
|
+
for (const s of p) {
|
|
133
|
+
if (!T(s))
|
|
129
134
|
continue;
|
|
130
135
|
const r = s.blocking;
|
|
131
|
-
(!
|
|
136
|
+
(!S(r) || !i.has(r)) && t.push(
|
|
132
137
|
g("open_questions", `unknown blocking milestone "${r}"`)
|
|
133
138
|
), typeof s.surfaced != "boolean" && t.push(
|
|
134
139
|
g(
|
|
@@ -144,15 +149,15 @@ function me(e) {
|
|
|
144
149
|
)
|
|
145
150
|
);
|
|
146
151
|
}
|
|
147
|
-
const
|
|
148
|
-
if (
|
|
149
|
-
if (!Array.isArray(
|
|
152
|
+
const c = e.dispatch_units;
|
|
153
|
+
if (c !== void 0)
|
|
154
|
+
if (!Array.isArray(c))
|
|
150
155
|
t.push(
|
|
151
|
-
g("dispatch_units", "must be an array if present",
|
|
156
|
+
g("dispatch_units", "must be an array if present", c)
|
|
152
157
|
);
|
|
153
158
|
else
|
|
154
|
-
for (const s of
|
|
155
|
-
if (!
|
|
159
|
+
for (const s of c) {
|
|
160
|
+
if (!T(s))
|
|
156
161
|
continue;
|
|
157
162
|
const r = s.fits_context_window;
|
|
158
163
|
typeof r != "boolean" && t.push(
|
|
@@ -162,17 +167,17 @@ function me(e) {
|
|
|
162
167
|
r
|
|
163
168
|
)
|
|
164
169
|
);
|
|
165
|
-
const
|
|
166
|
-
if (Array.isArray(
|
|
167
|
-
for (const u of
|
|
168
|
-
|
|
170
|
+
const a = s.milestones;
|
|
171
|
+
if (Array.isArray(a))
|
|
172
|
+
for (const u of a)
|
|
173
|
+
S(u) && !i.has(u) && t.push(
|
|
169
174
|
g(
|
|
170
175
|
`dispatch_units[${s.id}].milestones`,
|
|
171
176
|
`unknown milestone "${u}"`
|
|
172
177
|
)
|
|
173
178
|
);
|
|
174
179
|
}
|
|
175
|
-
|
|
180
|
+
T(e.pairwise_overlap) || t.push(
|
|
176
181
|
g(
|
|
177
182
|
"pairwise_overlap",
|
|
178
183
|
"must be an object",
|
|
@@ -183,7 +188,7 @@ function me(e) {
|
|
|
183
188
|
return { valid: t.length === 0, errors: t };
|
|
184
189
|
}
|
|
185
190
|
function he(e) {
|
|
186
|
-
const t =
|
|
191
|
+
const t = _e(e);
|
|
187
192
|
if (!t.valid)
|
|
188
193
|
throw new Error(
|
|
189
194
|
`Snapshot validation failed:
|
|
@@ -199,7 +204,7 @@ const U = {
|
|
|
199
204
|
py: 6.3,
|
|
200
205
|
default: 4
|
|
201
206
|
};
|
|
202
|
-
function
|
|
207
|
+
function N(e, t) {
|
|
203
208
|
if (e <= 0)
|
|
204
209
|
return 0;
|
|
205
210
|
const o = U[""] ?? U.default ?? 4;
|
|
@@ -218,8 +223,8 @@ const ge = {
|
|
|
218
223
|
low: 600,
|
|
219
224
|
medium: 1e3,
|
|
220
225
|
high: 2e3
|
|
221
|
-
},
|
|
222
|
-
function
|
|
226
|
+
}, ye = fe;
|
|
227
|
+
function be(e) {
|
|
223
228
|
const t = e.properties ?? {};
|
|
224
229
|
return Object.keys(t).length || Object.keys(e).length;
|
|
225
230
|
}
|
|
@@ -238,7 +243,7 @@ function ve(e, t) {
|
|
|
238
243
|
return ge[t ?? "medium"] ?? 1e3;
|
|
239
244
|
if (o === "structured-output") {
|
|
240
245
|
const i = "schema" in n && n.schema ? n.schema : {};
|
|
241
|
-
return
|
|
246
|
+
return be(i) * 50;
|
|
242
247
|
}
|
|
243
248
|
return 0;
|
|
244
249
|
}
|
|
@@ -263,37 +268,37 @@ function ke(e, t) {
|
|
|
263
268
|
return o;
|
|
264
269
|
}
|
|
265
270
|
function $e(e) {
|
|
266
|
-
var
|
|
271
|
+
var c;
|
|
267
272
|
const t = Object.keys(e), n = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map();
|
|
268
273
|
for (const s of t)
|
|
269
274
|
n.has(s) || n.set(s, 0), o.has(s) || o.set(s, []);
|
|
270
275
|
for (const s of t) {
|
|
271
|
-
const r = ((
|
|
272
|
-
for (const
|
|
273
|
-
const u = o.get(
|
|
276
|
+
const r = ((c = e[s]) == null ? void 0 : c.depends_on) ?? [];
|
|
277
|
+
for (const a of r) {
|
|
278
|
+
const u = o.get(a);
|
|
274
279
|
u !== void 0 && u.push(s), n.set(s, (n.get(s) ?? 0) + 1);
|
|
275
280
|
}
|
|
276
281
|
}
|
|
277
282
|
const i = /* @__PURE__ */ new Map(), l = [];
|
|
278
|
-
let
|
|
279
|
-
for (const s of
|
|
283
|
+
let p = t.filter((s) => (n.get(s) ?? 0) === 0).sort();
|
|
284
|
+
for (const s of p)
|
|
280
285
|
i.set(s, 0);
|
|
281
|
-
for (;
|
|
286
|
+
for (; p.length > 0; ) {
|
|
282
287
|
const s = [];
|
|
283
|
-
for (const r of
|
|
288
|
+
for (const r of p) {
|
|
284
289
|
l.push(r);
|
|
285
|
-
const
|
|
286
|
-
for (const u of
|
|
287
|
-
const
|
|
288
|
-
n.set(u,
|
|
289
|
-
const
|
|
290
|
-
i.set(u, Math.max(
|
|
290
|
+
const a = (o.get(r) ?? []).slice().sort();
|
|
291
|
+
for (const u of a) {
|
|
292
|
+
const f = (n.get(u) ?? 0) - 1;
|
|
293
|
+
n.set(u, f);
|
|
294
|
+
const _ = i.get(r) ?? 0, y = i.get(u) ?? 0;
|
|
295
|
+
i.set(u, Math.max(y, _ + 1)), f === 0 && s.push(u);
|
|
291
296
|
}
|
|
292
297
|
}
|
|
293
|
-
|
|
298
|
+
p = s.sort();
|
|
294
299
|
}
|
|
295
300
|
if (l.length !== t.length) {
|
|
296
|
-
const s = new Set(l), r = t.filter((
|
|
301
|
+
const s = new Set(l), r = t.filter((a) => !s.has(a));
|
|
297
302
|
throw new Error(
|
|
298
303
|
`snapshot(): cycle detected in milestone depends_on graph. Nodes involved: [${r.join(", ")}]`
|
|
299
304
|
);
|
|
@@ -312,20 +317,20 @@ function te(e, t) {
|
|
|
312
317
|
return e.filter((n) => n.operations.includes(t));
|
|
313
318
|
}
|
|
314
319
|
function Ae(e, t, n, o, i) {
|
|
315
|
-
const l = `${e}.guard`,
|
|
316
|
-
for (const r of
|
|
317
|
-
for (const
|
|
318
|
-
if (
|
|
320
|
+
const l = `${e}.guard`, p = [...n, l], c = ee(o, p);
|
|
321
|
+
for (const r of c)
|
|
322
|
+
for (const a of r.results)
|
|
323
|
+
if (a.op_id === l && a.guard_result === "pass")
|
|
319
324
|
return "complete";
|
|
320
|
-
for (const r of
|
|
321
|
-
for (const
|
|
322
|
-
if (
|
|
325
|
+
for (const r of c)
|
|
326
|
+
for (const a of r.results)
|
|
327
|
+
if (p.includes(a.op_id) && a.status === "failed")
|
|
323
328
|
return "failed";
|
|
324
|
-
for (const r of
|
|
325
|
-
for (const
|
|
326
|
-
if (
|
|
329
|
+
for (const r of c)
|
|
330
|
+
for (const a of r.results)
|
|
331
|
+
if (p.includes(a.op_id) && // "in_progress" is not a dispatch_log result status (only complete/failed/skipped)
|
|
327
332
|
// but orchestrators may write it; guard defensively
|
|
328
|
-
|
|
333
|
+
a.status === "in_progress")
|
|
329
334
|
return "in_progress";
|
|
330
335
|
const s = i.length === 0 || i.every((r) => r === "complete");
|
|
331
336
|
return t.pending !== null && s ? "pending-surfaced" : "pending";
|
|
@@ -333,10 +338,10 @@ function Ae(e, t, n, o, i) {
|
|
|
333
338
|
function Oe(e, t) {
|
|
334
339
|
const n = `${e}.guard`;
|
|
335
340
|
let o = null, i = null, l = null;
|
|
336
|
-
for (const
|
|
337
|
-
if (
|
|
338
|
-
for (const
|
|
339
|
-
|
|
341
|
+
for (const p of t)
|
|
342
|
+
if (p.operations.includes(n))
|
|
343
|
+
for (const c of p.results)
|
|
344
|
+
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));
|
|
340
345
|
return o !== null ? {
|
|
341
346
|
guard_result: o,
|
|
342
347
|
guard_output: i,
|
|
@@ -346,15 +351,15 @@ function Oe(e, t) {
|
|
|
346
351
|
function Se(e) {
|
|
347
352
|
const t = /* @__PURE__ */ new Set();
|
|
348
353
|
for (const n of e)
|
|
349
|
-
n.action === "move" && n.to_file ? t.add(n.to_file) :
|
|
354
|
+
n.action === "move" && n.to_file ? t.add(n.to_file) : ye.has(n.action) && n.file && t.add(n.file);
|
|
350
355
|
return Array.from(t);
|
|
351
356
|
}
|
|
352
|
-
function
|
|
353
|
-
const o = te(n, e.id), i = o.map((
|
|
354
|
-
let l = null,
|
|
355
|
-
for (const
|
|
356
|
-
for (const u of
|
|
357
|
-
u.op_id === e.id && u.guard_result !== null && (l = u.guard_result,
|
|
357
|
+
function Te(e, t, n) {
|
|
358
|
+
const o = te(n, e.id), i = o.map((a) => a.id);
|
|
359
|
+
let l = null, p = null, c = null;
|
|
360
|
+
for (const a of o)
|
|
361
|
+
for (const u of a.results)
|
|
362
|
+
u.op_id === e.id && u.guard_result !== null && (l = u.guard_result, p = u.guard_output, c = u.guard_ran_at);
|
|
358
363
|
const s = e.ki_estimate !== null && e.ki_estimate !== void 0 ? e.ki_estimate : ve(e, t), r = Me(e.shape);
|
|
359
364
|
return {
|
|
360
365
|
...e,
|
|
@@ -364,8 +369,8 @@ function je(e, t, n) {
|
|
|
364
369
|
// TODO: stubbed as 0 — op-level attempt_count requires per-op dispatch log scan
|
|
365
370
|
attempt_count: 0,
|
|
366
371
|
guard_result: l,
|
|
367
|
-
guard_output:
|
|
368
|
-
guard_ran_at:
|
|
372
|
+
guard_output: p,
|
|
373
|
+
guard_ran_at: c,
|
|
369
374
|
// TODO: stubbed — requires gitnexus_impact MCP call (future work)
|
|
370
375
|
blast_radius: [],
|
|
371
376
|
// TODO: stubbed — requires same-wave op-key collision scan (future work)
|
|
@@ -397,12 +402,12 @@ function Me(e) {
|
|
|
397
402
|
}
|
|
398
403
|
return e;
|
|
399
404
|
}
|
|
400
|
-
function
|
|
401
|
-
const i = `${e}.guard`, l = te(o, i),
|
|
402
|
-
let
|
|
403
|
-
for (const
|
|
404
|
-
for (const u of
|
|
405
|
-
u.op_id === i && u.guard_result !== null && (
|
|
405
|
+
function je(e, t, n, o) {
|
|
406
|
+
const i = `${e}.guard`, l = te(o, i), p = l.map((a) => a.id);
|
|
407
|
+
let c = null, s = null, r = null;
|
|
408
|
+
for (const a of l)
|
|
409
|
+
for (const u of a.results)
|
|
410
|
+
u.op_id === i && u.guard_result !== null && (c = u.guard_result, s = u.guard_output, r = u.guard_ran_at);
|
|
406
411
|
return {
|
|
407
412
|
id: i,
|
|
408
413
|
milestone: e,
|
|
@@ -425,9 +430,9 @@ function Te(e, t, n, o) {
|
|
|
425
430
|
authored_by: "synthesized",
|
|
426
431
|
status: "pending",
|
|
427
432
|
shape: null,
|
|
428
|
-
dispatch_ids:
|
|
433
|
+
dispatch_ids: p,
|
|
429
434
|
attempt_count: 0,
|
|
430
|
-
guard_result:
|
|
435
|
+
guard_result: c,
|
|
431
436
|
guard_output: s,
|
|
432
437
|
guard_ran_at: r,
|
|
433
438
|
blast_radius: [],
|
|
@@ -446,117 +451,117 @@ function xe(e, t) {
|
|
|
446
451
|
read_multiplier: i,
|
|
447
452
|
hit_probability: l
|
|
448
453
|
} = t;
|
|
449
|
-
for (const [
|
|
450
|
-
|
|
454
|
+
for (const [p, c] of Object.entries(e))
|
|
455
|
+
c === null ? n[p] = null : n[p] = Math.round(c * ((1 - l) * o + l * i));
|
|
451
456
|
return n;
|
|
452
457
|
}
|
|
453
458
|
function Ie(e, t, n) {
|
|
454
459
|
const o = Array.from(e.keys()), i = {};
|
|
455
460
|
for (let l = 0; l < o.length; l++)
|
|
456
|
-
for (let
|
|
457
|
-
const
|
|
458
|
-
if (
|
|
461
|
+
for (let p = l + 1; p < o.length; p++) {
|
|
462
|
+
const c = o[l], s = o[p];
|
|
463
|
+
if (c === void 0 || s === void 0)
|
|
459
464
|
continue;
|
|
460
|
-
const [r,
|
|
461
|
-
|
|
465
|
+
const [r, a] = c < s ? [c, s] : [s, c], u = `${r}:${a}`, f = e.get(c) ?? [], _ = e.get(s) ?? [], y = new Set(
|
|
466
|
+
f.map((w) => w.file).filter((w) => w !== null)
|
|
462
467
|
), v = new Set(
|
|
463
|
-
|
|
464
|
-
),
|
|
465
|
-
if (
|
|
468
|
+
_.map((w) => w.file).filter((w) => w !== null)
|
|
469
|
+
), b = Array.from(y).filter((w) => v.has(w));
|
|
470
|
+
if (b.length === 0)
|
|
466
471
|
continue;
|
|
467
|
-
const
|
|
468
|
-
let
|
|
469
|
-
for (const w of
|
|
470
|
-
|
|
471
|
-
i[u] =
|
|
472
|
+
const A = t.get(c) ?? "pending", j = t.get(s) ?? "pending", k = A === "complete" && j === "complete";
|
|
473
|
+
let $ = 0;
|
|
474
|
+
for (const w of b)
|
|
475
|
+
$ += k ? n(w) : 0;
|
|
476
|
+
i[u] = $;
|
|
472
477
|
}
|
|
473
478
|
return i;
|
|
474
479
|
}
|
|
475
|
-
function
|
|
480
|
+
function Pe(e) {
|
|
476
481
|
return (Array.isArray(e) ? e : Object.values(e)).map(
|
|
477
482
|
(n) => n.type === void 0 ? { ...n, type: "generative" } : n
|
|
478
483
|
);
|
|
479
484
|
}
|
|
480
|
-
function
|
|
481
|
-
const n = (/* @__PURE__ */ new Date()).toISOString(), o = t.dispatchLog ?? e.dispatch_log, i = e.optimization.sentinel_fanout, l = we(e.optimization.b_per_tier, t.bPerTier),
|
|
485
|
+
function Re(e, t) {
|
|
486
|
+
const n = (/* @__PURE__ */ new Date()).toISOString(), o = t.dispatchLog ?? e.dispatch_log, i = e.optimization.sentinel_fanout, l = we(e.optimization.b_per_tier, t.bPerTier), p = ke(
|
|
482
487
|
e.optimization.context_window_per_tier,
|
|
483
488
|
t.contextWindowPerTier
|
|
484
|
-
),
|
|
485
|
-
for (const
|
|
486
|
-
const d =
|
|
487
|
-
d.push(
|
|
489
|
+
), c = xe(l, i), { waves: s } = $e(e.milestones), r = Pe(e.operations), a = /* @__PURE__ */ new Map();
|
|
490
|
+
for (const m of r) {
|
|
491
|
+
const d = a.get(m.milestone) ?? [];
|
|
492
|
+
d.push(m), a.set(m.milestone, d);
|
|
488
493
|
}
|
|
489
494
|
const u = /* @__PURE__ */ new Set();
|
|
490
|
-
for (const
|
|
491
|
-
|
|
492
|
-
const
|
|
493
|
-
for (const
|
|
494
|
-
const d = e.milestones[
|
|
495
|
+
for (const m of r)
|
|
496
|
+
m.file && u.add(m.file), m.action === "move" && m.to_file && u.add(m.to_file);
|
|
497
|
+
const f = Z(Array.from(u), t), _ = (m) => f.get(m) ?? 0, y = /* @__PURE__ */ new Map(), v = Array.from(s.entries()).sort((m, d) => m[1] - d[1] || m[0].localeCompare(d[0])).map(([m]) => m);
|
|
498
|
+
for (const m of v) {
|
|
499
|
+
const d = e.milestones[m];
|
|
495
500
|
if (d === void 0)
|
|
496
501
|
continue;
|
|
497
|
-
const
|
|
498
|
-
(
|
|
499
|
-
),
|
|
500
|
-
|
|
502
|
+
const x = (a.get(m) ?? []).map((M) => M.id), I = d.depends_on.map(
|
|
503
|
+
(M) => y.get(M) ?? "pending"
|
|
504
|
+
), P = Ae(
|
|
505
|
+
m,
|
|
501
506
|
d,
|
|
502
|
-
|
|
507
|
+
x,
|
|
503
508
|
o,
|
|
504
|
-
|
|
509
|
+
I
|
|
505
510
|
);
|
|
506
|
-
|
|
511
|
+
y.set(m, P);
|
|
507
512
|
}
|
|
508
|
-
const
|
|
509
|
-
for (const
|
|
510
|
-
const d = e.milestones[
|
|
513
|
+
const b = {}, A = [];
|
|
514
|
+
for (const m of v) {
|
|
515
|
+
const d = e.milestones[m];
|
|
511
516
|
if (d === void 0)
|
|
512
517
|
continue;
|
|
513
|
-
const
|
|
514
|
-
(h) =>
|
|
515
|
-
), re = d.depends_on.length === 0 ||
|
|
516
|
-
...
|
|
517
|
-
`${
|
|
518
|
-
]),
|
|
519
|
-
let
|
|
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(
|
|
519
|
+
(h) => y.get(h) ?? "pending"
|
|
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, [
|
|
521
|
+
...P,
|
|
522
|
+
`${m}.guard`
|
|
523
|
+
]), ce = E.length > 0 ? E.map((h) => h.started_at).sort()[0] ?? null : null;
|
|
524
|
+
let D, B, F;
|
|
520
525
|
if (d.guard) {
|
|
521
|
-
const h = Oe(
|
|
522
|
-
|
|
526
|
+
const h = Oe(m, o);
|
|
527
|
+
D = h.guard_result, B = h.guard_output, F = h.completed_at;
|
|
523
528
|
} else
|
|
524
|
-
|
|
525
|
-
const R = Se(
|
|
526
|
-
(h) =>
|
|
529
|
+
D = null, B = null, F = null;
|
|
530
|
+
const R = Se(I), K = R.reduce((h, O) => h + _(O), 0), W = I.map(
|
|
531
|
+
(h) => Te(h, d.effort, o)
|
|
527
532
|
);
|
|
528
|
-
let z = null, G = 0,
|
|
533
|
+
let z = null, G = 0, Y = !1;
|
|
529
534
|
for (const h of W) {
|
|
530
535
|
if (h.ki_estimate === null) {
|
|
531
|
-
|
|
536
|
+
Y = !0;
|
|
532
537
|
break;
|
|
533
538
|
}
|
|
534
539
|
G += h.ki_estimate;
|
|
535
540
|
}
|
|
536
|
-
|
|
537
|
-
let
|
|
538
|
-
const
|
|
539
|
-
if (
|
|
540
|
-
const h =
|
|
541
|
+
Y || (z = G);
|
|
542
|
+
let H = null;
|
|
543
|
+
const L = d.model;
|
|
544
|
+
if (L !== null && z !== null) {
|
|
545
|
+
const h = c[L] ?? null;
|
|
541
546
|
if (h !== null) {
|
|
542
|
-
const
|
|
543
|
-
|
|
547
|
+
const O = N(K);
|
|
548
|
+
H = h + O + z;
|
|
544
549
|
}
|
|
545
550
|
}
|
|
546
|
-
let
|
|
551
|
+
let V = null;
|
|
547
552
|
const J = E.filter(
|
|
548
553
|
(h) => h.completed_at !== null && h.results.length > 0 && h.results.every(
|
|
549
|
-
(
|
|
554
|
+
(O) => O.status === "complete" || O.status === "skipped"
|
|
550
555
|
)
|
|
551
556
|
);
|
|
552
|
-
J.length > 0 && (
|
|
553
|
-
const
|
|
554
|
-
|
|
557
|
+
J.length > 0 && (V = J.reduce((h, O) => h + O.turns.reduce((pe, Q) => pe + Q.input_tokens + Q.output_tokens, 0), 0));
|
|
558
|
+
const ae = je(
|
|
559
|
+
m,
|
|
555
560
|
d,
|
|
556
|
-
|
|
561
|
+
P,
|
|
557
562
|
o
|
|
558
563
|
);
|
|
559
|
-
|
|
564
|
+
A.push(...W, ae), b[m] = {
|
|
560
565
|
description: d.description,
|
|
561
566
|
...d.rationale !== void 0 ? { rationale: d.rationale } : {},
|
|
562
567
|
authored_by: d.authored_by,
|
|
@@ -570,42 +575,42 @@ function Ne(e, t) {
|
|
|
570
575
|
two_stage: d.two_stage,
|
|
571
576
|
read_only: d.read_only,
|
|
572
577
|
guard: d.guard,
|
|
573
|
-
context: `contexts/${
|
|
574
|
-
wave:
|
|
578
|
+
context: `contexts/${m}.md`,
|
|
579
|
+
wave: x,
|
|
575
580
|
eligible: ue,
|
|
576
|
-
status:
|
|
577
|
-
started_at:
|
|
578
|
-
completed_at:
|
|
579
|
-
guard_result:
|
|
580
|
-
guard_output:
|
|
581
|
+
status: M,
|
|
582
|
+
started_at: ce,
|
|
583
|
+
completed_at: F,
|
|
584
|
+
guard_result: D,
|
|
585
|
+
guard_output: B,
|
|
581
586
|
artifacts: R,
|
|
582
587
|
si_bytes: K,
|
|
583
588
|
ki_estimate: z,
|
|
584
|
-
tokens_estimated:
|
|
585
|
-
tokens_actual:
|
|
589
|
+
tokens_estimated: H,
|
|
590
|
+
tokens_actual: V
|
|
586
591
|
};
|
|
587
592
|
}
|
|
588
|
-
const
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
),
|
|
593
|
+
const j = Ie(
|
|
594
|
+
a,
|
|
595
|
+
y,
|
|
596
|
+
_
|
|
597
|
+
), k = ze(e, b), w = {
|
|
593
598
|
tokens_naive: (() => {
|
|
594
|
-
let
|
|
595
|
-
for (const d of Object.values(
|
|
599
|
+
let m = 0;
|
|
600
|
+
for (const d of Object.values(b))
|
|
596
601
|
if (d.eligible && d.status === "pending" && d.model !== null) {
|
|
597
|
-
const
|
|
598
|
-
|
|
602
|
+
const x = l[d.model] ?? t.bPerTier[d.model] ?? 0;
|
|
603
|
+
m += x + (d.ki_estimate ?? 0);
|
|
599
604
|
}
|
|
600
|
-
return
|
|
605
|
+
return m;
|
|
601
606
|
})(),
|
|
602
607
|
sentinel_fanout: i,
|
|
603
608
|
context_window_override: e.optimization.context_window_override,
|
|
604
609
|
b_override: e.optimization.b_override,
|
|
605
610
|
b_per_tier: l,
|
|
606
|
-
b_eff_per_tier:
|
|
607
|
-
context_window_per_tier:
|
|
608
|
-
},
|
|
611
|
+
b_eff_per_tier: c,
|
|
612
|
+
context_window_per_tier: p
|
|
613
|
+
}, q = {
|
|
609
614
|
snapshot_at: n,
|
|
610
615
|
snapshot_version: 1,
|
|
611
616
|
// callers may increment if persisting
|
|
@@ -623,25 +628,25 @@ function Ne(e, t) {
|
|
|
623
628
|
terminal: e.terminal,
|
|
624
629
|
...e.assumed_baseline !== void 0 ? { assumed_baseline: e.assumed_baseline } : {},
|
|
625
630
|
optimization: w,
|
|
626
|
-
milestones:
|
|
627
|
-
operations:
|
|
628
|
-
pairwise_overlap:
|
|
629
|
-
open_questions:
|
|
631
|
+
milestones: b,
|
|
632
|
+
operations: A,
|
|
633
|
+
pairwise_overlap: j,
|
|
634
|
+
open_questions: k
|
|
630
635
|
};
|
|
631
|
-
return he(
|
|
636
|
+
return he(q), q;
|
|
632
637
|
}
|
|
633
|
-
function
|
|
638
|
+
function ze(e, t) {
|
|
634
639
|
const n = [];
|
|
635
640
|
for (const [o, i] of Object.entries(t)) {
|
|
636
641
|
const l = e.milestones[o];
|
|
637
642
|
if (l === void 0 || l.pending === null)
|
|
638
643
|
continue;
|
|
639
|
-
const
|
|
644
|
+
const p = i.status === "pending-surfaced";
|
|
640
645
|
n.push({
|
|
641
646
|
id: `q:${o}`,
|
|
642
647
|
text: l.pending,
|
|
643
648
|
blocking: o,
|
|
644
|
-
surfaced:
|
|
649
|
+
surfaced: p,
|
|
645
650
|
// TODO: scan dispatch_log notes for the turn/dispatch where question appeared
|
|
646
651
|
raised_at_dispatch: null,
|
|
647
652
|
raised_at_turn: null,
|
|
@@ -651,13 +656,14 @@ function Pe(e, t) {
|
|
|
651
656
|
}
|
|
652
657
|
return n;
|
|
653
658
|
}
|
|
659
|
+
const Ee = "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.";
|
|
654
660
|
function ne(e) {
|
|
655
661
|
return Object.keys(e.milestones).filter((t) => {
|
|
656
662
|
const n = e.milestones[t];
|
|
657
663
|
return n !== void 0 && n.eligible === !0 && n.status === "pending";
|
|
658
664
|
});
|
|
659
665
|
}
|
|
660
|
-
function
|
|
666
|
+
function De(e) {
|
|
661
667
|
if (e.length === 0 || e.every((t) => t.type === "tool-call"))
|
|
662
668
|
return "tool-call";
|
|
663
669
|
for (const t of e) {
|
|
@@ -673,48 +679,50 @@ function Ee(e) {
|
|
|
673
679
|
}
|
|
674
680
|
return "code-config";
|
|
675
681
|
}
|
|
676
|
-
function
|
|
682
|
+
function Be(e) {
|
|
677
683
|
if (!e)
|
|
678
684
|
return "";
|
|
679
685
|
const t = e.indexOf(":");
|
|
680
686
|
return t >= 0 ? e.slice(t + 1) : e;
|
|
681
687
|
}
|
|
682
|
-
function
|
|
688
|
+
function Fe(e, t, n) {
|
|
683
689
|
let o = !0;
|
|
684
690
|
const i = [];
|
|
685
691
|
for (const l of e) {
|
|
686
|
-
const
|
|
687
|
-
if (
|
|
692
|
+
const p = t[l];
|
|
693
|
+
if (p === void 0)
|
|
688
694
|
continue;
|
|
689
|
-
const
|
|
695
|
+
const c = n.filter(
|
|
690
696
|
(r) => r.milestone === l && r.action !== "guard"
|
|
691
697
|
);
|
|
692
|
-
|
|
693
|
-
*Rationale:* ${
|
|
698
|
+
c.some((r) => r.type === "generative") && (o = !1), i.push(`## Milestone: ${l}`), i.push(p.description), p.rationale && i.push(`
|
|
699
|
+
*Rationale:* ${p.rationale}`), i.push(`
|
|
694
700
|
### Operations:`);
|
|
695
|
-
for (const r of
|
|
696
|
-
const
|
|
697
|
-
if (i.push(`- [${r.id}] ${r.action}${
|
|
698
|
-
const
|
|
699
|
-
if (
|
|
700
|
-
i.push(` Description: ${
|
|
701
|
-
` Required sections: ${
|
|
701
|
+
for (const r of c) {
|
|
702
|
+
const a = r.file ? ` ${r.file}` : "", u = r.symbol ? ` (${r.symbol})` : "";
|
|
703
|
+
if (i.push(`- [${r.id}] ${r.action}${a}${u}`), r.shape && r.shape.kind !== null) {
|
|
704
|
+
const f = r.shape;
|
|
705
|
+
if (f.kind === "doc")
|
|
706
|
+
i.push(` Description: ${f.description}`), i.push(` Objective: ${f.objective}`), f.required_sections && f.required_sections.length > 0 && i.push(
|
|
707
|
+
` Required sections: ${f.required_sections.join(", ")}`
|
|
702
708
|
);
|
|
703
|
-
else if (
|
|
709
|
+
else if (f.kind === "structured-output")
|
|
704
710
|
i.push(
|
|
705
711
|
` Schema:
|
|
706
|
-
` + JSON.stringify(
|
|
707
|
-
`).map((
|
|
712
|
+
` + JSON.stringify(f.schema, null, 2).split(`
|
|
713
|
+
`).map((_) => ` ${_}`).join(`
|
|
708
714
|
`)
|
|
709
715
|
);
|
|
710
|
-
else if ("ops" in
|
|
711
|
-
for (const
|
|
712
|
-
const
|
|
713
|
-
i.push(` - ${
|
|
716
|
+
else if ("ops" in f && Array.isArray(f.ops))
|
|
717
|
+
for (const _ of f.ops) {
|
|
718
|
+
const y = _.to !== null ? ` → ${_.to}` : "", v = _.target !== null ? ` "${_.target}"` : "";
|
|
719
|
+
if (i.push(` - ${_.op}${v}${y}`), _.type_spec)
|
|
720
|
+
for (const [b, A] of Object.entries(_.type_spec))
|
|
721
|
+
i.push(` - ${b}: ${A}`);
|
|
714
722
|
}
|
|
715
723
|
}
|
|
716
724
|
}
|
|
717
|
-
const s =
|
|
725
|
+
const s = p.guard;
|
|
718
726
|
i.push(`
|
|
719
727
|
### Guard: ${s ?? "none"}`), i.push("");
|
|
720
728
|
}
|
|
@@ -763,63 +771,65 @@ function X(e, t, n) {
|
|
|
763
771
|
const l = ie(e, n).reduce(
|
|
764
772
|
(s, r) => s + (n.sizeMap.get(r) ?? 0),
|
|
765
773
|
0
|
|
766
|
-
),
|
|
774
|
+
), p = N(l), c = e.reduce(
|
|
767
775
|
(s, r) => {
|
|
768
|
-
var
|
|
769
|
-
return s + (((
|
|
776
|
+
var a;
|
|
777
|
+
return s + (((a = n.snapshot.milestones[r]) == null ? void 0 : a.ki_estimate) ?? 0);
|
|
770
778
|
},
|
|
771
779
|
0
|
|
772
780
|
);
|
|
773
|
-
return o +
|
|
781
|
+
return o + p + c;
|
|
774
782
|
}
|
|
775
|
-
function
|
|
776
|
-
const o = se(t, n.snapshot, n.deps), i = [...e].sort((
|
|
777
|
-
var u,
|
|
778
|
-
const r = ((u = n.snapshot.milestones[
|
|
779
|
-
return r -
|
|
783
|
+
function Ne(e, t, n) {
|
|
784
|
+
const o = se(t, n.snapshot, n.deps), i = [...e].sort((c, s) => {
|
|
785
|
+
var u, f;
|
|
786
|
+
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;
|
|
787
|
+
return r - a || c.localeCompare(s);
|
|
780
788
|
}), l = [];
|
|
781
|
-
let
|
|
782
|
-
for (const
|
|
783
|
-
const s = [...
|
|
784
|
-
r !== null && r > o &&
|
|
789
|
+
let p = [];
|
|
790
|
+
for (const c of i) {
|
|
791
|
+
const s = [...p, c], r = X(s, t, n);
|
|
792
|
+
r !== null && r > o && p.length > 0 ? (l.push(p), p = [c]) : p = s;
|
|
785
793
|
}
|
|
786
|
-
return
|
|
787
|
-
const s = X(
|
|
794
|
+
return p.length > 0 && l.push(p), l.filter((c) => {
|
|
795
|
+
const s = X(c, t, n);
|
|
788
796
|
return s === null || s <= o;
|
|
789
797
|
});
|
|
790
798
|
}
|
|
791
|
-
function
|
|
792
|
-
const i = e[0] ?? "", l = o.snapshot.milestones[i],
|
|
799
|
+
function qe(e, t, n, o) {
|
|
800
|
+
const i = e[0] ?? "", l = o.snapshot.milestones[i], p = (l == null ? void 0 : l.effort) ?? null, c = [];
|
|
793
801
|
for (const k of e)
|
|
794
802
|
for (const $ of o.opsByMilestone.get(k) ?? [])
|
|
795
|
-
|
|
803
|
+
c.push($.id);
|
|
796
804
|
const s = ie(e, o), r = s.reduce(
|
|
797
805
|
(k, $) => k + (o.sizeMap.get($) ?? 0),
|
|
798
806
|
0
|
|
799
|
-
),
|
|
807
|
+
), a = oe(n, o.snapshot, o.deps), u = e.reduce(
|
|
800
808
|
(k, $) => {
|
|
801
|
-
var
|
|
802
|
-
return k + (((
|
|
809
|
+
var w;
|
|
810
|
+
return k + (((w = o.snapshot.milestones[$]) == null ? void 0 : w.ki_estimate) ?? 0);
|
|
803
811
|
},
|
|
804
812
|
0
|
|
805
|
-
),
|
|
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;
|
|
806
814
|
return {
|
|
807
815
|
id: `${i}.dispatch.${t}`,
|
|
808
816
|
milestones: e,
|
|
809
|
-
operations:
|
|
817
|
+
operations: c,
|
|
810
818
|
model: n,
|
|
811
|
-
effort:
|
|
819
|
+
effort: p,
|
|
812
820
|
two_stage: (l == null ? void 0 : l.two_stage) ?? !1,
|
|
813
821
|
provider: null,
|
|
814
822
|
agent_name: v,
|
|
823
|
+
execution_mode: A,
|
|
815
824
|
mcp_servers: null,
|
|
816
825
|
resolved_max_tokens: null,
|
|
817
826
|
background: !0,
|
|
818
|
-
|
|
827
|
+
systemPrompt: j,
|
|
828
|
+
prompt: b,
|
|
819
829
|
context_files: s,
|
|
820
830
|
si_bytes: r,
|
|
821
|
-
tokens_estimated:
|
|
822
|
-
fits_context_window:
|
|
831
|
+
tokens_estimated: f,
|
|
832
|
+
fits_context_window: y,
|
|
823
833
|
sentinel_role: null,
|
|
824
834
|
dispatch_log_id: null,
|
|
825
835
|
remote_task_id: null,
|
|
@@ -830,7 +840,7 @@ function Ce(e, t, n, o) {
|
|
|
830
840
|
tokens_actual: null
|
|
831
841
|
};
|
|
832
842
|
}
|
|
833
|
-
function
|
|
843
|
+
function Ke(e, t) {
|
|
834
844
|
const n = ne(e);
|
|
835
845
|
if (n.length === 0)
|
|
836
846
|
return [];
|
|
@@ -838,53 +848,53 @@ function Re(e, t) {
|
|
|
838
848
|
for (const u of e.operations) {
|
|
839
849
|
if (u.action === "guard")
|
|
840
850
|
continue;
|
|
841
|
-
const
|
|
842
|
-
|
|
851
|
+
const f = o.get(u.milestone) ?? [];
|
|
852
|
+
f.push(u), o.set(u.milestone, f);
|
|
843
853
|
}
|
|
844
854
|
const i = /* @__PURE__ */ new Map();
|
|
845
855
|
for (const u of n) {
|
|
846
|
-
const
|
|
847
|
-
if (
|
|
856
|
+
const f = e.milestones[u];
|
|
857
|
+
if (f === void 0)
|
|
848
858
|
continue;
|
|
849
|
-
const
|
|
850
|
-
|
|
859
|
+
const _ = De(o.get(u) ?? []), y = f.model ?? "_null", v = `${_}:${y}`, b = i.get(v) ?? [];
|
|
860
|
+
b.push(u), i.set(v, b);
|
|
851
861
|
}
|
|
852
862
|
const l = /* @__PURE__ */ new Set();
|
|
853
863
|
for (const u of n) {
|
|
854
|
-
const
|
|
855
|
-
if (
|
|
856
|
-
l.add(
|
|
857
|
-
for (const
|
|
858
|
-
l.add(
|
|
859
|
-
for (const
|
|
860
|
-
|
|
864
|
+
const f = e.milestones[u];
|
|
865
|
+
if (f !== void 0) {
|
|
866
|
+
l.add(f.context);
|
|
867
|
+
for (const _ of f.read_only)
|
|
868
|
+
l.add(_);
|
|
869
|
+
for (const _ of o.get(u) ?? [])
|
|
870
|
+
_.file && l.add(_.file);
|
|
861
871
|
}
|
|
862
872
|
}
|
|
863
|
-
const
|
|
873
|
+
const p = Z(Array.from(l), t), c = { snapshot: e, deps: t, sizeMap: p, opsByMilestone: o }, s = [];
|
|
864
874
|
let r = 0;
|
|
865
|
-
const
|
|
866
|
-
for (const u of
|
|
867
|
-
const
|
|
868
|
-
if (
|
|
875
|
+
const a = Array.from(i.keys()).sort();
|
|
876
|
+
for (const u of a) {
|
|
877
|
+
const f = i.get(u);
|
|
878
|
+
if (f === void 0)
|
|
869
879
|
continue;
|
|
870
|
-
const
|
|
871
|
-
for (const
|
|
872
|
-
s.push(
|
|
880
|
+
const _ = u.slice(u.indexOf(":") + 1), y = _ !== "_null" ? _ : null, v = Ne(f, y, c);
|
|
881
|
+
for (const b of v)
|
|
882
|
+
s.push(qe(b, r++, y, c));
|
|
873
883
|
}
|
|
874
884
|
return s;
|
|
875
885
|
}
|
|
876
|
-
function
|
|
886
|
+
function We(e, t) {
|
|
877
887
|
let n = 0;
|
|
878
888
|
for (const o of ne(e)) {
|
|
879
889
|
const i = e.milestones[o];
|
|
880
890
|
if (i === void 0)
|
|
881
891
|
continue;
|
|
882
|
-
const l =
|
|
892
|
+
const l = Ce(i.model, e, t) ?? 0;
|
|
883
893
|
n += l + (i.ki_estimate ?? 0);
|
|
884
894
|
}
|
|
885
895
|
return n;
|
|
886
896
|
}
|
|
887
|
-
function
|
|
897
|
+
function Ce(e, t, n) {
|
|
888
898
|
if (e === null)
|
|
889
899
|
return null;
|
|
890
900
|
const o = t.optimization.b_per_tier[e];
|
|
@@ -894,8 +904,8 @@ function De(e, t, n) {
|
|
|
894
904
|
return i !== void 0 ? i : null;
|
|
895
905
|
}
|
|
896
906
|
export {
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
907
|
+
We as computeTokensNaive,
|
|
908
|
+
Ke as optimize,
|
|
909
|
+
Re as snapshot,
|
|
900
910
|
$e as topoSortMilestones
|
|
901
911
|
};
|
package/lib/optimize.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { DagSnapshot, DispatchUnit, IOptimizerDeps } from '@adhd/dispatch-base-spec';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Stable, milestone-independent preamble baked into every model-dispatch
|
|
5
|
+
* DispatchUnit's `systemPrompt` (DEBT-DISPATCH-012). Never varies per
|
|
6
|
+
* milestone — that's precisely what makes it safe to bake once at
|
|
7
|
+
* agent_create and never re-send.
|
|
8
|
+
*/
|
|
9
|
+
export declare const DISPATCH_AGENT_SYSTEM_PREAMBLE: string;
|
|
3
10
|
/**
|
|
4
11
|
* Compute the greedy dispatch plan for the current scheduling cycle.
|
|
5
12
|
*
|
package/package.json
CHANGED