@popmelt.com/core 0.24.1 → 0.24.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/claude-plugin/.claude-plugin/plugin.json +1 -1
- package/codex-plugin/.codex-plugin/plugin.json +1 -1
- package/dist/{ParticipantRuntime-SS2IDRLA.mjs → ParticipantRuntime-6QPULJPO.mjs} +1 -1
- package/dist/bridge-entry.mjs +1 -1
- package/dist/{browser-runtime-HYKTQV6Q.mjs → browser-runtime-3UZPA2SA.mjs} +1 -1
- package/dist/browser.mjs +1 -1
- package/dist/{chunk-7W3RBRFM.mjs → chunk-D4ZJC7OV.mjs} +17 -17
- package/dist/{chunk-3MO7Z4DV.mjs → chunk-NV55QGKG.mjs} +1 -1
- package/dist/{chunk-4WAFUF5Y.mjs → chunk-TJVWZRAF.mjs} +1 -1
- package/dist/{chunk-B5KUI32Q.mjs → chunk-ZL4X7KBW.mjs} +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/plugin-astro.mjs +1 -1
- package/dist/plugin-nuxt.mjs +1 -1
- package/dist/plugin-vite.mjs +1 -1
- package/dist/{server-OPX7SKA7.mjs → server-M6OXW7FE.mjs} +1 -1
- package/dist/server.mjs +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
export{b as PopmeltProvider}from"./chunk-
|
|
2
|
+
export{b as PopmeltProvider}from"./chunk-D4ZJC7OV.mjs";export{a as isPopmeltPreview}from"./chunk-EX63NVDN.mjs";import"./chunk-N2ZEZCHO.mjs";export{b as usePopmelt}from"./chunk-J3UIBBU2.mjs";import"./chunk-ZL4X7KBW.mjs";import"./chunk-ENERPQJN.mjs";
|
package/dist/plugin-astro.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as o}from"./chunk-
|
|
1
|
+
import{a as o}from"./chunk-NV55QGKG.mjs";import"./chunk-TJVWZRAF.mjs";import"./chunk-NOHXTT24.mjs";import{fileURLToPath as d}from"url";function c(t={}){return{name:"popmelt",hooks:{"astro:config:setup"({command:r,config:i,updateConfig:n,injectScript:p}){if(r!=="dev")return;let{client:e=!0,multiplayer:a=!1,...s}=t;n({vite:{plugins:[o({...s,projectRoot:t.projectRoot??d(i.root)})],optimizeDeps:{include:e?["react","react/jsx-runtime","react/jsx-dev-runtime","react-dom","react-dom/client","lucide-react"]:[]}}}),p("page",e?l(a):`
|
|
2
2
|
import { bridgeUrl, projectId } from 'virtual:popmelt/bridge';
|
|
3
3
|
if (bridgeUrl) window.__POPMELT_BRIDGE_URL__ = bridgeUrl;
|
|
4
4
|
if (projectId) window.__POPMELT_PROJECT_ID__ = projectId;
|
package/dist/plugin-nuxt.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as s,b as l}from"./chunk-
|
|
1
|
+
import{a as s,b as l}from"./chunk-TJVWZRAF.mjs";import{b as i}from"./chunk-NOHXTT24.mjs";import{addPluginTemplate as d,defineNuxtModule as m}from"nuxt/kit";var a=m({meta:{name:"@popmelt.com/core/nuxt",configKey:"popmelt"},async setup(o,e){if(!e.options.dev)return;let n={config:{server:e.options.devServer},middlewares:{use(){}}},t=await s({...o,projectRoot:o.projectRoot??e.options.rootDir},n,3e3);if(t.port===null)return;e.hook("vite:extend",({config:p})=>{p.optimizeDeps??={},p.optimizeDeps.include=[...new Set([...p.optimizeDeps.include??[],"react","react/jsx-runtime","react/jsx-dev-runtime","react-dom","react-dom/client","lucide-react"])]});let r=await l(t,n),u=r?i(r):void 0;e.hook("close",async()=>{u?.(),await r?.release()}),d({filename:"popmelt.client.mjs",mode:"client",getContents:()=>`import { defineNuxtPlugin } from '#app';
|
|
2
2
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
3
3
|
let disposed = false;
|
|
4
4
|
let mounting;
|
package/dist/plugin-vite.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-NV55QGKG.mjs";import"./chunk-TJVWZRAF.mjs";import"./chunk-NOHXTT24.mjs";export{a as popmelt};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as na,b as ra}from"./chunk-NOHXTT24.mjs";import{spawn as fy}from"child_process";import{closeSync as hy,openSync as gy}from"fs";import{appendFile as yy,mkdir as wy,readFile as Iy,realpath as vy}from"fs/promises";import{dirname as by,join as Ks}from"path";import{fileURLToPath as xy}from"url";function fn(r){return Ul(r).slice(0,12)}var Bl=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function Ul(r){let e=typeof TextEncoder<"u"?Array.from(new TextEncoder().encode(r)):zl(r),t=e.length*8;for(e.push(128);e.length%64!==56;)e.push(0);for(let g=7;g>=0;g--)e.push(t/Math.pow(2,g*8)&255);let n=1779033703,i=3144134277,o=1013904242,s=2773480762,a=1359893119,c=2600822924,d=528734635,p=1541459225,f=new Array(64);for(let g=0;g<e.length;g+=64){for(let b=0;b<16;b++){let I=g+b*4;f[b]=(e[I]<<24|e[I+1]<<16|e[I+2]<<8|e[I+3])>>>0}for(let b=16;b<64;b++){let I=xt(f[b-15],7)^xt(f[b-15],18)^f[b-15]>>>3,R=xt(f[b-2],17)^xt(f[b-2],19)^f[b-2]>>>10;f[b]=f[b-16]+I+f[b-7]+R>>>0}let v=n,w=i,u=o,m=s,x=a,y=c,h=d,k=p;for(let b=0;b<64;b++){let I=xt(x,6)^xt(x,11)^xt(x,25),R=x&y^~x&h,D=k+I+R+Bl[b]+f[b]>>>0,N=xt(v,2)^xt(v,13)^xt(v,22),G=v&w^v&u^w&u,re=N+G>>>0;k=h,h=y,y=x,x=m+D>>>0,m=u,u=w,w=v,v=D+re>>>0}n=n+v>>>0,i=i+w>>>0,o=o+u>>>0,s=s+m>>>0,a=a+x>>>0,c=c+y>>>0,d=d+h>>>0,p=p+k>>>0}return[n,i,o,s,a,c,d,p].map(g=>g.toString(16).padStart(8,"0")).join("")}function xt(r,e){return r>>>e|r<<32-e}function zl(r){let e=[];for(let t=0;t<r.length;t++){let n=r.charCodeAt(t);n<128?e.push(n):n<2048?e.push(192|n>>6,128|n&63):e.push(224|n>>12,128|n>>6&63,128|n&63)}return e}var ia={name:"@popmelt.com/core",version:"0.24.
|
|
1
|
+
import{a as na,b as ra}from"./chunk-NOHXTT24.mjs";import{spawn as fy}from"child_process";import{closeSync as hy,openSync as gy}from"fs";import{appendFile as yy,mkdir as wy,readFile as Iy,realpath as vy}from"fs/promises";import{dirname as by,join as Ks}from"path";import{fileURLToPath as xy}from"url";function fn(r){return Ul(r).slice(0,12)}var Bl=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function Ul(r){let e=typeof TextEncoder<"u"?Array.from(new TextEncoder().encode(r)):zl(r),t=e.length*8;for(e.push(128);e.length%64!==56;)e.push(0);for(let g=7;g>=0;g--)e.push(t/Math.pow(2,g*8)&255);let n=1779033703,i=3144134277,o=1013904242,s=2773480762,a=1359893119,c=2600822924,d=528734635,p=1541459225,f=new Array(64);for(let g=0;g<e.length;g+=64){for(let b=0;b<16;b++){let I=g+b*4;f[b]=(e[I]<<24|e[I+1]<<16|e[I+2]<<8|e[I+3])>>>0}for(let b=16;b<64;b++){let I=xt(f[b-15],7)^xt(f[b-15],18)^f[b-15]>>>3,R=xt(f[b-2],17)^xt(f[b-2],19)^f[b-2]>>>10;f[b]=f[b-16]+I+f[b-7]+R>>>0}let v=n,w=i,u=o,m=s,x=a,y=c,h=d,k=p;for(let b=0;b<64;b++){let I=xt(x,6)^xt(x,11)^xt(x,25),R=x&y^~x&h,D=k+I+R+Bl[b]+f[b]>>>0,N=xt(v,2)^xt(v,13)^xt(v,22),G=v&w^v&u^w&u,re=N+G>>>0;k=h,h=y,y=x,x=m+D>>>0,m=u,u=w,w=v,v=D+re>>>0}n=n+v>>>0,i=i+w>>>0,o=o+u>>>0,s=s+m>>>0,a=a+x>>>0,c=c+y>>>0,d=d+h>>>0,p=p+k>>>0}return[n,i,o,s,a,c,d,p].map(g=>g.toString(16).padStart(8,"0")).join("")}function xt(r,e){return r>>>e|r<<32-e}function zl(r){let e=[];for(let t=0;t<r.length;t++){let n=r.charCodeAt(t);n<128?e.push(n):n<2048?e.push(192|n>>6,128|n&63):e.push(224|n>>12,128|n>>6&63,128|n&63)}return e}var ia={name:"@popmelt.com/core",version:"0.24.2",description:"A tiny, powerful design layer for humans and AI",license:"PolyForm-Shield-1.0.0",author:"Popmelt <reb@popmelt.com> (https://popmelt.com)",homepage:"https://github.com/popmelt/core",bugs:{url:"https://github.com/popmelt/core/issues"},repository:{type:"git",url:"git+https://github.com/popmelt/core.git"},keywords:["ai","annotations","collaboration","devtools","react","visual-feedback"],bin:{popmelt:"dist/cli.mjs"},sideEffects:!1,packageManager:"pnpm@9.12.0",engines:{node:">=18.0.0"},scripts:{build:"tsup",clean:"git clean -xdf .turbo node_modules dist",format:'prettier --check "**/*.{ts,tsx}"',lint:"eslint . && node scripts/check-eslint-suppressions.mjs","pack:smoke":"node scripts/pack-smoke.mjs","peer:smoke":"node scripts/peer-compat-smoke.mjs","vue:smoke":"pnpm run build && node scripts/vue-install-smoke.mjs","nuxt:smoke":"pnpm run build && node scripts/nuxt-install-smoke.mjs","astro:smoke":"pnpm run build && node scripts/framework-install-smoke.mjs astro","svelte:smoke":"pnpm run build && node scripts/framework-install-smoke.mjs svelte && node scripts/framework-install-smoke.mjs sveltekit",prepublishOnly:"pnpm run verify",test:"vitest run","test:coverage":"vitest run --coverage.enabled","test:browser":"pnpm run build && tsc --noEmit -p tsconfig.browser.json && vitest run --config vitest.browser.config.ts","test:browser:mutation":"node e2e/check-lifecycle-mutation.mjs","test:watch":"vitest",typecheck:"tsc --noEmit --incremental false",verify:"pnpm run typecheck && pnpm run format && pnpm run lint && pnpm run test:coverage && pnpm run build && pnpm run pack:smoke"},exports:{".":{types:"./dist/index.d.mts",import:"./dist/index.mjs"},"./provider":{types:"./dist/index.d.mts",import:"./dist/index.mjs"},"./browser":{types:"./dist/browser.d.mts",import:"./dist/browser.mjs"},"./server":{types:"./dist/server.d.mts",import:"./dist/server.mjs"},"./memory":{types:"./dist/memory.d.mts",import:"./dist/memory.mjs"},"./memory/legacy":{types:"./dist/memory-legacy.d.mts",import:"./dist/memory-legacy.mjs"},"./memory/store":{types:"./dist/memory-store.d.mts",import:"./dist/memory-store.mjs"},"./next":{types:"./dist/plugin-next.d.mts",import:"./dist/plugin-next.mjs",default:"./dist/plugin-next.mjs"},"./vite":{types:"./dist/plugin-vite.d.mts",import:"./dist/plugin-vite.mjs",default:"./dist/plugin-vite.mjs"},"./vite/client":{types:"./dist/vite-client.d.ts"},"./astro":{types:"./dist/plugin-astro.d.mts",import:"./dist/plugin-astro.mjs",default:"./dist/plugin-astro.mjs"},"./nuxt":{types:"./dist/plugin-nuxt.d.mts",import:"./dist/plugin-nuxt.mjs",default:"./dist/plugin-nuxt.mjs"},"./media":{types:"./dist/media.d.mts",import:"./dist/media.mjs"},"./three":{types:"./dist/adapter-three.d.mts",import:"./dist/adapter-three.mjs"},"./react-three-fiber":{types:"./dist/adapter-react-three-fiber.d.mts",import:"./dist/adapter-react-three-fiber.mjs"}},files:["dist","codex-plugin","claude-plugin","LICENSE","README.md","THIRD_PARTY_NOTICES.md"],dependencies:{"modern-screenshot":"4.7.0",ws:"8.21.3"},peerDependencies:{nuxt:">=4.5.2 <5","lucide-react":">=1.23.0",next:">=14.0.0",react:">=18.0.0","react-dom":">=18.0.0","@react-three/fiber":">=8.0.0",three:">=0.150.0"},peerDependenciesMeta:{nuxt:{optional:!0},next:{optional:!0},"@react-three/fiber":{optional:!0},three:{optional:!0}},devDependencies:{nuxt:"4.5.2","@kit/eslint-config":"workspace:^","@react-three/fiber":"9.7.0","@tanstack/react-router":"1.120.5","@types/react":"19.1.0","@types/react-dom":"19.1.2","@types/three":"^0.185.4","@types/ws":"8.18.1","@vitejs/plugin-react":"^5.1.1","@vitejs/plugin-vue":"6.0.8","@vitest/coverage-v8":"3.2.4",eslint:"^9.24.0",geist:"1.7.2",jsdom:"26.1.0","lucide-react":"^1.23.0",next:"15.5.24",prettier:"3.5.3",react:"19.1.0","react-dom":"19.1.0",three:"^0.185.1",tsup:"^8.5.1",typescript:"^5.8.3",vite:"7.3.6",vitest:"3.2.4",vue:"3.5.42","vue-router":"5.3.1"}};var St=ia.version;import{execFileSync as Ag,spawn as sl}from"child_process";import{randomUUID as jt}from"crypto";function Gr(r){return[...r.matchAll(/<resolution>\s*([\s\S]*?)(?:<\/resolution>|$)/g)].at(-1)?.[1]?.trim()}function Vr(r){return r.replace(/<resolution>[\s\S]*?(?:<\/resolution>|$)/g,"")}function go(r,e){return{storeId:r,explanationId:e}}function Gl(r,e){let{fromId:t,toId:n,toStoreId:i,...o}=e;return{...o,from:go(r,t),to:go(i??r,n)}}var oa={project:0,route:1,component:2,selector:2,file:3},sa={intention:0,principle:1,pattern:2};function hn(r,e){let t=oa[r.scope.kind]-oa[e.scope.kind];return t!==0?t:sa[r.kind]-sa[e.kind]}function aa(r){return r==="expresses"||r==="excepts"}function Vl(r,e){if(e.type==="expresses"||e.type==="excepts")return structuredClone(e);if(e.type==="operationalizes")return{...structuredClone(e),type:"expresses"};if(e.type==="instantiates")return{...structuredClone(e),type:"expresses",fromId:e.toId,toId:e.fromId};if(e.type==="refines"){let t=r.explanations.find(o=>o.id===e.fromId),n=r.explanations.find(o=>o.id===e.toId);if(!t||!n)return;let i=hn(t,n);return i===0?void 0:i>0?{...structuredClone(e),type:"expresses"}:{...structuredClone(e),type:"expresses",fromId:e.toId,toId:e.fromId}}}function Qt(r){let e=structuredClone(r),t=new Set;return e.relations=r.relations.flatMap(n=>{let i=Vl(r,n);if(!i)return[];let o=`${i.type}:${i.fromId}:${i.toStoreId??""}:${i.toId}`;return t.has(o)?[]:(t.add(o),[i])}),e}import{createHash as Wl}from"crypto";import{mkdir as Kl,open as Ql,readFile as ca,readdir as Xl,rename as Yl,unlink as Zl}from"fs/promises";import{dirname as ep,join as gn}from"path";function ot(r){return structuredClone(r)}function da(r){return Wl("sha256").update(JSON.stringify(r)).digest("hex")}async function Xt(r,e){await Kl(ep(r),{recursive:!0});let t=`${r}.${process.pid}.${Date.now()}.tmp`,n=await Ql(t,"w");try{await n.writeFile(`${JSON.stringify(e,null,2)}
|
|
2
2
|
`,"utf8"),await n.sync()}finally{await n.close()}try{await Yl(t,r)}catch(i){throw await Zl(t).catch(()=>{}),i}}function tp(r,e){return{version:1,projectId:r,createdAt:e,updatedAt:e,head:{sequence:0,hash:null},explanations:[],concrete:[],relations:[]}}function np(r,e){let t=r.explanations.findIndex(n=>n.id===e.id);t>=0?r.explanations[t]=ot(e):r.explanations.push(ot(e))}function Wr(r,e){let t=ot(r);for(let n of e)if(n.op==="add_explanation"){if(t.explanations.some(i=>i.id===n.explanation.id))throw new Error(`Imprint explanation already exists: ${n.explanation.id}`);t.explanations.push(ot(n.explanation))}else if(n.op==="replace_explanation")np(t,n.explanation);else if(n.op==="remove_explanation")t.explanations=t.explanations.filter(i=>i.id!==n.explanationId),t.relations=t.relations.filter(i=>i.fromId!==n.explanationId&&(i.toStoreId!==void 0||i.toId!==n.explanationId));else if(n.op==="add_concrete")t.concrete.some(i=>i.id===n.concrete.id)||t.concrete.push(ot(n.concrete));else if(n.op==="remove_concrete")t.concrete=t.concrete.filter(i=>i.id!==n.concreteId),t.relations=t.relations.filter(i=>i.fromId!==n.concreteId&&(i.toStoreId!==void 0||i.toId!==n.concreteId));else if(n.op==="add_evidence"){let i=t.explanations.find(o=>o.id===n.explanationId);if(!i)throw new Error(`Unknown imprint explanation: ${n.explanationId}`);i.evidence.some(o=>o.id===n.evidence.id)||(i.evidence.push(ot(n.evidence)),i.updatedAt=n.evidence.createdAt)}else if(n.op==="revise_explanation"){let i=t.explanations.find(o=>o.id===n.explanationId);if(!i)throw new Error(`Unknown imprint explanation: ${n.explanationId}`);Object.assign(i,ot(n.patch),{updatedAt:n.updatedAt})}else if(n.op==="add_relation"){let i=n.relation,o=t.explanations.find(p=>p.id===i.fromId),s=!!i.toStoreId,a=s?void 0:t.explanations.find(p=>p.id===i.toId),c=t.concrete.some(p=>p.id===i.fromId),d=!s&&t.concrete.some(p=>p.id===i.toId);if(aa(i.type)){if(!(i.type==="expresses"?s?!!o:!!((o||c)&&a):!!(o&&(a||s))))throw new Error(`Imprint ${i.type} relation has invalid endpoints: ${i.id}`);if(t.relations.some(f=>f.type===i.type&&f.fromId===i.fromId&&f.toStoreId===i.toStoreId&&f.toId===i.toId))throw new Error(`Duplicate imprint relation: ${i.type}:${i.fromId}:${i.toStoreId??""}:${i.toId}`);if(i.type==="expresses"&&o&&a){if(hn(o,a)<0)throw new Error(`Imprint expresses relation must point from specific to abstract: ${i.id}`);let f=new Map;for(let w of t.relations)w.type!=="expresses"||w.toStoreId||f.set(w.fromId,[...f.get(w.fromId)??[],w.toId]);let g=[i.toId],v=new Set;for(;g.length;){let w=g.pop();if(w===i.fromId)throw new Error(`Imprint expresses relation would create a cycle: ${i.id}`);v.has(w)||(v.add(w),g.push(...f.get(w)??[]))}}}else if(!o||!a&&!d)throw new Error(`Imprint relation references an unknown explanation: ${i.id}`);t.relations.some(p=>p.id===i.id)||t.relations.push(ot(i))}else n.op==="remove_relation"&&(t.relations=t.relations.filter(i=>i.id!==n.relationId));return t}function rp(r,e){let t=[],n=ot(r);for(let i of e){if(i.op==="add_explanation")t.unshift({op:"remove_explanation",explanationId:i.explanation.id});else if(i.op==="remove_explanation"){let o=n.explanations.find(s=>s.id===i.explanationId);o&&t.unshift({op:"add_explanation",explanation:ot(o)})}else if(i.op==="add_concrete")t.unshift({op:"remove_concrete",concreteId:i.concrete.id});else if(i.op==="remove_concrete"){let o=n.concrete.find(s=>s.id===i.concreteId);o&&t.unshift({op:"add_concrete",concrete:ot(o)})}else if(i.op==="replace_explanation"||i.op==="revise_explanation"||i.op==="add_evidence"){let o=i.op==="replace_explanation"?i.explanation.id:i.explanationId,s=n.explanations.find(a=>a.id===o);s&&t.unshift({op:"replace_explanation",explanation:ot(s)})}else if(i.op==="add_relation")t.unshift({op:"remove_relation",relationId:i.relation.id});else if(i.op==="remove_relation"){let o=n.relations.find(s=>s.id===i.relationId);o&&t.unshift({op:"add_relation",relation:ot(o)})}n=Wr(n,[i])}return t}function la(r){return r.op==="add_explanation"||r.op==="replace_explanation"?[r.explanation.id]:r.op==="remove_explanation"||r.op==="add_evidence"||r.op==="revise_explanation"?[r.explanationId]:r.op==="add_relation"?[r.relation.fromId,...r.relation.toStoreId?[]:[r.relation.toId]]:[]}var yn=class{constructor(e,t){this.projectRoot=e;this.projectId=t;this.writeChain=Promise.resolve();this.imprintDir=gn(e,".popmelt","imprint"),this.manifestPath=gn(this.imprintDir,"manifest.json"),this.graphPath=gn(this.imprintDir,"graph.json"),this.journalDir=gn(this.imprintDir,"journal")}async readHead(){return(await this.readManifest()).head}async readManifest(){try{let e=JSON.parse(await ca(this.manifestPath,"utf8"));if(e.version!==1||e.projectId!==this.projectId)throw new Error("Imprint manifest does not match this project.");return e}catch(e){if(e.code!=="ENOENT")throw e;let t=new Date().toISOString();return{version:1,projectId:this.projectId,createdAt:t,updatedAt:t,head:{sequence:0,hash:null}}}}async loadRaw(){let e=await this.readManifest(),n=(await Xl(this.journalDir).catch(a=>{if(a.code==="ENOENT")return[];throw a})).filter(a=>/^\d{12}-.+\.json$/.test(a)).sort(),i=tp(this.projectId,e.createdAt),o=[],s=null;for(let a=0;a<n.length;a++){let c=JSON.parse(await ca(gn(this.journalDir,n[a]),"utf8")),{hash:d,...p}=c;if(c.sequence!==a+1||c.previousHash!==s||d!==da(p))throw new Error(`Imprint journal hash mismatch at sequence ${c.sequence}.`);i=Wr(i,c.mutations),i.updatedAt=c.committedAt,i.head={sequence:c.sequence,hash:c.hash},o.push(c),s=c.hash}return{graph:i,transactions:o,recoveredTransactions:Math.max(0,o.length-e.head.sequence)}}async load(){let e=await this.loadRaw();return{...e,graph:Qt(e.graph)}}async migrateTopology(){let e=await this.readManifest();if(e.topologyVersion===2)return{migrated:!1,relationMutations:0};let t=await this.loadRaw(),n=Qt(t.graph),i=new Map(n.relations.map(s=>[s.id,s])),o=[];for(let s of t.graph.relations){let a=i.get(s.id);a&&a.type===s.type&&a.fromId===s.fromId&&a.toStoreId===s.toStoreId&&a.toId===s.toId||(o.push({op:"remove_relation",relationId:s.id}),a&&o.push({op:"add_relation",relation:a}))}if(o.length){let s=new Date().toISOString();return await this.commit({transactionId:`topology-v2-${t.graph.head.sequence+1}`,committedAt:s,source:{kind:"migration",threadId:"imprint-topology",jobId:"imprint-topology-v2"},summary:"Simplify Imprint topology to expresses and excepts",mutations:o}),{migrated:!0,relationMutations:o.length}}return await Xt(this.graphPath,n),await Xt(this.manifestPath,{...e,topologyVersion:2}),{migrated:!0,relationMutations:0}}async commit(e){let t;return this.writeChain=this.writeChain.then(async()=>{let n=await this.load();if(n.transactions.some(f=>f.transactionId===e.transactionId))throw new Error(`Imprint transaction already exists: ${e.transactionId}`);let i=n.graph.head.sequence+1,o=rp(n.graph,e.mutations),s={version:1,sequence:i,transactionId:e.transactionId,projectId:this.projectId,committedAt:e.committedAt,previousHash:n.graph.head.hash,source:e.source,summary:e.summary,mutations:ot(e.mutations),inverseMutations:o,...e.undoesTransactionId?{undoesTransactionId:e.undoesTransactionId}:{}},a={...s,hash:da(s)},c=Wr(n.graph,a.mutations);c.updatedAt=e.committedAt,c.head={sequence:i,hash:a.hash};let d=`${String(i).padStart(12,"0")}-${e.transactionId}.json`;await Xt(gn(this.journalDir,d),a);let p={version:1,topologyVersion:2,projectId:this.projectId,createdAt:c.createdAt,updatedAt:e.committedAt,head:c.head};await Xt(this.graphPath,c),await Xt(this.manifestPath,p),t={graph:c,transaction:a}}),await this.writeChain,t}async undo(e,t,n,i){let o=await this.load(),s=o.transactions.find(d=>d.transactionId===e);if(!s)throw new Error("The imprint update is no longer available to undo.");if(o.transactions.some(d=>d.undoesTransactionId===e))throw new Error("This imprint update has already been undone.");let a=new Set(s.mutations.flatMap(la));if(o.transactions.filter(d=>d.sequence>s.sequence).some(d=>d.mutations.some(p=>la(p).some(f=>a.has(f)))))throw new Error("This imprint update has newer dependent changes and cannot be undone cleanly. Edit or challenge the current explanation instead.");return this.commit({transactionId:i,committedAt:n,source:t,summary:`Undo: ${s.summary}`,mutations:s.inverseMutations,undoesTransactionId:e})}async recover(){let e=await this.load();return await Xt(this.graphPath,e.graph),await Xt(this.manifestPath,{version:1,topologyVersion:2,projectId:this.projectId,createdAt:e.graph.createdAt,updatedAt:e.graph.updatedAt,head:e.graph.head}),{...e,recoveredTransactions:0}}};var ip=new Set(["application_only","transient_state","concrete_without_model_path","duplicate","insufficient_evidence","task_specific_detail","no_shared_understanding_change"]),op=new Set(["about","after","again","before","being","change","from","have","into","make","should","that","the","their","this","with","would","here","only","consistent","match","matched","matching","mirror","mirrored","mirroring","align","aligned","aligning"]),sp=[/\bconsistent\s+with\b/i,/\bmatch(?:es|ed|ing)?\b/i,/\bmirror(?:s|ed|ing)?\b/i,/\bthe\s+same\s+as\b/i,/\bborrow(?:s|ed|ing)?\s+from\b/i,/\balign(?:s|ed|ing)?\s+with\b/i,/\b(?:more|look|looks|feel|feels|behave|behaves)\s+like\b/i],ap=/\b(all|any|every|everywhere|across|throughout|globally|project[- ]wide)\b/i;function wo(r){return!!(r&&ap.test(r))}function cp(r){return r.scope.kind==="project"||wo(`${r.statement} ${r.rationale}`)}function dp(r){let e=r?.scope.values.filter(t=>t!=="*").join(", ");return e?`Does applying this understanding here match your intent for ${e}?`:"Does applying this understanding here match your intent?"}function lp(r){return r.replace(/([a-z0-9])([A-Z])/g,"$1 $2").toLowerCase().replace(/[^a-z0-9]+/g," ").trim().replace(/\s+/g," ")}function pp(r){return r.length>4&&r.endsWith("ies")?[r,`${r.slice(0,-3)}y`]:r.length>3&&r.endsWith("s")&&!r.endsWith("ss")?[r,r.slice(0,-1)]:[r]}function Mt(r){return new Set(lp(r).split(" ").filter(e=>e.length>2&&!op.has(e)).flatMap(pp))}function pa(r){return r.replace(/^\s*(?:please\s+)?(?:let(?:'|’)s\s+)?(?:make|apply|use|keep|change|update)\s+/i,"").replace(/[\s,.:;!?]+$/g,"").trim().slice(0,240)}function up(r){if(r)for(let e of sp){let t=e.exec(r);if(!t||t.index<=0)continue;let n=pa(r.slice(0,t.index)),i=pa(r.slice(t.index+t[0].length));if(n&&i)return{target:n,reference:i}}}function Lt(r,e){if(!r.size||!e.size)return 0;let t=0;for(let n of r)e.has(n)&&(t+=1);return t/Math.min(r.size,e.size)}function yo(r){return!r||!Array.isArray(r.values)||r.values.length===0?{kind:"project",values:["*"]}:{kind:r.kind,values:[...new Set(r.values.map(e=>e.trim()).filter(Boolean))]}}function Jt(r,e,t){return{id:jt(),kind:e==="excepts"?"exception":e==="challenges"?"correction":"observation",stance:e,summary:t,threadId:r.threadId,jobId:r.jobId,createdAt:r.occurredAt??new Date().toISOString()}}function ke(r,e=800){return typeof r=="string"?r.trim().slice(0,e):""}function ua(r){if(!r||typeof r!="object"||Array.isArray(r))return;let e=r;if(!["project","route","component","selector","file"].includes(String(e.kind))||!Array.isArray(e.values))return;let t=e.values.filter(n=>typeof n=="string"&&!!n.trim());return t.length?{kind:e.kind,values:t}:void 0}function ma(r,e,t){if(r&&typeof r=="object"&&!Array.isArray(r)){let o=r,s=ke(o.explanationId,100),a=ke(o.clientId,100),c=ke(o.storeId,100);if(s&&a)throw new Error("relation endpoint must use either explanationId or clientId, not both");let d=s||a;return d?{explanationId:d,...c?{storeId:c}:{}}:void 0}let n=ke(e,100),i=ke(t,100);return n?{explanationId:n,...i?{storeId:i}:{}}:void 0}function fa(r,e){if(!r||!e.trim())return{found:!1};let t=r;for(let n of e.split(".").filter(Boolean))if(Array.isArray(t)){let i=Number(n);if(!Number.isInteger(i)||i<0||i>=t.length)return{found:!1};t=t[i]}else if(t&&typeof t=="object"&&Object.prototype.hasOwnProperty.call(t,n))t=t[n];else return{found:!1};return{found:!0,value:t}}function wn(r,e={}){let t=[...r.matchAll(/<imprint>([\s\S]*?)<\/imprint>/g)],n=Vr(r).replace(/<imprint>[\s\S]*?<\/imprint>/g,"").replace(/<imprint>[\s\S]*$/g,"").trim(),i=t.at(-1)?.[1],o,s=[];if(i)o=i;else{let a=Gr(r);if(a===void 0)return{visibleText:n,error:"imprint assessment is missing"};try{let c=JSON.parse(a);if(!c||typeof c!="object"||Array.isArray(c)||!Object.prototype.hasOwnProperty.call(c,"imprint"))return{visibleText:n,error:"imprint assessment is missing"};let d=c;o=d.imprint,s=Array.isArray(d.annotations)?d.annotations:[]}catch{return{visibleText:n,error:"resolution envelope is invalid"}}}try{let a=typeof o=="string"?JSON.parse(o):o;if(!a||typeof a!="object"||Array.isArray(a))throw new Error("imprint assessment is invalid");if(a.decision==="none"){let u=String(a.reason);if(!ip.has(u))throw new Error("imprint no-op reason is invalid");if(u==="task_specific_detail"&&s.some(R=>{if(!R||typeof R!="object"||Array.isArray(R))return!1;let D=R;return(D.finalScope??D.inferredScope)?.breadth==="pattern"}))throw new Error("pattern-scoped resolution cannot be classified as task_specific_detail");let m=Array.isArray(a.usedExplanationIds)?a.usedExplanationIds.filter(R=>typeof R=="string"&&!!R.trim()):[],x=Array.isArray(a.appliedExplanationIds)?a.appliedExplanationIds.filter(R=>typeof R=="string"&&!!R.trim()):[],y=new Set(e.context?.explanations.map(R=>R.id)??[]);if([...new Set([...m,...x])].some(R=>!y.has(R)))throw new Error("imprint use must cite only surfaced explanations");let k=[...new Set([...m,...e.applicationOccurred?[]:x])],b=e.applicationOccurred?x:[],I;if(b.length){I=b;let R=new Set(e.context?.pendingGroundingExplanationIds??[]),D=b.filter(N=>{let G=e.context?.explanations.find(re=>re.id===N);return y.has(N)&&G&&(G.state==="emerging"||G.state==="testing")&&!R.has(N)});if(D.length){let N=a.grounding,G=typeof N?.explanationId=="string"&&D.includes(N.explanationId)?N.explanationId:D[0],re=ke(N?.question,300);return{draft:{decision:"apply",summary:{title:ke(a.summary?.title,120)||"Applied shared understanding",detail:ke(a.summary?.detail,500)||ke(e.requestText||n,500)||"Applied an ungrounded explanation in a new context."},appliedExplanationIds:b,grounding:{explanationId:G,question:re||"Does applying this understanding here match your intent?"}},visibleText:n}}}if(u==="duplicate"){let R=ke(a.duplicateOfExplanationId,100),D=a.scopeComparison;if(!R)throw new Error("duplicate assessment requires duplicateOfExplanationId");if(D!=="equivalent"&&D!=="existing_broader")throw new Error("duplicate assessment requires an equivalent or existing_broader scopeComparison");let N=e.context?.explanations.find(G=>G.id===R);if(!N)throw new Error("duplicate assessment must cite a surfaced explanation");if(wo(e.requestText)&&!cp(N))throw new Error("duplicate explanation does not cover the requested broader scope");return{draft:{decision:"none",reason:u,duplicateOfExplanationId:R,scopeComparison:D,...k.length?{usedExplanationIds:k}:{},...I?{appliedExplanationIds:I}:{}},visibleText:n}}return{draft:{decision:"none",reason:u,...k.length?{usedExplanationIds:k}:{},...I?{appliedExplanationIds:I}:{}},visibleText:n}}if(a.decision==="recognize"){let u=ke(a.explanationId,100);if(!u)throw new Error("recognition requires explanationId");let m=e.context?.explanations.find(h=>h.id===u);if(!m)throw new Error("recognition must cite a surfaced explanation");if(m.state!=="grounded")throw new Error("recognition must cite a grounded explanation");let x=a.summary,y={title:ke(x?.title,120),detail:ke(x?.detail,500)};if(!y.title||!y.detail)throw new Error("recognition summary title and detail are required");return{draft:{decision:"recognize",explanationId:u,summary:y},visibleText:n}}if(a.decision==="apply"){let u=a.summary,m={title:ke(u?.title,120),detail:ke(u?.detail,500)};if(!m.title||!m.detail)throw new Error("application summary title and detail are required");let x=Array.isArray(a.appliedExplanationIds)?a.appliedExplanationIds.filter(R=>typeof R=="string"&&!!R.trim()):[];if(!x.length)throw new Error("application requires appliedExplanationIds");let y=new Map(e.context?.explanations.map(R=>[R.id,R])??[]);if(x.some(R=>!y.has(R)))throw new Error("application must cite only surfaced explanations");if(!e.applicationOccurred)return{draft:{decision:"none",reason:"application_only",usedExplanationIds:[...new Set(x)]},visibleText:n};let h=new Set(e.context?.pendingGroundingExplanationIds??[]),k=x.filter(R=>{let D=y.get(R);return D&&(D.state==="emerging"||D.state==="testing")&&!h.has(R)});if(!k.length){if(x.every(D=>y.get(D)?.state==="grounded"||h.has(D)))return{draft:{decision:"none",reason:"application_only",appliedExplanationIds:x},visibleText:n};throw new Error("application must cite a surfaced ungrounded explanation")}let b=a.grounding,I=typeof b?.explanationId=="string"&&k.includes(b.explanationId)?b.explanationId:k[0];return{draft:{decision:"apply",summary:m,appliedExplanationIds:x,grounding:{explanationId:I,question:ke(b?.question,300)||"Does applying this understanding here match your intent?"}},visibleText:n}}if(a.decision!==void 0&&a.decision!=="mutate")throw new Error("imprint decision is invalid");let c=a.summary,d=c?.kind;if(!["added","strengthened","refined","challenged","exception","consolidated"].includes(String(d)))throw new Error("summary.kind is invalid");let p={kind:d,title:ke(c?.title,120),detail:ke(c?.detail,500)};if(!p.title||!p.detail)throw new Error("summary title and detail are required");let f=Array.isArray(a.appliedExplanationIds)?a.appliedExplanationIds.filter(u=>typeof u=="string"&&!!u.trim()):[],g=[];for(let u of Array.isArray(a.mutations)?a.mutations:[]){if(!u||typeof u!="object")continue;let m=u;if(m.op==="add"&&["intention","principle","pattern"].includes(String(m.kind))){let x=ke(m.statement),y=ke(m.rationale);if(!x||!y)continue;g.push({op:"add",clientId:ke(m.clientId,100)||void 0,kind:m.kind,statement:x,rationale:y,scope:ua(m.scope),rootReason:ke(m.rootReason,300)||void 0})}else if(m.op==="revise"&&typeof m.explanationId=="string"){let x={op:"revise",explanationId:m.explanationId,statement:ke(m.statement)||void 0,rationale:ke(m.rationale)||void 0,scope:ua(m.scope),reopenGrounding:m.reopenGrounding===!0};(x.statement||x.rationale||x.scope||x.reopenGrounding)&&g.push(x)}else if(m.op==="evidence"&&typeof m.explanationId=="string"&&["supports","challenges","excepts"].includes(String(m.stance))){let x=ke(m.summary);x&&g.push({op:"evidence",explanationId:m.explanationId,stance:m.stance,summary:x})}else if(m.op==="relation"){if(!["expresses","excepts"].includes(String(m.type)))throw new Error("relation type is invalid");let x=ke(m.rationale),y=ma(m.from,m.fromId,m.fromStoreId),h=ma(m.to,m.toId,m.toStoreId);if(!x)throw new Error("relation rationale is required");if(!y||!h)throw new Error("relation endpoints require an explanationId or clientId");g.push({op:"relation",type:m.type,from:y,to:h,rationale:x})}else if(m.op==="supersede"&&typeof m.explanationId=="string"&&typeof m.replacementId=="string"){let x=ke(m.reason);x&&g.push({op:"supersede",explanationId:m.explanationId,replacementId:m.replacementId,reason:x})}else if(m.op==="bind_concrete"&&typeof m.explanationId=="string"){let x=ke(m.modelPath,300);x&&g.push({op:"bind_concrete",explanationId:m.explanationId,modelPath:x,rationale:ke(m.rationale)})}else m.op==="retire"&&typeof m.explanationId=="string"&&g.push({op:"retire",explanationId:m.explanationId,reason:ke(m.reason)})}let v=a.grounding,w=v&&typeof v.explanationId=="string"&&ke(v.question)?{explanationId:v.explanationId,question:ke(v.question,300)}:void 0;return{draft:{decision:"mutate",summary:p,appliedExplanationIds:f,mutations:g,grounding:w},visibleText:n}}catch(a){return{visibleText:n,error:a instanceof Error?a.message:String(a)}}}function In(r,e={}){let t=r?.explanations??[],n=new Set(r?.pendingGroundingExplanationIds??[]),i=new Set(r?.correctionExplanationIds??[]),o=wo(e.requestText),s=r?.retrievalIntent,a=r?.historicalCaveats??[],c=t.find(g=>g.storeId&&!g.readOnly)?.storeId,d=(g,v)=>{let w=g[v];return w?`[${w.storeId}] ${w.explanationId}`:v==="from"?g.fromId:g.toId},p=!!r?.relations?.some(g=>g.from&&g.to&&g.from.storeId!==g.to.storeId),f=t.some(g=>g.readOnly);return["","## Continuous imprinting","","An imprint is provisional shared understanding learned through human-AI collaboration. It is advisory, not authoritative product truth. Accepted product decisions above always win when they conflict.",...t.length?["","Relevant explanations from the project imprint:",...t.map((g,v)=>[`${v+1}. [${g.state}; ${g.kind}] ${g.statement}`,` - Why: ${g.rationale}`,` - Scope: ${g.scope.kind} ${g.scope.values.join(", ")}`,` - Explanation: ${g.id}`,...g.storeId?[` - Store: ${g.storeId}${g.readOnly?" (read-only)":" (writable primary)"}`]:[],...n.has(g.id)?[" - Grounding: already pending; do not ask again"]:[],...i.has(g.id)?[" - Correction: the developer selected No for this explanation and the current reply supplies the missing correction context"]:[],...g.concrete.map(w=>` - Concrete terminal: ${w.modelPath} = ${JSON.stringify(w.value)}`)].join(`
|
|
3
3
|
`)),...r?.truncated?["Additional imprint context exists outside this bounded packet."]:[]]:[],...r?.relations?.length?["","Known explanation topology:",...r.relations.map(g=>`- ${g.storeId?`[owned by ${g.storeId}${g.readOnly?"; read-only":""}] `:""}${d(g,"from")} --${g.type}--> ${d(g,"to")}: ${g.rationale}`)]:[],...f||p?["","Store-qualified topology remains locally owned: the relation must originate at an explanation in the writable primary store, while its target may be in a mounted read-only store. Never proxy a relation whose source belongs to a mounted store.",`For a cross-store relation, use qualified endpoints: {"op":"relation","type":"expresses|excepts","from":{"storeId":"${c??"<writable-primary-store>"}","clientId":"<new-specific-client-id>"},"to":{"storeId":"<mounted-target-store>","explanationId":"<existing-abstract-target-id>"},"rationale":"<why>"}. Use clientId for a new explanation created in this transaction and explanationId for an existing durable explanation.`]:[],...s?["","Explicit pattern transfer detected:",`- Target: ${s.target}`,`- Reference: ${s.reference}`,"Before editing, state which dimensions you intend to transfer from the reference and which target-specific behavior you will preserve. Compare the relevant surface, spacing, typography, radius, and interaction behavior; transfer only the dimensions supported by the request and evidence. If the intended transfer remains materially ambiguous after inspecting both anchors, ask one focused question."]:[],...a.length?["","Directly relevant challenged history (historical caveats, not current Imprint truth):",...a.map((g,v)=>[`${v+1}. [challenged; ${g.kind}] ${g.statement}`,` - Why it was previously proposed: ${g.rationale}`,` - Scope: ${g.scope.kind} ${g.scope.values.join(", ")}`,` - Historical explanation: ${g.id}`,...g.storeId?[` - Store: ${g.storeId}${g.readOnly?" (read-only)":" (writable primary)"}`]:[]].join(`
|
|
4
4
|
`)),"Use these caveats only to avoid repeating a rejected or over-broad transfer. Do not cite them as usedExplanationIds or treat them as active guidance."]:[],...t.some(g=>g.readOnly)?["","Mounted-store explanations are read-only context. They may inform the work and be cited as used understanding, but do not mutate, ground, revise, or add evidence to them without an explicit writable orientation for that store."]:[],...r?.unavailableStoreIds?.length?["",`Some mounted Imprint knowledge was unavailable during this bounded read: ${r.unavailableStoreIds.join(", ")}. Do not infer its contents.`]:[],...r?.unavailableTopologyStoreIds?.length?["",`Some mounted Imprint topology was unavailable during this bounded read: ${r.unavailableTopologyStoreIds.join(", ")}. Available explanations remain usable, but do not infer missing relationships.`]:[],"","Work normally; Imprint is advisory. Testing explanations may guide action as hypotheses. Emerging explanations are observation-only: do not choose behavior from them. Independent human recurrence in a meaningfully different occurrence may promote emerging understanding to testing. Silence, acceptance of finished work, and the model's implementation choices are not confirmation.","Assess learning on every completion: would the human-supported reasoning change a future agent's behavior in a meaningfully different task? The original instruction, scope language, and corrections count as evidence; a separate learning prompt is unnecessary. Default to none, not a mutation for merely finishing work.","Compare behavior and effective scope with applicable surfaced explanations before dismissing a small edit as task-specific. A narrower departure from the same rule can establish an exception even when the developer did not say exception: add one narrow testing explanation linked by excepts. Distinct concepts may be siblings; differing implementations alone do not imply an exception.","Mutation admission requires all six: reusable beyond this edit; novel relative to explanations/evidence; durable intention, rationale, relationship or recurring pattern; atomic at one abstraction level; explicitly scoped; supported by human evidence rather than mere acceptance or AI choices. If any fails, report none. Copy, pixel tweaks, ordering and implementation mechanics alone usually fail; human-directed reusable rationale or applicability boundaries may pass.","Consolidate overlaps: same claim/new observation -> evidence; concrete application -> bind_concrete; emerging/testing scope refinement -> revise; direct rejection -> add replacement + supersede; different abstraction -> related explanation. Duplicate requires the same claim at equivalent or broader conceptual scope, not shared code or a narrower existing claim.","Explicit all/every/across/globally/project-wide language signals broadening. Preserve a grounded narrower claim; add a broader testing claim and link narrower -> broader with expresses. Pattern-scoped resolved annotations cannot use task_specific_detail; capture the change, application, valid duplicate, or another accurate no-op.","Correction context means the developer selected No but the graph has not yet been changed. Distinguish implementation-only, scope, and reasoning corrections. For emerging/testing refinement, revise with reopenGrounding:true; never also challenge the same identity. For rejection, preserve rejected wording and add a replacement + supersede. Do not challenge a whole claim for a narrow correction or recognize an overlapping clause.","Grounded explanations are append-only: compatible evidence is allowed, revision or demotion is not. Changed meaning/rationale/abstraction/applicability needs a new testing explanation. Do not append unrelated implementation facts. Emerging claims cannot alone support durable theory; one-off values are not universal principles.","Every add needs topology or rootReason explaining why no meaningful relative exists. Only expresses (specific -> abstract) and excepts (narrow exception -> rule) are relations. Multiple parents/children are allowed; no expresses cycles. Support/challenge use evidence; correction uses supersede.","Application/recognition require compatibility with the whole statement, scope and exceptions, not one clause. If narrower durable behavior passes admission, add an atomic related explanation; otherwise none.",...e.delivery==="ambient"?[]:['When a surfaced explanation materially informs an answer or action, immediately emit <imprint-use>{"explanationIds":["<used ids>"]}</imprint-use>; emit again only for newly useful IDs.'],"Cite every materially used surfaced ID in usedExplanationIds. Retrieval/reading/consideration alone is not use. Receipts do not strengthen understanding.","appliedExplanationIds is only for completed observable actions that test the explanation, never answer-only, research, advice or read-only work. All applied IDs are also used. For completed ungrounded application report decision apply even without changed wording; a no-op reason cannot suppress it. Grounded use usually means none; decision recognize is only consequential visible reuse/closing a correction loop, with one exact surfaced grounded ID. Never invent IDs.","Ask at most one grounding question, only for an applied ungrounded explanation with genuinely new evidence and no grounding already pending. The bridge can supply a fallback. Never claim a new explanation is grounded.",e.delivery==="ambient"?"Do not print a machine-readable resolution envelope in the visible response. When this collaboration changes reusable shared understanding, call `popmelt_assess_turn` before the final response.":'After normal prose emit exactly one hidden <resolution>{"annotations":[...],"imprint":{...}}</resolution>. imprint is required even for none; never emit a separate <imprint> block.',"Fields below are schemas: choose one decision and only the necessary operations, not every alternative.",...o?["CURRENT SCOPE SIGNAL: The developer used explicit broadening language in this instruction. Do not classify it as duplicate unless the cited existing explanation already expresses universal or project-wide applicability."]:[],"For no learning, include:",'"imprint":{"decision":"none","reason":"application_only|transient_state|concrete_without_model_path|duplicate|insufficient_evidence|task_specific_detail|no_shared_understanding_change","usedExplanationIds":["<every surfaced explanation that was actively useful, or omit when none>"]}',"A no-op reason cannot suppress genuine application evidence. When a completed action was governed by an ungrounded explanation, report decision apply directly so the summary and grounding question are intentional. Answering a question with that explanation is usage, not application.","When and only when reason is duplicate, also include `duplicateOfExplanationId` naming one surfaced explanation and `scopeComparison` set to `equivalent` or `existing_broader`. The bridge rejects uncited duplicates and duplicates whose cited explanation cannot cover explicit broadening language.","For application evidence without a conceptual change, include:",'"imprint":{"decision":"apply","summary":{"title":"<short expandable-summary title>","detail":"<how the explanation influenced this completed action>"},"appliedExplanationIds":["<surfaced emerging or testing explanation id>"],"grounding":{"explanationId":"<one applied id>","question":"<brief post-application confirmation question>"}}',"For a consequential, non-mutating reuse of grounded understanding that should be visible, include:",'"imprint":{"decision":"recognize","explanationId":"<one exact surfaced grounded explanation id>","summary":{"title":"<short name for the recognized understanding>","detail":"<how it guided this outcome>"}}',"Or, only after every admission test passes for a conceptual change:",'"imprint":{"decision":"mutate","summary":{"kind":"added|strengthened|refined|challenged|exception|consolidated","title":"<short expandable-summary title>","detail":"<what changed in shared understanding>"},"appliedExplanationIds":["<only an ungrounded explanation materially tested here>"],"mutations":[{"op":"add","clientId":"new-1","kind":"intention|principle|pattern","statement":"<one durable atomic explanation>","rationale":"<why the evidence supports it>","scope":{"kind":"project|route|component|selector|file","values":["<scope>"]},"rootReason":"<only when this is genuinely unrelated to every surfaced or new explanation>"},{"op":"revise","explanationId":"<only an emerging or testing id>","statement":"<optional>","rationale":"<optional>","scope":{"kind":"component","values":["CardTile"]},"reopenGrounding":false},{"op":"evidence","explanationId":"<id>","stance":"supports|challenges|excepts","summary":"<thread evidence>"},{"op":"relation","type":"expresses|excepts","from":{"clientId":"<new-specific-client-id>"},"to":{"explanationId":"<existing-abstract-id>"},"rationale":"<why; use clientId for new transaction-local explanations and explanationId for existing durable explanations>"},{"op":"supersede","explanationId":"<contradicted old id>","replacementId":"<new clientId or existing id>","reason":"<direct conflict>"},{"op":"bind_concrete","explanationId":"<id or clientId>","modelPath":"<exact existing model path>","rationale":"<how this fact expresses the explanation>"},{"op":"retire","explanationId":"<id>","reason":"<why>"}],"grounding":{"explanationId":"<one applied ungrounded id or clientId>","question":"<brief post-application confirmation question>"}}',e.delivery==="ambient"?'Pass the complete `<resolution>{"annotations":[...],"imprint":{...}}</resolution>` shape as `assessmentText` to `popmelt_assess_turn`; do not include it in conversational prose.':'The final shape is `<resolution>{"annotations":[...],"imprint":{...}}</resolution>`. The `imprint` field is required even when the decision is none; omission leaves the completed run explicitly unassessed.',"Include only necessary mutations. For a new explanation established through completed action, include its clientId in appliedExplanationIds. Grounded use requires usedExplanationIds; include appliedExplanationIds only for completed observable application, never answer-only use. Never claim new understanding is grounded."].join(`
|
package/dist/server.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{spawn as wy}from"child_process";import{closeSync as Iy,openSync as vy}from"fs";import{appendFile as by,mkdir as xy,readFile as Sy,realpath as ky}from"fs/promises";import{dirname as Py,join as Qs}from"path";import{fileURLToPath as Ty}from"url";function fn(r){return zl(r).slice(0,12)}var Ul=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function zl(r){let e=typeof TextEncoder<"u"?Array.from(new TextEncoder().encode(r)):Hl(r),t=e.length*8;for(e.push(128);e.length%64!==56;)e.push(0);for(let g=7;g>=0;g--)e.push(t/Math.pow(2,g*8)&255);let n=1779033703,i=3144134277,o=1013904242,s=2773480762,a=1359893119,c=2600822924,d=528734635,p=1541459225,f=new Array(64);for(let g=0;g<e.length;g+=64){for(let b=0;b<16;b++){let I=g+b*4;f[b]=(e[I]<<24|e[I+1]<<16|e[I+2]<<8|e[I+3])>>>0}for(let b=16;b<64;b++){let I=xt(f[b-15],7)^xt(f[b-15],18)^f[b-15]>>>3,R=xt(f[b-2],17)^xt(f[b-2],19)^f[b-2]>>>10;f[b]=f[b-16]+I+f[b-7]+R>>>0}let v=n,w=i,u=o,m=s,x=a,y=c,h=d,k=p;for(let b=0;b<64;b++){let I=xt(x,6)^xt(x,11)^xt(x,25),R=x&y^~x&h,D=k+I+R+Ul[b]+f[b]>>>0,N=xt(v,2)^xt(v,13)^xt(v,22),G=v&w^v&u^w&u,re=N+G>>>0;k=h,h=y,y=x,x=m+D>>>0,m=u,u=w,w=v,v=D+re>>>0}n=n+v>>>0,i=i+w>>>0,o=o+u>>>0,s=s+m>>>0,a=a+x>>>0,c=c+y>>>0,d=d+h>>>0,p=p+k>>>0}return[n,i,o,s,a,c,d,p].map(g=>g.toString(16).padStart(8,"0")).join("")}function xt(r,e){return r>>>e|r<<32-e}function Hl(r){let e=[];for(let t=0;t<r.length;t++){let n=r.charCodeAt(t);n<128?e.push(n):n<2048?e.push(192|n>>6,128|n&63):e.push(224|n>>12,128|n>>6&63,128|n&63)}return e}var ra={name:"@popmelt.com/core",version:"0.24.
|
|
1
|
+
import{spawn as wy}from"child_process";import{closeSync as Iy,openSync as vy}from"fs";import{appendFile as by,mkdir as xy,readFile as Sy,realpath as ky}from"fs/promises";import{dirname as Py,join as Qs}from"path";import{fileURLToPath as Ty}from"url";function fn(r){return zl(r).slice(0,12)}var Ul=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function zl(r){let e=typeof TextEncoder<"u"?Array.from(new TextEncoder().encode(r)):Hl(r),t=e.length*8;for(e.push(128);e.length%64!==56;)e.push(0);for(let g=7;g>=0;g--)e.push(t/Math.pow(2,g*8)&255);let n=1779033703,i=3144134277,o=1013904242,s=2773480762,a=1359893119,c=2600822924,d=528734635,p=1541459225,f=new Array(64);for(let g=0;g<e.length;g+=64){for(let b=0;b<16;b++){let I=g+b*4;f[b]=(e[I]<<24|e[I+1]<<16|e[I+2]<<8|e[I+3])>>>0}for(let b=16;b<64;b++){let I=xt(f[b-15],7)^xt(f[b-15],18)^f[b-15]>>>3,R=xt(f[b-2],17)^xt(f[b-2],19)^f[b-2]>>>10;f[b]=f[b-16]+I+f[b-7]+R>>>0}let v=n,w=i,u=o,m=s,x=a,y=c,h=d,k=p;for(let b=0;b<64;b++){let I=xt(x,6)^xt(x,11)^xt(x,25),R=x&y^~x&h,D=k+I+R+Ul[b]+f[b]>>>0,N=xt(v,2)^xt(v,13)^xt(v,22),G=v&w^v&u^w&u,re=N+G>>>0;k=h,h=y,y=x,x=m+D>>>0,m=u,u=w,w=v,v=D+re>>>0}n=n+v>>>0,i=i+w>>>0,o=o+u>>>0,s=s+m>>>0,a=a+x>>>0,c=c+y>>>0,d=d+h>>>0,p=p+k>>>0}return[n,i,o,s,a,c,d,p].map(g=>g.toString(16).padStart(8,"0")).join("")}function xt(r,e){return r>>>e|r<<32-e}function Hl(r){let e=[];for(let t=0;t<r.length;t++){let n=r.charCodeAt(t);n<128?e.push(n):n<2048?e.push(192|n>>6,128|n&63):e.push(224|n>>12,128|n>>6&63,128|n&63)}return e}var ra={name:"@popmelt.com/core",version:"0.24.2",description:"A tiny, powerful design layer for humans and AI",license:"PolyForm-Shield-1.0.0",author:"Popmelt <reb@popmelt.com> (https://popmelt.com)",homepage:"https://github.com/popmelt/core",bugs:{url:"https://github.com/popmelt/core/issues"},repository:{type:"git",url:"git+https://github.com/popmelt/core.git"},keywords:["ai","annotations","collaboration","devtools","react","visual-feedback"],bin:{popmelt:"dist/cli.mjs"},sideEffects:!1,packageManager:"pnpm@9.12.0",engines:{node:">=18.0.0"},scripts:{build:"tsup",clean:"git clean -xdf .turbo node_modules dist",format:'prettier --check "**/*.{ts,tsx}"',lint:"eslint . && node scripts/check-eslint-suppressions.mjs","pack:smoke":"node scripts/pack-smoke.mjs","peer:smoke":"node scripts/peer-compat-smoke.mjs","vue:smoke":"pnpm run build && node scripts/vue-install-smoke.mjs","nuxt:smoke":"pnpm run build && node scripts/nuxt-install-smoke.mjs","astro:smoke":"pnpm run build && node scripts/framework-install-smoke.mjs astro","svelte:smoke":"pnpm run build && node scripts/framework-install-smoke.mjs svelte && node scripts/framework-install-smoke.mjs sveltekit",prepublishOnly:"pnpm run verify",test:"vitest run","test:coverage":"vitest run --coverage.enabled","test:browser":"pnpm run build && tsc --noEmit -p tsconfig.browser.json && vitest run --config vitest.browser.config.ts","test:browser:mutation":"node e2e/check-lifecycle-mutation.mjs","test:watch":"vitest",typecheck:"tsc --noEmit --incremental false",verify:"pnpm run typecheck && pnpm run format && pnpm run lint && pnpm run test:coverage && pnpm run build && pnpm run pack:smoke"},exports:{".":{types:"./dist/index.d.mts",import:"./dist/index.mjs"},"./provider":{types:"./dist/index.d.mts",import:"./dist/index.mjs"},"./browser":{types:"./dist/browser.d.mts",import:"./dist/browser.mjs"},"./server":{types:"./dist/server.d.mts",import:"./dist/server.mjs"},"./memory":{types:"./dist/memory.d.mts",import:"./dist/memory.mjs"},"./memory/legacy":{types:"./dist/memory-legacy.d.mts",import:"./dist/memory-legacy.mjs"},"./memory/store":{types:"./dist/memory-store.d.mts",import:"./dist/memory-store.mjs"},"./next":{types:"./dist/plugin-next.d.mts",import:"./dist/plugin-next.mjs",default:"./dist/plugin-next.mjs"},"./vite":{types:"./dist/plugin-vite.d.mts",import:"./dist/plugin-vite.mjs",default:"./dist/plugin-vite.mjs"},"./vite/client":{types:"./dist/vite-client.d.ts"},"./astro":{types:"./dist/plugin-astro.d.mts",import:"./dist/plugin-astro.mjs",default:"./dist/plugin-astro.mjs"},"./nuxt":{types:"./dist/plugin-nuxt.d.mts",import:"./dist/plugin-nuxt.mjs",default:"./dist/plugin-nuxt.mjs"},"./media":{types:"./dist/media.d.mts",import:"./dist/media.mjs"},"./three":{types:"./dist/adapter-three.d.mts",import:"./dist/adapter-three.mjs"},"./react-three-fiber":{types:"./dist/adapter-react-three-fiber.d.mts",import:"./dist/adapter-react-three-fiber.mjs"}},files:["dist","codex-plugin","claude-plugin","LICENSE","README.md","THIRD_PARTY_NOTICES.md"],dependencies:{"modern-screenshot":"4.7.0",ws:"8.21.3"},peerDependencies:{nuxt:">=4.5.2 <5","lucide-react":">=1.23.0",next:">=14.0.0",react:">=18.0.0","react-dom":">=18.0.0","@react-three/fiber":">=8.0.0",three:">=0.150.0"},peerDependenciesMeta:{nuxt:{optional:!0},next:{optional:!0},"@react-three/fiber":{optional:!0},three:{optional:!0}},devDependencies:{nuxt:"4.5.2","@kit/eslint-config":"workspace:^","@react-three/fiber":"9.7.0","@tanstack/react-router":"1.120.5","@types/react":"19.1.0","@types/react-dom":"19.1.2","@types/three":"^0.185.4","@types/ws":"8.18.1","@vitejs/plugin-react":"^5.1.1","@vitejs/plugin-vue":"6.0.8","@vitest/coverage-v8":"3.2.4",eslint:"^9.24.0",geist:"1.7.2",jsdom:"26.1.0","lucide-react":"^1.23.0",next:"15.5.24",prettier:"3.5.3",react:"19.1.0","react-dom":"19.1.0",three:"^0.185.1",tsup:"^8.5.1",typescript:"^5.8.3",vite:"7.3.6",vitest:"3.2.4",vue:"3.5.42","vue-router":"5.3.1"}};var St=ra.version;import{execFileSync as Eg,spawn as ol}from"child_process";import{randomUUID as jt}from"crypto";function Gr(r){return[...r.matchAll(/<resolution>\s*([\s\S]*?)(?:<\/resolution>|$)/g)].at(-1)?.[1]?.trim()}function Vr(r){return r.replace(/<resolution>[\s\S]*?(?:<\/resolution>|$)/g,"")}function go(r,e){return{storeId:r,explanationId:e}}function Vl(r,e){let{fromId:t,toId:n,toStoreId:i,...o}=e;return{...o,from:go(r,t),to:go(i??r,n)}}var ia={project:0,route:1,component:2,selector:2,file:3},oa={intention:0,principle:1,pattern:2};function hn(r,e){let t=ia[r.scope.kind]-ia[e.scope.kind];return t!==0?t:oa[r.kind]-oa[e.kind]}function sa(r){return r==="expresses"||r==="excepts"}function Wl(r,e){if(e.type==="expresses"||e.type==="excepts")return structuredClone(e);if(e.type==="operationalizes")return{...structuredClone(e),type:"expresses"};if(e.type==="instantiates")return{...structuredClone(e),type:"expresses",fromId:e.toId,toId:e.fromId};if(e.type==="refines"){let t=r.explanations.find(o=>o.id===e.fromId),n=r.explanations.find(o=>o.id===e.toId);if(!t||!n)return;let i=hn(t,n);return i===0?void 0:i>0?{...structuredClone(e),type:"expresses"}:{...structuredClone(e),type:"expresses",fromId:e.toId,toId:e.fromId}}}function Qt(r){let e=structuredClone(r),t=new Set;return e.relations=r.relations.flatMap(n=>{let i=Wl(r,n);if(!i)return[];let o=`${i.type}:${i.fromId}:${i.toStoreId??""}:${i.toId}`;return t.has(o)?[]:(t.add(o),[i])}),e}import{createHash as Kl}from"crypto";import{mkdir as Ql,open as Xl,readFile as aa,readdir as Yl,rename as Zl,unlink as ep}from"fs/promises";import{dirname as tp,join as gn}from"path";function ot(r){return structuredClone(r)}function ca(r){return Kl("sha256").update(JSON.stringify(r)).digest("hex")}async function Xt(r,e){await Ql(tp(r),{recursive:!0});let t=`${r}.${process.pid}.${Date.now()}.tmp`,n=await Xl(t,"w");try{await n.writeFile(`${JSON.stringify(e,null,2)}
|
|
2
2
|
`,"utf8"),await n.sync()}finally{await n.close()}try{await Zl(t,r)}catch(i){throw await ep(t).catch(()=>{}),i}}function np(r,e){return{version:1,projectId:r,createdAt:e,updatedAt:e,head:{sequence:0,hash:null},explanations:[],concrete:[],relations:[]}}function rp(r,e){let t=r.explanations.findIndex(n=>n.id===e.id);t>=0?r.explanations[t]=ot(e):r.explanations.push(ot(e))}function Wr(r,e){let t=ot(r);for(let n of e)if(n.op==="add_explanation"){if(t.explanations.some(i=>i.id===n.explanation.id))throw new Error(`Imprint explanation already exists: ${n.explanation.id}`);t.explanations.push(ot(n.explanation))}else if(n.op==="replace_explanation")rp(t,n.explanation);else if(n.op==="remove_explanation")t.explanations=t.explanations.filter(i=>i.id!==n.explanationId),t.relations=t.relations.filter(i=>i.fromId!==n.explanationId&&(i.toStoreId!==void 0||i.toId!==n.explanationId));else if(n.op==="add_concrete")t.concrete.some(i=>i.id===n.concrete.id)||t.concrete.push(ot(n.concrete));else if(n.op==="remove_concrete")t.concrete=t.concrete.filter(i=>i.id!==n.concreteId),t.relations=t.relations.filter(i=>i.fromId!==n.concreteId&&(i.toStoreId!==void 0||i.toId!==n.concreteId));else if(n.op==="add_evidence"){let i=t.explanations.find(o=>o.id===n.explanationId);if(!i)throw new Error(`Unknown imprint explanation: ${n.explanationId}`);i.evidence.some(o=>o.id===n.evidence.id)||(i.evidence.push(ot(n.evidence)),i.updatedAt=n.evidence.createdAt)}else if(n.op==="revise_explanation"){let i=t.explanations.find(o=>o.id===n.explanationId);if(!i)throw new Error(`Unknown imprint explanation: ${n.explanationId}`);Object.assign(i,ot(n.patch),{updatedAt:n.updatedAt})}else if(n.op==="add_relation"){let i=n.relation,o=t.explanations.find(p=>p.id===i.fromId),s=!!i.toStoreId,a=s?void 0:t.explanations.find(p=>p.id===i.toId),c=t.concrete.some(p=>p.id===i.fromId),d=!s&&t.concrete.some(p=>p.id===i.toId);if(sa(i.type)){if(!(i.type==="expresses"?s?!!o:!!((o||c)&&a):!!(o&&(a||s))))throw new Error(`Imprint ${i.type} relation has invalid endpoints: ${i.id}`);if(t.relations.some(f=>f.type===i.type&&f.fromId===i.fromId&&f.toStoreId===i.toStoreId&&f.toId===i.toId))throw new Error(`Duplicate imprint relation: ${i.type}:${i.fromId}:${i.toStoreId??""}:${i.toId}`);if(i.type==="expresses"&&o&&a){if(hn(o,a)<0)throw new Error(`Imprint expresses relation must point from specific to abstract: ${i.id}`);let f=new Map;for(let w of t.relations)w.type!=="expresses"||w.toStoreId||f.set(w.fromId,[...f.get(w.fromId)??[],w.toId]);let g=[i.toId],v=new Set;for(;g.length;){let w=g.pop();if(w===i.fromId)throw new Error(`Imprint expresses relation would create a cycle: ${i.id}`);v.has(w)||(v.add(w),g.push(...f.get(w)??[]))}}}else if(!o||!a&&!d)throw new Error(`Imprint relation references an unknown explanation: ${i.id}`);t.relations.some(p=>p.id===i.id)||t.relations.push(ot(i))}else n.op==="remove_relation"&&(t.relations=t.relations.filter(i=>i.id!==n.relationId));return t}function ip(r,e){let t=[],n=ot(r);for(let i of e){if(i.op==="add_explanation")t.unshift({op:"remove_explanation",explanationId:i.explanation.id});else if(i.op==="remove_explanation"){let o=n.explanations.find(s=>s.id===i.explanationId);o&&t.unshift({op:"add_explanation",explanation:ot(o)})}else if(i.op==="add_concrete")t.unshift({op:"remove_concrete",concreteId:i.concrete.id});else if(i.op==="remove_concrete"){let o=n.concrete.find(s=>s.id===i.concreteId);o&&t.unshift({op:"add_concrete",concrete:ot(o)})}else if(i.op==="replace_explanation"||i.op==="revise_explanation"||i.op==="add_evidence"){let o=i.op==="replace_explanation"?i.explanation.id:i.explanationId,s=n.explanations.find(a=>a.id===o);s&&t.unshift({op:"replace_explanation",explanation:ot(s)})}else if(i.op==="add_relation")t.unshift({op:"remove_relation",relationId:i.relation.id});else if(i.op==="remove_relation"){let o=n.relations.find(s=>s.id===i.relationId);o&&t.unshift({op:"add_relation",relation:ot(o)})}n=Wr(n,[i])}return t}function da(r){return r.op==="add_explanation"||r.op==="replace_explanation"?[r.explanation.id]:r.op==="remove_explanation"||r.op==="add_evidence"||r.op==="revise_explanation"?[r.explanationId]:r.op==="add_relation"?[r.relation.fromId,...r.relation.toStoreId?[]:[r.relation.toId]]:[]}var yn=class{constructor(e,t){this.projectRoot=e;this.projectId=t;this.writeChain=Promise.resolve();this.imprintDir=gn(e,".popmelt","imprint"),this.manifestPath=gn(this.imprintDir,"manifest.json"),this.graphPath=gn(this.imprintDir,"graph.json"),this.journalDir=gn(this.imprintDir,"journal")}async readHead(){return(await this.readManifest()).head}async readManifest(){try{let e=JSON.parse(await aa(this.manifestPath,"utf8"));if(e.version!==1||e.projectId!==this.projectId)throw new Error("Imprint manifest does not match this project.");return e}catch(e){if(e.code!=="ENOENT")throw e;let t=new Date().toISOString();return{version:1,projectId:this.projectId,createdAt:t,updatedAt:t,head:{sequence:0,hash:null}}}}async loadRaw(){let e=await this.readManifest(),n=(await Yl(this.journalDir).catch(a=>{if(a.code==="ENOENT")return[];throw a})).filter(a=>/^\d{12}-.+\.json$/.test(a)).sort(),i=np(this.projectId,e.createdAt),o=[],s=null;for(let a=0;a<n.length;a++){let c=JSON.parse(await aa(gn(this.journalDir,n[a]),"utf8")),{hash:d,...p}=c;if(c.sequence!==a+1||c.previousHash!==s||d!==ca(p))throw new Error(`Imprint journal hash mismatch at sequence ${c.sequence}.`);i=Wr(i,c.mutations),i.updatedAt=c.committedAt,i.head={sequence:c.sequence,hash:c.hash},o.push(c),s=c.hash}return{graph:i,transactions:o,recoveredTransactions:Math.max(0,o.length-e.head.sequence)}}async load(){let e=await this.loadRaw();return{...e,graph:Qt(e.graph)}}async migrateTopology(){let e=await this.readManifest();if(e.topologyVersion===2)return{migrated:!1,relationMutations:0};let t=await this.loadRaw(),n=Qt(t.graph),i=new Map(n.relations.map(s=>[s.id,s])),o=[];for(let s of t.graph.relations){let a=i.get(s.id);a&&a.type===s.type&&a.fromId===s.fromId&&a.toStoreId===s.toStoreId&&a.toId===s.toId||(o.push({op:"remove_relation",relationId:s.id}),a&&o.push({op:"add_relation",relation:a}))}if(o.length){let s=new Date().toISOString();return await this.commit({transactionId:`topology-v2-${t.graph.head.sequence+1}`,committedAt:s,source:{kind:"migration",threadId:"imprint-topology",jobId:"imprint-topology-v2"},summary:"Simplify Imprint topology to expresses and excepts",mutations:o}),{migrated:!0,relationMutations:o.length}}return await Xt(this.graphPath,n),await Xt(this.manifestPath,{...e,topologyVersion:2}),{migrated:!0,relationMutations:0}}async commit(e){let t;return this.writeChain=this.writeChain.then(async()=>{let n=await this.load();if(n.transactions.some(f=>f.transactionId===e.transactionId))throw new Error(`Imprint transaction already exists: ${e.transactionId}`);let i=n.graph.head.sequence+1,o=ip(n.graph,e.mutations),s={version:1,sequence:i,transactionId:e.transactionId,projectId:this.projectId,committedAt:e.committedAt,previousHash:n.graph.head.hash,source:e.source,summary:e.summary,mutations:ot(e.mutations),inverseMutations:o,...e.undoesTransactionId?{undoesTransactionId:e.undoesTransactionId}:{}},a={...s,hash:ca(s)},c=Wr(n.graph,a.mutations);c.updatedAt=e.committedAt,c.head={sequence:i,hash:a.hash};let d=`${String(i).padStart(12,"0")}-${e.transactionId}.json`;await Xt(gn(this.journalDir,d),a);let p={version:1,topologyVersion:2,projectId:this.projectId,createdAt:c.createdAt,updatedAt:e.committedAt,head:c.head};await Xt(this.graphPath,c),await Xt(this.manifestPath,p),t={graph:c,transaction:a}}),await this.writeChain,t}async undo(e,t,n,i){let o=await this.load(),s=o.transactions.find(d=>d.transactionId===e);if(!s)throw new Error("The imprint update is no longer available to undo.");if(o.transactions.some(d=>d.undoesTransactionId===e))throw new Error("This imprint update has already been undone.");let a=new Set(s.mutations.flatMap(da));if(o.transactions.filter(d=>d.sequence>s.sequence).some(d=>d.mutations.some(p=>da(p).some(f=>a.has(f)))))throw new Error("This imprint update has newer dependent changes and cannot be undone cleanly. Edit or challenge the current explanation instead.");return this.commit({transactionId:i,committedAt:n,source:t,summary:`Undo: ${s.summary}`,mutations:s.inverseMutations,undoesTransactionId:e})}async recover(){let e=await this.load();return await Xt(this.graphPath,e.graph),await Xt(this.manifestPath,{version:1,topologyVersion:2,projectId:this.projectId,createdAt:e.graph.createdAt,updatedAt:e.graph.updatedAt,head:e.graph.head}),{...e,recoveredTransactions:0}}};var op=new Set(["application_only","transient_state","concrete_without_model_path","duplicate","insufficient_evidence","task_specific_detail","no_shared_understanding_change"]),sp=new Set(["about","after","again","before","being","change","from","have","into","make","should","that","the","their","this","with","would","here","only","consistent","match","matched","matching","mirror","mirrored","mirroring","align","aligned","aligning"]),ap=[/\bconsistent\s+with\b/i,/\bmatch(?:es|ed|ing)?\b/i,/\bmirror(?:s|ed|ing)?\b/i,/\bthe\s+same\s+as\b/i,/\bborrow(?:s|ed|ing)?\s+from\b/i,/\balign(?:s|ed|ing)?\s+with\b/i,/\b(?:more|look|looks|feel|feels|behave|behaves)\s+like\b/i],cp=/\b(all|any|every|everywhere|across|throughout|globally|project[- ]wide)\b/i;function wo(r){return!!(r&&cp.test(r))}function dp(r){return r.scope.kind==="project"||wo(`${r.statement} ${r.rationale}`)}function lp(r){let e=r?.scope.values.filter(t=>t!=="*").join(", ");return e?`Does applying this understanding here match your intent for ${e}?`:"Does applying this understanding here match your intent?"}function pp(r){return r.replace(/([a-z0-9])([A-Z])/g,"$1 $2").toLowerCase().replace(/[^a-z0-9]+/g," ").trim().replace(/\s+/g," ")}function up(r){return r.length>4&&r.endsWith("ies")?[r,`${r.slice(0,-3)}y`]:r.length>3&&r.endsWith("s")&&!r.endsWith("ss")?[r,r.slice(0,-1)]:[r]}function Mt(r){return new Set(pp(r).split(" ").filter(e=>e.length>2&&!sp.has(e)).flatMap(up))}function la(r){return r.replace(/^\s*(?:please\s+)?(?:let(?:'|’)s\s+)?(?:make|apply|use|keep|change|update)\s+/i,"").replace(/[\s,.:;!?]+$/g,"").trim().slice(0,240)}function mp(r){if(r)for(let e of ap){let t=e.exec(r);if(!t||t.index<=0)continue;let n=la(r.slice(0,t.index)),i=la(r.slice(t.index+t[0].length));if(n&&i)return{target:n,reference:i}}}function Lt(r,e){if(!r.size||!e.size)return 0;let t=0;for(let n of r)e.has(n)&&(t+=1);return t/Math.min(r.size,e.size)}function yo(r){return!r||!Array.isArray(r.values)||r.values.length===0?{kind:"project",values:["*"]}:{kind:r.kind,values:[...new Set(r.values.map(e=>e.trim()).filter(Boolean))]}}function Jt(r,e,t){return{id:jt(),kind:e==="excepts"?"exception":e==="challenges"?"correction":"observation",stance:e,summary:t,threadId:r.threadId,jobId:r.jobId,createdAt:r.occurredAt??new Date().toISOString()}}function ke(r,e=800){return typeof r=="string"?r.trim().slice(0,e):""}function pa(r){if(!r||typeof r!="object"||Array.isArray(r))return;let e=r;if(!["project","route","component","selector","file"].includes(String(e.kind))||!Array.isArray(e.values))return;let t=e.values.filter(n=>typeof n=="string"&&!!n.trim());return t.length?{kind:e.kind,values:t}:void 0}function ua(r,e,t){if(r&&typeof r=="object"&&!Array.isArray(r)){let o=r,s=ke(o.explanationId,100),a=ke(o.clientId,100),c=ke(o.storeId,100);if(s&&a)throw new Error("relation endpoint must use either explanationId or clientId, not both");let d=s||a;return d?{explanationId:d,...c?{storeId:c}:{}}:void 0}let n=ke(e,100),i=ke(t,100);return n?{explanationId:n,...i?{storeId:i}:{}}:void 0}function ma(r,e){if(!r||!e.trim())return{found:!1};let t=r;for(let n of e.split(".").filter(Boolean))if(Array.isArray(t)){let i=Number(n);if(!Number.isInteger(i)||i<0||i>=t.length)return{found:!1};t=t[i]}else if(t&&typeof t=="object"&&Object.prototype.hasOwnProperty.call(t,n))t=t[n];else return{found:!1};return{found:!0,value:t}}function wn(r,e={}){let t=[...r.matchAll(/<imprint>([\s\S]*?)<\/imprint>/g)],n=Vr(r).replace(/<imprint>[\s\S]*?<\/imprint>/g,"").replace(/<imprint>[\s\S]*$/g,"").trim(),i=t.at(-1)?.[1],o,s=[];if(i)o=i;else{let a=Gr(r);if(a===void 0)return{visibleText:n,error:"imprint assessment is missing"};try{let c=JSON.parse(a);if(!c||typeof c!="object"||Array.isArray(c)||!Object.prototype.hasOwnProperty.call(c,"imprint"))return{visibleText:n,error:"imprint assessment is missing"};let d=c;o=d.imprint,s=Array.isArray(d.annotations)?d.annotations:[]}catch{return{visibleText:n,error:"resolution envelope is invalid"}}}try{let a=typeof o=="string"?JSON.parse(o):o;if(!a||typeof a!="object"||Array.isArray(a))throw new Error("imprint assessment is invalid");if(a.decision==="none"){let u=String(a.reason);if(!op.has(u))throw new Error("imprint no-op reason is invalid");if(u==="task_specific_detail"&&s.some(R=>{if(!R||typeof R!="object"||Array.isArray(R))return!1;let D=R;return(D.finalScope??D.inferredScope)?.breadth==="pattern"}))throw new Error("pattern-scoped resolution cannot be classified as task_specific_detail");let m=Array.isArray(a.usedExplanationIds)?a.usedExplanationIds.filter(R=>typeof R=="string"&&!!R.trim()):[],x=Array.isArray(a.appliedExplanationIds)?a.appliedExplanationIds.filter(R=>typeof R=="string"&&!!R.trim()):[],y=new Set(e.context?.explanations.map(R=>R.id)??[]);if([...new Set([...m,...x])].some(R=>!y.has(R)))throw new Error("imprint use must cite only surfaced explanations");let k=[...new Set([...m,...e.applicationOccurred?[]:x])],b=e.applicationOccurred?x:[],I;if(b.length){I=b;let R=new Set(e.context?.pendingGroundingExplanationIds??[]),D=b.filter(N=>{let G=e.context?.explanations.find(re=>re.id===N);return y.has(N)&&G&&(G.state==="emerging"||G.state==="testing")&&!R.has(N)});if(D.length){let N=a.grounding,G=typeof N?.explanationId=="string"&&D.includes(N.explanationId)?N.explanationId:D[0],re=ke(N?.question,300);return{draft:{decision:"apply",summary:{title:ke(a.summary?.title,120)||"Applied shared understanding",detail:ke(a.summary?.detail,500)||ke(e.requestText||n,500)||"Applied an ungrounded explanation in a new context."},appliedExplanationIds:b,grounding:{explanationId:G,question:re||"Does applying this understanding here match your intent?"}},visibleText:n}}}if(u==="duplicate"){let R=ke(a.duplicateOfExplanationId,100),D=a.scopeComparison;if(!R)throw new Error("duplicate assessment requires duplicateOfExplanationId");if(D!=="equivalent"&&D!=="existing_broader")throw new Error("duplicate assessment requires an equivalent or existing_broader scopeComparison");let N=e.context?.explanations.find(G=>G.id===R);if(!N)throw new Error("duplicate assessment must cite a surfaced explanation");if(wo(e.requestText)&&!dp(N))throw new Error("duplicate explanation does not cover the requested broader scope");return{draft:{decision:"none",reason:u,duplicateOfExplanationId:R,scopeComparison:D,...k.length?{usedExplanationIds:k}:{},...I?{appliedExplanationIds:I}:{}},visibleText:n}}return{draft:{decision:"none",reason:u,...k.length?{usedExplanationIds:k}:{},...I?{appliedExplanationIds:I}:{}},visibleText:n}}if(a.decision==="recognize"){let u=ke(a.explanationId,100);if(!u)throw new Error("recognition requires explanationId");let m=e.context?.explanations.find(h=>h.id===u);if(!m)throw new Error("recognition must cite a surfaced explanation");if(m.state!=="grounded")throw new Error("recognition must cite a grounded explanation");let x=a.summary,y={title:ke(x?.title,120),detail:ke(x?.detail,500)};if(!y.title||!y.detail)throw new Error("recognition summary title and detail are required");return{draft:{decision:"recognize",explanationId:u,summary:y},visibleText:n}}if(a.decision==="apply"){let u=a.summary,m={title:ke(u?.title,120),detail:ke(u?.detail,500)};if(!m.title||!m.detail)throw new Error("application summary title and detail are required");let x=Array.isArray(a.appliedExplanationIds)?a.appliedExplanationIds.filter(R=>typeof R=="string"&&!!R.trim()):[];if(!x.length)throw new Error("application requires appliedExplanationIds");let y=new Map(e.context?.explanations.map(R=>[R.id,R])??[]);if(x.some(R=>!y.has(R)))throw new Error("application must cite only surfaced explanations");if(!e.applicationOccurred)return{draft:{decision:"none",reason:"application_only",usedExplanationIds:[...new Set(x)]},visibleText:n};let h=new Set(e.context?.pendingGroundingExplanationIds??[]),k=x.filter(R=>{let D=y.get(R);return D&&(D.state==="emerging"||D.state==="testing")&&!h.has(R)});if(!k.length){if(x.every(D=>y.get(D)?.state==="grounded"||h.has(D)))return{draft:{decision:"none",reason:"application_only",appliedExplanationIds:x},visibleText:n};throw new Error("application must cite a surfaced ungrounded explanation")}let b=a.grounding,I=typeof b?.explanationId=="string"&&k.includes(b.explanationId)?b.explanationId:k[0];return{draft:{decision:"apply",summary:m,appliedExplanationIds:x,grounding:{explanationId:I,question:ke(b?.question,300)||"Does applying this understanding here match your intent?"}},visibleText:n}}if(a.decision!==void 0&&a.decision!=="mutate")throw new Error("imprint decision is invalid");let c=a.summary,d=c?.kind;if(!["added","strengthened","refined","challenged","exception","consolidated"].includes(String(d)))throw new Error("summary.kind is invalid");let p={kind:d,title:ke(c?.title,120),detail:ke(c?.detail,500)};if(!p.title||!p.detail)throw new Error("summary title and detail are required");let f=Array.isArray(a.appliedExplanationIds)?a.appliedExplanationIds.filter(u=>typeof u=="string"&&!!u.trim()):[],g=[];for(let u of Array.isArray(a.mutations)?a.mutations:[]){if(!u||typeof u!="object")continue;let m=u;if(m.op==="add"&&["intention","principle","pattern"].includes(String(m.kind))){let x=ke(m.statement),y=ke(m.rationale);if(!x||!y)continue;g.push({op:"add",clientId:ke(m.clientId,100)||void 0,kind:m.kind,statement:x,rationale:y,scope:pa(m.scope),rootReason:ke(m.rootReason,300)||void 0})}else if(m.op==="revise"&&typeof m.explanationId=="string"){let x={op:"revise",explanationId:m.explanationId,statement:ke(m.statement)||void 0,rationale:ke(m.rationale)||void 0,scope:pa(m.scope),reopenGrounding:m.reopenGrounding===!0};(x.statement||x.rationale||x.scope||x.reopenGrounding)&&g.push(x)}else if(m.op==="evidence"&&typeof m.explanationId=="string"&&["supports","challenges","excepts"].includes(String(m.stance))){let x=ke(m.summary);x&&g.push({op:"evidence",explanationId:m.explanationId,stance:m.stance,summary:x})}else if(m.op==="relation"){if(!["expresses","excepts"].includes(String(m.type)))throw new Error("relation type is invalid");let x=ke(m.rationale),y=ua(m.from,m.fromId,m.fromStoreId),h=ua(m.to,m.toId,m.toStoreId);if(!x)throw new Error("relation rationale is required");if(!y||!h)throw new Error("relation endpoints require an explanationId or clientId");g.push({op:"relation",type:m.type,from:y,to:h,rationale:x})}else if(m.op==="supersede"&&typeof m.explanationId=="string"&&typeof m.replacementId=="string"){let x=ke(m.reason);x&&g.push({op:"supersede",explanationId:m.explanationId,replacementId:m.replacementId,reason:x})}else if(m.op==="bind_concrete"&&typeof m.explanationId=="string"){let x=ke(m.modelPath,300);x&&g.push({op:"bind_concrete",explanationId:m.explanationId,modelPath:x,rationale:ke(m.rationale)})}else m.op==="retire"&&typeof m.explanationId=="string"&&g.push({op:"retire",explanationId:m.explanationId,reason:ke(m.reason)})}let v=a.grounding,w=v&&typeof v.explanationId=="string"&&ke(v.question)?{explanationId:v.explanationId,question:ke(v.question,300)}:void 0;return{draft:{decision:"mutate",summary:p,appliedExplanationIds:f,mutations:g,grounding:w},visibleText:n}}catch(a){return{visibleText:n,error:a instanceof Error?a.message:String(a)}}}function In(r,e={}){let t=r?.explanations??[],n=new Set(r?.pendingGroundingExplanationIds??[]),i=new Set(r?.correctionExplanationIds??[]),o=wo(e.requestText),s=r?.retrievalIntent,a=r?.historicalCaveats??[],c=t.find(g=>g.storeId&&!g.readOnly)?.storeId,d=(g,v)=>{let w=g[v];return w?`[${w.storeId}] ${w.explanationId}`:v==="from"?g.fromId:g.toId},p=!!r?.relations?.some(g=>g.from&&g.to&&g.from.storeId!==g.to.storeId),f=t.some(g=>g.readOnly);return["","## Continuous imprinting","","An imprint is provisional shared understanding learned through human-AI collaboration. It is advisory, not authoritative product truth. Accepted product decisions above always win when they conflict.",...t.length?["","Relevant explanations from the project imprint:",...t.map((g,v)=>[`${v+1}. [${g.state}; ${g.kind}] ${g.statement}`,` - Why: ${g.rationale}`,` - Scope: ${g.scope.kind} ${g.scope.values.join(", ")}`,` - Explanation: ${g.id}`,...g.storeId?[` - Store: ${g.storeId}${g.readOnly?" (read-only)":" (writable primary)"}`]:[],...n.has(g.id)?[" - Grounding: already pending; do not ask again"]:[],...i.has(g.id)?[" - Correction: the developer selected No for this explanation and the current reply supplies the missing correction context"]:[],...g.concrete.map(w=>` - Concrete terminal: ${w.modelPath} = ${JSON.stringify(w.value)}`)].join(`
|
|
3
3
|
`)),...r?.truncated?["Additional imprint context exists outside this bounded packet."]:[]]:[],...r?.relations?.length?["","Known explanation topology:",...r.relations.map(g=>`- ${g.storeId?`[owned by ${g.storeId}${g.readOnly?"; read-only":""}] `:""}${d(g,"from")} --${g.type}--> ${d(g,"to")}: ${g.rationale}`)]:[],...f||p?["","Store-qualified topology remains locally owned: the relation must originate at an explanation in the writable primary store, while its target may be in a mounted read-only store. Never proxy a relation whose source belongs to a mounted store.",`For a cross-store relation, use qualified endpoints: {"op":"relation","type":"expresses|excepts","from":{"storeId":"${c??"<writable-primary-store>"}","clientId":"<new-specific-client-id>"},"to":{"storeId":"<mounted-target-store>","explanationId":"<existing-abstract-target-id>"},"rationale":"<why>"}. Use clientId for a new explanation created in this transaction and explanationId for an existing durable explanation.`]:[],...s?["","Explicit pattern transfer detected:",`- Target: ${s.target}`,`- Reference: ${s.reference}`,"Before editing, state which dimensions you intend to transfer from the reference and which target-specific behavior you will preserve. Compare the relevant surface, spacing, typography, radius, and interaction behavior; transfer only the dimensions supported by the request and evidence. If the intended transfer remains materially ambiguous after inspecting both anchors, ask one focused question."]:[],...a.length?["","Directly relevant challenged history (historical caveats, not current Imprint truth):",...a.map((g,v)=>[`${v+1}. [challenged; ${g.kind}] ${g.statement}`,` - Why it was previously proposed: ${g.rationale}`,` - Scope: ${g.scope.kind} ${g.scope.values.join(", ")}`,` - Historical explanation: ${g.id}`,...g.storeId?[` - Store: ${g.storeId}${g.readOnly?" (read-only)":" (writable primary)"}`]:[]].join(`
|
|
4
4
|
`)),"Use these caveats only to avoid repeating a rejected or over-broad transfer. Do not cite them as usedExplanationIds or treat them as active guidance."]:[],...t.some(g=>g.readOnly)?["","Mounted-store explanations are read-only context. They may inform the work and be cited as used understanding, but do not mutate, ground, revise, or add evidence to them without an explicit writable orientation for that store."]:[],...r?.unavailableStoreIds?.length?["",`Some mounted Imprint knowledge was unavailable during this bounded read: ${r.unavailableStoreIds.join(", ")}. Do not infer its contents.`]:[],...r?.unavailableTopologyStoreIds?.length?["",`Some mounted Imprint topology was unavailable during this bounded read: ${r.unavailableTopologyStoreIds.join(", ")}. Available explanations remain usable, but do not infer missing relationships.`]:[],"","Work normally; Imprint is advisory. Testing explanations may guide action as hypotheses. Emerging explanations are observation-only: do not choose behavior from them. Independent human recurrence in a meaningfully different occurrence may promote emerging understanding to testing. Silence, acceptance of finished work, and the model's implementation choices are not confirmation.","Assess learning on every completion: would the human-supported reasoning change a future agent's behavior in a meaningfully different task? The original instruction, scope language, and corrections count as evidence; a separate learning prompt is unnecessary. Default to none, not a mutation for merely finishing work.","Compare behavior and effective scope with applicable surfaced explanations before dismissing a small edit as task-specific. A narrower departure from the same rule can establish an exception even when the developer did not say exception: add one narrow testing explanation linked by excepts. Distinct concepts may be siblings; differing implementations alone do not imply an exception.","Mutation admission requires all six: reusable beyond this edit; novel relative to explanations/evidence; durable intention, rationale, relationship or recurring pattern; atomic at one abstraction level; explicitly scoped; supported by human evidence rather than mere acceptance or AI choices. If any fails, report none. Copy, pixel tweaks, ordering and implementation mechanics alone usually fail; human-directed reusable rationale or applicability boundaries may pass.","Consolidate overlaps: same claim/new observation -> evidence; concrete application -> bind_concrete; emerging/testing scope refinement -> revise; direct rejection -> add replacement + supersede; different abstraction -> related explanation. Duplicate requires the same claim at equivalent or broader conceptual scope, not shared code or a narrower existing claim.","Explicit all/every/across/globally/project-wide language signals broadening. Preserve a grounded narrower claim; add a broader testing claim and link narrower -> broader with expresses. Pattern-scoped resolved annotations cannot use task_specific_detail; capture the change, application, valid duplicate, or another accurate no-op.","Correction context means the developer selected No but the graph has not yet been changed. Distinguish implementation-only, scope, and reasoning corrections. For emerging/testing refinement, revise with reopenGrounding:true; never also challenge the same identity. For rejection, preserve rejected wording and add a replacement + supersede. Do not challenge a whole claim for a narrow correction or recognize an overlapping clause.","Grounded explanations are append-only: compatible evidence is allowed, revision or demotion is not. Changed meaning/rationale/abstraction/applicability needs a new testing explanation. Do not append unrelated implementation facts. Emerging claims cannot alone support durable theory; one-off values are not universal principles.","Every add needs topology or rootReason explaining why no meaningful relative exists. Only expresses (specific -> abstract) and excepts (narrow exception -> rule) are relations. Multiple parents/children are allowed; no expresses cycles. Support/challenge use evidence; correction uses supersede.","Application/recognition require compatibility with the whole statement, scope and exceptions, not one clause. If narrower durable behavior passes admission, add an atomic related explanation; otherwise none.",...e.delivery==="ambient"?[]:['When a surfaced explanation materially informs an answer or action, immediately emit <imprint-use>{"explanationIds":["<used ids>"]}</imprint-use>; emit again only for newly useful IDs.'],"Cite every materially used surfaced ID in usedExplanationIds. Retrieval/reading/consideration alone is not use. Receipts do not strengthen understanding.","appliedExplanationIds is only for completed observable actions that test the explanation, never answer-only, research, advice or read-only work. All applied IDs are also used. For completed ungrounded application report decision apply even without changed wording; a no-op reason cannot suppress it. Grounded use usually means none; decision recognize is only consequential visible reuse/closing a correction loop, with one exact surfaced grounded ID. Never invent IDs.","Ask at most one grounding question, only for an applied ungrounded explanation with genuinely new evidence and no grounding already pending. The bridge can supply a fallback. Never claim a new explanation is grounded.",e.delivery==="ambient"?"Do not print a machine-readable resolution envelope in the visible response. When this collaboration changes reusable shared understanding, call `popmelt_assess_turn` before the final response.":'After normal prose emit exactly one hidden <resolution>{"annotations":[...],"imprint":{...}}</resolution>. imprint is required even for none; never emit a separate <imprint> block.',"Fields below are schemas: choose one decision and only the necessary operations, not every alternative.",...o?["CURRENT SCOPE SIGNAL: The developer used explicit broadening language in this instruction. Do not classify it as duplicate unless the cited existing explanation already expresses universal or project-wide applicability."]:[],"For no learning, include:",'"imprint":{"decision":"none","reason":"application_only|transient_state|concrete_without_model_path|duplicate|insufficient_evidence|task_specific_detail|no_shared_understanding_change","usedExplanationIds":["<every surfaced explanation that was actively useful, or omit when none>"]}',"A no-op reason cannot suppress genuine application evidence. When a completed action was governed by an ungrounded explanation, report decision apply directly so the summary and grounding question are intentional. Answering a question with that explanation is usage, not application.","When and only when reason is duplicate, also include `duplicateOfExplanationId` naming one surfaced explanation and `scopeComparison` set to `equivalent` or `existing_broader`. The bridge rejects uncited duplicates and duplicates whose cited explanation cannot cover explicit broadening language.","For application evidence without a conceptual change, include:",'"imprint":{"decision":"apply","summary":{"title":"<short expandable-summary title>","detail":"<how the explanation influenced this completed action>"},"appliedExplanationIds":["<surfaced emerging or testing explanation id>"],"grounding":{"explanationId":"<one applied id>","question":"<brief post-application confirmation question>"}}',"For a consequential, non-mutating reuse of grounded understanding that should be visible, include:",'"imprint":{"decision":"recognize","explanationId":"<one exact surfaced grounded explanation id>","summary":{"title":"<short name for the recognized understanding>","detail":"<how it guided this outcome>"}}',"Or, only after every admission test passes for a conceptual change:",'"imprint":{"decision":"mutate","summary":{"kind":"added|strengthened|refined|challenged|exception|consolidated","title":"<short expandable-summary title>","detail":"<what changed in shared understanding>"},"appliedExplanationIds":["<only an ungrounded explanation materially tested here>"],"mutations":[{"op":"add","clientId":"new-1","kind":"intention|principle|pattern","statement":"<one durable atomic explanation>","rationale":"<why the evidence supports it>","scope":{"kind":"project|route|component|selector|file","values":["<scope>"]},"rootReason":"<only when this is genuinely unrelated to every surfaced or new explanation>"},{"op":"revise","explanationId":"<only an emerging or testing id>","statement":"<optional>","rationale":"<optional>","scope":{"kind":"component","values":["CardTile"]},"reopenGrounding":false},{"op":"evidence","explanationId":"<id>","stance":"supports|challenges|excepts","summary":"<thread evidence>"},{"op":"relation","type":"expresses|excepts","from":{"clientId":"<new-specific-client-id>"},"to":{"explanationId":"<existing-abstract-id>"},"rationale":"<why; use clientId for new transaction-local explanations and explanationId for existing durable explanations>"},{"op":"supersede","explanationId":"<contradicted old id>","replacementId":"<new clientId or existing id>","reason":"<direct conflict>"},{"op":"bind_concrete","explanationId":"<id or clientId>","modelPath":"<exact existing model path>","rationale":"<how this fact expresses the explanation>"},{"op":"retire","explanationId":"<id>","reason":"<why>"}],"grounding":{"explanationId":"<one applied ungrounded id or clientId>","question":"<brief post-application confirmation question>"}}',e.delivery==="ambient"?'Pass the complete `<resolution>{"annotations":[...],"imprint":{...}}</resolution>` shape as `assessmentText` to `popmelt_assess_turn`; do not include it in conversational prose.':'The final shape is `<resolution>{"annotations":[...],"imprint":{...}}</resolution>`. The `imprint` field is required even when the decision is none; omission leaves the completed run explicitly unassessed.',"Include only necessary mutations. For a new explanation established through completed action, include its clientId in appliedExplanationIds. Grounded use requires usedExplanationIds; include appliedExplanationIds only for completed observable application, never answer-only use. Never claim new understanding is grounded."].join(`
|
package/package.json
CHANGED