@codemem/core 0.30.0-alpha.3 → 0.30.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/db.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../src/db.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAgBH,OAAO,KAAK,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAO/D,YAAY,EAAE,YAAY,IAAI,QAAQ,EAAE,CAAC;AAEzC,gEAAgE;AAChE,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAYvC,eAAO,MAAM,4BAA4B,sHAA8C,CAAC;AAiExF,gEAAgE;AAChE,eAAO,MAAM,eAAe,QAA4C,CAAC;AAEzE;;;GAGG;AACH,wBAAgB,aAAa,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAKvD;AA2CD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CASxD;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,MAAM,GAAE,MAAwB,GAAG,YAAY,CA2BtE;AAcD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAQzD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAWpD;AAED,iEAAiE;AACjE,wBAAgB,mBAAmB,IAAI,OAAO,CAG7C;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,YAAY,GAAG,MAAM,CAGzD;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CA2GxD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAsCxD;AAED,+CAA+C;AAC/C,wBAAgB,WAAW,CAAC,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAKpE;AAED,2CAA2C;AAC3C,wBAAgB,YAAY,CAAC,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAMrF;AAoBD;;;;;;GAMG;AACH,wBAAgB,iCAAiC,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAoXxE;AAED,2DAA2D;AAC3D,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAYjF;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CASvF;AAED,oEAAoE;AACpE,wBAAgB,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAG5C;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAW3D"}
1
+ {"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../src/db.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAgBH,OAAO,KAAK,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAO/D,YAAY,EAAE,YAAY,IAAI,QAAQ,EAAE,CAAC;AAEzC,gEAAgE;AAChE,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAYvC,eAAO,MAAM,4BAA4B,sHAA8C,CAAC;AAiExF,gEAAgE;AAChE,eAAO,MAAM,eAAe,QAA4C,CAAC;AAEzE;;;GAGG;AACH,wBAAgB,aAAa,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAKvD;AA2CD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CASxD;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,MAAM,GAAE,MAAwB,GAAG,YAAY,CA2BtE;AAcD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAQzD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAWpD;AAED,iEAAiE;AACjE,wBAAgB,mBAAmB,IAAI,OAAO,CAG7C;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,YAAY,GAAG,MAAM,CAGzD;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CA2GxD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAsCxD;AAED,+CAA+C;AAC/C,wBAAgB,WAAW,CAAC,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAKpE;AAED,2CAA2C;AAC3C,wBAAgB,YAAY,CAAC,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAMrF;AAoBD;;;;;;GAMG;AACH,wBAAgB,iCAAiC,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CA2XxE;AAED,2DAA2D;AAC3D,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAYjF;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CASvF;AAED,oEAAoE;AACpE,wBAAgB,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAG5C;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAW3D"}
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * This package owns the SQLite store, embedding worker interface,
5
5
  * and type definitions shared across the codemem TS backend.
6
6
  */
7
- export declare const VERSION = "0.30.0-alpha.3";
7
+ export declare const VERSION = "0.30.0-alpha.4";
8
8
  export * as Api from "./api-types.js";
9
9
  export { extractApplyPatchPaths, MUTATING_TOOL_NAMES } from "./apply-patch.js";
10
10
  export type { CreateBetterSqliteCoordinatorAppOptions } from "./better-sqlite-coordinator-runtime.js";
package/dist/index.js CHANGED
@@ -616,6 +616,7 @@ var V = class {
616
616
  P("idx_memory_items_active_created").on(e.active, e.created_at),
617
617
  P("idx_memory_items_session").on(e.session_id),
618
618
  P("idx_memory_items_scope_visibility_created").on(e.scope_id, e.visibility, e.created_at),
619
+ P("idx_memory_items_scope_backfill_pending").on(e.id).where(M`scope_id IS NULL OR scope_id = ''`),
619
620
  P("idx_memory_items_dedup_key_active_created").on(e.dedup_key, e.active, e.created_at),
620
621
  xe("idx_memory_items_same_session_dedup_unique").on(e.session_id, e.kind, e.visibility, e.workspace_id, e.dedup_key).where(M`active = 1 AND dedup_key IS NOT NULL`)
621
622
  ]), tt = I("memory_file_refs", {
@@ -1339,7 +1340,7 @@ function ln(e, t) {
1339
1340
  }
1340
1341
  //#endregion
1341
1342
  //#region src/test-schema.generated.ts
1342
- var un = "CREATE TABLE IF NOT EXISTS `sessions` (\n `id` integer PRIMARY KEY NOT NULL,\n `started_at` text NOT NULL,\n `ended_at` text,\n `cwd` text,\n `project` text,\n `git_remote` text,\n `git_branch` text,\n `user` text,\n `tool_version` text,\n `metadata_json` text,\n `import_key` text\n);\n\nCREATE TABLE IF NOT EXISTS `replication_scopes` (\n `scope_id` text PRIMARY KEY NOT NULL,\n `label` text NOT NULL,\n `kind` text DEFAULT 'user' NOT NULL,\n `authority_type` text DEFAULT 'local' NOT NULL,\n `coordinator_id` text,\n `group_id` text,\n `manifest_issuer_device_id` text,\n `membership_epoch` integer DEFAULT 0 NOT NULL,\n `manifest_hash` text,\n `status` text DEFAULT 'active' NOT NULL,\n `created_at` text NOT NULL,\n `updated_at` text NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS `idx_replication_scopes_status` ON `replication_scopes` (`status`);\nCREATE INDEX IF NOT EXISTS `idx_replication_scopes_authority_group` ON `replication_scopes` (`coordinator_id`,`group_id`);\nCREATE TABLE IF NOT EXISTS `project_scope_mappings` (\n `id` integer PRIMARY KEY NOT NULL,\n `workspace_identity` text,\n `project_pattern` text NOT NULL,\n `scope_id` text NOT NULL,\n `priority` integer DEFAULT 0 NOT NULL,\n `source` text DEFAULT 'user' NOT NULL,\n `created_at` text NOT NULL,\n `updated_at` text NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS `idx_project_scope_mappings_workspace_priority` ON `project_scope_mappings` (`workspace_identity`,`priority`);\nCREATE INDEX IF NOT EXISTS `idx_project_scope_mappings_pattern_priority` ON `project_scope_mappings` (`project_pattern`,`priority`);\nCREATE INDEX IF NOT EXISTS `idx_project_scope_mappings_scope` ON `project_scope_mappings` (`scope_id`);\nCREATE TABLE IF NOT EXISTS `scope_memberships` (\n `scope_id` text NOT NULL,\n `device_id` text NOT NULL,\n `role` text DEFAULT 'member' NOT NULL,\n `status` text DEFAULT 'active' NOT NULL,\n `membership_epoch` integer DEFAULT 0 NOT NULL,\n `coordinator_id` text,\n `group_id` text,\n `manifest_issuer_device_id` text,\n `manifest_hash` text,\n `signed_manifest_json` text,\n `updated_at` text NOT NULL,\n PRIMARY KEY(`scope_id`, `device_id`)\n);\n\nCREATE INDEX IF NOT EXISTS `idx_scope_memberships_device_status` ON `scope_memberships` (`device_id`,`status`);\nCREATE INDEX IF NOT EXISTS `idx_scope_memberships_scope_status` ON `scope_memberships` (`scope_id`,`status`);\nCREATE INDEX IF NOT EXISTS `idx_scope_memberships_authority_group` ON `scope_memberships` (`coordinator_id`,`group_id`);\nCREATE TABLE IF NOT EXISTS `artifacts` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer NOT NULL,\n `kind` text NOT NULL,\n `path` text,\n `content_text` text,\n `content_hash` text,\n `created_at` text NOT NULL,\n `metadata_json` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_artifacts_session_kind` ON `artifacts` (`session_id`,`kind`);\nCREATE TABLE IF NOT EXISTS `memory_items` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer NOT NULL,\n `kind` text NOT NULL,\n `title` text NOT NULL,\n `subtitle` text,\n `body_text` text NOT NULL,\n `confidence` real DEFAULT 0.5,\n `tags_text` text DEFAULT '',\n `active` integer DEFAULT 1,\n `created_at` text NOT NULL,\n `updated_at` text NOT NULL,\n `metadata_json` text,\n `actor_id` text,\n `actor_display_name` text,\n `visibility` text,\n `workspace_id` text,\n `workspace_kind` text,\n `origin_device_id` text,\n `origin_source` text,\n `trust_state` text,\n `facts` text,\n `narrative` text,\n `concepts` text,\n `files_read` text,\n `files_modified` text,\n `user_prompt_id` integer,\n `prompt_number` integer,\n `deleted_at` text,\n `rev` integer DEFAULT 0,\n `dedup_key` text,\n `import_key` text,\n `scope_id` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_memory_items_active_created` ON `memory_items` (`active`,`created_at`);\nCREATE INDEX IF NOT EXISTS `idx_memory_items_session` ON `memory_items` (`session_id`);\nCREATE INDEX IF NOT EXISTS `idx_memory_items_scope_visibility_created` ON `memory_items` (`scope_id`,`visibility`,`created_at`);\nCREATE INDEX IF NOT EXISTS `idx_memory_items_dedup_key_active_created` ON `memory_items` (`dedup_key`,`active`,`created_at`);\nCREATE UNIQUE INDEX IF NOT EXISTS `idx_memory_items_same_session_dedup_unique` ON `memory_items` (`session_id`,`kind`,`visibility`,`workspace_id`,`dedup_key`) WHERE active = 1 AND dedup_key IS NOT NULL;\nCREATE TABLE IF NOT EXISTS `memory_file_refs` (\n `memory_id` integer NOT NULL,\n `file_path` text NOT NULL,\n `relation` text NOT NULL,\n PRIMARY KEY(`memory_id`, `file_path`, `relation`),\n FOREIGN KEY (`memory_id`) REFERENCES `memory_items`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_memory_file_refs_path` ON `memory_file_refs` (`file_path`);\nCREATE TABLE IF NOT EXISTS `memory_concept_refs` (\n `memory_id` integer NOT NULL,\n `concept` text NOT NULL,\n PRIMARY KEY(`memory_id`, `concept`),\n FOREIGN KEY (`memory_id`) REFERENCES `memory_items`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_memory_concept_refs_concept` ON `memory_concept_refs` (`concept`);\nCREATE TABLE IF NOT EXISTS `usage_events` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer,\n `event` text NOT NULL,\n `tokens_read` integer DEFAULT 0,\n `tokens_written` integer DEFAULT 0,\n `tokens_saved` integer DEFAULT 0,\n `created_at` text NOT NULL,\n `metadata_json` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE set null\n);\n\nCREATE INDEX IF NOT EXISTS `idx_usage_events_event_created` ON `usage_events` (`event`,`created_at`);\nCREATE INDEX IF NOT EXISTS `idx_usage_events_session` ON `usage_events` (`session_id`);\nCREATE TABLE IF NOT EXISTS `raw_events` (\n `id` integer PRIMARY KEY NOT NULL,\n `source` text DEFAULT 'opencode' NOT NULL,\n `stream_id` text DEFAULT '' NOT NULL,\n `opencode_session_id` text NOT NULL,\n `event_id` text,\n `event_seq` integer NOT NULL,\n `event_type` text NOT NULL,\n `ts_wall_ms` integer,\n `ts_mono_ms` real,\n `payload_json` text NOT NULL,\n `created_at` text NOT NULL\n);\n\nCREATE UNIQUE INDEX IF NOT EXISTS `idx_raw_events_source_stream_seq` ON `raw_events` (`source`,`stream_id`,`event_seq`);\nCREATE UNIQUE INDEX IF NOT EXISTS `idx_raw_events_source_stream_event_id` ON `raw_events` (`source`,`stream_id`,`event_id`);\nCREATE INDEX IF NOT EXISTS `idx_raw_events_session_seq` ON `raw_events` (`opencode_session_id`,`event_seq`);\nCREATE INDEX IF NOT EXISTS `idx_raw_events_created` ON `raw_events` (`created_at`);\nCREATE TABLE IF NOT EXISTS `raw_event_sessions` (\n `source` text DEFAULT 'opencode' NOT NULL,\n `stream_id` text DEFAULT '' NOT NULL,\n `opencode_session_id` text NOT NULL,\n `cwd` text,\n `project` text,\n `started_at` text,\n `last_seen_ts_wall_ms` integer,\n `last_received_event_seq` integer DEFAULT -1 NOT NULL,\n `last_flushed_event_seq` integer DEFAULT -1 NOT NULL,\n `updated_at` text NOT NULL,\n PRIMARY KEY(`source`, `stream_id`)\n);\n\nCREATE TABLE IF NOT EXISTS `opencode_sessions` (\n `source` text DEFAULT 'opencode' NOT NULL,\n `stream_id` text DEFAULT '' NOT NULL,\n `opencode_session_id` text NOT NULL,\n `session_id` integer,\n `created_at` text NOT NULL,\n PRIMARY KEY(`source`, `stream_id`),\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_opencode_sessions_session` ON `opencode_sessions` (`session_id`);\nCREATE TABLE IF NOT EXISTS `raw_event_flush_batches` (\n `id` integer PRIMARY KEY NOT NULL,\n `source` text DEFAULT 'opencode' NOT NULL,\n `stream_id` text DEFAULT '' NOT NULL,\n `opencode_session_id` text NOT NULL,\n `start_event_seq` integer NOT NULL,\n `end_event_seq` integer NOT NULL,\n `extractor_version` text NOT NULL,\n `status` text NOT NULL,\n `error_message` text,\n `error_type` text,\n `observer_provider` text,\n `observer_model` text,\n `observer_runtime` text,\n `observer_auth_source` text,\n `observer_auth_type` text,\n `observer_error_code` text,\n `observer_error_message` text,\n `attempt_count` integer DEFAULT 0 NOT NULL,\n `created_at` text NOT NULL,\n `updated_at` text NOT NULL\n);\n\nCREATE UNIQUE INDEX IF NOT EXISTS `idx_flush_batches_source_stream_seq_ver` ON `raw_event_flush_batches` (`source`,`stream_id`,`start_event_seq`,`end_event_seq`,`extractor_version`);\nCREATE INDEX IF NOT EXISTS `idx_flush_batches_session_created` ON `raw_event_flush_batches` (`opencode_session_id`,`created_at`);\nCREATE INDEX IF NOT EXISTS `idx_flush_batches_status_updated` ON `raw_event_flush_batches` (`status`,`updated_at`);\nCREATE TABLE IF NOT EXISTS `user_prompts` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer,\n `project` text,\n `prompt_text` text NOT NULL,\n `prompt_number` integer,\n `created_at` text NOT NULL,\n `created_at_epoch` integer NOT NULL,\n `metadata_json` text,\n `import_key` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_user_prompts_session` ON `user_prompts` (`session_id`);\nCREATE INDEX IF NOT EXISTS `idx_user_prompts_project` ON `user_prompts` (`project`);\nCREATE INDEX IF NOT EXISTS `idx_user_prompts_epoch` ON `user_prompts` (`created_at_epoch`);\nCREATE TABLE IF NOT EXISTS `session_summaries` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer,\n `project` text,\n `request` text,\n `investigated` text,\n `learned` text,\n `completed` text,\n `next_steps` text,\n `notes` text,\n `files_read` text,\n `files_edited` text,\n `prompt_number` integer,\n `created_at` text NOT NULL,\n `created_at_epoch` integer NOT NULL,\n `metadata_json` text,\n `import_key` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_session_summaries_session` ON `session_summaries` (`session_id`);\nCREATE INDEX IF NOT EXISTS `idx_session_summaries_project` ON `session_summaries` (`project`);\nCREATE INDEX IF NOT EXISTS `idx_session_summaries_epoch` ON `session_summaries` (`created_at_epoch`);\nCREATE TABLE IF NOT EXISTS `replication_ops` (\n `op_id` text PRIMARY KEY NOT NULL,\n `entity_type` text NOT NULL,\n `entity_id` text NOT NULL,\n `op_type` text NOT NULL,\n `payload_json` text,\n `clock_rev` integer NOT NULL,\n `clock_updated_at` text NOT NULL,\n `clock_device_id` text NOT NULL,\n `device_id` text NOT NULL,\n `created_at` text NOT NULL,\n `scope_id` text\n);\n\nCREATE INDEX IF NOT EXISTS `idx_replication_ops_created` ON `replication_ops` (`created_at`,`op_id`);\nCREATE INDEX IF NOT EXISTS `idx_replication_ops_entity` ON `replication_ops` (`entity_type`,`entity_id`);\nCREATE INDEX IF NOT EXISTS `idx_replication_ops_scope_created` ON `replication_ops` (`scope_id`,`created_at`,`op_id`);\nCREATE TABLE IF NOT EXISTS `replication_cursors` (\n `peer_device_id` text PRIMARY KEY NOT NULL,\n `last_applied_cursor` text,\n `last_acked_cursor` text,\n `updated_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `replication_cursors_v2` (\n `peer_device_id` text NOT NULL,\n `scope_id` text NOT NULL,\n `last_applied_cursor` text,\n `last_acked_cursor` text,\n `updated_at` text NOT NULL,\n PRIMARY KEY(`peer_device_id`, `scope_id`)\n);\n\nCREATE INDEX IF NOT EXISTS `idx_replication_cursors_v2_scope` ON `replication_cursors_v2` (`scope_id`);\nCREATE TABLE IF NOT EXISTS `sync_peers` (\n `peer_device_id` text PRIMARY KEY NOT NULL,\n `name` text,\n `pinned_fingerprint` text,\n `public_key` text,\n `addresses_json` text,\n `claimed_local_actor` integer DEFAULT 0 NOT NULL,\n `actor_id` text,\n `projects_include_json` text,\n `projects_exclude_json` text,\n `created_at` text NOT NULL,\n `last_seen_at` text,\n `last_sync_at` text,\n `last_error` text,\n `discovered_via_coordinator_id` text,\n `discovered_via_group_id` text\n);\n\nCREATE TABLE IF NOT EXISTS `sync_nonces` (\n `nonce` text PRIMARY KEY NOT NULL,\n `device_id` text NOT NULL,\n `created_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `sync_device` (\n `device_id` text PRIMARY KEY NOT NULL,\n `public_key` text NOT NULL,\n `fingerprint` text NOT NULL,\n `created_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `sync_attempts` (\n `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,\n `peer_device_id` text NOT NULL,\n `started_at` text NOT NULL,\n `finished_at` text,\n `ok` integer NOT NULL,\n `ops_in` integer NOT NULL,\n `ops_out` integer NOT NULL,\n `error` text,\n `local_sync_capability` text,\n `peer_sync_capability` text,\n `negotiated_sync_capability` text\n);\n\nCREATE INDEX IF NOT EXISTS `idx_sync_attempts_peer_started` ON `sync_attempts` (`peer_device_id`,`started_at`);\nCREATE TABLE IF NOT EXISTS `sync_scope_rejections` (\n `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,\n `peer_device_id` text,\n `op_id` text NOT NULL,\n `entity_type` text NOT NULL,\n `entity_id` text NOT NULL,\n `scope_id` text,\n `reason` text NOT NULL,\n `created_at` text NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS `idx_sync_scope_rejections_peer_created` ON `sync_scope_rejections` (`peer_device_id`,`created_at`);\nCREATE INDEX IF NOT EXISTS `idx_sync_scope_rejections_scope_created` ON `sync_scope_rejections` (`scope_id`,`created_at`);\nCREATE TABLE IF NOT EXISTS `sync_daemon_state` (\n `id` integer PRIMARY KEY NOT NULL,\n `last_error` text,\n `last_traceback` text,\n `last_error_at` text,\n `last_ok_at` text,\n `phase` text\n);\n\nCREATE TABLE IF NOT EXISTS `sync_reset_state` (\n `id` integer PRIMARY KEY NOT NULL,\n `generation` integer NOT NULL,\n `snapshot_id` text NOT NULL,\n `baseline_cursor` text,\n `retained_floor_cursor` text,\n `updated_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `sync_reset_state_v2` (\n `scope_id` text PRIMARY KEY NOT NULL,\n `generation` integer NOT NULL,\n `snapshot_id` text NOT NULL,\n `baseline_cursor` text,\n `retained_floor_cursor` text,\n `updated_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `sync_retention_state_v2` (\n `scope_id` text PRIMARY KEY NOT NULL,\n `last_run_at` text,\n `last_duration_ms` integer,\n `last_deleted_ops` integer DEFAULT 0 NOT NULL,\n `last_estimated_bytes_before` integer,\n `last_estimated_bytes_after` integer,\n `retained_floor_cursor` text,\n `last_error` text,\n `last_error_at` text\n);\n\nCREATE TABLE IF NOT EXISTS `raw_event_ingest_samples` (\n `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,\n `created_at` text NOT NULL,\n `inserted_events` integer DEFAULT 0 NOT NULL,\n `skipped_invalid` integer DEFAULT 0 NOT NULL,\n `skipped_duplicate` integer DEFAULT 0 NOT NULL,\n `skipped_conflict` integer DEFAULT 0 NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `raw_event_ingest_stats` (\n `id` integer PRIMARY KEY NOT NULL,\n `inserted_events` integer DEFAULT 0 NOT NULL,\n `skipped_events` integer DEFAULT 0 NOT NULL,\n `skipped_invalid` integer DEFAULT 0 NOT NULL,\n `skipped_duplicate` integer DEFAULT 0 NOT NULL,\n `skipped_conflict` integer DEFAULT 0 NOT NULL,\n `updated_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `coordinator_group_preferences` (\n `coordinator_id` text NOT NULL,\n `group_id` text NOT NULL,\n `projects_include_json` text,\n `projects_exclude_json` text,\n `auto_seed_scope` integer DEFAULT 1 NOT NULL,\n `updated_at` text NOT NULL,\n PRIMARY KEY(`coordinator_id`, `group_id`)\n);\n\nCREATE TABLE IF NOT EXISTS `actors` (\n `actor_id` text PRIMARY KEY NOT NULL,\n `display_name` text NOT NULL,\n `is_local` integer DEFAULT 0 NOT NULL,\n `status` text DEFAULT 'active' NOT NULL,\n `merged_into_actor_id` text,\n `created_at` text NOT NULL,\n `updated_at` text NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS `idx_actors_is_local` ON `actors` (`is_local`);\nCREATE INDEX IF NOT EXISTS `idx_actors_status` ON `actors` (`status`);", dn = "\nCREATE INDEX IF NOT EXISTS idx_sync_peers_actor_id ON sync_peers(actor_id);\n\nCREATE TABLE IF NOT EXISTS sync_retention_state (\n id INTEGER PRIMARY KEY,\n last_run_at TEXT,\n last_duration_ms INTEGER,\n last_deleted_ops INTEGER NOT NULL DEFAULT 0,\n last_estimated_bytes_before INTEGER,\n last_estimated_bytes_after INTEGER,\n retained_floor_cursor TEXT,\n last_error TEXT,\n last_error_at TEXT\n);\n\nCREATE TABLE IF NOT EXISTS maintenance_jobs (\n kind TEXT PRIMARY KEY,\n title TEXT NOT NULL,\n status TEXT NOT NULL,\n message TEXT,\n progress_current INTEGER NOT NULL DEFAULT 0,\n progress_total INTEGER,\n progress_unit TEXT NOT NULL DEFAULT 'items',\n metadata_json TEXT,\n started_at TEXT,\n updated_at TEXT NOT NULL,\n finished_at TEXT,\n error TEXT\n);\n\nCREATE INDEX IF NOT EXISTS idx_maintenance_jobs_status_updated\n ON maintenance_jobs(status, updated_at);\n\nCREATE TABLE IF NOT EXISTS sync_scope_rejections (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n peer_device_id TEXT,\n op_id TEXT NOT NULL,\n entity_type TEXT NOT NULL,\n entity_id TEXT NOT NULL,\n scope_id TEXT,\n reason TEXT NOT NULL,\n created_at TEXT NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS idx_sync_scope_rejections_peer_created\n ON sync_scope_rejections(peer_device_id, created_at);\n\nCREATE INDEX IF NOT EXISTS idx_sync_scope_rejections_scope_created\n ON sync_scope_rejections(scope_id, created_at);\n\n-- import_key is the primary lookup key from replication_ops.entity_id back to\n-- the source memory. The scope-backfill runner's selectReplicationOpScopeCandidates\n-- query joins on it for every unstamped op; without this index a Pi 4 with\n-- ~17k memories and ~35k ops scans the full memory_items table on every batch\n-- tick. The partial WHERE clause keeps the index small (most rows have\n-- import_key set; the few that don't aren't searchable anyway).\nCREATE INDEX IF NOT EXISTS idx_memory_items_import_key\n ON memory_items(import_key)\n WHERE import_key IS NOT NULL;\n\nCREATE VIRTUAL TABLE IF NOT EXISTS memory_fts USING fts5(\n title, body_text, tags_text,\n content='memory_items',\n content_rowid='id'\n);\n\nCREATE TRIGGER IF NOT EXISTS memory_items_ai AFTER INSERT ON memory_items BEGIN\n INSERT INTO memory_fts(rowid, title, body_text, tags_text)\n VALUES (new.id, new.title, new.body_text, new.tags_text);\nEND;\n\nDROP TRIGGER IF EXISTS memory_items_au;\nCREATE TRIGGER memory_items_au AFTER UPDATE ON memory_items BEGIN\n INSERT INTO memory_fts(memory_fts, rowid, title, body_text, tags_text)\n VALUES('delete', old.id, old.title, old.body_text, old.tags_text);\n INSERT INTO memory_fts(rowid, title, body_text, tags_text)\n VALUES (new.id, new.title, new.body_text, new.tags_text);\nEND;\n\nDROP TRIGGER IF EXISTS memory_items_ad;\nCREATE TRIGGER memory_items_ad AFTER DELETE ON memory_items BEGIN\n INSERT INTO memory_fts(memory_fts, rowid, title, body_text, tags_text)\n VALUES('delete', old.id, old.title, old.body_text, old.tags_text);\nEND;\n\nCREATE TABLE IF NOT EXISTS memory_file_refs (\n memory_id INTEGER NOT NULL,\n file_path TEXT NOT NULL,\n relation TEXT NOT NULL CHECK(relation IN ('read', 'modified')),\n PRIMARY KEY (memory_id, file_path, relation),\n FOREIGN KEY (memory_id) REFERENCES memory_items(id) ON DELETE CASCADE\n);\n\nCREATE INDEX IF NOT EXISTS idx_memory_file_refs_path\n ON memory_file_refs(file_path);\n\nCREATE TABLE IF NOT EXISTS memory_concept_refs (\n memory_id INTEGER NOT NULL,\n concept TEXT NOT NULL,\n PRIMARY KEY (memory_id, concept),\n FOREIGN KEY (memory_id) REFERENCES memory_items(id) ON DELETE CASCADE\n);\n\nCREATE INDEX IF NOT EXISTS idx_memory_concept_refs_concept\n ON memory_concept_refs(concept);\n\nCREATE TABLE IF NOT EXISTS coordinator_group_preferences (\n coordinator_id TEXT NOT NULL,\n group_id TEXT NOT NULL,\n projects_include_json TEXT,\n projects_exclude_json TEXT,\n auto_seed_scope INTEGER NOT NULL DEFAULT 1,\n updated_at TEXT NOT NULL,\n PRIMARY KEY (coordinator_id, group_id)\n);\n\nCREATE TABLE IF NOT EXISTS scope_membership_cache_state (\n coordinator_id TEXT NOT NULL,\n group_id TEXT NOT NULL,\n last_refresh_at TEXT NOT NULL,\n last_success_at TEXT,\n last_error TEXT,\n updated_at TEXT NOT NULL,\n PRIMARY KEY (coordinator_id, group_id)\n);\n", fn = "\nCREATE VIRTUAL TABLE IF NOT EXISTS memory_vectors USING vec0(\n embedding float[384],\n memory_id INTEGER,\n chunk_index INTEGER,\n content_hash TEXT,\n model TEXT\n);\n";
1343
+ var un = "CREATE TABLE IF NOT EXISTS `sessions` (\n `id` integer PRIMARY KEY NOT NULL,\n `started_at` text NOT NULL,\n `ended_at` text,\n `cwd` text,\n `project` text,\n `git_remote` text,\n `git_branch` text,\n `user` text,\n `tool_version` text,\n `metadata_json` text,\n `import_key` text\n);\n\nCREATE TABLE IF NOT EXISTS `replication_scopes` (\n `scope_id` text PRIMARY KEY NOT NULL,\n `label` text NOT NULL,\n `kind` text DEFAULT 'user' NOT NULL,\n `authority_type` text DEFAULT 'local' NOT NULL,\n `coordinator_id` text,\n `group_id` text,\n `manifest_issuer_device_id` text,\n `membership_epoch` integer DEFAULT 0 NOT NULL,\n `manifest_hash` text,\n `status` text DEFAULT 'active' NOT NULL,\n `created_at` text NOT NULL,\n `updated_at` text NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS `idx_replication_scopes_status` ON `replication_scopes` (`status`);\nCREATE INDEX IF NOT EXISTS `idx_replication_scopes_authority_group` ON `replication_scopes` (`coordinator_id`,`group_id`);\nCREATE TABLE IF NOT EXISTS `project_scope_mappings` (\n `id` integer PRIMARY KEY NOT NULL,\n `workspace_identity` text,\n `project_pattern` text NOT NULL,\n `scope_id` text NOT NULL,\n `priority` integer DEFAULT 0 NOT NULL,\n `source` text DEFAULT 'user' NOT NULL,\n `created_at` text NOT NULL,\n `updated_at` text NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS `idx_project_scope_mappings_workspace_priority` ON `project_scope_mappings` (`workspace_identity`,`priority`);\nCREATE INDEX IF NOT EXISTS `idx_project_scope_mappings_pattern_priority` ON `project_scope_mappings` (`project_pattern`,`priority`);\nCREATE INDEX IF NOT EXISTS `idx_project_scope_mappings_scope` ON `project_scope_mappings` (`scope_id`);\nCREATE TABLE IF NOT EXISTS `scope_memberships` (\n `scope_id` text NOT NULL,\n `device_id` text NOT NULL,\n `role` text DEFAULT 'member' NOT NULL,\n `status` text DEFAULT 'active' NOT NULL,\n `membership_epoch` integer DEFAULT 0 NOT NULL,\n `coordinator_id` text,\n `group_id` text,\n `manifest_issuer_device_id` text,\n `manifest_hash` text,\n `signed_manifest_json` text,\n `updated_at` text NOT NULL,\n PRIMARY KEY(`scope_id`, `device_id`)\n);\n\nCREATE INDEX IF NOT EXISTS `idx_scope_memberships_device_status` ON `scope_memberships` (`device_id`,`status`);\nCREATE INDEX IF NOT EXISTS `idx_scope_memberships_scope_status` ON `scope_memberships` (`scope_id`,`status`);\nCREATE INDEX IF NOT EXISTS `idx_scope_memberships_authority_group` ON `scope_memberships` (`coordinator_id`,`group_id`);\nCREATE TABLE IF NOT EXISTS `artifacts` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer NOT NULL,\n `kind` text NOT NULL,\n `path` text,\n `content_text` text,\n `content_hash` text,\n `created_at` text NOT NULL,\n `metadata_json` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_artifacts_session_kind` ON `artifacts` (`session_id`,`kind`);\nCREATE TABLE IF NOT EXISTS `memory_items` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer NOT NULL,\n `kind` text NOT NULL,\n `title` text NOT NULL,\n `subtitle` text,\n `body_text` text NOT NULL,\n `confidence` real DEFAULT 0.5,\n `tags_text` text DEFAULT '',\n `active` integer DEFAULT 1,\n `created_at` text NOT NULL,\n `updated_at` text NOT NULL,\n `metadata_json` text,\n `actor_id` text,\n `actor_display_name` text,\n `visibility` text,\n `workspace_id` text,\n `workspace_kind` text,\n `origin_device_id` text,\n `origin_source` text,\n `trust_state` text,\n `facts` text,\n `narrative` text,\n `concepts` text,\n `files_read` text,\n `files_modified` text,\n `user_prompt_id` integer,\n `prompt_number` integer,\n `deleted_at` text,\n `rev` integer DEFAULT 0,\n `dedup_key` text,\n `import_key` text,\n `scope_id` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_memory_items_active_created` ON `memory_items` (`active`,`created_at`);\nCREATE INDEX IF NOT EXISTS `idx_memory_items_session` ON `memory_items` (`session_id`);\nCREATE INDEX IF NOT EXISTS `idx_memory_items_scope_visibility_created` ON `memory_items` (`scope_id`,`visibility`,`created_at`);\nCREATE INDEX IF NOT EXISTS `idx_memory_items_scope_backfill_pending` ON `memory_items` (`id`) WHERE scope_id IS NULL OR scope_id = '';\nCREATE INDEX IF NOT EXISTS `idx_memory_items_dedup_key_active_created` ON `memory_items` (`dedup_key`,`active`,`created_at`);\nCREATE UNIQUE INDEX IF NOT EXISTS `idx_memory_items_same_session_dedup_unique` ON `memory_items` (`session_id`,`kind`,`visibility`,`workspace_id`,`dedup_key`) WHERE active = 1 AND dedup_key IS NOT NULL;\nCREATE TABLE IF NOT EXISTS `memory_file_refs` (\n `memory_id` integer NOT NULL,\n `file_path` text NOT NULL,\n `relation` text NOT NULL,\n PRIMARY KEY(`memory_id`, `file_path`, `relation`),\n FOREIGN KEY (`memory_id`) REFERENCES `memory_items`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_memory_file_refs_path` ON `memory_file_refs` (`file_path`);\nCREATE TABLE IF NOT EXISTS `memory_concept_refs` (\n `memory_id` integer NOT NULL,\n `concept` text NOT NULL,\n PRIMARY KEY(`memory_id`, `concept`),\n FOREIGN KEY (`memory_id`) REFERENCES `memory_items`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_memory_concept_refs_concept` ON `memory_concept_refs` (`concept`);\nCREATE TABLE IF NOT EXISTS `usage_events` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer,\n `event` text NOT NULL,\n `tokens_read` integer DEFAULT 0,\n `tokens_written` integer DEFAULT 0,\n `tokens_saved` integer DEFAULT 0,\n `created_at` text NOT NULL,\n `metadata_json` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE set null\n);\n\nCREATE INDEX IF NOT EXISTS `idx_usage_events_event_created` ON `usage_events` (`event`,`created_at`);\nCREATE INDEX IF NOT EXISTS `idx_usage_events_session` ON `usage_events` (`session_id`);\nCREATE TABLE IF NOT EXISTS `raw_events` (\n `id` integer PRIMARY KEY NOT NULL,\n `source` text DEFAULT 'opencode' NOT NULL,\n `stream_id` text DEFAULT '' NOT NULL,\n `opencode_session_id` text NOT NULL,\n `event_id` text,\n `event_seq` integer NOT NULL,\n `event_type` text NOT NULL,\n `ts_wall_ms` integer,\n `ts_mono_ms` real,\n `payload_json` text NOT NULL,\n `created_at` text NOT NULL\n);\n\nCREATE UNIQUE INDEX IF NOT EXISTS `idx_raw_events_source_stream_seq` ON `raw_events` (`source`,`stream_id`,`event_seq`);\nCREATE UNIQUE INDEX IF NOT EXISTS `idx_raw_events_source_stream_event_id` ON `raw_events` (`source`,`stream_id`,`event_id`);\nCREATE INDEX IF NOT EXISTS `idx_raw_events_session_seq` ON `raw_events` (`opencode_session_id`,`event_seq`);\nCREATE INDEX IF NOT EXISTS `idx_raw_events_created` ON `raw_events` (`created_at`);\nCREATE TABLE IF NOT EXISTS `raw_event_sessions` (\n `source` text DEFAULT 'opencode' NOT NULL,\n `stream_id` text DEFAULT '' NOT NULL,\n `opencode_session_id` text NOT NULL,\n `cwd` text,\n `project` text,\n `started_at` text,\n `last_seen_ts_wall_ms` integer,\n `last_received_event_seq` integer DEFAULT -1 NOT NULL,\n `last_flushed_event_seq` integer DEFAULT -1 NOT NULL,\n `updated_at` text NOT NULL,\n PRIMARY KEY(`source`, `stream_id`)\n);\n\nCREATE TABLE IF NOT EXISTS `opencode_sessions` (\n `source` text DEFAULT 'opencode' NOT NULL,\n `stream_id` text DEFAULT '' NOT NULL,\n `opencode_session_id` text NOT NULL,\n `session_id` integer,\n `created_at` text NOT NULL,\n PRIMARY KEY(`source`, `stream_id`),\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_opencode_sessions_session` ON `opencode_sessions` (`session_id`);\nCREATE TABLE IF NOT EXISTS `raw_event_flush_batches` (\n `id` integer PRIMARY KEY NOT NULL,\n `source` text DEFAULT 'opencode' NOT NULL,\n `stream_id` text DEFAULT '' NOT NULL,\n `opencode_session_id` text NOT NULL,\n `start_event_seq` integer NOT NULL,\n `end_event_seq` integer NOT NULL,\n `extractor_version` text NOT NULL,\n `status` text NOT NULL,\n `error_message` text,\n `error_type` text,\n `observer_provider` text,\n `observer_model` text,\n `observer_runtime` text,\n `observer_auth_source` text,\n `observer_auth_type` text,\n `observer_error_code` text,\n `observer_error_message` text,\n `attempt_count` integer DEFAULT 0 NOT NULL,\n `created_at` text NOT NULL,\n `updated_at` text NOT NULL\n);\n\nCREATE UNIQUE INDEX IF NOT EXISTS `idx_flush_batches_source_stream_seq_ver` ON `raw_event_flush_batches` (`source`,`stream_id`,`start_event_seq`,`end_event_seq`,`extractor_version`);\nCREATE INDEX IF NOT EXISTS `idx_flush_batches_session_created` ON `raw_event_flush_batches` (`opencode_session_id`,`created_at`);\nCREATE INDEX IF NOT EXISTS `idx_flush_batches_status_updated` ON `raw_event_flush_batches` (`status`,`updated_at`);\nCREATE TABLE IF NOT EXISTS `user_prompts` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer,\n `project` text,\n `prompt_text` text NOT NULL,\n `prompt_number` integer,\n `created_at` text NOT NULL,\n `created_at_epoch` integer NOT NULL,\n `metadata_json` text,\n `import_key` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_user_prompts_session` ON `user_prompts` (`session_id`);\nCREATE INDEX IF NOT EXISTS `idx_user_prompts_project` ON `user_prompts` (`project`);\nCREATE INDEX IF NOT EXISTS `idx_user_prompts_epoch` ON `user_prompts` (`created_at_epoch`);\nCREATE TABLE IF NOT EXISTS `session_summaries` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer,\n `project` text,\n `request` text,\n `investigated` text,\n `learned` text,\n `completed` text,\n `next_steps` text,\n `notes` text,\n `files_read` text,\n `files_edited` text,\n `prompt_number` integer,\n `created_at` text NOT NULL,\n `created_at_epoch` integer NOT NULL,\n `metadata_json` text,\n `import_key` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_session_summaries_session` ON `session_summaries` (`session_id`);\nCREATE INDEX IF NOT EXISTS `idx_session_summaries_project` ON `session_summaries` (`project`);\nCREATE INDEX IF NOT EXISTS `idx_session_summaries_epoch` ON `session_summaries` (`created_at_epoch`);\nCREATE TABLE IF NOT EXISTS `replication_ops` (\n `op_id` text PRIMARY KEY NOT NULL,\n `entity_type` text NOT NULL,\n `entity_id` text NOT NULL,\n `op_type` text NOT NULL,\n `payload_json` text,\n `clock_rev` integer NOT NULL,\n `clock_updated_at` text NOT NULL,\n `clock_device_id` text NOT NULL,\n `device_id` text NOT NULL,\n `created_at` text NOT NULL,\n `scope_id` text\n);\n\nCREATE INDEX IF NOT EXISTS `idx_replication_ops_created` ON `replication_ops` (`created_at`,`op_id`);\nCREATE INDEX IF NOT EXISTS `idx_replication_ops_entity` ON `replication_ops` (`entity_type`,`entity_id`);\nCREATE INDEX IF NOT EXISTS `idx_replication_ops_scope_created` ON `replication_ops` (`scope_id`,`created_at`,`op_id`);\nCREATE TABLE IF NOT EXISTS `replication_cursors` (\n `peer_device_id` text PRIMARY KEY NOT NULL,\n `last_applied_cursor` text,\n `last_acked_cursor` text,\n `updated_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `replication_cursors_v2` (\n `peer_device_id` text NOT NULL,\n `scope_id` text NOT NULL,\n `last_applied_cursor` text,\n `last_acked_cursor` text,\n `updated_at` text NOT NULL,\n PRIMARY KEY(`peer_device_id`, `scope_id`)\n);\n\nCREATE INDEX IF NOT EXISTS `idx_replication_cursors_v2_scope` ON `replication_cursors_v2` (`scope_id`);\nCREATE TABLE IF NOT EXISTS `sync_peers` (\n `peer_device_id` text PRIMARY KEY NOT NULL,\n `name` text,\n `pinned_fingerprint` text,\n `public_key` text,\n `addresses_json` text,\n `claimed_local_actor` integer DEFAULT 0 NOT NULL,\n `actor_id` text,\n `projects_include_json` text,\n `projects_exclude_json` text,\n `created_at` text NOT NULL,\n `last_seen_at` text,\n `last_sync_at` text,\n `last_error` text,\n `discovered_via_coordinator_id` text,\n `discovered_via_group_id` text\n);\n\nCREATE TABLE IF NOT EXISTS `sync_nonces` (\n `nonce` text PRIMARY KEY NOT NULL,\n `device_id` text NOT NULL,\n `created_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `sync_device` (\n `device_id` text PRIMARY KEY NOT NULL,\n `public_key` text NOT NULL,\n `fingerprint` text NOT NULL,\n `created_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `sync_attempts` (\n `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,\n `peer_device_id` text NOT NULL,\n `started_at` text NOT NULL,\n `finished_at` text,\n `ok` integer NOT NULL,\n `ops_in` integer NOT NULL,\n `ops_out` integer NOT NULL,\n `error` text,\n `local_sync_capability` text,\n `peer_sync_capability` text,\n `negotiated_sync_capability` text\n);\n\nCREATE INDEX IF NOT EXISTS `idx_sync_attempts_peer_started` ON `sync_attempts` (`peer_device_id`,`started_at`);\nCREATE TABLE IF NOT EXISTS `sync_scope_rejections` (\n `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,\n `peer_device_id` text,\n `op_id` text NOT NULL,\n `entity_type` text NOT NULL,\n `entity_id` text NOT NULL,\n `scope_id` text,\n `reason` text NOT NULL,\n `created_at` text NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS `idx_sync_scope_rejections_peer_created` ON `sync_scope_rejections` (`peer_device_id`,`created_at`);\nCREATE INDEX IF NOT EXISTS `idx_sync_scope_rejections_scope_created` ON `sync_scope_rejections` (`scope_id`,`created_at`);\nCREATE TABLE IF NOT EXISTS `sync_daemon_state` (\n `id` integer PRIMARY KEY NOT NULL,\n `last_error` text,\n `last_traceback` text,\n `last_error_at` text,\n `last_ok_at` text,\n `phase` text\n);\n\nCREATE TABLE IF NOT EXISTS `sync_reset_state` (\n `id` integer PRIMARY KEY NOT NULL,\n `generation` integer NOT NULL,\n `snapshot_id` text NOT NULL,\n `baseline_cursor` text,\n `retained_floor_cursor` text,\n `updated_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `sync_reset_state_v2` (\n `scope_id` text PRIMARY KEY NOT NULL,\n `generation` integer NOT NULL,\n `snapshot_id` text NOT NULL,\n `baseline_cursor` text,\n `retained_floor_cursor` text,\n `updated_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `sync_retention_state_v2` (\n `scope_id` text PRIMARY KEY NOT NULL,\n `last_run_at` text,\n `last_duration_ms` integer,\n `last_deleted_ops` integer DEFAULT 0 NOT NULL,\n `last_estimated_bytes_before` integer,\n `last_estimated_bytes_after` integer,\n `retained_floor_cursor` text,\n `last_error` text,\n `last_error_at` text\n);\n\nCREATE TABLE IF NOT EXISTS `raw_event_ingest_samples` (\n `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,\n `created_at` text NOT NULL,\n `inserted_events` integer DEFAULT 0 NOT NULL,\n `skipped_invalid` integer DEFAULT 0 NOT NULL,\n `skipped_duplicate` integer DEFAULT 0 NOT NULL,\n `skipped_conflict` integer DEFAULT 0 NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `raw_event_ingest_stats` (\n `id` integer PRIMARY KEY NOT NULL,\n `inserted_events` integer DEFAULT 0 NOT NULL,\n `skipped_events` integer DEFAULT 0 NOT NULL,\n `skipped_invalid` integer DEFAULT 0 NOT NULL,\n `skipped_duplicate` integer DEFAULT 0 NOT NULL,\n `skipped_conflict` integer DEFAULT 0 NOT NULL,\n `updated_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `coordinator_group_preferences` (\n `coordinator_id` text NOT NULL,\n `group_id` text NOT NULL,\n `projects_include_json` text,\n `projects_exclude_json` text,\n `auto_seed_scope` integer DEFAULT 1 NOT NULL,\n `updated_at` text NOT NULL,\n PRIMARY KEY(`coordinator_id`, `group_id`)\n);\n\nCREATE TABLE IF NOT EXISTS `actors` (\n `actor_id` text PRIMARY KEY NOT NULL,\n `display_name` text NOT NULL,\n `is_local` integer DEFAULT 0 NOT NULL,\n `status` text DEFAULT 'active' NOT NULL,\n `merged_into_actor_id` text,\n `created_at` text NOT NULL,\n `updated_at` text NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS `idx_actors_is_local` ON `actors` (`is_local`);\nCREATE INDEX IF NOT EXISTS `idx_actors_status` ON `actors` (`status`);", dn = "\nCREATE INDEX IF NOT EXISTS idx_sync_peers_actor_id ON sync_peers(actor_id);\n\nCREATE TABLE IF NOT EXISTS sync_retention_state (\n id INTEGER PRIMARY KEY,\n last_run_at TEXT,\n last_duration_ms INTEGER,\n last_deleted_ops INTEGER NOT NULL DEFAULT 0,\n last_estimated_bytes_before INTEGER,\n last_estimated_bytes_after INTEGER,\n retained_floor_cursor TEXT,\n last_error TEXT,\n last_error_at TEXT\n);\n\nCREATE TABLE IF NOT EXISTS maintenance_jobs (\n kind TEXT PRIMARY KEY,\n title TEXT NOT NULL,\n status TEXT NOT NULL,\n message TEXT,\n progress_current INTEGER NOT NULL DEFAULT 0,\n progress_total INTEGER,\n progress_unit TEXT NOT NULL DEFAULT 'items',\n metadata_json TEXT,\n started_at TEXT,\n updated_at TEXT NOT NULL,\n finished_at TEXT,\n error TEXT\n);\n\nCREATE INDEX IF NOT EXISTS idx_maintenance_jobs_status_updated\n ON maintenance_jobs(status, updated_at);\n\nCREATE TABLE IF NOT EXISTS sync_scope_rejections (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n peer_device_id TEXT,\n op_id TEXT NOT NULL,\n entity_type TEXT NOT NULL,\n entity_id TEXT NOT NULL,\n scope_id TEXT,\n reason TEXT NOT NULL,\n created_at TEXT NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS idx_sync_scope_rejections_peer_created\n ON sync_scope_rejections(peer_device_id, created_at);\n\nCREATE INDEX IF NOT EXISTS idx_sync_scope_rejections_scope_created\n ON sync_scope_rejections(scope_id, created_at);\n\n-- import_key is the primary lookup key from replication_ops.entity_id back to\n-- the source memory. The scope-backfill runner's selectReplicationOpScopeCandidates\n-- query joins on it for every unstamped op; without this index a Pi 4 with\n-- ~17k memories and ~35k ops scans the full memory_items table on every batch\n-- tick. The partial WHERE clause keeps the index small (most rows have\n-- import_key set; the few that don't aren't searchable anyway).\nCREATE INDEX IF NOT EXISTS idx_memory_items_import_key\n ON memory_items(import_key)\n WHERE import_key IS NOT NULL;\n\nCREATE VIRTUAL TABLE IF NOT EXISTS memory_fts USING fts5(\n title, body_text, tags_text,\n content='memory_items',\n content_rowid='id'\n);\n\nCREATE TRIGGER IF NOT EXISTS memory_items_ai AFTER INSERT ON memory_items BEGIN\n INSERT INTO memory_fts(rowid, title, body_text, tags_text)\n VALUES (new.id, new.title, new.body_text, new.tags_text);\nEND;\n\nDROP TRIGGER IF EXISTS memory_items_au;\nCREATE TRIGGER memory_items_au AFTER UPDATE ON memory_items BEGIN\n INSERT INTO memory_fts(memory_fts, rowid, title, body_text, tags_text)\n VALUES('delete', old.id, old.title, old.body_text, old.tags_text);\n INSERT INTO memory_fts(rowid, title, body_text, tags_text)\n VALUES (new.id, new.title, new.body_text, new.tags_text);\nEND;\n\nDROP TRIGGER IF EXISTS memory_items_ad;\nCREATE TRIGGER memory_items_ad AFTER DELETE ON memory_items BEGIN\n INSERT INTO memory_fts(memory_fts, rowid, title, body_text, tags_text)\n VALUES('delete', old.id, old.title, old.body_text, old.tags_text);\nEND;\n\nCREATE TABLE IF NOT EXISTS memory_file_refs (\n memory_id INTEGER NOT NULL,\n file_path TEXT NOT NULL,\n relation TEXT NOT NULL CHECK(relation IN ('read', 'modified')),\n PRIMARY KEY (memory_id, file_path, relation),\n FOREIGN KEY (memory_id) REFERENCES memory_items(id) ON DELETE CASCADE\n);\n\nCREATE INDEX IF NOT EXISTS idx_memory_file_refs_path\n ON memory_file_refs(file_path);\n\nCREATE TABLE IF NOT EXISTS memory_concept_refs (\n memory_id INTEGER NOT NULL,\n concept TEXT NOT NULL,\n PRIMARY KEY (memory_id, concept),\n FOREIGN KEY (memory_id) REFERENCES memory_items(id) ON DELETE CASCADE\n);\n\nCREATE INDEX IF NOT EXISTS idx_memory_concept_refs_concept\n ON memory_concept_refs(concept);\n\nCREATE TABLE IF NOT EXISTS coordinator_group_preferences (\n coordinator_id TEXT NOT NULL,\n group_id TEXT NOT NULL,\n projects_include_json TEXT,\n projects_exclude_json TEXT,\n auto_seed_scope INTEGER NOT NULL DEFAULT 1,\n updated_at TEXT NOT NULL,\n PRIMARY KEY (coordinator_id, group_id)\n);\n\nCREATE TABLE IF NOT EXISTS scope_membership_cache_state (\n coordinator_id TEXT NOT NULL,\n group_id TEXT NOT NULL,\n last_refresh_at TEXT NOT NULL,\n last_success_at TEXT,\n last_error TEXT,\n updated_at TEXT NOT NULL,\n PRIMARY KEY (coordinator_id, group_id)\n);\n", fn = "\nCREATE VIRTUAL TABLE IF NOT EXISTS memory_vectors USING vec0(\n embedding float[384],\n memory_id INTEGER,\n chunk_index INTEGER,\n content_hash TEXT,\n model TEXT\n);\n";
1343
1344
  function pn(e) {
1344
1345
  if (!Ln()) try {
1345
1346
  mn(e) || In(e), e.exec(fn);
@@ -1519,6 +1520,9 @@ function Hn(e) {
1519
1520
  try {
1520
1521
  e.exec("CREATE INDEX IF NOT EXISTS idx_memory_items_scope_visibility_created ON memory_items(scope_id, visibility, created_at)");
1521
1522
  } catch {}
1523
+ try {
1524
+ e.exec("CREATE INDEX IF NOT EXISTS idx_memory_items_scope_backfill_pending ON memory_items(id) WHERE scope_id IS NULL OR scope_id = ''");
1525
+ } catch {}
1522
1526
  }
1523
1527
  if (X(e, "replication_ops")) {
1524
1528
  Vn(e, "replication_ops", "scope_id", "TEXT");
@@ -14828,19 +14832,19 @@ function Tv(e, t = (/* @__PURE__ */ new Date()).toISOString()) {
14828
14832
  })();
14829
14833
  }
14830
14834
  function Ev(e) {
14831
- let t = e.prepare("SELECT COUNT(*) AS n\n FROM memory_items\n WHERE scope_id IS NULL OR TRIM(scope_id) = ''").get();
14835
+ let t = e.prepare("SELECT COUNT(*) AS n\n FROM memory_items\n WHERE scope_id IS NULL OR scope_id = ''").get();
14832
14836
  return Number(t?.n ?? 0);
14833
14837
  }
14834
14838
  function Dv(e) {
14835
- let t = e.prepare("SELECT MAX(id) AS max_id\n FROM memory_items\n WHERE scope_id IS NOT NULL AND TRIM(scope_id) <> ''").get();
14839
+ let t = e.prepare("SELECT MAX(id) AS max_id\n FROM memory_items\n WHERE scope_id IS NOT NULL AND scope_id <> ''").get();
14836
14840
  return Number(t?.max_id ?? 0);
14837
14841
  }
14838
14842
  function Ov(e) {
14839
- let t = e.prepare("SELECT COUNT(*) AS n\n FROM replication_ops\n WHERE entity_type = 'memory_item'\n AND (scope_id IS NULL OR TRIM(scope_id) = '')").get();
14843
+ let t = e.prepare("SELECT COUNT(*) AS n\n FROM replication_ops\n WHERE entity_type = 'memory_item'\n AND (scope_id IS NULL OR scope_id = '')").get();
14840
14844
  return Number(t?.n ?? 0);
14841
14845
  }
14842
14846
  function kv(e) {
14843
- if (e.prepare("SELECT 1\n FROM (SELECT ? AS scope_id UNION ALL SELECT ? AS scope_id) required\n WHERE NOT EXISTS (\n SELECT 1 FROM replication_scopes rs WHERE rs.scope_id = required.scope_id\n )\n LIMIT 1").get("local-default", "legacy-shared-review") || e.prepare("SELECT 1\n FROM memory_items\n WHERE scope_id IS NULL OR TRIM(scope_id) = ''\n LIMIT 1").get()) return !0;
14847
+ if (e.prepare("SELECT 1\n FROM (SELECT ? AS scope_id UNION ALL SELECT ? AS scope_id) required\n WHERE NOT EXISTS (\n SELECT 1 FROM replication_scopes rs WHERE rs.scope_id = required.scope_id\n )\n LIMIT 1").get("local-default", "legacy-shared-review") || e.prepare("SELECT 1\n FROM memory_items\n WHERE scope_id IS NULL OR scope_id = ''\n LIMIT 1").get()) return !0;
14844
14848
  let t = Ov(e);
14845
14849
  if (t === 0) return !1;
14846
14850
  let n = Q(e, bv);
@@ -14848,20 +14852,20 @@ function kv(e) {
14848
14852
  let r = n.metadata ?? {}, i = r.unstamped_replication_ops_at_completion;
14849
14853
  if (typeof i != "number" || t > i) return !0;
14850
14854
  let a = r.max_stamped_memory_id_at_completion;
14851
- return typeof a == "number" ? !!e.prepare("SELECT 1\n FROM memory_items\n WHERE id > ?\n AND scope_id IS NOT NULL AND TRIM(scope_id) <> ''\n LIMIT 1").get(a) : !0;
14855
+ return typeof a == "number" ? !!e.prepare("SELECT 1\n FROM memory_items\n WHERE id > ?\n AND scope_id IS NOT NULL AND scope_id <> ''\n LIMIT 1").get(a) : !0;
14852
14856
  }
14853
14857
  function Av(e, t) {
14854
- return e.prepare("SELECT\n mi.id,\n mi.visibility,\n mi.workspace_id,\n mi.workspace_kind,\n s.project,\n s.cwd,\n s.git_remote\n FROM memory_items mi\n LEFT JOIN sessions s ON s.id = mi.session_id\n WHERE mi.scope_id IS NULL OR TRIM(mi.scope_id) = ''\n ORDER BY mi.id ASC\n LIMIT ?").all(t);
14858
+ return e.prepare("SELECT\n mi.id,\n mi.visibility,\n mi.workspace_id,\n mi.workspace_kind,\n s.project,\n s.cwd,\n s.git_remote\n FROM memory_items AS mi INDEXED BY idx_memory_items_scope_backfill_pending\n LEFT JOIN sessions s ON s.id = mi.session_id\n WHERE mi.scope_id IS NULL OR mi.scope_id = ''\n ORDER BY mi.id ASC\n LIMIT ?").all(t);
14855
14859
  }
14856
14860
  function jv(e, t) {
14857
- return e.prepare("SELECT op_id, entity_id, created_at\n FROM (\n SELECT ro.op_id, ro.entity_id, ro.created_at\n FROM replication_ops ro\n INNER JOIN memory_items mi ON mi.import_key = ro.entity_id\n WHERE ro.entity_type = 'memory_item'\n AND (ro.scope_id IS NULL OR TRIM(ro.scope_id) = '')\n AND mi.scope_id IS NOT NULL\n AND TRIM(mi.scope_id) != ''\n UNION\n SELECT ro.op_id, ro.entity_id, ro.created_at\n FROM replication_ops ro\n INNER JOIN memory_items mi ON mi.id = CAST(ro.entity_id AS INTEGER)\n WHERE ro.entity_type = 'memory_item'\n AND (ro.scope_id IS NULL OR TRIM(ro.scope_id) = '')\n AND mi.scope_id IS NOT NULL\n AND TRIM(mi.scope_id) != ''\n AND CAST(mi.id AS TEXT) = ro.entity_id\n )\n ORDER BY created_at ASC, op_id ASC\n LIMIT ?").all(t);
14861
+ return e.prepare("SELECT op_id, entity_id, created_at\n FROM (\n SELECT ro.op_id, ro.entity_id, ro.created_at\n FROM replication_ops ro\n INNER JOIN memory_items mi ON mi.import_key = ro.entity_id\n WHERE ro.entity_type = 'memory_item'\n AND (ro.scope_id IS NULL OR ro.scope_id = '')\n AND mi.scope_id IS NOT NULL\n AND mi.scope_id != ''\n UNION\n SELECT ro.op_id, ro.entity_id, ro.created_at\n FROM replication_ops ro\n INNER JOIN memory_items mi ON mi.id = CAST(ro.entity_id AS INTEGER)\n WHERE ro.entity_type = 'memory_item'\n AND (ro.scope_id IS NULL OR ro.scope_id = '')\n AND mi.scope_id IS NOT NULL\n AND mi.scope_id != ''\n AND CAST(mi.id AS TEXT) = ro.entity_id\n )\n ORDER BY created_at ASC, op_id ASC\n LIMIT ?").all(t);
14858
14862
  }
14859
14863
  function Mv(e, t) {
14860
- return xv(e.prepare("SELECT scope_id\n FROM memory_items\n WHERE (import_key = ? OR CAST(id AS TEXT) = ?)\n AND scope_id IS NOT NULL\n AND TRIM(scope_id) != ''\n ORDER BY CASE WHEN import_key = ? THEN 0 ELSE 1 END, id ASC\n LIMIT 1").get(t, t, t)?.scope_id);
14864
+ return xv(e.prepare("SELECT scope_id\n FROM memory_items\n WHERE (import_key = ? OR CAST(id AS TEXT) = ?)\n AND scope_id IS NOT NULL\n AND scope_id != ''\n ORDER BY CASE WHEN import_key = ? THEN 0 ELSE 1 END, id ASC\n LIMIT 1").get(t, t, t)?.scope_id);
14861
14865
  }
14862
14866
  function Nv(e, t = {}) {
14863
- let n = Math.max(1, t.memoryLimit ?? 250), r = Math.max(1, t.replicationOpLimit ?? n), i = Tv(e, t.now), a = Av(e, n), o = e.prepare("UPDATE memory_items\n SET scope_id = ?\n WHERE id = ?\n AND (scope_id IS NULL OR TRIM(scope_id) = '')"), s = e.prepare("UPDATE replication_ops\n SET scope_id = ?\n WHERE op_id = ?\n AND (scope_id IS NULL OR TRIM(scope_id) = '')"), c = e.transaction(() => {
14864
- let t = 0, n = 0, i = 0;
14867
+ let n = Math.max(1, t.memoryLimit ?? 250), r = Math.max(1, t.replicationOpLimit ?? n), i = Tv(e, t.now), a = Av(e, n), o = e.prepare("UPDATE memory_items\n SET scope_id = ?\n WHERE id = ?\n AND (scope_id IS NULL OR scope_id = '')"), s = e.prepare("UPDATE replication_ops\n SET scope_id = ?\n WHERE op_id = ?\n AND (scope_id IS NULL OR scope_id = '')"), c = e.transaction(() => {
14868
+ let t = 0, i = 0, c = 0;
14865
14869
  for (let e of a) {
14866
14870
  let n = Cv({
14867
14871
  visibility: e.visibility,
@@ -14873,20 +14877,20 @@ function Nv(e, t = {}) {
14873
14877
  });
14874
14878
  t += Number(o.run(n.scopeId, e.id).changes ?? 0);
14875
14879
  }
14876
- let c = jv(e, r);
14877
- for (let t of c) {
14878
- let r = Mv(e, t.entity_id);
14879
- if (!r) {
14880
- i += 1;
14880
+ let l = a.length >= n ? [] : jv(e, r);
14881
+ for (let t of l) {
14882
+ let n = Mv(e, t.entity_id);
14883
+ if (!n) {
14884
+ c += 1;
14881
14885
  continue;
14882
14886
  }
14883
- n += Number(s.run(r, t.op_id).changes ?? 0);
14887
+ i += Number(s.run(n, t.op_id).changes ?? 0);
14884
14888
  }
14885
14889
  return {
14886
- checkedReplicationOps: c.length,
14890
+ checkedReplicationOps: l.length,
14887
14891
  updatedMemoryItems: t,
14888
- updatedReplicationOps: n,
14889
- skippedReplicationOps: i
14892
+ updatedReplicationOps: i,
14893
+ skippedReplicationOps: c
14890
14894
  };
14891
14895
  })();
14892
14896
  return {
@@ -14908,7 +14912,7 @@ async function Fv(e, t = {}) {
14908
14912
  if (l <= 0) {
14909
14913
  let t = !!i.exhausted_in_previous_pass;
14910
14914
  return r && r.status !== "completed" ? t ? (Yr(e, bv, {
14911
- message: "Scope backfill complete",
14915
+ message: "Sharing-domain backfill complete; future startup should be quieter",
14912
14916
  progressCurrent: Number(i.processed_memories ?? 0),
14913
14917
  progressTotal: Number(i.processed_memories ?? 0),
14914
14918
  metadata: {
@@ -14919,7 +14923,7 @@ async function Fv(e, t = {}) {
14919
14923
  max_stamped_memory_id_at_completion: Dv(e)
14920
14924
  }
14921
14925
  }), !1) : (Jr(e, bv, {
14922
- message: "Scope backfill quiescent — confirming on next tick",
14926
+ message: "Sharing-domain backfill quiescent — confirming on next tick",
14923
14927
  progressCurrent: Number(i.processed_memories ?? 0),
14924
14928
  progressTotal: Number(i.processed_memories ?? 0),
14925
14929
  metadata: {
@@ -14932,8 +14936,8 @@ async function Fv(e, t = {}) {
14932
14936
  }
14933
14937
  a && qr(e, {
14934
14938
  kind: bv,
14935
- title: "Backfilling sharing domains",
14936
- message: `Backfilling ${l} legacy scope item(s)`,
14939
+ title: "Backfilling Sharing domains",
14940
+ message: `Backfilling ${l} legacy Sharing-domain item(s), including memories and replication ops`,
14937
14941
  progressTotal: l,
14938
14942
  metadata: {
14939
14943
  seeded_scopes: 0,
@@ -14961,7 +14965,7 @@ async function Fv(e, t = {}) {
14961
14965
  exhausted_in_previous_pass: x
14962
14966
  };
14963
14967
  return C ? (Yr(e, bv, {
14964
- message: "Scope backfill complete",
14968
+ message: "Sharing-domain backfill complete; future startup should be quieter",
14965
14969
  progressCurrent: l,
14966
14970
  progressTotal: l,
14967
14971
  metadata: {
@@ -14970,7 +14974,7 @@ async function Fv(e, t = {}) {
14970
14974
  max_stamped_memory_id_at_completion: Dv(e)
14971
14975
  }
14972
14976
  }), !1) : (Jr(e, bv, {
14973
- message: `Backfilled sharing domains for ${w} of ${l} item(s)`,
14977
+ message: `Backfilled Sharing domains for ${w} of ${l} item(s), including memories and replication ops`,
14974
14978
  progressCurrent: w,
14975
14979
  progressTotal: l,
14976
14980
  metadata: ee
@@ -14991,7 +14995,7 @@ var Iv = class {
14991
14995
  this.active || (this.active = !0, this.schedule(100));
14992
14996
  }
14993
14997
  async stop() {
14994
- this.active = !1, this.timer &&= (clearTimeout(this.timer), null), this.currentRun && await this.currentRun;
14998
+ this.active = !1, this.timer &&= (clearTimeout(this.timer), null), !this.signal?.aborted && this.currentRun && await this.currentRun;
14995
14999
  }
14996
15000
  schedule(e) {
14997
15001
  !this.active || this.signal?.aborted || (this.timer = setTimeout(() => {
@@ -16306,12 +16310,13 @@ var yb = class {
16306
16310
  signal;
16307
16311
  batchSize;
16308
16312
  intervalMs;
16313
+ idleIntervalMs;
16309
16314
  active = !1;
16310
16315
  timer = null;
16311
16316
  currentRun = null;
16312
16317
  lastTickWasIdle = !1;
16313
16318
  constructor(e = {}) {
16314
- this.dbPath = Dn(e.dbPath), this.signal = e.signal, this.batchSize = Math.max(1, e.batchSize ?? 50), this.intervalMs = Math.max(1e3, e.intervalMs ?? 5e3);
16319
+ this.dbPath = Dn(e.dbPath), this.signal = e.signal, this.batchSize = Math.max(1, e.batchSize ?? 50), this.intervalMs = Math.max(1e3, e.intervalMs ?? 5e3), this.idleIntervalMs = Math.max(1e3, e.idleIntervalMs ?? eb);
16315
16320
  }
16316
16321
  start() {
16317
16322
  this.active || (this.active = !0, this.lastTickWasIdle = !1, tb = this, this.schedule(100));
@@ -16328,7 +16333,7 @@ var yb = class {
16328
16333
  console.error("Vector migration runner tick failed:", e);
16329
16334
  }).finally(() => {
16330
16335
  this.currentRun = null;
16331
- let e = this.lastTickWasIdle ? eb : this.intervalMs;
16336
+ let e = this.lastTickWasIdle ? this.idleIntervalMs : this.intervalMs;
16332
16337
  this.schedule(e);
16333
16338
  });
16334
16339
  }, e), typeof this.timer == "object" && "unref" in this.timer && this.timer.unref());
@@ -17425,7 +17430,7 @@ function Hx(e, t = "local") {
17425
17430
  }
17426
17431
  //#endregion
17427
17432
  //#region src/index.ts
17428
- var Ux = "0.30.0-alpha.3";
17433
+ var Ux = "0.30.0-alpha.4";
17429
17434
  //#endregion
17430
17435
  export { ke as Api, V as BetterSqliteCoordinatorStore, Ft as CODEMEM_CONFIG_ENV_OVERRIDES, xh as DEDUP_KEY_BACKFILL_JOB, R as DEFAULT_COORDINATOR_DB_PATH, En as DEFAULT_DB_PATH, Wl as DEFAULT_SCOPE_MEMBERSHIP_CACHE_MAX_AGE_MS, kb as DEFAULT_SERVICE_TYPE, Su as DEFAULT_SYNC_SCOPE_ID, o as DEFAULT_TIME_WINDOW_S, Th as DedupKeyBackfillRunner, si as INJECTION_EVAL_SCENARIO_PACKS, yv as LEGACY_SHARED_REVIEW_SCOPE_ID, Ti as LOCAL_DEFAULT_SCOPE_ID, qy as LOCAL_SYNC_CAPABILITY, zg as LOW_SIGNAL_TOOLS, Sr as MAPPABLE_CLAUDE_HOOK_EVENTS, Cn as MIN_COMPATIBLE_SCHEMA, Ae as MUTATING_TOOL_NAMES, bf as MemoryStore, yp as ObserverAuthAdapter, Hp as ObserverAuthError, pm as ObserverClient, gy as REF_BACKFILL_JOB, mg as RICH_TIER_DEFAULTS, hy as RawEventSweeper, Sy as RefBackfillRunner, Sn as SCHEMA_VERSION, bv as SCOPE_BACKFILL_JOB, n as SCOPE_MEMBERSHIP_REVOCATION_LIMITATION, Cy as SESSION_CONTEXT_BACKFILL_JOB, fr as SIGNATURE_VERSION, pg as SIMPLE_TIER_DEFAULTS, Ly as SUMMARY_DEDUP_BACKFILL_JOB, Gy as SYNC_CAPABILITIES, Ky as SYNC_CAPABILITY_HEADER, Ix as SYNC_SCOPE_QUERY_PARAM, Iv as ScopeBackfillRunner, Iy as SessionContextBackfillRunner, Wy as SummaryDedupBackfillRunner, Fx as SyncRetentionRunner, p_ as TRIVIAL_REQUESTS, Zy as VECTOR_MODEL_MIGRATION_JOB, Ux as VERSION, yb as VectorModelMigrationRunner, Qo as _resetEmbeddingClient, Rx as addSyncScopeToBoundary, vl as addressDedupeKey, Wb as advertiseMdns, Om as aiBackfillStructuredContent, cy as analyzeProjectScopeMappingChangeGuardrails, Db as applyBootstrapSnapshot, Zd as applyReplicationOps, zn as assertSchemaReady, ep as backfillMemoryDedupKeys, Yf as backfillNarrativeFromBody, Jd as backfillReplicationOps, Nv as backfillScopeIds, zf as backfillTagsText, ks as backfillVectors, hn as bootstrapSchema, Zg as budgetToolEvents, _r as buildAuthHeaders, bl as buildBaseUrl, pr as buildCanonicalRequest, mp as buildCodexHeaders, Ji as buildFilterClauses, Yi as buildFilterClausesWithContext, Ih as buildImportKey, zr as buildIngestPayloadFromHook, qc as buildMemoryPack, Yc as buildMemoryPackAsync, Jc as buildMemoryPackTrace, Xc as buildMemoryPackTraceAsync, d_ as buildObserverPrompt, Rr as buildRawEventEnvelopeFromHook, tv as buildSessionContext, v_ as buildTranscript, cd as bulkPruneReplicationOpsByAgeCutoff, mi as canonicalMemoryKind, ji as canonicalWorkspaceIdentity, Uu as chunkOpsBySize, Xo as chunkText, Cv as classifyLegacyMemoryScope, J_ as cleanOrphanSessions, yr as cleanupNonces, ha as clearMemoryRefs, Zu as clockTuple, Af as compareMemoryRoleReports, Yr as completeMaintenanceJob, Mn as connect, Xe as connectCoordinator, vx as consecutiveConnectivityFailures, qm as coordinatorArchiveGroupAction, Gm as coordinatorCreateGroupAction, ch as coordinatorCreateInviteAction, Zm as coordinatorCreateScopeAction, ah as coordinatorDisableDeviceAction, oh as coordinatorEnableDeviceAction, jl as coordinatorEnabled, nh as coordinatorEnrollDeviceAction, eh as coordinatorGrantScopeMembershipAction, lh as coordinatorImportInviteAction, fh as coordinatorListBootstrapGrantsAction, rh as coordinatorListDevicesAction, Ym as coordinatorListGroupsAction, uh as coordinatorListJoinRequestsAction, $m as coordinatorListScopeMembershipsAction, Xm as coordinatorListScopesAction, sh as coordinatorRemoveDeviceAction, ih as coordinatorRenameDeviceAction, Km as coordinatorRenameGroupAction, dh as coordinatorReviewJoinRequestAction, ph as coordinatorRevokeBootstrapGrantAction, th as coordinatorRevokeScopeMembershipAction, Hl as coordinatorStatusSnapshot, Jm as coordinatorUnarchiveGroupAction, Qm as coordinatorUpdateScopeAction, br as createBetterSqliteCoordinatorApp, c as createCoordinatorApp, Bl as createCoordinatorReciprocalApproval, Qb as cursorAdvances, Kf as deactivateLowSignalMemories, Gf as deactivateLowSignalObservations, Tg as decideExtractionReplayTier, s as decodeInvitePayload, qf as dedupNearDuplicateMemories, Wo as dedupeOrderedIds, bh as deleteCoordinatorGroupPreference, dy as deleteProjectScopeSettingsMapping, __ as deriveRequest, xu as deriveTags, Gb as discoverPeersViaMdns, ts as embedTexts, t as encodeInvitePayload, dr as ensureDeviceIdentity, Zr as ensureMaintenanceJobsSchema, yn as ensureSchemaBootstrapped, Tv as ensureScopeBackfillScopes, Xl as ensureScopeMembershipCacheStateTable, Bs as estimateTokens, dg as evaluateSessionExtractionItems, Wg as eventToToolEvent, Ga as expandQuery, Jo as explain, e as explainScopeMembershipRevocation, Gh as exportMemories, Kg as extractAdapterEvent, je as extractApplyPatchPaths, y_ as extractAssistantMessages, b_ as extractAssistantUsage, r as extractInvitePayload, Jf as extractNarrativeFromBody, lp as extractOAuthAccess, fp as extractOAuthAccountId, pp as extractOAuthExpires, x_ as extractPrompts, up as extractProviderApiKey, Xu as extractReplicationOps, Gg as extractToolEvents, Xr as failMaintenanceJob, bb as fetchAllSnapshotPages, Rl as fetchCoordinatorStalePeers, bu as fileTags, jd as filterReplicationOpsForSync, Ad as filterReplicationOpsForSyncWithStatus, va as findByConcept, _a as findByFile, i as fingerprintPublicKey, g_ as firstSentence, rv as flushRawEvents, Un as fromJson, Wn as fromJsonStrict, sr as generateKeypair, _u as getCachedScopeAuthorization, Lt as getCodememConfigPath, Ht as getCodememEnvOverrides, _h as getCoordinatorGroupPreference, es as getEmbeddingClient, rg as getExtractionBenchmarkProfile, oi as getInjectionEvalScenarioByPrompt, ci as getInjectionEvalScenarioPack, li as getInjectionEvalScenarioPrompts, Q as getMaintenanceJob, kf as getMemoryRoleReport, Wt as getOpenCodeProviderConfig, sn as getProviderApiKey, an as getProviderBaseUrl, on as getProviderHeaders, rn as getProviderOptions, ri as getRawEventRelinkPlan, ni as getRawEventRelinkReport, jf as getRawEventStatus, Nf as getReliabilityMetrics, qu as getReplicationCursor, Rn as getSchemaVersion, Cs as getSemanticIndexDiagnostics, fg as getSessionExtractionEval, ug as getSessionExtractionEvalScenario, di as getSummaryMetadata, Cx as getSyncDaemonPhase, Ru as getSyncResetState, At as getWorkspaceCodememConfigPath, jt as getWorkspaceScopedCodememConfigPath, P_ as hasMeaningfulObservation, Sh as hasPendingDedupKeyBackfill, vy as hasPendingRefBackfill, kv as hasPendingScopeBackfill, Ny as hasPendingSessionContextBackfill, zy as hasPendingSummaryDedupBackfill, ad as hasUnsyncedSharedMemoryChanges, Yo as hashText, tg as importMemories, K_ as ingest, Y_ as ingestMain, ii as initDatabase, Bx as initTestSchema, Vx as insertTestSession, l as inviteLink, _x as isConnectivityError, Ln as isEmbeddingDisabled, Bg as isInternalMemoryTool, Hf as isLowSignalObservation, Qu as isNewerClock, Mg as isSensitiveFieldName, fi as isSummaryLikeMemory, h_ as isTrivialRequest, qa as kindBonus, gu as listCachedScopesForDevice, Jt as listConfiguredOpenCodeProviders, vh as listCoordinatorGroupPreferences, Ul as listCoordinatorJoinRequests, zl as listCoordinatorReciprocalApprovals, Gt as listCustomProviders, ig as listExtractionBenchmarkProfiles, Wd as listInboundScopeRejections, Kr as listMaintenanceJobs, Yt as listObserverProviderOptions, ly as listProjectScopeCandidates, ry as listProjectScopeSettingsMappings, ny as listSharingDomainSettingsScopes, id as loadMemorySnapshotPageForPeer, Vp as loadObserverConfig, Dt as loadOpenCodeConfig, op as loadOpenCodeOAuthCache, jb as loadPeerAddresses, rr as loadPrivateKey, er as loadPrivateKeyKeychain, nr as loadPublicKey, rd as loadReplicationOpsForPeer, nd as loadReplicationOpsSince, In as loadSqliteVec, Pl as lookupCoordinatorPeers, Ir as mapClaudeHookPayload, Kb as mdnsAddressesForPeer, Rb as mdnsEnabled, yl as mergeAddresses, Lh as mergeSummaryMetadata, jn as migrateLegacyDbPath, qd as migrateLegacyImportKeys, Xy as negotiateSyncCapability, C_ as normalizeAdapterEvents, _l as normalizeAddress, ma as normalizeConcept, S_ as normalizeEventsForSessionContext, Vf as normalizeObservation, Dr as normalizeProjectLabel, m_ as normalizeRequestText, Yy as normalizeSyncCapability, yu as normalizeTag, Vg as normalizeToolName, N_ as parseObserverResponse, Sa as parsePositiveMemoryId, xa as parseStrictInteger, Lx as parseSyncScopeRequest, yx as peerBackoffSeconds, Sd as peerCanSyncPrivateOpByPersonalScopeGrant, yd as personalScopeGrantStatusForPeer, ld as planReplicationOpsAgePrune, ga as populateMemoryRefs, dp as probeAvailableCredentials, qg as projectAdapterToolEvent, yi as projectBasename, xi as projectClause, bi as projectColumnClause, Si as projectMatchesFilter, od as pruneReplicationOps, sd as pruneReplicationOpsUntilCaughtUp, Pf as rawEventsGate, gp as readAuthFile, Rt as readCodememConfigFile, zt as readCodememConfigFileAtPath, Al as readCoordinatorSyncConfig, Kh as readImportPayload, Pt as readWorkspaceCodememConfigFile, Ka as recencyScore, vr as recordNonce, Pb as recordPeerSuccess, $u as recordReplicationOp, Nb as recordSyncAttempt, rp as redactText, hu as refreshConfiguredScopeMembershipCache, mu as refreshScopeMembershipCache, Ll as refreshStoredCoordinatorPeerAddresses, Nl as registerCoordinatorPresence, Hd as rejectInboundScopeFailures, Cp as renderObserverHeaders, _v as replayBatchExtraction, vv as replayBatchExtractionWithTierRouting, xd as replicationOpRequiresPersonalScopeAuthorization, xl as requestJson, Lo as rerankResults, Zt as resolveBuiltInProviderDefaultModel, Xt as resolveBuiltInProviderFromModel, Qt as resolveBuiltInProviderModel, It as resolveCodememConfigPath, cn as resolveCustomProviderDefaultModel, $t as resolveCustomProviderFromModel, ln as resolveCustomProviderModel, Dn as resolveDbPath, Ar as resolveHookProject, tr as resolveKeyPaths, sp as resolveOAuthProvider, en as resolvePlaceholder, wi as resolveProject, Bi as resolveProjectScope, Mf as retryRawEventFailures, hp as runAuthCommand, wh as runDedupKeyBackfillPass, xy as runRefBackfillPass, Fv as runScopeBackfillPass, Py as runSessionContextBackfillPass, Uy as runSummaryDedupBackfillPass, Dx as runSyncDaemon, px as runSyncPass, vb as runVectorMigrationPass, Fg as sanitizePayload, Rg as sanitizeToolOutput, Im as scanSecretsRetroactive, H as schema, a as scopeMembershipEpochStatus, Ro as search, Hx as seedMixedScopeFixture, Ab as selectDialAddresses, As as semanticSearch, rs as serializeFloat32, Ib as setPeerLocalActorClaim, Fb as setPeerProjectFilter, Ju as setReplicationCursor, Sx as setSyncDaemonError, xx as setSyncDaemonOk, wx as setSyncDaemonPhase, zu as setSyncResetState, bx as shouldSkipOfflinePeer, mr as signRequest, qr as startMaintenanceJob, $n as storePrivateKeyKeychain, Os as storeVectors, Tt as stripJsonComments, kg as stripPrivate, Ng as stripPrivateObj, Et as stripTrailingCommas, Ud as summarizeInboundScopeRejections, Ex as syncDaemonTick, fx as syncOnce, dx as syncPassPreflight, _d as syncProjectAllowedByFilters, zx as syncScopeResetRequiredPayload, vd as syncVisibilityAllowed, X as tableExists, Ho as timeline, Z as toJson, Gn as toJsonNullable, Jr as updateMaintenanceJob, Mb as updatePeerAddresses, iu as upsertCachedScopeMemberships, yh as upsertCoordinatorGroupPreference, uy as upsertProjectScopeSettingsMapping, ai as vacuumDatabase, ur as validateExistingKeypair, hr as verifySignature, Bt as writeCodememConfigFile, Vt as writeWorkspaceCodememConfigFile };
17431
17436