@p4code/cli 0.6.52 → 0.6.54

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/bin.mjs CHANGED
@@ -263,7 +263,7 @@ const make$123 = () => {
263
263
  const layer$124 = Layer.sync(NetService, make$123);
264
264
  //#endregion
265
265
  //#region package.json
266
- var version$1 = "0.6.52";
266
+ var version$1 = "0.6.54";
267
267
  //#endregion
268
268
  //#region ../../packages/shared/src/serverInstance.ts
269
269
  /**
@@ -7950,9 +7950,18 @@ const RESET_CREDIT_IDEMPOTENCY_KEY_MAX_LENGTH = 128;
7950
7950
  * the request never produced an answer - the provider may or may not have
7951
7951
  * acted, so retrying with the same `idempotencyKey` is the safe next step.
7952
7952
  */
7953
+ /** A Codex account a usage source pools, named by the source and the source's account id. */
7954
+ const UsageLimitSourceAccountRef = Schema$1.Struct({
7955
+ sourceId: UsageLimitSourceId,
7956
+ accountId: TrimmedNonEmptyString
7957
+ });
7958
+ /** Whose reset credit: a native provider instance, or an account a usage source pools. */
7959
+ const ResetCreditTarget = Schema$1.Union([Schema$1.Struct({ instanceId: ProviderInstanceId }), Schema$1.Struct({ sourceAccount: UsageLimitSourceAccountRef })]);
7953
7960
  const ProviderResetCreditAttempt = Schema$1.Struct({
7954
7961
  idempotencyKey: TrimmedNonEmptyString,
7955
- instanceId: ProviderInstanceId,
7962
+ /** Set for a native instance's attempt; `sourceAccount` is set instead for a pooled account. */
7963
+ instanceId: Schema$1.optional(ProviderInstanceId),
7964
+ sourceAccount: Schema$1.optional(UsageLimitSourceAccountRef),
7956
7965
  /** The credit this attempt named, fixed at its first try so a retry cannot switch credits. */
7957
7966
  creditId: Schema$1.optional(TrimmedNonEmptyString),
7958
7967
  requestedAt: IsoDateTime,
@@ -7960,15 +7969,27 @@ const ProviderResetCreditAttempt = Schema$1.Struct({
7960
7969
  detail: Schema$1.optional(TrimmedNonEmptyString),
7961
7970
  completedAt: Schema$1.optional(IsoDateTime)
7962
7971
  });
7963
- const ConsumeProviderResetCreditInput = Schema$1.Struct({
7964
- instanceId: ProviderInstanceId,
7972
+ const ConsumeProviderResetCreditFields = {
7965
7973
  /** One logical attempt; resend the same key to retry it without spending twice. */
7966
7974
  idempotencyKey: TrimmedNonEmptyString.check(Schema$1.isMaxLength(RESET_CREDIT_IDEMPOTENCY_KEY_MAX_LENGTH)),
7967
- /** The credit the client was shown; omitted lets the provider pick the next one. */
7975
+ /**
7976
+ * The credit the client was shown; omitted lets the provider pick the next
7977
+ * one. Required for a pooled account, whose source may since hold another
7978
+ * login: naming the credit makes Codex refuse instead of spending its reset.
7979
+ */
7968
7980
  creditId: Schema$1.optional(TrimmedNonEmptyString)
7969
- });
7970
- var ProviderResetCreditError = class extends Schema$1.TaggedErrorClass()("ProviderResetCreditError", {
7981
+ };
7982
+ const ConsumeProviderResetCreditInput = Schema$1.Union([Schema$1.Struct({
7971
7983
  instanceId: ProviderInstanceId,
7984
+ ...ConsumeProviderResetCreditFields
7985
+ }), Schema$1.Struct({
7986
+ sourceAccount: UsageLimitSourceAccountRef,
7987
+ ...ConsumeProviderResetCreditFields,
7988
+ creditId: TrimmedNonEmptyString
7989
+ })]);
7990
+ var ProviderResetCreditError = class extends Schema$1.TaggedErrorClass()("ProviderResetCreditError", {
7991
+ instanceId: Schema$1.optionalKey(ProviderInstanceId),
7992
+ sourceAccount: Schema$1.optionalKey(UsageLimitSourceAccountRef),
7972
7993
  detail: Schema$1.String,
7973
7994
  /** True once the request reached Codex, so a reset may have been used. */
7974
7995
  consumeSent: Schema$1.optionalKey(Schema$1.Boolean),
@@ -16276,17 +16297,18 @@ const WsServerGetProviderUsageRpc = Rpc.make(WS_METHODS.serverGetProviderUsage,
16276
16297
  error: Schema$1.Union([TextGenerationError, EnvironmentAuthorizationError])
16277
16298
  });
16278
16299
  /**
16279
- * Redeem one of the account's banked reset credits. Only providers that can
16280
- * redeem natively answer; the rest fail with `ProviderResetCreditError`.
16300
+ * Redeem one of the account's banked reset credits: natively for a Codex
16301
+ * instance, or through the usage source for a pooled Codex account. Anything
16302
+ * else fails with `ProviderResetCreditError`.
16281
16303
  */
16282
16304
  const WsServerConsumeProviderResetCreditRpc = Rpc.make(WS_METHODS.serverConsumeProviderResetCredit, {
16283
16305
  payload: ConsumeProviderResetCreditInput,
16284
16306
  success: Schema$1.Struct({ attempt: ProviderResetCreditAttempt }),
16285
16307
  error: Schema$1.Union([ProviderResetCreditError, EnvironmentAuthorizationError])
16286
16308
  });
16287
- /** Redemptions started through P4 for one instance, newest first. */
16309
+ /** Redemptions started through P4 for one instance or pooled account, newest first. */
16288
16310
  const WsServerListProviderResetCreditAttemptsRpc = Rpc.make(WS_METHODS.serverListProviderResetCreditAttempts, {
16289
- payload: Schema$1.Struct({ instanceId: ProviderInstanceId }),
16311
+ payload: ResetCreditTarget,
16290
16312
  success: Schema$1.Struct({ attempts: Schema$1.Array(ProviderResetCreditAttempt) }),
16291
16313
  error: Schema$1.Union([ProviderResetCreditError, EnvironmentAuthorizationError])
16292
16314
  });
@@ -67107,7 +67129,7 @@ async function readManagementJson(config, path, body, signal) {
67107
67129
  });
67108
67130
  if (!response.ok || !response.body) {
67109
67131
  await response.body?.cancel();
67110
- throw new UsageLimitSourceError({ detail: response.status === 401 || response.status === 403 ? `The usage source rejected its management key (HTTP ${response.status}). Update the management key in Manage usage sources; a provider API key cannot replace it.` : `The usage source management request failed (HTTP ${response.status}). Check the source URL and management API availability.` });
67132
+ throw new UsageLimitSourceError({ detail: response.status === 401 || response.status === 403 ? `The usage source rejected its management key (HTTP ${response.status}). Edit the source under Usage sources to update the management key; a provider API key cannot replace it.` : `The usage source management request failed (HTTP ${response.status}). Check the source URL and management API availability.` });
67111
67133
  }
67112
67134
  const reader = response.body.getReader();
67113
67135
  const chunks = [];
@@ -70382,7 +70404,7 @@ const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(function*
70382
70404
  const baseUrl = claudeEnvironment.ANTHROPIC_BASE_URL?.trim();
70383
70405
  return yield* new TextGenerationError({
70384
70406
  operation,
70385
- detail: baseUrl && !/^https:\/\/api\.anthropic\.com\/?$/i.test(baseUrl) ? "This Claude instance uses a custom API endpoint. The CLI did not report subscription limits. For pooled accounts, open Subscription limits > Manage usage sources and configure the proxy's management URL and management key." : "Claude CLI did not return subscription limits. API-key accounts do not report subscription allowances here. If this instance should use a subscription, check its login and CLAUDE_CONFIG_DIR."
70407
+ detail: baseUrl && !/^https:\/\/api\.anthropic\.com\/?$/i.test(baseUrl) ? "This Claude instance uses a custom API endpoint. The CLI did not report subscription limits. For pooled accounts, open Subscription limits > Usage sources and configure the proxy's management URL and management key." : "Claude CLI did not return subscription limits. API-key accounts do not report subscription allowances here. If this instance should use a subscription, check its login and CLAUDE_CONFIG_DIR."
70386
70408
  });
70387
70409
  }
70388
70410
  return { report };
@@ -103713,7 +103735,21 @@ const CreditList = Schema$1.Struct({ credits: Schema$1.Array(Schema$1.Struct({
103713
103735
  reset_type: Schema$1.String,
103714
103736
  expires_at: Schema$1.String
103715
103737
  })) });
103738
+ /** Codex's answer to a consume request (openai/codex backend-client `ConsumeRateLimitResetCreditResponse`). */
103739
+ const ConsumeResponse = Schema$1.Struct({ code: Schema$1.Literals([
103740
+ "reset",
103741
+ "nothing_to_reset",
103742
+ "no_credit",
103743
+ "already_redeemed"
103744
+ ]) });
103745
+ const CONSUME_OUTCOMES = {
103746
+ reset: "reset",
103747
+ nothing_to_reset: "nothingToReset",
103748
+ no_credit: "noCredit",
103749
+ already_redeemed: "alreadyRedeemed"
103750
+ };
103716
103751
  const decodeAuthFiles = Schema$1.decodeUnknownEffect(AuthFiles);
103752
+ const decodeConsumeResponse = Schema$1.decodeUnknownEffect(Schema$1.fromJsonString(ConsumeResponse));
103717
103753
  const encodeJson$5 = Schema$1.encodeEffect(Schema$1.fromJsonString(Schema$1.Unknown));
103718
103754
  const decodeApiResponse = Schema$1.decodeUnknownEffect(ApiResponse);
103719
103755
  const decodeCreditList = Schema$1.decodeUnknownEffect(Schema$1.fromJsonString(CreditList));
@@ -103721,6 +103757,7 @@ const decodeClaudeUsage = Schema$1.decodeUnknownEffect(Schema$1.fromJsonString(C
103721
103757
  const decodeCodexUsage = Schema$1.decodeUnknownEffect(Schema$1.fromJsonString(CodexUsage));
103722
103758
  const CODEX_BASE = "https://chatgpt.com/backend-api/wham";
103723
103759
  const CREDIT_URL = `${CODEX_BASE}/rate-limit-reset-credits`;
103760
+ const CONSUME_URL = `${CREDIT_URL}/consume`;
103724
103761
  const makeCliproxyApi = Effect.gen(function* () {
103725
103762
  const management = (config, path, body) => Effect.tryPromise({
103726
103763
  try: (signal) => readManagementJson(config, path, body, signal),
@@ -103841,10 +103878,32 @@ const makeCliproxyApi = Effect.gen(function* () {
103841
103878
  })
103842
103879
  })));
103843
103880
  });
103844
- return { readAccounts: Effect.fn("CliproxyApi.readAccounts")(function* (config) {
103845
- const accounts = yield* authFiles(config).pipe(Effect.mapError((cause) => isUsageLimitSourceError$1(cause) ? cause : new UsageLimitSourceError({ detail: "The usage source returned an unsupported account list." })));
103846
- return yield* Effect.forEach(accounts.filter((account) => !account.disabled && (account.provider === "codex" || account.provider === "claude")), (account) => readAccount(config, account), { concurrency: ACCOUNT_READ_CONCURRENCY });
103847
- }) };
103881
+ return {
103882
+ readAccounts: Effect.fn("CliproxyApi.readAccounts")(function* (config) {
103883
+ const accounts = yield* authFiles(config).pipe(Effect.mapError((cause) => isUsageLimitSourceError$1(cause) ? cause : new UsageLimitSourceError({ detail: "The usage source returned an unsupported account list." })));
103884
+ return yield* Effect.forEach(accounts.filter((account) => !account.disabled && (account.provider === "codex" || account.provider === "claude")), (account) => readAccount(config, account), { concurrency: ACCOUNT_READ_CONCURRENCY });
103885
+ }),
103886
+ consumeResetCredit: Effect.fn("CliproxyApi.consumeResetCredit")(function* (config, accountId, input) {
103887
+ const notSent = (detail) => ({
103888
+ detail,
103889
+ sent: false
103890
+ });
103891
+ const account = (yield* authFiles(config).pipe(Effect.mapError((cause) => notSent(isUsageLimitSourceError$1(cause) ? cause.detail : "The usage source returned an unsupported account list.")))).find((file) => file.id === accountId && file.provider === "codex" && !file.disabled);
103892
+ if (!account) return yield* Effect.fail(notSent("The usage source no longer has this Codex account. Refresh and try again."));
103893
+ const body = yield* apiCall(config, account, CONSUME_URL, {
103894
+ redeem_request_id: input.idempotencyKey,
103895
+ credit_id: input.creditId
103896
+ }).pipe(Effect.mapError((cause) => ({
103897
+ detail: isUsageLimitSourceError$1(cause) ? cause.detail : "The usage source could not send the reset request.",
103898
+ sent: true
103899
+ })));
103900
+ const response = yield* decodeConsumeResponse(body).pipe(Effect.mapError(() => ({
103901
+ detail: "Codex answered the reset request in a form P4 does not understand.",
103902
+ sent: true
103903
+ })));
103904
+ return CONSUME_OUTCOMES[response.code];
103905
+ })
103906
+ };
103848
103907
  });
103849
103908
  //#endregion
103850
103909
  //#region src/usage/UsageLimitSources.ts
@@ -103893,9 +103952,21 @@ const makeWithReader = (api) => Effect.gen(function* () {
103893
103952
  yield* settings.streamChanges.pipe(Stream.map((value) => value.usageLimitSources), Stream.changes, Stream.switchMap(() => Stream.fromEffect(publish([]).pipe(Effect.andThen(refresh)))), Stream.runDrain, Effect.forkScoped);
103894
103953
  yield* Effect.forever(Effect.sleep(REFRESH_INTERVAL).pipe(Effect.andThen(refresh))).pipe(Effect.forkScoped);
103895
103954
  yield* refresh.pipe(Effect.forkScoped);
103955
+ const consumeResetCredit = (account, input) => Effect.gen(function* () {
103956
+ const config = (yield* settings.getSettings.pipe(Effect.mapError(() => ({
103957
+ detail: "Could not read the usage source settings.",
103958
+ sent: false
103959
+ })))).usageLimitSources[account.sourceId];
103960
+ if (!config?.enabled || !config.managementKey) return yield* Effect.fail({
103961
+ detail: "This usage source is off or has no management key.",
103962
+ sent: false
103963
+ });
103964
+ return yield* api.consumeResetCredit(config, account.accountId, input);
103965
+ });
103896
103966
  return {
103897
103967
  current: Ref.get(state),
103898
103968
  refresh,
103969
+ consumeResetCredit,
103899
103970
  streamChanges: Stream.unwrap(Effect.gen(function* () {
103900
103971
  const subscription = yield* PubSub.subscribe(changes);
103901
103972
  return Stream.concat(Stream.make(yield* Ref.get(state)), Stream.fromSubscription(subscription)).pipe(Stream.changes);
@@ -130708,10 +130779,18 @@ const make$27 = Effect.gen(function* PreviewManagerMake() {
130708
130779
  }).pipe(Effect.withSpan("PreviewManager.make"));
130709
130780
  const layer$19 = Layer.effect(PreviewManager, make$27);
130710
130781
  const isStoredOutcome = Schema$1.is(Schema$1.Union([ProviderResetCreditOutcome, Schema$1.Literal("failed")]));
130711
- function toAttempt(row) {
130782
+ /**
130783
+ * The `instance_id` column holds the target's owner key. Instance ids never
130784
+ * contain a colon, so a pooled account's `source:` key cannot collide with one,
130785
+ * and the JSON keeps any source id unambiguous.
130786
+ */
130787
+ function resetCreditOwnerKey(target) {
130788
+ return "instanceId" in target ? target.instanceId : `source:${JSON.stringify([target.sourceAccount.sourceId, target.sourceAccount.accountId])}`;
130789
+ }
130790
+ function toAttempt(row, target) {
130712
130791
  return {
130713
130792
  idempotencyKey: row.idempotency_key,
130714
- instanceId: ProviderInstanceId.make(row.instance_id),
130793
+ ...target,
130715
130794
  ...row.credit_id ? { creditId: row.credit_id } : {},
130716
130795
  requestedAt: row.requested_at,
130717
130796
  ...row.outcome !== null && isStoredOutcome(row.outcome) ? { outcome: row.outcome } : {},
@@ -130724,28 +130803,39 @@ function toAttempt(row) {
130724
130803
  * attempt already wrote. The stored row wins: its credit is the one a retry
130725
130804
  * must ask about, whatever the retry itself sent.
130726
130805
  *
130727
- * A new attempt is refused while another attempt for the same provider has no
130806
+ * A new attempt is refused while another attempt for the same target has no
130728
130807
  * answer; `blockedBy` is that attempt, which the caller must retry instead.
130729
130808
  * The partial unique index makes the refusal hold across concurrent clients.
130809
+ * `foreign` marks a key already used for another target.
130730
130810
  */
130731
130811
  const beginResetCreditAttempt = Effect.fn("ProviderResetCreditAttempts.begin")(function* (input) {
130732
130812
  const sql = yield* SqlClient.SqlClient;
130813
+ const owner = resetCreditOwnerKey(input.target);
130733
130814
  yield* sql`INSERT INTO provider_reset_credit_attempts
130734
130815
  (idempotency_key, instance_id, credit_id, requested_at)
130735
- VALUES (${input.idempotencyKey}, ${input.instanceId}, ${input.creditId ?? null},
130816
+ VALUES (${input.idempotencyKey}, ${owner}, ${input.creditId ?? null},
130736
130817
  ${input.requestedAt})
130737
130818
  ON CONFLICT DO NOTHING`;
130738
130819
  const own = yield* sql`SELECT * FROM provider_reset_credit_attempts
130739
130820
  WHERE idempotency_key = ${input.idempotencyKey}`;
130740
- if (own[0] !== void 0) return {
130741
- attempt: toAttempt(own[0]),
130742
- blockedBy: null
130743
- };
130821
+ if (own[0] !== void 0) {
130822
+ if (own[0].instance_id !== owner) return {
130823
+ attempt: null,
130824
+ blockedBy: null,
130825
+ foreign: true
130826
+ };
130827
+ return {
130828
+ attempt: toAttempt(own[0], input.target),
130829
+ blockedBy: null,
130830
+ foreign: false
130831
+ };
130832
+ }
130744
130833
  const unresolved = yield* sql`SELECT * FROM provider_reset_credit_attempts
130745
- WHERE instance_id = ${input.instanceId} AND (outcome IS NULL OR outcome = 'failed')`;
130834
+ WHERE instance_id = ${owner} AND (outcome IS NULL OR outcome = 'failed')`;
130746
130835
  return {
130747
130836
  attempt: null,
130748
- blockedBy: unresolved[0] === void 0 ? null : toAttempt(unresolved[0])
130837
+ blockedBy: unresolved[0] === void 0 ? null : toAttempt(unresolved[0], input.target),
130838
+ foreign: false
130749
130839
  };
130750
130840
  });
130751
130841
  /** Write what the provider answered, or `failed` when no answer came back. */
@@ -130757,15 +130847,15 @@ const completeResetCreditAttempt = Effect.fn("ProviderResetCreditAttempts.comple
130757
130847
  WHERE idempotency_key = ${input.idempotencyKey}
130758
130848
  AND (outcome IS NULL OR outcome = 'failed')
130759
130849
  RETURNING *`;
130760
- if (rows[0] !== void 0) return toAttempt(rows[0]);
130850
+ if (rows[0] !== void 0) return toAttempt(rows[0], input.target);
130761
130851
  return toAttempt((yield* sql`SELECT * FROM provider_reset_credit_attempts
130762
- WHERE idempotency_key = ${input.idempotencyKey}`)[0]);
130852
+ WHERE idempotency_key = ${input.idempotencyKey}`)[0], input.target);
130763
130853
  });
130764
- /** This instance's attempts, newest first. */
130765
- const listResetCreditAttempts = Effect.fn("ProviderResetCreditAttempts.list")(function* (instanceId) {
130854
+ /** This target's attempts, newest first. */
130855
+ const listResetCreditAttempts = Effect.fn("ProviderResetCreditAttempts.list")(function* (target) {
130766
130856
  return (yield* (yield* SqlClient.SqlClient)`SELECT * FROM provider_reset_credit_attempts
130767
- WHERE instance_id = ${instanceId}
130768
- ORDER BY requested_at DESC LIMIT ${20}`).map(toAttempt);
130857
+ WHERE instance_id = ${resetCreditOwnerKey(target)}
130858
+ ORDER BY requested_at DESC LIMIT ${20}`).map((row) => toAttempt(row, target));
130769
130859
  });
130770
130860
  //#endregion
130771
130861
  //#region src/workspace/WorkspaceSearchIndex.ts
@@ -134167,35 +134257,51 @@ const makeWsRpcLayer = (currentSession, previewAutomationBroker, computerUseBrok
134167
134257
  detail: "This provider does not report account usage."
134168
134258
  })), { "rpc.aggregate": "server" }),
134169
134259
  [WS_METHODS.serverConsumeProviderResetCredit]: (input) => {
134260
+ const target = "instanceId" in input ? { instanceId: input.instanceId } : { sourceAccount: input.sourceAccount };
134170
134261
  let consumeSent = false;
134171
134262
  return observeRpcEffect$1(WS_METHODS.serverConsumeProviderResetCredit, Effect.gen(function* () {
134172
134263
  const fail = (detail, cause) => new ProviderResetCreditError({
134173
- instanceId: input.instanceId,
134264
+ ...target,
134174
134265
  detail,
134175
134266
  ...consumeSent ? { consumeSent } : {},
134176
134267
  ...cause === void 0 ? {} : { cause }
134177
134268
  });
134178
134269
  const begun = yield* beginResetCreditAttempt({
134179
134270
  idempotencyKey: input.idempotencyKey,
134180
- instanceId: input.instanceId,
134271
+ target,
134181
134272
  creditId: input.creditId,
134182
134273
  requestedAt: yield* nowIso$2
134183
134274
  });
134275
+ if (begun.foreign) return yield* fail("This attempt belongs to another account.");
134184
134276
  const started = begun.attempt;
134185
134277
  if (started === null) return yield* fail(begun.blockedBy === null ? "Another reset request just finished. Check the count and try again." : "An earlier reset request has no answer from Codex yet. Retry it before starting another.");
134186
- if (started.instanceId !== input.instanceId) return yield* fail("This attempt belongs to another provider.");
134187
134278
  if (started.outcome !== void 0 && started.outcome !== "failed") return { attempt: started };
134188
- const consume = textGeneration.consumeResetCredit;
134189
- if (!consume) return yield* fail("This provider cannot redeem resets from P4.");
134279
+ const creditId = started.creditId;
134280
+ let send;
134281
+ let refresh;
134282
+ if ("instanceId" in target) {
134283
+ const consume = textGeneration.consumeResetCredit;
134284
+ if (!consume) return yield* fail("This provider cannot redeem resets from P4.");
134285
+ send = consume({
134286
+ instanceId: target.instanceId,
134287
+ idempotencyKey: input.idempotencyKey,
134288
+ creditId
134289
+ }).pipe(Effect.map((answer) => answer.outcome));
134290
+ refresh = providerRegistry.refreshInstance(target.instanceId).pipe(Effect.ignoreCause({ log: true }));
134291
+ } else {
134292
+ send = usageLimitSources.consumeResetCredit(target.sourceAccount, {
134293
+ idempotencyKey: input.idempotencyKey,
134294
+ creditId: creditId ?? ("sourceAccount" in input ? input.creditId : "")
134295
+ });
134296
+ refresh = usageLimitSources.refresh;
134297
+ }
134190
134298
  consumeSent = true;
134191
- const result = yield* consume({
134192
- instanceId: input.instanceId,
134193
- idempotencyKey: input.idempotencyKey,
134194
- creditId: started.creditId
134195
- }).pipe(Effect.result);
134299
+ const result = yield* send.pipe(Effect.result);
134196
134300
  if (Result$1.isFailure(result)) {
134301
+ if (result.failure.sent === false) consumeSent = false;
134197
134302
  const recorded = yield* completeResetCreditAttempt({
134198
134303
  idempotencyKey: input.idempotencyKey,
134304
+ target,
134199
134305
  outcome: "failed",
134200
134306
  detail: result.failure.detail,
134201
134307
  completedAt: yield* nowIso$2
@@ -134205,20 +134311,21 @@ const makeWsRpcLayer = (currentSession, previewAutomationBroker, computerUseBrok
134205
134311
  }
134206
134312
  const attempt = yield* completeResetCreditAttempt({
134207
134313
  idempotencyKey: input.idempotencyKey,
134208
- outcome: result.success.outcome,
134314
+ target,
134315
+ outcome: result.success,
134209
134316
  completedAt: yield* nowIso$2
134210
134317
  });
134211
- yield* providerRegistry.refreshInstance(input.instanceId).pipe(Effect.ignoreCause({ log: true }));
134318
+ yield* refresh;
134212
134319
  return { attempt };
134213
134320
  }).pipe(Effect.catchTag("SqlError", (cause) => Effect.fail(new ProviderResetCreditError({
134214
- instanceId: input.instanceId,
134321
+ ...target,
134215
134322
  detail: "Could not record the reset attempt.",
134216
134323
  ...consumeSent ? { consumeSent } : {},
134217
134324
  cause
134218
134325
  }))), Effect.provideService(SqlClient.SqlClient, sql)), { "rpc.aggregate": "server" });
134219
134326
  },
134220
- [WS_METHODS.serverListProviderResetCreditAttempts]: (input) => observeRpcEffect$1(WS_METHODS.serverListProviderResetCreditAttempts, listResetCreditAttempts(input.instanceId).pipe(Effect.map((attempts) => ({ attempts })), Effect.catchTag("SqlError", (cause) => Effect.fail(new ProviderResetCreditError({
134221
- instanceId: input.instanceId,
134327
+ [WS_METHODS.serverListProviderResetCreditAttempts]: (input) => observeRpcEffect$1(WS_METHODS.serverListProviderResetCreditAttempts, listResetCreditAttempts(input).pipe(Effect.map((attempts) => ({ attempts })), Effect.catchTag("SqlError", (cause) => Effect.fail(new ProviderResetCreditError({
134328
+ ...input,
134222
134329
  detail: "Could not read reset history.",
134223
134330
  cause
134224
134331
  }))), Effect.provideService(SqlClient.SqlClient, sql)), { "rpc.aggregate": "server" }),
@@ -1,4 +1,4 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{n as t,r as n,t as r}from"./compiler-runtime-CLAvuQ-D.js";import{$a as i,Ia as a,Jr as o,Ku as s,Qa as c,Tn as l,Ua as u,Ur as d,Wa as ee,Xa as te,Ya as f,Za as p,_l as m,bn as ne,cu as h,ei as g,g as _,gl as re,hl as v,kt as y,ml as ie,nu as b,pu as x,ut as S,vt as C,x as w,xt as T,yt as E,yu as D,za as O,zl as ae}from"./previewAssetResource-ejET8acj.js";import{a as k,c as oe,i as A,n as j,o as M,r as N,s as se,t as ce}from"./toggle-group-p4JN13Fg.js";import{F as P,Lr as le,M as ue,N as de,P as fe,Q as pe,Rr as me,Sr as he,Ur as ge,Vr as _e,Wr as ve,Z as ye,_r as be,b as xe,cr as Se,dr as Ce,dt as we,fi as Te,fr as Ee,ft as De,hr as Oe,ht as ke,lr as Ae,lt as je,mt as Me,or as Ne,pi as Pe,pr as Fe,pt as Ie,sr as Le,ur as Re,ut as ze,v as Be,zr as Ve}from"./index-Djq5emMe.js";import{a as He,n as Ue}from"./fileCommentAnnotations-BW7oZ8my.js";var We=m(`pilcrow`,[[`path`,{d:`M13 4v16`,key:`8vvj80`}],[`path`,{d:`M17 4v16`,key:`7dpous`}],[`path`,{d:`M19 4H9.5a4.5 4.5 0 0 0 0 9H13`,key:`sh4n9v`}]]),F=e(n(),1);function Ge({threadRef:e,filePath:t,activeCwd:n,openInEditor:r,openFileSurface:i}){if(e){if(i){i(t);return}S.getState().openFile(e,t);return}r(n?_(t,n):t)}var I=r();function Ke(e,t){let n=(0,I.c)(4),r=Oe(e,t),i;return n[0]!==r.data||n[1]!==r.error||n[2]!==r.isPending?(i={data:r.data,error:r.error,isPending:r.isPending},n[0]=r.data,n[1]=r.error,n[2]=r.isPending,n[3]=i):i=n[3],i}var L=t(),qe=[];function Je(e){return(e.endSide??e.side)===`deletions`?`deletions`:`additions`}function R(e,t,n){let r=Je(t),i=e.findIndex(e=>e.side===r&&e.lineNumber===t.end);return i<0?[...e,{side:r,lineNumber:t.end,metadata:{entries:[n]}}]:e.map((e,t)=>t===i?{...e,metadata:{entries:[...e.metadata.entries,n]}}:e)}function Ye(e){let t=(0,I.c)(50),{files:n,sectionId:r,sectionTitle:i,composerDraftTarget:a,options:s,viewerRef:c,className:l,renderHeaderPrefix:u}=e,ee=d(Qe),te=d(B),f;t[0]===a?f=t[1]:(f=e=>e.getComposerDraft(a)?.reviewComments??qe,t[0]=a,t[1]=f);let p=d(f),[m,ne]=(0,F.useState)(null),[h,_]=(0,F.useState)(null),re;t[2]===n?re=t[3]:(re=new Map(n.map(Ze)),t[2]=n,t[3]=re);let v=re,y;if(t[4]!==h||t[5]!==n||t[6]!==p||t[7]!==r){let e;t[9]!==h||t[10]!==p||t[11]!==r?(e=e=>{let{fileDiff:t,filePath:n,fileKey:i,collapsed:a}=e,o=p.filter(e=>e.sectionId===r&&e.filePath===n&&(e.fenceLanguage??`diff`)===`diff`).reduce((e,n)=>{let r=g(t,n);return r?R(e,r,{id:n.id,kind:`comment`,range:r,rangeLabel:n.rangeLabel,text:n.text}):e},[]),s=h?.fileKey===i?[...o,h.annotation]:o;return{id:i,type:`diff`,fileDiff:t,annotations:s,collapsed:a,version:ze(`${a?`1`:`0`}:${s.flatMap(z).join(`:`)}`)}},t[9]=h,t[10]=p,t[11]=r,t[12]=e):e=t[12],y=n.map(e),t[4]=h,t[5]=n,t[6]=p,t[7]=r,t[8]=y}else y=t[8];let ie=y,b;t[13]!==a||t[14]!==h?.annotation||t[15]!==te?(b=e=>{ne(null),h?.annotation.metadata.entries.some(t=>t.id===e)?_(null):te(a,e)},t[13]=a,t[14]=h?.annotation,t[15]=te,t[16]=b):b=t[16];let x=b,S;t[17]!==ee||t[18]!==a||t[19]!==h||t[20]!==v||t[21]!==r||t[22]!==i?(S=(e,t)=>{let n=h?.annotation.metadata.entries.find(t=>t.id===e),s=h?v.get(h.fileKey):void 0;if(!n||!s)return;let c=o({id:n.id,sectionId:r,sectionTitle:i,filePath:s.filePath,fileDiff:s.fileDiff,range:n.range,text:t});c&&ee(a,c),ne(null),_(null)},t[17]=ee,t[18]=a,t[19]=h,t[20]=v,t[21]=r,t[22]=i,t[23]=S):S=t[23];let C=S,w;t[24]!==v||t[25]!==r||t[26]!==i?(w=(e,t)=>{if(!e)return;let n=t.item;if(n.type!==`diff`)return;let a=v.get(n.id);if(!a)return;let s=Ue(),c=o({id:s,sectionId:r,sectionTitle:i,filePath:a.filePath,fileDiff:a.fileDiff,range:e,text:``});c&&_({fileKey:n.id,annotation:{side:Je(e),lineNumber:e.end,metadata:{entries:[{id:s,kind:`draft`,range:e,rangeLabel:c.rangeLabel,text:``}]}}})},t[24]=v,t[25]=r,t[26]=i,t[27]=w):w=t[27];let T=w,E=h!==null,D;t[28]===c?D=t[29]:(D=c?{ref:c}:{},t[28]=c,t[29]=D);let O;t[30]===l?O=t[31]:(O=l?{className:l}:{},t[30]=l,t[31]=O);let ae=!E,oe=!E,A;t[32]!==T||t[33]!==s||t[34]!==oe||t[35]!==ae?(A={...s,enableGutterUtility:ae,enableLineSelection:oe,onLineSelectionEnd:T},t[32]=T,t[33]=s,t[34]=oe,t[35]=ae,t[36]=A):A=t[36];let j;t[37]===u?j=t[38]:(j=e=>e.type===`diff`?u(e.fileDiff,e.id,e.collapsed===!0):null,t[37]=u,t[38]=j);let M;t[39]!==x||t[40]!==C?(M=e=>(0,L.jsx)(`div`,{className:`py-1`,children:e.metadata.entries.map(e=>(0,L.jsx)(He,{kind:e.kind,rangeLabel:e.rangeLabel,text:e.text,onCancel:()=>x(e.id),onComment:t=>C(e.id,t),onDelete:()=>x(e.id)},e.id))}),t[39]=x,t[40]=C,t[41]=M):M=t[41];let N;return t[42]!==ie||t[43]!==m||t[44]!==A||t[45]!==j||t[46]!==M||t[47]!==D||t[48]!==O?(N=(0,L.jsx)(k,{...D,...O,items:ie,selectedLines:m,onSelectedLinesChange:ne,options:A,renderHeaderPrefix:j,renderAnnotation:M}),t[42]=ie,t[43]=m,t[44]=A,t[45]=j,t[46]=M,t[47]=D,t[48]=O,t[49]=N):N=t[49],N}function z(e){return e.metadata.entries.map(Xe)}function Xe(e){return`${e.id}:${e.rangeLabel}:${e.text}`}function Ze(e){return[e.fileKey,e]}function B(e){return e.removeReviewComment}function Qe(e){return e.addReviewComment}function $e(e){return{diffPreview:b(e,{label:`environment-data:review:diff-preview`,tag:s.reviewGetDiffPreview,staleTimeMs:5e3})}}var et=$e(l);function V(e){return e.remoteName&&e.name.startsWith(`${e.remoteName}/`)?e.name.slice(e.remoteName.length+1):e.name}function tt(e,t){let n=new Set(t),r=e.map(e=>{let r=t.filter(t=>n.has(t)&&V(t)===e.name),i=r.find(e=>e.remoteName===`origin`)??r[0]??null;return i&&n.delete(i),{id:`local:${e.name}`,label:e.name,local:e,remote:i}}),i=t.filter(e=>n.has(e)).map(e=>({id:`remote:${e.name}`,label:e.name,local:null,remote:e}));return[...r,...i]}function nt(e,t){let n=t.trim().toLocaleLowerCase();return n.length===0?e:e.filter(e=>e.label.toLocaleLowerCase().includes(n)||e.local?.name.toLocaleLowerCase().includes(n)===!0||e.remote?.name.toLocaleLowerCase().includes(n)===!0)}var H=`__automatic_base_ref__`,rt=new Set,it=`
1
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{n as t,r as n,t as r}from"./compiler-runtime-CLAvuQ-D.js";import{$a as i,Ia as a,Jr as o,Ku as s,Qa as c,Tn as l,Ua as u,Ur as d,Wa as ee,Xa as te,Ya as f,Za as p,_l as m,bn as ne,cu as h,ei as g,g as _,gl as re,hl as v,kt as y,ml as ie,nu as b,pu as x,ut as S,vt as C,x as w,xt as T,yt as E,yu as D,za as O,zl as ae}from"./previewAssetResource-CgRbTpIo.js";import{a as k,c as oe,i as A,n as j,o as M,r as N,s as se,t as ce}from"./toggle-group-btEvGcuC.js";import{A as P,D as le,Lr as ue,O as de,Q as fe,Rr as pe,Sr as me,Ur as he,Vr as ge,Wr as _e,Z as ve,_r as ye,cr as be,dr as xe,dt as Se,fi as Ce,fr as we,ft as Te,gr as Ee,h as De,ht as Oe,k as ke,lr as Ae,lt as je,mr as Me,mt as Ne,or as Pe,p as Fe,pi as Ie,pt as Le,sr as Re,ur as ze,ut as Be,zr as Ve}from"./index-Bzq9Yppm.js";import{a as He,n as Ue}from"./fileCommentAnnotations-TYSP_6yS.js";var We=m(`pilcrow`,[[`path`,{d:`M13 4v16`,key:`8vvj80`}],[`path`,{d:`M17 4v16`,key:`7dpous`}],[`path`,{d:`M19 4H9.5a4.5 4.5 0 0 0 0 9H13`,key:`sh4n9v`}]]),F=e(n(),1);function Ge({threadRef:e,filePath:t,activeCwd:n,openInEditor:r,openFileSurface:i}){if(e){if(i){i(t);return}S.getState().openFile(e,t);return}r(n?_(t,n):t)}var I=r();function Ke(e,t){let n=(0,I.c)(4),r=Me(e,t),i;return n[0]!==r.data||n[1]!==r.error||n[2]!==r.isPending?(i={data:r.data,error:r.error,isPending:r.isPending},n[0]=r.data,n[1]=r.error,n[2]=r.isPending,n[3]=i):i=n[3],i}var L=t(),qe=[];function Je(e){return(e.endSide??e.side)===`deletions`?`deletions`:`additions`}function R(e,t,n){let r=Je(t),i=e.findIndex(e=>e.side===r&&e.lineNumber===t.end);return i<0?[...e,{side:r,lineNumber:t.end,metadata:{entries:[n]}}]:e.map((e,t)=>t===i?{...e,metadata:{entries:[...e.metadata.entries,n]}}:e)}function Ye(e){let t=(0,I.c)(50),{files:n,sectionId:r,sectionTitle:i,composerDraftTarget:a,options:s,viewerRef:c,className:l,renderHeaderPrefix:u}=e,ee=d(Qe),te=d(B),f;t[0]===a?f=t[1]:(f=e=>e.getComposerDraft(a)?.reviewComments??qe,t[0]=a,t[1]=f);let p=d(f),[m,ne]=(0,F.useState)(null),[h,_]=(0,F.useState)(null),re;t[2]===n?re=t[3]:(re=new Map(n.map(Ze)),t[2]=n,t[3]=re);let v=re,y;if(t[4]!==h||t[5]!==n||t[6]!==p||t[7]!==r){let e;t[9]!==h||t[10]!==p||t[11]!==r?(e=e=>{let{fileDiff:t,filePath:n,fileKey:i,collapsed:a}=e,o=p.filter(e=>e.sectionId===r&&e.filePath===n&&(e.fenceLanguage??`diff`)===`diff`).reduce((e,n)=>{let r=g(t,n);return r?R(e,r,{id:n.id,kind:`comment`,range:r,rangeLabel:n.rangeLabel,text:n.text}):e},[]),s=h?.fileKey===i?[...o,h.annotation]:o;return{id:i,type:`diff`,fileDiff:t,annotations:s,collapsed:a,version:Be(`${a?`1`:`0`}:${s.flatMap(z).join(`:`)}`)}},t[9]=h,t[10]=p,t[11]=r,t[12]=e):e=t[12],y=n.map(e),t[4]=h,t[5]=n,t[6]=p,t[7]=r,t[8]=y}else y=t[8];let ie=y,b;t[13]!==a||t[14]!==h?.annotation||t[15]!==te?(b=e=>{ne(null),h?.annotation.metadata.entries.some(t=>t.id===e)?_(null):te(a,e)},t[13]=a,t[14]=h?.annotation,t[15]=te,t[16]=b):b=t[16];let x=b,S;t[17]!==ee||t[18]!==a||t[19]!==h||t[20]!==v||t[21]!==r||t[22]!==i?(S=(e,t)=>{let n=h?.annotation.metadata.entries.find(t=>t.id===e),s=h?v.get(h.fileKey):void 0;if(!n||!s)return;let c=o({id:n.id,sectionId:r,sectionTitle:i,filePath:s.filePath,fileDiff:s.fileDiff,range:n.range,text:t});c&&ee(a,c),ne(null),_(null)},t[17]=ee,t[18]=a,t[19]=h,t[20]=v,t[21]=r,t[22]=i,t[23]=S):S=t[23];let C=S,w;t[24]!==v||t[25]!==r||t[26]!==i?(w=(e,t)=>{if(!e)return;let n=t.item;if(n.type!==`diff`)return;let a=v.get(n.id);if(!a)return;let s=Ue(),c=o({id:s,sectionId:r,sectionTitle:i,filePath:a.filePath,fileDiff:a.fileDiff,range:e,text:``});c&&_({fileKey:n.id,annotation:{side:Je(e),lineNumber:e.end,metadata:{entries:[{id:s,kind:`draft`,range:e,rangeLabel:c.rangeLabel,text:``}]}}})},t[24]=v,t[25]=r,t[26]=i,t[27]=w):w=t[27];let T=w,E=h!==null,D;t[28]===c?D=t[29]:(D=c?{ref:c}:{},t[28]=c,t[29]=D);let O;t[30]===l?O=t[31]:(O=l?{className:l}:{},t[30]=l,t[31]=O);let ae=!E,oe=!E,A;t[32]!==T||t[33]!==s||t[34]!==oe||t[35]!==ae?(A={...s,enableGutterUtility:ae,enableLineSelection:oe,onLineSelectionEnd:T},t[32]=T,t[33]=s,t[34]=oe,t[35]=ae,t[36]=A):A=t[36];let j;t[37]===u?j=t[38]:(j=e=>e.type===`diff`?u(e.fileDiff,e.id,e.collapsed===!0):null,t[37]=u,t[38]=j);let M;t[39]!==x||t[40]!==C?(M=e=>(0,L.jsx)(`div`,{className:`py-1`,children:e.metadata.entries.map(e=>(0,L.jsx)(He,{kind:e.kind,rangeLabel:e.rangeLabel,text:e.text,onCancel:()=>x(e.id),onComment:t=>C(e.id,t),onDelete:()=>x(e.id)},e.id))}),t[39]=x,t[40]=C,t[41]=M):M=t[41];let N;return t[42]!==ie||t[43]!==m||t[44]!==A||t[45]!==j||t[46]!==M||t[47]!==D||t[48]!==O?(N=(0,L.jsx)(k,{...D,...O,items:ie,selectedLines:m,onSelectedLinesChange:ne,options:A,renderHeaderPrefix:j,renderAnnotation:M}),t[42]=ie,t[43]=m,t[44]=A,t[45]=j,t[46]=M,t[47]=D,t[48]=O,t[49]=N):N=t[49],N}function z(e){return e.metadata.entries.map(Xe)}function Xe(e){return`${e.id}:${e.rangeLabel}:${e.text}`}function Ze(e){return[e.fileKey,e]}function B(e){return e.removeReviewComment}function Qe(e){return e.addReviewComment}function $e(e){return{diffPreview:b(e,{label:`environment-data:review:diff-preview`,tag:s.reviewGetDiffPreview,staleTimeMs:5e3})}}var et=$e(l);function V(e){return e.remoteName&&e.name.startsWith(`${e.remoteName}/`)?e.name.slice(e.remoteName.length+1):e.name}function tt(e,t){let n=new Set(t),r=e.map(e=>{let r=t.filter(t=>n.has(t)&&V(t)===e.name),i=r.find(e=>e.remoteName===`origin`)??r[0]??null;return i&&n.delete(i),{id:`local:${e.name}`,label:e.name,local:e,remote:i}}),i=t.filter(e=>n.has(e)).map(e=>({id:`remote:${e.name}`,label:e.name,local:null,remote:e}));return[...r,...i]}function nt(e,t){let n=t.trim().toLocaleLowerCase();return n.length===0?e:e.filter(e=>e.label.toLocaleLowerCase().includes(n)||e.local?.name.toLocaleLowerCase().includes(n)===!0||e.remote?.name.toLocaleLowerCase().includes(n)===!0)}var H=`__automatic_base_ref__`,rt=new Set,it=`
2
2
  [data-diffs-header],
3
3
  [data-diff],
4
4
  [data-file],
@@ -94,5 +94,5 @@ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{n as t,r as n,t as r}f
94
94
  color: color-mix(in srgb, var(--foreground) 84%, var(--primary)) !important;
95
95
  text-decoration-color: currentColor;
96
96
  }
97
- `;function U({mode:e=`inline`,composerDraftTarget:t,initialGitScope:n,threadRef:r}){let{resolvedTheme:o}=w(),s=_e(),[l]=(0,F.useState)(n),[d,m]=(0,F.useState)(`stacked`),[g,_]=(0,F.useState)(s.wordWrap),[b,S]=(0,F.useState)(s.diffIgnoreWhitespace),[k,xe]=(0,F.useState)(``),[Oe,ze]=(0,F.useState)(()=>({scopeKey:null,fileKeys:rt})),He=(0,F.useRef)(null),Ue=r.threadId,I=Ve(r),qe=I?.projectId??null,Je=me(I&&qe?{environmentId:I.environmentId,projectId:qe}:null),R=I?.worktreePath??Je?.workspaceRoot,z=ae(ne.configValueAtom(I?.environmentId??null)),Xe=be(I?.environmentId??null,z?.availableEditors??[]),Ze=y(I!=null&&R!=null?le.status({environmentId:I.environmentId,input:{cwd:R}}):null),B=P(e=>fe(e.byThreadKey,r,l===`unstaged`)),Qe=Ze.data?.isRepo??!0,{turnDiffSummaries:$e,inferredCheckpointTurnCountByTurnId:V}=de(I),U=(0,F.useMemo)(()=>[...$e].toSorted((e,t)=>{let n=e.checkpointTurnCount??V[e.turnId]??0,r=t.checkpointTurnCount??V[t.turnId]??0;return n===r?t.completedAt.localeCompare(e.completedAt):r-n}),[V,$e]);(0,F.useEffect)(()=>{B.kind===`turn`&&P.getState().reconcileTurnSelection(r,U.map(e=>e.turnId))},[B,U,r]);let W=B.kind===`turn`?B.turnId:null,G=B.kind===`unstaged`?`unstaged`:`branch`,K=B.kind===`branch`?B.baseRef:null,at=B.kind===`turn`?B.filePath:null,ot=B.kind===`turn`?B.revealRequestId:0,q=W===null?void 0:U.find(e=>e.turnId===W)??U[0],J=q&&(q.checkpointTurnCount??V[q.turnId]),st=U[0],ct=W===null?G===`unstaged`?`Working tree`:`Branch changes`:q?.turnId===st?.turnId?`Latest turn`:`Turn ${J??`?`}`,lt=q?`turn:${q.turnId}`:G,Y=`${r.environmentId}:${r.threadId}:${lt}`,ut=Oe.scopeKey===Y?Oe.fileKeys:rt,dt=q?`Turn ${J??`?`}`:G===`unstaged`?`Working tree`:`Branch changes`,ft=(0,F.useMemo)(()=>typeof J==`number`?{fromTurnCount:Math.max(0,J-1),toTurnCount:J}:null,[J]),pt=Ke({environmentId:I?.environmentId??null,threadId:Ue,fromTurnCount:ft?.fromTurnCount??null,toTurnCount:ft?.toTurnCount??null,ignoreWhitespace:b,cacheScope:q?`turn:${q.turnId}`:null},{enabled:Qe&&q!==void 0}),mt=y(W===null&&I&&R?et.diffPreview({environmentId:I.environmentId,input:{cwd:R,...K?{baseRef:K}:{},ignoreWhitespace:b}}):null),ht=W===null&&mt.error?.includes(`configured workspace root`)===!0&&z?.cwd!==void 0&&z.cwd!==R,gt=y(ht&&I&&z?et.diffPreview({environmentId:I.environmentId,input:{cwd:z.cwd,...K?{baseRef:K}:{},ignoreWhitespace:b}}):null),X=ht?gt:mt,Z=X.data?.sources.find(e=>e.kind===(G===`unstaged`?`working-tree`:`branch-range`)),_t=y(W===null&&G===`branch`&&I&&X.data?.cwd?le.listRefs({environmentId:I.environmentId,input:{cwd:X.data.cwd,includeMatchingRemoteRefs:!0,refKind:`local`,...k.trim().length>0?{query:k.trim()}:{},limit:100}}):null),vt=y(W===null&&G===`branch`&&I&&X.data?.cwd?le.listRefs({environmentId:I.environmentId,input:{cwd:X.data.cwd,includeMatchingRemoteRefs:!0,refKind:`remote`,...k.trim().length>0?{query:k.trim()}:{},limit:100}}):null),yt=tt(_t.data?.refs.filter(e=>e.name!==Z?.headRef)??[],vt.data?.refs??[]),bt=nt(yt,k),xt=e=>K&&K===e.remote?.name?K:e.local?.name??e.remote?.name??e.id,St=[H,...yt.map(xt)],Ct=[...k.trim().length===0?[H]:[],...bt.map(xt)],wt=Z?.diff,Tt=q?pt.data?.diff:wt,Et=!q&&Z?.truncated===!0,Dt=q?pt.isPending:X.isPending,Ot=q?pt.error:X.error,kt=typeof Tt==`string`&&Tt.trim().length===0,Q=(0,F.useMemo)(()=>Ie(Tt,`diff-panel:${o}`,{compactPartialHunkOffsets:W===null}),[o,Tt,W]),At=(0,F.useMemo)(()=>!Q||Q.kind!==`files`?[]:Q.files.toSorted((e,t)=>ke(e).localeCompare(ke(t),void 0,{numeric:!0,sensitivity:`base`})),[Q]),$=(0,F.useMemo)(()=>At.map(e=>{let t=je(e);return{fileDiff:e,filePath:ke(e),fileKey:t,collapsed:ut.has(t)}}),[ut,At]),jt=(0,F.useMemo)(()=>$.map(e=>e.fileKey),[$]),Mt=N(jt,ut),Nt=(0,F.useMemo)(()=>De(At),[At]);(0,F.useEffect)(()=>{if(!at)return;let e=$.find(e=>e.filePath===at);e&&He.current?.scrollTo({type:`item`,id:e.fileKey,align:`start`})},[$,at,ot]);let Pt=ue({threadRef:r,workspaceRoot:R??null}),Ft=(0,F.useCallback)(e=>{Ge({threadRef:r,filePath:e,activeCwd:R,openFileSurface:Pt,openInEditor:e=>{(async()=>{let t=await Xe(e);t._tag===`Failure`&&!h(t)&&console.warn(`Failed to open diff file in editor.`,{operation:`open-diff-file`,environmentId:r.environmentId,threadId:r.threadId,...D(x(t))})})()}})},[R,Pt,Xe,r]),It=(0,F.useCallback)(e=>{ze(t=>{let n=new Set(t.scopeKey===Y?t.fileKeys:[]);return n.has(e)?n.delete(e):n.add(e),{scopeKey:Y,fileKeys:n}})},[Y]),Lt=(0,F.useCallback)(()=>{ze(e=>{let t=e.scopeKey===Y?e.fileKeys:rt;return{scopeKey:Y,fileKeys:A(jt,t)}})},[Y,jt]),Rt=e=>{P.getState().selectTurn(r,e)},zt=e=>{P.getState().selectGitScope(r,e)},Bt=e=>{P.getState().selectBranchBaseRef(r,e)};return(0,L.jsx)(pe,{mode:e,header:(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-3 [-webkit-app-region:no-drag]`,children:[(0,L.jsxs)(O,{children:[(0,L.jsxs)(c,{className:`inline-flex h-6 max-w-full items-center gap-1 rounded-md bg-muted/70 px-2 text-xs font-medium text-foreground outline-none transition-colors hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring`,"aria-label":`Diff scope: ${ct}`,children:[(0,L.jsx)(`span`,{className:`truncate`,children:ct}),(0,L.jsx)(v,{className:`size-3.5 shrink-0 text-muted-foreground`})]}),(0,L.jsxs)(ee,{align:`start`,className:`w-60`,children:[(0,L.jsx)(u,{className:W===null&&G===`unstaged`?`bg-foreground/[0.08]`:void 0,onClick:()=>zt(`unstaged`),children:(0,L.jsx)(`span`,{children:`Working tree`})}),(0,L.jsx)(u,{className:W===null&&G===`branch`?`bg-foreground/[0.08]`:void 0,onClick:()=>zt(`branch`),children:(0,L.jsx)(`span`,{children:`Branch changes`})}),(0,L.jsx)(u,{className:W!==null&&q?.turnId===st?.turnId?`bg-foreground/[0.08]`:void 0,onClick:()=>{st&&Rt(st.turnId)},children:(0,L.jsx)(`span`,{children:`Latest turn`})}),(0,L.jsxs)(f,{children:[(0,L.jsx)(p,{children:`Turn`}),(0,L.jsx)(te,{className:`w-64`,children:U.map(e=>{let t=e.checkpointTurnCount??V[e.turnId]??`?`;return(0,L.jsxs)(u,{className:e.turnId===q?.turnId?`bg-foreground/[0.08]`:void 0,onClick:()=>Rt(e.turnId),children:[(0,L.jsxs)(`span`,{children:[`Turn `,t]}),(0,L.jsx)(`span`,{className:`ml-auto text-xs tabular-nums text-muted-foreground`,children:he(e.completedAt,s.timestampFormat)})]},e.turnId)})})]})]})]}),W===null&&G===`branch`&&Z?.baseRef&&(0,L.jsxs)(`div`,{className:`flex min-w-0 max-w-full items-center gap-2 overflow-hidden text-xs text-muted-foreground`,title:`${Z.headRef??`HEAD`} → ${Z.baseRef}`,"aria-label":`Comparing ${Z.headRef??`HEAD`} against ${Z.baseRef}`,children:[(0,L.jsx)(`span`,{className:`min-w-0 max-w-48 truncate`,children:Z.headRef??`HEAD`}),(0,L.jsx)(Pe,{className:`size-3.5 shrink-0 opacity-70`}),(0,L.jsxs)(Ne,{items:St,filteredItems:Ct,value:K??H,onOpenChange:e=>{e||xe(``)},onValueChange:e=>{e&&Bt(e===H?null:e)},children:[(0,L.jsxs)(Ee,{className:`inline-flex min-w-0 max-w-48 items-center gap-1 overflow-hidden rounded-md px-1.5 py-1 outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring`,"aria-label":`Change comparison target. Currently ${Z.baseRef}`,children:[(0,L.jsx)(`span`,{className:`min-w-0 truncate`,children:Z.baseRef}),(0,L.jsx)(v,{className:`size-3.5 shrink-0 opacity-70`})]}),(0,L.jsxs)(Ce,{align:`start`,className:`w-72 min-w-0 max-w-[calc(100vw-1rem)] overflow-hidden [&>[data-slot=combobox-popup]]:min-w-0 [&>[data-slot=combobox-popup]]:overflow-hidden`,children:[(0,L.jsx)(`div`,{className:`min-w-0 shrink-0 px-3 pt-2.5`,children:(0,L.jsxs)(`div`,{className:`relative -translate-y-px border-b border-border/70 pb-1.5 transition-colors focus-within:border-ring`,children:[(0,L.jsx)(ve,{"aria-hidden":`true`,className:`pointer-events-none absolute top-1.5 left-0 size-4 shrink-0 text-muted-foreground/55`}),(0,L.jsx)(Se,{className:`[&_input]:h-6.5 [&_input]:ps-5 [&_input]:font-sans [&_input]:leading-6.5`,inputClassName:`rounded-none bg-transparent text-sm`,placeholder:`Search refs...`,showTrigger:!1,size:`sm`,unstyled:!0,value:k,onChange:e=>xe(e.target.value)})]})}),(0,L.jsxs)(`div`,{className:`grid shrink-0 grid-cols-[1rem_minmax(0,1fr)] items-center gap-2 border-b border-border/70 ps-3 pe-6.5 pt-2 pb-1.5 font-medium text-[10px] text-muted-foreground uppercase tracking-wide`,children:[(0,L.jsx)(`span`,{"aria-hidden":`true`}),(0,L.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[minmax(0,1fr)_2rem] items-center`,children:[(0,L.jsx)(`span`,{children:`Branch`}),(0,L.jsx)(`span`,{className:`text-right`,children:`Remote`})]})]}),(0,L.jsx)(Le,{children:`No matching refs.`}),(0,L.jsxs)(Re,{className:`max-h-64 min-w-0 overflow-x-hidden`,children:[(0,L.jsx)(Ae,{className:`h-8 w-full min-w-0 grid-cols-[1rem_minmax(0,1fr)] py-0`,contentClassName:`w-full min-w-0 overflow-hidden`,value:H,children:(0,L.jsx)(`span`,{className:`block min-w-0 truncate`,children:`Automatic`})}),yt.map(e=>{let t=xt(e),n=e.local!==null&&e.remote!==null,r=e.remote?.name===t;return(0,L.jsx)(Ae,{className:`h-8 w-full min-w-0 grid-cols-[1rem_minmax(0,1fr)] py-0`,contentClassName:`w-full min-w-0 overflow-hidden`,value:t,children:(0,L.jsxs)(`div`,{className:`grid w-full min-w-0 grid-cols-[minmax(0,1fr)_2rem] items-center overflow-hidden`,children:[(0,L.jsx)(`span`,{className:`block min-w-0 truncate pe-2`,children:e.label}),n?(0,L.jsx)(`div`,{className:`flex justify-end`,onClick:e=>e.stopPropagation(),onPointerDown:e=>e.stopPropagation(),children:(0,L.jsx)(Fe,{"aria-label":`Use remote version of ${e.label}`,checked:r,className:`[--thumb-size:--spacing(3)]`,onCheckedChange:t=>{let n=t?e.remote?.name:e.local?.name;n&&Bt(n)}})}):e.remote?(0,L.jsx)(`span`,{className:`flex justify-end text-muted-foreground`,title:`Remote only`,children:(0,L.jsx)(re,{"aria-hidden":`true`,className:`size-3`})}):null]})},e.id)})]})]})]})]})]}),(0,L.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 [-webkit-app-region:no-drag]`,children:[$.length>0&&(0,L.jsx)(Be,{additions:Nt.additions,deletions:Nt.deletions,className:`mr-1 text-[11px]`,layout:`inline`}),$.length>0&&(0,L.jsxs)(C,{children:[(0,L.jsx)(T,{render:(0,L.jsx)(a,{type:`button`,size:`icon-xs`,variant:`outline`,"aria-label":Mt?`Expand all files`:`Collapse all files`,onClick:Lt}),children:Mt?(0,L.jsx)(Te,{className:`size-3`}):(0,L.jsx)(oe,{className:`size-3`})}),(0,L.jsx)(E,{side:`top`,children:Mt?`Expand all files`:`Collapse all files`})]}),(0,L.jsxs)(j,{className:`shrink-0`,variant:`outline`,size:`xs`,value:[d],onValueChange:e=>{let t=e[0];(t===`stacked`||t===`split`)&&m(t)},children:[(0,L.jsx)(ce,{"aria-label":`Stacked diff view`,value:`stacked`,children:(0,L.jsx)(M,{className:`size-3`})}),(0,L.jsx)(ce,{"aria-label":`Split diff view`,value:`split`,children:(0,L.jsx)(se,{className:`size-3`})})]}),(0,L.jsxs)(C,{children:[(0,L.jsx)(T,{render:(0,L.jsx)(ce,{"aria-label":g?`Disable diff line wrapping`:`Enable diff line wrapping`,variant:`outline`,size:`xs`,pressed:g,onPressedChange:e=>{_(!!e)}}),children:(0,L.jsx)(ge,{className:`size-3`})}),(0,L.jsx)(E,{side:`top`,children:g?`Disable line wrapping`:`Enable line wrapping`})]}),(0,L.jsxs)(C,{children:[(0,L.jsx)(T,{render:(0,L.jsx)(ce,{"aria-label":b?`Show whitespace changes`:`Hide whitespace changes`,variant:`outline`,size:`xs`,pressed:b,onPressedChange:e=>{S(!!e)}}),children:(0,L.jsx)(We,{className:`size-3`})}),(0,L.jsx)(E,{side:`top`,children:b?`Show whitespace changes`:`Hide whitespace changes`})]})]})]}),children:I?Qe?W!==null&&U.length===0?(0,L.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70`,children:`No completed turns yet.`}):(0,L.jsx)(L.Fragment,{children:(0,L.jsxs)(`div`,{className:`diff-panel-viewport flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[Et&&(0,L.jsx)(`p`,{className:`shrink-0 border-b border-border/70 bg-muted/40 px-3 py-1.5 text-[11px] text-muted-foreground`,children:`This diff was truncated because it exceeded the preview limit. The changes shown are incomplete.`}),Ot&&!Q&&(0,L.jsx)(`div`,{className:`px-3`,children:(0,L.jsx)(`p`,{className:`mb-2 text-[11px] text-red-500/80`,children:Ot})}),Q?Q.kind===`files`?(0,L.jsx)(`div`,{className:`min-h-0 flex-1`,onClickCapture:e=>{let t=(e.nativeEvent.composedPath?.()??[]).find(e=>e instanceof HTMLElement&&e.hasAttribute(`data-title`))?.textContent?.trim();t&&Ft(t)},children:(0,L.jsx)(Ye,{viewerRef:He,className:`diff-render-surface h-full min-h-0 overflow-auto`,files:$,sectionId:lt,sectionTitle:dt,composerDraftTarget:t,renderHeaderPrefix:(e,t,n)=>{let r=ke(e);return(0,L.jsxs)(C,{children:[(0,L.jsx)(T,{render:(0,L.jsx)(`button`,{type:`button`,className:i(`inline-flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-sm border-0 bg-transparent p-0 transition-colors hover:bg-foreground/10 focus-visible:outline-hidden`,we(e)),"aria-label":n?`Expand ${r}`:`Collapse ${r}`,"aria-expanded":!n,onClick:e=>{e.stopPropagation(),It(t)}}),children:n?(0,L.jsx)(ie,{className:`size-4`}):(0,L.jsx)(v,{className:`size-4`})}),(0,L.jsx)(E,{side:`top`,children:n?`Expand diff`:`Collapse diff`})]})},options:{diffStyle:d===`split`?`split`:`unified`,lineDiffType:`none`,overflow:g?`wrap`:`scroll`,theme:Me(o),themeType:o,unsafeCSS:it,stickyHeaders:!0,itemMetrics:{diffHeaderHeight:33},layout:{paddingTop:0,paddingBottom:8,gap:8}}},Y??lt)}):(0,L.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-2`,children:(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(`p`,{className:`text-[11px] text-muted-foreground/75`,children:Q.reason}),(0,L.jsx)(`pre`,{className:i(`max-h-[72vh] rounded-md border border-border/70 bg-background/70 p-3 font-mono text-[11px] leading-relaxed text-muted-foreground/90`,g?`overflow-auto whitespace-pre-wrap wrap-break-word`:`overflow-auto`),children:Q.text})]})}):Dt?(0,L.jsx)(ye,{label:q?`Loading checkpoint diff...`:G===`unstaged`?`Loading working tree diff...`:`Loading branch diff...`}):(0,L.jsx)(`div`,{className:`flex h-full items-center justify-center px-3 py-2 text-xs text-muted-foreground/70`,children:(0,L.jsx)(`p`,{children:kt?`No net changes in this selection.`:`No patch available for this selection.`})})]})}):(0,L.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70`,children:`Turn diffs are unavailable because this project is not a git repository.`}):(0,L.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70`,children:`Select a thread to inspect turn diffs.`})})}export{xe as DiffWorkerPoolProvider,U as default};
98
- //# sourceMappingURL=DiffPanel-CF9-LM5-.js.map
97
+ `;function U({mode:e=`inline`,composerDraftTarget:t,initialGitScope:n,threadRef:r}){let{resolvedTheme:o}=w(),s=ge(),[l]=(0,F.useState)(n),[d,m]=(0,F.useState)(`stacked`),[g,_]=(0,F.useState)(s.wordWrap),[b,S]=(0,F.useState)(s.diffIgnoreWhitespace),[k,De]=(0,F.useState)(``),[Me,Be]=(0,F.useState)(()=>({scopeKey:null,fileKeys:rt})),He=(0,F.useRef)(null),Ue=r.threadId,I=Ve(r),qe=I?.projectId??null,Je=pe(I&&qe?{environmentId:I.environmentId,projectId:qe}:null),R=I?.worktreePath??Je?.workspaceRoot,z=ae(ne.configValueAtom(I?.environmentId??null)),Xe=Ee(I?.environmentId??null,z?.availableEditors??[]),Ze=y(I!=null&&R!=null?ue.status({environmentId:I.environmentId,input:{cwd:R}}):null),B=P(e=>ke(e.byThreadKey,r,l===`unstaged`)),Qe=Ze.data?.isRepo??!0,{turnDiffSummaries:$e,inferredCheckpointTurnCountByTurnId:V}=de(I),U=(0,F.useMemo)(()=>[...$e].toSorted((e,t)=>{let n=e.checkpointTurnCount??V[e.turnId]??0,r=t.checkpointTurnCount??V[t.turnId]??0;return n===r?t.completedAt.localeCompare(e.completedAt):r-n}),[V,$e]);(0,F.useEffect)(()=>{B.kind===`turn`&&P.getState().reconcileTurnSelection(r,U.map(e=>e.turnId))},[B,U,r]);let W=B.kind===`turn`?B.turnId:null,G=B.kind===`unstaged`?`unstaged`:`branch`,K=B.kind===`branch`?B.baseRef:null,at=B.kind===`turn`?B.filePath:null,ot=B.kind===`turn`?B.revealRequestId:0,q=W===null?void 0:U.find(e=>e.turnId===W)??U[0],J=q&&(q.checkpointTurnCount??V[q.turnId]),st=U[0],ct=W===null?G===`unstaged`?`Working tree`:`Branch changes`:q?.turnId===st?.turnId?`Latest turn`:`Turn ${J??`?`}`,lt=q?`turn:${q.turnId}`:G,Y=`${r.environmentId}:${r.threadId}:${lt}`,ut=Me.scopeKey===Y?Me.fileKeys:rt,dt=q?`Turn ${J??`?`}`:G===`unstaged`?`Working tree`:`Branch changes`,ft=(0,F.useMemo)(()=>typeof J==`number`?{fromTurnCount:Math.max(0,J-1),toTurnCount:J}:null,[J]),pt=Ke({environmentId:I?.environmentId??null,threadId:Ue,fromTurnCount:ft?.fromTurnCount??null,toTurnCount:ft?.toTurnCount??null,ignoreWhitespace:b,cacheScope:q?`turn:${q.turnId}`:null},{enabled:Qe&&q!==void 0}),mt=y(W===null&&I&&R?et.diffPreview({environmentId:I.environmentId,input:{cwd:R,...K?{baseRef:K}:{},ignoreWhitespace:b}}):null),ht=W===null&&mt.error?.includes(`configured workspace root`)===!0&&z?.cwd!==void 0&&z.cwd!==R,gt=y(ht&&I&&z?et.diffPreview({environmentId:I.environmentId,input:{cwd:z.cwd,...K?{baseRef:K}:{},ignoreWhitespace:b}}):null),X=ht?gt:mt,Z=X.data?.sources.find(e=>e.kind===(G===`unstaged`?`working-tree`:`branch-range`)),_t=y(W===null&&G===`branch`&&I&&X.data?.cwd?ue.listRefs({environmentId:I.environmentId,input:{cwd:X.data.cwd,includeMatchingRemoteRefs:!0,refKind:`local`,...k.trim().length>0?{query:k.trim()}:{},limit:100}}):null),vt=y(W===null&&G===`branch`&&I&&X.data?.cwd?ue.listRefs({environmentId:I.environmentId,input:{cwd:X.data.cwd,includeMatchingRemoteRefs:!0,refKind:`remote`,...k.trim().length>0?{query:k.trim()}:{},limit:100}}):null),yt=tt(_t.data?.refs.filter(e=>e.name!==Z?.headRef)??[],vt.data?.refs??[]),bt=nt(yt,k),xt=e=>K&&K===e.remote?.name?K:e.local?.name??e.remote?.name??e.id,St=[H,...yt.map(xt)],Ct=[...k.trim().length===0?[H]:[],...bt.map(xt)],wt=Z?.diff,Tt=q?pt.data?.diff:wt,Et=!q&&Z?.truncated===!0,Dt=q?pt.isPending:X.isPending,Ot=q?pt.error:X.error,kt=typeof Tt==`string`&&Tt.trim().length===0,Q=(0,F.useMemo)(()=>Le(Tt,`diff-panel:${o}`,{compactPartialHunkOffsets:W===null}),[o,Tt,W]),At=(0,F.useMemo)(()=>!Q||Q.kind!==`files`?[]:Q.files.toSorted((e,t)=>Oe(e).localeCompare(Oe(t),void 0,{numeric:!0,sensitivity:`base`})),[Q]),$=(0,F.useMemo)(()=>At.map(e=>{let t=je(e);return{fileDiff:e,filePath:Oe(e),fileKey:t,collapsed:ut.has(t)}}),[ut,At]),jt=(0,F.useMemo)(()=>$.map(e=>e.fileKey),[$]),Mt=N(jt,ut),Nt=(0,F.useMemo)(()=>Te(At),[At]);(0,F.useEffect)(()=>{if(!at)return;let e=$.find(e=>e.filePath===at);e&&He.current?.scrollTo({type:`item`,id:e.fileKey,align:`start`})},[$,at,ot]);let Pt=le({threadRef:r,workspaceRoot:R??null}),Ft=(0,F.useCallback)(e=>{Ge({threadRef:r,filePath:e,activeCwd:R,openFileSurface:Pt,openInEditor:e=>{(async()=>{let t=await Xe(e);t._tag===`Failure`&&!h(t)&&console.warn(`Failed to open diff file in editor.`,{operation:`open-diff-file`,environmentId:r.environmentId,threadId:r.threadId,...D(x(t))})})()}})},[R,Pt,Xe,r]),It=(0,F.useCallback)(e=>{Be(t=>{let n=new Set(t.scopeKey===Y?t.fileKeys:[]);return n.has(e)?n.delete(e):n.add(e),{scopeKey:Y,fileKeys:n}})},[Y]),Lt=(0,F.useCallback)(()=>{Be(e=>{let t=e.scopeKey===Y?e.fileKeys:rt;return{scopeKey:Y,fileKeys:A(jt,t)}})},[Y,jt]),Rt=e=>{P.getState().selectTurn(r,e)},zt=e=>{P.getState().selectGitScope(r,e)},Bt=e=>{P.getState().selectBranchBaseRef(r,e)};return(0,L.jsx)(fe,{mode:e,header:(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-3 [-webkit-app-region:no-drag]`,children:[(0,L.jsxs)(O,{children:[(0,L.jsxs)(c,{className:`inline-flex h-6 max-w-full items-center gap-1 rounded-md bg-muted/70 px-2 text-xs font-medium text-foreground outline-none transition-colors hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring`,"aria-label":`Diff scope: ${ct}`,children:[(0,L.jsx)(`span`,{className:`truncate`,children:ct}),(0,L.jsx)(v,{className:`size-3.5 shrink-0 text-muted-foreground`})]}),(0,L.jsxs)(ee,{align:`start`,className:`w-60`,children:[(0,L.jsx)(u,{className:W===null&&G===`unstaged`?`bg-foreground/[0.08]`:void 0,onClick:()=>zt(`unstaged`),children:(0,L.jsx)(`span`,{children:`Working tree`})}),(0,L.jsx)(u,{className:W===null&&G===`branch`?`bg-foreground/[0.08]`:void 0,onClick:()=>zt(`branch`),children:(0,L.jsx)(`span`,{children:`Branch changes`})}),(0,L.jsx)(u,{className:W!==null&&q?.turnId===st?.turnId?`bg-foreground/[0.08]`:void 0,onClick:()=>{st&&Rt(st.turnId)},children:(0,L.jsx)(`span`,{children:`Latest turn`})}),(0,L.jsxs)(f,{children:[(0,L.jsx)(p,{children:`Turn`}),(0,L.jsx)(te,{className:`w-64`,children:U.map(e=>{let t=e.checkpointTurnCount??V[e.turnId]??`?`;return(0,L.jsxs)(u,{className:e.turnId===q?.turnId?`bg-foreground/[0.08]`:void 0,onClick:()=>Rt(e.turnId),children:[(0,L.jsxs)(`span`,{children:[`Turn `,t]}),(0,L.jsx)(`span`,{className:`ml-auto text-xs tabular-nums text-muted-foreground`,children:me(e.completedAt,s.timestampFormat)})]},e.turnId)})})]})]})]}),W===null&&G===`branch`&&Z?.baseRef&&(0,L.jsxs)(`div`,{className:`flex min-w-0 max-w-full items-center gap-2 overflow-hidden text-xs text-muted-foreground`,title:`${Z.headRef??`HEAD`} → ${Z.baseRef}`,"aria-label":`Comparing ${Z.headRef??`HEAD`} against ${Z.baseRef}`,children:[(0,L.jsx)(`span`,{className:`min-w-0 max-w-48 truncate`,children:Z.headRef??`HEAD`}),(0,L.jsx)(Ie,{className:`size-3.5 shrink-0 opacity-70`}),(0,L.jsxs)(Pe,{items:St,filteredItems:Ct,value:K??H,onOpenChange:e=>{e||De(``)},onValueChange:e=>{e&&Bt(e===H?null:e)},children:[(0,L.jsxs)(we,{className:`inline-flex min-w-0 max-w-48 items-center gap-1 overflow-hidden rounded-md px-1.5 py-1 outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring`,"aria-label":`Change comparison target. Currently ${Z.baseRef}`,children:[(0,L.jsx)(`span`,{className:`min-w-0 truncate`,children:Z.baseRef}),(0,L.jsx)(v,{className:`size-3.5 shrink-0 opacity-70`})]}),(0,L.jsxs)(xe,{align:`start`,className:`w-72 min-w-0 max-w-[calc(100vw-1rem)] overflow-hidden [&>[data-slot=combobox-popup]]:min-w-0 [&>[data-slot=combobox-popup]]:overflow-hidden`,children:[(0,L.jsx)(`div`,{className:`min-w-0 shrink-0 px-3 pt-2.5`,children:(0,L.jsxs)(`div`,{className:`relative -translate-y-px border-b border-border/70 pb-1.5 transition-colors focus-within:border-ring`,children:[(0,L.jsx)(_e,{"aria-hidden":`true`,className:`pointer-events-none absolute top-1.5 left-0 size-4 shrink-0 text-muted-foreground/55`}),(0,L.jsx)(be,{className:`[&_input]:h-6.5 [&_input]:ps-5 [&_input]:font-sans [&_input]:leading-6.5`,inputClassName:`rounded-none bg-transparent text-sm`,placeholder:`Search refs...`,showTrigger:!1,size:`sm`,unstyled:!0,value:k,onChange:e=>De(e.target.value)})]})}),(0,L.jsxs)(`div`,{className:`grid shrink-0 grid-cols-[1rem_minmax(0,1fr)] items-center gap-2 border-b border-border/70 ps-3 pe-6.5 pt-2 pb-1.5 font-medium text-[10px] text-muted-foreground uppercase tracking-wide`,children:[(0,L.jsx)(`span`,{"aria-hidden":`true`}),(0,L.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[minmax(0,1fr)_2rem] items-center`,children:[(0,L.jsx)(`span`,{children:`Branch`}),(0,L.jsx)(`span`,{className:`text-right`,children:`Remote`})]})]}),(0,L.jsx)(Re,{children:`No matching refs.`}),(0,L.jsxs)(ze,{className:`max-h-64 min-w-0 overflow-x-hidden`,children:[(0,L.jsx)(Ae,{className:`h-8 w-full min-w-0 grid-cols-[1rem_minmax(0,1fr)] py-0`,contentClassName:`w-full min-w-0 overflow-hidden`,value:H,children:(0,L.jsx)(`span`,{className:`block min-w-0 truncate`,children:`Automatic`})}),yt.map(e=>{let t=xt(e),n=e.local!==null&&e.remote!==null,r=e.remote?.name===t;return(0,L.jsx)(Ae,{className:`h-8 w-full min-w-0 grid-cols-[1rem_minmax(0,1fr)] py-0`,contentClassName:`w-full min-w-0 overflow-hidden`,value:t,children:(0,L.jsxs)(`div`,{className:`grid w-full min-w-0 grid-cols-[minmax(0,1fr)_2rem] items-center overflow-hidden`,children:[(0,L.jsx)(`span`,{className:`block min-w-0 truncate pe-2`,children:e.label}),n?(0,L.jsx)(`div`,{className:`flex justify-end`,onClick:e=>e.stopPropagation(),onPointerDown:e=>e.stopPropagation(),children:(0,L.jsx)(ye,{"aria-label":`Use remote version of ${e.label}`,checked:r,className:`[--thumb-size:--spacing(3)]`,onCheckedChange:t=>{let n=t?e.remote?.name:e.local?.name;n&&Bt(n)}})}):e.remote?(0,L.jsx)(`span`,{className:`flex justify-end text-muted-foreground`,title:`Remote only`,children:(0,L.jsx)(re,{"aria-hidden":`true`,className:`size-3`})}):null]})},e.id)})]})]})]})]})]}),(0,L.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 [-webkit-app-region:no-drag]`,children:[$.length>0&&(0,L.jsx)(Fe,{additions:Nt.additions,deletions:Nt.deletions,className:`mr-1 text-[11px]`,layout:`inline`}),$.length>0&&(0,L.jsxs)(C,{children:[(0,L.jsx)(T,{render:(0,L.jsx)(a,{type:`button`,size:`icon-xs`,variant:`outline`,"aria-label":Mt?`Expand all files`:`Collapse all files`,onClick:Lt}),children:Mt?(0,L.jsx)(Ce,{className:`size-3`}):(0,L.jsx)(oe,{className:`size-3`})}),(0,L.jsx)(E,{side:`top`,children:Mt?`Expand all files`:`Collapse all files`})]}),(0,L.jsxs)(j,{className:`shrink-0`,variant:`outline`,size:`xs`,value:[d],onValueChange:e=>{let t=e[0];(t===`stacked`||t===`split`)&&m(t)},children:[(0,L.jsx)(ce,{"aria-label":`Stacked diff view`,value:`stacked`,children:(0,L.jsx)(M,{className:`size-3`})}),(0,L.jsx)(ce,{"aria-label":`Split diff view`,value:`split`,children:(0,L.jsx)(se,{className:`size-3`})})]}),(0,L.jsxs)(C,{children:[(0,L.jsx)(T,{render:(0,L.jsx)(ce,{"aria-label":g?`Disable diff line wrapping`:`Enable diff line wrapping`,variant:`outline`,size:`xs`,pressed:g,onPressedChange:e=>{_(!!e)}}),children:(0,L.jsx)(he,{className:`size-3`})}),(0,L.jsx)(E,{side:`top`,children:g?`Disable line wrapping`:`Enable line wrapping`})]}),(0,L.jsxs)(C,{children:[(0,L.jsx)(T,{render:(0,L.jsx)(ce,{"aria-label":b?`Show whitespace changes`:`Hide whitespace changes`,variant:`outline`,size:`xs`,pressed:b,onPressedChange:e=>{S(!!e)}}),children:(0,L.jsx)(We,{className:`size-3`})}),(0,L.jsx)(E,{side:`top`,children:b?`Show whitespace changes`:`Hide whitespace changes`})]})]})]}),children:I?Qe?W!==null&&U.length===0?(0,L.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70`,children:`No completed turns yet.`}):(0,L.jsx)(L.Fragment,{children:(0,L.jsxs)(`div`,{className:`diff-panel-viewport flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[Et&&(0,L.jsx)(`p`,{className:`shrink-0 border-b border-border/70 bg-muted/40 px-3 py-1.5 text-[11px] text-muted-foreground`,children:`This diff was truncated because it exceeded the preview limit. The changes shown are incomplete.`}),Ot&&!Q&&(0,L.jsx)(`div`,{className:`px-3`,children:(0,L.jsx)(`p`,{className:`mb-2 text-[11px] text-red-500/80`,children:Ot})}),Q?Q.kind===`files`?(0,L.jsx)(`div`,{className:`min-h-0 flex-1`,onClickCapture:e=>{let t=(e.nativeEvent.composedPath?.()??[]).find(e=>e instanceof HTMLElement&&e.hasAttribute(`data-title`))?.textContent?.trim();t&&Ft(t)},children:(0,L.jsx)(Ye,{viewerRef:He,className:`diff-render-surface h-full min-h-0 overflow-auto`,files:$,sectionId:lt,sectionTitle:dt,composerDraftTarget:t,renderHeaderPrefix:(e,t,n)=>{let r=Oe(e);return(0,L.jsxs)(C,{children:[(0,L.jsx)(T,{render:(0,L.jsx)(`button`,{type:`button`,className:i(`inline-flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-sm border-0 bg-transparent p-0 transition-colors hover:bg-foreground/10 focus-visible:outline-hidden`,Se(e)),"aria-label":n?`Expand ${r}`:`Collapse ${r}`,"aria-expanded":!n,onClick:e=>{e.stopPropagation(),It(t)}}),children:n?(0,L.jsx)(ie,{className:`size-4`}):(0,L.jsx)(v,{className:`size-4`})}),(0,L.jsx)(E,{side:`top`,children:n?`Expand diff`:`Collapse diff`})]})},options:{diffStyle:d===`split`?`split`:`unified`,lineDiffType:`none`,overflow:g?`wrap`:`scroll`,theme:Ne(o),themeType:o,unsafeCSS:it,stickyHeaders:!0,itemMetrics:{diffHeaderHeight:33},layout:{paddingTop:0,paddingBottom:8,gap:8}}},Y??lt)}):(0,L.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-2`,children:(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(`p`,{className:`text-[11px] text-muted-foreground/75`,children:Q.reason}),(0,L.jsx)(`pre`,{className:i(`max-h-[72vh] rounded-md border border-border/70 bg-background/70 p-3 font-mono text-[11px] leading-relaxed text-muted-foreground/90`,g?`overflow-auto whitespace-pre-wrap wrap-break-word`:`overflow-auto`),children:Q.text})]})}):Dt?(0,L.jsx)(ve,{label:q?`Loading checkpoint diff...`:G===`unstaged`?`Loading working tree diff...`:`Loading branch diff...`}):(0,L.jsx)(`div`,{className:`flex h-full items-center justify-center px-3 py-2 text-xs text-muted-foreground/70`,children:(0,L.jsx)(`p`,{children:kt?`No net changes in this selection.`:`No patch available for this selection.`})})]})}):(0,L.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70`,children:`Turn diffs are unavailable because this project is not a git repository.`}):(0,L.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70`,children:`Select a thread to inspect turn diffs.`})})}export{De as DiffWorkerPoolProvider,U as default};
98
+ //# sourceMappingURL=DiffPanel-DIcYfI9A.js.map