@myagentroam/node 0.11.45 → 0.11.47

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 (37) hide show
  1. package/dist/connector.js +4 -4
  2. package/dist/database.js +7 -5
  3. package/dist/marctl-guidance.js +2 -2
  4. package/dist/migrations/v023.js +25 -0
  5. package/dist/runner/abstract-runner.js +1 -1
  6. package/dist/runner/claude/managed-run-controller.js +1 -1
  7. package/dist/runner/claude-code-runner.js +1 -1
  8. package/dist/runner/codex/managed-run-controller.js +1 -1
  9. package/dist/runner/codex-runner.js +10 -5
  10. package/dist/runner/mar-agent/agent-network-extension.js +54 -14
  11. package/dist/runner/mar-agent/conversation-normalizer.js +43 -3
  12. package/dist/runner/mar-agent/history-projection.js +1 -1
  13. package/dist/runner/mar-agent/hosted-conversation-runtime.js +1 -1
  14. package/dist/runner/mar-agent/managed-run-controller.js +2 -2
  15. package/dist/runner/mar-agent-runner.js +5 -5
  16. package/dist/runner/opencode/managed-run-controller.js +2 -2
  17. package/dist/runner/opencode-runner.js +5 -5
  18. package/dist/runner-profiles.js +1 -1
  19. package/dist/runtime-state.js +7 -7
  20. package/dist/service/agent-network-bindings.js +8 -7
  21. package/dist/service/agent-network-invoke.js +9 -9
  22. package/dist/service/agent-network-service.js +12 -7
  23. package/dist/service/continuous-run-coordinator.js +1 -1
  24. package/dist/service/external-session-resume-service.js +1 -1
  25. package/dist/service/goal-continuation-coordinator.js +3 -3
  26. package/dist/service/native-session-watch-service.js +6 -3
  27. package/dist/service/planned-restart-handoff.js +24 -5
  28. package/dist/service/restart-session-restorer.js +2 -2
  29. package/dist/service/session-recent-activity.js +1 -1
  30. package/dist/session/native-session-projection-service.js +39 -30
  31. package/dist/session/session-catalog-service.js +116 -90
  32. package/dist/session/session-command-service.js +1 -0
  33. package/dist/session/session-context-service.js +1 -1
  34. package/dist/session/session-lifecycle-service.js +12 -10
  35. package/dist/session/session-message-service.js +4 -3
  36. package/dist/workspace/workspace-session-service.js +1 -1
  37. package/package.json +4 -4
package/dist/connector.js CHANGED
@@ -443,7 +443,7 @@ export class NodeConnector {
443
443
  emitSession: (session) => this.emitSessionWorkbenchEvent({ session }),
444
444
  emitPage: (session, page) => this.emitWorkbenchEvent('conversation', {
445
445
  sessionId: session.id,
446
- snapshot: this.conversationSegmentService.projectInitial(session, page, 10)
446
+ snapshot: this.conversationSegmentService.projectInitial(session, page, 3)
447
447
  }),
448
448
  nodeId: () => this.config?.nodeId ?? 'runtime-node',
449
449
  nodeGeneration: () => this.nodeGeneration,
@@ -854,7 +854,7 @@ export class NodeConnector {
854
854
  prompt: item.content,
855
855
  modelText: prepared.input,
856
856
  clientMessageId: item.clientMessageId,
857
- model: prepared.model,
857
+ modelId: prepared.modelId,
858
858
  effort: prepared.effort,
859
859
  access: prepared.access,
860
860
  collaborationMode: prepared.collaborationMode,
@@ -968,7 +968,7 @@ export class NodeConnector {
968
968
  runner: session.runner,
969
969
  externalSessionId: nativeSessionId,
970
970
  workspaceId: session.workspaceId,
971
- ...(session.model === null ? {} : { model: session.model }),
971
+ ...(session.modelId === null ? {} : { modelId: session.modelId }),
972
972
  ...(session.effort === null ? {} : { effort: session.effort }),
973
973
  ...(session.access === null ? {} : { access: session.access }),
974
974
  ...(session.customTitle === null ? {} : { customTitle: session.customTitle }),
@@ -1508,7 +1508,7 @@ export class NodeConnector {
1508
1508
  workspaceId: task.workspaceId,
1509
1509
  ownerUserId: task.ownerUserId,
1510
1510
  runner: task.runner,
1511
- model: configuredSession.model
1511
+ modelId: configuredSession.modelId
1512
1512
  });
1513
1513
  return {
1514
1514
  secretEnvironment: context.secretEnvironment,
package/dist/database.js CHANGED
@@ -4,6 +4,7 @@ import { NODE_SCHEMA_MIGRATION_V19 } from './migrations/v019.js';
4
4
  import { NODE_SCHEMA_MIGRATION_V20 } from './migrations/v020.js';
5
5
  import { NODE_SCHEMA_MIGRATION_V21 } from './migrations/v021.js';
6
6
  import { NODE_SCHEMA_MIGRATION_V22 } from './migrations/v022.js';
7
+ import { NODE_SCHEMA_MIGRATION_V23 } from './migrations/v023.js';
7
8
  import { normalizeSessionPrompt } from './runner/personal-instructions.js';
8
9
  import { randomUUID } from 'node:crypto';
9
10
  import { closeSync, existsSync, mkdirSync, openSync, rmSync } from 'node:fs';
@@ -27,7 +28,8 @@ export const NODE_SCHEMA_MIGRATIONS = [
27
28
  NODE_SCHEMA_MIGRATION_V19,
28
29
  NODE_SCHEMA_MIGRATION_V20,
29
30
  NODE_SCHEMA_MIGRATION_V21,
30
- NODE_SCHEMA_MIGRATION_V22
31
+ NODE_SCHEMA_MIGRATION_V22,
32
+ NODE_SCHEMA_MIGRATION_V23
31
33
  ];
32
34
  const LEGACY_NODE_SCHEMA_V12 = NODE_SCHEMA_VERSION_V13 - 1;
33
35
  const OBSOLETE_NODE_SCHEMA_V16 = 16;
@@ -314,7 +316,7 @@ export class NodeDatabase {
314
316
  pinOrder = 0;
315
317
  else if (input.pinned === false)
316
318
  pinOrder = null;
317
- const model = input.model === undefined ? (current?.model ?? null) : input.model;
319
+ const model = input.modelId === undefined ? (current?.modelId ?? null) : input.modelId;
318
320
  const effort = input.effort === undefined ? (current?.effort ?? null) : input.effort;
319
321
  const access = input.access === undefined ? (current?.access ?? null) : input.access;
320
322
  const parentSessionId = current === undefined || input.initializeParent === true
@@ -326,7 +328,7 @@ export class NodeDatabase {
326
328
  sessionPrompt,
327
329
  runnerTitle,
328
330
  runnerTitlePending,
329
- model,
331
+ modelId: model,
330
332
  effort,
331
333
  access
332
334
  });
@@ -367,7 +369,7 @@ export class NodeDatabase {
367
369
  runnerTitlePending,
368
370
  pinnedAt: pinOrder === null ? null : 1,
369
371
  pinOrder,
370
- model,
372
+ modelId: model,
371
373
  effort,
372
374
  access
373
375
  };
@@ -666,7 +668,7 @@ function sessionMetadata(row) {
666
668
  sessionPrompt: value('sessionPrompt'),
667
669
  runnerTitle: value('runnerTitle'),
668
670
  runnerTitlePending: raw['runnerTitlePending'] === true,
669
- model: value('model'),
671
+ modelId: value('modelId'),
670
672
  effort: value('effort'),
671
673
  access: value('access')
672
674
  };
@@ -10,7 +10,7 @@ const marctlSafety = 'Acceptance is not completion. If a request result is unkno
10
10
  export const marctlManagementInstructions = [
11
11
  '## MAR Workspace management',
12
12
  'Use native agent_* tools for Agent discovery, creation, communication, observation, waiting and stopping. Do not switch to marctl when a native operation fails.',
13
- 'Use marctl agents config <id> --model <id> --effort <effort> to change future model settings; agents rename <id> --title <title> changes a title.',
13
+ 'Use marctl agents config <id> --model-id <id> --effort <effort> to change future model settings; agents rename <id> --title <title> changes a title.',
14
14
  'Use agents prompt get/set/clear for persistent instructions; set accepts -m or --message-file. Use agents schedule list/get/create/update for scheduled tasks; update requires --expected-revision.',
15
15
  'marctl nodes lists authorized Nodes; marctl ssh executes remote commands and marctl scp transfers files. Use marctl help agents, nodes, ssh or scp for options.',
16
16
  marctlSafety
@@ -19,7 +19,7 @@ export const marctlDescription = 'Use marctl agents to create, send to, wait for
19
19
  export const marctlInstructions = [
20
20
  '## MAR Workspace CLI',
21
21
  'Run marctl from the shell. Commands use the authenticated Node and Workspace; marctl help agents, nodes, ssh or scp shows options.',
22
- 'Use agents start --title <title> -m <text> [--runner <runner>] [--model <id>] [--effort <effort>] [--goal <objective>]. An Agent must supply a nonblank title; a manual terminal may omit it. The default Runner is the current Session Runner; a terminal without a current Session must specify --runner or an explicit --parent. Start returns without waiting.',
22
+ 'Use agents start --title <title> -m <text> [--runner <runner>] [--model-id <id>] [--effort <effort>] [--goal <objective>]. An Agent must supply a nonblank title; a manual terminal may omit it. The default Runner is the current Session Runner; a terminal without a current Session must specify --runner or an explicit --parent. Start returns without waiting.',
23
23
  'Use agents send <id> -m <text> [--steer|--queue], agents wait [<id>] [--wait-for message|completion] [--timeout <duration>], agents stop <id> --execution <execution-id>, agents list [--scope children|descendants|workspace|profile], and agents view <id> [--history]. Wait defaults to direct-child completion for 30 seconds; --timeout 0ms takes a snapshot. Stop clears the target Session Goal.',
24
24
  'Prefer agents send <id> --steer -m <text> for timely communication or course correction. Use --queue only for deliberately deferred input: it is consumed after current work and earlier queued inputs finish, and with an active Goal it is not consumed until that Goal exits. Acceptance is not a guarantee of immediate processing.',
25
25
  'Start and send accept repeated --image <local-path> for PNG, JPEG, GIF or WebP; limits are five images, 5 MiB each and 10 MiB total. Send can update a Goal alone with --goal <objective> or --clear-goal; omitted Goal leaves it unchanged. Decide a direct child approval with send <id> --approval <approval-id> --decision approve|reject.',
@@ -0,0 +1,25 @@
1
+ import { NODE_SCHEMA_MIGRATION_V22 } from './v022.js';
2
+ const defaultPaths = ['codex', 'claude-code', 'opencode', 'mar-agent'].map((runner) => `$.runnerDefaults."${runner}"`);
3
+ const rename = (column, path) => `json_remove(CASE WHEN json_type(${column}, '${path}.modelId') IS NULL
4
+ THEN json_set(${column}, '${path}.modelId', json_extract(${column}, '${path}.model'))
5
+ ELSE ${column} END, '${path}.model')`;
6
+ export const NODE_SCHEMA_MIGRATION_V23 = {
7
+ version: 23,
8
+ sql: [
9
+ `UPDATE agent_sessions SET metadata = ${rename('metadata', '$')}
10
+ WHERE json_type(metadata, '$.model') IS NOT NULL;`,
11
+ ...defaultPaths.map((path) => `UPDATE node_settings SET settings = ${rename('settings', path)}
12
+ WHERE json_type(settings, '${path}.model') IS NOT NULL;`)
13
+ ].join('\n'),
14
+ preflight: (database) => NODE_SCHEMA_MIGRATION_V22.assert(database),
15
+ assert(database) {
16
+ NODE_SCHEMA_MIGRATION_V22.assert(database);
17
+ if (database
18
+ .prepare("SELECT 1 FROM agent_sessions WHERE json_type(metadata, '$.model') IS NOT NULL")
19
+ .get() !== undefined ||
20
+ defaultPaths.some((path) => database
21
+ .prepare(`SELECT 1 FROM node_settings WHERE json_type(settings, '${path}.model') IS NOT NULL`)
22
+ .get() !== undefined))
23
+ throw new Error('NODE_DATABASE_SCHEMA_INVALID:modelId');
24
+ }
25
+ };
@@ -30,7 +30,7 @@ export class AbstractRunner {
30
30
  supportsConfiguration(configuration, workspace, environment) {
31
31
  void [workspace, environment];
32
32
  const profile = this.profileForValidation();
33
- const model = profile.models.find((candidate) => candidate.id === configuration.model);
33
+ const model = profile.models.find((candidate) => candidate.id === configuration.modelId);
34
34
  return (configuration.runner === this.name &&
35
35
  model !== undefined &&
36
36
  model.supportedEfforts.includes(configuration.effort) &&
@@ -62,7 +62,7 @@ export class ClaudeManagedRunController {
62
62
  input,
63
63
  cwd: session.cwd,
64
64
  externalSessionId: session.externalSessionId,
65
- model: session.model,
65
+ model: session.modelId,
66
66
  effort: session.effort,
67
67
  access: session.access,
68
68
  secretEnvironment
@@ -49,7 +49,7 @@ export class ClaudeCodeRunner extends AbstractRunner {
49
49
  defaultConfiguration() {
50
50
  return {
51
51
  runner: this.name,
52
- model: claudeDefaultModel(this.environment),
52
+ modelId: claudeDefaultModel(this.environment),
53
53
  effort: 'medium',
54
54
  access: 'default'
55
55
  };
@@ -400,7 +400,7 @@ export class CodexManagedRunController {
400
400
  usage = new CodexUsageNormalizer(runId, (value) => this.host.emit(runId, 'run.usage', {
401
401
  ...value,
402
402
  sessionId: this.runner.execution.runs.get(runId)?.threadId
403
- }), active ? (this.host.session(active.sessionId)?.model ?? undefined) : undefined);
403
+ }), active ? (this.host.session(active.sessionId)?.modelId ?? undefined) : undefined);
404
404
  this.usage.set(runId, usage);
405
405
  }
406
406
  return usage;
@@ -202,7 +202,7 @@ export class CodexRunner extends AbstractRunner {
202
202
  ? emptyCodexConfiguration()
203
203
  : {
204
204
  runner: this.name,
205
- model: selected.model,
205
+ modelId: selected.model,
206
206
  effort: selected.defaultEffort,
207
207
  access: 'on-request'
208
208
  }
@@ -361,7 +361,8 @@ export class CodexRunner extends AbstractRunner {
361
361
  return false;
362
362
  const profile = this.profileCacheForEnvironment(environment)?.profile;
363
363
  return (profile !== undefined &&
364
- profile.models.some((model) => model.id === configuration.model && model.supportedEfforts.includes(configuration.effort)) &&
364
+ profile.models.some((model) => model.id === configuration.modelId &&
365
+ model.supportedEfforts.includes(configuration.effort)) &&
365
366
  profile.accessOptions.some((option) => option.id === configuration.access));
366
367
  }
367
368
  profileCacheForEnvironment(_environment) {
@@ -695,7 +696,11 @@ export class CodexRunner extends AbstractRunner {
695
696
  const threadId = session.externalSessionId;
696
697
  if (threadId === null)
697
698
  throw new Error('SESSION_REWIND_UNAVAILABLE');
698
- const configuration = { model: session.model, effort: session.effort, access: session.access };
699
+ const configuration = {
700
+ model: session.modelId,
701
+ effort: session.effort,
702
+ access: session.access
703
+ };
699
704
  return this.withTemporaryClient(async (client) => {
700
705
  const result = boundary === null
701
706
  ? await client.startThread(session.cwd, configuration)
@@ -719,7 +724,7 @@ export class CodexRunner extends AbstractRunner {
719
724
  const threadId = session.externalSessionId;
720
725
  return this.withTemporaryClient(async (client) => {
721
726
  const resumed = await client.resumeThread(threadId, session.cwd, {
722
- model: session.model,
727
+ model: session.modelId,
723
728
  effort: session.effort,
724
729
  access: session.access
725
730
  });
@@ -753,7 +758,7 @@ export class CodexRunner extends AbstractRunner {
753
758
  }
754
759
  }
755
760
  function emptyCodexConfiguration() {
756
- return { runner: 'codex', model: '', effort: '', access: 'on-request' };
761
+ return { runner: 'codex', modelId: '', effort: '', access: 'on-request' };
757
762
  }
758
763
  function codexModelPage(value) {
759
764
  if (!isPlainRecord(value) || !Array.isArray(value.data))
@@ -1,6 +1,10 @@
1
1
  import { agentNetworkWaitModelOutput } from './agent-network-wait-output.js';
2
2
  import { agentOperationEvent } from './agent-operation-presentation.js';
3
3
  const text = { type: 'string', minLength: 1 };
4
+ const runner = {
5
+ ...text,
6
+ description: 'Runner type (for example mar-agent), not a model name; defaults to the current Runner.'
7
+ };
4
8
  const attachmentIds = {
5
9
  type: 'array',
6
10
  items: text,
@@ -42,8 +46,11 @@ const tools = [
42
46
  content: { type: 'string' },
43
47
  attachments,
44
48
  attachmentIds,
45
- runner: text,
46
- model: text,
49
+ runner,
50
+ modelId: {
51
+ ...text,
52
+ description: 'Model ID from the target Runner Profile models[].id, not a display name. For MAR Agent this is an internal configuration ID, not an upstream model ID; omit to use the Runner default.'
53
+ },
47
54
  effort: text,
48
55
  title: text,
49
56
  goal,
@@ -53,7 +60,7 @@ const tools = [
53
60
  },
54
61
  {
55
62
  action: 'send',
56
- description: 'Send input, decide an approval or update a Goal; goal:null leaves it unchanged, goal:{clear:true} clears it. Prefer REPLACE_CURRENT for timely communication or course correction. QUEUE is consumed only after current work and earlier queued inputs finish; an active Goal must exit first. Sending to a non-child does not subscribe to its updates.',
63
+ description: 'Send input, decide an approval or update a Goal; goal:null leaves it unchanged, goal:{clear:true} clears it. Messages default to REPLACE_CURRENT (steer); use QUEUE only when deferred delivery is explicitly requested. QUEUE is consumed only after current work and earlier queued inputs finish; an active Goal must exit first.',
57
64
  properties: {
58
65
  agentId: text,
59
66
  content: { type: 'string' },
@@ -66,14 +73,18 @@ const tools = [
66
73
  required: ['approvalId', 'decision'],
67
74
  properties: { approvalId: text, decision: { type: 'string', enum: ['approve', 'reject'] } }
68
75
  },
69
- deliveryIntent: { type: 'string', enum: ['SEND', 'QUEUE', 'REPLACE_CURRENT'] },
76
+ deliveryIntent: {
77
+ type: 'string',
78
+ enum: ['SEND', 'QUEUE', 'REPLACE_CURRENT'],
79
+ description: 'Message delivery defaults to REPLACE_CURRENT (steer); explicit SEND remains supported.'
80
+ },
70
81
  clientMessageId: text
71
82
  },
72
83
  required: ['agentId']
73
84
  },
74
85
  {
75
86
  action: 'wait',
76
- description: 'Wait for completion or messages; defaults to direct children, completion and 30 seconds. Use waitMs 0 for a snapshot. Non-child targets are observed only during this call.',
87
+ description: 'Wait for completion or messages; defaults to direct children, completion and 30 seconds. Use waitMs 0 for a snapshot.',
77
88
  properties: {
78
89
  agentId: text,
79
90
  agentIds: { type: 'array', items: text, minItems: 1, maxItems: 8 },
@@ -90,13 +101,18 @@ const tools = [
90
101
  },
91
102
  {
92
103
  action: 'list',
93
- description: 'List Sessions, descendants or a Runner profile.',
104
+ description: 'List direct children by default, discover Workspace Sessions, inspect descendants or query a Runner profile.',
94
105
  properties: {
95
106
  scope: { type: 'string', enum: ['workspace', 'children', 'descendants', 'profile'] },
96
- agentId: text,
97
- parent: text,
98
- runner: text,
99
- query: { type: 'string' },
107
+ agentId: {
108
+ ...text,
109
+ description: 'Root for children or descendants; defaults to the current Session.'
110
+ },
111
+ runner: {
112
+ ...runner,
113
+ description: 'Runner for profile scope; defaults to the current Runner, not a model name.'
114
+ },
115
+ query: { type: 'string', description: 'Search Sessions; not a model selector.' },
100
116
  limit: { type: 'integer', minimum: 1, maximum: 100 },
101
117
  cursor: text
102
118
  }
@@ -117,12 +133,14 @@ const delegationPrompt = [
117
133
  '# Delegation and coordination',
118
134
  'Delegate bounded, self-contained tasks when independent progress or context savings materially helps. Keep simple or tightly coupled work local.',
119
135
  'Give each child an objective, necessary context, expected output, and a read-only boundary or non-overlapping write scope.',
136
+ 'Follow up through the direct delegate by default; inspect deeper Sessions only when a concrete issue needs independent verification.',
120
137
  'While children run, continue meaningful non-overlapping work. Do not redo delegated work. Wait only when the next step needs the result.',
121
138
  'Verify consequential findings and changes. Join or stop task-required child work before final delivery, and retain responsibility for the final result.'
122
139
  ].join('\n\n');
123
140
  const collaborationPrompt = [
124
141
  '# Workspace collaboration',
125
- "Use native agent_* tools to collaborate within the Agent Network when another Session's context or ongoing work materially helps. Keep requests focused and avoid unnecessary cross-Session coordination. Peer Sessions retain their own work and lifecycle; do not treat them as task-owned children or stop them merely for task cleanup. Sending to a non-child does not subscribe to its updates; explicitly wait when you need its progress or completion."
142
+ "Use native agent_* tools to collaborate within the Agent Network when another Session's context or ongoing work materially helps. Keep requests focused and avoid unnecessary cross-Session coordination. Peer Sessions retain their own work and lifecycle; do not treat them as task-owned children or stop them merely for task cleanup. Explicitly wait when you need progress or completion.",
143
+ "Reuse known Session IDs rather than rediscovering them. Send updates for meaningful progress, blockers, or changes that affect the recipient's work; combine related updates and avoid acknowledgment-only exchanges."
126
144
  ].join('\n\n');
127
145
  const managementPrompt = [
128
146
  '# Workspace management',
@@ -168,7 +186,7 @@ export function agentNetworkExtension(invoke, currentExecution) {
168
186
  'title',
169
187
  'executionId',
170
188
  'runner',
171
- 'model',
189
+ 'modelId',
172
190
  'effort',
173
191
  'waitFor',
174
192
  'waitMs',
@@ -184,12 +202,34 @@ export function agentNetworkExtension(invoke, currentExecution) {
184
202
  const executionId = currentExecution();
185
203
  if (!executionId)
186
204
  throw new Error('AGENT_ACTOR_NOT_ACTIVE');
187
- const result = await invoke(executionId, tool.action, input, call);
205
+ const args = input;
206
+ const operationInput = tool.action === 'send' &&
207
+ args.deliveryIntent === undefined &&
208
+ ((typeof args.content === 'string' && !!args.content.trim()) ||
209
+ (Array.isArray(args.attachments) && args.attachments.length > 0) ||
210
+ (Array.isArray(args.attachmentIds) && args.attachmentIds.length > 0))
211
+ ? { ...args, deliveryIntent: 'REPLACE_CURRENT' }
212
+ : args;
213
+ const onResolved = call.publishEventData
214
+ ? async (sessions) => {
215
+ const rows = sessions.map((session) => ({
216
+ agentId: session.id,
217
+ title: session.customTitle ?? session.runnerTitle ?? undefined
218
+ }));
219
+ const result = tool.action === 'wait'
220
+ ? { agents: rows }
221
+ : tool.action === 'view'
222
+ ? { session: rows[0] }
223
+ : (rows[0] ?? {});
224
+ await call.publishEventData(agentOperationEvent(tool.action, {}, result).eventData);
225
+ }
226
+ : undefined;
227
+ const result = await invoke(executionId, tool.action, operationInput, call, onResolved);
188
228
  const modelResult = tool.action === 'wait' ? agentNetworkWaitModelOutput(result) : result;
189
229
  return {
190
230
  data: result,
191
231
  content: JSON.stringify(modelResult),
192
- ...agentOperationEvent(tool.action, input, result)
232
+ ...agentOperationEvent(tool.action, operationInput, result)
193
233
  };
194
234
  }
195
235
  });
@@ -6,7 +6,7 @@ export function normalizeMarAgentUsage(usage) {
6
6
  }
7
7
  import { boundedConversationItemId, compactRunnerText, compactRunnerValue } from '../normalization.js';
8
8
  import { runnerErrorProjection } from '../runner-error.js';
9
- import { toolPresentationSchema } from '@myagentroam/protocol';
9
+ import { toolPresentationSchema, agentOperationPresentationSchema } from '@myagentroam/protocol';
10
10
  import { publicOutputSnapshot, publicToolOutput } from '../normalization.js';
11
11
  import { boundToolOutput } from '@myagentroam/protocol';
12
12
  import { agentOperationAction, agentOperationPresentation } from './agent-operation-presentation.js';
@@ -170,6 +170,20 @@ export class MarAgentConversationNormalizer {
170
170
  ...this.#codeModeToolResults(event)
171
171
  ];
172
172
  }
173
+ if (event.type === 'tool.updated') {
174
+ const state = this.#tools.get(event.callId);
175
+ if (!state?.active ||
176
+ state.toolName !== event.toolName ||
177
+ !agentOperationAction(event.toolName))
178
+ return [];
179
+ const operation = agentOperationPresentationSchema.safeParse(record(event.data)?.agentOperation);
180
+ if (!operation.success || operation.data.action !== agentOperationAction(event.toolName))
181
+ return [];
182
+ this.#tools.set(event.callId, { ...state, presentationData: event.data });
183
+ return [
184
+ genericToolItem(state.itemId, state.toolName, 'IN_PROGRESS', state.input, null, null, false, event.data, state.subagentTitle, state.subagentDetails, undefined, undefined, state.inputTruncated)
185
+ ];
186
+ }
173
187
  if (event.type === 'sleep.started') {
174
188
  const state = this.#tools.get(event.callId);
175
189
  if (state?.toolName !== 'sleep')
@@ -673,7 +687,7 @@ export class MarAgentConversationNormalizer {
673
687
  }
674
688
  const item = genericToolItem(state?.itemId ?? itemId('tool', event.callId), event.toolName, 'COMPLETED', state?.input, generatedImages.length === 0
675
689
  ? event.summary
676
- : generatedImages.map((image) => image.name).join(', '), null, event.outputTruncation !== undefined, event.data, agentId === undefined ? state?.subagentTitle : this.#subagentTitles.get(agentId), details, state?.sleepStartedAt, event.outputTruncation, state?.inputTruncated, event.summaryTruncated === true);
690
+ : generatedImages.map((image) => image.name).join(', '), null, event.outputTruncation !== undefined, mergeAgentOperationData(event.toolName, state?.presentationData, event.data), agentId === undefined ? state?.subagentTitle : this.#subagentTitles.get(agentId), details, state?.sleepStartedAt, event.outputTruncation, state?.inputTruncated, event.summaryTruncated === true);
677
691
  return [
678
692
  {
679
693
  ...item,
@@ -704,7 +718,11 @@ export class MarAgentConversationNormalizer {
704
718
  return [
705
719
  genericToolItem(state?.itemId ?? itemId('tool', event.callId), event.toolName, event.code === 'MAR_AGENT_CANCELLED' || event.code === 'MAR_AGENT_EXECUTION_CANCELLED'
706
720
  ? 'CANCELLED'
707
- : 'FAILED', state?.input, event.message ?? event.code, event.code, event.truncated === true, state?.presentationData, state?.subagentTitle, state?.subagentDetails, state?.sleepStartedAt, event.outputTruncation, state?.inputTruncated)
721
+ : 'FAILED', state?.input, event.message ?? event.code, event.code, event.truncated === true, agentOperationAction(event.toolName)
722
+ ? mergeAgentOperationData(event.toolName, state?.presentationData, event.data)
723
+ : event.data === undefined
724
+ ? state?.presentationData
725
+ : event.data, state?.subagentTitle, state?.subagentDetails, state?.sleepStartedAt, event.outputTruncation, state?.inputTruncated)
708
726
  ];
709
727
  }
710
728
  #codeModeToolResults(event) {
@@ -1027,6 +1045,28 @@ function codeExecutionError(data) {
1027
1045
  message: compactRunnerText(error.message, 1000)
1028
1046
  };
1029
1047
  }
1048
+ function mergeAgentOperationData(toolName, previous, current) {
1049
+ if (!agentOperationAction(toolName))
1050
+ return current;
1051
+ const before = agentOperationPresentationSchema.safeParse(record(previous)?.agentOperation);
1052
+ if (!before.success || before.data.action !== agentOperationAction(toolName))
1053
+ return current;
1054
+ const after = agentOperationPresentationSchema.safeParse(record(current)?.agentOperation);
1055
+ if (!after.success || after.data.action !== before.data.action) {
1056
+ return { ...record(current), agentOperation: before.data };
1057
+ }
1058
+ return {
1059
+ ...record(current),
1060
+ agentOperation: {
1061
+ ...after.data,
1062
+ targets: before.data.targets.map((target) => ({
1063
+ ...after.data.targets.find((candidate) => candidate.agentId === target.agentId),
1064
+ ...target
1065
+ })),
1066
+ ...(before.data.targetsTruncated ? { targetsTruncated: true } : {})
1067
+ }
1068
+ };
1069
+ }
1030
1070
  function genericToolItem(id, toolName, status, input, outputSummary = null, errorCode = null, truncated = false, output, subagentTitle, knownSubagentDetails, sleepStartedAt, outputTruncation, inputTruncated = false, summaryTruncated = false) {
1031
1071
  if (toolName === 'code_exec') {
1032
1072
  const code = typeof input === 'string' ? input : record(input)?.code;
@@ -15,7 +15,7 @@ export function projectMarAgentHistory(session, entries, options = {}) {
15
15
  runId: null,
16
16
  userItemId: null,
17
17
  status: 'INTERRUPTED',
18
- model: session.model,
18
+ model: session.modelId,
19
19
  effort: session.effort,
20
20
  access: session.access,
21
21
  rewind: { before: previous?.id ?? null, after: turnId },
@@ -470,7 +470,7 @@ export class MarAgentHostedConversationRuntime {
470
470
  function historySession(input) {
471
471
  return {
472
472
  id: input.sessionId,
473
- model: input.modelId ?? null,
473
+ modelId: input.modelId ?? null,
474
474
  effort: null,
475
475
  access: 'full-access'
476
476
  };
@@ -118,7 +118,7 @@ export class MarAgentManagedRunController {
118
118
  const execution = context.executionContext;
119
119
  const resolved = resolveMarAgentExecutionInput(execution?.runner === 'mar-agent'
120
120
  ? execution.runnerInput
121
- : undefined, session.model ?? '');
121
+ : undefined, session.modelId ?? '');
122
122
  if (resolved === undefined)
123
123
  throw new Error('RUNNER_COMMAND_UNAVAILABLE');
124
124
  const runId = randomUUID();
@@ -409,7 +409,7 @@ export class MarAgentManagedRunController {
409
409
  if (input.mode !== 'compact')
410
410
  this.#steerTargets.set(input.runId, async (request) => {
411
411
  if (controller.signal.aborted ||
412
- (request.model && request.model !== input.model.id) ||
412
+ (request.modelId && request.modelId !== input.model.id) ||
413
413
  (request.effort &&
414
414
  request.effort !==
415
415
  (reasoningEffort ??
@@ -232,7 +232,7 @@ export class MarAgentRunner extends AbstractRunner {
232
232
  if (configuration.runner !== this.name)
233
233
  return false;
234
234
  const profile = this.profileForValidation();
235
- const model = profile.models.find((candidate) => candidate.id === configuration.model);
235
+ const model = profile.models.find((candidate) => candidate.id === configuration.modelId);
236
236
  return (model !== undefined &&
237
237
  (model.supportedEfforts.length === 0
238
238
  ? configuration.effort === model.defaultEffort
@@ -246,7 +246,7 @@ export class MarAgentRunner extends AbstractRunner {
246
246
  const model = profile.models[0];
247
247
  return {
248
248
  runner: 'mar-agent',
249
- model: model?.id ?? '',
249
+ modelId: model?.id ?? '',
250
250
  effort: model?.defaultEffort ?? '',
251
251
  access: 'auto'
252
252
  };
@@ -357,7 +357,7 @@ export class MarAgentRunner extends AbstractRunner {
357
357
  }),
358
358
  ...(executionConfiguration?.modelId === undefined
359
359
  ? {}
360
- : { model: executionConfiguration.modelId }),
360
+ : { modelId: executionConfiguration.modelId }),
361
361
  ...(executionConfiguration?.reasoningEffort === undefined
362
362
  ? {}
363
363
  : { effort: executionConfiguration.reasoningEffort })
@@ -577,9 +577,9 @@ export class MarAgentRunner extends AbstractRunner {
577
577
  return [resolve(session.cwd), ...(generatedImages === undefined ? [] : [generatedImages])];
578
578
  }
579
579
  async readContextUsage(session) {
580
- if (session.externalSessionId === null || session.model === null)
580
+ if (session.externalSessionId === null || session.modelId === null)
581
581
  return undefined;
582
- const model = this.#models.find((candidate) => candidate.id === session.model);
582
+ const model = this.#models.find((candidate) => candidate.id === session.modelId);
583
583
  if (model === undefined)
584
584
  return undefined;
585
585
  let catalog;
@@ -51,7 +51,7 @@ export class OpenCodeManagedRunController {
51
51
  }
52
52
  compact(session, environment, initiatedByUserId) {
53
53
  if (session.externalSessionId === null ||
54
- session.model === null ||
54
+ session.modelId === null ||
55
55
  session.nativeControl !== 'MAR_MANAGED' ||
56
56
  this.host.hasActiveSessionLease(session.id))
57
57
  throw new Error('RUNNER_COMMAND_UNAVAILABLE');
@@ -78,7 +78,7 @@ export class OpenCodeManagedRunController {
78
78
  });
79
79
  this.host.emit(runId, 'run.started', { command: 'compact' }, 'STARTING');
80
80
  this.host.emitItem(runId, openCodeCompactionItem('opencode-compact', runId, false));
81
- void this.runCompact(runId, session.model);
81
+ void this.runCompact(runId, session.modelId);
82
82
  return {
83
83
  command: 'compact',
84
84
  run: this.host.run(runId),
@@ -147,7 +147,7 @@ export class OpenCodeRunner extends AbstractRunner {
147
147
  if (configuration.runner !== this.name)
148
148
  return false;
149
149
  const models = this.cachedModels(environment);
150
- const model = models.find((candidate) => candidate.id === configuration.model);
150
+ const model = models.find((candidate) => candidate.id === configuration.modelId);
151
151
  return (model !== undefined &&
152
152
  (model.supportedEfforts.length === 0 ||
153
153
  model.supportedEfforts.includes(configuration.effort)) &&
@@ -157,7 +157,7 @@ export class OpenCodeRunner extends AbstractRunner {
157
157
  const model = this.cachedModels(environment)[0];
158
158
  return {
159
159
  runner: this.name,
160
- model: model?.id ?? '',
160
+ modelId: model?.id ?? '',
161
161
  effort: model?.supportedEfforts[0] ?? '',
162
162
  access: 'default'
163
163
  };
@@ -377,11 +377,11 @@ export class OpenCodeRunner extends AbstractRunner {
377
377
  return value.id;
378
378
  }
379
379
  async executeCompact(session, environment) {
380
- if (session.externalSessionId === null || session.model === null)
380
+ if (session.externalSessionId === null || session.modelId === null)
381
381
  throw new Error('RUNNER_COMMAND_UNAVAILABLE');
382
382
  const client = this.managedClient(environment);
383
383
  try {
384
- return await client.summarize(session.cwd, session.externalSessionId, session.model);
384
+ return await client.summarize(session.cwd, session.externalSessionId, session.modelId);
385
385
  }
386
386
  finally {
387
387
  this.releaseManagedClient(client);
@@ -402,7 +402,7 @@ export class OpenCodeRunner extends AbstractRunner {
402
402
  const tokens = object(latest?.tokens);
403
403
  const cache = object(tokens?.cache);
404
404
  const usedTokens = positiveNumber(tokens?.input) + positiveNumber(cache?.read);
405
- const modelId = provider !== undefined && model !== undefined ? `${provider}/${model}` : session.model;
405
+ const modelId = provider !== undefined && model !== undefined ? `${provider}/${model}` : session.modelId;
406
406
  if (modelId === null || usedTokens <= 0)
407
407
  return undefined;
408
408
  const maxTokens = Date.now() >= this.contextLimitsExpiresAt ? undefined : this.contextLimits.get(modelId);
@@ -239,7 +239,7 @@ export function supportsRunnerConfiguration(input) {
239
239
  const profile = input.runner === 'claude-code'
240
240
  ? claudeProfile(input.environment ?? process.env)
241
241
  : definitions[input.runner];
242
- const model = profile.models.find((candidate) => candidate.id === input.model);
242
+ const model = profile.models.find((candidate) => candidate.id === input.modelId);
243
243
  return (model !== undefined &&
244
244
  model.supportedEfforts.includes(input.effort) &&
245
245
  profile.accessOptions.some((candidate) => candidate.id === input.access));