agl 42.2.1 → 43.0.0

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.
Files changed (173) hide show
  1. package/changelog.md +22 -0
  2. package/dist_serve/bundle.js +6697 -5287
  3. package/dist_serve/bundle.js.map +2 -2
  4. package/dist_serve/bundle.js.third-party-notices.json +31 -31
  5. package/dist_serve/bundle.js.third-party-notices.txt +31 -31
  6. package/dist_serve/third-party-notices.md +597 -8
  7. package/dist_ts/00_commitinfo_data.js +1 -1
  8. package/dist_ts/aglapi/aglapisurface.document.js +114 -16
  9. package/dist_ts/aglapi/interfaces.d.ts +30 -0
  10. package/dist_ts/aglapi/interfaces.js +7 -1
  11. package/dist_ts/classes.authstore.d.ts +7 -0
  12. package/dist_ts/classes.authstore.js +12 -1
  13. package/dist_ts/classes.cli.js +10 -1
  14. package/dist_ts/classes.controller.d.ts +41 -11
  15. package/dist_ts/classes.controller.js +224 -48
  16. package/dist_ts/classes.harnessoperationmanager.d.ts +44 -0
  17. package/dist_ts/classes.harnessoperationmanager.js +15 -10
  18. package/dist_ts/classes.mcpclient.d.ts +5 -0
  19. package/dist_ts/classes.mcpclient.js +15 -3
  20. package/dist_ts/classes.mcpcontrollerhost.d.ts +3 -0
  21. package/dist_ts/classes.mcpcontrollerhost.js +14 -2
  22. package/dist_ts/classes.mcptools.d.ts +4 -3
  23. package/dist_ts/classes.mcptools.js +20 -1
  24. package/dist_ts/classes.mcpvalidation.js +4 -1
  25. package/dist_ts/classes.ticketstore.d.ts +71 -3
  26. package/dist_ts/classes.ticketstore.js +299 -12
  27. package/dist_ts/classes.validation.d.ts +2 -0
  28. package/dist_ts/classes.validation.js +27 -5
  29. package/dist_ts/driver/classes.directreports.d.ts +23 -3
  30. package/dist_ts/driver/classes.directreports.js +59 -2
  31. package/dist_ts/driver/classes.drivereventrelay.js +3 -2
  32. package/dist_ts/driver/functions.driverinstructions.d.ts +1 -1
  33. package/dist_ts/driver/functions.driverinstructions.js +12 -3
  34. package/dist_ts/driver/functions.drivertools.d.ts +4 -0
  35. package/dist_ts/driver/functions.drivertools.js +8 -2
  36. package/dist_ts/fleet/classes.boardpump.d.ts +53 -3
  37. package/dist_ts/fleet/classes.boardpump.js +237 -32
  38. package/dist_ts/fleet/classes.claudeworkers.d.ts +10 -3
  39. package/dist_ts/fleet/classes.claudeworkers.js +43 -19
  40. package/dist_ts/fleet/classes.codexworkers.d.ts +5 -3
  41. package/dist_ts/fleet/classes.codexworkers.js +26 -9
  42. package/dist_ts/fleet/classes.deploymonitor.d.ts +253 -0
  43. package/dist_ts/fleet/classes.deploymonitor.js +821 -0
  44. package/dist_ts/fleet/classes.gitfacts.d.ts +61 -0
  45. package/dist_ts/fleet/classes.gitfacts.js +125 -0
  46. package/dist_ts/fleet/classes.releasereconciler.d.ts +51 -0
  47. package/dist_ts/fleet/classes.releasereconciler.js +101 -0
  48. package/dist_ts/fleet/classes.service.d.ts +13 -1
  49. package/dist_ts/fleet/classes.service.js +76 -7
  50. package/dist_ts/fleet/classes.ticketeffects.d.ts +13 -0
  51. package/dist_ts/fleet/classes.ticketeffects.js +42 -8
  52. package/dist_ts/fleet/classes.workers.d.ts +10 -3
  53. package/dist_ts/fleet/classes.workers.js +18 -3
  54. package/dist_ts/fleet/functions.controllerbuild.d.ts +23 -0
  55. package/dist_ts/fleet/functions.controllerbuild.js +75 -0
  56. package/dist_ts/fleet/functions.deployprobes.d.ts +39 -0
  57. package/dist_ts/fleet/functions.deployprobes.js +82 -0
  58. package/dist_ts/fleet/functions.deployvalidation.d.ts +27 -0
  59. package/dist_ts/fleet/functions.deployvalidation.js +43 -0
  60. package/dist_ts/fleet/functions.release.d.ts +2 -1
  61. package/dist_ts/fleet/functions.release.js +32 -5
  62. package/dist_ts/fleet/functions.releasefacts.d.ts +45 -0
  63. package/dist_ts/fleet/functions.releasefacts.js +68 -0
  64. package/dist_ts/fleet/functions.validation.d.ts +3 -3
  65. package/dist_ts/fleet/functions.validation.js +4 -7
  66. package/dist_ts/fleet/functions.watchprobes.js +7 -9
  67. package/dist_ts/fleet/functions.workervalidation.js +4 -3
  68. package/dist_ts/fleet/interfaces.workers.d.ts +30 -3
  69. package/dist_ts/fleet/interfaces.workers.js +14 -1
  70. package/dist_ts/functions.deploycli.d.ts +33 -0
  71. package/dist_ts/functions.deploycli.js +155 -0
  72. package/dist_ts/functions.mcpdeploytools.d.ts +13 -0
  73. package/dist_ts/functions.mcpdeploytools.js +16 -0
  74. package/dist_ts/functions.mcptickettools.d.ts +54 -0
  75. package/dist_ts/functions.mcptickettools.js +8 -7
  76. package/dist_ts/functions.monacoassets.js +3 -3
  77. package/dist_ts/functions.ticketautolabels.d.ts +2 -0
  78. package/dist_ts/functions.ticketautolabels.js +9 -3
  79. package/dist_ts/functions.ticketcli.d.ts +16 -2
  80. package/dist_ts/functions.ticketcli.js +105 -27
  81. package/dist_ts/functions.ticketvalidation.d.ts +55 -0
  82. package/dist_ts/functions.ticketvalidation.js +26 -8
  83. package/dist_ts_interfaces/deployments.d.ts +241 -0
  84. package/dist_ts_interfaces/deployments.js +5 -6
  85. package/dist_ts_interfaces/fleet.d.ts +12 -0
  86. package/dist_ts_interfaces/fleetworkers.d.ts +21 -1
  87. package/dist_ts_interfaces/interfaces.d.ts +4 -2
  88. package/dist_ts_interfaces/interfaces.js +4 -2
  89. package/dist_ts_interfaces/mcprequests.d.ts +3 -2
  90. package/dist_ts_interfaces/mcprequests.js +3 -1
  91. package/dist_ts_interfaces/requests.d.ts +3 -2
  92. package/dist_ts_interfaces/requests.directreports.d.ts +58 -6
  93. package/dist_ts_interfaces/requests.js +1 -1
  94. package/dist_ts_interfaces/requests.tickets.d.ts +25 -5
  95. package/dist_ts_interfaces/requests.tickets.js +2 -2
  96. package/dist_ts_interfaces/tickets.d.ts +71 -6
  97. package/dist_ts_interfaces/tickets.js +34 -6
  98. package/dist_ts_migration/classes.documentmigrationrunner.d.ts +7 -0
  99. package/dist_ts_migration/classes.documentmigrationrunner.js +14 -1
  100. package/dist_ts_migration/index.d.ts +2 -0
  101. package/dist_ts_migration/index.js +3 -1
  102. package/dist_ts_migration/v41_ticketclosedcolumn.d.ts +20 -0
  103. package/dist_ts_migration/v41_ticketclosedcolumn.js +118 -0
  104. package/dist_ts_migration/v41_ticketlinkrepos.d.ts +24 -0
  105. package/dist_ts_migration/v41_ticketlinkrepos.js +101 -0
  106. package/package.json +6 -2
  107. package/readme.md +307 -37
  108. package/third-party-notices.md +597 -8
  109. package/ts/00_commitinfo_data.ts +1 -1
  110. package/ts/aglapi/aglapisurface.document.ts +113 -15
  111. package/ts/aglapi/interfaces.ts +6 -0
  112. package/ts/classes.authstore.ts +13 -0
  113. package/ts/classes.cli.ts +9 -0
  114. package/ts/classes.controller.ts +238 -59
  115. package/ts/classes.harnessoperationmanager.ts +20 -14
  116. package/ts/classes.mcpclient.ts +17 -2
  117. package/ts/classes.mcpcontrollerhost.ts +15 -1
  118. package/ts/classes.mcptools.ts +21 -2
  119. package/ts/classes.mcpvalidation.ts +2 -0
  120. package/ts/classes.ticketstore.ts +312 -13
  121. package/ts/classes.validation.ts +28 -4
  122. package/ts/driver/classes.directreports.ts +58 -3
  123. package/ts/driver/classes.drivereventrelay.ts +2 -1
  124. package/ts/driver/functions.driverinstructions.ts +11 -2
  125. package/ts/driver/functions.drivertools.ts +10 -2
  126. package/ts/fleet/classes.boardpump.ts +235 -28
  127. package/ts/fleet/classes.claudeworkers.ts +36 -15
  128. package/ts/fleet/classes.codexworkers.ts +24 -7
  129. package/ts/fleet/classes.deploymonitor.ts +854 -0
  130. package/ts/fleet/classes.gitfacts.ts +135 -0
  131. package/ts/fleet/classes.releasereconciler.ts +103 -0
  132. package/ts/fleet/classes.service.ts +81 -8
  133. package/ts/fleet/classes.ticketeffects.ts +38 -6
  134. package/ts/fleet/classes.workers.ts +19 -5
  135. package/ts/fleet/functions.controllerbuild.ts +84 -0
  136. package/ts/fleet/functions.deployprobes.ts +84 -0
  137. package/ts/fleet/functions.deployvalidation.ts +50 -0
  138. package/ts/fleet/functions.release.ts +32 -3
  139. package/ts/fleet/functions.releasefacts.ts +91 -0
  140. package/ts/fleet/functions.validation.ts +3 -6
  141. package/ts/fleet/functions.watchprobes.ts +6 -8
  142. package/ts/fleet/functions.workervalidation.ts +3 -2
  143. package/ts/fleet/interfaces.workers.ts +23 -3
  144. package/ts/functions.deploycli.ts +151 -0
  145. package/ts/functions.mcpdeploytools.ts +18 -0
  146. package/ts/functions.mcptickettools.ts +7 -6
  147. package/ts/functions.monacoassets.ts +2 -2
  148. package/ts/functions.ticketautolabels.ts +10 -2
  149. package/ts/functions.ticketcli.ts +100 -24
  150. package/ts/functions.ticketvalidation.ts +26 -7
  151. package/ts_interfaces/deployments.ts +194 -0
  152. package/ts_interfaces/fleet.ts +17 -2
  153. package/ts_interfaces/fleetworkers.ts +20 -0
  154. package/ts_interfaces/interfaces.ts +3 -1
  155. package/ts_interfaces/mcprequests.ts +3 -0
  156. package/ts_interfaces/requests.directreports.ts +52 -8
  157. package/ts_interfaces/requests.tickets.ts +20 -4
  158. package/ts_interfaces/requests.ts +6 -1
  159. package/ts_interfaces/tickets.ts +53 -6
  160. package/ts_migration/classes.documentmigrationrunner.ts +15 -0
  161. package/ts_migration/index.ts +2 -0
  162. package/ts_migration/v41_ticketclosedcolumn.ts +106 -0
  163. package/ts_migration/v41_ticketlinkrepos.ts +91 -0
  164. package/ts_web/00_commitinfo_data.ts +1 -1
  165. package/ts_web/elements.deployments.ts +1066 -0
  166. package/ts_web/elements.directreport.ts +2 -2
  167. package/ts_web/elements.directreportsession.ts +5 -5
  168. package/ts_web/elements.harnesscontrollerapp.ts +179 -13
  169. package/ts_web/elements.makedirectreport.ts +444 -0
  170. package/ts_web/elements.nativesession.ts +29 -1
  171. package/ts_web/elements.ticketboard.ts +74 -18
  172. package/ts_web/functions.deployments.ts +225 -0
  173. package/ts_web/functions.sessionchat.ts +2 -0
@@ -1,10 +1,10 @@
1
1
  import * as plugins from '../plugins.js';
2
2
  import { resolveControllerTerminalAgentTranscript } from '../functions.terminalagents.js';
3
3
  import { fleetWorkerPath, resolveClaudeWorkerExecutable } from '../functions.workerprocessproof.js';
4
- import type { IFleetWorker, IFleetWorkerProfile, IFleetWorkerReport, IFleetWorkerAbsenceProof, IFleetWorkerSessionProof, IFleetWorkerRebindProof } from '../../ts_interfaces/fleetworkers.js';
4
+ import type { IFleetWorker, IFleetWorkerProfile, IFleetWorkerReport, IFleetRelaunchBlocker, IFleetWorkerAbsenceProof, IFleetWorkerSessionProof, IFleetWorkerRebindProof } from '../../ts_interfaces/fleetworkers.js';
5
5
  import { controllerSessionFeedExcerpt, type IControllerMessageBundle } from '../../ts_interfaces/index.js';
6
6
  import { claudePage, claudeTranscript } from '../classes.claudeprojection.js';
7
- import { FleetDispatchError, boundedFleetReport, fleetMessageDigest, fleetReportMarker, type IFleetWorkerBackend, type IFleetNativeEvent, type IFleetNativeAgent, type IFleetNativeSession, type IFleetNativePage } from './interfaces.workers.js';
7
+ import { FleetDispatchError, FleetNativeTurnError, boundedFleetReport, fleetMessageDigest, fleetReportMarker, type IFleetWorkerBackend, type IFleetNativeEvent, type IFleetNativeAgent, type IFleetNativeSession, type IFleetNativePage, type IFleetNativeSendTurn, type IFleetNativeSendReceipt } from './interfaces.workers.js';
8
8
  import { runFleetWorkerCommand, type IFleetWorkerCommand, type TFleetWorkerRunner } from './classes.workercommand.js';
9
9
  import { sanitizeFailureText } from '../functions.failuredescription.js';
10
10
  import type { FleetWorkerLaunches } from './classes.workerlaunches.js';
@@ -295,7 +295,7 @@ export class FleetClaudeWorkers implements IFleetWorkerBackend {
295
295
  }
296
296
  if (!trusted) throw new Error(`Claude workspace not trusted. ${instruction}`);
297
297
  }
298
- private async supported(worker: IFleetWorker, profile: IFleetWorkerProfile, starting = false): Promise<void> {
298
+ private async supported(worker: Pick<IFleetWorker, 'cwd'>, profile: IFleetWorkerProfile, starting = false): Promise<void> {
299
299
  await this.supportedExecutable(profile, worker.cwd);
300
300
  if (starting) await this.trustedWorkspace(profile, worker.cwd);
301
301
  }
@@ -553,6 +553,31 @@ export class FleetClaudeWorkers implements IFleetWorkerBackend {
553
553
  throw new FleetDispatchError(error instanceof Error ? error.message : 'Claude start outcome is unknown.', true, { cause: error });
554
554
  }
555
555
  }
556
+ /**
557
+ * Why a relaunch of the session `nativeId` in `worker`'s directory would be refused now, read-only, or what the
558
+ * relaunch continues from: the profile home's fresh inventory, the session in it and its saved conversation. The
559
+ * relaunch and its preflight both run it, so they refuse alike.
560
+ */
561
+ private async relaunchState(worker: Pick<IFleetWorker, 'cwd'>, profile: IFleetWorkerProfile, nativeId: string): Promise<{ blocker: IFleetRelaunchBlocker }
562
+ | { before: TClaudeAgent[]; original: TClaudeAgent; baseline: { records: Record<string, unknown>[]; end: number; path?: string } }> {
563
+ if (!plugins.z.string().uuid().safeParse(nativeId).success) return { blocker: { code: 'invalidId', message: 'A Claude session is relaunched by its full session id.' } };
564
+ try { await this.supported(worker, profile, true); }
565
+ catch (error) { return { blocker: { code: 'unsupported', message: error instanceof Error ? error.message : 'Claude cannot start in this directory.' } }; }
566
+ const before = await this.agents(worker, profile), found = before.find((entry) => entry.sessionId === nativeId);
567
+ if (!found) return { blocker: { code: 'notInInventory', message: `Claude session ${nativeId} is not in the inventory of this profile's Claude home; AGL cannot prove it is not running.` } };
568
+ if (live(found) || found.state === 'working') {
569
+ return { blocker: { code: live(found) ? 'running' : 'working', ...(found.pid ? { pid: found.pid } : {}),
570
+ message: `Claude session ${nativeId} is still running outside the fleet${found.pid ? ` (pid ${found.pid})` : ''}. Its owner stops it first${found.id ? ` (\`claude stop ${found.id}\`, or exits it)` : ' (exits it)'}; the adopt never stops a session it does not manage.` } };
571
+ }
572
+ if (found.kind === 'background' && !found.id) return { blocker: { code: 'noAgentId', message: 'Claude background session has no agent id.' } };
573
+ const baseline = await this.transcript({ ...worker, nativeId }, profile);
574
+ if (!baseline.path || !baseline.records.some((entry) => typeof entry.uuid === 'string')) return { blocker: { code: 'noTranscript', message: 'Claude session has no readable saved conversation.' } };
575
+ return { before, original: found, baseline };
576
+ }
577
+ public async relaunchBlocker(cwd: string, profile: IFleetWorkerProfile, nativeId: string): Promise<IFleetRelaunchBlocker | undefined> {
578
+ const state = await this.relaunchState({ cwd }, profile, nativeId);
579
+ return 'blocker' in state ? state.blocker : undefined;
580
+ }
556
581
  /**
557
582
  * Resumes the settled session `nativeId` as `worker`, under the worker's own options and caller overlay. Claude
558
583
  * continues a background job's session as a copy under a new id, its saved options staying with the original, and
@@ -562,18 +587,10 @@ export class FleetClaudeWorkers implements IFleetWorkerBackend {
562
587
  public async relaunch(worker: IFleetWorker, profile: IFleetWorkerProfile, nativeId: string, prompt: string, bind: (id: string) => Promise<void>): Promise<void> {
563
588
  let before: TClaudeAgent[], original: TClaudeAgent, baseline: { records: Record<string, unknown>[]; end: number; path?: string }, overlay: string | undefined;
564
589
  try {
565
- if (!plugins.z.string().uuid().safeParse(nativeId).success) throw new Error('A Claude session is relaunched by its full session id.');
566
590
  if (Buffer.byteLength(prompt) > 96 * 1024) throw new Error('Claude relaunch prompt plus preamble exceeds 96 KiB.');
567
- await this.supported(worker, profile, true); before = await this.agents(worker, profile);
568
- const found = before.find((entry) => entry.sessionId === nativeId);
569
- if (!found) throw new Error(`Claude session ${nativeId} is not in the inventory of this profile's Claude home; AGL cannot prove it is not running.`);
570
- if (live(found) || found.state === 'working') {
571
- throw new Error(`Claude session ${nativeId} is still running outside the fleet${found.pid ? ` (pid ${found.pid})` : ''}. Its owner stops it first${found.id ? ` (\`claude stop ${found.id}\`, or exits it)` : ' (exits it)'}; the adopt never stops a session it does not manage.`);
572
- }
573
- if (found.kind === 'background' && !found.id) throw new Error('Claude background session has no agent id.');
574
- original = found;
575
- baseline = await this.transcript({ ...worker, nativeId }, profile);
576
- if (!baseline.path || !baseline.records.some((entry) => typeof entry.uuid === 'string')) throw new Error('Claude session has no readable saved conversation.');
591
+ const state = await this.relaunchState(worker, profile, nativeId);
592
+ if ('blocker' in state) throw new Error(state.blocker.message);
593
+ ({ before, original, baseline } = state);
577
594
  overlay = await this.callers?.prepareClaude(worker);
578
595
  }
579
596
  catch (error) { throw new FleetDispatchError(error instanceof Error ? error.message : 'Claude relaunch preflight failed.', false, { cause: error }); }
@@ -702,7 +719,10 @@ export class FleetClaudeWorkers implements IFleetWorkerBackend {
702
719
  * stopped) and with a readable conversation, is woken; anything else, and a message Claude Code would read as one of
703
720
  * its options, is refused before dispatch. Claude Code does not report when the woken turn ends, so `settled` never runs.
704
721
  */
705
- public async nativeSend(session: IFleetNativeSession, text: string, _settled: () => void): Promise<void> {
722
+ public async nativeSend(session: IFleetNativeSession, text: string, _settled: () => void, turn?: IFleetNativeSendTurn): Promise<IFleetNativeSendReceipt> {
723
+ if (turn?.expectedTurnId !== undefined || turn?.agentMessage) {
724
+ throw new FleetNativeTurnError("delivery_unsupported", "Claude Code background jobs do not support guarded native turn delivery.");
725
+ }
706
726
  const profile = { home: session.home };
707
727
  let original: TClaudeAgent;
708
728
  try {
@@ -724,6 +744,7 @@ export class FleetClaudeWorkers implements IFleetWorkerBackend {
724
744
  catch (error) {
725
745
  throw new FleetDispatchError(`Claude Code acknowledged the wake of background job ${original.id}, but its state is not confirmed: ${error instanceof Error ? error.message : 'unknown failure.'} Inspect it before sending again.`, true, { cause: error });
726
746
  }
747
+ return { steered: false };
727
748
  }
728
749
  public async send(messages: Array<{ worker: IFleetWorker; profile: IFleetWorkerProfile; text: string }>): Promise<void> {
729
750
  const groups = new Map<string, Array<{ worker: IFleetWorker; profile: IFleetWorkerProfile; text: string; to: string; mode: string; offset: number }>>();
@@ -6,7 +6,7 @@ import type { IFleetWorker, IFleetWorkerProfile, IFleetWorkerReport } from '../.
6
6
  import { controllerSessionFeedExcerpt } from '../../ts_interfaces/sessionfeed.js';
7
7
  import type { IControllerMessageBundle, IControllerPermission, IControllerQuestion, TControllerPermissionReply } from '../../ts_interfaces/index.js';
8
8
  import type { FleetWorkerLaunches, IFleetCodexCallerRuntime } from './classes.workerlaunches.js';
9
- import { FleetDispatchError, fleetReportMarker, boundedFleetReport, type IFleetWorkerBackend, type IFleetNativeEvent, type IFleetNativeThread, type IFleetNativeSession, type IFleetNativePage } from './interfaces.workers.js';
9
+ import { FleetDispatchError, FleetNativeTurnError, fleetReportMarker, boundedFleetReport, type IFleetWorkerBackend, type IFleetNativeEvent, type IFleetNativeThread, type IFleetNativeSession, type IFleetNativePage, type IFleetNativeSendTurn, type IFleetNativeSendReceipt } from './interfaces.workers.js';
10
10
 
11
11
  interface ICodexObservation { turns: Set<string>; items: Map<string, string>; status?: IFleetWorkerReport['status']; excerpt?: string }
12
12
  export interface IFleetCodexConnection { supervisor: CodexSupervisor; adapter: CodexClientAdapter }
@@ -166,23 +166,34 @@ export class FleetCodexWorkers implements IFleetWorkerBackend {
166
166
  /**
167
167
  * Steers the thread's running turn, AGL's own or another client's, or starts a turn; `settled` runs once the turn
168
168
  * that took the text ended. A steer of another client's turn proves that only when the turn ended before Codex took
169
- * the input; otherwise `settled` never runs.
169
+ * the input; otherwise `settled` never runs. `turn` refuses a running turn the caller did not name before anything is
170
+ * sent; the steer itself proves the turn again on the server.
170
171
  */
171
172
  private async deliver(adapter: CodexClientAdapter, id: string, text: string, model: Parameters<CodexClientAdapter['startTurn']>[3],
172
- prepare: () => Promise<void>, settled: () => void = () => {}): Promise<void> {
173
+ prepare: () => Promise<void>, settled: () => void = () => {}, turn: IFleetNativeSendTurn = {}): Promise<IFleetNativeSendReceipt> {
173
174
  const turns = await this.turns(adapter, id);
174
175
  const running = turns[0]?.status === 'inProgress' ? turns[0] : undefined;
176
+ if (turn.expectedTurnId !== undefined && !running) throw new FleetNativeTurnError('turn_ended', 'The Codex turn this message was to steer has ended; nothing was sent.');
175
177
  await prepare();
176
178
  const clientId = plugins.crypto.randomUUID(); let arm: () => void;
177
179
  if (running) {
178
180
  const turnId = codexString(running.id), activity = await adapter.refreshActivity(id, this.signal);
181
+ if (turn.expectedTurnId !== undefined && turn.expectedTurnId !== turnId) {
182
+ throw new FleetNativeTurnError('concurrent_change', 'Another Codex turn than the expected one runs; read the session again.');
183
+ }
184
+ if (turn.agentMessage && turn.expectedTurnId === undefined && activity.writer !== 'agl') {
185
+ throw new FleetNativeTurnError('delivery_unsupported', 'Steering a turn another Codex client runs requires expectedTurnId, the turn the last read reported.');
186
+ }
179
187
  arm = await this.dispatch(() => activity.writer === 'agl'
180
188
  ? adapter.steer(id, text, clientId, () => {}, () => {}, turnId, this.signal, () => settled())
181
189
  : adapter.steerObservedTurn(id, text, clientId, turnId, () => {}, (_outcome, _turnId, terminal) => { if (terminal) settled(); }, this.signal));
182
- } else {
183
- arm = await this.dispatch(() => adapter.startTurn(id, text, clientId, model, async () => {}, settled, this.signal));
190
+ arm();
191
+ return { steered: true, turnId };
184
192
  }
193
+ arm = await this.dispatch(() => adapter.startTurn(id, text, clientId, model, async () => {}, settled, this.signal));
185
194
  arm();
195
+ const started = adapter.activitySummary(id).turnId;
196
+ return { steered: false, ...(started === undefined ? {} : { turnId: started }) };
186
197
  }
187
198
  public async stop(worker: IFleetWorker, _profile: IFleetWorkerProfile): Promise<void> {
188
199
  const adapter = await this.scoped(worker), turns = await this.turns(adapter, worker.nativeId!);
@@ -211,9 +222,15 @@ export class FleetCodexWorkers implements IFleetWorkerBackend {
211
222
  return { bundles: page.bundles, earlier: page.nextCursor !== undefined || page.truncated === true, ...(page.nextCursor === undefined ? {} : { nextCursor: page.nextCursor }) };
212
223
  }
213
224
  /** Sends to a thread outside the fleet through the shared server that owns it; the thread keeps its own model. */
214
- public async nativeSend(session: IFleetNativeSession, text: string, settled: () => void): Promise<void> {
225
+ public async nativeSend(session: IFleetNativeSession, text: string, settled: () => void, turn?: IFleetNativeSendTurn): Promise<IFleetNativeSendReceipt> {
226
+ const adapter = await this.scoped(session);
227
+ return await this.deliver(adapter, session.nativeId, text, undefined, async () => {}, settled, turn);
228
+ }
229
+ public async nativeTurn(session: IFleetNativeSession): Promise<string | undefined> {
215
230
  const adapter = await this.scoped(session);
216
- await this.deliver(adapter, session.nativeId, text, undefined, async () => {}, settled);
231
+ const result = await adapter.request('thread/turns/list', { threadId: session.nativeId, limit: 1, sortDirection: 'desc', itemsView: 'notLoaded' }, this.signal);
232
+ const latest = codexArray(result.data, 1).map(codexRecord)[0];
233
+ return latest?.status === 'inProgress' ? codexString(latest.id) : undefined;
217
234
  }
218
235
  /** The requests of turns this connection runs in the thread that wait for an answer. */
219
236
  public async nativeAttention(session: IFleetNativeSession): Promise<{ permissions: IControllerPermission[]; questions: IControllerQuestion[] }> {