@onemem/oc-onemem 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Support. While redistributing the Work or
166
+ Derivative Works thereof, You may choose to offer, and charge a
167
+ fee for, acceptance of support, warranty, indemnity, or other
168
+ liability obligations and/or rights consistent with this License.
169
+ However, in accepting such obligations, You may act only on Your
170
+ own behalf and on Your sole responsibility, not on behalf of any
171
+ other Contributor, and only if You agree to indemnify, defend,
172
+ and hold each Contributor harmless for any liability incurred by,
173
+ or claims asserted against, such Contributor by reason of your
174
+ accepting any such warranty or support.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 OneMem contributors
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # @onemem/oc-onemem
2
+
3
+ OneMem plugin for **OpenClaw** — a strict superset of Mysten's `oc-memwal`:
4
+ delegates to it for Walrus-backed memory, then **adds a verifiable on-chain
5
+ trace** (each agent run → a OneMem `TraceSession` of Merkle-chained
6
+ `ActionCall`s).
7
+
8
+ ## How it works
9
+
10
+ OpenClaw discovers the plugin via `package.json` → `openclaw.extensions`. On
11
+ `register(api)` it:
12
+ 1. calls `ocMemwal.register(api)` — all Walrus memory (recall + capture);
13
+ 2. registers OneMem trace hooks on the real OpenClaw events:
14
+ - `agent_start` → open a OneMem TraceSession (in-memory, keyed by session);
15
+ - `tool_execution_end` / `tool_call` → buffer the tool call (instant);
16
+ - `agent_end` → flush buffered calls as Seal-encrypted, Walrus-stored,
17
+ Merkle-chained `ActionCall`s + close the session.
18
+
19
+ All trace work is defensive — a OneMem failure never breaks the agent.
20
+
21
+ ## Configure (env)
22
+
23
+ `ONEMEM_NAMESPACE_ID` + `ONEMEM_RW_CAP_ID` (record target), `ONEMEM_PRIVATE_KEY`
24
+ (else sui keystore), `SUI_NETWORK`. Without them, trace is inert (memory still
25
+ works).
26
+
27
+ ## Status
28
+
29
+ Built + typechecks/builds against the real `openclaw` (2026.6.6) + `oc-memwal`
30
+ (0.0.4); OpenClaw's installer accepts the manifest. The live agent-turn e2e
31
+ needs a **self-contained install** — OpenClaw's deep security scan rejects pnpm
32
+ workspace symlinks, so it requires the plugin published (with `@onemem/sdk-ts`
33
+ on npm) or installed from a deps-bundled tarball. Tracked for the npm-publish
34
+ milestone.
35
+
36
+ Spec: `docs/05-our-architecture/03-runtimes/openclaw-plugin.md`.
package/dist/index.js ADDED
@@ -0,0 +1,150 @@
1
+ // src/onemem-trace.ts
2
+ import { readFileSync } from "fs";
3
+ import { homedir } from "os";
4
+ import { join } from "path";
5
+ import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
6
+ import { CallStatus, OneMem, SessionStatus } from "@onemem/sdk-ts";
7
+ function loadConfig() {
8
+ const namespaceId = process.env.ONEMEM_NAMESPACE_ID;
9
+ const rwCapId = process.env.ONEMEM_RW_CAP_ID;
10
+ if (!namespaceId || !rwCapId) return null;
11
+ return {
12
+ namespaceId,
13
+ rwCapId,
14
+ network: process.env.SUI_NETWORK ?? "testnet",
15
+ privateKey: process.env.ONEMEM_PRIVATE_KEY
16
+ };
17
+ }
18
+ function loadSigner(privateKey) {
19
+ if (privateKey) return Ed25519Keypair.fromSecretKey(privateKey);
20
+ const path = join(homedir(), ".sui", "sui_config", "sui.keystore");
21
+ const entries = JSON.parse(readFileSync(path, "utf8"));
22
+ return Ed25519Keypair.fromSecretKey(Buffer.from(entries[0], "base64").subarray(1));
23
+ }
24
+ var TraceRecorder = class {
25
+ constructor(config) {
26
+ this.config = config;
27
+ }
28
+ config;
29
+ client = null;
30
+ sessions = /* @__PURE__ */ new Map();
31
+ async getClient() {
32
+ if (!this.client) {
33
+ this.client = await OneMem.create({
34
+ network: this.config.network,
35
+ signer: loadSigner(this.config.privateKey)
36
+ });
37
+ }
38
+ return this.client;
39
+ }
40
+ /** agent_start → open a OneMem TraceSession for this agent run. */
41
+ async start(sessionKey) {
42
+ try {
43
+ if (this.sessions.has(sessionKey)) return;
44
+ const onemem = await this.getClient();
45
+ const session = await onemem.traces.startSession({
46
+ namespaceId: this.config.namespaceId,
47
+ rwCapId: this.config.rwCapId,
48
+ agentId: "openclaw",
49
+ environment: "openclaw",
50
+ sdkVersion: "0.1.0"
51
+ });
52
+ this.sessions.set(sessionKey, { onememSessionId: session.sessionId, calls: [] });
53
+ } catch {
54
+ }
55
+ }
56
+ /** tool_execution_end → buffer the tool call (flushed on agent_end). */
57
+ record(sessionKey, call) {
58
+ this.sessions.get(sessionKey)?.calls.push(call);
59
+ }
60
+ /** agent_end → flush buffered calls as ActionCalls + close the session. */
61
+ async end(sessionKey) {
62
+ const entry = this.sessions.get(sessionKey);
63
+ if (!entry) return null;
64
+ this.sessions.delete(sessionKey);
65
+ try {
66
+ const onemem = await this.getClient();
67
+ const enc = (v) => new TextEncoder().encode(typeof v === "string" ? v : JSON.stringify(v ?? ""));
68
+ let parentCallId = null;
69
+ for (const call of entry.calls) {
70
+ const emitted = await onemem.traces.appendCall({
71
+ sessionId: entry.onememSessionId,
72
+ namespaceId: this.config.namespaceId,
73
+ rwCapId: this.config.rwCapId,
74
+ parentCallId,
75
+ toolName: call.toolName,
76
+ toolNamespace: "openclaw",
77
+ inputContent: enc(call.input),
78
+ encrypt: true
79
+ });
80
+ await onemem.traces.closeCall({
81
+ sessionId: entry.onememSessionId,
82
+ rwCapId: this.config.rwCapId,
83
+ namespaceId: this.config.namespaceId,
84
+ callId: emitted.callId,
85
+ outputContent: enc(call.output),
86
+ encrypt: true,
87
+ status: CallStatus.Success
88
+ });
89
+ parentCallId = emitted.callId;
90
+ }
91
+ await onemem.traces.endSession({
92
+ sessionId: entry.onememSessionId,
93
+ rwCapId: this.config.rwCapId,
94
+ status: SessionStatus.Completed
95
+ });
96
+ return entry.onememSessionId;
97
+ } catch {
98
+ return null;
99
+ }
100
+ }
101
+ };
102
+
103
+ // src/index.ts
104
+ async function delegateToOcMemwal(api) {
105
+ try {
106
+ const mod = await import("@mysten-incubation/oc-memwal");
107
+ mod.default?.register?.(api);
108
+ } catch {
109
+ }
110
+ }
111
+ function sessionKeyOf(event) {
112
+ const session = event.session;
113
+ return event.sessionKey ?? event.sessionId ?? session?.key ?? session?.id ?? "default";
114
+ }
115
+ var plugin = {
116
+ id: "oc-onemem",
117
+ name: "OneMem",
118
+ description: "Verifiable on-chain memory + action traces for OpenClaw (superset of oc-memwal).",
119
+ kind: "memory",
120
+ register(api) {
121
+ void delegateToOcMemwal(api);
122
+ const config = loadConfig();
123
+ if (!config || !api.registerHook) {
124
+ api.logger?.info?.("[oc-onemem] trace inert (set ONEMEM_NAMESPACE_ID + ONEMEM_RW_CAP_ID)");
125
+ return;
126
+ }
127
+ const recorder = new TraceRecorder(config);
128
+ api.registerHook("agent_start", async (event) => {
129
+ await recorder.start(sessionKeyOf(event));
130
+ });
131
+ api.registerHook(["tool_execution_end", "tool_call"], (event) => {
132
+ const tool = event.tool;
133
+ const toolName = event.toolName ?? tool?.name ?? event.name ?? "tool";
134
+ recorder.record(sessionKeyOf(event), {
135
+ toolName,
136
+ input: event.input ?? event.args ?? event.params ?? null,
137
+ output: event.output ?? event.result ?? event.response ?? null
138
+ });
139
+ });
140
+ api.registerHook("agent_end", async (event) => {
141
+ const sessionId = await recorder.end(sessionKeyOf(event));
142
+ if (sessionId) api.logger?.info?.(`[oc-onemem] verifiable trace ${sessionId}`);
143
+ });
144
+ }
145
+ };
146
+ var index_default = plugin;
147
+ export {
148
+ index_default as default
149
+ };
150
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/onemem-trace.ts","../src/index.ts"],"sourcesContent":["// OneMem trace recorder for the OpenClaw plugin.\n//\n// An OpenClaw plugin runs in one long-lived process, so per-session trace state\n// lives in an in-memory map (no cross-process file needed, unlike the Claude\n// Code hooks). Defensive throughout: a OneMem failure must never break the\n// agent, so callers swallow errors.\n\nimport { readFileSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { Ed25519Keypair } from \"@mysten/sui/keypairs/ed25519\";\n\nimport { CallStatus, OneMem, SessionStatus } from \"@onemem/sdk-ts\";\n\nexport interface TraceConfig {\n namespaceId: string;\n rwCapId: string;\n network: \"testnet\" | \"mainnet\" | \"devnet\" | \"local\";\n privateKey?: string;\n}\n\n/** OneMem config from env, or null (plugin then records nothing). */\nexport function loadConfig(): TraceConfig | null {\n const namespaceId = process.env.ONEMEM_NAMESPACE_ID;\n const rwCapId = process.env.ONEMEM_RW_CAP_ID;\n if (!namespaceId || !rwCapId) return null;\n return {\n namespaceId,\n rwCapId,\n network: (process.env.SUI_NETWORK as TraceConfig[\"network\"]) ?? \"testnet\",\n privateKey: process.env.ONEMEM_PRIVATE_KEY,\n };\n}\n\nfunction loadSigner(privateKey?: string): Ed25519Keypair {\n if (privateKey) return Ed25519Keypair.fromSecretKey(privateKey);\n const path = join(homedir(), \".sui\", \"sui_config\", \"sui.keystore\");\n const entries = JSON.parse(readFileSync(path, \"utf8\")) as string[];\n return Ed25519Keypair.fromSecretKey(Buffer.from(entries[0]!, \"base64\").subarray(1));\n}\n\ninterface BufferedCall {\n toolName: string;\n input: unknown;\n output: unknown;\n}\n\ninterface SessionEntry {\n onememSessionId: string;\n calls: BufferedCall[];\n}\n\n/**\n * Records OpenClaw agent activity as a verifiable OneMem trace: open a session\n * per agent run, buffer tool calls, flush them as Merkle-chained ActionCalls at\n * the end. One recorder instance per plugin process.\n */\nexport class TraceRecorder {\n private client: OneMem | null = null;\n private readonly sessions = new Map<string, SessionEntry>();\n\n constructor(private readonly config: TraceConfig) {}\n\n private async getClient(): Promise<OneMem> {\n if (!this.client) {\n this.client = await OneMem.create({\n network: this.config.network,\n signer: loadSigner(this.config.privateKey),\n });\n }\n return this.client;\n }\n\n /** agent_start → open a OneMem TraceSession for this agent run. */\n async start(sessionKey: string): Promise<void> {\n try {\n if (this.sessions.has(sessionKey)) return;\n const onemem = await this.getClient();\n const session = await onemem.traces.startSession({\n namespaceId: this.config.namespaceId,\n rwCapId: this.config.rwCapId,\n agentId: \"openclaw\",\n environment: \"openclaw\",\n sdkVersion: \"0.1.0\",\n });\n this.sessions.set(sessionKey, { onememSessionId: session.sessionId, calls: [] });\n } catch {\n // never break the agent\n }\n }\n\n /** tool_execution_end → buffer the tool call (flushed on agent_end). */\n record(sessionKey: string, call: BufferedCall): void {\n this.sessions.get(sessionKey)?.calls.push(call);\n }\n\n /** agent_end → flush buffered calls as ActionCalls + close the session. */\n async end(sessionKey: string): Promise<string | null> {\n const entry = this.sessions.get(sessionKey);\n if (!entry) return null;\n this.sessions.delete(sessionKey);\n try {\n const onemem = await this.getClient();\n const enc = (v: unknown) =>\n new TextEncoder().encode(typeof v === \"string\" ? v : JSON.stringify(v ?? \"\"));\n let parentCallId: string | null = null;\n for (const call of entry.calls) {\n const emitted = await onemem.traces.appendCall({\n sessionId: entry.onememSessionId,\n namespaceId: this.config.namespaceId,\n rwCapId: this.config.rwCapId,\n parentCallId,\n toolName: call.toolName,\n toolNamespace: \"openclaw\",\n inputContent: enc(call.input),\n encrypt: true,\n });\n await onemem.traces.closeCall({\n sessionId: entry.onememSessionId,\n rwCapId: this.config.rwCapId,\n namespaceId: this.config.namespaceId,\n callId: emitted.callId,\n outputContent: enc(call.output),\n encrypt: true,\n status: CallStatus.Success,\n });\n parentCallId = emitted.callId;\n }\n await onemem.traces.endSession({\n sessionId: entry.onememSessionId,\n rwCapId: this.config.rwCapId,\n status: SessionStatus.Completed,\n });\n return entry.onememSessionId;\n } catch {\n return null;\n }\n }\n}\n","// @onemem/oc-onemem — OpenClaw plugin.\n//\n// Strict superset of Mysten's oc-memwal: delegates to it for Walrus-backed\n// memory (recall/capture), then ADDS a verifiable on-chain trace — each agent\n// run becomes a OneMem TraceSession with Merkle-chained ActionCalls.\n//\n// Config via env: ONEMEM_NAMESPACE_ID + ONEMEM_RW_CAP_ID (the OneMem namespace\n// + ReadWrite cap to record into), ONEMEM_PRIVATE_KEY (else sui keystore),\n// SUI_NETWORK. Without them, trace recording is inert (memory still works).\n//\n// Spec: docs/05-our-architecture/03-runtimes/openclaw-plugin.md\n\nimport { loadConfig, TraceRecorder } from \"./onemem-trace.js\";\n\n// oc-memwal is an OPTIONAL peer: when installed, we delegate to it for\n// Walrus-backed memory; when absent (or its broken 0.0.4 publish can't install),\n// OneMem still provides the verifiable trace layer standalone. Loaded\n// dynamically so a missing dep never breaks plugin load.\nasync function delegateToOcMemwal(api: unknown): Promise<void> {\n try {\n const mod = (await import(\"@mysten-incubation/oc-memwal\")) as {\n default?: { register?: (api: unknown) => void };\n };\n mod.default?.register?.(api);\n } catch {\n // oc-memwal not present — trace layer works without it.\n }\n}\n\n// OpenClaw's plugin api is large + version-bundled; we use only a couple seams\n// (registerHook + logger), typed loosely to stay resilient across versions.\ninterface OpenClawApi {\n logger?: { info?: (msg: string) => void; warn?: (msg: string) => void };\n registerHook?: (\n events: string | string[],\n handler: (event: Record<string, unknown>) => unknown,\n ) => void;\n [k: string]: unknown;\n}\n\n/** Best-effort session-key extraction across OpenClaw event shapes. */\nfunction sessionKeyOf(event: Record<string, unknown>): string {\n const session = event.session as { key?: string; id?: string } | undefined;\n return (\n (event.sessionKey as string) ??\n (event.sessionId as string) ??\n session?.key ??\n session?.id ??\n \"default\"\n );\n}\n\nconst plugin = {\n id: \"oc-onemem\",\n name: \"OneMem\",\n description: \"Verifiable on-chain memory + action traces for OpenClaw (superset of oc-memwal).\",\n kind: \"memory\" as const,\n register(api: OpenClawApi): void {\n // 1) Delegate to oc-memwal (optional) — Walrus-backed memory when present.\n void delegateToOcMemwal(api);\n\n // 2) Add the OneMem verifiable trace layer.\n const config = loadConfig();\n if (!config || !api.registerHook) {\n api.logger?.info?.(\"[oc-onemem] trace inert (set ONEMEM_NAMESPACE_ID + ONEMEM_RW_CAP_ID)\");\n return;\n }\n const recorder = new TraceRecorder(config);\n\n api.registerHook(\"agent_start\", async (event) => {\n await recorder.start(sessionKeyOf(event));\n });\n\n api.registerHook([\"tool_execution_end\", \"tool_call\"], (event) => {\n const tool = event.tool as { name?: string } | undefined;\n const toolName = (event.toolName as string) ?? tool?.name ?? (event.name as string) ?? \"tool\";\n recorder.record(sessionKeyOf(event), {\n toolName,\n input: event.input ?? event.args ?? event.params ?? null,\n output: event.output ?? event.result ?? event.response ?? null,\n });\n });\n\n api.registerHook(\"agent_end\", async (event) => {\n const sessionId = await recorder.end(sessionKeyOf(event));\n if (sessionId) api.logger?.info?.(`[oc-onemem] verifiable trace ${sessionId}`);\n });\n },\n};\n\nexport default plugin;\n"],"mappings":";AAOA,SAAS,oBAAoB;AAC7B,SAAS,eAAe;AACxB,SAAS,YAAY;AACrB,SAAS,sBAAsB;AAE/B,SAAS,YAAY,QAAQ,qBAAqB;AAU3C,SAAS,aAAiC;AAC/C,QAAM,cAAc,QAAQ,IAAI;AAChC,QAAM,UAAU,QAAQ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plugin for OpenClaw — adds verifiable on-chain action traces on top of oc-memwal",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "openclaw": {
9
+ "extensions": [
10
+ "./dist/index.js"
11
+ ]
12
+ },
13
+ "files": [
14
+ "dist",
15
+ "README.md",
16
+ "LICENSE"
17
+ ],
18
+ "dependencies": {
19
+ "@mysten/sui": "^2.17.0",
20
+ "@onemem/sdk-ts": "0.1.0"
21
+ },
22
+ "optionalDependencies": {
23
+ "@mysten-incubation/oc-memwal": "^0.0.4"
24
+ },
25
+ "peerDependencies": {
26
+ "openclaw": ">=2026.6.0"
27
+ },
28
+ "peerDependenciesMeta": {
29
+ "openclaw": {
30
+ "optional": true
31
+ }
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^25.9.3",
35
+ "tsup": "^8.3.0",
36
+ "typescript": "^5.7.0",
37
+ "vitest": "^2.1.0"
38
+ },
39
+ "scripts": {
40
+ "build": "tsup",
41
+ "test": "vitest run --passWithNoTests",
42
+ "typecheck": "tsc --noEmit",
43
+ "lint": "biome check ."
44
+ }
45
+ }