code60-transmission-server 0.1.0-staging.19 → 0.1.0-staging.20

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.
package/README.md CHANGED
@@ -48,14 +48,20 @@ The initial worktree, including existing staged, unstaged and nonignored untrack
48
48
  | Status | What the caller receives |
49
49
  | --- | --- |
50
50
  | running | Current task and role |
51
+ | pausing | Current task while active agents are stopping |
52
+ | paused | Preserved progress, waiting for an explicit resume |
51
53
  | needs_input | A decision with a question ID and, for a permission request, the choices offered by the harness |
52
54
  | completed | The result, verifier verdict, and ordered accepted task records |
53
55
  | failed | The reason and attempt history |
54
56
  | cancelled | Confirmation and the accepted tasks so far |
55
57
 
56
- The MCP tools include status, paginated events, the paginated accepted diff, answering questions, steering and cancellation. `autoApprove` defaults to true and selects a one-time allowance when the harness offers one. Set it to false to receive those decisions yourself. Requirements and scope questions always go to the caller. The harness enforces its effective permissions.
58
+ The MCP tools include status, paginated events, the paginated accepted diff, answering questions, steering, pause, resume and cancellation. `autoApprove` defaults to true and selects a one-time allowance when the harness offers one. Set it to false to receive those decisions yourself. Requirements and scope questions always go to the caller. The harness enforces its effective permissions.
57
59
 
58
- The engine stays up when the MCP client disconnects. Approved tasks, questions, verdicts, and attempts are stored in SQLite. On restart, the engine continues with the first unfinished task and retains partial working-tree changes. Restarting the engine preserves the task’s retry allowance. A lost harness consumes a fresh-session retry. Completed tasks stay accepted. Cancellation leaves the files available for review.
60
+ Call `pause_workflow` with `{"runId":"<workflow ID>"}` to interrupt the active worker or verifier immediately. The workflow enters `pausing` before agent shutdown and returns `paused` once its agents and execution loop have stopped. Working files, HEAD, staging, accepted tasks, guidance and spent allowances are preserved. A paused workflow still reserves its checkout. Repeating pause returns the current pause outcome; cancellation can supersede an in-flight pause.
61
+
62
+ Call `resume_workflow` with the same run ID to continue. The first unfinished task starts with fresh worker and verifier sessions, including when verification was interrupted. Pause does not spend a fresh-session retry or replenish repair/retry allowances. The new worker is instructed to inspect partial work before repeating consequential actions. Unanswered scope questions survive pause and still require an answer; an answer given while paused is saved without starting work. Permission questions for stopped sessions are withdrawn and must be requested again by the fresh harness. Resume during `pausing` is rejected. Repeated resume after continuation returns the current snapshot; ended workflows reject pause and resume.
63
+
64
+ The engine stays up when the MCP client disconnects. Approved tasks, questions, verdicts, and attempts are stored in SQLite. On restart, the engine continues with the first unfinished task and retains partial working-tree changes. Explicitly paused workflows stay paused until `resume_workflow`; a restart during `pausing` also leaves the workflow paused. Restarting the engine preserves the task’s retry allowance. A lost harness consumes a fresh-session retry. Completed tasks stay accepted. Cancellation leaves the files available for review.
59
65
 
60
66
  A client can render the ordered tasks by calling `get_workflow` with only the run ID. For example, during verification the response can look like this:
61
67
 
@@ -76,7 +82,7 @@ A client can render the ordered tasks by calling `get_workflow` with only the ru
76
82
  }
77
83
  ```
78
84
 
79
- Each task keeps its zero-based index even when names repeat. The active row can be `implementing`, `verifying`, `repairing`, or `needs_input`. A terminal run has a null active index. Previously accepted rows stay `accepted`, the interrupted row records `failed` or `cancelled`, and unstarted rows stay `pending`.
85
+ Each task keeps its zero-based index even when names repeat. The active row can be `implementing`, `verifying`, `repairing`, `needs_input`, `pausing`, or `paused`. Pausing and paused runs retain their active index. A terminal run has a null active index. Previously accepted rows stay `accepted`, the interrupted row records `failed` or `cancelled`, and unstarted rows stay `pending`.
80
86
 
81
87
  For subsequent activity, call `get_workflow_events` with the same run ID and `after` set to the snapshot’s `eventCursor`. Use the last returned sequence for the next page. Sequence numbers can have gaps between events for a run. Use `after: 0` for earlier history, or refresh `get_workflow` for another complete snapshot.
82
88
 
@@ -28,6 +28,8 @@ export const operations = {
28
28
  }),
29
29
  answer_workflow_question: id.extend({ questionId: z.uuid(), answer: text }),
30
30
  send_workflow_message: id.extend({ message: text }),
31
+ pause_workflow: id,
32
+ resume_workflow: id,
31
33
  cancel_workflow: id,
32
34
  };
33
35
  export const descriptions = {
@@ -37,10 +39,12 @@ export const descriptions = {
37
39
  get_workflow_diff: 'Read a page of the accepted patch relative to the initial working tree. Offset is in bytes; content is base64.',
38
40
  answer_workflow_question: 'Answer the outstanding decision by ID. For a permission question select an offered option ID.',
39
41
  send_workflow_message: 'Deliver new guidance before the current task is accepted.',
42
+ pause_workflow: 'Interrupt active agents and pause the workflow, preserving files and accepted tasks. Returns paused after agents stop. Pause survives engine restart.',
43
+ resume_workflow: 'Resume a paused workflow with fresh sessions for the first unfinished task without spending a retry. An unanswered scope question still requires an answer.',
40
44
  cancel_workflow: 'Stop the workflow and its active agent sessions. Leave working files available for review.',
41
45
  };
42
46
  export const terminal = (status) => ['completed', 'failed', 'cancelled'].includes(status);
43
- const status = z.enum(['running', 'completed', 'needs_input', 'failed', 'cancelled']);
47
+ const status = z.enum(['running', 'pausing', 'paused', 'completed', 'needs_input', 'failed', 'cancelled']);
44
48
  const checkEvidence = z.object({
45
49
  command: text,
46
50
  passed: z.boolean(),
@@ -67,6 +71,7 @@ const question = z.object({
67
71
  const taskState = z.enum([
68
72
  'pending', 'implementing', 'verifying', 'repairing',
69
73
  'needs_input', 'accepted', 'failed', 'cancelled',
74
+ 'pausing', 'paused',
70
75
  ]);
71
76
  const nonnegativeInteger = z.int().nonnegative();
72
77
  export const workflowSnapshot = z.object({
@@ -86,7 +91,7 @@ export const workflowSnapshot = z.object({
86
91
  });
87
92
  export const snapshotOperations = new Set([
88
93
  'start_workflow', 'get_workflow', 'answer_workflow_question',
89
- 'send_workflow_message', 'cancel_workflow',
94
+ 'send_workflow_message', 'pause_workflow', 'resume_workflow', 'cancel_workflow',
90
95
  ]);
91
96
  export const workerReply = z.discriminatedUnion('kind', [
92
97
  z.object({ kind: z.literal('result'), summary: text }),
@@ -30,6 +30,8 @@ export class Engine {
30
30
  pumps = new Map();
31
31
  agents = new Map();
32
32
  pending = new Map();
33
+ disposals = new Map();
34
+ pauses = new Map();
33
35
  closing = false;
34
36
  settling = new Set();
35
37
  constructor(state, factory = (hooks, cwd) => new AcpHarness(hooks, cwd)) {
@@ -46,6 +48,15 @@ export class Engine {
46
48
  this.runs.set(r.id, r);
47
49
  if (terminal(r.status))
48
50
  continue;
51
+ if (r.status === 'pausing' || r.status === 'paused') {
52
+ this.withdrawPermission(r);
53
+ this.retireSessions(r);
54
+ const interrupted = r.status === 'pausing';
55
+ r.status = 'paused';
56
+ if (interrupted)
57
+ this.save(r, 'paused');
58
+ continue;
59
+ }
49
60
  if (r.worker || r.verifier) {
50
61
  this.retireSessions(r);
51
62
  r.feedback +=
@@ -185,15 +196,17 @@ export class Engine {
185
196
  const r = this.get(id);
186
197
  if (r.lastAnswer?.id === questionId && r.lastAnswer.answer === answer)
187
198
  return this.status(id);
188
- if (r.status !== 'needs_input' || r.question?.id !== questionId)
199
+ if (!['needs_input', 'pausing', 'paused'].includes(r.status) || r.question?.id !== questionId)
189
200
  throw new Error('This decision is no longer pending.');
190
201
  if (r.question.options &&
191
202
  !r.question.options.some((opt) => opt.id === answer))
192
203
  throw new Error('Select one of the offered option IDs.');
193
204
  const q = r.question, p = this.pending.get(id);
194
205
  delete r.question;
206
+ delete r.questionKind;
195
207
  r.lastAnswer = { id: questionId, answer };
196
- r.status = 'running';
208
+ if (r.status === 'needs_input')
209
+ r.status = 'running';
197
210
  if (!p || p.id !== q.id)
198
211
  r.guidance.push('Decision: ' + q.text + '\nUser answer: ' + answer);
199
212
  this.save(r, 'answered', { question: q, answer });
@@ -211,13 +224,72 @@ export class Engine {
211
224
  this.save(r, 'message', { message });
212
225
  return this.status(id);
213
226
  }
227
+ pause(id) {
228
+ const r = this.get(id);
229
+ if (this.closing)
230
+ throw new Error('Engine is stopping.');
231
+ if (terminal(r.status))
232
+ throw new Error('Workflow has ended.');
233
+ const prior = this.pauses.get(id);
234
+ if (prior)
235
+ return prior;
236
+ if (r.status === 'paused')
237
+ return Promise.resolve(this.status(id));
238
+ if (r.status !== 'pausing') {
239
+ r.status = 'pausing';
240
+ this.withdrawPermission(r);
241
+ this.save(r, 'pause_requested');
242
+ }
243
+ // Install the shared operation before shutdown can settle a prompt or a
244
+ // concurrent pause/cancel can join the same physical-exit barrier.
245
+ const work = Promise.resolve().then(async () => {
246
+ await this.dispose(r);
247
+ await this.pumps.get(id);
248
+ if (r.status === 'pausing') {
249
+ this.retireSessions(r);
250
+ r.status = 'paused';
251
+ this.save(r, 'paused');
252
+ }
253
+ return this.status(id);
254
+ }).finally(() => this.pauses.delete(id));
255
+ this.pauses.set(id, work);
256
+ return work;
257
+ }
258
+ resume(id) {
259
+ const r = this.get(id);
260
+ if (this.closing)
261
+ throw new Error('Engine is stopping.');
262
+ if (terminal(r.status))
263
+ throw new Error('Workflow has ended.');
264
+ if (r.status === 'pausing')
265
+ throw new Error('Workflow is still pausing.');
266
+ if (r.status !== 'paused')
267
+ return this.status(id);
268
+ this.retireSessions(r);
269
+ r.feedback += '\nWorkflow resumed after an operator pause. Inspect existing work and the outcome of consequential actions before repeating them. Ask if their outcome cannot be determined.';
270
+ r.status = r.question ? 'needs_input' : 'running';
271
+ this.save(r, 'resumed');
272
+ this.wake(r);
273
+ return this.status(id);
274
+ }
275
+ withdrawPermission(r) {
276
+ // Older records did not store question origin. Only permissions have
277
+ // offered options; scope questions must survive the loss of a session.
278
+ if (r.questionKind === 'permission' || r.question?.options) {
279
+ delete r.question;
280
+ delete r.questionKind;
281
+ }
282
+ }
214
283
  async cancel(id) {
215
284
  const r = this.get(id);
216
285
  if (!terminal(r.status)) {
217
- this.settling.add(id);
218
286
  r.status = 'cancelled';
219
287
  delete r.question;
288
+ delete r.questionKind;
220
289
  this.save(r, 'cancelled');
290
+ }
291
+ if (r.status === 'cancelled') {
292
+ this.settling.add(id);
221
293
  try {
222
294
  await this.dispose(r);
223
295
  await this.pumps.get(id);
@@ -228,17 +300,31 @@ export class Engine {
228
300
  }
229
301
  return this.status(id);
230
302
  }
231
- async dispose(r) {
303
+ dispose(r) {
304
+ const prior = this.disposals.get(r.id);
305
+ if (prior)
306
+ return prior;
232
307
  this.pending.get(r.id)?.resolve(undefined);
233
308
  this.pending.delete(r.id);
234
309
  const agent = this.agents.get(r.id);
235
310
  this.agents.delete(r.id);
236
- await agent?.close();
311
+ const work = Promise.resolve().then(() => agent?.close())
312
+ .catch(error => {
313
+ // A rejected shutdown is not proof of exit. Keep the same agent for
314
+ // another shutdown attempt instead of later declaring it paused.
315
+ if (agent)
316
+ this.agents.set(r.id, agent);
317
+ throw error;
318
+ })
319
+ .finally(() => this.disposals.delete(r.id));
320
+ this.disposals.set(r.id, work);
321
+ return work;
237
322
  }
238
323
  async close() {
239
324
  this.closing = true;
240
325
  await Promise.all([...this.runs.values()].map((r) => this.dispose(r)));
241
326
  await Promise.all(this.pumps.values());
327
+ await Promise.all(this.pauses.values());
242
328
  this.db.close();
243
329
  }
244
330
  wake(r) {
@@ -263,16 +349,16 @@ export class Engine {
263
349
  r.attempts.push(reason);
264
350
  this.retireSessions(r);
265
351
  r.repairsUsed = 0;
352
+ delete r.question;
353
+ delete r.questionKind;
266
354
  if (r.generation >= r.plan.retries) {
267
355
  r.failure = reason + ' Fresh-session retry limit reached.';
268
356
  r.status = 'failed';
269
- delete r.question;
270
357
  }
271
358
  else {
272
359
  r.generation++;
273
360
  r.feedback = reason + ' Inspect existing work before continuing.';
274
361
  r.status = 'running';
275
- delete r.question;
276
362
  }
277
363
  this.save(r, 'attempt_ended', {
278
364
  reason,
@@ -280,8 +366,9 @@ export class Engine {
280
366
  retriesUsed: r.generation,
281
367
  });
282
368
  }
283
- ask(r, question) {
369
+ ask(r, question, kind = 'scope') {
284
370
  r.question = question;
371
+ r.questionKind = kind;
285
372
  r.status = 'needs_input';
286
373
  this.save(r, 'needs_input', question);
287
374
  }
@@ -290,9 +377,12 @@ export class Engine {
290
377
  if (agent)
291
378
  return agent;
292
379
  agent = this.factory({
293
- tool: (session, detail) => this.event(r, 'tool', { session, detail }),
380
+ tool: (session, detail) => {
381
+ if (this.agents.get(r.id) === agent)
382
+ this.event(r, 'tool', { session, detail });
383
+ },
294
384
  permission: async (request) => {
295
- if (r.status !== 'running' || this.closing)
385
+ if (r.status !== 'running' || this.closing || this.agents.get(r.id) !== agent)
296
386
  return undefined;
297
387
  const once = request.options.find((o) => o.kind === 'allow_once');
298
388
  if (r.plan.autoApprove && once) {
@@ -310,7 +400,7 @@ export class Engine {
310
400
  name: o.name,
311
401
  })),
312
402
  };
313
- this.ask(r, question);
403
+ this.ask(r, question, 'permission');
314
404
  return new Promise((resolve) => this.pending.set(r.id, { id: question.id, resolve }));
315
405
  },
316
406
  }, r.plan.repository);
@@ -358,7 +448,7 @@ export class Engine {
358
448
  const raw = await harness.prompt(session, instructions +
359
449
  ' Only for a genuine decision about intent or scope, end with {"kind":"question","question":"decision needed"}.\n' +
360
450
  JSON.stringify(data));
361
- if (this.closing || terminal(r.status))
451
+ if (this.closing || r.status !== 'running')
362
452
  return;
363
453
  // Retain messages until a turn consumes them successfully.
364
454
  r.messages.splice(0, messages.length);
@@ -484,7 +574,7 @@ export class Engine {
484
574
  }
485
575
  }
486
576
  catch (error) {
487
- if (this.closing || terminal(r.status))
577
+ if (this.closing || terminal(r.status) || r.status === 'pausing' || r.status === 'paused')
488
578
  return;
489
579
  this.restart(r, diagnostic(error));
490
580
  await this.dispose(r);
@@ -57,6 +57,10 @@ export async function dispatch(engine, op, args) {
57
57
  }
58
58
  case 'cancel_workflow':
59
59
  return engine.cancel(operations.cancel_workflow.parse(args).runId);
60
+ case 'pause_workflow':
61
+ return engine.pause(operations.pause_workflow.parse(args).runId);
62
+ case 'resume_workflow':
63
+ return engine.resume(operations.resume_workflow.parse(args).runId);
60
64
  default:
61
65
  throw new Error('Unknown operation.');
62
66
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "code60-transmission-server",
3
- "version": "0.1.0-staging.19",
3
+ "version": "0.1.0-staging.20",
4
4
  "description": "Run user-approved workflows with independent coding agents over ACP.",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -395,6 +395,108 @@
395
395
  }
396
396
  }
397
397
  },
398
+ "/pause_workflow": {
399
+ "post": {
400
+ "operationId": "pause_workflow",
401
+ "description": "Interrupt active agents and pause the workflow, preserving files and accepted tasks. Returns paused after agents stop. Pause survives engine restart.",
402
+ "security": [
403
+ {
404
+ "localToken": []
405
+ }
406
+ ],
407
+ "requestBody": {
408
+ "required": true,
409
+ "content": {
410
+ "application/json": {
411
+ "schema": {
412
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
413
+ "type": "object",
414
+ "properties": {
415
+ "runId": {
416
+ "type": "string",
417
+ "format": "uuid",
418
+ "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
419
+ }
420
+ },
421
+ "required": [
422
+ "runId"
423
+ ],
424
+ "additionalProperties": false
425
+ }
426
+ }
427
+ }
428
+ },
429
+ "responses": {
430
+ "200": {
431
+ "description": "Workflow snapshot",
432
+ "content": {
433
+ "application/json": {
434
+ "schema": {
435
+ "$ref": "#/components/schemas/WorkflowSnapshot"
436
+ }
437
+ }
438
+ }
439
+ },
440
+ "400": {
441
+ "description": "Invalid input or workflow state"
442
+ },
443
+ "403": {
444
+ "description": "Invalid engine token"
445
+ }
446
+ }
447
+ }
448
+ },
449
+ "/resume_workflow": {
450
+ "post": {
451
+ "operationId": "resume_workflow",
452
+ "description": "Resume a paused workflow with fresh sessions for the first unfinished task without spending a retry. An unanswered scope question still requires an answer.",
453
+ "security": [
454
+ {
455
+ "localToken": []
456
+ }
457
+ ],
458
+ "requestBody": {
459
+ "required": true,
460
+ "content": {
461
+ "application/json": {
462
+ "schema": {
463
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
464
+ "type": "object",
465
+ "properties": {
466
+ "runId": {
467
+ "type": "string",
468
+ "format": "uuid",
469
+ "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
470
+ }
471
+ },
472
+ "required": [
473
+ "runId"
474
+ ],
475
+ "additionalProperties": false
476
+ }
477
+ }
478
+ }
479
+ },
480
+ "responses": {
481
+ "200": {
482
+ "description": "Workflow snapshot",
483
+ "content": {
484
+ "application/json": {
485
+ "schema": {
486
+ "$ref": "#/components/schemas/WorkflowSnapshot"
487
+ }
488
+ }
489
+ }
490
+ },
491
+ "400": {
492
+ "description": "Invalid input or workflow state"
493
+ },
494
+ "403": {
495
+ "description": "Invalid engine token"
496
+ }
497
+ }
498
+ }
499
+ },
398
500
  "/cancel_workflow": {
399
501
  "post": {
400
502
  "operationId": "cancel_workflow",
@@ -462,6 +564,8 @@
462
564
  "type": "string",
463
565
  "enum": [
464
566
  "running",
567
+ "pausing",
568
+ "paused",
465
569
  "completed",
466
570
  "needs_input",
467
571
  "failed",
@@ -491,7 +595,9 @@
491
595
  "needs_input",
492
596
  "accepted",
493
597
  "failed",
494
- "cancelled"
598
+ "cancelled",
599
+ "pausing",
600
+ "paused"
495
601
  ]
496
602
  }
497
603
  },