@1agents/acp-service 0.9.0 → 0.9.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 (266) hide show
  1. package/README.md +19 -13
  2. package/dist/bin/a2a.js +6 -2
  3. package/dist/bin/acp-service.js +24 -0
  4. package/dist/bin/process.d.ts +4 -0
  5. package/dist/bin/process.js +57 -0
  6. package/dist/bin/rsi.d.ts +3 -0
  7. package/dist/bin/rsi.js +114 -0
  8. package/dist/bin/ticket.d.ts +13 -0
  9. package/dist/bin/ticket.js +97 -0
  10. package/dist/bin/trail.d.ts +4 -0
  11. package/dist/bin/trail.js +62 -0
  12. package/dist/src/a2a/artifact-content.d.ts +9 -0
  13. package/dist/src/a2a/artifact-content.js +45 -0
  14. package/dist/src/a2a/desktop-notify.d.ts +1 -0
  15. package/dist/src/a2a/desktop-notify.js +12 -0
  16. package/dist/src/a2a/execution-binding.d.ts +9 -0
  17. package/dist/src/a2a/execution-binding.js +19 -0
  18. package/dist/src/a2a/executor.d.ts +6 -0
  19. package/dist/src/a2a/executor.js +112 -12
  20. package/dist/src/a2a/gateway.d.ts +537 -2
  21. package/dist/src/a2a/gateway.js +1014 -87
  22. package/dist/src/a2a/index.d.ts +8 -1
  23. package/dist/src/a2a/index.js +4 -0
  24. package/dist/src/a2a/job-directory.d.ts +6 -0
  25. package/dist/src/a2a/job-directory.js +19 -0
  26. package/dist/src/a2a/preflight.js +16 -1
  27. package/dist/src/a2a/resubmit.d.ts +46 -0
  28. package/dist/src/a2a/resubmit.js +82 -0
  29. package/dist/src/a2a/result-metadata.d.ts +3 -0
  30. package/dist/src/a2a/result-metadata.js +23 -5
  31. package/dist/src/a2a/server.d.ts +10 -0
  32. package/dist/src/a2a/server.js +125 -1
  33. package/dist/src/a2a/session-lifecycle.d.ts +40 -0
  34. package/dist/src/a2a/session-lifecycle.js +54 -0
  35. package/dist/src/a2a/store.d.ts +4 -0
  36. package/dist/src/a2a/store.js +70 -1
  37. package/dist/src/a2a/types.d.ts +45 -0
  38. package/dist/src/a2a/workbench-ui.d.ts +28 -0
  39. package/dist/src/a2a/workbench-ui.js +182 -0
  40. package/dist/src/acp-connection.js +27 -3
  41. package/dist/src/bridge.d.ts +1 -0
  42. package/dist/src/bridge.js +191 -39
  43. package/dist/src/capacity-queue.d.ts +35 -0
  44. package/dist/src/capacity-queue.js +139 -2
  45. package/dist/src/capacity.d.ts +25 -0
  46. package/dist/src/capacity.js +48 -9
  47. package/dist/src/dsh.js +1 -1
  48. package/dist/src/execution/agent-files.d.ts +25 -0
  49. package/dist/src/execution/agent-files.js +90 -0
  50. package/dist/src/execution/agent-registry.d.ts +164 -0
  51. package/dist/src/execution/agent-registry.js +275 -0
  52. package/dist/src/execution/human-review.d.ts +2 -0
  53. package/dist/src/execution/human-review.js +3 -1
  54. package/dist/src/execution/ledger.d.ts +52 -0
  55. package/dist/src/execution/ledger.js +83 -5
  56. package/dist/src/execution/process-request.d.ts +151 -0
  57. package/dist/src/execution/process-request.js +177 -0
  58. package/dist/src/execution/targets.d.ts +15 -0
  59. package/dist/src/execution/targets.js +22 -3
  60. package/dist/src/execution/ticket-executor.d.ts +25 -0
  61. package/dist/src/execution/ticket-executor.js +27 -0
  62. package/dist/src/execution/ticket.d.ts +326 -0
  63. package/dist/src/execution/ticket.js +301 -0
  64. package/dist/src/execution/workbench-chat.d.ts +25 -0
  65. package/dist/src/execution/workbench-chat.js +54 -0
  66. package/dist/src/execution/workbench.d.ts +32 -1
  67. package/dist/src/execution/workbench.js +113 -22
  68. package/dist/src/rsi/gate.d.ts +25 -0
  69. package/dist/src/rsi/gate.js +59 -0
  70. package/dist/src/rsi/outline-run.d.ts +107 -0
  71. package/dist/src/rsi/outline-run.js +443 -0
  72. package/dist/workbench-ui/app.css +453 -0
  73. package/dist/workbench-ui/app.js +13 -0
  74. package/dist/workbench-ui/chunk-23JHGYT3.js +1 -0
  75. package/dist/workbench-ui/chunk-3H6STGPV.js +1 -0
  76. package/dist/workbench-ui/chunk-3SNBBMGH.js +1 -0
  77. package/dist/workbench-ui/chunk-3XJZ6DIE.js +1 -0
  78. package/dist/workbench-ui/chunk-44KDLLKJ.js +1 -0
  79. package/dist/workbench-ui/chunk-46H7FU5Y.js +7 -0
  80. package/dist/workbench-ui/chunk-4N44QPL7.js +1 -0
  81. package/dist/workbench-ui/chunk-4YN4BS7I.js +1 -0
  82. package/dist/workbench-ui/chunk-53EG4IVQ.js +96 -0
  83. package/dist/workbench-ui/chunk-5FIPUNR4.js +1 -0
  84. package/dist/workbench-ui/chunk-6DWWYA6G.js +2 -0
  85. package/dist/workbench-ui/chunk-6FU3T633.js +99 -0
  86. package/dist/workbench-ui/chunk-6XKIHRA4.js +1 -0
  87. package/dist/workbench-ui/chunk-7GIX43Y5.js +1 -0
  88. package/dist/workbench-ui/chunk-7Q4WBGX6.js +4 -0
  89. package/dist/workbench-ui/chunk-A3BQM7HR.js +1 -0
  90. package/dist/workbench-ui/chunk-AFCFDDOP.js +24 -0
  91. package/dist/workbench-ui/chunk-AG67EUYD.js +89 -0
  92. package/dist/workbench-ui/chunk-AGJHMMTN.js +1 -0
  93. package/dist/workbench-ui/chunk-AO6JUBV6.js +41 -0
  94. package/dist/workbench-ui/chunk-AUSLTP43.js +72 -0
  95. package/dist/workbench-ui/chunk-AVZL46TT.js +1 -0
  96. package/dist/workbench-ui/chunk-AZRIGIV2.js +168 -0
  97. package/dist/workbench-ui/chunk-B2LIVH37.js +1 -0
  98. package/dist/workbench-ui/chunk-B7YX5TR5.js +1 -0
  99. package/dist/workbench-ui/chunk-BCB4X4XX.js +1 -0
  100. package/dist/workbench-ui/chunk-BCRQUL2A.js +88 -0
  101. package/dist/workbench-ui/chunk-BI6UHHQP.js +1 -0
  102. package/dist/workbench-ui/chunk-BLSLQ4AQ.js +120 -0
  103. package/dist/workbench-ui/chunk-C3QSRS6E.js +1 -0
  104. package/dist/workbench-ui/chunk-CK7M2PJ3.js +62 -0
  105. package/dist/workbench-ui/chunk-CM6LZ7TU.js +1 -0
  106. package/dist/workbench-ui/chunk-CP63H27F.js +36 -0
  107. package/dist/workbench-ui/chunk-CPUMMIS2.js +70 -0
  108. package/dist/workbench-ui/chunk-CSEIBI5U.js +2 -0
  109. package/dist/workbench-ui/chunk-CUS65DKZ.js +161 -0
  110. package/dist/workbench-ui/chunk-CVQY7TNC.js +1 -0
  111. package/dist/workbench-ui/chunk-D6S3XBIX.js +106 -0
  112. package/dist/workbench-ui/chunk-E253Y562.js +1 -0
  113. package/dist/workbench-ui/chunk-EADDJUDC.js +1 -0
  114. package/dist/workbench-ui/chunk-EBGJ3YXG.js +206 -0
  115. package/dist/workbench-ui/chunk-EKPVZ3WY.js +8 -0
  116. package/dist/workbench-ui/chunk-EQDCEAFY.js +1 -0
  117. package/dist/workbench-ui/chunk-ES3SSDJY.js +40 -0
  118. package/dist/workbench-ui/chunk-ESFD2H7N.js +231 -0
  119. package/dist/workbench-ui/chunk-FVOHPMS6.js +1 -0
  120. package/dist/workbench-ui/chunk-FXMQAGVT.js +1 -0
  121. package/dist/workbench-ui/chunk-GGTADRXD.js +24 -0
  122. package/dist/workbench-ui/chunk-GHIVPGNQ.js +1 -0
  123. package/dist/workbench-ui/chunk-GLU2YQV2.js +1 -0
  124. package/dist/workbench-ui/chunk-GOCKBYSM.js +1 -0
  125. package/dist/workbench-ui/chunk-H2KMMTJB.js +1 -0
  126. package/dist/workbench-ui/chunk-HGVLDNPP.js +39 -0
  127. package/dist/workbench-ui/chunk-HSAVC5GY.js +1 -0
  128. package/dist/workbench-ui/chunk-HSEAD2JH.js +1 -0
  129. package/dist/workbench-ui/chunk-HSIHOBTY.js +1 -0
  130. package/dist/workbench-ui/chunk-IZXOKUGG.js +67 -0
  131. package/dist/workbench-ui/chunk-JFT2LC2T.js +1 -0
  132. package/dist/workbench-ui/chunk-JHL3ZDYK.js +3 -0
  133. package/dist/workbench-ui/chunk-JMORLCZG.js +257 -0
  134. package/dist/workbench-ui/chunk-JR4SIX7A.js +1 -0
  135. package/dist/workbench-ui/chunk-K23HAGEH.js +30 -0
  136. package/dist/workbench-ui/chunk-K43JDCBH.js +1 -0
  137. package/dist/workbench-ui/chunk-KINKFJY7.js +1 -0
  138. package/dist/workbench-ui/chunk-KKQSA4LI.js +2 -0
  139. package/dist/workbench-ui/chunk-KOUZX3UX.js +1 -0
  140. package/dist/workbench-ui/chunk-KR4DRHW2.js +78 -0
  141. package/dist/workbench-ui/chunk-KT4DJNOR.js +1 -0
  142. package/dist/workbench-ui/chunk-KTPNKRRZ.js +292 -0
  143. package/dist/workbench-ui/chunk-LFHIPGSU.js +7 -0
  144. package/dist/workbench-ui/chunk-LWDL4HZB.js +125 -0
  145. package/dist/workbench-ui/chunk-MVYC3CY4.js +1 -0
  146. package/dist/workbench-ui/chunk-NWUPALCY.js +129 -0
  147. package/dist/workbench-ui/chunk-NY7C662Z.js +1 -0
  148. package/dist/workbench-ui/chunk-O76WTHWP.js +1 -0
  149. package/dist/workbench-ui/chunk-OTF7YHRE.js +162 -0
  150. package/dist/workbench-ui/chunk-P6TKKRKP.js +1 -0
  151. package/dist/workbench-ui/chunk-PFHOOWV3.js +1 -0
  152. package/dist/workbench-ui/chunk-PUQLANIM.js +1 -0
  153. package/dist/workbench-ui/chunk-PZCGBYVO.js +1 -0
  154. package/dist/workbench-ui/chunk-QOHUZGP4.js +1 -0
  155. package/dist/workbench-ui/chunk-QSEG3OFF.js +1 -0
  156. package/dist/workbench-ui/chunk-QYPOXZIA.js +84 -0
  157. package/dist/workbench-ui/chunk-R6SOF3JC.js +1 -0
  158. package/dist/workbench-ui/chunk-RCLOYU5F.js +1 -0
  159. package/dist/workbench-ui/chunk-RSRUP64S.js +1 -0
  160. package/dist/workbench-ui/chunk-RVAIT6JW.js +1 -0
  161. package/dist/workbench-ui/chunk-S2CCN3II.js +1 -0
  162. package/dist/workbench-ui/chunk-S2Q52W46.js +1 -0
  163. package/dist/workbench-ui/chunk-S2W5THJ5.js +1 -0
  164. package/dist/workbench-ui/chunk-S6ZQZNOX.js +1 -0
  165. package/dist/workbench-ui/chunk-S74PLMMS.js +1 -0
  166. package/dist/workbench-ui/chunk-S7C4HKEY.js +1 -0
  167. package/dist/workbench-ui/chunk-SDTB3Q65.js +1 -0
  168. package/dist/workbench-ui/chunk-SLPRGYUV.js +32 -0
  169. package/dist/workbench-ui/chunk-SQE76S5B.js +1 -0
  170. package/dist/workbench-ui/chunk-SSDZPVPW.js +1 -0
  171. package/dist/workbench-ui/chunk-SVI7DGIE.js +1 -0
  172. package/dist/workbench-ui/chunk-T6QKLZ4H.js +62 -0
  173. package/dist/workbench-ui/chunk-TJNRPTFL.js +1 -0
  174. package/dist/workbench-ui/chunk-TP6U4EDH.js +2 -0
  175. package/dist/workbench-ui/chunk-TYAAT3GQ.js +1 -0
  176. package/dist/workbench-ui/chunk-U6OCY4ZH.js +1 -0
  177. package/dist/workbench-ui/chunk-UAN3NLRF.js +1 -0
  178. package/dist/workbench-ui/chunk-UMLU3FIX.js +1 -0
  179. package/dist/workbench-ui/chunk-URIY2OTM.js +1 -0
  180. package/dist/workbench-ui/chunk-V2NUKAA7.js +38 -0
  181. package/dist/workbench-ui/chunk-V4QLL4TE.js +139 -0
  182. package/dist/workbench-ui/chunk-VASHXUK4.js +2 -0
  183. package/dist/workbench-ui/chunk-VJLIWNIU.js +1 -0
  184. package/dist/workbench-ui/chunk-VQNQFBID.js +1 -0
  185. package/dist/workbench-ui/chunk-VSIWU7XA.js +3 -0
  186. package/dist/workbench-ui/chunk-VSJASPUZ.js +321 -0
  187. package/dist/workbench-ui/chunk-VXPNUNUX.js +3 -0
  188. package/dist/workbench-ui/chunk-WBKLDCV6.js +1 -0
  189. package/dist/workbench-ui/chunk-WOKJM3FY.js +1 -0
  190. package/dist/workbench-ui/chunk-X3U3NA3X.js +34 -0
  191. package/dist/workbench-ui/chunk-XBYU7M4J.js +1 -0
  192. package/dist/workbench-ui/chunk-XBZAO4ID.js +10 -0
  193. package/dist/workbench-ui/chunk-XLLPZ2WO.js +1 -0
  194. package/dist/workbench-ui/chunk-YFVL4NJL.js +1 -0
  195. package/dist/workbench-ui/chunk-YRFQENM4.js +1 -0
  196. package/dist/workbench-ui/chunk-YUADQVB2.js +1 -0
  197. package/dist/workbench-ui/chunk-Z3TCAKM5.js +1 -0
  198. package/dist/workbench-ui/chunk-Z6QR6FRE.js +10 -0
  199. package/dist/workbench-ui/chunk-ZJPSORPP.js +3 -0
  200. package/dist/workbench-ui/chunk-ZLGCSTR2.js +15 -0
  201. package/dist/workbench-ui/chunk-ZLR4SG5X.js +1 -0
  202. package/dist/workbench-ui/chunk-ZND3TTGF.js +1 -0
  203. package/dist/workbench-ui/chunk-ZOP3ZYH7.js +2 -0
  204. package/dist/workbench-ui/index.html +14 -0
  205. package/package.json +19 -8
  206. package/skills/acp-service/SKILL.md +3 -1
  207. package/skills/acp-service/references/a2a.md +17 -5
  208. package/skills/acp-service/references/dsh.md +2 -0
  209. package/skills/acp-service/references/roles-and-tasks.md +1 -1
  210. package/skills/rsi-coach/SKILL.md +134 -0
  211. package/vendor/dsh/README.md +10 -6
  212. package/vendor/dsh/a2a-executor.d.ts +56 -2
  213. package/vendor/dsh/a2a-executor.js +163 -17
  214. package/vendor/dsh/a2a.d.ts +12 -2
  215. package/vendor/dsh/a2a.js +9 -2
  216. package/vendor/dsh/adapter.d.ts +52 -3
  217. package/vendor/dsh/adapter.js +297 -30
  218. package/vendor/dsh/client.js +67 -11
  219. package/vendor/dsh/index.js +55 -3
  220. package/vendor/dsh/native-approvals.d.ts +4 -0
  221. package/vendor/dsh/native-approvals.js +44 -0
  222. package/vendor/dsh/preset-route.d.ts +49 -0
  223. package/vendor/dsh/preset-route.js +51 -0
  224. package/vendor/dsh/preset.js +10 -3
  225. package/vendor/dsh/process-admission.d.ts +25 -0
  226. package/vendor/dsh/process-admission.js +87 -0
  227. package/vendor/dsh/process-requests.d.ts +57 -0
  228. package/vendor/dsh/process-requests.js +49 -0
  229. package/vendor/dsh/review-mcp.d.ts +1 -0
  230. package/vendor/dsh/review-mcp.js +56 -0
  231. package/vendor/dsh/review.d.ts +30 -0
  232. package/vendor/dsh/review.js +149 -0
  233. package/vendor/dsh/session-settings.d.ts +34 -0
  234. package/vendor/dsh/session-settings.js +114 -0
  235. package/vendor/dsh/ticket-spec.d.ts +30 -0
  236. package/vendor/dsh/ticket-spec.js +10 -0
  237. package/vendor/dsh/ticket-tools.d.ts +21 -0
  238. package/vendor/dsh/ticket-tools.js +43 -0
  239. package/vendor/dsh/workbench.d.ts +18 -0
  240. package/vendor/dsh/workbench.js +91 -0
  241. package/vendor/runtime/README.md +6 -4
  242. package/vendor/runtime/dist/docs-site/CLI.html +2 -2
  243. package/vendor/runtime/dist/docs-site/VISION.html +2 -2
  244. package/vendor/runtime/dist/docs-site/agents.html +2 -2
  245. package/vendor/runtime/dist/docs-site/compare.html +2 -2
  246. package/vendor/runtime/dist/docs-site/config.html +2 -2
  247. package/vendor/runtime/dist/docs-site/custom-agents.html +2 -2
  248. package/vendor/runtime/dist/docs-site/exit-codes.html +2 -2
  249. package/vendor/runtime/dist/docs-site/flows.html +2 -2
  250. package/vendor/runtime/dist/docs-site/index.html +1 -1
  251. package/vendor/runtime/dist/docs-site/install.html +2 -2
  252. package/vendor/runtime/dist/docs-site/llms.txt +1 -1
  253. package/vendor/runtime/dist/docs-site/output-formats.html +2 -2
  254. package/vendor/runtime/dist/docs-site/permissions.html +2 -2
  255. package/vendor/runtime/dist/docs-site/prompting.html +2 -2
  256. package/vendor/runtime/dist/docs-site/quickstart.html +2 -2
  257. package/vendor/runtime/dist/docs-site/releasing.html +2 -2
  258. package/vendor/runtime/dist/docs-site/runtime-environment.html +2 -2
  259. package/vendor/runtime/dist/docs-site/runtime-process-lifecycle.html +2 -2
  260. package/vendor/runtime/dist/docs-site/safe-errors.html +2 -2
  261. package/vendor/runtime/dist/docs-site/session-control.html +2 -2
  262. package/vendor/runtime/dist/docs-site/session-watch.html +2 -2
  263. package/vendor/runtime/dist/docs-site/sessions.html +2 -2
  264. package/vendor/runtime/dist/docs-site/shared-sessions.html +2 -2
  265. package/vendor/runtime/package.json +6 -4
  266. package/vendor/runtime/skills/acpx/SKILL.md +2 -0
@@ -0,0 +1,275 @@
1
+ /** Named agent drafts and releases for the workbench. A passed review does not publish a draft. */
2
+ import { randomUUID } from 'node:crypto';
3
+ import { closeSync, fsyncSync, mkdirSync, openSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
4
+ import path from 'node:path';
5
+ import { z } from 'zod';
6
+ const agentIdPattern = /^agt-[a-z0-9-]{8,80}$/;
7
+ const callName = z.string().trim().min(1).max(80).refine(value => !/[\u0000-\u001f\u007f]/.test(value), 'Invalid agent name');
8
+ const acpAgentName = z.string().trim().min(1).max(64).regex(/^[A-Za-z0-9][A-Za-z0-9._-]*$/);
9
+ const targetId = z.string().trim().min(1).max(200).regex(/^[A-Za-z0-9][A-Za-z0-9.:_-]*$/);
10
+ const optionId = z.string().trim().min(1).max(128).regex(/^[A-Za-z0-9][A-Za-z0-9._-]*$/);
11
+ const optionValue = z.string().trim().min(1).max(256).refine(value => !/[\u0000-\u001f\u007f]/.test(value), 'Invalid option value');
12
+ export const agentOptionSchema = z.object({
13
+ id: optionId,
14
+ value: optionValue,
15
+ model: z.literal(true).optional(),
16
+ }).strict();
17
+ const absolute = z.string().min(1).max(4096).refine(value => path.isAbsolute(value) && !value.includes('\0'), 'Expected an absolute local path');
18
+ /** Where a path-registered agent came from: the registered directory and its agents/*.md file. */
19
+ export const agentSourceSchema = z.object({ path: absolute, file: absolute }).strict();
20
+ const description = z.string().trim().min(1).max(1024);
21
+ export const agentDraftSchema = z.object({
22
+ agentId: z.string().regex(agentIdPattern),
23
+ name: callName,
24
+ // ACP drafts name their ACP agent; a path agent on a DSH-native preset names the preset (and an optional fixed model) instead.
25
+ acpAgent: acpAgentName.optional(),
26
+ agentPreset: targetId.optional(),
27
+ provider: targetId.optional(),
28
+ model: optionValue.optional(),
29
+ roleId: targetId.optional(),
30
+ targetId: targetId.optional(),
31
+ modeId: optionId.optional(),
32
+ options: z.array(agentOptionSchema).max(20),
33
+ source: agentSourceSchema.optional(),
34
+ description: description.optional(),
35
+ updatedAt: z.string().datetime(),
36
+ }).strict();
37
+ export const agentReleaseSchema = z.object({
38
+ releaseName: callName,
39
+ sourceAgentId: z.string().regex(agentIdPattern).optional(),
40
+ acpAgent: acpAgentName.optional(),
41
+ agentPreset: targetId.optional(),
42
+ provider: targetId.optional(),
43
+ model: optionValue.optional(),
44
+ roleId: targetId.optional(),
45
+ targetId: targetId.optional(),
46
+ modeId: optionId.optional(),
47
+ options: z.array(agentOptionSchema).max(20),
48
+ source: agentSourceSchema.optional(),
49
+ description: description.optional(),
50
+ publishedAt: z.string().datetime(),
51
+ }).strict();
52
+ const fileSchema = z.object({
53
+ version: z.literal(1),
54
+ drafts: z.array(agentDraftSchema),
55
+ releases: z.array(agentReleaseSchema),
56
+ }).strict();
57
+ const draftInputSchema = z.object({
58
+ name: callName,
59
+ acpAgent: acpAgentName,
60
+ roleId: targetId.optional(),
61
+ targetId: targetId.optional(),
62
+ modeId: optionId.optional(),
63
+ options: z.array(agentOptionSchema).max(20).default([]),
64
+ }).strict();
65
+ const draftPatchSchema = draftInputSchema.partial().strict();
66
+ const publishInputSchema = z.object({ releaseName: callName, replace: z.boolean().optional() }).strict();
67
+ export class AgentRegistryError extends Error {
68
+ code;
69
+ constructor(message, code) {
70
+ super(message);
71
+ this.code = code;
72
+ this.name = 'AgentRegistryError';
73
+ }
74
+ }
75
+ /** Model options stay ahead of the other accepted values. */
76
+ export function orderAgentOptions(options) {
77
+ const normalized = options.map(option => ({ id: option.id, value: option.value, ...(option.model || option.id === 'model' ? { model: true } : {}) }));
78
+ if (new Set(normalized.map(option => option.id)).size !== normalized.length)
79
+ throw new AgentRegistryError('Each ACP option id can be saved once', 'invalid');
80
+ return [...normalized.filter(option => option.model), ...normalized.filter(option => !option.model)];
81
+ }
82
+ export function readDevelopment(value) {
83
+ if (!value || typeof value !== 'object' || Array.isArray(value))
84
+ return undefined;
85
+ const record = value;
86
+ if ((record.channel !== 'trial' && record.channel !== 'formal') || (record.phase !== 'developing' && record.phase !== 'published'))
87
+ return undefined;
88
+ if (typeof record.agentId !== 'string' || !record.agentId || record.agentId.length > 200 || typeof record.name !== 'string' || !record.name || record.name.length > 80)
89
+ return undefined;
90
+ return { agentId: record.agentId, name: record.name, phase: record.phase, channel: record.channel };
91
+ }
92
+ /** A frozen admission wins. An unstamped resident target is already published. */
93
+ export function describeTaskDevelopment(raw, target) {
94
+ const stamped = readDevelopment(raw);
95
+ if (stamped)
96
+ return stamped;
97
+ if (target.resident)
98
+ return { channel: 'formal', phase: 'published', agentId: `resident:${target.targetId}`, name: target.residentName || target.targetId };
99
+ return { channel: 'standalone' };
100
+ }
101
+ export function projectWorkbenchAgents(catalog, tasks) {
102
+ const count = (agentId) => {
103
+ const owned = tasks.filter(task => task.agentId === agentId);
104
+ return { taskCount: owned.length, pendingCount: owned.filter(task => task.pendingReviewId || task.pendingProcessRequestId).length };
105
+ };
106
+ const developing = catalog.drafts.map(draft => {
107
+ const release = catalog.releases.find(item => item.sourceAgentId === draft.agentId);
108
+ return { agentId: draft.agentId, name: draft.name, phase: 'developing', origin: 'draft', ...(draft.acpAgent ? { acpAgent: draft.acpAgent } : {}),
109
+ ...(draft.agentPreset ? { agentPreset: draft.agentPreset } : {}), ...(draft.provider ? { provider: draft.provider, model: draft.model } : {}),
110
+ ...(draft.roleId ? { roleId: draft.roleId } : {}), ...(draft.targetId ? { targetId: draft.targetId } : {}),
111
+ ...(draft.modeId ? { modeId: draft.modeId } : {}), options: draft.options.map(option => ({ ...option })),
112
+ ...(draft.source ? { source: { ...draft.source } } : {}), ...(draft.description ? { description: draft.description } : {}),
113
+ ...(release ? { counterpartId: `release:${release.releaseName}`, releaseName: release.releaseName } : {}), ...count(draft.agentId) };
114
+ });
115
+ const publishedReleases = catalog.releases.map(release => ({
116
+ agentId: `release:${release.releaseName}`, name: release.releaseName, phase: 'published', origin: 'release',
117
+ ...(release.acpAgent ? { acpAgent: release.acpAgent } : {}), ...(release.agentPreset ? { agentPreset: release.agentPreset } : {}), ...(release.provider ? { provider: release.provider, model: release.model } : {}),
118
+ ...(release.roleId ? { roleId: release.roleId } : {}), ...(release.targetId ? { targetId: release.targetId } : {}),
119
+ ...(release.modeId ? { modeId: release.modeId } : {}), options: release.options.map(option => ({ ...option })), releaseName: release.releaseName,
120
+ ...(release.source ? { source: { ...release.source } } : {}), ...(release.description ? { description: release.description } : {}),
121
+ ...(release.sourceAgentId ? { sourceAgentId: release.sourceAgentId, counterpartId: release.sourceAgentId } : {}), ...count(`release:${release.releaseName}`),
122
+ }));
123
+ const releasedTargets = new Set(catalog.releases.map(release => release.targetId).filter((id) => Boolean(id)));
124
+ const publishedResidents = catalog.residents.filter(resident => !releasedTargets.has(resident.targetId)).map(resident => ({
125
+ agentId: `resident:${resident.targetId}`, name: resident.name, phase: 'published', origin: 'resident',
126
+ ...(resident.roleId ? { roleId: resident.roleId } : {}), targetId: resident.targetId,
127
+ ...(resident.agentPreset ? { agentPreset: resident.agentPreset, acpAgent: resident.agentPreset.replace(/^oneagents-acp-/, '') } : {}),
128
+ options: [], ...count(`resident:${resident.targetId}`),
129
+ }));
130
+ return { developing, published: [...publishedReleases, ...publishedResidents] };
131
+ }
132
+ export class AgentRegistry {
133
+ file;
134
+ state;
135
+ constructor(directory) {
136
+ if (!path.isAbsolute(directory))
137
+ throw new Error('stateDirectory must be absolute');
138
+ mkdirSync(directory, { recursive: true, mode: 0o700 });
139
+ this.file = path.join(directory, 'agent-registry.json');
140
+ try {
141
+ this.state = fileSchema.parse(JSON.parse(readFileSync(this.file, 'utf8')));
142
+ }
143
+ catch (error) {
144
+ if (error.code !== 'ENOENT')
145
+ throw error;
146
+ this.state = { version: 1, drafts: [], releases: [] };
147
+ }
148
+ this.assertUnique();
149
+ }
150
+ snapshot() {
151
+ return { drafts: this.state.drafts.map(item => structuredClone(item)), releases: this.state.releases.map(item => structuredClone(item)) };
152
+ }
153
+ /** New calls use a release when one owns the target, then a draft, then an already resident role. */
154
+ admit(target) {
155
+ const release = this.state.releases.find(item => item.targetId === target.targetId);
156
+ if (release)
157
+ return { agentId: `release:${release.releaseName}`, name: release.releaseName, phase: 'published', channel: 'formal' };
158
+ const draft = this.state.drafts.find(item => item.targetId === target.targetId);
159
+ if (draft)
160
+ return { agentId: draft.agentId, name: draft.name, phase: 'developing', channel: 'trial' };
161
+ if (target.kind === 'resident_agent')
162
+ return { agentId: `resident:${target.targetId}`, name: target.name, phase: 'published', channel: 'formal' };
163
+ }
164
+ create(input) {
165
+ const parsed = this.parse(draftInputSchema, input);
166
+ if (this.state.drafts.some(item => item.name === parsed.name))
167
+ throw new AgentRegistryError('An agent draft with this name already exists', 'conflict');
168
+ const draft = { agentId: `agt-${randomUUID()}`, name: parsed.name, acpAgent: parsed.acpAgent, options: orderAgentOptions(parsed.options), updatedAt: new Date().toISOString(),
169
+ ...(parsed.roleId ? { roleId: parsed.roleId } : {}), ...(parsed.targetId ? { targetId: parsed.targetId } : {}), ...(parsed.modeId ? { modeId: parsed.modeId } : {}) };
170
+ this.commit({ ...this.state, drafts: [...this.state.drafts, draft] });
171
+ return structuredClone(draft);
172
+ }
173
+ update(agentId, input) {
174
+ const parsed = this.parse(draftPatchSchema, input);
175
+ const current = this.draft(agentId);
176
+ const next = { ...current, ...(parsed.name ? { name: parsed.name } : {}), ...(parsed.acpAgent ? { acpAgent: parsed.acpAgent } : {}),
177
+ ...(parsed.roleId ? { roleId: parsed.roleId } : {}), ...(parsed.targetId ? { targetId: parsed.targetId } : {}),
178
+ ...(parsed.modeId ? { modeId: parsed.modeId } : {}), ...(parsed.options ? { options: orderAgentOptions(parsed.options) } : {}), updatedAt: new Date().toISOString() };
179
+ if (this.state.drafts.some(item => item.agentId !== agentId && item.name === next.name))
180
+ throw new AgentRegistryError('An agent draft with this name already exists', 'conflict');
181
+ this.commit({ ...this.state, drafts: this.state.drafts.map(item => item.agentId === agentId ? next : item) });
182
+ return structuredClone(next);
183
+ }
184
+ /** Copy the draft into a callable name. The draft remains, and its target moves to the release. */
185
+ publish(agentId, input) {
186
+ const parsed = this.parse(publishInputSchema, input);
187
+ const draft = this.draft(agentId);
188
+ const existing = this.state.releases.find(item => item.releaseName === parsed.releaseName);
189
+ if (existing && !parsed.replace)
190
+ throw new AgentRegistryError(`Published name "${parsed.releaseName}" already exists`, 'conflict');
191
+ const release = { releaseName: parsed.releaseName, sourceAgentId: draft.agentId, ...(draft.acpAgent ? { acpAgent: draft.acpAgent } : {}),
192
+ ...(draft.agentPreset ? { agentPreset: draft.agentPreset } : {}), ...(draft.provider ? { provider: draft.provider, model: draft.model } : {}), options: orderAgentOptions(draft.options), publishedAt: new Date().toISOString(),
193
+ ...(draft.roleId ? { roleId: draft.roleId } : {}), ...(draft.targetId ? { targetId: draft.targetId } : {}), ...(draft.modeId ? { modeId: draft.modeId } : {}),
194
+ ...(draft.source ? { source: { ...draft.source } } : {}), ...(draft.description ? { description: draft.description } : {}) };
195
+ const opened = { ...draft, updatedAt: release.publishedAt };
196
+ delete opened.targetId;
197
+ this.commit({ ...this.state, drafts: this.state.drafts.map(item => item.agentId === agentId ? opened : item),
198
+ releases: [...this.state.releases.filter(item => item.releaseName !== parsed.releaseName), release] });
199
+ return structuredClone(release);
200
+ }
201
+ /** The draft registered from this agents/*.md file for this runtime: an ACP agent name or a DSH-native preset. */
202
+ pathDraft(file, runtime) {
203
+ const found = this.state.drafts.find(item => item.source?.file === file && (item.acpAgent ?? item.agentPreset) === runtime);
204
+ return found && structuredClone(found);
205
+ }
206
+ /**
207
+ * Create or refresh the draft for one agents/*.md file on one runtime. The file and runtime identify the draft, so
208
+ * registering the same path again updates it in place and keeps its tasks, while another runtime gets its own draft.
209
+ * A different draft already using the name is a conflict.
210
+ */
211
+ registerPathDraft(input) {
212
+ const parsed = this.parse(z.object({ name: callName, targetId, source: agentSourceSchema, description: description.optional(),
213
+ acpAgent: acpAgentName.optional(), agentPreset: targetId.optional(), provider: targetId.optional(), model: optionValue.optional() }).strict()
214
+ .refine(value => (value.acpAgent === undefined) !== (value.agentPreset === undefined) && (value.provider === undefined) === (value.model === undefined)
215
+ && !(value.acpAgent && value.provider), 'Name either an ACP agent or a DSH-native preset'), input);
216
+ const runtime = parsed.acpAgent ?? parsed.agentPreset;
217
+ const current = this.state.drafts.find(item => item.source?.file === parsed.source.file && (item.acpAgent ?? item.agentPreset) === runtime);
218
+ if (this.state.drafts.some(item => item !== current && item.name === parsed.name))
219
+ throw new AgentRegistryError(`An agent draft named "${parsed.name}" already exists`, 'conflict');
220
+ const { acpAgent: _acp, agentPreset: _preset, provider: _provider, model: _model, description: _description, ...kept } = current ?? { agentId: `agt-${randomUUID()}`, options: [] };
221
+ const next = { ...kept, name: parsed.name, targetId: parsed.targetId, source: parsed.source, updatedAt: new Date().toISOString(),
222
+ ...(parsed.acpAgent ? { acpAgent: parsed.acpAgent } : { agentPreset: parsed.agentPreset }),
223
+ ...(parsed.provider ? { provider: parsed.provider, model: parsed.model } : {}), ...(parsed.description ? { description: parsed.description } : {}) };
224
+ this.commit({ ...this.state, drafts: current ? this.state.drafts.map(item => item === current ? next : item) : [...this.state.drafts, next] });
225
+ return structuredClone(next);
226
+ }
227
+ draft(agentId) {
228
+ const found = this.state.drafts.find(item => item.agentId === agentId);
229
+ if (!found)
230
+ throw new AgentRegistryError('Agent draft not found', 'not_found');
231
+ return found;
232
+ }
233
+ parse(schema, input) {
234
+ const result = schema.safeParse(input);
235
+ if (!result.success)
236
+ throw new AgentRegistryError('Invalid agent settings', 'invalid');
237
+ return result.data;
238
+ }
239
+ assertUnique() {
240
+ for (const [label, values] of [['draft', this.state.drafts.map(item => item.agentId)], ['draft name', this.state.drafts.map(item => item.name)], ['release', this.state.releases.map(item => item.releaseName)]]) {
241
+ if (new Set(values).size !== values.length)
242
+ throw new Error(`Duplicate agent registry ${label}`);
243
+ }
244
+ }
245
+ commit(next) {
246
+ fileSchema.parse(next);
247
+ const temp = `${this.file}.${randomUUID()}.tmp`;
248
+ const fd = openSync(temp, 'wx', 0o600);
249
+ try {
250
+ try {
251
+ writeFileSync(fd, JSON.stringify(next));
252
+ fsyncSync(fd);
253
+ }
254
+ finally {
255
+ closeSync(fd);
256
+ }
257
+ renameSync(temp, this.file);
258
+ const dir = openSync(path.dirname(this.file), 'r');
259
+ try {
260
+ fsyncSync(dir);
261
+ }
262
+ finally {
263
+ closeSync(dir);
264
+ }
265
+ this.state = next;
266
+ }
267
+ catch (error) {
268
+ try {
269
+ unlinkSync(temp);
270
+ }
271
+ catch { /* The failed temp file is already gone. */ }
272
+ throw error;
273
+ }
274
+ }
275
+ }
@@ -1,4 +1,6 @@
1
1
  import { z } from 'zod';
2
+ /** Upper bound for one human-reviewed slide script; the page count itself follows the frozen script (N pages). */
3
+ export declare const MAX_HUMAN_REVIEW_SLIDES = 200;
2
4
  export declare const humanReviewPreviewSchema: z.ZodObject<{
3
5
  title: z.ZodString;
4
6
  slides: z.ZodArray<z.ZodObject<{
@@ -3,10 +3,12 @@ import { randomUUID } from 'node:crypto';
3
3
  import { z } from 'zod';
4
4
  const id = z.string().trim().min(1).max(512);
5
5
  const sha256 = z.string().regex(/^[a-f0-9]{64}$/);
6
+ /** Upper bound for one human-reviewed slide script; the page count itself follows the frozen script (N pages). */
7
+ export const MAX_HUMAN_REVIEW_SLIDES = 200;
6
8
  export const humanReviewPreviewSchema = z.object({
7
9
  title: z.string().min(1),
8
10
  slides: z.array(z.object({ title: z.string().min(1), message: z.string(), body: z.array(z.string()),
9
- visual: z.string(), sources: z.array(z.string()).min(1), facts: z.array(z.string()).min(1), notes: z.string() }).strict()).length(6),
11
+ visual: z.string(), sources: z.array(z.string()).min(1), facts: z.array(z.string()).min(1), notes: z.string() }).strict()).min(1).max(MAX_HUMAN_REVIEW_SLIDES),
10
12
  }).strict();
11
13
  const markdownReviewPreviewSchema = z.object({
12
14
  kind: z.literal('markdown'), title: z.string().min(1), markdown: z.string().min(1).max(256 * 1024),
@@ -1,3 +1,4 @@
1
+ import { type Ticket, type TicketChange } from './ticket.js';
1
2
  export type ExecutionStatus = 'not_started' | 'submitted' | 'working' | 'input_required' | 'auth_required' | 'completed' | 'failed' | 'canceled' | 'rejected' | 'unknown';
2
3
  export type SubmissionStatus = 'prepared' | 'dispatching' | 'accepted' | 'known_not_submitted' | 'submission_unknown';
3
4
  export interface JobRef {
@@ -35,6 +36,12 @@ export interface LedgerResult {
35
36
  resultAvailable: boolean;
36
37
  observedAt: string;
37
38
  }
39
+ /** Who acted: a person, or a coach agent naming its session. */
40
+ export interface LedgerActor {
41
+ kind: 'person' | 'coach';
42
+ agent?: string;
43
+ sessionId?: string;
44
+ }
38
45
  export interface BusinessAcceptance {
39
46
  attemptId: string;
40
47
  resultRevision: string;
@@ -42,6 +49,8 @@ export interface BusinessAcceptance {
42
49
  reviewStatus: 'pending' | 'accepted' | 'changes_requested';
43
50
  note?: string;
44
51
  recordedAt: string;
52
+ /** Absent on records written before acceptances named who decided. */
53
+ decidedBy?: LedgerActor;
45
54
  }
46
55
  export interface LedgerAttempt {
47
56
  attemptId: string;
@@ -70,6 +79,13 @@ export interface LedgerAttempt {
70
79
  diagnostic?: string;
71
80
  result?: LedgerResult;
72
81
  resultHistory?: LedgerResult[];
82
+ /** The origin stopped waiting on this round before it ended (it timed out, or the caller itself failed); it may still run or have finished unseen. */
83
+ unwatched?: {
84
+ at: string;
85
+ reason: string;
86
+ };
87
+ /** Who asked for this round, when the caller named itself. */
88
+ initiatedBy?: LedgerActor;
73
89
  }
74
90
  export interface LedgerJob {
75
91
  sourceId: string;
@@ -95,6 +111,8 @@ export interface LedgerJob {
95
111
  updatedAt: string;
96
112
  provenance: 'native' | 'legacy';
97
113
  migratedAt?: string;
114
+ /** Who asked for the task. originSessionId stays the access scope, and many callers share a default one. */
115
+ initiatedBy?: LedgerActor;
98
116
  }
99
117
  export interface LedgerEvent {
100
118
  eventId: string;
@@ -121,6 +139,8 @@ export interface LedgerState {
121
139
  events: LedgerEvent[];
122
140
  nextSequence: number;
123
141
  acceptances: Record<string, BusinessAcceptance[]>;
142
+ /** Task tickets by executor jobId; absent in state written before tickets existed. */
143
+ tickets?: Record<string, Ticket>;
124
144
  }
125
145
  export interface LedgerPrepareInput {
126
146
  originSessionId: string;
@@ -137,6 +157,7 @@ export interface LedgerPrepareInput {
137
157
  operation?: string;
138
158
  resultRevision?: string;
139
159
  replacesJobRef?: JobRef;
160
+ initiatedBy?: LedgerActor;
140
161
  }
141
162
  export interface LedgerObservation {
142
163
  executionStatus?: ExecutionStatus;
@@ -228,7 +249,38 @@ export declare class JobLedger {
228
249
  job: LedgerJob;
229
250
  attempt: LedgerAttempt;
230
251
  } | undefined;
252
+ /**
253
+ * The origin stopped waiting on the job's current round while it was still running. The round itself is unchanged:
254
+ * the workbench lists the job as abnormal until a re-query finds the round ended.
255
+ */
256
+ unwatch(originSessionId: string, jobId: string, reason: string): LedgerAttempt;
231
257
  acceptance(originSessionId: string, jobId: string, input: Omit<BusinessAcceptance, 'recordedAt'>): BusinessAcceptance;
258
+ /** A process request changed. The request itself is stored by the gateway; this puts it on the job's timeline. */
259
+ processEvent(jobId: string, attemptId: string, type: string, data: unknown): void;
260
+ /** The originator waits on the job again, so it is no longer listed as abandoned. */
261
+ rewatch(originSessionId: string, jobId: string): LedgerAttempt;
262
+ ticket(originSessionId: string, jobId: string): Ticket;
263
+ /**
264
+ * One ticket operation: it gets the job's ticket (undefined before one is opened) to change in place and reports
265
+ * its changes, each appended as a `ticket.*` event stamped with `caller` (attempt, session, QA job).
266
+ */
267
+ changeTicket(originSessionId: string, jobId: string, operation: (ticket: Ticket | undefined) => {
268
+ ticket: Ticket;
269
+ changes: TicketChange[];
270
+ }, caller?: {
271
+ attemptId?: string;
272
+ [key: string]: unknown;
273
+ }): Ticket;
274
+ /**
275
+ * Trusted adapter use only: the origin of the job whose current, unfinished attempt `attemptId` is. When the
276
+ * host reported which session runs the attempt, the caller must be that session.
277
+ */
278
+ executorOrigin(jobId: string, attemptId: string, sessionId: string): string;
279
+ /** Trusted adapter use only: the job's current attempt and the session the host reported for it, for a caller that names only the job. */
280
+ currentAttempt(jobId: string): {
281
+ attemptId: string;
282
+ sessionId?: string;
283
+ };
232
284
  /** Each old Task gets one legacy Job; matching context IDs never merge jobs. */
233
285
  migrateLegacy(records: LegacyLedgerRecord[]): Array<{
234
286
  remote: string;
@@ -1,5 +1,6 @@
1
1
  /** Durable Job/Attempt facts. This module does not execute or schedule work. */
2
2
  import { createHash, randomUUID } from 'node:crypto';
3
+ import { TicketError } from './ticket.js';
3
4
  const terminal = new Set(['completed', 'failed', 'canceled', 'rejected']);
4
5
  const statuses = new Set(['not_started', 'submitted', 'working', 'input_required', 'auth_required', 'completed', 'failed', 'canceled', 'rejected', 'unknown']);
5
6
  const clone = (value) => structuredClone(value);
@@ -48,10 +49,10 @@ export class JobLedger {
48
49
  if (initial.version !== 1 || !initial.sourceId || !initial.jobs || !initial.attempts || !initial.requests || !Array.isArray(initial.events)
49
50
  || !Number.isSafeInteger(initial.nextSequence) || !initial.acceptances)
50
51
  throw new Error('Invalid execution ledger state');
51
- this.state = clone(initial);
52
+ this.state = { ...clone(initial), tickets: clone(initial.tickets ?? {}) };
52
53
  }
53
54
  else {
54
- this.state = { version: 1, sourceId: randomUUID(), jobs: {}, attempts: {}, requests: {}, events: [], nextSequence: 1, acceptances: {} };
55
+ this.state = { version: 1, sourceId: randomUUID(), jobs: {}, attempts: {}, requests: {}, events: [], nextSequence: 1, acceptances: {}, tickets: {} };
55
56
  }
56
57
  }
57
58
  snapshot() { return clone(this.state); }
@@ -176,7 +177,8 @@ export class JobLedger {
176
177
  ...(input.targetSnapshot.roleId ? { roleId: input.targetSnapshot.roleId } : {}),
177
178
  ...(input.parentJobRef ? { parentJobRef: clone(input.parentJobRef), parentAttemptId: input.parentAttemptId } : {}),
178
179
  ...(input.purpose ? { purpose: input.purpose } : {}), ...(input.resultRevision ? { resultRevision: input.resultRevision } : {}),
179
- ...(input.replacesJobRef ? { replacesJobRef: clone(input.replacesJobRef) } : {}) };
180
+ ...(input.replacesJobRef ? { replacesJobRef: clone(input.replacesJobRef) } : {}),
181
+ ...(input.initiatedBy ? { initiatedBy: clone(input.initiatedBy) } : {}) };
180
182
  state.jobs[job.jobId] = job;
181
183
  }
182
184
  const attempt = { attemptId: randomUUID(), jobId: job.jobId, operation, requestDigest: digest,
@@ -185,12 +187,13 @@ export class JobLedger {
185
187
  connectionId: input.targetSnapshot.connectionId, connectionVersion: input.targetSnapshot.connectionVersion,
186
188
  provider: input.targetSnapshot.provider ?? 'a2a', targetSnapshot: clone(input.targetSnapshot), input: clone(input.input),
187
189
  ...(job.currentAttemptId ? { previousAttemptId: job.currentAttemptId } : {}), submissionStatus: 'prepared',
188
- executionStatus: 'not_started', stale: false, createdAt: timestamp, updatedAt: timestamp };
190
+ executionStatus: 'not_started', stale: false, createdAt: timestamp, updatedAt: timestamp,
191
+ ...(input.initiatedBy ? { initiatedBy: clone(input.initiatedBy) } : {}) };
189
192
  state.attempts[attempt.attemptId] = attempt;
190
193
  job.currentAttemptId = attempt.attemptId;
191
194
  if (requestKey)
192
195
  state.requests[requestKey] = { digest, jobId: job.jobId, attemptId: attempt.attemptId };
193
- this.event(state, job, attempt.attemptId, input.jobId ? 'attempt.prepared' : 'job.created', { operation });
196
+ this.event(state, job, attempt.attemptId, input.jobId ? 'attempt.prepared' : 'job.created', { operation, ...(input.initiatedBy ? { initiatedBy: input.initiatedBy } : {}) });
194
197
  return { job, attempt, idempotent: false };
195
198
  });
196
199
  }
@@ -371,6 +374,21 @@ export class JobLedger {
371
374
  && Object.entries(ref).every(([key, value]) => value === undefined || item.backendRunRef?.[key] === value));
372
375
  return attempt ? clone({ job: this.state.jobs[attempt.jobId], attempt }) : undefined;
373
376
  }
377
+ /**
378
+ * The origin stopped waiting on the job's current round while it was still running. The round itself is unchanged:
379
+ * the workbench lists the job as abnormal until a re-query finds the round ended.
380
+ */
381
+ unwatch(originSessionId, jobId, reason) {
382
+ return this.mutate(state => {
383
+ const job = this.job(state, originSessionId, jobId), attempt = this.attempt(state, job.currentAttemptId);
384
+ nonempty(reason, 'reason');
385
+ if (!terminal.has(attempt.executionStatus) && !attempt.unwatched) {
386
+ attempt.unwatched = { at: now(), reason };
387
+ this.event(state, job, attempt.attemptId, 'attempt.unwatched', { reason });
388
+ }
389
+ return clone(attempt);
390
+ });
391
+ }
374
392
  acceptance(originSessionId, jobId, input) {
375
393
  return this.mutate(state => {
376
394
  const job = this.job(state, originSessionId, jobId), attempt = this.attempt(state, input.attemptId);
@@ -388,6 +406,66 @@ export class JobLedger {
388
406
  return record;
389
407
  });
390
408
  }
409
+ /** A process request changed. The request itself is stored by the gateway; this puts it on the job's timeline. */
410
+ processEvent(jobId, attemptId, type, data) {
411
+ this.mutate(state => { this.event(state, state.jobs[jobId], attemptId, type, data); });
412
+ }
413
+ /** The originator waits on the job again, so it is no longer listed as abandoned. */
414
+ rewatch(originSessionId, jobId) {
415
+ return this.mutate(state => {
416
+ const job = this.job(state, originSessionId, jobId), attempt = this.attempt(state, job.currentAttemptId);
417
+ if (attempt.unwatched) {
418
+ delete attempt.unwatched;
419
+ this.event(state, job, attempt.attemptId, 'attempt.rewatched', {});
420
+ }
421
+ return clone(attempt);
422
+ });
423
+ }
424
+ ticket(originSessionId, jobId) {
425
+ this.job(this.state, originSessionId, jobId);
426
+ const ticket = this.state.tickets[jobId];
427
+ if (!ticket)
428
+ throw new TicketError('这个任务还没有任务单');
429
+ return clone(ticket);
430
+ }
431
+ /**
432
+ * One ticket operation: it gets the job's ticket (undefined before one is opened) to change in place and reports
433
+ * its changes, each appended as a `ticket.*` event stamped with `caller` (attempt, session, QA job).
434
+ */
435
+ changeTicket(originSessionId, jobId, operation, caller = {}) {
436
+ return this.mutate(state => {
437
+ const job = this.job(state, originSessionId, jobId), tickets = state.tickets ??= {};
438
+ const { ticket, changes } = operation(tickets[jobId]);
439
+ tickets[jobId] = ticket;
440
+ for (const change of changes)
441
+ this.event(state, job, caller.attemptId, change.type, { ...change.data, ...caller });
442
+ return ticket;
443
+ });
444
+ }
445
+ /**
446
+ * Trusted adapter use only: the origin of the job whose current, unfinished attempt `attemptId` is. When the
447
+ * host reported which session runs the attempt, the caller must be that session.
448
+ */
449
+ executorOrigin(jobId, attemptId, sessionId) {
450
+ const job = Object.hasOwn(this.state.jobs, jobId) ? this.state.jobs[jobId] : undefined;
451
+ const attempt = Object.hasOwn(this.state.attempts, attemptId) ? this.state.attempts[attemptId] : undefined;
452
+ if (!job || !attempt || attempt.jobId !== jobId || job.currentAttemptId !== attemptId)
453
+ throw new TicketError('这一轮执行不是该任务的当前轮次');
454
+ if (terminal.has(attempt.executionStatus))
455
+ throw new TicketError('这一轮执行已经结束,不能再处理任务单');
456
+ const recorded = attempt.backendRunRef?.sessionId;
457
+ if (recorded !== undefined && recorded !== sessionId)
458
+ throw new TicketError('调用的会话不是执行这一轮的会话');
459
+ return job.originSessionId;
460
+ }
461
+ /** Trusted adapter use only: the job's current attempt and the session the host reported for it, for a caller that names only the job. */
462
+ currentAttempt(jobId) {
463
+ const job = Object.hasOwn(this.state.jobs, jobId) ? this.state.jobs[jobId] : undefined;
464
+ const attempt = job && Object.hasOwn(this.state.attempts, job.currentAttemptId) ? this.state.attempts[job.currentAttemptId] : undefined;
465
+ if (!attempt)
466
+ throw new TicketError('没有这个任务');
467
+ return { attemptId: attempt.attemptId, ...(attempt.backendRunRef?.sessionId !== undefined ? { sessionId: attempt.backendRunRef.sessionId } : {}) };
468
+ }
391
469
  /** Each old Task gets one legacy Job; matching context IDs never merge jobs. */
392
470
  migrateLegacy(records) {
393
471
  return this.mutate(state => records.map(record => {