Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions apps/native/src-tauri/examples/specta_gen_ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ fn main() {
let types = collection
.register::<sqlite_types::Commit>()
.register::<sqlite_types::Evolution>()
.register::<sqlite_types::Prompt>()
.register::<sqlite_types::Change>()
.register::<sqlite_types::ChangeSummary>()
.register::<sqlite_types::ChangeSet>();
.register::<sqlite_types::ChangeSummary>();

let manifest_dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));
let output_path = manifest_dir.join("../src/ipc/sqlite.ts");
Expand Down Expand Up @@ -68,8 +66,6 @@ fn main() {
.register::<shared_types::HomebrewItemType>()
.register::<shared_types::HomebrewItem>()
.register::<shared_types::HomebrewState>()
.register::<shared_types::SummarizedChange>()
.register::<shared_types::SummarizedChangeSet>()
.register::<shared_types::ChangeWithSummary>()
.register::<shared_types::LaunchdItem>()
.register::<shared_types::SemanticChangeGroup>()
Expand Down
100 changes: 41 additions & 59 deletions apps/native/src-tauri/migrations/01-initial/up.sql
Original file line number Diff line number Diff line change
@@ -1,79 +1,61 @@
CREATE TABLE IF NOT EXISTS commits (
id INTEGER PRIMARY KEY,
hash TEXT NOT NULL UNIQUE,
tree_hash TEXT NOT NULL,
message TEXT,
-- Content-addressed summary schema.
--
-- Summaries describe *what a patch does*, keyed only by the content hash of the
-- change(s) they cover. Git remains the source of truth for diffs; these tables
-- are a local cache that can always be rebuilt by re-summarizing.

-- Per-change summary. Used for singletons / fallback (a change the model
-- described on its own, or a one-member group).
CREATE TABLE IF NOT EXISTS patch_summaries (
id INTEGER PRIMARY KEY AUTOINCREMENT,
change_hash TEXT NOT NULL UNIQUE,
title TEXT NOT NULL DEFAULT '',
description TEXT NOT NULL DEFAULT '',
status TEXT NOT NULL DEFAULT 'DONE' CHECK(status IN ('QUEUED', 'DONE', 'FAILED', 'CANCELLED')),
created_at INTEGER NOT NULL
);

CREATE TABLE IF NOT EXISTS evolutions (
-- First-class group summary. `group_key` content-addresses the exact set of
-- member change hashes (sha256 of the sorted hashes), so a group's identity is
-- its membership.
CREATE TABLE IF NOT EXISTS summary_groups (
id INTEGER PRIMARY KEY AUTOINCREMENT,
origin_branch TEXT NOT NULL,
merged INTEGER NOT NULL DEFAULT 0,
builds INTEGER NOT NULL DEFAULT 0
);

CREATE TABLE IF NOT EXISTS change_summaries (
id INTEGER PRIMARY KEY,
group_key TEXT NOT NULL UNIQUE,
title TEXT NOT NULL DEFAULT '',
description TEXT NOT NULL DEFAULT '',
status TEXT NOT NULL DEFAULT 'QUEUED' CHECK(status IN ('QUEUED', 'DONE', 'FAILED', 'CANCELLED')),
status TEXT NOT NULL DEFAULT 'DONE' CHECK(status IN ('QUEUED', 'DONE', 'FAILED', 'CANCELLED')),
created_at INTEGER NOT NULL
);

CREATE TABLE IF NOT EXISTS changes (
id INTEGER PRIMARY KEY,
hash TEXT NOT NULL UNIQUE,
filename TEXT NOT NULL,
diff TEXT NOT NULL,
line_count INTEGER NOT NULL,
created_at INTEGER NOT NULL,
own_summary_id INTEGER REFERENCES change_summaries(id)
-- Membership of a group. Content-addressed by `group_key`.
CREATE TABLE IF NOT EXISTS summary_group_members (
group_key TEXT NOT NULL REFERENCES summary_groups(group_key),
change_hash TEXT NOT NULL,
PRIMARY KEY (group_key, change_hash)
);

CREATE TABLE IF NOT EXISTS group_summaries (
change_id INTEGER NOT NULL REFERENCES changes(id),
change_summary_id INTEGER NOT NULL REFERENCES change_summaries(id)
-- Thin evolution record — just the origin branch an evolution started from.
CREATE TABLE IF NOT EXISTS evolutions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
origin_branch TEXT NOT NULL
);

CREATE TABLE IF NOT EXISTS change_sets (
-- A snapshot caches the generated commit message for an exact set of change
-- hashes. `snapshot_key` = sha256(sorted change hashes). The integer `id` is the
-- value historically plumbed as `changeset_id` throughout evolve/build state.
CREATE TABLE IF NOT EXISTS snapshots (
id INTEGER PRIMARY KEY AUTOINCREMENT,
commit_id INTEGER REFERENCES commits(id),
base_commit_id INTEGER NOT NULL REFERENCES commits(id),
commit_message TEXT,
snapshot_key TEXT NOT NULL UNIQUE,
generated_commit_message TEXT,
created_at INTEGER NOT NULL,
evolution_id INTEGER REFERENCES evolutions(id)
);

CREATE TABLE IF NOT EXISTS set_changes (
change_set_id INTEGER NOT NULL REFERENCES change_sets(id),
change_id INTEGER NOT NULL REFERENCES changes(id),
PRIMARY KEY (change_set_id, change_id)
);

CREATE TABLE IF NOT EXISTS queued_summaries (
id INTEGER PRIMARY KEY,
status TEXT NOT NULL DEFAULT 'QUEUED' CHECK(status IN ('QUEUED', 'DONE', 'FAILED', 'CANCELLED')),
attempted_count INTEGER NOT NULL DEFAULT 0,
prompt TEXT NOT NULL,
model_response TEXT,
group_summary_id INTEGER REFERENCES change_summaries(id),
hash_own_summary_id_pairs TEXT,
type TEXT NOT NULL CHECK(type IN ('NEW_SINGLE', 'NEW_GROUP', 'EVOLVED_GROUP'))
evolution_id INTEGER REFERENCES evolutions(id),
created_at INTEGER NOT NULL
);

CREATE TABLE IF NOT EXISTS prompts (
id INTEGER PRIMARY KEY,
text TEXT NOT NULL,
commit_id INTEGER REFERENCES commits(id) ON DELETE SET NULL,
created_at INTEGER NOT NULL
-- Records which commits were created by a restore operation and their origin.
CREATE TABLE IF NOT EXISTS restore_commits (
commit_hash TEXT PRIMARY KEY,
origin_hash TEXT NOT NULL
);

CREATE INDEX IF NOT EXISTS idx_commits_tree_hash ON commits(tree_hash);
CREATE INDEX IF NOT EXISTS idx_evolutions_origin_branch ON evolutions(origin_branch);
CREATE INDEX IF NOT EXISTS idx_prompts_commit ON prompts(commit_id);
CREATE INDEX IF NOT EXISTS idx_change_sets_commit ON change_sets(commit_id);
CREATE INDEX IF NOT EXISTS idx_change_sets_base ON change_sets(base_commit_id);
CREATE INDEX IF NOT EXISTS idx_set_changes_change ON set_changes(change_id);
CREATE INDEX IF NOT EXISTS idx_queued_summaries_status ON queued_summaries(status);
CREATE INDEX IF NOT EXISTS idx_summary_group_members_hash ON summary_group_members(change_hash);
Comment on lines +1 to +61

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

The entire 01-initial migration is rewritten in place, and migrations 02-restore-commits and 03-drop-queued-summaries are deleted — but no new migration (e.g. 04-new-schema) is added to carry existing databases forward. Diesel migrations are identified by directory name and tracked in __diesel_schema_migrations; any database that already applied 01-initial will not re-run it, so patch_summaries, summary_groups, summary_group_members, and snapshots are never created, causing every call to db::summaries and db::snapshots to fail with "no such table." The state management migration plan locks "Preserve compatibility during frontend migration" and requires migrations to be "tested against temporary database," with no provision for rewriting baseline migrations in place.


4 changes: 0 additions & 4 deletions apps/native/src-tauri/migrations/02-restore-commits/up.sql

This file was deleted.

This file was deleted.

9 changes: 5 additions & 4 deletions apps/native/src-tauri/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ Each file (apply, cli_tool, config, debug, editor, evolve, evolve_state, feedbac

- `schema.rs` — Runs migrations
- `pool.rs`, `tables.rs` — Diesel r2d2 connection pool and `table!` declarations
- `commits.rs`, `evolutions.rs` — CRUD for their respective tables
- `changesets.rs` — Shared insert helpers for changeset tables
- `store_whole_diff_changeset.rs`, `store_bare_changeset.rs` — Persist summarization pipeline results
- `keys.rs` — Content-addressing helpers (`snapshot_key` / `group_key` = sha256 of sorted change hashes)
- `summaries.rs` — Store + lookup for content-addressed `patch_summaries` (singles) and `summary_groups`
- `snapshots.rs` — Upsert/get for `snapshots` (caches the generated commit message; its `id` is the `changeset_id` plumbed through evolve/build)
- `evolutions.rs` — CRUD for the thin `evolutions` table (`id`, `origin_branch`)
- `restore_commits.rs` — Tracks restore-origin provenance

**Called by:** history, summarize, evolve/lifecycle, managed_edits, state/watcher
Expand Down Expand Up @@ -147,7 +148,7 @@ grouping scheme).

- `mod.rs` — Top-level `new_changeset` / `summarize_since` flow
- `find_existing.rs` — Queries DB for existing summarized changesets
- `group_existing.rs` — Builds SemanticChangeMap from found changesets
- `find_existing.rs` — Content-addressed lookup: greedily selects non-overlapping `summary_groups` (`members ⊆ live hashes`), falls back to `patch_summaries` for uncovered hashes, loads the `snapshot`, and produces a `SemanticChangeMap`
- `model_calls.rs` — AI API call for the whole-diff summary
- `build_prompt.rs` — Constructs the whole-diff prompt
- `token_budgets.rs` — Computes input/output token allocations
Expand Down
31 changes: 1 addition & 30 deletions apps/native/src-tauri/src/commands/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::helpers::capture_err;
use crate::state::{build_state, evolve_state};
use crate::storage::store;
use crate::{db, git, shared_types};
use tauri::{AppHandle, Manager, State};
use tauri::{AppHandle, State};

pub async fn fetch_file_diff_contents(
app: AppHandle,
Expand All @@ -22,7 +22,6 @@ pub async fn create_commit(
app: AppHandle,
message: String,
) -> Result<shared_types::CommitResult, String> {
let db_pool = app.state::<db::DbPool>();
let dir = store::ensure_git_repo_folder(&app).map_err(|e| capture_err("git_commit", e))?;
let commit_info = git::commit_all(&dir, &message).map_err(|e| capture_err("git_commit", e))?;

Expand All @@ -35,22 +34,6 @@ pub async fn create_commit(
log::warn!("[git_commit] Failed to tag commit: {}", e);
}

let now = crate::utils::unix_now();
match db::commits::upsert_commit(
&db_pool,
&commit_info.hash,
&commit_info.tree_hash,
Some(&message),
now,
) {
Ok(id) => log::info!(
"[git_commit] Saved commit to database (id={}, hash={})",
id,
&commit_info.hash[..8]
),
Err(e) => log::error!("[git_commit] Failed to save commit: {}", e),
}

if let Ok(current_build_state) = build_state::get(&app) {
let updated = build_state::BuildState {
head_commit_hash: Some(commit_info.hash.clone()),
Expand Down Expand Up @@ -97,7 +80,6 @@ pub async fn commit_single_file(
filename: String,
message: String,
) -> Result<shared_types::CommitResult, String> {
let db_pool = app.state::<db::DbPool>();
let dir = store::ensure_git_repo_folder(&app).map_err(|e| capture_err("git_commit_file", e))?;
let commit_info = git::commit_file(&dir, &filename, &message)
.map_err(|e| capture_err("git_commit_file", e))?;
Expand All @@ -111,17 +93,6 @@ pub async fn commit_single_file(
log::warn!("[git_commit_file] Failed to tag commit: {}", e);
}

let now = crate::utils::unix_now();
if let Err(e) = db::commits::upsert_commit(
&db_pool,
&commit_info.hash,
&commit_info.tree_hash,
Some(&message),
now,
) {
log::error!("[git_commit_file] Failed to save commit: {}", e);
}

if let Ok(current_build_state) = build_state::get(&app) {
let updated = build_state::BuildState {
head_commit_hash: Some(commit_info.hash.clone()),
Expand Down
Loading
Loading