@prestyj/cli 5.2.0 → 5.3.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.
Files changed (192) hide show
  1. package/dist/app-sidecar.js +856 -91
  2. package/dist/app-sidecar.js.map +1 -1
  3. package/dist/core/agent-session-compaction.test.js +89 -0
  4. package/dist/core/agent-session-compaction.test.js.map +1 -1
  5. package/dist/core/agent-session-queue.test.d.ts +2 -0
  6. package/dist/core/agent-session-queue.test.d.ts.map +1 -0
  7. package/dist/core/agent-session-queue.test.js +122 -0
  8. package/dist/core/agent-session-queue.test.js.map +1 -0
  9. package/dist/core/agent-session.d.ts +79 -3
  10. package/dist/core/agent-session.d.ts.map +1 -1
  11. package/dist/core/agent-session.js +268 -47
  12. package/dist/core/agent-session.js.map +1 -1
  13. package/dist/core/autopilot-cycle.d.ts +119 -0
  14. package/dist/core/autopilot-cycle.d.ts.map +1 -0
  15. package/dist/core/autopilot-cycle.js +119 -0
  16. package/dist/core/autopilot-cycle.js.map +1 -0
  17. package/dist/core/autopilot-cycle.test.d.ts +2 -0
  18. package/dist/core/autopilot-cycle.test.d.ts.map +1 -0
  19. package/dist/core/autopilot-cycle.test.js +375 -0
  20. package/dist/core/autopilot-cycle.test.js.map +1 -0
  21. package/dist/core/autopilot-gate.d.ts +109 -0
  22. package/dist/core/autopilot-gate.d.ts.map +1 -0
  23. package/dist/core/autopilot-gate.js +205 -0
  24. package/dist/core/autopilot-gate.js.map +1 -0
  25. package/dist/core/autopilot-gate.test.d.ts +2 -0
  26. package/dist/core/autopilot-gate.test.d.ts.map +1 -0
  27. package/dist/core/autopilot-gate.test.js +295 -0
  28. package/dist/core/autopilot-gate.test.js.map +1 -0
  29. package/dist/core/autopilot-verdict.d.ts +20 -2
  30. package/dist/core/autopilot-verdict.d.ts.map +1 -1
  31. package/dist/core/autopilot-verdict.js +94 -3
  32. package/dist/core/autopilot-verdict.js.map +1 -1
  33. package/dist/core/autopilot-verdict.test.js +73 -0
  34. package/dist/core/autopilot-verdict.test.js.map +1 -1
  35. package/dist/core/bash-spawn-benchmark.d.ts +2 -0
  36. package/dist/core/bash-spawn-benchmark.d.ts.map +1 -0
  37. package/dist/core/bash-spawn-benchmark.js +139 -0
  38. package/dist/core/bash-spawn-benchmark.js.map +1 -0
  39. package/dist/core/hashline-edit-benchmark.d.ts +33 -1
  40. package/dist/core/hashline-edit-benchmark.d.ts.map +1 -1
  41. package/dist/core/hashline-edit-benchmark.js +193 -21
  42. package/dist/core/hashline-edit-benchmark.js.map +1 -1
  43. package/dist/core/hashline-edit-benchmark.test.js +51 -2
  44. package/dist/core/hashline-edit-benchmark.test.js.map +1 -1
  45. package/dist/core/json-mode-flag-parity.test.d.ts +2 -0
  46. package/dist/core/json-mode-flag-parity.test.d.ts.map +1 -0
  47. package/dist/core/json-mode-flag-parity.test.js +66 -0
  48. package/dist/core/json-mode-flag-parity.test.js.map +1 -0
  49. package/dist/core/mcp/deferred-catalog.d.ts +28 -0
  50. package/dist/core/mcp/deferred-catalog.d.ts.map +1 -0
  51. package/dist/core/mcp/deferred-catalog.js +72 -0
  52. package/dist/core/mcp/deferred-catalog.js.map +1 -0
  53. package/dist/core/mcp/resolve-stdio.d.ts +19 -3
  54. package/dist/core/mcp/resolve-stdio.d.ts.map +1 -1
  55. package/dist/core/mcp/resolve-stdio.js +136 -5
  56. package/dist/core/mcp/resolve-stdio.js.map +1 -1
  57. package/dist/core/mcp/resolve-stdio.test.js +82 -1
  58. package/dist/core/mcp/resolve-stdio.test.js.map +1 -1
  59. package/dist/core/nolan-context.d.ts +43 -2
  60. package/dist/core/nolan-context.d.ts.map +1 -1
  61. package/dist/core/nolan-context.js +91 -8
  62. package/dist/core/nolan-context.js.map +1 -1
  63. package/dist/core/nolan-context.test.js +167 -5
  64. package/dist/core/nolan-context.test.js.map +1 -1
  65. package/dist/core/nolan-model.d.ts +46 -0
  66. package/dist/core/nolan-model.d.ts.map +1 -0
  67. package/dist/core/nolan-model.js +30 -0
  68. package/dist/core/nolan-model.js.map +1 -0
  69. package/dist/core/nolan-model.test.d.ts +2 -0
  70. package/dist/core/nolan-model.test.d.ts.map +1 -0
  71. package/dist/core/nolan-model.test.js +51 -0
  72. package/dist/core/nolan-model.test.js.map +1 -0
  73. package/dist/core/nolan-prompt.d.ts +5 -18
  74. package/dist/core/nolan-prompt.d.ts.map +1 -1
  75. package/dist/core/nolan-prompt.js +112 -19
  76. package/dist/core/nolan-prompt.js.map +1 -1
  77. package/dist/core/nolan-prompt.test.d.ts +2 -0
  78. package/dist/core/nolan-prompt.test.d.ts.map +1 -0
  79. package/dist/core/nolan-prompt.test.js +138 -0
  80. package/dist/core/nolan-prompt.test.js.map +1 -0
  81. package/dist/core/persistent-shell.d.ts +27 -0
  82. package/dist/core/persistent-shell.d.ts.map +1 -0
  83. package/dist/core/persistent-shell.js +150 -0
  84. package/dist/core/persistent-shell.js.map +1 -0
  85. package/dist/core/persistent-shell.test.d.ts +2 -0
  86. package/dist/core/persistent-shell.test.d.ts.map +1 -0
  87. package/dist/core/persistent-shell.test.js +84 -0
  88. package/dist/core/persistent-shell.test.js.map +1 -0
  89. package/dist/core/process-manager-dev-server-repro.test.js +34 -6
  90. package/dist/core/process-manager-dev-server-repro.test.js.map +1 -1
  91. package/dist/core/progress/engine.d.ts +23 -0
  92. package/dist/core/progress/engine.d.ts.map +1 -0
  93. package/dist/core/progress/engine.js +131 -0
  94. package/dist/core/progress/engine.js.map +1 -0
  95. package/dist/core/progress/engine.test.d.ts +2 -0
  96. package/dist/core/progress/engine.test.d.ts.map +1 -0
  97. package/dist/core/progress/engine.test.js +136 -0
  98. package/dist/core/progress/engine.test.js.map +1 -0
  99. package/dist/core/progress/git-xp.d.ts +16 -0
  100. package/dist/core/progress/git-xp.d.ts.map +1 -0
  101. package/dist/core/progress/git-xp.js +106 -0
  102. package/dist/core/progress/git-xp.js.map +1 -0
  103. package/dist/core/progress/git-xp.test.d.ts +2 -0
  104. package/dist/core/progress/git-xp.test.d.ts.map +1 -0
  105. package/dist/core/progress/git-xp.test.js +88 -0
  106. package/dist/core/progress/git-xp.test.js.map +1 -0
  107. package/dist/core/progress/ranks.d.ts +21 -0
  108. package/dist/core/progress/ranks.d.ts.map +1 -0
  109. package/dist/core/progress/ranks.js +141 -0
  110. package/dist/core/progress/ranks.js.map +1 -0
  111. package/dist/core/progress/ranks.test.d.ts +2 -0
  112. package/dist/core/progress/ranks.test.d.ts.map +1 -0
  113. package/dist/core/progress/ranks.test.js +59 -0
  114. package/dist/core/progress/ranks.test.js.map +1 -0
  115. package/dist/core/progress/rebuild.d.ts +7 -0
  116. package/dist/core/progress/rebuild.d.ts.map +1 -0
  117. package/dist/core/progress/rebuild.js +106 -0
  118. package/dist/core/progress/rebuild.js.map +1 -0
  119. package/dist/core/progress/rebuild.test.d.ts +2 -0
  120. package/dist/core/progress/rebuild.test.d.ts.map +1 -0
  121. package/dist/core/progress/rebuild.test.js +72 -0
  122. package/dist/core/progress/rebuild.test.js.map +1 -0
  123. package/dist/core/progress/store.d.ts +35 -0
  124. package/dist/core/progress/store.d.ts.map +1 -0
  125. package/dist/core/progress/store.js +200 -0
  126. package/dist/core/progress/store.js.map +1 -0
  127. package/dist/core/progress/store.test.d.ts +2 -0
  128. package/dist/core/progress/store.test.d.ts.map +1 -0
  129. package/dist/core/progress/store.test.js +108 -0
  130. package/dist/core/progress/store.test.js.map +1 -0
  131. package/dist/core/progress/types.d.ts +108 -0
  132. package/dist/core/progress/types.d.ts.map +1 -0
  133. package/dist/core/progress/types.js +3 -0
  134. package/dist/core/progress/types.js.map +1 -0
  135. package/dist/core/project-discovery.d.ts.map +1 -1
  136. package/dist/core/project-discovery.js +40 -9
  137. package/dist/core/project-discovery.js.map +1 -1
  138. package/dist/core/project-discovery.test.d.ts +2 -0
  139. package/dist/core/project-discovery.test.d.ts.map +1 -0
  140. package/dist/core/project-discovery.test.js +104 -0
  141. package/dist/core/project-discovery.test.js.map +1 -0
  142. package/dist/core/session-history.d.ts +51 -0
  143. package/dist/core/session-history.d.ts.map +1 -0
  144. package/dist/core/session-history.js +156 -0
  145. package/dist/core/session-history.js.map +1 -0
  146. package/dist/core/session-history.test.d.ts +2 -0
  147. package/dist/core/session-history.test.d.ts.map +1 -0
  148. package/dist/core/session-history.test.js +101 -0
  149. package/dist/core/session-history.test.js.map +1 -0
  150. package/dist/core/session-manager.d.ts +34 -0
  151. package/dist/core/session-manager.d.ts.map +1 -1
  152. package/dist/core/session-manager.js +67 -0
  153. package/dist/core/session-manager.js.map +1 -1
  154. package/dist/core/session-manager.test.js +140 -1
  155. package/dist/core/session-manager.test.js.map +1 -1
  156. package/dist/core/settings-manager.d.ts +1 -0
  157. package/dist/core/settings-manager.d.ts.map +1 -1
  158. package/dist/core/settings-manager.js +4 -0
  159. package/dist/core/settings-manager.js.map +1 -1
  160. package/dist/core/speed-benchmark.test.js +2 -3
  161. package/dist/core/speed-benchmark.test.js.map +1 -1
  162. package/dist/system-prompt.d.ts.map +1 -1
  163. package/dist/system-prompt.js +12 -8
  164. package/dist/system-prompt.js.map +1 -1
  165. package/dist/system-prompt.test.js +15 -20
  166. package/dist/system-prompt.test.js.map +1 -1
  167. package/dist/tools/bash.d.ts +1 -0
  168. package/dist/tools/bash.d.ts.map +1 -1
  169. package/dist/tools/bash.js +27 -2
  170. package/dist/tools/bash.js.map +1 -1
  171. package/dist/tools/edit.d.ts +9 -2
  172. package/dist/tools/edit.d.ts.map +1 -1
  173. package/dist/tools/edit.js +91 -10
  174. package/dist/tools/edit.js.map +1 -1
  175. package/dist/tools/edit.test.js +97 -0
  176. package/dist/tools/edit.test.js.map +1 -1
  177. package/dist/tools/plan-mode.test.js +25 -0
  178. package/dist/tools/plan-mode.test.js.map +1 -1
  179. package/dist/tools/prompt-hints.d.ts.map +1 -1
  180. package/dist/tools/prompt-hints.js +3 -0
  181. package/dist/tools/prompt-hints.js.map +1 -1
  182. package/dist/tools/subagent.d.ts.map +1 -1
  183. package/dist/tools/subagent.js +24 -1
  184. package/dist/tools/subagent.js.map +1 -1
  185. package/dist/tools/tool-search.d.ts +15 -0
  186. package/dist/tools/tool-search.d.ts.map +1 -0
  187. package/dist/tools/tool-search.js +35 -0
  188. package/dist/tools/tool-search.js.map +1 -0
  189. package/dist/ui/hooks/useAgentLoop.d.ts.map +1 -1
  190. package/dist/ui/hooks/useAgentLoop.js +22 -9
  191. package/dist/ui/hooks/useAgentLoop.js.map +1 -1
  192. package/package.json +5 -5
@@ -8,7 +8,7 @@ import { SettingsManager } from "./settings-manager.js";
8
8
  import { AuthStorage } from "./auth-storage.js";
9
9
  import { getClaudeCliUserAgent } from "./claude-code-version.js";
10
10
  import { kimiCodingHeaders, isKimiCodingEndpoint } from "./oauth/kimi.js";
11
- import { SessionManager, NOLAN_TURN_CUSTOM_KIND, } from "./session-manager.js";
11
+ import { SessionManager, NOLAN_TURN_CUSTOM_KIND, AUTOPILOT_MARKER_CUSTOM_KIND, APP_MARKER_CUSTOM_KIND, } from "./session-manager.js";
12
12
  import { ExtensionLoader } from "./extensions/loader.js";
13
13
  import { shouldCompact, compact, getCompactionReserveTokens } from "./compaction/compactor.js";
14
14
  import { getAuthStorageKeys, getContextWindow, getModel, MODELS } from "./model-registry.js";
@@ -17,6 +17,8 @@ import { ensureAppDirs } from "../config.js";
17
17
  import { buildSystemPrompt } from "../system-prompt.js";
18
18
  import { createTools, createWebSearchTool, } from "../tools/index.js";
19
19
  import { MCPClientManager, getAllMcpServers } from "./mcp/index.js";
20
+ import { DeferredToolCatalog } from "./mcp/deferred-catalog.js";
21
+ import { createToolSearchTool } from "../tools/tool-search.js";
20
22
  import { log } from "./logger.js";
21
23
  import { setEstimatorModel } from "./compaction/token-estimator.js";
22
24
  import { discoverAgents } from "./agents.js";
@@ -45,6 +47,17 @@ export class AgentSession {
45
47
  // transcript. Each carries the non-system message count at record time so the
46
48
  // webview can interleave them chronologically.
47
49
  nolanTurns = [];
50
+ // Autopilot Nolan (auto-reviewer) markers recorded against this build session:
51
+ // the review verdict shown in the transcript (prompted / done / human /
52
+ // capped). Same not-on-the-DAG treatment as nolanTurns — advisory only,
53
+ // persisted + reloaded so a resumed session shows the identical Nolan bubble
54
+ // the live run showed instead of dropping it or replaying a raw verdict.
55
+ autopilotMarkers = [];
56
+ // Generic app transcript markers (plan-mode banner, task header, error rows,
57
+ // user-bubble display hints). Same not-on-the-DAG treatment as nolanTurns —
58
+ // display only, persisted + reloaded so a resumed session shows the same
59
+ // transcript rows the live run showed.
60
+ appMarkers = [];
48
61
  tools = [];
49
62
  /** Rebuilds the read tool for a new model (video byte cap is baked in at
50
63
  * creation). Called from switchModel so video-capable models get the
@@ -87,6 +100,8 @@ export class AgentSession {
87
100
  processManager;
88
101
  lspManager;
89
102
  mcpManager;
103
+ /** Deferred MCP tools awaiting discovery via tool_search (bench A win). */
104
+ mcpCatalog;
90
105
  provider;
91
106
  model;
92
107
  cwd;
@@ -352,7 +367,7 @@ export class AgentSession {
352
367
  const mcpTools = this.opts.allowedTools
353
368
  ? connected.filter((t) => this.isToolAllowed(t.name))
354
369
  : connected;
355
- this.tools.push(...mcpTools);
370
+ this.addMcpTools(mcpTools);
356
371
  // Background connect resolves AFTER initialize() has already built the
357
372
  // system prompt (the default path awaits this before buildSystemPrompt,
358
373
  // so its prompt already lists the tools). Refresh messages[0] so the
@@ -369,6 +384,31 @@ export class AgentSession {
369
384
  log("WARN", "mcp", `MCP initialization failed: ${err instanceof Error ? err.message : String(err)}`);
370
385
  }
371
386
  }
387
+ /**
388
+ * Route freshly connected MCP tools: deferred into the tool_search catalog
389
+ * (default — keeps ~8k tokens of schema out of every cache-miss turn, see
390
+ * bench/RESULTS.md bench A) or pushed eagerly when the user opted out.
391
+ * Allow-listed sessions (Nolan) always get the eager path — their fixed tool
392
+ * expectations predate the catalog, and tool_search isn't allow-listed.
393
+ * Promotion pushes onto the live `this.tools` array the running agent loop
394
+ * re-reads every turn, so promoted tools are callable on the next step.
395
+ */
396
+ addMcpTools(mcpTools) {
397
+ if (mcpTools.length === 0)
398
+ return;
399
+ const defer = !this.opts.allowedTools && this.settingsManager.get("deferredMcpTools");
400
+ if (!defer) {
401
+ this.tools.push(...mcpTools);
402
+ return;
403
+ }
404
+ this.mcpCatalog ??= new DeferredToolCatalog();
405
+ this.mcpCatalog.add(mcpTools);
406
+ if (!this.tools.some((t) => t.name === "tool_search")) {
407
+ this.tools.push(createToolSearchTool(this.mcpCatalog, (promoted) => {
408
+ this.tools.push(...promoted);
409
+ }));
410
+ }
411
+ }
372
412
  /**
373
413
  * Process user input. Handles slash commands or runs agent loop.
374
414
  */
@@ -579,22 +619,23 @@ export class AgentSession {
579
619
  // agent sees them mid-loop instead of after it stops.
580
620
  if (this.userQueue.length > 0) {
581
621
  const queued = this.userQueue.splice(0);
582
- // Frame the queued text as concurrent steering — without this wrapper the
583
- // model treats a mid-run message as a fresh request that supersedes the
584
- // original task and silently drops it.
585
- // Plain-text-only queue: keep the simple merged-string message.
586
- if (queued.every((m) => m.attachments.length === 0)) {
587
- const merged = queued.map((m) => m.text).join("\n\n");
588
- return [{ role: "user", content: wrapSteeringText(merged) }];
589
- }
590
- // Any queued attachments → deliver one user message with text + media
591
- // blocks built the same way as a non-queued attachment prompt.
592
- const parts = [
593
- { type: "text", text: STEERING_PREFIX },
594
- ];
595
- for (const m of queued)
596
- parts.push(...this.buildAttachmentParts(m.text, m.attachments));
597
- return [{ role: "user", content: parts }];
622
+ // Frame each queued item as concurrent steering — without this wrapper
623
+ // the model treats a mid-run message as a fresh request that supersedes
624
+ // the original task and silently drops it. ONE message per queued item
625
+ // (not merged): each persists as its own user message, so a resumed
626
+ // session shows the same number of bubbles the live run did.
627
+ return queued.map((m) => {
628
+ if (m.attachments.length === 0) {
629
+ return { role: "user", content: wrapSteeringText(m.text) };
630
+ }
631
+ // Queued attachments ride the same native-block path as a non-queued
632
+ // attachment prompt, prefixed with the steering framing.
633
+ const parts = [
634
+ { type: "text", text: STEERING_PREFIX },
635
+ ...this.buildAttachmentParts(m.text, m.attachments),
636
+ ];
637
+ return { role: "user", content: parts };
638
+ });
598
639
  }
599
640
  if (!this.settingsManager.get("idealReviewEnabled"))
600
641
  return null;
@@ -840,7 +881,11 @@ export class AgentSession {
840
881
  // Use getAllMcpServers so user-configured servers survive the reconnect.
841
882
  const servers = await getAllMcpServers(this.provider, apiKey, this.cwd);
842
883
  const mcpTools = await this.mcpManager.connectAll(servers);
843
- this.tools.push(...mcpTools);
884
+ // Drop stale MCP tools from both the live set and deferred catalog before
885
+ // re-adding. Some tools may already have been promoted out of the catalog.
886
+ this.tools = this.tools.filter((t) => !t.name.startsWith("mcp__"));
887
+ this.mcpCatalog?.removeWhere((name) => name.startsWith("mcp__"));
888
+ this.addMcpTools(mcpTools);
844
889
  }
845
890
  catch (err) {
846
891
  log("WARN", "mcp", `MCP reconnection failed: ${err instanceof Error ? err.message : String(err)}`);
@@ -869,20 +914,39 @@ export class AgentSession {
869
914
  signal: this.opts.signal,
870
915
  });
871
916
  this.messages = result.messages;
872
- // Persist compacted messages to a new session file so `ezcoder continue`
873
- // picks up the compacted state instead of the full original history.
874
- const session = await this.sessionManager.create(this.cwd, this.provider, this.model);
875
- this.sessionId = session.id;
876
- this.sessionPath = session.path;
877
- // Write compacted messages (skip system it's rebuilt on load)
878
- for (const msg of this.messages) {
879
- if (msg.role === "system")
880
- continue;
881
- await this.persistMessage(msg);
917
+ // Transient sessions (Nolan chat/autopilot, subagent spawns) must NEVER touch
918
+ // the session store: without this guard, the first auto-compaction called
919
+ // sessionManager.create() and assigned a real sessionPath, silently turning
920
+ // the "in-memory only" session into a persisted one — every later turn (and
921
+ // every further compaction) then leaked a Nolan transcript file into the
922
+ // project's session list. Compact in memory only and keep sessionPath empty.
923
+ if (this.opts.transient) {
924
+ this.lastPersistedIndex = this.messages.length;
925
+ }
926
+ else {
927
+ // Persist compacted messages to a new session file so `ezcoder continue`
928
+ // picks up the compacted state instead of the full original history.
929
+ const session = await this.sessionManager.create(this.cwd, this.provider, this.model);
930
+ this.sessionId = session.id;
931
+ this.sessionPath = session.path;
932
+ // Write compacted messages (skip system — it's rebuilt on load)
933
+ for (const msg of this.messages) {
934
+ if (msg.role === "system")
935
+ continue;
936
+ await this.persistMessage(msg);
937
+ }
938
+ this.lastPersistedIndex = this.messages.length;
939
+ // Carry Nolan's advisory turns into the new file so they survive compaction.
940
+ await this.rePersistNolanTurns();
941
+ await this.rePersistAutopilotMarkers();
942
+ await this.rePersistAppMarkers();
943
+ // Persist the compaction counts so a resumed session's quiet notice can
944
+ // show the same "N → M messages" summary the live run did.
945
+ await this.persistAppMarker("compaction", {
946
+ originalCount: result.result.originalCount,
947
+ newCount: result.result.newCount,
948
+ });
882
949
  }
883
- this.lastPersistedIndex = this.messages.length;
884
- // Carry Nolan's advisory turns into the new file so they survive compaction.
885
- await this.rePersistNolanTurns();
886
950
  this.eventBus.emit("compaction_end", {
887
951
  originalCount: result.result.originalCount,
888
952
  newCount: result.result.newCount,
@@ -892,10 +956,31 @@ export class AgentSession {
892
956
  // A fresh session drops any in-flight plan state so its prompt is clean.
893
957
  this.planModeRef.current = false;
894
958
  this.approvedPlanPath = undefined;
959
+ // Display-only history belongs to the OLD session. Without this, stale Nolan
960
+ // turns / autopilot verdicts / app markers linger in memory, show up in the
961
+ // new session's /history, and get re-persisted into the new file by the
962
+ // next compaction — the cross-session duplicate-marker propagation bug.
963
+ this.nolanTurns = [];
964
+ this.autopilotMarkers = [];
965
+ this.appMarkers = [];
895
966
  const basePrompt = this.customSystemPrompt ??
896
967
  (await buildSystemPrompt(this.cwd, this.skills, false, undefined, this.tools.map((tool) => tool.name), undefined, this.provider));
897
968
  this.messages = [{ role: "system", content: basePrompt }];
898
- await this.createNewSession();
969
+ // Fresh conversation — new entries must not chain onto the old DAG's leaf.
970
+ this.currentLeafId = null;
971
+ // Transient sessions (Nolan chat/autopilot, subagent spawns) never touch the
972
+ // session store. Without this guard, autopilot's per-cycle resetReviewer
973
+ // (nolanAutoSession.newSession()) created a real session file EVERY review
974
+ // cycle — the stream of 3-line "## Who you are … Nolan Grout" sessions that
975
+ // polluted the project's session list.
976
+ if (this.opts.transient) {
977
+ this.sessionId = "";
978
+ this.sessionPath = "";
979
+ this.lastPersistedIndex = this.messages.length;
980
+ }
981
+ else {
982
+ await this.createNewSession();
983
+ }
899
984
  this.eventBus.emit("session_start", { sessionId: this.sessionId });
900
985
  }
901
986
  async loadSession(sessionPath) {
@@ -970,6 +1055,13 @@ export class AgentSession {
970
1055
  getQueuedCount() {
971
1056
  return this.userQueue.length;
972
1057
  }
1058
+ /** Remove and return the oldest queued message (text + attachments), or null.
1059
+ * Used by the sidecar to run a message that queued while autopilot was
1060
+ * reviewing (no run in flight to steer it into) — unlike {@link drainQueue},
1061
+ * attachments survive so queued media isn't silently dropped. */
1062
+ takeNextQueuedMessage() {
1063
+ return this.userQueue.shift() ?? null;
1064
+ }
973
1065
  /** Clear the queue, returning the combined text (to restore to the composer).
974
1066
  * Queued attachments are dropped on cancel — the composer only restores text. */
975
1067
  drainQueue() {
@@ -1033,6 +1125,12 @@ export class AgentSession {
1033
1125
  getNolanTurns() {
1034
1126
  return this.nolanTurns;
1035
1127
  }
1128
+ /** Autopilot verdict markers recorded against this session, in record order.
1129
+ * Used by the host to interleave the auto-review loop's markers back into
1130
+ * the transcript on resume, mirroring `getNolanTurns`. */
1131
+ getAutopilotMarkers() {
1132
+ return this.autopilotMarkers;
1133
+ }
1036
1134
  /**
1037
1135
  * Record one Nolan Grout (mentor agent) turn against this build session: the
1038
1136
  * user's question + Nolan's reply. Kept in memory for the live transcript and
@@ -1078,6 +1176,103 @@ export class AgentSession {
1078
1176
  await this.sessionManager.appendEntry(this.sessionPath, entry);
1079
1177
  }
1080
1178
  }
1179
+ /**
1180
+ * Record one autopilot verdict marker (prompted / done / human / capped)
1181
+ * against this build session. Kept in memory for the live transcript and
1182
+ * persisted as a `custom` entry (parentId null, same as Nolan turns) so a
1183
+ * resumed session renders the exact same Nolan bubble the live run showed
1184
+ * instead of dropping the marker or falling back to a raw verdict string.
1185
+ * No-op persistence for transient sessions (kept in memory only).
1186
+ */
1187
+ async persistAutopilotMarker(phase, extra) {
1188
+ const afterMessageCount = this.messages.filter((m) => m.role !== "system").length;
1189
+ const payload = {
1190
+ version: 1,
1191
+ phase,
1192
+ afterMessageCount,
1193
+ ...(extra?.reason !== undefined ? { reason: extra.reason } : {}),
1194
+ ...(extra?.body !== undefined ? { body: extra.body } : {}),
1195
+ };
1196
+ this.autopilotMarkers.push(payload);
1197
+ if (!this.sessionPath)
1198
+ return;
1199
+ const entry = {
1200
+ type: "custom",
1201
+ kind: AUTOPILOT_MARKER_CUSTOM_KIND,
1202
+ id: crypto.randomUUID(),
1203
+ parentId: null,
1204
+ timestamp: new Date().toISOString(),
1205
+ data: payload,
1206
+ };
1207
+ await this.sessionManager.appendEntry(this.sessionPath, entry);
1208
+ }
1209
+ /** Re-append the in-memory autopilot markers to the current session file.
1210
+ * Mirrors `rePersistNolanTurns` — called after a continuation/compaction file
1211
+ * is created so the auto-review history survives the rewrite. */
1212
+ async rePersistAutopilotMarkers() {
1213
+ if (!this.sessionPath)
1214
+ return;
1215
+ for (const payload of this.autopilotMarkers) {
1216
+ const entry = {
1217
+ type: "custom",
1218
+ kind: AUTOPILOT_MARKER_CUSTOM_KIND,
1219
+ id: crypto.randomUUID(),
1220
+ parentId: null,
1221
+ timestamp: new Date().toISOString(),
1222
+ data: payload,
1223
+ };
1224
+ await this.sessionManager.appendEntry(this.sessionPath, entry);
1225
+ }
1226
+ }
1227
+ /** App transcript markers recorded against this session, in record order.
1228
+ * Used by the host to interleave display-only rows (plan banner, task
1229
+ * header, errors, user-bubble hints) back into the transcript on resume. */
1230
+ getAppMarkers() {
1231
+ return this.appMarkers;
1232
+ }
1233
+ /**
1234
+ * Record one app transcript marker (display-only row) against this session.
1235
+ * Same treatment as autopilot markers: kept in memory for the live
1236
+ * transcript, persisted as a `custom` entry (parentId null, never on the
1237
+ * message DAG) so a resumed session shows the identical row. `anchorOffset`
1238
+ * shifts the recorded `afterMessageCount` — pass +1 for a marker that should
1239
+ * attach to the user message about to be pushed by the imminent prompt.
1240
+ * No-op persistence for transient sessions.
1241
+ */
1242
+ async persistAppMarker(kind, data, anchorOffset = 0) {
1243
+ const afterMessageCount = this.messages.filter((m) => m.role !== "system").length + anchorOffset;
1244
+ const payload = { version: 1, kind, afterMessageCount, data };
1245
+ this.appMarkers.push(payload);
1246
+ if (!this.sessionPath)
1247
+ return;
1248
+ const entry = {
1249
+ type: "custom",
1250
+ kind: APP_MARKER_CUSTOM_KIND,
1251
+ id: crypto.randomUUID(),
1252
+ parentId: null,
1253
+ timestamp: new Date().toISOString(),
1254
+ data: payload,
1255
+ };
1256
+ await this.sessionManager.appendEntry(this.sessionPath, entry);
1257
+ }
1258
+ /** Re-append the in-memory app markers to the current session file. Mirrors
1259
+ * `rePersistNolanTurns` — called after a continuation/compaction file is
1260
+ * created so display-only rows survive the rewrite. */
1261
+ async rePersistAppMarkers() {
1262
+ if (!this.sessionPath)
1263
+ return;
1264
+ for (const payload of this.appMarkers) {
1265
+ const entry = {
1266
+ type: "custom",
1267
+ kind: APP_MARKER_CUSTOM_KIND,
1268
+ id: crypto.randomUUID(),
1269
+ parentId: null,
1270
+ timestamp: new Date().toISOString(),
1271
+ data: payload,
1272
+ };
1273
+ await this.sessionManager.appendEntry(this.sessionPath, entry);
1274
+ }
1275
+ }
1081
1276
  /**
1082
1277
  * Generate a short LLM session title from the conversation so far (first user
1083
1278
  * message + first assistant reply). Best-effort; returns null on failure or
@@ -1158,9 +1353,11 @@ export class AgentSession {
1158
1353
  setSignal(signal) {
1159
1354
  this.opts = { ...this.opts, signal };
1160
1355
  }
1161
- /** True when speedProfile is "optimized" (1-h cache TTL + pre-warm). */
1356
+ /** True when speedProfile is "optimized" (1-h cache TTL + pre-warm), or the
1357
+ * session was constructed with `forceLongCacheRetention` (Nolan sessions). */
1162
1358
  isSpeedOptimized() {
1163
- return this.settingsManager?.get("speedProfile") === "optimized";
1359
+ return (this.opts.forceLongCacheRetention === true ||
1360
+ this.settingsManager?.get("speedProfile") === "optimized");
1164
1361
  }
1165
1362
  /**
1166
1363
  * Ordered auth-storage keys the current (provider, model) pair tries, first
@@ -1240,6 +1437,10 @@ export class AgentSession {
1240
1437
  // Restore Nolan's advisory turns (custom entries, not on the message branch) so
1241
1438
  // they reappear in the transcript and survive into the continuation file.
1242
1439
  this.nolanTurns = this.sessionManager.getNolanTurns(loaded.entries);
1440
+ // Restore autopilot verdict markers the same way (not on the message DAG).
1441
+ this.autopilotMarkers = this.sessionManager.getAutopilotMarkers(loaded.entries);
1442
+ // Restore app transcript markers (plan banner / task header / errors / hints).
1443
+ this.appMarkers = this.sessionManager.getAppMarkers(loaded.entries);
1243
1444
  // Track the current leaf for subsequent entries
1244
1445
  this.currentLeafId = loaded.header.leafId;
1245
1446
  // Rebuild messages: keep system, add loaded
@@ -1275,20 +1476,40 @@ export class AgentSession {
1275
1476
  before: String(compacted.result.originalCount),
1276
1477
  after: String(compacted.result.newCount),
1277
1478
  });
1479
+ // Compaction rewrote history, so the on-disk file no longer reflects
1480
+ // what's in memory — fork a fresh session file for the compacted state
1481
+ // (mirrors compact()'s own persistence) so `ezcoder continue` picks up
1482
+ // the summary instead of the full original transcript.
1483
+ const session = await this.sessionManager.create(this.cwd, this.provider, this.model);
1484
+ this.sessionId = session.id;
1485
+ this.sessionPath = session.path;
1486
+ this.currentLeafId = null;
1487
+ // Re-persist (compacted) messages — skip system, it's rebuilt on load
1488
+ for (const msg of this.messages) {
1489
+ if (msg.role === "system")
1490
+ continue;
1491
+ await this.persistMessage(msg);
1492
+ }
1493
+ this.lastPersistedIndex = this.messages.length;
1494
+ // Carry Nolan's restored turns into the continuation file.
1495
+ await this.rePersistNolanTurns();
1496
+ await this.rePersistAutopilotMarkers();
1497
+ await this.rePersistAppMarkers();
1498
+ // Record this load-time auto-compaction's counts for the resumed notice.
1499
+ await this.persistAppMarker("compaction", {
1500
+ originalCount: compacted.result.originalCount,
1501
+ newCount: compacted.result.newCount,
1502
+ });
1503
+ return;
1278
1504
  }
1279
- // Create new session file for continuation
1280
- const session = await this.sessionManager.create(this.cwd, this.provider, this.model);
1281
- this.sessionId = session.id;
1282
- this.sessionPath = session.path;
1283
- // Re-persist (compacted) messagesskip system, it's rebuilt on load
1284
- for (const msg of this.messages) {
1285
- if (msg.role === "system")
1286
- continue;
1287
- await this.persistMessage(msg);
1288
- }
1505
+ // Plain resume (no compaction needed): keep using the original session
1506
+ // file/id and append future turns to it in place. Forking a new file here
1507
+ // unconditionally used to create a byte-identical duplicate every time a
1508
+ // session was merely reopened (e.g. app/window restart) with zero new
1509
+ // messages in betweenthe duplicate entries seen in the session list.
1510
+ this.sessionId = loaded.header.id;
1511
+ this.sessionPath = sessionPath;
1289
1512
  this.lastPersistedIndex = this.messages.length;
1290
- // Carry Nolan's restored turns into the continuation file.
1291
- await this.rePersistNolanTurns();
1292
1513
  }
1293
1514
  async prepareDynamicContext(_latestUserPrompt) {
1294
1515
  return this.messages;