@xzzpig/pi-subagents 0.7.0 → 0.9.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 +456 -4
- package/README.md +3 -3
- package/agents/claude-code-writer.md +15 -0
- package/agents/claude-code.md +15 -0
- package/agents/codex-exec-writer.md +15 -0
- package/agents/codex-exec.md +15 -0
- package/agents/cursor-agent-writer.md +14 -0
- package/agents/cursor-agent.md +14 -0
- package/agents/reviewer.md +13 -3
- package/agents/scout.md +1 -1
- package/docs/agents.md +154 -42
- package/docs/configuration.md +85 -26
- package/docs/extension-api.md +81 -16
- package/docs/missions.md +2 -0
- package/docs/models.md +75 -11
- package/docs/observability.md +34 -21
- package/docs/tool-reference.md +142 -18
- package/docs/watchdog.md +92 -114
- package/docs/workflows.md +148 -4
- package/index.ts +10 -1
- package/install.mjs +1 -1
- package/package.json +7 -6
- package/prompts/council.md +19 -7
- package/prompts/parallel-review.md +5 -1
- package/prompts/review-loop.md +11 -7
- package/skills/council-mode/SKILL.md +44 -215
- package/skills/council-mode/references/pass-contracts.md +150 -0
- package/skills/pi-subagents/SKILL.md +90 -32
- package/skills/pi-subagents/references/constraints-and-recipes.md +34 -223
- package/skills/pi-subagents/references/execution-controls.md +104 -19
- package/skills/pi-subagents/references/management-authoring-rpc.md +5 -5
- package/skills/pi-subagents/references/multi-lane-orchestration.md +16 -4
- package/skills/pi-subagents/references/prompting-and-roles.md +71 -36
- package/skills/pi-subagents/references/review-and-validation.md +73 -0
- package/src/agents/agent-management.ts +471 -114
- package/src/agents/agent-refinements.ts +4 -4
- package/src/agents/agent-serializer.ts +16 -4
- package/src/agents/agents.ts +1076 -351
- package/src/agents/builtin-names.ts +6 -0
- package/src/agents/runtime-agent-events.ts +70 -0
- package/src/agents/runtime-agent-registry.ts +31 -20
- package/src/api/agents.ts +10 -5
- package/src/api/background-work.ts +12 -3
- package/src/api/capability-ceiling.ts +0 -1
- package/src/api/{pi-args.ts → child-tool-plan.ts} +1 -1
- package/src/api/delegation.ts +0 -7
- package/src/api/external-job-provider.ts +10 -1
- package/src/api/external-runs.ts +67 -4
- package/src/api/preflight.ts +97 -34
- package/src/api/project-panes.ts +2 -0
- package/src/api/shared-types.ts +6 -0
- package/src/extension/config.ts +90 -0
- package/src/extension/doctor.ts +15 -13
- package/src/extension/fanout-child.ts +17 -16
- package/src/extension/index.ts +139 -41
- package/src/extension/public-execution.ts +113 -22
- package/src/extension/rpc.ts +182 -13
- package/src/extension/schemas.ts +63 -21
- package/src/extension/tool-description.ts +48 -23
- package/src/extension/tool-result.ts +19 -0
- package/src/inspectors/herdr/actions.ts +2 -1
- package/src/inspectors/herdr/client.ts +3 -3
- package/src/inspectors/herdr/focus.ts +55 -0
- package/src/inspectors/herdr/inspector-runner.ts +21 -23
- package/src/inspectors/herdr/project-panes.ts +228 -44
- package/src/inspectors/herdr/session-roots-codec.ts +42 -0
- package/src/integrations/herdr-status.ts +75 -5
- package/src/intercom/native-supervisor-channel.ts +138 -60
- package/src/intercom/result-intercom.ts +2 -0
- package/src/intercom/supervisor-ui.ts +243 -0
- package/src/profiles/profiles.ts +5 -6
- package/src/runs/background/active-async-capacity.ts +103 -18
- package/src/runs/background/async-execution.ts +492 -125
- package/src/runs/background/async-job-tracker.ts +127 -28
- package/src/runs/background/async-resume.ts +67 -29
- package/src/runs/background/async-retention.ts +21 -4
- package/src/runs/background/async-status-snapshot.ts +23 -261
- package/src/runs/background/async-status.ts +199 -14
- package/src/runs/background/auto-drain.ts +1 -1
- package/src/runs/background/chain-append.ts +8 -3
- package/src/runs/background/chain-root-attachment.ts +79 -8
- package/src/runs/background/control-channel.ts +101 -214
- package/src/runs/background/fleet-view.ts +38 -22
- package/src/runs/background/inspect-rpc.ts +8 -8
- package/src/runs/background/notify.ts +295 -8
- package/src/runs/background/process-terminal.ts +16 -0
- package/src/runs/background/result-delivery-ownership.ts +45 -0
- package/src/runs/background/result-files.ts +28 -14
- package/src/runs/background/result-watcher.ts +43 -19
- package/src/runs/background/resume-guidance.ts +2 -2
- package/src/runs/background/retained-children.ts +1 -1
- package/src/runs/background/run-child-session.ts +613 -0
- package/src/runs/background/run-status.ts +99 -18
- package/src/runs/background/runner-aliases.ts +125 -0
- package/src/runs/background/runner-child-sessions.ts +31 -0
- package/src/runs/background/scheduled-runs.ts +174 -18
- package/src/runs/background/stale-run-reconciler.ts +13 -4
- package/src/runs/background/steering.ts +8 -15
- package/src/runs/background/subagent-runner.ts +959 -1159
- package/src/runs/background/subagent-wait.ts +86 -31
- package/src/runs/background/terminal-run-index.ts +1 -1
- package/src/runs/background/wait-completions.ts +45 -2
- package/src/runs/background/wait-config.ts +23 -9
- package/src/runs/background/wait-tool.ts +27 -19
- package/src/runs/foreground/async-steering-action.ts +3 -19
- package/src/runs/foreground/async-stop-action.ts +23 -2
- package/src/runs/foreground/execution.ts +585 -481
- package/src/runs/foreground/foreground-control.ts +13 -0
- package/src/runs/foreground/foreground-history.ts +26 -3
- package/src/runs/foreground/subagent-executor.ts +1549 -410
- package/src/runs/foreground/workflow-detach-reconcile.ts +141 -104
- package/src/runs/foreground/workflow-foreground-steering.ts +24 -98
- package/src/runs/shared/abort-recovery.ts +119 -0
- package/src/runs/shared/acceptance.ts +147 -39
- package/src/runs/shared/agent-contract.ts +1 -1
- package/src/runs/shared/async-status-projection.ts +565 -0
- package/src/runs/shared/background-process-options.ts +9 -0
- package/src/runs/shared/capability-ceiling.ts +2 -2
- package/src/runs/shared/child-hooks.ts +25 -0
- package/src/runs/shared/child-identity.ts +62 -0
- package/src/runs/shared/child-launch-plan.ts +151 -0
- package/src/runs/shared/child-launch.ts +314 -0
- package/src/runs/shared/child-lifecycle.ts +25 -0
- package/src/runs/shared/child-runtime-config.ts +126 -0
- package/src/runs/shared/child-session.ts +342 -0
- package/src/runs/shared/child-tool-plan.ts +540 -0
- package/src/runs/shared/claude-code-adapter.ts +133 -0
- package/src/runs/shared/codex-exec-adapter.ts +129 -0
- package/src/runs/shared/completion-evidence.ts +89 -0
- package/src/runs/shared/completion-guard.ts +57 -6
- package/src/runs/shared/cursor-agent-adapter.ts +114 -0
- package/src/runs/shared/dynamic-fanout.ts +4 -4
- package/src/runs/shared/extension-bindings.ts +78 -0
- package/src/runs/shared/external-cli-contract.ts +167 -0
- package/src/runs/shared/external-cli-preflight.ts +138 -0
- package/src/runs/shared/external-cli-runner.ts +349 -54
- package/src/runs/shared/external-job-bridge.ts +53 -37
- package/src/runs/shared/external-job-runner.ts +126 -23
- package/src/runs/shared/fast-mode-extension.ts +10 -0
- package/src/runs/shared/host-step-status.ts +231 -0
- package/src/runs/shared/lane-metadata.ts +126 -0
- package/src/runs/shared/launch-cwd.ts +16 -0
- package/src/runs/shared/long-running-guard.ts +2 -1
- package/src/runs/shared/mcp-config-sources.ts +422 -0
- package/src/runs/shared/mcp-direct-tool-allowlist.ts +222 -158
- package/src/runs/shared/mcp-direct-tool-grant.ts +194 -0
- package/src/runs/shared/model-exclusions.ts +141 -10
- package/src/runs/shared/model-fallback.ts +187 -33
- package/src/runs/shared/model-scope.ts +106 -39
- package/src/runs/shared/mutation-evidence.ts +199 -0
- package/src/runs/shared/nested-events.ts +38 -48
- package/src/runs/shared/nested-path.ts +0 -14
- package/src/runs/shared/nested-render.ts +9 -5
- package/src/runs/shared/orca-progress-tabs.ts +83 -16
- package/src/runs/shared/parallel-handoff.ts +423 -7
- package/src/runs/shared/parallel-utils.ts +28 -5
- package/src/runs/shared/permissions.ts +1 -14
- package/src/runs/shared/pi-spawn.ts +69 -35
- package/src/runs/shared/process-signal.ts +16 -0
- package/src/runs/shared/run-fanout-budget.ts +0 -13
- package/src/runs/shared/run-history.ts +21 -1
- package/src/runs/shared/runtime-acknowledged-extensions.ts +0 -27
- package/src/runs/shared/single-output.ts +89 -22
- package/src/runs/shared/structured-output.ts +61 -7
- package/src/runs/shared/subagent-control.ts +6 -2
- package/src/runs/shared/subagent-prompt-runtime.ts +216 -360
- package/src/runs/shared/task-intent.ts +21 -7
- package/src/runs/shared/tool-availability.ts +18 -64
- package/src/runs/shared/tool-budget.ts +0 -14
- package/src/runs/shared/tool-timeout.ts +1 -1
- package/src/runs/shared/workflow-graph.ts +16 -0
- package/src/runs/shared/worktree-cleanup-plan.ts +866 -0
- package/src/runs/shared/worktree.ts +571 -62
- package/src/shared/atomic-json.ts +3 -1
- package/src/shared/child-session-name.ts +46 -0
- package/src/shared/extension-context.ts +24 -0
- package/src/shared/fork-context.ts +21 -12
- package/src/shared/fork-session-cwd.ts +27 -0
- package/src/shared/formatters.ts +18 -3
- package/src/shared/jsonl-writer.ts +11 -0
- package/src/shared/launch-contract.ts +20 -6
- package/src/shared/pruned-fork.ts +450 -0
- package/src/shared/session-file-trust.ts +19 -0
- package/src/shared/session-tokens.ts +14 -3
- package/src/shared/settings.ts +21 -102
- package/src/shared/shortcuts.ts +17 -0
- package/src/shared/thinking-ceiling.ts +46 -0
- package/src/shared/types.ts +644 -75
- package/src/shared/utils.ts +60 -93
- package/src/shared/workflow-child-permit.ts +207 -0
- package/src/slash/delegation-adapters.ts +1 -9
- package/src/slash/delegation-request.ts +0 -4
- package/src/slash/prompt-template-bridge.ts +37 -1
- package/src/slash/slash-bridge.ts +1 -2
- package/src/slash/slash-commands.ts +383 -116
- package/src/slash/slash-live-state.ts +22 -11
- package/src/slash/subagents-admin.ts +29 -12
- package/src/tui/fleet-native-transcript.ts +4 -0
- package/src/tui/fleet-status.ts +278 -90
- package/src/tui/fleet-transcript.ts +11 -5
- package/src/tui/fleet.ts +54 -28
- package/src/tui/render-helpers.ts +31 -0
- package/src/tui/render.ts +1433 -166
- package/src/watchdog/change-signature.ts +40 -1
- package/src/watchdog/child-status.ts +54 -34
- package/src/watchdog/diff-tool.ts +77 -0
- package/src/watchdog/emission-guard.ts +5 -3
- package/src/watchdog/guidance.ts +20 -0
- package/src/watchdog/permission-arbiter.ts +59 -52
- package/src/watchdog/register-child.ts +28 -25
- package/src/watchdog/register-main.ts +10 -9
- package/src/watchdog/render.ts +4 -5
- package/src/watchdog/review.ts +15 -4
- package/src/watchdog/rules.ts +70 -0
- package/src/watchdog/runtime.ts +75 -92
- package/src/watchdog/scope.ts +0 -11
- package/src/watchdog/settings.ts +48 -104
- package/src/watchdog/turn-delta.ts +1 -1
- package/src/watchdog/types.ts +18 -32
- package/src/watchdog/warning-format.ts +0 -1
- package/src/workflows/chat-progress.ts +7 -3
- package/src/workflows/host-command.ts +235 -0
- package/src/workflows/scripted-workflow.ts +1142 -69
- package/src/workflows/workflow-checklist.ts +439 -0
- package/src/workflows/workflow-child-summary.ts +121 -0
- package/src/workflows/workflow-preflight.ts +297 -0
- package/src/workflows/workflow-receipt.ts +232 -6
- package/src/workflows/workflow-resources.ts +150 -0
- package/src/workflows/workflow-settlement.ts +246 -0
- package/src/runs/shared/child-protocol.ts +0 -401
- package/src/runs/shared/pi-args.ts +0 -858
- package/src/runs/shared/subagent-startup-retry.ts +0 -116
- package/src/runs/shared/turn-budget.ts +0 -98
- package/src/shared/post-exit-stdio-guard.ts +0 -85
|
@@ -4,8 +4,9 @@ import type { AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
|
4
4
|
import { getPiSpawnCommand } from "../../runs/shared/pi-spawn.ts";
|
|
5
5
|
import { getProjectSubagentsDir } from "../../shared/artifacts.ts";
|
|
6
6
|
import { writeAtomicJson } from "../../shared/atomic-json.ts";
|
|
7
|
-
import type { Details } from "../../shared/types.ts";
|
|
7
|
+
import type { Details, HerdrProjectPaneSnapshot, SubagentState } from "../../shared/types.ts";
|
|
8
8
|
import { createHerdrClient, detectHerdr, type HerdrClient, type HerdrErrorCode } from "./client.ts";
|
|
9
|
+
import { focusHerdrPane, herdrPaneFocusTarget, herdrPaneRecord } from "./focus.ts";
|
|
9
10
|
import { formatShellCommand } from "./shell-command.ts";
|
|
10
11
|
|
|
11
12
|
export const HERDR_PROJECT_PANE_ACTIONS = ["project.open", "project.status", "project.close"] as const;
|
|
@@ -34,6 +35,9 @@ export interface ProjectPaneRuntime {
|
|
|
34
35
|
cwd?: string;
|
|
35
36
|
foregroundCwd?: string;
|
|
36
37
|
focused?: boolean;
|
|
38
|
+
tabId?: string;
|
|
39
|
+
workspaceId?: string;
|
|
40
|
+
summary?: string;
|
|
37
41
|
terminalTitle?: string;
|
|
38
42
|
}
|
|
39
43
|
|
|
@@ -44,6 +48,7 @@ export type ProjectPaneErrorCode = HerdrErrorCode
|
|
|
44
48
|
| "BINDING_READ_FAILED"
|
|
45
49
|
| "BINDING_WRITE_FAILED"
|
|
46
50
|
| "BINDING_REMOVE_FAILED"
|
|
51
|
+
| "PANE_FOCUS_UNSUPPORTED"
|
|
47
52
|
| "PANE_NOT_IDLE"
|
|
48
53
|
| "PANE_OWNERSHIP_UNVERIFIED";
|
|
49
54
|
|
|
@@ -87,6 +92,13 @@ export interface CloseProjectPaneData extends ProjectPaneCommonData {
|
|
|
87
92
|
runtime?: ProjectPaneRuntime;
|
|
88
93
|
}
|
|
89
94
|
|
|
95
|
+
export interface FocusProjectPaneData extends ProjectPaneCommonData {
|
|
96
|
+
binding: HerdrProjectPaneBinding;
|
|
97
|
+
runtime: ProjectPaneRuntime;
|
|
98
|
+
ownership: "verified" | "unknown" | "mismatch";
|
|
99
|
+
focused: { paneId: string; tabId?: string; workspaceId?: string };
|
|
100
|
+
}
|
|
101
|
+
|
|
90
102
|
export interface OpenProjectPaneOptions {
|
|
91
103
|
cwd: string;
|
|
92
104
|
message?: string;
|
|
@@ -106,12 +118,7 @@ export interface CloseProjectPaneOptions {
|
|
|
106
118
|
signal?: AbortSignal;
|
|
107
119
|
}
|
|
108
120
|
|
|
109
|
-
export
|
|
110
|
-
run<T = unknown>(
|
|
111
|
-
args: string[],
|
|
112
|
-
options?: { timeoutMs?: number; signal?: AbortSignal; textOk?: boolean },
|
|
113
|
-
): Promise<{ ok: true; data: T } | { ok: false; error: { code: HerdrErrorCode; message: string; details?: unknown } }>;
|
|
114
|
-
}
|
|
121
|
+
export type ProjectPaneCommandClient = Pick<HerdrClient, "run">;
|
|
115
122
|
|
|
116
123
|
export interface ProjectPaneManagerOptions {
|
|
117
124
|
client?: ProjectPaneCommandClient;
|
|
@@ -121,6 +128,7 @@ export interface ProjectPaneManagerOptions {
|
|
|
121
128
|
export interface ProjectPaneManager {
|
|
122
129
|
open(options: OpenProjectPaneOptions): Promise<ProjectPaneResult<OpenProjectPaneData>>;
|
|
123
130
|
status(options: GetProjectPaneStatusOptions): Promise<ProjectPaneResult<ProjectPaneStatusData>>;
|
|
131
|
+
focus(options: GetProjectPaneStatusOptions): Promise<ProjectPaneResult<FocusProjectPaneData>>;
|
|
124
132
|
close(options: CloseProjectPaneOptions): Promise<ProjectPaneResult<CloseProjectPaneData>>;
|
|
125
133
|
}
|
|
126
134
|
|
|
@@ -129,6 +137,12 @@ interface InternalProjectPaneManagerOptions extends ProjectPaneManagerOptions {
|
|
|
129
137
|
legacyToolCompatibility?: boolean;
|
|
130
138
|
}
|
|
131
139
|
|
|
140
|
+
interface HerdrProjectPaneRootIndex {
|
|
141
|
+
schemaVersion: 1;
|
|
142
|
+
kind: "herdr-project-pane-roots";
|
|
143
|
+
projectRoots: string[];
|
|
144
|
+
}
|
|
145
|
+
|
|
132
146
|
interface ProjectPaneParams {
|
|
133
147
|
cwd?: string;
|
|
134
148
|
message?: string;
|
|
@@ -137,6 +151,7 @@ interface ProjectPaneParams {
|
|
|
137
151
|
|
|
138
152
|
interface ProjectPaneDeps {
|
|
139
153
|
cwd: string;
|
|
154
|
+
state?: SubagentState;
|
|
140
155
|
client?: HerdrClient;
|
|
141
156
|
signal?: AbortSignal;
|
|
142
157
|
now?: () => Date;
|
|
@@ -162,6 +177,51 @@ export function projectPaneBindingPath(projectRoot: string): string {
|
|
|
162
177
|
return path.join(projectPaneDir(projectRoot), "herdr.json");
|
|
163
178
|
}
|
|
164
179
|
|
|
180
|
+
function projectPaneRootIndexPath(ownerRoot: string): string {
|
|
181
|
+
return path.join(projectPaneDir(ownerRoot), "herdr-roots.json");
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function parseRootIndex(value: unknown): string[] {
|
|
185
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("Invalid Herdr project pane root index.");
|
|
186
|
+
const input = value as Partial<HerdrProjectPaneRootIndex>;
|
|
187
|
+
if (input.schemaVersion !== 1 || input.kind !== "herdr-project-pane-roots" || !Array.isArray(input.projectRoots)) throw new Error("Invalid Herdr project pane root index.");
|
|
188
|
+
if (!input.projectRoots.every((root) => typeof root === "string" && root.length > 0)) throw new Error("Invalid Herdr project pane root index.");
|
|
189
|
+
return input.projectRoots;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function listHerdrProjectPaneRoots(ownerRoot: string): string[] {
|
|
193
|
+
try {
|
|
194
|
+
return parseRootIndex(JSON.parse(fs.readFileSync(projectPaneRootIndexPath(ownerRoot), "utf-8")));
|
|
195
|
+
} catch (error) {
|
|
196
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
197
|
+
if (code === "ENOENT" || code === "ENOTDIR") return [];
|
|
198
|
+
throw error;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function writeHerdrProjectPaneRoot(ownerRoot: string, projectRoot: string): void {
|
|
203
|
+
const projectRoots = [...new Set([...listHerdrProjectPaneRoots(ownerRoot), projectRoot])].sort();
|
|
204
|
+
writeAtomicJson(projectPaneRootIndexPath(ownerRoot), {
|
|
205
|
+
schemaVersion: 1,
|
|
206
|
+
kind: "herdr-project-pane-roots",
|
|
207
|
+
projectRoots,
|
|
208
|
+
} satisfies HerdrProjectPaneRootIndex);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function removeHerdrProjectPaneRoot(ownerRoot: string, projectRoot: string): void {
|
|
212
|
+
const projectRoots = listHerdrProjectPaneRoots(ownerRoot).filter((root) => root !== projectRoot);
|
|
213
|
+
const file = projectPaneRootIndexPath(ownerRoot);
|
|
214
|
+
if (projectRoots.length === 0) {
|
|
215
|
+
fs.rmSync(file, { force: true });
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
writeAtomicJson(file, {
|
|
219
|
+
schemaVersion: 1,
|
|
220
|
+
kind: "herdr-project-pane-roots",
|
|
221
|
+
projectRoots,
|
|
222
|
+
} satisfies HerdrProjectPaneRootIndex);
|
|
223
|
+
}
|
|
224
|
+
|
|
165
225
|
function parseBinding(value: unknown, strict = false): HerdrProjectPaneBinding | undefined {
|
|
166
226
|
if (!value || typeof value !== "object" || Array.isArray(value)) return undefined;
|
|
167
227
|
const input = value as Partial<HerdrProjectPaneBinding>;
|
|
@@ -224,27 +284,60 @@ export function readProjectPaneBinding(projectRoot: string): ProjectPaneResult<H
|
|
|
224
284
|
return { ok: true, data: read.binding };
|
|
225
285
|
}
|
|
226
286
|
|
|
227
|
-
function
|
|
287
|
+
function herdrProjectPaneSnapshotFromBinding(binding: HerdrProjectPaneBinding, now = Date.now()): HerdrProjectPaneSnapshot {
|
|
288
|
+
return {
|
|
289
|
+
projectRoot: binding.projectRoot,
|
|
290
|
+
bindingPath: projectPaneBindingPath(binding.projectRoot),
|
|
291
|
+
paneId: binding.paneId,
|
|
292
|
+
openedAt: binding.openedAt,
|
|
293
|
+
...(binding.lastFocusedAt ? { lastFocusedAt: binding.lastFocusedAt } : {}),
|
|
294
|
+
state: "open",
|
|
295
|
+
agentStatus: "unknown",
|
|
296
|
+
ownership: "unknown",
|
|
297
|
+
safeToClose: false,
|
|
298
|
+
refreshedAt: now,
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export function restoreHerdrProjectPaneSnapshots(state: SubagentState, projectRoots: Iterable<string>, now = Date.now()): void {
|
|
303
|
+
const restored = new Map(state.herdrProjectPanes ?? []);
|
|
304
|
+
for (const projectRoot of projectRoots) {
|
|
305
|
+
const binding = readHerdrProjectPaneBinding(projectRoot);
|
|
306
|
+
if (binding) restored.set(binding.projectRoot, herdrProjectPaneSnapshotFromBinding(binding, now));
|
|
307
|
+
}
|
|
308
|
+
state.herdrProjectPanes = restored;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function sanitizedSummary(value: unknown): string | undefined {
|
|
312
|
+
if (typeof value !== "string") return undefined;
|
|
313
|
+
const cleaned = value.replace(/[\u0000-\u001f\u007f]/g, " ").replace(/\s+/g, " ").trim();
|
|
314
|
+
return cleaned ? cleaned.slice(0, 120) : undefined;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function nestedRecord(value: unknown, key: string): Record<string, unknown> | undefined {
|
|
228
318
|
if (!value || typeof value !== "object" || Array.isArray(value)) return undefined;
|
|
229
|
-
const
|
|
230
|
-
return
|
|
231
|
-
? record.pane as Record<string, unknown>
|
|
232
|
-
: record;
|
|
319
|
+
const child = (value as Record<string, unknown>)[key];
|
|
320
|
+
return child && typeof child === "object" && !Array.isArray(child) ? child as Record<string, unknown> : undefined;
|
|
233
321
|
}
|
|
234
322
|
|
|
235
|
-
function
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
323
|
+
function paneSummary(pane: Record<string, unknown>): string | undefined {
|
|
324
|
+
return sanitizedSummary(pane.summary)
|
|
325
|
+
?? sanitizedSummary(pane.state_text)
|
|
326
|
+
?? sanitizedSummary(pane.stateText)
|
|
327
|
+
?? sanitizedSummary(pane.token_summary)
|
|
328
|
+
?? sanitizedSummary(nestedRecord(pane, "tokens")?.summary)
|
|
329
|
+
?? sanitizedSummary(nestedRecord(pane, "metadata")?.summary)
|
|
330
|
+
?? sanitizedSummary(nestedRecord(nestedRecord(pane, "metadata"), "tokens")?.summary);
|
|
240
331
|
}
|
|
241
332
|
|
|
242
333
|
function projectPaneRuntime(value: unknown): ProjectPaneRuntime | undefined {
|
|
243
|
-
const pane =
|
|
244
|
-
const
|
|
334
|
+
const pane = herdrPaneRecord(value);
|
|
335
|
+
const focusTarget = herdrPaneFocusTarget(value);
|
|
336
|
+
const paneId = focusTarget.paneId;
|
|
245
337
|
if (!pane || !paneId) return undefined;
|
|
246
338
|
const text = (key: string): string | undefined => typeof pane[key] === "string" ? pane[key] as string : undefined;
|
|
247
339
|
const agentStatus = text("agent_status") ?? text("agentStatus") ?? "unknown";
|
|
340
|
+
const summary = paneSummary(pane);
|
|
248
341
|
return {
|
|
249
342
|
paneId,
|
|
250
343
|
...(text("agent") ? { agent: text("agent") } : {}),
|
|
@@ -252,12 +345,48 @@ function projectPaneRuntime(value: unknown): ProjectPaneRuntime | undefined {
|
|
|
252
345
|
...(text("cwd") ? { cwd: text("cwd") } : {}),
|
|
253
346
|
...(text("foreground_cwd") || text("foregroundCwd") ? { foregroundCwd: text("foreground_cwd") ?? text("foregroundCwd") } : {}),
|
|
254
347
|
...(typeof pane.focused === "boolean" ? { focused: pane.focused } : {}),
|
|
348
|
+
...(focusTarget.tabId ? { tabId: focusTarget.tabId } : {}),
|
|
349
|
+
...(focusTarget.workspaceId ? { workspaceId: focusTarget.workspaceId } : {}),
|
|
350
|
+
...(summary ? { summary } : {}),
|
|
255
351
|
...(text("terminal_title_stripped") || text("terminal_title") || text("terminalTitle")
|
|
256
352
|
? { terminalTitle: text("terminal_title_stripped") ?? text("terminal_title") ?? text("terminalTitle") }
|
|
257
353
|
: {}),
|
|
258
354
|
};
|
|
259
355
|
}
|
|
260
356
|
|
|
357
|
+
function herdrProjectPaneSnapshotFromStatus(data: ProjectPaneStatusData, now: number): HerdrProjectPaneSnapshot | undefined {
|
|
358
|
+
if (data.state === "absent" || !data.binding) return undefined;
|
|
359
|
+
return {
|
|
360
|
+
projectRoot: data.projectRoot,
|
|
361
|
+
bindingPath: data.bindingPath,
|
|
362
|
+
paneId: data.binding.paneId,
|
|
363
|
+
openedAt: data.binding.openedAt,
|
|
364
|
+
...(data.binding.lastFocusedAt ? { lastFocusedAt: data.binding.lastFocusedAt } : {}),
|
|
365
|
+
state: data.state,
|
|
366
|
+
agentStatus: data.runtime?.agentStatus ?? "unknown",
|
|
367
|
+
ownership: data.ownership,
|
|
368
|
+
safeToClose: data.safeToClose,
|
|
369
|
+
refreshedAt: now,
|
|
370
|
+
...(data.runtime?.summary ? { summary: data.runtime.summary } : {}),
|
|
371
|
+
...(data.runtime?.tabId ? { tabId: data.runtime.tabId } : {}),
|
|
372
|
+
...(data.runtime?.workspaceId ? { workspaceId: data.runtime.workspaceId } : {}),
|
|
373
|
+
...(data.runtime?.terminalTitle ? { terminalTitle: data.runtime.terminalTitle } : {}),
|
|
374
|
+
...(data.staleReason ? { staleReason: data.staleReason.message } : {}),
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function rememberProjectPane(state: SubagentState | undefined, data: ProjectPaneStatusData, now: number): void {
|
|
379
|
+
if (!state) return;
|
|
380
|
+
state.herdrProjectPanes ??= new Map();
|
|
381
|
+
const snapshot = herdrProjectPaneSnapshotFromStatus(data, now);
|
|
382
|
+
if (snapshot) state.herdrProjectPanes.set(data.projectRoot, snapshot);
|
|
383
|
+
else state.herdrProjectPanes.delete(data.projectRoot);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function forgetProjectPane(state: SubagentState | undefined, projectRoot: string): void {
|
|
387
|
+
state?.herdrProjectPanes?.delete(projectRoot);
|
|
388
|
+
}
|
|
389
|
+
|
|
261
390
|
function resolveProjectRoot(requested: string): ProjectPaneResult<string> {
|
|
262
391
|
const resolved = path.resolve(requested);
|
|
263
392
|
try {
|
|
@@ -379,6 +508,41 @@ function createProjectPaneManagerInternal(options: InternalProjectPaneManagerOpt
|
|
|
379
508
|
} };
|
|
380
509
|
},
|
|
381
510
|
|
|
511
|
+
async focus(input) {
|
|
512
|
+
const status = await this.status(input);
|
|
513
|
+
if (!status.ok) return projectPaneError(status.error.code, status.error.message, status.error);
|
|
514
|
+
if (status.data.state !== "open" || !status.data.binding || !status.data.runtime) {
|
|
515
|
+
return projectPaneError("PANE_GONE", `No open Herdr project pane binding exists for '${status.data.projectRoot}'.`, {
|
|
516
|
+
projectRoot: status.data.projectRoot, bindingPath: status.data.bindingPath,
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
if (status.data.ownership !== "verified") {
|
|
520
|
+
return projectPaneError("PANE_OWNERSHIP_UNVERIFIED", `Project pane '${status.data.binding.paneId}' ownership is '${status.data.ownership}' for '${status.data.projectRoot}'.`, {
|
|
521
|
+
projectRoot: status.data.projectRoot, bindingPath: status.data.bindingPath, details: status.data.runtime,
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
const focused = await focusHerdrPane(client, status.data.binding.paneId, input.signal);
|
|
525
|
+
if (!focused.ok) return projectPaneError(focused.error.code, focused.error.message, {
|
|
526
|
+
projectRoot: status.data.projectRoot, bindingPath: status.data.bindingPath, details: focused.error.details,
|
|
527
|
+
});
|
|
528
|
+
const now = (options.now?.() ?? new Date()).toISOString();
|
|
529
|
+
const binding = { ...status.data.binding, lastFocusedAt: now };
|
|
530
|
+
try {
|
|
531
|
+
writeAtomicJson(status.data.bindingPath, binding);
|
|
532
|
+
} catch (cause) {
|
|
533
|
+
return projectPaneError("BINDING_WRITE_FAILED", `Failed to update project pane binding '${status.data.bindingPath}': ${cause instanceof Error ? cause.message : String(cause)}`, {
|
|
534
|
+
projectRoot: status.data.projectRoot, bindingPath: status.data.bindingPath, details: fileSystemErrorDetails(cause),
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
return { ok: true, data: {
|
|
538
|
+
...common(status.data.projectRoot),
|
|
539
|
+
binding,
|
|
540
|
+
runtime: status.data.runtime,
|
|
541
|
+
ownership: status.data.ownership,
|
|
542
|
+
focused: focused.data,
|
|
543
|
+
} };
|
|
544
|
+
},
|
|
545
|
+
|
|
382
546
|
async open(input) {
|
|
383
547
|
const root = resolveProjectRoot(input.cwd);
|
|
384
548
|
if (!root.ok) return root;
|
|
@@ -414,7 +578,7 @@ function createProjectPaneManagerInternal(options: InternalProjectPaneManagerOpt
|
|
|
414
578
|
splitArgs.push(input.focus === true ? "--focus" : "--no-focus");
|
|
415
579
|
const split = await client.run(splitArgs, { timeoutMs: 15_000, signal: input.signal });
|
|
416
580
|
if (!split.ok) return projectPaneError(split.error.code, split.error.message, { projectRoot, details: split.error.details });
|
|
417
|
-
const paneId =
|
|
581
|
+
const paneId = herdrPaneFocusTarget(split.data).paneId;
|
|
418
582
|
if (!paneId) return projectPaneError(options.legacyToolCompatibility ? "PANE_GONE" : "INVALID_PANE_RESPONSE", "Herdr pane split returned no pane id.", { projectRoot, details: split.data });
|
|
419
583
|
const startupMessage = input.message?.trim();
|
|
420
584
|
const command = projectPaneCommand(startupMessage);
|
|
@@ -466,29 +630,26 @@ function createProjectPaneManagerInternal(options: InternalProjectPaneManagerOpt
|
|
|
466
630
|
if (!bindingResult.ok) return bindingResult;
|
|
467
631
|
const existing = bindingResult.data;
|
|
468
632
|
if (!existing) return { ok: true, data: { ...common(projectRoot), disposition: "absent" } };
|
|
469
|
-
|
|
470
|
-
if (
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
if (
|
|
474
|
-
|
|
475
|
-
if (!removed.ok) return removed;
|
|
476
|
-
return { ok: true, data: { ...common(projectRoot), disposition: "stale-binding-removed", binding: existing } };
|
|
477
|
-
}
|
|
478
|
-
return { ok: false, error: { ...live.error, projectRoot, bindingPath: projectPaneBindingPath(projectRoot) } };
|
|
479
|
-
}
|
|
480
|
-
runtime = live.data;
|
|
481
|
-
const ownership = projectPaneOwnership(runtime, existing, projectRoot);
|
|
482
|
-
if (ownership !== "verified") {
|
|
483
|
-
return projectPaneError("PANE_OWNERSHIP_UNVERIFIED", `Project pane '${existing.paneId}' ownership is '${ownership}' for '${projectRoot}'.`, {
|
|
484
|
-
projectRoot, bindingPath: projectPaneBindingPath(projectRoot), details: runtime,
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
if (runtime.agentStatus !== "idle") {
|
|
488
|
-
return projectPaneError("PANE_NOT_IDLE", `Project pane '${existing.paneId}' is '${runtime.agentStatus}', not explicitly idle.`, {
|
|
489
|
-
projectRoot, bindingPath: projectPaneBindingPath(projectRoot), details: runtime,
|
|
490
|
-
});
|
|
633
|
+
const live = await inspectPane(client, existing.paneId, input.signal);
|
|
634
|
+
if (!live.ok) {
|
|
635
|
+
if (live.error.code === "NOT_FOUND" || live.error.code === "PANE_GONE") {
|
|
636
|
+
const removed = removeProjectPaneBinding(projectRoot);
|
|
637
|
+
if (!removed.ok) return removed;
|
|
638
|
+
return { ok: true, data: { ...common(projectRoot), disposition: "stale-binding-removed", binding: existing } };
|
|
491
639
|
}
|
|
640
|
+
return { ok: false, error: { ...live.error, projectRoot, bindingPath: projectPaneBindingPath(projectRoot) } };
|
|
641
|
+
}
|
|
642
|
+
const runtime = live.data;
|
|
643
|
+
const ownership = projectPaneOwnership(runtime, existing, projectRoot);
|
|
644
|
+
if (ownership !== "verified") {
|
|
645
|
+
return projectPaneError("PANE_OWNERSHIP_UNVERIFIED", `Project pane '${existing.paneId}' ownership is '${ownership}' for '${projectRoot}'.`, {
|
|
646
|
+
projectRoot, bindingPath: projectPaneBindingPath(projectRoot), details: runtime,
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
if (runtime.agentStatus !== "idle") {
|
|
650
|
+
return projectPaneError("PANE_NOT_IDLE", `Project pane '${existing.paneId}' is '${runtime.agentStatus}', not explicitly idle.`, {
|
|
651
|
+
projectRoot, bindingPath: projectPaneBindingPath(projectRoot), details: runtime,
|
|
652
|
+
});
|
|
492
653
|
}
|
|
493
654
|
const closed = await client.run(["pane", "close", existing.paneId], { timeoutMs: 10_000, signal: input.signal });
|
|
494
655
|
if (!closed.ok && closed.error.code !== "NOT_FOUND" && closed.error.code !== "PANE_GONE") {
|
|
@@ -518,12 +679,19 @@ export async function closeProjectPane(options: CloseProjectPaneOptions): Promis
|
|
|
518
679
|
return createProjectPaneManager().close(options);
|
|
519
680
|
}
|
|
520
681
|
|
|
682
|
+
export async function focusProjectPane(options: GetProjectPaneStatusOptions): Promise<ProjectPaneResult<FocusProjectPaneData>> {
|
|
683
|
+
return createProjectPaneManager().focus(options);
|
|
684
|
+
}
|
|
685
|
+
|
|
521
686
|
export async function handleHerdrProjectPaneAction(action: HerdrProjectPaneAction, params: ProjectPaneParams, deps: ProjectPaneDeps): Promise<AgentToolResult<Details>> {
|
|
522
687
|
const requested = params.cwd?.trim() || deps.cwd;
|
|
688
|
+
const ownerRoot = path.resolve(deps.cwd);
|
|
523
689
|
const manager = createProjectPaneManagerInternal({ client: deps.client, now: deps.now, legacyToolCompatibility: true });
|
|
690
|
+
const remember = (data: ProjectPaneStatusData) => rememberProjectPane(deps.state, data, deps.now?.().getTime() ?? Date.now());
|
|
524
691
|
if (action === "project.status") {
|
|
525
692
|
const status = await manager.status({ cwd: requested, signal: deps.signal });
|
|
526
693
|
if (!status.ok) return toolResult(formatProjectPaneError(status.error), true);
|
|
694
|
+
remember(status.data);
|
|
527
695
|
if (status.data.state === "absent") return toolResult(`No Herdr project pane binding exists for ${status.data.projectRoot}.`);
|
|
528
696
|
if (status.data.state === "stale") {
|
|
529
697
|
const reason = status.data.staleReason!;
|
|
@@ -532,15 +700,31 @@ export async function handleHerdrProjectPaneAction(action: HerdrProjectPaneActio
|
|
|
532
700
|
return toolResult(`Herdr project pane ${status.data.binding!.paneId} is open for ${status.data.projectRoot}.\nBinding: ${status.data.bindingPath}`);
|
|
533
701
|
}
|
|
534
702
|
if (action === "project.close") {
|
|
535
|
-
const closed = await manager.close({ cwd: requested, signal: deps.signal });
|
|
703
|
+
const closed = await manager.close({ cwd: requested, requireIdle: true, signal: deps.signal });
|
|
536
704
|
if (!closed.ok) return toolResult(formatProjectPaneError(closed.error), true);
|
|
705
|
+
forgetProjectPane(deps.state, closed.data.projectRoot);
|
|
706
|
+
try { removeHerdrProjectPaneRoot(ownerRoot, closed.data.projectRoot); } catch (error) {
|
|
707
|
+
return toolResult(`Herdr project pane error (BINDING_REMOVE_FAILED): Failed to remove project pane root index '${projectPaneRootIndexPath(ownerRoot)}': ${error instanceof Error ? error.message : String(error)}`, true);
|
|
708
|
+
}
|
|
537
709
|
if (closed.data.disposition === "absent") return toolResult(`No Herdr project pane binding exists for ${closed.data.projectRoot}.`);
|
|
538
710
|
return toolResult(`Closed Herdr project pane ${closed.data.binding!.paneId} for ${closed.data.projectRoot}.`);
|
|
539
711
|
}
|
|
540
712
|
const opened = await manager.open({ cwd: requested, message: params.message, focus: params.focus, signal: deps.signal });
|
|
541
713
|
if (!opened.ok) return toolResult(formatProjectPaneError(opened.error), true);
|
|
714
|
+
try { writeHerdrProjectPaneRoot(ownerRoot, opened.data.projectRoot); } catch (error) {
|
|
715
|
+
return toolResult(`Herdr project pane error (BINDING_WRITE_FAILED): Failed to persist project pane root index '${projectPaneRootIndexPath(ownerRoot)}': ${error instanceof Error ? error.message : String(error)}`, true);
|
|
716
|
+
}
|
|
717
|
+
const status = await manager.status({ cwd: opened.data.projectRoot, signal: deps.signal });
|
|
718
|
+
if (status.ok) remember(status.data);
|
|
542
719
|
if (opened.data.disposition === "already-open") {
|
|
543
|
-
|
|
720
|
+
if (params.focus) {
|
|
721
|
+
const focused = await manager.focus({ cwd: opened.data.projectRoot, signal: deps.signal });
|
|
722
|
+
if (!focused.ok) return toolResult(`Herdr project pane ${opened.data.binding.paneId} is already open for ${opened.data.projectRoot}. ${formatProjectPaneError(focused.error)}`, true);
|
|
723
|
+
const focusedStatus = await manager.status({ cwd: opened.data.projectRoot, signal: deps.signal });
|
|
724
|
+
if (focusedStatus.ok) remember(focusedStatus.data);
|
|
725
|
+
return toolResult(`Herdr project pane ${opened.data.binding.paneId} is already open for ${opened.data.projectRoot}. Focused ${focused.data.focused.tabId ? `tab ${focused.data.focused.tabId}` : `workspace ${focused.data.focused.workspaceId}`}.`);
|
|
726
|
+
}
|
|
727
|
+
return toolResult(`Herdr project pane ${opened.data.binding.paneId} is already open for ${opened.data.projectRoot}.`);
|
|
544
728
|
}
|
|
545
729
|
return toolResult(`Opened Herdr project pane ${opened.data.binding.paneId} for ${opened.data.projectRoot}. The pane runs its own Pi session; subagents launched there belong to that project.`);
|
|
546
730
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Windows PowerShell has no backslash-escape for embedded double quotes: a
|
|
3
|
+
* double-quoted string literal only recognizes `` `" `` or `""` to embed a
|
|
4
|
+
* literal quote, so a naively-quoted JSON array (which is full of `"` and
|
|
5
|
+
* `\` characters) gets truncated or split into multiple argv tokens the
|
|
6
|
+
* moment PowerShell tokenizes the `pane run` command line.
|
|
7
|
+
*
|
|
8
|
+
* Base64 has no quotes, backslashes, or spaces for any shell to mangle, so
|
|
9
|
+
* encoding the `--session-roots` payload sidesteps quoting entirely. It is
|
|
10
|
+
* also plain ASCII, so it never hits shellQuote's Windows quoting branch in
|
|
11
|
+
* a way that could still fail as new characters are added upstream.
|
|
12
|
+
*/
|
|
13
|
+
export function encodeSessionRoots(roots: readonly string[]): string {
|
|
14
|
+
return Buffer.from(JSON.stringify(roots), "utf-8").toString("base64");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function parseStringArray(value: unknown): string[] | undefined {
|
|
18
|
+
if (!Array.isArray(value) || value.some((root) => typeof root !== "string")) return undefined;
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Decodes a `--session-roots` argument produced by {@link encodeSessionRoots}.
|
|
24
|
+
* Falls back to parsing the value as raw JSON so any externally-launched
|
|
25
|
+
* inspector runner (a cached copy, or a manual invocation) that still passes
|
|
26
|
+
* the legacy unencoded form keeps working.
|
|
27
|
+
*/
|
|
28
|
+
export function decodeSessionRoots(raw: string): string[] {
|
|
29
|
+
try {
|
|
30
|
+
const decoded = parseStringArray(JSON.parse(Buffer.from(raw, "base64").toString("utf-8")));
|
|
31
|
+
if (decoded) return decoded;
|
|
32
|
+
} catch {
|
|
33
|
+
// fall through to legacy raw-JSON parsing below
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const parsed = parseStringArray(JSON.parse(raw));
|
|
37
|
+
if (parsed) return parsed;
|
|
38
|
+
} catch {
|
|
39
|
+
// fall through to the shared error below
|
|
40
|
+
}
|
|
41
|
+
throw new Error("--session-roots must be a base64-encoded or raw JSON array of strings.");
|
|
42
|
+
}
|
|
@@ -3,10 +3,15 @@ import {
|
|
|
3
3
|
SUBAGENT_ASYNC_STARTED_EVENT,
|
|
4
4
|
SUBAGENT_CONTROL_EVENT,
|
|
5
5
|
} from "../shared/types.ts";
|
|
6
|
+
import { previewDisplayText, sanitizeDisplayText } from "../shared/display-text.ts";
|
|
6
7
|
|
|
7
8
|
const DEFAULT_SOURCE = "pi-subagents:herdr";
|
|
8
9
|
const DEFAULT_TTL_MS = 120_000;
|
|
9
10
|
const DEFAULT_REFRESH_MS = 45_000;
|
|
11
|
+
const MAX_TASK_LABEL_CHARS = 80;
|
|
12
|
+
const MAX_TITLE_TASK_CHARS = 42;
|
|
13
|
+
const MAX_WORKFLOW_LABEL_NODES = 128;
|
|
14
|
+
const MAX_WORKFLOW_LABEL_DEPTH = 8;
|
|
10
15
|
|
|
11
16
|
let metadataReportSeq = Date.now() * 1000;
|
|
12
17
|
|
|
@@ -24,6 +29,8 @@ export interface HerdrStatusRun {
|
|
|
24
29
|
id: string;
|
|
25
30
|
agent?: string;
|
|
26
31
|
agents?: string[];
|
|
32
|
+
/** Explicit launch/workflow label only; raw prompts never enter pane metadata. */
|
|
33
|
+
taskLabel?: string;
|
|
27
34
|
needsAttention?: boolean;
|
|
28
35
|
attentionLabel?: string;
|
|
29
36
|
}
|
|
@@ -33,6 +40,8 @@ export interface HerdrStatusBridgeOptions {
|
|
|
33
40
|
env?: Record<string, string | undefined>;
|
|
34
41
|
/** Current authoritative active-run projection, used before TTL refresh. */
|
|
35
42
|
getRuns?: () => Iterable<HerdrStatusRun>;
|
|
43
|
+
/** Current project panes opened by this Pi session. Views are excluded. */
|
|
44
|
+
getProjectPaneCount?: () => number;
|
|
36
45
|
runHerdr: (args: readonly string[]) => void | Promise<void>;
|
|
37
46
|
ttlMs?: number;
|
|
38
47
|
refreshMs?: number;
|
|
@@ -50,6 +59,7 @@ export interface HerdrStatusBridge {
|
|
|
50
59
|
* state. Also re-syncs runs that survived a reload/resume.
|
|
51
60
|
*/
|
|
52
61
|
sessionStarted(input: { hasUI: boolean; runs: Iterable<HerdrStatusRun> }): void;
|
|
62
|
+
syncRuns(): void;
|
|
53
63
|
agentStarted(): void;
|
|
54
64
|
flush(): Promise<void>;
|
|
55
65
|
dispose(): void;
|
|
@@ -59,12 +69,42 @@ function isRecord(value: unknown): value is Record<string, unknown> {
|
|
|
59
69
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
60
70
|
}
|
|
61
71
|
|
|
72
|
+
function boundedTaskLabel(value: unknown, maxChars = MAX_TASK_LABEL_CHARS): string | undefined {
|
|
73
|
+
if (typeof value !== "string") return undefined;
|
|
74
|
+
const normalized = sanitizeDisplayText(value).trim();
|
|
75
|
+
if (!normalized) return undefined;
|
|
76
|
+
return previewDisplayText(normalized, maxChars);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function workflowTaskLabel(data: Record<string, unknown>): string | undefined {
|
|
80
|
+
const explicit = boundedTaskLabel(data.taskLabel);
|
|
81
|
+
if (explicit) return explicit;
|
|
82
|
+
if (!isRecord(data.workflowGraph) || !Array.isArray(data.workflowGraph.nodes)) return undefined;
|
|
83
|
+
const currentNodeId = typeof data.workflowGraph.currentNodeId === "string" ? data.workflowGraph.currentNodeId : undefined;
|
|
84
|
+
const nodes: Record<string, unknown>[] = [];
|
|
85
|
+
const collect = (values: unknown[], depth: number): void => {
|
|
86
|
+
if (depth > MAX_WORKFLOW_LABEL_DEPTH || nodes.length >= MAX_WORKFLOW_LABEL_NODES) return;
|
|
87
|
+
for (const value of values) {
|
|
88
|
+
if (nodes.length >= MAX_WORKFLOW_LABEL_NODES) return;
|
|
89
|
+
if (!isRecord(value)) continue;
|
|
90
|
+
nodes.push(value);
|
|
91
|
+
if (Array.isArray(value.children)) collect(value.children, depth + 1);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
collect(data.workflowGraph.nodes, 0);
|
|
95
|
+
const current = currentNodeId ? nodes.find((node) => node.id === currentNodeId) : undefined;
|
|
96
|
+
const active = current ?? nodes.find((node) => node.status === "running") ?? nodes.find((node) => node.status === "pending");
|
|
97
|
+
return boundedTaskLabel(active?.label);
|
|
98
|
+
}
|
|
99
|
+
|
|
62
100
|
function startedRun(data: unknown): HerdrStatusRun | undefined {
|
|
63
101
|
if (!isRecord(data) || typeof data.id !== "string" || !data.id) return undefined;
|
|
102
|
+
const taskLabel = workflowTaskLabel(data);
|
|
64
103
|
return {
|
|
65
104
|
id: data.id,
|
|
66
105
|
...(typeof data.agent === "string" ? { agent: data.agent } : {}),
|
|
67
106
|
...(Array.isArray(data.agents) && data.agents.every((agent) => typeof agent === "string") ? { agents: data.agents as string[] } : {}),
|
|
107
|
+
...(taskLabel ? { taskLabel } : {}),
|
|
68
108
|
};
|
|
69
109
|
}
|
|
70
110
|
|
|
@@ -109,12 +149,31 @@ export function registerHerdrStatusBridge(options: HerdrStatusBridgeOptions): He
|
|
|
109
149
|
let drainPromise = Promise.resolve();
|
|
110
150
|
let refreshTimer: ReturnType<typeof setInterval> | undefined;
|
|
111
151
|
|
|
112
|
-
const
|
|
113
|
-
|
|
152
|
+
const activeAgentNames = (): string[] => [...new Set([...runs.values()].flatMap((run) => run.agents?.length ? run.agents : run.agent ? [run.agent] : []))];
|
|
153
|
+
const activeSubagentCount = (): number => [...runs.values()].reduce((total, run) => total + Math.max(1, run.agents?.length ?? (run.agent ? 1 : 0)), 0);
|
|
154
|
+
const activeTaskLabel = (): string | undefined => [...runs.values()].reverse().find((run) => run.taskLabel)?.taskLabel;
|
|
155
|
+
|
|
156
|
+
const label = (includeAttention = false): string => {
|
|
157
|
+
const agents = activeAgentNames();
|
|
158
|
+
const activeCount = activeSubagentCount();
|
|
114
159
|
const who = agents.length > 0
|
|
115
160
|
? ` (${agents.slice(0, 3).join(", ")}${agents.length > 3 ? ", …" : ""})`
|
|
116
161
|
: "";
|
|
117
|
-
|
|
162
|
+
const panes = Math.max(0, options.getProjectPaneCount?.() ?? 0);
|
|
163
|
+
const paneText = panes > 0 ? ` · ${panes} pane${panes === 1 ? "" : "s"}` : "";
|
|
164
|
+
const task = activeTaskLabel();
|
|
165
|
+
const taskText = task ? ` · ${task}` : "";
|
|
166
|
+
const attention = includeAttention && attentionLabels.size > 0 ? " ⚠" : "";
|
|
167
|
+
return `⏳ ${activeCount} subagent${activeCount === 1 ? "" : "s"}${who}${paneText}${taskText}${attention}`;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const titleSuffix = (): string | undefined => {
|
|
171
|
+
if (runs.size === 0) return undefined;
|
|
172
|
+
const agentNames = activeAgentNames();
|
|
173
|
+
const activeCount = activeSubagentCount();
|
|
174
|
+
const task = boundedTaskLabel(activeTaskLabel(), MAX_TITLE_TASK_CHARS);
|
|
175
|
+
const target = task ?? (activeCount === 1 && agentNames.length === 1 ? agentNames[0]! : String(activeCount));
|
|
176
|
+
return `⏳${target}${attentionLabels.size > 0 ? "⚠" : ""}`;
|
|
118
177
|
};
|
|
119
178
|
|
|
120
179
|
const enqueue = (args: readonly string[]): void => {
|
|
@@ -150,11 +209,13 @@ export function registerHerdrStatusBridge(options: HerdrStatusBridgeOptions): He
|
|
|
150
209
|
"--applies-to-source", "herdr:pi",
|
|
151
210
|
"--clear-state-labels",
|
|
152
211
|
"--clear-token", "summary",
|
|
212
|
+
"--clear-token", "title-suffix",
|
|
153
213
|
"--seq", seq,
|
|
154
214
|
]);
|
|
155
215
|
return;
|
|
156
216
|
}
|
|
157
|
-
const text = label();
|
|
217
|
+
const text = label(true);
|
|
218
|
+
const suffix = titleSuffix();
|
|
158
219
|
published = true;
|
|
159
220
|
enqueue([
|
|
160
221
|
"pane", "report-metadata", paneId,
|
|
@@ -165,6 +226,7 @@ export function registerHerdrStatusBridge(options: HerdrStatusBridgeOptions): He
|
|
|
165
226
|
"--state-label", `done=${text}`,
|
|
166
227
|
"--state-label", `working=${text}`,
|
|
167
228
|
"--token", `summary=${text}`,
|
|
229
|
+
...(suffix ? ["--token", `title-suffix=${suffix}`] : []),
|
|
168
230
|
"--ttl-ms", String(ttlMs),
|
|
169
231
|
"--seq", seq,
|
|
170
232
|
]);
|
|
@@ -221,6 +283,7 @@ export function registerHerdrStatusBridge(options: HerdrStatusBridgeOptions): He
|
|
|
221
283
|
const clearAttention = (): void => {
|
|
222
284
|
attentionLabels.clear();
|
|
223
285
|
syncBlocked();
|
|
286
|
+
publish();
|
|
224
287
|
};
|
|
225
288
|
|
|
226
289
|
const raiseAttention = (runId: string, labelText: string): void => {
|
|
@@ -228,6 +291,7 @@ export function registerHerdrStatusBridge(options: HerdrStatusBridgeOptions): He
|
|
|
228
291
|
acknowledgedAttention.delete(runId);
|
|
229
292
|
attentionLabels.set(runId, labelText);
|
|
230
293
|
syncBlocked();
|
|
294
|
+
publish();
|
|
231
295
|
};
|
|
232
296
|
|
|
233
297
|
const replaceRuns = (nextRuns: Iterable<HerdrStatusRun>): void => {
|
|
@@ -237,7 +301,9 @@ export function registerHerdrStatusBridge(options: HerdrStatusBridgeOptions): He
|
|
|
237
301
|
for (const run of nextRuns) {
|
|
238
302
|
if (!run || typeof run.id !== "string" || !run.id) continue;
|
|
239
303
|
activeIds.add(run.id);
|
|
240
|
-
|
|
304
|
+
const taskLabel = boundedTaskLabel(run.taskLabel);
|
|
305
|
+
const { taskLabel: _rawTaskLabel, ...sanitizedRun } = run;
|
|
306
|
+
runs.set(run.id, { ...sanitizedRun, ...(taskLabel ? { taskLabel } : {}) });
|
|
241
307
|
if (!run.needsAttention) {
|
|
242
308
|
acknowledgedAttention.delete(run.id);
|
|
243
309
|
} else if (!acknowledgedAttention.has(run.id)) {
|
|
@@ -312,6 +378,10 @@ export function registerHerdrStatusBridge(options: HerdrStatusBridgeOptions): He
|
|
|
312
378
|
rootSession = true;
|
|
313
379
|
replaceRuns(restoredRuns);
|
|
314
380
|
},
|
|
381
|
+
syncRuns() {
|
|
382
|
+
if (!enabled || !rootSession || disposed) return;
|
|
383
|
+
refresh();
|
|
384
|
+
},
|
|
315
385
|
async flush() {
|
|
316
386
|
while (draining || pendingReport) await drainPromise;
|
|
317
387
|
},
|