ceulen 0.26.2 → 0.28.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/CHANGELOG.md +112 -0
- package/extensions/lib/registry.ts +1 -1
- package/extensions/modules/subagent/index.ts +528 -75
- package/extensions/modules/subagent/lib/herdr-app.ts +917 -0
- package/extensions/modules/subagent/lib/herdr.ts +50 -29
- package/extensions/modules/subagent/lib/render.ts +33 -2
- package/extensions/modules/subagent/lib/rex.ts +902 -0
- package/extensions/modules/subagent/lib/runner.ts +5 -0
- package/extensions/modules/subagent/lib/widget.ts +8 -6
- package/extensions/modules/subagent/test/herdr-app.test.ts +572 -0
- package/extensions/modules/subagent/test/render-hint.test.ts +31 -0
- package/extensions/modules/subagent/test/rex.test.ts +724 -0
- package/extensions/modules/web/test/configPanel.test.ts +20 -3
- package/extensions/modules/web/test/settings.test.ts +6 -1
- package/package.json +1 -1
|
@@ -298,10 +298,14 @@ export function clearHerdrRegistry(): void {
|
|
|
298
298
|
// ---------------------------------------------------------------------------
|
|
299
299
|
|
|
300
300
|
/** herdr injects HERDR_ENV=1 + workspace/pane IDs into every managed pane. */
|
|
301
|
-
export function
|
|
301
|
+
export function herdrTuiEnvDetected(): boolean {
|
|
302
302
|
return process.env.HERDR_ENV === "1" && Boolean(process.env.HERDR_WORKSPACE_ID);
|
|
303
303
|
}
|
|
304
304
|
|
|
305
|
+
/** Alias kept for the herdr-TUI call sites; herdr-APP detection lives in
|
|
306
|
+
* lib/herdr-app.ts (HC_TERMINAL_ID, set by herdr-core in every terminal). */
|
|
307
|
+
export const herdrEnvDetected = herdrTuiEnvDetected;
|
|
308
|
+
|
|
305
309
|
/** settings.subagent.herdr === "off" (or the child recursion guard) disables herdr dispatch. */
|
|
306
310
|
export function herdrDisabled(subagentSettings: { herdr?: unknown } | undefined): boolean {
|
|
307
311
|
if (subagentSettings?.herdr === "off") return true;
|
|
@@ -749,15 +753,16 @@ export async function promptAndWait(opts: {
|
|
|
749
753
|
/** Best-effort output collection: report file first, pane scrollback fallback. */
|
|
750
754
|
/** Cap for report-file content fed back into the parent context. */
|
|
751
755
|
export const MAX_REPORT_BYTES = 256 * 1024;
|
|
752
|
-
|
|
753
|
-
export
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
756
|
+
/** Cap for the pane-scrollback fallback (also bounds {previous} in chains). */
|
|
757
|
+
export const MAX_PANE_CAPTURE_BYTES = 8 * 1024;
|
|
758
|
+
|
|
759
|
+
/** The delivery-contract report file, or undefined when absent/empty.
|
|
760
|
+
* Shared by both backends (herdr TUI + herdr-app): open + stat FIRST, read at
|
|
761
|
+
* most MAX_REPORT_BYTES (+1 sentinel) — a runaway report (GBs) must not
|
|
762
|
+
* buffer whole into memory before the cap. */
|
|
763
|
+
export async function readReportFile(resultFile: string): Promise<string | undefined> {
|
|
757
764
|
try {
|
|
758
|
-
|
|
759
|
-
// a runaway report (GBs) must not buffer whole into memory before the cap.
|
|
760
|
-
const fh = await fs.open(opts.handle.resultFile, "r");
|
|
765
|
+
const fh = await fs.open(resultFile, "r");
|
|
761
766
|
const want = Math.min((await fh.stat()).size, MAX_REPORT_BYTES + 1);
|
|
762
767
|
const raw = Buffer.alloc(want);
|
|
763
768
|
await fh.read(raw, 0, want, 0);
|
|
@@ -765,22 +770,32 @@ export async function collectResult(opts: {
|
|
|
765
770
|
const text = raw.length > MAX_REPORT_BYTES
|
|
766
771
|
? raw.subarray(0, MAX_REPORT_BYTES).toString("utf8") + "\n\n…(truncated)"
|
|
767
772
|
: raw.toString("utf8");
|
|
768
|
-
|
|
769
|
-
} catch {
|
|
773
|
+
return text.trim() ? text.trim() : undefined;
|
|
774
|
+
} catch {
|
|
775
|
+
return undefined; // no report file — caller falls back to a pane read
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
/** Tail-cap pane capture text for parent context. */
|
|
780
|
+
export function capPaneCapture(paneText: string): string {
|
|
781
|
+
return paneText.length > MAX_PANE_CAPTURE_BYTES
|
|
782
|
+
? "…(earlier pane output truncated)\n" + paneText.slice(-MAX_PANE_CAPTURE_BYTES)
|
|
783
|
+
: paneText;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
export async function collectResult(opts: {
|
|
787
|
+
handle: HerdrHandle;
|
|
788
|
+
exec: HerdrExec;
|
|
789
|
+
}): Promise<{ output: string; source: "file" | "pane" | "none" }> {
|
|
790
|
+
const fromFile = await readReportFile(opts.handle.resultFile);
|
|
791
|
+
if (fromFile) return { output: fromFile, source: "file" };
|
|
770
792
|
const read = await opts.exec(
|
|
771
793
|
"herdr",
|
|
772
794
|
["agent", "read", opts.handle.name, "--source", "recent-unwrapped", "--lines", "200"],
|
|
773
795
|
{ timeout: 10_000 },
|
|
774
796
|
);
|
|
775
797
|
const paneText = read.code === 0 ? read.stdout.trim() : "";
|
|
776
|
-
|
|
777
|
-
// turns). The final reply sits at the END, so cap to the tail — this also
|
|
778
|
-
// bounds {previous} substitution in chains.
|
|
779
|
-
const MAX_PANE_CAPTURE_BYTES = 8 * 1024;
|
|
780
|
-
const capped = paneText.length > MAX_PANE_CAPTURE_BYTES
|
|
781
|
-
? "…(earlier pane output truncated)\n" + paneText.slice(-MAX_PANE_CAPTURE_BYTES)
|
|
782
|
-
: paneText;
|
|
783
|
-
return { output: capped, source: paneText ? "pane" : "none" };
|
|
798
|
+
return { output: capPaneCapture(paneText), source: paneText ? "pane" : "none" };
|
|
784
799
|
}
|
|
785
800
|
|
|
786
801
|
/** Interrupt a delegated agent: esc first (pi interrupt), ctrl+c if still working. */
|
|
@@ -847,12 +862,12 @@ export function buildHerdrResult(
|
|
|
847
862
|
status = "success";
|
|
848
863
|
}
|
|
849
864
|
// Synthetic assistant message carrying the report — keeps getResultOutput /
|
|
850
|
-
// renderSingleResult working unchanged (they read result.messages).
|
|
851
|
-
//
|
|
852
|
-
//
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
865
|
+
// renderSingleResult working unchanged (they read result.messages). Pane
|
|
866
|
+
// output is best-effort (echoed task, TUI noise); that is flagged as the
|
|
867
|
+
// `bestEffort` DATA field below, NOT as a text prefix: a prefix travelled
|
|
868
|
+
// into `{previous}` chain substitution and derailed the next step (live
|
|
869
|
+
// 2026-11-17: the child read the marker as a prompt-injection signal).
|
|
870
|
+
const output = outcome.output;
|
|
856
871
|
const messages = (output
|
|
857
872
|
? [{ role: "assistant", content: [{ type: "text", text: output }], stopReason: "stop" }]
|
|
858
873
|
: []) as unknown as Message[];
|
|
@@ -870,6 +885,7 @@ export function buildHerdrResult(
|
|
|
870
885
|
errorMessage,
|
|
871
886
|
status,
|
|
872
887
|
durationMs: outcome.durationMs,
|
|
888
|
+
bestEffort: outcome.outputSource === "pane" && Boolean(output),
|
|
873
889
|
};
|
|
874
890
|
}
|
|
875
891
|
|
|
@@ -902,7 +918,7 @@ function advisorMarkerPath(cwd: string, stamp: string): string {
|
|
|
902
918
|
}
|
|
903
919
|
|
|
904
920
|
/** Session + report files share one stamp so they correlate per dispatch. */
|
|
905
|
-
function dispatchStamp(): string {
|
|
921
|
+
export function dispatchStamp(): string {
|
|
906
922
|
return Date.now().toString(36);
|
|
907
923
|
}
|
|
908
924
|
|
|
@@ -1054,15 +1070,20 @@ function readAdvisorMarkerFile(file: string): AdvisorMarker | undefined {
|
|
|
1054
1070
|
*
|
|
1055
1071
|
* Returns the number of steered revisions folded in.
|
|
1056
1072
|
*/
|
|
1057
|
-
async function awaitAdvisorCycle(opts: {
|
|
1073
|
+
export async function awaitAdvisorCycle(opts: {
|
|
1058
1074
|
name: string;
|
|
1059
1075
|
markerFile: string;
|
|
1060
1076
|
advisorWaitMs: number;
|
|
1061
1077
|
signal?: AbortSignal;
|
|
1062
1078
|
onPhase?: (phase: string) => void;
|
|
1063
|
-
|
|
1079
|
+
/** pane-state probe; defaults to the herdr-TUI `agent get` reader. The
|
|
1080
|
+
* herdr-app backend passes its own `hc get` probe. */
|
|
1081
|
+
exec?: HerdrExec;
|
|
1082
|
+
getState?: () => Promise<HerdrAgentState>;
|
|
1064
1083
|
}): Promise<number> {
|
|
1065
1084
|
if (opts.advisorWaitMs <= 0) return 0;
|
|
1085
|
+
const probeState = opts.getState
|
|
1086
|
+
?? (() => getAgentState(opts.name, opts.exec ?? defaultExec));
|
|
1066
1087
|
const deadline = Date.now() + opts.advisorWaitMs;
|
|
1067
1088
|
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
1068
1089
|
const stopped = () => Boolean(opts.signal?.aborted) || Date.now() >= deadline;
|
|
@@ -1093,7 +1114,7 @@ async function awaitAdvisorCycle(opts: {
|
|
|
1093
1114
|
opts.onPhase?.("advisor-revise");
|
|
1094
1115
|
let sawWorking = false;
|
|
1095
1116
|
while (!stopped()) {
|
|
1096
|
-
const state = await
|
|
1117
|
+
const state = await probeState();
|
|
1097
1118
|
if (state === "working" || state === "blocked") sawWorking = true;
|
|
1098
1119
|
else if (sawWorking && (state === "idle" || state === "done")) break;
|
|
1099
1120
|
await sleep(1000);
|
|
@@ -11,7 +11,8 @@ import * as os from "node:os";
|
|
|
11
11
|
import { getMarkdownTheme } from "@earendil-works/pi-coding-agent";
|
|
12
12
|
import { Container, Markdown, Spacer, Text } from "@earendil-works/pi-tui";
|
|
13
13
|
import type { Message } from "./types.ts";
|
|
14
|
-
import { type SubAgentResult, isFailedResult, getResultOutput, getFinalOutput } from "./runner.ts";
|
|
14
|
+
import { type SubAgentResult, isFailedResult, getResultOutput, getFinalOutput, formatPatchBlock } from "./runner.ts";
|
|
15
|
+
import { truncateParallelOutput } from "./security.ts";
|
|
15
16
|
|
|
16
17
|
// ---------------------------------------------------------------------------
|
|
17
18
|
// Safe type guards
|
|
@@ -67,6 +68,29 @@ function formatMs(ms: number): string {
|
|
|
67
68
|
return `${ms}ms`;
|
|
68
69
|
}
|
|
69
70
|
|
|
71
|
+
/**
|
|
72
|
+
* The chain result's text: the FINAL step's output first (what callers act on),
|
|
73
|
+
* then every step's report. `{previous}` only carries one step forward, so
|
|
74
|
+
* without the per-step section an intermediate step's findings vanish from the
|
|
75
|
+
* result entirely. Patches stay labeled per step for ordered merging.
|
|
76
|
+
*/
|
|
77
|
+
export function formatChainReport(finalText: string, results: SubAgentResult[]): string {
|
|
78
|
+
const perStep = results
|
|
79
|
+
.map((r, i) => {
|
|
80
|
+
const status = isFailedResult(r)
|
|
81
|
+
? `failed${r.stopReason ? ` (${r.stopReason})` : ""}`
|
|
82
|
+
: r.stopReason === "blocked"
|
|
83
|
+
? "blocked — awaiting input in its pane"
|
|
84
|
+
: "completed";
|
|
85
|
+
const body = truncateParallelOutput(getResultOutput(r));
|
|
86
|
+
const patch = formatPatchBlock(r);
|
|
87
|
+
const caveat = r.bestEffort ? " ⚠ best-effort pane capture" : "";
|
|
88
|
+
return `### Step ${i + 1}/${results.length} — ${r.agent}: ${status}${caveat}\n\n${body}${patch ? `\n\n${patch}` : ""}`;
|
|
89
|
+
})
|
|
90
|
+
.join("\n\n---\n\n");
|
|
91
|
+
return [finalText || "(no output)", `---\n\n## Chain steps (${results.length})\n\n${perStep}`].join("\n\n");
|
|
92
|
+
}
|
|
93
|
+
|
|
70
94
|
export function formatUsageStats(
|
|
71
95
|
usage: { input: number; output: number; cacheRead: number; cacheWrite: number; cost: number; contextTokens?: number; turns?: number },
|
|
72
96
|
model?: string,
|
|
@@ -255,7 +279,11 @@ export function renderSingleResult(
|
|
|
255
279
|
container.addChild(new Text(theme.fg("muted", "─── Task ───"), 0, 0));
|
|
256
280
|
container.addChild(new Text(theme.fg("dim", result.task), 0, 0));
|
|
257
281
|
container.addChild(new Spacer(1));
|
|
258
|
-
container.addChild(new Text(
|
|
282
|
+
container.addChild(new Text(
|
|
283
|
+
theme.fg("muted", "─── Output ───") +
|
|
284
|
+
(result.bestEffort ? ` ${theme.fg("warning", "(best-effort pane capture)")}` : ""),
|
|
285
|
+
0, 0,
|
|
286
|
+
));
|
|
259
287
|
if (displayItems.length === 0 && !finalOutput) {
|
|
260
288
|
container.addChild(new Text(theme.fg("muted", "(no output)"), 0, 0));
|
|
261
289
|
} else {
|
|
@@ -323,6 +351,9 @@ export function renderSingleResult(
|
|
|
323
351
|
// (When errorMessage IS set, the Error: line above already conveys it.)
|
|
324
352
|
text += `\n${theme.fg("muted", "(no output)")}`;
|
|
325
353
|
}
|
|
354
|
+
// Provenance of a scraped answer travels as DATA (result.bestEffort), never
|
|
355
|
+
// as a text prefix — a prefix would flow into `{previous}` chain payloads.
|
|
356
|
+
if (result.bestEffort) text += `\n${theme.fg("warning", "⚠ best-effort pane capture")}`;
|
|
326
357
|
const usageStr = formatUsageStats(result.usage, result.model, { toolCount, durationMs: result.durationMs, thinking: result.thinking, advisorRounds: result.advisorRounds });
|
|
327
358
|
if (usageStr) text += `\n${theme.fg("dim", usageStr)}`;
|
|
328
359
|
if (result.patch) text += `\n${theme.fg("success", "🌿 worktree")} (${result.patch.split("\n").length} diff lines)`;
|