@f5-sales-demo/xcsh 21.17.0 → 21.19.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 +8 -0
- package/package.json +9 -8
- package/src/config/settings-schema.ts +11 -0
- package/src/config/settings.ts +4 -0
- package/src/debug/index.ts +2 -3
- package/src/extensibility/extensions/bundled/herdr-reporter.ts +251 -9
- package/src/herdr/client.ts +28 -5
- package/src/internal-urls/build-info.generated.ts +8 -8
- package/src/internal-urls/docs-index.generated.ts +4 -3
- package/src/locales/en.json +9 -2
- package/src/modes/components/assistant-message.ts +6 -2
- package/src/modes/components/auth-link-presenter.ts +4 -2
- package/src/modes/components/copy-selector.ts +273 -0
- package/src/modes/components/login-dialog.ts +10 -3
- package/src/modes/components/status-line/segments.ts +2 -2
- package/src/modes/controllers/command-controller.ts +34 -2
- package/src/modes/controllers/selector-controller.ts +80 -6
- package/src/modes/controllers/vertex-login-flow.ts +8 -4
- package/src/modes/interactive-mode.ts +15 -0
- package/src/modes/types.ts +4 -0
- package/src/modes/utils/copy-targets.ts +238 -0
- package/src/session/session-manager.ts +14 -0
- package/src/slash-commands/builtin-registry.ts +10 -0
- package/src/tui/hyperlink.ts +72 -0
- package/src/utils/clipboard.ts +14 -3
- package/src/utils/open.ts +30 -0
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,14 @@
|
|
|
6
6
|
|
|
7
7
|
### Added
|
|
8
8
|
|
|
9
|
+
- Added capability-aware terminal hyperlinks, automatic local Vertex sign-in launch with durable
|
|
10
|
+
manual recovery, HTTP(S)-only `/open`, `/copy link`, and a bounded fullscreen transcript copy
|
|
11
|
+
picker. Semantically ported from [can1357/oh-my-pi#10196](https://github.com/can1357/oh-my-pi/pull/10196),
|
|
12
|
+
[#10606](https://github.com/can1357/oh-my-pi/pull/10606),
|
|
13
|
+
[#11002](https://github.com/can1357/oh-my-pi/pull/11002),
|
|
14
|
+
[#10922](https://github.com/can1357/oh-my-pi/pull/10922), and
|
|
15
|
+
[#11086](https://github.com/can1357/oh-my-pi/pull/11086)
|
|
16
|
+
([#3758](https://github.com/f5-sales-demo/xcsh/issues/3758)).
|
|
9
17
|
- Added strict `xcsh://registry/provider/<namespace>/<type>` and
|
|
10
18
|
`xcsh://registry/module/<namespace>/<name>/<provider>` Terraform Registry lookups with bounded,
|
|
11
19
|
protocol-native discovery and actionable failures
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@f5-sales-demo/xcsh",
|
|
4
|
-
"version": "21.
|
|
4
|
+
"version": "21.19.0",
|
|
5
5
|
"description": "Coding agent CLI with read, bash, edit, write tools and session management",
|
|
6
6
|
"homepage": "https://github.com/f5-sales-demo/xcsh",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"pretest": "bun ../../scripts/check-installed-dependencies.ts",
|
|
42
42
|
"test": "bun run generate-build-info && bun scripts/bun-test-guarded.ts --max-concurrency 1",
|
|
43
43
|
"bench:routing-matrix": "bun scripts/bench-routing-matrix.ts",
|
|
44
|
+
"bench:copy-selector": "bun scripts/bench-copy-selector.ts",
|
|
44
45
|
"fix": "biome check --write --unsafe . && bun run format-prompts && bun run generate-docs-index && bun run generate-api-spec-index && bun run generate-build-info",
|
|
45
46
|
"fmt": "biome format --write . && bun run format-prompts",
|
|
46
47
|
"format-prompts": "bun scripts/format-prompts.ts",
|
|
@@ -61,13 +62,13 @@
|
|
|
61
62
|
},
|
|
62
63
|
"dependencies": {
|
|
63
64
|
"@agentclientprotocol/sdk": "1.3.0",
|
|
64
|
-
"@f5-sales-demo/pi-agent-core": "21.
|
|
65
|
-
"@f5-sales-demo/pi-ai": "21.
|
|
66
|
-
"@f5-sales-demo/pi-natives": "21.
|
|
67
|
-
"@f5-sales-demo/pi-resource-management": "21.
|
|
68
|
-
"@f5-sales-demo/pi-tui": "21.
|
|
69
|
-
"@f5-sales-demo/pi-utils": "21.
|
|
70
|
-
"@f5-sales-demo/xcsh-stats": "21.
|
|
65
|
+
"@f5-sales-demo/pi-agent-core": "21.19.0",
|
|
66
|
+
"@f5-sales-demo/pi-ai": "21.19.0",
|
|
67
|
+
"@f5-sales-demo/pi-natives": "21.19.0",
|
|
68
|
+
"@f5-sales-demo/pi-resource-management": "21.19.0",
|
|
69
|
+
"@f5-sales-demo/pi-tui": "21.19.0",
|
|
70
|
+
"@f5-sales-demo/pi-utils": "21.19.0",
|
|
71
|
+
"@f5-sales-demo/xcsh-stats": "21.19.0",
|
|
71
72
|
"@mozilla/readability": "^0.6",
|
|
72
73
|
"@sinclair/typebox": "^0.34",
|
|
73
74
|
"@xterm/headless": "^6.0",
|
|
@@ -475,6 +475,17 @@ export const SETTINGS_SCHEMA = {
|
|
|
475
475
|
description:
|
|
476
476
|
"Maximum height in terminal rows for inline images. Set to 0 to use only the viewport-based limit (60% of terminal height).",
|
|
477
477
|
},
|
|
478
|
+
"tui.hyperlinks": {
|
|
479
|
+
type: "enum",
|
|
480
|
+
values: ["off", "auto", "always"] as const,
|
|
481
|
+
default: "auto",
|
|
482
|
+
ui: {
|
|
483
|
+
tab: "appearance",
|
|
484
|
+
label: "Terminal Hyperlinks",
|
|
485
|
+
description: "Emit clickable terminal links automatically, always, or never",
|
|
486
|
+
submenu: true,
|
|
487
|
+
},
|
|
488
|
+
},
|
|
478
489
|
// Display rendering
|
|
479
490
|
"display.tabWidth": {
|
|
480
491
|
type: "number",
|
package/src/config/settings.ts
CHANGED
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
setSymbolPreset,
|
|
35
35
|
} from "../modes/theme/theme";
|
|
36
36
|
import { AgentStorage } from "../session/agent-storage";
|
|
37
|
+
import { applyHyperlinkSetting } from "../tui/hyperlink";
|
|
37
38
|
import { type EditMode, normalizeEditMode } from "../utils/edit-mode";
|
|
38
39
|
import { hardenAgentConfigFile, writeAgentConfigFile } from "./agent-config-file";
|
|
39
40
|
import { withFileLock } from "./file-lock";
|
|
@@ -712,6 +713,9 @@ const SETTING_HOOKS: Partial<Record<SettingPath, SettingHook<any>>> = {
|
|
|
712
713
|
setDefaultTabWidth(value);
|
|
713
714
|
}
|
|
714
715
|
},
|
|
716
|
+
"tui.hyperlinks": value => {
|
|
717
|
+
applyHyperlinkSetting(value);
|
|
718
|
+
},
|
|
715
719
|
};
|
|
716
720
|
|
|
717
721
|
// ═══════════════════════════════════════════════════════════════════════════
|
package/src/debug/index.ts
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* Provides tools for debugging, bug report generation, and system diagnostics.
|
|
5
5
|
*/
|
|
6
6
|
import * as fs from "node:fs/promises";
|
|
7
|
-
import * as url from "node:url";
|
|
8
7
|
import { getWorkProfile } from "@f5-sales-demo/pi-natives";
|
|
9
8
|
import {
|
|
10
9
|
Container,
|
|
@@ -21,6 +20,7 @@ import { DynamicBorder } from "../modes/components/dynamic-border";
|
|
|
21
20
|
import { getSelectListTheme, getSymbolTheme, theme } from "../modes/theme/theme";
|
|
22
21
|
import type { InteractiveModeContext } from "../modes/types";
|
|
23
22
|
import { formatBytes } from "../tools/render-utils";
|
|
23
|
+
import { fileHyperlink } from "../tui/hyperlink";
|
|
24
24
|
import { openPath } from "../utils/open";
|
|
25
25
|
import { DebugLogViewerComponent } from "./log-viewer";
|
|
26
26
|
import { generateHeapSnapshotData, type ProfilerSession, startCpuProfile } from "./profiler";
|
|
@@ -46,8 +46,7 @@ const DEBUG_MENU_ITEMS: SelectItem[] = [
|
|
|
46
46
|
];
|
|
47
47
|
|
|
48
48
|
const formatFileHyperlink = (path: string): string => {
|
|
49
|
-
|
|
50
|
-
return `\x1b]8;;${fileUrl}\x07${path}\x1b]8;;\x07`;
|
|
49
|
+
return fileHyperlink(path, path);
|
|
51
50
|
};
|
|
52
51
|
|
|
53
52
|
/**
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
1
2
|
import * as path from "node:path";
|
|
3
|
+
import type { AssistantMessage } from "@f5-sales-demo/pi-ai";
|
|
2
4
|
import type { ExtensionAPI, ExtensionContext, UserPromptKind } from "@f5-sales-demo/xcsh";
|
|
3
5
|
import { HerdrClient } from "../../../herdr/client";
|
|
6
|
+
import { finalAnswerText } from "../../../session/final-answer";
|
|
4
7
|
|
|
5
8
|
/**
|
|
6
9
|
* herdr integration (bundled, default-on).
|
|
@@ -10,7 +13,7 @@ import { HerdrClient } from "../../../herdr/client";
|
|
|
10
13
|
* blocked indicator.
|
|
11
14
|
*
|
|
12
15
|
* Transport: herdr injects `HERDR_SOCKET_PATH` into every pane, so state is
|
|
13
|
-
* reported over
|
|
16
|
+
* reported over Herdr's supported JSONL socket protocol via the shared `HerdrClient`
|
|
14
17
|
* (see `../../../herdr/client`) — the same client `herdr-terminal` uses. Each
|
|
15
18
|
* request reconnects independently, validates the `ping` protocol version
|
|
16
19
|
* before the first real request, and awaits herdr's typed response before
|
|
@@ -62,9 +65,13 @@ const METADATA_METHOD = "pane.report_metadata";
|
|
|
62
65
|
const SESSION_METHOD = "pane.report_agent_session";
|
|
63
66
|
const HEARTBEAT_METHOD = "pane.report_agent_heartbeat";
|
|
64
67
|
const RELEASE_METHOD = "pane.release_agent";
|
|
68
|
+
const TURN_REPORT_METHOD = "agent.turn.report";
|
|
65
69
|
const SOCKET_TIMEOUT_MS = 2000;
|
|
66
70
|
const HEARTBEAT_INTERVAL_MS = 10_000;
|
|
67
71
|
const PHASE_LABEL_TTL_MS = 60_000;
|
|
72
|
+
const RESULT_MAX_CHARS = 80;
|
|
73
|
+
const SEMANTIC_RESULT_MAX_BYTES = 8_000;
|
|
74
|
+
const TURN_ENTRY_TYPE = "herdr.semantic-turn";
|
|
68
75
|
const SETTLED_TURN_RECONCILE_DELAY_MS = 25;
|
|
69
76
|
const PROMPT_BLOCKED_REASONS = {
|
|
70
77
|
select: "selection required",
|
|
@@ -79,6 +86,60 @@ function getPromptBlockedReason(kind: unknown): string {
|
|
|
79
86
|
return "user input required";
|
|
80
87
|
}
|
|
81
88
|
|
|
89
|
+
function boundedResult(message: AssistantMessage | undefined): string | undefined {
|
|
90
|
+
if (message?.stopReason !== "stop") return undefined;
|
|
91
|
+
const result = finalAnswerText(message).replaceAll(/\s+/g, " ").trim().slice(0, RESULT_MAX_CHARS).trim();
|
|
92
|
+
return result || undefined;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function boundedSemanticResult(message: AssistantMessage | undefined): string {
|
|
96
|
+
if (message?.stopReason !== "stop") return "";
|
|
97
|
+
let result = finalAnswerText(message).trim();
|
|
98
|
+
while (Buffer.byteLength(result) > SEMANTIC_RESULT_MAX_BYTES) result = result.slice(0, -1);
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
interface PersistedTurn {
|
|
103
|
+
sessionId: string;
|
|
104
|
+
turnId: string;
|
|
105
|
+
generation: number;
|
|
106
|
+
eventRevision?: number;
|
|
107
|
+
state?: "starting" | "working" | "waiting_input" | "completed" | "failed" | "cancelled" | "interrupted";
|
|
108
|
+
result?: string;
|
|
109
|
+
reason?: string;
|
|
110
|
+
resultDigest?: string;
|
|
111
|
+
delivered?: boolean;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function persistedTurns(ctx: ExtensionContext): PersistedTurn[] {
|
|
115
|
+
try {
|
|
116
|
+
const entries = ctx.sessionManager?.getEntries?.() as unknown[] | undefined;
|
|
117
|
+
return (entries ?? []).flatMap(entry => {
|
|
118
|
+
if (typeof entry !== "object" || entry === null) return [];
|
|
119
|
+
const record = entry as Record<string, unknown>;
|
|
120
|
+
if (record.type !== "custom" || record.customType !== TURN_ENTRY_TYPE) return [];
|
|
121
|
+
if (typeof record.data !== "object" || record.data === null) return [];
|
|
122
|
+
const turn = record.data as Record<string, unknown>;
|
|
123
|
+
if (typeof turn.sessionId !== "string" || typeof turn.turnId !== "string") return [];
|
|
124
|
+
return [
|
|
125
|
+
{
|
|
126
|
+
sessionId: turn.sessionId,
|
|
127
|
+
turnId: turn.turnId,
|
|
128
|
+
generation: typeof turn.generation === "number" ? turn.generation : 0,
|
|
129
|
+
eventRevision: typeof turn.eventRevision === "number" ? turn.eventRevision : undefined,
|
|
130
|
+
state: typeof turn.state === "string" ? (turn.state as PersistedTurn["state"]) : undefined,
|
|
131
|
+
result: typeof turn.result === "string" ? turn.result : undefined,
|
|
132
|
+
reason: typeof turn.reason === "string" ? turn.reason : undefined,
|
|
133
|
+
resultDigest: typeof turn.resultDigest === "string" ? turn.resultDigest : undefined,
|
|
134
|
+
delivered: turn.delivered === true,
|
|
135
|
+
},
|
|
136
|
+
];
|
|
137
|
+
});
|
|
138
|
+
} catch {
|
|
139
|
+
return [];
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
82
143
|
// Reused across calls for the life of the extension so `ensureProtocol()`'s
|
|
83
144
|
// `ping` validation happens at most once per socket path, not once per frame.
|
|
84
145
|
let cachedClient: HerdrClient | undefined;
|
|
@@ -91,7 +152,7 @@ function getHerdrClient(socketPath: string): HerdrClient {
|
|
|
91
152
|
}
|
|
92
153
|
|
|
93
154
|
/**
|
|
94
|
-
* Send one JSON-RPC request to
|
|
155
|
+
* Send one JSON-RPC request to Herdr over its negotiated socket and await the
|
|
95
156
|
* typed response. Every failure path (transport error, timeout, protocol
|
|
96
157
|
* mismatch) is reported via `onError` without throwing, so a dead or
|
|
97
158
|
* incompatible herdr never disturbs the agent.
|
|
@@ -153,13 +214,19 @@ export default function herdrReporter(pi: ExtensionAPI): void {
|
|
|
153
214
|
// Once the normalized contract is observed it is authoritative. The legacy
|
|
154
215
|
// event mappings remain only for older hosts that load this bundled extension.
|
|
155
216
|
let normalizedPhasesObserved = false;
|
|
217
|
+
let currentTurnId = 0;
|
|
218
|
+
let lastNormalizedEventKey: string | undefined;
|
|
219
|
+
let pendingSuccessfulResult: string | undefined;
|
|
220
|
+
let pendingSemanticResult = "";
|
|
221
|
+
let activeSemanticTurn: PersistedTurn | undefined;
|
|
222
|
+
let semanticRevision = 0;
|
|
156
223
|
// Last session ref already delivered, so repeated lifecycle events do not
|
|
157
224
|
// re-send an unchanged ref every turn.
|
|
158
225
|
let lastSessionRefKey: string | undefined;
|
|
159
226
|
// Herdr only anchors a new full-lifecycle authority after the first session
|
|
160
227
|
// reference identifies how the session began. XCSH creates that reference
|
|
161
228
|
// lazily, so retain the startup marker until there is a concrete ref to send.
|
|
162
|
-
let pendingSessionStartSource: "startup" | undefined = "startup";
|
|
229
|
+
let pendingSessionStartSource: "startup" | "new" | "resume" | "fork" | undefined = "startup";
|
|
163
230
|
// `agent_end` is the primary completion signal. Keep one deferred check from
|
|
164
231
|
// `turn_end` as well: some interactive UI paths render the completed response
|
|
165
232
|
// before their agent-end extension callback has drained. The check consults
|
|
@@ -174,13 +241,22 @@ export default function herdrReporter(pi: ExtensionAPI): void {
|
|
|
174
241
|
// Serializes frames: herdr compares `seq` across all methods for this source,
|
|
175
242
|
// so frames must reach it in the order they were generated.
|
|
176
243
|
let queue: Promise<void> = Promise.resolve();
|
|
244
|
+
let latestContext: ExtensionContext | undefined;
|
|
245
|
+
let trackingWarningShown = false;
|
|
177
246
|
|
|
178
247
|
pi.setLabel(HERDR_AGENT_LABEL);
|
|
179
248
|
|
|
180
249
|
const onError = (err: unknown): void => {
|
|
250
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
181
251
|
pi.logger.debug("herdr report failed", {
|
|
182
|
-
error:
|
|
252
|
+
error: message,
|
|
183
253
|
});
|
|
254
|
+
const ui = (latestContext as { ui?: ExtensionContext["ui"] } | undefined)?.ui;
|
|
255
|
+
ui?.setStatus("herdr-tracking", "Herdr tracking degraded");
|
|
256
|
+
if (!trackingWarningShown) {
|
|
257
|
+
trackingWarningShown = true;
|
|
258
|
+
ui?.notify(`Herdr semantic tracking is degraded: ${message}`, "warning");
|
|
259
|
+
}
|
|
184
260
|
};
|
|
185
261
|
|
|
186
262
|
/** Chain a frame onto the tail of the send queue. Never rejects. */
|
|
@@ -203,6 +279,80 @@ export default function herdrReporter(pi: ExtensionAPI): void {
|
|
|
203
279
|
);
|
|
204
280
|
};
|
|
205
281
|
|
|
282
|
+
const reportSemanticTurn = (
|
|
283
|
+
state: "starting" | "working" | "waiting_input" | "completed" | "failed" | "cancelled" | "interrupted",
|
|
284
|
+
options: { result?: string; reason?: string } = {},
|
|
285
|
+
): Promise<void> => {
|
|
286
|
+
const executionId = process.env.HERDR_EXECUTION_ID;
|
|
287
|
+
if (!executionId || !activeSemanticTurn) return Promise.resolve();
|
|
288
|
+
const revision = ++semanticRevision;
|
|
289
|
+
const event: PersistedTurn = {
|
|
290
|
+
...activeSemanticTurn,
|
|
291
|
+
eventRevision: revision,
|
|
292
|
+
state,
|
|
293
|
+
...(options.result === undefined
|
|
294
|
+
? {}
|
|
295
|
+
: { result: options.result, resultDigest: createHash("sha256").update(options.result).digest("hex") }),
|
|
296
|
+
...(options.reason === undefined ? {} : { reason: options.reason }),
|
|
297
|
+
};
|
|
298
|
+
pi.appendEntry(TURN_ENTRY_TYPE, { ...event, delivered: false });
|
|
299
|
+
return deliverSemanticEvent(event);
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
const deliverSemanticEvent = (event: PersistedTurn): Promise<void> => {
|
|
303
|
+
const socketPath = process.env.HERDR_SOCKET_PATH;
|
|
304
|
+
const executionId = process.env.HERDR_EXECUTION_ID;
|
|
305
|
+
if (!socketPath || !executionId || event.eventRevision === undefined || event.state === undefined) {
|
|
306
|
+
return Promise.resolve();
|
|
307
|
+
}
|
|
308
|
+
const frame = {
|
|
309
|
+
execution_id: executionId,
|
|
310
|
+
pane_id: paneId,
|
|
311
|
+
producer: HERDR_AGENT_LABEL,
|
|
312
|
+
session_id: event.sessionId,
|
|
313
|
+
turn_id: event.turnId,
|
|
314
|
+
generation: event.generation,
|
|
315
|
+
event_revision: event.eventRevision,
|
|
316
|
+
state: event.state,
|
|
317
|
+
...(event.result === undefined ? {} : { result: event.result, result_digest: event.resultDigest }),
|
|
318
|
+
...(event.reason === undefined ? {} : { reason: event.reason }),
|
|
319
|
+
};
|
|
320
|
+
return enqueue(async () => {
|
|
321
|
+
const client = getHerdrClient(socketPath);
|
|
322
|
+
try {
|
|
323
|
+
await client.ensureProtocol();
|
|
324
|
+
if (!client.hasCapability("agent_turn_journal")) {
|
|
325
|
+
onError(new Error("Herdr does not advertise agent_turn_journal; semantic tracking is degraded"));
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
await client.request<Record<string, unknown>>(TURN_REPORT_METHOD, frame);
|
|
329
|
+
pi.appendEntry(TURN_ENTRY_TYPE, { ...event, delivered: true });
|
|
330
|
+
(latestContext as { ui?: ExtensionContext["ui"] } | undefined)?.ui?.setStatus("herdr-tracking", undefined);
|
|
331
|
+
} catch (err) {
|
|
332
|
+
onError(err);
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
const beginSemanticTurn = async (ctx: ExtensionContext): Promise<void> => {
|
|
338
|
+
const sessionId = ctx.sessionManager?.getSessionId?.();
|
|
339
|
+
if (typeof sessionId !== "string" || !sessionId) return;
|
|
340
|
+
activeSemanticTurn = { sessionId, turnId: randomUUID(), generation: 0 };
|
|
341
|
+
semanticRevision = 0;
|
|
342
|
+
pendingSemanticResult = "";
|
|
343
|
+
pi.appendEntry(TURN_ENTRY_TYPE, { ...activeSemanticTurn, eventRevision: 0 });
|
|
344
|
+
await reportSemanticTurn("starting");
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
const finishSemanticTurn = async (
|
|
348
|
+
state: "completed" | "failed" | "cancelled" | "interrupted",
|
|
349
|
+
options: { result?: string; reason?: string } = {},
|
|
350
|
+
): Promise<void> => {
|
|
351
|
+
if (!activeSemanticTurn) return;
|
|
352
|
+
await reportSemanticTurn(state, options);
|
|
353
|
+
activeSemanticTurn = undefined;
|
|
354
|
+
};
|
|
355
|
+
|
|
206
356
|
const report = (state: "idle" | "working" | "blocked", message?: string): Promise<void> =>
|
|
207
357
|
send(REPORT_METHOD, {
|
|
208
358
|
pane_id: paneId,
|
|
@@ -289,11 +439,12 @@ export default function herdrReporter(pi: ExtensionAPI): void {
|
|
|
289
439
|
// agent_start, and a ref missed there would otherwise be lost until the next
|
|
290
440
|
// turn — long enough for a restart to lose the pane. Unchanged refs are
|
|
291
441
|
// suppressed, so the extra call sites cost nothing on the wire.
|
|
292
|
-
const reportSession = (ctx: ExtensionContext): Promise<void> => {
|
|
442
|
+
const reportSession = (ctx: ExtensionContext, sessionStartSource?: "new" | "resume" | "fork"): Promise<void> => {
|
|
293
443
|
const socketPath = process.env.HERDR_SOCKET_PATH;
|
|
294
444
|
if (!socketPath) {
|
|
295
445
|
return Promise.resolve();
|
|
296
446
|
}
|
|
447
|
+
if (sessionStartSource !== undefined) pendingSessionStartSource = sessionStartSource;
|
|
297
448
|
let sessionRef: Record<string, unknown> | undefined;
|
|
298
449
|
try {
|
|
299
450
|
const file = ctx.sessionManager?.getSessionFile?.();
|
|
@@ -313,7 +464,7 @@ export default function herdrReporter(pi: ExtensionAPI): void {
|
|
|
313
464
|
return Promise.resolve();
|
|
314
465
|
}
|
|
315
466
|
const refKey = JSON.stringify(sessionRef);
|
|
316
|
-
if (refKey === lastSessionRefKey) {
|
|
467
|
+
if (refKey === lastSessionRefKey && sessionStartSource === undefined) {
|
|
317
468
|
return Promise.resolve();
|
|
318
469
|
}
|
|
319
470
|
lastSessionRefKey = refKey;
|
|
@@ -347,9 +498,53 @@ export default function herdrReporter(pi: ExtensionAPI): void {
|
|
|
347
498
|
|
|
348
499
|
// Announce presence and session identity as soon as the session is initialized.
|
|
349
500
|
pi.on("session_start", async (_event, ctx) => {
|
|
501
|
+
latestContext = ctx;
|
|
350
502
|
startHeartbeat();
|
|
351
503
|
await report("idle");
|
|
352
504
|
await reportSession(ctx);
|
|
505
|
+
const persisted = persistedTurns(ctx);
|
|
506
|
+
const byRevision = new Map<string, PersistedTurn>();
|
|
507
|
+
for (const event of persisted) {
|
|
508
|
+
if (event.eventRevision !== undefined && event.state !== undefined) {
|
|
509
|
+
byRevision.set(`${event.sessionId}:${event.turnId}:${event.generation}:${event.eventRevision}`, event);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
const events = [...byRevision.values()];
|
|
513
|
+
for (const event of events.filter(event => !event.delivered)) await deliverSemanticEvent(event);
|
|
514
|
+
const last = events.at(-1);
|
|
515
|
+
const terminal = last && ["completed", "failed", "cancelled", "interrupted"].includes(last.state ?? "");
|
|
516
|
+
if (last && !terminal) {
|
|
517
|
+
activeSemanticTurn = last;
|
|
518
|
+
semanticRevision = last.eventRevision ?? 0;
|
|
519
|
+
await finishSemanticTurn("interrupted", { reason: "XCSH restarted before semantic settlement" });
|
|
520
|
+
}
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
pi.on("before_agent_start", async (_event, ctx) => {
|
|
524
|
+
latestContext = ctx;
|
|
525
|
+
if (!activeSemanticTurn) await beginSemanticTurn(ctx);
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
pi.on("session_before_switch", async () => {
|
|
529
|
+
await finishSemanticTurn("interrupted", { reason: "XCSH switched sessions before semantic settlement" });
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
pi.on("session_before_branch", async () => {
|
|
533
|
+
await finishSemanticTurn("interrupted", { reason: "XCSH forked before semantic settlement" });
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
pi.on("session_switch", async (event, ctx) => {
|
|
537
|
+
latestContext = ctx;
|
|
538
|
+
currentTurnId = 0;
|
|
539
|
+
lastNormalizedEventKey = undefined;
|
|
540
|
+
await reportSession(ctx, event.reason);
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
pi.on("session_branch", async (_event, ctx) => {
|
|
544
|
+
latestContext = ctx;
|
|
545
|
+
currentTurnId = 0;
|
|
546
|
+
lastNormalizedEventKey = undefined;
|
|
547
|
+
await reportSession(ctx, "fork");
|
|
353
548
|
});
|
|
354
549
|
|
|
355
550
|
// Busy while the agent loop is streaming a response. Re-report session identity
|
|
@@ -364,6 +559,12 @@ export default function herdrReporter(pi: ExtensionAPI): void {
|
|
|
364
559
|
// This is also the first point where a lazily-created session file is certain
|
|
365
560
|
// to exist, so it is the backstop for capturing the resume ref.
|
|
366
561
|
pi.on("agent_end", async (_event, ctx) => {
|
|
562
|
+
const messages = _event.messages;
|
|
563
|
+
const lastAssistant = [...messages]
|
|
564
|
+
.reverse()
|
|
565
|
+
.find((message): message is AssistantMessage => message.role === "assistant");
|
|
566
|
+
pendingSuccessfulResult = boundedResult(lastAssistant);
|
|
567
|
+
pendingSemanticResult = boundedSemanticResult(lastAssistant);
|
|
367
568
|
if (!normalizedPhasesObserved) await report(promptBlockedReason ? "blocked" : "idle", promptBlockedReason);
|
|
368
569
|
await reportSession(ctx);
|
|
369
570
|
});
|
|
@@ -395,6 +596,14 @@ export default function herdrReporter(pi: ExtensionAPI): void {
|
|
|
395
596
|
|
|
396
597
|
pi.on("turn_phase", async (event, ctx) => {
|
|
397
598
|
normalizedPhasesObserved = true;
|
|
599
|
+
if (event.turnId < currentTurnId) return;
|
|
600
|
+
const eventKey = `${event.turnId}:${event.phase}`;
|
|
601
|
+
if (eventKey === lastNormalizedEventKey) return;
|
|
602
|
+
if (event.turnId > currentTurnId) {
|
|
603
|
+
currentTurnId = event.turnId;
|
|
604
|
+
pendingSuccessfulResult = undefined;
|
|
605
|
+
}
|
|
606
|
+
lastNormalizedEventKey = eventKey;
|
|
398
607
|
const state =
|
|
399
608
|
event.phase === "awaiting_user"
|
|
400
609
|
? "blocked"
|
|
@@ -402,7 +611,39 @@ export default function herdrReporter(pi: ExtensionAPI): void {
|
|
|
402
611
|
? "working"
|
|
403
612
|
: "idle";
|
|
404
613
|
await report(state, event.phase === "awaiting_user" ? "user input required" : undefined);
|
|
405
|
-
|
|
614
|
+
const turnStatus =
|
|
615
|
+
event.phase === "idle"
|
|
616
|
+
? "completed"
|
|
617
|
+
: event.phase === "error"
|
|
618
|
+
? "failed"
|
|
619
|
+
: event.phase === "cancelled"
|
|
620
|
+
? "cancelled"
|
|
621
|
+
: event.phase === "awaiting_user"
|
|
622
|
+
? "waiting_input"
|
|
623
|
+
: "working";
|
|
624
|
+
await reportMetadata({
|
|
625
|
+
state_labels: { [state]: event.phase },
|
|
626
|
+
tokens: {
|
|
627
|
+
xcsh_turn_id: String(event.turnId),
|
|
628
|
+
xcsh_turn_status: turnStatus,
|
|
629
|
+
xcsh_result: event.phase === "idle" ? (pendingSuccessfulResult ?? null) : null,
|
|
630
|
+
},
|
|
631
|
+
ttl_ms: PHASE_LABEL_TTL_MS,
|
|
632
|
+
});
|
|
633
|
+
if (event.phase === "idle") {
|
|
634
|
+
await finishSemanticTurn("completed", { result: pendingSemanticResult });
|
|
635
|
+
} else if (event.phase === "error") {
|
|
636
|
+
await finishSemanticTurn("failed", { reason: "XCSH turn failed" });
|
|
637
|
+
} else if (event.phase === "cancelled") {
|
|
638
|
+
await finishSemanticTurn("cancelled", { reason: "XCSH turn cancelled" });
|
|
639
|
+
} else if (event.phase === "awaiting_user") {
|
|
640
|
+
await reportSemanticTurn("waiting_input", { reason: "user input required" });
|
|
641
|
+
} else {
|
|
642
|
+
await reportSemanticTurn("working");
|
|
643
|
+
}
|
|
644
|
+
if (event.phase === "idle" || event.phase === "error" || event.phase === "cancelled") {
|
|
645
|
+
pendingSuccessfulResult = undefined;
|
|
646
|
+
}
|
|
406
647
|
await reportSession(ctx);
|
|
407
648
|
});
|
|
408
649
|
|
|
@@ -447,9 +688,10 @@ export default function herdrReporter(pi: ExtensionAPI): void {
|
|
|
447
688
|
});
|
|
448
689
|
|
|
449
690
|
// Relinquish pane authority so herdr stops showing xcsh once we exit.
|
|
450
|
-
pi.on("session_shutdown", () => {
|
|
691
|
+
pi.on("session_shutdown", async () => {
|
|
451
692
|
stopHeartbeat();
|
|
452
|
-
|
|
693
|
+
await finishSemanticTurn("interrupted", { reason: "XCSH shut down before semantic settlement" });
|
|
694
|
+
await send(RELEASE_METHOD, {
|
|
453
695
|
pane_id: paneId,
|
|
454
696
|
source: HERDR_SOURCE,
|
|
455
697
|
agent: HERDR_AGENT_LABEL,
|
package/src/herdr/client.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { connect } from "node:net";
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const HERDR_PROTOCOL_MIN_VERSION = 19;
|
|
5
|
+
export const HERDR_PROTOCOL_MAX_VERSION = 20;
|
|
5
6
|
const DEFAULT_TIMEOUT_MS = 5_000;
|
|
6
7
|
const MAX_RESPONSE_BYTES = 4 * 1024 * 1024;
|
|
7
8
|
|
|
@@ -19,9 +20,11 @@ function isRecord(value: unknown): value is Record<string, unknown> {
|
|
|
19
20
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
/** Typed, one-request-per-connection client for Herdr
|
|
23
|
+
/** Typed, one-request-per-connection client for supported Herdr JSONL protocols. */
|
|
23
24
|
export class HerdrClient {
|
|
24
25
|
private protocolChecked = false;
|
|
26
|
+
private negotiatedProtocol: number | undefined;
|
|
27
|
+
private capabilities: Readonly<Record<string, unknown>> = {};
|
|
25
28
|
|
|
26
29
|
constructor(
|
|
27
30
|
readonly socketPath: string,
|
|
@@ -32,16 +35,36 @@ export class HerdrClient {
|
|
|
32
35
|
|
|
33
36
|
async ensureProtocol(): Promise<void> {
|
|
34
37
|
if (this.protocolChecked) return;
|
|
35
|
-
const pong = await this.requestRaw<{
|
|
36
|
-
|
|
38
|
+
const pong = await this.requestRaw<{
|
|
39
|
+
type: string;
|
|
40
|
+
protocol: number;
|
|
41
|
+
version: string;
|
|
42
|
+
capabilities?: Record<string, unknown>;
|
|
43
|
+
}>("ping", {});
|
|
44
|
+
if (
|
|
45
|
+
pong.type !== "pong" ||
|
|
46
|
+
!Number.isInteger(pong.protocol) ||
|
|
47
|
+
pong.protocol < HERDR_PROTOCOL_MIN_VERSION ||
|
|
48
|
+
pong.protocol > HERDR_PROTOCOL_MAX_VERSION
|
|
49
|
+
) {
|
|
37
50
|
throw new HerdrProtocolError(
|
|
38
|
-
`Herdr protocol mismatch:
|
|
51
|
+
`Herdr protocol mismatch: supported ${HERDR_PROTOCOL_MIN_VERSION}-${HERDR_PROTOCOL_MAX_VERSION}, received ${String(pong.protocol)}`,
|
|
39
52
|
"protocol_mismatch",
|
|
40
53
|
);
|
|
41
54
|
}
|
|
55
|
+
this.negotiatedProtocol = pong.protocol;
|
|
56
|
+
this.capabilities = isRecord(pong.capabilities) ? Object.freeze({ ...pong.capabilities }) : {};
|
|
42
57
|
this.protocolChecked = true;
|
|
43
58
|
}
|
|
44
59
|
|
|
60
|
+
get protocolVersion(): number | undefined {
|
|
61
|
+
return this.negotiatedProtocol;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
hasCapability(name: string): boolean {
|
|
65
|
+
return this.capabilities[name] === true;
|
|
66
|
+
}
|
|
67
|
+
|
|
45
68
|
async request<T extends Record<string, unknown>>(method: string, params: Record<string, unknown>): Promise<T> {
|
|
46
69
|
await this.ensureProtocol();
|
|
47
70
|
return this.requestRaw<T>(method, params);
|
|
@@ -17,17 +17,17 @@ export interface BuildInfo {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export const BUILD_INFO: BuildInfo = {
|
|
20
|
-
"version": "21.
|
|
21
|
-
"commit": "
|
|
22
|
-
"shortCommit": "
|
|
20
|
+
"version": "21.19.0",
|
|
21
|
+
"commit": "d6ee0a02bee64b4deefa70ca26b25806055a526c",
|
|
22
|
+
"shortCommit": "d6ee0a0",
|
|
23
23
|
"branch": "main",
|
|
24
|
-
"tag": "v21.
|
|
25
|
-
"commitDate": "2026-09-
|
|
26
|
-
"buildDate": "2026-09-
|
|
24
|
+
"tag": "v21.19.0",
|
|
25
|
+
"commitDate": "2026-09-08T17:45:15+00:00",
|
|
26
|
+
"buildDate": "2026-09-08T18:51:12.735Z",
|
|
27
27
|
"dirty": true,
|
|
28
28
|
"prNumber": "",
|
|
29
29
|
"repoUrl": "https://github.com/f5-sales-demo/xcsh",
|
|
30
30
|
"repoSlug": "f5-sales-demo/xcsh",
|
|
31
|
-
"commitUrl": "https://github.com/f5-sales-demo/xcsh/commit/
|
|
32
|
-
"releaseUrl": "https://github.com/f5-sales-demo/xcsh/releases/tag/v21.
|
|
31
|
+
"commitUrl": "https://github.com/f5-sales-demo/xcsh/commit/d6ee0a02bee64b4deefa70ca26b25806055a526c",
|
|
32
|
+
"releaseUrl": "https://github.com/f5-sales-demo/xcsh/releases/tag/v21.19.0"
|
|
33
33
|
};
|