CodeLoop AI — How It Works

Four views: the big picture, one chat message, the hybrid multi-LLM flow, and the safety gates.

1. Big picture

The model proposes; the extension disposes. LLMs only ever emit text — every real action goes through typed tools, and every risky action through the approval gate.

flowchart TD
    U([You]) --> CH[Chat panel / Commands]
    CH --> LOOP[Agent loop]
    LOOP <--> LLM[LLM provider
ollama · lmstudio · openai · claude · copilot] LOOP --> REG[Tool registry] REG --> T1[Workspace tools
read · search · patch] REG --> T2[Salesforce tools
sf CLI · orgs · tests] REG --> T3[Analysis tools
Apex · LWC · logs · impact] REG --> T4[Migration tools
CSV · mapping · reconcile] T1 & T2 & T3 & T4 --> AP{Approval gate} AP -->|approved| EX[Execute + verify + journal] AP -->|rejected| LOOP EX --> FS[(Workspace files)] EX --> SF[(Salesforce orgs)] style AP fill:#fff3cd,stroke:#b8860b style LLM fill:#e8f0fe,stroke:#4a76c9

2. Life of one chat message

The loop repeats up to maxIterations: model streams a response → one tool call is parsed and (if needed) approved → the structured result feeds back in. It ends on FINAL, plain text, your Stop, or no-progress detection.

sequenceDiagram
    actor You
    participant P as Chat panel
    participant A as Agent loop
    participant M as LLM
    participant T as Tool
    You->>P: task
    P->>A: run(task, mode)
    loop up to maxIterations
        A->>M: prompt + history
        M-->>P: streamed tokens (live)
        M-->>A: full response
        alt starts with FINAL:
            A-->>P: report — done ✅
        else contains a tool call
            A->>T: execute(input)
            T-->>You: approval card (if risky)
            You-->>T: Approve / Reject
            T-->>A: structured result
            Note over A: result appended,
next iteration else malformed tool syntax A->>M: corrective bounce (≤2 retries) else plain text A-->>P: shown — waiting for you ⏸ end end

3. Hybrid multi-LLM flow (Run Hybrid Task)

The strong model thinks, the local model types, deterministic tools act — and you gate every write. Colors mark who does each step.

flowchart TD
    U([Your task]) --> D0[Discover project
compressed summary] D0 --> P1[PRIMARY: plan
1–5 single-file steps] P1 --> G1{You confirm
the plan} G1 -->|reject| STOP1([stopped]) G1 -->|proceed| RT{Task router} RT -->|small, low-risk| L1[LOCAL: generate
file content] RT -->|>3 files · security ·
production impact| P2[PRIMARY: generate] L1 --> G2{Approval card
with diff preview} P2 --> G2 G2 -->|approve| AP1[Apply + verify
+ journal] G2 -->|reject| SKIP[step skipped] AP1 --> V1[Static Apex review] AP1 --> V2[sf apex tests
approval-gated] V1 & V2 --> P3[PRIMARY: review
compressed diffs + results] P3 --> VD{Verdict} VD -->|approved ✅| REP[Report + token usage] VD -->|blocking issues ⛔| FIX[fix via chat, or revert] style P1 fill:#e8f0fe,stroke:#4a76c9 style P2 fill:#e8f0fe,stroke:#4a76c9 style P3 fill:#e8f0fe,stroke:#4a76c9 style L1 fill:#e6f4ea,stroke:#3d8b57 style D0 fill:#f1f3f4,stroke:#888 style AP1 fill:#f1f3f4,stroke:#888 style V1 fill:#f1f3f4,stroke:#888 style V2 fill:#f1f3f4,stroke:#888 style G1 fill:#fff3cd,stroke:#b8860b style G2 fill:#fff3cd,stroke:#b8860b
Primary model (Claude / GPT / Copilot) Local model (Ollama / LM Studio) Deterministic (no LLM) You decide

4. Safety gates

Every tool declares a risk level; the approval mode decides what runs automatically. Some things never auto-run, in any mode.

flowchart TD
    TC[Tool call] --> RL{Risk level}
    RL -->|read| R1{manual mode?}
    R1 -->|no| RUN[Run]
    R1 -->|yes| ASK[Ask you]
    RL -->|local-write| W1{autonomous mode AND
approvals not forced?} W1 -->|yes| RUN W1 -->|no| ASK RL -->|org-write| ASK RL -->|destructive| ASK ASK -->|approve| RUN ASK -->|reject| NO[Not executed] RUN --> PT{Target org
write-protected?} PT -->|yes, org write| ASK2[Second explicit
confirmation] PT -->|no| DONE[Execute · verify · journal · audit log] ASK2 -->|approve| DONE ASK2 -->|reject| NO style ASK fill:#fff3cd,stroke:#b8860b style ASK2 fill:#f8d7da,stroke:#b02a37 style DONE fill:#e6f4ea,stroke:#3d8b57

Always ask, regardless of mode: shell commands, MCP tools, org writes, anything destructive. Production/unknown orgs add the red second gate. Every decision is audit-logged; every file write is verified and revertible.