@earendil-works/pi-coding-agent 0.86.1 → 0.87.0

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 (114) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +36 -0
  3. package/dist/bundle/chunks/{chunk-CMRUVXTE.js → chunk-4DKZACXI.js} +38 -32
  4. package/dist/bundle/chunks/chunk-GV2E3GBU.js +2 -0
  5. package/dist/bundle/chunks/github-copilot.js +1 -1
  6. package/dist/bundle/chunks/{openai-completions-CYGM3XXP.js → openai-completions-XHML6MTL.js} +1 -1
  7. package/dist/bundle/chunks/{virtual-modules-MGTKWDID.js → virtual-modules-BNWPZYDH.js} +1 -1
  8. package/dist/bundle/cli-runtime.js +1 -1
  9. package/dist/bundle/index.js +1 -1
  10. package/dist/bundle/rpc-entry.js +1 -1
  11. package/dist/cli/file-processor.d.ts +1 -1
  12. package/dist/cli/file-processor.d.ts.map +1 -1
  13. package/dist/cli/file-processor.js.map +1 -1
  14. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  15. package/dist/core/agent-session-runtime.js +1 -1
  16. package/dist/core/agent-session-runtime.js.map +1 -1
  17. package/dist/core/agent-session.d.ts +27 -3
  18. package/dist/core/agent-session.d.ts.map +1 -1
  19. package/dist/core/agent-session.js +389 -119
  20. package/dist/core/agent-session.js.map +1 -1
  21. package/dist/core/cache-warmer.d.ts +1 -0
  22. package/dist/core/cache-warmer.d.ts.map +1 -1
  23. package/dist/core/cache-warmer.js +15 -1
  24. package/dist/core/cache-warmer.js.map +1 -1
  25. package/dist/core/compaction/compaction.d.ts +3 -1
  26. package/dist/core/compaction/compaction.d.ts.map +1 -1
  27. package/dist/core/compaction/compaction.js +146 -48
  28. package/dist/core/compaction/compaction.js.map +1 -1
  29. package/dist/core/crash-log.d.ts +5 -0
  30. package/dist/core/crash-log.d.ts.map +1 -1
  31. package/dist/core/crash-log.js +68 -0
  32. package/dist/core/crash-log.js.map +1 -1
  33. package/dist/core/export-html/template.js +6 -1
  34. package/dist/core/extensions/index.d.ts +1 -1
  35. package/dist/core/extensions/index.d.ts.map +1 -1
  36. package/dist/core/extensions/index.js.map +1 -1
  37. package/dist/core/extensions/runner.d.ts +16 -3
  38. package/dist/core/extensions/runner.d.ts.map +1 -1
  39. package/dist/core/extensions/runner.js +110 -5
  40. package/dist/core/extensions/runner.js.map +1 -1
  41. package/dist/core/extensions/types.d.ts +77 -6
  42. package/dist/core/extensions/types.d.ts.map +1 -1
  43. package/dist/core/extensions/types.js.map +1 -1
  44. package/dist/core/index.d.ts +1 -1
  45. package/dist/core/index.d.ts.map +1 -1
  46. package/dist/core/index.js.map +1 -1
  47. package/dist/core/model-config.d.ts +52 -0
  48. package/dist/core/model-config.d.ts.map +1 -1
  49. package/dist/core/model-config.js +16 -0
  50. package/dist/core/model-config.js.map +1 -1
  51. package/dist/core/prompt-templates.d.ts +6 -1
  52. package/dist/core/prompt-templates.d.ts.map +1 -1
  53. package/dist/core/prompt-templates.js +61 -35
  54. package/dist/core/prompt-templates.js.map +1 -1
  55. package/dist/core/provider-composer.d.ts +1 -0
  56. package/dist/core/provider-composer.d.ts.map +1 -1
  57. package/dist/core/provider-composer.js +19 -0
  58. package/dist/core/provider-composer.js.map +1 -1
  59. package/dist/core/resource-loader.d.ts.map +1 -1
  60. package/dist/core/resource-loader.js +6 -2
  61. package/dist/core/resource-loader.js.map +1 -1
  62. package/dist/core/sdk.d.ts.map +1 -1
  63. package/dist/core/sdk.js +3 -4
  64. package/dist/core/sdk.js.map +1 -1
  65. package/dist/core/session-manager.d.ts +36 -9
  66. package/dist/core/session-manager.d.ts.map +1 -1
  67. package/dist/core/session-manager.js +97 -7
  68. package/dist/core/session-manager.js.map +1 -1
  69. package/dist/core/tools/read.d.ts +4 -1
  70. package/dist/core/tools/read.d.ts.map +1 -1
  71. package/dist/core/tools/read.js +5 -1
  72. package/dist/core/tools/read.js.map +1 -1
  73. package/dist/index.d.ts +2 -2
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +1 -1
  76. package/dist/index.js.map +1 -1
  77. package/dist/main.d.ts.map +1 -1
  78. package/dist/main.js +4 -3
  79. package/dist/main.js.map +1 -1
  80. package/dist/modes/interactive/bug-report.d.ts.map +1 -1
  81. package/dist/modes/interactive/bug-report.js +4 -0
  82. package/dist/modes/interactive/bug-report.js.map +1 -1
  83. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  84. package/dist/modes/interactive/components/tree-selector.js +7 -0
  85. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  86. package/dist/modes/interactive/interactive-mode.d.ts +3 -0
  87. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  88. package/dist/modes/interactive/interactive-mode.js +64 -2
  89. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  90. package/dist/utils/mime.d.ts.map +1 -1
  91. package/dist/utils/mime.js +1 -1
  92. package/dist/utils/mime.js.map +1 -1
  93. package/dist/utils/tool-result-images.d.ts +3 -1
  94. package/dist/utils/tool-result-images.d.ts.map +1 -1
  95. package/dist/utils/tool-result-images.js +4 -1
  96. package/dist/utils/tool-result-images.js.map +1 -1
  97. package/docs/compaction.md +23 -4
  98. package/docs/extensions.md +70 -6
  99. package/docs/models.md +29 -1
  100. package/docs/sdk.md +13 -2
  101. package/docs/session-format.md +15 -2
  102. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  103. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  104. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  105. package/examples/extensions/gondolin/package-lock.json +2 -2
  106. package/examples/extensions/gondolin/package.json +1 -1
  107. package/examples/extensions/sandbox/package-lock.json +2 -2
  108. package/examples/extensions/sandbox/package.json +1 -1
  109. package/examples/extensions/with-deps/package-lock.json +2 -2
  110. package/examples/extensions/with-deps/package.json +1 -1
  111. package/examples/plugins/pi-example-plugin/src/session.ts +3 -2
  112. package/npm-shrinkwrap.json +20 -20
  113. package/package.json +8 -8
  114. package/dist/bundle/chunks/chunk-HTEQD2HM.js +0 -2
@@ -1 +1 @@
1
- {"version":3,"file":"mime.d.ts","sourceRoot":"","sources":["../../src/utils/mime.ts"],"names":[],"mappings":"AAKA,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAiB9E;AAED,wBAAsB,oCAAoC,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CASnG","sourcesContent":["import { open } from \"node:fs/promises\";\n\nconst IMAGE_TYPE_SNIFF_BYTES = 4100;\nconst PNG_SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];\n\nexport function detectSupportedImageMimeType(buffer: Uint8Array): string | null {\n\tif (startsWith(buffer, [0xff, 0xd8, 0xff])) {\n\t\treturn buffer[3] === 0xf7 ? null : \"image/jpeg\";\n\t}\n\tif (startsWith(buffer, PNG_SIGNATURE)) {\n\t\treturn isPng(buffer) && !isAnimatedPng(buffer) ? \"image/png\" : null;\n\t}\n\tif (startsWithAscii(buffer, 0, \"GIF\")) {\n\t\treturn \"image/gif\";\n\t}\n\tif (startsWithAscii(buffer, 0, \"RIFF\") && startsWithAscii(buffer, 8, \"WEBP\")) {\n\t\treturn \"image/webp\";\n\t}\n\tif (startsWithAscii(buffer, 0, \"BM\") && isBmp(buffer)) {\n\t\treturn \"image/bmp\";\n\t}\n\treturn null;\n}\n\nexport async function detectSupportedImageMimeTypeFromFile(filePath: string): Promise<string | null> {\n\tconst fileHandle = await open(filePath, \"r\");\n\ttry {\n\t\tconst buffer = Buffer.alloc(IMAGE_TYPE_SNIFF_BYTES);\n\t\tconst { bytesRead } = await fileHandle.read(buffer, 0, IMAGE_TYPE_SNIFF_BYTES, 0);\n\t\treturn detectSupportedImageMimeType(buffer.subarray(0, bytesRead));\n\t} finally {\n\t\tawait fileHandle.close();\n\t}\n}\n\nfunction isPng(buffer: Uint8Array): boolean {\n\treturn (\n\t\tbuffer.length >= 16 && readUint32BE(buffer, PNG_SIGNATURE.length) === 13 && startsWithAscii(buffer, 12, \"IHDR\")\n\t);\n}\n\nfunction isAnimatedPng(buffer: Uint8Array): boolean {\n\tlet offset = PNG_SIGNATURE.length;\n\twhile (offset + 8 <= buffer.length) {\n\t\tconst chunkLength = readUint32BE(buffer, offset);\n\t\tconst chunkTypeOffset = offset + 4;\n\t\tif (startsWithAscii(buffer, chunkTypeOffset, \"acTL\")) return true;\n\t\tif (startsWithAscii(buffer, chunkTypeOffset, \"IDAT\")) return false;\n\n\t\tconst nextOffset = offset + 8 + chunkLength + 4;\n\t\tif (nextOffset <= offset || nextOffset > buffer.length) return false;\n\t\toffset = nextOffset;\n\t}\n\treturn false;\n}\n\nfunction isBmp(buffer: Uint8Array): boolean {\n\tif (buffer.length < 26) return false;\n\n\tconst declaredFileSize = readUint32LE(buffer, 2);\n\tconst pixelDataOffset = readUint32LE(buffer, 10);\n\tconst dibHeaderSize = readUint32LE(buffer, 14);\n\tif (declaredFileSize !== 0 && declaredFileSize < 26) return false;\n\tif (pixelDataOffset < 14 + dibHeaderSize) return false;\n\tif (declaredFileSize !== 0 && pixelDataOffset >= declaredFileSize) return false;\n\n\tlet colorPlanes: number;\n\tlet bitsPerPixel: number;\n\tif (dibHeaderSize === 12) {\n\t\tcolorPlanes = readUint16LE(buffer, 22);\n\t\tbitsPerPixel = readUint16LE(buffer, 24);\n\t} else if (dibHeaderSize >= 40 && dibHeaderSize <= 124) {\n\t\tif (buffer.length < 30) return false;\n\t\tcolorPlanes = readUint16LE(buffer, 26);\n\t\tbitsPerPixel = readUint16LE(buffer, 28);\n\t} else {\n\t\treturn false;\n\t}\n\n\treturn colorPlanes === 1 && [1, 4, 8, 16, 24, 32].includes(bitsPerPixel);\n}\n\nfunction readUint16LE(buffer: Uint8Array, offset: number): number {\n\treturn (buffer[offset] ?? 0) + ((buffer[offset + 1] ?? 0) << 8);\n}\n\nfunction readUint32BE(buffer: Uint8Array, offset: number): number {\n\treturn (\n\t\t(buffer[offset] ?? 0) * 0x1000000 +\n\t\t((buffer[offset + 1] ?? 0) << 16) +\n\t\t((buffer[offset + 2] ?? 0) << 8) +\n\t\t(buffer[offset + 3] ?? 0)\n\t);\n}\n\nfunction readUint32LE(buffer: Uint8Array, offset: number): number {\n\treturn (\n\t\t(buffer[offset] ?? 0) +\n\t\t((buffer[offset + 1] ?? 0) << 8) +\n\t\t((buffer[offset + 2] ?? 0) << 16) +\n\t\t(buffer[offset + 3] ?? 0) * 0x1000000\n\t);\n}\n\nfunction startsWith(buffer: Uint8Array, bytes: number[]): boolean {\n\tif (buffer.length < bytes.length) return false;\n\treturn bytes.every((byte, index) => buffer[index] === byte);\n}\n\nfunction startsWithAscii(buffer: Uint8Array, offset: number, text: string): boolean {\n\tif (buffer.length < offset + text.length) return false;\n\tfor (let index = 0; index < text.length; index++) {\n\t\tif (buffer[offset + index] !== text.charCodeAt(index)) return false;\n\t}\n\treturn true;\n}\n"]}
1
+ {"version":3,"file":"mime.d.ts","sourceRoot":"","sources":["../../src/utils/mime.ts"],"names":[],"mappings":"AAKA,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAiB9E;AAED,wBAAsB,oCAAoC,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CASnG","sourcesContent":["import { open } from \"node:fs/promises\";\n\nconst IMAGE_TYPE_SNIFF_BYTES = 4100;\nconst PNG_SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];\n\nexport function detectSupportedImageMimeType(buffer: Uint8Array): string | null {\n\tif (startsWith(buffer, [0xff, 0xd8, 0xff])) {\n\t\treturn buffer[3] === 0xf7 ? null : \"image/jpeg\";\n\t}\n\tif (startsWith(buffer, PNG_SIGNATURE)) {\n\t\treturn isPng(buffer) && !isAnimatedPng(buffer) ? \"image/png\" : null;\n\t}\n\tif (startsWithAscii(buffer, 0, \"GIF87a\") || startsWithAscii(buffer, 0, \"GIF89a\")) {\n\t\treturn \"image/gif\";\n\t}\n\tif (startsWithAscii(buffer, 0, \"RIFF\") && startsWithAscii(buffer, 8, \"WEBP\")) {\n\t\treturn \"image/webp\";\n\t}\n\tif (startsWithAscii(buffer, 0, \"BM\") && isBmp(buffer)) {\n\t\treturn \"image/bmp\";\n\t}\n\treturn null;\n}\n\nexport async function detectSupportedImageMimeTypeFromFile(filePath: string): Promise<string | null> {\n\tconst fileHandle = await open(filePath, \"r\");\n\ttry {\n\t\tconst buffer = Buffer.alloc(IMAGE_TYPE_SNIFF_BYTES);\n\t\tconst { bytesRead } = await fileHandle.read(buffer, 0, IMAGE_TYPE_SNIFF_BYTES, 0);\n\t\treturn detectSupportedImageMimeType(buffer.subarray(0, bytesRead));\n\t} finally {\n\t\tawait fileHandle.close();\n\t}\n}\n\nfunction isPng(buffer: Uint8Array): boolean {\n\treturn (\n\t\tbuffer.length >= 16 && readUint32BE(buffer, PNG_SIGNATURE.length) === 13 && startsWithAscii(buffer, 12, \"IHDR\")\n\t);\n}\n\nfunction isAnimatedPng(buffer: Uint8Array): boolean {\n\tlet offset = PNG_SIGNATURE.length;\n\twhile (offset + 8 <= buffer.length) {\n\t\tconst chunkLength = readUint32BE(buffer, offset);\n\t\tconst chunkTypeOffset = offset + 4;\n\t\tif (startsWithAscii(buffer, chunkTypeOffset, \"acTL\")) return true;\n\t\tif (startsWithAscii(buffer, chunkTypeOffset, \"IDAT\")) return false;\n\n\t\tconst nextOffset = offset + 8 + chunkLength + 4;\n\t\tif (nextOffset <= offset || nextOffset > buffer.length) return false;\n\t\toffset = nextOffset;\n\t}\n\treturn false;\n}\n\nfunction isBmp(buffer: Uint8Array): boolean {\n\tif (buffer.length < 26) return false;\n\n\tconst declaredFileSize = readUint32LE(buffer, 2);\n\tconst pixelDataOffset = readUint32LE(buffer, 10);\n\tconst dibHeaderSize = readUint32LE(buffer, 14);\n\tif (declaredFileSize !== 0 && declaredFileSize < 26) return false;\n\tif (pixelDataOffset < 14 + dibHeaderSize) return false;\n\tif (declaredFileSize !== 0 && pixelDataOffset >= declaredFileSize) return false;\n\n\tlet colorPlanes: number;\n\tlet bitsPerPixel: number;\n\tif (dibHeaderSize === 12) {\n\t\tcolorPlanes = readUint16LE(buffer, 22);\n\t\tbitsPerPixel = readUint16LE(buffer, 24);\n\t} else if (dibHeaderSize >= 40 && dibHeaderSize <= 124) {\n\t\tif (buffer.length < 30) return false;\n\t\tcolorPlanes = readUint16LE(buffer, 26);\n\t\tbitsPerPixel = readUint16LE(buffer, 28);\n\t} else {\n\t\treturn false;\n\t}\n\n\treturn colorPlanes === 1 && [1, 4, 8, 16, 24, 32].includes(bitsPerPixel);\n}\n\nfunction readUint16LE(buffer: Uint8Array, offset: number): number {\n\treturn (buffer[offset] ?? 0) + ((buffer[offset + 1] ?? 0) << 8);\n}\n\nfunction readUint32BE(buffer: Uint8Array, offset: number): number {\n\treturn (\n\t\t(buffer[offset] ?? 0) * 0x1000000 +\n\t\t((buffer[offset + 1] ?? 0) << 16) +\n\t\t((buffer[offset + 2] ?? 0) << 8) +\n\t\t(buffer[offset + 3] ?? 0)\n\t);\n}\n\nfunction readUint32LE(buffer: Uint8Array, offset: number): number {\n\treturn (\n\t\t(buffer[offset] ?? 0) +\n\t\t((buffer[offset + 1] ?? 0) << 8) +\n\t\t((buffer[offset + 2] ?? 0) << 16) +\n\t\t(buffer[offset + 3] ?? 0) * 0x1000000\n\t);\n}\n\nfunction startsWith(buffer: Uint8Array, bytes: number[]): boolean {\n\tif (buffer.length < bytes.length) return false;\n\treturn bytes.every((byte, index) => buffer[index] === byte);\n}\n\nfunction startsWithAscii(buffer: Uint8Array, offset: number, text: string): boolean {\n\tif (buffer.length < offset + text.length) return false;\n\tfor (let index = 0; index < text.length; index++) {\n\t\tif (buffer[offset + index] !== text.charCodeAt(index)) return false;\n\t}\n\treturn true;\n}\n"]}
@@ -8,7 +8,7 @@ export function detectSupportedImageMimeType(buffer) {
8
8
  if (startsWith(buffer, PNG_SIGNATURE)) {
9
9
  return isPng(buffer) && !isAnimatedPng(buffer) ? "image/png" : null;
10
10
  }
11
- if (startsWithAscii(buffer, 0, "GIF")) {
11
+ if (startsWithAscii(buffer, 0, "GIF87a") || startsWithAscii(buffer, 0, "GIF89a")) {
12
12
  return "image/gif";
13
13
  }
14
14
  if (startsWithAscii(buffer, 0, "RIFF") && startsWithAscii(buffer, 8, "WEBP")) {
@@ -1 +1 @@
1
- {"version":3,"file":"mime.js","sourceRoot":"","sources":["../../src/utils/mime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,MAAM,sBAAsB,GAAG,IAAI,CAAC;AACpC,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAEvE,MAAM,UAAU,4BAA4B,CAAC,MAAkB,EAAiB;IAC/E,IAAI,UAAU,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC;QAC5C,OAAO,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC;IACjD,CAAC;IACD,IAAI,UAAU,CAAC,MAAM,EAAE,aAAa,CAAC,EAAE,CAAC;QACvC,OAAO,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC;IACrE,CAAC;IACD,IAAI,eAAe,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC;QACvC,OAAO,WAAW,CAAC;IACpB,CAAC;IACD,IAAI,eAAe,CAAC,MAAM,EAAE,CAAC,EAAE,MA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,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;QAChC,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;QACjC,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,CACrC,CAAC;AAAA,CACF;AAED,SAAS,UAAU,CAAC,MAAkB,EAAE,KAAe,EAAW;IACjE,IAAI,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAC/C,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC;AAAA,CAC5D;AAED,SAAS,eAAe,CAAC,MAAkB,EAAE,MAAc,EAAE,IAAY,EAAW;IACnF,IAAI,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IACvD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QAClD,IAAI,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC,KAAK,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;IACrE,CAAC;IACD,OAAO,IAAI,CAAC;AAAA,CACZ","sourcesContent":["import { open } from \"node:fs/promises\";\n\nconst IMAGE_TYPE_SNIFF_BYTES = 4100;\nconst PNG_SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];\n\nexport function detectSupportedImageMimeType(buffer: Uint8Array): string | null {\n\tif (startsWith(buffer, [0xff, 0xd8, 0xff])) {\n\t\treturn buffer[3] === 0xf7 ? null : \"image/jpeg\";\n\t}\n\tif (startsWith(buffer, PNG_SIGNATURE)) {\n\t\treturn isPng(buffer) && !isAnimatedPng(buffer) ? \"image/png\" : null;\n\t}\n\tif (startsWithAscii(buffer, 0, \"GIF\")) {\n\t\treturn \"image/gif\";\n\t}\n\tif (startsWithAscii(buffer, 0, \"RIFF\") && startsWithAscii(buffer, 8, \"WEBP\")) {\n\t\treturn \"image/webp\";\n\t}\n\tif (startsWithAscii(buffer, 0, \"BM\") && isBmp(buffer)) {\n\t\treturn \"image/bmp\";\n\t}\n\treturn null;\n}\n\nexport async function detectSupportedImageMimeTypeFromFile(filePath: string): Promise<string | null> {\n\tconst fileHandle = await open(filePath, \"r\");\n\ttry {\n\t\tconst buffer = Buffer.alloc(IMAGE_TYPE_SNIFF_BYTES);\n\t\tconst { bytesRead } = await fileHandle.read(buffer, 0, IMAGE_TYPE_SNIFF_BYTES, 0);\n\t\treturn detectSupportedImageMimeType(buffer.subarray(0, bytesRead));\n\t} finally {\n\t\tawait fileHandle.close();\n\t}\n}\n\nfunction isPng(buffer: Uint8Array): boolean {\n\treturn (\n\t\tbuffer.length >= 16 && readUint32BE(buffer, PNG_SIGNATURE.length) === 13 && startsWithAscii(buffer, 12, \"IHDR\")\n\t);\n}\n\nfunction isAnimatedPng(buffer: Uint8Array): boolean {\n\tlet offset = PNG_SIGNATURE.length;\n\twhile (offset + 8 <= buffer.length) {\n\t\tconst chunkLength = readUint32BE(buffer, offset);\n\t\tconst chunkTypeOffset = offset + 4;\n\t\tif (startsWithAscii(buffer, chunkTypeOffset, \"acTL\")) return true;\n\t\tif (startsWithAscii(buffer, chunkTypeOffset, \"IDAT\")) return false;\n\n\t\tconst nextOffset = offset + 8 + chunkLength + 4;\n\t\tif (nextOffset <= offset || nextOffset > buffer.length) return false;\n\t\toffset = nextOffset;\n\t}\n\treturn false;\n}\n\nfunction isBmp(buffer: Uint8Array): boolean {\n\tif (buffer.length < 26) return false;\n\n\tconst declaredFileSize = readUint32LE(buffer, 2);\n\tconst pixelDataOffset = readUint32LE(buffer, 10);\n\tconst dibHeaderSize = readUint32LE(buffer, 14);\n\tif (declaredFileSize !== 0 && declaredFileSize < 26) return false;\n\tif (pixelDataOffset < 14 + dibHeaderSize) return false;\n\tif (declaredFileSize !== 0 && pixelDataOffset >= declaredFileSize) return false;\n\n\tlet colorPlanes: number;\n\tlet bitsPerPixel: number;\n\tif (dibHeaderSize === 12) {\n\t\tcolorPlanes = readUint16LE(buffer, 22);\n\t\tbitsPerPixel = readUint16LE(buffer, 24);\n\t} else if (dibHeaderSize >= 40 && dibHeaderSize <= 124) {\n\t\tif (buffer.length < 30) return false;\n\t\tcolorPlanes = readUint16LE(buffer, 26);\n\t\tbitsPerPixel = readUint16LE(buffer, 28);\n\t} else {\n\t\treturn false;\n\t}\n\n\treturn colorPlanes === 1 && [1, 4, 8, 16, 24, 32].includes(bitsPerPixel);\n}\n\nfunction readUint16LE(buffer: Uint8Array, offset: number): number {\n\treturn (buffer[offset] ?? 0) + ((buffer[offset + 1] ?? 0) << 8);\n}\n\nfunction readUint32BE(buffer: Uint8Array, offset: number): number {\n\treturn (\n\t\t(buffer[offset] ?? 0) * 0x1000000 +\n\t\t((buffer[offset + 1] ?? 0) << 16) +\n\t\t((buffer[offset + 2] ?? 0) << 8) +\n\t\t(buffer[offset + 3] ?? 0)\n\t);\n}\n\nfunction readUint32LE(buffer: Uint8Array, offset: number): number {\n\treturn (\n\t\t(buffer[offset] ?? 0) +\n\t\t((buffer[offset + 1] ?? 0) << 8) +\n\t\t((buffer[offset + 2] ?? 0) << 16) +\n\t\t(buffer[offset + 3] ?? 0) * 0x1000000\n\t);\n}\n\nfunction startsWith(buffer: Uint8Array, bytes: number[]): boolean {\n\tif (buffer.length < bytes.length) return false;\n\treturn bytes.every((byte, index) => buffer[index] === byte);\n}\n\nfunction startsWithAscii(buffer: Uint8Array, offset: number, text: string): boolean {\n\tif (buffer.length < offset + text.length) return false;\n\tfor (let index = 0; index < text.length; index++) {\n\t\tif (buffer[offset + index] !== text.charCodeAt(index)) return false;\n\t}\n\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AED,SAAS,UAAU,CAAC,MAAkB,EAAE,KAAe,EAAW;IACjE,IAAI,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAC/C,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC;AAAA,CAC5D;AAED,SAAS,eAAe,CAAC,MAAkB,EAAE,MAAc,EAAE,IAAY,EAAW;IACnF,IAAI,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IACvD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QAClD,IAAI,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC,KAAK,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;IACrE,CAAC;IACD,OAAO,IAAI,CAAC;AAAA,CACZ","sourcesContent":["import { open } from \"node:fs/promises\";\n\nconst IMAGE_TYPE_SNIFF_BYTES = 4100;\nconst PNG_SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];\n\nexport function detectSupportedImageMimeType(buffer: Uint8Array): string | null {\n\tif (startsWith(buffer, [0xff, 0xd8, 0xff])) {\n\t\treturn buffer[3] === 0xf7 ? null : \"image/jpeg\";\n\t}\n\tif (startsWith(buffer, PNG_SIGNATURE)) {\n\t\treturn isPng(buffer) && !isAnimatedPng(buffer) ? \"image/png\" : null;\n\t}\n\tif (startsWithAscii(buffer, 0, \"GIF87a\") || startsWithAscii(buffer, 0, \"GIF89a\")) {\n\t\treturn \"image/gif\";\n\t}\n\tif (startsWithAscii(buffer, 0, \"RIFF\") && startsWithAscii(buffer, 8, \"WEBP\")) {\n\t\treturn \"image/webp\";\n\t}\n\tif (startsWithAscii(buffer, 0, \"BM\") && isBmp(buffer)) {\n\t\treturn \"image/bmp\";\n\t}\n\treturn null;\n}\n\nexport async function detectSupportedImageMimeTypeFromFile(filePath: string): Promise<string | null> {\n\tconst fileHandle = await open(filePath, \"r\");\n\ttry {\n\t\tconst buffer = Buffer.alloc(IMAGE_TYPE_SNIFF_BYTES);\n\t\tconst { bytesRead } = await fileHandle.read(buffer, 0, IMAGE_TYPE_SNIFF_BYTES, 0);\n\t\treturn detectSupportedImageMimeType(buffer.subarray(0, bytesRead));\n\t} finally {\n\t\tawait fileHandle.close();\n\t}\n}\n\nfunction isPng(buffer: Uint8Array): boolean {\n\treturn (\n\t\tbuffer.length >= 16 && readUint32BE(buffer, PNG_SIGNATURE.length) === 13 && startsWithAscii(buffer, 12, \"IHDR\")\n\t);\n}\n\nfunction isAnimatedPng(buffer: Uint8Array): boolean {\n\tlet offset = PNG_SIGNATURE.length;\n\twhile (offset + 8 <= buffer.length) {\n\t\tconst chunkLength = readUint32BE(buffer, offset);\n\t\tconst chunkTypeOffset = offset + 4;\n\t\tif (startsWithAscii(buffer, chunkTypeOffset, \"acTL\")) return true;\n\t\tif (startsWithAscii(buffer, chunkTypeOffset, \"IDAT\")) return false;\n\n\t\tconst nextOffset = offset + 8 + chunkLength + 4;\n\t\tif (nextOffset <= offset || nextOffset > buffer.length) return false;\n\t\toffset = nextOffset;\n\t}\n\treturn false;\n}\n\nfunction isBmp(buffer: Uint8Array): boolean {\n\tif (buffer.length < 26) return false;\n\n\tconst declaredFileSize = readUint32LE(buffer, 2);\n\tconst pixelDataOffset = readUint32LE(buffer, 10);\n\tconst dibHeaderSize = readUint32LE(buffer, 14);\n\tif (declaredFileSize !== 0 && declaredFileSize < 26) return false;\n\tif (pixelDataOffset < 14 + dibHeaderSize) return false;\n\tif (declaredFileSize !== 0 && pixelDataOffset >= declaredFileSize) return false;\n\n\tlet colorPlanes: number;\n\tlet bitsPerPixel: number;\n\tif (dibHeaderSize === 12) {\n\t\tcolorPlanes = readUint16LE(buffer, 22);\n\t\tbitsPerPixel = readUint16LE(buffer, 24);\n\t} else if (dibHeaderSize >= 40 && dibHeaderSize <= 124) {\n\t\tif (buffer.length < 30) return false;\n\t\tcolorPlanes = readUint16LE(buffer, 26);\n\t\tbitsPerPixel = readUint16LE(buffer, 28);\n\t} else {\n\t\treturn false;\n\t}\n\n\treturn colorPlanes === 1 && [1, 4, 8, 16, 24, 32].includes(bitsPerPixel);\n}\n\nfunction readUint16LE(buffer: Uint8Array, offset: number): number {\n\treturn (buffer[offset] ?? 0) + ((buffer[offset + 1] ?? 0) << 8);\n}\n\nfunction readUint32BE(buffer: Uint8Array, offset: number): number {\n\treturn (\n\t\t(buffer[offset] ?? 0) * 0x1000000 +\n\t\t((buffer[offset + 1] ?? 0) << 16) +\n\t\t((buffer[offset + 2] ?? 0) << 8) +\n\t\t(buffer[offset + 3] ?? 0)\n\t);\n}\n\nfunction readUint32LE(buffer: Uint8Array, offset: number): number {\n\treturn (\n\t\t(buffer[offset] ?? 0) +\n\t\t((buffer[offset + 1] ?? 0) << 8) +\n\t\t((buffer[offset + 2] ?? 0) << 16) +\n\t\t(buffer[offset + 3] ?? 0) * 0x1000000\n\t);\n}\n\nfunction startsWith(buffer: Uint8Array, bytes: number[]): boolean {\n\tif (buffer.length < bytes.length) return false;\n\treturn bytes.every((byte, index) => buffer[index] === byte);\n}\n\nfunction startsWithAscii(buffer: Uint8Array, offset: number, text: string): boolean {\n\tif (buffer.length < offset + text.length) return false;\n\tfor (let index = 0; index < text.length; index++) {\n\t\tif (buffer[offset + index] !== text.charCodeAt(index)) return false;\n\t}\n\treturn true;\n}\n"]}
@@ -1,8 +1,10 @@
1
- import type { ImageContent, TextContent } from "@earendil-works/pi-ai";
1
+ import type { ImageContent, ModelImageResizeOptions, TextContent } from "@earendil-works/pi-ai";
2
2
  export type ToolResultContent = TextContent | ImageContent;
3
3
  export interface NormalizeToolResultImagesOptions {
4
4
  /** Whether oversized images are resized to inline provider limits. Default: true */
5
5
  autoResizeImages?: boolean;
6
+ /** Model-specific resize profile. Uses the conservative built-in defaults when omitted. */
7
+ resizeOptions?: ModelImageResizeOptions;
6
8
  }
7
9
  /**
8
10
  * Normalize image blocks returned by tool results.
@@ -1 +1 @@
1
- {"version":3,"file":"tool-result-images.d.ts","sourceRoot":"","sources":["../../src/utils/tool-result-images.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGvE,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,YAAY,CAAC;AAE3D,MAAM,WAAW,gCAAgC;IAChD,oFAAoF;IACpF,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,yBAAyB,CAC9C,OAAO,EAAE,iBAAiB,EAAE,EAC5B,OAAO,CAAC,EAAE,gCAAgC,GACxC,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAqC9B","sourcesContent":["import type { ImageContent, TextContent } from \"@earendil-works/pi-ai\";\nimport { processImage } from \"./image-process.ts\";\n\nexport type ToolResultContent = TextContent | ImageContent;\n\nexport interface NormalizeToolResultImagesOptions {\n\t/** Whether oversized images are resized to inline provider limits. Default: true */\n\tautoResizeImages?: boolean;\n}\n\n/**\n * Normalize image blocks returned by tool results.\n *\n * The `read` tool and `@file` CLI attachments run their images through `processImage`, but tools\n * that produce images themselves (extensions, MCP bridges, screenshot tools) hand back arbitrary\n * base64 payloads that go straight into session history and every subsequent provider request.\n * Oversized images make the provider reject the whole conversation, not just the offending turn,\n * so normalize them once as they enter history.\n *\n * Returns the original array when nothing changed so callers can skip rewriting the result.\n */\nexport async function normalizeToolResultImages(\n\tcontent: ToolResultContent[],\n\toptions?: NormalizeToolResultImagesOptions,\n): Promise<ToolResultContent[]> {\n\tif (!content.some((block) => block.type === \"image\")) {\n\t\treturn content;\n\t}\n\n\tconst autoResizeImages = options?.autoResizeImages ?? true;\n\tconst normalized: ToolResultContent[] = [];\n\tlet changed = false;\n\n\tfor (const block of content) {\n\t\tif (block.type !== \"image\") {\n\t\t\tnormalized.push(block);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst processed = await processImage(Buffer.from(block.data, \"base64\"), block.mimeType, { autoResizeImages });\n\t\tif (!processed.ok) {\n\t\t\t// Unlike `read`, keep the original block. The tool already produced this image and the\n\t\t\t// failure may just be an unavailable image backend, so passing it through preserves the\n\t\t\t// behavior tools have today instead of silently deleting their output.\n\t\t\tnormalized.push(block);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (processed.data === block.data && processed.mimeType === block.mimeType && processed.hints.length === 0) {\n\t\t\tnormalized.push(block);\n\t\t\tcontinue;\n\t\t}\n\n\t\tnormalized.push({ type: \"image\", data: processed.data, mimeType: processed.mimeType });\n\t\tif (processed.hints.length > 0) {\n\t\t\tnormalized.push({ type: \"text\", text: processed.hints.join(\"\\n\") });\n\t\t}\n\t\tchanged = true;\n\t}\n\n\treturn changed ? normalized : content;\n}\n"]}
1
+ {"version":3,"file":"tool-result-images.d.ts","sourceRoot":"","sources":["../../src/utils/tool-result-images.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGhG,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,YAAY,CAAC;AAE3D,MAAM,WAAW,gCAAgC;IAChD,oFAAoF;IACpF,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,2FAA2F;IAC3F,aAAa,CAAC,EAAE,uBAAuB,CAAC;CACxC;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,yBAAyB,CAC9C,OAAO,EAAE,iBAAiB,EAAE,EAC5B,OAAO,CAAC,EAAE,gCAAgC,GACxC,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAwC9B","sourcesContent":["import type { ImageContent, ModelImageResizeOptions, TextContent } from \"@earendil-works/pi-ai\";\nimport { processImage } from \"./image-process.ts\";\n\nexport type ToolResultContent = TextContent | ImageContent;\n\nexport interface NormalizeToolResultImagesOptions {\n\t/** Whether oversized images are resized to inline provider limits. Default: true */\n\tautoResizeImages?: boolean;\n\t/** Model-specific resize profile. Uses the conservative built-in defaults when omitted. */\n\tresizeOptions?: ModelImageResizeOptions;\n}\n\n/**\n * Normalize image blocks returned by tool results.\n *\n * The `read` tool and `@file` CLI attachments run their images through `processImage`, but tools\n * that produce images themselves (extensions, MCP bridges, screenshot tools) hand back arbitrary\n * base64 payloads that go straight into session history and every subsequent provider request.\n * Oversized images make the provider reject the whole conversation, not just the offending turn,\n * so normalize them once as they enter history.\n *\n * Returns the original array when nothing changed so callers can skip rewriting the result.\n */\nexport async function normalizeToolResultImages(\n\tcontent: ToolResultContent[],\n\toptions?: NormalizeToolResultImagesOptions,\n): Promise<ToolResultContent[]> {\n\tif (!content.some((block) => block.type === \"image\")) {\n\t\treturn content;\n\t}\n\n\tconst autoResizeImages = options?.autoResizeImages ?? true;\n\tconst normalized: ToolResultContent[] = [];\n\tlet changed = false;\n\n\tfor (const block of content) {\n\t\tif (block.type !== \"image\") {\n\t\t\tnormalized.push(block);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst processed = await processImage(Buffer.from(block.data, \"base64\"), block.mimeType, {\n\t\t\tautoResizeImages,\n\t\t\tresizeOptions: options?.resizeOptions,\n\t\t});\n\t\tif (!processed.ok) {\n\t\t\t// Unlike `read`, keep the original block. The tool already produced this image and the\n\t\t\t// failure may just be an unavailable image backend, so passing it through preserves the\n\t\t\t// behavior tools have today instead of silently deleting their output.\n\t\t\tnormalized.push(block);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (processed.data === block.data && processed.mimeType === block.mimeType && processed.hints.length === 0) {\n\t\t\tnormalized.push(block);\n\t\t\tcontinue;\n\t\t}\n\n\t\tnormalized.push({ type: \"image\", data: processed.data, mimeType: processed.mimeType });\n\t\tif (processed.hints.length > 0) {\n\t\t\tnormalized.push({ type: \"text\", text: processed.hints.join(\"\\n\") });\n\t\t}\n\t\tchanged = true;\n\t}\n\n\treturn changed ? normalized : content;\n}\n"]}
@@ -22,7 +22,10 @@ export async function normalizeToolResultImages(content, options) {
22
22
  normalized.push(block);
23
23
  continue;
24
24
  }
25
- const processed = await processImage(Buffer.from(block.data, "base64"), block.mimeType, { autoResizeImages });
25
+ const processed = await processImage(Buffer.from(block.data, "base64"), block.mimeType, {
26
+ autoResizeImages,
27
+ resizeOptions: options?.resizeOptions,
28
+ });
26
29
  if (!processed.ok) {
27
30
  // Unlike `read`, keep the original block. The tool already produced this image and the
28
31
  // failure may just be an unavailable image backend, so passing it through preserves the
@@ -1 +1 @@
1
- {"version":3,"file":"tool-result-images.js","sourceRoot":"","sources":["../../src/utils/tool-result-images.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AASlD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC9C,OAA4B,EAC5B,OAA0C,EACX;IAC/B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,EAAE,CAAC;QACtD,OAAO,OAAO,CAAC;IAChB,CAAC;IAED,MAAM,gBAAgB,GAAG,OAAO,EAAE,gBAAgB,IAAI,IAAI,CAAC;IAC3D,MAAM,UAAU,GAAwB,EAAE,CAAC;IAC3C,IAAI,OAAO,GAAG,KAAK,CAAC;IAEpB,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAC5B,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACvB,SAAS;QACV,CAAC;QAED,MAAM,SAAS,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC;QAC9G,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC;YACnB,uFAAuF;YACvF,wFAAwF;YACxF,uEAAuE;YACvE,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACvB,SAAS;QACV,CAAC;QAED,IAAI,SAAS,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,IAAI,SAAS,CAAC,QAAQ,KAAK,KAAK,CAAC,QAAQ,IAAI,SAAS,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC5G,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACvB,SAAS;QACV,CAAC;QAED,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;QACvF,IAAI,SAAS,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChC,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACrE,CAAC;QACD,OAAO,GAAG,IAAI,CAAC;IAChB,CAAC;IAED,OAAO,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC;AAAA,CACtC","sourcesContent":["import type { ImageContent, TextContent } from \"@earendil-works/pi-ai\";\nimport { processImage } from \"./image-process.ts\";\n\nexport type ToolResultContent = TextContent | ImageContent;\n\nexport interface NormalizeToolResultImagesOptions {\n\t/** Whether oversized images are resized to inline provider limits. Default: true */\n\tautoResizeImages?: boolean;\n}\n\n/**\n * Normalize image blocks returned by tool results.\n *\n * The `read` tool and `@file` CLI attachments run their images through `processImage`, but tools\n * that produce images themselves (extensions, MCP bridges, screenshot tools) hand back arbitrary\n * base64 payloads that go straight into session history and every subsequent provider request.\n * Oversized images make the provider reject the whole conversation, not just the offending turn,\n * so normalize them once as they enter history.\n *\n * Returns the original array when nothing changed so callers can skip rewriting the result.\n */\nexport async function normalizeToolResultImages(\n\tcontent: ToolResultContent[],\n\toptions?: NormalizeToolResultImagesOptions,\n): Promise<ToolResultContent[]> {\n\tif (!content.some((block) => block.type === \"image\")) {\n\t\treturn content;\n\t}\n\n\tconst autoResizeImages = options?.autoResizeImages ?? true;\n\tconst normalized: ToolResultContent[] = [];\n\tlet changed = false;\n\n\tfor (const block of content) {\n\t\tif (block.type !== \"image\") {\n\t\t\tnormalized.push(block);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst processed = await processImage(Buffer.from(block.data, \"base64\"), block.mimeType, { autoResizeImages });\n\t\tif (!processed.ok) {\n\t\t\t// Unlike `read`, keep the original block. The tool already produced this image and the\n\t\t\t// failure may just be an unavailable image backend, so passing it through preserves the\n\t\t\t// behavior tools have today instead of silently deleting their output.\n\t\t\tnormalized.push(block);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (processed.data === block.data && processed.mimeType === block.mimeType && processed.hints.length === 0) {\n\t\t\tnormalized.push(block);\n\t\t\tcontinue;\n\t\t}\n\n\t\tnormalized.push({ type: \"image\", data: processed.data, mimeType: processed.mimeType });\n\t\tif (processed.hints.length > 0) {\n\t\t\tnormalized.push({ type: \"text\", text: processed.hints.join(\"\\n\") });\n\t\t}\n\t\tchanged = true;\n\t}\n\n\treturn changed ? normalized : content;\n}\n"]}
1
+ {"version":3,"file":"tool-result-images.js","sourceRoot":"","sources":["../../src/utils/tool-result-images.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAWlD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC9C,OAA4B,EAC5B,OAA0C,EACX;IAC/B,IAAI,CAAC,OAAO,CAAC,IAAI,CA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,EAAE,CAAC;YAChC,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACrE,CAAC;QACD,OAAO,GAAG,IAAI,CAAC;IAChB,CAAC;IAED,OAAO,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC;AAAA,CACtC","sourcesContent":["import type { ImageContent, ModelImageResizeOptions, TextContent } from \"@earendil-works/pi-ai\";\nimport { processImage } from \"./image-process.ts\";\n\nexport type ToolResultContent = TextContent | ImageContent;\n\nexport interface NormalizeToolResultImagesOptions {\n\t/** Whether oversized images are resized to inline provider limits. Default: true */\n\tautoResizeImages?: boolean;\n\t/** Model-specific resize profile. Uses the conservative built-in defaults when omitted. */\n\tresizeOptions?: ModelImageResizeOptions;\n}\n\n/**\n * Normalize image blocks returned by tool results.\n *\n * The `read` tool and `@file` CLI attachments run their images through `processImage`, but tools\n * that produce images themselves (extensions, MCP bridges, screenshot tools) hand back arbitrary\n * base64 payloads that go straight into session history and every subsequent provider request.\n * Oversized images make the provider reject the whole conversation, not just the offending turn,\n * so normalize them once as they enter history.\n *\n * Returns the original array when nothing changed so callers can skip rewriting the result.\n */\nexport async function normalizeToolResultImages(\n\tcontent: ToolResultContent[],\n\toptions?: NormalizeToolResultImagesOptions,\n): Promise<ToolResultContent[]> {\n\tif (!content.some((block) => block.type === \"image\")) {\n\t\treturn content;\n\t}\n\n\tconst autoResizeImages = options?.autoResizeImages ?? true;\n\tconst normalized: ToolResultContent[] = [];\n\tlet changed = false;\n\n\tfor (const block of content) {\n\t\tif (block.type !== \"image\") {\n\t\t\tnormalized.push(block);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst processed = await processImage(Buffer.from(block.data, \"base64\"), block.mimeType, {\n\t\t\tautoResizeImages,\n\t\t\tresizeOptions: options?.resizeOptions,\n\t\t});\n\t\tif (!processed.ok) {\n\t\t\t// Unlike `read`, keep the original block. The tool already produced this image and the\n\t\t\t// failure may just be an unavailable image backend, so passing it through preserves the\n\t\t\t// behavior tools have today instead of silently deleting their output.\n\t\t\tnormalized.push(block);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (processed.data === block.data && processed.mimeType === block.mimeType && processed.hints.length === 0) {\n\t\t\tnormalized.push(block);\n\t\t\tcontinue;\n\t\t}\n\n\t\tnormalized.push({ type: \"image\", data: processed.data, mimeType: processed.mimeType });\n\t\tif (processed.hints.length > 0) {\n\t\t\tnormalized.push({ type: \"text\", text: processed.hints.join(\"\\n\") });\n\t\t}\n\t\tchanged = true;\n\t}\n\n\treturn changed ? normalized : content;\n}\n"]}
@@ -34,14 +34,16 @@ contextTokens > contextWindow - reserveTokens
34
34
 
35
35
  By default, `reserveTokens` is 16384 tokens (configurable in `~/.pi/agent/settings.json` or `<project-dir>/.pi/settings.json`). This leaves room for the LLM's response.
36
36
 
37
- During a multi-turn agent run, Pi checks this threshold after tools finish and their results are appended, before starting the next assistant response. If the threshold is crossed, Pi compacts inside the same agent run and resumes with the summary and retained messages. It skips this between-turn check when the completed tool batch terminates the run and no queued message requires another response. Pi also checks the threshold before a new user prompt and after a low-level agent run ends.
37
+ During a multi-turn agent run, Pi checks the canonical projected context after tools finish and their results are appended, before starting the next assistant response. If the threshold is crossed, Pi compacts during `prepareNextTurn`, then performs the existing catch-up steering poll before `turn_start`. It skips this between-turn check when the completed tool batch terminates the run and no queued message requires another response. Pi also checks before a new user prompt and performs final-attempt overflow recovery after the low-level run ends.
38
+
39
+ A provider context-overflow error or an early final `stopReason: "length"` can select one compact-and-retry recovery attempt. Length responses with tool calls retain their synthetic failed tool results and follow the ordinary tool/queue scheduler rather than forcing the run to end.
38
40
 
39
41
  You can also trigger manually with `/compact [instructions]`, where optional instructions focus the summary.
40
42
 
41
43
  ### How It Works
42
44
 
43
- 1. **Find cut point**: Walk backwards from newest message, accumulating token estimates until `keepRecentTokens` (default 20k, configurable in `~/.pi/agent/settings.json` or `<project-dir>/.pi/settings.json`) is reached
44
- 2. **Extract messages**: Collect messages from the previous kept boundary (or session start) up to the cut point
45
+ 1. **Find cut point**: Walk backwards through the finalized session projection, accumulating token estimates until `keepRecentTokens` (default 20k, configurable in `~/.pi/agent/settings.json` or `<project-dir>/.pi/settings.json`) is reached
46
+ 2. **Extract messages**: Collect projected messages from the previous kept boundary (or session start) up to the cut point
45
47
  3. **Generate summary**: Call LLM to summarize with structured format, passing the previous summary as iterative context when present
46
48
  4. **Append entry**: Save `CompactionEntry` with summary and `firstKeptEntryId`
47
49
  5. **Rebuilds context**: Session rebuilds the context for the next request, using summary + messages from `firstKeptEntryId` onwards
@@ -78,7 +80,22 @@ What the LLM sees:
78
80
  prompt from cmp messages from firstKeptEntryId
79
81
  ```
80
82
 
81
- On repeated compactions, the summarized span starts at the previous compaction's kept boundary (`firstKeptEntryId`), not at the compaction entry itself, falling back to the entry after the previous compaction if that kept entry cannot be found in the path. This preserves messages that survived the earlier compaction by including them in the next summarization pass as well. Pi also recalculates `tokensBefore` from the rebuilt session context before writing the new `CompactionEntry`, so the token count reflects the actual pre-compaction context being replaced.
83
+ On repeated compactions, the summarized span starts at the previous compaction's kept boundary (`firstKeptEntryId`), not at the compaction entry itself, falling back to the entry after the previous compaction if that kept entry cannot be found in the path. A retain-none compaction records its own ID as `firstKeptEntryId`; repeated compaction starts after that entry. This preserves messages that survived the earlier compaction by including them in the next summarization pass as well. Pi also recalculates `tokensBefore` from the rebuilt, context-edited session projection before writing the new `CompactionEntry`, so the token count reflects the actual pre-compaction context being replaced. Omitted raw entries remain stored but do not affect cut selection, summaries, checkpoints, or token estimates.
84
+
85
+ ### Overflow and Length Recovery Ordering
86
+
87
+ Recovery preserves the existing lifecycle and queue order. The completed attempt remains visible to `turn_end` and `agent_end`; post-run recovery then repairs persisted model context before a fresh retry:
88
+
89
+ ```text
90
+ persist final assistant response
91
+ → extension/public turn_end
92
+ → extension/public agent_end
93
+ → append context_edit omissions for the selected attempt
94
+ → for overflow/length: run session_before_compact and append compaction on success
95
+ → start the retry as a fresh run
96
+ ```
97
+
98
+ If recovery compaction fails or is cancelled, Pi keeps the omission edits, appends no compaction, and schedules no internal retry. Existing queued work remains governed by ordinary steering and follow-up rules. `agent_before_settle` sees the repaired projection after recovery processing. Raw transcript history, exports, billing totals, and history-search extensions can still inspect the omitted attempt.
82
99
 
83
100
  ### Split Turns
84
101
 
@@ -118,6 +135,8 @@ Valid cut points are:
118
135
 
119
136
  Never cut at tool results (they must stay with their tool call).
120
137
 
138
+ Preparation advances the kept boundary into a context-invisible suffix only when that suffix contains an omitted assistant attempt and no unomitted context-producing entries. Recovery `context_edit` omissions satisfy this rule; intrinsically context-invisible metadata may coexist with them. Metadata alone and newly appended custom messages do not move the cut. A replacement edit affecting the candidate input or summarized prefix also blocks advancement because the omitted assistant answered the pre-edit input; replacements of suffix entries that are ultimately omitted remain safe. This allows an over-budget recovered input to be summarized while retaining the edits that keep the abandoned attempt omitted, without making bookkeeping change whether new model input is preserved verbatim.
139
+
121
140
  ### CompactionEntry Structure
122
141
 
123
142
  Defined in [`session-manager.ts`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/session-manager.ts):
@@ -294,7 +294,8 @@ user sends prompt ────────────────────
294
294
  │ ┌─── turn (repeats while LLM calls tools) ───┐ │
295
295
  │ │ │ │
296
296
  │ ├─► turn_start │ │
297
- │ ├─► context (can modify messages) │ │
297
+ │ ├─► context (can modify conversation messages) │
298
+ │ ├─► context_with_system (can modify the full transcript)
298
299
  │ ├─► before_provider_headers (can mutate headers) |
299
300
  │ ├─► before_provider_request (can inspect or replace payload)
300
301
  │ ├─► after_provider_response (status + headers, before stream consume)
@@ -307,9 +308,13 @@ user sends prompt ────────────────────
307
308
  │ │ └─► tool_execution_end │ │
308
309
  │ │ │ │
309
310
  │ └─► turn_end │ │
311
+ │ └─► threshold compaction before a naturally required next turn
310
312
  │ │
311
313
  ├─► agent_end │
312
- └─► agent_settled (no retry/compaction/follow-up left) │
314
+ ├─► retry backoff or final-attempt recovery (when selected)
315
+ │ └─► fresh agent_start on successful recovery │
316
+ ├─► agent_before_settle (can append entries and continue)│
317
+ └─► agent_settled (final, notification only) │
313
318
  │
314
319
  user sends another prompt ◄────────────────────────────────┘
315
320
 
@@ -567,9 +572,9 @@ The `systemPromptOptions` field gives extensions access to the same structured d
567
572
 
568
573
  Inside `before_agent_start`, `event.systemPrompt` and `ctx.getSystemPrompt()` both reflect the chained system prompt as of the current handler. Later `before_agent_start` handlers can still modify it again.
569
574
 
570
- #### agent_start / agent_end / agent_settled
575
+ #### agent_start / agent_end / agent_before_settle / agent_settled
571
576
 
572
- `agent_start` fires when a low-level agent run begins. `agent_end` fires when that run ends, but Pi may still auto-retry, auto-compact and retry, or continue with queued follow-up messages. Use `agent_settled` for status integrations that need to know Pi will not continue running automatically.
577
+ `agent_start` fires when a low-level agent run begins. `agent_end` fires when that run ends, but Pi may still auto-retry, auto-compact and retry, or continue with queued follow-up messages. `agent_before_settle` is the final actionable boundary: it can append session entries and request one continuation. `agent_settled` is final and notification-only; use it for status integrations that need to know Pi will not continue running automatically.
573
578
 
574
579
  ```typescript
575
580
  pi.on("agent_start", async (_event, ctx) => {});
@@ -578,11 +583,28 @@ pi.on("agent_end", async (event, ctx) => {
578
583
  // event.messages - messages from this low-level run
579
584
  });
580
585
 
586
+ let addedReviewReminder = false;
587
+ pi.on("agent_before_settle", async (event, ctx) => {
588
+ if (addedReviewReminder) return;
589
+ addedReviewReminder = true;
590
+ return {
591
+ entries: [...event.entries, {
592
+ type: "custom_message",
593
+ customType: "review-reminder",
594
+ content: "Review the final diff before replying.",
595
+ display: false,
596
+ }],
597
+ continue: true,
598
+ };
599
+ });
600
+
581
601
  pi.on("agent_settled", async (_event, ctx) => {
582
- // ctx.isIdle() is true here unless another extension started a new run.
602
+ // ctx.isIdle() is true; runs requested here start after all settled handlers finish.
583
603
  });
584
604
  ```
585
605
 
606
+ If the run is aborted while `agent_before_settle` handlers are running, valid returned entries are still committed, but requested continuation is suppressed. Work requested from `agent_settled` is deferred until every settled handler completes, so notification dispatch is non-reentrant.
607
+
586
608
  #### ui_prompt_start / ui_prompt_end
587
609
 
588
610
  Notification-only lifecycle events for blocking user-facing extension UI prompts. They fire around `ctx.ui.select()`, `ctx.ui.confirm()`, `ctx.ui.input()`, `ctx.ui.editor()`, and `ctx.ui.custom()` so host/status integrations can report "waiting for user" instead of just "running".
@@ -610,11 +632,34 @@ pi.on("turn_start", async (event, ctx) => {
610
632
  // event.turnIndex, event.timestamp
611
633
  });
612
634
 
635
+ let replacedResponse = false;
613
636
  pi.on("turn_end", async (event, ctx) => {
614
637
  // event.turnIndex, event.message, event.toolResults
638
+ // event.entries contains the structural entries proposed so far.
639
+ if (replacedResponse || event.outcome !== "completed" || event.toolResults.length > 0) return;
640
+ replacedResponse = true;
641
+ return {
642
+ entries: [
643
+ ...event.entries,
644
+ { type: "context_edit", targetId: event.messageEntryId, replacement: null },
645
+ {
646
+ type: "custom_message",
647
+ customType: "replacement-instruction",
648
+ content: "Answer again using the persisted user request.",
649
+ display: false,
650
+ },
651
+ ],
652
+ continue: true,
653
+ };
615
654
  });
616
655
  ```
617
656
 
657
+ `turn_end` runs after the assistant and tool-result messages have been persisted and before the low-level `turn_end` event. Retry backoff and final-attempt recovery still happen after `agent_end`, preserving their existing lifecycle and queue ordering; `agent_before_settle` sees the repaired projection after that work completes. Boundary handlers run in extension load and registration order. Each handler sees prior proposals in `event.entries` and sees `event.context` rebuilt from them. Returning `entries` or `continue` replaces only that field; omitted fields preserve the current proposal. Allowed draft entry types are `custom`, `custom_message`, `context_edit`, and `compaction`. The complete proposal is validated before it is appended in list order after all handlers finish; a handler error is reported and later handlers still run. Validation prevents partially applied semantic errors, but persistence is not transactional.
658
+
659
+ `continue: true` ensures one next provider request for that boundary invocation. If tool results, steering, or a follow-up already cause that request, they satisfy the decision and no additional request is made; otherwise Pi makes one context-only request. Error and aborted responses remain hard exits. `continue: false` never suppresses natural work. Guard continuation conditions: an unconditional `continue: true` is evaluated again after the next response and can create an endless loop. A `custom_message` draft contributes a user-role model message but is extension-authored: it does not run human input hooks, slash commands, skills, or prompt templates.
660
+
661
+ Host integrations that construct `TurnEndEvent` values must now provide `messageEntryId`, `toolResultEntryIds`, `outcome`, `entries`, `continue`, and `context`. `ExtensionEvent` exhaustive switches must also handle `agent_before_settle`. `ExtensionRunner.emit()` excludes actionable turn boundaries; dispatch `turn_end` and `agent_before_settle` through `emitBoundary(baseEvent, buildContext)` so handlers receive chained previews. Other dedicated runner methods still return results for events such as `session_before_*`.
662
+
618
663
  #### message_start / message_update / message_end
619
664
 
620
665
  Fired for message lifecycle updates.
@@ -681,12 +726,31 @@ Fired before each LLM call. Modify messages non-destructively. See [Session Form
681
726
 
682
727
  ```typescript
683
728
  pi.on("context", async (event, ctx) => {
684
- // event.messages - deep copy, safe to modify
729
+ // event.messages - deep copy without system messages, safe to modify
685
730
  const filtered = event.messages.filter(m => !shouldPrune(m));
686
731
  return { messages: filtered };
687
732
  });
688
733
  ```
689
734
 
735
+ `event.messages` holds the conversation without system messages. The prompt and tool declarations belong to Pi and are not part of this hook: when the handler returns a changed list, Pi replays the current prompt sections and tool declarations into one leading system message ahead of the returned messages. Filtering, windowing, or slicing from a compaction summary therefore cannot drop the prompt or the tools. An unchanged list keeps mid-conversation system messages in place, so models that accept them retain their cached prefix. System messages a handler adds are kept after Pi's head. To change the prompt or the tool set durably, use [`before_agent_start`](#before_agent_start) or `pi.setActiveTools()`; to edit system messages for one request, use [`context_with_system`](#context_with_system).
736
+
737
+ #### context_with_system
738
+
739
+ Fired before each LLM call, after every `context` handler has run and Pi has restored the prompt and tool state. `event.messages` is the full transcript, including the leading system message and any mid-conversation prompt or tool patches (see [Session Format](session-format.md#sessionmessageentry)). The returned messages are sent as they are: this hook owns the prompt and tool declarations for the request.
740
+
741
+ ```typescript
742
+ import { getCurrentSystemMessage } from "@earendil-works/pi-ai";
743
+
744
+ pi.on("context_with_system", async (event, ctx) => {
745
+ const cut = findCutIndex(event.messages);
746
+ // Fold the dropped prefix so its prompt and tool state survives as the new head.
747
+ const head = getCurrentSystemMessage(event.messages.slice(0, cut));
748
+ return { messages: head ? [head, ...event.messages.slice(cut)] : event.messages.slice(cut) };
749
+ });
750
+ ```
751
+
752
+ Rules: keep a system message at index 0 (providers read the prompt and initial tool declarations there; Pi reports an error if a handler drops it). Removing a system message removes the tool declarations and section patches it carries. Check your output with `getCurrentSystemPrompt()` and `getCurrentTools()` from `@earendil-works/pi-ai`. Handlers run in extension load order; a `systemPrompt` forced from `before_agent_start` is still projected onto the request afterwards.
753
+
690
754
  #### before_provider_headers
691
755
 
692
756
  Fired after the outgoing HTTP headers are assembled. Use it to add, override, or remove request headers.
package/docs/models.md CHANGED
@@ -205,6 +205,7 @@ If your command is slow, expensive, rate-limited, or should keep using a previou
205
205
  | `reasoning` | No | `false` | Supports extended thinking |
206
206
  | `thinkingLevelMap` | No | omitted | Maps pi thinking levels to provider values and marks unsupported levels (see below) |
207
207
  | `input` | No | `["text"]` | Input types: `["text"]` or `["text", "image"]` |
208
+ | `inputLimits` | No | omitted | Request limits and image preprocessing for this model (see below) |
208
209
  | `contextWindow` | No | `128000` | Context window size in tokens |
209
210
  | `maxTokens` | No | `16384` | Maximum output tokens |
210
211
  | `samplingParams` | No | omitted | Sampling parameters merged verbatim into every request body (see below) |
@@ -238,6 +239,33 @@ Current behavior:
238
239
  - `/model`, `--list-models`, and the interactive footer display entries by model `id`.
239
240
  - The configured `name` is used for model matching and secondary model detail text. It does not replace the footer/status-bar model id.
240
241
 
242
+ ### Image Input Limits
243
+
244
+ Use `inputLimits.images.resize` to configure how new images are encoded before they enter conversation history:
245
+
246
+ ```json
247
+ {
248
+ "id": "vision-model",
249
+ "input": ["text", "image"],
250
+ "inputLimits": {
251
+ "images": {
252
+ "resize": {
253
+ "maxWidth": 1568,
254
+ "maxHeight": 1568,
255
+ "maxBytes": 524288,
256
+ "jpegQuality": 75
257
+ }
258
+ }
259
+ }
260
+ }
261
+ ```
262
+
263
+ `maxBytes` is the maximum base64-encoded payload size. Omitted resize fields use pi's conservative defaults: 2000×2000, 4.5 MiB encoded, and JPEG quality 80. Built-in vision models carry that profile explicitly so unknown gateways never receive larger images than before.
264
+
265
+ Pi applies the selected model's resize profile to `@file` attachments, the `read` tool, and images returned by tools. Images are encoded once before they enter history; changing models does not rewrite historical images or invalidate the cached conversation prefix. The `images.autoResize` setting can disable resizing globally.
266
+
267
+ The catalog can also record `inputLimits.maxRequestBytes`, `images.maxPerMessage`, and `images.maxPerRequest`. These fields describe hard provider limits; this initial implementation does not yet rewrite or reject conversation history based on them.
268
+
241
269
  ### Prompt Cache Lifetimes
242
270
 
243
271
  `promptCache` states how long the provider keeps a prompt cache entry alive for each retention tier pi can request (`short` is the default tier; `long` is used when `PI_CACHE_RETENTION=long`). Values are seconds and are estimates: providers publish ranges, so pick the conservative end.
@@ -374,7 +402,7 @@ Use `modelOverrides` to customize built-in models and matching extension-registe
374
402
  }
375
403
  ```
376
404
 
377
- `modelOverrides` supports these fields per model: `name`, `reasoning`, `thinkingLevelMap`, `input`, `cost` (partial), `promptCache` (merged per tier), `contextWindow`, `maxTokens`, `samplingParams` (merged per key), `headers`, `compat`.
405
+ `modelOverrides` supports these fields per model: `name`, `reasoning`, `thinkingLevelMap`, `input`, `inputLimits` (deep-merged), `cost` (partial), `promptCache` (merged per tier), `contextWindow`, `maxTokens`, `samplingParams` (merged per key), `headers`, `compat`.
378
406
 
379
407
  Use a `promptCache` override to enable cache warming through a proxy whose backing cache you know, for example OpenRouter routed to Anthropic:
380
408
 
package/docs/sdk.md CHANGED
@@ -91,6 +91,8 @@ interface AgentSession {
91
91
 
92
92
  // State access
93
93
  agent: Agent;
94
+ sessionManager: SessionManager;
95
+ refreshContext(): void;
94
96
  model: Model | undefined;
95
97
  thinkingLevel: ThinkingLevel;
96
98
  messages: AgentMessage[];
@@ -251,8 +253,8 @@ const state = session.agent.state;
251
253
  // state.streamingMessage?: AgentMessage - current partial assistant message
252
254
  // state.errorMessage?: string - latest assistant error
253
255
 
254
- // Replace messages (useful for branching or restoration)
255
- session.agent.state.messages = messages; // copies the top-level array
256
+ // Model-visible messages are projected from session.sessionManager.
257
+ // agent.state.messages is a refreshed inspection cache; do not assign it for restoration.
256
258
 
257
259
  // Replace tools
258
260
  session.agent.state.tools = tools; // copies the top-level array
@@ -261,6 +263,15 @@ session.agent.state.tools = tools; // copies the top-level array
261
263
  await session.agent.waitForIdle();
262
264
  ```
263
265
 
266
+ Provider requests use `session.sessionManager` as the canonical finalized context. Assigning `session.agent.state.messages` does not replace persisted context and may be overwritten at the next request boundary. Restore externally stored history when constructing the session instead:
267
+
268
+ ```typescript
269
+ const restoredManager = SessionManager.inMemory(process.cwd(), { id: sessionId }, entries);
270
+ const { session } = await createAgentSession({ sessionManager: restoredManager });
271
+ ```
272
+
273
+ For an existing session, use `session.navigateTree(entryId)` to move its active branch. Use `session.sessionManager.appendMessage(...)` plus `session.refreshContext()` only when intentionally appending externally managed entries.
274
+
264
275
  ### Events
265
276
 
266
277
  Subscribe to events to receive streaming output and lifecycle notifications.
@@ -274,7 +274,7 @@ Created when context is compacted. Stores a summary of earlier messages and a co
274
274
  {"type":"compaction","id":"f6g7h8i9","parentId":"e5f6g7h8","timestamp":"2024-12-03T14:10:00.000Z","summary":"User discussed X, Y, Z...","firstKeptEntryId":"c3d4e5f6","tokensBefore":50000,"systemMessage":{"role":"system","content":"You are a coding assistant.","toolsAdded":[],"timestamp":1733235000000}}
275
275
  ```
276
276
 
277
- `firstKeptEntryId` is required. It identifies the first entry retained from before the compaction entry. When rebuilding context, Pi replaces older summarized entries with the compaction summary and keeps the range beginning at this entry.
277
+ `firstKeptEntryId` is required. It identifies the first entry retained from before the compaction entry. When rebuilding context, Pi replaces older summarized entries with the compaction summary and keeps the range beginning at this entry. A retain-none compaction stores its own ID in this field, so no preceding entries are retained.
278
278
 
279
279
  Optional fields:
280
280
  - `systemMessage`: The replayed prompt sections and tool declarations at the compaction boundary; it becomes the leading system message of the compacted context, and system messages among the kept entries are dropped in its favor. It is absent on older session entries.
@@ -282,6 +282,16 @@ Optional fields:
282
282
  - `details`: Implementation-specific data (e.g., `{ readFiles: string[], modifiedFiles: string[] }` for default, or custom data for extensions)
283
283
  - `fromHook`: `true` if generated by an extension, `false`/`undefined` if pi-generated (legacy field name)
284
284
 
285
+ ### ContextEditEntry
286
+
287
+ Append-only edit of one earlier context-producing entry. It changes only future model context; the target entry and its metadata remain unchanged in raw history, UI, exports, and session accounting.
288
+
289
+ ```json
290
+ {"type":"context_edit","id":"g6h7i8j9","parentId":"f6g7h8i9","timestamp":"2024-12-03T14:11:00.000Z","targetId":"c3d4e5f6","replacement":null}
291
+ ```
292
+
293
+ Targets may be user, assistant, tool-result, or custom-message entries. `replacement: null` omits the target from model context. A non-null `replacement` replaces only the target message content. String replacements for assistant and tool-result entries are normalized to one text block because those roles require content arrays. If several edits target the same entry, the latest edit on the active branch wins. Edits are branch-relative: navigating to a point before the edit reveals the target's original contribution again.
294
+
285
295
  ### BranchSummaryEntry
286
296
 
287
297
  Created when switching branches via `/tree` with an LLM generated summary of the left branch up to the common ancestor. Captures context from the abandoned path.
@@ -366,7 +376,9 @@ Entries normally form one tree, but navigation APIs can create multiple roots:
366
376
  - Includes entries after the compaction entry
367
377
  3. Preserves non-message entries in the selected range so interactive mode can render them
368
378
 
369
- `buildSessionContext()` builds on that entry list to produce the message list for the LLM:
379
+ `buildSessionProjection()` then applies the latest `context_edit` for each selected target. It returns the model-visible messages together with their source entries. Omitted targets produce no message; replacements retain the source entry's role and metadata while changing only content. The raw selected entries are not modified.
380
+
381
+ `buildSessionContext()` builds on that projection to produce the message list for the LLM:
370
382
 
371
383
  1. Extracts current model and thinking level settings from the full path
372
384
  2. Converts selected entries to messages:
@@ -374,6 +386,7 @@ Entries normally form one tree, but navigation APIs can create multiple roots:
374
386
  - `compaction` -> complete system checkpoint followed by `compactionSummary`
375
387
  - `branch_summary` -> `branchSummary`
376
388
  - `custom_message` -> `CustomMessage`
389
+ - `context_edit` -> no context message of its own
377
390
  - `usage` and `custom` -> no context message
378
391
 
379
392
  The compaction summary replaces entries before `firstKeptEntryId`. Pre-compaction system messages are folded into the complete checkpoint rather than replayed from the retained range. Retained non-system entries and all entries after the compaction remain available to the LLM.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pi-extension-custom-provider",
3
- "version": "0.86.1",
3
+ "version": "0.87.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pi-extension-custom-provider",
9
- "version": "0.86.1",
9
+ "version": "0.87.0",
10
10
  "dependencies": {
11
11
  "@anthropic-ai/sdk": "^0.52.0"
12
12
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-extension-custom-provider-anthropic",
3
3
  "private": true,
4
- "version": "0.86.1",
4
+ "version": "0.87.0",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "clean": "echo 'nothing to clean'",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-extension-custom-provider-gitlab-duo",
3
3
  "private": true,
4
- "version": "0.86.1",
4
+ "version": "0.87.0",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "clean": "echo 'nothing to clean'",
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pi-extension-gondolin",
3
- "version": "0.86.1",
3
+ "version": "0.87.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pi-extension-gondolin",
9
- "version": "0.86.1",
9
+ "version": "0.87.0",
10
10
  "dependencies": {
11
11
  "@earendil-works/gondolin": "0.12.0"
12
12
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-extension-gondolin",
3
3
  "private": true,
4
- "version": "0.86.1",
4
+ "version": "0.87.0",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "clean": "echo 'nothing to clean'",
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pi-extension-sandbox",
3
- "version": "1.16.1",
3
+ "version": "1.17.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pi-extension-sandbox",
9
- "version": "1.16.1",
9
+ "version": "1.17.0",
10
10
  "dependencies": {
11
11
  "@anthropic-ai/sandbox-runtime": "^0.0.26"
12
12
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-extension-sandbox",
3
3
  "private": true,
4
- "version": "1.16.1",
4
+ "version": "1.17.0",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "clean": "echo 'nothing to clean'",
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pi-extension-with-deps",
3
- "version": "0.86.1",
3
+ "version": "0.87.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pi-extension-with-deps",
9
- "version": "0.86.1",
9
+ "version": "0.87.0",
10
10
  "dependencies": {
11
11
  "ms": "^2.1.3"
12
12
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-extension-with-deps",
3
3
  "private": true,
4
- "version": "0.86.1",
4
+ "version": "0.87.0",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "clean": "echo 'nothing to clean'",
@@ -16,8 +16,9 @@ export default defineFacet({
16
16
  },
17
17
  });
18
18
  env.onActivate(() => {
19
- workerActivations.state.count += 1;
20
- workerActivations.publish(BACKGROUND_CONTEXT);
19
+ workerActivations.change(BACKGROUND_CONTEXT, (draft) => {
20
+ draft.count += 1;
21
+ });
21
22
  });
22
23
  },
23
24
  });