@byok-sdk/client 0.9.0-rc.1 → 0.9.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
@@ -134,6 +134,65 @@ files other than the SDK-reserved `.byok` namespace are opaque; there is no
134
134
  required `artifacts/` directory and the client does not parse or index their
135
135
  contents.
136
136
 
137
+ ## Embedded Agent memory
138
+
139
+ A product that embeds this SDK rather than running the daemon owns its own
140
+ Agent home, its own lease, and — on macOS — the absolute signed and notarized
141
+ helper binary. It still must not own the memory authority itself: the sha256
142
+ compare-and-swap, the audit record, the platform gate, and the exact set of
143
+ paths a model may name stay in the SDK. `@byok-sdk/client/agent-memory` is that
144
+ authority without the daemon.
145
+
146
+ ```ts
147
+ import {
148
+ AgentMemoryService,
149
+ captureAgentMemorySnapshot,
150
+ isAgentMemorySecureFilesystemAvailable,
151
+ openAgentMemoryFilesystemHelper,
152
+ prependAgentMemoryGuidance,
153
+ serveAgentMemoryMcpOverStdio,
154
+ } from '@byok-sdk/client/agent-memory';
155
+
156
+ if (!isAgentMemorySecureFilesystemAvailable(helperBin !== undefined)) return;
157
+
158
+ const context = {
159
+ taskId, tenantId, deviceId, agentRef, sessionRef, runtimeId, leaseId,
160
+ canonicalHome: lease.canonicalHome,
161
+ homeIdentity: lease.homeIdentity,
162
+ // macOS only: the host's own helper binary, admitted by absolute path.
163
+ ...(helperBin === undefined ? {} : {
164
+ filesystem: await openAgentMemoryFilesystemHelper({
165
+ helperBin, canonicalHome: lease.canonicalHome, homeIdentity: lease.homeIdentity,
166
+ }),
167
+ }),
168
+ };
169
+
170
+ const service = new AgentMemoryService(context);
171
+ serveAgentMemoryMcpOverStdio({ deps: service });
172
+ const instruction = prependAgentMemoryGuidance(agentInstruction);
173
+ // After the session closes, while the lease still exists:
174
+ const snapshot = await captureAgentMemorySnapshot(context);
175
+ ```
176
+
177
+ Platform behavior is inherited from the daemon path, not restated: Linux uses
178
+ the native descriptor-relative backend, macOS requires the external helper, and
179
+ Windows stays fail-closed with or without one.
180
+
181
+ This entry deliberately reaches no transport, no daemon composition, and no
182
+ control socket — importing the same symbols from the package root pulls all
183
+ three in. `connectControlClient` is not public anywhere in this package and
184
+ must not become reachable here; `src/__tests__/agent-memory-entry-constraints.test.ts`
185
+ pins the source module graph and `scripts/check-agent-memory-entry.mjs` pins the
186
+ built bundle.
187
+
188
+ Hosted projection is not on this entry. An embedded host gets the local
189
+ snapshot and no way to send it anywhere from this package.
190
+
191
+ Because each entry is bundled separately, `AgentMemoryError` imported from
192
+ `@byok-sdk/client/agent-memory` and from `@byok-sdk/client` are distinct
193
+ constructors. Discriminate on `error.name`, not `instanceof`, if a host mixes
194
+ both entries.
195
+
137
196
  ## Agent egress and explicit content reads
138
197
 
139
198
  `agentEgress` is consumed policy configuration, not a profile or tenant
@@ -0,0 +1,96 @@
1
+ /**
2
+ * `@byok-sdk/client/agent-memory` — the embedded-host composition surface for
3
+ * Agent memory.
4
+ *
5
+ * A product that embeds this SDK instead of running the daemon (no second
6
+ * control plane, no `control.sock`) already owns the pieces the daemon would
7
+ * otherwise own for it: the canonical Agent home under `AGENT_HOME_DIRECTORY`,
8
+ * the lease that pins it, and the signed/notarized macOS helper binary. What it
9
+ * cannot own is the memory authority itself — the compare-and-swap semantics,
10
+ * the audit record, the platform gate, and the exact path policy the model is
11
+ * allowed to name. Those must stay in one place or two implementations drift.
12
+ *
13
+ * This entry therefore exports exactly the pieces `daemon/task-runner.ts`
14
+ * composes for an in-daemon Agent task, minus the daemon:
15
+ *
16
+ * - `AgentMemoryService` — task-scoped recall/save authority.
17
+ * - `captureAgentMemorySnapshot` — the post-close bounded snapshot.
18
+ * - `openAgentMemoryFilesystemHelper`— admission of the host's macOS helper.
19
+ * - `serveAgentMemoryMcpOverStdio` — the two memory tools over stdio.
20
+ * - `prependAgentMemoryGuidance` — the prompt half of the path contract.
21
+ *
22
+ * Three things are deliberately absent, and this file is the record of why.
23
+ *
24
+ * 1. The control client. `connectControlClient`/`ControlClient` are not
25
+ * exported from this package at all (see `src/index.ts`) and must not become
26
+ * reachable here: they also carry `shutdown`, approval resolution, and the
27
+ * raw task-event stream. The shipped `byok-agent-memory-mcp` bin reaches the
28
+ * same service *through* that socket; an embedded host reaches it directly,
29
+ * which is the entire reason this entry exists.
30
+ *
31
+ * 2. The transport. Nothing reachable from this entry may import `ws`, the
32
+ * daemon composition, or any transport module. Importing a single memory
33
+ * symbol from the root entry drags the WebSocket transport into a host
34
+ * bundle; the subpath exists so it does not. `__tests__/agent-memory-entry-
35
+ * constraints.test.ts` walks this module graph and `scripts/check-agent-
36
+ * memory-entry.mjs` re-checks the built bundle.
37
+ *
38
+ * 3. Hosted projection. `AgentMemoryRedactor`, `AgentMemoryProjectionPort`,
39
+ * `AgentMemoryHostedProjection` and `snapshotAndProjectAgentMemory` stay off
40
+ * this entry. Projection is a network surface, and a credential-blind
41
+ * transport for it does not exist yet; an embedded host gets the local
42
+ * snapshot and nothing that sends it anywhere.
43
+ *
44
+ * Platform semantics are unchanged by this entry, not re-stated in it: Linux
45
+ * uses the native descriptor backend, macOS requires the host's external
46
+ * helper, and Windows stays fail-closed. `isAgentMemorySecureFilesystemAvailable`
47
+ * is the single gate a host consults before offering memory at all.
48
+ */
49
+ /** Per-task memory authority: `recall`/`save` under sha256 compare-and-swap, bound to one exact active Agent task context. */
50
+ export { AgentMemoryService } from '../daemon/agent-memory';
51
+ /** Bounded, audited snapshot of the Agent's local memory files, taken after `Session.close()` while the home lease still exists. */
52
+ export { captureAgentMemorySnapshot } from '../daemon/agent-memory';
53
+ /** The single source of truth for which relative path a model may name: `MEMORY.md` or `notes/<safe-relative>.md`. */
54
+ export { validateAgentMemoryPath } from '../daemon/agent-memory';
55
+ /** The sole platform gate for the memory write authority: native Linux, macOS only with the host's helper, Windows never. */
56
+ export { isAgentMemorySecureFilesystemAvailable } from '../daemon/agent-memory';
57
+ /** Base failure for every rejected memory operation. */
58
+ export { AgentMemoryError } from '../daemon/agent-memory';
59
+ /** Compare-and-swap failure carrying the expected and actual content revisions. */
60
+ export { AgentMemoryRevisionConflictError } from '../daemon/agent-memory';
61
+ /** The exact active-task binding required to construct the service; every field is validated on each call. */
62
+ export type { AgentMemoryTaskContext } from '../daemon/agent-memory';
63
+ /** One memory file as the snapshot sees it: relative path, sha256 revision, byte count, content. */
64
+ export type { AgentMemoryFile } from '../daemon/agent-memory';
65
+ /** A bounded set of memory files plus their total byte count. */
66
+ export type { AgentMemorySnapshot } from '../daemon/agent-memory';
67
+ /** Result of `recall`, including the metadata-only audit warning when the audit write failed but the read did not. */
68
+ export type { AgentMemoryRecallResult } from '../daemon/agent-memory';
69
+ /** Result of `save`, distinguishing a replace (with new revision) from a delete. */
70
+ export type { AgentMemorySaveResult } from '../daemon/agent-memory';
71
+ /** Metadata-only signal that the audit record could not be written; the source operation still succeeded. */
72
+ export type { AgentMemoryAuditWarning } from '../daemon/agent-memory';
73
+ /** Whether this platform can admit an external filesystem helper at all (macOS only today). */
74
+ export { isAgentMemoryFilesystemHelperSupported } from '../daemon/agent-memory-fs-helper';
75
+ /** Admits the host's absolute signed/notarized helper binary and returns the root-pinned filesystem for one Agent home. */
76
+ export { openAgentMemoryFilesystemHelper } from '../daemon/agent-memory-fs-helper';
77
+ /** Root-bound filesystem authority the service operates through; the host supplies it only on macOS. */
78
+ export type { AgentMemoryFilesystem } from '../daemon/agent-memory-filesystem';
79
+ /** One file's state as reported by that filesystem authority. */
80
+ export type { AgentMemoryFilesystemFileState } from '../daemon/agent-memory-filesystem';
81
+ /** Product-owned deployment pointer to the helper binary; the SDK never searches PATH. */
82
+ export type { AgentMemoryFilesystemHelperConfig } from '../daemon/agent-memory-filesystem';
83
+ /** Serves `memory.recall`/`memory.save` as a stdio MCP server over host-provided streams. */
84
+ export { serveAgentMemoryMcpOverStdio } from '../bin/agent-memory-mcp-server';
85
+ /** MCP tool name a host must allowlist for reads. */
86
+ export { AGENT_MEMORY_RECALL_TOOL_NAME } from '../bin/agent-memory-mcp-server';
87
+ /** MCP tool name a host must allowlist for writes. */
88
+ export { AGENT_MEMORY_SAVE_TOOL_NAME } from '../bin/agent-memory-mcp-server';
89
+ /** The two calls the stdio server delegates to; an `AgentMemoryService` satisfies it directly. */
90
+ export type { AgentMemoryMcpDeps } from '../bin/agent-memory-mcp-server';
91
+ /** Runtime-neutral instructions telling the model how to use `MEMORY.md` and `notes/`. */
92
+ export { AGENT_MEMORY_GUIDANCE } from '../daemon/memory-guidance';
93
+ /** Prepends that guidance to an Agent instruction, exactly as the daemon's task runner does. */
94
+ export { prependAgentMemoryGuidance } from '../daemon/memory-guidance';
95
+ /** The validated Agent identity carried by `AgentMemoryTaskContext`. */
96
+ export type { AgentRef } from '../agent-home';