@autohq/cli 0.1.551 → 0.1.553

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.
@@ -30870,7 +30870,7 @@ Object.assign(lookup, {
30870
30870
  // package.json
30871
30871
  var package_default = {
30872
30872
  name: "@autohq/cli",
30873
- version: "0.1.551",
30873
+ version: "0.1.553",
30874
30874
  license: "SEE LICENSE IN README.md",
30875
30875
  publishConfig: {
30876
30876
  access: "public"
@@ -31880,6 +31880,18 @@ var AuthActorSchema = external_exports.object({
31880
31880
  principal: PrincipalSchema,
31881
31881
  client: AuthClientSchema
31882
31882
  });
31883
+ var PersistedPrincipalSchema = external_exports.preprocess(
31884
+ normalizePersistedPrincipal,
31885
+ PrincipalSchema
31886
+ );
31887
+ var PersistedAuthClientSchema = external_exports.preprocess(
31888
+ normalizePersistedAuthClient,
31889
+ AuthClientSchema
31890
+ );
31891
+ var PersistedAuthActorSchema = external_exports.object({
31892
+ principal: PersistedPrincipalSchema,
31893
+ client: PersistedAuthClientSchema
31894
+ });
31883
31895
  var AuthContextSchema = external_exports.object({
31884
31896
  actor: AuthActorSchema,
31885
31897
  organizationId: OrganizationIdSchema,
@@ -31909,6 +31921,23 @@ var AuthWhoamiResponseSchema = external_exports.object({
31909
31921
  })
31910
31922
  }).optional()
31911
31923
  });
31924
+ function normalizePersistedPrincipal(value2) {
31925
+ if (typeof value2 !== "object" || value2 === null) {
31926
+ return value2;
31927
+ }
31928
+ const principal = value2;
31929
+ if (principal.kind !== "run" || typeof principal.runId !== "string" || principal.runId.trim().length === 0) {
31930
+ return value2;
31931
+ }
31932
+ return { kind: "session", sessionId: principal.runId };
31933
+ }
31934
+ function normalizePersistedAuthClient(value2) {
31935
+ if (typeof value2 !== "object" || value2 === null) {
31936
+ return value2;
31937
+ }
31938
+ const client = value2;
31939
+ return client.kind === "run_token" ? { kind: "session_token" } : value2;
31940
+ }
31912
31941
  var SERVICE_ACCOUNT_READ_ONLY_SCOPES = [
31913
31942
  "environments:read",
31914
31943
  "tools:read",
@@ -71964,7 +71993,9 @@ var AgentBridgeOutputBuffer = class {
71964
71993
  uiDeltaFlushTimer = null;
71965
71994
  activeUiMessageAssembler = null;
71966
71995
  uiMessagePartTracker = new UiMessagePartTracker();
71996
+ discardOnFailureOutputSeqs = /* @__PURE__ */ new Set();
71967
71997
  drainBlocked = false;
71998
+ drainBlockedError = null;
71968
71999
  drainPromise = null;
71969
72000
  // Sequence of the most recent liveness beat, for the skip-while-pending
71970
72001
  // gate in emitLivenessBeat.
@@ -71975,7 +72006,7 @@ var AgentBridgeOutputBuffer = class {
71975
72006
  // ---------------------------------------------------------------------------
71976
72007
  // Public API
71977
72008
  // ---------------------------------------------------------------------------
71978
- async emitProjection(context, projection) {
72009
+ async emitProjection(context, projection, options = {}) {
71979
72010
  if (projection.type === "ui_message_chunk") {
71980
72011
  const coalescible = coalescibleUiDeltaChunk(projection);
71981
72012
  if (coalescible) {
@@ -71992,7 +72023,7 @@ var AgentBridgeOutputBuffer = class {
71992
72023
  }
71993
72024
  await this.flushPendingUiDelta();
71994
72025
  await this.flushPendingDelta();
71995
- await this.enqueueProjectionAndDrain(context, projection);
72026
+ await this.enqueueProjectionAndDrain(context, projection, options);
71996
72027
  }
71997
72028
  async replayPendingOutputs() {
71998
72029
  await this.materializePendingUiDelta();
@@ -72131,15 +72162,22 @@ var AgentBridgeOutputBuffer = class {
72131
72162
  // Transport emit
72132
72163
  // ---------------------------------------------------------------------------
72133
72164
  async drainPendingOutputs(options = {}) {
72165
+ let previousDrainFailed = false;
72134
72166
  if (this.drainPromise && options.force) {
72135
72167
  try {
72136
72168
  await this.drainPromise;
72137
72169
  } catch {
72170
+ previousDrainFailed = true;
72138
72171
  }
72139
72172
  this.drainBlocked = false;
72173
+ this.drainBlockedError = null;
72174
+ }
72175
+ if (previousDrainFailed) {
72176
+ this.discardFailureSensitiveOutputs();
72140
72177
  }
72141
72178
  if (options.force) {
72142
72179
  this.drainBlocked = false;
72180
+ this.drainBlockedError = null;
72143
72181
  this.input.runtimeLogger?.info(
72144
72182
  "agent_bridge_output_buffer_replay_started",
72145
72183
  { pending_count: this.pendingOutputs.size }
@@ -72150,6 +72188,9 @@ var AgentBridgeOutputBuffer = class {
72150
72188
  "agent_bridge_output_buffer_drain_blocked",
72151
72189
  { pending_count: this.pendingOutputs.size }
72152
72190
  );
72191
+ if (options.failIfBlocked) {
72192
+ throw outputDrainBlockedError(this.drainBlockedError);
72193
+ }
72153
72194
  return;
72154
72195
  }
72155
72196
  this.drainPromise ??= (async () => {
@@ -72167,6 +72208,7 @@ var AgentBridgeOutputBuffer = class {
72167
72208
  }
72168
72209
  })().catch((error51) => {
72169
72210
  this.drainBlocked = true;
72211
+ this.drainBlockedError = error51;
72170
72212
  throw error51;
72171
72213
  }).finally(() => {
72172
72214
  this.drainPromise = null;
@@ -72363,6 +72405,7 @@ var AgentBridgeOutputBuffer = class {
72363
72405
  const ack = await this.input.emitOutput(output);
72364
72406
  if (isSuccessfulOutputAck(ack)) {
72365
72407
  this.pendingOutputs.delete(output.outputSeq);
72408
+ this.discardOnFailureOutputSeqs.delete(output.outputSeq);
72366
72409
  this.input.runtimeLogger?.info(
72367
72410
  "agent_bridge_output_buffer_emit_ready",
72368
72411
  this.outputLogContext(output, {
@@ -72390,12 +72433,33 @@ var AgentBridgeOutputBuffer = class {
72390
72433
  (left, right) => left.outputSeq - right.outputSeq
72391
72434
  )[0] ?? null;
72392
72435
  }
72393
- async enqueueProjectionAndDrain(context, projection) {
72436
+ async enqueueProjectionAndDrain(context, projection, options = {}) {
72394
72437
  this.outputSeq += 1;
72395
- this.enqueueOutput(
72396
- buildOutputEnvelope(context, this.outputSeq, projection)
72397
- );
72398
- await this.drainPendingOutputs();
72438
+ const outputSeq = this.outputSeq;
72439
+ this.enqueueOutput(buildOutputEnvelope(context, outputSeq, projection));
72440
+ if (options.discardOnFailure) {
72441
+ this.discardOnFailureOutputSeqs.add(outputSeq);
72442
+ }
72443
+ try {
72444
+ await this.drainPendingOutputs({
72445
+ failIfBlocked: options.requireDrain
72446
+ });
72447
+ this.discardOnFailureOutputSeqs.delete(outputSeq);
72448
+ } catch (error51) {
72449
+ if (options.discardOnFailure) {
72450
+ this.pendingOutputs.delete(outputSeq);
72451
+ this.discardOnFailureOutputSeqs.delete(outputSeq);
72452
+ this.ackExhaustsBySeq.delete(outputSeq);
72453
+ }
72454
+ throw error51;
72455
+ }
72456
+ }
72457
+ discardFailureSensitiveOutputs() {
72458
+ for (const outputSeq of this.discardOnFailureOutputSeqs) {
72459
+ this.pendingOutputs.delete(outputSeq);
72460
+ this.discardOnFailureOutputSeqs.delete(outputSeq);
72461
+ this.ackExhaustsBySeq.delete(outputSeq);
72462
+ }
72399
72463
  }
72400
72464
  enqueueOutput(output) {
72401
72465
  const sanitized = isLiveOnlyRuntimeOutputEnvelope(output) ? output : sanitizeUnstorableStrings(output);
@@ -72821,6 +72885,10 @@ function buildUiMessageCompletedOutputEnvelope(input) {
72821
72885
  function isSuccessfulOutputAck(ack) {
72822
72886
  return ack.status === "persisted" || ack.status === "duplicate" || ack.status === "published";
72823
72887
  }
72888
+ function outputDrainBlockedError(cause) {
72889
+ const detail = cause instanceof Error ? `: ${cause.message}` : "";
72890
+ return new Error(`Bridge output drain is blocked${detail}`);
72891
+ }
72824
72892
  function now2() {
72825
72893
  return (/* @__PURE__ */ new Date()).toISOString();
72826
72894
  }
@@ -75178,7 +75246,7 @@ var ClaudeCodeCommandHandler = class {
75178
75246
  "agent_bridge_claude_command_user_entry_emit_started",
75179
75247
  commandLogContext(delivery, { socket_id: socketId })
75180
75248
  );
75181
- await this.emitBridgeOutput(activeContext, {
75249
+ await this.emitRequiredBridgeOutput(activeContext, {
75182
75250
  type: "entry",
75183
75251
  entry: {
75184
75252
  messageId: delivery.commandId,
@@ -75279,7 +75347,7 @@ var ClaudeCodeCommandHandler = class {
75279
75347
  return;
75280
75348
  }
75281
75349
  const message = answerFallbackMessage(answer);
75282
- await this.emitBridgeOutput(activeContext, {
75350
+ await this.emitRequiredBridgeOutput(activeContext, {
75283
75351
  type: "entry",
75284
75352
  entry: {
75285
75353
  messageId: delivery.commandId,
@@ -75359,6 +75427,24 @@ var ClaudeCodeCommandHandler = class {
75359
75427
  );
75360
75428
  }
75361
75429
  }
75430
+ async emitRequiredBridgeOutput(activeContext, projection) {
75431
+ const options = {
75432
+ discardOnFailure: true,
75433
+ requireDrain: true
75434
+ };
75435
+ try {
75436
+ await this.outputBuffer.emitProjection(
75437
+ activeContext,
75438
+ projection,
75439
+ options
75440
+ );
75441
+ } catch (error51) {
75442
+ this.input.writeOutput?.(
75443
+ `agent_bridge_output_emit_failed error=${error51 instanceof Error ? error51.message : String(error51)}`
75444
+ );
75445
+ throw error51;
75446
+ }
75447
+ }
75362
75448
  async handleAgentMessage(message, meta3) {
75363
75449
  const activeContext = this.context;
75364
75450
  if (!activeContext) {
package/dist/index.js CHANGED
@@ -15442,7 +15442,24 @@ var init_account = __esm({
15442
15442
  });
15443
15443
 
15444
15444
  // ../../packages/schemas/src/auth.ts
15445
- var AuthRoleSchema, AuthIdentityProviderSchema, AuthScopeSchema, AUTH_SCOPES, PrincipalSchema, AuthClientSchema, AuthActorSchema, AuthContextSchema, AuthWhoamiResponseSchema, SERVICE_ACCOUNT_READ_ONLY_SCOPES, SERVICE_ACCOUNT_SCOPE_PRESETS, ServiceAccountScopePresetSchema;
15445
+ function normalizePersistedPrincipal(value) {
15446
+ if (typeof value !== "object" || value === null) {
15447
+ return value;
15448
+ }
15449
+ const principal = value;
15450
+ if (principal.kind !== "run" || typeof principal.runId !== "string" || principal.runId.trim().length === 0) {
15451
+ return value;
15452
+ }
15453
+ return { kind: "session", sessionId: principal.runId };
15454
+ }
15455
+ function normalizePersistedAuthClient(value) {
15456
+ if (typeof value !== "object" || value === null) {
15457
+ return value;
15458
+ }
15459
+ const client = value;
15460
+ return client.kind === "run_token" ? { kind: "session_token" } : value;
15461
+ }
15462
+ var AuthRoleSchema, AuthIdentityProviderSchema, AuthScopeSchema, AUTH_SCOPES, PrincipalSchema, AuthClientSchema, AuthActorSchema, PersistedPrincipalSchema, PersistedAuthClientSchema, PersistedAuthActorSchema, AuthContextSchema, AuthWhoamiResponseSchema, SERVICE_ACCOUNT_READ_ONLY_SCOPES, SERVICE_ACCOUNT_SCOPE_PRESETS, ServiceAccountScopePresetSchema;
15446
15463
  var init_auth = __esm({
15447
15464
  "../../packages/schemas/src/auth.ts"() {
15448
15465
  "use strict";
@@ -15529,6 +15546,18 @@ var init_auth = __esm({
15529
15546
  principal: PrincipalSchema,
15530
15547
  client: AuthClientSchema
15531
15548
  });
15549
+ PersistedPrincipalSchema = external_exports.preprocess(
15550
+ normalizePersistedPrincipal,
15551
+ PrincipalSchema
15552
+ );
15553
+ PersistedAuthClientSchema = external_exports.preprocess(
15554
+ normalizePersistedAuthClient,
15555
+ AuthClientSchema
15556
+ );
15557
+ PersistedAuthActorSchema = external_exports.object({
15558
+ principal: PersistedPrincipalSchema,
15559
+ client: PersistedAuthClientSchema
15560
+ });
15532
15561
  AuthContextSchema = external_exports.object({
15533
15562
  actor: AuthActorSchema,
15534
15563
  organizationId: OrganizationIdSchema,
@@ -82927,7 +82956,7 @@ var init_package = __esm({
82927
82956
  "package.json"() {
82928
82957
  package_default = {
82929
82958
  name: "@autohq/cli",
82930
- version: "0.1.551",
82959
+ version: "0.1.553",
82931
82960
  license: "SEE LICENSE IN README.md",
82932
82961
  publishConfig: {
82933
82962
  access: "public"
@@ -96105,7 +96134,9 @@ var AgentBridgeOutputBuffer = class {
96105
96134
  uiDeltaFlushTimer = null;
96106
96135
  activeUiMessageAssembler = null;
96107
96136
  uiMessagePartTracker = new UiMessagePartTracker();
96137
+ discardOnFailureOutputSeqs = /* @__PURE__ */ new Set();
96108
96138
  drainBlocked = false;
96139
+ drainBlockedError = null;
96109
96140
  drainPromise = null;
96110
96141
  // Sequence of the most recent liveness beat, for the skip-while-pending
96111
96142
  // gate in emitLivenessBeat.
@@ -96116,7 +96147,7 @@ var AgentBridgeOutputBuffer = class {
96116
96147
  // ---------------------------------------------------------------------------
96117
96148
  // Public API
96118
96149
  // ---------------------------------------------------------------------------
96119
- async emitProjection(context, projection) {
96150
+ async emitProjection(context, projection, options = {}) {
96120
96151
  if (projection.type === "ui_message_chunk") {
96121
96152
  const coalescible = coalescibleUiDeltaChunk(projection);
96122
96153
  if (coalescible) {
@@ -96133,7 +96164,7 @@ var AgentBridgeOutputBuffer = class {
96133
96164
  }
96134
96165
  await this.flushPendingUiDelta();
96135
96166
  await this.flushPendingDelta();
96136
- await this.enqueueProjectionAndDrain(context, projection);
96167
+ await this.enqueueProjectionAndDrain(context, projection, options);
96137
96168
  }
96138
96169
  async replayPendingOutputs() {
96139
96170
  await this.materializePendingUiDelta();
@@ -96272,15 +96303,22 @@ var AgentBridgeOutputBuffer = class {
96272
96303
  // Transport emit
96273
96304
  // ---------------------------------------------------------------------------
96274
96305
  async drainPendingOutputs(options = {}) {
96306
+ let previousDrainFailed = false;
96275
96307
  if (this.drainPromise && options.force) {
96276
96308
  try {
96277
96309
  await this.drainPromise;
96278
96310
  } catch {
96311
+ previousDrainFailed = true;
96279
96312
  }
96280
96313
  this.drainBlocked = false;
96314
+ this.drainBlockedError = null;
96315
+ }
96316
+ if (previousDrainFailed) {
96317
+ this.discardFailureSensitiveOutputs();
96281
96318
  }
96282
96319
  if (options.force) {
96283
96320
  this.drainBlocked = false;
96321
+ this.drainBlockedError = null;
96284
96322
  this.input.runtimeLogger?.info(
96285
96323
  "agent_bridge_output_buffer_replay_started",
96286
96324
  { pending_count: this.pendingOutputs.size }
@@ -96291,6 +96329,9 @@ var AgentBridgeOutputBuffer = class {
96291
96329
  "agent_bridge_output_buffer_drain_blocked",
96292
96330
  { pending_count: this.pendingOutputs.size }
96293
96331
  );
96332
+ if (options.failIfBlocked) {
96333
+ throw outputDrainBlockedError(this.drainBlockedError);
96334
+ }
96294
96335
  return;
96295
96336
  }
96296
96337
  this.drainPromise ??= (async () => {
@@ -96308,6 +96349,7 @@ var AgentBridgeOutputBuffer = class {
96308
96349
  }
96309
96350
  })().catch((error51) => {
96310
96351
  this.drainBlocked = true;
96352
+ this.drainBlockedError = error51;
96311
96353
  throw error51;
96312
96354
  }).finally(() => {
96313
96355
  this.drainPromise = null;
@@ -96504,6 +96546,7 @@ var AgentBridgeOutputBuffer = class {
96504
96546
  const ack = await this.input.emitOutput(output);
96505
96547
  if (isSuccessfulOutputAck(ack)) {
96506
96548
  this.pendingOutputs.delete(output.outputSeq);
96549
+ this.discardOnFailureOutputSeqs.delete(output.outputSeq);
96507
96550
  this.input.runtimeLogger?.info(
96508
96551
  "agent_bridge_output_buffer_emit_ready",
96509
96552
  this.outputLogContext(output, {
@@ -96531,12 +96574,33 @@ var AgentBridgeOutputBuffer = class {
96531
96574
  (left, right) => left.outputSeq - right.outputSeq
96532
96575
  )[0] ?? null;
96533
96576
  }
96534
- async enqueueProjectionAndDrain(context, projection) {
96577
+ async enqueueProjectionAndDrain(context, projection, options = {}) {
96535
96578
  this.outputSeq += 1;
96536
- this.enqueueOutput(
96537
- buildOutputEnvelope(context, this.outputSeq, projection)
96538
- );
96539
- await this.drainPendingOutputs();
96579
+ const outputSeq = this.outputSeq;
96580
+ this.enqueueOutput(buildOutputEnvelope(context, outputSeq, projection));
96581
+ if (options.discardOnFailure) {
96582
+ this.discardOnFailureOutputSeqs.add(outputSeq);
96583
+ }
96584
+ try {
96585
+ await this.drainPendingOutputs({
96586
+ failIfBlocked: options.requireDrain
96587
+ });
96588
+ this.discardOnFailureOutputSeqs.delete(outputSeq);
96589
+ } catch (error51) {
96590
+ if (options.discardOnFailure) {
96591
+ this.pendingOutputs.delete(outputSeq);
96592
+ this.discardOnFailureOutputSeqs.delete(outputSeq);
96593
+ this.ackExhaustsBySeq.delete(outputSeq);
96594
+ }
96595
+ throw error51;
96596
+ }
96597
+ }
96598
+ discardFailureSensitiveOutputs() {
96599
+ for (const outputSeq of this.discardOnFailureOutputSeqs) {
96600
+ this.pendingOutputs.delete(outputSeq);
96601
+ this.discardOnFailureOutputSeqs.delete(outputSeq);
96602
+ this.ackExhaustsBySeq.delete(outputSeq);
96603
+ }
96540
96604
  }
96541
96605
  enqueueOutput(output) {
96542
96606
  const sanitized = isLiveOnlyRuntimeOutputEnvelope(output) ? output : sanitizeUnstorableStrings(output);
@@ -96962,6 +97026,10 @@ function buildUiMessageCompletedOutputEnvelope(input) {
96962
97026
  function isSuccessfulOutputAck(ack) {
96963
97027
  return ack.status === "persisted" || ack.status === "duplicate" || ack.status === "published";
96964
97028
  }
97029
+ function outputDrainBlockedError(cause) {
97030
+ const detail = cause instanceof Error ? `: ${cause.message}` : "";
97031
+ return new Error(`Bridge output drain is blocked${detail}`);
97032
+ }
96965
97033
  function now2() {
96966
97034
  return (/* @__PURE__ */ new Date()).toISOString();
96967
97035
  }
@@ -99326,7 +99394,7 @@ var ClaudeCodeCommandHandler = class {
99326
99394
  "agent_bridge_claude_command_user_entry_emit_started",
99327
99395
  commandLogContext(delivery, { socket_id: socketId })
99328
99396
  );
99329
- await this.emitBridgeOutput(activeContext, {
99397
+ await this.emitRequiredBridgeOutput(activeContext, {
99330
99398
  type: "entry",
99331
99399
  entry: {
99332
99400
  messageId: delivery.commandId,
@@ -99427,7 +99495,7 @@ var ClaudeCodeCommandHandler = class {
99427
99495
  return;
99428
99496
  }
99429
99497
  const message = answerFallbackMessage(answer);
99430
- await this.emitBridgeOutput(activeContext, {
99498
+ await this.emitRequiredBridgeOutput(activeContext, {
99431
99499
  type: "entry",
99432
99500
  entry: {
99433
99501
  messageId: delivery.commandId,
@@ -99507,6 +99575,24 @@ var ClaudeCodeCommandHandler = class {
99507
99575
  );
99508
99576
  }
99509
99577
  }
99578
+ async emitRequiredBridgeOutput(activeContext, projection) {
99579
+ const options = {
99580
+ discardOnFailure: true,
99581
+ requireDrain: true
99582
+ };
99583
+ try {
99584
+ await this.outputBuffer.emitProjection(
99585
+ activeContext,
99586
+ projection,
99587
+ options
99588
+ );
99589
+ } catch (error51) {
99590
+ this.input.writeOutput?.(
99591
+ `agent_bridge_output_emit_failed error=${error51 instanceof Error ? error51.message : String(error51)}`
99592
+ );
99593
+ throw error51;
99594
+ }
99595
+ }
99510
99596
  async handleAgentMessage(message, meta3) {
99511
99597
  const activeContext = this.context;
99512
99598
  if (!activeContext) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autohq/cli",
3
- "version": "0.1.551",
3
+ "version": "0.1.553",
4
4
  "license": "SEE LICENSE IN README.md",
5
5
  "publishConfig": {
6
6
  "access": "public"