@covro/covro 0.8.1-dev.3 → 0.8.1-dev.5

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 (121) hide show
  1. package/README.md +2 -2
  2. package/README.zh-CN.md +2 -2
  3. package/dist/codex/adapter.js +7 -19
  4. package/dist/codex/adapter.js.map +2 -2
  5. package/dist/codex/mapping.js +1 -0
  6. package/dist/codex/mapping.js.map +2 -2
  7. package/dist/drizzle/0008_pending_user_messages.sql +12 -0
  8. package/dist/drizzle/0009_question_tracking.sql +15 -0
  9. package/dist/drizzle/meta/0008_snapshot.json +606 -0
  10. package/dist/drizzle/meta/0009_snapshot.json +698 -0
  11. package/dist/drizzle/meta/_journal.json +14 -0
  12. package/dist/server/db/operations.js +34 -3
  13. package/dist/server/db/operations.js.map +2 -2
  14. package/dist/server/db/question-tracking.js +83 -0
  15. package/dist/server/db/question-tracking.js.map +7 -0
  16. package/dist/server/db/schema.js +41 -0
  17. package/dist/server/db/schema.js.map +2 -2
  18. package/dist/server/http.js +7 -0
  19. package/dist/server/http.js.map +2 -2
  20. package/dist/server/projection.js +4 -1
  21. package/dist/server/projection.js.map +2 -2
  22. package/dist/server/service.js +156 -29
  23. package/dist/server/service.js.map +3 -3
  24. package/dist/server/snapshot.js +4 -0
  25. package/dist/server/snapshot.js.map +2 -2
  26. package/dist/shared/question-resolution.js +27 -0
  27. package/dist/shared/question-resolution.js.map +7 -0
  28. package/dist/shared/thread-attention.js +1 -1
  29. package/dist/shared/thread-attention.js.map +2 -2
  30. package/dist/shared/user-message.js +26 -0
  31. package/dist/shared/user-message.js.map +7 -0
  32. package/dist/shared/validation.js +8 -1
  33. package/dist/shared/validation.js.map +2 -2
  34. package/dist/web/assets/{abnfDiagram-WEYOIA3C-C0QnyqNd.js → abnfDiagram-WEYOIA3C-BO_RQeXN.js} +1 -1
  35. package/dist/web/assets/{arc-DlK1TXAl.js → arc-BrbjGKnJ.js} +1 -1
  36. package/dist/web/assets/{architecture-WOLXFQ4H-D-JMMs4D.js → architecture-WOLXFQ4H-CO5JiNWc.js} +1 -1
  37. package/dist/web/assets/{architectureDiagram-ZHVYKT53-DSI-eU_c.js → architectureDiagram-ZHVYKT53-VZ--7mt8.js} +1 -1
  38. package/dist/web/assets/{blockDiagram-RJAE7QA3-D3apsE0y.js → blockDiagram-RJAE7QA3-CFd3y32z.js} +1 -1
  39. package/dist/web/assets/{c4Diagram-XDPPPE54-CV9lupsD.js → c4Diagram-XDPPPE54-DAavEe0D.js} +1 -1
  40. package/dist/web/assets/channel-B6wPa8oJ.js +1 -0
  41. package/dist/web/assets/{chunk-2E7WHVMD-CndbUrrs.js → chunk-2E7WHVMD-DmIDdy_2.js} +1 -1
  42. package/dist/web/assets/{chunk-4EMNKR2T-dVEHP-LN.js → chunk-4EMNKR2T-Co0NPOlt.js} +1 -1
  43. package/dist/web/assets/{chunk-55XCU76K-CS7wNOAm.js → chunk-55XCU76K-Z9vyXWlz.js} +1 -1
  44. package/dist/web/assets/{chunk-7S6XSTFO-Bl2P04ut.js → chunk-7S6XSTFO-FtT06ZAY.js} +1 -1
  45. package/dist/web/assets/{chunk-AQDTSKZB-BPPo5iEd.js → chunk-AQDTSKZB-6ECeFeD7.js} +1 -1
  46. package/dist/web/assets/{chunk-DSNLSHJZ-YdcvH1wD.js → chunk-DSNLSHJZ-BwB4BSUm.js} +1 -1
  47. package/dist/web/assets/{chunk-HAGFOTED-zn-sYBst.js → chunk-HAGFOTED-DuK_RKqo.js} +1 -1
  48. package/dist/web/assets/{chunk-HNE4Q36P-CbN9Pv2N.js → chunk-HNE4Q36P-BGD3LccE.js} +1 -1
  49. package/dist/web/assets/{chunk-NQOKRVIF-Bkq32pDl.js → chunk-NQOKRVIF-d9_InO8B.js} +1 -1
  50. package/dist/web/assets/{chunk-UHW7PFBP-qVGiYjS0.js → chunk-UHW7PFBP-oyw-rnut.js} +1 -1
  51. package/dist/web/assets/{chunk-VQ5W62QI-DU7piROS.js → chunk-VQ5W62QI-CBtXwUMd.js} +1 -1
  52. package/dist/web/assets/{chunk-WQQL4CDK-WvwPd1wY.js → chunk-WQQL4CDK-C0yGAD8U.js} +1 -1
  53. package/dist/web/assets/{chunk-XXDRQBXY-CuDPEdzV.js → chunk-XXDRQBXY-CJoPDXBk.js} +1 -1
  54. package/dist/web/assets/{chunk-YZO67HFG-48QFsgYH.js → chunk-YZO67HFG-ClQ0H3pB.js} +1 -1
  55. package/dist/web/assets/{chunk-ZAUX2LTX-BO1ig1OF.js → chunk-ZAUX2LTX-Djwp7USo.js} +1 -1
  56. package/dist/web/assets/{chunk-ZCHMQSOR-DVZeqmws.js → chunk-ZCHMQSOR-B_XXu_RK.js} +1 -1
  57. package/dist/web/assets/{classDiagram-v2-4MYWR3UA-D7BkhGkQ.js → classDiagram-v2-4MYWR3UA-DTykvZXI.js} +1 -1
  58. package/dist/web/assets/{cose-bilkent-JH36ORCC-DXRdUuBj.js → cose-bilkent-JH36ORCC-C3noGEk8.js} +1 -1
  59. package/dist/web/assets/{cynefin-EF2NZ3EQ-BBnNE97R.js → cynefin-EF2NZ3EQ-Cu3p3KzN.js} +1 -1
  60. package/dist/web/assets/{cynefinDiagram-WF24UDRP-wgr6aImm.js → cynefinDiagram-WF24UDRP-CMJtiF5O.js} +1 -1
  61. package/dist/web/assets/{dagre-NK4GIZVX-CsybgXX3.js → dagre-NK4GIZVX-_gQW4c3R.js} +1 -1
  62. package/dist/web/assets/{diagram-CBK3MWTC-vA79ZB5L.js → diagram-CBK3MWTC-DQMdH7AV.js} +1 -1
  63. package/dist/web/assets/{diagram-I5XIIV2D-CbLbBDPI.js → diagram-I5XIIV2D-YBBLWFnG.js} +1 -1
  64. package/dist/web/assets/{diagram-ODIL2UCW-BRaufBHD.js → diagram-ODIL2UCW-CHXIVRf1.js} +1 -1
  65. package/dist/web/assets/{diagram-PFBEJUXE-D_wZutyI.js → diagram-PFBEJUXE-DDrYQuSn.js} +1 -1
  66. package/dist/web/assets/{diagram-RJA3I4VV-oCF08BO6.js → diagram-RJA3I4VV-T_QHVlBo.js} +1 -1
  67. package/dist/web/assets/{diagram-TYUNFSNR-CPTZQzbX.js → diagram-TYUNFSNR-CrttYzid.js} +1 -1
  68. package/dist/web/assets/{dist-maLQ4i5Q.js → dist-sxTkLBEW.js} +1 -1
  69. package/dist/web/assets/{ebnfDiagram-V4P3TTPT-XUuFYmm-.js → ebnfDiagram-V4P3TTPT-D5socIPN.js} +1 -1
  70. package/dist/web/assets/{elk-QONTBCTQ-DxYOwm6S.js → elk-QONTBCTQ-BnCDU5t4.js} +1 -1
  71. package/dist/web/assets/{erDiagram-KYQIGQAA-u2IbcKAR.js → erDiagram-KYQIGQAA-BneSJl0f.js} +1 -1
  72. package/dist/web/assets/{eventmodeling-K75KTNOO-CN9QS6Td.js → eventmodeling-K75KTNOO-DAa58bfp.js} +1 -1
  73. package/dist/web/assets/flowDiagram-IUGLLWBU-D5Kfq1wD.js +1 -0
  74. package/dist/web/assets/{ganttDiagram-R7GPNTJY-I0UVqGJv.js → ganttDiagram-R7GPNTJY-CbT7Vvh8.js} +1 -1
  75. package/dist/web/assets/{gitGraph-VSP46ZUC-CC-C8YfY.js → gitGraph-VSP46ZUC-DImhgnA-.js} +1 -1
  76. package/dist/web/assets/{gitGraphDiagram-PDYL7XHY-CfPpPR4y.js → gitGraphDiagram-PDYL7XHY-BCIhQSnt.js} +1 -1
  77. package/dist/web/assets/index-B5qrF3YQ.js +164 -0
  78. package/dist/web/assets/index-CJhiAWU_.css +1 -0
  79. package/dist/web/assets/{info-OHQRW6UA-DfEihEbe.js → info-OHQRW6UA-Ca1dcpLj.js} +1 -1
  80. package/dist/web/assets/{infoDiagram-MVDRKAX5-jsk2r5_p.js → infoDiagram-MVDRKAX5-CZwqwKIn.js} +1 -1
  81. package/dist/web/assets/{ishikawaDiagram-HPEHV2GE-Br5cNkrb.js → ishikawaDiagram-HPEHV2GE-K78USkcr.js} +1 -1
  82. package/dist/web/assets/{journeyDiagram-BOSHW7O7-BUHxmePY.js → journeyDiagram-BOSHW7O7-CInG1mSi.js} +1 -1
  83. package/dist/web/assets/{kanban-definition-FNSA4HC5-Drcedx-U.js → kanban-definition-FNSA4HC5-BnUr2xEF.js} +1 -1
  84. package/dist/web/assets/{line-Ctz7g8Ql.js → line-DzMtguNw.js} +1 -1
  85. package/dist/web/assets/{linear-P2wI5bXo.js → linear-CNySZw0C.js} +1 -1
  86. package/dist/web/assets/{mermaid-parser.core-BCm_6Ljg.js → mermaid-parser.core-BjNrmgSz.js} +3 -3
  87. package/dist/web/assets/{mermaid.core-7v3EUews.js → mermaid.core-opaDzh2t.js} +4 -4
  88. package/dist/web/assets/{mindmap-definition-6OY57UG3-CMv8VCIr.js → mindmap-definition-6OY57UG3-BfQCchDX.js} +1 -1
  89. package/dist/web/assets/{packet-JDAUHWVQ-3Pb0j6W3.js → packet-JDAUHWVQ-d61w6Aq3.js} +1 -1
  90. package/dist/web/assets/{pegDiagram-ECIUJNBX-zKTfibQY.js → pegDiagram-ECIUJNBX-C4qbCufd.js} +1 -1
  91. package/dist/web/assets/{pie-XZMESJXO-DMDT5UNv.js → pie-XZMESJXO-Bwb-SDtc.js} +1 -1
  92. package/dist/web/assets/{pieDiagram-GNMPY74T-B6yI6f_E.js → pieDiagram-GNMPY74T-DGajqL2R.js} +1 -1
  93. package/dist/web/assets/{quadrantDiagram-D57K4MC3-SO17XMVr.js → quadrantDiagram-D57K4MC3-DwCmnGz-.js} +1 -1
  94. package/dist/web/assets/{radar-ABXABTNO-YvpOzBAA.js → radar-ABXABTNO-CSV3Ys_t.js} +1 -1
  95. package/dist/web/assets/{railroad-I3PHUGI6-BPg1dOeA.js → railroad-I3PHUGI6-B53NZiRX.js} +1 -1
  96. package/dist/web/assets/{railroad-abnf-LNEFI6M7-BKGbo9CR.js → railroad-abnf-LNEFI6M7-AZHHU_Eu.js} +1 -1
  97. package/dist/web/assets/{railroad-ebnf-DWYD2UWJ-D5_PLI-N.js → railroad-ebnf-DWYD2UWJ-CfHUzG_e.js} +1 -1
  98. package/dist/web/assets/{railroad-peg-JR7BVNR7-CEFJd3SP.js → railroad-peg-JR7BVNR7-BFMwCv49.js} +1 -1
  99. package/dist/web/assets/{railroadDiagram-Y72NRBL7-BYh_5uw6.js → railroadDiagram-Y72NRBL7-JGBjh6gS.js} +1 -1
  100. package/dist/web/assets/{requirementDiagram-EQYSW5RA-DGYSElHG.js → requirementDiagram-EQYSW5RA-H89IE7Aj.js} +1 -1
  101. package/dist/web/assets/{sankeyDiagram-SY24JHO5-BeKh2o8l.js → sankeyDiagram-SY24JHO5-BW1h5GMG.js} +1 -1
  102. package/dist/web/assets/{sequenceDiagram-BLEHNHQU-CNyioWa2.js → sequenceDiagram-BLEHNHQU-DW1LCcm2.js} +1 -1
  103. package/dist/web/assets/{src-BLsnTRZ-.js → src-qKGv1ENI.js} +1 -1
  104. package/dist/web/assets/{stateDiagram-v2-A6IESKWZ-CKe1jjE0.js → stateDiagram-v2-A6IESKWZ-B1LYrPov.js} +1 -1
  105. package/dist/web/assets/{swimlanes-B3ENRKFQ-BdrScdIT.js → swimlanes-B3ENRKFQ-DTZ07PM6.js} +1 -1
  106. package/dist/web/assets/swimlanesDiagram-AYQRV4AK-CmXIvE2p.js +8 -0
  107. package/dist/web/assets/{timeline-definition-JXYKGLGB-CvaDxCqJ.js → timeline-definition-JXYKGLGB-BE1obc2i.js} +1 -1
  108. package/dist/web/assets/{treeView-D4JQ5SDB-DBJ9ILwb.js → treeView-D4JQ5SDB-B5wK9RCF.js} +1 -1
  109. package/dist/web/assets/{treemap-SAJKECNS-BZrygZQO.js → treemap-SAJKECNS-Cfy-_3AL.js} +1 -1
  110. package/dist/web/assets/{usecaseDiagram-WPOLBNNX-A0NUZ93A.js → usecaseDiagram-WPOLBNNX-xz4Our_C.js} +1 -1
  111. package/dist/web/assets/{vennDiagram-Q3Y3IDCW-dbdcosPe.js → vennDiagram-Q3Y3IDCW-DPiMvNxK.js} +1 -1
  112. package/dist/web/assets/{wardley-7MLQ67FV-B8pRUZnO.js → wardley-7MLQ67FV-By9tOblG.js} +1 -1
  113. package/dist/web/assets/{wardleyDiagram-IVAIDKWA-CzqNzRpd.js → wardleyDiagram-IVAIDKWA-CEXsZftZ.js} +1 -1
  114. package/dist/web/assets/{xychartDiagram-4URNHDU4-KcmVWSns.js → xychartDiagram-4URNHDU4-CpvteEDM.js} +1 -1
  115. package/dist/web/index.html +2 -2
  116. package/package.json +4 -4
  117. package/dist/web/assets/channel-hujhhrJ-.js +0 -1
  118. package/dist/web/assets/flowDiagram-IUGLLWBU-CSuZYZyu.js +0 -1
  119. package/dist/web/assets/index-DNGcj3B0.js +0 -158
  120. package/dist/web/assets/index-DZeeR_n0.css +0 -1
  121. package/dist/web/assets/swimlanesDiagram-AYQRV4AK-BLlQg197.js +0 -8
@@ -1,3 +1,6 @@
1
+ import { questionAnswers } from "../shared/question-resolution.js";
2
+ import { asyncQuestionId, parseQuestionReplies } from "../shared/async-questions.js";
3
+ import { QuestionTrackingStore } from "./db/question-tracking.js";
1
4
  import { hasSkillToken } from "../shared/skills.js";
2
5
  import { CapacityRetries } from "./capacity-retry.js";
3
6
  import { isModelCapacityError } from "../shared/turn-errors.js";
@@ -14,6 +17,7 @@ import { WorkspaceRegistry } from "./workspaces.js";
14
17
  import { UNASSIGNED_SCOPE } from "../shared/workspace-scope.js";
15
18
  import { AppError } from "../shared/errors.js";
16
19
  import { threadNameError } from "../shared/thread-name.js";
20
+ import { mergeUserMessage, submittedUserMessage } from "../shared/user-message.js";
17
21
  import {
18
22
  validateElicitationResolution,
19
23
  validatePermissionResolution
@@ -40,6 +44,7 @@ class GatewayService {
40
44
  this.options = options;
41
45
  this.store = options.store;
42
46
  this.turnUsage = new TurnUsageStore(this.store.database);
47
+ this.questionTracking = new QuestionTrackingStore(this.store.database);
43
48
  this.projects = options.projects;
44
49
  this.workspaces = new WorkspaceRegistry(
45
50
  this.store.database,
@@ -75,6 +80,7 @@ class GatewayService {
75
80
  projection;
76
81
  store;
77
82
  turnUsage;
83
+ questionTracking;
78
84
  projects;
79
85
  workspaces;
80
86
  codex;
@@ -593,7 +599,7 @@ class GatewayService {
593
599
  const thread = this.projection.get(threadId);
594
600
  if (!thread) return [];
595
601
  this.workspaces.assertOwnership(thread.projectId, thread.cwd, thread.id);
596
- return pendingAttention(thread);
602
+ return pendingAttention(this.threadView(thread));
597
603
  }
598
604
  async getThreadSnapshot(threadId) {
599
605
  await this.getThread(threadId);
@@ -619,7 +625,7 @@ class GatewayService {
619
625
  const root = links.get(turn.id);
620
626
  if (root) turn.retryOf = root;
621
627
  }
622
- return page;
628
+ return this.threadView(page);
623
629
  }
624
630
  async exportThread(threadId) {
625
631
  this.ensureReady();
@@ -920,11 +926,24 @@ class GatewayService {
920
926
  if (isActive(this.projection.get(threadId)?.status ?? thread.status))
921
927
  throw new AppError("THREAD_BUSY", "Session already has an active task", 409);
922
928
  }
923
- this.store.dispatch(input.clientOperationId, {
924
- threadId,
925
- workspaceKey: ownership.workspaceKey,
926
- codexEpoch: this.codex.epoch
927
- });
929
+ if (parseQuestionReplies(input.text))
930
+ await this.claimQuestionReplies(threadId, input.text, input.clientOperationId);
931
+ const message = {
932
+ ...input,
933
+ text: input.taskKind === "init" ? PROJECT_INIT_PROMPT : input.text
934
+ };
935
+ this.store.dispatch(
936
+ input.clientOperationId,
937
+ {
938
+ threadId,
939
+ workspaceKey: ownership.workspaceKey,
940
+ codexEpoch: this.codex.epoch
941
+ },
942
+ message.text || message.images?.length ? {
943
+ threadId,
944
+ item: submittedUserMessage(input.clientOperationId, message)
945
+ } : void 0
946
+ );
928
947
  if (retry && !this.capacityRetries.owns(retry))
929
948
  throw new AppError("TURN_CONFLICT", "\u5BB9\u91CF\u91CD\u8BD5\u5DF2\u53D6\u6D88\u6216\u88AB\u66FF\u4EE3", 409);
930
949
  const candidate = retry ?? this.capacityRetries.begin(
@@ -940,10 +959,11 @@ class GatewayService {
940
959
  const turn = await this.codex.startTurn(
941
960
  threadId,
942
961
  ownership.cwd,
943
- input.taskKind === "init" ? PROJECT_INIT_PROMPT : input.text,
962
+ message.text,
944
963
  input.settings,
945
964
  input.images,
946
- ...skills.length ? [skills] : []
965
+ skills.length ? skills : void 0,
966
+ input.clientOperationId
947
967
  );
948
968
  this.store.attachTurn(input.clientOperationId, turn.id);
949
969
  this.turnBaselines.delete(input.clientOperationId);
@@ -1178,14 +1198,22 @@ class GatewayService {
1178
1198
  409
1179
1199
  );
1180
1200
  this.ensureCompatibilityConfirmed();
1181
- this.store.dispatch(input.clientOperationId);
1201
+ if (parseQuestionReplies(input.text))
1202
+ await this.claimQuestionReplies(threadId, input.text, input.clientOperationId);
1203
+ this.store.dispatch(input.clientOperationId, void 0, {
1204
+ threadId,
1205
+ turnId: input.expectedTurnId,
1206
+ item: submittedUserMessage(input.clientOperationId, input)
1207
+ });
1208
+ this.publishThread(threadId);
1182
1209
  const result = await this.codex.steerTurn(
1183
1210
  threadId,
1184
1211
  input.expectedTurnId,
1185
1212
  input.text,
1186
- input.images
1213
+ input.images,
1214
+ input.clientOperationId
1187
1215
  );
1188
- return { result: { threadId, turnId: result.turnId } };
1216
+ return { result: { threadId, turnId: result.turnId }, turnId: result.turnId };
1189
1217
  });
1190
1218
  }
1191
1219
  async updateLiveSettings(threadId, input) {
@@ -1260,9 +1288,88 @@ class GatewayService {
1260
1288
  this.projection.resolveAction(actionId, "responding");
1261
1289
  if (action.threadId) this.publishThread(action.threadId);
1262
1290
  await this.codex.respond(actionId, input.resolution);
1291
+ if (action.kind === "questions") {
1292
+ this.projection.resolveAction(actionId, "responded");
1293
+ this.questionTracking.saveAction(
1294
+ action,
1295
+ questionAnswers(action.questions ?? [], input.resolution)
1296
+ );
1297
+ if (action.threadId) this.publishThread(action.threadId);
1298
+ }
1263
1299
  return { result: { actionId } };
1264
1300
  });
1265
1301
  }
1302
+ /** This ends Covro tracking only. It must never start/steer/interrupt a native turn. */
1303
+ async dismissQuestions(threadId, input) {
1304
+ return this.perform("question.dismiss", threadId, input, async () => {
1305
+ await this.loadThread(threadId);
1306
+ const history = this.normalize(await this.codex.readThread(threadId));
1307
+ this.workspaces.assertOwnership(history.projectId, history.cwd, history.id);
1308
+ this.projection.thread(history, true);
1309
+ const states = this.questionTracking.states(threadId);
1310
+ for (const id of new Set(input.questionIds)) {
1311
+ const question = this.findAsyncQuestion(history, id);
1312
+ if (!question) throw new AppError("QUESTION_EXPIRED", "\u8BE5\u95EE\u9898\u5DF2\u4E0D\u5B58\u5728\uFF0C\u8BF7\u5237\u65B0\u4F1A\u8BDD", 409);
1313
+ if (this.questionAnswered(history, id)) continue;
1314
+ if (states[id] && states[id].status !== "dismissed")
1315
+ throw new AppError("QUESTION_BUSY", "\u56DE\u7B54\u6B63\u5728\u63D0\u4EA4\u6216\u7ED3\u679C\u5F85\u6838\u5BF9\uFF0C\u8BF7\u5237\u65B0\u540E\u7EE7\u7EED", 409);
1316
+ }
1317
+ const ids = [...new Set(input.questionIds)].filter(
1318
+ (id) => !this.questionAnswered(history, id)
1319
+ );
1320
+ this.store.dispatch(input.clientOperationId);
1321
+ this.questionTracking.save(threadId, ids, "dismissed", input.clientOperationId);
1322
+ this.publishThread(threadId);
1323
+ return { result: { threadId, questionIds: ids } };
1324
+ });
1325
+ }
1326
+ questionItems(history) {
1327
+ return [...history.turns, ...this.projection.get(history.id)?.turns ?? []].flatMap(
1328
+ (turn) => turn.items
1329
+ );
1330
+ }
1331
+ findAsyncQuestion(history, id) {
1332
+ for (const item of this.questionItems(history)) {
1333
+ if (item.type !== "agentMessage") continue;
1334
+ const index = item.questions?.findIndex((_, index2) => asyncQuestionId(item.id, index2) === id);
1335
+ if (index !== void 0 && index >= 0) return { item, question: item.questions[index] };
1336
+ }
1337
+ }
1338
+ questionAnswered(history, id) {
1339
+ const source = this.findAsyncQuestion(history, id);
1340
+ return Boolean(
1341
+ source && this.questionItems(history).some(
1342
+ (item) => item.questionReplies?.some(
1343
+ (reply) => reply.questionItemId === id || reply.questionItemId === source.item.id && reply.question === source.question.title
1344
+ )
1345
+ )
1346
+ );
1347
+ }
1348
+ async claimQuestionReplies(threadId, text, operationId) {
1349
+ const replies = parseQuestionReplies(text);
1350
+ if (!replies) return;
1351
+ const history = this.normalize(await this.codex.readThread(threadId));
1352
+ this.workspaces.assertOwnership(history.projectId, history.cwd, history.id);
1353
+ this.projection.thread(history, true);
1354
+ const states = this.questionTracking.states(threadId);
1355
+ const ids = [];
1356
+ for (const reply of replies) {
1357
+ const source = this.findAsyncQuestion(history, reply.questionItemId) ?? (() => {
1358
+ const item = this.questionItems(history).find((item2) => item2.id === reply.questionItemId);
1359
+ const index2 = item?.questions?.findIndex((q) => q.title === reply.question);
1360
+ return item && index2 !== void 0 && index2 >= 0 ? this.findAsyncQuestion(history, asyncQuestionId(item.id, index2)) : void 0;
1361
+ })();
1362
+ const index = source?.item.questions?.indexOf(source.question);
1363
+ if (!source || index === void 0)
1364
+ throw new AppError("QUESTION_EXPIRED", "\u8BE5\u95EE\u9898\u5DF2\u4E0D\u5B58\u5728\uFF0C\u8BF7\u5237\u65B0\u4F1A\u8BDD", 409);
1365
+ if (!reply.answer.trim()) throw new AppError("VALIDATION_ERROR", "\u56DE\u7B54\u4E0D\u80FD\u4E3A\u7A7A");
1366
+ const id = asyncQuestionId(source.item.id, index);
1367
+ if (states[id] || this.questionAnswered(history, id) || ids.includes(id))
1368
+ throw new AppError("QUESTION_CONFLICT", "\u8BE5\u95EE\u9898\u5DF2\u5904\u7406\u6216\u6B63\u5728\u63D0\u4EA4\uFF0C\u8BF7\u5237\u65B0\u4F1A\u8BDD", 409);
1369
+ ids.push(id);
1370
+ }
1371
+ this.questionTracking.save(threadId, ids, "submitting", operationId);
1372
+ }
1266
1373
  getOperation(id) {
1267
1374
  const row = this.store.get(id);
1268
1375
  if (!row) throw new AppError("OPERATION_NOT_FOUND", "\u672A\u627E\u5230\u8BE5\u64CD\u4F5C", 404);
@@ -1370,9 +1477,14 @@ class GatewayService {
1370
1477
  const action = this.projection.resolveAction(target, "pending");
1371
1478
  if (action?.threadId) this.publishThread(action.threadId);
1372
1479
  }
1480
+ if (!uncertain && (kind === "turn.start" || kind === "turn.steer")) {
1481
+ this.questionTracking.release(input.clientOperationId);
1482
+ this.publishThread(target);
1483
+ }
1373
1484
  if (kind === "turn.start")
1374
1485
  this.capacityRetries.dispatchFailed(target, input.clientOperationId);
1375
- if (dispatched && kind === "turn.start") this.publishThread(target);
1486
+ if (dispatched && (kind === "turn.start" || kind === "turn.steer"))
1487
+ this.publishThread(target);
1376
1488
  this.events.publish("operation", operation);
1377
1489
  if (uncertain)
1378
1490
  throw new AppError(
@@ -1386,7 +1498,8 @@ class GatewayService {
1386
1498
  this.inFlightOperations.delete(input.clientOperationId);
1387
1499
  this.pendingThreadCreations.delete(input.clientOperationId);
1388
1500
  if (!this.store.activeForThread(target)) this.turnBaselines.delete(input.clientOperationId);
1389
- if (kind === "thread.compact") this.publishThread(target);
1501
+ if (kind === "thread.compact" || kind === "turn.start" || kind === "turn.steer")
1502
+ this.publishThread(target);
1390
1503
  }
1391
1504
  }
1392
1505
  normalize(thread, projectId, managed = false) {
@@ -1528,19 +1641,7 @@ class GatewayService {
1528
1641
  } else if (action.kind === "elicitation") {
1529
1642
  validateElicitationResolution(action.elicitation, resolution);
1530
1643
  } else if (action.kind === "questions") {
1531
- if (!("answers" in resolution)) throw new AppError("VALIDATION_ERROR", "\u8BF7\u6309\u95EE\u9898\u63D0\u4EA4\u7B54\u6848");
1532
- const questions = action.questions ?? [];
1533
- if (Object.keys(resolution.answers).some(
1534
- (id) => !questions.some((question) => question.id === id)
1535
- ))
1536
- throw new AppError("VALIDATION_ERROR", "\u56DE\u7B54\u5305\u542B\u672A\u77E5\u95EE\u9898");
1537
- for (const question of questions) {
1538
- const answers = resolution.answers[question.id];
1539
- if (!answers?.length || answers.some(
1540
- (answer) => !answer.trim() || !question.isOther && question.options.length > 0 && !question.options.some((option) => option.label === answer)
1541
- ))
1542
- throw new AppError("VALIDATION_ERROR", `\u95EE\u9898 ${question.header} \u7684\u56DE\u7B54\u4E0D\u7B26\u5408\u9009\u9879\u8981\u6C42`);
1543
- }
1644
+ questionAnswers(action.questions ?? [], resolution);
1544
1645
  } else if (!("decision" in resolution) || "content" in resolution || "persist" in resolution || !action.options.some((option) => option.id === resolution.decision))
1545
1646
  throw new AppError("VALIDATION_ERROR", "\u8BF7\u9009\u62E9\u4E0A\u6E38\u63D0\u4F9B\u7684\u5408\u6CD5\u9009\u9879");
1546
1647
  }
@@ -1616,7 +1717,22 @@ class GatewayService {
1616
1717
  return links;
1617
1718
  }
1618
1719
  threadView(thread, copy = true) {
1720
+ const submissions = new Map(
1721
+ this.store.pendingMessages(thread.id).map((message) => [message.id, message])
1722
+ );
1723
+ if (submissions.size)
1724
+ for (const turn of thread.turns)
1725
+ for (const item of turn.items) {
1726
+ const pending = item.clientId ? submissions.get(item.clientId) : void 0;
1727
+ if (pending && (!pending.turnId || pending.turnId === turn.id)) {
1728
+ Object.assign(item, mergeUserMessage(item, pending.item));
1729
+ this.store.confirmMessage(thread.id, turn.id, item);
1730
+ }
1731
+ }
1619
1732
  const result = copy ? structuredClone(thread) : { ...thread };
1733
+ const pendingMessages = this.store.pendingMessages(thread.id);
1734
+ if (pendingMessages.length) result.pendingMessages = pendingMessages;
1735
+ else delete result.pendingMessages;
1620
1736
  const links = this.capacityLinks.get(thread.id) ?? (thread.turns.some((turn) => !turn.items.some((item) => item.type === "userMessage")) ? this.retryLinks(thread.id) : void 0);
1621
1737
  result.turns = result.turns.map((turn) => {
1622
1738
  const root = links?.get(turn.id);
@@ -1626,6 +1742,13 @@ class GatewayService {
1626
1742
  if (retry) result.capacityRetry = structuredClone(retry);
1627
1743
  else delete result.capacityRetry;
1628
1744
  if (this.capacityRetries.pending(thread.id)) result.status = "running";
1745
+ result.questionTracking = this.questionTracking.states(thread.id);
1746
+ const savedActions = this.questionTracking.actions(thread.id);
1747
+ const actions = new Map(savedActions.map((action) => [action.actionId, action]));
1748
+ for (const action of thread.actions)
1749
+ if (action.status === "pending" || action.status === "responding" || !actions.has(action.actionId))
1750
+ actions.set(action.actionId, action);
1751
+ result.actions = [...actions.values()];
1629
1752
  result.archived = thread.archived ?? false;
1630
1753
  result.historyVisible = this.historyVisible(thread);
1631
1754
  const marker = this.store.activeForThread(thread.id);
@@ -1722,8 +1845,11 @@ class GatewayService {
1722
1845
  if (action.codexEpoch !== this.codex.epoch) return;
1723
1846
  const known = this.projection.actions.has(action.actionId);
1724
1847
  const owner = action.threadId ? this.projection.get(action.threadId) : void 0;
1725
- const previous = new Set(owner ? pendingAttention(owner).map(attentionKey) : []);
1848
+ const previous = new Set(
1849
+ owner ? pendingAttention(this.threadView(owner)).map(attentionKey) : []
1850
+ );
1726
1851
  this.projection.action(action);
1852
+ if (action.kind === "questions") this.questionTracking.saveAction(action);
1727
1853
  if (action.threadId) {
1728
1854
  this.publishThread(action.threadId);
1729
1855
  if (!known) this.publishNewAttention(action.threadId, previous);
@@ -1732,6 +1858,7 @@ class GatewayService {
1732
1858
  }
1733
1859
  if (event.type === "actionResolved") {
1734
1860
  const action = this.projection.resolveAction(event.actionId, "responded");
1861
+ if (action?.kind === "questions") this.questionTracking.saveAction(action);
1735
1862
  if (action?.threadId) this.publishThread(action.threadId);
1736
1863
  return;
1737
1864
  }
@@ -1749,7 +1876,7 @@ class GatewayService {
1749
1876
  return;
1750
1877
  }
1751
1878
  const previousAttention = new Set(
1752
- event.type === "item" || event.type === "turn" ? pendingAttention(thread).map(attentionKey) : []
1879
+ event.type === "item" || event.type === "turn" ? pendingAttention(this.threadView(thread)).map(attentionKey) : []
1753
1880
  );
1754
1881
  if (event.type === "tokenUsage") {
1755
1882
  if (this.projection.tokenUsage(thread.id, event.usage)) this.publishThread(thread.id);