@abelxiaoxing/cadence 2.0.33 → 2.0.34

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.
@@ -12,7 +12,22 @@ import {
12
12
  oneOf,
13
13
  text,
14
14
  } from "./core.ts";
15
- import { type ChoiceVersion, decodeChoiceVersion } from "./models.ts";
15
+ import { decodeModelSelector, type ModelSelector } from "./domain.ts";
16
+ import {
17
+ type ChoiceVersion,
18
+ type ConversationContext,
19
+ type ConversationLocation,
20
+ decodeChoiceVersion,
21
+ decodeConversationContext,
22
+ decodeConversationLocation,
23
+ decodeExecutionContext,
24
+ decodeModelCatalog,
25
+ decodeModelChoiceState,
26
+ decodeSessionId,
27
+ type ExecutionContext,
28
+ type ModelCatalog,
29
+ type ModelChoiceState,
30
+ } from "./models.ts";
16
31
 
17
32
  import {
18
33
  decodeWorkflowProposal,
@@ -60,13 +75,7 @@ export function decodeCadenceConversation(v: unknown): CadenceConversation {
60
75
  ...(degraded ? { notice: text(o.notice, 1024, true) } : {}),
61
76
  };
62
77
  }
63
- /** A conversation's identity: the Pi session id shared with the terminal. */
64
- export function decodeSessionId(v: unknown): string {
65
- const s = text(v, 128, true);
66
- if (!/^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/.test(s))
67
- throw new ContractError("invalid");
68
- return s;
69
- }
78
+ export { decodeSessionId } from "./models.ts";
70
79
  /** One entry of a Pi session (eight hex characters when Pi writes it). */
71
80
  export function decodeEntryId(v: unknown): string {
72
81
  const s = text(v, 64, true);
@@ -79,6 +88,10 @@ export interface WorkflowLink {
79
88
  conversationId: string;
80
89
  }
81
90
  export type WorkbenchRead =
91
+ | {
92
+ kind: "conversation-context" | "conversation-models";
93
+ location: ConversationLocation;
94
+ }
82
95
  | { kind: "cadence-conversation"; id: string }
83
96
  | { kind: "workflow-active" }
84
97
  | { kind: "workflow-history"; after: string | null; scan?: string }
@@ -87,7 +100,6 @@ export type WorkbenchRead =
87
100
  | { kind: "workflow"; id: string }
88
101
  | { kind: "conversation-active" }
89
102
  | { kind: "conversations"; after?: ChatCursor | null }
90
- | { kind: "task-origin"; taskId: string }
91
103
  | {
92
104
  kind: "conversation";
93
105
  id: string;
@@ -113,20 +125,36 @@ export type WorkbenchRead =
113
125
  part: number;
114
126
  }
115
127
  | { kind: "conversation-tree"; id: string; leaf: string | null }
116
- | { kind: "conversation-legacy" }
117
- | { kind: "files"; path: string }
118
- | { kind: "file"; path: string }
128
+ | { kind: "files"; path: string; location?: ConversationLocation }
129
+ | { kind: "file"; path: string; location?: ConversationLocation }
119
130
  | { kind: "directories"; path: string }
120
131
  | { kind: "projects" };
132
+ /** Maximum UTF-8 bytes of one explicit conversation Send. */
133
+ export const CONVERSATION_SEND_BYTES = 16 * 1024;
121
134
  export type WorkbenchCommand =
135
+ | {
136
+ kind: "conversation-model";
137
+ commandId: string;
138
+ location: ConversationLocation;
139
+ expected: ChoiceVersion;
140
+ choice: ModelSelector;
141
+ }
122
142
  | {
123
143
  kind: "cadence-exit";
144
+ location?: ConversationLocation;
124
145
  commandId: string;
125
146
  conversationId: string;
126
147
  head: string | null;
127
148
  revision: number;
128
149
  }
129
- | { kind: "restore-model"; commandId: string; epoch: string }
150
+ | {
151
+ kind: "restore-model";
152
+ commandId: string;
153
+ epoch: string;
154
+ location?: ConversationLocation;
155
+ expected?: ChoiceVersion;
156
+ choice?: ModelSelector;
157
+ }
130
158
  | {
131
159
  kind: "cadence-send";
132
160
  commandId: string;
@@ -176,8 +204,7 @@ export type WorkbenchCommand =
176
204
  turnId: string;
177
205
  epoch: string;
178
206
  }
179
- | { kind: "open-project"; commandId: string; path: string; epoch: string }
180
- | { kind: "conversation-migrate"; commandId: string };
207
+ | { kind: "open-project"; commandId: string; path: string; epoch: string };
181
208
  export type ChatStatus =
182
209
  | "queued"
183
210
  | "running"
@@ -195,6 +222,7 @@ export interface ChatItem {
195
222
  error: boolean;
196
223
  }
197
224
  export interface ChatTurn {
225
+ execution?: ExecutionContext;
198
226
  id: string;
199
227
  epoch: string;
200
228
  status: ChatStatus;
@@ -224,6 +252,7 @@ export interface ChatStep {
224
252
  }
225
253
  /** One turn of a conversation branch: a user message and what followed it. */
226
254
  export interface ChatTurnHeader {
255
+ execution?: ExecutionContext;
227
256
  /** The user message's session entry id; a browser command id while Pi has not
228
257
  * written that message yet. */
229
258
  id: string;
@@ -348,6 +377,9 @@ export interface FileEntry {
348
377
  directory: boolean;
349
378
  }
350
379
  export type WorkbenchResult =
380
+ | { kind: "conversation-context"; context: ConversationContext }
381
+ | { kind: "conversation-models"; catalog: ModelCatalog }
382
+ | { kind: "conversation-model"; commandId: string; choice: ModelChoiceState }
351
383
  | { kind: "workflow-history-progress"; after: string | null; scan: string }
352
384
  | {
353
385
  kind: "workflow-history";
@@ -376,7 +408,6 @@ export type WorkbenchResult =
376
408
  proposal: WorkflowProposal;
377
409
  }
378
410
  | { kind: "workflow"; commandId: string | null; response: WorkflowResponse }
379
- | { kind: "task-origin"; taskId: string; conversationId: string | null }
380
411
  | { kind: "conversation-active"; entries: ChatSummary[] }
381
412
  | { kind: "conversations"; entries: ChatSummary[]; next: ChatCursor | null }
382
413
  | {
@@ -392,6 +423,8 @@ export type WorkbenchResult =
392
423
  /** Workflows the terminal started in this session. */
393
424
  runs: string[];
394
425
  attempt: ChatAttempt | null;
426
+ /** Accepted browser commands, not inferred from session entry changes. */
427
+ commands?: string[];
395
428
  }
396
429
  | {
397
430
  kind: "conversation-tree";
@@ -399,13 +432,6 @@ export type WorkbenchResult =
399
432
  nodes: ChatTreeNode[];
400
433
  truncated: boolean;
401
434
  }
402
- | { kind: "conversation-legacy"; pending: number }
403
- | {
404
- kind: "conversation-migrated";
405
- commandId: string;
406
- migrated: number;
407
- skipped: number;
408
- }
409
435
  | {
410
436
  kind: "conversation-turn";
411
437
  conversationId: string;
@@ -459,6 +485,11 @@ const statuses = [
459
485
  export function decodeWorkbenchRead(v: unknown): WorkbenchRead {
460
486
  const kind = Object.getOwnPropertyDescriptor(v ?? {}, "kind")?.value;
461
487
  switch (kind) {
488
+ case "conversation-context":
489
+ case "conversation-models": {
490
+ const o = closed(v, ["kind", "location"]);
491
+ return { kind, location: decodeConversationLocation(o.location) };
492
+ }
462
493
  case "conversation-turn": {
463
494
  const o = closed(v, ["kind", "id", "leaf", "ordinal", "before"]);
464
495
  return {
@@ -522,14 +553,9 @@ export function decodeWorkbenchRead(v: unknown): WorkbenchRead {
522
553
  };
523
554
  }
524
555
  case "conversation-active":
525
- case "conversation-legacy":
526
556
  case "projects":
527
557
  closed(v, ["kind"]);
528
558
  return { kind };
529
- case "task-origin": {
530
- const o = closed(v, ["kind", "taskId"]);
531
- return { kind, taskId: decodeId(o.taskId) };
532
- }
533
559
  case "conversation": {
534
560
  const o = closed(v, ["kind", "id", "leaf", "known"]);
535
561
  return {
@@ -540,26 +566,74 @@ export function decodeWorkbenchRead(v: unknown): WorkbenchRead {
540
566
  };
541
567
  }
542
568
  default: {
543
- const o = closed(v, ["kind", "path"]);
569
+ const scoped =
570
+ (kind === "file" || kind === "files") &&
571
+ Object.hasOwn(v ?? {}, "location");
572
+ const o = closed(v, ["kind", "path", ...(scoped ? ["location"] : [])]);
544
573
  return {
545
574
  kind: oneOf(o.kind, ["files", "file", "directories"]),
546
575
  path: text(o.path, 4096),
576
+ ...(scoped ? { location: decodeConversationLocation(o.location) } : {}),
547
577
  };
548
578
  }
549
579
  }
550
580
  }
551
581
  export function decodeWorkbenchCommand(v: unknown): WorkbenchCommand {
552
582
  const kind = Object.getOwnPropertyDescriptor(v ?? {}, "kind")?.value;
583
+ if (kind === "conversation-model") {
584
+ const o = closed(v, [
585
+ "kind",
586
+ "commandId",
587
+ "location",
588
+ "expected",
589
+ "choice",
590
+ ]);
591
+ return {
592
+ kind,
593
+ commandId: decodeId(o.commandId),
594
+ location: decodeConversationLocation(o.location),
595
+ expected: decodeChoiceVersion(o.expected),
596
+ choice: decodeModelSelector(o.choice),
597
+ };
598
+ }
553
599
  if (kind === "restore-model" || kind === "workflow-cancel") {
554
600
  const o = closed(
555
601
  v,
556
602
  kind === "restore-model"
557
- ? ["kind", "commandId", "epoch"]
603
+ ? [
604
+ "kind",
605
+ "commandId",
606
+ "epoch",
607
+ ...(Object.hasOwn(v ?? {}, "location") ? ["location"] : []),
608
+ ...(Object.hasOwn(v ?? {}, "expected") ||
609
+ Object.hasOwn(v ?? {}, "choice")
610
+ ? ["expected", "choice"]
611
+ : []),
612
+ ]
558
613
  : ["kind", "commandId", "epoch", "runId"],
559
614
  );
615
+ if (
616
+ (o.expected !== undefined || o.choice !== undefined) &&
617
+ o.location === undefined
618
+ )
619
+ throw new ContractError("invalid");
620
+ const restored =
621
+ Object.hasOwn(v ?? {}, "expected") || Object.hasOwn(v ?? {}, "choice");
560
622
  const base = { commandId: decodeId(o.commandId), epoch: decodeId(o.epoch) };
561
623
  return kind === "restore-model"
562
- ? { kind, ...base }
624
+ ? {
625
+ kind,
626
+ ...base,
627
+ ...(o.location === undefined
628
+ ? {}
629
+ : { location: decodeConversationLocation(o.location) }),
630
+ ...(restored
631
+ ? {
632
+ expected: decodeChoiceVersion(o.expected),
633
+ choice: decodeModelSelector(o.choice),
634
+ }
635
+ : {}),
636
+ }
563
637
  : { kind, ...base, runId: decodeId(o.runId) };
564
638
  }
565
639
  if (kind === "cadence-exit") {
@@ -569,9 +643,13 @@ export function decodeWorkbenchCommand(v: unknown): WorkbenchCommand {
569
643
  "conversationId",
570
644
  "head",
571
645
  "revision",
646
+ ...(Object.hasOwn(v ?? {}, "location") ? ["location"] : []),
572
647
  ]);
573
648
  return {
574
649
  kind,
650
+ ...(o.location === undefined
651
+ ? {}
652
+ : { location: decodeConversationLocation(o.location) }),
575
653
  commandId: decodeId(o.commandId),
576
654
  conversationId: decodeSessionId(o.conversationId),
577
655
  head: nullable(o.head, decodeEntryId),
@@ -594,7 +672,7 @@ export function decodeWorkbenchCommand(v: unknown): WorkbenchCommand {
594
672
  commandId: decodeId(o.commandId),
595
673
  conversationId: decodeSessionId(o.conversationId),
596
674
  head: nullable(o.head, decodeEntryId),
597
- text: text(o.text, 16384, true),
675
+ text: text(o.text, CONVERSATION_SEND_BYTES, true),
598
676
  model: decodeChoiceVersion(o.model),
599
677
  revision: integer(o.revision, 0),
600
678
  intent: oneOf(o.intent, ["message", "enter", "exit"]),
@@ -645,7 +723,7 @@ export function decodeWorkbenchCommand(v: unknown): WorkbenchCommand {
645
723
  commandId: decodeId(o.commandId),
646
724
  conversationId: decodeSessionId(o.conversationId),
647
725
  head: nullable(o.head, decodeEntryId),
648
- text: text(o.text, 16 * 1024, true),
726
+ text: text(o.text, CONVERSATION_SEND_BYTES, true),
649
727
  model: decodeChoiceVersion(o.model),
650
728
  };
651
729
  }
@@ -665,10 +743,7 @@ export function decodeWorkbenchCommand(v: unknown): WorkbenchCommand {
665
743
  epoch: decodeId(o.epoch),
666
744
  };
667
745
  }
668
- if (kind === "conversation-migrate") {
669
- const o = closed(v, ["kind", "commandId"]);
670
- return { kind, commandId: decodeId(o.commandId) };
671
- }
746
+
672
747
  const o = closed(v, ["kind", "commandId", "path", "epoch"]);
673
748
  return {
674
749
  kind: oneOf(o.kind, ["open-project"]),
@@ -688,12 +763,16 @@ export function decodeChatTurn(v: unknown): ChatTurn {
688
763
  ...keys,
689
764
  ...(current ? ["omitted"] : []),
690
765
  ...(paged ? ["transcript"] : []),
766
+ ...(Object.hasOwn(v ?? {}, "execution") ? ["execution"] : []),
691
767
  ]);
692
768
  const transcript = paged ? closed(o.transcript, ["pages"]) : null;
693
769
  const omitted = current
694
770
  ? closed(o.omitted, ["thinking", "media", "other"])
695
771
  : null;
696
772
  return {
773
+ ...(o.execution === undefined
774
+ ? {}
775
+ : { execution: decodeExecutionContext(o.execution) }),
697
776
  id: decodeId(o.id),
698
777
  epoch: decodeId(o.epoch),
699
778
  status: oneOf(o.status, statuses),
@@ -753,12 +832,16 @@ function decodeChatTurnHeader(v: unknown): ChatTurnHeader {
753
832
  "omitted",
754
833
  "steps",
755
834
  "stable",
835
+ ...(Object.hasOwn(v ?? {}, "execution") ? ["execution"] : []),
756
836
  "entry",
757
837
  "at",
758
838
  ]);
759
839
  const omitted = closed(o.omitted, ["thinking", "media", "other"]);
760
840
  const steps = integer(o.steps, 0);
761
841
  return {
842
+ ...(o.execution === undefined
843
+ ? {}
844
+ : { execution: decodeExecutionContext(o.execution) }),
762
845
  id: decodeEntryId(o.id),
763
846
  entry: nullable(o.entry, decodeEntryId),
764
847
  at: integer(o.at, 0),
@@ -828,6 +911,22 @@ function decodeChatTreeNode(v: unknown): ChatTreeNode {
828
911
  export function decodeWorkbenchResult(v: unknown): WorkbenchResult {
829
912
  canonicalJson(v, 512 * 1024);
830
913
  const k = Object.getOwnPropertyDescriptor(v ?? {}, "kind")?.value;
914
+ if (k === "conversation-context") {
915
+ const o = closed(v, ["kind", "context"]);
916
+ return { kind: k, context: decodeConversationContext(o.context) };
917
+ }
918
+ if (k === "conversation-models") {
919
+ const o = closed(v, ["kind", "catalog"]);
920
+ return { kind: k, catalog: decodeModelCatalog(o.catalog) };
921
+ }
922
+ if (k === "conversation-model") {
923
+ const o = closed(v, ["kind", "commandId", "choice"]);
924
+ return {
925
+ kind: k,
926
+ commandId: decodeId(o.commandId),
927
+ choice: decodeModelChoiceState(o.choice),
928
+ };
929
+ }
831
930
  if (k === "workflow-transcript") {
832
931
  const o = closed(v, ["kind", "runId", "stepId", "turn"]);
833
932
  return {
@@ -915,14 +1014,7 @@ export function decodeWorkbenchResult(v: unknown): WorkbenchResult {
915
1014
  response: decodeWorkflowResponse(o.response),
916
1015
  };
917
1016
  }
918
- if (kind === "task-origin") {
919
- const o = closed(v, ["kind", "taskId", "conversationId"]);
920
- return {
921
- kind,
922
- taskId: decodeId(o.taskId),
923
- conversationId: nullable(o.conversationId, decodeSessionId),
924
- };
925
- }
1017
+
926
1018
  if (kind === "conversation-active") {
927
1019
  const o = closed(v, ["kind", "entries"]);
928
1020
  return { kind, entries: list(o.entries, 8, decodeChatSummary) };
@@ -945,12 +1037,16 @@ export function decodeWorkbenchResult(v: unknown): WorkbenchResult {
945
1037
  "branches",
946
1038
  "runs",
947
1039
  "attempt",
1040
+ ...(Object.hasOwn(v ?? {}, "commands") ? ["commands"] : []),
948
1041
  ]);
949
1042
  const summary = nullable(o.summary, decodeChatSummary),
950
1043
  turns = integer(o.turns, 0);
951
1044
  if (!summary && turns) throw new ContractError("invalid");
952
1045
  return {
953
1046
  kind,
1047
+ ...(o.commands === undefined
1048
+ ? {}
1049
+ : { commands: list(o.commands, 64, decodeId) }),
954
1050
  summary,
955
1051
  leaf: nullable(o.leaf, decodeEntryId),
956
1052
  continues: bool(o.continues),
@@ -969,19 +1065,7 @@ export function decodeWorkbenchResult(v: unknown): WorkbenchResult {
969
1065
  truncated: bool(o.truncated),
970
1066
  };
971
1067
  }
972
- if (kind === "conversation-legacy") {
973
- const o = closed(v, ["kind", "pending"]);
974
- return { kind, pending: integer(o.pending, 0) };
975
- }
976
- if (kind === "conversation-migrated") {
977
- const o = closed(v, ["kind", "commandId", "migrated", "skipped"]);
978
- return {
979
- kind,
980
- commandId: decodeId(o.commandId),
981
- migrated: integer(o.migrated, 0),
982
- skipped: integer(o.skipped, 0),
983
- };
984
- }
1068
+
985
1069
  if (kind === "conversation-turn") {
986
1070
  const o = closed(v, [
987
1071
  "kind",
@@ -11,7 +11,12 @@ import {
11
11
  oneOf,
12
12
  text,
13
13
  } from "./core.ts";
14
- import { type ChoiceVersion, decodeChoiceVersion } from "./models.ts";
14
+ import {
15
+ type ChoiceVersion,
16
+ decodeChoiceVersion,
17
+ decodeExecutionContext,
18
+ type ExecutionContext,
19
+ } from "./models.ts";
15
20
 
16
21
  export const WORKFLOW_LIMITS = {
17
22
  tasks: 16,
@@ -59,6 +64,7 @@ export interface WorkflowProposal {
59
64
  model: ChoiceVersion;
60
65
  plan: WorkflowPlan;
61
66
  cwd: string;
67
+ checkoutRoot?: string;
62
68
  display?: { model: string; branch: string; baseCommit: string };
63
69
  }
64
70
  export interface WorkflowTiming {
@@ -103,6 +109,7 @@ export interface WorkflowStep {
103
109
  truncated: boolean;
104
110
  }
105
111
  export interface WorkflowRun {
112
+ execution?: ExecutionContext;
106
113
  diagnostics?: WorkflowDiagnostics;
107
114
  id: string;
108
115
  epoch: string;
@@ -355,6 +362,7 @@ export function decodeWorkflowProposal(v: unknown): WorkflowProposal {
355
362
  "model",
356
363
  "plan",
357
364
  "cwd",
365
+ ...(Object.hasOwn(v ?? {}, "checkoutRoot") ? ["checkoutRoot"] : []),
358
366
  ...(modern ? ["display"] : []),
359
367
  ]);
360
368
  return {
@@ -365,6 +373,9 @@ export function decodeWorkflowProposal(v: unknown): WorkflowProposal {
365
373
  model: decodeChoiceVersion(o.model),
366
374
  plan: decodeWorkflowPlan(o.plan),
367
375
  cwd: text(o.cwd, 4096, true),
376
+ ...(o.checkoutRoot === undefined
377
+ ? {}
378
+ : { checkoutRoot: text(o.checkoutRoot, 4096, true) }),
368
379
  ...(modern
369
380
  ? {
370
381
  display: (() => {
@@ -445,6 +456,7 @@ export function decodeWorkflowRun(v: unknown): WorkflowRun {
445
456
  "mergedCommit",
446
457
  "humanReviewed",
447
458
  ...(Object.hasOwn(v ?? {}, "diagnostics") ? ["diagnostics"] : []),
459
+ ...(Object.hasOwn(v ?? {}, "execution") ? ["execution"] : []),
448
460
  ]);
449
461
  const status = (x: unknown) =>
450
462
  oneOf(x, [
@@ -458,6 +470,9 @@ export function decodeWorkflowRun(v: unknown): WorkflowRun {
458
470
  if (o.humanReviewed !== false)
459
471
  throw new Error("Automatic execution is not human review");
460
472
  return {
473
+ ...(o.execution === undefined
474
+ ? {}
475
+ : { execution: decodeExecutionContext(o.execution) }),
461
476
  ...(o.diagnostics === undefined
462
477
  ? {}
463
478
  : { diagnostics: decodeWorkflowDiagnostics(o.diagnostics) }),
@@ -266,6 +266,7 @@ var ERROR_CODES = [
266
266
  "expired-grant",
267
267
  "consumed-grant",
268
268
  "unsupported-context",
269
+ "retired-conversation",
269
270
  "quarantine",
270
271
  "capacity",
271
272
  "unavailable",
@@ -1921,6 +1922,19 @@ function resolveWorkspace(cwd) {
1921
1922
  throw new Error("Git workspace lookup refused");
1922
1923
  return { root: actual, cwd: actual };
1923
1924
  }
1925
+ function withinWorkspace(root, cwd) {
1926
+ const path2 = relative(root, cwd);
1927
+ return !isAbsolute(path2) && path2 !== ".." && !path2.startsWith(`..${sep}`);
1928
+ }
1929
+ function ownerDefaultInCheckout(root, cwd) {
1930
+ try {
1931
+ return resolveWorkspace(cwd).root === root;
1932
+ } catch (error) {
1933
+ if (!absent(error))
1934
+ throw error;
1935
+ return withinWorkspace(root, canonicalAmbientRoot(cwd));
1936
+ }
1937
+ }
1924
1938
  function defaultStateHome() {
1925
1939
  const candidate = process.platform === "win32" ? process.env.LOCALAPPDATA : process.env.XDG_STATE_HOME;
1926
1940
  if (candidate && !isAbsolute(candidate))
@@ -2902,7 +2916,7 @@ function decodeProjectEntry(value) {
2902
2916
  id: decodeHash(o.id),
2903
2917
  path: text(o.path, 4096, true),
2904
2918
  cwd: text(o.cwd, 4096, true),
2905
- epoch: decodeId(o.epoch)
2919
+ epoch: o.epoch === null ? null : decodeId(o.epoch)
2906
2920
  };
2907
2921
  }
2908
2922
  var RECOVERY_SCOPES = ["registry", "workbench", "project"];
@@ -4397,7 +4411,7 @@ class GatewayStore {
4397
4411
  if (!file)
4398
4412
  throw new ContractError("corrupt-selected");
4399
4413
  const project = decodeGatewayProject(json(file));
4400
- if (entry.name !== `${project.id}.json` || hash(project.path) !== project.id)
4414
+ if (entry.name !== `${project.id}.json` || hash(project.path) !== project.id && hash(`directory\x00${project.cwd}`) !== project.id)
4401
4415
  throw new ContractError("corrupt-selected");
4402
4416
  out.push(project);
4403
4417
  }
@@ -4407,7 +4421,7 @@ class GatewayStore {
4407
4421
  return out;
4408
4422
  }
4409
4423
  associatedProjects() {
4410
- const projects = this.projects(), recovery = this.read()?.recovery;
4424
+ const projects = this.projects().filter((project) => project.epoch !== null), recovery = this.read()?.recovery;
4411
4425
  if (!recovery)
4412
4426
  return projects;
4413
4427
  const receipt = this.files.read(this.path(recovery.receipt), 65536);
@@ -5754,7 +5768,7 @@ function selectStart(options, ambient) {
5754
5768
  tokenFile: server
5755
5769
  });
5756
5770
  }
5757
- if (fromFile && encoded(fromFile) !== encoded(selected) || options.port !== undefined && options.port !== selected.http.port || options.host !== undefined && options.host !== selected.http.host || options.agentDir !== undefined && resolve5(options.agentDir) !== selected.agentDir || options.tokenFile !== undefined && resolve5(options.tokenFile) !== selected.tokenFile || env && selected.tokenSource !== "environment" || selected.tokenSource === "environment" && !env || resolveWorkspace(selected.cwd).root !== workspace.root)
5771
+ if (fromFile && encoded(fromFile) !== encoded(selected) || options.port !== undefined && options.port !== selected.http.port || options.host !== undefined && options.host !== selected.http.host || options.agentDir !== undefined && resolve5(options.agentDir) !== selected.agentDir || options.tokenFile !== undefined && resolve5(options.tokenFile) !== selected.tokenFile || env && selected.tokenSource !== "environment" || selected.tokenSource === "environment" && !env || !ownerDefaultInCheckout(workspace.root, selected.cwd))
5758
5772
  throw new ContractError("conflict");
5759
5773
  return {
5760
5774
  workspace: workspace.root,
@@ -6805,7 +6819,7 @@ async function startService(options, foreground, hostUrl) {
6805
6819
  throw new ContractError("conflict");
6806
6820
  return existing;
6807
6821
  }
6808
- return launchHost(input, c, foreground, hostUrl, input.config.cwd, env, network);
6822
+ return launchHost(input, c, foreground, hostUrl, c.store.root, env, network);
6809
6823
  }
6810
6824
  async function launchHost(input, c, foreground, hostUrl, cwd, env, network) {
6811
6825
  const serialized = `${JSON.stringify(input)}
@@ -1,3 +1,4 @@
1
+ import type { ConversationLocation } from "./service/contracts/models.ts";
1
2
  import {
2
3
  decodeWorkbenchCommand,
3
4
  decodeWorkbenchRead,
@@ -143,10 +144,18 @@ export class ServiceClient {
143
144
  const request = decodeWorkbenchRead(input);
144
145
  try {
145
146
  if (!this.transport.workbenchRead) return unavailable(false);
146
- return decodeReply(
147
+ const reply = decodeReply(
147
148
  await this.transport.workbenchRead(request, signal),
148
149
  decodeWorkbenchResult,
149
150
  );
151
+ if (
152
+ reply.kind === "ok" &&
153
+ request.kind === "conversation-context" &&
154
+ (reply.value.kind !== request.kind ||
155
+ reply.value.context.id !== request.location.id)
156
+ )
157
+ return unavailable(false);
158
+ return reply;
150
159
  } catch {
151
160
  return unavailable(false);
152
161
  }
@@ -221,8 +230,22 @@ export class ServiceClient {
221
230
  return unavailable(false);
222
231
  }
223
232
  }
224
- async models(signal?: AbortSignal): Promise<Reply<ModelCatalog>> {
233
+ async models(
234
+ signal?: AbortSignal,
235
+ location?: ConversationLocation,
236
+ ): Promise<Reply<ModelCatalog>> {
225
237
  try {
238
+ if (location) {
239
+ const reply = await this.workbenchRead(
240
+ { kind: "conversation-models", location },
241
+ signal,
242
+ );
243
+ if (reply.kind === "error") return reply;
244
+ return reply.value.kind === "conversation-models" &&
245
+ reply.value.catalog.version.conversation?.id === location.id
246
+ ? { kind: "ok", value: reply.value.catalog }
247
+ : unavailable(false);
248
+ }
226
249
  if (!this.transport.models) return unavailable(false);
227
250
  return decodeReply(
228
251
  await this.transport.models(signal),
@@ -234,19 +257,38 @@ export class ServiceClient {
234
257
  }
235
258
  async chooseModel(
236
259
  input: ChooseModelRequest,
260
+ location?: ConversationLocation,
237
261
  ): Promise<Reply<ModelChoiceState>> {
238
262
  const request = decodeChooseModelRequest(input);
239
263
  try {
240
- if (!this.transport.chooseModel) return unavailable(false);
241
- const reply = decodeReply(
242
- await this.transport.chooseModel(request),
243
- decodeModelChoiceState,
244
- );
264
+ let reply: Reply<ModelChoiceState>;
265
+ if (location) {
266
+ const result = await this.workbenchCommand({
267
+ kind: "conversation-model",
268
+ commandId: crypto.randomUUID(),
269
+ location,
270
+ ...request,
271
+ });
272
+ reply =
273
+ result.kind === "error"
274
+ ? result
275
+ : result.value.kind === "conversation-model"
276
+ ? { kind: "ok", value: result.value.choice }
277
+ : unavailable(true);
278
+ } else {
279
+ if (!this.transport.chooseModel) return unavailable(false);
280
+ reply = decodeReply(
281
+ await this.transport.chooseModel(request),
282
+ decodeModelChoiceState,
283
+ );
284
+ }
245
285
  if (reply.kind === "ok") {
246
286
  const { sourceSelectionId: _id, ...selector } =
247
287
  reply.value.selected ?? {};
248
288
  if (
249
289
  canonicalJson(selector) !== canonicalJson(request.choice) ||
290
+ canonicalJson(reply.value.version.conversation ?? null) !==
291
+ canonicalJson(request.expected.conversation ?? null) ||
250
292
  reply.value.version.epoch !== request.expected.epoch ||
251
293
  reply.value.version.accessGeneration !==
252
294
  request.expected.accessGeneration ||
@@ -254,8 +296,12 @@ export class ServiceClient {
254
296
  request.expected.configRev,
255
297
  request.expected.configRev + 1,
256
298
  ].includes(reply.value.version.configRev) ||
257
- (reply.value.version.configRev === request.expected.configRev) !==
258
- (reply.value.version.catalogId === request.expected.catalogId)
299
+ (!location &&
300
+ (reply.value.version.configRev === request.expected.configRev) !==
301
+ (reply.value.version.catalogId === request.expected.catalogId)) ||
302
+ (!!location &&
303
+ reply.value.version.configRev !== request.expected.configRev &&
304
+ reply.value.version.catalogId === request.expected.catalogId)
259
305
  )
260
306
  return unavailable(true);
261
307
  }