@adhd/dispatch-core-optimizer 0.1.4 → 0.1.6
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 +10 -0
- package/index.js +2 -2
- package/index.mjs +3 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## 0.1.6 (2026-10-06)
|
|
2
|
+
|
|
3
|
+
### 🩹 Fixes
|
|
4
|
+
|
|
5
|
+
- **dispatch-orchestrator,dispatch-cli:** make HITL reachable from dispatch ([57f53429](https://github.com/PseudoSky/adhd/commit/57f53429))
|
|
6
|
+
|
|
7
|
+
### ❤️ Thank You
|
|
8
|
+
|
|
9
|
+
- pseudosky
|
|
10
|
+
|
|
1
11
|
## 0.1.4 (2026-09-26)
|
|
2
12
|
|
|
3
13
|
### 🚀 Features
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=new Set([`create`,`modify-signature`,`modify-body`,`add-export`,`remove-export`,`rename`]),t=new Set([`pending`,`pending-surfaced`,`in_progress`,`complete`,`failed`,`skipped`]),n=new Set([`pending`,`in_progress`,`complete`,`failed`,`skipped`]);function r(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function i(e){return typeof e==`string`}function a(e,t,n){return{path:e,message:t,value:n}}function o(e){let o=[];if(!r(e))return{valid:!1,errors:[a(``,`root must be an object`)]};for(let t of[`snapshot_at`,`description`])i(e[t])||o.push(a(t,`required string field missing`,e[t]));i(e.plan)||o.push(a(`plan`,`required string`,e.plan));let s=e.milestones;if(!r(s))o.push(a(`milestones`,`must be an object`,s));else{let c=Object.keys(s),l=new Set(c);for(let e of c){let n=s[e];if(!r(n)){o.push(a(`milestones.${e}`,`must be an object`,n));continue}let c=n.eligible,l=n.pending;c===!0&&l!=null&&o.push(a(`milestones.${e}`,`D-07 violation: eligible=true but pending not null`)),typeof c!=`boolean`&&o.push(a(`milestones.${e}.eligible`,`must be boolean`,c));let u=n.status;(!i(u)||!t.has(u))&&o.push(a(`milestones.${e}.status`,`invalid status`,u)),c===!0&&u===`complete`&&o.push(a(`milestones.${e}`,`D-07 violation: eligible=true but status is complete`));let d=n.wave;(typeof d!=`number`||!Number.isInteger(d)||d<0)&&o.push(a(`milestones.${e}.wave`,`must be non-negative integer`,d));let f=n.ki_estimate;f!=null&&typeof f!=`number`&&o.push(a(`milestones.${e}.ki_estimate`,`must be number|null`,f));for(let t of[`tokens_estimated`,`tokens_actual`]){let r=n[t];r!=null&&typeof r!=`number`&&o.push(a(`milestones.${e}.${t}`,`must be number|null`,r))}Array.isArray(n.artifacts)||o.push(a(`milestones.${e}.artifacts`,`must be an array`,n.artifacts)),typeof n.si_bytes!=`number`&&o.push(a(`milestones.${e}.si_bytes`,`must be a number`,n.si_bytes))}let u=e.operations;if(!Array.isArray(u))o.push(a(`operations`,`must be an array`,u));else for(let e of u){if(!r(e))continue;let t=i(e.id)?e.id:`?`,s=e.milestone;i(s)&&!l.has(s)&&o.push(a(`operations[${t}].milestone`,`unknown milestone "${s}"`));let c=e.status;(!i(c)||!n.has(c))&&o.push(a(`operations[${t}].status`,`invalid operation status`,c)),Array.isArray(e.dispatch_ids)||o.push(a(`operations[${t}].dispatch_ids`,`must be an array`,e.dispatch_ids)),typeof e.attempt_count!=`number`&&o.push(a(`operations[${t}].attempt_count`,`must be a number`,e.attempt_count)),Array.isArray(e.blast_radius)||o.push(a(`operations[${t}].blast_radius`,`must be an array`,e.blast_radius))}let d=e.open_questions;if(!Array.isArray(d))o.push(a(`open_questions`,`must be an array`,d));else for(let e of d){if(!r(e))continue;let t=e.blocking;(!i(t)||!l.has(t))&&o.push(a(`open_questions`,`unknown blocking milestone "${t}"`)),typeof e.surfaced!=`boolean`&&o.push(a(`open_questions[${e.id}]`,`surfaced must be boolean`,e.surfaced)),typeof e.answered!=`boolean`&&o.push(a(`open_questions[${e.id}]`,`answered must be boolean`,e.answered))}let f=e.dispatch_units;if(f!==void 0){if(!Array.isArray(f))o.push(a(`dispatch_units`,`must be an array if present`,f));else for(let e of f){if(!r(e))continue;let t=e.fits_context_window;typeof t!=`boolean`&&o.push(a(`dispatch_units[${e.id}]`,`fits_context_window must be boolean`,t));let n=e.milestones;if(Array.isArray(n))for(let t of n)i(t)&&!l.has(t)&&o.push(a(`dispatch_units[${e.id}].milestones`,`unknown milestone "${t}"`))}}r(e.pairwise_overlap)||o.push(a(`pairwise_overlap`,`must be an object`,e.pairwise_overlap))}return{valid:o.length===0,errors:o}}function s(e){let t=o(e);if(!t.valid)throw Error(`Snapshot validation failed:\n${t.errors.map(e=>` ${e.path}: ${e.message}`).join(`
|
|
2
|
-
`)}`)}var c={prose:5.5,md:5.5,ts:6.3,tsx:6.3,py:6.3,default:4};function l(e,t){if(e<=0)return 0;let n=c[t?t.split(`.`).pop()?.toLowerCase()??``:``]??c.default??4;return Math.ceil(e/n)}function u(e,t){if(e.length===0||t.fileSizes===void 0)return new Map;try{return t.fileSizes(e)}catch{return new Map}}var d={low:600,medium:1e3,high:2e3},f=e;function p(e){let t=e.properties??{};return Object.keys(t).length||Object.keys(e).length}function m(e,t){if(e.type===`tool-call`)return 0;let n=e.shape;if(n?.kind==null)return 0;let r=n.kind;return r===`function`||r===`interface`||r===`type`||r===`class`||r===`enum`||r===`const`||r===`script`?(`ops`in n&&Array.isArray(n.ops)?n.ops:[]).length*200:r===`config`||r===`env`||r===`schema`||r===`manifest`?(`ops`in n&&Array.isArray(n.ops)?n.ops:[]).length*100:r===`doc`?d[t??`medium`]??1e3:r===`structured-output`?p(`schema`in n&&n.schema?n.schema:{})*50:0}function h(e,t){let n=new Set([...Object.keys(e),...Object.keys(t)]),r={};for(let i of n)r[i]=e[i]??t[i]??null;return r}function g(e,t){let n=new Set([...Object.keys(e),...Object.keys(t)]),r={};for(let i of n){let n=e[i]??t[i];if(n===void 0)throw TypeError(`Model tier "${i}" not found in dag or deps context_window_per_tier`);r[i]=n}return r}function _(e){let t=Object.keys(e),n=new Map,r=new Map;for(let e of t)n.has(e)||n.set(e,0),r.has(e)||r.set(e,[]);for(let i of t){let t=e[i]?.depends_on??[];for(let e of t){let t=r.get(e);t!==void 0&&t.push(i),n.set(i,(n.get(i)??0)+1)}}let i=new Map,a=[],o=t.filter(e=>(n.get(e)??0)===0).sort();for(let e of o)i.set(e,0);for(;o.length>0;){let e=[];for(let t of o){a.push(t);let o=(r.get(t)??[]).slice().sort();for(let r of o){let a=(n.get(r)??0)-1;n.set(r,a);let o=i.get(t)??0,s=i.get(r)??0;i.set(r,Math.max(s,o+1)),a===0&&e.push(r)}}o=e.sort()}if(a.length!==t.length){let e=new Set(a),n=t.filter(t=>!e.has(t));throw Error(`snapshot(): cycle detected in milestone depends_on graph. Nodes involved: [${n.join(`, `)}]`)}return{order:a,waves:i}}function v(e,t){if(t.length===0)return[];let n=new Set(t);return e.filter(e=>e.operations.some(e=>n.has(e)))}function y(e,t){return e.filter(e=>e.operations.includes(t))}function b(e,t,n,r,i){let a=`${e}.guard`,o=[...n,a],s=v(r,o);for(let e of s)for(let t of e.results)if(t.op_id===a&&t.guard_result===`pass`)return`complete`;for(let e of s)for(let t of e.results)if(o.includes(t.op_id)&&t.status===`failed`)return`failed`;for(let e of s)for(let t of e.results)if(o.includes(t.op_id)&&t.status===`in_progress`)return`in_progress`;let c=i.length===0||i.every(e=>e===`complete`);return t.pending!==null&&c?`pending-surfaced`:`pending`}function x(e,t){let n=`${e}.guard`,r=null,i=null,a=null;for(let e of t)if(e.operations.includes(n))for(let t of e.results)t.op_id===n&&t.guard_result!==null&&(r=t.guard_result,i=t.guard_output,t.guard_result===`pass`&&(a=t.guard_ran_at));return r===null?{guard_result:`pending`,guard_output:null,completed_at:null}:{guard_result:r,guard_output:i,completed_at:a}}function S(e){let t=new Set;for(let n of e)n.action===`move`&&n.to_file?t.add(n.to_file):f.has(n.action)&&n.file&&t.add(n.file);return Array.from(t)}function C(e,t,n){let r=y(n,e.id),i=r.map(e=>e.id),a=null,o=null,s=null;for(let t of r)for(let n of t.results)n.op_id===e.id&&n.guard_result!==null&&(a=n.guard_result,o=n.guard_output,s=n.guard_ran_at);let c=e.ki_estimate!==null&&e.ki_estimate!==void 0?e.ki_estimate:m(e,t),l=w(e.shape);return{...e,ki_estimate:c,shape:l,dispatch_ids:i,attempt_count:0,guard_result:a,guard_output:o,guard_ran_at:s,blast_radius:[],conflict:{detected:!1,competing_op:null,op_key:null,resolution:null},tokens_actual:null}}function w(e){if(!e)return null;if(e.kind===null)return e;let 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`){let t=(`ops`in e&&Array.isArray(e.ops)?e.ops:[]).map(e=>({...e,from:null,breaking:null,severity:null}));return{...e,ops:t}}return e}function T(e,t,n,r){let i=`${e}.guard`,a=y(r,i),o=a.map(e=>e.id),s=null,c=null,l=null;for(let e of a)for(let t of e.results)t.op_id===i&&t.guard_result!==null&&(s=t.guard_result,c=t.guard_output,l=t.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:o,attempt_count:0,guard_result:s,guard_output:c,guard_ran_at:l,blast_radius:[],conflict:{detected:!1,competing_op:null,op_key:null,resolution:null},tokens_actual:null}}function E(e,t){let n={},{write_multiplier:r,read_multiplier:i,hit_probability:a}=t;for(let[t,o]of Object.entries(e))n[t]=o===null?null:Math.round(o*((1-a)*r+a*i));return n}function D(e,t,n){let r=Array.from(e.keys()),i={};for(let a=0;a<r.length;a++)for(let o=a+1;o<r.length;o++){let s=r[a],c=r[o];if(s===void 0||c===void 0)continue;let[l,u]=s<c?[s,c]:[c,s],d=`${l}:${u}`,f=e.get(s)??[],p=e.get(c)??[],m=new Set(f.map(e=>e.file).filter(e=>e!==null)),h=new Set(p.map(e=>e.file).filter(e=>e!==null)),g=Array.from(m).filter(e=>h.has(e));if(g.length===0)continue;let _=t.get(s)??`pending`,v=t.get(c)??`pending`,y=_===`complete`&&v===`complete`,b=0;for(let e of g)b+=y?n(e):0;i[d]=b}return i}function O(e){return(Array.isArray(e)?e:Object.values(e)).map(e=>e.type===void 0?{...e,type:`generative`}:e)}function k(e,t){let n=new Date().toISOString(),r=t.dispatchLog??e.dispatch_log,i=e.optimization.sentinel_fanout,a=h(e.optimization.b_per_tier,t.bPerTier),o=g(e.optimization.context_window_per_tier,t.contextWindowPerTier),c=E(a,i),{waves:d}=_(e.milestones),f=O(e.operations),p=new Map;for(let e of f){let t=p.get(e.milestone)??[];t.push(e),p.set(e.milestone,t)}let m=new Set;for(let e of f)e.file&&m.add(e.file),e.action===`move`&&e.to_file&&m.add(e.to_file);let y=u(Array.from(m),t),w=e=>y.get(e)??0,k=new Map,j=Array.from(d.entries()).sort((e,t)=>e[1]-t[1]||e[0].localeCompare(t[0])).map(([e])=>e);for(let t of j){let n=e.milestones[t];if(n===void 0)continue;let i=b(t,n,(p.get(t)??[]).map(e=>e.id),r,n.depends_on.map(e=>k.get(e)??`pending`));k.set(t,i)}let M={},N=[];for(let t of j){let n=e.milestones[t];if(n===void 0)continue;let i=d.get(t)??0,a=p.get(t)??[],o=a.map(e=>e.id),s=k.get(t)??`pending`,u=n.depends_on.map(e=>k.get(e)??`pending`),f=n.depends_on.length===0||u.every(e=>e===`complete`),m=u.every(e=>e!==`failed`),h=n.pending===null&&f&&m&&s!==`complete`,g=v(r,[...o,`${t}.guard`]),_=g.length>0?g.map(e=>e.started_at).sort()[0]??null:null,y,b,E;if(n.guard){let e=x(t,r);y=e.guard_result,b=e.guard_output,E=e.completed_at}else y=null,b=null,E=null;let D=S(a),O=D.reduce((e,t)=>e+w(t),0),A=a.map(e=>C(e,n.effort,r)),j=null,P=0,F=!1;for(let e of A){if(e.ki_estimate===null){F=!0;break}P+=e.ki_estimate}F||(j=P);let I=null,L=n.model;if(L!==null&&j!==null){let e=c[L]??null;e!==null&&(I=e+l(O)+j)}let R=null,z=g.filter(e=>e.completed_at!==null&&e.results.length>0&&e.results.every(e=>e.status===`complete`||e.status===`skipped`));z.length>0&&(R=z.reduce((e,t)=>e+t.turns.reduce((e,t)=>e+t.input_tokens+t.output_tokens,0),0));let B=T(t,n,o,r);N.push(...A,B),M[t]={description:n.description,...n.rationale===void 0?{}:{rationale:n.rationale},authored_by:n.authored_by,pending:n.pending,triggered_by:n.triggered_by,phase:n.phase,depends_on:n.depends_on,agent:n.agent,model:n.model,effort:n.effort,two_stage:n.two_stage,read_only:n.read_only,guard:n.guard,context:`contexts/${t}.md`,wave:i,eligible:h,status:s,started_at:_,completed_at:E,guard_result:y,guard_output:b,artifacts:D,si_bytes:O,ki_estimate:j,tokens_estimated:I,tokens_actual:R}}let P=D(p,k,w),F=A(e,M),I={tokens_naive:(()=>{let e=0;for(let n of Object.values(M))if(n.eligible&&n.status===`pending`&&n.model!==null){let r=a[n.model]??t.bPerTier[n.model]??0;e+=r+(n.ki_estimate??0)}return e})(),sentinel_fanout:i,context_window_override:e.optimization.context_window_override,b_override:e.optimization.b_override,b_per_tier:a,b_eff_per_tier:c,context_window_per_tier:o},L={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:I,milestones:M,operations:N,pairwise_overlap:P,open_questions:F};return s(L),L}function A(e,t){let n=[];for(let[r,i]of Object.entries(t)){let t=e.milestones[r];if(t?.pending==null)continue;let a=i.status===`pending-surfaced`;n.push({id:`q:${r}`,text:t.pending,blocking:r,surfaced:a,raised_at_dispatch:null,raised_at_turn:null,answered:!1,answer:null})}return n}var j=`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 M(e){return Object.keys(e.milestones).filter(t=>{let n=e.milestones[t];return n?.eligible===!0&&n.status===`pending`})}function N(e){if(e.length===0||e.every(e=>e.type===`tool-call`))return`tool-call`;for(let t of e){if(t.type!==`generative`||t.shape?.kind==null)continue;let e=t.shape.kind;if(e===`function`||e===`interface`||e===`type`||e===`class`||e===`enum`||e===`const`||e===`script`||e===`config`||e===`env`||e===`schema`||e===`manifest`)return`code-config`;if(e===`doc`)return`doc`;if(e===`structured-output`)return`structured`}return`code-config`}function P(e){if(!e)return``;let t=e.indexOf(`:`);return t>=0?e.slice(t+1):e}function F(e,t,n){let r=!0,i=[];for(let a of e){let e=t[a];if(e===void 0)continue;let o=n.filter(e=>e.milestone===a&&e.action!==`guard`);o.some(e=>e.type===`generative`)&&(r=!1),i.push(`## Milestone: ${a}`),i.push(e.description),e.rationale&&i.push(`\n*Rationale:* ${e.rationale}`),i.push(`
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=new Set([`create`,`modify-signature`,`modify-body`,`add-export`,`remove-export`,`rename`]),t=new Set([`pending`,`pending-surfaced`,`in_progress`,`complete`,`failed`,`skipped`,`awaiting_input`]),n=new Set([`pending`,`in_progress`,`complete`,`failed`,`skipped`]);function r(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function i(e){return typeof e==`string`}function a(e,t,n){return{path:e,message:t,value:n}}function o(e){let o=[];if(!r(e))return{valid:!1,errors:[a(``,`root must be an object`)]};for(let t of[`snapshot_at`,`description`])i(e[t])||o.push(a(t,`required string field missing`,e[t]));i(e.plan)||o.push(a(`plan`,`required string`,e.plan));let s=e.milestones;if(!r(s))o.push(a(`milestones`,`must be an object`,s));else{let c=Object.keys(s),l=new Set(c);for(let e of c){let n=s[e];if(!r(n)){o.push(a(`milestones.${e}`,`must be an object`,n));continue}let c=n.eligible,l=n.pending;c===!0&&l!=null&&o.push(a(`milestones.${e}`,`D-07 violation: eligible=true but pending not null`)),typeof c!=`boolean`&&o.push(a(`milestones.${e}.eligible`,`must be boolean`,c));let u=n.status;(!i(u)||!t.has(u))&&o.push(a(`milestones.${e}.status`,`invalid status`,u)),c===!0&&u===`complete`&&o.push(a(`milestones.${e}`,`D-07 violation: eligible=true but status is complete`));let d=n.wave;(typeof d!=`number`||!Number.isInteger(d)||d<0)&&o.push(a(`milestones.${e}.wave`,`must be non-negative integer`,d));let f=n.ki_estimate;f!=null&&typeof f!=`number`&&o.push(a(`milestones.${e}.ki_estimate`,`must be number|null`,f));for(let t of[`tokens_estimated`,`tokens_actual`]){let r=n[t];r!=null&&typeof r!=`number`&&o.push(a(`milestones.${e}.${t}`,`must be number|null`,r))}Array.isArray(n.artifacts)||o.push(a(`milestones.${e}.artifacts`,`must be an array`,n.artifacts)),typeof n.si_bytes!=`number`&&o.push(a(`milestones.${e}.si_bytes`,`must be a number`,n.si_bytes))}let u=e.operations;if(!Array.isArray(u))o.push(a(`operations`,`must be an array`,u));else for(let e of u){if(!r(e))continue;let t=i(e.id)?e.id:`?`,s=e.milestone;i(s)&&!l.has(s)&&o.push(a(`operations[${t}].milestone`,`unknown milestone "${s}"`));let c=e.status;(!i(c)||!n.has(c))&&o.push(a(`operations[${t}].status`,`invalid operation status`,c)),Array.isArray(e.dispatch_ids)||o.push(a(`operations[${t}].dispatch_ids`,`must be an array`,e.dispatch_ids)),typeof e.attempt_count!=`number`&&o.push(a(`operations[${t}].attempt_count`,`must be a number`,e.attempt_count)),Array.isArray(e.blast_radius)||o.push(a(`operations[${t}].blast_radius`,`must be an array`,e.blast_radius))}let d=e.open_questions;if(!Array.isArray(d))o.push(a(`open_questions`,`must be an array`,d));else for(let e of d){if(!r(e))continue;let t=e.blocking;(!i(t)||!l.has(t))&&o.push(a(`open_questions`,`unknown blocking milestone "${t}"`)),typeof e.surfaced!=`boolean`&&o.push(a(`open_questions[${e.id}]`,`surfaced must be boolean`,e.surfaced)),typeof e.answered!=`boolean`&&o.push(a(`open_questions[${e.id}]`,`answered must be boolean`,e.answered))}let f=e.dispatch_units;if(f!==void 0){if(!Array.isArray(f))o.push(a(`dispatch_units`,`must be an array if present`,f));else for(let e of f){if(!r(e))continue;let t=e.fits_context_window;typeof t!=`boolean`&&o.push(a(`dispatch_units[${e.id}]`,`fits_context_window must be boolean`,t));let n=e.milestones;if(Array.isArray(n))for(let t of n)i(t)&&!l.has(t)&&o.push(a(`dispatch_units[${e.id}].milestones`,`unknown milestone "${t}"`))}}r(e.pairwise_overlap)||o.push(a(`pairwise_overlap`,`must be an object`,e.pairwise_overlap))}return{valid:o.length===0,errors:o}}function s(e){let t=o(e);if(!t.valid)throw Error(`Snapshot validation failed:\n${t.errors.map(e=>` ${e.path}: ${e.message}`).join(`
|
|
2
|
+
`)}`)}var c={prose:5.5,md:5.5,ts:6.3,tsx:6.3,py:6.3,default:4};function l(e,t){if(e<=0)return 0;let n=c[t?t.split(`.`).pop()?.toLowerCase()??``:``]??c.default??4;return Math.ceil(e/n)}function u(e,t){if(e.length===0||t.fileSizes===void 0)return new Map;try{return t.fileSizes(e)}catch{return new Map}}var d={low:600,medium:1e3,high:2e3},f=e;function p(e){let t=e.properties??{};return Object.keys(t).length||Object.keys(e).length}function m(e,t){if(e.type===`tool-call`)return 0;let n=e.shape;if(n?.kind==null)return 0;let r=n.kind;return r===`function`||r===`interface`||r===`type`||r===`class`||r===`enum`||r===`const`||r===`script`?(`ops`in n&&Array.isArray(n.ops)?n.ops:[]).length*200:r===`config`||r===`env`||r===`schema`||r===`manifest`?(`ops`in n&&Array.isArray(n.ops)?n.ops:[]).length*100:r===`doc`?d[t??`medium`]??1e3:r===`structured-output`?p(`schema`in n&&n.schema?n.schema:{})*50:0}function h(e,t){let n=new Set([...Object.keys(e),...Object.keys(t)]),r={};for(let i of n)r[i]=e[i]??t[i]??null;return r}function g(e,t){let n=new Set([...Object.keys(e),...Object.keys(t)]),r={};for(let i of n){let n=e[i]??t[i];if(n===void 0)throw TypeError(`Model tier "${i}" not found in dag or deps context_window_per_tier`);r[i]=n}return r}function _(e){let t=Object.keys(e),n=new Map,r=new Map;for(let e of t)n.has(e)||n.set(e,0),r.has(e)||r.set(e,[]);for(let i of t){let t=e[i]?.depends_on??[];for(let e of t){let t=r.get(e);t!==void 0&&t.push(i),n.set(i,(n.get(i)??0)+1)}}let i=new Map,a=[],o=t.filter(e=>(n.get(e)??0)===0).sort();for(let e of o)i.set(e,0);for(;o.length>0;){let e=[];for(let t of o){a.push(t);let o=(r.get(t)??[]).slice().sort();for(let r of o){let a=(n.get(r)??0)-1;n.set(r,a);let o=i.get(t)??0,s=i.get(r)??0;i.set(r,Math.max(s,o+1)),a===0&&e.push(r)}}o=e.sort()}if(a.length!==t.length){let e=new Set(a),n=t.filter(t=>!e.has(t));throw Error(`snapshot(): cycle detected in milestone depends_on graph. Nodes involved: [${n.join(`, `)}]`)}return{order:a,waves:i}}function v(e,t){if(t.length===0)return[];let n=new Set(t);return e.filter(e=>e.operations.some(e=>n.has(e)))}function y(e,t){return e.filter(e=>e.operations.includes(t))}function b(e,t,n,r,i){let a=`${e}.guard`,o=[...n,a],s=v(r,o);for(let e of s)for(let t of e.results)if(t.op_id===a&&t.guard_result===`pass`)return`complete`;for(let e of s)if(e.suspension)return`awaiting_input`;for(let e of s)for(let t of e.results)if(o.includes(t.op_id)&&t.status===`failed`)return`failed`;for(let e of s)for(let t of e.results)if(o.includes(t.op_id)&&t.status===`in_progress`)return`in_progress`;let c=i.length===0||i.every(e=>e===`complete`);return t.pending!==null&&c?`pending-surfaced`:`pending`}function x(e,t){let n=`${e}.guard`,r=null,i=null,a=null;for(let e of t)if(e.operations.includes(n))for(let t of e.results)t.op_id===n&&t.guard_result!==null&&(r=t.guard_result,i=t.guard_output,t.guard_result===`pass`&&(a=t.guard_ran_at));return r===null?{guard_result:`pending`,guard_output:null,completed_at:null}:{guard_result:r,guard_output:i,completed_at:a}}function S(e){let t=new Set;for(let n of e)n.action===`move`&&n.to_file?t.add(n.to_file):f.has(n.action)&&n.file&&t.add(n.file);return Array.from(t)}function C(e,t,n){let r=y(n,e.id),i=r.map(e=>e.id),a=null,o=null,s=null;for(let t of r)for(let n of t.results)n.op_id===e.id&&n.guard_result!==null&&(a=n.guard_result,o=n.guard_output,s=n.guard_ran_at);let c=e.ki_estimate!==null&&e.ki_estimate!==void 0?e.ki_estimate:m(e,t),l=w(e.shape);return{...e,ki_estimate:c,shape:l,dispatch_ids:i,attempt_count:0,guard_result:a,guard_output:o,guard_ran_at:s,blast_radius:[],conflict:{detected:!1,competing_op:null,op_key:null,resolution:null},tokens_actual:null}}function w(e){if(!e)return null;if(e.kind===null)return e;let 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`){let t=(`ops`in e&&Array.isArray(e.ops)?e.ops:[]).map(e=>({...e,from:null,breaking:null,severity:null}));return{...e,ops:t}}return e}function T(e,t,n,r){let i=`${e}.guard`,a=y(r,i),o=a.map(e=>e.id),s=null,c=null,l=null;for(let e of a)for(let t of e.results)t.op_id===i&&t.guard_result!==null&&(s=t.guard_result,c=t.guard_output,l=t.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:o,attempt_count:0,guard_result:s,guard_output:c,guard_ran_at:l,blast_radius:[],conflict:{detected:!1,competing_op:null,op_key:null,resolution:null},tokens_actual:null}}function E(e,t){let n={},{write_multiplier:r,read_multiplier:i,hit_probability:a}=t;for(let[t,o]of Object.entries(e))n[t]=o===null?null:Math.round(o*((1-a)*r+a*i));return n}function D(e,t,n){let r=Array.from(e.keys()),i={};for(let a=0;a<r.length;a++)for(let o=a+1;o<r.length;o++){let s=r[a],c=r[o];if(s===void 0||c===void 0)continue;let[l,u]=s<c?[s,c]:[c,s],d=`${l}:${u}`,f=e.get(s)??[],p=e.get(c)??[],m=new Set(f.map(e=>e.file).filter(e=>e!==null)),h=new Set(p.map(e=>e.file).filter(e=>e!==null)),g=Array.from(m).filter(e=>h.has(e));if(g.length===0)continue;let _=t.get(s)??`pending`,v=t.get(c)??`pending`,y=_===`complete`&&v===`complete`,b=0;for(let e of g)b+=y?n(e):0;i[d]=b}return i}function O(e){return(Array.isArray(e)?e:Object.values(e)).map(e=>e.type===void 0?{...e,type:`generative`}:e)}function k(e,t){let n=new Date().toISOString(),r=t.dispatchLog??e.dispatch_log,i=e.optimization.sentinel_fanout,a=h(e.optimization.b_per_tier,t.bPerTier),o=g(e.optimization.context_window_per_tier,t.contextWindowPerTier),c=E(a,i),{waves:d}=_(e.milestones),f=O(e.operations),p=new Map;for(let e of f){let t=p.get(e.milestone)??[];t.push(e),p.set(e.milestone,t)}let m=new Set;for(let e of f)e.file&&m.add(e.file),e.action===`move`&&e.to_file&&m.add(e.to_file);let y=u(Array.from(m),t),w=e=>y.get(e)??0,k=new Map,j=Array.from(d.entries()).sort((e,t)=>e[1]-t[1]||e[0].localeCompare(t[0])).map(([e])=>e);for(let t of j){let n=e.milestones[t];if(n===void 0)continue;let i=b(t,n,(p.get(t)??[]).map(e=>e.id),r,n.depends_on.map(e=>k.get(e)??`pending`));k.set(t,i)}let M={},N=[];for(let t of j){let n=e.milestones[t];if(n===void 0)continue;let i=d.get(t)??0,a=p.get(t)??[],o=a.map(e=>e.id),s=k.get(t)??`pending`,u=n.depends_on.map(e=>k.get(e)??`pending`),f=n.depends_on.length===0||u.every(e=>e===`complete`),m=u.every(e=>e!==`failed`),h=n.pending===null&&f&&m&&s!==`complete`,g=v(r,[...o,`${t}.guard`]),_=g.length>0?g.map(e=>e.started_at).sort()[0]??null:null,y,b,E;if(n.guard){let e=x(t,r);y=e.guard_result,b=e.guard_output,E=e.completed_at}else y=null,b=null,E=null;let D=S(a),O=D.reduce((e,t)=>e+w(t),0),A=a.map(e=>C(e,n.effort,r)),j=null,P=0,F=!1;for(let e of A){if(e.ki_estimate===null){F=!0;break}P+=e.ki_estimate}F||(j=P);let I=null,L=n.model;if(L!==null&&j!==null){let e=c[L]??null;e!==null&&(I=e+l(O)+j)}let R=null,z=g.filter(e=>e.completed_at!==null&&e.results.length>0&&e.results.every(e=>e.status===`complete`||e.status===`skipped`));z.length>0&&(R=z.reduce((e,t)=>e+t.turns.reduce((e,t)=>e+t.input_tokens+t.output_tokens,0),0));let B=T(t,n,o,r);N.push(...A,B),M[t]={description:n.description,...n.rationale===void 0?{}:{rationale:n.rationale},authored_by:n.authored_by,pending:n.pending,triggered_by:n.triggered_by,phase:n.phase,depends_on:n.depends_on,agent:n.agent,model:n.model,effort:n.effort,two_stage:n.two_stage,read_only:n.read_only,guard:n.guard,context:`contexts/${t}.md`,wave:i,eligible:h,status:s,started_at:_,completed_at:E,guard_result:y,guard_output:b,artifacts:D,si_bytes:O,ki_estimate:j,tokens_estimated:I,tokens_actual:R}}let P=D(p,k,w),F=A(e,M),I={tokens_naive:(()=>{let e=0;for(let n of Object.values(M))if(n.eligible&&n.status===`pending`&&n.model!==null){let r=a[n.model]??t.bPerTier[n.model]??0;e+=r+(n.ki_estimate??0)}return e})(),sentinel_fanout:i,context_window_override:e.optimization.context_window_override,b_override:e.optimization.b_override,b_per_tier:a,b_eff_per_tier:c,context_window_per_tier:o},L={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:I,milestones:M,operations:N,pairwise_overlap:P,open_questions:F};return s(L),L}function A(e,t){let n=[];for(let[r,i]of Object.entries(t)){let t=e.milestones[r];if(t?.pending==null)continue;let a=i.status===`pending-surfaced`;n.push({id:`q:${r}`,text:t.pending,blocking:r,surfaced:a,raised_at_dispatch:null,raised_at_turn:null,answered:!1,answer:null})}return n}var j=`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 M(e){return Object.keys(e.milestones).filter(t=>{let n=e.milestones[t];return n?.eligible===!0&&n.status===`pending`})}function N(e){if(e.length===0||e.every(e=>e.type===`tool-call`))return`tool-call`;for(let t of e){if(t.type!==`generative`||t.shape?.kind==null)continue;let e=t.shape.kind;if(e===`function`||e===`interface`||e===`type`||e===`class`||e===`enum`||e===`const`||e===`script`||e===`config`||e===`env`||e===`schema`||e===`manifest`)return`code-config`;if(e===`doc`)return`doc`;if(e===`structured-output`)return`structured`}return`code-config`}function P(e){if(!e)return``;let t=e.indexOf(`:`);return t>=0?e.slice(t+1):e}function F(e,t,n){let r=!0,i=[];for(let a of e){let e=t[a];if(e===void 0)continue;let o=n.filter(e=>e.milestone===a&&e.action!==`guard`);o.some(e=>e.type===`generative`)&&(r=!1),i.push(`## Milestone: ${a}`),i.push(e.description),e.rationale&&i.push(`\n*Rationale:* ${e.rationale}`),i.push(`
|
|
3
3
|
### Operations:`);for(let e of o){let t=e.file?` ${e.file}`:``,n=e.symbol?` (${e.symbol})`:``;if(i.push(`- [${e.id}] ${e.action}${t}${n}`),e.shape&&e.shape.kind!==null){let t=e.shape;if(t.kind===`doc`)i.push(` Description: ${t.description}`),i.push(` Objective: ${t.objective}`),t.required_sections&&t.required_sections.length>0&&i.push(` Required sections: ${t.required_sections.join(`, `)}`);else if(t.kind===`structured-output`)i.push(` Schema:
|
|
4
4
|
`+JSON.stringify(t.schema,null,2).split(`
|
|
5
5
|
`).map(e=>` ${e}`).join(`
|
package/index.mjs
CHANGED
|
@@ -12,7 +12,8 @@ var e = /* @__PURE__ */ new Set([
|
|
|
12
12
|
"in_progress",
|
|
13
13
|
"complete",
|
|
14
14
|
"failed",
|
|
15
|
-
"skipped"
|
|
15
|
+
"skipped",
|
|
16
|
+
"awaiting_input"
|
|
16
17
|
]), n = /* @__PURE__ */ new Set([
|
|
17
18
|
"pending",
|
|
18
19
|
"in_progress",
|
|
@@ -204,6 +205,7 @@ function y(e, t) {
|
|
|
204
205
|
function b(e, t, n, r, i) {
|
|
205
206
|
let a = `${e}.guard`, o = [...n, a], s = v(r, o);
|
|
206
207
|
for (let e of s) for (let t of e.results) if (t.op_id === a && t.guard_result === "pass") return "complete";
|
|
208
|
+
for (let e of s) if (e.suspension) return "awaiting_input";
|
|
207
209
|
for (let e of s) for (let t of e.results) if (o.includes(t.op_id) && t.status === "failed") return "failed";
|
|
208
210
|
for (let e of s) for (let t of e.results) if (o.includes(t.op_id) && t.status === "in_progress") return "in_progress";
|
|
209
211
|
let c = i.length === 0 || i.every((e) => e === "complete");
|
package/package.json
CHANGED