@maincode-ai/matilda-code 0.22.3-nightly.20261110.cb1234773 → 0.22.4

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.
Files changed (44) hide show
  1. package/chunks/{agent-7LLN72GU.js → agent-MOVDRLTH.js} +1 -1
  2. package/chunks/{agent-headless-APBRBFN3.js → agent-headless-OIL2DH2J.js} +1 -1
  3. package/chunks/{chunk-HK3QQSM7.js → chunk-5372BQ2X.js} +3 -3
  4. package/chunks/{chunk-JZMGEGR6.js → chunk-5MS3VZDH.js} +1 -1
  5. package/chunks/{chunk-NO6BFSGG.js → chunk-EC2IF7DG.js} +1 -1
  6. package/chunks/{chunk-N3AQRPV5.js → chunk-J6YVJMKL.js} +31 -31
  7. package/chunks/{chunk-BEP4F3GO.js → chunk-LPPYEBZM.js} +475 -474
  8. package/chunks/{chunk-GDRS4OWI.js → chunk-LQ3VS2EV.js} +51 -46
  9. package/chunks/{chunk-TVNM3PQ7.js → chunk-MUYVUUSO.js} +1 -1
  10. package/chunks/chunk-RR3LDVGW.js +8 -0
  11. package/chunks/{chunk-DERMLVT6.js → chunk-RT2VU2QV.js} +1 -1
  12. package/chunks/{computer-use-RIDTFLYZ.js → computer-use-MBKJPMWZ.js} +4 -4
  13. package/chunks/{cron-create-T5QOBRRU.js → cron-create-K6DCVCY3.js} +1 -1
  14. package/chunks/{cron-delete-JXDOHSJF.js → cron-delete-XNCDKPVV.js} +1 -1
  15. package/chunks/{cron-list-ZQ76A2FW.js → cron-list-3IPROBTC.js} +1 -1
  16. package/chunks/{edit-LDTYXEVU.js → edit-72ASKQO7.js} +17 -17
  17. package/chunks/{enter-worktree-FOFQXTPW.js → enter-worktree-YYH4RD3G.js} +1 -1
  18. package/chunks/{enterPlanMode-2GHHILQY.js → enterPlanMode-SKK26RKS.js} +1 -1
  19. package/chunks/{exit-worktree-OK7AD7DC.js → exit-worktree-5K5Y2UR4.js} +1 -1
  20. package/chunks/{exitPlanMode-EANVOWTX.js → exitPlanMode-XDH6WKKD.js} +1 -1
  21. package/chunks/{glob-VZD7TOML.js → glob-3PF3E5R2.js} +1 -1
  22. package/chunks/{goal-tools-REBEAKVP.js → goal-tools-4SWS6CGW.js} +1 -1
  23. package/chunks/{grep-JPEHWEM3.js → grep-RQLOBTPU.js} +3 -3
  24. package/chunks/monitor-ZS5E3EAX.js +33 -0
  25. package/chunks/notebook-edit-JMRHVFA4.js +17 -0
  26. package/chunks/{openaiContentGenerator-QLDLWN4P.js → openaiContentGenerator-PRVYEJIU.js} +5 -5
  27. package/chunks/{read-file-4M76GCWT.js → read-file-GWUQN2ZM.js} +1 -1
  28. package/chunks/{ripGrep-LF2E2V6N.js → ripGrep-CWJYHBK6.js} +1 -1
  29. package/chunks/{scheduler-G4LEIBL4.js → scheduler-LPJ66QW3.js} +1 -1
  30. package/chunks/{shell-NUMSSUOV.js → shell-AXB4E537.js} +1 -1
  31. package/chunks/{skill-IVESDHGG.js → skill-7PMKFRET.js} +1 -1
  32. package/chunks/{symbol-search-BLJAKP7C.js → symbol-search-NHVD4D3O.js} +1 -1
  33. package/chunks/{team-create-QQD472XN.js → team-create-3S7UXATW.js} +1 -1
  34. package/chunks/{tool-search-LGTQYGTC.js → tool-search-ECQHNTSM.js} +1 -1
  35. package/chunks/{web-fetch-5X37JMDH.js → web-fetch-2BMJPIBC.js} +1 -1
  36. package/chunks/{web-search-62YZTP3D.js → web-search-CHJGDUDM.js} +1 -1
  37. package/chunks/{workflow-OT4I6TMY.js → workflow-H5E25IZN.js} +2 -2
  38. package/chunks/write-file-UPXM654K.js +15 -0
  39. package/cli.js +419 -419
  40. package/package.json +2 -2
  41. package/chunks/chunk-VBZS7ARJ.js +0 -8
  42. package/chunks/monitor-5WDGSYNZ.js +0 -33
  43. package/chunks/notebook-edit-W42S562V.js +0 -17
  44. package/chunks/write-file-GMIHG7AP.js +0 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maincode-ai/matilda-code",
3
- "version": "0.22.3-nightly.20261110.cb1234773",
3
+ "version": "0.22.4",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "cli.js",
@@ -26,7 +26,7 @@
26
26
  "bundled"
27
27
  ],
28
28
  "config": {
29
- "sandboxImageUri": "ghcr.io/maincode/matilda-code:0.22.3-nightly.20261110.cb1234773"
29
+ "sandboxImageUri": "ghcr.io/maincode/matilda-code:0.22.4"
30
30
  },
31
31
  "dependencies": {},
32
32
  "optionalDependencies": {
@@ -1,8 +0,0 @@
1
- // Force strict mode and setup for ESM
2
- "use strict";
3
- import{pa as n}from"./chunk-BEP4F3GO.js";import{l as i}from"./chunk-M5ABGGE7.js";import{b as r}from"./chunk-GZPNIYVZ.js";r();import c from"node:path";function g(t,s){if((n()??t.getApprovalMode())!=="bogan")return null;let o=c.resolve(s),a=t.getProjectRoot?.()??t.getTargetDir();if(i(o,a))return null;let e=t.getWorkspaceContext?.();if(!e||(typeof e.isPathWithinWorkspaceFresh=="function"?e.isPathWithinWorkspaceFresh(o):e.isPathWithinWorkspace(o)))return null;let p=e.getDirectories?.()??[t.getTargetDir()],l=t.getChannel?.()==="desktop"?"Approve the folder from Matilda Desktop, then retry the write.":"Use --include-directories to add extra roots, or a non-BOGAN approval mode for intentional external writes.";return`Refusing out-of-workspace write in BOGAN mode: ${o}. Workspace root(s): ${p.join(", ")}. This blocks path typos (e.g. writing under $HOME when the project is elsewhere). `+l}export{g as a};
4
- /**
5
- * @license
6
- * Copyright 2025 Matilda Team
7
- * SPDX-License-Identifier: Apache-2.0
8
- */
@@ -1,33 +0,0 @@
1
- // Force strict mode and setup for ESM
2
- "use strict";
3
- import{$ as st,Aa as gt,ba as D,da as at,db as ht,ea as P,fa as _,ga as lt,ha as mt,hb as yt,ma as ct,na as dt,qa as ut,ra as ft,sa as pt,vc as N,wc as vt,za as O}from"./chunk-BEP4F3GO.js";import{l as rt}from"./chunk-HK3QQSM7.js";import"./chunk-TXMXCR7D.js";import"./chunk-YULUB745.js";import"./chunk-NO6BFSGG.js";import"./chunk-R373GBK6.js";import"./chunk-VNSW4TSX.js";import"./chunk-EEPSTT7K.js";import"./chunk-DERMLVT6.js";import"./chunk-JZMGEGR6.js";import"./chunk-JVQHQDDE.js";import"./chunk-QXSBPCBA.js";import"./chunk-WAZCC4SE.js";import"./chunk-V6UPUMP3.js";import"./chunk-5B2QERWR.js";import"./chunk-TVNM3PQ7.js";import"./chunk-7ZODGQO6.js";import"./chunk-GT6MSEK4.js";import"./chunk-N3AQRPV5.js";import"./chunk-LBQNFSZ2.js";import"./chunk-GDRS4OWI.js";import"./chunk-B7BF33U4.js";import"./chunk-M5ABGGE7.js";import"./chunk-QKAKC34Q.js";import"./chunk-T6MRYRLI.js";import"./chunk-3EQIOCSJ.js";import"./chunk-XPVKH5TC.js";import"./chunk-J6NYCXUR.js";import"./chunk-UM6CLO7D.js";import"./chunk-YUCEPXGG.js";import{K as Q,e as u,ea as tt,ka as et,la as ot,ra as nt,sa as it}from"./chunk-4SDFTVQW.js";import"./chunk-HEJO7OBH.js";import{b as Y}from"./chunk-GZPNIYVZ.js";import"./chunk-OWGSC52X.js";Y();import{spawn as Tt}from"node:child_process";import _t from"node:path";import{randomUUID as Lt}from"node:crypto";var p=tt("MONITOR"),Pt=1e3,B=1e4,Ot=3e5,U=6e5,Ct=80,R=4096,wt=5,bt=1e3;function Mt(c){return c.length>Ct?c.slice(0,Ct-1)+"\u2026":c}var Nt=new Set(["task-notification","task-id","tool-use-id","kind","status","event-count","summary","result"]),Bt=/<(\/?)([a-zA-Z][a-zA-Z0-9-]*)>/g;function Et(c){let g="";for(let t=0;t<c.length;t++){let n=c.charCodeAt(t);if(n===9){g+=c[t];continue}n<32||n>=128&&n<=159||(g+=c[t])}return g=g.replace(Bt,(t,n,i)=>Nt.has(String(i).toLowerCase())?n==="/"?`</\u200B${i}>`:`<\u200B${i}>`:t),g}var W=class extends et{constructor(t,n){super(n);this.config=t}callId;setCallId(t){this.callId=t}getDescription(){let t=this.params.description||_(this.params.command).spawnCommand;return`Monitor: ${Mt(t)}`}async getDefaultPermission(){if(D().shell!=="bash")return"ask";let t=_(this.params.command).spawnCommand;return await O(t,{cwd:this.params.directory||this.config.getTargetDir(),workspace:this.config.getWorkspaceContext()})?"allow":"ask"}async getConfirmationDetails(t){let n=D(),i=_(this.params.command);if(n.shell==="bash"&&await ft(),n.shell!=="bash"||!gt(i.safetyCommand,this.params.directory||this.config.getTargetDir()))return{type:"exec",title:"Monitor",command:i.spawnCommand,rootCommand:n.executable,permissionRules:[],hideAlwaysAllow:!0,onConfirm:async()=>{}};let h=at(i.safetyCommand),C=[];for(let l of h){let a=!1;try{a=await O(l,{cwd:this.params.directory||this.config.getTargetDir(),workspace:this.config.getWorkspaceContext()})}catch(m){p.warn("AST read-only check failed for monitor sub-command, falling back to ask:",m)}a||C.push(l)}let v=C.length>0?C:h,w=[...new Set(v.map(l=>P(l)).filter(l=>!!l))],r=[];try{let l=[];for(let a of v){let m=await pt(a);l.push(...m)}r=[...new Set(l)].map(a=>`Monitor(${a})`)}catch(l){p.warn("Failed to extract monitor command rules:",l),r=[`Monitor(${i.safetyCommand})`]}let d=mt(i.safetyCommand,this.params.command),b={type:"exec",title:"Monitor",command:i.spawnCommand,rootCommand:w.join(", ")||(P(i.safetyCommand)??i.spawnCommand),permissionRules:r,onConfirm:async(l,a)=>{}};return d&&(b.warnings=d),b}async execute(t){if(t.aborted)return{llmContent:"Monitor was cancelled before it could start.",returnDisplay:"Monitor cancelled."};let n=_(this.params.command),i=n.spawnCommand;n.strippedTrailingAmp&&p.warn("Stripped trailing & from monitor command \u2014 monitor lifecycle handles backgrounding");let h=Et(this.params.description||i),C=Mt(h),v=Math.min(this.params.max_events??Pt,B),w=Math.min(this.params.idle_timeout_ms??Ot,U),r=`mon_${Lt().replace(/-/g,"").slice(0,16)}`,d=this.config.getMonitorRegistry(),b=st()??void 0;if(d.getRunning().length>=N)return{llmContent:`Cannot start monitor: maximum concurrent monitors (${N}) reached. Stop an existing monitor first.`,returnDisplay:"Monitor rejected: too many concurrent monitors."};let a=new AbortController,m={monitorId:r,command:i,description:h,status:"running",startTime:Date.now(),abortController:a,toolUseId:this.callId,eventCount:0,lastEventTime:0,maxEvents:v,idleTimeoutMs:w,droppedLines:0,outputFile:vt(this.config.storage.getProjectDir(),this.config.getSessionId(),r),...b?{ownerAgentId:b}:{}},G=D(),I={executable:G.executable,args:[...G.argsPrefix,i]},z=ut(this.config),F=z&&ct(I.executable,I.args,z),{executable:St,args:kt}=F||I,o;try{o=Tt(St,kt,{cwd:this.params.directory||this.config.getTargetDir(),stdio:["ignore","pipe","pipe"],detached:!0,env:{...rt(),MATILDA_CODE:"1",TERM:"dumb",PAGER:"cat",...yt()}})}catch(e){return{llmContent:`Monitor failed to start: ${u(e)}`,returnDisplay:`Monitor failed: ${u(e)}`}}m.pid=o.pid;let M=!1,E,$=e=>{E??=e};o.on("error",$);let j={value:""},X={value:""},S=wt,A=Date.now(),L=e=>{let s=Et(e);if(s.length===0||s.trim().length===0)return;let y=Date.now(),T=y-A;if(T<0)p.warn(`Monitor ${r}: clock moved backwards by ${-T}ms, resetting refill timestamp`),A=y;else{let f=Math.floor(T/bt);f>0&&(S=Math.min(wt,S+f),A+=f*bt)}S>0?(S--,d.emitEvent(r,s)):m.droppedLines++},V=()=>{for(let e of[j,X]){let s=e.value.trim();s.length>0&&L(s),e.value=""}},Dt=()=>{if(!(M||!o.pid))if(process.platform==="win32")Tt("taskkill",["/pid",o.pid.toString(),"/f","/t"],{stdio:"ignore"}).on("error",s=>p.warn(`Monitor taskkill failed for pid ${o.pid}: ${u(s)}`));else{try{process.kill(-o.pid,"SIGTERM")}catch(e){p.warn(`Monitor ${r} SIGTERM failed (pid=${o.pid}): ${u(e)}`)}setTimeout(()=>{if(!M&&o.pid)try{process.kill(-o.pid,"SIGKILL")}catch(e){p.warn(`Monitor ${r} SIGKILL escalation failed (pid=${o.pid}): ${u(e)}`)}},200).unref?.()}},x=()=>{V(),Dt()};a.signal.addEventListener("abort",x,{once:!0}),a.signal.aborted&&x();try{d.register(m)}catch(e){return x(),a.signal.removeEventListener("abort",x),o.stdout?.destroy?.(),o.stderr?.destroy?.(),o.removeListener("error",$),o.on("error",()=>{}),{llmContent:`Monitor failed to start: ${u(e)}`,returnDisplay:`Monitor failed: ${u(e)}`}}let H=(e,s)=>{if(m.status!=="running")return;let y=ht(s.toString("utf-8"));if(e.value+=y,!e.value.includes(`
4
- `)&&e.value.length>R){let f=e.value.trim();f.length>0&&L(f.slice(0,R)+"..."),e.value="";return}let T=e.value.split(`
5
- `);e.value=T.pop()??"";for(let f of T){let k=f.trim();if(k.length===0)continue;let At=k.length>R?k.slice(0,R)+"...":k;L(At)}};o.stdout?.on("data",e=>H(j,e)),o.stderr?.on("data",e=>H(X,e));let J=!1,K=()=>{J||(J=!0,V(),a.signal.removeEventListener("abort",x),m.droppedLines>0&&p.info(`Monitor ${r} dropped ${m.droppedLines} lines due to throttling`))},Z=null,Rt=(e,s)=>{m.status==="running"&&(a.signal.aborted?d.cancel(r):e!==null&&e!==0?d.fail(r,`Exit code ${e}`):s?d.fail(r,`Killed by signal ${s}`):d.complete(r,e))},It=(e,s)=>{M=!0,Z={code:e,sig:s}},$t=(e,s)=>{M=!0,K();let y=Z??{code:e,sig:s};Rt(y.code,y.sig)},q=e=>{M=!0,K(),m.status==="running"&&d.fail(r,u(e))};return o.on("exit",It),o.on("close",$t),o.on("error",q),o.removeListener("error",$),E?(q(E),{llmContent:`Monitor failed to start: ${u(E)}`,returnDisplay:`Monitor failed: ${u(E)}`}):{llmContent:`Monitor started.
6
- id: ${r}
7
- command: ${i}
8
- description: ${h}
9
- max_events: ${v}
10
- idle_timeout: ${w}ms
11
- `+(F?`${dt}
12
- `:"")+`Events will be delivered as notifications. The monitor auto-stops after ${v} events or ${w}ms of silence.
13
- To inspect: /tasks (text) or the interactive Background tasks dialog (focus the footer Background tasks pill, then Enter \u2014 detail view + live updates).`,returnDisplay:`Monitor started: ${C} (${r})`}}},xt=class c extends ot{constructor(t){super(c.Name,it.MONITOR,`Starts a long-running shell command and streams its stdout/stderr as event notifications back to you.
14
-
15
- Use this tool for:
16
- - Watching log files: \`tail -f /var/log/app.log\`
17
- - Monitoring build output: \`npm run build --watch\`
18
- - Polling for state changes: \`while true; do curl -s http://localhost:8080/health; sleep 1; done\`
19
- - Watching file changes: \`fswatch -r ./src\`
20
-
21
- Each output line from the command becomes a notification event delivered to you. The monitor runs in the background \u2014 you can continue working while it streams events.
22
-
23
- **Auto-stop:** The monitor automatically stops after max_events (default 1000) events or after idle_timeout_ms (default 5 minutes) of silence. The process is killed when the monitor stops.
24
-
25
- **Do NOT use this tool for:**
26
- - One-shot commands (use run_shell_command instead)
27
- - Commands you need the full output from (use run_shell_command instead)
28
- - Commands with no output (use run_shell_command with is_background: true instead)`,"execute",{type:"object",properties:{command:{type:"string",description:"Shell command to run and monitor. Each output line (stdout and stderr) becomes an event notification."},description:{type:"string",description:'Brief description of what this monitor watches (e.g., "webpack build output"). Truncated to 80 characters in display.'},max_events:{type:"number",description:"Stop the monitor after this many events. Default 1000. Max 10000."},idle_timeout_ms:{type:"number",description:"Stop the monitor if no output for this many milliseconds. Default 300000 (5 min). Max 600000."},directory:{type:"string",description:"(OPTIONAL) The absolute path of the directory to run the command in. If not provided, the project root directory is used. Must be within the workspace."}},required:["command"],additionalProperties:!1},!0,!1,!0,!1,"monitor watch tail log stream background");this.config=t}static Name=nt.MONITOR;validateToolParamValues(t){if(typeof t.command!="string"||!_(t.command).analysisCommand)return"Command cannot be empty.";if(lt(t.command))return'Monitor commands must not contain non-final top-level background operators. Remove "&" and let the monitor manage process lifetime.';if(t.max_events!==void 0){if(typeof t.max_events!="number"||!Number.isInteger(t.max_events)||t.max_events<=0)return"max_events must be a positive integer.";if(t.max_events>B)return`max_events cannot exceed ${B}.`}if(t.idle_timeout_ms!==void 0){if(typeof t.idle_timeout_ms!="number"||!Number.isInteger(t.idle_timeout_ms)||t.idle_timeout_ms<=0)return"idle_timeout_ms must be a positive integer.";if(t.idle_timeout_ms>U)return`idle_timeout_ms cannot exceed ${U}ms (10 minutes).`}if(t.directory){if(!_t.isAbsolute(t.directory))return"Directory must be an absolute path.";let n=_t.resolve(t.directory),i=this.config.storage.getUserSkillsDirs();if(Q(i,n))return"Explicitly running monitor commands from within the user skills directory is not allowed. Please use absolute paths for command parameter instead.";if(!this.config.getWorkspaceContext().isPathWithinWorkspace(t.directory))return`Directory '${t.directory}' is not within any of the registered workspace directories.`}return null}createInvocation(t){return new W(this.config,t)}toAutoClassifierInput(t){let n={command:t.command};return t.directory&&(n.directory=t.directory),n}};export{xt as MonitorTool,Et as sanitizeMonitorLine};
29
- /**
30
- * @license
31
- * Copyright 2025 Matilda
32
- * SPDX-License-Identifier: Apache-2.0
33
- */
@@ -1,17 +0,0 @@
1
- // Force strict mode and setup for ESM
2
- "use strict";
3
- import{a as te}from"./chunk-VBZS7ARJ.js";import{$a as X,Y,_a as D,jb as g,m as R,qb as Z,rb as ee}from"./chunk-BEP4F3GO.js";import"./chunk-HK3QQSM7.js";import"./chunk-TXMXCR7D.js";import"./chunk-YULUB745.js";import"./chunk-NO6BFSGG.js";import"./chunk-R373GBK6.js";import"./chunk-VNSW4TSX.js";import"./chunk-EEPSTT7K.js";import"./chunk-DERMLVT6.js";import"./chunk-JZMGEGR6.js";import"./chunk-JVQHQDDE.js";import"./chunk-QXSBPCBA.js";import"./chunk-WAZCC4SE.js";import"./chunk-V6UPUMP3.js";import"./chunk-5B2QERWR.js";import"./chunk-TVNM3PQ7.js";import"./chunk-7ZODGQO6.js";import"./chunk-GT6MSEK4.js";import"./chunk-N3AQRPV5.js";import"./chunk-LBQNFSZ2.js";import{Pb as Q,l as K,m as k,n as W,o as U,p as q,q as h,r as j,s as J,t as C,u as V,v as H,w,x as M,xa as z,z as G}from"./chunk-GDRS4OWI.js";import"./chunk-B7BF33U4.js";import"./chunk-M5ABGGE7.js";import"./chunk-QKAKC34Q.js";import"./chunk-T6MRYRLI.js";import"./chunk-3EQIOCSJ.js";import"./chunk-XPVKH5TC.js";import"./chunk-J6NYCXUR.js";import"./chunk-UM6CLO7D.js";import"./chunk-YUCEPXGG.js";import{D as _,E as N,G as T,ea as $,ka as L,la as x,ra as f,sa as B}from"./chunk-4SDFTVQW.js";import"./chunk-HEJO7OBH.js";import{b as F}from"./chunk-GZPNIYVZ.js";import"./chunk-OWGSC52X.js";F();import*as E from"node:fs";import*as b from"node:path";var oe=$("NOTEBOOK_EDIT");function m(s,r,e){return oe.debug("prior-read-rejected",{path:s,reason:r,type:e.type,displayMessage:e.displayMessage}),e}var y=class extends Error{constructor(e,i){super(e);this.type=i;this.name="NotebookEditError"}};function ie(s,r){if(r==="delete")return"";if(typeof s!="string")throw new y(`new_source is required when edit_mode is "${r}".`,"invalid_tool_params");return s}function I(s,r){return s?q(s,r):`cell-${r}`}function re(s,r,e){if(!r){if(e==="insert")return-1;throw new y("cell_id is required for replace and delete operations.","invalid_tool_params")}if(j(s,r))throw new y(`Cell ID "${r}" is ambiguous in the rendered notebook. Re-read the notebook and target a stable real cell ID before editing.`,"invalid_tool_params");let i=J(s,r);if(i===-1)throw new y(`Cell with ID "${r}" not found in notebook.`,"notebook_cell_not_found");return i}function ne(s,r,e,i){let t={cell_type:r,metadata:{},source:w(e,i)},o=V(s);return o&&(t.id=o),M(t,r),t}function O(s,r){let e;try{e=k(s)}catch(l){throw new y(l instanceof Error?l.message:String(l),"notebook_invalid_json")}let i=r.edit_mode??"replace",t=ie(r.new_source,i),o=h(e),n=re(e,r.cell_id,i),d=C(e),c=W(s),a=(l,u)=>{let p=i==="insert"||i==="delete";return{...u,updatedContent:U(l,c),requiresReadAfterWrite:p&&!(o&&h(l))}};switch(i){case"insert":{let l=r.cell_type??"code",u=n===-1?0:n+1,p=ne(e,l,t,H(e,u));return e.cells.splice(u,0,p),a(e,{editedCellId:I(p,u),editedCellType:l,language:d,mode:i})}case"delete":{let[l]=e.cells.splice(n,1);return a(e,{editedCellId:I(l,n),editedCellType:l?.cell_type,language:d,mode:i})}case"replace":{let l=e.cells[n];if(!l)throw new y(`Cell index ${n} is out of range.`,"notebook_cell_not_found");let u=r.cell_type??l.cell_type;return l.source=w(t,Array.isArray(l.source)),M(l,u),a(e,{editedCellId:I(l,n),editedCellType:u,language:d,mode:i})}default:throw new y(`Unsupported notebook edit mode: ${i}`,"invalid_tool_params")}}function ae(s,r,e){let i,t;try{i=k(r),t=k(s)}catch(o){throw new y(o instanceof Error?o.message:String(o),"notebook_invalid_json")}return{updatedContent:r,editedCellId:e.cell_id??"user-modified-notebook",editedCellType:void 0,language:C(i),mode:e.edit_mode??"replace",requiresReadAfterWrite:!h(t)||!h(i)}}async function A(s,r,e={}){if(s.getFileReadCacheDisabled())return{ok:!0};let i;try{i=await E.promises.stat(r)}catch(o){let n=o?.code;return n==="ENOENT"?e.expectExisting?m(r,"missing-after-read",{ok:!1,type:"file_changed_since_read",rawMessage:`Notebook ${r} disappeared after it was read. Re-read it with the ${f.READ_FILE} tool before editing it.`,displayMessage:`notebook disappeared after last read; re-run ${f.READ_FILE} first.`}):{ok:!0}:m(r,"stat-failed",{ok:!1,type:"prior_read_verification_failed",rawMessage:`Could not stat ${r} to verify prior notebook read (${n??"unknown error"}). Re-read it with the ${f.READ_FILE} tool before editing it.`,displayMessage:`cannot verify prior read of ${r}; re-run ${f.READ_FILE} before editing this notebook.`})}if(i.isDirectory())return m(r,"target-is-directory",{ok:!1,type:"target_is_directory",rawMessage:`${r} is a directory. The NotebookEdit tool only operates on .ipynb files.`,displayMessage:"path is a directory; cannot edit as a notebook."});if(!i.isFile())return m(r,"target-not-regular-file",{ok:!1,type:"target_not_regular_file",rawMessage:`${r} is not a regular file. The NotebookEdit tool only operates on .ipynb files.`,displayMessage:"special file; cannot edit as a notebook."});let t=s.getFileReadCache().check(i);return t.state==="fresh"&&t.entry.lastReadAt!==void 0&&t.entry.lastReadWasFull?{ok:!0}:t.state==="fresh"&&t.entry.lastReadAt!==void 0&&!t.entry.lastReadWasFull?m(r,"truncated-cache-entry",{ok:!1,type:"edit_requires_prior_read",rawMessage:`Notebook ${r} is too large for cell-level editing because its rendered output was truncated when read. Reduce the notebook output size or split the notebook before editing cells.`,displayMessage:"notebook too large for cell-level editing."}):t.state==="stale"?m(r,"stale-cache-entry",{ok:!1,type:"file_changed_since_read",rawMessage:`Notebook ${r} has been modified since you last read it. Re-read it with the ${f.READ_FILE} tool before editing it.`,displayMessage:`notebook changed since last read; re-run ${f.READ_FILE} first.`}):m(r,`cache-${t.state}`,{ok:!1,type:"edit_requires_prior_read",rawMessage:`Notebook ${r} has not been fully read in this session. Use the ${f.READ_FILE} tool first, without offset or limit, before editing cells.`,displayMessage:`${f.READ_FILE} required before editing this notebook.`})}var P=class extends L{constructor(e,i,t){super(i);this.config=e;this.modifyMetadata=t}toolLocations(){return[{path:this.params.notebook_path}]}getDescription(){let e=N(this.params.notebook_path,this.config.getTargetDir()),i=this.params.edit_mode??"replace",t=this.params.cell_id??"beginning";return`${i} notebook cell ${t} in ${_(e)}`}async getDefaultPermission(){return"ask"}outOfWorkspaceRefusal(){let e=te(this.config,this.params.notebook_path);return e?{llmContent:e,returnDisplay:e,error:{message:e,type:"path_not_in_workspace"}}:void 0}async getConfirmationDetails(e){let i=this.outOfWorkspaceRefusal();if(i)throw new g(i.error.message,"path_not_in_workspace");let t=await this.prepareEdit(e),o=b.basename(this.params.notebook_path),n=R(o,t.originalContent,t.updatedContent,"Current","Proposed",D);return{type:"edit",title:`Confirm Notebook Edit: ${_(N(this.params.notebook_path,this.config.getTargetDir()))}`,fileName:o,filePath:this.params.notebook_path,fileDiff:n,originalContent:t.originalContent,newContent:t.updatedContent,onConfirm:async c=>{c==="proceed_always"&&this.config.setApprovalMode("auto-edit")}}}async prepareEdit(e){let i=await A(this.config,this.params.notebook_path);if(!i.ok)throw new g(i.rawMessage,i.type);let t,o=!1,n,d="lf";try{let a=await this.config.getFileSystemService().readTextFile({path:this.params.notebook_path});t=a.content,o=a._meta?.bom??!1,n=a._meta?.encoding,d=a._meta?.lineEnding??Z(a.content)}catch(a){throw e.aborted?a:a?.code==="ENOENT"?new g(`Notebook file not found: ${this.params.notebook_path}`,"file_not_found"):new g(`Error reading notebook: ${a instanceof Error?a.message:String(a)}`,"read_content_failure")}let c=await A(this.config,this.params.notebook_path,{expectExisting:!0});if(!c.ok)throw new g(c.rawMessage,c.type);try{return this.modifyMetadata?.modifiedNotebookContent!==void 0?{...ae(t,this.modifyMetadata.modifiedNotebookContent,this.params),originalContent:t,bom:o,encoding:n,lineEnding:d}:{...O(t,this.params),originalContent:t,bom:o,encoding:n,lineEnding:d}}catch(a){throw a instanceof y?new g(a.message,a.type):a}}async execute(e){let i=this.outOfWorkspaceRefusal();if(i)return i;let t;try{t=await this.prepareEdit(e)}catch(o){if(e.aborted)throw o;let n=o instanceof g?o.errorType:"notebook_edit_failure",d=o instanceof Error?o.message:String(o);return{llmContent:d,returnDisplay:`Error: ${d}`,error:{message:d,type:n}}}try{try{await this.config.getFileHistoryService().trackEdit(this.params.notebook_path)}catch{}let o=await A(this.config,this.params.notebook_path,{expectExisting:!0});if(!o.ok)return{llmContent:o.rawMessage,returnDisplay:`Error: ${o.displayMessage}`,error:{message:o.rawMessage,type:o.type}};let n=this.outOfWorkspaceRefusal();if(n)return n;await this.config.getFileSystemService().writeTextFile({path:this.params.notebook_path,content:t.updatedContent,_meta:{bom:t.bom,encoding:t.encoding,lineEnding:t.lineEnding}}),this.modifyMetadata?.modifiedByUser||Y.getInstance().recordEdit(this.params.notebook_path,t.originalContent,t.updatedContent);try{let p=E.statSync(this.params.notebook_path),v=this.config.getFileReadCache();t.requiresReadAfterWrite?v.invalidate(p):v.recordWrite(this.params.notebook_path,p,{cacheable:!1})}catch(p){oe.warn(`[NotebookEdit] post-write cache update failed for ${this.params.notebook_path}: ${p instanceof Error?p.message:String(p)}`)}let d=b.basename(this.params.notebook_path),c=R(d,t.originalContent,t.updatedContent,"Current","Proposed",D),a=X(d,t.originalContent,this.modifyMetadata?.aiProposedContent??t.updatedContent,t.updatedContent);z(this.config,new Q(S.Name,"update",t.updatedContent.split(`
4
- `).length,G(this.params.notebook_path),".ipynb",t.language));let l={fileDiff:c,fileName:d,originalContent:t.originalContent,newContent:t.updatedContent,diffStat:a},u=this.modifyMetadata?.modifiedNotebookContent!==void 0?`Notebook ${this.params.notebook_path} has been updated. Notebook content was modified by the user before approval; the final saved notebook may differ from the original ${t.mode} cell ${t.editedCellId} proposal.`:`Notebook ${this.params.notebook_path} has been updated. ${t.mode} cell ${t.editedCellId}.${t.mode==="delete"?"":`
5
-
6
- Updated source:
7
-
8
- ---
9
-
10
- ${K(this.params.new_source??"")}`}`;try{let p=await ee(this.config,this.params.notebook_path);p&&(u+=`
11
-
12
- ${p}`)}catch{}return{llmContent:u,returnDisplay:l,resultFilePaths:[this.params.notebook_path]}}catch(o){let n=o instanceof Error?o.message:String(o);return{llmContent:`Error writing notebook: ${n}`,returnDisplay:`Error writing notebook: ${n}`,error:{message:n,type:"file_write_failure"}}}}},S=class s extends x{constructor(e){super(s.Name,B.NOTEBOOK_EDIT,`Edits a Jupyter notebook (.ipynb) safely at the cell level. Use this instead of ${f.EDIT} or ${f.WRITE_FILE} for notebook cells. Supports replacing, inserting, and deleting cells. Always read the notebook first with ${f.READ_FILE}; then use the cell IDs shown in that output.`,"edit",{properties:{notebook_path:{description:"Absolute path to the Jupyter notebook file to edit. Must end with .ipynb.",type:"string"},cell_id:{description:"Target cell ID from read_file output, or cell-N 0-based fallback. Required for replace and delete. For insert, the new cell is inserted after this cell; if omitted, inserted at the beginning.",type:"string"},new_source:{description:"New source content for replace and insert operations. Not required for delete.",type:"string"},cell_type:{description:"Cell type for inserted cells or type conversion on replace.",type:"string",enum:["code","markdown"]},edit_mode:{description:"Notebook edit operation. Defaults to replace.",type:"string",enum:["replace","insert","delete"]}},required:["notebook_path"],additionalProperties:!1,type:"object"});this.config=e}static Name=f.NOTEBOOK_EDIT;modifyMetadataByParams=new WeakMap;modifyMetadataByKey=new Map;validateToolParamValues(e){if(e.notebook_path=T(e.notebook_path.trim()),!e.notebook_path)return"The 'notebook_path' parameter must be non-empty.";if(!b.isAbsolute(e.notebook_path))return`Notebook path must be absolute: ${e.notebook_path}`;if(b.extname(e.notebook_path).toLowerCase()!==".ipynb")return"File must be a Jupyter notebook (.ipynb). Use the edit tool for other file types.";let i=e.edit_mode??"replace";return["replace","insert","delete"].includes(i)?e.cell_type&&!["code","markdown"].includes(e.cell_type)?"cell_type must be 'code' or 'markdown'.":i!=="insert"&&!e.cell_id?"cell_id is required for replace and delete operations.":i!=="delete"&&typeof e.new_source!="string"?`new_source is required when edit_mode is "${i}".`:this.config.getFileService().shouldMatildaIgnoreFile(e.notebook_path)?`File path '${e.notebook_path}' is ignored by .matildaignore pattern(s).`:null:"edit_mode must be 'replace', 'insert', or 'delete'."}createInvocation(e){return new P(this.config,e,this.consumeModifyMetadata(e))}getModifyMetadataKey(e){return JSON.stringify({notebook_path:T(e.notebook_path.trim()),cell_id:e.cell_id,new_source:e.new_source,cell_type:e.cell_type,edit_mode:e.edit_mode})}rememberModifyMetadata(e,i){this.modifyMetadataByParams.set(e,i);let t=this.getModifyMetadataKey(e),o=this.modifyMetadataByKey.get(t)??[];o.push(i),this.modifyMetadataByKey.set(t,o)}consumeModifyMetadata(e){let i=this.modifyMetadataByParams.get(e);if(i)return this.modifyMetadataByParams.delete(e),this.removeQueuedModifyMetadata(e,i),i;let t=this.getModifyMetadataKey(e),o=this.modifyMetadataByKey.get(t),n=o?.shift();return o&&o.length===0&&this.modifyMetadataByKey.delete(t),n}removeQueuedModifyMetadata(e,i){let t=this.getModifyMetadataKey(e),o=this.modifyMetadataByKey.get(t);if(!o)return;let n=o.indexOf(i);n!==-1&&o.splice(n,1),o.length===0&&this.modifyMetadataByKey.delete(t)}getModifyContext(e){let i=new Map,t=async o=>{let n=i.get(o.notebook_path);if(n!==void 0)return n;let{content:d}=await this.config.getFileSystemService().readTextFile({path:o.notebook_path});return i.set(o.notebook_path,d),d};return{getFilePath:o=>o.notebook_path,getCurrentContent:async o=>t(o),getProposedContent:async o=>{let n=await t(o);return O(n,o).updatedContent},createUpdatedParams:(o,n,d)=>{let c=this.modifyMetadataByParams.get(d)?.aiProposedContent;if(c===void 0)try{c=O(o,d).updatedContent}catch{c=n}let a={...d};return this.rememberModifyMetadata(a,{aiProposedContent:c,modifiedByUser:!0,modifiedNotebookContent:n}),a}}}};export{S as NotebookEditTool,O as applyNotebookEdit};
13
- /**
14
- * @license
15
- * Copyright 2026 Matilda Team
16
- * SPDX-License-Identifier: Apache-2.0
17
- */
@@ -1,15 +0,0 @@
1
- // Force strict mode and setup for ESM
2
- "use strict";
3
- import{a as _}from"./chunk-VBZS7ARJ.js";import{$a as Q,Y as G,_a as k,jb as P,kb as u,m as b,ob as V,pb as J,qb as X,rb as ee}from"./chunk-BEP4F3GO.js";import"./chunk-HK3QQSM7.js";import"./chunk-TXMXCR7D.js";import"./chunk-YULUB745.js";import"./chunk-NO6BFSGG.js";import"./chunk-R373GBK6.js";import"./chunk-VNSW4TSX.js";import"./chunk-EEPSTT7K.js";import"./chunk-DERMLVT6.js";import"./chunk-JZMGEGR6.js";import"./chunk-JVQHQDDE.js";import"./chunk-QXSBPCBA.js";import"./chunk-WAZCC4SE.js";import"./chunk-V6UPUMP3.js";import"./chunk-5B2QERWR.js";import"./chunk-TVNM3PQ7.js";import"./chunk-7ZODGQO6.js";import"./chunk-GT6MSEK4.js";import"./chunk-N3AQRPV5.js";import"./chunk-LBQNFSZ2.js";import{C,H as z,Pb as Y,xa as H,z as B}from"./chunk-GDRS4OWI.js";import"./chunk-B7BF33U4.js";import{l as K,m as Z,n as q}from"./chunk-M5ABGGE7.js";import"./chunk-QKAKC34Q.js";import"./chunk-T6MRYRLI.js";import"./chunk-3EQIOCSJ.js";import"./chunk-XPVKH5TC.js";import"./chunk-J6NYCXUR.js";import"./chunk-UM6CLO7D.js";import"./chunk-YUCEPXGG.js";import{D as R,E as S,G as M,c as d,e as D,ea as N,ka as $,la as L,ra as j,sa as U}from"./chunk-4SDFTVQW.js";import"./chunk-HEJO7OBH.js";import{b as O}from"./chunk-GZPNIYVZ.js";import"./chunk-OWGSC52X.js";O();import v from"node:fs";import y from"node:path";var F=N("WRITE_FILE"),fe=["filePath","filepath","path","file","filename"];function ge(f){if(!(typeof f.file_path=="string"&&f.file_path.trim()))for(let s of fe){let o=f[s];if(typeof o=="string"&&o.trim()){f.file_path=o,delete f[s];return}}}function pe(f){let s=f.content;if(typeof s!="string"||!s.includes("<arg_")&&!s.includes("</arg_"))return;let o={},e=/<arg_key>\s*([A-Za-z_][\w]*)\s*<\/arg_key>\s*<arg_value>\s*([\s\S]+?)(?:<\/arg_value>|(?=<arg_key\b)|$)/gi,r;for(;(r=e.exec(s))!==null;){let i=r[1].toLowerCase(),n=r[2].trim();n&&(o[i]=n)}let l=/(?:^|[^>])([A-Za-z_][\w]*)\s*<\/arg_key>\s*<arg_value>\s*([\s\S]+?)(?:<\/arg_value>|(?=<arg_key\b)|(?=[A-Za-z_][\w]*\s*<\/arg_key>)|$)/gi;for(;(r=l.exec(s))!==null;){let i=r[1].toLowerCase(),n=r[2].trim();(n&&!o[i]||n&&n.length>=(o[i]?.length??0))&&(o[i]=n)}let h=[s.search(/<arg_key\b/i),s.search(/<\/arg_key\b/i),s.search(/<arg_value\b/i)].filter(i=>i>=0),g=h.length>0?Math.min(...h):-1;if(g>=0&&s.slice(g,g+10).startsWith("</arg_key")){let i=s.slice(0,g),n=/([A-Za-z_][\w]*)\s*$/.exec(i);n&&(g=n.index)}let c=g>=0?s.slice(0,g).trimEnd():s;c=c.replace(/<\/?arg_(?:key|value)\b[^>]*>/gi,"").trimEnd(),f.content=c;let m=new Set(["file_path","filepath","path","file","filename"]);for(let[i,n]of Object.entries(o))!m.has(i)||!n||!n.startsWith("/")&&!/^[A-Za-z]:[\\/]/.test(n)||(typeof f.file_path!="string"||!String(f.file_path).trim()||n.length>String(f.file_path).length)&&(f.file_path=n)}var A=class extends ${constructor(o,e){super(e);this.config=o}toolLocations(){return[{path:this.params.file_path}]}getDescription(){let o=S(this.params.file_path,this.config.getTargetDir());return`Writing to ${R(o)}`}async getDefaultPermission(){let o=this.config.getProjectRoot();return K(y.resolve(this.params.file_path),o)?"allow":"ask"}async getConfirmationDetails(o){let e=_(this.config,this.params.file_path);if(e)throw new P(e,"path_not_in_workspace");let r="",l=await C(this.params.file_path);if(!this.config.getFileReadCacheDisabled()){let i=await u(this.config.getFileReadCache(),this.params.file_path,"overwriting");if(!i.ok)throw new P(i.rawMessage,i.type)}if(l)try{let{content:i}=await this.config.getFileSystemService().readTextFile({path:this.params.file_path});r=i}catch(i){if(d(i)&&i.code==="ENOENT")l=!1;else throw new Error(`Error reading existing file for confirmation: ${D(i)}`)}if(l&&!this.config.getFileReadCacheDisabled()){let i=await u(this.config.getFileReadCache(),this.params.file_path,"overwriting",{expectExisting:!0});if(!i.ok)throw F.warn("post-read TOCTOU rejection (confirmation)",{path:this.params.file_path,reason:i.type}),new P(i.rawMessage,i.type)}let h=S(this.params.file_path,this.config.getTargetDir()),g=y.basename(this.params.file_path),c=b(g,r,this.params.content,"Current","Proposed",k);return{type:"edit",title:`Confirm Write: ${R(h)}`,fileName:g,filePath:this.params.file_path,fileDiff:c,originalContent:r,newContent:this.params.content,onConfirm:async i=>{i==="proceed_always"&&this.config.setApprovalMode("auto-edit")}}}async execute(o){let{file_path:e,content:r,ai_proposed_content:l,modified_by_user:h}=this.params,g=_(this.config,e);if(g)return{llmContent:g,returnDisplay:g,error:{message:g,type:"path_not_in_workspace"}};let c=await C(e),m="",i=!1,n,I,te=y.dirname(e);if(!this.config.getFileReadCacheDisabled()){let t=await u(this.config.getFileReadCache(),e,"overwriting");if(!t.ok)return{llmContent:t.rawMessage,returnDisplay:`Error: ${t.displayMessage}`,error:{message:t.rawMessage,type:t.type}}}if(c)try{let t=await this.config.getFileSystemService().readTextFile({path:e});t._meta?.bom!==void 0?i=t._meta.bom:i=t.content.length>0&&t.content.codePointAt(0)===65279,n=t._meta?.encoding||"utf-8",I=X(t.content),m=t.content,c=!0}catch(t){if(d(t)&&t.code==="ENOENT")c=!1;else{let a={message:D(t),code:d(t)?t.code:void 0},p=a.code?`Error checking existing file '${e}': ${a.message} (${a.code})`:`Error checking existing file: ${a.message}`;return{llmContent:p,returnDisplay:p,error:{message:p,type:"file_write_failure"}}}}if(c&&!this.config.getFileReadCacheDisabled()){let t=await u(this.config.getFileReadCache(),e,"overwriting",{expectExisting:!0});if(!t.ok)return F.warn("post-read TOCTOU rejection (execute)",{path:e,reason:t.type}),{llmContent:t.rawMessage,returnDisplay:`Error: ${t.displayMessage}`,error:{message:t.rawMessage,type:t.type}}}if(!c){let t=this.config.getDefaultFileEncoding();t===V.UTF8_BOM?i=!0:t===void 0&&(i=J(e)),n=void 0}try{await this.config.getFileHistoryService().trackEdit(e)}catch{}if(!this.config.getFileReadCacheDisabled()){let t=await u(this.config.getFileReadCache(),e,"overwriting",{expectExisting:c});if(!t.ok)return F.warn("pre-write TOCTOU rejection",{path:e,reason:t.type}),{llmContent:t.rawMessage,returnDisplay:`Error: ${t.displayMessage}`,error:{message:t.rawMessage,type:t.type}}}let E=_(this.config,e);if(E)return{llmContent:E,returnDisplay:E,error:{message:E,type:"path_not_in_workspace"}};c||v.mkdirSync(te,{recursive:!0});try{let t=_(this.config,e);if(t)return{llmContent:t,returnDisplay:t,error:{message:t,type:"path_not_in_workspace"}};let a=q(e,this.config.getProjectRoot(),r);await this.config.getFileSystemService().writeTextFile({path:e,content:a,_meta:{bom:i,encoding:n,lineEnding:I}}),h||G.getInstance().recordEdit(e,c?m:null,r);try{let w=v.statSync(e);this.config.getFileReadCache().recordWrite(e,w)}catch{}let p=y.basename(e),W=m,ie=b(p,W,r,"Original","Written",k),oe=Q(p,W,l||r,r),T=[c?`Successfully overwrote file: ${e}.`:`Successfully created and wrote to new file: ${e}.`];a!==r&&T.push(Z),h&&T.push(`User modified the \`content\` to be: ${r}`);let re=B(e),ne=z(e),se=y.extname(e),ae=c?"update":"create",le=r.split(`
4
- `).length;H(this.config,new Y(x.Name,ae,le,re,se,ne));let ce={fileDiff:ie,fileName:p,originalContent:m,newContent:r,diffStat:oe};try{let w=await ee(this.config,e);w&&T.push(`
5
-
6
- ${w}`)}catch{}return{llmContent:T.join(" "),returnDisplay:ce}}catch(t){let a,p="file_write_failure";return d(t)?(a=`Error writing to file '${e}': ${t.message} (${t.code})`,t.code==="EACCES"?(a=`Permission denied writing to file: ${e} (${t.code})`,p="permission_denied"):t.code==="ENOSPC"?(a=`No space left on device: ${e} (${t.code})`,p="no_space_left"):t.code==="EISDIR"&&(a=`Target is a directory, not a file: ${e} (${t.code})`,p="target_is_directory"),this.config.getDebugMode()&&t.stack&&F.debug("Write file error stack:",t.stack)):t instanceof Error?a=`Error writing to file: ${t.message}`:a=`Error writing to file: ${String(t)}`,{llmContent:a,returnDisplay:a,error:{message:a,type:p}}}}},x=class f extends L{constructor(o){super(f.Name,U.WRITE_FILE,`Writes content to a specified file in the local filesystem.
7
-
8
- CRITICAL: Always emit file_path FIRST (absolute path), then content. Never omit file_path. Construct absolute paths from the project root + relative path (e.g. '/path/to/project/' + 'foo/bar.txt'). Relative paths are not supported.
9
-
10
- The user has the ability to modify \`content\`. If modified, this will be stated in the response.`,"edit",{properties:{file_path:{description:"REQUIRED. Absolute path to write (e.g. '/home/user/project/src/auth.ts'). Emit this BEFORE content.",type:"string"},content:{description:"The full file contents to write. Only after file_path is set.",type:"string"}},required:["file_path","content"],type:"object"});this.config=o}static Name=j.WRITE_FILE;validateToolParams(o){let e=o;return pe(e),ge(e),(typeof o.file_path!="string"||!o.file_path.trim())&&typeof o.content=="string"&&o.content.length>0?'WriteFile requires absolute "file_path" (emit file_path first, then content). Retry with both file_path and content.':super.validateToolParams(o)}validateToolParamValues(o){let e=M(o.file_path.trim());if(o.file_path=e,!e)return'Missing or empty "file_path"';if(!y.isAbsolute(e))return`File path must be absolute: ${e}`;try{if(v.existsSync(e)&&v.lstatSync(e).isDirectory())return`Path is a directory, not a file: ${e}`}catch(r){return`Error accessing path properties for validation: ${e}. Reason: ${r instanceof Error?r.message:String(r)}`}return null}createInvocation(o){return new A(this.config,o)}toAutoClassifierInput(o){let e=o.content??"";return{file_path:o.file_path,byte_count:Buffer.byteLength(e,"utf8"),content_preview:e.slice(0,300),content_truncated:e.length>300}}getModifyContext(o){return{getFilePath:e=>e.file_path,getCurrentContent:async e=>{if(await C(e.file_path))try{let{content:l}=await this.config.getFileSystemService().readTextFile({path:e.file_path});return l}catch(l){if(!d(l)||l.code!=="ENOENT")throw l;return""}else return""},getProposedContent:async e=>e.content,createUpdatedParams:(e,r,l)=>{let h=l.content;return{...l,ai_proposed_content:h,content:r,modified_by_user:!0}}}}};export{x as WriteFileTool,ge as normalizeWriteFilePathAliases,pe as repairLeakedWriteFileToolArgMarkup};
11
- /**
12
- * @license
13
- * Copyright 2025 Google LLC
14
- * SPDX-License-Identifier: Apache-2.0
15
- */