dominds 1.24.1 → 1.24.3

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 (107) hide show
  1. package/dist/dialog-drive-work.d.ts +1 -0
  2. package/dist/dialog-drive-work.js +20 -1
  3. package/dist/docs/tellask-background-continuation-refactor.zh.md +144 -15
  4. package/dist/llm/kernel-driver/drive.js +35 -2
  5. package/dist/llm/kernel-driver/flow.js +296 -78
  6. package/dist/llm/kernel-driver/reply-guidance.js +0 -3
  7. package/dist/llm/kernel-driver/tellask-special.d.ts +1 -0
  8. package/dist/llm/kernel-driver/tellask-special.js +3 -0
  9. package/dist/llm/kernel-driver/types.d.ts +0 -3
  10. package/dist/persistence.d.ts +2 -0
  11. package/dist/persistence.js +57 -31
  12. package/package.json +3 -3
  13. package/webapp/dist/assets/{_basePickBy-LdPzzrA2.js → _basePickBy-ZLV93S3E.js} +3 -3
  14. package/webapp/dist/assets/{_basePickBy-LdPzzrA2.js.map → _basePickBy-ZLV93S3E.js.map} +1 -1
  15. package/webapp/dist/assets/{_baseUniq-Dd4qkGWy.js → _baseUniq-D0wSOJ06.js} +2 -2
  16. package/webapp/dist/assets/{_baseUniq-Dd4qkGWy.js.map → _baseUniq-D0wSOJ06.js.map} +1 -1
  17. package/webapp/dist/assets/{arc-Bx35xRdo.js → arc-BHclbMTS.js} +2 -2
  18. package/webapp/dist/assets/{arc-Bx35xRdo.js.map → arc-BHclbMTS.js.map} +1 -1
  19. package/webapp/dist/assets/{architectureDiagram-2XIMDMQ5-CqJear9j.js → architectureDiagram-2XIMDMQ5-CK99gE_D.js} +7 -7
  20. package/webapp/dist/assets/{architectureDiagram-2XIMDMQ5-CqJear9j.js.map → architectureDiagram-2XIMDMQ5-CK99gE_D.js.map} +1 -1
  21. package/webapp/dist/assets/{blockDiagram-WCTKOSBZ-9tLmXg6W.js → blockDiagram-WCTKOSBZ-fE5MBTEU.js} +7 -7
  22. package/webapp/dist/assets/{blockDiagram-WCTKOSBZ-9tLmXg6W.js.map → blockDiagram-WCTKOSBZ-fE5MBTEU.js.map} +1 -1
  23. package/webapp/dist/assets/{c4Diagram-IC4MRINW-Dzv3iLb1.js → c4Diagram-IC4MRINW-BSLyPyoU.js} +3 -3
  24. package/webapp/dist/assets/{c4Diagram-IC4MRINW-Dzv3iLb1.js.map → c4Diagram-IC4MRINW-BSLyPyoU.js.map} +1 -1
  25. package/webapp/dist/assets/{channel-DlYmbJjD.js → channel-DSvMpp-a.js} +2 -2
  26. package/webapp/dist/assets/{channel-DlYmbJjD.js.map → channel-DSvMpp-a.js.map} +1 -1
  27. package/webapp/dist/assets/{chunk-4BX2VUAB-H-sbLEAZ.js → chunk-4BX2VUAB-OXEX170k.js} +2 -2
  28. package/webapp/dist/assets/{chunk-4BX2VUAB-H-sbLEAZ.js.map → chunk-4BX2VUAB-OXEX170k.js.map} +1 -1
  29. package/webapp/dist/assets/{chunk-55IACEB6-DM99Uhn7.js → chunk-55IACEB6-BFQ_spQD.js} +2 -2
  30. package/webapp/dist/assets/{chunk-55IACEB6-DM99Uhn7.js.map → chunk-55IACEB6-BFQ_spQD.js.map} +1 -1
  31. package/webapp/dist/assets/{chunk-FMBD7UC4-BrYi5v3v.js → chunk-FMBD7UC4-CbQ2BBPs.js} +2 -2
  32. package/webapp/dist/assets/{chunk-FMBD7UC4-BrYi5v3v.js.map → chunk-FMBD7UC4-CbQ2BBPs.js.map} +1 -1
  33. package/webapp/dist/assets/{chunk-JSJVCQXG-xsaAqb_D.js → chunk-JSJVCQXG-C4P1mjCL.js} +2 -2
  34. package/webapp/dist/assets/{chunk-JSJVCQXG-xsaAqb_D.js.map → chunk-JSJVCQXG-C4P1mjCL.js.map} +1 -1
  35. package/webapp/dist/assets/{chunk-KX2RTZJC-DP9JzJzb.js → chunk-KX2RTZJC-BMd-daMY.js} +2 -2
  36. package/webapp/dist/assets/{chunk-KX2RTZJC-DP9JzJzb.js.map → chunk-KX2RTZJC-BMd-daMY.js.map} +1 -1
  37. package/webapp/dist/assets/{chunk-NQ4KR5QH-B1Dmz0tx.js → chunk-NQ4KR5QH-B_ZhWMXR.js} +4 -4
  38. package/webapp/dist/assets/{chunk-NQ4KR5QH-B1Dmz0tx.js.map → chunk-NQ4KR5QH-B_ZhWMXR.js.map} +1 -1
  39. package/webapp/dist/assets/{chunk-QZHKN3VN-1BrJQ9T8.js → chunk-QZHKN3VN-Cbf92xIw.js} +2 -2
  40. package/webapp/dist/assets/{chunk-QZHKN3VN-1BrJQ9T8.js.map → chunk-QZHKN3VN-Cbf92xIw.js.map} +1 -1
  41. package/webapp/dist/assets/{chunk-WL4C6EOR-m9798qm6.js → chunk-WL4C6EOR-PtH-blkK.js} +6 -6
  42. package/webapp/dist/assets/{chunk-WL4C6EOR-m9798qm6.js.map → chunk-WL4C6EOR-PtH-blkK.js.map} +1 -1
  43. package/webapp/dist/assets/{classDiagram-VBA2DB6C-DunVoVHy.js → classDiagram-VBA2DB6C-Dc3ncaD0.js} +7 -7
  44. package/webapp/dist/assets/{classDiagram-VBA2DB6C-DunVoVHy.js.map → classDiagram-VBA2DB6C-Dc3ncaD0.js.map} +1 -1
  45. package/webapp/dist/assets/{classDiagram-v2-RAHNMMFH-DunVoVHy.js → classDiagram-v2-RAHNMMFH-Dc3ncaD0.js} +7 -7
  46. package/webapp/dist/assets/{classDiagram-v2-RAHNMMFH-DunVoVHy.js.map → classDiagram-v2-RAHNMMFH-Dc3ncaD0.js.map} +1 -1
  47. package/webapp/dist/assets/{clone-CxYNYmli.js → clone-E9Ad85BC.js} +2 -2
  48. package/webapp/dist/assets/{clone-CxYNYmli.js.map → clone-E9Ad85BC.js.map} +1 -1
  49. package/webapp/dist/assets/{cose-bilkent-S5V4N54A-CnD5vxv9.js → cose-bilkent-S5V4N54A-B-nj0o74.js} +2 -2
  50. package/webapp/dist/assets/{cose-bilkent-S5V4N54A-CnD5vxv9.js.map → cose-bilkent-S5V4N54A-B-nj0o74.js.map} +1 -1
  51. package/webapp/dist/assets/{dagre-KLK3FWXG-D8iLo6g8.js → dagre-KLK3FWXG-CyJYNIbm.js} +7 -7
  52. package/webapp/dist/assets/{dagre-KLK3FWXG-D8iLo6g8.js.map → dagre-KLK3FWXG-CyJYNIbm.js.map} +1 -1
  53. package/webapp/dist/assets/{diagram-E7M64L7V-CCGf4yS4.js → diagram-E7M64L7V-C8eweQ7b.js} +8 -8
  54. package/webapp/dist/assets/{diagram-E7M64L7V-CCGf4yS4.js.map → diagram-E7M64L7V-C8eweQ7b.js.map} +1 -1
  55. package/webapp/dist/assets/{diagram-IFDJBPK2-nZVTTM2s.js → diagram-IFDJBPK2-DMdygRl0.js} +7 -7
  56. package/webapp/dist/assets/{diagram-IFDJBPK2-nZVTTM2s.js.map → diagram-IFDJBPK2-DMdygRl0.js.map} +1 -1
  57. package/webapp/dist/assets/{diagram-P4PSJMXO-DUG05oR4.js → diagram-P4PSJMXO-BQDZHb0a.js} +7 -7
  58. package/webapp/dist/assets/{diagram-P4PSJMXO-DUG05oR4.js.map → diagram-P4PSJMXO-BQDZHb0a.js.map} +1 -1
  59. package/webapp/dist/assets/{erDiagram-INFDFZHY-DTtcqarO.js → erDiagram-INFDFZHY-C1HaXN6E.js} +5 -5
  60. package/webapp/dist/assets/{erDiagram-INFDFZHY-DTtcqarO.js.map → erDiagram-INFDFZHY-C1HaXN6E.js.map} +1 -1
  61. package/webapp/dist/assets/{flowDiagram-PKNHOUZH-Ol68h2lV.js → flowDiagram-PKNHOUZH-24nNqQyo.js} +7 -7
  62. package/webapp/dist/assets/{flowDiagram-PKNHOUZH-Ol68h2lV.js.map → flowDiagram-PKNHOUZH-24nNqQyo.js.map} +1 -1
  63. package/webapp/dist/assets/{ganttDiagram-A5KZAMGK-BD9KkhMb.js → ganttDiagram-A5KZAMGK-BWPOFaLV.js} +3 -3
  64. package/webapp/dist/assets/{ganttDiagram-A5KZAMGK-BD9KkhMb.js.map → ganttDiagram-A5KZAMGK-BWPOFaLV.js.map} +1 -1
  65. package/webapp/dist/assets/{gitGraphDiagram-K3NZZRJ6-CZ4C5yhB.js → gitGraphDiagram-K3NZZRJ6-D7_L-p_Y.js} +8 -8
  66. package/webapp/dist/assets/{gitGraphDiagram-K3NZZRJ6-CZ4C5yhB.js.map → gitGraphDiagram-K3NZZRJ6-D7_L-p_Y.js.map} +1 -1
  67. package/webapp/dist/assets/{graph-BICDsOFt.js → graph-OHu4dL2n.js} +3 -3
  68. package/webapp/dist/assets/{graph-BICDsOFt.js.map → graph-OHu4dL2n.js.map} +1 -1
  69. package/webapp/dist/assets/{index-BTMpGPk_.js → index-CDCDAfqP.js} +238 -83
  70. package/webapp/dist/assets/{index-BTMpGPk_.js.map → index-CDCDAfqP.js.map} +1 -1
  71. package/webapp/dist/assets/{infoDiagram-LFFYTUFH-D0xrjViS.js → infoDiagram-LFFYTUFH-CvaBM5j6.js} +6 -6
  72. package/webapp/dist/assets/{infoDiagram-LFFYTUFH-D0xrjViS.js.map → infoDiagram-LFFYTUFH-CvaBM5j6.js.map} +1 -1
  73. package/webapp/dist/assets/{ishikawaDiagram-PHBUUO56-Beaj-xkw.js → ishikawaDiagram-PHBUUO56-DB1l2Uue.js} +2 -2
  74. package/webapp/dist/assets/{ishikawaDiagram-PHBUUO56-Beaj-xkw.js.map → ishikawaDiagram-PHBUUO56-DB1l2Uue.js.map} +1 -1
  75. package/webapp/dist/assets/{journeyDiagram-4ABVD52K-k7BmCpXO.js → journeyDiagram-4ABVD52K-TQR6_teO.js} +5 -5
  76. package/webapp/dist/assets/{journeyDiagram-4ABVD52K-k7BmCpXO.js.map → journeyDiagram-4ABVD52K-TQR6_teO.js.map} +1 -1
  77. package/webapp/dist/assets/{kanban-definition-K7BYSVSG-BBQOWu--.js → kanban-definition-K7BYSVSG-B-BOuC-U.js} +3 -3
  78. package/webapp/dist/assets/{kanban-definition-K7BYSVSG-BBQOWu--.js.map → kanban-definition-K7BYSVSG-B-BOuC-U.js.map} +1 -1
  79. package/webapp/dist/assets/{layout-B_h66HyR.js → layout-B8yqIqbx.js} +5 -5
  80. package/webapp/dist/assets/{layout-B_h66HyR.js.map → layout-B8yqIqbx.js.map} +1 -1
  81. package/webapp/dist/assets/{linear-QdCnoDG9.js → linear-CoLfiZKK.js} +2 -2
  82. package/webapp/dist/assets/{linear-QdCnoDG9.js.map → linear-CoLfiZKK.js.map} +1 -1
  83. package/webapp/dist/assets/{mindmap-definition-YRQLILUH-BTk4BxEf.js → mindmap-definition-YRQLILUH-P70BMIHI.js} +4 -4
  84. package/webapp/dist/assets/{mindmap-definition-YRQLILUH-BTk4BxEf.js.map → mindmap-definition-YRQLILUH-P70BMIHI.js.map} +1 -1
  85. package/webapp/dist/assets/{pieDiagram-SKSYHLDU-DQonY6Ln.js → pieDiagram-SKSYHLDU-DsS_4dTB.js} +8 -8
  86. package/webapp/dist/assets/{pieDiagram-SKSYHLDU-DQonY6Ln.js.map → pieDiagram-SKSYHLDU-DsS_4dTB.js.map} +1 -1
  87. package/webapp/dist/assets/{quadrantDiagram-337W2JSQ-6tqc3Gus.js → quadrantDiagram-337W2JSQ-DoM9PEq-.js} +3 -3
  88. package/webapp/dist/assets/{quadrantDiagram-337W2JSQ-6tqc3Gus.js.map → quadrantDiagram-337W2JSQ-DoM9PEq-.js.map} +1 -1
  89. package/webapp/dist/assets/{requirementDiagram-Z7DCOOCP-C6r4anqd.js → requirementDiagram-Z7DCOOCP-Bn3lYMMI.js} +4 -4
  90. package/webapp/dist/assets/{requirementDiagram-Z7DCOOCP-C6r4anqd.js.map → requirementDiagram-Z7DCOOCP-Bn3lYMMI.js.map} +1 -1
  91. package/webapp/dist/assets/{sankeyDiagram-WA2Y5GQK-DE2CTSeA.js → sankeyDiagram-WA2Y5GQK-97kCegRT.js} +2 -2
  92. package/webapp/dist/assets/{sankeyDiagram-WA2Y5GQK-DE2CTSeA.js.map → sankeyDiagram-WA2Y5GQK-97kCegRT.js.map} +1 -1
  93. package/webapp/dist/assets/{sequenceDiagram-2WXFIKYE-DSnyMSe6.js → sequenceDiagram-2WXFIKYE-DXqjQjf6.js} +4 -4
  94. package/webapp/dist/assets/{sequenceDiagram-2WXFIKYE-DSnyMSe6.js.map → sequenceDiagram-2WXFIKYE-DXqjQjf6.js.map} +1 -1
  95. package/webapp/dist/assets/{stateDiagram-RAJIS63D-BsQOXkdZ.js → stateDiagram-RAJIS63D-DQcTPKWP.js} +9 -9
  96. package/webapp/dist/assets/{stateDiagram-RAJIS63D-BsQOXkdZ.js.map → stateDiagram-RAJIS63D-DQcTPKWP.js.map} +1 -1
  97. package/webapp/dist/assets/{stateDiagram-v2-FVOUBMTO-DW0AWykH.js → stateDiagram-v2-FVOUBMTO-DHmxRVJn.js} +5 -5
  98. package/webapp/dist/assets/{stateDiagram-v2-FVOUBMTO-DW0AWykH.js.map → stateDiagram-v2-FVOUBMTO-DHmxRVJn.js.map} +1 -1
  99. package/webapp/dist/assets/{timeline-definition-YZTLITO2-Dyxr7fE4.js → timeline-definition-YZTLITO2-BlovQQ4B.js} +3 -3
  100. package/webapp/dist/assets/{timeline-definition-YZTLITO2-Dyxr7fE4.js.map → timeline-definition-YZTLITO2-BlovQQ4B.js.map} +1 -1
  101. package/webapp/dist/assets/{treemap-KZPCXAKY-CPaPLIL2.js → treemap-KZPCXAKY-CGu93c9S.js} +5 -5
  102. package/webapp/dist/assets/{treemap-KZPCXAKY-CPaPLIL2.js.map → treemap-KZPCXAKY-CGu93c9S.js.map} +1 -1
  103. package/webapp/dist/assets/{vennDiagram-LZ73GAT5-CTduB1wl.js → vennDiagram-LZ73GAT5-Do1jprrz.js} +2 -2
  104. package/webapp/dist/assets/{vennDiagram-LZ73GAT5-CTduB1wl.js.map → vennDiagram-LZ73GAT5-Do1jprrz.js.map} +1 -1
  105. package/webapp/dist/assets/{xychartDiagram-JWTSCODW-Sb80BTd7.js → xychartDiagram-JWTSCODW-BKa1DxVq.js} +3 -3
  106. package/webapp/dist/assets/{xychartDiagram-JWTSCODW-Sb80BTd7.js.map → xychartDiagram-JWTSCODW-BKa1DxVq.js.map} +1 -1
  107. package/webapp/dist/index.html +1 -1
@@ -5,6 +5,7 @@ const id_1 = require("@longrun-ai/kernel/utils/id");
5
5
  const run_control_1 = require("../../apps/run-control");
6
6
  const dialog_1 = require("../../dialog");
7
7
  const dialog_display_state_1 = require("../../dialog-display-state");
8
+ const dialog_drive_work_1 = require("../../dialog-drive-work");
8
9
  const dialog_global_registry_1 = require("../../dialog-global-registry");
9
10
  const dialog_interruption_1 = require("../../dialog-interruption");
10
11
  const dialog_latest_state_1 = require("../../dialog-latest-state");
@@ -69,6 +70,125 @@ async function queueReplyReminderFollowUp(args) {
69
70
  function isReplyToolReminderPrompt(prompt) {
70
71
  return typeof prompt?.content === 'string' && (0, reply_prompt_copy_1.isReplyToolReminderPromptContent)(prompt.content);
71
72
  }
73
+ function hasSameReplyDirective(left, right) {
74
+ return (left.expectedReplyCallName === right.expectedReplyCallName &&
75
+ left.targetDialogId === right.targetDialogId &&
76
+ left.targetCallId === right.targetCallId &&
77
+ left.tellaskContent === right.tellaskContent);
78
+ }
79
+ function buildCurrentSideDialogAssignmentReplyDirective(dialog) {
80
+ switch (dialog.assignmentFromAsker.callName) {
81
+ case 'tellask':
82
+ return {
83
+ expectedReplyCallName: 'replyTellask',
84
+ targetDialogId: dialog.assignmentFromAsker.askerDialogId,
85
+ targetCallId: dialog.assignmentFromAsker.callId,
86
+ tellaskContent: dialog.assignmentFromAsker.tellaskContent,
87
+ };
88
+ case 'tellaskSessionless':
89
+ case 'freshBootsReasoning':
90
+ return {
91
+ expectedReplyCallName: 'replyTellaskSessionless',
92
+ targetDialogId: dialog.assignmentFromAsker.askerDialogId,
93
+ targetCallId: dialog.assignmentFromAsker.callId,
94
+ tellaskContent: dialog.assignmentFromAsker.tellaskContent,
95
+ };
96
+ default: {
97
+ const _exhaustive = dialog.assignmentFromAsker.callName;
98
+ throw new Error(`Unsupported sideDialog assignment callName: ${_exhaustive}`);
99
+ }
100
+ }
101
+ }
102
+ function isQueuedReplyObligationContinuation(prompt) {
103
+ return ((prompt.kind === 'new_course_runtime_reply' ||
104
+ prompt.kind === 'new_course_runtime_sideDialog') &&
105
+ (0, reply_prompt_copy_1.isReplyToolReminderPromptContent)(prompt.prompt));
106
+ }
107
+ function latestHasTellaskResultForCallId(latest, targetCallId) {
108
+ return (latest?.tellaskResults.results.some((entry) => entry.callId.trim() === targetCallId) === true);
109
+ }
110
+ async function claimQueuedReplyObligationContinuation(args) {
111
+ const directive = args.prompt.tellaskReplyDirective;
112
+ const targetCallId = directive.targetCallId.trim();
113
+ const targetDialogId = directive.targetDialogId.trim();
114
+ if (targetCallId === '' || targetDialogId === '') {
115
+ throw new Error(`reply obligation continuation invariant violation: empty target identity ` +
116
+ `(dialog=${args.dialog.id.valueOf()}, targetDialogId=${directive.targetDialogId}, targetCallId=${directive.targetCallId})`);
117
+ }
118
+ const latest = await persistence_1.DialogPersistence.loadDialogLatest(args.dialog.id, args.dialog.status);
119
+ if (latest?.sideDialogFinalResponse?.callId.trim() === targetCallId) {
120
+ return 'stale';
121
+ }
122
+ if (latestHasTellaskResultForCallId(latest, targetCallId)) {
123
+ return 'stale';
124
+ }
125
+ const targetLatest = targetDialogId === args.dialog.id.selfId
126
+ ? latest
127
+ : await persistence_1.DialogPersistence.loadDialogLatest(new dialog_1.DialogID(targetDialogId, args.dialog.id.rootId), args.dialog.status);
128
+ if (latestHasTellaskResultForCallId(targetLatest, targetCallId)) {
129
+ return 'stale';
130
+ }
131
+ if (args.dialog instanceof dialog_1.SideDialog) {
132
+ const assignmentDirective = buildCurrentSideDialogAssignmentReplyDirective(args.dialog);
133
+ if (hasSameReplyDirective(assignmentDirective, directive)) {
134
+ return 'claimed';
135
+ }
136
+ }
137
+ const activeDirective = await (0, tellask_special_1.loadActiveTellaskReplyDirective)(args.dialog);
138
+ if (!activeDirective) {
139
+ return 'stale';
140
+ }
141
+ if (activeDirective.targetCallId !== directive.targetCallId) {
142
+ return 'stale';
143
+ }
144
+ if (!hasSameReplyDirective(activeDirective, directive)) {
145
+ throw new Error(`reply obligation continuation invariant violation: active obligation changed for callId=${directive.targetCallId} ` +
146
+ `(dialog=${args.dialog.id.valueOf()}, expectedReplyCallName=${directive.expectedReplyCallName}, ` +
147
+ `activeReplyCallName=${activeDirective.expectedReplyCallName}, targetDialogId=${directive.targetDialogId}, ` +
148
+ `activeTargetDialogId=${activeDirective.targetDialogId})`);
149
+ }
150
+ return 'claimed';
151
+ }
152
+ async function resolveSideDialogReplyDirectiveForAssistantOutput(args) {
153
+ const replyTarget = args.replyTarget;
154
+ const targetCallId = replyTarget?.callId.trim();
155
+ if (!replyTarget || !targetCallId) {
156
+ return args.currentDirective;
157
+ }
158
+ if (args.currentDirective?.targetCallId === targetCallId) {
159
+ return args.currentDirective;
160
+ }
161
+ const latest = await persistence_1.DialogPersistence.loadDialogLatest(args.dialog.id, args.dialog.status);
162
+ if (!latest) {
163
+ return args.currentDirective;
164
+ }
165
+ if (latest.sideDialogFinalResponse?.callId.trim() === targetCallId) {
166
+ return args.currentDirective;
167
+ }
168
+ if (latestHasTellaskResultForCallId(latest, targetCallId)) {
169
+ return args.currentDirective;
170
+ }
171
+ const assignmentDirective = buildCurrentSideDialogAssignmentReplyDirective(args.dialog);
172
+ if (assignmentDirective.targetCallId !== targetCallId) {
173
+ return args.currentDirective;
174
+ }
175
+ if (assignmentDirective.targetDialogId !== replyTarget.callerDialogId ||
176
+ assignmentDirective.targetCallId !== replyTarget.callId) {
177
+ return args.currentDirective;
178
+ }
179
+ const latestAssignmentAnchor = latest.latestAssignmentAnchor;
180
+ if (latestAssignmentAnchor?.callId !== targetCallId ||
181
+ args.responseGenseq < latestAssignmentAnchor.assignmentGenseq) {
182
+ return args.currentDirective;
183
+ }
184
+ const activeDirective = await (0, tellask_special_1.loadActiveTellaskReplyDirective)(args.dialog);
185
+ if (activeDirective && !hasSameReplyDirective(activeDirective, assignmentDirective)) {
186
+ throw new Error(`sideDialog assistant output reply directive invariant violation: active obligation does not match latest assignment ` +
187
+ `(dialog=${args.dialog.id.valueOf()}, targetCallId=${targetCallId}, ` +
188
+ `activeTargetCallId=${activeDirective.targetCallId}, assignmentTargetCallId=${assignmentDirective.targetCallId})`);
189
+ }
190
+ return activeDirective ?? assignmentDirective;
191
+ }
72
192
  function hasQ4HAnswerCallId(callId) {
73
193
  return typeof callId === 'string' && callId.trim() !== '';
74
194
  }
@@ -293,13 +413,6 @@ async function clearStaleSideDialogRunControlForFinalResponse(args) {
293
413
  previousNextStepTriggerCount: latest.nextStep.triggers.length,
294
414
  };
295
415
  }
296
- function hasNoPromptSideDialogResumeEntitlement(dialog, driveOptions) {
297
- const entitlement = driveOptions?.noPromptSideDialogResumeEntitlement;
298
- if (!entitlement) {
299
- return false;
300
- }
301
- return entitlement.callerDialogId === dialog.id.selfId;
302
- }
303
416
  function hasResultArrivalTrigger(latest) {
304
417
  return latest?.nextStep.triggers.some((trigger) => trigger.kind === 'result_arrival') === true;
305
418
  }
@@ -408,19 +521,19 @@ async function inspectNoPromptSideDialogDrive(args) {
408
521
  const sideDialogFinalResponseCallId = latest?.sideDialogFinalResponse?.callId;
409
522
  const explicitInterruptedResumeAllowed = args.driveOptions?.allowResumeFromInterrupted === true &&
410
523
  latest?.executionMarker?.kind === 'interrupted';
411
- const inProgressGenerationResumeAllowed = args.driveOptions?.resumeInProgressGeneration === true;
524
+ const inProgressGenerationResumeAllowed = args.driveOptions?.resumeInProgressGeneration === true &&
525
+ latest !== null &&
526
+ latest !== undefined &&
527
+ (0, dialog_drive_work_1.hasRecoverableGenerationBeyondFinalResponse)(latest);
412
528
  const resolvedPendingSideDialogReplyEntitlement = hasResolvedPendingSideDialogReplyEntitlement(args.dialog, args.driveOptions);
413
529
  const resultArrivalTriggerPresent = hasResultArrivalTrigger(latest);
414
530
  const supplyResponseCallerReviveAllowed = hasCallerReviveEntitlement(args.dialog, args.driveOptions) &&
415
531
  (!resolvedPendingSideDialogReplyEntitlement || resultArrivalTriggerPresent);
416
532
  const backendLoopDurableWorkAllowed = source === 'kernel_driver_backend_loop' && resultArrivalTriggerPresent;
417
- const replyObligationFollowUpAllowed = source === 'kernel_driver_follow_up' &&
418
- args.driveOptions?.noPromptSideDialogResumeEntitlement?.reason ===
419
- 'reply_obligation_follow_up' &&
420
- hasNoPromptSideDialogResumeEntitlement(args.dialog, args.driveOptions);
421
533
  const finalResponseResultArrivalReviveAllowed = sideDialogFinalResponseCallId !== undefined &&
422
534
  ((resolvedPendingSideDialogReplyEntitlement && resultArrivalTriggerPresent) ||
423
- backendLoopDurableWorkAllowed);
535
+ backendLoopDurableWorkAllowed ||
536
+ inProgressGenerationResumeAllowed);
424
537
  if (sideDialogFinalResponseCallId !== undefined && !finalResponseResultArrivalReviveAllowed) {
425
538
  return {
426
539
  shouldReject: true,
@@ -431,11 +544,20 @@ async function inspectNoPromptSideDialogDrive(args) {
431
544
  sideDialogFinalResponseCallId,
432
545
  };
433
546
  }
547
+ if (resolvedPendingSideDialogReplyEntitlement && !resultArrivalTriggerPresent) {
548
+ return {
549
+ shouldReject: true,
550
+ source,
551
+ rejection: 'stale_consumed_result_arrival',
552
+ displayState,
553
+ currentCourse,
554
+ sideDialogFinalResponseCallId,
555
+ };
556
+ }
434
557
  if (!explicitInterruptedResumeAllowed &&
435
558
  !inProgressGenerationResumeAllowed &&
436
559
  !supplyResponseCallerReviveAllowed &&
437
- !backendLoopDurableWorkAllowed &&
438
- !replyObligationFollowUpAllowed) {
560
+ !backendLoopDurableWorkAllowed) {
439
561
  return {
440
562
  shouldReject: true,
441
563
  source,
@@ -539,71 +661,96 @@ async function surfaceRuntimeGuide(dialog, content) {
539
661
  }
540
662
  async function resolveEffectivePrompt(dialog, humanPrompt) {
541
663
  if (humanPrompt) {
542
- return { prompt: humanPrompt, fromUpNext: false };
664
+ return { prompt: humanPrompt, fromUpNext: false, droppedStaleQueuedContinuation: false };
543
665
  }
544
- const upNext = dialog.peekUpNext();
545
- if (!upNext) {
546
- return {
547
- prompt: await maybeResolveDeferredReplyReassertionPrompt(dialog),
548
- fromUpNext: false,
549
- };
550
- }
551
- return {
552
- fromUpNext: true,
553
- prompt: (() => {
554
- const normalizedUserLanguageCode = upNext.userLanguageCode === 'zh' || upNext.userLanguageCode === 'en'
555
- ? upNext.userLanguageCode
556
- : undefined;
557
- const common = {
558
- content: upNext.prompt,
559
- msgId: upNext.msgId,
560
- grammar: upNext.grammar ?? 'markdown',
561
- userLanguageCode: normalizedUserLanguageCode,
562
- runControl: upNext.runControl,
666
+ let droppedStaleQueuedContinuation = false;
667
+ for (;;) {
668
+ const upNext = dialog.peekUpNext();
669
+ if (!upNext) {
670
+ return {
671
+ prompt: await maybeResolveDeferredReplyReassertionPrompt(dialog),
672
+ fromUpNext: false,
673
+ droppedStaleQueuedContinuation,
563
674
  };
564
- switch (upNext.kind) {
565
- case 'user_generation_boundary':
566
- case 'deferred_q4h_answer': {
567
- const prompt = {
568
- ...common,
569
- origin: 'user',
570
- ...(upNext.q4hAnswerCallId === undefined
571
- ? {}
572
- : { q4hAnswerCallId: upNext.q4hAnswerCallId }),
573
- };
574
- return prompt;
675
+ }
676
+ if (isQueuedReplyObligationContinuation(upNext)) {
677
+ const claim = await claimQueuedReplyObligationContinuation({ dialog, prompt: upNext });
678
+ if (claim === 'stale') {
679
+ const discarded = dialog.takeUpNext();
680
+ if (!discarded || discarded.msgId !== upNext.msgId) {
681
+ throw new Error(`reply obligation continuation invariant violation: expected queued prompt ${upNext.msgId} before stale discard`);
575
682
  }
576
- case 'registered_assignment_update':
577
- case 'new_course_runtime_guide':
578
- case 'new_course_runtime_reply':
579
- case 'new_course_runtime_sideDialog': {
580
- const runtimeCommon = {
581
- ...common,
582
- origin: 'runtime',
583
- ...(upNext.skipTaskdoc === undefined ? {} : { skipTaskdoc: upNext.skipTaskdoc }),
584
- };
585
- if (upNext.kind === 'registered_assignment_update' ||
586
- upNext.kind === 'new_course_runtime_sideDialog') {
683
+ await persistence_1.DialogPersistence.clearPendingRuntimePrompt(dialog.id, upNext.msgId, dialog.status);
684
+ log_1.log.debug('kernel-driver dropped stale reply obligation continuation', undefined, {
685
+ dialogId: dialog.id.valueOf(),
686
+ rootId: dialog.id.rootId,
687
+ selfId: dialog.id.selfId,
688
+ msgId: upNext.msgId,
689
+ targetCallId: upNext.tellaskReplyDirective.targetCallId,
690
+ expectedReplyCallName: upNext.tellaskReplyDirective.expectedReplyCallName,
691
+ });
692
+ droppedStaleQueuedContinuation = true;
693
+ continue;
694
+ }
695
+ }
696
+ return {
697
+ fromUpNext: true,
698
+ droppedStaleQueuedContinuation,
699
+ prompt: (() => {
700
+ const normalizedUserLanguageCode = upNext.userLanguageCode === 'zh' || upNext.userLanguageCode === 'en'
701
+ ? upNext.userLanguageCode
702
+ : undefined;
703
+ const common = {
704
+ content: upNext.prompt,
705
+ msgId: upNext.msgId,
706
+ grammar: upNext.grammar ?? 'markdown',
707
+ userLanguageCode: normalizedUserLanguageCode,
708
+ runControl: upNext.runControl,
709
+ };
710
+ switch (upNext.kind) {
711
+ case 'user_generation_boundary':
712
+ case 'deferred_q4h_answer': {
587
713
  const prompt = {
588
- ...runtimeCommon,
589
- tellaskReplyDirective: upNext.tellaskReplyDirective,
590
- calleeDialogReplyTarget: upNext.calleeDialogReplyTarget,
714
+ ...common,
715
+ origin: 'user',
716
+ ...(upNext.q4hAnswerCallId === undefined
717
+ ? {}
718
+ : { q4hAnswerCallId: upNext.q4hAnswerCallId }),
591
719
  };
592
720
  return prompt;
593
721
  }
594
- if (upNext.kind === 'new_course_runtime_reply') {
595
- const prompt = {
596
- ...runtimeCommon,
597
- tellaskReplyDirective: upNext.tellaskReplyDirective,
722
+ case 'registered_assignment_update':
723
+ case 'new_course_runtime_guide':
724
+ case 'new_course_runtime_reply':
725
+ case 'new_course_runtime_sideDialog': {
726
+ const runtimeCommon = {
727
+ ...common,
728
+ origin: 'runtime',
729
+ ...(upNext.skipTaskdoc === undefined ? {} : { skipTaskdoc: upNext.skipTaskdoc }),
598
730
  };
731
+ if (upNext.kind === 'registered_assignment_update' ||
732
+ upNext.kind === 'new_course_runtime_sideDialog') {
733
+ const prompt = {
734
+ ...runtimeCommon,
735
+ tellaskReplyDirective: upNext.tellaskReplyDirective,
736
+ calleeDialogReplyTarget: upNext.calleeDialogReplyTarget,
737
+ };
738
+ return prompt;
739
+ }
740
+ if (upNext.kind === 'new_course_runtime_reply') {
741
+ const prompt = {
742
+ ...runtimeCommon,
743
+ tellaskReplyDirective: upNext.tellaskReplyDirective,
744
+ };
745
+ return prompt;
746
+ }
747
+ const prompt = runtimeCommon;
599
748
  return prompt;
600
749
  }
601
- const prompt = runtimeCommon;
602
- return prompt;
603
750
  }
604
- }
605
- })(),
606
- };
751
+ })(),
752
+ };
753
+ }
607
754
  }
608
755
  async function executeDriveRound(args) {
609
756
  const [dialog, humanPrompt, waitInQue, driveOptions] = args.driveArgs;
@@ -651,7 +798,7 @@ async function executeDriveRound(args) {
651
798
  if (!cleanup.cleared) {
652
799
  await persistence_1.DialogPersistence.removeDriveWatchForDialog(dialog.id, dialog.status);
653
800
  }
654
- log_1.log.warn('Dropped stale no-prompt sideDialog drive after final response anchor', undefined, {
801
+ log_1.log.debug('Dropped stale no-prompt sideDialog drive after final response anchor', undefined, {
655
802
  dialogId: dialog.id.valueOf(),
656
803
  rootId: dialog.id.rootId,
657
804
  selfId: dialog.id.selfId,
@@ -708,6 +855,22 @@ async function executeDriveRound(args) {
708
855
  try {
709
856
  const inspection = await inspectNoPromptSideDialogDrive({ dialog, driveOptions });
710
857
  if (inspection.shouldReject) {
858
+ if (inspection.rejection === 'stale_consumed_result_arrival') {
859
+ log_1.log.debug('Dropped stale no-prompt sideDialog caller revive after result arrival', undefined, {
860
+ dialogId: dialog.id.valueOf(),
861
+ rootId: dialog.id.rootId,
862
+ selfId: dialog.id.selfId,
863
+ source: inspection.source,
864
+ reason: driveOptions?.reason ?? null,
865
+ rejection: inspection.rejection,
866
+ allowResumeFromInterrupted: driveOptions?.allowResumeFromInterrupted === true,
867
+ displayState: inspection.displayState ?? null,
868
+ currentCourse: inspection.currentCourse,
869
+ sideDialogFinalResponseCallId: inspection.sideDialogFinalResponseCallId ?? null,
870
+ waitInQue,
871
+ });
872
+ return;
873
+ }
711
874
  log_1.log.error('Rejected unexpected no-prompt sideDialog drive request', undefined, {
712
875
  dialogId: dialog.id.valueOf(),
713
876
  rootId: dialog.id.rootId,
@@ -904,6 +1067,18 @@ async function executeDriveRound(args) {
904
1067
  dialog,
905
1068
  latest: latestBeforeCore,
906
1069
  }));
1070
+ if (resolvedPrompt.droppedStaleQueuedContinuation &&
1071
+ effectivePrompt === undefined &&
1072
+ !(0, dialog_drive_work_1.hasDurableDriveWork)(latestBeforeCore)) {
1073
+ log_1.log.debug('kernel-driver stopped after dropping stale queued continuation', undefined, {
1074
+ dialogId: dialog.id.valueOf(),
1075
+ rootId: dialog.id.rootId,
1076
+ selfId: dialog.id.selfId,
1077
+ source: driveSource,
1078
+ reason: driveOptions?.reason ?? null,
1079
+ });
1080
+ return;
1081
+ }
907
1082
  await applyRegisteredDialogRunControlsBeforeDrive({
908
1083
  dialog,
909
1084
  humanPrompt,
@@ -937,7 +1112,7 @@ async function executeDriveRound(args) {
937
1112
  replyGuidance.deferredReplyReassertionDirective !== undefined;
938
1113
  activeTellaskReplyDirective = replyGuidance.activeReplyDirective;
939
1114
  activePromptWasReplyToolReminder = isReplyToolReminderPrompt(effectivePrompt);
940
- const activePromptCarriesReplyDirective = effectivePrompt?.tellaskReplyDirective !== undefined &&
1115
+ let activePromptCarriesReplyDirective = effectivePrompt?.tellaskReplyDirective !== undefined &&
941
1116
  activeTellaskReplyDirective !== undefined &&
942
1117
  effectivePrompt.tellaskReplyDirective.targetCallId ===
943
1118
  activeTellaskReplyDirective.targetCallId;
@@ -968,7 +1143,31 @@ async function executeDriveRound(args) {
968
1143
  calleeDialogReplyTarget = driveResult.lastAssistantReplyTarget ?? calleeDialogReplyTarget;
969
1144
  interruptedBySignal = (0, dialog_display_state_1.getActiveRunSignal)(dialog.id)?.aborted === true;
970
1145
  if (!interruptedBySignal) {
971
- followUp = dialog.takeUpNext();
1146
+ const queuedFollowUp = dialog.takeUpNext();
1147
+ if (queuedFollowUp && isQueuedReplyObligationContinuation(queuedFollowUp)) {
1148
+ const claim = await claimQueuedReplyObligationContinuation({
1149
+ dialog,
1150
+ prompt: queuedFollowUp,
1151
+ });
1152
+ if (claim === 'stale') {
1153
+ await persistence_1.DialogPersistence.clearPendingRuntimePrompt(dialog.id, queuedFollowUp.msgId, dialog.status);
1154
+ log_1.log.debug('kernel-driver dropped stale reply obligation follow-up after core', undefined, {
1155
+ dialogId: dialog.id.valueOf(),
1156
+ rootId: dialog.id.rootId,
1157
+ selfId: dialog.id.selfId,
1158
+ msgId: queuedFollowUp.msgId,
1159
+ targetCallId: queuedFollowUp.tellaskReplyDirective.targetCallId,
1160
+ expectedReplyCallName: queuedFollowUp.tellaskReplyDirective.expectedReplyCallName,
1161
+ });
1162
+ followUp = undefined;
1163
+ }
1164
+ else {
1165
+ followUp = queuedFollowUp;
1166
+ }
1167
+ }
1168
+ else {
1169
+ followUp = queuedFollowUp;
1170
+ }
972
1171
  }
973
1172
  let tailError;
974
1173
  try {
@@ -1016,6 +1215,31 @@ async function executeDriveRound(args) {
1016
1215
  });
1017
1216
  }
1018
1217
  else {
1218
+ const replyDirectiveForAssistantOutput = await resolveSideDialogReplyDirectiveForAssistantOutput({
1219
+ dialog,
1220
+ responseGenseq: directFallbackResponse.responseGenseq,
1221
+ replyTarget: driveResult.lastAssistantReplyTarget,
1222
+ currentDirective: activeTellaskReplyDirective,
1223
+ });
1224
+ if (replyDirectiveForAssistantOutput !== undefined &&
1225
+ replyDirectiveForAssistantOutput.targetCallId !==
1226
+ activeTellaskReplyDirective?.targetCallId) {
1227
+ // `driveDialogStreamCore` may already have consumed a queued assignment-update prompt
1228
+ // inside the same drive, so rebind the tail decision to the assistant output target.
1229
+ log_1.log.debug('kernel-driver rebound sideDialog reply directive to latest assistant output target', undefined, {
1230
+ dialogId: dialog.id.valueOf(),
1231
+ previousTargetCallId: activeTellaskReplyDirective?.targetCallId ?? null,
1232
+ nextTargetCallId: replyDirectiveForAssistantOutput.targetCallId,
1233
+ responseGenseq: directFallbackResponse.responseGenseq,
1234
+ replyTargetCallId: driveResult.lastAssistantReplyTarget?.callId ?? null,
1235
+ });
1236
+ }
1237
+ activeTellaskReplyDirective = replyDirectiveForAssistantOutput;
1238
+ activePromptCarriesReplyDirective =
1239
+ activePromptCarriesReplyDirective ||
1240
+ (activeTellaskReplyDirective !== undefined &&
1241
+ driveResult.lastAssistantReplyTarget?.callId ===
1242
+ activeTellaskReplyDirective.targetCallId);
1019
1243
  const hasFollowUp = followUp !== undefined;
1020
1244
  const suspension = await dialog.getSuspensionStatus();
1021
1245
  const backgroundCalleeBlocksImplicitReply = suspension.backgroundCalleeDialogs &&
@@ -1190,12 +1414,6 @@ async function executeDriveRound(args) {
1190
1414
  driveOptions: {
1191
1415
  source: 'kernel_driver_follow_up',
1192
1416
  reason: 'follow_up_prompt',
1193
- noPromptSideDialogResumeEntitlement: dialog instanceof dialog_1.SideDialog
1194
- ? {
1195
- callerDialogId: dialog.id.selfId,
1196
- reason: 'reply_obligation_follow_up',
1197
- }
1198
- : undefined,
1199
1417
  },
1200
1418
  });
1201
1419
  return driveResult;
@@ -125,9 +125,6 @@ async function resolveFreshCurrentSideDialogAssignmentDirective(args) {
125
125
  if (!latest) {
126
126
  return undefined;
127
127
  }
128
- if (latest.pendingRuntimePrompt?.msgId !== args.prompt.msgId) {
129
- return undefined;
130
- }
131
128
  if (latest.sideDialogFinalResponse?.callId === currentAssignmentDirective.targetCallId.trim()) {
132
129
  return undefined;
133
130
  }
@@ -122,6 +122,7 @@ export type TellaskFunctionRoundResult = Readonly<{
122
122
  hasImmediateTellaskOutputs: boolean;
123
123
  immediateTellaskOutputCallIds: readonly string[];
124
124
  shouldStopAfterReplyTool: boolean;
125
+ shouldStopAfterPendingTellaskWait: boolean;
125
126
  }>;
126
127
  export declare function processTellaskFunctionRound(args: {
127
128
  dlg: Dialog;
@@ -2390,6 +2390,7 @@ async function processTellaskFunctionRound(args) {
2390
2390
  const tellaskToolOutputs = [];
2391
2391
  const immediateTellaskOutputCallIds = [];
2392
2392
  let hasImmediateTellaskOutputs = false;
2393
+ let shouldStopAfterPendingTellaskWait = false;
2393
2394
  for (const output of tellaskExecution.toolOutputs) {
2394
2395
  if (output.type === 'func_result_msg') {
2395
2396
  const result = output;
@@ -2445,6 +2446,7 @@ async function processTellaskFunctionRound(args) {
2445
2446
  });
2446
2447
  tellaskFuncResultByCallId.set(call.callId, pendingResult);
2447
2448
  tellaskFuncResults.push(pendingResult);
2449
+ shouldStopAfterPendingTellaskWait = true;
2448
2450
  }
2449
2451
  for (const result of tellaskFuncResults) {
2450
2452
  await persistTellaskFuncResult(args.dlg, result);
@@ -2459,5 +2461,6 @@ async function processTellaskFunctionRound(args) {
2459
2461
  hasImmediateTellaskOutputs,
2460
2462
  immediateTellaskOutputCallIds,
2461
2463
  shouldStopAfterReplyTool: orderedInvalidCalls.length === 0 && tellaskExecution.successfulReplyCallIds.length > 0,
2464
+ shouldStopAfterPendingTellaskWait,
2462
2465
  };
2463
2466
  }
@@ -21,9 +21,6 @@ export type KernelDriverDriveOptions = Readonly<{
21
21
  sideDialogId?: string;
22
22
  callType?: 'A' | 'B' | 'C';
23
23
  callId?: string;
24
- }> | Readonly<{
25
- callerDialogId: string;
26
- reason: 'reply_obligation_follow_up';
27
24
  }> | Readonly<{
28
25
  callerDialogId: string;
29
26
  reason: 'resolved_pending_sideDialog_reply';
@@ -455,6 +455,7 @@ export declare class DialogPersistence {
455
455
  static loadActiveCalleeDispatches(mainDialogId: DialogID, status?: DialogStatusKind): Promise<ActiveCalleeDispatchRecord[]>;
456
456
  private static isActiveCalleeDispatchRecord;
457
457
  private static activeCalleeDispatchCalleeDialogId;
458
+ private static buildActiveCalleeRecordFromDispatch;
458
459
  private static isActiveCalleeCompletion;
459
460
  private static isActiveCalleeRecord;
460
461
  private static isActiveCalleeBatch;
@@ -477,6 +478,7 @@ export declare class DialogPersistence {
477
478
  private static loadDriveWatchFromDisk;
478
479
  private static writeDriveWatchToDisk;
479
480
  private static mutateDriveWatch;
481
+ private static removeWithRetry;
480
482
  static loadDriveWatchedDialogIds(rootDialogId: DialogID, status?: DialogStatusKind): Promise<readonly DialogID[]>;
481
483
  private static setDialogDriveWatched;
482
484
  static syncDriveWatchForDialogLatest(dialogId: DialogID, latest: DialogLatestFile, status?: DialogStatusKind): Promise<void>;