@nylorun/core 0.22.0-beta → 0.24.0-beta

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.
Files changed (82) hide show
  1. package/CHANGELOG.md +126 -0
  2. package/README.md +1 -1
  3. package/dist/compatibility.d.ts +120 -47
  4. package/dist/compatibility.js +122 -49
  5. package/dist/contracts.d.ts +2824 -907
  6. package/dist/contracts.js +1286 -585
  7. package/dist/define.d.ts +9 -12
  8. package/dist/define.js +8 -11
  9. package/dist/definition/assemble.d.ts +1 -3
  10. package/dist/definition/assemble.js +4 -8
  11. package/dist/definition/bound.d.ts +1 -1
  12. package/dist/definition/delegate.d.ts +5 -0
  13. package/dist/definition/delegate.js +6 -1
  14. package/dist/definition/from.d.ts +4 -2
  15. package/dist/definition/from.js +11 -29
  16. package/dist/definition/http-tool.d.ts +5 -3
  17. package/dist/definition/http-tool.js +8 -5
  18. package/dist/definition/manifest.d.ts +7 -6
  19. package/dist/definition/manifest.js +7 -6
  20. package/dist/definition/mcp.d.ts +1 -1
  21. package/dist/definition/media-reference.d.ts +2 -11
  22. package/dist/definition/media-reference.js +0 -12
  23. package/dist/definition/model-failure.js +1 -0
  24. package/dist/definition/removed.d.ts +7 -0
  25. package/dist/definition/removed.js +21 -0
  26. package/dist/definition/sections.d.ts +63 -0
  27. package/dist/definition/sections.js +204 -0
  28. package/dist/definition/trace.d.ts +0 -7
  29. package/dist/definition/trace.js +0 -34
  30. package/dist/definition/variant.d.ts +1 -1
  31. package/dist/definition/variant.js +1 -3
  32. package/dist/harness-api/artifacts.d.ts +84 -0
  33. package/dist/harness-api/artifacts.js +128 -0
  34. package/dist/harness-api/gates.d.ts +0 -4
  35. package/dist/harness-api/gates.js +0 -4
  36. package/dist/harness-api/harness-api.schema.json +2798 -1124
  37. package/dist/harness-api/index.d.ts +9 -6
  38. package/dist/harness-api/index.js +9 -6
  39. package/dist/harness-api/json-schema.js +5 -2
  40. package/dist/harness-api/mcp.d.ts +77 -30
  41. package/dist/harness-api/mcp.js +42 -25
  42. package/dist/harness-api/messages.d.ts +47 -17
  43. package/dist/harness-api/messages.js +20 -5
  44. package/dist/harness-api/schema.d.ts +609 -200
  45. package/dist/harness-api/schema.js +345 -62
  46. package/dist/harness-api/transcript.d.ts +8 -10
  47. package/dist/harness-api/transcript.js +27 -11
  48. package/dist/harness-api/transport.d.ts +7 -1
  49. package/dist/harness-api/transport.js +10 -7
  50. package/dist/manifest-schemas.d.ts +9 -5
  51. package/dist/manifest-schemas.js +23 -27
  52. package/dist/schemas/agent-manifest.schema.json +1508 -365
  53. package/dist/schemas/harness-manifest.schema.json +1273 -0
  54. package/dist/schemas/{environment-manifest.schema.json → runtime-manifest.schema.json} +165 -84
  55. package/dist/types/manifest.d.ts +72 -14
  56. package/dist/types/manifest.js +4 -0
  57. package/dist/types/model.d.ts +15 -5
  58. package/dist/utils/definition-files.d.ts +20 -6
  59. package/dist/utils/definition-files.js +31 -17
  60. package/dist/utils/file-systems.d.ts +20 -0
  61. package/dist/utils/file-systems.js +20 -0
  62. package/dist/utils/harness-id.d.ts +4 -1
  63. package/dist/utils/harness-id.js +4 -1
  64. package/dist/utils/media-types.d.ts +30 -0
  65. package/dist/utils/media-types.js +128 -0
  66. package/dist/utils/memory.d.ts +64 -0
  67. package/dist/utils/memory.js +139 -0
  68. package/dist/utils/runtime-limits.d.ts +280 -0
  69. package/dist/utils/runtime-limits.js +585 -0
  70. package/dist/utils/runtime-tools.d.ts +8 -16
  71. package/dist/utils/runtime-tools.js +8 -27
  72. package/dist/utils/sandbox.d.ts +4 -1
  73. package/dist/utils/sandbox.js +4 -1
  74. package/package.json +6 -5
  75. package/dist/definition/deferred-tools.d.ts +0 -27
  76. package/dist/definition/deferred-tools.js +0 -82
  77. package/dist/definition/runtime-manifest.d.ts +0 -30
  78. package/dist/definition/runtime-manifest.js +0 -132
  79. package/dist/definition/sandbox-tools.d.ts +0 -5
  80. package/dist/definition/sandbox-tools.js +0 -109
  81. package/dist/definition/skill-tools.d.ts +0 -23
  82. package/dist/definition/skill-tools.js +0 -76
@@ -0,0 +1,20 @@
1
+ /**
2
+ * What the file systems a workspace lives on take (B15: constants fixed by a standard, not
3
+ * limits): artifact names and folder paths are written as file names and paths there, when an
4
+ * artifact is copied into a sandbox, a folder unpacked, a skill mounted or a file downloaded.
5
+ */
6
+ /**
7
+ * The longest file name: `NAME_MAX`, 255 on ext4, XFS, APFS and NTFS (POSIX `<limits.h>`).
8
+ */
9
+ export const FILE_NAME_MAX = 255;
10
+ /**
11
+ * The longest path: `PATH_MAX` of macOS (1024, `<sys/syslimits.h>`), where a local Runtime's
12
+ * virtual workspace lives, and the smallest of the systems a workspace lives on (Linux's is
13
+ * 4096).
14
+ */
15
+ export const FILE_PATH_MAX = 1024;
16
+ /**
17
+ * The longest target a symbolic link of a folder artifact may name: Linux's `PATH_MAX` (4096,
18
+ * `<linux/limits.h>`), the most `symlink(2)` stores, since a sandbox's disk is a Linux file system.
19
+ */
20
+ export const LINK_TARGET_MAX = 4096;
@@ -4,6 +4,9 @@
4
4
  */
5
5
  /** The harness of a session that names no other: ours (`@nylorun/harness`). */
6
6
  export declare const DEFAULT_HARNESS = "nylorun";
7
- /** Lowercase letters, digits and dashes, starting with a letter: 2 to 63 characters. */
7
+ /**
8
+ * Lowercase letters, digits and dashes, starting with a letter: 2 to 63 characters, an RFC 1123
9
+ * DNS label's length; an identifier's grammar is the protocol's (it crosses the Runtime API, the Harness API and tokens, and means the same in every installation), so its length is a constant of protocol 15, not a setting.
10
+ */
8
11
  export declare const HARNESS_ID_PATTERN: RegExp;
9
12
  export declare function isHarnessId(value: unknown): value is string;
@@ -4,7 +4,10 @@
4
4
  */
5
5
  /** The harness of a session that names no other: ours (`@nylorun/harness`). */
6
6
  export const DEFAULT_HARNESS = "nylorun";
7
- /** Lowercase letters, digits and dashes, starting with a letter: 2 to 63 characters. */
7
+ /**
8
+ * Lowercase letters, digits and dashes, starting with a letter: 2 to 63 characters, an RFC 1123
9
+ * DNS label's length; an identifier's grammar is the protocol's (it crosses the Runtime API, the Harness API and tokens, and means the same in every installation), so its length is a constant of protocol 15, not a setting.
10
+ */
8
11
  export const HARNESS_ID_PATTERN = /^[a-z][a-z0-9-]{1,62}$/;
9
12
  export function isHarnessId(value) {
10
13
  return typeof value === "string" && HARNESS_ID_PATTERN.test(value);
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Media types of file artifacts: what an upload may declare, what a name's extension implies,
3
+ * and which model input a file is (`modelInputOf`, protocol 12): text, an image, a PDF, an Office
4
+ * document, audio or video. A model reads a file only when its inputs include that one. The
5
+ * Runtime types what it stores with these, a harness what it reads and writes over the Harness
6
+ * API's artifact seam and how it shows a file to the model, and the Model Gate what it refuses
7
+ * (protocol 15), so all three agree.
8
+ */
9
+ import type { ModelInput } from "../contracts.js";
10
+ /** The media type of bytes nothing says more about. */
11
+ export declare const DEFAULT_CONTENT_TYPE = "application/octet-stream";
12
+ /** Images the model reads as images. */
13
+ export declare const MODEL_IMAGE_TYPES: readonly string[];
14
+ /** The type part of a `Content-Type` value, lowercased, without parameters. */
15
+ export declare function essence(contentType: string): string;
16
+ /** A declared `Content-Type` as stored, or undefined when it is not a media type. */
17
+ export declare function normalizeContentType(value: string | undefined): string | undefined;
18
+ /** The media type a file name implies, or `application/octet-stream`. */
19
+ export declare function contentTypeFor(name: string): string;
20
+ export declare function isModelImage(contentType: string): boolean;
21
+ /** Files the model reads as text: `text/*`, JSON, XML, YAML and their `+json`/`+xml` kin. */
22
+ export declare function isText(contentType: string): boolean;
23
+ /** The usual extension of a media type, for a name the Runtime gives a file; undefined if none. */
24
+ export declare function extensionFor(contentType: string): string | undefined;
25
+ /** Word, Excel and PowerPoint documents, old and Open XML. */
26
+ export declare function isOffice(contentType: string): boolean;
27
+ /** The model input a file of `contentType` is, or undefined for a type no model reads. */
28
+ export declare function modelInputOf(contentType: string): ModelInput | undefined;
29
+ /** An input, in a sentence: "PDFs", "Office documents"; "files of this type" for none. */
30
+ export declare function inputLabel(input: ModelInput | undefined): string;
@@ -0,0 +1,128 @@
1
+ /** The media type of bytes nothing says more about. */
2
+ export const DEFAULT_CONTENT_TYPE = "application/octet-stream";
3
+ const MEDIA_TYPE = /^[a-z0-9][a-z0-9!#$&^_.+-]{0,126}\/[a-z0-9][a-z0-9!#$&^_.+-]{0,126}$/;
4
+ const BY_EXTENSION = {
5
+ png: "image/png",
6
+ jpg: "image/jpeg",
7
+ jpeg: "image/jpeg",
8
+ gif: "image/gif",
9
+ webp: "image/webp",
10
+ svg: "image/svg+xml",
11
+ pdf: "application/pdf",
12
+ doc: "application/msword",
13
+ docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
14
+ xls: "application/vnd.ms-excel",
15
+ xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
16
+ ppt: "application/vnd.ms-powerpoint",
17
+ pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
18
+ txt: "text/plain",
19
+ md: "text/markdown",
20
+ csv: "text/csv",
21
+ html: "text/html",
22
+ htm: "text/html",
23
+ css: "text/css",
24
+ js: "text/javascript",
25
+ mjs: "text/javascript",
26
+ ts: "text/x-typescript",
27
+ py: "text/x-python",
28
+ sh: "text/x-sh",
29
+ json: "application/json",
30
+ xml: "application/xml",
31
+ yaml: "application/yaml",
32
+ yml: "application/yaml",
33
+ zip: "application/zip",
34
+ tar: "application/x-tar",
35
+ gz: "application/gzip",
36
+ mp3: "audio/mpeg",
37
+ wav: "audio/wav",
38
+ mp4: "video/mp4",
39
+ };
40
+ /** Images the model reads as images. */
41
+ export const MODEL_IMAGE_TYPES = Object.freeze([
42
+ "image/png",
43
+ "image/jpeg",
44
+ "image/webp",
45
+ "image/gif",
46
+ ]);
47
+ /** The type part of a `Content-Type` value, lowercased, without parameters. */
48
+ export function essence(contentType) {
49
+ return contentType.split(";")[0].trim().toLowerCase();
50
+ }
51
+ /**
52
+ * The longest `Content-Type` kept, its parameters included: RFC 6838 §4.2's type and subtype of at
53
+ * most 127 characters each and the slash between them. A standard's constant.
54
+ */
55
+ const MEDIA_TYPE_MAX = 127 + 1 + 127;
56
+ /** A declared `Content-Type` as stored, or undefined when it is not a media type. */
57
+ export function normalizeContentType(value) {
58
+ if (value === undefined)
59
+ return undefined;
60
+ const trimmed = value.trim();
61
+ if (trimmed === "" || trimmed.length > MEDIA_TYPE_MAX)
62
+ return undefined;
63
+ return MEDIA_TYPE.test(essence(trimmed)) ? trimmed : undefined;
64
+ }
65
+ /** The media type a file name implies, or `application/octet-stream`. */
66
+ export function contentTypeFor(name) {
67
+ const dot = name.lastIndexOf(".");
68
+ if (dot < 0)
69
+ return DEFAULT_CONTENT_TYPE;
70
+ return BY_EXTENSION[name.slice(dot + 1).toLowerCase()] ?? DEFAULT_CONTENT_TYPE;
71
+ }
72
+ export function isModelImage(contentType) {
73
+ return MODEL_IMAGE_TYPES.includes(essence(contentType));
74
+ }
75
+ /** Files the model reads as text: `text/*`, JSON, XML, YAML and their `+json`/`+xml` kin. */
76
+ export function isText(contentType) {
77
+ const type = essence(contentType);
78
+ return (type.startsWith("text/") ||
79
+ type === "application/json" ||
80
+ type === "application/xml" ||
81
+ type === "application/yaml" ||
82
+ type === "application/x-yaml" ||
83
+ type === "application/javascript" ||
84
+ type.endsWith("+json") ||
85
+ type.endsWith("+xml"));
86
+ }
87
+ /** The usual extension of a media type, for a name the Runtime gives a file; undefined if none. */
88
+ export function extensionFor(contentType) {
89
+ const type = essence(contentType);
90
+ return Object.keys(BY_EXTENSION).find((extension) => BY_EXTENSION[extension] === type);
91
+ }
92
+ /** Word, Excel and PowerPoint documents, old and Open XML. */
93
+ export function isOffice(contentType) {
94
+ const type = essence(contentType);
95
+ return (type === "application/msword" ||
96
+ type === "application/vnd.ms-excel" ||
97
+ type === "application/vnd.ms-powerpoint" ||
98
+ type.startsWith("application/vnd.openxmlformats-officedocument."));
99
+ }
100
+ /** The model input a file of `contentType` is, or undefined for a type no model reads. */
101
+ export function modelInputOf(contentType) {
102
+ const type = essence(contentType);
103
+ if (isText(type))
104
+ return "text";
105
+ if (type.startsWith("image/"))
106
+ return "image";
107
+ if (type === "application/pdf")
108
+ return "pdf";
109
+ if (isOffice(type))
110
+ return "office";
111
+ if (type.startsWith("audio/"))
112
+ return "audio";
113
+ if (type.startsWith("video/"))
114
+ return "video";
115
+ return undefined;
116
+ }
117
+ const LABELS = {
118
+ text: "text files",
119
+ image: "images",
120
+ pdf: "PDFs",
121
+ office: "Office documents",
122
+ audio: "audio",
123
+ video: "video",
124
+ };
125
+ /** An input, in a sentence: "PDFs", "Office documents"; "files of this type" for none. */
126
+ export function inputLabel(input) {
127
+ return input === undefined ? "files of this type" : LABELS[input];
128
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Agent memory (track T5, D72): what a memory's path may be, and what its index line shows.
3
+ * The Runtime and the engine's `memory` tool share these rules, so a path the tool accepts is one
4
+ * the Runtime stores.
5
+ *
6
+ * A memory is a Markdown file under `/memories`: its path is `/memories/` and one or more
7
+ * `/`-separated segments, ends in `.md`, has no `.` or `..` segment, no empty segment, no
8
+ * backslash or control character, and is at most `MEMORY_PATH_MAX` characters. Folders are only
9
+ * the prefixes of memory paths; no row holds one.
10
+ */
11
+ /** Where an Agent's memories live, in the tool and in every path the Runtime stores. */
12
+ export declare const MEMORY_ROOT = "/memories";
13
+ /** The longest memory path, `/memories/` included. */
14
+ export declare const MEMORY_PATH_MAX = 512;
15
+ /** The longest `harness.memory.instructions`. */
16
+ export declare const MEMORY_INSTRUCTIONS_MAX = 4096;
17
+ /** The longest description an index line shows. */
18
+ export declare const MEMORY_DESCRIPTION_MAX = 200;
19
+ /** What `harness.memory.access` may be: reads and writes, or reads only. */
20
+ export declare const MEMORY_ACCESS: readonly ["read_write", "read_only"];
21
+ export type MemoryAccess = (typeof MEMORY_ACCESS)[number];
22
+ /** What changed a memory, as a version records it. */
23
+ export declare const MEMORY_OPERATIONS: readonly ["create", "str_replace", "insert", "delete", "rename"];
24
+ export type MemoryOperation = (typeof MEMORY_OPERATIONS)[number];
25
+ /**
26
+ * Normalises a path the model or an API caller sent: a trailing `/` is dropped, and a path
27
+ * without the leading `/` of `/memories` gets it. Answers the path, or why it is refused.
28
+ * `kind: "file"` requires a memory's path (ending in `.md`); `kind: "any"` also takes a folder,
29
+ * `/memories` itself included.
30
+ */
31
+ export declare function memoryPathOf(raw: string, kind: "file" | "any"): {
32
+ path: string;
33
+ } | {
34
+ error: string;
35
+ };
36
+ /** Whether `path` is `folder` or inside it (`folder` a normalised memory path). */
37
+ export declare function memoryPathWithin(path: string, folder: string): boolean;
38
+ /**
39
+ * What a memory's index line shows: the `description` of its YAML frontmatter, when it has one,
40
+ * cut to `MEMORY_DESCRIPTION_MAX` characters; otherwise `null`. Frontmatter is optional and the
41
+ * Runtime never writes into a memory.
42
+ */
43
+ export declare function memoryDescriptionOf(content: string): string | null;
44
+ /** The `memory` tool's commands, Anthropic's memory tool's. */
45
+ export declare const MEMORY_COMMANDS: readonly ["view", "create", "str_replace", "insert", "delete", "rename"];
46
+ export type MemoryCommandName = (typeof MEMORY_COMMANDS)[number];
47
+ /**
48
+ * Checks a `memory` call's input against its command's parameters, which a JSON schema cannot
49
+ * tie to the command: answers the command, or the error text the model reads
50
+ * (`Error: create requires file_text.`). Our engine checks before it sends a call, and the
51
+ * Runtime checks again for every harness.
52
+ */
53
+ export declare function checkMemoryCall(input: unknown): {
54
+ command: MemoryCommandName;
55
+ args: Record<string, unknown>;
56
+ } | {
57
+ error: string;
58
+ };
59
+ /**
60
+ * The `memory` call a tool name stands for when a model names the command in it (E-P1):
61
+ * `memory.create` and `memory/create` are `memory` with `command: "create"`. Answers the command,
62
+ * or `undefined` for any other name.
63
+ */
64
+ export declare function memoryAliasOf(name: string): MemoryCommandName | undefined;
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Agent memory (track T5, D72): what a memory's path may be, and what its index line shows.
3
+ * The Runtime and the engine's `memory` tool share these rules, so a path the tool accepts is one
4
+ * the Runtime stores.
5
+ *
6
+ * A memory is a Markdown file under `/memories`: its path is `/memories/` and one or more
7
+ * `/`-separated segments, ends in `.md`, has no `.` or `..` segment, no empty segment, no
8
+ * backslash or control character, and is at most `MEMORY_PATH_MAX` characters. Folders are only
9
+ * the prefixes of memory paths; no row holds one.
10
+ */
11
+ /** Where an Agent's memories live, in the tool and in every path the Runtime stores. */
12
+ export const MEMORY_ROOT = "/memories";
13
+ /** The longest memory path, `/memories/` included. */
14
+ export const MEMORY_PATH_MAX = 512;
15
+ /** The longest `harness.memory.instructions`. */
16
+ export const MEMORY_INSTRUCTIONS_MAX = 4096;
17
+ /** The longest description an index line shows. */
18
+ export const MEMORY_DESCRIPTION_MAX = 200;
19
+ /** What `harness.memory.access` may be: reads and writes, or reads only. */
20
+ export const MEMORY_ACCESS = ["read_write", "read_only"];
21
+ /** What changed a memory, as a version records it. */
22
+ export const MEMORY_OPERATIONS = ["create", "str_replace", "insert", "delete", "rename"];
23
+ // Control characters (C0, DEL, C1) and the backslash; a path holds neither.
24
+ const FORBIDDEN = /[\u0000-\u001f\u007f-\u009f\\]/;
25
+ /**
26
+ * Normalises a path the model or an API caller sent: a trailing `/` is dropped, and a path
27
+ * without the leading `/` of `/memories` gets it. Answers the path, or why it is refused.
28
+ * `kind: "file"` requires a memory's path (ending in `.md`); `kind: "any"` also takes a folder,
29
+ * `/memories` itself included.
30
+ */
31
+ export function memoryPathOf(raw, kind) {
32
+ let path = raw.trim();
33
+ if (path.startsWith("memories/") || path === "memories")
34
+ path = `/${path}`;
35
+ if (path.length > 1 && path.endsWith("/"))
36
+ path = path.slice(0, -1);
37
+ if (path !== MEMORY_ROOT && !path.startsWith(`${MEMORY_ROOT}/`))
38
+ return { error: `${raw} is not under ${MEMORY_ROOT}: memory paths start with ${MEMORY_ROOT}/` };
39
+ if (path.length > MEMORY_PATH_MAX)
40
+ return { error: `A memory path is at most ${MEMORY_PATH_MAX} characters` };
41
+ if (FORBIDDEN.test(path))
42
+ return { error: "A memory path has no backslash or control character" };
43
+ const segments = path.slice(MEMORY_ROOT.length + 1).split("/");
44
+ if (path !== MEMORY_ROOT && segments.some((segment) => segment === "" || segment === "." || segment === ".."))
45
+ return { error: `${raw} has an empty, "." or ".." segment` };
46
+ if (kind === "file") {
47
+ if (path === MEMORY_ROOT)
48
+ return { error: `${MEMORY_ROOT} is the memory folder, not a memory` };
49
+ if (!path.endsWith(".md") || path.endsWith("/.md"))
50
+ return { error: `${path} must end in .md: memories are Markdown files` };
51
+ }
52
+ return { path };
53
+ }
54
+ /** Whether `path` is `folder` or inside it (`folder` a normalised memory path). */
55
+ export function memoryPathWithin(path, folder) {
56
+ return folder === MEMORY_ROOT ? path.startsWith(`${MEMORY_ROOT}/`) : path === folder || path.startsWith(`${folder}/`);
57
+ }
58
+ /**
59
+ * What a memory's index line shows: the `description` of its YAML frontmatter, when it has one,
60
+ * cut to `MEMORY_DESCRIPTION_MAX` characters; otherwise `null`. Frontmatter is optional and the
61
+ * Runtime never writes into a memory.
62
+ */
63
+ export function memoryDescriptionOf(content) {
64
+ const match = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(content);
65
+ if (!match)
66
+ return null;
67
+ const line = /^description:[ \t]*(.*)$/m.exec(match[1]);
68
+ if (!line)
69
+ return null;
70
+ let value = line[1].trim();
71
+ if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'")))
72
+ value = value.slice(1, -1).trim();
73
+ if (value === "")
74
+ return null;
75
+ return value.length > MEMORY_DESCRIPTION_MAX ? `${value.slice(0, MEMORY_DESCRIPTION_MAX - 1)}…` : value;
76
+ }
77
+ /** The `memory` tool's commands, Anthropic's memory tool's. */
78
+ export const MEMORY_COMMANDS = ["view", "create", "str_replace", "insert", "delete", "rename"];
79
+ /** Each command's parameters: name → whether it is required, and its kind. */
80
+ const MEMORY_PARAMETERS = {
81
+ view: { path: { required: true, kind: "string" }, view_range: { required: false, kind: "range" } },
82
+ create: { path: { required: true, kind: "string" }, file_text: { required: true, kind: "string" } },
83
+ str_replace: {
84
+ path: { required: true, kind: "string" },
85
+ old_str: { required: true, kind: "string" },
86
+ new_str: { required: false, kind: "string" },
87
+ },
88
+ insert: {
89
+ path: { required: true, kind: "string" },
90
+ insert_line: { required: true, kind: "integer" },
91
+ insert_text: { required: true, kind: "string" },
92
+ },
93
+ delete: { path: { required: true, kind: "string" } },
94
+ rename: { old_path: { required: true, kind: "string" }, new_path: { required: true, kind: "string" } },
95
+ };
96
+ /**
97
+ * Checks a `memory` call's input against its command's parameters, which a JSON schema cannot
98
+ * tie to the command: answers the command, or the error text the model reads
99
+ * (`Error: create requires file_text.`). Our engine checks before it sends a call, and the
100
+ * Runtime checks again for every harness.
101
+ */
102
+ export function checkMemoryCall(input) {
103
+ const error = (message) => ({ error: `Error: ${message}` });
104
+ if (input === null || typeof input !== "object" || Array.isArray(input))
105
+ return error("the input is an object with a command.");
106
+ const args = input;
107
+ const command = args.command;
108
+ if (typeof command !== "string" || !MEMORY_COMMANDS.includes(command))
109
+ return error(`command must be one of ${MEMORY_COMMANDS.join(", ")}; got ${JSON.stringify(command ?? null)}.`);
110
+ const parameters = MEMORY_PARAMETERS[command];
111
+ const missing = Object.entries(parameters)
112
+ .filter(([name, spec]) => spec.required && (args[name] === undefined || args[name] === null))
113
+ .map(([name]) => name);
114
+ if (missing.length > 0)
115
+ return error(`${command} requires ${missing.join(" and ")}.`);
116
+ for (const [name, spec] of Object.entries(parameters)) {
117
+ const value = args[name];
118
+ if (value === undefined || value === null)
119
+ continue;
120
+ if (spec.kind === "string" && typeof value !== "string")
121
+ return error(`${name} must be a string.`);
122
+ if (spec.kind === "integer" && !(Number.isInteger(value) || (typeof value === "string" && /^-?\d+$/.test(value))))
123
+ return error(`${name} must be an integer.`);
124
+ if (spec.kind === "range" &&
125
+ !(Array.isArray(value) && value.length === 2 && value.every((item) => Number.isInteger(Number(item)))))
126
+ return error(`${name} must be [start_line, end_line].`);
127
+ }
128
+ return { command: command, args };
129
+ }
130
+ /**
131
+ * The `memory` call a tool name stands for when a model names the command in it (E-P1):
132
+ * `memory.create` and `memory/create` are `memory` with `command: "create"`. Answers the command,
133
+ * or `undefined` for any other name.
134
+ */
135
+ export function memoryAliasOf(name) {
136
+ const match = /^memory[./]([a-z_]+)$/.exec(name);
137
+ const command = match?.[1];
138
+ return command && MEMORY_COMMANDS.includes(command) ? command : undefined;
139
+ }