pi-harness-runtime 1.1.506 → 1.1.507

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 (81) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/harness/provider-quota-reset.ts +53 -19
  3. package/harness/provider-recovery-runtime.ts +20 -0
  4. package/harness/quota-capture.ts +150 -0
  5. package/harness/quota-low-remaining.ts +75 -0
  6. package/harness/quota-reset-duration.ts +87 -0
  7. package/harness/quota-threshold.ts +117 -0
  8. package/harness/resume-scope.ts +85 -0
  9. package/harness/scope-expansion.ts +438 -0
  10. package/index.ts +212 -7
  11. package/mirror.ts +4 -0
  12. package/package.json +1 -1
  13. package/packages/agent-policy/package.json +1 -1
  14. package/packages/auth/package.json +1 -1
  15. package/packages/autonomous-runtime/package.json +1 -1
  16. package/packages/checkpoint/package.json +1 -1
  17. package/packages/clipboard/package.json +1 -1
  18. package/packages/codex-watcher/package.json +1 -1
  19. package/packages/config-capture/package.json +1 -1
  20. package/packages/contracts/package.json +1 -1
  21. package/packages/cookie-sanitizer/package.json +1 -1
  22. package/packages/evaluation-engine/package.json +1 -1
  23. package/packages/event-bus/package.json +1 -1
  24. package/packages/event-store/package.json +1 -1
  25. package/packages/experience-replay/package.json +1 -1
  26. package/packages/file-copy-helper/package.json +1 -1
  27. package/packages/intent-analyzer/package.json +1 -1
  28. package/packages/jev-judge/package.json +1 -1
  29. package/packages/knowledge-retrieval/package.json +1 -1
  30. package/packages/learning-engine/package.json +1 -1
  31. package/packages/logging/package.json +1 -1
  32. package/packages/memory-engine/package.json +1 -1
  33. package/packages/notification/dist/adapters/detail-format.d.ts +5 -2
  34. package/packages/notification/dist/adapters/detail-format.d.ts.map +1 -1
  35. package/packages/notification/dist/adapters/detail-format.js +17 -0
  36. package/packages/notification/dist/adapters/detail-format.js.map +1 -1
  37. package/packages/notification/dist/adapters/email-adapter.d.ts.map +1 -1
  38. package/packages/notification/dist/adapters/email-adapter.js +1 -0
  39. package/packages/notification/dist/adapters/email-adapter.js.map +1 -1
  40. package/packages/notification/dist/adapters/line-adapter.d.ts.map +1 -1
  41. package/packages/notification/dist/adapters/line-adapter.js +1 -0
  42. package/packages/notification/dist/adapters/line-adapter.js.map +1 -1
  43. package/packages/notification/dist/adapters/ntfy-adapter.d.ts.map +1 -1
  44. package/packages/notification/dist/adapters/ntfy-adapter.js +1 -0
  45. package/packages/notification/dist/adapters/ntfy-adapter.js.map +1 -1
  46. package/packages/notification/dist/adapters/telegram-adapter.d.ts.map +1 -1
  47. package/packages/notification/dist/adapters/telegram-adapter.js +1 -0
  48. package/packages/notification/dist/adapters/telegram-adapter.js.map +1 -1
  49. package/packages/notification/dist/notification-center.d.ts.map +1 -1
  50. package/packages/notification/dist/notification-center.js +10 -0
  51. package/packages/notification/dist/notification-center.js.map +1 -1
  52. package/packages/notification/dist/types.d.ts +14 -1
  53. package/packages/notification/dist/types.d.ts.map +1 -1
  54. package/packages/notification/package.json +1 -1
  55. package/packages/notification/src/adapters/detail-format.ts +29 -2
  56. package/packages/notification/src/adapters/email-adapter.ts +1 -0
  57. package/packages/notification/src/adapters/line-adapter.ts +1 -0
  58. package/packages/notification/src/adapters/ntfy-adapter.ts +1 -0
  59. package/packages/notification/src/adapters/telegram-adapter.ts +1 -0
  60. package/packages/notification/src/notification-center.ts +14 -0
  61. package/packages/notification/src/types.ts +14 -0
  62. package/packages/paperclip-integration/package.json +1 -1
  63. package/packages/performance-optimizer/package.json +1 -1
  64. package/packages/privilege-broker/package.json +1 -1
  65. package/packages/prompt-compiler/package.json +1 -1
  66. package/packages/providers/package.json +1 -1
  67. package/packages/qdrant-skills/package.json +1 -1
  68. package/packages/quota-manager/package.json +1 -1
  69. package/packages/relay/package.json +1 -1
  70. package/packages/skill-mcp-client/package.json +1 -1
  71. package/packages/skills/package.json +1 -1
  72. package/packages/todo-bd-sync/package.json +1 -1
  73. package/packages/token-estimation/package.json +1 -1
  74. package/packages/tooling-preference/package.json +1 -1
  75. package/packages/trajectory/package.json +1 -1
  76. package/packages/tui/package.json +1 -1
  77. package/packages/two-phase-review/package.json +1 -1
  78. package/packages/types/package.json +1 -1
  79. package/packages/webmcp-tester/package.json +1 -1
  80. package/packages/wiki/package.json +1 -1
  81. package/packages/write-review/package.json +1 -1
@@ -0,0 +1,85 @@
1
+ /**
2
+ * The scope of an automatic resume.
3
+ *
4
+ * An automatic resume continues the request that is running. It is not an
5
+ * instruction to find more work: a queued `resume` that arrives after the
6
+ * request is complete sends the agent to the backlog, and the backlog is
7
+ * not work of this request.
8
+ *
9
+ * The mechanical question - does authorized work remain? - belongs in code
10
+ * and not in the judge. The judge answers the other question: whether a
11
+ * concrete proposed scope may be taken on.
12
+ *
13
+ * The decision is deliberately conservative. An unknown state is not a
14
+ * completion: the uncertainty is preserved and the resume goes on, because
15
+ * stopping work that is unfinished is worse than asking again.
16
+ */
17
+
18
+ /** The state of the work of the request that is running. */
19
+ export type ResumeWorkState = "unfinished" | "complete" | "unknown";
20
+
21
+ /** What the guard does with an automatic resume. */
22
+ export type ResumeScopeAction = "continue" | "suppress";
23
+
24
+ export interface ResumeScopeInput {
25
+ /** The state of the work of the request that is running. */
26
+ work: ResumeWorkState;
27
+ /** The reason of the resume, for the report. */
28
+ reason: string;
29
+ }
30
+
31
+ export interface ResumeScopeDecision {
32
+ /** The action of the guard. */
33
+ action: ResumeScopeAction;
34
+ /** The reason of the decision, for the log. */
35
+ reason: string;
36
+ /** The line the user sees when the resume is suppressed. */
37
+ report?: string;
38
+ }
39
+
40
+ /**
41
+ * The rule that the agent keeps across a compaction.
42
+ *
43
+ * The rule is reinforcement, not enforcement: the guard in the code owns
44
+ * the decision, and this text tells the agent what the guard decided and
45
+ * why the backlog is not the next task.
46
+ */
47
+ export const RESUME_SCOPE_RULE = [
48
+ "An automatic resume continues only the current authorized request.",
49
+ "If that request and its required validation are finished, remain stopped.",
50
+ "Pending issues in bd or another backlog are not pending work of this request.",
51
+ "Propose any new scope separately; do not create executable todos for it",
52
+ "until the human or the configured Jev proposal policy authorizes it.",
53
+ ].join(" ");
54
+
55
+ /**
56
+ * The decision of the guard.
57
+ *
58
+ * - Work of the request remains: the resume goes on, and it continues that
59
+ * work only.
60
+ * - The work of the request is complete: the resume is suppressed. The
61
+ * agent is not told to find something else, and no backlog issue becomes
62
+ * work of this request.
63
+ * - The state is unknown: the resume goes on. The uncertainty is preserved
64
+ * - the guard does not declare a completion it cannot prove, and it does
65
+ * not substitute unrelated work either.
66
+ */
67
+ export function decideResumeScope(input: ResumeScopeInput): ResumeScopeDecision {
68
+ if (input.work === "complete") {
69
+ return {
70
+ action: "suppress",
71
+ reason: "the work of the request is complete",
72
+ report: `The work of the request is complete; the automatic resume (${input.reason}) is not sent.`,
73
+ };
74
+ }
75
+ if (input.work === "unknown") {
76
+ return {
77
+ action: "continue",
78
+ reason: "the state of the work is unknown; the uncertainty is preserved",
79
+ };
80
+ }
81
+ return {
82
+ action: "continue",
83
+ reason: "the work of the request is unfinished",
84
+ };
85
+ }
@@ -0,0 +1,438 @@
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
+ ].join("\n");
188
+ }
189
+
190
+ /**
191
+ * The ids of a decision that the proposal allows.
192
+ *
193
+ * A decision may only name ids of the proposal, and the work may only
194
+ * happen in the workspace of the proposal. Everything else is refused: a
195
+ * decision that names an issue nobody proposed does not authorize work.
196
+ */
197
+ export function authorizedScope(
198
+ proposal: ScopeProposal,
199
+ decision: ScopeDecision,
200
+ ): { ids: string[]; reason?: string } {
201
+ if (decision.outcome !== "approve") {
202
+ return { ids: [], reason: "the decision does not approve the proposal" };
203
+ }
204
+ const allowed = new Set(proposal.proposedIds);
205
+ const ids = decision.selectedIds.filter((id) => allowed.has(id));
206
+ if (ids.length === 0) {
207
+ return { ids: [], reason: "the decision names no id of the proposal" };
208
+ }
209
+ return { ids };
210
+ }
211
+
212
+ /** The dependencies of the controller. */
213
+ export interface ScopeExpansionDeps {
214
+ /** The clock of the controller. */
215
+ now(): number;
216
+ /**
217
+ * Deliver a message to the channels of the human.
218
+ *
219
+ * The result says whether at least one route accepted the message. An
220
+ * acknowledgement is a submission, not a reading.
221
+ */
222
+ deliver(text: string, meta: { id: string; kind: "proposal" | "decision" }): Promise<{
223
+ delivered: boolean;
224
+ failures: string[];
225
+ }>;
226
+ /** Jev decides the proposal. */
227
+ judge(proposal: ScopeProposal): Promise<ScopeDecision>;
228
+ /** Start the authorized work. */
229
+ dispatch(proposal: ScopeProposal, ids: string[]): void;
230
+ /** The log of the controller. */
231
+ log?(message: string): void;
232
+ }
233
+
234
+ /**
235
+ * The controller of the scope proposals.
236
+ *
237
+ * One proposal per completion generation: a second proposal needs the
238
+ * human. The human always wins over an evaluation that is still running,
239
+ * and a decision that was not delivered does not start work.
240
+ */
241
+ export class ScopeExpansionController {
242
+ private readonly deps: ScopeExpansionDeps;
243
+ private proposals = new Map<string, ScopeProposal>();
244
+ private generationCounter = 0;
245
+ private answered = new Set<string>();
246
+ private evaluated = new Set<string>();
247
+ private closedGeneration: number | null = null;
248
+
249
+ constructor(deps: ScopeExpansionDeps) {
250
+ this.deps = deps;
251
+ }
252
+
253
+ /** The proposals of the controller. */
254
+ get open(): ScopeProposal[] {
255
+ return [...this.proposals.values()].filter(
256
+ (proposal) => proposal.state === "proposed",
257
+ );
258
+ }
259
+
260
+ /** The proposal with this identity. */
261
+ get(id: string): ScopeProposal | undefined {
262
+ return this.proposals.get(id);
263
+ }
264
+
265
+ /** The generation of the next proposal. */
266
+ nextGeneration(): number {
267
+ this.generationCounter += 1;
268
+ return this.generationCounter;
269
+ }
270
+
271
+ /**
272
+ * Register a proposal.
273
+ *
274
+ * A generation that is closed does not get a second proposal: the
275
+ * approval of one group is not the approval of the next one.
276
+ */
277
+ register(proposal: ScopeProposal): boolean {
278
+ if (this.closedGeneration === proposal.generation) {
279
+ this.deps.log?.(
280
+ `The scope proposal ${proposal.id} is refused: the generation ${proposal.generation} is closed.`,
281
+ );
282
+ return false;
283
+ }
284
+ const existing = [...this.proposals.values()].find(
285
+ (candidate) =>
286
+ candidate.generation === proposal.generation &&
287
+ candidate.state === "proposed",
288
+ );
289
+ if (existing) {
290
+ this.deps.log?.(
291
+ `The scope proposal ${proposal.id} is refused: the generation ${proposal.generation} already has the proposal ${existing.id}.`,
292
+ );
293
+ return false;
294
+ }
295
+ this.proposals.set(proposal.id, proposal);
296
+ return true;
297
+ }
298
+
299
+ /**
300
+ * Apply the answer of the human.
301
+ *
302
+ * The answer wins over an evaluation that is still running: the
303
+ * evaluation of a proposal that was answered is discarded.
304
+ *
305
+ * The first answer wins. A second answer - a stale button of a
306
+ * notification that was already delivered - does not replace the
307
+ * decision of the human.
308
+ */
309
+ answer(id: string, outcome: ScopeDecision["outcome"], reasoning: string): ScopeDecision | null {
310
+ const proposal = this.proposals.get(id);
311
+ if (!proposal) return null;
312
+ if (proposal.state !== "proposed") return null;
313
+ if (this.answered.has(id)) return null;
314
+ this.answered.add(id);
315
+ const decision: ScopeDecision = {
316
+ outcome,
317
+ selectedIds: outcome === "approve" ? [...proposal.proposedIds] : [],
318
+ reasoning,
319
+ source: "human",
320
+ };
321
+ proposal.decision = decision;
322
+ return decision;
323
+ }
324
+
325
+ /**
326
+ * Evaluate the proposal, when the deadline has passed.
327
+ *
328
+ * The evaluation happens once. A wait, a failure or a rejection ends
329
+ * the automatic attempts for this proposal: the countdown is not
330
+ * restarted.
331
+ */
332
+ async evaluateDue(id: string): Promise<ScopeDecision | null> {
333
+ const proposal = this.proposals.get(id);
334
+ if (!proposal) return null;
335
+ if (proposal.state !== "proposed") return null;
336
+ if (this.answered.has(id)) return null;
337
+ if (this.evaluated.has(id)) return null;
338
+ if (this.deps.now() < proposal.deadlineAt) return null;
339
+ this.evaluated.add(id);
340
+ let decision: ScopeDecision;
341
+ try {
342
+ decision = await this.deps.judge(proposal);
343
+ } catch (error) {
344
+ decision = {
345
+ outcome: "wait",
346
+ selectedIds: [],
347
+ reasoning: `the evaluation failed: ${error instanceof Error ? error.message : String(error)}`,
348
+ source: "jev",
349
+ failed: true,
350
+ };
351
+ }
352
+ // The human answered while the evaluation was running: the answer
353
+ // wins.
354
+ if (this.answered.has(id)) {
355
+ this.deps.log?.(
356
+ `The evaluation of the proposal ${id} is discarded: the human answered meanwhile.`,
357
+ );
358
+ return null;
359
+ }
360
+ proposal.decision = decision;
361
+ return decision;
362
+ }
363
+
364
+ /**
365
+ * Notify the decision and start the authorized work.
366
+ *
367
+ * The decision is delivered before the work starts. A delivery that
368
+ * reaches no route leaves the work stopped: the session may not claim
369
+ * that the human was informed and start anyway.
370
+ */
371
+ async applyDecision(id: string): Promise<{ started: boolean; reason?: string }> {
372
+ const proposal = this.proposals.get(id);
373
+ if (!proposal) return { started: false, reason: "unknown proposal" };
374
+ const decision = proposal.decision;
375
+ if (!decision) return { started: false, reason: "the proposal has no decision" };
376
+ if (proposal.state === "dispatched" || proposal.state === "finished") {
377
+ return { started: false, reason: "the proposal was already executed" };
378
+ }
379
+ const scope = authorizedScope(proposal, decision);
380
+ const action: "starting the selected work" | "remaining stopped" =
381
+ scope.ids.length > 0 ? "starting the selected work" : "remaining stopped";
382
+ const delivery = await this.deps.deliver(scopeDecisionMessage(proposal, decision, action), {
383
+ id: proposal.id,
384
+ kind: "decision",
385
+ });
386
+ if (!delivery.delivered) {
387
+ proposal.state = "stopped";
388
+ proposal.stopReason = `the decision was not delivered: ${delivery.failures.join(", ")}`;
389
+ this.deps.log?.(`The scope proposal ${proposal.id} stays unexecuted: ${proposal.stopReason}`);
390
+ return { started: false, reason: proposal.stopReason };
391
+ }
392
+ proposal.state = "decided";
393
+ if (scope.ids.length === 0) {
394
+ proposal.state = "stopped";
395
+ proposal.stopReason = scope.reason ?? "the decision authorizes no work";
396
+ return { started: false, reason: proposal.stopReason };
397
+ }
398
+ this.deps.dispatch(proposal, scope.ids);
399
+ proposal.state = "dispatched";
400
+ return { started: true };
401
+ }
402
+
403
+ /**
404
+ * The authorized group finished.
405
+ *
406
+ * The session stops again. The approval of that group does not authorize
407
+ * the next group of the backlog.
408
+ */
409
+ finishGroup(id: string): void {
410
+ const proposal = this.proposals.get(id);
411
+ if (!proposal) return;
412
+ proposal.state = "finished";
413
+ this.closedGeneration = proposal.generation;
414
+ this.deps.log?.(
415
+ `The scope proposal ${proposal.id} is finished: the session stops again.`,
416
+ );
417
+ }
418
+
419
+ /**
420
+ * Deliver the proposal to the human.
421
+ *
422
+ * The window of the decision starts with the delivery: a proposal that
423
+ * reaches no route does not start a countdown that nobody can stop.
424
+ */
425
+ async deliverProposal(proposal: ScopeProposal): Promise<boolean> {
426
+ const delivery = await this.deps.deliver(scopeProposalMessage(proposal), {
427
+ id: proposal.id,
428
+ kind: "proposal",
429
+ });
430
+ if (!delivery.delivered) {
431
+ proposal.state = "stopped";
432
+ proposal.stopReason = `the proposal was not delivered: ${delivery.failures.join(", ")}`;
433
+ this.deps.log?.(`The scope proposal ${proposal.id} stays unexecuted: ${proposal.stopReason}`);
434
+ return false;
435
+ }
436
+ return true;
437
+ }
438
+ }