@nuvin/agent-core 0.2.0-rc.3 → 0.2.0-rc.5

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.
@@ -0,0 +1,5 @@
1
+ export interface AbortAwareSemaphore {
2
+ acquire(signal?: AbortSignal): Promise<() => void>;
3
+ }
4
+ export declare function createAbortAwareSemaphore(maxConcurrency: number): AbortAwareSemaphore;
5
+ //# sourceMappingURL=abort-aware-semaphore.d.ts.map
@@ -1,4 +1,5 @@
1
1
  export * from "./abort.ts";
2
+ export * from "./abort-aware-semaphore.ts";
2
3
  export * from "./model-identity.ts";
3
4
  export * from "./reasoning-config.ts";
4
5
  export * from "./turn-failed.ts";
@@ -1 +1 @@
1
- (function(_0x52d6a9,_0x19b009){var _0x1af99f={_0x5f604f:0x187,_0x5b8d97:0x184,_0x143e9d:0xca,_0x571f70:0xc9,_0x5a51c1:0xc8,_0x29b68e:0xca,_0x3899cb:0xd3,_0x184fd0:0xd0,_0xff9145:0xcb,_0x8c15cd:0x189,_0x3a3656:0x18a,_0x161592:0x18d,_0x583c86:0x185,_0x2fd984:0x180,_0x31c6f1:0x188,_0x561f84:0xc9},_0x3ea0bf=_0x52d6a9();function _0x17f373(_0x395d31,_0x424fa5,_0x5c23f4,_0x408dee){return _0x4cd4(_0x424fa5- -0x325,_0x395d31);}function _0x4eada4(_0x275509,_0x44c80a,_0x59dfe2,_0x63b107){return _0x4cd4(_0x59dfe2- -0xcf,_0x63b107);}while(!![]){try{var _0x100239=-parseInt(_0x17f373(-0x182,-_0x1af99f._0x5f604f,-0x188,-_0x1af99f._0x5b8d97))/0x1+parseInt(_0x4eada4(_0x1af99f._0x143e9d,_0x1af99f._0x571f70,_0x1af99f._0x5a51c1,0xc6))/0x2+parseInt(_0x4eada4(0xc8,0xc6,_0x1af99f._0x29b68e,0xcc))/0x3*(parseInt(_0x4eada4(0xd5,_0x1af99f._0x3899cb,_0x1af99f._0x184fd0,_0x1af99f._0xff9145))/0x4)+-parseInt(_0x17f373(-0x184,-_0x1af99f._0x8c15cd,-0x187,-0x184))/0x5*(-parseInt(_0x17f373(-0x189,-_0x1af99f._0x3a3656,-_0x1af99f._0x161592,-0x189))/0x6)+-parseInt(_0x17f373(-0x183,-_0x1af99f._0x583c86,-_0x1af99f._0x2fd984,-0x186))/0x7*(parseInt(_0x17f373(-0x189,-0x18b,-_0x1af99f._0x5f604f,-0x18e))/0x8)+parseInt(_0x17f373(-0x186,-_0x1af99f._0x31c6f1,-0x189,-_0x1af99f._0x5f604f))/0x9+-parseInt(_0x4eada4(0xca,0xca,_0x1af99f._0x561f84,0xcb))/0xa;if(_0x100239===_0x19b009)break;else _0x3ea0bf['push'](_0x3ea0bf['shift']());}catch(_0x595eb2){_0x3ea0bf['push'](_0x3ea0bf['shift']());}}}(_0xae9d,0x93226));function _0xae9d(){var _0x2450e2=['nJqWmteYvNH5shLz','odKWotaWzvHQswT0','m0LAqxznBa','ndCYnJiZmMjQsgvPCq','nNvhtwDpAa','mtG3mte1mhjVsNj6Da','mtaZndq3mtDxs1fpsxu','odq1ndqWwLLwEMnb','mZuWmdiWneLIuhDkDa','mtr3wu1jrNC'];_0xae9d=function(){return _0x2450e2;};return _0xae9d();}import{modelIdentityFromParts}from'../chunk-D5IVWJHX.js';import{resolveAnthropicReasoningConfig,resolveOpenAiReasoningConfig}from'../chunk-IUZALP6K.js';function _0x4cd4(_0x3c3a66,_0xd56804){_0x3c3a66=_0x3c3a66-0x197;var _0xae9db=_0xae9d();var _0x4cd407=_0xae9db[_0x3c3a66];if(_0x4cd4['mVxHgH']===undefined){var _0x55cea6=function(_0x2f0f7b){var _0x5bec90='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';var _0x3544ab='',_0xe3ed64='';for(var _0x3c5953=0x0,_0x524d85,_0x3e7deb,_0xf31e2=0x0;_0x3e7deb=_0x2f0f7b['charAt'](_0xf31e2++);~_0x3e7deb&&(_0x524d85=_0x3c5953%0x4?_0x524d85*0x40+_0x3e7deb:_0x3e7deb,_0x3c5953++%0x4)?_0x3544ab+=String['fromCharCode'](0xff&_0x524d85>>(-0x2*_0x3c5953&0x6)):0x0){_0x3e7deb=_0x5bec90['indexOf'](_0x3e7deb);}for(var _0x5d27dd=0x0,_0x2e0a18=_0x3544ab['length'];_0x5d27dd<_0x2e0a18;_0x5d27dd++){_0xe3ed64+='%'+('00'+_0x3544ab['charCodeAt'](_0x5d27dd)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0xe3ed64);};_0x4cd4['yrhrFk']=_0x55cea6,_0x4cd4['mnLfiT']={},_0x4cd4['mVxHgH']=!![];}var _0x31c2f8=_0xae9db[0x0],_0x15c899=_0x3c3a66+_0x31c2f8,_0x9418c7=_0x4cd4['mnLfiT'][_0x15c899];return!_0x9418c7?(_0x4cd407=_0x4cd4['yrhrFk'](_0x4cd407),_0x4cd4['mnLfiT'][_0x15c899]=_0x4cd407):_0x4cd407=_0x9418c7,_0x4cd407;}import{TurnFailedError}from'../chunk-FFIZ6TKW.js';import{OperationAbortedError,addAbortListener,isAbortError,throwIfAborted,toAbortError}from'../chunk-X7VAACWY.js';export{OperationAbortedError,TurnFailedError,addAbortListener,isAbortError,modelIdentityFromParts,resolveAnthropicReasoningConfig,resolveOpenAiReasoningConfig,throwIfAborted,toAbortError};
1
+ (function(_0x25cab3,_0x1f42ea){const _0x14a2a9={_0x2bb1db:0x38d,_0x502744:0x1f,_0x50e78f:0x19,_0x9b5a2a:0x1c,_0x3f93d5:0x1b,_0x174492:0x21,_0xd3573e:0xb,_0x442376:0x3,_0x3abdee:0x389,_0x26b90e:0x4,_0x5361be:0x9,_0xb2409b:0x6,_0x4712cc:0x39a,_0x372c83:0x15,_0x2d6b44:0x19,_0x5df508:0x397,_0x1e7783:0x38b,_0x215a75:0x24,_0x32b6c4:0x1d,_0x5918a8:0x398,_0x25ff60:0x3a2,_0x1b1b4b:0x39e},_0x17b679={_0x43a604:0x1f0},_0x52b0d1={_0x316cab:0x1b5};function _0x2f7435(_0x58df2c,_0x5e7da7,_0x4a2e9e,_0x394c6a){return _0x230d(_0x4a2e9e- -_0x52b0d1._0x316cab,_0x5e7da7);}function _0x12fd50(_0x2a4471,_0x527ef8,_0x198c09,_0x2cbe08){return _0x230d(_0x2a4471-_0x17b679._0x43a604,_0x527ef8);}const _0x3a06a4=_0x25cab3();while(!![]){try{const _0x12449f=parseInt(_0x12fd50(_0x14a2a9._0x2bb1db,0x389,0x38b,0x397))/0x1*(-parseInt(_0x2f7435(-_0x14a2a9._0x502744,-0xf,-0x16,-_0x14a2a9._0x50e78f))/0x2)+parseInt(_0x2f7435(-0x10,-_0x14a2a9._0x9b5a2a,-_0x14a2a9._0x3f93d5,-_0x14a2a9._0x174492))/0x3+-parseInt(_0x2f7435(-_0x14a2a9._0xd3573e,-_0x14a2a9._0xd3573e,-0xb,-_0x14a2a9._0x442376))/0x4+-parseInt(_0x12fd50(0x38e,0x393,0x38d,_0x14a2a9._0x3abdee))/0x5*(-parseInt(_0x2f7435(-_0x14a2a9._0x26b90e,-_0x14a2a9._0x5361be,-0xe,-_0x14a2a9._0xb2409b))/0x6)+-parseInt(_0x12fd50(0x396,_0x14a2a9._0x4712cc,0x38d,0x39d))/0x7+-parseInt(_0x2f7435(-0x22,-_0x14a2a9._0x372c83,-_0x14a2a9._0x2d6b44,-0x15))/0x8*(-parseInt(_0x12fd50(0x395,_0x14a2a9._0x5df508,_0x14a2a9._0x1e7783,0x394))/0x9)+parseInt(_0x2f7435(-_0x14a2a9._0x215a75,-_0x14a2a9._0x32b6c4,-0x1c,-0x23))/0xa*(parseInt(_0x12fd50(0x399,_0x14a2a9._0x5918a8,_0x14a2a9._0x25ff60,_0x14a2a9._0x1b1b4b))/0xb);if(_0x12449f===_0x1f42ea)break;else _0x3a06a4['push'](_0x3a06a4['shift']());}catch(_0x1a6eff){_0x3a06a4['push'](_0x3a06a4['shift']());}}}(_0x5ba7,0x512cf));import{modelIdentityFromParts}from'../chunk-D5IVWJHX.js';import{resolveAnthropicReasoningConfig,resolveOpenAiReasoningConfig}from'../chunk-IUZALP6K.js';import{TurnFailedError}from'../chunk-FFIZ6TKW.js';function _0x5ba7(){const _0x20588a=['y2fUy2vSBgvK','mtm4odqZodDkEuTlCfy','mJq0nZG2nhfJvxL4va','AxngAw5PDgu','ywjVCNrLza','CMvTB3zLqwjVCNrmAxn0zw5LCG','mtblANHrqLy','otK4odq3zNvXDMDT','Aw5KzxHpzG','otzpCeP6qxK','odmYouXRD1jowG','mte4odm1s2HzBwnS','odrtu1rKufe','CMvQzwn0','CMvHC29U','CMvZB2X2zq','C2HPzNq','ChvZAa','mtq2odq0zg1WsKrt','mZK3ntG2meL6ELj3ra','mtHJDwjuAgS'];_0x5ba7=function(){return _0x20588a;};return _0x5ba7();}function _0x230d(_0x199377,_0x12f75b){_0x199377=_0x199377-0x199;const _0x5ba700=_0x5ba7();let _0x230dc2=_0x5ba700[_0x199377];if(_0x230d['PqFmce']===undefined){var _0x412054=function(_0x3b8819){const _0x3b45da='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x5ba4a7='',_0x44c4c5='';for(let _0xf9b5b4=0x0,_0x4cf131,_0x111b2b,_0x3a88e3=0x0;_0x111b2b=_0x3b8819['charAt'](_0x3a88e3++);~_0x111b2b&&(_0x4cf131=_0xf9b5b4%0x4?_0x4cf131*0x40+_0x111b2b:_0x111b2b,_0xf9b5b4++%0x4)?_0x5ba4a7+=String['fromCharCode'](0xff&_0x4cf131>>(-0x2*_0xf9b5b4&0x6)):0x0){_0x111b2b=_0x3b45da['indexOf'](_0x111b2b);}for(let _0xb8353f=0x0,_0x5a0afd=_0x5ba4a7['length'];_0xb8353f<_0x5a0afd;_0xb8353f++){_0x44c4c5+='%'+('00'+_0x5ba4a7['charCodeAt'](_0xb8353f)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x44c4c5);};_0x230d['ONEisO']=_0x412054,_0x230d['QNSNIr']={},_0x230d['PqFmce']=!![];}const _0x2cc334=_0x5ba700[0x0],_0x16421=_0x199377+_0x2cc334,_0x11be62=_0x230d['QNSNIr'][_0x16421];return!_0x11be62?(_0x230dc2=_0x230d['ONEisO'](_0x230dc2),_0x230d['QNSNIr'][_0x16421]=_0x230dc2):_0x230dc2=_0x11be62,_0x230dc2;}import{OperationAbortedError,addAbortListener,isAbortError,throwIfAborted,toAbortError}from'../chunk-X7VAACWY.js';function createAbortAwareSemaphore(_0x5ba4a7){const _0x11f562={_0xc8fca:0x112,_0x4bfaec:0x113,_0x69b42:0x10f},_0x492015={_0x24756b:0x1b9,_0x50c879:0x1ad,_0x5054d7:0x240,_0x560be1:0x23a,_0x5555c4:0x23b,_0x275d0c:0x239},_0x1e38a3={_0x4172d5:0x110,_0x50d50e:0x10c,_0x533678:0x17f,_0x5449b1:0x178,_0x3a1569:0x115,_0x35e7fb:0x11b,_0x453fe0:0x17f,_0xd5e91:0x177,_0x503f2e:0x179,_0x7f77df:0x165,_0x122115:0x16e},_0x22a9d5={_0x58bc89:0x177},_0x49519f={_0x569fee:0x109};if(!Number[_0x28a953(0x111,_0x11f562._0xc8fca,_0x11f562._0x4bfaec,_0x11f562._0x69b42)](_0x5ba4a7)||!Number['isInteger'](_0x5ba4a7)||_0x5ba4a7<=0x0)throw new Error('maxConcurrency\x20must\x20be\x20a\x20finite\x20positive\x20integer');let _0x44c4c5=0x0;const _0xf9b5b4=[];function _0x28a953(_0x376fd9,_0x359728,_0x5ba059,_0x1adf59){return _0x230d(_0x376fd9- -0x9a,_0x5ba059);}const _0x4cf131=()=>{let _0x3a88e3=![];return()=>{if(_0x3a88e3)return;_0x3a88e3=!![],_0x44c4c5-=0x1,_0x111b2b();};},_0x111b2b=()=>{function _0x26d145(_0x192c16,_0x104149,_0x3bf0a1,_0x4e3f91){return _0x28a953(_0x192c16-0x7,_0x104149-0x1ef,_0x3bf0a1,_0x4e3f91-_0x49519f._0x569fee);}function _0x187906(_0x11b104,_0x45c2e9,_0x442402,_0x106fe1){return _0x28a953(_0x106fe1-0x66,_0x45c2e9-_0x22a9d5._0x58bc89,_0x11b104,_0x106fe1-0x137);}while(_0xf9b5b4['length']>0x0){const _0xb8353f=_0xf9b5b4[_0x26d145(_0x1e38a3._0x4172d5,0x110,0x115,_0x1e38a3._0x50d50e)]();if(!_0xb8353f||_0xb8353f[_0x187906(_0x1e38a3._0x533678,_0x1e38a3._0x5449b1,_0x1e38a3._0x5449b1,0x174)])continue;_0xb8353f[_0x26d145(_0x1e38a3._0x3a1569,_0x1e38a3._0x35e7fb,0x10d,0x115)]=!![],_0xb8353f[_0x187906(_0x1e38a3._0x453fe0,_0x1e38a3._0xd5e91,0x17a,_0x1e38a3._0x503f2e)](),_0x44c4c5+=0x1,_0xb8353f[_0x187906(0x16f,_0x1e38a3._0x7f77df,0x16b,_0x1e38a3._0x122115)](_0x4cf131());return;}};return{'acquire'(_0x5a0afd){const _0x2250fa={_0x1162bf:0x562,_0x361131:0x55e,_0x1bc93a:0x56a,_0x4af8f3:0x56b},_0x522417={_0x626dea:0x35d,_0x4accb3:0x359,_0x4a3b88:0x360,_0x40fb9f:0x358,_0xce9f42:0x364,_0x15ed93:0x355,_0x310768:0x355,_0x50692f:0x354,_0x413b82:0x35b},_0x5b10bc={_0x1544e0:0x2c},_0x3a97df={_0x5d2467:0xd0};function _0x2a0a61(_0x22bc32,_0x364633,_0x218b2f,_0x267fcc){return _0x28a953(_0x267fcc-0xad,_0x364633-0x134,_0x364633,_0x267fcc-0x28);}if(_0x5a0afd?.[_0x4d67a5(0x247,0x241,0x24f,0x24c)])return Promise[_0x2a0a61(0x1bd,_0x492015._0x24756b,_0x492015._0x50c879,0x1b3)](toAbortError(_0x5a0afd[_0x4d67a5(0x23c,_0x492015._0x5054d7,0x240,_0x492015._0x560be1)]));function _0x4d67a5(_0x53f85c,_0x2b08fa,_0x4732be,_0x593bc5){return _0x28a953(_0x53f85c-0x135,_0x2b08fa-_0x3a97df._0x5d2467,_0x4732be,_0x593bc5-0x96);}if(_0x44c4c5<_0x5ba4a7)return _0x44c4c5+=0x1,Promise[_0x4d67a5(0x23d,_0x492015._0x5555c4,0x23d,_0x492015._0x275d0c)](_0x4cf131());return new Promise((_0x50ce04,_0x28a186)=>{const _0x461778={_0x236788:0x322,_0x182324:0x109};function _0x233a91(_0x269155,_0x5a4942,_0x2ad50b,_0x13f40f){return _0x4d67a5(_0x5a4942-_0x461778._0x236788,_0x5a4942-_0x461778._0x182324,_0x13f40f,_0x13f40f-0x4a);}function _0x21de20(_0x3aab42,_0x38d2c5,_0xfaee88,_0x2c8957){return _0x4d67a5(_0x38d2c5- -0x360,_0x38d2c5-0x18f,_0x3aab42,_0x2c8957-_0x5b10bc._0x1544e0);}const _0x4077aa={'resolve':_0x50ce04,'reject':_0x28a186,'cancelled':![],'removeAbortListener':()=>{}};_0xf9b5b4[_0x233a91(_0x2250fa._0x1162bf,0x561,0x56a,_0x2250fa._0x361131)](_0x4077aa),_0x4077aa[_0x233a91(0x569,_0x2250fa._0x1bc93a,_0x2250fa._0x4af8f3,0x56a)]=addAbortListener(_0x5a0afd,()=>{const _0x4d3028={_0x3f818f:0x199,_0x5118e1:0x1f4};if(_0x4077aa[_0x4dc38c(_0x522417._0x626dea,_0x522417._0x4accb3,0x35e,_0x522417._0x4a3b88)])return;function _0x58a108(_0x5ac93e,_0x44a57e,_0x12f4f3,_0x496e24){return _0x233a91(_0x5ac93e-_0x4d3028._0x3f818f,_0x496e24- -_0x4d3028._0x5118e1,_0x12f4f3-0x9c,_0x44a57e);}_0x4077aa[_0x4dc38c(_0x522417._0x626dea,_0x522417._0x40fb9f,0x360,_0x522417._0xce9f42)]=!![],_0x4077aa['removeAbortListener']();const _0x3e8ddb=_0xf9b5b4[_0x4dc38c(0x350,0x350,_0x522417._0x15ed93,0x346)](_0x4077aa);function _0x4dc38c(_0x45bb45,_0x27e3de,_0x4d4e2d,_0x1a7713){return _0x21de20(_0x27e3de,_0x45bb45-0x47a,_0x4d4e2d-0x5c,_0x1a7713-0x5f);}if(_0x3e8ddb>=0x0)_0xf9b5b4['splice'](_0x3e8ddb,0x1);_0x4077aa[_0x4dc38c(_0x522417._0x310768,0x350,_0x522417._0x50692f,_0x522417._0x413b82)](toAbortError(_0x5a0afd?.['reason']));});});}};}export{OperationAbortedError,TurnFailedError,addAbortListener,createAbortAwareSemaphore,isAbortError,modelIdentityFromParts,resolveAnthropicReasoningConfig,resolveOpenAiReasoningConfig,throwIfAborted,toAbortError};
@@ -222,6 +222,13 @@ export interface ChatResponseUsage {
222
222
  reportedCost?: ReportedModelCost;
223
223
  estimatedCost?: EstimatedModelCost;
224
224
  }
225
+ export interface PersistedModelCallMetricsV1 {
226
+ version: 1;
227
+ usage: ChatResponseUsage;
228
+ modelTimeMs: number;
229
+ completesRequest: boolean;
230
+ }
231
+ export type PersistedModelCallMetrics = PersistedModelCallMetricsV1;
225
232
  export interface ChatResponse {
226
233
  id: string;
227
234
  content: AssistantContentBlock[];
@@ -390,6 +397,7 @@ export interface TurnMessageMeta {
390
397
  provider?: string;
391
398
  model?: string;
392
399
  modelIdentity?: string;
400
+ metrics?: PersistedModelCallMetrics;
393
401
  /** ms epoch — provider request sent. */
394
402
  turnStartedAt?: number;
395
403
  /** ms epoch — response fully received. */
@@ -444,9 +452,17 @@ export interface ToolExecutionContext extends AgentEventContext {
444
452
  signal: AbortSignal;
445
453
  toolCallId?: string;
446
454
  permissionClass?: ToolPermissionClass;
455
+ executionAuthorization?: unknown;
447
456
  askUser?: (request: AskUserQuestionRequest) => Promise<AskUserAnswers>;
448
457
  setTopic?: (topic: string) => void;
449
458
  }
459
+ export interface BashExecutionTarget {
460
+ command: string;
461
+ cwd: string;
462
+ shellPath: string;
463
+ dialect: "bash" | "posix" | "windows" | "unknown";
464
+ background: boolean;
465
+ }
450
466
  export interface ToolRuntimeStartedEvent {
451
467
  type: "tool_started";
452
468
  toolCall: ToolUseBlock;
@@ -477,6 +493,8 @@ export interface AgentModelRequestEvent {
477
493
  }
478
494
  export interface AgentModelResponseEvent {
479
495
  type: "model_response";
496
+ /** Exact provider/model-call duration measured by the turn engine. */
497
+ modelTimeMs?: number;
480
498
  response: ChatResponse;
481
499
  }
482
500
  export interface AgentAssistantMessageEvent {
@@ -548,6 +566,9 @@ export type ToolRuntimeDispatchDecision = {
548
566
  dir: string;
549
567
  persist: boolean;
550
568
  };
569
+ executionAuthorization?: unknown;
570
+ approvalDecision?: "y" | "a" | "t";
571
+ approvalSource?: "policy" | "remembered" | "sudo" | "user";
551
572
  };
552
573
  export type ToolRuntimeToolCallHandler = (toolCall: ToolUseBlock, ctx: ToolExecutionContext) => Promise<ToolRuntimeDispatchDecision | undefined> | ToolRuntimeDispatchDecision | undefined;
553
574
  export type ToolRuntimeEventHandler = (event: ToolRuntimeEvent, ctx: ToolExecutionContext) => Promise<void> | void;
@@ -621,6 +642,8 @@ export interface ObserverExtensionRegistration<S extends Stage = Stage> {
621
642
  kind: "observer";
622
643
  order: number;
623
644
  enabled: boolean;
645
+ /** Runs after every enabled non-terminal observer registered for this stage. */
646
+ terminal?: boolean;
624
647
  run: Observer<S>;
625
648
  }
626
649
  export type AnyExtensionRegistration = {
@@ -1,16 +1,34 @@
1
1
  import type { ChildProcess } from "node:child_process";
2
2
  import { StringDecoder } from "node:string_decoder";
3
- export type BackgroundProcessStatus = "running" | "exited" | "killed" | "error";
3
+ import { type ProcessTreeSignalAdapter } from "./process-tree-termination.ts";
4
+ import { type TerminalOutputNormalizer } from "./terminal-output-normalizer.ts";
5
+ export type BackgroundProcessStatus = "running" | "terminating" | "exited" | "killed" | "error";
6
+ export interface BackgroundProcessReservation {
7
+ readonly id: string;
8
+ }
9
+ export interface BackgroundProcessTerminationResult {
10
+ shellId: string;
11
+ outcome: "killed" | "already-terminal" | "failed";
12
+ status: BackgroundProcessStatus;
13
+ exitCode: number | null;
14
+ signal: NodeJS.Signals | null;
15
+ error: string | null;
16
+ gracefulRequested: boolean;
17
+ forceRequested: boolean;
18
+ }
4
19
  export interface BackgroundProcessEntry {
5
20
  shellId: string;
6
21
  command: string;
7
22
  cwd: string;
8
23
  pid: number | undefined;
24
+ processGroupId: number | undefined;
9
25
  status: BackgroundProcessStatus;
10
26
  exitCode: number | null;
11
27
  signal: NodeJS.Signals | null;
12
28
  startedAt: number;
13
- error?: string;
29
+ error: string | null;
30
+ gracefulRequested: boolean;
31
+ forceRequested: boolean;
14
32
  child: ChildProcess | null;
15
33
  buffer: string[];
16
34
  bufferChars: number;
@@ -19,29 +37,58 @@ export interface BackgroundProcessEntry {
19
37
  readCursor: number;
20
38
  stdoutDecoder: StringDecoder;
21
39
  stderrDecoder: StringDecoder;
40
+ stdoutNormalizer: TerminalOutputNormalizer;
41
+ stderrNormalizer: TerminalOutputNormalizer;
22
42
  stripAnsi: boolean;
23
43
  killRequested: boolean;
24
44
  processExited: boolean;
45
+ streamsFlushed: boolean;
46
+ terminalSettled: boolean;
47
+ terminalPromise: Promise<void>;
48
+ resolveTerminal: () => void;
49
+ terminationPromise?: Promise<BackgroundProcessTerminationResult>;
50
+ terminationSettled: boolean;
25
51
  }
26
52
  export interface BackgroundProcessReadResult {
27
53
  output: string;
28
54
  status: BackgroundProcessStatus;
29
55
  exitCode: number | null;
30
56
  signal: NodeJS.Signals | null;
57
+ error: string | null;
31
58
  truncated: boolean;
32
59
  }
33
60
  export interface BackgroundProcessRegistryOptions {
34
61
  maxConcurrent?: number;
35
62
  maxEntries?: number;
36
63
  capChars?: number;
64
+ platform?: NodeJS.Platform;
65
+ signalAdapter?: ProcessTreeSignalAdapter;
37
66
  }
67
+ export declare class BackgroundProcessCleanupError extends Error {
68
+ readonly results: BackgroundProcessTerminationResult[];
69
+ constructor(results: BackgroundProcessTerminationResult[]);
70
+ }
71
+ export declare function isTerminalStatus(status: BackgroundProcessStatus): boolean;
38
72
  export declare class BackgroundProcessRegistry {
39
73
  private readonly entries;
74
+ private readonly reservations;
40
75
  private readonly maxConcurrent;
41
76
  private readonly maxEntries;
42
77
  private readonly capChars;
78
+ private readonly platform;
79
+ private readonly signalAdapter;
43
80
  private counter;
44
81
  constructor(opts?: BackgroundProcessRegistryOptions);
82
+ reserve(): BackgroundProcessReservation;
83
+ release(reservation: BackgroundProcessReservation): void;
84
+ attach(reservation: BackgroundProcessReservation, opts: {
85
+ child: ChildProcess;
86
+ command: string;
87
+ cwd: string;
88
+ stripAnsi: boolean;
89
+ processGroupId?: number;
90
+ }): BackgroundProcessEntry;
91
+ /** Compatibility adapter for callers being migrated to reserve/attach. */
45
92
  spawn(opts: {
46
93
  child: ChildProcess;
47
94
  command: string;
@@ -52,12 +99,17 @@ export declare class BackgroundProcessRegistry {
52
99
  regex?: string;
53
100
  }): BackgroundProcessReadResult;
54
101
  list(): BackgroundProcessEntry[];
55
- kill(shellId: string): {
56
- status: BackgroundProcessStatus;
57
- exitCode: number | null;
58
- signal: NodeJS.Signals | null;
59
- };
60
- closeAll(): Promise<void>;
102
+ kill(shellId: string): Promise<BackgroundProcessTerminationResult>;
103
+ closeAll(): Promise<BackgroundProcessTerminationResult[]>;
104
+ reset(): Promise<BackgroundProcessTerminationResult[]>;
105
+ private terminate;
106
+ private confirmed;
107
+ private failed;
108
+ private result;
109
+ private waitForTerminal;
110
+ private appendDecoded;
111
+ private settleTerminal;
112
+ private flushStreams;
61
113
  private append;
62
114
  private evictIfNeeded;
63
115
  }
@@ -1,3 +1,4 @@
1
+ import type { BashExecutionTarget, ToolExecutionContext } from "../shared/types.ts";
1
2
  import type { BackgroundProcessRegistry } from "./background-process-registry.ts";
2
3
  export interface BashToolInput {
3
4
  command: string;
@@ -18,16 +19,19 @@ export interface BashToolOptions {
18
19
  shellPath?: string;
19
20
  stripAnsi?: boolean;
20
21
  scrubEnvKeys?: readonly string[];
22
+ scrubEnvPrefixes?: readonly string[];
21
23
  backgroundRegistry?: BackgroundProcessRegistry;
24
+ verifyExecution?: (target: BashExecutionTarget, authorization: unknown, ctx: ToolExecutionContext) => Promise<void> | void;
22
25
  }
26
+ export declare function resolveBashExecutionTarget(input: Pick<BashToolInput, "command" | "cwd" | "runInBackground">, options?: Pick<BashToolOptions, "allowedDirs" | "defaultCwd" | "shellPath">): BashExecutionTarget;
23
27
  export declare function createBashTool(options?: BashToolOptions): import("../shared/types.ts").ToolDefinition<{
24
28
  description: string;
25
29
  command: string;
26
30
  timeoutMs?: number | undefined;
27
31
  cwd?: string | undefined;
32
+ runInBackground?: boolean | undefined;
28
33
  ignoreOutput?: boolean | undefined;
29
34
  outputRegex?: string | undefined;
30
- runInBackground?: boolean | undefined;
31
35
  }, string, import("../shared/types.ts").ToolOutputEnvelope, {
32
36
  type: "object";
33
37
  properties: {
@@ -62,9 +66,9 @@ export declare function createShellExecTool(options?: BashToolOptions): import("
62
66
  command: string;
63
67
  timeoutMs?: number | undefined;
64
68
  cwd?: string | undefined;
69
+ runInBackground?: boolean | undefined;
65
70
  ignoreOutput?: boolean | undefined;
66
71
  outputRegex?: string | undefined;
67
- runInBackground?: boolean | undefined;
68
72
  }, string, import("../shared/types.ts").ToolOutputEnvelope, {
69
73
  type: "object";
70
74
  properties: {