@myagentroam/node 0.9.132 → 0.9.133

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.
@@ -433,6 +433,7 @@ async function readTranscript(path, runner, byteLimit, page, targetLines = Numbe
433
433
  const toolIndexes = new Map();
434
434
  const metaRecordIds = new Set();
435
435
  const claudeCompactCommandIds = new Set();
436
+ let codexTurnId;
436
437
  forEachJsonlRecord(content, (value) => {
437
438
  if (derivedTranscriptRecord(runner, value))
438
439
  derivedSession = true;
@@ -444,6 +445,13 @@ async function readTranscript(path, runner, byteLimit, page, targetLines = Numbe
444
445
  claudeCompactCommandIds.add(value['uuid']);
445
446
  });
446
447
  forEachJsonlRecord(truncated ? window.pageContent : content, (value) => {
448
+ if (runner === 'codex' && value['type'] === 'event_msg' && isRecord(value['payload'])) {
449
+ const payload = value['payload'];
450
+ if (payload['type'] === 'task_started')
451
+ codexTurnId = typeof payload['turn_id'] === 'string' ? payload['turn_id'] : undefined;
452
+ else if (payload['type'] === 'task_complete')
453
+ codexTurnId = undefined;
454
+ }
447
455
  const recordId = typeof value['uuid'] === 'string' ? value['uuid'] : undefined;
448
456
  const parentId = typeof value['parentUuid'] === 'string' ? value['parentUuid'] : undefined;
449
457
  if (value['isMeta'] === true && recordId !== undefined)
@@ -469,7 +477,16 @@ async function readTranscript(path, runner, byteLimit, page, targetLines = Numbe
469
477
  if (generatedImage !== undefined)
470
478
  items.push(generatedImage);
471
479
  for (const parsedItem of transcriptItems(runner, value)) {
472
- const item = recordId === undefined ? parsedItem : { ...parsedItem, nativeId: recordId };
480
+ const item = {
481
+ ...parsedItem,
482
+ ...(recordId === undefined ? {} : { nativeId: recordId }),
483
+ ...(runner === 'codex' &&
484
+ parsedItem.kind === 'message' &&
485
+ parsedItem.role === 'USER' &&
486
+ codexTurnId !== undefined
487
+ ? { nativeTurnId: codexTurnId }
488
+ : {})
489
+ };
473
490
  if (item.kind === 'tool_result') {
474
491
  const toolIndex = toolIndexes.get(item.toolUseId);
475
492
  if (toolIndex !== undefined)
@@ -0,0 +1,34 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { dirname, join, resolve } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ /** Environment for processes started by this Node, not for the Node service itself. */
5
+ export function nodeExecutionEnvironment(provided = {}, inherited = process.env, options = {}) {
6
+ const environment = Object.fromEntries(Object.entries(inherited).filter((entry) => typeof entry[1] === 'string'));
7
+ Object.assign(environment, provided);
8
+ environment['MAR_NODE_CONTEXT'] = '1';
9
+ const platform = options.platform ?? process.platform;
10
+ const packageRoot = options.packageRoot ?? resolve(dirname(fileURLToPath(import.meta.url)), '..');
11
+ const cliBin = join(packageRoot, 'node_modules', '.bin');
12
+ if (!existsSync(join(cliBin, platform === 'win32' ? 'marnodes.cmd' : 'marnodes')))
13
+ return environment;
14
+ const separator = platform === 'win32' ? ';' : ':';
15
+ const existingKeys = Object.keys(environment).filter((key) => key.toLowerCase() === 'path');
16
+ const key = platform === 'win32'
17
+ ? (Object.keys(provided).find((name) => name.toLowerCase() === 'path') ??
18
+ existingKeys[0] ??
19
+ 'Path')
20
+ : 'PATH';
21
+ const current = environment[key] ?? environment[existingKeys[0] ?? key] ?? '';
22
+ if (platform === 'win32')
23
+ for (const other of existingKeys)
24
+ if (other !== key)
25
+ delete environment[other];
26
+ const samePath = (entry) => platform === 'win32'
27
+ ? entry.replaceAll('/', '\\').toLowerCase() === cliBin.replaceAll('/', '\\').toLowerCase()
28
+ : entry === cliBin;
29
+ environment[key] = [
30
+ cliBin,
31
+ ...current.split(separator).filter((entry) => entry && !samePath(entry))
32
+ ].join(separator);
33
+ return environment;
34
+ }
@@ -1,4 +1,5 @@
1
1
  import { mcpRuntimeDescriptorSchema } from '@myagentroam/protocol';
2
+ import { nodeExecutionEnvironment } from '../node-execution-environment.js';
2
3
  /**
3
4
  * Stable lifecycle boundary for every Node Runner implementation.
4
5
  *
@@ -175,6 +176,7 @@ function resolvedMcpServers(raw, secrets) {
175
176
  : { MAR_MGR_USER_TOKEN: secrets['MAR_MGR_USER_TOKEN'] }),
176
177
  MAR_MGR_CONTEXT_REQUIRED: '1'
177
178
  };
179
+ const mcpEnvironment = (provided) => nodeExecutionEnvironment({ ...provided, ...marmgrEnvironment }, { PATH: process.env['PATH'], Path: process.env['Path'] });
178
180
  const result = [];
179
181
  for (const value of raw) {
180
182
  if (value === null || typeof value !== 'object' || Array.isArray(value))
@@ -197,24 +199,21 @@ function resolvedMcpServers(raw, secrets) {
197
199
  transport: 'STDIO',
198
200
  command: record['command'],
199
201
  args: record['args'],
200
- environment: record['__marGoal'] === true
202
+ environment: mcpEnvironment(record['__marGoal'] === true
201
203
  ? {
202
204
  MAR_GOAL_MCP_ENDPOINT: record['endpoint'],
203
- MAR_GOAL_MCP_TOKEN: secrets[record['secretName']],
204
- ...marmgrEnvironment
205
+ MAR_GOAL_MCP_TOKEN: secrets[record['secretName']]
205
206
  }
206
207
  : record['__marScheduled'] === true
207
208
  ? {
208
209
  MAR_SCHEDULE_MCP_ENDPOINT: record['endpoint'],
209
210
  MAR_SCHEDULE_MCP_TOKEN: secrets[record['secretName']],
210
- MAR_SCHEDULE_MCP_READ_ONLY: record['readOnly'] === true ? '1' : '0',
211
- ...marmgrEnvironment
211
+ MAR_SCHEDULE_MCP_READ_ONLY: record['readOnly'] === true ? '1' : '0'
212
212
  }
213
213
  : {
214
214
  MAR_MAIL_MCP_ENDPOINT: record['endpoint'],
215
- MAR_MAIL_MCP_TOKEN: secrets[record['secretName']],
216
- ...marmgrEnvironment
217
- }
215
+ MAR_MAIL_MCP_TOKEN: secrets[record['secretName']]
216
+ })
218
217
  });
219
218
  continue;
220
219
  }
@@ -251,11 +250,10 @@ function resolvedMcpServers(raw, secrets) {
251
250
  ? configuration['arguments'].filter((item) => typeof item === 'string')
252
251
  : [])
253
252
  ],
254
- environment: {
253
+ environment: mcpEnvironment({
255
254
  ...runtimeEnvironment,
256
- ...configuredEnvironment,
257
- ...marmgrEnvironment
258
- }
255
+ ...configuredEnvironment
256
+ })
259
257
  });
260
258
  }
261
259
  else {
@@ -1,5 +1,6 @@
1
1
  import { createEnvelope } from '@myagentroam/protocol';
2
2
  import { ClaudeChannelGate } from '../../claude-channel.js';
3
+ import { nodeExecutionEnvironment } from '../../node-execution-environment.js';
3
4
  import { boundedConversationItemId, claudePlanText, compactRunnerText, extractClaudeText, extractClaudeThinkingSummaries, extractClaudeToolResults, extractClaudeToolUses } from '../codex/conversation-parser.js';
4
5
  import { normalizeClaudeTool } from './tool-normalizer.js';
5
6
  import { claudeContentBlocks } from '../../util/node-operation-parsers.js';
@@ -170,7 +171,10 @@ export class ClaudeManagedRunController {
170
171
  ...(typeof payload.model === 'string' ? { model: payload.model } : {}),
171
172
  ...(typeof payload.effort === 'string' ? { effort: payload.effort } : {}),
172
173
  ...(typeof payload.access === 'string' ? { access: payload.access } : {}),
173
- environment: { ...secretEnvironment, MAR_MGR_CONTEXT_REQUIRED: '1' },
174
+ environment: nodeExecutionEnvironment({
175
+ ...secretEnvironment,
176
+ MAR_MGR_CONTEXT_REQUIRED: '1'
177
+ }, { PATH: process.env['PATH'], Path: process.env['Path'] }),
174
178
  ...(typeof payload.personalInstructions === 'string'
175
179
  ? { personalInstructions: payload.personalInstructions }
176
180
  : {}),
@@ -1,3 +1,4 @@
1
+ import { nodeExecutionEnvironment } from '../../node-execution-environment.js';
1
2
  import { extractId } from '../../util/runner-native-session-parsers.js';
2
3
  import { parseSecretEnvironment } from '../../util/secret-environment.js';
3
4
  import { safeErrorCode } from '../../util/safe-error.js';
@@ -65,7 +66,7 @@ export class CodexManagedRunController {
65
66
  throw new Error('RUNNER_COMMAND_UNAVAILABLE');
66
67
  if (command.id === 'compact') {
67
68
  const runId = crypto.randomUUID();
68
- this.runner.prepareEnvironment(context.secretEnvironment, runId);
69
+ this.runner.prepareEnvironment(nodeExecutionEnvironment({ ...context.secretEnvironment, MAR_MGR_CONTEXT_REQUIRED: '1' }, { PATH: process.env['PATH'], Path: process.env['Path'] }), runId);
69
70
  try {
70
71
  await this.runner.start(runId);
71
72
  return await this.compact(session, threadId, runId, context.initiatedByUserId);
@@ -385,7 +386,7 @@ export class CodexManagedRunController {
385
386
  return;
386
387
  }
387
388
  try {
388
- this.runner.prepareEnvironment({ ...secretEnvironment, MAR_MGR_CONTEXT_REQUIRED: '1' }, runId);
389
+ this.runner.prepareEnvironment(nodeExecutionEnvironment({ ...secretEnvironment, MAR_MGR_CONTEXT_REQUIRED: '1' }, { PATH: process.env['PATH'], Path: process.env['Path'] }), runId);
389
390
  }
390
391
  catch (error) {
391
392
  this.host.emit(runId, 'run.rejected', { code: safeErrorCode(error, 'SECRET_ENVIRONMENT_INVALID') }, 'FAILED');
@@ -2,6 +2,7 @@ import { computerUseHostSkill } from './computer-use-skill.js';
2
2
  import { createHash, randomUUID } from 'node:crypto';
3
3
  import { homedir } from 'node:os';
4
4
  import { access, constants } from 'node:fs/promises';
5
+ import { nodeExecutionEnvironment } from '../../node-execution-environment.js';
5
6
  import { BUNDLED_RIPGREP_VERSION, bundledRipgrepPath, prependBundledRipgrepToPath } from '../../ripgrep-binary.js';
6
7
  import { LocalAgentHost, createMarAgent } from '@myagentroam/agent';
7
8
  import { marAgentReasoningEffortSchema, marAgentRuntimeModelConfigurationSchema } from '@myagentroam/protocol';
@@ -686,7 +687,10 @@ export function allowsUntrustedWebFetchTls(environment) {
686
687
  return environment['MAR_AGENT_WEB_FETCH_ALLOW_UNTRUSTED_TLS'] !== '0';
687
688
  }
688
689
  async function resolveMarAgentHostRuntimeConfiguration(secretEnvironment = {}) {
689
- const environment = { ...process.env, ...secretEnvironment, MAR_MGR_CONTEXT_REQUIRED: '1' };
690
+ const environment = nodeExecutionEnvironment({
691
+ ...secretEnvironment,
692
+ MAR_MGR_CONTEXT_REQUIRED: '1'
693
+ });
690
694
  const ripgrep = await availableBundledRipgrep();
691
695
  return {
692
696
  environment: ripgrep === undefined ? environment : prependBundledRipgrepToPath(environment, ripgrep),
@@ -221,24 +221,36 @@ export class MarAgentRunner extends AbstractRunner {
221
221
  let catalog;
222
222
  try {
223
223
  catalog = await openMarAgentSessionCatalog({ homeDirectory: this.homeDirectory });
224
- const listed = await catalog.list({ limit: 200 });
224
+ const activeCatalog = catalog;
225
+ const listed = await activeCatalog.list({ limit: 200 });
225
226
  const workspaces = workspace ? [workspace] : context.workspaces;
226
- return listed.sessions.flatMap((session) => {
227
+ return (await Promise.all(listed.sessions.map(async (session) => {
227
228
  const target = workspaces.find((candidate) => resolve(candidate.path) === resolve(session.workspace));
228
229
  if (!target)
229
230
  return [];
231
+ const executionConfiguration = session.modelId === undefined
232
+ ? await activeCatalog.executionConfiguration(session.id)
233
+ : session;
230
234
  return [
231
- context.createProjection({
232
- workspace: target,
233
- runner: this.name,
234
- externalSessionId: session.id,
235
- cwd: session.workspace,
236
- title: session.title,
237
- titleOrigin: 'NATIVE',
238
- lastActivityAt: Date.parse(session.lastActivityAt)
239
- })
235
+ {
236
+ ...context.createProjection({
237
+ workspace: target,
238
+ runner: this.name,
239
+ externalSessionId: session.id,
240
+ cwd: session.workspace,
241
+ title: session.title,
242
+ titleOrigin: 'NATIVE',
243
+ lastActivityAt: Date.parse(session.lastActivityAt)
244
+ }),
245
+ ...(executionConfiguration?.modelId === undefined
246
+ ? {}
247
+ : { model: executionConfiguration.modelId }),
248
+ ...(executionConfiguration?.reasoningEffort === undefined
249
+ ? {}
250
+ : { effort: executionConfiguration.reasoningEffort })
251
+ }
240
252
  ];
241
- });
253
+ }))).flat();
242
254
  }
243
255
  catch {
244
256
  return [];
@@ -1,3 +1,4 @@
1
+ import { nodeExecutionEnvironment } from '../../node-execution-environment.js';
1
2
  import { parseSecretEnvironment } from '../../util/secret-environment.js';
2
3
  import { runnerErrorProjection } from '../../util/runner-error.js';
3
4
  import { boundedConversationItemId, compactRunnerText } from '../codex/conversation-parser.js';
@@ -49,7 +50,7 @@ export class OpenCodeManagedRunController {
49
50
  this.host.hasActiveSessionLease(session.id))
50
51
  throw new Error('RUNNER_COMMAND_UNAVAILABLE');
51
52
  const runId = crypto.randomUUID();
52
- const client = this.runner.managedClient(environment);
53
+ const client = this.runner.managedClient(nodeExecutionEnvironment({ ...environment, MAR_MGR_CONTEXT_REQUIRED: '1' }, { PATH: process.env['PATH'], Path: process.env['Path'] }));
53
54
  this.host.adopt({
54
55
  runId,
55
56
  sessionId: session.id,
@@ -108,10 +109,10 @@ export class OpenCodeManagedRunController {
108
109
  let mcp;
109
110
  let attachments;
110
111
  try {
111
- environment = {
112
+ environment = nodeExecutionEnvironment({
112
113
  ...parseSecretEnvironment(payload.secretEnvironment),
113
114
  MAR_MGR_CONTEXT_REQUIRED: '1'
114
- };
115
+ }, { PATH: process.env['PATH'], Path: process.env['Path'] });
115
116
  mcpSecretEnvironment = parseSecretEnvironment(payload.mcpSecretEnvironment);
116
117
  mcp = this.runner.mcpConfiguration(payload.mcpInstallations, {
117
118
  ...environment,
@@ -369,20 +369,22 @@ export class ConversationHistoryService {
369
369
  }
370
370
  async readManagedRuntime(session, input, cursor, snapshotSequence, readAt) {
371
371
  const page = await this.readManagedActive(session, input, cursor, snapshotSequence, readAt);
372
+ const codexActive = session.runner === 'codex' && this.options.hasManagedActiveRun(session);
372
373
  if (input.cursor !== undefined ||
373
374
  session.externalSessionId === null ||
374
- this.options.hasManagedActiveRun(session) ||
375
- !this.hasManagedRuntimeHistory(session) ||
375
+ (!codexActive &&
376
+ (this.options.hasManagedActiveRun(session) || !this.hasManagedRuntimeHistory(session))) ||
376
377
  !page.turns.some((turn) => turn.rewind === undefined &&
377
378
  terminalConversationTurn(turn.status) &&
378
379
  conversationClientMessageId(turn) !== null))
379
380
  return page;
380
381
  // A completed managed Turn keeps its live items and Run identity until Runtime cleanup.
381
- // Only the SDK's matched native Turn may supply a destructive history boundary.
382
- const official = await this.readOfficial(session, {
383
- limit: Math.min(500, Math.max(30, page.turns.length + 1))
384
- }).catch(() => undefined);
385
- if (official === undefined)
382
+ // Only its matched native Turn may supply a Rewind boundary.
383
+ const historyInput = { limit: Math.min(500, Math.max(30, page.turns.length + 1)) };
384
+ const authoritative = codexActive
385
+ ? (await this.readRunnerHistory(session, historyInput).catch(() => undefined))?.page
386
+ : await this.readOfficial(session, historyInput).catch(() => undefined);
387
+ if (authoritative === undefined)
386
388
  return page;
387
389
  return {
388
390
  ...page,
@@ -392,7 +394,7 @@ export class ConversationHistoryService {
392
394
  const messageId = conversationClientMessageId(turn);
393
395
  if (messageId === null)
394
396
  return turn;
395
- const native = official.turns.find((candidate) => candidate.rewind !== undefined &&
397
+ const native = authoritative.turns.find((candidate) => candidate.rewind !== undefined &&
396
398
  candidate.userItemId !== null &&
397
399
  conversationClientMessageId(candidate) === messageId);
398
400
  return native?.rewind === undefined ? turn : { ...turn, rewind: native.rewind };
package/dist/terminal.js CHANGED
@@ -5,6 +5,7 @@ import { homedir } from 'node:os';
5
5
  import { join } from 'node:path';
6
6
  import { spawn } from 'node-pty';
7
7
  import { terminalDataFrameSchema } from '@myagentroam/protocol';
8
+ import { nodeExecutionEnvironment } from './node-execution-environment.js';
8
9
  import { terminateProcessTree } from './process-tree.js';
9
10
  const MAX_FRAME_CHARACTERS = 65_536;
10
11
  const TERMINAL_COMMAND_MAX_BYTES = 64 * 1024;
@@ -138,7 +139,7 @@ export class TerminalManager {
138
139
  cols,
139
140
  rows,
140
141
  cwd: typeof input.cwd === 'string' ? input.cwd : this.cwd,
141
- env: { ...process.env, ...input.environment }
142
+ env: nodeExecutionEnvironment(input.environment, process.env, { platform: this.platform })
142
143
  };
143
144
  const commandArgs = command === undefined
144
145
  ? undefined
@@ -182,6 +182,11 @@ export function nativeConversationPage(session, history, input, runtimeTurns = [
182
182
  const startedAt = items[0]?.startedAt ?? null;
183
183
  const completedAt = items.at(-1)?.completedAt ?? startedAt;
184
184
  const after = lastNativeItemId(entries);
185
+ const nativeIndex = start + relativeIndex;
186
+ const turnBoundaryAfter = nativeUser?.kind === 'message' ? nativeUser.nativeTurnId : undefined;
187
+ const previousNativeUser = nativeTurns[nativeIndex - 1]?.find(({ entry }) => entry.kind === 'message' && entry.role === 'USER')?.entry;
188
+ const turnBoundaryBefore = previousNativeUser?.kind === 'message' ? previousNativeUser.nativeTurnId : undefined;
189
+ const firstNativeTurn = nativeIndex === 0 && history.truncated !== true;
185
190
  return {
186
191
  id: turnId,
187
192
  sessionId: session.id,
@@ -199,6 +204,10 @@ export function nativeConversationPage(session, history, input, runtimeTurns = [
199
204
  after
200
205
  }
201
206
  }),
207
+ ...(turnBoundaryAfter === undefined ||
208
+ (!firstNativeTurn && turnBoundaryBefore === undefined)
209
+ ? {}
210
+ : { rewind: { before: turnBoundaryBefore ?? null, after: turnBoundaryAfter } }),
202
211
  items,
203
212
  startedAt,
204
213
  completedAt
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myagentroam/node",
3
- "version": "0.9.132",
3
+ "version": "0.9.133",
4
4
  "description": "MyAgentRoam Node runtime CLI.",
5
5
  "license": "Apache-2.0 AND GPL-2.0-or-later",
6
6
  "type": "module",
@@ -34,9 +34,9 @@
34
34
  "npm": "11.12.1",
35
35
  "ws": "^8.21.3",
36
36
  "zod": "4.4.3",
37
- "@myagentroam/marmgr": "0.9.115",
38
- "@myagentroam/agent": "0.9.132",
39
- "@myagentroam/protocol": "0.9.132",
37
+ "@myagentroam/marmgr": "0.9.116",
38
+ "@myagentroam/agent": "0.9.133",
39
+ "@myagentroam/protocol": "0.9.133",
40
40
  "@myagentroam/code-navigation": "0.9.129"
41
41
  },
42
42
  "devDependencies": {