@clawtrail/context-graph-openclaw 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/README.md +252 -0
- package/dist/OpenClawAdapter.d.ts +75 -0
- package/dist/OpenClawAdapter.d.ts.map +1 -0
- package/dist/OpenClawAdapter.js +157 -0
- package/dist/OpenClawAdapter.js.map +1 -0
- package/dist/detectors/BuildDetector.d.ts +17 -0
- package/dist/detectors/BuildDetector.d.ts.map +1 -0
- package/dist/detectors/BuildDetector.js +98 -0
- package/dist/detectors/BuildDetector.js.map +1 -0
- package/dist/detectors/TestDetector.d.ts +19 -0
- package/dist/detectors/TestDetector.d.ts.map +1 -0
- package/dist/detectors/TestDetector.js +133 -0
- package/dist/detectors/TestDetector.js.map +1 -0
- package/dist/hooks/lifecycle.d.ts +29 -0
- package/dist/hooks/lifecycle.d.ts.map +1 -0
- package/dist/hooks/lifecycle.js +26 -0
- package/dist/hooks/lifecycle.js.map +1 -0
- package/dist/hooks/toolCall.d.ts +18 -0
- package/dist/hooks/toolCall.d.ts.map +1 -0
- package/dist/hooks/toolCall.js +34 -0
- package/dist/hooks/toolCall.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/mappers/MapperRegistry.d.ts +29 -0
- package/dist/mappers/MapperRegistry.d.ts.map +1 -0
- package/dist/mappers/MapperRegistry.js +29 -0
- package/dist/mappers/MapperRegistry.js.map +1 -0
- package/dist/mappers/fallback.d.ts +11 -0
- package/dist/mappers/fallback.d.ts.map +1 -0
- package/dist/mappers/fallback.js +25 -0
- package/dist/mappers/fallback.js.map +1 -0
- package/dist/mappers/fs.d.ts +7 -0
- package/dist/mappers/fs.d.ts.map +1 -0
- package/dist/mappers/fs.js +51 -0
- package/dist/mappers/fs.js.map +1 -0
- package/dist/mappers/git.d.ts +10 -0
- package/dist/mappers/git.d.ts.map +1 -0
- package/dist/mappers/git.js +79 -0
- package/dist/mappers/git.js.map +1 -0
- package/dist/mappers/shell.d.ts +16 -0
- package/dist/mappers/shell.d.ts.map +1 -0
- package/dist/mappers/shell.js +75 -0
- package/dist/mappers/shell.js.map +1 -0
- package/dist/rules/openclaw-rules.d.ts +15 -0
- package/dist/rules/openclaw-rules.d.ts.map +1 -0
- package/dist/rules/openclaw-rules.js +175 -0
- package/dist/rules/openclaw-rules.js.map +1 -0
- package/dist/tools/status.d.ts +14 -0
- package/dist/tools/status.d.ts.map +1 -0
- package/dist/tools/status.js +21 -0
- package/dist/tools/status.js.map +1 -0
- package/dist/tools/summarize.d.ts +17 -0
- package/dist/tools/summarize.d.ts.map +1 -0
- package/dist/tools/summarize.js +30 -0
- package/dist/tools/summarize.js.map +1 -0
- package/dist/util/hash.d.ts +23 -0
- package/dist/util/hash.d.ts.map +1 -0
- package/dist/util/hash.js +83 -0
- package/dist/util/hash.js.map +1 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
# @origintrail/context-graph-openclaw
|
|
2
|
+
|
|
3
|
+
[OpenClaw](https://github.com/origintrail/openclaw) adapter for [`@origintrail/context-graph`](../context-graph). Automatically captures agent execution traces as [PROV-O](https://www.w3.org/TR/prov-o/) provenance events with hash chain integrity and Ed25519 signed submissions.
|
|
4
|
+
|
|
5
|
+
## What it does
|
|
6
|
+
|
|
7
|
+
When installed as an OpenClaw plugin, this adapter **automatically captures every tool call** your agent makes — file reads, writes, shell commands, git operations — and turns them into a verifiable provenance graph. Test runs and builds are auto-detected from shell output and promoted to typed events with parsed metrics.
|
|
8
|
+
|
|
9
|
+
At session end, claims like "CanFixTests" and "CanRunTests" are derived from the observed outcomes. The resulting public graph is signed with Ed25519 and can be submitted to [ClawTrail](https://clawtrail.ai) for reputation building.
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
OpenClaw Agent
|
|
13
|
+
├── read file → FILE_READ event (path hashed)
|
|
14
|
+
├── write file → FILE_WRITE event (diff hashed)
|
|
15
|
+
├── npx jest → TEST_RUN event (pass/fail counts parsed)
|
|
16
|
+
├── npx tsc → BUILD_RUN event (error counts parsed)
|
|
17
|
+
└── git commit → GIT_COMMIT event (message hashed)
|
|
18
|
+
│
|
|
19
|
+
▼
|
|
20
|
+
Hash-chained JSONL log
|
|
21
|
+
│
|
|
22
|
+
▼
|
|
23
|
+
Summarize → claims + metrics
|
|
24
|
+
│
|
|
25
|
+
▼
|
|
26
|
+
Ed25519 signed public graph
|
|
27
|
+
│
|
|
28
|
+
▼
|
|
29
|
+
submission.signed.json (→ ClawTrail API)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Privacy:** File contents, diffs, command strings, and stdout are **never stored** — only their SHA-256 hashes. The public graph contains aggregate metrics and claims, never raw data.
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
### As an OpenClaw plugin
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# Install both packages
|
|
40
|
+
npm install @origintrail/context-graph @origintrail/context-graph-openclaw
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Or link locally during development:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# Build the core engine first
|
|
47
|
+
cd context-graph
|
|
48
|
+
npm install && npm run build
|
|
49
|
+
|
|
50
|
+
# Then the adapter
|
|
51
|
+
cd ../context-graph-openclaw
|
|
52
|
+
npm install && npm run build
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Register with OpenClaw
|
|
56
|
+
|
|
57
|
+
Add to your OpenClaw plugin configuration:
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"plugins": [
|
|
62
|
+
{
|
|
63
|
+
"id": "context-graph",
|
|
64
|
+
"package": "@origintrail/context-graph-openclaw",
|
|
65
|
+
"config": {
|
|
66
|
+
"enabled": true,
|
|
67
|
+
"agentId": "agent:openclaw:my-coder",
|
|
68
|
+
"detectTests": true,
|
|
69
|
+
"detectBuilds": true
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The plugin hooks into OpenClaw's `session_start`, `session_end`, `before_tool_call`, and `after_tool_call` lifecycle events automatically.
|
|
77
|
+
|
|
78
|
+
### Standalone (without OpenClaw)
|
|
79
|
+
|
|
80
|
+
You can use the adapter directly in any Node.js environment:
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { OpenClawAdapter } from '@origintrail/context-graph-openclaw';
|
|
84
|
+
|
|
85
|
+
const adapter = new OpenClawAdapter({
|
|
86
|
+
contextGraphRoot: '.context-graph',
|
|
87
|
+
agentId: 'agent:my-agent',
|
|
88
|
+
detectTests: true,
|
|
89
|
+
detectBuilds: true,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Create a mock context (or use your own session management)
|
|
93
|
+
const ctx = {
|
|
94
|
+
sessionKey: 'session-1',
|
|
95
|
+
initialMessage: 'Fix the auth bug',
|
|
96
|
+
set: (k, v) => sessionStore.set(k, v),
|
|
97
|
+
get: (k) => sessionStore.get(k),
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// Start session
|
|
101
|
+
await adapter.onSessionStart(ctx);
|
|
102
|
+
|
|
103
|
+
// Feed tool call results as they happen
|
|
104
|
+
await adapter.onAfterToolCall({
|
|
105
|
+
toolName: 'bash',
|
|
106
|
+
params: { command: 'npm test' },
|
|
107
|
+
result: { stdout: 'Tests: 5 passed, 0 failed', exitCode: 0 },
|
|
108
|
+
durationMs: 3200,
|
|
109
|
+
}, ctx);
|
|
110
|
+
|
|
111
|
+
await adapter.onAfterToolCall({
|
|
112
|
+
toolName: 'write',
|
|
113
|
+
params: { path: 'src/auth.ts' },
|
|
114
|
+
result: { content: '...', bytesWritten: 200 },
|
|
115
|
+
durationMs: 15,
|
|
116
|
+
}, ctx);
|
|
117
|
+
|
|
118
|
+
// End session
|
|
119
|
+
await adapter.onSessionEnd(ctx);
|
|
120
|
+
|
|
121
|
+
// Summarize + sign
|
|
122
|
+
const sessionId = ctx.get('cg:session_id');
|
|
123
|
+
const { summary, signed } = await adapter.summarizeAndSign(sessionId);
|
|
124
|
+
|
|
125
|
+
console.log(summary.claims); // [{ type: 'cg:CanRunTests', confidence: 0.8, scope: 'jest' }]
|
|
126
|
+
console.log(signed.payloadHash); // sha256:...
|
|
127
|
+
console.log(signed.signature); // base64 Ed25519 signature
|
|
128
|
+
|
|
129
|
+
// Verify the signature (e.g. on the ClawTrail server side)
|
|
130
|
+
const valid = OpenClawAdapter.verifySubmission(signed);
|
|
131
|
+
console.log(valid); // true
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## How tool calls are mapped
|
|
135
|
+
|
|
136
|
+
| OpenClaw tool | Event type | What's captured |
|
|
137
|
+
|---|---|---|
|
|
138
|
+
| `bash` / `shell` | `SHELL_COMMAND` | cmd hash, exit code, stdout/stderr hash |
|
|
139
|
+
| ↳ if test detected | `TEST_RUN` | framework, passed, failed, skipped |
|
|
140
|
+
| ↳ if build detected | `BUILD_RUN` | tool, error count, warning count |
|
|
141
|
+
| `read` | `FILE_READ` | path hash, extension, byte count |
|
|
142
|
+
| `write` / `edit` | `FILE_WRITE` | path hash, extension, diff hash, byte count |
|
|
143
|
+
| `git` (diff) | `GIT_DIFF` | diff hash, files changed, insertions, deletions |
|
|
144
|
+
| `git` (commit) | `GIT_COMMIT` | commit hash, message hash |
|
|
145
|
+
| anything else | `TOOL_CALL` | tool name, args hash, result hash |
|
|
146
|
+
|
|
147
|
+
### Auto-detected test frameworks
|
|
148
|
+
|
|
149
|
+
Jest, Vitest, Mocha, pytest, Hardhat test, Cargo test, Go test
|
|
150
|
+
|
|
151
|
+
### Auto-detected build tools
|
|
152
|
+
|
|
153
|
+
TypeScript (tsc), Webpack, Vite, Cargo build, Go build, Hardhat compile
|
|
154
|
+
|
|
155
|
+
## Signing
|
|
156
|
+
|
|
157
|
+
Every submission is signed with **Ed25519**:
|
|
158
|
+
|
|
159
|
+
1. A keypair is auto-generated on first use (saved to `.context-graph/signing-key.pem`)
|
|
160
|
+
2. The public graph is JSON-serialized and SHA-256 hashed
|
|
161
|
+
3. The hash is signed with the private key
|
|
162
|
+
4. The `submission.signed.json` contains: payload, hash, signature, and public key
|
|
163
|
+
|
|
164
|
+
ClawTrail (or any verifier) can check the signature:
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
import { OpenClawAdapter } from '@origintrail/context-graph-openclaw';
|
|
168
|
+
|
|
169
|
+
// Load the signed submission (e.g. from an API request body)
|
|
170
|
+
const submission = JSON.parse(fs.readFileSync('submission.signed.json', 'utf-8'));
|
|
171
|
+
|
|
172
|
+
const valid = OpenClawAdapter.verifySubmission(submission);
|
|
173
|
+
// true if payload matches hash AND signature is valid
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
This provides **non-repudiation**: the agent that produced the work is cryptographically bound to the submission.
|
|
177
|
+
|
|
178
|
+
## Claims derived
|
|
179
|
+
|
|
180
|
+
| Claim | When it fires | Confidence |
|
|
181
|
+
|---|---|---|
|
|
182
|
+
| `cg:CanFixBuild` | Build failed → succeeded in same session | 0.9 |
|
|
183
|
+
| `cg:CanFixTests` | Tests failed → succeeded in same session | 0.9 |
|
|
184
|
+
| `cg:CanRunTests` | 3+ successful test runs | 0.8 |
|
|
185
|
+
| `cg:CanRecoverFromError` | Error → subsequent success | 0.85 |
|
|
186
|
+
| `cg:CanWrite:<lang>` | File writes targeting `.ts`, `.py`, etc. | 0.3 |
|
|
187
|
+
| `cg:CanUseFramework:<name>` | Test/build framework usage | 0.5 |
|
|
188
|
+
| `cg:CanUseTool:<name>` | Shell tool usage (git, npm, etc.) | 0.4 |
|
|
189
|
+
|
|
190
|
+
Plus the built-in rules from `@origintrail/context-graph`:
|
|
191
|
+
|
|
192
|
+
| Claim | When it fires | Confidence |
|
|
193
|
+
|---|---|---|
|
|
194
|
+
| `cg:CanCompleteSession` | Session completed with > 5 actions | 0.6 |
|
|
195
|
+
| `cg:IntegrityValid` | Hash chain is fully valid | 1.0 |
|
|
196
|
+
|
|
197
|
+
## Agent-facing skill
|
|
198
|
+
|
|
199
|
+
The adapter ships with a `SKILL.md` that instructs the agent:
|
|
200
|
+
|
|
201
|
+
- Context Graph captures tool calls automatically — no agent action needed
|
|
202
|
+
- `context-graph.status` — check session progress
|
|
203
|
+
- `context-graph.summarize` — generate metrics and claims
|
|
204
|
+
- Never include raw code or secrets in notes (redaction is automatic)
|
|
205
|
+
|
|
206
|
+
## Demo
|
|
207
|
+
|
|
208
|
+
Run the interactive end-to-end demo that simulates a full agent session:
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
npx tsx demo.ts
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
This demonstrates: event capture → hash chain → Merkle root → claims → metrics → privacy verification → Ed25519 signing → tamper detection → export formats → storage layout.
|
|
215
|
+
|
|
216
|
+
## Configuration
|
|
217
|
+
|
|
218
|
+
```json
|
|
219
|
+
{
|
|
220
|
+
"enabled": true,
|
|
221
|
+
"contextGraphRoot": ".context-graph",
|
|
222
|
+
"agentId": "agent:openclaw:my-coder",
|
|
223
|
+
"policyPath": "policy.yaml",
|
|
224
|
+
"detectTests": true,
|
|
225
|
+
"detectBuilds": true,
|
|
226
|
+
"signingKeyPath": ".context-graph/signing-key.pem"
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
| Option | Default | Description |
|
|
231
|
+
|---|---|---|
|
|
232
|
+
| `enabled` | `true` | Enable/disable the adapter |
|
|
233
|
+
| `contextGraphRoot` | `.context-graph` | Storage directory |
|
|
234
|
+
| `agentId` | auto-generated | Agent identifier for provenance |
|
|
235
|
+
| `policyPath` | — | Path to privacy policy YAML |
|
|
236
|
+
| `detectTests` | `true` | Auto-detect test runs from shell output |
|
|
237
|
+
| `detectBuilds` | `true` | Auto-detect builds from shell output |
|
|
238
|
+
| `signingKeyPath` | auto | Ed25519 key path (auto-generated if missing) |
|
|
239
|
+
|
|
240
|
+
## Development
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
npm install
|
|
244
|
+
npm run build
|
|
245
|
+
npm test # 27 tests
|
|
246
|
+
npm run dev # watch mode
|
|
247
|
+
npx tsx demo.ts # interactive demo
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## License
|
|
251
|
+
|
|
252
|
+
MIT
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { ContextGraph, type Session } 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
|
+
export interface AdapterConfig {
|
|
7
|
+
/** Enable/disable the adapter */
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
/** Path to context-graph storage */
|
|
10
|
+
contextGraphRoot?: string;
|
|
11
|
+
/** Agent ID */
|
|
12
|
+
agentId?: string;
|
|
13
|
+
/** Path to policy file */
|
|
14
|
+
policyPath?: string;
|
|
15
|
+
/** Enable test detection from shell output */
|
|
16
|
+
detectTests?: boolean;
|
|
17
|
+
/** Enable build detection from shell output */
|
|
18
|
+
detectBuilds?: boolean;
|
|
19
|
+
/** Path to signing key (Ed25519 PEM). Auto-generated if missing. */
|
|
20
|
+
signingKeyPath?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface SignedSubmission {
|
|
23
|
+
/** The public graph payload */
|
|
24
|
+
payload: object;
|
|
25
|
+
/** SHA-256 hash of the JSON-serialized payload */
|
|
26
|
+
payloadHash: string;
|
|
27
|
+
/** Ed25519 signature of the payload hash */
|
|
28
|
+
signature: string;
|
|
29
|
+
/** Public key (PEM) for verification */
|
|
30
|
+
publicKey: string;
|
|
31
|
+
/** Agent ID */
|
|
32
|
+
agentId: string;
|
|
33
|
+
/** Session ID */
|
|
34
|
+
sessionId: string;
|
|
35
|
+
}
|
|
36
|
+
export declare class OpenClawAdapter {
|
|
37
|
+
readonly cg: ContextGraph;
|
|
38
|
+
readonly mappers: MapperRegistry;
|
|
39
|
+
private lifecycleHandlers;
|
|
40
|
+
private toolCallHandlers;
|
|
41
|
+
private config;
|
|
42
|
+
private privateKey;
|
|
43
|
+
private publicKey;
|
|
44
|
+
constructor(config?: AdapterConfig);
|
|
45
|
+
/**
|
|
46
|
+
* Initialize signing keys. If a key path is configured and exists,
|
|
47
|
+
* load it. Otherwise, generate a new Ed25519 keypair.
|
|
48
|
+
*/
|
|
49
|
+
initSigning(): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Sign a submission payload — produces a SignedSubmission that can
|
|
52
|
+
* be sent to the ClawTrail API.
|
|
53
|
+
*/
|
|
54
|
+
signSubmission(sessionId: string, payload: object): Promise<SignedSubmission>;
|
|
55
|
+
/**
|
|
56
|
+
* Verify a signed submission.
|
|
57
|
+
*/
|
|
58
|
+
static verifySubmission(submission: SignedSubmission): boolean;
|
|
59
|
+
/** Called when an OpenClaw session starts */
|
|
60
|
+
onSessionStart(ctx: OpenClawSessionContext): Promise<Session>;
|
|
61
|
+
/** Called when an OpenClaw session ends */
|
|
62
|
+
onSessionEnd(ctx: OpenClawSessionContext): Promise<void>;
|
|
63
|
+
/** Called before a tool call */
|
|
64
|
+
onBeforeToolCall(event: ToolCallEvent, ctx: OpenClawSessionContext): Promise<void>;
|
|
65
|
+
/** Called after a tool call */
|
|
66
|
+
onAfterToolCall(event: ToolCallEvent, ctx: OpenClawSessionContext): Promise<void>;
|
|
67
|
+
/** Get current session status */
|
|
68
|
+
getStatus(sessionId?: string): Promise<import("./tools/status.js").StatusResult>;
|
|
69
|
+
/** Summarize and optionally sign the current session */
|
|
70
|
+
summarizeAndSign(sessionId: string): Promise<{
|
|
71
|
+
summary: Awaited<ReturnType<typeof summarizeSession>>;
|
|
72
|
+
signed?: SignedSubmission;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|
|
3
|
+
*
|
|
4
|
+
* Initializes the context-graph engine, registers mappers, hooks,
|
|
5
|
+
* reasoning rules, and agent-facing tools.
|
|
6
|
+
*
|
|
7
|
+
* Also handles **signing** of submission hashes for ClawTrail API integration.
|
|
8
|
+
*/
|
|
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 { TestDetector } from './detectors/TestDetector.js';
|
|
19
|
+
import { BuildDetector } from './detectors/BuildDetector.js';
|
|
20
|
+
import { createLifecycleHandlers } from './hooks/lifecycle.js';
|
|
21
|
+
import { createToolCallHandlers } from './hooks/toolCall.js';
|
|
22
|
+
import { openclawRules } from './rules/openclaw-rules.js';
|
|
23
|
+
import { getStatus } from './tools/status.js';
|
|
24
|
+
import { summarizeSession } from './tools/summarize.js';
|
|
25
|
+
export class OpenClawAdapter {
|
|
26
|
+
cg;
|
|
27
|
+
mappers;
|
|
28
|
+
lifecycleHandlers;
|
|
29
|
+
toolCallHandlers;
|
|
30
|
+
config;
|
|
31
|
+
privateKey = null;
|
|
32
|
+
publicKey = null;
|
|
33
|
+
constructor(config) {
|
|
34
|
+
this.config = {
|
|
35
|
+
enabled: true,
|
|
36
|
+
contextGraphRoot: '.context-graph',
|
|
37
|
+
detectTests: true,
|
|
38
|
+
detectBuilds: true,
|
|
39
|
+
...config,
|
|
40
|
+
};
|
|
41
|
+
this.cg = new ContextGraph({ root: this.config.contextGraphRoot });
|
|
42
|
+
// Set up mappers
|
|
43
|
+
const fallback = new FallbackMapper();
|
|
44
|
+
this.mappers = new MapperRegistry(fallback);
|
|
45
|
+
this.mappers.register(new ShellMapper(this.config.detectTests ? new TestDetector() : undefined, this.config.detectBuilds ? new BuildDetector() : undefined));
|
|
46
|
+
this.mappers.register(new FsMapper());
|
|
47
|
+
this.mappers.register(new GitMapper());
|
|
48
|
+
// Register OpenClaw reasoning rules
|
|
49
|
+
for (const rule of openclawRules) {
|
|
50
|
+
this.cg.reasoning.registerRule(rule);
|
|
51
|
+
}
|
|
52
|
+
// Set up hooks
|
|
53
|
+
this.lifecycleHandlers = createLifecycleHandlers(this.cg, {
|
|
54
|
+
agentId: this.config.agentId,
|
|
55
|
+
policyPath: this.config.policyPath,
|
|
56
|
+
});
|
|
57
|
+
this.toolCallHandlers = createToolCallHandlers(this.cg, this.mappers);
|
|
58
|
+
}
|
|
59
|
+
// ── Signing ──────────────────────────────────────────────────────
|
|
60
|
+
/**
|
|
61
|
+
* Initialize signing keys. If a key path is configured and exists,
|
|
62
|
+
* load it. Otherwise, generate a new Ed25519 keypair.
|
|
63
|
+
*/
|
|
64
|
+
async initSigning() {
|
|
65
|
+
const keyPath = this.config.signingKeyPath ||
|
|
66
|
+
join(this.config.contextGraphRoot, 'signing-key.pem');
|
|
67
|
+
const pubKeyPath = keyPath.replace('.pem', '.pub.pem');
|
|
68
|
+
try {
|
|
69
|
+
this.privateKey = await readFile(keyPath, 'utf-8');
|
|
70
|
+
this.publicKey = await readFile(pubKeyPath, 'utf-8');
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
// Generate new keypair
|
|
74
|
+
const { privateKey, publicKey } = generateKeyPairSync('ed25519', {
|
|
75
|
+
privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
|
|
76
|
+
publicKeyEncoding: { type: 'spki', format: 'pem' },
|
|
77
|
+
});
|
|
78
|
+
this.privateKey = privateKey;
|
|
79
|
+
this.publicKey = publicKey;
|
|
80
|
+
// Save to disk
|
|
81
|
+
await mkdir(this.config.contextGraphRoot, { recursive: true });
|
|
82
|
+
await writeFile(keyPath, privateKey, 'utf-8');
|
|
83
|
+
await writeFile(pubKeyPath, publicKey, 'utf-8');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Sign a submission payload — produces a SignedSubmission that can
|
|
88
|
+
* be sent to the ClawTrail API.
|
|
89
|
+
*/
|
|
90
|
+
async signSubmission(sessionId, payload) {
|
|
91
|
+
if (!this.privateKey || !this.publicKey) {
|
|
92
|
+
await this.initSigning();
|
|
93
|
+
}
|
|
94
|
+
const payloadJson = JSON.stringify(payload);
|
|
95
|
+
const payloadHash = createHash('sha256').update(payloadJson).digest('hex');
|
|
96
|
+
// Ed25519 uses crypto.sign() directly (not createSign)
|
|
97
|
+
const signature = cryptoSign(null, Buffer.from(payloadHash, 'utf-8'), this.privateKey).toString('base64');
|
|
98
|
+
return {
|
|
99
|
+
payload,
|
|
100
|
+
payloadHash: `sha256:${payloadHash}`,
|
|
101
|
+
signature,
|
|
102
|
+
publicKey: this.publicKey,
|
|
103
|
+
agentId: this.config.agentId || 'agent:openclaw:local',
|
|
104
|
+
sessionId,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Verify a signed submission.
|
|
109
|
+
*/
|
|
110
|
+
static verifySubmission(submission) {
|
|
111
|
+
const payloadJson = JSON.stringify(submission.payload);
|
|
112
|
+
const payloadHash = createHash('sha256').update(payloadJson).digest('hex');
|
|
113
|
+
if (submission.payloadHash !== `sha256:${payloadHash}`) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
// Ed25519 uses crypto.verify() directly (not createVerify)
|
|
117
|
+
return cryptoVerify(null, Buffer.from(payloadHash, 'utf-8'), submission.publicKey, Buffer.from(submission.signature, 'base64'));
|
|
118
|
+
}
|
|
119
|
+
// ── Lifecycle API ────────────────────────────────────────────────
|
|
120
|
+
/** Called when an OpenClaw session starts */
|
|
121
|
+
async onSessionStart(ctx) {
|
|
122
|
+
return this.lifecycleHandlers.onSessionStart(ctx);
|
|
123
|
+
}
|
|
124
|
+
/** Called when an OpenClaw session ends */
|
|
125
|
+
async onSessionEnd(ctx) {
|
|
126
|
+
return this.lifecycleHandlers.onSessionEnd(ctx);
|
|
127
|
+
}
|
|
128
|
+
/** Called before a tool call */
|
|
129
|
+
async onBeforeToolCall(event, ctx) {
|
|
130
|
+
return this.toolCallHandlers.onBeforeToolCall(event, ctx);
|
|
131
|
+
}
|
|
132
|
+
/** Called after a tool call */
|
|
133
|
+
async onAfterToolCall(event, ctx) {
|
|
134
|
+
return this.toolCallHandlers.onAfterToolCall(event, ctx);
|
|
135
|
+
}
|
|
136
|
+
// ── Agent-facing tools ───────────────────────────────────────────
|
|
137
|
+
/** Get current session status */
|
|
138
|
+
async getStatus(sessionId) {
|
|
139
|
+
return getStatus(this.cg, sessionId);
|
|
140
|
+
}
|
|
141
|
+
/** Summarize and optionally sign the current session */
|
|
142
|
+
async summarizeAndSign(sessionId) {
|
|
143
|
+
const summary = await summarizeSession(this.cg, sessionId);
|
|
144
|
+
if (summary.status !== 'ok') {
|
|
145
|
+
return { summary };
|
|
146
|
+
}
|
|
147
|
+
// Get the full summary for signing
|
|
148
|
+
const fullSummary = await this.cg.summarize(sessionId);
|
|
149
|
+
const signed = await this.signSubmission(sessionId, fullSummary.publicGraph);
|
|
150
|
+
// Save the signed submission to disk
|
|
151
|
+
const session = await this.cg.getSession(sessionId);
|
|
152
|
+
const signedPath = join(session.sessionDir, 'submission.signed.json');
|
|
153
|
+
await writeFile(signedPath, JSON.stringify(signed, null, 2), 'utf-8');
|
|
154
|
+
return { summary, signed };
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=OpenClawAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpenClawAdapter.js","sourceRoot":"","sources":["../src/OpenClawAdapter.ts"],"names":[],"mappings":"AAAA;;;;;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AE,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"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BuildDetector — identifies build tool invocations from shell commands
|
|
3
|
+
* and parses results from stdout.
|
|
4
|
+
*/
|
|
5
|
+
export interface BuildResult {
|
|
6
|
+
tool: string;
|
|
7
|
+
errorsCount: number;
|
|
8
|
+
warningsCount: number;
|
|
9
|
+
}
|
|
10
|
+
export declare class BuildDetector {
|
|
11
|
+
/**
|
|
12
|
+
* Try to detect a build invocation from a shell command and its output.
|
|
13
|
+
* Returns null if this doesn't look like a build.
|
|
14
|
+
*/
|
|
15
|
+
detect(cmd: string, stdout: string, stderr: string, _exitCode: number): BuildResult | null;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=BuildDetector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BuildDetector.d.ts","sourceRoot":"","sources":["../../src/detectors/BuildDetector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;CACvB;AAkFD,qBAAa,aAAa;IACxB;;;OAGG;IACH,MAAM,CACJ,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAChB,WAAW,GAAG,IAAI;CActB"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BuildDetector — identifies build tool invocations from shell commands
|
|
3
|
+
* and parses results from stdout.
|
|
4
|
+
*/
|
|
5
|
+
const buildTools = [
|
|
6
|
+
{
|
|
7
|
+
tool: 'tsc',
|
|
8
|
+
cmdPatterns: [/\btsc\b/, /\btypescript\b/],
|
|
9
|
+
parseOutput(stdout, stderr) {
|
|
10
|
+
const combined = stdout + '\n' + stderr;
|
|
11
|
+
// tsc: "Found N errors."
|
|
12
|
+
const errMatch = combined.match(/Found\s+(\d+)\s+error/i);
|
|
13
|
+
return {
|
|
14
|
+
errorsCount: Number(errMatch?.[1] || 0),
|
|
15
|
+
warningsCount: 0,
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
tool: 'webpack',
|
|
21
|
+
cmdPatterns: [/\bwebpack\b/],
|
|
22
|
+
parseOutput(stdout, stderr) {
|
|
23
|
+
const combined = stdout + '\n' + stderr;
|
|
24
|
+
const errMatch = combined.match(/(\d+)\s+error/i);
|
|
25
|
+
const warnMatch = combined.match(/(\d+)\s+warning/i);
|
|
26
|
+
return {
|
|
27
|
+
errorsCount: Number(errMatch?.[1] || 0),
|
|
28
|
+
warningsCount: Number(warnMatch?.[1] || 0),
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
tool: 'vite',
|
|
34
|
+
cmdPatterns: [/\bvite\s+build\b/],
|
|
35
|
+
parseOutput(stdout, stderr) {
|
|
36
|
+
const combined = stdout + '\n' + stderr;
|
|
37
|
+
const hasError = /error/i.test(combined);
|
|
38
|
+
return {
|
|
39
|
+
errorsCount: hasError ? 1 : 0,
|
|
40
|
+
warningsCount: 0,
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
tool: 'cargo-build',
|
|
46
|
+
cmdPatterns: [/\bcargo\s+build\b/],
|
|
47
|
+
parseOutput(stdout, stderr) {
|
|
48
|
+
const combined = stdout + '\n' + stderr;
|
|
49
|
+
const errors = (combined.match(/error\[E\d+\]/g) || []).length;
|
|
50
|
+
const warnings = (combined.match(/warning\[/g) || []).length;
|
|
51
|
+
return { errorsCount: errors, warningsCount: warnings };
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
tool: 'go-build',
|
|
56
|
+
cmdPatterns: [/\bgo\s+build\b/],
|
|
57
|
+
parseOutput(_stdout, stderr) {
|
|
58
|
+
const hasError = stderr.trim().length > 0;
|
|
59
|
+
return {
|
|
60
|
+
errorsCount: hasError ? 1 : 0,
|
|
61
|
+
warningsCount: 0,
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
tool: 'hardhat-compile',
|
|
67
|
+
cmdPatterns: [/\bhardhat\s+compile\b/],
|
|
68
|
+
parseOutput(stdout, stderr) {
|
|
69
|
+
const combined = stdout + '\n' + stderr;
|
|
70
|
+
const errMatch = combined.match(/(\d+)\s+error/i);
|
|
71
|
+
return {
|
|
72
|
+
errorsCount: Number(errMatch?.[1] || 0),
|
|
73
|
+
warningsCount: 0,
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
];
|
|
78
|
+
export class BuildDetector {
|
|
79
|
+
/**
|
|
80
|
+
* Try to detect a build invocation from a shell command and its output.
|
|
81
|
+
* Returns null if this doesn't look like a build.
|
|
82
|
+
*/
|
|
83
|
+
detect(cmd, stdout, stderr, _exitCode) {
|
|
84
|
+
for (const bt of buildTools) {
|
|
85
|
+
const cmdMatch = bt.cmdPatterns.some((p) => p.test(cmd));
|
|
86
|
+
if (!cmdMatch)
|
|
87
|
+
continue;
|
|
88
|
+
const parsed = bt.parseOutput(stdout, stderr);
|
|
89
|
+
return {
|
|
90
|
+
tool: bt.tool,
|
|
91
|
+
errorsCount: parsed?.errorsCount ?? 0,
|
|
92
|
+
warningsCount: parsed?.warningsCount ?? 0,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=Bu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,CAAC,CAAC;YAClD,OAAO;gBACL,WAAW,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;gBACvC,aAAa,EAAE,CAAC;aACjB,CAAC;QACJ,CAAC;KACF;CACF,CAAC;AAEF,MAAM,OAAO,aAAa;IACxB;;;OAGG;IACH,MAAM,CACJ,GAAW,EACX,MAAc,EACd,MAAc,EACd,SAAiB;QAEjB,KAAK,MAAM,EAAE,IAAI,UAAU,EAAE,CAAC;YAC5B,MAAM,QAAQ,GAAG,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YACzD,IAAI,CAAC,QAAQ;gBAAE,SAAS;YAExB,MAAM,MAAM,GAAG,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YAC9C,OAAO;gBACL,IAAI,EAAE,EAAE,CAAC,IAAI;gBACb,WAAW,EAAE,MAAM,EAAE,WAAW,IAAI,CAAC;gBACrC,aAAa,EAAE,MAAM,EAAE,aAAa,IAAI,CAAC;aAC1C,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TestDetector — identifies test framework invocations from shell commands
|
|
3
|
+
* and parses test results from stdout.
|
|
4
|
+
*/
|
|
5
|
+
export interface TestResult {
|
|
6
|
+
framework: string;
|
|
7
|
+
passed: number;
|
|
8
|
+
failed: number;
|
|
9
|
+
skipped: number;
|
|
10
|
+
durationMs?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare class TestDetector {
|
|
13
|
+
/**
|
|
14
|
+
* Try to detect a test run from a shell command and its output.
|
|
15
|
+
* Returns null if this doesn't look like a test invocation.
|
|
16
|
+
*/
|
|
17
|
+
detect(cmd: string, stdout: string, stderr: string, exitCode: number): TestResult | null;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=TestDetector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TestDetector.d.ts","sourceRoot":"","sources":["../../src/detectors/TestDetector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAkHD,qBAAa,YAAY;IACvB;;;OAGG;IACH,MAAM,CACJ,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,UAAU,GAAG,IAAI;CAwBrB"}
|