@myagentroam/agent 0.13.21 → 0.13.23
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.
- package/dist/cli/catalog-file.d.ts +3 -2
- package/dist/cli/catalog-file.js +9 -3
- package/dist/cli/main.js +2 -1
- package/dist/extensions/session-messages.d.ts +1 -1
- package/dist/model/anthropic-messages.js +52 -43
- package/dist/model/configuration.d.ts +5 -3
- package/dist/model/configuration.js +16 -2
- package/dist/model/openai-responses.d.ts +2 -2
- package/dist/model/openai-responses.js +35 -26
- package/dist/model/sse.d.ts +3 -0
- package/dist/model/sse.js +19 -11
- package/dist/network/credential-runtime.d.ts +5 -0
- package/dist/network/credential-runtime.js +10 -2
- package/dist/network/http.d.ts +1 -0
- package/dist/network/http.js +24 -4
- package/dist/prompts/core.d.ts +2 -2
- package/dist/prompts/core.js +3 -3
- package/dist/prompts/index.d.ts +1 -1
- package/dist/prompts/index.js +2 -2
- package/dist/prompts/workflow.d.ts +3 -3
- package/dist/prompts/workflow.js +6 -26
- package/dist/runtime/context/contextual-blocks.js +0 -1
- package/dist/runtime/context/instructions.js +23 -2
- package/dist/runtime/context/world-state.d.ts +2 -1
- package/dist/runtime/context/world-state.js +9 -2
- package/dist/sdk/execution-context-coordinator.d.ts +1 -1
- package/dist/sdk/execution-context-coordinator.js +2 -2
- package/dist/sdk/execution-model-context.d.ts +2 -1
- package/dist/sdk/execution-model-context.js +31 -11
- package/dist/sdk/session-execution-factory.d.ts +1 -1
- package/dist/sdk/session-execution-factory.js +3 -2
- package/dist/sdk/session-extension-prompt.d.ts +2 -9
- package/dist/sdk/session-extension-prompt.js +2 -23
- package/dist/sdk/session.js +1 -8
- package/dist/tools/code-mode/cells.js +4 -3
- package/dist/tools/code-mode/index.js +5 -3
- package/dist/tools/local/apply-patch.js +11 -5
- package/dist/tools/local/exec.js +20 -20
- package/dist/tools/local/view-image.js +3 -0
- package/dist/tools/shared/text-input.d.ts +3 -0
- package/dist/tools/shared/text-input.js +13 -0
- package/package.json +3 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { permissionStopFromError } from '../permissions.js';
|
|
2
2
|
import { RuntimeResourceHandles } from '../runtime-resource-handles.js';
|
|
3
|
+
import { textToolInputError } from '../shared/text-input.js';
|
|
3
4
|
import { AgentError, describeAgentError } from '../../error.js';
|
|
4
5
|
import { truncateModelText } from '../../runtime/token-budget.js';
|
|
5
6
|
import { TOOL_EXECUTION_LIMITS as limits } from '../execution-limits.js';
|
|
@@ -159,9 +160,9 @@ export class CodeCells {
|
|
|
159
160
|
'code' in value
|
|
160
161
|
? value.code
|
|
161
162
|
: undefined;
|
|
162
|
-
if (typeof source !== 'string'
|
|
163
|
-
|
|
164
|
-
|
|
163
|
+
if (typeof source !== 'string')
|
|
164
|
+
throw textToolInputError('code', value);
|
|
165
|
+
if (!source.trim() || Buffer.byteLength(source) > limits.codeMaxInputBytes)
|
|
165
166
|
throw new AgentError('MAR_AGENT_TOOL_INPUT_INVALID', 'Code must be a nonempty bounded JavaScript string.');
|
|
166
167
|
let settings = options({}, false);
|
|
167
168
|
const pragma = /^\/\/ @options:\s*([^\r\n]*)(?:\r?\n|$)/u.exec(source);
|
|
@@ -30,7 +30,7 @@ export const codeModeToolDefinition = {
|
|
|
30
30
|
- Observe only evidence needed for the next decision or verification: use observe.result for original results, observe.text for derived values, and observe.image for image values. Preserve source and failure details needed for reasoning; keep other intermediate data in the cell.
|
|
31
31
|
- Single-tool cells are valid. Keep loops and retries bounded, and do not blindly replay operations with side effects.
|
|
32
32
|
- Evaluates source in a fresh restricted ECMAScript runtime with top-level await and Promise.all. It is not Node.js or a browser. JavaScript globals do not survive between cells; bounded JSON state is available through state.
|
|
33
|
-
- 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. Do not add another JSON wrapper, quoted string, or markdown code fence inside the source.
|
|
33
|
+
- 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.
|
|
34
34
|
- Keep embedded commands, patches and source in JSON-escaped double-quoted strings when they contain backticks or literal \${...}; escape newlines as \\n, never put literal line breaks inside single- or double-quoted JS strings. JavaScript template literals would interpolate their contents before the tool runs. Do not paste Python literals such as None into JavaScript expressions.
|
|
35
35
|
- 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.
|
|
36
36
|
|
|
@@ -67,13 +67,15 @@ Inspect before a dependent edit; successful await needs no invented success flag
|
|
|
67
67
|
const inspected = await tools.read({ reads: [{ path: "source.txt" }] });
|
|
68
68
|
const sourceText = inspected.data.results[0].text;
|
|
69
69
|
if (!sourceText?.includes("original=1")) throw new Error("Unexpected source");
|
|
70
|
-
const patched = await tools.apply_patch({
|
|
70
|
+
const patched = await tools.apply_patch({ input: "*** Begin Patch\\n*** Update File: source.txt\\n@@\\n original=1\\n+updated=2\\n*** End Patch" });
|
|
71
71
|
observe.result(patched);
|
|
72
72
|
\`\`\``,
|
|
73
73
|
inputMode: 'freeform',
|
|
74
74
|
inputSchema: {
|
|
75
75
|
type: 'object',
|
|
76
|
-
properties: {
|
|
76
|
+
properties: {
|
|
77
|
+
code: { type: 'string', description: 'JavaScript source for orchestrating tool calls.' }
|
|
78
|
+
},
|
|
77
79
|
required: ['code'],
|
|
78
80
|
additionalProperties: false
|
|
79
81
|
},
|
|
@@ -5,13 +5,14 @@ import { TextDecoder } from 'node:util';
|
|
|
5
5
|
import { AgentError } from '../../error.js';
|
|
6
6
|
import { TOOL_EXECUTION_LIMITS } from '../execution-limits.js';
|
|
7
7
|
import { captureFileChange, reserveFileChangePaths } from '../result-extensions.js';
|
|
8
|
+
import { textToolInputError } from '../shared/text-input.js';
|
|
8
9
|
import { parsePatch } from './apply-patch-parser.js';
|
|
9
10
|
export const applyPatchToolDefinition = {
|
|
10
11
|
name: 'apply_patch',
|
|
11
12
|
allowedCallers: ['direct', 'programmatic'],
|
|
12
13
|
codeModeExposure: 'both',
|
|
13
14
|
parallelSafety: 'safe',
|
|
14
|
-
description: `Preferred for precise, reviewable local edits. Do not batch all task files merely to reduce tool calls. Group only a few tightly coupled edits whose combined patch is quick to generate and review; split broad or independent work into successive bounded patches before composing them.
|
|
15
|
+
description: `Preferred for precise, reviewable local edits. Do not batch all task files merely to reduce tool calls. Group only a few tightly coupled edits whose combined patch is quick to generate and review; split broad or independent work into successive bounded patches before composing them. For freeform calls, submit the *** Begin Patch / *** End Patch text directly, each marker on its own line. For JSON calls, put the complete patch text in the input field. JSON input example: {"input":"*** Begin Patch\\n*** Add File: example.txt\\n+text\\n*** End Patch"}. Surrounding marker whitespace and an optional trailing *** are accepted; incomplete markers or extra text are rejected. Add File content lines, including blank lines, must start with +. Syntax errors include line/column and a bounded excerpt of the submitted patch with a caret at the error. Supports Add File, Update File, Delete File, and Move to. Add File may replace an existing regular file, and Move to may replace an existing regular destination; duplicate operations on the same resolved path remain invalid. Update hunks accept @@ or @@ <change context>. Context-only hunks, including trailing hunks, and unchanged file sections are validated in order but are not written or reported as edits. The patch must include a change or move. Context is searched forward with Codex-style exact, whitespace-tolerant, then common Unicode punctuation-tolerant matching. Syntax and resolved paths are validated before writing, then file units are committed in order. Each file unit is atomic, and a Move keeps its source and destination atomic. On MAR_AGENT_PATCH_PARTIAL, earlier files remain applied; the error lists applied, failed, and pending paths, so retry only failed and pending paths. Existing file permissions, line endings, and final-newline state are preserved. Returns changed file paths and operations with per-file and total line counts when all units succeed. In Code Mode, the Promise resolves on success and rejects with code/message on failure; the returned envelope has data.files and data.totals, not an ok or success flag. Oversized patches are rejected without advertising defensive limits as recommended patch sizes. A first-unit MAR_AGENT_PATCH_CONFLICT applies nothing; hunk match conflicts identify the affected path and hunk so you can reread only that file before retrying.`,
|
|
15
16
|
inputMode: 'freeform',
|
|
16
17
|
outputSchema: {
|
|
17
18
|
type: 'object',
|
|
@@ -51,15 +52,20 @@ export const applyPatchToolDefinition = {
|
|
|
51
52
|
},
|
|
52
53
|
inputSchema: {
|
|
53
54
|
type: 'object',
|
|
54
|
-
properties: {
|
|
55
|
-
|
|
55
|
+
properties: {
|
|
56
|
+
input: {
|
|
57
|
+
type: 'string',
|
|
58
|
+
description: 'Complete patch text, including the *** Begin Patch and *** End Patch markers.'
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
required: ['input'],
|
|
56
62
|
additionalProperties: false
|
|
57
63
|
}
|
|
58
64
|
};
|
|
59
65
|
export function applyPatchToolInput(input) {
|
|
60
|
-
const patch = typeof input === 'string' ? input : input?.
|
|
66
|
+
const patch = typeof input === 'string' ? input : input?.input;
|
|
61
67
|
if (typeof patch !== 'string')
|
|
62
|
-
throw
|
|
68
|
+
throw textToolInputError('input', input);
|
|
63
69
|
return patch;
|
|
64
70
|
}
|
|
65
71
|
const defaultFileOperations = { rename, rm };
|
package/dist/tools/local/exec.js
CHANGED
|
@@ -136,38 +136,38 @@ export const execWaitToolDefinition = {
|
|
|
136
136
|
/** Validate the public entry points before delegating to the single process manager. */
|
|
137
137
|
export function execToolInput(name, value) {
|
|
138
138
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
139
|
-
return invalidExecInput();
|
|
139
|
+
return invalidExecInput('Expected an object containing tool arguments.');
|
|
140
140
|
const input = value;
|
|
141
141
|
const allowed = name === 'exec'
|
|
142
142
|
? ['command', 'cwd', 'login', 'timeoutMs', 'yieldMs']
|
|
143
143
|
: ['processId', 'action', 'yieldMs', 'data'];
|
|
144
144
|
if (Object.keys(input).some((key) => !allowed.includes(key)))
|
|
145
|
-
return invalidExecInput();
|
|
145
|
+
return invalidExecInput(`Unexpected fields; expected only: ${allowed.join(', ')}.`);
|
|
146
146
|
if (name === 'exec')
|
|
147
147
|
return parseExecInput(input);
|
|
148
148
|
const action = input.action ?? 'poll';
|
|
149
|
-
if (!['poll', 'write', 'cancel'].includes(
|
|
150
|
-
return invalidExecInput();
|
|
149
|
+
if (typeof action !== 'string' || !['poll', 'write', 'cancel'].includes(action))
|
|
150
|
+
return invalidExecInput("Field 'action' must be one of: poll, write, cancel.");
|
|
151
151
|
return parseExecInput({ ...input, action });
|
|
152
152
|
}
|
|
153
153
|
export function parseExecInput(value) {
|
|
154
|
-
if (!value || typeof value !== 'object')
|
|
155
|
-
return invalidExecInput();
|
|
154
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
155
|
+
return invalidExecInput('Expected an object containing tool arguments.');
|
|
156
156
|
const input = value;
|
|
157
|
-
const action = input.action
|
|
158
|
-
if (!['start', 'poll', 'write', 'cancel'].includes(
|
|
159
|
-
return invalidExecInput();
|
|
160
|
-
const yieldMs = optionalBoundedInteger(input.yieldMs, 0, action === 'poll'
|
|
157
|
+
const action = input.action ?? 'start';
|
|
158
|
+
if (typeof action !== 'string' || !['start', 'poll', 'write', 'cancel'].includes(action))
|
|
159
|
+
return invalidExecInput("Field 'action' must be one of: start, poll, write, cancel.");
|
|
160
|
+
const yieldMs = optionalBoundedInteger('yieldMs', input.yieldMs, 0, action === 'poll'
|
|
161
161
|
? TOOL_EXECUTION_LIMITS.execMaxPollYieldMs
|
|
162
162
|
: TOOL_EXECUTION_LIMITS.execMaxYieldMs);
|
|
163
163
|
if (action === 'start') {
|
|
164
164
|
if (typeof input.command !== 'string' || input.command.trim() === '')
|
|
165
|
-
return invalidExecInput();
|
|
165
|
+
return invalidExecInput("Field 'command' must be a nonblank string.");
|
|
166
166
|
if (input.cwd !== undefined && input.cwd !== null && typeof input.cwd !== 'string')
|
|
167
|
-
return invalidExecInput();
|
|
167
|
+
return invalidExecInput("Field 'cwd' must be a string.");
|
|
168
168
|
if (input.login !== undefined && input.login !== null && typeof input.login !== 'boolean')
|
|
169
|
-
return invalidExecInput();
|
|
170
|
-
const timeoutMs = optionalBoundedInteger(input.timeoutMs, 1, TOOL_EXECUTION_LIMITS.execMaxTimeoutMs);
|
|
169
|
+
return invalidExecInput("Field 'login' must be a boolean.");
|
|
170
|
+
const timeoutMs = optionalBoundedInteger('timeoutMs', input.timeoutMs, 1, TOOL_EXECUTION_LIMITS.execMaxTimeoutMs);
|
|
171
171
|
return {
|
|
172
172
|
...(input.action === 'start' ? { action: 'start' } : {}),
|
|
173
173
|
command: input.command,
|
|
@@ -178,7 +178,7 @@ export function parseExecInput(value) {
|
|
|
178
178
|
};
|
|
179
179
|
}
|
|
180
180
|
if (typeof input.processId !== 'string' || input.processId === '')
|
|
181
|
-
return invalidExecInput();
|
|
181
|
+
return invalidExecInput("Field 'processId' must be a nonempty string.");
|
|
182
182
|
if (action === 'poll')
|
|
183
183
|
return {
|
|
184
184
|
action,
|
|
@@ -187,18 +187,18 @@ export function parseExecInput(value) {
|
|
|
187
187
|
};
|
|
188
188
|
if (action === 'write') {
|
|
189
189
|
if (typeof input.data !== 'string')
|
|
190
|
-
return invalidExecInput();
|
|
190
|
+
return invalidExecInput("Field 'data' must be a string for action 'write'.");
|
|
191
191
|
return { action, processId: input.processId, data: input.data };
|
|
192
192
|
}
|
|
193
193
|
return { action: 'cancel', processId: input.processId };
|
|
194
194
|
}
|
|
195
|
-
function optionalBoundedInteger(value, minimum, maximum) {
|
|
195
|
+
function optionalBoundedInteger(field, value, minimum, maximum) {
|
|
196
196
|
if (value === undefined || value === null)
|
|
197
197
|
return undefined;
|
|
198
198
|
if (!Number.isInteger(value) || value < minimum)
|
|
199
|
-
invalidExecInput();
|
|
199
|
+
invalidExecInput(`Field '${field}' must be an integer at least ${minimum}.`);
|
|
200
200
|
return Math.min(value, maximum);
|
|
201
201
|
}
|
|
202
|
-
function invalidExecInput() {
|
|
203
|
-
throw new AgentError('MAR_AGENT_TOOL_INPUT_INVALID',
|
|
202
|
+
function invalidExecInput(message) {
|
|
203
|
+
throw new AgentError('MAR_AGENT_TOOL_INPUT_INVALID', message);
|
|
204
204
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { open } from 'node:fs/promises';
|
|
3
|
+
import { crc32 } from 'node:zlib';
|
|
3
4
|
import { AgentError } from '../../error.js';
|
|
4
5
|
import { TOOL_EXECUTION_LIMITS } from '../execution-limits.js';
|
|
5
6
|
import { processImage, readImageMetadata } from './image-processing.js';
|
|
@@ -291,6 +292,8 @@ function validateImageContainer(data, mimeType) {
|
|
|
291
292
|
const next = offset + 12 + length;
|
|
292
293
|
if (next > data.length)
|
|
293
294
|
incompleteImage();
|
|
295
|
+
if (crc32(data.subarray(offset + 4, next - 4)) !== data.readUInt32BE(next - 4))
|
|
296
|
+
throw new AgentError('MAR_AGENT_IMAGE_INCOMPLETE', 'PNG chunk checksum is invalid. Repair or recreate the image and read it again.');
|
|
294
297
|
const type = data.toString('ascii', offset + 4, offset + 8);
|
|
295
298
|
if (offset === 8) {
|
|
296
299
|
if (type !== 'IHDR' ||
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AgentError } from '../../error.js';
|
|
2
|
+
/** Report missing or mistyped text input using only the expected field and actual value type. */
|
|
3
|
+
export function textToolInputError(field, value) {
|
|
4
|
+
const object = value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
5
|
+
const item = object ? value[field] : value;
|
|
6
|
+
const type = item === null ? 'null' : Array.isArray(item) ? 'array' : typeof item;
|
|
7
|
+
const message = object
|
|
8
|
+
? type === 'undefined'
|
|
9
|
+
? `Missing required string field "${field}".`
|
|
10
|
+
: `Expected string field "${field}"; received ${type}.`
|
|
11
|
+
: `Expected a string or an object with string field "${field}"; received ${type}.`;
|
|
12
|
+
return new AgentError('MAR_AGENT_TOOL_INPUT_INVALID', message);
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@myagentroam/agent",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.23",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/myagentroam/mar.git",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@jitl/quickjs-wasmfile-release-sync": "0.32.0",
|
|
55
|
+
"js-yaml": "4.3.2",
|
|
55
56
|
"quickjs-emscripten-core": "0.32.0",
|
|
56
57
|
"sharp": "0.35.5",
|
|
57
58
|
"undici": "7.29.0",
|
|
@@ -59,6 +60,7 @@
|
|
|
59
60
|
"zod": "4.4.3"
|
|
60
61
|
},
|
|
61
62
|
"devDependencies": {
|
|
63
|
+
"@types/js-yaml": "4.0.9",
|
|
62
64
|
"@types/ws": "8.18.1",
|
|
63
65
|
"vitest": "^4.0.14"
|
|
64
66
|
},
|