@hobin/developer 0.1.5 → 0.1.7
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/README.md +128 -86
- package/SOURCES.md +8 -8
- package/extensions/developer.ts +1713 -1176
- package/extensions/machine.ts +418 -286
- package/extensions/references/behavior-preserving-structural-change.md +14 -13
- package/extensions/state.ts +486 -330
- package/extensions/tool-policy.ts +70 -64
- package/extensions/tui.ts +1713 -653
- package/package.json +1 -1
- package/skills/sketch/references/responsibility-and-variation.md +1 -1
package/extensions/machine.ts
CHANGED
|
@@ -1,344 +1,476 @@
|
|
|
1
1
|
import { assign, setup, transition, type StateValue } from "xstate";
|
|
2
2
|
|
|
3
3
|
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
ActivationEvent,
|
|
5
|
+
DeveloperEvent,
|
|
6
|
+
DeveloperState,
|
|
7
|
+
FocusEvent,
|
|
8
|
+
JudgmentEvent,
|
|
9
|
+
PendingQuestion,
|
|
10
|
+
RouteEvent,
|
|
11
11
|
} from "./state.ts";
|
|
12
12
|
|
|
13
13
|
type DeveloperMachineEvent =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
| { type: "ACTIVATION"; event: ActivationEvent }
|
|
15
|
+
| { type: "FOCUS"; event: FocusEvent }
|
|
16
|
+
| { type: "ROUTE"; event: RouteEvent }
|
|
17
|
+
| { type: "JUDGMENT"; event: JudgmentEvent };
|
|
18
18
|
|
|
19
19
|
export type DeveloperMachineTag =
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
| "execute"
|
|
21
|
+
| "mutate"
|
|
22
|
+
| "blocks-implementation"
|
|
23
|
+
| "blocks-completion"
|
|
24
|
+
| "reroute-required"
|
|
25
|
+
| "framing-required"
|
|
26
|
+
| "verification-required";
|
|
27
27
|
|
|
28
28
|
export const initialState = (): DeveloperState => ({
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
enabled: false,
|
|
30
|
+
activeRoute: undefined,
|
|
31
|
+
lastRoute: undefined,
|
|
32
|
+
lastJudgment: undefined,
|
|
33
|
+
routeHistory: [],
|
|
34
|
+
judgmentHistory: [],
|
|
35
|
+
pendingQuestions: [],
|
|
36
|
+
focusedQuestionId: undefined,
|
|
37
|
+
rerouteRequired: false,
|
|
38
|
+
implementationFramingRequired: false,
|
|
39
|
+
verificationRequired: false,
|
|
36
40
|
});
|
|
37
41
|
|
|
38
42
|
function normalizedQuestion(value: string): string {
|
|
39
|
-
|
|
43
|
+
return value
|
|
44
|
+
.toLocaleLowerCase()
|
|
45
|
+
.replace(/[^\p{L}\p{N}]+/gu, " ")
|
|
46
|
+
.trim();
|
|
40
47
|
}
|
|
41
48
|
|
|
42
|
-
function upsertQuestion(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
function upsertQuestion(
|
|
50
|
+
questions: PendingQuestion[],
|
|
51
|
+
next: PendingQuestion,
|
|
52
|
+
): PendingQuestion[] {
|
|
53
|
+
const nextKey = normalizedQuestion(next.question);
|
|
54
|
+
const existingIndex = questions.findIndex(
|
|
55
|
+
(question) =>
|
|
56
|
+
question.id === next.id ||
|
|
57
|
+
normalizedQuestion(question.question) === nextKey,
|
|
58
|
+
);
|
|
59
|
+
if (existingIndex === -1) return [...questions, next];
|
|
48
60
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
61
|
+
const existing = questions[existingIndex];
|
|
62
|
+
if (!existing) return [...questions, next];
|
|
63
|
+
const updated = [...questions];
|
|
64
|
+
updated[existingIndex] = { ...next, id: existing.id };
|
|
65
|
+
return updated;
|
|
54
66
|
}
|
|
55
67
|
|
|
56
|
-
function applyRouteContext(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
function applyRouteContext(
|
|
69
|
+
state: DeveloperState,
|
|
70
|
+
event: RouteEvent,
|
|
71
|
+
): DeveloperState {
|
|
72
|
+
return {
|
|
73
|
+
...state,
|
|
74
|
+
activeRoute: event,
|
|
75
|
+
lastRoute: event,
|
|
76
|
+
routeHistory: [...state.routeHistory, event],
|
|
77
|
+
rerouteRequired: false,
|
|
78
|
+
focusedQuestionId:
|
|
79
|
+
event.targetQuestionId === state.focusedQuestionId
|
|
80
|
+
? undefined
|
|
81
|
+
: state.focusedQuestionId,
|
|
82
|
+
};
|
|
66
83
|
}
|
|
67
84
|
|
|
68
85
|
function questionsAfterJudgment(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
86
|
+
state: DeveloperState,
|
|
87
|
+
route: RouteEvent,
|
|
88
|
+
event: JudgmentEvent,
|
|
72
89
|
): PendingQuestion[] {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
90
|
+
let pending = [...state.pendingQuestions];
|
|
91
|
+
const remainsOpen =
|
|
92
|
+
event.status === "needs-evidence" || event.status === "blocked";
|
|
93
|
+
if (
|
|
94
|
+
!route.targetQuestionId &&
|
|
95
|
+
remainsOpen &&
|
|
96
|
+
event.openedQuestions.length === 0
|
|
97
|
+
) {
|
|
98
|
+
pending = upsertQuestion(pending, {
|
|
99
|
+
id: `question:${route.routeId}`,
|
|
100
|
+
question: route.question,
|
|
101
|
+
status: event.status === "blocked" ? "blocked" : "open",
|
|
102
|
+
resolutionOwner: "unknown",
|
|
103
|
+
gate: event.status === "blocked" ? "before-completion" : "none",
|
|
104
|
+
resolutionCriteria: `Obtain evidence that settles: ${route.question}`,
|
|
105
|
+
sourceRouteId: route.routeId,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
86
108
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
109
|
+
for (const question of event.openedQuestions)
|
|
110
|
+
pending = upsertQuestion(pending, question);
|
|
111
|
+
for (const update of event.questionUpdates) {
|
|
112
|
+
if (update.status === "resolved" || update.status === "not-applicable") {
|
|
113
|
+
pending = pending.filter((question) => question.id !== update.questionId);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
const existing = pending.find(
|
|
117
|
+
(question) => question.id === update.questionId,
|
|
118
|
+
);
|
|
119
|
+
if (!existing) continue;
|
|
120
|
+
pending = upsertQuestion(pending, {
|
|
121
|
+
...existing,
|
|
122
|
+
status: update.status,
|
|
123
|
+
sourceRouteId: route.routeId,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return pending;
|
|
102
127
|
}
|
|
103
128
|
|
|
104
|
-
function framingAfterJudgment(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
129
|
+
function framingAfterJudgment(
|
|
130
|
+
state: DeveloperState,
|
|
131
|
+
route: RouteEvent,
|
|
132
|
+
event: JudgmentEvent,
|
|
133
|
+
): boolean {
|
|
134
|
+
if (route.target === "model" && event.status === "resolved") return true;
|
|
135
|
+
const closesGate =
|
|
136
|
+
(route.target === "sketch" || route.target === "signal") &&
|
|
137
|
+
(event.status === "resolved" || event.status === "not-applicable");
|
|
138
|
+
return closesGate ? false : state.implementationFramingRequired;
|
|
110
139
|
}
|
|
111
140
|
|
|
112
141
|
function verificationAfterJudgment(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
142
|
+
state: DeveloperState,
|
|
143
|
+
route: RouteEvent,
|
|
144
|
+
event: JudgmentEvent,
|
|
145
|
+
pending: PendingQuestion[],
|
|
117
146
|
): boolean {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
147
|
+
if (route.target === "implementation" && event.changedArtifacts) return true;
|
|
148
|
+
const completionQuestionRemains = pending.some(
|
|
149
|
+
(question) =>
|
|
150
|
+
question.gate === "before-completion" ||
|
|
151
|
+
question.gate === "before-implementation",
|
|
152
|
+
);
|
|
153
|
+
if (
|
|
154
|
+
route.target === "verify" &&
|
|
155
|
+
event.status === "resolved" &&
|
|
156
|
+
!completionQuestionRemains
|
|
157
|
+
) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
return state.verificationRequired;
|
|
126
161
|
}
|
|
127
162
|
|
|
128
|
-
function applyJudgmentContext(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
163
|
+
function applyJudgmentContext(
|
|
164
|
+
state: DeveloperState,
|
|
165
|
+
event: JudgmentEvent,
|
|
166
|
+
): DeveloperState {
|
|
167
|
+
const route = state.activeRoute;
|
|
168
|
+
if (!route) return state;
|
|
169
|
+
const judgment = { ...event, question: route.question, target: route.target };
|
|
170
|
+
const pending = questionsAfterJudgment(state, route, event);
|
|
171
|
+
return {
|
|
172
|
+
...state,
|
|
173
|
+
activeRoute: undefined,
|
|
174
|
+
lastJudgment: judgment,
|
|
175
|
+
judgmentHistory: [...state.judgmentHistory, judgment],
|
|
176
|
+
pendingQuestions: pending,
|
|
177
|
+
focusedQuestionId: pending.some(
|
|
178
|
+
(question) => question.id === state.focusedQuestionId,
|
|
179
|
+
)
|
|
180
|
+
? state.focusedQuestionId
|
|
181
|
+
: undefined,
|
|
182
|
+
rerouteRequired: route.target === "implementation",
|
|
183
|
+
implementationFramingRequired: framingAfterJudgment(state, route, event),
|
|
184
|
+
verificationRequired: verificationAfterJudgment(
|
|
185
|
+
state,
|
|
186
|
+
route,
|
|
187
|
+
event,
|
|
188
|
+
pending,
|
|
189
|
+
),
|
|
190
|
+
};
|
|
146
191
|
}
|
|
147
192
|
|
|
148
193
|
function assertNever(value: never): never {
|
|
149
|
-
|
|
194
|
+
throw new Error(
|
|
195
|
+
`Unexpected Developer machine event: ${JSON.stringify(value)}`,
|
|
196
|
+
);
|
|
150
197
|
}
|
|
151
198
|
|
|
152
|
-
function reduceDeveloperContext(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
199
|
+
function reduceDeveloperContext(
|
|
200
|
+
state: DeveloperState,
|
|
201
|
+
event: DeveloperEvent,
|
|
202
|
+
): DeveloperState {
|
|
203
|
+
switch (event.kind) {
|
|
204
|
+
case "activation":
|
|
205
|
+
return event.enabled ? { ...state, enabled: true } : initialState();
|
|
206
|
+
case "focus":
|
|
207
|
+
return { ...state, focusedQuestionId: event.questionId };
|
|
208
|
+
case "route":
|
|
209
|
+
return applyRouteContext(state, event);
|
|
210
|
+
case "judgment":
|
|
211
|
+
return applyJudgmentContext(state, event);
|
|
212
|
+
default:
|
|
213
|
+
return assertNever(event);
|
|
214
|
+
}
|
|
165
215
|
}
|
|
166
216
|
|
|
167
217
|
function machineEvent(event: DeveloperEvent): DeveloperMachineEvent {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
218
|
+
switch (event.kind) {
|
|
219
|
+
case "activation":
|
|
220
|
+
return { type: "ACTIVATION", event };
|
|
221
|
+
case "focus":
|
|
222
|
+
return { type: "FOCUS", event };
|
|
223
|
+
case "route":
|
|
224
|
+
return { type: "ROUTE", event };
|
|
225
|
+
case "judgment":
|
|
226
|
+
return { type: "JUDGMENT", event };
|
|
227
|
+
default:
|
|
228
|
+
return assertNever(event);
|
|
229
|
+
}
|
|
180
230
|
}
|
|
181
231
|
|
|
182
|
-
function canApplyEvent(
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
232
|
+
function canApplyEvent(
|
|
233
|
+
context: DeveloperState,
|
|
234
|
+
event: DeveloperMachineEvent,
|
|
235
|
+
): boolean {
|
|
236
|
+
switch (event.type) {
|
|
237
|
+
case "ACTIVATION":
|
|
238
|
+
return true;
|
|
239
|
+
case "FOCUS":
|
|
240
|
+
return (
|
|
241
|
+
context.enabled &&
|
|
242
|
+
context.pendingQuestions.some(
|
|
243
|
+
(question) => question.id === event.event.questionId,
|
|
244
|
+
)
|
|
245
|
+
);
|
|
246
|
+
case "ROUTE":
|
|
247
|
+
return (
|
|
248
|
+
context.enabled &&
|
|
249
|
+
!context.activeRoute &&
|
|
250
|
+
(event.event.target !== "implementation" ||
|
|
251
|
+
!context.pendingQuestions.some(
|
|
252
|
+
(question) => question.gate === "before-implementation",
|
|
253
|
+
))
|
|
254
|
+
);
|
|
255
|
+
case "JUDGMENT":
|
|
256
|
+
return (
|
|
257
|
+
context.enabled && context.activeRoute?.routeId === event.event.routeId
|
|
258
|
+
);
|
|
259
|
+
default:
|
|
260
|
+
return assertNever(event);
|
|
261
|
+
}
|
|
199
262
|
}
|
|
200
263
|
|
|
201
264
|
const machineSetup = setup({
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
265
|
+
types: {
|
|
266
|
+
context: {} as DeveloperState,
|
|
267
|
+
events: {} as DeveloperMachineEvent,
|
|
268
|
+
tags: {} as DeveloperMachineTag,
|
|
269
|
+
},
|
|
270
|
+
actions: {
|
|
271
|
+
applyEvent: assign(({ context, event }) =>
|
|
272
|
+
reduceDeveloperContext(context, event.event),
|
|
273
|
+
),
|
|
274
|
+
},
|
|
275
|
+
guards: {
|
|
276
|
+
eventAllowed: ({ context, event }) => canApplyEvent(context, event),
|
|
277
|
+
activationDisabled: ({ context }) => !context.enabled,
|
|
278
|
+
activationEnabled: ({ context }) => context.enabled,
|
|
279
|
+
routeIdle: ({ context }) => !context.activeRoute,
|
|
280
|
+
routeJudgment: ({ context }) =>
|
|
281
|
+
Boolean(
|
|
282
|
+
context.activeRoute && context.activeRoute.target !== "implementation",
|
|
283
|
+
),
|
|
284
|
+
routeImplementation: ({ context }) =>
|
|
285
|
+
context.activeRoute?.target === "implementation",
|
|
286
|
+
questionsClear: ({ context }) => context.pendingQuestions.length === 0,
|
|
287
|
+
questionsOpen: ({ context }) => context.pendingQuestions.length > 0,
|
|
288
|
+
implementationGateClear: ({ context }) =>
|
|
289
|
+
!context.pendingQuestions.some(
|
|
290
|
+
(question) => question.gate === "before-implementation",
|
|
291
|
+
),
|
|
292
|
+
implementationGateBlocked: ({ context }) =>
|
|
293
|
+
context.pendingQuestions.some(
|
|
294
|
+
(question) => question.gate === "before-implementation",
|
|
295
|
+
),
|
|
296
|
+
completionGateClear: ({ context }) =>
|
|
297
|
+
!context.pendingQuestions.some(
|
|
298
|
+
(question) =>
|
|
299
|
+
question.gate === "before-implementation" ||
|
|
300
|
+
question.gate === "before-completion",
|
|
301
|
+
),
|
|
302
|
+
completionGateBlocked: ({ context }) =>
|
|
303
|
+
context.pendingQuestions.some(
|
|
304
|
+
(question) =>
|
|
305
|
+
question.gate === "before-implementation" ||
|
|
306
|
+
question.gate === "before-completion",
|
|
307
|
+
),
|
|
308
|
+
checkpointReady: ({ context }) => !context.rerouteRequired,
|
|
309
|
+
checkpointRequired: ({ context }) => context.rerouteRequired,
|
|
310
|
+
framingClear: ({ context }) => !context.implementationFramingRequired,
|
|
311
|
+
framingRequired: ({ context }) => context.implementationFramingRequired,
|
|
312
|
+
verificationCurrent: ({ context }) => !context.verificationRequired,
|
|
313
|
+
verificationRequired: ({ context }) => context.verificationRequired,
|
|
314
|
+
},
|
|
239
315
|
});
|
|
240
316
|
|
|
241
317
|
export const developerMachine = machineSetup.createMachine({
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
318
|
+
id: "developer",
|
|
319
|
+
type: "parallel",
|
|
320
|
+
context: initialState(),
|
|
321
|
+
on: {
|
|
322
|
+
ACTIVATION: { guard: "eventAllowed", actions: "applyEvent" },
|
|
323
|
+
FOCUS: { guard: "eventAllowed", actions: "applyEvent" },
|
|
324
|
+
ROUTE: { guard: "eventAllowed", actions: "applyEvent" },
|
|
325
|
+
JUDGMENT: { guard: "eventAllowed", actions: "applyEvent" },
|
|
326
|
+
},
|
|
327
|
+
states: {
|
|
328
|
+
activation: {
|
|
329
|
+
initial: "disabled",
|
|
330
|
+
states: {
|
|
331
|
+
disabled: { always: { guard: "activationEnabled", target: "enabled" } },
|
|
332
|
+
enabled: {
|
|
333
|
+
always: { guard: "activationDisabled", target: "disabled" },
|
|
334
|
+
},
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
route: {
|
|
338
|
+
initial: "idle",
|
|
339
|
+
states: {
|
|
340
|
+
idle: {
|
|
341
|
+
always: [
|
|
342
|
+
{ guard: "routeImplementation", target: "implementation" },
|
|
343
|
+
{ guard: "routeJudgment", target: "judgment" },
|
|
344
|
+
],
|
|
345
|
+
},
|
|
346
|
+
judgment: {
|
|
347
|
+
tags: "execute",
|
|
348
|
+
always: [
|
|
349
|
+
{ guard: "routeIdle", target: "idle" },
|
|
350
|
+
{ guard: "routeImplementation", target: "implementation" },
|
|
351
|
+
],
|
|
352
|
+
},
|
|
353
|
+
implementation: {
|
|
354
|
+
tags: ["execute", "mutate"],
|
|
355
|
+
always: [
|
|
356
|
+
{ guard: "routeIdle", target: "idle" },
|
|
357
|
+
{ guard: "routeJudgment", target: "judgment" },
|
|
358
|
+
],
|
|
359
|
+
},
|
|
360
|
+
},
|
|
361
|
+
},
|
|
362
|
+
questions: {
|
|
363
|
+
initial: "clear",
|
|
364
|
+
states: {
|
|
365
|
+
clear: { always: { guard: "questionsOpen", target: "open" } },
|
|
366
|
+
open: { always: { guard: "questionsClear", target: "clear" } },
|
|
367
|
+
},
|
|
368
|
+
},
|
|
369
|
+
implementationGate: {
|
|
370
|
+
initial: "clear",
|
|
371
|
+
states: {
|
|
372
|
+
clear: {
|
|
373
|
+
always: { guard: "implementationGateBlocked", target: "blocked" },
|
|
374
|
+
},
|
|
375
|
+
blocked: {
|
|
376
|
+
tags: "blocks-implementation",
|
|
377
|
+
always: { guard: "implementationGateClear", target: "clear" },
|
|
378
|
+
},
|
|
379
|
+
},
|
|
380
|
+
},
|
|
381
|
+
completionGate: {
|
|
382
|
+
initial: "clear",
|
|
383
|
+
states: {
|
|
384
|
+
clear: {
|
|
385
|
+
always: { guard: "completionGateBlocked", target: "blocked" },
|
|
386
|
+
},
|
|
387
|
+
blocked: {
|
|
388
|
+
tags: "blocks-completion",
|
|
389
|
+
always: { guard: "completionGateClear", target: "clear" },
|
|
390
|
+
},
|
|
391
|
+
},
|
|
392
|
+
},
|
|
393
|
+
checkpoint: {
|
|
394
|
+
initial: "ready",
|
|
395
|
+
states: {
|
|
396
|
+
ready: { always: { guard: "checkpointRequired", target: "required" } },
|
|
397
|
+
required: {
|
|
398
|
+
tags: "reroute-required",
|
|
399
|
+
always: { guard: "checkpointReady", target: "ready" },
|
|
400
|
+
},
|
|
401
|
+
},
|
|
402
|
+
},
|
|
403
|
+
framing: {
|
|
404
|
+
initial: "clear",
|
|
405
|
+
states: {
|
|
406
|
+
clear: { always: { guard: "framingRequired", target: "required" } },
|
|
407
|
+
required: {
|
|
408
|
+
tags: "framing-required",
|
|
409
|
+
always: { guard: "framingClear", target: "clear" },
|
|
410
|
+
},
|
|
411
|
+
},
|
|
412
|
+
},
|
|
413
|
+
verification: {
|
|
414
|
+
initial: "current",
|
|
415
|
+
states: {
|
|
416
|
+
current: {
|
|
417
|
+
always: { guard: "verificationRequired", target: "required" },
|
|
418
|
+
},
|
|
419
|
+
required: {
|
|
420
|
+
tags: "verification-required",
|
|
421
|
+
always: { guard: "verificationCurrent", target: "current" },
|
|
422
|
+
},
|
|
423
|
+
},
|
|
424
|
+
},
|
|
425
|
+
},
|
|
311
426
|
});
|
|
312
427
|
|
|
313
428
|
function machineValue(state: DeveloperState): StateValue {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
429
|
+
let route = "idle";
|
|
430
|
+
if (state.activeRoute?.target === "implementation") route = "implementation";
|
|
431
|
+
else if (state.activeRoute) route = "judgment";
|
|
432
|
+
const implementationBlocked = state.pendingQuestions.some(
|
|
433
|
+
(question) => question.gate === "before-implementation",
|
|
434
|
+
);
|
|
435
|
+
const completionBlocked = state.pendingQuestions.some(
|
|
436
|
+
(question) =>
|
|
437
|
+
question.gate === "before-implementation" ||
|
|
438
|
+
question.gate === "before-completion",
|
|
439
|
+
);
|
|
440
|
+
return {
|
|
441
|
+
activation: state.enabled ? "enabled" : "disabled",
|
|
442
|
+
route,
|
|
443
|
+
questions: state.pendingQuestions.length > 0 ? "open" : "clear",
|
|
444
|
+
implementationGate: implementationBlocked ? "blocked" : "clear",
|
|
445
|
+
completionGate: completionBlocked ? "blocked" : "clear",
|
|
446
|
+
checkpoint: state.rerouteRequired ? "required" : "ready",
|
|
447
|
+
framing: state.implementationFramingRequired ? "required" : "clear",
|
|
448
|
+
verification: state.verificationRequired ? "required" : "current",
|
|
449
|
+
};
|
|
331
450
|
}
|
|
332
451
|
|
|
333
452
|
export function developerSnapshot(state: DeveloperState) {
|
|
334
|
-
|
|
453
|
+
return developerMachine.resolveState({
|
|
454
|
+
value: machineValue(state),
|
|
455
|
+
context: state,
|
|
456
|
+
});
|
|
335
457
|
}
|
|
336
458
|
|
|
337
|
-
export function canApplyDeveloperEvent(
|
|
338
|
-
|
|
459
|
+
export function canApplyDeveloperEvent(
|
|
460
|
+
state: DeveloperState,
|
|
461
|
+
event: DeveloperEvent,
|
|
462
|
+
): boolean {
|
|
463
|
+
return developerSnapshot(state).can(machineEvent(event));
|
|
339
464
|
}
|
|
340
465
|
|
|
341
|
-
export function applyDeveloperEvent(
|
|
342
|
-
|
|
343
|
-
|
|
466
|
+
export function applyDeveloperEvent(
|
|
467
|
+
state: DeveloperState,
|
|
468
|
+
event: DeveloperEvent,
|
|
469
|
+
): DeveloperState {
|
|
470
|
+
const [nextSnapshot] = transition(
|
|
471
|
+
developerMachine,
|
|
472
|
+
developerSnapshot(state),
|
|
473
|
+
machineEvent(event),
|
|
474
|
+
);
|
|
475
|
+
return nextSnapshot.context;
|
|
344
476
|
}
|