Add mechanicus-thinking-label extension

Monkey-patches AssistantMessageComponent.updateContent to swap the
default "Thinking..." label for "Cogitating..." when reasoning blocks
are folded. Only replaces the default — if any code path sets its own
label, we leave it alone.

Override via PI_THINKING_LABEL env var.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-23 22:33:01 +02:00
parent c5eeba1e13
commit 4953ac7e73
2 changed files with 37 additions and 0 deletions
+1
View File
@@ -13,5 +13,6 @@
!/local-llama.ts
!/markdown-body-color.ts
!/mechanicus-banner.ts
!/mechanicus-thinking-label.ts
!/scripts/
!/themes/
+36
View File
@@ -0,0 +1,36 @@
/**
* mechanicus-thinking-label — replace pi's "Thinking..." label with a
* dark-mechanicum one when assistant reasoning blocks are folded.
*
* pi's AssistantMessageComponent stores the label as an instance field
* initialised from the constructor default. pi-coding-agent never
* overrides it in its own code paths, so we can monkey-patch
* updateContent() to swap the default before rendering.
*
* Override via env var: PI_THINKING_LABEL="Cogitating…"
*/
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
import { AssistantMessageComponent } from "@mariozechner/pi-coding-agent";
const DEFAULT_LABEL = "Thinking...";
const LABEL = process.env.PI_THINKING_LABEL ?? "Cogitating...";
let patched = false;
export default function (_pi: ExtensionAPI) {
if (patched) return;
patched = true;
const proto = AssistantMessageComponent.prototype as any;
const origUpdate = proto.updateContent;
proto.updateContent = function (message: unknown) {
if (this.hiddenThinkingLabel === DEFAULT_LABEL) {
this.hiddenThinkingLabel = LABEL;
}
return origUpdate.call(this, message);
};
console.log(`[mechanicus-thinking-label] "${DEFAULT_LABEL}" -> "${LABEL}"`);
}