mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 21:03:19 +00:00
Syntax highlighting improvements
- Fix cli-highlight import (use static import instead of dynamic require) - Add syntax highlighting to read/write tool output - Update dark/light themes with VS Code default syntax colors - Add highlightCode and getLanguageFromPath exports - Upgrade @google/genai to 1.34.0 for IMAGE_RECITATION/IMAGE_OTHER FinishReason - Add AGENTS.md rule: never downgrade code to fix type errors from outdated deps
This commit is contained in:
parent
d2088f7789
commit
1a944f50f9
7 changed files with 133 additions and 39 deletions
|
|
@ -51,15 +51,15 @@
|
|||
"toolDiffRemoved": "red",
|
||||
"toolDiffContext": "gray",
|
||||
|
||||
"syntaxComment": "gray",
|
||||
"syntaxKeyword": "cyan",
|
||||
"syntaxFunction": "blue",
|
||||
"syntaxVariable": "",
|
||||
"syntaxString": "green",
|
||||
"syntaxNumber": "yellow",
|
||||
"syntaxType": "cyan",
|
||||
"syntaxOperator": "",
|
||||
"syntaxPunctuation": "gray",
|
||||
"syntaxComment": "#6A9955",
|
||||
"syntaxKeyword": "#569CD6",
|
||||
"syntaxFunction": "#DCDCAA",
|
||||
"syntaxVariable": "#9CDCFE",
|
||||
"syntaxString": "#CE9178",
|
||||
"syntaxNumber": "#B5CEA8",
|
||||
"syntaxType": "#4EC9B0",
|
||||
"syntaxOperator": "#D4D4D4",
|
||||
"syntaxPunctuation": "#D4D4D4",
|
||||
|
||||
"thinkingOff": "darkGray",
|
||||
"thinkingMinimal": "#6e6e6e",
|
||||
|
|
|
|||
|
|
@ -50,15 +50,15 @@
|
|||
"toolDiffRemoved": "red",
|
||||
"toolDiffContext": "mediumGray",
|
||||
|
||||
"syntaxComment": "mediumGray",
|
||||
"syntaxKeyword": "teal",
|
||||
"syntaxFunction": "blue",
|
||||
"syntaxVariable": "",
|
||||
"syntaxString": "green",
|
||||
"syntaxNumber": "yellow",
|
||||
"syntaxType": "teal",
|
||||
"syntaxOperator": "",
|
||||
"syntaxPunctuation": "mediumGray",
|
||||
"syntaxComment": "#008000",
|
||||
"syntaxKeyword": "#0000FF",
|
||||
"syntaxFunction": "#795E26",
|
||||
"syntaxVariable": "#001080",
|
||||
"syntaxString": "#A31515",
|
||||
"syntaxNumber": "#098658",
|
||||
"syntaxType": "#267F99",
|
||||
"syntaxOperator": "#000000",
|
||||
"syntaxPunctuation": "#000000",
|
||||
|
||||
"thinkingOff": "lightGray",
|
||||
"thinkingMinimal": "#9e9e9e",
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import * as fs from "node:fs";
|
||||
import { createRequire } from "node:module";
|
||||
import * as path from "node:path";
|
||||
import type { EditorTheme, MarkdownTheme, SelectListTheme } from "@mariozechner/pi-tui";
|
||||
import { type Static, Type } from "@sinclair/typebox";
|
||||
import { TypeCompiler } from "@sinclair/typebox/compiler";
|
||||
import chalk from "chalk";
|
||||
import { highlight } from "cli-highlight";
|
||||
import { getCustomThemesDir, getThemesDir } from "../../../config.js";
|
||||
|
||||
// ============================================================================
|
||||
|
|
@ -664,17 +664,94 @@ function getCliHighlightTheme(t: Theme): CliHighlightTheme {
|
|||
return cachedCliHighlightTheme;
|
||||
}
|
||||
|
||||
function requireCliHighlight(): { highlight: (code: string, opts?: any) => string } {
|
||||
/**
|
||||
* Highlight code with syntax coloring based on file extension or language.
|
||||
* Returns array of highlighted lines.
|
||||
*/
|
||||
export function highlightCode(code: string, lang?: string): string[] {
|
||||
const opts = {
|
||||
language: lang,
|
||||
ignoreIllegals: true,
|
||||
theme: getCliHighlightTheme(theme),
|
||||
};
|
||||
try {
|
||||
const require = createRequire(import.meta.url);
|
||||
return require("cli-highlight");
|
||||
return highlight(code, opts).split("\n");
|
||||
} catch {
|
||||
return {
|
||||
highlight: (code: string) => code,
|
||||
};
|
||||
return code.split("\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get language identifier from file path extension.
|
||||
*/
|
||||
export function getLanguageFromPath(filePath: string): string | undefined {
|
||||
const ext = filePath.split(".").pop()?.toLowerCase();
|
||||
if (!ext) return undefined;
|
||||
|
||||
const extToLang: Record<string, string> = {
|
||||
ts: "typescript",
|
||||
tsx: "typescript",
|
||||
js: "javascript",
|
||||
jsx: "javascript",
|
||||
mjs: "javascript",
|
||||
cjs: "javascript",
|
||||
py: "python",
|
||||
rb: "ruby",
|
||||
rs: "rust",
|
||||
go: "go",
|
||||
java: "java",
|
||||
kt: "kotlin",
|
||||
swift: "swift",
|
||||
c: "c",
|
||||
h: "c",
|
||||
cpp: "cpp",
|
||||
cc: "cpp",
|
||||
cxx: "cpp",
|
||||
hpp: "cpp",
|
||||
cs: "csharp",
|
||||
php: "php",
|
||||
sh: "bash",
|
||||
bash: "bash",
|
||||
zsh: "bash",
|
||||
fish: "fish",
|
||||
ps1: "powershell",
|
||||
sql: "sql",
|
||||
html: "html",
|
||||
htm: "html",
|
||||
css: "css",
|
||||
scss: "scss",
|
||||
sass: "sass",
|
||||
less: "less",
|
||||
json: "json",
|
||||
yaml: "yaml",
|
||||
yml: "yaml",
|
||||
toml: "toml",
|
||||
xml: "xml",
|
||||
md: "markdown",
|
||||
markdown: "markdown",
|
||||
dockerfile: "dockerfile",
|
||||
makefile: "makefile",
|
||||
cmake: "cmake",
|
||||
lua: "lua",
|
||||
perl: "perl",
|
||||
r: "r",
|
||||
scala: "scala",
|
||||
clj: "clojure",
|
||||
ex: "elixir",
|
||||
exs: "elixir",
|
||||
erl: "erlang",
|
||||
hs: "haskell",
|
||||
ml: "ocaml",
|
||||
vim: "vim",
|
||||
graphql: "graphql",
|
||||
proto: "protobuf",
|
||||
tf: "hcl",
|
||||
hcl: "hcl",
|
||||
};
|
||||
|
||||
return extToLang[ext];
|
||||
}
|
||||
|
||||
export function getMarkdownTheme(): MarkdownTheme {
|
||||
return {
|
||||
heading: (text: string) => theme.fg("mdHeading", text),
|
||||
|
|
@ -692,8 +769,7 @@ export function getMarkdownTheme(): MarkdownTheme {
|
|||
underline: (text: string) => theme.underline(text),
|
||||
strikethrough: (text: string) => chalk.strikethrough(text),
|
||||
highlightCode: (code: string, lang?: string): string[] => {
|
||||
const { highlight } = requireCliHighlight();
|
||||
const opts: any = {
|
||||
const opts = {
|
||||
language: lang,
|
||||
ignoreIllegals: true,
|
||||
theme: getCliHighlightTheme(theme),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue