@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.
Files changed (125) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +2 -2
  3. package/README.zh.md +2 -2
  4. package/dist/cloud/client.d.ts.map +1 -1
  5. package/dist/cloud/client.js +9 -0
  6. package/dist/cloud/client.js.map +1 -1
  7. package/dist/cloud/types.d.ts +7 -0
  8. package/dist/cloud/types.d.ts.map +1 -1
  9. package/dist/cloud/types.js.map +1 -1
  10. package/dist/commands/agent-create.d.ts +11 -0
  11. package/dist/commands/agent-create.d.ts.map +1 -1
  12. package/dist/commands/agent-create.js +50 -1
  13. package/dist/commands/agent-create.js.map +1 -1
  14. package/dist/commands/agent-memory.d.ts +64 -0
  15. package/dist/commands/agent-memory.d.ts.map +1 -0
  16. package/dist/commands/agent-memory.js +235 -0
  17. package/dist/commands/agent-memory.js.map +1 -0
  18. package/dist/commands/agent-run.d.ts.map +1 -1
  19. package/dist/commands/agent-run.js +84 -26
  20. package/dist/commands/agent-run.js.map +1 -1
  21. package/dist/commands/arena-submit.d.ts.map +1 -1
  22. package/dist/commands/arena-submit.js +34 -36
  23. package/dist/commands/arena-submit.js.map +1 -1
  24. package/dist/commands/compile.d.ts.map +1 -1
  25. package/dist/commands/compile.js +32 -6
  26. package/dist/commands/compile.js.map +1 -1
  27. package/dist/commands/genome-format.d.ts +5 -1
  28. package/dist/commands/genome-format.d.ts.map +1 -1
  29. package/dist/commands/genome-format.js +5 -1
  30. package/dist/commands/genome-format.js.map +1 -1
  31. package/dist/commands/hello.d.ts.map +1 -1
  32. package/dist/commands/hello.js +15 -2
  33. package/dist/commands/hello.js.map +1 -1
  34. package/dist/commands/run.d.ts.map +1 -1
  35. package/dist/commands/run.js +59 -4
  36. package/dist/commands/run.js.map +1 -1
  37. package/dist/commands/test.d.ts.map +1 -1
  38. package/dist/commands/test.js +78 -23
  39. package/dist/commands/test.js.map +1 -1
  40. package/dist/commands/wrap.d.ts.map +1 -1
  41. package/dist/commands/wrap.js +28 -70
  42. package/dist/commands/wrap.js.map +1 -1
  43. package/dist/index.js +47 -1
  44. package/dist/index.js.map +1 -1
  45. package/dist/memory/access.d.ts +53 -0
  46. package/dist/memory/access.d.ts.map +1 -0
  47. package/dist/memory/access.js +111 -0
  48. package/dist/memory/access.js.map +1 -0
  49. package/dist/memory/audit.d.ts +26 -0
  50. package/dist/memory/audit.d.ts.map +1 -0
  51. package/dist/memory/audit.js +30 -0
  52. package/dist/memory/audit.js.map +1 -0
  53. package/dist/memory/backend.d.ts +141 -0
  54. package/dist/memory/backend.d.ts.map +1 -0
  55. package/dist/memory/backend.js +536 -0
  56. package/dist/memory/backend.js.map +1 -0
  57. package/dist/memory/codec.d.ts +34 -0
  58. package/dist/memory/codec.d.ts.map +1 -0
  59. package/dist/memory/codec.js +184 -0
  60. package/dist/memory/codec.js.map +1 -0
  61. package/dist/memory/data-policy.d.ts +39 -0
  62. package/dist/memory/data-policy.d.ts.map +1 -0
  63. package/dist/memory/data-policy.js +42 -0
  64. package/dist/memory/data-policy.js.map +1 -0
  65. package/dist/memory/host.d.ts +119 -0
  66. package/dist/memory/host.d.ts.map +1 -0
  67. package/dist/memory/host.js +226 -0
  68. package/dist/memory/host.js.map +1 -0
  69. package/dist/memory/index.d.ts +37 -0
  70. package/dist/memory/index.d.ts.map +1 -0
  71. package/dist/memory/index.js +64 -0
  72. package/dist/memory/index.js.map +1 -0
  73. package/dist/memory/telemetry.d.ts +35 -0
  74. package/dist/memory/telemetry.d.ts.map +1 -0
  75. package/dist/memory/telemetry.js +51 -0
  76. package/dist/memory/telemetry.js.map +1 -0
  77. package/dist/memory/types.d.ts +110 -0
  78. package/dist/memory/types.d.ts.map +1 -0
  79. package/dist/memory/types.js +74 -0
  80. package/dist/memory/types.js.map +1 -0
  81. package/dist/publish/auto-publish.d.ts +1 -1
  82. package/dist/publish/auto-publish.js +1 -1
  83. package/dist/runtime/network-gateway.d.ts +24 -4
  84. package/dist/runtime/network-gateway.d.ts.map +1 -1
  85. package/dist/runtime/network-gateway.js +86 -12
  86. package/dist/runtime/network-gateway.js.map +1 -1
  87. package/dist/testsuite/gate.d.ts +8 -0
  88. package/dist/testsuite/gate.d.ts.map +1 -1
  89. package/dist/testsuite/gate.js +13 -3
  90. package/dist/testsuite/gate.js.map +1 -1
  91. package/dist/testsuite/run.d.ts +6 -11
  92. package/dist/testsuite/run.d.ts.map +1 -1
  93. package/dist/testsuite/run.js +29 -4
  94. package/dist/testsuite/run.js.map +1 -1
  95. package/dist/utils/arena-success.d.ts +10 -0
  96. package/dist/utils/arena-success.d.ts.map +1 -1
  97. package/dist/utils/arena-success.js +35 -8
  98. package/dist/utils/arena-success.js.map +1 -1
  99. package/dist/utils/binding.d.ts +6 -2
  100. package/dist/utils/binding.d.ts.map +1 -1
  101. package/dist/utils/binding.js.map +1 -1
  102. package/dist/utils/clawhub-client.d.ts +73 -0
  103. package/dist/utils/clawhub-client.d.ts.map +1 -0
  104. package/dist/utils/clawhub-client.js +176 -0
  105. package/dist/utils/clawhub-client.js.map +1 -0
  106. package/dist/utils/config.d.ts +7 -0
  107. package/dist/utils/config.d.ts.map +1 -1
  108. package/dist/utils/config.js +15 -1
  109. package/dist/utils/config.js.map +1 -1
  110. package/dist/utils/fitness-formula.d.ts +20 -4
  111. package/dist/utils/fitness-formula.d.ts.map +1 -1
  112. package/dist/utils/fitness-formula.js +24 -6
  113. package/dist/utils/fitness-formula.js.map +1 -1
  114. package/dist/utils/gene-id-display.d.ts +14 -0
  115. package/dist/utils/gene-id-display.d.ts.map +1 -0
  116. package/dist/utils/gene-id-display.js +64 -0
  117. package/dist/utils/gene-id-display.js.map +1 -0
  118. package/dist/utils/l0-gate.d.ts.map +1 -1
  119. package/dist/utils/l0-gate.js +4 -1
  120. package/dist/utils/l0-gate.js.map +1 -1
  121. package/dist/utils/rust-phenotype.d.ts +17 -5
  122. package/dist/utils/rust-phenotype.d.ts.map +1 -1
  123. package/dist/utils/rust-phenotype.js +25 -4
  124. package/dist/utils/rust-phenotype.js.map +1 -1
  125. package/package.json +10 -5
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MAX_RETENTION_DAYS = exports.MAX_KEY_BYTES = void 0;
4
+ exports.entryIdFor = entryIdFor;
5
+ exports.encodeValue = encodeValue;
6
+ exports.decodeValue = decodeValue;
7
+ exports.checkKey = checkKey;
8
+ exports.checkAccessPolicy = checkAccessPolicy;
9
+ exports.checkRetentionPolicy = checkRetentionPolicy;
10
+ exports.toTimestamp = toTimestamp;
11
+ exports.parseTimestamp = parseTimestamp;
12
+ exports.toEntryJson = toEntryJson;
13
+ exports.fromEntryJson = fromEntryJson;
14
+ exports.parseMemoryQuota = parseMemoryQuota;
15
+ exports.entrySize = entrySize;
16
+ exports.isV2GeneId = isV2GeneId;
17
+ /**
18
+ * Conversions at the AgentMemory boundary: entry ids, base64
19
+ * values, the JSON shape of an entry, timestamps and the quota size syntax.
20
+ * Anything that does not parse is MEMORY_INVALID_INPUT, never coerced.
21
+ */
22
+ const node_crypto_1 = require("node:crypto");
23
+ const types_js_1 = require("./types.js");
24
+ /** Lowercase hex SHA-256 of `agentId + "\0" + key`. Updates keep the id. */
25
+ function entryIdFor(agentId, key) {
26
+ return (0, node_crypto_1.createHash)("sha256").update(`${agentId}\0${key}`, "utf8").digest("hex");
27
+ }
28
+ // Standard alphabet, padded: the same in every binding.
29
+ // Buffer.from(…, "base64") would also accept base64url, missing padding and
30
+ // stray characters, and silently decode something else.
31
+ const BASE64 = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
32
+ function encodeValue(value) {
33
+ return Buffer.from(value.buffer, value.byteOffset, value.byteLength).toString("base64");
34
+ }
35
+ function decodeValue(base64) {
36
+ if (typeof base64 !== "string" || !BASE64.test(base64)) {
37
+ throw new types_js_1.MemoryError("MEMORY_INVALID_INPUT", "value must be standard base64 (A–Z a–z 0–9 + /, padded)");
38
+ }
39
+ return new Uint8Array(Buffer.from(base64, "base64"));
40
+ }
41
+ /** Keys are UTF-8 text without NUL (the entry id uses "\0" as its separator). */
42
+ exports.MAX_KEY_BYTES = 1024;
43
+ function checkKey(key) {
44
+ if (typeof key !== "string" || key.length === 0) {
45
+ throw new types_js_1.MemoryError("MEMORY_INVALID_INPUT", "key must be a non-empty string");
46
+ }
47
+ if (key.includes("\0")) {
48
+ throw new types_js_1.MemoryError("MEMORY_INVALID_INPUT", "key must not contain a NUL character");
49
+ }
50
+ if (Buffer.byteLength(key, "utf8") > exports.MAX_KEY_BYTES) {
51
+ throw new types_js_1.MemoryError("MEMORY_INVALID_INPUT", `key is longer than ${exports.MAX_KEY_BYTES} bytes`);
52
+ }
53
+ return key;
54
+ }
55
+ function checkAccessPolicy(policy) {
56
+ const p = policy;
57
+ if (!p || typeof p !== "object") {
58
+ throw new types_js_1.MemoryError("MEMORY_INVALID_INPUT", "accessPolicy must be an object");
59
+ }
60
+ if (!(0, types_js_1.isAccessScope)(p.readScope)) {
61
+ throw new types_js_1.MemoryError("MEMORY_INVALID_INPUT", `unknown readScope '${String(p.readScope)}'`);
62
+ }
63
+ if (!(0, types_js_1.isAccessScope)(p.writeScope)) {
64
+ throw new types_js_1.MemoryError("MEMORY_INVALID_INPUT", `unknown writeScope '${String(p.writeScope)}'`);
65
+ }
66
+ if (!(0, types_js_1.isSharePolicy)(p.sharePolicy)) {
67
+ throw new types_js_1.MemoryError("MEMORY_INVALID_INPUT", `unknown sharePolicy '${String(p.sharePolicy)}'`);
68
+ }
69
+ return { readScope: p.readScope, writeScope: p.writeScope, sharePolicy: p.sharePolicy };
70
+ }
71
+ /** A retentionPolicy is at most 4 KiB of JSON. */
72
+ /** Spec §30.2 `Int`: maxRetentionDays is 1..2147483647. */
73
+ exports.MAX_RETENTION_DAYS = 2147483647;
74
+ const RETENTION_FIELDS = ["maxRetentionDays", "autoDeleteOnTermination", "anonymizationSupported"];
75
+ function checkRetentionPolicy(policy) {
76
+ if (policy === null || policy === undefined)
77
+ return null;
78
+ const unknown = typeof policy === "object" ? Object.keys(policy).filter((k) => !RETENTION_FIELDS.includes(k)) : [];
79
+ if (unknown.length > 0) {
80
+ throw new types_js_1.MemoryError("MEMORY_INVALID_INPUT", `unknown retentionPolicy field(s) ${unknown.join(", ")}`);
81
+ }
82
+ const p = policy;
83
+ const days = p.maxRetentionDays;
84
+ if (typeof p !== "object" ||
85
+ !(days === null || (Number.isInteger(days) && days >= 1 && days <= exports.MAX_RETENTION_DAYS)) ||
86
+ typeof p.autoDeleteOnTermination !== "boolean" ||
87
+ typeof p.anonymizationSupported !== "boolean") {
88
+ throw new types_js_1.MemoryError("MEMORY_INVALID_INPUT", `retentionPolicy must be {maxRetentionDays: integer 1..${exports.MAX_RETENTION_DAYS} | null, autoDeleteOnTermination: boolean, anonymizationSupported: boolean} or null`);
89
+ }
90
+ return {
91
+ maxRetentionDays: days,
92
+ autoDeleteOnTermination: p.autoDeleteOnTermination,
93
+ anonymizationSupported: p.anonymizationSupported,
94
+ };
95
+ }
96
+ /** RFC 3339 UTC, as timestamps go on the wire. */
97
+ function toTimestamp(ms) {
98
+ return new Date(ms).toISOString();
99
+ }
100
+ // RFC 3339 date-time: full date, full time, seconds, optional fraction, and
101
+ // an explicit offset ("Z" or ±hh:mm). Date.parse alone accepts "2026" and
102
+ // rolls "2026-02-30" over into March.
103
+ const RFC3339 = /^(\d{4})-(\d{2})-(\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(\.\d+)?([Zz]|[+-]\d{2}:\d{2})$/;
104
+ function parseTimestamp(value, field) {
105
+ const bad = () => new types_js_1.MemoryError("MEMORY_INVALID_INPUT", `${field} must be an RFC 3339 timestamp, e.g. 2026-10-30T12:00:00Z`);
106
+ const m = typeof value === "string" ? RFC3339.exec(value) : null;
107
+ if (!m)
108
+ throw bad();
109
+ const [year, month, day, hour, minute, second] = m.slice(1, 7).map(Number);
110
+ const daysInMonth = new Date(Date.UTC(year, month, 0)).getUTCDate();
111
+ if (month < 1 || month > 12 || day < 1 || day > daysInMonth || hour > 23 || minute > 59 || second > 59)
112
+ throw bad();
113
+ const ms = Date.parse(value);
114
+ if (Number.isNaN(ms))
115
+ throw bad();
116
+ return ms;
117
+ }
118
+ function toEntryJson(entry) {
119
+ return { ...entry, value: encodeValue(entry.value) };
120
+ }
121
+ /** Parse an entry received over JSON; refuses anything outside the wire format. */
122
+ function fromEntryJson(json) {
123
+ const j = json;
124
+ if (!j || typeof j !== "object")
125
+ throw new types_js_1.MemoryError("MEMORY_INVALID_INPUT", "entry must be an object");
126
+ if (!(0, types_js_1.isMemoryCategory)(j.category)) {
127
+ throw new types_js_1.MemoryError("MEMORY_INVALID_INPUT", `unknown category '${String(j.category)}'`);
128
+ }
129
+ if (typeof j.entryId !== "string" || !/^[0-9a-f]{64}$/.test(j.entryId)) {
130
+ throw new types_js_1.MemoryError("MEMORY_INVALID_INPUT", "entryId must be 64 lowercase hex characters");
131
+ }
132
+ if (typeof j.createdBy !== "string" || j.createdBy.length === 0) {
133
+ throw new types_js_1.MemoryError("MEMORY_INVALID_INPUT", "createdBy must be a gene id");
134
+ }
135
+ parseTimestamp(j.createdAt, "createdAt");
136
+ parseTimestamp(j.updatedAt, "updatedAt");
137
+ return {
138
+ entryId: j.entryId,
139
+ category: j.category,
140
+ key: checkKey(j.key),
141
+ value: decodeValue(j.value),
142
+ createdBy: j.createdBy,
143
+ lastAccessedBy: typeof j.lastAccessedBy === "string" ? j.lastAccessedBy : null,
144
+ createdAt: j.createdAt,
145
+ updatedAt: j.updatedAt,
146
+ accessPolicy: checkAccessPolicy(j.accessPolicy),
147
+ retentionPolicy: checkRetentionPolicy(j.retentionPolicy),
148
+ };
149
+ }
150
+ const QUOTA_UNITS = { KB: 1024, MB: 1024 ** 2, GB: 1024 ** 3 };
151
+ /**
152
+ * `--memory-quota`: a positive number with a KB / MB /
153
+ * GB suffix (binary units, case-insensitive), e.g. `512KB`, `10MB`, `1.5GB`.
154
+ * Zero, negative and unit-less values are refused rather than guessed.
155
+ */
156
+ function parseMemoryQuota(input) {
157
+ const match = /^\s*(-?\d+(?:\.\d+)?)\s*(KB|MB|GB)\s*$/i.exec(input);
158
+ if (!match) {
159
+ throw new types_js_1.MemoryError("MEMORY_INVALID_INPUT", `memory quota '${input}' is not a size; use a number with KB, MB or GB, e.g. 10MB`);
160
+ }
161
+ const bytes = Math.floor(Number(match[1]) * QUOTA_UNITS[match[2].toUpperCase()]);
162
+ if (!(bytes > 0)) {
163
+ throw new types_js_1.MemoryError("MEMORY_INVALID_INPUT", `memory quota must be greater than zero (got '${input}')`);
164
+ }
165
+ // Past 2^53 a JS number stops counting bytes exactly; the store (u64)
166
+ // would get a different quota from the one asked for.
167
+ if (!Number.isSafeInteger(bytes)) {
168
+ throw new types_js_1.MemoryError("MEMORY_INVALID_INPUT", `memory quota '${input}' is too large`);
169
+ }
170
+ return bytes;
171
+ }
172
+ /**
173
+ * What the quota counts: the UTF-8 bytes of the key and the
174
+ * value's bytes — never JS string length. The retentionPolicy is bounded by
175
+ * its §30.2 schema and not counted.
176
+ */
177
+ function entrySize(key, value) {
178
+ return Buffer.byteLength(key, "utf8") + value.byteLength;
179
+ }
180
+ /** A gene id as a caller's must be: "v2:" and 64 lowercase hex digits. */
181
+ function isV2GeneId(id) {
182
+ return typeof id === "string" && /^v2:[0-9a-f]{64}$/.test(id);
183
+ }
184
+ //# sourceMappingURL=codec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codec.js","sourceRoot":"","sources":["../../src/memory/codec.ts"],"names":[],"mappings":";;;AAkBA,gCAEC;AAOD,kCAEC;AAED,kCAKC;AAKD,4BAWC;AAED,8CAeC;AAOD,oDAwBC;AAGD,kCAEC;AAOD,wCAUC;AAED,kCAEC;AAGD,sCA0BC;AASD,4CAkBC;AAOD,8BAEC;AAGD,gCAEC;AApMD;;;;GAIG;AACH,6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IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,SAAgB,SAAS,CAAC,GAAW,EAAE,KAAiB;IACtD,OAAO,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC,UAAU,CAAC;AAC3D,CAAC;AAED,0EAA0E;AAC1E,SAAgB,UAAU,CAAC,EAAW;IACpC,OAAO,OAAO,EAAE,KAAK,QAAQ,IAAI,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAChE,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Spec §30.2 DataPolicy, and what it allows a gene to write into AgentMemory
3
+ * (spec §38.2 "与数据主权的集成").
4
+ *
5
+ * §30.2 has no field that says "may not write memory", so the checks below
6
+ * are what the declared policy implies for a memory entry:
7
+ * 1. an entry may not be kept longer than the agent's data retention;
8
+ * 2. an entry may not be shareable (ANONYMIZED_SHARE / KNOWLEDGE_GENE)
9
+ * when the agent's data cannot be anonymised — §38.3 makes
10
+ * de-identification a MUST before anything leaves as a knowledge gene;
11
+ * 3. DEPLOYER_CONFIGURED resolves from the DataPolicy, which defines no
12
+ * memory scope (always "not configured", so denied; no
13
+ * field is invented for it).
14
+ * A violation is MEMORY_ACCESS_DENIED.
15
+ */
16
+ import type { MemoryAccessPolicy, RetentionPolicy } from "./types.js";
17
+ export type DataOwner = "DEPLOYER" | "USER" | "AGENT" | {
18
+ SHARED: string[];
19
+ };
20
+ export interface DataPolicy {
21
+ inputDataOwnership: DataOwner;
22
+ outputDataOwnership: DataOwner;
23
+ learningDataOwnership: DataOwner;
24
+ metadataOwnership: DataOwner;
25
+ retentionPolicy: RetentionPolicy;
26
+ deletionSupport: boolean;
27
+ }
28
+ /**
29
+ * What `rotifer agent create` records when the deployer configures nothing
30
+ * (§30.2 says the deployer MUST configure one; this is the explicit
31
+ * default written into the agent record, not an implied one). Learning data
32
+ * — which memory is — belongs to the agent and travels with it (§30.4);
33
+ * retention has no day limit; and nothing claims anonymisation it does not
34
+ * do, so shareable entries are refused until the deployer says otherwise.
35
+ */
36
+ export declare const DEFAULT_DATA_POLICY: Readonly<DataPolicy>;
37
+ /** Why a write breaks the agent's DataPolicy, or null if it does not. */
38
+ export declare function dataPolicyViolation(policy: DataPolicy, accessPolicy: MemoryAccessPolicy, retention: RetentionPolicy | null): string | null;
39
+ //# sourceMappingURL=data-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-policy.d.ts","sourceRoot":"","sources":["../../src/memory/data-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEtE,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,MAAM,GAAG,OAAO,GAAG;IAAE,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAE7E,MAAM,WAAW,UAAU;IACzB,kBAAkB,EAAE,SAAS,CAAC;IAC9B,mBAAmB,EAAE,SAAS,CAAC;IAC/B,qBAAqB,EAAE,SAAS,CAAC;IACjC,iBAAiB,EAAE,SAAS,CAAC;IAC7B,eAAe,EAAE,eAAe,CAAC;IACjC,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,UAAU,CAWrC,CAAC;AAEjB,yEAAyE;AACzE,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,UAAU,EAClB,YAAY,EAAE,kBAAkB,EAChC,SAAS,EAAE,eAAe,GAAG,IAAI,GAChC,MAAM,GAAG,IAAI,CAgBf"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_DATA_POLICY = void 0;
4
+ exports.dataPolicyViolation = dataPolicyViolation;
5
+ /**
6
+ * What `rotifer agent create` records when the deployer configures nothing
7
+ * (§30.2 says the deployer MUST configure one; this is the explicit
8
+ * default written into the agent record, not an implied one). Learning data
9
+ * — which memory is — belongs to the agent and travels with it (§30.4);
10
+ * retention has no day limit; and nothing claims anonymisation it does not
11
+ * do, so shareable entries are refused until the deployer says otherwise.
12
+ */
13
+ exports.DEFAULT_DATA_POLICY = Object.freeze({
14
+ inputDataOwnership: "DEPLOYER",
15
+ outputDataOwnership: "DEPLOYER",
16
+ learningDataOwnership: "AGENT",
17
+ metadataOwnership: "DEPLOYER",
18
+ retentionPolicy: Object.freeze({
19
+ maxRetentionDays: null,
20
+ autoDeleteOnTermination: false,
21
+ anonymizationSupported: false,
22
+ }),
23
+ deletionSupport: true,
24
+ });
25
+ /** Why a write breaks the agent's DataPolicy, or null if it does not. */
26
+ function dataPolicyViolation(policy, accessPolicy, retention) {
27
+ const agentDays = policy.retentionPolicy.maxRetentionDays;
28
+ if (retention && agentDays !== null) {
29
+ if (retention.maxRetentionDays === null || retention.maxRetentionDays > agentDays) {
30
+ return `retentionPolicy keeps the entry ${retention.maxRetentionDays ?? "indefinitely"} day(s); the agent's DataPolicy allows at most ${agentDays}`;
31
+ }
32
+ }
33
+ if (accessPolicy.sharePolicy !== "PRIVATE" && !policy.retentionPolicy.anonymizationSupported) {
34
+ return `sharePolicy ${accessPolicy.sharePolicy} needs a DataPolicy that supports anonymisation (§38.3); this agent's does not`;
35
+ }
36
+ const isDeployerScopeUsed = accessPolicy.readScope === "DEPLOYER_CONFIGURED" || accessPolicy.writeScope === "DEPLOYER_CONFIGURED";
37
+ if (isDeployerScopeUsed) {
38
+ return "DEPLOYER_CONFIGURED resolves from the agent's DataPolicy (§30.2), which defines no memory scope yet, so it is treated as not configured";
39
+ }
40
+ return null;
41
+ }
42
+ //# sourceMappingURL=data-policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-policy.js","sourceRoot":"","sources":["../../src/memory/data-policy.ts"],"names":[],"mappings":";;;AAkDA,kDAoBC;AA1CD;;;;;;;GAOG;AACU,QAAA,mBAAmB,GAAyB,MAAM,CAAC,MAAM,CAAC;IACrE,kBAAkB,EAAE,UAAU;IAC9B,mBAAmB,EAAE,UAAU;IAC/B,qBAAqB,EAAE,OAAO;IAC9B,iBAAiB,EAAE,UAAU;IAC7B,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC;QAC7B,gBAAgB,EAAE,IAAI;QACtB,uBAAuB,EAAE,KAAK;QAC9B,sBAAsB,EAAE,KAAK;KAC9B,CAAC;IACF,eAAe,EAAE,IAAI;CACtB,CAAe,CAAC;AAEjB,yEAAyE;AACzE,SAAgB,mBAAmB,CACjC,MAAkB,EAClB,YAAgC,EAChC,SAAiC;IAEjC,MAAM,SAAS,GAAG,MAAM,CAAC,eAAe,CAAC,gBAAgB,CAAC;IAC1D,IAAI,SAAS,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;QACpC,IAAI,SAAS,CAAC,gBAAgB,KAAK,IAAI,IAAI,SAAS,CAAC,gBAAgB,GAAG,SAAS,EAAE,CAAC;YAClF,OAAO,mCAAmC,SAAS,CAAC,gBAAgB,IAAI,cAAc,kDAAkD,SAAS,EAAE,CAAC;QACtJ,CAAC;IACH,CAAC;IACD,IAAI,YAAY,CAAC,WAAW,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,sBAAsB,EAAE,CAAC;QAC7F,OAAO,eAAe,YAAY,CAAC,WAAW,gFAAgF,CAAC;IACjI,CAAC;IACD,MAAM,mBAAmB,GACvB,YAAY,CAAC,SAAS,KAAK,qBAAqB,IAAI,YAAY,CAAC,UAAU,KAAK,qBAAqB,CAAC;IACxG,IAAI,mBAAmB,EAAE,CAAC;QACxB,OAAO,yIAAyI,CAAC;IACnJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,119 @@
1
+ import { type NativeBinding } from "../utils/binding.js";
2
+ import { type GeneMemoryAccess } from "./access.js";
3
+ import { type MemoryAuditSink } from "./audit.js";
4
+ import { type MemoryBackend, type NativeMemoryApi } from "./backend.js";
5
+ import { type DataPolicy } from "./data-policy.js";
6
+ import { type MemoryTelemetrySink } from "./telemetry.js";
7
+ /** The memory fields of an agent record (`.rotifer/agents/<id>.json`). */
8
+ export interface AgentMemoryFields {
9
+ id: string;
10
+ /** Bytes; absent on agents created before v0.9.4 → the 10 MB default. */
11
+ memoryQuota?: number;
12
+ /** §30.2; absent on agents created before v0.9.4 → DEFAULT_DATA_POLICY. */
13
+ dataPolicy?: DataPolicy;
14
+ }
15
+ export declare function memoryQuotaOf(agent: AgentMemoryFields): number;
16
+ /**
17
+ * The calling gene's content-derived id (the v0.9.1 v2 id).
18
+ * There is no fallback: an entry's `createdBy` is what CREATOR_GENE_ONLY
19
+ * compares, and a second id scheme would make the same gene two creators.
20
+ */
21
+ export declare function geneIdentity(genesRoot: string, geneName: string): string;
22
+ /**
23
+ * rotifer-napi's memory, on a PlaygroundBinding opened on the project
24
+ * (store: `<root>/.rotifer/playground.db`), or null when the loaded addon has
25
+ * no memory functions. tryLoadBinding() opens its own instance under the
26
+ * user's home for other purposes; memory belongs to the project, so this
27
+ * opens another instance of the same class on the project root.
28
+ */
29
+ export declare function projectNativeMemory(root: string): (NativeMemoryApi & NativeBinding) | null;
30
+ /**
31
+ * What the WASM path needs for a gene's memory calls: a binding
32
+ * opened on the project — the one tryLoadBinding() returns lives under the
33
+ * user's home, and its store is not the agent's — and the memoryContext JSON
34
+ * rotifer-napi takes.
35
+ */
36
+ export interface WasmMemory {
37
+ binding: NativeBinding;
38
+ /** For executeGene: {"agentId","geneId"}; a gene without a v2 id gets {"agentId"} alone, and its calls are denied. */
39
+ geneContext(geneName: string): string;
40
+ /** For executeAlgebra: {"agentId"}; each gene runs as its entry's v2Id. */
41
+ agentContext: string;
42
+ }
43
+ /**
44
+ * Make sure the agent's memory exists in the native store, with its quota
45
+ * (`agent create`, and first use by an agent created before v0.9.4).
46
+ * Returns false when there is no native store to create it in.
47
+ */
48
+ export declare function ensureAgentMemory(native: NativeMemoryApi | null, agent: AgentMemoryFields): boolean;
49
+ export interface OpenGeneMemoryOptions {
50
+ /** Project root (where `.rotifer/` lives). */
51
+ root: string;
52
+ agent: AgentMemoryFields;
53
+ gene: {
54
+ id: string;
55
+ domain: string;
56
+ };
57
+ /** The store. Omitted → rotifer-napi's on this project, or none (memoryUnavailable). */
58
+ backend?: MemoryBackend;
59
+ telemetry?: MemoryTelemetrySink;
60
+ audit?: MemoryAuditSink;
61
+ }
62
+ /** A GeneMemoryAccess for `gene` inside `agent`. */
63
+ export declare function openGeneMemory(options: OpenGeneMemoryOptions): GeneMemoryAccess;
64
+ export interface AgentMemoryHandle {
65
+ /** "napi" (rotifer-core's store) or "unavailable" (no native memory: every call fails). */
66
+ store: "napi" | "unavailable";
67
+ /** The WASM path's binding and memoryContext; null without native memory, or when the store cannot execute genes. */
68
+ wasm: WasmMemory | null;
69
+ /** GeneMemoryAccess for one gene of the agent. Never undefined: a gene it cannot identify gets one that refuses, saying why. */
70
+ forGene(geneName: string, phenotype: {
71
+ domain?: unknown;
72
+ }): GeneMemoryAccess;
73
+ /** The same, for a host that already holds the caller's v2 gene id and domain. */
74
+ forCaller(geneId: string, domain: string): GeneMemoryAccess;
75
+ }
76
+ /**
77
+ * An agent's memory for one `agent run` (spec §38.2; Node path ctx.memory),
78
+ * in rotifer-napi's store on this project — created there on first use with
79
+ * the agent's quota. Without native memory every call fails with
80
+ * MEMORY_STORAGE_ERROR. Tests pass `native` to pin the store.
81
+ */
82
+ export declare function openAgentMemory(options: {
83
+ root: string;
84
+ genesRoot: string;
85
+ agent: AgentMemoryFields;
86
+ native?: NativeMemoryApi | null;
87
+ telemetry?: MemoryTelemetrySink;
88
+ audit?: MemoryAuditSink;
89
+ }): AgentMemoryHandle;
90
+ /**
91
+ * A throwaway agent memory for `rotifer test`, so a gene author can test a
92
+ * gene that uses memory: rotifer-napi's store in a fresh directory under the
93
+ * system temp dir, for a one-off agent with the default quota — as ctx.memory
94
+ * for the Node path, and as a binding + memoryContext for the WASM path.
95
+ * `dispose()` removes the directory. Without native memory every call is
96
+ * MEMORY_STORAGE_ERROR, as anywhere else.
97
+ */
98
+ export declare function scratchGeneMemory(options: {
99
+ genesRoot: string;
100
+ geneName: string;
101
+ phenotype: {
102
+ domain?: unknown;
103
+ };
104
+ /** Tests pin the store; omitted → rotifer-napi's, if the addon has memory. */
105
+ openNative?: (dir: string) => NativeMemoryApi | null;
106
+ }): {
107
+ memory: GeneMemoryAccess;
108
+ wasm: WasmMemory | null;
109
+ dispose(): void;
110
+ };
111
+ /**
112
+ * `rotifer run`'s memory for the gene in `geneDir`: no agent, so every call
113
+ * is refused "no agent context", and each refusal is reported to the
114
+ * project's .rotifer/telemetry.jsonl (honouring ROTIFER_TELEMETRY / DO_NOT_TRACK)
115
+ * with agentId null and the gene's v2 id when it has one — the record
116
+ * rotifer-core makes for a WASM gene run the same way.
117
+ */
118
+ export declare function projectNoAgentMemory(root: string, geneDir: string): GeneMemoryAccess;
119
+ //# sourceMappingURL=host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../../src/memory/host.ts"],"names":[],"mappings":"AAqBA,OAAO,EAA4B,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAA0B,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAiB,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EAAqD,KAAK,aAAa,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAC3H,OAAO,EAAuB,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAqB,KAAK,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAI7E,0EAA0E;AAC1E,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,yEAAyE;IACzE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2EAA2E;IAC3E,UAAU,CAAC,EAAE,UAAU,C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,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,gBAAgB,CAAC;IAC7E,kFAAkF;IAClF,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,gBAAgB,CAAC;CAC7D;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,iBAAiB,CAAC;IACzB,MAAM,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IAChC,SAAS,CAAC,EAAE,mBAAmB,CAAC;IAChC,KAAK,CAAC,EAAE,eAAe,CAAC;CACzB,GAAG,iBAAiB,CAsCpB;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IAChC,8EAA8E;IAC9E,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,eAAe,GAAG,IAAI,CAAC;CACtD,GAAG;IAAE,MAAM,EAAE,gBAAgB,CAAC;IAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC;IAAC,OAAO,IAAI,IAAI,CAAA;CAAE,CAsBzE;AAoBD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAGpF"}
@@ -0,0 +1,226 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.memoryQuotaOf = memoryQuotaOf;
4
+ exports.geneIdentity = geneIdentity;
5
+ exports.projectNativeMemory = projectNativeMemory;
6
+ exports.ensureAgentMemory = ensureAgentMemory;
7
+ exports.openGeneMemory = openGeneMemory;
8
+ exports.openAgentMemory = openAgentMemory;
9
+ exports.scratchGeneMemory = scratchGeneMemory;
10
+ exports.projectNoAgentMemory = projectNoAgentMemory;
11
+ /**
12
+ * The CLI's side of AgentMemory (spec §38.2): opening an agent's memory in
13
+ * rotifer-napi's store and binding it to one gene, for the Node path
14
+ * (ctx.memory) and the WASM path (a binding + memoryContext).
15
+ *
16
+ * Memory belongs to the agent (§38.1): it is keyed by the agent id, and
17
+ * nothing here looks at the agent's genome, so replacing genes neither
18
+ * deletes nor rewrites it.
19
+ *
20
+ * The store is rotifer-napi's, in the project's `.rotifer/playground.db`
21
+ *. Without the native binding there is no memory: every call
22
+ * fails with MEMORY_STORAGE_ERROR "native binding unavailable". There is no
23
+ * fallback store.
24
+ *
25
+ * Not part of `@rotifer/playground/memory`: these signatures carry the
26
+ * native binding's types.
27
+ */
28
+ const node_fs_1 = require("node:fs");
29
+ const node_os_1 = require("node:os");
30
+ const node_path_1 = require("node:path");
31
+ const node_crypto_1 = require("node:crypto");
32
+ const binding_js_1 = require("../utils/binding.js");
33
+ const access_js_1 = require("./access.js");
34
+ const audit_js_1 = require("./audit.js");
35
+ const backend_js_1 = require("./backend.js");
36
+ const data_policy_js_1 = require("./data-policy.js");
37
+ const telemetry_js_1 = require("./telemetry.js");
38
+ const types_js_1 = require("./types.js");
39
+ const index_js_1 = require("./index.js");
40
+ function memoryQuotaOf(agent) {
41
+ return agent.memoryQuota ?? types_js_1.DEFAULT_MEMORY_QUOTA_BYTES;
42
+ }
43
+ /**
44
+ * The calling gene's content-derived id (the v0.9.1 v2 id).
45
+ * There is no fallback: an entry's `createdBy` is what CREATOR_GENE_ONLY
46
+ * compares, and a second id scheme would make the same gene two creators.
47
+ */
48
+ function geneIdentity(genesRoot, geneName) {
49
+ const result = (0, binding_js_1.geneIdV2)(genesRoot, geneName);
50
+ if ("reason" in result) {
51
+ throw new types_js_1.MemoryError("MEMORY_INVALID_INPUT", `gene '${geneName}' has no content-derived id, so it cannot use agent memory: ${result.reason}`);
52
+ }
53
+ return result.id;
54
+ }
55
+ /**
56
+ * rotifer-napi's memory, on a PlaygroundBinding opened on the project
57
+ * (store: `<root>/.rotifer/playground.db`), or null when the loaded addon has
58
+ * no memory functions. tryLoadBinding() opens its own instance under the
59
+ * user's home for other purposes; memory belongs to the project, so this
60
+ * opens another instance of the same class on the project root.
61
+ */
62
+ function projectNativeMemory(root) {
63
+ const loaded = (0, binding_js_1.tryLoadBinding)();
64
+ if (!loaded || !(0, backend_js_1.hasNativeMemory)(loaded) || typeof loaded.constructor !== "function")
65
+ return null;
66
+ const binding = new loaded.constructor(root);
67
+ return (0, backend_js_1.hasNativeMemory)(binding) ? binding : null;
68
+ }
69
+ /**
70
+ * Make sure the agent's memory exists in the native store, with its quota
71
+ * (`agent create`, and first use by an agent created before v0.9.4).
72
+ * Returns false when there is no native store to create it in.
73
+ */
74
+ function ensureAgentMemory(native, agent) {
75
+ if (!native)
76
+ return false;
77
+ try {
78
+ native.memoryGet(agent.id);
79
+ }
80
+ catch (err) {
81
+ const e = (0, backend_js_1.asMemoryError)(err);
82
+ if (e.code !== "MEMORY_NOT_FOUND")
83
+ throw e;
84
+ try {
85
+ native.memoryCreate(agent.id, memoryQuotaOf(agent));
86
+ // Entries with no retentionPolicy of their own inherit the agent's
87
+ // DataPolicy retention; unlimited needs no call.
88
+ const days = agent.dataPolicy?.retentionPolicy.maxRetentionDays ?? null;
89
+ if (days !== null)
90
+ native.memorySetDataPolicyRetention(agent.id, days);
91
+ }
92
+ catch (createErr) {
93
+ throw (0, backend_js_1.asMemoryError)(createErr);
94
+ }
95
+ }
96
+ return true;
97
+ }
98
+ /** A GeneMemoryAccess for `gene` inside `agent`. */
99
+ function openGeneMemory(options) {
100
+ const { root, agent, gene } = options;
101
+ let backend = options.backend;
102
+ if (!backend) {
103
+ const native = projectNativeMemory(root);
104
+ if (!native)
105
+ return (0, index_js_1.memoryUnavailable)();
106
+ ensureAgentMemory(native, agent);
107
+ backend = new backend_js_1.NapiMemoryBackend(native);
108
+ }
109
+ return (0, access_js_1.createGeneMemoryAccess)({
110
+ backend,
111
+ caller: { agentId: agent.id, geneId: gene.id, domain: gene.domain },
112
+ dataPolicy: agent.dataPolicy ?? data_policy_js_1.DEFAULT_DATA_POLICY,
113
+ telemetry: options.telemetry ?? (0, telemetry_js_1.fileTelemetrySink)(root),
114
+ audit: options.audit ?? (0, audit_js_1.fileAuditSink)(root),
115
+ });
116
+ }
117
+ /**
118
+ * An agent's memory for one `agent run` (spec §38.2; Node path ctx.memory),
119
+ * in rotifer-napi's store on this project — created there on first use with
120
+ * the agent's quota. Without native memory every call fails with
121
+ * MEMORY_STORAGE_ERROR. Tests pass `native` to pin the store.
122
+ */
123
+ function openAgentMemory(options) {
124
+ const { root, genesRoot, agent } = options;
125
+ const native = options.native === undefined ? projectNativeMemory(root) : options.native;
126
+ ensureAgentMemory(native, agent);
127
+ const backend = native ? new backend_js_1.NapiMemoryBackend(native) : null;
128
+ const forCaller = (geneId, domain) => backend
129
+ ? openGeneMemory({ root, agent, gene: { id: geneId, domain }, backend, telemetry: options.telemetry, audit: options.audit })
130
+ : (0, index_js_1.memoryUnavailable)();
131
+ const canExecute = native !== null && typeof native.executeGene === "function";
132
+ return {
133
+ store: backend ? "napi" : "unavailable",
134
+ wasm: canExecute
135
+ ? {
136
+ binding: native,
137
+ geneContext(geneName) {
138
+ const id = (0, binding_js_1.geneIdV2)(genesRoot, geneName);
139
+ return JSON.stringify("id" in id ? { agentId: agent.id, geneId: id.id } : { agentId: agent.id });
140
+ },
141
+ agentContext: JSON.stringify({ agentId: agent.id }),
142
+ }
143
+ : null,
144
+ forGene(geneName, phenotype) {
145
+ if (!backend)
146
+ return (0, index_js_1.memoryUnavailable)();
147
+ const domain = typeof phenotype.domain === "string" ? phenotype.domain : "";
148
+ let geneId;
149
+ try {
150
+ geneId = geneIdentity(genesRoot, geneName);
151
+ }
152
+ catch (err) {
153
+ // The store refuses a caller without a v2 id and records it (audit,
154
+ // geneId null, and §17), as rotifer-core does
155
+ // for WASM genes; the refusal tells the author why.
156
+ return explainRefusals(forCaller("", domain), `gene '${geneName}' cannot use agent memory: ${err.message}`);
157
+ }
158
+ return forCaller(geneId, domain);
159
+ },
160
+ forCaller,
161
+ };
162
+ }
163
+ /**
164
+ * A throwaway agent memory for `rotifer test`, so a gene author can test a
165
+ * gene that uses memory: rotifer-napi's store in a fresh directory under the
166
+ * system temp dir, for a one-off agent with the default quota — as ctx.memory
167
+ * for the Node path, and as a binding + memoryContext for the WASM path.
168
+ * `dispose()` removes the directory. Without native memory every call is
169
+ * MEMORY_STORAGE_ERROR, as anywhere else.
170
+ */
171
+ function scratchGeneMemory(options) {
172
+ const dir = (0, node_fs_1.mkdtempSync)((0, node_path_1.join)((0, node_os_1.tmpdir)(), "rotifer-test-memory-"));
173
+ const dispose = () => {
174
+ try {
175
+ (0, node_fs_1.rmSync)(dir, { recursive: true, force: true, maxRetries: 3 });
176
+ }
177
+ catch {
178
+ /* a temp dir; the OS cleans what an open handle kept */
179
+ }
180
+ };
181
+ try {
182
+ const native = (options.openNative ?? projectNativeMemory)(dir);
183
+ if (!native) {
184
+ dispose();
185
+ return { memory: (0, index_js_1.memoryUnavailable)(), wasm: null, dispose: () => { } };
186
+ }
187
+ const agent = { id: `test-${(0, node_crypto_1.randomUUID)()}` };
188
+ const handle = openAgentMemory({ root: dir, genesRoot: options.genesRoot, agent, native });
189
+ return { memory: handle.forGene(options.geneName, options.phenotype), wasm: handle.wasm, dispose };
190
+ }
191
+ catch (err) {
192
+ dispose();
193
+ throw err;
194
+ }
195
+ }
196
+ /** `memory`, whose MEMORY_ACCESS_DENIED refusals carry `why` instead of the store's generic message. */
197
+ function explainRefusals(memory, why) {
198
+ const explain = (call) => {
199
+ try {
200
+ return call();
201
+ }
202
+ catch (err) {
203
+ if (err instanceof types_js_1.MemoryError && err.code === "MEMORY_ACCESS_DENIED")
204
+ throw new types_js_1.MemoryError("MEMORY_ACCESS_DENIED", why);
205
+ throw err;
206
+ }
207
+ };
208
+ return {
209
+ readMemory: (...args) => explain(() => memory.readMemory(...args)),
210
+ writeMemory: (...args) => explain(() => memory.writeMemory(...args)),
211
+ queryMemory: (...args) => explain(() => memory.queryMemory(...args)),
212
+ deleteMemory: (...args) => explain(() => memory.deleteMemory(...args)),
213
+ };
214
+ }
215
+ /**
216
+ * `rotifer run`'s memory for the gene in `geneDir`: no agent, so every call
217
+ * is refused "no agent context", and each refusal is reported to the
218
+ * project's .rotifer/telemetry.jsonl (honouring ROTIFER_TELEMETRY / DO_NOT_TRACK)
219
+ * with agentId null and the gene's v2 id when it has one — the record
220
+ * rotifer-core makes for a WASM gene run the same way.
221
+ */
222
+ function projectNoAgentMemory(root, geneDir) {
223
+ const id = (0, binding_js_1.geneIdV2)((0, node_path_1.dirname)(geneDir), (0, node_path_1.basename)(geneDir));
224
+ return (0, index_js_1.noAgentMemory)({ telemetry: (0, telemetry_js_1.fileTelemetrySink)(root), geneId: "id" in id ? id.id : null });
225
+ }
226
+ //# sourceMappingURL=host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.js","sourceRoot":"","sources":["../../src/memory/host.ts"],"names":[],"mappings":";;AAuCA,sCAEC;AAOD,oCASC;AASD,kDAKC;AAqBD,8CAkBC;AAcD,wCAgBC;AAmBD,0CA6CC;AAUD,8CA4BC;AA2BD,oDAGC;AAhRD;;;;;;;;;;;;;;;;GAgBG;AACH,qCAA8C;AAC9C,qCAAiC;AACjC,yCAAoD;AACpD,6CAAyC;AACzC,oDAAmF;AACnF,2CAA4E;AAC5E,yCAAiE;AACjE,6CAA2H;AAC3H,qDAAwE;AACxE,iDAA6E;AAC7E,yCAAqE;AACrE,yCAA8D;AAW9D,SAAgB,aAAa,CAAC,KAAwB;IACpD,OAAO,KAAK,CAAC,WAAW,IAAI,qCAA0B,CAAC;AACzD,CAAC;AAED;;;;GAIG;AACH,SAAgB,YAAY,CAAC,SAAiB,EAAE,QAAgB;IAC9D,MAAM,MAAM,GAAG,IAAA,qBAAQ,EAAC,SAAS,EAAE,QAAQ,CAAC,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