@retaw106/mmc-pi 2.5.0 → 2.7.1

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.
@@ -24,7 +24,7 @@ import {
24
24
  getRawSessionTagKeysThrough2,
25
25
  getLegacyProtectedTailStartOrdinal2,
26
26
  readSessionChunk2
27
- } from "./index-t2aaz8cn.js";
27
+ } from "./index-07rh0nr2.js";
28
28
  import"./index-vhs0y3s0.js";
29
29
  import"./index-83p1tc98.js";
30
30
  export {
package/dist/web/main.js CHANGED
@@ -1359,12 +1359,58 @@ var init_read_session_formatting = __esm(() => {
1359
1359
  promptTokenCounts = new Map;
1360
1360
  PROMPT_TOKEN_COUNT_BYTES = 8 * 1024 * 1024;
1361
1361
  });
1362
+
1363
+ // ../plugin/src/shared/bounded-session-map.ts
1364
+ class BoundedSessionMap {
1365
+ maxEntries;
1366
+ store = new Map;
1367
+ constructor(maxEntries) {
1368
+ if (!Number.isFinite(maxEntries) || maxEntries < 1) {
1369
+ throw new Error(`BoundedSessionMap: maxEntries must be >= 1, got ${maxEntries}`);
1370
+ }
1371
+ this.maxEntries = maxEntries;
1372
+ }
1373
+ get(sessionId) {
1374
+ const value = this.store.get(sessionId);
1375
+ if (value === undefined)
1376
+ return;
1377
+ this.store.delete(sessionId);
1378
+ this.store.set(sessionId, value);
1379
+ return value;
1380
+ }
1381
+ peek(sessionId) {
1382
+ return this.store.get(sessionId);
1383
+ }
1384
+ has(sessionId) {
1385
+ return this.store.has(sessionId);
1386
+ }
1387
+ set(sessionId, value) {
1388
+ if (this.store.has(sessionId)) {
1389
+ this.store.delete(sessionId);
1390
+ } else if (this.store.size >= this.maxEntries) {
1391
+ const oldest = this.store.keys().next().value;
1392
+ if (oldest !== undefined)
1393
+ this.store.delete(oldest);
1394
+ }
1395
+ this.store.set(sessionId, value);
1396
+ }
1397
+ delete(sessionId) {
1398
+ return this.store.delete(sessionId);
1399
+ }
1400
+ clear() {
1401
+ this.store.clear();
1402
+ }
1403
+ get size() {
1404
+ return this.store.size;
1405
+ }
1406
+ }
1362
1407
  // ../plugin/src/features/magic-context/tool-definition-tokens.ts
1363
- var measurements, fingerprints;
1408
+ var ACTIVITY_WINDOW_MS, routes, sessionFlights;
1364
1409
  var init_tool_definition_tokens = __esm(() => {
1365
1410
  init_read_session_formatting();
1366
- measurements = new Map;
1367
- fingerprints = new Map;
1411
+ ACTIVITY_WINDOW_MS = 10 * 60000;
1412
+ routes = new Map;
1413
+ sessionFlights = new BoundedSessionMap(1000);
1368
1414
  });
1369
1415
 
1370
1416
  // ../plugin/src/shared/opencode-db-path.ts
@@ -4614,9 +4660,10 @@ function closeConnection(connection) {
4614
4660
  counters.readersClosed += 1;
4615
4661
  }
4616
4662
  }
4617
- function messageTimesQuery(count) {
4663
+ function messageTimesQuery(count, withVersions = false) {
4618
4664
  return `SELECT id, COALESCE(time_created, json_extract(data, '$.time.created')) AS created,
4619
4665
  json_extract(data, '$.time.completed') AS completed
4666
+ ${withVersions ? ", type, seq, time_created AS version_created, time_updated AS version_updated" : ""}
4620
4667
  FROM session_message WHERE +session_id = ? AND id IN (${Array.from({ length: count }, () => "?").join(",")})`;
4621
4668
  }
4622
4669
 
@@ -4736,9 +4783,6 @@ class V2StoreReader {
4736
4783
  return null;
4737
4784
  return typeof row.parent_id === "string" && row.parent_id.length > 0;
4738
4785
  }
4739
- sessionIds() {
4740
- return this.prepare("SELECT id FROM session_v2").all().map((row) => row.id);
4741
- }
4742
4786
  storedRowsAfter(sessionID, after) {
4743
4787
  const row = this.prepare("SELECT COUNT(*) AS count FROM session_message WHERE session_id = ? AND seq > ?").get(sessionID, after);
4744
4788
  return row.count;
@@ -4757,16 +4801,46 @@ class V2StoreReader {
4757
4801
  return row ? decode(row) : null;
4758
4802
  });
4759
4803
  }
4760
- messageTimes(sessionID, ids) {
4761
- const times = new Map;
4804
+ messageTimeVersions(sessionID, ids, span) {
4805
+ const versions = new Map;
4806
+ if (ids.length > 0 && span && span.last - span.first < ids.length * 2) {
4807
+ const wanted = new Set(ids);
4808
+ const rows = this.prepare(`SELECT id, type, seq, time_created AS created, time_updated AS updated
4809
+ FROM session_message WHERE session_id = ? AND seq >= ? AND seq <= ?`).all(sessionID, span.first, span.last);
4810
+ for (const row of rows)
4811
+ if (wanted.has(row.id))
4812
+ versions.set(row.id, row);
4813
+ for (const [id, version] of this.messageTimeVersions(sessionID, ids.filter((id) => !versions.has(id))))
4814
+ versions.set(id, version);
4815
+ return versions;
4816
+ }
4762
4817
  for (let offset = 0;offset < ids.length; offset += 500) {
4763
4818
  const batch = ids.slice(offset, offset + 500);
4764
- const rows = this.prepare(messageTimesQuery(batch.length)).all(sessionID, ...batch);
4819
+ const rows = this.prepare(`SELECT id, type, seq, time_created AS created, time_updated AS updated
4820
+ FROM session_message WHERE +session_id = ? AND id IN (${batch.map(() => "?").join(",")})`).all(sessionID, ...batch);
4765
4821
  for (const row of rows)
4822
+ versions.set(row.id, row);
4823
+ }
4824
+ return versions;
4825
+ }
4826
+ messageTimes(sessionID, ids, versions) {
4827
+ const times = new Map;
4828
+ for (let offset = 0;offset < ids.length; offset += 500) {
4829
+ const batch = ids.slice(offset, offset + 500);
4830
+ const rows = this.prepare(messageTimesQuery(batch.length, versions !== undefined)).all(sessionID, ...batch);
4831
+ for (const row of rows) {
4766
4832
  times.set(row.id, {
4767
4833
  created: typeof row.created === "number" ? row.created : undefined,
4768
4834
  completed: typeof row.completed === "number" ? row.completed : undefined
4769
4835
  });
4836
+ versions?.set(row.id, {
4837
+ id: row.id,
4838
+ type: row.type,
4839
+ seq: row.seq,
4840
+ created: row.version_created,
4841
+ updated: row.version_updated
4842
+ });
4843
+ }
4770
4844
  }
4771
4845
  return times;
4772
4846
  }
@@ -5643,7 +5717,7 @@ function projectRawMessages(rows, ordinalFor) {
5643
5717
  const message = {
5644
5718
  id: row.id,
5645
5719
  ordinal: ordinalFor(row, index),
5646
- role: row.type === "assistant" ? "assistant" : "user",
5720
+ role: row.type === "assistant" ? "assistant" : row.type === "system" ? "system" : "user",
5647
5721
  createdAt: row.time_created ?? row.data.time?.created,
5648
5722
  parts: row.type === "assistant" ? (row.data.content ?? []).map((part) => {
5649
5723
  if (part.type !== "tool")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retaw106/mmc-pi",
3
- "version": "2.5.0",
3
+ "version": "2.7.1",
4
4
  "type": "module",
5
5
  "description": "Pi and OMP coding agent extension for Magic Context — cross-session memory and context management",
6
6
  "main": "dist/index.js",