@codemem/core 0.31.4 → 0.32.0
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/coordinator-group-preferences.d.ts +5 -0
- package/dist/coordinator-group-preferences.d.ts.map +1 -1
- package/dist/db.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +907 -886
- package/dist/index.js.map +1 -1
- package/dist/schema-bootstrap.d.ts.map +1 -1
- package/dist/schema.d.ts +72 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/test-schema.generated.d.ts +1 -1
- package/dist/test-schema.generated.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -881,6 +881,8 @@ var V = class {
|
|
|
881
881
|
projects_include_json: L("projects_include_json"),
|
|
882
882
|
projects_exclude_json: L("projects_exclude_json"),
|
|
883
883
|
auto_seed_scope: F("auto_seed_scope").notNull().default(1),
|
|
884
|
+
default_space_scope_id: L("default_space_scope_id"),
|
|
885
|
+
auto_grant_default_space_on_join: F("auto_grant_default_space_on_join").notNull().default(0),
|
|
884
886
|
updated_at: L("updated_at").notNull()
|
|
885
887
|
}, (e) => ({ pk: ye({ columns: [e.coordinator_id, e.group_id] }) })), St = I("actors", {
|
|
886
888
|
actor_id: L("actor_id").primaryKey(),
|
|
@@ -1382,7 +1384,7 @@ function ln(e, t) {
|
|
|
1382
1384
|
}
|
|
1383
1385
|
//#endregion
|
|
1384
1386
|
//#region src/test-schema.generated.ts
|
|
1385
|
-
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";
|
|
1387
|
+
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 `default_space_scope_id` text,\n `auto_grant_default_space_on_join` integer DEFAULT 0 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 default_space_scope_id TEXT,\n auto_grant_default_space_on_join INTEGER NOT NULL DEFAULT 0,\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";
|
|
1386
1388
|
function pn(e) {
|
|
1387
1389
|
if (!Ln()) try {
|
|
1388
1390
|
mn(e) || In(e), e.exec(fn);
|
|
@@ -1599,8 +1601,20 @@ function Hn(e) {
|
|
|
1599
1601
|
}
|
|
1600
1602
|
}
|
|
1601
1603
|
try {
|
|
1602
|
-
e.exec("\n CREATE 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 ");
|
|
1604
|
+
e.exec("\n CREATE 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 default_space_scope_id TEXT,\n auto_grant_default_space_on_join INTEGER NOT NULL DEFAULT 0,\n updated_at TEXT NOT NULL,\n PRIMARY KEY (coordinator_id, group_id)\n )\n ");
|
|
1603
1605
|
} catch {}
|
|
1606
|
+
for (let { name: t, ddl: n } of [{
|
|
1607
|
+
name: "default_space_scope_id",
|
|
1608
|
+
ddl: "TEXT"
|
|
1609
|
+
}, {
|
|
1610
|
+
name: "auto_grant_default_space_on_join",
|
|
1611
|
+
ddl: "INTEGER NOT NULL DEFAULT 0"
|
|
1612
|
+
}]) if (!Bn(e, "coordinator_group_preferences", t)) try {
|
|
1613
|
+
e.exec(`ALTER TABLE coordinator_group_preferences ADD COLUMN ${t} ${n}`);
|
|
1614
|
+
} catch (e) {
|
|
1615
|
+
if ((e instanceof Error ? e.message.toLowerCase() : "").includes("duplicate column name")) continue;
|
|
1616
|
+
throw e;
|
|
1617
|
+
}
|
|
1604
1618
|
if (X(e, "raw_event_flush_batches")) {
|
|
1605
1619
|
for (let { name: t, ddl: n } of [
|
|
1606
1620
|
{
|
|
@@ -12359,6 +12373,11 @@ async function Eh(e) {
|
|
|
12359
12373
|
//#endregion
|
|
12360
12374
|
//#region src/coordinator-group-preferences.ts
|
|
12361
12375
|
function Dh(e) {
|
|
12376
|
+
let t = e.trim();
|
|
12377
|
+
if (!t) throw Error("group_id must be a non-empty string");
|
|
12378
|
+
return `team:${t}:default`;
|
|
12379
|
+
}
|
|
12380
|
+
function Oh(e) {
|
|
12362
12381
|
if (!e) return null;
|
|
12363
12382
|
try {
|
|
12364
12383
|
let t = JSON.parse(e);
|
|
@@ -12367,50 +12386,52 @@ function Dh(e) {
|
|
|
12367
12386
|
return null;
|
|
12368
12387
|
}
|
|
12369
12388
|
}
|
|
12370
|
-
function
|
|
12389
|
+
function kh(e) {
|
|
12371
12390
|
return !e || e.length === 0 ? null : JSON.stringify(e.map(String).filter(Boolean));
|
|
12372
12391
|
}
|
|
12373
|
-
function
|
|
12392
|
+
function Ah(e) {
|
|
12374
12393
|
return {
|
|
12375
12394
|
coordinator_id: e.coordinator_id,
|
|
12376
12395
|
group_id: e.group_id,
|
|
12377
|
-
projects_include:
|
|
12378
|
-
projects_exclude:
|
|
12396
|
+
projects_include: Oh(e.projects_include_json),
|
|
12397
|
+
projects_exclude: Oh(e.projects_exclude_json),
|
|
12379
12398
|
auto_seed_scope: !!e.auto_seed_scope,
|
|
12399
|
+
default_space_scope_id: e.default_space_scope_id ?? null,
|
|
12400
|
+
auto_grant_default_space_on_join: e.auto_grant_default_space_on_join == null ? !1 : !!e.auto_grant_default_space_on_join,
|
|
12380
12401
|
updated_at: e.updated_at
|
|
12381
12402
|
};
|
|
12382
12403
|
}
|
|
12383
|
-
function
|
|
12404
|
+
function jh(e, t, n) {
|
|
12384
12405
|
let r = N(e, { schema: H }).select().from(xt).where(O(k(xt.coordinator_id, t), k(xt.group_id, n))).get();
|
|
12385
|
-
return r ?
|
|
12386
|
-
}
|
|
12387
|
-
function jh(e, t) {
|
|
12388
|
-
return N(e, { schema: H }).select().from(xt).where(k(xt.coordinator_id, t)).all().map(kh);
|
|
12406
|
+
return r ? Ah(r) : null;
|
|
12389
12407
|
}
|
|
12390
12408
|
function Mh(e, t) {
|
|
12409
|
+
return N(e, { schema: H }).select().from(xt).where(k(xt.coordinator_id, t)).all().map(Ah);
|
|
12410
|
+
}
|
|
12411
|
+
function Nh(e, t) {
|
|
12391
12412
|
let n = t.coordinator_id.trim(), r = t.group_id.trim();
|
|
12392
12413
|
if (!n) throw Error("coordinator_id must be a non-empty string");
|
|
12393
12414
|
if (!r) throw Error("group_id must be a non-empty string");
|
|
12394
|
-
let i = (/* @__PURE__ */ new Date()).toISOString(), a =
|
|
12395
|
-
e.prepare("INSERT INTO coordinator_group_preferences\n (coordinator_id, group_id, projects_include_json, projects_exclude_json, auto_seed_scope, updated_at)\n VALUES (?, ?, ?, ?, ?, ?)\n ON CONFLICT(coordinator_id, group_id) DO UPDATE SET\n projects_include_json = excluded.projects_include_json,\n projects_exclude_json = excluded.projects_exclude_json,\n auto_seed_scope = excluded.auto_seed_scope,\n updated_at = excluded.updated_at").run(n, r,
|
|
12396
|
-
let
|
|
12397
|
-
if (!
|
|
12398
|
-
return
|
|
12415
|
+
let i = (/* @__PURE__ */ new Date()).toISOString(), a = jh(e, n, r), o = t.projects_include === void 0 ? a?.projects_include : t.projects_include, s = t.projects_exclude === void 0 ? a?.projects_exclude : t.projects_exclude, c = t.auto_seed_scope === void 0 ? a?.auto_seed_scope ?? !0 : !!t.auto_seed_scope, l = t.default_space_scope_id === void 0 ? a?.default_space_scope_id ?? null : t.default_space_scope_id?.trim() || null, u = t.auto_grant_default_space_on_join === void 0 ? a?.auto_grant_default_space_on_join ?? !1 : !!t.auto_grant_default_space_on_join;
|
|
12416
|
+
e.prepare("INSERT INTO coordinator_group_preferences\n (coordinator_id, group_id, projects_include_json, projects_exclude_json, auto_seed_scope,\n default_space_scope_id, auto_grant_default_space_on_join, updated_at)\n VALUES (?, ?, ?, ?, ?, ?, ?, ?)\n ON CONFLICT(coordinator_id, group_id) DO UPDATE SET\n projects_include_json = excluded.projects_include_json,\n projects_exclude_json = excluded.projects_exclude_json,\n auto_seed_scope = excluded.auto_seed_scope,\n default_space_scope_id = excluded.default_space_scope_id,\n auto_grant_default_space_on_join = excluded.auto_grant_default_space_on_join,\n updated_at = excluded.updated_at").run(n, r, kh(o ?? null), kh(s ?? null), +!!c, l, +!!u, i);
|
|
12417
|
+
let d = jh(e, n, r);
|
|
12418
|
+
if (!d) throw Error("coordinator_group_preference upsert returned no row");
|
|
12419
|
+
return d;
|
|
12399
12420
|
}
|
|
12400
|
-
function
|
|
12421
|
+
function Ph(e, t, n) {
|
|
12401
12422
|
return e.prepare("DELETE FROM coordinator_group_preferences WHERE coordinator_id = ? AND group_id = ?").run(t, n).changes > 0;
|
|
12402
12423
|
}
|
|
12403
12424
|
//#endregion
|
|
12404
12425
|
//#region src/dedup-key-backfill.ts
|
|
12405
|
-
var
|
|
12406
|
-
function
|
|
12426
|
+
var Fh = "memory_dedup_key_backfill";
|
|
12427
|
+
function Ih(e) {
|
|
12407
12428
|
return op(e, { updateLimit: 1 }).backfillable > 0;
|
|
12408
12429
|
}
|
|
12409
|
-
function
|
|
12430
|
+
function Lh(e) {
|
|
12410
12431
|
return Q(e, "memory_dedup_key_backfill")?.metadata ?? {};
|
|
12411
12432
|
}
|
|
12412
|
-
async function
|
|
12413
|
-
let n = Q(e,
|
|
12433
|
+
async function Rh(e, t = {}) {
|
|
12434
|
+
let n = Q(e, Fh), r = Lh(e), i = Math.max(1, t.batchSize ?? 250), a = !n || n.status === "completed" || n.status === "failed", o = a ? 0 : Number(r.last_cursor_id ?? 0), s = op(e, {
|
|
12414
12435
|
rowLimit: i,
|
|
12415
12436
|
updateLimit: i,
|
|
12416
12437
|
afterId: o
|
|
@@ -12418,7 +12439,7 @@ async function Lh(e, t = {}) {
|
|
|
12418
12439
|
if (s.checked <= 0) {
|
|
12419
12440
|
if (n && n.status !== "completed") {
|
|
12420
12441
|
let t = Number(r.processed_updates ?? 0);
|
|
12421
|
-
Yr(e,
|
|
12442
|
+
Yr(e, Fh, {
|
|
12422
12443
|
message: Number(r.skipped_rows ?? 0) > 0 ? `No backfillable dedup keys remaining (${Number(r.skipped_rows ?? 0)} skipped)` : "Dedup-key backfill complete",
|
|
12423
12444
|
progressCurrent: t,
|
|
12424
12445
|
progressTotal: Number(r.total_backfillable ?? t),
|
|
@@ -12437,7 +12458,7 @@ async function Lh(e, t = {}) {
|
|
|
12437
12458
|
if (!n || n.status === "completed" || n.status === "failed") {
|
|
12438
12459
|
let t = op(e, { updateLimit: 1 }).backfillable;
|
|
12439
12460
|
qr(e, {
|
|
12440
|
-
kind:
|
|
12461
|
+
kind: Fh,
|
|
12441
12462
|
title: "Backfilling dedup keys",
|
|
12442
12463
|
message: `Backfilling ${t} legacy memories with dedup keys`,
|
|
12443
12464
|
progressTotal: t,
|
|
@@ -12453,8 +12474,8 @@ async function Lh(e, t = {}) {
|
|
|
12453
12474
|
}), l = t;
|
|
12454
12475
|
}
|
|
12455
12476
|
if (sp(e, s.updates), !f) {
|
|
12456
|
-
let t = Number(
|
|
12457
|
-
return Yr(e,
|
|
12477
|
+
let t = Number(Lh(e).total_backfillable ?? l ?? u);
|
|
12478
|
+
return Yr(e, Fh, {
|
|
12458
12479
|
message: d > 0 ? `Dedup-key backfill complete (${d} skipped)` : "Dedup-key backfill complete",
|
|
12459
12480
|
progressCurrent: t,
|
|
12460
12481
|
progressTotal: t,
|
|
@@ -12469,7 +12490,7 @@ async function Lh(e, t = {}) {
|
|
|
12469
12490
|
}
|
|
12470
12491
|
}), !1;
|
|
12471
12492
|
}
|
|
12472
|
-
return Jr(e,
|
|
12493
|
+
return Jr(e, Fh, {
|
|
12473
12494
|
message: `Backfilled ${u} of ${l} legacy dedup keys`,
|
|
12474
12495
|
progressCurrent: u,
|
|
12475
12496
|
progressTotal: l,
|
|
@@ -12484,7 +12505,7 @@ async function Lh(e, t = {}) {
|
|
|
12484
12505
|
}
|
|
12485
12506
|
}), !0;
|
|
12486
12507
|
}
|
|
12487
|
-
var
|
|
12508
|
+
var zh = class {
|
|
12488
12509
|
dbPath;
|
|
12489
12510
|
signal;
|
|
12490
12511
|
batchSize;
|
|
@@ -12514,14 +12535,14 @@ var Rh = class {
|
|
|
12514
12535
|
if (!this.active || this.signal?.aborted) return;
|
|
12515
12536
|
let e = null;
|
|
12516
12537
|
try {
|
|
12517
|
-
e = Mn(this.dbPath), await
|
|
12538
|
+
e = Mn(this.dbPath), await Rh(e, { batchSize: this.batchSize }) || (this.active = !1);
|
|
12518
12539
|
} catch (t) {
|
|
12519
|
-
e && Xr(e,
|
|
12540
|
+
e && Xr(e, Fh, t instanceof Error ? t.message : String(t)), console.warn("Dedup-key backfill runner failed", t);
|
|
12520
12541
|
} finally {
|
|
12521
12542
|
e?.close();
|
|
12522
12543
|
}
|
|
12523
12544
|
}
|
|
12524
|
-
},
|
|
12545
|
+
}, Bh = [
|
|
12525
12546
|
"request",
|
|
12526
12547
|
"investigated",
|
|
12527
12548
|
"learned",
|
|
@@ -12535,35 +12556,35 @@ var Rh = class {
|
|
|
12535
12556
|
"discovery_tokens",
|
|
12536
12557
|
"discovery_source"
|
|
12537
12558
|
];
|
|
12538
|
-
function
|
|
12559
|
+
function Vh() {
|
|
12539
12560
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
12540
12561
|
}
|
|
12541
|
-
function
|
|
12562
|
+
function Hh() {
|
|
12542
12563
|
return Date.now();
|
|
12543
12564
|
}
|
|
12544
|
-
function
|
|
12565
|
+
function Uh(e) {
|
|
12545
12566
|
return typeof e == "string" && e.trim() || null;
|
|
12546
12567
|
}
|
|
12547
|
-
function
|
|
12548
|
-
let t =
|
|
12568
|
+
function Wh(e) {
|
|
12569
|
+
let t = Uh(process.env.CODEMEM_DEVICE_ID);
|
|
12549
12570
|
if (t) return t;
|
|
12550
12571
|
try {
|
|
12551
|
-
return
|
|
12572
|
+
return Uh(e.prepare("SELECT device_id FROM sync_device LIMIT 1").get()?.device_id) ?? "local";
|
|
12552
12573
|
} catch {
|
|
12553
12574
|
return "local";
|
|
12554
12575
|
}
|
|
12555
12576
|
}
|
|
12556
|
-
function
|
|
12577
|
+
function Gh(e) {
|
|
12557
12578
|
return Xi(null, {
|
|
12558
12579
|
actorId: "export",
|
|
12559
|
-
deviceId:
|
|
12580
|
+
deviceId: Wh(e),
|
|
12560
12581
|
enforceScopeVisibility: !0
|
|
12561
12582
|
});
|
|
12562
12583
|
}
|
|
12563
|
-
function
|
|
12584
|
+
function Kh(e, t, n) {
|
|
12564
12585
|
return t === "local-default" ? !0 : e.prepare("SELECT 1 AS ok\n FROM replication_scopes rs\n WHERE rs.scope_id = ?\n AND rs.status = 'active'\n AND (\n rs.authority_type = 'local'\n OR EXISTS (\n SELECT 1\n FROM scope_memberships sm\n WHERE sm.scope_id = rs.scope_id\n AND sm.device_id = ?\n AND sm.status = 'active'\n AND sm.membership_epoch >= rs.membership_epoch\n )\n )\n LIMIT 1").get(t, n) != null;
|
|
12565
12586
|
}
|
|
12566
|
-
function
|
|
12587
|
+
function qh(e) {
|
|
12567
12588
|
if (typeof e != "string" || e.trim().length === 0) return null;
|
|
12568
12589
|
try {
|
|
12569
12590
|
return JSON.parse(e);
|
|
@@ -12571,12 +12592,12 @@ function Kh(e) {
|
|
|
12571
12592
|
return Un(e);
|
|
12572
12593
|
}
|
|
12573
12594
|
}
|
|
12574
|
-
function
|
|
12595
|
+
function Jh(e, t) {
|
|
12575
12596
|
let n = { ...e };
|
|
12576
|
-
for (let r of t) n[r] =
|
|
12597
|
+
for (let r of t) n[r] = qh(e[r]);
|
|
12577
12598
|
return n;
|
|
12578
12599
|
}
|
|
12579
|
-
function
|
|
12600
|
+
function Yh(e) {
|
|
12580
12601
|
if (e == null) return null;
|
|
12581
12602
|
if (typeof e == "string") try {
|
|
12582
12603
|
let t = JSON.parse(e);
|
|
@@ -12586,7 +12607,7 @@ function Jh(e) {
|
|
|
12586
12607
|
}
|
|
12587
12608
|
return typeof e == "object" && !Array.isArray(e) ? { ...e } : null;
|
|
12588
12609
|
}
|
|
12589
|
-
function
|
|
12610
|
+
function Xh(e, t, n, r) {
|
|
12590
12611
|
let i = [
|
|
12591
12612
|
e,
|
|
12592
12613
|
t,
|
|
@@ -12594,18 +12615,18 @@ function Yh(e, t, n, r) {
|
|
|
12594
12615
|
];
|
|
12595
12616
|
return r?.project && i.push(r.project), r?.createdAt && i.push(r.createdAt), r?.sourceDb && i.push(r.sourceDb), i.join("|");
|
|
12596
12617
|
}
|
|
12597
|
-
function
|
|
12598
|
-
let n =
|
|
12618
|
+
function Zh(e, t) {
|
|
12619
|
+
let n = Yh(t);
|
|
12599
12620
|
if (!n) return e;
|
|
12600
12621
|
let r = { ...e };
|
|
12601
|
-
for (let e of
|
|
12622
|
+
for (let e of Bh) {
|
|
12602
12623
|
if (!(e in n)) continue;
|
|
12603
12624
|
let t = r[e], i = !(e in r);
|
|
12604
12625
|
i ||= e === "discovery_tokens" || e === "prompt_number" ? t == null : typeof t == "string" ? t.trim().length === 0 : Array.isArray(t) ? t.length === 0 : t == null, i && (r[e] = n[e]);
|
|
12605
12626
|
}
|
|
12606
12627
|
return r.import_metadata = t, r;
|
|
12607
12628
|
}
|
|
12608
|
-
function
|
|
12629
|
+
function Qh(e) {
|
|
12609
12630
|
if (typeof e != "string") return null;
|
|
12610
12631
|
let t = e.trim();
|
|
12611
12632
|
if (!t) return null;
|
|
@@ -12615,10 +12636,10 @@ function Zh(e) {
|
|
|
12615
12636
|
}
|
|
12616
12637
|
return t;
|
|
12617
12638
|
}
|
|
12618
|
-
function
|
|
12639
|
+
function $h(e) {
|
|
12619
12640
|
return e.allProjects ? null : Ti(e.cwd ?? process.cwd(), e.project ?? null);
|
|
12620
12641
|
}
|
|
12621
|
-
function
|
|
12642
|
+
function eg(e, t, n, r, i) {
|
|
12622
12643
|
let a = "SELECT * FROM sessions", o = [], s = [];
|
|
12623
12644
|
if (t) {
|
|
12624
12645
|
let e = xi("project", t);
|
|
@@ -12626,49 +12647,49 @@ function $h(e, t, n, r, i) {
|
|
|
12626
12647
|
}
|
|
12627
12648
|
n && (s.push("started_at >= ?"), o.push(n));
|
|
12628
12649
|
let c = ["memory_items.session_id = sessions.id", ...r.clauses];
|
|
12629
|
-
return i || c.splice(1, 0, "memory_items.active = 1"), s.push(`EXISTS (SELECT 1 FROM memory_items WHERE ${c.join(" AND ")})`), o.push(...r.params), s.length > 0 && (a += ` WHERE ${s.join(" AND ")}`), a += " ORDER BY started_at ASC", e.prepare(a).all(...o).map((e) =>
|
|
12650
|
+
return i || c.splice(1, 0, "memory_items.active = 1"), s.push(`EXISTS (SELECT 1 FROM memory_items WHERE ${c.join(" AND ")})`), o.push(...r.params), s.length > 0 && (a += ` WHERE ${s.join(" AND ")}`), a += " ORDER BY started_at ASC", e.prepare(a).all(...o).map((e) => Jh(e, ["metadata_json"]));
|
|
12630
12651
|
}
|
|
12631
|
-
function
|
|
12652
|
+
function tg(e, t, n, r, i = "") {
|
|
12632
12653
|
if (n.length === 0) return [];
|
|
12633
12654
|
let a = `SELECT * FROM ${t} WHERE session_id IN (${n.map(() => "?").join(",")})${i} ORDER BY ${r}`;
|
|
12634
12655
|
return e.prepare(a).all(...n);
|
|
12635
12656
|
}
|
|
12636
|
-
function tg(e) {
|
|
12637
|
-
return Hh(e.scope_id) ?? "local-default";
|
|
12638
|
-
}
|
|
12639
12657
|
function ng(e) {
|
|
12658
|
+
return Uh(e.scope_id) ?? "local-default";
|
|
12659
|
+
}
|
|
12660
|
+
function rg(e) {
|
|
12640
12661
|
return {
|
|
12641
|
-
...
|
|
12662
|
+
...Jh(e, [
|
|
12642
12663
|
"metadata_json",
|
|
12643
12664
|
"facts",
|
|
12644
12665
|
"concepts",
|
|
12645
12666
|
"files_read",
|
|
12646
12667
|
"files_modified"
|
|
12647
12668
|
]),
|
|
12648
|
-
scope_id:
|
|
12669
|
+
scope_id: ng(e)
|
|
12649
12670
|
};
|
|
12650
12671
|
}
|
|
12651
|
-
function
|
|
12672
|
+
function ig(e, t, n, r) {
|
|
12652
12673
|
if (t.length === 0) return [];
|
|
12653
12674
|
let i = [`session_id IN (${t.map(() => "?").join(",")})`, ...n.clauses], a = [...t, ...n.params];
|
|
12654
12675
|
return r || i.push("active = 1"), e.prepare(`SELECT * FROM memory_items WHERE ${i.join(" AND ")} ORDER BY created_at ASC`).all(...a);
|
|
12655
12676
|
}
|
|
12656
|
-
function
|
|
12677
|
+
function ag(e = {}) {
|
|
12657
12678
|
let t = Mn(Dn(e.dbPath));
|
|
12658
12679
|
try {
|
|
12659
12680
|
zn(t);
|
|
12660
|
-
let n =
|
|
12681
|
+
let n = $h(e), r = {};
|
|
12661
12682
|
n && (r.project = n), e.since && (r.since = e.since);
|
|
12662
|
-
let i =
|
|
12683
|
+
let i = Gh(t), a = eg(t, n, e.since ?? null, i, !!e.includeInactive), o = a.map((e) => Number(e.id)).filter(Number.isFinite), s = ig(t, o, i, !!e.includeInactive).map((e) => rg(e)), c = tg(t, "session_summaries", o, "created_at_epoch ASC").map((e) => Jh(e, [
|
|
12663
12684
|
"metadata_json",
|
|
12664
12685
|
"files_read",
|
|
12665
12686
|
"files_edited"
|
|
12666
|
-
])), l =
|
|
12687
|
+
])), l = tg(t, "user_prompts", o, "created_at_epoch ASC").map((e) => Jh(e, ["metadata_json"])), u = /* @__PURE__ */ new Map();
|
|
12667
12688
|
for (let e of l) typeof e.id == "number" && typeof e.import_key == "string" && u.set(e.id, e.import_key);
|
|
12668
12689
|
for (let e of s) typeof e.user_prompt_id == "number" && (e.user_prompt_import_key = u.get(e.user_prompt_id) ?? null);
|
|
12669
12690
|
return {
|
|
12670
12691
|
version: "1.0",
|
|
12671
|
-
exported_at:
|
|
12692
|
+
exported_at: Vh(),
|
|
12672
12693
|
export_metadata: {
|
|
12673
12694
|
tool_version: "codemem",
|
|
12674
12695
|
projects: [...new Set(a.map((e) => String(e.project ?? "")).filter(Boolean))],
|
|
@@ -12686,28 +12707,28 @@ function ig(e = {}) {
|
|
|
12686
12707
|
t.close();
|
|
12687
12708
|
}
|
|
12688
12709
|
}
|
|
12689
|
-
function
|
|
12710
|
+
function og(e) {
|
|
12690
12711
|
let t = S(e === "-" ? 0 : Ot(e), "utf8"), n = JSON.parse(t);
|
|
12691
12712
|
if (typeof n != "object" || !n || Array.isArray(n)) throw Error("Import payload must be a JSON object");
|
|
12692
12713
|
let r = n;
|
|
12693
12714
|
if (r.version !== "1.0") throw Error(`Unsupported export version: ${String(n.version ?? "unknown")}`);
|
|
12694
12715
|
return r;
|
|
12695
12716
|
}
|
|
12696
|
-
function
|
|
12717
|
+
function sg(e, t, n) {
|
|
12697
12718
|
return e.prepare(`SELECT id FROM ${t} WHERE import_key = ? LIMIT 1`).get(n)?.id ?? null;
|
|
12698
12719
|
}
|
|
12699
|
-
function
|
|
12720
|
+
function cg() {
|
|
12700
12721
|
return process.env.USER?.trim() || process.env.USERNAME?.trim() || "import";
|
|
12701
12722
|
}
|
|
12702
|
-
function
|
|
12723
|
+
function lg(e, t) {
|
|
12703
12724
|
let n = e.insert(U).values({
|
|
12704
|
-
started_at: typeof t.started_at == "string" ? t.started_at :
|
|
12725
|
+
started_at: typeof t.started_at == "string" ? t.started_at : Vh(),
|
|
12705
12726
|
ended_at: typeof t.ended_at == "string" ? t.ended_at : null,
|
|
12706
12727
|
cwd: String(t.cwd ?? process.cwd()),
|
|
12707
12728
|
project: t.project == null ? null : String(t.project),
|
|
12708
12729
|
git_remote: t.git_remote == null ? null : String(t.git_remote),
|
|
12709
12730
|
git_branch: t.git_branch == null ? null : String(t.git_branch),
|
|
12710
|
-
user: String(t.user ??
|
|
12731
|
+
user: String(t.user ?? cg()),
|
|
12711
12732
|
tool_version: String(t.tool_version ?? "import"),
|
|
12712
12733
|
metadata_json: Z(t.metadata_json ?? null),
|
|
12713
12734
|
import_key: String(t.import_key)
|
|
@@ -12715,46 +12736,46 @@ function cg(e, t) {
|
|
|
12715
12736
|
if (n == null) throw Error("session insert returned no id");
|
|
12716
12737
|
return n;
|
|
12717
12738
|
}
|
|
12718
|
-
function
|
|
12739
|
+
function ug(e, t) {
|
|
12719
12740
|
let n = e.insert(ot).values({
|
|
12720
12741
|
session_id: Number(t.session_id),
|
|
12721
12742
|
project: t.project == null ? null : String(t.project),
|
|
12722
12743
|
prompt_text: String(t.prompt_text ?? ""),
|
|
12723
12744
|
prompt_number: t.prompt_number == null ? null : Number(t.prompt_number),
|
|
12724
|
-
created_at: typeof t.created_at == "string" ? t.created_at :
|
|
12725
|
-
created_at_epoch: typeof t.created_at_epoch == "number" ? t.created_at_epoch :
|
|
12745
|
+
created_at: typeof t.created_at == "string" ? t.created_at : Vh(),
|
|
12746
|
+
created_at_epoch: typeof t.created_at_epoch == "number" ? t.created_at_epoch : Hh(),
|
|
12726
12747
|
metadata_json: Z(t.metadata_json ?? null),
|
|
12727
12748
|
import_key: String(t.import_key)
|
|
12728
12749
|
}).returning({ id: ot.id }).all()[0]?.id;
|
|
12729
12750
|
if (n == null) throw Error("prompt insert returned no id");
|
|
12730
12751
|
return n;
|
|
12731
12752
|
}
|
|
12732
|
-
function
|
|
12733
|
-
let r =
|
|
12753
|
+
function dg(e, t, n) {
|
|
12754
|
+
let r = Uh(t.scope_id);
|
|
12734
12755
|
if (r) {
|
|
12735
|
-
if (!
|
|
12756
|
+
if (!Kh(e, r, n)) throw Error(`unauthorized_scope: ${r}`);
|
|
12736
12757
|
return r;
|
|
12737
12758
|
}
|
|
12738
12759
|
return cl(e, {
|
|
12739
12760
|
sessionId: Number(t.session_id),
|
|
12740
|
-
workspaceId:
|
|
12761
|
+
workspaceId: Uh(t.workspace_id)
|
|
12741
12762
|
});
|
|
12742
12763
|
}
|
|
12743
|
-
function
|
|
12764
|
+
function fg(e, t, n, r) {
|
|
12744
12765
|
let i = /* @__PURE__ */ new Set();
|
|
12745
12766
|
for (let a of t) {
|
|
12746
|
-
let t =
|
|
12767
|
+
let t = Uh(a.scope_id);
|
|
12747
12768
|
if (!t) continue;
|
|
12748
|
-
let o = r ??
|
|
12749
|
-
|
|
12769
|
+
let o = r ?? Qh(a.project);
|
|
12770
|
+
sg(e, "memory_items", typeof a.import_key == "string" && a.import_key.trim() ? a.import_key.trim() : Xh("export", "memory", a.id, {
|
|
12750
12771
|
project: o,
|
|
12751
12772
|
createdAt: typeof a.created_at == "string" ? a.created_at : null
|
|
12752
|
-
})) ?? (
|
|
12773
|
+
})) ?? (Kh(e, t, n) || i.add(t));
|
|
12753
12774
|
}
|
|
12754
12775
|
if (i.size > 0) throw Error(`unauthorized_scope: ${[...i].sort().join(", ")}`);
|
|
12755
12776
|
}
|
|
12756
|
-
function
|
|
12757
|
-
let i =
|
|
12777
|
+
function pg(e, t, n, r) {
|
|
12778
|
+
let i = Vh(), a = n.active == null ? 1 : Number(n.active), o = Number.isFinite(a) ? a : 1, s = typeof n.deleted_at == "string" && n.deleted_at.trim().length > 0 ? n.deleted_at : null, c = n.workspace_id == null ? null : String(n.workspace_id), l = dg(e, n, r), u = {
|
|
12758
12779
|
session_id: Number(n.session_id),
|
|
12759
12780
|
kind: String(n.kind ?? "observation"),
|
|
12760
12781
|
title: String(n.title ?? "Untitled"),
|
|
@@ -12789,7 +12810,7 @@ function fg(e, t, n, r) {
|
|
|
12789
12810
|
if (d == null) throw Error("memory insert returned no id");
|
|
12790
12811
|
return d;
|
|
12791
12812
|
}
|
|
12792
|
-
function
|
|
12813
|
+
function mg(e, t) {
|
|
12793
12814
|
let n = e.insert(st).values({
|
|
12794
12815
|
session_id: Number(t.session_id),
|
|
12795
12816
|
project: t.project == null ? null : String(t.project),
|
|
@@ -12802,20 +12823,20 @@ function pg(e, t) {
|
|
|
12802
12823
|
files_read: Gn(t.files_read),
|
|
12803
12824
|
files_edited: Gn(t.files_edited),
|
|
12804
12825
|
prompt_number: t.prompt_number == null ? null : Number(t.prompt_number),
|
|
12805
|
-
created_at: typeof t.created_at == "string" ? t.created_at :
|
|
12806
|
-
created_at_epoch: typeof t.created_at_epoch == "number" ? t.created_at_epoch :
|
|
12826
|
+
created_at: typeof t.created_at == "string" ? t.created_at : Vh(),
|
|
12827
|
+
created_at_epoch: typeof t.created_at_epoch == "number" ? t.created_at_epoch : Hh(),
|
|
12807
12828
|
metadata_json: Z(t.metadata_json ?? null),
|
|
12808
12829
|
import_key: String(t.import_key)
|
|
12809
12830
|
}).returning({ id: st.id }).all()[0]?.id;
|
|
12810
12831
|
if (n == null) throw Error("summary insert returned no id");
|
|
12811
12832
|
return n;
|
|
12812
12833
|
}
|
|
12813
|
-
function
|
|
12834
|
+
function hg(e, t = {}) {
|
|
12814
12835
|
let n = Array.isArray(e.sessions) ? e.sessions : [], r = Array.isArray(e.memory_items) ? e.memory_items : [], i = Array.isArray(e.session_summaries) ? e.session_summaries : [], a = Array.isArray(e.user_prompts) ? e.user_prompts : [], o = Mn(Dn(t.dbPath));
|
|
12815
12836
|
try {
|
|
12816
12837
|
zn(o);
|
|
12817
|
-
let e =
|
|
12818
|
-
if (
|
|
12838
|
+
let e = Wh(o);
|
|
12839
|
+
if (fg(o, r, e, t.remapProject ?? null), t.dryRun) return {
|
|
12819
12840
|
sessions: n.length,
|
|
12820
12841
|
user_prompts: a.length,
|
|
12821
12842
|
memory_items: r.length,
|
|
@@ -12826,10 +12847,10 @@ function mg(e, t = {}) {
|
|
|
12826
12847
|
return o.transaction(() => {
|
|
12827
12848
|
let c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), d = 0, f = 0, p = 0, m = 0;
|
|
12828
12849
|
for (let e of n) {
|
|
12829
|
-
let n = Number(e.id), r = t.remapProject ||
|
|
12850
|
+
let n = Number(e.id), r = t.remapProject || Qh(e.project), i = Xh("export", "session", e.id, {
|
|
12830
12851
|
project: r,
|
|
12831
12852
|
createdAt: typeof e.started_at == "string" ? e.started_at : null
|
|
12832
|
-
}), a =
|
|
12853
|
+
}), a = sg(o, "sessions", i);
|
|
12833
12854
|
if (a != null) {
|
|
12834
12855
|
c.set(n, a);
|
|
12835
12856
|
continue;
|
|
@@ -12841,7 +12862,7 @@ function mg(e, t = {}) {
|
|
|
12841
12862
|
original_ended_at: e.ended_at ?? null,
|
|
12842
12863
|
import_metadata: e.metadata_json ?? null,
|
|
12843
12864
|
import_key: i
|
|
12844
|
-
}, u =
|
|
12865
|
+
}, u = lg(s, {
|
|
12845
12866
|
...e,
|
|
12846
12867
|
project: r,
|
|
12847
12868
|
metadata_json: l,
|
|
@@ -12852,10 +12873,10 @@ function mg(e, t = {}) {
|
|
|
12852
12873
|
for (let e of a) {
|
|
12853
12874
|
let n = Number(e.session_id), r = c.get(n);
|
|
12854
12875
|
if (r == null) continue;
|
|
12855
|
-
let i = t.remapProject ||
|
|
12876
|
+
let i = t.remapProject || Qh(e.project), a = typeof e.import_key == "string" && e.import_key.trim() ? e.import_key.trim() : Xh("export", "prompt", e.id, {
|
|
12856
12877
|
project: i,
|
|
12857
12878
|
createdAt: typeof e.created_at == "string" ? e.created_at : null
|
|
12858
|
-
}), d =
|
|
12879
|
+
}), d = sg(o, "user_prompts", a);
|
|
12859
12880
|
if (d != null) {
|
|
12860
12881
|
typeof e.id == "number" && l.set(e.id, d), u.set(a, d);
|
|
12861
12882
|
continue;
|
|
@@ -12866,7 +12887,7 @@ function mg(e, t = {}) {
|
|
|
12866
12887
|
original_created_at: e.created_at ?? null,
|
|
12867
12888
|
import_metadata: e.metadata_json ?? null,
|
|
12868
12889
|
import_key: a
|
|
12869
|
-
}, m =
|
|
12890
|
+
}, m = ug(s, {
|
|
12870
12891
|
...e,
|
|
12871
12892
|
session_id: r,
|
|
12872
12893
|
project: i,
|
|
@@ -12878,13 +12899,13 @@ function mg(e, t = {}) {
|
|
|
12878
12899
|
for (let n of r) {
|
|
12879
12900
|
let r = Number(n.session_id), i = c.get(r);
|
|
12880
12901
|
if (i == null) continue;
|
|
12881
|
-
let a = t.remapProject ||
|
|
12902
|
+
let a = t.remapProject || Qh(n.project), d = typeof n.import_key == "string" && n.import_key.trim() ? n.import_key.trim() : Xh("export", "memory", n.id, {
|
|
12882
12903
|
project: a,
|
|
12883
12904
|
createdAt: typeof n.created_at == "string" ? n.created_at : null
|
|
12884
12905
|
});
|
|
12885
|
-
if (
|
|
12906
|
+
if (sg(o, "memory_items", d) != null) continue;
|
|
12886
12907
|
let f = null;
|
|
12887
|
-
typeof n.user_prompt_import_key == "string" && n.user_prompt_import_key.trim() ? f = u.get(n.user_prompt_import_key.trim()) ??
|
|
12908
|
+
typeof n.user_prompt_import_key == "string" && n.user_prompt_import_key.trim() ? f = u.get(n.user_prompt_import_key.trim()) ?? sg(o, "user_prompts", n.user_prompt_import_key.trim()) : typeof n.user_prompt_id == "number" && (f = l.get(n.user_prompt_id) ?? null);
|
|
12888
12909
|
let m = {
|
|
12889
12910
|
source: "export",
|
|
12890
12911
|
original_memory_id: n.id ?? null,
|
|
@@ -12893,8 +12914,8 @@ function mg(e, t = {}) {
|
|
|
12893
12914
|
import_key: d
|
|
12894
12915
|
};
|
|
12895
12916
|
typeof n.user_prompt_import_key == "string" && n.user_prompt_import_key.trim() && (m.user_prompt_import_key = n.user_prompt_import_key.trim());
|
|
12896
|
-
let h = n.kind === "session_summary" ?
|
|
12897
|
-
|
|
12917
|
+
let h = n.kind === "session_summary" ? Zh(m, n.metadata_json ?? null) : m;
|
|
12918
|
+
pg(o, s, {
|
|
12898
12919
|
...n,
|
|
12899
12920
|
session_id: i,
|
|
12900
12921
|
project: a,
|
|
@@ -12906,11 +12927,11 @@ function mg(e, t = {}) {
|
|
|
12906
12927
|
for (let e of i) {
|
|
12907
12928
|
let n = Number(e.session_id), r = c.get(n);
|
|
12908
12929
|
if (r == null) continue;
|
|
12909
|
-
let i = t.remapProject ||
|
|
12930
|
+
let i = t.remapProject || Qh(e.project), a = typeof e.import_key == "string" && e.import_key.trim() ? e.import_key.trim() : Xh("export", "summary", e.id, {
|
|
12910
12931
|
project: i,
|
|
12911
12932
|
createdAt: typeof e.created_at == "string" ? e.created_at : null
|
|
12912
12933
|
});
|
|
12913
|
-
if (
|
|
12934
|
+
if (sg(o, "session_summaries", a) != null) continue;
|
|
12914
12935
|
let l = {
|
|
12915
12936
|
source: "export",
|
|
12916
12937
|
original_summary_id: e.id ?? null,
|
|
@@ -12918,7 +12939,7 @@ function mg(e, t = {}) {
|
|
|
12918
12939
|
import_metadata: e.metadata_json ?? null,
|
|
12919
12940
|
import_key: a
|
|
12920
12941
|
};
|
|
12921
|
-
|
|
12942
|
+
mg(s, {
|
|
12922
12943
|
...e,
|
|
12923
12944
|
session_id: r,
|
|
12924
12945
|
project: i,
|
|
@@ -12940,7 +12961,7 @@ function mg(e, t = {}) {
|
|
|
12940
12961
|
}
|
|
12941
12962
|
//#endregion
|
|
12942
12963
|
//#region src/extraction-benchmarks.ts
|
|
12943
|
-
var
|
|
12964
|
+
var gg = [{
|
|
12944
12965
|
id: "rich-batch-shape-v1",
|
|
12945
12966
|
title: "Rich batch shape benchmark v1",
|
|
12946
12967
|
description: "Benchmark set for comparing observer models on rich-batch extraction shape. Shape-quality batches are used for observation/summary output quality. Replay-robustness batches are tracked separately and should not be counted as shape failures when the observer returns no output.",
|
|
@@ -13127,19 +13148,19 @@ var hg = [{
|
|
|
13127
13148
|
}
|
|
13128
13149
|
]
|
|
13129
13150
|
}];
|
|
13130
|
-
function
|
|
13151
|
+
function _g(e) {
|
|
13131
13152
|
let t = e.trim().toLowerCase();
|
|
13132
|
-
return
|
|
13153
|
+
return gg.find((e) => e.id === t) ?? null;
|
|
13133
13154
|
}
|
|
13134
|
-
function
|
|
13135
|
-
return
|
|
13155
|
+
function vg() {
|
|
13156
|
+
return gg.map((e) => ({
|
|
13136
13157
|
...e,
|
|
13137
13158
|
batches: e.batches.map((e) => ({ ...e }))
|
|
13138
13159
|
}));
|
|
13139
13160
|
}
|
|
13140
13161
|
//#endregion
|
|
13141
13162
|
//#region src/extraction-eval.ts
|
|
13142
|
-
var
|
|
13163
|
+
var yg = [
|
|
13143
13164
|
{
|
|
13144
13165
|
id: "simple-batch-shape",
|
|
13145
13166
|
title: "Simple batch output shape",
|
|
@@ -13250,25 +13271,25 @@ var vg = [
|
|
|
13250
13271
|
]
|
|
13251
13272
|
}
|
|
13252
13273
|
];
|
|
13253
|
-
function
|
|
13274
|
+
function bg(e) {
|
|
13254
13275
|
return e.trim().toLowerCase();
|
|
13255
13276
|
}
|
|
13256
|
-
function
|
|
13257
|
-
return
|
|
13277
|
+
function xg(e) {
|
|
13278
|
+
return bg(`${e.title}\n${e.bodyText}`);
|
|
13258
13279
|
}
|
|
13259
|
-
function
|
|
13260
|
-
let n =
|
|
13261
|
-
return t.keywords.some((e) => n.includes(
|
|
13280
|
+
function Sg(e, t) {
|
|
13281
|
+
let n = xg(e);
|
|
13282
|
+
return t.keywords.some((e) => n.includes(bg(e)));
|
|
13262
13283
|
}
|
|
13263
|
-
function
|
|
13284
|
+
function Cg(e, t, n, r) {
|
|
13264
13285
|
let i = [];
|
|
13265
13286
|
return r.summaryCountInRange || i.push(`summary count ${t.summaries} outside expected range ${e.summaryCountRange.min}-${e.summaryCountRange.max}`), r.observationCountInRange || i.push(`observation count ${t.observations} outside expected range ${e.observationCountRange.min}-${e.observationCountRange.max}`), n.summaryThreadCoverage < e.minSummaryThreadCoverage && i.push(`summary thread coverage ${n.summaryThreadCoverage} below required minimum ${e.minSummaryThreadCoverage}`), n.observationThreadCoverage < e.minObservationThreadCoverage && i.push(`observation thread coverage ${n.observationThreadCoverage} below required minimum ${e.minObservationThreadCoverage}`), n.totalThreadCoverage < e.minTotalThreadCoverage && i.push(`total thread coverage ${n.totalThreadCoverage} below required minimum ${e.minTotalThreadCoverage}`), n.duplicateObservationThreads > 1 && i.push(`duplicate observation thread matches ${n.duplicateObservationThreads} exceed tolerated maximum 1`), i;
|
|
13266
13287
|
}
|
|
13267
|
-
function
|
|
13268
|
-
let t =
|
|
13269
|
-
return
|
|
13288
|
+
function wg(e) {
|
|
13289
|
+
let t = bg(e);
|
|
13290
|
+
return yg.find((e) => e.id === t) ?? null;
|
|
13270
13291
|
}
|
|
13271
|
-
function
|
|
13292
|
+
function Tg(e, t, n, r) {
|
|
13272
13293
|
let i = n.map((e) => ({
|
|
13273
13294
|
...e,
|
|
13274
13295
|
summaryLike: fi({
|
|
@@ -13276,7 +13297,7 @@ function wg(e, t, n, r) {
|
|
|
13276
13297
|
metadata: e.metadata
|
|
13277
13298
|
})
|
|
13278
13299
|
})), a = i.filter((e) => e.summaryLike), o = i.filter((e) => !e.summaryLike), s = r.threads.map((e) => {
|
|
13279
|
-
let t = a.filter((t) =>
|
|
13300
|
+
let t = a.filter((t) => Sg(t, e)).map((e) => e.id), n = o.filter((t) => Sg(t, e)).map((e) => e.id);
|
|
13280
13301
|
return {
|
|
13281
13302
|
id: e.id,
|
|
13282
13303
|
title: e.title,
|
|
@@ -13297,7 +13318,7 @@ function wg(e, t, n, r) {
|
|
|
13297
13318
|
}, u = {
|
|
13298
13319
|
summaryCountInRange: c.summaries >= r.summaryCountRange.min && c.summaries <= r.summaryCountRange.max,
|
|
13299
13320
|
observationCountInRange: c.observations >= r.observationCountRange.min && c.observations <= r.observationCountRange.max
|
|
13300
|
-
}, d =
|
|
13321
|
+
}, d = Cg(r, c, l, u);
|
|
13301
13322
|
return {
|
|
13302
13323
|
scenario: {
|
|
13303
13324
|
id: r.id,
|
|
@@ -13319,8 +13340,8 @@ function wg(e, t, n, r) {
|
|
|
13319
13340
|
items: i
|
|
13320
13341
|
};
|
|
13321
13342
|
}
|
|
13322
|
-
function
|
|
13323
|
-
let n =
|
|
13343
|
+
function Eg(e, t) {
|
|
13344
|
+
let n = wg(t.scenarioId);
|
|
13324
13345
|
if (!n) throw Error(`Unknown session extraction eval scenario: ${t.scenarioId}`);
|
|
13325
13346
|
let r = Mn(Dn(e));
|
|
13326
13347
|
try {
|
|
@@ -13347,7 +13368,7 @@ function Tg(e, t) {
|
|
|
13347
13368
|
createdAt: e.created_at,
|
|
13348
13369
|
metadata: e.metadata_json
|
|
13349
13370
|
}));
|
|
13350
|
-
return
|
|
13371
|
+
return Tg("batchId" in t && typeof t.batchId == "number" ? {
|
|
13351
13372
|
type: "batch",
|
|
13352
13373
|
sessionId: i,
|
|
13353
13374
|
batchId: t.batchId
|
|
@@ -13361,11 +13382,11 @@ function Tg(e, t) {
|
|
|
13361
13382
|
}
|
|
13362
13383
|
//#endregion
|
|
13363
13384
|
//#region src/extraction-tier-routing.ts
|
|
13364
|
-
var
|
|
13385
|
+
var Dg = {
|
|
13365
13386
|
observerProvider: "openai",
|
|
13366
13387
|
observerModel: "gpt-5.4-mini",
|
|
13367
13388
|
observerTemperature: .2
|
|
13368
|
-
},
|
|
13389
|
+
}, Og = {
|
|
13369
13390
|
observerProvider: "openai",
|
|
13370
13391
|
observerModel: "gpt-5.4",
|
|
13371
13392
|
observerTemperature: .2,
|
|
@@ -13373,53 +13394,53 @@ var Eg = {
|
|
|
13373
13394
|
observerReasoningEffort: null,
|
|
13374
13395
|
observerReasoningSummary: null,
|
|
13375
13396
|
observerMaxOutputTokens: 12e3
|
|
13376
|
-
},
|
|
13397
|
+
}, kg = {
|
|
13377
13398
|
observerProvider: "anthropic",
|
|
13378
13399
|
observerModel: "claude-haiku-4-5",
|
|
13379
13400
|
observerTemperature: .2
|
|
13380
|
-
},
|
|
13401
|
+
}, Ag = {
|
|
13381
13402
|
observerProvider: "anthropic",
|
|
13382
13403
|
observerModel: "claude-sonnet-4-6",
|
|
13383
13404
|
observerTemperature: .2,
|
|
13384
13405
|
observerMaxOutputTokens: 12e3
|
|
13385
13406
|
};
|
|
13386
|
-
function
|
|
13407
|
+
function jg(e) {
|
|
13387
13408
|
if (!e) return null;
|
|
13388
13409
|
let t = e.toLowerCase();
|
|
13389
13410
|
return t === "openai" ? "openai" : t === "anthropic" ? "anthropic" : null;
|
|
13390
13411
|
}
|
|
13391
|
-
function
|
|
13412
|
+
function Mg(e) {
|
|
13392
13413
|
if (typeof e != "string") return null;
|
|
13393
13414
|
let t = e.trim();
|
|
13394
13415
|
return t ? t.toLowerCase() : null;
|
|
13395
13416
|
}
|
|
13396
|
-
function Mg(e) {
|
|
13397
|
-
return e === "anthropic" ? Og : Eg;
|
|
13398
|
-
}
|
|
13399
13417
|
function Ng(e) {
|
|
13400
13418
|
return e === "anthropic" ? kg : Dg;
|
|
13401
13419
|
}
|
|
13402
13420
|
function Pg(e) {
|
|
13403
|
-
return
|
|
13421
|
+
return e === "anthropic" ? Ag : Og;
|
|
13404
13422
|
}
|
|
13405
13423
|
function Fg(e) {
|
|
13424
|
+
return typeof e == "string" && e.trim().toLowerCase() === "claude_sidecar" ? "claude_sidecar" : "api_http";
|
|
13425
|
+
}
|
|
13426
|
+
function Ig(e) {
|
|
13406
13427
|
return e === void 0 ? null : e;
|
|
13407
13428
|
}
|
|
13408
|
-
function
|
|
13429
|
+
function Lg(e, t, n = null) {
|
|
13409
13430
|
return {
|
|
13410
13431
|
requestedTier: e.tier,
|
|
13411
13432
|
requestedProvider: t.observerProvider ?? null,
|
|
13412
13433
|
requestedModel: t.observerModel ?? null,
|
|
13413
13434
|
requestedRuntime: t.observerRuntime ?? null,
|
|
13414
|
-
requestedOpenAIResponses:
|
|
13435
|
+
requestedOpenAIResponses: Ig(t.observerOpenAIUseResponses),
|
|
13415
13436
|
fallbackApplied: n != null,
|
|
13416
13437
|
fallbackReason: n
|
|
13417
13438
|
};
|
|
13418
13439
|
}
|
|
13419
|
-
function
|
|
13420
|
-
let n =
|
|
13440
|
+
function Rg(e, t) {
|
|
13441
|
+
let n = Fg(e.observerRuntime), r = new Set(e.observerExplicitConfigKeys ?? []);
|
|
13421
13442
|
if (n === "claude_sidecar") {
|
|
13422
|
-
let i = t.tier === "simple" ? "observerSimpleProvider" : "observerRichProvider", a = r.has(i) || r.has("observerProvider"), o =
|
|
13443
|
+
let i = t.tier === "simple" ? "observerSimpleProvider" : "observerRichProvider", a = r.has(i) || r.has("observerProvider"), o = Mg(i === "observerSimpleProvider" ? e.observerSimpleProvider : e.observerRichProvider) ?? Mg(e.observerProvider), s = t.tier === "simple" ? kg : Ag, c = {
|
|
13423
13444
|
...e,
|
|
13424
13445
|
observerProvider: "anthropic",
|
|
13425
13446
|
observerModel: t.tier === "simple" ? e.observerSimpleModel ?? s.observerModel ?? e.observerModel : e.observerRichModel ?? s.observerModel ?? e.observerModel,
|
|
@@ -13431,7 +13452,7 @@ function Lg(e, t) {
|
|
|
13431
13452
|
}, l = a && o && o !== "anthropic" ? "unsupported tier override for runtime" : null;
|
|
13432
13453
|
return {
|
|
13433
13454
|
observer: c,
|
|
13434
|
-
metadata:
|
|
13455
|
+
metadata: Lg(t, {
|
|
13435
13456
|
...c,
|
|
13436
13457
|
observerProvider: o ?? c.observerProvider,
|
|
13437
13458
|
observerRuntime: n
|
|
@@ -13439,9 +13460,9 @@ function Lg(e, t) {
|
|
|
13439
13460
|
};
|
|
13440
13461
|
}
|
|
13441
13462
|
if (t.tier === "simple") {
|
|
13442
|
-
let i =
|
|
13463
|
+
let i = jg(e.observerSimpleProvider) ?? jg(e.observerProvider);
|
|
13443
13464
|
if (i) {
|
|
13444
|
-
let a =
|
|
13465
|
+
let a = Ng(i), o = r.has("observerOpenAIUseResponses"), s = {
|
|
13445
13466
|
...e,
|
|
13446
13467
|
observerProvider: i,
|
|
13447
13468
|
observerModel: e.observerSimpleModel ?? a.observerModel ?? e.observerModel,
|
|
@@ -13453,13 +13474,13 @@ function Lg(e, t) {
|
|
|
13453
13474
|
};
|
|
13454
13475
|
return {
|
|
13455
13476
|
observer: s,
|
|
13456
|
-
metadata:
|
|
13477
|
+
metadata: Lg(t, {
|
|
13457
13478
|
...s,
|
|
13458
13479
|
observerRuntime: n
|
|
13459
13480
|
})
|
|
13460
13481
|
};
|
|
13461
13482
|
}
|
|
13462
|
-
let a =
|
|
13483
|
+
let a = Mg(e.observerSimpleProvider) ?? e.observerProvider ?? null, o = {
|
|
13463
13484
|
...e,
|
|
13464
13485
|
observerProvider: a,
|
|
13465
13486
|
observerModel: e.observerSimpleModel ?? e.observerModel,
|
|
@@ -13471,15 +13492,15 @@ function Lg(e, t) {
|
|
|
13471
13492
|
};
|
|
13472
13493
|
return {
|
|
13473
13494
|
observer: o,
|
|
13474
|
-
metadata:
|
|
13495
|
+
metadata: Lg(t, {
|
|
13475
13496
|
...o,
|
|
13476
13497
|
observerRuntime: n
|
|
13477
13498
|
})
|
|
13478
13499
|
};
|
|
13479
13500
|
}
|
|
13480
|
-
let i =
|
|
13501
|
+
let i = jg(e.observerRichProvider) ?? jg(e.observerProvider);
|
|
13481
13502
|
if (i) {
|
|
13482
|
-
let r =
|
|
13503
|
+
let r = Pg(i), a = i === "openai", o = {
|
|
13483
13504
|
...e,
|
|
13484
13505
|
observerProvider: i,
|
|
13485
13506
|
observerModel: e.observerRichModel ?? r.observerModel ?? e.observerModel,
|
|
@@ -13491,13 +13512,13 @@ function Lg(e, t) {
|
|
|
13491
13512
|
};
|
|
13492
13513
|
return {
|
|
13493
13514
|
observer: o,
|
|
13494
|
-
metadata:
|
|
13515
|
+
metadata: Lg(t, {
|
|
13495
13516
|
...o,
|
|
13496
13517
|
observerRuntime: n
|
|
13497
13518
|
})
|
|
13498
13519
|
};
|
|
13499
13520
|
}
|
|
13500
|
-
let a =
|
|
13521
|
+
let a = Mg(e.observerRichProvider) ?? e.observerProvider ?? null, o = {
|
|
13501
13522
|
...e,
|
|
13502
13523
|
observerProvider: a,
|
|
13503
13524
|
observerModel: e.observerRichModel ?? e.observerModel,
|
|
@@ -13509,32 +13530,32 @@ function Lg(e, t) {
|
|
|
13509
13530
|
};
|
|
13510
13531
|
return {
|
|
13511
13532
|
observer: o,
|
|
13512
|
-
metadata:
|
|
13533
|
+
metadata: Lg(t, {
|
|
13513
13534
|
...o,
|
|
13514
13535
|
observerRuntime: n
|
|
13515
13536
|
})
|
|
13516
13537
|
};
|
|
13517
13538
|
}
|
|
13518
|
-
function
|
|
13539
|
+
function zg(e) {
|
|
13519
13540
|
let t = [];
|
|
13520
13541
|
return e.eventSpan >= 100 && t.push(`event_span=${e.eventSpan}`), e.transcriptLength >= 6e3 && t.push(`transcript_length=${e.transcriptLength}`), e.toolCount >= 25 && t.push(`tool_count=${e.toolCount}`), e.toolCount >= 9 && e.transcriptLength >= 2e3 && t.push(`tool_count=${e.toolCount}+transcript_length=${e.transcriptLength}`), e.promptCount >= 3 && e.toolCount >= 8 && t.push(`prompt_count=${e.promptCount}+tool_count=${e.toolCount}`), t.length > 0 ? {
|
|
13521
13542
|
tier: "rich",
|
|
13522
13543
|
reasons: t,
|
|
13523
|
-
observer: { ...
|
|
13544
|
+
observer: { ...Og }
|
|
13524
13545
|
} : {
|
|
13525
13546
|
tier: "simple",
|
|
13526
13547
|
reasons: ["fell below rich-batch thresholds"],
|
|
13527
|
-
observer: { ...
|
|
13548
|
+
observer: { ...Dg }
|
|
13528
13549
|
};
|
|
13529
13550
|
}
|
|
13530
13551
|
//#endregion
|
|
13531
13552
|
//#region src/ingest-sanitize.ts
|
|
13532
|
-
var
|
|
13533
|
-
function
|
|
13553
|
+
var Bg = "<private>", Vg = "</private>";
|
|
13554
|
+
function Hg(e) {
|
|
13534
13555
|
if (!e) return "";
|
|
13535
13556
|
let t = e, n = t.toLowerCase(), r = "";
|
|
13536
13557
|
for (; t;) {
|
|
13537
|
-
let e = n.indexOf(
|
|
13558
|
+
let e = n.indexOf(Bg), i = n.indexOf(Vg);
|
|
13538
13559
|
if (e < 0) {
|
|
13539
13560
|
if (i < 0) return r + t;
|
|
13540
13561
|
r += t.slice(0, i), t = t.slice(i + 10), n = t.toLowerCase();
|
|
@@ -13545,14 +13566,14 @@ function Vg(e) {
|
|
|
13545
13566
|
continue;
|
|
13546
13567
|
}
|
|
13547
13568
|
r += t.slice(0, e);
|
|
13548
|
-
let a = n.indexOf(
|
|
13569
|
+
let a = n.indexOf(Vg, e + 9);
|
|
13549
13570
|
if (a < 0) return r;
|
|
13550
13571
|
t = t.slice(a + 10), n = t.toLowerCase();
|
|
13551
13572
|
}
|
|
13552
13573
|
return r;
|
|
13553
13574
|
}
|
|
13554
|
-
var
|
|
13555
|
-
function
|
|
13575
|
+
var Ug = "[REDACTED]";
|
|
13576
|
+
function Wg(e) {
|
|
13556
13577
|
let t = [], n = "";
|
|
13557
13578
|
for (let r of e) if (r === "_" || r === "-") {
|
|
13558
13579
|
let e = n.trim();
|
|
@@ -13561,11 +13582,11 @@ function Ug(e) {
|
|
|
13561
13582
|
let r = n.trim();
|
|
13562
13583
|
return r && t.push(r), t;
|
|
13563
13584
|
}
|
|
13564
|
-
function
|
|
13585
|
+
function Gg(e) {
|
|
13565
13586
|
let t = e.trim().toLowerCase();
|
|
13566
13587
|
if (!t) return !1;
|
|
13567
13588
|
if (t.includes("apikey") || t.includes("privatekey")) return !0;
|
|
13568
|
-
let n =
|
|
13589
|
+
let n = Wg(t);
|
|
13569
13590
|
return n.some((e) => [
|
|
13570
13591
|
"token",
|
|
13571
13592
|
"secret",
|
|
@@ -13575,33 +13596,33 @@ function Wg(e) {
|
|
|
13575
13596
|
"cookie"
|
|
13576
13597
|
].includes(e)) ? !0 : n.length >= 2 && (n.includes("api") && n.includes("key") || n.includes("private") && n.includes("key"));
|
|
13577
13598
|
}
|
|
13578
|
-
function
|
|
13579
|
-
if (typeof e == "string") return
|
|
13580
|
-
if (Array.isArray(e)) return e.map(
|
|
13599
|
+
function Kg(e) {
|
|
13600
|
+
if (typeof e == "string") return Hg(e);
|
|
13601
|
+
if (Array.isArray(e)) return e.map(Kg);
|
|
13581
13602
|
if (typeof e == "object" && e) {
|
|
13582
13603
|
let t = {};
|
|
13583
|
-
for (let [n, r] of Object.entries(e))
|
|
13604
|
+
for (let [n, r] of Object.entries(e)) Gg(n) ? t[n] = Ug : t[n] = Kg(r);
|
|
13584
13605
|
return t;
|
|
13585
13606
|
}
|
|
13586
13607
|
return e;
|
|
13587
13608
|
}
|
|
13588
|
-
function
|
|
13609
|
+
function qg(e, t) {
|
|
13589
13610
|
return t <= 0 ? "" : e.length <= t ? e : `${e.slice(0, t)}... (truncated)`;
|
|
13590
13611
|
}
|
|
13591
|
-
function
|
|
13612
|
+
function Jg(e, t) {
|
|
13592
13613
|
if (e == null) return null;
|
|
13593
|
-
if (typeof e == "string") return
|
|
13594
|
-
let n =
|
|
13614
|
+
if (typeof e == "string") return qg(Hg(e), t);
|
|
13615
|
+
let n = Kg(e);
|
|
13595
13616
|
try {
|
|
13596
13617
|
let e = JSON.stringify(n);
|
|
13597
|
-
if (t > 0 && e.length > t) return
|
|
13618
|
+
if (t > 0 && e.length > t) return qg(e, t);
|
|
13598
13619
|
} catch {
|
|
13599
13620
|
let e = String(n);
|
|
13600
|
-
if (t > 0 && e.length > t) return
|
|
13621
|
+
if (t > 0 && e.length > t) return qg(e, t);
|
|
13601
13622
|
}
|
|
13602
13623
|
return n;
|
|
13603
13624
|
}
|
|
13604
|
-
var
|
|
13625
|
+
var Yg = new Set([
|
|
13605
13626
|
"wrote file successfully.",
|
|
13606
13627
|
"wrote file successfully",
|
|
13607
13628
|
"file written successfully.",
|
|
@@ -13610,19 +13631,19 @@ var Jg = new Set([
|
|
|
13610
13631
|
"<file>",
|
|
13611
13632
|
"<image>"
|
|
13612
13633
|
]);
|
|
13613
|
-
function
|
|
13634
|
+
function Xg(e) {
|
|
13614
13635
|
if (!e) return !0;
|
|
13615
13636
|
let t = e.split("\n").map((e) => e.trim()).filter(Boolean);
|
|
13616
|
-
return t.length === 0 ? !0 : t.every((e) =>
|
|
13637
|
+
return t.length === 0 ? !0 : t.every((e) => Yg.has(e.toLowerCase()));
|
|
13617
13638
|
}
|
|
13618
|
-
function
|
|
13639
|
+
function Zg(e, t, n) {
|
|
13619
13640
|
if (t == null) return null;
|
|
13620
|
-
let r =
|
|
13621
|
-
return
|
|
13641
|
+
let r = Jg(t, n);
|
|
13642
|
+
return Xg(String(r ?? "")) ? "" : r;
|
|
13622
13643
|
}
|
|
13623
13644
|
//#endregion
|
|
13624
13645
|
//#region src/ingest-events.ts
|
|
13625
|
-
var
|
|
13646
|
+
var Qg = new Set([
|
|
13626
13647
|
"tui",
|
|
13627
13648
|
"shell",
|
|
13628
13649
|
"cmd",
|
|
@@ -13632,48 +13653,48 @@ var Zg = new Set([
|
|
|
13632
13653
|
"todowrite",
|
|
13633
13654
|
"askuserquestion"
|
|
13634
13655
|
]);
|
|
13635
|
-
function
|
|
13656
|
+
function $g(e) {
|
|
13636
13657
|
return e.startsWith("codemem_memory_");
|
|
13637
13658
|
}
|
|
13638
|
-
function
|
|
13659
|
+
function e_(e) {
|
|
13639
13660
|
let t = String(e.tool ?? e.type ?? "tool").toLowerCase();
|
|
13640
13661
|
return t.includes(".") && (t = t.split(".").pop() ?? t), t.includes(":") && (t = t.split(":").pop() ?? t), t;
|
|
13641
13662
|
}
|
|
13642
|
-
function
|
|
13663
|
+
function t_(e, t = 80, n = 2e3) {
|
|
13643
13664
|
if (!e) return "";
|
|
13644
13665
|
let r = e.split("\n"), i = r;
|
|
13645
13666
|
i.length > t && (i = [...i.slice(0, t), `... (+${r.length - t} more lines)`]);
|
|
13646
13667
|
let a = i.join("\n");
|
|
13647
13668
|
return n > 0 && a.length > n && (a = `${a.slice(0, n)}\n... (truncated)`), a;
|
|
13648
13669
|
}
|
|
13649
|
-
function
|
|
13650
|
-
return
|
|
13670
|
+
function n_(e) {
|
|
13671
|
+
return t_(e, 120, 2400);
|
|
13651
13672
|
}
|
|
13652
|
-
function
|
|
13673
|
+
function r_(e, t, n = Qg) {
|
|
13653
13674
|
if (e.type !== "tool.execute.after") return null;
|
|
13654
|
-
let r =
|
|
13655
|
-
if (
|
|
13656
|
-
let i = e.args, a = typeof i == "object" && i && !Array.isArray(i) ? i : {}, o =
|
|
13657
|
-
r === "read" && typeof o == "string" && (o =
|
|
13658
|
-
let s =
|
|
13675
|
+
let r = e_(e);
|
|
13676
|
+
if ($g(r) || n.has(r)) return null;
|
|
13677
|
+
let i = e.args, a = typeof i == "object" && i && !Array.isArray(i) ? i : {}, o = Zg(r, e.result, t);
|
|
13678
|
+
r === "read" && typeof o == "string" && (o = t_(o)), r === "bash" && typeof o == "string" && (o = t_(o)), (r === "glob" || r === "grep") && typeof o == "string" && (o = n_(o));
|
|
13679
|
+
let s = Jg(e.error, t);
|
|
13659
13680
|
return {
|
|
13660
13681
|
toolName: r,
|
|
13661
|
-
toolInput:
|
|
13682
|
+
toolInput: Jg(a, t),
|
|
13662
13683
|
toolOutput: o,
|
|
13663
13684
|
toolError: s,
|
|
13664
13685
|
timestamp: typeof e.timestamp == "string" ? e.timestamp : null,
|
|
13665
13686
|
cwd: (typeof e.cwd == "string" ? e.cwd : null) ?? (typeof a.cwd == "string" ? a.cwd : null)
|
|
13666
13687
|
};
|
|
13667
13688
|
}
|
|
13668
|
-
function
|
|
13689
|
+
function i_(e, t) {
|
|
13669
13690
|
let n = [];
|
|
13670
13691
|
for (let r of e) {
|
|
13671
|
-
let e =
|
|
13692
|
+
let e = r_(r, t);
|
|
13672
13693
|
e && n.push(e);
|
|
13673
13694
|
}
|
|
13674
13695
|
return n;
|
|
13675
13696
|
}
|
|
13676
|
-
function
|
|
13697
|
+
function a_(e) {
|
|
13677
13698
|
let t = e._adapter;
|
|
13678
13699
|
if (typeof t != "object" || !t || Array.isArray(t)) return null;
|
|
13679
13700
|
let n = t;
|
|
@@ -13696,7 +13717,7 @@ function i_(e) {
|
|
|
13696
13717
|
}
|
|
13697
13718
|
return n;
|
|
13698
13719
|
}
|
|
13699
|
-
function
|
|
13720
|
+
function o_(e, t) {
|
|
13700
13721
|
let n = String(e.event_type ?? ""), r = e.payload;
|
|
13701
13722
|
if (!r || typeof r != "object" || n !== "tool_result") return null;
|
|
13702
13723
|
let i = r.tool_input;
|
|
@@ -13714,7 +13735,7 @@ function a_(e, t) {
|
|
|
13714
13735
|
cwd: t.cwd
|
|
13715
13736
|
};
|
|
13716
13737
|
}
|
|
13717
|
-
function
|
|
13738
|
+
function s_(e) {
|
|
13718
13739
|
if (e.toolName === "bash" && e.toolInput != null && typeof e.toolInput == "object") {
|
|
13719
13740
|
let t = e.toolInput, n = String(t.command ?? "").trim().toLowerCase();
|
|
13720
13741
|
if ((n === "git status" || n === "git diff") && !e.toolError) return `bash:${n}`;
|
|
@@ -13727,26 +13748,26 @@ function o_(e) {
|
|
|
13727
13748
|
}
|
|
13728
13749
|
return e.toolError && t.push(String(e.toolError).slice(0, 200)), typeof e.toolOutput == "string" && e.toolOutput && t.push(e.toolOutput.slice(0, 200)), t.join("|");
|
|
13729
13750
|
}
|
|
13730
|
-
function
|
|
13751
|
+
function c_(e) {
|
|
13731
13752
|
let t = 0;
|
|
13732
13753
|
e.toolError && (t += 100);
|
|
13733
13754
|
let n = (e.toolName || "").toLowerCase();
|
|
13734
13755
|
return n === "edit" || n === "write" ? t += 50 : n === "bash" ? t += 30 : n === "read" ? t += 20 : t += 10, t;
|
|
13735
13756
|
}
|
|
13736
|
-
function
|
|
13757
|
+
function l_(e) {
|
|
13737
13758
|
try {
|
|
13738
13759
|
return JSON.stringify(e).length;
|
|
13739
13760
|
} catch {
|
|
13740
13761
|
return String(e).length;
|
|
13741
13762
|
}
|
|
13742
13763
|
}
|
|
13743
|
-
function
|
|
13764
|
+
function u_(e, t, n) {
|
|
13744
13765
|
if (!e.length || t <= 0 || n <= 0) return [];
|
|
13745
13766
|
let r = /* @__PURE__ */ new Set(), i = [];
|
|
13746
13767
|
for (let t = e.length - 1; t >= 0; t--) {
|
|
13747
13768
|
let n = e[t];
|
|
13748
13769
|
if (!n) continue;
|
|
13749
|
-
let a =
|
|
13770
|
+
let a = s_(n);
|
|
13750
13771
|
r.has(a) || (r.add(a), i.push(n));
|
|
13751
13772
|
}
|
|
13752
13773
|
i.reverse();
|
|
@@ -13757,32 +13778,32 @@ function l_(e, t, n) {
|
|
|
13757
13778
|
idx: t
|
|
13758
13779
|
}));
|
|
13759
13780
|
e.sort((e, t) => {
|
|
13760
|
-
let n =
|
|
13781
|
+
let n = c_(t.event) - c_(e.event);
|
|
13761
13782
|
return n === 0 ? e.idx - t.idx : n;
|
|
13762
13783
|
});
|
|
13763
13784
|
let t = new Set(e.slice(0, n).map((e) => e.idx));
|
|
13764
13785
|
a = a.filter((e, n) => t.has(n));
|
|
13765
13786
|
}
|
|
13766
|
-
if (a.reduce((e, t) => e +
|
|
13787
|
+
if (a.reduce((e, t) => e + l_(t), 0) <= t) return a;
|
|
13767
13788
|
let o = a.map((e, t) => ({
|
|
13768
13789
|
event: e,
|
|
13769
13790
|
idx: t
|
|
13770
13791
|
}));
|
|
13771
13792
|
o.sort((e, t) => {
|
|
13772
|
-
let n =
|
|
13793
|
+
let n = c_(t.event) - c_(e.event);
|
|
13773
13794
|
return n === 0 ? e.idx - t.idx : n;
|
|
13774
13795
|
});
|
|
13775
13796
|
let s = [], c = 0;
|
|
13776
13797
|
for (let e of o) {
|
|
13777
|
-
let n =
|
|
13798
|
+
let n = l_(e.event);
|
|
13778
13799
|
if (!(c + n > t && s.length > 0) && (s.push(e), c += n, c >= t)) break;
|
|
13779
13800
|
}
|
|
13780
13801
|
return s.sort((e, t) => e.idx - t.idx), s.map((e) => e.event);
|
|
13781
13802
|
}
|
|
13782
13803
|
//#endregion
|
|
13783
13804
|
//#region src/ingest-prompts.ts
|
|
13784
|
-
var
|
|
13785
|
-
<type>[ ${
|
|
13805
|
+
var d_ = "bugfix, feature, refactor, change, discovery, decision, exploration", f_ = "You are a memory observer creating searchable records of development work FOR FUTURE SESSIONS. Record what was BUILT/FIXED/DEPLOYED/CONFIGURED/LEARNED, not what you (the observer) are doing. These memories help developers recall past work, decisions, learnings, and investigations.", p_ = "Focus on deliverables, capabilities, AND learnings:\n- What the system NOW DOES differently (new capabilities)\n- What shipped to users/production (features, fixes, configs, docs)\n- What was LEARNED through debugging, investigation, or testing\n- How systems work and why they behave the way they do\n- Changes in technical domains (auth, data, UI, infra, DevOps)\n\nUse outcome-focused verbs: implemented, fixed, deployed, configured, migrated, optimized, added, refactored, discovered, learned, debugged.\nOnly describe actions that are clearly supported by the observed context.\nNever invent file changes, API behavior, or code edits that are not explicitly present in the session evidence.\n\nGOOD examples (describes what was built or learned):\n- \"Authentication now supports OAuth2 with PKCE flow\"\n- \"Deployment pipeline runs canary releases with auto-rollback\"\n- \"Fixed race condition in session handler causing duplicate events\"\n- \"Discovered flush timing strategy needed adaptation for multi-session environment\"\n- \"Learned transcript building was broken - empty strings passed instead of conversation\"\n\nBAD examples (describes observation process - DO NOT DO THIS):\n- \"Analyzed authentication implementation and stored findings in database\"\n- \"Tracked deployment steps and logged outcomes to memory system\"\n- \"Recorded investigation results for later reference\"", m_ = "Skip routine operations WITHOUT learnings:\n- Empty status checks or listings (unless revealing important state)\n- Package installations with no errors or insights\n- Simple file reads with no discoveries\n- Repetitive operations already documented with no new findings\nIf nothing meaningful happened AND nothing was learned:\n- Output no <observation> blocks\n- Output <skip_summary reason=\"low-signal\"/> instead of a <summary> block.", h_ = "Create narratives that tell the complete story:\n- Context: What was the problem or goal? What prompted this work?\n- Investigation: What was examined? What was discovered?\n- Learning: How does it work? Why does it exist? Any gotchas?\n- Implementation: What was changed? What does the code do now?\n- Impact: What's better? What does the system do differently?\n- Next steps: What remains? What should future sessions know?\n\nAim for ~120-400 words per significant work item.\nPrefer fewer, higher-signal observations over many small ones.\nInclude specific details when present: file paths, function names, configuration values.", g_ = "When the session contains MULTIPLE meaningful threads:\n- Before writing XML, mentally inventory the 2-4 highest-value subthreads that future sessions would most want for rediscovery reduction.\n- Treat the <summary> as the broad session-wide state, not a recap of only the latest thread.\n- Cover the major subthreads in the summary when they materially changed the direction, outcome, or understanding of the work.\n- Do not let recency dominate: a long transcript often ends on only one thread, but the output should still represent the major work across the full observed batch.\n- Emit a SMALL capped set of durable <observation> blocks for the highest-value reusable subthreads (usually 2-4, not a dump of everything).\n- If the session clearly contains 2 or more substantial durable subthreads, emit at least 2 <observation> blocks. Summary-only output is not sufficient for a rich session.\n- Prefer one durable observation per distinct subthread, not several observations for one thread and silence for the others.\n- Prefer coverage diversity: do not emit multiple observations that mostly restate the same dominant thread.\n- Choose subthreads that future sessions would most want for rediscovery reduction: important decisions, durable learnings, shipped changes, closed investigations, or troubleshooting outcomes.\n- If one thread clearly dominates and the rest are trivial, keep a single observation. Do not invent diversity where none exists.", __ = "Output only XML. Do not include commentary outside XML.\n\nALWAYS emit at least one <observation> block for any meaningful work. Observations are the PRIMARY output - they capture what was built, fixed, learned, or decided. Also emit a <summary> block to track session progress.\n\nFor rich multi-thread sessions, prefer one broad summary plus a small set of durable observations covering the highest-value subthreads.\n\nFor rich sessions, do not return summary-only output when multiple substantial durable subthreads are present.\n\nDo not collapse a rich batch into only the final or most recent thread when earlier threads produced durable decisions, learnings, or outcomes.\n\nPrefer fewer, more comprehensive observations over many small ones.", v_ = `<observation>
|
|
13806
|
+
<type>[ ${d_} ]</type>
|
|
13786
13807
|
<!--
|
|
13787
13808
|
type MUST be EXACTLY one of these 7 options:
|
|
13788
13809
|
- bugfix: something was broken, now fixed
|
|
@@ -13830,11 +13851,11 @@ var u_ = "bugfix, feature, refactor, change, discovery, decision, exploration",
|
|
|
13830
13851
|
<files_modified>
|
|
13831
13852
|
<file>[full path from project root]</file>
|
|
13832
13853
|
</files_modified>
|
|
13833
|
-
</observation>`,
|
|
13834
|
-
function
|
|
13854
|
+
</observation>`, y_ = "<summary>\n <request>[What did the user request? What was the goal of this work session?]</request>\n\n <investigated>[What was explored or examined? What files, systems, logs were reviewed?\n What questions were asked? What did you try to understand?]</investigated>\n\n <learned>[What was learned about how things work? Any discoveries about the codebase,\n architecture, or domain? Gotchas or surprises? Understanding gained?]</learned>\n\n <completed>[What work was done? What shipped? What does the system do now that it\n didn't before? Be specific: files changed, features added, bugs fixed.]</completed>\n\n <next_steps>[What are the logical next steps? What remains to be done? What should\n the next session pick up? Any blockers or dependencies?]</next_steps>\n\n <notes>[Additional context, insights, or warnings. Anything future sessions should\n know that doesn't fit above. Design decisions, trade-offs, alternatives considered.]</notes>\n\n <files_read>\n <file>[path]</file>\n </files_read>\n <files_modified>\n <file>[path]</file>\n </files_modified>\n</summary>\n\nIf nothing meaningful happened, emit <skip_summary reason=\"low-signal\"/> and do not emit <summary>.\nOtherwise, write a summary that explains the current state of the PRIMARY work (not your observation process).\n\nIf the user prompt is a short approval or acknowledgement (\"yes\", \"ok\", \"approved\"),\ninfer the request from the observed work and the completed/learned sections instead.\n\nOnly summarize what is evidenced in the session context. Do not infer or fabricate\nfile edits, behaviors, or outcomes that are not explicitly observed.\n\nKeep summaries concise (aim for ~150-450 words total across all fields).\n\nFor rich sessions, make the summary broad enough that a future reader can see the major subthreads without reading every observation.\n\nThis summary helps future sessions understand where this work left off.";
|
|
13855
|
+
function b_(e) {
|
|
13835
13856
|
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
13836
13857
|
}
|
|
13837
|
-
function
|
|
13858
|
+
function x_(e) {
|
|
13838
13859
|
if (e == null) return "";
|
|
13839
13860
|
if (typeof e == "string") return e;
|
|
13840
13861
|
try {
|
|
@@ -13843,13 +13864,13 @@ function b_(e) {
|
|
|
13843
13864
|
return String(e);
|
|
13844
13865
|
}
|
|
13845
13866
|
}
|
|
13846
|
-
function
|
|
13867
|
+
function S_(e) {
|
|
13847
13868
|
let t = ["<observed_from_primary_session>"];
|
|
13848
|
-
t.push(` <what_happened>${
|
|
13849
|
-
let n =
|
|
13869
|
+
t.push(` <what_happened>${b_(e.toolName)}</what_happened>`), e.timestamp && t.push(` <occurred_at>${b_(e.timestamp)}</occurred_at>`), e.cwd && t.push(` <working_directory>${b_(e.cwd)}</working_directory>`);
|
|
13870
|
+
let n = b_(x_(e.toolInput)), r = b_(x_(e.toolOutput)), i = b_(x_(e.toolError));
|
|
13850
13871
|
return n && t.push(` <parameters>${n}</parameters>`), r && t.push(` <outcome>${r}</outcome>`), i && t.push(` <error>${i}</error>`), t.push("</observed_from_primary_session>"), t.join("\n");
|
|
13851
13872
|
}
|
|
13852
|
-
function
|
|
13873
|
+
function C_(e, t) {
|
|
13853
13874
|
if (e.length <= t) return e;
|
|
13854
13875
|
if (t <= 30) return e.slice(0, t);
|
|
13855
13876
|
let n = "\n[...]\n", r = t - 14;
|
|
@@ -13860,10 +13881,8 @@ function S_(e, t) {
|
|
|
13860
13881
|
let i = Math.floor(r * .35), a = Math.floor(r * .3), o = r - i - a, s = e.slice(0, i).trimEnd(), c = Math.max(0, Math.floor((e.length - a) / 2));
|
|
13861
13882
|
return `${s}${n}${e.slice(c, c + a).trim()}${n}${e.slice(e.length - o).trimStart()}`;
|
|
13862
13883
|
}
|
|
13863
|
-
function
|
|
13884
|
+
function w_(e) {
|
|
13864
13885
|
let t = [
|
|
13865
|
-
d_,
|
|
13866
|
-
"",
|
|
13867
13886
|
f_,
|
|
13868
13887
|
"",
|
|
13869
13888
|
p_,
|
|
@@ -13874,29 +13893,31 @@ function C_(e) {
|
|
|
13874
13893
|
"",
|
|
13875
13894
|
g_,
|
|
13876
13895
|
"",
|
|
13896
|
+
__,
|
|
13897
|
+
"",
|
|
13877
13898
|
"Observation XML schema:",
|
|
13878
|
-
|
|
13899
|
+
v_
|
|
13879
13900
|
];
|
|
13880
|
-
e.includeSummary && t.push("", "Summary XML schema:",
|
|
13901
|
+
e.includeSummary && t.push("", "Summary XML schema:", y_);
|
|
13881
13902
|
let n = t.join("\n\n").trim(), r = ["Observed session context:"];
|
|
13882
13903
|
if (e.userPrompt) {
|
|
13883
13904
|
let t = ["<observed_from_primary_session>"];
|
|
13884
|
-
t.push(` <user_request>${
|
|
13905
|
+
t.push(` <user_request>${b_(e.userPrompt)}</user_request>`), e.promptNumber != null && t.push(` <prompt_number>${e.promptNumber}</prompt_number>`), e.project && t.push(` <project>${b_(e.project)}</project>`), t.push("</observed_from_primary_session>"), r.push(t.join("\n"));
|
|
13885
13906
|
}
|
|
13886
|
-
e.transcript.trim() && r.push(`<conversation_transcript>\n${
|
|
13887
|
-
for (let t of e.toolEvents) r.push(
|
|
13888
|
-
return e.includeSummary && e.lastAssistantMessage && (r.push("Summary context:"), r.push(`<summary_context>\n <assistant_response>${
|
|
13907
|
+
e.transcript.trim() && r.push(`<conversation_transcript>\n${b_(e.transcript)}\n</conversation_transcript>`), e.diffSummary && r.push(`<observed_from_primary_session>\n <diff_summary>${b_(e.diffSummary)}</diff_summary>\n</observed_from_primary_session>`), e.recentFiles && r.push(`<observed_from_primary_session>\n <recent_files>${b_(e.recentFiles)}</recent_files>\n</observed_from_primary_session>`);
|
|
13908
|
+
for (let t of e.toolEvents) r.push(S_(t));
|
|
13909
|
+
return e.includeSummary && e.lastAssistantMessage && (r.push("Summary context:"), r.push(`<summary_context>\n <assistant_response>${b_(e.lastAssistantMessage)}</assistant_response>\n</summary_context>`)), {
|
|
13889
13910
|
system: n,
|
|
13890
13911
|
user: r.join("\n\n").trim()
|
|
13891
13912
|
};
|
|
13892
13913
|
}
|
|
13893
|
-
function
|
|
13914
|
+
function T_(e, t) {
|
|
13894
13915
|
let n = e.trim();
|
|
13895
|
-
return n ?
|
|
13916
|
+
return n ? C_(n, t) : "";
|
|
13896
13917
|
}
|
|
13897
13918
|
//#endregion
|
|
13898
13919
|
//#region src/ingest-transcript.ts
|
|
13899
|
-
var
|
|
13920
|
+
var E_ = new Set([
|
|
13900
13921
|
"yes",
|
|
13901
13922
|
"y",
|
|
13902
13923
|
"ok",
|
|
@@ -13911,18 +13932,18 @@ var T_ = new Set([
|
|
|
13911
13932
|
"go ahead",
|
|
13912
13933
|
"proceed"
|
|
13913
13934
|
]);
|
|
13914
|
-
function
|
|
13935
|
+
function D_(e) {
|
|
13915
13936
|
let t = 0, n = e.length;
|
|
13916
13937
|
for (; t < n && (e[t] === "\"" || e[t] === "'");) t++;
|
|
13917
13938
|
for (; n > t && (e[n - 1] === "\"" || e[n - 1] === "'");) n--;
|
|
13918
13939
|
return e.slice(t, n);
|
|
13919
13940
|
}
|
|
13920
|
-
function
|
|
13941
|
+
function O_(e) {
|
|
13921
13942
|
let t = [], n = "";
|
|
13922
13943
|
for (let r of e) r === " " || r === "\n" || r === "\r" || r === " " ? n &&= (t.push(n), "") : n += r;
|
|
13923
13944
|
return n && t.push(n), t.join(" ");
|
|
13924
13945
|
}
|
|
13925
|
-
function
|
|
13946
|
+
function k_(e) {
|
|
13926
13947
|
let t = 0;
|
|
13927
13948
|
for (; t < e.length;) {
|
|
13928
13949
|
let n = e[t];
|
|
@@ -13934,27 +13955,27 @@ function O_(e) {
|
|
|
13934
13955
|
}
|
|
13935
13956
|
return e.slice(t);
|
|
13936
13957
|
}
|
|
13937
|
-
function
|
|
13958
|
+
function A_(e) {
|
|
13938
13959
|
for (let t = 0; t < e.length - 1; t++) {
|
|
13939
13960
|
let n = e[t], r = e[t + 1];
|
|
13940
13961
|
if ((n === "." || n === "!" || n === "?") && (r === " " || r === " ")) return e.slice(0, t + 1);
|
|
13941
13962
|
}
|
|
13942
13963
|
return e;
|
|
13943
13964
|
}
|
|
13944
|
-
function A_(e) {
|
|
13945
|
-
if (!e) return "";
|
|
13946
|
-
let t = E_(e.trim()).trim();
|
|
13947
|
-
return t = D_(t), t.toLowerCase();
|
|
13948
|
-
}
|
|
13949
13965
|
function j_(e) {
|
|
13950
|
-
|
|
13951
|
-
|
|
13966
|
+
if (!e) return "";
|
|
13967
|
+
let t = D_(e.trim()).trim();
|
|
13968
|
+
return t = O_(t), t.toLowerCase();
|
|
13952
13969
|
}
|
|
13953
13970
|
function M_(e) {
|
|
13954
|
-
let t =
|
|
13955
|
-
return t
|
|
13971
|
+
let t = j_(e);
|
|
13972
|
+
return t ? E_.has(t) : !0;
|
|
13956
13973
|
}
|
|
13957
13974
|
function N_(e) {
|
|
13975
|
+
let t = e.split("\n").map((e) => e.trim()).filter(Boolean).join(" ");
|
|
13976
|
+
return t = k_(t), A_(t).trim();
|
|
13977
|
+
}
|
|
13978
|
+
function P_(e) {
|
|
13958
13979
|
let t = [
|
|
13959
13980
|
e.completed,
|
|
13960
13981
|
e.learned,
|
|
@@ -13962,24 +13983,24 @@ function N_(e) {
|
|
|
13962
13983
|
e.nextSteps,
|
|
13963
13984
|
e.notes
|
|
13964
13985
|
];
|
|
13965
|
-
for (let e of t) if (e) return
|
|
13986
|
+
for (let e of t) if (e) return N_(e);
|
|
13966
13987
|
return "";
|
|
13967
13988
|
}
|
|
13968
|
-
function
|
|
13989
|
+
function F_(e) {
|
|
13969
13990
|
let t = [];
|
|
13970
13991
|
for (let n of e) {
|
|
13971
13992
|
let e = n.type;
|
|
13972
13993
|
if (e === "user_prompt") {
|
|
13973
|
-
let e =
|
|
13994
|
+
let e = Hg(String(n.prompt_text ?? "")).trim();
|
|
13974
13995
|
e && t.push(`User: ${e}`);
|
|
13975
13996
|
} else if (e === "assistant_message") {
|
|
13976
|
-
let e =
|
|
13997
|
+
let e = Hg(String(n.assistant_text ?? "")).trim();
|
|
13977
13998
|
e && t.push(`Assistant: ${e}`);
|
|
13978
13999
|
}
|
|
13979
14000
|
}
|
|
13980
14001
|
return t.join("\n\n");
|
|
13981
14002
|
}
|
|
13982
|
-
function
|
|
14003
|
+
function I_(e) {
|
|
13983
14004
|
let t = [];
|
|
13984
14005
|
for (let n of e) {
|
|
13985
14006
|
if (n.type !== "assistant_message") continue;
|
|
@@ -13988,7 +14009,7 @@ function F_(e) {
|
|
|
13988
14009
|
}
|
|
13989
14010
|
return t;
|
|
13990
14011
|
}
|
|
13991
|
-
function
|
|
14012
|
+
function L_(e) {
|
|
13992
14013
|
let t = [];
|
|
13993
14014
|
for (let n of e) {
|
|
13994
14015
|
if (n.type !== "assistant_usage") continue;
|
|
@@ -14005,7 +14026,7 @@ function I_(e) {
|
|
|
14005
14026
|
}
|
|
14006
14027
|
return t;
|
|
14007
14028
|
}
|
|
14008
|
-
function
|
|
14029
|
+
function R_(e) {
|
|
14009
14030
|
let t = [];
|
|
14010
14031
|
for (let n of e) {
|
|
14011
14032
|
if (n.type !== "user_prompt") continue;
|
|
@@ -14018,10 +14039,10 @@ function L_(e) {
|
|
|
14018
14039
|
}
|
|
14019
14040
|
return t;
|
|
14020
14041
|
}
|
|
14021
|
-
function
|
|
14042
|
+
function z_(e) {
|
|
14022
14043
|
let t = [];
|
|
14023
14044
|
for (let n of e) {
|
|
14024
|
-
let e = n.timestamp_wall_ms, r =
|
|
14045
|
+
let e = n.timestamp_wall_ms, r = a_(n);
|
|
14025
14046
|
if (r) {
|
|
14026
14047
|
let i = String(r.event_type ?? "");
|
|
14027
14048
|
if (i === "prompt") {
|
|
@@ -14036,7 +14057,7 @@ function R_(e) {
|
|
|
14036
14057
|
continue;
|
|
14037
14058
|
}
|
|
14038
14059
|
} else if (i === "tool_result") {
|
|
14039
|
-
let i =
|
|
14060
|
+
let i = o_(r, n);
|
|
14040
14061
|
if (i) {
|
|
14041
14062
|
i.timestamp_wall_ms = e, t.push(i);
|
|
14042
14063
|
continue;
|
|
@@ -14049,7 +14070,7 @@ function R_(e) {
|
|
|
14049
14070
|
}
|
|
14050
14071
|
return t;
|
|
14051
14072
|
}
|
|
14052
|
-
function
|
|
14073
|
+
function B_(e) {
|
|
14053
14074
|
return e.map((e) => {
|
|
14054
14075
|
let t = e._adapter;
|
|
14055
14076
|
if (typeof t != "object" || !t || Array.isArray(t)) return e;
|
|
@@ -14080,15 +14101,15 @@ function z_(e) {
|
|
|
14080
14101
|
}
|
|
14081
14102
|
//#endregion
|
|
14082
14103
|
//#region src/ingest-xml-parser.ts
|
|
14083
|
-
var
|
|
14084
|
-
function
|
|
14085
|
-
return e.replace(
|
|
14104
|
+
var V_ = /<observation[^>]*>.*?<\/observation>/gs, H_ = /<summary[^>]*>.*?<\/summary>/gs, U_ = /<skip_summary(?:\s+reason="(?<reason>[^"]+)")?\s*\/>/i, W_ = /```(?:xml)?/gi;
|
|
14105
|
+
function G_(e) {
|
|
14106
|
+
return e.replace(W_, "").trim();
|
|
14086
14107
|
}
|
|
14087
|
-
function
|
|
14108
|
+
function K_(e, t) {
|
|
14088
14109
|
let n = RegExp(`<${t}[^>]*>([\\s\\S]*?)</${t}>`, "i").exec(e);
|
|
14089
14110
|
return n?.[1] ? n[1].trim() : "";
|
|
14090
14111
|
}
|
|
14091
|
-
function
|
|
14112
|
+
function q_(e, t, n) {
|
|
14092
14113
|
let r = RegExp(`<${t}[^>]*>([\\s\\S]*?)</${t}>`, "i").exec(e);
|
|
14093
14114
|
if (!r?.[1]) return [];
|
|
14094
14115
|
let i = RegExp(`<${n}[^>]*>([\\s\\S]*?)</${n}>`, "gi"), a = [];
|
|
@@ -14098,21 +14119,21 @@ function K_(e, t, n) {
|
|
|
14098
14119
|
}
|
|
14099
14120
|
return a;
|
|
14100
14121
|
}
|
|
14101
|
-
function
|
|
14102
|
-
let t =
|
|
14122
|
+
function J_(e) {
|
|
14123
|
+
let t = K_(e, "type"), n = K_(e, "title");
|
|
14103
14124
|
return !t && !n ? null : {
|
|
14104
14125
|
kind: t,
|
|
14105
14126
|
title: n,
|
|
14106
|
-
narrative:
|
|
14107
|
-
subtitle:
|
|
14108
|
-
facts:
|
|
14109
|
-
concepts:
|
|
14110
|
-
filesRead:
|
|
14111
|
-
filesModified:
|
|
14127
|
+
narrative: K_(e, "narrative"),
|
|
14128
|
+
subtitle: K_(e, "subtitle") || null,
|
|
14129
|
+
facts: q_(e, "facts", "fact"),
|
|
14130
|
+
concepts: q_(e, "concepts", "concept"),
|
|
14131
|
+
filesRead: q_(e, "files_read", "file"),
|
|
14132
|
+
filesModified: q_(e, "files_modified", "file")
|
|
14112
14133
|
};
|
|
14113
14134
|
}
|
|
14114
|
-
function
|
|
14115
|
-
let t =
|
|
14135
|
+
function Y_(e) {
|
|
14136
|
+
let t = K_(e, "request"), n = K_(e, "investigated"), r = K_(e, "learned"), i = K_(e, "completed"), a = K_(e, "next_steps"), o = K_(e, "notes");
|
|
14116
14137
|
return !t && !n && !r && !i && !a && !o ? null : {
|
|
14117
14138
|
request: t,
|
|
14118
14139
|
investigated: n,
|
|
@@ -14120,42 +14141,42 @@ function J_(e) {
|
|
|
14120
14141
|
completed: i,
|
|
14121
14142
|
nextSteps: a,
|
|
14122
14143
|
notes: o,
|
|
14123
|
-
filesRead:
|
|
14124
|
-
filesModified:
|
|
14144
|
+
filesRead: q_(e, "files_read", "file"),
|
|
14145
|
+
filesModified: q_(e, "files_modified", "file")
|
|
14125
14146
|
};
|
|
14126
14147
|
}
|
|
14127
|
-
function
|
|
14128
|
-
let t =
|
|
14148
|
+
function X_(e) {
|
|
14149
|
+
let t = G_(e), n = [], r = t.match(V_) ?? [];
|
|
14129
14150
|
for (let e of r) {
|
|
14130
|
-
let t =
|
|
14151
|
+
let t = J_(e);
|
|
14131
14152
|
t && n.push(t);
|
|
14132
14153
|
}
|
|
14133
|
-
let i = null, a = (t.match(
|
|
14134
|
-
a && (i =
|
|
14135
|
-
let o =
|
|
14154
|
+
let i = null, a = (t.match(H_) ?? []).at(-1);
|
|
14155
|
+
a && (i = Y_(a));
|
|
14156
|
+
let o = U_.exec(t)?.groups?.reason ?? null;
|
|
14136
14157
|
return {
|
|
14137
14158
|
observations: n,
|
|
14138
14159
|
summary: i,
|
|
14139
14160
|
skipSummaryReason: o
|
|
14140
14161
|
};
|
|
14141
14162
|
}
|
|
14142
|
-
function
|
|
14163
|
+
function Z_(e) {
|
|
14143
14164
|
return e.some((e) => e.title || e.narrative);
|
|
14144
14165
|
}
|
|
14145
14166
|
//#endregion
|
|
14146
14167
|
//#region src/session-policy.ts
|
|
14147
|
-
function
|
|
14148
|
-
let t = e.sessionContext.durationMs ?? 0, n = e.sessionContext.promptCount ?? 0, r = e.toolEventCount, i = e.sessionContext.toolCount ?? r, a = Math.max(r, i), o = (e.sessionContext.filesModified?.length ?? 0) > 0, s = (e.sessionContext.filesRead?.length ?? 0) > 0, c =
|
|
14168
|
+
function Q_(e) {
|
|
14169
|
+
let t = e.sessionContext.durationMs ?? 0, n = e.sessionContext.promptCount ?? 0, r = e.toolEventCount, i = e.sessionContext.toolCount ?? r, a = Math.max(r, i), o = (e.sessionContext.filesModified?.length ?? 0) > 0, s = (e.sessionContext.filesRead?.length ?? 0) > 0, c = M_(e.latestPrompt), l = e.observationsCount > 0;
|
|
14149
14170
|
return c && t > 0 && t < 6e4 && n <= 1 && a === 0 && !o && !l ? "trivial_turn" : t > 0 && t < 6e4 ? (l || o || a >= 3 || s || a > 0 && !c) && (l || o || a > 0 && !c || s) ? "micro_high_signal" : "micro_low_value" : t >= 6e5 || o || a >= 10 || e.observationsCount >= 3 ? "durable" : "working";
|
|
14150
14171
|
}
|
|
14151
|
-
function
|
|
14172
|
+
function $_(e) {
|
|
14152
14173
|
if (!e.hasSummaryCandidate || e.observationsCount > 0 || e.skipSummaryReason || !e.hasAssistantMessage) return !1;
|
|
14153
|
-
let t =
|
|
14174
|
+
let t = Q_(e);
|
|
14154
14175
|
return t === "trivial_turn" || t === "micro_low_value";
|
|
14155
14176
|
}
|
|
14156
14177
|
//#endregion
|
|
14157
14178
|
//#region src/ingest-pipeline.ts
|
|
14158
|
-
var
|
|
14179
|
+
var ev = new Set([
|
|
14159
14180
|
"bugfix",
|
|
14160
14181
|
"feature",
|
|
14161
14182
|
"refactor",
|
|
@@ -14164,17 +14185,17 @@ var $_ = new Set([
|
|
|
14164
14185
|
"decision",
|
|
14165
14186
|
"exploration"
|
|
14166
14187
|
]);
|
|
14167
|
-
function
|
|
14188
|
+
function tv(e, t) {
|
|
14168
14189
|
if (!e) return "";
|
|
14169
14190
|
let n = e.trim();
|
|
14170
14191
|
if (!t) return n;
|
|
14171
14192
|
let r = t.replace(/\/+$/, "");
|
|
14172
14193
|
return n === r ? "." : n.startsWith(`${r}/`) ? n.slice(r.length + 1) : n;
|
|
14173
14194
|
}
|
|
14174
|
-
function
|
|
14175
|
-
return e.map((e) =>
|
|
14195
|
+
function nv(e, t) {
|
|
14196
|
+
return e.map((e) => tv(e, t)).filter(Boolean);
|
|
14176
14197
|
}
|
|
14177
|
-
function
|
|
14198
|
+
function rv(e, t, n) {
|
|
14178
14199
|
let r = t.select({
|
|
14179
14200
|
id: W.id,
|
|
14180
14201
|
rev: W.rev,
|
|
@@ -14204,7 +14225,7 @@ function nv(e, t, n) {
|
|
|
14204
14225
|
}
|
|
14205
14226
|
return a;
|
|
14206
14227
|
}
|
|
14207
|
-
function
|
|
14228
|
+
function iv(e, t, n) {
|
|
14208
14229
|
if (t.length !== 0) for (let r of t) {
|
|
14209
14230
|
let t = e.select({ metadata_json: W.metadata_json }).from(W).where(k(W.id, r)).get();
|
|
14210
14231
|
if (!t) continue;
|
|
@@ -14212,7 +14233,7 @@ function rv(e, t, n) {
|
|
|
14212
14233
|
i.superseded_by = n, e.update(W).set({ metadata_json: Z(i) }).where(k(W.id, r)).run();
|
|
14213
14234
|
}
|
|
14214
14235
|
}
|
|
14215
|
-
function
|
|
14236
|
+
function av(e) {
|
|
14216
14237
|
return [
|
|
14217
14238
|
["Request", e.request],
|
|
14218
14239
|
["Completed", e.completed],
|
|
@@ -14222,42 +14243,42 @@ function iv(e) {
|
|
|
14222
14243
|
["Notes", e.notes]
|
|
14223
14244
|
].filter(([, e]) => e).map(([e, t]) => `## ${e}\n${t}`).join("\n\n");
|
|
14224
14245
|
}
|
|
14225
|
-
function
|
|
14246
|
+
function ov(e, t) {
|
|
14226
14247
|
let n = [];
|
|
14227
14248
|
for (let r of e) {
|
|
14228
|
-
let e =
|
|
14249
|
+
let e = a_(r);
|
|
14229
14250
|
if (e) {
|
|
14230
14251
|
if (e.event_type === "tool_call") continue;
|
|
14231
|
-
let i =
|
|
14252
|
+
let i = o_(e, r);
|
|
14232
14253
|
if (i) {
|
|
14233
|
-
let e =
|
|
14254
|
+
let e = r_(i, t);
|
|
14234
14255
|
if (e) {
|
|
14235
14256
|
n.push(e);
|
|
14236
14257
|
continue;
|
|
14237
14258
|
}
|
|
14238
14259
|
}
|
|
14239
14260
|
}
|
|
14240
|
-
let i =
|
|
14261
|
+
let i = i_([r], t);
|
|
14241
14262
|
n.push(...i);
|
|
14242
14263
|
}
|
|
14243
14264
|
return n;
|
|
14244
14265
|
}
|
|
14245
|
-
function
|
|
14266
|
+
function sv(e) {
|
|
14246
14267
|
return e.observations.length > 0 || e.summary !== null || e.skipSummaryReason !== null;
|
|
14247
14268
|
}
|
|
14248
|
-
async function
|
|
14249
|
-
let r = await e.observe(t, n), i = r.raw ?
|
|
14269
|
+
async function cv(e, t, n) {
|
|
14270
|
+
let r = await e.observe(t, n), i = r.raw ? X_(r.raw) : {
|
|
14250
14271
|
observations: [],
|
|
14251
14272
|
summary: null,
|
|
14252
14273
|
skipSummaryReason: null
|
|
14253
14274
|
};
|
|
14254
|
-
if (!r.raw ||
|
|
14275
|
+
if (!r.raw || sv(i)) return {
|
|
14255
14276
|
raw: r.raw,
|
|
14256
14277
|
parsed: i,
|
|
14257
14278
|
provider: r.provider,
|
|
14258
14279
|
model: r.model
|
|
14259
14280
|
};
|
|
14260
|
-
let a = `${t}\n\nYour previous reply was invalid because it did not follow the required XML-only schema. Rewrite the same analysis as valid XML only. Do not include prose outside XML.`, o = `${n}\n\nPrevious invalid response to rewrite as valid XML:\n${r.raw}`, s = await e.observe(a, o), c = s.raw ?
|
|
14281
|
+
let a = `${t}\n\nYour previous reply was invalid because it did not follow the required XML-only schema. Rewrite the same analysis as valid XML only. Do not include prose outside XML.`, o = `${n}\n\nPrevious invalid response to rewrite as valid XML:\n${r.raw}`, s = await e.observe(a, o), c = s.raw ? X_(s.raw) : {
|
|
14261
14282
|
observations: [],
|
|
14262
14283
|
summary: null,
|
|
14263
14284
|
skipSummaryReason: null
|
|
@@ -14269,7 +14290,7 @@ async function sv(e, t, n) {
|
|
|
14269
14290
|
model: s.model
|
|
14270
14291
|
};
|
|
14271
14292
|
}
|
|
14272
|
-
async function
|
|
14293
|
+
async function lv(e, t, n) {
|
|
14273
14294
|
let r = e.cwd ?? process.cwd(), i = e.events ?? [];
|
|
14274
14295
|
if (!Array.isArray(i) || i.length === 0) return;
|
|
14275
14296
|
let a = e.sessionContext ?? {}, o = n.storeSummary ?? !0, s = n.storeTyped ?? !0, c = n.maxChars ?? 12e3, l = n.observerMaxChars ?? 12e3, u = N(t.db, { schema: H }), d = (/* @__PURE__ */ new Date()).toISOString(), f = Dr(e.project) ?? Ti(r) ?? null, p = {
|
|
@@ -14298,15 +14319,15 @@ async function cv(e, t, n) {
|
|
|
14298
14319
|
return e;
|
|
14299
14320
|
})();
|
|
14300
14321
|
try {
|
|
14301
|
-
let e =
|
|
14302
|
-
h =
|
|
14303
|
-
let _ =
|
|
14304
|
-
if (b &&
|
|
14322
|
+
let e = B_(i), d = R_(e), p = d.length > 0 ? d[d.length - 1]?.promptNumber ?? d.length : null, h = ov(i, c), g = Math.max(2e3, Math.min(8e3, l - 5e3));
|
|
14323
|
+
h = u_(h, g, 30);
|
|
14324
|
+
let _ = I_(e), v = L_(e), y = _.at(-1) ?? null, b = a.firstPrompt ?? (d.length > 0 ? d[d.length - 1]?.promptText : null) ?? null, x = h.length > 0 || !!b || o && !!y;
|
|
14325
|
+
if (b && M_(b) && h.length === 0 && !y && (x = !1), !x) {
|
|
14305
14326
|
if (a?.flusher === "raw_events") throw Error("observer produced no storable output for raw-event flush");
|
|
14306
|
-
|
|
14327
|
+
uv(t, m, i.length, a);
|
|
14307
14328
|
return;
|
|
14308
14329
|
}
|
|
14309
|
-
let S =
|
|
14330
|
+
let S = F_(e), C = [];
|
|
14310
14331
|
if ((a.promptCount ?? 0) > 1 && C.push(`Session had ${a.promptCount} prompts`), (a.toolCount ?? 0) > 0 && C.push(`${a.toolCount} tool executions`), (a.durationMs ?? 0) > 0) {
|
|
14311
14332
|
let e = (a.durationMs ?? 0) / 6e4;
|
|
14312
14333
|
C.push(`~${e.toFixed(1)} minutes of work`);
|
|
@@ -14318,7 +14339,7 @@ async function cv(e, t, n) {
|
|
|
14318
14339
|
project: f,
|
|
14319
14340
|
userPrompt: ee,
|
|
14320
14341
|
promptNumber: p,
|
|
14321
|
-
transcript:
|
|
14342
|
+
transcript: T_(S, te),
|
|
14322
14343
|
toolEvents: h,
|
|
14323
14344
|
lastAssistantMessage: o ? y : null,
|
|
14324
14345
|
includeSummary: o,
|
|
@@ -14326,7 +14347,7 @@ async function cv(e, t, n) {
|
|
|
14326
14347
|
recentFiles: ""
|
|
14327
14348
|
}, re = n.observer, ie = null, T = [], ae = null, oe = null, E = null, se = null, D = !1, ce = null;
|
|
14328
14349
|
if (n.observer.tierRoutingEnabled) {
|
|
14329
|
-
let e = a.flushBatch && typeof a.flushBatch == "object" && "batch_id" in a.flushBatch ? Number(a.flushBatch.batch_id ?? 0) : 0, t =
|
|
14350
|
+
let e = a.flushBatch && typeof a.flushBatch == "object" && "batch_id" in a.flushBatch ? Number(a.flushBatch.batch_id ?? 0) : 0, t = zg({
|
|
14330
14351
|
batchId: Number.isFinite(e) ? e : 0,
|
|
14331
14352
|
sessionId: m,
|
|
14332
14353
|
eventSpan: i.length,
|
|
@@ -14335,40 +14356,40 @@ async function cv(e, t, n) {
|
|
|
14335
14356
|
transcriptLength: S.length
|
|
14336
14357
|
});
|
|
14337
14358
|
ie = t.tier, T = t.reasons;
|
|
14338
|
-
let r =
|
|
14359
|
+
let r = Rg(n.observer.toConfig(), t), o = r.observer;
|
|
14339
14360
|
ae = r.metadata.requestedProvider, oe = r.metadata.requestedModel, E = r.metadata.requestedRuntime, se = r.metadata.requestedOpenAIResponses, D = r.metadata.fallbackApplied, ce = r.metadata.fallbackReason, re = n.createTierObserver ? n.createTierObserver(o) : new Tm(o);
|
|
14340
14361
|
}
|
|
14341
|
-
let { system: le, user: O } =
|
|
14362
|
+
let { system: le, user: O } = w_(ne), ue = await cv(re, le, O);
|
|
14342
14363
|
if (!ue.raw) {
|
|
14343
14364
|
if (a?.flusher === "raw_events") throw Error("observer failed during raw-event flush");
|
|
14344
14365
|
let e = re.getStatus();
|
|
14345
|
-
console.warn(`[codemem] Observer returned no output (provider=${ue.provider}, model=${ue.model}${e.lastError ? `, error=${e.lastError}` : ""}). No memories will be created for this session.`),
|
|
14366
|
+
console.warn(`[codemem] Observer returned no output (provider=${ue.provider}, model=${ue.model}${e.lastError ? `, error=${e.lastError}` : ""}). No memories will be created for this session.`), uv(t, m, i.length, a);
|
|
14346
14367
|
return;
|
|
14347
14368
|
}
|
|
14348
14369
|
let k = ue.raw, A = ue.parsed, de = re.getStatus(), j = [];
|
|
14349
|
-
if (s &&
|
|
14370
|
+
if (s && Z_(A.observations)) for (let e of A.observations) {
|
|
14350
14371
|
let t = e.kind.trim().toLowerCase();
|
|
14351
|
-
|
|
14372
|
+
ev.has(t) && (!e.title && !e.narrative || Xf(e.title) || Xf(e.narrative) || (e.filesRead = nv(e.filesRead, r), e.filesModified = nv(e.filesModified, r), j.push(e)));
|
|
14352
14373
|
}
|
|
14353
14374
|
let fe = null;
|
|
14354
14375
|
if (o && A.summary && !A.skipSummaryReason) {
|
|
14355
14376
|
let e = A.summary;
|
|
14356
14377
|
if (e.request || e.investigated || e.learned || e.completed || e.nextSteps || e.notes) {
|
|
14357
|
-
e.filesRead =
|
|
14378
|
+
e.filesRead = nv(e.filesRead, r), e.filesModified = nv(e.filesModified, r);
|
|
14358
14379
|
let t = e.request;
|
|
14359
|
-
if (
|
|
14360
|
-
let n =
|
|
14380
|
+
if (M_(t)) {
|
|
14381
|
+
let n = P_(e);
|
|
14361
14382
|
n && (t = n);
|
|
14362
14383
|
}
|
|
14363
|
-
let n =
|
|
14364
|
-
n && !Xf(
|
|
14384
|
+
let n = av(e);
|
|
14385
|
+
n && !Xf(N_(n)) && (fe = {
|
|
14365
14386
|
summary: e,
|
|
14366
14387
|
request: t,
|
|
14367
14388
|
body: n
|
|
14368
14389
|
});
|
|
14369
14390
|
}
|
|
14370
14391
|
}
|
|
14371
|
-
let pe =
|
|
14392
|
+
let pe = Q_({
|
|
14372
14393
|
sessionContext: a,
|
|
14373
14394
|
latestPrompt: b,
|
|
14374
14395
|
toolEventCount: h.length,
|
|
@@ -14376,7 +14397,7 @@ async function cv(e, t, n) {
|
|
|
14376
14397
|
observationsCount: j.length,
|
|
14377
14398
|
hasSummaryCandidate: fe != null
|
|
14378
14399
|
}), me = fe ? "stored" : "none";
|
|
14379
|
-
if (
|
|
14400
|
+
if ($_({
|
|
14380
14401
|
sessionContext: a,
|
|
14381
14402
|
observationsCount: j.length,
|
|
14382
14403
|
hasSummaryCandidate: fe != null,
|
|
@@ -14385,7 +14406,7 @@ async function cv(e, t, n) {
|
|
|
14385
14406
|
hasAssistantMessage: !!y,
|
|
14386
14407
|
skipSummaryReason: A.skipSummaryReason
|
|
14387
14408
|
}) && (fe = null, me = "suppressed"), a?.flusher === "raw_events" && j.length === 0 && fe != null && h.length === 0 && !y && (fe = null), a?.flusher === "raw_events" && j.length + +!!fe === 0) {
|
|
14388
|
-
let e = A.skipSummaryReason?.trim().toLowerCase() === "low-signal" && A.observations.length === 0 && A.summary === null, n = A.observations.length === 0 && A.summary !== null &&
|
|
14409
|
+
let e = A.skipSummaryReason?.trim().toLowerCase() === "low-signal" && A.observations.length === 0 && A.summary === null, n = A.observations.length === 0 && A.summary !== null && $_({
|
|
14389
14410
|
sessionContext: a,
|
|
14390
14411
|
observationsCount: 0,
|
|
14391
14412
|
hasSummaryCandidate: !0,
|
|
@@ -14395,7 +14416,7 @@ async function cv(e, t, n) {
|
|
|
14395
14416
|
skipSummaryReason: A.skipSummaryReason
|
|
14396
14417
|
});
|
|
14397
14418
|
if (e || n) {
|
|
14398
|
-
|
|
14419
|
+
uv(t, m, i.length, a, {
|
|
14399
14420
|
session_class: pe,
|
|
14400
14421
|
summary_disposition: n ? "suppressed" : "none"
|
|
14401
14422
|
});
|
|
@@ -14450,7 +14471,7 @@ async function cv(e, t, n) {
|
|
|
14450
14471
|
title: i,
|
|
14451
14472
|
filesRead: e.filesRead,
|
|
14452
14473
|
filesModified: e.filesModified
|
|
14453
|
-
}), o =
|
|
14474
|
+
}), o = rv(t, u, m), s = t.remember(m, "session_summary", i, r, .3, a, {
|
|
14454
14475
|
is_summary: !0,
|
|
14455
14476
|
request: n,
|
|
14456
14477
|
investigated: e.investigated,
|
|
@@ -14477,7 +14498,7 @@ async function cv(e, t, n) {
|
|
|
14477
14498
|
source: "observer_summary",
|
|
14478
14499
|
flush_batch: ge
|
|
14479
14500
|
});
|
|
14480
|
-
|
|
14501
|
+
iv(u, o, s), he.push({
|
|
14481
14502
|
memoryId: s,
|
|
14482
14503
|
title: i,
|
|
14483
14504
|
bodyText: r
|
|
@@ -14515,7 +14536,7 @@ async function cv(e, t, n) {
|
|
|
14515
14536
|
for (let e of he) try {
|
|
14516
14537
|
await As(t.db, e.memoryId, e.title, e.bodyText);
|
|
14517
14538
|
} catch {}
|
|
14518
|
-
|
|
14539
|
+
uv(t, m, i.length, a, {
|
|
14519
14540
|
session_class: pe,
|
|
14520
14541
|
summary_disposition: me,
|
|
14521
14542
|
observer_tier: ie,
|
|
@@ -14533,12 +14554,12 @@ async function cv(e, t, n) {
|
|
|
14533
14554
|
});
|
|
14534
14555
|
} catch (e) {
|
|
14535
14556
|
try {
|
|
14536
|
-
|
|
14557
|
+
uv(t, m, i.length, a);
|
|
14537
14558
|
} catch {}
|
|
14538
14559
|
throw e;
|
|
14539
14560
|
}
|
|
14540
14561
|
}
|
|
14541
|
-
function
|
|
14562
|
+
function uv(e, t, n, r, i = {}) {
|
|
14542
14563
|
e.endSession(t, {
|
|
14543
14564
|
post: i,
|
|
14544
14565
|
source: "plugin",
|
|
@@ -14546,11 +14567,11 @@ function lv(e, t, n, r, i = {}) {
|
|
|
14546
14567
|
session_context: r
|
|
14547
14568
|
});
|
|
14548
14569
|
}
|
|
14549
|
-
function
|
|
14570
|
+
function dv(e, t = 24) {
|
|
14550
14571
|
let n = N(e.db, { schema: H }), r = (/* @__PURE__ */ new Date(Date.now() - t * 36e5)).toISOString();
|
|
14551
14572
|
return n.update(U).set({ ended_at: r }).where(O(pe(U.ended_at), he(U.started_at, r))).run().changes;
|
|
14552
14573
|
}
|
|
14553
|
-
async function
|
|
14574
|
+
async function fv(e, t) {
|
|
14554
14575
|
let n = [];
|
|
14555
14576
|
for await (let e of process.stdin) n.push(String(e));
|
|
14556
14577
|
let r = n.join("");
|
|
@@ -14561,24 +14582,24 @@ async function dv(e, t) {
|
|
|
14561
14582
|
} catch (e) {
|
|
14562
14583
|
throw Error(`codemem: invalid payload: ${e}`);
|
|
14563
14584
|
}
|
|
14564
|
-
await
|
|
14585
|
+
await lv(i, e, { observer: t });
|
|
14565
14586
|
}
|
|
14566
14587
|
//#endregion
|
|
14567
14588
|
//#region src/raw-event-flush.ts
|
|
14568
|
-
var
|
|
14569
|
-
function
|
|
14589
|
+
var pv = "raw_events_v1", mv = 5;
|
|
14590
|
+
function hv(e, t = 280) {
|
|
14570
14591
|
let n = e.replace(/\s+/g, " ").trim();
|
|
14571
14592
|
return n.length <= t ? n : `${n.slice(0, t - 3).trimEnd()}...`;
|
|
14572
14593
|
}
|
|
14573
|
-
function
|
|
14594
|
+
function gv(e) {
|
|
14574
14595
|
let t = (e ?? "").trim().toLowerCase();
|
|
14575
14596
|
return t === "openai" ? "OpenAI" : t === "anthropic" ? "Anthropic" : t ? t.charAt(0).toUpperCase() + t.slice(1) : "Observer";
|
|
14576
14597
|
}
|
|
14577
|
-
function
|
|
14578
|
-
let n =
|
|
14598
|
+
function _v(e, t) {
|
|
14599
|
+
let n = gv(t), r = String(e.message ?? "").trim().toLowerCase();
|
|
14579
14600
|
return e instanceof em ? `${n} authentication failed. Refresh credentials and retry.` : e.name === "TimeoutError" || r.includes("timeout") ? `${n} request timed out during raw-event processing.` : r === "observer failed during raw-event flush" || r === "observer produced no storable output for raw-event flush" ? `${n} returned no usable output for raw-event processing.` : /parse|xml|json/i.test(r) ? `${n} response could not be processed.` : `${n} processing failed during raw-event ingestion.`;
|
|
14580
14601
|
}
|
|
14581
|
-
function
|
|
14602
|
+
function vv(e) {
|
|
14582
14603
|
let t = 0, n = 0;
|
|
14583
14604
|
for (let r of e) r.type === "user_prompt" && t++, r.type === "tool.execute.after" && n++;
|
|
14584
14605
|
let r = [];
|
|
@@ -14628,14 +14649,14 @@ function _v(e) {
|
|
|
14628
14649
|
filesRead: [...o].sort()
|
|
14629
14650
|
};
|
|
14630
14651
|
}
|
|
14631
|
-
function
|
|
14652
|
+
function yv(e, t) {
|
|
14632
14653
|
let n = t.promptCount ?? 0, r = t.toolCount ?? 0;
|
|
14633
|
-
if (n > 0 || r > 0 || t.firstPrompt || e.length > 4 ||
|
|
14654
|
+
if (n > 0 || r > 0 || t.firstPrompt || e.length > 4 || B_(e).some((e) => {
|
|
14634
14655
|
let t = String(e.type ?? "");
|
|
14635
14656
|
return t === "user_prompt" || t === "assistant_message";
|
|
14636
14657
|
}) || e.some((e) => {
|
|
14637
|
-
let t =
|
|
14638
|
-
return t ?
|
|
14658
|
+
let t = a_(e);
|
|
14659
|
+
return t ? o_(t, e) != null : String(e.type ?? "") === "tool.execute.after";
|
|
14639
14660
|
})) return !1;
|
|
14640
14661
|
let i = new Set([
|
|
14641
14662
|
"session.started",
|
|
@@ -14647,11 +14668,11 @@ function vv(e, t) {
|
|
|
14647
14668
|
"error"
|
|
14648
14669
|
]);
|
|
14649
14670
|
return e.every((e) => {
|
|
14650
|
-
let t =
|
|
14671
|
+
let t = a_(e);
|
|
14651
14672
|
return t ? a.has(String(t.event_type ?? "")) : i.has(String(e.type ?? ""));
|
|
14652
14673
|
});
|
|
14653
14674
|
}
|
|
14654
|
-
async function
|
|
14675
|
+
async function bv(e, t, n) {
|
|
14655
14676
|
let { source: r = "opencode", cwd: i, project: a, startedAt: o } = n, { opencodeSessionId: s, maxEvents: c } = n;
|
|
14656
14677
|
r = (r ?? "").trim().toLowerCase() || "opencode";
|
|
14657
14678
|
let l = e.rawEventSessionMeta(s, r);
|
|
@@ -14683,13 +14704,13 @@ async function yv(e, t, n) {
|
|
|
14683
14704
|
flushed: 0,
|
|
14684
14705
|
updatedState: 0
|
|
14685
14706
|
};
|
|
14686
|
-
let { batchId: _, status: v, attemptCount: y } = e.getOrCreateRawEventFlushBatch(s, r, h, g,
|
|
14707
|
+
let { batchId: _, status: v, attemptCount: y } = e.getOrCreateRawEventFlushBatch(s, r, h, g, pv);
|
|
14687
14708
|
if (v === "completed") return e.updateRawEventFlushState(s, g, r), {
|
|
14688
14709
|
flushed: 0,
|
|
14689
14710
|
updatedState: 1
|
|
14690
14711
|
};
|
|
14691
14712
|
let b = Number.parseInt(process.env.CODEMEM_RAW_EVENTS_MAX_FLUSH_ATTEMPTS ?? "", 10);
|
|
14692
|
-
if (y >= (Number.isFinite(b) && b > 0 ? b :
|
|
14713
|
+
if (y >= (Number.isFinite(b) && b > 0 ? b : mv) && (v === "failed" || v === "error")) return e.updateRawEventFlushBatchStatus(_, "gave_up"), e.updateRawEventFlushState(s, g, r), {
|
|
14693
14714
|
flushed: 0,
|
|
14694
14715
|
updatedState: 1
|
|
14695
14716
|
};
|
|
@@ -14697,12 +14718,12 @@ async function yv(e, t, n) {
|
|
|
14697
14718
|
flushed: 0,
|
|
14698
14719
|
updatedState: 0
|
|
14699
14720
|
};
|
|
14700
|
-
let x =
|
|
14721
|
+
let x = vv(z_(d));
|
|
14701
14722
|
if (x.opencodeSessionId = s, x.source = r, x.streamId = s, x.flusher = "raw_events", x.flushBatch = {
|
|
14702
14723
|
batch_id: _,
|
|
14703
14724
|
start_event_seq: h,
|
|
14704
14725
|
end_event_seq: g
|
|
14705
|
-
},
|
|
14726
|
+
}, yv(d, x)) return e.updateRawEventFlushBatchStatus(_, "completed"), e.updateRawEventFlushState(s, g, r), {
|
|
14706
14727
|
flushed: d.length,
|
|
14707
14728
|
updatedState: 1
|
|
14708
14729
|
};
|
|
@@ -14714,9 +14735,9 @@ async function yv(e, t, n) {
|
|
|
14714
14735
|
sessionContext: x
|
|
14715
14736
|
};
|
|
14716
14737
|
try {
|
|
14717
|
-
await
|
|
14738
|
+
await lv(S, e, t);
|
|
14718
14739
|
} catch (n) {
|
|
14719
|
-
let r = n instanceof Error ? n : Error(String(n)), i = t.observer?.getStatus?.(), a = i?.provider, o =
|
|
14740
|
+
let r = n instanceof Error ? n : Error(String(n)), i = t.observer?.getStatus?.(), a = i?.provider, o = hv(_v(r, a));
|
|
14720
14741
|
throw e.recordRawEventFlushBatchFailure(_, {
|
|
14721
14742
|
message: o,
|
|
14722
14743
|
errorType: r instanceof em ? "ObserverAuthError" : r.name,
|
|
@@ -14726,7 +14747,7 @@ async function yv(e, t, n) {
|
|
|
14726
14747
|
observerAuthSource: i?.auth?.source ?? null,
|
|
14727
14748
|
observerAuthType: i?.auth?.type ?? null,
|
|
14728
14749
|
observerErrorCode: i?.lastError?.code ?? null,
|
|
14729
|
-
observerErrorMessage:
|
|
14750
|
+
observerErrorMessage: hv(i?.lastError?.message ?? "", 400) || null
|
|
14730
14751
|
}), n;
|
|
14731
14752
|
}
|
|
14732
14753
|
return e.updateRawEventFlushBatchStatus(_, "completed"), e.updateRawEventFlushState(s, g, r), {
|
|
@@ -14736,7 +14757,7 @@ async function yv(e, t, n) {
|
|
|
14736
14757
|
}
|
|
14737
14758
|
//#endregion
|
|
14738
14759
|
//#region src/extraction-replay.ts
|
|
14739
|
-
var
|
|
14760
|
+
var xv = new Set([
|
|
14740
14761
|
"bugfix",
|
|
14741
14762
|
"feature",
|
|
14742
14763
|
"refactor",
|
|
@@ -14745,17 +14766,17 @@ var bv = new Set([
|
|
|
14745
14766
|
"decision",
|
|
14746
14767
|
"exploration"
|
|
14747
14768
|
]);
|
|
14748
|
-
function
|
|
14769
|
+
function Sv(e, t) {
|
|
14749
14770
|
if (!e) return "";
|
|
14750
14771
|
let n = e.trim();
|
|
14751
14772
|
if (!t) return n;
|
|
14752
14773
|
let r = t.replace(/\/+$/, "");
|
|
14753
14774
|
return n === r ? "." : n.startsWith(`${r}/`) ? n.slice(r.length + 1) : n;
|
|
14754
14775
|
}
|
|
14755
|
-
function
|
|
14756
|
-
return e.map((e) =>
|
|
14776
|
+
function Cv(e, t) {
|
|
14777
|
+
return e.map((e) => Sv(e, t)).filter(Boolean);
|
|
14757
14778
|
}
|
|
14758
|
-
function
|
|
14779
|
+
function wv(e) {
|
|
14759
14780
|
return [
|
|
14760
14781
|
["Request", e.request],
|
|
14761
14782
|
["Completed", e.completed],
|
|
@@ -14765,27 +14786,27 @@ function Cv(e) {
|
|
|
14765
14786
|
["Notes", e.notes]
|
|
14766
14787
|
].filter(([, e]) => e).map(([e, t]) => `## ${e}\n${t}`).join("\n\n");
|
|
14767
14788
|
}
|
|
14768
|
-
function
|
|
14789
|
+
function Tv(e, t) {
|
|
14769
14790
|
let n = [];
|
|
14770
14791
|
for (let r of e) {
|
|
14771
|
-
let e =
|
|
14792
|
+
let e = a_(r);
|
|
14772
14793
|
if (e) {
|
|
14773
14794
|
if (e.event_type === "tool_call") continue;
|
|
14774
|
-
let i =
|
|
14795
|
+
let i = o_(e, r);
|
|
14775
14796
|
if (i) {
|
|
14776
|
-
let e =
|
|
14797
|
+
let e = r_(i, t);
|
|
14777
14798
|
if (e) {
|
|
14778
14799
|
n.push(e);
|
|
14779
14800
|
continue;
|
|
14780
14801
|
}
|
|
14781
14802
|
}
|
|
14782
14803
|
}
|
|
14783
|
-
n.push(...
|
|
14804
|
+
n.push(...i_([r], t));
|
|
14784
14805
|
}
|
|
14785
14806
|
return n;
|
|
14786
14807
|
}
|
|
14787
|
-
async function
|
|
14788
|
-
let r = await e.observe(t, n), i = r.raw ?
|
|
14808
|
+
async function Ev(e, t, n) {
|
|
14809
|
+
let r = await e.observe(t, n), i = r.raw ? X_(r.raw) : {
|
|
14789
14810
|
observations: [],
|
|
14790
14811
|
summary: null,
|
|
14791
14812
|
skipSummaryReason: null
|
|
@@ -14796,7 +14817,7 @@ async function Tv(e, t, n) {
|
|
|
14796
14817
|
provider: r.provider,
|
|
14797
14818
|
model: r.model
|
|
14798
14819
|
};
|
|
14799
|
-
let a = `${t}\n\nYour previous reply was invalid because it did not follow the required XML-only schema. Rewrite the same analysis as valid XML only. Do not include prose outside XML.`, o = `${n}\n\nPrevious invalid response to rewrite as valid XML:\n${r.raw}`, s = await e.observe(a, o), c = s.raw ?
|
|
14820
|
+
let a = `${t}\n\nYour previous reply was invalid because it did not follow the required XML-only schema. Rewrite the same analysis as valid XML only. Do not include prose outside XML.`, o = `${n}\n\nPrevious invalid response to rewrite as valid XML:\n${r.raw}`, s = await e.observe(a, o), c = s.raw ? X_(s.raw) : {
|
|
14800
14821
|
observations: [],
|
|
14801
14822
|
summary: null,
|
|
14802
14823
|
skipSummaryReason: null
|
|
@@ -14808,7 +14829,7 @@ async function Tv(e, t, n) {
|
|
|
14808
14829
|
model: s.model
|
|
14809
14830
|
};
|
|
14810
14831
|
}
|
|
14811
|
-
function
|
|
14832
|
+
function Dv(e) {
|
|
14812
14833
|
return e.raw ? e.evaluation.pass ? {
|
|
14813
14834
|
status: "pass",
|
|
14814
14835
|
reason: "fresh replay output satisfies the extraction rubric"
|
|
@@ -14820,15 +14841,15 @@ function Ev(e) {
|
|
|
14820
14841
|
reason: "observer returned no raw output"
|
|
14821
14842
|
};
|
|
14822
14843
|
}
|
|
14823
|
-
function
|
|
14844
|
+
function Ov(e, t, n) {
|
|
14824
14845
|
let r = e.transcript.trim().length;
|
|
14825
14846
|
return (t.promptCount ?? 0) >= 2 || (t.toolCount ?? 0) >= 3 || r >= 1500 || n >= 3;
|
|
14826
14847
|
}
|
|
14827
|
-
function
|
|
14848
|
+
function kv(e, t, n) {
|
|
14828
14849
|
let r = [], i = 1;
|
|
14829
14850
|
for (let a of e.observations) {
|
|
14830
14851
|
let e = a.kind.trim().toLowerCase();
|
|
14831
|
-
if (!e || !a.title && !a.narrative || !
|
|
14852
|
+
if (!e || !a.title && !a.narrative || !xv.has(e) || Xf(a.title) || Xf(a.narrative)) continue;
|
|
14832
14853
|
let o = [];
|
|
14833
14854
|
a.narrative && o.push(a.narrative), a.facts.length > 0 && o.push(a.facts.map((e) => `- ${e}`).join("\n")), r.push({
|
|
14834
14855
|
id: i++,
|
|
@@ -14839,22 +14860,22 @@ function Ov(e, t, n) {
|
|
|
14839
14860
|
createdAt: t.updated_at ?? t.started_at ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
14840
14861
|
metadata: {
|
|
14841
14862
|
source: "observer",
|
|
14842
|
-
files_read:
|
|
14843
|
-
files_modified:
|
|
14863
|
+
files_read: Cv(a.filesRead, t.cwd),
|
|
14864
|
+
files_modified: Cv(a.filesModified, t.cwd),
|
|
14844
14865
|
flush_batch: n.flushBatch
|
|
14845
14866
|
}
|
|
14846
14867
|
});
|
|
14847
14868
|
}
|
|
14848
14869
|
if (e.summary && !e.skipSummaryReason) {
|
|
14849
14870
|
let a = e.summary;
|
|
14850
|
-
a.filesRead =
|
|
14871
|
+
a.filesRead = Cv(a.filesRead, t.cwd), a.filesModified = Cv(a.filesModified, t.cwd);
|
|
14851
14872
|
let o = a.request;
|
|
14852
|
-
if (
|
|
14853
|
-
let e =
|
|
14873
|
+
if (M_(o)) {
|
|
14874
|
+
let e = P_(a);
|
|
14854
14875
|
e && (o = e);
|
|
14855
14876
|
}
|
|
14856
|
-
let s =
|
|
14857
|
-
s && !Xf(
|
|
14877
|
+
let s = wv(a);
|
|
14878
|
+
s && !Xf(N_(s)) && r.push({
|
|
14858
14879
|
id: i++,
|
|
14859
14880
|
kind: "session_summary",
|
|
14860
14881
|
title: o || "Session summary",
|
|
@@ -14870,12 +14891,12 @@ function Ov(e, t, n) {
|
|
|
14870
14891
|
}
|
|
14871
14892
|
return r;
|
|
14872
14893
|
}
|
|
14873
|
-
function
|
|
14874
|
-
return
|
|
14894
|
+
function Av(e, t, n) {
|
|
14895
|
+
return Ov(t, n, e.threads.length) ? e.counts.observations === 0 && e.counts.summaries >= 1 ? !0 : e.counts.observations < 2 : !1;
|
|
14875
14896
|
}
|
|
14876
|
-
async function
|
|
14897
|
+
async function jv(e, t, n, r, i) {
|
|
14877
14898
|
let a = i.threads.filter((e) => !e.observationMatch).map((e) => e.title);
|
|
14878
|
-
return
|
|
14899
|
+
return Ev(e, `${t}
|
|
14879
14900
|
|
|
14880
14901
|
RICH-SESSION REPAIR REQUIREMENT:
|
|
14881
14902
|
- The previous output under-extracted a rich batch.
|
|
@@ -14895,8 +14916,8 @@ The previous output failed because:
|
|
|
14895
14916
|
Rewrite the analysis as valid XML only.
|
|
14896
14917
|
Keep the broad summary, but add 2-4 durable observations for distinct subthreads if the transcript supports them.`);
|
|
14897
14918
|
}
|
|
14898
|
-
async function
|
|
14899
|
-
let n =
|
|
14919
|
+
async function Mv(e, t) {
|
|
14920
|
+
let n = wg(t.scenarioId);
|
|
14900
14921
|
if (!n) throw Error(`Unknown extraction eval scenario: ${t.scenarioId}`);
|
|
14901
14922
|
let r = Mn(Dn(e));
|
|
14902
14923
|
try {
|
|
@@ -14908,17 +14929,17 @@ async function jv(e, t) {
|
|
|
14908
14929
|
return t.type = t.type || e.event_type, t.timestamp_wall_ms = e.ts_wall_ms, t.timestamp_mono_ms = e.ts_mono_ms, t.event_seq = e.event_seq, t.event_id = e.event_id, t;
|
|
14909
14930
|
});
|
|
14910
14931
|
if (i.length === 0) throw Error(`Flush batch ${t.batchId} has no raw events in range`);
|
|
14911
|
-
let a =
|
|
14932
|
+
let a = vv(z_(i));
|
|
14912
14933
|
a.opencodeSessionId = e.opencode_session_id, a.source = e.source, a.streamId = e.stream_id, a.flusher = "raw_events", a.flushBatch = {
|
|
14913
14934
|
batch_id: e.id,
|
|
14914
14935
|
start_event_seq: e.start_event_seq,
|
|
14915
14936
|
end_event_seq: e.end_event_seq
|
|
14916
14937
|
};
|
|
14917
|
-
let o = t.maxChars ?? 12e3, s = t.observerMaxChars ?? 12e3, c =
|
|
14918
|
-
d =
|
|
14919
|
-
let p =
|
|
14920
|
-
if (m &&
|
|
14921
|
-
let g =
|
|
14938
|
+
let o = t.maxChars ?? 12e3, s = t.observerMaxChars ?? 12e3, c = B_(i), l = R_(c), u = l.length > 0 ? l[l.length - 1]?.promptNumber ?? l.length : null, d = Tv(i, o), f = Math.max(2e3, Math.min(8e3, s - 5e3));
|
|
14939
|
+
d = u_(d, f, 30);
|
|
14940
|
+
let p = I_(c).at(-1) ?? null, m = a.firstPrompt ?? (l.length > 0 ? l[l.length - 1]?.promptText : null) ?? null, h = d.length > 0 || !!m || !!p;
|
|
14941
|
+
if (m && M_(m) && d.length === 0 && !p && (h = !1), !h) throw Error(`Flush batch ${t.batchId} has no meaningful observer input to replay`);
|
|
14942
|
+
let g = F_(c), _ = [];
|
|
14922
14943
|
if ((a.promptCount ?? 0) > 1 && _.push(`Session had ${a.promptCount} prompts`), (a.toolCount ?? 0) > 0 && _.push(`${a.toolCount} tool executions`), (a.durationMs ?? 0) > 0) {
|
|
14923
14944
|
let e = (a.durationMs ?? 0) / 6e4;
|
|
14924
14945
|
_.push(`~${e.toFixed(1)} minutes of work`);
|
|
@@ -14930,13 +14951,13 @@ async function jv(e, t) {
|
|
|
14930
14951
|
project: e.project ?? Ti(e.cwd ?? process.cwd()) ?? null,
|
|
14931
14952
|
userPrompt: y,
|
|
14932
14953
|
promptNumber: u,
|
|
14933
|
-
transcript:
|
|
14954
|
+
transcript: T_(g, b),
|
|
14934
14955
|
toolEvents: d,
|
|
14935
14956
|
lastAssistantMessage: p,
|
|
14936
14957
|
includeSummary: !0,
|
|
14937
14958
|
diffSummary: "",
|
|
14938
14959
|
recentFiles: ""
|
|
14939
|
-
}, { system: S, user: C } =
|
|
14960
|
+
}, { system: S, user: C } = w_(x), w = (() => {
|
|
14940
14961
|
try {
|
|
14941
14962
|
return e.metadata_json ? JSON.parse(e.metadata_json) : {};
|
|
14942
14963
|
} catch {
|
|
@@ -14970,8 +14991,8 @@ async function jv(e, t) {
|
|
|
14970
14991
|
r.close();
|
|
14971
14992
|
}
|
|
14972
14993
|
}
|
|
14973
|
-
async function
|
|
14974
|
-
let i = await
|
|
14994
|
+
async function Nv(e, t, n, r) {
|
|
14995
|
+
let i = await Ev(t, e.system, e.user), a = i, o = kv(a.parsed, e.batch, e.sessionContext), s = Tg({
|
|
14975
14996
|
type: "batch",
|
|
14976
14997
|
sessionId: e.batch.session_id,
|
|
14977
14998
|
batchId: e.batch.id
|
|
@@ -14984,7 +15005,7 @@ async function Mv(e, t, n, r) {
|
|
|
14984
15005
|
sessionClass: String(e.sessionPost.session_class ?? "unknown"),
|
|
14985
15006
|
summaryDisposition: String(e.sessionPost.summary_disposition ?? "unknown")
|
|
14986
15007
|
}, o, e.scenario), c = !1;
|
|
14987
|
-
return i.raw &&
|
|
15008
|
+
return i.raw && Av(s, e.observerContext, e.sessionContext) && (c = !0, a = await jv(t, e.system, e.user, i.raw, s), o = kv(a.parsed, e.batch, e.sessionContext), s = Tg({
|
|
14988
15009
|
type: "batch",
|
|
14989
15010
|
sessionId: e.batch.session_id,
|
|
14990
15011
|
batchId: e.batch.id
|
|
@@ -15007,7 +15028,7 @@ async function Mv(e, t, n, r) {
|
|
|
15007
15028
|
sessionId: e.batch.session_id
|
|
15008
15029
|
},
|
|
15009
15030
|
analysis: e.analysis,
|
|
15010
|
-
classification:
|
|
15031
|
+
classification: Dv({
|
|
15011
15032
|
raw: a.raw,
|
|
15012
15033
|
evaluation: s
|
|
15013
15034
|
}),
|
|
@@ -15031,71 +15052,71 @@ async function Mv(e, t, n, r) {
|
|
|
15031
15052
|
evaluation: s
|
|
15032
15053
|
};
|
|
15033
15054
|
}
|
|
15034
|
-
async function
|
|
15035
|
-
return
|
|
15055
|
+
async function Pv(e, t, n) {
|
|
15056
|
+
return Nv(await Mv(e, {
|
|
15036
15057
|
...n,
|
|
15037
15058
|
observerMaxChars: n.observerMaxChars ?? t.maxChars
|
|
15038
15059
|
}), t, null, []);
|
|
15039
15060
|
}
|
|
15040
|
-
async function
|
|
15041
|
-
let r = new Tm(t), i = await
|
|
15061
|
+
async function Fv(e, t, n) {
|
|
15062
|
+
let r = new Tm(t), i = await Mv(e, {
|
|
15042
15063
|
...n,
|
|
15043
15064
|
observerMaxChars: n.observerMaxChars ?? r.maxChars
|
|
15044
|
-
}), a =
|
|
15045
|
-
return
|
|
15065
|
+
}), a = zg(i.analysis);
|
|
15066
|
+
return Nv(i, new Tm({
|
|
15046
15067
|
...t,
|
|
15047
15068
|
...a.observer
|
|
15048
15069
|
}), a.tier, a.reasons);
|
|
15049
15070
|
}
|
|
15050
15071
|
//#endregion
|
|
15051
15072
|
//#region src/scope-backfill.ts
|
|
15052
|
-
var
|
|
15053
|
-
function
|
|
15073
|
+
var Iv = "legacy-shared-review", Lv = "scope_id_backfill";
|
|
15074
|
+
function Rv(e) {
|
|
15054
15075
|
return e?.trim() || null;
|
|
15055
15076
|
}
|
|
15056
|
-
function
|
|
15057
|
-
if (
|
|
15058
|
-
let t =
|
|
15077
|
+
function zv(e) {
|
|
15078
|
+
if (Rv(e.gitRemote) || Rv(e.cwd)) return !0;
|
|
15079
|
+
let t = Rv(e.workspaceId);
|
|
15059
15080
|
return t != null && t !== "shared:default";
|
|
15060
15081
|
}
|
|
15061
|
-
function
|
|
15062
|
-
let t =
|
|
15082
|
+
function Bv(e) {
|
|
15083
|
+
let t = Rv(e.visibility)?.toLowerCase() ?? null, n = Rv(e.workspaceKind)?.toLowerCase() ?? null, r = Rv(e.workspaceId)?.toLowerCase() ?? null;
|
|
15063
15084
|
return t === "private" || t === "personal" || n === "personal" || r?.startsWith("personal:") ? {
|
|
15064
15085
|
scopeId: Ei,
|
|
15065
15086
|
reason: "private_or_personal",
|
|
15066
15087
|
needsReview: !1
|
|
15067
15088
|
} : {
|
|
15068
|
-
scopeId:
|
|
15069
|
-
reason:
|
|
15089
|
+
scopeId: Iv,
|
|
15090
|
+
reason: zv(e) ? "shared_with_canonical_workspace_review" : "shared_ambiguous_review",
|
|
15070
15091
|
needsReview: !0
|
|
15071
15092
|
};
|
|
15072
15093
|
}
|
|
15073
|
-
function
|
|
15074
|
-
let t = e.prepare("SELECT COUNT(*) AS n\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 )").get(Ei,
|
|
15094
|
+
function Vv(e) {
|
|
15095
|
+
let t = e.prepare("SELECT COUNT(*) AS n\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 )").get(Ei, Iv);
|
|
15075
15096
|
return Number(t?.n ?? 0);
|
|
15076
15097
|
}
|
|
15077
|
-
function
|
|
15098
|
+
function Hv(e, t = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
15078
15099
|
let n = e.prepare("INSERT OR IGNORE INTO replication_scopes(\n scope_id, label, kind, authority_type, membership_epoch, status, created_at, updated_at\n ) VALUES (?, ?, ?, 'local', 0, 'active', ?, ?)");
|
|
15079
15100
|
return e.transaction(() => {
|
|
15080
15101
|
let e = 0;
|
|
15081
15102
|
return e += Number(n.run("local-default", "Local only", "system", t, t).changes ?? 0), e += Number(n.run("legacy-shared-review", "Legacy shared review", "system", t, t).changes ?? 0), e;
|
|
15082
15103
|
})();
|
|
15083
15104
|
}
|
|
15084
|
-
function
|
|
15105
|
+
function Uv(e) {
|
|
15085
15106
|
let t = e.prepare("SELECT COUNT(*) AS n\n FROM memory_items\n WHERE scope_id IS NULL OR scope_id = ''").get();
|
|
15086
15107
|
return Number(t?.n ?? 0);
|
|
15087
15108
|
}
|
|
15088
|
-
function
|
|
15109
|
+
function Wv(e) {
|
|
15089
15110
|
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();
|
|
15090
15111
|
return Number(t?.max_id ?? 0);
|
|
15091
15112
|
}
|
|
15092
|
-
function
|
|
15113
|
+
function Gv(e) {
|
|
15093
15114
|
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();
|
|
15094
15115
|
return Number(t?.n ?? 0);
|
|
15095
15116
|
}
|
|
15096
|
-
function
|
|
15117
|
+
function Kv(e) {
|
|
15097
15118
|
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;
|
|
15098
|
-
let t =
|
|
15119
|
+
let t = Gv(e), n = Q(e, Lv);
|
|
15099
15120
|
if (n?.status === "running") return !0;
|
|
15100
15121
|
if (t === 0) return !1;
|
|
15101
15122
|
if (!n || n.status !== "completed") return !0;
|
|
@@ -15104,17 +15125,17 @@ function Gv(e) {
|
|
|
15104
15125
|
let a = r.max_stamped_memory_id_at_completion;
|
|
15105
15126
|
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;
|
|
15106
15127
|
}
|
|
15107
|
-
function
|
|
15128
|
+
function qv(e, t) {
|
|
15108
15129
|
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);
|
|
15109
15130
|
}
|
|
15110
|
-
function
|
|
15131
|
+
function Jv(e, t) {
|
|
15111
15132
|
return e.prepare("SELECT op_id, entity_id, scope_id, created_at\n FROM (\n SELECT ro.op_id, ro.entity_id, mi.scope_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 ALL\n SELECT ro.op_id, ro.entity_id, mi.scope_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 AND NOT EXISTS (\n SELECT 1\n FROM memory_items import_match\n WHERE import_match.import_key = ro.entity_id\n AND import_match.scope_id IS NOT NULL\n AND import_match.scope_id != ''\n LIMIT 1\n )\n )\n ORDER BY created_at ASC, op_id ASC\n LIMIT ?").all(t);
|
|
15112
15133
|
}
|
|
15113
|
-
function
|
|
15114
|
-
let n = Math.max(1, t.memoryLimit ?? 250), r = Math.max(1, t.replicationOpLimit ?? n), i =
|
|
15134
|
+
function Yv(e, t = {}) {
|
|
15135
|
+
let n = Math.max(1, t.memoryLimit ?? 250), r = Math.max(1, t.replicationOpLimit ?? n), i = Hv(e, t.now), a = qv(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(() => {
|
|
15115
15136
|
let t = 0, i = 0, c = 0;
|
|
15116
15137
|
for (let e of a) {
|
|
15117
|
-
let n =
|
|
15138
|
+
let n = Bv({
|
|
15118
15139
|
visibility: e.visibility,
|
|
15119
15140
|
workspaceKind: e.workspace_kind,
|
|
15120
15141
|
workspaceId: e.workspace_id,
|
|
@@ -15124,9 +15145,9 @@ function Jv(e, t = {}) {
|
|
|
15124
15145
|
});
|
|
15125
15146
|
t += Number(o.run(n.scopeId, e.id).changes ?? 0);
|
|
15126
15147
|
}
|
|
15127
|
-
let l = a.length >= n ? [] :
|
|
15148
|
+
let l = a.length >= n ? [] : Jv(e, r);
|
|
15128
15149
|
for (let e of l) {
|
|
15129
|
-
let t =
|
|
15150
|
+
let t = Rv(e.scope_id);
|
|
15130
15151
|
if (!t) {
|
|
15131
15152
|
c += 1;
|
|
15132
15153
|
continue;
|
|
@@ -15147,23 +15168,23 @@ function Jv(e, t = {}) {
|
|
|
15147
15168
|
checkedReplicationOps: c.checkedReplicationOps,
|
|
15148
15169
|
updatedReplicationOps: c.updatedReplicationOps,
|
|
15149
15170
|
skippedReplicationOps: c.skippedReplicationOps,
|
|
15150
|
-
remainingMemoryItems:
|
|
15151
|
-
remainingReplicationOps:
|
|
15171
|
+
remainingMemoryItems: Uv(e),
|
|
15172
|
+
remainingReplicationOps: Gv(e)
|
|
15152
15173
|
};
|
|
15153
15174
|
}
|
|
15154
|
-
function
|
|
15175
|
+
function Xv(e) {
|
|
15155
15176
|
return Q(e, "scope_id_backfill")?.metadata ?? {};
|
|
15156
15177
|
}
|
|
15157
|
-
function
|
|
15178
|
+
function Zv(e) {
|
|
15158
15179
|
return Number(e.seeded_scopes ?? 0) + Number(e.processed_memories ?? 0) + Number(e.processed_replication_ops ?? 0);
|
|
15159
15180
|
}
|
|
15160
|
-
async function
|
|
15161
|
-
let n = Math.max(1, t.batchSize ?? 250), r = Q(e,
|
|
15181
|
+
async function Qv(e, t = {}) {
|
|
15182
|
+
let n = Math.max(1, t.batchSize ?? 250), r = Q(e, Lv), i = Xv(e), a = !r || r.status === "completed" || r.status === "failed", o = Uv(e), s = Gv(e), c = Vv(e), l = o + s + c;
|
|
15162
15183
|
if (l <= 0) {
|
|
15163
15184
|
let t = !!i.exhausted_in_previous_pass;
|
|
15164
15185
|
if (r && r.status !== "completed") {
|
|
15165
|
-
let n =
|
|
15166
|
-
return t ? (Yr(e,
|
|
15186
|
+
let n = Zv(i);
|
|
15187
|
+
return t ? (Yr(e, Lv, {
|
|
15167
15188
|
message: "Sharing-domain backfill complete; future startup should be quieter",
|
|
15168
15189
|
progressCurrent: n,
|
|
15169
15190
|
progressTotal: n,
|
|
@@ -15171,10 +15192,10 @@ async function Zv(e, t = {}) {
|
|
|
15171
15192
|
...i,
|
|
15172
15193
|
remaining_memories: 0,
|
|
15173
15194
|
remaining_replication_ops: 0,
|
|
15174
|
-
unstamped_replication_ops_at_completion:
|
|
15175
|
-
max_stamped_memory_id_at_completion:
|
|
15195
|
+
unstamped_replication_ops_at_completion: Gv(e),
|
|
15196
|
+
max_stamped_memory_id_at_completion: Wv(e)
|
|
15176
15197
|
}
|
|
15177
|
-
}), !1) : (Jr(e,
|
|
15198
|
+
}), !1) : (Jr(e, Lv, {
|
|
15178
15199
|
message: "Sharing-domain backfill quiescent — confirming on next tick",
|
|
15179
15200
|
progressCurrent: n,
|
|
15180
15201
|
progressTotal: n + 1,
|
|
@@ -15189,7 +15210,7 @@ async function Zv(e, t = {}) {
|
|
|
15189
15210
|
return !1;
|
|
15190
15211
|
}
|
|
15191
15212
|
a && qr(e, {
|
|
15192
|
-
kind:
|
|
15213
|
+
kind: Lv,
|
|
15193
15214
|
title: "Backfilling Sharing domains",
|
|
15194
15215
|
message: `Backfilling ${l} legacy Sharing-domain item(s), including memories and replication ops`,
|
|
15195
15216
|
progressTotal: l,
|
|
@@ -15204,10 +15225,10 @@ async function Zv(e, t = {}) {
|
|
|
15204
15225
|
remaining_replication_ops: s
|
|
15205
15226
|
}
|
|
15206
15227
|
});
|
|
15207
|
-
let u =
|
|
15228
|
+
let u = Yv(e, {
|
|
15208
15229
|
memoryLimit: n,
|
|
15209
15230
|
replicationOpLimit: n
|
|
15210
|
-
}), d = a ? {} : i, f = Number(d.seeded_scopes ?? 0) + u.seededScopes, p = Number(d.processed_memories ?? 0) + u.checkedMemoryItems, m = Number(d.updated_memories ?? 0) + u.updatedMemoryItems, h = Number(d.processed_replication_ops ?? 0) + u.checkedReplicationOps, g = Number(d.updated_replication_ops ?? 0) + u.updatedReplicationOps, _ = Number(d.skipped_replication_ops ?? 0) + u.skippedReplicationOps, v = u.remainingMemoryItems, y = u.checkedReplicationOps === 0, b =
|
|
15231
|
+
}), d = a ? {} : i, f = Number(d.seeded_scopes ?? 0) + u.seededScopes, p = Number(d.processed_memories ?? 0) + u.checkedMemoryItems, m = Number(d.updated_memories ?? 0) + u.updatedMemoryItems, h = Number(d.processed_replication_ops ?? 0) + u.checkedReplicationOps, g = Number(d.updated_replication_ops ?? 0) + u.updatedReplicationOps, _ = Number(d.skipped_replication_ops ?? 0) + u.skippedReplicationOps, v = u.remainingMemoryItems, y = u.checkedReplicationOps === 0, b = Vv(e), x = v === 0 && y && b === 0, S = !!d.exhausted_in_previous_pass, C = x && S, w = f + p + h, ee = !C && v === 0 && u.remainingReplicationOps === 0 && b === 0, te = Math.max(w + v + u.remainingReplicationOps + b + +!!ee, w), ne = {
|
|
15211
15232
|
seeded_scopes: f,
|
|
15212
15233
|
processed_memories: p,
|
|
15213
15234
|
updated_memories: m,
|
|
@@ -15218,23 +15239,23 @@ async function Zv(e, t = {}) {
|
|
|
15218
15239
|
remaining_replication_ops: u.remainingReplicationOps,
|
|
15219
15240
|
exhausted_in_previous_pass: x
|
|
15220
15241
|
};
|
|
15221
|
-
return C ? (Yr(e,
|
|
15242
|
+
return C ? (Yr(e, Lv, {
|
|
15222
15243
|
message: "Sharing-domain backfill complete; future startup should be quieter",
|
|
15223
15244
|
progressCurrent: te,
|
|
15224
15245
|
progressTotal: te,
|
|
15225
15246
|
metadata: {
|
|
15226
15247
|
...ne,
|
|
15227
|
-
unstamped_replication_ops_at_completion:
|
|
15228
|
-
max_stamped_memory_id_at_completion:
|
|
15248
|
+
unstamped_replication_ops_at_completion: Gv(e),
|
|
15249
|
+
max_stamped_memory_id_at_completion: Wv(e)
|
|
15229
15250
|
}
|
|
15230
|
-
}), !1) : (Jr(e,
|
|
15251
|
+
}), !1) : (Jr(e, Lv, {
|
|
15231
15252
|
message: `Backfilled Sharing domains for ${w} of ${te} item(s), including memories and replication ops`,
|
|
15232
15253
|
progressCurrent: w,
|
|
15233
15254
|
progressTotal: te,
|
|
15234
15255
|
metadata: ne
|
|
15235
15256
|
}), !0);
|
|
15236
15257
|
}
|
|
15237
|
-
var
|
|
15258
|
+
var $v = class {
|
|
15238
15259
|
dbPath;
|
|
15239
15260
|
signal;
|
|
15240
15261
|
batchSize;
|
|
@@ -15264,19 +15285,19 @@ var Qv = class {
|
|
|
15264
15285
|
if (!this.active || this.signal?.aborted) return;
|
|
15265
15286
|
let e = null;
|
|
15266
15287
|
try {
|
|
15267
|
-
e = Mn(this.dbPath), await
|
|
15288
|
+
e = Mn(this.dbPath), await Qv(e, { batchSize: this.batchSize }) || (this.active = !1);
|
|
15268
15289
|
} catch (t) {
|
|
15269
|
-
if (
|
|
15290
|
+
if (ey(t)) {
|
|
15270
15291
|
console.warn("Scope backfill runner deferred because the database is busy", t);
|
|
15271
15292
|
return;
|
|
15272
15293
|
}
|
|
15273
|
-
e && Xr(e,
|
|
15294
|
+
e && Xr(e, Lv, t instanceof Error ? t.message : String(t)), console.warn("Scope backfill runner failed", t);
|
|
15274
15295
|
} finally {
|
|
15275
15296
|
e?.close();
|
|
15276
15297
|
}
|
|
15277
15298
|
}
|
|
15278
15299
|
};
|
|
15279
|
-
function
|
|
15300
|
+
function ey(e) {
|
|
15280
15301
|
let t = typeof e == "object" && e ? String(e.code ?? "") : "";
|
|
15281
15302
|
if (t === "SQLITE_BUSY" || t === "SQLITE_LOCKED") return !0;
|
|
15282
15303
|
let n = e instanceof Error ? e.message : String(e);
|
|
@@ -15284,27 +15305,27 @@ function $v(e) {
|
|
|
15284
15305
|
}
|
|
15285
15306
|
//#endregion
|
|
15286
15307
|
//#region src/project-scope-settings.ts
|
|
15287
|
-
function
|
|
15308
|
+
function ty(e) {
|
|
15288
15309
|
return e?.trim() || null;
|
|
15289
15310
|
}
|
|
15290
|
-
function
|
|
15291
|
-
let t =
|
|
15311
|
+
function ny(e) {
|
|
15312
|
+
let t = ty(e);
|
|
15292
15313
|
return t ? t.replaceAll("\\", "/").replace(/\/+$/, "") || t : null;
|
|
15293
15314
|
}
|
|
15294
|
-
function
|
|
15315
|
+
function ry(e, t) {
|
|
15295
15316
|
return e?.label || t;
|
|
15296
15317
|
}
|
|
15297
|
-
function
|
|
15318
|
+
function iy(e) {
|
|
15298
15319
|
return new Map(e.map((e) => [e.scope_id, e]));
|
|
15299
15320
|
}
|
|
15300
|
-
function
|
|
15321
|
+
function ay(e) {
|
|
15301
15322
|
return !e || e.scope_id === "local-default" ? !1 : e.authority_type === "local" ? e.kind === "team" || e.kind === "org" || e.kind === "client" : !0;
|
|
15302
15323
|
}
|
|
15303
|
-
function
|
|
15304
|
-
let t =
|
|
15324
|
+
function oy(e) {
|
|
15325
|
+
let t = ty(e)?.toLowerCase() ?? "";
|
|
15305
15326
|
return new Set(t.match(/[a-z0-9][a-z0-9-]{1,}/g) ?? []);
|
|
15306
15327
|
}
|
|
15307
|
-
function
|
|
15328
|
+
function sy(e) {
|
|
15308
15329
|
let t = new Set([
|
|
15309
15330
|
"domain",
|
|
15310
15331
|
"sharing",
|
|
@@ -15319,13 +15340,13 @@ function oy(e) {
|
|
|
15319
15340
|
"oss",
|
|
15320
15341
|
"personal",
|
|
15321
15342
|
"work"
|
|
15322
|
-
]), r = [...
|
|
15343
|
+
]), r = [...oy(`${e.scope_id} ${e.label}`)].filter((e) => !t.has(e));
|
|
15323
15344
|
return {
|
|
15324
15345
|
generic: r.filter((e) => n.has(e)),
|
|
15325
15346
|
specific: r.filter((e) => !n.has(e))
|
|
15326
15347
|
};
|
|
15327
15348
|
}
|
|
15328
|
-
function
|
|
15349
|
+
function cy(e) {
|
|
15329
15350
|
let t = [];
|
|
15330
15351
|
return e.git_remote && t.push({
|
|
15331
15352
|
signal: "git_remote",
|
|
@@ -15338,11 +15359,11 @@ function sy(e) {
|
|
|
15338
15359
|
text: e.workspace_identity
|
|
15339
15360
|
}), t;
|
|
15340
15361
|
}
|
|
15341
|
-
function
|
|
15362
|
+
function ly(e, t) {
|
|
15342
15363
|
if (e.resolution_reason !== "local_default" || e.workspace_identity.startsWith("unmapped:")) return null;
|
|
15343
|
-
for (let n of
|
|
15344
|
-
let e =
|
|
15345
|
-
let n =
|
|
15364
|
+
for (let n of cy(e)) {
|
|
15365
|
+
let e = oy(n.text), [r, i] = t.filter((e) => e.scope_id !== "local-default" && e.scope_id !== "legacy-shared-review" && e.status === "active").flatMap((t) => {
|
|
15366
|
+
let n = sy(t), r = n.specific.filter((t) => e.has(t)), i = n.generic.filter((n) => n === "personal" && e.has(n) && t.kind === n);
|
|
15346
15367
|
return r.length === 0 && i.length === 0 ? [] : [{
|
|
15347
15368
|
scope: t,
|
|
15348
15369
|
matches: [...r, ...i],
|
|
@@ -15350,7 +15371,7 @@ function cy(e, t) {
|
|
|
15350
15371
|
}];
|
|
15351
15372
|
}).toSorted((e, t) => t.score - e.score);
|
|
15352
15373
|
if (!r || i && i.score === r.score) continue;
|
|
15353
|
-
let a =
|
|
15374
|
+
let a = ry(r.scope, r.scope.scope_id), o = n.signal === "git_remote" ? "git remote" : n.signal;
|
|
15354
15375
|
return {
|
|
15355
15376
|
scopeId: r.scope.scope_id,
|
|
15356
15377
|
reason: `${a} is suggested because the ${o} contains ${r.matches.join(", ")}. Confirm before mapping; this does not grant peer access.`,
|
|
@@ -15359,18 +15380,18 @@ function cy(e, t) {
|
|
|
15359
15380
|
}
|
|
15360
15381
|
return null;
|
|
15361
15382
|
}
|
|
15362
|
-
function
|
|
15383
|
+
function uy(e) {
|
|
15363
15384
|
return /[*?]/.test(e);
|
|
15364
15385
|
}
|
|
15365
|
-
function
|
|
15386
|
+
function dy(e) {
|
|
15366
15387
|
let t = e.search(/[*?]/);
|
|
15367
15388
|
return (t >= 0 ? e.slice(0, t) : e).replace(/\/+$/, "");
|
|
15368
15389
|
}
|
|
15369
|
-
function
|
|
15370
|
-
let t =
|
|
15390
|
+
function fy(e) {
|
|
15391
|
+
let t = dy(e.replaceAll("\\", "/"));
|
|
15371
15392
|
return t === "~" || /^\/Users\/[^/]+$/i.test(t) || /^\/home\/[^/]+$/i.test(t) || /^\/var\/home\/[^/]+$/i.test(t) || /^[A-Z]:\/Users\/[^/]+$/i.test(t);
|
|
15372
15393
|
}
|
|
15373
|
-
function
|
|
15394
|
+
function py(e) {
|
|
15374
15395
|
let t = JSON.stringify({
|
|
15375
15396
|
code: e.code,
|
|
15376
15397
|
mapping_id: e.mapping_id ?? null,
|
|
@@ -15382,18 +15403,18 @@ function fy(e) {
|
|
|
15382
15403
|
});
|
|
15383
15404
|
return `psg_${u("sha256").update(t).digest("hex").slice(0, 32)}`;
|
|
15384
15405
|
}
|
|
15385
|
-
function
|
|
15406
|
+
function my(e) {
|
|
15386
15407
|
return e.requires_confirmation ? {
|
|
15387
15408
|
...e,
|
|
15388
|
-
confirmation_token:
|
|
15409
|
+
confirmation_token: py(e)
|
|
15389
15410
|
} : e;
|
|
15390
15411
|
}
|
|
15391
|
-
function
|
|
15412
|
+
function hy(e, t) {
|
|
15392
15413
|
if (e.workspace_identity) return [];
|
|
15393
|
-
let n =
|
|
15394
|
-
if (!
|
|
15395
|
-
let i =
|
|
15396
|
-
return
|
|
15414
|
+
let n = ny(e.project_pattern) ?? e.project_pattern, r = t.get(e.scope_id);
|
|
15415
|
+
if (!ay(r)) return [];
|
|
15416
|
+
let i = ry(r, e.scope_id), a = [];
|
|
15417
|
+
return uy(n) && a.push({
|
|
15397
15418
|
code: "broad_org_domain_pattern",
|
|
15398
15419
|
severity: "warning",
|
|
15399
15420
|
message: `Wildcard project pattern ${n} can catch multiple projects. Review before attaching it to ${i}.`,
|
|
@@ -15401,7 +15422,7 @@ function my(e, t) {
|
|
|
15401
15422
|
scope_id: e.scope_id,
|
|
15402
15423
|
mapping_id: e.id ?? null,
|
|
15403
15424
|
project_pattern: e.project_pattern
|
|
15404
|
-
}),
|
|
15425
|
+
}), fy(n) && a.push({
|
|
15405
15426
|
code: "home_directory_org_domain_pattern",
|
|
15406
15427
|
severity: "warning",
|
|
15407
15428
|
message: `Home-directory project pattern ${n} can mix personal and work projects. Review before attaching it to ${i}.`,
|
|
@@ -15409,20 +15430,20 @@ function my(e, t) {
|
|
|
15409
15430
|
scope_id: e.scope_id,
|
|
15410
15431
|
mapping_id: e.id ?? null,
|
|
15411
15432
|
project_pattern: e.project_pattern
|
|
15412
|
-
}), a.map(
|
|
15413
|
-
}
|
|
15414
|
-
function hy(e) {
|
|
15415
|
-
return (ey(e.project) ?? ey(e.display_project) ?? e.workspace_identity).toLowerCase();
|
|
15433
|
+
}), a.map(my);
|
|
15416
15434
|
}
|
|
15417
15435
|
function gy(e) {
|
|
15436
|
+
return (ty(e.project) ?? ty(e.display_project) ?? e.workspace_identity).toLowerCase();
|
|
15437
|
+
}
|
|
15438
|
+
function _y(e) {
|
|
15418
15439
|
let t = /* @__PURE__ */ new Map();
|
|
15419
15440
|
for (let n of e) {
|
|
15420
|
-
let e =
|
|
15441
|
+
let e = gy(n);
|
|
15421
15442
|
t.set(e, [...t.get(e) ?? [], n]);
|
|
15422
15443
|
}
|
|
15423
15444
|
return t;
|
|
15424
15445
|
}
|
|
15425
|
-
function
|
|
15446
|
+
function vy(e, t) {
|
|
15426
15447
|
let n = [];
|
|
15427
15448
|
e.resolution_reason === "local_default" && n.push({
|
|
15428
15449
|
code: "unknown_project_local_only",
|
|
@@ -15432,7 +15453,7 @@ function _y(e, t) {
|
|
|
15432
15453
|
workspace_identity: e.workspace_identity,
|
|
15433
15454
|
scope_id: Ei
|
|
15434
15455
|
});
|
|
15435
|
-
let r = (t.get(
|
|
15456
|
+
let r = (t.get(gy(e)) ?? []).filter((t) => t.workspace_identity !== e.workspace_identity);
|
|
15436
15457
|
return r.length > 0 && n.push({
|
|
15437
15458
|
code: "basename_collision_review",
|
|
15438
15459
|
severity: "info",
|
|
@@ -15441,21 +15462,21 @@ function _y(e, t) {
|
|
|
15441
15462
|
workspace_identity: e.workspace_identity,
|
|
15442
15463
|
related_workspace_identities: r.map((e) => e.workspace_identity),
|
|
15443
15464
|
related_projects: r.map((e) => e.display_project)
|
|
15444
|
-
}), n.map(
|
|
15465
|
+
}), n.map(my);
|
|
15445
15466
|
}
|
|
15446
|
-
function
|
|
15447
|
-
let t =
|
|
15467
|
+
function yy(e) {
|
|
15468
|
+
let t = _y(e);
|
|
15448
15469
|
return e.map((e) => ({
|
|
15449
15470
|
...e,
|
|
15450
|
-
guardrail_warnings:
|
|
15471
|
+
guardrail_warnings: vy(e, t)
|
|
15451
15472
|
}));
|
|
15452
15473
|
}
|
|
15453
|
-
function
|
|
15474
|
+
function by(e) {
|
|
15454
15475
|
let t = /* @__PURE__ */ new Set();
|
|
15455
15476
|
return e.resolved_scope_id === "local-default" && t.add("local_only"), e.resolved_scope_id === "legacy-shared-review" && t.add("legacy_review"), e.identity_source === "unmapped" && t.add("unmapped"), e.suggested_scope_id && e.suggested_scope_id !== e.resolved_scope_id && t.add("suggested"), e.mapping_id != null && t.add("explicitly_mapped"), (e.guardrail_warnings ?? []).some((e) => e.severity === "warning") && t.add("needs_attention"), [...t].sort();
|
|
15456
15477
|
}
|
|
15457
|
-
function
|
|
15458
|
-
let n =
|
|
15478
|
+
function xy(e, t) {
|
|
15479
|
+
let n = ty(t)?.toLowerCase();
|
|
15459
15480
|
return n ? [
|
|
15460
15481
|
e.display_project,
|
|
15461
15482
|
e.project,
|
|
@@ -15467,7 +15488,7 @@ function by(e, t) {
|
|
|
15467
15488
|
e.suggested_scope_id
|
|
15468
15489
|
].filter((e) => typeof e == "string" && e.length > 0).some((e) => e.toLowerCase().includes(n)) : !0;
|
|
15469
15490
|
}
|
|
15470
|
-
function
|
|
15491
|
+
function Sy(e, t, n) {
|
|
15471
15492
|
let r = Mi({
|
|
15472
15493
|
gitRemote: e.git_remote,
|
|
15473
15494
|
gitBranch: e.git_branch,
|
|
@@ -15484,11 +15505,11 @@ function xy(e, t, n) {
|
|
|
15484
15505
|
}), a = {
|
|
15485
15506
|
workspace_identity: r.value,
|
|
15486
15507
|
identity_source: r.source,
|
|
15487
|
-
display_project: r.displayProject ??
|
|
15488
|
-
project:
|
|
15489
|
-
cwd:
|
|
15490
|
-
git_remote:
|
|
15491
|
-
git_branch:
|
|
15508
|
+
display_project: r.displayProject ?? ty(e.project) ?? ty(e.cwd) ?? r.value,
|
|
15509
|
+
project: ty(e.project),
|
|
15510
|
+
cwd: ty(e.cwd),
|
|
15511
|
+
git_remote: ty(e.git_remote),
|
|
15512
|
+
git_branch: ty(e.git_branch),
|
|
15492
15513
|
latest_session_at: e.started_at,
|
|
15493
15514
|
resolved_scope_id: i.scopeId,
|
|
15494
15515
|
resolution_reason: i.reason,
|
|
@@ -15498,7 +15519,7 @@ function xy(e, t, n) {
|
|
|
15498
15519
|
suggestion_reason: null,
|
|
15499
15520
|
suggestion_signal: null,
|
|
15500
15521
|
guardrail_warnings: []
|
|
15501
|
-
}, o =
|
|
15522
|
+
}, o = ly(a, n);
|
|
15502
15523
|
return {
|
|
15503
15524
|
...a,
|
|
15504
15525
|
suggested_scope_id: o?.scopeId ?? null,
|
|
@@ -15506,7 +15527,7 @@ function xy(e, t, n) {
|
|
|
15506
15527
|
suggestion_signal: o?.signal ?? null
|
|
15507
15528
|
};
|
|
15508
15529
|
}
|
|
15509
|
-
function
|
|
15530
|
+
function Cy(e) {
|
|
15510
15531
|
let t = /* @__PURE__ */ new Set();
|
|
15511
15532
|
return e.filter((e) => {
|
|
15512
15533
|
let n = [
|
|
@@ -15517,28 +15538,28 @@ function Sy(e) {
|
|
|
15517
15538
|
e.related_workspace_identities?.join("|") ?? ""
|
|
15518
15539
|
].join("\0");
|
|
15519
15540
|
return t.has(n) ? !1 : (t.add(n), !0);
|
|
15520
|
-
}).map(
|
|
15541
|
+
}).map(my);
|
|
15521
15542
|
}
|
|
15522
|
-
function
|
|
15543
|
+
function wy(e, t) {
|
|
15523
15544
|
if (!e && !/[\\/:]/.test(t) && !(/[*?]/.test(t) && /[\\/:]/.test(t.replace(/[*?]/g, "")))) throw Error("project_pattern must use a canonical path, remote, or workspace pattern");
|
|
15524
15545
|
}
|
|
15525
|
-
function
|
|
15546
|
+
function Ty(e) {
|
|
15526
15547
|
return {
|
|
15527
15548
|
scope_id: String(e.scope_id ?? ""),
|
|
15528
15549
|
label: String(e.label ?? ""),
|
|
15529
15550
|
kind: String(e.kind ?? "user"),
|
|
15530
15551
|
authority_type: String(e.authority_type ?? "local"),
|
|
15531
|
-
coordinator_id:
|
|
15532
|
-
group_id:
|
|
15552
|
+
coordinator_id: ty(e.coordinator_id),
|
|
15553
|
+
group_id: ty(e.group_id),
|
|
15533
15554
|
membership_epoch: Number(e.membership_epoch ?? 0),
|
|
15534
15555
|
status: String(e.status ?? "active"),
|
|
15535
15556
|
updated_at: String(e.updated_at ?? "")
|
|
15536
15557
|
};
|
|
15537
15558
|
}
|
|
15538
|
-
function
|
|
15559
|
+
function Ey(e) {
|
|
15539
15560
|
return {
|
|
15540
15561
|
id: Number(e.id ?? 0),
|
|
15541
|
-
workspace_identity:
|
|
15562
|
+
workspace_identity: ny(e.workspace_identity),
|
|
15542
15563
|
project_pattern: String(e.project_pattern ?? ""),
|
|
15543
15564
|
scope_id: String(e.scope_id ?? ""),
|
|
15544
15565
|
priority: Number(e.priority ?? 0),
|
|
@@ -15548,55 +15569,55 @@ function Ty(e) {
|
|
|
15548
15569
|
guardrail_warnings: []
|
|
15549
15570
|
};
|
|
15550
15571
|
}
|
|
15551
|
-
function Ey(e) {
|
|
15552
|
-
return Vv(e), e.prepare("SELECT scope_id, label, kind, authority_type, coordinator_id, group_id,\n membership_epoch, status, updated_at\n FROM replication_scopes\n WHERE status = 'active'\n ORDER BY CASE WHEN scope_id = ? THEN 0 ELSE 1 END, label COLLATE NOCASE, scope_id").all(Ei).map((e) => wy(e));
|
|
15553
|
-
}
|
|
15554
15572
|
function Dy(e) {
|
|
15555
|
-
|
|
15556
|
-
|
|
15573
|
+
return Hv(e), e.prepare("SELECT scope_id, label, kind, authority_type, coordinator_id, group_id,\n membership_epoch, status, updated_at\n FROM replication_scopes\n WHERE status = 'active'\n ORDER BY CASE WHEN scope_id = ? THEN 0 ELSE 1 END, label COLLATE NOCASE, scope_id").all(Ei).map((e) => Ty(e));
|
|
15574
|
+
}
|
|
15575
|
+
function Oy(e) {
|
|
15576
|
+
Hv(e);
|
|
15577
|
+
let t = iy(Dy(e));
|
|
15557
15578
|
return e.prepare("SELECT id, workspace_identity, project_pattern, scope_id, priority, source, created_at, updated_at\n FROM project_scope_mappings\n ORDER BY priority DESC, updated_at DESC, id DESC").all().map((e) => {
|
|
15558
|
-
let n =
|
|
15579
|
+
let n = Ey(e);
|
|
15559
15580
|
return {
|
|
15560
15581
|
...n,
|
|
15561
|
-
guardrail_warnings:
|
|
15582
|
+
guardrail_warnings: hy(n, t)
|
|
15562
15583
|
};
|
|
15563
15584
|
});
|
|
15564
15585
|
}
|
|
15565
|
-
function
|
|
15586
|
+
function ky(e, t) {
|
|
15566
15587
|
let n = e.prepare("SELECT id, workspace_identity, project_pattern, scope_id, priority, source, created_at, updated_at\n FROM project_scope_mappings\n WHERE id = ?\n LIMIT 1").get(t);
|
|
15567
|
-
return n ?
|
|
15588
|
+
return n ? Ey(n) : null;
|
|
15568
15589
|
}
|
|
15569
|
-
function
|
|
15590
|
+
function Ay(e, t) {
|
|
15570
15591
|
let n = e.prepare("SELECT id, workspace_identity, project_pattern, scope_id, priority, source, created_at, updated_at\n FROM project_scope_mappings\n WHERE workspace_identity = ?\n ORDER BY priority DESC, updated_at DESC, id DESC\n LIMIT 1").get(t);
|
|
15571
|
-
return n ?
|
|
15592
|
+
return n ? Ey(n) : null;
|
|
15572
15593
|
}
|
|
15573
|
-
function
|
|
15594
|
+
function jy(e, t) {
|
|
15574
15595
|
if (t === "legacy-shared-review") throw Error("legacy-shared-review is a review bucket, not an assignable Sharing domain");
|
|
15575
15596
|
if (!e.prepare("SELECT 1 FROM replication_scopes WHERE scope_id = ? AND status = 'active' LIMIT 1").get(t)) throw Error(`scope_id ${t} is not an active Sharing domain`);
|
|
15576
15597
|
}
|
|
15577
|
-
function
|
|
15578
|
-
let n = t.id == null ? null : Number(t.id), r = n && Number.isInteger(n) ?
|
|
15598
|
+
function My(e, t) {
|
|
15599
|
+
let n = t.id == null ? null : Number(t.id), r = n && Number.isInteger(n) ? ky(e, n) : null, i = ny(t.workspace_identity) ?? r?.workspace_identity ?? null, a = i ? Ay(e, i) : null, o = r ?? a, s = ty(t.project_pattern) ?? o?.project_pattern ?? i, c = t.priority == null ? o?.priority ?? 0 : Number(t.priority);
|
|
15579
15600
|
return {
|
|
15580
15601
|
existing: o,
|
|
15581
15602
|
workspaceIdentity: i,
|
|
15582
15603
|
projectPattern: s,
|
|
15583
|
-
scopeId:
|
|
15604
|
+
scopeId: ty(t.scope_id) ?? "",
|
|
15584
15605
|
priority: c,
|
|
15585
|
-
source:
|
|
15606
|
+
source: ty(t.source) ?? "user"
|
|
15586
15607
|
};
|
|
15587
15608
|
}
|
|
15588
|
-
function
|
|
15589
|
-
|
|
15590
|
-
let n =
|
|
15591
|
-
n.projectPattern && n.scopeId && i.push(...
|
|
15609
|
+
function Ny(e, t) {
|
|
15610
|
+
Hv(e);
|
|
15611
|
+
let n = My(e, t), r = iy(Dy(e)), i = [];
|
|
15612
|
+
n.projectPattern && n.scopeId && i.push(...hy({
|
|
15592
15613
|
id: n.existing?.id ?? 0,
|
|
15593
15614
|
workspace_identity: n.workspaceIdentity,
|
|
15594
15615
|
project_pattern: n.projectPattern,
|
|
15595
15616
|
scope_id: n.scopeId
|
|
15596
15617
|
}, r));
|
|
15597
|
-
let a = n.workspaceIdentity ?
|
|
15598
|
-
if (a && i.push(...a.guardrail_warnings.filter((e) => e.code !== "basename_collision_review" ||
|
|
15599
|
-
let e =
|
|
15618
|
+
let a = n.workspaceIdentity ? Py(e, { limit: null }).find((e) => e.workspace_identity === n.workspaceIdentity) : null, o = r.get(n.scopeId);
|
|
15619
|
+
if (a && i.push(...a.guardrail_warnings.filter((e) => e.code !== "basename_collision_review" || ay(o))), n.scopeId && n.existing && n.existing.scope_id !== n.scopeId) {
|
|
15620
|
+
let e = ry(r.get(n.existing.scope_id), n.existing.scope_id), t = ry(r.get(n.scopeId), n.scopeId);
|
|
15600
15621
|
i.push({
|
|
15601
15622
|
code: "scope_reassignment_old_copies",
|
|
15602
15623
|
severity: "warning",
|
|
@@ -15614,12 +15635,12 @@ function My(e, t) {
|
|
|
15614
15635
|
requested_scope_id: n.scopeId,
|
|
15615
15636
|
requested_workspace_identity: n.workspaceIdentity,
|
|
15616
15637
|
requested_project_pattern: n.projectPattern,
|
|
15617
|
-
warnings:
|
|
15638
|
+
warnings: Cy(i)
|
|
15618
15639
|
};
|
|
15619
15640
|
}
|
|
15620
|
-
function
|
|
15621
|
-
|
|
15622
|
-
let n = t.limit === null ? null : Math.max(1, Math.min(t.limit ?? 250, 1e3)), r =
|
|
15641
|
+
function Py(e, t = {}) {
|
|
15642
|
+
Hv(e);
|
|
15643
|
+
let n = t.limit === null ? null : Math.max(1, Math.min(t.limit ?? 250, 1e3)), r = Oy(e), i = Dy(e), a = `SELECT
|
|
15623
15644
|
s.id,
|
|
15624
15645
|
s.started_at,
|
|
15625
15646
|
s.cwd,
|
|
@@ -15647,15 +15668,15 @@ function Ny(e, t = {}) {
|
|
|
15647
15668
|
project: e.project,
|
|
15648
15669
|
workspaceId: e.workspace_id
|
|
15649
15670
|
});
|
|
15650
|
-
s.has(t.value) || (s.add(t.value), c.push(
|
|
15671
|
+
s.has(t.value) || (s.add(t.value), c.push(Sy(e, r, i)));
|
|
15651
15672
|
}
|
|
15652
|
-
return
|
|
15673
|
+
return yy(c.toSorted((e, t) => e.display_project.localeCompare(t.display_project) || e.workspace_identity.localeCompare(t.workspace_identity)));
|
|
15653
15674
|
}
|
|
15654
|
-
function
|
|
15655
|
-
|
|
15656
|
-
let n = Math.max(1, Math.min(t.limit ?? 50, 250)), r = Math.max(0, t.offset ?? 0), i =
|
|
15675
|
+
function Fy(e, t = {}) {
|
|
15676
|
+
Hv(e);
|
|
15677
|
+
let n = Math.max(1, Math.min(t.limit ?? 50, 250)), r = Math.max(0, t.offset ?? 0), i = Oy(e), a = Dy(e), o = e.prepare("SELECT\n s.id,\n MAX(s.started_at) AS started_at,\n s.cwd,\n s.project,\n s.git_remote,\n s.git_branch,\n (\n SELECT mi.workspace_id\n FROM memory_items mi\n WHERE mi.session_id = s.id\n AND mi.workspace_id IS NOT NULL\n AND TRIM(mi.workspace_id) <> ''\n ORDER BY mi.id DESC\n LIMIT 1\n ) AS workspace_id,\n COUNT(DISTINCT s.id) AS session_count,\n COUNT(mi_count.id) AS memory_count\n FROM sessions s\n LEFT JOIN memory_items mi_count ON mi_count.session_id = s.id\n WHERE COALESCE(TRIM(s.git_remote), TRIM(s.cwd), TRIM(s.project), '') <> ''\n OR mi_count.id IS NOT NULL\n GROUP BY s.id\n ORDER BY MAX(s.started_at) DESC, s.id DESC").all(), s = /* @__PURE__ */ new Map(), c = [];
|
|
15657
15678
|
for (let e of o) {
|
|
15658
|
-
let t =
|
|
15679
|
+
let t = Sy(e, i, a), n = s.get(t.workspace_identity);
|
|
15659
15680
|
if (n) {
|
|
15660
15681
|
n.memory_count = (n.memory_count ?? 0) + Number(e.memory_count ?? 0), n.session_count += Number(e.session_count ?? 1);
|
|
15661
15682
|
continue;
|
|
@@ -15693,15 +15714,15 @@ function Py(e, t = {}) {
|
|
|
15693
15714
|
};
|
|
15694
15715
|
s.set(e.workspace_identity, t), c.push(t);
|
|
15695
15716
|
}
|
|
15696
|
-
let l =
|
|
15717
|
+
let l = yy(c).map((e) => {
|
|
15697
15718
|
let t = c.find((t) => t.workspace_identity === e.workspace_identity);
|
|
15698
15719
|
return {
|
|
15699
15720
|
...e,
|
|
15700
15721
|
memory_count: t?.memory_count ?? null,
|
|
15701
15722
|
session_count: t?.session_count ?? 0,
|
|
15702
|
-
statuses:
|
|
15723
|
+
statuses: by(e)
|
|
15703
15724
|
};
|
|
15704
|
-
}).filter((e) =>
|
|
15725
|
+
}).filter((e) => xy(e, t.query)).filter((e) => !t.scopeId || e.resolved_scope_id === t.scopeId).filter((e) => !t.identitySource || e.identity_source === t.identitySource).filter((e) => !t.status || e.statuses.some((e) => e === t.status)).toSorted((e, t) => (e.latest_session_at == null ? 1 : t.latest_session_at == null ? -1 : 0) || String(t.latest_session_at ?? "").localeCompare(String(e.latest_session_at ?? "")) || e.display_project.localeCompare(t.display_project) || e.workspace_identity.localeCompare(t.workspace_identity));
|
|
15705
15726
|
return {
|
|
15706
15727
|
projects: l.slice(r, r + n),
|
|
15707
15728
|
total: l.length,
|
|
@@ -15710,12 +15731,12 @@ function Py(e, t = {}) {
|
|
|
15710
15731
|
has_more: r + n < l.length
|
|
15711
15732
|
};
|
|
15712
15733
|
}
|
|
15713
|
-
function
|
|
15714
|
-
|
|
15715
|
-
let n =
|
|
15734
|
+
function Iy(e, t) {
|
|
15735
|
+
Hv(e);
|
|
15736
|
+
let n = ny(t.workspaceIdentity);
|
|
15716
15737
|
if (!n) throw Error("workspace_identity must be a non-empty string");
|
|
15717
15738
|
if (n.startsWith("unmapped:")) throw Error("unmapped projects cannot be reassigned until they have a stable identity");
|
|
15718
|
-
let r =
|
|
15739
|
+
let r = ty(t.project);
|
|
15719
15740
|
if (!r) throw Error("project must be a non-empty string");
|
|
15720
15741
|
let i = e.prepare("SELECT\n s.id,\n s.started_at,\n s.cwd,\n s.project,\n s.git_remote,\n s.git_branch,\n (\n SELECT mi.workspace_id\n FROM memory_items mi\n WHERE mi.session_id = s.id\n AND mi.workspace_id IS NOT NULL\n AND TRIM(mi.workspace_id) <> ''\n ORDER BY mi.id DESC\n LIMIT 1\n ) AS workspace_id,\n COUNT(mi_count.id) AS memory_count\n FROM sessions s\n LEFT JOIN memory_items mi_count ON mi_count.session_id = s.id\n WHERE COALESCE(TRIM(s.git_remote), TRIM(s.cwd), TRIM(s.project), '') <> ''\n OR mi_count.id IS NOT NULL\n GROUP BY s.id").all().filter((e) => Mi({
|
|
15721
15742
|
gitRemote: e.git_remote,
|
|
@@ -15725,7 +15746,7 @@ function Fy(e, t) {
|
|
|
15725
15746
|
workspaceId: e.workspace_id
|
|
15726
15747
|
}).value === n);
|
|
15727
15748
|
if (i.length === 0) throw Error("project identity not found");
|
|
15728
|
-
let a = [...new Set(i.map((e) =>
|
|
15749
|
+
let a = [...new Set(i.map((e) => ty(e.project) ?? "").filter(Boolean))].sort(), o = i.reduce((e, t) => e + Number(t.memory_count ?? 0), 0), s = e.prepare("UPDATE sessions SET project = ? WHERE id = ?");
|
|
15729
15750
|
return e.transaction(() => {
|
|
15730
15751
|
for (let e of i) s.run(r, e.id);
|
|
15731
15752
|
})(), {
|
|
@@ -15736,48 +15757,48 @@ function Fy(e, t) {
|
|
|
15736
15757
|
workspace_identity: n
|
|
15737
15758
|
};
|
|
15738
15759
|
}
|
|
15739
|
-
function
|
|
15740
|
-
|
|
15741
|
-
let n =
|
|
15760
|
+
function Ly(e, t) {
|
|
15761
|
+
Hv(e);
|
|
15762
|
+
let n = My(e, t), r = n.scopeId;
|
|
15742
15763
|
if (!r) throw Error("scope_id must be a non-empty string");
|
|
15743
|
-
|
|
15764
|
+
jy(e, r);
|
|
15744
15765
|
let { existing: i, workspaceIdentity: a } = n;
|
|
15745
15766
|
if (a?.startsWith("unmapped:")) throw Error("unmapped projects cannot be assigned to a Sharing domain");
|
|
15746
15767
|
let o = n.projectPattern;
|
|
15747
15768
|
if (!o) throw Error("project_pattern or workspace_identity is required");
|
|
15748
|
-
|
|
15769
|
+
wy(a, o);
|
|
15749
15770
|
let s = n.priority;
|
|
15750
15771
|
if (!Number.isFinite(s) || !Number.isInteger(s)) throw Error("priority must be an integer");
|
|
15751
15772
|
let c = n.source, l = (/* @__PURE__ */ new Date()).toISOString();
|
|
15752
15773
|
if (i) {
|
|
15753
15774
|
e.prepare("UPDATE project_scope_mappings\n SET workspace_identity = ?, project_pattern = ?, scope_id = ?, priority = ?, source = ?, updated_at = ?\n WHERE id = ?").run(a, o, r, s, c, l, i.id);
|
|
15754
|
-
let t =
|
|
15775
|
+
let t = ky(e, i.id);
|
|
15755
15776
|
if (!t) throw Error("project_scope_mapping update returned no row");
|
|
15756
15777
|
return t;
|
|
15757
15778
|
}
|
|
15758
|
-
let u = e.prepare("INSERT INTO project_scope_mappings(\n workspace_identity, project_pattern, scope_id, priority, source, created_at, updated_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?)").run(a, o, r, s, c, l, l), d =
|
|
15779
|
+
let u = e.prepare("INSERT INTO project_scope_mappings(\n workspace_identity, project_pattern, scope_id, priority, source, created_at, updated_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?)").run(a, o, r, s, c, l, l), d = ky(e, Number(u.lastInsertRowid));
|
|
15759
15780
|
if (!d) throw Error("project_scope_mapping insert returned no row");
|
|
15760
15781
|
return d;
|
|
15761
15782
|
}
|
|
15762
|
-
function
|
|
15783
|
+
function Ry(e, t) {
|
|
15763
15784
|
if (!Number.isInteger(t) || t <= 0) throw Error("id must be a positive integer");
|
|
15764
15785
|
let n = e.prepare("DELETE FROM project_scope_mappings WHERE id = ?").run(t);
|
|
15765
15786
|
return Number(n.changes ?? 0) > 0;
|
|
15766
15787
|
}
|
|
15767
15788
|
//#endregion
|
|
15768
15789
|
//#region src/raw-event-sweeper.ts
|
|
15769
|
-
var
|
|
15770
|
-
function
|
|
15790
|
+
var zy = 60;
|
|
15791
|
+
function By(e, t) {
|
|
15771
15792
|
let n = process.env[e];
|
|
15772
15793
|
if (n == null) return t;
|
|
15773
15794
|
let r = Number.parseInt(n, 10);
|
|
15774
15795
|
return Number.isFinite(r) ? r : t;
|
|
15775
15796
|
}
|
|
15776
|
-
function
|
|
15797
|
+
function Vy(e) {
|
|
15777
15798
|
let t = (process.env[e] ?? "1").trim().toLowerCase();
|
|
15778
15799
|
return t === "0" || t === "false" || t === "off";
|
|
15779
15800
|
}
|
|
15780
|
-
var
|
|
15801
|
+
var Hy = class {
|
|
15781
15802
|
store;
|
|
15782
15803
|
ingestOpts;
|
|
15783
15804
|
active = !1;
|
|
@@ -15795,7 +15816,7 @@ var Vy = class {
|
|
|
15795
15816
|
this.store = e, this.ingestOpts = t;
|
|
15796
15817
|
}
|
|
15797
15818
|
enabled() {
|
|
15798
|
-
return !
|
|
15819
|
+
return !Vy("CODEMEM_RAW_EVENTS_SWEEPER");
|
|
15799
15820
|
}
|
|
15800
15821
|
intervalMs() {
|
|
15801
15822
|
let e = process.env.CODEMEM_RAW_EVENTS_SWEEPER_INTERVAL_MS;
|
|
@@ -15807,31 +15828,31 @@ var Vy = class {
|
|
|
15807
15828
|
return Number.isFinite(n) && n > 0 ? Math.max(1e3, n * 1e3) : 3e4;
|
|
15808
15829
|
}
|
|
15809
15830
|
idleMs() {
|
|
15810
|
-
return
|
|
15831
|
+
return By("CODEMEM_RAW_EVENTS_SWEEPER_IDLE_MS", 12e4);
|
|
15811
15832
|
}
|
|
15812
15833
|
limit() {
|
|
15813
|
-
return
|
|
15834
|
+
return By("CODEMEM_RAW_EVENTS_SWEEPER_LIMIT", 25);
|
|
15814
15835
|
}
|
|
15815
15836
|
workerMaxEvents() {
|
|
15816
|
-
let e =
|
|
15837
|
+
let e = By("CODEMEM_RAW_EVENTS_WORKER_MAX_EVENTS", 100);
|
|
15817
15838
|
return e <= 0 ? null : e;
|
|
15818
15839
|
}
|
|
15819
15840
|
retentionMs() {
|
|
15820
|
-
return
|
|
15841
|
+
return By("CODEMEM_RAW_EVENTS_RETENTION_MS", 0);
|
|
15821
15842
|
}
|
|
15822
15843
|
autoFlushEnabled() {
|
|
15823
15844
|
return (process.env.CODEMEM_RAW_EVENTS_AUTO_FLUSH ?? "").trim() === "1";
|
|
15824
15845
|
}
|
|
15825
15846
|
debounceMs() {
|
|
15826
|
-
return
|
|
15847
|
+
return By("CODEMEM_RAW_EVENTS_DEBOUNCE_MS", 6e4);
|
|
15827
15848
|
}
|
|
15828
15849
|
stuckBatchMs() {
|
|
15829
|
-
return
|
|
15850
|
+
return By("CODEMEM_RAW_EVENTS_STUCK_BATCH_MS", 3e5);
|
|
15830
15851
|
}
|
|
15831
15852
|
handleAuthError(e) {
|
|
15832
|
-
if (this.authBackoffUntil = Date.now() / 1e3 +
|
|
15853
|
+
if (this.authBackoffUntil = Date.now() / 1e3 + zy, !this.authErrorLogged) {
|
|
15833
15854
|
this.authErrorLogged = !0;
|
|
15834
|
-
let t = `codemem: observer auth error — backing off for ${
|
|
15855
|
+
let t = `codemem: observer auth error — backing off for ${zy}s. Refresh your provider credentials or update observer_provider in settings. (${e.message})`;
|
|
15835
15856
|
console.error(t);
|
|
15836
15857
|
}
|
|
15837
15858
|
}
|
|
@@ -15911,7 +15932,7 @@ var Vy = class {
|
|
|
15911
15932
|
r && (clearTimeout(r), this.autoFlushTimers.delete(n));
|
|
15912
15933
|
try {
|
|
15913
15934
|
let n = this.workerMaxEvents();
|
|
15914
|
-
await
|
|
15935
|
+
await bv(this.store, this.ingestOpts, {
|
|
15915
15936
|
opencodeSessionId: e,
|
|
15916
15937
|
source: t,
|
|
15917
15938
|
cwd: null,
|
|
@@ -15968,7 +15989,7 @@ var Vy = class {
|
|
|
15968
15989
|
if (!this.sessionFlushing.has(r)) {
|
|
15969
15990
|
this.sessionFlushing.add(r);
|
|
15970
15991
|
try {
|
|
15971
|
-
await
|
|
15992
|
+
await bv(this.store, this.ingestOpts, {
|
|
15972
15993
|
opencodeSessionId: n,
|
|
15973
15994
|
source: t,
|
|
15974
15995
|
cwd: null,
|
|
@@ -15995,7 +16016,7 @@ var Vy = class {
|
|
|
15995
16016
|
if (!this.sessionFlushing.has(r)) {
|
|
15996
16017
|
this.sessionFlushing.add(r);
|
|
15997
16018
|
try {
|
|
15998
|
-
await
|
|
16019
|
+
await bv(this.store, this.ingestOpts, {
|
|
15999
16020
|
opencodeSessionId: n,
|
|
16000
16021
|
source: t,
|
|
16001
16022
|
cwd: null,
|
|
@@ -16015,16 +16036,16 @@ var Vy = class {
|
|
|
16015
16036
|
}
|
|
16016
16037
|
}
|
|
16017
16038
|
}
|
|
16018
|
-
},
|
|
16019
|
-
function
|
|
16039
|
+
}, Uy = "memory_ref_backfill", Wy = "mi.active = 1\n AND (\n (\n (\n (json_valid(mi.files_read) AND json_type(mi.files_read) = 'array' AND json_array_length(mi.files_read) > 0)\n OR\n (json_valid(mi.files_modified) AND json_type(mi.files_modified) = 'array' AND json_array_length(mi.files_modified) > 0)\n )\n AND NOT EXISTS (\n SELECT 1 FROM memory_file_refs mfr WHERE mfr.memory_id = mi.id\n )\n )\n OR\n (\n json_valid(mi.concepts)\n AND json_type(mi.concepts) = 'array'\n AND json_array_length(mi.concepts) > 0\n AND NOT EXISTS (\n SELECT 1 FROM memory_concept_refs mcr WHERE mcr.memory_id = mi.id\n )\n )\n )";
|
|
16040
|
+
function Gy(e) {
|
|
16020
16041
|
return e.prepare(`SELECT 1 FROM memory_items mi
|
|
16021
|
-
WHERE ${
|
|
16042
|
+
WHERE ${Wy}
|
|
16022
16043
|
LIMIT 1`).get() != null;
|
|
16023
16044
|
}
|
|
16024
|
-
function
|
|
16045
|
+
function Ky(e) {
|
|
16025
16046
|
return Q(e, "memory_ref_backfill")?.metadata ?? {};
|
|
16026
16047
|
}
|
|
16027
|
-
function
|
|
16048
|
+
function qy(e) {
|
|
16028
16049
|
if (!e) return null;
|
|
16029
16050
|
try {
|
|
16030
16051
|
let t = JSON.parse(e);
|
|
@@ -16032,17 +16053,17 @@ function Ky(e) {
|
|
|
16032
16053
|
} catch {}
|
|
16033
16054
|
return null;
|
|
16034
16055
|
}
|
|
16035
|
-
async function
|
|
16036
|
-
let n = Q(e,
|
|
16056
|
+
async function Jy(e, t = {}) {
|
|
16057
|
+
let n = Q(e, Uy), r = Ky(e), i = Math.max(1, t.batchSize ?? 50), a = !n || n.status === "completed" || n.status === "failed", o = a ? 0 : Number(r.last_cursor_id ?? 0), s = e.prepare(`SELECT mi.id, mi.files_read, mi.files_modified, mi.concepts
|
|
16037
16058
|
FROM memory_items mi
|
|
16038
16059
|
WHERE mi.id > ?
|
|
16039
|
-
AND ${
|
|
16060
|
+
AND ${Wy}
|
|
16040
16061
|
ORDER BY mi.id ASC
|
|
16041
16062
|
LIMIT ?`).all(o, i);
|
|
16042
16063
|
if (s.length === 0) {
|
|
16043
16064
|
if (n && n.status !== "completed") {
|
|
16044
16065
|
let t = Number(r.processed ?? 0);
|
|
16045
|
-
Yr(e,
|
|
16066
|
+
Yr(e, Uy, {
|
|
16046
16067
|
message: "Ref backfill complete",
|
|
16047
16068
|
progressCurrent: t,
|
|
16048
16069
|
progressTotal: Number(r.total_backfillable ?? t),
|
|
@@ -16058,9 +16079,9 @@ async function qy(e, t = {}) {
|
|
|
16058
16079
|
let c = a ? 0 : Number(r.processed ?? 0), l = Number(r.total_backfillable ?? 0);
|
|
16059
16080
|
if (a) {
|
|
16060
16081
|
let t = e.prepare(`SELECT COUNT(*) AS cnt FROM memory_items mi
|
|
16061
|
-
WHERE ${
|
|
16082
|
+
WHERE ${Wy}`).get().cnt;
|
|
16062
16083
|
qr(e, {
|
|
16063
|
-
kind:
|
|
16084
|
+
kind: Uy,
|
|
16064
16085
|
title: "Backfilling memory file/concept refs",
|
|
16065
16086
|
message: `Backfilling refs for ${t} memories`,
|
|
16066
16087
|
progressTotal: t,
|
|
@@ -16073,7 +16094,7 @@ async function qy(e, t = {}) {
|
|
|
16073
16094
|
}), l = t;
|
|
16074
16095
|
}
|
|
16075
16096
|
let u = e.prepare("INSERT OR IGNORE INTO memory_file_refs (memory_id, file_path, relation) VALUES (?, ?, ?)"), d = e.prepare("INSERT OR IGNORE INTO memory_concept_refs (memory_id, concept) VALUES (?, ?)"), f = e.transaction((e) => {
|
|
16076
|
-
let t =
|
|
16097
|
+
let t = qy(e.files_read), n = qy(e.files_modified), r = qy(e.concepts);
|
|
16077
16098
|
if (t) for (let n of t) n && u.run(e.id, n, "read");
|
|
16078
16099
|
if (n) for (let t of n) t && u.run(e.id, t, "modified");
|
|
16079
16100
|
if (r) for (let t of r) {
|
|
@@ -16084,8 +16105,8 @@ async function qy(e, t = {}) {
|
|
|
16084
16105
|
for (let e of s) f(e);
|
|
16085
16106
|
let p = c + s.length, m = s.length < i, h = s[s.length - 1].id;
|
|
16086
16107
|
if (m) {
|
|
16087
|
-
let t = Number(
|
|
16088
|
-
return Yr(e,
|
|
16108
|
+
let t = Number(Ky(e).total_backfillable ?? l ?? p);
|
|
16109
|
+
return Yr(e, Uy, {
|
|
16089
16110
|
message: "Ref backfill complete",
|
|
16090
16111
|
progressCurrent: t,
|
|
16091
16112
|
progressTotal: t,
|
|
@@ -16097,7 +16118,7 @@ async function qy(e, t = {}) {
|
|
|
16097
16118
|
}
|
|
16098
16119
|
}), !1;
|
|
16099
16120
|
}
|
|
16100
|
-
return Jr(e,
|
|
16121
|
+
return Jr(e, Uy, {
|
|
16101
16122
|
message: `Backfilled refs for ${p} of ${l} memories`,
|
|
16102
16123
|
progressCurrent: p,
|
|
16103
16124
|
progressTotal: l,
|
|
@@ -16109,7 +16130,7 @@ async function qy(e, t = {}) {
|
|
|
16109
16130
|
}
|
|
16110
16131
|
}), !0;
|
|
16111
16132
|
}
|
|
16112
|
-
var
|
|
16133
|
+
var Yy = class {
|
|
16113
16134
|
dbPath;
|
|
16114
16135
|
signal;
|
|
16115
16136
|
batchSize;
|
|
@@ -16139,14 +16160,14 @@ var Jy = class {
|
|
|
16139
16160
|
if (!this.active || this.signal?.aborted) return;
|
|
16140
16161
|
let e = null;
|
|
16141
16162
|
try {
|
|
16142
|
-
e = Mn(this.dbPath), await
|
|
16163
|
+
e = Mn(this.dbPath), await Jy(e, { batchSize: this.batchSize }) || (this.active = !1);
|
|
16143
16164
|
} catch (t) {
|
|
16144
|
-
e && Xr(e,
|
|
16165
|
+
e && Xr(e, Uy, t instanceof Error ? t.message : String(t)), console.warn("Ref backfill runner failed", t);
|
|
16145
16166
|
} finally {
|
|
16146
16167
|
e?.close();
|
|
16147
16168
|
}
|
|
16148
16169
|
}
|
|
16149
|
-
},
|
|
16170
|
+
}, Xy = "session_context_backfill", Zy = [
|
|
16150
16171
|
"firstPrompt",
|
|
16151
16172
|
"promptCount",
|
|
16152
16173
|
"toolCount",
|
|
@@ -16154,20 +16175,20 @@ var Jy = class {
|
|
|
16154
16175
|
"filesModified",
|
|
16155
16176
|
"filesRead"
|
|
16156
16177
|
];
|
|
16157
|
-
function
|
|
16178
|
+
function Qy(e) {
|
|
16158
16179
|
let t = e.prepare("SELECT COUNT(*) AS c FROM sessions\n WHERE json_extract(metadata_json, '$.session_context.flusher') = 'raw_events'").get();
|
|
16159
16180
|
return Number(t?.c ?? 0);
|
|
16160
16181
|
}
|
|
16161
|
-
function
|
|
16182
|
+
function $y(e, t, n) {
|
|
16162
16183
|
return e.prepare("SELECT\n s.id AS id,\n s.metadata_json AS metadata_json,\n os.source AS source,\n os.stream_id AS stream_id\n FROM sessions s\n LEFT JOIN (\n SELECT session_id, source, stream_id\n FROM opencode_sessions\n GROUP BY session_id\n ) os ON os.session_id = s.id\n WHERE s.id > ?\n AND json_extract(s.metadata_json, '$.session_context.flusher') = 'raw_events'\n ORDER BY s.id ASC\n LIMIT ?").all(t, n);
|
|
16163
16184
|
}
|
|
16164
|
-
function
|
|
16185
|
+
function eb(e, t, n) {
|
|
16165
16186
|
return e.prepare("SELECT event_seq, event_type, ts_wall_ms, ts_mono_ms, payload_json, event_id\n FROM raw_events\n WHERE source = ? AND stream_id = ?\n ORDER BY event_seq ASC").all(t, n).map((e) => {
|
|
16166
16187
|
let t = JSON.parse(e.payload_json);
|
|
16167
16188
|
return t.type = t.type || e.event_type, t.timestamp_wall_ms = e.ts_wall_ms, t.timestamp_mono_ms = e.ts_mono_ms, t.event_seq = e.event_seq, t.event_id = e.event_id, t;
|
|
16168
16189
|
});
|
|
16169
16190
|
}
|
|
16170
|
-
function
|
|
16191
|
+
function tb(e) {
|
|
16171
16192
|
if (!e) return {};
|
|
16172
16193
|
try {
|
|
16173
16194
|
let t = JSON.parse(e);
|
|
@@ -16175,42 +16196,42 @@ function eb(e) {
|
|
|
16175
16196
|
} catch {}
|
|
16176
16197
|
return {};
|
|
16177
16198
|
}
|
|
16178
|
-
function
|
|
16199
|
+
function nb(e) {
|
|
16179
16200
|
return Array.isArray(e) ? [...e].sort() : e ?? null;
|
|
16180
16201
|
}
|
|
16181
|
-
function
|
|
16182
|
-
for (let n of
|
|
16183
|
-
let r =
|
|
16202
|
+
function rb(e, t) {
|
|
16203
|
+
for (let n of Zy) {
|
|
16204
|
+
let r = nb(e[n]), i = nb(t[n]);
|
|
16184
16205
|
if (JSON.stringify(r) !== JSON.stringify(i)) return !0;
|
|
16185
16206
|
}
|
|
16186
16207
|
return !1;
|
|
16187
16208
|
}
|
|
16188
|
-
function
|
|
16209
|
+
function ib(e, t) {
|
|
16189
16210
|
let n = { ...e };
|
|
16190
|
-
for (let e of
|
|
16211
|
+
for (let e of Zy) {
|
|
16191
16212
|
let r = t[e];
|
|
16192
16213
|
r === void 0 ? delete n[e] : n[e] = r;
|
|
16193
16214
|
}
|
|
16194
16215
|
return n;
|
|
16195
16216
|
}
|
|
16196
|
-
function
|
|
16217
|
+
function ab(e, t, n) {
|
|
16197
16218
|
let r = 0, i = 0, a = 0, o = 0, s = t.at(-1)?.id ?? 0, c = e.prepare("UPDATE sessions SET metadata_json = ? WHERE id = ?");
|
|
16198
16219
|
for (let n of t) {
|
|
16199
16220
|
if (s = n.id, !n.source || !n.stream_id) {
|
|
16200
16221
|
a += 1;
|
|
16201
16222
|
continue;
|
|
16202
16223
|
}
|
|
16203
|
-
let t =
|
|
16224
|
+
let t = eb(e, n.source, n.stream_id);
|
|
16204
16225
|
if (t.length === 0) {
|
|
16205
16226
|
i += 1;
|
|
16206
16227
|
continue;
|
|
16207
16228
|
}
|
|
16208
|
-
let l =
|
|
16209
|
-
if (!
|
|
16229
|
+
let l = vv(z_(t)), u = tb(n.metadata_json), d = u.session_context, f = d && typeof d == "object" ? d : {};
|
|
16230
|
+
if (!rb(f, l)) {
|
|
16210
16231
|
o += 1;
|
|
16211
16232
|
continue;
|
|
16212
16233
|
}
|
|
16213
|
-
let p =
|
|
16234
|
+
let p = ib(f, l), m = {
|
|
16214
16235
|
...u,
|
|
16215
16236
|
session_context: p
|
|
16216
16237
|
};
|
|
@@ -16226,14 +16247,14 @@ function ib(e, t, n) {
|
|
|
16226
16247
|
exhausted: t.length < n
|
|
16227
16248
|
};
|
|
16228
16249
|
}
|
|
16229
|
-
function
|
|
16230
|
-
return Q(e, "session_context_backfill")?.status === "completed" ? !1 :
|
|
16250
|
+
function ob(e) {
|
|
16251
|
+
return Q(e, "session_context_backfill")?.status === "completed" ? !1 : Qy(e) > 0;
|
|
16231
16252
|
}
|
|
16232
|
-
async function
|
|
16233
|
-
let n = Math.max(1, t.batchSize ?? 100), r = Q(e,
|
|
16253
|
+
async function sb(e, t = {}) {
|
|
16254
|
+
let n = Math.max(1, t.batchSize ?? 100), r = Q(e, Xy), i = r?.metadata ?? {}, a = !r || r.status === "completed" || r.status === "failed", o = a ? 0 : Number(i.last_cursor_id ?? 0), s = a ? Qy(e) : Number(i.total_candidates ?? Qy(e));
|
|
16234
16255
|
if (a && s <= 0) return !1;
|
|
16235
16256
|
a && qr(e, {
|
|
16236
|
-
kind:
|
|
16257
|
+
kind: Xy,
|
|
16237
16258
|
title: "Backfilling session context",
|
|
16238
16259
|
message: `Rebuilding session_context for ${s} raw-event sessions`,
|
|
16239
16260
|
progressTotal: s,
|
|
@@ -16247,11 +16268,11 @@ async function ob(e, t = {}) {
|
|
|
16247
16268
|
unchanged_sessions: 0
|
|
16248
16269
|
}
|
|
16249
16270
|
});
|
|
16250
|
-
let c =
|
|
16271
|
+
let c = $y(e, o, n);
|
|
16251
16272
|
if (c.length === 0) {
|
|
16252
16273
|
let t = Q(e, "session_context_backfill")?.metadata ?? {};
|
|
16253
|
-
return Yr(e,
|
|
16254
|
-
message:
|
|
16274
|
+
return Yr(e, Xy, {
|
|
16275
|
+
message: cb(t),
|
|
16255
16276
|
progressCurrent: Number(t.processed_sessions ?? 0),
|
|
16256
16277
|
progressTotal: Number(t.total_candidates ?? t.processed_sessions ?? 0),
|
|
16257
16278
|
metadata: {
|
|
@@ -16260,7 +16281,7 @@ async function ob(e, t = {}) {
|
|
|
16260
16281
|
}
|
|
16261
16282
|
}), !1;
|
|
16262
16283
|
}
|
|
16263
|
-
let l =
|
|
16284
|
+
let l = ab(e, c, n), u = Q(e, "session_context_backfill")?.metadata ?? {}, d = Number(u.processed_sessions ?? 0) + l.processed, f = Number(u.rewritten_sessions ?? 0) + l.rewritten, p = Number(u.skipped_no_events ?? 0) + l.skippedNoEvents, m = Number(u.skipped_no_bridge ?? 0) + l.skippedNoBridge, h = Number(u.unchanged_sessions ?? 0) + l.unchanged, g = {
|
|
16264
16285
|
last_cursor_id: l.lastCursorId,
|
|
16265
16286
|
total_candidates: Number(u.total_candidates ?? s),
|
|
16266
16287
|
processed_sessions: d,
|
|
@@ -16269,12 +16290,12 @@ async function ob(e, t = {}) {
|
|
|
16269
16290
|
skipped_no_bridge: m,
|
|
16270
16291
|
unchanged_sessions: h
|
|
16271
16292
|
};
|
|
16272
|
-
return l.exhausted ? (Yr(e,
|
|
16273
|
-
message:
|
|
16293
|
+
return l.exhausted ? (Yr(e, Xy, {
|
|
16294
|
+
message: cb(g),
|
|
16274
16295
|
progressCurrent: d,
|
|
16275
16296
|
progressTotal: Number(g.total_candidates ?? d),
|
|
16276
16297
|
metadata: g
|
|
16277
|
-
}), !1) : (Jr(e,
|
|
16298
|
+
}), !1) : (Jr(e, Xy, {
|
|
16278
16299
|
status: "running",
|
|
16279
16300
|
message: `Rebuilt session_context for ${f} of ${d} scanned sessions`,
|
|
16280
16301
|
progressCurrent: d,
|
|
@@ -16282,11 +16303,11 @@ async function ob(e, t = {}) {
|
|
|
16282
16303
|
metadata: g
|
|
16283
16304
|
}), !0);
|
|
16284
16305
|
}
|
|
16285
|
-
function
|
|
16306
|
+
function cb(e) {
|
|
16286
16307
|
let t = Number(e.rewritten_sessions ?? 0), n = Number(e.processed_sessions ?? 0), r = Number(e.skipped_no_events ?? 0) + Number(e.skipped_no_bridge ?? 0);
|
|
16287
16308
|
return n === 0 ? "No raw-event sessions required session_context backfill" : t === 0 ? `Scanned ${n} sessions, no session_context rewrite required` : `Rebuilt session_context for ${t} of ${n} sessions${r > 0 ? ` (${r} skipped)` : ""}`;
|
|
16288
16309
|
}
|
|
16289
|
-
var
|
|
16310
|
+
var lb = class {
|
|
16290
16311
|
dbPath;
|
|
16291
16312
|
signal;
|
|
16292
16313
|
batchSize;
|
|
@@ -16316,25 +16337,25 @@ var cb = class {
|
|
|
16316
16337
|
if (!this.active || this.signal?.aborted) return;
|
|
16317
16338
|
let e = null;
|
|
16318
16339
|
try {
|
|
16319
|
-
e = Mn(this.dbPath), await
|
|
16340
|
+
e = Mn(this.dbPath), await sb(e, { batchSize: this.batchSize }) || (this.active = !1);
|
|
16320
16341
|
} catch (t) {
|
|
16321
|
-
e && Xr(e,
|
|
16342
|
+
e && Xr(e, Xy, t instanceof Error ? t.message : String(t)), console.warn("Session-context backfill runner failed", t);
|
|
16322
16343
|
} finally {
|
|
16323
16344
|
e?.close();
|
|
16324
16345
|
}
|
|
16325
16346
|
}
|
|
16326
|
-
},
|
|
16327
|
-
function
|
|
16347
|
+
}, ub = "session_summary_dedup_backfill";
|
|
16348
|
+
function db(e) {
|
|
16328
16349
|
let t = e.prepare("SELECT COUNT(*) AS n FROM (\n SELECT session_id\n FROM memory_items\n WHERE active = 1\n AND kind = 'session_summary'\n AND json_extract(metadata_json, '$.source') = 'observer_summary'\n GROUP BY session_id\n HAVING COUNT(*) > 1\n )").get();
|
|
16329
16350
|
return Number(t?.n ?? 0);
|
|
16330
16351
|
}
|
|
16331
|
-
function db(e) {
|
|
16332
|
-
return ub(e) > 0;
|
|
16333
|
-
}
|
|
16334
16352
|
function fb(e) {
|
|
16353
|
+
return db(e) > 0;
|
|
16354
|
+
}
|
|
16355
|
+
function pb(e) {
|
|
16335
16356
|
return Q(e, "session_summary_dedup_backfill")?.metadata ?? {};
|
|
16336
16357
|
}
|
|
16337
|
-
function
|
|
16358
|
+
function mb(e, t, n) {
|
|
16338
16359
|
let r = e.prepare("SELECT session_id\n FROM memory_items\n WHERE active = 1\n AND kind = 'session_summary'\n AND json_extract(metadata_json, '$.source') = 'observer_summary'\n AND session_id > ?\n GROUP BY session_id\n HAVING COUNT(*) > 1\n ORDER BY session_id ASC\n LIMIT ?").all(t, n);
|
|
16339
16360
|
if (r.length === 0) return [];
|
|
16340
16361
|
let i = e.prepare("SELECT id, rev, metadata_json, created_at\n FROM memory_items\n WHERE session_id = ?\n AND active = 1\n AND kind = 'session_summary'\n AND json_extract(metadata_json, '$.source') = 'observer_summary'\n ORDER BY created_at DESC, id DESC"), a = [];
|
|
@@ -16350,7 +16371,7 @@ function pb(e, t, n) {
|
|
|
16350
16371
|
}
|
|
16351
16372
|
return a;
|
|
16352
16373
|
}
|
|
16353
|
-
function
|
|
16374
|
+
function hb(e, t, n) {
|
|
16354
16375
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = e.prepare("UPDATE memory_items\n SET active = 0,\n deleted_at = ?,\n updated_at = ?,\n metadata_json = ?,\n rev = ?\n WHERE id = ?"), a = 0;
|
|
16355
16376
|
for (let o of t.superseded) {
|
|
16356
16377
|
let s = Un(o.metadata_json);
|
|
@@ -16366,9 +16387,9 @@ function mb(e, t, n) {
|
|
|
16366
16387
|
}
|
|
16367
16388
|
return a;
|
|
16368
16389
|
}
|
|
16369
|
-
async function
|
|
16370
|
-
let n = Math.max(1, t.batchSize ?? 50), r = t.deviceId ?? "local", i = Q(e,
|
|
16371
|
-
if (c.length === 0) return i && i.status !== "completed" && Yr(e,
|
|
16390
|
+
async function gb(e, t = {}) {
|
|
16391
|
+
let n = Math.max(1, t.batchSize ?? 50), r = t.deviceId ?? "local", i = Q(e, ub), a = pb(e), o = !i || i.status === "completed" || i.status === "failed", s = o ? 0 : Number(a.last_session_id ?? 0), c = mb(e, s, n), l = o ? 0 : Number(a.processed_sessions ?? 0), u = o ? 0 : Number(a.superseded_rows ?? 0);
|
|
16392
|
+
if (c.length === 0) return i && i.status !== "completed" && Yr(e, ub, {
|
|
16372
16393
|
message: u > 0 ? `Session-summary dedup complete (${u} rows superseded)` : "Session-summary dedup complete",
|
|
16373
16394
|
progressCurrent: l,
|
|
16374
16395
|
progressTotal: Number(a.total_sessions ?? l),
|
|
@@ -16378,9 +16399,9 @@ async function hb(e, t = {}) {
|
|
|
16378
16399
|
}
|
|
16379
16400
|
}), !1;
|
|
16380
16401
|
if (!i || i.status === "completed" || i.status === "failed") {
|
|
16381
|
-
let t =
|
|
16402
|
+
let t = db(e);
|
|
16382
16403
|
qr(e, {
|
|
16383
|
-
kind:
|
|
16404
|
+
kind: ub,
|
|
16384
16405
|
title: "Deduplicating historical session summaries",
|
|
16385
16406
|
message: `Cleaning up ${t} sessions with duplicate observer summaries`,
|
|
16386
16407
|
progressTotal: t,
|
|
@@ -16395,10 +16416,10 @@ async function hb(e, t = {}) {
|
|
|
16395
16416
|
}
|
|
16396
16417
|
let d = 0, f = s;
|
|
16397
16418
|
e.transaction(() => {
|
|
16398
|
-
for (let t of c) d +=
|
|
16419
|
+
for (let t of c) d += hb(e, t, r), t.session_id > f && (f = t.session_id);
|
|
16399
16420
|
})();
|
|
16400
|
-
let p = l + c.length, m = u + d, h =
|
|
16401
|
-
return h === 0 ? (Yr(e,
|
|
16421
|
+
let p = l + c.length, m = u + d, h = db(e), g = Math.max(Number(a.total_sessions ?? p), p + h);
|
|
16422
|
+
return h === 0 ? (Yr(e, ub, {
|
|
16402
16423
|
message: `Session-summary dedup complete (${m} rows superseded across ${p} sessions)`,
|
|
16403
16424
|
progressCurrent: p,
|
|
16404
16425
|
progressTotal: g,
|
|
@@ -16408,7 +16429,7 @@ async function hb(e, t = {}) {
|
|
|
16408
16429
|
superseded_rows: m,
|
|
16409
16430
|
last_session_id: f
|
|
16410
16431
|
}
|
|
16411
|
-
}), !1) : (Jr(e,
|
|
16432
|
+
}), !1) : (Jr(e, ub, {
|
|
16412
16433
|
message: `Deduplicated ${p} of ${g} sessions (${m} rows superseded)`,
|
|
16413
16434
|
progressCurrent: p,
|
|
16414
16435
|
progressTotal: g,
|
|
@@ -16420,7 +16441,7 @@ async function hb(e, t = {}) {
|
|
|
16420
16441
|
}
|
|
16421
16442
|
}), !0);
|
|
16422
16443
|
}
|
|
16423
|
-
var
|
|
16444
|
+
var _b = class {
|
|
16424
16445
|
dbPath;
|
|
16425
16446
|
signal;
|
|
16426
16447
|
batchSize;
|
|
@@ -16451,97 +16472,97 @@ var gb = class {
|
|
|
16451
16472
|
if (!this.active || this.signal?.aborted) return;
|
|
16452
16473
|
let e = null;
|
|
16453
16474
|
try {
|
|
16454
|
-
e = Mn(this.dbPath), await
|
|
16475
|
+
e = Mn(this.dbPath), await gb(e, {
|
|
16455
16476
|
batchSize: this.batchSize,
|
|
16456
16477
|
deviceId: this.deviceId
|
|
16457
16478
|
}) || (this.active = !1);
|
|
16458
16479
|
} catch (t) {
|
|
16459
|
-
e && Xr(e,
|
|
16480
|
+
e && Xr(e, ub, t instanceof Error ? t.message : String(t)), console.warn("Summary-dedup backfill runner failed", t);
|
|
16460
16481
|
} finally {
|
|
16461
16482
|
e?.close();
|
|
16462
16483
|
}
|
|
16463
16484
|
}
|
|
16464
|
-
},
|
|
16485
|
+
}, vb = [
|
|
16465
16486
|
"unsupported",
|
|
16466
16487
|
"aware",
|
|
16467
16488
|
"enforcing"
|
|
16468
|
-
],
|
|
16489
|
+
], yb = "X-Codemem-Sync-Capability", bb = "aware", xb = {
|
|
16469
16490
|
unsupported: 0,
|
|
16470
16491
|
aware: 1,
|
|
16471
16492
|
enforcing: 2
|
|
16472
16493
|
};
|
|
16473
|
-
function
|
|
16494
|
+
function Sb(e) {
|
|
16474
16495
|
if (typeof e != "string") return "unsupported";
|
|
16475
16496
|
let t = e.trim().toLowerCase();
|
|
16476
|
-
return
|
|
16497
|
+
return vb.includes(t) ? t : "unsupported";
|
|
16477
16498
|
}
|
|
16478
|
-
function
|
|
16479
|
-
let n =
|
|
16480
|
-
return
|
|
16499
|
+
function Cb(e, t) {
|
|
16500
|
+
let n = Sb(e), r = Sb(t);
|
|
16501
|
+
return xb[n] <= xb[r] ? n : r;
|
|
16481
16502
|
}
|
|
16482
16503
|
//#endregion
|
|
16483
16504
|
//#region src/vector-migration.ts
|
|
16484
|
-
var
|
|
16485
|
-
function
|
|
16505
|
+
var wb = "vector_model_migration", Tb = "sync_bootstrap", Eb = "sync_incremental", Db = 6e4, Ob = null;
|
|
16506
|
+
function kb(e) {
|
|
16486
16507
|
return [...new Set(e.filter((e) => Number.isInteger(e) && e > 0))].sort((e, t) => e - t);
|
|
16487
16508
|
}
|
|
16488
|
-
function
|
|
16489
|
-
return Array.isArray(e) ?
|
|
16509
|
+
function Ab(e) {
|
|
16510
|
+
return Array.isArray(e) ? kb(e.filter((e) => typeof e == "number")) : [];
|
|
16490
16511
|
}
|
|
16491
|
-
function
|
|
16492
|
-
let n = new Set(
|
|
16493
|
-
for (let e of
|
|
16494
|
-
for (let e of
|
|
16512
|
+
function jb(e, t) {
|
|
16513
|
+
let n = new Set(Ab(e.pending_upsert_memory_ids)), r = new Set(Ab(e.pending_delete_memory_ids));
|
|
16514
|
+
for (let e of kb(t.deleteMemoryIds)) n.delete(e), r.add(e);
|
|
16515
|
+
for (let e of kb(t.upsertMemoryIds)) r.delete(e), n.add(e);
|
|
16495
16516
|
return {
|
|
16496
16517
|
pending_upsert_memory_ids: [...n],
|
|
16497
16518
|
pending_delete_memory_ids: [...r]
|
|
16498
16519
|
};
|
|
16499
16520
|
}
|
|
16500
|
-
function
|
|
16521
|
+
function Mb(e, t) {
|
|
16501
16522
|
if (t.length === 0) return;
|
|
16502
16523
|
let n = t.map(() => "?").join(", ");
|
|
16503
16524
|
e.prepare(`DELETE FROM memory_vectors WHERE memory_id IN (${n})`).run(...t);
|
|
16504
16525
|
}
|
|
16505
|
-
function
|
|
16506
|
-
return JSON.stringify(
|
|
16526
|
+
function Nb(e, t) {
|
|
16527
|
+
return JSON.stringify(Ab(e.pending_upsert_memory_ids)) === JSON.stringify(Ab(t.pending_upsert_memory_ids)) && JSON.stringify(Ab(e.pending_delete_memory_ids)) === JSON.stringify(Ab(t.pending_delete_memory_ids));
|
|
16507
16528
|
}
|
|
16508
|
-
function
|
|
16509
|
-
|
|
16529
|
+
function Pb() {
|
|
16530
|
+
Ob?.wake();
|
|
16510
16531
|
}
|
|
16511
|
-
function
|
|
16512
|
-
let n =
|
|
16532
|
+
function Fb(e, t) {
|
|
16533
|
+
let n = jb({}, t);
|
|
16513
16534
|
if ((n.pending_upsert_memory_ids?.length ?? 0) === 0 && (n.pending_delete_memory_ids?.length ?? 0) === 0) return;
|
|
16514
|
-
let r = Q(e,
|
|
16535
|
+
let r = Q(e, wb), i = r && r.status !== "completed" && r.status !== "cancelled" ? r.metadata ?? {} : {}, a = {
|
|
16515
16536
|
...i,
|
|
16516
|
-
...
|
|
16517
|
-
trigger: i.trigger ??
|
|
16518
|
-
}, o =
|
|
16537
|
+
...jb(i, t),
|
|
16538
|
+
trigger: i.trigger ?? Eb
|
|
16539
|
+
}, o = Ab(a.pending_upsert_memory_ids).length + Ab(a.pending_delete_memory_ids).length;
|
|
16519
16540
|
if (!r || r.status === "completed" || r.status === "cancelled") {
|
|
16520
16541
|
qr(e, {
|
|
16521
|
-
kind:
|
|
16542
|
+
kind: wb,
|
|
16522
16543
|
title: "Re-indexing memories",
|
|
16523
16544
|
status: "pending",
|
|
16524
16545
|
message: "Queued vector catch-up for incremental sync data",
|
|
16525
16546
|
progressTotal: null,
|
|
16526
16547
|
metadata: a
|
|
16527
|
-
}),
|
|
16548
|
+
}), Pb();
|
|
16528
16549
|
return;
|
|
16529
16550
|
}
|
|
16530
|
-
Jr(e,
|
|
16551
|
+
Jr(e, wb, {
|
|
16531
16552
|
status: "pending",
|
|
16532
16553
|
message: "Queued vector catch-up for incremental sync data",
|
|
16533
16554
|
progressCurrent: r.status === "failed" ? 0 : Math.min(r.progress.current, o),
|
|
16534
16555
|
progressTotal: r.progress.total,
|
|
16535
16556
|
metadata: a
|
|
16536
|
-
}),
|
|
16557
|
+
}), Pb();
|
|
16537
16558
|
}
|
|
16538
|
-
async function
|
|
16539
|
-
let a = t.metadata ?? {}, o =
|
|
16559
|
+
async function Ib(e, t, n, r, i) {
|
|
16560
|
+
let a = t.metadata ?? {}, o = Ab(a.pending_delete_memory_ids), s = Ab(a.pending_upsert_memory_ids);
|
|
16540
16561
|
if (o.length === 0 && s.length === 0) return {
|
|
16541
16562
|
completed: !1,
|
|
16542
16563
|
metadata: a
|
|
16543
16564
|
};
|
|
16544
|
-
o.length > 0 &&
|
|
16565
|
+
o.length > 0 && Mb(e, o);
|
|
16545
16566
|
let c = s.slice(0, r);
|
|
16546
16567
|
if (c.length > 0) {
|
|
16547
16568
|
if (await js(e, {
|
|
@@ -16557,14 +16578,14 @@ async function Fb(e, t, n, r, i) {
|
|
|
16557
16578
|
...a,
|
|
16558
16579
|
pending_delete_memory_ids: [],
|
|
16559
16580
|
pending_upsert_memory_ids: s.slice(c.length)
|
|
16560
|
-
}, u = Q(e, "vector_model_migration")?.metadata ?? {}, d =
|
|
16581
|
+
}, u = Q(e, "vector_model_migration")?.metadata ?? {}, d = Nb(u, a) ? l : {
|
|
16561
16582
|
...u,
|
|
16562
|
-
...
|
|
16563
|
-
upsertMemoryIds:
|
|
16564
|
-
deleteMemoryIds:
|
|
16583
|
+
...jb(u, {
|
|
16584
|
+
upsertMemoryIds: Ab(l.pending_upsert_memory_ids),
|
|
16585
|
+
deleteMemoryIds: Ab(l.pending_delete_memory_ids)
|
|
16565
16586
|
})
|
|
16566
|
-
}, f =
|
|
16567
|
-
return f === 0 && p ? (Yr(e,
|
|
16587
|
+
}, f = Ab(d.pending_delete_memory_ids).length + Ab(d.pending_upsert_memory_ids).length, p = (a.trigger ?? Eb) === Eb && !a.source_model && !a.last_cursor_id && a.embeddable_total == null;
|
|
16588
|
+
return f === 0 && p ? (Yr(e, wb, {
|
|
16568
16589
|
message: "Finished vector catch-up for incremental sync data",
|
|
16569
16590
|
progressCurrent: 0,
|
|
16570
16591
|
progressTotal: null,
|
|
@@ -16572,7 +16593,7 @@ async function Fb(e, t, n, r, i) {
|
|
|
16572
16593
|
}), {
|
|
16573
16594
|
completed: !0,
|
|
16574
16595
|
metadata: d
|
|
16575
|
-
}) : (Jr(e,
|
|
16596
|
+
}) : (Jr(e, wb, {
|
|
16576
16597
|
status: f > 0 ? "running" : t.status,
|
|
16577
16598
|
message: f > 0 ? `Queued vector catch-up has ${f} memory change(s) remaining` : t.message,
|
|
16578
16599
|
progressCurrent: 0,
|
|
@@ -16583,36 +16604,36 @@ async function Fb(e, t, n, r, i) {
|
|
|
16583
16604
|
metadata: d
|
|
16584
16605
|
});
|
|
16585
16606
|
}
|
|
16586
|
-
function
|
|
16607
|
+
function Lb(e, t = {}) {
|
|
16587
16608
|
let n = typeof t.embeddableTotal == "number" && t.embeddableTotal >= 0 ? t.embeddableTotal : null, r = {
|
|
16588
16609
|
last_cursor_id: 0,
|
|
16589
16610
|
processed_embeddable: 0,
|
|
16590
|
-
trigger:
|
|
16611
|
+
trigger: Tb
|
|
16591
16612
|
};
|
|
16592
16613
|
n != null && (r.embeddable_total = n), qr(e, {
|
|
16593
|
-
kind:
|
|
16614
|
+
kind: wb,
|
|
16594
16615
|
title: "Re-indexing memories",
|
|
16595
16616
|
status: "pending",
|
|
16596
16617
|
message: "Queued vector catch-up for synced bootstrap data",
|
|
16597
16618
|
progressTotal: n,
|
|
16598
16619
|
metadata: r
|
|
16599
|
-
}),
|
|
16620
|
+
}), Pb();
|
|
16600
16621
|
}
|
|
16601
|
-
function
|
|
16622
|
+
function Rb(e) {
|
|
16602
16623
|
return e.prepare("SELECT model, COUNT(*) AS rows FROM memory_vectors GROUP BY model ORDER BY rows DESC, model ASC").all();
|
|
16603
16624
|
}
|
|
16604
|
-
function
|
|
16625
|
+
function zb(e) {
|
|
16605
16626
|
let t = e.prepare("SELECT COUNT(*) AS c FROM memory_items\n WHERE active = 1\n AND TRIM(COALESCE(title, '') || COALESCE(body_text, '')) != ''").get();
|
|
16606
16627
|
return Number(t?.c ?? 0);
|
|
16607
16628
|
}
|
|
16608
|
-
function
|
|
16629
|
+
function Bb(e, t, n) {
|
|
16609
16630
|
return e.prepare("SELECT id, title, body_text\n FROM memory_items\n WHERE active = 1 AND id > ?\n ORDER BY id ASC\n LIMIT ?").all(t, n);
|
|
16610
16631
|
}
|
|
16611
|
-
function
|
|
16632
|
+
function Vb(e) {
|
|
16612
16633
|
return `${e.title ?? ""}
|
|
16613
16634
|
${e.body_text ?? ""}`.trim().length > 0;
|
|
16614
16635
|
}
|
|
16615
|
-
function
|
|
16636
|
+
function Hb(e, t, n, r) {
|
|
16616
16637
|
let i = e?.metadata ?? {};
|
|
16617
16638
|
return {
|
|
16618
16639
|
source_model: t ?? i.source_model ?? null,
|
|
@@ -16622,39 +16643,39 @@ function Vb(e, t, n, r) {
|
|
|
16622
16643
|
embeddable_total: Number(i.embeddable_total ?? r)
|
|
16623
16644
|
};
|
|
16624
16645
|
}
|
|
16625
|
-
function
|
|
16646
|
+
function Ub(e, t) {
|
|
16626
16647
|
let n = e.prepare("SELECT COUNT(*) AS c FROM memory_vectors WHERE model != ?").get(t), r = Number(n?.c ?? 0);
|
|
16627
16648
|
return r > 0 && e.prepare("DELETE FROM memory_vectors WHERE model != ?").run(t), r;
|
|
16628
16649
|
}
|
|
16629
|
-
function
|
|
16630
|
-
return
|
|
16650
|
+
function Wb(e, t) {
|
|
16651
|
+
return Rb(e).filter((e) => e.model !== t)[0]?.model ?? null;
|
|
16631
16652
|
}
|
|
16632
|
-
async function
|
|
16633
|
-
let n = Q(e,
|
|
16653
|
+
async function Gb(e, t = {}) {
|
|
16654
|
+
let n = Q(e, wb), r = n?.status === "running" || n?.status === "pending";
|
|
16634
16655
|
if (Ln()) {
|
|
16635
|
-
r && Xr(e,
|
|
16656
|
+
r && Xr(e, wb, "Embeddings are disabled", { message: "Vector re-indexing is waiting for embeddings to be enabled" });
|
|
16636
16657
|
return;
|
|
16637
16658
|
}
|
|
16638
16659
|
let i = await ns();
|
|
16639
16660
|
if (!i) {
|
|
16640
|
-
r && Xr(e,
|
|
16661
|
+
r && Xr(e, wb, "Embedding client unavailable", { message: "Vector re-indexing is waiting for the embedding client" });
|
|
16641
16662
|
return;
|
|
16642
16663
|
}
|
|
16643
|
-
let a = i.model, o = Math.max(1, t.batchSize ?? 50), s = n?.metadata ?? {}, c =
|
|
16664
|
+
let a = i.model, o = Math.max(1, t.batchSize ?? 50), s = n?.metadata ?? {}, c = Ab(s.pending_upsert_memory_ids).length + Ab(s.pending_delete_memory_ids).length;
|
|
16644
16665
|
if (n?.status === "completed" && s.target_model === a && c === 0) return;
|
|
16645
16666
|
if (n) {
|
|
16646
|
-
let r = await
|
|
16667
|
+
let r = await Ib(e, n, a, o, t.signal);
|
|
16647
16668
|
if (r.completed) return;
|
|
16648
|
-
let i =
|
|
16649
|
-
if ((r.metadata.trigger ??
|
|
16650
|
-
n = Q(e,
|
|
16669
|
+
let i = Ab(r.metadata.pending_delete_memory_ids).length + Ab(r.metadata.pending_upsert_memory_ids).length;
|
|
16670
|
+
if ((r.metadata.trigger ?? Eb) === Eb && i > 0) return;
|
|
16671
|
+
n = Q(e, wb);
|
|
16651
16672
|
}
|
|
16652
|
-
let l =
|
|
16653
|
-
if (!l && (d ===
|
|
16673
|
+
let l = Wb(e, a), u = n?.status === "running" || n?.status === "pending" || n?.status === "failed", d = n?.metadata?.trigger;
|
|
16674
|
+
if (!l && (d === Eb || d === Tb) && u) {
|
|
16654
16675
|
let t = e.prepare("SELECT COUNT(*) AS c FROM memory_items\n WHERE active = 1\n AND id NOT IN (SELECT DISTINCT memory_id FROM memory_vectors WHERE model = ?)").get(a);
|
|
16655
16676
|
if (Number(t?.c ?? 0) <= 0) {
|
|
16656
|
-
let t = n?.metadata ?? {}, r =
|
|
16657
|
-
Yr(e,
|
|
16677
|
+
let t = n?.metadata ?? {}, r = zb(e);
|
|
16678
|
+
Yr(e, wb, {
|
|
16658
16679
|
message: "Finished re-indexing memories",
|
|
16659
16680
|
progressCurrent: r,
|
|
16660
16681
|
progressTotal: r,
|
|
@@ -16669,9 +16690,9 @@ async function Wb(e, t = {}) {
|
|
|
16669
16690
|
return;
|
|
16670
16691
|
}
|
|
16671
16692
|
}
|
|
16672
|
-
let f = n?.metadata ?? {}, p = (n?.status === "running" || n?.status === "pending") && f.embeddable_total ? Number(f.embeddable_total) :
|
|
16693
|
+
let f = n?.metadata ?? {}, p = (n?.status === "running" || n?.status === "pending") && f.embeddable_total ? Number(f.embeddable_total) : zb(e);
|
|
16673
16694
|
if (p <= 0 && u && !l) {
|
|
16674
|
-
Yr(e,
|
|
16695
|
+
Yr(e, wb, {
|
|
16675
16696
|
message: "No embeddable memories to re-index",
|
|
16676
16697
|
progressCurrent: 0,
|
|
16677
16698
|
progressTotal: 0,
|
|
@@ -16685,9 +16706,9 @@ async function Wb(e, t = {}) {
|
|
|
16685
16706
|
return;
|
|
16686
16707
|
}
|
|
16687
16708
|
if (l && p <= 0) {
|
|
16688
|
-
let t =
|
|
16709
|
+
let t = Ub(e, a);
|
|
16689
16710
|
qr(e, {
|
|
16690
|
-
kind:
|
|
16711
|
+
kind: wb,
|
|
16691
16712
|
title: "Re-indexing memories",
|
|
16692
16713
|
message: t > 0 ? `Removed ${t} stale vector rows` : "No embeddable memories to re-index",
|
|
16693
16714
|
progressTotal: 0,
|
|
@@ -16696,7 +16717,7 @@ async function Wb(e, t = {}) {
|
|
|
16696
16717
|
target_model: a,
|
|
16697
16718
|
removed_stale_rows: t
|
|
16698
16719
|
}
|
|
16699
|
-
}), Yr(e,
|
|
16720
|
+
}), Yr(e, wb, {
|
|
16700
16721
|
progressCurrent: 0,
|
|
16701
16722
|
progressTotal: 0,
|
|
16702
16723
|
metadata: {
|
|
@@ -16707,15 +16728,15 @@ async function Wb(e, t = {}) {
|
|
|
16707
16728
|
});
|
|
16708
16729
|
return;
|
|
16709
16730
|
}
|
|
16710
|
-
let m = n, h =
|
|
16731
|
+
let m = n, h = Hb(m, l, a, p);
|
|
16711
16732
|
(!m || m.status === "completed" || m.status === "failed") && qr(e, {
|
|
16712
|
-
kind:
|
|
16733
|
+
kind: wb,
|
|
16713
16734
|
title: "Re-indexing memories",
|
|
16714
16735
|
message: l ? `Building ${a} vectors while semantic search falls back to FTS-only` : `Building ${a} vectors`,
|
|
16715
16736
|
progressTotal: p,
|
|
16716
16737
|
metadata: h
|
|
16717
16738
|
});
|
|
16718
|
-
let g =
|
|
16739
|
+
let g = Bb(e, h.last_cursor_id ?? 0, o), _ = g.map((e) => e.id), v = g.filter(Vb).length, y = g.at(-1)?.id ?? h.last_cursor_id ?? 0, b = Math.min(p, (h.processed_embeddable ?? 0) + v);
|
|
16719
16740
|
if (_.length > 0) {
|
|
16720
16741
|
if (await js(e, {
|
|
16721
16742
|
memoryIds: _,
|
|
@@ -16723,8 +16744,8 @@ async function Wb(e, t = {}) {
|
|
|
16723
16744
|
}), t.signal?.aborted) return;
|
|
16724
16745
|
if (g.length < o) {
|
|
16725
16746
|
e.transaction(() => {
|
|
16726
|
-
let t =
|
|
16727
|
-
Yr(e,
|
|
16747
|
+
let t = Ub(e, a);
|
|
16748
|
+
Yr(e, wb, {
|
|
16728
16749
|
message: t > 0 ? `Finished re-indexing and removed ${t} stale vector rows` : "Finished re-indexing memories",
|
|
16729
16750
|
progressCurrent: b,
|
|
16730
16751
|
progressTotal: p,
|
|
@@ -16739,7 +16760,7 @@ async function Wb(e, t = {}) {
|
|
|
16739
16760
|
})();
|
|
16740
16761
|
return;
|
|
16741
16762
|
}
|
|
16742
|
-
Jr(e,
|
|
16763
|
+
Jr(e, wb, {
|
|
16743
16764
|
message: `Re-indexed ${b} of ${p} memories`,
|
|
16744
16765
|
progressCurrent: b,
|
|
16745
16766
|
progressTotal: p,
|
|
@@ -16753,8 +16774,8 @@ async function Wb(e, t = {}) {
|
|
|
16753
16774
|
return;
|
|
16754
16775
|
}
|
|
16755
16776
|
h.last_cursor_id && h.last_cursor_id > 0 && e.transaction(() => {
|
|
16756
|
-
let t =
|
|
16757
|
-
Yr(e,
|
|
16777
|
+
let t = Ub(e, a);
|
|
16778
|
+
Yr(e, wb, {
|
|
16758
16779
|
message: t > 0 ? `Finished re-indexing and removed ${t} stale vector rows` : "Finished re-indexing memories",
|
|
16759
16780
|
progressCurrent: p,
|
|
16760
16781
|
progressTotal: p,
|
|
@@ -16767,7 +16788,7 @@ async function Wb(e, t = {}) {
|
|
|
16767
16788
|
});
|
|
16768
16789
|
})();
|
|
16769
16790
|
}
|
|
16770
|
-
var
|
|
16791
|
+
var Kb = class {
|
|
16771
16792
|
dbPath;
|
|
16772
16793
|
signal;
|
|
16773
16794
|
batchSize;
|
|
@@ -16778,13 +16799,13 @@ var Gb = class {
|
|
|
16778
16799
|
currentRun = null;
|
|
16779
16800
|
lastTickWasIdle = !1;
|
|
16780
16801
|
constructor(e = {}) {
|
|
16781
|
-
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 ??
|
|
16802
|
+
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 ?? Db);
|
|
16782
16803
|
}
|
|
16783
16804
|
start() {
|
|
16784
|
-
this.active || (this.active = !0, this.lastTickWasIdle = !1,
|
|
16805
|
+
this.active || (this.active = !0, this.lastTickWasIdle = !1, Ob = this, this.schedule(100));
|
|
16785
16806
|
}
|
|
16786
16807
|
async stop() {
|
|
16787
|
-
this.active = !1,
|
|
16808
|
+
this.active = !1, Ob === this && (Ob = null), this.timer &&= (clearTimeout(this.timer), null), this.currentRun && await this.currentRun;
|
|
16788
16809
|
}
|
|
16789
16810
|
wake() {
|
|
16790
16811
|
this.active && (this.lastTickWasIdle = !1, this.timer && (clearTimeout(this.timer), this.timer = null, this.schedule(100)));
|
|
@@ -16804,28 +16825,28 @@ var Gb = class {
|
|
|
16804
16825
|
if (!this.active || this.signal?.aborted) return;
|
|
16805
16826
|
let e = null;
|
|
16806
16827
|
try {
|
|
16807
|
-
e = Mn(this.dbPath), In(e), await
|
|
16828
|
+
e = Mn(this.dbPath), In(e), await Gb(e, {
|
|
16808
16829
|
batchSize: this.batchSize,
|
|
16809
16830
|
signal: this.signal
|
|
16810
16831
|
}), this.lastTickWasIdle = this.computeIdle(e);
|
|
16811
16832
|
} catch (t) {
|
|
16812
|
-
e && Xr(e,
|
|
16833
|
+
e && Xr(e, wb, t instanceof Error ? t.message : String(t)), this.lastTickWasIdle = !0, console.warn("Vector migration runner failed", t);
|
|
16813
16834
|
} finally {
|
|
16814
16835
|
e?.close();
|
|
16815
16836
|
}
|
|
16816
16837
|
}
|
|
16817
16838
|
computeIdle(e) {
|
|
16818
16839
|
if (Ln()) return !0;
|
|
16819
|
-
let t = Q(e,
|
|
16840
|
+
let t = Q(e, wb);
|
|
16820
16841
|
if (t) {
|
|
16821
16842
|
if (t.status === "running" || t.status === "pending") return !1;
|
|
16822
16843
|
let e = t.metadata ?? {};
|
|
16823
|
-
return !(
|
|
16844
|
+
return !(Ab(e.pending_upsert_memory_ids).length + Ab(e.pending_delete_memory_ids).length > 0);
|
|
16824
16845
|
}
|
|
16825
16846
|
let n = ts();
|
|
16826
16847
|
try {
|
|
16827
16848
|
let t = e.prepare("SELECT COUNT(*) AS c FROM memory_items\n WHERE active = 1\n AND TRIM(COALESCE(title, '') || COALESCE(body_text, '')) != ''\n AND id NOT IN (SELECT DISTINCT memory_id FROM memory_vectors WHERE model = ?)").get(n);
|
|
16828
|
-
return Number(t?.c ?? 0) > 0 ? !1 :
|
|
16849
|
+
return Number(t?.c ?? 0) > 0 ? !1 : Wb(e, n) === null;
|
|
16829
16850
|
} catch (e) {
|
|
16830
16851
|
return console.warn("Vector migration runner idle peek failed", e), !1;
|
|
16831
16852
|
}
|
|
@@ -16833,7 +16854,7 @@ var Gb = class {
|
|
|
16833
16854
|
};
|
|
16834
16855
|
//#endregion
|
|
16835
16856
|
//#region src/sync-bootstrap.ts
|
|
16836
|
-
async function
|
|
16857
|
+
async function qb(e, t, n, r) {
|
|
16837
16858
|
let i = r?.pageSize ?? 200, a = r?.timeoutS ?? 10, o = r?.keysDir, s = r?.bootstrapGrantId?.trim() || void 0, c = r?.maxItems ?? 1e5, l = [], u = null, d = null;
|
|
16838
16859
|
for (;;) {
|
|
16839
16860
|
let r = new URLSearchParams({
|
|
@@ -16852,7 +16873,7 @@ async function Kb(e, t, n, r) {
|
|
|
16852
16873
|
bootstrapGrantId: s,
|
|
16853
16874
|
keysDir: o
|
|
16854
16875
|
}),
|
|
16855
|
-
[
|
|
16876
|
+
[yb]: bb
|
|
16856
16877
|
},
|
|
16857
16878
|
timeoutS: a
|
|
16858
16879
|
});
|
|
@@ -16876,7 +16897,7 @@ async function Kb(e, t, n, r) {
|
|
|
16876
16897
|
...d
|
|
16877
16898
|
};
|
|
16878
16899
|
}
|
|
16879
|
-
function
|
|
16900
|
+
function Jb(e) {
|
|
16880
16901
|
if (!e.payload_json) return null;
|
|
16881
16902
|
try {
|
|
16882
16903
|
let t = JSON.parse(e.payload_json);
|
|
@@ -16885,23 +16906,23 @@ function qb(e) {
|
|
|
16885
16906
|
return null;
|
|
16886
16907
|
}
|
|
16887
16908
|
}
|
|
16888
|
-
function
|
|
16909
|
+
function Yb(e) {
|
|
16889
16910
|
return `${typeof e.title == "string" ? e.title : ""}\n${typeof e.body_text == "string" ? e.body_text : ""}`.trim().length > 0;
|
|
16890
16911
|
}
|
|
16891
|
-
function
|
|
16912
|
+
function Xb(e) {
|
|
16892
16913
|
if (typeof e != "string") return null;
|
|
16893
16914
|
let t = e.trim();
|
|
16894
16915
|
return t.length > 0 ? t : null;
|
|
16895
16916
|
}
|
|
16896
|
-
function
|
|
16897
|
-
return t ||
|
|
16917
|
+
function Zb(e, t) {
|
|
16918
|
+
return t || Xb(e.scope_id);
|
|
16898
16919
|
}
|
|
16899
|
-
var
|
|
16900
|
-
function
|
|
16901
|
-
let r = n ?? "__none__", i =
|
|
16920
|
+
var Qb = /* @__PURE__ */ new Map();
|
|
16921
|
+
function $b(e, t, n) {
|
|
16922
|
+
let r = n ?? "__none__", i = Qb.get(r);
|
|
16902
16923
|
if (i != null) return i;
|
|
16903
16924
|
let a = n ? `__sync_bootstrap__:${n}` : "__sync_bootstrap__", o = e.select({ id: U.id }).from(U).where(k(U.cwd, a)).limit(1).get();
|
|
16904
|
-
if (o) return
|
|
16925
|
+
if (o) return Qb.set(r, o.id), o.id;
|
|
16905
16926
|
let s = e.insert(U).values({
|
|
16906
16927
|
started_at: t,
|
|
16907
16928
|
cwd: a,
|
|
@@ -16909,25 +16930,25 @@ function Qb(e, t, n) {
|
|
|
16909
16930
|
user: "sync",
|
|
16910
16931
|
tool_version: "bootstrap"
|
|
16911
16932
|
}).returning({ id: U.id }).all()[0]?.id ?? 0;
|
|
16912
|
-
return
|
|
16933
|
+
return Qb.set(r, s), s;
|
|
16913
16934
|
}
|
|
16914
|
-
function
|
|
16935
|
+
function ex(e, t, n, r, i) {
|
|
16915
16936
|
let a = {
|
|
16916
16937
|
ok: !1,
|
|
16917
16938
|
applied: 0,
|
|
16918
16939
|
deleted: 0
|
|
16919
|
-
}, o = i ?? new _l(), s =
|
|
16940
|
+
}, o = i ?? new _l(), s = Xb(r.scope_id), c = s ? k(W.scope_id, s) : ve(pe(W.scope_id), k(W.scope_id, Au));
|
|
16920
16941
|
return e.transaction(() => {
|
|
16921
16942
|
let i = N(e, { schema: H }), l = 0;
|
|
16922
|
-
a.deleted = i.delete(W).where(O(fe(W.import_key), c, _e(M`COALESCE(${W.visibility}, '')`, "private"))).run().changes,
|
|
16943
|
+
a.deleted = i.delete(W).where(O(fe(W.import_key), c, _e(M`COALESCE(${W.visibility}, '')`, "private"))).run().changes, Qb.clear();
|
|
16923
16944
|
for (let e of n) {
|
|
16924
|
-
let t =
|
|
16945
|
+
let t = Jb(e);
|
|
16925
16946
|
if (!t) continue;
|
|
16926
16947
|
Sl(t, o);
|
|
16927
|
-
let n =
|
|
16948
|
+
let n = Zb(t, s), r = typeof t.project == "string" && t.project.trim() ? t.project.trim() : null, c = $b(i, (/* @__PURE__ */ new Date()).toISOString(), r), u = t.metadata_json, d = u && typeof u == "object" && !Array.isArray(u) ? u : {};
|
|
16928
16949
|
d.clock_device_id = e.clock_device_id;
|
|
16929
16950
|
let f = e.op_type === "delete";
|
|
16930
|
-
!f &&
|
|
16951
|
+
!f && Yb(t) && l++, i.insert(W).values({
|
|
16931
16952
|
session_id: c,
|
|
16932
16953
|
kind: typeof t.kind == "string" ? t.kind : "discovery",
|
|
16933
16954
|
title: typeof t.title == "string" ? t.title : "",
|
|
@@ -16964,16 +16985,16 @@ function $b(e, t, n, r, i) {
|
|
|
16964
16985
|
generation: r.generation,
|
|
16965
16986
|
snapshot_id: r.snapshot_id,
|
|
16966
16987
|
baseline_cursor: r.baseline_cursor
|
|
16967
|
-
}, r.scope_id),
|
|
16988
|
+
}, r.scope_id), Lb(e, { embeddableTotal: l }), a.ok = !0;
|
|
16968
16989
|
}).immediate(), a;
|
|
16969
16990
|
}
|
|
16970
16991
|
//#endregion
|
|
16971
16992
|
//#region src/sync-discovery.ts
|
|
16972
|
-
var
|
|
16973
|
-
function
|
|
16993
|
+
var tx = Ee(import.meta.url), nx = "_codemem._tcp.local.";
|
|
16994
|
+
function rx(e) {
|
|
16974
16995
|
return e.mdns.length === 0 ? Tl(e.stored, []) : Tl(e.mdns, e.stored);
|
|
16975
16996
|
}
|
|
16976
|
-
function
|
|
16997
|
+
function ix(e, t) {
|
|
16977
16998
|
let n = N(e, { schema: H }).select({ addresses_json: Y.addresses_json }).from(Y).where(k(Y.peer_device_id, t)).get();
|
|
16978
16999
|
if (!n?.addresses_json) return [];
|
|
16979
17000
|
try {
|
|
@@ -16983,8 +17004,8 @@ function rx(e, t) {
|
|
|
16983
17004
|
return [];
|
|
16984
17005
|
}
|
|
16985
17006
|
}
|
|
16986
|
-
function
|
|
16987
|
-
let i = Tl(
|
|
17007
|
+
function ax(e, t, n, r) {
|
|
17008
|
+
let i = Tl(ix(e, t), n), a = (/* @__PURE__ */ new Date()).toISOString(), o = JSON.stringify(i);
|
|
16988
17009
|
return N(e, { schema: H }).insert(Y).values({
|
|
16989
17010
|
peer_device_id: t,
|
|
16990
17011
|
name: r?.name ?? null,
|
|
@@ -17004,7 +17025,7 @@ function ix(e, t, n, r) {
|
|
|
17004
17025
|
}
|
|
17005
17026
|
}).run(), i;
|
|
17006
17027
|
}
|
|
17007
|
-
function
|
|
17028
|
+
function ox(e, t, n) {
|
|
17008
17029
|
let r = N(e, { schema: H }), i = (/* @__PURE__ */ new Date()).toISOString();
|
|
17009
17030
|
r.insert(ft).values({
|
|
17010
17031
|
peer_device_id: t,
|
|
@@ -17019,10 +17040,10 @@ function ax(e, t, n) {
|
|
|
17019
17040
|
last_error: null
|
|
17020
17041
|
}).where(k(Y.peer_device_id, t)).run() : r.update(Y).set({ last_error: n.error ?? null }).where(k(Y.peer_device_id, t)).run();
|
|
17021
17042
|
}
|
|
17022
|
-
function
|
|
17043
|
+
function sx(e, t, n) {
|
|
17023
17044
|
let r = Cl(n ?? ""), i = (/* @__PURE__ */ new Date()).toISOString();
|
|
17024
17045
|
return e.transaction((t, n, r) => {
|
|
17025
|
-
let i =
|
|
17046
|
+
let i = ix(e, t), a = n ? i.filter((e) => Cl(e) !== n) : i, o = n ? [n, ...a] : i;
|
|
17026
17047
|
return N(e, { schema: H }).update(Y).set({
|
|
17027
17048
|
addresses_json: JSON.stringify(o),
|
|
17028
17049
|
last_sync_at: r,
|
|
@@ -17031,18 +17052,18 @@ function ox(e, t, n) {
|
|
|
17031
17052
|
}).where(k(Y.peer_device_id, t)).run(), o;
|
|
17032
17053
|
}).immediate(t, r, i);
|
|
17033
17054
|
}
|
|
17034
|
-
function
|
|
17055
|
+
function cx(e, t, n) {
|
|
17035
17056
|
let r = n.include === null ? null : JSON.stringify(n.include), i = n.exclude === null ? null : JSON.stringify(n.exclude);
|
|
17036
17057
|
N(e, { schema: H }).update(Y).set({
|
|
17037
17058
|
projects_include_json: r,
|
|
17038
17059
|
projects_exclude_json: i
|
|
17039
17060
|
}).where(k(Y.peer_device_id, t)).run();
|
|
17040
17061
|
}
|
|
17041
|
-
function
|
|
17062
|
+
function lx(e, t, n) {
|
|
17042
17063
|
N(e, { schema: H }).update(Y).set({ claimed_local_actor: +!!n }).where(k(Y.peer_device_id, t)).run();
|
|
17043
17064
|
}
|
|
17044
|
-
var
|
|
17045
|
-
function
|
|
17065
|
+
var ux = "codemem";
|
|
17066
|
+
function dx() {
|
|
17046
17067
|
let e = process.env.CODEMEM_SYNC_MDNS;
|
|
17047
17068
|
if (e) return e === "1" || e.toLowerCase() === "true";
|
|
17048
17069
|
try {
|
|
@@ -17051,9 +17072,9 @@ function ux() {
|
|
|
17051
17072
|
return !1;
|
|
17052
17073
|
}
|
|
17053
17074
|
}
|
|
17054
|
-
function
|
|
17075
|
+
function fx() {
|
|
17055
17076
|
try {
|
|
17056
|
-
let e =
|
|
17077
|
+
let e = tx("bonjour-service"), t = e.Bonjour ?? e.default;
|
|
17057
17078
|
return t ? new t(void 0, (e) => {
|
|
17058
17079
|
console.warn("[codemem] mDNS runtime error (non-fatal):", e?.message ?? e);
|
|
17059
17080
|
}) : null;
|
|
@@ -17061,40 +17082,40 @@ function dx() {
|
|
|
17061
17082
|
return null;
|
|
17062
17083
|
}
|
|
17063
17084
|
}
|
|
17064
|
-
var
|
|
17065
|
-
function mx() {
|
|
17066
|
-
if (fx) return px += 1, fx;
|
|
17067
|
-
let e = dx();
|
|
17068
|
-
return e ? (fx = e, px = 1, fx) : null;
|
|
17069
|
-
}
|
|
17085
|
+
var px = null, mx = 0;
|
|
17070
17086
|
function hx() {
|
|
17071
|
-
if (
|
|
17072
|
-
let e = fx;
|
|
17073
|
-
|
|
17087
|
+
if (px) return mx += 1, px;
|
|
17088
|
+
let e = fx();
|
|
17089
|
+
return e ? (px = e, mx = 1, px) : null;
|
|
17090
|
+
}
|
|
17091
|
+
function gx() {
|
|
17092
|
+
if (!px || (mx = Math.max(0, mx - 1), mx > 0)) return;
|
|
17093
|
+
let e = px;
|
|
17094
|
+
px = null;
|
|
17074
17095
|
try {
|
|
17075
17096
|
e.destroy();
|
|
17076
17097
|
} catch {}
|
|
17077
17098
|
}
|
|
17078
|
-
function
|
|
17079
|
-
if (!
|
|
17080
|
-
let n =
|
|
17099
|
+
function _x(e, t) {
|
|
17100
|
+
if (!dx() || !e || !t || !Number.isFinite(t)) return { close() {} };
|
|
17101
|
+
let n = hx();
|
|
17081
17102
|
if (!n) return { close() {} };
|
|
17082
17103
|
let r = null;
|
|
17083
17104
|
try {
|
|
17084
17105
|
r = n.publish({
|
|
17085
17106
|
name: `codemem-${e.slice(0, 12)}`,
|
|
17086
|
-
type:
|
|
17107
|
+
type: ux,
|
|
17087
17108
|
port: t,
|
|
17088
17109
|
txt: { device_id: e }
|
|
17089
17110
|
});
|
|
17090
17111
|
} catch {
|
|
17091
|
-
return
|
|
17112
|
+
return gx(), { close() {} };
|
|
17092
17113
|
}
|
|
17093
17114
|
let i = !1;
|
|
17094
17115
|
return { close() {
|
|
17095
17116
|
if (i) return;
|
|
17096
17117
|
i = !0;
|
|
17097
|
-
let e = () =>
|
|
17118
|
+
let e = () => gx();
|
|
17098
17119
|
try {
|
|
17099
17120
|
r?.stop(() => e());
|
|
17100
17121
|
} catch {
|
|
@@ -17102,13 +17123,13 @@ function gx(e, t) {
|
|
|
17102
17123
|
}
|
|
17103
17124
|
} };
|
|
17104
17125
|
}
|
|
17105
|
-
async function
|
|
17106
|
-
if (!
|
|
17107
|
-
let t =
|
|
17126
|
+
async function vx(e = 1500) {
|
|
17127
|
+
if (!dx()) return [];
|
|
17128
|
+
let t = hx();
|
|
17108
17129
|
if (!t) return [];
|
|
17109
17130
|
let n = [], r = /* @__PURE__ */ new Set(), i = !0, a = null;
|
|
17110
17131
|
try {
|
|
17111
|
-
a = t.find({ type:
|
|
17132
|
+
a = t.find({ type: ux }, (e) => {
|
|
17112
17133
|
if (!i) return;
|
|
17113
17134
|
let t = `${e.name}|${e.host ?? e.fqdn ?? ""}|${e.port}`;
|
|
17114
17135
|
if (r.has(t)) return;
|
|
@@ -17128,11 +17149,11 @@ async function _x(e = 1500) {
|
|
|
17128
17149
|
try {
|
|
17129
17150
|
a?.stop();
|
|
17130
17151
|
} catch {}
|
|
17131
|
-
|
|
17152
|
+
gx();
|
|
17132
17153
|
}
|
|
17133
17154
|
return n;
|
|
17134
17155
|
}
|
|
17135
|
-
function
|
|
17156
|
+
function yx(e, t) {
|
|
17136
17157
|
let n = [];
|
|
17137
17158
|
for (let r of t) {
|
|
17138
17159
|
let t = r.properties ?? {}, i = t.device_id ?? t.device_id;
|
|
@@ -17146,56 +17167,56 @@ function vx(e, t) {
|
|
|
17146
17167
|
}
|
|
17147
17168
|
//#endregion
|
|
17148
17169
|
//#region src/sync-pass.ts
|
|
17149
|
-
var
|
|
17150
|
-
function
|
|
17170
|
+
var bx = 1048576, xx = !1, Sx = 500, Cx = 2e3, wx = "2";
|
|
17171
|
+
function Tx(e, t) {
|
|
17151
17172
|
return !t || !t.includes("|") ? !1 : e ? t > e : !0;
|
|
17152
17173
|
}
|
|
17153
|
-
function
|
|
17174
|
+
function Ex(e) {
|
|
17154
17175
|
if (!e) return null;
|
|
17155
17176
|
let t = e.error, n = e.reason;
|
|
17156
17177
|
return typeof t == "string" && typeof n == "string" ? `${t}:${n}` : typeof t == "string" ? t : null;
|
|
17157
17178
|
}
|
|
17158
|
-
function
|
|
17179
|
+
function Dx(e) {
|
|
17159
17180
|
return e.length === 0 ? null : `all addresses failed | ${e.map((e) => `${e.address}: ${e.error}`).join(" || ")}`;
|
|
17160
17181
|
}
|
|
17161
|
-
function
|
|
17182
|
+
function Ox(e) {
|
|
17162
17183
|
if (typeof e != "string") return null;
|
|
17163
17184
|
let t = e.trim();
|
|
17164
17185
|
return t.length > 0 ? t : null;
|
|
17165
17186
|
}
|
|
17166
|
-
function
|
|
17187
|
+
function kx(e) {
|
|
17167
17188
|
let t = e?.sync_reset;
|
|
17168
17189
|
if (!t || typeof t != "object" || Array.isArray(t)) return null;
|
|
17169
17190
|
let n = t;
|
|
17170
17191
|
if (!Number.isFinite(n.generation) || typeof n.snapshot_id != "string" || n.snapshot_id.trim().length === 0) return null;
|
|
17171
|
-
let r =
|
|
17192
|
+
let r = Ox(n.baseline_cursor);
|
|
17172
17193
|
return {
|
|
17173
|
-
scope_id:
|
|
17194
|
+
scope_id: Ox(n.scope_id),
|
|
17174
17195
|
generation: Number(n.generation),
|
|
17175
17196
|
snapshot_id: n.snapshot_id.trim(),
|
|
17176
17197
|
baseline_cursor: r,
|
|
17177
|
-
retained_floor_cursor:
|
|
17198
|
+
retained_floor_cursor: Ox(n.retained_floor_cursor)
|
|
17178
17199
|
};
|
|
17179
17200
|
}
|
|
17180
|
-
function
|
|
17201
|
+
function Ax(e) {
|
|
17181
17202
|
return !(!e || e.reset_required !== !1 || !Number.isFinite(e.generation) || typeof e.snapshot_id != "string" || e.snapshot_id.trim().length === 0 || !(e.baseline_cursor == null || typeof e.baseline_cursor == "string") || !(e.retained_floor_cursor == null || typeof e.retained_floor_cursor == "string") || !Array.isArray(e.ops) || !(e.next_cursor == null || typeof e.next_cursor == "string") || !Number.isFinite(e.skipped));
|
|
17182
17203
|
}
|
|
17183
|
-
function
|
|
17184
|
-
let t =
|
|
17204
|
+
function jx(e) {
|
|
17205
|
+
let t = Sb(e);
|
|
17185
17206
|
return {
|
|
17186
|
-
local:
|
|
17207
|
+
local: bb,
|
|
17187
17208
|
peer: t,
|
|
17188
|
-
negotiated:
|
|
17209
|
+
negotiated: Cb(bb, t)
|
|
17189
17210
|
};
|
|
17190
17211
|
}
|
|
17191
|
-
function jx() {
|
|
17192
|
-
return { [vb]: yb };
|
|
17193
|
-
}
|
|
17194
17212
|
function Mx() {
|
|
17195
|
-
return
|
|
17213
|
+
return { [yb]: bb };
|
|
17214
|
+
}
|
|
17215
|
+
function Nx() {
|
|
17216
|
+
return jx("unsupported");
|
|
17196
17217
|
}
|
|
17197
|
-
function
|
|
17198
|
-
let r = N(e, { schema: H }), i = (/* @__PURE__ */ new Date()).toISOString(), a = n.capabilities ??
|
|
17218
|
+
function Px(e, t, n) {
|
|
17219
|
+
let r = N(e, { schema: H }), i = (/* @__PURE__ */ new Date()).toISOString(), a = n.capabilities ?? Nx();
|
|
17199
17220
|
r.insert(ft).values({
|
|
17200
17221
|
peer_device_id: t,
|
|
17201
17222
|
started_at: i,
|
|
@@ -17209,7 +17230,7 @@ function Nx(e, t, n) {
|
|
|
17209
17230
|
negotiated_sync_capability: a.negotiated
|
|
17210
17231
|
}).run();
|
|
17211
17232
|
}
|
|
17212
|
-
function
|
|
17233
|
+
function Fx(e, t, n, r) {
|
|
17213
17234
|
let i = N(e, { schema: H }), { replicationOps: a } = H, o;
|
|
17214
17235
|
if (t) {
|
|
17215
17236
|
let e = t.indexOf("|"), s = e >= 0 ? t.slice(0, e) : t, c = e >= 0 ? t.slice(e + 1) : "";
|
|
@@ -17221,12 +17242,12 @@ function Px(e, t, n, r) {
|
|
|
17221
17242
|
let c = `${s.created_at}|${s.op_id}`;
|
|
17222
17243
|
return [o, c];
|
|
17223
17244
|
}
|
|
17224
|
-
var
|
|
17225
|
-
async function
|
|
17245
|
+
var Ix = 8;
|
|
17246
|
+
async function Lx(e, t, n, r, i = 0) {
|
|
17226
17247
|
if (n.length === 0) return;
|
|
17227
17248
|
let a = {
|
|
17228
17249
|
ops: n,
|
|
17229
|
-
sync_capability:
|
|
17250
|
+
sync_capability: bb
|
|
17230
17251
|
}, o = Buffer.from(JSON.stringify(a), "utf-8"), [s, c] = await kl("POST", e, {
|
|
17231
17252
|
headers: {
|
|
17232
17253
|
..._r({
|
|
@@ -17236,28 +17257,28 @@ async function Ix(e, t, n, r, i = 0) {
|
|
|
17236
17257
|
bodyBytes: o,
|
|
17237
17258
|
keysDir: r
|
|
17238
17259
|
}),
|
|
17239
|
-
...
|
|
17260
|
+
...Mx()
|
|
17240
17261
|
},
|
|
17241
17262
|
body: a,
|
|
17242
17263
|
bodyBytes: o
|
|
17243
17264
|
});
|
|
17244
17265
|
if (s === 200 && c != null) return;
|
|
17245
|
-
let l =
|
|
17246
|
-
if (s === 413 && n.length > 1 && i <
|
|
17266
|
+
let l = Ex(c);
|
|
17267
|
+
if (s === 413 && n.length > 1 && i < Ix && (l === "payload_too_large" || l === "too_many_ops")) {
|
|
17247
17268
|
let a = Math.floor(n.length / 2);
|
|
17248
|
-
await
|
|
17269
|
+
await Lx(e, t, n.slice(0, a), r, i + 1), await Lx(e, t, n.slice(a), r, i + 1);
|
|
17249
17270
|
return;
|
|
17250
17271
|
}
|
|
17251
17272
|
let u = l ? ` (${s}: ${l})` : ` (${s})`;
|
|
17252
17273
|
throw Error(`peer ops push failed${u}`);
|
|
17253
17274
|
}
|
|
17254
|
-
function
|
|
17275
|
+
function Rx(e) {
|
|
17255
17276
|
Hn(e), tf(e, 2e3), nf(e, 200);
|
|
17256
17277
|
}
|
|
17257
|
-
async function
|
|
17278
|
+
async function zx(e, t, n, r) {
|
|
17258
17279
|
Hn(e);
|
|
17259
|
-
let i = r?.limit ??
|
|
17260
|
-
!o && !
|
|
17280
|
+
let i = r?.limit ?? Sx, a = r?.keysDir, o = r?.scanner;
|
|
17281
|
+
!o && !xx && (xx = !0, process.stderr.write("[codemem] sync apply running without explicit scanner — workspace-level secret rules will not apply to inbound peer content\n"));
|
|
17261
17282
|
let s = N(e, { schema: H }).select({ pinned_fingerprint: Y.pinned_fingerprint }).from(Y).where(k(Y.peer_device_id, t)).get()?.pinned_fingerprint ?? "";
|
|
17262
17283
|
if (!s) return {
|
|
17263
17284
|
ok: !1,
|
|
@@ -17271,7 +17292,7 @@ async function Rx(e, t, n, r) {
|
|
|
17271
17292
|
[u] = dr(e, { keysDir: a });
|
|
17272
17293
|
} catch (n) {
|
|
17273
17294
|
let r = `device identity unavailable: ${n instanceof Error ? n.message.trim() || n.constructor.name : "unknown"}`;
|
|
17274
|
-
return
|
|
17295
|
+
return Px(e, t, {
|
|
17275
17296
|
ok: !1,
|
|
17276
17297
|
error: r
|
|
17277
17298
|
}), {
|
|
@@ -17296,15 +17317,15 @@ async function Rx(e, t, n, r) {
|
|
|
17296
17317
|
bodyBytes: Buffer.alloc(0),
|
|
17297
17318
|
keysDir: a
|
|
17298
17319
|
}),
|
|
17299
|
-
...
|
|
17320
|
+
...Mx()
|
|
17300
17321
|
} });
|
|
17301
17322
|
if (d !== 200 || !f) {
|
|
17302
|
-
let e =
|
|
17323
|
+
let e = Ex(f), t = e ? ` (${d}: ${e})` : ` (${d})`;
|
|
17303
17324
|
throw Error(`peer status failed${t}`);
|
|
17304
17325
|
}
|
|
17305
17326
|
if (f.fingerprint !== s) throw Error("peer fingerprint mismatch");
|
|
17306
|
-
if (p =
|
|
17307
|
-
let m =
|
|
17327
|
+
if (p = jx(f.sync_capability), String(f.protocol_version ?? "") !== wx) throw Error(`peer protocol mismatch (expected ${wx}, got ${String(f.protocol_version ?? "missing")})`);
|
|
17328
|
+
let m = kx(f);
|
|
17308
17329
|
if (!m) throw Error("peer status missing sync_reset boundary");
|
|
17309
17330
|
if (c === null && l === null && Number(e.prepare("SELECT count(*) as n FROM memory_items WHERE import_key IS NOT NULL").get()?.n ?? 0) === 0) try {
|
|
17310
17331
|
let r = {
|
|
@@ -17315,11 +17336,11 @@ async function Rx(e, t, n, r) {
|
|
|
17315
17336
|
retained_floor_cursor: m.retained_floor_cursor ?? null,
|
|
17316
17337
|
reset_required: !0,
|
|
17317
17338
|
reason: "initial_bootstrap"
|
|
17318
|
-
}, { items: i } = await
|
|
17339
|
+
}, { items: i } = await qb(n, r, u, {
|
|
17319
17340
|
keysDir: a,
|
|
17320
|
-
pageSize:
|
|
17341
|
+
pageSize: Cx
|
|
17321
17342
|
}), s = Number(e.prepare("SELECT count(*) as n FROM memory_items WHERE import_key IS NOT NULL").get()?.n ?? 0);
|
|
17322
|
-
if (s > 0) return
|
|
17343
|
+
if (s > 0) return Px(e, t, {
|
|
17323
17344
|
ok: !1,
|
|
17324
17345
|
error: "needs_attention:shared_memories_appeared_during_bootstrap",
|
|
17325
17346
|
capabilities: p
|
|
@@ -17331,9 +17352,9 @@ async function Rx(e, t, n, r) {
|
|
|
17331
17352
|
opsOut: 0,
|
|
17332
17353
|
addressErrors: []
|
|
17333
17354
|
};
|
|
17334
|
-
let c =
|
|
17355
|
+
let c = ex(e, t, i, r, o);
|
|
17335
17356
|
if (!c.ok) throw Error("initial bootstrap apply failed");
|
|
17336
|
-
return
|
|
17357
|
+
return sx(e, t, n), Px(e, t, {
|
|
17337
17358
|
ok: !0,
|
|
17338
17359
|
opsIn: c.applied,
|
|
17339
17360
|
opsOut: 0,
|
|
@@ -17364,7 +17385,7 @@ async function Rx(e, t, n, r) {
|
|
|
17364
17385
|
bodyBytes: Buffer.alloc(0),
|
|
17365
17386
|
keysDir: a
|
|
17366
17387
|
}),
|
|
17367
|
-
...
|
|
17388
|
+
...Mx()
|
|
17368
17389
|
} });
|
|
17369
17390
|
if (_ === 409 && v?.reset_required === !0) {
|
|
17370
17391
|
let r = pd(e), i = {
|
|
@@ -17376,7 +17397,7 @@ async function Rx(e, t, n, r) {
|
|
|
17376
17397
|
baseline_cursor: typeof v.baseline_cursor == "string" && v.baseline_cursor.trim() ? v.baseline_cursor.trim() : null,
|
|
17377
17398
|
retained_floor_cursor: typeof v.retained_floor_cursor == "string" && v.retained_floor_cursor.trim() ? v.retained_floor_cursor.trim() : null
|
|
17378
17399
|
};
|
|
17379
|
-
if (r.dirty) return
|
|
17400
|
+
if (r.dirty) return Px(e, t, {
|
|
17380
17401
|
ok: !1,
|
|
17381
17402
|
error: `needs_attention:local_unsynced_shared_memory:${r.count}`,
|
|
17382
17403
|
capabilities: p
|
|
@@ -17390,8 +17411,8 @@ async function Rx(e, t, n, r) {
|
|
|
17390
17411
|
resetRequired: i
|
|
17391
17412
|
};
|
|
17392
17413
|
try {
|
|
17393
|
-
let { items: r } = await
|
|
17394
|
-
if (s.dirty) return
|
|
17414
|
+
let { items: r } = await qb(n, i, u, { keysDir: a }), s = pd(e);
|
|
17415
|
+
if (s.dirty) return Px(e, t, {
|
|
17395
17416
|
ok: !1,
|
|
17396
17417
|
error: `needs_attention:local_unsynced_shared_memory:${s.count}`,
|
|
17397
17418
|
capabilities: p
|
|
@@ -17404,9 +17425,9 @@ async function Rx(e, t, n, r) {
|
|
|
17404
17425
|
addressErrors: [],
|
|
17405
17426
|
resetRequired: i
|
|
17406
17427
|
};
|
|
17407
|
-
let c =
|
|
17428
|
+
let c = ex(e, t, r, i, o);
|
|
17408
17429
|
if (!c.ok) throw Error("bootstrap apply failed");
|
|
17409
|
-
return
|
|
17430
|
+
return sx(e, t, n), Px(e, t, {
|
|
17410
17431
|
ok: !0,
|
|
17411
17432
|
opsIn: c.applied,
|
|
17412
17433
|
opsOut: 0,
|
|
@@ -17420,7 +17441,7 @@ async function Rx(e, t, n, r) {
|
|
|
17420
17441
|
};
|
|
17421
17442
|
} catch (r) {
|
|
17422
17443
|
let a = r instanceof Error ? r.message : String(r);
|
|
17423
|
-
return
|
|
17444
|
+
return Px(e, t, {
|
|
17424
17445
|
ok: !1,
|
|
17425
17446
|
error: `bootstrap_failed:${a}`,
|
|
17426
17447
|
capabilities: p
|
|
@@ -17436,10 +17457,10 @@ async function Rx(e, t, n, r) {
|
|
|
17436
17457
|
}
|
|
17437
17458
|
}
|
|
17438
17459
|
if (_ !== 200 || v == null) {
|
|
17439
|
-
let e =
|
|
17460
|
+
let e = Ex(v), t = e ? ` (${_}: ${e})` : ` (${_})`;
|
|
17440
17461
|
throw Error(`peer ops fetch failed${t}`);
|
|
17441
17462
|
}
|
|
17442
|
-
if (!
|
|
17463
|
+
if (!Ax(v)) throw Error("invalid ops response");
|
|
17443
17464
|
let y = id(v), b = y.find((e) => e.device_id !== t || e.clock_device_id !== t);
|
|
17444
17465
|
if (b) throw Error(`inbound op device mismatch:${b.op_id}`);
|
|
17445
17466
|
let x = p?.negotiated === "unsupported" ? {
|
|
@@ -17451,7 +17472,7 @@ async function Rx(e, t, n, r) {
|
|
|
17451
17472
|
throw Error(`inbound scope rejected:${e}`);
|
|
17452
17473
|
}
|
|
17453
17474
|
try {
|
|
17454
|
-
|
|
17475
|
+
Fb(e, S.vectorWork);
|
|
17455
17476
|
} catch (t) {
|
|
17456
17477
|
let n = await ks(e, S.vectorWork);
|
|
17457
17478
|
if (n.errors.length > 0) {
|
|
@@ -17459,15 +17480,15 @@ async function Rx(e, t, n, r) {
|
|
|
17459
17480
|
throw Error(`vector catch-up queue failed: ${t instanceof Error ? t.message : String(t)}; fallback failed: ${e}`);
|
|
17460
17481
|
}
|
|
17461
17482
|
}
|
|
17462
|
-
let C =
|
|
17463
|
-
|
|
17464
|
-
let [w, ee] =
|
|
17483
|
+
let C = Ox(v.next_cursor);
|
|
17484
|
+
Tx(c, C) && (nd(e, t, { lastApplied: C }), c = C);
|
|
17485
|
+
let [w, ee] = Fx(e, l, u, i), [te, ne, re] = Rd(e, w, t, { localDeviceId: u }), ie = re?.skipped_count ?? 0, T = `${n}/v1/ops`;
|
|
17465
17486
|
if (te.length > 0) {
|
|
17466
|
-
let e = Zu(te,
|
|
17467
|
-
for (let t of e) await
|
|
17487
|
+
let e = Zu(te, bx);
|
|
17488
|
+
for (let t of e) await Lx(T, u, t, a);
|
|
17468
17489
|
}
|
|
17469
17490
|
let ae = ne ?? ee;
|
|
17470
|
-
return ae &&
|
|
17491
|
+
return ae && Tx(l, ae) && (nd(e, t, { lastAcked: ae }), l = ae), sx(e, t, n), Px(e, t, {
|
|
17471
17492
|
ok: !0,
|
|
17472
17493
|
opsIn: S.applied,
|
|
17473
17494
|
opsOut: te.length,
|
|
@@ -17490,8 +17511,8 @@ async function Rx(e, t, n, r) {
|
|
|
17490
17511
|
}
|
|
17491
17512
|
}
|
|
17492
17513
|
}
|
|
17493
|
-
let m =
|
|
17494
|
-
return f || (m = "no dialable peer addresses"), m ||= "sync failed without diagnostic detail",
|
|
17514
|
+
let m = Dx(d);
|
|
17515
|
+
return f || (m = "no dialable peer addresses"), m ||= "sync failed without diagnostic detail", Px(e, t, {
|
|
17495
17516
|
ok: !1,
|
|
17496
17517
|
error: m,
|
|
17497
17518
|
capabilities: p
|
|
@@ -17503,15 +17524,15 @@ async function Rx(e, t, n, r) {
|
|
|
17503
17524
|
addressErrors: d
|
|
17504
17525
|
};
|
|
17505
17526
|
}
|
|
17506
|
-
async function
|
|
17527
|
+
async function Bx(e, t, n) {
|
|
17507
17528
|
let r = N(e, { schema: H }).select({ addresses_json: Y.addresses_json }).from(Y).where(k(Y.peer_device_id, t)).get(), i = [];
|
|
17508
17529
|
if (r?.addresses_json) try {
|
|
17509
17530
|
let e = JSON.parse(r.addresses_json);
|
|
17510
17531
|
Array.isArray(e) && (i = e.filter((e) => typeof e == "string"));
|
|
17511
17532
|
} catch {}
|
|
17512
|
-
return
|
|
17533
|
+
return zx(e, t, i, n);
|
|
17513
17534
|
}
|
|
17514
|
-
var
|
|
17535
|
+
var Vx = [
|
|
17515
17536
|
"no route to host",
|
|
17516
17537
|
"connection refused",
|
|
17517
17538
|
"network is unreachable",
|
|
@@ -17522,33 +17543,33 @@ var Bx = [
|
|
|
17522
17543
|
"errno 61",
|
|
17523
17544
|
"errno 60",
|
|
17524
17545
|
"errno 111"
|
|
17525
|
-
],
|
|
17526
|
-
function
|
|
17546
|
+
], Hx = 120, Ux = 1800;
|
|
17547
|
+
function Wx(e) {
|
|
17527
17548
|
if (!e) return !1;
|
|
17528
17549
|
let t = e.toLowerCase();
|
|
17529
|
-
return
|
|
17550
|
+
return Vx.some((e) => t.includes(e));
|
|
17530
17551
|
}
|
|
17531
|
-
function
|
|
17552
|
+
function Gx(e, t, n = 10) {
|
|
17532
17553
|
let r = N(e, { schema: H }).select({
|
|
17533
17554
|
ok: ft.ok,
|
|
17534
17555
|
error: ft.error
|
|
17535
17556
|
}).from(ft).where(k(ft.peer_device_id, t)).orderBy(ue(ft.started_at)).limit(n).all(), i = 0;
|
|
17536
17557
|
for (let e of r) {
|
|
17537
17558
|
if (e.ok) break;
|
|
17538
|
-
if (
|
|
17559
|
+
if (Wx(e.error)) i++;
|
|
17539
17560
|
else break;
|
|
17540
17561
|
}
|
|
17541
17562
|
return i;
|
|
17542
17563
|
}
|
|
17543
|
-
function
|
|
17564
|
+
function Kx(e) {
|
|
17544
17565
|
if (e <= 1) return 0;
|
|
17545
17566
|
let t = Math.min(e - 1, 8);
|
|
17546
|
-
return Math.min(
|
|
17567
|
+
return Math.min(Hx * 2 ** (t - 1), Ux) * (.5 + Math.random() * .5);
|
|
17547
17568
|
}
|
|
17548
|
-
function
|
|
17549
|
-
let n =
|
|
17569
|
+
function qx(e, t) {
|
|
17570
|
+
let n = Gx(e, t);
|
|
17550
17571
|
if (n < 2) return !1;
|
|
17551
|
-
let r =
|
|
17572
|
+
let r = Kx(n);
|
|
17552
17573
|
if (r <= 0) return !1;
|
|
17553
17574
|
let i = N(e, { schema: H }).select({ started_at: ft.started_at }).from(ft).where(k(ft.peer_device_id, t)).orderBy(ue(ft.started_at)).limit(1).get();
|
|
17554
17575
|
if (!i?.started_at) return !1;
|
|
@@ -17561,7 +17582,7 @@ function Kx(e, t) {
|
|
|
17561
17582
|
}
|
|
17562
17583
|
//#endregion
|
|
17563
17584
|
//#region src/sync-daemon.ts
|
|
17564
|
-
function
|
|
17585
|
+
function Jx(e) {
|
|
17565
17586
|
let t = N(e, { schema: H }), n = (/* @__PURE__ */ new Date()).toISOString();
|
|
17566
17587
|
t.insert(mt).values({
|
|
17567
17588
|
id: 1,
|
|
@@ -17575,7 +17596,7 @@ function qx(e) {
|
|
|
17575
17596
|
}
|
|
17576
17597
|
}).run();
|
|
17577
17598
|
}
|
|
17578
|
-
function
|
|
17599
|
+
function Yx(e, t, n) {
|
|
17579
17600
|
let r = N(e, { schema: H }), i = (/* @__PURE__ */ new Date()).toISOString();
|
|
17580
17601
|
r.insert(mt).values({
|
|
17581
17602
|
id: 1,
|
|
@@ -17591,11 +17612,11 @@ function Jx(e, t, n) {
|
|
|
17591
17612
|
}
|
|
17592
17613
|
}).run();
|
|
17593
17614
|
}
|
|
17594
|
-
function
|
|
17615
|
+
function Xx(e) {
|
|
17595
17616
|
let t = N(e, { schema: H }).select({ phase: mt.phase }).from(mt).where(k(mt.id, 1)).get()?.phase;
|
|
17596
17617
|
return t === "needs_attention" ? t : null;
|
|
17597
17618
|
}
|
|
17598
|
-
function
|
|
17619
|
+
function Zx(e, t) {
|
|
17599
17620
|
N(e, { schema: H }).insert(mt).values({
|
|
17600
17621
|
id: 1,
|
|
17601
17622
|
phase: t
|
|
@@ -17604,18 +17625,18 @@ function Xx(e, t) {
|
|
|
17604
17625
|
set: { phase: t }
|
|
17605
17626
|
}).run();
|
|
17606
17627
|
}
|
|
17607
|
-
async function
|
|
17628
|
+
async function Qx(e, t, n) {
|
|
17608
17629
|
let r = Rl();
|
|
17609
17630
|
return zl(r) ? (await Vl({
|
|
17610
17631
|
db: e,
|
|
17611
17632
|
dbPath: t
|
|
17612
17633
|
}, r, { keysDir: n }), await Cu(e, r), !0) : !1;
|
|
17613
17634
|
}
|
|
17614
|
-
async function
|
|
17635
|
+
async function $x(e, t, n, r) {
|
|
17615
17636
|
let i = N(e, { schema: H }).select({ peer_device_id: Y.peer_device_id }).from(Y).all();
|
|
17616
17637
|
if (i.length === 0) return [];
|
|
17617
17638
|
let a = Rl().syncOpsLimit;
|
|
17618
|
-
|
|
17639
|
+
Rx(e);
|
|
17619
17640
|
let o = [];
|
|
17620
17641
|
for (let s of i) {
|
|
17621
17642
|
let i = s.peer_device_id;
|
|
@@ -17627,7 +17648,7 @@ async function Qx(e, t, n, r) {
|
|
|
17627
17648
|
});
|
|
17628
17649
|
continue;
|
|
17629
17650
|
}
|
|
17630
|
-
if (
|
|
17651
|
+
if (qx(e, i)) {
|
|
17631
17652
|
o.push({
|
|
17632
17653
|
ok: !1,
|
|
17633
17654
|
skipped: !0,
|
|
@@ -17635,7 +17656,7 @@ async function Qx(e, t, n, r) {
|
|
|
17635
17656
|
});
|
|
17636
17657
|
continue;
|
|
17637
17658
|
}
|
|
17638
|
-
let c = await
|
|
17659
|
+
let c = await Bx(e, i, {
|
|
17639
17660
|
keysDir: t,
|
|
17640
17661
|
limit: a,
|
|
17641
17662
|
scanner: r
|
|
@@ -17649,13 +17670,13 @@ async function Qx(e, t, n, r) {
|
|
|
17649
17670
|
}
|
|
17650
17671
|
return o;
|
|
17651
17672
|
}
|
|
17652
|
-
async function
|
|
17673
|
+
async function eS(e) {
|
|
17653
17674
|
let t = e?.intervalS ?? 120, n = Dn(e?.dbPath), r = e?.keysDir, i = e?.signal, a = e?.onPhaseChange, o = e?.scanner;
|
|
17654
17675
|
a?.("starting");
|
|
17655
17676
|
let s = Mn(n), c = null;
|
|
17656
17677
|
try {
|
|
17657
17678
|
let [t] = dr(s, { keysDir: r });
|
|
17658
|
-
|
|
17679
|
+
dx() && e?.port && (c = _x(t, e.port));
|
|
17659
17680
|
} finally {
|
|
17660
17681
|
s.close();
|
|
17661
17682
|
}
|
|
@@ -17665,7 +17686,7 @@ async function $x(e) {
|
|
|
17665
17686
|
}
|
|
17666
17687
|
return new Promise((e) => {
|
|
17667
17688
|
let s = !1, l = !1, u = () => {
|
|
17668
|
-
s || (s = !0,
|
|
17689
|
+
s || (s = !0, tS(n, r, o).finally(() => {
|
|
17669
17690
|
s = !1, l || (l = !0, a?.("running"));
|
|
17670
17691
|
}));
|
|
17671
17692
|
}, d = setInterval(u, t * 1e3);
|
|
@@ -17682,38 +17703,38 @@ async function $x(e) {
|
|
|
17682
17703
|
}
|
|
17683
17704
|
});
|
|
17684
17705
|
}
|
|
17685
|
-
async function
|
|
17706
|
+
async function tS(e, t, n) {
|
|
17686
17707
|
let r = Mn(e);
|
|
17687
17708
|
try {
|
|
17688
17709
|
Hn(r);
|
|
17689
17710
|
try {
|
|
17690
|
-
await
|
|
17711
|
+
await Qx(r, e, t);
|
|
17691
17712
|
} catch {}
|
|
17692
|
-
(await
|
|
17713
|
+
(await $x(r, t, await Kl(r, e, t), n)).some((e) => !e.ok && e.error?.includes("needs_attention")) ? Zx(r, "needs_attention") : Jx(r);
|
|
17693
17714
|
} catch (e) {
|
|
17694
|
-
|
|
17715
|
+
Yx(r, e instanceof Error ? e.message : String(e), e instanceof Error ? e.stack ?? "" : "");
|
|
17695
17716
|
} finally {
|
|
17696
17717
|
r.close();
|
|
17697
17718
|
}
|
|
17698
17719
|
}
|
|
17699
17720
|
//#endregion
|
|
17700
17721
|
//#region src/sync-retention-runner.ts
|
|
17701
|
-
function
|
|
17722
|
+
function nS(e) {
|
|
17702
17723
|
let t = String(e ?? "").trim();
|
|
17703
17724
|
return t.length > 0 ? t : Au;
|
|
17704
17725
|
}
|
|
17705
|
-
function
|
|
17726
|
+
function rS(e) {
|
|
17706
17727
|
e.exec("\n CREATE 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 CREATE 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 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 ");
|
|
17707
17728
|
}
|
|
17708
|
-
function
|
|
17729
|
+
function iS(e) {
|
|
17709
17730
|
let t = e.prepare("SELECT scope_id FROM (\n SELECT COALESCE(NULLIF(TRIM(scope_id), ''), ?) AS scope_id FROM replication_ops\n UNION\n SELECT COALESCE(NULLIF(TRIM(scope_id), ''), ?) AS scope_id FROM sync_reset_state_v2\n UNION\n SELECT COALESCE(NULLIF(TRIM(scope_id), ''), ?) AS scope_id FROM sync_retention_state_v2\n )\n ORDER BY CASE WHEN scope_id = ? THEN 0 ELSE 1 END, scope_id").all(Au, Au, Au, Au), n = new Set([Au]);
|
|
17710
17731
|
for (let e of t) {
|
|
17711
|
-
let t =
|
|
17732
|
+
let t = nS(e.scope_id);
|
|
17712
17733
|
n.add(t);
|
|
17713
17734
|
}
|
|
17714
17735
|
return Array.from(n);
|
|
17715
17736
|
}
|
|
17716
|
-
function
|
|
17737
|
+
function aS(e, t, n, r) {
|
|
17717
17738
|
e.insert(vt).values({
|
|
17718
17739
|
scope_id: t,
|
|
17719
17740
|
...n
|
|
@@ -17728,7 +17749,7 @@ function iS(e, t, n, r) {
|
|
|
17728
17749
|
set: n
|
|
17729
17750
|
}).run();
|
|
17730
17751
|
}
|
|
17731
|
-
function
|
|
17752
|
+
function oS(e, t, n, r, i) {
|
|
17732
17753
|
let a = i === Au;
|
|
17733
17754
|
try {
|
|
17734
17755
|
let o = yd(e, i), s = hd(e, {
|
|
@@ -17740,7 +17761,7 @@ function aS(e, t, n, r, i) {
|
|
|
17740
17761
|
maxPasses: n.maxCatchUpPasses,
|
|
17741
17762
|
signal: n.signal
|
|
17742
17763
|
});
|
|
17743
|
-
|
|
17764
|
+
aS(t, i, {
|
|
17744
17765
|
last_run_at: r,
|
|
17745
17766
|
last_duration_ms: Date.now() - Date.parse(r),
|
|
17746
17767
|
last_deleted_ops: s.totalDeleted,
|
|
@@ -17751,7 +17772,7 @@ function aS(e, t, n, r, i) {
|
|
|
17751
17772
|
last_error_at: null
|
|
17752
17773
|
}, a);
|
|
17753
17774
|
} catch (e) {
|
|
17754
|
-
|
|
17775
|
+
aS(t, i, {
|
|
17755
17776
|
last_run_at: r,
|
|
17756
17777
|
last_duration_ms: Date.now() - Date.parse(r),
|
|
17757
17778
|
last_deleted_ops: 0,
|
|
@@ -17763,13 +17784,13 @@ function aS(e, t, n, r, i) {
|
|
|
17763
17784
|
}, a);
|
|
17764
17785
|
}
|
|
17765
17786
|
}
|
|
17766
|
-
async function
|
|
17787
|
+
async function sS(e, t) {
|
|
17767
17788
|
if (!t.syncRetentionEnabled) return;
|
|
17768
|
-
|
|
17769
|
-
let n = N(e, { schema: H }), r = (/* @__PURE__ */ new Date()).toISOString(), i = t.scopeId === void 0 ?
|
|
17770
|
-
for (let a of i)
|
|
17789
|
+
rS(e);
|
|
17790
|
+
let n = N(e, { schema: H }), r = (/* @__PURE__ */ new Date()).toISOString(), i = t.scopeId === void 0 ? iS(e) : [nS(t.scopeId)];
|
|
17791
|
+
for (let a of i) oS(e, n, t, r, a);
|
|
17771
17792
|
}
|
|
17772
|
-
var
|
|
17793
|
+
var cS = class {
|
|
17773
17794
|
dbPath;
|
|
17774
17795
|
signal;
|
|
17775
17796
|
active = !1;
|
|
@@ -17797,7 +17818,7 @@ var sS = class {
|
|
|
17797
17818
|
if (!this.active || this.signal?.aborted) return;
|
|
17798
17819
|
let e = Rl(Rt()), t = Mn(this.dbPath);
|
|
17799
17820
|
try {
|
|
17800
|
-
await
|
|
17821
|
+
await sS(t, {
|
|
17801
17822
|
...e,
|
|
17802
17823
|
signal: this.signal
|
|
17803
17824
|
});
|
|
@@ -17805,8 +17826,8 @@ var sS = class {
|
|
|
17805
17826
|
t.close();
|
|
17806
17827
|
}
|
|
17807
17828
|
}
|
|
17808
|
-
},
|
|
17809
|
-
function
|
|
17829
|
+
}, lS = "scope_id";
|
|
17830
|
+
function uS(e, t) {
|
|
17810
17831
|
return t ? typeof e == "string" && e.trim() ? {
|
|
17811
17832
|
ok: !1,
|
|
17812
17833
|
reason: "unsupported_scope"
|
|
@@ -17819,31 +17840,31 @@ function lS(e, t) {
|
|
|
17819
17840
|
scope_id: null
|
|
17820
17841
|
};
|
|
17821
17842
|
}
|
|
17822
|
-
function
|
|
17843
|
+
function dS(e, t) {
|
|
17823
17844
|
return {
|
|
17824
17845
|
...e,
|
|
17825
17846
|
scope_id: t
|
|
17826
17847
|
};
|
|
17827
17848
|
}
|
|
17828
|
-
function
|
|
17849
|
+
function fS(e, t, n) {
|
|
17829
17850
|
return {
|
|
17830
17851
|
error: "reset_required",
|
|
17831
17852
|
reset_required: !0,
|
|
17832
17853
|
sync_capability: n,
|
|
17833
17854
|
reason: t,
|
|
17834
|
-
...
|
|
17855
|
+
...dS(e, null)
|
|
17835
17856
|
};
|
|
17836
17857
|
}
|
|
17837
17858
|
//#endregion
|
|
17838
17859
|
//#region src/test-utils.ts
|
|
17839
|
-
function
|
|
17860
|
+
function pS(e) {
|
|
17840
17861
|
hn(e);
|
|
17841
17862
|
}
|
|
17842
|
-
function
|
|
17863
|
+
function mS(e) {
|
|
17843
17864
|
let t = (/* @__PURE__ */ new Date()).toISOString(), n = e.prepare("INSERT INTO sessions(started_at, cwd, project, user, tool_version) VALUES (?, ?, ?, ?, ?)").run(t, "/tmp/test", "test-project", "test-user", "test");
|
|
17844
17865
|
return Number(n.lastInsertRowid);
|
|
17845
17866
|
}
|
|
17846
|
-
function
|
|
17867
|
+
function hS(e, t = "local") {
|
|
17847
17868
|
let n = "2026-04-01T00:00:00.000Z", r = "fixture-work-authorized", i = "fixture-oss-hidden", a = "mixedscopeleak";
|
|
17848
17869
|
e.prepare("INSERT OR IGNORE INTO sync_device(device_id, public_key, fingerprint, created_at) VALUES (?, ?, ?, ?)").run(t, "fixture-public-key", "fixture-fingerprint", n), e.prepare("INSERT OR REPLACE INTO replication_scopes(\n scope_id, label, kind, authority_type, coordinator_id, group_id,\n membership_epoch, status, created_at, updated_at\n ) VALUES (?, ?, 'team', 'coordinator', 'fixture-coordinator', 'fixture-group', 0, 'active', ?, ?)").run(r, "Authorized work fixture", n, n), e.prepare("INSERT OR REPLACE INTO replication_scopes(\n scope_id, label, kind, authority_type, coordinator_id, group_id,\n membership_epoch, status, created_at, updated_at\n ) VALUES (?, ?, 'team', 'coordinator', 'fixture-coordinator', 'fixture-group', 0, 'active', ?, ?)").run(i, "Hidden OSS fixture", n, n), e.prepare("INSERT OR REPLACE INTO scope_memberships(\n scope_id, device_id, role, status, membership_epoch,\n coordinator_id, group_id, updated_at\n ) VALUES (?, ?, 'member', 'active', 0, 'fixture-coordinator', 'fixture-group', ?)").run(r, t, n);
|
|
17849
17870
|
let o = e.prepare("INSERT INTO sessions(started_at, cwd, project, user, tool_version, metadata_json, import_key)\n VALUES (?, '/tmp/mixed-domain-fixture', 'mixed-domain-fixture', 'test-user', 'test', '{}', 'fixture-session')").run(n), s = Number(o.lastInsertRowid), c = (t) => {
|
|
@@ -17892,8 +17913,8 @@ function mS(e, t = "local") {
|
|
|
17892
17913
|
}
|
|
17893
17914
|
//#endregion
|
|
17894
17915
|
//#region src/index.ts
|
|
17895
|
-
var
|
|
17916
|
+
var gS = "0.32.0";
|
|
17896
17917
|
//#endregion
|
|
17897
|
-
export { ke as Api, V as BetterSqliteCoordinatorStore, Ft as CODEMEM_CONFIG_ENV_OVERRIDES, Ph as DEDUP_KEY_BACKFILL_JOB, R as DEFAULT_COORDINATOR_DB_PATH, En as DEFAULT_DB_PATH, Ql as DEFAULT_SCOPE_MEMBERSHIP_CACHE_MAX_AGE_MS, tx as DEFAULT_SERVICE_TYPE, Au as DEFAULT_SYNC_SCOPE_ID, o as DEFAULT_TIME_WINDOW_S, Rh as DedupKeyBackfillRunner, si as INJECTION_EVAL_SCENARIO_PACKS, Fv as LEGACY_SHARED_REVIEW_SCOPE_ID, Ei as LOCAL_DEFAULT_SCOPE_ID, yb 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, Of as MemoryStore, Op as ObserverAuthAdapter, em as ObserverAuthError, Tm as ObserverClient, Hy as REF_BACKFILL_JOB, Dg as RICH_TIER_DEFAULTS, Vy as RawEventSweeper, Jy as RefBackfillRunner, Sn as SCHEMA_VERSION, Iv as SCOPE_BACKFILL_JOB, n as SCOPE_MEMBERSHIP_REVOCATION_LIMITATION, Yy as SESSION_CONTEXT_BACKFILL_JOB, fr as SIGNATURE_VERSION, Eg as SIMPLE_TIER_DEFAULTS, lb as SUMMARY_DEDUP_BACKFILL_JOB, _b as SYNC_CAPABILITIES, vb as SYNC_CAPABILITY_HEADER, cS as SYNC_SCOPE_QUERY_PARAM, Qv as ScopeBackfillRunner, cb as SessionContextBackfillRunner, gb as SummaryDedupBackfillRunner, sS as SyncRetentionRunner, T_ as TRIVIAL_REQUESTS, Cb as VECTOR_MODEL_MIGRATION_JOB, hS as VERSION, Gb as VectorModelMigrationRunner, es as _resetEmbeddingClient, uS as addSyncScopeToBoundary, wl as addressDedupeKey, gx as advertiseMdns, Bm as aiBackfillStructuredContent, My as analyzeProjectScopeMappingChangeGuardrails, $b as applyBootstrapSnapshot, of as applyReplicationOps, zn as assertSchemaReady, cp as backfillMemoryDedupKeys, rp as backfillNarrativeFromBody, nf as backfillReplicationOps, Jv as backfillScopeIds, qf as backfillTagsText, js as backfillVectors, hn as bootstrapSchema, l_ as budgetToolEvents, _r as buildAuthHeaders, Ol as buildBaseUrl, pr as buildCanonicalRequest, Sp as buildCodexHeaders, Yi as buildFilterClauses, Xi as buildFilterClausesWithContext, Yh as buildImportKey, zr as buildIngestPayloadFromHook, $c as buildMemoryPack, tl as buildMemoryPackAsync, el as buildMemoryPackTrace, nl as buildMemoryPackTraceAsync, C_ as buildObserverPrompt, Rr as buildRawEventEnvelopeFromHook, _v as buildSessionContext, P_ as buildTranscript, gd as bulkPruneReplicationOpsByAgeCutoff, mi as canonicalMemoryKind, Mi as canonicalWorkspaceIdentity, Zu as chunkOpsBySize, Qo as chunkText, zv as classifyLegacyMemoryScope, uv as cleanOrphanSessions, yr as cleanupNonces, ga as clearMemoryRefs, ad as clockTuple, Rf as compareMemoryRoleReports, Yr as completeMaintenanceJob, Mn as connect, Xe as connectCoordinator, Wx as consecutiveConnectivityFailures, oh as coordinatorArchiveGroupAction, ih as coordinatorCreateGroupAction, xh as coordinatorCreateInviteAction, uh as coordinatorCreateScopeAction, vh as coordinatorDisableDeviceAction, yh as coordinatorEnableDeviceAction, zl as coordinatorEnabled, hh as coordinatorEnrollDeviceAction, ph as coordinatorGrantScopeMembershipAction, Sh as coordinatorImportInviteAction, Th as coordinatorListBootstrapGrantsAction, gh as coordinatorListDevicesAction, ch as coordinatorListGroupsAction, Ch as coordinatorListJoinRequestsAction, fh as coordinatorListScopeMembershipsAction, lh as coordinatorListScopesAction, bh as coordinatorRemoveDeviceAction, _h as coordinatorRenameDeviceAction, ah as coordinatorRenameGroupAction, wh as coordinatorReviewJoinRequestAction, Eh as coordinatorRevokeBootstrapGrantAction, mh as coordinatorRevokeScopeMembershipAction, Xl as coordinatorStatusSnapshot, sh as coordinatorUnarchiveGroupAction, dh as coordinatorUpdateScopeAction, br as createBetterSqliteCoordinatorApp, c as createCoordinatorApp, Jl as createCoordinatorReciprocalApproval, wx as cursorAdvances, ep as deactivateLowSignalMemories, $f as deactivateLowSignalObservations, Rg as decideExtractionReplayTier, s as decodeInvitePayload, tp as dedupNearDuplicateMemories, Ko as dedupeOrderedIds, Nh as deleteCoordinatorGroupPreference, Ly as deleteProjectScopeSettingsMapping, N_ as deriveRequest, ku as deriveTags, _x as discoverPeersViaMdns, rs as embedTexts, t as encodeInvitePayload, dr as ensureDeviceIdentity, Zr as ensureMaintenanceJobsSchema, yn as ensureSchemaBootstrapped, Vv as ensureScopeBackfillScopes, iu as ensureScopeMembershipCacheStateTable, Hs as estimateTokens, wg as evaluateSessionExtractionItems, n_ as eventToToolEvent, qa as expandQuery, Xo as explain, e as explainScopeMembershipRevocation, ig as exportMemories, i_ as extractAdapterEvent, je as extractApplyPatchPaths, F_ as extractAssistantMessages, I_ as extractAssistantUsage, r as extractInvitePayload, np as extractNarrativeFromBody, _p as extractOAuthAccess, bp as extractOAuthAccountId, xp as extractOAuthExpires, L_ as extractPrompts, vp as extractProviderApiKey, id as extractReplicationOps, r_ as extractToolEvents, Xr as failMaintenanceJob, Kb as fetchAllSnapshotPages, Kl as fetchCoordinatorStalePeers, Ou as fileTags, zd as filterReplicationOpsForSync, Rd as filterReplicationOpsForSyncWithStatus, ba as findByConcept, ya as findByFile, i as fingerprintPublicKey, M_ as firstSentence, yv as flushRawEvents, Un as fromJson, Wn as fromJsonStrict, sr as generateKeypair, Tu as getCachedScopeAuthorization, Lt as getCodememConfigPath, Ht as getCodememEnvOverrides, Ah as getCoordinatorGroupPreference, ns as getEmbeddingClient, gg as getExtractionBenchmarkProfile, oi as getInjectionEvalScenarioByPrompt, ci as getInjectionEvalScenarioPack, li as getInjectionEvalScenarioPrompts, Q as getMaintenanceJob, Lf as getMemoryRoleReport, Wt as getOpenCodeProviderConfig, sn as getProviderApiKey, an as getProviderBaseUrl, on as getProviderHeaders, rn as getProviderOptions, ri as getRawEventRelinkPlan, ni as getRawEventRelinkReport, zf as getRawEventStatus, Vf as getReliabilityMetrics, td as getReplicationCursor, Rn as getSchemaVersion, Ts as getSemanticIndexDiagnostics, Tg as getSessionExtractionEval, Cg as getSessionExtractionEvalScenario, di as getSummaryMetadata, Yx as getSyncDaemonPhase, Ku as getSyncResetState, At as getWorkspaceCodememConfigPath, jt as getWorkspaceScopedCodememConfigPath, X_ as hasMeaningfulObservation, Fh as hasPendingDedupKeyBackfill, Wy as hasPendingRefBackfill, Gv as hasPendingScopeBackfill, ab as hasPendingSessionContextBackfill, db as hasPendingSummaryDedupBackfill, pd as hasUnsyncedSharedMemoryChanges, Zo as hashText, mg as importMemories, cv as ingest, dv as ingestMain, ii as initDatabase, fS as initTestSchema, pS as insertTestSession, l as inviteLink, Ux as isConnectivityError, Ln as isEmbeddingDisabled, Qg as isInternalMemoryTool, Xf as isLowSignalObservation, od as isNewerClock, Wg as isSensitiveFieldName, fi as isSummaryLikeMemory, j_ as isTrivialRequest, Ya as kindBonus, wu as listCachedScopesForDevice, Jt as listConfiguredOpenCodeProviders, jh as listCoordinatorGroupPreferences, Zl as listCoordinatorJoinRequests, ql as listCoordinatorReciprocalApprovals, Gt as listCustomProviders, _g as listExtractionBenchmarkProfiles, Qd as listInboundScopeRejections, Kr as listMaintenanceJobs, Yt as listObserverProviderOptions, Ny as listProjectScopeCandidates, Py as listProjectScopeInventory, Dy as listProjectScopeSettingsMappings, Ey as listSharingDomainSettingsScopes, fd as loadMemorySnapshotPageForPeer, $p as loadObserverConfig, Dt as loadOpenCodeConfig, mp as loadOpenCodeOAuthCache, rx as loadPeerAddresses, rr as loadPrivateKey, er as loadPrivateKeyKeychain, nr as loadPublicKey, dd as loadReplicationOpsForPeer, ud as loadReplicationOpsSince, In as loadSqliteVec, Hl as lookupCoordinatorPeers, Ir as mapClaudeHookPayload, vx as mdnsAddressesForPeer, ux as mdnsEnabled, Tl as mergeAddresses, Xh as mergeSummaryMetadata, jn as migrateLegacyDbPath, tf as migrateLegacyImportKeys, Sb as negotiateSyncCapability, z_ as normalizeAdapterEvents, Cl as normalizeAddress, ha as normalizeConcept, R_ as normalizeEventsForSessionContext, Yf as normalizeObservation, Dr as normalizeProjectLabel, A_ as normalizeRequestText, xb as normalizeSyncCapability, Du as normalizeTag, $g as normalizeToolName, Y_ as parseObserverResponse, wa as parsePositiveMemoryId, Ca as parseStrictInteger, lS as parseSyncScopeRequest, Gx as peerBackoffSeconds, Ad as peerCanSyncPrivateOpByPersonalScopeGrant, Dd as personalScopeGrantStatusForPeer, _d as planReplicationOpsAgePrune, _a as populateMemoryRefs, yp as probeAvailableCredentials, a_ as projectAdapterToolEvent, yi as projectBasename, Si as projectClause, xi as projectColumnClause, Ci as projectMatchesFilter, md as pruneReplicationOps, hd as pruneReplicationOpsUntilCaughtUp, Hf as rawEventsGate, Tp as readAuthFile, Rt as readCodememConfigFile, zt as readCodememConfigFileAtPath, Rl as readCoordinatorSyncConfig, ag as readImportPayload, Pt as readWorkspaceCodememConfigFile, Fy as reassignProjectScopeInventoryProject, Ja as recencyScore, vr as recordNonce, ox as recordPeerSuccess, sd as recordReplicationOp, ax as recordSyncAttempt, dp as redactText, Cu as refreshConfiguredScopeMembershipCache, Su as refreshScopeMembershipCache, Gl as refreshStoredCoordinatorPeerAddresses, Vl as registerCoordinatorPresence, Xd as rejectInboundScopeFailures, Mp as renderObserverHeaders, Nv as replayBatchExtraction, Pv as replayBatchExtractionWithTierRouting, kd as replicationOpRequiresPersonalScopeAuthorization, kl as requestJson, zo 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, hp as resolveOAuthProvider, en as resolvePlaceholder, Ti as resolveProject, Vi as resolveProjectScope, Bf as retryRawEventFailures, Cp as runAuthCommand, Lh as runDedupKeyBackfillPass, qy as runRefBackfillPass, Zv as runScopeBackfillPass, ob as runSessionContextBackfillPass, hb as runSummaryDedupBackfillPass, $x as runSyncDaemon, zx as runSyncPass, Wb as runVectorMigrationPass, qg as sanitizePayload, Xg as sanitizeToolOutput, Jm as scanSecretsRetroactive, H as schema, a as scopeMembershipEpochStatus, Bo as search, mS as seedMixedScopeFixture, nx as selectDialAddresses, Ms as semanticSearch, as as serializeFloat32, cx as setPeerLocalActorClaim, sx as setPeerProjectFilter, nd as setReplicationCursor, Jx as setSyncDaemonError, qx as setSyncDaemonOk, Xx as setSyncDaemonPhase, qu as setSyncResetState, Kx as shouldSkipOfflinePeer, mr as signRequest, qr as startMaintenanceJob, $n as storePrivateKeyKeychain, As as storeVectors, Tt as stripJsonComments, Vg as stripPrivate, Gg as stripPrivateObj, Et as stripTrailingCommas, Zd as summarizeInboundScopeRejections, Qx as syncDaemonTick, Rx as syncOnce, Lx as syncPassPreflight, Td as syncProjectAllowedByFilters, dS as syncScopeResetRequiredPayload, Ed as syncVisibilityAllowed, X as tableExists, Wo as timeline, Z as toJson, Gn as toJsonNullable, Jr as updateMaintenanceJob, ix as updatePeerAddresses, fu as upsertCachedScopeMemberships, Mh as upsertCoordinatorGroupPreference, Iy as upsertProjectScopeSettingsMapping, ai as vacuumDatabase, ur as validateExistingKeypair, hr as verifySignature, Bt as writeCodememConfigFile, Vt as writeWorkspaceCodememConfigFile };
|
|
17918
|
+
export { ke as Api, V as BetterSqliteCoordinatorStore, Ft as CODEMEM_CONFIG_ENV_OVERRIDES, Fh as DEDUP_KEY_BACKFILL_JOB, R as DEFAULT_COORDINATOR_DB_PATH, En as DEFAULT_DB_PATH, Ql as DEFAULT_SCOPE_MEMBERSHIP_CACHE_MAX_AGE_MS, nx as DEFAULT_SERVICE_TYPE, Au as DEFAULT_SYNC_SCOPE_ID, o as DEFAULT_TIME_WINDOW_S, zh as DedupKeyBackfillRunner, si as INJECTION_EVAL_SCENARIO_PACKS, Iv as LEGACY_SHARED_REVIEW_SCOPE_ID, Ei as LOCAL_DEFAULT_SCOPE_ID, bb as LOCAL_SYNC_CAPABILITY, Qg as LOW_SIGNAL_TOOLS, Sr as MAPPABLE_CLAUDE_HOOK_EVENTS, Cn as MIN_COMPATIBLE_SCHEMA, Ae as MUTATING_TOOL_NAMES, Of as MemoryStore, Op as ObserverAuthAdapter, em as ObserverAuthError, Tm as ObserverClient, Uy as REF_BACKFILL_JOB, Og as RICH_TIER_DEFAULTS, Hy as RawEventSweeper, Yy as RefBackfillRunner, Sn as SCHEMA_VERSION, Lv as SCOPE_BACKFILL_JOB, n as SCOPE_MEMBERSHIP_REVOCATION_LIMITATION, Xy as SESSION_CONTEXT_BACKFILL_JOB, fr as SIGNATURE_VERSION, Dg as SIMPLE_TIER_DEFAULTS, ub as SUMMARY_DEDUP_BACKFILL_JOB, vb as SYNC_CAPABILITIES, yb as SYNC_CAPABILITY_HEADER, lS as SYNC_SCOPE_QUERY_PARAM, $v as ScopeBackfillRunner, lb as SessionContextBackfillRunner, _b as SummaryDedupBackfillRunner, cS as SyncRetentionRunner, E_ as TRIVIAL_REQUESTS, wb as VECTOR_MODEL_MIGRATION_JOB, gS as VERSION, Kb as VectorModelMigrationRunner, es as _resetEmbeddingClient, dS as addSyncScopeToBoundary, wl as addressDedupeKey, _x as advertiseMdns, Bm as aiBackfillStructuredContent, Ny as analyzeProjectScopeMappingChangeGuardrails, ex as applyBootstrapSnapshot, of as applyReplicationOps, zn as assertSchemaReady, cp as backfillMemoryDedupKeys, rp as backfillNarrativeFromBody, nf as backfillReplicationOps, Yv as backfillScopeIds, qf as backfillTagsText, js as backfillVectors, hn as bootstrapSchema, u_ as budgetToolEvents, _r as buildAuthHeaders, Ol as buildBaseUrl, pr as buildCanonicalRequest, Sp as buildCodexHeaders, Yi as buildFilterClauses, Xi as buildFilterClausesWithContext, Xh as buildImportKey, zr as buildIngestPayloadFromHook, $c as buildMemoryPack, tl as buildMemoryPackAsync, el as buildMemoryPackTrace, nl as buildMemoryPackTraceAsync, w_ as buildObserverPrompt, Rr as buildRawEventEnvelopeFromHook, vv as buildSessionContext, F_ as buildTranscript, gd as bulkPruneReplicationOpsByAgeCutoff, mi as canonicalMemoryKind, Mi as canonicalWorkspaceIdentity, Zu as chunkOpsBySize, Qo as chunkText, Bv as classifyLegacyMemoryScope, dv as cleanOrphanSessions, yr as cleanupNonces, ga as clearMemoryRefs, ad as clockTuple, Rf as compareMemoryRoleReports, Yr as completeMaintenanceJob, Mn as connect, Xe as connectCoordinator, Gx as consecutiveConnectivityFailures, oh as coordinatorArchiveGroupAction, ih as coordinatorCreateGroupAction, xh as coordinatorCreateInviteAction, uh as coordinatorCreateScopeAction, vh as coordinatorDisableDeviceAction, yh as coordinatorEnableDeviceAction, zl as coordinatorEnabled, hh as coordinatorEnrollDeviceAction, ph as coordinatorGrantScopeMembershipAction, Sh as coordinatorImportInviteAction, Th as coordinatorListBootstrapGrantsAction, gh as coordinatorListDevicesAction, ch as coordinatorListGroupsAction, Ch as coordinatorListJoinRequestsAction, fh as coordinatorListScopeMembershipsAction, lh as coordinatorListScopesAction, bh as coordinatorRemoveDeviceAction, _h as coordinatorRenameDeviceAction, ah as coordinatorRenameGroupAction, wh as coordinatorReviewJoinRequestAction, Eh as coordinatorRevokeBootstrapGrantAction, mh as coordinatorRevokeScopeMembershipAction, Xl as coordinatorStatusSnapshot, sh as coordinatorUnarchiveGroupAction, dh as coordinatorUpdateScopeAction, br as createBetterSqliteCoordinatorApp, c as createCoordinatorApp, Jl as createCoordinatorReciprocalApproval, Tx as cursorAdvances, ep as deactivateLowSignalMemories, $f as deactivateLowSignalObservations, zg as decideExtractionReplayTier, s as decodeInvitePayload, tp as dedupNearDuplicateMemories, Ko as dedupeOrderedIds, Dh as defaultSpaceScopeIdForGroup, Ph as deleteCoordinatorGroupPreference, Ry as deleteProjectScopeSettingsMapping, P_ as deriveRequest, ku as deriveTags, vx as discoverPeersViaMdns, rs as embedTexts, t as encodeInvitePayload, dr as ensureDeviceIdentity, Zr as ensureMaintenanceJobsSchema, yn as ensureSchemaBootstrapped, Hv as ensureScopeBackfillScopes, iu as ensureScopeMembershipCacheStateTable, Hs as estimateTokens, Tg as evaluateSessionExtractionItems, r_ as eventToToolEvent, qa as expandQuery, Xo as explain, e as explainScopeMembershipRevocation, ag as exportMemories, a_ as extractAdapterEvent, je as extractApplyPatchPaths, I_ as extractAssistantMessages, L_ as extractAssistantUsage, r as extractInvitePayload, np as extractNarrativeFromBody, _p as extractOAuthAccess, bp as extractOAuthAccountId, xp as extractOAuthExpires, R_ as extractPrompts, vp as extractProviderApiKey, id as extractReplicationOps, i_ as extractToolEvents, Xr as failMaintenanceJob, qb as fetchAllSnapshotPages, Kl as fetchCoordinatorStalePeers, Ou as fileTags, zd as filterReplicationOpsForSync, Rd as filterReplicationOpsForSyncWithStatus, ba as findByConcept, ya as findByFile, i as fingerprintPublicKey, N_ as firstSentence, bv as flushRawEvents, Un as fromJson, Wn as fromJsonStrict, sr as generateKeypair, Tu as getCachedScopeAuthorization, Lt as getCodememConfigPath, Ht as getCodememEnvOverrides, jh as getCoordinatorGroupPreference, ns as getEmbeddingClient, _g as getExtractionBenchmarkProfile, oi as getInjectionEvalScenarioByPrompt, ci as getInjectionEvalScenarioPack, li as getInjectionEvalScenarioPrompts, Q as getMaintenanceJob, Lf as getMemoryRoleReport, Wt as getOpenCodeProviderConfig, sn as getProviderApiKey, an as getProviderBaseUrl, on as getProviderHeaders, rn as getProviderOptions, ri as getRawEventRelinkPlan, ni as getRawEventRelinkReport, zf as getRawEventStatus, Vf as getReliabilityMetrics, td as getReplicationCursor, Rn as getSchemaVersion, Ts as getSemanticIndexDiagnostics, Eg as getSessionExtractionEval, wg as getSessionExtractionEvalScenario, di as getSummaryMetadata, Xx as getSyncDaemonPhase, Ku as getSyncResetState, At as getWorkspaceCodememConfigPath, jt as getWorkspaceScopedCodememConfigPath, Z_ as hasMeaningfulObservation, Ih as hasPendingDedupKeyBackfill, Gy as hasPendingRefBackfill, Kv as hasPendingScopeBackfill, ob as hasPendingSessionContextBackfill, fb as hasPendingSummaryDedupBackfill, pd as hasUnsyncedSharedMemoryChanges, Zo as hashText, hg as importMemories, lv as ingest, fv as ingestMain, ii as initDatabase, pS as initTestSchema, mS as insertTestSession, l as inviteLink, Wx as isConnectivityError, Ln as isEmbeddingDisabled, $g as isInternalMemoryTool, Xf as isLowSignalObservation, od as isNewerClock, Gg as isSensitiveFieldName, fi as isSummaryLikeMemory, M_ as isTrivialRequest, Ya as kindBonus, wu as listCachedScopesForDevice, Jt as listConfiguredOpenCodeProviders, Mh as listCoordinatorGroupPreferences, Zl as listCoordinatorJoinRequests, ql as listCoordinatorReciprocalApprovals, Gt as listCustomProviders, vg as listExtractionBenchmarkProfiles, Qd as listInboundScopeRejections, Kr as listMaintenanceJobs, Yt as listObserverProviderOptions, Py as listProjectScopeCandidates, Fy as listProjectScopeInventory, Oy as listProjectScopeSettingsMappings, Dy as listSharingDomainSettingsScopes, fd as loadMemorySnapshotPageForPeer, $p as loadObserverConfig, Dt as loadOpenCodeConfig, mp as loadOpenCodeOAuthCache, ix as loadPeerAddresses, rr as loadPrivateKey, er as loadPrivateKeyKeychain, nr as loadPublicKey, dd as loadReplicationOpsForPeer, ud as loadReplicationOpsSince, In as loadSqliteVec, Hl as lookupCoordinatorPeers, Ir as mapClaudeHookPayload, yx as mdnsAddressesForPeer, dx as mdnsEnabled, Tl as mergeAddresses, Zh as mergeSummaryMetadata, jn as migrateLegacyDbPath, tf as migrateLegacyImportKeys, Cb as negotiateSyncCapability, B_ as normalizeAdapterEvents, Cl as normalizeAddress, ha as normalizeConcept, z_ as normalizeEventsForSessionContext, Yf as normalizeObservation, Dr as normalizeProjectLabel, j_ as normalizeRequestText, Sb as normalizeSyncCapability, Du as normalizeTag, e_ as normalizeToolName, X_ as parseObserverResponse, wa as parsePositiveMemoryId, Ca as parseStrictInteger, uS as parseSyncScopeRequest, Kx as peerBackoffSeconds, Ad as peerCanSyncPrivateOpByPersonalScopeGrant, Dd as personalScopeGrantStatusForPeer, _d as planReplicationOpsAgePrune, _a as populateMemoryRefs, yp as probeAvailableCredentials, o_ as projectAdapterToolEvent, yi as projectBasename, Si as projectClause, xi as projectColumnClause, Ci as projectMatchesFilter, md as pruneReplicationOps, hd as pruneReplicationOpsUntilCaughtUp, Hf as rawEventsGate, Tp as readAuthFile, Rt as readCodememConfigFile, zt as readCodememConfigFileAtPath, Rl as readCoordinatorSyncConfig, og as readImportPayload, Pt as readWorkspaceCodememConfigFile, Iy as reassignProjectScopeInventoryProject, Ja as recencyScore, vr as recordNonce, sx as recordPeerSuccess, sd as recordReplicationOp, ox as recordSyncAttempt, dp as redactText, Cu as refreshConfiguredScopeMembershipCache, Su as refreshScopeMembershipCache, Gl as refreshStoredCoordinatorPeerAddresses, Vl as registerCoordinatorPresence, Xd as rejectInboundScopeFailures, Mp as renderObserverHeaders, Pv as replayBatchExtraction, Fv as replayBatchExtractionWithTierRouting, kd as replicationOpRequiresPersonalScopeAuthorization, kl as requestJson, zo 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, hp as resolveOAuthProvider, en as resolvePlaceholder, Ti as resolveProject, Vi as resolveProjectScope, Bf as retryRawEventFailures, Cp as runAuthCommand, Rh as runDedupKeyBackfillPass, Jy as runRefBackfillPass, Qv as runScopeBackfillPass, sb as runSessionContextBackfillPass, gb as runSummaryDedupBackfillPass, eS as runSyncDaemon, Bx as runSyncPass, Gb as runVectorMigrationPass, Jg as sanitizePayload, Zg as sanitizeToolOutput, Jm as scanSecretsRetroactive, H as schema, a as scopeMembershipEpochStatus, Bo as search, hS as seedMixedScopeFixture, rx as selectDialAddresses, Ms as semanticSearch, as as serializeFloat32, lx as setPeerLocalActorClaim, cx as setPeerProjectFilter, nd as setReplicationCursor, Yx as setSyncDaemonError, Jx as setSyncDaemonOk, Zx as setSyncDaemonPhase, qu as setSyncResetState, qx as shouldSkipOfflinePeer, mr as signRequest, qr as startMaintenanceJob, $n as storePrivateKeyKeychain, As as storeVectors, Tt as stripJsonComments, Hg as stripPrivate, Kg as stripPrivateObj, Et as stripTrailingCommas, Zd as summarizeInboundScopeRejections, $x as syncDaemonTick, zx as syncOnce, Rx as syncPassPreflight, Td as syncProjectAllowedByFilters, fS as syncScopeResetRequiredPayload, Ed as syncVisibilityAllowed, X as tableExists, Wo as timeline, Z as toJson, Gn as toJsonNullable, Jr as updateMaintenanceJob, ax as updatePeerAddresses, fu as upsertCachedScopeMemberships, Nh as upsertCoordinatorGroupPreference, Ly as upsertProjectScopeSettingsMapping, ai as vacuumDatabase, ur as validateExistingKeypair, hr as verifySignature, Bt as writeCodememConfigFile, Vt as writeWorkspaceCodememConfigFile };
|
|
17898
17919
|
|
|
17899
17920
|
//# sourceMappingURL=index.js.map
|