Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

feat(ts): follow harness-addressed messages in the SDK

Aldo Junior70844d10c947
diff --git a/companions/ai-memory-ts/CHANGELOG.md b/companions/ai-memory-ts/CHANGELOG.md
index 246da631..f68e94c3 100644
--- a/companions/ai-memory-ts/CHANGELOG.md
+++ b/companions/ai-memory-ts/CHANGELOG.md
@@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `query` takes the server's `memory_query` page filters: `kind`, `tier`,
`pathPrefix` and `tag`, in every search mode.
+- `messages.pop` takes `agent`, the harness claiming harness-addressed mail,
+ and `Message` carries `toAgent` (`null` for shared project mail), matching
+ the server's new `to_agent` addressing.
+
## [0.1.0]
### Added
diff --git a/companions/ai-memory-ts/docs/arguments.md b/companions/ai-memory-ts/docs/arguments.md
index 4c764020..6dfbc849 100644
--- a/companions/ai-memory-ts/docs/arguments.md
+++ b/companions/ai-memory-ts/docs/arguments.md
@@ -175,6 +175,7 @@ Methods: `messages.pop`
| `workspace` | `workspace` |
| `project` | `project` |
| `message_id` | `messageId` |
+| `agent` | `agent` |
## `memory_message_cancel`
diff --git a/companions/ai-memory-ts/schema/tools.json b/companions/ai-memory-ts/schema/tools.json
index 5146a071..ee744242 100644
--- a/companions/ai-memory-ts/schema/tools.json
+++ b/companions/ai-memory-ts/schema/tools.json
@@ -491,6 +491,12 @@
},
"memory_message_pop": {
"properties": {
+ "agent": {
+ "type": [
+ "null",
+ "string"
+ ]
+ },
"message_id": {
"type": [
"null",
diff --git a/companions/ai-memory-ts/src/client.ts b/companions/ai-memory-ts/src/client.ts
index 65bea6ce..b038f6e6 100644
--- a/companions/ai-memory-ts/src/client.ts
+++ b/companions/ai-memory-ts/src/client.ts
@@ -545,9 +545,10 @@ export class MessagesNamespace {
const a = argsObject(args, where);
const scope = this.#core.scope(a.scope, where);
if (a.messageId !== undefined) requireText(a.messageId, "messageId", where);
+ if (a.agent !== undefined) requireText(a.agent, "agent", where);
const decoded = await this.#core.invoke(
"memory_message_pop",
- wire({ ...scopeWire(scope), message_id: a.messageId }),
+ wire({ ...scopeWire(scope), message_id: a.messageId, agent: a.agent }),
true,
options,
);
diff --git a/companions/ai-memory-ts/src/coverage.ts b/companions/ai-memory-ts/src/coverage.ts
index 944ef109..8258ae4a 100644
--- a/companions/ai-memory-ts/src/coverage.ts
+++ b/companions/ai-memory-ts/src/coverage.ts
@@ -134,7 +134,7 @@ export const TOOL_COVERAGE: Readonly<Record<string, ToolClassification>> = {
status: "wrapped",
methods: ["messages.pop"],
phase: 2,
- sends: [...SCOPE, "message_id"],
+ sends: [...SCOPE, "message_id", "agent"],
},
memory_message_cancel: {
status: "wrapped",
diff --git a/companions/ai-memory-ts/src/decode.ts b/companions/ai-memory-ts/src/decode.ts
index 13fed77a..b4870aaf 100644
--- a/companions/ai-memory-ts/src/decode.ts
+++ b/companions/ai-memory-ts/src/decode.ts
@@ -294,6 +294,7 @@ export function message(value: unknown, where: string): Message {
createdAt: optStr(o, "created_at", where),
claimedAt: nullableStr(o, "claimed_at", where),
fromAgent: optStr(o, "from_agent", where),
+ toAgent: nullableStr(o, "to_agent", where),
fromOwner: nullableStr(o, "from_owner_user", where),
raw: o,
};
diff --git a/companions/ai-memory-ts/src/types.ts b/companions/ai-memory-ts/src/types.ts
index 5394f6a2..13f0b5a6 100644
--- a/companions/ai-memory-ts/src/types.ts
+++ b/companions/ai-memory-ts/src/types.ts
@@ -771,6 +771,8 @@ export interface Message {
readonly claimedAt: string | null;
/** The sender's harness label. */
readonly fromAgent: string | undefined;
+ /** The harness the message is addressed to, or `null` for shared project mail. */
+ readonly toAgent: string | null;
/** The sending operator key, or `null`. */
readonly fromOwner: string | null;
/** The server's decoded JSON. */
@@ -797,6 +799,12 @@ export interface ListMessagesResult {
export interface PopMessageArgs extends ScopedArgs {
/** Claim exactly this message. Omit to claim the oldest pending one. */
messageId?: string;
+ /**
+ * The harness claiming (for example `codex` or `claude-code`), for a
+ * client whose session metadata does not identify it. Mail addressed to a
+ * harness can only be claimed by that harness.
+ */
+ agent?: string;
}
/** Result of {@link MessagesNamespace.pop}. */
diff --git a/companions/ai-memory-ts/test/support/payloads.ts b/companions/ai-memory-ts/test/support/payloads.ts
index 62cab684..9dd18f99 100644
--- a/companions/ai-memory-ts/test/support/payloads.ts
+++ b/companions/ai-memory-ts/test/support/payloads.ts
@@ -129,6 +129,7 @@ export const messageRow = {
from_project_id: "p",
from_agent: "other",
from_owner_user: null,
+ to_agent: null,
subject: "hi",
body: "please do X",
state: "pending",
diff --git a/companions/ai-memory-ts/test/unit/client.test.ts b/companions/ai-memory-ts/test/unit/client.test.ts
index 185f4eed..ed09d350 100644
--- a/companions/ai-memory-ts/test/unit/client.test.ts
+++ b/companions/ai-memory-ts/test/unit/client.test.ts
@@ -345,7 +345,14 @@ describe("messages", () => {
const listed = await memory.messages.list({ box: "outbox", limit: 3 });
assert.deepEqual(server.lastArgs(), { workspace: "demo", project: "app", box: "outbox", limit: 3 });
assert.equal(listed.messages[0]?.body, "please do X");
- const popped = await memory.messages.pop({ messageId: payloads.MESSAGE_ID });
+ assert.equal(listed.messages[0]?.toAgent, null);
+ const popped = await memory.messages.pop({ messageId: payloads.MESSAGE_ID, agent: "codex" });
+ assert.deepEqual(server.lastArgs(), {
+ workspace: "demo",
+ project: "app",
+ message_id: payloads.MESSAGE_ID,
+ agent: "codex",
+ });
assert.equal(popped.message?.state, "claimed");
assert.equal(popped.securityNotice, "UNTRUSTED");
const cancelled = await memory.messages.cancel();
@@ -573,7 +580,7 @@ describe("wire names", () => {
memory.handoffs.cancel({ handoffId: "h", anyOwner: true }),
memory.messages.send({ to: OTHER, from: SCOPE, body: "b", subject: "s" }),
memory.messages.list({ box: "inbox", limit: 1 }),
- memory.messages.pop({ messageId: "m" }),
+ memory.messages.pop({ messageId: "m", agent: "codex" }),
memory.messages.cancel({ messageId: "m" }),
];
await Promise.allSettled(calls);