mixdog 0.9.87 → 0.9.88

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 (160) hide show
  1. package/package.json +13 -7
  2. package/scripts/tool-failures.mjs +60 -24
  3. package/src/agents/heavy-worker/AGENT.md +3 -4
  4. package/src/agents/worker/AGENT.md +1 -2
  5. package/src/cli.mjs +8 -0
  6. package/src/defaults/cycle3-review-prompt.md +4 -4
  7. package/src/rules/agent/00-core.md +3 -0
  8. package/src/rules/agent/42-cycle3-agent.md +5 -6
  9. package/src/rules/lead/01-general.md +2 -0
  10. package/src/rules/shared/01-tool.md +5 -1
  11. package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch.mjs +3 -51
  12. package/src/runtime/agent/orchestrator/agent-runtime/maintenance-route.mjs +59 -0
  13. package/src/runtime/agent/orchestrator/agent-runtime/session-builder.mjs +2 -2
  14. package/src/runtime/agent/orchestrator/agent-runtime/title-completion.mjs +67 -0
  15. package/src/runtime/agent/orchestrator/agent-trace-format.mjs +57 -4
  16. package/src/runtime/agent/orchestrator/agent-trace-io.mjs +2 -3
  17. package/src/runtime/agent/orchestrator/config.mjs +29 -11
  18. package/src/runtime/agent/orchestrator/context/collect.mjs +1 -1
  19. package/src/runtime/agent/orchestrator/internal-agents.mjs +1 -1
  20. package/src/runtime/agent/orchestrator/mcp/client.mjs +0 -24
  21. package/src/runtime/agent/orchestrator/providers/admission-scheduler.mjs +3 -3
  22. package/src/runtime/agent/orchestrator/providers/anthropic-oauth.mjs +25 -17
  23. package/src/runtime/agent/orchestrator/providers/anthropic-sse.mjs +321 -22
  24. package/src/runtime/agent/orchestrator/providers/anthropic.mjs +35 -22
  25. package/src/runtime/agent/orchestrator/providers/gemini-stream.mjs +28 -23
  26. package/src/runtime/agent/orchestrator/providers/gemini.mjs +10 -2
  27. package/src/runtime/agent/orchestrator/providers/grok-oauth-login.mjs +0 -1
  28. package/src/runtime/agent/orchestrator/providers/grok-oauth-tokens.mjs +0 -1
  29. package/src/runtime/agent/orchestrator/providers/grok-oauth.mjs +2 -5
  30. package/src/runtime/agent/orchestrator/providers/lib/anthropic-native-blocks.mjs +27 -0
  31. package/src/runtime/agent/orchestrator/providers/lib/anthropic-request-utils.mjs +23 -0
  32. package/src/runtime/agent/orchestrator/providers/lib/stream-outcome.mjs +329 -0
  33. package/src/runtime/agent/orchestrator/providers/oauth-usage.mjs +23 -1
  34. package/src/runtime/agent/orchestrator/providers/openai-compat-stream.mjs +107 -20
  35. package/src/runtime/agent/orchestrator/providers/openai-compat.mjs +4 -3
  36. package/src/runtime/agent/orchestrator/providers/openai-oauth-http-sse.mjs +124 -12
  37. package/src/runtime/agent/orchestrator/providers/openai-oauth-ws.mjs +19 -2
  38. package/src/runtime/agent/orchestrator/providers/openai-oauth.mjs +1 -1
  39. package/src/runtime/agent/orchestrator/providers/openai-responses-payload.mjs +1 -1
  40. package/src/runtime/agent/orchestrator/providers/openai-ws-stream.mjs +110 -75
  41. package/src/runtime/agent/orchestrator/providers/retry-classifier.mjs +96 -113
  42. package/src/runtime/agent/orchestrator/session/agent-loop.mjs +144 -10
  43. package/src/runtime/agent/orchestrator/session/lifecycle-scan.mjs +147 -117
  44. package/src/runtime/agent/orchestrator/session/loop/stop-hooks.mjs +88 -0
  45. package/src/runtime/agent/orchestrator/session/loop/termination.mjs +25 -0
  46. package/src/runtime/agent/orchestrator/session/loop/tool-exec.mjs +1 -1
  47. package/src/runtime/agent/orchestrator/session/manager/ask-session.mjs +47 -6
  48. package/src/runtime/agent/orchestrator/session/manager/pending-messages.mjs +485 -24
  49. package/src/runtime/agent/orchestrator/session/manager/session-close.mjs +100 -2
  50. package/src/runtime/agent/orchestrator/session/manager/session-crud.mjs +28 -0
  51. package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.mjs +80 -14
  52. package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint.mjs +142 -2
  53. package/src/runtime/agent/orchestrator/session/manager/usage-metrics.mjs +128 -32
  54. package/src/runtime/agent/orchestrator/session/manager.mjs +5 -1
  55. package/src/runtime/agent/orchestrator/session/save-session-worker.mjs +77 -4
  56. package/src/runtime/agent/orchestrator/session/send-with-recovery.mjs +70 -39
  57. package/src/runtime/agent/orchestrator/session/store/fs-probe.mjs +91 -0
  58. package/src/runtime/agent/orchestrator/session/store/listing.mjs +141 -64
  59. package/src/runtime/agent/orchestrator/session/store/live-state.mjs +253 -0
  60. package/src/runtime/agent/orchestrator/session/store/load-cache.mjs +211 -28
  61. package/src/runtime/agent/orchestrator/session/store/save-fault.mjs +313 -0
  62. package/src/runtime/agent/orchestrator/session/store/save-worker.mjs +622 -53
  63. package/src/runtime/agent/orchestrator/session/store/serialize.mjs +43 -10
  64. package/src/runtime/agent/orchestrator/session/store/summary-cache.mjs +53 -8
  65. package/src/runtime/agent/orchestrator/session/store/summary-rebuild-worker.mjs +20 -0
  66. package/src/runtime/agent/orchestrator/session/store/write-guards.mjs +113 -9
  67. package/src/runtime/agent/orchestrator/session/store-summary-index.mjs +2 -0
  68. package/src/runtime/agent/orchestrator/session/store-summary-reader.mjs +476 -52
  69. package/src/runtime/agent/orchestrator/session/store.mjs +721 -196
  70. package/src/runtime/agent/orchestrator/session/token-native.mjs +2 -4
  71. package/src/runtime/agent/orchestrator/session/tool-batch.mjs +19 -0
  72. package/src/runtime/agent/orchestrator/tools/bash-session.mjs +4 -6
  73. package/src/runtime/agent/orchestrator/tools/builtin/list-tool.mjs +146 -90
  74. package/src/runtime/agent/orchestrator/tools/builtin/read-single-tool.mjs +6 -0
  75. package/src/runtime/agent/orchestrator/tools/builtin/rg-runner.mjs +93 -17
  76. package/src/runtime/agent/orchestrator/tools/builtin/search-path-diagnostics.mjs +5 -0
  77. package/src/runtime/agent/orchestrator/tools/builtin/search-tool.mjs +7 -7
  78. package/src/runtime/agent/orchestrator/tools/builtin/shell-job-spawn.mjs +2 -0
  79. package/src/runtime/agent/orchestrator/tools/builtin/snapshot-store.mjs +52 -0
  80. package/src/runtime/agent/orchestrator/tools/code-graph/disk-cache.mjs +54 -51
  81. package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.mjs +14 -15
  82. package/src/runtime/agent/orchestrator/tools/patch/dispatch.mjs +132 -8
  83. package/src/runtime/agent/orchestrator/tools/patch/matcher.mjs +67 -3
  84. package/src/runtime/agent/orchestrator/tools/patch/native-server.mjs +6 -1
  85. package/src/runtime/agent/orchestrator/tools/patch/orchestrator.mjs +203 -38
  86. package/src/runtime/agent/orchestrator/tools/patch/paths.mjs +13 -1
  87. package/src/runtime/agent/orchestrator/tools/patch/v4a-convert.mjs +73 -19
  88. package/src/runtime/agent/orchestrator/tools/patch-manifest.json +11 -11
  89. package/src/runtime/agent/orchestrator/tools/patch-tool-defs.mjs +11 -8
  90. package/src/runtime/agent/orchestrator/tools/shell-command.mjs +12 -2
  91. package/src/runtime/media/lanes.mjs +2 -2
  92. package/src/runtime/media/renditions.mjs +101 -17
  93. package/src/runtime/media/renditions.test.mjs +54 -0
  94. package/src/runtime/media/store.mjs +111 -43
  95. package/src/runtime/media/store.test.mjs +53 -11
  96. package/src/runtime/memory/index.mjs +26 -50
  97. package/src/runtime/memory/lib/core-memory-candidates.mjs +2 -7
  98. package/src/runtime/memory/lib/core-memory-store.mjs +2 -9
  99. package/src/runtime/memory/lib/cycle-scheduler.mjs +10 -0
  100. package/src/runtime/memory/lib/embedding-provider.mjs +3 -3
  101. package/src/runtime/memory/lib/embedding-worker.mjs +60 -15
  102. package/src/runtime/memory/lib/http-router.mjs +4 -0
  103. package/src/runtime/memory/lib/ko-morph.mjs +49 -6
  104. package/src/runtime/memory/lib/memory-action-handlers.mjs +21 -18
  105. package/src/runtime/memory/lib/memory-cycle2.mjs +3 -3
  106. package/src/runtime/memory/lib/memory-cycle3.mjs +1 -3
  107. package/src/runtime/memory/lib/memory-recall-store.mjs +24 -0
  108. package/src/runtime/memory/lib/query-handlers.mjs +26 -28
  109. package/src/runtime/memory/tool-defs.mjs +3 -3
  110. package/src/runtime/shared/atomic-file.mjs +5 -1
  111. package/src/runtime/shared/child-guardian.mjs +52 -2
  112. package/src/runtime/shared/provider-api-key.mjs +22 -5
  113. package/src/runtime/shared/tool-execution-contract.mjs +53 -0
  114. package/src/session-runtime/config-helpers.mjs +6 -5
  115. package/src/session-runtime/lifecycle-api.mjs +16 -4
  116. package/src/session-runtime/media-api.mjs +31 -16
  117. package/src/session-runtime/prewarm.mjs +2 -24
  118. package/src/session-runtime/runtime-core.mjs +33 -15
  119. package/src/session-runtime/runtime-tunables.mjs +0 -3
  120. package/src/session-runtime/session-lifecycle.mjs +0 -6
  121. package/src/session-runtime/session-title.mjs +228 -0
  122. package/src/session-runtime/session-turn-api.mjs +11 -7
  123. package/src/session-runtime/workflow-agents-api.mjs +16 -0
  124. package/src/session-runtime/workflow.mjs +7 -5
  125. package/src/standalone/agent-tool/job-views.mjs +90 -36
  126. package/src/standalone/agent-tool/spawn-flow.mjs +25 -216
  127. package/src/standalone/agent-tool/worker-index.mjs +8 -0
  128. package/src/standalone/agent-tool/worker-rows.mjs +2 -1
  129. package/src/standalone/agent-tool.mjs +17 -17
  130. package/src/standalone/agent-watchdog-registry.mjs +19 -2
  131. package/src/standalone/channel-daemon.mjs +8 -0
  132. package/src/standalone/memory-runtime-proxy.mjs +4 -7
  133. package/src/standalone/projects.mjs +4 -1
  134. package/src/standalone/usage-dashboard.mjs +25 -3
  135. package/src/tui/App.jsx +5 -3
  136. package/src/tui/app/resume-picker.mjs +7 -2
  137. package/src/tui/app/slash-dispatch.mjs +13 -3
  138. package/src/tui/app/transcript-row-estimate.mjs +1 -1
  139. package/src/tui/app/transcript-window.mjs +17 -93
  140. package/src/tui/app/use-transcript-scroll.mjs +32 -2
  141. package/src/tui/app/use-transcript-window.mjs +64 -114
  142. package/src/tui/components/Markdown.jsx +19 -2
  143. package/src/tui/components/Message.jsx +8 -3
  144. package/src/tui/components/ToolExecution.jsx +7 -3
  145. package/src/tui/dist/index.mjs +233 -121
  146. package/src/tui/engine/live-share.mjs +15 -5
  147. package/src/tui/engine/render-timing.mjs +2 -2
  148. package/src/tui/engine/session-api-ext.mjs +74 -4
  149. package/src/tui/engine/session-flow.mjs +3 -1
  150. package/src/tui/engine.mjs +2 -2
  151. package/src/tui/hooks/useSharedTick.mjs +0 -2
  152. package/src/tui/index.jsx +5 -5
  153. package/src/ui/statusline-agents.mjs +44 -11
  154. package/src/vendor/statusline/bin/statusline-route.mjs +26 -3
  155. package/src/workflows/default/WORKFLOW.md +3 -3
  156. package/src/workflows/solo/WORKFLOW.md +1 -1
  157. package/src/runtime/media/index.mjs +0 -18
  158. package/src/runtime/memory/lib/embedding-warmup.mjs +0 -68
  159. package/src/standalone/agent-shard/shard-child.mjs +0 -300
  160. package/src/standalone/agent-shard/shard-pool.mjs +0 -443
@@ -1,4 +1,5 @@
1
1
  import { createSessionLifecycle } from './session-lifecycle.mjs';
2
+ import { createSessionTitleController } from './session-title.mjs';
2
3
  import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from 'node:fs';
3
4
  import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
4
5
  import { performance } from 'node:perf_hooks';
@@ -549,7 +550,6 @@ export async function createMixdogSessionRuntime({
549
550
  }
550
551
  // Env-tunable boot delays and feature gates: runtime-tunables.mjs.
551
552
  const {
552
- sessionPrewarmDelayMs,
553
553
  providerSetupWarmupDelayMs,
554
554
  modelCatalogWarmupDelayMs,
555
555
  providerWarmupDelayMs,
@@ -560,7 +560,6 @@ export async function createMixdogSessionRuntime({
560
560
  channelStartDelayMs,
561
561
  backgroundBusyRetryMs,
562
562
  remoteAutoStartDelayMs,
563
- sessionPrewarmEnabled,
564
563
  providerWarmupEnabled,
565
564
  modelPrefetchEnabled,
566
565
  codeGraphPrewarmEnabled,
@@ -815,6 +814,20 @@ export async function createMixdogSessionRuntime({
815
814
  getCurrentCwd: () => rt.currentCwd,
816
815
  getMode: () => rt.mode,
817
816
  });
817
+ const computeContextStatusForSession = (session) => {
818
+ if (!session || typeof session !== 'object') return null;
819
+ const { contextStatus } = createContextStatus({
820
+ getSession: () => session,
821
+ getRoute: () => ({
822
+ provider: session.provider || '',
823
+ model: session.model || '',
824
+ contextWindow: session.contextWindow || null,
825
+ }),
826
+ getCurrentCwd: () => session.cwd || rt.currentCwd,
827
+ getMode: () => rt.mode,
828
+ });
829
+ return contextStatus();
830
+ };
818
831
  internalTools.setInternalToolsProvider({
819
832
  tools: [...standaloneTools, ...searchRuntimeTools.filter((tool) => tool?.public === false)],
820
833
  executor: async (name, args, callerCtx = {}) => {
@@ -1156,7 +1169,6 @@ export async function createMixdogSessionRuntime({
1156
1169
  scheduleStatuslineUsageWarmup,
1157
1170
  scheduleStatuslineUsageRefresh,
1158
1171
  scheduleCodeGraphPrewarm,
1159
- scheduleLeadSessionPrewarm,
1160
1172
  scheduleToolRuntimeWarmup,
1161
1173
  invokeChannelStart,
1162
1174
  scheduleChannelStart,
@@ -1207,9 +1219,7 @@ export async function createMixdogSessionRuntime({
1207
1219
  channels,
1208
1220
  codeGraphPrewarmDelayMs,
1209
1221
  channelStartDelayMs,
1210
- sessionPrewarmDelayMs,
1211
1222
  codeGraphPrewarmEnabled,
1212
- sessionPrewarmEnabled,
1213
1223
  prewarmState,
1214
1224
  });
1215
1225
  const ensureRemoteTranscriptWriter = () => remoteTranscript.ensureRemoteTranscriptWriter();
@@ -1267,19 +1277,12 @@ export async function createMixdogSessionRuntime({
1267
1277
 
1268
1278
  bootProfile('session-runtime:ready', {
1269
1279
  lazySession: true,
1270
- prewarmSession: sessionPrewarmEnabled,
1271
1280
  providerWarmup: providerWarmupEnabled,
1272
1281
  codeGraphPrewarm: codeGraphPrewarmEnabled,
1273
1282
  });
1274
- scheduleLeadSessionPrewarm();
1275
- scheduleToolRuntimeWarmup();
1276
- // Lazy mode (default): skip the startup prewarm entirely; the first turn
1277
- // triggers it instead (see ask()). Eager mode keeps the old startup schedule.
1278
- if (!codeGraphPrewarmLazy) {
1279
- scheduleCodeGraphPrewarm(codeGraphPrewarmDelayMs, 'startup');
1280
- } else {
1281
- bootProfile('code-graph:prewarm-lazy', { reason: 'startup-deferred-to-first-turn' });
1282
- }
1283
+ // Heavy session/tool/code-graph work is demand-driven. Startup restores the
1284
+ // visible pane tree only; the first real turn arms these warmups.
1285
+ bootProfile('runtime:prewarm-deferred', { reason: 'first-turn' });
1283
1286
  scheduleProviderSetupWarmup();
1284
1287
  scheduleModelCatalogWarmup();
1285
1288
  scheduleProviderWarmup();
@@ -1411,6 +1414,12 @@ export async function createMixdogSessionRuntime({
1411
1414
  collectProviderModels,
1412
1415
  });
1413
1416
  const mediaApi = createMediaApi();
1417
+ const sessionTitles = createSessionTitleController({
1418
+ dataRoot: () => cfgMod.getPluginData?.() || STANDALONE_DATA_DIR,
1419
+ promoteGeneratedTitle: (sessionId, title, stage) => (
1420
+ mgr.updateSessionGeneratedTitle(sessionId, title, stage)
1421
+ ),
1422
+ });
1414
1423
  const lifecycleApi = createLifecycleApi({
1415
1424
  getSession: () => rt.session,
1416
1425
  setSession: (v) => { rt.session = v; },
@@ -1454,6 +1463,7 @@ export async function createMixdogSessionRuntime({
1454
1463
  // workflow's agent-tool gate, not reuse the boot-time array.
1455
1464
  getStandaloneTools: modelStandaloneTools,
1456
1465
  desktopSession: rt.desktopSession,
1466
+ disposeSessionTitles: () => sessionTitles.disposeAll(),
1457
1467
  });
1458
1468
  const resourceApi = createResourceApi({
1459
1469
  getConfig: () => rt.config,
@@ -1563,6 +1573,7 @@ export async function createMixdogSessionRuntime({
1563
1573
  getLastAppendedAssistant: () => rt._lastAppendedAssistant,
1564
1574
  setLastAppendedAssistant: (v) => { rt._lastAppendedAssistant = v; },
1565
1575
  scheduleCodeGraphPrewarm,
1576
+ scheduleToolRuntimeWarmup,
1566
1577
  refreshSessionForCwdIfNeeded,
1567
1578
  createCurrentSession,
1568
1579
  ensureRemoteTranscriptWriter,
@@ -1590,6 +1601,7 @@ export async function createMixdogSessionRuntime({
1590
1601
  remoteStateListeners,
1591
1602
  awaitInitialMcpConnect,
1592
1603
  awaitRoutePreparation: () => routePreparation.wait(),
1604
+ sessionTitles,
1593
1605
  });
1594
1606
 
1595
1607
  return {
@@ -1672,6 +1684,12 @@ export async function createMixdogSessionRuntime({
1672
1684
  // authoritative committed transcript.
1673
1685
  return computeContextStatus();
1674
1686
  },
1687
+ contextStatusForSession(session) {
1688
+ return computeContextStatusForSession(session);
1689
+ },
1690
+ renameSessionTitle(sessionId, title) {
1691
+ return mgr.updateSessionManualTitle(sessionId, title);
1692
+ },
1675
1693
  startRemote() {
1676
1694
  return startRemote();
1677
1695
  },
@@ -7,7 +7,6 @@ import { envDelayMs, envFlag, envPresent } from './env.mjs';
7
7
  export function readRuntimeTunables() {
8
8
  const codeGraphPrewarmEnabled = !envFlag('MIXDOG_DISABLE_CODE_GRAPH_PREWARM');
9
9
  return {
10
- sessionPrewarmDelayMs: envDelayMs('MIXDOG_SESSION_PREWARM_DELAY_MS', 50, { min: 0, max: 10_000 }),
11
10
  providerSetupWarmupDelayMs: envDelayMs('MIXDOG_PROVIDER_SETUP_WARMUP_DELAY_MS', 300, { min: 0, max: 60_000 }),
12
11
  modelCatalogWarmupDelayMs: envDelayMs('MIXDOG_MODEL_CATALOG_WARMUP_DELAY_MS', 200, { min: 0, max: 60_000 }),
13
12
  providerWarmupDelayMs: envDelayMs('MIXDOG_PROVIDER_WARMUP_DELAY_MS', 1_500, { min: 0, max: 60_000 }),
@@ -27,8 +26,6 @@ export function readRuntimeTunables() {
27
26
  backgroundBusyRetryMs: envDelayMs('MIXDOG_BACKGROUND_BUSY_RETRY_MS', 1_000, { min: 50, max: 10_000 }),
28
27
  // Boot-time remote start is deferred past the first frame; see the caller.
29
28
  remoteAutoStartDelayMs: envDelayMs('MIXDOG_REMOTE_AUTOSTART_DELAY_MS', 1_500, { min: 0, max: 60_000 }),
30
- sessionPrewarmEnabled: !envFlag('MIXDOG_DISABLE_SESSION_PREWARM')
31
- && (envFlag('MIXDOG_ENABLE_SESSION_PREWARM') || envPresent('MIXDOG_SESSION_PREWARM_DELAY_MS')),
32
29
  providerWarmupEnabled: !envFlag('MIXDOG_DISABLE_PROVIDER_WARMUP')
33
30
  && (
34
31
  envFlag('MIXDOG_ENABLE_PROVIDER_WARMUP')
@@ -59,9 +59,7 @@ export function createSessionLifecycle({
59
59
  channels,
60
60
  codeGraphPrewarmDelayMs,
61
61
  channelStartDelayMs,
62
- sessionPrewarmDelayMs,
63
62
  codeGraphPrewarmEnabled,
64
- sessionPrewarmEnabled,
65
63
  prewarmState,
66
64
  }) {
67
65
  async function resolveMissingRouteModelForFirstTurn() {
@@ -308,7 +306,6 @@ export function createSessionLifecycle({
308
306
 
309
307
  const {
310
308
  scheduleCodeGraphPrewarm,
311
- scheduleLeadSessionPrewarm,
312
309
  scheduleToolRuntimeWarmup,
313
310
  invokeChannelStart,
314
311
  scheduleChannelStart,
@@ -330,12 +327,10 @@ export function createSessionLifecycle({
330
327
  delays: {
331
328
  codeGraphPrewarmDelayMs,
332
329
  channelStartDelayMs,
333
- sessionPrewarmDelayMs,
334
330
  backgroundBusyRetryMs,
335
331
  },
336
332
  flags: {
337
333
  codeGraphPrewarmEnabled,
338
- sessionPrewarmEnabled,
339
334
  },
340
335
  state: prewarmState,
341
336
  });
@@ -364,7 +359,6 @@ export function createSessionLifecycle({
364
359
  scheduleStatuslineUsageWarmup,
365
360
  scheduleStatuslineUsageRefresh,
366
361
  scheduleCodeGraphPrewarm,
367
- scheduleLeadSessionPrewarm,
368
362
  scheduleToolRuntimeWarmup,
369
363
  invokeChannelStart,
370
364
  scheduleChannelStart,
@@ -0,0 +1,228 @@
1
+ import { appendFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+
4
+ import {
5
+ cleanSessionPreview,
6
+ isSessionPreviewNoise,
7
+ sessionMessageText,
8
+ } from './session-text.mjs';
9
+
10
+ // Title generation runs beside the main turn and may include a cold provider
11
+ // start. Keep it bounded, but allow enough time for the first-turn title to
12
+ // become the shared label instead of routinely falling back until turn three.
13
+ export const SESSION_TITLE_TIMEOUT_MS = 10_000;
14
+
15
+ const KOREAN_GREETING_TITLE = new Set([
16
+ 'ㅎㅇ',
17
+ '하이',
18
+ '안녕',
19
+ '안녕하세요',
20
+ '헬로',
21
+ '반가워',
22
+ '반갑습니다',
23
+ ]);
24
+ const ENGLISH_GREETING_TITLE = new Set(['hi', 'hello', 'hey']);
25
+
26
+ function hasMeaningfulTitleText(value) {
27
+ return /[\p{L}\p{N}]/u.test(String(value || ''));
28
+ }
29
+
30
+ function compactTitle(value, maximum = 32) {
31
+ const line = String(value || '')
32
+ .replace(/<think>[\s\S]*?<\/think>\s*/gi, '')
33
+ .split(/\r?\n/)
34
+ .map((entry) => entry.trim().replace(/^["'`#*\s]+|["'`\s.]+$/g, ''))
35
+ .find(Boolean) || '';
36
+ const text = cleanSessionPreview(line, Math.max(maximum * 4, 128));
37
+ if (!hasMeaningfulTitleText(text)) return '';
38
+ if (text.length <= maximum) return text;
39
+ const clipped = text.slice(0, maximum - 1);
40
+ const boundary = clipped.lastIndexOf(' ');
41
+ const head = boundary >= Math.floor(maximum * 0.6) ? clipped.slice(0, boundary) : clipped;
42
+ return `${head.trimEnd()}…`;
43
+ }
44
+
45
+ function titleMessageText(message, role) {
46
+ if (!message || typeof message !== 'object') return '';
47
+ if (message.internal === true || message.synthetic === true) return '';
48
+ const raw = sessionMessageText(message.content ?? message.text);
49
+ if (!raw || (role === 'user' && isSessionPreviewNoise(raw))) return '';
50
+ const visible = cleanSessionPreview(
51
+ raw.replace(/<think>[\s\S]*?<\/think>\s*/gi, ''),
52
+ 4_000,
53
+ );
54
+ return hasMeaningfulTitleText(visible) ? visible : '';
55
+ }
56
+
57
+ export function firstTurnTitleSource(prompt) {
58
+ const raw = sessionMessageText(prompt);
59
+ if (!raw || isSessionPreviewNoise(raw)) return '';
60
+ const visible = cleanSessionPreview(raw, 4_000);
61
+ return hasMeaningfulTitleText(visible) ? visible : '';
62
+ }
63
+
64
+ /** The first three COMPLETED human exchanges. Tool calls/results, system rows,
65
+ * reasoning, injected context and intermediate assistant preambles are
66
+ * excluded; only the final visible assistant text before the next user stays.
67
+ * A session that moved past turn three (e.g. because an earlier attempt timed
68
+ * out) still titles from its first three exchanges instead of never. */
69
+ export function thirdTurnTitleSource(messages) {
70
+ const turns = [];
71
+ let current = null;
72
+ for (const message of Array.isArray(messages) ? messages : []) {
73
+ const role = String(message?.role || '').toLowerCase();
74
+ if (role !== 'user' && role !== 'assistant') continue;
75
+ const text = titleMessageText(message, role);
76
+ if (!text) continue;
77
+ if (role === 'user') {
78
+ if (current) turns.push(current);
79
+ current = { user: text, assistant: '' };
80
+ } else if (current) {
81
+ current.assistant = text;
82
+ }
83
+ }
84
+ if (current) turns.push(current);
85
+ const completed = turns.filter((turn) => turn.user && turn.assistant);
86
+ if (completed.length < 3) return '';
87
+ return completed
88
+ .slice(0, 3)
89
+ .flatMap((turn) => [`User: ${turn.user}`, `Assistant: ${turn.assistant}`])
90
+ .join('\n');
91
+ }
92
+
93
+ function greetingTitle(source) {
94
+ const normalized = String(source || '').toLocaleLowerCase()
95
+ .replace(/[^\p{L}\p{N}]+/gu, '');
96
+ if (KOREAN_GREETING_TITLE.has(normalized)) return '인사';
97
+ if (ENGLISH_GREETING_TITLE.has(normalized)) return 'Greeting';
98
+ return '';
99
+ }
100
+
101
+ export function resolvedSystemLocale() {
102
+ try {
103
+ return Intl.DateTimeFormat().resolvedOptions().locale || '';
104
+ } catch {
105
+ return '';
106
+ }
107
+ }
108
+
109
+ /** Shared backend controller used by every lead surface (TUI and desktop). */
110
+ export function createSessionTitleController(deps = {}) {
111
+ const firstAttempts = new Set();
112
+ const thirdAttempts = new Set();
113
+ const active = new Map();
114
+ const timeoutMs = Number.isFinite(Number(deps.timeoutMs))
115
+ ? Math.max(1, Number(deps.timeoutMs))
116
+ : SESSION_TITLE_TIMEOUT_MS;
117
+ let disposed = false;
118
+
119
+ const log = (line) => {
120
+ const message = `[mixdog] llm-title ${line}`;
121
+ try { deps.log?.(message); } catch {}
122
+ if (!deps.log) {
123
+ try { process.stderr.write(`${message}\n`); } catch {}
124
+ }
125
+ try {
126
+ const root = String(deps.dataRoot?.() || '');
127
+ if (root) void appendFile(join(root, 'llm-title.log'), `${new Date().toISOString()} ${line}\n`, 'utf8')
128
+ .catch(() => undefined);
129
+ } catch { /* diagnostics must never break titling */ }
130
+ };
131
+
132
+ const promote = async (sessionId, title, stage) => {
133
+ if (disposed || !title) return false;
134
+ return await deps.promoteGeneratedTitle?.(sessionId, title, stage) === true;
135
+ };
136
+
137
+ const generate = async (sessionId, source, stage) => {
138
+ const abort = new AbortController();
139
+ const key = `${sessionId}:${stage}`;
140
+ active.set(key, abort);
141
+ let timer = null;
142
+ try {
143
+ const timeout = new Promise((_, reject) => {
144
+ timer = setTimeout(() => {
145
+ const error = new Error('Session title generation timed out.');
146
+ abort.abort(error);
147
+ reject(error);
148
+ }, timeoutMs);
149
+ timer.unref?.();
150
+ });
151
+ const raw = await Promise.race([
152
+ Promise.resolve().then(async () => {
153
+ const complete = deps.generateSessionTitle
154
+ || (await import('../runtime/agent/orchestrator/agent-runtime/title-completion.mjs'))
155
+ .generateSessionTitle;
156
+ if (disposed) return '';
157
+ return complete(source, {
158
+ signal: abort.signal,
159
+ locale: String(deps.systemLocale?.() || resolvedSystemLocale()),
160
+ });
161
+ }),
162
+ timeout,
163
+ ]);
164
+ const title = compactTitle(raw);
165
+ log(`generated id=${sessionId} stage=${stage} title=${JSON.stringify(title)}`);
166
+ if (title) await promote(sessionId, title, stage);
167
+ } finally {
168
+ if (timer) clearTimeout(timer);
169
+ if (active.get(key) === abort) active.delete(key);
170
+ }
171
+ };
172
+
173
+ const run = (sessionId, source, stage, attempts) => {
174
+ log(`start id=${sessionId} stage=${stage} chars=${source.length}`);
175
+ void generate(sessionId, source, stage).catch((error) => {
176
+ // Release the one-shot marker: a timed-out/failed generation may retry
177
+ // on the next trigger (next completed turn for stage three).
178
+ attempts?.delete(sessionId);
179
+ log(`failed id=${sessionId} stage=${stage} error=${error instanceof Error ? (error.stack || error.message) : String(error)}`);
180
+ });
181
+ };
182
+
183
+ function scheduleFirst(session, prompt) {
184
+ const sessionId = String(session?.id || '');
185
+ if (disposed || !sessionId || firstAttempts.has(sessionId)
186
+ || session?.titleLocked === true
187
+ || session?.generatedTitleStage === 'first' || session?.generatedTitleStage === 'third') return false;
188
+ const priorMeaningfulUser = (Array.isArray(session?.messages) ? session.messages : [])
189
+ .some((message) => message?.role === 'user' && titleMessageText(message, 'user'));
190
+ if (priorMeaningfulUser) return false;
191
+ const source = firstTurnTitleSource(prompt);
192
+ if (!source) return false;
193
+ firstAttempts.add(sessionId);
194
+ const greeting = greetingTitle(source);
195
+ if (greeting) {
196
+ log(`generated id=${sessionId} stage=first title=${JSON.stringify(greeting)} deterministic=greeting`);
197
+ void promote(sessionId, greeting, 'first').catch((error) => {
198
+ firstAttempts.delete(sessionId);
199
+ log(`failed id=${sessionId} stage=first error=${error instanceof Error ? (error.stack || error.message) : String(error)}`);
200
+ });
201
+ return true;
202
+ }
203
+ run(sessionId, source, 'first', firstAttempts);
204
+ return true;
205
+ }
206
+
207
+ function observeThird(session) {
208
+ const sessionId = String(session?.id || '');
209
+ if (disposed || !sessionId || thirdAttempts.has(sessionId)
210
+ || session?.titleLocked === true
211
+ || session?.generatedTitleStage === 'third') return false;
212
+ const source = thirdTurnTitleSource(session?.messages);
213
+ if (!source) return false;
214
+ thirdAttempts.add(sessionId);
215
+ run(sessionId, source, 'third', thirdAttempts);
216
+ return true;
217
+ }
218
+
219
+ function disposeAll() {
220
+ disposed = true;
221
+ for (const abort of active.values()) {
222
+ abort.abort(new Error('Session title generation disposed.'));
223
+ }
224
+ active.clear();
225
+ }
226
+
227
+ return { scheduleFirst, observeThird, disposeAll };
228
+ }
@@ -32,18 +32,18 @@ export function createSessionTurnApi(deps) {
32
32
  const {
33
33
  getSession, setSession, getCurrentCwd, getMode, setMode,
34
34
  getActiveTurnCount, setActiveTurnCount, isFirstTurnCompleted, setFirstTurnCompleted,
35
- getCodeGraphFirstTurnPrewarmDone, setCodeGraphFirstTurnPrewarmDone, codeGraphPrewarmLazy,
35
+ getCodeGraphFirstTurnPrewarmDone, setCodeGraphFirstTurnPrewarmDone,
36
36
  getRemoteEnabled, getCloseRequested,
37
37
  getPendingSessionReset, setPendingSessionReset,
38
38
  getTranscriptWriter, getTwKey, getLastAppendedAssistant, setLastAppendedAssistant,
39
- scheduleCodeGraphPrewarm, refreshSessionForCwdIfNeeded, createCurrentSession,
39
+ scheduleCodeGraphPrewarm, scheduleToolRuntimeWarmup, refreshSessionForCwdIfNeeded, createCurrentSession,
40
40
  ensureRemoteTranscriptWriter, channelsEnabled, invokeChannelStart, channels,
41
41
  pushTranscriptRebind, flushPendingTranscriptRebind,
42
42
  hooks, hookCommonPayload, mgr, notifyFnForSession, bootProfile,
43
43
  scheduleProviderWarmup, scheduleProviderModelWarmup, invalidateContextStatusCache,
44
44
  agentTool, recreateCurrentSessionIfReady, invalidatePreSessionToolSurface,
45
45
  activeToolSurface, applyResolvedCwd, resolveCwdPath, agentStatusState, notificationListeners,
46
- awaitInitialMcpConnect, awaitRoutePreparation,
46
+ awaitInitialMcpConnect, awaitRoutePreparation, sessionTitles,
47
47
  } = deps;
48
48
  const enqueueRemoteAttachedPrompt = (prompt) => {
49
49
  const attachedSession = getSession();
@@ -89,11 +89,13 @@ export function createSessionTurnApi(deps) {
89
89
  // actual turn waits, guaranteeing that it cannot run on a stale route.
90
90
  await awaitRoutePreparation?.();
91
91
  setActiveTurnCount(getActiveTurnCount() + 1);
92
- // Lazy code-graph prewarm: kick off the build ONCE, on the first real
93
- // turn, so a likely code lookup hits a warm cache.
94
- if (codeGraphPrewarmLazy && !getCodeGraphFirstTurnPrewarmDone()) {
92
+ // Heavy runtime warmup is one-shot and demand-driven: idle desktop panes
93
+ // never spawn shell/token/shard helpers or a code-graph worker.
94
+ if (typeof getCodeGraphFirstTurnPrewarmDone === 'function'
95
+ && !getCodeGraphFirstTurnPrewarmDone()) {
95
96
  setCodeGraphFirstTurnPrewarmDone(true);
96
- scheduleCodeGraphPrewarm(0, 'first-turn');
97
+ scheduleToolRuntimeWarmup?.(0);
98
+ scheduleCodeGraphPrewarm?.(0, 'first-turn');
97
99
  }
98
100
  const startedAt = Date.now();
99
101
  try {
@@ -128,6 +130,7 @@ export function createSessionTurnApi(deps) {
128
130
  }
129
131
  }
130
132
  const session0 = getSession();
133
+ try { sessionTitles?.scheduleFirst(session0, prompt); } catch { /* title fallback stays the preview */ }
131
134
  // Turn-review boundary: start a fresh session+turn generation. Lead
132
135
  // patches remain transcript-derived; worker apply_patch diffs bind to
133
136
  // this generation and cannot leak into the next turn/session.
@@ -257,6 +260,7 @@ export function createSessionTurnApi(deps) {
257
260
  },
258
261
  );
259
262
  setSession(mgr.getSession(session0.id) || getSession());
263
+ try { sessionTitles?.observeThird(getSession()); } catch { /* title refresh is best-effort */ }
260
264
  if (getRemoteEnabled() && getTranscriptWriter()) {
261
265
  try {
262
266
  const finalText = result?.content != null ? String(result.content) : '';
@@ -385,6 +385,22 @@ export function createWorkflowAgentsApi(deps) {
385
385
  ? `agent "${id}" has no user override to reset`
386
386
  : `agent "${id}" not found`);
387
387
  }
388
+ // Custom definitions are hard references from explicit workflow agent
389
+ // lists. Refuse deletion instead of leaving a pack that fails only when
390
+ // it next tries to delegate.
391
+ if (!builtIn) {
392
+ const workflowNames = listWorkflowPacks(dataDir)
393
+ .filter((workflow) => workflow.agentsConfigured === true
394
+ && Array.isArray(workflow.agents)
395
+ && workflow.agents.includes(id))
396
+ .map((workflow) => workflow.name || workflow.id);
397
+ if (workflowNames.length) {
398
+ throw new Error(
399
+ `agent "${id}" is used by ${workflowNames.length === 1 ? 'workflow' : 'workflows'}: `
400
+ + `${workflowNames.join(', ')}. Remove it from those workflows before deleting it`,
401
+ );
402
+ }
403
+ }
388
404
  rmSync(dir, { recursive: true, force: true });
389
405
  clearAgentDefinitionCache(id);
390
406
  const revertedToBuiltIn = Boolean(loadAgentDefinition(dataDir, id));
@@ -12,12 +12,14 @@ import { isHiddenAgent } from '../runtime/agent/orchestrator/internal-agents.mjs
12
12
 
13
13
  export const WORKFLOW_ROUTE_SLOTS = ['lead', 'agent', 'explorer', 'memory'];
14
14
  export const FIXED_AGENT_SLOTS = Object.freeze([
15
- { id: 'explore', label: 'Explore', description: 'Broad repository exploration', workflowSlot: 'explorer' },
16
- { id: 'maintainer', label: 'Maintainer', description: 'Background memory and upkeep', workflowSlot: 'memory' },
15
+ // Short one-liners on purpose: these render inside the 260px sidebar rail
16
+ // (user: 창이 크지 않으니 설명은 짧게).
17
+ { id: 'explore', label: 'Explore', description: 'Repository exploration', workflowSlot: 'explorer' },
18
+ { id: 'maintainer', label: 'Maintainer', description: 'Memory and upkeep', workflowSlot: 'memory' },
17
19
  { id: 'worker', label: 'Worker', description: 'Scoped implementation' },
18
- { id: 'heavy-worker', label: 'Heavy Worker', description: 'Broad or multi-file implementation' },
19
- { id: 'reviewer', label: 'Reviewer', description: 'Diff review and risk checks' },
20
- { id: 'debugger', label: 'Debugger', description: 'Root-cause analysis and failure tracing' },
20
+ { id: 'heavy-worker', label: 'Heavy Worker', description: 'Multi-file implementation' },
21
+ { id: 'reviewer', label: 'Reviewer', description: 'Diff and risk review' },
22
+ { id: 'debugger', label: 'Debugger', description: 'Root-cause debugging' },
21
23
  ]);
22
24
  const AGENT_ROLE_IDS = new Set(FIXED_AGENT_SLOTS.map((agent) => agent.id));
23
25
  export const DEFAULT_WORKFLOW_ID = 'default';