Skip to content

feat: QALB-7 cognitive architecture + frontend integration - #26

Merged
CodeWithJuber merged 1 commit into
mainfrom
feat/qalb7-full-architecture
Feb 28, 2026
Merged

feat: QALB-7 cognitive architecture + frontend integration#26
CodeWithJuber merged 1 commit into
mainfrom
feat/qalb7-full-architecture

Conversation

@CodeWithJuber

Copy link
Copy Markdown
Owner

Summary

  • 13 new backend modules implementing the 7-layer Quranic Cognitive Architecture (QALB-7): Fitrah (ethics), Nafs Triad (deliberation), Qalb Processor (LLM modulation), Fu'ad (conviction), Lubb (metacognition), Developmental Gate (capability gating), Causal Engine, Self-Healing, Parallel Agents, Imagination, Creativity, Dream Engine, Shura Council
  • 3 new memory modules: Lawh al-Mahfuz (immutable triple-checksum memory), Memory Pyramid (unified 5-layer query), Living Memory (adaptive lifecycle)
  • Full frontend cognitive UI: CognitiveBar pills under assistant messages (Qalb/Yaqin/Lubb/Ruh/Nafs/Lawwama), AgentCard Ruh energy bar, component extraction, dark mode redesign
  • 10 hardcoded rules replaced with proper QALB-7 module calls (dynamic turn limits, confidence scoring, checkpoint intervals, task classification)
  • XML tool-call parser for MiniMax-style models that output <invoke> XML instead of structured API
  • Docs updated: README with full architecture tables + developmental stages, docs/index.html with QALB-7 deep dive
  • Security: .gitignore now excludes .vault.key and .mcp.json

Changes

Area Files What
QALB-7 Core 13 new backend/core/*.py Cognitive pipeline modules
Memory 3 new backend/memory/*.py Lawh, Pyramid, Living Memory
Reasoning 1 new backend/reasoning/causal_engine.py Pearl's causal ladder
Agents 2 new backend/agents/*.py Shura Council, Perpetual Rotation
Base Agent backend/agents/base.py Wire QALB-7 pipeline + replace hardcoded rules
Providers backend/providers.py XML tool-call fallback parser
API backend/api/main.py Cognitive metadata in chat_complete WS
Frontend 10 new components, updated App.tsx CognitiveBar, AgentCard, full redesign
Types frontend/src/types.ts CognitiveMetadata interface
Docs README.md, docs/index.html QALB-7 architecture documentation
Config .gitignore, .env.example Security + Linode config
Skills 2 new backend/skills/builtin/*.py Linode cloud, SSH remote

66 files changed, +16,853 / -2,036 lines

Test plan

  • cd frontend && npm run build passes clean
  • cd backend && python -c "from agents.base import BaseAgent" imports all QALB-7 modules
  • Docker compose up — chat produces cognitive metadata in WS messages
  • CognitiveBar pills render under assistant messages
  • AgentCard shows Ruh energy bar with color gradient
  • Agent at nafs_level=3 gets 10 max_tool_turns (Mudghah stage)
  • MiniMax model XML tool calls are parsed and executed

🤖 Generated with Claude Code

…gration

Complete implementation of the 7-layer Quranic Cognitive Architecture:

Backend — QALB-7 Pipeline (13 new modules):
- Fitrah: innate ethical guardrails (NO_HARM, TRUTH, JUSTICE)
- Nafs Triad: 3-voice deliberation (Ammara/Lawwama/Mutmainna)
- Qalb Processor: cardiac oscillation modulating LLM temperature/tokens
- Fu'ad: Bayesian conviction engine (impression→belief→conviction)
- Lubb: metacognition (compress, coherence check, bias detection)
- Developmental Gate: 7-stage capability gating (Nutfah→Khalq Akhar)
- Causal Engine: Pearl's 3-rung causal ladder
- Self-Healing: Lawwama immune system with adaptive checkpoints
- Parallel Agents, Imagination, Creativity, Dream Engine
- Shura Council: multi-agent consultation

Backend — Memory Architecture (3 new modules):
- Lawh al-Mahfuz: immutable memory with triple-checksum integrity
- Memory Pyramid: unified 5-layer query engine
- Living Memory: adaptive memory lifecycle

Backend — Wiring & Fixes:
- Wire all QALB-7 modules into BaseAgent.execute()
- Replace 10 hardcoded rules with proper module calls
- Surface cognitive metadata in WS chat_complete messages
- XML tool-call fallback parser for MiniMax-style models
- Fix async coroutine issue in memory_pyramid.py
- SuperAgent starts at nafs_level=3 (Mudghah)

Frontend — Cognitive UI:
- CognitiveBar: expandable pill row under assistant messages
  (Qalb state, Yaqin level, Lubb quality, Ruh energy, Nafs badge)
- AgentCard: Ruh energy bar with color gradient
- Full UI redesign: component extraction, dark mode, responsive layout
- CognitiveMetadata TypeScript types

Docs & Config:
- README: full QALB-7 architecture docs, module tables, stage diagram
- docs/index.html: QALB-7 deep dive, updated project structure
- .gitignore: add .vault.key and .mcp.json
- New skills: linode_cloud, ssh_remote

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@CodeWithJuber
CodeWithJuber merged commit 6aa9a66 into main Feb 28, 2026
2 of 6 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1e61c899c0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread backend/api/main.py
Comment on lines +865 to +866
agent.ai_model = req.model_override
agent.ai_client = override_provider

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid mutating shared agent model state during overrides

The per-message override path mutates agent.ai_model/agent.ai_client on the shared agent instance before awaiting agent.execute, which creates a race when two chats hit the same agent concurrently. In an interleaving where request A and B both override models, A can restore mid-flight while B is still executing, and B can then restore a stale value, causing responses to run on the wrong model and leaving the agent in an unintended model state after completion.

Useful? React with 👍 / 👎.

Comment thread backend/api/main.py
Comment on lines +647 to +649
agent.ai_model = req.model
provider_obj = create_provider(model=req.model)
if provider_obj:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Validate provider before accepting agent model updates

This endpoint sets agent.ai_model even when create_provider(model=req.model) fails, so a model update can return success while leaving the old client attached. A common case is selecting a model that auto-resolves to a provider with no configured key; subsequent requests then run the old provider against the new model id and fail at inference time.

Useful? React with 👍 / 👎.

Comment thread backend/api/main.py
"role": agent.role,
"nafs_level": agent.nafs_level,
"capabilities": list(agent.tools.keys()),
"config": agent.config,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Persist updated model in agent profile configuration

The update flow saves agent.config back to storage but never writes req.model into that config, so model changes made via this endpoint are not durable. On restart, agent reconstruction reads profile["config"] and silently reverts to the old model, which makes model updates appear to “randomly” disappear after process restarts.

Useful? React with 👍 / 👎.

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