@clawtrail/context-graph-openclaw 0.7.4 → 0.8.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/README.md +64 -56
- package/dist/OpenClawAdapter.d.ts +6 -6
- package/dist/OpenClawAdapter.d.ts.map +1 -1
- package/dist/OpenClawAdapter.js +46 -36
- package/dist/OpenClawAdapter.js.map +1 -1
- package/dist/detectors/BuildDetector.js +11 -11
- package/dist/detectors/HttpDetector.d.ts.map +1 -1
- package/dist/detectors/HttpDetector.js +20 -17
- package/dist/detectors/HttpDetector.js.map +1 -1
- package/dist/detectors/TestDetector.js +9 -9
- package/dist/hooks/lifecycle.d.ts +1 -1
- package/dist/hooks/lifecycle.js +4 -4
- package/dist/hooks/llmOutput.d.ts +2 -2
- package/dist/hooks/llmOutput.js +5 -5
- package/dist/hooks/toolCall.d.ts +3 -3
- package/dist/hooks/toolCall.d.ts.map +1 -1
- package/dist/hooks/toolCall.js +4 -4
- package/dist/hooks/toolCall.js.map +1 -1
- package/dist/index.d.ts +29 -29
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -18
- package/dist/index.js.map +1 -1
- package/dist/mappers/MapperRegistry.d.ts +4 -0
- package/dist/mappers/MapperRegistry.d.ts.map +1 -1
- package/dist/mappers/MapperRegistry.js +8 -0
- package/dist/mappers/MapperRegistry.js.map +1 -1
- package/dist/mappers/browser.d.ts +11 -0
- package/dist/mappers/browser.d.ts.map +1 -0
- package/dist/mappers/browser.js +66 -0
- package/dist/mappers/browser.js.map +1 -0
- package/dist/mappers/document.d.ts +7 -0
- package/dist/mappers/document.d.ts.map +1 -0
- package/dist/mappers/document.js +49 -0
- package/dist/mappers/document.js.map +1 -0
- package/dist/mappers/fallback.d.ts +1 -1
- package/dist/mappers/fallback.js +3 -3
- package/dist/mappers/fs.d.ts +1 -1
- package/dist/mappers/fs.d.ts.map +1 -1
- package/dist/mappers/fs.js +11 -11
- package/dist/mappers/fs.js.map +1 -1
- package/dist/mappers/git.d.ts +1 -1
- package/dist/mappers/git.d.ts.map +1 -1
- package/dist/mappers/git.js +21 -14
- package/dist/mappers/git.js.map +1 -1
- package/dist/mappers/message.d.ts +11 -0
- package/dist/mappers/message.d.ts.map +1 -0
- package/dist/mappers/message.js +72 -0
- package/dist/mappers/message.js.map +1 -0
- package/dist/mappers/session.d.ts +12 -0
- package/dist/mappers/session.d.ts.map +1 -0
- package/dist/mappers/session.js +71 -0
- package/dist/mappers/session.js.map +1 -0
- package/dist/mappers/shell.d.ts +4 -4
- package/dist/mappers/shell.d.ts.map +1 -1
- package/dist/mappers/shell.js +17 -15
- package/dist/mappers/shell.js.map +1 -1
- package/dist/mappers/web.d.ts +11 -0
- package/dist/mappers/web.d.ts.map +1 -0
- package/dist/mappers/web.js +89 -0
- package/dist/mappers/web.js.map +1 -0
- package/dist/register.d.ts.map +1 -1
- package/dist/register.js +123 -4
- package/dist/register.js.map +1 -1
- package/dist/rules/openclaw-rules.d.ts +7 -1
- package/dist/rules/openclaw-rules.d.ts.map +1 -1
- package/dist/rules/openclaw-rules.js +321 -120
- package/dist/rules/openclaw-rules.js.map +1 -1
- package/dist/tools/status.d.ts +1 -1
- package/dist/tools/status.js +3 -3
- package/dist/tools/summarize.d.ts +1 -1
- package/dist/tools/summarize.d.ts.map +1 -1
- package/dist/tools/summarize.js +5 -5
- package/dist/tools/summarize.js.map +1 -1
- package/dist/util/hash.d.ts +3 -1
- package/dist/util/hash.d.ts.map +1 -1
- package/dist/util/hash.js +64 -43
- package/dist/util/hash.js.map +1 -1
- package/openclaw.plugin.json +5 -1
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -80,19 +80,19 @@ The plugin hooks into OpenClaw's `session_start`, `session_end`, `before_tool_ca
|
|
|
80
80
|
You can use the adapter directly in any Node.js environment:
|
|
81
81
|
|
|
82
82
|
```typescript
|
|
83
|
-
import { OpenClawAdapter } from
|
|
83
|
+
import { OpenClawAdapter } from "@origintrail/context-graph-openclaw";
|
|
84
84
|
|
|
85
85
|
const adapter = new OpenClawAdapter({
|
|
86
|
-
contextGraphRoot:
|
|
87
|
-
agentId:
|
|
86
|
+
contextGraphRoot: ".context-graph",
|
|
87
|
+
agentId: "agent:my-agent",
|
|
88
88
|
detectTests: true,
|
|
89
89
|
detectBuilds: true,
|
|
90
90
|
});
|
|
91
91
|
|
|
92
92
|
// Create a mock context (or use your own session management)
|
|
93
93
|
const ctx = {
|
|
94
|
-
sessionKey:
|
|
95
|
-
initialMessage:
|
|
94
|
+
sessionKey: "session-1",
|
|
95
|
+
initialMessage: "Fix the auth bug",
|
|
96
96
|
set: (k, v) => sessionStore.set(k, v),
|
|
97
97
|
get: (k) => sessionStore.get(k),
|
|
98
98
|
};
|
|
@@ -101,30 +101,36 @@ const ctx = {
|
|
|
101
101
|
await adapter.onSessionStart(ctx);
|
|
102
102
|
|
|
103
103
|
// Feed tool call results as they happen
|
|
104
|
-
await adapter.onAfterToolCall(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
104
|
+
await adapter.onAfterToolCall(
|
|
105
|
+
{
|
|
106
|
+
toolName: "bash",
|
|
107
|
+
params: { command: "npm test" },
|
|
108
|
+
result: { stdout: "Tests: 5 passed, 0 failed", exitCode: 0 },
|
|
109
|
+
durationMs: 3200,
|
|
110
|
+
},
|
|
111
|
+
ctx,
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
await adapter.onAfterToolCall(
|
|
115
|
+
{
|
|
116
|
+
toolName: "write",
|
|
117
|
+
params: { path: "src/auth.ts" },
|
|
118
|
+
result: { content: "...", bytesWritten: 200 },
|
|
119
|
+
durationMs: 15,
|
|
120
|
+
},
|
|
121
|
+
ctx,
|
|
122
|
+
);
|
|
117
123
|
|
|
118
124
|
// End session
|
|
119
125
|
await adapter.onSessionEnd(ctx);
|
|
120
126
|
|
|
121
127
|
// Summarize + sign
|
|
122
|
-
const sessionId = ctx.get(
|
|
128
|
+
const sessionId = ctx.get("cg:session_id");
|
|
123
129
|
const { summary, signed } = await adapter.summarizeAndSign(sessionId);
|
|
124
130
|
|
|
125
|
-
console.log(summary.claims);
|
|
126
|
-
console.log(signed.payloadHash);
|
|
127
|
-
console.log(signed.signature);
|
|
131
|
+
console.log(summary.claims); // [{ type: 'cg:CanRunTests', confidence: 0.8, scope: 'jest' }]
|
|
132
|
+
console.log(signed.payloadHash); // sha256:...
|
|
133
|
+
console.log(signed.signature); // base64 Ed25519 signature
|
|
128
134
|
|
|
129
135
|
// Verify the signature (e.g. on the ClawTrail server side)
|
|
130
136
|
const valid = OpenClawAdapter.verifySubmission(signed);
|
|
@@ -133,16 +139,16 @@ console.log(valid); // true
|
|
|
133
139
|
|
|
134
140
|
## How tool calls are mapped
|
|
135
141
|
|
|
136
|
-
| OpenClaw tool
|
|
137
|
-
|
|
138
|
-
| `bash` / `shell`
|
|
139
|
-
| ↳ if test detected
|
|
140
|
-
| ↳ if build detected | `BUILD_RUN`
|
|
141
|
-
| `read`
|
|
142
|
-
| `write` / `edit`
|
|
143
|
-
| `git` (diff)
|
|
144
|
-
| `git` (commit)
|
|
145
|
-
| anything else
|
|
142
|
+
| OpenClaw tool | Event type | What's captured |
|
|
143
|
+
| ------------------- | --------------- | ----------------------------------------------- |
|
|
144
|
+
| `bash` / `shell` | `SHELL_COMMAND` | cmd hash, exit code, stdout/stderr hash |
|
|
145
|
+
| ↳ if test detected | `TEST_RUN` | framework, passed, failed, skipped |
|
|
146
|
+
| ↳ if build detected | `BUILD_RUN` | tool, error count, warning count |
|
|
147
|
+
| `read` | `FILE_READ` | path hash, extension, byte count |
|
|
148
|
+
| `write` / `edit` | `FILE_WRITE` | path hash, extension, diff hash, byte count |
|
|
149
|
+
| `git` (diff) | `GIT_DIFF` | diff hash, files changed, insertions, deletions |
|
|
150
|
+
| `git` (commit) | `GIT_COMMIT` | commit hash, message hash |
|
|
151
|
+
| anything else | `TOOL_CALL` | tool name, args hash, result hash |
|
|
146
152
|
|
|
147
153
|
### Auto-detected test frameworks
|
|
148
154
|
|
|
@@ -164,10 +170,12 @@ Every submission is signed with **Ed25519**:
|
|
|
164
170
|
ClawTrail (or any verifier) can check the signature:
|
|
165
171
|
|
|
166
172
|
```typescript
|
|
167
|
-
import { OpenClawAdapter } from
|
|
173
|
+
import { OpenClawAdapter } from "@origintrail/context-graph-openclaw";
|
|
168
174
|
|
|
169
175
|
// Load the signed submission (e.g. from an API request body)
|
|
170
|
-
const submission = JSON.parse(
|
|
176
|
+
const submission = JSON.parse(
|
|
177
|
+
fs.readFileSync("submission.signed.json", "utf-8"),
|
|
178
|
+
);
|
|
171
179
|
|
|
172
180
|
const valid = OpenClawAdapter.verifySubmission(submission);
|
|
173
181
|
// true if payload matches hash AND signature is valid
|
|
@@ -177,22 +185,22 @@ This provides **non-repudiation**: the agent that produced the work is cryptogra
|
|
|
177
185
|
|
|
178
186
|
## Claims derived
|
|
179
187
|
|
|
180
|
-
| Claim
|
|
181
|
-
|
|
182
|
-
| `cg:CanFixBuild`
|
|
183
|
-
| `cg:CanFixTests`
|
|
184
|
-
| `cg:CanRunTests`
|
|
185
|
-
| `cg:CanRecoverFromError`
|
|
186
|
-
| `cg:CanWrite:<lang>`
|
|
187
|
-
| `cg:CanUseFramework:<name>` | Test/build framework usage
|
|
188
|
-
| `cg:CanUseTool:<name>`
|
|
188
|
+
| Claim | When it fires | Confidence |
|
|
189
|
+
| --------------------------- | ---------------------------------------- | ---------- |
|
|
190
|
+
| `cg:CanFixBuild` | Build failed → succeeded in same session | 0.9 |
|
|
191
|
+
| `cg:CanFixTests` | Tests failed → succeeded in same session | 0.9 |
|
|
192
|
+
| `cg:CanRunTests` | 3+ successful test runs | 0.8 |
|
|
193
|
+
| `cg:CanRecoverFromError` | Error → subsequent success | 0.85 |
|
|
194
|
+
| `cg:CanWrite:<lang>` | File writes targeting `.ts`, `.py`, etc. | 0.3 |
|
|
195
|
+
| `cg:CanUseFramework:<name>` | Test/build framework usage | 0.5 |
|
|
196
|
+
| `cg:CanUseTool:<name>` | Shell tool usage (git, npm, etc.) | 0.4 |
|
|
189
197
|
|
|
190
198
|
Plus the built-in rules from `@origintrail/context-graph`:
|
|
191
199
|
|
|
192
|
-
| Claim
|
|
193
|
-
|
|
194
|
-
| `cg:CanCompleteSession` | Session completed with > 5 actions | 0.6
|
|
195
|
-
| `cg:IntegrityValid`
|
|
200
|
+
| Claim | When it fires | Confidence |
|
|
201
|
+
| ----------------------- | ---------------------------------- | ---------- |
|
|
202
|
+
| `cg:CanCompleteSession` | Session completed with > 5 actions | 0.6 |
|
|
203
|
+
| `cg:IntegrityValid` | Hash chain is fully valid | 1.0 |
|
|
196
204
|
|
|
197
205
|
## Agent-facing skill
|
|
198
206
|
|
|
@@ -227,15 +235,15 @@ This demonstrates: event capture → hash chain → Merkle root → claims → m
|
|
|
227
235
|
}
|
|
228
236
|
```
|
|
229
237
|
|
|
230
|
-
| Option
|
|
231
|
-
|
|
232
|
-
| `enabled`
|
|
233
|
-
| `contextGraphRoot` | `.context-graph` | Storage directory
|
|
234
|
-
| `agentId`
|
|
235
|
-
| `policyPath`
|
|
236
|
-
| `detectTests`
|
|
237
|
-
| `detectBuilds`
|
|
238
|
-
| `signingKeyPath`
|
|
238
|
+
| Option | Default | Description |
|
|
239
|
+
| ------------------ | ---------------- | -------------------------------------------- |
|
|
240
|
+
| `enabled` | `true` | Enable/disable the adapter |
|
|
241
|
+
| `contextGraphRoot` | `.context-graph` | Storage directory |
|
|
242
|
+
| `agentId` | auto-generated | Agent identifier for provenance |
|
|
243
|
+
| `policyPath` | — | Path to privacy policy YAML |
|
|
244
|
+
| `detectTests` | `true` | Auto-detect test runs from shell output |
|
|
245
|
+
| `detectBuilds` | `true` | Auto-detect builds from shell output |
|
|
246
|
+
| `signingKeyPath` | auto | Ed25519 key path (auto-generated if missing) |
|
|
239
247
|
|
|
240
248
|
## Development
|
|
241
249
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ContextGraph, type Session, type ChainOpts } from
|
|
2
|
-
import { MapperRegistry } from
|
|
3
|
-
import { type OpenClawSessionContext } from
|
|
4
|
-
import { type ToolCallEvent } from
|
|
5
|
-
import { summarizeSession } from
|
|
1
|
+
import { ContextGraph, type Session, type ChainOpts } from "@clawtrail/context-graph";
|
|
2
|
+
import { MapperRegistry } from "./mappers/MapperRegistry.js";
|
|
3
|
+
import { type OpenClawSessionContext } from "./hooks/lifecycle.js";
|
|
4
|
+
import { type ToolCallEvent } from "./hooks/toolCall.js";
|
|
5
|
+
import { summarizeSession } from "./tools/summarize.js";
|
|
6
6
|
export interface AdapterConfig {
|
|
7
7
|
/** Enable/disable the adapter */
|
|
8
8
|
enabled?: boolean;
|
|
@@ -74,7 +74,7 @@ export declare class OpenClawAdapter {
|
|
|
74
74
|
* Used by register.ts to inject AGENT_ACTION events fetched from
|
|
75
75
|
* the ClawTrail decisions API at session summary time.
|
|
76
76
|
*/
|
|
77
|
-
logExternalEvent(sessionId: string, input: import(
|
|
77
|
+
logExternalEvent(sessionId: string, input: import("@clawtrail/context-graph").EventInput): Promise<void>;
|
|
78
78
|
/** Get current session status */
|
|
79
79
|
getStatus(sessionId?: string): Promise<import("./tools/status.js").StatusResult>;
|
|
80
80
|
/** Summarize and optionally sign the current session */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenClawAdapter.d.ts","sourceRoot":"","sources":["../src/OpenClawAdapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"OpenClawAdapter.d.ts","sourceRoot":"","sources":["../src/OpenClawAdapter.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,YAAY,EACZ,KAAK,OAAO,EAEZ,KAAK,SAAS,EACf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAa7D,OAAO,EAEL,KAAK,s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7
7
|
* Also handles **signing** of submission hashes for ClawTrail API integration.
|
|
8
8
|
*/
|
|
9
|
-
import { createHash, sign as cryptoSign, verify as cryptoVerify, generateKeyPairSync } from
|
|
10
|
-
import { readFile, writeFile, mkdir } from
|
|
11
|
-
import { join } from
|
|
12
|
-
import { ContextGraph, } from
|
|
13
|
-
import { MapperRegistry } from
|
|
14
|
-
import { FallbackMapper } from
|
|
15
|
-
import { ShellMapper } from
|
|
16
|
-
import { FsMapper } from
|
|
17
|
-
import { GitMapper } from
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
9
|
+
import { createHash, sign as cryptoSign, verify as cryptoVerify, generateKeyPairSync, } from "node:crypto";
|
|
10
|
+
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { ContextGraph, } from "@clawtrail/context-graph";
|
|
13
|
+
import { MapperRegistry } from "./mappers/MapperRegistry.js";
|
|
14
|
+
import { FallbackMapper } from "./mappers/fallback.js";
|
|
15
|
+
import { ShellMapper } from "./mappers/shell.js";
|
|
16
|
+
import { FsMapper } from "./mappers/fs.js";
|
|
17
|
+
import { GitMapper } from "./mappers/git.js";
|
|
18
|
+
import { WebMapper } from "./mappers/web.js";
|
|
19
|
+
import { BrowserMapper } from "./mappers/browser.js";
|
|
20
|
+
import { MessageMapper } from "./mappers/message.js";
|
|
21
|
+
import { DocumentMapper } from "./mappers/document.js";
|
|
22
|
+
import { SessionMapper } from "./mappers/session.js";
|
|
23
|
+
import { TestDetector } from "./detectors/TestDetector.js";
|
|
24
|
+
import { BuildDetector } from "./detectors/BuildDetector.js";
|
|
25
|
+
import { HttpDetector } from "./detectors/HttpDetector.js";
|
|
26
|
+
import { createLifecycleHandlers, } from "./hooks/lifecycle.js";
|
|
27
|
+
import { createToolCallHandlers, } from "./hooks/toolCall.js";
|
|
28
|
+
import { createLlmOutputHandlers } from "./hooks/llmOutput.js";
|
|
29
|
+
import { openclawRules } from "./rules/openclaw-rules.js";
|
|
30
|
+
import { getStatus } from "./tools/status.js";
|
|
31
|
+
import { summarizeSession } from "./tools/summarize.js";
|
|
27
32
|
export class OpenClawAdapter {
|
|
28
33
|
cg;
|
|
29
34
|
mappers;
|
|
@@ -36,7 +41,7 @@ export class OpenClawAdapter {
|
|
|
36
41
|
constructor(config) {
|
|
37
42
|
this.config = {
|
|
38
43
|
enabled: true,
|
|
39
|
-
contextGraphRoot:
|
|
44
|
+
contextGraphRoot: ".context-graph",
|
|
40
45
|
detectTests: true,
|
|
41
46
|
detectBuilds: true,
|
|
42
47
|
detectHttp: true,
|
|
@@ -49,6 +54,11 @@ export class OpenClawAdapter {
|
|
|
49
54
|
this.mappers.register(new ShellMapper(this.config.detectTests ? new TestDetector() : undefined, this.config.detectBuilds ? new BuildDetector() : undefined, this.config.detectHttp ? new HttpDetector() : undefined));
|
|
50
55
|
this.mappers.register(new FsMapper());
|
|
51
56
|
this.mappers.register(new GitMapper());
|
|
57
|
+
this.mappers.register(new WebMapper());
|
|
58
|
+
this.mappers.register(new BrowserMapper());
|
|
59
|
+
this.mappers.register(new MessageMapper());
|
|
60
|
+
this.mappers.register(new DocumentMapper());
|
|
61
|
+
this.mappers.register(new SessionMapper());
|
|
52
62
|
// Register OpenClaw reasoning rules
|
|
53
63
|
for (const rule of openclawRules) {
|
|
54
64
|
this.cg.reasoning.registerRule(rule);
|
|
@@ -68,24 +78,24 @@ export class OpenClawAdapter {
|
|
|
68
78
|
*/
|
|
69
79
|
async initSigning() {
|
|
70
80
|
const keyPath = this.config.signingKeyPath ||
|
|
71
|
-
join(this.config.contextGraphRoot,
|
|
72
|
-
const pubKeyPath = keyPath.replace(
|
|
81
|
+
join(this.config.contextGraphRoot, "signing-key.pem");
|
|
82
|
+
const pubKeyPath = keyPath.replace(".pem", ".pub.pem");
|
|
73
83
|
try {
|
|
74
|
-
this.privateKey = await readFile(keyPath,
|
|
75
|
-
this.publicKey = await readFile(pubKeyPath,
|
|
84
|
+
this.privateKey = await readFile(keyPath, "utf-8");
|
|
85
|
+
this.publicKey = await readFile(pubKeyPath, "utf-8");
|
|
76
86
|
}
|
|
77
87
|
catch {
|
|
78
88
|
// Generate new keypair
|
|
79
|
-
const { privateKey, publicKey } = generateKeyPairSync(
|
|
80
|
-
privateKeyEncoding: { type:
|
|
81
|
-
publicKeyEncoding: { type:
|
|
89
|
+
const { privateKey, publicKey } = generateKeyPairSync("ed25519", {
|
|
90
|
+
privateKeyEncoding: { type: "pkcs8", format: "pem" },
|
|
91
|
+
publicKeyEncoding: { type: "spki", format: "pem" },
|
|
82
92
|
});
|
|
83
93
|
this.privateKey = privateKey;
|
|
84
94
|
this.publicKey = publicKey;
|
|
85
95
|
// Save to disk
|
|
86
96
|
await mkdir(this.config.contextGraphRoot, { recursive: true });
|
|
87
|
-
await writeFile(keyPath, privateKey,
|
|
88
|
-
await writeFile(pubKeyPath, publicKey,
|
|
97
|
+
await writeFile(keyPath, privateKey, "utf-8");
|
|
98
|
+
await writeFile(pubKeyPath, publicKey, "utf-8");
|
|
89
99
|
}
|
|
90
100
|
}
|
|
91
101
|
/**
|
|
@@ -97,15 +107,15 @@ export class OpenClawAdapter {
|
|
|
97
107
|
await this.initSigning();
|
|
98
108
|
}
|
|
99
109
|
const payloadJson = JSON.stringify(payload);
|
|
100
|
-
const payloadHash = createHash(
|
|
110
|
+
const payloadHash = createHash("sha256").update(payloadJson).digest("hex");
|
|
101
111
|
// Ed25519 uses crypto.sign() directly (not createSign)
|
|
102
|
-
const signature = cryptoSign(null, Buffer.from(payloadHash,
|
|
112
|
+
const signature = cryptoSign(null, Buffer.from(payloadHash, "utf-8"), this.privateKey).toString("base64");
|
|
103
113
|
return {
|
|
104
114
|
payload,
|
|
105
115
|
payloadHash: `sha256:${payloadHash}`,
|
|
106
116
|
signature,
|
|
107
117
|
publicKey: this.publicKey,
|
|
108
|
-
agentId: this.config.agentId ||
|
|
118
|
+
agentId: this.config.agentId || "agent:openclaw:local",
|
|
109
119
|
sessionId,
|
|
110
120
|
};
|
|
111
121
|
}
|
|
@@ -114,12 +124,12 @@ export class OpenClawAdapter {
|
|
|
114
124
|
*/
|
|
115
125
|
static verifySubmission(submission) {
|
|
116
126
|
const payloadJson = JSON.stringify(submission.payload);
|
|
117
|
-
const payloadHash = createHash(
|
|
127
|
+
const payloadHash = createHash("sha256").update(payloadJson).digest("hex");
|
|
118
128
|
if (submission.payloadHash !== `sha256:${payloadHash}`) {
|
|
119
129
|
return false;
|
|
120
130
|
}
|
|
121
131
|
// Ed25519 uses crypto.verify() directly (not createVerify)
|
|
122
|
-
return cryptoVerify(null, Buffer.from(payloadHash,
|
|
132
|
+
return cryptoVerify(null, Buffer.from(payloadHash, "utf-8"), submission.publicKey, Buffer.from(submission.signature, "base64"));
|
|
123
133
|
}
|
|
124
134
|
// ── Lifecycle API ────────────────────────────────────────────────
|
|
125
135
|
/** Called when an OpenClaw session starts */
|
|
@@ -160,7 +170,7 @@ export class OpenClawAdapter {
|
|
|
160
170
|
/** Summarize and optionally sign the current session */
|
|
161
171
|
async summarizeAndSign(sessionId, chainOpts) {
|
|
162
172
|
const summary = await summarizeSession(this.cg, sessionId);
|
|
163
|
-
if (summary.status !==
|
|
173
|
+
if (summary.status !== "ok") {
|
|
164
174
|
return { summary };
|
|
165
175
|
}
|
|
166
176
|
// Get the full summary for signing (with chain data embedded in public graph)
|
|
@@ -168,8 +178,8 @@ export class OpenClawAdapter {
|
|
|
168
178
|
const signed = await this.signSubmission(sessionId, fullSummary.publicGraph);
|
|
169
179
|
// Save the signed submission to disk
|
|
170
180
|
const session = await this.cg.getSession(sessionId);
|
|
171
|
-
const signedPath = join(session.sessionDir,
|
|
172
|
-
await writeFile(signedPath, JSON.stringify(signed, null, 2),
|
|
181
|
+
const signedPath = join(session.sessionDir, "submission.signed.json");
|
|
182
|
+
await writeFile(signedPath, JSON.stringify(signed, null, 2), "utf-8");
|
|
173
183
|
return { summary, signed };
|
|
174
184
|
}
|
|
175
185
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenClawAdapter.js","sourceRoot":"","sources":["../src/OpenClawAdapter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,
|
|
1
|
+
{"version":3,"file":"OpenClawAdapter.js","sourceRoot":"","sources":["../src/OpenClawAdapter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,UAAU,EACV,IAAI,IAAI,UAAU,EAClB,MAAM,IAAI,YAAY,EACtB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACL,YAAY,GAIb,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC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,OAAO,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;YAC5B,OAAO,EAAE,OAAO,EAAE,CAAC;QACrB,CAAC;QAED,8EAA8E;QAC9E,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAClE,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,cAAc,CACtC,SAAS,EACT,WAAW,CAAC,WAAW,CACxB,CAAC;QAEF,qCAAqC;QACrC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;QACpD,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,wBAAwB,CAAC,CAAC;QACtE,MAAM,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QAEtE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IAC7B,CAAC;CACF"}
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
const buildTools = [
|
|
6
6
|
{
|
|
7
|
-
tool:
|
|
7
|
+
tool: "tsc",
|
|
8
8
|
cmdPatterns: [/\btsc\b/, /\btypescript\b/],
|
|
9
9
|
parseOutput(stdout, stderr) {
|
|
10
|
-
const combined = stdout +
|
|
10
|
+
const combined = stdout + "\n" + stderr;
|
|
11
11
|
// tsc: "Found N errors."
|
|
12
12
|
const errMatch = combined.match(/Found\s+(\d+)\s+error/i);
|
|
13
13
|
return {
|
|
@@ -17,10 +17,10 @@ const buildTools = [
|
|
|
17
17
|
},
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
|
-
tool:
|
|
20
|
+
tool: "webpack",
|
|
21
21
|
cmdPatterns: [/\bwebpack\b/],
|
|
22
22
|
parseOutput(stdout, stderr) {
|
|
23
|
-
const combined = stdout +
|
|
23
|
+
const combined = stdout + "\n" + stderr;
|
|
24
24
|
const errMatch = combined.match(/(\d+)\s+error/i);
|
|
25
25
|
const warnMatch = combined.match(/(\d+)\s+warning/i);
|
|
26
26
|
return {
|
|
@@ -30,10 +30,10 @@ const buildTools = [
|
|
|
30
30
|
},
|
|
31
31
|
},
|
|
32
32
|
{
|
|
33
|
-
tool:
|
|
33
|
+
tool: "vite",
|
|
34
34
|
cmdPatterns: [/\bvite\s+build\b/],
|
|
35
35
|
parseOutput(stdout, stderr) {
|
|
36
|
-
const combined = stdout +
|
|
36
|
+
const combined = stdout + "\n" + stderr;
|
|
37
37
|
const hasError = /error/i.test(combined);
|
|
38
38
|
return {
|
|
39
39
|
errorsCount: hasError ? 1 : 0,
|
|
@@ -42,17 +42,17 @@ const buildTools = [
|
|
|
42
42
|
},
|
|
43
43
|
},
|
|
44
44
|
{
|
|
45
|
-
tool:
|
|
45
|
+
tool: "cargo-build",
|
|
46
46
|
cmdPatterns: [/\bcargo\s+build\b/],
|
|
47
47
|
parseOutput(stdout, stderr) {
|
|
48
|
-
const combined = stdout +
|
|
48
|
+
const combined = stdout + "\n" + stderr;
|
|
49
49
|
const errors = (combined.match(/error\[E\d+\]/g) || []).length;
|
|
50
50
|
const warnings = (combined.match(/warning\[/g) || []).length;
|
|
51
51
|
return { errorsCount: errors, warningsCount: warnings };
|
|
52
52
|
},
|
|
53
53
|
},
|
|
54
54
|
{
|
|
55
|
-
tool:
|
|
55
|
+
tool: "go-build",
|
|
56
56
|
cmdPatterns: [/\bgo\s+build\b/],
|
|
57
57
|
parseOutput(_stdout, stderr) {
|
|
58
58
|
const hasError = stderr.trim().length > 0;
|
|
@@ -63,10 +63,10 @@ const buildTools = [
|
|
|
63
63
|
},
|
|
64
64
|
},
|
|
65
65
|
{
|
|
66
|
-
tool:
|
|
66
|
+
tool: "hardhat-compile",
|
|
67
67
|
cmdPatterns: [/\bhardhat\s+compile\b/],
|
|
68
68
|
parseOutput(stdout, stderr) {
|
|
69
|
-
const combined = stdout +
|
|
69
|
+
const combined = stdout + "\n" + stderr;
|
|
70
70
|
const errMatch = combined.match(/(\d+)\s+error/i);
|
|
71
71
|
return {
|
|
72
72
|
errorsCount: Number(errMatch?.[1] || 0),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpDetector.d.ts","sourceRoot":"","sources":["../../src/detectors/HttpDetector.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;CACd;
|
|
1
|
+
{"version":3,"file":"HttpDetector.d.ts","sourceRoot":"","sources":["../../src/detectors/HttpDetector.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;CACd;AAsID,qBAAa,YAAY;IACvB;;;OAGG;IACH,MAAM,CACJ,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAChB,UAAU,GAAG,IAAI;CA8CrB"}
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
* Follows the same pattern as TestDetector and BuildDetector.
|
|
6
6
|
* URLs are never stored raw — only sha256 hashes of host and path.
|
|
7
7
|
*/
|
|
8
|
-
import { sha256 } from
|
|
8
|
+
import { sha256 } from "../util/hash.js";
|
|
9
9
|
// ── Shared output parsers ────────────────────────────────────────────
|
|
10
10
|
function parseHttpStatus(stdout, stderr) {
|
|
11
|
-
const combined = stderr +
|
|
11
|
+
const combined = stderr + "\n" + stdout;
|
|
12
12
|
// curl -v: "< HTTP/1.1 200 OK" or "< HTTP/2 200"
|
|
13
13
|
// curl -I/-i: "HTTP/1.1 200 OK" at line start
|
|
14
14
|
// Also handles "HTTP/2 200" without reason phrase
|
|
@@ -20,12 +20,12 @@ function parseHttpStatus(stdout, stderr) {
|
|
|
20
20
|
return undefined;
|
|
21
21
|
}
|
|
22
22
|
function parseContentType(stdout, stderr) {
|
|
23
|
-
const combined = stderr +
|
|
23
|
+
const combined = stderr + "\n" + stdout;
|
|
24
24
|
const match = combined.match(/[Cc]ontent-[Tt]ype:\s*([^\s;]+)/);
|
|
25
25
|
return match?.[1];
|
|
26
26
|
}
|
|
27
27
|
function parseContentLength(stdout, stderr) {
|
|
28
|
-
const combined = stderr +
|
|
28
|
+
const combined = stderr + "\n" + stdout;
|
|
29
29
|
const match = combined.match(/[Cc]ontent-[Ll]ength:\s*(\d+)/);
|
|
30
30
|
return match ? Number(match[1]) : undefined;
|
|
31
31
|
}
|
|
@@ -44,21 +44,21 @@ function extractCurlMethod(cmd) {
|
|
|
44
44
|
return explicit[1].toUpperCase();
|
|
45
45
|
// -I or --head → HEAD
|
|
46
46
|
if (/\s-I\b|--head\b/.test(cmd))
|
|
47
|
-
return
|
|
47
|
+
return "HEAD";
|
|
48
48
|
// -d, --data, --data-raw, --data-binary, --data-urlencode, -F, --form → POST
|
|
49
49
|
if (/\s-[dF]\b|\s--data\b|\s--data-\w+\b|\s--form\b/.test(cmd))
|
|
50
|
-
return
|
|
51
|
-
return
|
|
50
|
+
return "POST";
|
|
51
|
+
return "GET";
|
|
52
52
|
}
|
|
53
53
|
// ── wget method extraction ───────────────────────────────────────────
|
|
54
54
|
function extractWgetMethod(cmd) {
|
|
55
55
|
if (/--post-data\b|--post-file\b/.test(cmd))
|
|
56
|
-
return
|
|
56
|
+
return "POST";
|
|
57
57
|
if (/--method\s+(\w+)/i.test(cmd)) {
|
|
58
58
|
const m = cmd.match(/--method\s+(\w+)/i);
|
|
59
59
|
return m[1].toUpperCase();
|
|
60
60
|
}
|
|
61
|
-
return
|
|
61
|
+
return "GET";
|
|
62
62
|
}
|
|
63
63
|
// ── URL extraction (shared) ──────────────────────────────────────────
|
|
64
64
|
function extractUrlFromCmd(cmd) {
|
|
@@ -80,26 +80,29 @@ function extractUrlFromCmd(cmd) {
|
|
|
80
80
|
// ── Tool patterns ────────────────────────────────────────────────────
|
|
81
81
|
const httpTools = [
|
|
82
82
|
{
|
|
83
|
-
tool:
|
|
83
|
+
tool: "curl",
|
|
84
84
|
cmdPatterns: [/\bcurl\b/],
|
|
85
85
|
extractMethod: extractCurlMethod,
|
|
86
86
|
extractUrl: extractUrlFromCmd,
|
|
87
87
|
parseOutput: parseOutputMetadata,
|
|
88
88
|
},
|
|
89
89
|
{
|
|
90
|
-
tool:
|
|
90
|
+
tool: "wget",
|
|
91
91
|
cmdPatterns: [/\bwget\b/],
|
|
92
92
|
extractMethod: extractWgetMethod,
|
|
93
93
|
extractUrl: extractUrlFromCmd,
|
|
94
94
|
parseOutput: parseOutputMetadata,
|
|
95
95
|
},
|
|
96
96
|
{
|
|
97
|
-
tool:
|
|
97
|
+
tool: "httpie",
|
|
98
98
|
// httpie uses `http` or `https` as command names
|
|
99
|
-
cmdPatterns: [
|
|
99
|
+
cmdPatterns: [
|
|
100
|
+
/\bhttpie\b/,
|
|
101
|
+
/\bhttp\s+(?:GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\b/i,
|
|
102
|
+
],
|
|
100
103
|
extractMethod(cmd) {
|
|
101
104
|
const m = cmd.match(/\bhttp\s+(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\b/i);
|
|
102
|
-
return m ? m[1].toUpperCase() :
|
|
105
|
+
return m ? m[1].toUpperCase() : "GET";
|
|
103
106
|
},
|
|
104
107
|
extractUrl: extractUrlFromCmd,
|
|
105
108
|
parseOutput: parseOutputMetadata,
|
|
@@ -119,8 +122,8 @@ export class HttpDetector {
|
|
|
119
122
|
const method = ht.extractMethod(cmd);
|
|
120
123
|
const rawUrl = ht.extractUrl(cmd);
|
|
121
124
|
// Hash URL components — never store raw
|
|
122
|
-
let hostHash = sha256(
|
|
123
|
-
let pathHash = sha256(
|
|
125
|
+
let hostHash = sha256("unknown");
|
|
126
|
+
let pathHash = sha256("/");
|
|
124
127
|
let hostDisplay;
|
|
125
128
|
let urlDisplay;
|
|
126
129
|
if (rawUrl) {
|
|
@@ -135,7 +138,7 @@ export class HttpDetector {
|
|
|
135
138
|
catch {
|
|
136
139
|
// URL parsing failed — hash the whole thing
|
|
137
140
|
hostHash = sha256(rawUrl);
|
|
138
|
-
pathHash = sha256(
|
|
141
|
+
pathHash = sha256("");
|
|
139
142
|
}
|
|
140
143
|
}
|
|
141
144
|
const output = ht.parseOutput(stdout, stderr);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpDetector.js","sourceRoot":"","sources":["../../src/detectors/HttpDetector.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAyBzC,wEAAwE;AAExE,SAAS,eAAe,CAAC,MAAc,EAAE,MAAc;IACrD,MAAM,QAAQ,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,CAAC;IACxC,iDAAiD;IACjD,8CAA8C;IAC9C,kDAAkD;IAClD,MAAM,OAAO,GAAG,CAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,yBAAyB,CAAC,CAAC,CAAC;IAClE,uDAAuD;IACvD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,C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