openclaw-clarke 0.4.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 +66 -0
- package/dist/cache.d.ts +21 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +44 -0
- package/dist/cache.js.map +1 -0
- package/dist/clarke-client.d.ts +72 -0
- package/dist/clarke-client.d.ts.map +1 -0
- package/dist/clarke-client.js +228 -0
- package/dist/clarke-client.js.map +1 -0
- package/dist/hooks/before-reply.d.ts +17 -0
- package/dist/hooks/before-reply.d.ts.map +1 -0
- package/dist/hooks/before-reply.js +50 -0
- package/dist/hooks/before-reply.js.map +1 -0
- package/dist/hooks/bootstrap.d.ts +9 -0
- package/dist/hooks/bootstrap.d.ts.map +1 -0
- package/dist/hooks/bootstrap.js +47 -0
- package/dist/hooks/bootstrap.js.map +1 -0
- package/dist/hooks/llm-output.d.ts +13 -0
- package/dist/hooks/llm-output.d.ts.map +1 -0
- package/dist/hooks/llm-output.js +28 -0
- package/dist/hooks/llm-output.js.map +1 -0
- package/dist/hooks/prompt-build.d.ts +15 -0
- package/dist/hooks/prompt-build.d.ts.map +1 -0
- package/dist/hooks/prompt-build.js +26 -0
- package/dist/hooks/prompt-build.js.map +1 -0
- package/dist/hooks/session-start.d.ts +10 -0
- package/dist/hooks/session-start.d.ts.map +1 -0
- package/dist/hooks/session-start.js +29 -0
- package/dist/hooks/session-start.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +181 -0
- package/dist/index.js.map +1 -0
- package/openclaw.plugin.json +55 -0
- package/package.json +48 -0
- package/skills/clarke/SKILL.md +81 -0
- package/skills/clarke-agent/SKILL.md +146 -0
- package/skills/clarke-configure/SKILL.md +86 -0
- package/skills/clarke-ingest/SKILL.md +70 -0
- package/skills/clarke-recall/SKILL.md +73 -0
- package/skills/clarke-review/SKILL.md +81 -0
- package/skills/clarke-skill/SKILL.md +91 -0
- package/skills/clarke-teach/SKILL.md +95 -0
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# openclaw-clarke
|
|
2
|
+
|
|
3
|
+
CLARKE (Cognitive Learning Augmentation Retrieval Knowledge Engine) plugin for [OpenClaw](https://github.com/openclaw/openclaw).
|
|
4
|
+
|
|
5
|
+
Gives your OpenClaw agent persistent memory, learned context, and self-improving skills — all injected programmatically into every LLM call.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
openclaw plugins install openclaw-clarke
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## What It Does
|
|
14
|
+
|
|
15
|
+
- **Every LLM call** gets CLARKE context injected into the system prompt (policies, decisions, skills, domain knowledge)
|
|
16
|
+
- **Every user query** gets retrieval-augmented with relevant documents, memory, and decisions
|
|
17
|
+
- **Every response** feeds back into CLARKE's learning loop for continuous improvement
|
|
18
|
+
|
|
19
|
+
## Hooks
|
|
20
|
+
|
|
21
|
+
| Hook | Purpose |
|
|
22
|
+
|------|---------|
|
|
23
|
+
| `agent:bootstrap` | Inject CLARKE identity into bootstrap files |
|
|
24
|
+
| `before_prompt_build` | Inject session context (cached 60s) into system prompt |
|
|
25
|
+
| `before_agent_reply` | Query-specific RAG augmentation |
|
|
26
|
+
| `session_start` | Greeting + cache invalidation + auto-registration |
|
|
27
|
+
| `llm_output` | Implicit feedback for learning loop |
|
|
28
|
+
|
|
29
|
+
## Tools
|
|
30
|
+
|
|
31
|
+
| Tool | Description |
|
|
32
|
+
|------|-------------|
|
|
33
|
+
| `clarke_status` | System health, agents, policies |
|
|
34
|
+
| `clarke_recall` | Query CLARKE memory |
|
|
35
|
+
| `clarke_teach` | Submit knowledge and corrections |
|
|
36
|
+
| `clarke_review` | List pending directive proposals |
|
|
37
|
+
|
|
38
|
+
## Commands
|
|
39
|
+
|
|
40
|
+
| Command | Description |
|
|
41
|
+
|---------|-------------|
|
|
42
|
+
| `/clarke` | Dashboard |
|
|
43
|
+
| `/clarke_recall <question>` | Query memory |
|
|
44
|
+
| `/clarke_teach <knowledge>` | Teach CLARKE |
|
|
45
|
+
|
|
46
|
+
## Prerequisites
|
|
47
|
+
|
|
48
|
+
CLARKE backend must be running. See the [setup guide](https://github.com/nicktanix/clarke_v2#openclaw).
|
|
49
|
+
|
|
50
|
+
## Configuration
|
|
51
|
+
|
|
52
|
+
Set these environment variables (or configure via `openclaw.json`):
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
CLARKE_API_URL=http://localhost:8000
|
|
56
|
+
CLARKE_TENANT_ID=<auto-registered>
|
|
57
|
+
CLARKE_PROJECT_ID=<auto-registered>
|
|
58
|
+
CLARKE_AGENT_SLUG=clarke-operator
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Tenant and project IDs are auto-registered from the workspace path on first session start.
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
Polyform Noncommercial 1.0.0 — free for personal and noncommercial use.
|
|
66
|
+
For commercial licensing: nick@neill.cloud
|
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple TTL cache for CLARKE session context.
|
|
3
|
+
*
|
|
4
|
+
* The before_prompt_build hook fires on every LLM call. We cache the
|
|
5
|
+
* CLARKE context response to avoid hitting the API on every single call.
|
|
6
|
+
* Default TTL is 60 seconds — context refreshes at most once per minute.
|
|
7
|
+
*/
|
|
8
|
+
export declare class TTLCache<T> {
|
|
9
|
+
private ttlMs;
|
|
10
|
+
private value;
|
|
11
|
+
private expiresAt;
|
|
12
|
+
constructor(ttlMs?: number);
|
|
13
|
+
get(): T | null;
|
|
14
|
+
set(value: T): void;
|
|
15
|
+
invalidate(): void;
|
|
16
|
+
/**
|
|
17
|
+
* Get cached value, or fetch and cache a new one.
|
|
18
|
+
*/
|
|
19
|
+
getOrFetch(fetcher: () => Promise<T | null>): Promise<T | null>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,qBAAa,QAAQ,CAAC,CAAC;IAIT,OAAO,CAAC,KAAK;IAHzB,OAAO,CAAC,KAAK,CAAkB;IAC/B,OAAO,CAAC,SAAS,CAAa;gBAEV,KAAK,GAAE,MAAe;IAE1C,GAAG,IAAI,CAAC,GAAG,IAAI;IAOf,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;IAKnB,UAAU,IAAI,IAAI;IAKlB;;OAEG;IACG,UAAU,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;CAYtE"}
|
package/dist/cache.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple TTL cache for CLARKE session context.
|
|
3
|
+
*
|
|
4
|
+
* The before_prompt_build hook fires on every LLM call. We cache the
|
|
5
|
+
* CLARKE context response to avoid hitting the API on every single call.
|
|
6
|
+
* Default TTL is 60 seconds — context refreshes at most once per minute.
|
|
7
|
+
*/
|
|
8
|
+
export class TTLCache {
|
|
9
|
+
ttlMs;
|
|
10
|
+
value = null;
|
|
11
|
+
expiresAt = 0;
|
|
12
|
+
constructor(ttlMs = 60_000) {
|
|
13
|
+
this.ttlMs = ttlMs;
|
|
14
|
+
}
|
|
15
|
+
get() {
|
|
16
|
+
if (this.value !== null && Date.now() < this.expiresAt) {
|
|
17
|
+
return this.value;
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
set(value) {
|
|
22
|
+
this.value = value;
|
|
23
|
+
this.expiresAt = Date.now() + this.ttlMs;
|
|
24
|
+
}
|
|
25
|
+
invalidate() {
|
|
26
|
+
this.value = null;
|
|
27
|
+
this.expiresAt = 0;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get cached value, or fetch and cache a new one.
|
|
31
|
+
*/
|
|
32
|
+
async getOrFetch(fetcher) {
|
|
33
|
+
const cached = this.get();
|
|
34
|
+
if (cached !== null) {
|
|
35
|
+
return cached;
|
|
36
|
+
}
|
|
37
|
+
const fresh = await fetcher();
|
|
38
|
+
if (fresh !== null) {
|
|
39
|
+
this.set(fresh);
|
|
40
|
+
}
|
|
41
|
+
return fresh;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,OAAO,QAAQ;IAIC;IAHZ,KAAK,GAAa,IAAI,CAAC;IACvB,SAAS,GAAW,CAAC,CAAC;IAE9B,YAAoB,QAAgB,MAAM;QAAtB,UAAK,GAAL,KAAK,CAAiB;IAAG,CAAC;IAE9C,GAAG;QACD,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;YACvD,OAAO,IAAI,CAAC,KAAK,CAAC;QACpB,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,GAAG,CAAC,KAAQ;QACV,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;IAC3C,CAAC;IAED,UAAU;QACR,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU,CAAC,OAAgC;QAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC1B,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACpB,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,MAAM,KAAK,GAAG,MAAM,OAAO,EAAE,CAAC;QAC9B,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACnB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLARKE API client for the OpenClaw plugin.
|
|
3
|
+
*
|
|
4
|
+
* Uses native fetch() — no dependencies. Reads config from environment
|
|
5
|
+
* variables or plugin configuration.
|
|
6
|
+
*/
|
|
7
|
+
export interface ClarkeConfig {
|
|
8
|
+
endpoint: string;
|
|
9
|
+
tenantId: string;
|
|
10
|
+
projectId: string;
|
|
11
|
+
agentSlug: string;
|
|
12
|
+
workspace: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Resolve CLARKE config from environment variables.
|
|
16
|
+
*
|
|
17
|
+
* If CLARKE_TENANT_ID and CLARKE_PROJECT_ID are set, uses them directly.
|
|
18
|
+
* Otherwise, auto-registers with the CLARKE backend using the workspace
|
|
19
|
+
* path to derive a project name (each workspace gets its own CLARKE project).
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveConfig(): ClarkeConfig | null;
|
|
22
|
+
/**
|
|
23
|
+
* Get or create the singleton CLARKE config.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getClarkeConfig(): ClarkeConfig | null;
|
|
26
|
+
/**
|
|
27
|
+
* Auto-register this workspace with CLARKE if tenant/project IDs aren't set.
|
|
28
|
+
*
|
|
29
|
+
* Calls POST /admin/setup with the workspace path as the project name.
|
|
30
|
+
* The endpoint is idempotent — same workspace path always returns the same IDs.
|
|
31
|
+
*/
|
|
32
|
+
export declare function ensureRegistered(config: ClarkeConfig): Promise<ClarkeConfig>;
|
|
33
|
+
/**
|
|
34
|
+
* Fetch CLARKE session context as rendered markdown.
|
|
35
|
+
*/
|
|
36
|
+
export declare function fetchSessionContext(config: ClarkeConfig): Promise<string | null>;
|
|
37
|
+
/**
|
|
38
|
+
* Fetch CLARKE health status.
|
|
39
|
+
*/
|
|
40
|
+
export declare function fetchHealth(config: ClarkeConfig): Promise<{
|
|
41
|
+
status: string;
|
|
42
|
+
version: string;
|
|
43
|
+
} | null>;
|
|
44
|
+
/**
|
|
45
|
+
* List agent profiles for the tenant.
|
|
46
|
+
*/
|
|
47
|
+
export declare function listAgents(config: ClarkeConfig): Promise<any[]>;
|
|
48
|
+
/**
|
|
49
|
+
* List active policies for the tenant.
|
|
50
|
+
*/
|
|
51
|
+
export declare function listPolicies(config: ClarkeConfig): Promise<any[]>;
|
|
52
|
+
/**
|
|
53
|
+
* Send a query through the CLARKE broker for retrieval-augmented context.
|
|
54
|
+
*
|
|
55
|
+
* Returns the broker's answer (which includes grounded context from
|
|
56
|
+
* policies, decisions, docs, and episodic memory) plus the request_id
|
|
57
|
+
* for feedback submission.
|
|
58
|
+
*/
|
|
59
|
+
export declare function queryBroker(config: ClarkeConfig, message: string, sessionId?: string): Promise<{
|
|
60
|
+
answer: string;
|
|
61
|
+
requestId: string;
|
|
62
|
+
degradedMode: boolean;
|
|
63
|
+
} | null>;
|
|
64
|
+
/**
|
|
65
|
+
* Submit feedback on a CLARKE query response.
|
|
66
|
+
*/
|
|
67
|
+
export declare function submitFeedback(config: ClarkeConfig, requestId: string, accepted: boolean, notes?: string): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Build a concise greeting string for session start.
|
|
70
|
+
*/
|
|
71
|
+
export declare function fetchGreeting(config: ClarkeConfig): Promise<string>;
|
|
72
|
+
//# sourceMappingURL=clarke-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clarke-client.d.ts","sourceRoot":"","sources":["../src/clarke-client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,YA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AAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAiBf;AAED;;GAEG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CA0BzE"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLARKE API client for the OpenClaw plugin.
|
|
3
|
+
*
|
|
4
|
+
* Uses native fetch() — no dependencies. Reads config from environment
|
|
5
|
+
* variables or plugin configuration.
|
|
6
|
+
*/
|
|
7
|
+
let _config = null;
|
|
8
|
+
/**
|
|
9
|
+
* Resolve CLARKE config from environment variables.
|
|
10
|
+
*
|
|
11
|
+
* If CLARKE_TENANT_ID and CLARKE_PROJECT_ID are set, uses them directly.
|
|
12
|
+
* Otherwise, auto-registers with the CLARKE backend using the workspace
|
|
13
|
+
* path to derive a project name (each workspace gets its own CLARKE project).
|
|
14
|
+
*/
|
|
15
|
+
export function resolveConfig() {
|
|
16
|
+
const endpoint = process.env.CLARKE_API_URL || process.env.CLARKE_ENDPOINT || "";
|
|
17
|
+
const agentSlug = process.env.CLARKE_AGENT_SLUG || "clarke-operator";
|
|
18
|
+
const workspace = process.env.OPENCLAW_WORKSPACE || process.cwd();
|
|
19
|
+
if (!endpoint)
|
|
20
|
+
return null;
|
|
21
|
+
let tenantId = process.env.CLARKE_TENANT_ID || "";
|
|
22
|
+
let projectId = process.env.CLARKE_PROJECT_ID || "";
|
|
23
|
+
// If IDs are pre-configured, use them
|
|
24
|
+
if (tenantId && projectId) {
|
|
25
|
+
return { endpoint, tenantId, projectId, agentSlug, workspace };
|
|
26
|
+
}
|
|
27
|
+
// Otherwise, we'll auto-register on first use (see ensureRegistered)
|
|
28
|
+
return { endpoint, tenantId, projectId, agentSlug, workspace };
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Get or create the singleton CLARKE config.
|
|
32
|
+
*/
|
|
33
|
+
export function getClarkeConfig() {
|
|
34
|
+
if (!_config) {
|
|
35
|
+
_config = resolveConfig();
|
|
36
|
+
}
|
|
37
|
+
return _config;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Auto-register this workspace with CLARKE if tenant/project IDs aren't set.
|
|
41
|
+
*
|
|
42
|
+
* Calls POST /admin/setup with the workspace path as the project name.
|
|
43
|
+
* The endpoint is idempotent — same workspace path always returns the same IDs.
|
|
44
|
+
*/
|
|
45
|
+
export async function ensureRegistered(config) {
|
|
46
|
+
if (config.tenantId && config.projectId)
|
|
47
|
+
return config;
|
|
48
|
+
try {
|
|
49
|
+
// Derive a project name from the workspace path
|
|
50
|
+
const projectName = `openclaw:${config.workspace.replace(/\//g, ":")}`;
|
|
51
|
+
const resp = await fetch(`${config.endpoint}/admin/setup`, {
|
|
52
|
+
method: "POST",
|
|
53
|
+
headers: { "Content-Type": "application/json" },
|
|
54
|
+
body: JSON.stringify({
|
|
55
|
+
tenant_name: "openclaw",
|
|
56
|
+
project_name: projectName,
|
|
57
|
+
}),
|
|
58
|
+
signal: AbortSignal.timeout(10_000),
|
|
59
|
+
});
|
|
60
|
+
if (resp.ok) {
|
|
61
|
+
const data = (await resp.json());
|
|
62
|
+
config.tenantId = data.tenant_id;
|
|
63
|
+
config.projectId = data.project_id;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// Non-fatal — config will have empty IDs, API calls will fail gracefully
|
|
68
|
+
}
|
|
69
|
+
return config;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Fetch CLARKE session context as rendered markdown.
|
|
73
|
+
*/
|
|
74
|
+
export async function fetchSessionContext(config) {
|
|
75
|
+
try {
|
|
76
|
+
const resp = await fetch(`${config.endpoint}/agents/session-context`, {
|
|
77
|
+
method: "POST",
|
|
78
|
+
headers: { "Content-Type": "application/json" },
|
|
79
|
+
body: JSON.stringify({
|
|
80
|
+
tenant_id: config.tenantId,
|
|
81
|
+
project_id: config.projectId,
|
|
82
|
+
agent_slug: config.agentSlug,
|
|
83
|
+
format: "markdown",
|
|
84
|
+
}),
|
|
85
|
+
signal: AbortSignal.timeout(15_000),
|
|
86
|
+
});
|
|
87
|
+
if (!resp.ok)
|
|
88
|
+
return null;
|
|
89
|
+
return await resp.text();
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Fetch CLARKE health status.
|
|
97
|
+
*/
|
|
98
|
+
export async function fetchHealth(config) {
|
|
99
|
+
try {
|
|
100
|
+
const resp = await fetch(`${config.endpoint}/health`, {
|
|
101
|
+
signal: AbortSignal.timeout(5_000),
|
|
102
|
+
});
|
|
103
|
+
if (!resp.ok)
|
|
104
|
+
return null;
|
|
105
|
+
return (await resp.json());
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* List agent profiles for the tenant.
|
|
113
|
+
*/
|
|
114
|
+
export async function listAgents(config) {
|
|
115
|
+
try {
|
|
116
|
+
const url = new URL(`${config.endpoint}/agents/profiles`);
|
|
117
|
+
url.searchParams.set("tenant_id", config.tenantId);
|
|
118
|
+
url.searchParams.set("status", "active");
|
|
119
|
+
const resp = await fetch(url.toString(), {
|
|
120
|
+
signal: AbortSignal.timeout(5_000),
|
|
121
|
+
});
|
|
122
|
+
if (!resp.ok)
|
|
123
|
+
return [];
|
|
124
|
+
return (await resp.json());
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
return [];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* List active policies for the tenant.
|
|
132
|
+
*/
|
|
133
|
+
export async function listPolicies(config) {
|
|
134
|
+
try {
|
|
135
|
+
const url = new URL(`${config.endpoint}/policy`);
|
|
136
|
+
url.searchParams.set("tenant_id", config.tenantId);
|
|
137
|
+
const resp = await fetch(url.toString(), {
|
|
138
|
+
signal: AbortSignal.timeout(5_000),
|
|
139
|
+
});
|
|
140
|
+
if (!resp.ok)
|
|
141
|
+
return [];
|
|
142
|
+
return (await resp.json());
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
return [];
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Send a query through the CLARKE broker for retrieval-augmented context.
|
|
150
|
+
*
|
|
151
|
+
* Returns the broker's answer (which includes grounded context from
|
|
152
|
+
* policies, decisions, docs, and episodic memory) plus the request_id
|
|
153
|
+
* for feedback submission.
|
|
154
|
+
*/
|
|
155
|
+
export async function queryBroker(config, message, sessionId) {
|
|
156
|
+
try {
|
|
157
|
+
const resp = await fetch(`${config.endpoint}/query`, {
|
|
158
|
+
method: "POST",
|
|
159
|
+
headers: { "Content-Type": "application/json" },
|
|
160
|
+
body: JSON.stringify({
|
|
161
|
+
tenant_id: config.tenantId,
|
|
162
|
+
project_id: config.projectId,
|
|
163
|
+
user_id: "openclaw-agent",
|
|
164
|
+
message,
|
|
165
|
+
session_id: sessionId,
|
|
166
|
+
}),
|
|
167
|
+
signal: AbortSignal.timeout(30_000),
|
|
168
|
+
});
|
|
169
|
+
if (!resp.ok)
|
|
170
|
+
return null;
|
|
171
|
+
const data = (await resp.json());
|
|
172
|
+
return {
|
|
173
|
+
answer: data.answer || "",
|
|
174
|
+
requestId: data.request_id || "",
|
|
175
|
+
degradedMode: data.degraded_mode || false,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Submit feedback on a CLARKE query response.
|
|
184
|
+
*/
|
|
185
|
+
export async function submitFeedback(config, requestId, accepted, notes) {
|
|
186
|
+
try {
|
|
187
|
+
await fetch(`${config.endpoint}/feedback`, {
|
|
188
|
+
method: "POST",
|
|
189
|
+
headers: { "Content-Type": "application/json" },
|
|
190
|
+
body: JSON.stringify({
|
|
191
|
+
request_id: requestId,
|
|
192
|
+
tenant_id: config.tenantId,
|
|
193
|
+
user_id: "openclaw-agent",
|
|
194
|
+
accepted,
|
|
195
|
+
notes,
|
|
196
|
+
}),
|
|
197
|
+
signal: AbortSignal.timeout(5_000),
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
// Best-effort, don't fail the interaction
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Build a concise greeting string for session start.
|
|
206
|
+
*/
|
|
207
|
+
export async function fetchGreeting(config) {
|
|
208
|
+
const health = await fetchHealth(config);
|
|
209
|
+
if (!health) {
|
|
210
|
+
return "CLARKE is offline | start with: make dev";
|
|
211
|
+
}
|
|
212
|
+
const agents = await listAgents(config);
|
|
213
|
+
const policies = await listPolicies(config);
|
|
214
|
+
const parts = [`CLARKE is ${health.status}`];
|
|
215
|
+
const stats = [];
|
|
216
|
+
if (agents.length > 0) {
|
|
217
|
+
stats.push(`${agents.length} agent${agents.length !== 1 ? "s" : ""}`);
|
|
218
|
+
}
|
|
219
|
+
if (policies.length > 0) {
|
|
220
|
+
stats.push(`${policies.length} ${policies.length !== 1 ? "policies" : "policy"}`);
|
|
221
|
+
}
|
|
222
|
+
if (stats.length > 0) {
|
|
223
|
+
parts.push(stats.join(", "));
|
|
224
|
+
}
|
|
225
|
+
parts.push("/clarke for dashboard");
|
|
226
|
+
return parts.join(" | ");
|
|
227
|
+
}
|
|
228
|
+
//# sourceMappingURL=clarke-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clarke-client.js","sourceRoot":"","sources":["../src/clarke-client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH,IAAI,OAAO,GAAwB,IAAI,CAAC;AAExC;;;;;;GAMG;AACH,MAAM,UAAU,aAAa;IAC3B,MAAM,QAAQ,GACZ,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC,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AAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACxE,CAAC;IACD,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,KAAK,CAAC,IAAI,CACR,GAAG,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,EAAE,CACtE,CAAC;IACJ,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;IACpC,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* before_agent_reply hook — augment user queries with CLARKE retrieval.
|
|
3
|
+
*
|
|
4
|
+
* Fires after the user message is received but before the LLM runs.
|
|
5
|
+
* Sends the user's message through CLARKE's broker which performs
|
|
6
|
+
* semantic search, reranking, and context composition against the
|
|
7
|
+
* user's specific query. The retrieved context is appended to the
|
|
8
|
+
* system prompt so the LLM has both:
|
|
9
|
+
* 1. Session-level context (from before_prompt_build — policies, skills, etc.)
|
|
10
|
+
* 2. Query-specific context (from this hook — relevant docs, decisions, memory)
|
|
11
|
+
*
|
|
12
|
+
* This is the RAG layer — it makes every user message retrieval-augmented.
|
|
13
|
+
*/
|
|
14
|
+
export declare function handleBeforeReply(event: any): Promise<{
|
|
15
|
+
appendSystemContext: string;
|
|
16
|
+
} | undefined>;
|
|
17
|
+
//# sourceMappingURL=before-reply.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"before-reply.d.ts","sourceRoot":"","sources":["../../src/hooks/before-reply.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,GAAG,GACT,OAAO,CAAC;IAAE,mBAAmB,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAAC,CAmCtD"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* before_agent_reply hook — augment user queries with CLARKE retrieval.
|
|
3
|
+
*
|
|
4
|
+
* Fires after the user message is received but before the LLM runs.
|
|
5
|
+
* Sends the user's message through CLARKE's broker which performs
|
|
6
|
+
* semantic search, reranking, and context composition against the
|
|
7
|
+
* user's specific query. The retrieved context is appended to the
|
|
8
|
+
* system prompt so the LLM has both:
|
|
9
|
+
* 1. Session-level context (from before_prompt_build — policies, skills, etc.)
|
|
10
|
+
* 2. Query-specific context (from this hook — relevant docs, decisions, memory)
|
|
11
|
+
*
|
|
12
|
+
* This is the RAG layer — it makes every user message retrieval-augmented.
|
|
13
|
+
*/
|
|
14
|
+
import { getClarkeConfig, queryBroker } from "../clarke-client.js";
|
|
15
|
+
import { lastQueryResult } from "../index.js";
|
|
16
|
+
export async function handleBeforeReply(event) {
|
|
17
|
+
const config = getClarkeConfig();
|
|
18
|
+
if (!config)
|
|
19
|
+
return undefined;
|
|
20
|
+
// Extract the user's message from the event
|
|
21
|
+
const userMessage = event.message?.content || event.message?.text || "";
|
|
22
|
+
if (!userMessage || userMessage.length < 5)
|
|
23
|
+
return undefined;
|
|
24
|
+
// Skip CLARKE queries for slash commands (handled by skills/MCP)
|
|
25
|
+
if (userMessage.startsWith("/clarke"))
|
|
26
|
+
return undefined;
|
|
27
|
+
// Query the CLARKE broker for retrieval-augmented context
|
|
28
|
+
const result = await queryBroker(config, userMessage, event.sessionId);
|
|
29
|
+
if (!result || !result.answer)
|
|
30
|
+
return undefined;
|
|
31
|
+
// Store the result so llm_output can submit feedback
|
|
32
|
+
lastQueryResult.requestId = result.requestId;
|
|
33
|
+
lastQueryResult.query = userMessage;
|
|
34
|
+
// Build the augmented context block
|
|
35
|
+
const augmented = [
|
|
36
|
+
"\n\n<!-- CLARKE Query Context (retrieval-augmented) -->",
|
|
37
|
+
`The CLARKE broker retrieved the following context for this specific query.`,
|
|
38
|
+
`Use this alongside the session context above. Cite sources when referencing.`,
|
|
39
|
+
"",
|
|
40
|
+
result.answer,
|
|
41
|
+
result.degradedMode
|
|
42
|
+
? "\n*Note: CLARKE is in degraded mode — some retrieval sources were unavailable.*"
|
|
43
|
+
: "",
|
|
44
|
+
"<!-- /CLARKE Query Context -->",
|
|
45
|
+
]
|
|
46
|
+
.filter(Boolean)
|
|
47
|
+
.join("\n");
|
|
48
|
+
return { appendSystemContext: augmented };
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=before-reply.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"before-reply.js","sourceRoot":"","sources":["../../src/hooks/before-reply.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,KAAU;IAEV,MAAM,MAAM,GAAG,eAAe,EAAE,CAAC;IACjC,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAE9B,4CAA4C;IAC5C,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,EAAE,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC;IACxE,IAAI,CAAC,WAAW,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC;IAE7D,iEAAiE;IACjE,IAAI,WAAW,CAAC,UAAU,CAAC,SAAS,CAAC;QAAE,OAAO,SAAS,CAAC;IAExD,0DAA0D;IAC1D,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IACvE,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAEhD,qDAAqD;IACrD,eAAe,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;IAC7C,eAAe,CAAC,KAAK,GAAG,WAAW,CAAC;IAEpC,oCAAoC;IACpC,MAAM,SAAS,GAAG;QAChB,yDAAyD;QACzD,4EAA4E;QAC5E,8EAA8E;QAC9E,EAAE;QACF,MAAM,CAAC,MAAM;QACb,MAAM,CAAC,YAAY;YACjB,CAAC,CAAC,iFAAiF;YACnF,CAAC,CAAC,EAAE;QACN,gCAAgC;KACjC;SACE,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agent:bootstrap hook — inject CLARKE identity into OpenClaw bootstrap files.
|
|
3
|
+
*
|
|
4
|
+
* Fires before workspace bootstrap files are injected into the system prompt.
|
|
5
|
+
* We add a lightweight AGENTS.md with CLARKE connection metadata so the agent
|
|
6
|
+
* knows CLARKE is active from the start.
|
|
7
|
+
*/
|
|
8
|
+
export declare function handleBootstrap(event: any): Promise<void>;
|
|
9
|
+
//# sourceMappingURL=bootstrap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../src/hooks/bootstrap.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,wBAAsB,eAAe,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAsC/D"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agent:bootstrap hook — inject CLARKE identity into OpenClaw bootstrap files.
|
|
3
|
+
*
|
|
4
|
+
* Fires before workspace bootstrap files are injected into the system prompt.
|
|
5
|
+
* We add a lightweight AGENTS.md with CLARKE connection metadata so the agent
|
|
6
|
+
* knows CLARKE is active from the start.
|
|
7
|
+
*/
|
|
8
|
+
import { getClarkeConfig } from "../clarke-client.js";
|
|
9
|
+
export async function handleBootstrap(event) {
|
|
10
|
+
const config = getClarkeConfig();
|
|
11
|
+
if (!config)
|
|
12
|
+
return;
|
|
13
|
+
const bootstrapContent = `# CLARKE-Managed Agent
|
|
14
|
+
|
|
15
|
+
This agent's context is dynamically managed by CLARKE (Cognitive Learning
|
|
16
|
+
Augmentation Retrieval Knowledge Engine). Policies, decisions, skills,
|
|
17
|
+
and domain knowledge are injected into every prompt automatically via
|
|
18
|
+
the before_prompt_build hook.
|
|
19
|
+
|
|
20
|
+
## Available Commands
|
|
21
|
+
- /clarke — system dashboard and status
|
|
22
|
+
- /clarke-agent — manage agent profiles
|
|
23
|
+
- /clarke-skill — author and ingest skills
|
|
24
|
+
- /clarke-teach — record decisions, policies, corrections
|
|
25
|
+
- /clarke-recall — query CLARKE memory
|
|
26
|
+
- /clarke-review — approve self-improvement proposals
|
|
27
|
+
- /clarke-ingest — feed documents into CLARKE
|
|
28
|
+
- /clarke-configure — view and modify settings
|
|
29
|
+
|
|
30
|
+
## How Context Works
|
|
31
|
+
CLARKE injects context before every LLM call. You don't need to read
|
|
32
|
+
files or query memory manually — relevant policies, decisions, skills,
|
|
33
|
+
and domain knowledge are already in your system prompt. When sources
|
|
34
|
+
conflict, follow the trust ordering: Policy > Decisions > Documents >
|
|
35
|
+
Episodic Memory > Semantic Neighbors.
|
|
36
|
+
|
|
37
|
+
## Learning Loop
|
|
38
|
+
Every interaction builds CLARKE's memory. When users correct you, those
|
|
39
|
+
corrections accumulate and may become behavioral directives. Encourage
|
|
40
|
+
users to provide feedback — it directly improves future responses.
|
|
41
|
+
`;
|
|
42
|
+
event.context?.bootstrapFiles?.push({
|
|
43
|
+
basename: "AGENTS.md",
|
|
44
|
+
content: bootstrapContent,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=bootstrap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../src/hooks/bootstrap.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,KAAU;IAC9C,MAAM,MAAM,GAAG,eAAe,EAAE,CAAC;IACjC,IAAI,CAAC,MAAM;QAAE,OAAO;IAEpB,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4B1B,CAAC;IAEA,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,IAAI,CAAC;QAClC,QAAQ,EAAE,WAAW;QACrB,OAAO,EAAE,gBAAgB;KAC1B,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* llm_output hook — feed interactions back to CLARKE for learning.
|
|
3
|
+
*
|
|
4
|
+
* Fires after the LLM responds. Submits positive feedback to CLARKE
|
|
5
|
+
* so the learning loop can track which retrieval plans worked. This
|
|
6
|
+
* is fire-and-forget (parallel hook) — it never blocks the response.
|
|
7
|
+
*
|
|
8
|
+
* Combined with user corrections via /clarke-teach, this creates the
|
|
9
|
+
* full feedback loop: every interaction either reinforces or corrects
|
|
10
|
+
* CLARKE's retrieval patterns.
|
|
11
|
+
*/
|
|
12
|
+
export declare function handleLlmOutput(_event: any): Promise<void>;
|
|
13
|
+
//# sourceMappingURL=llm-output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm-output.d.ts","sourceRoot":"","sources":["../../src/hooks/llm-output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,wBAAsB,eAAe,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAmBhE"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* llm_output hook — feed interactions back to CLARKE for learning.
|
|
3
|
+
*
|
|
4
|
+
* Fires after the LLM responds. Submits positive feedback to CLARKE
|
|
5
|
+
* so the learning loop can track which retrieval plans worked. This
|
|
6
|
+
* is fire-and-forget (parallel hook) — it never blocks the response.
|
|
7
|
+
*
|
|
8
|
+
* Combined with user corrections via /clarke-teach, this creates the
|
|
9
|
+
* full feedback loop: every interaction either reinforces or corrects
|
|
10
|
+
* CLARKE's retrieval patterns.
|
|
11
|
+
*/
|
|
12
|
+
import { getClarkeConfig, submitFeedback } from "../clarke-client.js";
|
|
13
|
+
import { lastQueryResult } from "../index.js";
|
|
14
|
+
export async function handleLlmOutput(_event) {
|
|
15
|
+
const config = getClarkeConfig();
|
|
16
|
+
if (!config)
|
|
17
|
+
return;
|
|
18
|
+
// If we queried CLARKE for this interaction, submit implicit positive feedback
|
|
19
|
+
// (the user didn't correct it, so it was presumably acceptable)
|
|
20
|
+
const { requestId } = lastQueryResult;
|
|
21
|
+
if (requestId) {
|
|
22
|
+
await submitFeedback(config, requestId, true, "Implicit positive — user did not correct the response.");
|
|
23
|
+
// Clear for next interaction
|
|
24
|
+
lastQueryResult.requestId = "";
|
|
25
|
+
lastQueryResult.query = "";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=llm-output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm-output.js","sourceRoot":"","sources":["../../src/hooks/llm-output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,MAAW;IAC/C,MAAM,MAAM,GAAG,eAAe,EAAE,CAAC;IACjC,IAAI,CAAC,MAAM;QAAE,OAAO;IAEpB,+EAA+E;IAC/E,gEAAgE;IAChE,MAAM,EAAE,SAAS,EAAE,GAAG,eAAe,CAAC;IACtC,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,cAAc,CAClB,MAAM,EACN,SAAS,EACT,IAAI,EACJ,wDAAwD,CACzD,CAAC;QAEF,6BAA6B;QAC7B,eAAe,CAAC,SAAS,GAAG,EAAE,CAAC;QAC/B,eAAe,CAAC,KAAK,GAAG,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC"}
|