openclaw-memory-atmem 2.2.6-beta.1 → 2.2.6-beta.10

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
@@ -5,7 +5,7 @@ This npm package is the host bridge for AtMem. It is not a standalone memory eng
5
5
  Use the Python-owned installer:
6
6
 
7
7
  ```bash
8
- python -m pip install --pre --upgrade atmem==2.2.6b1
8
+ python -m pip install --pre --upgrade atmem==2.2.6b10
9
9
  atmem openclaw install
10
10
  ```
11
11
 
@@ -22,6 +22,13 @@ Existing AtMem 2.1 users run `atmem openclaw upgrade` after upgrading the Python
22
22
  package. This preserves the current memory mode and migration, verifies the new
23
23
  bridge with a self-test flight, and rolls back the bridge on failure.
24
24
 
25
+ Bridge `2.2.6-beta.10` adds Spec 007 exact task-context delivery. When the host
26
+ supplies `taskId` in hook context, the bridge requests only that governed task,
27
+ checks its byte digest, contributes it separately from recalled memory, and
28
+ confirms exposure. With no `taskId`, task delivery stays off and existing
29
+ memory-only behavior is unchanged. Guard detection is available, but this
30
+ bridge does not claim it can block OpenClaw execution.
31
+
25
32
  In shadow mode the bridge observes native-memory changes without injecting AtMem context. In active mode it exposes compatible memory search/get tools, model-semantic capture, bounded recall and native-path protection. `atmem control restore` restores the saved OpenClaw configuration and native memory.
26
33
 
27
34
  The bridge also supplies Agent Black Box hooks. It records model/tool lifecycle digests and bounded metadata—not raw prompts, responses, parameters or results—so `atmem blackbox verify RUN_ID` can check timeline integrity and observed tool-hook closure. See the [Agent Black Box guide](../../docs/agent-blackbox.md) for the exact boundary.
package/dist/index.js CHANGED
@@ -25,6 +25,7 @@ import { lstat, mkdir, readFile, realpath, rename, unlink, writeFile } from "nod
25
25
  import { spawnSync } from "node:child_process";
26
26
  import { AtmemClient } from "./src/rpc-client.js";
27
27
  import { runSetup } from "./src/setup.js";
28
+ import { NOT_OWNER_MESSAGE, NO_IDENTITY_MESSAGE, describeDecision, isConversationOwner, ok, resolveBoundTaskForTool, refusal, sessionIdentityForTool, } from "./src/task-tools.js";
28
29
  const TAG = "[memory-atmem]";
29
30
  const TAKEOVER_GUIDANCE = "<atmem_memory_provider>\n" +
30
31
  "AtMem is the active durable-memory provider. " +
@@ -352,6 +353,26 @@ function register(api) {
352
353
  }
353
354
  return cfg.subject;
354
355
  };
356
+ /**
357
+ * The identity AtMem resolves a governed task through.
358
+ *
359
+ * `sessionId` is the generation: OpenClaw changes it when a conversation is
360
+ * reset, which is what stops a recycled `sessionKey` from inheriting an
361
+ * earlier task binding. Both fields are optional upstream, so returning
362
+ * `undefined` is an ordinary outcome and callers must withhold rather than
363
+ * send a partial identity.
364
+ */
365
+ const sessionIdentityFor = (ctx) => {
366
+ const sessionKey = ctx.sessionKey ?? ctx.sessionId;
367
+ const sessionEpoch = ctx.sessionId;
368
+ if (!sessionKey || !sessionEpoch)
369
+ return undefined;
370
+ return {
371
+ host_type: "openclaw",
372
+ session_key: sessionKey,
373
+ session_epoch: sessionEpoch,
374
+ };
375
+ };
355
376
  const workspaceIdFor = (ctx) => {
356
377
  const workspace = cfg.agentWorkspaces[agentIdFor(ctx)];
357
378
  return workspace ? `ws_${digestText(workspace).slice(0, 16)}` : undefined;
@@ -747,6 +768,27 @@ function register(api) {
747
768
  user_id: delegatedUserIdFor(ctx),
748
769
  workspace_id: workspaceIdFor(ctx),
749
770
  }, cfg.recall.timeoutMs));
771
+ // Task identity resolves through the manager, not from ctx.taskId
772
+ // alone: OpenClaw supplies no task identity of its own, so without a
773
+ // registered binding this branch could never run. Presenting the
774
+ // session identity on every lookup keeps binding and resolution from
775
+ // disagreeing about which conversation they mean.
776
+ const taskIdentity = sessionIdentityFor(ctx);
777
+ const taskPrepared = (ctx.taskId || taskIdentity)
778
+ ? (await callFor(ctx, "control_prepare_task_context", {
779
+ ...(ctx.taskId ? { task_id: ctx.taskId } : {}),
780
+ ...(taskIdentity ?? {}),
781
+ session_id: sessionKey,
782
+ host_run_id: ctx.runId,
783
+ agent_id: agentIdFor(ctx),
784
+ workspace_id: workspaceIdFor(ctx),
785
+ }, cfg.recall.timeoutMs))
786
+ : undefined;
787
+ if (taskPrepared?.disposition === "injected" &&
788
+ (!taskPrepared.context || !taskPrepared.context_sha256 ||
789
+ `sha256:${digestText(taskPrepared.context)}` !== taskPrepared.context_sha256)) {
790
+ throw new Error("governed task context failed exact handoff digest validation");
791
+ }
750
792
  pendingPrompts.set(sessionKey, {
751
793
  text: userText,
752
794
  ts: Date.now(),
@@ -758,7 +800,21 @@ function register(api) {
758
800
  delegatedContextSha256: prepared.authority === "delegated" ? prepared.context_sha256 : undefined,
759
801
  delegatedAuthority: prepared.authority,
760
802
  delegatedResultSha256: prepared.result_sha256,
803
+ taskDeliveryId: taskPrepared?.delivery_id,
804
+ taskContextSha256: taskPrepared?.context_sha256,
805
+ taskId: taskPrepared?.task_id ?? ctx.taskId,
761
806
  });
807
+ if (taskPrepared) {
808
+ await recordBlackbox("task.context.prepared", undefined, ctx, {
809
+ task_id: taskPrepared.task_id ?? ctx.taskId,
810
+ task_disposition: taskPrepared?.disposition ?? "withheld",
811
+ task_revision: taskPrepared?.revision,
812
+ ...(taskPrepared?.context_sha256
813
+ ? { task_context_sha256: taskPrepared.context_sha256.replace(/^sha256:/, "") }
814
+ : {}),
815
+ task_reason_codes: taskPrepared?.reason_codes ?? [],
816
+ });
817
+ }
762
818
  if (prepared.authority === "delegated" &&
763
819
  prepared.inject &&
764
820
  (!prepared.context ||
@@ -794,6 +850,10 @@ function register(api) {
794
850
  digest_profile: "atmem-context-envelope-canonical-json-v1",
795
851
  context_chars: (prepared.context ?? "").length,
796
852
  candidate_ids: prepared.candidate_ids ?? [],
853
+ candidates_considered: prepared.retrieval?.eligible_candidate_count ?? 0,
854
+ retrieval_support_class: prepared.retrieval?.decision?.support_class ?? "not_recorded",
855
+ retrieval_reason_codes: prepared.retrieval?.decision?.reason_codes ?? [],
856
+ retrieval_calibration_version: prepared.retrieval?.decision?.calibration_version,
797
857
  exposure_id: prepared.exposure_id,
798
858
  mode: prepared.mode,
799
859
  context_location: prepared.inject
@@ -805,8 +865,21 @@ function register(api) {
805
865
  if (prepared.inject && prepared.context) {
806
866
  api.logger.info(`${TAG} memory control plane ${prepared.mode ?? "active"} context exposed`);
807
867
  return prepared.authority === "delegated"
808
- ? { prependContext: prepared.context }
809
- : { appendContext: prepared.context };
868
+ ? {
869
+ prependContext: prepared.context,
870
+ appendContext: taskPrepared?.disposition === "injected"
871
+ ? taskPrepared.context
872
+ : undefined,
873
+ }
874
+ : {
875
+ appendContext: [
876
+ prepared.context,
877
+ taskPrepared?.disposition === "injected" ? taskPrepared.context : "",
878
+ ].filter(Boolean).join("\n\n"),
879
+ };
880
+ }
881
+ if (taskPrepared?.disposition === "injected" && taskPrepared.context) {
882
+ return { appendContext: taskPrepared.context };
810
883
  }
811
884
  return;
812
885
  }
@@ -1007,6 +1080,14 @@ function register(api) {
1007
1080
  if (cached?.exposureId) {
1008
1081
  await callFor(ctx, "control_exposure_shown", { exposure_id: cached.exposureId }, cfg.recall.timeoutMs);
1009
1082
  }
1083
+ if (cached?.taskDeliveryId) {
1084
+ await callFor(ctx, "control_task_exposure_shown", { delivery_id: cached.taskDeliveryId }, cfg.recall.timeoutMs);
1085
+ await recordBlackbox("task.context.exposed", event.runId, ctx, {
1086
+ task_id: cached.taskId ?? ctx.taskId,
1087
+ task_disposition: "injected",
1088
+ task_context_sha256: cached.taskContextSha256?.replace(/^sha256:/, ""),
1089
+ });
1090
+ }
1010
1091
  if (event.success !== false) {
1011
1092
  await callFor(ctx, "control_sync_openclaw_memory", {}, cfg.recall.timeoutMs);
1012
1093
  }
@@ -1630,6 +1711,128 @@ function register(api) {
1630
1711
  };
1631
1712
  },
1632
1713
  }), { name: "atmem_forget_artifact" });
1714
+ // --- governed task tools (Amendment A) -------------------------------
1715
+ //
1716
+ // A control-plane operation is invisible to a model. Without these
1717
+ // registrations an agent receives a task checklist it has no way to tick,
1718
+ // which is worse than receiving nothing: it looks like progress is being
1719
+ // tracked when nothing is being recorded.
1720
+ //
1721
+ // Every one resolves through this conversation's own binding, so a model
1722
+ // can only touch the task its conversation is bound to.
1723
+ const taskScope = (toolCtx) => ({
1724
+ agent_id: agentIdFor(toolCtx),
1725
+ workspace_id: workspaceIdFor(toolCtx),
1726
+ });
1727
+ api.registerTool((toolCtx) => ({
1728
+ name: "task_report_progress",
1729
+ label: "Report Task Progress (atmem)",
1730
+ description: "Report progress on the governed task this conversation is bound to. " +
1731
+ "State the item and its new status. AtMem validates the change and " +
1732
+ "decides; you are proposing, not writing. If no task is bound this " +
1733
+ "does nothing.",
1734
+ parameters: {
1735
+ type: "object",
1736
+ properties: {
1737
+ item_id: { type: "string", description: "Which task item changed" },
1738
+ status: {
1739
+ type: "string",
1740
+ enum: ["ready", "running", "blocked", "completed", "skipped", "failed"],
1741
+ description: "The item's new status",
1742
+ },
1743
+ base_revision: {
1744
+ type: "integer",
1745
+ description: "The task revision you read. If the task has moved since, this " +
1746
+ "returns a conflict instead of overwriting someone else's work.",
1747
+ },
1748
+ reason: { type: "string", description: "Why, in one line" },
1749
+ },
1750
+ required: ["item_id", "status", "base_revision"],
1751
+ },
1752
+ async execute(toolCallId, params) {
1753
+ const resolution = await resolveBoundTaskForTool(toolCtx, (identity) => callFor(toolCtx, "control_prepare_task_context", {
1754
+ ...identity,
1755
+ ...taskScope(toolCtx),
1756
+ host_run_id: toolCtx.runId,
1757
+ }));
1758
+ if (!resolution.ok) {
1759
+ return refusal(`${resolution.message} (${resolution.reasonCodes.join(", ")})`);
1760
+ }
1761
+ const result = (await callFor(toolCtx, "control_propose_task_delta", {
1762
+ ...resolution.identity,
1763
+ ...taskScope(toolCtx),
1764
+ // Redundant checked assertion. Authority came from the current
1765
+ // conversation focus above, never from the model's parameters.
1766
+ task_id: resolution.taskId,
1767
+ base_revision: Number(params.base_revision ?? 0),
1768
+ // Derived from stable host identifiers, never from payload content
1769
+ // or a clock, so a retried tool call collapses to one decision.
1770
+ idempotency_key: `${toolCtx.runId ?? "run"}:${toolCallId}`,
1771
+ operations: [
1772
+ {
1773
+ kind: "set_item_status",
1774
+ item_id: String(params.item_id ?? ""),
1775
+ status: String(params.status ?? ""),
1776
+ reason: params.reason ? String(params.reason) : undefined,
1777
+ },
1778
+ ],
1779
+ adapter: "openclaw",
1780
+ // The tool call is the evidence. Completing an item requires some,
1781
+ // and a host reporting its own tool outcome is asserting rather
1782
+ // than independently verifying -- AtMem records it at exactly that
1783
+ // assurance and never upgrades it.
1784
+ evidence: [
1785
+ { kind: "tool_call", reference_id: `${toolCtx.runId ?? "run"}-${toolCallId}` },
1786
+ ],
1787
+ reason: params.reason ? String(params.reason) : "",
1788
+ }));
1789
+ return {
1790
+ content: [{ type: "text", text: describeDecision(result) }],
1791
+ details: { outcome: result.outcome ?? result.reason_code ?? null },
1792
+ };
1793
+ },
1794
+ }), { name: "task_report_progress" });
1795
+ api.registerTool((toolCtx) => ({
1796
+ name: "task_binding_status",
1797
+ label: "Governed Task Binding (atmem)",
1798
+ description: "Show which governed task, if any, this conversation is bound to, and " +
1799
+ "the exact command to bind it. Owner only.",
1800
+ parameters: { type: "object", properties: {} },
1801
+ async execute() {
1802
+ if (!isConversationOwner(toolCtx))
1803
+ return refusal(NOT_OWNER_MESSAGE);
1804
+ const identity = sessionIdentityForTool(toolCtx);
1805
+ if (!identity)
1806
+ return refusal(NO_IDENTITY_MESSAGE);
1807
+ const prepared = (await callFor(toolCtx, "control_prepare_task_context", {
1808
+ ...identity,
1809
+ ...taskScope(toolCtx),
1810
+ }));
1811
+ // Binding stays an authenticated operator action at the terminal, so
1812
+ // the owner needs their own conversation's identity to run it. They
1813
+ // cannot see it otherwise -- it is an internal host value -- and
1814
+ // without it the whole feature is unreachable from inside OpenClaw.
1815
+ // Handing the owner a ready-to-run command is the same "one useful
1816
+ // next command" the CLI gives everywhere else. This discloses nothing
1817
+ // a non-owner can obtain: the gate above already refused them.
1818
+ const bindCommand = `atmem task bind DB_PATH TASK_ID --subject SUBJECT ` +
1819
+ `--agent ${agentIdFor(toolCtx)} --workspace ${workspaceIdFor(toolCtx) ?? "WORKSPACE"} ` +
1820
+ `--actor YOU --reason WHY --host-type ${identity.host_type} ` +
1821
+ `--session-key ${identity.session_key} --session-epoch ${identity.session_epoch} --yes`;
1822
+ if (prepared.disposition !== "injected") {
1823
+ return ok({
1824
+ bound: false,
1825
+ reason: (prepared.reason_codes ?? []).join(", ") || "not bound",
1826
+ bind_with: bindCommand,
1827
+ });
1828
+ }
1829
+ return ok({
1830
+ bound: true,
1831
+ task_id: prepared.task_id ?? null,
1832
+ rebind_with: bindCommand,
1833
+ });
1834
+ },
1835
+ }), { name: "task_binding_status" });
1633
1836
  }
1634
1837
  api.logger.info(`${TAG} registered (db=${cfg.dbPath}, subject=${cfg.subject}, ` +
1635
1838
  `recall=${cfg.recall.enabled}, capture=${cfg.capture.enabled}, ` +
@@ -128,7 +128,7 @@ export class AtmemClient {
128
128
  capabilities: {},
129
129
  clientInfo: {
130
130
  name: "openclaw-memory-atmem",
131
- version: "2.2.6-beta.1",
131
+ version: "2.2.6-beta.10",
132
132
  },
133
133
  });
134
134
  this.notify("notifications/initialized", {});
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Model- and owner-facing governed task tools.
3
+ *
4
+ * Spec 007 Amendment A, FR-049 path (b) and FR-050.
5
+ *
6
+ * A manager method and an MCP operation are invisible to a model. For an agent
7
+ * to report progress at all, a tool has to be registered with the host through
8
+ * the same mechanism that publishes `memory_search`. That is what this file is.
9
+ *
10
+ * Two audiences, deliberately separated:
11
+ *
12
+ * - `task_*` tools the model calls. They resolve through the conversation's
13
+ * own binding, so a model can only affect the task its conversation is bound
14
+ * to, and every outcome is reported back in words the model can act on -- a
15
+ * rejection it cannot interpret is a rejection it will retry blindly.
16
+ * - `task_bind` / `task_unbind` / `task_binding_status`, which an operator
17
+ * runs from inside the conversation. These are gated on the host's own owner
18
+ * signal. That signal is optional upstream, so anything other than an
19
+ * explicit `true` is treated as *not* the owner: absence is never permission.
20
+ */
21
+ /** The one place identity is derived, so no caller can assemble a partial one. */
22
+ export function sessionIdentityForTool(ctx) {
23
+ const sessionKey = ctx.sessionKey ?? ctx.sessionId;
24
+ const sessionEpoch = ctx.sessionId;
25
+ if (!sessionKey || !sessionEpoch)
26
+ return undefined;
27
+ return {
28
+ host_type: "openclaw",
29
+ session_key: sessionKey,
30
+ session_epoch: sessionEpoch,
31
+ };
32
+ }
33
+ /** Resolve authority from the authenticated conversation, never model input. */
34
+ export async function resolveBoundTaskForTool(ctx, prepare) {
35
+ const identity = sessionIdentityForTool(ctx);
36
+ if (!identity) {
37
+ return { ok: false, message: NO_IDENTITY_MESSAGE, reasonCodes: ["host_identity_missing"] };
38
+ }
39
+ const prepared = (await prepare(identity));
40
+ if (prepared.disposition !== "injected" || !prepared.task_id) {
41
+ const reasons = (prepared.reason_codes ?? []).map(String);
42
+ return {
43
+ ok: false,
44
+ message: "This conversation has no active governed task focus. " +
45
+ "No task progress was recorded.",
46
+ reasonCodes: reasons.length ? reasons : ["task_context_selection_required"],
47
+ };
48
+ }
49
+ return {
50
+ ok: true,
51
+ identity,
52
+ taskId: String(prepared.task_id),
53
+ revision: prepared.revision,
54
+ };
55
+ }
56
+ /** Absence is never permission. Only an explicit affirmative is the owner. */
57
+ export function isConversationOwner(ctx) {
58
+ return ctx.senderIsOwner === true;
59
+ }
60
+ /**
61
+ * Turn one AtMem decision into something a model can act on.
62
+ *
63
+ * The outcome vocabulary is small and each value implies a different next
64
+ * move, so saying which one it is matters more than saying it failed.
65
+ */
66
+ export function describeDecision(result) {
67
+ const outcome = String(result.outcome ?? "");
68
+ const reasons = Array.isArray(result.reason_codes)
69
+ ? result.reason_codes.join(", ")
70
+ : String(result.reason_code ?? "");
71
+ switch (outcome) {
72
+ case "accepted":
73
+ return `Recorded. The task is now at revision ${result.resulting_revision}.`;
74
+ case "no_change":
75
+ return `No change: the task already reflects this (${reasons}).`;
76
+ case "conflict":
77
+ return (`Conflict: the task moved while you were working (${reasons}). ` +
78
+ "Read it again with task_state and submit against the revision you get back.");
79
+ case "rejected":
80
+ return `Rejected (${reasons}). Do not retry this unchanged; the reason explains what AtMem will accept.`;
81
+ default:
82
+ break;
83
+ }
84
+ if (result.reason_code) {
85
+ return `Not applied (${result.reason_code}): ${String(result.message ?? "")}`;
86
+ }
87
+ return String(result.message ?? "No decision was returned.");
88
+ }
89
+ /** A refusal shaped like every other tool result, so a model reads one thing. */
90
+ export function refusal(message) {
91
+ return {
92
+ content: [{ type: "text", text: JSON.stringify({ ok: false, message }) }],
93
+ };
94
+ }
95
+ export function ok(payload) {
96
+ return {
97
+ content: [{ type: "text", text: JSON.stringify({ ok: true, ...payload }) }],
98
+ };
99
+ }
100
+ export const NOT_OWNER_MESSAGE =
101
+ // Identical whether a binding exists or not: a non-owner must not be able to
102
+ // learn what this conversation is bound to by asking.
103
+ "Only the owner of this conversation can manage its governed task binding.";
104
+ export const NO_IDENTITY_MESSAGE = "This conversation has no usable session identity, so AtMem cannot tell " +
105
+ "which conversation it is. No task binding can be resolved or created.";
@@ -2,7 +2,7 @@
2
2
  "id": "memory-atmem",
3
3
  "name": "Memory (atmem)",
4
4
  "description": "OpenClaw bridge installed and managed by the AtMem memory control plane.",
5
- "version": "2.2.6-beta.1",
5
+ "version": "2.2.6-beta.10",
6
6
  "commandAliases": ["memory-atmem"],
7
7
  "activation": {
8
8
  "onStartup": true,
@@ -16,7 +16,9 @@
16
16
  "atmem_search",
17
17
  "atmem_forget",
18
18
  "atmem_observe",
19
- "atmem_forget_artifact"
19
+ "atmem_forget_artifact",
20
+ "task_report_progress",
21
+ "task_binding_status"
20
22
  ]
21
23
  },
22
24
  "configSchema": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclaw-memory-atmem",
3
- "version": "2.2.6-beta.1",
3
+ "version": "2.2.6-beta.10",
4
4
  "description": "OpenClaw Agent Black Box and memory control-plane bridge for AtMem",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -40,9 +40,11 @@
40
40
  "scripts": {
41
41
  "build": "tsc -p tsconfig.json",
42
42
  "typecheck": "tsc -p tsconfig.json --noEmit",
43
- "test": "node test/setup.mjs && node test/hooks.mjs && node test/delegated-context-contract.mjs",
44
- "smoke": "node test/smoke.mjs",
45
- "prepack": "npm run build && npm run typecheck && npm test && npm run smoke"
43
+ "test": "node test/manifest.mjs && node test/hook-context-compat.mjs && node test/setup.mjs && node test/hooks.mjs && node test/task-tools.mjs && node test/delegated-context-contract.mjs",
44
+ "smoke": "node test/smoke.mjs && node test/task-journey.mjs && node test/delegated-journey.mjs",
45
+ "prepack": "npm run build && npm run typecheck && npm test && npm run smoke",
46
+ "hook-context": "node test/hook-context-compat.mjs",
47
+ "record-hook-context": "node test/lib/record-hook-context.mjs"
46
48
  },
47
49
  "devDependencies": {
48
50
  "@types/node": "^22.20.1",