@bastani/atomic 0.9.20-alpha.1 → 0.9.20-alpha.3

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 (80) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/builtin/intercom/package.json +1 -1
  3. package/dist/builtin/mcp/package.json +1 -1
  4. package/dist/builtin/subagents/CHANGELOG.md +6 -0
  5. package/dist/builtin/subagents/package.json +5 -1
  6. package/dist/builtin/subagents/skills/feedback/SKILL.md +49 -0
  7. package/dist/builtin/subagents/skills/feedback/scripts/scrub.mjs +498 -0
  8. package/dist/builtin/web-access/CHANGELOG.md +6 -0
  9. package/dist/builtin/web-access/index.bundle.mjs +5 -5
  10. package/dist/builtin/web-access/package.json +1 -1
  11. package/dist/builtin/workflows/package.json +1 -1
  12. package/dist/builtin/workflows/src/extension/index.bundle.mjs +78 -31
  13. package/dist/bun/split-loader.js +13 -0
  14. package/dist/bun/split-loader.js.map +1 -1
  15. package/dist/core/agent-session-compaction.d.ts.map +1 -1
  16. package/dist/core/agent-session-compaction.js +12 -6
  17. package/dist/core/agent-session-compaction.js.map +1 -1
  18. package/dist/core/compaction/compaction-boundary.d.ts +29 -1
  19. package/dist/core/compaction/compaction-boundary.d.ts.map +1 -1
  20. package/dist/core/compaction/compaction-boundary.js +35 -3
  21. package/dist/core/compaction/compaction-boundary.js.map +1 -1
  22. package/dist/core/compaction/compaction-runner.d.ts.map +1 -1
  23. package/dist/core/compaction/compaction-runner.js +18 -5
  24. package/dist/core/compaction/compaction-runner.js.map +1 -1
  25. package/dist/core/compaction/compaction-types.d.ts +7 -0
  26. package/dist/core/compaction/compaction-types.d.ts.map +1 -1
  27. package/dist/core/compaction/compaction-types.js.map +1 -1
  28. package/dist/core/compaction/index.d.ts +1 -0
  29. package/dist/core/compaction/index.d.ts.map +1 -1
  30. package/dist/core/compaction/index.js +1 -0
  31. package/dist/core/compaction/index.js.map +1 -1
  32. package/dist/core/compaction/whole-context-stats.d.ts +21 -0
  33. package/dist/core/compaction/whole-context-stats.d.ts.map +1 -0
  34. package/dist/core/compaction/whole-context-stats.js +32 -0
  35. package/dist/core/compaction/whole-context-stats.js.map +1 -0
  36. package/dist/core/extensions/index.d.ts +1 -1
  37. package/dist/core/extensions/index.d.ts.map +1 -1
  38. package/dist/core/extensions/index.js.map +1 -1
  39. package/dist/core/messages.d.ts.map +1 -1
  40. package/dist/core/messages.js +11 -1
  41. package/dist/core/messages.js.map +1 -1
  42. package/dist/core/model-config.d.ts +85 -0
  43. package/dist/core/model-config.d.ts.map +1 -1
  44. package/dist/core/model-config.js +22 -18
  45. package/dist/core/model-config.js.map +1 -1
  46. package/dist/core/session-manager-core.d.ts +2 -0
  47. package/dist/core/session-manager-core.d.ts.map +1 -1
  48. package/dist/core/session-manager-core.js +26 -3
  49. package/dist/core/session-manager-core.js.map +1 -1
  50. package/dist/core/system-prompt.d.ts.map +1 -1
  51. package/dist/core/system-prompt.js +2 -1
  52. package/dist/core/system-prompt.js.map +1 -1
  53. package/dist/index-extensions.d.ts +1 -1
  54. package/dist/index-extensions.d.ts.map +1 -1
  55. package/dist/index-extensions.js.map +1 -1
  56. package/dist/main-session.d.ts.map +1 -1
  57. package/dist/main-session.js +5 -6
  58. package/dist/main-session.js.map +1 -1
  59. package/dist/modes/interactive/components/compaction-boundary-message.d.ts +2 -0
  60. package/dist/modes/interactive/components/compaction-boundary-message.d.ts.map +1 -1
  61. package/dist/modes/interactive/components/compaction-boundary-message.js +13 -3
  62. package/dist/modes/interactive/components/compaction-boundary-message.js.map +1 -1
  63. package/dist/modes/interactive/interactive-tui.d.ts +3 -6
  64. package/dist/modes/interactive/interactive-tui.d.ts.map +1 -1
  65. package/dist/modes/interactive/interactive-tui.js +13 -5
  66. package/dist/modes/interactive/interactive-tui.js.map +1 -1
  67. package/dist/utils/clipboard.d.ts.map +1 -1
  68. package/dist/utils/clipboard.js +14 -2
  69. package/dist/utils/clipboard.js.map +1 -1
  70. package/docs/compaction/reference.md +2 -0
  71. package/docs/compaction.md +3 -1
  72. package/docs/docs.json +1 -0
  73. package/docs/getting-started/installation.md +1 -1
  74. package/docs/keybindings.md +2 -0
  75. package/docs/mcp.md +74 -0
  76. package/docs/models/reference.md +21 -0
  77. package/docs/prompt-templates.md +8 -0
  78. package/docs/workflows/operations.md +5 -1
  79. package/npm-shrinkwrap.json +32 -32
  80. package/package.json +3 -3
@@ -1812,14 +1812,15 @@ import { existsSync as existsSync7, mkdirSync as mkdirSync2, readFileSync as rea
1812
1812
  import { homedir as homedir3 } from "node:os";
1813
1813
  import { join as join3 } from "node:path";
1814
1814
  function loadConfig5() {
1815
- if (!existsSync7(WEB_SEARCH_CONFIG_READ_PATH))
1815
+ const configPath = findReadableConfigPath();
1816
+ if (!existsSync7(configPath))
1816
1817
  return {};
1817
- const raw = readFileSync6(WEB_SEARCH_CONFIG_READ_PATH, "utf-8");
1818
+ const raw = readFileSync6(configPath, "utf-8");
1818
1819
  try {
1819
1820
  return JSON.parse(raw);
1820
1821
  } catch (err) {
1821
1822
  const message = err instanceof Error ? err.message : String(err);
1822
- throw new Error(`Failed to parse ${WEB_SEARCH_CONFIG_READ_PATH}: ${message}`);
1823
+ throw new Error(`Failed to parse ${configPath}: ${message}`);
1823
1824
  }
1824
1825
  }
1825
1826
  function saveConfig(updates) {
@@ -1928,7 +1929,7 @@ function resolveProvider(requested, available) {
1928
1929
  }
1929
1930
  return provider;
1930
1931
  }
1931
- var WEB_SEARCH_CONFIG_PATH2, WEB_SEARCH_CONFIG_READ_PATH, MAX_CURATOR_TIMEOUT_SECONDS = 600, DEFAULT_CURATOR_TIMEOUT_SECONDS = 20, DEFAULT_SHORTCUTS;
1932
+ var WEB_SEARCH_CONFIG_PATH2, MAX_CURATOR_TIMEOUT_SECONDS = 600, DEFAULT_CURATOR_TIMEOUT_SECONDS = 20, DEFAULT_SHORTCUTS;
1932
1933
  var init_web_search_config = __esm(() => {
1933
1934
  init_config_paths();
1934
1935
  init_exa();
@@ -1936,7 +1937,6 @@ var init_web_search_config = __esm(() => {
1936
1937
  init_gemini_web();
1937
1938
  init_perplexity();
1938
1939
  WEB_SEARCH_CONFIG_PATH2 = getUserConfigPaths2("web-search.json")[0] ?? join3(homedir3(), CONFIG_DIR_NAME2, "web-search.json");
1939
- WEB_SEARCH_CONFIG_READ_PATH = findReadableConfigPath();
1940
1940
  DEFAULT_SHORTCUTS = { curate: "ctrl+shift+s", activity: "ctrl+shift+w" };
1941
1941
  });
1942
1942
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/web-access",
3
- "version": "0.9.20-alpha.1",
3
+ "version": "0.9.20-alpha.3",
4
4
  "private": true,
5
5
  "description": "Atomic extension for web search, URL fetching, GitHub repo cloning, PDF/video extraction. Fork of: https://github.com/nicobailon/pi-web-access",
6
6
  "contributors": [
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/workflows",
3
- "version": "0.9.20-alpha.1",
3
+ "version": "0.9.20-alpha.3",
4
4
  "private": true,
5
5
  "description": "Atomic extension for multi-stage workflow authoring and execution.",
6
6
  "contributors": [
@@ -84928,6 +84928,7 @@ import {
84928
84928
  readdirSync,
84929
84929
  readFileSync as readFileSync2,
84930
84930
  readlinkSync,
84931
+ realpathSync,
84931
84932
  renameSync,
84932
84933
  rmdirSync,
84933
84934
  rmSync,
@@ -84937,7 +84938,7 @@ import {
84937
84938
  } from "node:fs";
84938
84939
  import { createRequire as createRequire2 } from "node:module";
84939
84940
  import { tmpdir, uptime } from "node:os";
84940
- import { dirname as dirname3, join as join3, relative as relative2 } from "node:path";
84941
+ import { dirname as dirname3, isAbsolute as isAbsolute2, join as join3, relative as relative2 } from "node:path";
84941
84942
 
84942
84943
  // dist/builtin/workflows/src/durable/dbos-embedded-postgres-root.ts
84943
84944
  import { createHash as createHash2 } from "node:crypto";
@@ -85548,10 +85549,15 @@ function ensureEmbeddedDbosPostgres() {
85548
85549
  return ensured;
85549
85550
  }
85550
85551
  async function ensure() {
85551
- if (await tcpReachable(EMBEDDED_HOST, EMBEDDED_PORT))
85552
- return;
85553
85552
  const loaded = await loadEmbeddedPostgresBinaries();
85554
85553
  hydrateBinaryLibraryLinks(loaded.pg_ctl);
85554
+ for (const binary of [loaded.postgres, loaded.pg_ctl, loaded.initdb]) {
85555
+ const result = await runLocalCommand(binary, ["--version"]);
85556
+ if (result.exitCode !== 0)
85557
+ throw new Error(`incomplete PostgreSQL runtime: ${binary} --version failed: ${commandFailureDetail(result)}`);
85558
+ }
85559
+ if (await tcpReachable(EMBEDDED_HOST, EMBEDDED_PORT))
85560
+ return;
85555
85561
  const context = await resolveEmbeddedRunContext();
85556
85562
  const root = context.baseDir;
85557
85563
  const dataDir = join3(root, `v${EMBEDDED_PG_MAJOR}`);
@@ -85716,27 +85722,68 @@ function hydrateBinaryLibraryLinks(pgCtlPath, createLink = symlinkSync, copyFile
85716
85722
  let manifest;
85717
85723
  try {
85718
85724
  manifest = JSON.parse(readFileSync2(manifestPath, "utf8"));
85719
- } catch {
85720
- return;
85725
+ } catch (cause) {
85726
+ throw new Error(`incomplete PostgreSQL runtime: invalid ${manifestPath}`, { cause });
85727
+ }
85728
+ if (!Array.isArray(manifest) || manifest.some((link) => link === null || typeof link !== "object" || !safeLibraryPath(link.source) || !safeLibraryPath(link.target))) {
85729
+ throw new Error(`incomplete PostgreSQL runtime: invalid aliases in ${manifestPath}`);
85721
85730
  }
85722
85731
  const firstSource = manifest[0]?.source;
85723
- if (firstSource !== undefined && !existsSync3(join3(manifestRoot, firstSource)) && existsSync3(join3(dirname3(manifestRoot), firstSource))) {
85732
+ if (firstSource?.startsWith("native/") && !existsSync3(join3(manifestRoot, firstSource)) && existsSync3(join3(dirname3(manifestRoot), firstSource))) {
85724
85733
  manifestRoot = dirname3(manifestRoot);
85725
85734
  }
85726
- for (const { source, target } of manifest) {
85727
- const absoluteSource = join3(manifestRoot, source);
85735
+ const canonicalRoot = realpathSync(manifestRoot);
85736
+ const targets = new Map;
85737
+ const plannedSources = new Map;
85738
+ const plans = manifest.map(({ source, target }) => {
85739
+ const sourcePath = join3(manifestRoot, source);
85740
+ const absoluteSource = lstatSync(sourcePath, { throwIfNoEntry: false }) ? sourcePath : plannedSources.get(source) ?? sourcePath;
85728
85741
  const absoluteTarget = join3(manifestRoot, target);
85729
- if (existsSync3(absoluteTarget) || !existsSync3(absoluteSource))
85742
+ try {
85743
+ for (const path of [absoluteSource, dirname3(absoluteTarget)]) {
85744
+ const contained = relative2(canonicalRoot, realpathSync(path));
85745
+ if (isAbsolute2(contained) || contained === ".." || contained.startsWith("../") || contained.startsWith("..\\"))
85746
+ throw new Error(`alias escapes runtime: ${target}`);
85747
+ }
85748
+ if (!statSync(absoluteSource).isFile())
85749
+ throw new Error(`invalid source: ${source}`);
85750
+ if (targets.has(target) && targets.get(target) !== source)
85751
+ throw new Error(`conflicting alias: ${target}`);
85752
+ targets.set(target, source);
85753
+ if (lstatSync(absoluteTarget, { throwIfNoEntry: false }) && !existsSync3(absoluteTarget))
85754
+ throw new Error(`dangling alias target: ${target}`);
85755
+ if (existsSync3(absoluteTarget)) {
85756
+ const contained = relative2(canonicalRoot, realpathSync(absoluteTarget));
85757
+ if (isAbsolute2(contained) || contained === ".." || contained.startsWith("../") || contained.startsWith("..\\") || !statSync(absoluteTarget).isFile() || !readFileSync2(absoluteTarget).equals(readFileSync2(absoluteSource)))
85758
+ throw new Error(`invalid alias target: ${target}`);
85759
+ }
85760
+ } catch (cause) {
85761
+ throw new Error(`incomplete PostgreSQL runtime: ${source} -> ${target}`, { cause });
85762
+ }
85763
+ plannedSources.set(target, absoluteSource);
85764
+ return { absoluteSource, absoluteTarget };
85765
+ });
85766
+ for (const { absoluteSource, absoluteTarget } of plans) {
85767
+ if (lstatSync(absoluteTarget, { throwIfNoEntry: false })) {
85768
+ const contained = relative2(canonicalRoot, realpathSync(absoluteTarget));
85769
+ if (isAbsolute2(contained) || contained === ".." || contained.startsWith("../") || contained.startsWith("..\\") || !statSync(absoluteTarget).isFile() || !readFileSync2(absoluteTarget).equals(readFileSync2(absoluteSource)))
85770
+ throw new Error(`incomplete PostgreSQL runtime: invalid alias target: ${absoluteTarget}`);
85730
85771
  continue;
85772
+ }
85731
85773
  try {
85732
85774
  createLink(relative2(dirname3(absoluteTarget), absoluteSource), absoluteTarget);
85733
85775
  } catch {
85734
85776
  try {
85735
85777
  copyFile(absoluteSource, absoluteTarget);
85736
- } catch {}
85778
+ } catch (cause) {
85779
+ throw new Error(`incomplete PostgreSQL runtime: cannot materialize ${absoluteTarget}`, { cause });
85780
+ }
85737
85781
  }
85738
85782
  }
85739
85783
  }
85784
+ function safeLibraryPath(path) {
85785
+ return typeof path === "string" && path.length > 0 && !path.startsWith("/") && !/[\\:\u0000]/u.test(path) && !path.split("/").some((part) => part === ".." || part === "." || part === "");
85786
+ }
85740
85787
  function binariesFromDirectory(runtimeDirectory, platform) {
85741
85788
  const executableSuffix = platform === "win32" ? ".exe" : "";
85742
85789
  const binaries = {
@@ -90217,7 +90264,7 @@ async function recordWorkflowHeartbeatAnchor(backend, record) {
90217
90264
  }
90218
90265
 
90219
90266
  // dist/builtin/workflows/src/extension/config-loader.ts
90220
- import { isAbsolute as isAbsolute2, join as join4 } from "node:path";
90267
+ import { isAbsolute as isAbsolute3, join as join4 } from "node:path";
90221
90268
  import { CONFIG_DIR_NAME, CONFIG_DIR_NAMES, getAgentDir, getAgentDirs, getProjectConfigPaths } from "@bastani/atomic";
90222
90269
 
90223
90270
  // dist/builtin/workflows/src/shared/budget.ts
@@ -90519,7 +90566,7 @@ function resolveWorkflowPaths(workflows, baseDir) {
90519
90566
  }
90520
90567
  return Object.fromEntries(Object.entries(workflows).map(([name, entry]) => [
90521
90568
  name,
90522
- isAbsolute2(entry.path) ? entry.path : join4(baseDir, entry.path)
90569
+ isAbsolute3(entry.path) ? entry.path : join4(baseDir, entry.path)
90523
90570
  ]));
90524
90571
  }
90525
90572
  function workflowAgentDirs(opts) {
@@ -90542,7 +90589,7 @@ function toScopedDiscoveryConfig(globalConfig, projectConfig, opts) {
90542
90589
  if (hasWorkflows(globalConfig)) {
90543
90590
  const projectKeys = new Set(Object.keys(projectWorkflows ?? {}));
90544
90591
  const globalEntries = Object.entries(globalConfig.workflows).filter(([name]) => !projectKeys.has(name)).map(([name, entry]) => {
90545
- return [name, isAbsolute2(entry.path) ? entry.path : join4(globalBase, entry.path)];
90592
+ return [name, isAbsolute3(entry.path) ? entry.path : join4(globalBase, entry.path)];
90546
90593
  });
90547
90594
  if (globalEntries.length > 0) {
90548
90595
  result.globalWorkflows = Object.fromEntries(globalEntries);
@@ -96609,7 +96656,7 @@ import { Type as Type22 } from "typebox";
96609
96656
 
96610
96657
  // dist/builtin/workflows/builtin/tournament-runner.ts
96611
96658
  import { mkdir as mkdir6, readFile as readFile4, writeFile as writeFile10 } from "node:fs/promises";
96612
- import { join as join19, isAbsolute as isAbsolute3, relative as relative3, resolve as resolve4 } from "node:path";
96659
+ import { join as join19, isAbsolute as isAbsolute4, relative as relative3, resolve as resolve4 } from "node:path";
96613
96660
  import { Type as Type21 } from "typebox";
96614
96661
 
96615
96662
  // dist/builtin/workflows/builtin/selection-math.ts
@@ -96827,7 +96874,7 @@ function judgeArtifactPath(judgesDir, job, criterionIndex) {
96827
96874
  const root = resolve4(judgesDir);
96828
96875
  const path = resolve4(judgesDir, filename);
96829
96876
  const fromRoot = relative3(root, path);
96830
- if (fromRoot.startsWith("..") || isAbsolute3(fromRoot)) {
96877
+ if (fromRoot.startsWith("..") || isAbsolute4(fromRoot)) {
96831
96878
  throw new Error(`tournament: judge artifact escaped its directory: ${path}`);
96832
96879
  }
96833
96880
  return path;
@@ -97225,7 +97272,7 @@ function createRegistry(initial = []) {
97225
97272
 
97226
97273
  // dist/builtin/workflows/src/extension/discovery-loaders.ts
97227
97274
  import { readdir as readdir3, stat as stat2 } from "node:fs/promises";
97228
- import { extname, isAbsolute as isAbsolute12, join as join28, resolve as resolve14 } from "node:path";
97275
+ import { extname, isAbsolute as isAbsolute13, join as join28, resolve as resolve14 } from "node:path";
97229
97276
 
97230
97277
  // ../../node_modules/jiti/lib/jiti-static.mjs
97231
97278
  var import_jiti = __toESM(require_jiti(), 1);
@@ -98763,7 +98810,7 @@ function stripOnePrefix(value2, prefix) {
98763
98810
  }
98764
98811
 
98765
98812
  // dist/builtin/workflows/src/runs/foreground/executor-direct-helpers.ts
98766
- import { isAbsolute as isAbsolute10, join as join26, resolve as resolve12 } from "node:path";
98813
+ import { isAbsolute as isAbsolute11, join as join26, resolve as resolve12 } from "node:path";
98767
98814
  import { CONFIG_DIR_NAME as CONFIG_DIR_NAME2 } from "@bastani/atomic";
98768
98815
 
98769
98816
  // dist/builtin/workflows/src/runs/shared/worktree-git.ts
@@ -99877,15 +99924,15 @@ function cleanupWorktrees(setup) {
99877
99924
  }
99878
99925
  }
99879
99926
  // dist/builtin/workflows/src/runs/shared/worktree-cwd.ts
99880
- import { lstatSync as lstatSync5, realpathSync as realpathSync4 } from "node:fs";
99881
- import { dirname as dirname11, isAbsolute as isAbsolute8, relative as relative7, resolve as resolve10, sep as sep6 } from "node:path";
99927
+ import { lstatSync as lstatSync5, realpathSync as realpathSync5 } from "node:fs";
99928
+ import { dirname as dirname11, isAbsolute as isAbsolute9, relative as relative7, resolve as resolve10, sep as sep6 } from "node:path";
99882
99929
  function relativePathWithin(root, candidate) {
99883
99930
  const path = relative7(root, candidate);
99884
- return path === ".." || path.startsWith(`..${sep6}`) || isAbsolute8(path) ? undefined : path;
99931
+ return path === ".." || path.startsWith(`..${sep6}`) || isAbsolute9(path) ? undefined : path;
99885
99932
  }
99886
99933
  function existingRealPath(path, description) {
99887
99934
  try {
99888
- return realpathSync4.native(path);
99935
+ return realpathSync5.native(path);
99889
99936
  } catch (error) {
99890
99937
  const message = error instanceof Error ? error.message : String(error);
99891
99938
  throw new Error(`atomic-workflows: cannot resolve ${description} ${path}: ${message}`);
@@ -99896,7 +99943,7 @@ function resolveWorktreeStageCwd(cwd, setup) {
99896
99943
  const repositoryRoot = existingRealPath(setup.repositoryRoot, "invoking checkout");
99897
99944
  if (cwd === undefined || cwd.length === 0)
99898
99945
  return;
99899
- const absoluteInput = isAbsolute8(cwd);
99946
+ const absoluteInput = isAbsolute9(cwd);
99900
99947
  const candidate = absoluteInput ? cwd : resolve10(setup.cwd, cwd);
99901
99948
  if (!absoluteInput && relativePathWithin(setup.worktreeRoot, candidate) === undefined) {
99902
99949
  throw new Error(`atomic-workflows: relative cwd ${cwd} escapes gitWorktreeDir ${setup.worktreeRoot}; choose a cwd inside the worktree.`);
@@ -99905,7 +99952,7 @@ function resolveWorktreeStageCwd(cwd, setup) {
99905
99952
  const worktreeRelative = relativePathWithin(worktreeRoot, candidateRealPath);
99906
99953
  if (worktreeRelative !== undefined)
99907
99954
  return resolve10(setup.worktreeRoot, worktreeRelative);
99908
- if (!isAbsolute8(cwd)) {
99955
+ if (!isAbsolute9(cwd)) {
99909
99956
  throw new Error(`atomic-workflows: relative cwd ${cwd} escapes gitWorktreeDir ${setup.worktreeRoot}; choose a path that remains inside the selected worktree.`);
99910
99957
  }
99911
99958
  if (relativePathWithin(setup.worktreeRoot, candidate) !== undefined) {
@@ -99925,7 +99972,7 @@ function resolveWorktreeStageCwd(cwd, setup) {
99925
99972
 
99926
99973
  // dist/builtin/workflows/src/runs/foreground/executor-task-prompts.ts
99927
99974
  import { existsSync as existsSync8 } from "node:fs";
99928
- import { isAbsolute as isAbsolute9, resolve as resolve11 } from "node:path";
99975
+ import { isAbsolute as isAbsolute10, resolve as resolve11 } from "node:path";
99929
99976
  function normalizeTaskContexts(previous) {
99930
99977
  if (previous === undefined)
99931
99978
  return [];
@@ -99976,7 +100023,7 @@ function taskPrevious(options) {
99976
100023
  return options.previous;
99977
100024
  }
99978
100025
  function resolveWorkflowPath(filePath, baseDir) {
99979
- if (isAbsolute9(filePath))
100026
+ if (isAbsolute10(filePath))
99980
100027
  return filePath;
99981
100028
  return resolve11(baseDir ?? process.cwd(), filePath);
99982
100029
  }
@@ -100261,7 +100308,7 @@ function workflowInvocationMetadata(inputDefaults, workflowInvocationCwd, cache,
100261
100308
  function resolvedTaskCwd(cwd, workflowInvocationCwd) {
100262
100309
  if (cwd === undefined)
100263
100310
  return;
100264
- return isAbsolute10(cwd) ? cwd : resolve12(workflowInvocationCwd, cwd);
100311
+ return isAbsolute11(cwd) ? cwd : resolve12(workflowInvocationCwd, cwd);
100265
100312
  }
100266
100313
  function taskWorktreeOutputsRoot(runId) {
100267
100314
  return join26(workflowArtifactRunPath(runId), "task-outputs");
@@ -100274,7 +100321,7 @@ function prepareTaskWorktrees(tasks, options, runId, scope, workflowInvocationCw
100274
100321
  throw new Error("atomic-workflows: worktree and gitWorktreeDir are mutually exclusive; use gitWorktreeDir for a reusable worktree or worktree:true for temporary isolated worktrees.");
100275
100322
  }
100276
100323
  const explicitCwd = tasks.find((task) => typeof task.cwd === "string")?.cwd;
100277
- const sharedCwd = explicitCwd === undefined ? workflowInvocationCwd : isAbsolute10(explicitCwd) ? explicitCwd : resolve12(workflowInvocationCwd, explicitCwd);
100324
+ const sharedCwd = explicitCwd === undefined ? workflowInvocationCwd : isAbsolute11(explicitCwd) ? explicitCwd : resolve12(workflowInvocationCwd, explicitCwd);
100278
100325
  const conflict = findWorktreeTaskCwdConflict(tasks.map((task) => ({ agent: task.name, cwd: resolvedTaskCwd(task.cwd, workflowInvocationCwd) })), sharedCwd);
100279
100326
  if (conflict !== undefined)
100280
100327
  throw new Error(formatWorktreeTaskCwdConflict(conflict, sharedCwd));
@@ -108546,7 +108593,7 @@ class StageSessionController {
108546
108593
  // dist/builtin/workflows/src/runs/foreground/stage-runner-output.ts
108547
108594
  import { createHash as createHash4 } from "node:crypto";
108548
108595
  import { mkdir as mkdir7, writeFile as writeFile11 } from "node:fs/promises";
108549
- import { basename as basename4, dirname as dirname12, isAbsolute as isAbsolute11, join as join27, resolve as resolve13 } from "node:path";
108596
+ import { basename as basename4, dirname as dirname12, isAbsolute as isAbsolute12, join as join27, resolve as resolve13 } from "node:path";
108550
108597
  var DEFAULT_MAX_OUTPUT_BYTES = 200 * 1024;
108551
108598
  var DEFAULT_MAX_OUTPUT_LINES = 5000;
108552
108599
  function normalizeMaxOutput2(maxOutput) {
@@ -108669,9 +108716,9 @@ function savedOutputReference(outputPath, fullOutput, transcriptPathValue, trans
108669
108716
  function resolveOutputPath(output, runtimeCwd, requestedCwd) {
108670
108717
  if (typeof output !== "string" || output.length === 0)
108671
108718
  return;
108672
- if (isAbsolute11(output))
108719
+ if (isAbsolute12(output))
108673
108720
  return output;
108674
- const baseCwd = requestedCwd === undefined ? runtimeCwd : isAbsolute11(requestedCwd) ? requestedCwd : resolve13(runtimeCwd, requestedCwd);
108721
+ const baseCwd = requestedCwd === undefined ? runtimeCwd : isAbsolute12(requestedCwd) ? requestedCwd : resolve13(runtimeCwd, requestedCwd);
108675
108722
  return resolve13(baseCwd, output);
108676
108723
  }
108677
108724
  function degenerateWarning(fullOutput) {
@@ -110598,7 +110645,7 @@ async function loadFromPaths(pathsOrMap, kind, baseCwd, diagnostics) {
110598
110645
  const all = [];
110599
110646
  const entries = Array.isArray(pathsOrMap) ? pathsOrMap.map((p) => ({ rawPath: p })) : Object.entries(pathsOrMap).map(([name, p]) => ({ rawPath: p, configuredName: name }));
110600
110647
  for (const { rawPath, configuredName } of entries) {
110601
- const absPath = isAbsolute12(rawPath) ? rawPath : resolve14(baseCwd, rawPath);
110648
+ const absPath = isAbsolute13(rawPath) ? rawPath : resolve14(baseCwd, rawPath);
110602
110649
  let pathStats;
110603
110650
  try {
110604
110651
  pathStats = await stat2(absPath);
@@ -9,6 +9,7 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
9
9
  import { existsSync, readFileSync } from "node:fs";
10
10
  import { dirname, join } from "node:path";
11
11
  import { pathToFileURL } from "node:url";
12
+ import { validateInstalledPostgres } from "../../../../scripts/validate-installed-postgres.js";
12
13
  import { markLifecycleTiming } from "../core/lifecycle-timings.js";
13
14
  import { ATOMIC_AI_AGENT } from "../utils/agent-attribution.js";
14
15
  import { stripBom } from "../utils/text.js";
@@ -30,6 +31,18 @@ function readVersion() {
30
31
  return "0.0.0";
31
32
  }
32
33
  }
34
+ if (args[0] === "--internal-validate-postgres-runtime") {
35
+ try {
36
+ if (args.length !== 2)
37
+ throw new Error("runtime validation requires exactly one extracted runtime path");
38
+ validateInstalledPostgres(args[1]);
39
+ process.exit(0);
40
+ }
41
+ catch (error) {
42
+ console.error(error instanceof Error ? error.message : String(error));
43
+ process.exit(1);
44
+ }
45
+ }
33
46
  if (args[0] === INTERNAL_INTERCOM_BROKER_ARG) {
34
47
  if (args.length !== 2) {
35
48
  console.error(`Atomic startup error: ${INTERNAL_INTERCOM_BROKER_ARG} requires exactly one broker module path`);
@@ -1 +1 @@
1
- {"version":3,"file":"split-loader.js","sourceRoot":"","sources":["../../src/bun/split-loader.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,4BAA4B,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAC;AAE3G,mBAAmB,CAAC,eAAe,CAAC,CAAC;AAErC,MAAM,QAAQ,GAAG,QAAQ,CAAC;AAE1B,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC;AACzB,OAAO,CAAC,GAAG,CAAC,mBAAmB,GAAG,MAAM,CAAC;AACzC,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,eAAe,CAAC;AACvC,OAAO,CAAC,WAAW,GAAG,CAAC,GAAG,E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O,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC;IAC1D,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1B,OAAO,CAAC,KAAK,CAAC,+CAA+C,OAAO,EAAE,CAAC,CAAC;QACxE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC;IAED,KAAK,MAAM,kCAAC,aAAa,CAAC,OAAO,CAAC,CAAC,IAAI,EAAC,CAAC;AAC1C,CAAC","sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { markLifecycleTiming } from \"../core/lifecycle-timings.ts\";\nimport { ATOMIC_AI_AGENT } from \"../utils/agent-attribution.ts\";\nimport { stripBom } from \"../utils/text.ts\";\nimport { INTERNAL_INTERCOM_BROKER_ARG, importInternalIntercomBroker } from \"./internal-intercom-broker.ts\";\n\nmarkLifecycleTiming(\"process-entry\");\n\nconst APP_NAME = \"atomic\";\n\nprocess.title = APP_NAME;\nprocess.env.ATOMIC_CODING_AGENT = \"true\";\nprocess.env.AI_AGENT = ATOMIC_AI_AGENT;\nprocess.emitWarning = (() => {}) as typeof process.emitWarning;\n\nconst args = process.argv.slice(2);\n\nfunction readVersion(): string {\n\ttry {\n\t\tconst packageJsonPath = join(dirname(process.execPath), \"package.json\");\n\t\tconst pkg = JSON.parse(stripBom(readFileSync(packageJsonPath, \"utf8\"))) as { version?: unknown };\n\t\treturn typeof pkg.version === \"string\" ? pkg.version : \"0.0.0\";\n\t} catch {\n\t\treturn \"0.0.0\";\n\t}\n}\n\nif (args[0] === INTERNAL_INTERCOM_BROKER_ARG) {\n\tif (args.length !== 2) {\n\t\tconsole.error(`Atomic startup error: ${INTERNAL_INTERCOM_BROKER_ARG} requires exactly one broker module path`);\n\t\tprocess.exit(1);\n\t}\n\tvoid importInternalIntercomBroker(args[1]).catch((error: Error) => {\n\t\tconsole.error(`Atomic startup error: ${error.message}`);\n\t\tprocess.exit(1);\n\t});\n} else {\n\tif (args[0] === \"--version\" || args[0] === \"-v\") {\n\t\tconsole.log(readVersion());\n\t\tprocess.exit(0);\n\t}\n\n\tconst appPath = join(dirname(process.execPath), \"app.js\");\n\tif (!existsSync(appPath)) {\n\t\tconsole.error(`Atomic startup error: missing app bundle at ${appPath}`);\n\t\tprocess.exit(1);\n\t}\n\n\tvoid import(pathToFileURL(appPath).href);\n}\n"]}
1
+ {"version":3,"file":"split-loader.js","sourceRoot":"","sources":["../../src/bun/split-loader.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,yBAAyB,EAAE,MAAM,oDAAoD,CAAC;AAC/F,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,4BAA4B,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAC;AAE3G,mBAAmB,CAAC,eAAe,CAAC,CAAC;AAErC,MAAM,QAAQ,GAAG,QAAQ,CAAC;AAE1B,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC;AACzB,OAAO,CAAC,GAAG,CAAC,mBAAmB,GAAG,MAAM,CAAC;AACzC,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,eAAe,CAAC;AACvC,OAAO,CAAC,WAAW,GAAG,CAAC,GAAG,EAAE,GAAE,CAAC,CAA+B,CAAC;AAE/D,MAAM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AO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC;IACD,KAAK,4BAA4B,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAAY,EAAE,EAAE;QACjE,OAAO,CAAC,KAAK,CAAC,yBAAyB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACxD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC;AACJ,CAAC;KAAM,CAAC;IACP,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,WAAW,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QACjD,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;QAC3B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC;IAC1D,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1B,OAAO,CAAC,KAAK,CAAC,+CAA+C,OAAO,EAAE,CAAC,CAAC;QACxE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC;IAED,KAAK,MAAM,kCAAC,aAAa,CAAC,OAAO,CAAC,CAAC,IAAI,EAAC,CAAC;AAC1C,CAAC","sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { validateInstalledPostgres } from \"../../../../scripts/validate-installed-postgres.js\";\nimport { markLifecycleTiming } from \"../core/lifecycle-timings.ts\";\nimport { ATOMIC_AI_AGENT } from \"../utils/agent-attribution.ts\";\nimport { stripBom } from \"../utils/text.ts\";\nimport { INTERNAL_INTERCOM_BROKER_ARG, importInternalIntercomBroker } from \"./internal-intercom-broker.ts\";\n\nmarkLifecycleTiming(\"process-entry\");\n\nconst APP_NAME = \"atomic\";\n\nprocess.title = APP_NAME;\nprocess.env.ATOMIC_CODING_AGENT = \"true\";\nprocess.env.AI_AGENT = ATOMIC_AI_AGENT;\nprocess.emitWarning = (() => {}) as typeof process.emitWarning;\n\nconst args = process.argv.slice(2);\n\nfunction readVersion(): string {\n\ttry {\n\t\tconst packageJsonPath = join(dirname(process.execPath), \"package.json\");\n\t\tconst pkg = JSON.parse(stripBom(readFileSync(packageJsonPath, \"utf8\"))) as { version?: unknown };\n\t\treturn typeof pkg.version === \"string\" ? pkg.version : \"0.0.0\";\n\t} catch {\n\t\treturn \"0.0.0\";\n\t}\n}\n\nif (args[0] === \"--internal-validate-postgres-runtime\") {\n\ttry {\n\t\tif (args.length !== 2) throw new Error(\"runtime validation requires exactly one extracted runtime path\");\n\t\tvalidateInstalledPostgres(args[1]);\n\t\tprocess.exit(0);\n\t} catch (error) {\n\t\tconsole.error(error instanceof Error ? error.message : String(error));\n\t\tprocess.exit(1);\n\t}\n}\n\nif (args[0] === INTERNAL_INTERCOM_BROKER_ARG) {\n\tif (args.length !== 2) {\n\t\tconsole.error(`Atomic startup error: ${INTERNAL_INTERCOM_BROKER_ARG} requires exactly one broker module path`);\n\t\tprocess.exit(1);\n\t}\n\tvoid importInternalIntercomBroker(args[1]).catch((error: Error) => {\n\t\tconsole.error(`Atomic startup error: ${error.message}`);\n\t\tprocess.exit(1);\n\t});\n} else {\n\tif (args[0] === \"--version\" || args[0] === \"-v\") {\n\t\tconsole.log(readVersion());\n\t\tprocess.exit(0);\n\t}\n\n\tconst appPath = join(dirname(process.execPath), \"app.js\");\n\tif (!existsSync(appPath)) {\n\t\tconsole.error(`Atomic startup error: missing app bundle at ${appPath}`);\n\t\tprocess.exit(1);\n\t}\n\n\tvoid import(pathToFileURL(appPath).href);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"agent-session-compaction.d.ts","sourceRoot":"","sources":["../../src/core/agent-session-compaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,2BAA2B,IAAI,YAAY,EAC3C,8BAA8B,EAC9B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAWN,KAAK,4BAA4B,EAEjC,KAAK,wBAAwB,EAE7B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAIX,yBAAyB,EACzB,MAAM,uBAAuB,CAAC;AAiD/B,wBAAsB,wBAAwB,CAC7C,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE,8BAA8B,GACrC,OAAO,CAAC,wBAAwB,GAAG,SAAS,CAAC,CAmK/C;AAED,wBAAsB,wBAAwB,CAC7C,OAAO,EAAE,YAAY,EACrB,KAAK,EAAE,IAAI,CAAC,yBAAyB,EAAE,MAAM,CAAC,GAC5C,OAAO,CAAC,IAAI,CAAC,CAIf;AA4ED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CACtB,IAAI,EAAE,YAAY,EAClB,OAAO,GAAE,OAAO,CAAC,4BAA4B,CAAM,GACjD,OAAO,CAAC,wBAAwB,CAAC,CA8CnC;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAGxD;AACD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAE3D;AACD,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAEnF;AAED,eAAO,MAAM,6BAA6B;;;;;;CAMzC,CAAC"}
1
+ {"version":3,"file":"agent-session-compaction.d.ts","sourceRoot":"","sources":["../../src/core/agent-session-compaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,2BAA2B,IAAI,YAAY,EAC3C,8BAA8B,EAC9B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAWN,KAAK,4BAA4B,EAEjC,KAAK,wBAAwB,EAG7B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAIX,yBAAyB,EACzB,MAAM,uBAAuB,CAAC;AA0D/B,wBAAsB,wBAAwB,CAC7C,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE,8BAA8B,GACrC,OAAO,CAAC,wBAAwB,GAAG,SAAS,CAAC,CAmK/C;AAED,wBAAsB,wBAAwB,CAC7C,OAAO,EAAE,YAAY,EACrB,KAAK,EAAE,IAAI,CAAC,yBAAyB,EAAE,MAAM,CAAC,GAC5C,OAAO,CAAC,IAAI,CAAC,CAIf;AA4ED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CACtB,IAAI,EAAE,YAAY,EAClB,OAAO,GAAE,OAAO,CAAC,4BAA4B,CAAM,GACjD,OAAO,CAAC,wBAAwB,CAAC,CA8CnC;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAGxD;AACD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAE3D;AACD,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAEnF;AAED,eAAO,MAAM,6BAA6B;;;;;;CAMzC,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { formatNoModelSelectedMessage } from "./auth-guidance.js";
2
- import { getKeptTailTokenEstimate, prepareCompactionBoundary, runVerbatimCompaction, VERBATIM_COMPACTION_PROMPT_VERSION, VERBATIM_COMPACTION_STRATEGY, } from "./compaction/index.js";
2
+ import { getKeptTailTokenEstimate, prepareCompactionBoundary, runVerbatimCompaction, VERBATIM_COMPACTION_PROMPT_VERSION, VERBATIM_COMPACTION_STRATEGY, widenToWholeContextStats, } from "./compaction/index.js";
3
3
  import { createSummarizationRetryCallbacks } from "./summarization-retry.js";
4
4
  function frozenCollectionMutation() {
5
5
  throw new TypeError("Cannot mutate frozen compaction preparation");
@@ -36,16 +36,22 @@ function deepFreeze(value) {
36
36
  function extensionStats(preparation, compactedText) {
37
37
  const linesBefore = preparation.region.lines.length;
38
38
  const linesKept = compactedText.split("\n").length;
39
- const tokensAfter = Math.ceil(compactedText.length / 4) + getKeptTailTokenEstimate(preparation);
40
- return {
39
+ // Region-only view first what the extension's replacement text now costs
40
+ // inside the region — then widen it to the whole context with the
41
+ // independently estimated kept tail (symmetric, present on both sides when
42
+ // kept). The authoritative `preparation.tokensBefore` is never mixed into
43
+ // this comparison (#2052).
44
+ const tokensBefore = preparation.region.tokenEstimate;
45
+ const tokensAfter = Math.ceil(compactedText.length / 4);
46
+ return widenToWholeContextStats({
41
47
  linesBefore,
42
48
  linesDeleted: Math.max(0, linesBefore - linesKept),
43
49
  linesKept,
44
50
  rangeCount: 0,
45
- tokensBefore: preparation.tokensBefore,
51
+ tokensBefore,
46
52
  tokensAfter,
47
- percentReduction: preparation.tokensBefore === 0 ? 0 : Math.round((1 - tokensAfter / preparation.tokensBefore) * 1000) / 10,
48
- };
53
+ percentReduction: tokensBefore === 0 ? 0 : Math.round((1 - tokensAfter / tokensBefore) * 1000) / 10,
54
+ }, getKeptTailTokenEstimate(preparation), true);
49
55
  }
50
56
  export async function _applyVerbatimCompaction(options) {
51
57
  if (!this.model)
@@ -1 +1 @@
1
- {"version":3,"file":"agent-session-compaction.js","sourceRoot":"","sources":["../../src/core/agent-session-compaction.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAKN,wBAAwB,EACxB,yBAAyB,EACzB,qBAAqB,EACrB,kCAAkC,EAClC,4BAA4B,GAM5B,MAAM,uBAAuB,CAAC;AAQ/B,OAAO,EAAE,iCAAiC,EAAE,MAAM,0BAA0B,CAAC;AAE7E,SAAS,wBAAwB;IAChC,MAAM,IAAI,SAAS,CAAC,6CAA6C,CAAC,CAAC;AACpE,CAAC;AAED,SAAS,UAAU,CAAI,KAAQ;IAC9B,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAChF,IAAI,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EAAE,OAAO,CAAC,CAAC;IACjE,CAAC,CAAC;SACD,OAAO,CAAC,GAAG,EAAE;QACb,+BAA+B,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QACvD,IAAI,IAAI,CAAC,wBAAwB,KAAK,MAAM;YAAE,IAAI,CAAC,wBAAwB,GAAG,SAAS,CAAC;IACzF,CAAC,CAAC,CAAC;IACJ,IAAI,CAAC,wBAAwB,GAAG,MAAM,CAAC;IACvC,OAAO,MAAM,CAAC;AACf,CAAC;AAED,MAAM,UAAU,eAAe;IAC9B,IAAI,CAAC,0BAA0B,EAAE,KAAK,EAAE,CAAC;IACzC,IAAI,CAAC,8BAA8B,EAAE,KAAK,EAAE,CAAC;AAC9C,CAAC;AACD,MAAM,UAAU,kBAAkB;IACjC,IAAI,CAAC,6BAA6B,EAAE,KAAK,EAAE,CAAC;AAC7C,CAAC;AACD,MAAM,UAAU,wBAAwB,CAAqB,OAAgB;IAC5E,IAAI,CAAC,eAAe,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,CAAC,MAAM,6BAA6B,GAAG;IAC5C,wBAAwB;IACxB,OAAO;IACP,eAAe;IACf,kBAAkB;IAClB,wBAAwB;CACxB,CAAC","sourcesContent":["import type { Usage } from \"@bastani/pi-ai/compat\";\nimport type {\n\tAgentSessionInternalSurface as AgentSession,\n\tVerbatimCompactionApplyOptions,\n} from \"./agent-session-methods.ts\";\nimport { formatNoModelSelectedMessage } from \"./auth-guidance.ts\";\nimport {\n\ttype CompactionPlannerModel,\n\ttype CompactionPlanOptions,\n\ttype CompactionRung,\n\ttype FallbackPlannerContext,\n\tgetKeptTailTokenEstimate,\n\tprepareCompactionBoundary,\n\trunVerbatimCompaction,\n\tVERBATIM_COMPACTION_PROMPT_VERSION,\n\tVERBATIM_COMPACTION_STRATEGY,\n\ttype VerbatimCompactionDetails,\n\ttype VerbatimCompactionParameters,\n\ttype VerbatimCompactionPreparation,\n\ttype VerbatimCompactionResult,\n\ttype VerbatimCompactionStats,\n} from \"./compaction/index.ts\";\nimport type {\n\tSessionBeforeCompactEvent,\n\tSessionBeforeCompactResult,\n\tSessionCompactEvent,\n\tSessionCompactFailedEvent,\n} from \"./extensions/index.js\";\nimport type { CompactionEntry } from \"./session-manager.ts\";\nimport { createSummarizationRetryCallbacks } from \"./summarization-retry.ts\";\n\nfunction frozenCollectionMutation(): never {\n\tthrow new TypeError(\"Cannot mutate frozen compaction preparation\");\n}\n\nfunction deepFreeze<T>(value: T): T {\n\tif (!value || typeof value !== \"object\" || Object.isFrozen(value)) return value;\n\tif (value instanceof Map) {\n\t\tfor (const [key, nested] of value) {\n\t\t\tdeepFreeze(key);\n\t\t\tdeepFreeze(nested);\n\t\t}\n\t\tObject.defineProperties(value, {\n\t\t\tset: { value: frozenCollectionMutation },\n\t\t\tdelete: { value: frozenCollectionMutation },\n\t\t\tclear: { value: frozenCollectionMutation },\n\t\t});\n\t} else if (value instanceof Set) {\n\t\tfor (const nested of value) deepFreeze(nested);\n\t\tObject.defineProperties(value, {\n\t\t\tadd: { value: frozenCollectionMutation },\n\t\t\tdelete: { value: frozenCollectionMutation },\n\t\t\tclear: { value: frozenCollectionMutation },\n\t\t});\n\t} else {\n\t\tfor (const nested of Object.values(value)) deepFreeze(nested);\n\t}\n\treturn Object.freeze(value);\n}\n\nfunction extensionStats(preparation: VerbatimCompactionPreparation, compactedText: string): VerbatimCompactionStats {\n\tconst linesBefore = preparation.region.lines.length;\n\tconst linesKept = compactedText.split(\"\\n\").length;\n\tconst tokensAfter = Math.ceil(compactedText.length / 4) + getKeptTailTokenEstimate(preparation);\n\treturn {\n\t\tlinesBefore,\n\t\tlinesDeleted: Math.max(0, linesBefore - linesKept),\n\t\tlinesKept,\n\t\trangeCount: 0,\n\t\ttokensBefore: preparation.tokensBefore,\n\t\ttokensAfter,\n\t\tpercentReduction:\n\t\t\tpreparation.tokensBefore === 0 ? 0 : Math.round((1 - tokensAfter / preparation.tokensBefore) * 1000) / 10,\n\t};\n}\n\nexport async function _applyVerbatimCompaction(\n\tthis: AgentSession,\n\toptions: VerbatimCompactionApplyOptions,\n): Promise<VerbatimCompactionResult | undefined> {\n\tif (!this.model) throw new Error(formatNoModelSelectedMessage());\n\tconst model = this.model;\n\tconst pathEntries = this.sessionManager.getBranch();\n\tconst settings = this.settingsManager.getCompactionSettings(model);\n\t// A sub-minimum region is admitted only when the caller already knows the\n\t// context does not fit: overflow recovery, or a post-tool preflight over the\n\t// provider hard input limit. A threshold crossing that still fits must not\n\t// clear context — its follow-up request can be sent as-is. `load_bearing`\n\t// alone does not mean \"must destroy context\".\n\tconst allowSmallRegion = options.urgency === \"load_bearing\" && options.allowSmallRegion === true;\n\tconst preparation = prepareCompactionBoundary(\n\t\tpathEntries,\n\t\tsettings,\n\t\t{\n\t\t\t...(options.compression_ratio === undefined ? {} : { compression_ratio: options.compression_ratio }),\n\t\t\t...(options.preserve_recent === undefined ? {} : { preserve_recent: options.preserve_recent }),\n\t\t\t...(options.query === undefined ? {} : { query: options.query }),\n\t\t},\n\t\t{ allowSmallRegion },\n\t);\n\tif (!preparation) {\n\t\t// Mid-turn threshold preflight needs the load-bearing planner fallback if\n\t\t// a region exists, but a context that still fits is safe to send unchanged.\n\t\t// True overflow and a hard-limit preflight have no such escape hatch.\n\t\tconst mustFreeContext = options.urgency === \"load_bearing\" && (options.reason === \"overflow\" || allowSmallRegion);\n\t\tif (mustFreeContext) {\n\t\t\tthrow new Error(\n\t\t\t\t\"Context compaction found no compactable transcript entries; nothing more was safely deletable\",\n\t\t\t);\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tconst plan: CompactionPlanOptions = {\n\t\tstreamFn: this.agent.streamFunction,\n\t\tsessionFilePath: this.sessionManager.getSessionFile(),\n\t\tretry: this.settingsManager.getRetrySettings(),\n\t\tcallbacks: createSummarizationRetryCallbacks(this, { source: \"compaction\", reason: options.reason }),\n\t};\n\tlet fromExtension = false;\n\tlet compacted:\n\t\t| {\n\t\t\t\ttext: string;\n\t\t\t\tstats: VerbatimCompactionStats;\n\t\t\t\trung: CompactionRung;\n\t\t\t\tplannerModel?: CompactionPlannerModel;\n\t\t\t\tkeptTail: boolean;\n\t\t\t\tusage?: Usage;\n\t\t }\n\t\t| undefined;\n\n\tif (this._extensionRunner.hasHandlers(\"session_before_compact\")) {\n\t\tlet snapshot: VerbatimCompactionPreparation;\n\t\ttry {\n\t\t\tsnapshot = deepFreeze(structuredClone(preparation));\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to snapshot transcript for compaction extensions: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t}\n\t\tconst hookResult = (await this._extensionRunner.emit({\n\t\t\ttype: \"session_before_compact\",\n\t\t\treason: options.reason,\n\t\t\tparameters: preparation.parameters,\n\t\t\tpreparation: snapshot,\n\t\t\tbranchEntries: pathEntries,\n\t\t\tsignal: options.abortController.signal,\n\t\t} satisfies SessionBeforeCompactEvent)) as SessionBeforeCompactResult | undefined;\n\t\tif (hookResult?.cancel) throw new Error(\"Compaction cancelled\");\n\t\tif (hookResult?.compactedText !== undefined) {\n\t\t\tif (hookResult.compactedText.trim().length === 0) throw new Error(\"No compacted text provided by extension\");\n\t\t\tcompacted = {\n\t\t\t\ttext: hookResult.compactedText,\n\t\t\t\tstats: extensionStats(preparation, hookResult.compactedText),\n\t\t\t\trung: \"extension\",\n\t\t\t\tkeptTail: true,\n\t\t\t};\n\t\t\tfromExtension = true;\n\t\t\toptions.onCompactionSource?.(true);\n\t\t}\n\t}\n\n\tif (!compacted) {\n\t\t// Borrowing walks the session's *effective* fallback list, which SDK\n\t\t// options may override, and resolves credentials per candidate. It never\n\t\t// touches session model state or the main chat's attempted-key set.\n\t\tconst fallback: FallbackPlannerContext = {\n\t\t\tfallbackModels: this._fallbackModels,\n\t\t\tregistry: this._modelRuntime,\n\t\t\tpreferredProvider: model.provider,\n\t\t\tsessionThinkingLevel: this.thinkingLevel,\n\t\t};\n\t\tconst run = await runVerbatimCompaction(preparation, model, {\n\t\t\t...plan,\n\t\t\tresolveAuth: options.resolvePlannerAuth,\n\t\t\tsignal: options.abortController.signal,\n\t\t\tthinkingLevel: this.thinkingLevel,\n\t\t\turgency: options.urgency,\n\t\t\tfallback,\n\t\t});\n\t\tcompacted = {\n\t\t\ttext: run.text,\n\t\t\tstats: run.stats,\n\t\t\trung: run.rung,\n\t\t\t...(run.plannerModel ? { plannerModel: run.plannerModel } : {}),\n\t\t\t...(run.usage ? { usage: run.usage } : {}),\n\t\t\tkeptTail: run.keptTail,\n\t\t};\n\t}\n\tif (options.abortController.signal.aborted) throw new Error(\"Compaction cancelled\");\n\n\t// A fresh rung that had to drop the protected tail persists no tail boundary.\n\tconst firstKeptEntryId = compacted.keptTail ? preparation.firstKeptEntryId : null;\n\tconst backupPath = this.sessionManager.writeBackupSnapshot(options.backupLabel);\n\tconst details: VerbatimCompactionDetails = {\n\t\tstrategy: VERBATIM_COMPACTION_STRATEGY,\n\t\tpromptVersion: VERBATIM_COMPACTION_PROMPT_VERSION,\n\t\tparameters: preparation.parameters,\n\t\tstats: compacted.stats,\n\t\trung: compacted.rung,\n\t\t...(compacted.plannerModel ? { plannerModel: compacted.plannerModel } : {}),\n\t\t...(backupPath ? { backupPath } : {}),\n\t};\n\tconst entryId = this.sessionManager.appendCompaction(\n\t\tcompacted.text,\n\t\tfirstKeptEntryId,\n\t\tpreparation.tokensBefore,\n\t\tdetails,\n\t\tcompacted.usage,\n\t);\n\tthis.agent.state.messages = this.sessionManager.buildSessionContext().messages;\n\tconst result: VerbatimCompactionResult = {\n\t\tcompactedText: compacted.text,\n\t\tfirstKeptEntryId,\n\t\ttokensBefore: preparation.tokensBefore,\n\t\tstats: compacted.stats,\n\t\tparameters: preparation.parameters,\n\t\tpromptVersion: VERBATIM_COMPACTION_PROMPT_VERSION,\n\t\trung: compacted.rung,\n\t\t...(compacted.plannerModel ? { plannerModel: compacted.plannerModel } : {}),\n\t\t...(compacted.usage ? { usage: compacted.usage } : {}),\n\t\t...(backupPath ? { backupPath } : {}),\n\t};\n\tconst compactionEntry = this.sessionManager.getEntry(entryId) as CompactionEntry<VerbatimCompactionDetails>;\n\ttry {\n\t\tawait this._extensionRunner.emit({\n\t\t\ttype: \"session_compact\",\n\t\t\treason: options.reason,\n\t\t\tparameters: preparation.parameters,\n\t\t\tresult,\n\t\t\tcompactionEntry,\n\t\t\tfromExtension,\n\t\t} satisfies SessionCompactEvent);\n\t} catch (error) {\n\t\tthis._extensionRunner.emitError({\n\t\t\textensionPath: \"<session_compact>\",\n\t\t\tevent: \"session_compact\",\n\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\tstack: error instanceof Error ? error.stack : undefined,\n\t\t});\n\t}\n\treturn result;\n}\n\nexport async function emitSessionCompactFailed(\n\tsession: AgentSession,\n\tevent: Omit<SessionCompactFailedEvent, \"type\">,\n): Promise<void> {\n\tif (session._extensionRunner?.hasHandlers(\"session_compact_failed\")) {\n\t\tawait session._extensionRunner.emit({ type: \"session_compact_failed\", ...event });\n\t}\n}\n\nfunction clearOwnedManualCompactionState(this: AgentSession, controller: AbortController): void {\n\tif (this._compactionAbortController !== controller) return;\n\tthis._compactionAbortController = undefined;\n\tif (this._compactionReason === \"manual\") this._compactionReason = undefined;\n\t// Lifecycle listeners run synchronously. Once the manual end event is\n\t// emitted, a new /compact must own a new run rather than join the settled one.\n\tthis._manualCompactionPromise = undefined;\n}\n\nasync function emitManualCompactionFailure(\n\tthis: AgentSession,\n\tcontroller: AbortController,\n\terror: unknown,\n\tfromExtension: boolean,\n): Promise<void> {\n\tconst message = error instanceof Error ? error.message : String(error);\n\tconst aborted = message === \"Compaction cancelled\" || (error instanceof Error && error.name === \"AbortError\");\n\tconst errorMessage = aborted ? undefined : `Compaction failed: ${message}`;\n\tclearOwnedManualCompactionState.call(this, controller);\n\tthis._emit({\n\t\ttype: \"compaction_end\",\n\t\treason: \"manual\",\n\t\tresult: undefined,\n\t\taborted,\n\t\twillRetry: false,\n\t\terrorMessage,\n\t});\n\tawait emitSessionCompactFailed(this, {\n\t\treason: \"manual\",\n\t\terrorMessage,\n\t\taborted,\n\t\twillRetry: false,\n\t\tfromExtension,\n\t});\n}\n\nasync function runOwnedManualCompaction(\n\tthis: AgentSession,\n\tcontroller: AbortController,\n\toptions: Partial<VerbatimCompactionParameters>,\n): Promise<VerbatimCompactionResult> {\n\tthis._emit({ type: \"compaction_start\", reason: \"manual\" });\n\tlet fromExtension = false;\n\ttry {\n\t\tif (!this.model) throw new Error(formatNoModelSelectedMessage());\n\t\tconst result = await this._applyVerbatimCompaction({\n\t\t\t// Caller parameters are projected explicitly, so no extra runtime\n\t\t\t// property survives. A widened or cast object could otherwise carry\n\t\t\t// `urgency: \"load_bearing\"` through a public `session.compact()` call and\n\t\t\t// reach the context-destroying rung, which manual compaction must never do.\n\t\t\t...(options.compression_ratio === undefined ? {} : { compression_ratio: options.compression_ratio }),\n\t\t\t...(options.preserve_recent === undefined ? {} : { preserve_recent: options.preserve_recent }),\n\t\t\t...(options.query === undefined ? {} : { query: options.query }),\n\t\t\tresolvePlannerAuth: (candidate) => this._getRequiredRequestAuth(candidate),\n\t\t\tabortController: controller,\n\t\t\tbackupLabel: \"compact\",\n\t\t\treason: \"manual\",\n\t\t\turgency: \"recoverable\",\n\t\t\tonCompactionSource: (value) => {\n\t\t\t\tfromExtension = value;\n\t\t\t},\n\t\t});\n\t\tif (!result) throw new Error(\"Nothing to compact (session too small)\");\n\t\t// compaction_end listeners synchronously flush queued prompts, so they must\n\t\t// observe an idle session before dispatching the next user turn.\n\t\tclearOwnedManualCompactionState.call(this, controller);\n\t\tthis._emit({ type: \"compaction_end\", reason: \"manual\", result, aborted: false, willRetry: false });\n\t\treturn result;\n\t} catch (error) {\n\t\tawait emitManualCompactionFailure.call(this, controller, error, fromExtension);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Persist one verbatim line-subset compaction boundary.\n *\n * Re-entrancy safe: a call made while a manual compaction is still in flight\n * joins that run instead of starting a second one. Manual compaction aborts an\n * active agent run before it starts, while agent event delivery remains live so\n * a pending threshold check cannot race the requested manual boundary.\n */\nexport function compact(\n\tthis: AgentSession,\n\toptions: Partial<VerbatimCompactionParameters> = {},\n): Promise<VerbatimCompactionResult> {\n\tconst inFlight = this._manualCompactionPromise;\n\tif (inFlight) return inFlight;\n\n\t// A manual boundary replaces the automatic turn that scheduled any pending\n\t// retry. Invalidate its timer before this run claims compaction ownership.\n\tthis._postCompactionContinuationToken += 1;\n\tthis._pendingPostCompactionContinuation = undefined;\n\n\tconst automaticCompletion = this._autoCompactionCompletion;\n\t// The manual request wins. Abort the active automatic planner now, before the\n\t// next microtask can admit a post-tool or threshold boundary, then wait for\n\t// its owner to settle before mutating the transcript ourselves. Start the\n\t// session abort before publishing this new manual owner so abort() cancels\n\t// prior work rather than cancelling or waiting on the compaction being started.\n\tthis._autoCompactionAbortController?.abort();\n\tconst abortBoundary = this.abort();\n\n\tconst controller = new AbortController();\n\tthis._compactionAbortController = controller;\n\tthis._compactionReason = \"manual\";\n\t// Handle rejection now so a failing event drain cannot become unhandled\n\t// while an automatic run finishes.\n\tvoid abortBoundary.catch(() => {});\n\tlet flight!: Promise<VerbatimCompactionResult>;\n\t// Start the owned run in a microtask so both single-flight fields are\n\t// published before any joiner can observe a partially claimed compaction.\n\tflight = Promise.resolve()\n\t\t.then(async () => {\n\t\t\ttry {\n\t\t\t\tif (automaticCompletion !== undefined) await automaticCompletion;\n\t\t\t\tawait abortBoundary;\n\t\t\t} catch (error) {\n\t\t\t\t// The abort drain can fail before the planner starts. Finish the\n\t\t\t\t// manual lifecycle so event consumers can release queued input.\n\t\t\t\tawait emitManualCompactionFailure.call(this, controller, error, false);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\treturn runOwnedManualCompaction.call(this, controller, options);\n\t\t})\n\t\t.finally(() => {\n\t\t\tclearOwnedManualCompactionState.call(this, controller);\n\t\t\tif (this._manualCompactionPromise === flight) this._manualCompactionPromise = undefined;\n\t\t});\n\tthis._manualCompactionPromise = flight;\n\treturn flight;\n}\n\nexport function abortCompaction(this: AgentSession): void {\n\tthis._compactionAbortController?.abort();\n\tthis._autoCompactionAbortController?.abort();\n}\nexport function abortBranchSummary(this: AgentSession): void {\n\tthis._branchSummaryAbortController?.abort();\n}\nexport function setAutoCompactionEnabled(this: AgentSession, enabled: boolean): void {\n\tthis.settingsManager.setCompactionEnabled(enabled);\n}\n\nexport const agentSessionCompactionMethods = {\n\t_applyVerbatimCompaction,\n\tcompact,\n\tabortCompaction,\n\tabortBranchSummary,\n\tsetAutoCompactionEnabled,\n};\n"]}
1
+ {"version":3,"file":"agent-session-compaction.js","sourceRoot":"","sources":["../../src/core/agent-session-compaction.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAKN,wBAAwB,EACxB,yBAAyB,EACzB,qBAAqB,EACrB,kCAAkC,EAClC,4BAA4B,EAM5B,wBAAwB,GACxB,MAAM,uBAAuB,CAAC;AAQ/B,OAAO,EAAE,iCAAiC,EAAE,MAAM,0BAA0B,CAAC;AAE7E,SAAS,wBAAwB;IAChC,MAAM,IAAI,SAAS,CAAC,6CAA6C,CAAC,CAAC;AACpE,CAAC;AAED,SAAS,UAAU,CAAI,KAAQ;IAC9B,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAChF,IAAI,KAAK,YAAY,GAAG,EAAE,CAAC;QAC1B,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;YACnC,UAAU,CAAC,GAAG,CAAC,CAAC;YAChB,UAAU,CAAC,MAAM,CAAC,CAAC;QACpB,CAAC;QACD,MAAM,CAAC,gBAAgB,CAAC,KAAK,EAAE;YAC9B,GAAG,EAAE,EAAE,KAAK,EAAE,wBAAwB,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,wBAAwB,KAAK,MAAM;YAAE,IAAI,CAAC,wBAAwB,GAAG,SAAS,CAAC;IACzF,CAAC,CAAC,CAAC;IACJ,IAAI,CAAC,wBAAwB,GAAG,MAAM,CAAC;IACvC,OAAO,MAAM,CAAC;AACf,CAAC;AAED,MAAM,UAAU,eAAe;IAC9B,IAAI,CAAC,0BAA0B,EAAE,KAAK,EAAE,CAAC;IACzC,IAAI,CAAC,8BAA8B,EAAE,KAAK,EAAE,CAAC;AAC9C,CAAC;AACD,MAAM,UAAU,kBAAkB;IACjC,IAAI,CAAC,6BAA6B,EAAE,KAAK,EAAE,CAAC;AAC7C,CAAC;AACD,MAAM,UAAU,wBAAwB,CAAqB,OAAgB;IAC5E,IAAI,CAAC,eAAe,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,CAAC,MAAM,6BAA6B,GAAG;IAC5C,wBAAwB;IACxB,OAAO;IACP,eAAe;IACf,kBAAkB;IAClB,wBAAwB;CACxB,CAAC","sourcesContent":["import type { Usage } from \"@bastani/pi-ai/compat\";\nimport type {\n\tAgentSessionInternalSurface as AgentSession,\n\tVerbatimCompactionApplyOptions,\n} from \"./agent-session-methods.ts\";\nimport { formatNoModelSelectedMessage } from \"./auth-guidance.ts\";\nimport {\n\ttype CompactionPlannerModel,\n\ttype CompactionPlanOptions,\n\ttype CompactionRung,\n\ttype FallbackPlannerContext,\n\tgetKeptTailTokenEstimate,\n\tprepareCompactionBoundary,\n\trunVerbatimCompaction,\n\tVERBATIM_COMPACTION_PROMPT_VERSION,\n\tVERBATIM_COMPACTION_STRATEGY,\n\ttype VerbatimCompactionDetails,\n\ttype VerbatimCompactionParameters,\n\ttype VerbatimCompactionPreparation,\n\ttype VerbatimCompactionResult,\n\ttype VerbatimCompactionStats,\n\twidenToWholeContextStats,\n} from \"./compaction/index.ts\";\nimport type {\n\tSessionBeforeCompactEvent,\n\tSessionBeforeCompactResult,\n\tSessionCompactEvent,\n\tSessionCompactFailedEvent,\n} from \"./extensions/index.js\";\nimport type { CompactionEntry } from \"./session-manager.ts\";\nimport { createSummarizationRetryCallbacks } from \"./summarization-retry.ts\";\n\nfunction frozenCollectionMutation(): never {\n\tthrow new TypeError(\"Cannot mutate frozen compaction preparation\");\n}\n\nfunction deepFreeze<T>(value: T): T {\n\tif (!value || typeof value !== \"object\" || Object.isFrozen(value)) return value;\n\tif (value instanceof Map) {\n\t\tfor (const [key, nested] of value) {\n\t\t\tdeepFreeze(key);\n\t\t\tdeepFreeze(nested);\n\t\t}\n\t\tObject.defineProperties(value, {\n\t\t\tset: { value: frozenCollectionMutation },\n\t\t\tdelete: { value: frozenCollectionMutation },\n\t\t\tclear: { value: frozenCollectionMutation },\n\t\t});\n\t} else if (value instanceof Set) {\n\t\tfor (const nested of value) deepFreeze(nested);\n\t\tObject.defineProperties(value, {\n\t\t\tadd: { value: frozenCollectionMutation },\n\t\t\tdelete: { value: frozenCollectionMutation },\n\t\t\tclear: { value: frozenCollectionMutation },\n\t\t});\n\t} else {\n\t\tfor (const nested of Object.values(value)) deepFreeze(nested);\n\t}\n\treturn Object.freeze(value);\n}\n\nfunction extensionStats(preparation: VerbatimCompactionPreparation, compactedText: string): VerbatimCompactionStats {\n\tconst linesBefore = preparation.region.lines.length;\n\tconst linesKept = compactedText.split(\"\\n\").length;\n\t// Region-only view first — what the extension's replacement text now costs\n\t// inside the region — then widen it to the whole context with the\n\t// independently estimated kept tail (symmetric, present on both sides when\n\t// kept). The authoritative `preparation.tokensBefore` is never mixed into\n\t// this comparison (#2052).\n\tconst tokensBefore = preparation.region.tokenEstimate;\n\tconst tokensAfter = Math.ceil(compactedText.length / 4);\n\treturn widenToWholeContextStats(\n\t\t{\n\t\t\tlinesBefore,\n\t\t\tlinesDeleted: Math.max(0, linesBefore - linesKept),\n\t\t\tlinesKept,\n\t\t\trangeCount: 0,\n\t\t\ttokensBefore,\n\t\t\ttokensAfter,\n\t\t\tpercentReduction: tokensBefore === 0 ? 0 : Math.round((1 - tokensAfter / tokensBefore) * 1000) / 10,\n\t\t},\n\t\tgetKeptTailTokenEstimate(preparation),\n\t\ttrue,\n\t);\n}\n\nexport async function _applyVerbatimCompaction(\n\tthis: AgentSession,\n\toptions: VerbatimCompactionApplyOptions,\n): Promise<VerbatimCompactionResult | undefined> {\n\tif (!this.model) throw new Error(formatNoModelSelectedMessage());\n\tconst model = this.model;\n\tconst pathEntries = this.sessionManager.getBranch();\n\tconst settings = this.settingsManager.getCompactionSettings(model);\n\t// A sub-minimum region is admitted only when the caller already knows the\n\t// context does not fit: overflow recovery, or a post-tool preflight over the\n\t// provider hard input limit. A threshold crossing that still fits must not\n\t// clear context — its follow-up request can be sent as-is. `load_bearing`\n\t// alone does not mean \"must destroy context\".\n\tconst allowSmallRegion = options.urgency === \"load_bearing\" && options.allowSmallRegion === true;\n\tconst preparation = prepareCompactionBoundary(\n\t\tpathEntries,\n\t\tsettings,\n\t\t{\n\t\t\t...(options.compression_ratio === undefined ? {} : { compression_ratio: options.compression_ratio }),\n\t\t\t...(options.preserve_recent === undefined ? {} : { preserve_recent: options.preserve_recent }),\n\t\t\t...(options.query === undefined ? {} : { query: options.query }),\n\t\t},\n\t\t{ allowSmallRegion },\n\t);\n\tif (!preparation) {\n\t\t// Mid-turn threshold preflight needs the load-bearing planner fallback if\n\t\t// a region exists, but a context that still fits is safe to send unchanged.\n\t\t// True overflow and a hard-limit preflight have no such escape hatch.\n\t\tconst mustFreeContext = options.urgency === \"load_bearing\" && (options.reason === \"overflow\" || allowSmallRegion);\n\t\tif (mustFreeContext) {\n\t\t\tthrow new Error(\n\t\t\t\t\"Context compaction found no compactable transcript entries; nothing more was safely deletable\",\n\t\t\t);\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tconst plan: CompactionPlanOptions = {\n\t\tstreamFn: this.agent.streamFunction,\n\t\tsessionFilePath: this.sessionManager.getSessionFile(),\n\t\tretry: this.settingsManager.getRetrySettings(),\n\t\tcallbacks: createSummarizationRetryCallbacks(this, { source: \"compaction\", reason: options.reason }),\n\t};\n\tlet fromExtension = false;\n\tlet compacted:\n\t\t| {\n\t\t\t\ttext: string;\n\t\t\t\tstats: VerbatimCompactionStats;\n\t\t\t\trung: CompactionRung;\n\t\t\t\tplannerModel?: CompactionPlannerModel;\n\t\t\t\tkeptTail: boolean;\n\t\t\t\tusage?: Usage;\n\t\t }\n\t\t| undefined;\n\n\tif (this._extensionRunner.hasHandlers(\"session_before_compact\")) {\n\t\tlet snapshot: VerbatimCompactionPreparation;\n\t\ttry {\n\t\t\tsnapshot = deepFreeze(structuredClone(preparation));\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to snapshot transcript for compaction extensions: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t}\n\t\tconst hookResult = (await this._extensionRunner.emit({\n\t\t\ttype: \"session_before_compact\",\n\t\t\treason: options.reason,\n\t\t\tparameters: preparation.parameters,\n\t\t\tpreparation: snapshot,\n\t\t\tbranchEntries: pathEntries,\n\t\t\tsignal: options.abortController.signal,\n\t\t} satisfies SessionBeforeCompactEvent)) as SessionBeforeCompactResult | undefined;\n\t\tif (hookResult?.cancel) throw new Error(\"Compaction cancelled\");\n\t\tif (hookResult?.compactedText !== undefined) {\n\t\t\tif (hookResult.compactedText.trim().length === 0) throw new Error(\"No compacted text provided by extension\");\n\t\t\tcompacted = {\n\t\t\t\ttext: hookResult.compactedText,\n\t\t\t\tstats: extensionStats(preparation, hookResult.compactedText),\n\t\t\t\trung: \"extension\",\n\t\t\t\tkeptTail: true,\n\t\t\t};\n\t\t\tfromExtension = true;\n\t\t\toptions.onCompactionSource?.(true);\n\t\t}\n\t}\n\n\tif (!compacted) {\n\t\t// Borrowing walks the session's *effective* fallback list, which SDK\n\t\t// options may override, and resolves credentials per candidate. It never\n\t\t// touches session model state or the main chat's attempted-key set.\n\t\tconst fallback: FallbackPlannerContext = {\n\t\t\tfallbackModels: this._fallbackModels,\n\t\t\tregistry: this._modelRuntime,\n\t\t\tpreferredProvider: model.provider,\n\t\t\tsessionThinkingLevel: this.thinkingLevel,\n\t\t};\n\t\tconst run = await runVerbatimCompaction(preparation, model, {\n\t\t\t...plan,\n\t\t\tresolveAuth: options.resolvePlannerAuth,\n\t\t\tsignal: options.abortController.signal,\n\t\t\tthinkingLevel: this.thinkingLevel,\n\t\t\turgency: options.urgency,\n\t\t\tfallback,\n\t\t});\n\t\tcompacted = {\n\t\t\ttext: run.text,\n\t\t\tstats: run.stats,\n\t\t\trung: run.rung,\n\t\t\t...(run.plannerModel ? { plannerModel: run.plannerModel } : {}),\n\t\t\t...(run.usage ? { usage: run.usage } : {}),\n\t\t\tkeptTail: run.keptTail,\n\t\t};\n\t}\n\tif (options.abortController.signal.aborted) throw new Error(\"Compaction cancelled\");\n\n\t// A fresh rung that had to drop the protected tail persists no tail boundary.\n\tconst firstKeptEntryId = compacted.keptTail ? preparation.firstKeptEntryId : null;\n\tconst backupPath = this.sessionManager.writeBackupSnapshot(options.backupLabel);\n\tconst details: VerbatimCompactionDetails = {\n\t\tstrategy: VERBATIM_COMPACTION_STRATEGY,\n\t\tpromptVersion: VERBATIM_COMPACTION_PROMPT_VERSION,\n\t\tparameters: preparation.parameters,\n\t\tstats: compacted.stats,\n\t\trung: compacted.rung,\n\t\t...(compacted.plannerModel ? { plannerModel: compacted.plannerModel } : {}),\n\t\t...(backupPath ? { backupPath } : {}),\n\t};\n\tconst entryId = this.sessionManager.appendCompaction(\n\t\tcompacted.text,\n\t\tfirstKeptEntryId,\n\t\tpreparation.tokensBefore,\n\t\tdetails,\n\t\tcompacted.usage,\n\t);\n\tthis.agent.state.messages = this.sessionManager.buildSessionContext().messages;\n\tconst result: VerbatimCompactionResult = {\n\t\tcompactedText: compacted.text,\n\t\tfirstKeptEntryId,\n\t\ttokensBefore: preparation.tokensBefore,\n\t\tstats: compacted.stats,\n\t\tparameters: preparation.parameters,\n\t\tpromptVersion: VERBATIM_COMPACTION_PROMPT_VERSION,\n\t\trung: compacted.rung,\n\t\t...(compacted.plannerModel ? { plannerModel: compacted.plannerModel } : {}),\n\t\t...(compacted.usage ? { usage: compacted.usage } : {}),\n\t\t...(backupPath ? { backupPath } : {}),\n\t};\n\tconst compactionEntry = this.sessionManager.getEntry(entryId) as CompactionEntry<VerbatimCompactionDetails>;\n\ttry {\n\t\tawait this._extensionRunner.emit({\n\t\t\ttype: \"session_compact\",\n\t\t\treason: options.reason,\n\t\t\tparameters: preparation.parameters,\n\t\t\tresult,\n\t\t\tcompactionEntry,\n\t\t\tfromExtension,\n\t\t} satisfies SessionCompactEvent);\n\t} catch (error) {\n\t\tthis._extensionRunner.emitError({\n\t\t\textensionPath: \"<session_compact>\",\n\t\t\tevent: \"session_compact\",\n\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\tstack: error instanceof Error ? error.stack : undefined,\n\t\t});\n\t}\n\treturn result;\n}\n\nexport async function emitSessionCompactFailed(\n\tsession: AgentSession,\n\tevent: Omit<SessionCompactFailedEvent, \"type\">,\n): Promise<void> {\n\tif (session._extensionRunner?.hasHandlers(\"session_compact_failed\")) {\n\t\tawait session._extensionRunner.emit({ type: \"session_compact_failed\", ...event });\n\t}\n}\n\nfunction clearOwnedManualCompactionState(this: AgentSession, controller: AbortController): void {\n\tif (this._compactionAbortController !== controller) return;\n\tthis._compactionAbortController = undefined;\n\tif (this._compactionReason === \"manual\") this._compactionReason = undefined;\n\t// Lifecycle listeners run synchronously. Once the manual end event is\n\t// emitted, a new /compact must own a new run rather than join the settled one.\n\tthis._manualCompactionPromise = undefined;\n}\n\nasync function emitManualCompactionFailure(\n\tthis: AgentSession,\n\tcontroller: AbortController,\n\terror: unknown,\n\tfromExtension: boolean,\n): Promise<void> {\n\tconst message = error instanceof Error ? error.message : String(error);\n\tconst aborted = message === \"Compaction cancelled\" || (error instanceof Error && error.name === \"AbortError\");\n\tconst errorMessage = aborted ? undefined : `Compaction failed: ${message}`;\n\tclearOwnedManualCompactionState.call(this, controller);\n\tthis._emit({\n\t\ttype: \"compaction_end\",\n\t\treason: \"manual\",\n\t\tresult: undefined,\n\t\taborted,\n\t\twillRetry: false,\n\t\terrorMessage,\n\t});\n\tawait emitSessionCompactFailed(this, {\n\t\treason: \"manual\",\n\t\terrorMessage,\n\t\taborted,\n\t\twillRetry: false,\n\t\tfromExtension,\n\t});\n}\n\nasync function runOwnedManualCompaction(\n\tthis: AgentSession,\n\tcontroller: AbortController,\n\toptions: Partial<VerbatimCompactionParameters>,\n): Promise<VerbatimCompactionResult> {\n\tthis._emit({ type: \"compaction_start\", reason: \"manual\" });\n\tlet fromExtension = false;\n\ttry {\n\t\tif (!this.model) throw new Error(formatNoModelSelectedMessage());\n\t\tconst result = await this._applyVerbatimCompaction({\n\t\t\t// Caller parameters are projected explicitly, so no extra runtime\n\t\t\t// property survives. A widened or cast object could otherwise carry\n\t\t\t// `urgency: \"load_bearing\"` through a public `session.compact()` call and\n\t\t\t// reach the context-destroying rung, which manual compaction must never do.\n\t\t\t...(options.compression_ratio === undefined ? {} : { compression_ratio: options.compression_ratio }),\n\t\t\t...(options.preserve_recent === undefined ? {} : { preserve_recent: options.preserve_recent }),\n\t\t\t...(options.query === undefined ? {} : { query: options.query }),\n\t\t\tresolvePlannerAuth: (candidate) => this._getRequiredRequestAuth(candidate),\n\t\t\tabortController: controller,\n\t\t\tbackupLabel: \"compact\",\n\t\t\treason: \"manual\",\n\t\t\turgency: \"recoverable\",\n\t\t\tonCompactionSource: (value) => {\n\t\t\t\tfromExtension = value;\n\t\t\t},\n\t\t});\n\t\tif (!result) throw new Error(\"Nothing to compact (session too small)\");\n\t\t// compaction_end listeners synchronously flush queued prompts, so they must\n\t\t// observe an idle session before dispatching the next user turn.\n\t\tclearOwnedManualCompactionState.call(this, controller);\n\t\tthis._emit({ type: \"compaction_end\", reason: \"manual\", result, aborted: false, willRetry: false });\n\t\treturn result;\n\t} catch (error) {\n\t\tawait emitManualCompactionFailure.call(this, controller, error, fromExtension);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Persist one verbatim line-subset compaction boundary.\n *\n * Re-entrancy safe: a call made while a manual compaction is still in flight\n * joins that run instead of starting a second one. Manual compaction aborts an\n * active agent run before it starts, while agent event delivery remains live so\n * a pending threshold check cannot race the requested manual boundary.\n */\nexport function compact(\n\tthis: AgentSession,\n\toptions: Partial<VerbatimCompactionParameters> = {},\n): Promise<VerbatimCompactionResult> {\n\tconst inFlight = this._manualCompactionPromise;\n\tif (inFlight) return inFlight;\n\n\t// A manual boundary replaces the automatic turn that scheduled any pending\n\t// retry. Invalidate its timer before this run claims compaction ownership.\n\tthis._postCompactionContinuationToken += 1;\n\tthis._pendingPostCompactionContinuation = undefined;\n\n\tconst automaticCompletion = this._autoCompactionCompletion;\n\t// The manual request wins. Abort the active automatic planner now, before the\n\t// next microtask can admit a post-tool or threshold boundary, then wait for\n\t// its owner to settle before mutating the transcript ourselves. Start the\n\t// session abort before publishing this new manual owner so abort() cancels\n\t// prior work rather than cancelling or waiting on the compaction being started.\n\tthis._autoCompactionAbortController?.abort();\n\tconst abortBoundary = this.abort();\n\n\tconst controller = new AbortController();\n\tthis._compactionAbortController = controller;\n\tthis._compactionReason = \"manual\";\n\t// Handle rejection now so a failing event drain cannot become unhandled\n\t// while an automatic run finishes.\n\tvoid abortBoundary.catch(() => {});\n\tlet flight!: Promise<VerbatimCompactionResult>;\n\t// Start the owned run in a microtask so both single-flight fields are\n\t// published before any joiner can observe a partially claimed compaction.\n\tflight = Promise.resolve()\n\t\t.then(async () => {\n\t\t\ttry {\n\t\t\t\tif (automaticCompletion !== undefined) await automaticCompletion;\n\t\t\t\tawait abortBoundary;\n\t\t\t} catch (error) {\n\t\t\t\t// The abort drain can fail before the planner starts. Finish the\n\t\t\t\t// manual lifecycle so event consumers can release queued input.\n\t\t\t\tawait emitManualCompactionFailure.call(this, controller, error, false);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\treturn runOwnedManualCompaction.call(this, controller, options);\n\t\t})\n\t\t.finally(() => {\n\t\t\tclearOwnedManualCompactionState.call(this, controller);\n\t\t\tif (this._manualCompactionPromise === flight) this._manualCompactionPromise = undefined;\n\t\t});\n\tthis._manualCompactionPromise = flight;\n\treturn flight;\n}\n\nexport function abortCompaction(this: AgentSession): void {\n\tthis._compactionAbortController?.abort();\n\tthis._autoCompactionAbortController?.abort();\n}\nexport function abortBranchSummary(this: AgentSession): void {\n\tthis._branchSummaryAbortController?.abort();\n}\nexport function setAutoCompactionEnabled(this: AgentSession, enabled: boolean): void {\n\tthis.settingsManager.setCompactionEnabled(enabled);\n}\n\nexport const agentSessionCompactionMethods = {\n\t_applyVerbatimCompaction,\n\tcompact,\n\tabortCompaction,\n\tabortBranchSummary,\n\tsetAutoCompactionEnabled,\n};\n"]}
@@ -1,8 +1,36 @@
1
1
  import type { SessionEntry } from "../session-manager-types.ts";
2
2
  import { type CompactionSettings } from "./compaction.ts";
3
3
  import { type VerbatimCompactionParameters, type VerbatimCompactionPreparation } from "./compaction-types.js";
4
- /** Return the independently estimated cost of the protected tail. */
4
+ /**
5
+ * Return the independently estimated cost of the protected tail.
6
+ *
7
+ * Only the explicit estimate recorded by `prepareCompactionBoundary` (or a test)
8
+ * is returned. The old fallback of `tokensBefore - region.tokenEstimate` was
9
+ * removed because it mixed the authoritative whole-context count with the
10
+ * heuristic region estimate; when no explicit estimate exists the tail simply
11
+ * contributes nothing rather than a wrong-numbered value. Whether an estimate is
12
+ * registered at all is visible through `hasKeptTailTokenEstimate`, which the
13
+ * fresh rung uses to decide a tail whose size is unknown (P1 #3010).
14
+ */
5
15
  export declare function getKeptTailTokenEstimate(preparation: VerbatimCompactionPreparation): number;
16
+ /**
17
+ * Whether an independent tail estimate is registered for this preparation.
18
+ *
19
+ * A preparation built by `prepareCompactionBoundary` always has one. A directly
20
+ * constructed preparation may not; the fresh rung treats a kept tail whose size
21
+ * is unregistered as unknown and drops it conservatively rather than assuming it
22
+ * fits (P1 #3010).
23
+ */
24
+ export declare function hasKeptTailTokenEstimate(preparation: VerbatimCompactionPreparation): boolean;
25
+ /**
26
+ * Record the independent tail estimate for a preparation.
27
+ *
28
+ * `prepareCompactionBoundary` does this itself from the kept-tail messages;
29
+ * this setter is for test preparations built directly and for any other code
30
+ * that constructs a `VerbatimCompactionPreparation` without the boundary
31
+ * preparer. The estimate lives in a module-private map and is never persisted.
32
+ */
33
+ export declare function setKeptTailTokenEstimate(preparation: VerbatimCompactionPreparation, estimate: number): void;
6
34
  export declare function autoDetectCompactionQuery(entries: readonly SessionEntry[]): string;
7
35
  /**
8
36
  * Planner eligibility, kept separate from boundary preparation.
@@ -1 +1 @@
1
- {"version":3,"file":"compaction-boundary.d.ts","sourceRoot":"","sources":["../../../src/core/compaction/compaction-boundary.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAmB,YAAY,EAAE,MAAM,6BAA6B,CAAC;AACjF,OAAO,EAAE,KAAK,kBAAkB,EAAyC,MAAM,iBAAiB,CAAC;AAMjG,OAAO,EAIN,KAAK,4BAA4B,EACjC,KAAK,6BAA6B,EAClC,MAAM,uBAAuB,CAAC;AAW/B,qEAAqE;AACrE,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,6BAA6B,GAAG,MAAM,CAK3F;AAgDD,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,GAAG,MAAM,CASlF;AAYD;;;;;;;;GAQG;AACH,MAAM,WAAW,yBAAyB;IACzC;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,8FAA8F;AAC9F,wBAAgB,yBAAyB,CACxC,WAAW,EAAE,YAAY,EAAE,EAC3B,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,GAAE,OAAO,CAAC,4BAA4B,CAAM,EACnD,OAAO,GAAE,yBAA8B,GACrC,6BAA6B,GAAG,SAAS,CAuC3C"}
1
+ {"version":3,"file":"compaction-boundary.d.ts","sourceRoot":"","sources":["../../../src/core/compaction/compaction-boundary.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK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