@tangle-network/agent-runtime 0.338.0 → 0.340.0

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 (144) hide show
  1. package/dist/{activation-kbkAuSmY.js → activation-D2PVljaw.js} +5 -18
  2. package/dist/{activation-kbkAuSmY.js.map → activation-D2PVljaw.js.map} +1 -1
  3. package/dist/{activation-CsbNax2X.d.ts → activation-DGDl4wwI.d.ts} +4 -24
  4. package/dist/agent.d.ts +4 -18
  5. package/dist/agent.js +3 -21
  6. package/dist/agent.js.map +1 -1
  7. package/dist/analyst-loop.d.ts +2 -2
  8. package/dist/{bundle-DM60AI2B.js → bundle-DNUq-OPW.js} +2 -2
  9. package/dist/{bundle-DM60AI2B.js.map → bundle-DNUq-OPW.js.map} +1 -1
  10. package/dist/candidate-execution/index.d.ts +4 -101
  11. package/dist/candidate-execution/index.js +10 -395
  12. package/dist/candidate-execution/index.js.map +1 -1
  13. package/dist/{delegate-Se1YZKMb.js → delegate-CtJIS-tp.js} +2 -2
  14. package/dist/{delegate-Se1YZKMb.js.map → delegate-CtJIS-tp.js.map} +1 -1
  15. package/dist/{driver-control-acknowledgers-T2a1Ouay.js → driver-control-acknowledgers-MTrs8HAF.js} +15 -11
  16. package/dist/driver-control-acknowledgers-MTrs8HAF.js.map +1 -0
  17. package/dist/{durable-file-B_eJr6Mb.js → durable-file-gNI9ILAn.js} +1 -3
  18. package/dist/durable-file-gNI9ILAn.js.map +1 -0
  19. package/dist/durable.d.ts +3 -35
  20. package/dist/durable.js +10 -10
  21. package/dist/durable.js.map +1 -1
  22. package/dist/{graph-CY0wH838.js → graph-DfWqp_1e.js} +4 -4
  23. package/dist/graph-DfWqp_1e.js.map +1 -0
  24. package/dist/{graph-registry-By0tUj4S.js → graph-registry-BnO64cn8.js} +3 -3
  25. package/dist/{graph-registry-By0tUj4S.js.map → graph-registry-BnO64cn8.js.map} +1 -1
  26. package/dist/{improve-CWGBT13K.js → improve-CKRVQqzt.js} +8 -35
  27. package/dist/improve-CKRVQqzt.js.map +1 -0
  28. package/dist/{improvement-adapter-D5gwwoXQ.d.ts → improvement-adapter-sIthWkcN.d.ts} +3 -21
  29. package/dist/index.d.ts +10 -215
  30. package/dist/index.js +91 -302
  31. package/dist/index.js.map +1 -1
  32. package/dist/intelligence.d.ts +11 -143
  33. package/dist/intelligence.js +7 -81
  34. package/dist/intelligence.js.map +1 -1
  35. package/dist/{jsonl-file-DBv31uPi.js → jsonl-file-C9Kde_0Z.js} +2 -2
  36. package/dist/{jsonl-file-DBv31uPi.js.map → jsonl-file-C9Kde_0Z.js.map} +1 -1
  37. package/dist/kernel.d.ts +4 -3
  38. package/dist/kernel.js +12 -14
  39. package/dist/loop-runner-C4EWEcXf.d.ts +32 -0
  40. package/dist/loop-runner-DNWbTcVm.js +59 -0
  41. package/dist/loop-runner-DNWbTcVm.js.map +1 -0
  42. package/dist/loop-runner-bin.d.ts +32 -2
  43. package/dist/loop-runner-bin.js +93 -1
  44. package/dist/loop-runner-bin.js.map +1 -0
  45. package/dist/mcp/bin.js +3 -3
  46. package/dist/mcp/index.d.ts +99 -418
  47. package/dist/mcp/index.js +121 -203
  48. package/dist/mcp/index.js.map +1 -1
  49. package/dist/mcp/memory-bin.js +231 -1
  50. package/dist/mcp/memory-bin.js.map +1 -1
  51. package/dist/model-policy-CyCUwHed.js.map +1 -1
  52. package/dist/placement.d.ts +2 -33
  53. package/dist/placement.js +1 -35
  54. package/dist/placement.js.map +1 -1
  55. package/dist/platform.d.ts +188 -1
  56. package/dist/platform.js +129 -1
  57. package/dist/platform.js.map +1 -1
  58. package/dist/{prepare-Bt0IouPq.js → prepare-FzJoS68l.js} +8 -160
  59. package/dist/prepare-FzJoS68l.js.map +1 -0
  60. package/dist/{profile-Do-5xO_D.js → profile-DToH0XEs.js} +2 -2
  61. package/dist/profile-DToH0XEs.js.map +1 -0
  62. package/dist/profile-materialization-bPm0gGLO.d.ts +49 -0
  63. package/dist/profiles.d.ts +2 -2
  64. package/dist/profiles.js +3 -40
  65. package/dist/profiles.js.map +1 -1
  66. package/dist/{protected-model-port-DGxQ8_YM.d.ts → protected-model-port-DVVh-hEk.d.ts} +3 -33
  67. package/dist/protected-redaction-DFCeo4vg.js.map +1 -1
  68. package/dist/{provision-supervisor-0jMufp4h.js → provision-supervisor-DqvWXmAE.js} +6 -6
  69. package/dist/{provision-supervisor-0jMufp4h.js.map → provision-supervisor-DqvWXmAE.js.map} +1 -1
  70. package/dist/{run-cancellation-BoW5Sg9Y.js → run-cancellation-C9oL62sW.js} +3 -7
  71. package/dist/{run-cancellation-BoW5Sg9Y.js.map → run-cancellation-C9oL62sW.js.map} +1 -1
  72. package/dist/{runtime-D37zRSs7.js → runtime-C55Zgo1R.js} +2531 -2889
  73. package/dist/runtime-C55Zgo1R.js.map +1 -0
  74. package/dist/{runtime-hooks-Bj6wJHlH.d.ts → runtime-hooks-nsqxSUFL.d.ts} +2 -6
  75. package/dist/{sandbox-profile-compat-xSoVtdWw.js → sandbox-profile-compat-DRr3JwDx.js} +2 -4
  76. package/dist/sandbox-profile-compat-DRr3JwDx.js.map +1 -0
  77. package/dist/{search-executor-DmgUm5p7.js → search-executor-ChOlRBgg.js} +3 -3
  78. package/dist/search-executor-ChOlRBgg.js.map +1 -0
  79. package/dist/{server-DQHJszfk.js → server-DkVBSN_S.js} +362 -67
  80. package/dist/server-DkVBSN_S.js.map +1 -0
  81. package/dist/{structural-rollout-DAvIE8mw.js → structural-rollout-C1LEk_zq.js} +80 -80
  82. package/dist/structural-rollout-C1LEk_zq.js.map +1 -0
  83. package/dist/{substrate-B0TYNrXn.js → substrate-CGDFTSRh.js} +2 -9
  84. package/dist/substrate-CGDFTSRh.js.map +1 -0
  85. package/dist/{supervise-WuPAwfPh.js → supervise-CaUAxZZP.js} +92 -75
  86. package/dist/supervise-CaUAxZZP.js.map +1 -0
  87. package/dist/{supervisor-CPG1I9UN.js → supervisor-VXuN2OHT.js} +205 -319
  88. package/dist/supervisor-VXuN2OHT.js.map +1 -0
  89. package/dist/testing.d.ts +2 -2
  90. package/dist/testing.js +13 -13
  91. package/dist/testing.js.map +1 -1
  92. package/dist/tool-loop.d.ts +1 -1
  93. package/dist/{tool-server-Dqer2M4_.js → tool-server-XV4aJwoQ.js} +2 -2
  94. package/dist/tool-server-XV4aJwoQ.js.map +1 -0
  95. package/dist/top-snapshot-CbZE1JsU.js +502 -0
  96. package/dist/top-snapshot-CbZE1JsU.js.map +1 -0
  97. package/dist/tui/bin.js +711 -1
  98. package/dist/tui/bin.js.map +1 -1
  99. package/dist/tui/index.d.ts +2 -70
  100. package/dist/tui/index.js +3 -3
  101. package/dist/{types-zWfqDjeL.d.ts → types-Cwrea-bU.d.ts} +2 -17
  102. package/dist/{types-CrNWif8-.d.ts → types-DZ6L0Bv3.d.ts} +765 -2152
  103. package/dist/workspace-store/index.d.ts +1 -107
  104. package/dist/workspace-store/index.js +1 -415
  105. package/dist/workspace-store/index.js.map +1 -1
  106. package/dist/{workspace-streams-BZZds1Fw.d.ts → workspace-streams-BiS4ABah.d.ts} +3 -18
  107. package/package.json +1 -1
  108. package/skills/agent-graphs/references/authoring.md +3 -2
  109. package/dist/coder-yhVWbdWc.js +0 -40
  110. package/dist/coder-yhVWbdWc.js.map +0 -1
  111. package/dist/delegation-status-CF4D0NZ_.js +0 -358
  112. package/dist/delegation-status-CF4D0NZ_.js.map +0 -1
  113. package/dist/driver-control-acknowledgers-T2a1Ouay.js.map +0 -1
  114. package/dist/durable-file-B_eJr6Mb.js.map +0 -1
  115. package/dist/graph-CY0wH838.js.map +0 -1
  116. package/dist/improve-CWGBT13K.js.map +0 -1
  117. package/dist/integrations-6xttbPi9.d.ts +0 -190
  118. package/dist/integrations-dFi-ALk7.js +0 -132
  119. package/dist/integrations-dFi-ALk7.js.map +0 -1
  120. package/dist/kb-gate-C8z2juK8.d.ts +0 -80
  121. package/dist/kb-gate-DpaSwXVx.js +0 -80
  122. package/dist/kb-gate-DpaSwXVx.js.map +0 -1
  123. package/dist/loop-runner-bin-CFnrAHpl.d.ts +0 -164
  124. package/dist/loop-runner-bin-CdPlhy9g.js +0 -246
  125. package/dist/loop-runner-bin-CdPlhy9g.js.map +0 -1
  126. package/dist/memory-server-DXQ8IxGR.js +0 -234
  127. package/dist/memory-server-DXQ8IxGR.js.map +0 -1
  128. package/dist/openai-tools-DoQ32vpe.js +0 -44
  129. package/dist/openai-tools-DoQ32vpe.js.map +0 -1
  130. package/dist/openai-tools-zh2I_uD7.d.ts +0 -24
  131. package/dist/prepare-Bt0IouPq.js.map +0 -1
  132. package/dist/profile-Do-5xO_D.js.map +0 -1
  133. package/dist/profile-materialization-BnoEf1co.d.ts +0 -96
  134. package/dist/runtime-D37zRSs7.js.map +0 -1
  135. package/dist/sandbox-profile-compat-xSoVtdWw.js.map +0 -1
  136. package/dist/search-executor-DmgUm5p7.js.map +0 -1
  137. package/dist/server-DQHJszfk.js.map +0 -1
  138. package/dist/structural-rollout-DAvIE8mw.js.map +0 -1
  139. package/dist/substrate-B0TYNrXn.js.map +0 -1
  140. package/dist/supervise-WuPAwfPh.js.map +0 -1
  141. package/dist/supervisor-CPG1I9UN.js.map +0 -1
  142. package/dist/tool-server-Dqer2M4_.js.map +0 -1
  143. package/dist/top-app-C55Wa7uy.js +0 -1214
  144. package/dist/top-app-C55Wa7uy.js.map +0 -1
@@ -1,234 +0,0 @@
1
- import { m as ValidationError } from "./errors-DodWX-cb.js";
2
- import { r as createStdioToolServer } from "./tool-server-Dqer2M4_.js";
3
- import { appendFileSync, mkdirSync, readFileSync } from "node:fs";
4
- import { dirname } from "node:path";
5
- //#region src/mcp/memory-server.ts
6
- /**
7
- * Memory MCP server — the LIVE serving half of the `memory` profile surface
8
- * (Phase 5). A curated memory (lessons distilled from prior runs) is only
9
- * real if the DRIVEN agent can query it mid-task; this module serves a flat
10
- * store of `MemoryItem` rows as `memory_search` / `memory_get` tools over the
11
- * ONE in-repo stdio JSON-RPC core (`createStdioToolServer`), so the exact
12
- * wire protocol the same-host client (`connectStdioMcp` /
13
- * `materializeLocalMcp`, runtime/stdio-mcp-client.ts) speaks is guaranteed by
14
- * construction — serve and consume cannot drift.
15
- *
16
- * Retrieval is DETERMINISTIC lexical overlap (no vectors, no LLM): a lift
17
- * measured with this memory mounted is attributable to the lessons
18
- * themselves, never to retrieval-model noise. Every
19
- * `memory_search` can append one JSONL row to a retrieval log (`logPath`) —
20
- * the per-query record an off-policy retrieval estimator (agent-knowledge's
21
- * `RetrievalHoldout`) consumes. agent-knowledge is NOT a dependency of this
22
- * repo, so the log file is the flagged cross-package seam, not an import.
23
- *
24
- * Fail-loud discipline (mirrors `materializeLocalMcp`): an EMPTY memory is
25
- * never served — a profile without memory simply omits the artifact, and
26
- * silently serving zero rows would fake the with/without ablation.
27
- *
28
- * @experimental
29
- */
30
- /** Env var naming the durable row store file the memory bin loads (the
31
- * `memoryMcpServer` ↔ memory-bin contract). */
32
- const MEMORY_FILE_ENV = "AGENT_MEMORY_FILE";
33
- /** Env var carrying inline JSON `MemoryItem` rows (win over file rows on id). */
34
- const MEMORY_ITEMS_ENV = "AGENT_MEMORY_ITEMS";
35
- /** Env var naming the JSONL retrieval log (one row per `memory_search`). */
36
- const MEMORY_LOG_ENV = "AGENT_MEMORY_LOG";
37
- /** Env var overriding the served display name (default 'agent-memory'). */
38
- const MEMORY_NAME_ENV = "AGENT_MEMORY_NAME";
39
- /**
40
- * Build the memory MCP server: `memory_search` (lexical top-k over the rows)
41
- * and `memory_get` (one row by id) on the generic stdio JSON-RPC core.
42
- */
43
- function createMemoryToolServer(opts) {
44
- if (opts.items.length === 0) throw new ValidationError("createMemoryToolServer: refusing to serve an EMPTY memory — a profile without memory omits the artifact; serving zero rows would fake the with/without ablation");
45
- const byId = /* @__PURE__ */ new Map();
46
- for (const item of opts.items) {
47
- if (byId.has(item.id)) throw new ValidationError(`createMemoryToolServer: duplicate memory item id '${item.id}'`);
48
- byId.set(item.id, item);
49
- }
50
- const items = [...byId.values()];
51
- const defaultK = opts.defaultK ?? 5;
52
- const logPath = opts.logPath;
53
- if (logPath) mkdirSync(dirname(logPath), { recursive: true });
54
- const search = {
55
- name: "memory_search",
56
- description: "Search the agent memory of lessons learned from prior runs. Give what you are about to do or the problem you face; returns the top-k lessons ranked by relevance. Consult it BEFORE repeating work a prior run already learned from.",
57
- inputSchema: {
58
- type: "object",
59
- properties: {
60
- query: {
61
- type: "string",
62
- description: "The task/problem at hand — matched against lesson text and tags."
63
- },
64
- k: {
65
- type: "number",
66
- description: `Max results (default ${defaultK}).`
67
- },
68
- tags: {
69
- type: "array",
70
- items: { type: "string" },
71
- description: "Only return items carrying at least one of these tags."
72
- }
73
- },
74
- required: ["query"]
75
- },
76
- handler: async (raw) => {
77
- const args = raw ?? {};
78
- if (typeof args.query !== "string" || args.query.trim().length === 0) throw new TypeError("memory_search: query must be a non-empty string");
79
- const k = args.k === void 0 ? defaultK : Math.floor(Number(args.k));
80
- if (!Number.isFinite(k) || k < 1) throw new TypeError("memory_search: k must be a positive integer");
81
- let tagFilter;
82
- if (args.tags !== void 0) {
83
- if (!Array.isArray(args.tags) || args.tags.some((t) => typeof t !== "string")) throw new TypeError("memory_search: tags must be an array of strings");
84
- tagFilter = args.tags;
85
- }
86
- const queryTokens = tokenize(args.query);
87
- const results = (tagFilter ? items.filter((i) => (i.tags ?? []).some((t) => tagFilter.includes(t))) : items).map((item) => ({
88
- item,
89
- score: scoreItem(queryTokens, item)
90
- })).filter((r) => r.score > 0).sort((a, b) => b.score - a.score).slice(0, k).map(({ item, score }) => ({
91
- id: item.id,
92
- text: item.text,
93
- score: Number(score.toFixed(4)),
94
- ...item.tags ? { tags: item.tags } : {},
95
- ...item.source ? { source: item.source } : {}
96
- }));
97
- if (logPath) appendFileSync(logPath, `${JSON.stringify({
98
- ts: (/* @__PURE__ */ new Date()).toISOString(),
99
- query: args.query,
100
- k,
101
- returned: results.map((r) => ({
102
- id: r.id,
103
- score: r.score
104
- }))
105
- })}\n`);
106
- return {
107
- query: args.query,
108
- results
109
- };
110
- }
111
- };
112
- return createStdioToolServer({
113
- serverName: opts.serverName ?? "agent-memory",
114
- serverVersion: opts.serverVersion ?? "0",
115
- tools: [search, {
116
- name: "memory_get",
117
- description: "Fetch one memory item verbatim by its id (ids come from memory_search results).",
118
- inputSchema: {
119
- type: "object",
120
- properties: { id: {
121
- type: "string",
122
- description: "The memory item id."
123
- } },
124
- required: ["id"]
125
- },
126
- handler: async (raw) => {
127
- const args = raw ?? {};
128
- if (typeof args.id !== "string" || args.id.trim().length === 0) throw new TypeError("memory_get: id must be a non-empty string");
129
- const item = byId.get(args.id);
130
- if (!item) throw new Error(`memory_get: no memory item with id '${args.id}'`);
131
- return item;
132
- }
133
- }]
134
- });
135
- }
136
- /** Coerce an untrusted JSON array into validated `MemoryItem` rows. */
137
- function parseMemoryItems(value, source) {
138
- if (!Array.isArray(value)) throw new ValidationError(`${source}: expected a JSON array of memory items`);
139
- return value.map((row, i) => coerceMemoryItem(row, `${source}[${i}]`));
140
- }
141
- /** Read a memory store file: a JSON array, or JSONL (one `MemoryItem` per line). */
142
- function readMemoryItemsFile(path) {
143
- let raw;
144
- try {
145
- raw = readFileSync(path, "utf8");
146
- } catch (err) {
147
- throw new ValidationError(`readMemoryItemsFile: cannot read '${path}': ${err instanceof Error ? err.message : String(err)}`);
148
- }
149
- const trimmed = raw.trim();
150
- if (trimmed.length === 0) return [];
151
- if (trimmed.startsWith("[")) {
152
- let parsed;
153
- try {
154
- parsed = JSON.parse(trimmed);
155
- } catch (err) {
156
- throw new ValidationError(`readMemoryItemsFile: '${path}' is not valid JSON: ${err.message}`);
157
- }
158
- return parseMemoryItems(parsed, path);
159
- }
160
- return trimmed.split("\n").map((line) => line.trim()).filter((line) => line.length > 0).map((line, i) => {
161
- let parsed;
162
- try {
163
- parsed = JSON.parse(line);
164
- } catch (err) {
165
- throw new ValidationError(`readMemoryItemsFile: '${path}' line ${i + 1} is not valid JSON: ${err.message}`);
166
- }
167
- return coerceMemoryItem(parsed, `${path}:${i + 1}`);
168
- });
169
- }
170
- /**
171
- * Resolve the bin's memory from `AGENT_MEMORY_FILE` (durable store) and/or
172
- * `AGENT_MEMORY_ITEMS` (inline JSON rows; wins on id collision). Zero rows is
173
- * a boot FAILURE, matching the fail-closed materialization discipline.
174
- */
175
- function resolveMemoryFromEnv(env) {
176
- const filePath = env[MEMORY_FILE_ENV];
177
- const inlineRaw = env[MEMORY_ITEMS_ENV];
178
- const fromFile = filePath ? readMemoryItemsFile(filePath) : [];
179
- let inline = [];
180
- if (inlineRaw) {
181
- let parsed;
182
- try {
183
- parsed = JSON.parse(inlineRaw);
184
- } catch (err) {
185
- throw new ValidationError(`${MEMORY_ITEMS_ENV} is not valid JSON: ${err instanceof Error ? err.message : String(err)}`);
186
- }
187
- inline = parseMemoryItems(parsed, MEMORY_ITEMS_ENV);
188
- }
189
- const byId = /* @__PURE__ */ new Map();
190
- for (const item of fromFile) byId.set(item.id, item);
191
- for (const item of inline) byId.set(item.id, item);
192
- if (byId.size === 0) throw new ValidationError(`memory bin: no memory items — set ${MEMORY_FILE_ENV} and/or ${MEMORY_ITEMS_ENV}; an EMPTY memory must never be served (a profile without memory omits the artifact)`);
193
- const serverName = env[MEMORY_NAME_ENV];
194
- const logPath = env[MEMORY_LOG_ENV];
195
- return {
196
- items: [...byId.values()],
197
- ...serverName ? { serverName } : {},
198
- ...logPath ? { logPath } : {}
199
- };
200
- }
201
- function coerceMemoryItem(row, at) {
202
- if (!row || typeof row !== "object" || Array.isArray(row)) throw new ValidationError(`${at}: memory item must be an object`);
203
- const r = row;
204
- if (typeof r.id !== "string" || r.id.trim().length === 0) throw new ValidationError(`${at}: 'id' must be a non-empty string`);
205
- if (typeof r.text !== "string" || r.text.trim().length === 0) throw new ValidationError(`${at}: 'text' must be a non-empty string`);
206
- let tags;
207
- if (r.tags !== void 0) {
208
- if (!Array.isArray(r.tags) || r.tags.some((t) => typeof t !== "string")) throw new ValidationError(`${at}: 'tags' must be an array of strings`);
209
- tags = r.tags;
210
- }
211
- if (r.source !== void 0 && typeof r.source !== "string") throw new ValidationError(`${at}: 'source' must be a string`);
212
- return {
213
- id: r.id,
214
- text: r.text,
215
- ...tags ? { tags } : {},
216
- ...typeof r.source === "string" ? { source: r.source } : {}
217
- };
218
- }
219
- /** Unique lowercase alphanumeric tokens of length >= 2. */
220
- function tokenize(text) {
221
- return [...new Set(text.toLowerCase().split(/[^a-z0-9]+/).filter((t) => t.length >= 2))];
222
- }
223
- /** Fraction of query tokens present in the item's text + tags (0..1). */
224
- function scoreItem(queryTokens, item) {
225
- if (queryTokens.length === 0) return 0;
226
- const hay = new Set(tokenize(`${item.text} ${(item.tags ?? []).join(" ")}`));
227
- let hit = 0;
228
- for (const t of queryTokens) if (hay.has(t)) hit += 1;
229
- return hit / queryTokens.length;
230
- }
231
- //#endregion
232
- export { createMemoryToolServer as a, resolveMemoryFromEnv as c, MEMORY_NAME_ENV as i, MEMORY_ITEMS_ENV as n, parseMemoryItems as o, MEMORY_LOG_ENV as r, readMemoryItemsFile as s, MEMORY_FILE_ENV as t };
233
-
234
- //# sourceMappingURL=memory-server-DXQ8IxGR.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"memory-server-DXQ8IxGR.js","names":[],"sources":["../src/mcp/memory-server.ts"],"sourcesContent":["/**\n * Memory MCP server — the LIVE serving half of the `memory` profile surface\n * (Phase 5). A curated memory (lessons distilled from prior runs) is only\n * real if the DRIVEN agent can query it mid-task; this module serves a flat\n * store of `MemoryItem` rows as `memory_search` / `memory_get` tools over the\n * ONE in-repo stdio JSON-RPC core (`createStdioToolServer`), so the exact\n * wire protocol the same-host client (`connectStdioMcp` /\n * `materializeLocalMcp`, runtime/stdio-mcp-client.ts) speaks is guaranteed by\n * construction — serve and consume cannot drift.\n *\n * Retrieval is DETERMINISTIC lexical overlap (no vectors, no LLM): a lift\n * measured with this memory mounted is attributable to the lessons\n * themselves, never to retrieval-model noise. Every\n * `memory_search` can append one JSONL row to a retrieval log (`logPath`) —\n * the per-query record an off-policy retrieval estimator (agent-knowledge's\n * `RetrievalHoldout`) consumes. agent-knowledge is NOT a dependency of this\n * repo, so the log file is the flagged cross-package seam, not an import.\n *\n * Fail-loud discipline (mirrors `materializeLocalMcp`): an EMPTY memory is\n * never served — a profile without memory simply omits the artifact, and\n * silently serving zero rows would fake the with/without ablation.\n *\n * @experimental\n */\n\nimport { appendFileSync, mkdirSync, readFileSync } from 'node:fs'\nimport { dirname } from 'node:path'\nimport type { AgentProfileMcpServer } from '@tangle-network/agent-interface'\nimport { ValidationError } from '../errors'\nimport { createStdioToolServer, type McpToolDescriptor, type StdioToolServer } from './tool-server'\n\n/** One row of agent memory: a crisp lesson/fact with provenance. */\nexport interface MemoryItem {\n /** Stable id (content-hash by convention; see `memoryArtifactFromLessons`). */\n id: string\n /** The lesson itself — one imperative or observation the agent should recall. */\n text: string\n /** Optional retrieval tags, matched by `memory_search` alongside the text. */\n tags?: string[]\n /** Provenance: the finding / trace / curation pass this row came from. */\n source?: string\n}\n\n/**\n * The `memory` artifact payload — HOW a profile's memory is stored and served:\n *\n * - `store: 'file'` — served by the in-repo memory bin\n * (`agent-runtime-memory-mcp`, src/mcp/memory-bin.ts): rows load from\n * `path` (a JSON array or JSONL file of `MemoryItem`) and/or the inline\n * `items` seed (inline wins on id collision). At least one of\n * `path`/`items` is required.\n * - `store: 'mcp'` — an EXTERNAL, already-runnable MCP server that exposes\n * the memory tools itself; `server` is required and mounts verbatim.\n *\n * `logPath` makes the served memory append one JSONL row per `memory_search`\n * — the retrieval log a holdout estimator reads (see module doc).\n */\nexport interface AgentMemorySpec {\n store: 'file' | 'mcp'\n /** `store:'file'` — host path to the durable row store (JSON array or JSONL). */\n path?: string\n /** Inline seed rows, served alongside (and winning over) `path` rows. */\n items?: MemoryItem[]\n /** `store:'mcp'` — the external server that already serves memory tools. */\n server?: AgentProfileMcpServer\n /** JSONL retrieval log: one row per `memory_search` (ts, query, k, returned). */\n logPath?: string\n}\n\n/** Env var naming the durable row store file the memory bin loads (the\n * `memoryMcpServer` ↔ memory-bin contract). */\nexport const MEMORY_FILE_ENV = 'AGENT_MEMORY_FILE'\n/** Env var carrying inline JSON `MemoryItem` rows (win over file rows on id). */\nexport const MEMORY_ITEMS_ENV = 'AGENT_MEMORY_ITEMS'\n/** Env var naming the JSONL retrieval log (one row per `memory_search`). */\nexport const MEMORY_LOG_ENV = 'AGENT_MEMORY_LOG'\n/** Env var overriding the served display name (default 'agent-memory'). */\nexport const MEMORY_NAME_ENV = 'AGENT_MEMORY_NAME'\n\nexport interface CreateMemoryToolServerOptions {\n /** The rows to serve. MUST be non-empty (an empty memory is never served). */\n items: readonly MemoryItem[]\n /** Server display name surfaced via `initialize`. Default 'agent-memory'. */\n serverName?: string\n /** Server version surfaced via `initialize`. Default '0'. */\n serverVersion?: string\n /** Default result count for `memory_search`. Default 5. */\n defaultK?: number\n /** Append one JSONL row per `memory_search` (the retrieval-holdout seam). */\n logPath?: string\n}\n\n/**\n * Build the memory MCP server: `memory_search` (lexical top-k over the rows)\n * and `memory_get` (one row by id) on the generic stdio JSON-RPC core.\n */\nexport function createMemoryToolServer(opts: CreateMemoryToolServerOptions): StdioToolServer {\n if (opts.items.length === 0) {\n throw new ValidationError(\n 'createMemoryToolServer: refusing to serve an EMPTY memory — a profile without memory omits the artifact; serving zero rows would fake the with/without ablation',\n )\n }\n const byId = new Map<string, MemoryItem>()\n for (const item of opts.items) {\n if (byId.has(item.id)) {\n throw new ValidationError(`createMemoryToolServer: duplicate memory item id '${item.id}'`)\n }\n byId.set(item.id, item)\n }\n const items = [...byId.values()]\n const defaultK = opts.defaultK ?? 5\n const logPath = opts.logPath\n if (logPath) mkdirSync(dirname(logPath), { recursive: true })\n\n const search: McpToolDescriptor = {\n name: 'memory_search',\n description:\n 'Search the agent memory of lessons learned from prior runs. Give what you are about to do or the problem you face; returns the top-k lessons ranked by relevance. Consult it BEFORE repeating work a prior run already learned from.',\n inputSchema: {\n type: 'object',\n properties: {\n query: {\n type: 'string',\n description: 'The task/problem at hand — matched against lesson text and tags.',\n },\n k: { type: 'number', description: `Max results (default ${defaultK}).` },\n tags: {\n type: 'array',\n items: { type: 'string' },\n description: 'Only return items carrying at least one of these tags.',\n },\n },\n required: ['query'],\n },\n handler: async (raw) => {\n const args = (raw ?? {}) as { query?: unknown; k?: unknown; tags?: unknown }\n if (typeof args.query !== 'string' || args.query.trim().length === 0) {\n throw new TypeError('memory_search: query must be a non-empty string')\n }\n const k = args.k === undefined ? defaultK : Math.floor(Number(args.k))\n if (!Number.isFinite(k) || k < 1) {\n throw new TypeError('memory_search: k must be a positive integer')\n }\n let tagFilter: string[] | undefined\n if (args.tags !== undefined) {\n if (!Array.isArray(args.tags) || args.tags.some((t) => typeof t !== 'string')) {\n throw new TypeError('memory_search: tags must be an array of strings')\n }\n tagFilter = args.tags as string[]\n }\n const queryTokens = tokenize(args.query)\n const pool = tagFilter\n ? items.filter((i) => (i.tags ?? []).some((t) => tagFilter.includes(t)))\n : items\n const results = pool\n .map((item) => ({ item, score: scoreItem(queryTokens, item) }))\n .filter((r) => r.score > 0)\n // Highest score first; stable on ties (curation order is the tiebreak).\n .sort((a, b) => b.score - a.score)\n .slice(0, k)\n .map(({ item, score }) => ({\n id: item.id,\n text: item.text,\n score: Number(score.toFixed(4)),\n ...(item.tags ? { tags: item.tags } : {}),\n ...(item.source ? { source: item.source } : {}),\n }))\n if (logPath) {\n // The retrieval log: what was asked, what came back, at what rank —\n // exactly the per-query record an off-policy estimator needs.\n appendFileSync(\n logPath,\n `${JSON.stringify({\n ts: new Date().toISOString(),\n query: args.query,\n k,\n returned: results.map((r) => ({ id: r.id, score: r.score })),\n })}\\n`,\n )\n }\n return { query: args.query, results }\n },\n }\n\n const get: McpToolDescriptor = {\n name: 'memory_get',\n description: 'Fetch one memory item verbatim by its id (ids come from memory_search results).',\n inputSchema: {\n type: 'object',\n properties: { id: { type: 'string', description: 'The memory item id.' } },\n required: ['id'],\n },\n handler: async (raw) => {\n const args = (raw ?? {}) as { id?: unknown }\n if (typeof args.id !== 'string' || args.id.trim().length === 0) {\n throw new TypeError('memory_get: id must be a non-empty string')\n }\n const item = byId.get(args.id)\n if (!item) throw new Error(`memory_get: no memory item with id '${args.id}'`)\n return item\n },\n }\n\n return createStdioToolServer({\n serverName: opts.serverName ?? 'agent-memory',\n serverVersion: opts.serverVersion ?? '0',\n tools: [search, get],\n })\n}\n\n/** Coerce an untrusted JSON array into validated `MemoryItem` rows. */\nexport function parseMemoryItems(value: unknown, source: string): MemoryItem[] {\n if (!Array.isArray(value)) {\n throw new ValidationError(`${source}: expected a JSON array of memory items`)\n }\n return value.map((row, i) => coerceMemoryItem(row, `${source}[${i}]`))\n}\n\n/** Read a memory store file: a JSON array, or JSONL (one `MemoryItem` per line). */\nexport function readMemoryItemsFile(path: string): MemoryItem[] {\n let raw: string\n try {\n raw = readFileSync(path, 'utf8')\n } catch (err) {\n throw new ValidationError(\n `readMemoryItemsFile: cannot read '${path}': ${err instanceof Error ? err.message : String(err)}`,\n )\n }\n const trimmed = raw.trim()\n if (trimmed.length === 0) return []\n if (trimmed.startsWith('[')) {\n let parsed: unknown\n try {\n parsed = JSON.parse(trimmed)\n } catch (err) {\n throw new ValidationError(\n `readMemoryItemsFile: '${path}' is not valid JSON: ${(err as Error).message}`,\n )\n }\n return parseMemoryItems(parsed, path)\n }\n return trimmed\n .split('\\n')\n .map((line) => line.trim())\n .filter((line) => line.length > 0)\n .map((line, i) => {\n let parsed: unknown\n try {\n parsed = JSON.parse(line)\n } catch (err) {\n throw new ValidationError(\n `readMemoryItemsFile: '${path}' line ${i + 1} is not valid JSON: ${(err as Error).message}`,\n )\n }\n return coerceMemoryItem(parsed, `${path}:${i + 1}`)\n })\n}\n\n/** What the memory bin resolved from its environment. */\nexport interface ResolvedMemoryEnv {\n items: MemoryItem[]\n serverName?: string\n logPath?: string\n}\n\n/**\n * Resolve the bin's memory from `AGENT_MEMORY_FILE` (durable store) and/or\n * `AGENT_MEMORY_ITEMS` (inline JSON rows; wins on id collision). Zero rows is\n * a boot FAILURE, matching the fail-closed materialization discipline.\n */\nexport function resolveMemoryFromEnv(env: Record<string, string | undefined>): ResolvedMemoryEnv {\n const filePath = env[MEMORY_FILE_ENV]\n const inlineRaw = env[MEMORY_ITEMS_ENV]\n const fromFile = filePath ? readMemoryItemsFile(filePath) : []\n let inline: MemoryItem[] = []\n if (inlineRaw) {\n let parsed: unknown\n try {\n parsed = JSON.parse(inlineRaw)\n } catch (err) {\n throw new ValidationError(\n `${MEMORY_ITEMS_ENV} is not valid JSON: ${err instanceof Error ? err.message : String(err)}`,\n )\n }\n inline = parseMemoryItems(parsed, MEMORY_ITEMS_ENV)\n }\n const byId = new Map<string, MemoryItem>()\n for (const item of fromFile) byId.set(item.id, item)\n for (const item of inline) byId.set(item.id, item)\n if (byId.size === 0) {\n throw new ValidationError(\n `memory bin: no memory items — set ${MEMORY_FILE_ENV} and/or ${MEMORY_ITEMS_ENV}; an EMPTY memory must never be served (a profile without memory omits the artifact)`,\n )\n }\n const serverName = env[MEMORY_NAME_ENV]\n const logPath = env[MEMORY_LOG_ENV]\n return {\n items: [...byId.values()],\n ...(serverName ? { serverName } : {}),\n ...(logPath ? { logPath } : {}),\n }\n}\n\nfunction coerceMemoryItem(row: unknown, at: string): MemoryItem {\n if (!row || typeof row !== 'object' || Array.isArray(row)) {\n throw new ValidationError(`${at}: memory item must be an object`)\n }\n const r = row as Record<string, unknown>\n if (typeof r.id !== 'string' || r.id.trim().length === 0) {\n throw new ValidationError(`${at}: 'id' must be a non-empty string`)\n }\n if (typeof r.text !== 'string' || r.text.trim().length === 0) {\n throw new ValidationError(`${at}: 'text' must be a non-empty string`)\n }\n let tags: string[] | undefined\n if (r.tags !== undefined) {\n if (!Array.isArray(r.tags) || r.tags.some((t) => typeof t !== 'string')) {\n throw new ValidationError(`${at}: 'tags' must be an array of strings`)\n }\n tags = r.tags as string[]\n }\n if (r.source !== undefined && typeof r.source !== 'string') {\n throw new ValidationError(`${at}: 'source' must be a string`)\n }\n return {\n id: r.id,\n text: r.text,\n ...(tags ? { tags } : {}),\n ...(typeof r.source === 'string' ? { source: r.source } : {}),\n }\n}\n\n/** Unique lowercase alphanumeric tokens of length >= 2. */\nfunction tokenize(text: string): string[] {\n return [\n ...new Set(\n text\n .toLowerCase()\n .split(/[^a-z0-9]+/)\n .filter((t) => t.length >= 2),\n ),\n ]\n}\n\n/** Fraction of query tokens present in the item's text + tags (0..1). */\nfunction scoreItem(queryTokens: readonly string[], item: MemoryItem): number {\n if (queryTokens.length === 0) return 0\n const hay = new Set(tokenize(`${item.text} ${(item.tags ?? []).join(' ')}`))\n let hit = 0\n for (const t of queryTokens) if (hay.has(t)) hit += 1\n return hit / queryTokens.length\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuEA,MAAa,kBAAkB;;AAE/B,MAAa,mBAAmB;;AAEhC,MAAa,iBAAiB;;AAE9B,MAAa,kBAAkB;;;;;AAmB/B,SAAgB,uBAAuB,MAAsD;CAC3F,IAAI,KAAK,MAAM,WAAW,GACxB,MAAM,IAAI,gBACR,iKACF;CAEF,MAAM,uBAAO,IAAI,IAAwB;CACzC,KAAK,MAAM,QAAQ,KAAK,OAAO;EAC7B,IAAI,KAAK,IAAI,KAAK,EAAE,GAClB,MAAM,IAAI,gBAAgB,qDAAqD,KAAK,GAAG,EAAE;EAE3F,KAAK,IAAI,KAAK,IAAI,IAAI;CACxB;CACA,MAAM,QAAQ,CAAC,GAAG,KAAK,OAAO,CAAC;CAC/B,MAAM,WAAW,KAAK,YAAY;CAClC,MAAM,UAAU,KAAK;CACrB,IAAI,SAAS,UAAU,QAAQ,OAAO,GAAG,EAAE,WAAW,KAAK,CAAC;CAE5D,MAAM,SAA4B;EAChC,MAAM;EACN,aACE;EACF,aAAa;GACX,MAAM;GACN,YAAY;IACV,OAAO;KACL,MAAM;KACN,aAAa;IACf;IACA,GAAG;KAAE,MAAM;KAAU,aAAa,wBAAwB,SAAS;IAAI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CAAC,CACb,MAAM,YAAY,CAAC,CACnB,QAAQ,MAAM,EAAE,UAAU,CAAC,CAChC,CACF;AACF;;AAGA,SAAS,UAAU,aAAgC,MAA0B;CAC3E,IAAI,YAAY,WAAW,GAAG,OAAO;CACrC,MAAM,MAAM,IAAI,IAAI,SAAS,GAAG,KAAK,KAAK,IAAI,KAAK,QAAQ,CAAC,EAAA,CAAG,KAAK,GAAG,GAAG,CAAC;CAC3E,IAAI,MAAM;CACV,KAAK,MAAM,KAAK,aAAa,IAAI,IAAI,IAAI,CAAC,GAAG,OAAO;CACpD,OAAO,MAAM,YAAY;AAC3B"}
@@ -1,44 +0,0 @@
1
- import { c as DELEGATION_HISTORY_TOOL_NAME, f as DELEGATE_FEEDBACK_DESCRIPTION, m as DELEGATE_FEEDBACK_TOOL_NAME, n as DELEGATION_STATUS_INPUT_SCHEMA, o as DELEGATION_HISTORY_DESCRIPTION, p as DELEGATE_FEEDBACK_INPUT_SCHEMA, r as DELEGATION_STATUS_TOOL_NAME, s as DELEGATION_HISTORY_INPUT_SCHEMA, t as DELEGATION_STATUS_DESCRIPTION } from "./delegation-status-CF4D0NZ_.js";
2
- //#region src/mcp/openai-tools.ts
3
- function buildTool(name, description, parameters) {
4
- return {
5
- type: "function",
6
- function: {
7
- name,
8
- description,
9
- parameters: { ...parameters }
10
- }
11
- };
12
- }
13
- /**
14
- *
15
- * Returns the queue-bound delegation tools projected into OpenAI Chat
16
- * Completions `tools[]` shape. The order is stable: `delegate_feedback`,
17
- * `delegation_status`, `delegation_history`.
18
- *
19
- * @experimental
20
- */
21
- function mcpToolsForRuntimeMcp() {
22
- return [
23
- buildTool(DELEGATE_FEEDBACK_TOOL_NAME, DELEGATE_FEEDBACK_DESCRIPTION, DELEGATE_FEEDBACK_INPUT_SCHEMA),
24
- buildTool(DELEGATION_STATUS_TOOL_NAME, DELEGATION_STATUS_DESCRIPTION, DELEGATION_STATUS_INPUT_SCHEMA),
25
- buildTool(DELEGATION_HISTORY_TOOL_NAME, DELEGATION_HISTORY_DESCRIPTION, DELEGATION_HISTORY_INPUT_SCHEMA)
26
- ];
27
- }
28
- /**
29
- *
30
- * Subset filter — return only the projected tools whose `function.name`
31
- * appears in `names`. Useful for curated mounts (e.g. only the queue-bound
32
- * delegation tools, omitting `delegate_feedback`). Unknown names are
33
- * silently ignored; pass an empty array to get an empty result.
34
- *
35
- * @experimental
36
- */
37
- function mcpToolsForRuntimeMcpSubset(names) {
38
- const allowed = new Set(names);
39
- return mcpToolsForRuntimeMcp().filter((tool) => allowed.has(tool.function.name));
40
- }
41
- //#endregion
42
- export { mcpToolsForRuntimeMcpSubset as n, mcpToolsForRuntimeMcp as t };
43
-
44
- //# sourceMappingURL=openai-tools-DoQ32vpe.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"openai-tools-DoQ32vpe.js","names":[],"sources":["../src/mcp/openai-tools.ts"],"sourcesContent":["/**\n *\n * OpenAI Chat Completions `tools[]` projection of the queue-bound agent-runtime\n * MCP delegation tools.\n *\n * Use when a caller-owned OpenAI-compatible transport needs the model to call\n * `delegate_feedback`, `delegation_status`, and `delegation_history`. Execution\n * is the caller's responsibility (typically the parent sandbox runtime's MCP\n * mount); Runtime's profile-bound model path materializes profile tools through\n * its executor instead.\n *\n * Sandbox-SDK callers do NOT need this helper: the sandbox runtime mounts\n * MCP servers natively and the in-sandbox harness discovers tools via the\n * runtime, not via an OpenAI tools array.\n *\n * Tool name + description + JSON-schema are pulled from the canonical\n * `DELEGATE_*` constants exported by `./tools/*` so the projection cannot\n * drift from the server's own validators.\n *\n * @experimental\n */\n\nimport type { OpenAIChatTool } from '../types'\nimport {\n DELEGATE_FEEDBACK_DESCRIPTION,\n DELEGATE_FEEDBACK_INPUT_SCHEMA,\n DELEGATE_FEEDBACK_TOOL_NAME,\n} from './tools/delegate-feedback'\nimport {\n DELEGATION_HISTORY_DESCRIPTION,\n DELEGATION_HISTORY_INPUT_SCHEMA,\n DELEGATION_HISTORY_TOOL_NAME,\n} from './tools/delegation-history'\nimport {\n DELEGATION_STATUS_DESCRIPTION,\n DELEGATION_STATUS_INPUT_SCHEMA,\n DELEGATION_STATUS_TOOL_NAME,\n} from './tools/delegation-status'\n\nfunction buildTool(\n name: string,\n description: string,\n parameters: Readonly<Record<string, unknown>>,\n): OpenAIChatTool {\n // `parameters` arrives as a deeply-readonly `as const` literal. The\n // OpenAI-compatible transports JSON-serialize the body, so a shallow copy\n // into a plain object is sufficient and shields callers that mutate\n // the returned descriptor from corrupting the source constant.\n return {\n type: 'function',\n function: { name, description, parameters: { ...parameters } },\n }\n}\n\n/**\n *\n * Returns the queue-bound delegation tools projected into OpenAI Chat\n * Completions `tools[]` shape. The order is stable: `delegate_feedback`,\n * `delegation_status`, `delegation_history`.\n *\n * @experimental\n */\nexport function mcpToolsForRuntimeMcp(): OpenAIChatTool[] {\n return [\n buildTool(\n DELEGATE_FEEDBACK_TOOL_NAME,\n DELEGATE_FEEDBACK_DESCRIPTION,\n DELEGATE_FEEDBACK_INPUT_SCHEMA as Readonly<Record<string, unknown>>,\n ),\n buildTool(\n DELEGATION_STATUS_TOOL_NAME,\n DELEGATION_STATUS_DESCRIPTION,\n DELEGATION_STATUS_INPUT_SCHEMA as Readonly<Record<string, unknown>>,\n ),\n buildTool(\n DELEGATION_HISTORY_TOOL_NAME,\n DELEGATION_HISTORY_DESCRIPTION,\n DELEGATION_HISTORY_INPUT_SCHEMA as Readonly<Record<string, unknown>>,\n ),\n ]\n}\n\n/**\n *\n * Subset filter — return only the projected tools whose `function.name`\n * appears in `names`. Useful for curated mounts (e.g. only the queue-bound\n * delegation tools, omitting `delegate_feedback`). Unknown names are\n * silently ignored; pass an empty array to get an empty result.\n *\n * @experimental\n */\nexport function mcpToolsForRuntimeMcpSubset(names: ReadonlyArray<string>): OpenAIChatTool[] {\n const allowed = new Set(names)\n return mcpToolsForRuntimeMcp().filter((tool) => allowed.has(tool.function.name))\n}\n"],"mappings":";;AAuCA,SAAS,UACP,MACA,aACA,YACgB;CAKhB,OAAO;EACL,MAAM;EACN,UAAU;GAAE;GAAM;GAAa,YAAY,EAAE,GAAG,WAAW;EAAE;CAC/D;AACF;;;;;;;;;AAUA,SAAgB,wBAA0C;CACxD,OAAO;EACL,UACE,6BACA,+BACA,8BACF;EACA,UACE,6BACA,+BACA,8BACF;EACA,UACE,8BACA,gCACA,+BACF;CACF;AACF;;;;;;;;;;AAWA,SAAgB,4BAA4B,OAAgD;CAC1F,MAAM,UAAU,IAAI,IAAI,KAAK;CAC7B,OAAO,sBAAsB,CAAC,CAAC,QAAQ,SAAS,QAAQ,IAAI,KAAK,SAAS,IAAI,CAAC;AACjF"}
@@ -1,24 +0,0 @@
1
- import { h as OpenAIChatTool } from "./types-CrNWif8-.js";
2
- //#region src/mcp/openai-tools.d.ts
3
- /**
4
- *
5
- * Returns the queue-bound delegation tools projected into OpenAI Chat
6
- * Completions `tools[]` shape. The order is stable: `delegate_feedback`,
7
- * `delegation_status`, `delegation_history`.
8
- *
9
- * @experimental
10
- */
11
- declare function mcpToolsForRuntimeMcp(): OpenAIChatTool[];
12
- /**
13
- *
14
- * Subset filter — return only the projected tools whose `function.name`
15
- * appears in `names`. Useful for curated mounts (e.g. only the queue-bound
16
- * delegation tools, omitting `delegate_feedback`). Unknown names are
17
- * silently ignored; pass an empty array to get an empty result.
18
- *
19
- * @experimental
20
- */
21
- declare function mcpToolsForRuntimeMcpSubset(names: ReadonlyArray<string>): OpenAIChatTool[];
22
- //#endregion
23
- export { mcpToolsForRuntimeMcpSubset as n, mcpToolsForRuntimeMcp as t };
24
- //# sourceMappingURL=openai-tools-zh2I_uD7.d.ts.map