@united-workforce/cli 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (319) hide show
  1. package/README.md +45 -11
  2. package/dist/.build-fingerprint +1 -0
  3. package/dist/__tests__/adapter-json-roundtrip.test.js +17 -7
  4. package/dist/__tests__/adapter-json-roundtrip.test.js.map +1 -1
  5. package/dist/__tests__/agent-resolution-llm-free.test.d.ts +2 -0
  6. package/dist/__tests__/agent-resolution-llm-free.test.d.ts.map +1 -0
  7. package/dist/__tests__/agent-resolution-llm-free.test.js +30 -0
  8. package/dist/__tests__/agent-resolution-llm-free.test.js.map +1 -0
  9. package/dist/__tests__/build-step-entry.test.d.ts +2 -0
  10. package/dist/__tests__/build-step-entry.test.d.ts.map +1 -0
  11. package/dist/__tests__/build-step-entry.test.js +173 -0
  12. package/dist/__tests__/build-step-entry.test.js.map +1 -0
  13. package/dist/__tests__/clear-thread-failed-attempts.test.d.ts +2 -0
  14. package/dist/__tests__/clear-thread-failed-attempts.test.d.ts.map +1 -0
  15. package/dist/__tests__/clear-thread-failed-attempts.test.js +93 -0
  16. package/dist/__tests__/clear-thread-failed-attempts.test.js.map +1 -0
  17. package/dist/__tests__/concurrency.test.d.ts +2 -0
  18. package/dist/__tests__/concurrency.test.d.ts.map +1 -0
  19. package/dist/__tests__/concurrency.test.js +196 -0
  20. package/dist/__tests__/concurrency.test.js.map +1 -0
  21. package/dist/__tests__/config.test.js +26 -302
  22. package/dist/__tests__/config.test.js.map +1 -1
  23. package/dist/__tests__/current-role.test.js +7 -6
  24. package/dist/__tests__/current-role.test.js.map +1 -1
  25. package/dist/__tests__/e2e-mock-agent.test.js +43 -30
  26. package/dist/__tests__/e2e-mock-agent.test.js.map +1 -1
  27. package/dist/__tests__/format-text-default.test.d.ts +2 -0
  28. package/dist/__tests__/format-text-default.test.d.ts.map +1 -0
  29. package/dist/__tests__/format-text-default.test.js +43 -0
  30. package/dist/__tests__/format-text-default.test.js.map +1 -0
  31. package/dist/__tests__/format-text-registry.test.d.ts +2 -0
  32. package/dist/__tests__/format-text-registry.test.d.ts.map +1 -0
  33. package/dist/__tests__/format-text-registry.test.js +158 -0
  34. package/dist/__tests__/format-text-registry.test.js.map +1 -0
  35. package/dist/__tests__/issue-180-workflow-ref-removed.test.d.ts +2 -0
  36. package/dist/__tests__/issue-180-workflow-ref-removed.test.d.ts.map +1 -0
  37. package/dist/__tests__/issue-180-workflow-ref-removed.test.js +40 -0
  38. package/dist/__tests__/issue-180-workflow-ref-removed.test.js.map +1 -0
  39. package/dist/__tests__/log-text-renderer.test.d.ts +2 -0
  40. package/dist/__tests__/log-text-renderer.test.d.ts.map +1 -0
  41. package/dist/__tests__/log-text-renderer.test.js +265 -0
  42. package/dist/__tests__/log-text-renderer.test.js.map +1 -0
  43. package/dist/__tests__/moderator-evaluate.test.js +9 -50
  44. package/dist/__tests__/moderator-evaluate.test.js.map +1 -1
  45. package/dist/__tests__/output-mapper-thread-list-startedat.test.d.ts +2 -0
  46. package/dist/__tests__/output-mapper-thread-list-startedat.test.d.ts.map +1 -0
  47. package/dist/__tests__/output-mapper-thread-list-startedat.test.js +102 -0
  48. package/dist/__tests__/output-mapper-thread-list-startedat.test.js.map +1 -0
  49. package/dist/__tests__/output-mapper-workflow-add.test.d.ts +2 -0
  50. package/dist/__tests__/output-mapper-workflow-add.test.d.ts.map +1 -0
  51. package/dist/__tests__/output-mapper-workflow-add.test.js +22 -0
  52. package/dist/__tests__/output-mapper-workflow-add.test.js.map +1 -0
  53. package/dist/__tests__/pid-recycling.test.d.ts +2 -0
  54. package/dist/__tests__/pid-recycling.test.d.ts.map +1 -0
  55. package/dist/__tests__/pid-recycling.test.js +273 -0
  56. package/dist/__tests__/pid-recycling.test.js.map +1 -0
  57. package/dist/__tests__/prompt.test.js +365 -2
  58. package/dist/__tests__/prompt.test.js.map +1 -1
  59. package/dist/__tests__/resolve-head-hash.test.js +12 -4
  60. package/dist/__tests__/resolve-head-hash.test.js.map +1 -1
  61. package/dist/__tests__/setup-agent-discovery.test.js +21 -30
  62. package/dist/__tests__/setup-agent-discovery.test.js.map +1 -1
  63. package/dist/__tests__/setup-complexity.test.js +2 -168
  64. package/dist/__tests__/setup-complexity.test.js.map +1 -1
  65. package/dist/__tests__/setup-no-llm.test.d.ts +2 -0
  66. package/dist/__tests__/setup-no-llm.test.d.ts.map +1 -0
  67. package/dist/__tests__/setup-no-llm.test.js +52 -0
  68. package/dist/__tests__/setup-no-llm.test.js.map +1 -0
  69. package/dist/__tests__/solve-issue-tea-worktree.test.js +27 -28
  70. package/dist/__tests__/solve-issue-tea-worktree.test.js.map +1 -1
  71. package/dist/__tests__/step-ask.test.d.ts +2 -0
  72. package/dist/__tests__/step-ask.test.d.ts.map +1 -0
  73. package/dist/__tests__/step-ask.test.js +507 -0
  74. package/dist/__tests__/step-ask.test.js.map +1 -0
  75. package/dist/__tests__/step-show-json.test.js +1 -0
  76. package/dist/__tests__/step-show-json.test.js.map +1 -1
  77. package/dist/__tests__/step-timing.test.js +2 -0
  78. package/dist/__tests__/step-timing.test.js.map +1 -1
  79. package/dist/__tests__/store-global-cas.test.js +2 -2
  80. package/dist/__tests__/store-global-cas.test.js.map +1 -1
  81. package/dist/__tests__/store-unified-threads.test.js +28 -26
  82. package/dist/__tests__/store-unified-threads.test.js.map +1 -1
  83. package/dist/__tests__/thread-cancel-status.test.js +25 -19
  84. package/dist/__tests__/thread-cancel-status.test.js.map +1 -1
  85. package/dist/__tests__/thread-cancel-text-renderer.test.d.ts +2 -0
  86. package/dist/__tests__/thread-cancel-text-renderer.test.d.ts.map +1 -0
  87. package/dist/__tests__/thread-cancel-text-renderer.test.js +110 -0
  88. package/dist/__tests__/thread-cancel-text-renderer.test.js.map +1 -0
  89. package/dist/__tests__/thread-list-filters.test.js +354 -17
  90. package/dist/__tests__/thread-list-filters.test.js.map +1 -1
  91. package/dist/__tests__/thread-list-template-ms-date.test.d.ts +2 -0
  92. package/dist/__tests__/thread-list-template-ms-date.test.d.ts.map +1 -0
  93. package/dist/__tests__/thread-list-template-ms-date.test.js +102 -0
  94. package/dist/__tests__/thread-list-template-ms-date.test.js.map +1 -0
  95. package/dist/__tests__/thread-list-workflow-corrupt.test.d.ts +2 -0
  96. package/dist/__tests__/thread-list-workflow-corrupt.test.d.ts.map +1 -0
  97. package/dist/__tests__/thread-list-workflow-corrupt.test.js +157 -0
  98. package/dist/__tests__/thread-list-workflow-corrupt.test.js.map +1 -0
  99. package/dist/__tests__/thread-poke.test.d.ts +2 -0
  100. package/dist/__tests__/thread-poke.test.d.ts.map +1 -0
  101. package/dist/__tests__/thread-poke.test.js +422 -0
  102. package/dist/__tests__/thread-poke.test.js.map +1 -0
  103. package/dist/__tests__/thread-read-xml-tags.test.js +10 -9
  104. package/dist/__tests__/thread-read-xml-tags.test.js.map +1 -1
  105. package/dist/__tests__/thread-resume.test.js +21 -15
  106. package/dist/__tests__/thread-resume.test.js.map +1 -1
  107. package/dist/__tests__/thread-show-status.test.js +17 -28
  108. package/dist/__tests__/thread-show-status.test.js.map +1 -1
  109. package/dist/__tests__/thread-start-cwd-cli.test.js +15 -3
  110. package/dist/__tests__/thread-start-cwd-cli.test.js.map +1 -1
  111. package/dist/__tests__/thread-stop-text-renderer.test.d.ts +2 -0
  112. package/dist/__tests__/thread-stop-text-renderer.test.d.ts.map +1 -0
  113. package/dist/__tests__/thread-stop-text-renderer.test.js +148 -0
  114. package/dist/__tests__/thread-stop-text-renderer.test.js.map +1 -0
  115. package/dist/__tests__/thread-suspend-step.test.js +13 -16
  116. package/dist/__tests__/thread-suspend-step.test.js.map +1 -1
  117. package/dist/__tests__/thread-suspended-display.test.js +10 -22
  118. package/dist/__tests__/thread-suspended-display.test.js.map +1 -1
  119. package/dist/__tests__/thread-test-helpers.d.ts +7 -0
  120. package/dist/__tests__/thread-test-helpers.d.ts.map +1 -1
  121. package/dist/__tests__/thread-test-helpers.js +13 -0
  122. package/dist/__tests__/thread-test-helpers.js.map +1 -1
  123. package/dist/__tests__/thread.test.js +15 -13
  124. package/dist/__tests__/thread.test.js.map +1 -1
  125. package/dist/__tests__/validate-semantic.test.js +105 -23
  126. package/dist/__tests__/validate-semantic.test.js.map +1 -1
  127. package/dist/__tests__/workflow-list-recursive.test.d.ts +2 -0
  128. package/dist/__tests__/workflow-list-recursive.test.d.ts.map +1 -0
  129. package/dist/__tests__/workflow-list-recursive.test.js +286 -0
  130. package/dist/__tests__/workflow-list-recursive.test.js.map +1 -0
  131. package/dist/__tests__/workflow-resolution.test.js +46 -28
  132. package/dist/__tests__/workflow-resolution.test.js.map +1 -1
  133. package/dist/__tests__/workflow-show-resolution.test.d.ts +2 -0
  134. package/dist/__tests__/workflow-show-resolution.test.d.ts.map +1 -0
  135. package/dist/__tests__/workflow-show-resolution.test.js +213 -0
  136. package/dist/__tests__/workflow-show-resolution.test.js.map +1 -0
  137. package/dist/__tests__/workflow-validate.test.d.ts +2 -0
  138. package/dist/__tests__/workflow-validate.test.d.ts.map +1 -0
  139. package/dist/__tests__/workflow-validate.test.js +707 -0
  140. package/dist/__tests__/workflow-validate.test.js.map +1 -0
  141. package/dist/__tests__/write-envelope.test.d.ts +2 -0
  142. package/dist/__tests__/write-envelope.test.d.ts.map +1 -0
  143. package/dist/__tests__/write-envelope.test.js +201 -0
  144. package/dist/__tests__/write-envelope.test.js.map +1 -0
  145. package/dist/background/background.d.ts +22 -1
  146. package/dist/background/background.d.ts.map +1 -1
  147. package/dist/background/background.js +83 -6
  148. package/dist/background/background.js.map +1 -1
  149. package/dist/background/index.d.ts +1 -1
  150. package/dist/background/index.d.ts.map +1 -1
  151. package/dist/background/index.js +1 -1
  152. package/dist/background/index.js.map +1 -1
  153. package/dist/background/types.d.ts +1 -0
  154. package/dist/background/types.d.ts.map +1 -1
  155. package/dist/cli.js +120 -62
  156. package/dist/cli.js.map +1 -1
  157. package/dist/commands/config.d.ts +3 -1
  158. package/dist/commands/config.d.ts.map +1 -1
  159. package/dist/commands/config.js +17 -31
  160. package/dist/commands/config.js.map +1 -1
  161. package/dist/commands/prompt.d.ts.map +1 -1
  162. package/dist/commands/prompt.js +57 -31
  163. package/dist/commands/prompt.js.map +1 -1
  164. package/dist/commands/setup.d.ts +12 -39
  165. package/dist/commands/setup.d.ts.map +1 -1
  166. package/dist/commands/setup.js +72 -303
  167. package/dist/commands/setup.js.map +1 -1
  168. package/dist/commands/step.d.ts +44 -1
  169. package/dist/commands/step.d.ts.map +1 -1
  170. package/dist/commands/step.js +255 -11
  171. package/dist/commands/step.js.map +1 -1
  172. package/dist/commands/thread.d.ts +16 -3
  173. package/dist/commands/thread.d.ts.map +1 -1
  174. package/dist/commands/thread.js +423 -142
  175. package/dist/commands/thread.js.map +1 -1
  176. package/dist/commands/workflow.d.ts +9 -1
  177. package/dist/commands/workflow.d.ts.map +1 -1
  178. package/dist/commands/workflow.js +126 -6
  179. package/dist/commands/workflow.js.map +1 -1
  180. package/dist/concurrency/concurrency.d.ts +34 -0
  181. package/dist/concurrency/concurrency.d.ts.map +1 -0
  182. package/dist/concurrency/concurrency.js +216 -0
  183. package/dist/concurrency/concurrency.js.map +1 -0
  184. package/dist/concurrency/index.d.ts +3 -0
  185. package/dist/concurrency/index.d.ts.map +1 -0
  186. package/dist/concurrency/index.js +2 -0
  187. package/dist/concurrency/index.js.map +1 -0
  188. package/dist/concurrency/types.d.ts +19 -0
  189. package/dist/concurrency/types.d.ts.map +1 -0
  190. package/dist/concurrency/types.js +2 -0
  191. package/dist/concurrency/types.js.map +1 -0
  192. package/dist/format.d.ts +69 -2
  193. package/dist/format.d.ts.map +1 -1
  194. package/dist/format.js +198 -1
  195. package/dist/format.js.map +1 -1
  196. package/dist/moderator/__tests__/evaluate.test.js +31 -17
  197. package/dist/moderator/__tests__/evaluate.test.js.map +1 -1
  198. package/dist/moderator/evaluate.d.ts.map +1 -1
  199. package/dist/moderator/evaluate.js +4 -16
  200. package/dist/moderator/evaluate.js.map +1 -1
  201. package/dist/moderator/index.d.ts +1 -2
  202. package/dist/moderator/index.d.ts.map +1 -1
  203. package/dist/moderator/index.js +0 -1
  204. package/dist/moderator/index.js.map +1 -1
  205. package/dist/moderator/types.d.ts +6 -10
  206. package/dist/moderator/types.d.ts.map +1 -1
  207. package/dist/moderator/types.js +1 -3
  208. package/dist/moderator/types.js.map +1 -1
  209. package/dist/output-mappers.d.ts +122 -0
  210. package/dist/output-mappers.d.ts.map +1 -0
  211. package/dist/output-mappers.js +134 -0
  212. package/dist/output-mappers.js.map +1 -0
  213. package/dist/schemas.d.ts +6 -1
  214. package/dist/schemas.d.ts.map +1 -1
  215. package/dist/schemas.js +34 -5
  216. package/dist/schemas.js.map +1 -1
  217. package/dist/store.d.ts +28 -9
  218. package/dist/store.d.ts.map +1 -1
  219. package/dist/store.js +75 -16
  220. package/dist/store.js.map +1 -1
  221. package/dist/text-renderers.d.ts +30 -0
  222. package/dist/text-renderers.d.ts.map +1 -0
  223. package/dist/text-renderers.js +251 -0
  224. package/dist/text-renderers.js.map +1 -0
  225. package/dist/validate-semantic.d.ts.map +1 -1
  226. package/dist/validate-semantic.js +95 -61
  227. package/dist/validate-semantic.js.map +1 -1
  228. package/dist/validate.d.ts +6 -0
  229. package/dist/validate.d.ts.map +1 -1
  230. package/dist/validate.js +24 -0
  231. package/dist/validate.js.map +1 -1
  232. package/examples/brainstorm.yaml +130 -0
  233. package/examples/debate.yaml +169 -0
  234. package/examples/socratic-questioning.yaml +112 -0
  235. package/package.json +9 -10
  236. package/src/__tests__/adapter-json-roundtrip.test.ts +16 -7
  237. package/src/__tests__/agent-resolution-llm-free.test.ts +39 -0
  238. package/src/__tests__/build-step-entry.test.ts +203 -0
  239. package/src/__tests__/clear-thread-failed-attempts.test.ts +122 -0
  240. package/src/__tests__/concurrency.test.ts +266 -0
  241. package/src/__tests__/config.test.ts +33 -321
  242. package/src/__tests__/current-role.test.ts +7 -6
  243. package/src/__tests__/e2e-mock-agent.test.ts +65 -30
  244. package/src/__tests__/fixtures/e2e-count.workflow.yaml +1 -0
  245. package/src/__tests__/fixtures/e2e-linear.workflow.yaml +1 -0
  246. package/src/__tests__/fixtures/{e2e-mustache.workflow.yaml → e2e-liquid.workflow.yaml} +3 -2
  247. package/src/__tests__/fixtures/e2e-loop.workflow.yaml +1 -0
  248. package/src/__tests__/fixtures/e2e-suspend.mock.yaml +2 -2
  249. package/src/__tests__/fixtures/e2e-suspend.workflow.yaml +6 -10
  250. package/src/__tests__/format-text-default.test.ts +49 -0
  251. package/src/__tests__/format-text-registry.test.ts +173 -0
  252. package/src/__tests__/issue-180-workflow-ref-removed.test.ts +43 -0
  253. package/src/__tests__/log-text-renderer.test.ts +294 -0
  254. package/src/__tests__/moderator-evaluate.test.ts +9 -52
  255. package/src/__tests__/output-mapper-thread-list-startedat.test.ts +124 -0
  256. package/src/__tests__/output-mapper-workflow-add.test.ts +24 -0
  257. package/src/__tests__/pid-recycling.test.ts +329 -0
  258. package/src/__tests__/prompt.test.ts +443 -2
  259. package/src/__tests__/resolve-head-hash.test.ts +11 -4
  260. package/src/__tests__/setup-agent-discovery.test.ts +26 -51
  261. package/src/__tests__/setup-complexity.test.ts +1 -203
  262. package/src/__tests__/setup-no-llm.test.ts +68 -0
  263. package/src/__tests__/solve-issue-tea-worktree.test.ts +27 -31
  264. package/src/__tests__/step-ask.test.ts +677 -0
  265. package/src/__tests__/step-show-json.test.ts +1 -0
  266. package/src/__tests__/step-timing.test.ts +2 -0
  267. package/src/__tests__/store-global-cas.test.ts +2 -2
  268. package/src/__tests__/store-unified-threads.test.ts +30 -27
  269. package/src/__tests__/thread-cancel-status.test.ts +27 -20
  270. package/src/__tests__/thread-cancel-text-renderer.test.ts +125 -0
  271. package/src/__tests__/thread-list-filters.test.ts +443 -17
  272. package/src/__tests__/thread-list-template-ms-date.test.ts +110 -0
  273. package/src/__tests__/thread-list-workflow-corrupt.test.ts +198 -0
  274. package/src/__tests__/thread-poke.test.ts +554 -0
  275. package/src/__tests__/thread-read-xml-tags.test.ts +9 -11
  276. package/src/__tests__/thread-resume.test.ts +20 -15
  277. package/src/__tests__/thread-show-status.test.ts +17 -29
  278. package/src/__tests__/thread-start-cwd-cli.test.ts +15 -3
  279. package/src/__tests__/thread-stop-text-renderer.test.ts +168 -0
  280. package/src/__tests__/thread-suspend-step.test.ts +13 -16
  281. package/src/__tests__/thread-suspended-display.test.ts +10 -22
  282. package/src/__tests__/thread-test-helpers.ts +15 -1
  283. package/src/__tests__/thread.test.ts +14 -14
  284. package/src/__tests__/validate-semantic.test.ts +118 -33
  285. package/src/__tests__/workflow-list-recursive.test.ts +370 -0
  286. package/src/__tests__/workflow-resolution.test.ts +48 -29
  287. package/src/__tests__/workflow-show-resolution.test.ts +286 -0
  288. package/src/__tests__/workflow-validate.test.ts +828 -0
  289. package/src/__tests__/write-envelope.test.ts +257 -0
  290. package/src/background/background.ts +88 -6
  291. package/src/background/index.ts +2 -0
  292. package/src/background/types.ts +1 -0
  293. package/src/cli.ts +184 -77
  294. package/src/commands/config.ts +16 -33
  295. package/src/commands/prompt.ts +57 -31
  296. package/src/commands/setup.ts +80 -358
  297. package/src/commands/step.ts +339 -12
  298. package/src/commands/thread.ts +511 -171
  299. package/src/commands/workflow.ts +155 -4
  300. package/src/concurrency/concurrency.ts +245 -0
  301. package/src/concurrency/index.ts +10 -0
  302. package/src/concurrency/types.ts +19 -0
  303. package/src/format.ts +282 -2
  304. package/src/moderator/__tests__/evaluate.test.ts +34 -17
  305. package/src/moderator/evaluate.ts +5 -17
  306. package/src/moderator/index.ts +1 -6
  307. package/src/moderator/types.ts +6 -14
  308. package/src/output-mappers.ts +254 -0
  309. package/src/schemas.ts +51 -5
  310. package/src/store.ts +86 -20
  311. package/src/text-renderers.ts +355 -0
  312. package/src/validate-semantic.ts +125 -73
  313. package/src/validate.ts +27 -0
  314. package/dist/__tests__/setup-validate.test.d.ts +0 -2
  315. package/dist/__tests__/setup-validate.test.d.ts.map +0 -1
  316. package/dist/__tests__/setup-validate.test.js +0 -108
  317. package/dist/__tests__/setup-validate.test.js.map +0 -1
  318. package/src/__tests__/setup-validate.test.ts +0 -148
  319. /package/src/__tests__/fixtures/{e2e-mustache.mock.yaml → e2e-liquid.mock.yaml} +0 -0
@@ -0,0 +1,216 @@
1
+ import { unlinkSync } from "node:fs";
2
+ import { mkdir, readdir, rm, writeFile } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ import { isPidAlive } from "../background/index.js";
5
+ /** Default concurrency limit when no config or flag is provided. */
6
+ export const DEFAULT_MAX_RUNNING = 2;
7
+ /** Default poll interval (ms) for waiting on a slot. */
8
+ const DEFAULT_POLL_INTERVAL_MS = 2000;
9
+ /**
10
+ * Get the path to the slots directory.
11
+ */
12
+ export function getSlotsDir(storageRoot) {
13
+ return join(storageRoot, "slots");
14
+ }
15
+ /**
16
+ * Count active slot files (alive PIDs only). Stale slots are skipped but not removed.
17
+ */
18
+ export async function countActiveSlots(storageRoot) {
19
+ const slotsDir = getSlotsDir(storageRoot);
20
+ let files;
21
+ try {
22
+ files = await readdir(slotsDir);
23
+ }
24
+ catch {
25
+ return 0;
26
+ }
27
+ let count = 0;
28
+ for (const file of files) {
29
+ if (!file.endsWith(".slot")) {
30
+ continue;
31
+ }
32
+ const pidStr = file.slice(0, -5);
33
+ const pid = Number(pidStr);
34
+ if (Number.isNaN(pid)) {
35
+ continue;
36
+ }
37
+ if (isPidAlive(pid)) {
38
+ count++;
39
+ }
40
+ }
41
+ return count;
42
+ }
43
+ /**
44
+ * Remove slot files whose PIDs are no longer alive.
45
+ * Returns the number of stale slots cleaned.
46
+ */
47
+ export async function cleanStaleSlots(storageRoot) {
48
+ const slotsDir = getSlotsDir(storageRoot);
49
+ let files;
50
+ try {
51
+ files = await readdir(slotsDir);
52
+ }
53
+ catch {
54
+ return 0;
55
+ }
56
+ let cleaned = 0;
57
+ for (const file of files) {
58
+ if (!file.endsWith(".slot")) {
59
+ continue;
60
+ }
61
+ const pidStr = file.slice(0, -5);
62
+ const pid = Number(pidStr);
63
+ if (Number.isNaN(pid)) {
64
+ continue;
65
+ }
66
+ if (!isPidAlive(pid)) {
67
+ try {
68
+ await rm(join(slotsDir, file), { force: true });
69
+ cleaned++;
70
+ }
71
+ catch {
72
+ // Ignore removal errors (race with another cleanup)
73
+ }
74
+ }
75
+ }
76
+ return cleaned;
77
+ }
78
+ /**
79
+ * Create a slot file for the current process. Returns the path to the created file.
80
+ */
81
+ async function writeSlotFile(storageRoot) {
82
+ const slotsDir = getSlotsDir(storageRoot);
83
+ await mkdir(slotsDir, { recursive: true });
84
+ const slotPath = join(slotsDir, `${process.pid}.slot`);
85
+ await writeFile(slotPath, "", "utf8");
86
+ return slotPath;
87
+ }
88
+ /**
89
+ * Remove a slot file. Idempotent — silently ignores missing file.
90
+ */
91
+ async function removeSlotFile(slotPath) {
92
+ try {
93
+ await rm(slotPath, { force: true });
94
+ }
95
+ catch {
96
+ // Already removed or race condition — safe to ignore
97
+ }
98
+ }
99
+ function sleep(ms, signal) {
100
+ return new Promise((resolve, reject) => {
101
+ if (signal?.aborted) {
102
+ reject(new Error("aborted"));
103
+ return;
104
+ }
105
+ const timer = setTimeout(resolve, ms);
106
+ if (signal !== null) {
107
+ const onAbort = () => {
108
+ clearTimeout(timer);
109
+ reject(new Error("aborted"));
110
+ };
111
+ signal.addEventListener("abort", onAbort, { once: true });
112
+ }
113
+ });
114
+ }
115
+ /**
116
+ * Try to claim a slot. Returns the slot path on success, null if a race was
117
+ * detected (post-write count exceeds maxRunning → rolls back).
118
+ */
119
+ async function tryClaimSlot(storageRoot, maxRunning) {
120
+ const slotPath = await writeSlotFile(storageRoot);
121
+ const postWriteCount = await countActiveSlots(storageRoot);
122
+ if (postWriteCount > maxRunning) {
123
+ await removeSlotFile(slotPath);
124
+ return null;
125
+ }
126
+ return slotPath;
127
+ }
128
+ function createSlotHandle(slotPath) {
129
+ let released = false;
130
+ return {
131
+ slotPath,
132
+ release: async () => {
133
+ if (released)
134
+ return;
135
+ released = true;
136
+ await removeSlotFile(slotPath);
137
+ },
138
+ };
139
+ }
140
+ function resolveOptions(options) {
141
+ return {
142
+ onWaiting: options.onWaiting ?? null,
143
+ onAcquired: options.onAcquired ?? null,
144
+ pollIntervalMs: options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS,
145
+ signal: options.signal ?? null,
146
+ };
147
+ }
148
+ function notifyWaiting(opts, waited, message) {
149
+ if (!waited && opts.onWaiting !== null) {
150
+ opts.onWaiting(message);
151
+ return true;
152
+ }
153
+ return waited;
154
+ }
155
+ /**
156
+ * Acquire a concurrency slot. If all slots are occupied, polls until one is available.
157
+ *
158
+ * Race protection: after writing the slot file, double-checks countActiveSlots.
159
+ * If the count exceeds maxRunning, rolls back (removes own slot) and retries.
160
+ */
161
+ export async function acquireSlot(storageRoot, maxRunning, options = {}) {
162
+ const opts = resolveOptions(options);
163
+ let waited = false;
164
+ while (true) {
165
+ await cleanStaleSlots(storageRoot);
166
+ const currentCount = await countActiveSlots(storageRoot);
167
+ if (currentCount >= maxRunning) {
168
+ waited = notifyWaiting(opts, waited, `${currentCount}/${maxRunning} running`);
169
+ await sleep(opts.pollIntervalMs, opts.signal);
170
+ continue;
171
+ }
172
+ const slotPath = await tryClaimSlot(storageRoot, maxRunning);
173
+ if (slotPath === null) {
174
+ waited = notifyWaiting(opts, waited, `race detected, retrying`);
175
+ await sleep(opts.pollIntervalMs, opts.signal);
176
+ continue;
177
+ }
178
+ if (waited && opts.onAcquired !== null) {
179
+ opts.onAcquired();
180
+ }
181
+ return createSlotHandle(slotPath);
182
+ }
183
+ }
184
+ /**
185
+ * Alias for SlotHandle.release() — explicit function form for callers that
186
+ * prefer passing the handle as an argument.
187
+ */
188
+ export async function releaseSlot(handle) {
189
+ await handle.release();
190
+ }
191
+ /**
192
+ * Install process signal handlers that release the slot on SIGINT/SIGTERM.
193
+ * Returns a cleanup function that removes the handlers (call on normal exit).
194
+ */
195
+ export function installSlotCleanup(handle) {
196
+ const cleanup = () => {
197
+ try {
198
+ unlinkSync(handle.slotPath);
199
+ }
200
+ catch {
201
+ // Already removed
202
+ }
203
+ };
204
+ const onSignal = () => {
205
+ cleanup();
206
+ process.exit(1);
207
+ };
208
+ process.on("SIGINT", onSignal);
209
+ process.on("SIGTERM", onSignal);
210
+ // Return a function to uninstall the handlers
211
+ return () => {
212
+ process.removeListener("SIGINT", onSignal);
213
+ process.removeListener("SIGTERM", onSignal);
214
+ };
215
+ }
216
+ //# sourceMappingURL=concurrency.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"concurrency.js","sourceRoot":"","sources":["../../src/concurrency/concurrency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGpD,oEAAoE;AACpE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAErC,wDAAwD;AACxD,MAAM,wBAAwB,GAAG,IAAI,CAAC;AAEtC;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,WAAmB;IAC7C,OAAO,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AACpC,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,WAAmB;IACxD,MAAM,QAAQ,GAAG,WAAW,CAAC,WAAW,CAAC,CAAC;IAC1C,IAAI,KAAe,CAAC;IACpB,IAAI,CAAC;QACH,KAAK,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,CAAC,CAAC;IACX,CAAC;IAED,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,IAAI,CAAC,QAAQ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ACH,MAAM,UAAU,kBAAkB,CAAC,MAAkB;IACnD,MAAM,OAAO,GAAG,GAAG,EAAE;QACnB,IAAI,CAAC;YACH,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC9B,CAAC;QAAC,MAAM,CAAC;YACP,kBAAkB;QACpB,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,QAAQ,GAAG,GAAG,EAAE;QACpB,OAAO,EAAE,CAAC;QACV,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC;IAEF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAEhC,8CAA8C;IAC9C,OAAO,GAAG,EAAE;QACV,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC3C,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAC9C,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { acquireSlot, cleanStaleSlots, countActiveSlots, DEFAULT_MAX_RUNNING, getSlotsDir, installSlotCleanup, releaseSlot, } from "./concurrency.js";
2
+ export type { AcquireSlotOptions, SlotHandle } from "./types.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/concurrency/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,WAAW,EACX,kBAAkB,EAClB,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { acquireSlot, cleanStaleSlots, countActiveSlots, DEFAULT_MAX_RUNNING, getSlotsDir, installSlotCleanup, releaseSlot, } from "./concurrency.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/concurrency/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,WAAW,EACX,kBAAkB,EAClB,WAAW,GACZ,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,19 @@
1
+ /** Handle returned by acquireSlot; call release() to free the slot. */
2
+ export type SlotHandle = {
3
+ /** Remove the slot file. Idempotent — second call is a no-op. */
4
+ release: () => Promise<void>;
5
+ /** The slot file path (for signal-handler cleanup). */
6
+ slotPath: string;
7
+ };
8
+ /** Options for acquireSlot polling behavior and callbacks. */
9
+ export type AcquireSlotOptions = {
10
+ /** Called when the function starts waiting (all slots occupied). */
11
+ onWaiting: ((info: string) => void) | null;
12
+ /** Called when a slot becomes available after waiting. */
13
+ onAcquired: (() => void) | null;
14
+ /** Poll interval in milliseconds (default: 2000). */
15
+ pollIntervalMs: number;
16
+ /** AbortSignal to cancel waiting. */
17
+ signal: AbortSignal | null;
18
+ };
19
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/concurrency/types.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,MAAM,MAAM,UAAU,GAAG;IACvB,iEAAiE;IACjE,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,uDAAuD;IACvD,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,8DAA8D;AAC9D,MAAM,MAAM,kBAAkB,GAAG;IAC/B,oEAAoE;IACpE,SAAS,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IAC3C,0DAA0D;IAC1D,UAAU,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC;IAChC,qDAAqD;IACrD,cAAc,EAAE,MAAM,CAAC;IACvB,qCAAqC;IACrC,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;CAC5B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/concurrency/types.ts"],"names":[],"mappings":""}
package/dist/format.d.ts CHANGED
@@ -1,3 +1,70 @@
1
- export type OutputFormat = "json" | "yaml";
2
- export declare function formatOutput(data: unknown, format: OutputFormat): string;
1
+ import type { Hash, Store } from "@ocas/core";
2
+ import type { OutputSchemaName } from "@united-workforce/protocol";
3
+ import type { UwfSchemaHashes } from "./schemas.js";
4
+ /**
5
+ * Five output formats supported by the uwf CLI. `text` is the default and
6
+ * produces a Liquid-rendered human-readable view. `json` and `yaml` wrap the
7
+ * payload in an ocas envelope `{ type, value }` for self-describing output.
8
+ * `raw-json` and `raw-yaml` emit the bare value, preserving 0.5.0 byte-for-byte
9
+ * output for backward-compat consumers.
10
+ */
11
+ export type OutputFormat = "text" | "json" | "yaml" | "raw-json" | "raw-yaml";
12
+ export declare const SUPPORTED_FORMATS: readonly OutputFormat[];
13
+ export declare function isOutputFormat(v: string): v is OutputFormat;
14
+ /**
15
+ * Per-command text renderer registry. Maps a fully-qualified command path
16
+ * (e.g. `"thread list"`, `"workflow show"`) to a function that converts
17
+ * the command's payload into a human-readable string.
18
+ *
19
+ * Renderers must:
20
+ * - Always return a `string` (never `undefined`).
21
+ * - Tolerate missing/null fields without throwing.
22
+ *
23
+ * The Liquid template path inside `writeEnvelope` is the primary rendering
24
+ * implementation. This registry exists so callers without a CAS store
25
+ * (tests, library consumers) can resolve `text` rendering, and so
26
+ * `formatOutput(data, "text", commandPath)` returns a meaningful string.
27
+ */
28
+ export type TextRenderer = (data: unknown) => string;
29
+ export declare const TEXT_RENDERERS: Record<string, TextRenderer>;
30
+ /** Look up a registered text renderer by command path. */
31
+ export declare function getTextRenderer(commandPath: string): TextRenderer | undefined;
32
+ /** Register (or override) a text renderer for a command path. */
33
+ export declare function registerTextRenderer(commandPath: string, renderer: TextRenderer): void;
34
+ /**
35
+ * Format a payload as a string in the requested output format.
36
+ *
37
+ * For `"text"`, `formatOutput` looks up the registered renderer for
38
+ * `commandPath` (when provided) and falls back to a JSON serialization when
39
+ * no renderer is registered. The result is always a `string` — never
40
+ * `undefined`. For `"json"` and `"yaml"` the bare value is serialized.
41
+ * For `"raw-json"` and `"raw-yaml"` the output is identical to `"json"` /
42
+ * `"yaml"` (both modes emit the bare value; envelope wrapping happens in
43
+ * `writeEnvelope`).
44
+ *
45
+ * Note: this is the legacy in-process formatter used by raw output paths
46
+ * (`thread cancel`, `step fork`, `setup`, `log/config`) and tests. Production
47
+ * commands with a registered output schema go through `writeEnvelope`.
48
+ */
49
+ export declare function formatOutput(data: unknown, format: OutputFormat, commandPath?: string): string;
50
+ /**
51
+ * Resolve the CAS hash for an output schema by short name, caching the result
52
+ * for the lifetime of the process.
53
+ */
54
+ export declare function resolveOutputSchemaHash(outputs: Record<OutputSchemaName, Hash>, schemaName: OutputSchemaName): Hash;
55
+ export type WriteEnvelopeOptions = {
56
+ format: OutputFormat;
57
+ store: Store;
58
+ schemas: UwfSchemaHashes;
59
+ };
60
+ /**
61
+ * Wrap a CLI command payload in the chosen format and write it to stdout.
62
+ *
63
+ * - `text` → Liquid template at `@ocas/template/text/<hash>` (fallback YAML envelope)
64
+ * - `json` → `{"type":<hash>,"value":<payload>}` (envelope JSON)
65
+ * - `yaml` → envelope as multi-line YAML
66
+ * - `raw-json` → bare `<payload>` (legacy 0.5.0 shape)
67
+ * - `raw-yaml` → bare `<payload>` (legacy 0.5.0 shape)
68
+ */
69
+ export declare function writeEnvelope(payload: unknown, schemaName: OutputSchemaName, options: WriteEnvelopeOptions): Promise<void>;
3
70
  //# sourceMappingURL=format.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../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,gBAAgB,EAAE,IAAI,CAAC,EACvC,UAAU,EAAE,gBAAgB,GAC3B,IAAI,CASN;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,YAAY,CAAC;IACrB,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,EAAE,eAAe,CAAC;CAC1B,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,gBAAgB,EAC5B,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,IAAI,CAAC,CA2Bf"}
package/dist/format.js CHANGED
@@ -1,10 +1,207 @@
1
+ import { Liquid } from "liquidjs";
1
2
  import { stringify } from "yaml";
2
- export function formatOutput(data, format) {
3
+ import { renderConfigGet, renderConfigList, renderConfigSet, renderLogList, renderLogShow, renderStepList, renderStepShow, renderThreadCancel, renderThreadList, renderThreadShow, renderThreadStart, renderThreadStop, renderWorkflowList, renderWorkflowShow, } from "./text-renderers.js";
4
+ export const SUPPORTED_FORMATS = [
5
+ "text",
6
+ "json",
7
+ "yaml",
8
+ "raw-json",
9
+ "raw-yaml",
10
+ ];
11
+ export function isOutputFormat(v) {
12
+ return SUPPORTED_FORMATS.includes(v);
13
+ }
14
+ export const TEXT_RENDERERS = {
15
+ "thread list": renderThreadList,
16
+ "thread show": renderThreadShow,
17
+ "thread start": renderThreadStart,
18
+ "thread cancel": renderThreadCancel,
19
+ "thread stop": renderThreadStop,
20
+ "workflow list": renderWorkflowList,
21
+ "workflow show": renderWorkflowShow,
22
+ "step list": renderStepList,
23
+ "step show": renderStepShow,
24
+ "config list": renderConfigList,
25
+ "config get": renderConfigGet,
26
+ "config set": renderConfigSet,
27
+ "log list": renderLogList,
28
+ "log show": renderLogShow,
29
+ };
30
+ /** Look up a registered text renderer by command path. */
31
+ export function getTextRenderer(commandPath) {
32
+ return TEXT_RENDERERS[commandPath];
33
+ }
34
+ /** Register (or override) a text renderer for a command path. */
35
+ export function registerTextRenderer(commandPath, renderer) {
36
+ TEXT_RENDERERS[commandPath] = renderer;
37
+ }
38
+ /**
39
+ * Format a payload as a string in the requested output format.
40
+ *
41
+ * For `"text"`, `formatOutput` looks up the registered renderer for
42
+ * `commandPath` (when provided) and falls back to a JSON serialization when
43
+ * no renderer is registered. The result is always a `string` — never
44
+ * `undefined`. For `"json"` and `"yaml"` the bare value is serialized.
45
+ * For `"raw-json"` and `"raw-yaml"` the output is identical to `"json"` /
46
+ * `"yaml"` (both modes emit the bare value; envelope wrapping happens in
47
+ * `writeEnvelope`).
48
+ *
49
+ * Note: this is the legacy in-process formatter used by raw output paths
50
+ * (`thread cancel`, `step fork`, `setup`, `log/config`) and tests. Production
51
+ * commands with a registered output schema go through `writeEnvelope`.
52
+ */
53
+ export function formatOutput(data, format, commandPath) {
3
54
  switch (format) {
4
55
  case "json":
56
+ case "raw-json":
5
57
  return JSON.stringify(data);
6
58
  case "yaml":
59
+ case "raw-yaml":
7
60
  return stringify(data, { aliasDuplicateObjects: false }).trimEnd();
61
+ case "text": {
62
+ if (commandPath !== undefined) {
63
+ const renderer = TEXT_RENDERERS[commandPath];
64
+ if (renderer !== undefined) {
65
+ return renderer(data);
66
+ }
67
+ }
68
+ // Fallback: JSON pretty-printed so `formatOutput(_, "text")` never returns
69
+ // `"undefined"` (the bug from issue #327).
70
+ return JSON.stringify(data, null, 2);
71
+ }
72
+ }
73
+ }
74
+ const schemaHashCache = new Map();
75
+ /**
76
+ * Resolve the CAS hash for an output schema by short name, caching the result
77
+ * for the lifetime of the process.
78
+ */
79
+ export function resolveOutputSchemaHash(outputs, schemaName) {
80
+ const cached = schemaHashCache.get(schemaName);
81
+ if (cached !== undefined)
82
+ return cached;
83
+ const hash = outputs[schemaName];
84
+ if (hash === undefined) {
85
+ throw new Error(`output schema not registered: @uwf/output/${schemaName}`);
86
+ }
87
+ schemaHashCache.set(schemaName, hash);
88
+ return hash;
89
+ }
90
+ /**
91
+ * Wrap a CLI command payload in the chosen format and write it to stdout.
92
+ *
93
+ * - `text` → Liquid template at `@ocas/template/text/<hash>` (fallback YAML envelope)
94
+ * - `json` → `{"type":<hash>,"value":<payload>}` (envelope JSON)
95
+ * - `yaml` → envelope as multi-line YAML
96
+ * - `raw-json` → bare `<payload>` (legacy 0.5.0 shape)
97
+ * - `raw-yaml` → bare `<payload>` (legacy 0.5.0 shape)
98
+ */
99
+ export async function writeEnvelope(payload, schemaName, options) {
100
+ const { format, store, schemas } = options;
101
+ const schemaHash = resolveOutputSchemaHash(schemas.outputs, schemaName);
102
+ let body;
103
+ switch (format) {
104
+ case "json":
105
+ body = JSON.stringify({ type: schemaHash, value: payload });
106
+ break;
107
+ case "yaml":
108
+ body = stringify({ type: schemaHash, value: payload }, { aliasDuplicateObjects: false }).trimEnd();
109
+ break;
110
+ case "raw-json":
111
+ body = JSON.stringify(payload);
112
+ break;
113
+ case "raw-yaml":
114
+ body = stringify(payload, { aliasDuplicateObjects: false }).trimEnd();
115
+ break;
116
+ case "text":
117
+ body = await renderEnvelopeText(store, schemaHash, payload, schemaName);
118
+ break;
119
+ }
120
+ process.stdout.write(`${body}\n`);
121
+ }
122
+ let liquidEngine = null;
123
+ function firstRole(graph, current) {
124
+ const transitions = graph[current];
125
+ if (!transitions)
126
+ return null;
127
+ const firstKey = Object.keys(transitions)[0];
128
+ if (firstKey === undefined)
129
+ return null;
130
+ const next = transitions[firstKey]?.role;
131
+ return typeof next === "string" ? next : null;
132
+ }
133
+ function buildGraphPath(graph, start, limit) {
134
+ const out = [start];
135
+ const seen = new Set([start]);
136
+ let cur = start;
137
+ while (out.length < limit) {
138
+ const next = firstRole(graph, cur);
139
+ if (next === null || next === "$END") {
140
+ out.push("$END");
141
+ break;
142
+ }
143
+ if (seen.has(next))
144
+ break;
145
+ seen.add(next);
146
+ out.push(next);
147
+ cur = next;
148
+ }
149
+ return out;
150
+ }
151
+ function getLiquidEngine() {
152
+ if (liquidEngine !== null)
153
+ return liquidEngine;
154
+ const engine = new Liquid({ cache: false, strictFilters: false, strictVariables: false });
155
+ engine.registerFilter("keys", (input) => input !== null && typeof input === "object" ? Object.keys(input) : []);
156
+ engine.registerFilter("graph_path", (graph, start, max) => {
157
+ if (graph === null || typeof graph !== "object")
158
+ return [];
159
+ const limit = typeof max === "number" ? max : 5;
160
+ const startNode = typeof start === "string" ? start : "$START";
161
+ return buildGraphPath(graph, startNode, limit);
162
+ });
163
+ liquidEngine = engine;
164
+ return engine;
165
+ }
166
+ function readTemplateContent(store, schemaHash) {
167
+ const varName = `@ocas/template/text/${schemaHash}`;
168
+ const variable = store.var.get(varName);
169
+ if (variable === null)
170
+ return null;
171
+ const node = store.cas.get(variable.value);
172
+ if (node === null)
173
+ return null;
174
+ if (typeof node.payload !== "string")
175
+ return null;
176
+ return node.payload;
177
+ }
178
+ function buildLiquidContext(payload, schemaHash) {
179
+ const ctx = { payload, type: schemaHash };
180
+ if (payload !== null && typeof payload === "object" && !Array.isArray(payload)) {
181
+ for (const [k, v] of Object.entries(payload)) {
182
+ if (k !== "payload" && k !== "type") {
183
+ ctx[k] = v;
184
+ }
185
+ }
186
+ }
187
+ return ctx;
188
+ }
189
+ async function renderEnvelopeText(store, schemaHash, payload, schemaName) {
190
+ const template = readTemplateContent(store, schemaHash);
191
+ if (template === null) {
192
+ process.stderr.write(`warning: missing text template for @uwf/output/${schemaName} (var @ocas/template/text/${schemaHash}); falling back to YAML\n`);
193
+ return stringify({ type: schemaHash, value: payload }, { aliasDuplicateObjects: false }).trimEnd();
194
+ }
195
+ try {
196
+ const engine = getLiquidEngine();
197
+ const context = buildLiquidContext(payload, schemaHash);
198
+ const out = await engine.parseAndRender(template, context);
199
+ return out.replace(/\n+$/, "");
200
+ }
201
+ catch (e) {
202
+ const message = e instanceof Error ? e.message : String(e);
203
+ process.stderr.write(`warning: failed to render text template for @uwf/output/${schemaName}: ${message}; falling back to YAML\n`);
204
+ return stringify({ type: schemaHash, value: payload }, { aliasDuplicateObjects: false }).trimEnd();
8
205
  }
9
206
  }
10
207
  //# sourceMappingURL=format.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"format.js","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAIjC,MAAM,UAAU,YAAY,CAAC,IAAa,EAAE,MAAoB;IAC9D,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,MAAM;YACT,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAC9B,KAAK,MAAM;YACT,OAAO,SAAS,CAAC,IAAI,EAAE,EAAE,qBAAqB,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;IACvE,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"format.js","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEjC,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,aAAa,EACb,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAW7B,MAAM,CAAC,MAAM,iBAAiB,GAA4B;IACxD,MAAM;IACN,MAAM;IACN,MAAM;IACN,UAAU;IACV,UAAU;CACX,CAAC;AAEF,MAAM,UAAU,cAAc,CAAC,CAAS;IACtC,OAAQ,iBAAuC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AAC9D,CAAC;AAkBD,MAAM,CAAC,MAAM,cAAc,GAAiC;IAC1D,aAAa,EAAE,gBAAgB;IAC/B,aAAa,EAAE,gBAAgB;IAC/B,cAAc,EAAE,iBAAiB;IACjC,eAAe,EAAE,kBAAkB;IACnC,aAAa,EAAE,gBAAgB;IAC/B,eAAe,EAAE,kBAAk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