@clearideas/agent-runtime-store-local 0.5.0 → 0.6.1

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/README.md CHANGED
@@ -1,7 +1,16 @@
1
1
  # @clearideas/agent-runtime-store-local
2
2
 
3
3
  Local adapters for in-memory state, atomic JSON files, JSON/YAML manifest
4
- loading, console and JSONL events, and integrity-checked file artifacts.
4
+ loading, console and JSONL events, integrity-checked file artifacts, and
5
+ directory-backed workspaces.
6
+
7
+ `LocalDirectoryWorkspace` exposes a host directory as a `WorkspaceStore` that
8
+ enumerates and moves opaque bytes only: every path is confined beneath the
9
+ root, symbolic links are never followed, hidden entries are unaddressable,
10
+ include/exclude globs apply to enumeration and reads alike, and sizes are
11
+ bounded. Content is never interpreted here; that happens inside the run
12
+ sandbox. `MemoryWorkspace` provides the same contract in memory for tests and
13
+ ephemeral hosts.
5
14
 
6
15
  `FileRunStore` is for a single process. Atomic replacement prevents partial JSON reads but
7
16
  does not arbitrate concurrent processes. Use `@clearideas/agent-runtime-store-sqlite` or another
package/dist/index.d.ts CHANGED
@@ -4,3 +4,6 @@ export { FileAgentManifestSource } from "./manifest-source.file.js";
4
4
  export { FileAgentRunManifestSource } from "./run-manifest-source.file.js";
5
5
  export { FileRunStore } from "./run-store.file.js";
6
6
  export { MemoryRunStore } from "./run-store.memory.js";
7
+ export { LocalDirectoryWorkspace, type LocalDirectoryWorkspaceOptions, } from "./workspace.directory.js";
8
+ export { MemoryWorkspace, type MemoryWorkspaceOptions, } from "./workspace.memory.js";
9
+ export { compileGlob } from "./workspace-common.js";
package/dist/index.js CHANGED
@@ -4,3 +4,6 @@ export { FileAgentManifestSource } from "./manifest-source.file.js";
4
4
  export { FileAgentRunManifestSource } from "./run-manifest-source.file.js";
5
5
  export { FileRunStore } from "./run-store.file.js";
6
6
  export { MemoryRunStore } from "./run-store.memory.js";
7
+ export { LocalDirectoryWorkspace, } from "./workspace.directory.js";
8
+ export { MemoryWorkspace, } from "./workspace.memory.js";
9
+ export { compileGlob } from "./workspace-common.js";
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Compile a small, deterministic glob dialect to a RegExp: `**` matches any
3
+ * number of path segments, `*` matches within a segment, and `?` matches one
4
+ * character. Patterns are anchored to the complete relative path. Globs are
5
+ * applied to file names only, never to content.
6
+ */
7
+ export declare const compileGlob: (pattern: string) => RegExp;
8
+ export interface WorkspaceVisibility {
9
+ include?: readonly string[] | undefined;
10
+ exclude?: readonly string[] | undefined;
11
+ }
12
+ export declare class WorkspacePathFilter {
13
+ #private;
14
+ constructor(visibility?: WorkspaceVisibility);
15
+ get isUnfiltered(): boolean;
16
+ /** True when a file path may be enumerated, read, written, or deleted. */
17
+ isVisible(relativePath: string): boolean;
18
+ /** True when a directory subtree is excluded as a whole and can be pruned. */
19
+ isDirectoryExcluded(relativeDirectory: string): boolean;
20
+ }
21
+ export declare const positiveInteger: (value: number | undefined, fallback: number, label: string) => number;
22
+ export declare const throwIfAborted: (signal: AbortSignal | undefined) => void;
23
+ export declare const compareNames: (left: string, right: string) => number;
24
+ export declare const DEFAULT_WORKSPACE_MAX_FILES = 5000;
25
+ export declare const DEFAULT_WORKSPACE_MAX_FILE_BYTES = 1048576;
26
+ export declare const DEFAULT_WORKSPACE_MAX_TOTAL_BYTES: number;
@@ -0,0 +1,79 @@
1
+ const MAXIMUM_GLOB_LENGTH = 512;
2
+ const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
3
+ /**
4
+ * Compile a small, deterministic glob dialect to a RegExp: `**` matches any
5
+ * number of path segments, `*` matches within a segment, and `?` matches one
6
+ * character. Patterns are anchored to the complete relative path. Globs are
7
+ * applied to file names only, never to content.
8
+ */
9
+ export const compileGlob = (pattern) => {
10
+ if (!pattern.trim() || pattern.length > MAXIMUM_GLOB_LENGTH) {
11
+ throw new Error(`Invalid workspace glob: ${pattern}`);
12
+ }
13
+ let source = "";
14
+ let index = 0;
15
+ while (index < pattern.length) {
16
+ const character = pattern[index];
17
+ if (character === "*") {
18
+ if (pattern[index + 1] === "*") {
19
+ const followedBySlash = pattern[index + 2] === "/";
20
+ source += followedBySlash ? "(?:.*/)?" : ".*";
21
+ index += followedBySlash ? 3 : 2;
22
+ continue;
23
+ }
24
+ source += "[^/]*";
25
+ index += 1;
26
+ continue;
27
+ }
28
+ if (character === "?") {
29
+ source += "[^/]";
30
+ index += 1;
31
+ continue;
32
+ }
33
+ source += escapeRegExp(character);
34
+ index += 1;
35
+ }
36
+ return new RegExp(`^${source}$`, "u");
37
+ };
38
+ export class WorkspacePathFilter {
39
+ #include;
40
+ #exclude;
41
+ constructor(visibility = {}) {
42
+ this.#include = (visibility.include ?? []).map(compileGlob);
43
+ this.#exclude = (visibility.exclude ?? []).map(compileGlob);
44
+ }
45
+ get isUnfiltered() {
46
+ return this.#include.length === 0 && this.#exclude.length === 0;
47
+ }
48
+ /** True when a file path may be enumerated, read, written, or deleted. */
49
+ isVisible(relativePath) {
50
+ if (this.#exclude.some((pattern) => pattern.test(relativePath)))
51
+ return false;
52
+ return (this.#include.length === 0 ||
53
+ this.#include.some((pattern) => pattern.test(relativePath)));
54
+ }
55
+ /** True when a directory subtree is excluded as a whole and can be pruned. */
56
+ isDirectoryExcluded(relativeDirectory) {
57
+ const probe = `${relativeDirectory}/`;
58
+ return this.#exclude.some((pattern) => pattern.test(probe));
59
+ }
60
+ }
61
+ export const positiveInteger = (value, fallback, label) => {
62
+ if (value == null)
63
+ return fallback;
64
+ if (!Number.isSafeInteger(value) || value <= 0) {
65
+ throw new Error(`${label} must be a positive safe integer.`);
66
+ }
67
+ return value;
68
+ };
69
+ export const throwIfAborted = (signal) => {
70
+ if (!signal?.aborted)
71
+ return;
72
+ throw signal.reason instanceof Error
73
+ ? signal.reason
74
+ : new Error("Workspace operation was aborted");
75
+ };
76
+ export const compareNames = (left, right) => left < right ? -1 : left > right ? 1 : 0;
77
+ export const DEFAULT_WORKSPACE_MAX_FILES = 5_000;
78
+ export const DEFAULT_WORKSPACE_MAX_FILE_BYTES = 1_048_576;
79
+ export const DEFAULT_WORKSPACE_MAX_TOTAL_BYTES = 100 * 1_048_576;
@@ -0,0 +1,54 @@
1
+ import type { WorkspaceMode } from "@clearideas/agent-runtime-contracts";
2
+ import type { WorkspaceEntry, WorkspaceLimits, WorkspaceStore } from "@clearideas/agent-runtime-core";
3
+ export interface LocalDirectoryWorkspaceOptions {
4
+ /** Host directory that becomes the workspace root. */
5
+ root: string;
6
+ /**
7
+ * Explicitly allow a raw read-only directory bind. Defaults to never.
8
+ * auto exposes all directory entries and bypasses store size limits for programs.
9
+ */
10
+ attach?: "auto" | "never";
11
+ /** Defaults to read. */
12
+ mode?: WorkspaceMode;
13
+ /** Glob allowlist over relative file paths. Defaults to every safe path. */
14
+ include?: string[];
15
+ /** Glob denylist over relative file and directory paths. */
16
+ exclude?: string[];
17
+ /** Ceiling on enumerated files. Defaults to 5000. */
18
+ maxFiles?: number;
19
+ /** Ceiling on bytes read or written for one file. Defaults to 1 MiB. */
20
+ maxFileBytes?: number;
21
+ /** Ceiling on total staged bytes, advertised to the run sandbox. Defaults to 100 MiB. */
22
+ maxTotalBytes?: number;
23
+ /** Ceiling on directory entries visited by one enumeration. Defaults to 200000. */
24
+ maxScanEntries?: number;
25
+ }
26
+ /**
27
+ * A workspace backed by a host directory. It enumerates and moves opaque
28
+ * bytes only. Every path is confined beneath the root, symbolic links are
29
+ * never followed, hidden entries are unaddressable, invisible paths are
30
+ * neither enumerated nor readable, and sizes are bounded.
31
+ */
32
+ export declare class LocalDirectoryWorkspace implements WorkspaceStore {
33
+ #private;
34
+ readonly mode: WorkspaceMode;
35
+ readonly limits: WorkspaceLimits;
36
+ readonly attachable?: {
37
+ kind: "local-directory";
38
+ root: string;
39
+ };
40
+ constructor(options: LocalDirectoryWorkspaceOptions);
41
+ get root(): string;
42
+ entries(options?: {
43
+ signal?: AbortSignal;
44
+ }): Promise<WorkspaceEntry[]>;
45
+ read(relativePath: string, options?: {
46
+ signal?: AbortSignal;
47
+ }): Promise<Uint8Array>;
48
+ write(relativePath: string, data: Uint8Array, options?: {
49
+ signal?: AbortSignal;
50
+ }): Promise<WorkspaceEntry>;
51
+ delete(relativePath: string, options?: {
52
+ signal?: AbortSignal;
53
+ }): Promise<void>;
54
+ }
@@ -0,0 +1,209 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { lstat, mkdir, open, readdir, readFile, rename, unlink, } from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { assertWorkspacePath, isSafeWorkspacePath, } from "@clearideas/agent-runtime-core";
5
+ import { DEFAULT_WORKSPACE_MAX_FILE_BYTES, DEFAULT_WORKSPACE_MAX_FILES, DEFAULT_WORKSPACE_MAX_TOTAL_BYTES, WorkspacePathFilter, compareNames, positiveInteger, throwIfAborted, } from "./workspace-common.js";
6
+ const DEFAULT_MAX_SCAN_ENTRIES = 200_000;
7
+ const isMissing = (error) => error?.code === "ENOENT";
8
+ const writeAtomically = async (filePath, data, mode) => {
9
+ const temporaryPath = path.join(path.dirname(filePath), `.${path.basename(filePath)}.${process.pid}.${randomUUID()}.tmp`);
10
+ let handle;
11
+ try {
12
+ handle = await open(temporaryPath, "wx", mode);
13
+ await handle.writeFile(data);
14
+ await handle.sync();
15
+ await handle.close();
16
+ handle = undefined;
17
+ await rename(temporaryPath, filePath);
18
+ }
19
+ catch (error) {
20
+ await handle?.close().catch(() => undefined);
21
+ await unlink(temporaryPath).catch(() => undefined);
22
+ throw error;
23
+ }
24
+ };
25
+ /**
26
+ * A workspace backed by a host directory. It enumerates and moves opaque
27
+ * bytes only. Every path is confined beneath the root, symbolic links are
28
+ * never followed, hidden entries are unaddressable, invisible paths are
29
+ * neither enumerated nor readable, and sizes are bounded.
30
+ */
31
+ export class LocalDirectoryWorkspace {
32
+ mode;
33
+ limits;
34
+ attachable;
35
+ #root;
36
+ #filter;
37
+ #maxScanEntries;
38
+ constructor(options) {
39
+ if (!options.root.trim())
40
+ throw new Error("LocalDirectoryWorkspace requires a root directory.");
41
+ this.#root = path.resolve(options.root);
42
+ this.mode = options.mode ?? "read";
43
+ this.#filter = new WorkspacePathFilter(options);
44
+ this.limits = {
45
+ maxFiles: positiveInteger(options.maxFiles, DEFAULT_WORKSPACE_MAX_FILES, "Workspace maxFiles"),
46
+ maxFileBytes: positiveInteger(options.maxFileBytes, DEFAULT_WORKSPACE_MAX_FILE_BYTES, "Workspace maxFileBytes"),
47
+ maxTotalBytes: positiveInteger(options.maxTotalBytes, DEFAULT_WORKSPACE_MAX_TOTAL_BYTES, "Workspace maxTotalBytes"),
48
+ };
49
+ this.#maxScanEntries = positiveInteger(options.maxScanEntries, DEFAULT_MAX_SCAN_ENTRIES, "Workspace maxScanEntries");
50
+ if (options.attach === "auto" && this.#filter.isUnfiltered) {
51
+ this.attachable = { kind: "local-directory", root: this.#root };
52
+ }
53
+ }
54
+ get root() {
55
+ return this.#root;
56
+ }
57
+ async entries(options = {}) {
58
+ const entries = [];
59
+ const pending = [""];
60
+ let visited = 0;
61
+ while (pending.length > 0) {
62
+ throwIfAborted(options.signal);
63
+ const directory = pending.shift();
64
+ let children;
65
+ try {
66
+ children = await readdir(this.#absolute(directory), {
67
+ withFileTypes: true,
68
+ });
69
+ }
70
+ catch (error) {
71
+ if (isMissing(error) && directory === "")
72
+ return [];
73
+ throw error;
74
+ }
75
+ children.sort((left, right) => compareNames(left.name, right.name));
76
+ for (const child of children) {
77
+ visited += 1;
78
+ if (visited > this.#maxScanEntries) {
79
+ throw new Error(`Workspace enumeration exceeded ${this.#maxScanEntries} directory entries.`);
80
+ }
81
+ const relativePath = directory
82
+ ? `${directory}/${child.name}`
83
+ : child.name;
84
+ if (!isSafeWorkspacePath(relativePath))
85
+ continue;
86
+ if (child.isSymbolicLink())
87
+ continue;
88
+ if (child.isDirectory()) {
89
+ if (!this.#filter.isDirectoryExcluded(relativePath))
90
+ pending.push(relativePath);
91
+ continue;
92
+ }
93
+ if (!child.isFile() || !this.#filter.isVisible(relativePath))
94
+ continue;
95
+ const stats = await lstat(this.#absolute(relativePath));
96
+ if (!stats.isFile())
97
+ continue;
98
+ entries.push({
99
+ path: relativePath,
100
+ size: stats.size,
101
+ modifiedAt: stats.mtime.toISOString(),
102
+ });
103
+ if (entries.length > this.limits.maxFiles) {
104
+ throw new Error(`Workspace contains more than ${this.limits.maxFiles} visible files.`);
105
+ }
106
+ }
107
+ }
108
+ entries.sort((left, right) => compareNames(left.path, right.path));
109
+ return entries;
110
+ }
111
+ async read(relativePath, options = {}) {
112
+ throwIfAborted(options.signal);
113
+ const entry = await this.#statVisibleFile(relativePath);
114
+ if (entry.size > this.limits.maxFileBytes) {
115
+ throw new Error(`Workspace file ${relativePath} is ${entry.size} bytes, exceeding the ${this.limits.maxFileBytes}-byte limit.`);
116
+ }
117
+ const data = await readFile(this.#absolute(entry.path));
118
+ if (data.byteLength > this.limits.maxFileBytes) {
119
+ throw new Error(`Workspace file ${relativePath} exceeds the ${this.limits.maxFileBytes}-byte limit.`);
120
+ }
121
+ return data;
122
+ }
123
+ async write(relativePath, data, options = {}) {
124
+ this.#assertWritable();
125
+ throwIfAborted(options.signal);
126
+ const target = this.#visiblePath(relativePath);
127
+ if (data.byteLength > this.limits.maxFileBytes) {
128
+ throw new Error(`Workspace write to ${relativePath} is ${data.byteLength} bytes, exceeding the ${this.limits.maxFileBytes}-byte limit.`);
129
+ }
130
+ await this.#assertNoSymbolicLinks(target);
131
+ const absolute = this.#absolute(target);
132
+ const existing = await lstat(absolute).catch((error) => {
133
+ if (isMissing(error))
134
+ return undefined;
135
+ throw error;
136
+ });
137
+ if (existing && !existing.isFile()) {
138
+ throw new Error(`Workspace path ${relativePath} is not a regular file.`);
139
+ }
140
+ await mkdir(path.dirname(absolute), { recursive: true });
141
+ await writeAtomically(absolute, data, existing?.mode ?? 0o600);
142
+ const written = await lstat(absolute);
143
+ return {
144
+ path: target,
145
+ size: written.size,
146
+ modifiedAt: written.mtime.toISOString(),
147
+ };
148
+ }
149
+ async delete(relativePath, options = {}) {
150
+ this.#assertWritable();
151
+ throwIfAborted(options.signal);
152
+ const entry = await this.#statVisibleFile(relativePath);
153
+ await unlink(this.#absolute(entry.path));
154
+ }
155
+ #assertWritable() {
156
+ if (this.mode !== "read_write")
157
+ throw new Error("Workspace is read-only.");
158
+ }
159
+ #visiblePath(relativePath) {
160
+ const normalized = assertWorkspacePath(relativePath);
161
+ if (!this.#filter.isVisible(normalized)) {
162
+ throw new Error(`Workspace file is not available: ${relativePath}`);
163
+ }
164
+ return normalized;
165
+ }
166
+ #absolute(relativePath) {
167
+ const absolute = relativePath
168
+ ? path.resolve(this.#root, ...relativePath.split("/"))
169
+ : this.#root;
170
+ if (absolute !== this.#root &&
171
+ !absolute.startsWith(`${this.#root}${path.sep}`)) {
172
+ throw new Error(`Workspace path escapes the root: ${relativePath}`);
173
+ }
174
+ return absolute;
175
+ }
176
+ async #assertNoSymbolicLinks(relativePath) {
177
+ let current = this.#root;
178
+ for (const segment of relativePath.split("/")) {
179
+ current = path.join(current, segment);
180
+ const stats = await lstat(current).catch((error) => {
181
+ if (isMissing(error))
182
+ return undefined;
183
+ throw error;
184
+ });
185
+ if (!stats)
186
+ return;
187
+ if (stats.isSymbolicLink()) {
188
+ throw new Error(`Workspace path ${relativePath} crosses a symbolic link.`);
189
+ }
190
+ }
191
+ }
192
+ async #statVisibleFile(relativePath) {
193
+ const target = this.#visiblePath(relativePath);
194
+ await this.#assertNoSymbolicLinks(target);
195
+ const stats = await lstat(this.#absolute(target)).catch((error) => {
196
+ if (isMissing(error))
197
+ return undefined;
198
+ throw error;
199
+ });
200
+ if (!stats || !stats.isFile()) {
201
+ throw new Error(`Workspace file is not available: ${relativePath}`);
202
+ }
203
+ return {
204
+ path: target,
205
+ size: stats.size,
206
+ modifiedAt: stats.mtime.toISOString(),
207
+ };
208
+ }
209
+ }
@@ -0,0 +1,36 @@
1
+ import type { WorkspaceMode } from "@clearideas/agent-runtime-contracts";
2
+ import type { WorkspaceEntry, WorkspaceLimits, WorkspaceStore } from "@clearideas/agent-runtime-core";
3
+ export interface MemoryWorkspaceOptions {
4
+ mode?: WorkspaceMode;
5
+ /** Initial files keyed by relative path. Strings are stored as UTF-8. */
6
+ files?: Record<string, Uint8Array | string>;
7
+ include?: string[];
8
+ exclude?: string[];
9
+ maxFiles?: number;
10
+ maxFileBytes?: number;
11
+ maxTotalBytes?: number;
12
+ now?: () => Date;
13
+ }
14
+ /** An in-memory workspace for tests, examples, and ephemeral embedding hosts. */
15
+ export declare class MemoryWorkspace implements WorkspaceStore {
16
+ #private;
17
+ readonly mode: WorkspaceMode;
18
+ readonly limits: WorkspaceLimits;
19
+ constructor(options?: MemoryWorkspaceOptions);
20
+ /** Current file paths, for assertions in tests. */
21
+ get paths(): string[];
22
+ /** Current file contents decoded as UTF-8, for assertions in tests. */
23
+ text(relativePath: string): string | undefined;
24
+ entries(options?: {
25
+ signal?: AbortSignal;
26
+ }): Promise<WorkspaceEntry[]>;
27
+ read(relativePath: string, options?: {
28
+ signal?: AbortSignal;
29
+ }): Promise<Uint8Array>;
30
+ write(relativePath: string, data: Uint8Array, options?: {
31
+ signal?: AbortSignal;
32
+ }): Promise<WorkspaceEntry>;
33
+ delete(relativePath: string, options?: {
34
+ signal?: AbortSignal;
35
+ }): Promise<void>;
36
+ }
@@ -0,0 +1,97 @@
1
+ import { assertWorkspacePath } from "@clearideas/agent-runtime-core";
2
+ import { DEFAULT_WORKSPACE_MAX_FILE_BYTES, DEFAULT_WORKSPACE_MAX_FILES, DEFAULT_WORKSPACE_MAX_TOTAL_BYTES, WorkspacePathFilter, compareNames, positiveInteger, throwIfAborted, } from "./workspace-common.js";
3
+ /** An in-memory workspace for tests, examples, and ephemeral embedding hosts. */
4
+ export class MemoryWorkspace {
5
+ mode;
6
+ limits;
7
+ #files = new Map();
8
+ #filter;
9
+ #now;
10
+ constructor(options = {}) {
11
+ this.mode = options.mode ?? "read";
12
+ this.#filter = new WorkspacePathFilter(options);
13
+ this.limits = {
14
+ maxFiles: positiveInteger(options.maxFiles, DEFAULT_WORKSPACE_MAX_FILES, "Workspace maxFiles"),
15
+ maxFileBytes: positiveInteger(options.maxFileBytes, DEFAULT_WORKSPACE_MAX_FILE_BYTES, "Workspace maxFileBytes"),
16
+ maxTotalBytes: positiveInteger(options.maxTotalBytes, DEFAULT_WORKSPACE_MAX_TOTAL_BYTES, "Workspace maxTotalBytes"),
17
+ };
18
+ this.#now = options.now ?? (() => new Date());
19
+ for (const [relativePath, content] of Object.entries(options.files ?? {})) {
20
+ this.#store(assertWorkspacePath(relativePath), content);
21
+ }
22
+ }
23
+ /** Current file paths, for assertions in tests. */
24
+ get paths() {
25
+ return [...this.#files.keys()].sort(compareNames);
26
+ }
27
+ /** Current file contents decoded as UTF-8, for assertions in tests. */
28
+ text(relativePath) {
29
+ const stored = this.#files.get(relativePath);
30
+ return stored ? new TextDecoder().decode(stored.data) : undefined;
31
+ }
32
+ async entries(options = {}) {
33
+ throwIfAborted(options.signal);
34
+ return this.paths
35
+ .filter((relativePath) => this.#filter.isVisible(relativePath))
36
+ .map((relativePath) => this.#entry(relativePath, this.#files.get(relativePath)));
37
+ }
38
+ async read(relativePath, options = {}) {
39
+ throwIfAborted(options.signal);
40
+ const target = this.#visiblePath(relativePath);
41
+ const stored = this.#files.get(target);
42
+ if (!stored)
43
+ throw new Error(`Workspace file is not available: ${relativePath}`);
44
+ if (stored.data.byteLength > this.limits.maxFileBytes) {
45
+ throw new Error(`Workspace file ${relativePath} exceeds the ${this.limits.maxFileBytes}-byte limit.`);
46
+ }
47
+ return new Uint8Array(stored.data);
48
+ }
49
+ async write(relativePath, data, options = {}) {
50
+ this.#assertWritable();
51
+ throwIfAborted(options.signal);
52
+ const target = this.#visiblePath(relativePath);
53
+ if (data.byteLength > this.limits.maxFileBytes) {
54
+ throw new Error(`Workspace write to ${relativePath} is ${data.byteLength} bytes, exceeding the ${this.limits.maxFileBytes}-byte limit.`);
55
+ }
56
+ if (!this.#files.has(target) && this.#files.size >= this.limits.maxFiles) {
57
+ throw new Error(`Workspace cannot hold more than ${this.limits.maxFiles} files.`);
58
+ }
59
+ return this.#entry(target, this.#store(target, data));
60
+ }
61
+ async delete(relativePath, options = {}) {
62
+ this.#assertWritable();
63
+ throwIfAborted(options.signal);
64
+ const target = this.#visiblePath(relativePath);
65
+ if (!this.#files.delete(target)) {
66
+ throw new Error(`Workspace file is not available: ${relativePath}`);
67
+ }
68
+ }
69
+ #assertWritable() {
70
+ if (this.mode !== "read_write")
71
+ throw new Error("Workspace is read-only.");
72
+ }
73
+ #visiblePath(relativePath) {
74
+ const normalized = assertWorkspacePath(relativePath);
75
+ if (!this.#filter.isVisible(normalized)) {
76
+ throw new Error(`Workspace file is not available: ${relativePath}`);
77
+ }
78
+ return normalized;
79
+ }
80
+ #store(relativePath, content) {
81
+ const stored = {
82
+ data: typeof content === "string"
83
+ ? new TextEncoder().encode(content)
84
+ : new Uint8Array(content),
85
+ modifiedAt: this.#now().toISOString(),
86
+ };
87
+ this.#files.set(relativePath, stored);
88
+ return stored;
89
+ }
90
+ #entry(relativePath, stored) {
91
+ return {
92
+ path: relativePath,
93
+ size: stored.data.byteLength,
94
+ modifiedAt: stored.modifiedAt,
95
+ };
96
+ }
97
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clearideas/agent-runtime-store-local",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
4
4
  "description": "Memory, file, console, and JSONL adapters for Clear Ideas Agent Runtime.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Clear Ideas Incorporated",
@@ -36,8 +36,8 @@
36
36
  "postpack": "node ../../scripts/cleanup-package-license.mjs"
37
37
  },
38
38
  "dependencies": {
39
- "@clearideas/agent-runtime-contracts": "0.5.0",
40
- "@clearideas/agent-runtime-core": "0.5.0",
39
+ "@clearideas/agent-runtime-contracts": "0.6.1",
40
+ "@clearideas/agent-runtime-core": "0.6.1",
41
41
  "yaml": "^2.9.1"
42
42
  },
43
43
  "devDependencies": {