@retaw106/mmc-pi 2.3.0 → 2.4.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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  withSqliteBackgroundWriter,
3
3
  withoutSqliteTransformPass
4
- } from "./index-3qawqvws.js";
4
+ } from "./index-cr4hzd76.js";
5
5
  import"./index-83p1tc98.js";
6
6
  import {
7
7
  logSlowWriteTransaction
@@ -24,8 +24,8 @@ import {
24
24
  getRawSessionTagKeysThrough2,
25
25
  getLegacyProtectedTailStartOrdinal2,
26
26
  readSessionChunk2
27
- } from "./index-f7z4jc1f.js";
28
- import"./index-3qawqvws.js";
27
+ } from "./index-zmx631ey.js";
28
+ import"./index-cr4hzd76.js";
29
29
  import"./index-83p1tc98.js";
30
30
  export {
31
31
  cleanUserText2 as cleanUserText,
package/dist/web/main.js CHANGED
@@ -446,7 +446,10 @@ var init_logger = __esm(() => {
446
446
  });
447
447
 
448
448
  // ../plugin/src/shared/sqlite.ts
449
- import { AsyncLocalStorage } from "node:async_hooks";
449
+ import { AsyncLocalStorage, AsyncResource } from "node:async_hooks";
450
+ function inRootAsyncContext(operation) {
451
+ return resourceRoot.runInAsyncScope(operation);
452
+ }
450
453
  function registerSlowWriteReporter(reporter) {
451
454
  reportSlowPrivilegedWrite = reporter;
452
455
  }
@@ -597,7 +600,7 @@ function installTransactionRouting(db, readonly) {
597
600
  return endWriterTransaction(db, () => nativeExec(sql), sql);
598
601
  if (!/^\s*(?:SELECT|EXPLAIN|PRAGMA|COMMIT|END|ROLLBACK|SAVEPOINT|RELEASE)\b/i.test(sql)) {
599
602
  try {
600
- return withAutocommitTimeout(db, () => nativeExec(sql));
603
+ return withAutocommitTimeout(db, () => nativeExec(sql), false);
601
604
  } finally {
602
605
  if (mayChangeTagIdentity(sql))
603
606
  tagIdentityWriteGeneration += 1;
@@ -839,29 +842,48 @@ function foregroundWaitLease() {
839
842
  const lease = transformPassScope.getStore();
840
843
  return lease?.active && !admissionScope.getStore() && !backgroundWriterScope.getStore() ? lease : undefined;
841
844
  }
842
- function withAutocommitTimeout(db, operation) {
845
+ function withAutocommitTimeout(db, operation, singleStatement = true) {
843
846
  assertTransformWrite();
844
847
  const lease = foregroundWaitLease();
845
848
  if (isInTransaction(db))
846
849
  return operation();
847
850
  const scoped = lease || backgroundWriterScope.getStore();
848
851
  const previous = scoped ? pragmaNumber(db, "busy_timeout") : null;
849
- if (scoped)
850
- db.exec(`PRAGMA busy_timeout=${lease ? Math.floor(Math.min(lease.remainingWaitMs, lease.guard?.remainingMs() ?? Infinity)) : SHORT_BUSY_TIMEOUT_MS}`);
851
852
  const started = performance.now();
852
853
  let completed = false;
853
- try {
854
+ const execute = () => {
854
855
  const result = operation();
855
856
  completed = true;
856
857
  return result;
858
+ };
859
+ try {
860
+ if (!scoped)
861
+ return execute();
862
+ if (singleStatement) {
863
+ db.exec("PRAGMA busy_timeout=0");
864
+ try {
865
+ return execute();
866
+ } catch (error) {
867
+ if (!isTransientSqliteError(error) || isInTransaction(db))
868
+ throw error;
869
+ }
870
+ assertTransformWrite();
871
+ }
872
+ const timeout = Math.floor(Math.min(lease?.remainingWaitMs ?? SHORT_BUSY_TIMEOUT_MS, lease?.guard?.remainingMs() ?? Infinity));
873
+ db.exec(`PRAGMA busy_timeout=${timeout}`);
874
+ const waitStarted = performance.now();
875
+ try {
876
+ return execute();
877
+ } finally {
878
+ if (lease)
879
+ lease.remainingWaitMs = Math.max(0, lease.remainingWaitMs - (performance.now() - waitStarted));
880
+ }
857
881
  } catch (error) {
858
882
  if (lease && isTransientSqliteError(error))
859
883
  throw new SqliteAcquisitionBusyError(error, "autocommit");
860
884
  throw error;
861
885
  } finally {
862
886
  const elapsed = performance.now() - started;
863
- if (lease)
864
- lease.remainingWaitMs = Math.max(0, lease.remainingWaitMs - elapsed);
865
887
  if (previous !== null)
866
888
  db.exec(`PRAGMA busy_timeout=${previous}`);
867
889
  if (elapsed >= SLOW_WRITER_LOG_MS)
@@ -935,8 +957,9 @@ function isInTransaction(db) {
935
957
  const candidate = db;
936
958
  return candidate.inTransaction === true || candidate.isTransaction === true;
937
959
  }
938
- var reportSlowPrivilegedWrite, sqliteDiagnosticSink, sqliteDiagnosticHost = () => "unknown", bunSpec, nodeSpec, SqliteRuntimeUnavailableError, detectedRuntime, isBun, sqliteModule, DatabaseImpl, trackedSqliteConnections, nextSqliteConnectionSequence = 1, TAG_COLUMNS_OUTSIDE_IDENTITY, tagIdentityWriteGeneration = 0, TrackedDatabase, Database, statementOwners, FIRST_PRUNE_AT = 256, privilegeDepth, transformPassScope, admissionScope, backgroundWriterScope, SqliteAcquisitionBusyError, SHORT_BUSY_TIMEOUT_MS = 25, SLOW_WRITER_LOG_MS = 100, WRITER_TRANSACTION_END, writerAcquisitionScope, openWriterTransactions, indexCoordinationKey, indexCoordinationHeap, indexCoordinationBuffer, indexCoordinationState;
960
+ var resourceRoot, reportSlowPrivilegedWrite, sqliteDiagnosticSink, sqliteDiagnosticHost = () => "unknown", bunSpec, nodeSpec, SqliteRuntimeUnavailableError, detectedRuntime, isBun, sqliteModule, DatabaseImpl, trackedSqliteConnections, nextSqliteConnectionSequence = 1, TAG_COLUMNS_OUTSIDE_IDENTITY, tagIdentityWriteGeneration = 0, TrackedDatabase, Database, statementOwners, FIRST_PRUNE_AT = 256, privilegeDepth, transformPassScope, admissionScope, backgroundWriterScope, SqliteAcquisitionBusyError, SHORT_BUSY_TIMEOUT_MS = 25, SLOW_WRITER_LOG_MS = 100, WRITER_TRANSACTION_END, writerAcquisitionScope, openWriterTransactions, indexCoordinationKey, indexCoordinationHeap, indexCoordinationBuffer, indexCoordinationState;
939
961
  var init_sqlite = __esm(async () => {
962
+ resourceRoot = new AsyncResource("magic-context:root");
940
963
  bunSpec = "bun:" + "sqlite";
941
964
  nodeSpec = "node:" + "sqlite";
942
965
  SqliteRuntimeUnavailableError = class SqliteRuntimeUnavailableError extends Error {
@@ -970,7 +993,7 @@ var init_sqlite = __esm(async () => {
970
993
  ]);
971
994
  TrackedDatabase = new Proxy(DatabaseImpl, {
972
995
  construct(target, args) {
973
- const db = Reflect.construct(target, args, target);
996
+ const db = inRootAsyncContext(() => Reflect.construct(target, args, target));
974
997
  return trackSqliteConnection(db, args[0], args[1]);
975
998
  }
976
999
  });
@@ -5150,6 +5173,7 @@ var AGENT_STEP_CAPS = {
5150
5173
  [MEMORY_MAINTAINER_A_AGENT]: MEMORY_MAINTAINER_A_STEP_CAP,
5151
5174
  [HIDDEN_HISTORIAN_AGENT]: HISTORIAN_STEP_CAP
5152
5175
  };
5176
+ var DISPOSED_CHILDREN_KEY = Symbol.for("magic-context.v2.disposed-hidden-children");
5153
5177
 
5154
5178
  // ../plugin/src/v2/hidden-child-record.ts
5155
5179
  var HIDDEN_CHILD_ROLE_TITLES = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retaw106/mmc-pi",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
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",