@myagentroam/agent 0.9.62 → 0.9.64
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/LICENSE +202 -0
- package/NOTICE +4 -0
- package/dist/cli/codex-auth-file.js +268 -3
- package/dist/cli/main.js +427 -2
- package/dist/error.js +66 -2
- package/dist/host/contracts.js +20 -2
- package/dist/host/local-agent-host.js +146 -2
- package/dist/host/local-process-executor.js +39 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +12 -2
- package/dist/model/anthropic-messages.js +474 -2
- package/dist/model/anthropic-thinking.js +33 -2
- package/dist/model/catalog-file.js +88 -2
- package/dist/model/configuration.js +137 -2
- package/dist/model/contracts.d.ts +2 -0
- package/dist/model/contracts.js +1 -2
- package/dist/model/http.js +529 -2
- package/dist/model/openai-responses.d.ts +2 -0
- package/dist/model/openai-responses.js +1602 -2
- package/dist/model/runtime-credential.js +35 -2
- package/dist/model/sse.js +199 -2
- package/dist/prompts/compact.js +25 -2
- package/dist/prompts/core.js +37 -2
- package/dist/prompts/execution-budget.js +10 -2
- package/dist/prompts/index.d.ts +3 -2
- package/dist/prompts/index.js +47 -2
- package/dist/prompts/modes.js +25 -2
- package/dist/prompts/output.js +1 -2
- package/dist/prompts/resources.d.ts +1 -1
- package/dist/prompts/resources.js +31 -2
- package/dist/prompts/subagent.d.ts +6 -0
- package/dist/prompts/subagent.js +29 -2
- package/dist/prompts/title.js +9 -2
- package/dist/prompts/workflow.js +32 -2
- package/dist/runtime/async-queue.js +62 -2
- package/dist/runtime/builtin-skills.js +19 -2
- package/dist/runtime/byted-ark-imagegen-skill.js +18 -2
- package/dist/runtime/codex-imagegen-skill.js +35 -2
- package/dist/runtime/compact.js +225 -2
- package/dist/runtime/context-gc-runtime.d.ts +35 -0
- package/dist/runtime/context-gc-runtime.js +163 -0
- package/dist/runtime/context-gc-tokens.d.ts +24 -0
- package/dist/runtime/context-gc-tokens.js +83 -0
- package/dist/runtime/context-gc.d.ts +66 -0
- package/dist/runtime/context-gc.js +909 -0
- package/dist/runtime/context-projection.d.ts +23 -0
- package/dist/runtime/context-projection.js +203 -0
- package/dist/runtime/environment-context.js +41 -2
- package/dist/runtime/execution-policy.js +13 -2
- package/dist/runtime/instructions.js +298 -2
- package/dist/runtime/normalize.js +40 -2
- package/dist/runtime/plan-output.js +95 -2
- package/dist/runtime/rollout-budget.d.ts +2 -0
- package/dist/runtime/rollout-budget.js +92 -2
- package/dist/runtime/token-budget.d.ts +2 -0
- package/dist/runtime/token-budget.js +44 -2
- package/dist/sdk/agent.js +1804 -2
- package/dist/sdk/types.d.ts +15 -5
- package/dist/sdk/types.js +1 -2
- package/dist/session/catalog.d.ts +5 -4
- package/dist/session/catalog.js +133 -2
- package/dist/session/context-gc-checkpoint.d.ts +148 -0
- package/dist/session/context-gc-checkpoint.js +665 -0
- package/dist/session/context-gc-replacements.d.ts +52 -0
- package/dist/session/context-gc-replacements.js +226 -0
- package/dist/session/context-gc-subagent.d.ts +43 -0
- package/dist/session/context-gc-subagent.js +267 -0
- package/dist/session/jsonl-store.d.ts +42 -4
- package/dist/session/jsonl-store.js +1657 -2
- package/dist/subagent/scheduler.d.ts +35 -2
- package/dist/subagent/scheduler.js +249 -2
- package/dist/subagent/session-controller.d.ts +94 -0
- package/dist/subagent/session-controller.js +675 -0
- package/dist/tools/agent-cancel.js +28 -2
- package/dist/tools/{task.d.ts → agent-message.d.ts} +2 -2
- package/dist/tools/agent-message.js +51 -0
- package/dist/tools/agent-start.js +84 -2
- package/dist/tools/agent-wait.js +53 -2
- package/dist/tools/apply-patch.js +478 -2
- package/dist/tools/code-mode.js +370 -2
- package/dist/tools/codex-image-gen.js +312 -2
- package/dist/tools/exec.js +455 -2
- package/dist/tools/execution-limits.d.ts +1 -0
- package/dist/tools/execution-limits.js +44 -2
- package/dist/tools/local-registry.js +233 -2
- package/dist/tools/local-workspace-tools.js +28 -2
- package/dist/tools/question.js +124 -2
- package/dist/tools/read-context.d.ts +16 -0
- package/dist/tools/read-context.js +85 -0
- package/dist/tools/read.d.ts +13 -0
- package/dist/tools/read.js +294 -2
- package/dist/tools/registry.js +76 -2
- package/dist/tools/runtime-context.d.ts +9 -2
- package/dist/tools/runtime-context.js +1 -2
- package/dist/tools/runtime.js +21 -2
- package/dist/tools/scheduler.js +41 -2
- package/dist/tools/shared/path-resolver.js +133 -2
- package/dist/tools/skill.js +37 -2
- package/dist/tools/todo-read.js +10 -2
- package/dist/tools/todo-write.js +65 -2
- package/dist/tools/todo.js +67 -2
- package/dist/tools/view-image.js +81 -2
- package/dist/tools/web-fetch.js +11 -2
- package/dist/tools/web-search.js +14 -2
- package/package.json +9 -7
- package/README.md +0 -3
- package/dist/runtime/prompt.d.ts +0 -9
- package/dist/runtime/prompt.js +0 -2
- package/dist/tools/shared/secret-redaction.d.ts +0 -4
- package/dist/tools/shared/secret-redaction.js +0 -2
- package/dist/tools/task-cancel.d.ts +0 -7
- package/dist/tools/task-cancel.js +0 -2
- package/dist/tools/task-output.d.ts +0 -7
- package/dist/tools/task-output.js +0 -2
- package/dist/tools/task-tools.d.ts +0 -36
- package/dist/tools/task-tools.js +0 -2
- package/dist/tools/task.js +0 -2
- package/dist/tools/todo-tools.d.ts +0 -25
- package/dist/tools/todo-tools.js +0 -2
package/dist/tools/read.js
CHANGED
|
@@ -1,2 +1,294 @@
|
|
|
1
|
-
|
|
2
|
-
const _0x416975=_0xf27c;(function(_0x4cd655,_0x27b7fd){const _0x304368=_0xf27c,_0x201e24=_0x4cd655();while(!![]){try{const _0x36191f=parseInt(_0x304368(0x1cf))/(-0x56*-0xd+-0x2*-0xe03+-0x2063)*(parseInt(_0x304368(0x1cd))/(-0x19ae+0x1153*0x1+-0x85d*-0x1))+parseInt(_0x304368(0x1fa))/(-0xcb5+-0x1b0d+-0x1*-0x27c5)+parseInt(_0x304368(0x214))/(-0x81*0x3d+-0x101*0x1d+0x3bde)*(parseInt(_0x304368(0x1dd))/(0x4a2*0x4+-0x810+-0x19*0x6b))+-parseInt(_0x304368(0x1ed))/(0x21d4+0xee*0xd+-0x2de4)*(-parseInt(_0x304368(0x1cb))/(0xb8f*-0x3+0x1*0x378+0x1f3c))+-parseInt(_0x304368(0x211))/(-0x58*-0x3e+-0x1*-0x101b+-0x2563)+parseInt(_0x304368(0x1c8))/(0x6a4+-0x6b5+0x1a)+-parseInt(_0x304368(0x1f9))/(-0x2163+-0xf2e+0x17*0x21d);if(_0x36191f===_0x27b7fd)break;else _0x201e24['push'](_0x201e24['shift']());}catch(_0x53d969){_0x201e24['push'](_0x201e24['shift']());}}}(_0x30f6,-0x20bb0+-0x32255+-0x6e269*-0x1));import{createReadStream}from'node:fs';import{lstat,open}from'node:fs/promises';function _0xf27c(_0xf3cabf,_0x5297b3){_0xf3cabf=_0xf3cabf-(-0x197*0xd+0x9*0x1df+0x593);const _0x316429=_0x30f6();let _0x1aa71a=_0x316429[_0xf3cabf];if(_0xf27c['CbLSfy']===undefined){var _0x57c8bf=function(_0x142d3e){const _0x4d1aab='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0xfd6179='',_0x45939e='';for(let _0x492023=-0xf96+-0x4*-0x5b9+-0x74e,_0x5213e0,_0x1188c6,_0x554f0f=-0x1c3*-0x8+0x1b*0x29+0x29*-0x73;_0x1188c6=_0x142d3e['charAt'](_0x554f0f++);~_0x1188c6&&(_0x5213e0=_0x492023%(-0xc9d*-0x3+-0x374+0x3*-0xb75)?_0x5213e0*(-0xb5a+0xaae+0xec)+_0x1188c6:_0x1188c6,_0x492023++%(0x18ba+-0xe37+-0xa7f))?_0xfd6179+=String['fromCharCode'](-0xc19+0x2421*-0x1+0x3139&_0x5213e0>>(-(0x6f0+0x2281+-0x1*0x296f)*_0x492023&-0x1*0xb62+0x331+0x837)):-0x1fd*-0x5+-0xf*-0xb5+-0x148c){_0x1188c6=_0x4d1aab['indexOf'](_0x1188c6);}for(let _0x14811c=-0x3*-0x311+-0x1426+-0xaf3*-0x1,_0x5f3f34=_0xfd6179['length'];_0x14811c<_0x5f3f34;_0x14811c++){_0x45939e+='%'+('00'+_0xfd6179['charCodeAt'](_0x14811c)['toString'](-0xcc3+0x11*-0x1b2+0x5f3*0x7))['slice'](-(-0x23ab+-0x6*0xfa+0x1*0x2989));}return decodeURIComponent(_0x45939e);};_0xf27c['RNdszj']=_0x57c8bf,_0xf27c['xETAby']={},_0xf27c['CbLSfy']=!![];}const _0x1dd079=_0x316429[-0x79b+-0x1b3d+0x22d8];_0xf27c['oxLAiO']!==_0x1dd079&&(_0xf27c['xETAby']={},_0xf27c['oxLAiO']=_0x1dd079);const _0x24f5c7=_0xf27c['xETAby'][_0xf3cabf];return _0x24f5c7===undefined?(_0x1aa71a=_0xf27c['RNdszj'](_0x1aa71a),_0xf27c['xETAby'][_0xf3cabf]=_0x1aa71a):_0x1aa71a=_0x24f5c7,_0x1aa71a;}import{TextDecoder}from'node:util';import{MarAgentError}from'../error.js';import{TOOL_EXECUTION_LIMITS}from'./execution-limits.js';export const readToolDefinition={'name':_0x416975(0x207),'parallelSafety':_0x416975(0x20d),'outputSchema':{'type':_0x416975(0x1d2),'required':[_0x416975(0x1d0),_0x416975(0x201),_0x416975(0x1d5)],'properties':{'content':{'type':_0x416975(0x20c)},'truncated':{'type':_0x416975(0x1c7)},'data':{'type':_0x416975(0x1d2),'required':[_0x416975(0x202),_0x416975(0x1e3),_0x416975(0x1d5)],'properties':{'mode':{'enum':[_0x416975(0x1f3)]},'truncated':{'type':_0x416975(0x1c7)},'results':{'type':_0x416975(0x1ca),'items':{'type':_0x416975(0x1d2),'required':[_0x416975(0x1e9)],'properties':{'path':{'type':_0x416975(0x20c)},'content':{'type':_0x416975(0x20c)},'text':{'type':_0x416975(0x20c)},'startLine':{'type':_0x416975(0x21a)},'endLine':{'type':_0x416975(0x21a)},'nextOffset':{'type':_0x416975(0x21a)},'eof':{'type':_0x416975(0x1c7)},'truncated':{'type':_0x416975(0x1c7)},'encoding':{'enum':[_0x416975(0x1f2),_0x416975(0x1ec),_0x416975(0x1e1)]},'newline':{'enum':['lf',_0x416975(0x217)]},'error':{'type':_0x416975(0x1d2),'required':[_0x416975(0x206),_0x416975(0x1ea)],'properties':{'code':{'type':_0x416975(0x20c)},'message':{'type':_0x416975(0x20c)}}}}}}}}}},'description':_0x416975(0x1dc)+TOOL_EXECUTION_LIMITS[_0x416975(0x204)]+_0x416975(0x1ff)+TOOL_EXECUTION_LIMITS[_0x416975(0x1ee)]+_0x416975(0x1c4)+TOOL_EXECUTION_LIMITS[_0x416975(0x1f4)]+_0x416975(0x1f0)+TOOL_EXECUTION_LIMITS[_0x416975(0x1da)]+_0x416975(0x1c1),'inputSchema':{'type':_0x416975(0x1d2),'properties':{'reads':{'type':_0x416975(0x1ca),'minItems':0x1,'maxItems':TOOL_EXECUTION_LIMITS[_0x416975(0x204)],'description':_0x416975(0x20b),'items':{'type':_0x416975(0x1d2),'properties':{'path':{'type':_0x416975(0x20c),'description':_0x416975(0x1fe)},'offset':{'type':_0x416975(0x1db),'minimum':0x1,'description':_0x416975(0x1e4)},'limit':{'type':_0x416975(0x1db),'minimum':0x1,'maximum':TOOL_EXECUTION_LIMITS[_0x416975(0x1ee)],'description':_0x416975(0x1f8)+TOOL_EXECUTION_LIMITS[_0x416975(0x1e6)]+'.'}},'required':[_0x416975(0x1e9)],'additionalProperties':![]}}},'required':[_0x416975(0x216)],'additionalProperties':![]}};export class ReadTool{[_0x416975(0x1e0)];constructor(_0xa36962){const _0xb4a7dc=_0x416975;this[_0xb4a7dc(0x1e0)]=_0xa36962;}async[_0x416975(0x20a)](_0x35b685,_0x1b47b1){const _0x559c58=_0x416975;return this.#readBatch(parseReadInput(_0x35b685)[_0x559c58(0x216)],_0x1b47b1);}async #readBatch(_0x24dbb3,_0x25327a){const _0x3caabc=_0x416975,_0x176eb1=Math[_0x3caabc(0x1fc)](TOOL_EXECUTION_LIMITS[_0x3caabc(0x1f4)],Math[_0x3caabc(0x205)](TOOL_EXECUTION_LIMITS[_0x3caabc(0x1da)]/_0x24dbb3[_0x3caabc(0x209)])),_0x5a38b5=new Map();for(const _0x361388 of _0x24dbb3)_0x5a38b5[_0x3caabc(0x1e5)](readKey(_0x361388),_0x361388);const _0x1e8b30=[..._0x5a38b5[_0x3caabc(0x1c6)]()],_0x2e9971=new Map();let _0xa285d=0x6a2+0x1*-0x716+-0x3a*-0x2;const _0x39bbca=async()=>{const _0x3cd71d=_0x3caabc;for(;;){const _0x8269ee=_0x1e8b30[_0xa285d++];if(!_0x8269ee)return;const [_0x24e39a,_0x387b40]=_0x8269ee;try{_0x2e9971[_0x3cd71d(0x1e5)](_0x24e39a,await this.#readOne(_0x387b40,_0x176eb1,_0x25327a));}catch(_0x1d9847){if(_0x25327a?.[_0x3cd71d(0x21c)])throw _0x1d9847;_0x2e9971[_0x3cd71d(0x1e5)](_0x24e39a,readError(_0x387b40[_0x3cd71d(0x1e9)],_0x1d9847));}}};await Promise[_0x3caabc(0x200)](Array[_0x3caabc(0x1e7)]({'length':Math[_0x3caabc(0x1fc)](TOOL_EXECUTION_LIMITS[_0x3caabc(0x210)],_0x1e8b30[_0x3caabc(0x209)])},_0x39bbca));const _0x21bf02=_0x24dbb3[_0x3caabc(0x1e2)](_0x280110=>_0x2e9971[_0x3caabc(0x1d8)](readKey(_0x280110)));return{'mode':_0x3caabc(0x1f3),'results':_0x21bf02,'truncated':_0x21bf02[_0x3caabc(0x1bf)](_0x36dfc9=>_0x3caabc(0x1d5)in _0x36dfc9&&_0x36dfc9[_0x3caabc(0x1d5)])};}async #readOne(_0x5c98fb,_0x44768b,_0x2b36d0){const _0x1f23e4=_0x416975;_0x2b36d0?.[_0x1f23e4(0x1f1)]();const _0x3858d4=await this[_0x1f23e4(0x1e0)][_0x1f23e4(0x1ef)](_0x5c98fb[_0x1f23e4(0x1e9)]),_0x149ac1=await lstat(_0x3858d4);if(!_0x149ac1[_0x1f23e4(0x208)]())throw new MarAgentError(_0x1f23e4(0x1fb),_0x1f23e4(0x1d6));const _0x55fabf=Math[_0x1f23e4(0x1fd)](0x25*0xdf+-0x1*-0xf5c+-0x17cb*0x2,_0x5c98fb[_0x1f23e4(0x1d7)]??-0x5*0x54a+-0x1*-0x22b2+-0x83f),_0x5372bb=Math[_0x1f23e4(0x1fc)](TOOL_EXECUTION_LIMITS[_0x1f23e4(0x1ee)],Math[_0x1f23e4(0x1fd)](-0x4f9+0x18ba+-0x13c0,_0x5c98fb[_0x1f23e4(0x1df)]??TOOL_EXECUTION_LIMITS[_0x1f23e4(0x1e6)])),_0x357493=await detectEncoding(_0x3858d4),_0x232041=[],_0xc36f0=[];let _0x3a098b=-0x8fe+-0xc19+0x1517*0x1,_0x5a5a88=-0x1*0x215b+0x6f0+-0x1*-0x1a6b,_0x5b85d1=![],_0x546505='lf',_0x2cb98c='',_0x2c9887=![];const _0x555973=new TextDecoder(_0x357493[_0x1f23e4(0x1f6)],{'fatal':!![],'ignoreBOM':!![]}),_0x44e67f=createReadStream(_0x3858d4,{'start':_0x357493[_0x1f23e4(0x1d9)],'signal':_0x2b36d0}),_0x4e7b10=(_0x4132c5,_0x5219c1)=>{const _0x439ec1=_0x1f23e4,_0x35bdf3=_0x4132c5+(_0x5219c1?'\x0a':'');_0x5a5a88++;_0x4132c5[_0x439ec1(0x1f5)]('\x0d')&&(_0x546505=_0x439ec1(0x217),_0x4132c5=_0x4132c5[_0x439ec1(0x1d1)](-0x1*0xb62+0x331+0x831,-(-0x1fd*-0x5+-0xf*-0xb5+-0x148b)));if(_0x5a5a88<_0x55fabf)return!![];if(_0x232041[_0x439ec1(0x209)]>=_0x5372bb)return _0x5b85d1=!![],![];const _0x15a8a8=_0x5a5a88+'\x09'+_0x4132c5,_0x4ce7db=Buffer[_0x439ec1(0x1c2)](_0x15a8a8),_0x51acd3=_0x232041[_0x439ec1(0x209)]===-0x3*-0x311+-0x1426+-0xaf3*-0x1?-0xcc3+0x11*-0x1b2+0x851*0x5:-0x23ab+-0x6*0xfa+0x2*0x14c4;if(_0x3a098b+_0x51acd3+_0x4ce7db>_0x44768b){if(_0x232041[_0x439ec1(0x209)]===-0x79b+-0x1b3d+0x22d8)throw new MarAgentError(_0x439ec1(0x215),_0x439ec1(0x1cc));return _0x5b85d1=!![],![];}return _0x232041[_0x439ec1(0x1d3)](_0x15a8a8),_0xc36f0[_0x439ec1(0x1d3)](_0x35bdf3),_0x3a098b+=_0x51acd3+_0x4ce7db,!![];},_0x418e05=_0x36cb0d=>{const _0x43c167=_0x1f23e4;if(_0x36cb0d[_0x43c167(0x1c5)]('\x00'))throw new MarAgentError(_0x43c167(0x219),_0x43c167(0x1f7));_0x2cb98c+=_0x36cb0d;for(;;){const _0x479154=_0x2cb98c[_0x43c167(0x1eb)]('\x0a');if(_0x479154<-0x1a97+0x1c99+-0x2*0x101)break;const _0x354dcc=_0x2cb98c[_0x43c167(0x1d1)](-0x1297*0x2+-0x168a+0x3bb8,_0x479154);_0x2cb98c=_0x2cb98c[_0x43c167(0x1d1)](_0x479154+(-0x1c2d*-0x1+0x19*-0xfd+-0x377));if(!_0x4e7b10(_0x354dcc,!![]))return![];}if(_0x5a5a88+(-0xb*0x372+-0x1*-0x11c3+0x1424)<_0x55fabf&&_0x2cb98c[_0x43c167(0x209)]>-0x14e+0x2b*0x97+-0x180e)_0x2cb98c=_0x2cb98c[_0x43c167(0x1f5)]('\x0d')?'\x0d':'';else{if(Buffer[_0x43c167(0x1c2)](_0x2cb98c)>_0x44768b)throw new MarAgentError(_0x43c167(0x215),_0x43c167(0x1cc));}return!![];};try{for await(const _0x142110 of _0x44e67f){if(!_0x418e05(_0x555973[_0x1f23e4(0x203)](_0x142110,{'stream':!![]}))){_0x2c9887=!![];break;}}if(!_0x2c9887){_0x418e05(_0x555973[_0x1f23e4(0x203)]());if(_0x2cb98c[_0x1f23e4(0x209)]>-0x1dd0+0x6f7*0x1+0x1*0x16d9)_0x4e7b10(_0x2cb98c,![]);}}catch(_0x72801f){if(_0x72801f instanceof TypeError)throw new MarAgentError(_0x1f23e4(0x219),_0x1f23e4(0x20e),{'cause':_0x72801f});throw _0x72801f;}finally{_0x44e67f[_0x1f23e4(0x21b)]();}const _0xc06832=_0x5b85d1?_0x55fabf+_0x232041[_0x1f23e4(0x209)]:undefined;return{'path':_0x5c98fb[_0x1f23e4(0x1e9)],'content':_0x232041[_0x1f23e4(0x1d4)]('\x0a'),'text':_0xc36f0[_0x1f23e4(0x1d4)](''),'encoding':_0x357493[_0x1f23e4(0x1ce)],'newline':_0x546505,'startLine':_0x55fabf,..._0x232041[_0x1f23e4(0x209)]?{'endLine':_0x55fabf+_0x232041[_0x1f23e4(0x209)]-(-0x10d*0x1d+0x1469+-0x35b*-0x3)}:{},'eof':!_0x5b85d1,'truncated':_0x5b85d1,..._0xc06832===undefined?{}:{'nextOffset':_0xc06832}};}}async function detectEncoding(_0x2ceb2b){const _0xe1b63d=_0x416975,_0x555924=await open(_0x2ceb2b,'r');try{const _0x38ccf4=Buffer[_0xe1b63d(0x212)](0x7*-0xe5+0x99a*0x1+0x1aa*-0x2),{bytesRead:_0x1b7b64}=await _0x555924[_0xe1b63d(0x207)](_0x38ccf4,0x15*-0x169+0xee*0x5+0x18f7,_0x38ccf4[_0xe1b63d(0x209)],-0x5*-0x535+-0x216e*0x1+0x3*0x277);if(_0x1b7b64>=0x153b+-0x1*-0x1f0f+-0x3447&&_0x38ccf4[-0x183*-0x9+0xa7b+0xc0b*-0x2]===-0xc3+0x2*-0x74+0x14d*0x2&&_0x38ccf4[-0xada+0x1a47+-0xf6c]===-0x1*-0x53+-0x1093*-0x2+-0x20be&&_0x38ccf4[0x92*-0x33+0x120c+0xb0c]===0x846+-0x17f3+0x1*0x106c)return{'encoding':_0xe1b63d(0x1f2),'decoder':_0xe1b63d(0x1f2),'bomBytes':0x3};if(_0x1b7b64>=-0x711+0x18bd+-0x11aa&&_0x38ccf4[-0x24fe+-0x1*0x23bf+-0x183f*-0x3]===0xdaa+-0x18bb+0xc10&&_0x38ccf4[0xf10+-0x1b69*0x1+0x1f*0x66]===0x8ee+0x1fe+-0x1f*0x52)return{'encoding':_0xe1b63d(0x1ec),'decoder':_0xe1b63d(0x1ec),'bomBytes':0x2};if(_0x1b7b64>=0xfe6+0x38*-0x3e+-0x254&&_0x38ccf4[-0xaf6+-0x99a*0x3+0x27c4]===0x747+-0x4eb+-0xaf*0x2&&_0x38ccf4[0x1864+-0x1395+-0x2*0x267]===-0xb*0x139+-0x584+-0x3fe*-0x5)return{'encoding':_0xe1b63d(0x1e1),'decoder':_0xe1b63d(0x1e1),'bomBytes':0x2};return{'encoding':_0xe1b63d(0x1f2),'decoder':_0xe1b63d(0x1f2),'bomBytes':0x0};}finally{await _0x555924[_0xe1b63d(0x20f)]();}}function _0x30f6(){const _0x1f1d86=['ntHTB0L0z2C','y29UDgvUDa','C2XPy2u','B2jQzwn0','ChvZAa','AM9PBG','Dhj1BMnHDgvK','ugf0AcbPCYbUB3qGysbYzwD1BgfYigzPBguU','B2zMC2v0','z2v0','yM9TqNL0zxm','CMvHze1HEejHDgnOqNL0zxm','Aw50zwDLCG','uMvHzcbVBMuGB3iGBw9YzsbRBM93BIb0zxH0igzPBgvZl3jHBMDLCY4Gu3rYAwn0ifvurI04ihDPDgGGB3b0Aw9UywWGqK9nigLZihrOzsbKzwzHDwX0oYbct00TzgvJBgfYzwqGvvrglte2teuVvvrglte2qKuGAxmGC3vWCg9YDgvKlIbjBNzHBgLKihrLEhqGCMv0DxjUCYbHBIbPDgvTigvYCM9YigLUC3rLywqGB2yGCMvWBgfJzw1LBNqGy2HHCMfJDgvYCY4GqwX3yxLZihbHC3mGCMvHzhm7ihvZzsbVBMuGAxrLBsbMB3iGysbZAw5NBguGzMLSzsbHBMqGDxaGDg8G','mtiWnvv5wxLbtq','uMvHzcbPBNb1DcbPCYbPBNzHBgLKlG','BgLTAxq','Cgf0Ahm','DxrMlte2yMu','BwfW','CMvZDwX0CW','rMLYC3qGms1IyxnLzcbSAw5LoYbKzwzHDwX0CYb0BYaXlG','C2v0','CMvHzerLzMf1BhrmAw5LCW','zNjVBq','AxnbCNjHEq','Cgf0Aa','BwvZC2fNzq','Aw5KzxHpzG','DxrMlte2Bgu','mtm0otrZBgPfuxq','CMvHze1HEeXPBMvZ','CMvZB2X2zq','igj5DgvZoYb0AguGy2fSBcbZAgfYzxmGysa','DgHYB3DjzKfIB3j0zwq','DxrMltG','yMf0y2G','CMvHze1HEej5DgvZ','zw5KC1DPDgG','zgvJB2rLCG','vgv4DcbMAwXLCYbJyw5UB3qGy29UDgfPBIbovuWGy2HHCMfJDgvYCZSGvvrglte2ihjLCxvPCMvZigeGqK9nlG','twf4Aw11BsbSAw5LCZSGzgvMyxvSDhmGDg8G','mZuXota3mejezhHfBq','mteXotG0BxDntu5X','tufsx0fhru5ux1rpt0XFsu5qvvrFsu5wquXjra','BwLU','Bwf4','uMvSyxrPDMuGD29YA3nWywnLihbHDgGGB3iGywjZB2X1DguGzMLSzsbWyxrOlG','igL0zw1ZigzVCIbHigjHDgnOlIbszxn1BhrZihjLDgfPBIbPBNb1DcbVCMrLCIWGDxnLideTyMfZzwqGBgLUzsbUDw1IzxjZlcbHBMqGAw5JBhvKzsa8CMvHzf9TzxrHzgf0yt4GD2L0AcbWyxrOlcbLBMnVzgLUzYWGBMv3BgLUzsWGzxHHy3qGCMfUz2uSigvVzIWGDhj1BMnHDgLVBIWGyw5Kig5LEhrpzMzZzxqUieL0zw1ZigzHAwWGAw5KzxbLBMrLBNrSEsbHBMqGCNvUihDPDgGGyM91BMrLzcbJB25JDxjYzw5JEs4GrwfJAcbPDgvTihjLDhvYBNmGyxqGBw9ZDca','ywXS','zgf0yq','Bw9Kzq','zgvJB2rL','CMvHze1HEejHDgnOsxrLBxm','zMXVB3i','y29Kzq','CMvHza','AxngAwXL','BgvUz3rO','zxHLy3v0zq','s25VD24GzMLSzxmGB3iGCMfUz2vZihrVihjLywqGAw4GB25Lig9YzgvYzwqGyMf0y2GU','C3rYAw5N','C2fMzq','rMLSzsbJB250ywLUCYbPBNzHBgLKihrLEhqGzM9YigL0CYbKzwnSyxjLzcbLBMnVzgLUzY4','y2XVC2u','CMvHzejHDgnOq29Uy3vYCMvUy3K','ntK0mdblDLvTBxK','ywXSB2m','AxnjBNrLz2vY','mJa1nNngzgjVqq','tufsx0fhru5ux1rpt0XFt1vuufvux0XjtuLu','CMvHzhm','y3jSzG','vw5HyMXLihrVihjLywqGzMLSzs4','tufsx0fhru5ux0zjtevFru5dt0rjtKDFsu5wquXjra','BNvTyMvY','zgvZDhjVEq','ywjVCNrLza','C29Tzq','A2v5CW','lwj5DguGyNvKz2v0lIbtDhj1y3r1CMvKigrHDgeUCMvZDwX0CYbPDgvTCYbWCM92AwrLihrLEhqGyxmGzgvJB2rLzcbZB3vYy2uGzM9YihrOzsbYzxr1CM5LzcbYyw5NzsWGChjLC2vYDMLUzYbSAw5LigvUzgLUz3mGyw5Kigv4y2X1zgLUzYbct007ignVBNrLBNqGAxmGBNvTyMvYzwqGzgLZCgXHEsb0zxH0lIbmyxjNzsbMAwXLCYbZDxbWB3j0igjVDw5KzwqGCMfUz2uGCMvHzhmUifjLBgf0AxzLihbHDgHZihvZzsb0AguGD29YA3nWywnLoYbHyNnVBhv0zsbWyxrOCYbHCMuGywXSB3DLzc4GuhjLzMvYigv4zwmGD2L0AcbYzYbMB3iGC2vHCMnOigfUzcbYzwfKigzVCIbRBM93BIbMAwXLCY4','yNL0zuXLBMD0Aa','C3rYAw5NAwz5','igXPBMvZlW','Aw5JBhvKzxm','zw50CMLLCW','yM9VBgvHBG','mty1mtyWohznANrHsW','tufsx0fhru5ux1rpt0XFrKfjteve','yxjYyxK','mtGYswjSCwDN','qsbZAw5NBguGBgLUzsbLEgnLzwrZihrOzsbYzwfKihjLC3vSDcbSAw1PDc4','mJm0mfb5s25dEa','zw5JB2rPBMC'];_0x30f6=function(){return _0x1f1d86;};return _0x30f6();}function parseReadInput(_0x284989){const _0x152599=_0x416975;if(!_0x284989||typeof _0x284989!==_0x152599(0x1d2))return invalidReadInput();const _0x21d84c=_0x284989;if(Object[_0x152599(0x1c0)](_0x21d84c)[_0x152599(0x1bf)](_0x11fab2=>_0x11fab2!==_0x152599(0x216)))return invalidReadInput();if(!Array[_0x152599(0x1e8)](_0x21d84c[_0x152599(0x216)])||_0x21d84c[_0x152599(0x216)][_0x152599(0x209)]===0x1b21+-0x1*0x10d3+-0xa4e||_0x21d84c[_0x152599(0x216)][_0x152599(0x209)]>TOOL_EXECUTION_LIMITS[_0x152599(0x204)])return invalidReadInput();return{'reads':_0x21d84c[_0x152599(0x216)][_0x152599(0x1e2)](parseReadRequest)};}function parseReadRequest(_0x2e9c32){const _0x5b199f=_0x416975;if(!_0x2e9c32||typeof _0x2e9c32!==_0x5b199f(0x1d2))return invalidReadInput();const _0x310e65=_0x2e9c32;if(Object[_0x5b199f(0x1c0)](_0x310e65)[_0x5b199f(0x1bf)](_0x3ff3c8=>![_0x5b199f(0x1e9),_0x5b199f(0x1d7),_0x5b199f(0x1df)][_0x5b199f(0x1c5)](_0x3ff3c8)))return invalidReadInput();if(typeof _0x310e65[_0x5b199f(0x1e9)]!==_0x5b199f(0x20c)||_0x310e65[_0x5b199f(0x1e9)]==='')return invalidReadInput();if(_0x310e65[_0x5b199f(0x1d7)]!==undefined&&_0x310e65[_0x5b199f(0x1d7)]!==null&&(!Number[_0x5b199f(0x213)](_0x310e65[_0x5b199f(0x1d7)])||_0x310e65[_0x5b199f(0x1d7)]<-0xbc4+0x1*0x192f+0xd6a*-0x1))return invalidReadInput();if(_0x310e65[_0x5b199f(0x1df)]!==undefined&&_0x310e65[_0x5b199f(0x1df)]!==null&&(!Number[_0x5b199f(0x213)](_0x310e65[_0x5b199f(0x1df)])||_0x310e65[_0x5b199f(0x1df)]<-0x1472+0x2116+-0x5*0x287))return invalidReadInput();return{'path':_0x310e65[_0x5b199f(0x1e9)],...typeof _0x310e65[_0x5b199f(0x1d7)]===_0x5b199f(0x21a)?{'offset':_0x310e65[_0x5b199f(0x1d7)]}:{},...typeof _0x310e65[_0x5b199f(0x1df)]===_0x5b199f(0x21a)?{'limit':Math[_0x5b199f(0x1fc)](_0x310e65[_0x5b199f(0x1df)],TOOL_EXECUTION_LIMITS[_0x5b199f(0x1ee)])}:{}};}function readKey(_0x5cf7c5){const _0x49a881=_0x416975;return JSON[_0x49a881(0x1c3)]([_0x5cf7c5[_0x49a881(0x1e9)],_0x5cf7c5[_0x49a881(0x1d7)]??-0x194b+0xbe9*-0x1+0x2535,_0x5cf7c5[_0x49a881(0x1df)]??TOOL_EXECUTION_LIMITS[_0x49a881(0x1e6)]]);}function readError(_0x1a0b36,_0x171755){const _0x3ba136=_0x416975;if(_0x171755 instanceof MarAgentError)return{'path':_0x1a0b36,'error':{'code':_0x171755[_0x3ba136(0x206)],'message':_0x171755[_0x3ba136(0x1ea)]}};const _0x2001b3=typeof _0x171755===_0x3ba136(0x1d2)&&_0x171755!==null&&_0x3ba136(0x206)in _0x171755&&typeof _0x171755[_0x3ba136(0x206)]===_0x3ba136(0x20c)?_0x171755[_0x3ba136(0x206)]:_0x3ba136(0x1c9);return{'path':_0x1a0b36,'error':{'code':_0x2001b3,'message':_0x3ba136(0x218)}};}function invalidReadInput(){const _0x4d6b3a=_0x416975;throw new MarAgentError(_0x4d6b3a(0x1fb),_0x4d6b3a(0x1de));}
|
|
1
|
+
import { createReadStream } from 'node:fs';
|
|
2
|
+
import { lstat, open } from 'node:fs/promises';
|
|
3
|
+
import { TextDecoder } from 'node:util';
|
|
4
|
+
import { MarAgentError } from '../error.js';
|
|
5
|
+
import { TOOL_EXECUTION_LIMITS } from './execution-limits.js';
|
|
6
|
+
export const readToolDefinition = {
|
|
7
|
+
name: 'read',
|
|
8
|
+
parallelSafety: 'safe',
|
|
9
|
+
outputSchema: {
|
|
10
|
+
type: 'object',
|
|
11
|
+
required: ['content', 'data', 'truncated'],
|
|
12
|
+
properties: {
|
|
13
|
+
content: { type: 'string' },
|
|
14
|
+
truncated: { type: 'boolean' },
|
|
15
|
+
data: {
|
|
16
|
+
type: 'object',
|
|
17
|
+
required: ['mode', 'results', 'truncated'],
|
|
18
|
+
properties: {
|
|
19
|
+
mode: { enum: ['batch'] },
|
|
20
|
+
truncated: { type: 'boolean' },
|
|
21
|
+
results: {
|
|
22
|
+
type: 'array',
|
|
23
|
+
items: {
|
|
24
|
+
type: 'object',
|
|
25
|
+
required: ['path'],
|
|
26
|
+
properties: {
|
|
27
|
+
path: { type: 'string' },
|
|
28
|
+
content: { type: 'string' },
|
|
29
|
+
text: { type: 'string' },
|
|
30
|
+
startLine: { type: 'number' },
|
|
31
|
+
endLine: { type: 'number' },
|
|
32
|
+
nextOffset: { type: 'number' },
|
|
33
|
+
eof: { type: 'boolean' },
|
|
34
|
+
truncated: { type: 'boolean' },
|
|
35
|
+
encoding: { enum: ['utf-8', 'utf-16le', 'utf-16be'] },
|
|
36
|
+
newline: { enum: ['lf', 'crlf'] },
|
|
37
|
+
error: {
|
|
38
|
+
type: 'object',
|
|
39
|
+
required: ['code', 'message'],
|
|
40
|
+
properties: { code: { type: 'string' }, message: { type: 'string' } }
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
description: `Read one or more known text files/ranges. Strict UTF-8 with optional BOM is the default; BOM-declared UTF-16LE/UTF-16BE is supported. Invalid text returns an item error instead of replacement characters. Always pass reads; use one item for a single file and up to ${TOOL_EXECUTION_LIMITS.readMaxBatchItems} items for a batch. Results retain input order, use 1-based line numbers, and include <read_metadata> with path, encoding, newline, exact range, eof, truncation, and nextOffset. Items fail independently and run with bounded concurrency. Each item returns at most ${TOOL_EXECUTION_LIMITS.readMaxLines} lines/${TOOL_EXECUTION_LIMITS.readMaxBytes} bytes; the call shares a ${TOOL_EXECUTION_LIMITS.readMaxBatchBytes}-byte budget. Structured data.results items provide text as decoded source for the returned range, preserving line endings and excluding BOM; content is numbered display text. Large files support bounded range reads. Relative paths use the workspace; absolute paths are allowed. Prefer exec with rg for search and read for known files.`,
|
|
50
|
+
inputSchema: {
|
|
51
|
+
type: 'object',
|
|
52
|
+
properties: {
|
|
53
|
+
reads: {
|
|
54
|
+
type: 'array',
|
|
55
|
+
minItems: 1,
|
|
56
|
+
maxItems: TOOL_EXECUTION_LIMITS.readMaxBatchItems,
|
|
57
|
+
description: 'Known files or ranges to read in one ordered batch.',
|
|
58
|
+
items: {
|
|
59
|
+
type: 'object',
|
|
60
|
+
properties: {
|
|
61
|
+
path: { type: 'string', description: 'Relative workspace path or absolute file path.' },
|
|
62
|
+
offset: {
|
|
63
|
+
type: 'integer',
|
|
64
|
+
minimum: 1,
|
|
65
|
+
description: 'First 1-based line; defaults to 1.'
|
|
66
|
+
},
|
|
67
|
+
limit: {
|
|
68
|
+
type: 'integer',
|
|
69
|
+
minimum: 1,
|
|
70
|
+
maximum: TOOL_EXECUTION_LIMITS.readMaxLines,
|
|
71
|
+
description: `Maximum lines; defaults to ${TOOL_EXECUTION_LIMITS.readDefaultLines}.`
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
required: ['path'],
|
|
75
|
+
additionalProperties: false
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
required: ['reads'],
|
|
80
|
+
additionalProperties: false
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
export class ReadTool {
|
|
84
|
+
paths;
|
|
85
|
+
constructor(paths) {
|
|
86
|
+
this.paths = paths;
|
|
87
|
+
}
|
|
88
|
+
async execute(arguments_, signal) {
|
|
89
|
+
return this.#readBatch(parseReadInput(arguments_).reads, signal);
|
|
90
|
+
}
|
|
91
|
+
async #readBatch(reads, signal) {
|
|
92
|
+
const perItemBytes = Math.min(TOOL_EXECUTION_LIMITS.readMaxBytes, Math.floor(TOOL_EXECUTION_LIMITS.readMaxBatchBytes / reads.length));
|
|
93
|
+
const unique = new Map();
|
|
94
|
+
for (const item of reads)
|
|
95
|
+
unique.set(readKey(item), item);
|
|
96
|
+
const entries = [...unique.entries()];
|
|
97
|
+
const completed = new Map();
|
|
98
|
+
let cursor = 0;
|
|
99
|
+
const worker = async () => {
|
|
100
|
+
for (;;) {
|
|
101
|
+
const entry = entries[cursor++];
|
|
102
|
+
if (!entry)
|
|
103
|
+
return;
|
|
104
|
+
const [key, item] = entry;
|
|
105
|
+
try {
|
|
106
|
+
completed.set(key, await this.#readOne(item, perItemBytes, signal));
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
if (signal?.aborted)
|
|
110
|
+
throw error;
|
|
111
|
+
completed.set(key, readError(item.path, error));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
await Promise.all(Array.from({ length: Math.min(TOOL_EXECUTION_LIMITS.readBatchConcurrency, entries.length) }, worker));
|
|
116
|
+
const results = reads.map((item) => completed.get(readKey(item)));
|
|
117
|
+
return {
|
|
118
|
+
mode: 'batch',
|
|
119
|
+
results,
|
|
120
|
+
truncated: results.some((result) => 'truncated' in result && result.truncated)
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
async #readOne(input, maxBytes, signal) {
|
|
124
|
+
signal?.throwIfAborted();
|
|
125
|
+
const path = await this.paths.resolve(input.path);
|
|
126
|
+
const stat = await lstat(path);
|
|
127
|
+
if (!stat.isFile())
|
|
128
|
+
throw new MarAgentError('MAR_AGENT_TOOL_INPUT_INVALID', 'Path is not a regular file.');
|
|
129
|
+
const offset = Math.max(1, input.offset ?? 1);
|
|
130
|
+
const limit = Math.min(TOOL_EXECUTION_LIMITS.readMaxLines, Math.max(1, input.limit ?? TOOL_EXECUTION_LIMITS.readDefaultLines));
|
|
131
|
+
const detected = await detectEncoding(path);
|
|
132
|
+
const selected = [];
|
|
133
|
+
const sourceLines = [];
|
|
134
|
+
let outputBytes = 0;
|
|
135
|
+
let lineNumber = 0;
|
|
136
|
+
let hasMore = false;
|
|
137
|
+
let newline = 'lf';
|
|
138
|
+
let pending = '';
|
|
139
|
+
let stopped = false;
|
|
140
|
+
const decoder = new TextDecoder(detected.decoder, { fatal: true, ignoreBOM: true });
|
|
141
|
+
const stream = createReadStream(path, { start: detected.bomBytes, signal });
|
|
142
|
+
const consumeLine = (rawLine, hasLineFeed) => {
|
|
143
|
+
const source = rawLine + (hasLineFeed ? '\n' : '');
|
|
144
|
+
lineNumber++;
|
|
145
|
+
if (rawLine.endsWith('\r')) {
|
|
146
|
+
newline = 'crlf';
|
|
147
|
+
rawLine = rawLine.slice(0, -1);
|
|
148
|
+
}
|
|
149
|
+
if (lineNumber < offset)
|
|
150
|
+
return true;
|
|
151
|
+
if (selected.length >= limit) {
|
|
152
|
+
hasMore = true;
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
const formatted = `${lineNumber}\t${rawLine}`;
|
|
156
|
+
const formattedBytes = Buffer.byteLength(formatted);
|
|
157
|
+
const separatorBytes = selected.length === 0 ? 0 : 1;
|
|
158
|
+
if (outputBytes + separatorBytes + formattedBytes > maxBytes) {
|
|
159
|
+
if (selected.length === 0)
|
|
160
|
+
throw new MarAgentError('MAR_AGENT_TOOL_OUTPUT_LIMIT', 'A single line exceeds the read result limit.');
|
|
161
|
+
hasMore = true;
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
selected.push(formatted);
|
|
165
|
+
sourceLines.push(source);
|
|
166
|
+
outputBytes += separatorBytes + formattedBytes;
|
|
167
|
+
return true;
|
|
168
|
+
};
|
|
169
|
+
const consumeDecoded = (value) => {
|
|
170
|
+
if (value.includes('\0'))
|
|
171
|
+
throw new MarAgentError('MAR_AGENT_FILE_ENCODING_INVALID', 'Text files cannot contain NUL characters; UTF-16 requires a BOM.');
|
|
172
|
+
pending += value;
|
|
173
|
+
for (;;) {
|
|
174
|
+
const delimiter = pending.indexOf('\n');
|
|
175
|
+
if (delimiter < 0)
|
|
176
|
+
break;
|
|
177
|
+
const line = pending.slice(0, delimiter);
|
|
178
|
+
pending = pending.slice(delimiter + 1);
|
|
179
|
+
if (!consumeLine(line, true))
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
if (lineNumber + 1 < offset && pending.length > 1)
|
|
183
|
+
pending = pending.endsWith('\r') ? '\r' : '';
|
|
184
|
+
else if (Buffer.byteLength(pending) > maxBytes)
|
|
185
|
+
throw new MarAgentError('MAR_AGENT_TOOL_OUTPUT_LIMIT', 'A single line exceeds the read result limit.');
|
|
186
|
+
return true;
|
|
187
|
+
};
|
|
188
|
+
try {
|
|
189
|
+
for await (const chunk of stream) {
|
|
190
|
+
if (!consumeDecoded(decoder.decode(chunk, { stream: true }))) {
|
|
191
|
+
stopped = true;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (!stopped) {
|
|
196
|
+
consumeDecoded(decoder.decode());
|
|
197
|
+
if (pending.length > 0)
|
|
198
|
+
consumeLine(pending, false);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
if (error instanceof TypeError)
|
|
203
|
+
throw new MarAgentError('MAR_AGENT_FILE_ENCODING_INVALID', 'File contains invalid text for its declared encoding.', { cause: error });
|
|
204
|
+
throw error;
|
|
205
|
+
}
|
|
206
|
+
finally {
|
|
207
|
+
stream.destroy();
|
|
208
|
+
}
|
|
209
|
+
const nextOffset = hasMore ? offset + selected.length : undefined;
|
|
210
|
+
return {
|
|
211
|
+
path: input.path,
|
|
212
|
+
content: selected.join('\n'),
|
|
213
|
+
text: sourceLines.join(''),
|
|
214
|
+
encoding: detected.encoding,
|
|
215
|
+
newline,
|
|
216
|
+
startLine: offset,
|
|
217
|
+
...(selected.length ? { endLine: offset + selected.length - 1 } : {}),
|
|
218
|
+
eof: !hasMore,
|
|
219
|
+
truncated: hasMore,
|
|
220
|
+
...(nextOffset === undefined ? {} : { nextOffset })
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
async function detectEncoding(path) {
|
|
225
|
+
const handle = await open(path, 'r');
|
|
226
|
+
try {
|
|
227
|
+
const header = Buffer.alloc(3);
|
|
228
|
+
const { bytesRead } = await handle.read(header, 0, header.length, 0);
|
|
229
|
+
if (bytesRead >= 3 && header[0] === 0xef && header[1] === 0xbb && header[2] === 0xbf)
|
|
230
|
+
return { encoding: 'utf-8', decoder: 'utf-8', bomBytes: 3 };
|
|
231
|
+
if (bytesRead >= 2 && header[0] === 0xff && header[1] === 0xfe)
|
|
232
|
+
return { encoding: 'utf-16le', decoder: 'utf-16le', bomBytes: 2 };
|
|
233
|
+
if (bytesRead >= 2 && header[0] === 0xfe && header[1] === 0xff)
|
|
234
|
+
return { encoding: 'utf-16be', decoder: 'utf-16be', bomBytes: 2 };
|
|
235
|
+
return { encoding: 'utf-8', decoder: 'utf-8', bomBytes: 0 };
|
|
236
|
+
}
|
|
237
|
+
finally {
|
|
238
|
+
await handle.close();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function parseReadInput(value) {
|
|
242
|
+
if (!value || typeof value !== 'object')
|
|
243
|
+
return invalidReadInput();
|
|
244
|
+
const input = value;
|
|
245
|
+
if (Object.keys(input).some((key) => key !== 'reads'))
|
|
246
|
+
return invalidReadInput();
|
|
247
|
+
if (!Array.isArray(input.reads) ||
|
|
248
|
+
input.reads.length === 0 ||
|
|
249
|
+
input.reads.length > TOOL_EXECUTION_LIMITS.readMaxBatchItems)
|
|
250
|
+
return invalidReadInput();
|
|
251
|
+
return { reads: input.reads.map(parseReadRequest) };
|
|
252
|
+
}
|
|
253
|
+
function parseReadRequest(value) {
|
|
254
|
+
if (!value || typeof value !== 'object')
|
|
255
|
+
return invalidReadInput();
|
|
256
|
+
const input = value;
|
|
257
|
+
if (Object.keys(input).some((key) => !['path', 'offset', 'limit'].includes(key)))
|
|
258
|
+
return invalidReadInput();
|
|
259
|
+
if (typeof input.path !== 'string' || input.path === '')
|
|
260
|
+
return invalidReadInput();
|
|
261
|
+
if (input.offset !== undefined &&
|
|
262
|
+
input.offset !== null &&
|
|
263
|
+
(!Number.isInteger(input.offset) || input.offset < 1))
|
|
264
|
+
return invalidReadInput();
|
|
265
|
+
if (input.limit !== undefined &&
|
|
266
|
+
input.limit !== null &&
|
|
267
|
+
(!Number.isInteger(input.limit) || input.limit < 1))
|
|
268
|
+
return invalidReadInput();
|
|
269
|
+
return {
|
|
270
|
+
path: input.path,
|
|
271
|
+
...(typeof input.offset === 'number' ? { offset: input.offset } : {}),
|
|
272
|
+
...(typeof input.limit === 'number'
|
|
273
|
+
? { limit: Math.min(input.limit, TOOL_EXECUTION_LIMITS.readMaxLines) }
|
|
274
|
+
: {})
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
function readKey(input) {
|
|
278
|
+
return JSON.stringify([
|
|
279
|
+
input.path,
|
|
280
|
+
input.offset ?? 1,
|
|
281
|
+
input.limit ?? TOOL_EXECUTION_LIMITS.readDefaultLines
|
|
282
|
+
]);
|
|
283
|
+
}
|
|
284
|
+
function readError(path, error) {
|
|
285
|
+
if (error instanceof MarAgentError)
|
|
286
|
+
return { path, error: { code: error.code, message: error.message } };
|
|
287
|
+
const code = typeof error === 'object' && error !== null && 'code' in error && typeof error.code === 'string'
|
|
288
|
+
? error.code
|
|
289
|
+
: 'MAR_AGENT_TOOL_FAILED';
|
|
290
|
+
return { path, error: { code, message: 'Unable to read file.' } };
|
|
291
|
+
}
|
|
292
|
+
function invalidReadInput() {
|
|
293
|
+
throw new MarAgentError('MAR_AGENT_TOOL_INPUT_INVALID', 'Read input is invalid.');
|
|
294
|
+
}
|
package/dist/tools/registry.js
CHANGED
|
@@ -1,2 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { MarAgentError } from '../error.js';
|
|
2
|
+
import { applyPatchToolDefinition } from './apply-patch.js';
|
|
3
|
+
import { codexImageGenToolDefinition, bytedArkImageGenToolDefinition, executeCodexImageGen } from './codex-image-gen.js';
|
|
4
|
+
import { execToolDefinition } from './exec.js';
|
|
5
|
+
import { codeModeToolDefinition } from './code-mode.js';
|
|
6
|
+
import { executeQuestion, questionToolDefinition } from './question.js';
|
|
7
|
+
import { readToolDefinition } from './read.js';
|
|
8
|
+
import { viewImageToolDefinition } from './view-image.js';
|
|
9
|
+
import { executeAgentStart, agentStartToolDefinition } from './agent-start.js';
|
|
10
|
+
import { executeAgentCancel, agentCancelToolDefinition } from './agent-cancel.js';
|
|
11
|
+
import { executeAgentWait, agentWaitToolDefinition } from './agent-wait.js';
|
|
12
|
+
import { executeAgentMessage, agentMessageToolDefinition } from './agent-message.js';
|
|
13
|
+
import { executeTodoRead, todoReadToolDefinition } from './todo-read.js';
|
|
14
|
+
import { executeTodoWrite, todoWriteToolDefinition } from './todo-write.js';
|
|
15
|
+
import { webFetchToolDefinition } from './web-fetch.js';
|
|
16
|
+
import { webSearchToolDefinition } from './web-search.js';
|
|
17
|
+
import { executeSkill, skillToolDefinition } from './skill.js';
|
|
18
|
+
export const BUILTIN_TOOL_DEFINITIONS = [
|
|
19
|
+
skillToolDefinition,
|
|
20
|
+
readToolDefinition,
|
|
21
|
+
viewImageToolDefinition,
|
|
22
|
+
codexImageGenToolDefinition,
|
|
23
|
+
bytedArkImageGenToolDefinition,
|
|
24
|
+
execToolDefinition,
|
|
25
|
+
codeModeToolDefinition,
|
|
26
|
+
applyPatchToolDefinition,
|
|
27
|
+
questionToolDefinition,
|
|
28
|
+
todoReadToolDefinition,
|
|
29
|
+
todoWriteToolDefinition,
|
|
30
|
+
agentStartToolDefinition,
|
|
31
|
+
agentWaitToolDefinition,
|
|
32
|
+
agentMessageToolDefinition,
|
|
33
|
+
agentCancelToolDefinition,
|
|
34
|
+
webSearchToolDefinition,
|
|
35
|
+
webFetchToolDefinition
|
|
36
|
+
];
|
|
37
|
+
export const AGENT_TOOL_HANDLERS = new Map([
|
|
38
|
+
['skill', executeSkill],
|
|
39
|
+
['codex_image_gen', imageGenerationHandler('CODEX')],
|
|
40
|
+
['byted_ark_image_gen', imageGenerationHandler('BYTED_ARK')],
|
|
41
|
+
['question', executeQuestion],
|
|
42
|
+
['todo_read', (_arguments, context) => executeTodoRead(context)],
|
|
43
|
+
['todo_write', executeTodoWrite],
|
|
44
|
+
['agent_start', executeAgentStart],
|
|
45
|
+
['agent_wait', executeAgentWait],
|
|
46
|
+
['agent_message', executeAgentMessage],
|
|
47
|
+
['agent_cancel', executeAgentCancel]
|
|
48
|
+
]);
|
|
49
|
+
function imageGenerationHandler(provider) {
|
|
50
|
+
return (arguments_, context, callId) => {
|
|
51
|
+
if (context.imageGeneration === undefined ||
|
|
52
|
+
context.imageGeneration.configuration.imageGeneration.provider !== provider)
|
|
53
|
+
throw new MarAgentError('MAR_AGENT_MODEL_CONFIG_INVALID', 'Codex image generation is unavailable.');
|
|
54
|
+
return executeCodexImageGen(arguments_, {
|
|
55
|
+
...context.imageGeneration,
|
|
56
|
+
callId,
|
|
57
|
+
signal: context.signal,
|
|
58
|
+
readImage: async (path) => {
|
|
59
|
+
const output = await context.host.executeTool({ name: 'view_image', arguments: { path } }, {
|
|
60
|
+
access: context.access,
|
|
61
|
+
mode: context.mode,
|
|
62
|
+
signal: context.signal,
|
|
63
|
+
sessionId: context.sessionId,
|
|
64
|
+
executionId: context.executionId
|
|
65
|
+
});
|
|
66
|
+
const image = output.images?.length === 1 ? output.images[0] : undefined;
|
|
67
|
+
if (image === undefined)
|
|
68
|
+
throw new MarAgentError('MAR_AGENT_TOOL_OUTPUT_INVALID', 'Referenced image result is invalid.');
|
|
69
|
+
const data = Buffer.from(image.dataBase64, 'base64');
|
|
70
|
+
if (data.byteLength === 0)
|
|
71
|
+
throw new MarAgentError('MAR_AGENT_TOOL_OUTPUT_INVALID', 'Referenced image result is invalid.');
|
|
72
|
+
return { mimeType: image.mimeType, data };
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AccessMode, ExecutionMode, MarAgentHost } from '../sdk/types.js';
|
|
2
2
|
import type { ImageGenerationConfiguration, ModelCredentialProvider } from '../model/configuration.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { SubagentController, SubagentLatestMessage } from '../subagent/scheduler.js';
|
|
4
4
|
import type { TodoStore } from './todo.js';
|
|
5
5
|
import type { AgentSkill } from '../runtime/instructions.js';
|
|
6
6
|
export type ToolRuntimeEvent = {
|
|
@@ -18,11 +18,18 @@ export type ToolRuntimeEvent = {
|
|
|
18
18
|
type: 'subagent.started';
|
|
19
19
|
agentId: string;
|
|
20
20
|
description: string;
|
|
21
|
+
modelId?: string;
|
|
22
|
+
modelName?: string;
|
|
23
|
+
reasoningEffort?: import('../model/configuration.js').MarAgentReasoningEffort;
|
|
21
24
|
} | {
|
|
22
25
|
type: 'subagent.completed';
|
|
23
26
|
agentId: string;
|
|
24
27
|
description: string;
|
|
25
28
|
status: string;
|
|
29
|
+
modelId?: string;
|
|
30
|
+
modelName?: string;
|
|
31
|
+
reasoningEffort?: import('../model/configuration.js').MarAgentReasoningEffort;
|
|
32
|
+
latestMessage?: SubagentLatestMessage;
|
|
26
33
|
errorCode?: string;
|
|
27
34
|
errorMessage?: string;
|
|
28
35
|
};
|
|
@@ -33,7 +40,7 @@ export interface ToolRuntimeImage {
|
|
|
33
40
|
export interface ToolRuntimeContext {
|
|
34
41
|
host: MarAgentHost;
|
|
35
42
|
todo: TodoStore;
|
|
36
|
-
subagents
|
|
43
|
+
subagents?: SubagentController;
|
|
37
44
|
access: AccessMode;
|
|
38
45
|
mode: ExecutionMode;
|
|
39
46
|
sessionId: string;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export{};
|
|
1
|
+
export {};
|
package/dist/tools/runtime.js
CHANGED
|
@@ -1,2 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { MarAgentError } from '../error.js';
|
|
2
|
+
import { AGENT_TOOL_HANDLERS } from './registry.js';
|
|
3
|
+
export async function executeRegisteredTool(name, arguments_, callId, context) {
|
|
4
|
+
const handler = AGENT_TOOL_HANDLERS.get(name);
|
|
5
|
+
if (handler)
|
|
6
|
+
return handler(arguments_, context, callId);
|
|
7
|
+
const call = { name, arguments: arguments_, callId };
|
|
8
|
+
if (name.startsWith('mcp__')) {
|
|
9
|
+
if (!context.host.callMcpTool)
|
|
10
|
+
throw new MarAgentError('MAR_AGENT_MCP_FAILED', 'MCP execution is unavailable.');
|
|
11
|
+
return context.host.callMcpTool(call, context.signal);
|
|
12
|
+
}
|
|
13
|
+
return context.host.executeTool(call, {
|
|
14
|
+
access: context.access,
|
|
15
|
+
mode: context.mode,
|
|
16
|
+
signal: context.signal,
|
|
17
|
+
sessionId: context.sessionId,
|
|
18
|
+
executionId: context.executionId,
|
|
19
|
+
...(context.codeMode === undefined ? {} : { codeMode: context.codeMode })
|
|
20
|
+
});
|
|
21
|
+
}
|
package/dist/tools/scheduler.js
CHANGED
|
@@ -1,2 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/** Schedules an incremental stream while preserving the same safe/serial barriers as batches. */
|
|
2
|
+
export function createToolCallScheduler(definitions, execute) {
|
|
3
|
+
const safety = new Map(definitions.map((definition) => [definition.name, definition.parallelSafety]));
|
|
4
|
+
let barrier = Promise.resolve();
|
|
5
|
+
const readers = new Set();
|
|
6
|
+
return (call) => {
|
|
7
|
+
const safe = safety.get(call.name) === 'safe';
|
|
8
|
+
const gate = safe ? barrier : Promise.all([barrier, ...readers]).then(() => undefined);
|
|
9
|
+
const result = gate.then(() => execute(call));
|
|
10
|
+
const settled = result.then(() => undefined, () => undefined);
|
|
11
|
+
if (safe) {
|
|
12
|
+
readers.add(settled);
|
|
13
|
+
void settled.then(() => readers.delete(settled));
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
readers.clear();
|
|
17
|
+
barrier = settled;
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export async function scheduleToolCallBatch(calls, definitions, execute) {
|
|
23
|
+
const safety = new Map(definitions.map((definition) => [definition.name, definition.parallelSafety]));
|
|
24
|
+
const results = new Array(calls.length);
|
|
25
|
+
let index = 0;
|
|
26
|
+
while (index < calls.length) {
|
|
27
|
+
if (safety.get(calls[index].name) !== 'safe') {
|
|
28
|
+
results[index] = await execute(calls[index]);
|
|
29
|
+
index++;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
let end = index + 1;
|
|
33
|
+
while (end < calls.length && safety.get(calls[end].name) === 'safe')
|
|
34
|
+
end++;
|
|
35
|
+
const segment = await Promise.all(calls.slice(index, end).map((call) => execute(call)));
|
|
36
|
+
for (let segmentIndex = 0; segmentIndex < segment.length; segmentIndex++)
|
|
37
|
+
results[index + segmentIndex] = segment[segmentIndex];
|
|
38
|
+
index = end;
|
|
39
|
+
}
|
|
40
|
+
return results;
|
|
41
|
+
}
|