pi-harness-runtime 1.1.506 → 1.1.508

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 (88) hide show
  1. package/CHANGELOG.md +166 -0
  2. package/harness/auto-resume-marker.ts +177 -0
  3. package/harness/provider-quota-reset.ts +53 -19
  4. package/harness/provider-recovery-runtime.ts +20 -0
  5. package/harness/quota-capture.ts +150 -0
  6. package/harness/quota-low-remaining.ts +75 -0
  7. package/harness/quota-reset-duration.ts +87 -0
  8. package/harness/quota-threshold.ts +117 -0
  9. package/harness/resume-scope.ts +85 -0
  10. package/harness/scope-expansion-runtime.ts +337 -0
  11. package/harness/scope-expansion.ts +512 -0
  12. package/index.ts +608 -14
  13. package/mirror.ts +4 -0
  14. package/package.json +1 -1
  15. package/packages/agent-policy/package.json +1 -1
  16. package/packages/auth/package.json +1 -1
  17. package/packages/autonomous-runtime/package.json +1 -1
  18. package/packages/checkpoint/package.json +1 -1
  19. package/packages/clipboard/package.json +1 -1
  20. package/packages/codex-watcher/package.json +1 -1
  21. package/packages/config-capture/package.json +1 -1
  22. package/packages/contracts/package.json +1 -1
  23. package/packages/cookie-sanitizer/package.json +1 -1
  24. package/packages/evaluation-engine/package.json +1 -1
  25. package/packages/event-bus/package.json +1 -1
  26. package/packages/event-store/package.json +1 -1
  27. package/packages/experience-replay/package.json +1 -1
  28. package/packages/file-copy-helper/package.json +1 -1
  29. package/packages/intent-analyzer/package.json +1 -1
  30. package/packages/jev-judge/package.json +1 -1
  31. package/packages/knowledge-retrieval/package.json +1 -1
  32. package/packages/learning-engine/package.json +1 -1
  33. package/packages/logging/package.json +1 -1
  34. package/packages/memory-engine/package.json +1 -1
  35. package/packages/notification/dist/adapters/detail-format.d.ts +5 -2
  36. package/packages/notification/dist/adapters/detail-format.d.ts.map +1 -1
  37. package/packages/notification/dist/adapters/detail-format.js +29 -0
  38. package/packages/notification/dist/adapters/detail-format.js.map +1 -1
  39. package/packages/notification/dist/adapters/email-adapter.d.ts.map +1 -1
  40. package/packages/notification/dist/adapters/email-adapter.js +3 -0
  41. package/packages/notification/dist/adapters/email-adapter.js.map +1 -1
  42. package/packages/notification/dist/adapters/line-adapter.d.ts.map +1 -1
  43. package/packages/notification/dist/adapters/line-adapter.js +3 -0
  44. package/packages/notification/dist/adapters/line-adapter.js.map +1 -1
  45. package/packages/notification/dist/adapters/ntfy-adapter.d.ts.map +1 -1
  46. package/packages/notification/dist/adapters/ntfy-adapter.js +3 -0
  47. package/packages/notification/dist/adapters/ntfy-adapter.js.map +1 -1
  48. package/packages/notification/dist/adapters/telegram-adapter.d.ts +0 -1
  49. package/packages/notification/dist/adapters/telegram-adapter.d.ts.map +1 -1
  50. package/packages/notification/dist/adapters/telegram-adapter.js +3 -3
  51. package/packages/notification/dist/adapters/telegram-adapter.js.map +1 -1
  52. package/packages/notification/dist/notification-center.d.ts.map +1 -1
  53. package/packages/notification/dist/notification-center.js +24 -0
  54. package/packages/notification/dist/notification-center.js.map +1 -1
  55. package/packages/notification/dist/notification-policy.d.ts.map +1 -1
  56. package/packages/notification/dist/notification-policy.js +3 -0
  57. package/packages/notification/dist/notification-policy.js.map +1 -1
  58. package/packages/notification/dist/types.d.ts +23 -1
  59. package/packages/notification/dist/types.d.ts.map +1 -1
  60. package/packages/notification/package.json +1 -1
  61. package/packages/notification/src/adapters/detail-format.ts +45 -2
  62. package/packages/notification/src/adapters/email-adapter.ts +3 -0
  63. package/packages/notification/src/adapters/line-adapter.ts +3 -0
  64. package/packages/notification/src/adapters/ntfy-adapter.ts +3 -0
  65. package/packages/notification/src/adapters/telegram-adapter.ts +3 -4
  66. package/packages/notification/src/notification-center.ts +28 -0
  67. package/packages/notification/src/notification-policy.ts +3 -0
  68. package/packages/notification/src/types.ts +25 -0
  69. package/packages/paperclip-integration/package.json +1 -1
  70. package/packages/performance-optimizer/package.json +1 -1
  71. package/packages/privilege-broker/package.json +1 -1
  72. package/packages/prompt-compiler/package.json +1 -1
  73. package/packages/providers/package.json +1 -1
  74. package/packages/qdrant-skills/package.json +1 -1
  75. package/packages/quota-manager/package.json +1 -1
  76. package/packages/relay/package.json +1 -1
  77. package/packages/skill-mcp-client/package.json +1 -1
  78. package/packages/skills/package.json +1 -1
  79. package/packages/todo-bd-sync/package.json +1 -1
  80. package/packages/token-estimation/package.json +1 -1
  81. package/packages/tooling-preference/package.json +1 -1
  82. package/packages/trajectory/package.json +1 -1
  83. package/packages/tui/package.json +1 -1
  84. package/packages/two-phase-review/package.json +1 -1
  85. package/packages/types/package.json +1 -1
  86. package/packages/webmcp-tester/package.json +1 -1
  87. package/packages/wiki/package.json +1 -1
  88. package/packages/write-review/package.json +1 -1
@@ -0,0 +1,512 @@
1
+ /**
2
+ * The proposal of a new scope.
3
+ *
4
+ * The work of a request is finite. When it is finished, the session may
5
+ * still find work in a backlog - a bd issue that nobody asked for. That
6
+ * work is not work of the request, and it does not become work because it
7
+ * was discovered.
8
+ *
9
+ * A proposal is the only way to reach it: a bounded, concrete question with
10
+ * exact issue IDs, a deadline, and a decision that belongs to a human or to
11
+ * Jev under an explicit policy. Silence is not an approval of the
12
+ * backlog, and an approval of one group is not an approval of the next
13
+ * one.
14
+ *
15
+ * The state machine lives here and not in the judge: the mechanical
16
+ * questions - is the proposal still open, is the answer a subset of the
17
+ * proposal, was the decision delivered - are decided in code.
18
+ */
19
+
20
+ /** How long the human has to answer before Jev may decide the proposal. */
21
+ export const SCOPE_EXPANSION_WINDOW_MS = 5 * 60_000;
22
+
23
+ /** How many candidates a proposal may name at most. */
24
+ export const MAX_SCOPE_CANDIDATES = 10;
25
+
26
+ /** The state of a proposal. */
27
+ export type ScopeProposalState =
28
+ /** The proposal waits for the human or for the deadline. */
29
+ | "proposed"
30
+ /** The proposal was decided and the decision was delivered. */
31
+ | "decided"
32
+ /** The authorized work was started. */
33
+ | "dispatched"
34
+ /** The authorized work finished; the session stops again. */
35
+ | "finished"
36
+ /** The proposal was not executed; the reason is known. */
37
+ | "stopped";
38
+
39
+ /** One backlog candidate. */
40
+ export interface ScopeCandidate {
41
+ /** The exact id of the issue. */
42
+ id: string;
43
+ /** The title of the issue. */
44
+ title: string;
45
+ }
46
+
47
+ /** The decision about a proposal. */
48
+ export interface ScopeDecision {
49
+ /** The outcome of the decision. */
50
+ outcome: "approve" | "reject" | "wait";
51
+ /** The exact ids that are authorized. */
52
+ selectedIds: string[];
53
+ /** Why the decision was made. */
54
+ reasoning: string;
55
+ /** Who decided. */
56
+ source: "human" | "jev";
57
+ /** The evaluation failed: a failure is not a decision. */
58
+ failed?: boolean;
59
+ }
60
+
61
+ /** A concrete proposal of a new scope. */
62
+ export interface ScopeProposal {
63
+ /** The identity of the proposal. */
64
+ id: string;
65
+ /** The session the proposal belongs to. */
66
+ sessionId: string;
67
+ /** The request whose work is finished. */
68
+ requestId: string;
69
+ /** The completion generation the proposal belongs to. */
70
+ generation: number;
71
+ /** The workspace the work happens in. */
72
+ workspace: string;
73
+ /** The candidates the proposal may name. */
74
+ candidates: ScopeCandidate[];
75
+ /** The exact subset the proposal asks for. */
76
+ proposedIds: string[];
77
+ /** What would be done. */
78
+ scope: string;
79
+ /** How the work would be validated. */
80
+ validation: string;
81
+ /** The material risks or costs. */
82
+ risks: string[];
83
+ /** The choices the human has. */
84
+ choices: string[];
85
+ /** The moment the proposal was created. */
86
+ createdAt: number;
87
+ /** The absolute moment the decision has to be made. */
88
+ deadlineAt: number;
89
+ /** Where the proposal stands. */
90
+ state: ScopeProposalState;
91
+ /** The decision, when there is one. */
92
+ decision?: ScopeDecision;
93
+ /** The reason the proposal was not executed. */
94
+ stopReason?: string;
95
+ }
96
+
97
+ export interface CreateScopeProposalInput {
98
+ id: string;
99
+ sessionId: string;
100
+ requestId: string;
101
+ generation: number;
102
+ workspace: string;
103
+ candidates: ScopeCandidate[];
104
+ proposedIds: string[];
105
+ scope: string;
106
+ validation: string;
107
+ risks?: string[];
108
+ now: number;
109
+ }
110
+
111
+ /**
112
+ * Create a proposal.
113
+ *
114
+ * The proposal names a bounded subset of the candidates: a candidate that
115
+ * is not named is not proposed, and an id that is not a candidate is
116
+ * refused. The deadline is absolute, so every reader measures the same
117
+ * moment.
118
+ */
119
+ export function createScopeProposal(input: CreateScopeProposalInput): ScopeProposal {
120
+ const candidates = input.candidates.slice(0, MAX_SCOPE_CANDIDATES);
121
+ const known = new Set(candidates.map((candidate) => candidate.id));
122
+ const proposedIds = input.proposedIds.filter((id) => known.has(id));
123
+ if (proposedIds.length === 0) {
124
+ throw new Error("a scope proposal needs at least one candidate id");
125
+ }
126
+ return {
127
+ id: input.id,
128
+ sessionId: input.sessionId,
129
+ requestId: input.requestId,
130
+ generation: input.generation,
131
+ workspace: input.workspace,
132
+ candidates,
133
+ proposedIds,
134
+ scope: input.scope,
135
+ validation: input.validation,
136
+ risks: input.risks ?? [],
137
+ choices: ["approve the proposed subset", "decline", "revise the proposal"],
138
+ createdAt: input.now,
139
+ deadlineAt: input.now + SCOPE_EXPANSION_WINDOW_MS,
140
+ state: "proposed",
141
+ };
142
+ }
143
+
144
+ /**
145
+ * The message of the proposal.
146
+ *
147
+ * The message names the exact ids, the deadline, and the fact that the
148
+ * silence of the human lets Jev decide the proposal - it does not let the
149
+ * backlog be worked on.
150
+ */
151
+ export function scopeProposalMessage(proposal: ScopeProposal): string {
152
+ const ids = proposal.proposedIds.join(", ");
153
+ const lines = [
154
+ `The requested work is complete. I found additional bd issues outside it.`,
155
+ `Proposal: work on ${ids} in ${proposal.workspace}.`,
156
+ `Scope: ${proposal.scope}`,
157
+ `Validation: ${proposal.validation}`,
158
+ ];
159
+ if (proposal.risks.length > 0) {
160
+ lines.push(`Risks/costs: ${proposal.risks.join("; ")}`);
161
+ }
162
+ lines.push(
163
+ `Choices: ${proposal.choices.join(" / ")}.`,
164
+ `Deadline: ${new Date(proposal.deadlineAt).toISOString()}.`,
165
+ `If unanswered for 5 minutes, Jev may decide this proposal under your policy.`,
166
+ );
167
+ return lines.join("\n");
168
+ }
169
+
170
+ /**
171
+ * The message of the decision.
172
+ *
173
+ * The decision names what was decided, what it means, and whether the work
174
+ * starts or the session stays stopped.
175
+ */
176
+ export function scopeDecisionMessage(
177
+ proposal: ScopeProposal,
178
+ decision: ScopeDecision,
179
+ action: "starting the selected work" | "remaining stopped",
180
+ ): string {
181
+ const who = decision.source === "jev" ? "Jev decision after 5 minutes" : "Your decision";
182
+ return [
183
+ `${who}: ${decision.outcome}.`,
184
+ `Scope: ${decision.selectedIds.length > 0 ? decision.selectedIds.join(", ") : "none"}.`,
185
+ `Reason: ${decision.reasoning}`,
186
+ `Action: ${action}.`,
187
+ `Proposed: ${proposal.scope}`,
188
+ ].join("\n");
189
+ }
190
+
191
+ /**
192
+ * The ids of a decision that the proposal allows.
193
+ *
194
+ * A decision may only name ids of the proposal, and the work may only
195
+ * happen in the workspace of the proposal. Everything else is refused: a
196
+ * decision that names an issue nobody proposed does not authorize work.
197
+ */
198
+ export function authorizedScope(
199
+ proposal: ScopeProposal,
200
+ decision: ScopeDecision,
201
+ ): { ids: string[]; reason?: string } {
202
+ if (decision.outcome !== "approve") {
203
+ return { ids: [], reason: "the decision does not approve the proposal" };
204
+ }
205
+ const allowed = new Set(proposal.proposedIds);
206
+ const ids = decision.selectedIds.filter((id) => allowed.has(id));
207
+ if (ids.length === 0) {
208
+ return { ids: [], reason: "the decision names no id of the proposal" };
209
+ }
210
+ return { ids };
211
+ }
212
+
213
+ /** The dependencies of the controller. */
214
+ export interface ScopeExpansionDeps {
215
+ /** The clock of the controller. */
216
+ now(): number;
217
+ /**
218
+ * Deliver a message to the channels of the human.
219
+ *
220
+ * The result says whether at least one route accepted the message. An
221
+ * acknowledgement is a submission, not a reading.
222
+ */
223
+ deliver(
224
+ text: string,
225
+ meta: { id: string; kind: "proposal" | "decision"; questionId?: string },
226
+ ): Promise<{
227
+ delivered: boolean;
228
+ failures: string[];
229
+ }>;
230
+ /** Jev decides the proposal. */
231
+ judge(proposal: ScopeProposal): Promise<ScopeDecision>;
232
+ /** Start the authorized work. */
233
+ dispatch(proposal: ScopeProposal, ids: string[]): void;
234
+ /**
235
+ * The latest human decision of a proposal.
236
+ *
237
+ * It is read after the delivery of the decision and before the
238
+ * dispatch: a rejection that arrived while the decision was on its way
239
+ * still prevents the work.
240
+ */
241
+ latestHumanDecision?(proposal: ScopeProposal): "approve" | "reject" | undefined;
242
+ /** The log of the controller. */
243
+ log?(message: string): void;
244
+ }
245
+
246
+ /**
247
+ * The controller of the scope proposals.
248
+ *
249
+ * One proposal per completion generation: a second proposal needs the
250
+ * human. The human always wins over an evaluation that is still running,
251
+ * and a decision that was not delivered does not start work.
252
+ */
253
+ export class ScopeExpansionController {
254
+ private readonly deps: ScopeExpansionDeps;
255
+ private proposals = new Map<string, ScopeProposal>();
256
+ private generationCounter = 0;
257
+ private answered = new Set<string>();
258
+ private evaluated = new Set<string>();
259
+ private closedGeneration: number | null = null;
260
+
261
+ constructor(deps: ScopeExpansionDeps) {
262
+ this.deps = deps;
263
+ }
264
+
265
+ /** The proposals of the controller. */
266
+ get open(): ScopeProposal[] {
267
+ return [...this.proposals.values()].filter(
268
+ (proposal) => proposal.state === "proposed",
269
+ );
270
+ }
271
+
272
+ /** The proposal with this identity. */
273
+ get(id: string): ScopeProposal | undefined {
274
+ return this.proposals.get(id);
275
+ }
276
+
277
+ /** The generation of the next proposal. */
278
+ nextGeneration(): number {
279
+ this.generationCounter += 1;
280
+ return this.generationCounter;
281
+ }
282
+
283
+ /**
284
+ * Register a proposal.
285
+ *
286
+ * A generation that is closed does not get a second proposal: the
287
+ * approval of one group is not the approval of the next one.
288
+ */
289
+ register(proposal: ScopeProposal): boolean {
290
+ if (this.closedGeneration === proposal.generation) {
291
+ this.deps.log?.(
292
+ `The scope proposal ${proposal.id} is refused: the generation ${proposal.generation} is closed.`,
293
+ );
294
+ return false;
295
+ }
296
+ const existing = [...this.proposals.values()].find(
297
+ (candidate) =>
298
+ candidate.generation === proposal.generation &&
299
+ candidate.state === "proposed",
300
+ );
301
+ if (existing) {
302
+ this.deps.log?.(
303
+ `The scope proposal ${proposal.id} is refused: the generation ${proposal.generation} already has the proposal ${existing.id}.`,
304
+ );
305
+ return false;
306
+ }
307
+ this.proposals.set(proposal.id, proposal);
308
+ return true;
309
+ }
310
+
311
+ /**
312
+ * Apply the answer of the human.
313
+ *
314
+ * The answer wins over an evaluation that is still running: the
315
+ * evaluation of a proposal that was answered is discarded.
316
+ *
317
+ * The first answer wins. A second answer - a stale button of a
318
+ * notification that was already delivered - does not replace the
319
+ * decision of the human.
320
+ */
321
+ answer(id: string, outcome: ScopeDecision["outcome"], reasoning: string): ScopeDecision | null {
322
+ const proposal = this.proposals.get(id);
323
+ if (!proposal) return null;
324
+ if (proposal.state !== "proposed") return null;
325
+ if (this.answered.has(id)) return null;
326
+ this.answered.add(id);
327
+ const decision: ScopeDecision = {
328
+ outcome,
329
+ selectedIds: outcome === "approve" ? [...proposal.proposedIds] : [],
330
+ reasoning,
331
+ source: "human",
332
+ };
333
+ proposal.decision = decision;
334
+ return decision;
335
+ }
336
+
337
+ /**
338
+ * Evaluate the proposal, when the deadline has passed.
339
+ *
340
+ * The evaluation happens once. A wait, a failure or a rejection ends
341
+ * the automatic attempts for this proposal: the countdown is not
342
+ * restarted.
343
+ */
344
+ async evaluateDue(id: string): Promise<ScopeDecision | null> {
345
+ const proposal = this.proposals.get(id);
346
+ if (!proposal) return null;
347
+ if (proposal.state !== "proposed") return null;
348
+ if (this.answered.has(id)) return null;
349
+ if (this.evaluated.has(id)) return null;
350
+ if (this.deps.now() < proposal.deadlineAt) return null;
351
+ this.evaluated.add(id);
352
+ let decision: ScopeDecision;
353
+ try {
354
+ decision = await this.deps.judge(proposal);
355
+ } catch (error) {
356
+ decision = {
357
+ outcome: "wait",
358
+ selectedIds: [],
359
+ reasoning: `the evaluation failed: ${error instanceof Error ? error.message : String(error)}`,
360
+ source: "jev",
361
+ failed: true,
362
+ };
363
+ }
364
+ // The human answered while the evaluation was running: the answer
365
+ // wins.
366
+ if (this.answered.has(id)) {
367
+ this.deps.log?.(
368
+ `The evaluation of the proposal ${id} is discarded: the human answered meanwhile.`,
369
+ );
370
+ return null;
371
+ }
372
+ proposal.decision = decision;
373
+ return decision;
374
+ }
375
+
376
+ /**
377
+ * Notify the decision and start the authorized work.
378
+ *
379
+ * The decision is delivered before the work starts. A delivery that
380
+ * reaches no route leaves the work stopped: the session may not claim
381
+ * that the human was informed and start anyway.
382
+ */
383
+ async applyDecision(id: string): Promise<{ started: boolean; reason?: string }> {
384
+ const proposal = this.proposals.get(id);
385
+ if (!proposal) return { started: false, reason: "unknown proposal" };
386
+ const decision = proposal.decision;
387
+ if (!decision) return { started: false, reason: "the proposal has no decision" };
388
+ if (proposal.state === "dispatched" || proposal.state === "finished") {
389
+ return { started: false, reason: "the proposal was already executed" };
390
+ }
391
+ // The human decides. The answer is read before the delivery, so the
392
+ // delivered message and the executed work agree.
393
+ let effective = decision;
394
+ const latestBefore = this.deps.latestHumanDecision?.(proposal);
395
+ if (latestBefore === "reject") {
396
+ effective = {
397
+ outcome: "reject",
398
+ selectedIds: [],
399
+ reasoning: "the human rejected the proposal",
400
+ source: "human",
401
+ };
402
+ proposal.decision = effective;
403
+ } else if (latestBefore === "approve" && decision.source !== "human") {
404
+ effective = {
405
+ ...decision,
406
+ outcome: "approve",
407
+ selectedIds: [...proposal.proposedIds],
408
+ source: "human",
409
+ };
410
+ proposal.decision = effective;
411
+ }
412
+ const scope = authorizedScope(proposal, effective);
413
+ const action: "starting the selected work" | "remaining stopped" =
414
+ scope.ids.length > 0 ? "starting the selected work" : "remaining stopped";
415
+ const delivery = await this.deps.deliver(scopeDecisionMessage(proposal, effective, action), {
416
+ id: proposal.id,
417
+ kind: "decision",
418
+ });
419
+ if (!delivery.delivered) {
420
+ proposal.state = "stopped";
421
+ proposal.stopReason = `the decision was not delivered: ${delivery.failures.join(", ")}`;
422
+ this.deps.log?.(`The scope proposal ${proposal.id} stays unexecuted: ${proposal.stopReason}`);
423
+ return { started: false, reason: proposal.stopReason };
424
+ }
425
+ proposal.state = "decided";
426
+ // The answer is read again after the delivery: a rejection that
427
+ // arrived while the decision was on its way still prevents the work.
428
+ const latestAfter = this.deps.latestHumanDecision?.(proposal);
429
+ if (latestAfter === "reject" && effective.outcome !== "reject") {
430
+ proposal.state = "stopped";
431
+ proposal.stopReason =
432
+ "the human rejected the proposal after the decision was delivered";
433
+ this.deps.log?.(
434
+ `The scope proposal ${proposal.id} stays unexecuted: ${proposal.stopReason}`,
435
+ );
436
+ return { started: false, reason: proposal.stopReason };
437
+ }
438
+ let finalScope = scope;
439
+ if (latestAfter === "approve" && effective.source !== "human") {
440
+ const approved: ScopeDecision = {
441
+ ...effective,
442
+ outcome: "approve",
443
+ selectedIds: [...proposal.proposedIds],
444
+ source: "human",
445
+ };
446
+ proposal.decision = approved;
447
+ finalScope = authorizedScope(proposal, approved);
448
+ // The delivered message said something else: the human has to
449
+ // know what started. A correction that reaches nobody leaves
450
+ // the work stopped.
451
+ const correction = await this.deps.deliver(
452
+ scopeDecisionMessage(proposal, approved, "starting the selected work"),
453
+ { id: proposal.id, kind: "decision" },
454
+ );
455
+ if (!correction.delivered) {
456
+ proposal.state = "stopped";
457
+ proposal.stopReason = `the correction was not delivered: ${correction.failures.join(", ")}`;
458
+ this.deps.log?.(
459
+ `The scope proposal ${proposal.id} stays unexecuted: ${proposal.stopReason}`,
460
+ );
461
+ return { started: false, reason: proposal.stopReason };
462
+ }
463
+ }
464
+ if (finalScope.ids.length === 0) {
465
+ proposal.state = "stopped";
466
+ proposal.stopReason =
467
+ effective.outcome === "reject"
468
+ ? effective.reasoning
469
+ : (finalScope.reason ?? "the decision authorizes no work");
470
+ return { started: false, reason: proposal.stopReason };
471
+ }
472
+ this.deps.dispatch(proposal, finalScope.ids);
473
+ proposal.state = "dispatched";
474
+ return { started: true };
475
+ }
476
+
477
+ /**
478
+ * The authorized group finished.
479
+ *
480
+ * The session stops again. The approval of that group does not authorize
481
+ * the next group of the backlog.
482
+ */
483
+ finishGroup(id: string): void {
484
+ const proposal = this.proposals.get(id);
485
+ if (!proposal) return;
486
+ proposal.state = "finished";
487
+ this.closedGeneration = proposal.generation;
488
+ this.deps.log?.(
489
+ `The scope proposal ${proposal.id} is finished: the session stops again.`,
490
+ );
491
+ }
492
+
493
+ /**
494
+ * Deliver the proposal to the human.
495
+ *
496
+ * The window of the decision starts with the delivery: a proposal that
497
+ * reaches no route does not start a countdown that nobody can stop.
498
+ */
499
+ async deliverProposal(proposal: ScopeProposal): Promise<boolean> {
500
+ const delivery = await this.deps.deliver(scopeProposalMessage(proposal), {
501
+ id: proposal.id,
502
+ kind: "proposal",
503
+ });
504
+ if (!delivery.delivered) {
505
+ proposal.state = "stopped";
506
+ proposal.stopReason = `the proposal was not delivered: ${delivery.failures.join(", ")}`;
507
+ this.deps.log?.(`The scope proposal ${proposal.id} stays unexecuted: ${proposal.stopReason}`);
508
+ return false;
509
+ }
510
+ return true;
511
+ }
512
+ }