@rotifer/playground 0.31.0 → 0.33.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.
- package/CHANGELOG.md +40 -0
- package/README.md +2 -2
- package/README.zh.md +2 -2
- package/dist/cloud/client.d.ts.map +1 -1
- package/dist/cloud/client.js +9 -0
- package/dist/cloud/client.js.map +1 -1
- package/dist/cloud/types.d.ts +7 -0
- package/dist/cloud/types.d.ts.map +1 -1
- package/dist/cloud/types.js.map +1 -1
- package/dist/commands/agent-create.d.ts +11 -0
- package/dist/commands/agent-create.d.ts.map +1 -1
- package/dist/commands/agent-create.js +50 -1
- package/dist/commands/agent-create.js.map +1 -1
- package/dist/commands/agent-memory.d.ts +64 -0
- package/dist/commands/agent-memory.d.ts.map +1 -0
- package/dist/commands/agent-memory.js +235 -0
- package/dist/commands/agent-memory.js.map +1 -0
- package/dist/commands/agent-run.d.ts.map +1 -1
- package/dist/commands/agent-run.js +84 -26
- package/dist/commands/agent-run.js.map +1 -1
- package/dist/commands/arena-submit.d.ts.map +1 -1
- package/dist/commands/arena-submit.js +34 -36
- package/dist/commands/arena-submit.js.map +1 -1
- package/dist/commands/compile.d.ts.map +1 -1
- package/dist/commands/compile.js +32 -6
- package/dist/commands/compile.js.map +1 -1
- package/dist/commands/genome-format.d.ts +5 -1
- package/dist/commands/genome-format.d.ts.map +1 -1
- package/dist/commands/genome-format.js +5 -1
- package/dist/commands/genome-format.js.map +1 -1
- package/dist/commands/hello.d.ts.map +1 -1
- package/dist/commands/hello.js +15 -2
- package/dist/commands/hello.js.map +1 -1
- package/dist/commands/run.d.ts.map +1 -1
- package/dist/commands/run.js +59 -4
- package/dist/commands/run.js.map +1 -1
- package/dist/commands/test.d.ts.map +1 -1
- package/dist/commands/test.js +78 -23
- package/dist/commands/test.js.map +1 -1
- package/dist/commands/wrap.d.ts.map +1 -1
- package/dist/commands/wrap.js +28 -70
- package/dist/commands/wrap.js.map +1 -1
- package/dist/index.js +47 -1
- package/dist/index.js.map +1 -1
- package/dist/memory/access.d.ts +53 -0
- package/dist/memory/access.d.ts.map +1 -0
- package/dist/memory/access.js +111 -0
- package/dist/memory/access.js.map +1 -0
- package/dist/memory/audit.d.ts +26 -0
- package/dist/memory/audit.d.ts.map +1 -0
- package/dist/memory/audit.js +30 -0
- package/dist/memory/audit.js.map +1 -0
- package/dist/memory/backend.d.ts +141 -0
- package/dist/memory/backend.d.ts.map +1 -0
- package/dist/memory/backend.js +536 -0
- package/dist/memory/backend.js.map +1 -0
- package/dist/memory/codec.d.ts +34 -0
- package/dist/memory/codec.d.ts.map +1 -0
- package/dist/memory/codec.js +184 -0
- package/dist/memory/codec.js.map +1 -0
- package/dist/memory/data-policy.d.ts +39 -0
- package/dist/memory/data-policy.d.ts.map +1 -0
- package/dist/memory/data-policy.js +42 -0
- package/dist/memory/data-policy.js.map +1 -0
- package/dist/memory/host.d.ts +119 -0
- package/dist/memory/host.d.ts.map +1 -0
- package/dist/memory/host.js +226 -0
- package/dist/memory/host.js.map +1 -0
- package/dist/memory/index.d.ts +37 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +64 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/telemetry.d.ts +35 -0
- package/dist/memory/telemetry.d.ts.map +1 -0
- package/dist/memory/telemetry.js +51 -0
- package/dist/memory/telemetry.js.map +1 -0
- package/dist/memory/types.d.ts +110 -0
- package/dist/memory/types.d.ts.map +1 -0
- package/dist/memory/types.js +74 -0
- package/dist/memory/types.js.map +1 -0
- package/dist/publish/auto-publish.d.ts +1 -1
- package/dist/publish/auto-publish.js +1 -1
- package/dist/runtime/network-gateway.d.ts +24 -4
- package/dist/runtime/network-gateway.d.ts.map +1 -1
- package/dist/runtime/network-gateway.js +86 -12
- package/dist/runtime/network-gateway.js.map +1 -1
- package/dist/testsuite/gate.d.ts +8 -0
- package/dist/testsuite/gate.d.ts.map +1 -1
- package/dist/testsuite/gate.js +13 -3
- package/dist/testsuite/gate.js.map +1 -1
- package/dist/testsuite/run.d.ts +6 -11
- package/dist/testsuite/run.d.ts.map +1 -1
- package/dist/testsuite/run.js +29 -4
- package/dist/testsuite/run.js.map +1 -1
- package/dist/utils/arena-success.d.ts +10 -0
- package/dist/utils/arena-success.d.ts.map +1 -1
- package/dist/utils/arena-success.js +35 -8
- package/dist/utils/arena-success.js.map +1 -1
- package/dist/utils/binding.d.ts +6 -2
- package/dist/utils/binding.d.ts.map +1 -1
- package/dist/utils/binding.js.map +1 -1
- package/dist/utils/clawhub-client.d.ts +73 -0
- package/dist/utils/clawhub-client.d.ts.map +1 -0
- package/dist/utils/clawhub-client.js +176 -0
- package/dist/utils/clawhub-client.js.map +1 -0
- package/dist/utils/config.d.ts +7 -0
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +15 -1
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/fitness-formula.d.ts +20 -4
- package/dist/utils/fitness-formula.d.ts.map +1 -1
- package/dist/utils/fitness-formula.js +24 -6
- package/dist/utils/fitness-formula.js.map +1 -1
- package/dist/utils/gene-id-display.d.ts +14 -0
- package/dist/utils/gene-id-display.d.ts.map +1 -0
- package/dist/utils/gene-id-display.js +64 -0
- package/dist/utils/gene-id-display.js.map +1 -0
- package/dist/utils/l0-gate.d.ts.map +1 -1
- package/dist/utils/l0-gate.js +4 -1
- package/dist/utils/l0-gate.js.map +1 -1
- package/dist/utils/rust-phenotype.d.ts +17 -5
- package/dist/utils/rust-phenotype.d.ts.map +1 -1
- package/dist/utils/rust-phenotype.js +25 -4
- package/dist/utils/rust-phenotype.js.map +1 -1
- package/package.json +10 -5
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.agentMemoryCommand = void 0;
|
|
37
|
+
exports.listAgentMemory = listAgentMemory;
|
|
38
|
+
exports.creatorLabels = creatorLabels;
|
|
39
|
+
exports.deleteSelector = deleteSelector;
|
|
40
|
+
exports.deleteAgentMemory = deleteAgentMemory;
|
|
41
|
+
/**
|
|
42
|
+
* `rotifer agent memory` — the deployer's view of an agent's memory
|
|
43
|
+
*. PREFERENCE entries are never evicted
|
|
44
|
+
* for quota, so a full memory needs a person to look and clean up.
|
|
45
|
+
*
|
|
46
|
+
* `list` shows what is stored without the values: key, category, size,
|
|
47
|
+
* the creating gene and the last update. Values can hold user data (§30), so
|
|
48
|
+
* they are never printed. `delete` removes one key or a whole category
|
|
49
|
+
* through rotifer-napi's deployer path (memoryAdminDelete), which audits each
|
|
50
|
+
* entry with actor "deployer". Both work on rotifer-napi's store in the
|
|
51
|
+
* project (`.rotifer/playground.db`); the deployer owns the agent, so gene
|
|
52
|
+
* access scopes do not apply. There is no edit command.
|
|
53
|
+
*/
|
|
54
|
+
const commander_1 = require("commander");
|
|
55
|
+
const node_fs_1 = require("node:fs");
|
|
56
|
+
const node_path_1 = require("node:path");
|
|
57
|
+
const display = __importStar(require("../utils/display.js"));
|
|
58
|
+
const config_js_1 = require("../utils/config.js");
|
|
59
|
+
const binding_js_1 = require("../utils/binding.js");
|
|
60
|
+
const project_root_js_1 = require("../utils/project-root.js");
|
|
61
|
+
const agent_run_js_1 = require("./agent-run.js");
|
|
62
|
+
const agent_create_js_1 = require("./agent-create.js");
|
|
63
|
+
const index_js_1 = require("../memory/index.js");
|
|
64
|
+
const host_js_1 = require("../memory/host.js");
|
|
65
|
+
const codec_js_1 = require("../memory/codec.js");
|
|
66
|
+
const types_js_1 = require("../memory/types.js");
|
|
67
|
+
/**
|
|
68
|
+
* What `agent memory list` shows. An agent created before v0.9.4 has no
|
|
69
|
+
* memory yet: an empty listing, not an error. Without native memory there is
|
|
70
|
+
* no store to read: MEMORY_STORAGE_ERROR.
|
|
71
|
+
*/
|
|
72
|
+
function listAgentMemory(native, agentId, category) {
|
|
73
|
+
if (!native) {
|
|
74
|
+
throw new types_js_1.MemoryError("MEMORY_STORAGE_ERROR", "native binding unavailable: agent memory needs the rotifer native addon on this platform");
|
|
75
|
+
}
|
|
76
|
+
let memory;
|
|
77
|
+
try {
|
|
78
|
+
memory = native.memoryGet(agentId);
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
const e = (0, index_js_1.asMemoryError)(err);
|
|
82
|
+
if (e.code === "MEMORY_NOT_FOUND")
|
|
83
|
+
return { entries: [], totalSize: 0, quota: null };
|
|
84
|
+
throw e;
|
|
85
|
+
}
|
|
86
|
+
const entries = memory.entries
|
|
87
|
+
.filter((e) => category === undefined || e.category === category)
|
|
88
|
+
.map((e) => ({
|
|
89
|
+
key: e.key,
|
|
90
|
+
category: e.category,
|
|
91
|
+
size: (0, codec_js_1.entrySize)(e.key, Buffer.from(e.value, "base64")),
|
|
92
|
+
createdBy: e.createdBy,
|
|
93
|
+
updatedAt: e.updatedAt,
|
|
94
|
+
}))
|
|
95
|
+
.sort((a, b) => (a.updatedAt < b.updatedAt ? 1 : a.updatedAt > b.updatedAt ? -1 : a.key < b.key ? -1 : 1));
|
|
96
|
+
return { entries, totalSize: memory.totalSize, quota: memory.quota };
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* How a creating gene is shown: its name when a gene in the project has that
|
|
100
|
+
* id, otherwise (an older version, a gene since removed) a short id prefix.
|
|
101
|
+
*/
|
|
102
|
+
function creatorLabels(genesRoot) {
|
|
103
|
+
const names = new Map();
|
|
104
|
+
if ((0, node_fs_1.existsSync)(genesRoot)) {
|
|
105
|
+
for (const name of (0, node_fs_1.readdirSync)(genesRoot)) {
|
|
106
|
+
const result = (0, binding_js_1.geneIdV2)(genesRoot, name);
|
|
107
|
+
if ("id" in result)
|
|
108
|
+
names.set(result.id, name);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return (geneId) => names.get(geneId) ?? `${geneId.slice(0, 15)}…`;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The selector from `--key` / `--category`: exactly one of them. A bad one
|
|
115
|
+
* is MEMORY_INVALID_INPUT, before anything is touched.
|
|
116
|
+
*/
|
|
117
|
+
function deleteSelector(options) {
|
|
118
|
+
const hasKey = options.key !== undefined;
|
|
119
|
+
const hasCategory = options.category !== undefined;
|
|
120
|
+
if (hasKey === hasCategory) {
|
|
121
|
+
throw new types_js_1.MemoryError("MEMORY_INVALID_INPUT", "give exactly one of --key or --category");
|
|
122
|
+
}
|
|
123
|
+
if (hasKey) {
|
|
124
|
+
if (options.key === "")
|
|
125
|
+
throw new types_js_1.MemoryError("MEMORY_INVALID_INPUT", "--key must not be empty");
|
|
126
|
+
return { key: options.key };
|
|
127
|
+
}
|
|
128
|
+
if (!(0, types_js_1.isMemoryCategory)(options.category)) {
|
|
129
|
+
throw new types_js_1.MemoryError("MEMORY_INVALID_INPUT", `unknown memory category '${options.category}'; use one of PREFERENCE, PATTERN, CONTEXT, CACHE`);
|
|
130
|
+
}
|
|
131
|
+
return { category: options.category };
|
|
132
|
+
}
|
|
133
|
+
/** Delete as the deployer; returns how many entries went. A missing key is MEMORY_NOT_FOUND. */
|
|
134
|
+
function deleteAgentMemory(native, agentId, selector) {
|
|
135
|
+
if (!native || typeof native.memoryAdminDelete !== "function") {
|
|
136
|
+
throw new types_js_1.MemoryError("MEMORY_STORAGE_ERROR", "native binding unavailable: agent memory needs the rotifer native addon on this platform");
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
return Number(native.memoryAdminDelete(agentId, JSON.stringify(selector)));
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
throw (0, index_js_1.asMemoryError)(err);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/** The agent named on the command line, or exit with E0050. */
|
|
146
|
+
function agentOrExit(root, agentName) {
|
|
147
|
+
const agent = (0, agent_run_js_1.findAgent)(root, agentName);
|
|
148
|
+
if (!agent) {
|
|
149
|
+
display.rustStyleError({
|
|
150
|
+
code: "E0050",
|
|
151
|
+
message: `Agent '${agentName}' not found`,
|
|
152
|
+
suggestion: "List agents: rotifer agent list",
|
|
153
|
+
});
|
|
154
|
+
process.exit(1);
|
|
155
|
+
}
|
|
156
|
+
return agent;
|
|
157
|
+
}
|
|
158
|
+
const memoryListCommand = new commander_1.Command("list")
|
|
159
|
+
.description("List an agent's memory entries: key, category, size, creating gene, last update (values are not shown)")
|
|
160
|
+
.argument("<agent-name>", "agent name")
|
|
161
|
+
.option("-c, --category <category>", "only this category: PREFERENCE, PATTERN, CONTEXT or CACHE")
|
|
162
|
+
.addHelpText("after", ["", "Examples:", " $ rotifer agent memory list my-agent", " $ rotifer agent memory list my-agent --category PREFERENCE"].join("\n"))
|
|
163
|
+
.action((agentName, options) => {
|
|
164
|
+
const root = (0, project_root_js_1.requireProjectRoot)();
|
|
165
|
+
const agent = agentOrExit(root, agentName);
|
|
166
|
+
if (options.category !== undefined && !(0, types_js_1.isMemoryCategory)(options.category)) {
|
|
167
|
+
display.rustStyleError({
|
|
168
|
+
code: "E0040",
|
|
169
|
+
message: `unknown memory category '${options.category}'`,
|
|
170
|
+
suggestion: "Use one of PREFERENCE, PATTERN, CONTEXT, CACHE",
|
|
171
|
+
});
|
|
172
|
+
process.exit(1);
|
|
173
|
+
}
|
|
174
|
+
let listing;
|
|
175
|
+
try {
|
|
176
|
+
listing = listAgentMemory((0, host_js_1.projectNativeMemory)(root), agent.id, options.category);
|
|
177
|
+
}
|
|
178
|
+
catch (err) {
|
|
179
|
+
const e = (0, index_js_1.asMemoryError)(err);
|
|
180
|
+
display.rustStyleError({ code: "E0040", message: `${e.code}: ${e.message}` });
|
|
181
|
+
process.exit(1);
|
|
182
|
+
}
|
|
183
|
+
display.header(`Agent Memory: ${agentName}`);
|
|
184
|
+
const creator = creatorLabels((0, node_path_1.join)(root, (0, config_js_1.loadConfig)(root).genes_dir));
|
|
185
|
+
if (listing.entries.length === 0) {
|
|
186
|
+
display.info(options.category ? `No ${options.category} entries` : "No memory entries yet");
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
display.table(listing.entries.map((e) => ({ ...e, createdBy: creator(e.createdBy) })), [
|
|
190
|
+
{ key: "key", label: "Key" },
|
|
191
|
+
{ key: "category", label: "Category", width: 12 },
|
|
192
|
+
{ key: "size", label: "Size", align: "right", format: (v) => (0, agent_create_js_1.formatQuota)(Number(v)) },
|
|
193
|
+
{ key: "createdBy", label: "Created by" },
|
|
194
|
+
{ key: "updatedAt", label: "Updated" },
|
|
195
|
+
]);
|
|
196
|
+
}
|
|
197
|
+
const quota = listing.quota === null ? "no memory created yet" : `${(0, agent_create_js_1.formatQuota)(listing.totalSize)} of ${(0, agent_create_js_1.formatQuota)(listing.quota)} used`;
|
|
198
|
+
display.hint(`${listing.entries.length} entr${listing.entries.length === 1 ? "y" : "ies"} shown · ${quota}`);
|
|
199
|
+
});
|
|
200
|
+
const memoryDeleteCommand = new commander_1.Command("delete")
|
|
201
|
+
.description("Delete an agent's memory entries as the deployer: one key, or every entry of one category")
|
|
202
|
+
.argument("<agent-name>", "agent name")
|
|
203
|
+
.option("-k, --key <key>", "the entry with this key")
|
|
204
|
+
.option("-c, --category <category>", "every entry of this category: PREFERENCE, PATTERN, CONTEXT or CACHE")
|
|
205
|
+
.addHelpText("after", [
|
|
206
|
+
"",
|
|
207
|
+
"Give exactly one of --key or --category. PREFERENCE entries are never evicted for quota, so this is how a full memory is cleared.",
|
|
208
|
+
"",
|
|
209
|
+
"Examples:",
|
|
210
|
+
" $ rotifer agent memory delete my-agent --key preference-demo/ada/language",
|
|
211
|
+
" $ rotifer agent memory delete my-agent --category CACHE",
|
|
212
|
+
].join("\n"))
|
|
213
|
+
.action((agentName, options) => {
|
|
214
|
+
const root = (0, project_root_js_1.requireProjectRoot)();
|
|
215
|
+
const agent = agentOrExit(root, agentName);
|
|
216
|
+
let deleted;
|
|
217
|
+
try {
|
|
218
|
+
deleted = deleteAgentMemory((0, host_js_1.projectNativeMemory)(root), agent.id, deleteSelector(options));
|
|
219
|
+
}
|
|
220
|
+
catch (err) {
|
|
221
|
+
const e = (0, index_js_1.asMemoryError)(err);
|
|
222
|
+
display.rustStyleError({
|
|
223
|
+
code: "E0040",
|
|
224
|
+
message: `${e.code}: ${e.message}`,
|
|
225
|
+
suggestion: e.code === "MEMORY_NOT_FOUND" ? `See what is stored: rotifer agent memory list ${agentName}` : undefined,
|
|
226
|
+
});
|
|
227
|
+
process.exit(1);
|
|
228
|
+
}
|
|
229
|
+
display.success(`Deleted ${deleted} entr${deleted === 1 ? "y" : "ies"} from ${agentName}'s memory`);
|
|
230
|
+
});
|
|
231
|
+
exports.agentMemoryCommand = new commander_1.Command("memory")
|
|
232
|
+
.description("Look at and clean up an agent's memory (deployer tools)")
|
|
233
|
+
.addCommand(memoryListCommand)
|
|
234
|
+
.addCommand(memoryDeleteCommand);
|
|
235
|
+
//# sourceMappingURL=agent-memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-memory.js","sourceRoot":"","sources":["../../src/commands/agent-memory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,0CAuBC;AAMD,sCASC;AAcD,wCAcC;AAGD,8CASC;AA/HD;;;;;;;;;;;;GAYG;AACH,yCAAoC;AACpC,qCAAkD;AAClD,yCAAiC;AACjC,6DAA+C;AAC/C,kDAAgD;AAChD,oDAA+C;AAC/C,8DAA8D;AAC9D,iDAA2C;AAC3C,uDAAgD;AAChD,iDAAyE;AACzE,+CAAwD;AACxD,iDAA+C;AAC/C,iDAA8G;AAmB9G;;;;GAIG;AACH,SAAgB,eAAe,CAAC,MAA8B,EAAE,OAAe,EAAE,QAAyB;IACxG,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,sBAAW,CAAC,sBAAsB,EAAE,0FAA0F,CAAC,CAAC;IAC5I,CAAC;IACD,IAAI,MAAwE,CAAC;IAC7E,IAAI,CAAC;QACH,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,OAAO,CAAkB,CAAC;IACtD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,CAAC,GAAG,IAAA,wBAAa,EAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,CAAC,CAAC,IAAI,KAAK,kBAAkB;YAAE,OAAO,EAAE,OAAO,EAA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,CAAC,CAAC;AAEQ,QAAA,kBAAkB,GAAG,IAAI,mBAAO,CAAC,QAAQ,CAAC;KACpD,WAAW,CAAC,yDAAyD,CAAC;KACtE,UAAU,CAAC,iBAAiB,CAAC;KAC7B,UAAU,CAAC,mBAAmB,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-run.d.ts","sourceRoot":"","sources":["../../src/commands/agent-run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"agent-run.d.ts","sourceRoot":"","sources":["../../src/commands/agent-run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAqBpC,UAAU,SAAS;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,WAAW,CAAC,EAAE;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;QACpB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,SAAS,CAAC,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,EAAE,CAAC,EAAE,MAAM,CAAC;YAAC,KAAK,CAAC,EAAE,OAAO,CAAC;YAAC,MAAM,CAAC,EAAE,OAAO,CAAA;SAAE,CAAC;QAC9E,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED,eAAO,MAAM,eAAe,SAiZxB,CAAC;AA4fL,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAgB3E;AAUD,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EAAE,EAChB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GACjB,IAAI,CA0DN"}
|
|
@@ -48,6 +48,7 @@ const project_root_js_1 = require("../utils/project-root.js");
|
|
|
48
48
|
const binding_js_1 = require("../utils/binding.js");
|
|
49
49
|
const l0_gate_js_1 = require("../utils/l0-gate.js");
|
|
50
50
|
const network_gateway_js_1 = require("../runtime/network-gateway.js");
|
|
51
|
+
const host_js_1 = require("../memory/host.js");
|
|
51
52
|
const domain_failover_js_1 = require("../runtime/domain-failover.js");
|
|
52
53
|
const invocation_js_1 = require("../cloud/invocation.js");
|
|
53
54
|
const heartbeat_js_1 = require("../telemetry/heartbeat.js");
|
|
@@ -106,16 +107,42 @@ exports.agentRunCommand = new commander_1.Command("run")
|
|
|
106
107
|
const l0Binding = (0, binding_js_1.tryLoadBinding)();
|
|
107
108
|
const binding = isSandboxEnabled ? l0Binding : null;
|
|
108
109
|
const startTime = performance.now();
|
|
110
|
+
// The agent's memory for this run (spec §38.2): ctx.memory on the Node
|
|
111
|
+
// path, and the project binding + memoryContext on the WASM path.
|
|
112
|
+
const agentMemory = (0, host_js_1.openAgentMemory)({ root, genesRoot: genesDir, agent });
|
|
109
113
|
// TryPool: domain-based failover with fitness tracking
|
|
110
114
|
if (compositionType === "TryPool") {
|
|
111
|
-
await executeTryPool(agent, genesDir, binding, l0Binding, input, root, options.verbose, options.trustUnsigned);
|
|
115
|
+
await executeTryPool(agent, genesDir, binding, l0Binding, input, root, options.verbose, options.trustUnsigned, agentMemory);
|
|
112
116
|
return;
|
|
113
117
|
}
|
|
114
|
-
//
|
|
115
|
-
|
|
116
|
-
|
|
118
|
+
// Par, Cond and Try run only on the Rust algebra executor, which needs the
|
|
119
|
+
// sandbox and every gene compiled. Where it cannot run, the agent is
|
|
120
|
+
// refused before any gene executes: the sequential loop below would run
|
|
121
|
+
// a different workflow under the same label — Seq's result for Par and
|
|
122
|
+
// Cond, a Try that never reaches its handler, a branch that should not
|
|
123
|
+
// have run (#450).
|
|
124
|
+
if (compositionType !== "Single" && compositionType !== "Seq") {
|
|
125
|
+
const refuse = (reason, hint) => {
|
|
126
|
+
display.error(`${compositionType} cannot run here: ${reason}. No gene was run.`);
|
|
127
|
+
display.hint(hint);
|
|
128
|
+
process.exit(1);
|
|
129
|
+
};
|
|
130
|
+
if (!binding) {
|
|
131
|
+
if (!isSandboxEnabled) {
|
|
132
|
+
refuse("--no-sandbox runs genes as Node.js modules one after another, which is Seq, not " + compositionType, "Run it without --no-sandbox, or create a Seq agent for the Node.js path.");
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
refuse("it runs on the sandbox's algebra executor, and the native addon did not load", "Run 'rotifer doctor' to see what is missing.");
|
|
136
|
+
}
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const algebra = executeViaAlgebra(agent, genesDir, binding, input, compositionType, options.verbose, agentMemory.wasm);
|
|
117
140
|
if (algebra.kind === "failed")
|
|
118
141
|
return;
|
|
142
|
+
if (algebra.kind === "unavailable") {
|
|
143
|
+
refuse(algebra.reason, algebra.hint);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
119
146
|
if (algebra.kind === "done") {
|
|
120
147
|
const totalElapsed = performance.now() - startTime;
|
|
121
148
|
console.log();
|
|
@@ -128,10 +155,9 @@ exports.agentRunCommand = new commander_1.Command("run")
|
|
|
128
155
|
console.log(JSON.stringify(algebra.output, null, 2));
|
|
129
156
|
return;
|
|
130
157
|
}
|
|
131
|
-
display.warn("Falling back to sequential execution (some genes not compiled)");
|
|
132
158
|
}
|
|
133
159
|
const pipelineLog = [];
|
|
134
|
-
// Sequential execution (Seq / Single
|
|
160
|
+
// Sequential execution (Seq / Single)
|
|
135
161
|
let current = input;
|
|
136
162
|
for (let i = 0; i < agent.genome.length; i++) {
|
|
137
163
|
const geneName = agent.genome[i];
|
|
@@ -150,7 +176,9 @@ exports.agentRunCommand = new commander_1.Command("run")
|
|
|
150
176
|
? JSON.parse((0, node_fs_1.readFileSync)(phenotypePath, "utf-8"))
|
|
151
177
|
: {};
|
|
152
178
|
const { irHash: _strip, ...phenotypeForExec } = rawPhenotype;
|
|
153
|
-
|
|
179
|
+
// With native memory, run on the project binding so the gene's
|
|
180
|
+
// memory calls reach the agent's store.
|
|
181
|
+
const result = (agentMemory.wasm?.binding ?? binding).executeGene(irWasm, JSON.stringify(current), JSON.stringify(phenotypeForExec), sandbox_defaults_js_1.DEFAULT_SANDBOX_CONSTRAINTS_JSON, agentMemory.wasm?.geneContext(geneName));
|
|
154
182
|
const stepElapsed = performance.now() - stepStart;
|
|
155
183
|
if (result.success) {
|
|
156
184
|
display.success(`${step} ${geneName} completed via WASM sandbox (${result.durationMs}ms, fuel: ${result.fuelConsumed})`);
|
|
@@ -296,17 +324,19 @@ exports.agentRunCommand = new commander_1.Command("run")
|
|
|
296
324
|
process.exit(1);
|
|
297
325
|
}
|
|
298
326
|
let result;
|
|
327
|
+
// The agent's memory (spec §38.2; ctx.memory), bound to this gene.
|
|
328
|
+
const memory = agentMemory.forGene(geneName, phenotypeData);
|
|
299
329
|
if (phenotypeData.fidelity === "Hybrid" && phenotypeData.network) {
|
|
300
330
|
const { gatewayFetch, gateway } = (0, network_gateway_js_1.createGatewayFetch)(phenotypeData.network);
|
|
301
331
|
display.info(` ${geneName} is Hybrid — gateway active (domains: ${phenotypeData.network.allowedDomains?.join(", ") || "none"})`);
|
|
302
|
-
result = await mod.express(current, { gatewayFetch });
|
|
332
|
+
result = await mod.express(current, { gatewayFetch, memory });
|
|
303
333
|
if (options.verbose) {
|
|
304
334
|
const stats = gateway.stats;
|
|
305
335
|
display.info(` Gateway stats: ${stats.totalRequests} requests, ${stats.totalBytes} bytes`);
|
|
306
336
|
}
|
|
307
337
|
}
|
|
308
338
|
else {
|
|
309
|
-
result = await mod.express(current);
|
|
339
|
+
result = await mod.express(current, { memory });
|
|
310
340
|
}
|
|
311
341
|
const stepElapsed = performance.now() - stepStart;
|
|
312
342
|
display.success(`${step} ${geneName} completed via Node.js (${stepElapsed.toFixed(1)}ms)`);
|
|
@@ -394,7 +424,7 @@ function printPipelineLog(log) {
|
|
|
394
424
|
}
|
|
395
425
|
}
|
|
396
426
|
}
|
|
397
|
-
async function executeTryPool(agent, genesDir, binding, l0Binding, input, root, isVerbose, isTrustUnsigned) {
|
|
427
|
+
async function executeTryPool(agent, genesDir, binding, l0Binding, input, root, isVerbose, isTrustUnsigned, agentMemory) {
|
|
398
428
|
const engine = new domain_failover_js_1.DomainFailoverEngine();
|
|
399
429
|
const startTime = performance.now();
|
|
400
430
|
for (const geneName of agent.genome) {
|
|
@@ -406,7 +436,7 @@ async function executeTryPool(agent, genesDir, binding, l0Binding, input, root,
|
|
|
406
436
|
const domain = phenotype.domain || "default";
|
|
407
437
|
const irWasmPath = (0, node_path_1.join)(geneDir, "gene.ir.wasm");
|
|
408
438
|
const hasWasm = (0, node_fs_1.existsSync)(irWasmPath);
|
|
409
|
-
const executor = await buildGeneExecutor(geneName, geneDir, irWasmPath, hasWasm, phenotype, binding, l0Binding, isTrustUnsigned);
|
|
439
|
+
const executor = await buildGeneExecutor(geneName, geneDir, irWasmPath, hasWasm, phenotype, binding, l0Binding, isTrustUnsigned, agentMemory.forGene(geneName, phenotype), agentMemory.wasm);
|
|
410
440
|
engine.registerGene(geneName, domain, executor);
|
|
411
441
|
}
|
|
412
442
|
const fitnessPath = (0, node_path_1.join)(root, ".rotifer", "agents", `${agent.name}.fitness.json`);
|
|
@@ -499,7 +529,11 @@ function refuseNodeExecution(geneDir, isTrustUnsigned) {
|
|
|
499
529
|
return null;
|
|
500
530
|
return "Cloud-installed genes cannot run via Node.js without sandbox.";
|
|
501
531
|
}
|
|
502
|
-
async function buildGeneExecutor(geneName, geneDir, irWasmPath, hasWasm, phenotype, binding, l0Binding, isTrustUnsigned
|
|
532
|
+
async function buildGeneExecutor(geneName, geneDir, irWasmPath, hasWasm, phenotype, binding, l0Binding, isTrustUnsigned,
|
|
533
|
+
/** The agent's memory for this gene, handed to a Node-path gene as ctx.memory. */
|
|
534
|
+
memory,
|
|
535
|
+
/** The same memory for the WASM path: project binding + memoryContext. */
|
|
536
|
+
wasmMemory) {
|
|
503
537
|
if (hasWasm && binding) {
|
|
504
538
|
const wasmBytes = (0, node_fs_1.readFileSync)(irWasmPath);
|
|
505
539
|
const { irHash: _strip, ...phenotypeForExec } = phenotype;
|
|
@@ -507,7 +541,7 @@ async function buildGeneExecutor(geneName, geneDir, irWasmPath, hasWasm, phenoty
|
|
|
507
541
|
return async (input) => {
|
|
508
542
|
const start = performance.now();
|
|
509
543
|
try {
|
|
510
|
-
const result = binding.executeGene(wasmBytes, JSON.stringify(input), phenoStr, sandbox_defaults_js_1.DEFAULT_SANDBOX_CONSTRAINTS_JSON);
|
|
544
|
+
const result = (wasmMemory?.binding ?? binding).executeGene(wasmBytes, JSON.stringify(input), phenoStr, sandbox_defaults_js_1.DEFAULT_SANDBOX_CONSTRAINTS_JSON, wasmMemory?.geneContext(geneName));
|
|
511
545
|
const elapsed = performance.now() - start;
|
|
512
546
|
(0, run_logger_js_1.logGeneExecution)({ geneDir,
|
|
513
547
|
geneName, success: result.success, durationMs: elapsed,
|
|
@@ -592,10 +626,10 @@ async function buildGeneExecutor(geneName, geneDir, irWasmPath, hasWasm, phenoty
|
|
|
592
626
|
let result;
|
|
593
627
|
if (isHybrid) {
|
|
594
628
|
const { gatewayFetch } = (0, network_gateway_js_1.createGatewayFetch)(phenotype.network);
|
|
595
|
-
result = await mod.express(input, { gatewayFetch });
|
|
629
|
+
result = await mod.express(input, { gatewayFetch, memory });
|
|
596
630
|
}
|
|
597
631
|
else {
|
|
598
|
-
result = await mod.express(input);
|
|
632
|
+
result = await mod.express(input, { memory });
|
|
599
633
|
}
|
|
600
634
|
const elapsed = performance.now() - start;
|
|
601
635
|
(0, run_logger_js_1.logGeneExecution)({ geneDir,
|
|
@@ -629,18 +663,28 @@ async function buildGeneExecutor(geneName, geneDir, irWasmPath, hasWasm, phenoty
|
|
|
629
663
|
function geneNameToId(geneName) {
|
|
630
664
|
return (0, node_crypto_1.createHash)("sha256").update(geneName).digest("hex");
|
|
631
665
|
}
|
|
632
|
-
function executeViaAlgebra(agent, genesDir, binding, input, compositionType, isVerbose
|
|
666
|
+
function executeViaAlgebra(agent, genesDir, binding, input, compositionType, isVerbose,
|
|
667
|
+
/** With native memory: run on the project binding with {"agentId"}; each gene acts as its entry's v2Id. */
|
|
668
|
+
wasmMemory) {
|
|
633
669
|
const comp = agent.composition;
|
|
634
|
-
if (!comp)
|
|
635
|
-
return {
|
|
670
|
+
if (!comp) {
|
|
671
|
+
return {
|
|
672
|
+
kind: "unavailable",
|
|
673
|
+
reason: "this agent has no composition record",
|
|
674
|
+
hint: `Re-create it: rotifer agent create ${agent.name} --genes ${agent.genome.join(" ")} --composition ${compositionType}`,
|
|
675
|
+
};
|
|
676
|
+
}
|
|
636
677
|
const geneEntries = {};
|
|
637
678
|
for (const geneName of agent.genome) {
|
|
638
679
|
const geneDir = (0, node_path_1.join)(genesDir, geneName);
|
|
639
680
|
const irWasmPath = (0, node_path_1.join)(geneDir, "gene.ir.wasm");
|
|
640
681
|
const phenotypePath = (0, node_path_1.join)(geneDir, "phenotype.json");
|
|
641
682
|
if (!(0, node_fs_1.existsSync)(irWasmPath)) {
|
|
642
|
-
|
|
643
|
-
|
|
683
|
+
return {
|
|
684
|
+
kind: "unavailable",
|
|
685
|
+
reason: `gene '${geneName}' is not compiled, and the algebra executor runs compiled genes only`,
|
|
686
|
+
hint: `Compile it first: rotifer compile ${geneName}`,
|
|
687
|
+
};
|
|
644
688
|
}
|
|
645
689
|
const wasmBytes = (0, node_fs_1.readFileSync)(irWasmPath);
|
|
646
690
|
const phenotype = (0, node_fs_1.existsSync)(phenotypePath)
|
|
@@ -682,8 +726,13 @@ function executeViaAlgebra(agent, genesDir, binding, input, compositionType, isV
|
|
|
682
726
|
break;
|
|
683
727
|
}
|
|
684
728
|
case "Cond": {
|
|
685
|
-
if (geneIds.length < 2)
|
|
686
|
-
return {
|
|
729
|
+
if (geneIds.length < 2) {
|
|
730
|
+
return {
|
|
731
|
+
kind: "unavailable",
|
|
732
|
+
reason: `it needs two genes and this agent has ${geneIds.length}`,
|
|
733
|
+
hint: "Re-create the agent with two genes.",
|
|
734
|
+
};
|
|
735
|
+
}
|
|
687
736
|
const pred = comp?.predicate;
|
|
688
737
|
algebraExpr = {
|
|
689
738
|
Cond: {
|
|
@@ -700,8 +749,13 @@ function executeViaAlgebra(agent, genesDir, binding, input, compositionType, isV
|
|
|
700
749
|
break;
|
|
701
750
|
}
|
|
702
751
|
case "Try": {
|
|
703
|
-
if (geneIds.length < 2)
|
|
704
|
-
return {
|
|
752
|
+
if (geneIds.length < 2) {
|
|
753
|
+
return {
|
|
754
|
+
kind: "unavailable",
|
|
755
|
+
reason: `it needs two genes and this agent has ${geneIds.length}`,
|
|
756
|
+
hint: "Re-create the agent with two genes.",
|
|
757
|
+
};
|
|
758
|
+
}
|
|
705
759
|
algebraExpr = {
|
|
706
760
|
Try: {
|
|
707
761
|
primary: { Gene: hexToGeneIdArray(geneIds[0]) },
|
|
@@ -712,14 +766,18 @@ function executeViaAlgebra(agent, genesDir, binding, input, compositionType, isV
|
|
|
712
766
|
break;
|
|
713
767
|
}
|
|
714
768
|
default:
|
|
715
|
-
return {
|
|
769
|
+
return {
|
|
770
|
+
kind: "unavailable",
|
|
771
|
+
reason: `'${compositionType}' is not a composition agent run knows`,
|
|
772
|
+
hint: "Use Seq, Par, Cond, Try or TryPool.",
|
|
773
|
+
};
|
|
716
774
|
}
|
|
717
775
|
try {
|
|
718
776
|
// Same sandbox limits as the Single / Seq path (execute_gene). Without
|
|
719
777
|
// them the binding falls back to ConstraintSet::default() (1M fuel),
|
|
720
778
|
// below what one compiled gene of ordinary size needs. A binding older
|
|
721
779
|
// than this argument ignores it.
|
|
722
|
-
const result = binding.executeAlgebra(JSON.stringify(algebraExpr), JSON.stringify(geneEntries), JSON.stringify(input), sandbox_defaults_js_1.DEFAULT_SANDBOX_CONSTRAINTS_JSON);
|
|
780
|
+
const result = (wasmMemory?.binding ?? binding).executeAlgebra(JSON.stringify(algebraExpr), JSON.stringify(geneEntries), JSON.stringify(input), sandbox_defaults_js_1.DEFAULT_SANDBOX_CONSTRAINTS_JSON, wasmMemory?.agentContext);
|
|
723
781
|
if (result.success) {
|
|
724
782
|
display.success(`${compositionType} execution completed (${result.totalDurationMs}ms, fuel: ${result.totalFuelConsumed})`);
|
|
725
783
|
if (isVerbose) {
|