@gencode/agents 0.9.3-preview.4 → 0.9.3-preview.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -57,10 +57,10 @@ Preview:
|
|
|
57
57
|
`);return[`[context collapse] ${t.length} tool results across ${n.join(`, `)}`,i?`Assistant checkpoints:\n${i}`:``,r?`Recent tool findings:\n${r}`:``].filter(Boolean).join(`
|
|
58
58
|
|
|
59
59
|
`)}function zd(e){return e.role===`tool_result`}function Bd(e){return e.toolName===`skill_load`}function Vd(e){let t=Hd(e),n=t.name||`<skill-name>`,r=t.path?`skill_load(name="${n}", skillPath="${t.path}")`:`skill_load(name="${n}")`;return[`[skill content folded] The previous skill_load result for "${n}" was folded out of model-visible context.`,`The complete SKILL.md content is no longer available in the current prompt.`,`Before using this skill again, call ${r} again. Do not infer or reconstruct the skill instructions from memory or summaries.`,t.path?`Original path: ${t.path}`:``].filter(Boolean).join(`
|
|
60
|
-
`)}function Hd(e){for(let t of[e.content,e.toolResultRef?.preview??``]){let e=Ud(t);if(e.name||e.path)return e}return{}}function Ud(e){let t=e.trim();if(!t)return{};try{let e=JSON.parse(t);if(e.success===!0)return{name:typeof e.name==`string`?e.name:void 0,path:typeof e.path==`string`?e.path:void 0}}catch{}let n=t.match(/\[skill content persisted\] skill_load output for "([^"]+)"/)?.[1],r=t.match(/\[skill content folded\] The previous skill_load result for "([^"]+)"/)?.[1],i=t.match(/^Original path: (.+)$/m)?.[1]?.trim();return{name:n??r,path:i}}function Wd(e){return e.reduce((e,t)=>e+(t.role===`user`?1:0),0)}function Gd(e){for(let t=e.length-1;t>=0;--t)if(e[t]?.role===`compaction`)return t;return-1}function Kd(e){let t=e.pendingUserMessage?.trim()?Z([{role:`user`,content:e.pendingUserMessage,timestamp:new Date(0).toISOString()}]):0;if(!e.checkpoint){let n=Z(e.workingEntries)+t;return{projectedInputTokens:n,estimatedIncrementTokens:n}}let n=Z(e.entries.slice(Math.max(0,e.checkpoint.coveredTranscriptEntryCount)).filter(e=>e.role!==`compaction`))+t;return{projectedInputTokens:e.checkpoint.inputTokens+n,estimatedIncrementTokens:n}}async function qd(e,t,n,r){let i=k(e,t,r);await V.mkdir(H.dirname(i),{recursive:!0}),await V.appendFile(i,`${JSON.stringify(n)}\n`,`utf-8`)}async function Jd(e){let t={storeName:e.sessionStoreName,...e.sessionPathScope},n=await xd({dataDir:e.dataDir,sessionId:e.sessionId,...t});return{async getReusableRead(e,t,r){let i=await n.findReusableRead(e,t,r);return i?{reused:!0,lineCount:i.lineCount}:{reused:!1}},async rememberRead(e){await n.recordRead(e)},async invalidateReadPath(e){await n.invalidatePath(e)},persistToolResult(e){return n.persistToolResult(e)},async recordModelUsage(e){await n.recordModelUsage({version:1,model:e.model,inputTokens:e.inputTokens,outputTokens:e.outputTokens,totalTokens:e.totalTokens,coveredTranscriptEntryCount:e.coveredTranscriptEntryCount,recordedAt:new Date().toISOString()})},manageHistory(t){return Nd({...t,contextStore:n,sessionStoreName:e.sessionStoreName,sessionPathScope:e.sessionPathScope})},getSnapshot:n.getSnapshot}}async function Yd(e){return e.contextManager?e.contextManager.manageHistory({entries:e.entries,modelInfo:e.modelInfo,contextWindowTokens:e.contextWindowTokens,llm:e.llm,historyLimit:e.historyLimit,compactionEnabled:e.compactionEnabled,pendingUserMessage:e.pendingUserMessage,topicSegmentation:e.topicSegmentation,signal:e.signal,hooks:e.hooks,hookCtx:e.hookCtx,dataDir:e.dataDir,sessionId:e.sessionId,sessionStoreName:e.sessionStoreName,channel:e.channel,isSubagent:e.isSubagent}):Nd({entries:e.entries,modelInfo:e.modelInfo,contextWindowTokens:e.contextWindowTokens,llm:e.llm,historyLimit:e.historyLimit,compactionEnabled:e.compactionEnabled,pendingUserMessage:e.pendingUserMessage,topicSegmentation:e.topicSegmentation,signal:e.signal,hooks:e.hooks,hookCtx:e.hookCtx,dataDir:e.dataDir,sessionId:e.sessionId,sessionStoreName:e.sessionStoreName,channel:e.channel,isSubagent:e.isSubagent})}const Xd=W.Object({command:W.String({description:`Shell command to execute
|
|
60
|
+
`)}function Hd(e){for(let t of[e.content,e.toolResultRef?.preview??``]){let e=Ud(t);if(e.name||e.path)return e}return{}}function Ud(e){let t=e.trim();if(!t)return{};try{let e=JSON.parse(t);if(e.success===!0)return{name:typeof e.name==`string`?e.name:void 0,path:typeof e.path==`string`?e.path:void 0}}catch{}let n=t.match(/\[skill content persisted\] skill_load output for "([^"]+)"/)?.[1],r=t.match(/\[skill content folded\] The previous skill_load result for "([^"]+)"/)?.[1],i=t.match(/^Original path: (.+)$/m)?.[1]?.trim();return{name:n??r,path:i}}function Wd(e){return e.reduce((e,t)=>e+(t.role===`user`?1:0),0)}function Gd(e){for(let t=e.length-1;t>=0;--t)if(e[t]?.role===`compaction`)return t;return-1}function Kd(e){let t=e.pendingUserMessage?.trim()?Z([{role:`user`,content:e.pendingUserMessage,timestamp:new Date(0).toISOString()}]):0;if(!e.checkpoint){let n=Z(e.workingEntries)+t;return{projectedInputTokens:n,estimatedIncrementTokens:n}}let n=Z(e.entries.slice(Math.max(0,e.checkpoint.coveredTranscriptEntryCount)).filter(e=>e.role!==`compaction`))+t;return{projectedInputTokens:e.checkpoint.inputTokens+n,estimatedIncrementTokens:n}}async function qd(e,t,n,r){let i=k(e,t,r);await V.mkdir(H.dirname(i),{recursive:!0}),await V.appendFile(i,`${JSON.stringify(n)}\n`,`utf-8`)}async function Jd(e){let t={storeName:e.sessionStoreName,...e.sessionPathScope},n=await xd({dataDir:e.dataDir,sessionId:e.sessionId,...t});return{async getReusableRead(e,t,r){let i=await n.findReusableRead(e,t,r);return i?{reused:!0,lineCount:i.lineCount}:{reused:!1}},async rememberRead(e){await n.recordRead(e)},async invalidateReadPath(e){await n.invalidatePath(e)},persistToolResult(e){return n.persistToolResult(e)},async recordModelUsage(e){await n.recordModelUsage({version:1,model:e.model,inputTokens:e.inputTokens,outputTokens:e.outputTokens,totalTokens:e.totalTokens,coveredTranscriptEntryCount:e.coveredTranscriptEntryCount,recordedAt:new Date().toISOString()})},manageHistory(t){return Nd({...t,contextStore:n,sessionStoreName:e.sessionStoreName,sessionPathScope:e.sessionPathScope})},getSnapshot:n.getSnapshot}}async function Yd(e){return e.contextManager?e.contextManager.manageHistory({entries:e.entries,modelInfo:e.modelInfo,contextWindowTokens:e.contextWindowTokens,llm:e.llm,historyLimit:e.historyLimit,compactionEnabled:e.compactionEnabled,pendingUserMessage:e.pendingUserMessage,topicSegmentation:e.topicSegmentation,signal:e.signal,hooks:e.hooks,hookCtx:e.hookCtx,dataDir:e.dataDir,sessionId:e.sessionId,sessionStoreName:e.sessionStoreName,channel:e.channel,isSubagent:e.isSubagent}):Nd({entries:e.entries,modelInfo:e.modelInfo,contextWindowTokens:e.contextWindowTokens,llm:e.llm,historyLimit:e.historyLimit,compactionEnabled:e.compactionEnabled,pendingUserMessage:e.pendingUserMessage,topicSegmentation:e.topicSegmentation,signal:e.signal,hooks:e.hooks,hookCtx:e.hookCtx,dataDir:e.dataDir,sessionId:e.sessionId,sessionStoreName:e.sessionStoreName,channel:e.channel,isSubagent:e.isSubagent})}const Xd=W.Object({command:W.String({description:`Shell command to execute. If the command contains file paths with spaces or other shell-special characters, you MUST escape them (e.g. wrap in single/double quotes or backslash-escape each space) so the shell parses them as a single argument.`}),workdir:W.Optional(W.String({description:"Working directory, must be inside the workspace root (relative path resolved against workspace, or an absolute path under it). If the desired directory cannot be located inside the workspace, do NOT set workdir — instead adjust the command itself (e.g. prefix with `cd /abs/path && ...` or pass absolute paths as arguments)."})),env:W.Optional(W.Record(W.String(),W.String())),timeout:W.Optional(W.Number({description:`Timeout in seconds (default: 1800)`})),yieldMs:W.Optional(W.Number({description:`Wait this many milliseconds before returning running state`})),background:W.Optional(W.Boolean({description:`Return immediately with running session`}))});function Zd(e,t,n){return Math.max(t,Math.min(n,e))}function Qd(e){return typeof e!=`number`||!Number.isFinite(e)||e<=0?1800:Math.floor(e)}function $d(e){return typeof e!=`number`||!Number.isFinite(e)||e<0?1e4:Zd(Math.floor(e),0,12e4)}function ef(e,t){if(!t?.trim())return e;let n=H.isAbsolute(t)?H.normalize(t):H.normalize(H.join(e,t));if(!n.startsWith(e+H.sep)&&n!==e)throw Error(`workdir escapes workspace: ${t}`);return n}function tf(e){let t=e.outputTail.trim();return`${t.length>0?`${t}\n\n`:``}Process is running in the background. sessionId=${e.sessionId}\nUse process(action="poll"|"log", sessionId) to continue.`}function nf(e){return af({stdout:e.stdoutTail,stderr:e.stderrTail,exitCode:e.exitCode,backgroundInfo:``}).join(`
|
|
61
61
|
`)}function rf(e){return e.replace(/^(\s*\n)+/,``).trimEnd()}function af(e){let t=rf(e.stdout),n=e.stderr.trim();if(e.exitCode!==void 0&&e.exitCode!==0){let t=`Exit code: ${e.exitCode===null?`null`:e.exitCode}`;n=n.length>0?`${n}\n${t}`:t}return[t.length>0?t:`(no output)`,n,e.backgroundInfo?.trim()||``].filter(e=>e.length>0)}function of(e){return{name:`exec`,label:`Exec`,description:`Execute shell commands. Prefer modern tools: rg (not grep), fd (not find), jq (not python/awk) for JSON. For long-running tasks set background:true and poll with process tool.`,parameters:Xd,async execute(t,n,r){if(!n.command?.trim())return{content:[{type:`text`,text:`Error: command is required.`}],details:{status:`failed`}};let i;try{i=ef(e.workspaceDir,n.workdir)}catch(e){return{content:[{type:`text`,text:`Error: ${e instanceof Error?e.message:String(e)}`}],details:{status:`failed`}}}let a=Qd(n.timeout);console.log(`Executing command: ${n.command} in ${i} with timeout ${a} seconds`,{command:n.command,cwd:i,env:n.env,baseEnv:e.baseEnv,timeoutSec:a,scopeKey:e.scopeKey});let o=e.registry.start({command:n.command,cwd:i,env:n.env,baseEnv:e.baseEnv,timeoutSec:a,scopeKey:e.scopeKey}),s=n.background===!0,c=typeof n.yieldMs==`number`&&Number.isFinite(n.yieldMs),l=o,u;try{if(!s&&r&&(u=()=>{e.registry.terminate(o.sessionId,e.scopeKey)},r.aborted?u():r.addEventListener(`abort`,u,{once:!0})),!s&&!c){let t=await e.registry.wait(o.sessionId,e.scopeKey,void 0);t&&(l=t)}else if(!s){let t=await e.registry.wait(o.sessionId,e.scopeKey,$d(n.yieldMs));t&&(l=t)}}finally{r&&u&&r.removeEventListener(`abort`,u)}if(l.status===`running`)return{content:[{type:`text`,text:tf(l)}],details:{status:`running`,sessionId:l.sessionId,command:l.command,cwd:l.cwd,pid:l.pid}};let d=e.registry.readOutput(l.sessionId,e.scopeKey),f=d?af({stdout:d.stdout,stderr:d.stderr,exitCode:l.exitCode,backgroundInfo:``}):[nf(l)],p=rf(d?.stdout??l.stdoutTail),m=await e.contextManager?.persistToolResult({toolCallId:t,toolName:`exec`,content:p.length>0?p:`(no output)`});return{content:[{type:`text`,text:[m?.content??(p.length>0?p:`(no output)`),...f.slice(1)].join(`
|
|
62
62
|
`)}],details:{status:l.status,sessionId:l.sessionId,command:l.command,cwd:l.cwd,exitCode:l.exitCode,exitSignal:l.exitSignal,toolResultRef:m?.reference}}}}}const sf=W.Object({action:W.String({description:`Process action: list | poll | log | kill`}),sessionId:W.Optional(W.String({description:`Session id for non-list actions`})),offset:W.Optional(W.Number({description:`Log line offset (0-based)`})),limit:W.Optional(W.Number({description:`Maximum lines to return`})),timeout:W.Optional(W.Number({description:`Poll wait time in milliseconds`}))});function cf(e){return typeof e!=`number`||!Number.isFinite(e)||e<0?0:Math.max(0,Math.min(12e4,Math.floor(e)))}function lf(e){return{content:[{type:`text`,text:e}],details:{status:`failed`}}}function uf(e){return{name:`process`,label:`Process`,description:`Manage background exec sessions: list, poll, log, kill.`,parameters:sf,async execute(t,n){let r=n.action?.trim().toLowerCase();if(r===`list`){let t=e.registry.list(e.scopeKey);return{content:[{type:`text`,text:t.length===0?`No running or recent sessions.`:t.map(e=>{let t=(e.endedAt??Date.now())-e.startedAt;return`${e.sessionId} ${e.status.padEnd(9)} ${t}ms :: ${e.command}`}).join(`
|
|
63
|
-
`)}],details:{status:`completed`,sessions:t}}}if(!n.sessionId?.trim())return lf(`sessionId is required for this action.`);let i=n.sessionId.trim();if(r===`poll`){let t=await e.registry.wait(i,e.scopeKey,cf(n.timeout));return t?{content:[{type:`text`,text:t.status===`running`?`Session ${i} is still running.`:`Session ${i} finished with status=${t.status}, exitCode=${t.exitCode??`null`}.`}],details:{status:t.status,sessionId:i,exitCode:t.exitCode,exitSignal:t.exitSignal,aggregated:t.status!==`running`}}:lf(`No session found for ${i}`)}if(r===`log`){let t=e.registry.readLog({sessionId:i,scopeKey:e.scopeKey,offset:n.offset,limit:n.limit});return t?{content:[{type:`text`,text:t.text.trim().length>0?t.text:`(no output)`}],details:{status:t.status,sessionId:i,totalLines:t.totalLines,totalChars:t.totalChars,truncated:t.truncated,exitCode:t.exitCode,exitSignal:t.exitSignal}}:lf(`No session found for ${i}`)}if(r===`kill`){let t=await e.registry.terminate(i,e.scopeKey);return t?{content:[{type:`text`,text:t.status===`running`?`Termination signal sent to ${i}.`:`Session ${i} terminated with status=${t.status}.`}],details:{status:t.status,sessionId:i,exitCode:t.exitCode,exitSignal:t.exitSignal}}:lf(`No session found for ${i}`)}return lf(`Unsupported action: ${n.action}`)}}}const df=process.platform===`win32`;function ff(e){return df?{file:process.env.ComSpec||process.env.COMSPEC||`cmd.exe`,args:[`/d`,`/s`,`/c
|
|
63
|
+
`)}],details:{status:`completed`,sessions:t}}}if(!n.sessionId?.trim())return lf(`sessionId is required for this action.`);let i=n.sessionId.trim();if(r===`poll`){let t=await e.registry.wait(i,e.scopeKey,cf(n.timeout));return t?{content:[{type:`text`,text:t.status===`running`?`Session ${i} is still running.`:`Session ${i} finished with status=${t.status}, exitCode=${t.exitCode??`null`}.`}],details:{status:t.status,sessionId:i,exitCode:t.exitCode,exitSignal:t.exitSignal,aggregated:t.status!==`running`}}:lf(`No session found for ${i}`)}if(r===`log`){let t=e.registry.readLog({sessionId:i,scopeKey:e.scopeKey,offset:n.offset,limit:n.limit});return t?{content:[{type:`text`,text:t.text.trim().length>0?t.text:`(no output)`}],details:{status:t.status,sessionId:i,totalLines:t.totalLines,totalChars:t.totalChars,truncated:t.truncated,exitCode:t.exitCode,exitSignal:t.exitSignal}}:lf(`No session found for ${i}`)}if(r===`kill`){let t=await e.registry.terminate(i,e.scopeKey);return t?{content:[{type:`text`,text:t.status===`running`?`Termination signal sent to ${i}.`:`Session ${i} terminated with status=${t.status}.`}],details:{status:t.status,sessionId:i,exitCode:t.exitCode,exitSignal:t.exitSignal}}:lf(`No session found for ${i}`)}return lf(`Unsupported action: ${n.action}`)}}}const df=process.platform===`win32`;function ff(e){return df?{file:process.env.ComSpec||process.env.COMSPEC||`cmd.exe`,args:[`/d`,`/s`,`/c`,`chcp 65001>nul & ${e}`]}:{file:`bash`,args:[`-lc`,e]}}function pf(e,t){if(!(e.exitCode!==null||e.signalCode!==null)){if(df&&typeof e.pid==`number`){let n=[`/pid`,String(e.pid),`/T`];t===`SIGKILL`&&n.push(`/F`);try{bt(`taskkill`,n,{windowsHide:!0,stdio:`ignore`})}catch{try{e.kill()}catch{}}return}try{e.kill(t)}catch{}}}const mf=2e5;function hf(e,t=4e3){return e?e.length>t?e.slice(-t):e:``}function gf(e,t){let n=e+t;return n.length<=mf?{text:n,truncated:!1}:{text:n.slice(-mf),truncated:!0}}function _f(e,t,n){if(n.length===0)return;let r=n.toString(`utf-8`),i=gf(e.output,r);e.output=i.text;let a=gf(e[t],r);e[t]=a.text,(i.truncated||a.truncated)&&(e.outputTruncated=!0)}function vf(e){return{sessionId:e.sessionId,scopeKey:e.scopeKey,command:e.command,cwd:e.cwd,pid:typeof e.child.pid==`number`?e.child.pid:void 0,startedAt:e.startedAt,endedAt:e.endedAt,status:e.status,exitCode:e.exitCode,exitSignal:e.exitSignal,outputTail:hf(e.output),stdoutTail:hf(e.stdout),stderrTail:hf(e.stderr),outputTruncated:e.outputTruncated}}function yf(e,t){return t?e.scopeKey===t:!0}function bf(e,t){return typeof e!=`number`||!Number.isFinite(e)||e<=0?t:Math.floor(e)}function xf(e){return e?e.split(/\r?\n/):[]}function Sf(e){let t=xf(e.record.output),n=e.offset===void 0&&e.limit===void 0,r=Math.max(0,(e.offset??0)|0),i=bf(e.limit,n?200:Math.max(1,t.length-r)),a=(n&&t.length>200?t.slice(t.length-200):t.slice(r,r+i)).join(`
|
|
64
64
|
`);return{sessionId:e.record.sessionId,status:e.record.status,text:a,totalLines:t.length,totalChars:e.record.output.length,truncated:e.record.outputTruncated,exitCode:e.record.exitCode,exitSignal:e.record.exitSignal}}function Cf(e){e.timeoutTimer&&=(clearTimeout(e.timeoutTimer),void 0),e.killTimer&&=(clearTimeout(e.killTimer),void 0),e.resolveDone()}function wf(){let e=new Map,t=new Map,n=n=>{if(e.delete(n.sessionId),t.set(n.sessionId,n),t.size<=100)return;let r=Array.from(t.values()).sort((e,t)=>(e.endedAt??2**53-1)-(t.endedAt??2**53-1));for(;r.length>100;){let e=r.shift();if(!e)break;t.delete(e.sessionId)}},r=n=>e.get(n)??t.get(n)??null,i=(e,t)=>{e.endedAt===void 0&&(t?.(),e.endedAt=Date.now(),n(e),Cf(e))};return{start(t){let{file:n,args:r}=ff(t.command),a=bt(n,r,{cwd:t.cwd,env:{...process.env,...t.baseEnv??{},...t.env??{}},stdio:[`pipe`,`pipe`,`pipe`],windowsHide:!0}),o=()=>{},s=new Promise(e=>{o=e}),c={sessionId:Ze(),scopeKey:t.scopeKey,command:t.command,cwd:t.cwd,startedAt:Date.now(),child:a,status:`running`,output:``,stdout:``,stderr:``,outputTruncated:!1,donePromise:s,resolveDone:o};e.set(c.sessionId,c),a.stdout.on(`data`,e=>_f(c,`stdout`,e)),a.stderr.on(`data`,e=>_f(c,`stderr`,e));let l=bf(t.timeoutSec,1800);return c.timeoutTimer=setTimeout(()=>{c.status===`running`&&(c.status=`timeout`,_f(c,`stderr`,Buffer.from(`\n[Timed out after ${l}s]\n`)),pf(c.child,`SIGTERM`),c.killTimer=setTimeout(()=>{(c.status===`running`||c.status===`timeout`)&&pf(c.child,`SIGKILL`)},1e3))},l*1e3),a.on(`error`,e=>{i(c,()=>{c.status===`running`&&(c.status=`failed`),_f(c,`stderr`,Buffer.from(`\n[Process error: ${e.message}]\n`))})}),a.on(`close`,(e,t)=>{i(c,()=>{c.exitCode=e,c.exitSignal=t,c.status===`running`?c.status=e===0?`completed`:`failed`:c.status===`killed`&&e===0&&(c.status=`completed`)})}),vf(c)},get(e,t){let n=r(e);return!n||!yf(n,t)?null:vf(n)},list(n){return[...e.values(),...t.values()].filter(e=>yf(e,n)).sort((e,t)=>t.startedAt-e.startedAt).map(e=>vf(e))},async wait(e,t,n){let i=r(e);if(!i||!yf(i,t))return null;if(i.status!==`running`)return vf(i);typeof n==`number`&&Number.isFinite(n)&&n>=0?await Promise.race([i.donePromise,new Promise(e=>{setTimeout(e,n)})]):await i.donePromise;let a=r(e);return!a||!yf(a,t)?null:vf(a)},readLog(e){let t=r(e.sessionId);return!t||!yf(t,e.scopeKey)?null:Sf({record:t,offset:e.offset,limit:e.limit})},readOutput(e,t){let n=r(e);return!n||!yf(n,t)?null:{sessionId:n.sessionId,status:n.status,stdout:n.stdout,stderr:n.stderr,combined:n.output,truncated:n.outputTruncated,exitCode:n.exitCode,exitSignal:n.exitSignal}},async terminate(e,t){let n=r(e);if(!n||!yf(n,t))return null;if(n.status!==`running`)return vf(n);n.status=`killed`,pf(n.child,`SIGTERM`),n.killTimer=setTimeout(()=>{(n.status===`running`||n.status===`killed`)&&pf(n.child,`SIGKILL`)},1e3),await Promise.race([n.donePromise,new Promise(e=>{setTimeout(e,1500)})]);let i=r(e);return i?vf(i):null}}}function Tf(e){return of({workspaceDir:e,registry:wf(),scopeKey:e})}const Ef=5*1024*1024,Df=2e3;async function Of(e,t){e&&await e(t).catch(()=>{})}function kf(e,t){return H.isAbsolute(e)?H.normalize(e):H.normalize(H.join(t,e))}const Af=W.Object({path:W.String({description:`File path (relative to workspace or absolute)`}),offset:W.Optional(W.Number({description:`Line offset (1-based, default: 1)`})),limit:W.Optional(W.Number({description:`Maximum lines to read (default: 2000)`}))});function jf(e,t){return{name:`read_file`,label:`Read File`,description:`Read the contents of a file`,parameters:Af,async execute(n,r){let i;try{i=kf(r.path,e)}catch(e){return{content:[{type:`text`,text:`Error: ${e instanceof Error?e.message:String(e)}`}],details:{content:``,lines:0,truncated:!1}}}let a=await t?.getReusableRead(i,r.offset,r.limit);if(a?.reused)return{content:[{type:`text`,text:`[file unchanged] ${r.path}`}],details:{content:``,lines:a.lineCount??0,truncated:!1,deduplicated:!0}};let o;try{o=await V.readFile(i)}catch(e){return{content:[{type:`text`,text:`Error: ${e.code===`ENOENT`?`File not found: ${r.path}`:String(e)}`}],details:{content:``,lines:0,truncated:!1}}}let s=o.subarray(0,Math.min(o.length,4096));if(await xt(s,s.length))return{content:[{type:`text`,text:`Error: read_file only supports text files. ${r.path} appears to be binary; use another tool or install an appropriate skill to handle it.`}],details:{content:``,lines:0,truncated:!1}};if(o.length>Ef){let e=o.slice(0,Ef).toString(`utf-8`);return{content:[{type:`text`,text:`${e}\n[...file truncated at ${Ef} bytes]`}],details:{content:e,lines:0,truncated:!0}}}let c=o.toString(`utf-8`).split(`
|
|
65
65
|
`),l=Math.max(1,r.offset??1),u=Math.min(Df,r.limit??Df),d=c.slice(l-1,l-1+u),f=d.length<c.length-(l-1),p=d.map((e,t)=>`${(l+t).toString().padStart(4)} ${e}`).join(`
|
|
66
66
|
`),m=f?`\n[...${c.length-(l-1+d.length)} more lines]`:``;return await t?.rememberRead({path:i,content:d.join(`
|