mu-agent 0.1.8 → 0.1.13
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.
- package/CHANGELOG.md +121 -0
- package/README.md +34 -30
- package/dist/bundle/chunks/anthropic-messages-4PAJY4R6.js +6 -0
- package/dist/bundle/chunks/anthropic.js +1 -1
- package/dist/bundle/chunks/azure-openai-responses-Y4BBWQ3N.js +2 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +12 -9
- package/dist/bundle/chunks/{chunk-NG4PO5FP.js → chunk-3J3HSHLX.js} +128 -110
- package/dist/bundle/chunks/{chunk-TRDNDS6A.js → chunk-3V45WARH.js} +6 -3
- package/dist/bundle/chunks/{chunk-S3GGRYIO.js → chunk-5AGIVGSV.js} +1 -1
- package/dist/bundle/chunks/chunk-6QGV3IWD.js +6 -0
- package/dist/bundle/chunks/{chunk-4OBXYPH4.js → chunk-6Z2347ML.js} +1 -1
- package/dist/bundle/chunks/{chunk-F5ZABL6Z.js → chunk-7CBJINYJ.js} +2 -2
- package/dist/bundle/chunks/{chunk-DRQDKNXA.js → chunk-7DDKXS2Q.js} +1 -1
- package/dist/bundle/chunks/{chunk-H3QXYIF7.js → chunk-CF5GWZHW.js} +1 -1
- package/dist/bundle/chunks/{chunk-RLZVFGW4.js → chunk-DYTENXHX.js} +29 -92
- package/dist/bundle/chunks/{chunk-NTSWBG4X.js → chunk-FLHKNMLQ.js} +1 -1
- package/dist/bundle/chunks/chunk-FTJT2X6E.js +2 -0
- package/dist/bundle/chunks/{chunk-4L3WN2XY.js → chunk-JXWJOIH4.js} +1 -1
- package/dist/bundle/chunks/{chunk-TAOL3JFA.js → chunk-KIDDRTZP.js} +4 -4
- package/dist/bundle/chunks/chunk-LHRPMXVI.js +2 -0
- package/dist/bundle/chunks/chunk-LMNWTX2L.js +11 -0
- package/dist/bundle/chunks/chunk-LPXNMA2W.js +2 -0
- package/dist/bundle/chunks/chunk-LT2C56HV.js +130 -0
- package/dist/bundle/chunks/{chunk-6CYCI3EJ.js → chunk-LVVZS2NO.js} +1 -1
- package/dist/bundle/chunks/chunk-MF3VB62R.js +91 -0
- package/dist/bundle/chunks/chunk-NN4BEPYX.js +2 -0
- package/dist/bundle/chunks/{chunk-LD2P6SFZ.js → chunk-PMRZO46Y.js} +1 -1
- package/dist/bundle/chunks/chunk-R4VPBBDS.js +2 -0
- package/dist/bundle/chunks/chunk-RDZVAGPR.js +2 -0
- package/dist/bundle/chunks/chunk-TMTOQ7H7.js +2 -0
- package/dist/bundle/chunks/chunk-UKVNB6C4.js +2 -0
- package/dist/bundle/chunks/chunk-URBBMV3M.js +9 -0
- package/dist/bundle/chunks/chunk-WCGU75WO.js +11 -0
- package/dist/bundle/chunks/chunk-WCJNJQO5.js +9 -0
- package/dist/bundle/chunks/chunk-WDURT4ZM.js +2 -0
- package/dist/bundle/chunks/{cli-AOVD3SSZ.js → cli-M4YBZZ6Q.js} +4 -4
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-MEZHQVNP.js +2 -0
- package/dist/bundle/chunks/codemode-worker.js +117 -13
- package/dist/bundle/chunks/easter-egg-3d-VFY3YRQR.js +2 -0
- package/dist/bundle/chunks/execute-FKI7Y4XR.js +499 -0
- package/dist/bundle/chunks/github-copilot.js +1 -1
- package/dist/bundle/chunks/{google-generative-ai-XMFHGQC5.js → google-generative-ai-D2VJQBTK.js} +1 -1
- package/dist/bundle/chunks/{google-vertex-4XRRNP74.js → google-vertex-SQG2BO6C.js} +1 -1
- package/dist/bundle/chunks/https-proxy-agent-LVOO5TPL.js +13 -0
- package/dist/bundle/chunks/image-resize-worker.js +1 -1
- package/dist/bundle/chunks/{jiti-loader-C3NU2SDH.js → jiti-loader-GL4HJFAD.js} +1 -1
- package/dist/bundle/chunks/{jiti-static-loader-E6ANQD5T.js → jiti-static-loader-2RCDI6B4.js} +1 -1
- package/dist/bundle/chunks/{lib-TEDK3E5I.js → lib-4AVRLBHM.js} +1 -1
- package/dist/bundle/chunks/{llama-cpp-classify-XT44PI3C.js → llama-cpp-classify-5YHLY3RC.js} +2 -2
- package/dist/bundle/chunks/mistral-conversations-BDARVJTT.js +5 -0
- package/dist/bundle/chunks/{multipart-parser-SQ6GDJL7.js → multipart-parser-FMGQ7342.js} +1 -1
- package/dist/bundle/chunks/{node-TWVVAGPO.js → node-AUOGOBCN.js} +1 -1
- package/dist/bundle/chunks/{node-N5BSDOA5.js → node-KCMANYC2.js} +1 -1
- package/dist/bundle/chunks/openai-chatgpt.js +1 -1
- package/dist/bundle/chunks/openai-codex-responses-CECGTDYD.js +10 -0
- package/dist/bundle/chunks/openai-codex.js +1 -1
- package/dist/bundle/chunks/openai-completions-UOA7MELD.js +7 -0
- package/dist/bundle/chunks/openai-decisions-HLM372N6.js +5 -0
- package/dist/bundle/chunks/openai-responses-TII7ZY5X.js +3 -0
- package/dist/bundle/chunks/{openrouter-images-ZVXWCSIM.js → openrouter-images-7T452AS5.js} +1 -1
- package/dist/bundle/chunks/{pi-messages-TM5SOOIW.js → pi-messages-2UDKLKOO.js} +1 -1
- package/dist/bundle/chunks/runtime-IKE5OQIW.js +2 -0
- package/dist/bundle/chunks/{src-UK77SYZE.js → src-QKGKDFSU.js} +1 -1
- package/dist/bundle/chunks/typesafe-system-one-KNCICMO5.js +2 -0
- package/dist/bundle/chunks/virtual-modules-TJPHLTRT.js +2 -0
- package/dist/bundle/cli-runtime.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/core/export-html/template.js +21 -16
- package/dist/modes/interactive/theme/dark.json +1 -1
- package/dist/modes/interactive/theme/light.json +1 -1
- package/dist/modes/interactive/theme/theme-schema.d.ts +28 -0
- package/dist/modes/interactive/theme/theme-schema.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme-schema.js +105 -0
- package/dist/modes/interactive/theme/theme-schema.js.map +1 -0
- package/dist/modes/interactive/theme/theme-tokens.d.ts +257 -0
- package/dist/modes/interactive/theme/theme-tokens.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme-tokens.js +94 -0
- package/dist/modes/interactive/theme/theme-tokens.js.map +1 -0
- package/dist/modes/interactive/theme/theme.d.ts +13 -16
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +22 -29
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/docs/cli-integration.md +1 -1
- package/docs/cli.md +22 -10
- package/docs/codemode.md +29 -6
- package/docs/compaction.md +5 -5
- package/docs/custom-provider.md +53 -1
- package/docs/docs.json +8 -0
- package/docs/environment-variables.md +3 -1
- package/docs/extensions.md +122 -13
- package/docs/json.md +3 -3
- package/docs/keybindings.md +5 -4
- package/docs/llama-cpp.md +9 -2
- package/docs/mcp.md +4 -2
- package/docs/message-types.md +22 -4
- package/docs/models-configuration.md +187 -0
- package/docs/models.md +18 -2
- package/docs/nvidia-rtx-llama-cpp.md +96 -0
- package/docs/providers.md +47 -0
- package/docs/sessions.md +1 -1
- package/docs/settings.md +9 -6
- package/docs/terminal-setup.md +14 -0
- package/docs/themes.md +4 -2
- package/docs/tui.md +71 -1
- package/docs/usage.md +1 -1
- package/examples/README.md +0 -3
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/dynamic-resources/dynamic.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/minimal-mode.ts +4 -5
- package/examples/extensions/overlay-test.ts +2 -2
- package/examples/extensions/plan-mode/index.ts +6 -2
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/subagent/index.ts +4 -6
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/judge/dist/auth.js +91 -35
- package/judge/dist/chrome.js +2 -2
- package/judge/dist/import.js +852 -175
- package/judge/dist/setup.js +240 -153
- package/judge/manifest.json +2512 -546
- package/judge/mu/chunk-3NQ5BIBI.js +4773 -0
- package/judge/mu/chunk-SKGYWHW6.js +51 -0
- package/judge/mu/chunk-WQM4MV6L.js +58 -0
- package/judge/mu/cloud-code-V7FOGB4J.js +22802 -0
- package/judge/mu/dist-75PS4OC4.js +1283 -0
- package/judge/{dist/kyrn-judge.js → mu/index.js} +5365 -32809
- package/judge/mu/multipart-parser-ZDXVIOOP.js +372 -0
- package/judge/mu/src-TVVA5ZK2.js +1409 -0
- package/judge/themes/mu-dark.json +80 -0
- package/judge/themes/mu-light.json +80 -0
- package/kyrn/bin/kyrn-doctor +44 -19
- package/kyrn/bin/kyrn-judge-local +43 -14
- package/kyrn/bin/kyrn-ledger +16 -1
- package/kyrn/bin/mu.mjs +142 -61
- package/kyrn/local-judge/server.py +26 -14
- package/package.json +8 -6
- package/dist/bundle/chunks/anthropic-messages-MI4QHRXW.js +0 -6
- package/dist/bundle/chunks/azure-openai-responses-E3QGN4VN.js +0 -2
- package/dist/bundle/chunks/chunk-33KL6IIQ.js +0 -20
- package/dist/bundle/chunks/chunk-A3JYRWB6.js +0 -2
- package/dist/bundle/chunks/chunk-C47CLQZK.js +0 -2
- package/dist/bundle/chunks/chunk-HQHD6PZI.js +0 -2
- package/dist/bundle/chunks/chunk-KJUDFE6Y.js +0 -11
- package/dist/bundle/chunks/chunk-TE3GUV6H.js +0 -9
- package/dist/bundle/chunks/chunk-VIV3CWXG.js +0 -2
- package/dist/bundle/chunks/chunk-WE4MXUQS.js +0 -11
- package/dist/bundle/chunks/chunk-Y2PP32XV.js +0 -2
- package/dist/bundle/chunks/chunk-YLY6CKPK.js +0 -132
- package/dist/bundle/chunks/chunk-ZE5FMF3V.js +0 -99
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-NM3JRRWQ.js +0 -2
- package/dist/bundle/chunks/easter-egg-3d-G2LUBEMZ.js +0 -2
- package/dist/bundle/chunks/execute-MZVUC6BB.js +0 -388
- package/dist/bundle/chunks/https-proxy-agent-2VXB7436.js +0 -13
- package/dist/bundle/chunks/mistral-conversations-Q22M3IBG.js +0 -5
- package/dist/bundle/chunks/openai-codex-responses-4MYQSO5E.js +0 -10
- package/dist/bundle/chunks/openai-completions-OSRCWAAA.js +0 -7
- package/dist/bundle/chunks/openai-responses-UHF3DHNG.js +0 -3
- package/dist/bundle/chunks/runtime-VJMMDLVH.js +0 -2
- package/dist/bundle/chunks/typesafe-system-one-PRR5K6CI.js +0 -2
- package/dist/bundle/chunks/virtual-modules-RJXJGCPI.js +0 -2
- package/dist/modes/interactive/theme/theme-json.d.ts +0 -85
- package/dist/modes/interactive/theme/theme-json.d.ts.map +0 -1
- package/dist/modes/interactive/theme/theme-json.js +0 -132
- package/dist/modes/interactive/theme/theme-json.js.map +0 -1
- package/dist/modes/interactive/theme/theme-schema.json +0 -361
- package/examples/plugins/pi-example-plugin/README.md +0 -38
- package/examples/plugins/pi-example-plugin/package.json +0 -10
- package/examples/plugins/pi-example-plugin/src/contract.ts +0 -13
- package/examples/plugins/pi-example-plugin/src/session.ts +0 -24
- package/examples/plugins/pi-example-plugin/src/tui.ts +0 -31
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.js","sourceRoot":"","sources":["../../../../src/modes/interactive/theme/theme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EACN,cAAc,EAEd,UAAU,EACV,YAAY,EAEZ,cAAc,EACd,oBAAoB,EACpB,YAAY,EAEZ,SAAS,EACT,UAAU,EAEV,QAAQ,EAGR,iBAAiB,GAIjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEtE,OAAO,EAAE,YA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,EAAE,IAAI,CAAC;QACpD,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC;QAChC,IAAI,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC;KAC7C,CAAC;AACH,CAAC","sourcesContent":["import * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport {\n\tbackgroundAnsi,\n\ttype Color,\n\tcolorToHex,\n\tcolorToOklch,\n\ttype EditorTheme,\n\tforegroundAnsi,\n\tgetTerminalColorMode,\n\tindexedColor,\n\ttype MarkdownTheme,\n\tmixColors,\n\tparseColor,\n\ttype RgbColor,\n\trgbColor,\n\ttype SelectListTheme,\n\ttype SettingsListTheme,\n\tstyleTextWithAnsi,\n\ttype TerminalColorMode,\n\ttype TerminalColors,\n\ttype TextAttributes,\n} from \"@earendil-works/pi-tui\";\nimport chalk from \"chalk\";\nimport { getCustomThemesDir, getThemesDir } from \"../../../config.ts\";\nimport type { SourceInfo } from \"../../../core/source-info.ts\";\nimport { closeWatcher, watchWithErrorHandler } from \"../../../utils/fs-watch.ts\";\nimport { highlight, supportsLanguage } from \"../../../utils/syntax-highlight.ts\";\nimport { stripBom } from \"../../../utils/text.ts\";\nimport { generateSystemThemeColors, SYSTEM_THEME_NAME, terminalAppearance } from \"./system-theme.ts\";\n\nexport { SYSTEM_THEME_NAME } from \"./system-theme.ts\";\n\n// ============================================================================\n// Types & Schema\n// ============================================================================\n\n/** The schema that validates this shape lives in `theme-json.ts`; importing the type is free. */\nimport type { ThemeColorValue as ColorValue, ValidatedThemeJson as ThemeJson } from \"./theme-json.ts\";\n\nexport type { ValidatedThemeJson as ThemeJson } from \"./theme-json.ts\";\n\nexport type ThemeJsonValidator = (label: string, json: unknown) => ThemeJson;\n\nlet themeJsonValidator: ThemeJsonValidator | undefined;\n\n/**\n * Install full theme validation. Without it, documents are accepted as-is, which is what built-in\n * themes already do: validating user-authored JSON needs typebox, and a presentation that only uses\n * built-in themes should not pay ~17 MB of module graph for it.\n */\nexport function setThemeJsonValidator(validator: ThemeJsonValidator): void {\n\tthemeJsonValidator = validator;\n}\n\nexport type ThemeColor =\n\t| \"accent\"\n\t| \"border\"\n\t| \"borderAccent\"\n\t| \"borderMuted\"\n\t| \"success\"\n\t| \"error\"\n\t| \"warning\"\n\t| \"muted\"\n\t| \"dim\"\n\t| \"text\"\n\t| \"thinkingText\"\n\t| \"scrollbarTrack\"\n\t| \"scrollbarThumb\"\n\t| \"searchMatchText\"\n\t| \"userMessageText\"\n\t| \"customMessageText\"\n\t| \"customMessageLabel\"\n\t| \"toolTitle\"\n\t| \"toolOutput\"\n\t| \"mdHeading\"\n\t| \"mdLink\"\n\t| \"mdLinkUrl\"\n\t| \"mdCode\"\n\t| \"mdCodeBlock\"\n\t| \"mdCodeBlockBorder\"\n\t| \"mdQuote\"\n\t| \"mdQuoteBorder\"\n\t| \"mdHr\"\n\t| \"mdListBullet\"\n\t| \"toolDiffAdded\"\n\t| \"toolDiffRemoved\"\n\t| \"toolDiffContext\"\n\t| \"syntaxComment\"\n\t| \"syntaxKeyword\"\n\t| \"syntaxFunction\"\n\t| \"syntaxVariable\"\n\t| \"syntaxString\"\n\t| \"syntaxNumber\"\n\t| \"syntaxType\"\n\t| \"syntaxOperator\"\n\t| \"syntaxPunctuation\"\n\t| \"thinkingOff\"\n\t| \"thinkingMinimal\"\n\t| \"thinkingLow\"\n\t| \"thinkingMedium\"\n\t| \"thinkingHigh\"\n\t| \"thinkingXhigh\"\n\t| \"thinkingMax\"\n\t| \"bashMode\";\n\nexport type ThemeBg =\n\t| \"selectedBg\"\n\t| \"searchMatchBg\"\n\t| \"userMessageBg\"\n\t| \"customMessageBg\"\n\t| \"toolPendingBg\"\n\t| \"toolSuccessBg\"\n\t| \"toolErrorBg\";\n\nexport type ThemeToken = ThemeColor | ThemeBg;\n\n/**\n * Tokens are only accepted in their own slot, because \"\" (terminal default) means the default foreground\n * or background depending on the slot. Use `theme.colors[token]` to use a token's color in the other slot.\n */\nexport interface ThemeStyle extends TextAttributes {\n\tfg?: ThemeColor | Color;\n\tbg?: ThemeBg | Color;\n}\n\ntype OptionalThemeColor = \"scrollbarTrack\" | \"scrollbarThumb\" | \"thinkingMax\" | \"searchMatchText\";\ntype OptionalThemeBg = \"searchMatchBg\";\n\n// ============================================================================\n// Color Utilities\n// ============================================================================\n\nfunction resolveVarRefs(\n\tvalue: ColorValue,\n\tvars: Record<string, ColorValue>,\n\tvisited = new Set<string>(),\n): string | number {\n\tif (typeof value === \"number\" || value === \"\" || value.startsWith(\"#\") || /^ok(lch|hsl)\\(/i.test(value)) {\n\t\treturn value;\n\t}\n\tif (visited.has(value)) {\n\t\tthrow new Error(`Circular variable reference detected: ${value}`);\n\t}\n\tif (!(value in vars)) {\n\t\tthrow new Error(`Variable reference not found: ${value}`);\n\t}\n\tvisited.add(value);\n\treturn resolveVarRefs(vars[value], vars, visited);\n}\n\nfunction resolveThemeColors<T extends Record<string, ColorValue>>(\n\tcolors: T,\n\tvars: Record<string, ColorValue> = {},\n): Record<keyof T, string | number> {\n\tconst resolved: Record<string, string | number> = {};\n\tfor (const [key, value] of Object.entries(colors)) {\n\t\tresolved[key] = resolveVarRefs(value, vars);\n\t}\n\treturn resolved as Record<keyof T, string | number>;\n}\n\nfunction withThemeColorFallbacks(colors: ThemeJson[\"colors\"]): ThemeJson[\"colors\"] & {\n\tscrollbarTrack: ColorValue;\n\tscrollbarThumb: ColorValue;\n\tthinkingMax: ColorValue;\n\tsearchMatchBg: ColorValue;\n\tsearchMatchText: ColorValue;\n} {\n\treturn {\n\t\t...colors,\n\t\tscrollbarTrack: colors.scrollbarTrack ?? colors.muted,\n\t\tscrollbarThumb: colors.scrollbarThumb ?? colors.text,\n\t\tthinkingMax: colors.thinkingMax ?? colors.thinkingXhigh,\n\t\tsearchMatchBg: colors.searchMatchBg ?? colors.selectedBg,\n\t\tsearchMatchText: colors.searchMatchText ?? colors.text,\n\t};\n}\n\n// ============================================================================\n// Appearance & Terminal Default Colors\n// ============================================================================\n\n/** The background a theme is designed for. */\nexport type ThemeAppearance = TerminalTheme;\n\n// The terminal's reported colors. Replaced (never mutated) on update, so themes can cache resolved colors\n// by identity.\nlet terminalColors: TerminalColors = {};\n// While the terminal color query is in flight, the system theme renders in grayscale.\nlet terminalColorsPending = false;\n// The terminal's last light/dark report (mode 2031). Only used while it has not reported a background.\nlet terminalColorScheme: TerminalTheme | undefined;\n\n/**\n * Record the terminal's reported colors. Themes use the default colors for tokens set to \"\" (terminal\n * default); the system theme is generated from all of them. Ends the pending state.\n */\nexport function setTerminalColors(colors: TerminalColors): void {\n\tterminalColors = { ...colors };\n\tterminalColorsPending = false;\n}\n\n/** Record the terminal's light/dark report, the fallback for terminals that do not report their background. */\nexport function setTerminalColorScheme(scheme: TerminalTheme | undefined): void {\n\tterminalColorScheme = scheme;\n}\n\n/** Render the system theme in grayscale until `setTerminalColors()` reports the terminal's colors. */\nexport function markTerminalColorsPending(): void {\n\tterminalColorsPending = true;\n}\n\n/** Assumed terminal default colors when the terminal does not report them. */\nconst GUESSED_DEFAULT_COLORS: Record<ThemeAppearance, { foreground: Color; background: Color }> = {\n\tdark: { foreground: parseColor(\"#e5e5e7\"), background: parseColor(\"#000000\") },\n\tlight: { foreground: parseColor(\"#000000\"), background: parseColor(\"#ffffff\") },\n};\n\nfunction averageLightness(colors: Color[]): number | undefined {\n\t// Palette colors 0-15 follow the user's terminal palette, so they say nothing about the theme.\n\tconst fixed = colors.filter((color) => color.kind !== \"indexed\" || color.index >= 16);\n\tif (fixed.length === 0) return undefined;\n\treturn fixed.reduce((sum, color) => sum + colorToOklch(color).l, 0) / fixed.length;\n}\n\n/** Detect the background a theme is designed for from the lightness of its own colors. */\nfunction detectAppearance(foregrounds: Color[], backgrounds: Color[]): ThemeAppearance | undefined {\n\tconst fg = averageLightness(foregrounds);\n\tconst bg = averageLightness(backgrounds);\n\tif (fg !== undefined && bg !== undefined) return bg < fg ? \"dark\" : \"light\";\n\tif (bg !== undefined) return bg < 0.5 ? \"dark\" : \"light\";\n\tif (fg !== undefined) return fg > 0.5 ? \"dark\" : \"light\";\n\treturn undefined;\n}\n\n// ============================================================================\n// Theme Class\n// ============================================================================\n\nexport class Theme {\n\treadonly name?: string;\n\treadonly sourcePath?: string;\n\tsourceInfo?: SourceInfo;\n\tprivate mode: TerminalColorMode;\n\t// Precomputed escape sequences keep fg()/bg() on the render hot path to a lookup and concat.\n\tprivate readonly fgAnsi = new Map<ThemeColor, string>();\n\tprivate readonly bgAnsi = new Map<ThemeBg, string>();\n\t// Tokens set to \"\" have no color of their own; `colors` fills them from the terminal defaults.\n\tprivate readonly concreteColors: Partial<Record<ThemeToken, Color>> = {};\n\tprivate readonly defaultForegroundTokens: ThemeToken[] = [];\n\tprivate readonly defaultBackgroundTokens: ThemeToken[] = [];\n\t// Foreground tokens rendered faint (SGR 2) on top of their color.\n\tprivate readonly dimTokens: ReadonlySet<ThemeColor>;\n\tprivate readonly ownAppearance: ThemeAppearance | undefined;\n\tprivate resolvedColors: { terminal: TerminalColors; colors: Readonly<Record<ThemeToken, Color>> } | undefined;\n\n\tconstructor(\n\t\tfgColors: Record<Exclude<ThemeColor, OptionalThemeColor>, string | number> &\n\t\t\tPartial<Record<OptionalThemeColor, string | number>>,\n\t\tbgColors: Record<Exclude<ThemeBg, OptionalThemeBg>, string | number> &\n\t\t\tPartial<Record<OptionalThemeBg, string | number>>,\n\t\tmode: TerminalColorMode,\n\t\toptions: {\n\t\t\tname?: string;\n\t\t\tsourcePath?: string;\n\t\t\tsourceInfo?: SourceInfo;\n\t\t\tappearance?: ThemeAppearance;\n\t\t\t/** Foreground tokens to render faint (SGR 2). */\n\t\t\tdim?: readonly ThemeColor[];\n\t\t} = {},\n\t) {\n\t\tthis.name = options.name;\n\t\tthis.sourcePath = options.sourcePath;\n\t\tthis.sourceInfo = options.sourceInfo;\n\t\tthis.mode = mode;\n\t\tthis.dimTokens = new Set(options.dim);\n\t\tconst foregrounds = {\n\t\t\t...fgColors,\n\t\t\tscrollbarTrack: fgColors.scrollbarTrack ?? fgColors.muted,\n\t\t\tscrollbarThumb: fgColors.scrollbarThumb ?? fgColors.text,\n\t\t\tthinkingMax: fgColors.thinkingMax ?? fgColors.thinkingXhigh,\n\t\t\tsearchMatchText: fgColors.searchMatchText ?? fgColors.text,\n\t\t};\n\t\tconst backgrounds = { ...bgColors, searchMatchBg: bgColors.searchMatchBg ?? bgColors.selectedBg };\n\t\tconst concreteForegrounds: Color[] = [];\n\t\tconst concreteBackgrounds: Color[] = [];\n\t\t// Returns the escape sequence for the token's own slot.\n\t\tconst addToken = (token: ThemeToken, value: string | number, isBackground: boolean): string => {\n\t\t\tif (value === \"\") {\n\t\t\t\t(isBackground ? this.defaultBackgroundTokens : this.defaultForegroundTokens).push(token);\n\t\t\t\treturn isBackground ? \"\\x1b[49m\" : \"\\x1b[39m\";\n\t\t\t}\n\t\t\tconst color = parseColor(value);\n\t\t\tthis.concreteColors[token] = color;\n\t\t\t(isBackground ? concreteBackgrounds : concreteForegrounds).push(color);\n\t\t\treturn isBackground ? backgroundAnsi(color, mode) : foregroundAnsi(color, mode);\n\t\t};\n\t\tfor (const [token, value] of Object.entries(foregrounds) as [ThemeColor, string | number][]) {\n\t\t\tthis.fgAnsi.set(token, addToken(token, value, false));\n\t\t}\n\t\tfor (const [token, value] of Object.entries(backgrounds) as [ThemeBg, string | number][]) {\n\t\t\tthis.bgAnsi.set(token, addToken(token, value, true));\n\t\t}\n\t\tthis.ownAppearance = options.appearance ?? detectAppearance(concreteForegrounds, concreteBackgrounds);\n\t}\n\n\t/**\n\t * The background the theme is designed for: declared in the theme JSON, detected from its colors,\n\t * or, for themes without usable colors, the terminal's appearance.\n\t */\n\tget appearance(): ThemeAppearance {\n\t\treturn this.ownAppearance ?? getTerminalTheme();\n\t}\n\n\t/**\n\t * Concrete colors for all tokens. Tokens set to \"\" (terminal default) use the terminal's reported\n\t * default colors, or a guess based on `appearance` when the terminal did not report them. Faint\n\t * tokens are approximated by mixing their color toward the background.\n\t */\n\tget colors(): Readonly<Record<ThemeToken, Color>> {\n\t\tconst terminal = terminalColors;\n\t\tif (this.resolvedColors?.terminal !== terminal) {\n\t\t\tconst guess = GUESSED_DEFAULT_COLORS[this.appearance];\n\t\t\tconst toColor = (rgb: RgbColor | undefined, fallback: Color) =>\n\t\t\t\trgb ? rgbColor(rgb.r, rgb.g, rgb.b) : fallback;\n\t\t\tconst foreground = toColor(terminal.foreground, guess.foreground);\n\t\t\tconst background = toColor(terminal.background, guess.background);\n\t\t\tconst colors = { ...this.concreteColors };\n\t\t\tfor (const token of this.defaultForegroundTokens) colors[token] = foreground;\n\t\t\tfor (const token of this.defaultBackgroundTokens) colors[token] = background;\n\t\t\tfor (const token of this.dimTokens) {\n\t\t\t\tconst color = colors[token];\n\t\t\t\tif (color) colors[token] = mixColors(color, background, 0.4);\n\t\t\t}\n\t\t\tthis.resolvedColors = { terminal, colors: Object.freeze(colors as Record<ThemeToken, Color>) };\n\t\t}\n\t\treturn this.resolvedColors.colors;\n\t}\n\n\tstyle(text: string, options: ThemeStyle): string {\n\t\tconst { fg, bg } = options;\n\t\tif (typeof fg === \"string\" && this.dimTokens.has(fg)) options = { ...options, dim: true };\n\t\treturn styleTextWithAnsi(\n\t\t\ttext,\n\t\t\tfg === undefined\n\t\t\t\t? undefined\n\t\t\t\t: typeof fg === \"string\"\n\t\t\t\t\t? this.tokenAnsi(this.fgAnsi, fg)\n\t\t\t\t\t: foregroundAnsi(fg, this.mode),\n\t\t\tbg === undefined\n\t\t\t\t? undefined\n\t\t\t\t: typeof bg === \"string\"\n\t\t\t\t\t? this.tokenAnsi(this.bgAnsi, bg)\n\t\t\t\t\t: backgroundAnsi(bg, this.mode),\n\t\t\toptions,\n\t\t);\n\t}\n\n\tfg(color: ThemeColor, text: string): string {\n\t\tconst ansi = this.tokenAnsi(this.fgAnsi, color);\n\t\tif (this.dimTokens.has(color)) return `${ansi}\\x1b[2m${text}\\x1b[22;39m`;\n\t\treturn `${ansi}${text}\\x1b[39m`;\n\t}\n\n\tbg(color: ThemeBg, text: string): string {\n\t\tconst ansi = this.tokenAnsi(this.bgAnsi, color);\n\t\treturn `${ansi}${text}\\x1b[49m`;\n\t}\n\n\tprivate tokenAnsi<T extends ThemeToken>(ansi: Map<T, string>, token: T): string {\n\t\tconst value = ansi.get(token);\n\t\tif (value === undefined) throw new Error(`Unknown theme color: ${token}`);\n\t\treturn value;\n\t}\n\n\tbold(text: string): string {\n\t\treturn chalk.bold(text);\n\t}\n\n\titalic(text: string): string {\n\t\treturn chalk.italic(text);\n\t}\n\n\tunderline(text: string): string {\n\t\treturn chalk.underline(text);\n\t}\n\n\tinverse(text: string): string {\n\t\treturn chalk.inverse(text);\n\t}\n\n\tstrikethrough(text: string): string {\n\t\treturn chalk.strikethrough(text);\n\t}\n\n\t/** Opening escape sequence for a foreground token. Faint tokens include SGR 2, which `\\x1b[22m` closes. */\n\tgetFgAnsi(color: ThemeColor): string {\n\t\tconst ansi = this.tokenAnsi(this.fgAnsi, color);\n\t\treturn this.dimTokens.has(color) ? `${ansi}\\x1b[2m` : ansi;\n\t}\n\n\tgetBgAnsi(color: ThemeBg): string {\n\t\treturn this.tokenAnsi(this.bgAnsi, color);\n\t}\n\n\tgetColorMode(): TerminalColorMode {\n\t\treturn this.mode;\n\t}\n\n\tgetThinkingBorderColor(level: ThinkingLevel): (str: string) => string {\n\t\t// Map thinking levels to dedicated theme colors\n\t\tswitch (level) {\n\t\t\tcase \"off\":\n\t\t\t\treturn (str: string) => this.fg(\"thinkingOff\", str);\n\t\t\tcase \"minimal\":\n\t\t\t\treturn (str: string) => this.fg(\"thinkingMinimal\", str);\n\t\t\tcase \"low\":\n\t\t\t\treturn (str: string) => this.fg(\"thinkingLow\", str);\n\t\t\tcase \"medium\":\n\t\t\t\treturn (str: string) => this.fg(\"thinkingMedium\", str);\n\t\t\tcase \"high\":\n\t\t\t\treturn (str: string) => this.fg(\"thinkingHigh\", str);\n\t\t\tcase \"xhigh\":\n\t\t\t\treturn (str: string) => this.fg(\"thinkingXhigh\", str);\n\t\t\tcase \"max\":\n\t\t\t\treturn (str: string) => this.fg(\"thinkingMax\", str);\n\t\t\tdefault:\n\t\t\t\treturn (str: string) => this.fg(\"thinkingOff\", str);\n\t\t}\n\t}\n\n\tgetBashModeBorderColor(): (str: string) => string {\n\t\treturn (str: string) => this.fg(\"bashMode\", str);\n\t}\n}\n\n// ============================================================================\n// Theme Loading\n// ============================================================================\n\nlet BUILTIN_THEMES: Record<string, ThemeJson> | undefined;\n\nfunction getBuiltinThemes(): Record<string, ThemeJson> {\n\tif (!BUILTIN_THEMES) {\n\t\tconst themesDir = getThemesDir();\n\t\tconst darkPath = path.join(themesDir, \"dark.json\");\n\t\tconst lightPath = path.join(themesDir, \"light.json\");\n\t\tBUILTIN_THEMES = {\n\t\t\tdark: JSON.parse(stripBom(fs.readFileSync(darkPath, \"utf-8\"))) as ThemeJson,\n\t\t\tlight: JSON.parse(stripBom(fs.readFileSync(lightPath, \"utf-8\"))) as ThemeJson,\n\t\t};\n\t}\n\treturn BUILTIN_THEMES;\n}\n\nexport function getAvailableThemes(): string[] {\n\treturn getAvailableThemesWithPaths().map(({ name }) => name);\n}\n\nexport interface ThemeInfo {\n\tname: string;\n\tpath: string | undefined;\n}\n\nexport function getAvailableThemesWithPaths(): ThemeInfo[] {\n\tconst themesDir = getThemesDir();\n\tconst result: ThemeInfo[] = [];\n\tconst seen = new Set<string>();\n\tconst addTheme = (themeInfo: ThemeInfo) => {\n\t\tif (seen.has(themeInfo.name)) {\n\t\t\treturn;\n\t\t}\n\t\tseen.add(themeInfo.name);\n\t\tresult.push(themeInfo);\n\t};\n\n\t// Built-in themes. The system theme is generated, so it has no file.\n\taddTheme({ name: SYSTEM_THEME_NAME, path: undefined });\n\tfor (const name of Object.keys(getBuiltinThemes())) {\n\t\taddTheme({ name, path: path.join(themesDir, `${name}.json`) });\n\t}\n\n\t// Custom themes\n\tfor (const themeInfo of getCustomThemeInfos()) {\n\t\taddTheme(themeInfo);\n\t}\n\n\tfor (const [name, theme] of registeredThemes.entries()) {\n\t\taddTheme({ name, path: theme.sourcePath });\n\t}\n\n\t// The system theme comes first: it is the default and adapts to every terminal.\n\treturn result.sort((a, b) =>\n\t\ta.name === SYSTEM_THEME_NAME ? -1 : b.name === SYSTEM_THEME_NAME ? 1 : a.name.localeCompare(b.name),\n\t);\n}\n\nfunction getCustomThemeInfos(): ThemeInfo[] {\n\tconst customThemesDir = getCustomThemesDir();\n\tconst result: ThemeInfo[] = [];\n\tif (!fs.existsSync(customThemesDir)) {\n\t\treturn result;\n\t}\n\n\tfor (const file of fs.readdirSync(customThemesDir)) {\n\t\tif (!file.endsWith(\".json\")) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst themePath = path.join(customThemesDir, file);\n\t\ttry {\n\t\t\tconst customTheme = loadThemeFromPath(themePath);\n\t\t\tif (customTheme.name) {\n\t\t\t\tresult.push({ name: customTheme.name, path: themePath });\n\t\t\t}\n\t\t} catch {\n\t\t\t// Invalid themes are ignored here; the resource loader reports them\n\t\t\t// during normal startup/reload.\n\t\t}\n\t}\n\treturn result;\n}\n\nfunction assertThemeNameIsValid(name: string): void {\n\tif (name.includes(\"/\")) {\n\t\tthrow new Error(\n\t\t\t`Invalid theme name \"${name}\": theme names cannot contain \"/\" because it is reserved for automatic light/dark theme settings.`,\n\t\t);\n\t}\n}\n\nfunction parseThemeJson(label: string, json: unknown): ThemeJson {\n\tif (themeJsonValidator) return themeJsonValidator(label, json);\n\tif (typeof json !== \"object\" || json === null || !(\"colors\" in json)) {\n\t\tthrow new Error(`Invalid theme \"${label}\": expected an object with a \"colors\" map.`);\n\t}\n\treturn json as ThemeJson;\n}\n\nfunction parseThemeJsonContent(label: string, content: string): ThemeJson {\n\tlet json: unknown;\n\ttry {\n\t\tjson = JSON.parse(stripBom(content));\n\t} catch (error) {\n\t\tthrow new Error(`Failed to parse theme ${label}: ${error}`);\n\t}\n\treturn parseThemeJson(label, json);\n}\n\nfunction loadThemeJson(name: string): ThemeJson {\n\tconst builtinThemes = getBuiltinThemes();\n\tif (name in builtinThemes) {\n\t\treturn builtinThemes[name];\n\t}\n\tconst registeredTheme = registeredThemes.get(name);\n\tif (registeredTheme?.sourcePath) {\n\t\tconst content = fs.readFileSync(registeredTheme.sourcePath, \"utf-8\");\n\t\treturn parseThemeJsonContent(registeredTheme.sourcePath, content);\n\t}\n\tif (registeredTheme) {\n\t\tthrow new Error(`Theme \"${name}\" does not have a source path for export`);\n\t}\n\tconst customThemesDir = getCustomThemesDir();\n\tconst themePath = path.join(customThemesDir, `${name}.json`);\n\tif (!fs.existsSync(themePath)) {\n\t\tthrow new Error(`Theme not found: ${name}`);\n\t}\n\tconst content = fs.readFileSync(themePath, \"utf-8\");\n\treturn parseThemeJsonContent(name, content);\n}\n\nconst BACKGROUND_TOKENS: ReadonlySet<string> = new Set<ThemeBg>([\n\t\"selectedBg\",\n\t\"searchMatchBg\",\n\t\"userMessageBg\",\n\t\"customMessageBg\",\n\t\"toolPendingBg\",\n\t\"toolSuccessBg\",\n\t\"toolErrorBg\",\n]);\n\nfunction splitThemeColors(colors: Record<string, string | number>): {\n\tfgColors: Record<ThemeColor, string | number>;\n\tbgColors: Record<ThemeBg, string | number>;\n} {\n\tconst fgColors = {} as Record<ThemeColor, string | number>;\n\tconst bgColors = {} as Record<ThemeBg, string | number>;\n\tfor (const [key, value] of Object.entries(colors)) {\n\t\tif (BACKGROUND_TOKENS.has(key)) {\n\t\t\tbgColors[key as ThemeBg] = value;\n\t\t} else {\n\t\t\tfgColors[key as ThemeColor] = value;\n\t\t}\n\t}\n\treturn { fgColors, bgColors };\n}\n\nfunction createTheme(themeJson: ThemeJson, mode?: TerminalColorMode, sourcePath?: string): Theme {\n\tconst colorMode = mode ?? getTerminalColorMode();\n\tconst resolvedColors = resolveThemeColors(withThemeColorFallbacks(themeJson.colors), themeJson.vars);\n\tconst { fgColors, bgColors } = splitThemeColors(resolvedColors);\n\treturn new Theme(fgColors, bgColors, colorMode, {\n\t\tname: themeJson.name,\n\t\tsourcePath,\n\t\tappearance: themeJson.appearance,\n\t});\n}\n\n/** Generate the system theme from the terminal's reported colors (grayscale while they are pending). */\nfunction createSystemTheme(mode?: TerminalColorMode): Theme {\n\tconst generated = generateSystemThemeColors({\n\t\t...terminalColors,\n\t\tsaturation: terminalColorsPending ? 0 : 1,\n\t\tappearanceHint: getTerminalTheme(),\n\t});\n\tconst { fgColors, bgColors } = splitThemeColors(generated.colors);\n\treturn new Theme(fgColors, bgColors, mode ?? getTerminalColorMode(), {\n\t\tname: SYSTEM_THEME_NAME,\n\t\tappearance: generated.appearance,\n\t\tdim: generated.dim,\n\t});\n}\n\nexport function loadThemeFromPath(themePath: string, mode?: TerminalColorMode): Theme {\n\tconst content = fs.readFileSync(themePath, \"utf-8\");\n\tconst themeJson = parseThemeJsonContent(themePath, content);\n\treturn createTheme(themeJson, mode, themePath);\n}\n\nfunction loadTheme(name: string, mode?: TerminalColorMode): Theme {\n\t// The system theme name is reserved: it takes precedence over custom themes of the same name.\n\tif (name === SYSTEM_THEME_NAME) return createSystemTheme(mode);\n\tconst registeredTheme = registeredThemes.get(name);\n\tif (registeredTheme) {\n\t\treturn registeredTheme;\n\t}\n\tconst themeJson = loadThemeJson(name);\n\treturn createTheme(themeJson, mode);\n}\n\nexport function getThemeByName(name: string): Theme | undefined {\n\ttry {\n\t\treturn loadTheme(name);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nexport type TerminalTheme = \"dark\" | \"light\";\n\nexport function parseAutoThemeSetting(\n\tthemeSetting: string | undefined,\n): { lightTheme: string; darkTheme: string } | undefined {\n\tif (!themeSetting) return undefined;\n\tconst slashIndex = themeSetting.indexOf(\"/\");\n\tif (slashIndex === -1 || themeSetting.indexOf(\"/\", slashIndex + 1) !== -1) {\n\t\treturn undefined;\n\t}\n\n\tconst lightTheme = themeSetting.slice(0, slashIndex).trim();\n\tconst darkTheme = themeSetting.slice(slashIndex + 1).trim();\n\tif (!lightTheme || !darkTheme) {\n\t\treturn undefined;\n\t}\n\treturn { lightTheme, darkTheme };\n}\n\nexport function resolveThemeSetting(\n\tthemeSetting: string | undefined,\n\tterminalTheme: TerminalTheme,\n): string | undefined {\n\tconst autoTheme = parseAutoThemeSetting(themeSetting);\n\tif (autoTheme) {\n\t\treturn terminalTheme === \"light\" ? autoTheme.lightTheme : autoTheme.darkTheme;\n\t}\n\tif (themeSetting?.includes(\"/\")) return undefined;\n\tif (typeof themeSetting === \"string\") return themeSetting;\n\treturn undefined;\n}\n\n/**\n * Dark or light from the `COLORFGBG` environment variable some terminals set, or undefined without a\n * usable background index. The value is `fg;bg` or `fg;xpm;bg` (rxvt), where a field is an ANSI color\n * index or `default` when the color is not in the palette. The index refers to the terminal's own palette,\n * whose colors are unknown here, so it is classified by index like Vim does: 0-6 and 8 (bright black, e.g.\n * Solarized Dark's background) are dark, 7 and 9-15 are light.\n */\nexport function detectColorFgBgTheme(env: NodeJS.ProcessEnv = process.env): TerminalTheme | undefined {\n\tconst bg = env.COLORFGBG?.split(\";\").at(-1)?.trim();\n\tif (!bg || !/^\\d{1,2}$/.test(bg)) return undefined;\n\tconst index = Number(bg);\n\tif (index > 15) return undefined;\n\treturn index <= 6 || index === 8 ? \"dark\" : \"light\";\n}\n\n/**\n * Whether the terminal is dark or light. The background it renders decides, classified the same way the\n * system theme does. Without a reported background: the terminal's light/dark report, then COLORFGBG,\n * then dark.\n */\nexport function detectTerminalTheme(\n\tcolors: TerminalColors = {},\n\treportedScheme?: TerminalTheme,\n\tenv: NodeJS.ProcessEnv = process.env,\n): TerminalTheme {\n\tconst { background, foreground } = colors;\n\tif (background) return terminalAppearance(background, foreground);\n\treturn reportedScheme ?? detectColorFgBgTheme(env) ?? \"dark\";\n}\n\n/** Whether the terminal is dark or light, from everything it reported so far. See `detectTerminalTheme()`. */\nexport function getTerminalTheme(): TerminalTheme {\n\treturn detectTerminalTheme(terminalColors, terminalColorScheme);\n}\n\n// ============================================================================\n// Global Theme Instance\n// ============================================================================\n\n// Use globalThis to share theme across module loaders (node + jiti in dev mode)\nconst THEME_KEY = Symbol.for(\"@earendil-works/pi-coding-agent:theme\");\nconst THEME_KEY_OLD = Symbol.for(\"@mariozechner/pi-coding-agent:theme\");\n\n// Export theme as a getter that reads from globalThis\n// This ensures all module instances (node, jiti) see the same theme\nexport const theme: Theme = new Proxy({} as Theme, {\n\tget(_target, prop) {\n\t\tconst t = (globalThis as Record<symbol, Theme>)[THEME_KEY];\n\t\tif (!t) throw new Error(\"Theme not initialized. Call initTheme() first.\");\n\t\treturn (t as unknown as Record<string | symbol, unknown>)[prop];\n\t},\n});\n\nfunction setGlobalTheme(t: Theme): void {\n\t(globalThis as Record<symbol, Theme>)[THEME_KEY] = t;\n\t(globalThis as Record<symbol, Theme>)[THEME_KEY_OLD] = t;\n}\n\nlet currentThemeName: string | undefined;\nlet themeWatcher: fs.FSWatcher | undefined;\nlet themeReloadTimer: NodeJS.Timeout | undefined;\nlet onThemeChangeCallback: (() => void) | undefined;\nconst registeredThemes = new Map<string, Theme>();\n\nexport function setRegisteredThemes(themes: Theme[]): void {\n\tregisteredThemes.clear();\n\tfor (const theme of themes) {\n\t\tif (theme.name) {\n\t\t\tassertThemeNameIsValid(theme.name);\n\t\t\tregisteredThemes.set(theme.name, theme);\n\t\t}\n\t}\n}\n\nexport function initTheme(themeName?: string, enableWatcher: boolean = false): void {\n\tconst name = themeName ?? SYSTEM_THEME_NAME;\n\tcurrentThemeName = name;\n\ttry {\n\t\tsetGlobalTheme(loadTheme(name));\n\t\tif (enableWatcher) {\n\t\t\tstartThemeWatcher();\n\t\t}\n\t} catch (_error) {\n\t\t// Theme is invalid - fall back to the system theme silently\n\t\tcurrentThemeName = SYSTEM_THEME_NAME;\n\t\tsetGlobalTheme(loadTheme(SYSTEM_THEME_NAME));\n\t\t// Don't start watcher for fallback theme\n\t}\n}\n\nexport function setTheme(name: string, enableWatcher: boolean = false): { success: boolean; error?: string } {\n\tcurrentThemeName = name;\n\ttry {\n\t\tsetGlobalTheme(loadTheme(name));\n\t\tif (enableWatcher) {\n\t\t\tstartThemeWatcher();\n\t\t}\n\t\tif (onThemeChangeCallback) {\n\t\t\tonThemeChangeCallback();\n\t\t}\n\t\treturn { success: true };\n\t} catch (error) {\n\t\t// Theme is invalid - fall back to the system theme\n\t\tcurrentThemeName = SYSTEM_THEME_NAME;\n\t\tsetGlobalTheme(loadTheme(SYSTEM_THEME_NAME));\n\t\t// Don't start watcher for fallback theme\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t};\n\t}\n}\n\nexport function setThemeInstance(themeInstance: Theme): void {\n\tsetGlobalTheme(themeInstance);\n\tcurrentThemeName = \"<in-memory>\";\n\tstopThemeWatcher(); // Can't watch a direct instance\n\tif (onThemeChangeCallback) {\n\t\tonThemeChangeCallback();\n\t}\n}\n\nexport function onThemeChange(callback: () => void): void {\n\tonThemeChangeCallback = callback;\n}\n\nfunction startThemeWatcher(): void {\n\tstopThemeWatcher();\n\n\t// Only watch if it's a custom theme (not built-in)\n\tif (\n\t\t!currentThemeName ||\n\t\tcurrentThemeName === \"dark\" ||\n\t\tcurrentThemeName === \"light\" ||\n\t\tcurrentThemeName === SYSTEM_THEME_NAME\n\t) {\n\t\treturn;\n\t}\n\n\tconst customThemesDir = getCustomThemesDir();\n\tconst watchedThemeName = currentThemeName;\n\tconst watchedFileName = `${watchedThemeName}.json`;\n\tconst themeFile = path.join(customThemesDir, watchedFileName);\n\n\t// Only watch if the file exists\n\tif (!fs.existsSync(themeFile)) {\n\t\treturn;\n\t}\n\n\tconst scheduleReload = () => {\n\t\tif (themeReloadTimer) {\n\t\t\tclearTimeout(themeReloadTimer);\n\t\t}\n\t\tthemeReloadTimer = setTimeout(() => {\n\t\t\tthemeReloadTimer = undefined;\n\n\t\t\t// Ignore stale timers after switching themes or stopping the watcher\n\t\t\tif (currentThemeName !== watchedThemeName) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Keep the last successfully loaded theme active if the file is temporarily missing\n\t\t\tif (!fs.existsSync(themeFile)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\t// Reload the theme from disk and refresh the registry cache\n\t\t\t\tconst reloadedTheme = loadThemeFromPath(themeFile);\n\t\t\t\tregisteredThemes.set(watchedThemeName, reloadedTheme);\n\t\t\t\tsetGlobalTheme(reloadedTheme);\n\t\t\t\t// Notify callback (to invalidate UI)\n\t\t\t\tif (onThemeChangeCallback) {\n\t\t\t\t\tonThemeChangeCallback();\n\t\t\t\t}\n\t\t\t} catch (_error) {\n\t\t\t\t// Ignore errors (file might be in invalid state while being edited)\n\t\t\t}\n\t\t}, 100);\n\t};\n\n\tthemeWatcher =\n\t\twatchWithErrorHandler(\n\t\t\tcustomThemesDir,\n\t\t\t(_eventType, filename) => {\n\t\t\t\tif (currentThemeName !== watchedThemeName) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (!filename) {\n\t\t\t\t\tscheduleReload();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (filename !== watchedFileName) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tscheduleReload();\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tcloseWatcher(themeWatcher);\n\t\t\t\tthemeWatcher = undefined;\n\t\t\t},\n\t\t) ?? undefined;\n}\n\nexport function stopThemeWatcher(): void {\n\tif (themeReloadTimer) {\n\t\tclearTimeout(themeReloadTimer);\n\t\tthemeReloadTimer = undefined;\n\t}\n\tcloseWatcher(themeWatcher);\n\tthemeWatcher = undefined;\n}\n\n// ============================================================================\n// HTML Export Helpers\n// ============================================================================\n\n/**\n * Get resolved theme colors as CSS-compatible hex strings.\n * Used by HTML export to generate CSS custom properties.\n */\nexport function getResolvedThemeColors(themeName?: string): Record<string, string> {\n\tconst colors = loadTheme(themeName ?? currentThemeName ?? SYSTEM_THEME_NAME).colors;\n\treturn Object.fromEntries(Object.entries(colors).map(([token, color]) => [token, colorToHex(color)]));\n}\n\n/**\n * Check if a theme is a \"light\" theme (for CSS that needs light/dark variants).\n */\nexport function isLightTheme(themeName?: string): boolean {\n\treturn loadTheme(themeName ?? currentThemeName ?? SYSTEM_THEME_NAME).appearance === \"light\";\n}\n\n/**\n * Get explicit export colors from theme JSON, if specified.\n * Returns undefined for each color that isn't explicitly set.\n */\nexport function getThemeExportColors(themeName?: string): {\n\tpageBg?: string;\n\tcardBg?: string;\n\tinfoBg?: string;\n} {\n\tconst name = themeName ?? currentThemeName ?? SYSTEM_THEME_NAME;\n\tif (name === SYSTEM_THEME_NAME) return {};\n\ttry {\n\t\tconst themeJson = loadThemeJson(name);\n\t\tconst exportSection = themeJson.export;\n\t\tif (!exportSection) return {};\n\n\t\tconst vars = themeJson.vars ?? {};\n\t\t// Export colors end up in CSS, which understands hex and oklch() values directly but not okhsl().\n\t\tconst resolve = (value: ColorValue | undefined): string | undefined => {\n\t\t\tif (value === undefined) return undefined;\n\t\t\tconst resolved = resolveVarRefs(value, vars);\n\t\t\tif (typeof resolved === \"number\") return colorToHex(indexedColor(resolved));\n\t\t\tif (resolved === \"\") return undefined;\n\t\t\tif (/^okhsl\\(/i.test(resolved)) return colorToHex(parseColor(resolved));\n\t\t\treturn resolved;\n\t\t};\n\n\t\treturn {\n\t\t\tpageBg: resolve(exportSection.pageBg),\n\t\t\tcardBg: resolve(exportSection.cardBg),\n\t\t\tinfoBg: resolve(exportSection.infoBg),\n\t\t};\n\t} catch {\n\t\treturn {};\n\t}\n}\n\n// ============================================================================\n// TUI Helpers\n// ============================================================================\n\ntype CliHighlightTheme = Record<string, (s: string) => string>;\n\nlet cachedHighlightThemeFor: Theme | undefined;\nlet cachedCliHighlightTheme: CliHighlightTheme | undefined;\n\nfunction buildCliHighlightTheme(t: Theme): CliHighlightTheme {\n\treturn {\n\t\tkeyword: (s: string) => t.fg(\"syntaxKeyword\", s),\n\t\tbuilt_in: (s: string) => t.fg(\"syntaxType\", s),\n\t\tliteral: (s: string) => t.fg(\"syntaxNumber\", s),\n\t\tnumber: (s: string) => t.fg(\"syntaxNumber\", s),\n\t\tregexp: (s: string) => t.fg(\"syntaxString\", s),\n\t\tstring: (s: string) => t.fg(\"syntaxString\", s),\n\t\tcomment: (s: string) => t.fg(\"syntaxComment\", s),\n\t\tdoctag: (s: string) => t.fg(\"syntaxComment\", s),\n\t\tmeta: (s: string) => t.fg(\"muted\", s),\n\t\tfunction: (s: string) => t.fg(\"syntaxFunction\", s),\n\t\ttitle: (s: string) => t.fg(\"syntaxFunction\", s),\n\t\tclass: (s: string) => t.fg(\"syntaxType\", s),\n\t\ttype: (s: string) => t.fg(\"syntaxType\", s),\n\t\ttag: (s: string) => t.fg(\"syntaxPunctuation\", s),\n\t\tname: (s: string) => t.fg(\"syntaxKeyword\", s),\n\t\tattr: (s: string) => t.fg(\"syntaxVariable\", s),\n\t\tvariable: (s: string) => t.fg(\"syntaxVariable\", s),\n\t\tparams: (s: string) => t.fg(\"syntaxVariable\", s),\n\t\toperator: (s: string) => t.fg(\"syntaxOperator\", s),\n\t\tpunctuation: (s: string) => t.fg(\"syntaxPunctuation\", s),\n\t\temphasis: (s: string) => t.italic(s),\n\t\tstrong: (s: string) => t.bold(s),\n\t\tlink: (s: string) => t.underline(s),\n\t\taddition: (s: string) => t.fg(\"toolDiffAdded\", s),\n\t\tdeletion: (s: string) => t.fg(\"toolDiffRemoved\", s),\n\t};\n}\n\nfunction getCliHighlightTheme(t: Theme): CliHighlightTheme {\n\tif (cachedHighlightThemeFor !== t || !cachedCliHighlightTheme) {\n\t\tcachedHighlightThemeFor = t;\n\t\tcachedCliHighlightTheme = buildCliHighlightTheme(t);\n\t}\n\treturn cachedCliHighlightTheme;\n}\n\n/**\n * Highlight code with syntax coloring based on file extension or language.\n * Returns array of highlighted lines.\n */\nexport function highlightCode(code: string, lang?: string): string[] {\n\t// Validate language before highlighting to avoid stderr spam from cli-highlight\n\tconst validLang = lang && supportsLanguage(lang) ? lang : undefined;\n\t// Skip highlighting when no valid language is specified. cli-highlight's\n\t// auto-detection is unreliable and can misidentify prose as AppleScript,\n\t// LiveCodeServer, etc., coloring random English words as keywords.\n\tif (!validLang) {\n\t\treturn code.split(\"\\n\").map((line) => theme.fg(\"mdCodeBlock\", line));\n\t}\n\tconst opts = {\n\t\tlanguage: validLang,\n\t\tignoreIllegals: true,\n\t\ttheme: getCliHighlightTheme(theme),\n\t};\n\ttry {\n\t\treturn highlight(code, opts).split(\"\\n\");\n\t} catch {\n\t\treturn code.split(\"\\n\");\n\t}\n}\n\n/**\n * Get language identifier from file path extension.\n */\nexport function getLanguageFromPath(filePath: string): string | undefined {\n\tconst ext = filePath.split(\".\").pop()?.toLowerCase();\n\tif (!ext) return undefined;\n\n\tconst extToLang: Record<string, string> = {\n\t\tts: \"typescript\",\n\t\ttsx: \"typescript\",\n\t\tjs: \"javascript\",\n\t\tjsx: \"javascript\",\n\t\tmjs: \"javascript\",\n\t\tcjs: \"javascript\",\n\t\tpy: \"python\",\n\t\trb: \"ruby\",\n\t\trs: \"rust\",\n\t\tgo: \"go\",\n\t\tjava: \"java\",\n\t\tkt: \"kotlin\",\n\t\tswift: \"swift\",\n\t\tc: \"c\",\n\t\th: \"c\",\n\t\tcpp: \"cpp\",\n\t\tcc: \"cpp\",\n\t\tcxx: \"cpp\",\n\t\thpp: \"cpp\",\n\t\tcs: \"csharp\",\n\t\tphp: \"php\",\n\t\tsh: \"bash\",\n\t\tbash: \"bash\",\n\t\tzsh: \"bash\",\n\t\tfish: \"fish\",\n\t\tps1: \"powershell\",\n\t\tsql: \"sql\",\n\t\thtml: \"html\",\n\t\thtm: \"html\",\n\t\tcss: \"css\",\n\t\tscss: \"scss\",\n\t\tsass: \"sass\",\n\t\tless: \"less\",\n\t\tjson: \"json\",\n\t\tyaml: \"yaml\",\n\t\tyml: \"yaml\",\n\t\ttoml: \"toml\",\n\t\txml: \"xml\",\n\t\tmd: \"markdown\",\n\t\tmarkdown: \"markdown\",\n\t\tdockerfile: \"dockerfile\",\n\t\tmakefile: \"makefile\",\n\t\tcmake: \"cmake\",\n\t\tlua: \"lua\",\n\t\tperl: \"perl\",\n\t\tr: \"r\",\n\t\tscala: \"scala\",\n\t\tclj: \"clojure\",\n\t\tex: \"elixir\",\n\t\texs: \"elixir\",\n\t\terl: \"erlang\",\n\t\ths: \"haskell\",\n\t\tml: \"ocaml\",\n\t\tvim: \"vim\",\n\t\tgraphql: \"graphql\",\n\t\tproto: \"protobuf\",\n\t\ttf: \"hcl\",\n\t\thcl: \"hcl\",\n\t};\n\n\treturn extToLang[ext];\n}\n\nexport function getMarkdownTheme(): MarkdownTheme {\n\treturn {\n\t\theading: (text: string) => theme.fg(\"mdHeading\", text),\n\t\tlink: (text: string) => theme.fg(\"mdLink\", text),\n\t\tlinkUrl: (text: string) => theme.fg(\"mdLinkUrl\", text),\n\t\tcode: (text: string) => theme.fg(\"mdCode\", text),\n\t\tcodeBlock: (text: string) => theme.fg(\"mdCodeBlock\", text),\n\t\tcodeBlockBorder: (text: string) => theme.fg(\"mdCodeBlockBorder\", text),\n\t\tquote: (text: string) => theme.fg(\"mdQuote\", text),\n\t\tquoteBorder: (text: string) => theme.fg(\"mdQuoteBorder\", text),\n\t\thr: (text: string) => theme.fg(\"mdHr\", text),\n\t\tlistBullet: (text: string) => theme.fg(\"mdListBullet\", text),\n\t\tbold: (text: string) => theme.bold(text),\n\t\titalic: (text: string) => theme.italic(text),\n\t\tunderline: (text: string) => theme.underline(text),\n\t\tstrikethrough: (text: string) => theme.strikethrough(text),\n\t\thighlightCode: (code: string, lang?: string): string[] => {\n\t\t\t// Validate language before highlighting to avoid stderr spam from cli-highlight\n\t\t\tconst validLang = lang && supportsLanguage(lang) ? lang : undefined;\n\t\t\t// Skip highlighting when no valid language is specified. cli-highlight's\n\t\t\t// auto-detection is unreliable and can misidentify prose as AppleScript,\n\t\t\t// LiveCodeServer, etc., coloring random English words as keywords.\n\t\t\tif (!validLang) {\n\t\t\t\treturn code.split(\"\\n\").map((line) => theme.fg(\"mdCodeBlock\", line));\n\t\t\t}\n\t\t\tconst opts = {\n\t\t\t\tlanguage: validLang,\n\t\t\t\tignoreIllegals: true,\n\t\t\t\ttheme: getCliHighlightTheme(theme),\n\t\t\t};\n\t\t\ttry {\n\t\t\t\treturn highlight(code, opts).split(\"\\n\");\n\t\t\t} catch {\n\t\t\t\treturn code.split(\"\\n\").map((line) => theme.fg(\"mdCodeBlock\", line));\n\t\t\t}\n\t\t},\n\t};\n}\n\nexport function getSelectListTheme(): SelectListTheme {\n\treturn {\n\t\tselectedPrefix: (text: string) => theme.fg(\"accent\", text),\n\t\tselectedText: (text: string) => theme.fg(\"accent\", text),\n\t\tdescription: (text: string) => theme.fg(\"muted\", text),\n\t\tscrollInfo: (text: string) => theme.fg(\"muted\", text),\n\t\tnoMatch: (text: string) => theme.fg(\"muted\", text),\n\t};\n}\n\nexport function getEditorTheme(): EditorTheme {\n\treturn {\n\t\tborderColor: (text: string) => theme.fg(\"borderMuted\", text),\n\t\tselectList: getSelectListTheme(),\n\t};\n}\n\nexport function getSettingsListTheme(): SettingsListTheme {\n\treturn {\n\t\tlabel: (text: string, selected: boolean) => (selected ? theme.fg(\"accent\", text) : text),\n\t\tvalue: (text: string, selected: boolean) => (selected ? theme.fg(\"accent\", text) : theme.fg(\"muted\", text)),\n\t\tdescription: (text: string) => theme.fg(\"dim\", text),\n\t\tcursor: theme.fg(\"accent\", \"→ \"),\n\t\thint: (text: string) => theme.fg(\"dim\", text),\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"theme.js","sourceRoot":"","sources":["../../../../src/modes/interactive/theme/theme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EACN,cAAc,EAEd,UAA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,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACxF,KAAK,EAAE,CAAC,IAAY,EAAE,QAAiB,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC3G,WAAW,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC;QACpD,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC;QAChC,IAAI,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC;KAC7C,CAAC;AACH,CAAC","sourcesContent":["import * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport {\n\tbackgroundAnsi,\n\ttype Color,\n\tcolorToHex,\n\tcolorToOklch,\n\ttype EditorTheme,\n\tforegroundAnsi,\n\tgetTerminalColorMode,\n\tindexedColor,\n\ttype MarkdownTheme,\n\tmixColors,\n\tparseColor,\n\ttype RgbColor,\n\trgbColor,\n\ttype SelectListTheme,\n\ttype SettingsListTheme,\n\tstyleTextWithAnsi,\n\ttype TerminalColorMode,\n\ttype TerminalColors,\n\ttype TextAttributes,\n} from \"@earendil-works/pi-tui\";\nimport chalk from \"chalk\";\nimport { getCustomThemesDir, getThemesDir } from \"../../../config.ts\";\nimport type { SourceInfo } from \"../../../core/source-info.ts\";\nimport { closeWatcher, watchWithErrorHandler } from \"../../../utils/fs-watch.ts\";\nimport { highlight, supportsLanguage } from \"../../../utils/syntax-highlight.ts\";\nimport { stripBom } from \"../../../utils/text.ts\";\nimport { generateSystemThemeColors, SYSTEM_THEME_NAME, terminalAppearance } from \"./system-theme.ts\";\nimport {\n\ttype ResolvedThemeColorValues,\n\tTHEME_TOKENS,\n\ttype ThemeBg,\n\ttype ThemeColor,\n\ttype ThemeColorValues,\n\ttype ThemeToken,\n} from \"./theme-tokens.ts\";\n\nexport { SYSTEM_THEME_NAME } from \"./system-theme.ts\";\n\n// ============================================================================\n// Types & Schema\n// ============================================================================\n\n/** The schema that validates this shape lives in `theme-schema.ts`; importing the type is free. */\nimport type { ThemeColorValue as ColorValue, ValidatedThemeJson as ThemeJson } from \"./theme-schema.ts\";\n\nexport type { ValidatedThemeJson as ThemeJson } from \"./theme-schema.ts\";\nexport type { ThemeBg, ThemeColor, ThemeToken } from \"./theme-tokens.ts\";\n\n/**\n * Tokens are only accepted in their own slot, because \"\" (terminal default) means the default foreground\n * or background depending on the slot. Use `theme.colors[token]` to use a token's color in the other slot.\n */\nexport interface ThemeStyle extends TextAttributes {\n\tfg?: ThemeColor | Color;\n\tbg?: ThemeBg | Color;\n}\n\nexport type ThemeJsonValidator = (label: string, json: unknown) => ThemeJson;\n\nlet themeJsonValidator: ThemeJsonValidator | undefined;\n\n/**\n * Install full theme validation. Without it, documents are accepted as-is, which is what built-in\n * themes already do: validating user-authored JSON needs typebox, and a presentation that only uses\n * built-in themes should not pay ~17 MB of module graph for it.\n */\nexport function setThemeJsonValidator(validator: ThemeJsonValidator): void {\n\tthemeJsonValidator = validator;\n}\n\n// ============================================================================\n// Color Utilities\n// ============================================================================\n\nfunction resolveVarRefs(\n\tvalue: ColorValue,\n\tvars: Record<string, ColorValue>,\n\tvisited = new Set<string>(),\n): string | number {\n\tif (typeof value === \"number\" || value === \"\" || value.startsWith(\"#\") || /^ok(lch|hsl)\\(/i.test(value)) {\n\t\treturn value;\n\t}\n\tif (visited.has(value)) {\n\t\tthrow new Error(`Circular variable reference detected: ${value}`);\n\t}\n\tif (!(value in vars)) {\n\t\tthrow new Error(`Variable reference not found: ${value}`);\n\t}\n\tvisited.add(value);\n\treturn resolveVarRefs(vars[value], vars, visited);\n}\n\nfunction resolveThemeColors<T extends Record<string, ColorValue>>(\n\tcolors: T,\n\tvars: Record<string, ColorValue> = {},\n): Record<keyof T, string | number> {\n\tconst resolved: Record<string, string | number> = {};\n\tfor (const [key, value] of Object.entries(colors)) {\n\t\tresolved[key] = resolveVarRefs(value, vars);\n\t}\n\treturn resolved as Record<keyof T, string | number>;\n}\n\nfunction withThemeTokenFallbacks<Value>(values: ThemeColorValues<Value>): ResolvedThemeColorValues<Value> {\n\tconst resolved = { ...values } as Partial<ResolvedThemeColorValues<Value>>;\n\tfor (const [rawName, descriptor] of Object.entries(THEME_TOKENS)) {\n\t\tif (!(\"fallback\" in descriptor)) continue;\n\t\tconst name = rawName as ThemeToken;\n\t\tif (resolved[name] !== undefined) continue;\n\t\tconst fallback = descriptor.fallback as ThemeToken;\n\t\tconst fallbackValue = resolved[fallback];\n\t\tif (fallbackValue === undefined) {\n\t\t\tthrow new Error(`Theme token ${rawName} has unresolved fallback ${descriptor.fallback}`);\n\t\t}\n\t\tresolved[name] = fallbackValue;\n\t}\n\treturn resolved as ResolvedThemeColorValues<Value>;\n}\n\n// ============================================================================\n// Appearance & Terminal Default Colors\n// ============================================================================\n\n/** The background a theme is designed for. */\nexport type ThemeAppearance = TerminalTheme;\n\n// The terminal's reported colors. Replaced (never mutated) on update, so themes can cache resolved colors\n// by identity.\nlet terminalColors: TerminalColors = {};\n// While the terminal color query is in flight, the system theme renders in grayscale.\nlet terminalColorsPending = false;\n// The terminal's last light/dark report (mode 2031). Only used while it has not reported a background.\nlet terminalColorScheme: TerminalTheme | undefined;\n\n/**\n * Record the terminal's reported colors. Themes use the default colors for tokens set to \"\" (terminal\n * default); the system theme is generated from all of them. Ends the pending state.\n */\nexport function setTerminalColors(colors: TerminalColors): void {\n\tterminalColors = { ...colors };\n\tterminalColorsPending = false;\n}\n\n/** Record the terminal's light/dark report, the fallback for terminals that do not report their background. */\nexport function setTerminalColorScheme(scheme: TerminalTheme | undefined): void {\n\tterminalColorScheme = scheme;\n}\n\n/** Render the system theme in grayscale until `setTerminalColors()` reports the terminal's colors. */\nexport function markTerminalColorsPending(): void {\n\tterminalColorsPending = true;\n}\n\n/** Assumed terminal default colors when the terminal does not report them. */\nconst GUESSED_DEFAULT_COLORS: Record<ThemeAppearance, { foreground: Color; background: Color }> = {\n\tdark: { foreground: parseColor(\"#e5e5e7\"), background: parseColor(\"#000000\") },\n\tlight: { foreground: parseColor(\"#000000\"), background: parseColor(\"#ffffff\") },\n};\n\nfunction averageLightness(colors: Color[]): number | undefined {\n\t// Palette colors 0-15 follow the user's terminal palette, so they say nothing about the theme.\n\tconst fixed = colors.filter((color) => color.kind !== \"indexed\" || color.index >= 16);\n\tif (fixed.length === 0) return undefined;\n\treturn fixed.reduce((sum, color) => sum + colorToOklch(color).l, 0) / fixed.length;\n}\n\n/** Detect the background a theme is designed for from the lightness of its own colors. */\nfunction detectAppearance(foregrounds: Color[], backgrounds: Color[]): ThemeAppearance | undefined {\n\tconst fg = averageLightness(foregrounds);\n\tconst bg = averageLightness(backgrounds);\n\tif (fg !== undefined && bg !== undefined) return bg < fg ? \"dark\" : \"light\";\n\tif (bg !== undefined) return bg < 0.5 ? \"dark\" : \"light\";\n\tif (fg !== undefined) return fg > 0.5 ? \"dark\" : \"light\";\n\treturn undefined;\n}\n\n// ============================================================================\n// Theme Class\n// ============================================================================\n\nexport class Theme {\n\treadonly name?: string;\n\treadonly sourcePath?: string;\n\tsourceInfo?: SourceInfo;\n\tprivate mode: TerminalColorMode;\n\t// Precomputed escape sequences keep fg()/bg() on the render hot path to a lookup and concat.\n\tprivate readonly fgAnsi = new Map<ThemeColor, string>();\n\tprivate readonly bgAnsi = new Map<ThemeBg, string>();\n\t// Tokens set to \"\" have no color of their own; `colors` fills them from the terminal defaults.\n\tprivate readonly concreteColors: Partial<Record<ThemeToken, Color>> = {};\n\tprivate readonly defaultForegroundTokens: ThemeToken[] = [];\n\tprivate readonly defaultBackgroundTokens: ThemeToken[] = [];\n\t// Foreground tokens rendered faint (SGR 2) on top of their color.\n\tprivate readonly dimTokens: ReadonlySet<ThemeColor>;\n\tprivate readonly ownAppearance: ThemeAppearance | undefined;\n\tprivate resolvedColors: { terminal: TerminalColors; colors: Readonly<Record<ThemeToken, Color>> } | undefined;\n\n\tconstructor(\n\t\tfgColors: Pick<ThemeColorValues<string | number>, ThemeColor>,\n\t\tbgColors: Pick<ThemeColorValues<string | number>, ThemeBg>,\n\t\tmode: TerminalColorMode,\n\t\toptions: {\n\t\t\tname?: string;\n\t\t\tsourcePath?: string;\n\t\t\tsourceInfo?: SourceInfo;\n\t\t\tappearance?: ThemeAppearance;\n\t\t\t/** Foreground tokens to render faint (SGR 2). */\n\t\t\tdim?: readonly ThemeColor[];\n\t\t} = {},\n\t) {\n\t\tthis.name = options.name;\n\t\tthis.sourcePath = options.sourcePath;\n\t\tthis.sourceInfo = options.sourceInfo;\n\t\tthis.mode = mode;\n\t\tthis.dimTokens = new Set(options.dim);\n\t\tconst { fgColors: foregrounds, bgColors: backgrounds } = splitThemeColors(\n\t\t\twithThemeTokenFallbacks({ ...fgColors, ...bgColors }),\n\t\t);\n\t\tconst concreteForegrounds: Color[] = [];\n\t\tconst concreteBackgrounds: Color[] = [];\n\t\t// Returns the escape sequence for the token's own slot.\n\t\tconst addToken = (token: ThemeToken, value: string | number, isBackground: boolean): string => {\n\t\t\tif (value === \"\") {\n\t\t\t\t(isBackground ? this.defaultBackgroundTokens : this.defaultForegroundTokens).push(token);\n\t\t\t\treturn isBackground ? \"\\x1b[49m\" : \"\\x1b[39m\";\n\t\t\t}\n\t\t\tconst color = parseColor(value);\n\t\t\tthis.concreteColors[token] = color;\n\t\t\t(isBackground ? concreteBackgrounds : concreteForegrounds).push(color);\n\t\t\treturn isBackground ? backgroundAnsi(color, mode) : foregroundAnsi(color, mode);\n\t\t};\n\t\tfor (const [token, value] of Object.entries(foregrounds) as [ThemeColor, string | number][]) {\n\t\t\tthis.fgAnsi.set(token, addToken(token, value, false));\n\t\t}\n\t\tfor (const [token, value] of Object.entries(backgrounds) as [ThemeBg, string | number][]) {\n\t\t\tthis.bgAnsi.set(token, addToken(token, value, true));\n\t\t}\n\t\tthis.ownAppearance = options.appearance ?? detectAppearance(concreteForegrounds, concreteBackgrounds);\n\t}\n\n\t/**\n\t * The background the theme is designed for: declared in the theme JSON, detected from its colors,\n\t * or, for themes without usable colors, the terminal's appearance.\n\t */\n\tget appearance(): ThemeAppearance {\n\t\treturn this.ownAppearance ?? getTerminalTheme();\n\t}\n\n\t/**\n\t * Concrete colors for all tokens. Tokens set to \"\" (terminal default) use the terminal's reported\n\t * default colors, or a guess based on `appearance` when the terminal did not report them. Faint\n\t * tokens are approximated by mixing their color toward the background.\n\t */\n\tget colors(): Readonly<Record<ThemeToken, Color>> {\n\t\tconst terminal = terminalColors;\n\t\tif (this.resolvedColors?.terminal !== terminal) {\n\t\t\tconst guess = GUESSED_DEFAULT_COLORS[this.appearance];\n\t\t\tconst toColor = (rgb: RgbColor | undefined, fallback: Color) =>\n\t\t\t\trgb ? rgbColor(rgb.r, rgb.g, rgb.b) : fallback;\n\t\t\tconst foreground = toColor(terminal.foreground, guess.foreground);\n\t\t\tconst background = toColor(terminal.background, guess.background);\n\t\t\tconst colors = { ...this.concreteColors };\n\t\t\tfor (const token of this.defaultForegroundTokens) colors[token] = foreground;\n\t\t\tfor (const token of this.defaultBackgroundTokens) colors[token] = background;\n\t\t\tfor (const token of this.dimTokens) {\n\t\t\t\tconst color = colors[token];\n\t\t\t\tif (color) colors[token] = mixColors(color, background, 0.4);\n\t\t\t}\n\t\t\tthis.resolvedColors = { terminal, colors: Object.freeze(colors as Record<ThemeToken, Color>) };\n\t\t}\n\t\treturn this.resolvedColors.colors;\n\t}\n\n\tstyle(text: string, options: ThemeStyle): string {\n\t\tconst { fg, bg } = options;\n\t\tif (typeof fg === \"string\" && this.dimTokens.has(fg)) options = { ...options, dim: true };\n\t\treturn styleTextWithAnsi(\n\t\t\ttext,\n\t\t\tfg === undefined\n\t\t\t\t? undefined\n\t\t\t\t: typeof fg === \"string\"\n\t\t\t\t\t? this.tokenAnsi(this.fgAnsi, fg)\n\t\t\t\t\t: foregroundAnsi(fg, this.mode),\n\t\t\tbg === undefined\n\t\t\t\t? undefined\n\t\t\t\t: typeof bg === \"string\"\n\t\t\t\t\t? this.tokenAnsi(this.bgAnsi, bg)\n\t\t\t\t\t: backgroundAnsi(bg, this.mode),\n\t\t\toptions,\n\t\t);\n\t}\n\n\tfg(color: ThemeColor, text: string): string {\n\t\tconst ansi = this.tokenAnsi(this.fgAnsi, color);\n\t\tif (this.dimTokens.has(color)) return `${ansi}\\x1b[2m${text}\\x1b[22;39m`;\n\t\treturn `${ansi}${text}\\x1b[39m`;\n\t}\n\n\tbg(color: ThemeBg, text: string): string {\n\t\tconst ansi = this.tokenAnsi(this.bgAnsi, color);\n\t\treturn `${ansi}${text}\\x1b[49m`;\n\t}\n\n\tprivate tokenAnsi<T extends ThemeToken>(ansi: Map<T, string>, token: T): string {\n\t\tconst value = ansi.get(token);\n\t\tif (value === undefined) throw new Error(`Unknown theme color: ${token}`);\n\t\treturn value;\n\t}\n\n\tbold(text: string): string {\n\t\treturn chalk.bold(text);\n\t}\n\n\titalic(text: string): string {\n\t\treturn chalk.italic(text);\n\t}\n\n\tunderline(text: string): string {\n\t\treturn chalk.underline(text);\n\t}\n\n\tinverse(text: string): string {\n\t\treturn chalk.inverse(text);\n\t}\n\n\tstrikethrough(text: string): string {\n\t\treturn chalk.strikethrough(text);\n\t}\n\n\t/** Opening escape sequence for a foreground token. Faint tokens include SGR 2, which `\\x1b[22m` closes. */\n\tgetFgAnsi(color: ThemeColor): string {\n\t\tconst ansi = this.tokenAnsi(this.fgAnsi, color);\n\t\treturn this.dimTokens.has(color) ? `${ansi}\\x1b[2m` : ansi;\n\t}\n\n\tgetBgAnsi(color: ThemeBg): string {\n\t\treturn this.tokenAnsi(this.bgAnsi, color);\n\t}\n\n\tgetColorMode(): TerminalColorMode {\n\t\treturn this.mode;\n\t}\n\n\tgetThinkingBorderColor(level: ThinkingLevel): (str: string) => string {\n\t\t// Map thinking levels to dedicated theme colors\n\t\tswitch (level) {\n\t\t\tcase \"off\":\n\t\t\t\treturn (str: string) => this.fg(\"thinkingOff\", str);\n\t\t\tcase \"minimal\":\n\t\t\t\treturn (str: string) => this.fg(\"thinkingMinimal\", str);\n\t\t\tcase \"low\":\n\t\t\t\treturn (str: string) => this.fg(\"thinkingLow\", str);\n\t\t\tcase \"medium\":\n\t\t\t\treturn (str: string) => this.fg(\"thinkingMedium\", str);\n\t\t\tcase \"high\":\n\t\t\t\treturn (str: string) => this.fg(\"thinkingHigh\", str);\n\t\t\tcase \"xhigh\":\n\t\t\t\treturn (str: string) => this.fg(\"thinkingXhigh\", str);\n\t\t\tcase \"max\":\n\t\t\t\treturn (str: string) => this.fg(\"thinkingMax\", str);\n\t\t\tdefault:\n\t\t\t\treturn (str: string) => this.fg(\"thinkingOff\", str);\n\t\t}\n\t}\n\n\tgetBashModeBorderColor(): (str: string) => string {\n\t\treturn (str: string) => this.fg(\"bashMode\", str);\n\t}\n}\n\n// ============================================================================\n// Theme Loading\n// ============================================================================\n\nlet BUILTIN_THEMES: Record<string, ThemeJson> | undefined;\n\nfunction getBuiltinThemes(): Record<string, ThemeJson> {\n\tif (!BUILTIN_THEMES) {\n\t\tconst themesDir = getThemesDir();\n\t\tconst darkPath = path.join(themesDir, \"dark.json\");\n\t\tconst lightPath = path.join(themesDir, \"light.json\");\n\t\tBUILTIN_THEMES = {\n\t\t\tdark: JSON.parse(stripBom(fs.readFileSync(darkPath, \"utf-8\"))) as ThemeJson,\n\t\t\tlight: JSON.parse(stripBom(fs.readFileSync(lightPath, \"utf-8\"))) as ThemeJson,\n\t\t};\n\t}\n\treturn BUILTIN_THEMES;\n}\n\nexport function getAvailableThemes(): string[] {\n\treturn getAvailableThemesWithPaths().map(({ name }) => name);\n}\n\nexport interface ThemeInfo {\n\tname: string;\n\tpath: string | undefined;\n}\n\nexport function getAvailableThemesWithPaths(): ThemeInfo[] {\n\tconst themesDir = getThemesDir();\n\tconst result: ThemeInfo[] = [];\n\tconst seen = new Set<string>();\n\tconst addTheme = (themeInfo: ThemeInfo) => {\n\t\tif (seen.has(themeInfo.name)) {\n\t\t\treturn;\n\t\t}\n\t\tseen.add(themeInfo.name);\n\t\tresult.push(themeInfo);\n\t};\n\n\t// Built-in themes. The system theme is generated, so it has no file.\n\taddTheme({ name: SYSTEM_THEME_NAME, path: undefined });\n\tfor (const name of Object.keys(getBuiltinThemes())) {\n\t\taddTheme({ name, path: path.join(themesDir, `${name}.json`) });\n\t}\n\n\t// Custom themes\n\tfor (const themeInfo of getCustomThemeInfos()) {\n\t\taddTheme(themeInfo);\n\t}\n\n\tfor (const [name, theme] of registeredThemes.entries()) {\n\t\taddTheme({ name, path: theme.sourcePath });\n\t}\n\n\t// The system theme comes first: it is the default and adapts to every terminal.\n\treturn result.sort((a, b) =>\n\t\ta.name === SYSTEM_THEME_NAME ? -1 : b.name === SYSTEM_THEME_NAME ? 1 : a.name.localeCompare(b.name),\n\t);\n}\n\nfunction getCustomThemeInfos(): ThemeInfo[] {\n\tconst customThemesDir = getCustomThemesDir();\n\tconst result: ThemeInfo[] = [];\n\tif (!fs.existsSync(customThemesDir)) {\n\t\treturn result;\n\t}\n\n\tfor (const file of fs.readdirSync(customThemesDir)) {\n\t\tif (!file.endsWith(\".json\")) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst themePath = path.join(customThemesDir, file);\n\t\ttry {\n\t\t\tconst customTheme = loadThemeFromPath(themePath);\n\t\t\tif (customTheme.name) {\n\t\t\t\tresult.push({ name: customTheme.name, path: themePath });\n\t\t\t}\n\t\t} catch {\n\t\t\t// Invalid themes are ignored here; the resource loader reports them\n\t\t\t// during normal startup/reload.\n\t\t}\n\t}\n\treturn result;\n}\n\nfunction assertThemeNameIsValid(name: string): void {\n\tif (name.includes(\"/\")) {\n\t\tthrow new Error(\n\t\t\t`Invalid theme name \"${name}\": theme names cannot contain \"/\" because it is reserved for automatic light/dark theme settings.`,\n\t\t);\n\t}\n}\n\nfunction parseThemeJson(label: string, json: unknown): ThemeJson {\n\tif (themeJsonValidator) return themeJsonValidator(label, json);\n\tif (typeof json !== \"object\" || json === null || !(\"colors\" in json)) {\n\t\tthrow new Error(`Invalid theme \"${label}\": expected an object with a \"colors\" map.`);\n\t}\n\treturn json as ThemeJson;\n}\n\nfunction parseThemeJsonContent(label: string, content: string): ThemeJson {\n\tlet json: unknown;\n\ttry {\n\t\tjson = JSON.parse(stripBom(content));\n\t} catch (error) {\n\t\tthrow new Error(`Failed to parse theme ${label}: ${error}`);\n\t}\n\treturn parseThemeJson(label, json);\n}\n\nfunction loadThemeJson(name: string): ThemeJson {\n\tconst builtinThemes = getBuiltinThemes();\n\tif (name in builtinThemes) {\n\t\treturn builtinThemes[name];\n\t}\n\tconst registeredTheme = registeredThemes.get(name);\n\tif (registeredTheme?.sourcePath) {\n\t\tconst content = fs.readFileSync(registeredTheme.sourcePath, \"utf-8\");\n\t\treturn parseThemeJsonContent(registeredTheme.sourcePath, content);\n\t}\n\tif (registeredTheme) {\n\t\tthrow new Error(`Theme \"${name}\" does not have a source path for export`);\n\t}\n\tconst customThemesDir = getCustomThemesDir();\n\tconst themePath = path.join(customThemesDir, `${name}.json`);\n\tif (!fs.existsSync(themePath)) {\n\t\tthrow new Error(`Theme not found: ${name}`);\n\t}\n\tconst content = fs.readFileSync(themePath, \"utf-8\");\n\treturn parseThemeJsonContent(name, content);\n}\n\nfunction splitThemeColors(colors: ResolvedThemeColorValues<string | number>): {\n\tfgColors: Record<ThemeColor, string | number>;\n\tbgColors: Record<ThemeBg, string | number>;\n} {\n\tconst fgColors = {} as Record<ThemeColor, string | number>;\n\tconst bgColors = {} as Record<ThemeBg, string | number>;\n\tfor (const [key, value] of Object.entries(colors)) {\n\t\tif (THEME_TOKENS[key as ThemeToken].slot === \"background\") {\n\t\t\tbgColors[key as ThemeBg] = value;\n\t\t} else {\n\t\t\tfgColors[key as ThemeColor] = value;\n\t\t}\n\t}\n\treturn { fgColors, bgColors };\n}\n\nfunction createTheme(themeJson: ThemeJson, mode?: TerminalColorMode, sourcePath?: string): Theme {\n\tconst colorMode = mode ?? getTerminalColorMode();\n\tconst resolvedColors = withThemeTokenFallbacks(resolveThemeColors(themeJson.colors, themeJson.vars));\n\tconst { fgColors, bgColors } = splitThemeColors(resolvedColors);\n\treturn new Theme(fgColors, bgColors, colorMode, {\n\t\tname: themeJson.name,\n\t\tsourcePath,\n\t\tappearance: themeJson.appearance,\n\t});\n}\n\n/** Generate the system theme from the terminal's reported colors (grayscale while they are pending). */\nfunction createSystemTheme(mode?: TerminalColorMode): Theme {\n\tconst generated = generateSystemThemeColors({\n\t\t...terminalColors,\n\t\tsaturation: terminalColorsPending ? 0 : 1,\n\t\tappearanceHint: getTerminalTheme(),\n\t});\n\tconst { fgColors, bgColors } = splitThemeColors(withThemeTokenFallbacks(generated.colors));\n\treturn new Theme(fgColors, bgColors, mode ?? getTerminalColorMode(), {\n\t\tname: SYSTEM_THEME_NAME,\n\t\tappearance: generated.appearance,\n\t\tdim: generated.dim,\n\t});\n}\n\nexport function loadThemeFromPath(themePath: string, mode?: TerminalColorMode): Theme {\n\tconst content = fs.readFileSync(themePath, \"utf-8\");\n\tconst themeJson = parseThemeJsonContent(themePath, content);\n\treturn createTheme(themeJson, mode, themePath);\n}\n\nfunction loadTheme(name: string, mode?: TerminalColorMode): Theme {\n\t// The system theme name is reserved: it takes precedence over custom themes of the same name.\n\tif (name === SYSTEM_THEME_NAME) return createSystemTheme(mode);\n\tconst registeredTheme = registeredThemes.get(name);\n\tif (registeredTheme) {\n\t\treturn registeredTheme;\n\t}\n\tconst themeJson = loadThemeJson(name);\n\treturn createTheme(themeJson, mode);\n}\n\nexport function getThemeByName(name: string): Theme | undefined {\n\ttry {\n\t\treturn loadTheme(name);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nexport type TerminalTheme = \"dark\" | \"light\";\n\nexport function parseAutoThemeSetting(\n\tthemeSetting: string | undefined,\n): { lightTheme: string; darkTheme: string } | undefined {\n\tif (!themeSetting) return undefined;\n\tconst slashIndex = themeSetting.indexOf(\"/\");\n\tif (slashIndex === -1 || themeSetting.indexOf(\"/\", slashIndex + 1) !== -1) {\n\t\treturn undefined;\n\t}\n\n\tconst lightTheme = themeSetting.slice(0, slashIndex).trim();\n\tconst darkTheme = themeSetting.slice(slashIndex + 1).trim();\n\tif (!lightTheme || !darkTheme) {\n\t\treturn undefined;\n\t}\n\treturn { lightTheme, darkTheme };\n}\n\nexport function resolveThemeSetting(\n\tthemeSetting: string | undefined,\n\tterminalTheme: TerminalTheme,\n): string | undefined {\n\tconst autoTheme = parseAutoThemeSetting(themeSetting);\n\tif (autoTheme) {\n\t\treturn terminalTheme === \"light\" ? autoTheme.lightTheme : autoTheme.darkTheme;\n\t}\n\tif (themeSetting?.includes(\"/\")) return undefined;\n\tif (typeof themeSetting === \"string\") return themeSetting;\n\treturn undefined;\n}\n\n/**\n * Dark or light from the `COLORFGBG` environment variable some terminals set, or undefined without a\n * usable background index. The value is `fg;bg` or `fg;xpm;bg` (rxvt), where a field is an ANSI color\n * index or `default` when the color is not in the palette. The index refers to the terminal's own palette,\n * whose colors are unknown here, so it is classified by index like Vim does: 0-6 and 8 (bright black, e.g.\n * Solarized Dark's background) are dark, 7 and 9-15 are light.\n */\nexport function detectColorFgBgTheme(env: NodeJS.ProcessEnv = process.env): TerminalTheme | undefined {\n\tconst bg = env.COLORFGBG?.split(\";\").at(-1)?.trim();\n\tif (!bg || !/^\\d{1,2}$/.test(bg)) return undefined;\n\tconst index = Number(bg);\n\tif (index > 15) return undefined;\n\treturn index <= 6 || index === 8 ? \"dark\" : \"light\";\n}\n\n/**\n * Whether the terminal is dark or light. The background it renders decides, classified the same way the\n * system theme does. Without a reported background: the terminal's light/dark report, then COLORFGBG,\n * then dark.\n */\nexport function detectTerminalTheme(\n\tcolors: TerminalColors = {},\n\treportedScheme?: TerminalTheme,\n\tenv: NodeJS.ProcessEnv = process.env,\n): TerminalTheme {\n\tconst { background, foreground } = colors;\n\tif (background) return terminalAppearance(background, foreground);\n\treturn reportedScheme ?? detectColorFgBgTheme(env) ?? \"dark\";\n}\n\n/** Whether the terminal is dark or light, from everything it reported so far. See `detectTerminalTheme()`. */\nexport function getTerminalTheme(): TerminalTheme {\n\treturn detectTerminalTheme(terminalColors, terminalColorScheme);\n}\n\n// ============================================================================\n// Global Theme Instance\n// ============================================================================\n\n// Use globalThis to share theme across module loaders (node + jiti in dev mode)\nconst THEME_KEY = Symbol.for(\"@earendil-works/pi-coding-agent:theme\");\nconst THEME_KEY_OLD = Symbol.for(\"@mariozechner/pi-coding-agent:theme\");\n\n// Export theme as a getter that reads from globalThis\n// This ensures all module instances (node, jiti) see the same theme\nexport const theme: Theme = new Proxy({} as Theme, {\n\tget(_target, prop) {\n\t\tconst t = (globalThis as Record<symbol, Theme>)[THEME_KEY];\n\t\tif (!t) throw new Error(\"Theme not initialized. Call initTheme() first.\");\n\t\treturn (t as unknown as Record<string | symbol, unknown>)[prop];\n\t},\n});\n\nfunction setGlobalTheme(t: Theme): void {\n\t(globalThis as Record<symbol, Theme>)[THEME_KEY] = t;\n\t(globalThis as Record<symbol, Theme>)[THEME_KEY_OLD] = t;\n}\n\nlet currentThemeName: string | undefined;\nlet themeWatcher: fs.FSWatcher | undefined;\nlet themeReloadTimer: NodeJS.Timeout | undefined;\nlet onThemeChangeCallback: (() => void) | undefined;\nconst registeredThemes = new Map<string, Theme>();\n\nexport function setRegisteredThemes(themes: Theme[]): void {\n\tregisteredThemes.clear();\n\tfor (const theme of themes) {\n\t\tif (theme.name) {\n\t\t\tassertThemeNameIsValid(theme.name);\n\t\t\tregisteredThemes.set(theme.name, theme);\n\t\t}\n\t}\n}\n\nexport function initTheme(themeName?: string, enableWatcher: boolean = false): void {\n\tconst name = themeName ?? SYSTEM_THEME_NAME;\n\tcurrentThemeName = name;\n\ttry {\n\t\tsetGlobalTheme(loadTheme(name));\n\t\tif (enableWatcher) {\n\t\t\tstartThemeWatcher();\n\t\t}\n\t} catch (_error) {\n\t\t// Theme is invalid - fall back to the system theme silently\n\t\tcurrentThemeName = SYSTEM_THEME_NAME;\n\t\tsetGlobalTheme(loadTheme(SYSTEM_THEME_NAME));\n\t\t// Don't start watcher for fallback theme\n\t}\n}\n\nexport function setTheme(name: string, enableWatcher: boolean = false): { success: boolean; error?: string } {\n\tcurrentThemeName = name;\n\ttry {\n\t\tsetGlobalTheme(loadTheme(name));\n\t\tif (enableWatcher) {\n\t\t\tstartThemeWatcher();\n\t\t}\n\t\tif (onThemeChangeCallback) {\n\t\t\tonThemeChangeCallback();\n\t\t}\n\t\treturn { success: true };\n\t} catch (error) {\n\t\t// Theme is invalid - fall back to the system theme\n\t\tcurrentThemeName = SYSTEM_THEME_NAME;\n\t\tsetGlobalTheme(loadTheme(SYSTEM_THEME_NAME));\n\t\t// Don't start watcher for fallback theme\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t};\n\t}\n}\n\nexport function setThemeInstance(themeInstance: Theme): void {\n\tsetGlobalTheme(themeInstance);\n\tcurrentThemeName = \"<in-memory>\";\n\tstopThemeWatcher(); // Can't watch a direct instance\n\tif (onThemeChangeCallback) {\n\t\tonThemeChangeCallback();\n\t}\n}\n\nexport function onThemeChange(callback: () => void): void {\n\tonThemeChangeCallback = callback;\n}\n\nfunction startThemeWatcher(): void {\n\tstopThemeWatcher();\n\n\t// Only watch if it's a custom theme (not built-in)\n\tif (\n\t\t!currentThemeName ||\n\t\tcurrentThemeName === \"dark\" ||\n\t\tcurrentThemeName === \"light\" ||\n\t\tcurrentThemeName === SYSTEM_THEME_NAME\n\t) {\n\t\treturn;\n\t}\n\n\tconst customThemesDir = getCustomThemesDir();\n\tconst watchedThemeName = currentThemeName;\n\tconst watchedFileName = `${watchedThemeName}.json`;\n\tconst themeFile = path.join(customThemesDir, watchedFileName);\n\n\t// Only watch if the file exists\n\tif (!fs.existsSync(themeFile)) {\n\t\treturn;\n\t}\n\n\tconst scheduleReload = () => {\n\t\tif (themeReloadTimer) {\n\t\t\tclearTimeout(themeReloadTimer);\n\t\t}\n\t\tthemeReloadTimer = setTimeout(() => {\n\t\t\tthemeReloadTimer = undefined;\n\n\t\t\t// Ignore stale timers after switching themes or stopping the watcher\n\t\t\tif (currentThemeName !== watchedThemeName) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Keep the last successfully loaded theme active if the file is temporarily missing\n\t\t\tif (!fs.existsSync(themeFile)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\t// Reload the theme from disk and refresh the registry cache\n\t\t\t\tconst reloadedTheme = loadThemeFromPath(themeFile);\n\t\t\t\tregisteredThemes.set(watchedThemeName, reloadedTheme);\n\t\t\t\tsetGlobalTheme(reloadedTheme);\n\t\t\t\t// Notify callback (to invalidate UI)\n\t\t\t\tif (onThemeChangeCallback) {\n\t\t\t\t\tonThemeChangeCallback();\n\t\t\t\t}\n\t\t\t} catch (_error) {\n\t\t\t\t// Ignore errors (file might be in invalid state while being edited)\n\t\t\t}\n\t\t}, 100);\n\t};\n\n\tthemeWatcher =\n\t\twatchWithErrorHandler(\n\t\t\tcustomThemesDir,\n\t\t\t(_eventType, filename) => {\n\t\t\t\tif (currentThemeName !== watchedThemeName) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (!filename) {\n\t\t\t\t\tscheduleReload();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (filename !== watchedFileName) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tscheduleReload();\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tcloseWatcher(themeWatcher);\n\t\t\t\tthemeWatcher = undefined;\n\t\t\t},\n\t\t) ?? undefined;\n}\n\nexport function stopThemeWatcher(): void {\n\tif (themeReloadTimer) {\n\t\tclearTimeout(themeReloadTimer);\n\t\tthemeReloadTimer = undefined;\n\t}\n\tcloseWatcher(themeWatcher);\n\tthemeWatcher = undefined;\n}\n\n// ============================================================================\n// HTML Export Helpers\n// ============================================================================\n\n/**\n * Get resolved theme colors as CSS-compatible hex strings.\n * Used by HTML export to generate CSS custom properties.\n */\nexport function getResolvedThemeColors(themeName?: string): Record<string, string> {\n\tconst colors = loadTheme(themeName ?? currentThemeName ?? SYSTEM_THEME_NAME).colors;\n\treturn Object.fromEntries(Object.entries(colors).map(([token, color]) => [token, colorToHex(color)]));\n}\n\n/**\n * Check if a theme is a \"light\" theme (for CSS that needs light/dark variants).\n */\nexport function isLightTheme(themeName?: string): boolean {\n\treturn loadTheme(themeName ?? currentThemeName ?? SYSTEM_THEME_NAME).appearance === \"light\";\n}\n\n/**\n * Get explicit export colors from theme JSON, if specified.\n * Returns undefined for each color that isn't explicitly set.\n */\nexport function getThemeExportColors(themeName?: string): {\n\tpageBg?: string;\n\tcardBg?: string;\n\tinfoBg?: string;\n} {\n\tconst name = themeName ?? currentThemeName ?? SYSTEM_THEME_NAME;\n\tif (name === SYSTEM_THEME_NAME) return {};\n\ttry {\n\t\tconst themeJson = loadThemeJson(name);\n\t\tconst exportSection = themeJson.export;\n\t\tif (!exportSection) return {};\n\n\t\tconst vars = themeJson.vars ?? {};\n\t\t// Export colors end up in CSS, which understands hex and oklch() values directly but not okhsl().\n\t\tconst resolve = (value: ColorValue | undefined): string | undefined => {\n\t\t\tif (value === undefined) return undefined;\n\t\t\tconst resolved = resolveVarRefs(value, vars);\n\t\t\tif (typeof resolved === \"number\") return colorToHex(indexedColor(resolved));\n\t\t\tif (resolved === \"\") return undefined;\n\t\t\tif (/^okhsl\\(/i.test(resolved)) return colorToHex(parseColor(resolved));\n\t\t\treturn resolved;\n\t\t};\n\n\t\treturn {\n\t\t\tpageBg: resolve(exportSection.pageBg),\n\t\t\tcardBg: resolve(exportSection.cardBg),\n\t\t\tinfoBg: resolve(exportSection.infoBg),\n\t\t};\n\t} catch {\n\t\treturn {};\n\t}\n}\n\n// ============================================================================\n// TUI Helpers\n// ============================================================================\n\ntype CliHighlightTheme = Record<string, (s: string) => string>;\n\nlet cachedHighlightThemeFor: Theme | undefined;\nlet cachedCliHighlightTheme: CliHighlightTheme | undefined;\n\nfunction buildCliHighlightTheme(t: Theme): CliHighlightTheme {\n\treturn {\n\t\tkeyword: (s: string) => t.fg(\"syntaxKeyword\", s),\n\t\tbuilt_in: (s: string) => t.fg(\"syntaxType\", s),\n\t\tliteral: (s: string) => t.fg(\"syntaxNumber\", s),\n\t\tnumber: (s: string) => t.fg(\"syntaxNumber\", s),\n\t\tregexp: (s: string) => t.fg(\"syntaxString\", s),\n\t\tstring: (s: string) => t.fg(\"syntaxString\", s),\n\t\tsubst: (s: string) => t.fg(\"text\", s),\n\t\tcomment: (s: string) => t.fg(\"syntaxComment\", s),\n\t\tdoctag: (s: string) => t.fg(\"syntaxComment\", s),\n\t\tmeta: (s: string) => t.fg(\"muted\", s),\n\t\tfunction: (s: string) => t.fg(\"syntaxFunction\", s),\n\t\ttitle: (s: string) => t.fg(\"syntaxFunction\", s),\n\t\tclass: (s: string) => t.fg(\"syntaxType\", s),\n\t\ttype: (s: string) => t.fg(\"syntaxType\", s),\n\t\ttag: (s: string) => t.fg(\"syntaxPunctuation\", s),\n\t\tname: (s: string) => t.fg(\"syntaxKeyword\", s),\n\t\tattr: (s: string) => t.fg(\"syntaxVariable\", s),\n\t\tvariable: (s: string) => t.fg(\"syntaxVariable\", s),\n\t\tparams: (s: string) => t.fg(\"syntaxVariable\", s),\n\t\toperator: (s: string) => t.fg(\"syntaxOperator\", s),\n\t\tpunctuation: (s: string) => t.fg(\"syntaxPunctuation\", s),\n\t\temphasis: (s: string) => t.italic(s),\n\t\tstrong: (s: string) => t.bold(s),\n\t\tlink: (s: string) => t.underline(s),\n\t\taddition: (s: string) => t.fg(\"toolDiffAdded\", s),\n\t\tdeletion: (s: string) => t.fg(\"toolDiffRemoved\", s),\n\t};\n}\n\nfunction getCliHighlightTheme(t: Theme): CliHighlightTheme {\n\tif (cachedHighlightThemeFor !== t || !cachedCliHighlightTheme) {\n\t\tcachedHighlightThemeFor = t;\n\t\tcachedCliHighlightTheme = buildCliHighlightTheme(t);\n\t}\n\treturn cachedCliHighlightTheme;\n}\n\n/**\n * Highlight code with syntax coloring based on file extension or language.\n * Returns array of highlighted lines.\n */\nexport function highlightCode(code: string, lang?: string): string[] {\n\t// Validate language before highlighting to avoid stderr spam from cli-highlight\n\tconst validLang = lang && supportsLanguage(lang) ? lang : undefined;\n\t// Skip highlighting when no valid language is specified. cli-highlight's\n\t// auto-detection is unreliable and can misidentify prose as AppleScript,\n\t// LiveCodeServer, etc., coloring random English words as keywords.\n\tif (!validLang) {\n\t\treturn code.split(\"\\n\").map((line) => theme.fg(\"mdCodeBlock\", line));\n\t}\n\tconst opts = {\n\t\tlanguage: validLang,\n\t\tignoreIllegals: true,\n\t\ttheme: getCliHighlightTheme(theme),\n\t};\n\ttry {\n\t\treturn highlight(code, opts).split(\"\\n\");\n\t} catch {\n\t\treturn code.split(\"\\n\");\n\t}\n}\n\n/**\n * Get language identifier from file path extension.\n */\nexport function getLanguageFromPath(filePath: string): string | undefined {\n\tconst ext = filePath.split(\".\").pop()?.toLowerCase();\n\tif (!ext) return undefined;\n\n\tconst extToLang: Record<string, string> = {\n\t\tts: \"typescript\",\n\t\ttsx: \"typescript\",\n\t\tjs: \"javascript\",\n\t\tjsx: \"javascript\",\n\t\tmjs: \"javascript\",\n\t\tcjs: \"javascript\",\n\t\tpy: \"python\",\n\t\trb: \"ruby\",\n\t\trs: \"rust\",\n\t\tgo: \"go\",\n\t\tjava: \"java\",\n\t\tkt: \"kotlin\",\n\t\tswift: \"swift\",\n\t\tc: \"c\",\n\t\th: \"c\",\n\t\tcpp: \"cpp\",\n\t\tcc: \"cpp\",\n\t\tcxx: \"cpp\",\n\t\thpp: \"cpp\",\n\t\tcs: \"csharp\",\n\t\tphp: \"php\",\n\t\tsh: \"bash\",\n\t\tbash: \"bash\",\n\t\tzsh: \"bash\",\n\t\tfish: \"fish\",\n\t\tps1: \"powershell\",\n\t\tsql: \"sql\",\n\t\thtml: \"html\",\n\t\thtm: \"html\",\n\t\tcss: \"css\",\n\t\tscss: \"scss\",\n\t\tsass: \"sass\",\n\t\tless: \"less\",\n\t\tjson: \"json\",\n\t\tyaml: \"yaml\",\n\t\tyml: \"yaml\",\n\t\ttoml: \"toml\",\n\t\txml: \"xml\",\n\t\tmd: \"markdown\",\n\t\tmarkdown: \"markdown\",\n\t\tdockerfile: \"dockerfile\",\n\t\tmakefile: \"makefile\",\n\t\tcmake: \"cmake\",\n\t\tlua: \"lua\",\n\t\tperl: \"perl\",\n\t\tr: \"r\",\n\t\tscala: \"scala\",\n\t\tclj: \"clojure\",\n\t\tex: \"elixir\",\n\t\texs: \"elixir\",\n\t\terl: \"erlang\",\n\t\ths: \"haskell\",\n\t\tml: \"ocaml\",\n\t\tvim: \"vim\",\n\t\tgraphql: \"graphql\",\n\t\tproto: \"protobuf\",\n\t\ttf: \"hcl\",\n\t\thcl: \"hcl\",\n\t};\n\n\treturn extToLang[ext];\n}\n\nexport function getMarkdownTheme(): MarkdownTheme {\n\treturn {\n\t\theading: (text: string) => theme.fg(\"mdHeading\", text),\n\t\tlink: (text: string) => theme.fg(\"mdLink\", text),\n\t\tlinkUrl: (text: string) => theme.fg(\"mdLinkUrl\", text),\n\t\tcode: (text: string) => theme.fg(\"mdCode\", text),\n\t\tcodeBlock: (text: string) => theme.fg(\"mdCodeBlock\", text),\n\t\tcodeBlockBorder: (text: string) => theme.fg(\"mdCodeBlockBorder\", text),\n\t\tquote: (text: string) => theme.fg(\"mdQuote\", text),\n\t\tquoteBorder: (text: string) => theme.fg(\"mdQuoteBorder\", text),\n\t\thr: (text: string) => theme.fg(\"mdHr\", text),\n\t\tlistBullet: (text: string) => theme.fg(\"mdListBullet\", text),\n\t\tbold: (text: string) => theme.bold(text),\n\t\titalic: (text: string) => theme.italic(text),\n\t\tunderline: (text: string) => theme.underline(text),\n\t\tstrikethrough: (text: string) => theme.strikethrough(text),\n\t\thighlightCode: (code: string, lang?: string): string[] => {\n\t\t\t// Validate language before highlighting to avoid stderr spam from cli-highlight\n\t\t\tconst validLang = lang && supportsLanguage(lang) ? lang : undefined;\n\t\t\t// Skip highlighting when no valid language is specified. cli-highlight's\n\t\t\t// auto-detection is unreliable and can misidentify prose as AppleScript,\n\t\t\t// LiveCodeServer, etc., coloring random English words as keywords.\n\t\t\tif (!validLang) {\n\t\t\t\treturn code.split(\"\\n\").map((line) => theme.fg(\"mdCodeBlock\", line));\n\t\t\t}\n\t\t\tconst opts = {\n\t\t\t\tlanguage: validLang,\n\t\t\t\tignoreIllegals: true,\n\t\t\t\ttheme: getCliHighlightTheme(theme),\n\t\t\t};\n\t\t\ttry {\n\t\t\t\treturn highlight(code, opts).split(\"\\n\");\n\t\t\t} catch {\n\t\t\t\treturn code.split(\"\\n\").map((line) => theme.fg(\"mdCodeBlock\", line));\n\t\t\t}\n\t\t},\n\t};\n}\n\nexport function getSelectListTheme(): SelectListTheme {\n\treturn {\n\t\tselectedPrefix: (text: string) => theme.fg(\"accent\", text),\n\t\tselectedText: (text: string) => theme.fg(\"accent\", text),\n\t\tdescription: (text: string) => theme.fg(\"muted\", text),\n\t\tscrollInfo: (text: string) => theme.fg(\"muted\", text),\n\t\tnoMatch: (text: string) => theme.fg(\"muted\", text),\n\t};\n}\n\nexport function getEditorTheme(): EditorTheme {\n\treturn {\n\t\tborderColor: (text: string) => theme.fg(\"borderMuted\", text),\n\t\tselectList: getSelectListTheme(),\n\t};\n}\n\nexport function getSettingsListTheme(): SettingsListTheme {\n\treturn {\n\t\tlabel: (text: string, selected: boolean) => (selected ? theme.fg(\"accent\", text) : text),\n\t\tvalue: (text: string, selected: boolean) => (selected ? theme.fg(\"accent\", text) : theme.fg(\"muted\", text)),\n\t\tdescription: (text: string) => theme.fg(\"dim\", text),\n\t\tcursor: theme.fg(\"accent\", \"→ \"),\n\t\thint: (text: string) => theme.fg(\"dim\", text),\n\t};\n}\n"]}
|
package/docs/cli-integration.md
CHANGED
|
@@ -27,7 +27,7 @@ pi --print "Summarize the changes in this repository"
|
|
|
27
27
|
|
|
28
28
|
Use print mode when only the final text is needed, including command substitution, pipelines, and one-shot jobs. Intermediate events are not exposed.
|
|
29
29
|
|
|
30
|
-
Print mode writes errors to stderr. A final assistant response with an `error` or `aborted` stop reason produces a nonzero exit status.
|
|
30
|
+
Print mode writes errors to stderr. A final assistant response with an `error` or `aborted` stop reason produces a nonzero exit status. A response cut off at the model's output token limit (`length` stop reason) still prints its partial text to stdout, writes a warning to stderr, and produces a nonzero exit status.
|
|
31
31
|
|
|
32
32
|
When no mode is selected explicitly, non-TTY stdin or stdout also selects print mode. This allows piped input and output without adding `--print`.
|
|
33
33
|
|
package/docs/cli.md
CHANGED
|
@@ -63,13 +63,13 @@ See [Choose a Model](models.md) for model selection and [Providers](providers.md
|
|
|
63
63
|
- `--provider <name>`<br>
|
|
64
64
|
Restricts `--model` lookup to one provider. It requires `--model`.
|
|
65
65
|
- `--model <pattern>`<br>
|
|
66
|
-
Selects by exact ID or fuzzy ID/name match. It accepts `provider/id` and an optional `:<thinking>` suffix.
|
|
66
|
+
Selects by exact ID or fuzzy ID/name match. It accepts `provider/id` and an optional `:<thinking>` suffix. If several providers match, Pi prefers the one with credentials, otherwise it asks for `--provider`.
|
|
67
67
|
- `--api-key <key>`<br>
|
|
68
|
-
Uses a non-persistent API-key override. It requires a model selected through `--model` or `--models`.
|
|
68
|
+
Uses a non-persistent API-key override. It requires a model selected through `--model` or `--models`. It does not choose between providers that offer the same model.
|
|
69
69
|
- `--thinking <level>`<br>
|
|
70
70
|
Sets `off`, `minimal`, `low`, `medium`, `high`, `xhigh`, or `max`. It overrides a `--model` suffix and is clamped to the model's capabilities.
|
|
71
71
|
- `--models <patterns>`<br>
|
|
72
|
-
Sets a comma-separated scope for startup and cycling. It accepts exact IDs, fuzzy matches, case-insensitive globs, and optional `:<thinking>` suffixes.
|
|
72
|
+
Sets a comma-separated scope for startup and cycling. It accepts exact IDs, fuzzy matches, case-insensitive globs, and optional `:<thinking>` suffixes. A model offered by several providers is added for each, with a warning.
|
|
73
73
|
- `--list-models [search]`<br>
|
|
74
74
|
Lists available models, optionally filtered by a fuzzy search, then exits.
|
|
75
75
|
|
|
@@ -117,15 +117,25 @@ pi --tools read,grep,find,ls --print "Review this project"
|
|
|
117
117
|
See [Settings](settings.md#tools) for configuring the default tool selection.
|
|
118
118
|
|
|
119
119
|
- `-t`, `--tools <list>`<br>
|
|
120
|
-
Replaces the default selection with a comma-separated allowlist of built-in, extension, or custom tools.
|
|
120
|
+
Replaces the default selection with a comma-separated allowlist of built-in, extension, or custom tools. Entries are tool names or patterns where `*` matches any characters. MCP tools are kept unless an entry starts with `mcp__` (see [MCP tools](#mcp-tools)). A list of only `+name` and `-name` entries is not an allowlist; it changes the default selection instead.
|
|
121
121
|
- `-xt`, `--exclude-tools <list>`<br>
|
|
122
|
-
Disables comma-separated tool names after all other selection options.
|
|
122
|
+
Disables comma-separated tool names or patterns after all other selection options, MCP tools included.
|
|
123
123
|
- `-nbt`, `--no-builtin-tools`<br>
|
|
124
124
|
Disables default built-in tools while retaining extension and custom tools.
|
|
125
125
|
- `-nt`, `--no-tools`<br>
|
|
126
|
-
Starts with all built-in, extension, and
|
|
126
|
+
Starts with all built-in, extension, custom, and MCP tools disabled.
|
|
127
127
|
|
|
128
|
-
Default enabled tools are `read`, `bash`, `edit`, and `write`, unless `defaultTools` changes them. `--tools` replaces the whole selection, so name every tool you want
|
|
128
|
+
Default enabled tools are `read`, `bash`, `edit`, and `write`, unless `defaultTools` changes them. `--tools` with plain names replaces the whole selection, so name every tool you want. Like `defaultTools`, it also accepts a list of only `+name` and `-name` entries, which adds tools to or removes them from the default selection: `pi --tools +codemode,-write` keeps the other default tools, enables `codemode`, and disables `write`. These entries take exact tool names, not `*` patterns; use `--exclude-tools` to disable tools by pattern. Plain names and `+name`/`-name` entries cannot be mixed. `/reload` enables tools newly added to `defaultTools`, but a tool removed with `-name` stays removed.
|
|
129
|
+
|
|
130
|
+
<a id="mcp-tools"></a>
|
|
131
|
+
|
|
132
|
+
`--tools` selects the tools declared to the model. It does not remove MCP tools, whose reach is set by their [exposure](mcp.md#control-tool-exposure): `pi --tools read,codemode` keeps every MCP tool callable from codemode scripts. An MCP tool that no entry names or matches is never declared directly, whatever its exposure; only `tool_search`, if listed, can load it. Once an entry starts with `mcp__`, `--tools` filters MCP tools too, so this keeps only the tools of the `radius` server:
|
|
133
|
+
|
|
134
|
+
```sh
|
|
135
|
+
pi --tools read,bash,codemode,'mcp__radius__*'
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
The MCP resource tools (`list_mcp_resources`, `list_mcp_resource_templates`, `read_mcp_resource`) count as MCP tools. To remove MCP tools, use `--exclude-tools 'mcp__*'` or [`--no-mcp`](#resource-options).
|
|
129
139
|
|
|
130
140
|
| Built-in | Purpose |
|
|
131
141
|
|---|---|
|
|
@@ -155,10 +165,10 @@ To turn on `codemode` for every session, add it to the default tools in `~/.pi/a
|
|
|
155
165
|
}
|
|
156
166
|
```
|
|
157
167
|
|
|
158
|
-
This keeps `read`, `bash`, `edit`, and `write` and adds `codemode`. For one invocation,
|
|
168
|
+
This keeps `read`, `bash`, `edit`, and `write` and adds `codemode`. For one invocation, add it with `--tools`:
|
|
159
169
|
|
|
160
170
|
```sh
|
|
161
|
-
pi --tools
|
|
171
|
+
pi --tools +codemode
|
|
162
172
|
```
|
|
163
173
|
|
|
164
174
|
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)).
|
|
@@ -185,6 +195,8 @@ See [Configuration](configuration.md) for conventional directories and project t
|
|
|
185
195
|
Loads an extension file or directory, or a built-in extension such as `builtin:mcp`, and is repeatable.
|
|
186
196
|
- `-ne`, `--no-extensions`<br>
|
|
187
197
|
Disables discovered, configured, and built-in extensions. Explicit `-e` paths still load, so `pi -ne -e builtin:mcp` keeps only the built-in MCP support.
|
|
198
|
+
- `--no-mcp`<br>
|
|
199
|
+
Disables the built-in MCP support for this run: no servers connect, and there are no MCP tools or `/mcp`. It does not affect an extension that replaces the built-in MCP support.
|
|
188
200
|
- `--skill <path>`<br>
|
|
189
201
|
Loads a skill file or directory and is repeatable.
|
|
190
202
|
- `-ns`, `--no-skills`<br>
|
|
@@ -313,7 +325,7 @@ These commands work outside a session, so agents can run them through `bash`. Se
|
|
|
313
325
|
| `pi mcp add <server> [options] --url <url>` | Add or replace a streamable HTTP server; `--header KEY=VALUE` (repeatable), `--bearer-token-env-var <NAME>` (sends `Authorization: Bearer ${NAME}`), `--oauth-client-id`, `--oauth-client-secret`, `--oauth-callback-port`, and `--oauth-client-name` configure authentication |
|
|
314
326
|
| `pi mcp remove <server>` | Remove a server from `mcp.json`; stored OAuth credentials are kept |
|
|
315
327
|
| `pi mcp list [--json]` | Connect to every enabled server and print its state, tools, and errors; exit with `1` when a config entry is invalid or an enabled server is not connected |
|
|
316
|
-
| `pi mcp login <server> [--timeout <seconds>]` | Sign in to an OAuth server: open the authorization page and wait for the browser
|
|
328
|
+
| `pi mcp login <server> [--timeout <seconds>]` | Sign in to an OAuth server: open the authorization page and wait for the browser; a terminal also accepts the pasted redirect URL. `--timeout` limits the whole sign-in, including requests to the authorization server (default 300 seconds) |
|
|
317
329
|
| `pi mcp logout <server>` | Delete the stored OAuth credentials of a server |
|
|
318
330
|
|
|
319
331
|
`add` and `remove` change `~/.pi/agent/mcp.json`, or `.pi/mcp.json` in the current directory with `--local` (`-l`). `add` also takes `--exposure <mode>` (see [Exposure](mcp.md#exposure)) and `--description <text>` and does not connect; run `pi mcp list` to check the server.
|
package/docs/codemode.md
CHANGED
|
@@ -6,7 +6,7 @@ The `codemode` tool lets the model write a JavaScript script that calls pi's oth
|
|
|
6
6
|
|
|
7
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
8
|
|
|
9
|
-
A script may start with an options line:
|
|
9
|
+
A script may start with an options line. It must be the first line; an options line anywhere else fails the call before the script runs:
|
|
10
10
|
|
|
11
11
|
```js
|
|
12
12
|
// @options: {"max_output_tokens": 2000, "timeout_ms": 60000}
|
|
@@ -15,7 +15,7 @@ A script may start with an options line:
|
|
|
15
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. A script fails when its output passes 16777216 characters of text and base64 image data or 100000 `text()`, `image()`, and `console` calls; write large data to a file with a tool instead.
|
|
16
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
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.
|
|
18
|
+
The result starts with `Script completed` or `Script failed`, the wall time, and the output. Text and image items appear in order, each on its own line. When the output has more than one text item (from `text()` or `return`), each starts with a `==> text N/M <==` line. `console` calls follow in one `<console_output>` block with one line per call. 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
19
|
|
|
20
20
|
## Globals
|
|
21
21
|
|
|
@@ -24,7 +24,7 @@ The result starts with `Script completed` or `Script failed`, the wall time, and
|
|
|
24
24
|
| `tools.<name>(args)` | Call a tool. See [Call tools](#call-tools). |
|
|
25
25
|
| `text(value)` | Add a text item to the output. Strings are added as is, other values as JSON. |
|
|
26
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. Each image is also saved to a temp file, and the result names the path before the image. |
|
|
27
|
-
| `console.log(...)` |
|
|
27
|
+
| `console.log(...)` | Add a line to the `<console_output>` block after the other output. Arguments are joined with spaces; `info`, `warn`, `error`, and `debug` do the same. |
|
|
28
28
|
| `return value` | A top-level `return` adds the value like `text()`. |
|
|
29
29
|
| `exit()` | End the script successfully. |
|
|
30
30
|
| `store(key, value)` / `load(key)` | Keep small JSON values across `codemode` calls. See [Store values](#store-values). |
|
|
@@ -42,13 +42,14 @@ What a call resolves to depends on the tool:
|
|
|
42
42
|
|
|
43
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
44
|
- MCP tools resolve to their `CallToolResult`, including `isError` and `structuredContent`.
|
|
45
|
-
-
|
|
45
|
+
- `read` resolves to the file's text, or for an image to an image block `{ type: "image", data, mimeType, note }` that `image()` shows. `data` is the base64 image the model would see and `note` the text that goes with it, such as resize hints.
|
|
46
|
+
- Other tools, such as `edit` and `write`, resolve to their text output.
|
|
46
47
|
|
|
47
48
|
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
|
|
|
49
50
|
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
|
|
|
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
|
+
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. Tool declarations in the `codemode` description, `describeTool()`, and `ALL_TOOLS` carry the tools' prompt guidelines, since the system prompt rules only cover declared tools.
|
|
52
53
|
|
|
53
54
|
## Store values
|
|
54
55
|
|
|
@@ -58,7 +59,7 @@ The store is for small state such as IDs, cursors, or summaries. One value may h
|
|
|
58
59
|
|
|
59
60
|
## Models
|
|
60
61
|
|
|
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
|
+
`models` reaches the model catalog and runs non-LLM models with the session's credentials: classifiers, which answer typed questions about JSON state and, for some models, images, 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
|
|
|
63
64
|
```ts
|
|
64
65
|
type ModelType = "chat" | "image" | "classifier";
|
|
@@ -99,6 +100,8 @@ Model IDs differ between providers, for example `typesafe/jev-latest` and `openr
|
|
|
99
100
|
interface ClassifierContext {
|
|
100
101
|
/** The data to classify. */
|
|
101
102
|
state: Record<string, unknown>;
|
|
103
|
+
/** Images judged together with `state`. Only models whose `input` includes "image" accept them. */
|
|
104
|
+
images?: { type: "image"; data: string; mimeType: string }[];
|
|
102
105
|
/** Questions by ID. One call answers all of them. */
|
|
103
106
|
questions: Record<string, ClassifierQuestion>;
|
|
104
107
|
}
|
|
@@ -162,6 +165,24 @@ return results.map((result, i) =>
|
|
|
162
165
|
);
|
|
163
166
|
```
|
|
164
167
|
|
|
168
|
+
Classifiers whose `input` includes `"image"` also judge images. `tools.read()` returns an image file as an image block that `images` accepts. Other classifiers return an error result when `images` is not empty.
|
|
169
|
+
|
|
170
|
+
```js
|
|
171
|
+
const luna = await models.getModelOfType("classifier", "openai", "gpt-6-luna");
|
|
172
|
+
const photo = await tools.read({ path: "screenshot.png" });
|
|
173
|
+
const result = await models.classify(luna, {
|
|
174
|
+
state: { task: "Settings page redesign" },
|
|
175
|
+
images: [photo],
|
|
176
|
+
questions: {
|
|
177
|
+
broken: {
|
|
178
|
+
type: "bool",
|
|
179
|
+
instructions: "Does the screenshot show a broken layout?",
|
|
180
|
+
criteria: { true: "Overlapping, cut-off, or misaligned elements", false: "Clean layout" },
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
```
|
|
185
|
+
|
|
165
186
|
### Generate images
|
|
166
187
|
|
|
167
188
|
```ts
|
|
@@ -203,5 +224,7 @@ for (const block of result.output) {
|
|
|
203
224
|
## Limits
|
|
204
225
|
|
|
205
226
|
- 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.
|
|
227
|
+
- On Bun, stopping a script or reaching its deadline ends the call promptly, but a built-in that does not poll QuickJS's interrupt handler can keep computing in its worker until it returns.
|
|
228
|
+
- At most two codemode workers may be alive across all sessions in one pi process. A cancelled worker occupies its slot until it exits. At capacity, new scripts fail immediately without starting another worker; retry after an existing worker exits.
|
|
206
229
|
- A script that waits on a promise that can never settle (no tool call pending) fails immediately, since there are no timers.
|
|
207
230
|
- Scripts cannot start other `codemode` scripts.
|
package/docs/compaction.md
CHANGED
|
@@ -32,7 +32,7 @@ Auto-compaction triggers when:
|
|
|
32
32
|
contextTokens > contextWindow - reserveTokens
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
By default, `reserveTokens` is 16384 tokens (configurable in `~/.pi/agent/settings.json` or `<project-dir>/.pi/settings.json`).
|
|
35
|
+
By default, `reserveTokens` is 16384 tokens (configurable in `~/.pi/agent/settings.json` or `<project-dir>/.pi/settings.json`). It only decides when compaction starts. Summary requests use the model's output limit, reduced when needed so input and output fit the context window.
|
|
36
36
|
|
|
37
37
|
During a multi-turn agent run, Pi checks the canonical projected context after tools finish and their results are appended, before starting the next assistant response. If the threshold is crossed, Pi compacts during `prepareNextTurn`, then performs the existing catch-up steering poll before `turn_start`. It skips this between-turn check when the completed tool batch terminates the run and no queued message requires another response. Pi also checks before a new user prompt and performs final-attempt overflow recovery after the low-level run ends.
|
|
38
38
|
|
|
@@ -279,7 +279,6 @@ Before summarization, messages are serialized to text via [`serializeConversatio
|
|
|
279
279
|
|
|
280
280
|
```
|
|
281
281
|
[User]: What they said
|
|
282
|
-
[Assistant thinking]: Internal reasoning
|
|
283
282
|
[Assistant]: Response text
|
|
284
283
|
[Assistant tool calls]: read(path="foo.ts"); edit(path="bar.ts", ...)
|
|
285
284
|
[Tool result]: Output from tool
|
|
@@ -287,6 +286,8 @@ Before summarization, messages are serialized to text via [`serializeConversatio
|
|
|
287
286
|
|
|
288
287
|
This prevents the model from treating it as a conversation to continue.
|
|
289
288
|
|
|
289
|
+
Thinking blocks are omitted. Providers return summaries of the real reasoning, and replayed thinking is often not part of the model's live context, so including it could make the summarization request larger than the context it summarizes.
|
|
290
|
+
|
|
290
291
|
Tool results are truncated to 2000 characters during serialization. Content beyond that limit is replaced with a marker indicating how many characters were truncated. This keeps summarization requests within reasonable token budgets, since tool results (especially from `read` and `bash`) are typically the largest contributors to context size.
|
|
291
292
|
|
|
292
293
|
## Custom Summarization via Extensions
|
|
@@ -346,7 +347,6 @@ pi.on("session_before_compact", async (event, ctx) => {
|
|
|
346
347
|
);
|
|
347
348
|
// Returns:
|
|
348
349
|
// [User]: message text
|
|
349
|
-
// [Assistant thinking]: thinking content
|
|
350
350
|
// [Assistant]: response text
|
|
351
351
|
// [Assistant tool calls]: read(path="..."); bash(command="...")
|
|
352
352
|
// [Tool result]: output text
|
|
@@ -431,7 +431,7 @@ Configure compaction in `~/.pi/agent/settings.json` or `<project-dir>/.pi/settin
|
|
|
431
431
|
| Setting | Default | Description |
|
|
432
432
|
|---------|---------|-------------|
|
|
433
433
|
| `enabled` | `true` | Enable auto-compaction |
|
|
434
|
-
| `reserveTokens` | `16384` |
|
|
434
|
+
| `reserveTokens` | `16384` | Free context tokens below which auto-compaction starts |
|
|
435
435
|
| `keepRecentTokens` | `20000` | Recent tokens to keep (not summarized) |
|
|
436
436
|
|
|
437
437
|
Disable auto-compaction with `"enabled": false`. You can still compact manually with `/compact`.
|
|
@@ -454,7 +454,7 @@ Use `compaction.modelOverrides` to tune token budgets for different models:
|
|
|
454
454
|
}
|
|
455
455
|
```
|
|
456
456
|
|
|
457
|
-
For a model with a 1M context window, this override triggers compaction above 600K tokens and keeps the ordinary 20000 recent tokens. Other models retain the ordinary 16384-token reserve.
|
|
457
|
+
For a model with a 1M context window, this override triggers compaction above 600K tokens and keeps the ordinary 20000 recent tokens. Other models retain the ordinary 16384-token reserve.
|
|
458
458
|
|
|
459
459
|
Keys are exact, case-sensitive `provider/modelId` values, including any slashes within the model ID. Each `reserveTokens` and `keepRecentTokens` value falls back independently from the model override to the ordinary setting to the built-in default. Values must be non-negative safe integers. Invalid values in the matching model override produce an error when read; only omitted fields fall back to the ordinary setting. Model override entries must be objects. Invalid ordinary token settings produce an error when read, even if the active model has a valid override. Only omitted ordinary values use built-in defaults. `enabled` remains global, not model-specific.
|
|
460
460
|
|