@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.
package/dist/cli.js CHANGED
@@ -4981,6 +4981,15 @@ var HistorianModelEntryObjectSchema = object({
4981
4981
  thinking_level: PiThinkingLevelSchema.describe("Pi thinking level for this entry.")
4982
4982
  }).strict();
4983
4983
  var HistorianModelEntrySchema = union([string2(), HistorianModelEntryObjectSchema]);
4984
+ var MaintenanceModelEntrySchema = HistorianModelEntrySchema.superRefine((entry, ctx) => {
4985
+ const model = typeof entry === "string" ? entry : entry.model;
4986
+ if (typeof model !== "string" || model.trim().length === 0) {
4987
+ ctx.addIssue({
4988
+ code: "custom",
4989
+ message: "maintenance model entries must be non-empty: a bare provider/model string or { model, variant?, thinking_level? }"
4990
+ });
4991
+ }
4992
+ });
4984
4993
  var ProfileHistorianSchema = object({
4985
4994
  model: HistorianModelEntrySchema.optional().describe("Primary historian model entry."),
4986
4995
  fallback_models: array(HistorianModelEntrySchema).optional().describe("Ordered fallback historian model entries."),
@@ -5107,6 +5116,8 @@ var MagicContextConfigSchema = object({
5107
5116
  }).describe("Cross-session memory configuration"),
5108
5117
  maintenance: object({
5109
5118
  enabled: boolean2().default(true).describe("Enable the automatic memory-maintenance task (default: true). USER-LEVEL ONLY — the whole maintenance group is stripped from project-tier config."),
5119
+ model: MaintenanceModelEntrySchema.optional().describe("Primary maintenance model entry: a bare provider/model string or { model, variant? (OpenCode), thinking_level? (Pi) }. USER-LEVEL ONLY. When absent, inherit historian model configuration. If neither has a primary, automatic passes skip and manual runs refuse. The main-session model is never inherited."),
5120
+ fallback_models: array(MaintenanceModelEntrySchema).optional().describe("Ordered fallback maintenance model entries, tried after CALL failures only. When absent and the primary is inherited, inherit historian fallbacks; explicit [] disables fallbacks. Illegal manifests, permission refusals, and exhausted budgets never switch models."),
5110
5121
  budgets: object({
5111
5122
  inputTokens: number2().int().min(1).default(400000).describe("Per-run input-token budget (input + cacheRead + cacheWrite pricing dimensions). Default 400000."),
5112
5123
  outputTokens: number2().int().min(1).default(32000).describe("Per-run output-token budget. Default 32000."),
@@ -5148,7 +5159,7 @@ var MagicContextConfigSchema = object({
5148
5159
  maxRetries: 3
5149
5160
  },
5150
5161
  anomalyThreshold: { absoluteRows: 10, poolFraction: 0.25 }
5151
- }).describe("Automatic memory-maintenance run controls (dreamer replacement). USER-LEVEL ONLY: the whole group is stripped from project-tier config so a cloned repository cannot raise budgets, relax cooldowns, or loosen the anomaly guard.")
5162
+ }).describe("Automatic memory-maintenance run controls (dreamer replacement). USER-LEVEL ONLY: project-tier config cannot pick maintenance models or change run controls. An absent model inherits historian model configuration, never the session model.")
5152
5163
  });
5153
5164
  var LIVE_RELOAD_CONFIG_PATHS = [
5154
5165
  "cache_ttl",
@@ -4998,6 +4998,15 @@ var HistorianModelEntryObjectSchema = object({
4998
4998
  thinking_level: PiThinkingLevelSchema.describe("Pi thinking level for this entry.")
4999
4999
  }).strict();
5000
5000
  var HistorianModelEntrySchema = union([string2(), HistorianModelEntryObjectSchema]);
5001
+ var MaintenanceModelEntrySchema = HistorianModelEntrySchema.superRefine((entry, ctx) => {
5002
+ const model = typeof entry === "string" ? entry : entry.model;
5003
+ if (typeof model !== "string" || model.trim().length === 0) {
5004
+ ctx.addIssue({
5005
+ code: "custom",
5006
+ message: "maintenance model entries must be non-empty: a bare provider/model string or { model, variant?, thinking_level? }"
5007
+ });
5008
+ }
5009
+ });
5001
5010
  var ProfileHistorianSchema = object({
5002
5011
  model: HistorianModelEntrySchema.optional().describe("Primary historian model entry."),
5003
5012
  fallback_models: array(HistorianModelEntrySchema).optional().describe("Ordered fallback historian model entries."),
@@ -5124,6 +5133,8 @@ var MagicContextConfigSchema = object({
5124
5133
  }).describe("Cross-session memory configuration"),
5125
5134
  maintenance: object({
5126
5135
  enabled: boolean2().default(true).describe("Enable the automatic memory-maintenance task (default: true). USER-LEVEL ONLY — the whole maintenance group is stripped from project-tier config."),
5136
+ model: MaintenanceModelEntrySchema.optional().describe("Primary maintenance model entry: a bare provider/model string or { model, variant? (OpenCode), thinking_level? (Pi) }. USER-LEVEL ONLY. When absent, inherit historian model configuration. If neither has a primary, automatic passes skip and manual runs refuse. The main-session model is never inherited."),
5137
+ fallback_models: array(MaintenanceModelEntrySchema).optional().describe("Ordered fallback maintenance model entries, tried after CALL failures only. When absent and the primary is inherited, inherit historian fallbacks; explicit [] disables fallbacks. Illegal manifests, permission refusals, and exhausted budgets never switch models."),
5127
5138
  budgets: object({
5128
5139
  inputTokens: number2().int().min(1).default(400000).describe("Per-run input-token budget (input + cacheRead + cacheWrite pricing dimensions). Default 400000."),
5129
5140
  outputTokens: number2().int().min(1).default(32000).describe("Per-run output-token budget. Default 32000."),
@@ -5165,7 +5176,7 @@ var MagicContextConfigSchema = object({
5165
5176
  maxRetries: 3
5166
5177
  },
5167
5178
  anomalyThreshold: { absoluteRows: 10, poolFraction: 0.25 }
5168
- }).describe("Automatic memory-maintenance run controls (dreamer replacement). USER-LEVEL ONLY: the whole group is stripped from project-tier config so a cloned repository cannot raise budgets, relax cooldowns, or loosen the anomaly guard.")
5179
+ }).describe("Automatic memory-maintenance run controls (dreamer replacement). USER-LEVEL ONLY: project-tier config cannot pick maintenance models or change run controls. An absent model inherits historian model configuration, never the session model.")
5169
5180
  });
5170
5181
  var LIVE_RELOAD_CONFIG_PATHS = [
5171
5182
  "cache_ttl",
@@ -1,5 +1,9 @@
1
1
  // ../plugin/src/shared/sqlite.ts
2
- import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { AsyncLocalStorage, AsyncResource } from "node:async_hooks";
3
+ var resourceRoot = new AsyncResource("magic-context:root");
4
+ function inRootAsyncContext(operation) {
5
+ return resourceRoot.runInAsyncScope(operation);
6
+ }
3
7
  var reportSlowPrivilegedWrite;
4
8
  function registerSlowWriteReporter(reporter) {
5
9
  reportSlowPrivilegedWrite = reporter;
@@ -190,7 +194,7 @@ function installTransactionRouting(db, readonly) {
190
194
  return endWriterTransaction(db, () => nativeExec(sql), sql);
191
195
  if (!/^\s*(?:SELECT|EXPLAIN|PRAGMA|COMMIT|END|ROLLBACK|SAVEPOINT|RELEASE)\b/i.test(sql)) {
192
196
  try {
193
- return withAutocommitTimeout(db, () => nativeExec(sql));
197
+ return withAutocommitTimeout(db, () => nativeExec(sql), false);
194
198
  } finally {
195
199
  if (mayChangeTagIdentity(sql))
196
200
  tagIdentityWriteGeneration += 1;
@@ -332,7 +336,7 @@ function trackSqliteConnection(db, filename, options) {
332
336
  }
333
337
  var TrackedDatabase = new Proxy(DatabaseImpl, {
334
338
  construct(target, args) {
335
- const db = Reflect.construct(target, args, target);
339
+ const db = inRootAsyncContext(() => Reflect.construct(target, args, target));
336
340
  return trackSqliteConnection(db, args[0], args[1]);
337
341
  }
338
342
  });
@@ -516,29 +520,48 @@ function foregroundWaitLease() {
516
520
  const lease = transformPassScope.getStore();
517
521
  return lease?.active && !admissionScope.getStore() && !backgroundWriterScope.getStore() ? lease : undefined;
518
522
  }
519
- function withAutocommitTimeout(db, operation) {
523
+ function withAutocommitTimeout(db, operation, singleStatement = true) {
520
524
  assertTransformWrite();
521
525
  const lease = foregroundWaitLease();
522
526
  if (isInTransaction(db))
523
527
  return operation();
524
528
  const scoped = lease || backgroundWriterScope.getStore();
525
529
  const previous = scoped ? pragmaNumber(db, "busy_timeout") : null;
526
- if (scoped)
527
- db.exec(`PRAGMA busy_timeout=${lease ? Math.floor(Math.min(lease.remainingWaitMs, lease.guard?.remainingMs() ?? Infinity)) : SHORT_BUSY_TIMEOUT_MS}`);
528
530
  const started = performance.now();
529
531
  let completed = false;
530
- try {
532
+ const execute = () => {
531
533
  const result = operation();
532
534
  completed = true;
533
535
  return result;
536
+ };
537
+ try {
538
+ if (!scoped)
539
+ return execute();
540
+ if (singleStatement) {
541
+ db.exec("PRAGMA busy_timeout=0");
542
+ try {
543
+ return execute();
544
+ } catch (error) {
545
+ if (!isTransientSqliteError(error) || isInTransaction(db))
546
+ throw error;
547
+ }
548
+ assertTransformWrite();
549
+ }
550
+ const timeout = Math.floor(Math.min(lease?.remainingWaitMs ?? SHORT_BUSY_TIMEOUT_MS, lease?.guard?.remainingMs() ?? Infinity));
551
+ db.exec(`PRAGMA busy_timeout=${timeout}`);
552
+ const waitStarted = performance.now();
553
+ try {
554
+ return execute();
555
+ } finally {
556
+ if (lease)
557
+ lease.remainingWaitMs = Math.max(0, lease.remainingWaitMs - (performance.now() - waitStarted));
558
+ }
534
559
  } catch (error) {
535
560
  if (lease && isTransientSqliteError(error))
536
561
  throw new SqliteAcquisitionBusyError(error, "autocommit");
537
562
  throw error;
538
563
  } finally {
539
564
  const elapsed = performance.now() - started;
540
- if (lease)
541
- lease.remainingWaitMs = Math.max(0, lease.remainingWaitMs - elapsed);
542
565
  if (previous !== null)
543
566
  db.exec(`PRAGMA busy_timeout=${previous}`);
544
567
  if (elapsed >= SLOW_WRITER_LOG_MS)
@@ -768,4 +791,4 @@ async function withIndexChunk(input, operation) {
768
791
  }
769
792
  }
770
793
 
771
- export { registerSlowWriteReporter, registerSqliteDiagnosticSink, detectSqliteRuntime, getTagIdentityWriteGeneration, Database, getSqliteDatabasePath, prepareCachedStatement, withSqliteBackgroundWriter, withSqliteTransformPass, withoutSqliteTransformPass, guardSqliteTransformPass, isTransientSqliteError, withAsyncPrivilegedWriter, withPrivilegedWriter, indexCoordinationInput, withIndexChunk };
794
+ export { inRootAsyncContext, registerSlowWriteReporter, registerSqliteDiagnosticSink, detectSqliteRuntime, getTagIdentityWriteGeneration, Database, getSqliteDatabasePath, prepareCachedStatement, withSqliteBackgroundWriter, withSqliteTransformPass, withoutSqliteTransformPass, guardSqliteTransformPass, isTransientSqliteError, withAsyncPrivilegedWriter, withPrivilegedWriter, indexCoordinationInput, withIndexChunk };