← Files DXIRARCHIVED FILE
scripts/action-room.mjs
3.97 KB · Nov 9, 2026 · 01:16 UTC
import b from"node:path";import{pathToFileURL as I}from"node:url";import{acknowledge as D,bind as R,checkpoint as w,goalCheckpoint as k,researchCheckpoint as m,executionCheckpoint as y,decisionMaterials as x,hookIdentity as E,identity as _,pending as U,prepareLayout as A,recordHook as M,recordProgress as C,taskArtifact as g,taskDirectory as j,unbind as S,uploadArtifact as T}from"./journal.mjs";function r(e){process.stdout.write(`${JSON.stringify(e)}
`)}async function p({line:e=!1,maxBytes:s=1024*1024}={}){if(e)return new Promise((i,n)=>{let o=Buffer.alloc(0);const c=(d,v)=>{process.stdin.off("data",f),process.stdin.off("end",l),process.stdin.off("error",h),process.stdin.pause(),d?n(d):i(v)},u=()=>{try{c(null,JSON.parse(o.toString("utf8").trim()))}catch{c(new Error("Invalid upload input."))}},f=d=>{if(o=Buffer.concat([o,d]),o.length>s||o.includes(3)){c(new Error("Upload input aborted."));return}(o.includes(10)||o.includes(13))&&u()},l=()=>u(),h=()=>c(new Error("Upload input unavailable."));process.stdin.on("data",f),process.stdin.once("end",l),process.stdin.once("error",h),process.stdin.resume()});const t=[];let a=0;for await(const i of process.stdin){if(a+=i.length,a>s)throw new Error("Input exceeds the helper limit.");t.push(i)}return JSON.parse(Buffer.concat(t).toString("utf8").trim())}async function B(){try{const e=await p(),s=process.env.PLUGIN_DATA,t=E(e,s);if(t){r(t);return}if(!s){r({});return}const a=await M(s,e);r(a.incomplete?{systemMessage:"DXIR activity journal reached its limit. Work may continue, but the next active synchronization must report incomplete activity."}:{})}catch{r({systemMessage:"DXIR could not save this activity. Work may continue; Action Room activity may be incomplete."})}}function N(e){const s={};for(let t=0;t<e.length;t+=2){if(!e[t].startsWith("--")||e[t+1]===void 0)throw new Error("Use named options with values.");s[e[t].slice(2)]=e[t+1]}return s}async function J(){const[e,...s]=process.argv.slice(2);if(e==="hook"){await B();return}const t=N(s),a=process.cwd();if(e==="identity"){r({requires_host_hook_identity:!0,message:"Use the DXIR host identity attached by this invocation's trusted hook. If absent, review the plugin in /hooks and retry. Do not guess a session ID."});return}const i=_(a,t.session);if(t["project-key"]!==i.project_key)throw new Error("Current project differs from the host-provided project identity.");const n=t["data-dir"];if(e==="artifact"){r(await g(n,i,t.task,t.file,a));return}if(e==="upload"){await g(n,i,t.task,t.file,a);const c=!!(process.stdin.isTTY&&process.stdin.setRawMode);c&&process.stdin.setRawMode(!0),r({ready_for_upload_url:!0});try{const u=await p({line:!0,maxBytes:16384});r(await T({file:t.file,cwd:a,sha256:t.sha256,contentType:t["content-type"],uploadUrl:u.upload_url}))}finally{c&&process.stdin.setRawMode(!1)}return}if(e==="task-dir"){r(await j(n,i,t.task,a));return}if(e==="pending"){r(await U(n,i));return}if(e==="unbind"){r(await S(n,i));return}if(e==="checkpoint"&&t.read==="true"){r(await w(n,i,void 0,a,t.work));return}if(e==="goal-checkpoint"&&t.read==="true"){r(await k(n,i));return}if(e==="research-checkpoint"&&t.read==="true"){r(await m(n,i,t.task));return}if(e==="execution-checkpoint"&&t.read==="true"){r(await y(n,i,t.task));return}const o=await p();if(e==="decision-materials"){r(await x(n,i,t.task,o,a));return}if(e==="bind"){r(await R(n,i,o));return}if(e==="layout"){r(await A(n,i,o,a));return}if(e==="ack"){r(await D(n,i,o));return}if(e==="checkpoint"){r(await w(n,i,o,a,t.work));return}if(e==="goal-checkpoint"){r(await k(n,i,o));return}if(e==="research-checkpoint"){r(await m(n,i,t.task,o));return}if(e==="execution-checkpoint"){r(await y(n,i,t.task,o));return}if(e==="event"){r(await C(n,i,o));return}throw new Error("Unknown Action Room helper command.")}process.argv[1]&&import.meta.url===I(b.resolve(process.argv[1])).href&&J().catch(()=>{r({ok:!1,error:"Action Room helper failed. Check the selected binding, host identity, input fields, and file limits; nothing was acknowledged."}),process.exitCode=1});export{B as runHook};
SHA-256: 5249856f599c5266c042887b80ebf1fe9c54c6011f8809d1b0d0b707a953ba70