mixdog 0.9.19 → 0.9.21

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 (120) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +100 -34
  3. package/package.json +3 -2
  4. package/scripts/build-tui.mjs +6 -0
  5. package/scripts/hook-bus-test.mjs +8 -0
  6. package/scripts/log-writer-guard-smoke.mjs +131 -0
  7. package/scripts/reactive-compact-persist-smoke.mjs +22 -6
  8. package/scripts/recall-bench-cases.json +0 -1
  9. package/scripts/recall-quality-cases.json +1 -2
  10. package/scripts/session-ingest-compaction-smoke.mjs +241 -0
  11. package/scripts/tool-smoke.mjs +150 -45
  12. package/src/defaults/skills/setup/SKILL.md +327 -0
  13. package/src/help.mjs +2 -5
  14. package/src/lib/mixdog-debug.cjs +13 -0
  15. package/src/mixdog-session-runtime.mjs +7 -3328
  16. package/src/runtime/agent/orchestrator/context/collect.mjs +33 -9
  17. package/src/runtime/agent/orchestrator/providers/anthropic.mjs +34 -2
  18. package/src/runtime/agent/orchestrator/providers/gemini.mjs +3 -0
  19. package/src/runtime/agent/orchestrator/providers/grok-oauth.mjs +67 -10
  20. package/src/runtime/agent/orchestrator/providers/openai-compat.mjs +3 -0
  21. package/src/runtime/agent/orchestrator/providers/openai-oauth-http-sse.mjs +40 -3
  22. package/src/runtime/agent/orchestrator/providers/openai-ws.mjs +73 -3
  23. package/src/runtime/agent/orchestrator/session/agent-loop.mjs +663 -0
  24. package/src/runtime/agent/orchestrator/session/compact/engine.mjs +6 -0
  25. package/src/runtime/agent/orchestrator/session/eager-dispatch.mjs +153 -0
  26. package/src/runtime/agent/orchestrator/session/loop/recall-fasttrack.mjs +49 -0
  27. package/src/runtime/agent/orchestrator/session/loop/stored-tool-args.mjs +9 -1
  28. package/src/runtime/agent/orchestrator/session/loop.mjs +8 -1860
  29. package/src/runtime/agent/orchestrator/session/manager/agent-runtime-singleton.mjs +29 -0
  30. package/src/runtime/agent/orchestrator/session/manager/ask-session.mjs +686 -0
  31. package/src/runtime/agent/orchestrator/session/manager/compaction-runner.mjs +60 -12
  32. package/src/runtime/agent/orchestrator/session/manager/env-utils.mjs +8 -0
  33. package/src/runtime/agent/orchestrator/session/manager/idle-cleanup.mjs +159 -0
  34. package/src/runtime/agent/orchestrator/session/manager/message-sanitize.mjs +143 -0
  35. package/src/runtime/agent/orchestrator/session/manager/prefetch-bridge.mjs +268 -0
  36. package/src/runtime/agent/orchestrator/session/manager/provider-cache-key.mjs +22 -0
  37. package/src/runtime/agent/orchestrator/session/manager/runtime-loaders.mjs +26 -0
  38. package/src/runtime/agent/orchestrator/session/manager/session-close.mjs +124 -0
  39. package/src/runtime/agent/orchestrator/session/manager/session-crud.mjs +258 -0
  40. package/src/runtime/agent/orchestrator/session/manager/session-errors.mjs +20 -0
  41. package/src/runtime/agent/orchestrator/session/manager/session-id.mjs +9 -0
  42. package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.mjs +475 -0
  43. package/src/runtime/agent/orchestrator/session/manager/session-lock.mjs +23 -0
  44. package/src/runtime/agent/orchestrator/session/manager.mjs +88 -2285
  45. package/src/runtime/agent/orchestrator/session/pre-send-compact.mjs +440 -0
  46. package/src/runtime/agent/orchestrator/session/send-with-recovery.mjs +153 -0
  47. package/src/runtime/agent/orchestrator/session/store.mjs +4 -1
  48. package/src/runtime/agent/orchestrator/session/tool-batch.mjs +642 -0
  49. package/src/runtime/agent/orchestrator/tools/bash-session.mjs +23 -3
  50. package/src/runtime/agent/orchestrator/tools/builtin/shell-job-paths.mjs +108 -2
  51. package/src/runtime/agent/orchestrator/tools/builtin/shell-job-process.mjs +15 -3
  52. package/src/runtime/agent/orchestrator/tools/builtin/shell-jobs.mjs +7 -0
  53. package/src/runtime/agent/orchestrator/tools/builtin/shell-runtime.mjs +24 -2
  54. package/src/runtime/agent/orchestrator/tools/patch/orchestrator.mjs +2 -2
  55. package/src/runtime/agent/orchestrator/tools/patch/parsing.mjs +72 -8
  56. package/src/runtime/agent/orchestrator/tools/shell-policy-danger-target.mjs +5 -1
  57. package/src/runtime/channels/index.mjs +6 -2183
  58. package/src/runtime/channels/lib/inbound-handler.mjs +328 -0
  59. package/src/runtime/channels/lib/interaction-handlers.mjs +260 -0
  60. package/src/runtime/channels/lib/network-retry.mjs +23 -0
  61. package/src/runtime/channels/lib/owned-runtime.mjs +627 -0
  62. package/src/runtime/channels/lib/runtime-paths.mjs +20 -9
  63. package/src/runtime/channels/lib/transcript-binding.mjs +336 -0
  64. package/src/runtime/channels/lib/voice-runtime-fetcher.mjs +39 -2
  65. package/src/runtime/channels/lib/worker-bootstrap.mjs +97 -0
  66. package/src/runtime/channels/lib/worker-ipc.mjs +201 -0
  67. package/src/runtime/channels/lib/worker-main.mjs +777 -0
  68. package/src/runtime/memory/index.mjs +163 -1725
  69. package/src/runtime/memory/lib/embedding-provider.mjs +4 -2
  70. package/src/runtime/memory/lib/embedding-worker.mjs +47 -6
  71. package/src/runtime/memory/lib/http-router.mjs +811 -0
  72. package/src/runtime/memory/lib/memory-action-handlers.mjs +901 -0
  73. package/src/runtime/memory/lib/memory-cycle2-gate.mjs +6 -0
  74. package/src/runtime/memory/lib/memory-cycle2-mutations.mjs +46 -9
  75. package/src/runtime/memory/lib/memory-cycle2.mjs +87 -11
  76. package/src/runtime/memory/lib/memory-embed.mjs +28 -7
  77. package/src/runtime/memory/lib/memory-recall-store.mjs +4 -4
  78. package/src/runtime/memory/lib/memory.mjs +39 -0
  79. package/src/runtime/memory/lib/query-handlers.mjs +2 -2
  80. package/src/runtime/memory/lib/session-ingest-runtime.mjs +401 -0
  81. package/src/runtime/shared/atomic-file.mjs +138 -80
  82. package/src/runtime/shared/child-guardian.mjs +61 -3
  83. package/src/session-runtime/boot-profile.mjs +36 -0
  84. package/src/session-runtime/channel-config-api.mjs +70 -0
  85. package/src/session-runtime/context-status.mjs +181 -0
  86. package/src/session-runtime/env.mjs +17 -0
  87. package/src/session-runtime/lifecycle-api.mjs +242 -0
  88. package/src/session-runtime/model-route-api.mjs +198 -0
  89. package/src/session-runtime/provider-auth-api.mjs +135 -0
  90. package/src/session-runtime/resource-api.mjs +282 -0
  91. package/src/session-runtime/runtime-core.mjs +2104 -0
  92. package/src/session-runtime/session-turn-api.mjs +274 -0
  93. package/src/session-runtime/tool-catalog.mjs +18 -264
  94. package/src/session-runtime/tool-defs.mjs +2 -2
  95. package/src/session-runtime/workflow-agents-api.mjs +238 -0
  96. package/src/standalone/agent-tool.mjs +2 -2
  97. package/src/standalone/channel-worker.mjs +67 -7
  98. package/src/standalone/folder-dialog.mjs +4 -1
  99. package/src/standalone/memory-runtime-proxy.mjs +154 -17
  100. package/src/standalone/seeds.mjs +28 -1
  101. package/src/tui/App.jsx +40 -28
  102. package/src/tui/app/core-memory-picker.mjs +1 -1
  103. package/src/tui/app/doctor.mjs +175 -0
  104. package/src/tui/app/slash-commands.mjs +1 -0
  105. package/src/tui/app/slash-dispatch.mjs +9 -0
  106. package/src/tui/app/use-mouse-input.mjs +6 -0
  107. package/src/tui/app/use-transcript-scroll.mjs +77 -3
  108. package/src/tui/dist/index.mjs +2851 -2162
  109. package/src/tui/engine/context-state.mjs +145 -0
  110. package/src/tui/engine/prompt-history.mjs +27 -0
  111. package/src/tui/engine/session-api-ext.mjs +478 -0
  112. package/src/tui/engine/session-api.mjs +564 -0
  113. package/src/tui/engine/session-flow.mjs +485 -0
  114. package/src/tui/engine/turn.mjs +1078 -0
  115. package/src/tui/engine.mjs +68 -2620
  116. package/src/tui/index.jsx +7 -0
  117. package/vendor/ink/build/ink.js +16 -1
  118. package/vendor/ink/build/output.js +30 -4
  119. package/vendor/ink/build/render.js +5 -0
  120. package/src/workflows/sequential/WORKFLOW.md +0 -51
@@ -218,14 +218,16 @@ export function warmupEmbeddingProvider() {
218
218
  return _warmupPromise
219
219
  }
220
220
 
221
- export async function embedText(text) {
221
+ export async function embedText(text, options = {}) {
222
222
  const clean = String(text ?? '').trim()
223
223
  if (!clean) return []
224
224
  const cacheKey = `${MODEL_ID}\n${clean}`
225
225
  const cached = getCachedEmbedding(cacheKey)
226
226
  if (cached) return [...cached]
227
227
 
228
- const result = await sendToWorker('embed', { text: clean })
228
+ // Interactive query embeds pass { priority: true } so the worker can
229
+ // queue-jump them ahead of background flush embed-batch work.
230
+ const result = await sendToWorker('embed', { text: clean, priority: options?.priority === true })
229
231
  if (!result.dims) throw new Error(`embed result missing dims (model=${MODEL_ID})`)
230
232
  const resultDims = result.dims
231
233
  if (cachedDims && resultDims !== cachedDims) {
@@ -57,6 +57,47 @@ let _idleTimer = null
57
57
  let _embedInFlight = false
58
58
  const _msgQueue = []
59
59
  let ortPatched = false
60
+ // Control ops must never be overtaken by a priority embed: crossing a queued
61
+ // configure/dispose/warmup would run inference against pre-configure or
62
+ // post-dispose model state.
63
+ const CONTROL_ACTIONS = new Set(['configure', 'dispose', 'warmup'])
64
+ // Anti-starvation cap: max times a single queued flush embed-batch may be
65
+ // overtaken by priority embeds before it is allowed to run. Bounds how long a
66
+ // flush (which may hold DB row locks in flushEmbeddingDirty) can be delayed
67
+ // under sustained interactive traffic. MIXDOG_EMBED_PRIORITY_SKIP_CAP overrides.
68
+ const _envSkipCap = Number(process.env.MIXDOG_EMBED_PRIORITY_SKIP_CAP)
69
+ const PRIORITY_SKIP_CAP = Number.isFinite(_envSkipCap) && _envSkipCap >= 1 ? Math.floor(_envSkipCap) : 8
70
+ // Queue with a single priority lane. Interactive query embeds (msg.priority)
71
+ // jump ahead of background flush embed-batch work so an in-progress large
72
+ // flush cannot starve a live recall's query vector. Constraints:
73
+ // - never cross a queued control op (insert only after the last one),
74
+ // - stay in FIFO order behind already-queued priority embeds,
75
+ // - never preempt the running ONNX call,
76
+ // - never overtake the same flush batch more than PRIORITY_SKIP_CAP times.
77
+ function enqueue(msg) {
78
+ if (!msg?.priority) { _msgQueue.push(msg); return }
79
+ // Barrier: insertion must land after the last queued control op.
80
+ let lastControl = -1
81
+ for (let i = 0; i < _msgQueue.length; i++) {
82
+ if (CONTROL_ACTIONS.has(_msgQueue[i].action)) lastControl = i
83
+ }
84
+ // In the tail after that barrier, priority embeds cluster first, then the
85
+ // background embed-batch entries — advance to the first embed-batch so this
86
+ // embed sits behind existing priority embeds but ahead of flush work.
87
+ let pos = lastControl + 1
88
+ while (pos < _msgQueue.length && _msgQueue[pos].action !== 'embed-batch') pos++
89
+ if (pos < _msgQueue.length) {
90
+ const batch = _msgQueue[pos]
91
+ if ((batch._priorityJumps || 0) >= PRIORITY_SKIP_CAP) {
92
+ // This flush batch has been overtaken enough — yield so it makes
93
+ // progress (and can release any row locks) before more query embeds run.
94
+ _msgQueue.splice(pos + 1, 0, msg)
95
+ return
96
+ }
97
+ batch._priorityJumps = (batch._priorityJumps || 0) + 1
98
+ }
99
+ _msgQueue.splice(pos, 0, msg)
100
+ }
60
101
  // Actions that must hold the in-flight guard for their entire async duration.
61
102
  // Inference actions hold it so concurrent embeds serialize; configure/dispose
62
103
  // hold it so a new embed arriving mid-await cannot race extractorPromise
@@ -209,7 +250,7 @@ async function processMessage(msg) {
209
250
  switch (action) {
210
251
  case 'embed-batch': {
211
252
  if (_embedInFlight) {
212
- _msgQueue.push(msg)
253
+ enqueue(msg)
213
254
  return
214
255
  }
215
256
  _embedInFlight = true
@@ -236,7 +277,7 @@ async function processMessage(msg) {
236
277
  case 'embed': {
237
278
  if (_embedInFlight) {
238
279
  // Re-queue behind current — serialize all embed calls
239
- _msgQueue.push(msg)
280
+ enqueue(msg)
240
281
  return
241
282
  }
242
283
  _embedInFlight = true
@@ -254,7 +295,7 @@ async function processMessage(msg) {
254
295
  }
255
296
  case 'warmup': {
256
297
  if (_embedInFlight) {
257
- _msgQueue.push(msg)
298
+ enqueue(msg)
258
299
  return
259
300
  }
260
301
  _embedInFlight = true
@@ -272,7 +313,7 @@ async function processMessage(msg) {
272
313
  }
273
314
  case 'configure': {
274
315
  if (_embedInFlight) {
275
- _msgQueue.push(msg)
316
+ enqueue(msg)
276
317
  return
277
318
  }
278
319
  _embedInFlight = true
@@ -293,7 +334,7 @@ async function processMessage(msg) {
293
334
  }
294
335
  case 'dispose': {
295
336
  if (_embedInFlight) {
296
- _msgQueue.push(msg)
337
+ enqueue(msg)
297
338
  return
298
339
  }
299
340
  _embedInFlight = true
@@ -332,7 +373,7 @@ parentPort.on('message', async (msg) => {
332
373
  // here, a new embed arriving mid-dispose would bypass the queue and race
333
374
  // extractorPromise reset / ext.dispose() against the prior tear-down.
334
375
  if (_embedInFlight) {
335
- _msgQueue.push(msg)
376
+ enqueue(msg)
336
377
  return
337
378
  }
338
379
  await processMessage(msg)