Polarize
GitHub Get in touch

Changelog

What changed in the code.

Merged pull requests across the public polarizetech repositories, newest first, synced from GitHub once a day. Every repository, with the posts about it, is under Work.

2026-10-29 retrieval-augmented-generation #23

Lay out replies from an editable template file

Replies (the quick ask reply, the queued/working reply, and the research pipeline’s finished answer) are now laid out by config/replies.default.md. Your own copy goes in the gitignored config/replies.md; a template left out of it keeps the default. It’s read on every reply, so edits need no restart.

Shorthands:

  • {{name}} places a block (passages, steps, limits, sources…; the file lists every block per template)
  • {{#name}}…{{/name}} shows only when the block has something in it; {{^name}}…{{/name}} only when it’s empty
  • <!-- notes --> are dropped

Code still writes every block, so quotes, evidence ids and sources are never retyped; the template only picks order, headings and what appears. An unknown name stays visible so a typo shows.

Checks: the default template reproduces the old output exactly (9,720 relay cases and 27 answer cases, including companions, compared with the old code). The run log now stores bottom_line so the session capsule no longer depends on the answer’s heading. Tests use only the tracked templates. Suite (415 + new), ruff and pyright pass.

🤖 Generated with Claude Code

2026-10-28 polarize-ui #7

Add the build-vs-reuse register

Adds reuse.toml, this repo’s build-vs-reuse register: each piece of our own scientific code, its state, and the open-source, peer-reviewed tool that does (or could do) the same job, with the test that runs them side by side where one exists.

Entries: 5 (5 candidate).

Seeded from the 2026-10-28 review, so treat entries as a starting point. The checker (research-reuse in polarizetech/retrieval-augmented-generation, docs/reuse-register.md) reads this file in place of its private seed once merged.

🤖 Generated with Claude Code

2026-10-28 paper-fetch #14

Add the build-vs-reuse register

Adds reuse.toml, this repo’s build-vs-reuse register: each piece of our own scientific code, its state, and the open-source, peer-reviewed tool that does (or could do) the same job, with the test that runs them side by side where one exists.

Entries: 6 (4 candidate, 2 none-found).

Seeded from the 2026-10-28 review, so treat entries as a starting point. The checker (research-reuse in polarizetech/retrieval-augmented-generation, docs/reuse-register.md) reads this file in place of its private seed once merged.

🤖 Generated with Claude Code

2026-10-28 olimex-shield #4

Add the build-vs-reuse register

Adds reuse.toml, this repo’s build-vs-reuse register: each piece of our own scientific code, its state, and the open-source, peer-reviewed tool that does (or could do) the same job, with the test that runs them side by side where one exists.

Entries: 9 (6 candidate, 2 none-found, 1 tandem).

Seeded from the 2026-10-28 review, so treat entries as a starting point. The checker (research-reuse in polarizetech/retrieval-augmented-generation, docs/reuse-register.md) reads this file in place of its private seed once merged.

🤖 Generated with Claude Code

2026-10-28 neural-memory #10

Add the build-vs-reuse register

Adds reuse.toml, this repo’s build-vs-reuse register: each piece of our own scientific code, its state, and the open-source, peer-reviewed tool that does (or could do) the same job, with the test that runs them side by side where one exists.

Entries: 29 (4 candidate, 24 none-found, 1 tandem).

Seeded from the 2026-10-28 review, so treat entries as a starting point. The checker (research-reuse in polarizetech/retrieval-augmented-generation, docs/reuse-register.md) reads this file in place of its private seed once merged.

🤖 Generated with Claude Code

2026-10-28 iphone-magnetometer #1

Add the build-vs-reuse register

Adds reuse.toml, this repo’s build-vs-reuse register: each piece of our own scientific code, its state, and the open-source, peer-reviewed tool that does (or could do) the same job, with the test that runs them side by side where one exists.

Entries: 19 (11 candidate, 8 none-found).

Seeded from the 2026-10-28 review, so treat entries as a starting point. The checker (research-reuse in polarizetech/retrieval-augmented-generation, docs/reuse-register.md) reads this file in place of its private seed once merged.

🤖 Generated with Claude Code

2026-10-28 retrieval-augmented-generation #22

Build-vs-reuse register and runner

Adds research-reuse, a runner that tracks where we wrote our own scientific code instead of using an open-source, peer-reviewed package, and which of our pieces run in tandem with one.

  • Register: each repo lists its custom scientific code in reuse.toml (state: tandem, candidate, none-found or replaced; the alternative; the comparison test). Until a repo has one, a private seed in $REUSE_HOME/registers/ is used.
  • Catalogue: config/reuse-catalogue.default.toml, 34 packages with their papers (all DOIs resolve via --check-dois). Local additions go in the gitignored config/reuse-catalogue.toml.
  • Runner: scans local checkouts under ~/Sites and shallow clones of the org’s other repos, finds catalogue packages in dependency files and imports, checks each register entry (path exists, tandem check exists and names the alternative, alternative already a dependency), and writes report.{json,md,html}, a running history.csv and flat dashboard tables to $REUSE_HOME. No model is used.
  • Reports name private repositories, so they stay in $REUSE_HOME and are never committed here.

Format and states: docs/reuse-register.md.

Tests: tests/test_reuse.py (9); full suite passes (408 + new).

🤖 Generated with Claude Code

2026-10-28 retrieval-augmented-generation #19

Plan the gateway as the hub, and record hosting options

Docs only.

  • docs/hub-plan.md: the plan for the next group of work. The gateway becomes the hub every request goes through:
    • a request ledger and board;
    • queues, limits and deadlines;
    • duplicate and conflict detection across sessions;
    • health checks, circuit breakers and labelled fallbacks, with one error contract;
    • usage meters (OpenRouter, NEAR AI, the Claude plan, ChatGPT, local) and per-step provider ladders down to a local model;
    • project capsules and a size watcher, to keep sessions small and save credits.

    It is split into four phases and ends with the decisions still open.

  • docs/hosting-options.md: a dated reference to update over time. It covers the local-first decision, the dropped droplet, GitHub Codespaces, and what Hugging Face Spaces, Inference Endpoints and Inference Providers would mean here.
  • docs/mcp-clients.md links to both.

🤖 Generated with Claude Code

2026-10-28 retrieval-augmented-generation #21

Hub phase 2: queues, deadlines, duplicates, stale processes

Builds phase 2 of the hub plan, and brings in the plan itself (#19, which conflicted with #20 in one paragraph of docs/mcp-clients.md; both paragraphs are kept). Merging this marks #19 merged.

What’s in it

  • Queues and limits (research_mcp/hub/queue.py): retrieval runs two at a time and the rest wait in order. A research request the pipeline turns away (PIPELINE_MAX_RUNS) waits in line and starts when a slot frees, for up to 2 h. Model calls are limited per provider across all runs in the pipeline process (OpenRouter 8, NEAR AI 4, local 1).
  • Memory pressure: retrieval and research wait while less than 10 % of memory is free (kern.memorystatus_level on macOS, MemAvailable on Linux).
  • Reply deadline: every ask answers within 45 s. Longer work replies queued (position and estimate, under the error contract) or working, carries on in the gateway, and leaves its result for hub__result.
  • Duplicate research (research_mcp/hub/overlap.py): the same words, or a bge-m3 similarity of 0.92 or more, attaches to the request on the go instead of starting a second run. From 0.80 the run starts with a warning naming the other request. Without embeddings only exact matches attach.
  • Stale processes (research_mcp/hub/processes.py): hub__board lists stdio gateways (each holding its own library copy), gateways older than the code, and orphaned upstreams. They’re reported, never killed. On this Mac it currently finds five stdio gateways.
  • Ledger: an attached_to column, added to the live database on open. Run updates reach every attached request.
  • Docs: docs/hub-plan.md marks phases 1 and 2 built and records the 2026-10-28 decisions. docs/mcp-clients.md describes the queues and duplicates.

Decisions applied

Code conflicts are not held: each session works in its own worktree (decided 2026-10-28). The plan’s “held” for code conflicts is replaced by the existing mention of other sessions’ work.

Checks

  • tests/test_hub_phase2.py: lanes, memory hold, deadline replies finishing into the ledger, a busy retrieval lane, a full pipeline queuing then starting, exact and paraphrase attaches, near-duplicate warnings, no-embeddings behaviour, ledger migration, stale-process parsing, and the one-at-a-time local model across runs.
  • 400 tests pass; ruff and pyright --pythonpath .venv/bin/python are clean.

🤖 Generated with Claude Code

2026-10-28 retrieval-augmented-generation #20

Hub phase 1: ledger, error contract, health, usage, ladders

Builds phase 1 of the hub plan (docs/hub-plan.md, in #19).

What’s in it

  • Request ledger (data/pipeline/hub.sqlite): every ask gets a request_id and a row (client, session, project, repo, route, specialist, question fingerprint, files named, status, timings, problems; for a research run, provider, tokens and cost once its calls pass through the gateway). New tools: hub__status, hub__board, hub__result(id).
  • One error contract on every non-success reply: status, component, what_failed, impact, fallback_used, options, recommendation, retry_after. The relay shows it first in plain words. Gateway tool errors, upstream errors and the bridge’s “gateway is down” all carry it.
  • Health and circuit breakers for the reranker, embeddings, paper library, model provider, verifier, upstream processes, GitHub and the corpus (3 failures, then skipped for 120 s, then probed), with the plan’s labelled fallbacks.
  • Usage meters: OpenRouter /api/v1/key + /api/v1/credits (balance, day/week/month spend, burn per day, run-out); NEAR AI reported as “needs a reporting token” until ~/.config/polarize/nearai-reporting.env exists; Ollama up/installed/loaded. Adds hub__usage and a cached one-line readout under each relay.
  • Provider ladders (research_pipeline/ladder.py, config/hub.default.toml): planning, extraction and writing go OpenRouter → NEAR AI direct → local qwen3:4b-instruct-2507, skipping a rung that is failing or low (USD 1 or 95 %). Each move is logged in the run’s notes and ladder log. Checking stays on the local verifier.

Decisions (asked 2026-10-28)

  • Code conflict: worktrees. Nothing is blocked; ask mentions recent code work on the same repo from another session and says to use your own worktree.
  • Degraded fallbacks: ask once per session per component. The reply is needs_decision; the client passes decisions={"<component>": "fallback"|"stop"}, and that choice holds for the rest of the session.
  • Session identity: pass it, or the gateway infers it. The bridge sends X-Hub-Session/X-Hub-Project; inferred sessions are marked in the ledger.
  • Ladders and thresholds: as proposed.

Limits

  • Switching off only the reranker or only the embeddings needs rerank/dense flags on paper-fetch’s retrieve tool. The gateway sends them as soon as the tool lists them; until then those two fall back to scholarly search, and the relay says so.
  • Inside a running pipeline, ladder moves happen automatically and are labelled; only the pre-run check asks.
  • Upstream restart with backoff is phase 3: for now a dead upstream fails with the restart command.
  • docs/hub-plan.md should record these decisions once #19 merges; for now they are in docs/mcp-clients.md.

Checks

  • tests/test_hub.py: fault injection for every component, plus the ledger, breakers, meters, ladders and the gateway’s hub tools.
  • 388 tests pass; ruff and pyright --pythonpath .venv/bin/python are clean.

🤖 Generated with Claude Code