Skip to content

feat: Phase 2 local intelligence engine - #95

Merged
alvarolorentedev merged 1 commit into
mainfrom
feat/local-intelligence-engine
Nov 26, 2026
Merged

alvarolorentedev merged 1 commit into
mainfrom
feat/local-intelligence-engine

Conversation

@alvarolorentedev

@alvarolorentedev alvarolorentedev commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Summary

Phase 2 adds optional, local-first diagnostic intelligence to Barklarm 4.0:

  • A separate analysis pipeline from diagnostic evidence to a validated, cited diagnosis.
  • Deterministic context assembly, prompt v1, strict JSON validation, citation subset checks, secret/destructive-command rejection and one bounded repair attempt.
  • A provider-independent adapter for OpenAI-compatible endpoints, including a managed llama.cpp runtime and custom endpoints.
  • A pinned, SHA-256-verified Qwen3-1.7B-Instruct Q4_K_M model download and a pinned llama.cpp b12732 sidecar.
  • Explicit consent for non-loopback destinations, OS credential storage for API keys, and no automatic fallback to remote inference.
  • Intelligence settings, model management, an AI analysis panel and 13 deterministic mock scenarios.
  • ADRs 0009–0013, spec 0002, a model-selection report and a runtime/platform matrix.

Scope

Intelligence is disabled by default. Monitoring, notifications, tray, diagnostic evidence and the issue webhook are unchanged when intelligence is disabled, unavailable or failed. No automatic remediation, tools, shell execution, MCP, incident history or cloud backend is introduced.

Architecture

EvidenceManager -> available/cleared event -> AnalysisManager
  -> ContextAssembler -> Prompt v1 -> provider -> Validator
  -> AnalysisSnapshot (memory only)
  • src/types/Intelligence.ts: analysis, provider, model and runtime contracts.
  • src/core/intelligence/: assembler, prompt, endpoint policy, providers, validator, analysis lifecycle.
  • src-tauri/src/intelligence/: runtime supervisor, model manifest/download, hardware, consent and credential storage.
  • src/mainview/: settings, analysis panel and mock runtime.

ADRs: 0009 analysis boundary, 0010 provider trust/consent, 0011 managed runtime, 0012 artifact supply chain, 0013 evaluation/model selection.

Model selection

Default: Qwen3-1.7B-Instruct Q4_K_M (Apache-2.0, 1,107,409,472 bytes, SHA-256 b139949c…), served by llama.cpp b12732 with thinking disabled.

  • Three repeated Qwen3 runs after destructive-command redaction: 16/16 automatic checks.
  • Human review: 15/16 accepted for correctness and 15/16 for actionability (93.75%).
  • Qwen2.5-1.5B followed a prompt injection and was rejected.
  • Phi-3.5-mini had one invalid output and was materially slower (21–83 s per case).
  • Acceptance thresholds were not lowered. See docs/evaluations/0001-model-selection.md.

Verification

Executed in this workspace (macOS arm64, 16 GB, Bun 1.4.5, Rust 1.99):

bun install --frozen-lockfile   no changes
bun run check                   passed: 466 tests, coverage gates, renderer build,
                                mock isolation and 16/16 deterministic evals
bun run test:e2e                passed: 23 Playwright tests
bun run audit                   no high/critical production vulnerabilities
bun run rust:fmt                passed
bun run rust:clippy             passed
bun run rust:test               9 tests passed
bun run test:evals:mock         16/16 passed
bun run test:evals:local        16/16 automatic checks in the final repeated run
bun run build                   Barklarm 4.0.0 macOS arm64 app and dmg built
bun run sidecar:smoke           llama.cpp b12732 version check passed

GitHub Actions run 45727624900 is green: Quality gate, Browser end-to-end, Rust native checks, Native sidecar and Production dependency audit.

Coverage: 86.91% lines/statements, 86.05% branches, 87.09% functions. A separate native smoke launched the bundled sidecar with its libraries and an ephemeral bearer token and verified its health endpoint.

Platform support

Target Managed AI Validation
macOS arm64 Enabled Full local packaging, sidecar start, real model inference
macOS x64 Pending smoke Packaged in CI
Linux x64/arm64 Pending smoke Packaged in CI; Linux sidecar smoke job
Windows x64 Pending smoke Packaged in CI

Other platforms keep the traditional radiator and custom-provider option. See docs/evaluations/0002-runtime-platform-matrix.md.

Independent review

An independent agent review was executed against the committed diff. Its material findings were addressed:

  • Per-destination API keys; credential changes invalidate the cached provider.
  • Native managed-runtime reasons are preserved in analysis snapshots.
  • Managed context selection is passed to the runtime.
  • Startup stale-runtime cleanup, PID removal and Windows process matching.
  • Download body timeout, partial-file cleanup and size verification.
  • Response-body timeout and control/bidi stripping of model output.
  • Imported configurations reset intelligence to disabled.
  • Analysis/evidence TTL cleanup and corrected cancellation state.

Remaining native test gaps and unexecuted platforms are stated below rather than claimed as validated.

Security

  • Analysis is separate from State and evidence; it never changes operational status or the webhook.
  • Unknown/omitted citations, malformed output, credential-like text and destructive commands are rejected.
  • Remote/private consent is stored outside imported configuration; changing the destination invalidates it.
  • Redirects and URL credentials are rejected; connectivity tests never include evidence.
  • Runtime binds only to loopback, uses an ephemeral token, an explicit argument allowlist and idle shutdown.
  • Model downloads require consent, verify size/SHA-256/GGUF header, use a temporary file and never execute content.
  • Tauri CSP is set; the HTTP capability remains broad for user-configured integrations and is documented as accepted risk.

Residual risks and release blockers are recorded in docs/engineering/SECURITY.md and the runtime matrix: non-macOS managed execution, signed/notarized bundles, full interactive CSP validation on every target, and the small synthetic evaluation set.

Screenshots

  • docs/media/intelligence-complete.png
  • docs/media/intelligence-remote-consent.png

Rollback

Disable intelligence, remove the downloaded model and delete the runtime artifact directory. Evidence and analysis are memory-only, so no data migration is required. Existing configurations load with intelligence disabled.

Definition of done

Implemented and locally validated on macOS arm64. Classified as implemented but not release-ready for all platforms until the remaining native smoke tests, signed/notarized bundles and broader evaluation are complete.

@alvarolorentedev
alvarolorentedev force-pushed the feat/local-intelligence-engine branch 4 times, most recently from 1ecd273 to b40b3c0 Compare November 26, 2026 00:14
@alvarolorentedev
alvarolorentedev marked this pull request as ready for review November 26, 2026 00:16
Adds the Phase 2 evidence-to-analysis pipeline, deterministic and real-model evaluation, a managed llama.cpp runtime with verified on-demand model downloads, custom OpenAI-compatible providers with explicit consent, and the intelligence settings/analysis UI with deterministic mock scenarios.
@alvarolorentedev
alvarolorentedev force-pushed the feat/local-intelligence-engine branch from b40b3c0 to d74ef8e Compare November 26, 2026 00:16
@alvarolorentedev
alvarolorentedev merged commit aa9bb4c into main Nov 26, 2026
5 checks passed
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