@hncode/hncode 0.7.2 → 0.7.4
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/package.json +1 -1
- package/src/agent.js +10 -5
- package/src/banner.js +222 -0
- package/src/colors.js +50 -1
- package/src/config.js +46 -2
- package/src/highlight.js +432 -0
- package/src/i18n.js +5 -5
- package/src/registry-browser.js +1 -1
- package/src/settings-schema.js +4 -0
- package/src/team-panel.js +1 -1
- package/src/term.js +971 -764
- package/src/tools/edit.js +63 -12
- package/src/tools/memory.js +92 -80
- package/src/tui.js +22214 -21521
- package/src/wordlist.js +6 -0
package/src/highlight.js
ADDED
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
// Syntax highlighting for the code a session shows: a diff, a Read result, a fenced block.
|
|
2
|
+
//
|
|
3
|
+
// NO DEPENDENCY, ONE TOKENIZER. A highlighter per language would be fifty parsers to keep correct; what makes a
|
|
4
|
+
// listing readable is not its grammar but five things every language has — strings, comments, numbers, keywords
|
|
5
|
+
// and calls — and those can be found with one scanner plus a per-language WORD LIST. Where a language has a shape
|
|
6
|
+
// the scanner cannot know (a template literal spanning lines, a regex literal) it is handled by a small flag on
|
|
7
|
+
// its entry rather than by code of its own.
|
|
8
|
+
//
|
|
9
|
+
// The colours are the Islands Dark palette, the same source as C's diff colours.
|
|
10
|
+
import { C } from './colors.js';
|
|
11
|
+
|
|
12
|
+
/** Words that read as a keyword, per family. Kept as strings so one set can serve several languages. */
|
|
13
|
+
const JS_KEYWORDS = [
|
|
14
|
+
'async', 'await', 'break', 'case', 'catch', 'class', 'const', 'continue', 'debugger', 'default', 'delete', 'do',
|
|
15
|
+
'else', 'export', 'extends', 'finally', 'for', 'from', 'function', 'get', 'if', 'import', 'in', 'instanceof',
|
|
16
|
+
'let', 'new', 'of', 'return', 'set', 'static', 'super', 'switch', 'this', 'throw', 'try', 'typeof', 'var',
|
|
17
|
+
'void', 'while', 'with', 'yield', 'as', 'implements', 'interface', 'type', 'enum', 'declare', 'namespace',
|
|
18
|
+
'readonly', 'private', 'public', 'protected', 'abstract', 'satisfies', 'keyof', 'infer', 'is',
|
|
19
|
+
];
|
|
20
|
+
const JS_LITERALS = ['true', 'false', 'null', 'undefined', 'NaN', 'Infinity'];
|
|
21
|
+
|
|
22
|
+
const PY_KEYWORDS = [
|
|
23
|
+
'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except',
|
|
24
|
+
'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass',
|
|
25
|
+
'raise', 'return', 'try', 'while', 'with', 'yield', 'match', 'case',
|
|
26
|
+
];
|
|
27
|
+
const PY_LITERALS = ['True', 'False', 'None', 'NotImplemented', 'Ellipsis'];
|
|
28
|
+
|
|
29
|
+
const JAVA_LIKE = [
|
|
30
|
+
'abstract', 'assert', 'break', 'case', 'catch', 'class', 'const', 'continue', 'default', 'do', 'else', 'enum',
|
|
31
|
+
'extends', 'final', 'finally', 'for', 'goto', 'if', 'implements', 'import', 'instanceof', 'interface', 'native',
|
|
32
|
+
'new', 'package', 'private', 'protected', 'public', 'return', 'static', 'strictfp', 'super', 'switch',
|
|
33
|
+
'synchronized', 'this', 'throw', 'throws', 'transient', 'try', 'volatile', 'while', 'record', 'sealed',
|
|
34
|
+
'permits', 'var', 'yield',
|
|
35
|
+
];
|
|
36
|
+
const JAVA_LITERALS = ['true', 'false', 'null'];
|
|
37
|
+
|
|
38
|
+
const C_LIKE = [
|
|
39
|
+
'auto', 'break', 'case', 'char', 'const', 'continue', 'default', 'do', 'double', 'else', 'enum', 'extern',
|
|
40
|
+
'float', 'for', 'goto', 'if', 'inline', 'int', 'long', 'register', 'restrict', 'return', 'short', 'signed',
|
|
41
|
+
'sizeof', 'static', 'struct', 'switch', 'typedef', 'union', 'unsigned', 'void', 'volatile', 'while', 'bool',
|
|
42
|
+
'class', 'namespace', 'template', 'typename', 'public', 'private', 'protected', 'virtual', 'override', 'constexpr',
|
|
43
|
+
'using', 'nullptr', 'auto', 'concept', 'requires', 'co_await', 'co_return', 'co_yield',
|
|
44
|
+
];
|
|
45
|
+
const C_LITERALS = ['true', 'false', 'NULL', 'nullptr'];
|
|
46
|
+
|
|
47
|
+
const RUST_KEYWORDS = [
|
|
48
|
+
'as', 'async', 'await', 'break', 'const', 'continue', 'crate', 'dyn', 'else', 'enum', 'extern', 'fn', 'for',
|
|
49
|
+
'if', 'impl', 'in', 'let', 'loop', 'match', 'mod', 'move', 'mut', 'pub', 'ref', 'return', 'self', 'Self', 'static',
|
|
50
|
+
'struct', 'super', 'trait', 'type', 'unsafe', 'use', 'where', 'while', 'macro_rules',
|
|
51
|
+
];
|
|
52
|
+
const RUST_LITERALS = ['true', 'false', 'None', 'Some', 'Ok', 'Err'];
|
|
53
|
+
|
|
54
|
+
const GO_KEYWORDS = [
|
|
55
|
+
'break', 'case', 'chan', 'const', 'continue', 'default', 'defer', 'else', 'fallthrough', 'for', 'func', 'go',
|
|
56
|
+
'goto', 'if', 'import', 'interface', 'map', 'package', 'range', 'return', 'select', 'struct', 'switch', 'type',
|
|
57
|
+
'var',
|
|
58
|
+
];
|
|
59
|
+
const GO_LITERALS = ['true', 'false', 'nil', 'iota'];
|
|
60
|
+
|
|
61
|
+
const SHELL_KEYWORDS = [
|
|
62
|
+
'if', 'then', 'else', 'elif', 'fi', 'for', 'while', 'until', 'do', 'done', 'case', 'esac', 'function', 'in',
|
|
63
|
+
'return', 'local', 'export', 'readonly', 'declare', 'unset', 'shift', 'source', 'alias', 'command', 'eval',
|
|
64
|
+
'exec', 'exit', 'trap', 'set', 'let',
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
const SQL_KEYWORDS = [
|
|
68
|
+
'SELECT', 'FROM', 'WHERE', 'GROUP', 'BY', 'ORDER', 'HAVING', 'LIMIT', 'OFFSET', 'INSERT', 'INTO', 'VALUES',
|
|
69
|
+
'UPDATE', 'SET', 'DELETE', 'CREATE', 'TABLE', 'INDEX', 'VIEW', 'ALTER', 'DROP', 'TRUNCATE', 'JOIN', 'INNER',
|
|
70
|
+
'LEFT', 'RIGHT', 'FULL', 'OUTER', 'ON', 'AS', 'AND', 'OR', 'NOT', 'NULL', 'IS', 'IN', 'EXISTS', 'BETWEEN',
|
|
71
|
+
'LIKE', 'DISTINCT', 'UNION', 'ALL', 'CASE', 'WHEN', 'THEN', 'ELSE', 'END', 'PRIMARY', 'KEY', 'FOREIGN',
|
|
72
|
+
'REFERENCES', 'DEFAULT', 'CASCADE', 'WITH', 'RETURNING',
|
|
73
|
+
];
|
|
74
|
+
const SQL_LITERALS = ['NULL', 'TRUE', 'FALSE'];
|
|
75
|
+
|
|
76
|
+
const RUBY_KEYWORDS = [
|
|
77
|
+
'alias', 'begin', 'break', 'case', 'class', 'def', 'defined', 'do', 'else', 'elsif', 'end', 'ensure', 'for',
|
|
78
|
+
'if', 'in', 'module', 'next', 'not', 'or', 'and', 'redo', 'rescue', 'retry', 'return', 'self', 'super', 'then',
|
|
79
|
+
'undef', 'unless', 'until', 'when', 'while', 'yield', 'require', 'include', 'extend', 'attr_accessor',
|
|
80
|
+
];
|
|
81
|
+
const RUBY_LITERALS = ['true', 'false', 'nil', '__FILE__', '__LINE__'];
|
|
82
|
+
|
|
83
|
+
const PHP_KEYWORDS = [
|
|
84
|
+
'abstract', 'and', 'array', 'as', 'break', 'case', 'catch', 'class', 'clone', 'const', 'continue', 'declare',
|
|
85
|
+
'default', 'do', 'echo', 'else', 'elseif', 'empty', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch',
|
|
86
|
+
'endwhile', 'extends', 'final', 'finally', 'fn', 'for', 'foreach', 'function', 'global', 'goto', 'if',
|
|
87
|
+
'implements', 'include', 'instanceof', 'insteadof', 'interface', 'isset', 'list', 'match', 'namespace', 'new',
|
|
88
|
+
'or', 'print', 'private', 'protected', 'public', 'require', 'return', 'static', 'switch', 'throw', 'trait',
|
|
89
|
+
'try', 'unset', 'use', 'var', 'while', 'xor', 'yield', 'namespace',
|
|
90
|
+
];
|
|
91
|
+
const PHP_LITERALS = ['true', 'false', 'null', 'TRUE', 'FALSE', 'NULL'];
|
|
92
|
+
|
|
93
|
+
const KOTLIN_KEYWORDS = [
|
|
94
|
+
'as', 'break', 'by', 'catch', 'class', 'continue', 'do', 'else', 'false', 'finally', 'for', 'fun', 'if', 'in',
|
|
95
|
+
'interface', 'is', 'null', 'object', 'package', 'return', 'super', 'this', 'throw', 'true', 'try', 'typealias',
|
|
96
|
+
'val', 'var', 'when', 'while', 'suspend', 'data', 'sealed', 'companion', 'inline', 'reified',
|
|
97
|
+
];
|
|
98
|
+
|
|
99
|
+
const CS_KEYWORDS = [
|
|
100
|
+
'abstract', 'as', 'base', 'break', 'case', 'catch', 'checked', 'class', 'const', 'continue', 'default', 'delegate',
|
|
101
|
+
'do', 'else', 'enum', 'event', 'explicit', 'extern', 'finally', 'fixed', 'for', 'foreach', 'goto', 'if',
|
|
102
|
+
'implicit', 'in', 'interface', 'internal', 'is', 'lock', 'namespace', 'new', 'operator', 'out', 'override',
|
|
103
|
+
'params', 'private', 'protected', 'public', 'readonly', 'ref', 'return', 'sealed', 'sizeof', 'stackalloc',
|
|
104
|
+
'static', 'struct', 'switch', 'this', 'throw', 'try', 'typeof', 'unchecked', 'unsafe', 'using', 'virtual',
|
|
105
|
+
'volatile', 'while', 'async', 'await', 'var', 'record', 'init',
|
|
106
|
+
];
|
|
107
|
+
const CS_LITERALS = ['true', 'false', 'null'];
|
|
108
|
+
|
|
109
|
+
const SWIFT_KEYWORDS = [
|
|
110
|
+
'associatedtype', 'class', 'deinit', 'enum', 'extension', 'fileprivate', 'func', 'import', 'init', 'inout',
|
|
111
|
+
'internal', 'let', 'open', 'operator', 'private', 'protocol', 'public', 'rethrows', 'static', 'struct',
|
|
112
|
+
'subscript', 'typealias', 'var', 'break', 'case', 'continue', 'default', 'defer', 'do', 'else', 'fallthrough',
|
|
113
|
+
'for', 'guard', 'if', 'in', 'repeat', 'return', 'switch', 'where', 'while', 'as', 'catch', 'is', 'throw',
|
|
114
|
+
'throws', 'try', 'async', 'await', 'some', 'any',
|
|
115
|
+
];
|
|
116
|
+
const SWIFT_LITERALS = ['true', 'false', 'nil', 'self', 'Self'];
|
|
117
|
+
|
|
118
|
+
const SCALA_KEYWORDS = [
|
|
119
|
+
'abstract', 'case', 'catch', 'class', 'def', 'do', 'else', 'enum', 'extends', 'final', 'finally', 'for',
|
|
120
|
+
'forSome', 'given', 'if', 'implicit', 'import', 'lazy', 'match', 'new', 'object', 'override', 'package',
|
|
121
|
+
'private', 'protected', 'return', 'sealed', 'super', 'then', 'this', 'throw', 'trait', 'try', 'type', 'val',
|
|
122
|
+
'var', 'while', 'with', 'yield', 'using', 'end',
|
|
123
|
+
];
|
|
124
|
+
const SCALA_LITERALS = ['true', 'false', 'null', 'None', 'Some'];
|
|
125
|
+
|
|
126
|
+
const DART_KEYWORDS = [
|
|
127
|
+
'abstract', 'as', 'assert', 'async', 'await', 'break', 'case', 'catch', 'class', 'const', 'continue', 'covariant',
|
|
128
|
+
'default', 'deferred', 'do', 'dynamic', 'else', 'enum', 'export', 'extends', 'extension', 'external', 'factory',
|
|
129
|
+
'false', 'final', 'finally', 'for', 'Function', 'get', 'hide', 'if', 'implements', 'import', 'in', 'interface',
|
|
130
|
+
'is', 'late', 'library', 'mixin', 'new', 'null', 'on', 'operator', 'part', 'required', 'rethrow', 'return',
|
|
131
|
+
'sealed', 'set', 'show', 'static', 'super', 'switch', 'sync', 'this', 'throw', 'true', 'try', 'typedef', 'var',
|
|
132
|
+
'void', 'while', 'with', 'yield',
|
|
133
|
+
];
|
|
134
|
+
|
|
135
|
+
const LUA_KEYWORDS = [
|
|
136
|
+
'and', 'break', 'do', 'else', 'elseif', 'end', 'false', 'for', 'function', 'goto', 'if', 'in', 'local', 'nil',
|
|
137
|
+
'not', 'or', 'repeat', 'return', 'then', 'true', 'until', 'while',
|
|
138
|
+
];
|
|
139
|
+
|
|
140
|
+
const ELIXIR_KEYWORDS = [
|
|
141
|
+
'def', 'defmodule', 'defp', 'defmacro', 'defstruct', 'do', 'end', 'case', 'cond', 'if', 'unless', 'when', 'fn',
|
|
142
|
+
'with', 'for', 'receive', 'after', 'try', 'catch', 'rescue', 'raise', 'import', 'alias', 'use', 'require',
|
|
143
|
+
'nil', 'true', 'false',
|
|
144
|
+
];
|
|
145
|
+
|
|
146
|
+
const HASKELL_KEYWORDS = [
|
|
147
|
+
'case', 'class', 'data', 'default', 'deriving', 'do', 'else', 'if', 'import', 'in', 'infix', 'instance', 'let',
|
|
148
|
+
'module', 'newtype', 'of', 'then', 'type', 'where', 'qualified', 'as', 'hiding',
|
|
149
|
+
];
|
|
150
|
+
const HASKELL_LITERALS = ['True', 'False', 'Nothing', 'Just'];
|
|
151
|
+
|
|
152
|
+
const PERL_KEYWORDS = [
|
|
153
|
+
'my', 'our', 'local', 'sub', 'package', 'use', 'require', 'if', 'elsif', 'else', 'unless', 'while', 'until',
|
|
154
|
+
'for', 'foreach', 'do', 'last', 'next', 'redo', 'return', 'die', 'eval', 'print', 'say', 'chomp', 'split',
|
|
155
|
+
'join', 'push', 'pop', 'shift', 'unshift', 'keys', 'values', 'exists', 'delete', 'defined', 'ref', 'bless',
|
|
156
|
+
];
|
|
157
|
+
|
|
158
|
+
const R_KEYWORDS = [
|
|
159
|
+
'if', 'else', 'repeat', 'while', 'function', 'for', 'in', 'next', 'break', 'TRUE', 'FALSE', 'NULL', 'Inf',
|
|
160
|
+
'NaN', 'NA', 'library', 'require',
|
|
161
|
+
];
|
|
162
|
+
|
|
163
|
+
const JULIA_KEYWORDS = [
|
|
164
|
+
'baremodule', 'begin', 'break', 'catch', 'const', 'continue', 'do', 'else', 'elseif', 'end', 'export', 'finally',
|
|
165
|
+
'for', 'function', 'global', 'if', 'import', 'let', 'local', 'macro', 'module', 'quote', 'return', 'struct',
|
|
166
|
+
'try', 'using', 'while', 'mutable', 'abstract', 'primitive', 'where',
|
|
167
|
+
];
|
|
168
|
+
const JULIA_LITERALS = ['true', 'false', 'nothing', 'missing'];
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Extensions to a language entry.
|
|
172
|
+
*
|
|
173
|
+
* line the line-comment marker (`//`, `#`, `--`) or '' for none
|
|
174
|
+
* block [open, close] for a block comment, or null
|
|
175
|
+
* quotes the string delimiters this language uses
|
|
176
|
+
* triple whether `"""` / `'''` open a multi-line string
|
|
177
|
+
* words the keyword list
|
|
178
|
+
* literals the literal list (coloured like values, not like keywords)
|
|
179
|
+
* raw a prefix that starts an uninterpreted string (`r"` in Python, `` ` `` in Go)
|
|
180
|
+
* attr a line starting with this is a decorator or preprocessor line, coloured as one
|
|
181
|
+
*/
|
|
182
|
+
const LANGS = {
|
|
183
|
+
javascript: { line: '//', block: ['/*', '*/'], quotes: '\'"`', words: JS_KEYWORDS, literals: JS_LITERALS, regex: true },
|
|
184
|
+
typescript: { line: '//', block: ['/*', '*/'], quotes: '\'"`', words: JS_KEYWORDS, literals: JS_LITERALS, regex: true },
|
|
185
|
+
python: { line: '#', block: null, quotes: '\'"', triple: true, words: PY_KEYWORDS, literals: PY_LITERALS, raw: 'rbfRBF' },
|
|
186
|
+
java: { line: '//', block: ['/*', '*/'], quotes: '"\'', words: JAVA_LIKE, literals: JAVA_LITERALS, attr: '@' },
|
|
187
|
+
kotlin: { line: '//', block: ['/*', '*/'], quotes: '"\'', triple: true, words: KOTLIN_KEYWORDS, literals: [], attr: '@' },
|
|
188
|
+
scala: { line: '//', block: ['/*', '*/'], quotes: '"\'', triple: true, words: SCALA_KEYWORDS, literals: SCALA_LITERALS, attr: '@' },
|
|
189
|
+
csharp: { line: '//', block: ['/*', '*/'], quotes: '"\'', words: CS_KEYWORDS, literals: CS_LITERALS, attr: '#' },
|
|
190
|
+
swift: { line: '//', block: ['/*', '*/'], quotes: '"', triple: true, words: SWIFT_KEYWORDS, literals: SWIFT_LITERALS, attr: '@' },
|
|
191
|
+
c: { line: '//', block: ['/*', '*/'], quotes: '"\'', words: C_LIKE, literals: C_LITERALS, attr: '#' },
|
|
192
|
+
cpp: { line: '//', block: ['/*', '*/'], quotes: '"\'\'', words: C_LIKE, literals: C_LITERALS, attr: '#' },
|
|
193
|
+
rust: { line: '//', block: ['/*', '*/'], quotes: '"', words: RUST_KEYWORDS, literals: RUST_LITERALS, attr: '#' },
|
|
194
|
+
go: { line: '//', block: ['/*', '*/'], quotes: '"`\'', words: GO_KEYWORDS, literals: GO_LITERALS },
|
|
195
|
+
dart: { line: '//', block: ['/*', '*/'], quotes: '"\'\'', words: DART_KEYWORDS, literals: [], attr: '@' },
|
|
196
|
+
zig: { line: '//', block: null, quotes: '"', words: ['const', 'var', 'fn', 'pub', 'return', 'if', 'else', 'while', 'for', 'switch', 'struct', 'enum', 'union', 'error', 'try', 'catch', 'defer', 'comptime', 'inline', 'extern', 'export', 'test', 'orelse', 'unreachable', 'usingnamespace', 'asm', 'break', 'continue'], literals: ['true', 'false', 'null', 'undefined'], attr: '@' },
|
|
197
|
+
ruby: { line: '#', block: null, quotes: '"\'', words: RUBY_KEYWORDS, literals: RUBY_LITERALS, attr: '@' },
|
|
198
|
+
php: { line: '//', block: ['/*', '*/'], quotes: '"\'\'', words: PHP_KEYWORDS, literals: PHP_LITERALS, attr: '#' },
|
|
199
|
+
perl: { line: '#', block: null, quotes: '"\'\'', words: PERL_KEYWORDS, literals: [], raw: 'qr' },
|
|
200
|
+
lua: { line: '--', block: ['--[[', ']]'], quotes: '"\'\'', words: LUA_KEYWORDS, literals: [] },
|
|
201
|
+
elixir: { line: '#', block: null, quotes: '"\'', words: ELIXIR_KEYWORDS, literals: [], attr: '@' },
|
|
202
|
+
haskell: { line: '--', block: ['{-', '-}'], quotes: '"\'', words: HASKELL_KEYWORDS, literals: HASKELL_LITERALS },
|
|
203
|
+
ocaml: { line: '', block: ['(*', '*)'], quotes: '"\'', words: ['let', 'in', 'rec', 'and', 'match', 'with', 'type', 'module', 'open', 'fun', 'function', 'if', 'then', 'else', 'begin', 'end', 'try', 'exception', 'val', 'mutable', 'struct', 'sig', 'include', 'for', 'to', 'downto', 'while', 'do', 'done', 'as', 'when'], literals: ['true', 'false'] },
|
|
204
|
+
fsharp: { line: '//', block: ['(*', '*)'], quotes: '"', words: ['let', 'in', 'rec', 'and', 'match', 'with', 'type', 'module', 'open', 'fun', 'function', 'if', 'then', 'else', 'begin', 'end', 'try', 'exception', 'member', 'interface', 'inherit', 'mutable', 'yield', 'for', 'to', 'downto', 'while', 'do', 'done', 'as', 'when', 'use', 'namespace'], literals: ['true', 'false', 'None', 'Some'] },
|
|
205
|
+
erlang: { line: '%', block: null, quotes: '"\'', words: ['after', 'begin', 'case', 'catch', 'cond', 'end', 'fun', 'if', 'let', 'of', 'query', 'receive', 'try', 'when', 'andalso', 'orelse', 'band', 'bor', 'bnot', 'bsl', 'bsr', 'bxor', 'div', 'rem', 'not', 'and', 'or', 'xor', 'module', 'export', 'import', 'record', 'spec', 'type'], literals: ['true', 'false'] },
|
|
206
|
+
clojure: { line: ';', block: null, quotes: '"', words: ['def', 'defn', 'defmacro', 'let', 'if', 'do', 'fn', 'loop', 'recur', 'when', 'cond', 'case', 'ns', 'require', 'import', 'use', 'and', 'or', 'not', 'nil', 'true', 'false'], literals: [] },
|
|
207
|
+
lisp: { line: ';', block: null, quotes: '"', words: ['defun', 'defvar', 'defmacro', 'let', 'let*', 'if', 'cond', 'progn', 'lambda', 'setq', 'while', 'dolist', 'dotimes', 'car', 'cdr', 'cons', 'list', 'nil', 't'], literals: [] },
|
|
208
|
+
scheme: { line: ';', block: null, quotes: '"', words: ['define', 'lambda', 'let', 'let*', 'letrec', 'if', 'cond', 'else', 'begin', 'set!', 'quote', 'car', 'cdr', 'cons', 'list', 'null?'], literals: ['#t', '#f'] },
|
|
209
|
+
shell: { line: '#', block: null, quotes: '"\'', words: SHELL_KEYWORDS, literals: [] },
|
|
210
|
+
powershell: { line: '#', block: ['<#', '#>'], quotes: '"\'\'', words: ['begin', 'break', 'catch', 'class', 'continue', 'data', 'do', 'dynamicparam', 'else', 'elseif', 'end', 'enum', 'exit', 'filter', 'finally', 'for', 'foreach', 'from', 'function', 'if', 'in', 'param', 'process', 'return', 'switch', 'throw', 'trap', 'try', 'until', 'using', 'var', 'while', 'workflow', 'return', 'function'], literals: ['$true', '$false', '$null'], attr: '[' },
|
|
211
|
+
sql: { line: '--', block: ['/*', '*/'], quotes: '\'"', words: SQL_KEYWORDS, literals: SQL_LITERALS, upper: true },
|
|
212
|
+
json: { line: '', block: null, quotes: '"', words: [], literals: ['true', 'false', 'null'] },
|
|
213
|
+
yaml: { line: '#', block: null, quotes: '\'"', words: [], literals: ['true', 'false', 'null', 'yes', 'no', 'on', 'off'] , keyValue: true },
|
|
214
|
+
toml: { line: '#', block: null, quotes: '\'"', words: [], literals: ['true', 'false'] , keyValue: true },
|
|
215
|
+
ini: { line: ';', block: null, quotes: '\'"', words: [], literals: [] , keyValue: true },
|
|
216
|
+
dockerfile: { line: '#', block: null, quotes: '\'"', words: ['FROM', 'RUN', 'CMD', 'LABEL', 'EXPOSE', 'ENV', 'ADD', 'COPY', 'ENTRYPOINT', 'VOLUME', 'USER', 'WORKDIR', 'ARG', 'ONBUILD', 'STOPSIGNAL', 'HEALTHCHECK', 'SHELL', 'AS'], literals: [] },
|
|
217
|
+
makefile: { line: '#', block: null, quotes: '\'"', words: ['ifeq', 'ifneq', 'ifdef', 'ifndef', 'else', 'endif', 'include', 'define', 'endef', 'export', 'unexport', 'override', 'PHONY'], literals: [] },
|
|
218
|
+
css: { line: '', block: ['/*', '*/'], quotes: '\'"', words: [], literals: [] },
|
|
219
|
+
scss: { line: '//', block: ['/*', '*/'], quotes: '\'"', words: [], literals: [] },
|
|
220
|
+
html: { line: '', block: ['<!--', '-->'], quotes: '\'"', words: [], literals: [] },
|
|
221
|
+
xml: { line: '', block: ['<!--', '-->'], quotes: '\'"', words: [], literals: [] },
|
|
222
|
+
markdown: { line: '', block: ['<!--', '-->'], quotes: '`', words: [], literals: [] },
|
|
223
|
+
r: { line: '#', block: null, quotes: '\'"', words: R_KEYWORDS, literals: [] },
|
|
224
|
+
julia: { line: '#', block: ['#=', '=#'], quotes: '"\'', triple: true, words: JULIA_KEYWORDS, literals: JULIA_LITERALS },
|
|
225
|
+
matlab: { line: '%', block: ['%{', '%}'], quotes: '\'"', words: ['break', 'case', 'catch', 'classdef', 'continue', 'else', 'elseif', 'end', 'for', 'function', 'global', 'if', 'otherwise', 'parfor', 'persistent', 'return', 'spmd', 'switch', 'try', 'while'], literals: ['true', 'false'] },
|
|
226
|
+
verilog: { line: '//', block: ['/*', '*/'], quotes: '"', words: ['module', 'endmodule', 'input', 'output', 'inout', 'wire', 'reg', 'always', 'initial', 'begin', 'end', 'if', 'else', 'case', 'endcase', 'assign', 'parameter', 'localparam', 'posedge', 'negedge', 'function', 'endfunction', 'task', 'endtask', 'for', 'while', 'repeat'], literals: [] },
|
|
227
|
+
vhdl: { line: '--', block: null, quotes: '\'"', words: ['architecture', 'begin', 'entity', 'end', 'is', 'library', 'use', 'port', 'signal', 'process', 'if', 'then', 'else', 'elsif', 'case', 'when', 'component', 'function', 'procedure', 'type', 'constant', 'variable', 'downto', 'to', 'all', 'others'], literals: [] },
|
|
228
|
+
protobuf: { line: '//', block: ['/*', '*/'], quotes: '\'"', words: ['syntax', 'package', 'option', 'import', 'message', 'enum', 'service', 'rpc', 'returns', 'repeated', 'optional', 'required', 'oneof', 'reserved', 'map', 'stream'], literals: ['true', 'false'] },
|
|
229
|
+
graphql: { line: '#', block: null, quotes: '\'"', words: ['query', 'mutation', 'subscription', 'fragment', 'on', 'type', 'input', 'enum', 'interface', 'union', 'schema', 'scalar', 'directive', 'extend', 'implements'], literals: ['true', 'false', 'null'] },
|
|
230
|
+
nginx: { line: '#', block: null, quotes: '\'"', words: ['server', 'location', 'upstream', 'events', 'http', 'listen', 'server_name', 'root', 'index', 'proxy_pass', 'return', 'rewrite', 'if', 'include', 'error_page', 'access_log', 'error_log'], literals: [] },
|
|
231
|
+
terraform: { line: '#', block: ['/*', '*/'], quotes: '"', words: ['resource', 'data', 'variable', 'output', 'module', 'provider', 'locals', 'terraform', 'for_each', 'count', 'depends_on', 'lifecycle', 'dynamic', 'provisioner', 'true', 'false', 'null'], literals: [] },
|
|
232
|
+
diff: { line: '', block: null, quotes: '', words: [], literals: [] },
|
|
233
|
+
/** No highlighting: a language we do not know, or plain prose. */
|
|
234
|
+
text: { line: '', block: null, quotes: '', words: [], literals: [] },
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
/** Extension to language. Unknown extensions fall back to `text`, which renders unchanged. */
|
|
238
|
+
const BY_EXT = {
|
|
239
|
+
js: 'javascript', mjs: 'javascript', cjs: 'javascript', jsx: 'javascript',
|
|
240
|
+
ts: 'typescript', tsx: 'typescript', mts: 'typescript', cts: 'typescript',
|
|
241
|
+
py: 'python', pyw: 'python', pyi: 'python',
|
|
242
|
+
java: 'java', kt: 'kotlin', kts: 'kotlin', scala: 'scala', sc: 'scala',
|
|
243
|
+
cs: 'csharp', fs: 'fsharp', swift: 'swift',
|
|
244
|
+
c: 'c', h: 'c', cc: 'cpp', cpp: 'cpp', cxx: 'cpp', hpp: 'cpp', hh: 'cpp', hxx: 'cpp',
|
|
245
|
+
rs: 'rust', go: 'go', dart: 'dart', zig: 'zig',
|
|
246
|
+
rb: 'ruby', rake: 'ruby', gemspec: 'ruby', php: 'php', pl: 'perl', pm: 'perl', lua: 'lua',
|
|
247
|
+
ex: 'elixir', exs: 'elixir', erl: 'erlang', hrl: 'erlang',
|
|
248
|
+
hs: 'haskell', lhs: 'haskell', ml: 'ocaml', mli: 'ocaml', clj: 'clojure', cljs: 'clojure',
|
|
249
|
+
el: 'lisp', lisp: 'lisp', scm: 'scheme', ss: 'scheme',
|
|
250
|
+
sh: 'shell', bash: 'shell', zsh: 'shell', fish: 'shell', ps1: 'powershell', psm1: 'powershell',
|
|
251
|
+
sql: 'sql', json: 'json', jsonc: 'json', yml: 'yaml', yaml: 'yaml', toml: 'toml', ini: 'ini', cfg: 'ini', conf: 'nginx',
|
|
252
|
+
css: 'css', scss: 'scss', sass: 'scss', less: 'scss',
|
|
253
|
+
html: 'html', htm: 'html', xml: 'xml', svg: 'xml', vue: 'html',
|
|
254
|
+
md: 'markdown', markdown: 'markdown', mdx: 'markdown',
|
|
255
|
+
r: 'r', jl: 'julia', m: 'matlab',
|
|
256
|
+
v: 'verilog', sv: 'verilog', vhd: 'vhdl', vhdl: 'vhdl',
|
|
257
|
+
proto: 'protobuf', graphql: 'graphql', gql: 'graphql', tf: 'terraform',
|
|
258
|
+
diff: 'diff', patch: 'diff',
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
/** The language for a path, by extension, then by a few well-known bare names. */
|
|
262
|
+
export function langForPath(p) {
|
|
263
|
+
const base = String(p == null ? '' : p).split(/[\\/]/).pop().toLowerCase();
|
|
264
|
+
if (base === 'dockerfile' || base.startsWith('dockerfile.')) return LANGS.dockerfile;
|
|
265
|
+
if (base === 'makefile' || base === 'gnumakefile') return LANGS.makefile;
|
|
266
|
+
if (base === 'vite.config' || base === 'package.json') return LANGS.json;
|
|
267
|
+
const ext = base.includes('.') ? base.slice(base.lastIndexOf('.') + 1) : '';
|
|
268
|
+
return LANGS[BY_EXT[ext]] || LANGS.text;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Token kind -> colour, resolved on EVERY call rather than captured once.
|
|
273
|
+
*
|
|
274
|
+
* `C` is a live object that `setTheme` rewrites in place. Reading `C.cyan` at module load froze the colour of the
|
|
275
|
+
* theme that happened to be active when the file was first imported, so `/theme` changed every other colour on
|
|
276
|
+
* screen and left code tinted like the old one.
|
|
277
|
+
*
|
|
278
|
+
* Every value must be a key `C` actually EXPORTS. `C.blue` did not exist — the theme tables carry a `blue` entry
|
|
279
|
+
* but `C` never surfaces it — so `func` was `undefined` and every call to a function, and every YAML key, silently
|
|
280
|
+
* rendered uncoloured.
|
|
281
|
+
*/
|
|
282
|
+
function colorFor(kind) {
|
|
283
|
+
switch (kind) {
|
|
284
|
+
case 'keyword': return C.cyan;
|
|
285
|
+
case 'literal': return C.heading;
|
|
286
|
+
case 'string': return C.diffAddFg;
|
|
287
|
+
// COMMENTS ARE DERIVED FROM THE FOREGROUND, not from the theme's grey.
|
|
288
|
+
//
|
|
289
|
+
// `C.gray` is tuned to sit quiet against the PAGE background, and in several themes it lands almost exactly on
|
|
290
|
+
// the diff wash — dracula and tokyo came out at a brightness difference of 3 to 5, which is invisible. A comment
|
|
291
|
+
// is the one token that has to stay readable ON the wash, so it comes from `C.comment`, which `setTheme` mixes
|
|
292
|
+
// from the palette's foreground: quiet, but always far enough from whatever is behind it.
|
|
293
|
+
case 'comment': return C.comment;
|
|
294
|
+
case 'number': return C.heading;
|
|
295
|
+
case 'func': return C.cyan;
|
|
296
|
+
case 'attr': return C.orange;
|
|
297
|
+
default: return '';
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Colour one line of source.
|
|
303
|
+
*
|
|
304
|
+
* A LINE AT A TIME, deliberately: the caller renders rows and tracks its own wrapping, and a tokenizer that
|
|
305
|
+
* needed to see the whole file could not run on a diff (which is two fragments of a file, not a file).
|
|
306
|
+
*
|
|
307
|
+
* A multi-line string or block comment is not tracked across calls — the row would need state threaded through
|
|
308
|
+
* every renderer. In practice a diff's rows are short and the mismatch shows as one line of a block comment drawn
|
|
309
|
+
* as ordinary text, which is a small price for a highlighter that cannot get out of step.
|
|
310
|
+
*
|
|
311
|
+
* Returns the text with ANSI codes inserted. Unknown languages return it unchanged.
|
|
312
|
+
*/
|
|
313
|
+
export function highlightLine(text, lang, inComment = false) {
|
|
314
|
+
const L = lang && typeof lang === 'object' ? lang : null;
|
|
315
|
+
if (!L || !L.words || !L.words.length && !L.quotes) return { text: String(text), inComment: false };
|
|
316
|
+
const src = String(text);
|
|
317
|
+
// AN EMPTY ROW KEEPS THE STATE: the line is blank, not the comment. Resetting here made the row after a
|
|
318
|
+
// blank line inside `/* ... */` read as ordinary code, and its `const` came out as a keyword.
|
|
319
|
+
if (!src) return { text: src, inComment };
|
|
320
|
+
|
|
321
|
+
const words = new Set(L.words || []);
|
|
322
|
+
const literals = new Set(L.literals || []);
|
|
323
|
+
const quotes = L.quotes || '';
|
|
324
|
+
const upper = !!L.upper;
|
|
325
|
+
|
|
326
|
+
let out = '';
|
|
327
|
+
let i = 0;
|
|
328
|
+
const paint = (s, kind) => {
|
|
329
|
+
const c = colorFor(kind);
|
|
330
|
+
return c ? c + s + C.reset : s;
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
// A `key:` at the start of a line is the one structure YAML, TOML tables and INI share, and it is what a reader
|
|
334
|
+
// navigates by. Those languages have no keywords to match on, so the shape is matched instead.
|
|
335
|
+
if (L.keyValue) {
|
|
336
|
+
const m = /^(\s*)([A-Za-z_][\w.-]*)(\s*:)/.exec(src);
|
|
337
|
+
if (m) {
|
|
338
|
+
const tail = src.slice(m[0].length);
|
|
339
|
+
const rest = tail ? highlightLine(tail, { ...L, keyValue: false }) : { text: '', inComment: false };
|
|
340
|
+
return { text: m[1] + paint(m[2], 'func') + m[3] + rest.text, inComment: rest.inComment };
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
// A line that is a preprocessor directive or a decorator is coloured whole — its own grammar is not worth
|
|
346
|
+
// parsing and the visual cue is the point.
|
|
347
|
+
if (L.attr && src.trimStart().startsWith(L.attr)) {
|
|
348
|
+
const lead = src.slice(0, src.length - src.trimStart().length);
|
|
349
|
+
return { text: lead + paint(src.trimStart(), 'attr'), inComment: false };
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
while (i < src.length) {
|
|
353
|
+
const ch = src[i];
|
|
354
|
+
const rest = src.slice(i);
|
|
355
|
+
|
|
356
|
+
// Block comment opener.
|
|
357
|
+
if (L.block && rest.startsWith(L.block[0])) {
|
|
358
|
+
const end = src.indexOf(L.block[1], i + L.block[0].length);
|
|
359
|
+
const stop = end < 0 ? src.length : end + L.block[1].length;
|
|
360
|
+
out += paint(src.slice(i, stop), 'comment');
|
|
361
|
+
// THE ROW ENDED INSIDE THE COMMENT when there is no closing marker on it. The caller passes this back in
|
|
362
|
+
// for the next row, which is what keeps a multi-line comment grey all the way down.
|
|
363
|
+
if (end < 0) return { text: out, inComment: true };
|
|
364
|
+
i = stop;
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
// Line comment.
|
|
368
|
+
// THE ROW BEGINS INSIDE A BLOCK COMMENT. Everything up to the closing marker is comment, and the rest of
|
|
369
|
+
// the row is ordinary code again.
|
|
370
|
+
if (inComment && L.block) {
|
|
371
|
+
const closeAt = src.indexOf(L.block[1]);
|
|
372
|
+
if (closeAt < 0) return { text: paint(src, 'comment'), inComment: true };
|
|
373
|
+
out += paint(src.slice(0, closeAt + L.block[1].length), 'comment');
|
|
374
|
+
i = closeAt + L.block[1].length;
|
|
375
|
+
inComment = false;
|
|
376
|
+
}
|
|
377
|
+
if (L.line && rest.startsWith(L.line)) {
|
|
378
|
+
out += paint(src.slice(i), 'comment');
|
|
379
|
+
break;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// String. A raw prefix (`r"` in Python, `` ` `` in Go) is handled by treating the prefix as part of the quote
|
|
383
|
+
// run — the whole literal is one colour either way.
|
|
384
|
+
if (quotes.includes(ch)) {
|
|
385
|
+
const triple = L.triple && rest.startsWith(ch + ch + ch);
|
|
386
|
+
const delim = triple ? ch + ch + ch : ch;
|
|
387
|
+
let j = i + delim.length;
|
|
388
|
+
while (j < src.length) {
|
|
389
|
+
if (src[j] === '\\') { j += 2; continue; }
|
|
390
|
+
if (!triple && src[j] === ch && !(L.raw && ch === '"' && /\\$/.test(''))) { j++; break; }
|
|
391
|
+
if (triple && src.startsWith(delim, j)) { j += delim.length; break; }
|
|
392
|
+
j++;
|
|
393
|
+
}
|
|
394
|
+
out += paint(src.slice(i, Math.min(j, src.length)), 'string');
|
|
395
|
+
i = Math.min(j, src.length);
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// Number: digits, a decimal part, an exponent, and a trailing unit letter (`10px`, `1e5`, `0x1f`).
|
|
400
|
+
if (/[0-9]/.test(ch) && !/[A-Za-z_$]/.test(src[i - 1] || '')) {
|
|
401
|
+
const m = /^(?:0[xXbBoO][0-9a-fA-F_]+|[0-9][0-9_]*(?:\.[0-9_]+)?(?:[eE][+-]?[0-9]+)?)(?:[a-zA-Z]{1,4}\b)?/.exec(rest);
|
|
402
|
+
if (m) { out += paint(m[0], 'number'); i += m[0].length; continue; }
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// Identifier or keyword.
|
|
406
|
+
if (/[A-Za-z_$@]/.test(ch)) {
|
|
407
|
+
const m = /^[A-Za-z_$@][A-Za-z0-9_$]*/.exec(rest);
|
|
408
|
+
const word = m[0];
|
|
409
|
+
const key = upper ? word.toUpperCase() : word;
|
|
410
|
+
// A name followed directly by `(` is a call, which reads as a function even when the language also uses it
|
|
411
|
+
// as a keyword (`if (`, `for (`) — so keywords win, and everything else before `(` is a call.
|
|
412
|
+
const after = src[i + word.length];
|
|
413
|
+
if (words.has(key)) out += paint(word, 'keyword');
|
|
414
|
+
else if (literals.has(key) || literals.has(word)) out += paint(word, 'literal');
|
|
415
|
+
else if (after === '(') out += paint(word, 'func');
|
|
416
|
+
else out += word;
|
|
417
|
+
i += word.length;
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
out += ch;
|
|
422
|
+
i++;
|
|
423
|
+
}
|
|
424
|
+
return { text: out, inComment: false };
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/** True when the path resolves to a language this module can colour. */
|
|
428
|
+
export function canHighlight(p) {
|
|
429
|
+
const L = langForPath(p);
|
|
430
|
+
return !!(L && (L.words.length || L.quotes));
|
|
431
|
+
}
|
|
432
|
+
|
package/src/i18n.js
CHANGED
|
@@ -258,11 +258,11 @@ export const MESSAGES = {
|
|
|
258
258
|
// A copy button reports its own result in place: the label IS the feedback.
|
|
259
259
|
// ---- transcript markers ---------------------------------------------------
|
|
260
260
|
// The glyph the terminal prints in the gutter for each kind of row. They live
|
|
261
|
-
// here because the terminal and the browser must agree on them: a
|
|
262
|
-
// terminal and a
|
|
263
|
-
'mark.user': { zh: '
|
|
264
|
-
'mark.queued': { zh: '
|
|
265
|
-
'mark.steer': { zh: '
|
|
261
|
+
// here because the terminal and the browser must agree on them: a `>` in the
|
|
262
|
+
// terminal and a `>` in the browser are the same message.
|
|
263
|
+
'mark.user': { zh: '>', en: '>' },
|
|
264
|
+
'mark.queued': { zh: '>', en: '>' },
|
|
265
|
+
'mark.steer': { zh: '>', en: '>' },
|
|
266
266
|
'mark.bash': { zh: '!', en: '!' },
|
|
267
267
|
'mark.warn': { zh: '⚑', en: '⚑' },
|
|
268
268
|
'mark.thinking': { zh: '●', en: '●' },
|
package/src/registry-browser.js
CHANGED
package/src/settings-schema.js
CHANGED
|
@@ -89,6 +89,10 @@ export const SETTINGS_SCHEMA = [
|
|
|
89
89
|
ui: { tab: 'appearance', group: 'Transcript', label: 'Save display transcript', hint: 'Keep notices, warnings, plan cards and reasoning in the saved session' } },
|
|
90
90
|
{ key: 'save_thinking', ...bool(true),
|
|
91
91
|
ui: { tab: 'appearance', group: 'Transcript', label: 'Save reasoning', hint: 'Persist thinking blocks, not only the visible answer' } },
|
|
92
|
+
{ key: 'title_display', ...bool(true),
|
|
93
|
+
ui: { tab: 'appearance', group: 'Display', label: 'Title display', hint: 'Show the session title band at the top of the screen' } },
|
|
94
|
+
{ key: 'auto_title', ...bool(true),
|
|
95
|
+
ui: { tab: 'appearance', group: 'Display', label: 'Auto title', hint: 'Let the model name the session from its first message' } },
|
|
92
96
|
{ key: 'cost_currency', ...en('usd', ['usd', 'cny']),
|
|
93
97
|
ui: { tab: 'appearance', group: 'Display', label: 'Cost currency', hint: 'Which unit /cost reports in' } },
|
|
94
98
|
{ key: 'cny_per_usd', ...int(0, 0, 100000),
|
package/src/team-panel.js
CHANGED
|
@@ -340,7 +340,7 @@ export function renderTeamPanel(panel, cols, rows) {
|
|
|
340
340
|
for (let i = 0; i < roster.length && out.length < rows - composerRows - trafficRoom - 2; i++) {
|
|
341
341
|
const m = roster[i];
|
|
342
342
|
const sel = i === panel.selectedIndex;
|
|
343
|
-
const ptr = sel ? `${C.cyan}
|
|
343
|
+
const ptr = sel ? `${C.cyan}>${C.reset} ` : ' ';
|
|
344
344
|
const name = (m.isLead ? `${m.name} (lead)` : m.name).padEnd(20);
|
|
345
345
|
// The states a member can be in, each with its own colour: green is a tool actually running,
|
|
346
346
|
// cyan is blocked on the model, grey is waiting for work, yellow is an agent that has not
|