feat(extensions): bench-reflective-dreaming + claude-code-bridge#1
Merged
Conversation
Adds two BenchAGI-owned extensions to the fork that together unify
OpenClaw's native dreaming with a structured reflective + fleet-canon
layer, synced to the Firebase agent wiki via our cloud-mirror daemon.
extensions/bench-reflective-dreaming/
Lightweight extension (prompts + defaults + install scripts, no TS
runtime yet) that runs alongside memory-core.dreaming. Where memory-core
is mechanical (score-based MEMORY.md promotion) and poetic (dreaming-
narrative diary prose), this adds the ops-log dimension:
02:30-02:46 per-agent structured reflection (5 cron jobs)
03:00 memory-core's existing sweep (light/REM/deep + narrative)
03:15 fleet canon (coordinator synthesizes across agents)
03:40 memory consolidation (prune duplicates, stage risky)
- assets/prompts/{dreaming,fleet-canon,memory-consolidation}-protocol.md
version-controlled prompts; install.mjs copies into vault concepts/
(content-hashed, so re-runs are cheap)
- defaults/cron-schedule.json: agent list + minute offsets + timezone
- scripts/install.mjs: idempotent reconciler. Adds/updates/prunes the
7 managed cron jobs to match defaults; migrates untagged orphan jobs
into managed ones by matching on name
- scripts/uninstall.mjs: removes managed jobs; preserves vault protocols
- openclaw.plugin.json: manifest with config schema; runtime=scripts
today, upgrade path to a full TS plugin later
extensions/claude-code-bridge/
Was already present in the working tree but untracked. Now version-
controlled. cloud-mirror.mjs is the daemon that pushes
~/.openclaw/wiki/main deltas to benchagi.com/api/v1/wiki/ingest.
Paired with the launchd plist template. Also tracked: serve.mjs (MCP
bridge) and statusline.mjs.
Verified tonight: first dream on `main` produced a real 5.4 KB reflection
that mirrored to Firebase in ~30s. install.mjs is idempotent — re-running
reports 0 changes once reconciled. Coexists with memory-core.dreaming
cleanly; no upstream code modified.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 task
LightDriverCS
added a commit
that referenced
this pull request
Apr 28, 2026
Commits the bench-reflective-dreaming bundler stub (untracked since 2026-04-20). Should have shipped with #1 / #4 but was missed. Codex Anvil (gpt-5.5 xhigh) verdict: REPAIR. Initial bare `export const PLUGIN_RUNTIME` satisfied tsdown but failed the OpenClaw plugin loader contract (`src/plugins/loader.ts` rejects modules without `register`/`activate`). Repair: replaced with no-op `definePluginEntry`. Verified pnpm build emits dist/extensions/bench-reflective-dreaming/index.js + loader returns status: "loaded". 🤖 Generated with [Claude Code](https://claude.com/claude-code)
LightDriverCS
pushed a commit
that referenced
this pull request
May 6, 2026
Two small Codex W3 findings: #1 — Null-body guard. A JSON body of `null` (or a primitive/array) would skip the LlmTurnWireRequest cast and throw on field access, producing a 500 from the dispatch error handler instead of a clean 400. Added top-level object guard at the start of validateLlmTurnRequest that returns invalid_field('<root>', 'request body must be a JSON object'). Renamed local var `body` → `wire` for the rest of the function so TypeScript sees the narrowed type. #2 — Fractional max_tokens. Original `Number.isFinite(x) && x > 0` let `max_tokens: 0.5` pass and floor to a 0-token budget. Now require `Number.isInteger(x) && x > 0`. Reason text updated to 'must be a positive integer'. Tests: 14 → 16 (added fractional + non-object body cases). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
LightDriverCS
pushed a commit
that referenced
this pull request
May 6, 2026
P1 #1 — thinking.budget_tokens < max_tokens constraint. Anthropic rejects requests where thinking.budget_tokens >= max_tokens; my budget map (high=16384, xhigh=32768) exceeded typical max_tokens=8192 which would 400 immediately. Fix: cap budget to (max_tokens - 1024) reserving room for actual output. If the cap drops below Anthropic's minimum thinking budget (1024), disable thinking entirely rather than send an invalid request. P1 #2 — ANTHROPIC_AUTH_TOKEN env var. Anthropic SDK reads ANTHROPIC_AUTH_TOKEN for OAuth tokens and ANTHROPIC_API_KEY for API keys. My resolver only checked ANTHROPIC_API_KEY, so OAuth-only setups got 'no_anthropic_credential'. Fix: read both, with ANTHROPIC_AUTH_TOKEN taking precedence (matches SDK behavior). API_KEY-shaped OAuth tokens (sk-ant-oat*) still detected and routed via authToken. P2 (deferred) — `as never` casts. Codex flagged that imports of SDK param types would catch shape bugs (e.g. Tool.InputSchema requires `type: "object"`). Validation layer already enforces shape, but upgrading to proper SDK types is a follow-up — not landing this commit to keep the patch focused. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
LightDriverCS
added a commit
that referenced
this pull request
May 6, 2026
* feat(gateway): W3 scaffold for /v1/llm_turn cloud-brain endpoint Phase 1B W3 of BenchAGI ADR-0002. Route registration + body validation + auth check for the cloud-brain dispatch target. Anthropic call is TODO (returns 501 so relay claim path can land first). Also: minor lint-fix in extensions/claude-code-bridge/serve.mjs to unblock the repo-wide pre-commit hook (oxlint curly-rule on a pre- existing single-line return). Out of W3 scope but required for commit. Spec: ~/.openclaw/wiki/main/_boards/specs/phase-1a-design-gate-2026-05-05-v2.md §7 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(gateway-w3): address Codex GO-WITH-PATCHES feedback Two small Codex W3 findings: #1 — Null-body guard. A JSON body of `null` (or a primitive/array) would skip the LlmTurnWireRequest cast and throw on field access, producing a 500 from the dispatch error handler instead of a clean 400. Added top-level object guard at the start of validateLlmTurnRequest that returns invalid_field('<root>', 'request body must be a JSON object'). Renamed local var `body` → `wire` for the rest of the function so TypeScript sees the narrowed type. #2 — Fractional max_tokens. Original `Number.isFinite(x) && x > 0` let `max_tokens: 0.5` pass and floor to a 0-token budget. Now require `Number.isInteger(x) && x > 0`. Reason text updated to 'must be a positive integer'. Tests: 14 → 16 (added fractional + non-object body cases). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(gateway-w3): wire real Anthropic call (env-credential MVP) Replaces the 501 stub with an actual Anthropic SDK call. Resolves the credential from process.env.ANTHROPIC_API_KEY, distinguishing OAuth tokens (sk-ant-oat*) from API keys, and surfaces the resolved profile name back as 'used_auth_profile' so the cloud orchestrator (W2) can decide between OAuth-mode (no aiUsageRecords) and API/coin-mode (write aiUsageRecords) per spec §6. NEW IN llm-turn-http.ts: - callAnthropicForLlmTurn(request) — translates camelCase request to Anthropic SDK params. Handles cache_control on system prompt (ephemeral), thinking_level → thinking config with conservative budget_tokens (low=4096, medium=8192, high=16384, xhigh=32768). Calls messages.create, returns wire-format response (snake_case). - resolveAnthropicCredential() — env-based credential resolution. Reports 'env-api-key' or 'env-oauth-token' as the profile name. - LlmTurnWireResponse type — explicit snake_case shape per spec §7 line 741. ERROR PATHS: - 'no_anthropic_credential' (500) — env not set - 'anthropic_auth_failed' (401/403) — credential rejected - 'anthropic_call_failed' (502 default) — SDK error EXPLICIT NEXT-ITERATION work captured inline: - Real auth-profile-machinery integration (loads the agent's configured profile via OpenClaw's auth-profile store, handles OAuth refresh, etc.). The env approach gets Cory's local OpenClaw to a working smoke test path; production-grade auth-profile resolution is the follow-up. - Idempotency-key write-ahead store (lease-recovery semantics per spec §7 line 851). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(gateway-w3): address Codex Anthropic-call P1 feedback (2 fixes) P1 #1 — thinking.budget_tokens < max_tokens constraint. Anthropic rejects requests where thinking.budget_tokens >= max_tokens; my budget map (high=16384, xhigh=32768) exceeded typical max_tokens=8192 which would 400 immediately. Fix: cap budget to (max_tokens - 1024) reserving room for actual output. If the cap drops below Anthropic's minimum thinking budget (1024), disable thinking entirely rather than send an invalid request. P1 #2 — ANTHROPIC_AUTH_TOKEN env var. Anthropic SDK reads ANTHROPIC_AUTH_TOKEN for OAuth tokens and ANTHROPIC_API_KEY for API keys. My resolver only checked ANTHROPIC_API_KEY, so OAuth-only setups got 'no_anthropic_credential'. Fix: read both, with ANTHROPIC_AUTH_TOKEN taking precedence (matches SDK behavior). API_KEY-shaped OAuth tokens (sk-ant-oat*) still detected and routed via authToken. P2 (deferred) — `as never` casts. Codex flagged that imports of SDK param types would catch shape bugs (e.g. Tool.InputSchema requires `type: "object"`). Validation layer already enforces shape, but upgrading to proper SDK types is a follow-up — not landing this commit to keep the patch focused. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Cory Shelton <coryshelton@Corys-Mac-mini.local> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
LightDriverCS
added a commit
that referenced
this pull request
May 6, 2026
* feat(gateway): W3 scaffold for /v1/llm_turn cloud-brain endpoint Phase 1B W3 of BenchAGI ADR-0002. Route registration + body validation + auth check for the cloud-brain dispatch target. Anthropic call is TODO (returns 501 so relay claim path can land first). Also: minor lint-fix in extensions/claude-code-bridge/serve.mjs to unblock the repo-wide pre-commit hook (oxlint curly-rule on a pre- existing single-line return). Out of W3 scope but required for commit. Spec: ~/.openclaw/wiki/main/_boards/specs/phase-1a-design-gate-2026-05-05-v2.md §7 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(gateway-w3): address Codex GO-WITH-PATCHES feedback Two small Codex W3 findings: #1 — Null-body guard. A JSON body of `null` (or a primitive/array) would skip the LlmTurnWireRequest cast and throw on field access, producing a 500 from the dispatch error handler instead of a clean 400. Added top-level object guard at the start of validateLlmTurnRequest that returns invalid_field('<root>', 'request body must be a JSON object'). Renamed local var `body` → `wire` for the rest of the function so TypeScript sees the narrowed type. #2 — Fractional max_tokens. Original `Number.isFinite(x) && x > 0` let `max_tokens: 0.5` pass and floor to a 0-token budget. Now require `Number.isInteger(x) && x > 0`. Reason text updated to 'must be a positive integer'. Tests: 14 → 16 (added fractional + non-object body cases). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(gateway-w3): wire real Anthropic call (env-credential MVP) Replaces the 501 stub with an actual Anthropic SDK call. Resolves the credential from process.env.ANTHROPIC_API_KEY, distinguishing OAuth tokens (sk-ant-oat*) from API keys, and surfaces the resolved profile name back as 'used_auth_profile' so the cloud orchestrator (W2) can decide between OAuth-mode (no aiUsageRecords) and API/coin-mode (write aiUsageRecords) per spec §6. NEW IN llm-turn-http.ts: - callAnthropicForLlmTurn(request) — translates camelCase request to Anthropic SDK params. Handles cache_control on system prompt (ephemeral), thinking_level → thinking config with conservative budget_tokens (low=4096, medium=8192, high=16384, xhigh=32768). Calls messages.create, returns wire-format response (snake_case). - resolveAnthropicCredential() — env-based credential resolution. Reports 'env-api-key' or 'env-oauth-token' as the profile name. - LlmTurnWireResponse type — explicit snake_case shape per spec §7 line 741. ERROR PATHS: - 'no_anthropic_credential' (500) — env not set - 'anthropic_auth_failed' (401/403) — credential rejected - 'anthropic_call_failed' (502 default) — SDK error EXPLICIT NEXT-ITERATION work captured inline: - Real auth-profile-machinery integration (loads the agent's configured profile via OpenClaw's auth-profile store, handles OAuth refresh, etc.). The env approach gets Cory's local OpenClaw to a working smoke test path; production-grade auth-profile resolution is the follow-up. - Idempotency-key write-ahead store (lease-recovery semantics per spec §7 line 851). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(gateway-w3): address Codex Anthropic-call P1 feedback (2 fixes) P1 #1 — thinking.budget_tokens < max_tokens constraint. Anthropic rejects requests where thinking.budget_tokens >= max_tokens; my budget map (high=16384, xhigh=32768) exceeded typical max_tokens=8192 which would 400 immediately. Fix: cap budget to (max_tokens - 1024) reserving room for actual output. If the cap drops below Anthropic's minimum thinking budget (1024), disable thinking entirely rather than send an invalid request. P1 #2 — ANTHROPIC_AUTH_TOKEN env var. Anthropic SDK reads ANTHROPIC_AUTH_TOKEN for OAuth tokens and ANTHROPIC_API_KEY for API keys. My resolver only checked ANTHROPIC_API_KEY, so OAuth-only setups got 'no_anthropic_credential'. Fix: read both, with ANTHROPIC_AUTH_TOKEN taking precedence (matches SDK behavior). API_KEY-shaped OAuth tokens (sk-ant-oat*) still detected and routed via authToken. P2 (deferred) — `as never` casts. Codex flagged that imports of SDK param types would catch shape bugs (e.g. Tool.InputSchema requires `type: "object"`). Validation layer already enforces shape, but upgrading to proper SDK types is a follow-up — not landing this commit to keep the patch focused. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Cory Shelton <coryshelton@Corys-Mac-mini.local> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds two BenchAGI-owned extensions to our fork that together unify OpenClaw's native
memory-core.dreamingwith a structured reflective + fleet-canon layer, synced to the Firebase agent wiki via our owncloud-mirrordaemon.extensions/bench-reflective-dreaming/(new)Complements — does not replace — memory-core's existing sleep phases. Where memory-core is mechanical (score-based MEMORY.md promotion) and poetic (
dreaming-narrativewrites dream-diary prose), this adds the ops-log dimension: per-agent structured reflection + a coordinator-written fleet canon + a nightly consolidation pass.Shape (lightweight — prompts + defaults + scripts, not a full TS plugin yet):
assets/prompts/{dreaming,fleet-canon,memory-consolidation}-protocol.md— version-controlled prompt templates.defaults/cron-schedule.json— agent list, minute offsets, coordinator agent.scripts/install.mjs— idempotent reconciler. Adds/updates/prunes 7 managed cron jobs to match defaults; migrates un-tagged orphan jobs (from manual bootstrap) by name.scripts/uninstall.mjs— removes managed cron jobs; preserves vault protocols.openclaw.plugin.json— manifest with config schema. Runtime is `"scripts"` today; upgrade path to a full TS plugin later.extensions/claude-code-bridge/(was untracked)Already present in working trees but never committed. Now version-controlled:
cloud-mirror.mjs— the daemon that mirrors~/.openclaw/wiki/main/*→https://benchagi.com/api/v1/wiki/ingest(X-API-Key auth). This is how vault writes reach the Firebase Agent Wiki.ai.openclaw.wiki-mirror.plist.template— launchd template.serve.mjs,statusline.mjs,mirror.mjs— supporting files already in use.Verification
Ran
scripts/install.shtonight against Cory's local gateway:~/.openclaw/wiki/main/concepts/(content-hashed — re-runs report `0 written, 3 unchanged`)How it fits with upstream
extensions/.Test plan
bash extensions/bench-reflective-dreaming/scripts/install.shon a fresh machine → expect 3 protocols written + 7 crons added.defaults/cron-schedule.json(change a minute offset) → re-run install → expect 1 reconciled.bash extensions/bench-reflective-dreaming/scripts/uninstall.sh→ expect 7 cron jobs removed, protocols preserved.~/.openclaw/wiki/main/.Follow-ups
index.tsusingdefinePluginEntry) once the API surface stabilizes — would enable runtime config reconciliation without re-runninginstall.sh.memory-core.dreaming's light/REM/deep once pattern is proven.🤖 Generated with Claude Code