Skip to content

feat: add Company Brain context injection safety#29

Merged
100yenadmin merged 1 commit into
mainfrom
codex/company-brain-context-injection
May 8, 2026
Merged

feat: add Company Brain context injection safety#29
100yenadmin merged 1 commit into
mainfrom
codex/company-brain-context-injection

Conversation

@100yenadmin
Copy link
Copy Markdown
Member

@100yenadmin 100yenadmin commented May 8, 2026

Summary

  • adds an opt-in companyBrainContextMode: "auto" runtime path that injects a separate <company-brain-context> block instead of flattening Company Brain into <relevant-memories>
  • resolves account context through a configured account ID or the existing company_brain_accounts_list client path, then fetches account brief plus follow-up/action-readiness context
  • preserves cited Cortex metadata including citations, insufficient_evidence, requires_approval, action_readiness, verification_status, and visibility_scope
  • adds an explicit action-safety envelope with executable_actions: [] and approval_required_not_executable for approval-gated items
  • updates tests, generated dist output, manifest config, docs, and the Company Brain canary summary

Targets #24 and #25.

Verification

  • npm run build
  • npm test
  • node --check scripts/company-brain-canary.mjs
  • GitNexus impact checks on touched existing symbols reported LOW risk; npx gitnexus detect_changes is unavailable in this installed CLI (unknown command), so scope was verified with explicit git diff --name-only and git diff --check.

Notes

The new injection mode remains opt-in. If no account ID is configured, the plugin only injects context when the account-list path resolves exactly one account; ambiguous or empty resolution is logged and skipped.

Summary by CodeRabbit

  • New Features

    • Added Company Brain context injection with account-scoped selection, configurable search, and adjustable limits for facts, events, and output size.
    • New configuration options to enable/disable context injection and specify account resolution strategy.
  • Documentation

    • Updated documentation with complete details on Company Brain context configuration, account resolution, and contextual information handling.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 8, 2026

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b98e26b1-305c-4aa7-8ec4-35bb4ec44cb5

📥 Commits

Reviewing files that changed from the base of the PR and between 587ef29 and 8c8c0d7.

⛔ Files ignored due to path filters (8)
  • dist/__tests__/company-brain-context-format.test.d.ts is excluded by !**/dist/**
  • dist/__tests__/company-brain-context-format.test.d.ts.map is excluded by !**/dist/**, !**/*.map
  • dist/__tests__/company-brain-context-format.test.js is excluded by !**/dist/**
  • dist/__tests__/company-brain-context-format.test.js.map is excluded by !**/dist/**, !**/*.map
  • dist/index.d.ts is excluded by !**/dist/**
  • dist/index.d.ts.map is excluded by !**/dist/**, !**/*.map
  • dist/index.js is excluded by !**/dist/**
  • dist/index.js.map is excluded by !**/dist/**, !**/*.map
📒 Files selected for processing (7)
  • README.md
  • docs/company-brain-tools.md
  • openclaw.plugin.json
  • package.json
  • scripts/company-brain-canary.mjs
  • src/__tests__/company-brain-context-format.test.ts
  • src/index.ts

📝 Walkthrough

Walkthrough

This PR implements account-scoped Company Brain context injection into the plugin's before-agent-start hook. It adds configuration for enabling context mode, resolving accounts, and sizing injected context; implements account resolution with keyword heuristics or explicit search; renders context blocks with approval-gated items marked read-only; and includes tests, documentation, and diagnostic tooling.

Changes

Company Brain Context Injection

Layer / File(s) Summary
Configuration Schema & Parsing
openclaw.plugin.json, src/index.ts
Plugin manifest extends configSchema with six new properties: mode (off|auto), account ID, search text, facts/events limits, and max characters; parseConfig maps and validates all settings with defaults.
Types & Data Contracts
src/index.ts
Adds CompanyBrainResolvedAccount type with id/name; CompanyBrainContextPayload models account, action-readiness, evidence, citations, and insufficient-evidence flags for rendering.
Context Rendering & Formatting
src/index.ts
Exports formatCompanyBrainContext() function that renders XML-like <company-brain-context> block with account_id, approval-gated items marked as non-executable read-only with citations and status fields, plus character-limit truncation.
Account Resolution & Search
src/index.ts
Adds keyword heuristics to detect Company Brain relevance in prompts; resolves account from configured ID or by calling Cortex accounts_list with search term; requires exactly one unambiguous match.
Hook Integration & Context Injection
src/index.ts
Modifies before_agent_start to check context mode, resolve account, fetch brief and action-readiness in parallel from Cortex, render context block with configured limits, inject into prompt when enabled/resolvable, and log outcomes.
Message Content Stripping & Recall Adjustments
src/index.ts
Message extraction strips previously-injected <company-brain-context>...</company-brain-context> blocks to prevent cross-turn contamination; adjusts retrieval-failure log and renames elapsed-time variable for memory recall threshold.
Test Suite
src/__tests__/company-brain-context-format.test.ts
Verifies parseEvaMemoryConfig returns Company Brain settings correctly; formatCompanyBrainContext renders expected XML with account_id, read-only messaging, approval-gated items as non-executable with citations and status; tests both sufficient and insufficient evidence cases.
User Documentation
README.md, docs/company-brain-tools.md
README documents new config options and explains how contextMode=auto creates dedicated <company-brain-context> block distinct from relevant-memories, preserving evidence citations and treating approval-gated items as read-only operator candidates; company-brain-tools.md details account resolution, context placement, and field preservation.
Test Infrastructure & Diagnostics
package.json, scripts/company-brain-canary.mjs
package.json adds company-brain-context-format.test.js to npm test; canary script extends query output with field-occurrence counters, approval-gated item counts, and static action_safety note.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

  • electricsheephq/evaos-cortex-plugin#27: Implements canary script diagnostic metrics and tests for Company Brain tools with approval-gated field preservation and insufficient_evidence handling.
  • electricsheephq/evaos-cortex-plugin#26: Implements account-scoped Company Brain context injection with account resolution, evidence-backed briefings, and action-readiness/approval-gated metadata preservation.
  • electricsheephq/evaos-cortex-plugin#24: Implements Company Brain injection mode with dedicated context block, source-citation preservation, and marking of approval-gated/non-authoritative items as read-only.

Possibly related PRs

Poem

🐰 Whiskers twitch with glee so bright,
Brain contexts now inject just right!
Approval-gated, read-only friends,
Safety first—that never ends! 🧠✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/company-brain-context-injection

Comment @coderabbitai help to get the list of available commands and usage tips.

@100yenadmin 100yenadmin marked this pull request as ready for review May 8, 2026 10:46
@100yenadmin 100yenadmin merged commit 75f4c53 into main May 8, 2026
2 of 3 checks passed
@100yenadmin 100yenadmin deleted the codex/company-brain-context-injection branch May 8, 2026 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant