@caupulican/pi-adaptative 0.80.30 → 0.80.34

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.
@@ -15,6 +15,7 @@
15
15
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
16
16
  import { basename, dirname, join } from "node:path";
17
17
  import { clampThinkingLevel, cleanupSessionResources, getSupportedThinkingLevels, isContextOverflow, modelsAreEqual, resetApiProviders, streamSimple, } from "@caupulican/pi-ai";
18
+ import { getAgentDir } from "../config.js";
18
19
  import { theme } from "../modes/interactive/theme/theme.js";
19
20
  import { stripFrontmatter } from "../utils/frontmatter.js";
20
21
  import { resolvePath } from "../utils/paths.js";
@@ -100,6 +101,7 @@ export class AgentSession {
100
101
  _customTools;
101
102
  _baseToolDefinitions = new Map();
102
103
  _cwd;
104
+ _agentDir;
103
105
  _extensionRunnerRef;
104
106
  _initialActiveToolNames;
105
107
  _allowedToolNames;
@@ -132,6 +134,7 @@ export class AgentSession {
132
134
  this._resourceLoader = config.resourceLoader;
133
135
  this._customTools = config.customTools ?? [];
134
136
  this._cwd = config.cwd;
137
+ this._agentDir = config.agentDir ?? getAgentDir();
135
138
  this._modelRegistry = config.modelRegistry;
136
139
  this._extensionRunnerRef = config.extensionRunnerRef;
137
140
  this._initialActiveToolNames = config.initialActiveToolNames;
@@ -247,7 +250,7 @@ export class AgentSession {
247
250
  };
248
251
  }
249
252
  _contextGcStorageDir() {
250
- return join(this.sessionManager.getSessionDir(), "context-gc", this.sessionManager.getSessionId());
253
+ return join(this._agentDir, "context-gc", this.sessionManager.getSessionId());
251
254
  }
252
255
  _applyContextGc(messages, writePayloads) {
253
256
  try {
@@ -2047,8 +2050,14 @@ export class AgentSession {
2047
2050
  })();
2048
2051
  },
2049
2052
  reload: () => {
2053
+ if (this.isStreaming) {
2054
+ return Promise.reject(new Error("ctx.reload() cannot run while the agent is streaming or a tool call is active. Wait for ctx.isIdle(), queue a follow-up /reload, or use an idle command/event handler so hot reload cannot destabilize the UI."));
2055
+ }
2056
+ if (this.isCompacting) {
2057
+ return Promise.reject(new Error("ctx.reload() cannot run during context compaction or branch summarization. Let compaction finish before reloading so the session tree and UI remain stable."));
2058
+ }
2050
2059
  const actions = this._extensionCommandContextActions;
2051
- if (this.isStreaming || !actions) {
2060
+ if (!actions) {
2052
2061
  return this.reload();
2053
2062
  }
2054
2063
  return actions.reload();
@@ -2246,6 +2255,12 @@ export class AgentSession {
2246
2255
  });
2247
2256
  }
2248
2257
  async reload() {
2258
+ if (this.isStreaming) {
2259
+ throw new Error("Cannot reload while the agent is streaming or a tool call is active");
2260
+ }
2261
+ if (this.isCompacting) {
2262
+ throw new Error("Cannot reload while context compaction or branch summarization is active");
2263
+ }
2249
2264
  const previousRunner = this._extensionRunner;
2250
2265
  const snapshot = this._createReloadRuntimeSnapshot();
2251
2266
  const activeToolNames = this.getActiveToolNames();