@framers/agentos 0.13.3 → 0.13.4

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 (87) hide show
  1. package/dist/cognition/emergent/EffectsStore.d.ts +6 -1
  2. package/dist/cognition/emergent/EffectsStore.d.ts.map +1 -1
  3. package/dist/cognition/emergent/EffectsStore.js.map +1 -1
  4. package/dist/cognition/emergent/EmergentCapabilityEngine.d.ts +8 -0
  5. package/dist/cognition/emergent/EmergentCapabilityEngine.d.ts.map +1 -1
  6. package/dist/cognition/emergent/EmergentCapabilityEngine.js +84 -9
  7. package/dist/cognition/emergent/EmergentCapabilityEngine.js.map +1 -1
  8. package/dist/cognition/emergent/EmergentJudge.d.ts.map +1 -1
  9. package/dist/cognition/emergent/EmergentJudge.js +8 -1
  10. package/dist/cognition/emergent/EmergentJudge.js.map +1 -1
  11. package/dist/cognition/emergent/ForgeToolMetaTool.d.ts +2 -1
  12. package/dist/cognition/emergent/ForgeToolMetaTool.d.ts.map +1 -1
  13. package/dist/cognition/emergent/ForgeToolMetaTool.js +27 -4
  14. package/dist/cognition/emergent/ForgeToolMetaTool.js.map +1 -1
  15. package/dist/cognition/emergent/SandboxedToolForge.d.ts +7 -3
  16. package/dist/cognition/emergent/SandboxedToolForge.d.ts.map +1 -1
  17. package/dist/cognition/emergent/SandboxedToolForge.js +21 -8
  18. package/dist/cognition/emergent/SandboxedToolForge.js.map +1 -1
  19. package/dist/cognition/emergent/broker/CapabilityBroker.d.ts +56 -18
  20. package/dist/cognition/emergent/broker/CapabilityBroker.d.ts.map +1 -1
  21. package/dist/cognition/emergent/broker/CapabilityBroker.js +309 -47
  22. package/dist/cognition/emergent/broker/CapabilityBroker.js.map +1 -1
  23. package/dist/cognition/emergent/broker/dry-run.d.ts +39 -0
  24. package/dist/cognition/emergent/broker/dry-run.d.ts.map +1 -0
  25. package/dist/cognition/emergent/broker/dry-run.js +88 -0
  26. package/dist/cognition/emergent/broker/dry-run.js.map +1 -0
  27. package/dist/cognition/emergent/broker/fetch.d.ts +30 -7
  28. package/dist/cognition/emergent/broker/fetch.d.ts.map +1 -1
  29. package/dist/cognition/emergent/broker/fetch.js +69 -9
  30. package/dist/cognition/emergent/broker/fetch.js.map +1 -1
  31. package/dist/cognition/emergent/broker/fs-write.d.ts +73 -0
  32. package/dist/cognition/emergent/broker/fs-write.d.ts.map +1 -0
  33. package/dist/cognition/emergent/broker/fs-write.js +268 -0
  34. package/dist/cognition/emergent/broker/fs-write.js.map +1 -0
  35. package/dist/cognition/emergent/broker/protected.d.ts +19 -0
  36. package/dist/cognition/emergent/broker/protected.d.ts.map +1 -0
  37. package/dist/cognition/emergent/broker/protected.js +89 -0
  38. package/dist/cognition/emergent/broker/protected.js.map +1 -0
  39. package/dist/cognition/emergent/capabilities.d.ts +2 -0
  40. package/dist/cognition/emergent/capabilities.d.ts.map +1 -1
  41. package/dist/cognition/emergent/capabilities.js +12 -2
  42. package/dist/cognition/emergent/capabilities.js.map +1 -1
  43. package/dist/cognition/emergent/ceiling.d.ts +38 -3
  44. package/dist/cognition/emergent/ceiling.d.ts.map +1 -1
  45. package/dist/cognition/emergent/ceiling.js +119 -2
  46. package/dist/cognition/emergent/ceiling.js.map +1 -1
  47. package/dist/cognition/emergent/executor/QuickJSExecutor.d.ts +1 -1
  48. package/dist/cognition/emergent/executor/QuickJSExecutor.d.ts.map +1 -1
  49. package/dist/cognition/emergent/executor/QuickJSExecutor.js +45 -15
  50. package/dist/cognition/emergent/executor/QuickJSExecutor.js.map +1 -1
  51. package/dist/cognition/emergent/executor/guest-prelude.d.ts.map +1 -1
  52. package/dist/cognition/emergent/executor/guest-prelude.js +48 -17
  53. package/dist/cognition/emergent/executor/guest-prelude.js.map +1 -1
  54. package/dist/cognition/emergent/executor/guest-surface.d.ts.map +1 -1
  55. package/dist/cognition/emergent/executor/guest-surface.js +18 -5
  56. package/dist/cognition/emergent/executor/guest-surface.js.map +1 -1
  57. package/dist/cognition/emergent/persisted-source.d.ts.map +1 -1
  58. package/dist/cognition/emergent/persisted-source.js +7 -1
  59. package/dist/cognition/emergent/persisted-source.js.map +1 -1
  60. package/dist/cognition/emergent/types.d.ts +117 -6
  61. package/dist/cognition/emergent/types.d.ts.map +1 -1
  62. package/dist/cognition/emergent/types.js.map +1 -1
  63. package/dist/core/tools/ITool.d.ts +12 -2
  64. package/dist/core/tools/ITool.d.ts.map +1 -1
  65. package/dist/io/hearing/LiveKitTranscriptionOutput.d.ts +95 -0
  66. package/dist/io/hearing/LiveKitTranscriptionOutput.d.ts.map +1 -0
  67. package/dist/io/hearing/LiveKitTranscriptionOutput.js +108 -0
  68. package/dist/io/hearing/LiveKitTranscriptionOutput.js.map +1 -0
  69. package/dist/io/hearing/livekit.d.ts +15 -0
  70. package/dist/io/hearing/livekit.d.ts.map +1 -0
  71. package/dist/io/hearing/livekit.js +15 -0
  72. package/dist/io/hearing/livekit.js.map +1 -0
  73. package/dist/io/voice-pipeline/browser.d.ts +19 -0
  74. package/dist/io/voice-pipeline/browser.d.ts.map +1 -0
  75. package/dist/io/voice-pipeline/browser.js +20 -0
  76. package/dist/io/voice-pipeline/browser.js.map +1 -0
  77. package/dist/io/voice-pipeline/index.d.ts +1 -0
  78. package/dist/io/voice-pipeline/index.d.ts.map +1 -1
  79. package/dist/io/voice-pipeline/index.js +1 -0
  80. package/dist/io/voice-pipeline/index.js.map +1 -1
  81. package/dist/io/voice-pipeline/transcriptLedger.d.ts +139 -0
  82. package/dist/io/voice-pipeline/transcriptLedger.d.ts.map +1 -0
  83. package/dist/io/voice-pipeline/transcriptLedger.js +192 -0
  84. package/dist/io/voice-pipeline/transcriptLedger.js.map +1 -0
  85. package/dist/io/voice-pipeline/types.d.ts +27 -0
  86. package/dist/io/voice-pipeline/types.d.ts.map +1 -1
  87. package/package.json +11 -1
@@ -0,0 +1,268 @@
1
+ /**
2
+ * @fileoverview The broker's `fs.writeFile` and `fs.unlink` for code-forged
3
+ * tools under a ceiling: the path checks against the roots (lexical, then
4
+ * the parent's real path, then the last component), and the operations. A
5
+ * write opens its file with an exclusive create and no signal, so the broker
6
+ * always knows whether it made the file, and writes through the handle in
7
+ * chunks, checking the call's signal and its own time bound between them: a
8
+ * cut write closes the handle and removes what it made. A removal or a
9
+ * rename, once started, runs to its end. Node has no `openat`, so a process
10
+ * that swaps a parent directory for a link between the check and the open is
11
+ * outside what these checks stop; and an exclusive create on a network file
12
+ * system that does not honour it is too. The documentation says both.
13
+ * @module @framers/agentos/emergent/broker/fs-write
14
+ */
15
+ import { lstat, open, realpath, rename, unlink } from 'node:fs/promises';
16
+ import * as path from 'node:path';
17
+ import { withinRoots } from './fs-read.js';
18
+ import { isProtectedRoot } from './protected.js';
19
+ import { CapabilityRefusal } from './refusal.js';
20
+ /** The bytes a write hands the file system at once; the call's signal is checked between them. */
21
+ const CHUNK_BYTES = 64 * 1024;
22
+ /**
23
+ * An effect cut by the call's end or by its own time bound before it was
24
+ * done. `fileLeft` is set when the broker could not remove a file it made.
25
+ */
26
+ export class EffectCut extends CapabilityRefusal {
27
+ constructor(outcome, detail, fileLeft = false) {
28
+ super(fileLeft ? 'file_left' : outcome, detail);
29
+ this.outcome = outcome;
30
+ this.fileLeft = fileLeft;
31
+ }
32
+ }
33
+ /**
34
+ * Write or delete roots, each root's real path resolved lazily and pinned,
35
+ * as the broker's read roots are. A root whose real path is protected (see
36
+ * protected.ts) is set apart when it resolves: a target under it is refused
37
+ * with `protected_path`, whether the root existed at construction or not.
38
+ */
39
+ export class EffectRoots {
40
+ constructor(roots, protectedReal) {
41
+ this.roots = roots;
42
+ this.protectedReal = protectedReal;
43
+ this.cache = new Map();
44
+ this.guarded = new Set();
45
+ }
46
+ /** The roots' real paths, the protected ones set apart. */
47
+ async real() {
48
+ const allowed = [];
49
+ for (const root of this.roots) {
50
+ const real = await this.realOf(root);
51
+ if (real !== undefined && !this.guarded.has(real)) {
52
+ allowed.push(real);
53
+ }
54
+ }
55
+ return { allowed, guarded: [...this.guarded] };
56
+ }
57
+ realOf(root) {
58
+ const cached = this.cache.get(root);
59
+ if (cached !== undefined) {
60
+ return cached;
61
+ }
62
+ const pending = realpath(root).then((real) => {
63
+ if (isProtectedRoot(real, this.protectedReal)) {
64
+ this.guarded.add(real);
65
+ }
66
+ return real;
67
+ }, () => {
68
+ // A root that does not resolve yet grants nothing until it does.
69
+ this.cache.delete(root);
70
+ return undefined;
71
+ });
72
+ this.cache.set(root, pending);
73
+ return pending;
74
+ }
75
+ }
76
+ /** What the run's view says of a path: the overlay first in a dry run, then the real tree. */
77
+ async function kindOf(target, overlay) {
78
+ const seen = overlay?.look(target);
79
+ if (seen === 'file') {
80
+ return 'file';
81
+ }
82
+ if (seen === 'absent') {
83
+ return 'absent';
84
+ }
85
+ try {
86
+ const stats = await lstat(target);
87
+ return stats.isFile() ? 'file' : 'other';
88
+ }
89
+ catch (error) {
90
+ if (error.code === 'ENOENT') {
91
+ return 'absent';
92
+ }
93
+ throw error;
94
+ }
95
+ }
96
+ /**
97
+ * The path checks of a write or a delete, in order: a path string; the path
98
+ * resolved as a read's is (against the process's working directory) and
99
+ * checked against the roots; the real path of its parent checked against the
100
+ * roots' real paths, the parent having to exist (no directory is made).
101
+ * Returns the target as written: the parent's real path and the last
102
+ * component.
103
+ */
104
+ async function checkPath(filePath, roots, functionName) {
105
+ if (typeof filePath !== 'string') {
106
+ throw new CapabilityRefusal('invalid_path', `${functionName} takes a path string`);
107
+ }
108
+ const resolved = path.resolve(filePath);
109
+ if (!withinRoots(resolved, roots.roots)) {
110
+ throw new CapabilityRefusal('path_not_allowed', resolved);
111
+ }
112
+ const name = path.basename(resolved);
113
+ if (name === '' || resolved === path.parse(resolved).root) {
114
+ throw new CapabilityRefusal('not_a_file', resolved);
115
+ }
116
+ let parent;
117
+ try {
118
+ parent = await realpath(path.dirname(resolved));
119
+ }
120
+ catch (error) {
121
+ const code = error.code;
122
+ if (code === 'ENOENT' || code === 'ENOTDIR') {
123
+ throw new CapabilityRefusal('no_such_directory', path.dirname(resolved));
124
+ }
125
+ throw error;
126
+ }
127
+ const { allowed, guarded } = await roots.real();
128
+ if (withinRoots(parent, guarded)) {
129
+ throw new CapabilityRefusal('protected_path', `${resolved} is under a protected root`);
130
+ }
131
+ if (!withinRoots(parent, allowed)) {
132
+ throw new CapabilityRefusal('path_not_allowed', `${resolved} resolves outside the roots`);
133
+ }
134
+ return path.join(parent, name);
135
+ }
136
+ /**
137
+ * A write's scope: the path checks, then the last component, which may
138
+ * exist only as a regular file, and under `create-only` not at all.
139
+ */
140
+ export async function checkWrite(filePath, roots, mode, overlay) {
141
+ const target = await checkPath(filePath, roots, 'fs.writeFile');
142
+ const kind = await kindOf(target, overlay);
143
+ if (kind === 'other') {
144
+ throw new CapabilityRefusal('not_a_file', target);
145
+ }
146
+ if (kind === 'file' && mode === 'create-only') {
147
+ throw new CapabilityRefusal('file_exists', target);
148
+ }
149
+ return target;
150
+ }
151
+ /** A delete's scope: the path checks, then the last component, which must be a regular file. */
152
+ export async function checkDelete(filePath, roots, overlay) {
153
+ const target = await checkPath(filePath, roots, 'fs.unlink');
154
+ const kind = await kindOf(target, overlay);
155
+ if (kind === 'absent') {
156
+ throw new CapabilityRefusal('no_such_file', target);
157
+ }
158
+ if (kind === 'other') {
159
+ throw new CapabilityRefusal('not_a_file', target);
160
+ }
161
+ return target;
162
+ }
163
+ /** The data a write carries, as bytes: a string is written as UTF-8. */
164
+ export function writeBytes(data) {
165
+ if (typeof data === 'string') {
166
+ return Buffer.from(data, 'utf8');
167
+ }
168
+ if (data instanceof Uint8Array) {
169
+ return data;
170
+ }
171
+ if (data instanceof ArrayBuffer) {
172
+ return new Uint8Array(data);
173
+ }
174
+ if (ArrayBuffer.isView(data)) {
175
+ return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
176
+ }
177
+ throw new CapabilityRefusal('unsupported_data', 'fs.writeFile takes a string, an ArrayBuffer or a typed array');
178
+ }
179
+ async function removeQuietly(file) {
180
+ try {
181
+ await unlink(file);
182
+ return true;
183
+ }
184
+ catch (error) {
185
+ return error.code === 'ENOENT';
186
+ }
187
+ }
188
+ /**
189
+ * Writes `data` at `target` (already checked). Under `create-only` the
190
+ * target itself is created exclusively; under `create-or-replace` a
191
+ * temporary file beside it, named for the call, is created exclusively and
192
+ * then renamed over the target. A cut (the call's `signal`, or the effect's
193
+ * `timer`, started when the effect was admitted) that arrives while the open
194
+ * runs takes effect once the open settles.
195
+ */
196
+ export async function writeAt(target, data, mode, callId, signal, timer) {
197
+ const cutNow = () => signal.aborted
198
+ ? new EffectCut('aborted', target)
199
+ : timer.aborted
200
+ ? new EffectCut('timed_out', target)
201
+ : undefined;
202
+ const before = cutNow();
203
+ if (before) {
204
+ throw before;
205
+ }
206
+ const file = mode === 'create-only' ? target : path.join(path.dirname(target), `.${path.basename(target)}.${callId}.tmp`);
207
+ let handle;
208
+ try {
209
+ handle = await open(file, 'wx');
210
+ }
211
+ catch (error) {
212
+ if (error.code === 'EEXIST') {
213
+ // Put there between the check and the open.
214
+ throw new CapabilityRefusal('file_exists', file);
215
+ }
216
+ throw error;
217
+ }
218
+ let failure;
219
+ try {
220
+ for (let offset = 0; offset < data.byteLength;) {
221
+ const cut = cutNow();
222
+ if (cut) {
223
+ failure = cut;
224
+ break;
225
+ }
226
+ const { bytesWritten } = await handle.write(data, offset, Math.min(CHUNK_BYTES, data.byteLength - offset));
227
+ offset += bytesWritten;
228
+ }
229
+ }
230
+ catch (error) {
231
+ failure = error;
232
+ }
233
+ finally {
234
+ await handle.close().catch(() => undefined);
235
+ }
236
+ if (failure === undefined && mode === 'create-or-replace') {
237
+ try {
238
+ await rename(file, target);
239
+ }
240
+ catch (error) {
241
+ failure = error;
242
+ }
243
+ }
244
+ if (failure !== undefined) {
245
+ const removed = await removeQuietly(file);
246
+ if (failure instanceof EffectCut) {
247
+ throw removed ? failure : new EffectCut(failure.outcome, `${file} could not be removed`, true);
248
+ }
249
+ throw failure;
250
+ }
251
+ return { bytes: data.byteLength };
252
+ }
253
+ /**
254
+ * Removes `target` (already checked): one directory entry, a regular file.
255
+ * The removal is one system call: the call's `signal` and the effect's
256
+ * `timer` can stop it from starting, and once started it runs to its end.
257
+ */
258
+ export async function removeAt(target, signal, timer) {
259
+ if (signal.aborted) {
260
+ throw new EffectCut('aborted', target);
261
+ }
262
+ if (timer.aborted) {
263
+ throw new EffectCut('timed_out', target);
264
+ }
265
+ await unlink(target);
266
+ return { bytes: 0 };
267
+ }
268
+ //# sourceMappingURL=fs-write.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs-write.js","sourceRoot":"","sources":["../../../../src/cognition/emergent/broker/fs-write.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAmB,MAAM,kBAAkB,CAAC;AAC1F,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,kGAAkG;AAClG,MAAM,WAAW,GAAG,EAAE,GAAG,IAAI,CAAC;AAE9B;;;GAGG;AACH,MAAM,OAAO,SAAU,SAAQ,iBAAiB;IAC9C,YACW,OAAgC,EACzC,MAAc,EACL,WAAoB,KAAK;QAElC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAJvC,YAAO,GAAP,OAAO,CAAyB;QAEhC,aAAQ,GAAR,QAAQ,CAAiB;IAGpC,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,WAAW;IAItB,YACW,KAAwB,EAChB,aAAgC;QADxC,UAAK,GAAL,KAAK,CAAmB;QAChB,kBAAa,GAAb,aAAa,CAAmB;QALlC,UAAK,GAAG,IAAI,G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CAAC;QAC1B,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,IAAI,CAAC,CAAC;QAC1C,IAAI,OAAO,YAAY,SAAS,EAAE,CAAC;YACjC,MAAM,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,IAAI,uBAAuB,EAAE,IAAI,CAAC,CAAC;QACjG,CAAC;QACD,MAAM,OAAO,CAAC;IAChB,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC;AACpC,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,MAAc,EAAE,MAAmB,EAAE,KAAkB;IACpF,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,MAAM,IAAI,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACzC,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;QAClB,MAAM,IAAI,SAAS,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAC3C,CAAC;IACD,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;IACrB,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;AACtB,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @fileoverview The paths no `fs.write` or `fs.delete` root may hold or lie
3
+ * inside: the library's own package directory, the `node_modules` directory
4
+ * it was loaded from, the directory of the process's entry script, and the
5
+ * paths the host lists in `protectedPaths`; and no root may pass through a
6
+ * directory named `node_modules`. The check is partial, and the
7
+ * documentation says so: the library cannot find a host's own code and data
8
+ * in general, so the host lists them.
9
+ * @module @framers/agentos/emergent/broker/protected
10
+ */
11
+ /**
12
+ * The real paths a write or delete root may neither hold nor lie inside,
13
+ * computed once per engine: the library's package directory, the nearest
14
+ * `node_modules` above it, the entry script's directory, and the host's list.
15
+ */
16
+ export declare function protectedRealPaths(hostPaths?: readonly string[]): string[];
17
+ /** A root (by its real path) that holds or lies inside a protected path, or passes through `node_modules`. */
18
+ export declare function isProtectedRoot(realRoot: string, protectedReal: readonly string[]): boolean;
19
+ //# sourceMappingURL=protected.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protected.d.ts","sourceRoot":"","sources":["../../../../src/cognition/emergent/broker/protected.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAiDH;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,GAAE,SAAS,MAAM,EAAO,GAAG,MAAM,EAAE,CAoB9E;AAED,8GAA8G;AAC9G,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAK3F"}
@@ -0,0 +1,89 @@
1
+ /**
2
+ * @fileoverview The paths no `fs.write` or `fs.delete` root may hold or lie
3
+ * inside: the library's own package directory, the `node_modules` directory
4
+ * it was loaded from, the directory of the process's entry script, and the
5
+ * paths the host lists in `protectedPaths`; and no root may pass through a
6
+ * directory named `node_modules`. The check is partial, and the
7
+ * documentation says so: the library cannot find a host's own code and data
8
+ * in general, so the host lists them.
9
+ * @module @framers/agentos/emergent/broker/protected
10
+ */
11
+ import { readFileSync, realpathSync } from 'node:fs';
12
+ import * as path from 'node:path';
13
+ import { fileURLToPath } from 'node:url';
14
+ const PACKAGE_NAME = '@framers/agentos';
15
+ function realOrResolved(candidate) {
16
+ const resolved = path.resolve(candidate);
17
+ try {
18
+ return realpathSync.native(resolved);
19
+ }
20
+ catch {
21
+ return resolved;
22
+ }
23
+ }
24
+ /** Whether `candidate` is `root` or lies under it, by path segments. */
25
+ function within(candidate, root) {
26
+ const relative = path.relative(root, candidate);
27
+ return relative === '' || (relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative));
28
+ }
29
+ /** The directory of the package.json named `@framers/agentos` above this module, if one is found. */
30
+ function libraryRoot() {
31
+ let dir;
32
+ try {
33
+ dir = path.dirname(fileURLToPath(import.meta.url));
34
+ }
35
+ catch {
36
+ return undefined;
37
+ }
38
+ for (let depth = 0; depth < 8; depth += 1) {
39
+ try {
40
+ const manifest = JSON.parse(readFileSync(path.join(dir, 'package.json'), 'utf8'));
41
+ if (manifest.name === PACKAGE_NAME) {
42
+ return dir;
43
+ }
44
+ }
45
+ catch {
46
+ // Not this directory; look one up.
47
+ }
48
+ const parent = path.dirname(dir);
49
+ if (parent === dir) {
50
+ return undefined;
51
+ }
52
+ dir = parent;
53
+ }
54
+ return undefined;
55
+ }
56
+ /**
57
+ * The real paths a write or delete root may neither hold nor lie inside,
58
+ * computed once per engine: the library's package directory, the nearest
59
+ * `node_modules` above it, the entry script's directory, and the host's list.
60
+ */
61
+ export function protectedRealPaths(hostPaths = []) {
62
+ const found = new Set();
63
+ const library = libraryRoot();
64
+ if (library) {
65
+ const real = realOrResolved(library);
66
+ found.add(real);
67
+ const segments = real.split(path.sep);
68
+ const index = segments.lastIndexOf('node_modules');
69
+ if (index > 0) {
70
+ found.add(segments.slice(0, index + 1).join(path.sep));
71
+ }
72
+ }
73
+ const entry = process.argv[1];
74
+ if (typeof entry === 'string' && entry !== '') {
75
+ found.add(path.dirname(realOrResolved(entry)));
76
+ }
77
+ for (const hostPath of hostPaths) {
78
+ found.add(realOrResolved(hostPath));
79
+ }
80
+ return [...found];
81
+ }
82
+ /** A root (by its real path) that holds or lies inside a protected path, or passes through `node_modules`. */
83
+ export function isProtectedRoot(realRoot, protectedReal) {
84
+ if (realRoot.split(path.sep).includes('node_modules')) {
85
+ return true;
86
+ }
87
+ return protectedReal.some((guarded) => within(realRoot, guarded) || within(guarded, realRoot));
88
+ }
89
+ //# sourceMappingURL=protected.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protected.js","sourceRoot":"","sources":["../../../../src/cognition/emergent/broker/protected.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,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IACjD,CAAC;IACD,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC;AACpB,CAAC;AAED,8GAA8G;AAC9G,MAAM,UAAU,eAAe,CAAC,QAAgB,EAAE,aAAgC;IAChF,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;QACtD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;AACjG,CAAC"}
@@ -11,6 +11,8 @@ import type { CapabilityName, SandboxAPI } from './types.js';
11
11
  * has one stored form.
12
12
  */
13
13
  export declare const CAPABILITY_NAMES: readonly CapabilityName[];
14
+ /** The capabilities that change something outside the process: an isolating executor and a ceiling only. */
15
+ export declare const EFFECT_CAPABILITIES: readonly CapabilityName[];
14
16
  /** Names accepted in a request that are not catalogue names. */
15
17
  export declare const CAPABILITY_ALIASES: Readonly<Record<string, CapabilityName>>;
16
18
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../../src/cognition/emergent/capabilities.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7D;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,EAAE,SAAS,cAAc,EAAmC,CAAC;AAE1F,gEAAgE;AAChE,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAEvE,CAAC;AAaF;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG;IAC5D,YAAY,EAAE,cAAc,EAAE,CAAC;IAC/B,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,CAYA;AAED,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,YAAY,EAAE,SAAS,cAAc,EAAE,GAAG,UAAU,EAAE,CAEnF"}
1
+ {"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../../src/cognition/emergent/capabilities.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7D;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,EAAE,SAAS,cAAc,EAA4D,CAAC;AAEnH,4GAA4G;AAC5G,eAAO,MAAM,mBAAmB,EAAE,SAAS,cAAc,EAA8B,CAAC;AAExF,gEAAgE;AAChE,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAIvE,CAAC;AAoBF;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG;IAC5D,YAAY,EAAE,cAAc,EAAE,CAAC;IAC/B,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,CAYA;AAED,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,YAAY,EAAE,SAAS,cAAc,EAAE,GAAG,UAAU,EAAE,CAEnF"}
@@ -9,10 +9,20 @@
9
9
  * its names in this order whatever order a request wrote them in, so one grant
10
10
  * has one stored form.
11
11
  */
12
- export const CAPABILITY_NAMES = ['fetch', 'fs.read', 'crypto'];
12
+ export const CAPABILITY_NAMES = ['fetch', 'fs.read', 'fs.write', 'fs.delete', 'crypto'];
13
+ /** The capabilities that change something outside the process: an isolating executor and a ceiling only. */
14
+ export const EFFECT_CAPABILITIES = ['fs.write', 'fs.delete'];
13
15
  /** Names accepted in a request that are not catalogue names. */
14
16
  export const CAPABILITY_ALIASES = {
15
17
  'fs.readFile': 'fs.read',
18
+ 'fs.writeFile': 'fs.write',
19
+ 'fs.unlink': 'fs.delete',
20
+ };
21
+ /** The function each file capability injects into forged code. */
22
+ const INJECTED = {
23
+ 'fs.read': 'fs.readFile',
24
+ 'fs.write': 'fs.writeFile',
25
+ 'fs.delete': 'fs.unlink',
16
26
  };
17
27
  /** The catalogue name a request's name stands for, or `undefined` for a name outside the catalogue. */
18
28
  function catalogueNameOf(raw) {
@@ -45,6 +55,6 @@ export function normalizeAllowlist(names) {
45
55
  }
46
56
  /** The names `SandboxedToolForge` injects for a set of catalogue names. */
47
57
  export function toSandboxApis(capabilities) {
48
- return capabilities.map((name) => (name === 'fs.read' ? 'fs.readFile' : name));
58
+ return capabilities.map((name) => INJECTED[name] ?? name);
49
59
  }
50
60
  //# sourceMappingURL=capabilities.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../../../src/cognition/emergent/capabilities.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAA8B,CAAC,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;AAE1F,gEAAgE;AAChE,MAAM,CAAC,MAAM,kBAAkB,GAA6C;IAC1E,aAAa,EAAE,SAAS;CACzB,CAAC;AAEF,uGAAuG;AACvG,SAAS,eAAe,CAAC,GAAW;IAClC,0EAA0E;IAC1E,qCAAqC;IACrC,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,kBAAkB,EAAE,GAAG,CAAC;QACzE,CAAC,CAAC,kBAAkB,CAAC,GAAG,CAAC;QACzB,CAAC,CAAC,SAAS,CAAC;IACd,MAAM,IAAI,GAAG,KAAK,IAAI,GAAG,CAAC;IAC1B,OAAQ,gBAAsC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAA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AE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC;AACzF,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,aAAa,CAAC,YAAuC;IACnE,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAK,IAAmB,CAAC,CAAC;AAC5E,CAAC"}
@@ -4,21 +4,41 @@
4
4
  * the check of a host-built forge's options against it.
5
5
  * @module @framers/agentos/emergent/ceiling
6
6
  */
7
- import type { CapabilityName, EmergentAuditConfig, ForgedCapabilities } from './types.js';
7
+ import type { CapabilityName, EffectApproval, EmergentAuditConfig, ForgedCapabilities, HttpMethod } from './types.js';
8
+ /** The methods that change state: an isolating executor, a request bound and an approval setting. */
9
+ export declare const STATE_CHANGING_METHODS: readonly HttpMethod[];
8
10
  /** A ceiling with every default applied and every list normalised. */
9
11
  export interface ResolvedCeiling {
10
12
  fetch?: {
11
13
  domains: string[] | '*';
12
- methods: Array<'GET' | 'HEAD'>;
14
+ methods: HttpMethod[];
13
15
  maxResponseBytes: number;
14
16
  maxRedirects: number;
15
17
  timeoutMs: number;
18
+ /** Set exactly when `methods` holds a state-changing method. */
19
+ maxRequestBytes?: number;
20
+ approval?: EffectApproval;
16
21
  };
17
22
  'fs.read'?: {
18
23
  roots: string[];
19
24
  maxBytesPerRead: number;
20
25
  timeoutMs: number;
21
26
  };
27
+ 'fs.write'?: {
28
+ roots: string[];
29
+ mode: 'create-only' | 'create-or-replace';
30
+ maxBytesPerFile: number;
31
+ maxBytesPerCall: number;
32
+ maxFilesPerCall: number;
33
+ timeoutMs: number;
34
+ approval: EffectApproval;
35
+ };
36
+ 'fs.delete'?: {
37
+ roots: string[];
38
+ maxFilesPerCall: number;
39
+ timeoutMs: number;
40
+ approval: EffectApproval;
41
+ };
22
42
  crypto?: true;
23
43
  audit: {
24
44
  store: 'storage' | 'none';
@@ -26,7 +46,7 @@ export interface ResolvedCeiling {
26
46
  retainDays?: number;
27
47
  };
28
48
  }
29
- export type CeilingErrorCode = 'unknown_capability' | 'root_not_absolute' | 'method_not_allowed' | 'invalid_domain' | 'invalid_bound' | 'invalid_audit' | 'audit_needs_storage' | 'forge_wider_than_ceiling';
49
+ export type CeilingErrorCode = 'unknown_capability' | 'root_not_absolute' | 'method_not_allowed' | 'invalid_domain' | 'invalid_bound' | 'invalid_audit' | 'audit_needs_storage' | 'forge_wider_than_ceiling' | 'invalid_mode' | 'invalid_approval' | 'approval_not_available' | 'executor_does_not_isolate' | 'protected_path';
30
50
  /** A ceiling the engine cannot build; the message starts with the code and the key. */
31
51
  export declare class CeilingError extends Error {
32
52
  readonly code: CeilingErrorCode;
@@ -53,6 +73,21 @@ export declare const CEILING_DEFAULTS: {
53
73
  export declare function resolveCeiling(capabilities: ForgedCapabilities, audit: EmergentAuditConfig | undefined, options: {
54
74
  hasStorage: boolean;
55
75
  }): ResolvedCeiling;
76
+ /**
77
+ * Whether a resolved ceiling grants anything that changes the world outside
78
+ * the process: a write, a delete or a state-changing method. Such a ceiling
79
+ * constructs only on an executor that declares `isolates: true`.
80
+ */
81
+ export declare function grantsEffects(ceiling: ResolvedCeiling): boolean;
82
+ /**
83
+ * Refuses a write or delete root that holds, or lies inside, a protected
84
+ * path, or that passes through a `node_modules` directory. Roots that exist
85
+ * are checked by their real paths now; one that does not exist yet is
86
+ * checked by the broker when its real path is first resolved.
87
+ *
88
+ * @throws CeilingError (`protected_path`) naming the capability's roots key.
89
+ */
90
+ export declare function checkProtectedRoots(ceiling: ResolvedCeiling, protectedReal: readonly string[]): void;
56
91
  /** The capabilities a resolved ceiling grants, in catalogue order. */
57
92
  export declare function grantedCapabilities(ceiling: ResolvedCeiling): CapabilityName[];
58
93
  /** Whether a request (catalogue names) fits the ceiling; a refusal names the rest and what is allowed. */
@@ -1 +1 @@
1
- {"version":3,"file":"ceiling.d.ts","sourceRoot":"","sources":["../../../src/cognition/emergent/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