@united-workforce/cli 0.4.0 → 0.6.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 (223) hide show
  1. package/README.md +30 -3
  2. package/dist/.build-fingerprint +1 -0
  3. package/dist/__tests__/adapter-json-roundtrip.test.js +16 -6
  4. package/dist/__tests__/adapter-json-roundtrip.test.js.map +1 -1
  5. package/dist/__tests__/concurrency.test.d.ts +2 -0
  6. package/dist/__tests__/concurrency.test.d.ts.map +1 -0
  7. package/dist/__tests__/concurrency.test.js +196 -0
  8. package/dist/__tests__/concurrency.test.js.map +1 -0
  9. package/dist/__tests__/config-text-renderer.test.d.ts +2 -0
  10. package/dist/__tests__/config-text-renderer.test.d.ts.map +1 -0
  11. package/dist/__tests__/config-text-renderer.test.js +137 -0
  12. package/dist/__tests__/config-text-renderer.test.js.map +1 -0
  13. package/dist/__tests__/e2e-mock-agent.test.js +23 -7
  14. package/dist/__tests__/e2e-mock-agent.test.js.map +1 -1
  15. package/dist/__tests__/format-text-default.test.d.ts +2 -0
  16. package/dist/__tests__/format-text-default.test.d.ts.map +1 -0
  17. package/dist/__tests__/format-text-default.test.js +43 -0
  18. package/dist/__tests__/format-text-default.test.js.map +1 -0
  19. package/dist/__tests__/format-text-registry.test.d.ts +2 -0
  20. package/dist/__tests__/format-text-registry.test.d.ts.map +1 -0
  21. package/dist/__tests__/format-text-registry.test.js +158 -0
  22. package/dist/__tests__/format-text-registry.test.js.map +1 -0
  23. package/dist/__tests__/issue-180-workflow-ref-removed.test.js +1 -1
  24. package/dist/__tests__/log-text-renderer.test.d.ts +2 -0
  25. package/dist/__tests__/log-text-renderer.test.d.ts.map +1 -0
  26. package/dist/__tests__/log-text-renderer.test.js +265 -0
  27. package/dist/__tests__/log-text-renderer.test.js.map +1 -0
  28. package/dist/__tests__/output-mapper-thread-list-startedat.test.d.ts +2 -0
  29. package/dist/__tests__/output-mapper-thread-list-startedat.test.d.ts.map +1 -0
  30. package/dist/__tests__/output-mapper-thread-list-startedat.test.js +102 -0
  31. package/dist/__tests__/output-mapper-thread-list-startedat.test.js.map +1 -0
  32. package/dist/__tests__/output-mapper-workflow-add.test.d.ts +2 -0
  33. package/dist/__tests__/output-mapper-workflow-add.test.d.ts.map +1 -0
  34. package/dist/__tests__/output-mapper-workflow-add.test.js +22 -0
  35. package/dist/__tests__/output-mapper-workflow-add.test.js.map +1 -0
  36. package/dist/__tests__/pid-recycling.test.js +9 -7
  37. package/dist/__tests__/pid-recycling.test.js.map +1 -1
  38. package/dist/__tests__/prompt.test.js +46 -4
  39. package/dist/__tests__/prompt.test.js.map +1 -1
  40. package/dist/__tests__/resolve-head-hash.test.js +8 -0
  41. package/dist/__tests__/resolve-head-hash.test.js.map +1 -1
  42. package/dist/__tests__/solve-issue-tea-worktree.test.js +3 -1
  43. package/dist/__tests__/solve-issue-tea-worktree.test.js.map +1 -1
  44. package/dist/__tests__/step-ask.test.js +9 -1
  45. package/dist/__tests__/step-ask.test.js.map +1 -1
  46. package/dist/__tests__/store-unified-threads.test.js +19 -17
  47. package/dist/__tests__/store-unified-threads.test.js.map +1 -1
  48. package/dist/__tests__/thread-agent-failure-suspended.test.d.ts +2 -0
  49. package/dist/__tests__/thread-agent-failure-suspended.test.d.ts.map +1 -0
  50. package/dist/__tests__/thread-agent-failure-suspended.test.js +332 -0
  51. package/dist/__tests__/thread-agent-failure-suspended.test.js.map +1 -0
  52. package/dist/__tests__/thread-cancel-status.test.js +19 -13
  53. package/dist/__tests__/thread-cancel-status.test.js.map +1 -1
  54. package/dist/__tests__/thread-cancel-text-renderer.test.d.ts +2 -0
  55. package/dist/__tests__/thread-cancel-text-renderer.test.d.ts.map +1 -0
  56. package/dist/__tests__/thread-cancel-text-renderer.test.js +110 -0
  57. package/dist/__tests__/thread-cancel-text-renderer.test.js.map +1 -0
  58. package/dist/__tests__/thread-join.test.d.ts +2 -0
  59. package/dist/__tests__/thread-join.test.d.ts.map +1 -0
  60. package/dist/__tests__/thread-join.test.js +77 -0
  61. package/dist/__tests__/thread-join.test.js.map +1 -0
  62. package/dist/__tests__/thread-list-filters.test.js +10 -8
  63. package/dist/__tests__/thread-list-filters.test.js.map +1 -1
  64. package/dist/__tests__/thread-list-template-ms-date.test.d.ts +2 -0
  65. package/dist/__tests__/thread-list-template-ms-date.test.d.ts.map +1 -0
  66. package/dist/__tests__/thread-list-template-ms-date.test.js +102 -0
  67. package/dist/__tests__/thread-list-template-ms-date.test.js.map +1 -0
  68. package/dist/__tests__/thread-list-workflow-corrupt.test.d.ts +2 -0
  69. package/dist/__tests__/thread-list-workflow-corrupt.test.d.ts.map +1 -0
  70. package/dist/__tests__/thread-list-workflow-corrupt.test.js +157 -0
  71. package/dist/__tests__/thread-list-workflow-corrupt.test.js.map +1 -0
  72. package/dist/__tests__/thread-poke.test.js +15 -2
  73. package/dist/__tests__/thread-poke.test.js.map +1 -1
  74. package/dist/__tests__/thread-read-xml-tags.test.js +10 -9
  75. package/dist/__tests__/thread-read-xml-tags.test.js.map +1 -1
  76. package/dist/__tests__/thread-resume.test.js +11 -1
  77. package/dist/__tests__/thread-resume.test.js.map +1 -1
  78. package/dist/__tests__/thread-start-cwd-cli.test.js +15 -3
  79. package/dist/__tests__/thread-start-cwd-cli.test.js.map +1 -1
  80. package/dist/__tests__/thread-stop-text-renderer.test.d.ts +2 -0
  81. package/dist/__tests__/thread-stop-text-renderer.test.d.ts.map +1 -0
  82. package/dist/__tests__/thread-stop-text-renderer.test.js +148 -0
  83. package/dist/__tests__/thread-stop-text-renderer.test.js.map +1 -0
  84. package/dist/__tests__/thread-suspend-step.test.js +5 -2
  85. package/dist/__tests__/thread-suspend-step.test.js.map +1 -1
  86. package/dist/__tests__/thread-test-helpers.d.ts +7 -0
  87. package/dist/__tests__/thread-test-helpers.d.ts.map +1 -1
  88. package/dist/__tests__/thread-test-helpers.js +13 -0
  89. package/dist/__tests__/thread-test-helpers.js.map +1 -1
  90. package/dist/__tests__/thread.test.js +11 -9
  91. package/dist/__tests__/thread.test.js.map +1 -1
  92. package/dist/__tests__/validate-semantic.test.js +56 -2
  93. package/dist/__tests__/validate-semantic.test.js.map +1 -1
  94. package/dist/__tests__/workflow-list-recursive.test.js +10 -7
  95. package/dist/__tests__/workflow-list-recursive.test.js.map +1 -1
  96. package/dist/__tests__/workflow-paths.test.d.ts +2 -0
  97. package/dist/__tests__/workflow-paths.test.d.ts.map +1 -0
  98. package/dist/__tests__/workflow-paths.test.js +261 -0
  99. package/dist/__tests__/workflow-paths.test.js.map +1 -0
  100. package/dist/__tests__/workflow-resolution.test.js +10 -7
  101. package/dist/__tests__/workflow-resolution.test.js.map +1 -1
  102. package/dist/__tests__/workflow-show-resolution.test.js +10 -7
  103. package/dist/__tests__/workflow-show-resolution.test.js.map +1 -1
  104. package/dist/__tests__/workflow-validate.test.js +75 -55
  105. package/dist/__tests__/workflow-validate.test.js.map +1 -1
  106. package/dist/__tests__/write-envelope.test.d.ts +2 -0
  107. package/dist/__tests__/write-envelope.test.d.ts.map +1 -0
  108. package/dist/__tests__/write-envelope.test.js +201 -0
  109. package/dist/__tests__/write-envelope.test.js.map +1 -0
  110. package/dist/cli.js +76 -36
  111. package/dist/cli.js.map +1 -1
  112. package/dist/commands/config.d.ts +5 -0
  113. package/dist/commands/config.d.ts.map +1 -1
  114. package/dist/commands/config.js +81 -3
  115. package/dist/commands/config.js.map +1 -1
  116. package/dist/commands/prompt.d.ts.map +1 -1
  117. package/dist/commands/prompt.js +42 -29
  118. package/dist/commands/prompt.js.map +1 -1
  119. package/dist/commands/setup.d.ts +9 -4
  120. package/dist/commands/setup.d.ts.map +1 -1
  121. package/dist/commands/setup.js +51 -7
  122. package/dist/commands/setup.js.map +1 -1
  123. package/dist/commands/thread.d.ts +12 -0
  124. package/dist/commands/thread.d.ts.map +1 -1
  125. package/dist/commands/thread.js +226 -9
  126. package/dist/commands/thread.js.map +1 -1
  127. package/dist/commands/workflow.d.ts +2 -2
  128. package/dist/commands/workflow.d.ts.map +1 -1
  129. package/dist/commands/workflow.js +26 -10
  130. package/dist/commands/workflow.js.map +1 -1
  131. package/dist/concurrency/concurrency.d.ts +34 -0
  132. package/dist/concurrency/concurrency.d.ts.map +1 -0
  133. package/dist/concurrency/concurrency.js +216 -0
  134. package/dist/concurrency/concurrency.js.map +1 -0
  135. package/dist/concurrency/index.d.ts +3 -0
  136. package/dist/concurrency/index.d.ts.map +1 -0
  137. package/dist/concurrency/index.js +2 -0
  138. package/dist/concurrency/index.js.map +1 -0
  139. package/dist/concurrency/types.d.ts +19 -0
  140. package/dist/concurrency/types.d.ts.map +1 -0
  141. package/dist/concurrency/types.js +2 -0
  142. package/dist/concurrency/types.js.map +1 -0
  143. package/dist/format.d.ts +69 -2
  144. package/dist/format.d.ts.map +1 -1
  145. package/dist/format.js +198 -1
  146. package/dist/format.js.map +1 -1
  147. package/dist/output-mappers.d.ts +122 -0
  148. package/dist/output-mappers.d.ts.map +1 -0
  149. package/dist/output-mappers.js +134 -0
  150. package/dist/output-mappers.js.map +1 -0
  151. package/dist/schemas.d.ts +4 -1
  152. package/dist/schemas.d.ts.map +1 -1
  153. package/dist/schemas.js +31 -4
  154. package/dist/schemas.js.map +1 -1
  155. package/dist/store.d.ts +11 -0
  156. package/dist/store.d.ts.map +1 -1
  157. package/dist/store.js +20 -1
  158. package/dist/store.js.map +1 -1
  159. package/dist/text-renderers.d.ts +30 -0
  160. package/dist/text-renderers.d.ts.map +1 -0
  161. package/dist/text-renderers.js +251 -0
  162. package/dist/text-renderers.js.map +1 -0
  163. package/dist/validate-semantic.d.ts.map +1 -1
  164. package/dist/validate-semantic.js +28 -11
  165. package/dist/validate-semantic.js.map +1 -1
  166. package/examples/brainstorm.yaml +130 -0
  167. package/examples/debate.yaml +169 -0
  168. package/examples/socratic-questioning.yaml +112 -0
  169. package/package.json +12 -11
  170. package/src/__tests__/adapter-json-roundtrip.test.ts +15 -6
  171. package/src/__tests__/concurrency.test.ts +266 -0
  172. package/src/__tests__/config-text-renderer.test.ts +156 -0
  173. package/src/__tests__/e2e-mock-agent.test.ts +45 -7
  174. package/src/__tests__/format-text-default.test.ts +49 -0
  175. package/src/__tests__/format-text-registry.test.ts +173 -0
  176. package/src/__tests__/issue-180-workflow-ref-removed.test.ts +1 -1
  177. package/src/__tests__/log-text-renderer.test.ts +294 -0
  178. package/src/__tests__/output-mapper-thread-list-startedat.test.ts +124 -0
  179. package/src/__tests__/output-mapper-workflow-add.test.ts +24 -0
  180. package/src/__tests__/pid-recycling.test.ts +9 -8
  181. package/src/__tests__/prompt.test.ts +48 -4
  182. package/src/__tests__/resolve-head-hash.test.ts +7 -0
  183. package/src/__tests__/solve-issue-tea-worktree.test.ts +3 -1
  184. package/src/__tests__/step-ask.test.ts +8 -1
  185. package/src/__tests__/store-unified-threads.test.ts +21 -18
  186. package/src/__tests__/thread-agent-failure-suspended.test.ts +406 -0
  187. package/src/__tests__/thread-cancel-status.test.ts +21 -14
  188. package/src/__tests__/thread-cancel-text-renderer.test.ts +125 -0
  189. package/src/__tests__/thread-join.test.ts +103 -0
  190. package/src/__tests__/thread-list-filters.test.ts +9 -9
  191. package/src/__tests__/thread-list-template-ms-date.test.ts +110 -0
  192. package/src/__tests__/thread-list-workflow-corrupt.test.ts +198 -0
  193. package/src/__tests__/thread-poke.test.ts +14 -2
  194. package/src/__tests__/thread-read-xml-tags.test.ts +9 -11
  195. package/src/__tests__/thread-resume.test.ts +10 -1
  196. package/src/__tests__/thread-start-cwd-cli.test.ts +15 -3
  197. package/src/__tests__/thread-stop-text-renderer.test.ts +168 -0
  198. package/src/__tests__/thread-suspend-step.test.ts +5 -2
  199. package/src/__tests__/thread-test-helpers.ts +15 -1
  200. package/src/__tests__/thread.test.ts +10 -10
  201. package/src/__tests__/validate-semantic.test.ts +59 -2
  202. package/src/__tests__/workflow-list-recursive.test.ts +9 -9
  203. package/src/__tests__/workflow-paths.test.ts +337 -0
  204. package/src/__tests__/workflow-resolution.test.ts +9 -8
  205. package/src/__tests__/workflow-show-resolution.test.ts +9 -8
  206. package/src/__tests__/workflow-validate.test.ts +78 -56
  207. package/src/__tests__/write-envelope.test.ts +257 -0
  208. package/src/cli.ts +111 -35
  209. package/src/commands/config.ts +85 -3
  210. package/src/commands/prompt.ts +42 -29
  211. package/src/commands/setup.ts +57 -7
  212. package/src/commands/thread.ts +280 -9
  213. package/src/commands/workflow.ts +32 -11
  214. package/src/concurrency/concurrency.ts +245 -0
  215. package/src/concurrency/index.ts +10 -0
  216. package/src/concurrency/types.ts +19 -0
  217. package/src/format.ts +282 -2
  218. package/src/output-mappers.ts +255 -0
  219. package/src/schemas.ts +39 -3
  220. package/src/store.ts +25 -1
  221. package/src/text-renderers.ts +355 -0
  222. package/src/validate-semantic.ts +33 -12
  223. package/LICENSE +0 -21
@@ -0,0 +1,169 @@
1
+ version: 1
2
+ name: debate
3
+ description: "Multi-role structured debate with critical thinking framework and host summary."
4
+
5
+ # Shared frontmatter schema for debater roles (YAML anchor)
6
+ x-debater-frontmatter: &debater-frontmatter
7
+ type: object
8
+ oneOf:
9
+ - properties:
10
+ $status: { const: speak }
11
+ argument: { type: string }
12
+ required: [$status, argument]
13
+ - properties:
14
+ $status: { const: conceded }
15
+ reason: { type: string }
16
+ required: [$status, reason]
17
+ - properties:
18
+ $status: { const: final }
19
+ closing: { type: string }
20
+ required: [$status, closing]
21
+
22
+ roles:
23
+ proponent:
24
+ description: "Argues FOR the proposition"
25
+ goal: "Build a compelling case for the proposition through logical reasoning and evidence"
26
+ capabilities: []
27
+ procedure: |
28
+ You are an experienced scholar arguing FOR the proposition.
29
+
30
+ ## Critical Thinking Framework (execute before every speech)
31
+
32
+ ### A. Pre-speech reflection (internal, do not output)
33
+ - Does every step in my argument chain hold? Any hidden assumptions or logical gaps?
34
+ - If I were my opponent, how would I attack this? Where am I weakest?
35
+ - Does my evidence actually support my claim, or could it backfire?
36
+ - Should I go on offense or defense this round?
37
+
38
+ ### B. Evidence discipline
39
+ - Verify key numbers — watch for order-of-magnitude errors
40
+ - Assess data freshness — fast-moving fields have short half-lives
41
+ - Distinguish primary data from secondary citations, expert opinion, and common assumptions
42
+
43
+ ### C. Anti-fragility
44
+ - Anticipate counterarguments; preemptively strengthen or strategically abandon weak points
45
+ - Catch logical gaps, data misuse, or outdated claims in your opponent's reasoning
46
+
47
+ ## Rules
48
+ 1. Check Thread Progress to see how many times you have spoken.
49
+ 2. On your 3rd speech, you MUST output $status: final (closing statement).
50
+ 3. If genuinely convinced by the opponent, output $status: conceded.
51
+ 4. Otherwise output $status: speak and counter the opponent's points.
52
+ 5. Be rigorous, cite evidence, stay concise.
53
+ output: "Debate argument"
54
+ frontmatter: *debater-frontmatter
55
+
56
+ opponent:
57
+ description: "Argues AGAINST the proposition"
58
+ goal: "Build a compelling case against the proposition through logical reasoning and evidence"
59
+ capabilities: []
60
+ procedure: |
61
+ You are an experienced scholar arguing AGAINST the proposition.
62
+
63
+ ## Critical Thinking Framework (execute before every speech)
64
+
65
+ ### A. Pre-speech reflection (internal, do not output)
66
+ - Does every step in my argument chain hold? Any hidden assumptions or logical gaps?
67
+ - If I were my opponent, how would I attack this? Where am I weakest?
68
+ - Does my evidence actually support my claim, or could it backfire?
69
+ - Should I go on offense or defense this round?
70
+
71
+ ### B. Evidence discipline
72
+ - Verify key numbers — watch for order-of-magnitude errors
73
+ - Assess data freshness — fast-moving fields have short half-lives
74
+ - Distinguish primary data from secondary citations, expert opinion, and common assumptions
75
+
76
+ ### C. Anti-fragility
77
+ - Anticipate counterarguments; preemptively strengthen or strategically abandon weak points
78
+ - Catch logical gaps, data misuse, or outdated claims in your opponent's reasoning
79
+
80
+ ## Rules
81
+ 1. Check Thread Progress to see how many times you have spoken.
82
+ 2. On your 3rd speech, or when the proponent has issued a final statement, you MUST output $status: final.
83
+ 3. If genuinely convinced by the proponent, output $status: conceded.
84
+ 4. Otherwise output $status: speak and counter the proponent's points.
85
+ 5. Be rigorous, cite evidence, stay concise.
86
+ output: "Debate argument"
87
+ frontmatter: *debater-frontmatter
88
+
89
+ host:
90
+ description: "Debate moderator — delivers impartial summary and verdict"
91
+ goal: "Objectively review the debate, analyze both sides, and deliver a verdict"
92
+ capabilities: []
93
+ procedure: |
94
+ You are an experienced academic debate moderator.
95
+
96
+ ## Task
97
+ 1. Outline each side's core arguments
98
+ 2. Evaluate reasoning quality and evidence use
99
+ 3. Highlight the most impactful exchanges
100
+ 4. Analyze the deeper significance of the topic
101
+ 5. Deliver an overall verdict
102
+
103
+ ## Style
104
+ - Impartial but with independent judgment
105
+ - Substantive, not superficial
106
+ output: "Debate summary report"
107
+ frontmatter:
108
+ type: object
109
+ properties:
110
+ $status: { const: done }
111
+ summary: { type: string }
112
+ highlights: { type: string }
113
+ verdict: { type: string }
114
+ required: [$status, summary, highlights, verdict]
115
+
116
+ reporter:
117
+ description: "Generates an HTML report of the completed debate"
118
+ goal: "Produce a self-contained, visually polished HTML report that faithfully reproduces the entire debate with no paraphrasing."
119
+ capabilities: [run_command, write_file, read_file]
120
+ procedure: |
121
+ You are a report generator for a structured debate.
122
+
123
+ ## Steps
124
+ 1. Read Thread Progress to get the thread ID.
125
+ 2. Run: `uwf thread read <thread-id>` to get the full debate transcript.
126
+ 3. Design and write a self-contained HTML file that presents the debate beautifully.
127
+ 4. Save to `/tmp/debate-report-<thread-id>.html`.
128
+
129
+ ## HTML Report Requirements
130
+ - Title: the debate proposition
131
+ - Two-column layout comparing proponent vs opponent arguments round by round
132
+ - Key exchanges highlighted with visual callouts
133
+ - Host's verdict and summary in a prominent section
134
+ - If a side conceded, make it visually clear
135
+ - Clean typography, responsive layout, dark/light theme friendly
136
+ - All content verbatim from `uwf thread read` — do NOT paraphrase
137
+
138
+ ## Rules
139
+ 1. You MUST use `uwf thread read` to get the data — do NOT rely on context.
140
+ 2. Completely self-contained (inline styles, no CDN links).
141
+ 3. Output the file path in your response body.
142
+ output: "Confirmation that the report was generated, with the file path."
143
+ frontmatter:
144
+ type: object
145
+ properties:
146
+ $status: { const: done }
147
+ reportPath: { type: string }
148
+ required: [$status, reportPath]
149
+
150
+ graph:
151
+ $START:
152
+ new: { role: proponent, prompt: "The debate begins. You are arguing FOR the proposition. Present your opening argument." }
153
+ resume: { role: proponent, prompt: "The debate continues." }
154
+
155
+ proponent:
156
+ speak: { role: opponent, prompt: "Proponent argues:\n\n{{ argument }}\n\nYou are the opponent. Counter this argument." }
157
+ conceded: { role: host, prompt: "The proponent conceded: {{ reason }}\n\nPlease summarize the debate." }
158
+ final: { role: opponent, prompt: "Proponent's closing statement:\n\n{{ closing }}\n\nYou are the opponent. Deliver your final response." }
159
+
160
+ opponent:
161
+ speak: { role: proponent, prompt: "Opponent argues:\n\n{{ argument }}\n\nYou are the proponent. Counter this argument." }
162
+ conceded: { role: host, prompt: "The opponent conceded: {{ reason }}\n\nPlease summarize the debate." }
163
+ final: { role: host, prompt: "Opponent's closing statement:\n\n{{ closing }}\n\nThe debate is over. Please summarize." }
164
+
165
+ host:
166
+ done: { role: reporter, prompt: "Debate summary complete.\n\nSummary: {{ summary }}\nHighlights: {{ highlights }}\nVerdict: {{ verdict }}\n\nGenerate a polished HTML report of the entire debate." }
167
+
168
+ reporter:
169
+ done: { role: "$END", prompt: "Report generated." }
@@ -0,0 +1,112 @@
1
+ version: 1
2
+ name: socratic-questioning
3
+ description: "Socratic dialogue — a questioner helps the thinker examine their beliefs through probing questions."
4
+
5
+ roles:
6
+ thinker:
7
+ description: "Holds and defends a position, refining it through dialogue"
8
+ goal: "Articulate and examine your position honestly. When a question exposes a weakness, acknowledge it and refine your view rather than deflecting."
9
+ capabilities: []
10
+ procedure: |
11
+ You are a thoughtful person exploring your own beliefs through dialogue.
12
+
13
+ ## Rules
14
+ 1. Check Thread Progress to see how many times you have responded.
15
+ 2. On your 3rd response, you MUST output $status: synthesis (your refined position).
16
+ 3. Be honest — if a question reveals a gap, say so and adjust.
17
+ 4. Build on previous exchanges, don't repeat yourself.
18
+ 5. Keep responses focused (under 300 words).
19
+ output: "Your response to the question, or your final synthesis."
20
+ frontmatter:
21
+ oneOf:
22
+ - properties:
23
+ $status: { const: respond }
24
+ insight: { type: string }
25
+ required: [$status, insight]
26
+ - properties:
27
+ $status: { const: synthesis }
28
+ revisedPosition: { type: string }
29
+ keyInsights: { type: string }
30
+ required: [$status, revisedPosition, keyInsights]
31
+
32
+ questioner:
33
+ description: "Asks probing questions to help the thinker examine assumptions"
34
+ goal: "Guide the thinker to deeper understanding through questions — never lecture, never argue, never assert your own position."
35
+ capabilities: []
36
+ procedure: |
37
+ You are a Socratic questioner. Your only tool is the question.
38
+
39
+ ## Questioning techniques
40
+ - **Clarification**: "What do you mean by...?" / "Can you give an example?"
41
+ - **Assumptions**: "What are you assuming here?" / "Why do you believe that's true?"
42
+ - **Evidence**: "What evidence supports this?" / "How would you respond to someone who says...?"
43
+ - **Implications**: "If that's true, what follows?" / "What would change if you're wrong?"
44
+ - **Perspective**: "How might someone in a different situation see this?"
45
+
46
+ ## Rules
47
+ 1. Ask 1-2 questions per turn, not more.
48
+ 2. NEVER state your own opinion or argue a position.
49
+ 3. Build on the thinker's previous answer — don't jump to unrelated topics.
50
+ 4. When the thinker reaches a synthesis, output $status: done.
51
+ 5. Keep questions concise and sharp.
52
+ output: "Your probing question(s)."
53
+ frontmatter:
54
+ oneOf:
55
+ - properties:
56
+ $status: { const: ask }
57
+ question: { type: string }
58
+ required: [$status, question]
59
+ - properties:
60
+ $status: { const: done }
61
+ summary: { type: string }
62
+ required: [$status, summary]
63
+
64
+ reporter:
65
+ description: "Generates an HTML report of the completed Socratic dialogue"
66
+ goal: "Produce a self-contained, visually polished HTML report that faithfully reproduces the entire dialogue with no paraphrasing."
67
+ capabilities: [run_command, write_file, read_file]
68
+ procedure: |
69
+ You are a report generator for a Socratic questioning session.
70
+
71
+ ## Steps
72
+ 1. Read Thread Progress to get the thread ID.
73
+ 2. Run: `uwf thread read <thread-id>` to get the full dialogue transcript.
74
+ 3. Design and write a self-contained HTML file that presents the dialogue beautifully.
75
+ 4. Save to `/tmp/socratic-report-<thread-id>.html`.
76
+
77
+ ## HTML Report Requirements
78
+ - Title: the original topic/position being examined
79
+ - Each exchange as a dialogue card (questioner question → thinker response)
80
+ - Visual distinction between questions and reflections
81
+ - The thinker's initial position and final synthesis prominently displayed
82
+ - A "journey" section showing how the position evolved
83
+ - Clean typography, responsive layout, dark/light theme friendly
84
+ - All content verbatim from `uwf thread read` — do NOT paraphrase
85
+
86
+ ## Rules
87
+ 1. You MUST use `uwf thread read` to get the data — do NOT rely on context.
88
+ 2. Completely self-contained (inline styles, no CDN links).
89
+ 3. Output the file path in your response body.
90
+ output: "Confirmation that the report was generated, with the file path."
91
+ frontmatter:
92
+ type: object
93
+ properties:
94
+ $status: { const: done }
95
+ reportPath: { type: string }
96
+ required: [$status, reportPath]
97
+
98
+ graph:
99
+ $START:
100
+ new: { role: thinker, prompt: "State your initial position on the topic. Be clear about what you believe and why." }
101
+ resume: { role: thinker, prompt: "Continue the dialogue from where you left off." }
102
+
103
+ thinker:
104
+ respond: { role: questioner, prompt: "The thinker says:\n\n{{ _body }}\n\nAsk a probing question to help them examine this further." }
105
+ synthesis: { role: questioner, prompt: "The thinker has reached a synthesis:\n\n{{ _body }}\n\nBriefly summarize the journey of this dialogue." }
106
+
107
+ questioner:
108
+ ask: { role: thinker, prompt: "The questioner asks:\n\n{{ _body }}\n\nReflect on this question and respond honestly." }
109
+ done: { role: reporter, prompt: "Dialogue complete.\n\nSummary: {{ summary }}\n\nGenerate a polished HTML report of the entire Socratic dialogue." }
110
+
111
+ reporter:
112
+ done: { role: "$END", prompt: "Report generated." }
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@united-workforce/cli",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "files": [
5
5
  "src",
6
6
  "dist",
7
+ "examples",
7
8
  "package.json"
8
9
  ],
9
10
  "type": "module",
@@ -13,13 +14,17 @@
13
14
  "dependencies": {
14
15
  "@ocas/core": "^0.5.0",
15
16
  "@ocas/fs": "^0.4.1",
17
+ "@united-workforce/protocol": "workspace:^",
18
+ "@united-workforce/util": "workspace:^",
19
+ "@united-workforce/util-agent": "workspace:^",
16
20
  "commander": "^14.0.3",
17
21
  "dotenv": "^16.6.1",
18
22
  "liquidjs": "^10.27.0",
19
- "yaml": "^2.8.4",
20
- "@united-workforce/protocol": "^0.2.0",
21
- "@united-workforce/util": "^0.1.5",
22
- "@united-workforce/util-agent": "^0.2.0"
23
+ "yaml": "^2.8.4"
24
+ },
25
+ "scripts": {
26
+ "test": "vitest run src/",
27
+ "test:ci": "vitest run src/"
23
28
  },
24
29
  "publishConfig": {
25
30
  "access": "public"
@@ -34,9 +39,5 @@
34
39
  "bugs": {
35
40
  "url": "https://git.shazhou.work/shazhou/united-workforce/issues"
36
41
  },
37
- "license": "MIT",
38
- "scripts": {
39
- "test": "vitest run src/",
40
- "test:ci": "vitest run src/"
41
- }
42
- }
42
+ "license": "MIT"
43
+ }
@@ -25,12 +25,19 @@ const OUTPUT_SCHEMA = {
25
25
  // ── fixture ──────────────────────────────────────────────────────────────────
26
26
 
27
27
  let tmpDir: string;
28
+ let savedOcasHome: string | undefined;
28
29
 
29
30
  beforeEach(async () => {
31
+ savedOcasHome = process.env.OCAS_HOME;
30
32
  tmpDir = await mkdtemp(join(tmpdir(), "cli-uwf-roundtrip-test-"));
31
33
  });
32
34
 
33
35
  afterEach(async () => {
36
+ if (savedOcasHome === undefined) {
37
+ delete process.env.OCAS_HOME;
38
+ } else {
39
+ process.env.OCAS_HOME = savedOcasHome;
40
+ }
34
41
  await rm(tmpDir, { recursive: true, force: true });
35
42
  });
36
43
 
@@ -131,7 +138,7 @@ describe("C1: adapter JSON round-trip integration", () => {
131
138
  try {
132
139
  stdout = execFileSync(
133
140
  process.execPath,
134
- [cliPath, "thread", "exec", threadId, "--agent", mockAgentPath],
141
+ [cliPath, "--format", "raw-json", "thread", "exec", threadId, "--agent", mockAgentPath],
135
142
  {
136
143
  encoding: "utf8",
137
144
  stdio: ["ignore", "pipe", "pipe"],
@@ -162,15 +169,17 @@ describe("C1: adapter JSON round-trip integration", () => {
162
169
  throw new Error(`CLI exited with code ${exitCode}\nstdout: ${stdout}\nstderr: ${stderr}`);
163
170
  }
164
171
 
165
- // Parse CLI output
172
+ // Parse CLI output (raw-json envelope value: { threadId, workflowHash, steps: [...] })
166
173
  const cliOutput = JSON.parse(stdout.trim());
167
- expect(cliOutput).toHaveProperty("thread", threadId);
168
- expect(cliOutput).toHaveProperty("head", stepHash);
169
- expect(cliOutput.head).toMatch(/^[0-9A-HJ-NP-TV-Z]{13}$/);
174
+ expect(cliOutput).toHaveProperty("threadId", threadId);
175
+ expect(cliOutput.steps).toHaveLength(1);
176
+ const firstStep = cliOutput.steps[0];
177
+ expect(firstStep).toHaveProperty("head", stepHash);
178
+ expect(firstStep.head).toMatch(/^[0-9A-HJ-NP-TV-Z]{13}$/);
170
179
 
171
180
  // Verify the CAS step node exists and has correct metadata
172
181
  const storeAfter = await openStore(casDir);
173
- const stepNode = storeAfter.cas.get(cliOutput.head as CasRef);
182
+ const stepNode = storeAfter.cas.get(firstStep.head as CasRef);
174
183
  expect(stepNode).not.toBeNull();
175
184
 
176
185
  const payload = stepNode!.payload as StepNodePayload;
@@ -0,0 +1,266 @@
1
+ import { mkdir, mkdtemp, readdir, rm, writeFile } from "node:fs/promises";
2
+ import { tmpdir } from "node:os";
3
+ import { join } from "node:path";
4
+ import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
5
+
6
+ import {
7
+ acquireSlot,
8
+ cleanStaleSlots,
9
+ countActiveSlots,
10
+ DEFAULT_MAX_RUNNING,
11
+ getSlotsDir,
12
+ installSlotCleanup,
13
+ } from "../concurrency/index.js";
14
+
15
+ // ── test setup ────────────────────────────────────────────────────────────────
16
+
17
+ let tmpDir: string;
18
+
19
+ beforeEach(async () => {
20
+ tmpDir = await mkdtemp(join(tmpdir(), "concurrency-test-"));
21
+ });
22
+
23
+ afterEach(async () => {
24
+ await rm(tmpDir, { recursive: true, force: true });
25
+ });
26
+
27
+ // ── Spec: concurrency-acquire-slot-under-limit ──────────────────────────────
28
+
29
+ describe("acquireSlot succeeds immediately when below maxRunning", () => {
30
+ test("creates slot file and returns SlotHandle when under limit", async () => {
31
+ const handle = await acquireSlot(tmpDir, 2);
32
+
33
+ // Slot file exists
34
+ const slotsDir = getSlotsDir(tmpDir);
35
+ const files = await readdir(slotsDir);
36
+ expect(files).toContain(`${process.pid}.slot`);
37
+
38
+ // Returns a SlotHandle with release()
39
+ expect(handle).toHaveProperty("release");
40
+ expect(typeof handle.release).toBe("function");
41
+
42
+ // countActiveSlots returns 1
43
+ const count = await countActiveSlots(tmpDir);
44
+ expect(count).toBe(1);
45
+
46
+ // Cleanup
47
+ await handle.release();
48
+ });
49
+
50
+ test("returns immediately (no blocking) when slots available", async () => {
51
+ const start = Date.now();
52
+ const handle = await acquireSlot(tmpDir, 2);
53
+ const elapsed = Date.now() - start;
54
+
55
+ // Should complete in well under 1 second (no polling delay)
56
+ expect(elapsed).toBeLessThan(500);
57
+
58
+ await handle.release();
59
+ });
60
+ });
61
+
62
+ // ── Spec: concurrency-acquire-slot-blocks-at-limit ──────────────────────────
63
+
64
+ describe("acquireSlot blocks when at capacity", () => {
65
+ test("calls onWaiting when all slots are occupied", async () => {
66
+ // Create a slot file for a "live" process — use parent PID (same user, signalable)
67
+ const slotsDir = getSlotsDir(tmpDir);
68
+ await mkdir(slotsDir, { recursive: true });
69
+ const blockerPid = process.ppid;
70
+ await writeFile(join(slotsDir, `${blockerPid}.slot`), "", "utf8");
71
+
72
+ const onWaiting = vi.fn();
73
+ const onAcquired = vi.fn();
74
+
75
+ // maxRunning=1, one slot occupied → should block
76
+ // Release the blocking slot after a brief delay
77
+ setTimeout(async () => {
78
+ await rm(join(slotsDir, `${blockerPid}.slot`), { force: true });
79
+ }, 200);
80
+
81
+ const handle = await acquireSlot(tmpDir, 1, {
82
+ onWaiting,
83
+ onAcquired,
84
+ pollIntervalMs: 100,
85
+ });
86
+
87
+ expect(onWaiting).toHaveBeenCalled();
88
+ expect(onAcquired).toHaveBeenCalled();
89
+
90
+ await handle.release();
91
+ });
92
+
93
+ test("polls with interval and proceeds after slot is freed", async () => {
94
+ const slotsDir = getSlotsDir(tmpDir);
95
+ await mkdir(slotsDir, { recursive: true });
96
+ const blockerPid = process.ppid;
97
+ await writeFile(join(slotsDir, `${blockerPid}.slot`), "", "utf8");
98
+
99
+ // Remove after 250ms
100
+ setTimeout(async () => {
101
+ await rm(join(slotsDir, `${blockerPid}.slot`), { force: true });
102
+ }, 250);
103
+
104
+ const start = Date.now();
105
+ const handle = await acquireSlot(tmpDir, 1, { pollIntervalMs: 100 });
106
+ const elapsed = Date.now() - start;
107
+
108
+ // Should have waited at least ~200ms (polling)
109
+ expect(elapsed).toBeGreaterThanOrEqual(150);
110
+
111
+ await handle.release();
112
+ });
113
+ });
114
+
115
+ // ── Spec: concurrency-stale-slot-cleanup ────────────────────────────────────
116
+
117
+ describe("cleanStaleSlots removes slot files for dead PIDs", () => {
118
+ test("removes slot file for dead PID, preserves live PID", async () => {
119
+ const slotsDir = getSlotsDir(tmpDir);
120
+ await mkdir(slotsDir, { recursive: true });
121
+
122
+ // Dead PID (99999999 should not exist)
123
+ await writeFile(join(slotsDir, "99999999.slot"), "", "utf8");
124
+ // Live PID (current process)
125
+ await writeFile(join(slotsDir, `${process.pid}.slot`), "", "utf8");
126
+
127
+ const cleaned = await cleanStaleSlots(tmpDir);
128
+ expect(cleaned).toBe(1);
129
+
130
+ const files = await readdir(slotsDir);
131
+ expect(files).not.toContain("99999999.slot");
132
+ expect(files).toContain(`${process.pid}.slot`);
133
+ });
134
+
135
+ test("countActiveSlots reflects correct count after cleanup", async () => {
136
+ const slotsDir = getSlotsDir(tmpDir);
137
+ await mkdir(slotsDir, { recursive: true });
138
+
139
+ // 1 dead + 1 live
140
+ await writeFile(join(slotsDir, "99999999.slot"), "", "utf8");
141
+ await writeFile(join(slotsDir, `${process.pid}.slot`), "", "utf8");
142
+
143
+ // Before cleanup: 2 files
144
+ const beforeFiles = await readdir(slotsDir);
145
+ expect(beforeFiles.filter((f) => f.endsWith(".slot")).length).toBe(2);
146
+
147
+ await cleanStaleSlots(tmpDir);
148
+
149
+ // After cleanup
150
+ const count = await countActiveSlots(tmpDir);
151
+ expect(count).toBe(1);
152
+ });
153
+ });
154
+
155
+ // ── Spec: concurrency-race-protection-rollback ──────────────────────────────
156
+
157
+ describe("acquireSlot rolls back on race condition", () => {
158
+ test("rolls back slot file if post-write count exceeds maxRunning", async () => {
159
+ const slotsDir = getSlotsDir(tmpDir);
160
+ await mkdir(slotsDir, { recursive: true });
161
+
162
+ // Simulate: maxRunning=2, and we already have 1 slot from another live process
163
+ const blockerPid = process.ppid;
164
+ await writeFile(join(slotsDir, `${blockerPid}.slot`), "", "utf8");
165
+
166
+ // Our process writes its slot, making count=2 which equals maxRunning=2
167
+ // This should succeed (at limit, not over)
168
+ const handle = await acquireSlot(tmpDir, 2);
169
+ const count = await countActiveSlots(tmpDir);
170
+ expect(count).toBe(2);
171
+
172
+ await handle.release();
173
+ });
174
+
175
+ test("when another slot appears during write, rollback occurs", async () => {
176
+ // This tests the double-check logic. We'll simulate by pre-filling to capacity.
177
+ const slotsDir = getSlotsDir(tmpDir);
178
+ await mkdir(slotsDir, { recursive: true });
179
+
180
+ // maxRunning=1, one slot already occupied by parent PID
181
+ const blockerPid = process.ppid;
182
+ await writeFile(join(slotsDir, `${blockerPid}.slot`), "", "utf8");
183
+
184
+ // Release after delay so acquireSlot can proceed
185
+ setTimeout(async () => {
186
+ await rm(join(slotsDir, `${blockerPid}.slot`), { force: true });
187
+ }, 200);
188
+
189
+ const handle = await acquireSlot(tmpDir, 1, { pollIntervalMs: 100 });
190
+
191
+ // After acquiring, only our slot should exist
192
+ const files = await readdir(slotsDir);
193
+ const slotFiles = files.filter((f) => f.endsWith(".slot"));
194
+ expect(slotFiles).toContain(`${process.pid}.slot`);
195
+
196
+ await handle.release();
197
+ });
198
+ });
199
+
200
+ // ── Spec: concurrency-exec-signal-cleanup ────────────────────────────────────
201
+
202
+ describe("installSlotCleanup removes slot on signal", () => {
203
+ test("release function removes slot file", async () => {
204
+ const handle = await acquireSlot(tmpDir, 2);
205
+
206
+ // Verify slot exists
207
+ const slotsDir = getSlotsDir(tmpDir);
208
+ const filesBefore = await readdir(slotsDir);
209
+ expect(filesBefore).toContain(`${process.pid}.slot`);
210
+
211
+ // installSlotCleanup returns a cleanup function
212
+ const cleanup = installSlotCleanup(handle);
213
+
214
+ // Call release directly (simulating what signal handler would do)
215
+ await handle.release();
216
+
217
+ const filesAfter = await readdir(slotsDir);
218
+ expect(filesAfter).not.toContain(`${process.pid}.slot`);
219
+
220
+ // Uninstall the cleanup handler
221
+ cleanup();
222
+ });
223
+ });
224
+
225
+ // ── Spec: concurrency-default-max-running ────────────────────────────────────
226
+
227
+ describe("DEFAULT_MAX_RUNNING is 2", () => {
228
+ test("constant equals 2", () => {
229
+ expect(DEFAULT_MAX_RUNNING).toBe(2);
230
+ });
231
+ });
232
+
233
+ // ── Spec: concurrency-exec-uses-slot (unit level) ───────────────────────────
234
+
235
+ describe("slot lifecycle during exec", () => {
236
+ test("acquireSlot + release = 0 active slots", async () => {
237
+ const handle = await acquireSlot(tmpDir, 2);
238
+ expect(await countActiveSlots(tmpDir)).toBe(1);
239
+
240
+ await handle.release();
241
+ expect(await countActiveSlots(tmpDir)).toBe(0);
242
+ });
243
+
244
+ test("release is idempotent", async () => {
245
+ const handle = await acquireSlot(tmpDir, 2);
246
+ await handle.release();
247
+ // Calling release again should not throw
248
+ await handle.release();
249
+ expect(await countActiveSlots(tmpDir)).toBe(0);
250
+ });
251
+ });
252
+
253
+ // ── Spec: concurrency-config-set-max-running ─────────────────────────────────
254
+
255
+ describe("config set concurrency.maxRunning", () => {
256
+ test("concurrency config key is validated correctly", async () => {
257
+ // Import config module to test the key validation
258
+ const { parseDotPath, setNestedValue } = await import("../commands/config.js");
259
+
260
+ const config: Record<string, unknown> = {};
261
+ const path = parseDotPath("concurrency.maxRunning");
262
+ setNestedValue(config, path, 3);
263
+
264
+ expect(config).toEqual({ concurrency: { maxRunning: 3 } });
265
+ });
266
+ });