@autohq/cli 0.1.222 → 0.1.223
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/dist/agent-bridge.js +289 -19
- package/dist/index.js +293 -23
- package/package.json +1 -1
package/dist/agent-bridge.js
CHANGED
|
@@ -23319,7 +23319,7 @@ Object.assign(lookup, {
|
|
|
23319
23319
|
// package.json
|
|
23320
23320
|
var package_default = {
|
|
23321
23321
|
name: "@autohq/cli",
|
|
23322
|
-
version: "0.1.
|
|
23322
|
+
version: "0.1.223",
|
|
23323
23323
|
license: "SEE LICENSE IN README.md",
|
|
23324
23324
|
publishConfig: {
|
|
23325
23325
|
access: "public"
|
|
@@ -23455,9 +23455,10 @@ async function runAgentBridgeSocket(options) {
|
|
|
23455
23455
|
token: options.token,
|
|
23456
23456
|
onBootstrap: options.onBootstrap,
|
|
23457
23457
|
createHandler: (bootstrap) => options.createHandler({
|
|
23458
|
-
emitOutput: (output) => emitOutputWithAck(socket, output),
|
|
23458
|
+
emitOutput: (output) => emitOutputWithAck(socket, output, options.runtimeLogger),
|
|
23459
23459
|
bootstrap,
|
|
23460
23460
|
outputSeqStart: bootstrap.outputSeqStart,
|
|
23461
|
+
runtimeLogger: options.runtimeLogger,
|
|
23461
23462
|
socketId: () => socket.id,
|
|
23462
23463
|
writeOutput: options.writeOutput
|
|
23463
23464
|
}),
|
|
@@ -23495,23 +23496,55 @@ async function runAgentBridgeSocket(options) {
|
|
|
23495
23496
|
});
|
|
23496
23497
|
});
|
|
23497
23498
|
socket.on(RUNTIME_BRIDGE_COMMAND_EVENT, (rawDelivery, ack) => {
|
|
23499
|
+
const startedAt = Date.now();
|
|
23500
|
+
const logContext = runtimeCommandLogContext(rawDelivery, socket.id);
|
|
23501
|
+
options.runtimeLogger?.info("agent_bridge_command_received", logContext);
|
|
23498
23502
|
if (!handler) {
|
|
23499
23503
|
const delivery = RuntimeBridgeCommandDeliverySchema.safeParse(rawDelivery);
|
|
23500
23504
|
if (delivery.success) {
|
|
23501
|
-
|
|
23502
|
-
|
|
23503
|
-
|
|
23504
|
-
|
|
23505
|
-
|
|
23506
|
-
|
|
23507
|
-
|
|
23508
|
-
|
|
23505
|
+
const response = commandAck({
|
|
23506
|
+
delivery: delivery.data,
|
|
23507
|
+
socketId: socket.id,
|
|
23508
|
+
status: "failed",
|
|
23509
|
+
error: "Bridge command received before bootstrap completed"
|
|
23510
|
+
});
|
|
23511
|
+
options.runtimeLogger?.info("agent_bridge_command_ack_ready", {
|
|
23512
|
+
...logContext,
|
|
23513
|
+
duration_ms: Date.now() - startedAt,
|
|
23514
|
+
ack_status: response.status,
|
|
23515
|
+
error: response.error
|
|
23516
|
+
});
|
|
23517
|
+
ack(response);
|
|
23509
23518
|
return;
|
|
23510
23519
|
}
|
|
23511
|
-
|
|
23520
|
+
const error51 = "Bridge command received before bootstrap completed";
|
|
23521
|
+
options.runtimeLogger?.info("agent_bridge_command_ack_ready", {
|
|
23522
|
+
...logContext,
|
|
23523
|
+
duration_ms: Date.now() - startedAt,
|
|
23524
|
+
ack_status: "failed",
|
|
23525
|
+
error: error51
|
|
23526
|
+
});
|
|
23527
|
+
ack({ error: error51 });
|
|
23512
23528
|
return;
|
|
23513
23529
|
}
|
|
23514
|
-
void handler.handleCommand(rawDelivery).then((response) =>
|
|
23530
|
+
void handler.handleCommand(rawDelivery).then((response) => {
|
|
23531
|
+
const parsedResponse = RuntimeBridgeCommandAckSchema.safeParse(response);
|
|
23532
|
+
options.runtimeLogger?.info("agent_bridge_command_ack_ready", {
|
|
23533
|
+
...logContext,
|
|
23534
|
+
duration_ms: Date.now() - startedAt,
|
|
23535
|
+
ack_parse_status: parsedResponse.success ? "succeeded" : "failed",
|
|
23536
|
+
ack_status: parsedResponse.success ? parsedResponse.data.status : void 0,
|
|
23537
|
+
ack_socket_id: parsedResponse.success ? parsedResponse.data.socketId : void 0,
|
|
23538
|
+
error: parsedResponse.success ? parsedResponse.data.error : parsedResponse.error.message
|
|
23539
|
+
});
|
|
23540
|
+
ack(response);
|
|
23541
|
+
}).catch((error51) => {
|
|
23542
|
+
options.runtimeLogger?.warn("agent_bridge_command_handler_failed", {
|
|
23543
|
+
...logContext,
|
|
23544
|
+
duration_ms: Date.now() - startedAt,
|
|
23545
|
+
ack_status: "failed",
|
|
23546
|
+
error: errorMessage(error51)
|
|
23547
|
+
});
|
|
23515
23548
|
const delivery = RuntimeBridgeCommandDeliverySchema.safeParse(rawDelivery);
|
|
23516
23549
|
if (!delivery.success) {
|
|
23517
23550
|
ack({
|
|
@@ -23613,27 +23646,54 @@ function createSessiontimeBridgeBootstrapListener(input) {
|
|
|
23613
23646
|
}
|
|
23614
23647
|
};
|
|
23615
23648
|
}
|
|
23616
|
-
function emitOutputWithAck(socket, output) {
|
|
23649
|
+
function emitOutputWithAck(socket, output, runtimeLogger) {
|
|
23650
|
+
const startedAt = Date.now();
|
|
23651
|
+
runtimeLogger?.info(
|
|
23652
|
+
"agent_bridge_output_emit_started",
|
|
23653
|
+
outputLogContext(output, socket.id)
|
|
23654
|
+
);
|
|
23617
23655
|
return new Promise((resolve, reject) => {
|
|
23618
23656
|
socket.timeout(5e3).emit(
|
|
23619
23657
|
RUNTIME_BRIDGE_OUTPUT_EVENT,
|
|
23620
23658
|
output,
|
|
23621
23659
|
(error51, rawAck) => {
|
|
23622
23660
|
if (error51) {
|
|
23661
|
+
runtimeLogger?.warn("agent_bridge_output_emit_ack_failed", {
|
|
23662
|
+
...outputLogContext(output, socket.id),
|
|
23663
|
+
duration_ms: Date.now() - startedAt,
|
|
23664
|
+
error: error51.message
|
|
23665
|
+
});
|
|
23623
23666
|
reject(error51);
|
|
23624
23667
|
return;
|
|
23625
23668
|
}
|
|
23626
23669
|
const ack = RuntimeBridgeOutputAckSchema.safeParse(rawAck);
|
|
23627
23670
|
if (!ack.success) {
|
|
23671
|
+
runtimeLogger?.warn("agent_bridge_output_emit_ack_invalid", {
|
|
23672
|
+
...outputLogContext(output, socket.id),
|
|
23673
|
+
duration_ms: Date.now() - startedAt,
|
|
23674
|
+
error: ack.error.message
|
|
23675
|
+
});
|
|
23628
23676
|
reject(ack.error);
|
|
23629
23677
|
return;
|
|
23630
23678
|
}
|
|
23631
23679
|
if (ack.data.status === "failed") {
|
|
23680
|
+
runtimeLogger?.warn("agent_bridge_output_emit_ack_rejected", {
|
|
23681
|
+
...outputLogContext(output, socket.id),
|
|
23682
|
+
duration_ms: Date.now() - startedAt,
|
|
23683
|
+
ack_status: ack.data.status,
|
|
23684
|
+
error: ack.data.error
|
|
23685
|
+
});
|
|
23632
23686
|
reject(
|
|
23633
23687
|
new Error(ack.data.error ?? "Bridge rejected runtime output")
|
|
23634
23688
|
);
|
|
23635
23689
|
return;
|
|
23636
23690
|
}
|
|
23691
|
+
runtimeLogger?.info("agent_bridge_output_emit_ack_ready", {
|
|
23692
|
+
...outputLogContext(output, socket.id),
|
|
23693
|
+
duration_ms: Date.now() - startedAt,
|
|
23694
|
+
ack_status: ack.data.status,
|
|
23695
|
+
cursor: ack.data.cursor
|
|
23696
|
+
});
|
|
23637
23697
|
resolve(ack.data);
|
|
23638
23698
|
}
|
|
23639
23699
|
);
|
|
@@ -23678,6 +23738,42 @@ function isNgrokFreeUrl(url3) {
|
|
|
23678
23738
|
return false;
|
|
23679
23739
|
}
|
|
23680
23740
|
}
|
|
23741
|
+
function runtimeCommandLogContext(rawDelivery, socketId) {
|
|
23742
|
+
const delivery = RuntimeBridgeCommandDeliverySchema.safeParse(rawDelivery);
|
|
23743
|
+
if (!delivery.success) {
|
|
23744
|
+
return {
|
|
23745
|
+
socket_id: socketId,
|
|
23746
|
+
delivery_parse_status: "failed"
|
|
23747
|
+
};
|
|
23748
|
+
}
|
|
23749
|
+
return {
|
|
23750
|
+
socket_id: socketId,
|
|
23751
|
+
delivery_parse_status: "succeeded",
|
|
23752
|
+
session_id: delivery.data.sessionId,
|
|
23753
|
+
runtime_id: delivery.data.runtimeId,
|
|
23754
|
+
bridge_lease_id: delivery.data.bridgeLeaseId,
|
|
23755
|
+
delivery_id: delivery.data.deliveryId,
|
|
23756
|
+
command_id: delivery.data.commandId,
|
|
23757
|
+
command_kind: delivery.data.kind
|
|
23758
|
+
};
|
|
23759
|
+
}
|
|
23760
|
+
function outputLogContext(output, socketId) {
|
|
23761
|
+
return {
|
|
23762
|
+
socket_id: socketId,
|
|
23763
|
+
session_id: output.sessionId,
|
|
23764
|
+
runtime_id: output.runtimeId,
|
|
23765
|
+
bridge_lease_id: output.bridgeLeaseId,
|
|
23766
|
+
output_seq: output.outputSeq,
|
|
23767
|
+
output_type: output.type,
|
|
23768
|
+
role: "role" in output ? output.role : void 0,
|
|
23769
|
+
kind: "kind" in output ? output.kind : void 0,
|
|
23770
|
+
output_status: "status" in output ? output.status : void 0,
|
|
23771
|
+
message_id: "messageId" in output ? output.messageId : void 0
|
|
23772
|
+
};
|
|
23773
|
+
}
|
|
23774
|
+
function errorMessage(error51) {
|
|
23775
|
+
return error51 instanceof Error ? error51.message : String(error51);
|
|
23776
|
+
}
|
|
23681
23777
|
|
|
23682
23778
|
// ../../packages/schemas/src/account.ts
|
|
23683
23779
|
var AccountDeleteRequestSchema = external_exports.object({
|
|
@@ -24499,12 +24595,12 @@ function parseClaudeCodeStreamRecord(parsed) {
|
|
|
24499
24595
|
}
|
|
24500
24596
|
const isError = record2.is_error === true || record2.subtype === "error";
|
|
24501
24597
|
const sdkErrorMessage = record2.errors?.map((error51) => error51.trim()).filter(Boolean).join("\n");
|
|
24502
|
-
const
|
|
24598
|
+
const errorMessage2 = isError ? record2.error ?? record2.result ?? (sdkErrorMessage || void 0) ?? "claude-code reported an error" : void 0;
|
|
24503
24599
|
return {
|
|
24504
24600
|
projections: [],
|
|
24505
24601
|
result: {
|
|
24506
24602
|
isError,
|
|
24507
|
-
errorMessage
|
|
24603
|
+
errorMessage: errorMessage2
|
|
24508
24604
|
}
|
|
24509
24605
|
};
|
|
24510
24606
|
}
|
|
@@ -27316,6 +27412,12 @@ var AgentBridgeOutputBuffer = class {
|
|
|
27316
27412
|
this.outputSeq,
|
|
27317
27413
|
buildOutputEnvelope(context, this.outputSeq, projection)
|
|
27318
27414
|
);
|
|
27415
|
+
this.input.runtimeLogger?.info(
|
|
27416
|
+
"agent_bridge_output_buffer_enqueued",
|
|
27417
|
+
this.outputLogContext(this.pendingOutputs.get(this.outputSeq), {
|
|
27418
|
+
pending_count: this.pendingOutputs.size
|
|
27419
|
+
})
|
|
27420
|
+
);
|
|
27319
27421
|
await this.drainPendingOutputs();
|
|
27320
27422
|
}
|
|
27321
27423
|
async replayPendingOutputs() {
|
|
@@ -27334,8 +27436,16 @@ var AgentBridgeOutputBuffer = class {
|
|
|
27334
27436
|
}
|
|
27335
27437
|
if (options.force) {
|
|
27336
27438
|
this.drainBlocked = false;
|
|
27439
|
+
this.input.runtimeLogger?.info(
|
|
27440
|
+
"agent_bridge_output_buffer_replay_started",
|
|
27441
|
+
{ pending_count: this.pendingOutputs.size }
|
|
27442
|
+
);
|
|
27337
27443
|
}
|
|
27338
27444
|
if (this.drainBlocked) {
|
|
27445
|
+
this.input.runtimeLogger?.warn(
|
|
27446
|
+
"agent_bridge_output_buffer_drain_blocked",
|
|
27447
|
+
{ pending_count: this.pendingOutputs.size }
|
|
27448
|
+
);
|
|
27339
27449
|
return;
|
|
27340
27450
|
}
|
|
27341
27451
|
this.drainPromise ??= (async () => {
|
|
@@ -27355,11 +27465,36 @@ var AgentBridgeOutputBuffer = class {
|
|
|
27355
27465
|
await this.drainPromise;
|
|
27356
27466
|
}
|
|
27357
27467
|
async emitUntilAcked(output) {
|
|
27468
|
+
const startedAt = Date.now();
|
|
27469
|
+
this.input.runtimeLogger?.info(
|
|
27470
|
+
"agent_bridge_output_buffer_emit_started",
|
|
27471
|
+
this.outputLogContext(output, {
|
|
27472
|
+
pending_count: this.pendingOutputs.size
|
|
27473
|
+
})
|
|
27474
|
+
);
|
|
27358
27475
|
const ack = await this.input.emitOutput(output);
|
|
27359
27476
|
if (isSuccessfulOutputAck(ack)) {
|
|
27360
27477
|
this.pendingOutputs.delete(output.outputSeq);
|
|
27478
|
+
this.input.runtimeLogger?.info(
|
|
27479
|
+
"agent_bridge_output_buffer_emit_ready",
|
|
27480
|
+
this.outputLogContext(output, {
|
|
27481
|
+
duration_ms: Date.now() - startedAt,
|
|
27482
|
+
ack_status: ack.status,
|
|
27483
|
+
cursor: ack.cursor,
|
|
27484
|
+
pending_count: this.pendingOutputs.size
|
|
27485
|
+
})
|
|
27486
|
+
);
|
|
27361
27487
|
return;
|
|
27362
27488
|
}
|
|
27489
|
+
this.input.runtimeLogger?.warn(
|
|
27490
|
+
"agent_bridge_output_buffer_emit_rejected",
|
|
27491
|
+
this.outputLogContext(output, {
|
|
27492
|
+
duration_ms: Date.now() - startedAt,
|
|
27493
|
+
ack_status: ack.status,
|
|
27494
|
+
error: ack.error,
|
|
27495
|
+
pending_count: this.pendingOutputs.size
|
|
27496
|
+
})
|
|
27497
|
+
);
|
|
27363
27498
|
throw new Error(ack.error ?? `Bridge rejected output: ${ack.status}`);
|
|
27364
27499
|
}
|
|
27365
27500
|
nextPendingOutput() {
|
|
@@ -27367,6 +27502,17 @@ var AgentBridgeOutputBuffer = class {
|
|
|
27367
27502
|
(left, right) => left.outputSeq - right.outputSeq
|
|
27368
27503
|
)[0] ?? null;
|
|
27369
27504
|
}
|
|
27505
|
+
outputLogContext(output, fields = {}) {
|
|
27506
|
+
return {
|
|
27507
|
+
output_seq: output?.outputSeq,
|
|
27508
|
+
output_type: output?.type,
|
|
27509
|
+
role: output && "role" in output ? output.role : void 0,
|
|
27510
|
+
kind: output && "kind" in output ? output.kind : void 0,
|
|
27511
|
+
output_status: output && "status" in output ? output.status : void 0,
|
|
27512
|
+
message_id: output && "messageId" in output ? output.messageId : void 0,
|
|
27513
|
+
...fields
|
|
27514
|
+
};
|
|
27515
|
+
}
|
|
27370
27516
|
};
|
|
27371
27517
|
function buildOutputEnvelope(context, outputSeq, projection) {
|
|
27372
27518
|
if (projection.type === "delta") {
|
|
@@ -47347,15 +47493,33 @@ var ClaudeAgentBridgeSessionImpl = class {
|
|
|
47347
47493
|
}
|
|
47348
47494
|
async sendMessage(message, options) {
|
|
47349
47495
|
const mode = options?.mode ?? "interrupt";
|
|
47496
|
+
const startedAt = Date.now();
|
|
47497
|
+
this.input.runtimeLogger?.info("agent_bridge_claude_send_message_started", {
|
|
47498
|
+
delivery_mode: mode,
|
|
47499
|
+
state: this.state.kind,
|
|
47500
|
+
active_turn_count: this.activeTurnCount,
|
|
47501
|
+
pending_tool_use_count: this.pendingToolUseIds.size,
|
|
47502
|
+
deferred_count: this.deferredMessages.length
|
|
47503
|
+
});
|
|
47350
47504
|
if (mode === "deferred" && this.hasInterruptibleTurn()) {
|
|
47351
47505
|
this.deferredMessages.push(message);
|
|
47352
|
-
this.input.
|
|
47353
|
-
|
|
47354
|
-
|
|
47506
|
+
this.input.runtimeLogger?.info("agent_bridge_claude_message_deferred", {
|
|
47507
|
+
active_turn_count: this.activeTurnCount,
|
|
47508
|
+
pending_tool_use_count: this.pendingToolUseIds.size,
|
|
47509
|
+
deferred_count: this.deferredMessages.length
|
|
47510
|
+
});
|
|
47355
47511
|
return;
|
|
47356
47512
|
}
|
|
47357
47513
|
await this.interruptActiveTurnBeforeMessage();
|
|
47358
47514
|
this.enqueueUserMessage(message);
|
|
47515
|
+
this.input.runtimeLogger?.info("agent_bridge_claude_send_message_queued", {
|
|
47516
|
+
delivery_mode: mode,
|
|
47517
|
+
duration_ms: Date.now() - startedAt,
|
|
47518
|
+
state: this.state.kind,
|
|
47519
|
+
active_turn_count: this.activeTurnCount,
|
|
47520
|
+
pending_tool_use_count: this.pendingToolUseIds.size,
|
|
47521
|
+
deferred_count: this.deferredMessages.length
|
|
47522
|
+
});
|
|
47359
47523
|
}
|
|
47360
47524
|
close() {
|
|
47361
47525
|
const previousState = this.state;
|
|
@@ -47460,6 +47624,12 @@ var ClaudeAgentBridgeSessionImpl = class {
|
|
|
47460
47624
|
this.pendingToolUseIds.clear();
|
|
47461
47625
|
this.turnResultCount += 1;
|
|
47462
47626
|
this.resolveTurnSettlement(true);
|
|
47627
|
+
this.input.runtimeLogger?.info("agent_bridge_claude_turn_result", {
|
|
47628
|
+
active_turn_count: this.activeTurnCount,
|
|
47629
|
+
pending_tool_use_count: this.pendingToolUseIds.size,
|
|
47630
|
+
turn_result_count: this.turnResultCount,
|
|
47631
|
+
deferred_count: this.deferredMessages.length
|
|
47632
|
+
});
|
|
47463
47633
|
if (this.activeTurnCount === 0) {
|
|
47464
47634
|
this.flushDeferredMessages();
|
|
47465
47635
|
}
|
|
@@ -47500,6 +47670,12 @@ var ClaudeAgentBridgeSessionImpl = class {
|
|
|
47500
47670
|
enqueueUserMessage(message) {
|
|
47501
47671
|
this.inputQueue.push(claudeAgentUserMessage(message));
|
|
47502
47672
|
this.activeTurnCount += 1;
|
|
47673
|
+
this.input.runtimeLogger?.info("agent_bridge_claude_message_enqueued", {
|
|
47674
|
+
state: this.state.kind,
|
|
47675
|
+
active_turn_count: this.activeTurnCount,
|
|
47676
|
+
pending_tool_use_count: this.pendingToolUseIds.size,
|
|
47677
|
+
deferred_count: this.deferredMessages.length
|
|
47678
|
+
});
|
|
47503
47679
|
void this.ensureRunningQuery().catch((error51) => {
|
|
47504
47680
|
void this.input.onError(error51);
|
|
47505
47681
|
});
|
|
@@ -47873,10 +48049,25 @@ var ClaudeCodeCommandHandler = class {
|
|
|
47873
48049
|
this.settlePendingQuestions("Runtime is shutting down");
|
|
47874
48050
|
}
|
|
47875
48051
|
async handleCommand(rawDelivery) {
|
|
48052
|
+
const startedAt = Date.now();
|
|
47876
48053
|
const delivery = RuntimeBridgeCommandDeliverySchema.parse(rawDelivery);
|
|
47877
48054
|
const socketId = this.input.socketId?.();
|
|
48055
|
+
this.input.runtimeLogger?.info(
|
|
48056
|
+
"agent_bridge_claude_command_started",
|
|
48057
|
+
commandLogContext(delivery, {
|
|
48058
|
+
socket_id: socketId
|
|
48059
|
+
})
|
|
48060
|
+
);
|
|
47878
48061
|
const activeContext = this.context;
|
|
47879
48062
|
if (!activeContext || delivery.sessionId !== activeContext.sessionId || delivery.runtimeId !== activeContext.runtimeId || delivery.bridgeLeaseId !== activeContext.bridgeLeaseId) {
|
|
48063
|
+
this.input.runtimeLogger?.warn(
|
|
48064
|
+
"agent_bridge_claude_command_stale",
|
|
48065
|
+
commandLogContext(delivery, {
|
|
48066
|
+
socket_id: socketId,
|
|
48067
|
+
duration_ms: Date.now() - startedAt,
|
|
48068
|
+
active_bridge_lease_id: activeContext?.bridgeLeaseId
|
|
48069
|
+
})
|
|
48070
|
+
);
|
|
47880
48071
|
return commandAck({
|
|
47881
48072
|
delivery,
|
|
47882
48073
|
socketId,
|
|
@@ -47884,6 +48075,13 @@ var ClaudeCodeCommandHandler = class {
|
|
|
47884
48075
|
});
|
|
47885
48076
|
}
|
|
47886
48077
|
if (this.injectedCommands.has(delivery.commandId)) {
|
|
48078
|
+
this.input.runtimeLogger?.info(
|
|
48079
|
+
"agent_bridge_claude_command_duplicate",
|
|
48080
|
+
commandLogContext(delivery, {
|
|
48081
|
+
socket_id: socketId,
|
|
48082
|
+
duration_ms: Date.now() - startedAt
|
|
48083
|
+
})
|
|
48084
|
+
);
|
|
47887
48085
|
return commandAck({
|
|
47888
48086
|
delivery,
|
|
47889
48087
|
socketId,
|
|
@@ -47896,6 +48094,13 @@ var ClaudeCodeCommandHandler = class {
|
|
|
47896
48094
|
if (delivery.kind === "stop") {
|
|
47897
48095
|
this.injectedCommands.add(delivery.commandId);
|
|
47898
48096
|
this.shutdown();
|
|
48097
|
+
this.input.runtimeLogger?.info(
|
|
48098
|
+
"agent_bridge_claude_command_stop_ready",
|
|
48099
|
+
commandLogContext(delivery, {
|
|
48100
|
+
socket_id: socketId,
|
|
48101
|
+
duration_ms: Date.now() - startedAt
|
|
48102
|
+
})
|
|
48103
|
+
);
|
|
47899
48104
|
return commandAck({
|
|
47900
48105
|
delivery,
|
|
47901
48106
|
socketId,
|
|
@@ -47903,6 +48108,13 @@ var ClaudeCodeCommandHandler = class {
|
|
|
47903
48108
|
});
|
|
47904
48109
|
}
|
|
47905
48110
|
if (delivery.kind !== "message") {
|
|
48111
|
+
this.input.runtimeLogger?.warn(
|
|
48112
|
+
"agent_bridge_claude_command_unsupported",
|
|
48113
|
+
commandLogContext(delivery, {
|
|
48114
|
+
socket_id: socketId,
|
|
48115
|
+
duration_ms: Date.now() - startedAt
|
|
48116
|
+
})
|
|
48117
|
+
);
|
|
47906
48118
|
return commandAck({
|
|
47907
48119
|
delivery,
|
|
47908
48120
|
socketId,
|
|
@@ -47921,6 +48133,11 @@ var ClaudeCodeCommandHandler = class {
|
|
|
47921
48133
|
}
|
|
47922
48134
|
this.injectedCommands.add(delivery.commandId);
|
|
47923
48135
|
try {
|
|
48136
|
+
const emitStartedAt = Date.now();
|
|
48137
|
+
this.input.runtimeLogger?.info(
|
|
48138
|
+
"agent_bridge_claude_command_user_entry_emit_started",
|
|
48139
|
+
commandLogContext(delivery, { socket_id: socketId })
|
|
48140
|
+
);
|
|
47924
48141
|
await this.emitBridgeOutput(activeContext, {
|
|
47925
48142
|
type: "entry",
|
|
47926
48143
|
entry: {
|
|
@@ -47933,11 +48150,43 @@ var ClaudeCodeCommandHandler = class {
|
|
|
47933
48150
|
}
|
|
47934
48151
|
}
|
|
47935
48152
|
});
|
|
48153
|
+
this.input.runtimeLogger?.info(
|
|
48154
|
+
"agent_bridge_claude_command_user_entry_emit_ready",
|
|
48155
|
+
commandLogContext(delivery, {
|
|
48156
|
+
socket_id: socketId,
|
|
48157
|
+
duration_ms: Date.now() - emitStartedAt
|
|
48158
|
+
})
|
|
48159
|
+
);
|
|
48160
|
+
const sendStartedAt = Date.now();
|
|
48161
|
+
const mode = deliveryMode(delivery);
|
|
48162
|
+
this.input.runtimeLogger?.info(
|
|
48163
|
+
"agent_bridge_claude_command_send_message_started",
|
|
48164
|
+
commandLogContext(delivery, {
|
|
48165
|
+
socket_id: socketId,
|
|
48166
|
+
delivery_mode: mode
|
|
48167
|
+
})
|
|
48168
|
+
);
|
|
47936
48169
|
await this.ensureAgentSession().sendMessage(message, {
|
|
47937
|
-
mode
|
|
48170
|
+
mode
|
|
47938
48171
|
});
|
|
48172
|
+
this.input.runtimeLogger?.info(
|
|
48173
|
+
"agent_bridge_claude_command_send_message_ready",
|
|
48174
|
+
commandLogContext(delivery, {
|
|
48175
|
+
socket_id: socketId,
|
|
48176
|
+
delivery_mode: mode,
|
|
48177
|
+
duration_ms: Date.now() - sendStartedAt
|
|
48178
|
+
})
|
|
48179
|
+
);
|
|
47939
48180
|
} catch (error51) {
|
|
47940
48181
|
this.injectedCommands.delete(delivery.commandId);
|
|
48182
|
+
this.input.runtimeLogger?.warn(
|
|
48183
|
+
"agent_bridge_claude_command_failed",
|
|
48184
|
+
commandLogContext(delivery, {
|
|
48185
|
+
socket_id: socketId,
|
|
48186
|
+
duration_ms: Date.now() - startedAt,
|
|
48187
|
+
error: error51 instanceof Error ? error51.message : String(error51)
|
|
48188
|
+
})
|
|
48189
|
+
);
|
|
47941
48190
|
return commandAck({
|
|
47942
48191
|
delivery,
|
|
47943
48192
|
socketId,
|
|
@@ -47945,6 +48194,13 @@ var ClaudeCodeCommandHandler = class {
|
|
|
47945
48194
|
error: error51 instanceof Error ? error51.message : String(error51)
|
|
47946
48195
|
});
|
|
47947
48196
|
}
|
|
48197
|
+
this.input.runtimeLogger?.info(
|
|
48198
|
+
"agent_bridge_claude_command_injected",
|
|
48199
|
+
commandLogContext(delivery, {
|
|
48200
|
+
socket_id: socketId,
|
|
48201
|
+
duration_ms: Date.now() - startedAt
|
|
48202
|
+
})
|
|
48203
|
+
);
|
|
47948
48204
|
return commandAck({
|
|
47949
48205
|
delivery,
|
|
47950
48206
|
socketId,
|
|
@@ -48159,6 +48415,7 @@ var ClaudeCodeCommandHandler = class {
|
|
|
48159
48415
|
}
|
|
48160
48416
|
this.input.writeOutput?.("agent_bridge_claude_sdk_exited");
|
|
48161
48417
|
},
|
|
48418
|
+
runtimeLogger: this.input.runtimeLogger,
|
|
48162
48419
|
writeOutput: this.input.writeOutput
|
|
48163
48420
|
});
|
|
48164
48421
|
this.agentSession = session;
|
|
@@ -48191,6 +48448,17 @@ function deliveryMode(delivery) {
|
|
|
48191
48448
|
}
|
|
48192
48449
|
return "interrupt";
|
|
48193
48450
|
}
|
|
48451
|
+
function commandLogContext(delivery, fields = {}) {
|
|
48452
|
+
return {
|
|
48453
|
+
session_id: delivery.sessionId,
|
|
48454
|
+
runtime_id: delivery.runtimeId,
|
|
48455
|
+
bridge_lease_id: delivery.bridgeLeaseId,
|
|
48456
|
+
delivery_id: delivery.deliveryId,
|
|
48457
|
+
command_id: delivery.commandId,
|
|
48458
|
+
command_kind: delivery.kind,
|
|
48459
|
+
...fields
|
|
48460
|
+
};
|
|
48461
|
+
}
|
|
48194
48462
|
|
|
48195
48463
|
// src/commands/agent-bridge/harness/index.ts
|
|
48196
48464
|
async function runAgentBridgeHarness(options) {
|
|
@@ -48204,6 +48472,7 @@ function createHarnessCommandHandler(input) {
|
|
|
48204
48472
|
const base = {
|
|
48205
48473
|
emitOutput: input.emitOutput,
|
|
48206
48474
|
...input.outputSeqStart !== void 0 ? { outputSeqStart: input.outputSeqStart } : {},
|
|
48475
|
+
...input.runtimeLogger ? { runtimeLogger: input.runtimeLogger } : {},
|
|
48207
48476
|
socketId: input.socketId,
|
|
48208
48477
|
...input.writeOutput ? { writeOutput: input.writeOutput } : {}
|
|
48209
48478
|
};
|
|
@@ -48271,6 +48540,7 @@ async function runAgentBridgeProcess(input) {
|
|
|
48271
48540
|
try {
|
|
48272
48541
|
await runAgentBridge({
|
|
48273
48542
|
...agentBridgeOptionsFromEnv(input),
|
|
48543
|
+
runtimeLogger: log,
|
|
48274
48544
|
onBootstrap: createGitCredentialRelayStarter(input.writeOutput, log)
|
|
48275
48545
|
});
|
|
48276
48546
|
} catch (error51) {
|
package/dist/index.js
CHANGED
|
@@ -15964,12 +15964,12 @@ function parseClaudeCodeStreamRecord(parsed) {
|
|
|
15964
15964
|
}
|
|
15965
15965
|
const isError = record2.is_error === true || record2.subtype === "error";
|
|
15966
15966
|
const sdkErrorMessage = record2.errors?.map((error51) => error51.trim()).filter(Boolean).join("\n");
|
|
15967
|
-
const
|
|
15967
|
+
const errorMessage4 = isError ? record2.error ?? record2.result ?? (sdkErrorMessage || void 0) ?? "claude-code reported an error" : void 0;
|
|
15968
15968
|
return {
|
|
15969
15969
|
projections: [],
|
|
15970
15970
|
result: {
|
|
15971
15971
|
isError,
|
|
15972
|
-
errorMessage:
|
|
15972
|
+
errorMessage: errorMessage4
|
|
15973
15973
|
}
|
|
15974
15974
|
};
|
|
15975
15975
|
}
|
|
@@ -21996,7 +21996,7 @@ var init_package = __esm({
|
|
|
21996
21996
|
"package.json"() {
|
|
21997
21997
|
package_default = {
|
|
21998
21998
|
name: "@autohq/cli",
|
|
21999
|
-
version: "0.1.
|
|
21999
|
+
version: "0.1.223",
|
|
22000
22000
|
license: "SEE LICENSE IN README.md",
|
|
22001
22001
|
publishConfig: {
|
|
22002
22002
|
access: "public"
|
|
@@ -27985,7 +27985,7 @@ function SessionsView({
|
|
|
27985
27985
|
visibleSessions.map((session, vi) => {
|
|
27986
27986
|
const i = scrollOffset + vi;
|
|
27987
27987
|
const title = sessionDisplayTitle(session);
|
|
27988
|
-
const err = session.status === "failed" ?
|
|
27988
|
+
const err = session.status === "failed" ? errorMessage2(session) : null;
|
|
27989
27989
|
const isSelected = i === safeIndex;
|
|
27990
27990
|
const isMarked = selectedSessionIds.has(session.id);
|
|
27991
27991
|
return /* @__PURE__ */ jsxs10(Box11, { flexDirection: "column", children: [
|
|
@@ -28123,7 +28123,7 @@ function truncateToWidth(value, width) {
|
|
|
28123
28123
|
function agentNameForRun(session) {
|
|
28124
28124
|
return session.snapshot.metadata.name;
|
|
28125
28125
|
}
|
|
28126
|
-
function
|
|
28126
|
+
function errorMessage2(session) {
|
|
28127
28127
|
if (session.error == null) return null;
|
|
28128
28128
|
if (typeof session.error === "string") return session.error;
|
|
28129
28129
|
const msg = readField(session.error, "message");
|
|
@@ -29545,7 +29545,7 @@ function HomeView({ apiUrl, notice, returnToAgent }) {
|
|
|
29545
29545
|
if (inspectedResource) {
|
|
29546
29546
|
sectionTitle = `Inspect ${inspectedResource.kind}/${inspectedResource.name}`;
|
|
29547
29547
|
}
|
|
29548
|
-
const runError =
|
|
29548
|
+
const runError = errorMessage3(triggerSession.error) ?? errorMessage3(archiveSessions.error) ?? errorMessage3(unarchiveSessions.error) ?? errorMessage3(stopSessions.error);
|
|
29549
29549
|
const isRunMutationPending = triggerSession.isPending || archiveSessions.isPending || unarchiveSessions.isPending || stopSessions.isPending;
|
|
29550
29550
|
const isConnectionMutationPending = startConnection.isPending || allowConnection.isPending || removeConnection.isPending || createGithubSyncBinding.isPending;
|
|
29551
29551
|
const serviceAccountStatus = createServiceAccount2.error instanceof Error ? createServiceAccount2.error.message : rotateServiceAccount2.error instanceof Error ? rotateServiceAccount2.error.message : removeServiceAccount2.error instanceof Error ? removeServiceAccount2.error.message : serviceAccountNotice;
|
|
@@ -29958,7 +29958,7 @@ function runActionTargetLabel(sessionIds, markedRunCount) {
|
|
|
29958
29958
|
function pluralizeRunCount(count) {
|
|
29959
29959
|
return `${count} ${count === 1 ? "session" : "sessions"}`;
|
|
29960
29960
|
}
|
|
29961
|
-
function
|
|
29961
|
+
function errorMessage3(error51) {
|
|
29962
29962
|
if (error51 instanceof Error) return error51.message;
|
|
29963
29963
|
return error51 ? String(error51) : null;
|
|
29964
29964
|
}
|
|
@@ -31779,9 +31779,10 @@ async function runAgentBridgeSocket(options) {
|
|
|
31779
31779
|
token: options.token,
|
|
31780
31780
|
onBootstrap: options.onBootstrap,
|
|
31781
31781
|
createHandler: (bootstrap) => options.createHandler({
|
|
31782
|
-
emitOutput: (output) => emitOutputWithAck(socket, output),
|
|
31782
|
+
emitOutput: (output) => emitOutputWithAck(socket, output, options.runtimeLogger),
|
|
31783
31783
|
bootstrap,
|
|
31784
31784
|
outputSeqStart: bootstrap.outputSeqStart,
|
|
31785
|
+
runtimeLogger: options.runtimeLogger,
|
|
31785
31786
|
socketId: () => socket.id,
|
|
31786
31787
|
writeOutput: options.writeOutput
|
|
31787
31788
|
}),
|
|
@@ -31819,23 +31820,55 @@ async function runAgentBridgeSocket(options) {
|
|
|
31819
31820
|
});
|
|
31820
31821
|
});
|
|
31821
31822
|
socket.on(RUNTIME_BRIDGE_COMMAND_EVENT, (rawDelivery, ack) => {
|
|
31823
|
+
const startedAt = Date.now();
|
|
31824
|
+
const logContext = runtimeCommandLogContext(rawDelivery, socket.id);
|
|
31825
|
+
options.runtimeLogger?.info("agent_bridge_command_received", logContext);
|
|
31822
31826
|
if (!handler) {
|
|
31823
31827
|
const delivery = RuntimeBridgeCommandDeliverySchema.safeParse(rawDelivery);
|
|
31824
31828
|
if (delivery.success) {
|
|
31825
|
-
|
|
31826
|
-
|
|
31827
|
-
|
|
31828
|
-
|
|
31829
|
-
|
|
31830
|
-
|
|
31831
|
-
|
|
31832
|
-
|
|
31829
|
+
const response = commandAck({
|
|
31830
|
+
delivery: delivery.data,
|
|
31831
|
+
socketId: socket.id,
|
|
31832
|
+
status: "failed",
|
|
31833
|
+
error: "Bridge command received before bootstrap completed"
|
|
31834
|
+
});
|
|
31835
|
+
options.runtimeLogger?.info("agent_bridge_command_ack_ready", {
|
|
31836
|
+
...logContext,
|
|
31837
|
+
duration_ms: Date.now() - startedAt,
|
|
31838
|
+
ack_status: response.status,
|
|
31839
|
+
error: response.error
|
|
31840
|
+
});
|
|
31841
|
+
ack(response);
|
|
31833
31842
|
return;
|
|
31834
31843
|
}
|
|
31835
|
-
|
|
31844
|
+
const error51 = "Bridge command received before bootstrap completed";
|
|
31845
|
+
options.runtimeLogger?.info("agent_bridge_command_ack_ready", {
|
|
31846
|
+
...logContext,
|
|
31847
|
+
duration_ms: Date.now() - startedAt,
|
|
31848
|
+
ack_status: "failed",
|
|
31849
|
+
error: error51
|
|
31850
|
+
});
|
|
31851
|
+
ack({ error: error51 });
|
|
31836
31852
|
return;
|
|
31837
31853
|
}
|
|
31838
|
-
void handler.handleCommand(rawDelivery).then((response) =>
|
|
31854
|
+
void handler.handleCommand(rawDelivery).then((response) => {
|
|
31855
|
+
const parsedResponse = RuntimeBridgeCommandAckSchema.safeParse(response);
|
|
31856
|
+
options.runtimeLogger?.info("agent_bridge_command_ack_ready", {
|
|
31857
|
+
...logContext,
|
|
31858
|
+
duration_ms: Date.now() - startedAt,
|
|
31859
|
+
ack_parse_status: parsedResponse.success ? "succeeded" : "failed",
|
|
31860
|
+
ack_status: parsedResponse.success ? parsedResponse.data.status : void 0,
|
|
31861
|
+
ack_socket_id: parsedResponse.success ? parsedResponse.data.socketId : void 0,
|
|
31862
|
+
error: parsedResponse.success ? parsedResponse.data.error : parsedResponse.error.message
|
|
31863
|
+
});
|
|
31864
|
+
ack(response);
|
|
31865
|
+
}).catch((error51) => {
|
|
31866
|
+
options.runtimeLogger?.warn("agent_bridge_command_handler_failed", {
|
|
31867
|
+
...logContext,
|
|
31868
|
+
duration_ms: Date.now() - startedAt,
|
|
31869
|
+
ack_status: "failed",
|
|
31870
|
+
error: errorMessage(error51)
|
|
31871
|
+
});
|
|
31839
31872
|
const delivery = RuntimeBridgeCommandDeliverySchema.safeParse(rawDelivery);
|
|
31840
31873
|
if (!delivery.success) {
|
|
31841
31874
|
ack({
|
|
@@ -31937,27 +31970,54 @@ function createSessiontimeBridgeBootstrapListener(input) {
|
|
|
31937
31970
|
}
|
|
31938
31971
|
};
|
|
31939
31972
|
}
|
|
31940
|
-
function emitOutputWithAck(socket, output) {
|
|
31973
|
+
function emitOutputWithAck(socket, output, runtimeLogger) {
|
|
31974
|
+
const startedAt = Date.now();
|
|
31975
|
+
runtimeLogger?.info(
|
|
31976
|
+
"agent_bridge_output_emit_started",
|
|
31977
|
+
outputLogContext(output, socket.id)
|
|
31978
|
+
);
|
|
31941
31979
|
return new Promise((resolve4, reject) => {
|
|
31942
31980
|
socket.timeout(5e3).emit(
|
|
31943
31981
|
RUNTIME_BRIDGE_OUTPUT_EVENT,
|
|
31944
31982
|
output,
|
|
31945
31983
|
(error51, rawAck) => {
|
|
31946
31984
|
if (error51) {
|
|
31985
|
+
runtimeLogger?.warn("agent_bridge_output_emit_ack_failed", {
|
|
31986
|
+
...outputLogContext(output, socket.id),
|
|
31987
|
+
duration_ms: Date.now() - startedAt,
|
|
31988
|
+
error: error51.message
|
|
31989
|
+
});
|
|
31947
31990
|
reject(error51);
|
|
31948
31991
|
return;
|
|
31949
31992
|
}
|
|
31950
31993
|
const ack = RuntimeBridgeOutputAckSchema.safeParse(rawAck);
|
|
31951
31994
|
if (!ack.success) {
|
|
31995
|
+
runtimeLogger?.warn("agent_bridge_output_emit_ack_invalid", {
|
|
31996
|
+
...outputLogContext(output, socket.id),
|
|
31997
|
+
duration_ms: Date.now() - startedAt,
|
|
31998
|
+
error: ack.error.message
|
|
31999
|
+
});
|
|
31952
32000
|
reject(ack.error);
|
|
31953
32001
|
return;
|
|
31954
32002
|
}
|
|
31955
32003
|
if (ack.data.status === "failed") {
|
|
32004
|
+
runtimeLogger?.warn("agent_bridge_output_emit_ack_rejected", {
|
|
32005
|
+
...outputLogContext(output, socket.id),
|
|
32006
|
+
duration_ms: Date.now() - startedAt,
|
|
32007
|
+
ack_status: ack.data.status,
|
|
32008
|
+
error: ack.data.error
|
|
32009
|
+
});
|
|
31956
32010
|
reject(
|
|
31957
32011
|
new Error(ack.data.error ?? "Bridge rejected runtime output")
|
|
31958
32012
|
);
|
|
31959
32013
|
return;
|
|
31960
32014
|
}
|
|
32015
|
+
runtimeLogger?.info("agent_bridge_output_emit_ack_ready", {
|
|
32016
|
+
...outputLogContext(output, socket.id),
|
|
32017
|
+
duration_ms: Date.now() - startedAt,
|
|
32018
|
+
ack_status: ack.data.status,
|
|
32019
|
+
cursor: ack.data.cursor
|
|
32020
|
+
});
|
|
31961
32021
|
resolve4(ack.data);
|
|
31962
32022
|
}
|
|
31963
32023
|
);
|
|
@@ -32002,6 +32062,42 @@ function isNgrokFreeUrl(url2) {
|
|
|
32002
32062
|
return false;
|
|
32003
32063
|
}
|
|
32004
32064
|
}
|
|
32065
|
+
function runtimeCommandLogContext(rawDelivery, socketId) {
|
|
32066
|
+
const delivery = RuntimeBridgeCommandDeliverySchema.safeParse(rawDelivery);
|
|
32067
|
+
if (!delivery.success) {
|
|
32068
|
+
return {
|
|
32069
|
+
socket_id: socketId,
|
|
32070
|
+
delivery_parse_status: "failed"
|
|
32071
|
+
};
|
|
32072
|
+
}
|
|
32073
|
+
return {
|
|
32074
|
+
socket_id: socketId,
|
|
32075
|
+
delivery_parse_status: "succeeded",
|
|
32076
|
+
session_id: delivery.data.sessionId,
|
|
32077
|
+
runtime_id: delivery.data.runtimeId,
|
|
32078
|
+
bridge_lease_id: delivery.data.bridgeLeaseId,
|
|
32079
|
+
delivery_id: delivery.data.deliveryId,
|
|
32080
|
+
command_id: delivery.data.commandId,
|
|
32081
|
+
command_kind: delivery.data.kind
|
|
32082
|
+
};
|
|
32083
|
+
}
|
|
32084
|
+
function outputLogContext(output, socketId) {
|
|
32085
|
+
return {
|
|
32086
|
+
socket_id: socketId,
|
|
32087
|
+
session_id: output.sessionId,
|
|
32088
|
+
runtime_id: output.runtimeId,
|
|
32089
|
+
bridge_lease_id: output.bridgeLeaseId,
|
|
32090
|
+
output_seq: output.outputSeq,
|
|
32091
|
+
output_type: output.type,
|
|
32092
|
+
role: "role" in output ? output.role : void 0,
|
|
32093
|
+
kind: "kind" in output ? output.kind : void 0,
|
|
32094
|
+
output_status: "status" in output ? output.status : void 0,
|
|
32095
|
+
message_id: "messageId" in output ? output.messageId : void 0
|
|
32096
|
+
};
|
|
32097
|
+
}
|
|
32098
|
+
function errorMessage(error51) {
|
|
32099
|
+
return error51 instanceof Error ? error51.message : String(error51);
|
|
32100
|
+
}
|
|
32005
32101
|
|
|
32006
32102
|
// src/commands/agent-bridge/harness/claude-code/index.ts
|
|
32007
32103
|
init_src();
|
|
@@ -32026,6 +32122,12 @@ var AgentBridgeOutputBuffer = class {
|
|
|
32026
32122
|
this.outputSeq,
|
|
32027
32123
|
buildOutputEnvelope(context, this.outputSeq, projection)
|
|
32028
32124
|
);
|
|
32125
|
+
this.input.runtimeLogger?.info(
|
|
32126
|
+
"agent_bridge_output_buffer_enqueued",
|
|
32127
|
+
this.outputLogContext(this.pendingOutputs.get(this.outputSeq), {
|
|
32128
|
+
pending_count: this.pendingOutputs.size
|
|
32129
|
+
})
|
|
32130
|
+
);
|
|
32029
32131
|
await this.drainPendingOutputs();
|
|
32030
32132
|
}
|
|
32031
32133
|
async replayPendingOutputs() {
|
|
@@ -32044,8 +32146,16 @@ var AgentBridgeOutputBuffer = class {
|
|
|
32044
32146
|
}
|
|
32045
32147
|
if (options.force) {
|
|
32046
32148
|
this.drainBlocked = false;
|
|
32149
|
+
this.input.runtimeLogger?.info(
|
|
32150
|
+
"agent_bridge_output_buffer_replay_started",
|
|
32151
|
+
{ pending_count: this.pendingOutputs.size }
|
|
32152
|
+
);
|
|
32047
32153
|
}
|
|
32048
32154
|
if (this.drainBlocked) {
|
|
32155
|
+
this.input.runtimeLogger?.warn(
|
|
32156
|
+
"agent_bridge_output_buffer_drain_blocked",
|
|
32157
|
+
{ pending_count: this.pendingOutputs.size }
|
|
32158
|
+
);
|
|
32049
32159
|
return;
|
|
32050
32160
|
}
|
|
32051
32161
|
this.drainPromise ??= (async () => {
|
|
@@ -32065,11 +32175,36 @@ var AgentBridgeOutputBuffer = class {
|
|
|
32065
32175
|
await this.drainPromise;
|
|
32066
32176
|
}
|
|
32067
32177
|
async emitUntilAcked(output) {
|
|
32178
|
+
const startedAt = Date.now();
|
|
32179
|
+
this.input.runtimeLogger?.info(
|
|
32180
|
+
"agent_bridge_output_buffer_emit_started",
|
|
32181
|
+
this.outputLogContext(output, {
|
|
32182
|
+
pending_count: this.pendingOutputs.size
|
|
32183
|
+
})
|
|
32184
|
+
);
|
|
32068
32185
|
const ack = await this.input.emitOutput(output);
|
|
32069
32186
|
if (isSuccessfulOutputAck(ack)) {
|
|
32070
32187
|
this.pendingOutputs.delete(output.outputSeq);
|
|
32188
|
+
this.input.runtimeLogger?.info(
|
|
32189
|
+
"agent_bridge_output_buffer_emit_ready",
|
|
32190
|
+
this.outputLogContext(output, {
|
|
32191
|
+
duration_ms: Date.now() - startedAt,
|
|
32192
|
+
ack_status: ack.status,
|
|
32193
|
+
cursor: ack.cursor,
|
|
32194
|
+
pending_count: this.pendingOutputs.size
|
|
32195
|
+
})
|
|
32196
|
+
);
|
|
32071
32197
|
return;
|
|
32072
32198
|
}
|
|
32199
|
+
this.input.runtimeLogger?.warn(
|
|
32200
|
+
"agent_bridge_output_buffer_emit_rejected",
|
|
32201
|
+
this.outputLogContext(output, {
|
|
32202
|
+
duration_ms: Date.now() - startedAt,
|
|
32203
|
+
ack_status: ack.status,
|
|
32204
|
+
error: ack.error,
|
|
32205
|
+
pending_count: this.pendingOutputs.size
|
|
32206
|
+
})
|
|
32207
|
+
);
|
|
32073
32208
|
throw new Error(ack.error ?? `Bridge rejected output: ${ack.status}`);
|
|
32074
32209
|
}
|
|
32075
32210
|
nextPendingOutput() {
|
|
@@ -32077,6 +32212,17 @@ var AgentBridgeOutputBuffer = class {
|
|
|
32077
32212
|
(left, right) => left.outputSeq - right.outputSeq
|
|
32078
32213
|
)[0] ?? null;
|
|
32079
32214
|
}
|
|
32215
|
+
outputLogContext(output, fields = {}) {
|
|
32216
|
+
return {
|
|
32217
|
+
output_seq: output?.outputSeq,
|
|
32218
|
+
output_type: output?.type,
|
|
32219
|
+
role: output && "role" in output ? output.role : void 0,
|
|
32220
|
+
kind: output && "kind" in output ? output.kind : void 0,
|
|
32221
|
+
output_status: output && "status" in output ? output.status : void 0,
|
|
32222
|
+
message_id: output && "messageId" in output ? output.messageId : void 0,
|
|
32223
|
+
...fields
|
|
32224
|
+
};
|
|
32225
|
+
}
|
|
32080
32226
|
};
|
|
32081
32227
|
function buildOutputEnvelope(context, outputSeq, projection) {
|
|
32082
32228
|
if (projection.type === "delta") {
|
|
@@ -32486,15 +32632,33 @@ var ClaudeAgentBridgeSessionImpl = class {
|
|
|
32486
32632
|
}
|
|
32487
32633
|
async sendMessage(message, options) {
|
|
32488
32634
|
const mode = options?.mode ?? "interrupt";
|
|
32635
|
+
const startedAt = Date.now();
|
|
32636
|
+
this.input.runtimeLogger?.info("agent_bridge_claude_send_message_started", {
|
|
32637
|
+
delivery_mode: mode,
|
|
32638
|
+
state: this.state.kind,
|
|
32639
|
+
active_turn_count: this.activeTurnCount,
|
|
32640
|
+
pending_tool_use_count: this.pendingToolUseIds.size,
|
|
32641
|
+
deferred_count: this.deferredMessages.length
|
|
32642
|
+
});
|
|
32489
32643
|
if (mode === "deferred" && this.hasInterruptibleTurn()) {
|
|
32490
32644
|
this.deferredMessages.push(message);
|
|
32491
|
-
this.input.
|
|
32492
|
-
|
|
32493
|
-
|
|
32645
|
+
this.input.runtimeLogger?.info("agent_bridge_claude_message_deferred", {
|
|
32646
|
+
active_turn_count: this.activeTurnCount,
|
|
32647
|
+
pending_tool_use_count: this.pendingToolUseIds.size,
|
|
32648
|
+
deferred_count: this.deferredMessages.length
|
|
32649
|
+
});
|
|
32494
32650
|
return;
|
|
32495
32651
|
}
|
|
32496
32652
|
await this.interruptActiveTurnBeforeMessage();
|
|
32497
32653
|
this.enqueueUserMessage(message);
|
|
32654
|
+
this.input.runtimeLogger?.info("agent_bridge_claude_send_message_queued", {
|
|
32655
|
+
delivery_mode: mode,
|
|
32656
|
+
duration_ms: Date.now() - startedAt,
|
|
32657
|
+
state: this.state.kind,
|
|
32658
|
+
active_turn_count: this.activeTurnCount,
|
|
32659
|
+
pending_tool_use_count: this.pendingToolUseIds.size,
|
|
32660
|
+
deferred_count: this.deferredMessages.length
|
|
32661
|
+
});
|
|
32498
32662
|
}
|
|
32499
32663
|
close() {
|
|
32500
32664
|
const previousState = this.state;
|
|
@@ -32599,6 +32763,12 @@ var ClaudeAgentBridgeSessionImpl = class {
|
|
|
32599
32763
|
this.pendingToolUseIds.clear();
|
|
32600
32764
|
this.turnResultCount += 1;
|
|
32601
32765
|
this.resolveTurnSettlement(true);
|
|
32766
|
+
this.input.runtimeLogger?.info("agent_bridge_claude_turn_result", {
|
|
32767
|
+
active_turn_count: this.activeTurnCount,
|
|
32768
|
+
pending_tool_use_count: this.pendingToolUseIds.size,
|
|
32769
|
+
turn_result_count: this.turnResultCount,
|
|
32770
|
+
deferred_count: this.deferredMessages.length
|
|
32771
|
+
});
|
|
32602
32772
|
if (this.activeTurnCount === 0) {
|
|
32603
32773
|
this.flushDeferredMessages();
|
|
32604
32774
|
}
|
|
@@ -32639,6 +32809,12 @@ var ClaudeAgentBridgeSessionImpl = class {
|
|
|
32639
32809
|
enqueueUserMessage(message) {
|
|
32640
32810
|
this.inputQueue.push(claudeAgentUserMessage(message));
|
|
32641
32811
|
this.activeTurnCount += 1;
|
|
32812
|
+
this.input.runtimeLogger?.info("agent_bridge_claude_message_enqueued", {
|
|
32813
|
+
state: this.state.kind,
|
|
32814
|
+
active_turn_count: this.activeTurnCount,
|
|
32815
|
+
pending_tool_use_count: this.pendingToolUseIds.size,
|
|
32816
|
+
deferred_count: this.deferredMessages.length
|
|
32817
|
+
});
|
|
32642
32818
|
void this.ensureRunningQuery().catch((error51) => {
|
|
32643
32819
|
void this.input.onError(error51);
|
|
32644
32820
|
});
|
|
@@ -33012,10 +33188,25 @@ var ClaudeCodeCommandHandler = class {
|
|
|
33012
33188
|
this.settlePendingQuestions("Runtime is shutting down");
|
|
33013
33189
|
}
|
|
33014
33190
|
async handleCommand(rawDelivery) {
|
|
33191
|
+
const startedAt = Date.now();
|
|
33015
33192
|
const delivery = RuntimeBridgeCommandDeliverySchema.parse(rawDelivery);
|
|
33016
33193
|
const socketId = this.input.socketId?.();
|
|
33194
|
+
this.input.runtimeLogger?.info(
|
|
33195
|
+
"agent_bridge_claude_command_started",
|
|
33196
|
+
commandLogContext(delivery, {
|
|
33197
|
+
socket_id: socketId
|
|
33198
|
+
})
|
|
33199
|
+
);
|
|
33017
33200
|
const activeContext = this.context;
|
|
33018
33201
|
if (!activeContext || delivery.sessionId !== activeContext.sessionId || delivery.runtimeId !== activeContext.runtimeId || delivery.bridgeLeaseId !== activeContext.bridgeLeaseId) {
|
|
33202
|
+
this.input.runtimeLogger?.warn(
|
|
33203
|
+
"agent_bridge_claude_command_stale",
|
|
33204
|
+
commandLogContext(delivery, {
|
|
33205
|
+
socket_id: socketId,
|
|
33206
|
+
duration_ms: Date.now() - startedAt,
|
|
33207
|
+
active_bridge_lease_id: activeContext?.bridgeLeaseId
|
|
33208
|
+
})
|
|
33209
|
+
);
|
|
33019
33210
|
return commandAck({
|
|
33020
33211
|
delivery,
|
|
33021
33212
|
socketId,
|
|
@@ -33023,6 +33214,13 @@ var ClaudeCodeCommandHandler = class {
|
|
|
33023
33214
|
});
|
|
33024
33215
|
}
|
|
33025
33216
|
if (this.injectedCommands.has(delivery.commandId)) {
|
|
33217
|
+
this.input.runtimeLogger?.info(
|
|
33218
|
+
"agent_bridge_claude_command_duplicate",
|
|
33219
|
+
commandLogContext(delivery, {
|
|
33220
|
+
socket_id: socketId,
|
|
33221
|
+
duration_ms: Date.now() - startedAt
|
|
33222
|
+
})
|
|
33223
|
+
);
|
|
33026
33224
|
return commandAck({
|
|
33027
33225
|
delivery,
|
|
33028
33226
|
socketId,
|
|
@@ -33035,6 +33233,13 @@ var ClaudeCodeCommandHandler = class {
|
|
|
33035
33233
|
if (delivery.kind === "stop") {
|
|
33036
33234
|
this.injectedCommands.add(delivery.commandId);
|
|
33037
33235
|
this.shutdown();
|
|
33236
|
+
this.input.runtimeLogger?.info(
|
|
33237
|
+
"agent_bridge_claude_command_stop_ready",
|
|
33238
|
+
commandLogContext(delivery, {
|
|
33239
|
+
socket_id: socketId,
|
|
33240
|
+
duration_ms: Date.now() - startedAt
|
|
33241
|
+
})
|
|
33242
|
+
);
|
|
33038
33243
|
return commandAck({
|
|
33039
33244
|
delivery,
|
|
33040
33245
|
socketId,
|
|
@@ -33042,6 +33247,13 @@ var ClaudeCodeCommandHandler = class {
|
|
|
33042
33247
|
});
|
|
33043
33248
|
}
|
|
33044
33249
|
if (delivery.kind !== "message") {
|
|
33250
|
+
this.input.runtimeLogger?.warn(
|
|
33251
|
+
"agent_bridge_claude_command_unsupported",
|
|
33252
|
+
commandLogContext(delivery, {
|
|
33253
|
+
socket_id: socketId,
|
|
33254
|
+
duration_ms: Date.now() - startedAt
|
|
33255
|
+
})
|
|
33256
|
+
);
|
|
33045
33257
|
return commandAck({
|
|
33046
33258
|
delivery,
|
|
33047
33259
|
socketId,
|
|
@@ -33060,6 +33272,11 @@ var ClaudeCodeCommandHandler = class {
|
|
|
33060
33272
|
}
|
|
33061
33273
|
this.injectedCommands.add(delivery.commandId);
|
|
33062
33274
|
try {
|
|
33275
|
+
const emitStartedAt = Date.now();
|
|
33276
|
+
this.input.runtimeLogger?.info(
|
|
33277
|
+
"agent_bridge_claude_command_user_entry_emit_started",
|
|
33278
|
+
commandLogContext(delivery, { socket_id: socketId })
|
|
33279
|
+
);
|
|
33063
33280
|
await this.emitBridgeOutput(activeContext, {
|
|
33064
33281
|
type: "entry",
|
|
33065
33282
|
entry: {
|
|
@@ -33072,11 +33289,43 @@ var ClaudeCodeCommandHandler = class {
|
|
|
33072
33289
|
}
|
|
33073
33290
|
}
|
|
33074
33291
|
});
|
|
33292
|
+
this.input.runtimeLogger?.info(
|
|
33293
|
+
"agent_bridge_claude_command_user_entry_emit_ready",
|
|
33294
|
+
commandLogContext(delivery, {
|
|
33295
|
+
socket_id: socketId,
|
|
33296
|
+
duration_ms: Date.now() - emitStartedAt
|
|
33297
|
+
})
|
|
33298
|
+
);
|
|
33299
|
+
const sendStartedAt = Date.now();
|
|
33300
|
+
const mode = deliveryMode(delivery);
|
|
33301
|
+
this.input.runtimeLogger?.info(
|
|
33302
|
+
"agent_bridge_claude_command_send_message_started",
|
|
33303
|
+
commandLogContext(delivery, {
|
|
33304
|
+
socket_id: socketId,
|
|
33305
|
+
delivery_mode: mode
|
|
33306
|
+
})
|
|
33307
|
+
);
|
|
33075
33308
|
await this.ensureAgentSession().sendMessage(message, {
|
|
33076
|
-
mode
|
|
33309
|
+
mode
|
|
33077
33310
|
});
|
|
33311
|
+
this.input.runtimeLogger?.info(
|
|
33312
|
+
"agent_bridge_claude_command_send_message_ready",
|
|
33313
|
+
commandLogContext(delivery, {
|
|
33314
|
+
socket_id: socketId,
|
|
33315
|
+
delivery_mode: mode,
|
|
33316
|
+
duration_ms: Date.now() - sendStartedAt
|
|
33317
|
+
})
|
|
33318
|
+
);
|
|
33078
33319
|
} catch (error51) {
|
|
33079
33320
|
this.injectedCommands.delete(delivery.commandId);
|
|
33321
|
+
this.input.runtimeLogger?.warn(
|
|
33322
|
+
"agent_bridge_claude_command_failed",
|
|
33323
|
+
commandLogContext(delivery, {
|
|
33324
|
+
socket_id: socketId,
|
|
33325
|
+
duration_ms: Date.now() - startedAt,
|
|
33326
|
+
error: error51 instanceof Error ? error51.message : String(error51)
|
|
33327
|
+
})
|
|
33328
|
+
);
|
|
33080
33329
|
return commandAck({
|
|
33081
33330
|
delivery,
|
|
33082
33331
|
socketId,
|
|
@@ -33084,6 +33333,13 @@ var ClaudeCodeCommandHandler = class {
|
|
|
33084
33333
|
error: error51 instanceof Error ? error51.message : String(error51)
|
|
33085
33334
|
});
|
|
33086
33335
|
}
|
|
33336
|
+
this.input.runtimeLogger?.info(
|
|
33337
|
+
"agent_bridge_claude_command_injected",
|
|
33338
|
+
commandLogContext(delivery, {
|
|
33339
|
+
socket_id: socketId,
|
|
33340
|
+
duration_ms: Date.now() - startedAt
|
|
33341
|
+
})
|
|
33342
|
+
);
|
|
33087
33343
|
return commandAck({
|
|
33088
33344
|
delivery,
|
|
33089
33345
|
socketId,
|
|
@@ -33298,6 +33554,7 @@ var ClaudeCodeCommandHandler = class {
|
|
|
33298
33554
|
}
|
|
33299
33555
|
this.input.writeOutput?.("agent_bridge_claude_sdk_exited");
|
|
33300
33556
|
},
|
|
33557
|
+
runtimeLogger: this.input.runtimeLogger,
|
|
33301
33558
|
writeOutput: this.input.writeOutput
|
|
33302
33559
|
});
|
|
33303
33560
|
this.agentSession = session;
|
|
@@ -33330,6 +33587,17 @@ function deliveryMode(delivery) {
|
|
|
33330
33587
|
}
|
|
33331
33588
|
return "interrupt";
|
|
33332
33589
|
}
|
|
33590
|
+
function commandLogContext(delivery, fields = {}) {
|
|
33591
|
+
return {
|
|
33592
|
+
session_id: delivery.sessionId,
|
|
33593
|
+
runtime_id: delivery.runtimeId,
|
|
33594
|
+
bridge_lease_id: delivery.bridgeLeaseId,
|
|
33595
|
+
delivery_id: delivery.deliveryId,
|
|
33596
|
+
command_id: delivery.commandId,
|
|
33597
|
+
command_kind: delivery.kind,
|
|
33598
|
+
...fields
|
|
33599
|
+
};
|
|
33600
|
+
}
|
|
33333
33601
|
|
|
33334
33602
|
// src/commands/agent-bridge/harness/index.ts
|
|
33335
33603
|
async function runAgentBridgeHarness(options) {
|
|
@@ -33343,6 +33611,7 @@ function createHarnessCommandHandler(input) {
|
|
|
33343
33611
|
const base = {
|
|
33344
33612
|
emitOutput: input.emitOutput,
|
|
33345
33613
|
...input.outputSeqStart !== void 0 ? { outputSeqStart: input.outputSeqStart } : {},
|
|
33614
|
+
...input.runtimeLogger ? { runtimeLogger: input.runtimeLogger } : {},
|
|
33346
33615
|
socketId: input.socketId,
|
|
33347
33616
|
...input.writeOutput ? { writeOutput: input.writeOutput } : {}
|
|
33348
33617
|
};
|
|
@@ -33411,6 +33680,7 @@ async function runAgentBridgeProcess(input) {
|
|
|
33411
33680
|
try {
|
|
33412
33681
|
await runAgentBridge({
|
|
33413
33682
|
...agentBridgeOptionsFromEnv(input),
|
|
33683
|
+
runtimeLogger: log,
|
|
33414
33684
|
onBootstrap: createGitCredentialRelayStarter(input.writeOutput, log)
|
|
33415
33685
|
});
|
|
33416
33686
|
} catch (error51) {
|