wicked-crew 0.17.0 → 0.17.1

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 (71) hide show
  1. package/README.md +27 -9
  2. package/dist/api/chat-jobs.d.ts +163 -0
  3. package/dist/api/chat-jobs.d.ts.map +1 -0
  4. package/dist/api/chat-jobs.js +767 -0
  5. package/dist/api/chat-jobs.js.map +1 -0
  6. package/dist/api/chat-proposals.d.ts +149 -3
  7. package/dist/api/chat-proposals.d.ts.map +1 -1
  8. package/dist/api/chat-proposals.js +831 -11
  9. package/dist/api/chat-proposals.js.map +1 -1
  10. package/dist/api/delivery-assurance.d.ts.map +1 -1
  11. package/dist/api/delivery-assurance.js +5 -2
  12. package/dist/api/delivery-assurance.js.map +1 -1
  13. package/dist/api/product.d.ts +79 -2
  14. package/dist/api/product.d.ts.map +1 -1
  15. package/dist/api/product.js +145 -66
  16. package/dist/api/product.js.map +1 -1
  17. package/dist/api/recording.d.ts +60 -3
  18. package/dist/api/recording.d.ts.map +1 -1
  19. package/dist/api/recording.js +51 -38
  20. package/dist/api/recording.js.map +1 -1
  21. package/dist/api/routes.d.ts +76 -7
  22. package/dist/api/routes.d.ts.map +1 -1
  23. package/dist/api/routes.js +697 -51
  24. package/dist/api/routes.js.map +1 -1
  25. package/dist/api/run-timing-index.d.ts +12 -1
  26. package/dist/api/run-timing-index.d.ts.map +1 -1
  27. package/dist/api/run-timing-index.js +35 -0
  28. package/dist/api/run-timing-index.js.map +1 -1
  29. package/dist/api/server.d.ts.map +1 -1
  30. package/dist/api/server.js +3 -1
  31. package/dist/api/server.js.map +1 -1
  32. package/dist/apps/exec/texts.d.ts +1 -1
  33. package/dist/core/adapter.d.ts +11 -1
  34. package/dist/core/adapter.d.ts.map +1 -1
  35. package/dist/core/adapter.js +29 -1
  36. package/dist/core/adapter.js.map +1 -1
  37. package/dist/core/builtin-catalog.d.ts.map +1 -1
  38. package/dist/core/builtin-catalog.js +2 -0
  39. package/dist/core/builtin-catalog.js.map +1 -1
  40. package/dist/core/deliver-text.d.ts +42 -6
  41. package/dist/core/deliver-text.d.ts.map +1 -1
  42. package/dist/core/deliver-text.js +204 -27
  43. package/dist/core/deliver-text.js.map +1 -1
  44. package/dist/core/deliver.d.ts.map +1 -1
  45. package/dist/core/deliver.js +28 -7
  46. package/dist/core/deliver.js.map +1 -1
  47. package/dist/core/qe-acceptance-setting.d.ts.map +1 -1
  48. package/dist/core/qe-acceptance-setting.js +6 -0
  49. package/dist/core/qe-acceptance-setting.js.map +1 -1
  50. package/dist/team/routes.d.ts +10 -0
  51. package/dist/team/routes.d.ts.map +1 -1
  52. package/dist/team/routes.js +27 -0
  53. package/dist/team/routes.js.map +1 -1
  54. package/dist/workflow-catalog/build-v2.d.ts +90 -0
  55. package/dist/workflow-catalog/build-v2.d.ts.map +1 -0
  56. package/dist/workflow-catalog/build-v2.js +527 -0
  57. package/dist/workflow-catalog/build-v2.js.map +1 -0
  58. package/dist/workflow-catalog/catalog-data-v2.d.ts +12 -0
  59. package/dist/workflow-catalog/catalog-data-v2.d.ts.map +1 -0
  60. package/dist/workflow-catalog/catalog-data-v2.js +2582 -0
  61. package/dist/workflow-catalog/catalog-data-v2.js.map +1 -0
  62. package/dist/workflow-catalog/seeds-v2.d.ts +91 -0
  63. package/dist/workflow-catalog/seeds-v2.d.ts.map +1 -0
  64. package/dist/workflow-catalog/seeds-v2.js +2 -0
  65. package/dist/workflow-catalog/seeds-v2.js.map +1 -0
  66. package/dist/workflow-catalog/shape.d.ts +97 -0
  67. package/dist/workflow-catalog/shape.d.ts.map +1 -0
  68. package/dist/workflow-catalog/shape.js +97 -0
  69. package/dist/workflow-catalog/shape.js.map +1 -0
  70. package/endpoint-manifest.json +33 -3
  71. package/package.json +23 -4
@@ -37,6 +37,9 @@ import { createHash } from 'node:crypto';
37
37
  import { appendFileSync, chmodSync, existsSync, mkdirSync, readFileSync } from 'node:fs';
38
38
  import { dirname } from 'node:path';
39
39
  import { z } from '../zod.js';
40
+ import { parseCommand, resolveOption } from '../workflow-catalog/build-v2.js';
41
+ import { CATALOG_V2_CARDS } from '../workflow-catalog/catalog-data-v2.js';
42
+ import { checksLabel, factsOf, JobRefusal, mergeRevision, nounOf, optionFor, personAskedSkip, personPid, proposalKindOf, qeSkipBound, requestDigest, resolveJob, SEAT_WORDS, seatProtections, briefOf, SELF_SEATED, } from './chat-jobs.js';
40
43
  import { artifactExists, artifactHead, chatMount, parseArtifactRef, UNFILED_MOUNT } from './chat-context.js';
41
44
  import { tornTailPrefix } from './chat-transcripts.js';
42
45
  // ── the block ──────────────────────────────────────────────────────────────────────────────────────────────────────
@@ -104,6 +107,47 @@ export function parseMakeBlock(body) {
104
107
  const r = ThemeBlock.safeParse(o);
105
108
  return r.success ? { op: 'theme', ...r.data } : null;
106
109
  }
110
+ const InputValueSchema = z.discriminatedUnion('kind', [
111
+ z.strictObject({ kind: z.literal('text'), value: z.string().max(8000) }),
112
+ z.strictObject({ kind: z.literal('url'), value: z.string().max(2048) }),
113
+ z.strictObject({ kind: z.literal('requirements'), refs: z.array(z.strictObject({ repoId: z.string().min(1).max(200), key: z.string().min(1).max(200) })).min(1).max(50) }),
114
+ ]);
115
+ /** (DES-CATALOG-002 §4.6) The edits of a {@link ProposalRevision}, as a block or a request carries them. Unknown keys
116
+ * pass through to the merge, which drops each with a note (a refused edit leaves the rest standing). */
117
+ export const RevisionEditsSchema = z.looseObject({
118
+ card: z.string().trim().min(1).max(80).optional(),
119
+ option: z.string().trim().min(1).max(80).nullable().optional(),
120
+ depth: z.enum(['quick', 'standard', 'deep']).nullable().optional(),
121
+ repoRef: z.string().trim().min(1).max(200).optional(),
122
+ project: z.string().trim().max(128).nullable().optional(),
123
+ lead: z.string().trim().min(1).max(64).optional(),
124
+ addSeats: z.array(z.string().trim().min(1).max(64)).max(8).optional(),
125
+ removeSeats: z.array(z.string().trim().min(1).max(64)).max(8).optional(),
126
+ inputs: z.record(z.string().min(1).max(64), InputValueSchema).optional(),
127
+ detail: z.strictObject({ add: z.array(z.string().max(200)).max(8).optional(), remove: z.array(z.string().max(200)).max(8).optional() }).optional(),
128
+ skipQe: z.strictObject({ reason: z.string().trim().min(1).max(600) }).optional(),
129
+ restoreQe: z.literal(true).optional(),
130
+ confirmLoss: z.union([z.literal(true), z.array(z.string().min(1).max(40)).min(1).max(12)]).optional(),
131
+ });
132
+ /** A seat's typed revision block: `{"revises":"<pid>","edits":{…}}`. `null` for anything else. */
133
+ export function parseRevisionBlock(body) {
134
+ let raw;
135
+ try {
136
+ raw = JSON.parse(body);
137
+ }
138
+ catch {
139
+ return null;
140
+ }
141
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw))
142
+ return null;
143
+ const o = raw;
144
+ if (typeof o['revises'] !== 'string' || o['revises'] === '' || o['edits'] === null || typeof o['edits'] !== 'object')
145
+ return null;
146
+ const edits = RevisionEditsSchema.safeParse(o['edits']);
147
+ if (!edits.success)
148
+ return null;
149
+ return { revises: o['revises'], edits: edits.data };
150
+ }
107
151
  /** The last block of a reply that parses (DES §4.1: the last valid block wins), or `null`. */
108
152
  export function lastValidBlock(bodies) {
109
153
  for (let i = bodies.length - 1; i >= 0; i -= 1) {
@@ -157,16 +201,38 @@ export function foldProposals(records) {
157
201
  }
158
202
  // The newest proposal is the chat's one open proposal: a new pid, or a re-resolution of the newest (which replaces
159
203
  // its frozen choices: the next Go uses the fresh card).
160
- for (const [other, v] of out)
161
- if (other !== pid && v.state === 'open')
204
+ for (const [other, v] of out) {
205
+ if (other !== pid && (v.state === 'open' || v.state === 'revising')) {
162
206
  v.state = 'superseded';
207
+ delete v.hold;
208
+ }
209
+ }
163
210
  out.set(pid, { proposal: r.proposal, state: 'open', turnId: r.turnId });
164
211
  }
212
+ else if (r.kind === 'proposal_revising') {
213
+ // DES-CATALOG-002 §4.6: the person's message holds an open proposal while its seat turn may revise it.
214
+ const v = out.get(r.pid);
215
+ if (v === undefined || v.state !== 'open')
216
+ continue;
217
+ v.state = 'revising';
218
+ v.hold = r.turnId;
219
+ delete v.note;
220
+ }
221
+ else if (r.kind === 'proposal_released') {
222
+ const v = out.get(r.pid);
223
+ if (v === undefined || v.state !== 'revising' || v.hold !== r.turnId)
224
+ continue;
225
+ v.state = 'open';
226
+ delete v.hold;
227
+ if (r.note !== null)
228
+ v.note = r.note;
229
+ }
165
230
  else if (r.kind === 'proposal_accepting') {
166
231
  const v = out.get(r.pid);
167
232
  if (v === undefined || v.state === 'decided')
168
233
  continue;
169
234
  v.state = 'accepting';
235
+ delete v.hold;
170
236
  v.accepting = { pid: r.pid, actor: r.actor, edits: r.edits, resolution: r.resolution, identity: r.identity };
171
237
  }
172
238
  else if (r.kind === 'proposal_decided') {
@@ -186,6 +252,8 @@ export function viewOf(f) {
186
252
  return {
187
253
  proposal: f.accepting !== undefined && (f.state === 'accepting' || (f.state === 'decided' && f.decision === 'go')) ? f.accepting.resolution : f.proposal,
188
254
  state: f.state,
255
+ ...(f.hold !== undefined ? { revisingTurn: f.hold } : {}),
256
+ ...(f.note !== undefined ? { note: f.note } : {}),
189
257
  ...(f.decision !== undefined ? { decision: f.decision } : {}),
190
258
  ...(f.result !== undefined ? { result: f.result } : {}),
191
259
  ...(f.decidedAt !== undefined ? { decidedAt: f.decidedAt } : {}),
@@ -479,6 +547,17 @@ class EditRefusal extends Error {
479
547
  }
480
548
  /** The one block a person can lift from the card (Change something → two helpers); every other block is the record's. */
481
549
  const NEEDS_HELPER = 'Needs a second helper to check it';
550
+ /** A reshape's immutable context (the held run it replaces, its envelope, inherited reduced assurance) survives every
551
+ * re-resolution of its proposal: a revision, a catalog refresh (codex r1). */
552
+ function keepReshape(next, from) {
553
+ return {
554
+ ...next,
555
+ ...(from.reshapes !== undefined ? { reshapes: from.reshapes } : {}),
556
+ ...(from.relaunch !== undefined ? { relaunch: from.relaunch } : {}),
557
+ ...(from.reducedAssurance === true ? { reducedAssurance: true } : {}),
558
+ ...(from.heldRejected === true ? { heldRejected: true } : {}),
559
+ };
560
+ }
482
561
  export class ChatProposals {
483
562
  deps;
484
563
  lock = new KeyedLock();
@@ -486,6 +565,10 @@ export class ChatProposals {
486
565
  order = new KeyedLock();
487
566
  pending = new Set();
488
567
  costs = new Map();
568
+ /** Holds being written (`<chat>\0<turn>`): a reply to that turn waits for its hold first (codex r2). */
569
+ holding = new Map();
570
+ /** Turns whose reply is being settled (`<chat>\0<turn>` → replies in flight): their holds are not gone. */
571
+ settling = new Map();
489
572
  now;
490
573
  log;
491
574
  constructor(deps) {
@@ -527,6 +610,8 @@ export class ChatProposals {
527
610
  * so it runs off the fold; the record is appended only if the chat is still the same instance.
528
611
  */
529
612
  onReply(frame) {
613
+ // DES-CATALOG-002 §4.6: the turn's revision of a held job proposal (or the hold's release), first.
614
+ this.onTurnReply(frame);
530
615
  if (frame.blocks.length === 0 || frame.turnId === undefined || !frame.ok)
531
616
  return;
532
617
  if (!this.deps.flags().proposals)
@@ -568,7 +653,12 @@ export class ChatProposals {
568
653
  return;
569
654
  // Published under the chat's lock, so it never lands between an accept's checks and its record.
570
655
  await this.lock.run(`chat\u0000${instance ?? frame.chat}`, async () => {
571
- if (!has())
656
+ // DES-CATALOG-002 §4.6 (codex r1): a chat whose job lineage is open is changed only through a revision (merged,
657
+ // loss-checked); a seat's root block never replaces it.
658
+ const jobOpen = [...foldProposals(this.deps.records(frame.chat)).values()].some((f) => f.proposal.shape !== undefined && (f.state === 'open' || f.state === 'revising'));
659
+ if (jobOpen)
660
+ this.log(`[proposals] chat ${frame.chat}: turn ${turnId}'s block would replace the open job; a change to it is a revision — dropped`);
661
+ else if (!has())
572
662
  this.write(frame.chat, { at: this.now(), turnId, kind: 'proposal', proposal }, instance);
573
663
  });
574
664
  })
@@ -1033,6 +1123,13 @@ export class ChatProposals {
1033
1123
  return this.gone(chatId);
1034
1124
  return ok(reread());
1035
1125
  }
1126
+ // DES-CATALOG-002 §4.6 (codex r1): a v2 proposal whose run never started is re-checked against the catalog first;
1127
+ // a changed one is refreshed (the person starts the refreshed proposal), never retried on a stale revision.
1128
+ if (acc.resolution.shape !== undefined) {
1129
+ const stale = await this.lock.run(`chat\u0000${instance ?? chatId}`, () => this.jobStale(chatId, folded, instance));
1130
+ if (stale !== null)
1131
+ return stale;
1132
+ }
1036
1133
  // Go again: the frozen choices and identity, re-checked. Only the helpers may change (one may have signed out
1037
1134
  // since); everything else stays as accepted.
1038
1135
  let again = acc.resolution;
@@ -1044,8 +1141,8 @@ export class ChatProposals {
1044
1141
  again = await this.applyEdits(chatId, { ...folded, proposal: acc.resolution }, body.edits);
1045
1142
  }
1046
1143
  catch (err) {
1047
- if (err instanceof EditRefusal)
1048
- return { code: 400, body: { code: 'edits_invalid', error: err.message } };
1144
+ if (err instanceof EditRefusal || err instanceof JobRefusal)
1145
+ return this.refusalOf(err);
1049
1146
  throw err;
1050
1147
  }
1051
1148
  }
@@ -1054,20 +1151,54 @@ export class ChatProposals {
1054
1151
  if (folded.state === 'superseded') {
1055
1152
  return { code: 409, body: { code: 'proposal_superseded', error: 'a newer proposal in this chat replaced this one', view: viewOf(folded) } };
1056
1153
  }
1154
+ // DES-CATALOG-002 §4.6: a typed correction in flight holds Start. A hold whose turn is gone is released with its note
1155
+ // first (the person sees the proposal as it stands, and presses again).
1156
+ if (folded.state === 'revising' && body.decision === 'go') {
1157
+ if (await this.reopenStale(chatId, instance)) {
1158
+ return { code: 409, body: { code: 'proposal_reopened', error: "your typed change wasn't applied: check the job and press Start again", view: viewOf(reread()) } };
1159
+ }
1160
+ return { code: 409, body: { code: 'proposal_revising', error: 'your typed change is still being applied; Start waits for it', view: viewOf(folded) } };
1161
+ }
1057
1162
  // 2. Not now: nothing else is checked.
1058
1163
  if (body.decision === 'not_now') {
1059
1164
  if (!this.decided(chatId, folded.turnId, pid, actor, 'not_now', null, folded.proposal, null, instance))
1060
1165
  return this.gone(chatId);
1061
1166
  return ok(reread());
1062
1167
  }
1168
+ // DES-CATALOG-002 §4.6: a job's Go launches only what is on screen, against the catalog it was proposed on.
1169
+ if (kind === 'job') {
1170
+ if (!this.jobsOn())
1171
+ return { code: 409, body: { code: 'operation_unavailable', error: 'this daemon does not start jobs from a chat', view: viewOf(folded) } };
1172
+ if (folded.proposal.coming !== undefined) {
1173
+ return { code: 409, body: { code: 'card_not_available', error: folded.proposal.blocked ?? `${folded.proposal.what.label} is coming later`, nearest: folded.proposal.coming.nearest, view: viewOf(folded) } };
1174
+ }
1175
+ if (folded.proposal.question !== undefined && folded.proposal.question !== null) {
1176
+ return { code: 409, body: { code: 'proposal_blocked', error: folded.proposal.question.text, view: viewOf(folded) } };
1177
+ }
1178
+ }
1179
+ // Every v2 proposal (a job, or a document's create) starts only on the catalog it was proposed on (codex r1).
1180
+ if (folded.proposal.shape !== undefined) {
1181
+ const stale = await this.lock.run(`chat\u0000${instance ?? chatId}`, () => this.jobStale(chatId, folded, instance));
1182
+ if (stale !== null)
1183
+ return stale;
1184
+ }
1185
+ if (kind === 'job') {
1186
+ // A reshape starts only through its own transition (the held plan answered Reject first; codex r3).
1187
+ // The seats the proposal names can still work, before any edit re-resolves them (codex r3).
1188
+ const can = new Set(this.deps.rosterEligible().map((x) => x.key));
1189
+ const gone = (folded.proposal.seats?.keys ?? []).filter((k) => !can.has(k));
1190
+ if (gone.length > 0 && body.edits?.seats === undefined) {
1191
+ return { code: 409, body: { code: 'helper_unavailable', error: `${gone.join(' and ')} can't work now; change who works on it`, view: viewOf(folded) } };
1192
+ }
1193
+ }
1063
1194
  // 3. A fresh Go: the edits first (the one block a person can lift is a missing second helper), then the block.
1064
1195
  let effective;
1065
1196
  try {
1066
1197
  effective = await this.applyEdits(chatId, folded, body.edits);
1067
1198
  }
1068
1199
  catch (err) {
1069
- if (err instanceof EditRefusal)
1070
- return { code: 400, body: { code: 'edits_invalid', error: err.message } };
1200
+ if (err instanceof EditRefusal || err instanceof JobRefusal)
1201
+ return this.refusalOf(err);
1071
1202
  throw err;
1072
1203
  }
1073
1204
  if (effective.blocked !== null) {
@@ -1093,11 +1224,14 @@ export class ChatProposals {
1093
1224
  if (this.deps.instanceOf(chatId) !== instance)
1094
1225
  return this.gone(chatId);
1095
1226
  const now = foldProposals(this.deps.records(chatId)).get(pid);
1227
+ if (now?.state === 'revising') {
1228
+ return { code: 409, body: { code: 'proposal_revising', error: 'your typed change is still being applied; Start waits for it', view: viewOf(now) } };
1229
+ }
1096
1230
  if (now === undefined || now.state === 'superseded' || now.state === 'decided' || now.state !== folded.state) {
1097
1231
  return { code: 409, body: { code: now?.state === 'decided' ? 'proposal_decided' : 'proposal_superseded', error: 'this proposal changed while it was being answered; check the card again', ...(now !== undefined ? { view: viewOf(now) } : {}) } };
1098
1232
  }
1099
1233
  const flags = this.deps.flags();
1100
- if (!flags.proposals || !flags[kind] || !this.deps.registry.has(kind)) {
1234
+ if (!flags.proposals || !(kind === 'job' ? this.jobsOn() : flags[kind]) || !this.deps.registry.has(kind)) {
1101
1235
  return { code: 409, body: { code: 'operation_unavailable', error: `studio cannot start a ${kind === 'create' ? 'document' : kind} from a chat on this daemon yet`, view: viewOf(folded) } };
1102
1236
  }
1103
1237
  // The helpers can still work (one may have signed out since the card was drawn).
@@ -1108,6 +1242,21 @@ export class ChatProposals {
1108
1242
  return { code: 409, body: { code: 'helper_unavailable', error: `${lost.join(' and ')} can't work now; pick another helper`, view: viewOf(folded) } };
1109
1243
  }
1110
1244
  }
1245
+ // A job's seats can still work: Go never launches with fewer of them than the proposal names (codex r2).
1246
+ if (kind === 'job' && resolution.seats !== undefined && resolution.seats.keys.length > 0) {
1247
+ const can = new Set(this.deps.rosterEligible().map((s) => s.key));
1248
+ const lost = resolution.seats.keys.filter((k) => !can.has(k));
1249
+ if (lost.length > 0) {
1250
+ return { code: 409, body: { code: 'helper_unavailable', error: `${lost.join(' and ')} can't work now; change who works on it`, view: viewOf(folded) } };
1251
+ }
1252
+ }
1253
+ // Only the newest proposal of a lineage starts (a refreshed or revised one supersedes an interrupted one; codex r2).
1254
+ if (resolution.lineage !== undefined) {
1255
+ const newest = [...foldProposals(this.deps.records(chatId)).values()].filter((f) => f.proposal.lineage === resolution.lineage).pop();
1256
+ if (newest !== undefined && newest.proposal.pid !== pid) {
1257
+ return { code: 409, body: { code: 'proposal_superseded', error: 'a newer version of this job replaced this one', view: viewOf(newest) } };
1258
+ }
1259
+ }
1111
1260
  // Where it is filed still exists (a create or demo files into the chat's project).
1112
1261
  if ((kind === 'create' || kind === 'demo') && (await this.deps.docsRoot(resolution.filedIn.projectId ?? 'default')) === null) {
1113
1262
  return { code: 409, body: { code: 'source_gone', error: `${resolution.filedIn.label} is no longer on this daemon`, view: viewOf(folded) } };
@@ -1151,6 +1300,25 @@ export class ChatProposals {
1151
1300
  };
1152
1301
  }
1153
1302
  }
1303
+ // DES-CATALOG-002 §4.6/§2.5 (codex r4): what can be checked before anything changes is checked first (a Backlog's
1304
+ // requirements, its project's members), so a reshape never answers its held plan for a launch that would refuse.
1305
+ if (kind === 'job' && this.deps.preflight !== undefined) {
1306
+ const why = await this.deps.preflight(resolution);
1307
+ if (why !== null)
1308
+ return { code: 409, body: { code: 'proposal_blocked', error: why, view: viewOf(folded) } };
1309
+ }
1310
+ // §2.5: a reshape (or its corrected descendant) answers the held plan Reject first, in this one transition; the
1311
+ // proposal then records that it did, so a retry launches without asking again.
1312
+ if (resolution.reshapes !== undefined && resolution.heldRejected !== true) {
1313
+ if (this.deps.reshapeReject === undefined)
1314
+ return { code: 409, body: { code: 'operation_unavailable', error: 'this daemon cannot answer the held plan for a reshape', view: viewOf(folded) } };
1315
+ const refused = await this.deps.reshapeReject(resolution.reshapes, actor, pid);
1316
+ if (refused !== null)
1317
+ return refused;
1318
+ resolution = { ...resolution, heldRejected: true };
1319
+ if (!this.write(chatId, { at: this.now(), turnId: folded.turnId, kind: 'proposal', proposal: { ...(now.accepting?.resolution ?? now.proposal), heldRejected: true } }, instance))
1320
+ return this.gone(chatId);
1321
+ }
1154
1322
  // Recorded before anything starts.
1155
1323
  const accepting = { at: this.now(), turnId: folded.turnId, kind: 'proposal_accepting', pid, actor: actor.id, edits, resolution, identity };
1156
1324
  if (!this.write(chatId, accepting, instance))
@@ -1236,18 +1404,20 @@ export class ChatProposals {
1236
1404
  */
1237
1405
  async busy(chatId, artifactRef, p) {
1238
1406
  const runs = await this.deps.runs();
1407
+ // A reshape's held run is the one it replaces: answered Reject inside this Go, so it does not make the chat busy.
1408
+ const held = p.reshapes !== undefined && p.heldRejected !== true ? p.reshapes : null;
1239
1409
  for (const f of foldProposals(this.deps.records(chatId)).values()) {
1240
1410
  if (f.proposal.pid === p.pid)
1241
1411
  continue;
1242
1412
  // Another proposal of this chat started a job (decided go, or accepting with its run launched) still live.
1243
1413
  const runId = f.state === 'decided' && f.decision === 'go' ? f.result?.runId ?? null
1244
1414
  : f.state === 'accepting' ? f.accepting?.identity.runId ?? null : null;
1245
- if (runId !== null && (await this.deps.registry.live(f.proposal.kind, runId))) {
1415
+ if (runId !== null && runId !== held && (await this.deps.registry.live(f.proposal.kind, runId))) {
1246
1416
  return { code: 'chat_busy', reason: `This chat already has a job running (${f.proposal.what.label}). Wait, or stop that run.` };
1247
1417
  }
1248
1418
  }
1249
1419
  for (const v of runs) {
1250
- if (!isLive(v) || this.deps.chatOfRun(v.session.id) !== chatId || this.deps.isAskPath(v.session.id))
1420
+ if (!isLive(v) || v.session.id === held || this.deps.chatOfRun(v.session.id) !== chatId || this.deps.isAskPath(v.session.id))
1251
1421
  continue;
1252
1422
  return { code: 'chat_busy', reason: `This chat already has a job running (run ${v.session.id.slice(0, 8)}). Wait, or stop that run.` };
1253
1423
  }
@@ -1277,14 +1447,17 @@ export class ChatProposals {
1277
1447
  const p = f.proposal;
1278
1448
  if (edits === undefined)
1279
1449
  return p;
1450
+ if (p.kind === 'job')
1451
+ return this.applyJobEdits(chatId, f, edits);
1280
1452
  const allowed = {
1281
1453
  create: p.artifactRef !== undefined ? ['title', 'brief', 'sources', 'helpers'] : ['title', 'brief', 'sources', 'helpers', 'repos', 'project'],
1282
1454
  refine: ['ask', 'helpers'],
1283
1455
  theme: ['name', 'patch'],
1284
1456
  demo: ['audience', 'show', 'helpers'],
1285
1457
  };
1458
+ const kindAllowed = allowed[p.kind];
1286
1459
  for (const k of Object.keys(edits)) {
1287
- if (!allowed[p.kind].includes(k))
1460
+ if (!kindAllowed.includes(k))
1288
1461
  throw new EditRefusal(`${k} can't be changed on a ${p.kind} proposal here yet`);
1289
1462
  }
1290
1463
  let next = { ...p };
@@ -1465,6 +1638,653 @@ export class ChatProposals {
1465
1638
  delete out.repoRefs;
1466
1639
  return out;
1467
1640
  }
1641
+ // ── DES-CATALOG-002 §4.6: job proposals ──────────────────────────────────────────────────────────────────────────
1642
+ /** (DES-CATALOG-002 §4.6) Whether a seat's job block may become a job proposal in this chat (its client draws them);
1643
+ * an older client gets the prose command line instead (Lane D's chat statement). */
1644
+ acceptsJobs(chatId) {
1645
+ return this.jobsOn() && this.deps.acceptsJobs?.(chatId) === true;
1646
+ }
1647
+ /** The chat as a job's resolution sees it, or `null` once it has ended. */
1648
+ jobChat(chatId) {
1649
+ const c = this.deps.chat(chatId);
1650
+ return c === null ? null : { projectId: c.projectId, repos: c.repos, lead: c.lead, seats: c.seats };
1651
+ }
1652
+ async jobContext(chatId, pid, turnId, seat, chat, extra) {
1653
+ if (this.deps.served === undefined)
1654
+ throw new JobRefusal('operation_unavailable', 'this daemon cannot read its catalog for a job', 409);
1655
+ let served;
1656
+ try {
1657
+ served = await this.deps.served(chat.projectId);
1658
+ }
1659
+ catch (err) {
1660
+ throw new JobRefusal('catalog_unavailable', err instanceof Error ? err.message : String(err), 409);
1661
+ }
1662
+ const projectLabel = chat.projectId === null ? 'Not in a project · this chat' : ((await this.deps.projectName(chat.projectId)) ?? chat.projectId);
1663
+ const qeOff = (await this.deps.qeOff?.().catch(() => false)) === true;
1664
+ return { chatId, pid, turnId, seat, chat, served, roster: this.deps.rosterEligible(), projectLabel, qeOff, ...extra };
1665
+ }
1666
+ /** Job proposals are on: the flag, the catalog read and the operation. */
1667
+ jobsOn() {
1668
+ return this.deps.flags().proposals && this.deps.jobs?.() === true && this.deps.served !== undefined;
1669
+ }
1670
+ /**
1671
+ * A document option picked or reached by a revision is an artifact `create` (§4.6 "Across kinds"): the existing create
1672
+ * resolution (sources, scope, helpers, its own identity), with the conversation's fields on it.
1673
+ */
1674
+ async documentProposal(chatId, pid, facts, ctx, records) {
1675
+ const card = CATALOG_V2_CARDS.find((c) => c.id === facts.card);
1676
+ const r = resolveOption(card.id, optionFor(card, facts.option), ctx.served);
1677
+ const style = r?.style ?? null;
1678
+ const seed = this.deps.catalog.find((c) => c.launch.kind === 'document' && c.launch.style === style);
1679
+ if (r === null || seed === undefined)
1680
+ throw new JobRefusal('operation_unavailable', `${card.title} can't be made from a chat on this daemon`, 409);
1681
+ if (!this.deps.flags().create)
1682
+ throw new JobRefusal('operation_unavailable', 'studio cannot start a document from a chat on this daemon yet', 409);
1683
+ const turnId = ctx.turnId ?? `person:${pid.slice(pid.lastIndexOf(':') + 1)}`;
1684
+ const words = [briefOf(facts), r.resolved.brief ?? ''].filter((x) => x !== '').join('\n\n');
1685
+ const made = await this.resolve({ chatId, turnId, seat: ctx.seat, block: { op: 'entry', entry: seed.id, brief: words, sources: ['chat'], repos: facts.repoRef !== null ? [facts.repoRef] : [] }, records });
1686
+ if (made === null)
1687
+ throw new JobRefusal('operation_unavailable', 'studio cannot start a document from a chat on this daemon yet', 409);
1688
+ const shape = { card: card.id, option: r.option?.id ?? null, depth: null, by: facts.by, source: facts.source, ...(facts.guess !== undefined ? { guess: facts.guess } : {}) };
1689
+ const kindTok = { id: 'kind', kind: (card.variant !== undefined ? 'option' : 'card'), label: nounOf(card, shape.option), swap: null };
1690
+ const checksTok = { id: 'checks', kind: 'checks', label: checksLabel(r.resolved.gate), swap: null };
1691
+ return {
1692
+ ...made,
1693
+ pid,
1694
+ turnId: ctx.turnId,
1695
+ // `what.entry` stays the document entry the create launcher reads its style from (codex r1); the card is in `shape`.
1696
+ shape,
1697
+ catalogRev: ctx.served.rev,
1698
+ resolution: r.resolved.resolution,
1699
+ launch: 'document',
1700
+ command: r.option?.command ?? card.command,
1701
+ gate: [...r.resolved.gate],
1702
+ words: facts.words,
1703
+ details: [...facts.details],
1704
+ sentence: { text: `I'll make {kind} from this conversation, filed in ${made.filedIn.label}, checked by {checks}.`, tokens: [kindTok, checksTok], notes: [...ctx.notes], ask: made.blocked === null ? 'Start?' : null },
1705
+ suggestions: [],
1706
+ question: null,
1707
+ revises: ctx.revises,
1708
+ lineage: ctx.lineage ?? pid,
1709
+ ...(ctx.answers !== undefined ? { answers: ctx.answers } : {}),
1710
+ ...(ctx.request !== undefined ? { request: ctx.request } : {}),
1711
+ };
1712
+ }
1713
+ /** Resolve facts to the proposal of their kind (a job, or a document's create). */
1714
+ async proposalOf(chatId, pid, facts, ctx, records, allowHidden = false) {
1715
+ const card = CATALOG_V2_CARDS.find((c) => c.id === facts.card);
1716
+ const r = card === undefined ? null : resolveOption(card.id, optionFor(card, facts.option), ctx.served);
1717
+ if (r !== null && proposalKindOf(r) === 'create')
1718
+ return this.documentProposal(chatId, pid, facts, ctx, records);
1719
+ return resolveJob(facts, ctx, { allowHidden });
1720
+ }
1721
+ refusalOf(err) {
1722
+ if (err instanceof JobRefusal)
1723
+ return { code: err.status, body: { code: err.code, error: err.message } };
1724
+ if (err instanceof EditRefusal)
1725
+ return { code: 400, body: { code: 'edits_invalid', error: err.message } };
1726
+ return null;
1727
+ }
1728
+ /**
1729
+ * `POST /chats/:id/proposals` after the route's capability, person and owner checks: a person-made proposal (a `/`
1730
+ * pick, a typed command, a question's choice) or a revision (a swap, a suggestion, a question's choice). No seat turn
1731
+ * runs. A repeated `requestId` answers the same proposal; another body under it is refused.
1732
+ */
1733
+ propose(chatId, body, actor, instance) {
1734
+ return this.lock.run(`chat\u0000${instance ?? chatId}`, async () => {
1735
+ if (this.deps.instanceOf(chatId) !== instance)
1736
+ return this.gone(chatId);
1737
+ if (!this.jobsOn())
1738
+ return { code: 409, body: { code: 'operation_unavailable', error: 'this daemon does not take job proposals from a chat' } };
1739
+ const pid = personPid(chatId, actor.id, body.requestId);
1740
+ const digest = requestDigest(body);
1741
+ const records = this.deps.records(chatId);
1742
+ const held = foldProposals(records).get(pid);
1743
+ if (held !== undefined) {
1744
+ if (held.proposal.request?.digest === digest)
1745
+ return { code: 201, body: { view: viewOf(held) } };
1746
+ return { code: 409, body: { code: 'request_reused', error: 'this requestId already made a different proposal', view: viewOf(held) } };
1747
+ }
1748
+ try {
1749
+ if ('revises' in body) {
1750
+ return await this.reviseLocked(chatId, { revises: body.revises, edits: body.edits }, { person: actor, source: body.source, pid, request: { id: body.requestId, digest }, turnId: null, message: null }, instance);
1751
+ }
1752
+ const chat = this.jobChat(chatId);
1753
+ if (chat === null)
1754
+ return { code: 409, body: { code: 'chat_gone', error: `chat ${chatId} has ended; start a new one` } };
1755
+ // A command names its card (and maybe its option); an alias is the only way to a hidden card.
1756
+ let card = body.card;
1757
+ let option = body.option;
1758
+ let allowHidden = false;
1759
+ if (card.startsWith('/')) {
1760
+ const hit = parseCommand(card);
1761
+ if (hit === null)
1762
+ return { code: 400, body: { code: 'card_unknown', error: `no job has the command ${card.slice(0, 80)}` } };
1763
+ allowHidden = CATALOG_V2_CARDS.find((c) => c.id === hit.card)?.aliases.some((a) => a.command.toLowerCase() === card.trim().split(/\s+/u)[0].toLowerCase()) === true;
1764
+ card = hit.card;
1765
+ if (option === undefined && hit.option !== undefined)
1766
+ option = hit.option;
1767
+ }
1768
+ const facts = {
1769
+ card,
1770
+ option,
1771
+ depth: body.depth ?? null,
1772
+ words: (body.words ?? '').slice(0, 8000),
1773
+ details: [],
1774
+ repoRef: null,
1775
+ projectId: chat.projectId,
1776
+ lead: null,
1777
+ seats: null,
1778
+ inputs: {},
1779
+ skipQe: null,
1780
+ by: 'person',
1781
+ source: body.source,
1782
+ };
1783
+ const ctx = await this.jobContext(chatId, pid, null, 'person', chat, { revises: null, lineage: null, notes: [], request: { id: body.requestId, digest } });
1784
+ const proposal = await this.proposalOf(chatId, pid, facts, ctx, records, allowHidden);
1785
+ if (!this.write(chatId, { at: this.now(), turnId: `person:${pid.slice(pid.lastIndexOf(':') + 1)}`, kind: 'proposal', proposal }, instance))
1786
+ return this.gone(chatId);
1787
+ const view = foldProposals(this.deps.records(chatId)).get(pid);
1788
+ return { code: 201, body: { view: view !== undefined ? viewOf(view) : { proposal, state: 'open' } } };
1789
+ }
1790
+ catch (err) {
1791
+ const refused = this.refusalOf(err);
1792
+ if (refused !== null)
1793
+ return refused;
1794
+ throw err;
1795
+ }
1796
+ });
1797
+ }
1798
+ /**
1799
+ * A revision of the lineage's open proposal (§4.6), under the chat's lock: the stale-parent check, the merge, the
1800
+ * lost-check question, the re-resolution, and the write that supersedes the parent. `src.person` is the person's
1801
+ * route (only it takes `confirmLoss`); otherwise a seat's block bound to the person's message `src.turnId`.
1802
+ */
1803
+ async reviseLocked(chatId, rev, src, instance) {
1804
+ const records = this.deps.records(chatId);
1805
+ const folded = foldProposals(records);
1806
+ const parent = folded.get(rev.revises);
1807
+ if (parent === undefined)
1808
+ return { code: 404, body: { error: `no proposal ${rev.revises} in chat ${chatId}` } };
1809
+ // The parent must be the lineage's open proposal: superseded, accepted, decided, or held by another turn is stale.
1810
+ const ownHold = parent.state === 'revising' && src.turnId !== null && parent.hold === src.turnId;
1811
+ if (!(parent.state === 'open' || ownHold)) {
1812
+ return { code: 409, body: { code: parent.state === 'revising' ? 'proposal_revising' : 'proposal_stale', error: parent.state === 'revising' ? 'your typed change is still being applied; wait for it' : 'this proposal is no longer the open one in this chat', view: viewOf(parent) } };
1813
+ }
1814
+ if (parent.proposal.shape === undefined)
1815
+ return { code: 400, body: { code: 'edits_invalid', error: 'only a job proposal is revised this way' } };
1816
+ const chat = this.jobChat(chatId);
1817
+ if (chat === null)
1818
+ return { code: 409, body: { code: 'chat_gone', error: `chat ${chatId} has ended; start a new one` } };
1819
+ const fromPerson = src.person !== null;
1820
+ // Only the person's own press can give up a check.
1821
+ const edits = { ...rev.edits };
1822
+ // What the press confirms (codex r4): `true` on a lost-check question covers exactly what that question names; a
1823
+ // swap or suggestion carries the ids its own label named. Anything else covers nothing.
1824
+ const confirmIds = !fromPerson || edits.confirmLoss === undefined
1825
+ ? null
1826
+ : Array.isArray(edits.confirmLoss)
1827
+ ? new Set(edits.confirmLoss)
1828
+ : parent.proposal.question?.kind === 'lost_check'
1829
+ ? new Set([...(parent.proposal.question.lost ?? []), ...(parent.proposal.question.lostSeats ?? [])])
1830
+ : new Set();
1831
+ const confirmed = confirmIds !== null;
1832
+ delete edits.confirmLoss;
1833
+ const ctx0 = await this.jobContext(chatId, src.pid, src.turnId, fromPerson ? 'person' : (parent.proposal.seat ?? 'seat'), chat, {
1834
+ revises: parent.proposal.pid,
1835
+ lineage: parent.proposal.lineage ?? parent.proposal.pid,
1836
+ notes: [],
1837
+ ...(src.turnId !== null ? { answers: src.turnId } : {}),
1838
+ ...(src.request !== undefined ? { request: src.request } : {}),
1839
+ });
1840
+ // A QE skip is never applied from a seat's block (§4.6 step 7, §9.2 (ac)): it becomes wicked's question, with the
1841
+ // person's own reason when their message (the one this turn answers) gives one unquoted, else asking for it. A skip
1842
+ // the person never asked for in their own words changes nothing. On the person's route, only the press applies it.
1843
+ let qe = null;
1844
+ const extraNotes = [];
1845
+ if (edits.skipQe !== undefined && !confirmed) {
1846
+ const reason = edits.skipQe.reason;
1847
+ delete edits.skipQe;
1848
+ if (parent.proposal.gate?.includes('qe-acceptance') !== true)
1849
+ extraNotes.push('Not changed: this job has no QE acceptance to skip.');
1850
+ else if (fromPerson || qeSkipBound(reason, src.message))
1851
+ qe = { reason };
1852
+ else if (personAskedSkip(src.message))
1853
+ qe = { reason: null };
1854
+ else
1855
+ extraNotes.push('Not changed: QE acceptance stays. Skipping it needs your own reason, in your own words.');
1856
+ }
1857
+ const merged = mergeRevision(parent.proposal, edits, { chat, served: ctx0.served, roster: ctx0.roster });
1858
+ merged.notes.push(...extraNotes);
1859
+ const ctx = { ...ctx0, notes: merged.notes };
1860
+ // A hidden card stays reachable while the revision keeps it (it was reached by its alias once).
1861
+ const allowHidden = merged.facts.card === parent.proposal.shape.card;
1862
+ // The candidate as it would be written, settings included (a daemon's QE setting can drop QE from it): its checks
1863
+ // are compared with the parent's too, so nothing is lost unseen (codex r2).
1864
+ let candidate = null;
1865
+ let candidateErr = null;
1866
+ try {
1867
+ candidate = keepReshape(await this.proposalOf(chatId, src.pid, { ...merged.facts, by: fromPerson ? 'person' : merged.facts.by, source: src.source }, ctx, records, allowHidden), parent.proposal);
1868
+ }
1869
+ catch (err) {
1870
+ candidateErr = err;
1871
+ }
1872
+ // Losses only the fully resolved candidate shows (a daemon setting since): never covered by an earlier press.
1873
+ const extra = [];
1874
+ for (const g of parent.proposal.gate ?? [])
1875
+ if (candidate !== null && !(candidate.gate ?? []).includes(g) && !merged.lost.includes(g) && !(g === 'qe-acceptance' && merged.facts.skipQe !== null))
1876
+ extra.push(g);
1877
+ merged.lost.push(...extra);
1878
+ const loses = merged.lost.length > 0 || merged.lostSeats.length > 0;
1879
+ // A press confirms exactly what was disclosed to it (codex r3): the question's named losses, or a swap's own
1880
+ // (catalog-derived, named in its label). A loss beyond that asks again.
1881
+ const uncovered = confirmIds === null ? [...merged.lost, ...merged.lostSeats] : [...merged.lost, ...merged.lostSeats].filter((k) => !confirmIds.has(k));
1882
+ const covered = confirmed && uncovered.length === 0;
1883
+ // A candidate the daemon cannot make is said at once, never behind a question it could not honour (codex r4, r5):
1884
+ // a refusal, or a candidate blocked for a reason no answer fixes (unavailable, coming).
1885
+ if (candidate === null && candidateErr !== null && loses && !covered) {
1886
+ const refused = this.refusalOf(candidateErr);
1887
+ if (refused !== null)
1888
+ return refused;
1889
+ }
1890
+ // Unmakeable = coming, or blocked for a reason other than the one question an answer fixes (codex r6).
1891
+ const unmakeable = candidate !== null && (candidate.coming !== undefined || (candidate.blocked !== null && candidate.blocked !== (candidate.question?.text ?? null)));
1892
+ if (candidate !== null && loses && !covered && unmakeable) {
1893
+ return { code: 409, body: { code: 'card_not_available', error: candidate.blocked, view: viewOf(parent) } };
1894
+ }
1895
+ if (qe !== null || (loses && !covered)) {
1896
+ const base = keepReshape(await this.proposalOf(chatId, src.pid, factsOf(parent.proposal), ctx, records, true), parent.proposal);
1897
+ const newCard = CATALOG_V2_CARDS.find((c) => c.id === merged.facts.card);
1898
+ const oldCard = CATALOG_V2_CARDS.find((c) => c.id === parent.proposal.shape.card);
1899
+ const newNoun = nounOf(newCard, optionFor(newCard, merged.facts.option));
1900
+ const oldNoun = nounOf(oldCard, parent.proposal.shape.option);
1901
+ // The choice carries exactly the edits crew kept (codex r1: never a refused seat skip), plus the press.
1902
+ const lossEdit = { ...edits, confirmLoss: true };
1903
+ let question;
1904
+ if (qe !== null && !loses) {
1905
+ question = qe.reason === null
1906
+ ? { kind: 'lost_check', text: 'Skip QE acceptance? Say why, and the job will be labelled with your reason.', choices: [{ label: 'Keep QE', edit: {} }], lost: ['qe-acceptance'], input: { kind: 'text', label: 'Your reason', edit: 'skipQe.reason' } }
1907
+ : { kind: 'lost_check', text: `Skip QE acceptance? The job will be labelled with your reason: “${qe.reason}”.`, choices: [{ label: 'Skip it', edit: { ...lossEdit, skipQe: { reason: qe.reason } } }, { label: 'Keep QE', edit: {} }], lost: ['qe-acceptance'] };
1908
+ }
1909
+ else {
1910
+ const lost = qe?.reason !== null && qe !== null ? [...new Set(['qe-acceptance', ...merged.lost])] : merged.lost;
1911
+ const choice = qe !== null && qe.reason !== null ? { ...lossEdit, skipQe: { reason: qe.reason } } : lossEdit;
1912
+ const words = [...lost.map((g) => checksLabel([g])), ...merged.lostSeats.map((k) => SEAT_WORDS[k])];
1913
+ const lostText = words.length <= 1 ? (words[0] ?? '') : `${words.slice(0, -1).join(', ')} and ${words[words.length - 1]}`;
1914
+ question = {
1915
+ kind: 'lost_check',
1916
+ text: newNoun === oldNoun ? `That would no longer have ${lostText}. Change it anyway?` : `That's ${newNoun}, not ${oldNoun}: it would no longer have ${lostText}. Make it ${newNoun}?`,
1917
+ choices: [{ label: newNoun === oldNoun ? 'Change it' : `Make it ${newNoun}`, edit: choice }, { label: `Keep ${oldNoun}`, edit: {} }],
1918
+ lost,
1919
+ ...(merged.lostSeats.length > 0 ? { lostSeats: merged.lostSeats } : {}),
1920
+ };
1921
+ }
1922
+ const asked = {
1923
+ ...base,
1924
+ // The baseline stays what the person saw (codex r3): a later unrelated revision compares against it.
1925
+ gate: [...new Set([...(parent.proposal.gate ?? []), ...(base.gate ?? [])])],
1926
+ seatRules: [...new Set([...(parent.proposal.seatRules ?? []), ...(base.seatRules ?? [])])],
1927
+ question,
1928
+ suggestions: [],
1929
+ blocked: question.text,
1930
+ ...(base.sentence !== undefined ? { sentence: { ...base.sentence, ask: question.text } } : {}),
1931
+ };
1932
+ if (!this.write(chatId, { at: this.now(), turnId: src.turnId ?? `person:${src.pid.slice(src.pid.lastIndexOf(':') + 1)}`, kind: 'proposal', proposal: asked }, instance))
1933
+ return this.gone(chatId);
1934
+ const view = foldProposals(this.deps.records(chatId)).get(src.pid);
1935
+ return { code: 201, body: { view: view !== undefined ? viewOf(view) : { proposal: asked, state: 'open' } } };
1936
+ }
1937
+ // A seat's revision that changes nothing and says nothing re-proposes nothing ("skip parity": the seat says why).
1938
+ if (!fromPerson && merged.unchanged && merged.notes.length === 0)
1939
+ return { code: 200, body: { view: viewOf(parent) } };
1940
+ if (candidate === null)
1941
+ throw candidateErr;
1942
+ const proposal = candidate;
1943
+ if (!this.write(chatId, { at: this.now(), turnId: src.turnId ?? `person:${src.pid.slice(src.pid.lastIndexOf(':') + 1)}`, kind: 'proposal', proposal }, instance))
1944
+ return this.gone(chatId);
1945
+ const view = foldProposals(this.deps.records(chatId)).get(src.pid);
1946
+ return { code: 201, body: { view: view !== undefined ? viewOf(view) : { proposal, state: 'open' } } };
1947
+ }
1948
+ /**
1949
+ * The person's message `turnId` was written (`POST /chats/:id/messages`): the chat's open job proposal is held as
1950
+ * `revising` until that turn settles, under the lock Go takes, so a Go is either before the message (and launches
1951
+ * what was on screen) or after it (and waits).
1952
+ */
1953
+ holdForMessage(chatId, turnId) {
1954
+ const instance = this.deps.instanceOf(chatId);
1955
+ const key = `${chatId}\u0000${turnId}`;
1956
+ const done = this.lock.run(`chat\u0000${instance ?? chatId}`, async () => {
1957
+ if (!this.jobsOn() || this.deps.instanceOf(chatId) !== instance)
1958
+ return;
1959
+ for (const f of foldProposals(this.deps.records(chatId)).values()) {
1960
+ if (f.state !== 'open' || f.proposal.shape === undefined)
1961
+ continue;
1962
+ this.write(chatId, { at: this.now(), turnId, kind: 'proposal_revising', pid: f.proposal.pid }, instance);
1963
+ }
1964
+ });
1965
+ this.holding.set(key, done);
1966
+ void done.finally(() => {
1967
+ if (this.holding.get(key) === done)
1968
+ this.holding.delete(key);
1969
+ }).catch(() => undefined);
1970
+ return done;
1971
+ }
1972
+ /**
1973
+ * A seat's reply to a turn that holds a job proposal: its revision block (bound to that turn's message) is merged and
1974
+ * published, or refused; either way, and when the turn wrote none or failed, the hold ends.
1975
+ */
1976
+ onTurnReply(frame) {
1977
+ const turnId = frame.turnId;
1978
+ if (turnId === undefined || !this.jobsOn())
1979
+ return;
1980
+ // Answered, not gone: a read must not release this hold while its revision is still queued (codex r1).
1981
+ const key = `${frame.chat}\u0000${turnId}`;
1982
+ this.settling.set(key, (this.settling.get(key) ?? 0) + 1);
1983
+ const instance = this.deps.instanceOf(frame.chat);
1984
+ const job = this.order.run(`chat\u0000${frame.chat}`, async () => {
1985
+ // The hold is written with the person's message, which can land just after a fast reply.
1986
+ const heldBy = () => [...foldProposals(this.deps.records(frame.chat)).values()].find((f) => f.state === 'revising' && f.hold === turnId);
1987
+ for (let i = 0; i < 25 && heldBy() === undefined && !this.deps.records(frame.chat).some((r) => r.kind === 'user' && r.turnId === turnId); i += 1) {
1988
+ await new Promise((res) => setTimeout(res, 200));
1989
+ }
1990
+ // The hold is enqueued with the message; a fast reply waits for it to be written, not only for the message.
1991
+ await this.holding.get(`${frame.chat}\u0000${turnId}`);
1992
+ if (heldBy() === undefined)
1993
+ return;
1994
+ await this.lock.run(`chat\u0000${instance ?? frame.chat}`, async () => {
1995
+ if (this.deps.instanceOf(frame.chat) !== instance)
1996
+ return;
1997
+ const held = heldBy();
1998
+ if (held === undefined)
1999
+ return;
2000
+ let note = frame.ok ? null : "Your change wasn't applied: say it again.";
2001
+ if (frame.ok) {
2002
+ let rev = null;
2003
+ for (let i = frame.blocks.length - 1; i >= 0 && rev === null; i -= 1)
2004
+ rev = parseRevisionBlock(frame.blocks[i]);
2005
+ if (rev !== null && rev.revises === held.proposal.pid) {
2006
+ const message = this.deps.records(frame.chat).find((r) => r.kind === 'user' && r.turnId === turnId && r.owner === true)?.text ?? null;
2007
+ try {
2008
+ const out = await this.reviseLocked(frame.chat, rev, { person: null, source: 'chat', pid: `${frame.chat}:${turnId}`, turnId, message }, instance);
2009
+ if (out.code >= 400)
2010
+ this.log(`[proposals] chat ${frame.chat}: turn ${turnId}'s revision was refused (${String(out.body.code ?? out.code)})`);
2011
+ }
2012
+ catch (err) {
2013
+ note = "Your change wasn't applied: say it again.";
2014
+ this.log(`[proposals] chat ${frame.chat}: turn ${turnId}'s revision failed: ${err instanceof Error ? err.message : String(err)}`);
2015
+ }
2016
+ }
2017
+ else if (rev !== null) {
2018
+ this.log(`[proposals] chat ${frame.chat}: turn ${turnId}'s revision names ${rev.revises}, not the proposal its message held — dropped`);
2019
+ }
2020
+ }
2021
+ // Released whatever happened (a published revision supersedes the parent; the record is then a no-op).
2022
+ this.write(frame.chat, { at: this.now(), turnId, kind: 'proposal_released', pid: held.proposal.pid, note }, instance);
2023
+ });
2024
+ })
2025
+ .catch((err) => this.log(`[proposals] chat ${frame.chat}: turn ${turnId}'s hold could not be settled: ${err instanceof Error ? err.message : String(err)}`))
2026
+ .finally(() => {
2027
+ this.pending.delete(job);
2028
+ const n = (this.settling.get(key) ?? 1) - 1;
2029
+ if (n <= 0)
2030
+ this.settling.delete(key);
2031
+ else
2032
+ this.settling.set(key, n);
2033
+ });
2034
+ this.pending.add(job);
2035
+ }
2036
+ /**
2037
+ * A hold whose turn is no longer live (it failed or expired, or a restart forgot it) is released with a note, so the
2038
+ * proposal is startable again. Called by a Go and by a read of the chat. `true` when one was released.
2039
+ */
2040
+ async reopenStale(chatId, instance = this.deps.instanceOf(chatId)) {
2041
+ if (this.deps.turnLive === undefined)
2042
+ return false;
2043
+ const gone = (turnId) => !this.deps.turnLive(chatId, turnId) && !this.settling.has(`${chatId}\u0000${turnId}`);
2044
+ const stale = [...foldProposals(this.deps.records(chatId)).values()].filter((f) => f.state === 'revising' && f.hold !== undefined && gone(f.hold));
2045
+ if (stale.length === 0)
2046
+ return false;
2047
+ return this.lock.run(`chat\u0000${instance ?? chatId}`, async () => {
2048
+ let released = false;
2049
+ for (const f of foldProposals(this.deps.records(chatId)).values()) {
2050
+ if (f.state !== 'revising' || f.hold === undefined || !gone(f.hold))
2051
+ continue;
2052
+ released = this.write(chatId, { at: this.now(), turnId: f.hold, kind: 'proposal_released', pid: f.proposal.pid, note: "Your change wasn't applied: say it again." }, instance) || released;
2053
+ }
2054
+ return released;
2055
+ });
2056
+ }
2057
+ /** A job's Go edits (option, depth, repository, seats, inputs) merged by the revision rules: one that loses a check
2058
+ * is refused (that is the person's press on the lost-check question, not an edit at Go). */
2059
+ async applyJobEdits(chatId, f, edits) {
2060
+ const allowed = ['option', 'depth', 'repoRef', 'seats', 'inputs'];
2061
+ for (const k of Object.keys(edits))
2062
+ if (!allowed.includes(k))
2063
+ throw new EditRefusal(`${k} can't be changed on a job proposal`);
2064
+ const chat = this.jobChat(chatId);
2065
+ if (chat === null)
2066
+ throw new EditRefusal('this chat has ended');
2067
+ const rev = {
2068
+ ...(edits.option !== undefined ? { option: edits.option } : {}),
2069
+ ...(edits.depth !== undefined ? { depth: edits.depth } : {}),
2070
+ ...(edits.repoRef !== undefined ? { repoRef: edits.repoRef } : {}),
2071
+ ...(edits.inputs !== undefined ? { inputs: edits.inputs } : {}),
2072
+ };
2073
+ const ctx = await this.jobContext(chatId, f.proposal.pid, f.proposal.turnId, f.proposal.seat, chat, { revises: f.proposal.revises ?? null, lineage: f.proposal.lineage ?? f.proposal.pid, notes: [] });
2074
+ const merged = mergeRevision(f.proposal, rev, { chat, served: ctx.served, roster: ctx.roster });
2075
+ if (edits.seats !== undefined) {
2076
+ const sr = f.proposal.shape === undefined ? null : resolveOption(f.proposal.shape.card, f.proposal.shape.option, ctx.served);
2077
+ if (sr?.workflow !== null && sr?.workflow !== undefined && SELF_SEATED.has(sr.workflow))
2078
+ throw new EditRefusal(`${f.proposal.what.title} picks its own seat`);
2079
+ const can = new Set(ctx.roster.map((s) => s.key));
2080
+ if (edits.seats.length === 0 || edits.seats.some((k) => !can.has(k)))
2081
+ throw new EditRefusal('pick seats that can work now');
2082
+ merged.facts.seats = [...new Set(edits.seats)];
2083
+ merged.facts.lead = edits.seats[0];
2084
+ }
2085
+ if (merged.notes.length > 0)
2086
+ throw new EditRefusal(merged.notes[0]);
2087
+ if (merged.lost.length > 0 || merged.lostSeats.length > 0) {
2088
+ throw new EditRefusal(`that would drop ${[...merged.lost.map((g) => checksLabel([g])), ...merged.lostSeats.map((k) => SEAT_WORDS[k])].join(', ')}; ask for it in the chat`);
2089
+ }
2090
+ const out = keepReshape(await this.proposalOf(chatId, f.proposal.pid, merged.facts, ctx, this.deps.records(chatId), merged.facts.card === f.proposal.shape?.card), f.proposal);
2091
+ if (out.kind !== 'job')
2092
+ throw new EditRefusal('that option makes a document: pick it in the chat');
2093
+ const dropped = (f.proposal.gate ?? []).filter((g) => !(out.gate ?? []).includes(g));
2094
+ if (dropped.length > 0)
2095
+ throw new EditRefusal(`that would drop ${checksLabel(dropped)}; check the job again`);
2096
+ if (out.seats !== undefined && out.shape !== undefined) {
2097
+ const r = resolveOption(out.shape.card, out.shape.option, ctx.served);
2098
+ if (r !== null && !(r.workflow !== null && SELF_SEATED.has(r.workflow)) && out.seats.keys.length < 1 + (r.resolved.seats.distinctEvaluator ? 1 : 0) + (r.resolved.seats.distinctJudge ? 1 : 0)) {
2099
+ throw new EditRefusal('this job needs another seat to check the one that builds');
2100
+ }
2101
+ }
2102
+ return out;
2103
+ }
2104
+ /**
2105
+ * Go on a job (§4.6): the frozen catalog revision and resolution are compared with the current catalog first; a
2106
+ * mismatch records the refreshed proposal (superseding this one) and answers 409 `catalog_changed`.
2107
+ */
2108
+ async jobStale(chatId, f0, instance) {
2109
+ // Re-read under the chat's lock: a revision that won the lock first made this one stale (codex r1).
2110
+ const f = foldProposals(this.deps.records(chatId)).get(f0.proposal.pid);
2111
+ if (f === undefined || f.state !== f0.state) {
2112
+ return { code: 409, body: { code: 'proposal_stale', error: 'this proposal changed while it was being started; check it again', ...(f !== undefined ? { view: viewOf(f) } : {}) } };
2113
+ }
2114
+ const p = f.state === 'accepting' && f.accepting !== undefined ? f.accepting.resolution : f.proposal;
2115
+ if (p.shape === undefined)
2116
+ return null;
2117
+ // A chat that has ended is re-checked from the proposal's own facts (codex r2): the check never depends on it being open.
2118
+ const chat = this.jobChat(chatId) ?? {
2119
+ projectId: p.filedIn.projectId,
2120
+ repos: (p.repoRefs ?? []).map((id, i) => ({ id, name: p.repos[i] ?? id })),
2121
+ lead: p.seats?.lead ?? null,
2122
+ seats: p.seats?.keys ?? [],
2123
+ };
2124
+ const pid = `${p.pid}:c:${this.now().toString(36)}`;
2125
+ let ctx;
2126
+ try {
2127
+ ctx = await this.jobContext(chatId, pid, p.turnId, p.seat, chat, { revises: p.pid, lineage: p.lineage ?? p.pid, notes: ['The catalog changed since this was proposed: check it again before starting.'] });
2128
+ }
2129
+ catch (err) {
2130
+ const refused = this.refusalOf(err);
2131
+ if (refused !== null)
2132
+ return refused;
2133
+ throw err;
2134
+ }
2135
+ const card = CATALOG_V2_CARDS.find((c) => c.id === p.shape.card);
2136
+ const r = card === undefined ? null : resolveOption(card.id, optionFor(card, p.shape.option), ctx.served);
2137
+ if (r !== null && ctx.served.rev === p.catalogRev && r.resolved.resolution === p.resolution)
2138
+ return null;
2139
+ let fresh;
2140
+ try {
2141
+ fresh = keepReshape(await this.proposalOf(chatId, pid, factsOf(p), ctx, this.deps.records(chatId), true), p);
2142
+ }
2143
+ catch (err) {
2144
+ const refused = this.refusalOf(err);
2145
+ if (refused !== null)
2146
+ return { code: 409, body: { code: 'catalog_changed', error: `the catalog changed since this was proposed: ${String(refused.body['error'])}`, view: viewOf(f) } };
2147
+ throw err;
2148
+ }
2149
+ // A refresh that would carry fewer checks (or seat protections) than the proposal on screen is not startable until
2150
+ // the person presses the question naming what changed (codex r1).
2151
+ const lost = (p.gate ?? []).filter((g) => !(fresh.gate ?? []).includes(g));
2152
+ const lostSeats = (p.seatRules ?? []).filter((k) => !(fresh.seatRules ?? []).includes(k));
2153
+ if ((lost.length > 0 || lostSeats.length > 0) && fresh.kind === 'job') {
2154
+ const words = [...lost.map((g) => checksLabel([g])), ...lostSeats.map((k) => SEAT_WORDS[k])].join(', ');
2155
+ const text = `The catalog changed: this job would no longer have ${words}. Start it like that?`;
2156
+ // The baseline stays the proposal the person saw, so an unrelated revision cannot clear the question (codex r2).
2157
+ fresh = { ...fresh, gate: [...new Set([...(fresh.gate ?? []), ...lost])], seatRules: [...new Set([...(fresh.seatRules ?? []), ...lostSeats])], question: { kind: 'lost_check', text, choices: [{ label: 'Accept the change', edit: { confirmLoss: true } }], lost, ...(lostSeats.length > 0 ? { lostSeats } : {}) }, suggestions: [], blocked: text, ...(fresh.sentence !== undefined ? { sentence: { ...fresh.sentence, ask: text } } : {}) };
2158
+ }
2159
+ if (!this.write(chatId, { at: this.now(), turnId: f.turnId, kind: 'proposal', proposal: fresh }, instance))
2160
+ return this.gone(chatId);
2161
+ const after = foldProposals(this.deps.records(chatId)).get(pid);
2162
+ return { code: 409, body: { code: 'catalog_changed', error: 'the catalog changed since this was proposed; check the job again and press Start', ...(after !== undefined ? { view: viewOf(after) } : {}) } };
2163
+ }
2164
+ /**
2165
+ * `POST /runs/:id/reshape` (§2.5) after the route's checks (a person, the chat is theirs, the run is held at its first
2166
+ * work-plan approval): under the chat's lock, so another proposal's Start waits for it — the crew-made reshape
2167
+ * proposal `<chatId>:reshape:<run>:<requestId>` is written (or found: a repeated request is idempotent), validated
2168
+ * against the held job's checks, then Go's one reshape transition (preflight, the held plan answered Reject through
2169
+ * `deps.reshapeReject`, `heldRejected` recorded, the launch). A failed launch after the Reject leaves it accepting:
2170
+ * the same request, or Go on it, tries again.
2171
+ */
2172
+ reshape(chatId, x, actor, instance) {
2173
+ return this.lock.run(`pid\u0000${x.pid}`, () => this.lock.run(`chat\u0000${instance ?? chatId}`, async () => {
2174
+ if (this.deps.instanceOf(chatId) !== instance)
2175
+ return this.gone(chatId);
2176
+ if (!this.jobsOn())
2177
+ return { code: 409, body: { code: 'operation_unavailable', error: 'this daemon does not start jobs from a chat' } };
2178
+ let folded = foldProposals(this.deps.records(chatId)).get(x.pid);
2179
+ if (folded !== undefined && folded.proposal.request?.digest !== x.request.digest) {
2180
+ return { code: 409, body: { code: 'request_reused', error: 'this requestId already started the run again as something else', view: viewOf(folded) } };
2181
+ }
2182
+ if (folded?.state === 'decided') {
2183
+ return folded.decision === 'go' ? { code: 200, body: { view: viewOf(folded) } } : { code: 409, body: { code: 'proposal_decided', error: 'this reshape was answered Not now', view: viewOf(folded) } };
2184
+ }
2185
+ if (folded === undefined) {
2186
+ const chat = this.jobChat(chatId);
2187
+ if (chat === null)
2188
+ return { code: 409, body: { code: 'chat_gone', error: `chat ${chatId} has ended; start a new one` } };
2189
+ const parent = x.parentPid === null ? undefined : foldProposals(this.deps.records(chatId)).get(x.parentPid);
2190
+ let proposal;
2191
+ try {
2192
+ const ctx = await this.jobContext(chatId, x.pid, null, 'person', chat, {
2193
+ revises: x.parentPid,
2194
+ lineage: parent?.proposal.lineage ?? x.parentPid ?? x.pid,
2195
+ notes: x.reducedAssurance ? ['Reduced assurance, as the held run had it.'] : [],
2196
+ request: x.request,
2197
+ });
2198
+ // The held job's proposal, merged by the revision rules (its inputs validated against the new card, what
2199
+ // the new card does not take dropped with a note; codex r2). A QE skip is never carried.
2200
+ const heldP = parent?.accepting?.resolution ?? parent?.proposal;
2201
+ let facts = x.facts;
2202
+ if (heldP?.shape !== undefined) {
2203
+ const merged = mergeRevision(heldP, x.edits, { chat, served: ctx.served, roster: ctx.roster });
2204
+ // Nothing is answered for a shape, or an input, that is not the one asked for (codex r3, r4).
2205
+ const wantCard = CATALOG_V2_CARDS.find((c) => c.id === (x.edits.card ?? merged.facts.card));
2206
+ const norm = (o) => (wantCard === undefined ? null : o === null || o === undefined ? (wantCard.variant?.default ?? null) : o);
2207
+ const optionOk = wantCard !== undefined && (x.edits.option === undefined || norm(merged.facts.option) === norm(x.edits.option));
2208
+ const depthOk = x.edits.depth === undefined || x.edits.depth === null || merged.facts.depth === x.edits.depth;
2209
+ const inputsOk = Object.entries(x.edits.inputs ?? {}).every(([k, v]) => (k === 'intent' ? merged.facts.words === (v.kind === 'text' ? v.value.slice(0, 8000) : '') : JSON.stringify(merged.facts.inputs[k]) === JSON.stringify(v)));
2210
+ if (wantCard === undefined || merged.facts.card !== wantCard.id || !optionOk || !depthOk || !inputsOk) {
2211
+ return { code: 400, body: { code: 'edits_invalid', error: merged.notes[0] ?? `there is no ${String(x.edits.card)}${x.edits.option !== undefined && x.edits.option !== null ? ` · ${String(x.edits.option)}` : ''} to start it again as`, notes: merged.notes } };
2212
+ }
2213
+ facts = { ...merged.facts, skipQe: null, by: 'person', source: 'reshape' };
2214
+ ctx.notes.push(...merged.notes);
2215
+ }
2216
+ proposal = await this.proposalOf(chatId, x.pid, facts, ctx, this.deps.records(chatId));
2217
+ }
2218
+ catch (err) {
2219
+ const refused = this.refusalOf(err);
2220
+ if (refused !== null)
2221
+ return refused;
2222
+ throw err;
2223
+ }
2224
+ if (proposal.kind !== 'job')
2225
+ return { code: 400, body: { code: 'shape_mismatch', error: 'a held run starts again as another job, not a document' } };
2226
+ // The held job's checks and seat protections are the parent's; a replacement with fewer is started only on the
2227
+ // person's press naming them (§2.5: the reshape question names the checks given up; codex r1).
2228
+ const held = parent?.accepting?.resolution ?? parent?.proposal;
2229
+ if (held !== undefined) {
2230
+ const lost = (held.gate ?? []).filter((g) => !(proposal.gate ?? []).includes(g));
2231
+ const heldCard = held.shape === undefined ? null : CATALOG_V2_CARDS.find((c) => c.id === held.shape.card) ?? null;
2232
+ const before = held.seatRules ?? (heldCard === null ? [] : seatProtections(resolveOption(heldCard.id, optionFor(heldCard, held.shape.option), (await this.deps.served(chat.projectId)))));
2233
+ const after = proposal.seatRules ?? [];
2234
+ const lostSeats = before.filter((k) => !after.includes(k));
2235
+ // Confirmed only for exactly what the person was shown (a loss since asks again; codex r4).
2236
+ if ([...lost, ...lostSeats].some((k) => !x.confirmLoss.includes(k))) {
2237
+ const words = [...lost.map((g) => checksLabel([g])), ...lostSeats.map((k) => SEAT_WORDS[k])];
2238
+ return { code: 409, body: { code: 'reshape_loses_check', error: `started again like that, it would no longer have ${words.join(', ')}: confirm to give ${words.length === 1 ? 'it' : 'them'} up`, lost, lostSeats } };
2239
+ }
2240
+ }
2241
+ proposal = { ...proposal, reshapes: x.oldRunId, relaunch: x.relaunch, ...(x.reducedAssurance ? { reducedAssurance: true } : {}) };
2242
+ if (!this.write(chatId, { at: this.now(), turnId: `reshape:${x.oldRunId}`, kind: 'proposal', proposal }, instance))
2243
+ return this.gone(chatId);
2244
+ folded = foldProposals(this.deps.records(chatId)).get(x.pid);
2245
+ }
2246
+ const p = folded.state === 'accepting' && folded.accepting !== undefined ? folded.accepting.resolution : folded.proposal;
2247
+ if (folded.state === 'accepting' && folded.accepting !== undefined) {
2248
+ // A retry after the replacement launched (a lost response, a crash before the decision): adopt it (codex r1).
2249
+ const found = await this.deps.registry.find('job', folded.accepting.identity);
2250
+ if (found !== null) {
2251
+ const result = { runId: folded.accepting.identity.runId, artifactRef: null, adopted: true, stub: found.stub };
2252
+ if (!this.decided(chatId, folded.turnId, x.pid, actor, 'go', result, folded.accepting.resolution, folded.accepting.edits, instance))
2253
+ return this.gone(chatId);
2254
+ return { code: 200, body: { view: viewOf(foldProposals(this.deps.records(chatId)).get(x.pid)) } };
2255
+ }
2256
+ }
2257
+ // Only the open (or interrupted) newest proposal of its lineage goes on: checked before any Reject (codex r3).
2258
+ if (folded.state === 'superseded' || folded.state === 'revising') {
2259
+ return { code: 409, body: { code: folded.state === 'revising' ? 'proposal_revising' : 'proposal_superseded', error: 'this reshape changed since; check it again', view: viewOf(folded) } };
2260
+ }
2261
+ const newest = [...foldProposals(this.deps.records(chatId)).values()].filter((f) => f.proposal.lineage === p.lineage).pop();
2262
+ if (newest !== undefined && newest.proposal.pid !== x.pid) {
2263
+ return { code: 409, body: { code: 'proposal_superseded', error: 'a newer version of this job replaced this reshape', view: viewOf(newest) } };
2264
+ }
2265
+ // A retry is checked against the catalog like any Go, interrupted ones included (codex r2, r3).
2266
+ const stale = await this.jobStale(chatId, folded, instance);
2267
+ if (stale !== null)
2268
+ return stale;
2269
+ if (folded.state !== 'accepting') {
2270
+ if (p.blocked !== null)
2271
+ return { code: 409, body: { code: 'proposal_blocked', error: p.blocked, view: viewOf(folded) } };
2272
+ }
2273
+ const current = folded.state === 'accepting' && folded.accepting !== undefined ? folded.accepting.resolution : folded.proposal;
2274
+ const identity = folded.accepting?.identity ?? this.identityOf(current);
2275
+ return this.goLocked(chatId, folded, current, null, identity, actor, instance);
2276
+ }));
2277
+ }
2278
+ /** A proposal of this chat, folded, or `null`. */
2279
+ viewOfPid(chatId, pid) {
2280
+ const f = foldProposals(this.deps.records(chatId)).get(pid);
2281
+ return f === undefined ? null : viewOf(f);
2282
+ }
2283
+ /** The proposal as it was accepted (its effective resolution), else as it stands; `null` when the chat has none. */
2284
+ proposalOfPid(chatId, pid) {
2285
+ const f = foldProposals(this.deps.records(chatId)).get(pid);
2286
+ return f === undefined ? null : (f.accepting?.resolution ?? f.proposal);
2287
+ }
1468
2288
  // ── A3: what the create launcher and the daemon need from the proposals ────────────────────────────────────────────
1469
2289
  /**
1470
2290
  * The accepted proposal a create's `chat_id` + `proposal_id` names, for this actor (§5.2): accepting (or decided go),