mu-agent 0.1.7 → 0.1.8
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 +25 -0
- package/README.md +5 -4
- package/dist/bundle/chunks/anthropic-messages-MI4QHRXW.js +6 -0
- package/dist/bundle/chunks/anthropic.js +2 -2
- package/dist/bundle/chunks/azure-openai-responses-E3QGN4VN.js +2 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +2 -2
- package/dist/bundle/chunks/chunk-33KL6IIQ.js +20 -0
- package/dist/bundle/chunks/chunk-4OBXYPH4.js +4 -0
- package/dist/bundle/chunks/chunk-C47CLQZK.js +2 -0
- package/dist/bundle/chunks/chunk-F5ZABL6Z.js +20 -0
- package/dist/bundle/chunks/chunk-H3QXYIF7.js +31 -0
- package/dist/bundle/chunks/chunk-HQHD6PZI.js +2 -0
- package/dist/bundle/chunks/chunk-KJUDFE6Y.js +11 -0
- package/dist/bundle/chunks/chunk-LD2P6SFZ.js +2 -0
- package/dist/bundle/chunks/chunk-NG4PO5FP.js +1204 -0
- package/dist/bundle/chunks/chunk-NTSWBG4X.js +2 -0
- package/dist/bundle/chunks/chunk-RLZVFGW4.js +127 -0
- package/dist/bundle/chunks/{chunk-XDUWOHPL.js → chunk-S3GGRYIO.js} +2 -2
- package/dist/bundle/chunks/{chunk-4O2SCVYF.js → chunk-TAOL3JFA.js} +1 -1
- package/dist/bundle/chunks/chunk-TE3GUV6H.js +9 -0
- package/dist/bundle/chunks/chunk-VIV3CWXG.js +2 -0
- package/dist/bundle/chunks/{chunk-V7IXECST.js → chunk-WE4MXUQS.js} +3 -3
- package/dist/bundle/chunks/chunk-Y2PP32XV.js +2 -0
- package/dist/bundle/chunks/chunk-YLY6CKPK.js +132 -0
- package/dist/bundle/chunks/chunk-ZE5FMF3V.js +99 -0
- package/dist/bundle/chunks/cli-AOVD3SSZ.js +51 -0
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-NM3JRRWQ.js +2 -0
- package/dist/bundle/chunks/codemode-worker.js +374 -0
- package/dist/bundle/chunks/easter-egg-3d-G2LUBEMZ.js +2 -0
- package/dist/bundle/chunks/execute-MZVUC6BB.js +388 -0
- package/dist/bundle/chunks/github-copilot.js +1 -1
- package/dist/bundle/chunks/{google-generative-ai-C44KRRZ4.js → google-generative-ai-XMFHGQC5.js} +1 -1
- package/dist/bundle/chunks/{google-vertex-25DUXPTJ.js → google-vertex-4XRRNP74.js} +1 -1
- package/dist/bundle/chunks/{lib-HGQMNYVT.js → lib-TEDK3E5I.js} +2 -2
- package/dist/bundle/chunks/llama-cpp-classify-XT44PI3C.js +22 -0
- package/dist/bundle/chunks/mistral-conversations-Q22M3IBG.js +5 -0
- package/dist/bundle/chunks/node-N5BSDOA5.js +16 -0
- package/dist/bundle/chunks/openai-chatgpt.js +86 -0
- package/dist/bundle/chunks/{openai-codex-responses-3UAYOSSR.js → openai-codex-responses-4MYQSO5E.js} +1 -1
- package/dist/bundle/chunks/openai-codex.js +2 -2
- package/dist/bundle/chunks/openai-completions-OSRCWAAA.js +7 -0
- package/dist/bundle/chunks/openai-responses-UHF3DHNG.js +3 -0
- package/dist/bundle/chunks/{openrouter-images-JVEJN44Q.js → openrouter-images-ZVXWCSIM.js} +1 -1
- package/dist/bundle/chunks/openrouter.js +2 -2
- package/dist/bundle/chunks/radius.js +2 -2
- package/dist/bundle/chunks/runtime-VJMMDLVH.js +2 -0
- package/dist/bundle/chunks/typesafe-system-one-PRR5K6CI.js +2 -0
- package/dist/bundle/chunks/virtual-modules-RJXJGCPI.js +2 -0
- package/dist/bundle/cli-runtime.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/native/darwin/prebuilds/darwin-arm64/darwin-platform.node +0 -0
- package/dist/bundle/native/darwin/prebuilds/darwin-x64/darwin-platform.node +0 -0
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/core/export-html/template.js +16 -0
- package/dist/modes/interactive/theme/dark.json +59 -72
- package/dist/modes/interactive/theme/light.json +57 -69
- package/dist/modes/interactive/theme/system-theme.d.ts +55 -0
- package/dist/modes/interactive/theme/system-theme.d.ts.map +1 -0
- package/dist/modes/interactive/theme/system-theme.js +546 -0
- package/dist/modes/interactive/theme/system-theme.js.map +1 -0
- package/dist/modes/interactive/theme/theme-controller.d.ts +43 -9
- package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme-controller.js +121 -79
- package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
- package/dist/modes/interactive/theme/theme-json.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme-json.js +1 -1
- package/dist/modes/interactive/theme/theme-json.js.map +1 -1
- package/dist/modes/interactive/theme/theme-schema.json +2 -2
- package/dist/modes/interactive/theme/theme.d.ts +34 -40
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +139 -126
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/native/darwin/prebuilds/darwin-arm64/darwin-platform.node +0 -0
- package/dist/native/darwin/prebuilds/darwin-x64/darwin-platform.node +0 -0
- package/docs/cli.md +60 -7
- package/docs/codemode.md +207 -0
- package/docs/configuration.md +2 -0
- package/docs/docs.json +13 -1
- package/docs/environment-variables.md +2 -2
- package/docs/extensions.md +53 -0
- package/docs/index.md +1 -1
- package/docs/keybindings.md +2 -2
- package/docs/llama-cpp.md +13 -0
- package/docs/mcp.md +270 -0
- package/docs/models.md +83 -1
- package/docs/packages.md +1 -1
- package/docs/providers.md +19 -6
- package/docs/quickstart.md +16 -2
- package/docs/rpc-commands.md +9 -3
- package/docs/rpc.md +3 -1
- package/docs/sdk.md +8 -3
- package/docs/security.md +2 -0
- package/docs/session-format.md +5 -1
- package/docs/settings.md +24 -5
- package/docs/themes.md +28 -6
- package/docs/usage.md +1 -1
- package/docs/virtual-models.md +114 -0
- package/docs/windows.md +2 -0
- package/examples/README.md +1 -1
- package/examples/extensions/README.md +1 -0
- package/examples/extensions/built-in-tool-renderer.ts +16 -40
- 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/custom-provider-gitlab-duo/test.ts +5 -5
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/jev-router.ts +113 -0
- package/examples/extensions/minimal-mode.ts +24 -96
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/rpc-client.ts +1 -1
- package/examples/rpc-extension-ui.ts +1 -1
- package/examples/sdk/14-codemode-mcp.ts +61 -0
- package/examples/sdk/README.md +2 -1
- package/judge/THIRD_PARTY_NOTICES.md +63 -0
- package/judge/dist/auth.js +128 -113
- package/judge/dist/import.js +10 -9
- package/judge/dist/kyrn-judge.js +5444 -5354
- package/judge/dist/setup.js +138 -12
- package/judge/manifest.json +414 -102
- package/kyrn/bin/kyrn-doctor +61 -11
- package/kyrn/bin/mu.mjs +84 -69
- package/package.json +4 -4
- package/dist/bundle/chunks/anthropic-messages-VMESUHQ7.js +0 -6
- package/dist/bundle/chunks/azure-openai-responses-K232MQFF.js +0 -2
- package/dist/bundle/chunks/chunk-AYFRR3OD.js +0 -2
- package/dist/bundle/chunks/chunk-DTD7JQ7Y.js +0 -42
- package/dist/bundle/chunks/chunk-FU4XQUSL.js +0 -11
- package/dist/bundle/chunks/chunk-GNYZK6XN.js +0 -2
- package/dist/bundle/chunks/chunk-HEMXN7VJ.js +0 -1653
- package/dist/bundle/chunks/chunk-MVPXOVOJ.js +0 -2
- package/dist/bundle/chunks/chunk-NUHFSC37.js +0 -25
- package/dist/bundle/chunks/chunk-XNGRGP62.js +0 -2
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-NR2TDCXU.js +0 -2
- package/dist/bundle/chunks/mistral-conversations-6IHQOR4R.js +0 -5
- package/dist/bundle/chunks/node-O3RIBJRH.js +0 -16
- package/dist/bundle/chunks/openai-completions-FIEQGWAH.js +0 -7
- package/dist/bundle/chunks/openai-responses-OZJXLHFC.js +0 -2
- package/dist/bundle/chunks/typesafe-system-one-VKYX4OGY.js +0 -2
- package/dist/bundle/chunks/virtual-modules-V7SXVVLP.js +0 -2
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import { Type } from "typebox";
|
|
10
10
|
import { Compile } from "typebox/compile";
|
|
11
11
|
const ColorValueSchema = Type.Union([
|
|
12
|
-
Type.String(), // hex, OKLCH, var ref "primary", or empty ""
|
|
12
|
+
Type.String(), // hex, OKLCH, OKHSL, var ref "primary", or empty ""
|
|
13
13
|
Type.Integer({ minimum: 0, maximum: 255 }), // 256-color index
|
|
14
14
|
]);
|
|
15
15
|
const ThemeJsonSchema = Type.Object({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme-json.js","sourceRoot":"","sources":["../../../../src/modes/interactive/theme/theme-json.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC;IACnC,IAAI,CAAC,MAAM,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"theme-json.js","sourceRoot":"","sources":["../../../../src/modes/interactive/theme/theme-json.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC;IACnC,IAAI,CAAC,MAAM,EAAE,EAAE,oDAAoD;IACnE,IAAI,CAAC,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YAC5B,YAAY,IAAI,oCAAoC,CAAC;YACrD,YAAY,IAAI,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC;iBACvC,IAAI,EAAE;iBACN,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,EAAE,CAAC;iBAC9B,IAAI,CAAC,IAAI,CAAC,CAAC;YACb,YAAY,IAAI,+DAA+D,CAAC;YAChF,YAAY,IAAI,yEAAyE,CAAC;QAC3F,CAAC;QACD,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5B,YAAY,IAAI,sBAAsB,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAChE,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;IAC/B,CAAC;IAED,MAAM,SAAS,GAAG,IAA0B,CAAC;IAC7C,IAAI,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CACd,uBAAuB,SAAS,CAAC,IAAI,mGAAmG,CACxI,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["/**\n * Theme JSON validation, kept out of `theme.ts` on purpose.\n *\n * Validating user-authored theme files needs typebox, which costs ~17 MB of module graph to import.\n * Palette lookup does not, so a presentation that only uses built-in themes should never pay for it.\n * `interactive-mode.ts` installs this validator; anything that does not simply skips validation, as\n * built-in themes already do.\n */\n\nimport { type Static, Type } from \"typebox\";\nimport { Compile } from \"typebox/compile\";\n\nconst ColorValueSchema = Type.Union([\n\tType.String(), // hex, OKLCH, OKHSL, var ref \"primary\", or empty \"\"\n\tType.Integer({ minimum: 0, maximum: 255 }), // 256-color index\n]);\n\nconst ThemeJsonSchema = Type.Object({\n\t$schema: Type.Optional(Type.String()),\n\tname: Type.String(),\n\t// Background the theme is designed for. Detected from the theme colors when omitted.\n\tappearance: Type.Optional(Type.Union([Type.Literal(\"dark\"), Type.Literal(\"light\")])),\n\tvars: Type.Optional(Type.Record(Type.String(), ColorValueSchema)),\n\tcolors: Type.Object({\n\t\t// Core UI (11 colors)\n\t\taccent: ColorValueSchema,\n\t\tborder: ColorValueSchema,\n\t\tborderAccent: ColorValueSchema,\n\t\tborderMuted: ColorValueSchema,\n\t\tsuccess: ColorValueSchema,\n\t\terror: ColorValueSchema,\n\t\twarning: ColorValueSchema,\n\t\tmuted: ColorValueSchema,\n\t\tdim: ColorValueSchema,\n\t\ttext: ColorValueSchema,\n\t\tthinkingText: ColorValueSchema,\n\t\t// Scrollbar (2 optional colors)\n\t\tscrollbarTrack: Type.Optional(ColorValueSchema),\n\t\tscrollbarThumb: Type.Optional(ColorValueSchema),\n\t\t// Backgrounds & Content Text (11 required, 2 optional)\n\t\tselectedBg: ColorValueSchema,\n\t\tsearchMatchBg: Type.Optional(ColorValueSchema),\n\t\tsearchMatchText: Type.Optional(ColorValueSchema),\n\t\tuserMessageBg: ColorValueSchema,\n\t\tuserMessageText: ColorValueSchema,\n\t\tcustomMessageBg: ColorValueSchema,\n\t\tcustomMessageText: ColorValueSchema,\n\t\tcustomMessageLabel: ColorValueSchema,\n\t\ttoolPendingBg: ColorValueSchema,\n\t\ttoolSuccessBg: ColorValueSchema,\n\t\ttoolErrorBg: ColorValueSchema,\n\t\ttoolTitle: ColorValueSchema,\n\t\ttoolOutput: ColorValueSchema,\n\t\t// Markdown (10 colors)\n\t\tmdHeading: ColorValueSchema,\n\t\tmdLink: ColorValueSchema,\n\t\tmdLinkUrl: ColorValueSchema,\n\t\tmdCode: ColorValueSchema,\n\t\tmdCodeBlock: ColorValueSchema,\n\t\tmdCodeBlockBorder: ColorValueSchema,\n\t\tmdQuote: ColorValueSchema,\n\t\tmdQuoteBorder: ColorValueSchema,\n\t\tmdHr: ColorValueSchema,\n\t\tmdListBullet: ColorValueSchema,\n\t\t// Tool Diffs (3 colors)\n\t\ttoolDiffAdded: ColorValueSchema,\n\t\ttoolDiffRemoved: ColorValueSchema,\n\t\ttoolDiffContext: ColorValueSchema,\n\t\t// Syntax Highlighting (9 colors)\n\t\tsyntaxComment: ColorValueSchema,\n\t\tsyntaxKeyword: ColorValueSchema,\n\t\tsyntaxFunction: ColorValueSchema,\n\t\tsyntaxVariable: ColorValueSchema,\n\t\tsyntaxString: ColorValueSchema,\n\t\tsyntaxNumber: ColorValueSchema,\n\t\tsyntaxType: ColorValueSchema,\n\t\tsyntaxOperator: ColorValueSchema,\n\t\tsyntaxPunctuation: ColorValueSchema,\n\t\t// Thinking Level Borders (6 colors)\n\t\tthinkingOff: ColorValueSchema,\n\t\tthinkingMinimal: ColorValueSchema,\n\t\tthinkingLow: ColorValueSchema,\n\t\tthinkingMedium: ColorValueSchema,\n\t\tthinkingHigh: ColorValueSchema,\n\t\tthinkingXhigh: ColorValueSchema,\n\t\tthinkingMax: Type.Optional(ColorValueSchema),\n\t\t// Bash Mode (1 color)\n\t\tbashMode: ColorValueSchema,\n\t}),\n\texport: Type.Optional(\n\t\tType.Object({\n\t\t\tpageBg: Type.Optional(ColorValueSchema),\n\t\t\tcardBg: Type.Optional(ColorValueSchema),\n\t\t\tinfoBg: Type.Optional(ColorValueSchema),\n\t\t}),\n\t),\n});\n\nconst compiledThemeSchema = Compile(ThemeJsonSchema);\n\nexport type ThemeColorValue = Static<typeof ColorValueSchema>;\nexport type ValidatedThemeJson = Static<typeof ThemeJsonSchema>;\n\n/** Validate one theme document, throwing a message that names the offending tokens. */\nexport function validateThemeJson(label: string, json: unknown): ValidatedThemeJson {\n\tif (!compiledThemeSchema.Check(json)) {\n\t\tconst errors = Array.from(compiledThemeSchema.Errors(json));\n\t\tconst missingColors = new Set<string>();\n\t\tconst otherErrors: string[] = [];\n\n\t\tfor (const error of errors) {\n\t\t\tif (error.keyword === \"required\" && error.instancePath === \"/colors\") {\n\t\t\t\tconst requiredProperties = (error.params as { requiredProperties?: string[] }).requiredProperties;\n\t\t\t\tfor (const requiredProperty of requiredProperties ?? []) {\n\t\t\t\t\tmissingColors.add(requiredProperty);\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst path = error.instancePath || \"/\";\n\t\t\totherErrors.push(` - ${path}: ${error.message}`);\n\t\t}\n\n\t\tlet errorMessage = `Invalid theme \"${label}\":\\n`;\n\t\tif (missingColors.size > 0) {\n\t\t\terrorMessage += \"\\nMissing required color tokens:\\n\";\n\t\t\terrorMessage += Array.from(missingColors)\n\t\t\t\t.sort()\n\t\t\t\t.map((color) => ` - ${color}`)\n\t\t\t\t.join(\"\\n\");\n\t\t\terrorMessage += '\\n\\nPlease add these colors to your theme\\'s \"colors\" object.';\n\t\t\terrorMessage += \"\\nSee the built-in themes (dark.json, light.json) for reference values.\";\n\t\t}\n\t\tif (otherErrors.length > 0) {\n\t\t\terrorMessage += `\\n\\nOther errors:\\n${otherErrors.join(\"\\n\")}`;\n\t\t}\n\n\t\tthrow new Error(errorMessage);\n\t}\n\n\tconst themeJson = json as ValidatedThemeJson;\n\tif (themeJson.name.includes(\"/\")) {\n\t\tthrow new Error(\n\t\t\t`Invalid theme name \"${themeJson.name}\": theme names cannot contain \"/\" because it is reserved for automatic light/dark theme settings.`,\n\t\t);\n\t}\n\treturn themeJson;\n}\n"]}
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"oneOf": [
|
|
27
27
|
{
|
|
28
28
|
"type": "string",
|
|
29
|
-
"description": "Hex color (#RGB or #RRGGBB), OKLCH color, variable reference, or empty string for terminal default"
|
|
29
|
+
"description": "Hex color (#RGB or #RRGGBB), OKLCH or OKHSL color, variable reference, or empty string for terminal default"
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
32
|
"type": "integer",
|
|
@@ -347,7 +347,7 @@
|
|
|
347
347
|
"oneOf": [
|
|
348
348
|
{
|
|
349
349
|
"type": "string",
|
|
350
|
-
"description": "Hex color (#RGB or #RRGGBB), OKLCH color, variable reference, or empty string for terminal default"
|
|
350
|
+
"description": "Hex color (#RGB or #RRGGBB), OKLCH or OKHSL color, variable reference, or empty string for terminal default"
|
|
351
351
|
},
|
|
352
352
|
{
|
|
353
353
|
"type": "integer",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
|
|
2
|
-
import { type Color, type EditorTheme, type MarkdownTheme, type
|
|
2
|
+
import { type Color, type EditorTheme, type MarkdownTheme, type SelectListTheme, type SettingsListTheme, type TerminalColorMode, type TerminalColors, type TextAttributes } from "@earendil-works/pi-tui";
|
|
3
3
|
import type { SourceInfo } from "../../../core/source-info.ts";
|
|
4
|
+
export { SYSTEM_THEME_NAME } from "./system-theme.ts";
|
|
4
5
|
/** The schema that validates this shape lives in `theme-json.ts`; importing the type is free. */
|
|
5
6
|
import type { ValidatedThemeJson as ThemeJson } from "./theme-json.ts";
|
|
6
7
|
export type { ValidatedThemeJson as ThemeJson } from "./theme-json.ts";
|
|
@@ -26,11 +27,15 @@ type OptionalThemeColor = "scrollbarTrack" | "scrollbarThumb" | "thinkingMax" |
|
|
|
26
27
|
type OptionalThemeBg = "searchMatchBg";
|
|
27
28
|
/** The background a theme is designed for. */
|
|
28
29
|
export type ThemeAppearance = TerminalTheme;
|
|
29
|
-
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Record the terminal's reported colors. Themes use the default colors for tokens set to "" (terminal
|
|
32
|
+
* default); the system theme is generated from all of them. Ends the pending state.
|
|
33
|
+
*/
|
|
34
|
+
export declare function setTerminalColors(colors: TerminalColors): void;
|
|
35
|
+
/** Record the terminal's light/dark report, the fallback for terminals that do not report their background. */
|
|
36
|
+
export declare function setTerminalColorScheme(scheme: TerminalTheme | undefined): void;
|
|
37
|
+
/** Render the system theme in grayscale until `setTerminalColors()` reports the terminal's colors. */
|
|
38
|
+
export declare function markTerminalColorsPending(): void;
|
|
34
39
|
export declare class Theme {
|
|
35
40
|
readonly name?: string;
|
|
36
41
|
readonly sourcePath?: string;
|
|
@@ -41,6 +46,7 @@ export declare class Theme {
|
|
|
41
46
|
private readonly concreteColors;
|
|
42
47
|
private readonly defaultForegroundTokens;
|
|
43
48
|
private readonly defaultBackgroundTokens;
|
|
49
|
+
private readonly dimTokens;
|
|
44
50
|
private readonly ownAppearance;
|
|
45
51
|
private resolvedColors;
|
|
46
52
|
constructor(fgColors: Record<Exclude<ThemeColor, OptionalThemeColor>, string | number> & Partial<Record<OptionalThemeColor, string | number>>, bgColors: Record<Exclude<ThemeBg, OptionalThemeBg>, string | number> & Partial<Record<OptionalThemeBg, string | number>>, mode: TerminalColorMode, options?: {
|
|
@@ -48,15 +54,18 @@ export declare class Theme {
|
|
|
48
54
|
sourcePath?: string;
|
|
49
55
|
sourceInfo?: SourceInfo;
|
|
50
56
|
appearance?: ThemeAppearance;
|
|
57
|
+
/** Foreground tokens to render faint (SGR 2). */
|
|
58
|
+
dim?: readonly ThemeColor[];
|
|
51
59
|
});
|
|
52
60
|
/**
|
|
53
61
|
* The background the theme is designed for: declared in the theme JSON, detected from its colors,
|
|
54
|
-
* or, for themes without usable colors,
|
|
62
|
+
* or, for themes without usable colors, the terminal's appearance.
|
|
55
63
|
*/
|
|
56
64
|
get appearance(): ThemeAppearance;
|
|
57
65
|
/**
|
|
58
66
|
* Concrete colors for all tokens. Tokens set to "" (terminal default) use the terminal's reported
|
|
59
|
-
* default colors, or a guess based on `appearance` when the terminal did not report them.
|
|
67
|
+
* default colors, or a guess based on `appearance` when the terminal did not report them. Faint
|
|
68
|
+
* tokens are approximated by mixing their color toward the background.
|
|
60
69
|
*/
|
|
61
70
|
get colors(): Readonly<Record<ThemeToken, Color>>;
|
|
62
71
|
style(text: string, options: ThemeStyle): string;
|
|
@@ -68,6 +77,7 @@ export declare class Theme {
|
|
|
68
77
|
underline(text: string): string;
|
|
69
78
|
inverse(text: string): string;
|
|
70
79
|
strikethrough(text: string): string;
|
|
80
|
+
/** Opening escape sequence for a foreground token. Faint tokens include SGR 2, which `\x1b[22m` closes. */
|
|
71
81
|
getFgAnsi(color: ThemeColor): string;
|
|
72
82
|
getBgAnsi(color: ThemeBg): string;
|
|
73
83
|
getColorMode(): TerminalColorMode;
|
|
@@ -88,38 +98,22 @@ export declare function parseAutoThemeSetting(themeSetting: string | undefined):
|
|
|
88
98
|
darkTheme: string;
|
|
89
99
|
} | undefined;
|
|
90
100
|
export declare function resolveThemeSetting(themeSetting: string | undefined, terminalTheme: TerminalTheme): string | undefined;
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
timeoutMs: number;
|
|
108
|
-
}): Promise<TerminalTheme | undefined>;
|
|
109
|
-
}
|
|
110
|
-
export interface TerminalBackgroundThemeDetectionOptions extends TerminalThemeDetectionOptions {
|
|
111
|
-
ui: TerminalBackgroundThemeDetector;
|
|
112
|
-
timeoutMs: number;
|
|
113
|
-
}
|
|
114
|
-
export interface TerminalAutoThemeDetectionOptions extends TerminalThemeDetectionOptions {
|
|
115
|
-
ui: TerminalAutoThemeDetector;
|
|
116
|
-
timeoutMs: number;
|
|
117
|
-
}
|
|
118
|
-
export declare function getThemeForRgbColor(rgb: RgbColor): TerminalTheme;
|
|
119
|
-
export declare function detectTerminalBackgroundFromEnv(options?: TerminalThemeDetectionOptions): TerminalThemeDetection;
|
|
120
|
-
export declare function detectTerminalBackgroundTheme({ ui, timeoutMs, env }: TerminalBackgroundThemeDetectionOptions): Promise<TerminalThemeDetection>;
|
|
121
|
-
export declare function detectTerminalThemeForAuto({ ui, timeoutMs, env }: TerminalAutoThemeDetectionOptions): Promise<TerminalTheme>;
|
|
122
|
-
export declare function getDefaultTheme(): string;
|
|
101
|
+
/**
|
|
102
|
+
* Dark or light from the `COLORFGBG` environment variable some terminals set, or undefined without a
|
|
103
|
+
* usable background index. The value is `fg;bg` or `fg;xpm;bg` (rxvt), where a field is an ANSI color
|
|
104
|
+
* index or `default` when the color is not in the palette. The index refers to the terminal's own palette,
|
|
105
|
+
* whose colors are unknown here, so it is classified by index like Vim does: 0-6 and 8 (bright black, e.g.
|
|
106
|
+
* Solarized Dark's background) are dark, 7 and 9-15 are light.
|
|
107
|
+
*/
|
|
108
|
+
export declare function detectColorFgBgTheme(env?: NodeJS.ProcessEnv): TerminalTheme | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* Whether the terminal is dark or light. The background it renders decides, classified the same way the
|
|
111
|
+
* system theme does. Without a reported background: the terminal's light/dark report, then COLORFGBG,
|
|
112
|
+
* then dark.
|
|
113
|
+
*/
|
|
114
|
+
export declare function detectTerminalTheme(colors?: TerminalColors, reportedScheme?: TerminalTheme, env?: NodeJS.ProcessEnv): TerminalTheme;
|
|
115
|
+
/** Whether the terminal is dark or light, from everything it reported so far. See `detectTerminalTheme()`. */
|
|
116
|
+
export declare function getTerminalTheme(): TerminalTheme;
|
|
123
117
|
export declare const theme: Theme;
|
|
124
118
|
export declare function setRegisteredThemes(themes: Theme[]): void;
|
|
125
119
|
export declare function initTheme(themeName?: string, enableWatcher?: boolean): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/theme/theme.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAEN,KAAK,KAAK,EAIV,KAAK,WAAW,EAIhB,KAAK,aAAa,EAElB,KAAK,QAAQ,EAEb,KAAK,eAAe,EACpB,KAAK,iBAAiB,EAEtB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAS/D,iGAAiG;AACjG,OAAO,KAAK,EAAiC,kB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AC,MAAM,EAAE,MAAM,CAAC,CAGjF;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAExD;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG;IACzD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB,CAyBA;AAiDD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAmBnE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAkExE;AAED,wBAAgB,gBAAgB,IAAI,aAAa,CAqChD;AAED,wBAAgB,kBAAkB,IAAI,eAAe,CAQpD;AAED,wBAAgB,cAAc,IAAI,WAAW,CAK5C;AAED,wBAAgB,oBAAoB,IAAI,iBAAiB,CAQxD","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\tcolorToRgb,\n\ttype EditorTheme,\n\tforegroundAnsi,\n\tgetTerminalColorMode,\n\tindexedColor,\n\ttype MarkdownTheme,\n\tparseColor,\n\ttype RgbColor,\n\trgbColor,\n\ttype SelectListTheme,\n\ttype SettingsListTheme,\n\tstyleTextWithAnsi,\n\ttype TerminalColorMode,\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\";\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(\"#\") || /^oklch\\(/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\ninterface TerminalDefaultColors {\n\tforeground?: Color;\n\tbackground?: Color;\n}\n\n// Replaced (never mutated) on update, so themes can cache resolved colors by identity.\nlet terminalDefaultColors: TerminalDefaultColors = {};\n\n/** Record the terminal's reported default colors. Themes use them for tokens set to \"\" (terminal default). */\nexport function setTerminalDefaultColors(colors: { foreground?: RgbColor; background?: RgbColor }): void {\n\tconst toColor = (rgb: RgbColor | undefined) => rgb && rgbColor(rgb.r, rgb.g, rgb.b);\n\tterminalDefaultColors = { foreground: toColor(colors.foreground), background: toColor(colors.background) };\n}\n\n/** Assumed terminal default colors when the terminal does not report them. */\nconst GUESSED_DEFAULT_COLORS: Record<ThemeAppearance, Required<TerminalDefaultColors>> = {\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\tprivate readonly ownAppearance: ThemeAppearance | undefined;\n\tprivate resolvedColors: { terminal: TerminalDefaultColors; 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: { name?: string; sourcePath?: string; sourceInfo?: SourceInfo; appearance?: ThemeAppearance } = {},\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\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, taken from the terminal background.\n\t */\n\tget appearance(): ThemeAppearance {\n\t\tif (this.ownAppearance) return this.ownAppearance;\n\t\tconst background = terminalDefaultColors.background;\n\t\treturn background ? getThemeForRgbColor(colorToRgb(background)) : \"dark\";\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.\n\t */\n\tget colors(): Readonly<Record<ThemeToken, Color>> {\n\t\tconst terminal = terminalDefaultColors;\n\t\tif (this.resolvedColors?.terminal !== terminal) {\n\t\t\tconst guess = GUESSED_DEFAULT_COLORS[this.appearance];\n\t\t\tconst colors = { ...this.concreteColors };\n\t\t\tfor (const token of this.defaultForegroundTokens) colors[token] = terminal.foreground ?? guess.foreground;\n\t\t\tfor (const token of this.defaultBackgroundTokens) colors[token] = terminal.background ?? guess.background;\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\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\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\tgetFgAnsi(color: ThemeColor): string {\n\t\treturn this.tokenAnsi(this.fgAnsi, color);\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\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\treturn result.sort((a, b) => a.name.localeCompare(b.name));\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 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: Record<ThemeColor, string | number> = {} as Record<ThemeColor, string | number>;\n\tconst bgColors: Record<ThemeBg, string | number> = {} as Record<ThemeBg, string | number>;\n\tconst bgColorKeys: Set<string> = new Set([\n\t\t\"selectedBg\",\n\t\t\"searchMatchBg\",\n\t\t\"userMessageBg\",\n\t\t\"customMessageBg\",\n\t\t\"toolPendingBg\",\n\t\t\"toolSuccessBg\",\n\t\t\"toolErrorBg\",\n\t]);\n\tfor (const [key, value] of Object.entries(resolvedColors)) {\n\t\tif (bgColorKeys.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 new Theme(fgColors, bgColors, colorMode, {\n\t\tname: themeJson.name,\n\t\tsourcePath,\n\t\tappearance: themeJson.appearance,\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\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\nexport interface TerminalThemeDetection {\n\ttheme: TerminalTheme;\n\tsource: \"terminal background\" | \"COLORFGBG\" | \"fallback\";\n\tdetail: string;\n\tconfidence: \"high\" | \"low\";\n}\n\nexport interface TerminalThemeDetectionOptions {\n\tenv?: NodeJS.ProcessEnv;\n}\n\nexport interface TerminalBackgroundThemeDetector {\n\tqueryTerminalBackgroundColor({ timeoutMs }: { timeoutMs: number }): Promise<RgbColor | undefined>;\n}\n\nexport interface TerminalAutoThemeDetector extends TerminalBackgroundThemeDetector {\n\tqueryTerminalColorScheme?({ timeoutMs }: { timeoutMs: number }): Promise<TerminalTheme | undefined>;\n}\n\nexport interface TerminalBackgroundThemeDetectionOptions extends TerminalThemeDetectionOptions {\n\tui: TerminalBackgroundThemeDetector;\n\ttimeoutMs: number;\n}\n\nexport interface TerminalAutoThemeDetectionOptions extends TerminalThemeDetectionOptions {\n\tui: TerminalAutoThemeDetector;\n\ttimeoutMs: number;\n}\n\nfunction getColorFgBgBackgroundIndex(colorfgbg: string): number | undefined {\n\tconst parts = colorfgbg.split(\";\");\n\tfor (let i = parts.length - 1; i >= 0; i--) {\n\t\tconst bg = parseInt(parts[i].trim(), 10);\n\t\tif (Number.isInteger(bg) && bg >= 0 && bg <= 255) {\n\t\t\treturn bg;\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction getRgbColorLuminance({ r, g, b }: RgbColor): number {\n\tconst toLinear = (channel: number) => {\n\t\tconst value = channel / 255;\n\t\treturn value <= 0.03928 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;\n\t};\n\treturn 0.2126 * toLinear(r) + 0.7152 * toLinear(g) + 0.0722 * toLinear(b);\n}\n\nfunction getAnsiColorLuminance(index: number): number {\n\treturn getRgbColorLuminance(colorToRgb(indexedColor(index)));\n}\n\nexport function getThemeForRgbColor(rgb: RgbColor): TerminalTheme {\n\treturn getRgbColorLuminance(rgb) >= 0.5 ? \"light\" : \"dark\";\n}\n\nexport function detectTerminalBackgroundFromEnv(options: TerminalThemeDetectionOptions = {}): TerminalThemeDetection {\n\tconst env = options.env ?? process.env;\n\tconst colorfgbg = env.COLORFGBG || \"\";\n\tconst bg = getColorFgBgBackgroundIndex(colorfgbg);\n\tif (bg !== undefined) {\n\t\treturn {\n\t\t\ttheme: getAnsiColorLuminance(bg) >= 0.5 ? \"light\" : \"dark\",\n\t\t\tsource: \"COLORFGBG\",\n\t\t\tdetail: `background color index ${bg}`,\n\t\t\tconfidence: \"high\",\n\t\t};\n\t}\n\n\treturn {\n\t\ttheme: \"dark\",\n\t\tsource: \"fallback\",\n\t\tdetail: \"no terminal background hint found\",\n\t\tconfidence: \"low\",\n\t};\n}\n\nexport async function detectTerminalBackgroundTheme({\n\tui,\n\ttimeoutMs,\n\tenv,\n}: TerminalBackgroundThemeDetectionOptions): Promise<TerminalThemeDetection> {\n\ttry {\n\t\tconst rgb = await ui.queryTerminalBackgroundColor({ timeoutMs });\n\t\tif (rgb) {\n\t\t\treturn {\n\t\t\t\ttheme: getThemeForRgbColor(rgb),\n\t\t\t\tsource: \"terminal background\",\n\t\t\t\tdetail: `OSC 11 background rgb(${rgb.r}, ${rgb.g}, ${rgb.b})`,\n\t\t\t\tconfidence: \"high\",\n\t\t\t};\n\t\t}\n\t} catch {\n\t\t// Fall back to environment-based detection when the terminal query fails.\n\t}\n\n\treturn detectTerminalBackgroundFromEnv({ env });\n}\n\nexport async function detectTerminalThemeForAuto({\n\tui,\n\ttimeoutMs,\n\tenv,\n}: TerminalAutoThemeDetectionOptions): Promise<TerminalTheme> {\n\tlet colorSchemePromise: Promise<TerminalTheme | undefined> | undefined;\n\ttry {\n\t\tcolorSchemePromise = ui.queryTerminalColorScheme?.({ timeoutMs });\n\t} catch {\n\t\t// Fall back to OSC 11 / COLORFGBG detection when starting the color-scheme query fails.\n\t}\n\tconst backgroundThemePromise = detectTerminalBackgroundTheme({ ui, timeoutMs, env });\n\n\ttry {\n\t\tconst colorScheme = await colorSchemePromise;\n\t\tif (colorScheme) return colorScheme;\n\t} catch {\n\t\t// Fall back to the concurrently queried OSC 11 / COLORFGBG detection.\n\t}\n\treturn (await backgroundThemePromise).theme;\n}\n\nexport function getDefaultTheme(): string {\n\treturn detectTerminalBackgroundFromEnv().theme;\n}\n\n// ============================================================================\n// Global Theme Instance\n// ============================================================================\n\n// Use globalThis to share theme across module loaders (tsx + 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 (tsx, 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 ?? getDefaultTheme();\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 dark theme silently\n\t\tcurrentThemeName = \"dark\";\n\t\tsetGlobalTheme(loadTheme(\"dark\"));\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 dark theme\n\t\tcurrentThemeName = \"dark\";\n\t\tsetGlobalTheme(loadTheme(\"dark\"));\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 (!currentThemeName || currentThemeName === \"dark\" || currentThemeName === \"light\") {\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 ?? getDefaultTheme()).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 ?? getDefaultTheme()).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 ?? getDefaultTheme();\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, rgb() and oklch() values directly.\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\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.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/theme/theme.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAEN,KAAK,KAAK,EAGV,KAAK,WAAW,EAIhB,KAAK,aAAa,EAKlB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EAEtB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAM/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAMtD,iGAAiG;AACjG,OAAO,KAAK,EAAiC,kBAAkB,IAAI,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEtG,YAAY,EAAE,kBAAkB,IAAI,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEvE,MAAM,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,SAAS,CAAC;AAI7E;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,kBAAkB,GAAG,IAAI,CAEzE;AAED,MAAM,MAAM,UAAU,GACnB,QAAQ,GACR,QAAQ,GACR,cAAc,GACd,aAAa,GACb,SAAS,GACT,OAAO,GACP,SAAS,GACT,OAAO,GACP,KAAK,GACL,MAAM,GACN,cAAc,GACd,gBAAgB,GAChB,gBAAgB,GAChB,iBAAiB,GACjB,iBAAiB,GACjB,mBAAmB,GACnB,oBAAoB,GACpB,WAAW,GACX,YAAY,GACZ,WAAW,GACX,QAAQ,GACR,WAAW,GACX,QAAQ,GACR,aAAa,GACb,mBAAmB,GACnB,SAAS,GACT,eAAe,GAC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