mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
* feat(vault): V2 — create-seam + drift janitor, archival, weekly org-report, KB ingest, Bases views + sync runbook Implements the vault V2 canonical spec end to end (the splice guard shipped separately and is reused at KB-ingest time): - materialize-on-create: TaskService.create writes each task's note best-effort from the moment it exists; the transition-touch stops no-oping on live work - drift janitor (services/vault_janitor.py + hourly _vault_janitor_loop): daily changed-task re-projection, random drift sample, archival pass — restart-proof via RoboCo/_meta/.janitor_state.json, 200/cycle caps, per-item isolation, processed-only resume markers, self-repairing state file - archival: vault_archive_days (30, 0=off) moves old terminal tasks' notes to RoboCo/Archive/<year>/Tasks/<project>/ — one write_task code path for janitor and rebuild, id8 lookup across Tasks/+Archive/, alias links keep moves safe - weekly org-report: VaultWriter.write_org_report renders Reports/<ISO-week>.md from MetricsService/UsageService (numbers duplicated into frontmatter for trend queries), once per ISO week, with a best-effort CEO notification - KB ingest: IndexType.VAULT_NOTES + VaultNotesIndexPlugin + _vault_kb_loop embed the CEO's RoboCo/Notes into the RAG corpus — injection guard as a hard gate (flagged notes quarantined with an idempotent callout), traversal- and symlink-contained at both config and engine layers, content-hash dedup, 50-ingest/cycle cap, frontmatter stripped; reaches roboco_kb_search, the mentor default domain, claim-time briefings (kind vault_note), and the panel KB browser; no migration (chunks table auto-creates; migration 030's CHUNK_TABLES tuple appended per the chunks_playbooks precedent) - Bases views (Task Board.base, Reports.base — schema verified against the Obsidian docs) + the Mac sync runbook vault asset - config/flags/compose: vault_archive_days, vault_report_enabled (flags card), vault_kb_enabled (flags card; NAS compose arms it, registry ships it off), vault_kb_dirs (+ overlap/traversal validator), vault_kb_interval_seconds - e2e smoke (tests/e2e_smoke/test_vault_v2.py): real create-seam, real janitor cycle incl. archival + state, real KB engine + real guard * docs: vault V2 sweep — map, RAG corpus, CLAUDE.md - docs/map/vault.md: V1+V2 — janitor/archival/report/KB data flows, new files, config, health posture - docs/map/orchestrator.md + task-service.md: the two new loops, the create seam, the three janitor queries - docs/rag/architecture/obsidian-vault.md: agent-facing what-changed (notes from creation, archive link-safety, CEO notes retrievable, weekly report) - docs/rag/architecture/config-reference.md: the five new settings - CLAUDE.md: vault paragraph covers V1+V2; flags-card list mentions the vault report/KB flags --------- Co-authored-by: Renn F <rennf93@users.noreply.github.com>
161 lines
5.3 KiB
Python
161 lines
5.3 KiB
Python
"""Org-memory keystone — role-shaped query + relevance-floored injection.
|
|
|
|
``shape_memory_query`` shapes the KB query per role; ``EvidenceRepo.similar_memory``
|
|
applies the cosine floor + top-K and returns the shaped items that
|
|
``_briefing_for`` injects as ``context_briefing["institutional_memory"]`` (only
|
|
when ``org_memory_enabled``).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import AsyncMock, MagicMock
|
|
|
|
import pytest
|
|
from roboco.models.optimal import IndexType, SearchResult
|
|
from roboco.services.gateway.evidence_builder import shape_memory_query
|
|
from roboco.services.gateway.evidence_repo import EvidenceRepo
|
|
|
|
_FLOOR = 0.6
|
|
_HIGH = 0.9
|
|
_LOW = 0.4
|
|
|
|
|
|
def _result(score: float, index_type: IndexType = IndexType.LEARNINGS) -> SearchResult:
|
|
return SearchResult(
|
|
content="a distilled lesson body",
|
|
source="roboco://learnings/lrn-1",
|
|
score=score,
|
|
index_type=index_type,
|
|
)
|
|
|
|
|
|
def test_shape_memory_query_is_role_specific() -> None:
|
|
dev = shape_memory_query("developer", "Add retry", "code")
|
|
pm = shape_memory_query("cell_pm", "Add retry", "code")
|
|
qa = shape_memory_query("qa", "Add retry", "code")
|
|
doc = shape_memory_query("documenter", "Add retry", "documentation")
|
|
assert dev != pm # role shaping actually differs
|
|
assert "Add retry" in dev and "implementation" in dev
|
|
assert "decomposition" in pm
|
|
assert "defect" in qa
|
|
assert "documentation pattern" in doc
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_similar_memory_applies_floor_and_shapes(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
optimal = MagicMock()
|
|
optimal.search = AsyncMock(
|
|
return_value=[_result(_HIGH, IndexType.PLAYBOOKS), _result(_LOW)]
|
|
)
|
|
monkeypatch.setattr(
|
|
"roboco.services.optimal.get_optimal_service",
|
|
AsyncMock(return_value=optimal),
|
|
)
|
|
out = await EvidenceRepo(MagicMock()).similar_memory(
|
|
query="q", top_k=3, min_score=_FLOOR
|
|
)
|
|
# the 0.4 result is below the floor, excluded; one met the floor → ok
|
|
assert out["status"] == "ok"
|
|
assert len(out["items"]) == 1
|
|
assert out["items"][0]["kind"] == "playbook"
|
|
assert out["items"][0]["score"] == _HIGH
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_similar_memory_labels_vault_notes(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
optimal = MagicMock()
|
|
optimal.search = AsyncMock(return_value=[_result(_HIGH, IndexType.VAULT_NOTES)])
|
|
monkeypatch.setattr(
|
|
"roboco.services.optimal.get_optimal_service",
|
|
AsyncMock(return_value=optimal),
|
|
)
|
|
out = await EvidenceRepo(MagicMock()).similar_memory(
|
|
query="q", top_k=3, min_score=_FLOOR
|
|
)
|
|
assert out["status"] == "ok"
|
|
assert out["items"][0]["kind"] == "vault_note"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_similar_memory_queries_vault_notes_index(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
"""The claim-time briefing must reach the CEO's own vault notes, not just
|
|
learnings/playbooks — the relevance floor is the only gate against bloat."""
|
|
optimal = MagicMock()
|
|
optimal.search = AsyncMock(return_value=[])
|
|
monkeypatch.setattr(
|
|
"roboco.services.optimal.get_optimal_service",
|
|
AsyncMock(return_value=optimal),
|
|
)
|
|
await EvidenceRepo(MagicMock()).similar_memory(query="q", top_k=3, min_score=_FLOOR)
|
|
_, kwargs = optimal.search.call_args
|
|
assert IndexType.VAULT_NOTES in kwargs["context"].index_types
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_similar_memory_caps_at_top_k(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
optimal = MagicMock()
|
|
optimal.search = AsyncMock(return_value=[_result(_HIGH) for _ in range(5)])
|
|
monkeypatch.setattr(
|
|
"roboco.services.optimal.get_optimal_service",
|
|
AsyncMock(return_value=optimal),
|
|
)
|
|
out = await EvidenceRepo(MagicMock()).similar_memory(
|
|
query="q", top_k=2, min_score=_FLOOR
|
|
)
|
|
assert out["status"] == "ok"
|
|
assert len(out["items"]) == 2 # noqa: PLR2004 - top_k cap
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_similar_memory_error_status_on_rag_failure(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
monkeypatch.setattr(
|
|
"roboco.services.optimal.get_optimal_service",
|
|
AsyncMock(side_effect=RuntimeError("rag down")),
|
|
)
|
|
out = await EvidenceRepo(MagicMock()).similar_memory(
|
|
query="q", top_k=3, min_score=_FLOOR
|
|
)
|
|
assert out == {"items": [], "status": "error"}
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_similar_memory_empty_status_when_search_yields_nothing(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
optimal = MagicMock()
|
|
optimal.search = AsyncMock(return_value=[])
|
|
monkeypatch.setattr(
|
|
"roboco.services.optimal.get_optimal_service",
|
|
AsyncMock(return_value=optimal),
|
|
)
|
|
out = await EvidenceRepo(MagicMock()).similar_memory(
|
|
query="q", top_k=3, min_score=_FLOOR
|
|
)
|
|
assert out == {"items": [], "status": "empty"}
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_similar_memory_below_floor_status_when_all_under_floor(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
optimal = MagicMock()
|
|
optimal.search = AsyncMock(return_value=[_result(_LOW), _result(_LOW)])
|
|
monkeypatch.setattr(
|
|
"roboco.services.optimal.get_optimal_service",
|
|
AsyncMock(return_value=optimal),
|
|
)
|
|
out = await EvidenceRepo(MagicMock()).similar_memory(
|
|
query="q", top_k=3, min_score=_FLOOR
|
|
)
|
|
assert out == {"items": [], "status": "below_floor"}
|