@pi-archimedes/core 1.9.0 → 2.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Daniel Cherubini and contributors
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-archimedes/core",
3
- "version": "1.9.0",
3
+ "version": "2.0.0",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "pi-package"
@@ -1,6 +1,6 @@
1
1
  import type { Theme } from "@earendil-works/pi-coding-agent";
2
2
  import { AssistantMessageComponent, VERSION } from "@earendil-works/pi-coding-agent";
3
- import { Markdown, type MarkdownTheme, Spacer, Text } from "@earendil-works/pi-tui";
3
+ import { Markdown, type MarkdownOptions, type MarkdownTheme, Spacer, Text } from "@earendil-works/pi-tui";
4
4
  import { buildMutedMarkdownTheme } from "./theme.js";
5
5
 
6
6
  // The label we prepend to visible thinking content.
@@ -99,12 +99,52 @@ export function patchThinkingRenderer(getTheme: () => Theme): void {
99
99
  return mutedTheme;
100
100
  };
101
101
 
102
+ // Pi's native updateContent passes a `transform` (createMarkdownTransform)
103
+ // to Markdown so the markdown-transformer pipeline runs — that is what
104
+ // renders Mermaid blocks to ASCII and applies any extension transformers.
105
+ // We must preserve it here, otherwise those transformers are silently
106
+ // dropped when this patch replaces updateContent.
107
+ //
108
+ // NOTE: the `transform` option was added to @earendil-works/pi-tui in
109
+ // 0.84.1. The repo's lockfile pins 0.78.0 whose types lack the field, so we
110
+ // extend the options type locally; at runtime the field is ignored by very
111
+ // old pi-tui and honored by 0.84.1+ (which is where Mermaid rendering and
112
+ // the bug both exist).
113
+ type MarkdownOptionsWithTransform = MarkdownOptions & {
114
+ transform?: (markdown: string, availableWidth: number) => string;
115
+ };
116
+ const transformFor =
117
+ (messageType: "assistant" | "assistant-thinking") =>
118
+ (markdown: string, availableWidth: number): string => {
119
+ let out = markdown;
120
+ for (const transformer of (this as any).markdownTransformers ?? []) {
121
+ try {
122
+ const transformed = transformer(out, {
123
+ messageType,
124
+ isStreaming: this.isStreaming,
125
+ availableWidth,
126
+ });
127
+ if (typeof transformed === "string") out = transformed;
128
+ } catch {
129
+ // Keep the current markdown and continue with the next transformer.
130
+ }
131
+ }
132
+ return out;
133
+ };
134
+
102
135
  // Render content in order.
103
136
  for (let i = 0; i < message.content.length; i++) {
104
137
  const content = message.content[i];
105
138
  if (content.type === "text" && content.text.trim()) {
106
139
  this.contentContainer.addChild(
107
- new Markdown(content.text.trim(), 1, 0, this.markdownTheme),
140
+ new Markdown(
141
+ content.text.trim(),
142
+ 1,
143
+ 0,
144
+ this.markdownTheme,
145
+ undefined,
146
+ { transform: transformFor("assistant") } as MarkdownOptionsWithTransform,
147
+ ),
108
148
  );
109
149
  } else if (content.type === "thinking" && content.thinking.trim()) {
110
150
  const hasVisibleContentAfter = message.content
@@ -133,10 +173,17 @@ export function patchThinkingRenderer(getTheme: () => Theme): void {
133
173
  if (!t) continue;
134
174
  const muted = ensureMuted();
135
175
  this.contentContainer.addChild(
136
- new Markdown(thinkingContent, 1, 0, muted ?? this.markdownTheme, {
137
- color: (text: string) => t.fg("thinkingText", text),
138
- italic: true,
139
- }),
176
+ new Markdown(
177
+ thinkingContent,
178
+ 1,
179
+ 0,
180
+ muted ?? this.markdownTheme,
181
+ {
182
+ color: (text: string) => t.fg("thinkingText", text),
183
+ italic: true,
184
+ },
185
+ { transform: transformFor("assistant-thinking") } as MarkdownOptionsWithTransform,
186
+ ),
140
187
  );
141
188
  if (hasVisibleContentAfter) {
142
189
  this.contentContainer.addChild(new Spacer(1));