@dashclaw/openclaw-plugin 1.2.2 → 1.2.4
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 +31 -0
- package/openclaw.plugin.json +6 -1
- package/package.json +16 -8
- package/src/index.ts +30 -1
package/README.md
CHANGED
|
@@ -117,6 +117,7 @@ empty because the wait target didn't exist. Fixed in `1.0.1`.
|
|
|
117
117
|
| `dashclawUrl` | string | **required** | Base URL of your DashClaw instance, e.g. `https://my-dashclaw.vercel.app`. |
|
|
118
118
|
| `dashclawApiKey` | string | **required** | DashClaw API key (starts with `oc_live_`). |
|
|
119
119
|
| `agentId` | string | `"openclaw"` | Identifier this OpenClaw instance reports to DashClaw. |
|
|
120
|
+
| `defaultModel` | string | `""` | Fallback model id (e.g. `claude-sonnet-4-6`, `gpt-4o`) used when `llm_output` events don't include a `model` field. Without this, unpriced turns land `tokens_in`/`tokens_out` but `cost_estimate` stays `$0`. Env var: `DASHCLAW_DEFAULT_MODEL`. |
|
|
120
121
|
| `failClosed` | boolean | `true` | If DashClaw is unreachable, block the tool call. Set `false` to fail open. |
|
|
121
122
|
| `riskScoreDefault` | number | `50` | Fallback risk score for tool calls the classifier doesn't recognize. Recognized commands (git, curl, rm, npm, etc.) compute their own risk score automatically. |
|
|
122
123
|
| `highRiskTools` | string[] | `[]` | Tool names that should always start at risk score 85 before classification. The classifier may raise the score further (e.g. `rm -rf` → 90) but will never lower it below 85 for tools in this list. |
|
|
@@ -155,6 +156,36 @@ Accounting notes:
|
|
|
155
156
|
- Tokens are split evenly across the tool calls attributable to the same assistant response. Remainders go to the earliest buckets so the sum is preserved.
|
|
156
157
|
- Cache reads are weighted at 0.1× (Anthropic bills cache reads at ~10% of base input price) before being added to `tokens_in`. Cache writes are counted at full price. This keeps the derived cost aligned with real billing without requiring the server to model cache pricing.
|
|
157
158
|
- Failures are silent: a warning is logged but token attribution never blocks or throws. If your provider doesn't populate `usage`, nothing is patched.
|
|
159
|
+
- **Missing `model`:** if `llm_output` fires with `usage` but no `model`, the plugin stashes tokens using `config.defaultModel` / `DASHCLAW_DEFAULT_MODEL` as a fallback. When both are unset, tokens are still attributed but `cost_estimate` stays `$0` — because the server refuses to guess the model (retroactively backfilling `model = NULL` would have priced every historical row as Opus). The plugin logs a one-time breadcrumb per run in this case so ops can spot it quickly.
|
|
160
|
+
|
|
161
|
+
## Troubleshooting cost attribution
|
|
162
|
+
|
|
163
|
+
If actions are flowing but `cost_estimate` stays `$0` for an OpenClaw agent, run this query against your DashClaw DB — it decomposes the three failure modes in one shot:
|
|
164
|
+
|
|
165
|
+
```sql
|
|
166
|
+
SELECT
|
|
167
|
+
agent_id,
|
|
168
|
+
COUNT(*) AS actions,
|
|
169
|
+
COUNT(*) FILTER (WHERE tokens_in > 0 OR tokens_out > 0) AS with_tokens,
|
|
170
|
+
COUNT(*) FILTER (WHERE model IS NOT NULL AND model <> '') AS with_model,
|
|
171
|
+
COUNT(*) FILTER (WHERE cost_estimate > 0) AS with_cost
|
|
172
|
+
FROM action_records
|
|
173
|
+
WHERE org_id = '<your_org_id>'
|
|
174
|
+
AND timestamp_start::timestamptz >= NOW() - INTERVAL '30 days'
|
|
175
|
+
GROUP BY agent_id
|
|
176
|
+
ORDER BY actions DESC;
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Interpretation:
|
|
180
|
+
|
|
181
|
+
| `with_tokens` | `with_model` | `with_cost` | Likely cause |
|
|
182
|
+
|---|---|---|---|
|
|
183
|
+
| `0` | `0` | `0` | Plugin older than v1.2.0, or OpenClaw runtime doesn't emit `llm_output`. Upgrade both. |
|
|
184
|
+
| `> 0` | `0` | `0` | `llm_output` fires without `model`. Set `config.defaultModel` or `DASHCLAW_DEFAULT_MODEL`. |
|
|
185
|
+
| `> 0` | `> 0` | `0` | Model string isn't matched by DashClaw's pricing table. Add it via Settings → Model Pricing. |
|
|
186
|
+
| `> 0` | `> 0` | `> 0` | Working. If the UI disagrees, check the analytics aggregation. |
|
|
187
|
+
|
|
188
|
+
Repo operators can run `node scripts/diagnose-cost-attribution.mjs` from a DashClaw checkout — it auto-discovers `org_id` from `.env.local` and prints the same table.
|
|
158
189
|
|
|
159
190
|
## Links
|
|
160
191
|
|
package/openclaw.plugin.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "dashclaw-governance",
|
|
3
3
|
"name": "DashClaw Governance",
|
|
4
4
|
"description": "Policy enforcement, human-in-the-loop approval, and decision recording for every OpenClaw tool call. Powered by DashClaw.",
|
|
5
|
-
"version": "1.2.
|
|
5
|
+
"version": "1.2.4",
|
|
6
6
|
"entry": "src/index.ts",
|
|
7
7
|
"main": "./src/index.ts",
|
|
8
8
|
"configSchema": {
|
|
@@ -31,6 +31,10 @@
|
|
|
31
31
|
"default": "openclaw",
|
|
32
32
|
"description": "Agent identifier in DashClaw"
|
|
33
33
|
},
|
|
34
|
+
"defaultModel": {
|
|
35
|
+
"type": "string",
|
|
36
|
+
"description": "Fallback model id (e.g. 'openai-codex/gpt-5.4') used when llm_output events fire without a model field. Without this, server-side cost estimation cannot price the turn and stores cost_estimate = 0. Also settable via DASHCLAW_DEFAULT_MODEL env var."
|
|
37
|
+
},
|
|
34
38
|
"failClosed": {
|
|
35
39
|
"type": "boolean",
|
|
36
40
|
"default": true,
|
|
@@ -55,6 +59,7 @@
|
|
|
55
59
|
"baseUrl": { "label": "DashClaw URL (alias)", "advanced": true },
|
|
56
60
|
"apiKey": { "sensitive": true, "label": "DashClaw API Key (alias)", "advanced": true },
|
|
57
61
|
"agentId": { "label": "Agent ID" },
|
|
62
|
+
"defaultModel": { "label": "Default model (for cost pricing)", "placeholder": "openai-codex/gpt-5.4", "advanced": true },
|
|
58
63
|
"failClosed": { "label": "Fail-closed when DashClaw unreachable", "advanced": true },
|
|
59
64
|
"riskScoreDefault": { "label": "Default risk score", "advanced": true },
|
|
60
65
|
"highRiskTools": { "label": "High-risk tool names", "advanced": true }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dashclaw/openclaw-plugin",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"description": "DashClaw governance for OpenClaw — policy enforcement, human approval, and decision recording for every tool call.",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -28,28 +28,36 @@
|
|
|
28
28
|
"LICENSE"
|
|
29
29
|
],
|
|
30
30
|
"openclaw": {
|
|
31
|
-
"extensions": [
|
|
32
|
-
|
|
31
|
+
"extensions": [
|
|
32
|
+
"./src/index.ts"
|
|
33
|
+
],
|
|
34
|
+
"hooks": [
|
|
35
|
+
"./src/index.ts"
|
|
36
|
+
]
|
|
33
37
|
},
|
|
34
38
|
"scripts": {
|
|
35
39
|
"build": "tsc --noEmit",
|
|
36
40
|
"typecheck": "tsc --noEmit"
|
|
37
41
|
},
|
|
38
42
|
"dependencies": {
|
|
43
|
+
"@dashclaw/openclaw-plugin": "^1.2.3",
|
|
39
44
|
"dashclaw": "^2.11.1"
|
|
40
45
|
},
|
|
41
46
|
"peerDependencies": {
|
|
42
|
-
"openclaw": "
|
|
47
|
+
"openclaw": "^2026.4.15"
|
|
43
48
|
},
|
|
44
49
|
"peerDependenciesMeta": {
|
|
45
|
-
"openclaw": {
|
|
50
|
+
"openclaw": {
|
|
51
|
+
"optional": false
|
|
52
|
+
}
|
|
46
53
|
},
|
|
47
54
|
"devDependencies": {
|
|
48
|
-
"
|
|
49
|
-
"
|
|
55
|
+
"@types/node": "^20.11.0",
|
|
56
|
+
"typescript": "^5.4.0"
|
|
50
57
|
},
|
|
51
58
|
"overrides": {
|
|
52
59
|
"axios": "^1.15.0",
|
|
53
|
-
"tar": "^7.5.11"
|
|
60
|
+
"tar": "^7.5.11",
|
|
61
|
+
"protobufjs": "^7.5.5"
|
|
54
62
|
}
|
|
55
63
|
}
|
package/src/index.ts
CHANGED
|
@@ -38,6 +38,11 @@ interface PluginConfig {
|
|
|
38
38
|
dashclawUrl: string;
|
|
39
39
|
dashclawApiKey: string;
|
|
40
40
|
agentId: string;
|
|
41
|
+
// Fallback model id used when `llm_output` events fire without a `model`
|
|
42
|
+
// field. Without this, the server's `estimateCost` treats the usage as
|
|
43
|
+
// unpriceable and stores `cost_estimate = 0` — producing the "tokens
|
|
44
|
+
// but no cost" failure mode. Empty string disables the fallback.
|
|
45
|
+
defaultModel: string;
|
|
41
46
|
failClosed: boolean;
|
|
42
47
|
riskScoreDefault: number;
|
|
43
48
|
highRiskTools: ReadonlySet<string>;
|
|
@@ -84,11 +89,16 @@ function resolveConfig(raw: Record<string, unknown> | undefined): PluginConfig {
|
|
|
84
89
|
env.DASHCLAW_API_KEY
|
|
85
90
|
);
|
|
86
91
|
const agentId = firstString(cfg.agentId, env.DASHCLAW_AGENT_ID) || 'openclaw';
|
|
92
|
+
const defaultModel = firstString(
|
|
93
|
+
cfg.defaultModel,
|
|
94
|
+
env.DASHCLAW_DEFAULT_MODEL
|
|
95
|
+
);
|
|
87
96
|
|
|
88
97
|
return {
|
|
89
98
|
dashclawUrl,
|
|
90
99
|
dashclawApiKey,
|
|
91
100
|
agentId,
|
|
101
|
+
defaultModel,
|
|
92
102
|
failClosed,
|
|
93
103
|
riskScoreDefault,
|
|
94
104
|
highRiskTools,
|
|
@@ -117,6 +127,10 @@ const pendingActions = new Map<string, string>();
|
|
|
117
127
|
interface TokenTurnState {
|
|
118
128
|
pendingUsage?: { tokens_in: number; tokens_out: number; model: string };
|
|
119
129
|
turnActionIds: string[];
|
|
130
|
+
// Set after the first llm_output on this run that fires without a model
|
|
131
|
+
// field. Used to suppress repeat warnings within the same run — ops see
|
|
132
|
+
// one log line per run, not one per turn.
|
|
133
|
+
warnedMissingModel?: boolean;
|
|
120
134
|
}
|
|
121
135
|
const tokenTurnByRun = new Map<string, TokenTurnState>();
|
|
122
136
|
|
|
@@ -577,7 +591,22 @@ export default definePluginEntry({
|
|
|
577
591
|
(usage.input ?? 0) + (usage.cacheWrite ?? 0) + cacheReadEffective;
|
|
578
592
|
const tokens_out = usage.output ?? 0;
|
|
579
593
|
if (tokens_in > 0 || tokens_out > 0) {
|
|
580
|
-
|
|
594
|
+
// Model resolution: real event value > configured default > empty.
|
|
595
|
+
// When both are empty, still stash the tokens so ops see activity,
|
|
596
|
+
// but log a one-time breadcrumb per run — otherwise the "tokens
|
|
597
|
+
// arrive but cost stays $0" failure mode is invisible.
|
|
598
|
+
const resolvedModel = (model && model.length > 0)
|
|
599
|
+
? model
|
|
600
|
+
: config.defaultModel;
|
|
601
|
+
if (!resolvedModel && !state.warnedMissingModel) {
|
|
602
|
+
console.warn(
|
|
603
|
+
`[dashclaw-governance] llm_output has no model for run ${runId} — ` +
|
|
604
|
+
`tokens will land on action records but cost_estimate will stay $0. ` +
|
|
605
|
+
`Set config.defaultModel or DASHCLAW_DEFAULT_MODEL to price these turns.`
|
|
606
|
+
);
|
|
607
|
+
state.warnedMissingModel = true;
|
|
608
|
+
}
|
|
609
|
+
state.pendingUsage = { tokens_in, tokens_out, model: resolvedModel };
|
|
581
610
|
}
|
|
582
611
|
}
|
|
583
612
|
});
|