openpond 0.2.38 → 0.2.39
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/dist/app-server.js +1 -1
- package/dist/chunks/{app-server-runtime-PDT6BJD2.js → app-server-runtime-72NRJAB5.js} +1 -1
- package/dist/chunks/{chunk-V5BC6QT2.js → chunk-6GLGOIMQ.js} +1 -1
- package/dist/chunks/{chunk-IKM6ICPY.js → chunk-DHP75QSG.js} +1 -1
- package/dist/chunks/{chunk-KNEMKYHY.js → chunk-FVALIUVY.js} +1 -1
- package/dist/chunks/{chunk-OCWH4BV7.js → chunk-L6ELXODL.js} +1 -1
- package/dist/chunks/{chunk-GKRTXVNT.js → chunk-R6DWG5A4.js} +1 -1
- package/dist/chunks/{chunk-GOHJHZVA.js → chunk-RJACNWYJ.js} +159 -159
- package/dist/chunks/{chunk-ZCDOE3EO.js → chunk-ZO7DTED5.js} +1 -1
- package/dist/chunks/{cli-OP4EDGZN.js → cli-ETZV6JZI.js} +1 -1
- package/dist/chunks/{hosted-harness-runtime-6TE37GBH.js → hosted-harness-runtime-2YI2FLU2.js} +1 -1
- package/dist/chunks/{hosted-profile-compiler-7ZWCIHPA.js → hosted-profile-compiler-35BQPVJ6.js} +1 -1
- package/dist/chunks/{src-2NVS6PNZ.js → src-J7NT5WEH.js} +1 -1
- package/dist/chunks/{workspaces-2KYAFRX4.js → workspaces-RFQ4QB5A.js} +1 -1
- package/dist/cli.js +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire as __openpondCreateRequire } from "node:module"; var require = __openpondCreateRequire(import.meta.url);
|
|
2
|
-
import{ca as Y,fa as D,ga as Z,ha as ee,la as I,ma as re}from"./chunk-OCWH4BV7.js";import{E as x}from"./chunk-PKBU37CH.js";import{kd as X}from"./chunk-SBBXUZWL.js";import{b as W}from"./chunk-L3KS6MOV.js";import{Ba as G,Ca as Q,i as B,l as K,o as J,q as $,r as P,s as U,v as L,x as q}from"./chunk-QUNRWDVO.js";import{k as N,l as _,m as A}from"./chunk-HZP5U2AA.js";import{b as S}from"./chunk-ES2ISFJC.js";import{a as w}from"./chunk-FTQLQJQV.js";import{randomUUID as Re}from"node:crypto";import{readFile as C}from"node:fs/promises";import E from"node:path";import{promises as le}from"node:fs";import y from"node:path";import{randomUUID as O}from"node:crypto";import{promises as h}from"node:fs";import{stripTypeScriptTypes as me}from"node:module";import R from"node:path";async function Oe(s){let e=$.parse(s.overlay),r=P.parse(s.proposal),t=s.validations.map(u=>U.parse(u));if((r.route==="agent"?r.edits.filter(u=>u.target!=="harness.json"&&u.operation!=="delete"):[]).length>0){let u=r.validationPlan.find(a=>a.kind==="component_activation"&&a.required);if(!u)throw new Error("Desktop Work Agent proposals require component-activation validation before review.");if(t.find(a=>a.validationId===u.id)?.status==="passed")throw new Error("Desktop Work cannot accept a passed Agent activation receipt until an Agent source executor exists.")}if(r.overlay.id!==e.id||r.overlay.revision!==e.revision||r.overlay.contentHash!==e.contentHash)throw new Error("Refiner proposal is not bound to the supplied run overlay.");if(e.status!=="frozen")throw new Error("Only a frozen run overlay can advance a Harness workspace.");let o=await s.store.getHarnessWorkspace(r.expectedWorkspace.workspaceId);if(!o)throw new Error(`Harness workspace ${r.expectedWorkspace.workspaceId} does not exist.`);if(o.location!==s.store.harnessStoragePlacement)throw new Error("Refiner workspace does not match the admitted storage placement.");let i=D(s.storeDir,o.id),l=await I({workspaceId:o.id,sourceDir:i.source});if(l.sourceRevision!==o.sourceRevision)throw new Error(`Harness source is ${l.sourceRevision}; workspace expects ${o.sourceRevision}. Record or revert the source change before refinement.`);let d=R.join(i.root,`.source-candidate-${O()}`);await h.cp(i.source,d,{recursive:!0,force:!1,errorOnExist:!0,verbatimSymlinks:!1});try{await ae(d,r);let u=await I({workspaceId:o.id,sourceDir:d}),f=(s.now??(()=>new Date().toISOString()))(),a=await re({storeDir:s.storeDir,workspaceId:o.id,compiled:u,createdAt:f});await s.store.saveHarnessReleaseRecord(a),await s.store.saveHarnessImprovementArtifact(o.id,"run_overlay",e),await s.store.saveHarnessImprovementArtifact(o.id,"proposal",r);for(let c of t)await s.store.saveHarnessImprovementArtifact(o.id,"targeted_validation",c);if(!X({workspace:o,proposal:r}).eligible&&!s.reviewAuthority)return s.store.advanceHarnessWorkspaceAtomically({receiptId:s.receiptId,workspaceId:o.id,proposal:r,validations:t,nextRelease:{id:a.harnessRelease.id,contentHash:a.harnessRelease.contentHash},nextSourceRevision:a.sourceRevision,now:f});let m=R.join(i.root,`.source-backup-${O()}`),p=R.join(i.root,"source-swap.json");await ne(p,{schemaVersion:"openpond.localHarnessSourceSwap.v1",workspaceId:o.id,expectedWorkspaceRevision:o.revision,previousSourceRevision:o.sourceRevision,nextSourceRevision:a.sourceRevision,backupSource:m,candidateSource:d,createdAt:f}),await h.rename(i.source,m),await h.rename(d,i.source);try{let c=s.reviewAuthority?await s.store.advanceReviewedHarnessWorkspaceAtomically({receiptId:s.receiptId,workspaceId:o.id,proposal:r,validations:t,nextRelease:{id:a.harnessRelease.id,contentHash:a.harnessRelease.contentHash},nextSourceRevision:a.sourceRevision,reviewer:s.reviewAuthority.reviewer,now:f}):await s.store.advanceHarnessWorkspaceAtomically({receiptId:s.receiptId,workspaceId:o.id,proposal:r,validations:t,nextRelease:{id:a.harnessRelease.id,contentHash:a.harnessRelease.contentHash},nextSourceRevision:a.sourceRevision,now:f});return c.receipt.decision!=="advanced"?await j(i.source,m):await h.rm(m,{recursive:!0,force:!0}),await h.rm(p,{force:!0}),c}catch(c){throw await j(i.source,m).catch(()=>{}),await h.rm(p,{force:!0}).catch(()=>{}),c}}finally{await h.rm(d,{recursive:!0,force:!0}).catch(()=>{})}}w(Oe,"applyLocalHarnessRefinerProposal");async function $e(s){let e=await s.store.getHarnessWorkspace(s.workspaceId);if(!e||e.location!==s.store.harnessStoragePlacement)throw new Error(`Local Harness workspace ${s.workspaceId} does not exist.`);if(e.currentChannel.release?.id!==s.rollbackOf.id||e.currentChannel.release.contentHash!==s.rollbackOf.contentHash)throw new Error("Harness rollback source is no longer the current release.");let r=await s.store.getHarnessReleaseRecord(s.targetRelease.contentHash);if(!r||r.workspaceId!==e.id||r.harnessRelease.id!==s.targetRelease.id)throw new Error("Harness rollback target is unavailable in this workspace.");let t=D(s.storeDir,e.id);if((await I({workspaceId:e.id,sourceDir:t.source})).sourceRevision!==e.sourceRevision)throw new Error("Harness source changed before rollback.");let o=R.join(t.root,`.source-rollback-${O()}`);await h.cp(R.join(r.bundlePath,"source"),o,{recursive:!0,force:!1,errorOnExist:!0,verbatimSymlinks:!1});try{if((await I({workspaceId:e.id,sourceDir:o})).sourceRevision!==r.sourceRevision)throw new Error("Harness rollback bundle does not reproduce its registered source revision.");let l=(s.now??(()=>new Date().toISOString()))(),d=R.join(t.root,`.source-backup-${O()}`),u=R.join(t.root,"source-swap.json");await ne(u,{schemaVersion:"openpond.localHarnessSourceSwap.v1",workspaceId:e.id,expectedWorkspaceRevision:e.revision,previousSourceRevision:e.sourceRevision,nextSourceRevision:r.sourceRevision,backupSource:d,candidateSource:o,createdAt:l}),await h.rename(t.source,d),await h.rename(o,t.source);try{let f=await s.store.rollbackHarnessWorkspaceAtomically({receiptId:s.receiptId,workspaceId:e.id,expectedWorkspaceRevision:e.revision,expectedChannelRevision:e.currentChannel.revision,targetRelease:s.targetRelease,targetSourceRevision:r.sourceRevision,rollbackOf:s.rollbackOf,now:l});return f.receipt.decision!=="rolled_back"?await j(t.source,d):await h.rm(d,{recursive:!0,force:!0}),await h.rm(u,{force:!0}),f}catch(f){throw await j(t.source,d).catch(()=>{}),await h.rm(u,{force:!0}).catch(()=>{}),f}}finally{await h.rm(o,{recursive:!0,force:!0}).catch(()=>{})}}w($e,"rollbackLocalHarnessWorkspaceRelease");async function We(s){let e=P.parse(s.proposal);if(e.expectedWorkspace.workspaceId!==s.workspace.id)throw new Error("Refiner proposal targets a different Harness workspace.");if(e.route==="memory")return we({proposal:e,now:s.now});let r=D(s.storeDir,s.workspace.id),t=await I({workspaceId:s.workspace.id,sourceDir:r.source});if(t.sourceRevision!==e.expectedWorkspace.sourceRevision)throw new Error("Refiner proposal source revision no longer matches the Local Harness workspace.");let n=R.join(r.root,`.validation-candidate-${O()}`);await h.cp(r.source,n,{recursive:!0,force:!1,errorOnExist:!0,verbatimSymlinks:!1});let o=(s.now??(()=>new Date().toISOString()))();try{await ae(n,e);let i=await I({workspaceId:s.workspace.id,sourceDir:n}),l=new Map(i.manifest.files.map(a=>[a.path,a])),d=new Map(e.edits.map(a=>[a.target,a])),u=se(t),f=se(i);return Promise.all(e.validationPlan.map(async a=>{let v="passed",m="The candidate Harness source compiles and preserves its manifest contract.";try{if(a.kind==="observed_recovery"){let p=e.evidence.filter(c=>c.kind==="recovery");if(p.length===0)throw new Error("Observed-recovery validation requires recorded recovery evidence.");m=`Validated ${p.length} immutable recovery evidence reference(s) before candidate advancement.`}else if(a.kind==="prompt"){let p=e.edits.filter(c=>c.route==="prompt"&&c.target!=="harness.json");if(p.length===0)throw new Error("Prompt validation requires an instruction-file edit.");for(let c of p){let g=l.get(c.target);if(c.operation==="delete"){if(g)throw new Error(`Deleted instruction ${c.target} remains declared.`)}else if(g?.kind!=="instruction")throw new Error(`Instruction ${c.target} is not declared in the candidate Harness.`);if(c.content!==null&&/\b(?:api[_-]?key|access[_-]?token|password|secret)\s*[:=]/i.test(c.content))throw new Error(`Instruction ${c.target} appears to contain credential material.`)}m=`Validated ${p.length} textual instruction edit(s) and compiled candidate ${i.harnessRelease.id}.`}else if(a.kind==="skill"){let p=e.edits.filter(c=>c.route==="skill"&&c.target!=="harness.json");if(p.length===0)throw new Error("Skill validation requires a declared Skill-file edit.");for(let c of p){let g=l.get(c.target);if(c.operation==="delete"){if(g)throw new Error(`Deleted Skill ${c.target} remains declared.`);continue}if(g?.kind!=="skill")throw new Error(`Skill ${c.target} is not declared in the candidate Harness.`);let k=d.get(c.target)?.content;if(!k)throw new Error(`Skill edit ${c.target} has no content.`);let H=W(k);if(!H.name||!H.description||H.messages.length>0)throw new Error(`Skill ${c.target} is invalid: ${H.messages.join(" ")}`)}m=`Validated ${p.length} Skill edit(s), Skill frontmatter, and compiled candidate ${i.harnessRelease.id}.`}else if(a.kind==="dependency"){let p=i.manifest.files.find(c=>c.kind==="dependency_lock");if(!p)throw new Error("Candidate Harness has no dependency lock.");JSON.parse(await h.readFile(oe(n,p.path),"utf8")),m=`Validated dependency lock ${p.path} and compiled candidate ${i.harnessRelease.id}.`}else if(a.kind==="schema")P.parse(e),m=`Validated proposal, manifest, and candidate release schemas for ${i.harnessRelease.id}.`;else if(a.kind==="package"){let p=e.edits.filter(c=>c.route==="agent"&&c.operation!=="delete"&&c.target!=="harness.json");for(let c of p){if(!c.content)throw new Error(`Agent edit ${c.target} has no source.`);me(c.content,{mode:"transform",sourceUrl:c.target,sourceMap:!1})}m=p.length>0?`Syntax-checked ${p.length} Agent source edit(s) and compiled candidate ${i.harnessRelease.id}.`:`Compiled candidate package ${i.harnessRelease.id} and preserved the Harness source manifest contract.`}else if(a.kind==="component_activation"){let p=e.edits.filter(c=>c.target!=="harness.json");if(p.length===0)throw new Error("Component activation requires a concrete Harness component edit.");if(e.route==="agent"){if(p.filter(g=>g.operation!=="delete").length>0)throw new Error("Desktop Work does not compile or execute released Agent source; use an active instruction or standalone Skill, or add an Agent executor before release.");m=`Confirmed ${p.length} deleted Agent component(s) were inactive in Desktop Work.`}else{if(!["prompt","skill"].includes(e.route))throw new Error(`Desktop Work has no activation policy for ${e.route} proposals.`);let c=e.route==="prompt"?"instruction":"skill";for(let g of p){let k=f.components.find(H=>H.path===g.target&&H.kind===c);if(g.operation==="delete"?k:!k)throw new Error(`${c} ${g.target} is not reflected in the candidate Desktop Work runtime surface.`)}if(u.contentHash===f.contentHash)throw new Error("The candidate does not change the effective Desktop Work runtime surface.");m=`Activated ${p.length} ${c} edit(s) in the candidate Desktop Work runtime surface.`}}else a.kind==="business_formula"?(v="blocked",m="Business or financial logic is retained for review until an approved deterministic fixture supplies inputs and expected outputs."):a.kind==="targeted_evaluation"?(v="blocked",m="This sensitive change requires an explicit authority-preserving targeted Evaluation before release."):a.kind==="file_render"?(v="blocked",m="File-render validation requires an exact produced artifact reference; no artifact was attached to this Harness-source proposal."):(v="blocked",m=`Local targeted validation does not yet own ${a.kind}; it requires its dedicated validator.`)}catch(p){v="failed",m=p instanceof Error?p.message:String(p)}return q({schemaVersion:"openpond.harnessTargetedValidationReceipt.v1",id:`validation-${e.id}-${a.id}`,proposal:{id:e.id,contentHash:e.contentHash},validationId:a.id,kind:a.kind,status:v,summary:m,evidenceRefs:e.evidence,createdAt:o,metadata:{candidateHarnessRelease:{id:i.harnessRelease.id,contentHash:i.harnessRelease.contentHash},sourceRevision:i.sourceRevision,...a.kind==="component_activation"?{targetRuntime:"desktop_work",beforeEffectiveRuntimeHash:u.contentHash,afterEffectiveRuntimeHash:f.contentHash,activatedComponentRefs:f.components,inactiveAgentRefs:f.inactiveAgents}:{}}})}))}catch(i){let l=i instanceof Error?i.message:String(i);return e.validationPlan.map(d=>q({schemaVersion:"openpond.harnessTargetedValidationReceipt.v1",id:`validation-${e.id}-${d.id}`,proposal:{id:e.id,contentHash:e.contentHash},validationId:d.id,kind:d.kind,status:"failed",summary:l,evidenceRefs:e.evidence,createdAt:o,metadata:{}}))}finally{await h.rm(n,{recursive:!0,force:!0}).catch(()=>{})}}w(We,"validateLocalHarnessRefinerProposal");function se(s){let e=[...s.agentSnapshot.instructions.map(t=>({kind:"instruction",path:t.path,contentHash:t.contentHash})),...s.agentSnapshot.skills.map(t=>({kind:"skill",path:t.path,contentHash:t.contentHash}))].sort((t,n)=>t.path.localeCompare(n.path)),r=s.agentSnapshot.agents.map(t=>({path:t.path,contentHash:t.contentHash})).sort((t,n)=>t.path.localeCompare(n.path));return{contentHash:_({schemaVersion:"openpond.desktopWorkHarnessSurface.v1",components:e}),components:e,inactiveAgents:r}}w(se,"desktopWorkRuntimeSurface");function we(s){let e=(s.now??(()=>new Date().toISOString()))(),r=s.proposal.edits.find(t=>t.route==="memory");return s.proposal.validationPlan.map(t=>{let n="passed",o="Memory candidate is bounded, scoped, and contains no obvious credential material.";try{if(t.kind==="observed_recovery"){if(!s.proposal.evidence.some(i=>i.kind==="recovery"))throw new Error("Observed-recovery validation requires recorded recovery evidence.");o="Memory proposal is grounded in immutable recovery evidence."}else if(t.kind==="memory"){if(!r||!/^memory\/[a-z0-9][a-z0-9-]{0,119}$/.test(r.target))throw new Error("Memory proposal requires one safe memory/<slug> target.");let i=s.proposal.metadata.expectedMemory;if(!i||typeof i!="object"||Array.isArray(i))throw new Error("Memory proposal requires an expected revision snapshot.");let l=i;if(l.key!==fe(r.target))throw new Error("Memory proposal expected revision targets a different key.");if(l.revision!==null&&(!Number.isInteger(l.revision)||Number(l.revision)<1))throw new Error("Memory proposal expected revision is invalid.");if(l.contentHash!==null&&typeof l.contentHash!="string")throw new Error("Memory proposal expected content hash is invalid.");if(l.status!==null&&l.status!=="active"&&l.status!=="deleted")throw new Error("Memory proposal expected status is invalid.");if(l.revision===null&&(l.contentHash!==null||l.status!==null))throw new Error("New memory snapshot must not claim existing content or status.");if(l.revision!==null&&(typeof l.contentHash!="string"||l.status===null))throw new Error("Existing memory snapshot requires its content hash and status.");if(r.operation==="delete"&&l.status!=="active")throw new Error("Memory deletion requires an active expected revision.");if(r.operation!=="delete"){if(!r.content?.trim()||r.content.length>24e3)throw new Error("Memory content must contain 1-24,000 characters.");if(/\b(?:api[_-]?key|access[_-]?token|password|secret)\s*[:=]/i.test(r.content))throw new Error("Memory content appears to contain credential material.")}}else n="blocked",o=`Memory validation cannot satisfy ${t.kind}.`}catch(i){n="failed",o=i instanceof Error?i.message:String(i)}return q({schemaVersion:"openpond.harnessTargetedValidationReceipt.v1",id:`validation-${s.proposal.id}-${t.id}`,proposal:{id:s.proposal.id,contentHash:s.proposal.contentHash},validationId:t.id,kind:t.kind,status:n,summary:o,evidenceRefs:s.proposal.evidence,createdAt:e,metadata:{externalState:"harness_memory"}})})}w(we,"validateMemoryProposal");function fe(s){let e=s.replaceAll("\\","/"),r=/^memory\/([a-z0-9][a-z0-9-]{0,119})$/.exec(e);if(!r)throw new Error(`Invalid Harness memory target: ${s}.`);return r[1]}w(fe,"memoryKeyFromTarget");async function te(s){let e=await s.store.getHarnessWorkspace(s.workspaceId);if(!e)throw new Error(`Harness workspace ${s.workspaceId} does not exist.`);let r=D(s.storeDir,e.id),t=R.join(r.root,"source-swap.json"),n=await h.readFile(t,"utf8").then(JSON.parse).catch(l=>{if(l.code==="ENOENT")return null;throw l});if(!n)return"none";let o=await I({workspaceId:e.id,sourceDir:r.source});if(e.sourceRevision===n.nextSourceRevision&&o.sourceRevision===n.nextSourceRevision)return await h.rm(n.backupSource,{recursive:!0,force:!0}),await h.rm(t,{force:!0}),"completed";let i=await I({workspaceId:e.id,sourceDir:n.backupSource});if(e.sourceRevision===n.previousSourceRevision&&i.sourceRevision===n.previousSourceRevision)return await j(r.source,n.backupSource),await h.rm(t,{force:!0}),"restored";throw new Error("Harness source-swap recovery cannot reconcile filesystem and workspace revisions.")}w(te,"recoverLocalHarnessSourceSwap");async function ae(s,e){for(let r of e.edits){let t=oe(s,r.target);if(r.operation==="delete"){await h.rm(t,{force:!1});continue}if(r.content===null)throw new Error(`Refiner edit ${r.id} has no content.`);if(r.operation==="create")await h.mkdir(R.dirname(t),{recursive:!0}),await h.writeFile(t,r.content,{flag:"wx"});else{let n=await h.lstat(t);if(!n.isFile()||n.isSymbolicLink())throw new Error(`Refiner update target must be a regular file: ${r.target}`);await h.writeFile(t,r.content,{flag:"w"})}}}w(ae,"applyOverlayEdits");function oe(s,e){let r=R.resolve(s),t=R.resolve(r,...e.replaceAll("\\","/").split("/")),n=R.relative(r,t);if(!n||n.startsWith("..")||R.isAbsolute(n))throw new Error(`Refiner edit target escapes the Harness source: ${e}`);return t}w(oe,"containedPath");async function ne(s,e){let r=`${s}.${O()}.tmp`;await h.writeFile(r,`${JSON.stringify(e,null,2)}
|
|
2
|
+
import{ca as Y,fa as D,ga as Z,ha as ee,la as I,ma as re}from"./chunk-L6ELXODL.js";import{E as x}from"./chunk-PKBU37CH.js";import{kd as X}from"./chunk-SBBXUZWL.js";import{b as W}from"./chunk-L3KS6MOV.js";import{Ba as G,Ca as Q,i as B,l as K,o as J,q as $,r as P,s as U,v as L,x as q}from"./chunk-QUNRWDVO.js";import{k as N,l as _,m as A}from"./chunk-HZP5U2AA.js";import{b as S}from"./chunk-ES2ISFJC.js";import{a as w}from"./chunk-FTQLQJQV.js";import{randomUUID as Re}from"node:crypto";import{readFile as C}from"node:fs/promises";import E from"node:path";import{promises as le}from"node:fs";import y from"node:path";import{randomUUID as O}from"node:crypto";import{promises as h}from"node:fs";import{stripTypeScriptTypes as me}from"node:module";import R from"node:path";async function Oe(s){let e=$.parse(s.overlay),r=P.parse(s.proposal),t=s.validations.map(u=>U.parse(u));if((r.route==="agent"?r.edits.filter(u=>u.target!=="harness.json"&&u.operation!=="delete"):[]).length>0){let u=r.validationPlan.find(a=>a.kind==="component_activation"&&a.required);if(!u)throw new Error("Desktop Work Agent proposals require component-activation validation before review.");if(t.find(a=>a.validationId===u.id)?.status==="passed")throw new Error("Desktop Work cannot accept a passed Agent activation receipt until an Agent source executor exists.")}if(r.overlay.id!==e.id||r.overlay.revision!==e.revision||r.overlay.contentHash!==e.contentHash)throw new Error("Refiner proposal is not bound to the supplied run overlay.");if(e.status!=="frozen")throw new Error("Only a frozen run overlay can advance a Harness workspace.");let o=await s.store.getHarnessWorkspace(r.expectedWorkspace.workspaceId);if(!o)throw new Error(`Harness workspace ${r.expectedWorkspace.workspaceId} does not exist.`);if(o.location!==s.store.harnessStoragePlacement)throw new Error("Refiner workspace does not match the admitted storage placement.");let i=D(s.storeDir,o.id),l=await I({workspaceId:o.id,sourceDir:i.source});if(l.sourceRevision!==o.sourceRevision)throw new Error(`Harness source is ${l.sourceRevision}; workspace expects ${o.sourceRevision}. Record or revert the source change before refinement.`);let d=R.join(i.root,`.source-candidate-${O()}`);await h.cp(i.source,d,{recursive:!0,force:!1,errorOnExist:!0,verbatimSymlinks:!1});try{await ae(d,r);let u=await I({workspaceId:o.id,sourceDir:d}),f=(s.now??(()=>new Date().toISOString()))(),a=await re({storeDir:s.storeDir,workspaceId:o.id,compiled:u,createdAt:f});await s.store.saveHarnessReleaseRecord(a),await s.store.saveHarnessImprovementArtifact(o.id,"run_overlay",e),await s.store.saveHarnessImprovementArtifact(o.id,"proposal",r);for(let c of t)await s.store.saveHarnessImprovementArtifact(o.id,"targeted_validation",c);if(!X({workspace:o,proposal:r}).eligible&&!s.reviewAuthority)return s.store.advanceHarnessWorkspaceAtomically({receiptId:s.receiptId,workspaceId:o.id,proposal:r,validations:t,nextRelease:{id:a.harnessRelease.id,contentHash:a.harnessRelease.contentHash},nextSourceRevision:a.sourceRevision,now:f});let m=R.join(i.root,`.source-backup-${O()}`),p=R.join(i.root,"source-swap.json");await ne(p,{schemaVersion:"openpond.localHarnessSourceSwap.v1",workspaceId:o.id,expectedWorkspaceRevision:o.revision,previousSourceRevision:o.sourceRevision,nextSourceRevision:a.sourceRevision,backupSource:m,candidateSource:d,createdAt:f}),await h.rename(i.source,m),await h.rename(d,i.source);try{let c=s.reviewAuthority?await s.store.advanceReviewedHarnessWorkspaceAtomically({receiptId:s.receiptId,workspaceId:o.id,proposal:r,validations:t,nextRelease:{id:a.harnessRelease.id,contentHash:a.harnessRelease.contentHash},nextSourceRevision:a.sourceRevision,reviewer:s.reviewAuthority.reviewer,now:f}):await s.store.advanceHarnessWorkspaceAtomically({receiptId:s.receiptId,workspaceId:o.id,proposal:r,validations:t,nextRelease:{id:a.harnessRelease.id,contentHash:a.harnessRelease.contentHash},nextSourceRevision:a.sourceRevision,now:f});return c.receipt.decision!=="advanced"?await j(i.source,m):await h.rm(m,{recursive:!0,force:!0}),await h.rm(p,{force:!0}),c}catch(c){throw await j(i.source,m).catch(()=>{}),await h.rm(p,{force:!0}).catch(()=>{}),c}}finally{await h.rm(d,{recursive:!0,force:!0}).catch(()=>{})}}w(Oe,"applyLocalHarnessRefinerProposal");async function $e(s){let e=await s.store.getHarnessWorkspace(s.workspaceId);if(!e||e.location!==s.store.harnessStoragePlacement)throw new Error(`Local Harness workspace ${s.workspaceId} does not exist.`);if(e.currentChannel.release?.id!==s.rollbackOf.id||e.currentChannel.release.contentHash!==s.rollbackOf.contentHash)throw new Error("Harness rollback source is no longer the current release.");let r=await s.store.getHarnessReleaseRecord(s.targetRelease.contentHash);if(!r||r.workspaceId!==e.id||r.harnessRelease.id!==s.targetRelease.id)throw new Error("Harness rollback target is unavailable in this workspace.");let t=D(s.storeDir,e.id);if((await I({workspaceId:e.id,sourceDir:t.source})).sourceRevision!==e.sourceRevision)throw new Error("Harness source changed before rollback.");let o=R.join(t.root,`.source-rollback-${O()}`);await h.cp(R.join(r.bundlePath,"source"),o,{recursive:!0,force:!1,errorOnExist:!0,verbatimSymlinks:!1});try{if((await I({workspaceId:e.id,sourceDir:o})).sourceRevision!==r.sourceRevision)throw new Error("Harness rollback bundle does not reproduce its registered source revision.");let l=(s.now??(()=>new Date().toISOString()))(),d=R.join(t.root,`.source-backup-${O()}`),u=R.join(t.root,"source-swap.json");await ne(u,{schemaVersion:"openpond.localHarnessSourceSwap.v1",workspaceId:e.id,expectedWorkspaceRevision:e.revision,previousSourceRevision:e.sourceRevision,nextSourceRevision:r.sourceRevision,backupSource:d,candidateSource:o,createdAt:l}),await h.rename(t.source,d),await h.rename(o,t.source);try{let f=await s.store.rollbackHarnessWorkspaceAtomically({receiptId:s.receiptId,workspaceId:e.id,expectedWorkspaceRevision:e.revision,expectedChannelRevision:e.currentChannel.revision,targetRelease:s.targetRelease,targetSourceRevision:r.sourceRevision,rollbackOf:s.rollbackOf,now:l});return f.receipt.decision!=="rolled_back"?await j(t.source,d):await h.rm(d,{recursive:!0,force:!0}),await h.rm(u,{force:!0}),f}catch(f){throw await j(t.source,d).catch(()=>{}),await h.rm(u,{force:!0}).catch(()=>{}),f}}finally{await h.rm(o,{recursive:!0,force:!0}).catch(()=>{})}}w($e,"rollbackLocalHarnessWorkspaceRelease");async function We(s){let e=P.parse(s.proposal);if(e.expectedWorkspace.workspaceId!==s.workspace.id)throw new Error("Refiner proposal targets a different Harness workspace.");if(e.route==="memory")return we({proposal:e,now:s.now});let r=D(s.storeDir,s.workspace.id),t=await I({workspaceId:s.workspace.id,sourceDir:r.source});if(t.sourceRevision!==e.expectedWorkspace.sourceRevision)throw new Error("Refiner proposal source revision no longer matches the Local Harness workspace.");let n=R.join(r.root,`.validation-candidate-${O()}`);await h.cp(r.source,n,{recursive:!0,force:!1,errorOnExist:!0,verbatimSymlinks:!1});let o=(s.now??(()=>new Date().toISOString()))();try{await ae(n,e);let i=await I({workspaceId:s.workspace.id,sourceDir:n}),l=new Map(i.manifest.files.map(a=>[a.path,a])),d=new Map(e.edits.map(a=>[a.target,a])),u=se(t),f=se(i);return Promise.all(e.validationPlan.map(async a=>{let v="passed",m="The candidate Harness source compiles and preserves its manifest contract.";try{if(a.kind==="observed_recovery"){let p=e.evidence.filter(c=>c.kind==="recovery");if(p.length===0)throw new Error("Observed-recovery validation requires recorded recovery evidence.");m=`Validated ${p.length} immutable recovery evidence reference(s) before candidate advancement.`}else if(a.kind==="prompt"){let p=e.edits.filter(c=>c.route==="prompt"&&c.target!=="harness.json");if(p.length===0)throw new Error("Prompt validation requires an instruction-file edit.");for(let c of p){let g=l.get(c.target);if(c.operation==="delete"){if(g)throw new Error(`Deleted instruction ${c.target} remains declared.`)}else if(g?.kind!=="instruction")throw new Error(`Instruction ${c.target} is not declared in the candidate Harness.`);if(c.content!==null&&/\b(?:api[_-]?key|access[_-]?token|password|secret)\s*[:=]/i.test(c.content))throw new Error(`Instruction ${c.target} appears to contain credential material.`)}m=`Validated ${p.length} textual instruction edit(s) and compiled candidate ${i.harnessRelease.id}.`}else if(a.kind==="skill"){let p=e.edits.filter(c=>c.route==="skill"&&c.target!=="harness.json");if(p.length===0)throw new Error("Skill validation requires a declared Skill-file edit.");for(let c of p){let g=l.get(c.target);if(c.operation==="delete"){if(g)throw new Error(`Deleted Skill ${c.target} remains declared.`);continue}if(g?.kind!=="skill")throw new Error(`Skill ${c.target} is not declared in the candidate Harness.`);let k=d.get(c.target)?.content;if(!k)throw new Error(`Skill edit ${c.target} has no content.`);let H=W(k);if(!H.name||!H.description||H.messages.length>0)throw new Error(`Skill ${c.target} is invalid: ${H.messages.join(" ")}`)}m=`Validated ${p.length} Skill edit(s), Skill frontmatter, and compiled candidate ${i.harnessRelease.id}.`}else if(a.kind==="dependency"){let p=i.manifest.files.find(c=>c.kind==="dependency_lock");if(!p)throw new Error("Candidate Harness has no dependency lock.");JSON.parse(await h.readFile(oe(n,p.path),"utf8")),m=`Validated dependency lock ${p.path} and compiled candidate ${i.harnessRelease.id}.`}else if(a.kind==="schema")P.parse(e),m=`Validated proposal, manifest, and candidate release schemas for ${i.harnessRelease.id}.`;else if(a.kind==="package"){let p=e.edits.filter(c=>c.route==="agent"&&c.operation!=="delete"&&c.target!=="harness.json");for(let c of p){if(!c.content)throw new Error(`Agent edit ${c.target} has no source.`);me(c.content,{mode:"transform",sourceUrl:c.target,sourceMap:!1})}m=p.length>0?`Syntax-checked ${p.length} Agent source edit(s) and compiled candidate ${i.harnessRelease.id}.`:`Compiled candidate package ${i.harnessRelease.id} and preserved the Harness source manifest contract.`}else if(a.kind==="component_activation"){let p=e.edits.filter(c=>c.target!=="harness.json");if(p.length===0)throw new Error("Component activation requires a concrete Harness component edit.");if(e.route==="agent"){if(p.filter(g=>g.operation!=="delete").length>0)throw new Error("Desktop Work does not compile or execute released Agent source; use an active instruction or standalone Skill, or add an Agent executor before release.");m=`Confirmed ${p.length} deleted Agent component(s) were inactive in Desktop Work.`}else{if(!["prompt","skill"].includes(e.route))throw new Error(`Desktop Work has no activation policy for ${e.route} proposals.`);let c=e.route==="prompt"?"instruction":"skill";for(let g of p){let k=f.components.find(H=>H.path===g.target&&H.kind===c);if(g.operation==="delete"?k:!k)throw new Error(`${c} ${g.target} is not reflected in the candidate Desktop Work runtime surface.`)}if(u.contentHash===f.contentHash)throw new Error("The candidate does not change the effective Desktop Work runtime surface.");m=`Activated ${p.length} ${c} edit(s) in the candidate Desktop Work runtime surface.`}}else a.kind==="business_formula"?(v="blocked",m="Business or financial logic is retained for review until an approved deterministic fixture supplies inputs and expected outputs."):a.kind==="targeted_evaluation"?(v="blocked",m="This sensitive change requires an explicit authority-preserving targeted Evaluation before release."):a.kind==="file_render"?(v="blocked",m="File-render validation requires an exact produced artifact reference; no artifact was attached to this Harness-source proposal."):(v="blocked",m=`Local targeted validation does not yet own ${a.kind}; it requires its dedicated validator.`)}catch(p){v="failed",m=p instanceof Error?p.message:String(p)}return q({schemaVersion:"openpond.harnessTargetedValidationReceipt.v1",id:`validation-${e.id}-${a.id}`,proposal:{id:e.id,contentHash:e.contentHash},validationId:a.id,kind:a.kind,status:v,summary:m,evidenceRefs:e.evidence,createdAt:o,metadata:{candidateHarnessRelease:{id:i.harnessRelease.id,contentHash:i.harnessRelease.contentHash},sourceRevision:i.sourceRevision,...a.kind==="component_activation"?{targetRuntime:"desktop_work",beforeEffectiveRuntimeHash:u.contentHash,afterEffectiveRuntimeHash:f.contentHash,activatedComponentRefs:f.components,inactiveAgentRefs:f.inactiveAgents}:{}}})}))}catch(i){let l=i instanceof Error?i.message:String(i);return e.validationPlan.map(d=>q({schemaVersion:"openpond.harnessTargetedValidationReceipt.v1",id:`validation-${e.id}-${d.id}`,proposal:{id:e.id,contentHash:e.contentHash},validationId:d.id,kind:d.kind,status:"failed",summary:l,evidenceRefs:e.evidence,createdAt:o,metadata:{}}))}finally{await h.rm(n,{recursive:!0,force:!0}).catch(()=>{})}}w(We,"validateLocalHarnessRefinerProposal");function se(s){let e=[...s.agentSnapshot.instructions.map(t=>({kind:"instruction",path:t.path,contentHash:t.contentHash})),...s.agentSnapshot.skills.map(t=>({kind:"skill",path:t.path,contentHash:t.contentHash}))].sort((t,n)=>t.path.localeCompare(n.path)),r=s.agentSnapshot.agents.map(t=>({path:t.path,contentHash:t.contentHash})).sort((t,n)=>t.path.localeCompare(n.path));return{contentHash:_({schemaVersion:"openpond.desktopWorkHarnessSurface.v1",components:e}),components:e,inactiveAgents:r}}w(se,"desktopWorkRuntimeSurface");function we(s){let e=(s.now??(()=>new Date().toISOString()))(),r=s.proposal.edits.find(t=>t.route==="memory");return s.proposal.validationPlan.map(t=>{let n="passed",o="Memory candidate is bounded, scoped, and contains no obvious credential material.";try{if(t.kind==="observed_recovery"){if(!s.proposal.evidence.some(i=>i.kind==="recovery"))throw new Error("Observed-recovery validation requires recorded recovery evidence.");o="Memory proposal is grounded in immutable recovery evidence."}else if(t.kind==="memory"){if(!r||!/^memory\/[a-z0-9][a-z0-9-]{0,119}$/.test(r.target))throw new Error("Memory proposal requires one safe memory/<slug> target.");let i=s.proposal.metadata.expectedMemory;if(!i||typeof i!="object"||Array.isArray(i))throw new Error("Memory proposal requires an expected revision snapshot.");let l=i;if(l.key!==fe(r.target))throw new Error("Memory proposal expected revision targets a different key.");if(l.revision!==null&&(!Number.isInteger(l.revision)||Number(l.revision)<1))throw new Error("Memory proposal expected revision is invalid.");if(l.contentHash!==null&&typeof l.contentHash!="string")throw new Error("Memory proposal expected content hash is invalid.");if(l.status!==null&&l.status!=="active"&&l.status!=="deleted")throw new Error("Memory proposal expected status is invalid.");if(l.revision===null&&(l.contentHash!==null||l.status!==null))throw new Error("New memory snapshot must not claim existing content or status.");if(l.revision!==null&&(typeof l.contentHash!="string"||l.status===null))throw new Error("Existing memory snapshot requires its content hash and status.");if(r.operation==="delete"&&l.status!=="active")throw new Error("Memory deletion requires an active expected revision.");if(r.operation!=="delete"){if(!r.content?.trim()||r.content.length>24e3)throw new Error("Memory content must contain 1-24,000 characters.");if(/\b(?:api[_-]?key|access[_-]?token|password|secret)\s*[:=]/i.test(r.content))throw new Error("Memory content appears to contain credential material.")}}else n="blocked",o=`Memory validation cannot satisfy ${t.kind}.`}catch(i){n="failed",o=i instanceof Error?i.message:String(i)}return q({schemaVersion:"openpond.harnessTargetedValidationReceipt.v1",id:`validation-${s.proposal.id}-${t.id}`,proposal:{id:s.proposal.id,contentHash:s.proposal.contentHash},validationId:t.id,kind:t.kind,status:n,summary:o,evidenceRefs:s.proposal.evidence,createdAt:e,metadata:{externalState:"harness_memory"}})})}w(we,"validateMemoryProposal");function fe(s){let e=s.replaceAll("\\","/"),r=/^memory\/([a-z0-9][a-z0-9-]{0,119})$/.exec(e);if(!r)throw new Error(`Invalid Harness memory target: ${s}.`);return r[1]}w(fe,"memoryKeyFromTarget");async function te(s){let e=await s.store.getHarnessWorkspace(s.workspaceId);if(!e)throw new Error(`Harness workspace ${s.workspaceId} does not exist.`);let r=D(s.storeDir,e.id),t=R.join(r.root,"source-swap.json"),n=await h.readFile(t,"utf8").then(JSON.parse).catch(l=>{if(l.code==="ENOENT")return null;throw l});if(!n)return"none";let o=await I({workspaceId:e.id,sourceDir:r.source});if(e.sourceRevision===n.nextSourceRevision&&o.sourceRevision===n.nextSourceRevision)return await h.rm(n.backupSource,{recursive:!0,force:!0}),await h.rm(t,{force:!0}),"completed";let i=await I({workspaceId:e.id,sourceDir:n.backupSource});if(e.sourceRevision===n.previousSourceRevision&&i.sourceRevision===n.previousSourceRevision)return await j(r.source,n.backupSource),await h.rm(t,{force:!0}),"restored";throw new Error("Harness source-swap recovery cannot reconcile filesystem and workspace revisions.")}w(te,"recoverLocalHarnessSourceSwap");async function ae(s,e){for(let r of e.edits){let t=oe(s,r.target);if(r.operation==="delete"){await h.rm(t,{force:!1});continue}if(r.content===null)throw new Error(`Refiner edit ${r.id} has no content.`);if(r.operation==="create")await h.mkdir(R.dirname(t),{recursive:!0}),await h.writeFile(t,r.content,{flag:"wx"});else{let n=await h.lstat(t);if(!n.isFile()||n.isSymbolicLink())throw new Error(`Refiner update target must be a regular file: ${r.target}`);await h.writeFile(t,r.content,{flag:"w"})}}}w(ae,"applyOverlayEdits");function oe(s,e){let r=R.resolve(s),t=R.resolve(r,...e.replaceAll("\\","/").split("/")),n=R.relative(r,t);if(!n||n.startsWith("..")||R.isAbsolute(n))throw new Error(`Refiner edit target escapes the Harness source: ${e}`);return t}w(oe,"containedPath");async function ne(s,e){let r=`${s}.${O()}.tmp`;await h.writeFile(r,`${JSON.stringify(e,null,2)}
|
|
3
3
|
`,{flag:"wx"}),await h.rename(r,s)}w(ne,"writeSwapJournal");async function j(s,e){await h.rm(s,{recursive:!0,force:!0}),await h.rename(e,s)}w(j,"restoreSource");var b="desktop-personal",ie="personal-default";async function qe(s){let e=await s.store.getSelectedHarnessWorkspace({ownerKind:"personal",ownerId:b});if(e&&e.metadata.selectionEligible!==!1)return await te({store:s.store,storeDir:s.storeDir,workspaceId:e.id}),M(s.store,e.id,e.currentChannel.release?.contentHash??null);let r=(await s.store.listHarnessWorkspaces({ownerKind:"personal",ownerId:b})).find(o=>o.metadata.selectionEligible!==!1);if(r)return await s.store.selectHarnessWorkspace({ownerKind:"personal",ownerId:b,workspaceId:r.id,updatedAt:(s.now??(()=>new Date().toISOString()))()}),M(s.store,r.id,r.currentChannel.release?.contentHash??null);let t=await s.loadProfileState(),n=t.mode==="local"&&t.sourcePath&&!t.error?await ee({store:s.store,storeDir:s.storeDir,id:ie,ownerId:b,name:t.activeProfile?.trim()||"Personal Harness",profile:t,now:s.now}):await Z({store:s.store,storeDir:s.storeDir,id:ie,ownerId:b,name:"Personal Harness",now:s.now});return await s.store.selectHarnessWorkspace({ownerKind:"personal",ownerId:b,workspaceId:n.workspace.id,updatedAt:(s.now??(()=>new Date().toISOString()))()}),n.release}w(qe,"ensureSelectedLocalHarnessWorkspace");async function ce(s){let e=await s.getSelectedHarnessWorkspace({ownerKind:"personal",ownerId:b});return e?M(s,e.id,e.currentChannel.release?.contentHash??null):null}w(ce,"resolveSelectedLocalHarnessRelease");async function M(s,e,r){if(!r)throw new Error(`Selected Harness workspace ${e} has no current release.`);let t=await s.getHarnessReleaseRecord(r);if(!t||t.workspaceId!==e)throw new Error(`Selected Harness workspace ${e} points to a missing release ${r}.`);return A(t.agentSnapshot,"Selected Agent snapshot"),A(t.harnessRelease,"Selected Harness release"),t}w(M,"requireCurrentRelease");async function Ke(s,e){if(e){let n=await s.getHarnessReleaseRecord(e.contentHash);if(!n||n.harnessRelease.id!==e.id)throw new Error("The selected immutable Harness release is unavailable.");let o=await s.getHarnessWorkspace(n.workspaceId);if(!o||o.ownerScope.kind!=="personal"||o.ownerScope.id!==b)throw new Error("The selected Harness release is not available to this local owner.");return A(n.agentSnapshot,"Selected Agent snapshot"),A(n.harnessRelease,"Selected Harness release"),T({workspace:o,release:n})}let r=await ce(s);if(!r)return null;let t=await s.getSelectedHarnessWorkspace({ownerKind:"personal",ownerId:b});if(!t||t.id!==r.workspaceId)throw new Error("Selected Harness workspace changed while its release was being admitted.");return T({workspace:t,release:r})}w(Ke,"loadSelectedLocalHarnessRuntime");async function T(s){let{workspace:e,release:r}=s;if(r.workspaceId!==e.id)throw new Error("Harness release does not belong to the requested workspace.");let t=y.join(r.bundlePath,"source");await Promise.all(r.harnessRelease.files.map(a=>ve(t,a.path,a.contentHash)));let n=await Promise.all(r.agentSnapshot.instructions.map(async a=>({path:a.path,content:await z(t,a.path,a.contentHash)}))),o=[],i=new Map;for(let a of r.agentSnapshot.skills){let v=await z(t,a.path,a.contentHash),m=W(v);if(!m.name||!m.description||m.messages.length>0)throw new Error(`Released Harness Skill ${a.path} is invalid: ${m.messages.join(" ")||"missing name or description"}`);if(i.has(m.name))throw new Error(`Released Harness has duplicate Skill ${m.name}.`);let p=`${y.posix.dirname(a.path)}/`,c=r.harnessRelease.files.filter(k=>k.path.startsWith(p)&&k.path!==a.path).map(k=>k.path.slice(p.length)).sort(),g={name:m.name,description:m.description,path:a.path,scope:"profile",enabled:!0,sourcePath:t,charCount:v.length,sourceHash:a.contentHash,validationStatus:"valid",validationMessages:[],resourceFiles:c};o.push(g),i.set(g.name,async()=>{let k=await z(t,a.path,a.contentHash),H=W(k);if(!H.name||!H.description||H.messages.length>0)throw new Error(`Released Harness Skill ${a.path} failed validation while loading.`);return{name:H.name,description:H.description,body:H.body,path:a.path,sourceHash:a.contentHash,charCount:k.length,packagePath:y.join(t,...y.posix.dirname(a.path).split("/")),resourceFiles:c}})}o.sort((a,v)=>a.name.localeCompare(v.name));let l={profileSourcePath:t,skills:o,readSkill:i.size>0?async a=>{let v=i.get(a);if(!v)throw new Error(`Released Harness Skill not found: ${a}`);return v()}:null},d=n.sort((a,v)=>a.path.localeCompare(v.path)).map(({path:a,content:v})=>[`Active Harness instruction (${a}):`,v.trim()].join(`
|
|
4
4
|
`)).filter(a=>a.trim().length>0),f=[["Harness capability receipt:",JSON.stringify({harnessRelease:{id:r.harnessRelease.id,contentHash:r.harnessRelease.contentHash},agentSnapshot:{id:r.agentSnapshot.id,contentHash:r.agentSnapshot.contentHash},files:r.harnessRelease.files.map(a=>({path:a.path,contentHash:a.contentHash})),skills:r.agentSnapshot.skills.map(a=>a.path),agents:r.agentSnapshot.agents.map(a=>a.path),tools:r.agentSnapshot.toolDeclarations.map(a=>a.name),capabilityRequirements:r.agentSnapshot.capabilityRequirements})].join(`
|
|
5
5
|
`),d.length>0?["Active Harness preflight:","Apply the following released instructions when planning work and immediately before every tool call.","Preflight each call: (1) identify any active instruction that matches the planned operation, (2) inspect the exact tool arguments for a forbidden pattern, and (3) rewrite the call before sending it when a pattern matches. Compliance is required even when the prohibited call might still succeed.",...d].join(`
|