From 4953ac7e7365707bd0782c72afc78876a891ccd6 Mon Sep 17 00:00:00 2001 From: shahondin1624 Date: Thu, 23 Apr 2026 22:33:01 +0200 Subject: [PATCH] Add mechanicus-thinking-label extension MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- .gitignore | 1 + mechanicus-thinking-label.ts | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 mechanicus-thinking-label.ts diff --git a/.gitignore b/.gitignore index 60a76a0..89713d3 100644 --- a/.gitignore +++ b/.gitignore @@ -13,5 +13,6 @@ !/local-llama.ts !/markdown-body-color.ts !/mechanicus-banner.ts +!/mechanicus-thinking-label.ts !/scripts/ !/themes/ diff --git a/mechanicus-thinking-label.ts b/mechanicus-thinking-label.ts new file mode 100644 index 0000000..8d7e237 --- /dev/null +++ b/mechanicus-thinking-label.ts @@ -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}"`); +}