@trevonistrevon/pi-loop 0.4.10 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -1
- package/dist/coordinator.d.ts +35 -0
- package/dist/coordinator.js +56 -0
- package/dist/goal-types.d.ts +78 -0
- package/dist/goal-types.js +1 -0
- package/dist/goal-verifier.d.ts +20 -0
- package/dist/goal-verifier.js +198 -0
- package/dist/index.js +182 -40
- package/dist/loop-reducer.d.ts +63 -0
- package/dist/loop-reducer.js +67 -0
- package/dist/monitor-completion-coordinator.d.ts +10 -0
- package/dist/monitor-completion-coordinator.js +13 -0
- package/dist/monitor-manager.d.ts +2 -0
- package/dist/monitor-manager.js +107 -29
- package/dist/monitor-reducer.d.ts +82 -0
- package/dist/monitor-reducer.js +69 -0
- package/dist/notification-reducer.d.ts +81 -0
- package/dist/notification-reducer.js +65 -0
- package/dist/store.d.ts +2 -0
- package/dist/store.js +118 -44
- package/dist/task-backlog-coordinator.d.ts +12 -0
- package/dist/task-backlog-coordinator.js +22 -0
- package/dist/task-reducer.d.ts +66 -0
- package/dist/task-reducer.js +76 -0
- package/dist/task-store.d.ts +2 -0
- package/dist/task-store.js +82 -30
- package/docs/architecture/goal-state-schema.md +505 -0
- package/docs/architecture/state-machine-migration.md +546 -0
- package/docs/architecture/state-machine-reducer-event-model.md +823 -0
- package/docs/architecture/state-machine-test-matrix.md +249 -0
- package/docs/architecture/state-machine-transition-map.md +436 -0
- package/package.json +1 -1
- package/src/coordinator.ts +115 -0
- package/src/goal-types.ts +99 -0
- package/src/goal-verifier.ts +241 -0
- package/src/index.ts +209 -39
- package/src/loop-reducer.ts +148 -0
- package/src/monitor-completion-coordinator.ts +24 -0
- package/src/monitor-manager.ts +115 -27
- package/src/monitor-reducer.ts +166 -0
- package/src/notification-reducer.ts +155 -0
- package/src/store.ts +119 -43
- package/src/task-backlog-coordinator.ts +32 -0
- package/src/task-reducer.ts +152 -0
- package/src/task-store.ts +84 -27
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
export type ReducerSource =
|
|
2
|
+
| "tool"
|
|
3
|
+
| "command"
|
|
4
|
+
| "scheduler"
|
|
5
|
+
| "eventbus"
|
|
6
|
+
| "monitor"
|
|
7
|
+
| "session"
|
|
8
|
+
| "coordinator"
|
|
9
|
+
| "system";
|
|
10
|
+
|
|
11
|
+
export type ReducerEntityType = "task" | "loop" | "monitor" | "notification" | "goal";
|
|
12
|
+
|
|
13
|
+
export interface ReducerEvent<TType extends string = string, TPayload = unknown> {
|
|
14
|
+
type: TType;
|
|
15
|
+
at: number;
|
|
16
|
+
source: ReducerSource;
|
|
17
|
+
entityType?: ReducerEntityType;
|
|
18
|
+
entityId?: string;
|
|
19
|
+
payload: TPayload;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ReducerEffect<TEffect extends string = string, TPayload = unknown> {
|
|
23
|
+
type: TEffect;
|
|
24
|
+
entityType?: ReducerEntityType;
|
|
25
|
+
entityId?: string;
|
|
26
|
+
payload: TPayload;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type DispatchEventEffect = ReducerEffect<"DISPATCH_EVENT", { event: ReducerEvent }>;
|
|
30
|
+
export type AnyReducerEffect = ReducerEffect | DispatchEventEffect;
|
|
31
|
+
|
|
32
|
+
export type ReducerHandler =
|
|
33
|
+
(event: ReducerEvent) => undefined | AnyReducerEffect[] | Promise<undefined | AnyReducerEffect[]>;
|
|
34
|
+
|
|
35
|
+
export type EffectHandler =
|
|
36
|
+
(effect: ReducerEffect) => void | Promise<void>;
|
|
37
|
+
|
|
38
|
+
export interface CoordinatorOptions {
|
|
39
|
+
reducers: ReducerHandler[];
|
|
40
|
+
effectHandlers?: Partial<Record<string, EffectHandler>>;
|
|
41
|
+
effectExecutor?: EffectHandler;
|
|
42
|
+
maxDispatchDepth?: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export class CoordinatorError extends Error {
|
|
46
|
+
constructor(message: string) {
|
|
47
|
+
super(message);
|
|
48
|
+
this.name = "CoordinatorError";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface Coordinator {
|
|
53
|
+
dispatch(event: ReducerEvent): Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function createCoordinator(options: CoordinatorOptions): Coordinator {
|
|
57
|
+
const {
|
|
58
|
+
reducers,
|
|
59
|
+
effectHandlers = {},
|
|
60
|
+
effectExecutor,
|
|
61
|
+
maxDispatchDepth = 100,
|
|
62
|
+
} = options;
|
|
63
|
+
|
|
64
|
+
function isPromiseLike<T>(value: T | Promise<T>): value is Promise<T> {
|
|
65
|
+
return typeof value === "object" && value !== null && "then" in value;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function executeEffect(effect: AnyReducerEffect, depth: number): Promise<void> {
|
|
69
|
+
if (effect.type === "DISPATCH_EVENT") {
|
|
70
|
+
const dispatchEffect = effect as DispatchEventEffect;
|
|
71
|
+
const derivedEvent = dispatchEffect.payload.event;
|
|
72
|
+
if (!derivedEvent) {
|
|
73
|
+
throw new CoordinatorError("DISPATCH_EVENT effect missing payload.event");
|
|
74
|
+
}
|
|
75
|
+
await dispatchAtDepth(derivedEvent, depth + 1);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const specificHandler = effectHandlers[effect.type];
|
|
80
|
+
if (specificHandler) {
|
|
81
|
+
const handled = specificHandler(effect);
|
|
82
|
+
if (isPromiseLike(handled)) await handled;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (effectExecutor) {
|
|
87
|
+
const handled = effectExecutor(effect);
|
|
88
|
+
if (isPromiseLike(handled)) await handled;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function dispatchAtDepth(event: ReducerEvent, depth: number): Promise<void> {
|
|
93
|
+
if (depth > maxDispatchDepth) {
|
|
94
|
+
throw new CoordinatorError(`Maximum dispatch depth exceeded (${maxDispatchDepth})`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const effects: AnyReducerEffect[] = [];
|
|
98
|
+
for (const reducer of reducers) {
|
|
99
|
+
const emitted = reducer(event);
|
|
100
|
+
const resolved = isPromiseLike(emitted) ? await emitted : emitted;
|
|
101
|
+
if (!resolved || resolved.length === 0) continue;
|
|
102
|
+
effects.push(...resolved);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
for (const effect of effects) {
|
|
106
|
+
await executeEffect(effect, depth);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
async dispatch(event: ReducerEvent): Promise<void> {
|
|
112
|
+
await dispatchAtDepth(event, 1);
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
export type GoalStatus =
|
|
2
|
+
| "pending"
|
|
3
|
+
| "active"
|
|
4
|
+
| "satisfied"
|
|
5
|
+
| "blocked"
|
|
6
|
+
| "failed"
|
|
7
|
+
| "archived";
|
|
8
|
+
|
|
9
|
+
export type GoalVerificationStatus =
|
|
10
|
+
| "unknown"
|
|
11
|
+
| "checking"
|
|
12
|
+
| "verified"
|
|
13
|
+
| "unverified"
|
|
14
|
+
| "inconclusive";
|
|
15
|
+
|
|
16
|
+
export interface GoalScope {
|
|
17
|
+
taskIds?: string[];
|
|
18
|
+
loopIds?: string[];
|
|
19
|
+
monitorIds?: string[];
|
|
20
|
+
tags?: string[];
|
|
21
|
+
subjectPrefixes?: string[];
|
|
22
|
+
includeFutureMatchingTasks?: boolean;
|
|
23
|
+
includeFutureMatchingLoops?: boolean;
|
|
24
|
+
includeFutureMatchingMonitors?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface GoalSuccessCriteria {
|
|
28
|
+
minCompletedTasks?: number;
|
|
29
|
+
requiredTaskIds?: string[];
|
|
30
|
+
requiredMonitorIdsCompleted?: string[];
|
|
31
|
+
requiredLoopIdsPresent?: string[];
|
|
32
|
+
requireNoPendingTasksInScope?: boolean;
|
|
33
|
+
requireLatestVerificationPass?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface GoalFailureCriteria {
|
|
37
|
+
anyMonitorIdsErrored?: string[];
|
|
38
|
+
maxVerificationFailures?: number;
|
|
39
|
+
failIfTaskIdsDeleted?: string[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface GoalBlockedCriteria {
|
|
43
|
+
blockedIfAllTasksCompletedButVerificationFails?: boolean;
|
|
44
|
+
blockedIfNoScopedProgressSinceMs?: number;
|
|
45
|
+
blockedIfRequiredLoopMissing?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface GoalCriteria {
|
|
49
|
+
success: GoalSuccessCriteria;
|
|
50
|
+
failure?: GoalFailureCriteria;
|
|
51
|
+
blocked?: GoalBlockedCriteria;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface GoalProgressSnapshot {
|
|
55
|
+
totalTasks: number;
|
|
56
|
+
pendingTasks: number;
|
|
57
|
+
inProgressTasks: number;
|
|
58
|
+
completedTasks: number;
|
|
59
|
+
activeLoops: number;
|
|
60
|
+
pausedLoops: number;
|
|
61
|
+
runningMonitors: number;
|
|
62
|
+
completedMonitors: number;
|
|
63
|
+
erroredMonitors: number;
|
|
64
|
+
stoppedMonitors: number;
|
|
65
|
+
lastProgressAt?: number;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface GoalVerificationState {
|
|
69
|
+
attempts: number;
|
|
70
|
+
passes: number;
|
|
71
|
+
failures: number;
|
|
72
|
+
lastCheckedAt?: number;
|
|
73
|
+
lastPassedAt?: number;
|
|
74
|
+
lastFailedAt?: number;
|
|
75
|
+
lastReason?: string;
|
|
76
|
+
nextCheckAfter?: number;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface GoalEntry {
|
|
80
|
+
id: string;
|
|
81
|
+
title: string;
|
|
82
|
+
description: string;
|
|
83
|
+
status: GoalStatus;
|
|
84
|
+
verificationStatus: GoalVerificationStatus;
|
|
85
|
+
createdAt: number;
|
|
86
|
+
updatedAt: number;
|
|
87
|
+
activatedAt?: number;
|
|
88
|
+
resolvedAt?: number;
|
|
89
|
+
scope: GoalScope;
|
|
90
|
+
criteria: GoalCriteria;
|
|
91
|
+
progress: GoalProgressSnapshot;
|
|
92
|
+
verification: GoalVerificationState;
|
|
93
|
+
metadata?: Record<string, unknown>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface GoalReducerState {
|
|
97
|
+
nextId: number;
|
|
98
|
+
goalsById: Record<string, GoalEntry>;
|
|
99
|
+
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import type { ReducerEffect, ReducerEvent } from "./coordinator.js";
|
|
2
|
+
import type { GoalEntry, GoalProgressSnapshot } from "./goal-types.js";
|
|
3
|
+
import type { LoopReducerState } from "./loop-reducer.js";
|
|
4
|
+
import type { MonitorReducerState } from "./monitor-reducer.js";
|
|
5
|
+
import type { TaskReducerState } from "./task-reducer.js";
|
|
6
|
+
import type { TaskEntry } from "./task-types.js";
|
|
7
|
+
import type { LoopEntry, MonitorEntry } from "./types.js";
|
|
8
|
+
|
|
9
|
+
export interface GoalVerifierInput {
|
|
10
|
+
goal: GoalEntry;
|
|
11
|
+
taskState: TaskReducerState;
|
|
12
|
+
loopState: LoopReducerState;
|
|
13
|
+
monitorState: MonitorReducerState;
|
|
14
|
+
at: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface GoalVerifierResult {
|
|
18
|
+
progress: GoalProgressSnapshot;
|
|
19
|
+
verdict: "passed" | "failed" | "blocked";
|
|
20
|
+
reason: string;
|
|
21
|
+
effects: ReducerEffect[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function uniqueById<T extends { id: string }>(items: T[]): T[] {
|
|
25
|
+
const seen = new Set<string>();
|
|
26
|
+
const result: T[] = [];
|
|
27
|
+
for (const item of items) {
|
|
28
|
+
if (seen.has(item.id)) continue;
|
|
29
|
+
seen.add(item.id);
|
|
30
|
+
result.push(item);
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function selectTasks(goal: GoalEntry, taskState: TaskReducerState): TaskEntry[] {
|
|
36
|
+
const selected: TaskEntry[] = [];
|
|
37
|
+
for (const id of goal.scope.taskIds ?? []) {
|
|
38
|
+
const task = taskState.tasksById[id];
|
|
39
|
+
if (task) selected.push(task);
|
|
40
|
+
}
|
|
41
|
+
for (const prefix of goal.scope.subjectPrefixes ?? []) {
|
|
42
|
+
for (const task of Object.values(taskState.tasksById)) {
|
|
43
|
+
if (task.subject.startsWith(prefix)) selected.push(task);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return uniqueById(selected);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function selectLoops(goal: GoalEntry, loopState: LoopReducerState): LoopEntry[] {
|
|
50
|
+
const selected: LoopEntry[] = [];
|
|
51
|
+
for (const id of goal.scope.loopIds ?? []) {
|
|
52
|
+
const loop = loopState.loopsById[id];
|
|
53
|
+
if (loop) selected.push(loop);
|
|
54
|
+
}
|
|
55
|
+
return uniqueById(selected);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function selectMonitors(goal: GoalEntry, monitorState: MonitorReducerState): MonitorEntry[] {
|
|
59
|
+
const selected: MonitorEntry[] = [];
|
|
60
|
+
for (const id of goal.scope.monitorIds ?? []) {
|
|
61
|
+
const monitor = monitorState.monitorsById[id];
|
|
62
|
+
if (monitor) selected.push(monitor);
|
|
63
|
+
}
|
|
64
|
+
return uniqueById(selected);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function projectGoalProgress(
|
|
68
|
+
goal: GoalEntry,
|
|
69
|
+
taskState: TaskReducerState,
|
|
70
|
+
loopState: LoopReducerState,
|
|
71
|
+
monitorState: MonitorReducerState,
|
|
72
|
+
): GoalProgressSnapshot {
|
|
73
|
+
const tasks = selectTasks(goal, taskState);
|
|
74
|
+
const loops = selectLoops(goal, loopState);
|
|
75
|
+
const monitors = selectMonitors(goal, monitorState);
|
|
76
|
+
|
|
77
|
+
const timestamps: number[] = [];
|
|
78
|
+
for (const task of tasks) timestamps.push(task.updatedAt);
|
|
79
|
+
for (const loop of loops) timestamps.push(loop.updatedAt);
|
|
80
|
+
for (const monitor of monitors) timestamps.push(monitor.completedAt ?? monitor.startedAt);
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
totalTasks: tasks.length,
|
|
84
|
+
pendingTasks: tasks.filter(task => task.status === "pending").length,
|
|
85
|
+
inProgressTasks: tasks.filter(task => task.status === "in_progress").length,
|
|
86
|
+
completedTasks: tasks.filter(task => task.status === "completed").length,
|
|
87
|
+
activeLoops: loops.filter(loop => loop.status === "active").length,
|
|
88
|
+
pausedLoops: loops.filter(loop => loop.status === "paused").length,
|
|
89
|
+
runningMonitors: monitors.filter(monitor => monitor.status === "running").length,
|
|
90
|
+
completedMonitors: monitors.filter(monitor => monitor.status === "completed").length,
|
|
91
|
+
erroredMonitors: monitors.filter(monitor => monitor.status === "error").length,
|
|
92
|
+
stoppedMonitors: monitors.filter(monitor => monitor.status === "stopped").length,
|
|
93
|
+
lastProgressAt: timestamps.length > 0 ? Math.max(...timestamps) : undefined,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function dispatchEffect(event: ReducerEvent): ReducerEffect<"DISPATCH_EVENT", { event: ReducerEvent }> {
|
|
98
|
+
return {
|
|
99
|
+
type: "DISPATCH_EVENT",
|
|
100
|
+
entityType: "goal",
|
|
101
|
+
entityId: event.entityId,
|
|
102
|
+
payload: { event },
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function buildEffects(goal: GoalEntry, at: number, progress: GoalProgressSnapshot, resultType: string, reason: string) {
|
|
107
|
+
return [
|
|
108
|
+
dispatchEffect({
|
|
109
|
+
type: "GOAL_VERIFICATION_STARTED",
|
|
110
|
+
at,
|
|
111
|
+
source: "coordinator",
|
|
112
|
+
entityType: "goal",
|
|
113
|
+
entityId: goal.id,
|
|
114
|
+
payload: { id: goal.id },
|
|
115
|
+
}),
|
|
116
|
+
dispatchEffect({
|
|
117
|
+
type: "GOAL_PROGRESS_RECORDED",
|
|
118
|
+
at,
|
|
119
|
+
source: "coordinator",
|
|
120
|
+
entityType: "goal",
|
|
121
|
+
entityId: goal.id,
|
|
122
|
+
payload: { id: goal.id, progress },
|
|
123
|
+
}),
|
|
124
|
+
dispatchEffect({
|
|
125
|
+
type: resultType,
|
|
126
|
+
at,
|
|
127
|
+
source: "coordinator",
|
|
128
|
+
entityType: "goal",
|
|
129
|
+
entityId: goal.id,
|
|
130
|
+
payload: { id: goal.id, reason, progress },
|
|
131
|
+
}),
|
|
132
|
+
];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function verifyGoal(input: GoalVerifierInput): GoalVerifierResult {
|
|
136
|
+
const { goal, taskState, loopState, monitorState, at } = input;
|
|
137
|
+
const progress = projectGoalProgress(goal, taskState, loopState, monitorState);
|
|
138
|
+
|
|
139
|
+
if (goal.criteria.failure?.maxVerificationFailures !== undefined
|
|
140
|
+
&& goal.verification.failures >= goal.criteria.failure.maxVerificationFailures) {
|
|
141
|
+
return {
|
|
142
|
+
progress,
|
|
143
|
+
verdict: "failed",
|
|
144
|
+
reason: "maximum verification failures reached",
|
|
145
|
+
effects: buildEffects(goal, at, progress, "GOAL_FAILED", "maximum verification failures reached"),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
for (const monitorId of goal.criteria.failure?.anyMonitorIdsErrored ?? []) {
|
|
150
|
+
if (monitorState.monitorsById[monitorId]?.status === "error") {
|
|
151
|
+
return {
|
|
152
|
+
progress,
|
|
153
|
+
verdict: "failed",
|
|
154
|
+
reason: `monitor #${monitorId} errored`,
|
|
155
|
+
effects: buildEffects(goal, at, progress, "GOAL_FAILED", `monitor #${monitorId} errored`),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
for (const taskId of goal.criteria.failure?.failIfTaskIdsDeleted ?? []) {
|
|
161
|
+
if (!taskState.tasksById[taskId]) {
|
|
162
|
+
return {
|
|
163
|
+
progress,
|
|
164
|
+
verdict: "failed",
|
|
165
|
+
reason: `task #${taskId} missing`,
|
|
166
|
+
effects: buildEffects(goal, at, progress, "GOAL_FAILED", `task #${taskId} missing`),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const requiredTasksDone = (goal.criteria.success.requiredTaskIds ?? [])
|
|
172
|
+
.every(taskId => taskState.tasksById[taskId]?.status === "completed");
|
|
173
|
+
const requiredMonitorsDone = (goal.criteria.success.requiredMonitorIdsCompleted ?? [])
|
|
174
|
+
.every(monitorId => monitorState.monitorsById[monitorId]?.status === "completed");
|
|
175
|
+
const requiredLoopsPresent = (goal.criteria.success.requiredLoopIdsPresent ?? [])
|
|
176
|
+
.every(loopId => Boolean(loopState.loopsById[loopId]));
|
|
177
|
+
const minCompletedTasksMet = progress.completedTasks >= (goal.criteria.success.minCompletedTasks ?? 0);
|
|
178
|
+
const noPendingWork = !goal.criteria.success.requireNoPendingTasksInScope
|
|
179
|
+
|| (progress.pendingTasks === 0 && progress.inProgressTasks === 0);
|
|
180
|
+
const latestVerificationPass = !goal.criteria.success.requireLatestVerificationPass
|
|
181
|
+
|| goal.verificationStatus === "verified";
|
|
182
|
+
|
|
183
|
+
const success = requiredTasksDone
|
|
184
|
+
&& requiredMonitorsDone
|
|
185
|
+
&& requiredLoopsPresent
|
|
186
|
+
&& minCompletedTasksMet
|
|
187
|
+
&& noPendingWork
|
|
188
|
+
&& latestVerificationPass;
|
|
189
|
+
|
|
190
|
+
if (success) {
|
|
191
|
+
return {
|
|
192
|
+
progress,
|
|
193
|
+
verdict: "passed",
|
|
194
|
+
reason: "success criteria satisfied",
|
|
195
|
+
effects: buildEffects(goal, at, progress, "GOAL_VERIFICATION_PASSED", "success criteria satisfied"),
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (goal.criteria.blocked?.blockedIfRequiredLoopMissing && !requiredLoopsPresent) {
|
|
200
|
+
return {
|
|
201
|
+
progress,
|
|
202
|
+
verdict: "blocked",
|
|
203
|
+
reason: "required loop missing",
|
|
204
|
+
effects: buildEffects(goal, at, progress, "GOAL_BLOCKED", "required loop missing"),
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (
|
|
209
|
+
goal.criteria.blocked?.blockedIfNoScopedProgressSinceMs !== undefined
|
|
210
|
+
&& progress.lastProgressAt !== undefined
|
|
211
|
+
&& at - progress.lastProgressAt >= goal.criteria.blocked.blockedIfNoScopedProgressSinceMs
|
|
212
|
+
) {
|
|
213
|
+
return {
|
|
214
|
+
progress,
|
|
215
|
+
verdict: "blocked",
|
|
216
|
+
reason: "no scoped progress within configured interval",
|
|
217
|
+
effects: buildEffects(goal, at, progress, "GOAL_BLOCKED", "no scoped progress within configured interval"),
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (
|
|
222
|
+
goal.criteria.blocked?.blockedIfAllTasksCompletedButVerificationFails
|
|
223
|
+
&& progress.totalTasks > 0
|
|
224
|
+
&& progress.pendingTasks === 0
|
|
225
|
+
&& progress.inProgressTasks === 0
|
|
226
|
+
) {
|
|
227
|
+
return {
|
|
228
|
+
progress,
|
|
229
|
+
verdict: "blocked",
|
|
230
|
+
reason: "all scoped tasks completed but verification has not passed",
|
|
231
|
+
effects: buildEffects(goal, at, progress, "GOAL_BLOCKED", "all scoped tasks completed but verification has not passed"),
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return {
|
|
236
|
+
progress,
|
|
237
|
+
verdict: "failed",
|
|
238
|
+
reason: "success criteria not yet satisfied",
|
|
239
|
+
effects: buildEffects(goal, at, progress, "GOAL_VERIFICATION_FAILED", "success criteria not yet satisfied"),
|
|
240
|
+
};
|
|
241
|
+
}
|