@myrialabs/clopen 0.4.48 → 0.4.50

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.
Files changed (114) hide show
  1. package/backend/chat/background-wait.test.ts +28 -0
  2. package/backend/chat/message-pages.test.ts +180 -0
  3. package/backend/chat/message-pages.ts +237 -0
  4. package/backend/chat/stream-manager.ts +101 -18
  5. package/backend/database/migrations/087_create_blob_line_stats.ts +37 -0
  6. package/backend/database/migrations/088_create_messages_fts_map.ts +52 -0
  7. package/backend/database/migrations/089_add_memory_layout_tiles.ts +58 -0
  8. package/backend/database/migrations/index.ts +21 -0
  9. package/backend/database/queries/blob-line-stats-queries.ts +48 -0
  10. package/backend/database/queries/graph-queries.ts +392 -135
  11. package/backend/database/queries/index.ts +2 -0
  12. package/backend/database/queries/message-fts.test.ts +120 -0
  13. package/backend/database/queries/message-queries.ts +45 -9
  14. package/backend/database/queries/session-queries.ts +3 -2
  15. package/backend/database/queries/utils-queries.ts +3 -0
  16. package/backend/db-client/env/diff.ts +9 -33
  17. package/backend/db-client/env/env.test.ts +8 -8
  18. package/backend/db-client/env/service.ts +1 -1
  19. package/backend/engine/adapters/claude/environment.ts +4 -0
  20. package/backend/engine/adapters/claude/input-gate.test.ts +59 -0
  21. package/backend/engine/adapters/claude/input-gate.ts +74 -0
  22. package/backend/engine/adapters/claude/message-converter.test.ts +16 -0
  23. package/backend/engine/adapters/claude/message-converter.ts +8 -0
  24. package/backend/engine/adapters/claude/stream.ts +15 -0
  25. package/backend/files/file-watcher.ts +19 -0
  26. package/backend/git/contributors.test.ts +35 -0
  27. package/backend/git/contributors.ts +46 -0
  28. package/backend/git/identity/scope-config.test.ts +7 -4
  29. package/backend/http/static-assets.test.ts +78 -0
  30. package/backend/http/static-assets.ts +104 -0
  31. package/backend/index.ts +46 -17
  32. package/backend/memory/README.md +7 -4
  33. package/backend/memory/layout.test.ts +377 -0
  34. package/backend/memory/layout.ts +1029 -265
  35. package/backend/memory/view.ts +257 -386
  36. package/backend/preview/browser/browser-preview-service.ts +24 -6
  37. package/backend/project/status-manager.ts +4 -2
  38. package/backend/snapshot/blob-store.ts +9 -1
  39. package/backend/snapshot/helpers.ts +3 -10
  40. package/backend/snapshot/line-stats.test.ts +80 -0
  41. package/backend/snapshot/line-stats.ts +64 -0
  42. package/backend/snapshot/snapshot-service.ts +14 -27
  43. package/backend/snapshot/turn-changes.test.ts +10 -5
  44. package/backend/snapshot/turn-changes.ts +78 -40
  45. package/backend/terminal/ptykit.ts +6 -1
  46. package/backend/utils/ws-wire.test.ts +87 -0
  47. package/backend/utils/ws-wire.ts +189 -0
  48. package/backend/utils/ws.ts +40 -38
  49. package/backend/ws/chat/stream.ts +60 -20
  50. package/backend/ws/files/read.ts +30 -0
  51. package/backend/ws/git/log.ts +52 -0
  52. package/backend/ws/memory/crud.ts +118 -81
  53. package/backend/ws/messages/crud.ts +51 -0
  54. package/backend/ws/preview/index.ts +2 -0
  55. package/backend/ws/preview/watchers.ts +84 -0
  56. package/backend/ws/sessions/crud.ts +8 -12
  57. package/backend/ws/snapshot/changes.ts +5 -6
  58. package/backend/ws/terminal/tunnel.ts +2 -2
  59. package/bin/clopen.ts +37 -30
  60. package/dist/assets/addon-clipboard-wHJhZAA4.js.br +0 -0
  61. package/dist/assets/addon-clipboard-wHJhZAA4.js.gz +0 -0
  62. package/dist/assets/addon-fit-DX4qG4td.js.br +1 -0
  63. package/dist/assets/addon-fit-DX4qG4td.js.gz +0 -0
  64. package/dist/assets/addon-ligatures-DpDY8N_X.js.br +0 -0
  65. package/dist/assets/addon-ligatures-DpDY8N_X.js.gz +0 -0
  66. package/dist/assets/addon-unicode11-Bt8F3D7-.js.br +0 -0
  67. package/dist/assets/addon-unicode11-Bt8F3D7-.js.gz +0 -0
  68. package/dist/assets/addon-web-links-DIbG5aQx.js.br +0 -0
  69. package/dist/assets/addon-web-links-DIbG5aQx.js.gz +0 -0
  70. package/dist/assets/diff.worker-BoHLxmr2.js +7 -0
  71. package/dist/assets/diff.worker-BoHLxmr2.js.br +0 -0
  72. package/dist/assets/diff.worker-BoHLxmr2.js.gz +0 -0
  73. package/dist/assets/{index-DJzwt-hq.js → index-By6KdSLT.js} +1 -1
  74. package/dist/assets/index-By6KdSLT.js.br +0 -0
  75. package/dist/assets/index-By6KdSLT.js.gz +0 -0
  76. package/dist/assets/{index-CONlwAXZ.js → index-DV4TiDn1.js} +1 -1
  77. package/dist/assets/index-DV4TiDn1.js.br +0 -0
  78. package/dist/assets/index-DV4TiDn1.js.gz +0 -0
  79. package/dist/assets/main-DIESTGTD.css +1 -0
  80. package/dist/assets/main-DIESTGTD.css.br +0 -0
  81. package/dist/assets/main-DIESTGTD.css.gz +0 -0
  82. package/dist/assets/{main-nBOb9YOA.js → main-Da3JKoua.js} +623 -623
  83. package/dist/assets/main-Da3JKoua.js.br +0 -0
  84. package/dist/assets/main-Da3JKoua.js.gz +0 -0
  85. package/dist/assets/preview-video.worker-DcpDhCWL.js.br +0 -0
  86. package/dist/assets/preview-video.worker-DcpDhCWL.js.gz +0 -0
  87. package/dist/assets/xterm-B-qIQCd3.js.br +0 -0
  88. package/dist/assets/xterm-B-qIQCd3.js.gz +0 -0
  89. package/dist/assets/zipkit-engine-CaR0t_Uy.wasm.br +0 -0
  90. package/dist/assets/zipkit-engine-CaR0t_Uy.wasm.gz +0 -0
  91. package/dist/fonts/dm-sans.css.br +0 -0
  92. package/dist/fonts/dm-sans.css.gz +0 -0
  93. package/dist/index.html +2 -2
  94. package/dist/index.html.br +0 -0
  95. package/dist/index.html.gz +0 -0
  96. package/dist/sw.js.br +0 -0
  97. package/dist/sw.js.gz +0 -0
  98. package/package.json +3 -4
  99. package/shared/types/memory.ts +96 -73
  100. package/shared/types/unified/index.ts +1 -0
  101. package/shared/types/unified/stream.ts +33 -2
  102. package/shared/utils/diff-calculator.test.ts +178 -41
  103. package/shared/utils/diff-calculator.ts +383 -100
  104. package/shared/utils/process-supervisor.test.ts +242 -0
  105. package/shared/utils/process-supervisor.ts +356 -0
  106. package/shared/utils/process-tree.ts +99 -0
  107. package/shared/utils/ws-chunk.test.ts +33 -0
  108. package/shared/utils/ws-chunk.ts +73 -0
  109. package/shared/utils/ws-client-chunks.test.ts +45 -0
  110. package/shared/utils/ws-client.ts +43 -0
  111. package/shared/utils/ws-server.ts +17 -14
  112. package/backend/database/migrations/086_single_owner.test.ts +0 -170
  113. package/dist/assets/graph-layout.worker-CRFqN7ZQ.js +0 -1
  114. package/dist/assets/main-BUiUL3eZ.css +0 -1
@@ -0,0 +1,37 @@
1
+ import type { DatabaseConnection } from '$shared/types/database/connection';
2
+ import { debug } from '$shared/utils/logger';
3
+
4
+ export const description = 'Create blob_line_stats to count each pair of file versions once';
5
+
6
+ /**
7
+ * The +/- line counts of one pair of snapshot blobs.
8
+ *
9
+ * Blobs are content-addressed (sha256), so the count for a given
10
+ * (old_hash, new_hash) can never change — it is computed the first time any
11
+ * surface asks and read from here ever after. Every chat open used to re-diff
12
+ * every changed file of every turn, twice; on a chat that touched a large
13
+ * generated file that recomputation alone could block the server for minutes.
14
+ *
15
+ * An empty hash is a side that does not exist (a created or deleted file).
16
+ * Rows are pruned together with the blobs they describe.
17
+ */
18
+ export const up = (db: DatabaseConnection): void => {
19
+ debug.log('migration', '📋 Creating blob_line_stats table...');
20
+ db.exec(`
21
+ CREATE TABLE IF NOT EXISTS blob_line_stats (
22
+ old_hash TEXT NOT NULL,
23
+ new_hash TEXT NOT NULL,
24
+ insertions INTEGER NOT NULL,
25
+ deletions INTEGER NOT NULL,
26
+ is_binary INTEGER NOT NULL DEFAULT 0,
27
+ PRIMARY KEY (old_hash, new_hash)
28
+ ) WITHOUT ROWID
29
+ `);
30
+ db.exec('CREATE INDEX IF NOT EXISTS idx_blob_line_stats_new_hash ON blob_line_stats (new_hash)');
31
+ debug.log('migration', '✅ blob_line_stats table created');
32
+ };
33
+
34
+ export const down = (db: DatabaseConnection): void => {
35
+ db.exec('DROP INDEX IF EXISTS idx_blob_line_stats_new_hash');
36
+ db.exec('DROP TABLE IF EXISTS blob_line_stats');
37
+ };
@@ -0,0 +1,52 @@
1
+ import type { DatabaseConnection } from '$shared/types/database/connection';
2
+ import { debug } from '$shared/utils/logger';
3
+
4
+ export const description = 'Map each message to its messages_fts row so saves stop scanning the whole index';
5
+
6
+ /**
7
+ * Which `messages_fts` row holds a message's text.
8
+ *
9
+ * `messages_fts.message_id` is an UNINDEXED FTS5 column: FTS5 cannot look a
10
+ * row up by it, so `DELETE FROM messages_fts WHERE message_id = ?` walked the
11
+ * entire index. Every message save ran that delete first, on the server's only
12
+ * thread — measured on a 4 GB database (165k indexed messages) at up to 1.8 s
13
+ * per save, 3–5 saves per turn, which stalled every panel, terminal and preview
14
+ * request while any chat was streaming. Deleting by `rowid` is a direct lookup.
15
+ *
16
+ * A separate narrow table rather than a column on `messages`: adding a column
17
+ * to `messages` and filling it rewrites every row, which on the same database
18
+ * took 31 s at startup; filling this table takes under 2 s. `session_id` is
19
+ * kept here so a whole session's or project's rows can be found without
20
+ * depending on the order `messages` rows are deleted in.
21
+ */
22
+ export const up = (db: DatabaseConnection): void => {
23
+ debug.log('migration', '📋 Creating messages_fts_map...');
24
+ db.exec(`
25
+ CREATE TABLE IF NOT EXISTS messages_fts_map (
26
+ message_id TEXT PRIMARY KEY,
27
+ session_id TEXT NOT NULL,
28
+ fts_rowid INTEGER NOT NULL
29
+ ) WITHOUT ROWID
30
+ `);
31
+ db.exec('CREATE INDEX IF NOT EXISTS idx_messages_fts_map_session ON messages_fts_map (session_id)');
32
+
33
+ // One pass over the index. If a message somehow has more than one row, the
34
+ // newest (highest rowid) wins and the others are dropped below.
35
+ db.exec(`
36
+ INSERT OR REPLACE INTO messages_fts_map (message_id, session_id, fts_rowid)
37
+ SELECT message_id, session_id, rowid FROM messages_fts ORDER BY rowid
38
+ `);
39
+
40
+ // Rows the map does not point at (duplicates), and rows whose message no
41
+ // longer exists, were never reachable by a delete before; drop them now.
42
+ db.exec('DELETE FROM messages_fts_map WHERE message_id NOT IN (SELECT id FROM messages)');
43
+ db.exec('DELETE FROM messages_fts WHERE rowid NOT IN (SELECT fts_rowid FROM messages_fts_map)');
44
+
45
+ const { count } = db.prepare('SELECT COUNT(*) AS count FROM messages_fts_map').get() as { count: number };
46
+ debug.log('migration', `✅ messages_fts_map created for ${count} messages`);
47
+ };
48
+
49
+ export const down = (db: DatabaseConnection): void => {
50
+ db.exec('DROP INDEX IF EXISTS idx_messages_fts_map_session');
51
+ db.exec('DROP TABLE IF EXISTS messages_fts_map');
52
+ };
@@ -0,0 +1,58 @@
1
+ import type { DatabaseConnection } from '$shared/types/database/connection';
2
+ import { debug } from '$shared/utils/logger';
3
+
4
+ export const description =
5
+ 'Persist memory-graph node degree and derived edges so the view can be served as tiles';
6
+
7
+ /**
8
+ * What a tiled Memory view needs from the arrangement and could not get.
9
+ *
10
+ * The view no longer asks for "the graph"; it asks for the rectangles of it that
11
+ * are on screen, at the resolution the camera is at. Two things a tile has to
12
+ * carry were only ever computed for a whole fetch:
13
+ *
14
+ * - DEGREE sizes a node. It was counted over whatever was drawn, which for a
15
+ * tile is a meaningless slice — the same memory would change size as the
16
+ * tiles around it loaded. The layout pass already builds the full graph, so
17
+ * it writes each node's degree alongside its position.
18
+ *
19
+ * - DERIVED EDGES (two memories naming the same subject or file) are most of
20
+ * the structure the episodic half has. They were derived at read time from
21
+ * the set being drawn, which is unbounded for the whole store and wrong for a
22
+ * tile: an edge whose other end sits in the next tile was never derived at
23
+ * all. The layout pass derives them over every live node anyway — it lays out
24
+ * on them — so it now keeps them. Stored edges stay in `graph_edges` and are
25
+ * read from there, so a connection a model records shows up without waiting
26
+ * for a pass.
27
+ *
28
+ * Both are derived and disposable like the rest of `graph_layout`: deleting them
29
+ * costs one background pass and no memory.
30
+ */
31
+ export const up = (db: DatabaseConnection): void => {
32
+ debug.log('migration', 'Adding memory layout degree and derived edges...');
33
+
34
+ const columns = db.prepare(`PRAGMA table_info(graph_layout)`).all() as { name: string }[];
35
+ if (!columns.some(column => column.name === 'degree')) {
36
+ db.exec(`ALTER TABLE graph_layout ADD COLUMN degree INTEGER NOT NULL DEFAULT 0`);
37
+ }
38
+
39
+ // Stored once per pair, smaller id first, so "edges touching this node" is the
40
+ // union of a lookup on each column — the same shape `graph_edges` is read in.
41
+ db.exec(`
42
+ CREATE TABLE IF NOT EXISTS graph_layout_edges (
43
+ src_id TEXT NOT NULL REFERENCES graph_nodes(id) ON DELETE CASCADE,
44
+ dst_id TEXT NOT NULL REFERENCES graph_nodes(id) ON DELETE CASCADE,
45
+ weight REAL NOT NULL DEFAULT 1,
46
+ PRIMARY KEY (src_id, dst_id)
47
+ ) WITHOUT ROWID
48
+ `);
49
+ db.exec(`CREATE INDEX IF NOT EXISTS idx_graph_layout_edges_dst ON graph_layout_edges (dst_id)`);
50
+
51
+ debug.log('migration', 'Memory layout tiles ready');
52
+ };
53
+
54
+ export const down = (db: DatabaseConnection): void => {
55
+ db.exec(`DROP INDEX IF EXISTS idx_graph_layout_edges_dst`);
56
+ db.exec(`DROP TABLE IF EXISTS graph_layout_edges`);
57
+ db.exec(`ALTER TABLE graph_layout DROP COLUMN degree`);
58
+ };
@@ -85,6 +85,9 @@ import * as migration083 from './083_create_project_mcp_trust';
85
85
  import * as migration084 from './084_create_channel_links';
86
86
  import * as migration085 from './085_add_home_projects';
87
87
  import * as migration086 from './086_single_owner';
88
+ import * as migration087 from './087_create_blob_line_stats';
89
+ import * as migration088 from './088_create_messages_fts_map';
90
+ import * as migration089 from './089_add_memory_layout_tiles';
88
91
 
89
92
  // Export all migrations in order
90
93
  export const migrations = [
@@ -603,6 +606,24 @@ export const migrations = [
603
606
  description: migration086.description,
604
607
  up: migration086.up,
605
608
  down: migration086.down
609
+ },
610
+ {
611
+ id: '087',
612
+ description: migration087.description,
613
+ up: migration087.up,
614
+ down: migration087.down
615
+ },
616
+ {
617
+ id: '088',
618
+ description: migration088.description,
619
+ up: migration088.up,
620
+ down: migration088.down
621
+ },
622
+ {
623
+ id: '089',
624
+ description: migration089.description,
625
+ up: migration089.up,
626
+ down: migration089.down
606
627
  }
607
628
  ];
608
629
 
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Cached +/- line counts per pair of snapshot blobs (see migration 087).
3
+ *
4
+ * Keyed by content hashes, so a row is true forever: the only writes are the
5
+ * first computation of a pair and the prune that follows its blobs out.
6
+ */
7
+
8
+ import { getDatabase } from '../index';
9
+
10
+ export interface BlobLineStatsRow {
11
+ insertions: number;
12
+ deletions: number;
13
+ isBinary: boolean;
14
+ }
15
+
16
+ export const blobLineStatsQueries = {
17
+ get(oldHash: string, newHash: string): BlobLineStatsRow | null {
18
+ const row = getDatabase()
19
+ .prepare('SELECT insertions, deletions, is_binary FROM blob_line_stats WHERE old_hash = ? AND new_hash = ?')
20
+ .get(oldHash, newHash) as { insertions: number; deletions: number; is_binary: number } | null;
21
+ return row ? { insertions: row.insertions, deletions: row.deletions, isBinary: row.is_binary === 1 } : null;
22
+ },
23
+
24
+ save(oldHash: string, newHash: string, stats: BlobLineStatsRow): void {
25
+ getDatabase()
26
+ .prepare(`
27
+ INSERT OR IGNORE INTO blob_line_stats (old_hash, new_hash, insertions, deletions, is_binary)
28
+ VALUES (?, ?, ?, ?, ?)
29
+ `)
30
+ .run(oldHash, newHash, stats.insertions, stats.deletions, stats.isBinary ? 1 : 0);
31
+ },
32
+
33
+ /** Drop every pair that names one of these blobs — they are gone from the store. */
34
+ deleteByHashes(hashes: string[]): void {
35
+ const db = getDatabase();
36
+ const byOld = db.prepare('DELETE FROM blob_line_stats WHERE old_hash = ?');
37
+ const byNew = db.prepare('DELETE FROM blob_line_stats WHERE new_hash = ?');
38
+ const prune = () => {
39
+ for (const hash of hashes) {
40
+ if (!hash) continue;
41
+ byOld.run(hash);
42
+ byNew.run(hash);
43
+ }
44
+ };
45
+ if (db.transaction) db.transaction(prune)();
46
+ else prune();
47
+ }
48
+ };