@hunsu/protocol 0.1.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 (47) hide show
  1. package/LICENSE +157 -0
  2. package/dist/command-decoder.d.ts +5 -0
  3. package/dist/command-decoder.js +329 -0
  4. package/dist/constants.d.ts +15 -0
  5. package/dist/constants.js +15 -0
  6. package/dist/decoder-helpers.d.ts +58 -0
  7. package/dist/decoder-helpers.js +1757 -0
  8. package/dist/errors.d.ts +14 -0
  9. package/dist/errors.js +28 -0
  10. package/dist/event-decoder.d.ts +5 -0
  11. package/dist/event-decoder.js +232 -0
  12. package/dist/index.d.ts +10 -0
  13. package/dist/index.js +10 -0
  14. package/dist/lifecycle.d.ts +67 -0
  15. package/dist/lifecycle.js +271 -0
  16. package/dist/model.d.ts +1058 -0
  17. package/dist/model.js +1 -0
  18. package/dist/primitives.d.ts +59 -0
  19. package/dist/primitives.js +135 -0
  20. package/dist/projection.d.ts +8 -0
  21. package/dist/projection.js +875 -0
  22. package/dist/prompt-template.d.ts +12 -0
  23. package/dist/prompt-template.js +83 -0
  24. package/dist/protocol-validation.d.ts +36 -0
  25. package/dist/protocol-validation.js +1139 -0
  26. package/dist/result.d.ts +20 -0
  27. package/dist/result.js +21 -0
  28. package/dist/workflow-helpers.d.ts +31 -0
  29. package/dist/workflow-helpers.js +193 -0
  30. package/dist/workflow.d.ts +10 -0
  31. package/dist/workflow.js +594 -0
  32. package/package.json +30 -0
  33. package/src/command-decoder.ts +292 -0
  34. package/src/constants.ts +27 -0
  35. package/src/decoder-helpers.ts +1672 -0
  36. package/src/errors.ts +38 -0
  37. package/src/event-decoder.ts +225 -0
  38. package/src/index.ts +43 -0
  39. package/src/lifecycle.ts +403 -0
  40. package/src/model.ts +1233 -0
  41. package/src/primitives.ts +196 -0
  42. package/src/projection.ts +1081 -0
  43. package/src/prompt-template.ts +97 -0
  44. package/src/protocol-validation.ts +1252 -0
  45. package/src/result.ts +35 -0
  46. package/src/workflow-helpers.ts +239 -0
  47. package/src/workflow.ts +753 -0
package/LICENSE ADDED
@@ -0,0 +1,157 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
13
+ owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities
16
+ that control, are controlled by, or are under common control with that entity.
17
+ For the purposes of this definition, "control" means (i) the power, direct or
18
+ indirect, to cause the direction or management of such entity, whether by
19
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+ outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
23
+ permissions granted by this License.
24
+
25
+ "Source" form shall mean the preferred form for making modifications, including
26
+ but not limited to software source code, documentation source, and configuration
27
+ files.
28
+
29
+ "Object" form shall mean any form resulting from mechanical transformation or
30
+ translation of a Source form, including but not limited to compiled object code,
31
+ generated documentation, and conversions to other media types.
32
+
33
+ "Work" shall mean the work of authorship, whether in Source or Object form,
34
+ made available under the License, as indicated by a copyright notice that is
35
+ included in or attached to the work.
36
+
37
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
38
+ is based on (or derived from) the Work and for which the editorial revisions,
39
+ annotations, elaborations, or other modifications represent, as a whole, an
40
+ original work of authorship. For the purposes of this License, Derivative Works
41
+ shall not include works that remain separable from, or merely link (or bind by
42
+ name) to the interfaces of, the Work and Derivative Works thereof.
43
+
44
+ "Contribution" shall mean any work of authorship, including the original version
45
+ of the Work and any modifications or additions to that Work or Derivative Works
46
+ thereof, that is intentionally submitted to Licensor for inclusion in the Work by
47
+ the copyright owner or by an individual or Legal Entity authorized to submit on
48
+ behalf of the copyright owner. For the purposes of this definition, "submitted"
49
+ means any form of electronic, verbal, or written communication sent to the
50
+ Licensor or its representatives, including but not limited to communication on
51
+ electronic mailing lists, source code control systems, and issue tracking systems
52
+ that are managed by, or on behalf of, the Licensor for the purpose of discussing
53
+ and improving the Work, but excluding communication that is conspicuously marked
54
+ or otherwise designated in writing by the copyright owner as "Not a Contribution."
55
+
56
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
57
+ of whom a Contribution has been received by Licensor and subsequently
58
+ incorporated within the Work.
59
+
60
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
61
+ License, each Contributor hereby grants to You a perpetual, worldwide,
62
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
63
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
64
+ sublicense, and distribute the Work and such Derivative Works in Source or
65
+ Object form.
66
+
67
+ 3. Grant of Patent License. Subject to the terms and conditions of this License,
68
+ each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
69
+ no-charge, royalty-free, irrevocable (except as stated in this section) patent
70
+ license to make, have made, use, offer to sell, sell, import, and otherwise
71
+ transfer the Work, where such license applies only to those patent claims
72
+ licensable by such Contributor that are necessarily infringed by their
73
+ Contribution(s) alone or by combination of their Contribution(s) with the Work
74
+ to which such Contribution(s) was submitted. If You institute patent litigation
75
+ against any entity (including a cross-claim or counterclaim in a lawsuit)
76
+ alleging that the Work or a Contribution incorporated within the Work
77
+ constitutes direct or contributory patent infringement, then any patent licenses
78
+ granted to You under this License for that Work shall terminate as of the date
79
+ such litigation is filed.
80
+
81
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
82
+ Derivative Works thereof in any medium, with or without modifications, and in
83
+ Source or Object form, provided that You meet the following conditions:
84
+
85
+ (a) You must give any other recipients of the Work or Derivative Works a copy of
86
+ this License; and
87
+
88
+ (b) You must cause any modified files to carry prominent notices stating that
89
+ You changed the files; and
90
+
91
+ (c) You must retain, in the Source form of any Derivative Works that You
92
+ distribute, all copyright, patent, trademark, and attribution notices from the
93
+ Source form of the Work, excluding those notices that do not pertain to any part
94
+ of the Derivative Works; and
95
+
96
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then
97
+ any Derivative Works that You distribute must include a readable copy of the
98
+ attribution notices contained within such NOTICE file, excluding those notices
99
+ that do not pertain to any part of the Derivative Works, in at least one of the
100
+ following places: within a NOTICE text file distributed as part of the Derivative
101
+ Works; within the Source form or documentation, if provided along with the
102
+ Derivative Works; or, within a display generated by the Derivative Works, if and
103
+ wherever such third-party notices normally appear. The contents of the NOTICE
104
+ file are for informational purposes only and do not modify the License. You may
105
+ add Your own attribution notices within Derivative Works that You distribute,
106
+ alongside or as an addendum to the NOTICE text from the Work, provided that such
107
+ additional attribution notices cannot be construed as modifying the License.
108
+
109
+ You may add Your own copyright statement to Your modifications and may provide
110
+ additional or different license terms and conditions for use, reproduction, or
111
+ distribution of Your modifications, or for any such Derivative Works as a whole,
112
+ provided Your use, reproduction, and distribution of the Work otherwise complies
113
+ with the conditions stated in this License.
114
+
115
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
116
+ Contribution intentionally submitted for inclusion in the Work by You to the
117
+ Licensor shall be under the terms and conditions of this License, without any
118
+ additional terms or conditions. Notwithstanding the above, nothing herein shall
119
+ supersede or modify the terms of any separate license agreement you may have
120
+ executed with Licensor regarding such Contributions.
121
+
122
+ 6. Trademarks. This License does not grant permission to use the trade names,
123
+ trademarks, service marks, or product names of the Licensor, except as required
124
+ for reasonable and customary use in describing the origin of the Work and
125
+ reproducing the content of the NOTICE file.
126
+
127
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
128
+ writing, Licensor provides the Work (and each Contributor provides its
129
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
130
+ KIND, either express or implied, including, without limitation, any warranties or
131
+ conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
132
+ PARTICULAR PURPOSE. You are solely responsible for determining the
133
+ appropriateness of using or redistributing the Work and assume any risks
134
+ associated with Your exercise of permissions under this License.
135
+
136
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
137
+ tort (including negligence), contract, or otherwise, unless required by
138
+ applicable law (such as deliberate and grossly negligent acts) or agreed to in
139
+ writing, shall any Contributor be liable to You for damages, including any
140
+ direct, indirect, special, incidental, or consequential damages of any character
141
+ arising as a result of this License or out of the use or inability to use the
142
+ Work (including but not limited to damages for loss of goodwill, work stoppage,
143
+ computer failure or malfunction, or any and all other commercial damages or
144
+ losses), even if such Contributor has been advised of the possibility of such
145
+ damages.
146
+
147
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or
148
+ Derivative Works thereof, You may choose to offer, and charge a fee for,
149
+ acceptance of support, warranty, indemnity, or other liability obligations
150
+ and/or rights consistent with this License. However, in accepting such
151
+ obligations, You may act only on Your own behalf and on Your sole
152
+ responsibility, not on behalf of any other Contributor, and only if You agree to
153
+ indemnify, defend, and hold each Contributor harmless for any liability incurred
154
+ by, or claims asserted against, such Contributor by reason of your accepting any
155
+ such warranty or additional liability.
156
+
157
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,5 @@
1
+ import { type DomainWorkflowError } from "./errors.ts";
2
+ import type { ValidatedCommand } from "./model.ts";
3
+ import { type Result } from "./result.ts";
4
+ import { type HarnessDecoder } from "./decoder-helpers.ts";
5
+ export declare function decodeCommand(input: unknown, decodeHarness: HarnessDecoder): Result<ValidatedCommand, DomainWorkflowError>;
@@ -0,0 +1,329 @@
1
+ import { workflowError } from "./errors.js";
2
+ import { makeLineId, makeMoveCommit, makeMoveId, makeNonEmptyText, makeTeamName, makeRequestGoal, makeRequestId, makeRequestTitle, makeSingleItemArray, makeSkillDraftId, makeSummary, makeDestinationId, makeFailureReason } from "./primitives.js";
3
+ import { ok } from "./result.js";
4
+ import { decodeAgentConversationRef, decodeArtifactRecord, decodeDestinationIdArray, decodeDestinationSeedArray, decodeHubPackageLock, decodeHunsuOrigin, decodeEvidenceArray, decodeHunsuDraftRecord, decodeOptionalAt, decodeOptionalExecuteId, decodeOptionalNonEmptyText, decodeRecord, decodeRiskArray, decodeWorktreeRef } from "./decoder-helpers.js";
5
+ export function decodeCommand(input, decodeHarness) {
6
+ const command = decodeRecord(input, "Command");
7
+ if (!command.ok) {
8
+ return command;
9
+ }
10
+ switch (command.value.type) {
11
+ case "RegisterHunsuOrigin": {
12
+ const origin = decodeHunsuOrigin(command.value.origin, "origin");
13
+ if (!origin.ok)
14
+ return origin;
15
+ const actor = decodeOptionalNonEmptyText(command.value.actor, "actor");
16
+ if (!actor.ok)
17
+ return actor;
18
+ const at = decodeOptionalAt(command.value.at);
19
+ if (!at.ok)
20
+ return at;
21
+ return ok({ type: "RegisterHunsuOrigin", origin: origin.value, actor: actor.value, at: at.value });
22
+ }
23
+ case "CreateInitialTeam": {
24
+ const requestId = primitive(makeRequestId(command.value.requestId));
25
+ if (!requestId.ok)
26
+ return requestId;
27
+ const lineId = primitive(makeLineId(command.value.lineId));
28
+ if (!lineId.ok)
29
+ return lineId;
30
+ const title = primitive(makeRequestTitle(command.value.title));
31
+ if (!title.ok)
32
+ return title;
33
+ const goal = primitive(makeRequestGoal(command.value.goal));
34
+ if (!goal.ok)
35
+ return goal;
36
+ const destinations = decodeDestinationSeedArray(command.value.destinations, "destinations");
37
+ if (!destinations.ok)
38
+ return destinations;
39
+ const harness = command.value.harness === undefined ? ok(undefined) : decodeHarness(command.value.harness);
40
+ if (!harness.ok)
41
+ return harness;
42
+ const harnessLock = decodeHubPackageLock(command.value.harnessLock, "harnessLock", ["team"]);
43
+ if (!harnessLock.ok)
44
+ return harnessLock;
45
+ const teamName = command.value.teamName === undefined ? ok(undefined) : primitive(makeTeamName(command.value.teamName));
46
+ if (!teamName.ok)
47
+ return teamName;
48
+ const actor = decodeOptionalNonEmptyText(command.value.actor, "actor");
49
+ if (!actor.ok)
50
+ return actor;
51
+ const at = decodeOptionalAt(command.value.at);
52
+ if (!at.ok)
53
+ return at;
54
+ return ok({
55
+ type: "CreateInitialTeam",
56
+ requestId: requestId.value,
57
+ lineId: lineId.value,
58
+ title: title.value,
59
+ goal: goal.value,
60
+ destinations: destinations.value,
61
+ harness: harness.value,
62
+ harnessLock: harnessLock.value,
63
+ teamName: teamName.value,
64
+ actor: actor.value,
65
+ at: at.value
66
+ });
67
+ }
68
+ case "StartLine": {
69
+ const requestId = primitive(makeRequestId(command.value.requestId));
70
+ if (!requestId.ok)
71
+ return requestId;
72
+ const lineId = primitive(makeLineId(command.value.lineId));
73
+ if (!lineId.ok)
74
+ return lineId;
75
+ const teamName = command.value.teamName === undefined ? ok(undefined) : primitive(makeTeamName(command.value.teamName));
76
+ if (!teamName.ok)
77
+ return teamName;
78
+ const at = decodeOptionalAt(command.value.at);
79
+ if (!at.ok)
80
+ return at;
81
+ return ok({ type: "StartLine", lineId: lineId.value, requestId: requestId.value, teamName: teamName.value, at: at.value });
82
+ }
83
+ case "PauseLine":
84
+ case "ResumeLine": {
85
+ const lineId = primitive(makeLineId(command.value.lineId));
86
+ if (!lineId.ok)
87
+ return lineId;
88
+ const at = decodeOptionalAt(command.value.at);
89
+ if (!at.ok)
90
+ return at;
91
+ return ok({ type: command.value.type, lineId: lineId.value, at: at.value });
92
+ }
93
+ case "AcceptLine":
94
+ case "RejectLine": {
95
+ const lineId = primitive(makeLineId(command.value.lineId));
96
+ if (!lineId.ok)
97
+ return lineId;
98
+ const reason = decodeOptionalNonEmptyText(command.value.reason, "reason");
99
+ if (!reason.ok)
100
+ return reason;
101
+ const at = decodeOptionalAt(command.value.at);
102
+ if (!at.ok)
103
+ return at;
104
+ return ok({ type: command.value.type, lineId: lineId.value, reason: reason.value, at: at.value });
105
+ }
106
+ case "ClaimDestination":
107
+ case "StartDestinationWork": {
108
+ const destinationId = primitive(makeDestinationId(command.value.destinationId));
109
+ if (!destinationId.ok)
110
+ return destinationId;
111
+ const actor = primitive(makeNonEmptyText(command.value.actor, "actor"));
112
+ if (!actor.ok)
113
+ return actor;
114
+ const at = decodeOptionalAt(command.value.at);
115
+ if (!at.ok)
116
+ return at;
117
+ return ok({ type: command.value.type, destinationId: destinationId.value, actor: actor.value, at: at.value });
118
+ }
119
+ case "ReportDestinationBlocked": {
120
+ const destinationId = primitive(makeDestinationId(command.value.destinationId));
121
+ if (!destinationId.ok)
122
+ return destinationId;
123
+ const reason = primitive(makeFailureReason(command.value.reason, "reason"));
124
+ if (!reason.ok)
125
+ return reason;
126
+ const actor = primitive(makeNonEmptyText(command.value.actor, "actor"));
127
+ if (!actor.ok)
128
+ return actor;
129
+ const at = decodeOptionalAt(command.value.at);
130
+ if (!at.ok)
131
+ return at;
132
+ return ok({ type: "ReportDestinationBlocked", destinationId: destinationId.value, reason: reason.value, actor: actor.value, at: at.value });
133
+ }
134
+ case "RecordMove": {
135
+ const lineId = primitive(makeLineId(command.value.lineId));
136
+ if (!lineId.ok)
137
+ return lineId;
138
+ const moveId = primitive(makeMoveId(command.value.moveId));
139
+ if (!moveId.ok)
140
+ return moveId;
141
+ const summary = primitive(makeSummary(command.value.summary));
142
+ if (!summary.ok)
143
+ return summary;
144
+ const commit = primitive(makeMoveCommit(command.value.commit, "commit"));
145
+ if (!commit.ok)
146
+ return commit;
147
+ const reachedDestinationIds = decodeDestinationIdArray(command.value.reachedDestinationIds, "reachedDestinationIds", true);
148
+ if (!reachedDestinationIds.ok)
149
+ return reachedDestinationIds;
150
+ const singleReachedDestinationIds = primitive(makeSingleItemArray(reachedDestinationIds.value, "reachedDestinationIds"));
151
+ if (!singleReachedDestinationIds.ok)
152
+ return singleReachedDestinationIds;
153
+ const evidence = decodeEvidenceArray(command.value.evidence, "evidence", true);
154
+ if (!evidence.ok)
155
+ return evidence;
156
+ const risks = command.value.risks === undefined ? ok(undefined) : decodeRiskArray(command.value.risks, "risks");
157
+ if (!risks.ok)
158
+ return risks;
159
+ const executeId = decodeOptionalExecuteId(command.value.executeId);
160
+ if (!executeId.ok)
161
+ return executeId;
162
+ const conversationRef = decodeAgentConversationRef(command.value.conversationRef, "conversationRef");
163
+ if (!conversationRef.ok)
164
+ return conversationRef;
165
+ const worktree = decodeWorktreeRef(command.value.worktree, "worktree");
166
+ if (!worktree.ok)
167
+ return worktree;
168
+ const actor = primitive(makeNonEmptyText(command.value.actor, "actor"));
169
+ if (!actor.ok)
170
+ return actor;
171
+ const at = decodeOptionalAt(command.value.at);
172
+ if (!at.ok)
173
+ return at;
174
+ return ok({
175
+ type: "RecordMove",
176
+ lineId: lineId.value,
177
+ moveId: moveId.value,
178
+ summary: summary.value,
179
+ commit: commit.value,
180
+ reachedDestinationIds: singleReachedDestinationIds.value,
181
+ evidence: evidence.value,
182
+ risks: risks.value,
183
+ executeId: executeId.value,
184
+ conversationRef: conversationRef.value,
185
+ worktree: worktree.value,
186
+ actor: actor.value,
187
+ at: at.value
188
+ });
189
+ }
190
+ case "RecordAccident": {
191
+ const lineId = primitive(makeLineId(command.value.lineId));
192
+ if (!lineId.ok)
193
+ return lineId;
194
+ const moveId = primitive(makeMoveId(command.value.moveId));
195
+ if (!moveId.ok)
196
+ return moveId;
197
+ const summary = primitive(makeSummary(command.value.summary));
198
+ if (!summary.ok)
199
+ return summary;
200
+ const commit = primitive(makeMoveCommit(command.value.commit, "commit"));
201
+ if (!commit.ok)
202
+ return commit;
203
+ const evidence = decodeEvidenceArray(command.value.evidence, "evidence", true);
204
+ if (!evidence.ok)
205
+ return evidence;
206
+ const failureReason = primitive(makeFailureReason(command.value.failureReason));
207
+ if (!failureReason.ok)
208
+ return failureReason;
209
+ const risks = command.value.risks === undefined ? ok(undefined) : decodeRiskArray(command.value.risks, "risks");
210
+ if (!risks.ok)
211
+ return risks;
212
+ const executeId = decodeOptionalExecuteId(command.value.executeId);
213
+ if (!executeId.ok)
214
+ return executeId;
215
+ const conversationRef = decodeAgentConversationRef(command.value.conversationRef, "conversationRef");
216
+ if (!conversationRef.ok)
217
+ return conversationRef;
218
+ const worktree = decodeWorktreeRef(command.value.worktree, "worktree");
219
+ if (!worktree.ok)
220
+ return worktree;
221
+ const actor = primitive(makeNonEmptyText(command.value.actor, "actor"));
222
+ if (!actor.ok)
223
+ return actor;
224
+ const at = decodeOptionalAt(command.value.at);
225
+ if (!at.ok)
226
+ return at;
227
+ return ok({
228
+ type: "RecordAccident",
229
+ lineId: lineId.value,
230
+ moveId: moveId.value,
231
+ summary: summary.value,
232
+ commit: commit.value,
233
+ evidence: evidence.value,
234
+ failureReason: failureReason.value,
235
+ risks: risks.value,
236
+ executeId: executeId.value,
237
+ conversationRef: conversationRef.value,
238
+ worktree: worktree.value,
239
+ actor: actor.value,
240
+ at: at.value
241
+ });
242
+ }
243
+ case "AttachMoveEvidence": {
244
+ const moveId = primitive(makeMoveId(command.value.moveId));
245
+ if (!moveId.ok)
246
+ return moveId;
247
+ const artifact = decodeArtifactRecord(command.value.artifact, "artifact");
248
+ if (!artifact.ok)
249
+ return artifact;
250
+ const actor = primitive(makeNonEmptyText(command.value.actor, "actor"));
251
+ if (!actor.ok)
252
+ return actor;
253
+ const at = decodeOptionalAt(command.value.at);
254
+ if (!at.ok)
255
+ return at;
256
+ return ok({ type: "AttachMoveEvidence", moveId: moveId.value, artifact: artifact.value, actor: actor.value, at: at.value });
257
+ }
258
+ case "ConfirmHunsuDraft": {
259
+ const draft = decodeHunsuDraftRecord(command.value.draft, "draft", decodeHarness);
260
+ if (!draft.ok)
261
+ return draft;
262
+ if (draft.value.status !== "ready") {
263
+ return workflowError(`HUNSU Draft ${draft.value.id} cannot be confirmed from status ${draft.value.status}`);
264
+ }
265
+ const actor = primitive(makeNonEmptyText(command.value.actor, "actor"));
266
+ if (!actor.ok)
267
+ return actor;
268
+ const at = decodeOptionalAt(command.value.at);
269
+ if (!at.ok)
270
+ return at;
271
+ return ok({
272
+ type: "ConfirmHunsuDraft",
273
+ draft: draft.value,
274
+ actor: actor.value,
275
+ at: at.value
276
+ });
277
+ }
278
+ case "CreateSkillDraft": {
279
+ const draftId = primitive(makeSkillDraftId(command.value.draftId));
280
+ if (!draftId.ok)
281
+ return draftId;
282
+ const lineId = primitive(makeLineId(command.value.lineId));
283
+ if (!lineId.ok)
284
+ return lineId;
285
+ const name = primitive(makeNonEmptyText(command.value.name, "name"));
286
+ if (!name.ok)
287
+ return name;
288
+ const draftPath = primitive(makeNonEmptyText(command.value.draftPath, "draftPath"));
289
+ if (!draftPath.ok)
290
+ return draftPath;
291
+ const sourcePath = decodeOptionalNonEmptyText(command.value.sourcePath, "sourcePath");
292
+ if (!sourcePath.ok)
293
+ return sourcePath;
294
+ const actor = primitive(makeNonEmptyText(command.value.actor, "actor"));
295
+ if (!actor.ok)
296
+ return actor;
297
+ const at = decodeOptionalAt(command.value.at);
298
+ if (!at.ok)
299
+ return at;
300
+ return ok({ type: "CreateSkillDraft", draftId: draftId.value, lineId: lineId.value, name: name.value, draftPath: draftPath.value, sourcePath: sourcePath.value, actor: actor.value, at: at.value });
301
+ }
302
+ case "DiscardSkillDraft": {
303
+ const draftId = primitive(makeSkillDraftId(command.value.draftId));
304
+ if (!draftId.ok)
305
+ return draftId;
306
+ const actor = primitive(makeNonEmptyText(command.value.actor, "actor"));
307
+ if (!actor.ok)
308
+ return actor;
309
+ const at = decodeOptionalAt(command.value.at);
310
+ if (!at.ok)
311
+ return at;
312
+ return ok({ type: "DiscardSkillDraft", draftId: draftId.value, actor: actor.value, at: at.value });
313
+ }
314
+ case "RecordArtifact": {
315
+ const artifact = decodeArtifactRecord(command.value.artifact, "artifact");
316
+ if (!artifact.ok)
317
+ return artifact;
318
+ const at = decodeOptionalAt(command.value.at);
319
+ if (!at.ok)
320
+ return at;
321
+ return ok({ type: "RecordArtifact", artifact: artifact.value, at: at.value });
322
+ }
323
+ default:
324
+ return workflowError(`Unsupported command type: ${String(command.value.type)}`);
325
+ }
326
+ }
327
+ function primitive(result) {
328
+ return result.ok ? ok(result.value) : workflowError(result.error.message);
329
+ }
@@ -0,0 +1,15 @@
1
+ export declare const REASONING_EFFORTS: readonly ["default", "minimal", "low", "medium", "high", "xhigh"];
2
+ export declare const SERVICE_TIERS: readonly ["default", "fast"];
3
+ export declare const DOMAIN_ROLES: readonly ["TEAM", "DIRECTOR", "SYSTEM"];
4
+ export declare const GUARDRAIL_SCOPES: readonly ["input", "output", "context", "artifact", "final_evidence"];
5
+ export declare const GUARDRAIL_SEVERITIES: readonly ["warn", "block"];
6
+ export declare const VOTE_RULES: readonly ["majority", "unanimous", "weighted", "coordinator_decides"];
7
+ export declare const DESTINATION_STATUSES: readonly ["pending", "claimed", "in_progress", "reached", "blocked", "superseded", "canceled"];
8
+ export declare const DESTINATION_SOURCES: readonly ["initial-execute-team", "initial-request", "hunsu"];
9
+ export declare const LINE_STATUSES: readonly ["active", "paused", "complete", "failed", "abandoned"];
10
+ export declare const MOVE_OUTCOMES: readonly ["arrived", "accident"];
11
+ export declare const HUNSU_DRAFT_STATUSES: readonly ["draft", "ready", "confirmed", "discarded"];
12
+ export declare const SKILL_DRAFT_STATUSES: readonly ["draft", "accepted", "discarded"];
13
+ export declare const ARTIFACT_KINDS: readonly ["transcript", "command-output", "test-log", "screenshot", "diff-summary", "note"];
14
+ export declare const ARTIFACT_ACTION_KINDS: readonly ["host", "check"];
15
+ export declare const ARTIFACT_ACTION_SOURCE_SCOPES: readonly ["move", "commit", "move-or-commit"];
@@ -0,0 +1,15 @@
1
+ export const REASONING_EFFORTS = ["default", "minimal", "low", "medium", "high", "xhigh"];
2
+ export const SERVICE_TIERS = ["default", "fast"];
3
+ export const DOMAIN_ROLES = ["TEAM", "DIRECTOR", "SYSTEM"];
4
+ export const GUARDRAIL_SCOPES = ["input", "output", "context", "artifact", "final_evidence"];
5
+ export const GUARDRAIL_SEVERITIES = ["warn", "block"];
6
+ export const VOTE_RULES = ["majority", "unanimous", "weighted", "coordinator_decides"];
7
+ export const DESTINATION_STATUSES = ["pending", "claimed", "in_progress", "reached", "blocked", "superseded", "canceled"];
8
+ export const DESTINATION_SOURCES = ["initial-execute-team", "initial-request", "hunsu"];
9
+ export const LINE_STATUSES = ["active", "paused", "complete", "failed", "abandoned"];
10
+ export const MOVE_OUTCOMES = ["arrived", "accident"];
11
+ export const HUNSU_DRAFT_STATUSES = ["draft", "ready", "confirmed", "discarded"];
12
+ export const SKILL_DRAFT_STATUSES = ["draft", "accepted", "discarded"];
13
+ export const ARTIFACT_KINDS = ["transcript", "command-output", "test-log", "screenshot", "diff-summary", "note"];
14
+ export const ARTIFACT_ACTION_KINDS = ["host", "check"];
15
+ export const ARTIFACT_ACTION_SOURCE_SCOPES = ["move", "commit", "move-or-commit"];
@@ -0,0 +1,58 @@
1
+ import { type DomainWorkflowError } from "./errors.ts";
2
+ import type { AgentConversationRef, ArtifactActionDefinition, ArtifactActionPatch, ArtifactRecord, Destination, DestinationPatch, DestinationSeed, HubPackageKind, HubPackageLock, HarnessSnapshot, HunsuOrigin, HunsuDraftRecord, HunsuRecord, HunsuTarget, LineRecord, MoveRecord, NodeRecord, ExecutorPackageBinding, MemberPluginBinding, RequestRecord, SkillBinding, ResourcePackageBinding, SkillDraftRecord, WorktreeRef } from "./model.ts";
3
+ import { makeArtifactActionId, makeDestinationId, makeExecuteId, makeEvidenceText, makeHunsuDraftId, makeHunsuId, makeLineId, makeMoveId, makeNodeId, type NonEmptyText, type RiskText } from "./primitives.ts";
4
+ import { type Result } from "./result.ts";
5
+ export type HarnessDecoder = (value: unknown) => Result<HarnessSnapshot, DomainWorkflowError>;
6
+ export declare function decodeRecord(value: unknown, path: string): Result<Record<string, unknown>, DomainWorkflowError>;
7
+ export declare function decodeArray(value: unknown, path: string): Result<unknown[], DomainWorkflowError>;
8
+ export declare function decodeAllowed<const T extends string>(path: string, value: unknown, allowed: readonly T[]): Result<T, DomainWorkflowError>;
9
+ export declare function decodeNumber(value: unknown, path: string): Result<number, DomainWorkflowError>;
10
+ export declare function decodeOptionalBoolean(value: unknown, path: string): Result<boolean | undefined, DomainWorkflowError>;
11
+ export declare function decodeNonNegativeInteger(value: unknown, path: string): Result<number, DomainWorkflowError>;
12
+ export declare function decodeOptionalString(value: unknown, path: string): Result<string | undefined, DomainWorkflowError>;
13
+ export declare function decodeString(value: unknown, path: string): Result<string, DomainWorkflowError>;
14
+ export declare function decodeOptionalNonEmptyText(value: unknown, path: string): Result<NonEmptyText | undefined, DomainWorkflowError>;
15
+ export declare function decodeNonEmptyText(value: unknown, path: string): Result<NonEmptyText, DomainWorkflowError>;
16
+ export declare function decodeOptionalAt(value: unknown, path?: string): Result<string | undefined, DomainWorkflowError>;
17
+ export declare function decodeStringArray(value: unknown, path: string): Result<string[], DomainWorkflowError>;
18
+ export declare function decodeOptionalStringArray(value: unknown, path: string): Result<string[] | undefined, DomainWorkflowError>;
19
+ export declare function decodeOptionalNumber(value: unknown, path: string): Result<number | undefined, DomainWorkflowError>;
20
+ export declare function decodeRequestRecord(value: unknown, path: string): Result<RequestRecord, DomainWorkflowError>;
21
+ export declare function decodeDestinationSeed(value: unknown, path: string): Result<DestinationSeed, DomainWorkflowError>;
22
+ export declare function decodeDestinationSeedArray(value: unknown, path: string, requireNonEmpty?: boolean): Result<DestinationSeed[], DomainWorkflowError>;
23
+ export declare function decodeDestinationPatch(value: unknown, path: string): Result<DestinationPatch, DomainWorkflowError>;
24
+ export declare function decodeDestinationRecord(value: unknown, path: string): Result<Destination, DomainWorkflowError>;
25
+ export declare function decodeDestinationRecordArray(value: unknown, path: string): Result<Destination[], DomainWorkflowError>;
26
+ export declare function decodeDestinationIdArray(value: unknown, path: string, requireNonEmpty: boolean): Result<ReturnType<typeof makeDestinationId> extends Result<infer T, unknown> ? T[] : never, DomainWorkflowError>;
27
+ export declare function decodeMoveIdArray(value: unknown, path: string, requireNonEmpty: boolean): Result<ReturnType<typeof makeMoveId> extends Result<infer T, unknown> ? T[] : never, DomainWorkflowError>;
28
+ export declare function decodeNodeIdArray(value: unknown, path: string, requireNonEmpty: true): Result<ReturnType<typeof makeNodeId> extends Result<infer T, unknown> ? [T, ...T[]] : never, DomainWorkflowError>;
29
+ export declare function decodeNodeIdArray(value: unknown, path: string, requireNonEmpty: false): Result<ReturnType<typeof makeNodeId> extends Result<infer T, unknown> ? T[] : never, DomainWorkflowError>;
30
+ export declare function decodeEvidenceArray(value: unknown, path: string, requireNonEmpty: boolean): Result<ReturnType<typeof makeEvidenceText> extends Result<infer T, unknown> ? T[] : never, DomainWorkflowError>;
31
+ export declare function decodeRiskArray(value: unknown, path: string): Result<RiskText[], DomainWorkflowError>;
32
+ export declare function decodeOptionalRiskArray(value: unknown, path: string): Result<RiskText[] | undefined, DomainWorkflowError>;
33
+ export declare function decodeHunsuTarget(value: unknown, path: string): Result<HunsuTarget, DomainWorkflowError>;
34
+ export declare function decodeAgentConversationRef(value: unknown, path: string): Result<AgentConversationRef | undefined, DomainWorkflowError>;
35
+ export declare function decodeWorktreeRef(value: unknown, path: string): Result<WorktreeRef | undefined, DomainWorkflowError>;
36
+ export declare function decodeSkillBinding(value: unknown, path: string): Result<SkillBinding, DomainWorkflowError>;
37
+ export declare function decodeMemberPluginBinding(value: unknown, path: string): Result<MemberPluginBinding, DomainWorkflowError>;
38
+ export declare function decodeHubPackageLock(value: unknown, path: string, allowedKinds?: HubPackageKind[]): Result<HubPackageLock | undefined, DomainWorkflowError>;
39
+ export declare function decodeExecutorPackageBindings(value: unknown, path: string): Result<ExecutorPackageBinding[], DomainWorkflowError>;
40
+ export declare function decodeResourcePackageBindings(value: unknown, path: string): Result<ResourcePackageBinding[], DomainWorkflowError>;
41
+ export declare function decodeHunsuOrigin(value: unknown, path: string): Result<HunsuOrigin, DomainWorkflowError>;
42
+ export declare function decodeArtifactRecord(value: unknown, path: string): Result<ArtifactRecord, DomainWorkflowError>;
43
+ export declare function decodeArtifactActionDefinition(value: unknown, path: string): Result<ArtifactActionDefinition, DomainWorkflowError>;
44
+ export declare function decodeArtifactActionPatch(value: unknown, path: string): Result<ArtifactActionPatch, DomainWorkflowError>;
45
+ export declare function decodeLineRecord(value: unknown, path: string): Result<LineRecord, DomainWorkflowError>;
46
+ export declare function decodeSkillDraftRecord(value: unknown, path: string): Result<SkillDraftRecord, DomainWorkflowError>;
47
+ export declare function decodeHunsuDraftRecord(value: unknown, path: string, decodeHarness: HarnessDecoder): Result<HunsuDraftRecord, DomainWorkflowError>;
48
+ export declare function decodeMoveRecord(value: unknown, path: string, decodeHarness: HarnessDecoder): Result<MoveRecord, DomainWorkflowError>;
49
+ export declare function decodeHunsuRecord(value: unknown, path: string, decodeHarness: HarnessDecoder): Result<HunsuRecord, DomainWorkflowError>;
50
+ export declare function decodeNodeRecord(value: unknown, path: string, decodeHarness: HarnessDecoder): Result<NodeRecord, DomainWorkflowError>;
51
+ export declare function decodeOptionalHunsuDraftId(value: unknown): Result<ReturnType<typeof makeHunsuDraftId> extends Result<infer T, unknown> ? T | undefined : never, DomainWorkflowError>;
52
+ export declare function decodeOptionalHunsuId(value: unknown): Result<ReturnType<typeof makeHunsuId> extends Result<infer T, unknown> ? T | undefined : never, DomainWorkflowError>;
53
+ export declare function decodeOptionalMoveId(value: unknown): Result<ReturnType<typeof makeMoveId> extends Result<infer T, unknown> ? T | undefined : never, DomainWorkflowError>;
54
+ export declare function decodeArtifactActionIdArray(value: unknown, path: string): Result<Array<ReturnType<typeof makeArtifactActionId> extends Result<infer T, unknown> ? T : never>, DomainWorkflowError>;
55
+ export declare function decodeOptionalLineId(value: unknown): Result<ReturnType<typeof makeLineId> extends Result<infer T, unknown> ? T | undefined : never, DomainWorkflowError>;
56
+ export declare function decodeOptionalNodeId(value: unknown): Result<ReturnType<typeof makeNodeId> extends Result<infer T, unknown> ? T | undefined : never, DomainWorkflowError>;
57
+ export declare function decodeOptionalExecuteId(value: unknown): Result<ReturnType<typeof makeExecuteId> extends Result<infer T, unknown> ? T | undefined : never, DomainWorkflowError>;
58
+ export declare function decodeArtifactActionDefinitionArray(value: unknown, path: string): Result<ArtifactActionDefinition[], DomainWorkflowError>;