mtech-ai-local-runner 0.1.47 → 0.1.48

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,10 @@
1
1
  import { chmod, mkdir, open, readFile, rename, rm, writeFile } from "node:fs/promises";
2
2
  import { isAbsolute, join } from "node:path";
3
3
  import { randomBytes } from "node:crypto";
4
+ /** The mode a stored configuration runs in (Work Item e1c08b33): a missing mode is a full runner. */
5
+ export function runnerMode(config) {
6
+ return config.mode ?? "full";
7
+ }
4
8
  export class FileLocalConfigStore {
5
9
  stateRoot;
6
10
  filePath;
@@ -49,8 +53,9 @@ export class FileLocalConfigStore {
49
53
  || typeof candidate.workspaceRoot !== "string"
50
54
  || !isAbsolute(candidate.workspaceRoot)
51
55
  || candidate.concurrency !== 1
56
+ || (candidate.mode !== undefined && candidate.mode !== "full" && candidate.mode !== "messenger")
52
57
  || Object.keys(candidate).some((key) => ![
53
- "schemaVersion", "gatewayMcpUrl", "runnerId", "workspaceRoot", "concurrency",
58
+ "schemaVersion", "gatewayMcpUrl", "runnerId", "workspaceRoot", "concurrency", "mode",
54
59
  ].includes(key))) {
55
60
  return null;
56
61
  }
@@ -60,6 +65,7 @@ export class FileLocalConfigStore {
60
65
  runnerId: candidate.runnerId,
61
66
  workspaceRoot: candidate.workspaceRoot,
62
67
  concurrency: 1,
68
+ ...(candidate.mode === undefined ? {} : { mode: candidate.mode }),
63
69
  };
64
70
  }
65
71
  }
@@ -0,0 +1,14 @@
1
+ /** local_edit accepts the complete replacement file, never an edit script.
2
+ * Pure function: the identical predicate is embedded in the isolated worker.
3
+ * Ordinary source strings and YAML separators are not patch headers. */
4
+ export function isPatchContent(content) {
5
+ const lines = content.replace(/^\uFEFF/, '').split(/\r?\n/);
6
+ return lines.some((line, index) => {
7
+ const value = line.trimStart();
8
+ return /^\*\*\* (?:Begin Patch|End Patch|End of File|(?:Update|Add|Delete) File:|Move to:)(?:\s|$)/.test(value)
9
+ || /^@@(?:\s|$)/.test(value)
10
+ || /^diff --git\s/.test(value)
11
+ || /^(?:--- (?:a\/|\/dev\/null)|\+\+\+ (?:b\/|\/dev\/null))/.test(value)
12
+ || /^---[ \t]+\S/.test(value) && /^\+\+\+[ \t]+\S/.test(lines[index + 1]?.trimStart() ?? '');
13
+ });
14
+ }
@@ -1,3 +1,4 @@
1
+ import { isPatchContent } from './local-edit-content.js';
1
2
  import path from 'node:path';
2
3
  import { randomBytes } from 'node:crypto';
3
4
  import { lstat, realpath } from 'node:fs/promises';
@@ -46,6 +47,8 @@ export class LocalToolPolicy {
46
47
  const file = await this.authorizedFile(input.path, tool === 'local_edit');
47
48
  if (tool === 'local_edit' && (typeof input.content !== 'string' || Buffer.byteLength(input.content) > 1024 * 1024))
48
49
  throw new Error('DENIED_CONTENT');
50
+ if (tool === 'local_edit' && isPatchContent(input.content))
51
+ throw new Error('DENIED_PATCH_CONTENT');
49
52
  if (tool === 'local_search' && (typeof input.query !== 'string' || input.query.length > 4096))
50
53
  throw new Error('DENIED_QUERY');
51
54
  const temp = file + '.runner-edit-' + randomBytes(16).toString('hex');
@@ -23,12 +23,12 @@ const MAX_BODY = 1024 * 1024;
23
23
  const schemas = {
24
24
  local_read: { type: 'object', properties: { path: { type: 'string' } }, required: ['path'], additionalProperties: false },
25
25
  local_search: { type: 'object', properties: { path: { type: 'string' }, query: { type: 'string' } }, required: ['path', 'query'], additionalProperties: false },
26
- local_edit: { type: 'object', properties: { path: { type: 'string' }, content: { type: 'string' } }, required: ['path', 'content'], additionalProperties: false },
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_test: { type: 'object', properties: { command: { type: 'string' } }, required: ['command'], additionalProperties: false },
28
28
  };
29
29
  /** Same immutable-by-copy inventory used by native admission and MCP discovery. */
30
30
  export function localToolInventory() {
31
- return LOCAL_TOOL_NAMES.map(name => ({ name, description: `Scoped ${name} operation`, inputSchema: structuredClone(schemas[name]) }));
31
+ 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.' : `Scoped ${name} operation`, inputSchema: structuredClone(schemas[name]) }));
32
32
  }
33
33
  /** Job-only JSON MCP endpoint; intentionally has no Gateway transport or discovery. */
34
34
  export class LocalToolServer {
@@ -1,7 +1,10 @@
1
+ import { isPatchContent } from './local-edit-content.js';
1
2
  /** Standalone worker: --eval avoids ambient module/config lookup. All paths are host-supplied. */
2
3
  export const LOCAL_TOOL_WORKER = String.raw `
3
4
  const fs = require('node:fs');
4
5
  const input = JSON.parse(process.argv[1]);
6
+ const isPatchContent = ${isPatchContent.toString()};
7
+ if (input.tool === 'local_edit' && isPatchContent(input.content)) throw Error('DENIED_PATCH_CONTENT');
5
8
  let current = '';
6
9
  for (const part of input.path.split('/').filter(Boolean)) {
7
10
  current += '/' + part;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mtech-ai-local-runner",
3
- "version": "0.1.47",
3
+ "version": "0.1.48",
4
4
  "private": false,
5
5
  "license": "UNLICENSED",
6
6
  "bin": {