@myagentroam/agent 0.9.61 → 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.
Files changed (119) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +4 -0
  3. package/dist/cli/codex-auth-file.js +268 -3
  4. package/dist/cli/main.js +427 -2
  5. package/dist/error.js +66 -2
  6. package/dist/host/contracts.js +20 -2
  7. package/dist/host/local-agent-host.js +146 -2
  8. package/dist/host/local-process-executor.js +39 -2
  9. package/dist/index.d.ts +1 -1
  10. package/dist/index.js +12 -2
  11. package/dist/model/anthropic-messages.js +474 -2
  12. package/dist/model/anthropic-thinking.js +33 -2
  13. package/dist/model/catalog-file.js +88 -2
  14. package/dist/model/configuration.js +137 -2
  15. package/dist/model/contracts.d.ts +2 -0
  16. package/dist/model/contracts.js +1 -2
  17. package/dist/model/http.js +529 -2
  18. package/dist/model/openai-responses.d.ts +2 -0
  19. package/dist/model/openai-responses.js +1602 -2
  20. package/dist/model/runtime-credential.js +35 -2
  21. package/dist/model/sse.js +199 -2
  22. package/dist/prompts/compact.js +25 -2
  23. package/dist/prompts/core.js +37 -2
  24. package/dist/prompts/execution-budget.js +10 -2
  25. package/dist/prompts/index.d.ts +3 -2
  26. package/dist/prompts/index.js +47 -2
  27. package/dist/prompts/modes.js +25 -2
  28. package/dist/prompts/output.js +1 -2
  29. package/dist/prompts/resources.d.ts +1 -1
  30. package/dist/prompts/resources.js +31 -2
  31. package/dist/prompts/subagent.d.ts +6 -0
  32. package/dist/prompts/subagent.js +29 -2
  33. package/dist/prompts/title.js +9 -2
  34. package/dist/prompts/workflow.js +32 -2
  35. package/dist/runtime/async-queue.js +62 -2
  36. package/dist/runtime/builtin-skills.js +19 -2
  37. package/dist/runtime/byted-ark-imagegen-skill.js +18 -2
  38. package/dist/runtime/codex-imagegen-skill.js +35 -2
  39. package/dist/runtime/compact.js +225 -2
  40. package/dist/runtime/context-gc-runtime.d.ts +35 -0
  41. package/dist/runtime/context-gc-runtime.js +163 -0
  42. package/dist/runtime/context-gc-tokens.d.ts +24 -0
  43. package/dist/runtime/context-gc-tokens.js +83 -0
  44. package/dist/runtime/context-gc.d.ts +66 -0
  45. package/dist/runtime/context-gc.js +909 -0
  46. package/dist/runtime/context-projection.d.ts +23 -0
  47. package/dist/runtime/context-projection.js +203 -0
  48. package/dist/runtime/environment-context.js +41 -2
  49. package/dist/runtime/execution-policy.js +13 -2
  50. package/dist/runtime/instructions.js +298 -2
  51. package/dist/runtime/normalize.js +40 -2
  52. package/dist/runtime/plan-output.js +95 -2
  53. package/dist/runtime/rollout-budget.d.ts +2 -0
  54. package/dist/runtime/rollout-budget.js +92 -2
  55. package/dist/runtime/token-budget.d.ts +2 -0
  56. package/dist/runtime/token-budget.js +44 -2
  57. package/dist/sdk/agent.js +1804 -2
  58. package/dist/sdk/types.d.ts +15 -5
  59. package/dist/sdk/types.js +1 -2
  60. package/dist/session/catalog.d.ts +5 -4
  61. package/dist/session/catalog.js +133 -2
  62. package/dist/session/context-gc-checkpoint.d.ts +148 -0
  63. package/dist/session/context-gc-checkpoint.js +665 -0
  64. package/dist/session/context-gc-replacements.d.ts +52 -0
  65. package/dist/session/context-gc-replacements.js +226 -0
  66. package/dist/session/context-gc-subagent.d.ts +43 -0
  67. package/dist/session/context-gc-subagent.js +267 -0
  68. package/dist/session/jsonl-store.d.ts +42 -4
  69. package/dist/session/jsonl-store.js +1657 -2
  70. package/dist/subagent/scheduler.d.ts +35 -2
  71. package/dist/subagent/scheduler.js +249 -2
  72. package/dist/subagent/session-controller.d.ts +94 -0
  73. package/dist/subagent/session-controller.js +675 -0
  74. package/dist/tools/agent-cancel.js +28 -2
  75. package/dist/tools/{task.d.ts → agent-message.d.ts} +2 -2
  76. package/dist/tools/agent-message.js +51 -0
  77. package/dist/tools/agent-start.js +84 -2
  78. package/dist/tools/agent-wait.js +53 -2
  79. package/dist/tools/apply-patch.js +478 -2
  80. package/dist/tools/code-mode.js +370 -2
  81. package/dist/tools/codex-image-gen.js +312 -2
  82. package/dist/tools/exec.js +455 -2
  83. package/dist/tools/execution-limits.d.ts +1 -0
  84. package/dist/tools/execution-limits.js +44 -2
  85. package/dist/tools/local-registry.js +233 -2
  86. package/dist/tools/local-workspace-tools.js +28 -2
  87. package/dist/tools/question.js +124 -2
  88. package/dist/tools/read-context.d.ts +16 -0
  89. package/dist/tools/read-context.js +85 -0
  90. package/dist/tools/read.d.ts +13 -0
  91. package/dist/tools/read.js +294 -2
  92. package/dist/tools/registry.js +76 -2
  93. package/dist/tools/runtime-context.d.ts +9 -2
  94. package/dist/tools/runtime-context.js +1 -2
  95. package/dist/tools/runtime.js +21 -2
  96. package/dist/tools/scheduler.js +41 -2
  97. package/dist/tools/shared/path-resolver.js +133 -2
  98. package/dist/tools/skill.js +37 -2
  99. package/dist/tools/todo-read.js +10 -2
  100. package/dist/tools/todo-write.js +65 -2
  101. package/dist/tools/todo.js +67 -2
  102. package/dist/tools/view-image.js +81 -2
  103. package/dist/tools/web-fetch.js +11 -2
  104. package/dist/tools/web-search.js +14 -2
  105. package/package.json +17 -15
  106. package/README.md +0 -3
  107. package/dist/runtime/prompt.d.ts +0 -9
  108. package/dist/runtime/prompt.js +0 -2
  109. package/dist/tools/shared/secret-redaction.d.ts +0 -4
  110. package/dist/tools/shared/secret-redaction.js +0 -2
  111. package/dist/tools/task-cancel.d.ts +0 -7
  112. package/dist/tools/task-cancel.js +0 -2
  113. package/dist/tools/task-output.d.ts +0 -7
  114. package/dist/tools/task-output.js +0 -2
  115. package/dist/tools/task-tools.d.ts +0 -36
  116. package/dist/tools/task-tools.js +0 -2
  117. package/dist/tools/task.js +0 -2
  118. package/dist/tools/todo-tools.d.ts +0 -25
  119. package/dist/tools/todo-tools.js +0 -2
@@ -1,6 +1,8 @@
1
1
  import type { HostDescription } from '../host/contracts.js';
2
2
  import type { MarAgentModelConfiguration, MarAgentReasoningEffort } from '../model/configuration.js';
3
3
  import type { ModelAdapter } from '../model/contracts.js';
4
+ import type { MarAgentSessionPage, MarAgentSessionSummary } from '../session/catalog.js';
5
+ import type { SessionListInput, SessionSource } from '../session/jsonl-store.js';
4
6
  export type AccessMode = 'on-request' | 'full-access';
5
7
  export type ExecutionMode = 'run' | 'plan' | 'compact';
6
8
  export interface ToolCall {
@@ -83,6 +85,8 @@ export type MarAgentEvent = MarAgentEventBase & ({
83
85
  itemId: string;
84
86
  phase: 'commentary' | 'final_answer';
85
87
  text: string;
88
+ modelId: string;
89
+ modelName: string;
86
90
  } | {
87
91
  type: 'plan.completed';
88
92
  itemId: string;
@@ -117,7 +121,7 @@ export type MarAgentEvent = MarAgentEventBase & ({
117
121
  summary: string;
118
122
  truncated?: boolean;
119
123
  artifacts?: readonly MarAgentToolArtifact[];
120
- data?: import('../tools/exec.js').ExecResult | Omit<import('../tools/exec.js').ExecResult, 'stdout' | 'stderr'> | import('../tools/apply-patch.js').ApplyPatchResult | import('../tools/view-image.js').ViewImageResult | import('../subagent/scheduler.js').SubagentTaskSnapshot;
124
+ data?: import('../tools/exec.js').ExecResult | Omit<import('../tools/exec.js').ExecResult, 'stdout' | 'stderr'> | import('../tools/apply-patch.js').ApplyPatchResult | import('../tools/read.js').ReadEventData | import('../tools/view-image.js').ViewImageResult | import('../subagent/scheduler.js').SubagentTaskSnapshot;
121
125
  } | {
122
126
  type: 'tool.failed';
123
127
  toolName: string;
@@ -146,11 +150,18 @@ export type MarAgentEvent = MarAgentEventBase & ({
146
150
  type: 'subagent.started';
147
151
  agentId: string;
148
152
  description: string;
153
+ modelId?: string;
154
+ modelName?: string;
155
+ reasoningEffort?: MarAgentReasoningEffort;
149
156
  } | {
150
157
  type: 'subagent.completed';
151
158
  agentId: string;
152
159
  description?: string;
153
160
  status: string;
161
+ modelId?: string;
162
+ modelName?: string;
163
+ reasoningEffort?: MarAgentReasoningEffort;
164
+ latestMessage?: import('../subagent/scheduler.js').SubagentLatestMessage;
154
165
  errorCode?: string;
155
166
  errorMessage?: string;
156
167
  } | {
@@ -212,10 +223,8 @@ export interface MarAgentSession {
212
223
  export interface MarAgent {
213
224
  createSession(input: CreateSessionInput): Promise<MarAgentSession>;
214
225
  openSession(sessionId: string): Promise<MarAgentSession>;
215
- listSessions(input?: {
216
- limit?: number;
217
- cursor?: string;
218
- }): Promise<unknown>;
226
+ listSessions(input?: SessionListInput): Promise<MarAgentSessionPage>;
227
+ clearSession(sessionId: string): Promise<void>;
219
228
  reconfigureModels(input: {
220
229
  readonly models: readonly MarAgentModelConfiguration[];
221
230
  readonly defaultModelId?: string;
@@ -244,3 +253,4 @@ export interface CreateMarAgentOptions {
244
253
  rolloutBudget?: false | RolloutBudgetOptions;
245
254
  adapterFactory?: (configuration: MarAgentModelConfiguration) => ModelAdapter;
246
255
  }
256
+ export type { MarAgentSessionSummary, SessionListInput, SessionSource };
package/dist/sdk/types.js CHANGED
@@ -1,2 +1 @@
1
- /* mar-release-protected */
2
- export{};
1
+ export {};
@@ -1,3 +1,4 @@
1
+ import { type SessionListInput, type SessionSource } from './jsonl-store.js';
1
2
  import type { MarAgentEvent, MarAgentImageMetadata } from '../sdk/types.js';
2
3
  export interface MarAgentSessionSummary {
3
4
  id: string;
@@ -5,6 +6,7 @@ export interface MarAgentSessionSummary {
5
6
  workspace: string;
6
7
  createdAt: string;
7
8
  lastActivityAt: string;
9
+ source: SessionSource;
8
10
  }
9
11
  export interface MarAgentSessionPage {
10
12
  sessions: MarAgentSessionSummary[];
@@ -22,6 +24,7 @@ export type MarAgentHistoryEntry = {
22
24
  turnId: string;
23
25
  text: string;
24
26
  clientMessageId?: string;
27
+ inputSource?: 'user' | 'parent_agent';
25
28
  images?: readonly MarAgentHistoryImageMetadata[];
26
29
  } | {
27
30
  kind: 'event';
@@ -46,10 +49,7 @@ export interface MarAgentSessionImage {
46
49
  }
47
50
  /** Public session catalog facade. Storage details remain SDK-private. */
48
51
  export interface MarAgentSessionCatalog {
49
- list(input?: {
50
- limit?: number;
51
- cursor?: string;
52
- }): Promise<MarAgentSessionPage>;
52
+ list(input?: SessionListInput): Promise<MarAgentSessionPage>;
53
53
  history(sessionId: string, input?: {
54
54
  limit?: number;
55
55
  cursor?: string;
@@ -66,6 +66,7 @@ export interface MarAgentSessionCatalog {
66
66
  rollback(sessionId: string, input: {
67
67
  readonly boundaryTurnId: string | null;
68
68
  }): Promise<MarAgentSessionSummary>;
69
+ clear(sessionId: string): Promise<MarAgentSessionSummary>;
69
70
  delete(sessionId: string): Promise<MarAgentSessionDeleteResult>;
70
71
  close(): Promise<void>;
71
72
  }
@@ -1,2 +1,133 @@
1
- /* mar-release-protected */
2
- const _0x65f843=_0x2765;(function(_0x1a46fd,_0x55cabd){const _0x1e9968=_0x2765,_0x30c05a=_0x1a46fd();while(!![]){try{const _0x14257a=parseInt(_0x1e9968(0x12b))/(0x225+0x515+-0x739)*(-parseInt(_0x1e9968(0x135))/(0xc80+0x419*-0x9+0x1863*0x1))+parseInt(_0x1e9968(0x11f))/(0x1364*-0x2+-0x305*0x1+-0x1be*-0x18)+parseInt(_0x1e9968(0x140))/(0x243*0x6+0x239b*-0x1+0x160d)+parseInt(_0x1e9968(0x117))/(0x99*0x2e+-0x2694*-0x1+-0x420d)*(parseInt(_0x1e9968(0x138))/(-0x20a3+-0x2*-0xce5+0x6df*0x1))+parseInt(_0x1e9968(0x10b))/(-0x13b3+0x1*-0x2397+0x3751)*(parseInt(_0x1e9968(0x10f))/(0x249b+0xb2b+-0x2fbe))+-parseInt(_0x1e9968(0x11d))/(0xd1d+-0x16f+-0xba5)*(parseInt(_0x1e9968(0x143))/(-0x1bee+0xefe+-0x67d*-0x2))+-parseInt(_0x1e9968(0x11e))/(-0x15c+0x13d7+-0x1270);if(_0x14257a===_0x55cabd)break;else _0x30c05a['push'](_0x30c05a['shift']());}catch(_0x4c9311){_0x30c05a['push'](_0x30c05a['shift']());}}}(_0x3189,0x1*0x1bedd+0x49319+-0x3c9f5));import{JsonlSessionStore}from'./jsonl-store.js';function _0x2765(_0x17a33f,_0x2e8ffd){_0x17a33f=_0x17a33f-(-0x6*-0x114+0x11a5+-0x101*0x17);const _0x6fd9ea=_0x3189();let _0x211e4c=_0x6fd9ea[_0x17a33f];if(_0x2765['XQmArt']===undefined){var _0x3d4c07=function(_0x57a0cc){const _0x27d019='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x2ff906='',_0x39c1c1='';for(let _0x11552d=-0x690+0xcfc+-0x66c,_0x114979,_0x336631,_0x5306f8=0xe3*0x29+-0x1*0x22c2+-0x199;_0x336631=_0x57a0cc['charAt'](_0x5306f8++);~_0x336631&&(_0x114979=_0x11552d%(0x18*0x1+0x2*-0x1114+0x885*0x4)?_0x114979*(-0x1*-0x212e+-0x702+0xcf6*-0x2)+_0x336631:_0x336631,_0x11552d++%(-0x5*-0x288+0x5d*-0x6b+0x1a3b))?_0x2ff906+=String['fromCharCode'](0x7*-0x1c9+0x79c*0x3+-0x956&_0x114979>>(-(0xf75+0x3bb*-0x4+-0x1*0x87)*_0x11552d&-0xb0+0x1204+-0x114e)):-0x2382+-0x2014+-0x52*-0xd3){_0x336631=_0x27d019['indexOf'](_0x336631);}for(let _0x47ddd3=0x2*-0x102f+0x506+0x1b58,_0x414678=_0x2ff906['length'];_0x47ddd3<_0x414678;_0x47ddd3++){_0x39c1c1+='%'+('00'+_0x2ff906['charCodeAt'](_0x47ddd3)['toString'](0x17d+0x1fa*-0x4+0x15*0x4f))['slice'](-(0x1ace+-0x2*0xd8d+0x4e));}return decodeURIComponent(_0x39c1c1);};_0x2765['ygmdVy']=_0x3d4c07,_0x2765['lkZqTn']={},_0x2765['XQmArt']=!![];}const _0x4f00b1=_0x6fd9ea[-0x1475+-0x13d*-0x1d+-0x56*0x2e];_0x2765['zLVfUW']!==_0x4f00b1&&(_0x2765['lkZqTn']={},_0x2765['zLVfUW']=_0x4f00b1);const _0x516ee6=_0x2765['lkZqTn'][_0x17a33f];return _0x516ee6===undefined?(_0x211e4c=_0x2765['ygmdVy'](_0x211e4c),_0x2765['lkZqTn'][_0x17a33f]=_0x211e4c):_0x211e4c=_0x516ee6,_0x211e4c;}function _0x3189(){const _0x1e6a4b=['AxnbCNjHEq','y2XPzw50twvZC2fNzuLK','BNvTyMvY','zgf0yujHC2u2na','nZmZodbAB1jLru0','Cgf5Bg9Hza','Aw1Hz2uVANbLzW','BwLTzvr5Cgu','C3rYAw5N','Aw5WDxruB2TLBNm','nZa0nJfcAvj6CKq','ntuZntG0ouLfugTkzG','mJG0mdG4rgvLywHZ','zM9YA1nLC3nPB24','CM9SBgjHy2TtzxnZAw9U','CMvHzeLUChv0sw1Hz2u','B3bLBG','y29UDgv4Dc5JB21Wywn0zwq','y3vYC29Y','C2vXDwvUy2u','Aw1Hz2uVD2vICa','BgvUz3rO','Ag9TzurPCMvJDg9YEq','zxzLBNrjza','mJHyt0TIC1i','zxzLBNq','C2vZC2LVBKLK','AgfZ','B2jQzwn0','y2XVC2u','Dg9szxzLCNnLza','zMXHDe1HCa','ChjVBxb0','Aw1Hz2uVCg5N','nZi0mMnJy3H2qW','BgLZDa','Aw1Hz2vZ','otzeq1jlEwq','zMLSzu5HBwu','Aw1Hz2uVz2LM','DhvYBI51C2vY','BgLTAxq','DxnLCG','AxntywzLsw50zwDLCG','DgvZDa','odCXnJeYzgf1sKnO','yNL0zvnPEMu','DhvYBKLK','nZbtqM5VB0u','C2HHmJu2','y29UDgv4DeLUChv0vg9Rzw5Z','CMvJB3jKCW','ChjLDMLVDxnczwzVCMvtzxf1zw5Jzq','DhLWzq','mJHArLvYAhC','DgLTzxn0yw1W','zgvSzxrL','DxnHz2uUDxbKyxrLza','ntu1odq4qvLRzurm','CMvHzfbHz2u','zxHLy3v0Aw9Uswq','BMfTzq'];_0x3189=function(){return _0x1e6a4b;};return _0x3189();}const MAX_INPUT_IMAGE_BYTES=(-0xb4f*0x1+0x83*-0x30+-0x1*-0x23e4)*(-0x1650+0x18*0x1+0x2*0xd1c)*(-0x2*-0x457+-0x1*-0x1c96+-0x2144),INPUT_IMAGE_MIME_TYPES=new Set([_0x65f843(0x134),_0x65f843(0x119),_0x65f843(0x13a),_0x65f843(0x127)]);export async function openMarAgentSessionCatalog(_0x82ec60){const _0x286e9c=_0x65f843,_0x35d14f=await JsonlSessionStore[_0x286e9c(0x123)](_0x82ec60[_0x286e9c(0x129)]);return{'list':_0x4ea044=>_0x35d14f[_0x286e9c(0x136)](_0x4ea044),'history':async(_0x375ef9,_0xad3ccc={})=>{const _0x54a342=_0x286e9c,_0x151252=parseCursor(_0xad3ccc[_0x54a342(0x125)]),_0x318108=await _0x35d14f[_0x54a342(0x110)](_0x375ef9,{..._0xad3ccc[_0x54a342(0x13c)]===undefined?{}:{'limit':_0xad3ccc[_0x54a342(0x13c)]},..._0x151252===undefined?{}:{'beforeSequence':_0x151252}}),_0x2609a4=_0x318108[_0x54a342(0x108)][_0x54a342(0x132)](_0x277fc6=>{const _0x141534=_0x54a342;if(_0x277fc6[_0x141534(0x10a)]===_0x141534(0x13b)&&_0x277fc6[_0x141534(0x111)]!==undefined&&_0x277fc6[_0x141534(0x142)]!==undefined&&isRecord(_0x277fc6[_0x141534(0x118)])&&typeof _0x277fc6[_0x141534(0x118)][_0x141534(0x133)]===_0x141534(0x11b)){const _0x30c222=imageMetadata(_0x277fc6[_0x141534(0x118)][_0x141534(0x137)]);return[{'kind':_0x141534(0x13d),'sequence':_0x277fc6[_0x141534(0x126)],'timestamp':_0x277fc6[_0x141534(0x10c)],'sessionId':_0x277fc6[_0x141534(0x12d)],'executionId':_0x277fc6[_0x141534(0x111)],'turnId':_0x277fc6[_0x141534(0x142)],'text':_0x277fc6[_0x141534(0x118)][_0x141534(0x133)],...typeof _0x277fc6[_0x141534(0x118)][_0x141534(0x114)]===_0x141534(0x11b)?{'clientMessageId':_0x277fc6[_0x141534(0x118)][_0x141534(0x114)]}:{},..._0x30c222[_0x141534(0x128)]>-0x2556*-0x1+-0x1*-0x24f7+0x17*-0x33b?{'images':_0x30c222}:{}}];}if(isMarAgentEvent(_0x277fc6[_0x141534(0x118)]))return[{'kind':_0x141534(0x12c),'sequence':_0x277fc6[_0x141534(0x126)],'event':_0x277fc6[_0x141534(0x118)]}];return[];});return{'entries':_0x2609a4,..._0x318108[_0x54a342(0x109)]===undefined?{}:{'nextCursor':String(_0x318108[_0x54a342(0x109)])}};},'readImage':async(_0x5773c1,_0x522452)=>{const _0x3d7107=_0x286e9c,_0x41b74a=await _0x35d14f[_0x3d7107(0x122)](_0x5773c1,_0x522452);return _0x41b74a===undefined?undefined:{'name':_0x41b74a[_0x3d7107(0x112)],'mimeType':_0x41b74a[_0x3d7107(0x11a)],'byteSize':_0x41b74a[_0x3d7107(0x141)],'dataBase64':_0x41b74a[_0x3d7107(0x116)]};},'contextUsage':async _0x5067e8=>{const _0x39b4c0=_0x286e9c,_0xe9c702=await _0x35d14f[_0x39b4c0(0x110)](_0x5067e8,{'limit':0x3e8});for(const _0x11c663 of _0xe9c702[_0x39b4c0(0x108)][_0x39b4c0(0x131)]()){if(!isMarAgentEvent(_0x11c663[_0x39b4c0(0x118)]))continue;if(_0x11c663[_0x39b4c0(0x118)][_0x39b4c0(0x10a)]===_0x39b4c0(0x124))return{'inputTokens':0x0};if(_0x11c663[_0x39b4c0(0x118)][_0x39b4c0(0x10a)]===_0x39b4c0(0x10e)){const _0x367966=_0x11c663[_0x39b4c0(0x118)][_0x39b4c0(0x107)]??_0x11c663[_0x39b4c0(0x118)][_0x39b4c0(0x11c)];if(typeof _0x367966===_0x39b4c0(0x115)&&Number[_0x39b4c0(0x13e)](_0x367966)&&_0x367966>=0x58e*-0x3+0x1c9*-0x7+-0x1d29*-0x1)return{'inputTokens':_0x367966};}}return undefined;},'fork':(_0x1d6d27,_0x131324)=>_0x35d14f[_0x286e9c(0x120)](_0x1d6d27,_0x131324),'rollback':(_0x16b830,_0x5b8504)=>_0x35d14f[_0x286e9c(0x121)](_0x16b830,_0x5b8504),'delete':_0x101508=>_0x35d14f[_0x286e9c(0x10d)](_0x101508),'close':()=>_0x35d14f[_0x286e9c(0x130)]()};}function parseCursor(_0x410359){const _0x2235bb=_0x65f843;if(_0x410359===undefined)return undefined;const _0x142619=Number(_0x410359);if(!Number[_0x2235bb(0x13e)](_0x142619)||_0x142619<0xf75+0x3bb*-0x4+-0x1*0x88)return undefined;return _0x142619;}function isRecord(_0x515f5a){const _0x56b1cf=_0x65f843;return _0x515f5a!==null&&typeof _0x515f5a===_0x56b1cf(0x12f)&&!Array[_0x56b1cf(0x113)](_0x515f5a);}function imageMetadata(_0x14bafd){const _0x4f945a=_0x65f843;if(!Array[_0x4f945a(0x113)](_0x14bafd))return[];return _0x14bafd[_0x4f945a(0x132)](_0x17a33f=>isRecord(_0x17a33f)&&typeof _0x17a33f[_0x4f945a(0x112)]===_0x4f945a(0x11b)&&typeof _0x17a33f[_0x4f945a(0x11a)]===_0x4f945a(0x11b)&&typeof _0x17a33f[_0x4f945a(0x141)]===_0x4f945a(0x115)&&Number[_0x4f945a(0x13e)](_0x17a33f[_0x4f945a(0x141)])&&_0x17a33f[_0x4f945a(0x141)]>=-0xb0+0x1204+-0x1154?[{'name':_0x17a33f[_0x4f945a(0x112)],'mimeType':_0x17a33f[_0x4f945a(0x11a)],'byteSize':_0x17a33f[_0x4f945a(0x141)],'readable':INPUT_IMAGE_MIME_TYPES[_0x4f945a(0x12e)](_0x17a33f[_0x4f945a(0x11a)])&&_0x17a33f[_0x4f945a(0x141)]>-0x2382+-0x2014+-0x52*-0xd3&&_0x17a33f[_0x4f945a(0x141)]<=MAX_INPUT_IMAGE_BYTES&&typeof _0x17a33f[_0x4f945a(0x139)]===_0x4f945a(0x11b)&&/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}\.bin$/u[_0x4f945a(0x13f)](_0x17a33f[_0x4f945a(0x139)])&&typeof _0x17a33f[_0x4f945a(0x106)]===_0x4f945a(0x11b)&&/^[a-f0-9]{64}$/u[_0x4f945a(0x13f)](_0x17a33f[_0x4f945a(0x106)])}]:[]);}function isMarAgentEvent(_0x2e8ffd){const _0x1ad8cb=_0x65f843;return isRecord(_0x2e8ffd)&&typeof _0x2e8ffd[_0x1ad8cb(0x10a)]===_0x1ad8cb(0x11b)&&typeof _0x2e8ffd[_0x1ad8cb(0x12a)]===_0x1ad8cb(0x11b)&&typeof _0x2e8ffd[_0x1ad8cb(0x126)]===_0x1ad8cb(0x115)&&typeof _0x2e8ffd[_0x1ad8cb(0x10c)]===_0x1ad8cb(0x11b)&&typeof _0x2e8ffd[_0x1ad8cb(0x12d)]===_0x1ad8cb(0x11b)&&typeof _0x2e8ffd[_0x1ad8cb(0x111)]===_0x1ad8cb(0x11b);}
1
+ import { JsonlSessionStore } from './jsonl-store.js';
2
+ const MAX_INPUT_IMAGE_BYTES = 5 * 1024 * 1024;
3
+ const INPUT_IMAGE_MIME_TYPES = new Set(['image/png', 'image/jpeg', 'image/gif', 'image/webp']);
4
+ export async function openMarAgentSessionCatalog(input) {
5
+ const store = await JsonlSessionStore.open(input.homeDirectory);
6
+ return {
7
+ list: (options) => store.list(options),
8
+ history: async (sessionId, options = {}) => {
9
+ const beforeSequence = parseCursor(options.cursor);
10
+ const page = await store.readPage(sessionId, {
11
+ ...(options.limit === undefined ? {} : { limit: options.limit }),
12
+ ...(beforeSequence === undefined ? {} : { beforeSequence })
13
+ });
14
+ const entries = page.records.flatMap((record) => {
15
+ if (record.type === 'turn.user' &&
16
+ record.executionId !== undefined &&
17
+ record.turnId !== undefined &&
18
+ isRecord(record.payload) &&
19
+ typeof record.payload.prompt === 'string') {
20
+ const images = imageMetadata(record.payload.images);
21
+ return [
22
+ {
23
+ kind: 'user',
24
+ sequence: record.sequence,
25
+ timestamp: record.timestamp,
26
+ sessionId: record.sessionId,
27
+ executionId: record.executionId,
28
+ turnId: record.turnId,
29
+ text: record.payload.prompt,
30
+ ...(typeof record.payload.clientMessageId === 'string'
31
+ ? { clientMessageId: record.payload.clientMessageId }
32
+ : {}),
33
+ ...(record.payload.inputSource === 'parent_agent'
34
+ ? { inputSource: 'parent_agent' }
35
+ : {}),
36
+ ...(images.length > 0 ? { images } : {})
37
+ }
38
+ ];
39
+ }
40
+ if (isMarAgentEvent(record.payload))
41
+ return [{ kind: 'event', sequence: record.sequence, event: record.payload }];
42
+ return [];
43
+ });
44
+ return {
45
+ entries,
46
+ ...(page.previousBeforeSequence === undefined
47
+ ? {}
48
+ : { nextCursor: String(page.previousBeforeSequence) })
49
+ };
50
+ },
51
+ readImage: async (sessionId, input) => {
52
+ const image = await store.readInputImage(sessionId, input);
53
+ return image === undefined
54
+ ? undefined
55
+ : {
56
+ name: image.name,
57
+ mimeType: image.mimeType,
58
+ byteSize: image.byteSize,
59
+ dataBase64: image.dataBase64
60
+ };
61
+ },
62
+ contextUsage: async (sessionId) => {
63
+ const page = await store.readPage(sessionId, { limit: 1000 });
64
+ for (const record of page.records.toReversed()) {
65
+ if (!isMarAgentEvent(record.payload))
66
+ continue;
67
+ if (record.payload.type === 'context.compacted')
68
+ return { inputTokens: 0 };
69
+ if (record.payload.type === 'usage.updated') {
70
+ const inputTokens = record.payload.contextInputTokens ?? record.payload.inputTokens;
71
+ if (typeof inputTokens === 'number' &&
72
+ Number.isSafeInteger(inputTokens) &&
73
+ inputTokens >= 0)
74
+ return { inputTokens };
75
+ }
76
+ }
77
+ return undefined;
78
+ },
79
+ fork: async (sessionId, options) => {
80
+ const session = await store.forkSession(sessionId, options);
81
+ return { ...session, source: session.source ?? { type: 'user' } };
82
+ },
83
+ rollback: (sessionId, options) => store.rollbackSession(sessionId, options),
84
+ clear: (sessionId) => store.clearSession(sessionId),
85
+ delete: (sessionId) => store.delete(sessionId),
86
+ close: () => store.close()
87
+ };
88
+ }
89
+ function parseCursor(cursor) {
90
+ if (cursor === undefined)
91
+ return undefined;
92
+ const value = Number(cursor);
93
+ if (!Number.isSafeInteger(value) || value < 1)
94
+ return undefined;
95
+ return value;
96
+ }
97
+ function isRecord(value) {
98
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
99
+ }
100
+ function imageMetadata(value) {
101
+ if (!Array.isArray(value))
102
+ return [];
103
+ return value.flatMap((image) => isRecord(image) &&
104
+ typeof image.name === 'string' &&
105
+ typeof image.mimeType === 'string' &&
106
+ typeof image.byteSize === 'number' &&
107
+ Number.isSafeInteger(image.byteSize) &&
108
+ image.byteSize >= 0
109
+ ? [
110
+ {
111
+ name: image.name,
112
+ mimeType: image.mimeType,
113
+ byteSize: image.byteSize,
114
+ readable: INPUT_IMAGE_MIME_TYPES.has(image.mimeType) &&
115
+ image.byteSize > 0 &&
116
+ image.byteSize <= MAX_INPUT_IMAGE_BYTES &&
117
+ typeof image.fileName === 'string' &&
118
+ /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}\.bin$/u.test(image.fileName) &&
119
+ typeof image.sha256 === 'string' &&
120
+ /^[a-f0-9]{64}$/u.test(image.sha256)
121
+ }
122
+ ]
123
+ : []);
124
+ }
125
+ function isMarAgentEvent(value) {
126
+ return (isRecord(value) &&
127
+ typeof value.type === 'string' &&
128
+ typeof value.eventId === 'string' &&
129
+ typeof value.sequence === 'number' &&
130
+ typeof value.timestamp === 'string' &&
131
+ typeof value.sessionId === 'string' &&
132
+ typeof value.executionId === 'string');
133
+ }
@@ -0,0 +1,148 @@
1
+ import { type ContextGcSubagentToolName } from './context-gc-subagent.js';
2
+ import type { SessionRecord } from './jsonl-store.js';
3
+ export declare const CONTEXT_GC_CHECKPOINT_VERSION: 1;
4
+ export declare const CONTEXT_GC_MAX_TARGETS = 4096;
5
+ export type ContextGcPlatform = 'linux' | 'darwin' | 'win32';
6
+ export interface ContextGcEconomicsPolicy {
7
+ readonly version: 1;
8
+ readonly immediatePaybackRollouts: number;
9
+ readonly maximumPaybackRollouts: number;
10
+ readonly contextGrowthSampleWindow: number;
11
+ readonly minimumContextGrowthSamples: number;
12
+ readonly minimumObservationRollouts: number;
13
+ readonly stageAProtectionRollouts: number;
14
+ readonly largeExecProtectionRollouts: number;
15
+ readonly normalInputCostRate: number;
16
+ readonly cacheReadCostRate: number;
17
+ readonly cacheWriteCostRate: number;
18
+ readonly outputCostRate: number;
19
+ readonly minimumGrossReductionRate: number;
20
+ readonly minimumCacheInvestmentRoi: number;
21
+ }
22
+ export type ContextGcBase = {
23
+ readonly type: 'SESSION_START';
24
+ readonly firstSequence: number;
25
+ } | {
26
+ readonly type: 'COMPACT';
27
+ readonly sequence: number;
28
+ readonly recordId: string;
29
+ };
30
+ export interface ContextGcTarget {
31
+ readonly sequence: number;
32
+ readonly recordId: string;
33
+ readonly role: 'tool_call' | 'tool' | 'provider';
34
+ readonly callId?: string;
35
+ readonly toolName?: string;
36
+ readonly sourceHash: string;
37
+ }
38
+ export interface ContextGcReadItemReplacement {
39
+ readonly index: number;
40
+ readonly path: string;
41
+ readonly replacement: string;
42
+ readonly evidenceSequence: number;
43
+ }
44
+ export type ContextGcReplacement = {
45
+ readonly kind: 'READ_OUTPUT_ITEMS';
46
+ readonly callId: string;
47
+ readonly target: ContextGcTarget;
48
+ readonly items: readonly ContextGcReadItemReplacement[];
49
+ readonly evidenceSequences: readonly number[];
50
+ } | {
51
+ readonly kind: 'TOOL_CALL_INPUT';
52
+ readonly toolName: 'apply_patch' | 'exec';
53
+ readonly callId: string;
54
+ readonly target: ContextGcTarget;
55
+ readonly replacementArguments: unknown;
56
+ readonly providerAliasTargets: readonly ContextGcTarget[];
57
+ readonly evidenceSequence: number;
58
+ } | {
59
+ readonly kind: 'EXEC_OUTPUT';
60
+ readonly callId: string;
61
+ readonly target: ContextGcTarget;
62
+ readonly replacementContent: string;
63
+ readonly evidenceSequence: number;
64
+ } | {
65
+ readonly kind: 'SUBAGENT_OUTPUT';
66
+ readonly toolName: 'agent_wait' | 'agent_message';
67
+ readonly callId: string;
68
+ readonly target: ContextGcTarget;
69
+ readonly replacementContent: string;
70
+ readonly terminalToolName: ContextGcSubagentToolName;
71
+ readonly terminalCallId: string;
72
+ readonly evidenceSequence: number;
73
+ readonly retainedPriorFinal?: {
74
+ readonly toolName: ContextGcSubagentToolName;
75
+ readonly callId: string;
76
+ readonly evidenceSequence: number;
77
+ };
78
+ };
79
+ export interface ContextGcMetrics {
80
+ readonly stage: 'STAGE_A' | 'STAGE_A_AND_EXEC';
81
+ readonly tokenEstimator?: 'UTF8_BYTES_V1';
82
+ readonly beforeTokens: number;
83
+ readonly afterTokens: number;
84
+ readonly reclaimedTokens: number;
85
+ readonly grossReductionRate: number;
86
+ readonly effectiveMinimumGrossReductionRate?: number;
87
+ readonly minimumRequiredReclaimedTokens?: number;
88
+ readonly cacheRebuildPenaltyCostUnits: number;
89
+ readonly compactDeferralCreditCostUnits: number;
90
+ readonly imminentCompactAvoidanceCreditCostUnits?: number;
91
+ readonly appliedCompactCreditCostUnits?: number;
92
+ readonly requiredPositiveNetRollouts: number;
93
+ readonly requiredTargetRoiRollouts: number;
94
+ readonly projectedRolloutsUntilCompactAfterGc: number;
95
+ readonly projectedTokensBeforeGc?: number;
96
+ readonly projectedTokensAfterGc?: number;
97
+ readonly contextGrowthSampleCount: number;
98
+ readonly contextGrowthP75Tokens: number;
99
+ readonly expectedNetSavedCostUnits: number;
100
+ readonly cacheInvestmentRoi: number;
101
+ readonly minimumObservedRollouts: number;
102
+ readonly protectedCandidateTokens: number;
103
+ readonly eligibleCandidateCount: number;
104
+ readonly eligibleTargetCount: number;
105
+ readonly cachePenaltyKnown?: boolean;
106
+ }
107
+ export interface ContextGcCheckpointDraft {
108
+ readonly version: 1;
109
+ readonly base: ContextGcBase;
110
+ readonly boundarySequence: number;
111
+ sourceProjectionHash: string;
112
+ readonly replacements: readonly ContextGcReplacement[];
113
+ readonly trigger: {
114
+ readonly usageSequence: number;
115
+ readonly contextInputTokens: number;
116
+ readonly contextWindowTokens: number;
117
+ readonly normalRolloutOrdinal: number;
118
+ readonly modelId: string;
119
+ readonly platform: ContextGcPlatform;
120
+ };
121
+ readonly economics: ContextGcEconomicsPolicy;
122
+ readonly metrics: ContextGcMetrics;
123
+ }
124
+ export interface ContextGcCheckpointPayload extends ContextGcCheckpointDraft {
125
+ readonly checkpointId: string;
126
+ readonly generation: number;
127
+ }
128
+ /** Disposable memoization for one evaluation's immutable record snapshot. */
129
+ export declare class ContextGcCheckpointCache {
130
+ #private;
131
+ read(records: readonly SessionRecord[], boundarySequence?: number, workspace?: string | undefined): ReturnType<typeof latestValidContextGcCheckpoint>;
132
+ }
133
+ export declare function contextGcMinimumUsageGrowth(contextWindowTokens: number): number;
134
+ export declare function contextGcRecordSourceHash(record: Pick<SessionRecord, 'payload'>): string;
135
+ export declare function contextGcLogicalPathKey(path: string, workspace: string, platform?: ContextGcPlatform): string | undefined;
136
+ export declare function contextGcTargetKey(target: ContextGcTarget): string;
137
+ export declare function contextGcReplacementKey(replacement: ContextGcReplacement): string;
138
+ export declare function contextGcBaseFromRecords(records: readonly SessionRecord[], boundarySequence?: number): ContextGcBase | undefined;
139
+ export declare function contextGcBaseSequence(base: ContextGcBase): number;
140
+ export declare function contextGcSourceProjectionHash(records: readonly SessionRecord[], boundarySequence: number, base?: ContextGcBase | undefined): string | undefined;
141
+ export declare function normalizeContextGcReplacements(replacements: readonly ContextGcReplacement[]): ContextGcReplacement[] | undefined;
142
+ export declare function parseContextGcCheckpoint(record: SessionRecord | undefined): ContextGcCheckpointPayload | undefined;
143
+ export declare function validateContextGcCheckpoint(records: readonly SessionRecord[], record: SessionRecord, workspace?: string | undefined): ContextGcCheckpointPayload | undefined;
144
+ export declare function latestValidContextGcCheckpoint(records: readonly SessionRecord[], boundarySequence?: number, workspace?: string | undefined): {
145
+ readonly record: SessionRecord;
146
+ readonly payload: ContextGcCheckpointPayload;
147
+ } | undefined;
148
+ export declare function sameContextGcBase(left: ContextGcBase | undefined, right: ContextGcBase | undefined): boolean;