@myagentroam/agent 0.9.62 → 0.9.65
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 +431 -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/exec.js
CHANGED
|
@@ -1,2 +1,455 @@
|
|
|
1
|
-
|
|
2
|
-
const _0x58e7c3=_0x2bfd;(function(_0x3aa619,_0x37d4e2){const _0x340208=_0x2bfd,_0x38deaf=_0x3aa619();while(!![]){try{const _0x43abec=parseInt(_0x340208(0x1d2))/(0x5c+-0xb*-0x17b+0x852*-0x2)+-parseInt(_0x340208(0x1df))/(0x124e*-0x1+0x1310+0x40*-0x3)*(-parseInt(_0x340208(0x24c))/(-0x1a83+0x3c9+0x16bd))+-parseInt(_0x340208(0x1ce))/(-0x2ab*0x8+-0xef+0x164b)*(parseInt(_0x340208(0x1da))/(0x13*0x107+0x6aa*0x4+-0x38*0xd3))+parseInt(_0x340208(0x213))/(0x4*0x22e+-0x1*0x2153+0x18a1)*(-parseInt(_0x340208(0x1c2))/(-0x1*0xc2d+0x5b4+-0x1*-0x680))+-parseInt(_0x340208(0x240))/(-0x23f2+0xffc+-0x355*-0x6)*(parseInt(_0x340208(0x230))/(-0x1198+-0x2*0xeac+0x2ef9))+-parseInt(_0x340208(0x1c4))/(0xef*0x25+0x8f0+0x3f3*-0xb)+parseInt(_0x340208(0x1bf))/(-0x33*-0xbb+-0x4a*0xf+-0x20e0);if(_0x43abec===_0x37d4e2)break;else _0x38deaf['push'](_0x38deaf['shift']());}catch(_0x1f1244){_0x38deaf['push'](_0x38deaf['shift']());}}}(_0x2211,-0x86*0xeb9+-0x5d747+0x159554));import{directLocalProcessExecutor,signalProcessTree}from'../host/local-process-executor.js';import{randomUUID}from'node:crypto';import{StringDecoder}from'node:string_decoder';import{MarAgentError}from'../error.js';import{TOOL_EXECUTION_LIMITS}from'./execution-limits.js';export const execToolDefinition={'name':_0x58e7c3(0x1f4),'parallelSafety':_0x58e7c3(0x219),'description':_0x58e7c3(0x231),'outputSchema':{'type':_0x58e7c3(0x21d),'required':[_0x58e7c3(0x1f8),_0x58e7c3(0x1f0)],'properties':{'content':{'type':_0x58e7c3(0x1e2)},'data':{'type':_0x58e7c3(0x21d),'required':[_0x58e7c3(0x1fa),_0x58e7c3(0x212),_0x58e7c3(0x1be),_0x58e7c3(0x1e0),_0x58e7c3(0x1ee),_0x58e7c3(0x1ed),_0x58e7c3(0x233),_0x58e7c3(0x1ec)],'properties':{'status':{'enum':[_0x58e7c3(0x243),_0x58e7c3(0x21f),_0x58e7c3(0x23f)]},'processId':{'type':_0x58e7c3(0x1e2)},'stdout':{'type':_0x58e7c3(0x1e2)},'stderr':{'type':_0x58e7c3(0x1e2)},'exitCode':{'type':[_0x58e7c3(0x23b),_0x58e7c3(0x1e7)]},'truncated':{'type':_0x58e7c3(0x211)},'stdoutBytes':{'type':_0x58e7c3(0x23b)},'stderrBytes':{'type':_0x58e7c3(0x23b)},'stdoutDroppedBytes':{'type':_0x58e7c3(0x23b)},'stderrDroppedBytes':{'type':_0x58e7c3(0x23b)}}}}},'inputSchema':{'type':_0x58e7c3(0x21d),'properties':{'action':{'enum':[_0x58e7c3(0x227),_0x58e7c3(0x221),_0x58e7c3(0x220),_0x58e7c3(0x241)],'description':_0x58e7c3(0x1fe)},'command':{'type':_0x58e7c3(0x1e2),'description':_0x58e7c3(0x1d3)},'cwd':{'type':_0x58e7c3(0x1e2),'description':_0x58e7c3(0x1fb)},'timeoutMs':{'type':_0x58e7c3(0x1f1),'minimum':0x1,'maximum':TOOL_EXECUTION_LIMITS[_0x58e7c3(0x209)]},'yieldMs':{'type':_0x58e7c3(0x1f1),'minimum':0x0,'maximum':TOOL_EXECUTION_LIMITS[_0x58e7c3(0x20a)],'default':TOOL_EXECUTION_LIMITS[_0x58e7c3(0x218)],'description':_0x58e7c3(0x217)+TOOL_EXECUTION_LIMITS[_0x58e7c3(0x218)]+_0x58e7c3(0x24b)+TOOL_EXECUTION_LIMITS[_0x58e7c3(0x20a)]+_0x58e7c3(0x24a)},'processId':{'type':_0x58e7c3(0x1e2),'description':_0x58e7c3(0x1dc)},'data':{'type':_0x58e7c3(0x1e2),'description':_0x58e7c3(0x1e8)}},'required':[_0x58e7c3(0x248)],'additionalProperties':![]}};export class ExecTool{[_0x58e7c3(0x205)];[_0x58e7c3(0x20b)];[_0x58e7c3(0x1bd)];[_0x58e7c3(0x206)];[_0x58e7c3(0x20d)];[_0x58e7c3(0x1d4)];#processes=new Map();constructor(_0x17d503,_0x52205b=TOOL_EXECUTION_LIMITS[_0x58e7c3(0x21a)],_0x3a6682=TOOL_EXECUTION_LIMITS[_0x58e7c3(0x1bd)],_0xf60ca7=process.env,_0x3e07e7,_0x4ddb46=directLocalProcessExecutor){const _0x3ca6a6=_0x58e7c3;this[_0x3ca6a6(0x205)]=_0x17d503,this[_0x3ca6a6(0x20b)]=_0x52205b,this[_0x3ca6a6(0x1bd)]=_0x3a6682,this[_0x3ca6a6(0x206)]=_0xf60ca7,this[_0x3ca6a6(0x20d)]=_0x3e07e7,this[_0x3ca6a6(0x1d4)]=_0x4ddb46;}async[_0x58e7c3(0x210)](_0x5637d5,_0x34bf32,_0x590b66){const _0x585029=_0x58e7c3;if(_0x34bf32?.[_0x585029(0x1f3)])throw executionAbortReason(_0x34bf32);const _0xb58f07=parseExecInput(_0x5637d5);if(_0xb58f07[_0x585029(0x248)]!==_0x585029(0x227)){const _0x587356=this.#processes[_0x585029(0x1d6)](_0xb58f07[_0x585029(0x1c5)]);if(!_0x587356||_0x590b66!==undefined&&_0x587356[_0x585029(0x23c)]!==_0x590b66[_0x585029(0x1d0)])throw new MarAgentError(_0x585029(0x1e4),_0x585029(0x1fc));if(_0xb58f07[_0x585029(0x248)]===_0x585029(0x221)&&_0xb58f07[_0x585029(0x1ca)])await waitForProcessChange(_0x587356,Math[_0x585029(0x246)](Math[_0x585029(0x22c)](_0xb58f07[_0x585029(0x1ca)],0x551*-0x7+0xd4+0x73*0x51),TOOL_EXECUTION_LIMITS[_0x585029(0x20a)]),_0x34bf32);if(_0xb58f07[_0x585029(0x248)]===_0x585029(0x220))_0x587356[_0x585029(0x249)][_0x585029(0x242)][_0x585029(0x220)](_0xb58f07[_0x585029(0x1f0)]);if(_0xb58f07[_0x585029(0x248)]===_0x585029(0x241))await this.#terminate(_0x587356,!![]);const _0x26f26d=this.#result(_0xb58f07[_0x585029(0x1c5)],_0x587356);if(_0x587356[_0x585029(0x1fa)]!==_0x585029(0x243))this.#processes[_0x585029(0x23e)](_0xb58f07[_0x585029(0x1c5)]);return _0x26f26d;}if(this.#processes[_0x585029(0x1cb)]>=this[_0x585029(0x1bd)])throw new MarAgentError(_0x585029(0x1c3),_0x585029(0x202));const _0x1ef027=randomUUID(),_0x3f38dc=await this[_0x585029(0x205)][_0x585029(0x1d1)](_0xb58f07[_0x585029(0x1e1)]??'.'),_0x2b2ab7=await this[_0x585029(0x1d4)][_0x585029(0x216)]({'command':_0xb58f07[_0x585029(0x234)],'cwd':_0x3f38dc[_0x585029(0x1cf)],'shell':this[_0x585029(0x20d)]??!![],'environment':this[_0x585029(0x206)],'detached':process[_0x585029(0x1ea)]!==_0x585029(0x200),..._0x590b66===undefined?{}:{'owner':_0x590b66},..._0x34bf32===undefined?{}:{'signal':_0x34bf32}});let _0x76abed,_0x5a5916;const _0x3712e0={'child':_0x2b2ab7,..._0x590b66===undefined?{}:{'ownerSessionId':_0x590b66[_0x585029(0x1d0)]},'command':_0xb58f07[_0x585029(0x234)],'cwd':_0x3f38dc[_0x585029(0x1c1)],'stdout':createOutputBuffer(),'stderr':createOutputBuffer(),'status':_0x585029(0x243),'exited':new Promise(_0x4682e0=>_0x76abed=_0x4682e0),'settled':new Promise(_0x244ea5=>_0x5a5916=_0x244ea5),'resolveExited':_0x76abed,'resolveSettled':_0x5a5916,'exitObserved':_0x2b2ab7[_0x585029(0x1d9)]!==null,'finalized':![],'waiters':new Set()};this.#processes[_0x585029(0x236)](_0x1ef027,_0x3712e0),_0x2b2ab7[_0x585029(0x212)]['on'](_0x585029(0x1f0),_0x4ad9ed=>{const _0xb055e2=_0x585029;if(_0x3712e0[_0xb055e2(0x229)])return;appendOutput(_0x3712e0[_0xb055e2(0x212)],Buffer[_0xb055e2(0x23d)](_0x3712e0[_0xb055e2(0x212)][_0xb055e2(0x235)][_0xb055e2(0x220)](_0x4ad9ed)),this[_0xb055e2(0x20b)],_0x4ad9ed[_0xb055e2(0x1dd)]),notifyProcessChange(_0x3712e0);}),_0x2b2ab7[_0x585029(0x1be)]['on'](_0x585029(0x1f0),_0x4b1394=>{const _0x5a7177=_0x585029;if(_0x3712e0[_0x5a7177(0x229)])return;appendOutput(_0x3712e0[_0x5a7177(0x1be)],Buffer[_0x5a7177(0x23d)](_0x3712e0[_0x5a7177(0x1be)][_0x5a7177(0x235)][_0x5a7177(0x220)](_0x4b1394)),this[_0x5a7177(0x20b)],_0x4b1394[_0x5a7177(0x1dd)]),notifyProcessChange(_0x3712e0);}),_0x2b2ab7[_0x585029(0x237)](_0x585029(0x21e),_0xc40c91=>{const _0x552990=_0x585029;_0x3712e0[_0x552990(0x22a)]=!![],_0x3712e0[_0x552990(0x1d9)]=_0xc40c91,_0x3712e0[_0x552990(0x222)](),void finalizeAfterOutputGrace(_0x3712e0,this[_0x552990(0x20b)]);}),_0x2b2ab7[_0x585029(0x237)](_0x585029(0x20e),_0x2a2345=>{const _0x260274=_0x585029;_0x3712e0[_0x260274(0x22a)]=!![],_0x3712e0[_0x260274(0x222)](),finalizeManagedProcess(_0x3712e0,this[_0x260274(0x20b)],_0x2a2345);}),_0x2b2ab7[_0x585029(0x237)](_0x585029(0x1d8),_0xa9ec8b=>{const _0x16fdb0=_0x585029;if(_0x3712e0[_0x16fdb0(0x229)])return;appendOutput(_0x3712e0[_0x16fdb0(0x1be)],Buffer[_0x16fdb0(0x23d)](_0xa9ec8b[_0x16fdb0(0x22e)]),this[_0x16fdb0(0x20b)]),notifyProcessChange(_0x3712e0);}),_0x3712e0[_0x585029(0x1ff)]=setTimeout(()=>{void this.#terminate(_0x3712e0,!![]);},Math[_0x585029(0x246)](_0xb58f07[_0x585029(0x228)]??TOOL_EXECUTION_LIMITS[_0x585029(0x21b)],TOOL_EXECUTION_LIMITS[_0x585029(0x209)])),_0x3712e0[_0x585029(0x1ff)][_0x585029(0x20f)](),await waitForExitOrDelay(_0x3712e0[_0x585029(0x1fd)],Math[_0x585029(0x246)](_0xb58f07[_0x585029(0x1ca)]??TOOL_EXECUTION_LIMITS[_0x585029(0x218)],TOOL_EXECUTION_LIMITS[_0x585029(0x20a)]),_0x34bf32);const _0x2a4056=this.#result(_0x1ef027,_0x3712e0);if(_0x3712e0[_0x585029(0x1fa)]!==_0x585029(0x243))this.#processes[_0x585029(0x23e)](_0x1ef027);return _0x2a4056;}[_0x58e7c3(0x225)](_0x219f8e){const _0x3002b2=_0x58e7c3;return[...this.#processes[_0x3002b2(0x1cd)]()][_0x3002b2(0x245)](([_0x1e6399,_0x45c688])=>_0x45c688[_0x3002b2(0x23c)]===_0x219f8e?[{'processId':_0x1e6399,'status':_0x45c688[_0x3002b2(0x1fa)],'command':_0x45c688[_0x3002b2(0x234)],'cwd':_0x45c688[_0x3002b2(0x1e1)]}]:[]);}async[_0x58e7c3(0x238)](_0x409611){const _0x3a3a05=_0x58e7c3,_0x435860=[...this.#processes[_0x3a3a05(0x1cd)]()][_0x3a3a05(0x215)](([,_0x15dc24])=>_0x15dc24[_0x3a3a05(0x23c)]===_0x409611);await Promise[_0x3a3a05(0x224)](_0x435860[_0x3a3a05(0x1c0)](([,_0x43f517])=>_0x43f517[_0x3a3a05(0x1fa)]===_0x3a3a05(0x243)?this.#terminate(_0x43f517,![]):_0x43f517[_0x3a3a05(0x1fd)]));for(const [_0x1cee35]of _0x435860)this.#processes[_0x3a3a05(0x23e)](_0x1cee35);}async #terminate(_0x23f26e,_0x53bd6a){const _0x42a29f=_0x58e7c3;if(_0x23f26e[_0x42a29f(0x1eb)])return _0x23f26e[_0x42a29f(0x1eb)];return _0x23f26e[_0x42a29f(0x1eb)]=((async()=>{const _0xc55d06=_0x42a29f;if(_0x23f26e[_0xc55d06(0x22a)]||_0x23f26e[_0xc55d06(0x249)][_0xc55d06(0x1d9)]!==null){if(_0x23f26e[_0xc55d06(0x249)][_0xc55d06(0x1d9)]!==null)_0x23f26e[_0xc55d06(0x1d9)]=_0x23f26e[_0xc55d06(0x249)][_0xc55d06(0x1d9)];if(_0x53bd6a){const _0x403315=await waitForExit(_0x23f26e[_0xc55d06(0x1fd)],TOOL_EXECUTION_LIMITS[_0xc55d06(0x22f)]);if(_0x403315)return;}finalizeManagedProcess(_0x23f26e,this[_0xc55d06(0x20b)],_0x23f26e[_0xc55d06(0x249)][_0xc55d06(0x1d9)]),destroyManagedStreams(_0x23f26e);return;}_0x23f26e[_0xc55d06(0x1fa)]=_0xc55d06(0x23f);if(_0x23f26e[_0xc55d06(0x1ff)])clearTimeout(_0x23f26e[_0xc55d06(0x1ff)]);await signalProcessTree(_0x23f26e[_0xc55d06(0x249)],_0xc55d06(0x1c7));const _0x24c0f3=await waitForExit(_0x23f26e[_0xc55d06(0x1c8)],TOOL_EXECUTION_LIMITS[_0xc55d06(0x22f)]);!_0x24c0f3&&(await signalProcessTree(_0x23f26e[_0xc55d06(0x249)],_0xc55d06(0x214)),await _0x23f26e[_0xc55d06(0x1c8)]);if(_0x53bd6a){const _0x51ce75=await waitForExit(_0x23f26e[_0xc55d06(0x1fd)],TOOL_EXECUTION_LIMITS[_0xc55d06(0x22f)]);if(_0x51ce75)return;}finalizeManagedProcess(_0x23f26e,this[_0xc55d06(0x20b)],_0x23f26e[_0xc55d06(0x1d9)]),destroyManagedStreams(_0x23f26e);})()),_0x23f26e[_0x42a29f(0x1eb)];}#result(_0x45000d,_0x282821){const _0x58f6b7=_0x58e7c3,_0x4a5303=consumeOutput(_0x282821[_0x58f6b7(0x212)]),_0x31e8ac=consumeOutput(_0x282821[_0x58f6b7(0x1be)]);return{'status':_0x282821[_0x58f6b7(0x1fa)],..._0x282821[_0x58f6b7(0x1fa)]===_0x58f6b7(0x243)?{'processId':_0x45000d}:{},'stdout':_0x4a5303[_0x58f6b7(0x208)],'stderr':_0x31e8ac[_0x58f6b7(0x208)],..._0x282821[_0x58f6b7(0x1d9)]===undefined?{}:{'exitCode':_0x282821[_0x58f6b7(0x1d9)]},'truncated':_0x4a5303[_0x58f6b7(0x201)]>-0x14cf*0x1+0x14b+0x1384*0x1||_0x31e8ac[_0x58f6b7(0x201)]>-0x1*0x719+0x161f+-0xf06,'stdoutBytes':_0x282821[_0x58f6b7(0x212)][_0x58f6b7(0x22b)],'stderrBytes':_0x282821[_0x58f6b7(0x1be)][_0x58f6b7(0x22b)],'stdoutDroppedBytes':_0x4a5303[_0x58f6b7(0x201)],'stderrDroppedBytes':_0x31e8ac[_0x58f6b7(0x201)]};}async[_0x58e7c3(0x1de)](){const _0xf5cbf0=_0x58e7c3;await Promise[_0xf5cbf0(0x224)]([...this.#processes[_0xf5cbf0(0x21c)]()][_0xf5cbf0(0x1c0)](_0x49d9cc=>_0x49d9cc[_0xf5cbf0(0x1fa)]===_0xf5cbf0(0x243)?this.#terminate(_0x49d9cc,![]):_0x49d9cc[_0xf5cbf0(0x1fd)])),this.#processes[_0xf5cbf0(0x20c)]();}}function createOutputBuffer(){const _0x40c992=_0x58e7c3;return{'chunks':[],'bytes':0x0,'totalBytes':0x0,'droppedBytes':0x0,'windowOffset':0x0,'decoder':new StringDecoder(_0x40c992(0x244))};}function finalizeManagedProcess(_0x17132b,_0x3b8d40,_0x1c4580){const _0x560d27=_0x58e7c3;if(_0x17132b[_0x560d27(0x229)])return;_0x17132b[_0x560d27(0x229)]=!![],appendOutput(_0x17132b[_0x560d27(0x212)],Buffer[_0x560d27(0x23d)](_0x17132b[_0x560d27(0x212)][_0x560d27(0x235)][_0x560d27(0x1e9)]()),_0x3b8d40),appendOutput(_0x17132b[_0x560d27(0x1be)],Buffer[_0x560d27(0x23d)](_0x17132b[_0x560d27(0x1be)][_0x560d27(0x235)][_0x560d27(0x1e9)]()),_0x3b8d40),_0x17132b[_0x560d27(0x1fa)]=_0x17132b[_0x560d27(0x1fa)]===_0x560d27(0x23f)?_0x560d27(0x23f):_0x560d27(0x21f);if(_0x1c4580!==undefined)_0x17132b[_0x560d27(0x1d9)]=_0x1c4580;if(_0x17132b[_0x560d27(0x1ff)])clearTimeout(_0x17132b[_0x560d27(0x1ff)]);notifyProcessChange(_0x17132b),_0x17132b[_0x560d27(0x203)]();}async function finalizeAfterOutputGrace(_0x393a08,_0x35f111){const _0x5cdc74=_0x58e7c3,_0x5866c1=await waitForExit(_0x393a08[_0x5cdc74(0x1fd)],TOOL_EXECUTION_LIMITS[_0x5cdc74(0x22f)]);if(_0x5866c1)return;finalizeManagedProcess(_0x393a08,_0x35f111,_0x393a08[_0x5cdc74(0x1d9)]),destroyManagedStreams(_0x393a08);}function destroyManagedStreams(_0x17bb25){const _0x436e2e=_0x58e7c3;_0x17bb25[_0x436e2e(0x249)][_0x436e2e(0x242)][_0x436e2e(0x226)](),_0x17bb25[_0x436e2e(0x249)][_0x436e2e(0x212)][_0x436e2e(0x226)](),_0x17bb25[_0x436e2e(0x249)][_0x436e2e(0x1be)][_0x436e2e(0x226)]();}function appendOutput(_0x5f0177,_0x34e605,_0x30a6e3,_0x18cb4c=_0x34e605[_0x58e7c3(0x1dd)]){const _0x4a2163=_0x58e7c3;_0x5f0177[_0x4a2163(0x22b)]+=_0x18cb4c;if(!_0x34e605[_0x4a2163(0x1dd)])return;_0x5f0177[_0x4a2163(0x1e5)][_0x4a2163(0x1e6)](_0x34e605),_0x5f0177[_0x4a2163(0x207)]+=_0x34e605[_0x4a2163(0x1dd)];const _0x4c8ab7=_0x5f0177[_0x4a2163(0x207)]-_0x30a6e3;if(_0x4c8ab7<=-0xac9+0x1*-0x1b2+0x9*0x163)return;const _0x53f1ba=Math[_0x4a2163(0x1d5)](_0x30a6e3/(-0x24a6+-0x1ce4+0x418c));let _0x3efcf3=_0x5f0177[_0x4a2163(0x1f7)];(!_0x3efcf3||_0x5f0177[_0x4a2163(0x207)]!==_0x3efcf3[_0x4a2163(0x1dd)]-_0x5f0177[_0x4a2163(0x232)])&&(_0x3efcf3=Buffer[_0x4a2163(0x23a)](_0x5f0177[_0x4a2163(0x1e5)],_0x5f0177[_0x4a2163(0x207)]),_0x5f0177[_0x4a2163(0x232)]=-0x134a+0xfe*-0x1d+0x3010);const _0x1c4413=_0x3efcf3[_0x4a2163(0x1cc)](_0x5f0177[_0x4a2163(0x232)],_0x5f0177[_0x4a2163(0x232)]+_0x5f0177[_0x4a2163(0x207)]);_0x5f0177[_0x4a2163(0x1e5)]=[],_0x5f0177[_0x4a2163(0x207)]=0x2503+-0x69e+-0x1e65,_0x5f0177[_0x4a2163(0x201)]+=_0x4c8ab7;const _0x4cb4af=(_0x423dc3,_0x1374c2)=>{const _0x5a6af0=_0x4a2163;while(_0x423dc3<_0x1374c2&&(_0x1c4413[_0x423dc3]&0x37*-0x62+0x105*0x25+0xfeb*-0x1)===0x6f*-0x3f+-0x2cd*-0xa+-0x7*0x7)_0x423dc3++;while(_0x1374c2>_0x423dc3&&(_0x1c4413[_0x1374c2-(-0x11*0x19e+0x1bfa+-0x7b)]&-0x485+-0x586+0xacb)===0x7*-0x7f+-0x1d44+0x1*0x213d)_0x1374c2--;if(_0x423dc3>=_0x1374c2)return;const _0x2bb887=_0x1c4413[_0x5a6af0(0x1cc)](_0x423dc3,_0x1374c2);_0x5f0177[_0x5a6af0(0x1e5)][_0x5a6af0(0x1e6)](_0x2bb887),_0x5f0177[_0x5a6af0(0x207)]+=_0x2bb887[_0x5a6af0(0x1dd)];};_0x4cb4af(-0x2*-0xcce+0x2074+-0x3a10,Math[_0x4a2163(0x246)](_0x53f1ba,_0x1c4413[_0x4a2163(0x1dd)])),_0x4cb4af(Math[_0x4a2163(0x246)](_0x53f1ba+_0x4c8ab7,_0x1c4413[_0x4a2163(0x1dd)]),_0x1c4413[_0x4a2163(0x1dd)]),_0x5f0177[_0x4a2163(0x1f7)]=_0x3efcf3;}function _0x2211(){const _0x40ce8d=['C2v0','B25Jzq','zgLZCg9ZzvnLC3nPB24','DgHLBG','y29Uy2f0','BNvTyMvY','B3DUzxjtzxnZAw9Uswq','zNjVBq','zgvSzxrL','y2fUy2vSBgvK','oeDJA1zmAa','y2fUy2vS','C3rKAw4','CNvUBMLUzW','DxrMoa','zMXHDe1HCa','BwLU','CMvTB3zLrxzLBNrmAxn0zw5LCG','ywn0Aw9U','y2HPBgq','ig1ZlG','ig1ZoYbLzMzLy3rPDMuGCMfUz2uGAxmGmc0','ou9VBfbKyW','tufsx0fhru5ux0vyrunvveLptL9dqu5druXmruq','Bwf4uhjVy2vZC2vZ','C3rKzxjY','mtyWnZa1nZfsAuD5Ew0','BwfW','zgLZCgXHEvbHDgG','mti2n2vhuNfSzG','tufsx0fhru5ux1bst0nfu1nFteLnsvq','ndeWmdeZmgjpzKz1uq','ChjVy2vZC0LK','CMfJzq','u0Lhvevstq','zxHPDgvK','DhjPBq','EwLLBgrnCW','C2L6zq','C3vIyxjYyxK','zw50CMLLCW','nfDgAhLiza','CgH5C2LJywXqyxrO','C2vZC2LVBKLK','CMvZB2X2zvDPDgHeAxnWBgf5','otK0ody5rvz5t2Dp','uMvXDwLYzwqGB25SEsbMB3iGC3rHCNqU','ChjVy2vZC0v4zwn1Dg9Y','y2vPBa','z2v0','AxnjBNrLz2vY','zxjYB3i','zxHPDenVzgu','mtK3ndq3nwnbEvPtCq','rxHLyYbPBNb1DcbPCYbPBNzHBgLKlG','uMvXDwLYzwqGzM9YihbVBgWSihDYAxrLigfUzcbJyw5JzwWU','BgvUz3rO','zgLZCg9Zzq','mtiYmtaYEwLzt25s','Dhj1BMnHDgvK','y3DK','C3rYAw5N','ywjVCNq','tufsx0fhru5ux1bst0nfu1nFtK9ux0zpvu5e','y2H1BMTZ','ChvZAa','BNvSBa','C3rKAw4Gzgf0ysbYzxf1AxjLzcbMB3iGD3jPDguU','zw5K','CgXHDgzVCM0','DgvYBwLUyxrL','C3rKzxjYrhjVChbLzej5DgvZ','C3rKzxjYqNL0zxm','C3rKB3v0qNL0zxm','Dg9tDhjPBMC','zgf0yq','Aw50zwDLCG','CMvHC29U','ywjVCNrLza','zxHLyW','Aw5JBhvKzxm','ywrK','D2LUzg93','y29UDgvUDa','ywrKrxzLBNrmAxn0zw5LCG','C3rHDhvZ','t3b0Aw9UywWGCMvSyxrPDMuVywjZB2X1DguGC3rHCNqGzgLYzwn0B3j5oYbKzwzHDwX0CYb0BYb3B3jRC3bHy2uU','twfUywDLzcbWCM9JzxnZihDHCYbUB3qGzM91BMqU','C2v0DgXLza','tgLMzwn5y2XLig9WzxjHDgLVBI4','DgLTzxi','D2LUmZi','zhjVChbLzej5DgvZ','vgHLig1HBMfNzwqGChjVy2vZCYbSAw1PDcb3yxmGCMvHy2HLzc4','CMvZB2X2zvnLDhrSzwq','tufsx0fhru5ux1rpt0XFsu5qvvrFsu5wquXjra','Cgf0Ahm','zw52AxjVBM1LBNq','yNL0zxm','DMfSDwu','zxHLy01HEfrPBwvVDxrnCW','zxHLy01HEfLPzwXKtxm','Bwf4t3v0Chv0qNL0zxm','y2XLyxi','C2HLBgW','y2XVC2u','Dw5Yzwy','zxHLy3v0zq','yM9VBgvHBG','C3rKB3v0','mtqWotrmvMHRweK','u0Lhs0Lmta','zMLSDgvY','C3bHD24','v2fPDcbIzwzVCMuGEwLLBgrPBMCGB3v0Chv0lIbezwzHDwX0CYb0BYa','zxHLy0rLzMf1BhrzAwvSze1Z','C2vYAwfS','zxHLy0rLzMf1BhrnyxHpDxrWDxrcExrLCW','zxHLy0rLzMf1BhruAw1LB3v0txm','DMfSDwvZ','B2jQzwn0','zxHPDa','y29TCgXLDgvK','D3jPDgu','Cg9SBa','CMvZB2X2zuv4AxrLza','D2fPDgvYCW','ywXS','BgLZDfnLC3nPB25szxnVDxjJzxm','zgvZDhjVEq','C3rHCNq','DgLTzw91De1Z','zMLUywXPEMvK','zxHPDe9IC2vYDMvK','Dg90ywXcExrLCW','Bwf4','rxHLy3v0Aw9UignHBMnLBgXLzc4','BwvZC2fNzq','zxHLy1rLCM1PBMf0Aw9Ur3jHy2vnCW','nZK0mdmZmvbxvM1kAa','vw5Yzxn0CMLJDgvKigDLBMvYywWGC3LZDgvTigv4zwn1DgLVBI4GC3rHCNqGCNvUCYbHBNKGCgXHDgzVCM0TBMf0AxzLignVBw1HBMqSihnJCMLWDcWGDgv4Dc9MAwXLihrVB2WSigj1AwXKzxiSigDLBMvYyxrVCIWGBMv0D29YAYbJBgLLBNqSig9YihbYB2DYyw0GAw4GD29YA3nWywnLl2rLzMf1BhqGy3DKigfUzcbTyxKGCMv0DxjUihj1BM5PBMCGD2L0AcbWCM9JzxnZswq7ihbVBgWGD2fPDhmGDxaGDg8GEwLLBgrnCYbMB3iGBMv3ig91Dhb1DcbVCIb0zxjTAw5HDgLVBIbHBMqGCMv0DxjUCYbVBMX5ig91Dhb1DcbWCM9KDwnLzcbZAw5Jzsb0AguGChjPB3iGCMvZDwX0oYb3CML0zsbZzw5KCYbZDgrPBJSGy2fUy2vSihrLCM1PBMf0zxmGDgHLihbYB2nLC3mGDhjLzs4GuMv0DxjUCYbZDgf0DxmSihbYB2nLC3njzcWGAw5JCMvTzw50ywWGC3rKB3v0l3n0zgvYCIWGy3vTDwXHDgL2zsbZDgrVDxrcExrLCY9ZDgrLCNjcExrLCYWGCgvYlxjLC3vSDcbKCM9WCgvKigj5DgvZlcbLEgL0q29KzsWGyw5KihrYDw5JyxrLzdSGysbJB21WBgv0zwqGC3rHDhvZigrVzxmGBM90igLTCgX5igv4AxrdB2rLidaUiefSD2f5CYbPBNnWzwn0ihn0zgvYCI9LEgL0q29KzsbHBMqGy29UC3vTzsb0zxjTAw5HBcbVDxrWDxqGB3iGy2fUy2vSlG','D2LUzg93t2zMC2v0','C3rKB3v0rhjVChbLzej5DgvZ','y29TBwfUza','zgvJB2rLCG'];_0x2211=function(){return _0x40ce8d;};return _0x2211();}function consumeOutput(_0x1e4952){const _0x2145ee=_0x58e7c3,_0x4e6dd7=Buffer[_0x2145ee(0x23a)](_0x1e4952[_0x2145ee(0x1e5)],_0x1e4952[_0x2145ee(0x207)])[_0x2145ee(0x1ef)](_0x2145ee(0x244)),_0x3325ed=_0x1e4952[_0x2145ee(0x201)];return _0x1e4952[_0x2145ee(0x1e5)]=[],_0x1e4952[_0x2145ee(0x207)]=-0x1d08+-0x103c*-0x1+0x4*0x333,_0x1e4952[_0x2145ee(0x201)]=-0x1a22+0x1*-0xbc1+0x9f*0x3d,delete _0x1e4952[_0x2145ee(0x1f7)],_0x1e4952[_0x2145ee(0x232)]=-0x685*-0x3+0xd81+-0x2110,{'value':_0x4e6dd7,'droppedBytes':_0x3325ed};}function parseExecInput(_0x1929dd){const _0x3d760a=_0x58e7c3;if(!_0x1929dd||typeof _0x1929dd!==_0x3d760a(0x21d))return invalidExecInput();const _0xb83017=_0x1929dd,_0x226d10=_0xb83017[_0x3d760a(0x248)];if(![_0x3d760a(0x227),_0x3d760a(0x221),_0x3d760a(0x220),_0x3d760a(0x241)][_0x3d760a(0x1f5)](String(_0x226d10)))return invalidExecInput();const _0x21413c=optionalBoundedInteger(_0xb83017[_0x3d760a(0x1ca)],0x1fc7+0x578+-0x253f,TOOL_EXECUTION_LIMITS[_0x3d760a(0x20a)]);if(_0x226d10===_0x3d760a(0x227)){if(typeof _0xb83017[_0x3d760a(0x234)]!==_0x3d760a(0x1e2)||_0xb83017[_0x3d760a(0x234)][_0x3d760a(0x1c9)]()==='')return invalidExecInput();if(_0xb83017[_0x3d760a(0x1e1)]!==undefined&&_0xb83017[_0x3d760a(0x1e1)]!==null&&typeof _0xb83017[_0x3d760a(0x1e1)]!==_0x3d760a(0x1e2))return invalidExecInput();const _0x2930a9=optionalBoundedInteger(_0xb83017[_0x3d760a(0x228)],-0x1*0x1984+-0x1*-0x20e1+-0x75c,TOOL_EXECUTION_LIMITS[_0x3d760a(0x209)]);return{'action':_0x226d10,'command':_0xb83017[_0x3d760a(0x234)],...typeof _0xb83017[_0x3d760a(0x1e1)]===_0x3d760a(0x1e2)?{'cwd':_0xb83017[_0x3d760a(0x1e1)]}:{},..._0x2930a9===undefined?{}:{'timeoutMs':_0x2930a9},..._0x21413c===undefined?{}:{'yieldMs':_0x21413c}};}if(typeof _0xb83017[_0x3d760a(0x1c5)]!==_0x3d760a(0x1e2)||_0xb83017[_0x3d760a(0x1c5)]==='')return invalidExecInput();if(_0x226d10===_0x3d760a(0x221))return{'action':_0x226d10,'processId':_0xb83017[_0x3d760a(0x1c5)],..._0x21413c===undefined?{}:{'yieldMs':_0x21413c}};if(_0x226d10===_0x3d760a(0x220)){if(typeof _0xb83017[_0x3d760a(0x1f0)]!==_0x3d760a(0x1e2))return invalidExecInput();return{'action':_0x226d10,'processId':_0xb83017[_0x3d760a(0x1c5)],'data':_0xb83017[_0x3d760a(0x1f0)]};}return{'action':_0x3d760a(0x241),'processId':_0xb83017[_0x3d760a(0x1c5)]};}function optionalBoundedInteger(_0x5d78ec,_0x15673f,_0x3c7688){const _0x94e582=_0x58e7c3;if(_0x5d78ec===undefined||_0x5d78ec===null)return undefined;if(!Number[_0x94e582(0x1d7)](_0x5d78ec)||_0x5d78ec<_0x15673f)invalidExecInput();return Math[_0x94e582(0x246)](_0x5d78ec,_0x3c7688);}function invalidExecInput(){const _0x4258e1=_0x58e7c3;throw new MarAgentError(_0x4258e1(0x204),_0x4258e1(0x1db));}async function waitForExitOrDelay(_0x1d131d,_0x5283cf,_0x131820){const _0x5dd61f=_0x58e7c3;if(_0x131820?.[_0x5dd61f(0x1f3)])throw executionAbortReason(_0x131820);let _0x20a61a,_0x1421aa;const _0x2329e3=new Promise((_0x2a8319,_0x341618)=>_0x1421aa=_0x341618),_0x2f7929=()=>_0x1421aa(executionAbortReason(_0x131820));_0x131820?.[_0x5dd61f(0x1f9)](_0x5dd61f(0x1e3),_0x2f7929,{'once':!![]});try{await Promise[_0x5dd61f(0x1c6)]([_0x1d131d,_0x2329e3,new Promise(_0x45b4f8=>{const _0x294360=_0x5dd61f;_0x20a61a=setTimeout(_0x45b4f8,_0x5283cf),_0x20a61a[_0x294360(0x20f)]();})]);}finally{_0x131820?.[_0x5dd61f(0x247)](_0x5dd61f(0x1e3),_0x2f7929);if(_0x20a61a)clearTimeout(_0x20a61a);}}async function waitForExit(_0x2a3265,_0x34399b){const _0x432c36=_0x58e7c3;let _0x2df944;try{return await Promise[_0x432c36(0x1c6)]([_0x2a3265[_0x432c36(0x239)](()=>!![]),new Promise(_0x1f6d53=>{const _0x1dcb77=_0x432c36;_0x2df944=setTimeout(()=>_0x1f6d53(![]),_0x34399b),_0x2df944[_0x1dcb77(0x20f)]();})]);}finally{if(_0x2df944)clearTimeout(_0x2df944);}}function notifyProcessChange(_0x3f154b){const _0x5e6ab6=_0x58e7c3;for(const _0x40244a of _0x3f154b[_0x5e6ab6(0x223)])_0x40244a();_0x3f154b[_0x5e6ab6(0x223)][_0x5e6ab6(0x20c)]();}function _0x2bfd(_0x499071,_0x2803e2){_0x499071=_0x499071-(0xee9+-0xa18+0x1*-0x314);const _0xec8ca2=_0x2211();let _0x5a6160=_0xec8ca2[_0x499071];if(_0x2bfd['asyDTe']===undefined){var _0xc41d61=function(_0x47d479){const _0x33afa1='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x3f3593='',_0x34c7f4='';for(let _0xfcb2c0=-0x2419*-0x1+-0x18b5+0x6c*-0x1b,_0x215799,_0x12fc6f,_0x4b0a7a=0x74f*0x3+-0x14f8+0x31*-0x5;_0x12fc6f=_0x47d479['charAt'](_0x4b0a7a++);~_0x12fc6f&&(_0x215799=_0xfcb2c0%(0x1373*-0x2+-0x1b1f+0x1*0x4209)?_0x215799*(-0x769+-0x114e+0x18f7)+_0x12fc6f:_0x12fc6f,_0xfcb2c0++%(0x1da*-0x13+-0x25dd*-0x1+-0x2ab))?_0x3f3593+=String['fromCharCode'](-0x1241+-0x1756+0x2a96&_0x215799>>(-(-0x8*0x63+-0xa*-0x21c+-0x11fe)*_0xfcb2c0&-0x1cce+0x8*-0x312+0xcc*0x43)):-0x232*-0xb+0x1241*0x2+0x287*-0x18){_0x12fc6f=_0x33afa1['indexOf'](_0x12fc6f);}for(let _0x31465b=-0x1ac7+0x879+0x927*0x2,_0x5d9a9c=_0x3f3593['length'];_0x31465b<_0x5d9a9c;_0x31465b++){_0x34c7f4+='%'+('00'+_0x3f3593['charCodeAt'](_0x31465b)['toString'](-0x8f1+-0x2f9+0xbfa))['slice'](-(-0x200b+-0x2529+0x4536));}return decodeURIComponent(_0x34c7f4);};_0x2bfd['WYMjFq']=_0xc41d61,_0x2bfd['AWyjPA']={},_0x2bfd['asyDTe']=!![];}const _0x438101=_0xec8ca2[0x5c7+0x1*0xb3a+0x1101*-0x1];_0x2bfd['lAtuiW']!==_0x438101&&(_0x2bfd['AWyjPA']={},_0x2bfd['lAtuiW']=_0x438101);const _0x22387a=_0x2bfd['AWyjPA'][_0x499071];return _0x22387a===undefined?(_0x5a6160=_0x2bfd['WYMjFq'](_0x5a6160),_0x2bfd['AWyjPA'][_0x499071]=_0x5a6160):_0x5a6160=_0x22387a,_0x5a6160;}async function waitForProcessChange(_0x15e1de,_0x5df446,_0x40a34d){const _0x53b92f=_0x58e7c3;if(_0x15e1de[_0x53b92f(0x1fa)]!==_0x53b92f(0x243)||_0x5df446===-0x10c3+-0x300+0x13c3)return;if(_0x40a34d?.[_0x53b92f(0x1f3)])throw executionAbortReason(_0x40a34d);let _0x195015,_0x47b189;const _0x560f10=new Promise(_0x5912fe=>_0x47b189=_0x5912fe);let _0x40d8ab;const _0x3a7d9a=new Promise((_0x3a5131,_0x44252f)=>_0x40d8ab=_0x44252f),_0x40522c=()=>_0x40d8ab(executionAbortReason(_0x40a34d));_0x15e1de[_0x53b92f(0x223)][_0x53b92f(0x1f6)](_0x47b189),_0x40a34d?.[_0x53b92f(0x1f9)](_0x53b92f(0x1e3),_0x40522c,{'once':!![]});try{await Promise[_0x53b92f(0x1c6)]([_0x560f10,_0x3a7d9a,new Promise(_0x3ca67c=>{const _0x52f5c3=_0x53b92f;_0x195015=setTimeout(_0x3ca67c,_0x5df446),_0x195015[_0x52f5c3(0x20f)]();})]);}finally{_0x15e1de[_0x53b92f(0x223)][_0x53b92f(0x23e)](_0x47b189),_0x40a34d?.[_0x53b92f(0x247)](_0x53b92f(0x1e3),_0x40522c);if(_0x195015)clearTimeout(_0x195015);}}function executionAbortReason(_0x383be7){const _0x2f6393=_0x58e7c3;return _0x383be7?.[_0x2f6393(0x1f2)]??new MarAgentError(_0x2f6393(0x24d),_0x2f6393(0x22d));}
|
|
1
|
+
import { directLocalProcessExecutor, signalProcessTree } from '../host/local-process-executor.js';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { StringDecoder } from 'node:string_decoder';
|
|
4
|
+
import { MarAgentError } from '../error.js';
|
|
5
|
+
import { TOOL_EXECUTION_LIMITS } from './execution-limits.js';
|
|
6
|
+
export const execToolDefinition = {
|
|
7
|
+
name: 'exec',
|
|
8
|
+
parallelSafety: 'serial',
|
|
9
|
+
description: 'Unrestricted general system execution. start runs any platform-native command, script, text/file tool, builder, generator, network client, or program in workspace/default cwd and may return running with processId; poll waits up to yieldMs for new output or termination and returns only output produced since the prior result; write sends stdin; cancel terminates the process tree. Returns status, processId, incremental stdout/stderr, cumulative stdoutBytes/stderrBytes, per-result dropped bytes, exitCode, and truncated; a completed status does not imply exitCode 0. Always inspect stderr/exitCode and consume terminal output or cancel.',
|
|
10
|
+
outputSchema: {
|
|
11
|
+
type: 'object',
|
|
12
|
+
required: ['content', 'data'],
|
|
13
|
+
properties: {
|
|
14
|
+
content: { type: 'string' },
|
|
15
|
+
data: {
|
|
16
|
+
type: 'object',
|
|
17
|
+
required: [
|
|
18
|
+
'status',
|
|
19
|
+
'stdout',
|
|
20
|
+
'stderr',
|
|
21
|
+
'truncated',
|
|
22
|
+
'stdoutBytes',
|
|
23
|
+
'stderrBytes',
|
|
24
|
+
'stdoutDroppedBytes',
|
|
25
|
+
'stderrDroppedBytes'
|
|
26
|
+
],
|
|
27
|
+
properties: {
|
|
28
|
+
status: { enum: ['running', 'completed', 'cancelled'] },
|
|
29
|
+
processId: { type: 'string' },
|
|
30
|
+
stdout: { type: 'string' },
|
|
31
|
+
stderr: { type: 'string' },
|
|
32
|
+
exitCode: { type: ['number', 'null'] },
|
|
33
|
+
truncated: { type: 'boolean' },
|
|
34
|
+
stdoutBytes: { type: 'number' },
|
|
35
|
+
stderrBytes: { type: 'number' },
|
|
36
|
+
stdoutDroppedBytes: { type: 'number' },
|
|
37
|
+
stderrDroppedBytes: { type: 'number' }
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
inputSchema: {
|
|
43
|
+
type: 'object',
|
|
44
|
+
properties: {
|
|
45
|
+
action: { enum: ['start', 'poll', 'write', 'cancel'], description: 'Lifecycle operation.' },
|
|
46
|
+
command: { type: 'string', description: 'Required only for start.' },
|
|
47
|
+
cwd: {
|
|
48
|
+
type: 'string',
|
|
49
|
+
description: 'Optional relative/absolute start directory; defaults to workspace.'
|
|
50
|
+
},
|
|
51
|
+
timeoutMs: { type: 'integer', minimum: 1, maximum: TOOL_EXECUTION_LIMITS.execMaxTimeoutMs },
|
|
52
|
+
yieldMs: {
|
|
53
|
+
type: 'integer',
|
|
54
|
+
minimum: 0,
|
|
55
|
+
maximum: TOOL_EXECUTION_LIMITS.execMaxYieldMs,
|
|
56
|
+
default: TOOL_EXECUTION_LIMITS.execDefaultYieldMs,
|
|
57
|
+
description: `Wait before yielding output. Defaults to ${TOOL_EXECUTION_LIMITS.execDefaultYieldMs} ms; effective range is 0-${TOOL_EXECUTION_LIMITS.execMaxYieldMs} ms.`
|
|
58
|
+
},
|
|
59
|
+
processId: { type: 'string', description: 'Required for poll, write and cancel.' },
|
|
60
|
+
data: { type: 'string', description: 'stdin data required for write.' }
|
|
61
|
+
},
|
|
62
|
+
required: ['action'],
|
|
63
|
+
additionalProperties: false
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
export class ExecTool {
|
|
67
|
+
paths;
|
|
68
|
+
maxOutputBytes;
|
|
69
|
+
maxProcesses;
|
|
70
|
+
environment;
|
|
71
|
+
shell;
|
|
72
|
+
processExecutor;
|
|
73
|
+
#processes = new Map();
|
|
74
|
+
constructor(paths, maxOutputBytes = TOOL_EXECUTION_LIMITS.execDefaultMaxOutputBytes, maxProcesses = TOOL_EXECUTION_LIMITS.maxProcesses, environment = process.env, shell, processExecutor = directLocalProcessExecutor) {
|
|
75
|
+
this.paths = paths;
|
|
76
|
+
this.maxOutputBytes = maxOutputBytes;
|
|
77
|
+
this.maxProcesses = maxProcesses;
|
|
78
|
+
this.environment = environment;
|
|
79
|
+
this.shell = shell;
|
|
80
|
+
this.processExecutor = processExecutor;
|
|
81
|
+
}
|
|
82
|
+
async execute(arguments_, signal, owner) {
|
|
83
|
+
if (signal?.aborted)
|
|
84
|
+
throw executionAbortReason(signal);
|
|
85
|
+
const input = parseExecInput(arguments_);
|
|
86
|
+
if (input.action !== 'start') {
|
|
87
|
+
const process = this.#processes.get(input.processId);
|
|
88
|
+
if (!process || (owner !== undefined && process.ownerSessionId !== owner.sessionId))
|
|
89
|
+
throw new MarAgentError('MAR_AGENT_PROCESS_NOT_FOUND', 'Managed process was not found.');
|
|
90
|
+
if (input.action === 'poll' && input.yieldMs)
|
|
91
|
+
await waitForProcessChange(process, Math.min(Math.max(input.yieldMs, 0), TOOL_EXECUTION_LIMITS.execMaxYieldMs), signal);
|
|
92
|
+
if (input.action === 'write')
|
|
93
|
+
process.child.stdin.write(input.data);
|
|
94
|
+
if (input.action === 'cancel')
|
|
95
|
+
await this.#terminate(process, true);
|
|
96
|
+
const result = this.#result(input.processId, process);
|
|
97
|
+
if (process.status !== 'running')
|
|
98
|
+
this.#processes.delete(input.processId);
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
if (this.#processes.size >= this.maxProcesses)
|
|
102
|
+
throw new MarAgentError('MAR_AGENT_PROCESS_LIMIT', 'The managed process limit was reached.');
|
|
103
|
+
const id = randomUUID();
|
|
104
|
+
const cwd = await this.paths.resolveWithDisplay(input.cwd ?? '.');
|
|
105
|
+
const child = await this.processExecutor.spawn({
|
|
106
|
+
command: input.command,
|
|
107
|
+
cwd: cwd.physicalPath,
|
|
108
|
+
shell: this.shell ?? true,
|
|
109
|
+
environment: this.environment,
|
|
110
|
+
detached: process.platform !== 'win32',
|
|
111
|
+
...(owner === undefined ? {} : { owner }),
|
|
112
|
+
...(signal === undefined ? {} : { signal })
|
|
113
|
+
});
|
|
114
|
+
let resolveExited;
|
|
115
|
+
let resolveSettled;
|
|
116
|
+
const managed = {
|
|
117
|
+
child,
|
|
118
|
+
...(owner === undefined ? {} : { ownerSessionId: owner.sessionId }),
|
|
119
|
+
command: input.command,
|
|
120
|
+
cwd: cwd.displayPath,
|
|
121
|
+
stdout: createOutputBuffer(),
|
|
122
|
+
stderr: createOutputBuffer(),
|
|
123
|
+
status: 'running',
|
|
124
|
+
exited: new Promise((resolve) => (resolveExited = resolve)),
|
|
125
|
+
settled: new Promise((resolve) => (resolveSettled = resolve)),
|
|
126
|
+
resolveExited,
|
|
127
|
+
resolveSettled,
|
|
128
|
+
exitObserved: child.exitCode !== null,
|
|
129
|
+
finalized: false,
|
|
130
|
+
waiters: new Set()
|
|
131
|
+
};
|
|
132
|
+
this.#processes.set(id, managed);
|
|
133
|
+
child.stdout.on('data', (chunk) => {
|
|
134
|
+
if (managed.finalized)
|
|
135
|
+
return;
|
|
136
|
+
appendOutput(managed.stdout, Buffer.from(managed.stdout.decoder.write(chunk)), this.maxOutputBytes, chunk.length);
|
|
137
|
+
notifyProcessChange(managed);
|
|
138
|
+
});
|
|
139
|
+
child.stderr.on('data', (chunk) => {
|
|
140
|
+
if (managed.finalized)
|
|
141
|
+
return;
|
|
142
|
+
appendOutput(managed.stderr, Buffer.from(managed.stderr.decoder.write(chunk)), this.maxOutputBytes, chunk.length);
|
|
143
|
+
notifyProcessChange(managed);
|
|
144
|
+
});
|
|
145
|
+
child.once('exit', (code) => {
|
|
146
|
+
managed.exitObserved = true;
|
|
147
|
+
managed.exitCode = code;
|
|
148
|
+
managed.resolveExited();
|
|
149
|
+
void finalizeAfterOutputGrace(managed, this.maxOutputBytes);
|
|
150
|
+
});
|
|
151
|
+
child.once('close', (code) => {
|
|
152
|
+
managed.exitObserved = true;
|
|
153
|
+
managed.resolveExited();
|
|
154
|
+
finalizeManagedProcess(managed, this.maxOutputBytes, code);
|
|
155
|
+
});
|
|
156
|
+
child.once('error', (error) => {
|
|
157
|
+
if (managed.finalized)
|
|
158
|
+
return;
|
|
159
|
+
appendOutput(managed.stderr, Buffer.from(error.message), this.maxOutputBytes);
|
|
160
|
+
notifyProcessChange(managed);
|
|
161
|
+
});
|
|
162
|
+
managed.timer = setTimeout(() => {
|
|
163
|
+
void this.#terminate(managed, true);
|
|
164
|
+
}, Math.min(input.timeoutMs ?? TOOL_EXECUTION_LIMITS.execDefaultTimeoutMs, TOOL_EXECUTION_LIMITS.execMaxTimeoutMs));
|
|
165
|
+
managed.timer.unref();
|
|
166
|
+
await waitForExitOrDelay(managed.settled, Math.min(input.yieldMs ?? TOOL_EXECUTION_LIMITS.execDefaultYieldMs, TOOL_EXECUTION_LIMITS.execMaxYieldMs), signal);
|
|
167
|
+
const result = this.#result(id, managed);
|
|
168
|
+
if (managed.status !== 'running')
|
|
169
|
+
this.#processes.delete(id);
|
|
170
|
+
return result;
|
|
171
|
+
}
|
|
172
|
+
listSessionResources(sessionId) {
|
|
173
|
+
return [...this.#processes.entries()].flatMap(([processId, process]) => process.ownerSessionId === sessionId
|
|
174
|
+
? [
|
|
175
|
+
{
|
|
176
|
+
processId,
|
|
177
|
+
status: process.status,
|
|
178
|
+
command: process.command,
|
|
179
|
+
cwd: process.cwd
|
|
180
|
+
}
|
|
181
|
+
]
|
|
182
|
+
: []);
|
|
183
|
+
}
|
|
184
|
+
async disposeSession(sessionId) {
|
|
185
|
+
const owned = [...this.#processes.entries()].filter(([, process]) => process.ownerSessionId === sessionId);
|
|
186
|
+
await Promise.all(owned.map(([, process]) => process.status === 'running' ? this.#terminate(process, false) : process.settled));
|
|
187
|
+
for (const [processId] of owned)
|
|
188
|
+
this.#processes.delete(processId);
|
|
189
|
+
}
|
|
190
|
+
async #terminate(managed, waitForOutputClose) {
|
|
191
|
+
if (managed.terminate)
|
|
192
|
+
return managed.terminate;
|
|
193
|
+
managed.terminate = (async () => {
|
|
194
|
+
if (managed.exitObserved || managed.child.exitCode !== null) {
|
|
195
|
+
if (managed.child.exitCode !== null)
|
|
196
|
+
managed.exitCode = managed.child.exitCode;
|
|
197
|
+
if (waitForOutputClose) {
|
|
198
|
+
const settled = await waitForExit(managed.settled, TOOL_EXECUTION_LIMITS.execTerminationGraceMs);
|
|
199
|
+
if (settled)
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
finalizeManagedProcess(managed, this.maxOutputBytes, managed.child.exitCode);
|
|
203
|
+
destroyManagedStreams(managed);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
managed.status = 'cancelled';
|
|
207
|
+
if (managed.timer)
|
|
208
|
+
clearTimeout(managed.timer);
|
|
209
|
+
await signalProcessTree(managed.child, 'SIGTERM');
|
|
210
|
+
const exited = await waitForExit(managed.exited, TOOL_EXECUTION_LIMITS.execTerminationGraceMs);
|
|
211
|
+
if (!exited) {
|
|
212
|
+
await signalProcessTree(managed.child, 'SIGKILL');
|
|
213
|
+
await managed.exited;
|
|
214
|
+
}
|
|
215
|
+
if (waitForOutputClose) {
|
|
216
|
+
const settled = await waitForExit(managed.settled, TOOL_EXECUTION_LIMITS.execTerminationGraceMs);
|
|
217
|
+
if (settled)
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
finalizeManagedProcess(managed, this.maxOutputBytes, managed.exitCode);
|
|
221
|
+
destroyManagedStreams(managed);
|
|
222
|
+
})();
|
|
223
|
+
return managed.terminate;
|
|
224
|
+
}
|
|
225
|
+
#result(id, process) {
|
|
226
|
+
const stdout = consumeOutput(process.stdout);
|
|
227
|
+
const stderr = consumeOutput(process.stderr);
|
|
228
|
+
return {
|
|
229
|
+
status: process.status,
|
|
230
|
+
...(process.status === 'running' ? { processId: id } : {}),
|
|
231
|
+
stdout: stdout.value,
|
|
232
|
+
stderr: stderr.value,
|
|
233
|
+
...(process.exitCode === undefined ? {} : { exitCode: process.exitCode }),
|
|
234
|
+
truncated: stdout.droppedBytes > 0 || stderr.droppedBytes > 0,
|
|
235
|
+
stdoutBytes: process.stdout.totalBytes,
|
|
236
|
+
stderrBytes: process.stderr.totalBytes,
|
|
237
|
+
stdoutDroppedBytes: stdout.droppedBytes,
|
|
238
|
+
stderrDroppedBytes: stderr.droppedBytes
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
async dispose() {
|
|
242
|
+
await Promise.all([...this.#processes.values()].map((process) => process.status === 'running' ? this.#terminate(process, false) : process.settled));
|
|
243
|
+
this.#processes.clear();
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
function createOutputBuffer() {
|
|
247
|
+
return {
|
|
248
|
+
chunks: [],
|
|
249
|
+
bytes: 0,
|
|
250
|
+
totalBytes: 0,
|
|
251
|
+
droppedBytes: 0,
|
|
252
|
+
windowOffset: 0,
|
|
253
|
+
decoder: new StringDecoder('utf8')
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
function finalizeManagedProcess(managed, maximumOutputBytes, exitCode) {
|
|
257
|
+
if (managed.finalized)
|
|
258
|
+
return;
|
|
259
|
+
managed.finalized = true;
|
|
260
|
+
appendOutput(managed.stdout, Buffer.from(managed.stdout.decoder.end()), maximumOutputBytes);
|
|
261
|
+
appendOutput(managed.stderr, Buffer.from(managed.stderr.decoder.end()), maximumOutputBytes);
|
|
262
|
+
managed.status = managed.status === 'cancelled' ? 'cancelled' : 'completed';
|
|
263
|
+
if (exitCode !== undefined)
|
|
264
|
+
managed.exitCode = exitCode;
|
|
265
|
+
if (managed.timer)
|
|
266
|
+
clearTimeout(managed.timer);
|
|
267
|
+
notifyProcessChange(managed);
|
|
268
|
+
managed.resolveSettled();
|
|
269
|
+
}
|
|
270
|
+
async function finalizeAfterOutputGrace(managed, maximumOutputBytes) {
|
|
271
|
+
const settled = await waitForExit(managed.settled, TOOL_EXECUTION_LIMITS.execTerminationGraceMs);
|
|
272
|
+
if (settled)
|
|
273
|
+
return;
|
|
274
|
+
finalizeManagedProcess(managed, maximumOutputBytes, managed.exitCode);
|
|
275
|
+
destroyManagedStreams(managed);
|
|
276
|
+
}
|
|
277
|
+
function destroyManagedStreams(managed) {
|
|
278
|
+
managed.child.stdin.destroy();
|
|
279
|
+
managed.child.stdout.destroy();
|
|
280
|
+
managed.child.stderr.destroy();
|
|
281
|
+
}
|
|
282
|
+
function appendOutput(output, chunk, maximumBytes, receivedBytes = chunk.length) {
|
|
283
|
+
output.totalBytes += receivedBytes;
|
|
284
|
+
if (!chunk.length)
|
|
285
|
+
return;
|
|
286
|
+
output.chunks.push(chunk);
|
|
287
|
+
output.bytes += chunk.length;
|
|
288
|
+
// Retain the oldest and newest halves symmetrically so early failures stay
|
|
289
|
+
// visible next to the latest progress; droppedBytes makes the discarded
|
|
290
|
+
// middle explicit because it is not recoverable from this bounded buffer.
|
|
291
|
+
const overflow = output.bytes - maximumBytes;
|
|
292
|
+
if (overflow <= 0)
|
|
293
|
+
return;
|
|
294
|
+
const head = Math.ceil(maximumBytes / 2);
|
|
295
|
+
// Materialize the current window once per overflow so subsequent appends slice
|
|
296
|
+
// it zero-copy instead of re-concatenating the whole retained buffer per chunk.
|
|
297
|
+
let span = output.window;
|
|
298
|
+
if (!span || output.bytes !== span.length - output.windowOffset) {
|
|
299
|
+
span = Buffer.concat(output.chunks, output.bytes);
|
|
300
|
+
output.windowOffset = 0;
|
|
301
|
+
}
|
|
302
|
+
const content = span.subarray(output.windowOffset, output.windowOffset + output.bytes);
|
|
303
|
+
output.chunks = [];
|
|
304
|
+
output.bytes = 0;
|
|
305
|
+
output.droppedBytes += overflow;
|
|
306
|
+
const pushSlice = (start, end) => {
|
|
307
|
+
while (start < end && (content[start] & 0xc0) === 0x80)
|
|
308
|
+
start++;
|
|
309
|
+
while (end > start && (content[end - 1] & 0xc0) === 0x80)
|
|
310
|
+
end--;
|
|
311
|
+
if (start >= end)
|
|
312
|
+
return;
|
|
313
|
+
const slice = content.subarray(start, end);
|
|
314
|
+
output.chunks.push(slice);
|
|
315
|
+
output.bytes += slice.length;
|
|
316
|
+
};
|
|
317
|
+
pushSlice(0, Math.min(head, content.length));
|
|
318
|
+
pushSlice(Math.min(head + overflow, content.length), content.length);
|
|
319
|
+
output.window = span;
|
|
320
|
+
}
|
|
321
|
+
function consumeOutput(output) {
|
|
322
|
+
const value = Buffer.concat(output.chunks, output.bytes).toString('utf8');
|
|
323
|
+
const droppedBytes = output.droppedBytes;
|
|
324
|
+
output.chunks = [];
|
|
325
|
+
output.bytes = 0;
|
|
326
|
+
output.droppedBytes = 0;
|
|
327
|
+
delete output.window;
|
|
328
|
+
output.windowOffset = 0;
|
|
329
|
+
return { value, droppedBytes };
|
|
330
|
+
}
|
|
331
|
+
function parseExecInput(value) {
|
|
332
|
+
if (!value || typeof value !== 'object')
|
|
333
|
+
return invalidExecInput();
|
|
334
|
+
const input = value;
|
|
335
|
+
const action = input.action;
|
|
336
|
+
if (!['start', 'poll', 'write', 'cancel'].includes(String(action)))
|
|
337
|
+
return invalidExecInput();
|
|
338
|
+
const yieldMs = optionalBoundedInteger(input.yieldMs, 0, TOOL_EXECUTION_LIMITS.execMaxYieldMs);
|
|
339
|
+
if (action === 'start') {
|
|
340
|
+
if (typeof input.command !== 'string' || input.command.trim() === '')
|
|
341
|
+
return invalidExecInput();
|
|
342
|
+
if (input.cwd !== undefined && input.cwd !== null && typeof input.cwd !== 'string')
|
|
343
|
+
return invalidExecInput();
|
|
344
|
+
const timeoutMs = optionalBoundedInteger(input.timeoutMs, 1, TOOL_EXECUTION_LIMITS.execMaxTimeoutMs);
|
|
345
|
+
return {
|
|
346
|
+
action,
|
|
347
|
+
command: input.command,
|
|
348
|
+
...(typeof input.cwd === 'string' ? { cwd: input.cwd } : {}),
|
|
349
|
+
...(timeoutMs === undefined ? {} : { timeoutMs }),
|
|
350
|
+
...(yieldMs === undefined ? {} : { yieldMs })
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
if (typeof input.processId !== 'string' || input.processId === '')
|
|
354
|
+
return invalidExecInput();
|
|
355
|
+
if (action === 'poll')
|
|
356
|
+
return {
|
|
357
|
+
action,
|
|
358
|
+
processId: input.processId,
|
|
359
|
+
...(yieldMs === undefined ? {} : { yieldMs })
|
|
360
|
+
};
|
|
361
|
+
if (action === 'write') {
|
|
362
|
+
if (typeof input.data !== 'string')
|
|
363
|
+
return invalidExecInput();
|
|
364
|
+
return { action, processId: input.processId, data: input.data };
|
|
365
|
+
}
|
|
366
|
+
return { action: 'cancel', processId: input.processId };
|
|
367
|
+
}
|
|
368
|
+
function optionalBoundedInteger(value, minimum, maximum) {
|
|
369
|
+
if (value === undefined || value === null)
|
|
370
|
+
return undefined;
|
|
371
|
+
if (!Number.isInteger(value) || value < minimum)
|
|
372
|
+
invalidExecInput();
|
|
373
|
+
return Math.min(value, maximum);
|
|
374
|
+
}
|
|
375
|
+
function invalidExecInput() {
|
|
376
|
+
throw new MarAgentError('MAR_AGENT_TOOL_INPUT_INVALID', 'Exec input is invalid.');
|
|
377
|
+
}
|
|
378
|
+
async function waitForExitOrDelay(exited, delayMs, signal) {
|
|
379
|
+
if (signal?.aborted)
|
|
380
|
+
throw executionAbortReason(signal);
|
|
381
|
+
let timer;
|
|
382
|
+
let rejectAbort;
|
|
383
|
+
const aborted = new Promise((_resolve, reject) => (rejectAbort = reject));
|
|
384
|
+
const abort = () => rejectAbort(executionAbortReason(signal));
|
|
385
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
386
|
+
try {
|
|
387
|
+
await Promise.race([
|
|
388
|
+
exited,
|
|
389
|
+
aborted,
|
|
390
|
+
new Promise((resolve) => {
|
|
391
|
+
timer = setTimeout(resolve, delayMs);
|
|
392
|
+
timer.unref();
|
|
393
|
+
})
|
|
394
|
+
]);
|
|
395
|
+
}
|
|
396
|
+
finally {
|
|
397
|
+
signal?.removeEventListener('abort', abort);
|
|
398
|
+
if (timer)
|
|
399
|
+
clearTimeout(timer);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
async function waitForExit(exited, delayMs) {
|
|
403
|
+
let timer;
|
|
404
|
+
try {
|
|
405
|
+
return await Promise.race([
|
|
406
|
+
exited.then(() => true),
|
|
407
|
+
new Promise((resolve) => {
|
|
408
|
+
timer = setTimeout(() => resolve(false), delayMs);
|
|
409
|
+
timer.unref();
|
|
410
|
+
})
|
|
411
|
+
]);
|
|
412
|
+
}
|
|
413
|
+
finally {
|
|
414
|
+
if (timer)
|
|
415
|
+
clearTimeout(timer);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
function notifyProcessChange(managed) {
|
|
419
|
+
for (const resolve of managed.waiters)
|
|
420
|
+
resolve();
|
|
421
|
+
managed.waiters.clear();
|
|
422
|
+
}
|
|
423
|
+
async function waitForProcessChange(managed, waitMs, signal) {
|
|
424
|
+
if (managed.status !== 'running' || waitMs === 0)
|
|
425
|
+
return;
|
|
426
|
+
if (signal?.aborted)
|
|
427
|
+
throw executionAbortReason(signal);
|
|
428
|
+
let timer;
|
|
429
|
+
let resolveChange;
|
|
430
|
+
const changed = new Promise((resolve) => (resolveChange = resolve));
|
|
431
|
+
let rejectAbort;
|
|
432
|
+
const aborted = new Promise((_resolve, reject) => (rejectAbort = reject));
|
|
433
|
+
const abort = () => rejectAbort(executionAbortReason(signal));
|
|
434
|
+
managed.waiters.add(resolveChange);
|
|
435
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
436
|
+
try {
|
|
437
|
+
await Promise.race([
|
|
438
|
+
changed,
|
|
439
|
+
aborted,
|
|
440
|
+
new Promise((resolve) => {
|
|
441
|
+
timer = setTimeout(resolve, waitMs);
|
|
442
|
+
timer.unref();
|
|
443
|
+
})
|
|
444
|
+
]);
|
|
445
|
+
}
|
|
446
|
+
finally {
|
|
447
|
+
managed.waiters.delete(resolveChange);
|
|
448
|
+
signal?.removeEventListener('abort', abort);
|
|
449
|
+
if (timer)
|
|
450
|
+
clearTimeout(timer);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
function executionAbortReason(signal) {
|
|
454
|
+
return (signal?.reason ?? new MarAgentError('MAR_AGENT_EXECUTION_CANCELLED', 'Execution cancelled.'));
|
|
455
|
+
}
|
|
@@ -31,6 +31,7 @@ export declare const TOOL_EXECUTION_LIMITS: Readonly<{
|
|
|
31
31
|
agentWaitMaxWaitMs: 300000;
|
|
32
32
|
subagentDescriptionMaxCharacters: 80;
|
|
33
33
|
subagentPromptMaxBytes: 131072;
|
|
34
|
+
subagentMessageMaxBytes: 131072;
|
|
34
35
|
subagentReasoningEffortMaxCharacters: 64;
|
|
35
36
|
subagentSummaryMaxBytes: 16384;
|
|
36
37
|
subagentEvidenceMaxItems: 64;
|
|
@@ -1,2 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export const TOOL_EXECUTION_LIMITS = Object.freeze({
|
|
2
|
+
readDefaultLines: 200,
|
|
3
|
+
readMaxLines: 2_000,
|
|
4
|
+
readMaxBytes: 1_048_576,
|
|
5
|
+
readMaxBatchItems: 16,
|
|
6
|
+
readBatchConcurrency: 4,
|
|
7
|
+
readMaxBatchBytes: 4_194_304,
|
|
8
|
+
viewImageMaxBytes: 20_971_520,
|
|
9
|
+
execDefaultTimeoutMs: 120_000,
|
|
10
|
+
execMaxTimeoutMs: 3_600_000,
|
|
11
|
+
execDefaultYieldMs: 10_000,
|
|
12
|
+
execMaxYieldMs: 30_000,
|
|
13
|
+
execTerminationGraceMs: 1_000,
|
|
14
|
+
execDefaultMaxOutputBytes: 1_000_000,
|
|
15
|
+
maxProcesses: 8,
|
|
16
|
+
codeMaxInputBytes: 1_048_576,
|
|
17
|
+
codeMaxOutputBytes: 1_048_576,
|
|
18
|
+
codeMaxFrameBytes: 33_554_432,
|
|
19
|
+
codeMaxTransportBytes: 67_108_864,
|
|
20
|
+
codeMaxCalls: 128,
|
|
21
|
+
codeMaxConcurrentCells: 4,
|
|
22
|
+
codeHeapMegabytes: 128,
|
|
23
|
+
codeTimeoutMs: 120_000,
|
|
24
|
+
patchMaxBytes: 4_194_304,
|
|
25
|
+
patchMaxFiles: 100,
|
|
26
|
+
patchMaxFileBytes: 8_388_608,
|
|
27
|
+
patchMaxTotalBytes: 33_554_432,
|
|
28
|
+
agentWaitMinWaitMs: 0,
|
|
29
|
+
agentWaitWaitFloorMs: 10_000,
|
|
30
|
+
agentWaitDefaultWaitMs: 30_000,
|
|
31
|
+
agentWaitMaxWaitMs: 300_000,
|
|
32
|
+
subagentDescriptionMaxCharacters: 80,
|
|
33
|
+
subagentPromptMaxBytes: 131_072,
|
|
34
|
+
subagentMessageMaxBytes: 131_072,
|
|
35
|
+
subagentReasoningEffortMaxCharacters: 64,
|
|
36
|
+
subagentSummaryMaxBytes: 16_384,
|
|
37
|
+
subagentEvidenceMaxItems: 64,
|
|
38
|
+
subagentVerificationMaxItems: 16,
|
|
39
|
+
subagentChangedFilesMaxItems: 200,
|
|
40
|
+
questionMaxTextCharacters: 1_000,
|
|
41
|
+
questionMaxOptionCharacters: 500,
|
|
42
|
+
todoMaxItems: 100,
|
|
43
|
+
todoMaxTextCharacters: 1_000
|
|
44
|
+
});
|