@edspencer/paddock 0.65.0 → 0.66.0

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 (87) hide show
  1. package/README.md +3 -3
  2. package/package.json +1 -1
  3. package/packages/server/dist/cli/args.d.ts +4 -4
  4. package/packages/server/dist/cli/args.js +5 -5
  5. package/packages/server/dist/cli/paddock.js +1 -1
  6. package/packages/server/dist/config.d.ts +7 -0
  7. package/packages/server/dist/config.js +9 -1
  8. package/packages/server/dist/herdctl.d.ts +89 -0
  9. package/packages/server/dist/herdctl.js +169 -2
  10. package/packages/server/dist/instance-config.js +12 -1
  11. package/packages/server/dist/projects.d.ts +11 -0
  12. package/packages/server/dist/projects.js +40 -2
  13. package/packages/server/dist/routes/chats.js +77 -6
  14. package/packages/server/dist/routes/projects.js +22 -2
  15. package/packages/server/dist/schema-version.d.ts +111 -0
  16. package/packages/server/dist/schema-version.js +142 -0
  17. package/packages/server/dist/subagents.d.ts +65 -0
  18. package/packages/server/dist/subagents.js +159 -19
  19. package/packages/server/dist/tooldetails.d.ts +10 -4
  20. package/packages/server/dist/tooldetails.js +23 -6
  21. package/packages/server/dist/trusted-proxy.js +1 -1
  22. package/packages/server/dist/turn-interlock.d.ts +101 -0
  23. package/packages/server/dist/turn-interlock.js +76 -0
  24. package/packages/server/package.json +1 -1
  25. package/packages/web/dist/assets/InstanceConfigPage-DBrwtZjx.js +2 -0
  26. package/packages/web/dist/assets/{MarkdownRenderer-Ri1LwAUN.js → MarkdownRenderer-Bn6VPBdL.js} +1 -1
  27. package/packages/web/dist/assets/{ProjectRedirect-Dze5H8Xy.js → ProjectRedirect-CQmDBtd-.js} +1 -1
  28. package/packages/web/dist/assets/ProjectView-BVKu9oIg.js +13 -0
  29. package/packages/web/dist/assets/{ProjectsGrid-BidsM7ah.js → ProjectsGrid-BW56zqke.js} +1 -1
  30. package/packages/web/dist/assets/{arc-eQ3ryE9c.js → arc-CGy6WkLl.js} +1 -1
  31. package/packages/web/dist/assets/{architectureDiagram-3BPJPVTR-Dc6Tj2Ai.js → architectureDiagram-3BPJPVTR-DJH1WIxY.js} +1 -1
  32. package/packages/web/dist/assets/{blockDiagram-GPEHLZMM-DBX5pma_.js → blockDiagram-GPEHLZMM-Cufb_pvX.js} +1 -1
  33. package/packages/web/dist/assets/{c4Diagram-AAUBKEIU-CnWrtTpa.js → c4Diagram-AAUBKEIU-glqeg1Ky.js} +1 -1
  34. package/packages/web/dist/assets/channel-C4kPYn_d.js +2 -0
  35. package/packages/web/dist/assets/{chunk-2J33WTMH-2qmLvtsr.js → chunk-2J33WTMH-SOFTHYgh.js} +1 -1
  36. package/packages/web/dist/assets/{chunk-4BX2VUAB-Dn-LUDMV.js → chunk-4BX2VUAB-DFxFAiG8.js} +1 -1
  37. package/packages/web/dist/assets/{chunk-55IACEB6-DB0augUY.js → chunk-55IACEB6-CEEDxZVG.js} +1 -1
  38. package/packages/web/dist/assets/{chunk-727SXJPM-BPQQM0i8.js → chunk-727SXJPM--3eiptsh.js} +1 -1
  39. package/packages/web/dist/assets/{chunk-AQP2D5EJ-DOhfwA-x.js → chunk-AQP2D5EJ-DIHIugCo.js} +1 -1
  40. package/packages/web/dist/assets/{chunk-FMBD7UC4-CatHHdFD.js → chunk-FMBD7UC4-BmxWZl5c.js} +1 -1
  41. package/packages/web/dist/assets/{chunk-ND2GUHAM-B645aAlG.js → chunk-ND2GUHAM-hMHtJs_I.js} +1 -1
  42. package/packages/web/dist/assets/{chunk-QZHKN3VN-D1fAaPSZ.js → chunk-QZHKN3VN-CRnnasyy.js} +1 -1
  43. package/packages/web/dist/assets/classDiagram-4FO5ZUOK-DCg6gTVh.js +2 -0
  44. package/packages/web/dist/assets/classDiagram-v2-Q7XG4LA2-DCg6gTVh.js +2 -0
  45. package/packages/web/dist/assets/{core-B4t7D8Om.js → core-CGW2CVAY.js} +1 -1
  46. package/packages/web/dist/assets/{cose-bilkent-S5V4N54A-BLdKDAwa.js → cose-bilkent-S5V4N54A-kcl9qSfK.js} +1 -1
  47. package/packages/web/dist/assets/{dagre-BM42HDAG-CbTbTVKv.js → dagre-BM42HDAG-BiLsFx1W.js} +1 -1
  48. package/packages/web/dist/assets/{diagram-2AECGRRQ-CorSS29_.js → diagram-2AECGRRQ-BcIpoY66.js} +1 -1
  49. package/packages/web/dist/assets/{diagram-5GNKFQAL-PLKivts0.js → diagram-5GNKFQAL-BK5p5kJa.js} +1 -1
  50. package/packages/web/dist/assets/{diagram-KO2AKTUF-CUSIBacZ.js → diagram-KO2AKTUF-BmJYalCP.js} +1 -1
  51. package/packages/web/dist/assets/{diagram-LMA3HP47-CZ69mAZs.js → diagram-LMA3HP47-BHs0SWEM.js} +1 -1
  52. package/packages/web/dist/assets/{diagram-OG6HWLK6-Cmf042Rh.js → diagram-OG6HWLK6-CSs8hie4.js} +1 -1
  53. package/packages/web/dist/assets/{erDiagram-TEJ5UH35-DyIKGj6e.js → erDiagram-TEJ5UH35-4qd_Td27.js} +1 -1
  54. package/packages/web/dist/assets/{flowDiagram-I6XJVG4X-B79pLdLD.js → flowDiagram-I6XJVG4X-CstUgr7V.js} +1 -1
  55. package/packages/web/dist/assets/{format-C5nhFL8q.js → format-B_kAvAW3.js} +1 -1
  56. package/packages/web/dist/assets/{ganttDiagram-6RSMTGT7-BFTR_oNA.js → ganttDiagram-6RSMTGT7-DTn9OuIc.js} +1 -1
  57. package/packages/web/dist/assets/{gitGraphDiagram-PVQCEYII-DdGUlJxS.js → gitGraphDiagram-PVQCEYII-E_bCor2O.js} +1 -1
  58. package/packages/web/dist/assets/{index-DVSsta3B.js → index-B-QAOq9a.js} +2 -2
  59. package/packages/web/dist/assets/index-B3K5nsLe.css +1 -0
  60. package/packages/web/dist/assets/{infoDiagram-5YYISTIA-B80FyUOy.js → infoDiagram-5YYISTIA-foRUrIOQ.js} +1 -1
  61. package/packages/web/dist/assets/{ishikawaDiagram-YF4QCWOH-_wRlphn9.js → ishikawaDiagram-YF4QCWOH-CTON8v5t.js} +1 -1
  62. package/packages/web/dist/assets/{journeyDiagram-JHISSGLW-qu4yvjW8.js → journeyDiagram-JHISSGLW-D-qwGjr7.js} +1 -1
  63. package/packages/web/dist/assets/{kanban-definition-UN3LZRKU-D2DEUp2-.js → kanban-definition-UN3LZRKU-5l4y83rE.js} +1 -1
  64. package/packages/web/dist/assets/{linear-D-CLRUEW.js → linear-B1GiUWpI.js} +1 -1
  65. package/packages/web/dist/assets/{mermaid.core-DdihBJl4.js → mermaid.core-btQIOU6d.js} +4 -4
  66. package/packages/web/dist/assets/{mindmap-definition-RKZ34NQL-BEh_TDBf.js → mindmap-definition-RKZ34NQL-DduczfMv.js} +1 -1
  67. package/packages/web/dist/assets/{pieDiagram-4H26LBE5-BbrmLVaZ.js → pieDiagram-4H26LBE5-D86uGusc.js} +1 -1
  68. package/packages/web/dist/assets/{quadrantDiagram-W4KKPZXB-DfVuygAv.js → quadrantDiagram-W4KKPZXB-Bo5EW3MZ.js} +1 -1
  69. package/packages/web/dist/assets/{requirementDiagram-4Y6WPE33-BHp2QpZt.js → requirementDiagram-4Y6WPE33-C9aZJK93.js} +1 -1
  70. package/packages/web/dist/assets/{sankeyDiagram-5OEKKPKP-D2G6lRMY.js → sankeyDiagram-5OEKKPKP-b__W6SAJ.js} +1 -1
  71. package/packages/web/dist/assets/{sequenceDiagram-3UESZ5HK-Dj-jzR-c.js → sequenceDiagram-3UESZ5HK-Lr4Df8kX.js} +1 -1
  72. package/packages/web/dist/assets/{stateDiagram-AJRCARHV-C5D6bT13.js → stateDiagram-AJRCARHV-R0XxGxD5.js} +1 -1
  73. package/packages/web/dist/assets/stateDiagram-v2-BHNVJYJU-i2pZN-iR.js +2 -0
  74. package/packages/web/dist/assets/{timeline-definition-PNZ67QCA-DE4gGjhP.js → timeline-definition-PNZ67QCA-D42Je9LW.js} +1 -1
  75. package/packages/web/dist/assets/{vennDiagram-CIIHVFJN-C9QNrl92.js → vennDiagram-CIIHVFJN-KCu14-QB.js} +1 -1
  76. package/packages/web/dist/assets/{wardley-L42UT6IY-U2fSGy-d.js → wardley-L42UT6IY-Cfir3V9o.js} +1 -1
  77. package/packages/web/dist/assets/{wardleyDiagram-YWT4CUSO-B9RhObdH.js → wardleyDiagram-YWT4CUSO-BkXjbTXu.js} +1 -1
  78. package/packages/web/dist/assets/{xychartDiagram-2RQKCTM6-BnlPrtQ9.js → xychartDiagram-2RQKCTM6-BVT60Pln.js} +1 -1
  79. package/packages/web/dist/index.html +2 -2
  80. package/packages/web/dist/sw.js +1 -1
  81. package/packages/web/dist/assets/InstanceConfigPage-DcprTH2W.js +0 -2
  82. package/packages/web/dist/assets/ProjectView-PrA8purE.js +0 -13
  83. package/packages/web/dist/assets/channel-B4sED4OP.js +0 -2
  84. package/packages/web/dist/assets/classDiagram-4FO5ZUOK-BlVeHFir.js +0 -2
  85. package/packages/web/dist/assets/classDiagram-v2-Q7XG4LA2-BlVeHFir.js +0 -2
  86. package/packages/web/dist/assets/index-B6etJCHf.css +0 -1
  87. package/packages/web/dist/assets/stateDiagram-v2-BHNVJYJU-C8NDOqTq.js +0 -2
@@ -24,6 +24,7 @@ import { childOf, HUMAN_ROOT, ADOPTED_ROOT } from "../run-provenance.js";
24
24
  import { sendProjectError } from "../route-errors.js";
25
25
  import { mapWithConcurrency, FILE_FANOUT_CONCURRENCY } from "../concurrency.js";
26
26
  import { CHAT_USAGE_SCOPES, SAFE_SESSION_ID, RUNS_SEEN_SESSION, clampRunsLimit, toChatUsage, buildProjectChats, makeTriggerResolver, makeParentResolver, normalizeBatchSessionIds, BATCH_SESSIONS_MAX, } from "../chat-dto.js";
27
+ import { quiesceSession, turnRunningError } from "../turn-interlock.js";
27
28
  /**
28
29
  * Workspace-scoped chat routes: paths are declared RELATIVE to the workspace
29
30
  * (e.g. `/chats/:sessionId`), and this plugin is mounted TWICE — once at
@@ -56,6 +57,17 @@ export function registerChatWorkspaceRoutes(app, ctx) {
56
57
  * feed then degrades to its unread half instead of 500ing.
57
58
  */
58
59
  const isRunning = (sessionId) => ctx.managementOpsContext?.hub.isRunning(sessionId) ?? false;
60
+ /**
61
+ * The interlock every DESTRUCTIVE chat route runs first (issue #731).
62
+ *
63
+ * `claude` writes the transcript itself, so unlinking or rewriting it while a
64
+ * turn is live does not remove the chat — the surviving process re-creates the
65
+ * file from its own tail and the chat comes back with its history gone. These
66
+ * routes therefore stop the turn and WAIT for it to be dead before touching a
67
+ * byte; `stuck` means we could not confirm that, and the only safe answer then
68
+ * is to refuse.
69
+ */
70
+ const interlock = { hub: ctx.managementOpsContext?.hub, herdctl };
59
71
  // --- chats (sessions) --------------------------------------------------
60
72
  app.get("/chats", {
61
73
  schema: {
@@ -595,7 +607,12 @@ export function registerChatWorkspaceRoutes(app, ctx) {
595
607
  },
596
608
  response: {
597
609
  200: {
598
- description: "Object `{ ok, removed }` indicating whether the transcript was removed.",
610
+ description: "Object `{ ok, removed, retained, cancelledTurn }` — whether the transcript was removed, and whether a live turn had to be stopped first (#731).",
611
+ type: "object",
612
+ additionalProperties: true,
613
+ },
614
+ 409: {
615
+ description: "`{ code: 'turn_running' }` — a turn is still running on this chat and could not be stopped, so nothing was deleted (#731).",
599
616
  type: "object",
600
617
  additionalProperties: true,
601
618
  },
@@ -604,6 +621,15 @@ export function registerChatWorkspaceRoutes(app, ctx) {
604
621
  }, async (req, reply) => {
605
622
  try {
606
623
  const agent = await agentForSlug(req.params.slug);
624
+ // #731: stop any in-flight turn FIRST. A delete is an unambiguous "this
625
+ // chat is going away", so we cancel rather than refuse — refusing would
626
+ // strand the user behind a turn that may never end (a hung turn was
627
+ // exactly how this was found). If the turn will not die we refuse, since
628
+ // deleting under a live writer is what resurrected the chat.
629
+ const quiesced = await quiesceSession(interlock, req.params.sessionId);
630
+ if (quiesced === "stuck") {
631
+ return reply.code(409).send(turnRunningError([req.params.sessionId]));
632
+ }
607
633
  await cleanupAttachments(agent, req.params.sessionId);
608
634
  const { removed, retained } = await herdctl.deleteSession(agent, req.params.sessionId);
609
635
  // Drop any archived/starred/unread/detached flag so a future session id
@@ -619,7 +645,9 @@ export function registerChatWorkspaceRoutes(app, ctx) {
619
645
  // has to be cleared on the same path — otherwise a recycled session id
620
646
  // silently starts life detached from a parent it never had.
621
647
  await parentDetach.setDetached(agent, req.params.sessionId, false).catch(() => undefined);
622
- return reply.code(200).send({ ok: true, removed, retained });
648
+ return reply
649
+ .code(200)
650
+ .send({ ok: true, removed, retained, cancelledTurn: quiesced === "stopped" });
623
651
  }
624
652
  catch (err) {
625
653
  return sendProjectError(reply, err);
@@ -751,7 +779,12 @@ export function registerChatWorkspaceRoutes(app, ctx) {
751
779
  },
752
780
  response: {
753
781
  200: {
754
- description: "Object reporting how many messages were removed.",
782
+ description: "Object reporting how many messages were removed, and whether a live turn had to be stopped first (`cancelledTurn`, #731).",
783
+ type: "object",
784
+ additionalProperties: true,
785
+ },
786
+ 409: {
787
+ description: "`{ code: 'turn_running' }` — a turn is still running on this chat and could not be stopped, so nothing was truncated (#731).",
755
788
  type: "object",
756
789
  additionalProperties: true,
757
790
  },
@@ -763,8 +796,19 @@ export function registerChatWorkspaceRoutes(app, ctx) {
763
796
  if (!uuid)
764
797
  return reply.code(400).send({ error: "uuid is required" });
765
798
  const project = await projects.get(req.params.slug);
799
+ // #731: revert truncates the LIVE transcript in place — the same file a
800
+ // running turn is appending to — so mid-turn it left an orphan
801
+ // `tool_result` whose `tool_use` had just been truncated away. Cancel
802
+ // rather than refuse: an in-flight turn is by definition part of the tail
803
+ // the user just asked to throw away.
804
+ const quiesced = await quiesceSession(interlock, req.params.sessionId);
805
+ if (quiesced === "stuck") {
806
+ return reply.code(409).send(turnRunningError([req.params.sessionId]));
807
+ }
766
808
  const { removed } = await herdctl.revertSession(project, req.params.sessionId, uuid);
767
- return reply.code(200).send({ ok: true, removed });
809
+ return reply
810
+ .code(200)
811
+ .send({ ok: true, removed, cancelledTurn: quiesced === "stopped" });
768
812
  }
769
813
  catch (err) {
770
814
  return sendProjectError(reply, err);
@@ -1206,6 +1250,14 @@ export function registerChatWorkspaceRoutes(app, ctx) {
1206
1250
  const failed = [];
1207
1251
  for (const sessionId of sessionIds) {
1208
1252
  try {
1253
+ // #731: same interlock as the single delete, per id. A chat whose
1254
+ // turn refuses to die lands in `failed` rather than aborting the
1255
+ // batch — the route is already best-effort-and-honest per chat, and
1256
+ // "still running" is exactly the kind of partial failure it reports.
1257
+ if ((await quiesceSession(interlock, sessionId)) === "stuck") {
1258
+ failed.push(sessionId);
1259
+ continue;
1260
+ }
1209
1261
  await cleanupAttachments(agent, sessionId);
1210
1262
  const gone = await herdctl.deleteSession(agent, sessionId);
1211
1263
  // `retained` counts as success here, and the distinction matters for
@@ -1279,7 +1331,12 @@ export function registerChatWorkspaceRoutes(app, ctx) {
1279
1331
  },
1280
1332
  response: {
1281
1333
  201: {
1282
- description: "Object `{ project, promoted, sessionId }` describing the created project and whether the transcript was re-homed.",
1334
+ description: "Object `{ project, promoted, sessionId, cancelledTurn }` describing the created project, whether the transcript was re-homed, and whether a live turn had to be stopped first (#731).",
1335
+ type: "object",
1336
+ additionalProperties: true,
1337
+ },
1338
+ 409: {
1339
+ description: "`{ code: 'turn_running' }` — a turn is still running on this chat and could not be stopped. Nothing was moved and NO project was created (#731).",
1283
1340
  type: "object",
1284
1341
  additionalProperties: true,
1285
1342
  },
@@ -1292,6 +1349,15 @@ export function registerChatWorkspaceRoutes(app, ctx) {
1292
1349
  }
1293
1350
  try {
1294
1351
  const from = await projects.get(req.params.slug);
1352
+ // #731: promote MOVES the transcript, so mid-turn it lost the chat from
1353
+ // BOTH projects — the surviving process rewrote the source path it still
1354
+ // held, while the moved copy went unlisted in the target with no recovery
1355
+ // path in the UI. Quiesce BEFORE `projects.create` so a refusal doesn't
1356
+ // leave an empty project behind as a side-effect of a failed promote.
1357
+ const quiesced = await quiesceSession(interlock, req.params.sessionId);
1358
+ if (quiesced === "stuck") {
1359
+ return reply.code(409).send(turnRunningError([req.params.sessionId]));
1360
+ }
1295
1361
  const project = await projects.create({
1296
1362
  name: body.name,
1297
1363
  slug: body.slug,
@@ -1315,7 +1381,12 @@ export function registerChatWorkspaceRoutes(app, ctx) {
1315
1381
  catch (err) {
1316
1382
  req.log.warn({ err }, "promote: could not re-home the transcript");
1317
1383
  }
1318
- return reply.code(201).send({ project, promoted, sessionId: req.params.sessionId });
1384
+ return reply.code(201).send({
1385
+ project,
1386
+ promoted,
1387
+ sessionId: req.params.sessionId,
1388
+ cancelledTurn: quiesced === "stopped",
1389
+ });
1319
1390
  }
1320
1391
  catch (err) {
1321
1392
  return sendProjectError(reply, err);
@@ -1,9 +1,10 @@
1
- import { ProjectError, ROOT_KEY, } from "../projects.js";
1
+ import { ProjectError, ROOT_KEY, isRootKey, } from "../projects.js";
2
2
  import { keeperAgentName } from "../herdctl.js";
3
3
  import { isKnownModel, isKnownPermissionMode, isValidMaxTurns, isKnownDriveMode, resolveModels, MAX_TURNS_LIMIT, } from "../models.js";
4
4
  import { isValidMaxSpawnDepth, MAX_SPAWN_DEPTH_LIMIT } from "../spawn-capability.js";
5
5
  import { sendProjectError } from "../route-errors.js";
6
6
  import { buildProjectChats, makeTriggerResolver, makeParentResolver } from "../chat-dto.js";
7
+ import { quiesceProject, turnRunningError } from "../turn-interlock.js";
7
8
  /**
8
9
  * Build ONE workspace's compact `{ sessionId, lastTurnCompletedAt, lastSeen?,
9
10
  * unread? }` list — the sidebar's UNREAD-badge feed (#161), server-backed (#189).
@@ -406,11 +407,30 @@ export function registerProjectWorkspaceRoutes(app, ctx) {
406
407
  type: "object",
407
408
  additionalProperties: true,
408
409
  },
410
+ 409: {
411
+ description: "`{ code: 'turn_running', sessionIds }` — one or more of the project's chats has a turn that could not be stopped, so nothing was deleted (#731).",
412
+ type: "object",
413
+ additionalProperties: true,
414
+ },
409
415
  },
410
416
  },
411
417
  }, async (req, reply) => {
412
418
  try {
413
- const project = await projects.remove(req.params.slug); // throws not_found
419
+ // #731: a project delete takes every chat in it, so it races the same live
420
+ // writers a chat delete does — and the orphaned `claude` was observed
421
+ // running on with a cwd of `…/<slug> (deleted)`. Stop them all first, and
422
+ // refuse rather than remove the directory out from under one.
423
+ //
424
+ // `remove()` refuses the ROOT workspace, and a refusal must not have killed
425
+ // the root's live turns on the way to saying no — so that one check comes
426
+ // first, mirroring the guard in `remove()` rather than duplicating its
427
+ // error.
428
+ if (!isRootKey(req.params.slug)) {
429
+ const stuck = await quiesceProject({ hub: ctx.managementOpsContext?.hub, herdctl }, req.params.slug);
430
+ if (stuck.length > 0)
431
+ return reply.code(409).send(turnRunningError(stuck));
432
+ }
433
+ const project = await projects.remove(req.params.slug); // throws not_found / refuses root
414
434
  try {
415
435
  await herdctl.removeProjectAgent(project.slug, Object.keys(project.hooks ?? {}), Object.keys(project.triggers ?? {}));
416
436
  }
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Schema versioning for the two on-disk formats paddock OWNS (issue #724).
3
+ *
4
+ * Those two are `project.yaml` and `paddock.config.yaml`, and only those two.
5
+ * The `version: 1` fields elsewhere in the tree belong to herdctl — its fleet
6
+ * config (`herdctl-agent-config.ts`) and `@herdctl/core`'s session metadata —
7
+ * and transcripts are Claude Code's format. Paddock reads neither back.
8
+ *
9
+ * ## What this is for: the DOWNGRADE guard, not migrations
10
+ *
11
+ * There is no migration runner here, deliberately (#724, and #717 for the
12
+ * sequencing). With `1` as the only version there is nothing to migrate, and a
13
+ * runner with zero migrations cannot be meaningfully tested.
14
+ *
15
+ * The value delivered on its own is the guard. Running an OLDER paddock against
16
+ * a data dir a newer one wrote — `npx @edspencer/paddock@0.62.0` is one command
17
+ * away — lenient-parses it: `ProjectStore.normalize` drops every key it does not
18
+ * recognise, and the next `update()` writes the file back without them. A
19
+ * `path:` or a `managed:` disappears with no error. A declared version turns
20
+ * that into "this file is version 4, I understand 1, I am not touching it".
21
+ *
22
+ * **Never lenient-parse a file from the future.** That is the whole point.
23
+ *
24
+ * ## Adoption cost: nothing
25
+ *
26
+ * The CURRENT on-disk shape *is* version 1, and an ABSENT `schemaVersion` reads
27
+ * as 1 — so no live instance needs rewriting and nothing pre-adoption can break,
28
+ * because those files genuinely are v1. Files we write carry the field
29
+ * explicitly; existing files gain it whenever they are next written for some
30
+ * other reason. There is no backfill.
31
+ *
32
+ * ## When to bump — read this before changing either format
33
+ *
34
+ * Bump ONLY when an old reader would get the wrong answer, or a new reader
35
+ * cannot recover the truth from an old file:
36
+ *
37
+ * | Change | Bump? |
38
+ * | --------------------------------------------------- | ----- |
39
+ * | Add an optional key with a safe default | **No** — lenient parsing already handles it |
40
+ * | Rename a key | Yes |
41
+ * | Change what an existing key *means* | Yes — silent misinterpretation, the dangerous one |
42
+ * | Change a default so *absence* now means something new | Yes |
43
+ * | Remove a load-bearing key | Yes |
44
+ *
45
+ * Adding a key does not bump, which covers most changes. The additive-vs-
46
+ * breaking distinction is expressed by NOT bumping, rather than by a second
47
+ * version component — hence a monotonic integer and never semver. A data file
48
+ * has one consumer, the app, and it always wants latest: there is no version
49
+ * negotiation for a minor/patch to describe, and migrations chain (1→2→3), which
50
+ * "does 1.2→2.0 include 1.3?" cannot express. Rails, Django, SQLite's
51
+ * `user_version` and IndexedDB all land in the same place.
52
+ *
53
+ * Worked example, so the table is not abstract. v0.64.0's `managed` default is
54
+ * `managed ?? !(repo || path)` (`project-paths.ts`) — row four, the absence of a
55
+ * key acquiring a derived meaning. Under this scheme that was a 1→2 migration:
56
+ * read v1, compute `managed`, write it explicitly, stamp 2. Instead it is a
57
+ * derivation re-evaluated on every read, forever, with `stripDto` deliberately
58
+ * letting `managed` survive so the first PATCH pins it. It works, but it is a
59
+ * migration in disguise, and that pattern accretes.
60
+ *
61
+ * The two constants are independent on purpose: a breaking change to
62
+ * `project.yaml` should not force every `paddock.config.yaml` to claim a version
63
+ * whose shape it never had. They happen to both be 1 today.
64
+ */
65
+ /** Schema version of the `project.yaml` format this build writes and understands. */
66
+ export declare const PROJECT_SCHEMA_VERSION = 1;
67
+ /** Schema version of the `paddock.config.yaml` format this build writes and understands. */
68
+ export declare const CONFIG_SCHEMA_VERSION = 1;
69
+ /** The key both formats carry it under. */
70
+ export declare const SCHEMA_VERSION_KEY = "schemaVersion";
71
+ /**
72
+ * The version a parsed file declares, or `null` if it declares something we
73
+ * cannot make sense of.
74
+ *
75
+ * - **Absent / null** → {@link PROJECT_SCHEMA_VERSION}-era, i.e. `1`. Every file
76
+ * written before adoption is genuinely a v1 file.
77
+ * - A positive integer (or a string spelling one, since YAML quoting is easy to
78
+ * get wrong by hand) → that integer.
79
+ * - Anything else — `0`, `-1`, `1.5`, `"banana"`, a list — → `null`.
80
+ *
81
+ * `null` is deliberately treated by callers the same way a from-the-future
82
+ * version is, not the same way an absent one is. A file whose own claim about
83
+ * its shape is unreadable is a file we cannot establish is safe to rewrite, and
84
+ * the failure mode this whole mechanism exists to prevent is rewriting one we
85
+ * did not understand.
86
+ */
87
+ export declare function readSchemaVersion(raw: unknown): number | null;
88
+ /** Whether `raw` declares a version this build cannot safely read. */
89
+ export declare function isFromTheFuture(raw: unknown, supported: number): boolean;
90
+ /**
91
+ * Why `paddock.config.yaml` is unreadable by this build, or `undefined` if it is
92
+ * fine. Pure, so the decision is testable without a filesystem.
93
+ *
94
+ * Fail-closed, in the same shape as the `claudeHome`-points-at-your-own-`~/.claude`
95
+ * refusal in `config.ts`: an instance config from the future governs auth mode,
96
+ * bind host and data paths, and half-understanding those is worse than not
97
+ * starting.
98
+ */
99
+ export declare function configSchemaRefusal(raw: unknown, configPath: string): string | undefined;
100
+ /**
101
+ * Why a `project.yaml` cannot be read by this build, or `undefined` if it is fine.
102
+ *
103
+ * Asymmetric with {@link configSchemaRefusal} on purpose, and this is the
104
+ * judgement call worth knowing about: a project from the future is SKIPPED,
105
+ * loudly, rather than refusing the boot. `readSafe` already returns `null` for
106
+ * an unreadable `project.yaml` and the project simply vanishes from `list()`, so
107
+ * saying it out loud is a strict improvement on today. Bricking a whole instance
108
+ * because one project directory was copied in from a newer box would be a worse
109
+ * failure than the data loss being prevented.
110
+ */
111
+ export declare function projectSchemaSkip(raw: unknown, file: string): string | undefined;
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Schema versioning for the two on-disk formats paddock OWNS (issue #724).
3
+ *
4
+ * Those two are `project.yaml` and `paddock.config.yaml`, and only those two.
5
+ * The `version: 1` fields elsewhere in the tree belong to herdctl — its fleet
6
+ * config (`herdctl-agent-config.ts`) and `@herdctl/core`'s session metadata —
7
+ * and transcripts are Claude Code's format. Paddock reads neither back.
8
+ *
9
+ * ## What this is for: the DOWNGRADE guard, not migrations
10
+ *
11
+ * There is no migration runner here, deliberately (#724, and #717 for the
12
+ * sequencing). With `1` as the only version there is nothing to migrate, and a
13
+ * runner with zero migrations cannot be meaningfully tested.
14
+ *
15
+ * The value delivered on its own is the guard. Running an OLDER paddock against
16
+ * a data dir a newer one wrote — `npx @edspencer/paddock@0.62.0` is one command
17
+ * away — lenient-parses it: `ProjectStore.normalize` drops every key it does not
18
+ * recognise, and the next `update()` writes the file back without them. A
19
+ * `path:` or a `managed:` disappears with no error. A declared version turns
20
+ * that into "this file is version 4, I understand 1, I am not touching it".
21
+ *
22
+ * **Never lenient-parse a file from the future.** That is the whole point.
23
+ *
24
+ * ## Adoption cost: nothing
25
+ *
26
+ * The CURRENT on-disk shape *is* version 1, and an ABSENT `schemaVersion` reads
27
+ * as 1 — so no live instance needs rewriting and nothing pre-adoption can break,
28
+ * because those files genuinely are v1. Files we write carry the field
29
+ * explicitly; existing files gain it whenever they are next written for some
30
+ * other reason. There is no backfill.
31
+ *
32
+ * ## When to bump — read this before changing either format
33
+ *
34
+ * Bump ONLY when an old reader would get the wrong answer, or a new reader
35
+ * cannot recover the truth from an old file:
36
+ *
37
+ * | Change | Bump? |
38
+ * | --------------------------------------------------- | ----- |
39
+ * | Add an optional key with a safe default | **No** — lenient parsing already handles it |
40
+ * | Rename a key | Yes |
41
+ * | Change what an existing key *means* | Yes — silent misinterpretation, the dangerous one |
42
+ * | Change a default so *absence* now means something new | Yes |
43
+ * | Remove a load-bearing key | Yes |
44
+ *
45
+ * Adding a key does not bump, which covers most changes. The additive-vs-
46
+ * breaking distinction is expressed by NOT bumping, rather than by a second
47
+ * version component — hence a monotonic integer and never semver. A data file
48
+ * has one consumer, the app, and it always wants latest: there is no version
49
+ * negotiation for a minor/patch to describe, and migrations chain (1→2→3), which
50
+ * "does 1.2→2.0 include 1.3?" cannot express. Rails, Django, SQLite's
51
+ * `user_version` and IndexedDB all land in the same place.
52
+ *
53
+ * Worked example, so the table is not abstract. v0.64.0's `managed` default is
54
+ * `managed ?? !(repo || path)` (`project-paths.ts`) — row four, the absence of a
55
+ * key acquiring a derived meaning. Under this scheme that was a 1→2 migration:
56
+ * read v1, compute `managed`, write it explicitly, stamp 2. Instead it is a
57
+ * derivation re-evaluated on every read, forever, with `stripDto` deliberately
58
+ * letting `managed` survive so the first PATCH pins it. It works, but it is a
59
+ * migration in disguise, and that pattern accretes.
60
+ *
61
+ * The two constants are independent on purpose: a breaking change to
62
+ * `project.yaml` should not force every `paddock.config.yaml` to claim a version
63
+ * whose shape it never had. They happen to both be 1 today.
64
+ */
65
+ /** Schema version of the `project.yaml` format this build writes and understands. */
66
+ export const PROJECT_SCHEMA_VERSION = 1;
67
+ /** Schema version of the `paddock.config.yaml` format this build writes and understands. */
68
+ export const CONFIG_SCHEMA_VERSION = 1;
69
+ /** The key both formats carry it under. */
70
+ export const SCHEMA_VERSION_KEY = "schemaVersion";
71
+ /**
72
+ * The version a parsed file declares, or `null` if it declares something we
73
+ * cannot make sense of.
74
+ *
75
+ * - **Absent / null** → {@link PROJECT_SCHEMA_VERSION}-era, i.e. `1`. Every file
76
+ * written before adoption is genuinely a v1 file.
77
+ * - A positive integer (or a string spelling one, since YAML quoting is easy to
78
+ * get wrong by hand) → that integer.
79
+ * - Anything else — `0`, `-1`, `1.5`, `"banana"`, a list — → `null`.
80
+ *
81
+ * `null` is deliberately treated by callers the same way a from-the-future
82
+ * version is, not the same way an absent one is. A file whose own claim about
83
+ * its shape is unreadable is a file we cannot establish is safe to rewrite, and
84
+ * the failure mode this whole mechanism exists to prevent is rewriting one we
85
+ * did not understand.
86
+ */
87
+ export function readSchemaVersion(raw) {
88
+ if (raw === undefined || raw === null)
89
+ return 1;
90
+ const n = typeof raw === "number" ? raw : typeof raw === "string" ? Number(raw.trim()) : NaN;
91
+ if (!Number.isInteger(n) || n < 1)
92
+ return null;
93
+ return n;
94
+ }
95
+ /** How a declared version reads in a message, including the unreadable case. */
96
+ function describeDeclared(raw) {
97
+ const found = readSchemaVersion(raw);
98
+ return found === null ? `an unreadable \`schemaVersion\` (${JSON.stringify(raw)})` : `version ${found}`;
99
+ }
100
+ /** Whether `raw` declares a version this build cannot safely read. */
101
+ export function isFromTheFuture(raw, supported) {
102
+ const found = readSchemaVersion(raw);
103
+ return found === null || found > supported;
104
+ }
105
+ /**
106
+ * Why `paddock.config.yaml` is unreadable by this build, or `undefined` if it is
107
+ * fine. Pure, so the decision is testable without a filesystem.
108
+ *
109
+ * Fail-closed, in the same shape as the `claudeHome`-points-at-your-own-`~/.claude`
110
+ * refusal in `config.ts`: an instance config from the future governs auth mode,
111
+ * bind host and data paths, and half-understanding those is worse than not
112
+ * starting.
113
+ */
114
+ export function configSchemaRefusal(raw, configPath) {
115
+ if (!isFromTheFuture(raw, CONFIG_SCHEMA_VERSION))
116
+ return undefined;
117
+ return (`refusing to start: ${configPath} declares ${describeDeclared(raw)} of the paddock config ` +
118
+ `format, but this build understands up to version ${CONFIG_SCHEMA_VERSION}. It was written ` +
119
+ `by a NEWER paddock. Reading it with this build would silently drop every key this version ` +
120
+ `does not know, and the next write would persist the loss. Upgrade paddock to a version that ` +
121
+ `understands it, or point PADDOCK_CONFIG at a config file this build wrote.`);
122
+ }
123
+ /**
124
+ * Why a `project.yaml` cannot be read by this build, or `undefined` if it is fine.
125
+ *
126
+ * Asymmetric with {@link configSchemaRefusal} on purpose, and this is the
127
+ * judgement call worth knowing about: a project from the future is SKIPPED,
128
+ * loudly, rather than refusing the boot. `readSafe` already returns `null` for
129
+ * an unreadable `project.yaml` and the project simply vanishes from `list()`, so
130
+ * saying it out loud is a strict improvement on today. Bricking a whole instance
131
+ * because one project directory was copied in from a newer box would be a worse
132
+ * failure than the data loss being prevented.
133
+ */
134
+ export function projectSchemaSkip(raw, file) {
135
+ if (!isFromTheFuture(raw, PROJECT_SCHEMA_VERSION))
136
+ return undefined;
137
+ return (`skipping a project: ${file} declares ${describeDeclared(raw)} of the paddock project ` +
138
+ `format, but this build understands up to version ${PROJECT_SCHEMA_VERSION}. It was written ` +
139
+ `by a NEWER paddock. The project is hidden — NOT deleted, and the file is left exactly as it ` +
140
+ `is — because reading it here would drop the keys this version does not know and the next ` +
141
+ `save would persist that loss. Upgrade paddock to see it again.`);
142
+ }
@@ -266,6 +266,31 @@ export interface TaskToolUses {
266
266
  paired: TaskToolUse[];
267
267
  /** Launches still in flight (no tool_result yet), in file order. */
268
268
  pending: TaskToolUse[];
269
+ /** What of this transcript belongs to a sub-agent's own lane — see {@link SidechainLines}. */
270
+ sidechain: SidechainLines;
271
+ }
272
+ /**
273
+ * The sub-agent-lane content of one transcript (issue #727).
274
+ *
275
+ * A sub-agent's steps belong INSIDE its Task card, served by the subagents
276
+ * endpoint — never as top-level rows of the parent transcript. The live path
277
+ * enforces that in five places via `isSidechainMessage` (`ws-turn.ts`), but the
278
+ * history path had no equivalent: `@herdctl/core`'s parser treats `isSidechain`
279
+ * as a whole-SESSION property (a sidechain gets its own file) and drops the
280
+ * per-line flag from the `ChatMessage` it returns, so any sidechain line written
281
+ * INTO a main transcript is parsed as a first-class message and served by
282
+ * `/messages`. This recovers the markers from the raw transcript, which is the
283
+ * only place they survive.
284
+ *
285
+ * Recovered in the same pass as the Task launches above, so it costs no extra I/O.
286
+ */
287
+ export interface SidechainLines {
288
+ /** `uuid` of every sidechain line — the key `ChatMessage.uuid` joins on. */
289
+ uuids: Set<string>;
290
+ /** `tool_use.id` of every Task/Agent launched FROM a sidechain line (a sub-agent
291
+ * spawning its own sub-agent). Dropped from the parent's join so the file-order
292
+ * alignment survives losing the sidechain messages. */
293
+ taskIds: Set<string>;
269
294
  }
270
295
  /**
271
296
  * Stream the main session transcript and recover, in file order, every
@@ -277,6 +302,46 @@ export interface TaskToolUses {
277
302
  * launches separately, and mixing them here would break that alignment.
278
303
  */
279
304
  export declare function readTaskToolUses(projectDir: string, sessionId: string): Promise<TaskToolUse[]>;
305
+ /**
306
+ * True when a raw transcript LINE was written on a sub-agent's own lane.
307
+ *
308
+ * Two markers, because the writers disagree: Claude Code stamps `isSidechain:
309
+ * true` (plus an `agentId`) on the line, while the SDK message stream — which
310
+ * `isSidechainMessage` in `ws-turn.ts` reads live, and which the test harness
311
+ * mirrors onto disk — carries `parent_tool_use_id`. Either is conclusive.
312
+ *
313
+ * Exported because EVERY file-order join over a main transcript has to agree with
314
+ * {@link dropSidechainMessages} about which lines exist: a scan that keeps a
315
+ * sidechain line while the parsed message list has dropped it shifts the whole
316
+ * join by one (#727).
317
+ */
318
+ export declare function isSidechainLine(parsed: {
319
+ isSidechain?: unknown;
320
+ parent_tool_use_id?: unknown;
321
+ message?: {
322
+ parent_tool_use_id?: unknown;
323
+ };
324
+ }): boolean;
325
+ /**
326
+ * Drop a session's sub-agent sidechain steps from its parsed history (issue
327
+ * #727) — the history-path counterpart of the live path's `isSidechainMessage`
328
+ * filter, and the same invariant: a sub-agent's steps render INSIDE its Task
329
+ * card (via the subagents endpoint), never as top-level rows of the parent.
330
+ *
331
+ * Joins on `uuid`, the source line's own id, which `@herdctl/core` preserves on
332
+ * every parsed message (and, for a paired tool message, takes from the
333
+ * originating `tool_use` entry — so a sidechain tool call matches on the same
334
+ * line that made it sidechain). Rides the mtime-cached transcript scan, and
335
+ * short-circuits to the identity for the overwhelmingly common transcript with
336
+ * no sidechain lines at all, so this costs nothing on the normal path.
337
+ *
338
+ * A transcript that is sidechain top to bottom is not a parent with leaked steps
339
+ * — it IS a sub-agent's own session, the shape Claude Code writes as its own
340
+ * `agent-<hex>.jsonl`. herdctl keeps those out of session discovery, but if one
341
+ * is ever reached directly it should render its content, not an empty chat, so
342
+ * a drop that would empty the history is refused.
343
+ */
344
+ export declare function dropSidechainMessages<T extends ChatMessage>(projectDir: string, sessionId: string, messages: T[]): Promise<T[]>;
280
345
  /**
281
346
  * Live sub-agent enrichment for a tool frame (issue #429). When the tool is a
282
347
  * `Task`/`Agent` launch this turn already recovered (via {@link extractSubagentLaunches}),