@myagentroam/agent 0.15.29 → 0.15.30

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.
@@ -1,6 +1,6 @@
1
1
  import type { ExecutionMode } from '../runtime/contracts.js';
2
2
  import { type PromptPart } from './prompt-sections.js';
3
- export declare const MAR_AGENT_PROMPT_VERSION = "1.85";
3
+ export declare const MAR_AGENT_PROMPT_VERSION = "1.87";
4
4
  interface SystemPromptInput {
5
5
  mode: ExecutionMode;
6
6
  platform: string;
@@ -1,9 +1,10 @@
1
+ import { THOUGHT_TOOL_NAME } from '../runtime/context/thought-contract.js';
1
2
  import { renderPromptSections } from './prompt-sections.js';
2
3
  import { compactionPrompt } from './compact.js';
3
4
  import { environmentPrompt, identityPrompt, instructionPriorityPrompt, progressCommunicationPrompt, securityPrompt } from './core.js';
4
5
  import { modePrompt } from './modes.js';
5
- import { toolUsagePrompt } from './workflow.js';
6
- export const MAR_AGENT_PROMPT_VERSION = '1.85';
6
+ import { reasoningPrompt } from './reasoning.js';
7
+ export const MAR_AGENT_PROMPT_VERSION = '1.87';
7
8
  export function buildSystemPrompt(input) {
8
9
  return renderPromptSections(buildSystemPromptSections(input));
9
10
  }
@@ -14,7 +15,10 @@ export function buildSystemPromptSections(input) {
14
15
  ['instruction-priority', instructionPriorityPrompt],
15
16
  ['safety', securityPrompt],
16
17
  ['environment-rules', environmentPrompt(input)],
17
- ['tools', input.tools.length > 0 ? toolUsagePrompt(input.tools, input.directTools) : ''],
18
+ [
19
+ 'reasoning',
20
+ (input.directTools ?? input.tools).includes(THOUGHT_TOOL_NAME) ? reasoningPrompt : ''
21
+ ],
18
22
  ['interaction', input.mode === 'compact' ? null : progressCommunicationPrompt],
19
23
  [
20
24
  'mode',
@@ -0,0 +1 @@
1
+ export declare const reasoningPrompt = "<reasoning>\nDuring extended reasoning, earlier insights may be lost if left unrecorded.\n\nWhen you reach a conclusion useful for later reasoning - such as confirming a hypothesis, ruling out an approach, or making a decision - use `thought` to record it and its key evidence before moving on.\n\nSkip trivial observations. Do not repeat conclusions already recorded with their supporting evidence.\n</reasoning>";
@@ -0,0 +1,7 @@
1
+ export const reasoningPrompt = `<reasoning>
2
+ During extended reasoning, earlier insights may be lost if left unrecorded.
3
+
4
+ When you reach a conclusion useful for later reasoning - such as confirming a hypothesis, ruling out an approach, or making a decision - use \`thought\` to record it and its key evidence before moving on.
5
+
6
+ Skip trivial observations. Do not repeat conclusions already recorded with their supporting evidence.
7
+ </reasoning>`;
@@ -23,7 +23,7 @@ export function contextualBlock(part, kind, operation = 'replace') {
23
23
  const CORE_IDS = new Set(['core:identity', 'core:instruction-priority', 'core:safety']);
24
24
  const SDK_CONTEXTUAL_IDS = new Set([
25
25
  'core:environment-rules',
26
- 'core:tools',
26
+ 'core:reasoning',
27
27
  'core:interaction',
28
28
  'core:mode',
29
29
  'core:compaction',
@@ -121,12 +121,10 @@ export function createExecutionModelContext(ports) {
121
121
  // Compact can run before normal prompt composition after an upgrade.
122
122
  // Revoke retired SDK instructions before either path projects the world state.
123
123
  if (worldState.promptSnapshot !== undefined) {
124
+ const isRetiredSdkPrompt = (part) => part.source === 'sdk' && (part.id === 'core:long-running' || part.id === 'core:tools');
124
125
  // A manual Compact's instruction anchor may precede the last Run's prompt blocks.
125
- const retiredPromptAnchor = worldState.entries.reduce((anchor, entry) => entry.block?.id === 'core:long-running' && entry.block.source === 'sdk'
126
- ? Math.max(anchor, entry.index)
127
- : anchor, instructionInsertIndex);
128
- const migrated = updatePromptWorldState(worldState, retiredPromptAnchor, worldState.promptSnapshot.filter((part) => part.id !== 'core:skill-catalog' &&
129
- !(part.id === 'core:long-running' && part.source === 'sdk')));
126
+ const retiredPromptAnchor = worldState.entries.reduce((anchor, entry) => entry.block && isRetiredSdkPrompt(entry.block) ? Math.max(anchor, entry.index) : anchor, instructionInsertIndex);
127
+ const migrated = updatePromptWorldState(worldState, retiredPromptAnchor, worldState.promptSnapshot.filter((part) => part.id !== 'core:skill-catalog' && !isRetiredSdkPrompt(part)));
130
128
  if (migrated !== worldState)
131
129
  await commitWorldState(migrated);
132
130
  }
@@ -23,49 +23,27 @@ import { structuredToolFailureData } from '../output-projection.js';
23
23
  import { failedToolResultExtensions } from '../result-extensions.js';
24
24
  export const codeModeToolDefinition = {
25
25
  name: 'code_exec',
26
- description: `Run JavaScript to orchestrate or compose tool calls.
27
- - Code Mode Only by default: call the programmatic tools listed below through tools.NAME, including single-tool operations. Tools exposed in both places may also be called directly.
26
+ description: `Run JavaScript with programmatic tools.
28
27
  - Evaluates source in a fresh restricted ECMAScript runtime with top-level await. It is not Node.js or a browser. JavaScript globals do not survive between cells; bounded JSON state is available through state.
29
- - Accepts JavaScript source text. When exposed as a freeform tool, send the source directly; when exposed with a JSON input schema, put the source in its code field. JSON input example: \`{"code":"observe.text(1);"}\`. Do not add another JSON wrapper, quoted string, or markdown code fence inside the source.
30
- - Use only standard ECMAScript built-ins and the explicitly documented tools, observe, state, catalog and cell namespaces. Do not use Node.js, browser or Web APIs. Module imports, filesystem and network APIs are unavailable. Obtain external capabilities only through available tools. Use tools.exec to start managed processes when permitted; follow exec_wait's calling guidance for process control.
28
+ - When exposed as a freeform tool, send the source directly; when exposed with a JSON input schema, put the source in its code field. JSON input example: \`{"code":"observe.text(1);"}\`. The source itself is raw JavaScript, not a JSON wrapper, quoted string, or markdown code fence.
29
+ - Provides standard ECMAScript built-ins and frozen tools, observe, state and cell bindings. Module imports, filesystem and network APIs are unavailable in the guest.
31
30
 
32
31
  Tool calls:
33
- - tools.NAME(input) returns a Promise. Pass a JavaScript value matching the current catalog inputSchema. For parameterless tools prefer tools.NAME({}); tools.NAME() is accepted only for explicitly closed empty-object schemas.
34
- - Results use the MAR envelope: { content?: string, data?: unknown, images?: Array<{mimeType:string,dataBase64:string,url?:string,urlExpiresAt?:number}>, truncated?: boolean }. Redundant JSON content is omitted when it exactly renders data; independent text remains in content. Prefer data for programmatic results: result.data.results[0].text for read source text and result.data.exitCode/result.data.stdout for exec. content, when present, is rendered text, not raw file bytes. Use only fields documented by that tool; do not invent success or ok flags.
35
- - Await every tool call. Independent calls can run concurrently in an awaited Promise.all; use sequential await for dependent calls. Unawaited calls fail the cell. Runtime preserves safe/serial barriers and Host checks.
36
- - Tool errors reject with code/message and may be caught, except nested Auto deny, which skips only that call and resolves with data.error/data.message. A failed cell preserves already emitted output alongside its status and error; completed tool effects are not rolled back. Check the failed cell result before retrying.
32
+ - tools.NAME(input) returns an awaitable. Pass a JavaScript value matching the tool's inputSchema. Only parameterless tools accept an omitted argument.
33
+ - Results use the MAR envelope: { content?: string, data?: unknown, images?: Array<{mimeType:string,dataBase64:string,url?:string,urlExpiresAt?:number}>, truncated?: boolean }. Redundant JSON content is omitted when it exactly renders data; independent rendered text remains in content.
34
+ - A cell cannot finish successfully with unconsumed tool calls or pending operations. Runtime preserves safe/serial barriers and Host checks.
35
+ - Tool execution errors reject with code/message, except nested Auto deny, which skips only that call and resolves with data.error/data.message. A failed cell preserves already emitted output alongside its status and error; completed tool effects are not rolled back.
37
36
  - Direct-only tools cannot be called here. When available, tools.tool_search discovers deferred tools for the next model request; the current cell's tools do not change.
38
37
 
39
38
  Built-in namespaces:
40
39
  - observe.result(result): void registers an unmodified complete tools.NAME result or caught tool error as a tool_result observation, using the original text and all images without repeating program data. Non-original, copied or modified values are rejected.
41
40
  - observe.text(value): void registers text/JSON values. observe.image(value): void registers one image value when image input is supported. Both accept original tool results for compatibility and register the full result as tool_result. Extracted images, copies and computed summaries are value observations. Observations are returned in registration order; registering one does not trigger a new model request. No out or callable observe(value) alias exists.
42
41
  - state.get(key), state.has(key), state.set(key, value), state.delete(key) access bounded session JSON state. Mutations commit atomically only when the cell succeeds; failed or cancelled cells discard them.
43
- - catalog.tools() returns a read-only array of the tools callable in this cell, including name, description and inputSchema. It does not discover or authorize additional tools.
44
42
  - await cell.sleep(ms) performs a cancellable delay up to ${limits.codeSleepMaxMs} ms.
45
43
  - await cell.yield_control() returns accumulated output to the model immediately while this cell continues running.
46
44
  - Optionally start source with // @options: {"yieldMs": ${limits.codeDefaultYieldMs}}. yieldMs defaults to ${limits.codeDefaultYieldMs} ms and controls this call's wait window (0..${limits.codeMaxYieldMs}), not nested tool timeouts or wait windows. A running result includes cellId (c_ plus 12 lowercase hex characters); use direct code_exec_wait for new output, completion or termination.
47
45
  - waitOutcome separates snapshot, completion, timeout, and yield from the cell status. A foreground steer returns interrupted with reason=steer without stopping the cell or its internal tool waits.
48
- - Registered cells are Session warm resources: ending or cancelling the model Execution cancels its wait, not the cell. Reuse retained cellId; do not start duplicate work. Host cleanup or explicit termination stops the cell.
49
- - tools, observe, state, catalog and cell are frozen bindings. Do not shadow their names.
50
-
51
- Examples (copy the JavaScript source, not the fences; use only tools available in the current directory):
52
- Independent reads, observing the original tool results:
53
- \`\`\`js
54
- const [a, b] = await Promise.all([
55
- tools.read({ reads: [{ path: "a.txt" }] }),
56
- tools.read({ reads: [{ path: "b.txt" }] })
57
- ]);
58
- observe.result(a);
59
- observe.result(b);
60
- \`\`\`
61
- Inspect before a dependent edit; successful await needs no invented success flag:
62
- \`\`\`js
63
- const inspected = await tools.read({ reads: [{ path: "source.txt" }] });
64
- const sourceText = inspected.data.results[0].text;
65
- if (!sourceText?.includes("original=1")) throw new Error("Unexpected source");
66
- const patched = await tools.apply_patch({ input: "*** Begin Patch\\n*** Update File: source.txt\\n@@\\n original=1\\n+updated=2\\n*** End Patch" });
67
- observe.result(patched);
68
- \`\`\``,
46
+ - Registered cells are Session warm resources: ending or cancelling the model Execution cancels its wait, not the cell. Host cleanup or explicit termination stops the cell.`,
69
47
  inputMode: 'freeform',
70
48
  inputSchema: {
71
49
  type: 'object',
@@ -116,10 +94,7 @@ export function projectCodeModeTools(tools, residentTools = tools) {
116
94
  if (!codeModeEnabled)
117
95
  return direct;
118
96
  const programmatic = orderToolDefinitions(residentTools.filter((tool) => allowsToolCaller(tool, 'programmatic')));
119
- const directory = JSON.stringify({
120
- callableNames: programmatic.map((tool) => tool.name),
121
- tools: programmatic.map(projectProgrammaticTool)
122
- });
97
+ const directory = JSON.stringify(programmatic.map(projectProgrammaticTool));
123
98
  if (Buffer.byteLength(directory) > 48 * 1024)
124
99
  throw new AgentError('MAR_AGENT_TOOL_EXPOSURE_LIMIT', 'Programmatic tool directory is too large.');
125
100
  return direct.map((tool) => tool.name === 'code_exec'
@@ -158,13 +158,6 @@ export async function createCodeModeEngine(options) {
158
158
  try { return walk(value); } catch { return ''; }
159
159
  };
160
160
  })();
161
- globalThis.__deepFreeze = function deepFreeze(value) {
162
- if (value && typeof value === 'object' && !Object.isFrozen(value)) {
163
- for (const item of Object.values(value)) deepFreeze(item);
164
- Object.freeze(value);
165
- }
166
- return value;
167
- };
168
161
  `);
169
162
  if (setup.error)
170
163
  fail(setup.error);
@@ -186,7 +179,6 @@ export async function createCodeModeEngine(options) {
186
179
  value.value.dispose();
187
180
  }
188
181
  };
189
- const deepFreeze = vm.getProp(vm.global, '__deepFreeze');
190
182
  const parse = (value) => {
191
183
  const handle = vm.newString(JSON.stringify(value));
192
184
  try {
@@ -235,6 +227,7 @@ export async function createCodeModeEngine(options) {
235
227
  return guestError('MAR_AGENT_TOOL_OUTPUT_LIMIT', 'Code Mode state is too large.');
236
228
  };
237
229
  const tools = vm.newObject();
230
+ // The internal snapshot still determines which tools may omit their argument.
238
231
  const parameterlessTools = new Set(input.catalog.filter(isParameterlessTool).map((tool) => tool.name));
239
232
  let toolCallSequence = 0;
240
233
  for (const name of input.tools) {
@@ -460,21 +453,6 @@ export async function createCodeModeEngine(options) {
460
453
  });
461
454
  vm.setProp(vm.global, 'state', stateObject);
462
455
  stateObject.dispose();
463
- const catalog = vm.newObject();
464
- method(catalog, 'tools', () => {
465
- const value = parse(input.catalog.map(({ name, description, inputSchema }) => ({
466
- name,
467
- description,
468
- inputSchema
469
- })));
470
- const frozen = callGuest(deepFreeze, vm.undefined, value);
471
- value.dispose();
472
- if (frozen.error)
473
- return { error: frozen.error };
474
- return frozen.value;
475
- });
476
- vm.setProp(vm.global, 'catalog', catalog);
477
- catalog.dispose();
478
456
  const cell = vm.newObject();
479
457
  method(cell, 'yield_control', () => {
480
458
  input.onYield();
@@ -545,7 +523,7 @@ export async function createCodeModeEngine(options) {
545
523
  { code: 'MAR_AGENT_TOOL_NOT_AVAILABLE' }); };
546
524
  return target[name];
547
525
  }});
548
- for (const name of ['tools', 'observe', 'state', 'catalog', 'cell']) {
526
+ for (const name of ['tools', 'observe', 'state', 'cell']) {
549
527
  const value = globalThis[name];
550
528
  Object.freeze(value);
551
529
  Object.defineProperty(globalThis, name, {
@@ -556,7 +534,6 @@ export async function createCodeModeEngine(options) {
556
534
  delete globalThis.__serialize;
557
535
  delete globalThis.__text;
558
536
  delete globalThis.__snapshot;
559
- delete globalThis.__deepFreeze;
560
537
  delete globalThis.__consumeToolCall;
561
538
  `);
562
539
  if (lock.error)
@@ -614,7 +591,6 @@ export async function createCodeModeEngine(options) {
614
591
  snapshotFunction.dispose();
615
592
  for (const origin of origins)
616
593
  origin.handle.dispose();
617
- deepFreeze.dispose();
618
594
  }
619
595
  },
620
596
  async dispose() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myagentroam/agent",
3
- "version": "0.15.29",
3
+ "version": "0.15.30",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/myagentroam/mar.git",
@@ -1 +0,0 @@
1
- export declare function toolUsagePrompt(tools: readonly string[], directTools?: readonly string[]): string;
@@ -1,29 +0,0 @@
1
- import { THOUGHT_TOOL_NAME } from '../runtime/context/thought-contract.js';
2
- export function toolUsagePrompt(tools, directTools = tools) {
3
- const names = new Set(tools);
4
- const clauses = [
5
- `# Tools and execution\nAvailable client tools: ${directTools.join(', ')}.`,
6
- 'Use the tool descriptions and schemas for calling conventions, limits, results, and recovery. Respect dependencies and side effects when combining operations.'
7
- ];
8
- if (names.has('code_exec')) {
9
- const direct = new Set(directTools);
10
- const programmatic = tools.filter((name) => !direct.has(name));
11
- if (programmatic.length > 0)
12
- clauses.push(`Code Mode Only: ${programmatic.join(', ')} are callable only as tools.NAME inside code_exec.`);
13
- clauses.push('Tools exposed in both modes may use either permitted entry point; direct-only controls remain direct.');
14
- }
15
- if (names.has('exec'))
16
- clauses.push('You can use the built-in rg through exec to search file contents or rg --files to list file paths.');
17
- const execution = clauses.join(' ');
18
- if (!directTools.includes(THOUGHT_TOOL_NAME))
19
- return execution;
20
- return `${execution}
21
-
22
- <reasoning>
23
- During extended reasoning, earlier insights may be lost if left unrecorded.
24
-
25
- When you reach a conclusion useful for later reasoning - such as confirming a hypothesis, ruling out an approach, or making a decision - use \`thought\` to record it and its key evidence before moving on.
26
-
27
- Skip trivial observations. Do not repeat conclusions already recorded with their supporting evidence.
28
- </reasoning>`;
29
- }