Skip to content

feat: Enterprise Architecture — 9-Layer Pipeline, Isolation, Sandbox, Resilience - #2

Open
ilvan-develop wants to merge 14 commits into
developfrom
feature/enterprise-arch
Open

feat: Enterprise Architecture — 9-Layer Pipeline, Isolation, Sandbox, Resilience#2
ilvan-develop wants to merge 14 commits into
developfrom
feature/enterprise-arch

Conversation

@ilvan-develop

Copy link
Copy Markdown
Owner

Resumo

Implementação completa da arquitetura enterprise para o BehaviorOS, incluindo 4 fases de engenharia com 80+ ficheiros criados.

Fases Implementadas

Fase 1: Motor do Interceptor Híbrido

  • PipelineDispatcher com Chain of Responsibility pattern
  • 9 camadas: dna-loader, schema-validator, behavioral, domain-invariants, governance, decision, quality, audit-trail, learning
  • Interceptors: timeout, metrics, audit-log
  • Modos: conversational (skip layers 4,5,6,8), transactional (todas)
  • YAML→OPA compiler com policy store

Fase 2: Isolamento de Contexto Multi-DNA

  • DDD Boundaries: DNABoundary, AgentBoundary, ExecutionBoundary
  • Anti-Corruption Layers: AgentACL, DataACL, EventACL
  • Permission Matrix: conversational/transactional/hybrid
  • Cross-DNA Guard: bloqueia acesso cross-DNA por padrão

Fase 3: Sandbox Ephemeral & Shadow-Mode

  • SandboxEngine: ephemeral, persistent, shadow
  • Shadow Pipeline: traffic capture → replay → diff → alerts
  • Canary Deployer: 5% → 25% → 50% → 100% com auto-rollback
  • Compliance Reports: EU AI Act, PCI-DSS, SOC 2

Fase 4: Resiliência Armada & Circuit Breakers

  • Rate Limiter: token-bucket, sliding-window, adaptive
  • Escalation: warning (80%), throttle (90%), block (100%)
  • Circuit Breaker: closed → open → half-open
  • Agent Isolation: suspicion detection, quarantine, sandbox

Typecheck Fixes

  • schemas: added --dts flag
  • 7 erros de typecheck corrigidos
  • 164 testes passando

Verificação

  • ✅ Typecheck: 0 erros
  • ✅ Testes: 164 passed
  • ✅ Lint: limpo
  • ✅ Audit: PASS

Arquivos

  • 80 ficheiros criados
  • 7 ficheiros modificados
  • 10,927 linhas adicionadas

Co-authored-by: BehaviorOS Agent Team agents@behavioros.dev

ilvan-develop and others added 14 commits July 16, 2026 02:11
…, sandbox, resilience

Phase 1: Hybrid Interceptor Motor
- PipelineDispatcher with Chain of Responsibility pattern
- 9 layers: dna-loader, schema-validator, behavioral, domain-invariants, governance, decision, quality, audit-trail, learning
- Interceptors: timeout, metrics, audit-log
- Mode adapters: conversational (skip layers 4,5,6,8), transactional (all)
- YAML→OPA compiler with policy store and evaluator

Phase 2: Multi-DNA Context Isolation
- DDD Boundaries: DNABoundary, AgentBoundary, ExecutionBoundary
- Anti-Corruption Layers: AgentACL, DataACL, EventACL
- DNAContext, AgentContext with ACL validation
- Permission Matrix: conversational/transactional/hybrid modes
- CrossDNAGuard blocks cross-DNA access by default

Phase 3: Ephemeral Sandbox & Shadow-Mode
- SandboxEngine: ephemeral, persistent, shadow environments
- Shadow Pipeline: traffic capture → replay → diff analysis → alerts
- Canary Deployer: 5% → 25% → 50% → 100% with auto-rollback
- Compliance Reports: EU AI Act, PCI-DSS, SOC 2

Phase 4: Armed Resilience & Circuit Breakers
- Rate Limiter: token-bucket, sliding-window, adaptive algorithms
- Escalation: warning (80%), throttle (90%), block (100%)
- Circuit Breaker: closed → open → half-open states
- Agent Isolation: suspicion detection, quarantine, sandbox execution

Typecheck fixes:
- schemas: added --dts flag for type declarations
- core-engine.test: added autoApply/applied properties
- governance-engine: removed duplicate escalate check
- pipeline-engine: added skillsUsed/skillsScore, fixed PipelineReport emit
- quality-engine: fixed string→boolean/number type mismatches
- sqlite-store: fixed boolean comparison

Co-authored-by: BehaviorOS Agent Team <agents@behavioros.dev>
Added 5 new sections:
- Pipeline Dispatcher (9-layer architecture)
- Domain Isolation (DDD + ACL)
- Sandbox & Shadow Mode
- Resilience (Rate Limiter + Circuit Breaker)
- Package Architecture (new packages)

Updated from 162 to 562 lines.

Co-authored-by: BehaviorOS Agent Team <agents@behavioros.dev>
- biome.json: exclude *.css, e2e-tests, finpay-integration from linting
- biome.json: fix deprecated 'recommended' field, fix folder ignore syntax
- core/package.json: add --dts flag to build script
- sdk/package.json: add --dts, add core/schemas as devDeps for topological order
- sdk/src/index.ts: remove unused qualityEngine/missionEngine assignments
- cli/package.json: add @behavioros/schemas as devDep for typecheck
- mcp-server/package.json: add @behavioros/schemas as devDep for typecheck
- mcp-server: fix missing 'applied' in LearningEvent calls
- mcp-server: fix missing 'autoApply' in learning config
- mcp-server: fix ZodOptional .shape access with type casts
- observability-dashboard: restore removed 'rules' private property
- core rate-limiter test: fix AuthorityLevel type
- seed-data.ts: remove unused 'now' variable
- bos-select-dna.ts: fix string concatenation in template literal
- SDK test: add missing 'applied' and 'confidence' fields

Audit: lint PASS, typecheck PASS (12/12), build PASS, tests PASS (60/60 + 439 + 38 + 17)
Added 418 new tests across 10 test files:

Pipeline Dispatcher (26 tests):
- Layer ordering, fail-fast, skip layers, never-block
- Interceptors, mode adapters

Domain Boundaries (25 tests):
- DNABoundary, AgentBoundary, ExecutionBoundary

Agent ACL (43 tests):
- Malicious pattern detection, XSS sanitization
- Sensitive field filtering

Permission Matrix (26 tests):
- Conversational/transactional/hybrid modes

Rate Limiter (40 tests):
- Token bucket, sliding window, adaptive
- Per-agent, per-DNA, per-action limits

Circuit Breaker (31 tests):
- State transitions (closed→open→half-open)
- Event emission

Circuit Breaker Detectors (56 tests):
- FailureDetector, AttackDetector, AnomalyDetector

Circuit Breaker Recovery (43 tests):
- AutoRecovery, ManualRecovery

Agent Isolation (84 tests):
- SuspicionDetector, QuarantineManager
- SandboxExecutor, ForensicCollector

Rate Limiter Policies (35 tests):
- PerDNAPolicy, PerActionPolicy

Total: 573 tests passing (164 existing + 418 new)

Co-authored-by: BehaviorOS Agent Team <agents@behavioros.dev>
New commands for enterprise architecture features:

- behavioros diff: Compare two DNA files (governance, quality gates, patterns)
- behavioros simulate: Simulate prompt against DNA configuration
- behavioros deploy: Canary deployment with staged rollout (5→25→50→100%)
- behavioros drift-check: Behavioral drift analysis with severity scoring

Each command follows existing CLI patterns (commander, ora, chalk, cli-table3).

Co-authored-by: BehaviorOS Agent Team <agents@behavioros.dev>
Implements tamper-evident audit trail verification:

- HashChain: SHA-256 chain with genesis block and incremental verification
- AuditChainVerifier: verify(), verifyLast(n), verifyEntryAt(i)
- VerificationResult: broken links, tampered entries, chain metadata
- Supports 7-year retention for regulatory compliance (EU AI Act, PCI-DSS)

Co-authored-by: BehaviorOS Agent Team <agents@behavioros.dev>
Regulatory compliance reporting engine:

- ComplianceExporter: orchestrates all framework assessors, JSON/Markdown/CSV output
- EUAIActAssessor: risk classification, transparency, human oversight, data governance
- PCIDSSAssessor: 12 requirement categories, network security, access control
- SOC2Assessor: 5 trust service criteria, control mapping, gap analysis
- Audit chain hash verification status in all reports
- Summary statistics with per-framework scores and critical gaps

Co-authored-by: BehaviorOS Agent Team <agents@behavioros.dev>
OpenTelemetry Pipeline Tracing:
- Lightweight OTel-compatible tracer (no-op by default)
- tracePipeline() and traceLayer() wrappers
- Span attributes: pipeline.id, layer.name, layer.index
- Enable with BEHAVIOROS_TELEMETRY=console env var
- Pipeline dispatcher now wraps each layer in traceLayer()

Canary Prompt Schema:
- Fixed type mismatch in canary-prompt-runner.ts
- All 4 files verified: schema, registry, runner, index

573 tests passing, typecheck clean.

Co-authored-by: BehaviorOS Agent Team <agents@behavioros.dev>
Deep audit found 13 gaps between docs and code. All fixed:

CRITICAL:
- AGENTS.md: Fixed tool names (underscores → hyphens) to match MCP server

HIGH:
- ARCHITECTURE.md: Updated PipelineHandler → PipelineDispatcherLayer
- ARCHITECTURE.md: Fixed 'New Packages' → 'Internal Modules' in core
- SDK.md: Added 9 missing methods (pipeline + decision)
- CLI.md: Added 4 new commands + fixed compile/validate options
- package.json: Added 'types' to exports (core, sdk, cli, dnas)

MEDIUM:
- ARCHITECTURE.md: Fixed MCP tools count (8→36), removed contradiction
- ARCHITECTURE.md: Fixed AgentIsolation (single → 4 classes)
- DNAs.md: Documented enterprise-agent-review.yaml (EAARG)
- SDK.md: Added 10 missing schema type re-exports

LOW:
- cli: Removed unused sdk peer dep
- dnas: Removed unused core peer dep
- mcp-server: Removed duplicate core dep

12/12 packages typecheck clean. 573 tests passing.

Co-authored-by: BehaviorOS Agent Team <agents@behavioros.dev>
The landing page (apps/landing/) was redundant with the web dashboard (apps/web/).
Consolidating into a single web app for simplicity.

Removed:
- apps/landing/ (Next.js marketing page)
- Workspace reference in pnpm-lock.yaml

Co-authored-by: BehaviorOS Agent Team <agents@behavioros.dev>
Phase 1: Zero-Trust Foundations (7 fixes)
- Governance strict default: true
- Conversational mode: removed governance+audit-trail bypass
- Path traversal protection: startsWith check + 1MB limit
- Regex injection fix: escape special chars in glob matching
- Authority verification: verifiedAuthority field + validation
- DNA override guard: blocks autonomy.never_do override
- HMAC audit chain: optional signingKey for HMAC-SHA256

Phase 2: Latency Optimization (2 fixes)
- Pre-index governance rules: O(1) rule lookup
- Extract God Class: MissionManager + AgentManager

Phase 3: Active Defense (2 fixes)
- Unified authority hierarchy: shared constant
- SQLite integrity check: PRAGMA on startup

Phase 4: Observability & Production (6 fixes)
- Structured logging: Logger class with JSON/text output
- Governance bypass detection: bypassAttempts tracking
- Pipeline metrics: MetricsCollector for telemetry
- Schema tests: 47 tests for Zod schemas
- CI typecheck: removed continue-on-error
- Security workflow: npm audit in GitHub Actions

Verification:
- Typecheck: 0 errors (all packages)
- Tests: 573 + 47 = 620 passing
- Lint: clean

Co-authored-by: BehaviorOS Agent Team <agents@behavioros.dev>
…cement

- SDK: loadDNA() test now uses async/await with rejects.toThrow()
- CLI: empty personas test now expects Zod schema rejection at load time
- 709 tests passing (632 core + 60 SDK + 17 CLI)
- DNA loader: skip path traversal check for absolute paths (enables cross-project DNA loading)
- Schema: add parallel_pairs to WorkflowStepSchema type enum
- Enables finpay-app to load its DNA from behavioros MCP server
- 739 tests passing (632 core + 60 SDK + 47 schemas)
- Complete guide for AI agent teams using BehaviorOS day-to-day
- FinPay as real-world example (28 agents, payments domain)
- DNA selection, mission lifecycle, delegation flow
- Governance rules, quality gates, audit trail
- 4 practical examples: bug fix, feature, security fix, deployment
- Tool reference table (36 MCP tools)
- Golden rules for orchestrator and agents
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