@p4code/cli 0.3.14 → 0.3.16

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
@@ -238,7 +238,7 @@ const make$91 = () => {
238
238
  const layer$82 = Layer.sync(NetService, make$91);
239
239
  //#endregion
240
240
  //#region package.json
241
- var version = "0.3.14";
241
+ var version = "0.3.16";
242
242
  //#endregion
243
243
  //#region src/config.ts
244
244
  /**
@@ -9734,10 +9734,31 @@ const ThreadRenameResult = Schema$1.Struct({
9734
9734
  * whether or not it is addressed elsewhere.
9735
9735
  */
9736
9736
  const ControlTargetThreadId = Schema$1.optional(ThreadId.annotate({ description: "The thread to act on. Omit for this session's own thread. Only threads this session started with thread_spawn can be named here; any other id is refused." }));
9737
+ /**
9738
+ * The model a spawned thread starts on, with the instance made optional.
9739
+ *
9740
+ * `ModelSelection` requires `instanceId`, and that is right where a selection
9741
+ * is stored - a thread runs on one configured provider instance and nothing
9742
+ * else. It is the wrong requirement at the point of spawning: an agent handing
9743
+ * work to a new thread knows the model it wants that work done on, and has no
9744
+ * way to discover which of this machine's instances serves it. Omitting the id
9745
+ * means "the instance this thread is already running on", which is the answer
9746
+ * whenever the spawn is a split of the caller's own work - and naming one is
9747
+ * still there for the spawn that crosses providers.
9748
+ *
9749
+ * The resolution is the handler's, not this schema's: only the server can read
9750
+ * the calling thread to find the instance to fall back to.
9751
+ */
9752
+ const ThreadSpawnModelSelection = Schema$1.Struct({
9753
+ model: TrimmedNonEmptyString.annotate({ description: "Model id to run the new thread on, as the provider names it." }),
9754
+ instanceId: Schema$1.optional(ProviderInstanceId.annotate({ description: "Configured provider instance to run the model on. Defaults to the instance this session's own thread runs on, so a model on the same provider needs no id." })),
9755
+ options: Schema$1.optional(ProviderOptionSelections.annotate({ description: "Provider option selections for the new thread, such as reasoning effort or context window. Omitted means no options rather than this thread's, because an option that suits one model rarely suits another." }))
9756
+ });
9737
9757
  const ThreadSpawnInput = Schema$1.Struct({
9738
9758
  title: TrimmedNonEmptyString.annotate({ description: "Title for the new thread. Shown on the board and in the sidebar." }),
9739
9759
  prompt: TrimmedNonEmptyString.annotate({ description: "The first message to send. The thread starts its turn immediately, so this is the whole brief the new agent gets." }),
9740
9760
  projectId: Schema$1.optional(ProjectId.annotate({ description: "Project to start the thread in. Defaults to this session's own project." })),
9761
+ modelSelection: Schema$1.optional(ThreadSpawnModelSelection.annotate({ description: "Model the new thread runs on, in force for its first turn. Defaults to this session's own model, options included." })),
9741
9762
  runtimeMode: Schema$1.optional(RuntimeMode.annotate({ description: "Permission mode for the new thread. Defaults to this session's own." })),
9742
9763
  interactionMode: Schema$1.optional(ProviderInteractionMode),
9743
9764
  compressMode: Schema$1.optional(CompressMode),
@@ -16403,6 +16424,39 @@ function asTrimmedString$1(value) {
16403
16424
  const trimmed = value.trim();
16404
16425
  return trimmed.length > 0 ? trimmed : null;
16405
16426
  }
16427
+ const MCP_TOOL_ACTIVITY_DATA_CHARACTER_LIMIT = 64 * 1024;
16428
+ const MCP_TOOL_ACTIVITY_FIELD_CHARACTER_LIMIT = 1024;
16429
+ const MCP_TOOL_ACTIVITY_FIELD_LIMIT = 24;
16430
+ function serializedCharacterLength(value) {
16431
+ try {
16432
+ return JSON.stringify(value)?.length ?? 0;
16433
+ } catch {
16434
+ return null;
16435
+ }
16436
+ }
16437
+ function compactMcpField(value) {
16438
+ const originalCharacters = serializedCharacterLength(value);
16439
+ if (originalCharacters !== null && originalCharacters <= MCP_TOOL_ACTIVITY_FIELD_CHARACTER_LIMIT) return value;
16440
+ return {
16441
+ truncated: true,
16442
+ ...originalCharacters === null ? {} : { originalCharacters }
16443
+ };
16444
+ }
16445
+ function compactMcpRecord(record) {
16446
+ const entries = Object.entries(record);
16447
+ const projected = {};
16448
+ for (const [key, value] of entries.slice(0, MCP_TOOL_ACTIVITY_FIELD_LIMIT)) {
16449
+ const nestedItem = key === "item" ? asRecord$6(value) : null;
16450
+ projected[key] = nestedItem === null ? compactMcpField(value) : compactMcpRecord(nestedItem);
16451
+ }
16452
+ if (entries.length > MCP_TOOL_ACTIVITY_FIELD_LIMIT) projected.truncatedFields = entries.length - MCP_TOOL_ACTIVITY_FIELD_LIMIT;
16453
+ return projected;
16454
+ }
16455
+ function projectMcpToolCallData(data) {
16456
+ const characters = serializedCharacterLength(data);
16457
+ if (characters !== null && characters <= 65536) return data;
16458
+ return compactMcpRecord(data);
16459
+ }
16406
16460
  function pushChangedFile(target, seen, value) {
16407
16461
  const normalized = asTrimmedString$1(value);
16408
16462
  if (!normalized || seen.has(normalized)) return;
@@ -16491,7 +16545,18 @@ function projectRawOutput(value) {
16491
16545
  function projectActivityPayload(activity) {
16492
16546
  const payload = asRecord$6(activity.payload);
16493
16547
  const data = asRecord$6(payload?.data);
16494
- if (!payload || !data || payload.itemType === "mcp_tool_call") return activity;
16548
+ if (!payload || !data) return activity;
16549
+ if (payload.itemType === "mcp_tool_call") {
16550
+ const projectedMcpData = projectMcpToolCallData(data);
16551
+ if (projectedMcpData === data) return activity;
16552
+ return {
16553
+ ...activity,
16554
+ payload: {
16555
+ ...payload,
16556
+ data: projectedMcpData
16557
+ }
16558
+ };
16559
+ }
16495
16560
  const projectedData = {};
16496
16561
  const item = projectCommandData(data);
16497
16562
  if (item) projectedData.item = item;
@@ -16584,19 +16649,21 @@ function projectActivityEvent(event) {
16584
16649
  };
16585
16650
  }
16586
16651
  const HISTORICAL_ACTIVITY_COMPACTION_BATCH_BYTE_LIMIT = 8 * 1024 * 1024;
16587
- const JOB_NAME = "tool-activity-payload-v1";
16652
+ const TOOL_ACTIVITY_JOB_NAME = "tool-activity-payload-v1";
16653
+ const MCP_TOOL_ACTIVITY_JOB_NAME = "mcp-tool-activity-payload-v1";
16588
16654
  const SCHEMA_TRANSFORM_FAILURE_REASON = "schema-transform-failed";
16589
16655
  const decodeActivityEventPayload = Schema$1.decodeUnknownEffect(Schema$1.fromJsonString(ThreadActivityAppendedPayload$1));
16590
16656
  const encodeActivityEventPayload = Schema$1.encodeEffect(Schema$1.fromJsonString(ThreadActivityAppendedPayload$1));
16591
16657
  const encodeUnknownJson = Schema$1.encodeEffect(Schema$1.fromJsonString(Schema$1.Unknown));
16592
- const runHistoricalActivityCompaction = Effect.fn("runHistoricalActivityCompaction")(function* () {
16658
+ const runHistoricalActivityCompactionJob = Effect.fn("runHistoricalActivityCompactionJob")(function* (job) {
16593
16659
  const sql = yield* SqlClient.SqlClient;
16660
+ const oversizedMcpOnly = job.oversizedMcpOnly ? 1 : 0;
16594
16661
  const progress = (yield* sql`
16595
16662
  SELECT
16596
16663
  cursor_sequence AS "cursorSequence",
16597
16664
  completed_at AS "completedAt"
16598
16665
  FROM historical_activity_compaction_progress
16599
- WHERE job_name = ${JOB_NAME}
16666
+ WHERE job_name = ${job.jobName}
16600
16667
  `)[0];
16601
16668
  if (progress?.completedAt !== null && progress?.completedAt !== void 0) return {
16602
16669
  batches: 0,
@@ -16632,6 +16699,14 @@ const runHistoricalActivityCompaction = Effect.fn("runHistoricalActivityCompacti
16632
16699
  WHERE sequence > ${cursor}
16633
16700
  AND event_type = 'thread.activity-appended'
16634
16701
  AND CASE
16702
+ WHEN ${oversizedMcpOnly} = 1 THEN CASE
16703
+ WHEN json_valid(payload_json) = 0 THEN 0
16704
+ WHEN json_type(payload_json, '$.activity.payload.data') = 'object'
16705
+ AND json_extract(payload_json, '$.activity.payload.itemType') = 'mcp_tool_call'
16706
+ AND length(payload_json) > ${MCP_TOOL_ACTIVITY_DATA_CHARACTER_LIMIT}
16707
+ THEN 1
16708
+ ELSE 0
16709
+ END
16635
16710
  WHEN json_valid(payload_json) = 0 THEN 1
16636
16711
  WHEN json_type(payload_json, '$.activity.payload.data') = 'object'
16637
16712
  AND COALESCE(
@@ -16670,7 +16745,7 @@ const runHistoricalActivityCompaction = Effect.fn("runHistoricalActivityCompacti
16670
16745
  job_name,
16671
16746
  cursor_sequence,
16672
16747
  completed_at
16673
- ) VALUES (${JOB_NAME}, ${cursor}, datetime('now'))
16748
+ ) VALUES (${job.jobName}, ${cursor}, datetime('now'))
16674
16749
  ON CONFLICT(job_name) DO UPDATE SET
16675
16750
  cursor_sequence = excluded.cursor_sequence,
16676
16751
  completed_at = excluded.completed_at
@@ -16744,7 +16819,7 @@ const runHistoricalActivityCompaction = Effect.fn("runHistoricalActivityCompacti
16744
16819
  job_name,
16745
16820
  cursor_sequence,
16746
16821
  completed_at
16747
- ) VALUES (${JOB_NAME}, ${nextCursor}, NULL)
16822
+ ) VALUES (${job.jobName}, ${nextCursor}, NULL)
16748
16823
  ON CONFLICT(job_name) DO UPDATE SET
16749
16824
  cursor_sequence = excluded.cursor_sequence,
16750
16825
  completed_at = NULL
@@ -16770,6 +16845,21 @@ const runHistoricalActivityCompaction = Effect.fn("runHistoricalActivityCompacti
16770
16845
  skippedEvents
16771
16846
  };
16772
16847
  });
16848
+ const runHistoricalActivityCompaction = Effect.fn("runHistoricalActivityCompaction")(function* () {
16849
+ const toolActivityResult = yield* runHistoricalActivityCompactionJob({
16850
+ jobName: TOOL_ACTIVITY_JOB_NAME,
16851
+ oversizedMcpOnly: false
16852
+ });
16853
+ const mcpToolActivityResult = yield* runHistoricalActivityCompactionJob({
16854
+ jobName: MCP_TOOL_ACTIVITY_JOB_NAME,
16855
+ oversizedMcpOnly: true
16856
+ });
16857
+ return {
16858
+ batches: toolActivityResult.batches + mcpToolActivityResult.batches,
16859
+ processedEvents: toolActivityResult.processedEvents + mcpToolActivityResult.processedEvents,
16860
+ skippedEvents: toolActivityResult.skippedEvents + mcpToolActivityResult.skippedEvents
16861
+ };
16862
+ });
16773
16863
  //#endregion
16774
16864
  //#region src/persistence/Layers/Sqlite.ts
16775
16865
  const defaultSqliteClientLoaders = {
@@ -90866,13 +90956,19 @@ const COLLAB_TERMINAL_STATUSES = {
90866
90956
  shutdown: "stopped",
90867
90957
  notFound: "stopped"
90868
90958
  };
90869
- function collabTaskEvents(event, canonicalThreadId, item) {
90959
+ function collabTaskEventBase(base, taskId, phase) {
90960
+ return {
90961
+ ...base,
90962
+ eventId: EventId.make(`${base.eventId}:subagent:${taskId}:${phase}`)
90963
+ };
90964
+ }
90965
+ function collabTaskEvents(event, canonicalThreadId, item, defaults) {
90870
90966
  const base = runtimeEventBase(event, canonicalThreadId);
90871
90967
  if (item.type === "subAgentActivity") {
90872
90968
  const taskId = RuntimeTaskId.make(item.agentThreadId);
90873
90969
  const name = agentNameFromPath(item.agentPath);
90874
90970
  if (item.kind === "started") return [{
90875
- ...base,
90971
+ ...collabTaskEventBase(base, taskId, "started"),
90876
90972
  type: "task.started",
90877
90973
  payload: {
90878
90974
  taskId,
@@ -90883,7 +90979,7 @@ function collabTaskEvents(event, canonicalThreadId, item) {
90883
90979
  }
90884
90980
  }];
90885
90981
  if (item.kind === "interrupted") return [{
90886
- ...base,
90982
+ ...collabTaskEventBase(base, taskId, "completed"),
90887
90983
  type: "task.completed",
90888
90984
  payload: {
90889
90985
  taskId,
@@ -90891,7 +90987,7 @@ function collabTaskEvents(event, canonicalThreadId, item) {
90891
90987
  }
90892
90988
  }];
90893
90989
  return [{
90894
- ...base,
90990
+ ...collabTaskEventBase(base, taskId, "progress"),
90895
90991
  type: "task.progress",
90896
90992
  payload: {
90897
90993
  taskId,
@@ -90902,11 +90998,11 @@ function collabTaskEvents(event, canonicalThreadId, item) {
90902
90998
  if (item.type !== "collabAgentToolCall") return [];
90903
90999
  const events = [];
90904
91000
  const prompt = trimText$1(item.prompt);
90905
- const model = trimText$1(item.model);
90906
- const reasoningEffort = trimText$1(item.reasoningEffort);
91001
+ const model = trimText$1(item.model) ?? trimText$1(defaults?.model);
91002
+ const reasoningEffort = trimText$1(item.reasoningEffort) ?? trimText$1(defaults?.reasoningEffort);
90907
91003
  if (item.tool === "spawnAgent") for (const receiverThreadId of item.receiverThreadIds) {
90908
91004
  events.push({
90909
- ...base,
91005
+ ...collabTaskEventBase(base, RuntimeTaskId.make(receiverThreadId), "started"),
90910
91006
  type: "task.started",
90911
91007
  payload: {
90912
91008
  taskId: RuntimeTaskId.make(receiverThreadId),
@@ -90915,8 +91011,8 @@ function collabTaskEvents(event, canonicalThreadId, item) {
90915
91011
  ...reasoningEffort ? { reasoningEffort } : {}
90916
91012
  }
90917
91013
  });
90918
- if (!(receiverThreadId in item.agentsStates)) events.push({
90919
- ...base,
91014
+ events.push({
91015
+ ...collabTaskEventBase(base, RuntimeTaskId.make(receiverThreadId), "progress"),
90920
91016
  type: "task.progress",
90921
91017
  payload: {
90922
91018
  taskId: RuntimeTaskId.make(receiverThreadId),
@@ -90930,7 +91026,7 @@ function collabTaskEvents(event, canonicalThreadId, item) {
90930
91026
  const terminalStatus = COLLAB_TERMINAL_STATUSES[state.status];
90931
91027
  if (terminalStatus) {
90932
91028
  events.push({
90933
- ...base,
91029
+ ...collabTaskEventBase(base, taskId, "completed"),
90934
91030
  type: "task.completed",
90935
91031
  payload: {
90936
91032
  taskId,
@@ -90940,8 +91036,9 @@ function collabTaskEvents(event, canonicalThreadId, item) {
90940
91036
  });
90941
91037
  continue;
90942
91038
  }
91039
+ if (item.tool === "spawnAgent" && !message) continue;
90943
91040
  events.push({
90944
- ...base,
91041
+ ...collabTaskEventBase(base, taskId, "progress"),
90945
91042
  type: "task.progress",
90946
91043
  payload: {
90947
91044
  taskId,
@@ -91125,7 +91222,7 @@ function mapItemLifecycle(event, canonicalThreadId, lifecycle) {
91125
91222
  }
91126
91223
  };
91127
91224
  }
91128
- function mapToRuntimeEvents(event, canonicalThreadId) {
91225
+ function mapToRuntimeEvents(event, canonicalThreadId, collabDefaults) {
91129
91226
  if (event.kind === "error") {
91130
91227
  if (!event.message) return [];
91131
91228
  return [{
@@ -91319,7 +91416,7 @@ function mapToRuntimeEvents(event, canonicalThreadId) {
91319
91416
  if (event.method === "item/started") {
91320
91417
  const started = mapItemLifecycle(event, canonicalThreadId, "item.started");
91321
91418
  const item = readPayload(V2ItemStartedNotification, event.payload)?.item;
91322
- const taskEvents = item ? collabTaskEvents(event, canonicalThreadId, item) : [];
91419
+ const taskEvents = item ? collabTaskEvents(event, canonicalThreadId, item, collabDefaults) : [];
91323
91420
  return started ? [started, ...taskEvents] : taskEvents;
91324
91421
  }
91325
91422
  if (event.method === "item/completed") {
@@ -91336,7 +91433,7 @@ function mapToRuntimeEvents(event, canonicalThreadId) {
91336
91433
  }];
91337
91434
  }
91338
91435
  const completed = mapItemLifecycle(event, canonicalThreadId, "item.completed");
91339
- const taskEvents = collabTaskEvents(event, canonicalThreadId, item);
91436
+ const taskEvents = collabTaskEvents(event, canonicalThreadId, item, collabDefaults);
91340
91437
  return completed ? [completed, ...taskEvents] : taskEvents;
91341
91438
  }
91342
91439
  if (event.method === "item/reasoning/summaryPartAdded" || event.method === "item/commandExecution/terminalInteraction") return [{
@@ -91708,9 +91805,13 @@ const makeCodexAdapter = Effect.fn("makeCodexAdapter")(function* (codexConfig, o
91708
91805
  detail: cause.message,
91709
91806
  cause
91710
91807
  })));
91808
+ const collabDefaults = {
91809
+ model: input.modelSelection?.instanceId === boundInstanceId ? input.modelSelection.model : void 0,
91810
+ reasoningEffort: input.modelSelection?.instanceId === boundInstanceId ? getModelSelectionStringOptionValue(input.modelSelection, "reasoningEffort") : void 0
91811
+ };
91711
91812
  const eventFiber = yield* Stream.runForEach(runtime.events, (event) => Effect.gen(function* () {
91712
91813
  yield* writeNativeEvent(event);
91713
- const runtimeEvents = mapToRuntimeEvents(event, event.threadId);
91814
+ const runtimeEvents = mapToRuntimeEvents(event, event.threadId, collabDefaults);
91714
91815
  if (runtimeEvents.length === 0) {
91715
91816
  yield* Effect.logDebug("ignoring unhandled Codex provider event", {
91716
91817
  method: event.method,
@@ -91733,6 +91834,7 @@ const makeCodexAdapter = Effect.fn("makeCodexAdapter")(function* (codexConfig, o
91733
91834
  scope: sessionScope,
91734
91835
  runtime,
91735
91836
  eventFiber,
91837
+ collabDefaults,
91736
91838
  stopped: false
91737
91839
  });
91738
91840
  sessionScopeTransferred = true;
@@ -91764,6 +91866,10 @@ const makeCodexAdapter = Effect.fn("makeCodexAdapter")(function* (codexConfig, o
91764
91866
  const session = yield* requireSession(input.threadId);
91765
91867
  const reasoningEffort = input.modelSelection?.instanceId === boundInstanceId ? getModelSelectionStringOptionValue(input.modelSelection, "reasoningEffort") : void 0;
91766
91868
  const serviceTier = input.modelSelection?.instanceId === boundInstanceId ? getCodexServiceTierOptionValue(input.modelSelection) : void 0;
91869
+ if (input.modelSelection?.instanceId === boundInstanceId) {
91870
+ session.collabDefaults.model = input.modelSelection.model;
91871
+ session.collabDefaults.reasoningEffort = reasoningEffort;
91872
+ }
91767
91873
  return yield* session.runtime.sendTurn({
91768
91874
  ...input.input !== void 0 ? { input: input.input } : {},
91769
91875
  ...input.modelSelection?.instanceId === boundInstanceId ? { model: input.modelSelection.model } : {},
@@ -104565,7 +104671,7 @@ const AskUserQuestionTool = Tool.make("ask_user_question", {
104565
104671
  ]
104566
104672
  }).annotate(Tool.Title, "Ask user question").annotate(Tool.Readonly, false).annotate(Tool.Destructive, false).annotate(Tool.Idempotent, false);
104567
104673
  const ThreadSpawnTool = Tool.make("thread_spawn", {
104568
- description: "Start a new agent thread and send it a first message, then return its id. Use it to hand a piece of work to a fresh thread - a subtask you just planned, a job that wants its own transcript. Set fusionWatcher true for a Fusion watcher; the server then requires explicit user approval before creating anything. The new thread inherits this one's project, model and permission mode unless you say otherwise, and can then be watched with thread_watch_events and adjusted with thread_configure. A thread that was itself started this way cannot start another.",
104674
+ description: "Start a new agent thread and send it a first message, then return its id. Use it to hand a piece of work to a fresh thread - a subtask you just planned, a job that wants its own transcript. Set fusionWatcher true for a Fusion watcher; the server then requires explicit user approval before creating anything. The new thread inherits this one's project, model, permission mode, interaction mode, compression and subagent policy, and every one of those can be set here instead - what you set is already in force for the first turn, so a thread never has to be corrected after it starts. Set modelSelection to run it on another model: give the model id, and leave instanceId out to keep this thread's provider instance. Once started it can be watched with thread_watch_events and changed later with thread_configure. A thread that was itself started this way cannot start another.",
104569
104675
  parameters: ThreadSpawnInput,
104570
104676
  success: ThreadSpawnResult,
104571
104677
  failure: ThreadControlToolError,
@@ -104756,6 +104862,22 @@ const requireFusionApproval = Effect.fn("mcp.threads.requireFusionApproval")(fun
104756
104862
  if (latestUser !== void 0 && fusionAffirmativeLine.test(lastNonEmptyLine(latestUser.text)) && asksForFusionApproval(precedingAssistant)) return;
104757
104863
  return yield* new ThreadPairApprovalRequiredError({ threadId });
104758
104864
  });
104865
+ /**
104866
+ * The model a spawned thread starts on.
104867
+ *
104868
+ * No selection at all inherits the caller's whole one, which is what keeps a
104869
+ * split of the caller's work running the way the caller runs. A named model
104870
+ * with no instance keeps the caller's instance instead of guessing at one: the
104871
+ * agent knows the model it wants the work done on and has no way to see which
104872
+ * of this machine's configured instances serves it. Options are taken only
104873
+ * from the request, because an effort or context-window choice made for one
104874
+ * model is rarely the right one for another.
104875
+ */
104876
+ const resolveSpawnModelSelection = (requested, inherited) => requested === void 0 ? inherited : {
104877
+ instanceId: requested.instanceId ?? inherited.instanceId,
104878
+ model: requested.model,
104879
+ ...requested.options !== void 0 ? { options: requested.options } : {}
104880
+ };
104759
104881
  const ThreadToolkitHandlersLive = ThreadToolkit.toLayer({
104760
104882
  ask_user_question: (input) => Effect.gen(function* () {
104761
104883
  const invocation = yield* requireThreadCapability();
@@ -104821,6 +104943,7 @@ const ThreadToolkitHandlersLive = ThreadToolkit.toLayer({
104821
104943
  });
104822
104944
  const template = parent.value;
104823
104945
  const projectId = input.projectId ?? template.projectId;
104946
+ const modelSelection = resolveSpawnModelSelection(input.modelSelection, template.modelSelection);
104824
104947
  const runtimeMode = input.runtimeMode ?? template.runtimeMode;
104825
104948
  const interactionMode = input.interactionMode ?? template.interactionMode;
104826
104949
  const compressMode = input.compressMode ?? template.compressMode;
@@ -104833,7 +104956,7 @@ const ThreadToolkitHandlersLive = ThreadToolkit.toLayer({
104833
104956
  threadId,
104834
104957
  projectId,
104835
104958
  title: input.title,
104836
- modelSelection: template.modelSelection,
104959
+ modelSelection,
104837
104960
  runtimeMode,
104838
104961
  interactionMode,
104839
104962
  compressMode,
@@ -104856,7 +104979,7 @@ const ThreadToolkitHandlersLive = ThreadToolkit.toLayer({
104856
104979
  text: input.prompt,
104857
104980
  attachments: []
104858
104981
  },
104859
- modelSelection: template.modelSelection,
104982
+ modelSelection,
104860
104983
  titleSeed: input.title,
104861
104984
  runtimeMode,
104862
104985
  interactionMode,
@@ -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,Dl as a,Dr as o,Ea as s,Et as c,Fa as l,Ll as ee,Ma as te,Ml as ne,Na as u,Nr as re,Pa as d,Qc as ie,Sr as f,Ta as p,Xc as m,Zc as h,_n as g,gl as _,gt as v,h as y,ht as b,ja as x,ot as S,ou as C,va as w,vt as T,x as ae,xa as E,xl as D,xn as O}from"./previewAssetResource-X_ZJUi3_.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-C20FLf9y.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,Sr as ge,Y as _e,_ as ve,at as ye,ci as be,cr as xe,ct as Se,dr as Ce,fr as we,gr as Te,h as Ee,it as De,jr as Oe,lr as ke,lt as Ae,mr as je,oi as Me,or as Ne,ot as Pe,pr as Fe,rt as Ie,si as Le,sr as Re,st as ze,ur as Be,zr as Ve}from"./index-BjqFn_84.js";import{a as He,n as Ue}from"./fileCommentAnnotations-D0qxrhmU.js";var We=i(`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?y(t,n):t)}var I=r();function Ke(e,t){let n=(0,I.c)(4),r=Te(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:ee}=e,te=f(Qe),ne=f(B),u;t[0]===a?u=t[1]:(u=e=>e.getComposerDraft(a)?.reviewComments??qe,t[0]=a,t[1]=u);let d=f(u),[ie,p]=(0,F.useState)(null),[m,h]=(0,F.useState)(null),g;t[2]===n?g=t[3]:(g=new Map(n.map(Ze)),t[2]=n,t[3]=g);let _=g,v;if(t[4]!==m||t[5]!==n||t[6]!==d||t[7]!==r){let e;t[9]!==m||t[10]!==d||t[11]!==r?(e=e=>{let{fileDiff:t,filePath:n,fileKey:i,collapsed:a}=e,o=d.filter(e=>e.sectionId===r&&e.filePath===n&&(e.fenceLanguage??`diff`)===`diff`).reduce((e,n)=>{let r=re(t,n);return r?R(e,r,{id:n.id,kind:`comment`,range:r,rangeLabel:n.rangeLabel,text:n.text}):e},[]),s=m?.fileKey===i?[...o,m.annotation]:o;return{id:i,type:`diff`,fileDiff:t,annotations:s,collapsed:a,version:De(`${a?`1`:`0`}:${s.flatMap(z).join(`:`)}`)}},t[9]=m,t[10]=d,t[11]=r,t[12]=e):e=t[12],v=n.map(e),t[4]=m,t[5]=n,t[6]=d,t[7]=r,t[8]=v}else v=t[8];let y=v,b;t[13]!==a||t[14]!==m?.annotation||t[15]!==ne?(b=e=>{p(null),m?.annotation.metadata.entries.some(t=>t.id===e)?h(null):ne(a,e)},t[13]=a,t[14]=m?.annotation,t[15]=ne,t[16]=b):b=t[16];let x=b,S;t[17]!==te||t[18]!==a||t[19]!==m||t[20]!==_||t[21]!==r||t[22]!==i?(S=(e,t)=>{let n=m?.annotation.metadata.entries.find(t=>t.id===e),s=m?_.get(m.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&&te(a,c),p(null),h(null)},t[17]=te,t[18]=a,t[19]=m,t[20]=_,t[21]=r,t[22]=i,t[23]=S):S=t[23];let C=S,w;t[24]!==_||t[25]!==r||t[26]!==i?(w=(e,t)=>{if(!e)return;let n=t.item;if(n.type!==`diff`)return;let a=_.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&&h({fileKey:n.id,annotation:{side:Je(e),lineNumber:e.end,metadata:{entries:[{id:s,kind:`draft`,range:e,rangeLabel:c.rangeLabel,text:``}]}}})},t[24]=_,t[25]=r,t[26]=i,t[27]=w):w=t[27];let T=w,ae=m!==null,E;t[28]===c?E=t[29]:(E=c?{ref:c}:{},t[28]=c,t[29]=E);let D;t[30]===l?D=t[31]:(D=l?{className:l}:{},t[30]=l,t[31]=D);let O=!ae,oe=!ae,A;t[32]!==T||t[33]!==s||t[34]!==oe||t[35]!==O?(A={...s,enableGutterUtility:O,enableLineSelection:oe,onLineSelectionEnd:T},t[32]=T,t[33]=s,t[34]=oe,t[35]=O,t[36]=A):A=t[36];let j;t[37]===ee?j=t[38]:(j=e=>e.type===`diff`?ee(e.fileDiff,e.id,e.collapsed===!0):null,t[37]=ee,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]!==y||t[43]!==ie||t[44]!==A||t[45]!==j||t[46]!==M||t[47]!==E||t[48]!==D?(N=(0,L.jsx)(k,{...E,...D,items:y,selectedLines:ie,onSelectedLinesChange:p,options:A,renderHeaderPrefix:j,renderAnnotation:M}),t[42]=y,t[43]=ie,t[44]=A,t[45]=j,t[46]=M,t[47]=E,t[48]=D,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:D(e,{label:`environment-data:review:diff-preview`,tag:C.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,Dl as a,Dr as o,Ea as s,Et as c,Fa as l,Ll as ee,Ma as te,Ml as ne,Na as u,Nr as re,Pa as d,Qc as ie,Sr as f,Ta as p,Xc as m,Zc as h,_n as g,gl as _,gt as v,h as y,ht as b,ja as x,ot as S,ou as C,va as w,vt as T,x as ae,xa as E,xl as D,xn as O}from"./previewAssetResource-Dpr4tPSe.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-yQrflbtL.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,Sr as ge,Y as _e,_ as ve,at as ye,ci as be,cr as xe,ct as Se,dr as Ce,fr as we,gr as Te,h as Ee,it as De,jr as Oe,lr as ke,lt as Ae,mr as je,oi as Me,or as Ne,ot as Pe,pr as Fe,rt as Ie,si as Le,sr as Re,st as ze,ur as Be,zr as Ve}from"./index-H-f1YHA3.js";import{a as He,n as Ue}from"./fileCommentAnnotations-C-n_jPm-.js";var We=i(`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?y(t,n):t)}var I=r();function Ke(e,t){let n=(0,I.c)(4),r=Te(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:ee}=e,te=f(Qe),ne=f(B),u;t[0]===a?u=t[1]:(u=e=>e.getComposerDraft(a)?.reviewComments??qe,t[0]=a,t[1]=u);let d=f(u),[ie,p]=(0,F.useState)(null),[m,h]=(0,F.useState)(null),g;t[2]===n?g=t[3]:(g=new Map(n.map(Ze)),t[2]=n,t[3]=g);let _=g,v;if(t[4]!==m||t[5]!==n||t[6]!==d||t[7]!==r){let e;t[9]!==m||t[10]!==d||t[11]!==r?(e=e=>{let{fileDiff:t,filePath:n,fileKey:i,collapsed:a}=e,o=d.filter(e=>e.sectionId===r&&e.filePath===n&&(e.fenceLanguage??`diff`)===`diff`).reduce((e,n)=>{let r=re(t,n);return r?R(e,r,{id:n.id,kind:`comment`,range:r,rangeLabel:n.rangeLabel,text:n.text}):e},[]),s=m?.fileKey===i?[...o,m.annotation]:o;return{id:i,type:`diff`,fileDiff:t,annotations:s,collapsed:a,version:De(`${a?`1`:`0`}:${s.flatMap(z).join(`:`)}`)}},t[9]=m,t[10]=d,t[11]=r,t[12]=e):e=t[12],v=n.map(e),t[4]=m,t[5]=n,t[6]=d,t[7]=r,t[8]=v}else v=t[8];let y=v,b;t[13]!==a||t[14]!==m?.annotation||t[15]!==ne?(b=e=>{p(null),m?.annotation.metadata.entries.some(t=>t.id===e)?h(null):ne(a,e)},t[13]=a,t[14]=m?.annotation,t[15]=ne,t[16]=b):b=t[16];let x=b,S;t[17]!==te||t[18]!==a||t[19]!==m||t[20]!==_||t[21]!==r||t[22]!==i?(S=(e,t)=>{let n=m?.annotation.metadata.entries.find(t=>t.id===e),s=m?_.get(m.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&&te(a,c),p(null),h(null)},t[17]=te,t[18]=a,t[19]=m,t[20]=_,t[21]=r,t[22]=i,t[23]=S):S=t[23];let C=S,w;t[24]!==_||t[25]!==r||t[26]!==i?(w=(e,t)=>{if(!e)return;let n=t.item;if(n.type!==`diff`)return;let a=_.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&&h({fileKey:n.id,annotation:{side:Je(e),lineNumber:e.end,metadata:{entries:[{id:s,kind:`draft`,range:e,rangeLabel:c.rangeLabel,text:``}]}}})},t[24]=_,t[25]=r,t[26]=i,t[27]=w):w=t[27];let T=w,ae=m!==null,E;t[28]===c?E=t[29]:(E=c?{ref:c}:{},t[28]=c,t[29]=E);let D;t[30]===l?D=t[31]:(D=l?{className:l}:{},t[30]=l,t[31]=D);let O=!ae,oe=!ae,A;t[32]!==T||t[33]!==s||t[34]!==oe||t[35]!==O?(A={...s,enableGutterUtility:O,enableLineSelection:oe,onLineSelectionEnd:T},t[32]=T,t[33]=s,t[34]=oe,t[35]=O,t[36]=A):A=t[36];let j;t[37]===ee?j=t[38]:(j=e=>e.type===`diff`?ee(e.fileDiff,e.id,e.collapsed===!0):null,t[37]=ee,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]!==y||t[43]!==ie||t[44]!==A||t[45]!==j||t[46]!==M||t[47]!==E||t[48]!==D?(N=(0,L.jsx)(k,{...E,...D,items:y,selectedLines:ie,onSelectedLinesChange:p,options:A,renderHeaderPrefix:j,renderAnnotation:M}),t[42]=y,t[43]=ie,t[44]=A,t[45]=j,t[46]=M,t[47]=E,t[48]=D,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:D(e,{label:`environment-data:review:diff-preview`,tag:C.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],
@@ -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:i}=ae(),o=le(),[re]=(0,F.useState)(n),[f,y]=(0,F.useState)(`stacked`),[S,C]=(0,F.useState)(o.wordWrap),[D,O]=(0,F.useState)(o.diffIgnoreWhitespace),[k,ve]=(0,F.useState)(``),[Te,De]=(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=_(g.configValueAtom(I?.environmentId??null)),Xe=je(I?.environmentId??null,z?.availableEditors??[]),Ze=c(I!=null&&R!=null?Oe.status({environmentId:I.environmentId,input:{cwd:R}}):null),B=P(e=>fe(e.byThreadKey,r,re===`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=Te.scopeKey===Y?Te.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?Oe.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?Oe.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)(()=>ze(Tt,`diff-panel:${i}`,{compactPartialHunkOffsets:W===null}),[i,Tt,W]),At=(0,F.useMemo)(()=>!Q||Q.kind!==`files`?[]:Q.files.toSorted((e,t)=>Ae(e).localeCompare(Ae(t),void 0,{numeric:!0,sensitivity:`base`})),[Q]),$=(0,F.useMemo)(()=>At.map(e=>{let t=Ie(e);return{fileDiff:e,filePath:Ae(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)(()=>Pe(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,...ee(ne(t))})})()}})},[R,Pt,Xe,r]),It=(0,F.useCallback)(e=>{De(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)(()=>{De(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)(_e,{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)(E,{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)(h,{className:`size-3.5 shrink-0 text-muted-foreground`})]}),(0,L.jsxs)(s,{align:`start`,className:`w-60`,children:[(0,L.jsx)(p,{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)(p,{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)(p,{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)(x,{children:[(0,L.jsx)(u,{children:`Turn`}),(0,L.jsx)(te,{className:`w-64`,children:U.map(e=>{let t=e.checkpointTurnCount??V[e.turnId]??`?`;return(0,L.jsxs)(p,{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:ge(e.completedAt,o.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)(be,{className:`size-3.5 shrink-0 opacity-70`}),(0,L.jsxs)(Re,{items:St,filteredItems:Ct,value:K??H,onOpenChange:e=>{e||ve(``)},onValueChange:e=>{e&&Bt(e===H?null:e)},children:[(0,L.jsxs)(Fe,{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)(h,{className:`size-3.5 shrink-0 opacity-70`})]}),(0,L.jsxs)(we,{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)(ke,{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=>ve(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)(xe,{children:`No matching refs.`}),(0,L.jsxs)(Ce,{className:`max-h-64 min-w-0 overflow-x-hidden`,children:[(0,L.jsx)(Be,{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)(Be,{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)(Ne,{"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)(ie,{"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)(Ee,{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)(w,{type:`button`,size:`icon-xs`,variant:`outline`,"aria-label":Mt?`Expand all files`:`Collapse all files`,onClick:Lt}),children:Mt?(0,L.jsx)(Me,{className:`size-3`}):(0,L.jsx)(Le,{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:[f],onValueChange:e=>{let t=e[0];(t===`stacked`||t===`split`)&&y(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":S?`Disable diff line wrapping`:`Enable diff line wrapping`,variant:`outline`,size:`xs`,pressed:S,onPressedChange:e=>{C(!!e)}}),children:(0,L.jsx)(pe,{className:`size-3`})}),(0,L.jsx)(v,{side:`top`,children:S?`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=Ae(e);return(0,L.jsxs)(b,{children:[(0,L.jsx)(T,{render:(0,L.jsx)(`button`,{type:`button`,className:l(`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`,ye(e)),"aria-label":n?`Expand ${r}`:`Collapse ${r}`,"aria-expanded":!n,onClick:e=>{e.stopPropagation(),It(t)}}),children:n?(0,L.jsx)(m,{className:`size-4`}):(0,L.jsx)(h,{className:`size-4`})}),(0,L.jsx)(v,{side:`top`,children:n?`Expand diff`:`Collapse diff`})]})},options:{diffStyle:f===`split`?`split`:`unified`,lineDiffType:`none`,overflow:S?`wrap`:`scroll`,theme:Se(i),themeType:i,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:l(`max-h-[72vh] rounded-md border border-border/70 bg-background/70 p-3 font-mono text-[11px] leading-relaxed text-muted-foreground/90`,S?`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{ve as DiffWorkerPoolProvider,U as default};
98
- //# sourceMappingURL=DiffPanel-_ZNDNQOt.js.map
98
+ //# sourceMappingURL=DiffPanel-BArgAYQw.js.map