Skip to main content

Module db

Module db 

Source

Structs§

PendingEmbed
One event awaiting an embedding: its id, task, and the text to embed.
RelatedTask
Score-weighted relationship between a fresh prompt’s artifacts and every prior task’s artifacts. Higher score = stronger continuation signal. Threshold tuning is the caller’s job; v0.6.0 auto-link keeps anything with score > 0.0.
ScoredHit
A retrieval hit: the event, its task, and the relevance score.
StaleTask
One row of the stale-task report: an open task whose last event crossed the inactivity threshold.
TaskMetadata
Read-only metadata bundle used by pack rendering (and TUI list teasers in v0.4.0+). Returns None for unknown tasks.
TaskRow
One row of the task list rendered by the TUI: enough to render the list view without round-tripping for each task. event_count joins events_index so we don’t need a second query per row.

Functions§

add_task_external
Append an external reference to tasks.external. The column is stored as a comma-separated list — small, append-mostly, no uniqueness constraint. Acceptable shapes (loose, not enforced): beads:claude-memory-rsw, github:#42, jira:PROJ-1234.
children_of
Direct children of a task (one level), newest activity first.
count_embeddings
Number of stored embeddings for a project (test/stats helper).
count_open_children
Number of direct children of task_id whose status is still open.
embed_pending
Embed up to limit events that still need a vector for the embedder’s model, and store them. Returns how many were embedded this call. Shared by embed-on-ingest (small batch after ingest_new_events) and embed --backfill (looped until it returns 0). Every pending text gets a vector — including short boilerplate — so nothing is re-scanned next pass; retrieval-side filtering (crate::embed::is_embeddable) decides what’s worth surfacing.
events_needing_embedding
Events that have no up-to-date embedding for model — either never embedded or embedded by a different model. Pulls the text straight from search_fts. limit bounds the batch; pass a large value to drain.
find_related_tasks
Find tasks whose events overlap the given artifacts on any dimension we have a signal for. Weights: shared linked_issue → +1.0 (strongest, ticket id is unique) shared commit_hash → +0.8 (commits are nearly unique) shared file path → +0.3 (files churn across tasks)
find_task_by_title
First task whose title exactly matches title, if any — used to find the reusable per-project consolidation task.
find_tasks_by_linked_issues
Find tasks (open or closed) whose events reference any of the given issue identifiers (FIN-868, JIRA-123, INC-7…). Looks at the per-event artifacts.linked_issues column populated on ingest. Returns (task_id, status) deduplicated, most-recent first. Used by the v0.5.0 Phase C auto-link flow to recognise that a fresh prompt is a continuation of a prior task.
high_signal_events
High-signal events (decisions, constraints, rejections) for consolidation — (event_id, text), newest first, capped at limit.
index_event
ingest_new_events
Read only the tail of the JSONL log since the last call. The cheap path for hot loops (every MCP tool invocation): scan to the marker, ingest the rest, update the marker.
invalidate_pack_cascade
Clear the pack cache for a task and its parent (roll-up depends on both).
list_all_projects
list_tasks_by_project
All tasks for a project, ordered with open ones first (by recency) then closed ones. The TUI list view binds directly to this — there is no other consumer, so the shape is tuned for that callsite.
open
parent_of
The stored parent of a task, if any.
rebuild_state
reclassify_task_artifacts
Re-run artifact extraction over every event of a task and write the result back to events_index.artifacts. Used to backfill events that were ingested before Phase B landed. Returns the number of events touched. Wipes the pack cache for the task so the next render reflects the freshly extracted artifacts.
semantic_search
Semantic search over a project’s embeddings. Scores every stored vector for model against query_vec by cosine, returns the top k by score. The caller embeds the query with the same embedder so the model ids match. Pure vector ranking for now; recency / tier / contradiction weighting layer on top in later phases.
set_task_goal
Set or replace tasks.goal for an existing task. Caller is expected to have validated the task exists (via task_exists); we don’t error on no-op rows so the upsert pattern is uniform.
set_task_outcome
Set or replace the closure metadata. Pass None for outcome_tag to leave it unset; pass Some("done"|"abandoned"|"superseded") for a structured tag. Free-text outcome is the primary field.
stale_tasks
Find open tasks with no event in the last days days. Sorted by idle time descending so the user sees the most ancient first.
task_artifacts
Aggregate artifacts (commit hashes, PR URLs, ticket IDs, files, branches) across every event of a task, deduplicated. Reads the per-event JSON payload that ingest_new_events populated. Skips events whose artifacts column is NULL or unparseable rather than failing the pack render.
task_event_texts
Texts of all events under a task (for de-duplicating consolidated facts).
task_exists
Returns whether a task with this id has been recorded in the derived state. Cheap O(1) lookup against the tasks primary key. Callers should run ingest_new_events first if they want to see the latest JSONL state.
task_metadata
task_status
Status string for an existing task (e.g. “open”, “closed”). Returns None when the task is unknown — caller decides whether that’s a hard error or a route-to-pending case.
top_level_tasks
Top-level tasks for a project (those with no parent), ordered like list_tasks_by_project — open first, then by recency. The roots of the list --tree view.
upsert_embedding
Upsert one vector. Keyed on event_id, so re-embedding (e.g. after a model change) replaces the prior row idempotently across rebuild_state replays.
upsert_task_from_event
would_create_cycle
True if setting new_parent as the parent of task_id would create a cycle (i.e. new_parent is task_id itself or a descendant of it). Walks ancestors of new_parent; a depth cap guards against pre-existing corrupt cycles.