@p4code/cli 0.3.25 → 0.3.27

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
@@ -239,7 +239,7 @@ const make$92 = () => {
239
239
  const layer$82 = Layer.sync(NetService, make$92);
240
240
  //#endregion
241
241
  //#region package.json
242
- var version = "0.3.25";
242
+ var version = "0.3.27";
243
243
  //#endregion
244
244
  //#region src/config.ts
245
245
  /**
@@ -56312,6 +56312,16 @@ function resolveWorkspaceCleanupRefusal(input) {
56312
56312
  if (!input.isMerged) return "Cleanup refused because branch is not merged into default branch.";
56313
56313
  return null;
56314
56314
  }
56315
+ /**
56316
+ * A thread on a detached HEAD has no branch to merge, so its worktree is safe
56317
+ * to drop as soon as nothing in it is unsaved and every commit it points at is
56318
+ * already on the default branch.
56319
+ */
56320
+ function resolveDetachedWorkspaceCleanupRefusal(input) {
56321
+ if (input.hasUncommittedChanges) return "Cleanup refused because worktree has uncommitted changes.";
56322
+ if (!input.headIsAncestorOfDefault) return "Cleanup refused because the detached worktree has commits that are not on the default branch.";
56323
+ return null;
56324
+ }
56315
56325
  function resolveMergedWorkspaceContext(input) {
56316
56326
  const pullRequest = input.pullRequest;
56317
56327
  if (input.branchIsAncestor && input.branchCommitSha !== null) return {
@@ -56352,6 +56362,72 @@ const make$29 = Effect.gen(function* () {
56352
56362
  }))), { discard: true });
56353
56363
  });
56354
56364
  const record = (input) => recordRaw(input).pipe(mapLifecycleError);
56365
+ const cleanupDetachedWorktree = Effect.fn("threadWorkspaceLifecycle.cleanupDetached")(function* (input) {
56366
+ const { threadIds, project, worktreePath, refusal, now } = input;
56367
+ if ((yield* git.statusDetailsLocal(worktreePath).pipe(Effect.mapError((cause) => new ThreadWorkspaceLifecycleError({
56368
+ detail: "Could not inspect thread worktree before cleanup.",
56369
+ cause
56370
+ })))).hasWorkingTreeChanges) return yield* refusal(resolveDetachedWorkspaceCleanupRefusal({
56371
+ hasUncommittedChanges: true,
56372
+ headIsAncestorOfDefault: true
56373
+ }));
56374
+ const defaultRef = (yield* gitWorkflow.listRefs({
56375
+ cwd: project.workspaceRoot,
56376
+ includeMatchingRemoteRefs: true,
56377
+ refresh: true
56378
+ })).refs.find((ref) => ref.isRemote === true && ref.isDefault);
56379
+ if (defaultRef === void 0 || defaultRef.remoteName === void 0) return yield* refusal("Cleanup refused because the default remote branch could not be resolved.");
56380
+ yield* gitWorkflow.fetchRemote({
56381
+ cwd: project.workspaceRoot,
56382
+ remoteName: defaultRef.remoteName
56383
+ });
56384
+ const ancestorResult = yield* git.execute({
56385
+ operation: "ThreadWorkspaceLifecycle.detachedMergeBase",
56386
+ cwd: worktreePath,
56387
+ args: [
56388
+ "merge-base",
56389
+ "--is-ancestor",
56390
+ "HEAD",
56391
+ `refs/remotes/${defaultRef.name}`
56392
+ ],
56393
+ allowNonZeroExit: true
56394
+ });
56395
+ if (ancestorResult.exitCode !== 0 && ancestorResult.exitCode !== 1) return yield* refusal("Cleanup refused because worktree ancestry could not be verified.");
56396
+ const ancestryRefusal = resolveDetachedWorkspaceCleanupRefusal({
56397
+ hasUncommittedChanges: false,
56398
+ headIsAncestorOfDefault: ancestorResult.exitCode === 0
56399
+ });
56400
+ if (ancestryRefusal !== null) return yield* refusal(ancestryRefusal);
56401
+ yield* record({
56402
+ threadIds,
56403
+ lifecycle: {
56404
+ status: "cleanup-pending",
56405
+ detail: "Detached worktree verified; workspace cleanup is pending.",
56406
+ pullRequestNumber: null,
56407
+ mergeCommitSha: null,
56408
+ updatedAt: now
56409
+ }
56410
+ });
56411
+ yield* gitWorkflow.removeWorktree({
56412
+ cwd: project.workspaceRoot,
56413
+ path: worktreePath
56414
+ });
56415
+ const detail = "Detached worktree removed; thread context preserved.";
56416
+ yield* record({
56417
+ threadIds,
56418
+ lifecycle: {
56419
+ status: "cleaned",
56420
+ detail,
56421
+ pullRequestNumber: null,
56422
+ mergeCommitSha: null,
56423
+ updatedAt: DateTime.formatIso(yield* DateTime.now)
56424
+ }
56425
+ });
56426
+ return {
56427
+ outcome: "cleaned",
56428
+ detail
56429
+ };
56430
+ });
56355
56431
  const cleanupRaw = Effect.fn("threadWorkspaceLifecycle.cleanup")(function* (threadId) {
56356
56432
  const snapshot = yield* snapshots.getCommandReadModel();
56357
56433
  const threadIds = activePairThreadIds(threadId, snapshot.threadPairs ?? []);
@@ -56387,8 +56463,15 @@ const make$29 = Effect.gen(function* () {
56387
56463
  if (threads.some((thread) => thread.archivedAt === null)) return yield* refusal("Cleanup refused because thread is not archived.");
56388
56464
  const branch = requestedThread.branch;
56389
56465
  const worktreePath = requestedThread.worktreePath;
56390
- if (branch === null || worktreePath === null) return yield* refusal("Cleanup refused because thread has no worktree and branch binding.");
56466
+ if (worktreePath === null) return yield* refusal("Cleanup refused because thread has no worktree.");
56391
56467
  if (threads.some((thread) => thread.branch !== branch || thread.worktreePath !== worktreePath)) return yield* refusal("Cleanup refused because Fusion threads do not share one workspace.");
56468
+ if (branch === null) return yield* cleanupDetachedWorktree({
56469
+ threadIds,
56470
+ project,
56471
+ worktreePath,
56472
+ refusal,
56473
+ now
56474
+ });
56392
56475
  const dirtyRefusal = resolveWorkspaceCleanupRefusal({
56393
56476
  hasLiveSession: false,
56394
56477
  hasUncommittedChanges: (yield* git.statusDetailsLocal(worktreePath).pipe(Effect.mapError((cause) => new ThreadWorkspaceLifecycleError({
@@ -69039,6 +69122,19 @@ const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(function*
69039
69122
  };
69040
69123
  });
69041
69124
  //#endregion
69125
+ //#region ../../packages/shared/src/String.ts
69126
+ /**
69127
+ * Drop a leaked tool-call tag from a plan step title. A mis-closed
69128
+ * `<parameter name="subject">` call swallows `</subject> <parameter
69129
+ * name="description">...` into the title; everything from the first closing
69130
+ * or parameter tag onward is noise the banner must not render.
69131
+ */
69132
+ function cleanPlanStepTitle(title) {
69133
+ const cut = title.search(/<\/[a-z_-]+>\s*(?=<parameter\b)|<parameter\b/i);
69134
+ const cleaned = (cut === -1 ? title : title.slice(0, cut)).trim();
69135
+ return cleaned.length > 0 ? cleaned : title.trim();
69136
+ }
69137
+ //#endregion
69042
69138
  //#region ../../packages/shared/src/cliArgs.ts
69043
69139
  function tokenizeCliArgs(args) {
69044
69140
  const input = args?.trim();
@@ -69721,7 +69817,7 @@ function extractPlanStepsFromTodoInput(input) {
69721
69817
  const todos = input.todos;
69722
69818
  if (!Array.isArray(todos) || todos.length === 0) return null;
69723
69819
  return todos.filter((t) => t !== null && typeof t === "object").map((todo) => ({
69724
- step: typeof todo.content === "string" && todo.content.trim().length > 0 ? todo.content.trim() : "Task",
69820
+ step: typeof todo.content === "string" && todo.content.trim().length > 0 ? cleanPlanStepTitle(todo.content) : "Task",
69725
69821
  status: todo.status === "completed" ? "completed" : todo.status === "in_progress" ? "inProgress" : "pending"
69726
69822
  }));
69727
69823
  }
@@ -69751,6 +69847,9 @@ function isClaudeTaskTool(toolName) {
69751
69847
  function normalizeClaudeTaskStatus(value) {
69752
69848
  return value === "completed" ? "completed" : value === "in_progress" ? "inProgress" : "pending";
69753
69849
  }
69850
+ function cleanStepSubject(value) {
69851
+ return value === void 0 ? void 0 : cleanPlanStepTitle(value);
69852
+ }
69754
69853
  function readString(value) {
69755
69854
  return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
69756
69855
  }
@@ -69777,7 +69876,7 @@ function applyClaudeTaskToolResult(tasks, tool, result) {
69777
69876
  if (entry === null || typeof entry !== "object" || Array.isArray(entry)) continue;
69778
69877
  const task = entry;
69779
69878
  const id = readString(task.id);
69780
- const subject = readString(task.subject);
69879
+ const subject = cleanStepSubject(readString(task.subject));
69781
69880
  if (!id || !subject) continue;
69782
69881
  tasks.set(id, {
69783
69882
  id,
@@ -69791,7 +69890,7 @@ function applyClaudeTaskToolResult(tasks, tool, result) {
69791
69890
  if (tool.toolName === "TaskCreate") {
69792
69891
  const resultTask = readClaudeTaskFromResult(result);
69793
69892
  const id = readString(resultTask?.id);
69794
- const subject = readString(resultTask?.subject) ?? readString(tool.input.subject);
69893
+ const subject = cleanStepSubject(readString(resultTask?.subject) ?? readString(tool.input.subject));
69795
69894
  if (!id || !subject) return false;
69796
69895
  tasks.set(id, {
69797
69896
  id,
@@ -69805,7 +69904,7 @@ function applyClaudeTaskToolResult(tasks, tool, result) {
69805
69904
  if (!taskId) return false;
69806
69905
  const task = tasks.get(taskId);
69807
69906
  if (!task) return false;
69808
- const subject = readString(tool.input.subject);
69907
+ const subject = cleanStepSubject(readString(tool.input.subject));
69809
69908
  if (subject && task.subject !== subject) {
69810
69909
  task.subject = subject;
69811
69910
  changed = true;
@@ -92560,10 +92659,15 @@ function collabTaskEvents(event, canonicalThreadId, item, defaults) {
92560
92659
  }
92561
92660
  return events;
92562
92661
  }
92563
- function itemTitle(itemType, item) {
92662
+ function itemTitle(itemType, item, agentNames) {
92564
92663
  if (itemType === "mcp_tool_call" && item?.type === "mcpToolCall") return `${item.server} · ${item.tool}`;
92565
92664
  if (item?.type === "collabAgentToolCall") {
92566
92665
  const title = COLLAB_TOOL_TITLES[item.tool] ?? "Agent tool call";
92666
+ const names = item.receiverThreadIds.flatMap((threadId) => {
92667
+ const name = agentNames?.get(threadId);
92668
+ return name ? [name] : [];
92669
+ });
92670
+ if (names.length > 0) return `${title} · ${names.join(", ")}`;
92567
92671
  const model = trimText$1(item.model);
92568
92672
  return model ? `${title} · ${model}` : title;
92569
92673
  }
@@ -92715,12 +92819,13 @@ function runtimeEventBase(event, canonicalThreadId) {
92715
92819
  }
92716
92820
  };
92717
92821
  }
92718
- function mapItemLifecycle(event, canonicalThreadId, lifecycle) {
92822
+ function mapItemLifecycle(event, canonicalThreadId, lifecycle, agentNames) {
92719
92823
  const item = (readPayload(V2ItemStartedNotification, event.payload) ?? readPayload(V2ItemCompletedNotification, event.payload))?.item;
92720
92824
  if (!item) return;
92721
92825
  const itemType = toCanonicalItemType(item.type);
92722
92826
  if (itemType === "unknown" && lifecycle !== "item.updated") return;
92723
92827
  const detail = itemDetail(itemType, item);
92828
+ const title = itemTitle(itemType, item, agentNames);
92724
92829
  const status = lifecycle === "item.started" ? "inProgress" : lifecycle === "item.completed" ? "completed" : void 0;
92725
92830
  return {
92726
92831
  ...runtimeEventBase(event, canonicalThreadId),
@@ -92728,12 +92833,17 @@ function mapItemLifecycle(event, canonicalThreadId, lifecycle) {
92728
92833
  payload: {
92729
92834
  itemType,
92730
92835
  ...status ? { status } : {},
92731
- ...itemTitle(itemType, item) ? { title: itemTitle(itemType, item) } : {},
92836
+ ...title ? { title } : {},
92732
92837
  ...detail ? { detail } : {},
92733
92838
  ...event.payload !== void 0 ? { data: event.payload } : {}
92734
92839
  }
92735
92840
  };
92736
92841
  }
92842
+ function rememberAgentName(item, collabDefaults) {
92843
+ if (item.type !== "subAgentActivity" || collabDefaults === void 0) return;
92844
+ const name = agentNameFromPath(item.agentPath);
92845
+ if (name) collabDefaults.agentNames.set(item.agentThreadId, name);
92846
+ }
92737
92847
  function mapToRuntimeEvents(event, canonicalThreadId, collabDefaults) {
92738
92848
  if (event.kind === "error") {
92739
92849
  if (!event.message) return [];
@@ -92926,8 +93036,9 @@ function mapToRuntimeEvents(event, canonicalThreadId, collabDefaults) {
92926
93036
  }];
92927
93037
  }
92928
93038
  if (event.method === "item/started") {
92929
- const started = mapItemLifecycle(event, canonicalThreadId, "item.started");
92930
93039
  const item = readPayload(V2ItemStartedNotification, event.payload)?.item;
93040
+ if (item) rememberAgentName(item, collabDefaults);
93041
+ const started = mapItemLifecycle(event, canonicalThreadId, "item.started", collabDefaults?.agentNames);
92931
93042
  const taskEvents = item ? collabTaskEvents(event, canonicalThreadId, item, collabDefaults) : [];
92932
93043
  return started ? [started, ...taskEvents] : taskEvents;
92933
93044
  }
@@ -92944,7 +93055,8 @@ function mapToRuntimeEvents(event, canonicalThreadId, collabDefaults) {
92944
93055
  payload: { planMarkdown: detail }
92945
93056
  }];
92946
93057
  }
92947
- const completed = mapItemLifecycle(event, canonicalThreadId, "item.completed");
93058
+ rememberAgentName(item, collabDefaults);
93059
+ const completed = mapItemLifecycle(event, canonicalThreadId, "item.completed", collabDefaults?.agentNames);
92948
93060
  const taskEvents = collabTaskEvents(event, canonicalThreadId, item, collabDefaults);
92949
93061
  return completed ? [completed, ...taskEvents] : taskEvents;
92950
93062
  }
@@ -93318,6 +93430,7 @@ const makeCodexAdapter = Effect.fn("makeCodexAdapter")(function* (codexConfig, o
93318
93430
  cause
93319
93431
  })));
93320
93432
  const collabDefaults = {
93433
+ agentNames: /* @__PURE__ */ new Map(),
93321
93434
  model: input.modelSelection?.instanceId === boundInstanceId ? input.modelSelection.model : void 0,
93322
93435
  reasoningEffort: input.modelSelection?.instanceId === boundInstanceId ? getModelSelectionStringOptionValue(input.modelSelection, "reasoningEffort") : void 0
93323
93436
  };
@@ -108694,7 +108807,7 @@ const DEFAULT_RUNTIME_MODE = "full-access";
108694
108807
  const DEFAULT_THREAD_TITLE = "New thread";
108695
108808
  const NON_SYSTEM_PROVIDER_STRUCTURED_USER_QUESTIONS = structuredUserQuestionPrompt("your provider's structured user-input question tool");
108696
108809
  const FUSION_PROMOTION_INSTRUCTIONS = `Work independently in this normal thread. Fusion is a silent escalation path, not a startup procedure. Do not inspect Fusion tools/skill, mention Fusion status, or announce that Fusion was not invoked. First analyze the task normally. Only if that analysis reveals a concrete unresolved tradeoff, correctness risk, or design decision materially needing a second opinion, stop before implementation, propose Fusion, and ask the user for explicit approval. The user may approve with ordinary affirmative text such as "approved"; /fusion or $fusion also authorizes Fusion directly without a prior proposal. Do not activate, spawn, or promote until one of those authorizations arrives. UI work, complex logic, task size, unfamiliarity, or duration alone never qualifies.`;
108697
- const FUSION_BUILDER_INSTRUCTIONS = `You are Fusion Builder in an already-created native server pair. Server owns pairing and coordination. Do not inspect or invoke the Fusion skill, create/pair/rename threads, or announce/setup Fusion. Start the user's task directly. Before editing, create and maintain the phase list with your provider's step-tracking tool (Claude Code: TaskCreate for each phase, then TaskUpdate for status, or TodoWrite when that is the tool offered; Codex: update_plan), never the MCP task board tools - one entry per phase in order, exactly one in progress at a time, marked completed at each phase end - so phases render in the task banner. That list holds phase entries only for the whole task; keep step-level or per-file todos out of it. Prose alone leaves the banner empty. Split it into the fewest substantial phases the task genuinely needs plus a final integration/whole-task phase; most tasks need one to three work phases. Each phase is a complete reviewable slice of behavior. Never split per file, per function, or per trivial step: over-splitting spends review turns instead of finishing the job. Add a phase only when a real review boundary, risky decision, or independent behavior separates the work. Complete exactly one phase per turn, and finish the whole phase in that turn rather than stopping early. Do not run tests, typecheck, lint, or builds per phase; write the tests the change needs, then run verification once in the final phase over the whole task. Exception: a phase whose own correctness is unclear may run the single narrowest check that resolves it. End every phase turn with phase completed, todo status, changed behavior/files, and remaining phases; do not start the next phase in the same turn. Server then wakes the paired Supervisor, which resumes you through ${FUSION_ADVICE_PROMPT_PREFIX}; a user message may also revise or resume the work. Final phase verifies the entire task against the original request and labels it ready for whole-task review. Supervisor is unreachable during your turn. Never spawn/use another Supervisor thread/subagent or attribute Supervisor decisions without ${FUSION_ADVICE_PROMPT_PREFIX}. Within the current phase, continue when straightforward or evidence is clear. For a concrete unresolved tradeoff, correctness risk, or design decision materially needing judgment, stop safely before the risky choice; final response states the exact question and why review is needed. Evaluate/follow Supervisor advice unless conflicting with user request or verified repo state.`;
108810
+ const FUSION_BUILDER_INSTRUCTIONS = `You are Fusion Builder in an already-created native server pair. Server owns pairing and coordination. Do not inspect or invoke the Fusion skill, create/pair/rename threads, or announce/setup Fusion. Start the user's task directly. Before editing, create and maintain the phase list with your provider's step-tracking tool (Claude Code: TaskCreate for each phase, then TaskUpdate for status, or TodoWrite when that is the tool offered; Codex: update_plan), never the MCP task board tools - one entry per phase in order, exactly one in progress at a time, marked completed at each phase end - so phases render in the task banner. That list holds phase entries only for the whole task; keep step-level or per-file todos out of it. Name each phase in 3-6 words by its outcome, never by a command, file path, or flag, because the banner shows the title verbatim. Prose alone leaves the banner empty. Split it into the fewest substantial phases the task genuinely needs plus a final integration/whole-task phase; most tasks need one to three work phases. Each phase is a complete reviewable slice of behavior. Never split per file, per function, or per trivial step: over-splitting spends review turns instead of finishing the job. Add a phase only when a real review boundary, risky decision, or independent behavior separates the work. Complete exactly one phase per turn, and finish the whole phase in that turn rather than stopping early. Do not run tests, typecheck, lint, or builds per phase; write the tests the change needs, then run verification once in the final phase over the whole task. Exception: a phase whose own correctness is unclear may run the single narrowest check that resolves it. End every phase turn with phase completed, todo status, changed behavior/files, and remaining phases; do not start the next phase in the same turn. Server then wakes the paired Supervisor, which resumes you through ${FUSION_ADVICE_PROMPT_PREFIX}; a user message may also revise or resume the work. Final phase verifies the entire task against the original request and labels it ready for whole-task review. Supervisor is unreachable during your turn. Never spawn/use another Supervisor thread/subagent or attribute Supervisor decisions without ${FUSION_ADVICE_PROMPT_PREFIX}. Within the current phase, continue when straightforward or evidence is clear. For a concrete unresolved tradeoff, correctness risk, or design decision materially needing judgment, stop safely before the risky choice; final response states the exact question and why review is needed. Evaluate/follow Supervisor advice unless conflicting with user request or verified repo state.`;
108698
108811
  const FUSION_WATCHER_INSTRUCTIONS = `You are Fusion Supervisor (watcher) in an already-created native server pair. Server owns pairing and coordination and wakes you with ${FUSION_REVIEW_PROMPT_PREFIX} or ${FUSION_GATE_PROMPT_PREFIX} prompts at builder turn boundaries; this message arrived outside such a wake, so your conversational memory of the pair may be gone. The pair metadata below is authoritative: the builder thread exists and is the counterpart thread id. Never report that no builder thread exists. To resume supervision, read builder events with thread_watch_events from lastReviewedImplementerSequence with limit 50, paging forward with the last returned sequence rather than requesting a whole range at once, derive phase from artifacts (git log/status, PR, builder events, including its turn.plan.updated phase list), steer with thread_advise, and answer an open gate with thread_gate_respond. When a review or gate wake prompt specifies an explicit event range, that range wins over this metadata. Never poll or wait for the builder; deliver review or advice, then end the turn.`;
108699
108812
  const isFusionWatcherWakeMessageId = (messageId) => messageId.startsWith("fusion-review:") || messageId.startsWith("fusion-gate:");
108700
108813
  const fusionPairContext = (pair, role) => {
@@ -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{$c as i,Ca as a,Cl as o,Da as s,Et as c,Fa as l,Fr as u,Ia as d,La as f,Na as p,Oa as m,Pa as ee,Pl as h,Qc as g,_n as te,b as _,ba as v,cu as y,el as ne,gt as b,h as x,ht as S,kl as C,kr as re,st as w,tl as T,vl as ie,vt as E,wr as D,xn as O,zl as ae}from"./previewAssetResource-xr2rxKjm.js";import{a as k,i as oe,n as A,o as j,r as M,s as N,t as se}from"./toggle-group-D3d10cVi.js";import{F as ce,Fr as le,I as ue,J as de,L as fe,Lr as pe,Mr as me,Nr as he,R as P,Y as ge,_ as _e,at as ve,ci as ye,cr as be,ct as xe,dr as Se,fr as Ce,gr as we,h as Te,it as Ee,jr as De,lr as Oe,lt as ke,mr as Ae,oi as je,or as Me,ot as Ne,pr as Pe,rt as Fe,si as Ie,sr as Le,st as Re,ur as ze,yr as Be,zr as Ve}from"./index-BIKAuS5A.js";import{a as He,n as Ue}from"./fileCommentAnnotations-BeZLWoIj.js";var We=T(`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}w.getState().openFile(e,t);return}r(n?x(t,n):t)}var I=r();function Ke(e,t){let n=(0,I.c)(4),r=we(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:o,viewerRef:s,className:c,renderHeaderPrefix:l}=e,d=D(Qe),f=D(B),p;t[0]===a?p=t[1]:(p=e=>e.getComposerDraft(a)?.reviewComments??qe,t[0]=a,t[1]=p);let m=D(p),[ee,h]=(0,F.useState)(null),[g,te]=(0,F.useState)(null),_;t[2]===n?_=t[3]:(_=new Map(n.map(Ze)),t[2]=n,t[3]=_);let v=_,y;if(t[4]!==g||t[5]!==n||t[6]!==m||t[7]!==r){let e;t[9]!==g||t[10]!==m||t[11]!==r?(e=e=>{let{fileDiff:t,filePath:n,fileKey:i,collapsed:a}=e,o=m.filter(e=>e.sectionId===r&&e.filePath===n&&(e.fenceLanguage??`diff`)===`diff`).reduce((e,n)=>{let r=u(t,n);return r?R(e,r,{id:n.id,kind:`comment`,range:r,rangeLabel:n.rangeLabel,text:n.text}):e},[]),s=g?.fileKey===i?[...o,g.annotation]:o;return{id:i,type:`diff`,fileDiff:t,annotations:s,collapsed:a,version:Ee(`${a?`1`:`0`}:${s.flatMap(z).join(`:`)}`)}},t[9]=g,t[10]=m,t[11]=r,t[12]=e):e=t[12],y=n.map(e),t[4]=g,t[5]=n,t[6]=m,t[7]=r,t[8]=y}else y=t[8];let ne=y,b;t[13]!==a||t[14]!==g?.annotation||t[15]!==f?(b=e=>{h(null),g?.annotation.metadata.entries.some(t=>t.id===e)?te(null):f(a,e)},t[13]=a,t[14]=g?.annotation,t[15]=f,t[16]=b):b=t[16];let x=b,S;t[17]!==d||t[18]!==a||t[19]!==g||t[20]!==v||t[21]!==r||t[22]!==i?(S=(e,t)=>{let n=g?.annotation.metadata.entries.find(t=>t.id===e),o=g?v.get(g.fileKey):void 0;if(!n||!o)return;let s=re({id:n.id,sectionId:r,sectionTitle:i,filePath:o.filePath,fileDiff:o.fileDiff,range:n.range,text:t});s&&d(a,s),h(null),te(null)},t[17]=d,t[18]=a,t[19]=g,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 o=Ue(),s=re({id:o,sectionId:r,sectionTitle:i,filePath:a.filePath,fileDiff:a.fileDiff,range:e,text:``});s&&te({fileKey:n.id,annotation:{side:Je(e),lineNumber:e.end,metadata:{entries:[{id:o,kind:`draft`,range:e,rangeLabel:s.rangeLabel,text:``}]}}})},t[24]=v,t[25]=r,t[26]=i,t[27]=w):w=t[27];let T=w,ie=g!==null,E;t[28]===s?E=t[29]:(E=s?{ref:s}:{},t[28]=s,t[29]=E);let O;t[30]===c?O=t[31]:(O=c?{className:c}:{},t[30]=c,t[31]=O);let ae=!ie,oe=!ie,A;t[32]!==T||t[33]!==o||t[34]!==oe||t[35]!==ae?(A={...o,enableGutterUtility:ae,enableLineSelection:oe,onLineSelectionEnd:T},t[32]=T,t[33]=o,t[34]=oe,t[35]=ae,t[36]=A):A=t[36];let j;t[37]===l?j=t[38]:(j=e=>e.type===`diff`?l(e.fileDiff,e.id,e.collapsed===!0):null,t[37]=l,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]!==ne||t[43]!==ee||t[44]!==A||t[45]!==j||t[46]!==M||t[47]!==E||t[48]!==O?(N=(0,L.jsx)(k,{...E,...O,items:ne,selectedLines:ee,onSelectedLinesChange:h,options:A,renderHeaderPrefix:j,renderAnnotation:M}),t[42]=ne,t[43]=ee,t[44]=A,t[45]=j,t[46]=M,t[47]=E,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:o(e,{label:`environment-data:review:diff-preview`,tag:y.reviewGetDiffPreview,staleTimeMs:5e3})}}var et=$e(O);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{$c as i,Al as a,Bl as o,Ca as s,Da as c,Et as l,Fa as ee,Fl as te,Fr as u,Ia as d,La as f,Na as ne,Oa as re,Pa as p,_n as m,b as h,ba as g,el as _,gt as v,h as y,ht as b,kr as ie,lu as x,nl as S,st as C,tl as w,vt as T,wl as E,wr as D,xn as O,yl as ae}from"./previewAssetResource-BzsIqfaZ.js";import{a as k,i as oe,n as A,o as j,r as M,s as N,t as se}from"./toggle-group-iMME8AIo.js";import{F as ce,Fr as le,I as ue,J as de,L as fe,Lr as pe,Mr as me,Nr as he,R as P,Y as ge,_ as _e,at as ve,ci as ye,cr as be,ct as xe,dr as Se,fr as Ce,gr as we,h as Te,it as Ee,jr as De,lr as Oe,lt as ke,mr as Ae,oi as je,or as Me,ot as Ne,pr as Pe,rt as Fe,si as Ie,sr as Le,st as Re,ur as ze,yr as Be,zr as Ve}from"./index-DlCE-3-H.js";import{a as He,n as Ue}from"./fileCommentAnnotations-CR_6r0A9.js";var We=S(`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}C.getState().openFile(e,t);return}r(n?y(t,n):t)}var I=r();function Ke(e,t){let n=(0,I.c)(4),r=we(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:o,viewerRef:s,className:c,renderHeaderPrefix:l}=e,ee=D(Qe),te=D(B),d;t[0]===a?d=t[1]:(d=e=>e.getComposerDraft(a)?.reviewComments??qe,t[0]=a,t[1]=d);let f=D(d),[ne,re]=(0,F.useState)(null),[p,m]=(0,F.useState)(null),h;t[2]===n?h=t[3]:(h=new Map(n.map(Ze)),t[2]=n,t[3]=h);let g=h,_;if(t[4]!==p||t[5]!==n||t[6]!==f||t[7]!==r){let e;t[9]!==p||t[10]!==f||t[11]!==r?(e=e=>{let{fileDiff:t,filePath:n,fileKey:i,collapsed:a}=e,o=f.filter(e=>e.sectionId===r&&e.filePath===n&&(e.fenceLanguage??`diff`)===`diff`).reduce((e,n)=>{let r=u(t,n);return r?R(e,r,{id:n.id,kind:`comment`,range:r,rangeLabel:n.rangeLabel,text:n.text}):e},[]),s=p?.fileKey===i?[...o,p.annotation]:o;return{id:i,type:`diff`,fileDiff:t,annotations:s,collapsed:a,version:Ee(`${a?`1`:`0`}:${s.flatMap(z).join(`:`)}`)}},t[9]=p,t[10]=f,t[11]=r,t[12]=e):e=t[12],_=n.map(e),t[4]=p,t[5]=n,t[6]=f,t[7]=r,t[8]=_}else _=t[8];let v=_,y;t[13]!==a||t[14]!==p?.annotation||t[15]!==te?(y=e=>{re(null),p?.annotation.metadata.entries.some(t=>t.id===e)?m(null):te(a,e)},t[13]=a,t[14]=p?.annotation,t[15]=te,t[16]=y):y=t[16];let b=y,x;t[17]!==ee||t[18]!==a||t[19]!==p||t[20]!==g||t[21]!==r||t[22]!==i?(x=(e,t)=>{let n=p?.annotation.metadata.entries.find(t=>t.id===e),o=p?g.get(p.fileKey):void 0;if(!n||!o)return;let s=ie({id:n.id,sectionId:r,sectionTitle:i,filePath:o.filePath,fileDiff:o.fileDiff,range:n.range,text:t});s&&ee(a,s),re(null),m(null)},t[17]=ee,t[18]=a,t[19]=p,t[20]=g,t[21]=r,t[22]=i,t[23]=x):x=t[23];let S=x,C;t[24]!==g||t[25]!==r||t[26]!==i?(C=(e,t)=>{if(!e)return;let n=t.item;if(n.type!==`diff`)return;let a=g.get(n.id);if(!a)return;let o=Ue(),s=ie({id:o,sectionId:r,sectionTitle:i,filePath:a.filePath,fileDiff:a.fileDiff,range:e,text:``});s&&m({fileKey:n.id,annotation:{side:Je(e),lineNumber:e.end,metadata:{entries:[{id:o,kind:`draft`,range:e,rangeLabel:s.rangeLabel,text:``}]}}})},t[24]=g,t[25]=r,t[26]=i,t[27]=C):C=t[27];let w=C,T=p!==null,E;t[28]===s?E=t[29]:(E=s?{ref:s}:{},t[28]=s,t[29]=E);let O;t[30]===c?O=t[31]:(O=c?{className:c}:{},t[30]=c,t[31]=O);let ae=!T,oe=!T,A;t[32]!==w||t[33]!==o||t[34]!==oe||t[35]!==ae?(A={...o,enableGutterUtility:ae,enableLineSelection:oe,onLineSelectionEnd:w},t[32]=w,t[33]=o,t[34]=oe,t[35]=ae,t[36]=A):A=t[36];let j;t[37]===l?j=t[38]:(j=e=>e.type===`diff`?l(e.fileDiff,e.id,e.collapsed===!0):null,t[37]=l,t[38]=j);let M;t[39]!==b||t[40]!==S?(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:()=>b(e.id),onComment:t=>S(e.id,t),onDelete:()=>b(e.id)},e.id))}),t[39]=b,t[40]=S,t[41]=M):M=t[41];let N;return t[42]!==v||t[43]!==ne||t[44]!==A||t[45]!==j||t[46]!==M||t[47]!==E||t[48]!==O?(N=(0,L.jsx)(k,{...E,...O,items:v,selectedLines:ne,onSelectedLinesChange:re,options:A,renderHeaderPrefix:j,renderAnnotation:M}),t[42]=v,t[43]=ne,t[44]=A,t[45]=j,t[46]=M,t[47]=E,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:E(e,{label:`environment-data:review:diff-preview`,tag:x.reviewGetDiffPreview,staleTimeMs:5e3})}}var et=$e(O);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}=_(),u=le(),[y]=(0,F.useState)(n),[x,re]=(0,F.useState)(`stacked`),[w,T]=(0,F.useState)(u.wordWrap),[D,O]=(0,F.useState)(u.diffIgnoreWhitespace),[k,_e]=(0,F.useState)(``),[we,Ee]=(0,F.useState)(()=>({scopeKey:null,fileKeys:rt})),He=(0,F.useRef)(null),Ue=r.threadId,I=he(r),qe=I?.projectId??null,Je=me(I&&qe?{environmentId:I.environmentId,projectId:qe}:null),R=I?.worktreePath??Je?.workspaceRoot,z=ie(te.configValueAtom(I?.environmentId??null)),Xe=Ae(I?.environmentId??null,z?.availableEditors??[]),Ze=c(I!=null&&R!=null?De.status({environmentId:I.environmentId,input:{cwd:R}}):null),B=P(e=>fe(e.byThreadKey,r,y===`unstaged`)),Qe=Ze.data?.isRepo??!0,{turnDiffSummaries:$e,inferredCheckpointTurnCountByTurnId:V}=ue(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=we.scopeKey===Y?we.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:D,cacheScope:q?`turn:${q.turnId}`:null},{enabled:Qe&&q!==void 0}),mt=c(W===null&&I&&R?et.diffPreview({environmentId:I.environmentId,input:{cwd:R,...K?{baseRef:K}:{},ignoreWhitespace:D}}):null),ht=W===null&&mt.error?.includes(`configured workspace root`)===!0&&z?.cwd!==void 0&&z.cwd!==R,gt=c(ht&&I&&z?et.diffPreview({environmentId:I.environmentId,input:{cwd:z.cwd,...K?{baseRef:K}:{},ignoreWhitespace:D}}):null),X=ht?gt:mt,Z=X.data?.sources.find(e=>e.kind===(G===`unstaged`?`working-tree`:`branch-range`)),_t=c(W===null&&G===`branch`&&I&&X.data?.cwd?De.listRefs({environmentId:I.environmentId,input:{cwd:X.data.cwd,includeMatchingRemoteRefs:!0,refKind:`local`,...k.trim().length>0?{query:k.trim()}:{},limit:100}}):null),vt=c(W===null&&G===`branch`&&I&&X.data?.cwd?De.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)(()=>Re(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=Fe(e);return{fileDiff:e,filePath:ke(e),fileKey:t,collapsed:ut.has(t)}}),[ut,At]),jt=(0,F.useMemo)(()=>$.map(e=>e.fileKey),[$]),Mt=M(jt,ut),Nt=(0,F.useMemo)(()=>Ne(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=ce({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`&&!C(t)&&console.warn(`Failed to open diff file in editor.`,{operation:`open-diff-file`,environmentId:r.environmentId,threadId:r.threadId,...ae(h(t))})})()}})},[R,Pt,Xe,r]),It=(0,F.useCallback)(e=>{Ee(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)(()=>{Ee(e=>{let t=e.scopeKey===Y?e.fileKeys:rt;return{scopeKey:Y,fileKeys:oe(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)(ge,{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)(a,{children:[(0,L.jsxs)(d,{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)(i,{className:`size-3.5 shrink-0 text-muted-foreground`})]}),(0,L.jsxs)(m,{align:`start`,className:`w-60`,children:[(0,L.jsx)(s,{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)(s,{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)(s,{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)(p,{children:[(0,L.jsx)(l,{children:`Turn`}),(0,L.jsx)(ee,{className:`w-64`,children:U.map(e=>{let t=e.checkpointTurnCount??V[e.turnId]??`?`;return(0,L.jsxs)(s,{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:Be(e.completedAt,u.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)(ye,{className:`size-3.5 shrink-0 opacity-70`}),(0,L.jsxs)(Le,{items:St,filteredItems:Ct,value:K??H,onOpenChange:e=>{e||_e(``)},onValueChange:e=>{e&&Bt(e===H?null:e)},children:[(0,L.jsxs)(Pe,{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)(i,{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)(Oe,{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=>_e(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)(be,{children:`No matching refs.`}),(0,L.jsxs)(Se,{className:`max-h-64 min-w-0 overflow-x-hidden`,children:[(0,L.jsx)(ze,{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)(ze,{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)(Me,{"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)(ne,{"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)(Te,{additions:Nt.additions,deletions:Nt.deletions,className:`mr-1 text-[11px]`,layout:`inline`}),$.length>0&&(0,L.jsxs)(S,{children:[(0,L.jsx)(E,{render:(0,L.jsx)(v,{type:`button`,size:`icon-xs`,variant:`outline`,"aria-label":Mt?`Expand all files`:`Collapse all files`,onClick:Lt}),children:Mt?(0,L.jsx)(je,{className:`size-3`}):(0,L.jsx)(Ie,{className:`size-3`})}),(0,L.jsx)(b,{side:`top`,children:Mt?`Expand all files`:`Collapse all files`})]}),(0,L.jsxs)(A,{className:`shrink-0`,variant:`outline`,size:`xs`,value:[x],onValueChange:e=>{let t=e[0];(t===`stacked`||t===`split`)&&re(t)},children:[(0,L.jsx)(se,{"aria-label":`Stacked diff view`,value:`stacked`,children:(0,L.jsx)(j,{className:`size-3`})}),(0,L.jsx)(se,{"aria-label":`Split diff view`,value:`split`,children:(0,L.jsx)(N,{className:`size-3`})})]}),(0,L.jsxs)(S,{children:[(0,L.jsx)(E,{render:(0,L.jsx)(se,{"aria-label":w?`Disable diff line wrapping`:`Enable diff line wrapping`,variant:`outline`,size:`xs`,pressed:w,onPressedChange:e=>{T(!!e)}}),children:(0,L.jsx)(pe,{className:`size-3`})}),(0,L.jsx)(b,{side:`top`,children:w?`Disable line wrapping`:`Enable line wrapping`})]}),(0,L.jsxs)(S,{children:[(0,L.jsx)(E,{render:(0,L.jsx)(se,{"aria-label":D?`Show whitespace changes`:`Hide whitespace changes`,variant:`outline`,size:`xs`,pressed:D,onPressedChange:e=>{O(!!e)}}),children:(0,L.jsx)(We,{className:`size-3`})}),(0,L.jsx)(b,{side:`top`,children:D?`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)(S,{children:[(0,L.jsx)(E,{render:(0,L.jsx)(`button`,{type:`button`,className:f(`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`,ve(e)),"aria-label":n?`Expand ${r}`:`Collapse ${r}`,"aria-expanded":!n,onClick:e=>{e.stopPropagation(),It(t)}}),children:n?(0,L.jsx)(g,{className:`size-4`}):(0,L.jsx)(i,{className:`size-4`})}),(0,L.jsx)(b,{side:`top`,children:n?`Expand diff`:`Collapse diff`})]})},options:{diffStyle:x===`split`?`split`:`unified`,lineDiffType:`none`,overflow:w?`wrap`:`scroll`,theme:xe(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:f(`max-h-[72vh] rounded-md border border-border/70 bg-background/70 p-3 font-mono text-[11px] leading-relaxed text-muted-foreground/90`,w?`overflow-auto whitespace-pre-wrap wrap-break-word`:`overflow-auto`),children:Q.text})]})}):Dt?(0,L.jsx)(de,{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{_e as DiffWorkerPoolProvider,U as default};
98
- //# sourceMappingURL=DiffPanel-DyRCsN-L.js.map
97
+ `;function U({mode:e=`inline`,composerDraftTarget:t,initialGitScope:n,threadRef:r}){let{resolvedTheme:u}=h(),y=le(),[ie]=(0,F.useState)(n),[x,S]=(0,F.useState)(`stacked`),[C,E]=(0,F.useState)(y.wordWrap),[D,O]=(0,F.useState)(y.diffIgnoreWhitespace),[k,_e]=(0,F.useState)(``),[we,Ee]=(0,F.useState)(()=>({scopeKey:null,fileKeys:rt})),He=(0,F.useRef)(null),Ue=r.threadId,I=he(r),qe=I?.projectId??null,Je=me(I&&qe?{environmentId:I.environmentId,projectId:qe}:null),R=I?.worktreePath??Je?.workspaceRoot,z=ae(m.configValueAtom(I?.environmentId??null)),Xe=Ae(I?.environmentId??null,z?.availableEditors??[]),Ze=l(I!=null&&R!=null?De.status({environmentId:I.environmentId,input:{cwd:R}}):null),B=P(e=>fe(e.byThreadKey,r,ie===`unstaged`)),Qe=Ze.data?.isRepo??!0,{turnDiffSummaries:$e,inferredCheckpointTurnCountByTurnId:V}=ue(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=we.scopeKey===Y?we.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:D,cacheScope:q?`turn:${q.turnId}`:null},{enabled:Qe&&q!==void 0}),mt=l(W===null&&I&&R?et.diffPreview({environmentId:I.environmentId,input:{cwd:R,...K?{baseRef:K}:{},ignoreWhitespace:D}}):null),ht=W===null&&mt.error?.includes(`configured workspace root`)===!0&&z?.cwd!==void 0&&z.cwd!==R,gt=l(ht&&I&&z?et.diffPreview({environmentId:I.environmentId,input:{cwd:z.cwd,...K?{baseRef:K}:{},ignoreWhitespace:D}}):null),X=ht?gt:mt,Z=X.data?.sources.find(e=>e.kind===(G===`unstaged`?`working-tree`:`branch-range`)),_t=l(W===null&&G===`branch`&&I&&X.data?.cwd?De.listRefs({environmentId:I.environmentId,input:{cwd:X.data.cwd,includeMatchingRemoteRefs:!0,refKind:`local`,...k.trim().length>0?{query:k.trim()}:{},limit:100}}):null),vt=l(W===null&&G===`branch`&&I&&X.data?.cwd?De.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)(()=>Re(Tt,`diff-panel:${u}`,{compactPartialHunkOffsets:W===null}),[u,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=Fe(e);return{fileDiff:e,filePath:ke(e),fileKey:t,collapsed:ut.has(t)}}),[ut,At]),jt=(0,F.useMemo)(()=>$.map(e=>e.fileKey),[$]),Mt=M(jt,ut),Nt=(0,F.useMemo)(()=>Ne(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=ce({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`&&!a(t)&&console.warn(`Failed to open diff file in editor.`,{operation:`open-diff-file`,environmentId:r.environmentId,threadId:r.threadId,...o(te(t))})})()}})},[R,Pt,Xe,r]),It=(0,F.useCallback)(e=>{Ee(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)(()=>{Ee(e=>{let t=e.scopeKey===Y?e.fileKeys:rt;return{scopeKey:Y,fileKeys:oe(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)(ge,{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)(s,{children:[(0,L.jsxs)(d,{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)(_,{className:`size-3.5 shrink-0 text-muted-foreground`})]}),(0,L.jsxs)(re,{align:`start`,className:`w-60`,children:[(0,L.jsx)(c,{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)(c,{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)(c,{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)(ne,{children:[(0,L.jsx)(ee,{children:`Turn`}),(0,L.jsx)(p,{className:`w-64`,children:U.map(e=>{let t=e.checkpointTurnCount??V[e.turnId]??`?`;return(0,L.jsxs)(c,{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:Be(e.completedAt,y.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)(ye,{className:`size-3.5 shrink-0 opacity-70`}),(0,L.jsxs)(Le,{items:St,filteredItems:Ct,value:K??H,onOpenChange:e=>{e||_e(``)},onValueChange:e=>{e&&Bt(e===H?null:e)},children:[(0,L.jsxs)(Pe,{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)(_,{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)(Oe,{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=>_e(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)(be,{children:`No matching refs.`}),(0,L.jsxs)(Se,{className:`max-h-64 min-w-0 overflow-x-hidden`,children:[(0,L.jsx)(ze,{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)(ze,{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)(Me,{"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)(w,{"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)(Te,{additions:Nt.additions,deletions:Nt.deletions,className:`mr-1 text-[11px]`,layout:`inline`}),$.length>0&&(0,L.jsxs)(b,{children:[(0,L.jsx)(T,{render:(0,L.jsx)(g,{type:`button`,size:`icon-xs`,variant:`outline`,"aria-label":Mt?`Expand all files`:`Collapse all files`,onClick:Lt}),children:Mt?(0,L.jsx)(je,{className:`size-3`}):(0,L.jsx)(Ie,{className:`size-3`})}),(0,L.jsx)(v,{side:`top`,children:Mt?`Expand all files`:`Collapse all files`})]}),(0,L.jsxs)(A,{className:`shrink-0`,variant:`outline`,size:`xs`,value:[x],onValueChange:e=>{let t=e[0];(t===`stacked`||t===`split`)&&S(t)},children:[(0,L.jsx)(se,{"aria-label":`Stacked diff view`,value:`stacked`,children:(0,L.jsx)(j,{className:`size-3`})}),(0,L.jsx)(se,{"aria-label":`Split diff view`,value:`split`,children:(0,L.jsx)(N,{className:`size-3`})})]}),(0,L.jsxs)(b,{children:[(0,L.jsx)(T,{render:(0,L.jsx)(se,{"aria-label":C?`Disable diff line wrapping`:`Enable diff line wrapping`,variant:`outline`,size:`xs`,pressed:C,onPressedChange:e=>{E(!!e)}}),children:(0,L.jsx)(pe,{className:`size-3`})}),(0,L.jsx)(v,{side:`top`,children:C?`Disable line wrapping`:`Enable line wrapping`})]}),(0,L.jsxs)(b,{children:[(0,L.jsx)(T,{render:(0,L.jsx)(se,{"aria-label":D?`Show whitespace changes`:`Hide whitespace changes`,variant:`outline`,size:`xs`,pressed:D,onPressedChange:e=>{O(!!e)}}),children:(0,L.jsx)(We,{className:`size-3`})}),(0,L.jsx)(v,{side:`top`,children:D?`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)(b,{children:[(0,L.jsx)(T,{render:(0,L.jsx)(`button`,{type:`button`,className:f(`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`,ve(e)),"aria-label":n?`Expand ${r}`:`Collapse ${r}`,"aria-expanded":!n,onClick:e=>{e.stopPropagation(),It(t)}}),children:n?(0,L.jsx)(i,{className:`size-4`}):(0,L.jsx)(_,{className:`size-4`})}),(0,L.jsx)(v,{side:`top`,children:n?`Expand diff`:`Collapse diff`})]})},options:{diffStyle:x===`split`?`split`:`unified`,lineDiffType:`none`,overflow:C?`wrap`:`scroll`,theme:xe(u),themeType:u,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:f(`max-h-[72vh] rounded-md border border-border/70 bg-background/70 p-3 font-mono text-[11px] leading-relaxed text-muted-foreground/90`,C?`overflow-auto whitespace-pre-wrap wrap-break-word`:`overflow-auto`),children:Q.text})]})}):Dt?(0,L.jsx)(de,{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{_e as DiffWorkerPoolProvider,U as default};
98
+ //# sourceMappingURL=DiffPanel-Bi93CA_m.js.map