@kodax-ai/kodax 0.7.97-beta.2 → 0.7.97-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +96 -0
- package/README.md +55 -2
- package/README_CN.md +37 -1
- package/dist/artifacts/dist/contract.js +1 -1
- package/dist/artifacts/dist/contract.js.map +1 -1
- package/dist/artifacts/dist/document-render.d.ts +1 -1
- package/dist/artifacts/dist/document-render.js +41 -10
- package/dist/artifacts/dist/document-render.js.map +1 -1
- package/dist/artifacts/dist/kodax.js +1 -1
- package/dist/artifacts/dist/kodax.js.map +1 -1
- package/dist/artifacts/dist/libreoffice.d.ts +6 -1
- package/dist/artifacts/dist/libreoffice.js +37 -13
- package/dist/artifacts/dist/libreoffice.js.map +1 -1
- package/dist/artifacts/dist/runtime.js +13 -6
- package/dist/artifacts/dist/runtime.js.map +1 -1
- package/dist/artifacts/skills/artifact-review/SKILL.md +5 -1
- package/dist/chunks/agent-NWQPMZ7B.js +2 -0
- package/dist/chunks/agent-adapter-V3IPADCX.js +2 -0
- package/dist/chunks/argument-completer-VNKHT4X4.js +2 -0
- package/dist/chunks/{bedrock-native-Z5VNWF5U.js → bedrock-native-OEPOBW6W.js} +1 -1
- package/dist/chunks/{chunk-NSR4RW2F.js → chunk-3I2MIS4D.js} +1 -1
- package/dist/chunks/{chunk-RYBUYHDL.js → chunk-3Y5PBEOD.js} +1 -1
- package/dist/chunks/chunk-4FVCMKG2.js +20 -0
- package/dist/chunks/{chunk-F6GJXQNA.js → chunk-4GYXZTOD.js} +7 -7
- package/dist/chunks/{chunk-EISRVOBJ.js → chunk-4Z7ZHL6V.js} +2 -2
- package/dist/chunks/{chunk-W2CWO4PQ.js → chunk-576AAIQM.js} +1 -1
- package/dist/chunks/chunk-5E2P4RYS.js +4 -0
- package/dist/chunks/{chunk-X5M7TLJV.js → chunk-5LFQ5FVY.js} +1 -1
- package/dist/chunks/{chunk-WMMESRP3.js → chunk-6RDMSU4B.js} +1 -1
- package/dist/chunks/{chunk-3CP7AUWY.js → chunk-7BA4TSKC.js} +1 -1
- package/dist/chunks/{chunk-I325ER7D.js → chunk-AUU3N4V4.js} +1 -1
- package/dist/chunks/{chunk-DCE7XQUG.js → chunk-AYDLX2UK.js} +1 -1
- package/dist/chunks/{chunk-D36OIMV7.js → chunk-BP3NAYKY.js} +64 -64
- package/dist/chunks/{chunk-6TITQQAI.js → chunk-BSCSKJNC.js} +230 -229
- package/dist/chunks/{chunk-2HH5AS7E.js → chunk-DAQGOWKD.js} +88 -462
- package/dist/chunks/{chunk-UF3GZ5PO.js → chunk-EZF6ZRCO.js} +1 -1
- package/dist/chunks/chunk-F2TFWNVZ.js +2 -0
- package/dist/chunks/{chunk-53CJDQS2.js → chunk-FVXZ5L33.js} +1 -1
- package/dist/chunks/{chunk-MCDZNQWD.js → chunk-G32BMSHH.js} +75 -71
- package/dist/chunks/chunk-HJLYZ5AX.js +361 -0
- package/dist/chunks/{chunk-P55RJIOG.js → chunk-IOIFCU46.js} +1 -1
- package/dist/chunks/{chunk-DV5YPYLW.js → chunk-IR46ZHXU.js} +1 -1
- package/dist/chunks/chunk-NJDR5EEF.js +6 -0
- package/dist/chunks/{chunk-KDSO7V4O.js → chunk-OC3DQXN6.js} +1 -1
- package/dist/chunks/{chunk-J2L2NK6E.js → chunk-OMVAPRQI.js} +90 -57
- package/dist/chunks/chunk-OXCB2TRF.js +42 -0
- package/dist/chunks/{chunk-C6JGLEYD.js → chunk-P6R6V7EW.js} +1 -1
- package/dist/chunks/{chunk-SK3RRGHJ.js → chunk-PFBZ4ZXO.js} +28 -28
- package/dist/chunks/{chunk-V2XJSFFE.js → chunk-QDE6THC5.js} +1 -1
- package/dist/chunks/{chunk-EPK6EWRI.js → chunk-QRYEP34M.js} +1 -1
- package/dist/chunks/chunk-ROWYE472.js +460 -0
- package/dist/chunks/{chunk-R42S4BLA.js → chunk-SQGESMNC.js} +1 -1
- package/dist/chunks/{chunk-XZSFUGPN.js → chunk-U73VEVMP.js} +1 -1
- package/dist/chunks/{chunk-D425EZGC.js → chunk-V2TG7GNW.js} +1 -1
- package/dist/chunks/{chunk-QSZCR5GC.js → chunk-VRO2CDBY.js} +97 -97
- package/dist/chunks/{chunk-BBZWF2EA.js → chunk-WMQQQY3D.js} +1 -1
- package/dist/chunks/{chunk-JAF2YLZO.js → chunk-X3YYJJTF.js} +2 -2
- package/dist/chunks/{chunk-UL6YIT4M.js → chunk-XYRI6ER5.js} +1 -1
- package/dist/chunks/chunk-YRPB3LID.js +3 -0
- package/dist/chunks/{chunk-5MUVRFMU.js → chunk-ZDAU3LZ2.js} +1 -1
- package/dist/chunks/{chunk-WWPVEK6B.js → chunk-ZP3YSYWM.js} +10 -10
- package/dist/chunks/{client-LTIFNED5.js → client-NJ32JBC3.js} +1 -1
- package/dist/chunks/compaction-config-JBQGU3NO.js +2 -0
- package/dist/chunks/{construction-bootstrap-OAZKGI5Y.js → construction-bootstrap-CM47ZXG7.js} +1 -1
- package/dist/chunks/dist-O6BHIQEP.js +2 -0
- package/dist/chunks/{google-native-WLL27OV7.js → google-native-BV5GKT5B.js} +1 -1
- package/dist/chunks/host-PI5NL4W4.js +2 -0
- package/dist/chunks/{mistral-native-JXPIDDYZ.js → mistral-native-X42JCFZH.js} +1 -1
- package/dist/chunks/{model-DZF6URW3.js → model-MT3WJX76.js} +1 -1
- package/dist/chunks/{permission-YVVMLQ5I.js → permission-YVDVSE6H.js} +1 -1
- package/dist/chunks/{pi-messages-5LLOZH57.js → pi-messages-DVJANXV5.js} +1 -1
- package/dist/chunks/readline-helpers-5JS7UGTE.js +2 -0
- package/dist/chunks/run-manager-Y6VYEWSJ.js +2 -0
- package/dist/chunks/running-session-ANMBA5XV.js +2 -0
- package/dist/chunks/skills-XL2XIBWV.js +2 -0
- package/dist/chunks/{tool-dispatch-MLM3QTSU.js → tool-dispatch-2FOG65FC.js} +1 -1
- package/dist/chunks/{utils-2QNMYRGA.js → utils-XZ22R6VB.js} +1 -1
- package/dist/client-history.js +2 -0
- package/dist/history-turn.js +3 -0
- package/dist/index.d.ts +19 -19
- package/dist/index.js +2 -2
- package/dist/kodax_bootstrap.js +1 -1
- package/dist/kodax_cli.js +1472 -1810
- package/dist/kodax_doctor.js +1 -1
- package/dist/maintenance-scheduler.js +2 -0
- package/dist/manual-topics.json +32 -3
- package/dist/native/win32-x64/kodax-windows-sandbox.exe +0 -0
- package/dist/native/win32-x64/kodax-windows-text-transaction.node +0 -0
- package/dist/native/win32-x64/manifest.json +2 -2
- package/dist/one-shot-task.js +1 -1
- package/dist/provider-auth-cli.js +1 -1
- package/dist/runtime-daemon-schema.json +1 -1
- package/dist/sandbox-network-broker.js +93 -441
- package/dist/sdk-a2a.d.ts +13 -13
- package/dist/sdk-a2a.js +1 -1
- package/dist/sdk-agent.d.ts +17 -12
- package/dist/sdk-agent.js +1 -1
- package/dist/sdk-client.d.ts +6 -6
- package/dist/sdk-client.js +1 -1
- package/dist/sdk-coding.d.ts +17 -17
- package/dist/sdk-coding.js +1 -1
- package/dist/sdk-experimental-memory.d.ts +2 -2
- package/dist/sdk-experimental-memory.js +1 -1
- package/dist/sdk-llm.d.ts +4 -2
- package/dist/sdk-llm.js +1 -1
- package/dist/sdk-mcp.js +1 -1
- package/dist/sdk-media.d.ts +13 -13
- package/dist/sdk-media.js +1 -1
- package/dist/sdk-repl.d.ts +16 -16
- package/dist/sdk-repl.js +1 -1
- package/dist/sdk-runtime.d.ts +46 -46
- package/dist/sdk-runtime.js +1 -1
- package/dist/sdk-sandbox.js +1 -1
- package/dist/sdk-session.d.ts +7 -7
- package/dist/sdk-session.js +1 -1
- package/dist/sdk-skills.js +1 -1
- package/dist/semantic-worker.js +87 -435
- package/dist/storage-repair-cli.js +1 -1
- package/dist/types-chunks/{bash-prefix-extractor.d-CJliu5-D.d.ts → bash-prefix-extractor.d-BghXa_md.d.ts} +9 -3
- package/dist/types-chunks/{capsule.d-EMwSALqK.d.ts → capsule.d-BTlvC5qq.d.ts} +4 -4
- package/dist/types-chunks/{client-contract-B7q69yMA.d.ts → client-contract-B7ZSFKTv.d.ts} +52 -4
- package/dist/types-chunks/{controller.d-C0SAuNKu.d.ts → controller.d-Btu5FDdw.d.ts} +1 -1
- package/dist/types-chunks/{controller.d-D-hPLKaA.d.ts → controller.d-D6rEz5LS.d.ts} +3 -3
- package/dist/types-chunks/{history-retrieval.d-BwEUR9cb.d.ts → history-retrieval.d-B_AriUJp.d.ts} +1 -1
- package/dist/types-chunks/{manifest.d-YE3-AIeO.d.ts → manifest.d-Yyce-hHj.d.ts} +1 -1
- package/dist/types-chunks/{public-api.d-BhDU643p.d.ts → public-api.d-BLv3lFmw.d.ts} +9 -4
- package/dist/types-chunks/{review-inbox.d-Bgt46S7L.d.ts → review-inbox.d-yREk25Vf.d.ts} +2 -0
- package/dist/types-chunks/{review-packet.d-ChOfJaNI.d.ts → review-packet.d-xwXxHmML.d.ts} +1 -1
- package/dist/types-chunks/{run-manager.d-ChzguipG.d.ts → run-manager.d-D4sa9JYz.d.ts} +26 -12
- package/dist/types-chunks/{runtime-client-info-P_mRDG7j.d.ts → runtime-client-info-oRMrkHmb.d.ts} +2 -2
- package/dist/types-chunks/{runtime-event-BW5Pla7a.d.ts → runtime-event-BOyaILWg.d.ts} +3 -1
- package/dist/types-chunks/{sdk-runtime-cDe7qmN3.d.ts → sdk-runtime-CYyXmQok.d.ts} +27 -13
- package/dist/types-chunks/{sdk-session-D3pcSbnA.d.ts → sdk-session-D6mS5qgO.d.ts} +6 -3
- package/dist/types-chunks/{skill-invocation-error.d-gsNNDnnt.d.ts → skill-invocation-error.d-Be3qg4JQ.d.ts} +3 -3
- package/dist/types-chunks/{trusted-repl-entry-Bbkd2HlO.d.ts → trusted-repl-entry-YWNc4m-Z.d.ts} +7 -7
- package/dist/types-chunks/{types.d-BlXTogOo.d.ts → types.d-BQ-hbni4.d.ts} +1 -1
- package/dist/types-chunks/{utils.d-CxHyBvO6.d.ts → utils.d-C0F3Uf2X.d.ts} +6 -6
- package/dist/windows-effect-job-programs.json +4 -0
- package/docs/ARTIFACT_SDK.md +3 -3
- package/docs/CLIENT_CONTRACT.md +4 -2
- package/docs/SDK_MIGRATION.md +9 -5
- package/docs/SPACE_SDK_SEAMS.md +12 -1
- package/package.json +4 -3
- package/public_docs/README.md +10 -3
- package/public_docs/sdk/embedder-guide.md +1 -1
- package/dist/chunks/agent-DS7M57WD.js +0 -2
- package/dist/chunks/agent-adapter-TLWGGK3V.js +0 -2
- package/dist/chunks/argument-completer-OGCXKTRQ.js +0 -2
- package/dist/chunks/chunk-GJXOTOZB.js +0 -465
- package/dist/chunks/chunk-KE2NBMAP.js +0 -20
- package/dist/chunks/chunk-OGTRDK4Q.js +0 -359
- package/dist/chunks/chunk-R2HTPDI7.js +0 -2
- package/dist/chunks/chunk-SDPZFH6M.js +0 -4
- package/dist/chunks/chunk-XDMNJW6J.js +0 -42
- package/dist/chunks/compaction-config-ECMOFP5H.js +0 -2
- package/dist/chunks/dist-5J53DGAO.js +0 -2
- package/dist/chunks/host-65E5NM5P.js +0 -2
- package/dist/chunks/readline-helpers-UZXWBRXQ.js +0 -2
- package/dist/chunks/run-manager-ZFACIZM2.js +0 -2
- package/dist/chunks/running-session-Q5Y6A2QV.js +0 -2
- package/dist/chunks/skills-TJP6BLZJ.js +0 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @kodax-ai/kodax — bundled distribution. See docs/ADR.md ADR-022 + ADR-024.
|
|
2
|
-
import{h as f,k as v,l as y}from"./chunk-
|
|
2
|
+
import{h as f,k as v,l as y}from"./chunk-IOIFCU46.js";import{c as T}from"./chunk-HJLYZ5AX.js";import{a as c}from"./chunk-V4WSBIXB.js";import u from"node:fs";import{createHash as O}from"node:crypto";import{createRequire as C}from"node:module";import l from"node:path";var h=5;var P=C(import.meta.url),E=3e4,p;function S(t,o){let e=t.replaceAll("/","\\"),r=e.toLowerCase(),a=e.slice(3),d=(a===""?[]:a.split("\\")).some(n=>{let i=n.split(".",1)[0].toUpperCase(),g=["CON","PRN","AUX","NUL","CONIN$","CONOUT$"].includes(i)||/^(?:COM|LPT)[1-9¹²³]$/.test(i);return n===""||n==="."||n===".."||n.endsWith(".")||n.endsWith(" ")||/[\u0000-\u001f<>"|?*]/.test(n)||/~[0-9¹²³]/.test(n)||g});if(t.includes("\0")||e.startsWith("\\\\")||r.startsWith("\\??\\")||r.startsWith("\\device\\")||r.startsWith("\\global??\\")||r.startsWith("globalroot\\")||!/^[A-Za-z]:\\/.test(e)||e.slice(2).includes(":")||d)throw new T({code:"text_mutation_unsafe_path",path:t,message:`Trusted text mutation ${o} must use a local drive-absolute path; UNC and device namespaces are denied: ${t}`})}c(S,"assertLocalDriveAbsolutePath");function m(t,o){if(process.platform==="win32"){S(t,o);return}if(t.includes("\0")||!l.isAbsolute(t)||t.startsWith("//"))throw new T({code:"text_mutation_unsafe_path",path:t,message:`Trusted text mutation ${o} must use a local absolute path: ${t}`})}c(m,"assertSupportedAbsolutePath");function w(t,o){let e=l.relative(t,o);return e===""||!e.startsWith("..")&&!l.isAbsolute(e)}c(w,"sameOrInside");function A(t){let o=new Map;for(let e of t){let r=l.resolve(e),a=process.platform==="win32"?r.toLowerCase():r;o.has(a)||o.set(a,r)}return[...o.values()].sort((e,r)=>r.length-e.length)}c(A,"normalizedRootCandidates");function _(t,o,e=!1){m(t,"target");for(let n of o)m(n,"write root");let r=l.resolve(t),a=[...A(o)];if(e){let n=l.dirname(r);for(;!u.existsSync(n);){let i=l.dirname(n);if(i===n)break;n=i}a.unshift(n)}let s=a.find(n=>n!==r&&w(n,r)),d=c(n=>{try{if(!u.lstatSync(n).isDirectory())throw new Error("write root is not a directory");return u.realpathSync.native(n)}catch(i){throw new T({code:"text_mutation_unsafe_path",path:t,message:`Trusted text mutation write root is unavailable: ${n}`,cause:i})}},"canonicalizeRoot");if(s!==void 0){let n=d(s);return{canonicalRoot:n,canonicalTarget:l.join(n,l.relative(s,r))}}for(let n of a){let i=d(n);if(i!==r&&w(i,r))return{canonicalRoot:i,canonicalTarget:r}}throw new T({code:"text_mutation_policy_denied",path:t,message:`Trusted text mutation target is outside the Runtime write roots: ${t}`})}c(_,"authorizeTarget");function x(t,o=t){if(f(t),p!==void 0)return p;let e=y(import.meta.url,h,t,o),r=B(e);return p=X(r),p}c(x,"loadNativeBinding");function z(){try{return{ready:!0,protocol:x([]).textTransactionProtocol()}}catch(t){return{ready:!1,error:t instanceof Error?t.message:String(t)}}}c(z,"probeTrustedTextNativeBinding");function X(t){if(typeof t.textTransactionProtocol!="function"||typeof t.TrustedTextTransactionRoot!="function"||t.textTransactionProtocol()!==h)throw new Error(`The KodaX trusted text transaction binding must implement protocol ${h}.`);return t}c(X,"validateNativeBinding");function B(t){if(process.platform==="win32")return P(t);let o=u.openSync(t,u.constants.O_RDONLY|u.constants.O_NOFOLLOW);try{let e=u.fstatSync(o);if(!e.isFile()||e.nlink!==1||e.size>64*1024*1024)throw new Error("The protected native text binding has an unsafe identity.");let r=l.basename(l.dirname(t)).toLowerCase(),a=u.readFileSync(o),s=O("sha256").update(a).digest("hex");if(!/^[0-9a-f]{64}$/.test(r)||s!==r)throw new Error("The protected native text binding changed after provisioning.");let d={exports:{}},n=process.platform==="linux"?`/proc/self/fd/${o}`:`/dev/fd/${o}`;return process.dlopen(d,n),d.exports}finally{u.closeSync(o)}}c(B,"loadNativeBindingFile");function N(t,o,e){return process.platform==="win32"?new t.TrustedTextTransactionRoot(o,void 0,e):new t.TrustedTextTransactionRoot(o,v(),e)}c(N,"createNativeRoot");function W(t){switch(t){case"invalid_path":case"reparse_point":case"hard_link":return"text_mutation_unsafe_path";case"unauthorized_path":return"text_mutation_policy_denied";case"remote_filesystem":case"unsupported_filesystem":case"unsupported_platform":return"text_mutation_unsupported_filesystem";case"contended":return"text_mutation_contended";case"stale":return"text_mutation_stale";case"metadata_preservation":return"text_mutation_metadata_preservation_failed";default:return"text_mutation_io_failed"}}c(W,"mappedNativeErrorCode");function R(t,o){if(o instanceof T)throw o;let e=o instanceof Error?o.message:String(o),r="KODAX_TEXT_TRANSACTION:",a=e.indexOf(r),s={};if(a>=0)try{let d=JSON.parse(e.slice(a+r.length));d!==null&&typeof d=="object"&&!Array.isArray(d)&&(s=d)}catch{s={}}throw new T({code:W(s.code),path:t,message:s.message??e,...typeof s.os_code=="number"?{osCode:s.os_code}:{},cause:o})}c(R,"translateNativeError");function k(t){return{state:t.state,content:t.content,revision:t.revision,slot:t.slotId,canonicalPath:t.canonicalPath}}c(k,"publicSnapshot");function I(t,o,e){if(e.status==="stale"){if(typeof e.currentRevision!="string")throw new Error("Native text transaction returned a stale result without a revision.");return{status:"stale",currentRevision:e.currentRevision}}if(typeof e.slotId!="string"||typeof e.preContent!="string"||typeof e.preRevision!="string"||typeof e.postRevision!="string")throw new Error("Native text transaction returned an incomplete commit receipt.");let r={before:{state:e.preRevision.startsWith("missing:")?"missing":"present",content:e.preContent,revision:e.preRevision,slot:e.slotId,canonicalPath:t},after:{state:"present",content:o,revision:e.postRevision,slot:e.slotId,canonicalPath:t},recoveredAbandonedLock:e.abandonedLock===!0};if(e.status==="committed_uncertain"){if(typeof e.message!="string"||e.message==="")throw new Error("Native text transaction returned an uncertain commit without a reason.");return{status:"committed_uncertain",...r,reason:e.message}}return{status:"written",...r}}c(I,"requireWrittenOutcome");function H(t,o,e=()=>!1,r){return{async snapshot(a){if(a.signal?.aborted)throw a.signal.reason;m(a.path,"target");let s=e(),d=r?.(a.toolCall,a.path,"snapshot")===!0,n=_(a.path,t(),s||d);o(n.canonicalTarget),f([n.canonicalTarget]);try{let i=x([n.canonicalTarget],t()),g=N(i,n.canonicalRoot,s);return k(await g.snapshot(n.canonicalTarget))}catch(i){R(n.canonicalTarget,i)}},async commit(a){if(a.signal?.aborted)throw a.signal.reason;m(a.path,"target");let s=e(),d=r?.(a.toolCall,a.path,"commit")===!0,n=_(a.path,t(),s||d);o(n.canonicalTarget),f([n.canonicalTarget]);try{let i=x([n.canonicalTarget],t()),b=await N(i,n.canonicalRoot,s).commit(n.canonicalTarget,a.expectedRevision,a.content,a.createParentDirectories,E);return I(n.canonicalTarget,a.content,b)}catch(i){R(n.canonicalTarget,i)}}}}c(H,"createTrustedTextMutationHost");export{z as a,H as b};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @kodax-ai/kodax — bundled distribution. See docs/ADR.md ADR-022 + ADR-024.
|
|
2
|
-
import{b as Y}from"./chunk-D5OW7UD5.js";import{a as H,b as X}from"./chunk-45ZP2YHG.js";import{y as G}from"./chunk-NSR4RW2F.js";import{n as U,o as N}from"./chunk-SDPZFH6M.js";import{c as j,e as D}from"./chunk-2HH5AS7E.js";import{a as u}from"./chunk-V4WSBIXB.js";import h from"node:fs";import d from"node:path";import{createHash as ee,randomUUID as x}from"node:crypto";var B=new Map,_=64*1024*1024,k=u(e=>ee("sha256").update(e).digest("hex"),"hash");function b(e){return!!e&&typeof e=="object"&&"code"in e&&e.code==="ENOENT"}u(b,"missing");function E(e,t){let r=d.relative(e,t);if(r===".."||r.startsWith(`..${d.sep}`)||d.isAbsolute(r))throw new Error("Storage repair path escapes its declared root.");let n=d.resolve(t),o=d.parse(n),i=o.root;for(let a of n.slice(o.root.length).split(d.sep).filter(Boolean)){i=d.join(i,a);try{if(h.lstatSync(i).isSymbolicLink())throw new Error("Storage repair refuses filesystem aliases.")}catch(s){if(!b(s))throw s}}}u(E,"assertPath");function p(e,t,r=!1){E(e,t);let n=h.lstatSync(t);if(n.isDirectory()){if(!r||h.readdirSync(t).some(a=>a!=="owner.json"))throw new Error("Storage repair refuses directories with unexpected contents.");let i=Buffer.alloc(0);try{i=p(e,d.join(t,"owner.json")).bytes}catch(a){if(!b(a))throw a}return{snapshot:{type:"directory",sha256:k(Buffer.concat([Buffer.from("directory\0"),i])),bytes:i.length,dev:n.dev,ino:n.ino,mtimeMs:n.mtimeMs},bytes:i}}if(!n.isFile()||n.size>_)throw new Error("Storage repair requires a regular file within the inspection limit.");let o=h.openSync(t,"r");try{let i=h.fstatSync(o);if(i.dev!==n.dev||i.ino!==n.ino||i.size>_)throw new Error("Storage changed during inspection.");let a=Buffer.alloc(i.size+1),s=h.readSync(o,a,0,a.length,0),l=h.fstatSync(o);if(s!==i.size||l.size!==i.size||l.mtimeMs!==i.mtimeMs)throw new Error("Storage changed during inspection.");let y=a.subarray(0,s);return{snapshot:{type:"file",sha256:k(y),bytes:s,dev:l.dev,ino:l.ino,mtimeMs:l.mtimeMs},bytes:y}}finally{h.closeSync(o)}}u(p,"readSnapshot");function A(e){if(!e||!["runtime-agent-ledger","runtime-agent-snapshot","extension","a2a","lock"].includes(e.kind)||typeof e.root!="string"||!d.isAbsolute(e.root))throw new Error("Invalid storage repair target.");let t=d.resolve(e.root);if(e.kind==="runtime-agent-ledger"||e.kind==="runtime-agent-snapshot"){if(typeof e.taskId!="string"||!e.taskId)throw new Error("Runtime ledger repair requires a task ID.");return{kind:e.kind,root:t,taskId:e.taskId}}if(e.kind==="lock"){if(typeof e.path!="string"||!d.isAbsolute(e.path))throw new Error("Lock repair requires an exact absolute path.");return{kind:e.kind,root:t,path:d.resolve(e.path)}}return{kind:e.kind,root:t}}u(A,"normalizeTarget");function P(e,t=!1){let r=A(e),n=r.root;if(r.kind==="runtime-agent-ledger"||r.kind==="runtime-agent-snapshot"){let i=d.join(n,"tasks",k(r.taskId));return{file:d.join(i,r.kind==="runtime-agent-ledger"?"events.jsonl":"snapshot.json"),lock:d.join(n,".store.lock"),fence:d.join(i,".repair-fence")}}if(r.kind==="lock"){if(typeof r.path!="string"||!d.isAbsolute(r.path))throw new Error("Lock repair requires an exact absolute path.");if(E(n,r.path),!t&&!Y(n).items.some(i=>i.path===r.path&&i.state==="present"))throw new Error("Lock is outside the diagnosed repair inventory.");return{file:r.path,lock:`${r.path}.offline-repair.lock`}}let o=d.join(n,r.kind==="a2a"?"tasks.json":"store.jsonl");return{file:o,lock:r.kind==="a2a"?d.join(n,".server.lock"):`${o}.lock`,fence:`${o}.repair-fence`}}u(P,"targetFiles");function $(e){return new TextDecoder("utf-8",{fatal:!0}).decode(e)}u($,"decode");function I(e,t){try{let r=$(t);e.kind==="runtime-agent-ledger"?X(r,e.taskId):e.kind==="runtime-agent-snapshot"?H(r,e.taskId):e.kind==="extension"?D(r):e.kind==="a2a"&&G(r)}catch{throw new Error(`Invalid recovery candidate for ${e.kind}; original bytes retained.`)}}u(I,"validate");function T(e){try{let t=JSON.parse($(e));if(!t||typeof t!="object"||Array.isArray(t))throw new Error("Invalid metadata shape.");return t}catch{throw new Error("Invalid storage repair metadata; retain the receipt and original files.")}}u(T,"parseMetadata");function Q(e,t,r,n){let o=T(p(e,t).bytes);if(o.version!==1||o.state!=="unverified-recovery"||o.repairId!==r.id||o.receipt!==n)throw new Error("Storage recovery fence changed after repair.")}u(Q,"assertRepairFence");function V(e,t){if(e.kind==="lock")return{state:"unverified-ownership"};try{return I(e,t),{state:"valid"}}catch{}if(e.kind==="a2a"||e.kind==="runtime-agent-snapshot")return{state:"invalid-snapshot"};let r;for(let n=0;n<t.length;){let o=t.indexOf(10,n),i=o<0?t.length:o,a=t.subarray(n,i);if(a.some(s=>![9,13,32].includes(s))){if(r!==void 0)return{state:"invalid-json-middle"};try{JSON.parse($(a))}catch{r=n}}n=i+1}if(r!==void 0){let n=t.subarray(0,r);try{return I(e,n),{state:"invalid-json-tail",validPrefixBytes:n.length}}catch{return{state:"invalid-record"}}}return{state:"invalid-record"}}u(V,"diagnosis");function le(e){let t=A(e),r=P(t),n=p(t.root,r.file,e.kind==="lock");return{version:1,id:x(),target:t,file:r.file,source:n.snapshot,diagnosis:V(t,n.bytes)}}u(le,"inspectStorageRepair");function ue(e){if(!d.isAbsolute(e))throw new Error("Recovery candidate requires an absolute path.");let t=p(d.dirname(e),e);return{path:e,sha256:t.snapshot.sha256,bytes:t.snapshot.bytes}}u(ue,"inspectStorageRepairCandidate");function S(e,t,r=!1){let n=`${e}.${x()}.tmp`,o,i;try{o=h.openSync(n,"wx",384),h.writeFileSync(o,t),h.fsyncSync(o);let a=o;o=void 0,h.closeSync(a),r?h.linkSync(n,e):h.renameSync(n,e)}catch(a){throw i=a,a}finally{try{try{o!==void 0&&h.closeSync(o)}finally{h.rmSync(n,{force:!0})}}catch(a){throw new AggregateError(i===void 0?[a]:[i,a],"Storage repair publication cleanup failed.")}}}u(S,"atomic");function v(e,t){if(e.type!==t.type||e.sha256!==t.sha256||e.bytes!==t.bytes)throw new Error("Storage repair conflict: retained bytes changed.")}u(v,"assertSameContent");function J(e,t=!1){let r;try{r=JSON.parse(e.toString("utf8"))}catch{if(t)throw new Error("Reclamation claim ownership is unverified; retain it for separate offline inspection.");return}let n=typeof r=="number"?r:r&&typeof r=="object"&&"pid"in r?r.pid:void 0;if(typeof n!="number"||!Number.isSafeInteger(n)||n<=0){if(t)throw new Error("Reclamation claim ownership is unverified.");return}try{process.kill(n,0)}catch(o){if(o&&typeof o=="object"&&"code"in o&&o.code==="ESRCH")return;throw new Error("Lock owner cannot be verified offline.")}throw new Error("Lock still has a live owner; offline quarantine is refused.")}u(J,"assertOfflineOwner");function Z(e){let t=d.basename(e).split(".reclaim.")[0];if(d.basename(d.dirname(e))===".write-locks")throw new Error("Session writer locks use a different protocol; offline automatic quarantine is unsupported.");if(t.endsWith(".write.lock")||d.basename(d.dirname(e))==="integrations"&&t.endsWith(".json.lock"))return"config";if(["owner-policy.lock","startup.lock"].includes(t))return"coordination";if(t===".migration-lock")return"migration";if(/^[a-f0-9]{64}\.sealed\.lock$/.test(t))return"sealed";if([".store.lock",".server.lock","store.jsonl.lock"].includes(t))return"storage";if(["daemon.lock","owner.lock"].includes(t)&&!d.basename(e).includes(".reclaim."))return"host-owner";throw new Error("Unsupported lock protocol; retain the lock for qualified offline repair.")}u(Z,"lockFamily");function re(e,t,r,n){let o=Z(e.file);if(r.assertOwned(),o==="host-owner"){let f=U(e.file);if(!f)throw new Error("Host ownership coordination is busy or unverified; repair refused.");return{release:f}}if(d.basename(e.file).includes(".reclaim."))return{};let i,a=t.bytes.toString("utf8");try{i=JSON.parse(a)}catch{return{}}let s=i&&typeof i=="object"?i:void 0,l=u(f=>typeof f=="number"&&Number.isSafeInteger(f)&&f>0,"validPid"),y;if(o==="config"&&s?.version===1&&l(s.pid)&&typeof s.nonce=="string"&&s.nonce&&(y=k(s.nonce)),o==="coordination"&&s&&typeof s.nonce=="string"&&typeof s.runtimeId=="string"&&s.runtimeId.startsWith("owner-transition-")&&N(e.file)&&(y=k(s.nonce)),o==="migration"&&s&&l(s.pid)&&(t.snapshot.type==="directory"||s.version===1&&typeof s.nonce=="string"&&s.nonce)&&(y=k(a)),o==="storage"&&(s?.version===1&&l(s.pid)&&typeof s.token=="string"&&s.token||d.basename(e.file)===".server.lock"&&l(i))&&(y=k(a)),o==="sealed"){let f=N(t.snapshot.type==="directory"?d.join(e.file,"owner.json"):e.file);f&&(y=k(JSON.stringify(f)))}if(!y)return{};let w=`${e.file}.reclaim.${y}`;E(e.target.root,w);let c;try{c=p(e.target.root,w).bytes}catch(f){if(!b(f))throw f}if(c){let f=B.get(w);f&&!f.active&&f.planId===e.id&&f.raw.equals(c)?(r.assertOwned(),f.active=!0,n.push(w)):J(c,!0)}else{let f=Buffer.from(JSON.stringify({version:1,pid:process.pid,nonce:x(),offlineRepairId:e.id}));B.set(w,{planId:e.id,raw:f,active:!0}),n.push(w);try{S(w,f,!0)}catch(m){if(!m||typeof m!="object"||!("code"in m)||m.code!=="EEXIST")throw m;J(p(e.target.root,w).bytes,!0)}}return{claim:w}}u(re,"reserveGeneration");async function te(e,t){if(t.allWritersStopped!==!0)throw new Error("Offline storage repair requires every shared writer to be stopped.");if(!e||e.version!==1||typeof e.id!="string"||!/^[a-f0-9-]{36}$/.test(e.id)||typeof e.file!="string"||!d.isAbsolute(e.file)||!e.source||!/^[a-f0-9]{64}$/.test(e.source.sha256))throw new Error("Invalid storage repair plan.");if(Object.keys(e).some(c=>!["version","id","target","file","source","diagnosis"].includes(c))||Object.keys(e.source).some(c=>!["type","sha256","bytes","dev","ino","mtimeMs"].includes(c))||!e.diagnosis||Object.keys(e.diagnosis).some(c=>!["state","validPrefixBytes"].includes(c))||JSON.stringify(A(e.target))!==JSON.stringify(e.target))throw new Error("Storage repair plan contains unsupported metadata.");let r=d.resolve(e.target.root);E(r,e.file);let n=`${e.file}.repair.${e.id}.json`,o=`${e.file}.quarantined.${e.id}`,i;try{i=T(p(r,n).bytes)}catch(c){if(!b(c))throw c}if(i&&(JSON.stringify(i.plan)!==JSON.stringify(e)||i.backup!==o))throw new Error("Storage repair receipt conflicts with this plan.");if(i&&(i.version!==1||typeof i.completed!="boolean"||i.verified!==void 0&&i.verified!==!0||i.candidateSha256!==void 0&&!/^[a-f0-9]{64}$/.test(i.candidateSha256)||Object.keys(i).some(c=>!["version","plan","backup","candidateSha256","fence","completed","reclamationClaim","verified"].includes(c))))throw new Error("Invalid storage repair receipt metadata.");if(i?.completed&&e.target.kind==="lock")return v(e.source,p(r,o,!0).snapshot),i;let a=P(e.target,i!==void 0&&e.target.kind==="lock");if(a.file!==e.file)throw new Error("Storage repair plan target changed.");e.target.kind==="lock"&&Z(a.file),E(r,a.lock);let s=j(a.lock,{legacyPidRecord:e.target.kind==="a2a"});if(!s)throw new Error("Storage is busy, owned, or its lock is unverified; repair refused.");let l,y,w=[];try{if(i?.completed){if(v(e.source,p(r,o).snapshot),p(r,a.file).snapshot.sha256!==i.candidateSha256)throw new Error("Restored storage changed after repair.");if(t.candidate&&t.candidate.sha256!==i.candidateSha256)throw new Error("Recovery candidate conflicts with the completed repair.");return i.verified||Q(r,a.fence,e,n),i}if(e.target.kind==="lock"){if(i){let O;try{O=p(r,o,!0).snapshot}catch(R){if(!b(R))throw R}if(O){v(e.source,O);let R={...i,completed:!0};return S(n,Buffer.from(JSON.stringify(R))),R}}let g=p(r,a.file,!0);if(v(e.source,g.snapshot),JSON.stringify(g.snapshot)!==JSON.stringify(e.source))throw new Error("Lock generation changed after inspection.");J(g.bytes);let F=re(e,g,s,w);y=F.release;let K=p(r,a.file,!0);if(JSON.stringify(K.snapshot)!==JSON.stringify(g.snapshot))throw new Error("Lock generation changed before quarantine.");s.assertOwned();let W={version:1,plan:e,backup:o,reclamationClaim:F.claim,completed:!1};S(n,Buffer.from(JSON.stringify(W))),h.renameSync(a.file,o);let z={...W,completed:!0};return S(n,Buffer.from(JSON.stringify(z))),z}let c=p(r,a.file),f=i!==void 0&&c.snapshot.sha256===i.candidateSha256;if(!f){if(v(e.source,c.snapshot),JSON.stringify(e.source)!==JSON.stringify(c.snapshot))throw new Error("Storage file generation changed after inspection.");if(JSON.stringify(V(e.target,c.bytes))!==JSON.stringify(e.diagnosis))throw new Error("Storage repair diagnosis conflicts with this plan.");if(e.diagnosis.state==="valid")throw new Error("Storage is valid; corrupt-storage repair is not required.")}let m;if(f){if(t.candidate&&t.candidate.sha256!==i.candidateSha256)throw new Error("Recovery candidate conflicts with the interrupted repair.");m=c.bytes}else if(t.candidate){if(!d.isAbsolute(t.candidate.path)||!/^[a-f0-9]{64}$/.test(t.candidate.sha256))throw new Error("Invalid recovery candidate.");let g=p(d.dirname(t.candidate.path),t.candidate.path);if(g.snapshot.sha256!==t.candidate.sha256)throw new Error("Recovery candidate changed.");m=g.bytes}else{if(e.target.kind!=="runtime-agent-ledger"||e.diagnosis.state!=="invalid-json-tail"||e.diagnosis.validPrefixBytes===void 0)throw new Error("A complete validated recovery candidate is required.");m=c.bytes.subarray(0,e.diagnosis.validPrefixBytes)}I(e.target,m);let q=k(m);if(i&&i.candidateSha256!==q)throw new Error("Recovery candidate conflicts with the interrupted repair.");try{v(e.source,p(r,o).snapshot)}catch(g){if(!b(g)||f)throw g;S(o,c.bytes,!0)}let L={version:1,plan:e,backup:o,candidateSha256:q,fence:a.fence,completed:!1};S(n,Buffer.from(JSON.stringify(L))),E(r,a.fence);let M=Buffer.from(JSON.stringify({version:1,repairId:e.id,receipt:n,state:"unverified-recovery"}));try{S(a.fence,M,!0)}catch(g){if(!g||typeof g!="object"||!("code"in g)||g.code!=="EEXIST"||!p(r,a.fence).bytes.equals(M))throw g}f||S(a.file,m);let C={...L,completed:!0};return S(n,Buffer.from(JSON.stringify(C))),C}catch(c){throw l=c,c}finally{for(let f of w){let m=B.get(f);m?.planId===e.id&&(m.active=!1)}let c=l===void 0?[]:[l];try{y?.()}catch(f){c.push(f)}try{s.release()}catch(f){c.push(f)}if(c.length>(l===void 0?0:1))throw new AggregateError(c,"Storage repair ownership cleanup failed.")}}u(te,"applyStorageRepair");async function pe(e,t){if(t.verifiedCurrentState!==!0)throw new Error("Explicit verification of restored state is required before resuming access.");let r=await te(e.plan,{allWritersStopped:t.allWritersStopped});if(r.plan.target.kind==="lock")throw new Error("Lock quarantine has no recovery fence to confirm.");let n=P(r.plan.target),o=r.plan.target.root,i=`${n.file}.repair.${r.plan.id}.json`,a=j(n.lock,{legacyPidRecord:r.plan.target.kind==="a2a"});if(!a)throw new Error("Storage is busy or owned; verification refused.");let s;try{let l=T(p(o,i).bytes);if(JSON.stringify(l)!==JSON.stringify(r))throw new Error("Storage repair receipt changed during verification.");if(p(o,n.file).snapshot.sha256!==r.candidateSha256)throw new Error("Restored storage changed before verification.");v(r.plan.source,p(o,r.backup).snapshot),a.assertOwned();let y=!0;try{Q(o,n.fence,r.plan,i)}catch(c){if(!b(c)||!r.verified)throw c;y=!1}let w={...r,verified:!0};return r.verified||S(i,Buffer.from(JSON.stringify(w))),y&&(E(o,n.fence),h.unlinkSync(n.fence)),w}catch(l){throw s=l,l}finally{try{a.release()}catch(l){throw new AggregateError(s===void 0?[l]:[s,l],"Storage verification ownership cleanup failed.")}}}u(pe,"confirmStorageRepair");export{le as a,ue as b,te as c,pe as d};
|
|
2
|
+
import{b as Y}from"./chunk-D5OW7UD5.js";import{a as H,b as X}from"./chunk-45ZP2YHG.js";import{y as G}from"./chunk-3I2MIS4D.js";import{n as U,o as N}from"./chunk-5E2P4RYS.js";import{c as j,e as D}from"./chunk-DAQGOWKD.js";import{a as u}from"./chunk-V4WSBIXB.js";import h from"node:fs";import d from"node:path";import{createHash as ee,randomUUID as x}from"node:crypto";var B=new Map,_=64*1024*1024,k=u(e=>ee("sha256").update(e).digest("hex"),"hash");function b(e){return!!e&&typeof e=="object"&&"code"in e&&e.code==="ENOENT"}u(b,"missing");function E(e,t){let r=d.relative(e,t);if(r===".."||r.startsWith(`..${d.sep}`)||d.isAbsolute(r))throw new Error("Storage repair path escapes its declared root.");let n=d.resolve(t),o=d.parse(n),i=o.root;for(let a of n.slice(o.root.length).split(d.sep).filter(Boolean)){i=d.join(i,a);try{if(h.lstatSync(i).isSymbolicLink())throw new Error("Storage repair refuses filesystem aliases.")}catch(s){if(!b(s))throw s}}}u(E,"assertPath");function p(e,t,r=!1){E(e,t);let n=h.lstatSync(t);if(n.isDirectory()){if(!r||h.readdirSync(t).some(a=>a!=="owner.json"))throw new Error("Storage repair refuses directories with unexpected contents.");let i=Buffer.alloc(0);try{i=p(e,d.join(t,"owner.json")).bytes}catch(a){if(!b(a))throw a}return{snapshot:{type:"directory",sha256:k(Buffer.concat([Buffer.from("directory\0"),i])),bytes:i.length,dev:n.dev,ino:n.ino,mtimeMs:n.mtimeMs},bytes:i}}if(!n.isFile()||n.size>_)throw new Error("Storage repair requires a regular file within the inspection limit.");let o=h.openSync(t,"r");try{let i=h.fstatSync(o);if(i.dev!==n.dev||i.ino!==n.ino||i.size>_)throw new Error("Storage changed during inspection.");let a=Buffer.alloc(i.size+1),s=h.readSync(o,a,0,a.length,0),l=h.fstatSync(o);if(s!==i.size||l.size!==i.size||l.mtimeMs!==i.mtimeMs)throw new Error("Storage changed during inspection.");let y=a.subarray(0,s);return{snapshot:{type:"file",sha256:k(y),bytes:s,dev:l.dev,ino:l.ino,mtimeMs:l.mtimeMs},bytes:y}}finally{h.closeSync(o)}}u(p,"readSnapshot");function A(e){if(!e||!["runtime-agent-ledger","runtime-agent-snapshot","extension","a2a","lock"].includes(e.kind)||typeof e.root!="string"||!d.isAbsolute(e.root))throw new Error("Invalid storage repair target.");let t=d.resolve(e.root);if(e.kind==="runtime-agent-ledger"||e.kind==="runtime-agent-snapshot"){if(typeof e.taskId!="string"||!e.taskId)throw new Error("Runtime ledger repair requires a task ID.");return{kind:e.kind,root:t,taskId:e.taskId}}if(e.kind==="lock"){if(typeof e.path!="string"||!d.isAbsolute(e.path))throw new Error("Lock repair requires an exact absolute path.");return{kind:e.kind,root:t,path:d.resolve(e.path)}}return{kind:e.kind,root:t}}u(A,"normalizeTarget");function P(e,t=!1){let r=A(e),n=r.root;if(r.kind==="runtime-agent-ledger"||r.kind==="runtime-agent-snapshot"){let i=d.join(n,"tasks",k(r.taskId));return{file:d.join(i,r.kind==="runtime-agent-ledger"?"events.jsonl":"snapshot.json"),lock:d.join(n,".store.lock"),fence:d.join(i,".repair-fence")}}if(r.kind==="lock"){if(typeof r.path!="string"||!d.isAbsolute(r.path))throw new Error("Lock repair requires an exact absolute path.");if(E(n,r.path),!t&&!Y(n).items.some(i=>i.path===r.path&&i.state==="present"))throw new Error("Lock is outside the diagnosed repair inventory.");return{file:r.path,lock:`${r.path}.offline-repair.lock`}}let o=d.join(n,r.kind==="a2a"?"tasks.json":"store.jsonl");return{file:o,lock:r.kind==="a2a"?d.join(n,".server.lock"):`${o}.lock`,fence:`${o}.repair-fence`}}u(P,"targetFiles");function $(e){return new TextDecoder("utf-8",{fatal:!0}).decode(e)}u($,"decode");function I(e,t){try{let r=$(t);e.kind==="runtime-agent-ledger"?X(r,e.taskId):e.kind==="runtime-agent-snapshot"?H(r,e.taskId):e.kind==="extension"?D(r):e.kind==="a2a"&&G(r)}catch{throw new Error(`Invalid recovery candidate for ${e.kind}; original bytes retained.`)}}u(I,"validate");function T(e){try{let t=JSON.parse($(e));if(!t||typeof t!="object"||Array.isArray(t))throw new Error("Invalid metadata shape.");return t}catch{throw new Error("Invalid storage repair metadata; retain the receipt and original files.")}}u(T,"parseMetadata");function Q(e,t,r,n){let o=T(p(e,t).bytes);if(o.version!==1||o.state!=="unverified-recovery"||o.repairId!==r.id||o.receipt!==n)throw new Error("Storage recovery fence changed after repair.")}u(Q,"assertRepairFence");function V(e,t){if(e.kind==="lock")return{state:"unverified-ownership"};try{return I(e,t),{state:"valid"}}catch{}if(e.kind==="a2a"||e.kind==="runtime-agent-snapshot")return{state:"invalid-snapshot"};let r;for(let n=0;n<t.length;){let o=t.indexOf(10,n),i=o<0?t.length:o,a=t.subarray(n,i);if(a.some(s=>![9,13,32].includes(s))){if(r!==void 0)return{state:"invalid-json-middle"};try{JSON.parse($(a))}catch{r=n}}n=i+1}if(r!==void 0){let n=t.subarray(0,r);try{return I(e,n),{state:"invalid-json-tail",validPrefixBytes:n.length}}catch{return{state:"invalid-record"}}}return{state:"invalid-record"}}u(V,"diagnosis");function le(e){let t=A(e),r=P(t),n=p(t.root,r.file,e.kind==="lock");return{version:1,id:x(),target:t,file:r.file,source:n.snapshot,diagnosis:V(t,n.bytes)}}u(le,"inspectStorageRepair");function ue(e){if(!d.isAbsolute(e))throw new Error("Recovery candidate requires an absolute path.");let t=p(d.dirname(e),e);return{path:e,sha256:t.snapshot.sha256,bytes:t.snapshot.bytes}}u(ue,"inspectStorageRepairCandidate");function S(e,t,r=!1){let n=`${e}.${x()}.tmp`,o,i;try{o=h.openSync(n,"wx",384),h.writeFileSync(o,t),h.fsyncSync(o);let a=o;o=void 0,h.closeSync(a),r?h.linkSync(n,e):h.renameSync(n,e)}catch(a){throw i=a,a}finally{try{try{o!==void 0&&h.closeSync(o)}finally{h.rmSync(n,{force:!0})}}catch(a){throw new AggregateError(i===void 0?[a]:[i,a],"Storage repair publication cleanup failed.")}}}u(S,"atomic");function v(e,t){if(e.type!==t.type||e.sha256!==t.sha256||e.bytes!==t.bytes)throw new Error("Storage repair conflict: retained bytes changed.")}u(v,"assertSameContent");function J(e,t=!1){let r;try{r=JSON.parse(e.toString("utf8"))}catch{if(t)throw new Error("Reclamation claim ownership is unverified; retain it for separate offline inspection.");return}let n=typeof r=="number"?r:r&&typeof r=="object"&&"pid"in r?r.pid:void 0;if(typeof n!="number"||!Number.isSafeInteger(n)||n<=0){if(t)throw new Error("Reclamation claim ownership is unverified.");return}try{process.kill(n,0)}catch(o){if(o&&typeof o=="object"&&"code"in o&&o.code==="ESRCH")return;throw new Error("Lock owner cannot be verified offline.")}throw new Error("Lock still has a live owner; offline quarantine is refused.")}u(J,"assertOfflineOwner");function Z(e){let t=d.basename(e).split(".reclaim.")[0];if(d.basename(d.dirname(e))===".write-locks")throw new Error("Session writer locks use a different protocol; offline automatic quarantine is unsupported.");if(t.endsWith(".write.lock")||d.basename(d.dirname(e))==="integrations"&&t.endsWith(".json.lock"))return"config";if(["owner-policy.lock","startup.lock"].includes(t))return"coordination";if(t===".migration-lock")return"migration";if(/^[a-f0-9]{64}\.sealed\.lock$/.test(t))return"sealed";if([".store.lock",".server.lock","store.jsonl.lock"].includes(t))return"storage";if(["daemon.lock","owner.lock"].includes(t)&&!d.basename(e).includes(".reclaim."))return"host-owner";throw new Error("Unsupported lock protocol; retain the lock for qualified offline repair.")}u(Z,"lockFamily");function re(e,t,r,n){let o=Z(e.file);if(r.assertOwned(),o==="host-owner"){let f=U(e.file);if(!f)throw new Error("Host ownership coordination is busy or unverified; repair refused.");return{release:f}}if(d.basename(e.file).includes(".reclaim."))return{};let i,a=t.bytes.toString("utf8");try{i=JSON.parse(a)}catch{return{}}let s=i&&typeof i=="object"?i:void 0,l=u(f=>typeof f=="number"&&Number.isSafeInteger(f)&&f>0,"validPid"),y;if(o==="config"&&s?.version===1&&l(s.pid)&&typeof s.nonce=="string"&&s.nonce&&(y=k(s.nonce)),o==="coordination"&&s&&typeof s.nonce=="string"&&typeof s.runtimeId=="string"&&s.runtimeId.startsWith("owner-transition-")&&N(e.file)&&(y=k(s.nonce)),o==="migration"&&s&&l(s.pid)&&(t.snapshot.type==="directory"||s.version===1&&typeof s.nonce=="string"&&s.nonce)&&(y=k(a)),o==="storage"&&(s?.version===1&&l(s.pid)&&typeof s.token=="string"&&s.token||d.basename(e.file)===".server.lock"&&l(i))&&(y=k(a)),o==="sealed"){let f=N(t.snapshot.type==="directory"?d.join(e.file,"owner.json"):e.file);f&&(y=k(JSON.stringify(f)))}if(!y)return{};let w=`${e.file}.reclaim.${y}`;E(e.target.root,w);let c;try{c=p(e.target.root,w).bytes}catch(f){if(!b(f))throw f}if(c){let f=B.get(w);f&&!f.active&&f.planId===e.id&&f.raw.equals(c)?(r.assertOwned(),f.active=!0,n.push(w)):J(c,!0)}else{let f=Buffer.from(JSON.stringify({version:1,pid:process.pid,nonce:x(),offlineRepairId:e.id}));B.set(w,{planId:e.id,raw:f,active:!0}),n.push(w);try{S(w,f,!0)}catch(m){if(!m||typeof m!="object"||!("code"in m)||m.code!=="EEXIST")throw m;J(p(e.target.root,w).bytes,!0)}}return{claim:w}}u(re,"reserveGeneration");async function te(e,t){if(t.allWritersStopped!==!0)throw new Error("Offline storage repair requires every shared writer to be stopped.");if(!e||e.version!==1||typeof e.id!="string"||!/^[a-f0-9-]{36}$/.test(e.id)||typeof e.file!="string"||!d.isAbsolute(e.file)||!e.source||!/^[a-f0-9]{64}$/.test(e.source.sha256))throw new Error("Invalid storage repair plan.");if(Object.keys(e).some(c=>!["version","id","target","file","source","diagnosis"].includes(c))||Object.keys(e.source).some(c=>!["type","sha256","bytes","dev","ino","mtimeMs"].includes(c))||!e.diagnosis||Object.keys(e.diagnosis).some(c=>!["state","validPrefixBytes"].includes(c))||JSON.stringify(A(e.target))!==JSON.stringify(e.target))throw new Error("Storage repair plan contains unsupported metadata.");let r=d.resolve(e.target.root);E(r,e.file);let n=`${e.file}.repair.${e.id}.json`,o=`${e.file}.quarantined.${e.id}`,i;try{i=T(p(r,n).bytes)}catch(c){if(!b(c))throw c}if(i&&(JSON.stringify(i.plan)!==JSON.stringify(e)||i.backup!==o))throw new Error("Storage repair receipt conflicts with this plan.");if(i&&(i.version!==1||typeof i.completed!="boolean"||i.verified!==void 0&&i.verified!==!0||i.candidateSha256!==void 0&&!/^[a-f0-9]{64}$/.test(i.candidateSha256)||Object.keys(i).some(c=>!["version","plan","backup","candidateSha256","fence","completed","reclamationClaim","verified"].includes(c))))throw new Error("Invalid storage repair receipt metadata.");if(i?.completed&&e.target.kind==="lock")return v(e.source,p(r,o,!0).snapshot),i;let a=P(e.target,i!==void 0&&e.target.kind==="lock");if(a.file!==e.file)throw new Error("Storage repair plan target changed.");e.target.kind==="lock"&&Z(a.file),E(r,a.lock);let s=j(a.lock,{legacyPidRecord:e.target.kind==="a2a"});if(!s)throw new Error("Storage is busy, owned, or its lock is unverified; repair refused.");let l,y,w=[];try{if(i?.completed){if(v(e.source,p(r,o).snapshot),p(r,a.file).snapshot.sha256!==i.candidateSha256)throw new Error("Restored storage changed after repair.");if(t.candidate&&t.candidate.sha256!==i.candidateSha256)throw new Error("Recovery candidate conflicts with the completed repair.");return i.verified||Q(r,a.fence,e,n),i}if(e.target.kind==="lock"){if(i){let O;try{O=p(r,o,!0).snapshot}catch(R){if(!b(R))throw R}if(O){v(e.source,O);let R={...i,completed:!0};return S(n,Buffer.from(JSON.stringify(R))),R}}let g=p(r,a.file,!0);if(v(e.source,g.snapshot),JSON.stringify(g.snapshot)!==JSON.stringify(e.source))throw new Error("Lock generation changed after inspection.");J(g.bytes);let F=re(e,g,s,w);y=F.release;let K=p(r,a.file,!0);if(JSON.stringify(K.snapshot)!==JSON.stringify(g.snapshot))throw new Error("Lock generation changed before quarantine.");s.assertOwned();let W={version:1,plan:e,backup:o,reclamationClaim:F.claim,completed:!1};S(n,Buffer.from(JSON.stringify(W))),h.renameSync(a.file,o);let z={...W,completed:!0};return S(n,Buffer.from(JSON.stringify(z))),z}let c=p(r,a.file),f=i!==void 0&&c.snapshot.sha256===i.candidateSha256;if(!f){if(v(e.source,c.snapshot),JSON.stringify(e.source)!==JSON.stringify(c.snapshot))throw new Error("Storage file generation changed after inspection.");if(JSON.stringify(V(e.target,c.bytes))!==JSON.stringify(e.diagnosis))throw new Error("Storage repair diagnosis conflicts with this plan.");if(e.diagnosis.state==="valid")throw new Error("Storage is valid; corrupt-storage repair is not required.")}let m;if(f){if(t.candidate&&t.candidate.sha256!==i.candidateSha256)throw new Error("Recovery candidate conflicts with the interrupted repair.");m=c.bytes}else if(t.candidate){if(!d.isAbsolute(t.candidate.path)||!/^[a-f0-9]{64}$/.test(t.candidate.sha256))throw new Error("Invalid recovery candidate.");let g=p(d.dirname(t.candidate.path),t.candidate.path);if(g.snapshot.sha256!==t.candidate.sha256)throw new Error("Recovery candidate changed.");m=g.bytes}else{if(e.target.kind!=="runtime-agent-ledger"||e.diagnosis.state!=="invalid-json-tail"||e.diagnosis.validPrefixBytes===void 0)throw new Error("A complete validated recovery candidate is required.");m=c.bytes.subarray(0,e.diagnosis.validPrefixBytes)}I(e.target,m);let q=k(m);if(i&&i.candidateSha256!==q)throw new Error("Recovery candidate conflicts with the interrupted repair.");try{v(e.source,p(r,o).snapshot)}catch(g){if(!b(g)||f)throw g;S(o,c.bytes,!0)}let L={version:1,plan:e,backup:o,candidateSha256:q,fence:a.fence,completed:!1};S(n,Buffer.from(JSON.stringify(L))),E(r,a.fence);let M=Buffer.from(JSON.stringify({version:1,repairId:e.id,receipt:n,state:"unverified-recovery"}));try{S(a.fence,M,!0)}catch(g){if(!g||typeof g!="object"||!("code"in g)||g.code!=="EEXIST"||!p(r,a.fence).bytes.equals(M))throw g}f||S(a.file,m);let C={...L,completed:!0};return S(n,Buffer.from(JSON.stringify(C))),C}catch(c){throw l=c,c}finally{for(let f of w){let m=B.get(f);m?.planId===e.id&&(m.active=!1)}let c=l===void 0?[]:[l];try{y?.()}catch(f){c.push(f)}try{s.release()}catch(f){c.push(f)}if(c.length>(l===void 0?0:1))throw new AggregateError(c,"Storage repair ownership cleanup failed.")}}u(te,"applyStorageRepair");async function pe(e,t){if(t.verifiedCurrentState!==!0)throw new Error("Explicit verification of restored state is required before resuming access.");let r=await te(e.plan,{allWritersStopped:t.allWritersStopped});if(r.plan.target.kind==="lock")throw new Error("Lock quarantine has no recovery fence to confirm.");let n=P(r.plan.target),o=r.plan.target.root,i=`${n.file}.repair.${r.plan.id}.json`,a=j(n.lock,{legacyPidRecord:r.plan.target.kind==="a2a"});if(!a)throw new Error("Storage is busy or owned; verification refused.");let s;try{let l=T(p(o,i).bytes);if(JSON.stringify(l)!==JSON.stringify(r))throw new Error("Storage repair receipt changed during verification.");if(p(o,n.file).snapshot.sha256!==r.candidateSha256)throw new Error("Restored storage changed before verification.");v(r.plan.source,p(o,r.backup).snapshot),a.assertOwned();let y=!0;try{Q(o,n.fence,r.plan,i)}catch(c){if(!b(c)||!r.verified)throw c;y=!1}let w={...r,verified:!0};return r.verified||S(i,Buffer.from(JSON.stringify(w))),y&&(E(o,n.fence),h.unlinkSync(n.fence)),w}catch(l){throw s=l,l}finally{try{a.release()}catch(l){throw new AggregateError(s===void 0?[l]:[s,l],"Storage verification ownership cleanup failed.")}}}u(pe,"confirmStorageRepair");export{le as a,ue as b,te as c,pe as d};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @kodax-ai/kodax — bundled distribution. See docs/ADR.md ADR-022 + ADR-024.
|
|
2
|
-
import{qd as o}from"./chunk-
|
|
2
|
+
import{qd as o}from"./chunk-DAQGOWKD.js";import{c}from"./chunk-OMVAPRQI.js";import{a as n}from"./chunk-V4WSBIXB.js";import{readFile as a}from"fs/promises";var i={enabled:!0,triggerPercent:75};async function s(r){let t=c("config.json");try{let e=await f(t);if(e?.compaction)return o({...i,...e.compaction})}catch{}return o(i)}n(s,"loadCompactionConfig");async function f(r){try{let t=await a(r,"utf-8");return JSON.parse(t)}catch{return null}}n(f,"readConfigFile");export{s as a};
|