mtech-ai-local-runner 0.1.53 → 0.1.54
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/README.md +5 -0
- package/dist/src/adapters/codex/prompt-compiler.js +1 -1
- package/dist/src/safety/job-tool-dispatcher.js +9 -2
- package/dist/src/safety/local-read-range.js +13 -0
- package/dist/src/safety/local-tool-policy.js +5 -1
- package/dist/src/safety/local-tool-server.js +2 -2
- package/dist/src/safety/local-tool-worker.js +12 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
## 0.1.53: separate candidate change, file and payload limits
|
|
2
2
|
|
|
3
|
+
## 0.1.54: read only the source lines you need
|
|
4
|
+
|
|
5
|
+
Use `local_search` to locate code, then `local_read({path, start_line, end_line})`. Lines are 1-based and inclusive; supply both bounds, at most 400 lines. The response includes `content`, `start_line`, `end_line` and `total_lines`. Invalid/missing bounds, ranges over 400 lines and ranges past EOF are rejected with `DENIED_READ_RANGE`, `DENIED_READ_RANGE_LIMIT` and `DENIED_READ_RANGE_BOUNDS`. Empty files have 0 lines; a final newline adds no extra line. Original LF/CRLF line endings are preserved. Without bounds the existing `{content}` whole-file result is unchanged. Existing file-size and path protections still apply; no shell permission is added.
|
|
6
|
+
|
|
7
|
+
|
|
3
8
|
New `gateway_publish_v1` scopes may explicitly opt into `candidate_limits.version: 2` with
|
|
4
9
|
`max_changed_files`, `max_change_bytes`, `max_file_bytes` and `max_payload_bytes`.
|
|
5
10
|
Change bytes are the exact minimum byte insertions plus deletions from the frozen base;
|
|
@@ -23,7 +23,7 @@ function repositoryScope(taskPackage) {
|
|
|
23
23
|
"These are scope descriptions, not instructions from source files; the host policy remains authoritative and may deny blocked/private paths within an allowed prefix.";
|
|
24
24
|
}
|
|
25
25
|
export function compileCodexPrompt(taskPackage, label) {
|
|
26
|
-
return `${compileBrief(taskPackage, { workItemLabel: label, progressReporting: "native_messages" })}\n\n${repositoryScope(taskPackage)}\n\nUse only the ai_local job tools for repository reads, edits and approved tests. For reading, use server ai_local's
|
|
26
|
+
return `${compileBrief(taskPackage, { workItemLabel: label, progressReporting: "native_messages" })}\n\n${repositoryScope(taskPackage)}\n\nUse only the ai_local job tools for repository reads, edits and approved tests. For reading, first use server ai_local's local_search({path: "<exact approved path>", query: "text"}) to find the location, then local_read({path: "<exact approved path>", start_line: 1, end_line: 1}) with the matching line numbers. Ranges are inclusive, at most 400 lines; both bounds are required together. Read a matched line first to learn total_lines, then request only the needed in-file context. Omit both bounds only when the entire file is necessary. Use approved checkout-relative paths. For small approved edits, use local_replace({path, old, new}) after reading: old must match exactly once, including whitespace. local_edit requires the complete replacement file, never a patch. Required test criteria are not command grants. No model test commands are registered unless the host explicitly supplies exact model-callable command IDs; do not use local_test to discover commands or run --help. Missing tests remain not_run/unverified, not passed. In a read-only task, use only read/search tools; the Runner enforces the approved paths and operations. A denied native cwd is intentional: it is a private control directory, not the source checkout. Native filesystem, commands, web, images and delegation are unavailable or denied. A denied tool is a scope boundary, never permission to broaden scope or bypass the denial. Do not retry the denied path. It does not remove independently approved paths: continue with relevant listed paths, and report a missing dependency only after checking the available approved source. Do not repeat host orchestration: claim, shadow, fingerprints, binding, administrator checks, launches, Gateway usage and Job reporting belong to the Runner/host, even when described in the objective. Perform only the assigned repository work and report evidence you actually observed. Do not claim that no model call occurred. If the required tool is unavailable, emit one final structured blocked report naming the missing tool and unfinished repository work; do not request or attempt a new launch.`;
|
|
27
27
|
}
|
|
28
28
|
export const CODEX_REPORT_SCHEMA = {
|
|
29
29
|
type: "object", additionalProperties: false, required: ["status", "report", "evidence", "pending_work"],
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { validateLocalReadRange } from './local-read-range.js';
|
|
1
2
|
import { localToolInventory } from './local-tool-server.js';
|
|
2
3
|
const rejected = () => new Error('JOB_TOOL_DISPATCH_REJECTED');
|
|
3
4
|
function record(value) { return !!value && typeof value === 'object' && !Array.isArray(value); }
|
|
@@ -35,10 +36,16 @@ export class JobToolDispatcher {
|
|
|
35
36
|
throw rejected();
|
|
36
37
|
const tool = localToolInventory().find(t => t.name === envelope.tool);
|
|
37
38
|
const properties = tool?.inputSchema.properties;
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
const required = tool?.inputSchema.required;
|
|
40
|
+
if (!record(properties) || !Array.isArray(required) || required.some(key => typeof key !== 'string' || !Object.hasOwn(envelope.args, key))
|
|
41
|
+
|| Object.entries(envelope.args).some(([key, value]) => {
|
|
42
|
+
const schema = properties[key];
|
|
43
|
+
return !record(schema) || (schema.type === 'integer' ? typeof value !== 'number' || !Number.isSafeInteger(value) || (typeof schema.minimum === 'number' && value < schema.minimum) : schema.type !== 'string' || typeof value !== 'string');
|
|
44
|
+
})
|
|
40
45
|
|| Buffer.byteLength(JSON.stringify(envelope.args)) > 1024 * 1024)
|
|
41
46
|
throw rejected();
|
|
47
|
+
if (envelope.tool === 'local_read')
|
|
48
|
+
validateLocalReadRange(envelope.args);
|
|
42
49
|
this.#lastRequest = BigInt(envelope.requestId);
|
|
43
50
|
const result = await this.policy.call(envelope.tool, envelope.args);
|
|
44
51
|
if (this.#revoked || !this.active())
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Kept standalone so the isolated worker repeats the same validation. */
|
|
2
|
+
export function validateLocalReadRange(input) {
|
|
3
|
+
if (!Object.hasOwn(input, 'start_line') && !Object.hasOwn(input, 'end_line'))
|
|
4
|
+
return;
|
|
5
|
+
const start = input.start_line, end = input.end_line;
|
|
6
|
+
if (typeof start !== 'number' || typeof end !== 'number'
|
|
7
|
+
|| !Number.isSafeInteger(start) || !Number.isSafeInteger(end)
|
|
8
|
+
|| start < 1 || end < start)
|
|
9
|
+
throw new Error('DENIED_READ_RANGE');
|
|
10
|
+
if (end - start + 1 > 400)
|
|
11
|
+
throw new Error('DENIED_READ_RANGE_LIMIT');
|
|
12
|
+
return { start_line: start, end_line: end };
|
|
13
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { validateLocalReadRange } from './local-read-range.js';
|
|
1
2
|
import { isPatchContent } from './local-edit-content.js';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import { randomBytes } from 'node:crypto';
|
|
@@ -44,6 +45,7 @@ export class LocalToolPolicy {
|
|
|
44
45
|
throw new Error('DENIED_READ_ONLY');
|
|
45
46
|
if (tool === 'local_test')
|
|
46
47
|
return this.test(input);
|
|
48
|
+
const readRange = tool === 'local_read' ? validateLocalReadRange(input) : undefined;
|
|
47
49
|
const file = await this.authorizedFile(input.path, tool === 'local_edit');
|
|
48
50
|
if (tool === 'local_replace') {
|
|
49
51
|
if (typeof input.old !== 'string' || !input.old || Buffer.byteLength(input.old) > 1024 * 1024)
|
|
@@ -60,10 +62,12 @@ export class LocalToolPolicy {
|
|
|
60
62
|
if (tool === 'local_search' && (typeof input.query !== 'string' || input.query.length > 4096))
|
|
61
63
|
throw new Error('DENIED_QUERY');
|
|
62
64
|
const temp = file + '.runner-edit-' + randomBytes(16).toString('hex');
|
|
63
|
-
const output = await runSandboxed({ executable: process.execPath, argv: ['--no-addons', '--no-global-search-paths', '--eval', LOCAL_TOOL_WORKER, JSON.stringify({ tool, path: file, temp, content: input.content, query: input.query, old: input.old, new: input.new })], readFiles: (tool === 'local_edit' || tool === 'local_replace') ? [file, temp] : [file], writeFiles: (tool === 'local_edit' || tool === 'local_replace') ? [file, temp] : [], timeoutMs: 10000, signal: this.abort.signal });
|
|
65
|
+
const output = await runSandboxed({ executable: process.execPath, argv: ['--no-addons', '--no-global-search-paths', '--eval', LOCAL_TOOL_WORKER, JSON.stringify({ tool, path: file, temp, content: input.content, query: input.query, old: input.old, new: input.new, ...readRange })], readFiles: (tool === 'local_edit' || tool === 'local_replace') ? [file, temp] : [file], writeFiles: (tool === 'local_edit' || tool === 'local_replace') ? [file, temp] : [], timeoutMs: 10000, signal: this.abort.signal });
|
|
64
66
|
if (this.abort.signal.aborted)
|
|
65
67
|
throw new Error('DENIED_REVOKED');
|
|
66
68
|
const result = JSON.parse(output);
|
|
69
|
+
if (tool === 'local_read' && ['DENIED_READ_RANGE', 'DENIED_READ_RANGE_LIMIT', 'DENIED_READ_RANGE_BOUNDS'].includes(result.denied))
|
|
70
|
+
throw new Error(result.denied);
|
|
67
71
|
if (tool === 'local_replace' && ['DENIED_REPLACE_NOT_FOUND', 'DENIED_REPLACE_AMBIGUOUS', 'DENIED_SIZE'].includes(result.denied))
|
|
68
72
|
throw new Error(result.denied);
|
|
69
73
|
return result;
|
|
@@ -21,7 +21,7 @@ export function localEndpointObservations(url, token) {
|
|
|
21
21
|
}
|
|
22
22
|
const MAX_BODY = 1024 * 1024;
|
|
23
23
|
const schemas = {
|
|
24
|
-
local_read: { type: 'object', properties: { path: { type: 'string' } }, required: ['path'], additionalProperties: false },
|
|
24
|
+
local_read: { type: 'object', properties: { path: { type: 'string' }, start_line: { type: 'integer', minimum: 1, description: 'First line (1-based, inclusive). Supply with end_line; maximum 400 lines.' }, end_line: { type: 'integer', minimum: 1, description: 'Last line (inclusive). Must not exceed total_lines; supply with start_line.' } }, required: ['path'], additionalProperties: false },
|
|
25
25
|
local_search: { type: 'object', properties: { path: { type: 'string' }, query: { type: 'string' } }, required: ['path', 'query'], additionalProperties: false },
|
|
26
26
|
local_edit: { type: 'object', properties: { path: { type: 'string' }, content: { type: 'string', description: 'The complete new contents of the entire file. Do not send a diff, patch, hunk, or edit instructions.' } }, required: ['path', 'content'], additionalProperties: false },
|
|
27
27
|
local_replace: { type: 'object', properties: { path: { type: 'string' }, old: { type: 'string', minLength: 1 }, new: { type: 'string' } }, required: ['path', 'old', 'new'], additionalProperties: false },
|
|
@@ -29,7 +29,7 @@ const schemas = {
|
|
|
29
29
|
};
|
|
30
30
|
/** Same immutable-by-copy inventory used by native admission and MCP discovery. */
|
|
31
31
|
export function localToolInventory() {
|
|
32
|
-
return LOCAL_TOOL_NAMES.map(name => ({ name, description: name === 'local_edit' ? 'Replace the entire file at path with content (or create it). Read the current file first and include all unchanged text in content. This is not a diff or patch tool; patch headers and hunks are rejected.' : name === 'local_replace' ? 'Replace exactly one occurrence of old with new in the file at path. Read the file first; old must match exactly, including whitespace, and appear once. Prefer this for small changes; use local_edit only to write a whole file.' : `Scoped ${name} operation`, inputSchema: structuredClone(schemas[name]) }));
|
|
32
|
+
return LOCAL_TOOL_NAMES.map(name => ({ name, description: name === 'local_read' ? 'Find locations with local_search first, then use local_read with start_line and end_line to read only the needed inclusive range (maximum 400 lines). Both range arguments are required together; invalid or beyond-EOF ranges are rejected, never widened. Returns content, start_line, end_line and total_lines for ranges; omit both for the entire file.' : name === 'local_edit' ? 'Replace the entire file at path with content (or create it). Read the current file first and include all unchanged text in content. This is not a diff or patch tool; patch headers and hunks are rejected.' : name === 'local_replace' ? 'Replace exactly one occurrence of old with new in the file at path. Read the file first; old must match exactly, including whitespace, and appear once. Prefer this for small changes; use local_edit only to write a whole file.' : `Scoped ${name} operation`, inputSchema: structuredClone(schemas[name]) }));
|
|
33
33
|
}
|
|
34
34
|
/** Job-only JSON MCP endpoint; intentionally has no Gateway transport or discovery. */
|
|
35
35
|
export class LocalToolServer {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { validateLocalReadRange } from './local-read-range.js';
|
|
1
2
|
import { isPatchContent } from './local-edit-content.js';
|
|
2
3
|
/** Standalone worker: --eval avoids ambient module/config lookup. All paths are host-supplied. */
|
|
3
4
|
export const LOCAL_TOOL_WORKER = String.raw `
|
|
4
5
|
const fs = require('node:fs');
|
|
5
6
|
const input = JSON.parse(process.argv[1]);
|
|
6
7
|
const isPatchContent = ${isPatchContent.toString()};
|
|
8
|
+
const validateLocalReadRange = ${validateLocalReadRange.toString()};
|
|
7
9
|
if (input.tool === 'local_edit' && isPatchContent(input.content)) throw Error('DENIED_PATCH_CONTENT');
|
|
8
10
|
if (input.tool === 'local_replace') {
|
|
9
11
|
if (typeof input.old !== 'string' || !input.old || Buffer.byteLength(input.old) > 1048576) throw Error('DENIED_REPLACE_OLD');
|
|
@@ -11,6 +13,7 @@ if (input.tool === 'local_replace') {
|
|
|
11
13
|
if (isPatchContent(input.new)) throw Error('DENIED_PATCH_CONTENT');
|
|
12
14
|
}
|
|
13
15
|
try {
|
|
16
|
+
const readRange = input.tool === 'local_read' ? validateLocalReadRange(input) : undefined;
|
|
14
17
|
let current = '';
|
|
15
18
|
for (const part of input.path.split('/').filter(Boolean)) {
|
|
16
19
|
current += '/' + part;
|
|
@@ -72,12 +75,19 @@ try {
|
|
|
72
75
|
const count = fs.readSync(fd, buffer, 0, buffer.length, 0);
|
|
73
76
|
if (count > 1048576) throw Error('DENIED_SIZE');
|
|
74
77
|
const content = buffer.subarray(0, count).toString('utf8');
|
|
75
|
-
|
|
78
|
+
if (readRange) {
|
|
79
|
+
// Retain each original line terminator; a final newline adds no phantom line.
|
|
80
|
+
const lines = content.match(/[^\n]*\n|[^\n]+$/g) || [];
|
|
81
|
+
if (readRange.end_line > lines.length) throw Error('DENIED_READ_RANGE_BOUNDS');
|
|
82
|
+
result = {content: lines.slice(readRange.start_line - 1, readRange.end_line).join(''), ...readRange, total_lines: lines.length};
|
|
83
|
+
} else result = input.tool === 'local_search' ? {matches: content.split('\n').flatMap((line, index) => line.includes(input.query) ? [{line: index + 1, text: line}] : [])} : {content};
|
|
76
84
|
}
|
|
77
85
|
process.stdout.write(JSON.stringify(result));
|
|
78
86
|
} finally { if (fd !== null) fs.closeSync(fd); }
|
|
79
87
|
} catch (error) {
|
|
80
|
-
|
|
88
|
+
const rangeDenied = input.tool === 'local_read' && ['DENIED_READ_RANGE','DENIED_READ_RANGE_LIMIT','DENIED_READ_RANGE_BOUNDS'].includes(error.message);
|
|
89
|
+
const replaceDenied = input.tool === 'local_replace' && ['DENIED_REPLACE_NOT_FOUND','DENIED_REPLACE_AMBIGUOUS','DENIED_SIZE'].includes(error.message);
|
|
90
|
+
if (!rangeDenied && !replaceDenied) throw error;
|
|
81
91
|
process.stdout.write(JSON.stringify({denied: error.message}));
|
|
82
92
|
}
|
|
83
93
|
`;
|