Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
refactor([med-ai-dispatch-server-lib-tuipromptrunner-js-198]): /simplify polish — readable warn units, JSDoc placement, defer agent-spawn parity
[._.]/ Adam Eivy2eb8409d6553
diff --git a/PLAN.md b/PLAN.mdindex bc49c5e588..53a4ed6efa 100644--- a/PLAN.md+++ b/PLAN.md@@ -18,6 +18,7 @@ _Nothing currently parked — pick the next item from the Backlog._### v2.1.0 pre-release review residue (deferred from main→release multi-agent review, 2026-05-16)+- [ ] [agent-tui-spawn-truncation-warn-parity] **[LOW][AI-DISPATCH]** `server/services/agentTuiSpawning.js:177-179` (and the `rawBuffer` slice at line ~273-274) silently slice the head of the same buffers when they cross `OUTPUT_BUFFER_HEADROOM` / `RAW_BUFFER_HEADROOM`, with no warning and no agent-metadata flag. The companion one-shot runner now sets `outputBufferTruncated` and surfaces it through the run record (see `[med-ai-dispatch-server-lib-tuipromptrunner-js-198]`). Long-running CoS agents using `agentTuiSpawning.js` mostly stream to `output.txt` via `appendAgentOutputLines`, so the buffer overflow here is less load-bearing — but the same warn-once + agent-metadata flag would close the visibility gap. Deferred from `[med-ai-dispatch-server-lib-tuipromptrunner-js-198]` to keep that PR scoped.- [ ] [med-tests-no-direct-tests-for-executetuirun-pty] **[MED][TESTS]** No direct tests for `executeTuiRun` PTY mechanics — idle-complete, hard-timeout, missing-binary early-fail, `emitRunStarted` shape, CLAUDECODE env stripping. The new `tuiPromptRunner.test.js` only covers `cleanTuiResponse`.- [ ] [med-importer-server-routes-importer-test-js-no] **[MED][IMPORTER]** `server/routes/importer.test.js` — no test pins `ERR_PARTIAL_COMMIT_ISSUES → 207` status mapping. Future refactor that drops the entry from `SERVICE_ERROR_STATUS` would 500 on partial commits and trigger pager alerts (the in-code comment's stated regression).- [ ] [med-importer-server-services-importer-test-js-no] **[MED][IMPORTER]** `server/services/importer.test.js` — no test exercises `existingCanonBlock` dedupe wiring. A regression that wires `null` would silently degrade second-pass imports. Assert `mockRunStagedLLM.mock.calls[0][1].existingCanonBlock` contains a seeded character name.diff --git a/server/lib/tuiPromptRunner.js b/server/lib/tuiPromptRunner.jsindex f8630a599c..b897fb1c59 100644--- a/server/lib/tuiPromptRunner.js+++ b/server/lib/tuiPromptRunner.js@@ -245,7 +245,7 @@ ${prompt}`;outputBuffer = outputBuffer.slice(-OUTPUT_BUFFER_CAP);if (!outputBufferTruncated) {outputBufferTruncated = true;- console.warn(`⚠️ TUI run ${runId} output buffer exceeded ${OUTPUT_BUFFER_HEADROOM} bytes — head dropped (response file is the authoritative path; fallback may be incomplete)`);+ console.warn(`⚠️ TUI run ${runId} output buffer exceeded ${Math.round(OUTPUT_BUFFER_HEADROOM / 1024 / 1024)}MB — head dropped (response file is the authoritative path; fallback may be incomplete)`);}}onData?.(stripped);@@ -373,22 +373,6 @@ ${prompt}`;});}-/**- * Best-effort response cleanup for an already-ANSI-stripped TUI buffer.- *- * The TUI buffer is a screen, not a log — it contains banner art, the- * pasted prompt echoed back, status lines ("thinking...", token counters),- * box-drawing characters around the input prompt, and the model's response- * interleaved with all of it. Reliable carve-out would need per-binary- * scrapers; this helper just drops the obvious bits (paste marker + echoed- * prompt) and leaves downstream consumers (`extractJson`,- * `extractCodexAssistant`) to find structured content in the rest.- *- * Input is assumed pre-stripped of ANSI codes (the central handler streams- * each chunk through `createStreamingAnsiStripper` during accumulation, so- * `outputBuffer` is already clean). Don't strip again — it's a wasted scan- * over up to 1MB of text.- *//*** Pick the TUI response text — preferring the file the model was directed* to write, falling back to the cleaned screen scrape.@@ -410,6 +394,22 @@ export async function resolveTuiResponseText({ success, responseFilePath, outputreturn { text: cleanTuiResponse(outputBuffer, wrappedPrompt), usedResponseFile: false };}+/**+ * Best-effort response cleanup for an already-ANSI-stripped TUI buffer.+ *+ * The TUI buffer is a screen, not a log — it contains banner art, the+ * pasted prompt echoed back, status lines ("thinking...", token counters),+ * box-drawing characters around the input prompt, and the model's response+ * interleaved with all of it. Reliable carve-out would need per-binary+ * scrapers; this helper just drops the obvious bits (paste marker + echoed+ * prompt) and leaves downstream consumers (`extractJson`,+ * `extractCodexAssistant`) to find structured content in the rest.+ *+ * Input is assumed pre-stripped of ANSI codes (the central handler streams+ * each chunk through `createStreamingAnsiStripper` during accumulation, so+ * `outputBuffer` is already clean). Don't strip again — it's a wasted scan+ * over up to `OUTPUT_BUFFER_CAP` bytes of text.+ */export function cleanTuiResponse(strippedText, prompt) {if (typeof strippedText !== 'string' || !strippedText) return '';let text = strippedText.replace(/\[Pasted text #\d+[^\]]*\]/g, '');