@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.
- package/LICENSE +157 -0
- package/dist/command-decoder.d.ts +5 -0
- package/dist/command-decoder.js +329 -0
- package/dist/constants.d.ts +15 -0
- package/dist/constants.js +15 -0
- package/dist/decoder-helpers.d.ts +58 -0
- package/dist/decoder-helpers.js +1757 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.js +28 -0
- package/dist/event-decoder.d.ts +5 -0
- package/dist/event-decoder.js +232 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/lifecycle.d.ts +67 -0
- package/dist/lifecycle.js +271 -0
- package/dist/model.d.ts +1058 -0
- package/dist/model.js +1 -0
- package/dist/primitives.d.ts +59 -0
- package/dist/primitives.js +135 -0
- package/dist/projection.d.ts +8 -0
- package/dist/projection.js +875 -0
- package/dist/prompt-template.d.ts +12 -0
- package/dist/prompt-template.js +83 -0
- package/dist/protocol-validation.d.ts +36 -0
- package/dist/protocol-validation.js +1139 -0
- package/dist/result.d.ts +20 -0
- package/dist/result.js +21 -0
- package/dist/workflow-helpers.d.ts +31 -0
- package/dist/workflow-helpers.js +193 -0
- package/dist/workflow.d.ts +10 -0
- package/dist/workflow.js +594 -0
- package/package.json +30 -0
- package/src/command-decoder.ts +292 -0
- package/src/constants.ts +27 -0
- package/src/decoder-helpers.ts +1672 -0
- package/src/errors.ts +38 -0
- package/src/event-decoder.ts +225 -0
- package/src/index.ts +43 -0
- package/src/lifecycle.ts +403 -0
- package/src/model.ts +1233 -0
- package/src/primitives.ts +196 -0
- package/src/projection.ts +1081 -0
- package/src/prompt-template.ts +97 -0
- package/src/protocol-validation.ts +1252 -0
- package/src/result.ts +35 -0
- package/src/workflow-helpers.ts +239 -0
- package/src/workflow.ts +753 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { err, ok, type Result } from "./result.ts";
|
|
2
|
+
|
|
3
|
+
export type Brand<T, Name extends string> = T & { readonly __brand: Name };
|
|
4
|
+
export type NonEmptyText = Brand<string, "NonEmptyText">;
|
|
5
|
+
export type RequestTitle = Brand<string, "RequestTitle">;
|
|
6
|
+
export type RequestGoal = Brand<string, "RequestGoal">;
|
|
7
|
+
export type DestinationTitle = Brand<string, "DestinationTitle">;
|
|
8
|
+
export type DestinationAcceptanceCriterion = Brand<string, "DestinationAcceptanceCriterion">;
|
|
9
|
+
export type DestinationConstraint = Brand<string, "DestinationConstraint">;
|
|
10
|
+
export type DestinationNotes = Brand<string, "DestinationNotes">;
|
|
11
|
+
export type Summary = Brand<string, "Summary">;
|
|
12
|
+
export type EvidenceText = Brand<string, "EvidenceText">;
|
|
13
|
+
export type FailureReason = Brand<string, "FailureReason">;
|
|
14
|
+
export type RiskText = Brand<string, "RiskText">;
|
|
15
|
+
export type MoveCommit = Brand<string, "MoveCommit">;
|
|
16
|
+
export type TeamName = Brand<string, "TeamName">;
|
|
17
|
+
export type PositiveInteger = Brand<number, "PositiveInteger">;
|
|
18
|
+
export type NonNegativeInteger = Brand<number, "NonNegativeInteger">;
|
|
19
|
+
export type NonEmptyArray<T> = [T, ...T[]];
|
|
20
|
+
export type SingleItemArray<T> = [T];
|
|
21
|
+
|
|
22
|
+
export type PrimitiveValidationError = {
|
|
23
|
+
type: "PrimitiveValidationError";
|
|
24
|
+
field: string;
|
|
25
|
+
message: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export function makeNonEmptyText(value: unknown, field = "text"): Result<NonEmptyText, PrimitiveValidationError> {
|
|
29
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
30
|
+
return invalid(field, `${field} must be a non-empty string`);
|
|
31
|
+
}
|
|
32
|
+
return ok(value as NonEmptyText);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function makeRequestTitle(value: unknown): Result<RequestTitle, PrimitiveValidationError> {
|
|
36
|
+
return makeTextBrand(value, "title");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function makeRequestGoal(value: unknown): Result<RequestGoal, PrimitiveValidationError> {
|
|
40
|
+
return makeTextBrand(value, "goal");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function makeDestinationTitle(value: unknown, field = "title"): Result<DestinationTitle, PrimitiveValidationError> {
|
|
44
|
+
return makeTextBrand(value, field);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function makeDestinationAcceptanceCriterion(value: unknown, field = "acceptanceCriterion"): Result<DestinationAcceptanceCriterion, PrimitiveValidationError> {
|
|
48
|
+
return makeTextBrand(value, field);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function makeDestinationConstraint(value: unknown, field = "constraint"): Result<DestinationConstraint, PrimitiveValidationError> {
|
|
52
|
+
return makeTextBrand(value, field);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function makeDestinationNotes(value: unknown, field = "notes"): Result<DestinationNotes, PrimitiveValidationError> {
|
|
56
|
+
return makeTextBrand(value, field);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function makeSummary(value: unknown, field = "summary"): Result<Summary, PrimitiveValidationError> {
|
|
60
|
+
return makeTextBrand(value, field);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function makeEvidenceText(value: unknown, field = "evidence"): Result<EvidenceText, PrimitiveValidationError> {
|
|
64
|
+
return makeTextBrand(value, field);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function makeFailureReason(value: unknown, field = "failureReason"): Result<FailureReason, PrimitiveValidationError> {
|
|
68
|
+
return makeTextBrand(value, field);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function makeRiskText(value: unknown, field = "risk"): Result<RiskText, PrimitiveValidationError> {
|
|
72
|
+
return makeTextBrand(value, field);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function makeMoveCommit(value: unknown, field = "commit"): Result<MoveCommit, PrimitiveValidationError> {
|
|
76
|
+
return makeTextBrand(value, field);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function makeTeamName(value: unknown, field = "teamName"): Result<TeamName, PrimitiveValidationError> {
|
|
80
|
+
return makeTextBrand(value, field);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function makePositiveInteger(value: unknown, field = "number"): Result<PositiveInteger, PrimitiveValidationError> {
|
|
84
|
+
if (!Number.isInteger(value) || Number(value) < 1) {
|
|
85
|
+
return invalid(field, `${field} must be a positive integer`);
|
|
86
|
+
}
|
|
87
|
+
return ok(value as PositiveInteger);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function makeNonNegativeInteger(value: unknown, field = "number"): Result<NonNegativeInteger, PrimitiveValidationError> {
|
|
91
|
+
if (!Number.isInteger(value) || Number(value) < 0) {
|
|
92
|
+
return invalid(field, `${field} must be a non-negative integer`);
|
|
93
|
+
}
|
|
94
|
+
return ok(value as NonNegativeInteger);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function makeNonEmptyArray<T>(value: T[], field = "array"): Result<NonEmptyArray<T>, PrimitiveValidationError> {
|
|
98
|
+
if (value.length === 0) {
|
|
99
|
+
return invalid(field, `${field} must include at least one item`);
|
|
100
|
+
}
|
|
101
|
+
return ok(value as NonEmptyArray<T>);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function makeSingleItemArray<T>(value: T[], field = "array"): Result<SingleItemArray<T>, PrimitiveValidationError> {
|
|
105
|
+
if (value.length !== 1) {
|
|
106
|
+
return invalid(field, `${field} must include exactly one item`);
|
|
107
|
+
}
|
|
108
|
+
return ok(value as SingleItemArray<T>);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function makeDomainId<T extends string>(value: unknown, field: string): Result<Brand<string, T>, PrimitiveValidationError> {
|
|
112
|
+
const text = makeNonEmptyText(value, field);
|
|
113
|
+
if (!text.ok) {
|
|
114
|
+
return text;
|
|
115
|
+
}
|
|
116
|
+
if (/\s/.test(text.value)) {
|
|
117
|
+
return invalid(field, `${field} must not contain whitespace`);
|
|
118
|
+
}
|
|
119
|
+
return ok(text.value as Brand<string, T>);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function makeRequestId(value: unknown): Result<Brand<string, "RequestId">, PrimitiveValidationError> {
|
|
123
|
+
return makeDomainId(value, "requestId");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function makeDestinationId(value: unknown): Result<Brand<string, "DestinationId">, PrimitiveValidationError> {
|
|
127
|
+
return makeDomainId(value, "destinationId");
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function makeMoveId(value: unknown): Result<Brand<string, "MoveId">, PrimitiveValidationError> {
|
|
131
|
+
return makeDomainId(value, "moveId");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function makeHunsuId(value: unknown): Result<Brand<string, "HunsuId">, PrimitiveValidationError> {
|
|
135
|
+
return makeDomainId(value, "hunsuId");
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function makeHunsuDraftId(value: unknown): Result<Brand<string, "HunsuDraftId">, PrimitiveValidationError> {
|
|
139
|
+
return makeDomainId(value, "hunsuDraftId");
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function makeLineId(value: unknown): Result<Brand<string, "LineId">, PrimitiveValidationError> {
|
|
143
|
+
return makeDomainId(value, "lineId");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function makeNodeId(value: unknown): Result<Brand<string, "NodeId">, PrimitiveValidationError> {
|
|
147
|
+
return makeDomainId(value, "nodeId");
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function makeArtifactId(value: unknown): Result<Brand<string, "ArtifactId">, PrimitiveValidationError> {
|
|
151
|
+
return makeDomainId(value, "artifactId");
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function makeArtifactActionId(value: unknown): Result<Brand<string, "ArtifactActionId">, PrimitiveValidationError> {
|
|
155
|
+
return makeDomainId(value, "artifactActionId");
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function makeTeamId(value: unknown): Result<Brand<string, "TeamId">, PrimitiveValidationError> {
|
|
159
|
+
return makeDomainId(value, "teamId");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function makeSkillDraftId(value: unknown): Result<Brand<string, "SkillDraftId">, PrimitiveValidationError> {
|
|
163
|
+
return makeDomainId(value, "skillDraftId");
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function makeAgentConversationHash(value: unknown): Result<Brand<string, "AgentConversationHash">, PrimitiveValidationError> {
|
|
167
|
+
return makeDomainId(value, "agentConversationHash");
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function makeExecuteId(value: unknown): Result<Brand<string, "ExecuteId">, PrimitiveValidationError> {
|
|
171
|
+
return makeDomainId(value, "executeId");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function makeRouteId(value: unknown): Result<Brand<string, "RouteId">, PrimitiveValidationError> {
|
|
175
|
+
return makeDomainId(value, "routeId");
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function makeWorktreeHash(value: unknown): Result<Brand<string, "WorktreeHash">, PrimitiveValidationError> {
|
|
179
|
+
return makeDomainId(value, "worktreeHash");
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function invalid(field: string, message: string): Result<never, PrimitiveValidationError> {
|
|
183
|
+
return err({ type: "PrimitiveValidationError", field, message });
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function makeTextBrand<T extends string>(value: unknown, field: string): Result<Brand<string, T>, PrimitiveValidationError> {
|
|
187
|
+
const text = makeNonEmptyText(value, field);
|
|
188
|
+
return text.ok ? ok(text.value as Brand<string, T>) : text;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function makeStringBrand<T extends string>(value: unknown, field: string): Result<Brand<string, T>, PrimitiveValidationError> {
|
|
192
|
+
if (typeof value !== "string") {
|
|
193
|
+
return invalid(field, `${field} must be a string`);
|
|
194
|
+
}
|
|
195
|
+
return ok(value as Brand<string, T>);
|
|
196
|
+
}
|