mayura 0.1.0-dev.0 → 1.0.0-rc.2

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 (578) hide show
  1. package/README.md +152 -35
  2. package/docs/README.md +82 -0
  3. package/docs/ai-agents.md +73 -0
  4. package/docs/cli/dev.md +111 -0
  5. package/docs/cli/init.md +192 -0
  6. package/docs/cli/operations.md +235 -0
  7. package/docs/cli/overview.md +129 -0
  8. package/docs/cli/run.md +182 -0
  9. package/docs/concepts/agent.md +197 -0
  10. package/docs/concepts/costs-and-budgets.md +177 -0
  11. package/docs/concepts/outcomes.md +154 -0
  12. package/docs/concepts/permissions.md +155 -0
  13. package/docs/concepts/runtime.md +172 -0
  14. package/docs/concepts/tools.md +202 -0
  15. package/docs/concepts/workflows.md +134 -0
  16. package/docs/guides/approvals-and-human-input.md +278 -0
  17. package/docs/guides/artifacts.md +123 -0
  18. package/docs/guides/child-agents.md +158 -0
  19. package/docs/guides/code-mode.md +233 -0
  20. package/docs/guides/deployment.md +644 -0
  21. package/docs/guides/durable-workflows.md +463 -0
  22. package/docs/guides/guardrails.md +205 -0
  23. package/docs/guides/helpers.md +176 -0
  24. package/docs/guides/lifecycle-hooks.md +187 -0
  25. package/docs/guides/mcp.md +123 -0
  26. package/docs/guides/memory-and-context.md +293 -0
  27. package/docs/guides/model-providers.md +371 -0
  28. package/docs/guides/model-routing.md +138 -0
  29. package/docs/guides/observability.md +238 -0
  30. package/docs/guides/operator-console.md +140 -0
  31. package/docs/guides/react.md +276 -0
  32. package/docs/guides/sagas-and-loops.md +212 -0
  33. package/docs/guides/server-and-client.md +559 -0
  34. package/docs/guides/skills.md +152 -0
  35. package/docs/guides/storage.md +251 -0
  36. package/docs/guides/streaming.md +146 -0
  37. package/docs/guides/terminal.md +166 -0
  38. package/docs/guides/testing.md +220 -0
  39. package/docs/guides/vision.md +155 -0
  40. package/docs/guides/webhooks.md +172 -0
  41. package/docs/guides/workflow-composition.md +141 -0
  42. package/docs/guides/workflow-operations.md +269 -0
  43. package/docs/installation.md +90 -0
  44. package/docs/introduction.md +74 -0
  45. package/docs/project/credits.md +78 -0
  46. package/docs/project/security.md +178 -0
  47. package/docs/project/support.md +91 -0
  48. package/docs/project/versioning.md +122 -0
  49. package/docs/quickstart.md +190 -0
  50. package/docs/reference/entry-points.md +146 -0
  51. package/lib/adapter-code-docker/dist/index.d.ts +8 -1
  52. package/lib/adapter-code-docker/dist/index.d.ts.map +1 -1
  53. package/lib/adapter-code-docker/dist/index.js +64 -67
  54. package/lib/adapter-code-docker/dist/index.js.map +1 -1
  55. package/lib/adapter-code-docker/dist/options.d.ts +15 -0
  56. package/lib/adapter-code-docker/dist/options.d.ts.map +1 -0
  57. package/lib/adapter-code-docker/dist/options.js +56 -0
  58. package/lib/adapter-code-docker/dist/options.js.map +1 -0
  59. package/lib/adapter-code-docker/image/Dockerfile +4 -2
  60. package/lib/adapter-code-docker/package.json +1 -1
  61. package/lib/adapter-code-docker/src/index.ts +63 -65
  62. package/lib/adapter-code-docker/src/options.ts +51 -0
  63. package/lib/adapter-code-quickjs/dist/index.d.ts +16 -4
  64. package/lib/adapter-code-quickjs/dist/index.d.ts.map +1 -1
  65. package/lib/adapter-code-quickjs/dist/index.js +94 -50
  66. package/lib/adapter-code-quickjs/dist/index.js.map +1 -1
  67. package/lib/adapter-code-quickjs/dist/worker-command.d.ts +27 -0
  68. package/lib/adapter-code-quickjs/dist/worker-command.d.ts.map +1 -0
  69. package/lib/adapter-code-quickjs/dist/worker-command.js +66 -0
  70. package/lib/adapter-code-quickjs/dist/worker-command.js.map +1 -0
  71. package/lib/adapter-code-quickjs/dist/worker.js +421 -104
  72. package/lib/adapter-code-quickjs/dist/worker.js.map +1 -1
  73. package/lib/adapter-code-quickjs/package.json +1 -1
  74. package/lib/adapter-code-quickjs/src/index.ts +88 -44
  75. package/lib/adapter-code-quickjs/src/worker-command.ts +68 -0
  76. package/lib/adapter-code-quickjs/src/worker.ts +315 -89
  77. package/lib/adapter-mcp/package.json +1 -1
  78. package/lib/artifacts/dist/contracts.d.ts +6 -2
  79. package/lib/artifacts/dist/contracts.d.ts.map +1 -1
  80. package/lib/artifacts/dist/contracts.js.map +1 -1
  81. package/lib/artifacts/dist/index.d.ts +1 -0
  82. package/lib/artifacts/dist/index.d.ts.map +1 -1
  83. package/lib/artifacts/dist/index.js +1 -0
  84. package/lib/artifacts/dist/index.js.map +1 -1
  85. package/lib/artifacts/dist/local-store.d.ts.map +1 -1
  86. package/lib/artifacts/dist/local-store.js +4 -7
  87. package/lib/artifacts/dist/local-store.js.map +1 -1
  88. package/lib/artifacts/dist/media.d.ts +11 -0
  89. package/lib/artifacts/dist/media.d.ts.map +1 -0
  90. package/lib/artifacts/dist/media.js +18 -0
  91. package/lib/artifacts/dist/media.js.map +1 -0
  92. package/lib/artifacts/package.json +1 -1
  93. package/lib/artifacts/src/contracts.ts +6 -2
  94. package/lib/artifacts/src/index.ts +1 -0
  95. package/lib/artifacts/src/local-store.ts +5 -7
  96. package/lib/artifacts/src/media.ts +20 -0
  97. package/lib/cli/dist/agent-guide.d.ts +10 -0
  98. package/lib/cli/dist/agent-guide.d.ts.map +1 -0
  99. package/lib/cli/dist/agent-guide.js +48 -0
  100. package/lib/cli/dist/agent-guide.js.map +1 -0
  101. package/lib/cli/dist/application.d.ts +24 -0
  102. package/lib/cli/dist/application.d.ts.map +1 -1
  103. package/lib/cli/dist/application.js +21 -0
  104. package/lib/cli/dist/application.js.map +1 -1
  105. package/lib/cli/dist/bin.js +26 -6
  106. package/lib/cli/dist/bin.js.map +1 -1
  107. package/lib/cli/dist/dev.d.ts.map +1 -1
  108. package/lib/cli/dist/dev.js +7 -1
  109. package/lib/cli/dist/dev.js.map +1 -1
  110. package/lib/cli/dist/index.d.ts +3 -3
  111. package/lib/cli/dist/index.d.ts.map +1 -1
  112. package/lib/cli/dist/index.js +19 -9
  113. package/lib/cli/dist/index.js.map +1 -1
  114. package/lib/cli/dist/interactive.d.ts.map +1 -1
  115. package/lib/cli/dist/interactive.js +52 -11
  116. package/lib/cli/dist/interactive.js.map +1 -1
  117. package/lib/cli/dist/operations.d.ts +25 -2
  118. package/lib/cli/dist/operations.d.ts.map +1 -1
  119. package/lib/cli/dist/operations.js +125 -12
  120. package/lib/cli/dist/operations.js.map +1 -1
  121. package/lib/cli/dist/output.d.ts.map +1 -1
  122. package/lib/cli/dist/output.js +3 -0
  123. package/lib/cli/dist/output.js.map +1 -1
  124. package/lib/cli/dist/providers.d.ts +34 -4
  125. package/lib/cli/dist/providers.d.ts.map +1 -1
  126. package/lib/cli/dist/providers.js +26 -5
  127. package/lib/cli/dist/providers.js.map +1 -1
  128. package/lib/cli/package.json +1 -1
  129. package/lib/cli/src/agent-guide.ts +47 -0
  130. package/lib/cli/src/application.ts +24 -0
  131. package/lib/cli/src/bin.ts +22 -5
  132. package/lib/cli/src/dev.ts +5 -1
  133. package/lib/cli/src/index.ts +18 -10
  134. package/lib/cli/src/interactive.ts +44 -12
  135. package/lib/cli/src/operations.ts +82 -12
  136. package/lib/cli/src/output.ts +3 -0
  137. package/lib/cli/src/providers.ts +45 -10
  138. package/lib/cli/starters/approval-workflow/dot-env.example +11 -0
  139. package/lib/cli/starters/approval-workflow/package.json +1 -2
  140. package/lib/cli/starters/approval-workflow/src/config.ts +25 -7
  141. package/lib/cli/starters/approval-workflow/src/intake.ts +1 -2
  142. package/lib/cli/starters/approval-workflow/src/model.ts +11 -4
  143. package/lib/cli/starters/approval-workflow/src/workflow.ts +1 -2
  144. package/lib/cli/starters/cli-agent/README.md +121 -0
  145. package/lib/cli/starters/cli-agent/dot-env.example +37 -0
  146. package/lib/cli/starters/cli-agent/dot-github/workflows/ci.yml +13 -0
  147. package/lib/cli/starters/cli-agent/dot-gitignore +10 -0
  148. package/lib/cli/starters/cli-agent/mayura.project.json +15 -0
  149. package/lib/cli/starters/cli-agent/package.json +28 -0
  150. package/lib/cli/starters/cli-agent/skills/release-notes/SKILL.md +18 -0
  151. package/lib/cli/starters/cli-agent/skills/release-notes/references/example.md +12 -0
  152. package/lib/cli/starters/cli-agent/src/assistant.ts +124 -0
  153. package/lib/cli/starters/cli-agent/src/cli.ts +72 -0
  154. package/lib/cli/starters/cli-agent/src/config.ts +117 -0
  155. package/lib/cli/starters/cli-agent/src/model.ts +34 -0
  156. package/lib/cli/starters/cli-agent/src/workspace.ts +170 -0
  157. package/lib/cli/starters/cli-agent/test/assistant.test.ts +205 -0
  158. package/lib/cli/starters/cli-agent/tsconfig.json +20 -0
  159. package/lib/cli/starters/event-automation/README.md +4 -3
  160. package/lib/cli/starters/event-automation/dot-env.example +11 -0
  161. package/lib/cli/starters/event-automation/package.json +1 -2
  162. package/lib/cli/starters/event-automation/src/config.ts +25 -7
  163. package/lib/cli/starters/event-automation/src/ingress.ts +3 -5
  164. package/lib/cli/starters/event-automation/src/model.ts +11 -4
  165. package/lib/cli/starters/event-automation/src/send-sample.ts +1 -1
  166. package/lib/cli/starters/event-automation/src/tracker/main.ts +1 -1
  167. package/lib/cli/starters/event-automation/src/tracker/mcp-server.ts +1 -1
  168. package/lib/cli/starters/event-automation/src/tracker/tickets.ts +1 -1
  169. package/lib/cli/starters/event-automation/src/tracker-tools.ts +1 -1
  170. package/lib/cli/starters/event-automation/src/triage.ts +15 -22
  171. package/lib/cli/starters/event-automation/src/workflows.ts +1 -1
  172. package/lib/cli/starters/event-automation/test/automation.test.ts +3 -3
  173. package/lib/cli/starters/research-team/README.md +2 -2
  174. package/lib/cli/starters/research-team/dot-env.example +11 -0
  175. package/lib/cli/starters/research-team/package.json +1 -2
  176. package/lib/cli/starters/research-team/src/config.ts +25 -7
  177. package/lib/cli/starters/research-team/src/desk.ts +1 -2
  178. package/lib/cli/starters/research-team/src/library/index.ts +1 -2
  179. package/lib/cli/starters/research-team/src/model.ts +11 -4
  180. package/lib/cli/starters/research-team/src/services.ts +1 -1
  181. package/lib/cli/starters/research-team/src/team.ts +1 -2
  182. package/lib/cli/starters/research-team/src/workflow.ts +45 -59
  183. package/lib/cli/starters/support-agent/dot-env.example +11 -0
  184. package/lib/cli/starters/support-agent/package.json +1 -2
  185. package/lib/cli/starters/support-agent/src/assistant.ts +5 -5
  186. package/lib/cli/starters/support-agent/src/config.ts +25 -7
  187. package/lib/cli/starters/support-agent/src/guardrails.ts +3 -1
  188. package/lib/cli/starters/support-agent/src/model.ts +11 -4
  189. package/lib/cli/starters/support-agent/src/returns.ts +1 -2
  190. package/lib/cli/starters/support-agent/test/support.test.ts +25 -1
  191. package/lib/cli/templates/basic-agent.ts +1 -2
  192. package/lib/cli/templates/capability-policy.ts +1 -2
  193. package/lib/cli/templates/code-mode-workflow.ts +1 -1
  194. package/lib/cli/templates/durable-approval.ts +1 -1
  195. package/lib/cli/templates/parallel-research.ts +1 -2
  196. package/lib/cli/templates/typed-tool-runner.ts +1 -2
  197. package/lib/client/dist/forms.d.ts.map +1 -1
  198. package/lib/client/dist/forms.js +3 -4
  199. package/lib/client/dist/forms.js.map +1 -1
  200. package/lib/client/dist/headless.d.ts +3 -1
  201. package/lib/client/dist/headless.d.ts.map +1 -1
  202. package/lib/client/dist/headless.js +10 -6
  203. package/lib/client/dist/headless.js.map +1 -1
  204. package/lib/client/dist/index.d.ts +95 -6
  205. package/lib/client/dist/index.d.ts.map +1 -1
  206. package/lib/client/dist/index.js +397 -124
  207. package/lib/client/dist/index.js.map +1 -1
  208. package/lib/client/dist/workflows.d.ts +1 -1
  209. package/lib/client/dist/workflows.d.ts.map +1 -1
  210. package/lib/client/dist/workflows.js +7 -6
  211. package/lib/client/dist/workflows.js.map +1 -1
  212. package/lib/client/package.json +1 -1
  213. package/lib/client/src/forms.ts +3 -4
  214. package/lib/client/src/headless.ts +13 -7
  215. package/lib/client/src/index.ts +344 -74
  216. package/lib/client/src/workflows.ts +8 -7
  217. package/lib/client-react/package.json +1 -1
  218. package/lib/code-mode/dist/index.d.ts +32 -1
  219. package/lib/code-mode/dist/index.d.ts.map +1 -1
  220. package/lib/code-mode/dist/index.js +289 -221
  221. package/lib/code-mode/dist/index.js.map +1 -1
  222. package/lib/code-mode/package.json +1 -1
  223. package/lib/code-mode/src/index.ts +288 -184
  224. package/lib/code-mode-workflows/package.json +1 -1
  225. package/lib/context/package.json +1 -1
  226. package/lib/core/dist/budget.d.ts.map +1 -1
  227. package/lib/core/dist/budget.js +17 -2
  228. package/lib/core/dist/budget.js.map +1 -1
  229. package/lib/core/dist/contracts.d.ts +57 -0
  230. package/lib/core/dist/contracts.d.ts.map +1 -1
  231. package/lib/core/dist/contracts.js +36 -0
  232. package/lib/core/dist/contracts.js.map +1 -1
  233. package/lib/core/dist/destination.d.ts +12 -0
  234. package/lib/core/dist/destination.d.ts.map +1 -0
  235. package/lib/core/dist/destination.js +37 -0
  236. package/lib/core/dist/destination.js.map +1 -0
  237. package/lib/core/dist/event-stream.d.ts +1 -1
  238. package/lib/core/dist/event-stream.d.ts.map +1 -1
  239. package/lib/core/dist/event-stream.js +7 -0
  240. package/lib/core/dist/event-stream.js.map +1 -1
  241. package/lib/core/dist/host.d.ts +3 -0
  242. package/lib/core/dist/host.d.ts.map +1 -1
  243. package/lib/core/dist/host.js +3 -0
  244. package/lib/core/dist/host.js.map +1 -1
  245. package/lib/core/dist/index.d.ts +2 -0
  246. package/lib/core/dist/index.d.ts.map +1 -1
  247. package/lib/core/dist/index.js +2 -0
  248. package/lib/core/dist/index.js.map +1 -1
  249. package/lib/core/dist/media.d.ts +98 -0
  250. package/lib/core/dist/media.d.ts.map +1 -0
  251. package/lib/core/dist/media.js +227 -0
  252. package/lib/core/dist/media.js.map +1 -0
  253. package/lib/core/dist/model-schema.d.ts +37 -0
  254. package/lib/core/dist/model-schema.d.ts.map +1 -0
  255. package/lib/core/dist/model-schema.js +154 -0
  256. package/lib/core/dist/model-schema.js.map +1 -0
  257. package/lib/core/package.json +1 -1
  258. package/lib/core/src/budget.ts +17 -2
  259. package/lib/core/src/contracts.ts +71 -3
  260. package/lib/core/src/destination.ts +33 -0
  261. package/lib/core/src/event-stream.ts +5 -1
  262. package/lib/core/src/host.ts +3 -0
  263. package/lib/core/src/index.ts +2 -0
  264. package/lib/core/src/media.ts +228 -0
  265. package/lib/core/src/model-schema.ts +129 -0
  266. package/lib/exporter-otlp/dist/otlp-http-json.js +1 -1
  267. package/lib/exporter-otlp/dist/otlp-http-json.js.map +1 -1
  268. package/lib/exporter-otlp/dist/signals.js +2 -2
  269. package/lib/exporter-otlp/dist/signals.js.map +1 -1
  270. package/lib/exporter-otlp/package.json +1 -1
  271. package/lib/exporter-otlp/src/otlp-http-json.ts +1 -1
  272. package/lib/exporter-otlp/src/signals.ts +2 -2
  273. package/lib/guardrails/package.json +1 -1
  274. package/lib/helpers/package.json +1 -1
  275. package/lib/memory/dist/index.js +1 -1
  276. package/lib/memory/dist/index.js.map +1 -1
  277. package/lib/memory/dist/native.d.ts.map +1 -1
  278. package/lib/memory/dist/native.js +4 -3
  279. package/lib/memory/dist/native.js.map +1 -1
  280. package/lib/memory/package.json +1 -1
  281. package/lib/memory/src/index.ts +1 -1
  282. package/lib/memory/src/native.ts +4 -3
  283. package/lib/memory-remote/package.json +1 -1
  284. package/lib/observability/package.json +1 -1
  285. package/lib/provider-anthropic/dist/index.d.ts +36 -3
  286. package/lib/provider-anthropic/dist/index.d.ts.map +1 -1
  287. package/lib/provider-anthropic/dist/index.js +128 -78
  288. package/lib/provider-anthropic/dist/index.js.map +1 -1
  289. package/lib/provider-anthropic/package.json +1 -1
  290. package/lib/provider-anthropic/src/index.ts +152 -76
  291. package/lib/provider-openai/dist/index.d.ts +71 -4
  292. package/lib/provider-openai/dist/index.d.ts.map +1 -1
  293. package/lib/provider-openai/dist/index.js +259 -96
  294. package/lib/provider-openai/dist/index.js.map +1 -1
  295. package/lib/provider-openai/package.json +1 -1
  296. package/lib/provider-openai/src/index.ts +282 -84
  297. package/lib/runtime/dist/agent.d.ts +18 -1
  298. package/lib/runtime/dist/agent.d.ts.map +1 -1
  299. package/lib/runtime/dist/agent.js +59 -3
  300. package/lib/runtime/dist/agent.js.map +1 -1
  301. package/lib/runtime/dist/composition.d.ts.map +1 -1
  302. package/lib/runtime/dist/composition.js +2 -1
  303. package/lib/runtime/dist/composition.js.map +1 -1
  304. package/lib/runtime/dist/hooks.d.ts +15 -3
  305. package/lib/runtime/dist/hooks.d.ts.map +1 -1
  306. package/lib/runtime/dist/hooks.js.map +1 -1
  307. package/lib/runtime/dist/index.d.ts +1 -1
  308. package/lib/runtime/dist/index.d.ts.map +1 -1
  309. package/lib/runtime/dist/index.js.map +1 -1
  310. package/lib/runtime/dist/response.d.ts +7 -1
  311. package/lib/runtime/dist/response.d.ts.map +1 -1
  312. package/lib/runtime/dist/response.js +23 -2
  313. package/lib/runtime/dist/response.js.map +1 -1
  314. package/lib/runtime/dist/router.d.ts +10 -3
  315. package/lib/runtime/dist/router.d.ts.map +1 -1
  316. package/lib/runtime/dist/router.js +45 -8
  317. package/lib/runtime/dist/router.js.map +1 -1
  318. package/lib/runtime/dist/runtime.d.ts +9 -1
  319. package/lib/runtime/dist/runtime.d.ts.map +1 -1
  320. package/lib/runtime/dist/runtime.js +50 -22
  321. package/lib/runtime/dist/runtime.js.map +1 -1
  322. package/lib/runtime/package.json +1 -1
  323. package/lib/runtime/src/agent.ts +69 -3
  324. package/lib/runtime/src/composition.ts +2 -1
  325. package/lib/runtime/src/hooks.ts +10 -4
  326. package/lib/runtime/src/index.ts +1 -1
  327. package/lib/runtime/src/response.ts +20 -2
  328. package/lib/runtime/src/router.ts +43 -10
  329. package/lib/runtime/src/runtime.ts +58 -27
  330. package/lib/sdk/dist/index.d.ts +9 -1
  331. package/lib/sdk/dist/index.d.ts.map +1 -1
  332. package/lib/sdk/dist/index.js +9 -1
  333. package/lib/sdk/dist/index.js.map +1 -1
  334. package/lib/sdk/package.json +1 -1
  335. package/lib/sdk/src/index.ts +9 -1
  336. package/lib/server/dist/index.d.ts +201 -3
  337. package/lib/server/dist/index.d.ts.map +1 -1
  338. package/lib/server/dist/index.js +701 -149
  339. package/lib/server/dist/index.js.map +1 -1
  340. package/lib/server/dist/inspector-bundle.d.ts +1 -1
  341. package/lib/server/dist/inspector-bundle.d.ts.map +1 -1
  342. package/lib/server/dist/inspector-bundle.js +4 -4
  343. package/lib/server/dist/inspector-bundle.js.map +1 -1
  344. package/lib/server/package.json +1 -1
  345. package/lib/server/src/index.ts +611 -135
  346. package/lib/server/src/inspector-bundle.ts +4 -4
  347. package/lib/server-node/dist/hardening.d.ts +1 -1
  348. package/lib/server-node/dist/hardening.d.ts.map +1 -1
  349. package/lib/server-node/dist/hardening.js +4 -2
  350. package/lib/server-node/dist/hardening.js.map +1 -1
  351. package/lib/server-node/dist/index.d.ts +2 -1
  352. package/lib/server-node/dist/index.d.ts.map +1 -1
  353. package/lib/server-node/dist/index.js.map +1 -1
  354. package/lib/server-node/dist/probe.js +2 -2
  355. package/lib/server-node/dist/probe.js.map +1 -1
  356. package/lib/server-node/dist/production.d.ts +8 -1
  357. package/lib/server-node/dist/production.d.ts.map +1 -1
  358. package/lib/server-node/dist/production.js +15 -2
  359. package/lib/server-node/dist/production.js.map +1 -1
  360. package/lib/server-node/package.json +1 -1
  361. package/lib/server-node/src/hardening.ts +5 -3
  362. package/lib/server-node/src/index.ts +2 -1
  363. package/lib/server-node/src/probe.ts +2 -2
  364. package/lib/server-node/src/production.ts +23 -3
  365. package/lib/skills/dist/index.d.ts +81 -0
  366. package/lib/skills/dist/index.d.ts.map +1 -0
  367. package/lib/skills/dist/index.js +311 -0
  368. package/lib/skills/dist/index.js.map +1 -0
  369. package/lib/skills/package.json +5 -0
  370. package/lib/skills/src/index.ts +260 -0
  371. package/lib/storage/dist/index.d.ts +1 -1
  372. package/lib/storage/dist/index.d.ts.map +1 -1
  373. package/lib/storage/dist/index.js.map +1 -1
  374. package/lib/storage/package.json +1 -1
  375. package/lib/storage/src/index.ts +1 -1
  376. package/lib/storage-contracts/dist/contracts.d.ts +12 -5
  377. package/lib/storage-contracts/dist/contracts.d.ts.map +1 -1
  378. package/lib/storage-contracts/dist/contracts.js +24 -6
  379. package/lib/storage-contracts/dist/contracts.js.map +1 -1
  380. package/lib/storage-contracts/dist/index.d.ts +2 -0
  381. package/lib/storage-contracts/dist/index.d.ts.map +1 -1
  382. package/lib/storage-contracts/dist/index.js +2 -0
  383. package/lib/storage-contracts/dist/index.js.map +1 -1
  384. package/lib/storage-contracts/dist/memory-contracts.js +1 -1
  385. package/lib/storage-contracts/dist/memory-contracts.js.map +1 -1
  386. package/lib/storage-contracts/dist/run-records.d.ts +100 -0
  387. package/lib/storage-contracts/dist/run-records.d.ts.map +1 -0
  388. package/lib/storage-contracts/dist/run-records.js +464 -0
  389. package/lib/storage-contracts/dist/run-records.js.map +1 -0
  390. package/lib/storage-contracts/dist/schema-digest.d.ts +17 -0
  391. package/lib/storage-contracts/dist/schema-digest.d.ts.map +1 -0
  392. package/lib/storage-contracts/dist/schema-digest.js +94 -0
  393. package/lib/storage-contracts/dist/schema-digest.js.map +1 -0
  394. package/lib/storage-contracts/dist/submission-journal.js +1 -1
  395. package/lib/storage-contracts/dist/submission-journal.js.map +1 -1
  396. package/lib/storage-contracts/dist/workflow-format5.d.ts +30 -2
  397. package/lib/storage-contracts/dist/workflow-format5.d.ts.map +1 -1
  398. package/lib/storage-contracts/dist/workflow-format5.js +57 -5
  399. package/lib/storage-contracts/dist/workflow-format5.js.map +1 -1
  400. package/lib/storage-contracts/package.json +1 -1
  401. package/lib/storage-contracts/src/contracts.ts +29 -5
  402. package/lib/storage-contracts/src/index.ts +2 -0
  403. package/lib/storage-contracts/src/memory-contracts.ts +1 -1
  404. package/lib/storage-contracts/src/run-records.ts +365 -0
  405. package/lib/storage-contracts/src/schema-digest.ts +71 -0
  406. package/lib/storage-contracts/src/submission-journal.ts +1 -1
  407. package/lib/storage-contracts/src/workflow-format5.ts +70 -6
  408. package/lib/storage-postgres/dist/index.d.ts +1 -1
  409. package/lib/storage-postgres/dist/index.d.ts.map +1 -1
  410. package/lib/storage-postgres/dist/index.js.map +1 -1
  411. package/lib/storage-postgres/dist/postgres.d.ts +15 -0
  412. package/lib/storage-postgres/dist/postgres.d.ts.map +1 -1
  413. package/lib/storage-postgres/dist/postgres.js +18 -7
  414. package/lib/storage-postgres/dist/postgres.js.map +1 -1
  415. package/lib/storage-postgres/package.json +1 -1
  416. package/lib/storage-postgres/src/index.ts +1 -1
  417. package/lib/storage-postgres/src/postgres.ts +34 -8
  418. package/lib/storage-sql/dist/aggregate-session.js +1 -1
  419. package/lib/storage-sql/dist/aggregate-session.js.map +1 -1
  420. package/lib/storage-sql/dist/scheduled-database.js +1 -1
  421. package/lib/storage-sql/dist/scheduled-database.js.map +1 -1
  422. package/lib/storage-sql/dist/workflow-tree-validation.js +1 -1
  423. package/lib/storage-sql/dist/workflow-tree-validation.js.map +1 -1
  424. package/lib/storage-sql/package.json +1 -1
  425. package/lib/storage-sql/src/aggregate-session.ts +1 -1
  426. package/lib/storage-sql/src/scheduled-database.ts +1 -1
  427. package/lib/storage-sql/src/workflow-tree-validation.ts +1 -1
  428. package/lib/storage-sqlite/dist/sqlite-database.js +4 -4
  429. package/lib/storage-sqlite/dist/sqlite-database.js.map +1 -1
  430. package/lib/storage-sqlite/dist/sqlite-worker.js +2 -2
  431. package/lib/storage-sqlite/dist/sqlite-worker.js.map +1 -1
  432. package/lib/storage-sqlite/dist/sqlite.js +1 -1
  433. package/lib/storage-sqlite/dist/sqlite.js.map +1 -1
  434. package/lib/storage-sqlite/package.json +1 -1
  435. package/lib/storage-sqlite/src/sqlite-database.ts +4 -4
  436. package/lib/storage-sqlite/src/sqlite-worker.ts +2 -2
  437. package/lib/storage-sqlite/src/sqlite.ts +1 -1
  438. package/lib/terminal/dist/index.d.ts +92 -0
  439. package/lib/terminal/dist/index.d.ts.map +1 -0
  440. package/lib/terminal/dist/index.js +397 -0
  441. package/lib/terminal/dist/index.js.map +1 -0
  442. package/lib/terminal/package.json +5 -0
  443. package/lib/terminal/src/index.ts +273 -0
  444. package/lib/testing/dist/index.d.ts +44 -1
  445. package/lib/testing/dist/index.d.ts.map +1 -1
  446. package/lib/testing/dist/index.js +63 -10
  447. package/lib/testing/dist/index.js.map +1 -1
  448. package/lib/testing/package.json +1 -1
  449. package/lib/testing/src/index.ts +83 -10
  450. package/lib/tools/dist/index.d.ts +32 -4
  451. package/lib/tools/dist/index.d.ts.map +1 -1
  452. package/lib/tools/dist/index.js +64 -11
  453. package/lib/tools/dist/index.js.map +1 -1
  454. package/lib/tools/package.json +1 -1
  455. package/lib/tools/src/index.ts +74 -13
  456. package/lib/workflows/dist/abandoned.d.ts +15 -0
  457. package/lib/workflows/dist/abandoned.d.ts.map +1 -0
  458. package/lib/workflows/dist/abandoned.js +33 -0
  459. package/lib/workflows/dist/abandoned.js.map +1 -0
  460. package/lib/workflows/dist/agent-step.d.ts +83 -0
  461. package/lib/workflows/dist/agent-step.d.ts.map +1 -0
  462. package/lib/workflows/dist/agent-step.js +161 -0
  463. package/lib/workflows/dist/agent-step.js.map +1 -0
  464. package/lib/workflows/dist/children-runtime.js +8 -8
  465. package/lib/workflows/dist/children-runtime.js.map +1 -1
  466. package/lib/workflows/dist/composite-fleet.js +2 -2
  467. package/lib/workflows/dist/composite-fleet.js.map +1 -1
  468. package/lib/workflows/dist/composite-host.d.ts.map +1 -1
  469. package/lib/workflows/dist/composite-host.js +26 -2
  470. package/lib/workflows/dist/composite-host.js.map +1 -1
  471. package/lib/workflows/dist/hook-relay.js +2 -2
  472. package/lib/workflows/dist/hook-relay.js.map +1 -1
  473. package/lib/workflows/dist/index.d.ts +1 -1
  474. package/lib/workflows/dist/index.d.ts.map +1 -1
  475. package/lib/workflows/dist/index.js.map +1 -1
  476. package/lib/workflows/dist/leadership.js +3 -3
  477. package/lib/workflows/dist/leadership.js.map +1 -1
  478. package/lib/workflows/dist/lifecycle-definition.d.ts +26 -4
  479. package/lib/workflows/dist/lifecycle-definition.d.ts.map +1 -1
  480. package/lib/workflows/dist/lifecycle-definition.js +31 -6
  481. package/lib/workflows/dist/lifecycle-definition.js.map +1 -1
  482. package/lib/workflows/dist/lifecycle-fleet.d.ts.map +1 -1
  483. package/lib/workflows/dist/lifecycle-fleet.js +9 -11
  484. package/lib/workflows/dist/lifecycle-fleet.js.map +1 -1
  485. package/lib/workflows/dist/lifecycle-host.d.ts.map +1 -1
  486. package/lib/workflows/dist/lifecycle-host.js +26 -2
  487. package/lib/workflows/dist/lifecycle-host.js.map +1 -1
  488. package/lib/workflows/dist/lifecycle-human-transport.d.ts +22 -2
  489. package/lib/workflows/dist/lifecycle-human-transport.d.ts.map +1 -1
  490. package/lib/workflows/dist/lifecycle-human-transport.js +115 -33
  491. package/lib/workflows/dist/lifecycle-human-transport.js.map +1 -1
  492. package/lib/workflows/dist/lifecycle-runtime.d.ts +62 -1
  493. package/lib/workflows/dist/lifecycle-runtime.d.ts.map +1 -1
  494. package/lib/workflows/dist/lifecycle-runtime.js +268 -64
  495. package/lib/workflows/dist/lifecycle-runtime.js.map +1 -1
  496. package/lib/workflows/dist/lifecycle.d.ts +6 -4
  497. package/lib/workflows/dist/lifecycle.d.ts.map +1 -1
  498. package/lib/workflows/dist/lifecycle.js +2 -0
  499. package/lib/workflows/dist/lifecycle.js.map +1 -1
  500. package/lib/workflows/dist/loop-runtime.d.ts.map +1 -1
  501. package/lib/workflows/dist/loop-runtime.js +38 -26
  502. package/lib/workflows/dist/loop-runtime.js.map +1 -1
  503. package/lib/workflows/dist/migration.d.ts +1 -1
  504. package/lib/workflows/dist/migration.d.ts.map +1 -1
  505. package/lib/workflows/dist/migration.js +3 -3
  506. package/lib/workflows/dist/migration.js.map +1 -1
  507. package/lib/workflows/dist/operator-transports.d.ts +24 -2
  508. package/lib/workflows/dist/operator-transports.d.ts.map +1 -1
  509. package/lib/workflows/dist/operator-transports.js +49 -3
  510. package/lib/workflows/dist/operator-transports.js.map +1 -1
  511. package/lib/workflows/dist/runtime.d.ts.map +1 -1
  512. package/lib/workflows/dist/runtime.js +34 -22
  513. package/lib/workflows/dist/runtime.js.map +1 -1
  514. package/lib/workflows/dist/saga-runtime.d.ts.map +1 -1
  515. package/lib/workflows/dist/saga-runtime.js +44 -30
  516. package/lib/workflows/dist/saga-runtime.js.map +1 -1
  517. package/lib/workflows/dist/scheduled-helpers.d.ts.map +1 -1
  518. package/lib/workflows/dist/scheduled-helpers.js +3 -3
  519. package/lib/workflows/dist/scheduled-helpers.js.map +1 -1
  520. package/lib/workflows/dist/storage-failure.d.ts +16 -0
  521. package/lib/workflows/dist/storage-failure.d.ts.map +1 -0
  522. package/lib/workflows/dist/storage-failure.js +38 -0
  523. package/lib/workflows/dist/storage-failure.js.map +1 -0
  524. package/lib/workflows/dist/sweep-position.d.ts +22 -0
  525. package/lib/workflows/dist/sweep-position.d.ts.map +1 -0
  526. package/lib/workflows/dist/sweep-position.js +45 -0
  527. package/lib/workflows/dist/sweep-position.js.map +1 -0
  528. package/lib/workflows/dist/traces.js +2 -2
  529. package/lib/workflows/dist/traces.js.map +1 -1
  530. package/lib/workflows/dist/worker.d.ts +31 -0
  531. package/lib/workflows/dist/worker.d.ts.map +1 -1
  532. package/lib/workflows/dist/worker.js +94 -0
  533. package/lib/workflows/dist/worker.js.map +1 -1
  534. package/lib/workflows/package.json +1 -1
  535. package/lib/workflows/src/abandoned.ts +32 -0
  536. package/lib/workflows/src/agent-step.ts +199 -0
  537. package/lib/workflows/src/children-runtime.ts +8 -8
  538. package/lib/workflows/src/composite-fleet.ts +2 -2
  539. package/lib/workflows/src/composite-host.ts +21 -3
  540. package/lib/workflows/src/hook-relay.ts +2 -2
  541. package/lib/workflows/src/index.ts +2 -1
  542. package/lib/workflows/src/leadership.ts +3 -3
  543. package/lib/workflows/src/lifecycle-definition.ts +50 -9
  544. package/lib/workflows/src/lifecycle-fleet.ts +7 -8
  545. package/lib/workflows/src/lifecycle-host.ts +21 -5
  546. package/lib/workflows/src/lifecycle-human-transport.ts +110 -26
  547. package/lib/workflows/src/lifecycle-runtime.ts +270 -60
  548. package/lib/workflows/src/lifecycle.ts +7 -0
  549. package/lib/workflows/src/loop-runtime.ts +34 -25
  550. package/lib/workflows/src/migration.ts +2 -2
  551. package/lib/workflows/src/operator-transports.ts +48 -4
  552. package/lib/workflows/src/runtime.ts +28 -22
  553. package/lib/workflows/src/saga-runtime.ts +38 -28
  554. package/lib/workflows/src/scheduled-helpers.ts +3 -3
  555. package/lib/workflows/src/storage-failure.ts +37 -0
  556. package/lib/workflows/src/sweep-position.ts +52 -0
  557. package/lib/workflows/src/traces.ts +2 -2
  558. package/lib/workflows/src/worker.ts +79 -1
  559. package/lib/workstream/dist/humans.d.ts +7 -3
  560. package/lib/workstream/dist/humans.d.ts.map +1 -1
  561. package/lib/workstream/dist/humans.js +13 -2
  562. package/lib/workstream/dist/humans.js.map +1 -1
  563. package/lib/workstream/dist/index.js +2 -2
  564. package/lib/workstream/dist/index.js.map +1 -1
  565. package/lib/workstream/dist/timers.js +2 -2
  566. package/lib/workstream/dist/timers.js.map +1 -1
  567. package/lib/workstream/dist/webhooks.d.ts +6 -2
  568. package/lib/workstream/dist/webhooks.d.ts.map +1 -1
  569. package/lib/workstream/dist/webhooks.js +17 -7
  570. package/lib/workstream/dist/webhooks.js.map +1 -1
  571. package/lib/workstream/package.json +1 -1
  572. package/lib/workstream/src/humans.ts +15 -5
  573. package/lib/workstream/src/index.ts +2 -2
  574. package/lib/workstream/src/timers.ts +2 -2
  575. package/lib/workstream/src/webhooks.ts +21 -8
  576. package/llms-full.txt +9766 -0
  577. package/llms.txt +92 -0
  578. package/package.json +18 -6
@@ -0,0 +1,311 @@
1
+ // Agent skills: named bundles of instructions (and optional reference files) that an agent loads only when a task
2
+ // needs them. Folders follow the open SKILL.md format: YAML front matter with `name` and `description`, then the
3
+ // instructions in Markdown, plus any other files the instructions refer to.
4
+ //
5
+ // An agent sees only each skill's name and description (the catalog). Two read-only tools load a skill's full
6
+ // instructions and read its files on demand, so dozens of skills cost little until one is used. Skills never grant
7
+ // permissions: a tool or script a skill mentions still needs its own grant, and this package never runs scripts.
8
+ import { createHash } from 'node:crypto';
9
+ import { lstat, readdir, readFile } from 'node:fs/promises';
10
+ import { basename, join, relative, resolve, sep } from 'node:path';
11
+ import { MayuraError, freezeJson, jsonValue } from '../../core/dist/index.js';
12
+ import { defineTool } from '../../tools/dist/index.js';
13
+ const namePattern = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
14
+ const pathPattern = /^[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*$/u;
15
+ const fail = (message) => { throw new MayuraError('INVALID_CONFIG', message); };
16
+ const sha256 = (value) => createHash('sha256').update(value).digest('hex');
17
+ const canonical = (value) => {
18
+ if (value === null || typeof value !== 'object')
19
+ return JSON.stringify(value);
20
+ if (Array.isArray(value))
21
+ return `[${value.map(canonical).join(',')}]`;
22
+ return `{${Object.keys(value).sort().map(key => `${JSON.stringify(key)}:${canonical(value[key])}`).join(',')}}`;
23
+ };
24
+ function limits(options = {}) {
25
+ const pick = (value, fallback, name) => {
26
+ const result = value ?? fallback;
27
+ if (!Number.isSafeInteger(result) || result < 1)
28
+ fail(`${name} must be a positive integer.`);
29
+ return result;
30
+ };
31
+ return { maxSkills: pick(options.maxSkills, 64, 'maxSkills'), maxFilesPerSkill: pick(options.maxFilesPerSkill, 128, 'maxFilesPerSkill'),
32
+ maxFileBytes: pick(options.maxFileBytes, 262_144, 'maxFileBytes'), maxTotalBytes: pick(options.maxTotalBytes, 16_777_216, 'maxTotalBytes'),
33
+ maxCatalogBytes: pick(options.maxCatalogBytes, 16_384, 'maxCatalogBytes') };
34
+ }
35
+ /**
36
+ * The front matter of SKILL.md: a small, strict YAML subset (`key: value`, quoted values, `>`/`|` block scalars, a
37
+ * `metadata` map and an `allowed-tools` list). Unknown keys are ignored.
38
+ */
39
+ export function parseSkillFile(text, label = 'SKILL.md') {
40
+ const normalized = text.replace(/^/u, '').replace(/\r\n?/gu, '\n');
41
+ if (!normalized.startsWith('---\n'))
42
+ fail(`${label} must start with a --- front matter block.`);
43
+ const end = normalized.indexOf('\n---', 4);
44
+ if (end < 0)
45
+ fail(`${label} front matter is not closed with ---.`);
46
+ const after = normalized.slice(end + 4);
47
+ if (after && !after.startsWith('\n'))
48
+ fail(`${label} front matter must end with a --- line.`);
49
+ const lines = normalized.slice(4, end).split('\n');
50
+ const fields = {};
51
+ const scalar = (raw) => {
52
+ const value = raw.trim();
53
+ if ((value.startsWith('"') && value.endsWith('"') && value.length >= 2)) {
54
+ try {
55
+ return JSON.parse(value);
56
+ }
57
+ catch {
58
+ return fail(`${label}: invalid quoted value.`);
59
+ }
60
+ }
61
+ if (value.startsWith("'") && value.endsWith("'") && value.length >= 2)
62
+ return value.slice(1, -1).replaceAll("''", "'");
63
+ return value;
64
+ };
65
+ for (let index = 0; index < lines.length; index++) {
66
+ const line = lines[index];
67
+ if (!line.trim() || line.trimStart().startsWith('#'))
68
+ continue;
69
+ const match = /^([A-Za-z][A-Za-z0-9_-]*):(?:\s(.*)|)$/u.exec(line);
70
+ if (!match)
71
+ fail(`${label}: cannot read front matter line ${index + 1}.`);
72
+ const key = match[1];
73
+ const rest = (match[2] ?? '').trim();
74
+ const block = [];
75
+ while (index + 1 < lines.length && (/^\s+\S/u.test(lines[index + 1]) || lines[index + 1] === ''))
76
+ block.push(lines[++index]);
77
+ if (rest === '>' || rest === '|' || rest === '>-' || rest === '|-') {
78
+ const content = block.map(item => item.trim());
79
+ fields[key] = rest.startsWith('>') ? content.filter(Boolean).join(' ') : content.join('\n').trim();
80
+ }
81
+ else if (rest === '' && block.some(item => item.trim().startsWith('- '))) {
82
+ fields[key] = block.filter(item => item.trim()).map(item => { const entry = item.trim(); if (!entry.startsWith('- '))
83
+ fail(`${label}: ${key} mixes list and map entries.`); return scalar(entry.slice(2)); });
84
+ }
85
+ else if (rest === '' && block.length > 0) {
86
+ const map = {};
87
+ for (const item of block.filter(entry => entry.trim())) {
88
+ const pair = /^\s+([A-Za-z0-9_.-]+):\s*(.*)$/u.exec(item);
89
+ if (!pair)
90
+ fail(`${label}: cannot read ${key} entry "${item.trim()}".`);
91
+ map[pair[1]] = scalar(pair[2]);
92
+ }
93
+ fields[key] = map;
94
+ }
95
+ else
96
+ fields[key] = scalar(rest);
97
+ }
98
+ return { fields, body: after.replace(/^\n/u, '') };
99
+ }
100
+ /** Define a skill in code: the same shape a SKILL.md folder has. `files` maps relative paths to their text. */
101
+ export function defineSkill(options) {
102
+ const files = Object.entries(options.files ?? {}).map(([path, content]) => ({ path, content: new TextEncoder().encode(content) }));
103
+ return build({ name: options.name, description: options.description, instructions: options.instructions, license: options.license,
104
+ allowedTools: options.allowedTools, metadata: options.metadata, files }, `skill ${options.name}`).skill;
105
+ }
106
+ const contents = new WeakMap();
107
+ function build(input, label) {
108
+ const name = typeof input.name === 'string' ? input.name : fail(`${label} needs a name.`);
109
+ if (name.length > 64 || !namePattern.test(name))
110
+ fail(`${label}: the name must be lower-case letters, digits and single hyphens, up to 64 characters.`);
111
+ const description = typeof input.description === 'string' ? input.description.trim() : fail(`${label} needs a description.`);
112
+ if (!description || description.length > 1_024)
113
+ fail(`${label}: the description must be 1 to 1024 characters.`);
114
+ if (typeof input.instructions !== 'string' || !input.instructions.trim())
115
+ fail(`${label} has no instructions.`);
116
+ const license = input.license === undefined ? undefined : typeof input.license === 'string' && input.license.length <= 256 ? input.license : fail(`${label}: license must be text.`);
117
+ const allowed = input.allowedTools === undefined ? [] : typeof input.allowedTools === 'string' ? input.allowedTools.split(/[\s,]+/u).filter(Boolean)
118
+ : Array.isArray(input.allowedTools) && input.allowedTools.every(item => typeof item === 'string') ? input.allowedTools : fail(`${label}: allowed-tools must be a list.`);
119
+ const metadata = input.metadata === undefined ? {} : input.metadata !== null && typeof input.metadata === 'object' && !Array.isArray(input.metadata)
120
+ && Object.values(input.metadata).every(value => typeof value === 'string') ? input.metadata : fail(`${label}: metadata must map names to text.`);
121
+ const files = [...input.files].sort((a, b) => a.path.localeCompare(b.path));
122
+ const map = new Map();
123
+ for (const file of files) {
124
+ if (!pathPattern.test(file.path) || file.path.split('/').some(part => part === '..' || part === '.') || file.path === 'SKILL.md')
125
+ fail(`${label}: invalid file path ${JSON.stringify(file.path)}.`);
126
+ if (map.has(file.path))
127
+ fail(`${label}: duplicate file ${file.path}.`);
128
+ map.set(file.path, file.content);
129
+ }
130
+ const decoder = new TextDecoder('utf-8', { fatal: true });
131
+ const text = (bytes) => { try {
132
+ decoder.decode(bytes);
133
+ return true;
134
+ }
135
+ catch {
136
+ return false;
137
+ } };
138
+ const listed = files.map(file => Object.freeze({ path: file.path, bytes: file.content.byteLength, text: text(file.content) }));
139
+ const digest = sha256(canonical({ format: 'mayura.skill.v1', name, description, license: license ?? null, allowedTools: allowed, metadata,
140
+ instructions: input.instructions, files: files.map(file => ({ path: file.path, sha256: sha256(file.content) })) }));
141
+ const skill = Object.freeze({ name, description, instructions: input.instructions, files: Object.freeze(listed), ...(license === undefined ? {} : { license }),
142
+ allowedTools: Object.freeze([...allowed]), metadata: Object.freeze({ ...metadata }), digest });
143
+ contents.set(skill, map);
144
+ return { skill, bytes: new TextEncoder().encode(input.instructions).byteLength + files.reduce((sum, file) => sum + file.content.byteLength, 0) };
145
+ }
146
+ /**
147
+ * Load skills from folders. Each source is either one skill folder (it has a SKILL.md) or a folder of skill folders.
148
+ * Everything is read once, within bounds, so later reads cannot change what the digest names. Symbolic links, hidden
149
+ * entries and node_modules are refused or skipped; a skill's name must match its folder's.
150
+ */
151
+ export async function loadSkills(sources, options = {}) {
152
+ const bounds = limits(options);
153
+ const skills = [];
154
+ let total = 0;
155
+ const folders = [];
156
+ for (const source of typeof sources === 'string' ? [sources] : sources) {
157
+ const directory = resolve(source);
158
+ const details = await lstat(directory).catch(() => fail(`Skill source not found: ${source}`));
159
+ if (!details.isDirectory() || details.isSymbolicLink())
160
+ fail(`Skill source must be a directory: ${source}`);
161
+ if (await lstat(join(directory, 'SKILL.md')).then(() => true, () => false)) {
162
+ folders.push(directory);
163
+ continue;
164
+ }
165
+ for (const entry of (await readdir(directory, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name))) {
166
+ if (entry.name.startsWith('.') || entry.name === 'node_modules')
167
+ continue;
168
+ if (entry.isSymbolicLink())
169
+ fail(`Skills may not be symbolic links: ${join(source, entry.name)}`);
170
+ if (entry.isDirectory() && await lstat(join(directory, entry.name, 'SKILL.md')).then(() => true, () => false))
171
+ folders.push(join(directory, entry.name));
172
+ }
173
+ }
174
+ for (const folder of folders) {
175
+ if (skills.length >= bounds.maxSkills)
176
+ fail(`More than ${bounds.maxSkills} skills.`);
177
+ const label = `skill folder ${basename(folder)}`;
178
+ const files = [];
179
+ const walk = async (directory, depth) => {
180
+ if (depth > 8)
181
+ fail(`${label} is nested too deeply.`);
182
+ for (const entry of (await readdir(directory, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name))) {
183
+ if (entry.name.startsWith('.') || entry.name === 'node_modules')
184
+ continue;
185
+ const path = join(directory, entry.name);
186
+ if (entry.isSymbolicLink())
187
+ fail(`${label} may not contain symbolic links (${relative(folder, path)}).`);
188
+ if (entry.isDirectory()) {
189
+ await walk(path, depth + 1);
190
+ continue;
191
+ }
192
+ if (!entry.isFile())
193
+ continue;
194
+ const relativePath = relative(folder, path).split(sep).join('/');
195
+ if (relativePath === 'SKILL.md')
196
+ continue;
197
+ if (files.length >= bounds.maxFilesPerSkill)
198
+ fail(`${label} has more than ${bounds.maxFilesPerSkill} files.`);
199
+ const details = await lstat(path);
200
+ if (details.size > bounds.maxFileBytes)
201
+ fail(`${label}: ${relativePath} is larger than ${bounds.maxFileBytes} bytes.`);
202
+ files.push({ path: relativePath, content: new Uint8Array(await readFile(path)) });
203
+ }
204
+ };
205
+ const skillFile = join(folder, 'SKILL.md');
206
+ const skillDetails = await lstat(skillFile);
207
+ if (!skillDetails.isFile() || skillDetails.isSymbolicLink())
208
+ fail(`${label}: SKILL.md must be a regular file.`);
209
+ if (skillDetails.size > bounds.maxFileBytes)
210
+ fail(`${label}: SKILL.md is larger than ${bounds.maxFileBytes} bytes.`);
211
+ let text;
212
+ try {
213
+ text = new TextDecoder('utf-8', { fatal: true }).decode(await readFile(skillFile));
214
+ }
215
+ catch {
216
+ return fail(`${label}: SKILL.md is not UTF-8 text.`);
217
+ }
218
+ await walk(folder, 0);
219
+ const { fields, body } = parseSkillFile(text, `${label}/SKILL.md`);
220
+ const { skill, bytes } = build({ name: fields['name'], description: fields['description'], instructions: body, license: fields['license'],
221
+ allowedTools: fields['allowed-tools'], metadata: fields['metadata'], files }, label);
222
+ if (skill.name !== basename(folder))
223
+ fail(`${label}: the name "${skill.name}" must match the folder name.`);
224
+ total += bytes;
225
+ if (total > bounds.maxTotalBytes)
226
+ fail(`Skills are larger than ${bounds.maxTotalBytes} bytes together.`);
227
+ skills.push(skill);
228
+ }
229
+ return createSkillSet(skills, options);
230
+ }
231
+ /** Tool input validators: strict objects of short strings, without a schema library. */
232
+ function object(fields) {
233
+ return { '~standard': { version: 1, vendor: 'mayura-skills', validate: value => {
234
+ if (value === null || typeof value !== 'object' || Array.isArray(value))
235
+ return { issues: [{ message: 'Expected an object.' }] };
236
+ const record = value;
237
+ const extra = Object.keys(record).filter(key => !fields.includes(key));
238
+ if (extra.length)
239
+ return { issues: [{ message: `Unexpected field ${extra[0]}.` }] };
240
+ for (const field of fields)
241
+ if (typeof record[field] !== 'string' || !record[field].length || record[field].length > 512)
242
+ return { issues: [{ message: `${field} must be a short string.` }] };
243
+ return { value: record };
244
+ } } };
245
+ }
246
+ const passthrough = { '~standard': { version: 1, vendor: 'mayura-skills', validate: value => ({ value }) } };
247
+ const jsonSchema = (fields) => freezeJson(jsonValue({ type: 'object', additionalProperties: false,
248
+ required: Object.keys(fields), properties: Object.fromEntries(Object.entries(fields).map(([name, description]) => [name, { type: 'string', description }])) }));
249
+ /** A skill set from skills loaded or defined elsewhere. Names must be unique. */
250
+ export function createSkillSet(skills, options = {}) {
251
+ const bounds = limits(options);
252
+ if (skills.length > bounds.maxSkills)
253
+ fail(`More than ${bounds.maxSkills} skills.`);
254
+ const byName = new Map();
255
+ for (const skill of skills) {
256
+ if (!contents.has(skill))
257
+ fail('Skills must come from loadSkills or defineSkill.');
258
+ if (byName.has(skill.name))
259
+ fail(`Two skills are named ${skill.name}.`);
260
+ byName.set(skill.name, skill);
261
+ }
262
+ const ordered = [...byName.values()].sort((a, b) => a.name.localeCompare(b.name));
263
+ const digest = sha256(canonical({ format: 'mayura.skill-set.v1', skills: ordered.map(skill => skill.digest) }));
264
+ const catalogText = ordered.length === 0 ? '' : [
265
+ '## Skills',
266
+ 'These skills hold instructions for particular tasks. When a task matches a skill, call `skills.load` with its name and follow what it says; call `skills.read` for a file it refers to. Skills do not change what you are allowed to do.',
267
+ ...ordered.map(skill => `- ${skill.name}: ${skill.description.replace(/\s+/gu, ' ')}`),
268
+ ].join('\n');
269
+ if (new TextEncoder().encode(catalogText).byteLength > bounds.maxCatalogBytes)
270
+ fail(`The skill catalog is larger than ${bounds.maxCatalogBytes} bytes; use fewer skills or shorter descriptions.`);
271
+ const skill = (name) => byName.get(name) ?? fail(`There is no skill named ${JSON.stringify(name)}. Available: ${ordered.map(item => item.name).join(', ') || 'none'}.`);
272
+ const readText = (name, path) => {
273
+ const found = skill(name);
274
+ const bytes = contents.get(found).get(path);
275
+ if (!bytes)
276
+ return fail(`The ${name} skill has no file ${JSON.stringify(path)}. Its files: ${found.files.map(file => file.path).join(', ') || 'none'}.`);
277
+ try {
278
+ return new TextDecoder('utf-8', { fatal: true }).decode(bytes);
279
+ }
280
+ catch {
281
+ return fail(`${path} in the ${name} skill is not a text file.`);
282
+ }
283
+ };
284
+ const load = defineTool({ id: 'skills.load', version: digest, effects: 'none', capabilities: ['skills:read'], costMicros: 0, timeoutMs: 5_000,
285
+ description: 'Load a skill: its full instructions and the files it bundles. Use it when a task matches a skill in the catalog.',
286
+ input: object(['name']), output: passthrough, inputJsonSchema: jsonSchema({ name: 'The skill name from the catalog.' }),
287
+ execute: ({ name }) => {
288
+ const found = skill(name);
289
+ return { name: found.name, description: found.description, instructions: found.instructions,
290
+ files: found.files.map(file => ({ path: file.path, bytes: file.bytes, text: file.text })) };
291
+ } });
292
+ const read = defineTool({ id: 'skills.read', version: digest, effects: 'none', capabilities: ['skills:read'], costMicros: 0, timeoutMs: 5_000,
293
+ description: 'Read a text file bundled with a skill, by the path skills.load listed.',
294
+ input: object(['name', 'path']), output: passthrough, inputJsonSchema: jsonSchema({ name: 'The skill name.', path: 'The file path, as skills.load listed it.' }),
295
+ execute: ({ name, path }) => ({ name, path, content: readText(name, path) }) });
296
+ return Object.freeze({ skills: Object.freeze(ordered), digest, get: (name) => byName.get(name), readFile: readText,
297
+ catalog: () => catalogText, tools: Object.freeze([load, read]),
298
+ permissions: Object.freeze(['tool:skills.load', 'tool:skills.read', 'skills:read']) });
299
+ }
300
+ /**
301
+ * Give an agent a skill set: its catalog appended to the instructions and its two tools added. Grant
302
+ * `skills.permissions` in the runtime too.
303
+ */
304
+ export function withSkills(skills, options) {
305
+ if (skills.skills.length === 0)
306
+ return options;
307
+ if (options.tools.some(tool => tool.id === 'skills.load' || tool.id === 'skills.read'))
308
+ fail('The agent already has skill tools.');
309
+ return { ...options, instructions: `${options.instructions.trimEnd()}\n\n${skills.catalog()}`, tools: [...options.tools, ...skills.tools] };
310
+ }
311
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAClH,iHAAiH;AACjH,4EAA4E;AAC5E,EAAE;AACF,8GAA8G;AAC9G,mHAAmH;AACnH,iHAAiH;AACjH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,UA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ads only when a task\n// needs them. Folders follow the open SKILL.md format: YAML front matter with `name` and `description`, then the\n// instructions in Markdown, plus any other files the instructions refer to.\n//\n// An agent sees only each skill's name and description (the catalog). Two read-only tools load a skill's full\n// instructions and read its files on demand, so dozens of skills cost little until one is used. Skills never grant\n// permissions: a tool or script a skill mentions still needs its own grant, and this package never runs scripts.\nimport { createHash } from 'node:crypto';\nimport { lstat, readdir, readFile } from 'node:fs/promises';\nimport { basename, join, relative, resolve, sep } from 'node:path';\nimport { MayuraError, freezeJson, jsonValue, type JsonObject, type Schema } from '@mayura/core';\nimport { defineTool, type AnyTool } from '@mayura/tools';\n\n/** A file a skill bundles besides SKILL.md, by path relative to the skill folder (`references/api.md`). */\nexport interface SkillFile { readonly path: string; readonly bytes: number; readonly text: boolean }\nexport interface Skill {\n readonly name: string;\n readonly description: string;\n /** The Markdown after the front matter: what the agent reads when it loads the skill. */\n readonly instructions: string;\n readonly files: readonly SkillFile[];\n readonly license?: string;\n /** Tools the skill expects (informational: it grants nothing). */\n readonly allowedTools: readonly string[];\n readonly metadata: Readonly<Record<string, string>>;\n /** SHA-256 over the skill's front matter, instructions and every file. */\n readonly digest: string;\n}\nexport interface SkillSet {\n readonly skills: readonly Skill[];\n /** SHA-256 over every skill's digest; also the version of the skill tools, so durable runs pin what they read. */\n readonly digest: string;\n get(name: string): Skill | undefined;\n /** A skill file's text. Binary files are listed but not readable. */\n readFile(name: string, path: string): string;\n /** The block to add to an agent's instructions: how to use skills, and each skill's name and description. */\n catalog(): string;\n /** `skills.load` and `skills.read`: read-only tools with no effects. */\n readonly tools: readonly AnyTool[];\n /** What a runtime must allow for the tools: `tool:skills.load`, `tool:skills.read` and `skills:read`. */\n readonly permissions: readonly string[];\n}\nexport interface SkillLimits {\n /** Skills in one set (default 64). */\n readonly maxSkills?: number;\n /** Files in one skill besides SKILL.md (default 128). */\n readonly maxFilesPerSkill?: number;\n /** Bytes in one file, SKILL.md included (default 256 KiB). */\n readonly maxFileBytes?: number;\n /** Bytes across all skills (default 16 MiB). */\n readonly maxTotalBytes?: number;\n /** Bytes of the catalog added to the agent's instructions (default 16 KiB). */\n readonly maxCatalogBytes?: number;\n}\n\nconst namePattern = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;\nconst pathPattern = /^[A-Za-z0-9._-]+(?:\\/[A-Za-z0-9._-]+)*$/u;\nconst fail = (message: string): never => { throw new MayuraError('INVALID_CONFIG', message); };\nconst sha256 = (value: string | Uint8Array): string => createHash('sha256').update(value).digest('hex');\nconst canonical = (value: unknown): string => {\n if (value === null || typeof value !== 'object') return JSON.stringify(value);\n if (Array.isArray(value)) return `[${value.map(canonical).join(',')}]`;\n return `{${Object.keys(value).sort().map(key => `${JSON.stringify(key)}:${canonical((value as Record<string, unknown>)[key])}`).join(',')}}`;\n};\nfunction limits(options: SkillLimits = {}): Required<SkillLimits> {\n const pick = (value: number | undefined, fallback: number, name: string): number => {\n const result = value ?? fallback; if (!Number.isSafeInteger(result) || result < 1) fail(`${name} must be a positive integer.`); return result;\n };\n return { maxSkills: pick(options.maxSkills, 64, 'maxSkills'), maxFilesPerSkill: pick(options.maxFilesPerSkill, 128, 'maxFilesPerSkill'),\n maxFileBytes: pick(options.maxFileBytes, 262_144, 'maxFileBytes'), maxTotalBytes: pick(options.maxTotalBytes, 16_777_216, 'maxTotalBytes'),\n maxCatalogBytes: pick(options.maxCatalogBytes, 16_384, 'maxCatalogBytes') };\n}\n\n/**\n * The front matter of SKILL.md: a small, strict YAML subset (`key: value`, quoted values, `>`/`|` block scalars, a\n * `metadata` map and an `allowed-tools` list). Unknown keys are ignored.\n */\nexport function parseSkillFile(text: string, label = 'SKILL.md'): { readonly fields: Record<string, unknown>; readonly body: string } {\n const normalized = text.replace(/^/u, '').replace(/\\r\\n?/gu, '\\n');\n if (!normalized.startsWith('---\\n')) fail(`${label} must start with a --- front matter block.`);\n const end = normalized.indexOf('\\n---', 4); if (end < 0) fail(`${label} front matter is not closed with ---.`);\n const after = normalized.slice(end + 4); if (after && !after.startsWith('\\n')) fail(`${label} front matter must end with a --- line.`);\n const lines = normalized.slice(4, end).split('\\n'); const fields: Record<string, unknown> = {};\n const scalar = (raw: string): string => {\n const value = raw.trim();\n if ((value.startsWith('\"') && value.endsWith('\"') && value.length >= 2)) { try { return JSON.parse(value) as string; } catch { return fail(`${label}: invalid quoted value.`); } }\n if (value.startsWith(\"'\") && value.endsWith(\"'\") && value.length >= 2) return value.slice(1, -1).replaceAll(\"''\", \"'\");\n return value;\n };\n for (let index = 0; index < lines.length; index++) {\n const line = lines[index]!; if (!line.trim() || line.trimStart().startsWith('#')) continue;\n const match = /^([A-Za-z][A-Za-z0-9_-]*):(?:\\s(.*)|)$/u.exec(line); if (!match) fail(`${label}: cannot read front matter line ${index + 1}.`);\n const key = match![1]!; const rest = (match![2] ?? '').trim();\n const block: string[] = [];\n while (index + 1 < lines.length && (/^\\s+\\S/u.test(lines[index + 1]!) || lines[index + 1] === '')) block.push(lines[++index]!);\n if (rest === '>' || rest === '|' || rest === '>-' || rest === '|-') {\n const content = block.map(item => item.trim());\n fields[key] = rest.startsWith('>') ? content.filter(Boolean).join(' ') : content.join('\\n').trim();\n } else if (rest === '' && block.some(item => item.trim().startsWith('- '))) {\n fields[key] = block.filter(item => item.trim()).map(item => { const entry = item.trim(); if (!entry.startsWith('- ')) fail(`${label}: ${key} mixes list and map entries.`); return scalar(entry.slice(2)); });\n } else if (rest === '' && block.length > 0) {\n const map: Record<string, string> = {};\n for (const item of block.filter(entry => entry.trim())) {\n const pair = /^\\s+([A-Za-z0-9_.-]+):\\s*(.*)$/u.exec(item); if (!pair) fail(`${label}: cannot read ${key} entry \"${item.trim()}\".`);\n map[pair![1]!] = scalar(pair![2]!);\n }\n fields[key] = map;\n } else fields[key] = scalar(rest);\n }\n return { fields, body: after.replace(/^\\n/u, '') };\n}\n\n/** Define a skill in code: the same shape a SKILL.md folder has. `files` maps relative paths to their text. */\nexport function defineSkill(options: { readonly name: string; readonly description: string; readonly instructions: string;\n readonly files?: Readonly<Record<string, string>>; readonly license?: string; readonly allowedTools?: readonly string[];\n readonly metadata?: Readonly<Record<string, string>> }): Skill {\n const files = Object.entries(options.files ?? {}).map(([path, content]) => ({ path, content: new TextEncoder().encode(content) }));\n return build({ name: options.name, description: options.description, instructions: options.instructions, license: options.license,\n allowedTools: options.allowedTools, metadata: options.metadata, files }, `skill ${options.name}`).skill;\n}\n\ntype Contents = ReadonlyMap<string, Uint8Array>;\nconst contents = new WeakMap<Skill, Contents>();\nfunction build(input: { name: unknown; description: unknown; instructions: string; license?: unknown; allowedTools?: unknown; metadata?: unknown;\n files: readonly { path: string; content: Uint8Array }[] }, label: string): { skill: Skill; bytes: number } {\n const name = typeof input.name === 'string' ? input.name : fail(`${label} needs a name.`);\n if (name.length > 64 || !namePattern.test(name)) fail(`${label}: the name must be lower-case letters, digits and single hyphens, up to 64 characters.`);\n const description = typeof input.description === 'string' ? input.description.trim() : fail(`${label} needs a description.`);\n if (!description || description.length > 1_024) fail(`${label}: the description must be 1 to 1024 characters.`);\n if (typeof input.instructions !== 'string' || !input.instructions.trim()) fail(`${label} has no instructions.`);\n const license = input.license === undefined ? undefined : typeof input.license === 'string' && input.license.length <= 256 ? input.license : fail(`${label}: license must be text.`);\n const allowed = input.allowedTools === undefined ? [] : typeof input.allowedTools === 'string' ? input.allowedTools.split(/[\\s,]+/u).filter(Boolean)\n : Array.isArray(input.allowedTools) && input.allowedTools.every(item => typeof item === 'string') ? input.allowedTools as string[] : fail(`${label}: allowed-tools must be a list.`);\n const metadata = input.metadata === undefined ? {} : input.metadata !== null && typeof input.metadata === 'object' && !Array.isArray(input.metadata)\n && Object.values(input.metadata).every(value => typeof value === 'string') ? input.metadata as Record<string, string> : fail(`${label}: metadata must map names to text.`);\n const files = [...input.files].sort((a, b) => a.path.localeCompare(b.path)); const map = new Map<string, Uint8Array>();\n for (const file of files) {\n if (!pathPattern.test(file.path) || file.path.split('/').some(part => part === '..' || part === '.') || file.path === 'SKILL.md') fail(`${label}: invalid file path ${JSON.stringify(file.path)}.`);\n if (map.has(file.path)) fail(`${label}: duplicate file ${file.path}.`); map.set(file.path, file.content);\n }\n const decoder = new TextDecoder('utf-8', { fatal: true }); const text = (bytes: Uint8Array): boolean => { try { decoder.decode(bytes); return true; } catch { return false; } };\n const listed = files.map(file => Object.freeze({ path: file.path, bytes: file.content.byteLength, text: text(file.content) }));\n const digest = sha256(canonical({ format: 'mayura.skill.v1', name, description, license: license ?? null, allowedTools: allowed, metadata,\n instructions: input.instructions, files: files.map(file => ({ path: file.path, sha256: sha256(file.content) })) }));\n const skill: Skill = Object.freeze({ name, description, instructions: input.instructions, files: Object.freeze(listed), ...(license === undefined ? {} : { license }),\n allowedTools: Object.freeze([...allowed]), metadata: Object.freeze({ ...metadata }), digest });\n contents.set(skill, map);\n return { skill, bytes: new TextEncoder().encode(input.instructions).byteLength + files.reduce((sum, file) => sum + file.content.byteLength, 0) };\n}\n\n/**\n * Load skills from folders. Each source is either one skill folder (it has a SKILL.md) or a folder of skill folders.\n * Everything is read once, within bounds, so later reads cannot change what the digest names. Symbolic links, hidden\n * entries and node_modules are refused or skipped; a skill's name must match its folder's.\n */\nexport async function loadSkills(sources: string | readonly string[], options: SkillLimits = {}): Promise<SkillSet> {\n const bounds = limits(options); const skills: Skill[] = []; let total = 0;\n const folders: string[] = [];\n for (const source of typeof sources === 'string' ? [sources] : sources) {\n const directory = resolve(source); const details = await lstat(directory).catch(() => fail(`Skill source not found: ${source}`));\n if (!details.isDirectory() || details.isSymbolicLink()) fail(`Skill source must be a directory: ${source}`);\n if (await lstat(join(directory, 'SKILL.md')).then(() => true, () => false)) { folders.push(directory); continue; }\n for (const entry of (await readdir(directory, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name))) {\n if (entry.name.startsWith('.') || entry.name === 'node_modules') continue;\n if (entry.isSymbolicLink()) fail(`Skills may not be symbolic links: ${join(source, entry.name)}`);\n if (entry.isDirectory() && await lstat(join(directory, entry.name, 'SKILL.md')).then(() => true, () => false)) folders.push(join(directory, entry.name));\n }\n }\n for (const folder of folders) {\n if (skills.length >= bounds.maxSkills) fail(`More than ${bounds.maxSkills} skills.`);\n const label = `skill folder ${basename(folder)}`; const files: { path: string; content: Uint8Array }[] = [];\n const walk = async (directory: string, depth: number): Promise<void> => {\n if (depth > 8) fail(`${label} is nested too deeply.`);\n for (const entry of (await readdir(directory, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name))) {\n if (entry.name.startsWith('.') || entry.name === 'node_modules') continue;\n const path = join(directory, entry.name);\n if (entry.isSymbolicLink()) fail(`${label} may not contain symbolic links (${relative(folder, path)}).`);\n if (entry.isDirectory()) { await walk(path, depth + 1); continue; }\n if (!entry.isFile()) continue;\n const relativePath = relative(folder, path).split(sep).join('/'); if (relativePath === 'SKILL.md') continue;\n if (files.length >= bounds.maxFilesPerSkill) fail(`${label} has more than ${bounds.maxFilesPerSkill} files.`);\n const details = await lstat(path); if (details.size > bounds.maxFileBytes) fail(`${label}: ${relativePath} is larger than ${bounds.maxFileBytes} bytes.`);\n files.push({ path: relativePath, content: new Uint8Array(await readFile(path)) });\n }\n };\n const skillFile = join(folder, 'SKILL.md'); const skillDetails = await lstat(skillFile);\n if (!skillDetails.isFile() || skillDetails.isSymbolicLink()) fail(`${label}: SKILL.md must be a regular file.`);\n if (skillDetails.size > bounds.maxFileBytes) fail(`${label}: SKILL.md is larger than ${bounds.maxFileBytes} bytes.`);\n let text: string; try { text = new TextDecoder('utf-8', { fatal: true }).decode(await readFile(skillFile)); } catch { return fail(`${label}: SKILL.md is not UTF-8 text.`); }\n await walk(folder, 0);\n const { fields, body } = parseSkillFile(text, `${label}/SKILL.md`);\n const { skill, bytes } = build({ name: fields['name'], description: fields['description'], instructions: body, license: fields['license'],\n allowedTools: fields['allowed-tools'], metadata: fields['metadata'], files }, label);\n if (skill.name !== basename(folder)) fail(`${label}: the name \"${skill.name}\" must match the folder name.`);\n total += bytes; if (total > bounds.maxTotalBytes) fail(`Skills are larger than ${bounds.maxTotalBytes} bytes together.`);\n skills.push(skill);\n }\n return createSkillSet(skills, options);\n}\n\n/** Tool input validators: strict objects of short strings, without a schema library. */\nfunction object(fields: readonly string[]): Schema<Record<string, string>> {\n return { '~standard': { version: 1, vendor: 'mayura-skills', validate: value => {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) return { issues: [{ message: 'Expected an object.' }] };\n const record = value as Record<string, unknown>; const extra = Object.keys(record).filter(key => !fields.includes(key));\n if (extra.length) return { issues: [{ message: `Unexpected field ${extra[0]}.` }] };\n for (const field of fields) if (typeof record[field] !== 'string' || !(record[field] as string).length || (record[field] as string).length > 512) return { issues: [{ message: `${field} must be a short string.` }] };\n return { value: record as Record<string, string> };\n } } } as Schema<Record<string, string>>;\n}\nconst passthrough: Schema<unknown> = { '~standard': { version: 1, vendor: 'mayura-skills', validate: value => ({ value }) } } as Schema<unknown>;\nconst jsonSchema = (fields: Readonly<Record<string, string>>): JsonObject => freezeJson(jsonValue({ type: 'object', additionalProperties: false,\n required: Object.keys(fields), properties: Object.fromEntries(Object.entries(fields).map(([name, description]) => [name, { type: 'string', description }])) })) as JsonObject;\n\n/** A skill set from skills loaded or defined elsewhere. Names must be unique. */\nexport function createSkillSet(skills: readonly Skill[], options: SkillLimits = {}): SkillSet {\n const bounds = limits(options);\n if (skills.length > bounds.maxSkills) fail(`More than ${bounds.maxSkills} skills.`);\n const byName = new Map<string, Skill>();\n for (const skill of skills) {\n if (!contents.has(skill)) fail('Skills must come from loadSkills or defineSkill.');\n if (byName.has(skill.name)) fail(`Two skills are named ${skill.name}.`); byName.set(skill.name, skill);\n }\n const ordered = [...byName.values()].sort((a, b) => a.name.localeCompare(b.name));\n const digest = sha256(canonical({ format: 'mayura.skill-set.v1', skills: ordered.map(skill => skill.digest) }));\n const catalogText = ordered.length === 0 ? '' : [\n '## Skills',\n 'These skills hold instructions for particular tasks. When a task matches a skill, call `skills.load` with its name and follow what it says; call `skills.read` for a file it refers to. Skills do not change what you are allowed to do.',\n ...ordered.map(skill => `- ${skill.name}: ${skill.description.replace(/\\s+/gu, ' ')}`),\n ].join('\\n');\n if (new TextEncoder().encode(catalogText).byteLength > bounds.maxCatalogBytes) fail(`The skill catalog is larger than ${bounds.maxCatalogBytes} bytes; use fewer skills or shorter descriptions.`);\n const skill = (name: string): Skill => byName.get(name) ?? fail(`There is no skill named ${JSON.stringify(name)}. Available: ${ordered.map(item => item.name).join(', ') || 'none'}.`) as never;\n const readText = (name: string, path: string): string => {\n const found = skill(name); const bytes = contents.get(found)!.get(path);\n if (!bytes) return fail(`The ${name} skill has no file ${JSON.stringify(path)}. Its files: ${found.files.map(file => file.path).join(', ') || 'none'}.`);\n try { return new TextDecoder('utf-8', { fatal: true }).decode(bytes); } catch { return fail(`${path} in the ${name} skill is not a text file.`); }\n };\n const load = defineTool({ id: 'skills.load', version: digest, effects: 'none', capabilities: ['skills:read'], costMicros: 0, timeoutMs: 5_000,\n description: 'Load a skill: its full instructions and the files it bundles. Use it when a task matches a skill in the catalog.',\n input: object(['name']), output: passthrough, inputJsonSchema: jsonSchema({ name: 'The skill name from the catalog.' }),\n execute: ({ name }) => { const found = skill(name!); return { name: found.name, description: found.description, instructions: found.instructions,\n files: found.files.map(file => ({ path: file.path, bytes: file.bytes, text: file.text })) }; } });\n const read = defineTool({ id: 'skills.read', version: digest, effects: 'none', capabilities: ['skills:read'], costMicros: 0, timeoutMs: 5_000,\n description: 'Read a text file bundled with a skill, by the path skills.load listed.',\n input: object(['name', 'path']), output: passthrough, inputJsonSchema: jsonSchema({ name: 'The skill name.', path: 'The file path, as skills.load listed it.' }),\n execute: ({ name, path }) => ({ name, path, content: readText(name!, path!) }) });\n return Object.freeze({ skills: Object.freeze(ordered), digest, get: (name: string) => byName.get(name), readFile: readText,\n catalog: () => catalogText, tools: Object.freeze([load, read]) as readonly AnyTool[],\n permissions: Object.freeze(['tool:skills.load', 'tool:skills.read', 'skills:read']) });\n}\n\n/**\n * Give an agent a skill set: its catalog appended to the instructions and its two tools added. Grant\n * `skills.permissions` in the runtime too.\n */\nexport function withSkills<T extends { readonly instructions: string; readonly tools: readonly AnyTool[] }>(skills: SkillSet, options: T): T {\n if (skills.skills.length === 0) return options;\n if (options.tools.some(tool => tool.id === 'skills.load' || tool.id === 'skills.read')) fail('The agent already has skill tools.');\n return { ...options, instructions: `${options.instructions.trimEnd()}\\n\\n${skills.catalog()}`, tools: [...options.tools, ...skills.tools] };\n}\n"]}
@@ -0,0 +1,5 @@
1
+ {
2
+ "type": "module",
3
+ "version": "1.0.0-rc.2",
4
+ "private": true
5
+ }