Skip to content

feat: scope Company Brain context by account key#36

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

feat: scope Company Brain context by account key#36
100yenadmin merged 1 commit into
mainfrom
codex/company-brain-context-scope

Conversation

@100yenadmin

@100yenadmin 100yenadmin commented May 26, 2026

Copy link
Copy Markdown
Member

Summary

  • add source_scope and account_key filters to company_brain_accounts_list
  • add plugin config for companyBrainContextSourceScope and companyBrainContextAccountKey
  • support ElectricSheep internal beta context with source_scope=internal and account_key=company:electricsheep-internal
  • preserve cited Company Brain context as a distinct <company-brain-context> block

Verification

  • npm test

Notes

  • Built output and manifest are included because this package ships dist/.

Summary by CodeRabbit

  • New Features

    • Added stable account key and source scope support for Company Brain context resolution, enabling more precise account filtering and selection.
  • Documentation

    • Updated configuration guidance for Company Brain tools, including new account filtering options and example configurations.
  • Tests

    • Enhanced test coverage for new account resolution and context configuration features.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 26, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 74922b67-c459-4aaf-9f0e-4fc7e5f7d108

📥 Commits

Reviewing files that changed from the base of the PR and between 8e42b40 and b02e40c.

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

📝 Walkthrough

Walkthrough

This PR extends Company Brain context resolution to support stable account key–based account selection and optional source scope filtering. Changes include type definitions, config schema updates, core resolution logic, client API wiring, canary script enhancements, comprehensive test coverage, and documentation updates.

Changes

Company Brain Key-Based Account Resolution

Layer / File(s) Summary
Type & Schema Contracts
src/index.ts (type definition), openclaw.plugin.json, src/index.ts (configSchema)
Define CompanyBrainSourceScope union type (internal | customer_accounts), extend EvaMemoryConfig interface with companyBrainContextAccountKey and companyBrainContextSourceScope fields, and update plugin schema in both manifest and source code.
Config Parsing & Defaults
src/index.ts
Add default values for new config fields and implement validation for sourceScope to accept only allowed values; wire parsed accountKey and sourceScope into returned config object.
Account Resolution & Context Triggering
src/index.ts
Extend shouldAttemptCompanyBrainContext to trigger when accountKey is configured; implement filtering in resolveCompanyBrainAccountFromAccountsList to match accounts by key; extend resolution payload to include account_key and source_scope; update resolveCompanyBrainAccountForContext to treat key as stable resolver alongside account ID and adjust search fallback behavior.
Cortex Client & Tool Integration
src/index.ts
Update CortexClient.listCompanyBrainAccounts method to accept sourceScope and accountKey parameters and forward them as query params; extend company_brain_accounts_list tool schema to expose these optional parameters to agents and wire through to client calls.
Test Coverage
src/__tests__/company-brain-context-format.test.ts, src/__tests__/company-brain-tools.test.ts, src/__tests__/plugin-manifest-parity.test.ts
Add test cases for config parsing including validation of sourceScope values; update account resolution tests to exercise key-based filtering and resolution payload fields; add manifest parity assertions for new schema properties.
Canary Script Support
scripts/company-brain-canary.mjs
Add support for COMPANY_BRAIN_ACCOUNT_KEY and COMPANY_BRAIN_SOURCE_SCOPE environment variables; incorporate into account-resolution request; update account selection fallback to prefer accounts matching the provided key via account_key or external_id.
Documentation Updates
README.md, docs/company-brain-tools.md
Update README configuration table to document new fields and add ElectricSheep internal beta configuration example; enhance tools documentation with guidance on calling company_brain_accounts_list before other tools and using account-key filters; update canary example environment variables.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • electricsheephq/evaos-cortex-plugin#29: Implements the initial Company Brain "auto" context injection and account-resolution flow that this PR extends with key-based resolution.
  • electricsheephq/evaos-cortex-plugin#32: Modifies the same account-resolution and context-injection logic in src/index.ts that is further refined here with accountKey/sourceScope support.
  • electricsheephq/evaos-cortex-plugin#30: Establishes manifest-parity test and dist manifest sync logic that this PR extends to validate new companyBrainContextAccountKey and companyBrainContextSourceScope schema properties.

Poem

🐰 A business account key, so neat and so stable,
Scopes filter the depths, makes queries more able,
From schemas to resolvers, the context flows through,
ElectricSheep's brain now sees what is true! ✨

✨ 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-scope

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@100yenadmin 100yenadmin marked this pull request as ready for review May 26, 2026 22:24
@100yenadmin 100yenadmin merged commit 6c1fbca into main May 26, 2026
5 checks passed
@100yenadmin 100yenadmin deleted the codex/company-brain-context-scope branch May 26, 2026 22:24
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