pi-syntax-highlight 0.1.1 → 0.2.1
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 +73 -58
- package/DEVELOPER.md +61 -34
- package/LICENSE +21 -0
- package/README.md +19 -18
- package/extensions/index.ts +5 -10
- package/package.json +5 -4
- package/src/detect-language.ts +205 -8
- package/src/emphasis.ts +82 -1
- package/src/highlight.ts +25 -9
- package/src/lru-cache.ts +30 -0
- package/src/markdown-fence-lang.ts +20 -87
- package/src/render-bash.ts +29 -2
- package/src/render-edit.ts +0 -6
- package/src/render-generic.ts +10 -21
- package/src/render-read.ts +8 -149
- package/src/render-utils.ts +8 -17
- package/src/resolve-renderers.ts +181 -240
- package/src/tokens.ts +1 -34
- package/assets/icon.png +0 -0
- package/assets/icon.svg +0 -36
- package/src/active-theme.ts +0 -26
- package/src/markdown-style.ts +0 -134
- package/src/markdown-theme.ts +0 -53
- package/src/render-path.ts +0 -54
- package/src/render-write.ts +0 -81
- package/test/unit/active-theme.test.ts +0 -38
- package/test/unit/bash-preview.test.ts +0 -57
- package/test/unit/detect-language.test.ts +0 -124
- package/test/unit/emphasis.test.ts +0 -113
- package/test/unit/extensions-index.test.ts +0 -116
- package/test/unit/grep-parse.test.ts +0 -125
- package/test/unit/highlight.test.ts +0 -107
- package/test/unit/markdown-fence-lang.test.ts +0 -131
- package/test/unit/markdown-pipeline.test.ts +0 -153
- package/test/unit/markdown-render-parity.test.ts +0 -127
- package/test/unit/markdown-style.test.ts +0 -152
- package/test/unit/markdown-theme.test.ts +0 -86
- package/test/unit/render-bash.test.ts +0 -194
- package/test/unit/render-edit.test.ts +0 -214
- package/test/unit/render-find.test.ts +0 -139
- package/test/unit/render-generic.test.ts +0 -152
- package/test/unit/render-grep.test.ts +0 -338
- package/test/unit/render-ls.test.ts +0 -132
- package/test/unit/render-read.test.ts +0 -375
- package/test/unit/render-utils.test.ts +0 -324
- package/test/unit/render-write.test.ts +0 -143
- package/test/unit/resolve-renderers.test.ts +0 -474
- package/test/unit/style-path.test.ts +0 -74
- package/tsconfig.json +0 -15
package/CHANGELOG.md
CHANGED
|
@@ -3,84 +3,99 @@
|
|
|
3
3
|
All notable changes to this project are documented in this file. The format
|
|
4
4
|
follows Keep a Changelog, and this project uses semantic versioning.
|
|
5
5
|
|
|
6
|
+
## [0.2.1] - 2026-11-16
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- Manual GitHub Actions workflow to publish to npm.
|
|
11
|
+
- MIT `LICENSE` file.
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- Only runtime files are published (43 → 22 files).
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- Stack traces and email headers are no longer detected as `makefile`. Targets starting with a capital letter (e.g. `Main:`) are no longer detected either.
|
|
20
|
+
- Code fences in user messages get their language label again.
|
|
21
|
+
|
|
22
|
+
## [0.2.0] - 2026-11-16
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
|
|
26
|
+
- Language detection for Dockerfile, Makefile, C, C++, PHP, Ruby, PowerShell, JSX, TSX, properties and HTML fragments.
|
|
27
|
+
- Tests that fail if pi changes the internals this package relies on.
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
|
|
31
|
+
- Requires pi 1.5.1 or newer.
|
|
32
|
+
- `read`, `write` and error results now use the stock pi renderers. Final `bash`/`powershell` results keep the styled body, even on failure.
|
|
33
|
+
- Fence labels also apply to thinking, custom and summary messages.
|
|
34
|
+
- Colors follow stock pi.
|
|
35
|
+
- The 400-line highlight limit applies to `bash` and `powershell` only.
|
|
36
|
+
- MCP tools use pi's own renderers.
|
|
37
|
+
|
|
38
|
+
### Removed
|
|
39
|
+
|
|
40
|
+
- Markdown styling of assistant messages. Only unlabeled fences get a label now.
|
|
41
|
+
- The `read` line-number gutter and the `write` content overlay.
|
|
42
|
+
- Fence info strings are copied as written, so `{.ts}` and `js title="a"` are no longer cleaned up.
|
|
43
|
+
|
|
44
|
+
### Fixed
|
|
45
|
+
|
|
46
|
+
- `bash` duration stops at the final result.
|
|
47
|
+
- `grep` no longer hangs on lines over 500 characters or risky patterns.
|
|
48
|
+
|
|
49
|
+
## [0.1.2] - 2026-10-26
|
|
50
|
+
|
|
51
|
+
### Added
|
|
52
|
+
|
|
53
|
+
- `bash` and `powershell` output in a known language (YAML, SQL, TOML, shell, Python, JS, TS, Go, Rust, XML, HTML) is highlighted as one block.
|
|
54
|
+
|
|
55
|
+
### Changed
|
|
56
|
+
|
|
57
|
+
- Detection reads the same lines the highlighter paints.
|
|
58
|
+
- README lists the detected languages and fixes the collapsed-call description.
|
|
59
|
+
|
|
6
60
|
## [0.1.1] - 2026-10-26
|
|
7
61
|
|
|
8
62
|
### Added
|
|
9
63
|
|
|
10
|
-
-
|
|
11
|
-
|
|
12
|
-
height to 16/9, so the terminal window sits inside the central area and no edge
|
|
13
|
-
of it is cut.
|
|
14
|
-
- `DEVELOPER.md`: module map, theme handling and cache invalidation, the rules
|
|
15
|
-
the markdown transformer follows, what the hook cannot reach, and the tests.
|
|
64
|
+
- Package icon for the gallery.
|
|
65
|
+
- `DEVELOPER.md` with the module map and design notes.
|
|
16
66
|
|
|
17
67
|
### Changed
|
|
18
68
|
|
|
19
|
-
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
`pi-extension`, `syntax-highlighting`, `markdown`, `code-fences`,
|
|
23
|
-
`language-detection`, `tui`, `diff` and `tool-output`, and `pi.image` points at
|
|
24
|
-
the raw icon.
|
|
25
|
-
- README rewritten for the pi.dev audience: install first, one or two sentences
|
|
26
|
-
per renderer, the limits in user terms, and links to `DEVELOPER.md` and
|
|
27
|
-
`CHANGELOG.md`. The tagline now opens the file with the badges under it,
|
|
28
|
-
because the gallery builds its description from the first README paragraph,
|
|
29
|
-
and the `pi -e` example no longer carries an absolute path from the author's
|
|
30
|
-
machine.
|
|
69
|
+
- Added `license: "MIT"`; npm was listing the package as Proprietary.
|
|
70
|
+
- Better npm description and keywords.
|
|
71
|
+
- README rewritten for pi.dev readers.
|
|
31
72
|
|
|
32
73
|
## [0.1.0] - 2026-10-25
|
|
33
74
|
|
|
34
75
|
### Added
|
|
35
76
|
|
|
36
|
-
- `read`
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
-
|
|
40
|
-
header for skills and agent resource files, and a highlighted content preview
|
|
41
|
-
for `write` that is capped while the argument streams.
|
|
42
|
-
- `edit` result renderer: diff highlighted by file language, dimmed line numbers,
|
|
43
|
-
changed words in reverse video, error body in the error color. The diff fills
|
|
44
|
-
the body of the call's own box, so the header keeps its success or failure
|
|
45
|
-
background.
|
|
46
|
-
- Markdown styling for assistant messages: headings in the accent color with one
|
|
47
|
-
attribute per level, inline code with its backtick delimiters restored, and
|
|
48
|
-
blockquote text in the accent color. Sequences close the attribute they opened
|
|
49
|
-
and never cross a line; the visible text is unchanged apart from the restored
|
|
50
|
-
delimiters.
|
|
51
|
-
- `diff` dependency for the word-level highlight of an edited line.
|
|
77
|
+
- `read` results with line numbers and highlighting by file language.
|
|
78
|
+
- `read` and `write` headers with a path link and line range, plus a highlighted preview for `write`.
|
|
79
|
+
- `edit` results with a highlighted diff and word-level changes.
|
|
80
|
+
- Markdown styling for assistant messages: headings, inline code and blockquotes.
|
|
52
81
|
|
|
53
82
|
### Changed
|
|
54
83
|
|
|
55
|
-
- `read` numbers its body and
|
|
56
|
-
|
|
57
|
-
- `edit` no longer paints its diff through pi's `renderDiff`, which reads the
|
|
58
|
-
module-global theme and does not highlight code.
|
|
84
|
+
- `read` numbers its body and keeps the continuation notice out of the highlighted text.
|
|
85
|
+
- `edit` no longer uses pi's `renderDiff`.
|
|
59
86
|
|
|
60
87
|
### Fixed
|
|
61
88
|
|
|
62
|
-
- The highlight cache now
|
|
63
|
-
|
|
64
|
-
cache is keyed by the color sequences the highlighter actually reads.
|
|
65
|
-
- Tool failures are detected through the render context. The host passes no
|
|
66
|
-
`isError` inside the result, so the previous check was always false and
|
|
67
|
-
`grep`, `find`, `ls` and the generic overlay never painted an error.
|
|
89
|
+
- The highlight cache now refreshes when the theme changes.
|
|
90
|
+
- Tool errors are detected correctly, so `grep`, `find`, `ls` and generic results show them.
|
|
68
91
|
|
|
69
92
|
## [0.0.1] - 2026-10-24
|
|
70
93
|
|
|
71
94
|
### Added
|
|
72
95
|
|
|
73
|
-
- `grep`
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
-
|
|
77
|
-
|
|
78
|
-
- `
|
|
79
|
-
styled, collapsed preview with the expand hint, duration line.
|
|
80
|
-
- Generic result overlay for `codemode`, MCP and unknown tools that have no
|
|
81
|
-
renderer of their own: JSON and diff bodies highlighted, 10-line collapsed
|
|
82
|
-
preview.
|
|
83
|
-
- Markdown fence transformer: unlabeled fences get a detected language
|
|
84
|
-
injected; labeled fences and `mermaid`, `math`, `latex`, `katex` are left
|
|
85
|
-
untouched.
|
|
86
|
-
- `read`, `write` and `edit` are passed through unchanged.
|
|
96
|
+
- `grep` results with styled paths, line numbers and highlighted matches.
|
|
97
|
+
- `find` and `ls` results with dimmed directories and colored file names.
|
|
98
|
+
- `bash` and `powershell` results with styled diffs, JSON, paths and errors.
|
|
99
|
+
- Generic renderer for `codemode`, MCP and unknown tools.
|
|
100
|
+
- Markdown fences without a label get a detected language.
|
|
101
|
+
- `read`, `write` and `edit` pass through unchanged.
|
package/DEVELOPER.md
CHANGED
|
@@ -2,59 +2,66 @@
|
|
|
2
2
|
|
|
3
3
|
How the extension draws what it draws, and why a few things stay out of reach. For installation and user-facing behavior, see [README.md](./README.md).
|
|
4
4
|
|
|
5
|
-
Needs Node 24 or newer (the tests run through `--experimental-strip-types`) and pi 1.
|
|
5
|
+
Needs Node 24 or newer (the tests run through `--experimental-strip-types`) and pi 1.5.1 or newer.
|
|
6
6
|
|
|
7
7
|
## Layout
|
|
8
8
|
|
|
9
|
-
`extensions/index.ts` is the whole public surface: it registers the tool
|
|
9
|
+
`extensions/index.ts` is the whole public surface: it registers the tool renderer resolver and one markdown transformer (messages `user`, `assistant`, `assistant-thinking`, `custom`, `summary`). Everything else under `src/` is internal.
|
|
10
10
|
|
|
11
|
-
- `resolve-renderers.ts`
|
|
12
|
-
- `render-*.ts` turn a tool result into the text of a `Text` node: `grep`, `find`, `ls`, `bash`, `read`, `edit`,
|
|
13
|
-
- `render-utils.ts` holds the pieces those builders share:
|
|
11
|
+
- `resolve-renderers.ts` is the resolver; see below.
|
|
12
|
+
- `render-*.ts` turn a tool result into the text of a `Text` node: `grep`, `find`, `ls`, `bash`, `read`, `edit`, and `generic` (extension tools without a result renderer).
|
|
13
|
+
- `render-utils.ts` holds the pieces those builders share: footers, the expand hint, the truncation notice.
|
|
14
14
|
- `highlight.ts` wraps pi's `highlightCode` with a cache, and `tokens.ts` holds the SGR sequences the code reads directly.
|
|
15
|
-
- `style-path.ts
|
|
16
|
-
- `grep-parse.ts` splits grep's `path:line: text` and `path-line- text` forms. `detect-language.ts` answers a language for a fence
|
|
17
|
-
- `markdown-fence-lang.ts
|
|
18
|
-
- `active-theme.ts` keeps the theme object from the last rendered tool result.
|
|
15
|
+
- `style-path.ts` and `emphasis.ts` handle the small decisions a path or a grep line needs: which color a basename gets, where the match sits inside a line (with the length and backtracking guards).
|
|
16
|
+
- `grep-parse.ts` splits grep's `path:line: text` and `path-line- text` forms. `detect-language.ts` answers a language for a fence, and `detectOutputLanguage` answers one for a tool-output body.
|
|
17
|
+
- `markdown-fence-lang.ts` is the markdown pass: it labels unlabeled closed fences and nothing else.
|
|
19
18
|
|
|
20
|
-
##
|
|
19
|
+
## The resolver
|
|
20
|
+
|
|
21
|
+
`resolveToolRenderers` wraps the host chain: it calls `next()` and decides per tool.
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
- No base renderers: `undefined` passes through.
|
|
24
|
+
- Base with no `renderResult`: the generic renderer is installed.
|
|
25
|
+
- Otherwise the slot is overlaid only if it is the stock one. Detection is by identity against the host's own `create*ToolDefinition(cwd)` result, then by `toString()` equality, because the stock `bash` and `powershell` renderers are built per definition. Anything undecidable counts as foreign and is returned unchanged, so MCP tools and extensions that bring their own renderer keep it.
|
|
26
|
+
- Styled slots: `grep`, `find`, `ls`, `read` (result only), `edit` (the highlighted diff is swapped into the box stock filled), `bash`/`powershell` (final results only; partial results stay on stock, which owns the elapsed line and repaint interval).
|
|
27
|
+
- Every overlay is wrapped: if ours throws, stock renders the result with a fresh component; the generic renderer falls back to the plain body.
|
|
28
|
+
- `write`, and the `read`/`write` call headers, are stock. Error results render like stock; final `bash`/`powershell` results keep the styled body, including failures.
|
|
29
|
+
- The key hint comes from `context.keyHint`, with `rawKeyHint` as the fallback outside a session.
|
|
23
30
|
|
|
24
|
-
|
|
31
|
+
The overlays depend on host internals, and contract tests fail when pi renames them: `state.callComponent` (edit's call box, header first), `state.startedAt` and `state.interval` (shell clock).
|
|
32
|
+
|
|
33
|
+
## Theme handling
|
|
25
34
|
|
|
26
|
-
|
|
35
|
+
The theme reaches the renderers as a proxy of stable identity, so a reference comparison never sees a theme switch. The highlight cache is keyed by the color sequences the highlighter actually reads, which changes when the theme does. `syncHighlightTheme` does the comparison on every render. Nothing captures the theme for the markdown pass, which writes no colors.
|
|
27
36
|
|
|
28
|
-
|
|
37
|
+
Tool failure is read from the render context, not from the result: the host passes no `isError` field inside `AgentToolResult`, so a check there is always false.
|
|
29
38
|
|
|
30
|
-
|
|
39
|
+
Without an initialized theme the renderers fall back to the plain tool output color.
|
|
31
40
|
|
|
32
|
-
|
|
33
|
-
- Every sequence opens and closes inside its line and closes only the attribute it opened, never with a full reset, so the style of the surrounding construct survives the span.
|
|
34
|
-
- The visible text is unchanged: stripping the sequences from the render leaves the same characters as the render without the transformer, except the backtick delimiters of inline code, which the stock renderer drops.
|
|
41
|
+
## How a bash body gets its language
|
|
35
42
|
|
|
36
|
-
|
|
43
|
+
Diff and JSON are recognized over the whole body. Anything else goes to `detectOutputLanguage`, which wraps the fence detector with an allowlist and two raised thresholds, because shell output is log-shaped far more often than code-shaped. Three false positives decided that design, all measured: two `key: value` lines are `git log`, `curl -I` headers are a YAML document to any count that ignores case, and "Update the docs in the table from last week" is SQL. A wrong label paints the body with a grammar that does not fit it, which reads worse than flat text.
|
|
37
44
|
|
|
38
|
-
|
|
45
|
+
Detection reads the first `HIGHLIGHT_LINE_BUDGET` lines, the same lines the tokenizer will paint, so nothing is detected in a region that would stay flat anyway. A classified line (error, warning, `path:line:`) replaces the highlighted one instead of being wrapped inside it: `theme.fg()` closes at the end of the string and cannot recolor a span of an already painted line.
|
|
39
46
|
|
|
40
|
-
|
|
47
|
+
`render-generic` does not use the detector. It recognizes JSON and diff only, and anything else keeps the plain content color.
|
|
41
48
|
|
|
42
|
-
|
|
49
|
+
## The markdown pass
|
|
43
50
|
|
|
44
|
-
|
|
51
|
+
`registerMarkdownTransformer` is a display-only `string => string` step applied before parsing. This package uses it for one thing: the info string of a closed fence with no label gets a detected language, so pi's own highlighter has a grammar. The pass is memoized (small LRU), copies an unclosed fence as it is because its body is still arriving, never rewrites an existing label or a body that already carries escape sequences, and falls back to the original markdown if it throws.
|
|
45
52
|
|
|
46
|
-
|
|
47
|
-
- The `│ ` border of a blockquote, which the renderer prepends after wrapping the content.
|
|
48
|
-
- The accent color of a heading stops at its first inline token: the renderer reopens its own heading color around every inline span, so text after `**bold**` or `` `code` `` in the same heading returns to the theme's heading color.
|
|
53
|
+
Labels are chosen by `detect-language.ts`, which never answers `markdown` or `plaintext`, and leaves `mermaid`, `math`, `latex`, and `katex` alone. There is no hook that replaces the `Markdown` component, so headings, quotes, inline code, tables and lists are outside this package.
|
|
49
54
|
|
|
50
55
|
## Known limits
|
|
51
56
|
|
|
52
|
-
-
|
|
53
|
-
-
|
|
54
|
-
- A
|
|
55
|
-
-
|
|
56
|
-
-
|
|
57
|
-
-
|
|
57
|
+
- Fences inside lists or blockquotes are not recognized, so they are not labeled.
|
|
58
|
+
- A bash body is read once, from its head: a log that turns into YAML after the first `HIGHLIGHT_LINE_BUDGET` (400) lines keeps the flat paint. The cap applies to bash only.
|
|
59
|
+
- A lowercase SQL query with no terminator stays flat, which is the price of rejecting English prose that starts with "Update" or "Delete".
|
|
60
|
+
- `properties` is detected in fences only; it is not in the bash allowlist.
|
|
61
|
+
- HTML fragments need a known lowercase tag and a closing tag; JSX without `className=` or `={` can be detected as HTML.
|
|
62
|
+
- `grep` output whose path contains `:N: ` or `-N- ` is ambiguous; pi does not disambiguate it either. Emphasis is skipped for lines over 500 characters and for backtracking-prone patterns.
|
|
63
|
+
- The diff of an `edit` marks changed words only where one removed line is followed by one added line, the same rule pi applies.
|
|
64
|
+
- Only one markdown transformer is registered by this extension.
|
|
58
65
|
|
|
59
66
|
## Tests
|
|
60
67
|
|
|
@@ -64,9 +71,29 @@ npm run typecheck
|
|
|
64
71
|
npm test
|
|
65
72
|
```
|
|
66
73
|
|
|
67
|
-
|
|
74
|
+
Seams the tests rely on:
|
|
75
|
+
|
|
76
|
+
- `stock-parity.test.ts` renders the same input through stock pi and through the resolver and compares text and shape (errors except final shell results, read/write calls, generic fallback, edit diff).
|
|
77
|
+
- `resolve-renderers.test.ts` covers slot detection, fallback to stock on error, the shell clock, and the contract tests on `state.callComponent`, `state.startedAt` and `state.interval`.
|
|
78
|
+
- `markdown-fence-lang.test.ts` and `markdown-render-parity.test.ts` cover the fence labeling and that the visible text is unchanged.
|
|
79
|
+
- `extensions-index.test.ts` covers what is registered.
|
|
80
|
+
- `highlight.test.ts` covers the theme cache; builders take an injected highlighter because `highlightCode` reads the module-global theme.
|
|
81
|
+
- `emphasis.test.ts` includes the backtracking guard.
|
|
82
|
+
|
|
83
|
+
To try a working copy without installing it, run `pi -e .` from the package directory. With `node_modules` present the extension can import a second copy of pi next to the host's: `keyHint` therefore comes from the render context, never from a module-level import, and languages beyond the eager set (about 21) are registered asynchronously, so the first render of a rarer language can be flat.
|
|
84
|
+
|
|
85
|
+
## Release
|
|
86
|
+
|
|
87
|
+
The package is published from `.github/workflows/publish-syntax-highlight.yml`, which lives at the root of the
|
|
88
|
+
monorepo and runs with `working-directory: pi-syntax-highlight`. It is triggered by hand only
|
|
89
|
+
(`workflow_dispatch`), over OIDC with `npm stage publish`. There is no `NPM_TOKEN`: the npm CLI exchanges the
|
|
90
|
+
runner's OIDC identity for a short-lived publish token. The trust relationship is configured on npmjs.com and
|
|
91
|
+
names the exact filename of that workflow, so renaming it breaks publishing until the connection is deleted and
|
|
92
|
+
created again. The publish stays in stage and goes to production when a person approves it on npmjs.com.
|
|
68
93
|
|
|
69
|
-
|
|
94
|
+
The job order is `npm ci`, `npm run typecheck`, `npm test` and `npm stage publish`. The version published is the
|
|
95
|
+
one in `package.json` at that commit, so a release is a version bump committed to `main`, a push and then the
|
|
96
|
+
dispatch; a version already on the registry fails the last step and leaves nothing staged.
|
|
70
97
|
|
|
71
98
|
## License
|
|
72
99
|
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pablo Peraza
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# pi-syntax-highlight
|
|
2
2
|
|
|
3
|
-
Syntax highlighting for what pi prints: tool output
|
|
3
|
+
Syntax highlighting for what pi prints: tool output, and code fences the assistant writes without a language. Rendering only: tool calls, results and settings stay exactly as they are.
|
|
4
4
|
|
|
5
5
|
[](https://badge.fury.io/js/pi-syntax-highlight)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
@@ -17,7 +17,7 @@ Start a new session and the colors are on. To try it without installing:
|
|
|
17
17
|
pi -e npm:pi-syntax-highlight
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
Needs pi 1.
|
|
20
|
+
Needs pi 1.5.1 or newer. Node 24 or newer matters only for running the working copy, not for the install.
|
|
21
21
|
|
|
22
22
|
## What gets colored
|
|
23
23
|
|
|
@@ -25,26 +25,27 @@ Needs pi 1.4 or newer. Node 24 or newer matters only for running the working cop
|
|
|
25
25
|
|---|---|
|
|
26
26
|
| `grep` | Paths and line numbers styled, each matched line highlighted in the language of its file, the match itself emphasized. The truncation footer stays. |
|
|
27
27
|
| `find`, `ls` | Directories dimmed with a trailing slash, basenames colored by file family. The limit footer stays. |
|
|
28
|
-
| `bash`, `powershell` | Finished output styled: diffs, JSON, paths, errors. A collapsed call shows its
|
|
29
|
-
| `read` |
|
|
30
|
-
| `edit` | The diff is highlighted by file language, line numbers dimmed, changed words in reverse video. A failure
|
|
31
|
-
| `write` |
|
|
32
|
-
|
|
|
33
|
-
|
|
|
34
|
-
|
|
|
28
|
+
| `bash`, `powershell` | Finished output styled: diffs, JSON, paths, errors, and a body in a recognized language (YAML, SQL, TOML, shell, Python, JavaScript, TypeScript, JSX, TSX, Go, Rust, C, C++, PHP, Ruby, PowerShell, Dockerfile, Makefile, XML, HTML). Error, warning and `path:line:` lines keep their own color inside a highlighted body. A collapsed call shows its last lines, the expand hint, and the duration. Only the first 400 lines are tokenized. |
|
|
29
|
+
| `read` | The expanded body is highlighted by file language. No line numbers, and a collapsed read stays silent, as in stock pi. The call header, errors and image results are stock. |
|
|
30
|
+
| `edit` | The successful diff is highlighted by file language, line numbers dimmed, changed words in reverse video. A failure is drawn by stock pi. |
|
|
31
|
+
| `write` | Stock pi. |
|
|
32
|
+
| Extension tools with no result renderer | JSON and diff bodies get highlighted, anything else keeps the plain content color, and the body collapses to 10 lines with the expand hint, as the host's own fallback does. |
|
|
33
|
+
| MCP tools and tools that bring their own renderer | Left to pi's renderers. |
|
|
34
|
+
| Markdown fences | A closed fence with no label gets a detected language, so the block comes out colored. A fence that already carries a label is never rewritten, and `mermaid`, `math`, `latex` and `katex` are left alone. Applies to assistant messages, thinking blocks, custom messages and summaries. |
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
Headings take the theme's accent color, with one extra attribute per level so the levels stay apart; blockquote text takes the accent color too, and inline code shows its backticks again. Nothing else in the message moves, so the text reads the same once the colors are stripped.
|
|
36
|
+
Nothing else in the markdown is restyled.
|
|
39
37
|
|
|
40
38
|
## Limits
|
|
41
39
|
|
|
40
|
+
- Fences inside lists and blockquotes are not labeled.
|
|
41
|
+
- A fence that is still streaming (not closed yet) is not labeled.
|
|
42
42
|
- A `grep` output whose own path contains `:N: ` is ambiguous, and pi does not disambiguate it either.
|
|
43
|
-
-
|
|
44
|
-
-
|
|
45
|
-
-
|
|
46
|
-
-
|
|
47
|
-
-
|
|
43
|
+
- Match emphasis in `grep` is skipped for lines longer than 500 characters and for patterns prone to catastrophic backtracking; the line is still shown.
|
|
44
|
+
- A bash body is identified and tokenized from its first 400 lines. A language that only appears after that line leaves the body flat. The 400-line limit applies to `bash` and `powershell` only.
|
|
45
|
+
- Java-style `.properties` content is detected only inside fences, not in bash output.
|
|
46
|
+
- HTML fragments are recognized by a list of known tags plus a closing tag; unknown tags stay flat. JSX without `className` or `={` can be detected as HTML.
|
|
47
|
+
- A tool whose result renderer this package does not recognize keeps its own look.
|
|
48
|
+
- No initialized theme, no color: the renderers fall back to plain tool output.
|
|
48
49
|
|
|
49
50
|
## Development
|
|
50
51
|
|
|
@@ -58,7 +59,7 @@ Load the working copy from the package directory with `pi -e .`.
|
|
|
58
59
|
|
|
59
60
|
## More
|
|
60
61
|
|
|
61
|
-
- [DEVELOPER.md](DEVELOPER.md): how the renderers and the
|
|
62
|
+
- [DEVELOPER.md](DEVELOPER.md): how the renderers and the fence labeler are built, and the tests.
|
|
62
63
|
- [CHANGELOG.md](CHANGELOG.md): what changed in each release.
|
|
63
64
|
|
|
64
65
|
## License
|
package/extensions/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { activeTheme, captureTheme } from "../src/active-theme.ts";
|
|
3
2
|
import { createMarkdownTransformer } from "../src/markdown-fence-lang.ts";
|
|
4
3
|
import { resolveToolRenderers } from "../src/resolve-renderers.ts";
|
|
5
4
|
|
|
@@ -7,16 +6,12 @@ import { resolveToolRenderers } from "../src/resolve-renderers.ts";
|
|
|
7
6
|
* pi-syntax-highlight entry point.
|
|
8
7
|
*
|
|
9
8
|
* The tool resolver wraps the host chain and overrides only the result slots
|
|
10
|
-
* this package styles; the markdown transformer labels the fences that
|
|
11
|
-
* without a language so the built-in highlighter has a grammar to paint with
|
|
12
|
-
* styles headings, blockquotes and inline code spans for the assistant message.
|
|
9
|
+
* this package styles; the markdown transformer labels the closed fences that
|
|
10
|
+
* arrive without a language so the built-in highlighter has a grammar to paint with.
|
|
13
11
|
*/
|
|
14
12
|
export default function piSyntaxHighlight(pi: ExtensionAPI): void {
|
|
15
13
|
pi.registerToolRenderer(resolveToolRenderers);
|
|
16
|
-
pi.registerMarkdownTransformer(createMarkdownTransformer({
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// reference it captures keeps resolving against the theme in effect, so no later
|
|
20
|
-
// session event is needed.
|
|
21
|
-
pi.on("session_start", (_event, ctx) => captureTheme(ctx.ui.theme));
|
|
14
|
+
pi.registerMarkdownTransformer(createMarkdownTransformer(), {
|
|
15
|
+
messageTypes: ["user", "assistant", "assistant-thinking", "custom", "summary"],
|
|
16
|
+
});
|
|
22
17
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-syntax-highlight",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"private": false,
|
|
5
|
-
"description": "Syntax highlighting for pi: colors tool output (grep, find, ls, bash, read, edit
|
|
5
|
+
"description": "Syntax highlighting for pi: colors tool output (grep, find, ls, bash, read, edit), diffs and JSON, and detects the language of unlabeled code fences in assistant markdown.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
]
|
|
32
32
|
},
|
|
33
33
|
"type": "module",
|
|
34
|
+
"files": ["extensions", "src", "README.md", "CHANGELOG.md", "DEVELOPER.md", "LICENSE"],
|
|
34
35
|
"scripts": {
|
|
35
36
|
"test": "node --experimental-strip-types --test test/unit/*.test.ts",
|
|
36
37
|
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
@@ -44,8 +45,8 @@
|
|
|
44
45
|
"diff": "^8.0.4"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
|
-
"@earendil-works/pi-coding-agent": "^1.
|
|
48
|
-
"@earendil-works/pi-tui": "^1.
|
|
48
|
+
"@earendil-works/pi-coding-agent": "^1.5.1",
|
|
49
|
+
"@earendil-works/pi-tui": "^1.5.1",
|
|
49
50
|
"typescript": "^7.0.2"
|
|
50
51
|
}
|
|
51
52
|
}
|