@earendil-works/pi-coding-agent 0.99.2 → 1.0.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 (143) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/bundle/chunks/anthropic.js +2 -2
  3. package/dist/bundle/chunks/{azure-openai-responses-TLHNIYZK.js → azure-openai-responses-AFMVM6NP.js} +1 -1
  4. package/dist/bundle/chunks/{chunk-7QSPBJKW.js → chunk-2KTBZM5G.js} +14 -28
  5. package/dist/bundle/chunks/{chunk-R5J3MOBF.js → chunk-2VNGUWBO.js} +1 -1
  6. package/dist/bundle/chunks/chunk-33XOIQ5N.js +1204 -0
  7. package/dist/bundle/chunks/chunk-4KU537KD.js +2 -0
  8. package/dist/bundle/chunks/chunk-7FH3BDRG.js +82 -0
  9. package/dist/bundle/chunks/{chunk-45SXDISG.js → chunk-IBCPYVFK.js} +4 -4
  10. package/dist/bundle/chunks/chunk-KDN6RCEQ.js +4 -0
  11. package/dist/bundle/chunks/{chunk-G3UZ5FWD.js → chunk-LTXEMVMA.js} +11 -60
  12. package/dist/bundle/chunks/chunk-PRD6WYBT.js +16 -0
  13. package/dist/bundle/chunks/{cli-ALNBTL3U.js → cli-QOMC26IJ.js} +3 -3
  14. package/dist/bundle/chunks/codemode-worker.js +44 -5
  15. package/dist/bundle/chunks/execute-GVRSEGHL.js +367 -0
  16. package/dist/bundle/chunks/openai-chatgpt.js +1 -1
  17. package/dist/bundle/chunks/{openai-codex-responses-3GKGNXC4.js → openai-codex-responses-GK67DQQJ.js} +1 -1
  18. package/dist/bundle/chunks/openai-codex.js +1 -1
  19. package/dist/bundle/chunks/{openai-responses-S7GKCCDG.js → openai-responses-CQDDLDQF.js} +1 -1
  20. package/dist/bundle/chunks/openrouter.js +1 -1
  21. package/dist/bundle/chunks/pi-logo-animation-MPKZE4EK.js +2 -0
  22. package/dist/bundle/chunks/radius.js +1 -1
  23. package/dist/bundle/chunks/runtime-2SO2JDWM.js +2 -0
  24. package/dist/bundle/chunks/virtual-modules-6ZMK7GDO.js +2 -0
  25. package/dist/bundle/cli-runtime.js +1 -1
  26. package/dist/bundle/index.js +1 -1
  27. package/dist/bundle/rpc-entry.js +1 -1
  28. package/dist/cli/args.js +2 -2
  29. package/dist/cli/args.js.map +1 -1
  30. package/dist/core/agent-session.d.ts +8 -0
  31. package/dist/core/agent-session.d.ts.map +1 -1
  32. package/dist/core/agent-session.js +37 -8
  33. package/dist/core/agent-session.js.map +1 -1
  34. package/dist/core/mcp-servers.d.ts +6 -0
  35. package/dist/core/mcp-servers.d.ts.map +1 -1
  36. package/dist/core/mcp-servers.js +7 -0
  37. package/dist/core/mcp-servers.js.map +1 -1
  38. package/dist/core/model-registry.d.ts +3 -1
  39. package/dist/core/model-registry.d.ts.map +1 -1
  40. package/dist/core/model-registry.js +4 -0
  41. package/dist/core/model-registry.js.map +1 -1
  42. package/dist/core/radius.d.ts +2 -0
  43. package/dist/core/radius.d.ts.map +1 -1
  44. package/dist/core/radius.js +2 -0
  45. package/dist/core/radius.js.map +1 -1
  46. package/dist/core/settings-manager.d.ts +7 -5
  47. package/dist/core/settings-manager.d.ts.map +1 -1
  48. package/dist/core/settings-manager.js +3 -2
  49. package/dist/core/settings-manager.js.map +1 -1
  50. package/dist/core/system-prompt.js +1 -1
  51. package/dist/core/system-prompt.js.map +1 -1
  52. package/dist/core/tools/bash.d.ts.map +1 -1
  53. package/dist/core/tools/bash.js +3 -5
  54. package/dist/core/tools/bash.js.map +1 -1
  55. package/dist/extensions/codemode/execute.d.ts.map +1 -1
  56. package/dist/extensions/codemode/execute.js +154 -47
  57. package/dist/extensions/codemode/execute.js.map +1 -1
  58. package/dist/extensions/codemode/tool.d.ts +7 -7
  59. package/dist/extensions/codemode/tool.d.ts.map +1 -1
  60. package/dist/extensions/codemode/tool.js +55 -102
  61. package/dist/extensions/codemode/tool.js.map +1 -1
  62. package/dist/extensions/mcp/cli.js +2 -2
  63. package/dist/extensions/mcp/cli.js.map +1 -1
  64. package/dist/extensions/mcp/index.d.ts.map +1 -1
  65. package/dist/extensions/mcp/index.js +23 -12
  66. package/dist/extensions/mcp/index.js.map +1 -1
  67. package/dist/extensions/mcp/oauth.d.ts +8 -7
  68. package/dist/extensions/mcp/oauth.d.ts.map +1 -1
  69. package/dist/extensions/mcp/oauth.js +55 -30
  70. package/dist/extensions/mcp/oauth.js.map +1 -1
  71. package/dist/extensions/mcp/runtime.d.ts.map +1 -1
  72. package/dist/extensions/mcp/runtime.js +2 -1
  73. package/dist/extensions/mcp/runtime.js.map +1 -1
  74. package/dist/index.d.ts +1 -1
  75. package/dist/index.d.ts.map +1 -1
  76. package/dist/index.js.map +1 -1
  77. package/dist/main.d.ts.map +1 -1
  78. package/dist/main.js +6 -0
  79. package/dist/main.js.map +1 -1
  80. package/dist/modes/interactive/components/oauth-selector.d.ts +8 -2
  81. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  82. package/dist/modes/interactive/components/oauth-selector.js +24 -21
  83. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  84. package/dist/modes/interactive/components/pi-logo-animation.d.ts +68 -0
  85. package/dist/modes/interactive/components/pi-logo-animation.d.ts.map +1 -0
  86. package/dist/modes/interactive/components/pi-logo-animation.js +1086 -0
  87. package/dist/modes/interactive/components/pi-logo-animation.js.map +1 -0
  88. package/dist/modes/interactive/components/pi-logo-animation.lazy.d.ts +7 -0
  89. package/dist/modes/interactive/components/pi-logo-animation.lazy.d.ts.map +1 -0
  90. package/dist/modes/interactive/components/pi-logo-animation.lazy.js +12 -0
  91. package/dist/modes/interactive/components/pi-logo-animation.lazy.js.map +1 -0
  92. package/dist/modes/interactive/components/pi-logo.d.ts +7 -0
  93. package/dist/modes/interactive/components/pi-logo.d.ts.map +1 -1
  94. package/dist/modes/interactive/components/pi-logo.js +13 -1
  95. package/dist/modes/interactive/components/pi-logo.js.map +1 -1
  96. package/dist/modes/interactive/components/radius-login-selector.d.ts +15 -0
  97. package/dist/modes/interactive/components/radius-login-selector.d.ts.map +1 -0
  98. package/dist/modes/interactive/components/radius-login-selector.js +85 -0
  99. package/dist/modes/interactive/components/radius-login-selector.js.map +1 -0
  100. package/dist/modes/interactive/components/settings-selector.d.ts +3 -3
  101. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  102. package/dist/modes/interactive/components/settings-selector.js +5 -5
  103. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  104. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  105. package/dist/modes/interactive/components/user-message.js +5 -4
  106. package/dist/modes/interactive/components/user-message.js.map +1 -1
  107. package/dist/modes/interactive/interactive-mode.d.ts +10 -0
  108. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  109. package/dist/modes/interactive/interactive-mode.js +153 -40
  110. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  111. package/dist/modes/interactive/theme/system-theme.d.ts +2 -1
  112. package/dist/modes/interactive/theme/system-theme.d.ts.map +1 -1
  113. package/dist/modes/interactive/theme/system-theme.js +16 -5
  114. package/dist/modes/interactive/theme/system-theme.js.map +1 -1
  115. package/docs/cli.md +6 -16
  116. package/docs/codemode.md +207 -0
  117. package/docs/docs.json +5 -1
  118. package/docs/environment-variables.md +2 -2
  119. package/docs/index.md +1 -1
  120. package/docs/mcp.md +17 -0
  121. package/docs/models.md +22 -1
  122. package/docs/providers.md +16 -6
  123. package/docs/sdk.md +1 -1
  124. package/docs/settings.md +3 -3
  125. package/docs/usage.md +1 -1
  126. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  127. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  128. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  129. package/examples/extensions/gondolin/package-lock.json +2 -2
  130. package/examples/extensions/gondolin/package.json +1 -1
  131. package/examples/extensions/sandbox/package-lock.json +2 -2
  132. package/examples/extensions/sandbox/package.json +1 -1
  133. package/examples/extensions/with-deps/package-lock.json +2 -2
  134. package/examples/extensions/with-deps/package.json +1 -1
  135. package/npm-shrinkwrap.json +25 -30
  136. package/package.json +10 -10
  137. package/dist/bundle/chunks/chunk-3KYEVQKX.js +0 -82
  138. package/dist/bundle/chunks/chunk-3NVH2HQH.js +0 -4
  139. package/dist/bundle/chunks/chunk-3YAHQSW6.js +0 -1438
  140. package/dist/bundle/chunks/chunk-ECRK44UV.js +0 -2
  141. package/dist/bundle/chunks/execute-RC7W4ML3.js +0 -328
  142. package/dist/bundle/chunks/runtime-NJPX4ID2.js +0 -2
  143. package/dist/bundle/chunks/virtual-modules-5UGH4HRZ.js +0 -2
@@ -5,7 +5,8 @@
5
5
  * on the background and on the panels it is drawn on. Hue and saturation come from the terminal's palette
6
6
  * color for the family's ANSI slot, or from the family's own hue when the terminal reports no palette.
7
7
  * Lightness comes from the rules alone. Colors are built in OKHSL, whose saturation is relative to the
8
- * sRGB gamut, and fade toward gray near black and white.
8
+ * sRGB gamut, and fade toward gray near black and white. A palette color never gains OKLCH chroma when it
9
+ * moves to another lightness, so pastel palettes stay pastel.
9
10
  *
10
11
  * A contrast level is a target-lightness curve: the OKLab lightness a token needs, given the lightness of
11
12
  * the surface below it. The curves were fitted to the reference theme design from the "Pi themes: system
@@ -1 +1 @@
1
- {"version":3,"file":"system-theme.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/theme/system-theme.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAMN,KAAK,QAAQ,EAEb,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,eAAe,EAAW,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEnF,eAAO,MAAM,iBAAiB,WAAW,CAAC;AAgV1C,MAAM,WAAW,gBAAgB;IAChC,UAAU,CAAC,EAAE,QAAQ,CAAC;IACtB,UAAU,CAAC,EAAE,QAAQ,CAAC;IACtB,wBAAwB;IACxB,OAAO,CAAC,EAAE,QAAQ,EAAE,CAAC;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C,EAAE,MAAM,CAAC;IACpB,gHAAgH;IAChH,cAAc,CAAC,EAAE,eAAe,CAAC;CACjC;AAED,MAAM,WAAW,iBAAiB;IACjC,wEAAwE;IACxE,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;IAC5C,0FAA0F;IAC1F,GAAG,EAAE,UAAU,EAAE,CAAC;IAClB,UAAU,EAAE,eAAe,GAAG,SAAS,CAAC;CACxC;AAOD,iCAAiC;AACjC,wBAAgB,iBAAiB,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,QAAQ,GAAG,MAAM,CAM/D;AAED,mCAAmC;AACnC,wBAAgB,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,GAAG,MAAM,CAItE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC,EAAE,QAAQ,GAAG,eAAe,CAe/F;AA+BD;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,gBAAgB,GAAG,iBAAiB,CA0HpF"}
@@ -5,7 +5,8 @@
5
5
  * on the background and on the panels it is drawn on. Hue and saturation come from the terminal's palette
6
6
  * color for the family's ANSI slot, or from the family's own hue when the terminal reports no palette.
7
7
  * Lightness comes from the rules alone. Colors are built in OKHSL, whose saturation is relative to the
8
- * sRGB gamut, and fade toward gray near black and white.
8
+ * sRGB gamut, and fade toward gray near black and white. A palette color never gains OKLCH chroma when it
9
+ * moves to another lightness, so pastel palettes stay pastel.
9
10
  *
10
11
  * A contrast level is a target-lightness curve: the OKLab lightness a token needs, given the lightness of
11
12
  * the surface below it. The curves were fitted to the reference theme design from the "Pi themes: system
@@ -17,7 +18,7 @@
17
18
  * - background only: the families' own hues, lightness from the background;
18
19
  * - nothing: ANSI palette indices and the default colors, which the terminal renders itself.
19
20
  */
20
- import { colorToOkhsl, colorToOklch, okhslColor, oklabToOkhslLightness, rgbColor, } from "@earendil-works/pi-tui";
21
+ import { colorToOkhsl, colorToOklch, colorToRgb, okhslColor, oklabToOkhslLightness, oklchColor, rgbColor, } from "@earendil-works/pi-tui";
21
22
  export const SYSTEM_THEME_NAME = "system";
22
23
  const FAMILIES = {
23
24
  neutral: { hue: 231.49, saturation: { min: 0.02, max: 0.08 }, slot: 8 },
@@ -364,7 +365,7 @@ export function generateSystemThemeColors(input) {
364
365
  const { background, foreground } = input;
365
366
  if (!background)
366
367
  return indexedColors(saturation, input.appearanceHint);
367
- const palette = input.palette?.length === 16 ? input.palette.map(okhslOf) : undefined;
368
+ const palette = input.palette?.length === 16 ? input.palette.map(sourceOf) : undefined;
368
369
  const appearance = terminalAppearance(background, foreground);
369
370
  const lighter = appearance === "dark";
370
371
  const extreme = lighter ? 1 : 0;
@@ -471,7 +472,7 @@ export function generateSystemThemeColors(input) {
471
472
  result[token] = "";
472
473
  continue;
473
474
  }
474
- text = anchored(okhslOf(foreground), FAMILIES.neutral, oklabToOkhslLightness(needed), saturation);
475
+ text = anchored(sourceOf(foreground), FAMILIES.neutral, oklabToOkhslLightness(needed), saturation);
475
476
  }
476
477
  }
477
478
  // Body text keeps at least 4.5:1 on the surfaces it is drawn on, even on relaxed mid-gray backgrounds.
@@ -483,14 +484,24 @@ export function generateSystemThemeColors(input) {
483
484
  function okhslOf({ r, g, b }) {
484
485
  return colorToOkhsl(rgbColor(r, g, b));
485
486
  }
487
+ function sourceOf(color) {
488
+ return { ...okhslOf(color), chroma: colorToOklch(rgbColor(color.r, color.g, color.b)).c };
489
+ }
486
490
  /**
487
491
  * A source color's hue at another OKHSL lightness. Its saturation applies at its own lightness and falls off
488
492
  * toward black and white along the family's saturation curve, never rising above it.
493
+ *
494
+ * OKHSL saturation is relative to the most chroma sRGB allows at a lightness, so the same saturation can mean
495
+ * more chroma elsewhere: Catppuccin Frappe's pink #f4b8e4 (chroma 0.089) would become #eb76d1 (0.180) at the
496
+ * lightness the accent needs. Chroma is therefore also capped at the source's, with the same falloff.
489
497
  */
490
498
  function anchored(source, family, lightness, saturation) {
491
499
  const anchor = saturationCurve(family, source.l);
492
500
  const falloff = anchor > 0 ? Math.min(1, saturationCurve(family, lightness) / anchor) : 1;
493
- return okhslColor(source.h, source.s * falloff * saturation, lightness);
501
+ const color = okhslColor(source.h, source.s * falloff * saturation, lightness);
502
+ const cap = source.chroma * falloff * saturation;
503
+ const { l, c } = colorToOklch(color);
504
+ return c <= cap ? color : colorToRgb(oklchColor(l, cap, source.h));
494
505
  }
495
506
  /** Move a text color toward white or black until it reaches the WCAG minimum on every surface. */
496
507
  function withTextContrast(color, surfaces, lighter) {
@@ -1 +1 @@
1
- {"version":3,"file":"system-theme.js","sourceRoot":"","sources":["../../../../src/modes/interactive/theme/system-theme.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EACN,YAAY,EACZ,YAAY,EAEZ,UAAU,EACV,qBAAqB,EAErB,QAAQ,GACR,MAAM,wBAAwB,CAAC;AAGhC,MAAM,CAAC,MAAM,iBAAiB,GAAG,QAAQ,CAAC;AAc1C,MAAM,QAAQ,GAAG;IAChB,OAAO,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;IACvE,IAAI,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;IACnE,KAAK,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;IACpE,GAAG,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,GAAG,E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,GAAG,CAAC,EAAE,KAAK,GAAG,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC;QACzC,MAAM,MAAM,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;QAChC,IAAI,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;YAAE,IAAI,GAAG,MAAM,CAAC;;YAChC,GAAG,GAAG,MAAM,CAAC;IACnB,CAAC;IACD,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;AACjB,CAAC;AAED;;;;GAIG;AACH,SAAS,aAAa,CAAC,UAAkB,EAAE,UAAuC;IACjF,MAAM,MAAM,GAAG,EAAyC,CAAC;IACzD,MAAM,GAAG,GAAiB,EAAE,CAAC;IAC7B,KAAK,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,cAAc,CAA+B,EAAE,CAAC;QAChG,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAgB,CAAC,EAAE,CAAC;YACvC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;YACnB,SAAS;QACV,CAAC;QACD,MAAM,OAAO,GAAG,UAAU,KAAK,SAAS,CAAC;QACzC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,IAAI,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACpG,IAAI,OAAO,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,KAAmB,CAAC;YAAE,GAAG,CAAC,IAAI,CAAC,KAAmB,CAAC,CAAC;IAChG,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC;AACpC,CAAC","sourcesContent":["/**\n * The `system` theme: pi's colors derived from the terminal's own theme.\n *\n * Every token belongs to a color family (its hue) and has contrast rules: it must reach a contrast level\n * on the background and on the panels it is drawn on. Hue and saturation come from the terminal's palette\n * color for the family's ANSI slot, or from the family's own hue when the terminal reports no palette.\n * Lightness comes from the rules alone. Colors are built in OKHSL, whose saturation is relative to the\n * sRGB gamut, and fade toward gray near black and white.\n *\n * A contrast level is a target-lightness curve: the OKLab lightness a token needs, given the lightness of\n * the surface below it. The curves were fitted to the reference theme design from the \"Pi themes: system\n * and light/dark\" review. On dark backgrounds they aim for nearly fixed lightness; on light backgrounds the\n * required difference grows as the background darkens.\n *\n * Depending on what the terminal reports, the theme is generated in one of three tiers:\n * - background and palette: hues from the palette, lightness from the background;\n * - background only: the families' own hues, lightness from the background;\n * - nothing: ANSI palette indices and the default colors, which the terminal renders itself.\n */\n\nimport {\n\tcolorToOkhsl,\n\tcolorToOklch,\n\ttype OkhslChannels,\n\tokhslColor,\n\toklabToOkhslLightness,\n\ttype RgbColor,\n\trgbColor,\n} from \"@earendil-works/pi-tui\";\nimport type { ThemeAppearance, ThemeBg, ThemeColor, ThemeToken } from \"./theme.ts\";\n\nexport const SYSTEM_THEME_NAME = \"system\";\n\n// ============================================================================\n// Recipe: color families and their tokens\n// ============================================================================\n\n/** A family's OKHSL hue and saturation: `max` at mid lightness, falling toward `min` at black and white. */\ninterface Family {\n\thue: number;\n\tsaturation: { min: number; max: number };\n\t/** ANSI palette slot the family takes its hue and saturation from. */\n\tslot: number;\n}\n\nconst FAMILIES = {\n\tneutral: { hue: 231.49, saturation: { min: 0.02, max: 0.08 }, slot: 8 },\n\tblue: { hue: 231.49, saturation: { min: 0.1, max: 0.68 }, slot: 4 },\n\tgreen: { hue: 158.68, saturation: { min: 0.1, max: 0.76 }, slot: 2 },\n\tred: { hue: 20, saturation: { min: 0.1, max: 0.92 }, slot: 1 },\n\tyellow: { hue: 82.36, saturation: { min: 0.5, max: 1 }, slot: 3 },\n\torange: { hue: 52, saturation: { min: 0.12, max: 0.85 }, slot: 3 },\n\tviolet: { hue: 295, saturation: { min: 0.2, max: 0.6 }, slot: 5 },\n\tcalamine: { hue: 202.43, saturation: { min: 0.1, max: 0.74 }, slot: 6 },\n\tthinkingSlate: { hue: 231.49, saturation: { min: 0.08, max: 0.2 }, slot: 4 },\n\tthinkingBlue: { hue: 231.49, saturation: { min: 0.2, max: 0.45 }, slot: 4 },\n\tthinkingPeriwinkle: { hue: 263.25, saturation: { min: 0.3, max: 0.6 }, slot: 6 },\n\tthinkingViolet: { hue: 295, saturation: { min: 0.4, max: 0.75 }, slot: 5 },\n\tthinkingMagenta: { hue: 337.5, saturation: { min: 0.5, max: 0.85 }, slot: 13 },\n\tthinkingRed: { hue: 20, saturation: { min: 0.95, max: 1 }, slot: 1 },\n} satisfies Record<string, Family>;\n\ntype FamilyName = keyof typeof FAMILIES;\n\nconst TOKEN_FAMILIES: Record<ThemeToken, FamilyName> = {\n\tselectedBg: \"blue\",\n\tsearchMatchBg: \"orange\",\n\tuserMessageBg: \"blue\",\n\tcustomMessageBg: \"violet\",\n\ttoolPendingBg: \"neutral\",\n\ttoolSuccessBg: \"green\",\n\ttoolErrorBg: \"red\",\n\n\ttext: \"neutral\",\n\tuserMessageText: \"neutral\",\n\tcustomMessageText: \"neutral\",\n\ttoolTitle: \"neutral\",\n\tsyntaxOperator: \"neutral\",\n\tsyntaxPunctuation: \"neutral\",\n\tmuted: \"neutral\",\n\tdim: \"neutral\",\n\tthinkingText: \"neutral\",\n\ttoolOutput: \"neutral\",\n\tmdLinkUrl: \"neutral\",\n\tmdQuote: \"neutral\",\n\tmdQuoteBorder: \"neutral\",\n\tmdHr: \"neutral\",\n\tmdCodeBlockBorder: \"neutral\",\n\ttoolDiffContext: \"neutral\",\n\tsyntaxComment: \"neutral\",\n\tscrollbarTrack: \"neutral\",\n\tscrollbarThumb: \"neutral\",\n\tsearchMatchText: \"neutral\",\n\tborderMuted: \"neutral\",\n\n\taccent: \"violet\",\n\tborderAccent: \"violet\",\n\tcustomMessageLabel: \"violet\",\n\tmdCode: \"violet\",\n\tmdListBullet: \"violet\",\n\tsyntaxType: \"violet\",\n\tborder: \"blue\",\n\tmdLink: \"blue\",\n\tsyntaxKeyword: \"blue\",\n\tsyntaxVariable: \"calamine\",\n\tsuccess: \"green\",\n\tmdCodeBlock: \"green\",\n\ttoolDiffAdded: \"green\",\n\tbashMode: \"green\",\n\tsyntaxNumber: \"green\",\n\terror: \"red\",\n\ttoolDiffRemoved: \"red\",\n\twarning: \"yellow\",\n\tmdHeading: \"yellow\",\n\tsyntaxFunction: \"yellow\",\n\tsyntaxString: \"orange\",\n\n\tthinkingOff: \"neutral\",\n\tthinkingMinimal: \"thinkingSlate\",\n\tthinkingLow: \"thinkingBlue\",\n\tthinkingMedium: \"thinkingPeriwinkle\",\n\tthinkingHigh: \"thinkingViolet\",\n\tthinkingXhigh: \"thinkingMagenta\",\n\tthinkingMax: \"thinkingRed\",\n};\n\n/** Palette slots for tokens that would otherwise share a hue with a similar token. */\nconst TOKEN_SLOTS: Partial<Record<ThemeToken, number>> = { syntaxString: 2, syntaxNumber: 5, searchMatchBg: 3 };\n\n// ============================================================================\n// Contrast levels and rules\n// ============================================================================\n\n/**\n * Target-lightness curves: a polynomial in the surface's OKLab lightness giving the OKLab lightness a token\n * needs on it. `reachable` is the range of surface lightness where the level can be reached; beyond it the\n * level is relaxed.\n */\ninterface Curve {\n\tcoefficients: number[];\n\treachable: [number, number];\n}\n\nconst LEVELS = {\n\tpanel: {\n\t\tdark: { coefficients: [0.29131, -0.39746, 2.33185, -0.85524, -1.2076, 0.86276], reachable: [0, 0.979] },\n\t\tlight: { coefficients: [-3.74073, 27.94549, -78.44258, 112.6798, -79.60015, 22.11277], reachable: [0.348, 1] },\n\t},\n\ttrack: {\n\t\tdark: { coefficients: [0.39028, -0.23015, 0.83573, 2.43829, -4.38292, 2.01582], reachable: [0, 0.946] },\n\t\tlight: { coefficients: [-5.24921, 38.37322, -107.28833, 152.10005, -106.17127, 29.18061], reachable: [0.368, 1] },\n\t},\n\tthinking0: {\n\t\tdark: { coefficients: [0.52988, -0.05809, -0.30924, 4.63567, -6.52933, 2.89108], reachable: [0, 0.873] },\n\t\tlight: {\n\t\t\tcoefficients: [-28.27749, 182.85284, -469.62416, 603.15916, -384.59976, 97.35147],\n\t\t\treachable: [0.51, 1],\n\t\t},\n\t},\n\tthinking1: {\n\t\tdark: { coefficients: [0.55278, -0.03667, -0.45659, 4.95347, -6.90265, 3.0706], reachable: [0, 0.858] },\n\t\tlight: {\n\t\t\tcoefficients: [-37.10484, 235.86282, -596.62344, 754.3633, -474.00763, 118.3551],\n\t\t\treachable: [0.535, 1],\n\t\t},\n\t},\n\tthinking2: {\n\t\tdark: { coefficients: [0.57486, -0.01765, -0.58987, 5.25227, -7.27175, 3.25532], reachable: [0, 0.842] },\n\t\tlight: {\n\t\t\tcoefficients: [-59.89653, 377.05024, -945.07843, 1182.03145, -734.96375, 181.68658],\n\t\t\treachable: [0.556, 1],\n\t\t},\n\t},\n\tthinking3: {\n\t\tdark: { coefficients: [0.59621, -0.00062, -0.71148, 5.53588, -7.6392, 3.44606], reachable: [0, 0.827] },\n\t\tlight: {\n\t\t\tcoefficients: [-72.07122, 445.84082, -1099.57352, 1353.88793, -829.53392, 202.26164],\n\t\t\treachable: [0.58, 1],\n\t\t},\n\t},\n\tthinking4: {\n\t\tdark: { coefficients: [0.61691, 0.01462, -0.82288, 5.80651, -8.00641, 3.64333], reachable: [0, 0.811] },\n\t\tlight: {\n\t\t\tcoefficients: [-110.14338, 674.21488, -1645.75941, 2004.32367, -1215.15899, 293.3183],\n\t\t\treachable: [0.6, 1],\n\t\t},\n\t},\n\tthinking5: {\n\t\tdark: { coefficients: [0.63702, 0.02826, -0.92498, 6.06465, -8.37246, 3.84651], reachable: [0, 0.795] },\n\t\tlight: {\n\t\t\tcoefficients: [-175.47701, 1063.54495, -2570.70594, 3098.80776, -1860.15527, 444.76392],\n\t\t\treachable: [0.62, 1],\n\t\t},\n\t},\n\tthinking6: {\n\t\tdark: { coefficients: [0.65658, 0.04044, -1.01835, 6.30989, -8.73529, 4.05439], reachable: [0, 0.779] },\n\t\tlight: {\n\t\t\tcoefficients: [-183.81712, 1094.70055, -2602.68539, 3088.71276, -1826.91131, 430.75931],\n\t\t\treachable: [0.643, 1],\n\t\t},\n\t},\n\tsubtle: {\n\t\tdark: { coefficients: [0.56762, -0.02475, -0.5383, 5.12628, -7.10931, 3.17324], reachable: [0, 0.848] },\n\t\tlight: {\n\t\t\tcoefficients: [-232.85459, 1376.54473, -3249.11801, 3827.91186, -2248.29472, 526.55751],\n\t\t\treachable: [0.657, 1],\n\t\t},\n\t},\n\tthumb: {\n\t\tdark: { coefficients: [0.60323, 0.00278, -0.73328, 5.57157, -7.68067, 3.46933], reachable: [0, 0.823] },\n\t\tlight: {\n\t\t\tcoefficients: [-82.89897, 511.01355, -1255.98095, 1540.76821, -940.68087, 228.58523],\n\t\t\treachable: [0.586, 1],\n\t\t},\n\t},\n\treadable: {\n\t\tdark: { coefficients: [0.66937, 0.04704, -1.06871, 6.43941, -8.9332, 4.17229], reachable: [0, 0.77] },\n\t\tlight: {\n\t\t\tcoefficients: [-1554.52576, 8733.56817, -19604.93507, 21977.72696, -12300.99599, 2749.81288],\n\t\t\treachable: [0.751, 1],\n\t\t},\n\t},\n\temphasis: {\n\t\tdark: { coefficients: [0.7303, 0.07695, -1.31626, 7.1681, -10.14436, 4.92846], reachable: [0, 0.712] },\n\t\tlight: {\n\t\t\tcoefficients: [-4948.31942, 26870.91986, -58334.48399, 63280.17197, -34298.01053, 7430.30146],\n\t\t\treachable: [0.811, 1],\n\t\t},\n\t},\n\ttextOnPanel: {\n\t\tdark: { coefficients: [0.86713, 0.05232, -0.89428, 4.79014, -5.5432, 1.75023], reachable: [0, 0.542] },\n\t\tlight: {\n\t\t\tcoefficients: [-8570.89457, 43954.60805, -90084.00702, 92220.6791, -47152.15802, 9632.27113],\n\t\t\treachable: [0.867, 1],\n\t\t},\n\t},\n\ttext: {\n\t\tdark: { coefficients: [0.89242, 0.02311, -0.44862, 2.34417, -0.06084, -2.63844], reachable: [0, 0.5] },\n\t\tlight: {\n\t\t\tcoefficients: [-2004.67048, 6664.47299, -6060.70202, -1792.61209, 5133.82359, -1939.85583],\n\t\t\treachable: [0.894, 1],\n\t\t},\n\t},\n} satisfies Record<string, Record<ThemeAppearance, Curve>>;\n\ntype Level = keyof typeof LEVELS;\n\ntype Surface = ThemeBg | \"background\" | \"scrollbarTrack\";\n\ninterface Rule {\n\ttoken: ThemeToken;\n\ton: Surface[];\n\tlevel: Level;\n}\n\nconst TOOL_PANELS: Surface[] = [\"toolPendingBg\", \"toolSuccessBg\", \"toolErrorBg\"];\nconst MESSAGE_PANELS: Surface[] = [\"userMessageBg\", \"customMessageBg\"];\nconst PANELS: ThemeBg[] = [\n\t\"userMessageBg\",\n\t\"toolPendingBg\",\n\t\"toolSuccessBg\",\n\t\"toolErrorBg\",\n\t\"selectedBg\",\n\t\"searchMatchBg\",\n\t\"customMessageBg\",\n];\nconst THINKING: ThemeColor[] = [\n\t\"thinkingOff\",\n\t\"thinkingMinimal\",\n\t\"thinkingLow\",\n\t\"thinkingMedium\",\n\t\"thinkingHigh\",\n\t\"thinkingXhigh\",\n\t\"thinkingMax\",\n];\nconst THINKING_LEVELS: Level[] = [\n\t\"thinking0\",\n\t\"thinking1\",\n\t\"thinking2\",\n\t\"thinking3\",\n\t\"thinking4\",\n\t\"thinking5\",\n\t\"thinking6\",\n];\n\nconst each = (tokens: ThemeToken[], on: Surface[], level: Level): Rule[] =>\n\ttokens.map((token) => ({ token, on, level }));\n\nconst RULES: Rule[] = [\n\t...each(PANELS, [\"background\"], \"panel\"),\n\t{ token: \"text\", on: [\"background\"], level: \"text\" },\n\t{ token: \"text\", on: [\"selectedBg\"], level: \"textOnPanel\" },\n\t{ token: \"userMessageText\", on: [\"userMessageBg\"], level: \"textOnPanel\" },\n\t{ token: \"toolTitle\", on: TOOL_PANELS, level: \"textOnPanel\" },\n\t...each([\"accent\", \"success\", \"error\", \"warning\"], [\"background\", \"selectedBg\", ...TOOL_PANELS], \"readable\"),\n\t{ token: \"muted\", on: [\"background\", \"selectedBg\", \"customMessageBg\", ...TOOL_PANELS], level: \"readable\" },\n\t{ token: \"dim\", on: [\"background\", \"selectedBg\", \"customMessageBg\", ...TOOL_PANELS], level: \"subtle\" },\n\t{ token: \"thinkingText\", on: [\"background\"], level: \"readable\" },\n\t{ token: \"customMessageText\", on: [\"customMessageBg\", ...TOOL_PANELS], level: \"readable\" },\n\t{\n\t\ttoken: \"customMessageLabel\",\n\t\ton: [\"background\", \"customMessageBg\", \"selectedBg\", ...TOOL_PANELS],\n\t\tlevel: \"readable\",\n\t},\n\t{ token: \"toolOutput\", on: [\"background\", ...TOOL_PANELS], level: \"readable\" },\n\t...each(\n\t\t[\"mdHeading\", \"mdLink\", \"mdLinkUrl\", \"mdCode\", \"mdQuote\", \"mdCodeBlockBorder\", \"mdListBullet\"],\n\t\t[\"background\", ...MESSAGE_PANELS],\n\t\t\"readable\",\n\t),\n\t{ token: \"mdCodeBlock\", on: [\"background\", ...MESSAGE_PANELS, ...TOOL_PANELS], level: \"readable\" },\n\t...each([\"toolDiffAdded\", \"toolDiffRemoved\", \"toolDiffContext\"], [\"background\", ...TOOL_PANELS], \"readable\"),\n\t...each(\n\t\t[\n\t\t\t\"syntaxComment\",\n\t\t\t\"syntaxKeyword\",\n\t\t\t\"syntaxFunction\",\n\t\t\t\"syntaxVariable\",\n\t\t\t\"syntaxString\",\n\t\t\t\"syntaxNumber\",\n\t\t\t\"syntaxType\",\n\t\t\t\"syntaxOperator\",\n\t\t\t\"syntaxPunctuation\",\n\t\t],\n\t\t[\"background\", ...MESSAGE_PANELS, ...TOOL_PANELS],\n\t\t\"readable\",\n\t),\n\t{ token: \"searchMatchText\", on: [\"searchMatchBg\"], level: \"readable\" },\n\t...each([\"bashMode\", \"border\", \"borderAccent\"], [\"background\"], \"readable\"),\n\t{ token: \"borderMuted\", on: [\"background\"], level: \"subtle\" },\n\t...each([\"mdQuoteBorder\", \"mdHr\"], [\"background\", ...MESSAGE_PANELS, ...TOOL_PANELS], \"readable\"),\n\t{ token: \"scrollbarTrack\", on: [\"background\"], level: \"track\" },\n\t{ token: \"scrollbarThumb\", on: [\"scrollbarTrack\"], level: \"thumb\" },\n\t...THINKING.map((token, index): Rule => ({ token, on: [\"background\"], level: THINKING_LEVELS[index] })),\n];\n\n/** Relaxation compresses levels stronger than this one toward it before weakening all levels. */\nconst READABLE_FLOOR: Record<ThemeAppearance, Level> = { dark: \"readable\", light: \"subtle\" };\n\n/** Body text uses the terminal's foreground when it reaches this level, which is clearly stronger than muted. */\nconst FOREGROUND_LEVEL: Level = \"emphasis\";\n\n/** Text-level tokens that take the terminal's foreground. */\nconst FOREGROUND_TOKENS: ThemeColor[] = [\"text\", \"userMessageText\", \"toolTitle\"];\n\n/** WCAG 2 contrast ratio that body text must reach on the surfaces it is drawn on. */\nconst TEXT_MINIMUM_WCAG_CONTRAST = 4.5;\n\n/** Tokens in dependency order: every surface before the tokens drawn on it. */\nconst SOLVE_ORDER: ThemeToken[] = (() => {\n\tconst order: ThemeToken[] = [];\n\tconst visit = (token: ThemeToken): void => {\n\t\tif (order.includes(token)) return;\n\t\tfor (const rule of RULES) {\n\t\t\tif (rule.token !== token) continue;\n\t\t\tfor (const surface of rule.on) if (surface !== \"background\") visit(surface);\n\t\t}\n\t\torder.push(token);\n\t};\n\tfor (const rule of RULES) visit(rule.token);\n\treturn order;\n})();\n\n// ============================================================================\n// Public API\n// ============================================================================\n\nexport interface SystemThemeInput {\n\tforeground?: RgbColor;\n\tbackground?: RgbColor;\n\t/** ANSI colors 0-15. */\n\tpalette?: RgbColor[];\n\t/** Saturation multiplier from 0 (grayscale) to 1. The first frame renders in grayscale until colors arrive. */\n\tsaturation?: number;\n\t/** Appearance when the terminal did not report its background, e.g. from its light/dark report or COLORFGBG. */\n\tappearanceHint?: ThemeAppearance;\n}\n\nexport interface SystemThemeColors {\n\t/** Hex colors, ANSI palette indices, or \"\" for the terminal default. */\n\tcolors: Record<ThemeToken, string | number>;\n\t/** Foreground tokens rendered faint (SGR 2), for terminals that did not report colors. */\n\tdim: ThemeColor[];\n\tappearance: ThemeAppearance | undefined;\n}\n\n/** OKLab lightness of an sRGB color, 0-1. */\nfunction oklabLightness(color: RgbColor): number {\n\treturn colorToOklch(rgbColor(color.r, color.g, color.b)).l;\n}\n\n/** WCAG 2 relative luminance. */\nexport function relativeLuminance({ r, g, b }: RgbColor): number {\n\tconst linear = (channel: number) => {\n\t\tconst value = channel / 255;\n\t\treturn value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;\n\t};\n\treturn 0.2126 * linear(r) + 0.7152 * linear(g) + 0.0722 * linear(b);\n}\n\n/** WCAG 2 contrast ratio, 1-21. */\nexport function wcagContrast(first: RgbColor, second: RgbColor): number {\n\tconst a = relativeLuminance(first);\n\tconst b = relativeLuminance(second);\n\treturn (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05);\n}\n\n/**\n * Whether a terminal is dark or light, from its reported colors: the direction of its own foreground\n * when text can be readable that way, otherwise dark when white text has more contrast on the\n * background than black text.\n */\nexport function terminalAppearance(background: RgbColor, foreground?: RgbColor): ThemeAppearance {\n\tconst white = { r: 255, g: 255, b: 255 };\n\tconst black = { r: 0, g: 0, b: 0 };\n\tconst whiteContrast = wcagContrast(white, background);\n\tconst blackContrast = wcagContrast(black, background);\n\tif (foreground) {\n\t\tconst foregroundL = oklabLightness(foreground);\n\t\tconst backgroundL = oklabLightness(background);\n\t\tif (Math.abs(foregroundL - backgroundL) > 0.05) {\n\t\t\tconst appearance = foregroundL > backgroundL ? \"dark\" : \"light\";\n\t\t\tconst best = appearance === \"dark\" ? whiteContrast : blackContrast;\n\t\t\tif (best >= TEXT_MINIMUM_WCAG_CONTRAST) return appearance;\n\t\t}\n\t}\n\treturn whiteContrast >= blackContrast ? \"dark\" : \"light\";\n}\n\n// ============================================================================\n// Generation\n// ============================================================================\n\nconst clamp = (value: number, min: number, max: number) => Math.min(max, Math.max(min, value));\n\nfunction hexOf({ r, g, b }: RgbColor): string {\n\treturn `#${[r, g, b].map((channel) => Math.round(channel).toString(16).padStart(2, \"0\")).join(\"\")}`;\n}\n\n/** Saturation weight at a lightness: a Gaussian (center 0.5, sigma 0.25), 0 at black and white, 1 in the middle. */\nfunction bellWeight(lightness: number): number {\n\tconst gaussian = (x: number): number => Math.exp(-((x - 0.5) ** 2) / (2 * 0.25 ** 2));\n\treturn (gaussian(lightness) - gaussian(0)) / (1 - gaussian(0));\n}\n\n/** A family's saturation curve relative to its maximum: 1 at mid lightness, `min / max` at black and white. */\nfunction saturationCurve({ saturation: { min, max } }: Family, lightness: number): number {\n\tconst floor = max > 0 ? min / max : 1;\n\treturn floor + (1 - floor) * bellWeight(lightness);\n}\n\n/** The target lightness for a level on a surface, or undefined where the level cannot be reached. */\nfunction levelTarget(level: Level, appearance: ThemeAppearance, surfaceL: number): number | undefined {\n\tconst curve: Curve = LEVELS[level][appearance];\n\tif (surfaceL < curve.reachable[0] || surfaceL > curve.reachable[1]) return undefined;\n\treturn curve.coefficients.reduce((sum, coefficient, power) => sum + coefficient * surfaceL ** power, 0);\n}\n\n/**\n * Generate the system theme's colors from the terminal's reported colors.\n */\nexport function generateSystemThemeColors(input: SystemThemeInput): SystemThemeColors {\n\tconst saturation = clamp(input.saturation ?? 1, 0, 1);\n\tconst { background, foreground } = input;\n\tif (!background) return indexedColors(saturation, input.appearanceHint);\n\tconst palette = input.palette?.length === 16 ? input.palette.map(okhslOf) : undefined;\n\n\tconst appearance = terminalAppearance(background, foreground);\n\tconst lighter = appearance === \"dark\";\n\tconst extreme = lighter ? 1 : 0;\n\tconst backgroundL = oklabLightness(background);\n\n\t/**\n\t * A token's color at an OKLab lightness. With a palette, the palette color's saturation applies at its\n\t * own lightness and falls off toward black and white along the family's curve, never rising above it.\n\t */\n\tconst paint = (token: ThemeToken, oklabL: number): RgbColor => {\n\t\tconst lightness = oklabToOkhslLightness(oklabL);\n\t\tconst family: Family = FAMILIES[TOKEN_FAMILIES[token]];\n\t\tif (!palette) {\n\t\t\tconst { min, max } = family.saturation;\n\t\t\treturn okhslColor(family.hue, (min + (max - min) * bellWeight(lightness)) * saturation, lightness);\n\t\t}\n\t\treturn anchored(palette[TOKEN_SLOTS[token] ?? family.slot], family, lightness, saturation);\n\t};\n\n\t/**\n\t * The lightness a rule needs on a surface, relaxed by `t`: from 0 to 1, levels stronger than the readable\n\t * floor move toward it; from 1 to 2, all levels move toward the surface itself.\n\t */\n\tconst target = (level: Level, surfaceL: number, t: number): number | undefined => {\n\t\tconst reached = levelTarget(level, appearance, surfaceL);\n\t\tif (reached === undefined && t === 0) return undefined;\n\t\tconst distance = (reached ?? extreme) - surfaceL;\n\t\tconst floor = (levelTarget(READABLE_FLOOR[appearance], appearance, surfaceL) ?? extreme) - surfaceL;\n\t\tconst compressed =\n\t\t\tMath.abs(distance) > Math.abs(floor) ? distance - (distance - floor) * Math.min(t, 1) : distance;\n\t\treturn surfaceL + compressed * (1 - Math.max(0, t - 1));\n\t};\n\n\t/**\n\t * Keep a panel light enough (or dark enough) that white (or black) text still reaches the body text\n\t * minimum on it. This only matters for backgrounds near mid-gray, where it barely does on the background.\n\t */\n\tconst extremeText = lighter ? { r: 255, g: 255, b: 255 } : { r: 0, g: 0, b: 0 };\n\tconst readable = (color: RgbColor) => wcagContrast(extremeText, color) >= TEXT_MINIMUM_WCAG_CONTRAST;\n\tconst limitPanel = (token: ThemeToken, l: number): RgbColor => {\n\t\tconst color = paint(token, l);\n\t\tif (readable(color)) return color;\n\t\tlet [low, high] = [backgroundL, l];\n\t\tfor (let index = 0; index < 20; index++) {\n\t\t\tconst middle = (low + high) / 2;\n\t\t\tif (readable(paint(token, middle))) low = middle;\n\t\t\telse high = middle;\n\t\t}\n\t\treturn paint(token, low);\n\t};\n\n\tconst solve = (t: number): Map<Surface | ThemeToken, RgbColor> | undefined => {\n\t\tconst colors = new Map<Surface | ThemeToken, RgbColor>([[\"background\", background]]);\n\t\tfor (const token of SOLVE_ORDER) {\n\t\t\tconst targets: number[] = [];\n\t\t\tfor (const rule of RULES) {\n\t\t\t\tif (rule.token !== token) continue;\n\t\t\t\tfor (const surface of rule.on) {\n\t\t\t\t\tconst value = target(rule.level, oklabLightness(colors.get(surface) ?? background), t);\n\t\t\t\t\tif (value === undefined || value < 0 || value > 1) return undefined;\n\t\t\t\t\ttargets.push(value);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst l = lighter ? Math.max(...targets) : Math.min(...targets);\n\t\t\tcolors.set(token, PANELS.includes(token as ThemeBg) ? limitPanel(token, l) : paint(token, l));\n\t\t}\n\t\treturn colors;\n\t};\n\n\tlet relaxation = 0;\n\tlet colors = solve(0);\n\tif (!colors) {\n\t\t// Mid-gray backgrounds cannot fit every level: relax as little as possible. Full relaxation always fits.\n\t\tlet [low, high] = [0, 2];\n\t\tcolors = solve(high);\n\t\tfor (let index = 0; index < 20; index++) {\n\t\t\tconst middle = (low + high) / 2;\n\t\t\tconst attempt = solve(middle);\n\t\t\tif (attempt) [high, colors] = [middle, attempt];\n\t\t\telse low = middle;\n\t\t}\n\t\trelaxation = high;\n\t}\n\tconst solved = colors ?? new Map<Surface | ThemeToken, RgbColor>();\n\tconst surfacesOf = (token: ThemeToken) =>\n\t\tRULES.filter((rule) => rule.token === token).flatMap((rule) =>\n\t\t\trule.on.map((surface) => solved.get(surface) ?? background),\n\t\t);\n\n\tconst result = {} as Record<ThemeToken, string | number>;\n\tfor (const token of Object.keys(TOKEN_FAMILIES) as ThemeToken[]) {\n\t\tconst color = solved.get(token);\n\t\tresult[token] = color ? hexOf(color) : \"\";\n\t}\n\n\tfor (const token of FOREGROUND_TOKENS) {\n\t\tconst surfaces = surfacesOf(token);\n\t\t// Body text uses the terminal's own foreground where it is clearly stronger than muted text; otherwise\n\t\t// the foreground's hue at just enough lightness.\n\t\tlet text = solved.get(token);\n\t\tif (foreground) {\n\t\t\tconst targets = surfaces.map((surface) => target(FOREGROUND_LEVEL, oklabLightness(surface), relaxation));\n\t\t\tif (targets.every((value) => value !== undefined && value >= 0 && value <= 1)) {\n\t\t\t\tconst needed = lighter ? Math.max(...(targets as number[])) : Math.min(...(targets as number[]));\n\t\t\t\tconst foregroundL = oklabLightness(foreground);\n\t\t\t\tif (lighter ? foregroundL >= needed : foregroundL <= needed) {\n\t\t\t\t\tresult[token] = \"\";\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\ttext = anchored(okhslOf(foreground), FAMILIES.neutral, oklabToOkhslLightness(needed), saturation);\n\t\t\t}\n\t\t}\n\t\t// Body text keeps at least 4.5:1 on the surfaces it is drawn on, even on relaxed mid-gray backgrounds.\n\t\tif (text) result[token] = hexOf(withTextContrast(text, surfaces, lighter));\n\t}\n\treturn { colors: result, dim: [], appearance };\n}\n\nfunction okhslOf({ r, g, b }: RgbColor): OkhslChannels {\n\treturn colorToOkhsl(rgbColor(r, g, b));\n}\n\n/**\n * A source color's hue at another OKHSL lightness. Its saturation applies at its own lightness and falls off\n * toward black and white along the family's saturation curve, never rising above it.\n */\nfunction anchored(source: OkhslChannels, family: Family, lightness: number, saturation: number): RgbColor {\n\tconst anchor = saturationCurve(family, source.l);\n\tconst falloff = anchor > 0 ? Math.min(1, saturationCurve(family, lightness) / anchor) : 1;\n\treturn okhslColor(source.h, source.s * falloff * saturation, lightness);\n}\n\n/** Move a text color toward white or black until it reaches the WCAG minimum on every surface. */\nfunction withTextContrast(color: RgbColor, surfaces: RgbColor[], lighter: boolean): RgbColor {\n\tconst meets = (candidate: RgbColor) =>\n\t\tsurfaces.every((surface) => wcagContrast(candidate, surface) >= TEXT_MINIMUM_WCAG_CONTRAST);\n\tif (meets(color)) return color;\n\tconst { h, s, l } = okhslOf(color);\n\tconst at = (lightness: number) => okhslColor(h, s, lightness);\n\tconst extreme = lighter ? 1 : 0;\n\tif (!meets(at(extreme))) return at(extreme);\n\tlet [low, high] = [l, extreme];\n\tfor (let index = 0; index < 20; index++) {\n\t\tconst middle = (low + high) / 2;\n\t\tif (meets(at(middle))) high = middle;\n\t\telse low = middle;\n\t}\n\treturn at(high);\n}\n\n/**\n * Colors for terminals that reported nothing: the terminal renders ANSI indices 0-15 and the default\n * colors with its own theme, so they fit any background. Neutral tokens below body text are faint (SGR 2)\n * instead of bright black, which some themes make nearly invisible. Panels have no background.\n */\nfunction indexedColors(saturation: number, appearance: ThemeAppearance | undefined): SystemThemeColors {\n\tconst colors = {} as Record<ThemeToken, string | number>;\n\tconst dim: ThemeColor[] = [];\n\tfor (const [token, familyName] of Object.entries(TOKEN_FAMILIES) as [ThemeToken, FamilyName][]) {\n\t\tif (PANELS.includes(token as ThemeBg)) {\n\t\t\tcolors[token] = \"\";\n\t\t\tcontinue;\n\t\t}\n\t\tconst neutral = familyName === \"neutral\";\n\t\tcolors[token] = !neutral && saturation > 0 ? (TOKEN_SLOTS[token] ?? FAMILIES[familyName].slot) : \"\";\n\t\tif (neutral && !FOREGROUND_TOKENS.includes(token as ThemeColor)) dim.push(token as ThemeColor);\n\t}\n\treturn { colors, dim, appearance };\n}\n"]}
1
+ {"version":3,"file":"system-theme.js","sourceRoot":"","sources":["../../../../src/modes/interactive/theme/system-theme.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EACN,YAAY,EACZ,YAAY,EACZ,UAAU,EAEV,UAAU,EACV,qBAAqB,EACrB,UAAU,EAEV,QAAQ,GACR,MAAM,wBAAwB,CAAC;AAGhC,MAAM,CAAC,MAAM,iBAAiB,GAAG,QAAQ,CAAC;AAc1C,MAAM,QAAQ,GAAG;IAChB,OAAO,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;IACvE,IAAI,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,E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,CAAC;IACzD,MAAM,GAAG,GAAiB,EAAE,CAAC;IAC7B,KAAK,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,cAAc,CAA+B,EAAE,CAAC;QAChG,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAgB,CAAC,EAAE,CAAC;YACvC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;YACnB,SAAS;QACV,CAAC;QACD,MAAM,OAAO,GAAG,UAAU,KAAK,SAAS,CAAC;QACzC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,IAAI,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACpG,IAAI,OAAO,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,KAAmB,CAAC;YAAE,GAAG,CAAC,IAAI,CAAC,KAAmB,CAAC,CAAC;IAChG,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC;AACpC,CAAC","sourcesContent":["/**\n * The `system` theme: pi's colors derived from the terminal's own theme.\n *\n * Every token belongs to a color family (its hue) and has contrast rules: it must reach a contrast level\n * on the background and on the panels it is drawn on. Hue and saturation come from the terminal's palette\n * color for the family's ANSI slot, or from the family's own hue when the terminal reports no palette.\n * Lightness comes from the rules alone. Colors are built in OKHSL, whose saturation is relative to the\n * sRGB gamut, and fade toward gray near black and white. A palette color never gains OKLCH chroma when it\n * moves to another lightness, so pastel palettes stay pastel.\n *\n * A contrast level is a target-lightness curve: the OKLab lightness a token needs, given the lightness of\n * the surface below it. The curves were fitted to the reference theme design from the \"Pi themes: system\n * and light/dark\" review. On dark backgrounds they aim for nearly fixed lightness; on light backgrounds the\n * required difference grows as the background darkens.\n *\n * Depending on what the terminal reports, the theme is generated in one of three tiers:\n * - background and palette: hues from the palette, lightness from the background;\n * - background only: the families' own hues, lightness from the background;\n * - nothing: ANSI palette indices and the default colors, which the terminal renders itself.\n */\n\nimport {\n\tcolorToOkhsl,\n\tcolorToOklch,\n\tcolorToRgb,\n\ttype OkhslChannels,\n\tokhslColor,\n\toklabToOkhslLightness,\n\toklchColor,\n\ttype RgbColor,\n\trgbColor,\n} from \"@earendil-works/pi-tui\";\nimport type { ThemeAppearance, ThemeBg, ThemeColor, ThemeToken } from \"./theme.ts\";\n\nexport const SYSTEM_THEME_NAME = \"system\";\n\n// ============================================================================\n// Recipe: color families and their tokens\n// ============================================================================\n\n/** A family's OKHSL hue and saturation: `max` at mid lightness, falling toward `min` at black and white. */\ninterface Family {\n\thue: number;\n\tsaturation: { min: number; max: number };\n\t/** ANSI palette slot the family takes its hue and saturation from. */\n\tslot: number;\n}\n\nconst FAMILIES = {\n\tneutral: { hue: 231.49, saturation: { min: 0.02, max: 0.08 }, slot: 8 },\n\tblue: { hue: 231.49, saturation: { min: 0.1, max: 0.68 }, slot: 4 },\n\tgreen: { hue: 158.68, saturation: { min: 0.1, max: 0.76 }, slot: 2 },\n\tred: { hue: 20, saturation: { min: 0.1, max: 0.92 }, slot: 1 },\n\tyellow: { hue: 82.36, saturation: { min: 0.5, max: 1 }, slot: 3 },\n\torange: { hue: 52, saturation: { min: 0.12, max: 0.85 }, slot: 3 },\n\tviolet: { hue: 295, saturation: { min: 0.2, max: 0.6 }, slot: 5 },\n\tcalamine: { hue: 202.43, saturation: { min: 0.1, max: 0.74 }, slot: 6 },\n\tthinkingSlate: { hue: 231.49, saturation: { min: 0.08, max: 0.2 }, slot: 4 },\n\tthinkingBlue: { hue: 231.49, saturation: { min: 0.2, max: 0.45 }, slot: 4 },\n\tthinkingPeriwinkle: { hue: 263.25, saturation: { min: 0.3, max: 0.6 }, slot: 6 },\n\tthinkingViolet: { hue: 295, saturation: { min: 0.4, max: 0.75 }, slot: 5 },\n\tthinkingMagenta: { hue: 337.5, saturation: { min: 0.5, max: 0.85 }, slot: 13 },\n\tthinkingRed: { hue: 20, saturation: { min: 0.95, max: 1 }, slot: 1 },\n} satisfies Record<string, Family>;\n\ntype FamilyName = keyof typeof FAMILIES;\n\nconst TOKEN_FAMILIES: Record<ThemeToken, FamilyName> = {\n\tselectedBg: \"blue\",\n\tsearchMatchBg: \"orange\",\n\tuserMessageBg: \"blue\",\n\tcustomMessageBg: \"violet\",\n\ttoolPendingBg: \"neutral\",\n\ttoolSuccessBg: \"green\",\n\ttoolErrorBg: \"red\",\n\n\ttext: \"neutral\",\n\tuserMessageText: \"neutral\",\n\tcustomMessageText: \"neutral\",\n\ttoolTitle: \"neutral\",\n\tsyntaxOperator: \"neutral\",\n\tsyntaxPunctuation: \"neutral\",\n\tmuted: \"neutral\",\n\tdim: \"neutral\",\n\tthinkingText: \"neutral\",\n\ttoolOutput: \"neutral\",\n\tmdLinkUrl: \"neutral\",\n\tmdQuote: \"neutral\",\n\tmdQuoteBorder: \"neutral\",\n\tmdHr: \"neutral\",\n\tmdCodeBlockBorder: \"neutral\",\n\ttoolDiffContext: \"neutral\",\n\tsyntaxComment: \"neutral\",\n\tscrollbarTrack: \"neutral\",\n\tscrollbarThumb: \"neutral\",\n\tsearchMatchText: \"neutral\",\n\tborderMuted: \"neutral\",\n\n\taccent: \"violet\",\n\tborderAccent: \"violet\",\n\tcustomMessageLabel: \"violet\",\n\tmdCode: \"violet\",\n\tmdListBullet: \"violet\",\n\tsyntaxType: \"violet\",\n\tborder: \"blue\",\n\tmdLink: \"blue\",\n\tsyntaxKeyword: \"blue\",\n\tsyntaxVariable: \"calamine\",\n\tsuccess: \"green\",\n\tmdCodeBlock: \"green\",\n\ttoolDiffAdded: \"green\",\n\tbashMode: \"green\",\n\tsyntaxNumber: \"green\",\n\terror: \"red\",\n\ttoolDiffRemoved: \"red\",\n\twarning: \"yellow\",\n\tmdHeading: \"yellow\",\n\tsyntaxFunction: \"yellow\",\n\tsyntaxString: \"orange\",\n\n\tthinkingOff: \"neutral\",\n\tthinkingMinimal: \"thinkingSlate\",\n\tthinkingLow: \"thinkingBlue\",\n\tthinkingMedium: \"thinkingPeriwinkle\",\n\tthinkingHigh: \"thinkingViolet\",\n\tthinkingXhigh: \"thinkingMagenta\",\n\tthinkingMax: \"thinkingRed\",\n};\n\n/** Palette slots for tokens that would otherwise share a hue with a similar token. */\nconst TOKEN_SLOTS: Partial<Record<ThemeToken, number>> = { syntaxString: 2, syntaxNumber: 5, searchMatchBg: 3 };\n\n// ============================================================================\n// Contrast levels and rules\n// ============================================================================\n\n/**\n * Target-lightness curves: a polynomial in the surface's OKLab lightness giving the OKLab lightness a token\n * needs on it. `reachable` is the range of surface lightness where the level can be reached; beyond it the\n * level is relaxed.\n */\ninterface Curve {\n\tcoefficients: number[];\n\treachable: [number, number];\n}\n\nconst LEVELS = {\n\tpanel: {\n\t\tdark: { coefficients: [0.29131, -0.39746, 2.33185, -0.85524, -1.2076, 0.86276], reachable: [0, 0.979] },\n\t\tlight: { coefficients: [-3.74073, 27.94549, -78.44258, 112.6798, -79.60015, 22.11277], reachable: [0.348, 1] },\n\t},\n\ttrack: {\n\t\tdark: { coefficients: [0.39028, -0.23015, 0.83573, 2.43829, -4.38292, 2.01582], reachable: [0, 0.946] },\n\t\tlight: { coefficients: [-5.24921, 38.37322, -107.28833, 152.10005, -106.17127, 29.18061], reachable: [0.368, 1] },\n\t},\n\tthinking0: {\n\t\tdark: { coefficients: [0.52988, -0.05809, -0.30924, 4.63567, -6.52933, 2.89108], reachable: [0, 0.873] },\n\t\tlight: {\n\t\t\tcoefficients: [-28.27749, 182.85284, -469.62416, 603.15916, -384.59976, 97.35147],\n\t\t\treachable: [0.51, 1],\n\t\t},\n\t},\n\tthinking1: {\n\t\tdark: { coefficients: [0.55278, -0.03667, -0.45659, 4.95347, -6.90265, 3.0706], reachable: [0, 0.858] },\n\t\tlight: {\n\t\t\tcoefficients: [-37.10484, 235.86282, -596.62344, 754.3633, -474.00763, 118.3551],\n\t\t\treachable: [0.535, 1],\n\t\t},\n\t},\n\tthinking2: {\n\t\tdark: { coefficients: [0.57486, -0.01765, -0.58987, 5.25227, -7.27175, 3.25532], reachable: [0, 0.842] },\n\t\tlight: {\n\t\t\tcoefficients: [-59.89653, 377.05024, -945.07843, 1182.03145, -734.96375, 181.68658],\n\t\t\treachable: [0.556, 1],\n\t\t},\n\t},\n\tthinking3: {\n\t\tdark: { coefficients: [0.59621, -0.00062, -0.71148, 5.53588, -7.6392, 3.44606], reachable: [0, 0.827] },\n\t\tlight: {\n\t\t\tcoefficients: [-72.07122, 445.84082, -1099.57352, 1353.88793, -829.53392, 202.26164],\n\t\t\treachable: [0.58, 1],\n\t\t},\n\t},\n\tthinking4: {\n\t\tdark: { coefficients: [0.61691, 0.01462, -0.82288, 5.80651, -8.00641, 3.64333], reachable: [0, 0.811] },\n\t\tlight: {\n\t\t\tcoefficients: [-110.14338, 674.21488, -1645.75941, 2004.32367, -1215.15899, 293.3183],\n\t\t\treachable: [0.6, 1],\n\t\t},\n\t},\n\tthinking5: {\n\t\tdark: { coefficients: [0.63702, 0.02826, -0.92498, 6.06465, -8.37246, 3.84651], reachable: [0, 0.795] },\n\t\tlight: {\n\t\t\tcoefficients: [-175.47701, 1063.54495, -2570.70594, 3098.80776, -1860.15527, 444.76392],\n\t\t\treachable: [0.62, 1],\n\t\t},\n\t},\n\tthinking6: {\n\t\tdark: { coefficients: [0.65658, 0.04044, -1.01835, 6.30989, -8.73529, 4.05439], reachable: [0, 0.779] },\n\t\tlight: {\n\t\t\tcoefficients: [-183.81712, 1094.70055, -2602.68539, 3088.71276, -1826.91131, 430.75931],\n\t\t\treachable: [0.643, 1],\n\t\t},\n\t},\n\tsubtle: {\n\t\tdark: { coefficients: [0.56762, -0.02475, -0.5383, 5.12628, -7.10931, 3.17324], reachable: [0, 0.848] },\n\t\tlight: {\n\t\t\tcoefficients: [-232.85459, 1376.54473, -3249.11801, 3827.91186, -2248.29472, 526.55751],\n\t\t\treachable: [0.657, 1],\n\t\t},\n\t},\n\tthumb: {\n\t\tdark: { coefficients: [0.60323, 0.00278, -0.73328, 5.57157, -7.68067, 3.46933], reachable: [0, 0.823] },\n\t\tlight: {\n\t\t\tcoefficients: [-82.89897, 511.01355, -1255.98095, 1540.76821, -940.68087, 228.58523],\n\t\t\treachable: [0.586, 1],\n\t\t},\n\t},\n\treadable: {\n\t\tdark: { coefficients: [0.66937, 0.04704, -1.06871, 6.43941, -8.9332, 4.17229], reachable: [0, 0.77] },\n\t\tlight: {\n\t\t\tcoefficients: [-1554.52576, 8733.56817, -19604.93507, 21977.72696, -12300.99599, 2749.81288],\n\t\t\treachable: [0.751, 1],\n\t\t},\n\t},\n\temphasis: {\n\t\tdark: { coefficients: [0.7303, 0.07695, -1.31626, 7.1681, -10.14436, 4.92846], reachable: [0, 0.712] },\n\t\tlight: {\n\t\t\tcoefficients: [-4948.31942, 26870.91986, -58334.48399, 63280.17197, -34298.01053, 7430.30146],\n\t\t\treachable: [0.811, 1],\n\t\t},\n\t},\n\ttextOnPanel: {\n\t\tdark: { coefficients: [0.86713, 0.05232, -0.89428, 4.79014, -5.5432, 1.75023], reachable: [0, 0.542] },\n\t\tlight: {\n\t\t\tcoefficients: [-8570.89457, 43954.60805, -90084.00702, 92220.6791, -47152.15802, 9632.27113],\n\t\t\treachable: [0.867, 1],\n\t\t},\n\t},\n\ttext: {\n\t\tdark: { coefficients: [0.89242, 0.02311, -0.44862, 2.34417, -0.06084, -2.63844], reachable: [0, 0.5] },\n\t\tlight: {\n\t\t\tcoefficients: [-2004.67048, 6664.47299, -6060.70202, -1792.61209, 5133.82359, -1939.85583],\n\t\t\treachable: [0.894, 1],\n\t\t},\n\t},\n} satisfies Record<string, Record<ThemeAppearance, Curve>>;\n\ntype Level = keyof typeof LEVELS;\n\ntype Surface = ThemeBg | \"background\" | \"scrollbarTrack\";\n\ninterface Rule {\n\ttoken: ThemeToken;\n\ton: Surface[];\n\tlevel: Level;\n}\n\nconst TOOL_PANELS: Surface[] = [\"toolPendingBg\", \"toolSuccessBg\", \"toolErrorBg\"];\nconst MESSAGE_PANELS: Surface[] = [\"userMessageBg\", \"customMessageBg\"];\nconst PANELS: ThemeBg[] = [\n\t\"userMessageBg\",\n\t\"toolPendingBg\",\n\t\"toolSuccessBg\",\n\t\"toolErrorBg\",\n\t\"selectedBg\",\n\t\"searchMatchBg\",\n\t\"customMessageBg\",\n];\nconst THINKING: ThemeColor[] = [\n\t\"thinkingOff\",\n\t\"thinkingMinimal\",\n\t\"thinkingLow\",\n\t\"thinkingMedium\",\n\t\"thinkingHigh\",\n\t\"thinkingXhigh\",\n\t\"thinkingMax\",\n];\nconst THINKING_LEVELS: Level[] = [\n\t\"thinking0\",\n\t\"thinking1\",\n\t\"thinking2\",\n\t\"thinking3\",\n\t\"thinking4\",\n\t\"thinking5\",\n\t\"thinking6\",\n];\n\nconst each = (tokens: ThemeToken[], on: Surface[], level: Level): Rule[] =>\n\ttokens.map((token) => ({ token, on, level }));\n\nconst RULES: Rule[] = [\n\t...each(PANELS, [\"background\"], \"panel\"),\n\t{ token: \"text\", on: [\"background\"], level: \"text\" },\n\t{ token: \"text\", on: [\"selectedBg\"], level: \"textOnPanel\" },\n\t{ token: \"userMessageText\", on: [\"userMessageBg\"], level: \"textOnPanel\" },\n\t{ token: \"toolTitle\", on: TOOL_PANELS, level: \"textOnPanel\" },\n\t...each([\"accent\", \"success\", \"error\", \"warning\"], [\"background\", \"selectedBg\", ...TOOL_PANELS], \"readable\"),\n\t{ token: \"muted\", on: [\"background\", \"selectedBg\", \"customMessageBg\", ...TOOL_PANELS], level: \"readable\" },\n\t{ token: \"dim\", on: [\"background\", \"selectedBg\", \"customMessageBg\", ...TOOL_PANELS], level: \"subtle\" },\n\t{ token: \"thinkingText\", on: [\"background\"], level: \"readable\" },\n\t{ token: \"customMessageText\", on: [\"customMessageBg\", ...TOOL_PANELS], level: \"readable\" },\n\t{\n\t\ttoken: \"customMessageLabel\",\n\t\ton: [\"background\", \"customMessageBg\", \"selectedBg\", ...TOOL_PANELS],\n\t\tlevel: \"readable\",\n\t},\n\t{ token: \"toolOutput\", on: [\"background\", ...TOOL_PANELS], level: \"readable\" },\n\t...each(\n\t\t[\"mdHeading\", \"mdLink\", \"mdLinkUrl\", \"mdCode\", \"mdQuote\", \"mdCodeBlockBorder\", \"mdListBullet\"],\n\t\t[\"background\", ...MESSAGE_PANELS],\n\t\t\"readable\",\n\t),\n\t{ token: \"mdCodeBlock\", on: [\"background\", ...MESSAGE_PANELS, ...TOOL_PANELS], level: \"readable\" },\n\t...each([\"toolDiffAdded\", \"toolDiffRemoved\", \"toolDiffContext\"], [\"background\", ...TOOL_PANELS], \"readable\"),\n\t...each(\n\t\t[\n\t\t\t\"syntaxComment\",\n\t\t\t\"syntaxKeyword\",\n\t\t\t\"syntaxFunction\",\n\t\t\t\"syntaxVariable\",\n\t\t\t\"syntaxString\",\n\t\t\t\"syntaxNumber\",\n\t\t\t\"syntaxType\",\n\t\t\t\"syntaxOperator\",\n\t\t\t\"syntaxPunctuation\",\n\t\t],\n\t\t[\"background\", ...MESSAGE_PANELS, ...TOOL_PANELS],\n\t\t\"readable\",\n\t),\n\t{ token: \"searchMatchText\", on: [\"searchMatchBg\"], level: \"readable\" },\n\t...each([\"bashMode\", \"border\", \"borderAccent\"], [\"background\"], \"readable\"),\n\t{ token: \"borderMuted\", on: [\"background\"], level: \"subtle\" },\n\t...each([\"mdQuoteBorder\", \"mdHr\"], [\"background\", ...MESSAGE_PANELS, ...TOOL_PANELS], \"readable\"),\n\t{ token: \"scrollbarTrack\", on: [\"background\"], level: \"track\" },\n\t{ token: \"scrollbarThumb\", on: [\"scrollbarTrack\"], level: \"thumb\" },\n\t...THINKING.map((token, index): Rule => ({ token, on: [\"background\"], level: THINKING_LEVELS[index] })),\n];\n\n/** Relaxation compresses levels stronger than this one toward it before weakening all levels. */\nconst READABLE_FLOOR: Record<ThemeAppearance, Level> = { dark: \"readable\", light: \"subtle\" };\n\n/** Body text uses the terminal's foreground when it reaches this level, which is clearly stronger than muted. */\nconst FOREGROUND_LEVEL: Level = \"emphasis\";\n\n/** Text-level tokens that take the terminal's foreground. */\nconst FOREGROUND_TOKENS: ThemeColor[] = [\"text\", \"userMessageText\", \"toolTitle\"];\n\n/** WCAG 2 contrast ratio that body text must reach on the surfaces it is drawn on. */\nconst TEXT_MINIMUM_WCAG_CONTRAST = 4.5;\n\n/** Tokens in dependency order: every surface before the tokens drawn on it. */\nconst SOLVE_ORDER: ThemeToken[] = (() => {\n\tconst order: ThemeToken[] = [];\n\tconst visit = (token: ThemeToken): void => {\n\t\tif (order.includes(token)) return;\n\t\tfor (const rule of RULES) {\n\t\t\tif (rule.token !== token) continue;\n\t\t\tfor (const surface of rule.on) if (surface !== \"background\") visit(surface);\n\t\t}\n\t\torder.push(token);\n\t};\n\tfor (const rule of RULES) visit(rule.token);\n\treturn order;\n})();\n\n// ============================================================================\n// Public API\n// ============================================================================\n\nexport interface SystemThemeInput {\n\tforeground?: RgbColor;\n\tbackground?: RgbColor;\n\t/** ANSI colors 0-15. */\n\tpalette?: RgbColor[];\n\t/** Saturation multiplier from 0 (grayscale) to 1. The first frame renders in grayscale until colors arrive. */\n\tsaturation?: number;\n\t/** Appearance when the terminal did not report its background, e.g. from its light/dark report or COLORFGBG. */\n\tappearanceHint?: ThemeAppearance;\n}\n\nexport interface SystemThemeColors {\n\t/** Hex colors, ANSI palette indices, or \"\" for the terminal default. */\n\tcolors: Record<ThemeToken, string | number>;\n\t/** Foreground tokens rendered faint (SGR 2), for terminals that did not report colors. */\n\tdim: ThemeColor[];\n\tappearance: ThemeAppearance | undefined;\n}\n\n/** OKLab lightness of an sRGB color, 0-1. */\nfunction oklabLightness(color: RgbColor): number {\n\treturn colorToOklch(rgbColor(color.r, color.g, color.b)).l;\n}\n\n/** WCAG 2 relative luminance. */\nexport function relativeLuminance({ r, g, b }: RgbColor): number {\n\tconst linear = (channel: number) => {\n\t\tconst value = channel / 255;\n\t\treturn value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;\n\t};\n\treturn 0.2126 * linear(r) + 0.7152 * linear(g) + 0.0722 * linear(b);\n}\n\n/** WCAG 2 contrast ratio, 1-21. */\nexport function wcagContrast(first: RgbColor, second: RgbColor): number {\n\tconst a = relativeLuminance(first);\n\tconst b = relativeLuminance(second);\n\treturn (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05);\n}\n\n/**\n * Whether a terminal is dark or light, from its reported colors: the direction of its own foreground\n * when text can be readable that way, otherwise dark when white text has more contrast on the\n * background than black text.\n */\nexport function terminalAppearance(background: RgbColor, foreground?: RgbColor): ThemeAppearance {\n\tconst white = { r: 255, g: 255, b: 255 };\n\tconst black = { r: 0, g: 0, b: 0 };\n\tconst whiteContrast = wcagContrast(white, background);\n\tconst blackContrast = wcagContrast(black, background);\n\tif (foreground) {\n\t\tconst foregroundL = oklabLightness(foreground);\n\t\tconst backgroundL = oklabLightness(background);\n\t\tif (Math.abs(foregroundL - backgroundL) > 0.05) {\n\t\t\tconst appearance = foregroundL > backgroundL ? \"dark\" : \"light\";\n\t\t\tconst best = appearance === \"dark\" ? whiteContrast : blackContrast;\n\t\t\tif (best >= TEXT_MINIMUM_WCAG_CONTRAST) return appearance;\n\t\t}\n\t}\n\treturn whiteContrast >= blackContrast ? \"dark\" : \"light\";\n}\n\n// ============================================================================\n// Generation\n// ============================================================================\n\nconst clamp = (value: number, min: number, max: number) => Math.min(max, Math.max(min, value));\n\nfunction hexOf({ r, g, b }: RgbColor): string {\n\treturn `#${[r, g, b].map((channel) => Math.round(channel).toString(16).padStart(2, \"0\")).join(\"\")}`;\n}\n\n/** Saturation weight at a lightness: a Gaussian (center 0.5, sigma 0.25), 0 at black and white, 1 in the middle. */\nfunction bellWeight(lightness: number): number {\n\tconst gaussian = (x: number): number => Math.exp(-((x - 0.5) ** 2) / (2 * 0.25 ** 2));\n\treturn (gaussian(lightness) - gaussian(0)) / (1 - gaussian(0));\n}\n\n/** A family's saturation curve relative to its maximum: 1 at mid lightness, `min / max` at black and white. */\nfunction saturationCurve({ saturation: { min, max } }: Family, lightness: number): number {\n\tconst floor = max > 0 ? min / max : 1;\n\treturn floor + (1 - floor) * bellWeight(lightness);\n}\n\n/** The target lightness for a level on a surface, or undefined where the level cannot be reached. */\nfunction levelTarget(level: Level, appearance: ThemeAppearance, surfaceL: number): number | undefined {\n\tconst curve: Curve = LEVELS[level][appearance];\n\tif (surfaceL < curve.reachable[0] || surfaceL > curve.reachable[1]) return undefined;\n\treturn curve.coefficients.reduce((sum, coefficient, power) => sum + coefficient * surfaceL ** power, 0);\n}\n\n/**\n * Generate the system theme's colors from the terminal's reported colors.\n */\nexport function generateSystemThemeColors(input: SystemThemeInput): SystemThemeColors {\n\tconst saturation = clamp(input.saturation ?? 1, 0, 1);\n\tconst { background, foreground } = input;\n\tif (!background) return indexedColors(saturation, input.appearanceHint);\n\tconst palette = input.palette?.length === 16 ? input.palette.map(sourceOf) : undefined;\n\n\tconst appearance = terminalAppearance(background, foreground);\n\tconst lighter = appearance === \"dark\";\n\tconst extreme = lighter ? 1 : 0;\n\tconst backgroundL = oklabLightness(background);\n\n\t/**\n\t * A token's color at an OKLab lightness. With a palette, the palette color's saturation applies at its\n\t * own lightness and falls off toward black and white along the family's curve, never rising above it.\n\t */\n\tconst paint = (token: ThemeToken, oklabL: number): RgbColor => {\n\t\tconst lightness = oklabToOkhslLightness(oklabL);\n\t\tconst family: Family = FAMILIES[TOKEN_FAMILIES[token]];\n\t\tif (!palette) {\n\t\t\tconst { min, max } = family.saturation;\n\t\t\treturn okhslColor(family.hue, (min + (max - min) * bellWeight(lightness)) * saturation, lightness);\n\t\t}\n\t\treturn anchored(palette[TOKEN_SLOTS[token] ?? family.slot], family, lightness, saturation);\n\t};\n\n\t/**\n\t * The lightness a rule needs on a surface, relaxed by `t`: from 0 to 1, levels stronger than the readable\n\t * floor move toward it; from 1 to 2, all levels move toward the surface itself.\n\t */\n\tconst target = (level: Level, surfaceL: number, t: number): number | undefined => {\n\t\tconst reached = levelTarget(level, appearance, surfaceL);\n\t\tif (reached === undefined && t === 0) return undefined;\n\t\tconst distance = (reached ?? extreme) - surfaceL;\n\t\tconst floor = (levelTarget(READABLE_FLOOR[appearance], appearance, surfaceL) ?? extreme) - surfaceL;\n\t\tconst compressed =\n\t\t\tMath.abs(distance) > Math.abs(floor) ? distance - (distance - floor) * Math.min(t, 1) : distance;\n\t\treturn surfaceL + compressed * (1 - Math.max(0, t - 1));\n\t};\n\n\t/**\n\t * Keep a panel light enough (or dark enough) that white (or black) text still reaches the body text\n\t * minimum on it. This only matters for backgrounds near mid-gray, where it barely does on the background.\n\t */\n\tconst extremeText = lighter ? { r: 255, g: 255, b: 255 } : { r: 0, g: 0, b: 0 };\n\tconst readable = (color: RgbColor) => wcagContrast(extremeText, color) >= TEXT_MINIMUM_WCAG_CONTRAST;\n\tconst limitPanel = (token: ThemeToken, l: number): RgbColor => {\n\t\tconst color = paint(token, l);\n\t\tif (readable(color)) return color;\n\t\tlet [low, high] = [backgroundL, l];\n\t\tfor (let index = 0; index < 20; index++) {\n\t\t\tconst middle = (low + high) / 2;\n\t\t\tif (readable(paint(token, middle))) low = middle;\n\t\t\telse high = middle;\n\t\t}\n\t\treturn paint(token, low);\n\t};\n\n\tconst solve = (t: number): Map<Surface | ThemeToken, RgbColor> | undefined => {\n\t\tconst colors = new Map<Surface | ThemeToken, RgbColor>([[\"background\", background]]);\n\t\tfor (const token of SOLVE_ORDER) {\n\t\t\tconst targets: number[] = [];\n\t\t\tfor (const rule of RULES) {\n\t\t\t\tif (rule.token !== token) continue;\n\t\t\t\tfor (const surface of rule.on) {\n\t\t\t\t\tconst value = target(rule.level, oklabLightness(colors.get(surface) ?? background), t);\n\t\t\t\t\tif (value === undefined || value < 0 || value > 1) return undefined;\n\t\t\t\t\ttargets.push(value);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst l = lighter ? Math.max(...targets) : Math.min(...targets);\n\t\t\tcolors.set(token, PANELS.includes(token as ThemeBg) ? limitPanel(token, l) : paint(token, l));\n\t\t}\n\t\treturn colors;\n\t};\n\n\tlet relaxation = 0;\n\tlet colors = solve(0);\n\tif (!colors) {\n\t\t// Mid-gray backgrounds cannot fit every level: relax as little as possible. Full relaxation always fits.\n\t\tlet [low, high] = [0, 2];\n\t\tcolors = solve(high);\n\t\tfor (let index = 0; index < 20; index++) {\n\t\t\tconst middle = (low + high) / 2;\n\t\t\tconst attempt = solve(middle);\n\t\t\tif (attempt) [high, colors] = [middle, attempt];\n\t\t\telse low = middle;\n\t\t}\n\t\trelaxation = high;\n\t}\n\tconst solved = colors ?? new Map<Surface | ThemeToken, RgbColor>();\n\tconst surfacesOf = (token: ThemeToken) =>\n\t\tRULES.filter((rule) => rule.token === token).flatMap((rule) =>\n\t\t\trule.on.map((surface) => solved.get(surface) ?? background),\n\t\t);\n\n\tconst result = {} as Record<ThemeToken, string | number>;\n\tfor (const token of Object.keys(TOKEN_FAMILIES) as ThemeToken[]) {\n\t\tconst color = solved.get(token);\n\t\tresult[token] = color ? hexOf(color) : \"\";\n\t}\n\n\tfor (const token of FOREGROUND_TOKENS) {\n\t\tconst surfaces = surfacesOf(token);\n\t\t// Body text uses the terminal's own foreground where it is clearly stronger than muted text; otherwise\n\t\t// the foreground's hue at just enough lightness.\n\t\tlet text = solved.get(token);\n\t\tif (foreground) {\n\t\t\tconst targets = surfaces.map((surface) => target(FOREGROUND_LEVEL, oklabLightness(surface), relaxation));\n\t\t\tif (targets.every((value) => value !== undefined && value >= 0 && value <= 1)) {\n\t\t\t\tconst needed = lighter ? Math.max(...(targets as number[])) : Math.min(...(targets as number[]));\n\t\t\t\tconst foregroundL = oklabLightness(foreground);\n\t\t\t\tif (lighter ? foregroundL >= needed : foregroundL <= needed) {\n\t\t\t\t\tresult[token] = \"\";\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\ttext = anchored(sourceOf(foreground), FAMILIES.neutral, oklabToOkhslLightness(needed), saturation);\n\t\t\t}\n\t\t}\n\t\t// Body text keeps at least 4.5:1 on the surfaces it is drawn on, even on relaxed mid-gray backgrounds.\n\t\tif (text) result[token] = hexOf(withTextContrast(text, surfaces, lighter));\n\t}\n\treturn { colors: result, dim: [], appearance };\n}\n\nfunction okhslOf({ r, g, b }: RgbColor): OkhslChannels {\n\treturn colorToOkhsl(rgbColor(r, g, b));\n}\n\n/** A terminal color's OKHSL channels and its OKLCH chroma. */\ninterface SourceColor extends OkhslChannels {\n\tchroma: number;\n}\n\nfunction sourceOf(color: RgbColor): SourceColor {\n\treturn { ...okhslOf(color), chroma: colorToOklch(rgbColor(color.r, color.g, color.b)).c };\n}\n\n/**\n * A source color's hue at another OKHSL lightness. Its saturation applies at its own lightness and falls off\n * toward black and white along the family's saturation curve, never rising above it.\n *\n * OKHSL saturation is relative to the most chroma sRGB allows at a lightness, so the same saturation can mean\n * more chroma elsewhere: Catppuccin Frappe's pink #f4b8e4 (chroma 0.089) would become #eb76d1 (0.180) at the\n * lightness the accent needs. Chroma is therefore also capped at the source's, with the same falloff.\n */\nfunction anchored(source: SourceColor, family: Family, lightness: number, saturation: number): RgbColor {\n\tconst anchor = saturationCurve(family, source.l);\n\tconst falloff = anchor > 0 ? Math.min(1, saturationCurve(family, lightness) / anchor) : 1;\n\tconst color = okhslColor(source.h, source.s * falloff * saturation, lightness);\n\tconst cap = source.chroma * falloff * saturation;\n\tconst { l, c } = colorToOklch(color);\n\treturn c <= cap ? color : colorToRgb(oklchColor(l, cap, source.h));\n}\n\n/** Move a text color toward white or black until it reaches the WCAG minimum on every surface. */\nfunction withTextContrast(color: RgbColor, surfaces: RgbColor[], lighter: boolean): RgbColor {\n\tconst meets = (candidate: RgbColor) =>\n\t\tsurfaces.every((surface) => wcagContrast(candidate, surface) >= TEXT_MINIMUM_WCAG_CONTRAST);\n\tif (meets(color)) return color;\n\tconst { h, s, l } = okhslOf(color);\n\tconst at = (lightness: number) => okhslColor(h, s, lightness);\n\tconst extreme = lighter ? 1 : 0;\n\tif (!meets(at(extreme))) return at(extreme);\n\tlet [low, high] = [l, extreme];\n\tfor (let index = 0; index < 20; index++) {\n\t\tconst middle = (low + high) / 2;\n\t\tif (meets(at(middle))) high = middle;\n\t\telse low = middle;\n\t}\n\treturn at(high);\n}\n\n/**\n * Colors for terminals that reported nothing: the terminal renders ANSI indices 0-15 and the default\n * colors with its own theme, so they fit any background. Neutral tokens below body text are faint (SGR 2)\n * instead of bright black, which some themes make nearly invisible. Panels have no background.\n */\nfunction indexedColors(saturation: number, appearance: ThemeAppearance | undefined): SystemThemeColors {\n\tconst colors = {} as Record<ThemeToken, string | number>;\n\tconst dim: ThemeColor[] = [];\n\tfor (const [token, familyName] of Object.entries(TOKEN_FAMILIES) as [ThemeToken, FamilyName][]) {\n\t\tif (PANELS.includes(token as ThemeBg)) {\n\t\t\tcolors[token] = \"\";\n\t\t\tcontinue;\n\t\t}\n\t\tconst neutral = familyName === \"neutral\";\n\t\tcolors[token] = !neutral && saturation > 0 ? (TOKEN_SLOTS[token] ?? FAMILIES[familyName].slot) : \"\";\n\t\tif (neutral && !FOREGROUND_TOKENS.includes(token as ThemeColor)) dim.push(token as ThemeColor);\n\t}\n\treturn { colors, dim, appearance };\n}\n"]}
package/docs/cli.md CHANGED
@@ -58,10 +58,10 @@ RPC mode rejects `@file` arguments. JSON and RPC modes reserve stdout for protoc
58
58
  pi --model sonnet:high
59
59
  ```
60
60
 
61
- See [Choose a Model](models.md) for model selection and [Provider Authentication](providers.md) for credentials.
61
+ See [Choose a Model](models.md) for model selection and [Providers](providers.md) for credentials.
62
62
 
63
63
  - `--provider <name>`<br>
64
- Restricts `--model` lookup to one provider.
64
+ Restricts `--model` lookup to one provider. It requires `--model`.
65
65
  - `--model <pattern>`<br>
66
66
  Selects by exact ID or fuzzy ID/name match. It accepts `provider/id` and an optional `:<thinking>` suffix.
67
67
  - `--api-key <key>`<br>
@@ -161,21 +161,11 @@ This keeps `read`, `bash`, `edit`, and `write` and adds `codemode`. For one invo
161
161
  pi --tools read,bash,edit,write,codemode
162
162
  ```
163
163
 
164
- Codemode is useful without MCP: scripts can run several tool calls in parallel, filter large output before it reaches the model, and call classifier models such as TypeSafe's Jev through `models.classify()` (see [Classifier models](models.md#use-classifier-models)).
164
+ Codemode is useful without MCP: scripts can run several tool calls in parallel, filter large output before it reaches the model, call classifier models such as TypeSafe's Jev through `models.classify()` (see [Classifier models](models.md#use-classifier-models)), and generate images through `models.generateImages()` (see [Image models](models.md#use-image-models)).
165
165
 
166
166
  ### How codemode works
167
167
 
168
- Codemode scripts run in a QuickJS sandbox that can only reach the other tools, through `tools.<name>(args)`; `ALL_TOOLS` lists them. Output comes from `text(value)`, `image(dataUrlOrImageContent)`, `console.*`, and a top-level `return value`; `exit()` ends the script early. The result starts with `Script completed` or `Script failed`, the wall time, and the output; a failed script keeps its partial output, followed by `Script error:` and the error.
169
-
170
- A script may start with an options line such as `// @options: {"max_output_tokens": 2000, "timeout_ms": 60000}`. `max_output_tokens` (default 10000) limits the output: longer output keeps its start and end, and the full text is written to a temp file whose path is included in the result. `timeout_ms` is a hard deadline, unset by default.
171
-
172
- While `codemode` is active, `codemode.mode` in [settings](settings.md#tools) decides how the other tools are presented. With `on` (default) declared tools keep being declared and their descriptions show how to call them from scripts. With `only` they are hidden from the model and listed in the `codemode` description instead, so the model calls them through scripts.
173
-
174
- The `codemode` description lists the callable tools with their TypeScript declarations, grouped by namespace (for example one MCP server). Tools with `deferred` exposure, which includes MCP tools with the default `codemode` exposure, are not listed and do not affect the description, so it stays the same while MCP servers connect. Declarations share a budget of 3000 estimated tokens (`codemode.inlineBudget` in [settings](settings.md#tools)). Scripts find the rest with `await searchTools(query, { limit, namespace })`, which ranks tools with BM25, and `await describeTool(name)`, or by filtering `ALL_TOOLS`. `await describeNamespace(name)` returns a namespace's description, its instructions (for MCP servers, the server instructions), and the names of its tools.
175
-
176
- Tools with an output schema resolve to structured values: `bash` to `{ output, truncated, full_output_path?, exit_code, wall_time_seconds }`, also for non-zero exit codes, and MCP tools to their `CallToolResult`. Other tools resolve to their text output. The `output` of `bash` is not limited to the 2000 lines or 50KB the model sees: it holds up to 1 MiB, and longer output keeps its first and last 512 KiB around an omission marker, with `truncated` set and the full output in `full_output_path`.
177
-
178
- `store(key, value)` and `load(key)` keep JSON values across `codemode` calls: each successful script that stores values appends a `codemode-store` custom entry to the session, so resumed sessions keep the values and each branch sees only the values written on its path. Scripts can also use `models`: `getModelsOfType`, `getAvailableOfType`, and `getModelOfType` list the model catalog, and `classify(model, context)` runs a classifier model with the session's credentials, at most four at a time per script.
168
+ Scripts run in a QuickJS sandbox and reach the other tools through `tools.<name>(args)`. [Codemode](codemode.md) describes the script API, how tools are listed and found, the `store()` and `models` globals, and the limits.
179
169
 
180
170
  ### Tool search
181
171
 
@@ -229,7 +219,7 @@ See [Configuration](configuration.md) for saved configuration, [Security](securi
229
219
  - `--append-system-prompt <text|path>`<br>
230
220
  Appends text or an existing file to the system prompt and is repeatable.
231
221
  - `--tui-mode <mode>`<br>
232
- Uses `regular` or `fullscreen` terminal mode.
222
+ Uses `fullscreen` (default) or `regular` terminal mode.
233
223
  - `--verbose`<br>
234
224
  Shows verbose interactive startup information, overriding `quietStartup`.
235
225
  - `-a`, `--approve`<br>
@@ -292,7 +282,7 @@ Add `--force` to reinstall Pi when the selected update includes Pi.
292
282
  pi auth check --provider openai --json
293
283
  ```
294
284
 
295
- Authentication commands require `--provider <provider>` or `--model <model>`. See [Provider Authentication](providers.md) for supported methods.
285
+ Authentication commands require `--provider <provider>` or `--model <model>`. See [Providers](providers.md) for supported methods.
296
286
 
297
287
  | Command | Description |
298
288
  |---|---|
@@ -0,0 +1,207 @@
1
+ # Codemode
2
+
3
+ The `codemode` tool lets the model write a JavaScript script that calls pi's other tools and runs non-LLM models, such as classifiers and image models. Only the script's output reaches the model, so a script can run calls in parallel and filter large results before the model sees them. To turn it on, see [Enable codemode](cli.md#enable-codemode).
4
+
5
+ ## Scripts
6
+
7
+ The tool input is raw JavaScript source, not JSON and not a markdown code fence. It runs as the body of an async function in a QuickJS sandbox, so top-level `await` and `return` work. The sandbox has no Node APIs, file system, network, or timers; scripts reach the outside world only through tools and `models`.
8
+
9
+ A script may start with an options line:
10
+
11
+ ```js
12
+ // @options: {"max_output_tokens": 2000, "timeout_ms": 60000}
13
+ ```
14
+
15
+ - `max_output_tokens` (default 10000) limits the output. Longer output keeps its start and end, and the full text is written to a temp file whose path is included in the result.
16
+ - `timeout_ms` is a hard deadline for the whole script. It is unset by default. Image generation can take minutes, so do not set a short deadline for scripts that generate images.
17
+
18
+ The result starts with `Script completed` or `Script failed`, the wall time, and the output. A failed script keeps its partial output, followed by `Script error:` and the error. Tool calls are real: calls made before a failure are not undone. Calls still running when the script ends are cancelled, and unawaited promises are discarded.
19
+
20
+ ## Globals
21
+
22
+ | Global | Purpose |
23
+ |---|---|
24
+ | `tools.<name>(args)` | Call a tool. See [Call tools](#call-tools). |
25
+ | `text(value)` | Add a text item to the output. Strings are added as is, other values as JSON. |
26
+ | `image(value)` | Add an image to the output: a base64 `data:` URL, an `{ image_url }` object, or an image block `{ type: "image", data, mimeType }` such as those returned by MCP tools and `models.generateImages()`. Remote URLs are not supported. PNG, JPEG, GIF, and WebP are accepted. |
27
+ | `console.log(...)` | Like `text()`; `info`, `warn`, `error`, and `debug` do the same. |
28
+ | `return value` | A top-level `return` adds the value like `text()`. |
29
+ | `exit()` | End the script successfully. |
30
+ | `store(key, value)` / `load(key)` | Keep small JSON values across `codemode` calls. See [Store values](#store-values). |
31
+ | `ALL_TOOLS` | Every callable tool as `{ name, description }`, including tools the description does not list. |
32
+ | `searchTools(query, { limit?, namespace? })` | Rank callable tools by relevance (BM25, default limit 8). Resolves to `{ name, description }[]`. |
33
+ | `describeTool(name)` | Resolves to a tool's description and TypeScript declaration, or `undefined`. |
34
+ | `describeNamespace(name)` | Resolves to `{ name, description?, instructions?, tools }` for a namespace such as an MCP server, or `undefined`. |
35
+ | `models` | List and run non-LLM models. See [Models](#models). |
36
+
37
+ ## Call tools
38
+
39
+ Every tool the session can call is a method of `tools`, named by its identifier: characters that are not valid in a JavaScript identifier become `_`, so the MCP tool `mcp__dev-radius__search` is `tools.mcp__dev_radius__search`. Each method takes one object with the tool's arguments.
40
+
41
+ What a call resolves to depends on the tool:
42
+
43
+ - Tools with an output schema resolve to a structured value. `bash` resolves to `{ output, truncated, full_output_path?, exit_code, wall_time_seconds }`, also for non-zero exit codes. Its `output` is not limited to the 2000 lines or 50KB the model sees: it holds up to 1 MiB, and longer output keeps its first and last 512 KiB around an omission marker, with `truncated` set and the full output in `full_output_path`.
44
+ - MCP tools resolve to their `CallToolResult`, including `isError` and `structuredContent`.
45
+ - Other tools, such as `read`, `edit`, and `write`, resolve to their text output.
46
+
47
+ A call that fails, is blocked, or gets invalid arguments rejects with an `Error` that carries the tool's error text. Use `Promise.allSettled()` to keep the results of the calls that succeed.
48
+
49
+ The `codemode` description lists tools with their TypeScript declarations, grouped by namespace (for example one MCP server). Tools with `deferred` exposure, which includes MCP tools with the default `codemode` exposure, are not listed, so the description stays the same while MCP servers connect. Listed declarations share a budget of 3000 estimated tokens (`codemode.inlineBudget` in [settings](settings.md#tools)). Scripts find the other tools with `searchTools()`, `describeTool()`, `describeNamespace()`, or by filtering `ALL_TOOLS`.
50
+
51
+ While `codemode` is active, `codemode.mode` in [settings](settings.md#tools) decides how the other tools are presented. With `on` (default) declared tools stay declared, and their descriptions say how to call them from scripts. With `only` they are hidden from the model and listed in the `codemode` description instead, so the model calls them through scripts.
52
+
53
+ ## Store values
54
+
55
+ `store(key, value)` keeps a JSON value under a string key for later `codemode` calls; storing `undefined` deletes the key. `load(key)` returns the value, or `undefined`. Writes are kept only when the script succeeds: each successful script that stores values appends a `codemode-store` custom entry to the session, so resumed sessions keep the values and each branch sees only the values written on its path.
56
+
57
+ The store is for small state such as IDs, cursors, or summaries. One value may have at most 262144 characters of JSON and all values together at most 1048576. Do not store image data; show images with `image()` or write them to a file with a tool.
58
+
59
+ ## Models
60
+
61
+ `models` reaches the model catalog and runs non-LLM models with the session's credentials: classifiers, which answer typed questions about JSON state, and image models, which generate images. Chat models are listed but cannot be run from scripts. Which classifier and image models exist is described in [Use classifier models](models.md#use-classifier-models) and [Use image models](models.md#use-image-models).
62
+
63
+ ```ts
64
+ type ModelType = "chat" | "image" | "classifier";
65
+
66
+ /** A catalog entry. `provider` and `id` identify it; other fields depend on the type. */
67
+ interface ModelInfo {
68
+ type?: ModelType;
69
+ provider: string;
70
+ id: string;
71
+ name: string;
72
+ api: string;
73
+ input: ("text" | "image")[];
74
+ contextWindow?: number;
75
+ [key: string]: unknown;
76
+ }
77
+
78
+ declare const models: {
79
+ /** Every known model of a type, optionally for one provider. */
80
+ getModelsOfType(type: ModelType, provider?: string): Promise<ModelInfo[]>;
81
+ /** Models of a type whose provider has working credentials. */
82
+ getAvailableOfType(type: ModelType, provider?: string): Promise<ModelInfo[]>;
83
+ /** One catalog entry, or undefined. */
84
+ getModelOfType(type: ModelType, provider: string, id: string): Promise<ModelInfo | undefined>;
85
+ /** Answer `context.questions` about `context.state`; answers are in `result.answers` by question ID. */
86
+ classify(model: ModelInfo, context: ClassifierContext): Promise<ClassifierResult>;
87
+ /** Generate images from `context.input` text and image blocks; show `result.output` blocks with image(). Can take minutes. */
88
+ generateImages(model: ModelInfo, context: ImagesContext): Promise<ImagesResult>;
89
+ };
90
+ ```
91
+
92
+ `classify()` and `generateImages()` use only the `provider` and `id` of `model`, so `{ provider, id }` works as well. They do not throw on provider errors: check `stopReason` and `errorMessage`. At most four such calls run at once per script; more calls wait for a free slot, so `Promise.all()` over many items is fine. Their usage is added to the `codemode` tool result and counts toward the session cost.
93
+
94
+ Model IDs differ between providers, for example `typesafe/jev-latest` and `openrouter/typesafe/jev-1.13`. Use `models.getAvailableOfType(type)` to find the IDs that work with the current credentials.
95
+
96
+ ### Classify
97
+
98
+ ```ts
99
+ interface ClassifierContext {
100
+ /** The data to classify. */
101
+ state: Record<string, unknown>;
102
+ /** Questions by ID. One call answers all of them. */
103
+ questions: Record<string, ClassifierQuestion>;
104
+ }
105
+
106
+ type ClassifierQuestion =
107
+ /** Pick one label. `criteria` maps each label to what it means. */
108
+ | { type: "choice"; instructions: string; criteria: Record<string, string> }
109
+ /** Score on an ordered scale. `criteria` describes each level, lowest first. */
110
+ | { type: "score"; instructions: string; criteria: string[] }
111
+ /** Yes or no. */
112
+ | { type: "bool"; instructions: string; criteria: { true: string; false: string } };
113
+
114
+ interface ClassifierResult {
115
+ provider: string;
116
+ model: string;
117
+ /** Answers by question ID. */
118
+ answers: Record<string, ClassifierAnswer>;
119
+ usage?: ModelUsage;
120
+ stopReason: "stop" | "error" | "aborted";
121
+ errorMessage?: string;
122
+ }
123
+
124
+ type ClassifierAnswer =
125
+ | { type: "choice"; choice: string; probabilities: Record<string, number>; confidence: number }
126
+ /** `score` is the expected level index, from 0 to `criteria.length - 1`. */
127
+ | { type: "score"; score: number; confidence: number }
128
+ /** Probability of `true`. */
129
+ | { type: "bool"; probability: number };
130
+
131
+ /** Token counts and cost in USD, when the service reports them. */
132
+ type ModelUsage = { input: number; output: number; totalTokens: number; cost: { total: number } };
133
+ ```
134
+
135
+ Classify several items by calling `classify()` once per item. This script sorts feedback messages, for example ones a tool returned earlier in the script:
136
+
137
+ ```js
138
+ const jev = await models.getModelOfType("classifier", "typesafe", "jev-latest");
139
+ const results = await Promise.all(
140
+ messages.map((message) =>
141
+ models.classify(jev, {
142
+ state: { message },
143
+ questions: {
144
+ sentiment: {
145
+ type: "choice",
146
+ instructions: "How does the user feel about the product?",
147
+ criteria: { positive: "Satisfied or happy", negative: "Unhappy or frustrated", neutral: "Neither" },
148
+ },
149
+ urgency: {
150
+ type: "score",
151
+ instructions: "How urgently does this need a reply?",
152
+ criteria: ["no reply needed", "reply this week", "reply today"],
153
+ },
154
+ },
155
+ }),
156
+ ),
157
+ );
158
+ return results.map((result, i) =>
159
+ result.stopReason === "stop"
160
+ ? { message: messages[i], sentiment: result.answers.sentiment.choice, urgency: result.answers.urgency.score }
161
+ : { message: messages[i], error: result.errorMessage },
162
+ );
163
+ ```
164
+
165
+ ### Generate images
166
+
167
+ ```ts
168
+ interface ImagesContext {
169
+ /** The prompt as text blocks, plus image blocks to edit or use as references. */
170
+ input: (TextBlock | ImageBlock)[];
171
+ }
172
+
173
+ interface ImagesResult {
174
+ provider: string;
175
+ model: string;
176
+ /** Generated images, and text blocks for models that also return text. */
177
+ output: (TextBlock | ImageBlock)[];
178
+ usage?: ModelUsage;
179
+ stopReason: "stop" | "error" | "aborted";
180
+ errorMessage?: string;
181
+ }
182
+
183
+ type TextBlock = { type: "text"; text: string };
184
+ /** `data` is base64. */
185
+ type ImageBlock = { type: "image"; data: string; mimeType: string };
186
+ ```
187
+
188
+ Show generated images with `image(block)`. Do not print `data` with `text()`, `console`, or `return`: it is large and the model cannot read it as text. Generated images are not saved to disk; to keep one, write it to a file with a tool.
189
+
190
+ ```js
191
+ // @options: {"timeout_ms": 300000}
192
+ const painter = await models.getModelOfType("image", "openrouter", "google/gemini-2.5-flash-image");
193
+ const result = await models.generateImages(painter, {
194
+ input: [{ type: "text", text: "A red fox in the snow, watercolor" }],
195
+ });
196
+ if (result.stopReason !== "stop") return result.errorMessage;
197
+ for (const block of result.output) {
198
+ if (block.type === "image") image(block);
199
+ else text(block.text);
200
+ }
201
+ ```
202
+
203
+ ## Limits
204
+
205
+ - A script's VM has 256 MB of memory. Running out throws `InternalError: out of memory`; filter or aggregate large data instead of accumulating it.
206
+ - A script that waits on a promise that can never settle (no tool call pending) fails immediately, since there are no timers.
207
+ - Scripts cannot start other `codemode` scripts.
package/docs/docs.json CHANGED
@@ -136,6 +136,10 @@
136
136
  "title": "CLI",
137
137
  "path": "cli.md"
138
138
  },
139
+ {
140
+ "title": "Codemode",
141
+ "path": "codemode.md"
142
+ },
139
143
  {
140
144
  "title": "Slash Commands",
141
145
  "path": "slash-commands.md"
@@ -153,7 +157,7 @@
153
157
  "path": "keybindings.md"
154
158
  },
155
159
  {
156
- "title": "Provider Authentication",
160
+ "title": "Providers",
157
161
  "path": "providers.md"
158
162
  },
159
163
  {