@popmelt.com/core 0.6.1 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -23
- package/dist/cli.mjs +21 -20
- package/dist/index.mjs +30 -20
- package/dist/plugin-astro.mjs +1 -1
- package/dist/plugin-vite.mjs +1 -1
- package/dist/server-56YLMPXH.mjs +131 -0
- package/dist/server.mjs +21 -20
- package/package.json +2 -2
- package/dist/server-RSWDAN3X.mjs +0 -130
package/README.md
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
|
|
7
7
|
## What is it?
|
|
8
8
|
|
|
9
|
-
Popmelt is a design collaboration layer for AI coding agents. Drop it into any React
|
|
9
|
+
Popmelt is a design collaboration layer for AI coding agents. Drop it into any React codebase and get a full design-feedback loop: draw on your running UI, pin feedback to elements, adjust style and layout directly, and hand off annotated screenshots with full technical context in a keystroke.
|
|
10
10
|
|
|
11
|
-
It works with AI CLI tools like [Claude Code](https://code.claude.com/docs/en/cli-reference) and [Codex](https://developers.openai.com/codex/cli/),
|
|
11
|
+
It works with AI CLI tools like [Claude Code](https://code.claude.com/docs/en/cli-reference) and [Codex](https://developers.openai.com/codex/cli/) — your agent sees exactly what you marked up, understands the code behind it, and edits your files.
|
|
12
12
|
|
|
13
13
|
<p align="center">
|
|
14
14
|
<img src="src/assets/bar - annotations.png" alt="Popmelt annotations on a running app" width="720" style="border-radius: 6px;" />
|
|
@@ -104,6 +104,8 @@ Open your app in the browser and double-tap Cmd (or Ctrl) to toggle the toolbar.
|
|
|
104
104
|
| Tool | Shortcut | What it does |
|
|
105
105
|
|------|----------|-------------|
|
|
106
106
|
| **Comment** | `C` | Click any element to pin a comment. Captures tag, classes, React component name, and ancestor context. |
|
|
107
|
+
| **Handle** | `H` | Drag padding, gap, border-radius, font-size, and line-height handles directly on elements. Shift to snap to a scale. |
|
|
108
|
+
| **Model** | `M` | Hover elements to see component boundaries. Click to promote a component or token into your design model. |
|
|
107
109
|
| **Rectangle** | `R` | Draw a rectangle to highlight a region. Auto-prompts for a text label. |
|
|
108
110
|
| **Oval** | `O` | Draw an ellipse. |
|
|
109
111
|
| **Line** | `L` | Draw a straight line. |
|
|
@@ -116,7 +118,6 @@ Open your app in the browser and double-tap Cmd (or Ctrl) to toggle the toolbar.
|
|
|
116
118
|
<img src="src/assets/bar - text.png" alt="Text tool guidance" width="360" style="border-radius: 12px;" />
|
|
117
119
|
</p>
|
|
118
120
|
|
|
119
|
-
|
|
120
121
|
## Handle tool
|
|
121
122
|
|
|
122
123
|
Switch to the Handle tool (`H`) and hover any element to see draggable handles for its spatial properties:
|
|
@@ -135,42 +136,41 @@ Right-click any element in Handle mode to open the **style panel** for full cont
|
|
|
135
136
|
<img src="src/assets/bar - handle.png" alt="Handle tool guidance" width="360" style="border-radius: 12px;" />
|
|
136
137
|
</p>
|
|
137
138
|
|
|
139
|
+
## AI collaboration
|
|
138
140
|
|
|
141
|
+
Press Cmd+Enter to capture an annotated screenshot, bundle it with structured feedback (element selectors, style diffs, annotation text), and send it to your AI. Cmd+C copies the screenshot to your clipboard instead. Toggle between Claude (Opus/Sonnet) and Codex at any time.
|
|
139
142
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
Popmelt maintains a design model for your project, a structured record of components, tokens, and rules.
|
|
143
|
+
### Threaded conversations
|
|
143
144
|
|
|
144
|
-
|
|
145
|
+
Follow-up annotations on the same element continue the existing thread — your AI sees prior context without re-explaining. If your AI needs clarification, a question badge appears on the annotation; reply inline and the conversation continues.
|
|
145
146
|
|
|
146
|
-
|
|
147
|
+
### Multi-page annotations
|
|
147
148
|
|
|
148
|
-
|
|
149
|
+
Annotate across multiple pages in a single session. Popmelt captures per-page screenshots and stitches them into a single submission so your AI understands the full scope of your feedback. Pass a `navigate` prop to `PopmeltProvider` to enable this.
|
|
149
150
|
|
|
150
|
-
|
|
151
|
-
<img src="src/assets/bar - model.png" alt="Model tool guidance" width="360" style="border-radius: 12px;" />
|
|
152
|
-
</p>
|
|
151
|
+
### Resolution lifecycle
|
|
153
152
|
|
|
153
|
+
When your AI resolves an annotation, it's marked with a status badge. Resolved annotations show a checkmark; annotations that need your review get a flag. Dismissed annotations gray out. The lifecycle keeps your canvas clean as you iterate.
|
|
154
154
|
|
|
155
|
-
##
|
|
155
|
+
## Design model
|
|
156
156
|
|
|
157
|
-
|
|
157
|
+
Popmelt maintains a design model in `.popmelt/model.json` — a structured record of your design tokens and promoted components.
|
|
158
158
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
Press Cmd+Enter to capture an annotated screenshot, bundle it with structured feedback (element selectors, style diffs, annotation text), and send it to your AI. Cmd+C copies the screenshot to your clipboard instead. Toggle between Claude (Opus/Sonnet) and Codex at any time.
|
|
159
|
+
Switch to the Model tool (`M`) and hover any element to see component boundaries. Click to promote a component or token into your model. Popmelt classifies the scope of each promotion (instance vs pattern, element vs component vs token) so your AI understands what's a one-off tweak and what's a system-level change.
|
|
162
160
|
|
|
163
|
-
|
|
161
|
+
Your AI references the design model when making changes, keeping its output consistent with your established patterns.
|
|
164
162
|
|
|
165
|
-
|
|
163
|
+
<p align="center">
|
|
164
|
+
<img src="src/assets/bar - model.png" alt="Model tool guidance" width="360" style="border-radius: 12px;" />
|
|
165
|
+
</p>
|
|
166
166
|
|
|
167
|
-
|
|
167
|
+
## Decision history
|
|
168
168
|
|
|
169
|
-
|
|
169
|
+
Every annotation and resolution is persisted to `.popmelt/decisions/` — a searchable record of what changed, why, and who asked for it. As your project evolves, this history becomes an invaluable reference for understanding past design choices and their context.
|
|
170
170
|
|
|
171
|
-
|
|
171
|
+
## Annotation counter
|
|
172
172
|
|
|
173
|
-
|
|
173
|
+
The toolbar shows a count of active annotations. Click the counter to cycle through them; scroll to change the annotation color; hover to see a route-grouped navigation list of all annotations across pages.
|
|
174
174
|
|
|
175
175
|
## API
|
|
176
176
|
|
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as C,b as V,c as
|
|
2
|
+
import{a as C,b as V,c as rt,d as ue}from"./chunk-4LDJX6BW.mjs";import{spawn as En}from"child_process";import{execFileSync as ln,spawn as dn}from"child_process";import{createHash as un,randomUUID as Ge}from"crypto";import{mkdir as pn,readFile as $t,readdir as hn,stat as fn,unlink as mn,writeFile as Ae}from"fs/promises";import{createServer as gn}from"http";import{tmpdir as yn}from"os";import{basename as wn,dirname as vn,join as ie}from"path";import{fileURLToPath as Sn}from"url";function it(r,e){return`<!DOCTYPE html>
|
|
3
3
|
<html>
|
|
4
4
|
<head>
|
|
5
5
|
<meta charset="utf-8">
|
|
@@ -26,8 +26,9 @@ import{a as C,b as V,c as ot,d as ue}from"./chunk-4LDJX6BW.mjs";import{spawn as
|
|
|
26
26
|
});
|
|
27
27
|
</script>
|
|
28
28
|
</body>
|
|
29
|
-
</html>`}import{spawn as At}from"child_process";import{createInterface as _t}from"readline";function $e(r,e){let{prompt:t,projectRoot:n,maxTurns:o=40,maxBudgetUsd:i=1,allowedTools:l=["Read","Edit","Write","Glob","Grep","Bash"],claudePath:c="claude",resumeSessionId:p,model:d,timeoutMs:S=3e5,onEvent:x}=e,k=[];p?k.push("--resume",p,"-p",t):k.push("-p",t),k.push("--output-format","stream-json","--verbose","--max-turns",String(o),"--max-budget-usd",String(i)),d&&k.push("--model",d);for(let F of l)k.push("--allowedTools",F);let y=At(c,k,{cwd:n,stdio:["ignore","pipe","pipe"],env:V(C({},process.env),{ANTHROPIC_API_KEY:void 0})}),J=new Promise(F=>{var N;let U,I=[],L=[],D=!1,j="",W=!1,oe=setTimeout(()=>{W=!0,y.kill("SIGTERM"),setTimeout(()=>{try{y.kill("SIGKILL")}catch(T){}},5e3)},S),A=_t({input:y.stdout}),z=new Set;A.on("line",T=>{var H,ne,he,ve,Se,xe,Pe,Ie,be;if(T.trim())try{let Q=JSON.parse(T);Q.session_id&&!U&&(U=Q.session_id);let Ae=(ne=Q.type)!=null?ne:(H=Q.event)!=null&&H.type?`event.${Q.event.type}`:"unknown";if(z.add(Ae),Q.type==="result"&&Q.result&&I.length===0){let _=typeof Q.result=="string"?Q.result:"";_&&(I.push(_),x==null||x({type:"delta",jobId:r,text:_},r))}if(Q.type==="assistant"&&Array.isArray((he=Q.message)==null?void 0:he.content))for(let _ of Q.message.content){if(_.type==="text"&&_.text&&(I.push(_.text),x==null||x({type:"delta",jobId:r,text:_.text},r)),_.type==="tool_use"&&_.name){let ke=((ve=_.input)==null?void 0:ve.file_path)||((Se=_.input)==null?void 0:Se.path)||void 0;x==null||x(C({type:"tool_use",jobId:r,tool:_.name},ke?{file:ke}:{}),r),_.name==="Edit"&&((xe=_.input)!=null&&xe.file_path)?L.push({tool:"Edit",file_path:_.input.file_path,old_string:_.input.old_string,new_string:_.input.new_string,replace_all:_.input.replace_all}):_.name==="Write"&&((Pe=_.input)!=null&&Pe.file_path)&&L.push({tool:"Write",file_path:_.input.file_path,content:_.input.content})}_.type==="thinking"&&_.thinking&&(x==null||x({type:"thinking",jobId:r,text:_.thinking},r))}Q.type==="user"&&((be=(Ie=Q.tool_use_result)==null?void 0:Ie.file)!=null&&be.filePath)&&(x==null||x({type:"tool_use",jobId:r,tool:"Read",file:Q.tool_use_result.file.filePath},r))}catch(Q){}});let g=[];(N=y.stderr)==null||N.on("data",T=>{g.push(T.toString())}),y.on("close",T=>{if(clearTimeout(oe),A.close(),I.length===0&&z.size>0&&console.warn(`[Claude:${r}] No text captured. Event types seen: ${[...z].join(", ")}`),W)D=!0,j=`Timed out after ${Math.round(S/6e4)} minutes`;else if(T!==0&&T!==null){D=!0;let H=g.join("").trim(),ne=I.length===0&&z.size>0?` (no text captured, event types: ${[...z].join(", ")})`:"";j=H||`Claude process exited with code ${T}${ne}`}F({sessionId:U,text:I.join(""),success:!D,error:D?j:void 0,fileEdits:L.length>0?L:void 0})}),y.on("error",T=>{clearTimeout(oe),D=!0,j=T.message,F({sessionId:U,text:I.join(""),success:!1,error:j,fileEdits:L.length>0?L:void 0})})});return{process:y,result:J}}import{spawn as Nt}from"child_process";import{createInterface as Bt}from"readline";function it(r,e){let{prompt:t,projectRoot:n,screenshotPath:o,resumeSessionId:i,model:l,onEvent:c}=e,p=[];i?(p.push("exec","resume",i),l&&p.push("-m",l),p.push("--json","--full-auto",t),o&&p.push("--image",o)):(p.push("exec","--json","--full-auto"),l&&p.push("-m",l),p.push(t),o&&p.push("--image",o));let d=Nt("codex",p,{cwd:n,stdio:["ignore","pipe","pipe"],env:C({},process.env)}),S=new Promise(x=>{var D;let k,y=[],J=!1,F="",U=Bt({input:d.stdout}),I=new Set;U.on("line",j=>{var W,oe,A,z;if(j.trim())try{let g=JSON.parse(j),N=(W=g.type)!=null?W:"unknown";if(I.add(N),N==="thread.started"&&g.thread_id&&!k&&(k=g.thread_id),(N==="item.agentMessage.delta"||N==="item/agentMessage/delta")&&((oe=g.delta)!=null&&oe.text)&&(y.push(g.delta.text),c==null||c({type:"delta",jobId:r,text:g.delta.text},r)),(N==="item.reasoning.delta"||N==="item/reasoning/delta")&&((A=g.delta)!=null&&A.text)&&(c==null||c({type:"thinking",jobId:r,text:g.delta.text},r)),(N==="item.started"||N==="item/started")&&g.item){let T=g.item.type;if(T==="command_execution")c==null||c({type:"tool_use",jobId:r,tool:"Bash"},r);else if(T==="file_change"){let H=g.item.filename||g.item.path;c==null||c(C({type:"tool_use",jobId:r,tool:"Edit"},H?{file:H}:{}),r)}else if(T==="file_read"){let H=g.item.filename||g.item.path;c==null||c(C({type:"tool_use",jobId:r,tool:"Read"},H?{file:H}:{}),r)}else if(T==="web_search")c==null||c({type:"tool_use",jobId:r,tool:"WebSearch"},r);else if(T==="mcp_tool_call"){let H=g.item.tool_name||g.item.name||"MCP";c==null||c({type:"tool_use",jobId:r,tool:H},r)}}if((N==="item.completed"||N==="item/completed")&&g.item){if(g.item.type==="agent_message"){let T=g.item.text;typeof T=="string"&&T&&(y.push(T),c==null||c({type:"delta",jobId:r,text:T},r))}else if(g.item.type==="reasoning"){let T=g.item.text;typeof T=="string"&&T&&(c==null||c({type:"thinking",jobId:r,text:T},r))}}N==="turn.failed"&&(J=!0,F=((z=g.error)==null?void 0:z.message)||g.message||"Turn failed")}catch(g){}});let L=[];(D=d.stderr)==null||D.on("data",j=>{L.push(j.toString())}),d.on("close",j=>{U.close(),y.length===0&&I.size>0&&console.warn(`[Codex:${r}] No text captured. Event types seen: ${[...I].join(", ")}`),j!==0&&j!==null&&(J=!0,F=L.join("")||`Codex process exited with code ${j}`),x({sessionId:k,text:y.join(""),success:!J,error:J?F:void 0})}),d.on("error",j=>{J=!0,F=j.message,x({sessionId:k,text:y.join(""),success:!1,error:F})})});return{process:d,result:S}}import{execFile as Jt}from"child_process";import{copyFile as at,mkdir as ct,readdir as Ut,readFile as Ft,writeFile as Lt}from"fs/promises";import{join as pe}from"path";var Re=class{constructor(e){this.projectRoot=e;let t=pe(e,".popmelt");this.decisionsDir=pe(t,"decisions"),this.screenshotsDir=pe(t,"screenshots")}async persist(e,t,n){try{await ct(this.decisionsDir,{recursive:!0}),await ct(this.screenshotsDir,{recursive:!0});try{await at(t,pe(this.screenshotsDir,`s-${e.id}.png`))}catch(o){}for(let o=0;o<n.length;o++)try{let i=e.pastedImagePaths[o];i&&await at(n[o],pe(this.screenshotsDir,i.replace("screenshots/","")))}catch(i){}await Lt(pe(this.decisionsDir,`d-${e.id}.json`),JSON.stringify(e,null,2))}catch(o){console.error("[DecisionStore] Failed to persist decision record:",o)}}async listDecisionIds(){try{return(await Ut(this.decisionsDir)).filter(t=>t.startsWith("d-")&&t.endsWith(".json")).map(t=>t.slice(2,-5))}catch(e){return[]}}async loadDecision(e){try{let t=await Ft(pe(this.decisionsDir,`d-${e}.json`),"utf-8");return JSON.parse(t)}catch(t){return null}}async loadDecisions(e){return(await Promise.all(e.map(n=>this.loadDecision(n)))).filter(n=>n!==null)}captureGitDiff(e){return new Promise(t=>{Jt("git",["diff","HEAD"],{cwd:e,timeout:5e3,maxBuffer:1024*1024},(n,o)=>{if(n){t(null);return}t(o||null)})})}};import{readFile as lt,writeFile as me}from"fs/promises";import{join as Ne}from"path";var re="[Materializer]",jt={version:1,materializedIds:[],lastRunAt:null,lastRunDecisionIds:[],lastRunError:null},Me=class{constructor(e,t,n={}){this.projectRoot=e;this.decisionStore=t;this.options=n;this.cachedIndex=null;this.running=!1;let o=Ne(e,".popmelt");this.indexPath=Ne(o,"materialized.json"),this.modelPath=Ne(o,"model.json")}get isRunning(){return this.running}async loadModel(){try{let e=await lt(this.modelPath,"utf-8");return JSON.parse(e)}catch(e){return null}}async addComponent(e){let t=await this.loadModel();t||(t={tokens:{},components:{},rules:[]}),(!t.components||typeof t.components!="object")&&(t.components={});let n=t.components;return n[e]?{added:!1,alreadyExists:!0}:(n[e]={description:""},await me(this.modelPath,JSON.stringify(t,null,2)),console.log(`${re} Added component "${e}" to model`),{added:!0,alreadyExists:!1})}async updateToken(e,t){let n=await this.loadModel();n||(n={tokens:{},components:{},rules:[]});let o=e.split("."),i=n;for(let p=0;p<o.length-1;p++){let d=o[p];(!i[d]||typeof i[d]!="object")&&(i[d]={}),i=i[d]}let l=o[o.length-1],c;try{c=JSON.parse(t)}catch(p){c=null}if(c&&typeof c=="object"&&c!==null&&"value"in c)i[l]=c;else{let p=i[l];p&&typeof p=="object"&&p!==null&&"value"in p?p.value=t:i[l]=t}return await me(this.modelPath,JSON.stringify(n,null,2)),console.log(`${re} Updated token "${e}" \u2192 "${t.slice(0,80)}"`),{updated:!0}}async removeToken(e){let t=await this.loadModel();if(!t)return{removed:!1};let n=e.split("."),o=t;for(let l=0;l<n.length-1;l++){let c=n[l];if(!o[c]||typeof o[c]!="object")return{removed:!1};o=o[c]}let i=n[n.length-1];return i in o?(delete o[i],await me(this.modelPath,JSON.stringify(t,null,2)),console.log(`${re} Removed token "${e}" from model`),{removed:!0}):{removed:!1}}async removeComponent(e){let t=await this.loadModel();if(!t)return{removed:!1};let n=t.components;return!n||!n[e]?{removed:!1}:(delete n[e],await me(this.modelPath,JSON.stringify(t,null,2)),console.log(`${re} Removed component "${e}" from model`),{removed:!0})}async getUnmaterializedPatternDecisions(){let e=await this.loadIndex(),t=new Set(e.materializedIds),o=(await this.decisionStore.listDecisionIds()).filter(l=>!t.has(l));return o.length===0?[]:(await this.decisionStore.loadDecisions(o)).filter(l=>l.resolutions.some(c=>{var d;let p=(d=c.finalScope)!=null?d:c.inferredScope;return(p==null?void 0:p.breadth)==="pattern"}))}async run(){var e,t,n,o,i,l,c;if(this.running)return{processedIds:[],success:!0,error:"Already running"};this.running=!0;try{let p=await this.getUnmaterializedPatternDecisions();if(p.length===0)return{processedIds:[],success:!0};let d=p.map(U=>U.id);console.log(`${re} Processing ${d.length} pattern-scoped decision(s): ${d.join(", ")}`),(t=(e=this.options).onEvent)==null||t.call(e,{type:"materialize_started",decisionIds:d});let S=await this.loadModel(),x=Ht(p,S),k=!0,y;try{let{result:U}=$e(`mat-${Date.now()}`,{prompt:x,projectRoot:this.projectRoot,maxTurns:(n=this.options.maxTurns)!=null?n:5,maxBudgetUsd:(o=this.options.maxBudgetUsd)!=null?o:.5,allowedTools:["Read"],claudePath:(i=this.options.claudePath)!=null?i:"claude"}),I=await U;if(!I.success)k=!1,y=I.error,console.error(`${re} Claude spawn error:`,y);else{let L=zt(I.text);L?(await me(this.modelPath,JSON.stringify(L,null,2)),console.log(`${re} Successfully materialized ${d.length} decision(s) \u2192 ${this.modelPath}`)):(k=!1,y="No <model> block found in response",console.error(`${re} ${y}`))}}catch(U){k=!1,y=U instanceof Error?U.message:String(U),console.error(`${re} Error:`,y)}let J=await this.loadIndex(),F=new Set(J.materializedIds);for(let U of d)F.add(U);return J.materializedIds=[...F],J.lastRunAt=Date.now(),J.lastRunDecisionIds=d,J.lastRunError=y!=null?y:null,await this.persistIndex(J),(c=(l=this.options).onEvent)==null||c.call(l,{type:"materialize_done",decisionIds:d,success:k,error:y}),{processedIds:d,success:k,error:y}}finally{this.running=!1}}async loadIndex(){if(this.cachedIndex)return this.cachedIndex;try{let e=await lt(this.indexPath,"utf-8"),t=JSON.parse(e);return this.cachedIndex=t,t}catch(e){return this.cachedIndex=V(C({},jt),{materializedIds:[],lastRunDecisionIds:[]}),this.cachedIndex}}async persistIndex(e){this.cachedIndex=e;try{await me(this.indexPath,JSON.stringify(e,null,2))}catch(t){console.error(`${re} Failed to write index:`,t)}}};function zt(r){let e=r.match(/<model>\s*([\s\S]*?)\s*<\/model>/);if(!(e!=null&&e[1]))return null;try{let t=JSON.parse(e[1]);return typeof t!="object"||t===null||Array.isArray(t)?null:t}catch(t){return null}}function Ht(r,e){let t=r.map(o=>{let l=o.resolutions.filter(d=>{var x;let S=(x=d.finalScope)!=null?x:d.inferredScope;return(S==null?void 0:S.breadth)==="pattern"}).map(d=>{var y,J,F,U;let S=(y=d.finalScope)!=null?y:d.inferredScope,x=(J=S==null?void 0:S.target)!=null?J:"unknown",k=(U=(F=d.filesModified)==null?void 0:F.join(", "))!=null?U:"none";return`- **${d.summary}** [scope: pattern/${x}]
|
|
30
|
-
Files modified: ${k}`}).join(`
|
|
29
|
+
</html>`}import{spawn as Dt}from"child_process";import{createInterface as Nt}from"readline";var Bt=new Set([".md",".txt",".json",".ts",".tsx",".js",".jsx",".css",".scss",".html",".xml",".yaml",".yml",".toml",".ini",".cfg",".conf",".sh",".bash",".zsh",".py",".rb",".go",".rs",".java",".c",".h",".cpp",".hpp",".swift",".kt",".sql",".graphql",".svg",".env",".gitignore",".prettierrc",".eslintrc"]),at=1e5;function Jt(r){var o,i,l,c;let e=((o=r.input)==null?void 0:o.file_path)||((i=r.input)==null?void 0:i.path);if(!e)return;let t=e.includes(".")?`.${e.split(".").pop().toLowerCase()}`:"";if(!Bt.has(t))return;let n;if(r.name==="Write"&&typeof((l=r.input)==null?void 0:l.content)=="string"?n=r.input.content:r.name==="Edit"&&typeof((c=r.input)==null?void 0:c.new_string)=="string"&&(n=r.input.new_string),!!n)return n.length>at?n.slice(0,at)+`
|
|
30
|
+
\u2026[truncated]`:n}function Re(r,e){let{prompt:t,projectRoot:n,maxTurns:o=40,maxBudgetUsd:i=1,allowedTools:l=["Read","Edit","Write","Glob","Grep","Bash"],claudePath:c="claude",resumeSessionId:p,model:d,timeoutMs:S=3e5,onEvent:x}=e,b=[];p?b.push("--resume",p,"-p",t):b.push("-p",t),b.push("--output-format","stream-json","--verbose","--max-turns",String(o),"--max-budget-usd",String(i)),d&&b.push("--model",d);for(let F of l)b.push("--allowedTools",F);let y=Dt(c,b,{cwd:n,stdio:["ignore","pipe","pipe"],env:V(C({},process.env),{ANTHROPIC_API_KEY:void 0})}),J=new Promise(F=>{var N;let U,P=[],L=[],A=!1,j="",W=!1,oe=setTimeout(()=>{W=!0,y.kill("SIGTERM"),setTimeout(()=>{try{y.kill("SIGKILL")}catch(k){}},5e3)},S),D=Nt({input:y.stdout}),z=new Set;D.on("line",k=>{var H,ne,he,ve,Se,xe,Ie,Pe,Te;if(k.trim())try{let Q=JSON.parse(k);Q.session_id&&!U&&(U=Q.session_id);let De=(ne=Q.type)!=null?ne:(H=Q.event)!=null&&H.type?`event.${Q.event.type}`:"unknown";if(z.add(De),Q.type==="result"&&Q.result&&P.length===0){let O=typeof Q.result=="string"?Q.result:"";O&&(P.push(O),x==null||x({type:"delta",jobId:r,text:O},r))}if(Q.type==="assistant"&&Array.isArray((he=Q.message)==null?void 0:he.content))for(let O of Q.message.content){if(O.type==="text"&&O.text&&(P.push(O.text),x==null||x({type:"delta",jobId:r,text:O.text},r)),O.type==="tool_use"&&O.name){let be=((ve=O.input)==null?void 0:ve.file_path)||((Se=O.input)==null?void 0:Se.path)||void 0,ke=Jt(O);x==null||x(C(C({type:"tool_use",jobId:r,tool:O.name},be?{file:be}:{}),ke?{content:ke}:{}),r),O.name==="Edit"&&((xe=O.input)!=null&&xe.file_path)?L.push({tool:"Edit",file_path:O.input.file_path,old_string:O.input.old_string,new_string:O.input.new_string,replace_all:O.input.replace_all}):O.name==="Write"&&((Ie=O.input)!=null&&Ie.file_path)&&L.push({tool:"Write",file_path:O.input.file_path,content:O.input.content})}O.type==="thinking"&&O.thinking&&(x==null||x({type:"thinking",jobId:r,text:O.thinking},r))}Q.type==="user"&&((Te=(Pe=Q.tool_use_result)==null?void 0:Pe.file)!=null&&Te.filePath)&&(x==null||x({type:"tool_use",jobId:r,tool:"Read",file:Q.tool_use_result.file.filePath},r))}catch(Q){}});let g=[];(N=y.stderr)==null||N.on("data",k=>{g.push(k.toString())}),y.on("close",k=>{if(clearTimeout(oe),D.close(),P.length===0&&z.size>0&&console.warn(`[Claude:${r}] No text captured. Event types seen: ${[...z].join(", ")}`),W)A=!0,j=`Timed out after ${Math.round(S/6e4)} minutes`;else if(k!==0&&k!==null){A=!0;let H=g.join("").trim(),ne=P.length===0&&z.size>0?` (no text captured, event types: ${[...z].join(", ")})`:"";j=H||`Claude process exited with code ${k}${ne}`}F({sessionId:U,text:P.join(""),success:!A,error:A?j:void 0,fileEdits:L.length>0?L:void 0})}),y.on("error",k=>{clearTimeout(oe),A=!0,j=k.message,F({sessionId:U,text:P.join(""),success:!1,error:j,fileEdits:L.length>0?L:void 0})})});return{process:y,result:J}}import{spawn as Ut}from"child_process";import{createInterface as Ft}from"readline";function ct(r,e){let{prompt:t,projectRoot:n,screenshotPath:o,resumeSessionId:i,model:l,onEvent:c}=e,p=[];i?(p.push("exec","resume",i),l&&p.push("-m",l),p.push("--json","--full-auto",t),o&&p.push("--image",o)):(p.push("exec","--json","--full-auto"),l&&p.push("-m",l),p.push(t),o&&p.push("--image",o));let d=Ut("codex",p,{cwd:n,stdio:["ignore","pipe","pipe"],env:C({},process.env)}),S=new Promise(x=>{var A;let b,y=[],J=!1,F="",U=Ft({input:d.stdout}),P=new Set;U.on("line",j=>{var W,oe,D,z;if(j.trim())try{let g=JSON.parse(j),N=(W=g.type)!=null?W:"unknown";if(P.add(N),N==="thread.started"&&g.thread_id&&!b&&(b=g.thread_id),(N==="item.agentMessage.delta"||N==="item/agentMessage/delta")&&((oe=g.delta)!=null&&oe.text)&&(y.push(g.delta.text),c==null||c({type:"delta",jobId:r,text:g.delta.text},r)),(N==="item.reasoning.delta"||N==="item/reasoning/delta")&&((D=g.delta)!=null&&D.text)&&(c==null||c({type:"thinking",jobId:r,text:g.delta.text},r)),(N==="item.started"||N==="item/started")&&g.item){let k=g.item.type;if(k==="command_execution")c==null||c({type:"tool_use",jobId:r,tool:"Bash"},r);else if(k==="file_change"){let H=g.item.filename||g.item.path;c==null||c(C({type:"tool_use",jobId:r,tool:"Edit"},H?{file:H}:{}),r)}else if(k==="file_read"){let H=g.item.filename||g.item.path;c==null||c(C({type:"tool_use",jobId:r,tool:"Read"},H?{file:H}:{}),r)}else if(k==="web_search")c==null||c({type:"tool_use",jobId:r,tool:"WebSearch"},r);else if(k==="mcp_tool_call"){let H=g.item.tool_name||g.item.name||"MCP";c==null||c({type:"tool_use",jobId:r,tool:H},r)}}if((N==="item.completed"||N==="item/completed")&&g.item){if(g.item.type==="agent_message"){let k=g.item.text;typeof k=="string"&&k&&(y.push(k),c==null||c({type:"delta",jobId:r,text:k},r))}else if(g.item.type==="reasoning"){let k=g.item.text;typeof k=="string"&&k&&(c==null||c({type:"thinking",jobId:r,text:k},r))}}N==="turn.failed"&&(J=!0,F=((z=g.error)==null?void 0:z.message)||g.message||"Turn failed")}catch(g){}});let L=[];(A=d.stderr)==null||A.on("data",j=>{L.push(j.toString())}),d.on("close",j=>{U.close(),y.length===0&&P.size>0&&console.warn(`[Codex:${r}] No text captured. Event types seen: ${[...P].join(", ")}`),j!==0&&j!==null&&(J=!0,F=L.join("")||`Codex process exited with code ${j}`),x({sessionId:b,text:y.join(""),success:!J,error:J?F:void 0})}),d.on("error",j=>{J=!0,F=j.message,x({sessionId:b,text:y.join(""),success:!1,error:F})})});return{process:d,result:S}}import{execFile as Lt}from"child_process";import{copyFile as lt,mkdir as dt,readdir as jt,readFile as zt,writeFile as Ht}from"fs/promises";import{join as pe}from"path";var Me=class{constructor(e){this.projectRoot=e;let t=pe(e,".popmelt");this.decisionsDir=pe(t,"decisions"),this.screenshotsDir=pe(t,"screenshots")}async persist(e,t,n){try{await dt(this.decisionsDir,{recursive:!0}),await dt(this.screenshotsDir,{recursive:!0});try{await lt(t,pe(this.screenshotsDir,`s-${e.id}.png`))}catch(o){}for(let o=0;o<n.length;o++)try{let i=e.pastedImagePaths[o];i&&await lt(n[o],pe(this.screenshotsDir,i.replace("screenshots/","")))}catch(i){}await Ht(pe(this.decisionsDir,`d-${e.id}.json`),JSON.stringify(e,null,2))}catch(o){console.error("[DecisionStore] Failed to persist decision record:",o)}}async listDecisionIds(){try{return(await jt(this.decisionsDir)).filter(t=>t.startsWith("d-")&&t.endsWith(".json")).map(t=>t.slice(2,-5))}catch(e){return[]}}async loadDecision(e){try{let t=await zt(pe(this.decisionsDir,`d-${e}.json`),"utf-8");return JSON.parse(t)}catch(t){return null}}async loadDecisions(e){return(await Promise.all(e.map(n=>this.loadDecision(n)))).filter(n=>n!==null)}captureGitDiff(e){return new Promise(t=>{Lt("git",["diff","HEAD"],{cwd:e,timeout:5e3,maxBuffer:1024*1024},(n,o)=>{if(n){t(null);return}t(o||null)})})}};import{readFile as ut,writeFile as me}from"fs/promises";import{join as Be}from"path";var re="[Materializer]",Gt={version:1,materializedIds:[],lastRunAt:null,lastRunDecisionIds:[],lastRunError:null},Ee=class{constructor(e,t,n={}){this.projectRoot=e;this.decisionStore=t;this.options=n;this.cachedIndex=null;this.running=!1;let o=Be(e,".popmelt");this.indexPath=Be(o,"materialized.json"),this.modelPath=Be(o,"model.json")}get isRunning(){return this.running}async loadModel(){try{let e=await ut(this.modelPath,"utf-8");return JSON.parse(e)}catch(e){return null}}async addComponent(e){let t=await this.loadModel();t||(t={tokens:{},components:{},rules:[]}),(!t.components||typeof t.components!="object")&&(t.components={});let n=t.components;return n[e]?{added:!1,alreadyExists:!0}:(n[e]={description:""},await me(this.modelPath,JSON.stringify(t,null,2)),console.log(`${re} Added component "${e}" to model`),{added:!0,alreadyExists:!1})}async updateToken(e,t){let n=await this.loadModel();n||(n={tokens:{},components:{},rules:[]});let o=e.split("."),i=n;for(let p=0;p<o.length-1;p++){let d=o[p];(!i[d]||typeof i[d]!="object")&&(i[d]={}),i=i[d]}let l=o[o.length-1],c;try{c=JSON.parse(t)}catch(p){c=null}if(c&&typeof c=="object"&&c!==null&&"value"in c)i[l]=c;else{let p=i[l];p&&typeof p=="object"&&p!==null&&"value"in p?p.value=t:i[l]=t}return await me(this.modelPath,JSON.stringify(n,null,2)),console.log(`${re} Updated token "${e}" \u2192 "${t.slice(0,80)}"`),{updated:!0}}async removeToken(e){let t=await this.loadModel();if(!t)return{removed:!1};let n=e.split("."),o=t;for(let l=0;l<n.length-1;l++){let c=n[l];if(!o[c]||typeof o[c]!="object")return{removed:!1};o=o[c]}let i=n[n.length-1];return i in o?(delete o[i],await me(this.modelPath,JSON.stringify(t,null,2)),console.log(`${re} Removed token "${e}" from model`),{removed:!0}):{removed:!1}}async removeComponent(e){let t=await this.loadModel();if(!t)return{removed:!1};let n=t.components;return!n||!n[e]?{removed:!1}:(delete n[e],await me(this.modelPath,JSON.stringify(t,null,2)),console.log(`${re} Removed component "${e}" from model`),{removed:!0})}async getUnmaterializedPatternDecisions(){let e=await this.loadIndex(),t=new Set(e.materializedIds),o=(await this.decisionStore.listDecisionIds()).filter(l=>!t.has(l));return o.length===0?[]:(await this.decisionStore.loadDecisions(o)).filter(l=>l.resolutions.some(c=>{var d;let p=(d=c.finalScope)!=null?d:c.inferredScope;return(p==null?void 0:p.breadth)==="pattern"}))}async run(){var e,t,n,o,i,l,c;if(this.running)return{processedIds:[],success:!0,error:"Already running"};this.running=!0;try{let p=await this.getUnmaterializedPatternDecisions();if(p.length===0)return{processedIds:[],success:!0};let d=p.map(U=>U.id);console.log(`${re} Processing ${d.length} pattern-scoped decision(s): ${d.join(", ")}`),(t=(e=this.options).onEvent)==null||t.call(e,{type:"materialize_started",decisionIds:d});let S=await this.loadModel(),x=qt(p,S),b=!0,y;try{let{result:U}=Re(`mat-${Date.now()}`,{prompt:x,projectRoot:this.projectRoot,maxTurns:(n=this.options.maxTurns)!=null?n:5,maxBudgetUsd:(o=this.options.maxBudgetUsd)!=null?o:.5,allowedTools:["Read"],claudePath:(i=this.options.claudePath)!=null?i:"claude"}),P=await U;if(!P.success)b=!1,y=P.error,console.error(`${re} Claude spawn error:`,y);else{let L=Wt(P.text);L?(await me(this.modelPath,JSON.stringify(L,null,2)),console.log(`${re} Successfully materialized ${d.length} decision(s) \u2192 ${this.modelPath}`)):(b=!1,y="No <model> block found in response",console.error(`${re} ${y}`))}}catch(U){b=!1,y=U instanceof Error?U.message:String(U),console.error(`${re} Error:`,y)}let J=await this.loadIndex(),F=new Set(J.materializedIds);for(let U of d)F.add(U);return J.materializedIds=[...F],J.lastRunAt=Date.now(),J.lastRunDecisionIds=d,J.lastRunError=y!=null?y:null,await this.persistIndex(J),(c=(l=this.options).onEvent)==null||c.call(l,{type:"materialize_done",decisionIds:d,success:b,error:y}),{processedIds:d,success:b,error:y}}finally{this.running=!1}}async loadIndex(){if(this.cachedIndex)return this.cachedIndex;try{let e=await ut(this.indexPath,"utf-8"),t=JSON.parse(e);return this.cachedIndex=t,t}catch(e){return this.cachedIndex=V(C({},Gt),{materializedIds:[],lastRunDecisionIds:[]}),this.cachedIndex}}async persistIndex(e){this.cachedIndex=e;try{await me(this.indexPath,JSON.stringify(e,null,2))}catch(t){console.error(`${re} Failed to write index:`,t)}}};function Wt(r){let e=r.match(/<model>\s*([\s\S]*?)\s*<\/model>/);if(!(e!=null&&e[1]))return null;try{let t=JSON.parse(e[1]);return typeof t!="object"||t===null||Array.isArray(t)?null:t}catch(t){return null}}function qt(r,e){let t=r.map(o=>{let l=o.resolutions.filter(d=>{var x;let S=(x=d.finalScope)!=null?x:d.inferredScope;return(S==null?void 0:S.breadth)==="pattern"}).map(d=>{var y,J,F,U;let S=(y=d.finalScope)!=null?y:d.inferredScope,x=(J=S==null?void 0:S.target)!=null?J:"unknown",b=(U=(F=d.filesModified)==null?void 0:F.join(", "))!=null?U:"none";return`- **${d.summary}** [scope: pattern/${x}]
|
|
31
|
+
Files modified: ${b}`}).join(`
|
|
31
32
|
`),c=o.annotations.map(d=>d.instruction).filter(Boolean).join(`
|
|
32
33
|
`),p=o.gitDiff?`
|
|
33
34
|
\`\`\`diff
|
|
@@ -94,39 +95,39 @@ Example:
|
|
|
94
95
|
{ "value": "8px", "property": "gap", "bindings": ["gap-2"] }
|
|
95
96
|
- property: "gap", "padding", or "margin" \u2014 which CSS property this token controls
|
|
96
97
|
- bindings: Tailwind class names (without responsive prefixes) that use this token
|
|
97
|
-
Include property and bindings when the decision context has class-level evidence.`}import{readFile as
|
|
98
|
-
`),t=[],n=null;for(let o of e){let i=o.match(
|
|
98
|
+
Include property and bindings when the decision context has class-level evidence.`}import{readFile as ft}from"fs/promises";import{homedir as mt}from"os";import{join as ge}from"path";var Ue=/popmelt/i;function Fe(){return{found:!1,name:null,scope:null,disabled:!1}}function ye(r,e,t=!1){return{found:!0,name:r,scope:e,disabled:t}}function Ce(r){for(let e of Object.keys(r))if(Ue.test(e))return e;return null}async function Je(r){try{let e=await ft(r,"utf-8");return JSON.parse(e)}catch(e){return null}}async function Le(r){let e=mt(),t=await Je(ge(e,".claude.json"));if(t&&typeof t=="object"){let o=t;if(o.mcpServers&&typeof o.mcpServers=="object"){let i=Ce(o.mcpServers);if(i)return ye(i,"user")}if(o.projects&&typeof o.projects=="object"){let l=o.projects[r];if(l&&typeof l=="object"){let c=l;if(c.mcpServers&&typeof c.mcpServers=="object"){let p=Ce(c.mcpServers);if(p){let d=Array.isArray(c.disabledMcpjsonServers)&&c.disabledMcpjsonServers.some(S=>Ue.test(S));return ye(p,"project",d)}}}}}let n=await Je(ge(r,".mcp.json"));if(n&&typeof n=="object"){let o=n;if(o.mcpServers&&typeof o.mcpServers=="object"){let l=Ce(o.mcpServers);if(l){let c=await pt(r,l);return ye(l,"mcp.json",c)}}let i=Ce(o);if(i&&i!=="mcpServers"){let l=await pt(r,i);return ye(i,"mcp.json",l)}}return Fe()}async function pt(r,e){let t=ge(r,".claude","settings.local.json"),n=await Je(t);if(n&&typeof n=="object"){let o=n;if(Array.isArray(o.disabledMcpjsonServers))return o.disabledMcpjsonServers.some(i=>i===e)}return!1}var Qt=/^\[mcp_servers\.([^\]]+)\]/;function Xt(r){let e=r.split(`
|
|
99
|
+
`),t=[],n=null;for(let o of e){let i=o.match(Qt);i?(n&&t.push({name:n.name,body:n.bodyLines.join(`
|
|
99
100
|
`)}),n={name:i[1],bodyLines:[]}):o.startsWith("[")?n&&(t.push({name:n.name,body:n.bodyLines.join(`
|
|
100
101
|
`)}),n=null):n&&n.bodyLines.push(o)}return n&&t.push({name:n.name,body:n.bodyLines.join(`
|
|
101
|
-
`)}),t}function
|
|
102
|
-
`,"utf-8"),{installed:!0,provider:"claude",scope:"user"}}async function
|
|
102
|
+
`)}),t}function Yt(r){return/enabled\s*=\s*false/i.test(r)}async function je(r){let e=process.env.CODEX_HOME||ge(mt(),".codex"),t=await ht(ge(e,"config.toml"),"user");if(t.found)return t;let n=await ht(ge(r,".codex","config.toml"),"project");return n.found?n:Fe()}async function ht(r,e){try{let t=await ft(r,"utf-8"),n=Xt(t);for(let o of n)if(Ue.test(o.name)){let i=Yt(o.body);return ye(o.name,e,i)}}catch(t){}return Fe()}import{mkdir as Vt,readFile as gt,writeFile as yt}from"fs/promises";import{homedir as wt}from"os";import{dirname as Kt,join as ze}from"path";var vt="https://mcp.popmelt.com/mcp";async function St(r=vt){let e=ze(wt(),".claude.json"),t;try{let o=await gt(e,"utf-8");t=JSON.parse(o)}catch(o){t={}}(!t.mcpServers||typeof t.mcpServers!="object")&&(t.mcpServers={});let n=t.mcpServers;for(let o of Object.keys(n))if(/popmelt/i.test(o))return{installed:!1,provider:"claude",scope:null,reason:"already_configured"};return n.popmelt={type:"http",url:r},await yt(e,JSON.stringify(t,null,2)+`
|
|
103
|
+
`,"utf-8"),{installed:!0,provider:"claude",scope:"user"}}async function xt(r=vt){let e=process.env.CODEX_HOME||ze(wt(),".codex"),t=ze(e,"config.toml"),n;try{n=await gt(t,"utf-8")}catch(i){n=""}if(/\[mcp_servers\.[^\]]*popmelt[^\]]*\]/i.test(n))return{installed:!1,provider:"codex",scope:null,reason:"already_configured"};await Vt(Kt(t),{recursive:!0});let o=`
|
|
103
104
|
[mcp_servers.popmelt]
|
|
104
105
|
url = "${r}"
|
|
105
|
-
`;return await
|
|
106
|
+
`;return await yt(t,n+o,"utf-8"),{installed:!0,provider:"codex",scope:"user"}}async function He(r){let t=(r.headers["content-type"]||"").match(/boundary=(?:"([^"]+)"|([^\s;]+))/);if(!t)throw new Error("Missing multipart boundary");let n=t[1]||t[2],o=await Zt(r),i=Buffer.from(`--${n}`),l=Buffer.from(`--${n}--`),c,p,d,S,x,b,y,J,F,U,P,L,A=[],j=[],W=0,oe=[];for(;W<o.length;){let D=o.indexOf(i,W);if(D===-1)break;let z=D+i.length;if(o.slice(D,D+l.length).equals(l))break;let g=z;o[g]===13&&o[g+1]===10&&(g+=2);let N=o.indexOf(`\r
|
|
106
107
|
\r
|
|
107
|
-
`,g);if(N===-1)break;let
|
|
108
|
+
`,g);if(N===-1)break;let k=o.slice(g,N).toString("utf-8"),H=N+4,ne=o.indexOf(i,H),he=ne!==-1?ne-2:o.length;oe.push({headers:k,body:o.slice(H,he)}),W=ne!==-1?ne:o.length}for(let D of oe){let z=D.headers.match(/name="([^"]+)"/);if(!z)continue;let g=z[1];if(g==="screenshot")c=D.body;else if(g==="feedback")p=D.body.toString("utf-8");else if(g==="color")d=D.body.toString("utf-8");else if(g==="provider")S=D.body.toString("utf-8");else if(g==="model")x=D.body.toString("utf-8");else if(g==="goal")b=D.body.toString("utf-8");else if(g==="pageUrl")y=D.body.toString("utf-8");else if(g==="viewport")J=D.body.toString("utf-8");else if(g==="planId")F=D.body.toString("utf-8");else if(g==="manifest")U=D.body.toString("utf-8");else if(g==="tasks")P=D.body.toString("utf-8");else if(g==="sourceId")L=D.body.toString("utf-8");else if(g.startsWith("screenshot-")){let N=g.slice(11);try{let k=decodeURIComponent(N);j.push({pathname:k,data:D.body})}catch(k){}}else if(g.startsWith("image-")){let N=g.split("-"),k=parseInt(N[N.length-1],10),H=N.slice(1,-1).join("-");H&&!isNaN(k)&&A.push({annotationId:H,index:k,data:D.body})}}if(!c)throw new Error("Missing screenshot field");return p||(p=""),{screenshot:c,feedback:p,color:d,provider:S,model:x,goal:b,pageUrl:y,viewport:J,planId:F,manifest:U,tasks:P,sourceId:L,pastedImages:A,pageScreenshots:j}}function Zt(r){return new Promise((e,t)=>{let n=[];r.on("data",o=>n.push(o)),r.on("end",()=>e(Buffer.concat(n))),r.on("error",t)})}function we(r,e){var n,o;let t=[];if(r.annotations.length>0){t.push("## Annotations");for(let i of r.annotations){let l=i.elements.map(d=>{let S=[d.selector];return d.reactComponent&&S.push(`(${d.reactComponent})`),S.join(" ")}).join(", "),c=i.instruction||"No text";t.push(`- id=${i.id} [${i.type}] ${c} \u2192 Elements: ${l||"none"}`);let p=e==null?void 0:e[i.id];if(p&&p.length>0)for(let d of p)t.push(` Attached image: use the Read tool to view ${d}`)}}if(r.styleModifications.length>0){t.push(""),t.push("## Style Changes (make permanent in source)"),t.push("The developer previewed these CSS changes via inline style overrides. Find the corresponding styles in the source files and update them so the changes persist:");for(let i of r.styleModifications){let l=(n=i.element)!=null&&n.reactComponent?`(${i.element.reactComponent})`:"";for(let c of i.changes)t.push(`- ${i.selector} ${l}: ${c.property} ${c.original} \u2192 ${c.modified}`)}}if((o=r.spacingTokenChanges)!=null&&o.length){t.push(""),t.push("## Spacing Token Changes"),t.push("The developer adjusted these spacing tokens. Apply each change to the source code:");for(let i of r.spacingTokenChanges){t.push(`
|
|
108
109
|
### ${i.tokenName}: ${i.originalPx}px \u2192 ${i.newPx}px`);for(let l of i.affectedElements){let c=l.reactComponent?` (${l.reactComponent})`:"";l.matchedClass&&l.suggestedClass?t.push(`- ${l.selector}${c}: \`${l.matchedClass}\` \u2192 \`${l.suggestedClass}\``):t.push(`- ${l.selector}${c}: ${l.property} ${i.originalPx}px \u2192 ${i.newPx}px`),t.push(` class="${l.className}"`)}}}if(r.inspectedElement){let i=r.inspectedElement;t.push(""),t.push("## Inspected Element"),t.push("The developer has this element selected in the inspector:");let l=[i.selector];i.reactComponent&&l.push(`(${i.reactComponent})`),i.context&&l.push(`in ${i.context}`),i.textContent&&l.push(`"${i.textContent.slice(0,80)}"`),t.push(`- ${l.join(" ")}`)}return t.join(`
|
|
109
|
-
`)}function
|
|
110
|
-
`)}function
|
|
111
|
-
`)}function
|
|
110
|
+
`)}function It(r,e,t){var l,c;let n=[],i=new Set(e.annotations.map(p=>p.pathname).filter(Boolean)).size>1;if(n.push("You are reviewing a UI screenshot with developer annotations."),n.push(""),!i&&(t==null?void 0:t.provider)!=="codex"&&(n.push(`IMPORTANT: First, use the Read tool to view the screenshot at: ${r}`),n.push("")),n.push(`The developer annotated their running app at ${e.url} (${e.viewport.width}x${e.viewport.height}).`),t!=null&&t.threadHistory&&t.threadHistory.length>0){n.push(""),n.push("## Previous Conversation");let p=0;for(let d of t.threadHistory)if(d.role==="human")p++,d.replyToQuestion?(n.push(`### Round ${p} (human) \u2014 reply`),n.push(`"${d.replyToQuestion}"`)):(n.push(`### Round ${p} (human)`),d.feedbackSummary&&n.push(`Annotations: ${d.feedbackSummary}`),d.annotationIds&&d.annotationIds.length>0&&n.push(`Annotation IDs: ${d.annotationIds.join(", ")}`));else if(d.question)n.push(`### Round ${p} (assistant) \u2014 question`),n.push(`"${d.question}"`);else{if(n.push(`### Round ${p} (assistant)`),d.responseText&&n.push(`Response: ${d.responseText}`),d.resolutions&&d.resolutions.length>0)for(let S of d.resolutions){let x=(l=S.finalScope)!=null?l:S.inferredScope,b=x?` [${x.breadth} ${x.target}]`:"";n.push(`- ${S.annotationId}: ${S.status}${b} \u2014 ${S.summary}`),S.filesModified&&S.filesModified.length>0&&n.push(` Files: ${S.filesModified.join(", ")}`)}d.toolsUsed&&d.toolsUsed.length>0&&n.push(`Tools used: ${d.toolsUsed.join(", ")}`)}n.push(""),n.push("The current round is shown in full below.")}if(t!=null&&t.designModel){n.push(""),n.push("## Established Design Policies"),n.push("This project has an established design model (stored in .popmelt/model.json), extracted from the developer's previous design decisions. When making changes, follow these patterns unless the developer explicitly overrides them. When asked about design tokens, component patterns, or design decisions, reference this model as the authoritative source.");let p=t.designModel.rules;if(Array.isArray(p)&&p.length>0){n.push(""),n.push("Rules:");for(let x of p)typeof x=="string"&&n.push(`- ${x}`)}let d=t.designModel.tokens;d&&typeof d=="object"&&(n.push(""),n.push("Design tokens:"),n.push("```json"),n.push(JSON.stringify(d,null,2)),n.push("```"));let S=t.designModel.components;S&&typeof S=="object"&&(n.push(""),n.push("Component patterns:"),n.push("```json"),n.push(JSON.stringify(S,null,2)),n.push("```")),n.push(""),n.push("### Novel Pattern Detection"),n.push("When you make a design decision that has no matching policy in the model above (e.g., styling a component type not yet in the model, choosing a color with no token, picking spacing with no rule), flag it:"),n.push("<novel>"),n.push('[{"category":"component","element":"button","decision":"Used 8px border-radius, 12px 24px padding","reason":"No button pattern in design model"}]'),n.push("</novel>"),n.push('- `category`: "token" (color, spacing, typography), "component" (UI component pattern), or "element" (specific element style)'),n.push("- `element`: What you are styling or creating"),n.push("- `decision`: What you decided to do (specific values)"),n.push("- `reason`: Why this is novel (what is missing from the model)"),n.push("Still do the work \u2014 just flag it so the developer can review and set policy.")}if(t!=null&&t.designModel||(n.push(""),n.push("## Design Context"),n.push("This project uses Popmelt for design governance. Design decisions are stored in .popmelt/decisions/ (JSON files). A materialized design model may exist at .popmelt/model.json. When the developer asks about design tokens, patterns, or past decisions, check these files first before searching source code.")),i){let p=(c=t==null?void 0:t.screenshotPaths)!=null?c:{},d=new Map;for(let S of e.annotations){let x=S.pathname||new URL(e.url).pathname;d.has(x)||d.set(x,[]),d.get(x).push(S)}n.push(""),n.push("The developer annotated multiple pages. Each page section includes its own screenshot where available.");for(let[S,x]of d){n.push(""),n.push(`## Page: ${S}`);let b=p[S];b&&(t==null?void 0:t.provider)!=="codex"?n.push(`IMPORTANT: Use the Read tool to view the screenshot at: ${b}`):!b&&(t==null?void 0:t.provider)!=="codex"&&(Object.keys(p).length===0?(n.push(`IMPORTANT: Use the Read tool to view the screenshot at: ${r}`),n.push("(This screenshot shows the page the developer was on when submitting \u2014 not this page)")):n.push("(No screenshot available for this page \u2014 work from the annotation text and selectors)"));let y=V(C({},e),{annotations:x,styleModifications:e.styleModifications}),J=we(y,t==null?void 0:t.imagePaths);J&&(n.push(""),n.push(J))}}else{let p=we(e,t==null?void 0:t.imagePaths);p&&(n.push(""),n.push(p))}return n.push(""),n.push("Follow the developer's instructions. If they ask for changes, apply them to the source files \u2014 the dev server has HMR so changes appear immediately. If they ask a question or request analysis, respond in text without modifying code."),n.push(""),n.push("IMPORTANT: If any elements you modify have a `data-pm` attribute, preserve it in the source. This attribute tracks annotation positions."),n.push(""),n.push("## Resolution"),n.push("After completing all work, output a resolution block listing what you did for each annotation:"),n.push("<resolution>"),n.push('[{"annotationId":"<id>","status":"resolved","summary":"<what you did>","filesModified":["<file>"],"declaredScope":{"breadth":"...","target":"..."},"inferredScope":{"breadth":"...","target":"..."}}]'),n.push("</resolution>"),n.push(`Use status "resolved" when the change is complete, or "needs_review" if you're unsure about the result.`),n.push(""),n.push("### Scope classification"),n.push("Each resolution MUST include scope fields:"),n.push("- `declaredScope`: What scope the user's instruction text implies. null if no signal."),n.push("- `inferredScope`: What scope the change actually has, based on what you modified."),n.push("Scope has two dimensions:"),n.push('- `breadth`: "instance" (just this occurrence) or "pattern" (all similar occurrences)'),n.push('- `target`: "element" (a specific DOM element), "component" (a React/UI component), or "token" (a design token \u2014 color, spacing, typography)'),n.push('Note: "instance" + "token" is invalid \u2014 tokens are inherently patterns.'),n.push("If you cannot confidently determine scope, set it to null."),n.push(""),n.push("## Questions"),n.push("If the annotation text is unclear, ambiguous, gibberish, or you are unsure what the developer wants, output a question:"),n.push('<question>What do you mean by "..."?</question>'),n.push("Do NOT guess what unclear instructions mean \u2014 ask instead."),n.push("You may output BOTH a <resolution> for clear annotations AND a <question> for unclear ones in the same response."),n.join(`
|
|
111
|
+
`)}function Pt(r){var t;let e=r.match(/<question>\s*([\s\S]*?)\s*<\/question>/);return(t=e==null?void 0:e[1])!=null?t:null}function Tt(r,e,t,n){let o=[];o.push("You are continuing work on a UI based on the developer's reply to your question."),o.push(""),t!=="codex"&&o.push(`IMPORTANT: First, use the Read tool to view the screenshot at: ${r}`);let i=e.find(l=>l.role==="human"&&l.feedbackContext);if(i!=null&&i.feedbackContext&&(o.push(""),o.push(i.feedbackContext)),e.length>0){o.push(""),o.push("## Conversation History");let l=0;for(let c of e)c.role==="human"?(l++,c.replyToQuestion?(o.push(`### Round ${l} (human) \u2014 reply`),o.push(`"${c.replyToQuestion}"`)):(o.push(`### Round ${l} (human)`),c.feedbackSummary&&o.push(`Annotations: ${c.feedbackSummary}`))):c.question?(o.push(`### Round ${l} (assistant) \u2014 question`),o.push(`"${c.question}"`)):(o.push(`### Round ${l} (assistant)`),c.responseText&&o.push(`Response: ${c.responseText}`))}if(o.push(""),o.push("The developer answered your question. Continue working based on their reply."),o.push("Follow their instructions \u2014 apply code changes only if requested. The dev server has HMR so changes appear immediately."),o.push(""),o.push("IMPORTANT: If any elements you modify have a `data-pm` attribute, preserve it in the source. This attribute tracks annotation positions."),n&&n.length>0){o.push(""),o.push("## Attached Images"),o.push("The developer attached reference images with their reply:");for(let l of n)o.push(`Attached image: use the Read tool to view the image at: ${l}`)}return o.push(""),o.push("## Resolution"),o.push("After completing all work, output a resolution block listing what you did for each annotation:"),o.push("<resolution>"),o.push('[{"annotationId":"<id>","status":"resolved","summary":"<what you did>","filesModified":["<file>"],"declaredScope":{"breadth":"...","target":"..."},"inferredScope":{"breadth":"...","target":"..."}}]'),o.push("</resolution>"),o.push(`Use status "resolved" when the change is complete, or "needs_review" if you're unsure about the result.`),o.push(""),o.push("### Scope classification"),o.push("Each resolution MUST include scope fields:"),o.push("- `declaredScope`: What scope the user's instruction text implies. null if no signal."),o.push("- `inferredScope`: What scope the change actually has, based on what you modified."),o.push("Scope has two dimensions:"),o.push('- `breadth`: "instance" (just this occurrence) or "pattern" (all similar occurrences)'),o.push('- `target`: "element" (a specific DOM element), "component" (a React/UI component), or "token" (a design token \u2014 color, spacing, typography)'),o.push('Note: "instance" + "token" is invalid \u2014 tokens are inherently patterns.'),o.push("If you cannot confidently determine scope, set it to null."),o.push('If the developer\'s reply corrects a prior scope classification (e.g., "this should apply everywhere" or "only fix this one"), set `finalScope` on your resolution to reflect their correction and apply the change at the corrected scope.'),o.push(""),o.push("## Questions"),o.push("If you still need clarification, output:"),o.push("<question>Your question here</question>"),o.push("You may output BOTH a <resolution> and a <question> in the same response."),o.join(`
|
|
112
|
+
`)}function en(r){if(typeof r!="object"||r===null)return!1;let e=r;return(e.breadth==="instance"||e.breadth==="pattern")&&(e.target==="element"||e.target==="component"||e.target==="token")}function tn(r){if(typeof r!="object"||r===null||typeof r.annotationId!="string"||r.status!=="resolved"&&r.status!=="needs_review"||typeof r.summary!="string")return!1;let e=r;for(let t of["declaredScope","inferredScope","finalScope"])if(e[t]!==void 0&&e[t]!==null&&!en(e[t]))return!1;return!0}function bt(r){let e=r.match(/<resolution>\s*([\s\S]*?)\s*<\/resolution>/);if(!e||!e[1])return[];try{let t=JSON.parse(e[1]);return Array.isArray(t)?t.filter(tn):[]}catch(t){return[]}}function kt(r){let e=r.match(/<novel>\s*([\s\S]*?)\s*<\/novel>/);if(!(e!=null&&e[1]))return[];try{let t=JSON.parse(e[1]);return Array.isArray(t)?t.filter(n=>{if(typeof n!="object"||n===null)return!1;let o=n;return(o.category==="token"||o.category==="component"||o.category==="element")&&typeof o.element=="string"&&typeof o.decision=="string"&&typeof o.reason=="string"}):[]}catch(t){return[]}}var Oe=class{constructor(e=5){this.queue=[];this.activeJobs=new Map;this.activeProcesses=new Map;this.listeners=new Set;this.processor=null;this.eventBuffers=new Map;this.accumulators=new Map;this.cleanupTimers=new Map;this.maxConcurrency=e}setProcessor(e){this.processor=e}get active(){let e=this.activeJobs.values().next();return e.done?null:e.value}get allActive(){return Array.from(this.activeJobs.values())}get activeCount(){return this.activeJobs.size}get depth(){return this.queue.length}get isRunning(){return this.activeJobs.size>0}setActiveProcess(e,t){t?this.activeProcesses.set(e,t):this.activeProcesses.delete(e)}enqueue(e){return this.queue.push(e),this.processNext(),this.queue.length+this.activeJobs.size}addListener(e){return this.listeners.add(e),()=>this.listeners.delete(e)}broadcast(e,t,n){let o=this.bufferEvent(t,e);for(let i of this.listeners)i(o,t,n)}bufferEvent(e,t){let n=this.eventBuffers.get(e);n||(n={events:[],nextSeq:0},this.eventBuffers.set(e,n));let o=V(C({},t),{seq:n.nextSeq++});return n.events.push(o),n.events.length>1e4&&n.events.splice(0,n.events.length-1e4),o}getBufferedEvents(e,t=-1){var c;let n=this.eventBuffers.get(e),o=(c=this.accumulators.get(e))!=null?c:{response:"",thinking:""},i=this.activeJobs.has(e);if(!n)return null;let l=t<0?n.events:n.events.filter(p=>p.seq>t);return{jobId:e,events:l,currentSeq:n.nextSeq-1,accumulated:C({},o),jobActive:i}}accumulateText(e,t,n){let o=this.accumulators.get(e);o||(o={response:"",thinking:""},this.accumulators.set(e,o)),o[t]+=n}getAccumulated(e){var t;return(t=this.accumulators.get(e))!=null?t:null}scheduleBufferCleanup(e){let t=this.cleanupTimers.get(e);t&&clearTimeout(t);let n=setTimeout(()=>{this.eventBuffers.delete(e),this.accumulators.delete(e),this.cleanupTimers.delete(e)},6e4);this.cleanupTimers.set(e,n)}cancelJob(e){let t=this.activeProcesses.get(e),n=this.activeJobs.get(e);return!t||!n?!1:(t.kill("SIGTERM"),this.activeProcesses.delete(e),this.activeJobs.delete(e),n.status="error",n.error="Cancelled by user",this.broadcast({type:"error",jobId:n.id,message:"Cancelled by user",cancelled:!0},n.id,n.sourceId),this.processNext(),!0)}cancelActive(){if(this.activeJobs.size===0)return!1;let e=Array.from(this.activeJobs.keys());for(let t of e)this.cancelJob(t);return!0}destroy(){for(let e of this.activeProcesses.values())e.kill("SIGTERM");this.activeProcesses.clear(),this.activeJobs.clear(),this.queue=[],this.listeners.clear(),this.eventBuffers.clear(),this.accumulators.clear();for(let e of this.cleanupTimers.values())clearTimeout(e);this.cleanupTimers.clear()}async destroyAsync(e=1e4){let t=Array.from(this.activeProcesses.values());if(this.queue=[],this.listeners.clear(),t.length===0){this.activeProcesses.clear(),this.activeJobs.clear();return}for(let n of t)try{n.kill("SIGTERM")}catch(o){}await Promise.all(t.map(n=>new Promise(o=>{let i=!1,l=()=>{i||(i=!0,o())};n.on("exit",l),n.on("error",l),setTimeout(()=>{if(!i){try{n.kill("SIGKILL")}catch(c){}setTimeout(l,500)}},e)}))),this.activeProcesses.clear(),this.activeJobs.clear(),this.eventBuffers.clear(),this.accumulators.clear();for(let n of this.cleanupTimers.values())clearTimeout(n);this.cleanupTimers.clear()}processNext(){for(;this.activeJobs.size<this.maxConcurrency&&this.queue.length>0&&this.processor;){let e=this.queue.shift();this.activeJobs.set(e.id,e),e.status="running",this.broadcast({type:"job_started",jobId:e.id,position:0,threadId:e.threadId},e.id,e.sourceId),this.processor(e).catch(t=>{e.status="error",e.error=t instanceof Error?t.message:String(t),this.broadcast({type:"error",jobId:e.id,message:e.error},e.id,e.sourceId)}).finally(()=>{this.activeJobs.delete(e.id),this.activeProcesses.delete(e.id),this.scheduleBufferCleanup(e.id),this.processNext(),this.activeJobs.size===0&&this.queue.length===0&&this.broadcast({type:"queue_drained"},e.id)})}}};import{mkdir as nn,readFile as sn,writeFile as on}from"fs/promises";import{dirname as rn,join as an}from"path";var cn={version:1,threads:{}},_e=class{constructor(e){this.cache=null;this.writeChain=Promise.resolve();this.filePath=an(e,".popmelt","threads.json")}async load(){if(this.cache)return this.cache;try{let e=await sn(this.filePath,"utf-8"),t=JSON.parse(e);if(t&&t.version===1&&t.threads)return this.cache=t,this.cache}catch(e){}return this.cache=V(C({},cn),{threads:{}}),this.cache}async getThread(e){var n;return(n=(await this.load()).threads[e])!=null?n:null}async findContinuationThread(e){if(e.length===0)return null;let t=await this.load(),n=new Set(e);for(let o of Object.values(t.threads))if(o.elementIdentifiers.some(l=>n.has(l)))return o;return null}async createThread(e,t){let n=await this.load(),o={id:e,createdAt:Date.now(),updatedAt:Date.now(),elementIdentifiers:t,messages:[]};return n.threads[e]=o,await this.persist(),o}async appendMessage(e,t){let o=(await this.load()).threads[e];o&&(o.messages.push(t),o.updatedAt=Date.now(),await this.persist())}async addElementIdentifiers(e,t){let o=(await this.load()).threads[e];if(!o)return;let i=new Set(o.elementIdentifiers);for(let l of t)i.has(l)||o.elementIdentifiers.push(l);o.updatedAt=Date.now(),await this.persist()}async getThreadHistory(e,t=6){let n=await this.getThread(e);return!n||n.messages.length===0?[]:n.messages.length<=t?n.messages:[n.messages[0],...n.messages.slice(-(t-1))]}async persist(){this.writeChain=this.writeChain.then(async()=>{if(this.cache)try{await nn(rn(this.filePath),{recursive:!0}),await on(this.filePath,JSON.stringify(this.cache,null,2))}catch(e){console.error("[ThreadStore] Failed to persist:",e)}}),await this.writeChain}};var Mn={};var xn=1111,In=["Read","Edit","Write","Glob","Grep","Bash","WebFetch","WebSearch","Bash(curl:*)"],Pn=1800*1e3,Tn=3600*1e3;function Mt(r){if(!r)return!1;try{let e=new URL(r);return e.hostname==="localhost"||e.hostname==="127.0.0.1"}catch(e){return!1}}function bn(r,e){let t=r.headers.origin;Mt(t)&&(e.setHeader("Access-Control-Allow-Origin",t),e.setHeader("Access-Control-Allow-Methods","GET, POST, PATCH, DELETE, OPTIONS"),e.setHeader("Access-Control-Allow-Headers","Content-Type"))}function T(r,e,t){r.writeHead(e,{"Content-Type":"application/json"}),r.end(JSON.stringify(t))}function kn(r,e){if(!r)return e;let t=r.match(/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i);if(!t)return e;let[,n,o,i]=t;return`\x1B[38;2;${parseInt(n,16)};${parseInt(o,16)};${parseInt(i,16)}m${e}\x1B[0m`}function We(r,e){try{r.res.write(`event: ${e.type}
|
|
112
113
|
data: ${JSON.stringify(e)}
|
|
113
114
|
|
|
114
|
-
`)}catch(t){}}async function
|
|
115
|
+
`)}catch(t){}}async function $n(r){try{let e=new AbortController,t=setTimeout(()=>e.abort(),500),n=await fetch(`http://127.0.0.1:${r}/status`,{signal:e.signal});return clearTimeout(t),n.ok?await n.json():null}catch(e){return null}}function Rn(r,e){return new Promise((t,n)=>{let o=l=>{r.removeListener("listening",i),n(l)},i=()=>{r.removeListener("error",o),t()};r.once("error",o),r.once("listening",i),r.listen(e,"127.0.0.1")})}async function qe(r={}){var Ye,Ve,Ke,Ze,et,tt,nt,st,ot;let e=(Ye=r.port)!=null?Ye:xn,t=(Ve=r.projectRoot)!=null?Ve:process.cwd(),n=un("sha256").update(t).digest("hex").slice(0,12),o=(Ke=r.devOrigin)!=null?Ke:process.env.PORT?`http://localhost:${process.env.PORT}`:null,i=(Ze=r.tempDir)!=null?Ze:ie(yn(),"popmelt-bridge"),l=(et=r.maxTurns)!=null?et:40,c=(tt=r.maxBudgetUsd)!=null?tt:1,p=[...(nt=r.allowedTools)!=null?nt:In],d=(st=r.claudePath)!=null?st:"claude",S=(ot=r.provider)!=null?ot:"claude",x=r.timeoutMs,b=e,y={};for(let s of["claude","codex"])try{let a=ln("which",[s],{encoding:"utf-8"}).trim();y[s]={available:!0,path:a}}catch(a){y[s]={available:!1,path:null}}function J(s,a){return new Promise(h=>{let u=dn(a,["--version"],{stdio:["ignore","ignore","ignore"]}),w=!1,f=R=>{w||(w=!0,h(R))},E=setTimeout(()=>{u.kill("SIGTERM"),f(!0)},5e3);u.on("error",()=>{clearTimeout(E),f(!1)}),u.on("close",R=>{clearTimeout(E),f(R===0)})})}let[F,U]=await Promise.all([Le(t),je(t)]);y.claude&&(y.claude.mcp=F),y.codex&&(y.codex.mcp=U),F.found&&F.name&&p.push(`mcp__${F.name}__*`),await pn(i,{recursive:!0}),Rt(i).catch(()=>{});let P=new Oe(1),L=new Set,A=new _e(t),j=new Me(t),W=new Ee(t,j,{claudePath:d,onEvent:s=>{for(let a of L)We(a,s)}}),oe=20,D=300*1e3,z=[],g=null,N;P.addListener((s,a,h)=>{for(let u of L)(!h||!u.sourceId||u.sourceId===h)&&We(u,s)}),P.setProcessor(async s=>{var X,Z,te,ee,de,ae;let a=s._replyPrompt,h=s._replyImagePaths,u=(X=s.provider)!=null?X:S,w;if(s.threadId){let $=await A.getThread(s.threadId);if($){for(let _=$.messages.length-1;_>=0;_--)if($.messages[_].sessionId){w=$.messages[_].sessionId;break}}}let f;if(w&&a){let $=(Z=await A.getThread(s.threadId))==null?void 0:Z.messages.filter(se=>se.role==="human").pop();if(f=($==null?void 0:$.replyToQuestion)||($==null?void 0:$.feedbackSummary)||"",h&&h.length>0){f+=`
|
|
115
116
|
|
|
116
|
-
The developer attached reference images with their reply:`;for(let se of f
|
|
117
|
-
Attached image: use the Read tool to view the image at: ${se}`}
|
|
117
|
+
The developer attached reference images with their reply:`;for(let se of h)f+=`
|
|
118
|
+
Attached image: use the Read tool to view the image at: ${se}`}f+=`
|
|
118
119
|
|
|
119
|
-
After completing work, output a <resolution> block with declaredScope and inferredScope. If the developer corrected scope, set finalScope. If unclear, output a <question> block.`}else if(w)
|
|
120
|
+
After completing work, output a <resolution> block with declaredScope and inferredScope. If the developer corrected scope, set finalScope. If unclear, output a <question> block.`}else if(w)f=we(s.feedback,s.imagePaths)+`
|
|
120
121
|
|
|
121
122
|
Follow the developer's instructions. If they ask for changes, apply them to the source files.
|
|
122
123
|
|
|
123
124
|
After completing work, output a <resolution> block with declaredScope and inferredScope. If unclear, output a <question> block.`+(u!=="codex"?`
|
|
124
125
|
|
|
125
|
-
IMPORTANT: First, use the Read tool to view the updated screenshot at: ${s.screenshotPath}`:"");else{let $=!a&&s.threadId?await
|
|
126
|
+
IMPORTANT: First, use the Read tool to view the updated screenshot at: ${s.screenshotPath}`:"");else{let $=!a&&s.threadId?await A.getThreadHistory(s.threadId):void 0,_=a?null:await W.loadModel();f=a!=null?a:It(s.screenshotPath,s.feedback,{threadHistory:$&&$.length>0?$:void 0,provider:u,imagePaths:s.imagePaths,designModel:_!=null?_:void 0,screenshotPaths:s.screenshotPaths})}let E=kn(s.color,`[\u22B9 ${b}:${s.id}]`),R=s.screenshotPaths&&Object.keys(s.screenshotPaths).length>0?`${Object.keys(s.screenshotPaths).length} pages [${Object.keys(s.screenshotPaths).join(", ")}]`:s.screenshotPath;console.log(`${E} Reviewing ${R} (provider: ${u})${s.threadId?` (thread: ${s.threadId})`:""}${w?` (resuming: ${w.slice(0,8)})`:""}`);let q=($,_)=>{$.type==="delta"&&"text"in $?P.accumulateText(_,"response",$.text):$.type==="thinking"&&"text"in $&&P.accumulateText(_,"thinking",$.text),P.broadcast($,_,s.sourceId)},{process:M,result:K}=u==="codex"?ct(s.id,{prompt:f,projectRoot:t,screenshotPath:s.screenshotPath,resumeSessionId:w,model:s.model,onEvent:q}):Re(s.id,{prompt:f,projectRoot:t,maxTurns:l,maxBudgetUsd:c,allowedTools:p,claudePath:d,resumeSessionId:w,model:s.model,timeoutMs:x,onEvent:q});P.setActiveProcess(s.id,M);let v=await K;if(s.result=v.text,v.success){console.log(`${E} Iteration complete`),v.fileEdits&&v.fileEdits.length>0&&console.log(`${E} Captured ${v.fileEdits.length} file edit(s): ${v.fileEdits.map(Y=>`${Y.tool} ${Y.file_path}`).join(", ")}`),s.status="done";let $=Pt(v.text),_=bt(v.text);if(_.length>0&&s.annotationIds&&s.annotationIds.length>0){let Y=new Set(s.annotationIds);_.every(I=>Y.has(I.annotationId))||(_=_.map((I,B)=>V(C({},I),{annotationId:s.annotationIds[B%s.annotationIds.length]})))}let se=v.fileEdits&&v.fileEdits.length>0?v.fileEdits.map(Y=>`${Y.tool} ${Y.file_path.split("/").pop()}`):void 0;s.threadId&&await A.appendMessage(s.threadId,{role:"assistant",timestamp:Date.now(),jobId:s.id,responseText:v.text,resolutions:_.length>0?_:void 0,question:$!=null?$:void 0,sessionId:v.sessionId,toolsUsed:se,model:s.model,provider:s.provider}),j.captureGitDiff(t).then(async Y=>{var ce;let m=Date.now(),I=s.imagePaths?Object.values(s.imagePaths).flat():[],B=[];if(s.imagePaths)for(let[_t,At]of Object.entries(s.imagePaths))for(let Ne=0;Ne<At.length;Ne++)B.push(`screenshots/p-${s.id}-${_t}-${Ne}.png`);await j.persist({version:1,id:s.id,createdAt:s.createdAt,completedAt:m,durationMs:m-s.createdAt,url:s.feedback.url,viewport:s.feedback.viewport,screenshotPath:`screenshots/s-${s.id}.png`,pastedImagePaths:B,annotations:s.feedback.annotations,styleModifications:s.feedback.styleModifications,inspectedElement:s.feedback.inspectedElement,provider:s.provider,model:s.model,sessionId:v.sessionId,threadId:s.threadId,responseText:v.text,resolutions:_.length>0?_:[],question:$!=null?$:void 0,fileEdits:(ce=v.fileEdits)!=null?ce:[],toolsUsed:se,gitDiff:Y},s.screenshotPath,I)}).catch(()=>{}),_.length>0&&_.some(m=>{var B;let I=(B=m.finalScope)!=null?B:m.inferredScope;return(I==null?void 0:I.breadth)==="pattern"})&&W.run().catch(()=>{}),$&&(console.log(`${E} \u{1F4AC} Question detected: "${$.slice(0,120)}" \u2192 broadcasting to ${L.size} SSE clients (threadId=${(te=s.threadId)!=null?te:s.id}, annotationIds=${(de=(ee=s.annotationIds)==null?void 0:ee.join(","))!=null?de:"none"})`),P.broadcast({type:"question",jobId:s.id,threadId:(ae=s.threadId)!=null?ae:s.id,question:$,annotationIds:s.annotationIds},s.id,s.sourceId));let fe=kt(v.text);fe.length>0&&(console.log(`${E} Novel pattern(s): ${fe.map(Y=>`${Y.category}/${Y.element}`).join(", ")}`),P.broadcast({type:"novel_patterns",jobId:s.id,patterns:fe,threadId:s.threadId},s.id,s.sourceId)),P.broadcast({type:"done",jobId:s.id,success:!0,resolutions:_.length>0?_:void 0,responseText:v.text,threadId:s.threadId},s.id,s.sourceId),z.push({id:s.id,status:"done",completedAt:Date.now(),threadId:s.threadId,annotationIds:s.annotationIds})}else console.error(`${E} Error: ${v.error}`),s.status="error",s.error=v.error,s.threadId&&await A.appendMessage(s.threadId,{role:"assistant",timestamp:Date.now(),jobId:s.id,error:v.error||"Unknown error",model:s.model,provider:s.provider}),P.broadcast({type:"error",jobId:s.id,threadId:s.threadId,message:v.error||"Unknown error"},s.id,s.sourceId),z.push({id:s.id,status:"error",completedAt:Date.now(),error:v.error,threadId:s.threadId,annotationIds:s.annotationIds});let G=Date.now()-D;for(;z.length>0&&(z[0].completedAt<G||z.length>oe);)z.shift()});let k=gn(async(s,a)=>{var E;if(bn(s,a),s.method==="OPTIONS"){a.writeHead(204),a.end();return}let h=s.url||"/",u=h.split("?")[0],w=new URL(h,`http://127.0.0.1:${b}`),f=w.pathname;try{if(s.method==="POST"&&f==="/send")await H(s,a);else if(s.method==="GET"&&f==="/events")he(s,a);else if(s.method==="GET"&&f==="/status")ve(a);else if(s.method==="GET"&&f==="/capabilities")T(a,200,{providers:y});else if(s.method==="POST"&&f==="/mcp/install")await Ie(s,a);else if(s.method==="POST"&&f==="/reply")await ne(s,a);else if(s.method==="POST"&&f==="/cancel")Se(s,a);else if(s.method==="POST"&&f==="/materialize")await xe(a);else if(s.method==="POST"&&f==="/model/component")await Pe(s,a);else if(s.method==="DELETE"&&f==="/model/component")await Te(s,a);else if(s.method==="PATCH"&&f==="/model/token")await Q(s,a);else if(s.method==="DELETE"&&f==="/model/token")await De(s,a);else if(s.method==="GET"&&f==="/model"){let R=await W.loadModel();T(a,200,{model:R})}else if(s.method==="GET"&&f.startsWith("/jobs/")&&f.endsWith("/events")){let R=f.slice(6,f.length-7),q=parseInt((E=w.searchParams.get("afterSeq"))!=null?E:"-1",10),M=P.getBufferedEvents(R,isNaN(q)?-1:q);M?T(a,200,M):T(a,404,{error:"Unknown job"})}else if(s.method==="GET"&&u.startsWith("/files/"))await Et(u.slice(7),a);else if(s.method==="GET"&&f.startsWith("/thread/")){let R=f.slice(8);await Ct(R,a)}else s.method==="GET"&&(f==="/canvas"||f==="/canvas/")?O(s,a):s.method==="GET"&&f==="/canvas/manifest"?await be(a):s.method==="GET"&&f==="/canvas/app.mjs"?await ke(a):T(a,404,{error:"Not found"})}catch(R){console.error("[Bridge] Request error:",R),T(a,500,{error:R instanceof Error?R.message:"Internal error"})}});async function H(s,a){let{screenshot:h,feedback:u,color:w,provider:f,model:E,sourceId:R,pastedImages:q,pageScreenshots:M}=await He(s),K;try{K=JSON.parse(u)}catch(m){T(a,400,{error:"Invalid feedback JSON"});return}let v=Ge().slice(0,8),G={};if(M.length>0)for(let m of M){let I=encodeURIComponent(m.pathname),B=ie(i,`screenshot-${v}-${I}.png`);await Ae(B,m.data),G[m.pathname]=B}let X=ie(i,`screenshot-${v}.png`);await Ae(X,h);let Z={};if(q.length>0)for(let m of q){let I=ie(i,`pasted-${v}-${m.annotationId}-${m.index}.png`);await Ae(I,m.data),Z[m.annotationId]||(Z[m.annotationId]=[]),Z[m.annotationId].push(I)}let te=K.annotations.map(m=>m.linkedSelector?m.pathname?`${m.pathname}:${m.linkedSelector}`:m.linkedSelector:null).filter(m=>!!m),ee;if(te.length>0){let m=await A.findContinuationThread(te);m?(ee=m.id,await A.addElementIdentifiers(ee,te)):ee=(await A.createThread(v,te)).id}else ee=(await A.createThread(v,[])).id;let de=K.annotations.map(m=>m.id),ae=Object.keys(G).length>0,$=C(V(C({id:v,status:"queued",screenshotPath:X,feedback:K,createdAt:Date.now(),color:w,threadId:ee,annotationIds:de,provider:f==="claude"||f==="codex"?f:void 0,model:E||void 0},Object.keys(Z).length>0?{imagePaths:Z}:{}),{sourceId:R||void 0}),ae?{screenshotPaths:G}:{}),_=new Set(K.annotations.map(m=>m.pathname).filter(Boolean)),se;if(_.size>1){let m=new Map;for(let I of K.annotations){let B=I.pathname||"(unknown)";m.has(B)||m.set(B,[]),m.get(B).push(I.instruction||`[${I.type}]`)}se=[...m.entries()].map(([I,B])=>`\`${I}\`
|
|
126
127
|
${B.map(ce=>`- ${ce}`).join(`
|
|
127
128
|
`)}`).join(`
|
|
128
|
-
`)}else se=K.annotations.map(m=>m.instruction||`[${m.type}]`).join("; ");let fe=we(K,Object.keys(Z).length>0?Z:void 0);await
|
|
129
|
+
`)}else se=K.annotations.map(m=>m.instruction||`[${m.type}]`).join("; ");let fe=we(K,Object.keys(Z).length>0?Z:void 0);await A.appendMessage(ee,V(C(C({role:"human",timestamp:Date.now(),jobId:v,screenshotPath:X},ae?{screenshotPaths:G}:{}),Object.keys(Z).length>0?{imagePaths:Z}:{}),{annotationIds:de,feedbackSummary:se,feedbackContext:fe||void 0}));let Y=P.enqueue($);T(a,200,{jobId:v,position:Y,threadId:ee})}async function ne(s,a){let h=s.headers["content-type"]||"",u,w,f,E,R,q,M=[];if(h.includes("multipart/form-data")){let m=await He(s),I=m.feedback?JSON.parse(m.feedback):{};u=I.threadId,w=I.reply,f=I.color,E=I.provider,R=I.model,q=I.sourceId||m.sourceId;for(let B of m.pastedImages)M.push(B.data)}else{let m=[];try{for(var _=ue(s),se,fe,Y;se=!(fe=await _.next()).done;se=!1){let ce=fe.value;m.push(typeof ce=="string"?Buffer.from(ce):ce)}}catch(fe){Y=[fe]}finally{try{se&&(fe=_.return)&&await fe.call(_)}finally{if(Y)throw Y[0]}}let I=Buffer.concat(m).toString("utf-8"),B;try{B=JSON.parse(I)}catch(ce){T(a,400,{error:"Invalid JSON"});return}u=B.threadId,w=B.reply,f=B.color,E=B.provider,R=B.model,q=B.sourceId}if(!u||!w){T(a,400,{error:"Missing threadId or reply"});return}if(!await A.getThread(u)){T(a,404,{error:"Thread not found"});return}let v=Ge().slice(0,8),G=[];for(let m=0;m<M.length;m++){let I=ie(i,`reply-${v}-${m}.png`);await Ae(I,M[m]),G.push(I)}let X="";{let m=await A.getThreadHistory(u);for(let I=m.length-1;I>=0;I--)if(m[I].screenshotPath){X=m[I].screenshotPath;break}}if(!X){T(a,400,{error:"No screenshot available"});return}await A.appendMessage(u,C({role:"human",timestamp:Date.now(),jobId:v,replyToQuestion:w,screenshotPath:X},G.length>0?{replyImagePaths:G}:{}));let Z=await A.getThreadHistory(u),te=[];for(let m of Z)if(m.annotationIds)for(let I of m.annotationIds)te.includes(I)||te.push(I);let ee=E==="claude"||E==="codex"?E:void 0,de=Tt(X,Z,ee,G.length>0?G:void 0),ae={id:v,status:"queued",screenshotPath:X,feedback:{timestamp:new Date().toISOString(),url:"",viewport:{width:0,height:0},scrollPosition:{x:0,y:0},annotations:[],styleModifications:[]},createdAt:Date.now(),color:f,threadId:u,annotationIds:te.length>0?te:void 0,provider:ee,model:R||void 0,sourceId:q||void 0};ae._replyPrompt=de,G.length>0&&(ae._replyImagePaths=G);let $=P.enqueue(ae);T(a,200,{jobId:v,position:$,threadId:u})}function he(s,a){a.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"}),a.write(`event: connected
|
|
129
130
|
data: {"status":"connected"}
|
|
130
131
|
|
|
131
|
-
`),!o&&s.headers.origin
|
|
132
|
-
${le} Shutting down bridge...`),await r.close(),e()};process.on("SIGINT",t),process.on("SIGTERM",t)})}async function
|
|
132
|
+
`),!o&&s.headers.origin&&Mt(s.headers.origin)&&(o=s.headers.origin);let u=new URL(s.url||"/",`http://127.0.0.1:${b}`).searchParams.get("sourceId")||void 0,w={id:Ge().slice(0,8),res:a,sourceId:u};L.add(w),s.on("close",()=>{L.delete(w)})}function ve(s){let a=P.allActive;T(s,200,{ok:!0,projectId:n,devOrigin:o,activeJob:a[0]?{id:a[0].id,status:a[0].status}:null,activeJobs:a.map(h=>({id:h.id,status:h.status,threadId:h.threadId,annotationIds:h.annotationIds,color:h.color})),queueDepth:P.depth,recentJobs:z})}async function Se(s,a){let u=new URL(s.url||"/",`http://127.0.0.1:${b}`).searchParams.get("jobId"),f=(u?P.allActive.filter(R=>R.id===u):P.allActive).map(R=>R.threadId).filter(Boolean),E=u?P.cancelJob(u):P.cancelActive();for(let R of f)await A.appendMessage(R,{role:"assistant",timestamp:Date.now(),jobId:u||"",cancelled:!0});T(a,200,{cancelled:E})}async function xe(s){if(W.isRunning){T(s,200,{skipped:!0,reason:"Already running"});return}let a=await W.getUnmaterializedPatternDecisions();if(a.length===0){T(s,200,{skipped:!0,reason:"No unmaterialized pattern decisions"});return}W.run().catch(()=>{}),T(s,200,{started:!0,decisionCount:a.length,decisionIds:a.map(h=>h.id)})}async function Ie(s,a){var v,G;let h=[];try{for(var R=ue(s),q,M,K;q=!(M=await R.next()).done;q=!1){let X=M.value;h.push(typeof X=="string"?Buffer.from(X):X)}}catch(M){K=[M]}finally{try{q&&(M=R.return)&&await M.call(R)}finally{if(K)throw K[0]}}let u;if(h.length>0)try{u=JSON.parse(Buffer.concat(h).toString("utf-8")).serverUrl}catch(X){}let w=[];(v=y.claude)!=null&&v.available&&y.claude.mcp&&!y.claude.mcp.found&&w.push(await St(u)),(G=y.codex)!=null&&G.available&&y.codex.mcp&&!y.codex.mcp.found&&w.push(await xt(u));let[f,E]=await Promise.all([Le(t),je(t)]);y.claude&&(y.claude.mcp=f),y.codex&&(y.codex.mcp=E),T(a,200,{results:w,capabilities:{providers:y}})}async function Pe(s,a){let h=[];try{for(var f=ue(s),E,R,q;E=!(R=await f.next()).done;E=!1){let M=R.value;h.push(typeof M=="string"?Buffer.from(M):M)}}catch(R){q=[R]}finally{try{E&&(R=f.return)&&await R.call(f)}finally{if(q)throw q[0]}}let u;try{u=JSON.parse(Buffer.concat(h).toString("utf-8"))}catch(M){T(a,400,{error:"Invalid JSON"});return}if(!u.name||typeof u.name!="string"){T(a,400,{error:"Missing or invalid name"});return}let w=await W.addComponent(u.name);T(a,200,w)}async function Te(s,a){let h=[];try{for(var f=ue(s),E,R,q;E=!(R=await f.next()).done;E=!1){let M=R.value;h.push(typeof M=="string"?Buffer.from(M):M)}}catch(R){q=[R]}finally{try{E&&(R=f.return)&&await R.call(f)}finally{if(q)throw q[0]}}let u;try{u=JSON.parse(Buffer.concat(h).toString("utf-8"))}catch(M){T(a,400,{error:"Invalid JSON"});return}if(!u.name||typeof u.name!="string"){T(a,400,{error:"Missing or invalid name"});return}let w=await W.removeComponent(u.name);T(a,200,w)}async function Q(s,a){let h=[];try{for(var f=ue(s),E,R,q;E=!(R=await f.next()).done;E=!1){let M=R.value;h.push(typeof M=="string"?Buffer.from(M):M)}}catch(R){q=[R]}finally{try{E&&(R=f.return)&&await R.call(f)}finally{if(q)throw q[0]}}let u;try{u=JSON.parse(Buffer.concat(h).toString("utf-8"))}catch(M){T(a,400,{error:"Invalid JSON"});return}if(!u.path||typeof u.path!="string"||typeof u.value!="string"){T(a,400,{error:"Missing or invalid path/value"});return}let w=await W.updateToken(u.path,u.value);T(a,200,w)}async function De(s,a){let h=[];try{for(var f=ue(s),E,R,q;E=!(R=await f.next()).done;E=!1){let M=R.value;h.push(typeof M=="string"?Buffer.from(M):M)}}catch(R){q=[R]}finally{try{E&&(R=f.return)&&await R.call(f)}finally{if(q)throw q[0]}}let u;try{u=JSON.parse(Buffer.concat(h).toString("utf-8"))}catch(M){T(a,400,{error:"Invalid JSON"});return}if(!u.path||typeof u.path!="string"){T(a,400,{error:"Missing or invalid path"});return}let w=await W.removeToken(u.path);T(a,200,w)}function O(s,a){let h=o!=null?o:"http://localhost:3000";if(!o){let w=s.headers.referer||s.headers.origin;if(w)try{let f=new URL(typeof w=="string"?w:w[0]||"");(f.hostname==="localhost"||f.hostname==="127.0.0.1")&&(h=f.origin)}catch(f){}}let u=it(b,h);a.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),a.end(u)}async function be(s){let a=Date.now();if(g&&a<g.expires){T(s,200,g.data);return}try{let{scanForComponents:h}=await import("./react-scanner-MSMGKCIV.mjs"),{generateRenderFiles:u}=await import("./render-generator-QV5BYGPF.mjs"),w=await h(t);g={data:w,expires:a+5e3},u(w,t,N).then(f=>{N=f}).catch(f=>console.warn("[Bridge] Render generation failed:",f)),T(s,200,w)}catch(h){console.error("[Bridge] Scanner error:",h),T(s,500,{error:"Failed to scan components"})}}async function ke(s){let a=[ie(t,"node_modules","@popmelt.com","core","dist","canvas.mjs"),ie(t,"packages","popmelt","dist","canvas.mjs")];try{let h=Sn(Mn.url);a.unshift(ie(vn(h),"canvas.mjs"))}catch(h){}for(let h of a)try{let u=await $t(h,"utf-8");s.writeHead(200,{"Content-Type":"application/javascript; charset=utf-8","Access-Control-Allow-Origin":"*"}),s.end(u);return}catch(u){}console.error("[Bridge] Canvas bundle not found in:",a),T(s,404,{error:"Canvas bundle not found"})}async function Et(s,a){var h;if(!s||s.includes("/")||s.includes("\\")||s.includes("..")){T(a,400,{error:"Invalid filename"});return}try{let u=await $t(ie(i,s)),w=(h=s.split(".").pop())==null?void 0:h.toLowerCase(),f=w==="png"?"image/png":w==="jpg"||w==="jpeg"?"image/jpeg":"application/octet-stream";a.writeHead(200,{"Content-Type":f,"Cache-Control":"public, max-age=3600"}),a.end(u)}catch(u){T(a,404,{error:"File not found"})}}function $e(s){return`/files/${wn(s)}`}async function Ct(s,a){let h=await A.getThread(s);if(!h){T(a,404,{error:"Thread not found"});return}let u=h.messages.map(M=>{var K=M,{screenshotPath:w,screenshotPaths:f,imagePaths:E,replyImagePaths:R}=K,q=rt(K,["screenshotPath","screenshotPaths","imagePaths","replyImagePaths"]);return C(C(C(C(C({},q),w?{screenshotUrl:$e(w)}:{}),f?{screenshotUrls:Object.fromEntries(Object.entries(f).map(([v,G])=>[v,$e(G)]))}:{}),E?{imageUrls:Object.fromEntries(Object.entries(E).map(([v,G])=>[v,G.map($e)]))}:{}),R?{replyImageUrls:R.map($e)}:{})});T(a,200,{id:h.id,createdAt:h.createdAt,messages:u})}let Qe=9,Xe=!1;for(let s=e;s<e+Qe;s++)try{await Rn(k,s),b=s,Xe=!0,console.log(`[\u22B9 is watching :${b}]`);break}catch(a){if(a.code==="EADDRINUSE"){let h=await $n(s);if(h&&h.projectId===n)return console.log(`[\u22B9 already watching :${s}]`),{port:s,projectId:n,close:async()=>{}};continue}throw a}if(!Xe)throw new Error(`[Bridge] All ports ${e}\u2013${e+Qe-1} in use`);for(let[s,a]of Object.entries(y))!a.available||!a.path||J(s,a.path).then(h=>{if(h)console.log(`[Bridge] ${s} warmed up`);else{console.warn(`[Bridge] ${s} warm-up failed \u2014 marking unavailable`),a.available=!1,a.path=null;for(let u of L)We(u,{type:"capabilities_changed",data:{}})}});let Ot=setInterval(()=>{Rt(i).catch(()=>{})},Pn);return{port:b,projectId:n,close:async()=>{clearInterval(Ot),await P.destroyAsync();for(let s of L)try{s.res.end()}catch(a){}return L.clear(),new Promise(s=>{k.close(()=>s())})}}}async function Rt(r){try{let e=await hn(r),t=Date.now();for(let n of e){let o=ie(r,n);try{let i=await fn(o);t-i.mtimeMs>Tn&&await mn(o)}catch(i){}}}catch(e){}}var le="\x1B[35m[popmelt]\x1B[0m";async function Cn(){let r=process.argv.slice(2);if(r[0]==="wrap"){let e=r.indexOf("--");(e===-1||e===r.length-1)&&(console.error(`${le} Usage: popmelt wrap -- <dev command>`),console.error(`${le} Example: popmelt wrap -- next dev`),console.error(`${le} Example: popmelt wrap -- astro dev`),process.exit(1));let t=r.slice(e+1);await _n(t);return}if(r[0]==="bridge"){await On();return}console.log(`${le} Popmelt \u2014 design collaboration for AI coding agents`),console.log(""),console.log(" popmelt wrap -- <command> Start bridge + dev server together"),console.log(" popmelt bridge Start the bridge server standalone"),console.log(""),console.log("Examples:"),console.log(" popmelt wrap -- next dev"),console.log(" popmelt wrap -- astro dev"),console.log(" popmelt wrap -- vite"),console.log(""),console.log("In package.json:"),console.log(' "scripts": { "dev": "popmelt wrap -- next dev" }')}async function On(){let r=await qe({projectRoot:process.cwd()});console.log(`${le} Bridge running on http://localhost:${r.port}`),await new Promise(e=>{let t=async()=>{console.log(`
|
|
133
|
+
${le} Shutting down bridge...`),await r.close(),e()};process.on("SIGINT",t),process.on("SIGTERM",t)})}async function _n(r){let e=await qe({projectRoot:process.cwd()});console.log(`${le} Bridge running on http://localhost:${e.port}`);let[t,...n]=r;console.log(`${le} Starting: ${r.join(" ")}`);let o=En(t,n,{stdio:"inherit",shell:!0,env:V(C({},process.env),{POPMELT_BRIDGE_URL:`http://localhost:${e.port}`})}),i=l=>{o.kill(l)};process.on("SIGINT",()=>i("SIGINT")),process.on("SIGTERM",()=>i("SIGTERM")),o.on("exit",async(l,c)=>{await e.close(),c?process.kill(process.pid,c):process.exit(l!=null?l:0)})}Cn().catch(r=>{console.error(`${le} Fatal:`,r),process.exit(1)});
|