@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
@@ -1,5 +1,7 @@
1
1
  export type CapacityKind = 'process' | 'task';
2
2
  export type CapacitySource = 'automatic' | 'interactive';
3
+ /** Process leases only. Missing on a record means the lease stays unlabeled. */
4
+ export type ProcessLeaseOrigin = 'prewarm' | 'job' | 'user-opened';
3
5
  export interface CapacityMemoryReading {
4
6
  totalBytes: number;
5
7
  availableBytes: number;
@@ -18,6 +20,7 @@ export interface CapacityRequest {
18
20
  kind: CapacityKind;
19
21
  source: CapacitySource;
20
22
  id: string;
23
+ origin?: ProcessLeaseOrigin;
21
24
  }
22
25
  export interface CapacityLimits {
23
26
  soft: number;
@@ -45,6 +48,22 @@ export interface CapacityLease {
45
48
  recheck(): Promise<void>;
46
49
  release(): Promise<void>;
47
50
  }
51
+ export interface CapacityProcessSession {
52
+ id: string;
53
+ ownerPid: number;
54
+ childPid?: number;
55
+ }
56
+ export interface CapacityInspection {
57
+ taskSlot: {
58
+ limit: number;
59
+ used: number;
60
+ };
61
+ processSlot: {
62
+ limit: number;
63
+ used: number;
64
+ };
65
+ sessions: Record<ProcessLeaseOrigin | 'unlabeled', CapacityProcessSession[]>;
66
+ }
48
67
  export type CapacityErrorCode = 'ACP_CAPACITY_SOFT_LIMIT' | 'ACP_CAPACITY_HARD_LIMIT' | 'ACP_CAPACITY_MEMORY_LIMIT';
49
68
  export declare class CapacityError extends Error {
50
69
  readonly code: CapacityErrorCode;
@@ -64,7 +83,13 @@ export declare class CapacityGovernor {
64
83
  constructor(options?: CapacityOptions);
65
84
  acquire(request: CapacityRequest): Promise<CapacityLease>;
66
85
  snapshot(kind: CapacityKind): Promise<CapacitySnapshot>;
86
+ /**
87
+ * Read both ledgers and process-lease origins. Does not acquire, release, or relabel.
88
+ * A missing origin stays unlabeled. Dead owners stay on disk for the next admission pass.
89
+ */
90
+ inspect(): Promise<CapacityInspection>;
67
91
  private count;
92
+ private recordedLimit;
68
93
  private readReservations;
69
94
  private reservationPath;
70
95
  private ensurePolicy;
@@ -18,6 +18,7 @@ export class CapacityError extends Error {
18
18
  this.name = 'CapacityError';
19
19
  }
20
20
  }
21
+ const processOrigins = new Set(['prewarm', 'job', 'user-opened']);
21
22
  const MiB = 1024 ** 2;
22
23
  const startupWindowMs = 30_000;
23
24
  const tokenPattern = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/;
@@ -132,10 +133,12 @@ export class CapacityGovernor {
132
133
  }
133
134
  async acquire(request) {
134
135
  if (!request || !validKind(request.kind) || !validSource(request.source) || typeof request.id !== 'string' ||
135
- !request.id.trim() || request.id.length > 4096)
136
+ !request.id.trim() || request.id.length > 4096 ||
137
+ (request.origin !== undefined && (request.kind !== 'process' || !processOrigins.has(request.origin)))) {
136
138
  throw new Error('Invalid ACP capacity request');
139
+ }
137
140
  const reservation = { version: 1, token: randomUUID(), ownerPid: process.pid, startupUntil: Date.now() + startupWindowMs,
138
- kind: request.kind, source: request.source, id: request.id };
141
+ kind: request.kind, source: request.source, id: request.id, ...(request.origin ? { origin: request.origin } : {}) };
139
142
  await this.transaction(() => {
140
143
  const records = this.readReservations();
141
144
  this.ensurePolicy(records);
@@ -210,6 +213,28 @@ export class CapacityGovernor {
210
213
  return this.count(kind, records);
211
214
  });
212
215
  }
216
+ /**
217
+ * Read both ledgers and process-lease origins. Does not acquire, release, or relabel.
218
+ * A missing origin stays unlabeled. Dead owners stay on disk for the next admission pass.
219
+ */
220
+ async inspect() {
221
+ return this.transaction(() => {
222
+ const records = this.readReservations(false);
223
+ const limit = this.recordedLimit() ?? this.limits.soft;
224
+ const sessions = { prewarm: [], job: [], 'user-opened': [], unlabeled: [] };
225
+ for (const record of records) {
226
+ if (record.kind !== 'process')
227
+ continue;
228
+ const row = { id: record.id, ownerPid: record.ownerPid, ...(record.childPid !== undefined ? { childPid: record.childPid } : {}) };
229
+ if (record.origin && processOrigins.has(record.origin))
230
+ sessions[record.origin].push(row);
231
+ else
232
+ sessions.unlabeled.push(row);
233
+ }
234
+ const used = (kind) => records.filter(record => record.kind === kind).length;
235
+ return { taskSlot: { limit, used: used('task') }, processSlot: { limit, used: used('process') }, sessions };
236
+ });
237
+ }
213
238
  count(kind, reservations, excludeStartupToken) {
214
239
  const matching = reservations.filter(item => item.kind === kind);
215
240
  const automatic = matching.filter(item => item.source === 'automatic').length;
@@ -221,10 +246,10 @@ export class CapacityGovernor {
221
246
  }
222
247
  // Pending processes retain their budget until spawn is registered. Stable leases stay counted
223
248
  // for concurrency, but actual free memory carries their cost after the startup window expires.
224
- // Share startup memory budget across kinds. Without an explicit task-to-child association,
225
- // short-lived double counting is safer than letting unrelated starts spend the same bytes.
226
- const starting = reservations.filter(item => item.token !== excludeStartupToken &&
227
- ((item.kind === 'process' && item.childPid === undefined) || item.startupUntil > Date.now()));
249
+ // Only process starts hold startup memory. A task allocates nothing itself: its ACP agent is
250
+ // admitted as a process, so counting the task too would charge the same start twice.
251
+ const starting = reservations.filter(item => item.token !== excludeStartupToken && item.kind === 'process' &&
252
+ (item.childPid === undefined || item.startupUntil > Date.now()));
228
253
  const startupReservedBytes = starting.length * this.estimatedInstanceBytes;
229
254
  const availableForStartupBytes = Math.max(0, reading.availableBytes - this.memoryReserveBytes - startupReservedBytes);
230
255
  const availableSlots = Math.floor(availableForStartupBytes / this.estimatedInstanceBytes);
@@ -234,7 +259,20 @@ export class CapacityGovernor {
234
259
  memory: { ...reading, source: reading.source ?? 'host-provider', reserveBytes: this.memoryReserveBytes, estimatedInstanceBytes: this.estimatedInstanceBytes,
235
260
  startupReservedBytes, availableForStartupBytes, availableSlots, startupWindowMs } };
236
261
  }
237
- readReservations() {
262
+ recordedLimit() {
263
+ try {
264
+ const value = this.readJson(join(this.directory, 'policy.json'));
265
+ if (!value || value.version !== 1 || !Number.isSafeInteger(value.softLimit) || value.softLimit < 1)
266
+ throw new Error(stateMessage);
267
+ return value.softLimit;
268
+ }
269
+ catch (error) {
270
+ if (error.code === 'ENOENT')
271
+ return undefined;
272
+ throw error;
273
+ }
274
+ }
275
+ readReservations(reclaim = true) {
238
276
  const records = [];
239
277
  for (const name of readdirSync(this.directory)) {
240
278
  if (name === '.lock' || name === 'policy.json')
@@ -259,7 +297,7 @@ export class CapacityGovernor {
259
297
  // An unregistered process may have spawned just before its owner crashed. Never guess it dead.
260
298
  const reclaimable = isDead(record.ownerPid) &&
261
299
  (record.kind === 'task' || (record.childPid !== undefined && isDead(record.childPid)));
262
- if (reclaimable)
300
+ if (reclaim && reclaimable)
263
301
  unlinkSync(path);
264
302
  else
265
303
  records.push(record);
@@ -313,7 +351,8 @@ export class CapacityGovernor {
313
351
  !pidIsValid(value.ownerPid) || !validKind(value.kind) || !validSource(value.source) ||
314
352
  typeof value.id !== 'string' || !value.id.trim() || value.id.length > 4096 ||
315
353
  !Number.isSafeInteger(value.startupUntil) || value.startupUntil < 0 ||
316
- (value.childPid !== undefined && (!pidIsValid(value.childPid) || value.kind !== 'process')))
354
+ (value.childPid !== undefined && (!pidIsValid(value.childPid) || value.kind !== 'process')) ||
355
+ (value.origin !== undefined && (value.kind !== 'process' || !processOrigins.has(value.origin))))
317
356
  throw new Error(stateMessage);
318
357
  return value;
319
358
  }
package/dist/src/dsh.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /** Host services are requested only when DSH activates this package as a plugin. */
2
2
  export const name = 'oneagents-acp';
3
- export const inject = ['llm', 'agents', 'approval', 'userQuestions', 'commands', 'sessionProjections', 'webServer', 'sessionController', 'agentPresets', 'sessions', 'sessionPersistence', 'workspaceRegistry'];
3
+ export const inject = ['llm', 'agents', 'approval', 'userQuestions', 'commands', 'sessionProjections', 'webServer', 'sessionController', 'agentPresets', 'sessions', 'sessionPersistence', 'workspaceRegistry', 'tools', 'connection'];
4
4
  /** Keep the service API usable without loading plugin code or DSH declarations.
5
5
  * The fully typed plugin entry is available from /dsh. */
6
6
  export async function apply(ctx, input = {}) {
@@ -0,0 +1,25 @@
1
+ export declare const AGENT_FILE_MAX_BYTES: number;
2
+ export declare const agentNamePattern: RegExp;
3
+ export interface AgentDefinition {
4
+ name: string;
5
+ description?: string;
6
+ /** Real path of the Markdown file. */
7
+ file: string;
8
+ /** The Markdown body after the frontmatter: the role's instructions. */
9
+ body: string;
10
+ sha256: string;
11
+ }
12
+ /** Reads the top-level `key: value` lines of a leading `---` block. Nested YAML is not needed for name and description. */
13
+ export declare function parseAgentMarkdown(text: string): {
14
+ fields: Record<string, string>;
15
+ body: string;
16
+ };
17
+ /**
18
+ * Read one agent file that must stay inside `root` after symlinks resolve.
19
+ * The frontmatter `name` must be a valid agent name; the body must not be empty.
20
+ */
21
+ export declare function readAgentFile(file: string, root: string): Promise<AgentDefinition>;
22
+ /** List `<root>/agents/*.md` in name order. Names must be unique within the directory. */
23
+ export declare function listAgentFiles(root: string): Promise<AgentDefinition[]>;
24
+ /** The prompt prefix a host prepends to a path agent's first message. */
25
+ export declare function agentPromptPrefix(agent: AgentDefinition): string;
@@ -0,0 +1,90 @@
1
+ /** Plugin-style agent definitions, the format Claude Code and Grok load natively: `<root>/agents/*.md`, Markdown with a frontmatter header. */
2
+ import { createHash } from 'node:crypto';
3
+ import { constants } from 'node:fs';
4
+ import { lstat, open, readdir, realpath } from 'node:fs/promises';
5
+ import path from 'node:path';
6
+ export const AGENT_FILE_MAX_BYTES = 64 * 1024;
7
+ const MAX_AGENT_FILES = 100;
8
+ export const agentNamePattern = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
9
+ const within = (root, value) => {
10
+ const relative = path.relative(root, value);
11
+ return relative !== '' && relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
12
+ };
13
+ /** Reads the top-level `key: value` lines of a leading `---` block. Nested YAML is not needed for name and description. */
14
+ export function parseAgentMarkdown(text) {
15
+ const normalized = text.replace(/^/, '').replace(/\r\n/g, '\n');
16
+ const match = /^---\n([\s\S]*?)\n---(?:\n|$)/.exec(normalized);
17
+ if (!match)
18
+ return { fields: {}, body: normalized.trim() };
19
+ const fields = {};
20
+ for (const line of match[1].split('\n')) {
21
+ const pair = /^([A-Za-z][A-Za-z0-9_-]*):\s*(.*)$/.exec(line);
22
+ if (!pair)
23
+ continue;
24
+ let value = pair[2].trim();
25
+ if (value.length >= 2 && ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))))
26
+ value = value.slice(1, -1);
27
+ fields[pair[1]] = value;
28
+ }
29
+ return { fields, body: normalized.slice(match[0].length).trim() };
30
+ }
31
+ /**
32
+ * Read one agent file that must stay inside `root` after symlinks resolve.
33
+ * The frontmatter `name` must be a valid agent name; the body must not be empty.
34
+ */
35
+ export async function readAgentFile(file, root) {
36
+ const actualRoot = await realpath(root), actual = await realpath(file);
37
+ if (!within(actualRoot, actual) || path.extname(actual) !== '.md')
38
+ throw new Error('Agent file must be a .md file inside its directory');
39
+ const handle = await open(actual, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
40
+ let bytes;
41
+ try {
42
+ const info = await handle.stat();
43
+ if (!info.isFile() || info.size > AGENT_FILE_MAX_BYTES)
44
+ throw new Error(`Agent file must be a regular file of at most ${AGENT_FILE_MAX_BYTES} bytes`);
45
+ bytes = await handle.readFile();
46
+ }
47
+ finally {
48
+ await handle.close();
49
+ }
50
+ const { fields, body } = parseAgentMarkdown(bytes.toString('utf8'));
51
+ const name = fields.name ?? path.basename(actual, '.md');
52
+ if (!agentNamePattern.test(name))
53
+ throw new Error(`Invalid agent name in ${path.basename(actual)}`);
54
+ if (!body)
55
+ throw new Error(`Agent file ${path.basename(actual)} has no instructions`);
56
+ return { name, ...(fields.description ? { description: fields.description } : {}), file: actual, body,
57
+ sha256: createHash('sha256').update(bytes).digest('hex') };
58
+ }
59
+ /** List `<root>/agents/*.md` in name order. Names must be unique within the directory. */
60
+ export async function listAgentFiles(root) {
61
+ if (!path.isAbsolute(root))
62
+ throw new Error('Agent path must be absolute');
63
+ const actualRoot = await realpath(root);
64
+ if (!(await lstat(actualRoot)).isDirectory())
65
+ throw new Error('Agent path must be a directory');
66
+ const directory = path.join(actualRoot, 'agents');
67
+ let entries;
68
+ try {
69
+ entries = await readdir(directory, { withFileTypes: true });
70
+ }
71
+ catch (error) {
72
+ if (error.code === 'ENOENT')
73
+ throw new Error('No agents/ directory under this path');
74
+ throw error;
75
+ }
76
+ const files = entries.filter(entry => entry.name.endsWith('.md') && (entry.isFile() || entry.isSymbolicLink())).map(entry => entry.name).sort();
77
+ if (files.length > MAX_AGENT_FILES)
78
+ throw new Error(`At most ${MAX_AGENT_FILES} agent files are supported`);
79
+ const agents = [];
80
+ for (const name of files)
81
+ agents.push(await readAgentFile(path.join(directory, name), actualRoot));
82
+ const names = agents.map(agent => agent.name);
83
+ if (new Set(names).size !== names.length)
84
+ throw new Error('Agent names must be unique within agents/');
85
+ return agents;
86
+ }
87
+ /** The prompt prefix a host prepends to a path agent's first message. */
88
+ export function agentPromptPrefix(agent) {
89
+ return `宿主已按路径加载智能体 ${agent.name}(${agent.file})。以下是它的角色说明:\n\n${agent.body}\n\n上游任务:\n`;
90
+ }
@@ -0,0 +1,164 @@
1
+ import { z } from 'zod';
2
+ export declare const agentOptionSchema: z.ZodObject<{
3
+ id: z.ZodString;
4
+ value: z.ZodString;
5
+ model: z.ZodOptional<z.ZodLiteral<true>>;
6
+ }, z.core.$strict>;
7
+ export type AgentOption = z.output<typeof agentOptionSchema>;
8
+ /** Where a path-registered agent came from: the registered directory and its agents/*.md file. */
9
+ export declare const agentSourceSchema: z.ZodObject<{
10
+ path: z.ZodString;
11
+ file: z.ZodString;
12
+ }, z.core.$strict>;
13
+ export type AgentSource = z.output<typeof agentSourceSchema>;
14
+ export declare const agentDraftSchema: z.ZodObject<{
15
+ agentId: z.ZodString;
16
+ name: z.ZodString;
17
+ acpAgent: z.ZodOptional<z.ZodString>;
18
+ agentPreset: z.ZodOptional<z.ZodString>;
19
+ provider: z.ZodOptional<z.ZodString>;
20
+ model: z.ZodOptional<z.ZodString>;
21
+ roleId: z.ZodOptional<z.ZodString>;
22
+ targetId: z.ZodOptional<z.ZodString>;
23
+ modeId: z.ZodOptional<z.ZodString>;
24
+ options: z.ZodArray<z.ZodObject<{
25
+ id: z.ZodString;
26
+ value: z.ZodString;
27
+ model: z.ZodOptional<z.ZodLiteral<true>>;
28
+ }, z.core.$strict>>;
29
+ source: z.ZodOptional<z.ZodObject<{
30
+ path: z.ZodString;
31
+ file: z.ZodString;
32
+ }, z.core.$strict>>;
33
+ description: z.ZodOptional<z.ZodString>;
34
+ updatedAt: z.ZodString;
35
+ }, z.core.$strict>;
36
+ export declare const agentReleaseSchema: z.ZodObject<{
37
+ releaseName: z.ZodString;
38
+ sourceAgentId: z.ZodOptional<z.ZodString>;
39
+ acpAgent: z.ZodOptional<z.ZodString>;
40
+ agentPreset: z.ZodOptional<z.ZodString>;
41
+ provider: z.ZodOptional<z.ZodString>;
42
+ model: z.ZodOptional<z.ZodString>;
43
+ roleId: z.ZodOptional<z.ZodString>;
44
+ targetId: z.ZodOptional<z.ZodString>;
45
+ modeId: z.ZodOptional<z.ZodString>;
46
+ options: z.ZodArray<z.ZodObject<{
47
+ id: z.ZodString;
48
+ value: z.ZodString;
49
+ model: z.ZodOptional<z.ZodLiteral<true>>;
50
+ }, z.core.$strict>>;
51
+ source: z.ZodOptional<z.ZodObject<{
52
+ path: z.ZodString;
53
+ file: z.ZodString;
54
+ }, z.core.$strict>>;
55
+ description: z.ZodOptional<z.ZodString>;
56
+ publishedAt: z.ZodString;
57
+ }, z.core.$strict>;
58
+ export type AgentDraft = z.output<typeof agentDraftSchema>;
59
+ export type AgentRelease = z.output<typeof agentReleaseSchema>;
60
+ export interface DevelopmentAdmission {
61
+ agentId: string;
62
+ name: string;
63
+ phase: 'developing' | 'published';
64
+ channel: 'trial' | 'formal';
65
+ }
66
+ export interface ResidentAgentRef {
67
+ targetId: string;
68
+ name: string;
69
+ roleId?: string;
70
+ agentPreset?: string;
71
+ }
72
+ export interface AgentTaskRef {
73
+ agentId?: string;
74
+ pendingReviewId?: string;
75
+ pendingProcessRequestId?: string;
76
+ }
77
+ export interface WorkbenchAgentRow {
78
+ agentId: string;
79
+ name: string;
80
+ phase: 'developing' | 'published';
81
+ origin: 'draft' | 'release' | 'resident';
82
+ acpAgent?: string;
83
+ roleId?: string;
84
+ targetId?: string;
85
+ agentPreset?: string;
86
+ provider?: string;
87
+ model?: string;
88
+ modeId?: string;
89
+ options: AgentOption[];
90
+ source?: AgentSource;
91
+ description?: string;
92
+ releaseName?: string;
93
+ sourceAgentId?: string;
94
+ counterpartId?: string;
95
+ taskCount: number;
96
+ pendingCount: number;
97
+ }
98
+ export declare class AgentRegistryError extends Error {
99
+ readonly code: 'invalid' | 'not_found' | 'conflict';
100
+ constructor(message: string, code: 'invalid' | 'not_found' | 'conflict');
101
+ }
102
+ /** Model options stay ahead of the other accepted values. */
103
+ export declare function orderAgentOptions(options: readonly AgentOption[]): AgentOption[];
104
+ export declare function readDevelopment(value: unknown): DevelopmentAdmission | undefined;
105
+ export interface TaskDevelopment {
106
+ channel: 'trial' | 'formal' | 'standalone';
107
+ agentId?: string;
108
+ name?: string;
109
+ phase?: 'developing' | 'published';
110
+ }
111
+ /** A frozen admission wins. An unstamped resident target is already published. */
112
+ export declare function describeTaskDevelopment(raw: unknown, target: {
113
+ targetId: string;
114
+ resident: boolean;
115
+ residentName?: string;
116
+ }): TaskDevelopment;
117
+ export declare function projectWorkbenchAgents(catalog: {
118
+ drafts: readonly AgentDraft[];
119
+ releases: readonly AgentRelease[];
120
+ residents: readonly ResidentAgentRef[];
121
+ }, tasks: readonly AgentTaskRef[]): {
122
+ developing: WorkbenchAgentRow[];
123
+ published: WorkbenchAgentRow[];
124
+ };
125
+ export declare class AgentRegistry {
126
+ private readonly file;
127
+ private state;
128
+ constructor(directory: string);
129
+ snapshot(): {
130
+ drafts: AgentDraft[];
131
+ releases: AgentRelease[];
132
+ };
133
+ /** New calls use a release when one owns the target, then a draft, then an already resident role. */
134
+ admit(target: {
135
+ targetId: string;
136
+ kind: string;
137
+ name: string;
138
+ }): DevelopmentAdmission | undefined;
139
+ create(input: unknown): AgentDraft;
140
+ update(agentId: string, input: unknown): AgentDraft;
141
+ /** Copy the draft into a callable name. The draft remains, and its target moves to the release. */
142
+ publish(agentId: string, input: unknown): AgentRelease;
143
+ /** The draft registered from this agents/*.md file for this runtime: an ACP agent name or a DSH-native preset. */
144
+ pathDraft(file: string, runtime: string): AgentDraft | undefined;
145
+ /**
146
+ * Create or refresh the draft for one agents/*.md file on one runtime. The file and runtime identify the draft, so
147
+ * registering the same path again updates it in place and keeps its tasks, while another runtime gets its own draft.
148
+ * A different draft already using the name is a conflict.
149
+ */
150
+ registerPathDraft(input: {
151
+ name: string;
152
+ targetId: string;
153
+ source: AgentSource;
154
+ description?: string;
155
+ acpAgent?: string;
156
+ agentPreset?: string;
157
+ provider?: string;
158
+ model?: string;
159
+ }): AgentDraft;
160
+ private draft;
161
+ private parse;
162
+ private assertUnique;
163
+ private commit;
164
+ }