@p4code/cli 0.6.45 → 0.6.47

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.45";
266
+ var version$1 = "0.6.47";
267
267
  //#endregion
268
268
  //#region ../../packages/shared/src/serverInstance.ts
269
269
  /**
@@ -3002,6 +3002,7 @@ const ExecutionEnvironmentCapabilities = Schema$1.Struct({
3002
3002
  never send the commands under version skew. */
3003
3003
  threadSettlement: Schema$1.optionalKey(Schema$1.Boolean),
3004
3004
  threadArchiveCleanup: Schema$1.optionalKey(Schema$1.Boolean),
3005
+ threadArchiveForceWorktree: Schema$1.optionalKey(Schema$1.Boolean),
3005
3006
  /** Server understands thread.snooze / thread.unsnooze commands. Same
3006
3007
  version-skew contract as threadSettlement. */
3007
3008
  threadSnooze: Schema$1.optionalKey(Schema$1.Boolean),
@@ -3357,6 +3358,7 @@ const OrchestrationSession = Schema$1.Struct({
3357
3358
  threadId: ThreadId,
3358
3359
  status: OrchestrationSessionStatus,
3359
3360
  providerName: Schema$1.NullOr(TrimmedNonEmptyString),
3361
+ providerThreadId: Schema$1.optionalKey(Schema$1.NullOr(TrimmedNonEmptyString)),
3360
3362
  providerInstanceId: Schema$1.optional(ProviderInstanceId),
3361
3363
  runtimeMode: RuntimeMode.pipe(Schema$1.withDecodingDefault(Effect.succeed(DEFAULT_RUNTIME_MODE$2))),
3362
3364
  activeTurnId: Schema$1.NullOr(TurnId),
@@ -3456,6 +3458,7 @@ const OrchestrationTurnSummary = Schema$1.Struct({
3456
3458
  });
3457
3459
  const ThreadArchiveCleanup = Schema$1.Struct({
3458
3460
  worktree: Schema$1.Boolean,
3461
+ forceWorktree: Schema$1.optional(Schema$1.Boolean),
3459
3462
  localBranch: Schema$1.Boolean,
3460
3463
  remoteBranch: Schema$1.Boolean,
3461
3464
  assets: Schema$1.Boolean
@@ -42814,7 +42817,7 @@ const ProjectionThreadActivityDbRowSchema = ProjectionThreadActivity.mapFields(S
42814
42817
  sequence: Schema$1.NullOr(NonNegativeInt)
42815
42818
  }));
42816
42819
  const ProjectionThreadActivityIdRowSchema = Schema$1.Struct({ activityId: ProjectionThreadActivity.fields.activityId });
42817
- const ProjectionThreadSessionDbRowSchema = ProjectionThreadSession;
42820
+ const ProjectionThreadSessionDbRowSchema = ProjectionThreadSession.mapFields(Struct.assign({ providerThreadId: Schema$1.NullOr(Schema$1.String) }));
42818
42821
  const ProjectionCheckpointDbRowSchema = ProjectionCheckpoint.mapFields(Struct.assign({ files: Schema$1.fromJsonString(Schema$1.Array(OrchestrationCheckpointFile)) }));
42819
42822
  const ProjectionLatestTurnDbRowSchema = Schema$1.Struct({
42820
42823
  threadId: ProjectionThread.fields.threadId,
@@ -42990,6 +42993,7 @@ function mapSessionRow(row) {
42990
42993
  threadId: row.threadId,
42991
42994
  status: row.status,
42992
42995
  providerName: row.providerName,
42996
+ ...row.providerThreadId !== null ? { providerThreadId: row.providerThreadId } : {},
42993
42997
  ...row.providerInstanceId !== null ? { providerInstanceId: row.providerInstanceId } : {},
42994
42998
  runtimeMode: row.runtimeMode,
42995
42999
  activeTurnId: row.activeTurnId,
@@ -43576,18 +43580,23 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
43576
43580
  Result: ProjectionThreadSessionDbRowSchema,
43577
43581
  execute: () => sql`
43578
43582
  SELECT
43579
- thread_id AS "threadId",
43580
- status,
43581
- provider_name AS "providerName",
43582
- provider_instance_id AS "providerInstanceId",
43583
- provider_session_id AS "providerSessionId",
43584
- provider_thread_id AS "providerThreadId",
43585
- runtime_mode AS "runtimeMode",
43586
- active_turn_id AS "activeTurnId",
43587
- last_error AS "lastError",
43588
- updated_at AS "updatedAt"
43589
- FROM projection_thread_sessions
43590
- ORDER BY thread_id ASC
43583
+ sessions.thread_id AS "threadId",
43584
+ sessions.status,
43585
+ sessions.provider_name AS "providerName",
43586
+ sessions.provider_instance_id AS "providerInstanceId",
43587
+ sessions.provider_session_id AS "providerSessionId",
43588
+ CASE WHEN json_type(runtime.resume_cursor_json, '$.threadId') = 'text'
43589
+ THEN NULLIF(TRIM(json_extract(runtime.resume_cursor_json, '$.threadId')), '')
43590
+ END AS "providerThreadId",
43591
+ sessions.runtime_mode AS "runtimeMode",
43592
+ sessions.active_turn_id AS "activeTurnId",
43593
+ sessions.last_error AS "lastError",
43594
+ sessions.updated_at AS "updatedAt"
43595
+ FROM projection_thread_sessions sessions
43596
+ LEFT JOIN provider_session_runtime runtime
43597
+ ON runtime.thread_id = sessions.thread_id
43598
+ AND runtime.provider_name = 'codex' AND sessions.provider_name = 'codex'
43599
+ ORDER BY sessions.thread_id ASC
43591
43600
  `
43592
43601
  });
43593
43602
  const listActiveThreadSessionRows = SqlSchema.findAll({
@@ -43600,12 +43609,17 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
43600
43609
  sessions.provider_name AS "providerName",
43601
43610
  sessions.provider_instance_id AS "providerInstanceId",
43602
43611
  sessions.provider_session_id AS "providerSessionId",
43603
- sessions.provider_thread_id AS "providerThreadId",
43612
+ CASE WHEN json_type(runtime.resume_cursor_json, '$.threadId') = 'text'
43613
+ THEN NULLIF(TRIM(json_extract(runtime.resume_cursor_json, '$.threadId')), '')
43614
+ END AS "providerThreadId",
43604
43615
  sessions.runtime_mode AS "runtimeMode",
43605
43616
  sessions.active_turn_id AS "activeTurnId",
43606
43617
  sessions.last_error AS "lastError",
43607
43618
  sessions.updated_at AS "updatedAt"
43608
43619
  FROM projection_thread_sessions sessions
43620
+ LEFT JOIN provider_session_runtime runtime
43621
+ ON runtime.thread_id = sessions.thread_id
43622
+ AND runtime.provider_name = 'codex' AND sessions.provider_name = 'codex'
43609
43623
  INNER JOIN projection_threads threads
43610
43624
  ON threads.thread_id = sessions.thread_id
43611
43625
  WHERE threads.deleted_at IS NULL
@@ -43623,12 +43637,17 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
43623
43637
  sessions.provider_name AS "providerName",
43624
43638
  sessions.provider_instance_id AS "providerInstanceId",
43625
43639
  sessions.provider_session_id AS "providerSessionId",
43626
- sessions.provider_thread_id AS "providerThreadId",
43640
+ CASE WHEN json_type(runtime.resume_cursor_json, '$.threadId') = 'text'
43641
+ THEN NULLIF(TRIM(json_extract(runtime.resume_cursor_json, '$.threadId')), '')
43642
+ END AS "providerThreadId",
43627
43643
  sessions.runtime_mode AS "runtimeMode",
43628
43644
  sessions.active_turn_id AS "activeTurnId",
43629
43645
  sessions.last_error AS "lastError",
43630
43646
  sessions.updated_at AS "updatedAt"
43631
43647
  FROM projection_thread_sessions sessions
43648
+ LEFT JOIN provider_session_runtime runtime
43649
+ ON runtime.thread_id = sessions.thread_id
43650
+ AND runtime.provider_name = 'codex' AND sessions.provider_name = 'codex'
43632
43651
  INNER JOIN projection_threads threads
43633
43652
  ON threads.thread_id = sessions.thread_id
43634
43653
  WHERE threads.deleted_at IS NULL
@@ -44109,16 +44128,22 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
44109
44128
  Result: ProjectionThreadSessionDbRowSchema,
44110
44129
  execute: ({ threadId }) => sql`
44111
44130
  SELECT
44112
- thread_id AS "threadId",
44113
- status,
44114
- provider_name AS "providerName",
44115
- provider_instance_id AS "providerInstanceId",
44116
- runtime_mode AS "runtimeMode",
44117
- active_turn_id AS "activeTurnId",
44118
- last_error AS "lastError",
44119
- updated_at AS "updatedAt"
44120
- FROM projection_thread_sessions
44121
- WHERE thread_id = ${threadId}
44131
+ sessions.thread_id AS "threadId",
44132
+ sessions.status,
44133
+ sessions.provider_name AS "providerName",
44134
+ sessions.provider_instance_id AS "providerInstanceId",
44135
+ CASE WHEN json_type(runtime.resume_cursor_json, '$.threadId') = 'text'
44136
+ THEN NULLIF(TRIM(json_extract(runtime.resume_cursor_json, '$.threadId')), '')
44137
+ END AS "providerThreadId",
44138
+ sessions.runtime_mode AS "runtimeMode",
44139
+ sessions.active_turn_id AS "activeTurnId",
44140
+ sessions.last_error AS "lastError",
44141
+ sessions.updated_at AS "updatedAt"
44142
+ FROM projection_thread_sessions sessions
44143
+ LEFT JOIN provider_session_runtime runtime
44144
+ ON runtime.thread_id = sessions.thread_id
44145
+ AND runtime.provider_name = 'codex' AND sessions.provider_name = 'codex'
44146
+ WHERE sessions.thread_id = ${threadId}
44122
44147
  LIMIT 1
44123
44148
  `
44124
44149
  });
@@ -44649,16 +44674,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
44649
44674
  }
44650
44675
  for (const row of sessionRows) {
44651
44676
  updatedAt = maxIso(updatedAt, row.updatedAt);
44652
- sessionsByThread.set(row.threadId, {
44653
- threadId: row.threadId,
44654
- status: row.status,
44655
- providerName: row.providerName,
44656
- ...row.providerInstanceId !== null ? { providerInstanceId: row.providerInstanceId } : {},
44657
- runtimeMode: row.runtimeMode,
44658
- activeTurnId: row.activeTurnId,
44659
- lastError: row.lastError,
44660
- updatedAt: row.updatedAt
44661
- });
44677
+ sessionsByThread.set(row.threadId, mapSessionRow(row));
44662
44678
  }
44663
44679
  const repositoryIdentities = yield* resolveRepositoryIdentitiesForProjects(projectRows, { includeDeleted: true });
44664
44680
  const projects = projectRows.map((row) => ({
@@ -48106,6 +48122,7 @@ const make$96 = Effect.gen(function* () {
48106
48122
  pullRequestStackActions: true,
48107
48123
  threadSettlement: false,
48108
48124
  threadArchiveCleanup: true,
48125
+ threadArchiveForceWorktree: true,
48109
48126
  threadLifecycleV2: false,
48110
48127
  checkoutPreparation: true,
48111
48128
  threadSnooze: true,
@@ -123900,6 +123917,39 @@ const make$36 = Effect.gen(function* () {
123900
123917
  }))), { discard: true });
123901
123918
  });
123902
123919
  const record = (input) => recordRaw(input).pipe(mapLifecycleError);
123920
+ const removeConfirmedWorktree = Effect.fn("threadWorkspaceLifecycle.removeConfirmedWorktree")(function* (input) {
123921
+ yield* record({
123922
+ threadIds: input.threadIds,
123923
+ lifecycle: {
123924
+ status: "cleanup-pending",
123925
+ detail: "Confirmed worktree deletion is pending; branches will be kept.",
123926
+ cleanup: input.cleanup,
123927
+ pullRequestNumber: input.lifecycle?.pullRequestNumber ?? null,
123928
+ mergeCommitSha: input.lifecycle?.mergeCommitSha ?? null,
123929
+ updatedAt: DateTime.formatIso(yield* DateTime.now)
123930
+ }
123931
+ });
123932
+ yield* gitWorkflow.removeWorktree({
123933
+ cwd: input.project.workspaceRoot,
123934
+ path: input.worktreePath,
123935
+ force: true
123936
+ });
123937
+ const detail = `Worktree and all its files deleted as confirmed; branches kept. Branch cleanup skipped: ${input.reason.replace("Cleanup refused because ", "")}`;
123938
+ yield* record({
123939
+ threadIds: input.threadIds,
123940
+ lifecycle: {
123941
+ status: "cleaned",
123942
+ detail,
123943
+ pullRequestNumber: input.lifecycle?.pullRequestNumber ?? null,
123944
+ mergeCommitSha: input.lifecycle?.mergeCommitSha ?? null,
123945
+ updatedAt: DateTime.formatIso(yield* DateTime.now)
123946
+ }
123947
+ });
123948
+ return {
123949
+ outcome: "cleaned",
123950
+ detail
123951
+ };
123952
+ });
123903
123953
  const cleanupDetachedWorktree = Effect.fn("threadWorkspaceLifecycle.cleanupDetached")(function* (input) {
123904
123954
  const { threadIds, project, worktreePath, refusal, now } = input;
123905
123955
  const defaultRef = (yield* gitWorkflow.listRefs({
@@ -123908,10 +123958,10 @@ const make$36 = Effect.gen(function* () {
123908
123958
  refresh: true
123909
123959
  })).refs.find((ref) => ref.isRemote === true && ref.isDefault);
123910
123960
  if (defaultRef === void 0 || defaultRef.remoteName === void 0) return yield* refusal("Cleanup refused because the default remote branch could not be resolved.");
123911
- yield* gitWorkflow.fetchRemote({
123961
+ if ((yield* gitWorkflow.fetchRemote({
123912
123962
  cwd: project.workspaceRoot,
123913
123963
  remoteName: defaultRef.remoteName
123914
- });
123964
+ }).pipe(Effect.result))._tag === "Failure") return yield* refusal("Cleanup refused because the default remote branch could not be fetched.");
123915
123965
  const ancestorResult = yield* git.execute({
123916
123966
  operation: "ThreadWorkspaceLifecycle.detachedMergeBase",
123917
123967
  cwd: worktreePath,
@@ -123985,7 +124035,8 @@ const make$36 = Effect.gen(function* () {
123985
124035
  });
123986
124036
  if (input.cleanup === void 0 || input.cleanup.worktree) yield* gitWorkflow.removeWorktree({
123987
124037
  cwd: project.workspaceRoot,
123988
- path: worktreePath
124038
+ path: worktreePath,
124039
+ ...input.cleanup?.forceWorktree ? { force: true } : {}
123989
124040
  });
123990
124041
  const removedDetail = input.cleanup && !input.cleanup.worktree ? "Thread assets removed; workspace preserved." : "Detached worktree removed; thread context preserved.";
123991
124042
  const detail = input.cleanup?.localBranch || input.cleanup?.remoteBranch ? `${removedDetail} No feature branch was checked out, so branch cleanup was skipped.` : removedDetail;
@@ -124085,6 +124136,15 @@ const make$36 = Effect.gen(function* () {
124085
124136
  })).stdout.split("\0").flatMap((field) => field.startsWith("worktree ") ? [field.slice(9)] : []);
124086
124137
  if (!(yield* Effect.forEach(registeredPaths, (registeredPath) => fs.realPath(registeredPath).pipe(Effect.orElseSucceed(() => null)), { concurrency: 8 })).includes(canonicalWorktree)) return yield* refusal("Cleanup refused because this is not a registered project worktree.");
124087
124138
  if (cleanup?.localBranch && !cleanup.worktree) return yield* refusal("Select worktree removal before deleting its checked-out local branch.");
124139
+ const workspaceRefusal = (detail) => cleanup?.worktree && cleanup.forceWorktree ? removeConfirmedWorktree({
124140
+ threadIds,
124141
+ project,
124142
+ worktreePath,
124143
+ cleanup,
124144
+ reason: detail,
124145
+ lifecycle: requestedThread.workspaceLifecycle
124146
+ }).pipe(mapLifecycleError) : refusal(detail);
124147
+ if (cleanup?.worktree && cleanup.forceWorktree && !cleanup.localBranch && !cleanup.remoteBranch) return yield* workspaceRefusal("Branch deletion was not selected.");
124088
124148
  const localStatus = yield* git.statusDetailsLocal(worktreePath).pipe(Effect.mapError((cause) => new ThreadWorkspaceLifecycleError({
124089
124149
  detail: "Could not inspect thread worktree before cleanup.",
124090
124150
  cause
@@ -124103,7 +124163,7 @@ const make$36 = Effect.gen(function* () {
124103
124163
  hasUncommittedChanges: trackedStatus === null ? localStatus.hasWorkingTreeChanges : trackedStatus.stdout.trim().length > 0,
124104
124164
  isMerged: true
124105
124165
  });
124106
- if (dirtyRefusal !== null) return yield* refusal(dirtyRefusal);
124166
+ if (dirtyRefusal !== null) return yield* workspaceRefusal(dirtyRefusal);
124107
124167
  const cleanGeneratedFiles = Effect.fn("ThreadWorkspaceLifecycle.cleanGeneratedFiles")(function* () {
124108
124168
  if (!cleanup?.assets) return;
124109
124169
  yield* git.execute({
@@ -124119,7 +124179,7 @@ const make$36 = Effect.gen(function* () {
124119
124179
  threadIds,
124120
124180
  project,
124121
124181
  worktreePath,
124122
- refusal,
124182
+ refusal: workspaceRefusal,
124123
124183
  now,
124124
124184
  ...cleanup === void 0 ? {} : { cleanup }
124125
124185
  });
@@ -124131,11 +124191,11 @@ const make$36 = Effect.gen(function* () {
124131
124191
  });
124132
124192
  const branchRef = refs.refs.find((ref) => ref.isRemote !== true && ref.name === branch);
124133
124193
  const defaultRef = refs.refs.find((ref) => ref.isRemote === true && ref.isDefault);
124134
- if (branchRef === void 0 || defaultRef === void 0 || defaultRef.remoteName === void 0) return yield* refusal("Cleanup refused because branch or default remote branch could not be resolved.");
124135
- yield* gitWorkflow.fetchRemote({
124194
+ if (branchRef === void 0 || defaultRef === void 0 || defaultRef.remoteName === void 0) return yield* workspaceRefusal("Cleanup refused because branch or default remote branch could not be resolved.");
124195
+ if ((yield* gitWorkflow.fetchRemote({
124136
124196
  cwd: project.workspaceRoot,
124137
124197
  remoteName: defaultRef.remoteName
124138
- });
124198
+ }).pipe(Effect.result))._tag === "Failure") return yield* workspaceRefusal("Cleanup refused because the default remote branch could not be fetched.");
124139
124199
  yield* gitWorkflow.invalidateStatus(worktreePath);
124140
124200
  const pullRequestSummary = (yield* gitWorkflow.status({ cwd: worktreePath })).pr;
124141
124201
  const repository = repositoryIdentityOf(project);
@@ -124160,7 +124220,7 @@ const make$36 = Effect.gen(function* () {
124160
124220
  ],
124161
124221
  allowNonZeroExit: true
124162
124222
  });
124163
- if (ancestorResult.exitCode !== 0 && ancestorResult.exitCode !== 1) return yield* refusal("Cleanup refused because branch ancestry could not be verified.");
124223
+ if (ancestorResult.exitCode !== 0 && ancestorResult.exitCode !== 1) return yield* workspaceRefusal("Cleanup refused because branch ancestry could not be verified.");
124164
124224
  const branchCommitResult = yield* git.execute({
124165
124225
  operation: "ThreadWorkspaceLifecycle.branchCommit",
124166
124226
  cwd: project.workspaceRoot,
@@ -124192,9 +124252,9 @@ const make$36 = Effect.gen(function* () {
124192
124252
  hasUncommittedChanges: false,
124193
124253
  isMerged: merged !== null
124194
124254
  });
124195
- if (mergeRefusal !== null || merged === null) return yield* refusal(mergeRefusal ?? "Cleanup refused because branch merge status is unknown.");
124255
+ if (mergeRefusal !== null || merged === null) return yield* workspaceRefusal(mergeRefusal ?? "Cleanup refused because branch merge status is unknown.");
124196
124256
  if (cleanup?.remoteBranch) {
124197
- const [configuredRemote, configuredRef] = (yield* git.execute({
124257
+ const upstream = yield* git.execute({
124198
124258
  operation: "ThreadWorkspaceLifecycle.remoteUpstream",
124199
124259
  cwd: project.workspaceRoot,
124200
124260
  args: [
@@ -124202,12 +124262,14 @@ const make$36 = Effect.gen(function* () {
124202
124262
  "--format=%(upstream:remotename)%00%(upstream:remoteref)",
124203
124263
  `refs/heads/${branch}`
124204
124264
  ]
124205
- })).stdout.trim().split("\0");
124265
+ }).pipe(Effect.result);
124266
+ if (upstream._tag === "Failure") return yield* workspaceRefusal("Cleanup refused because the feature branch's remote upstream could not be verified.");
124267
+ const [configuredRemote, configuredRef] = upstream.success.stdout.trim().split("\0");
124206
124268
  const missingUpstream = !configuredRemote && !configuredRef;
124207
124269
  const remoteName = missingUpstream ? defaultRef.remoteName : configuredRemote;
124208
124270
  const remoteRef = missingUpstream ? `refs/heads/${branch}` : configuredRef;
124209
- if (!remoteName || remoteName === "." || remoteRef !== `refs/heads/${branch}`) return yield* refusal("Cleanup refused because the feature branch's remote upstream could not be verified.");
124210
- const remoteSha = (yield* git.execute({
124271
+ if (!remoteName || remoteName === "." || remoteRef !== `refs/heads/${branch}`) return yield* workspaceRefusal("Cleanup refused because the feature branch's remote upstream could not be verified.");
124272
+ const remoteTip = yield* git.execute({
124211
124273
  operation: "ThreadWorkspaceLifecycle.remoteTip",
124212
124274
  cwd: project.workspaceRoot,
124213
124275
  args: [
@@ -124216,19 +124278,23 @@ const make$36 = Effect.gen(function* () {
124216
124278
  remoteName,
124217
124279
  remoteRef
124218
124280
  ]
124219
- })).stdout.trim().split(/\s+/)[0];
124220
- if (missingUpstream && remoteSha) return yield* refusal("Cleanup refused because a remote branch exists without a verified upstream.");
124221
- if (remoteSha && remoteSha !== branchCommitResult.stdout.trim()) return yield* refusal("Cleanup refused because the remote branch differs from the verified merged branch.");
124222
- if (remoteSha) yield* git.execute({
124223
- operation: "ThreadWorkspaceLifecycle.deleteRemoteBranch",
124224
- cwd: project.workspaceRoot,
124225
- args: [
124226
- "push",
124227
- `--force-with-lease=refs/heads/${branch}:${remoteSha}`,
124228
- remoteName,
124229
- `:refs/heads/${branch}`
124230
- ]
124231
- });
124281
+ }).pipe(Effect.result);
124282
+ if (remoteTip._tag === "Failure") return yield* workspaceRefusal("Cleanup refused because the remote branch could not be verified.");
124283
+ const remoteSha = remoteTip.success.stdout.trim().split(/\s+/)[0];
124284
+ if (missingUpstream && remoteSha) return yield* workspaceRefusal("Cleanup refused because a remote branch exists without a verified upstream.");
124285
+ if (remoteSha && remoteSha !== branchCommitResult.stdout.trim()) return yield* workspaceRefusal("Cleanup refused because the remote branch differs from the verified merged branch.");
124286
+ if (remoteSha) {
124287
+ if ((yield* git.execute({
124288
+ operation: "ThreadWorkspaceLifecycle.deleteRemoteBranch",
124289
+ cwd: project.workspaceRoot,
124290
+ args: [
124291
+ "push",
124292
+ `--force-with-lease=refs/heads/${branch}:${remoteSha}`,
124293
+ remoteName,
124294
+ `:refs/heads/${branch}`
124295
+ ]
124296
+ }).pipe(Effect.result))._tag === "Failure") return yield* workspaceRefusal("Cleanup refused because the remote branch could not be removed.");
124297
+ }
124232
124298
  }
124233
124299
  yield* record({
124234
124300
  threadIds,
@@ -124244,7 +124310,8 @@ const make$36 = Effect.gen(function* () {
124244
124310
  yield* cleanGeneratedFiles();
124245
124311
  if (cleanup === void 0 || cleanup.worktree) yield* gitWorkflow.removeWorktree({
124246
124312
  cwd: project.workspaceRoot,
124247
- path: worktreePath
124313
+ path: worktreePath,
124314
+ ...cleanup?.forceWorktree ? { force: true } : {}
124248
124315
  });
124249
124316
  if (cleanup === void 0 || cleanup.localBranch) yield* git.execute({
124250
124317
  operation: "ThreadWorkspaceLifecycle.deleteBranch",
@@ -142410,6 +142477,7 @@ const make$9 = Effect.gen(function* () {
142410
142477
  threadId: thread.id,
142411
142478
  status,
142412
142479
  providerName: event.provider,
142480
+ ...event.type === "thread.started" && event.provider === "codex" ? { providerThreadId: event.payload?.providerThreadId ?? thread.session?.providerThreadId ?? null } : thread.session?.providerName === event.provider && thread.session.providerThreadId !== void 0 ? { providerThreadId: thread.session.providerThreadId } : {},
142413
142481
  ...event.providerInstanceId !== void 0 ? { providerInstanceId: event.providerInstanceId } : {},
142414
142482
  runtimeMode: thread.session?.runtimeMode ?? "full-access",
142415
142483
  activeTurnId: nextActiveTurnId,
@@ -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-Bv_X-cMv.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-B5J-luuB.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-CSrXgWE0.js";import{a as He,n as Ue}from"./fileCommentAnnotations-CgA7zGQt.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-Cp_rWZ2h.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-CKhF-2cv.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-BLoqyfJ3.js";import{a as He,n as Ue}from"./fileCommentAnnotations-CyPhtPu2.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=`
2
2
  [data-diffs-header],
3
3
  [data-diff],
4
4
  [data-file],
@@ -95,4 +95,4 @@ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{n as t,r as n,t as r}f
95
95
  text-decoration-color: currentColor;
96
96
  }
97
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-DCSXkAw9.js.map
98
+ //# sourceMappingURL=DiffPanel-CcEQfFwb.js.map