jfl 0.7.1 → 0.8.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/dist/commands/context-hub.d.ts.map +1 -1
- package/dist/commands/context-hub.js +26 -0
- package/dist/commands/context-hub.js.map +1 -1
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +37 -3
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/migrate-tenet.d.ts +25 -0
- package/dist/commands/migrate-tenet.d.ts.map +1 -0
- package/dist/commands/migrate-tenet.js +252 -0
- package/dist/commands/migrate-tenet.js.map +1 -0
- package/dist/commands/peter.d.ts.map +1 -1
- package/dist/commands/peter.js +47 -5
- package/dist/commands/peter.js.map +1 -1
- package/dist/commands/pi.d.ts +1 -0
- package/dist/commands/pi.d.ts.map +1 -1
- package/dist/commands/pi.js +5 -1
- package/dist/commands/pi.js.map +1 -1
- package/dist/commands/pivot.d.ts +28 -0
- package/dist/commands/pivot.d.ts.map +1 -0
- package/dist/commands/pivot.js +219 -0
- package/dist/commands/pivot.js.map +1 -0
- package/dist/commands/services-create.js +348 -0
- package/dist/commands/services-create.js.map +1 -1
- package/dist/dashboard-static/assets/index-BVrmW-ZI.js +154 -0
- package/dist/dashboard-static/assets/{index-CW8oWAdr.css → index-DtruPD44.css} +1 -1
- package/dist/dashboard-static/index.html +2 -2
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/agent-generator.d.ts.map +1 -1
- package/dist/lib/agent-generator.js +15 -0
- package/dist/lib/agent-generator.js.map +1 -1
- package/dist/lib/counterfactual-engine.d.ts +136 -0
- package/dist/lib/counterfactual-engine.d.ts.map +1 -0
- package/dist/lib/counterfactual-engine.js +417 -0
- package/dist/lib/counterfactual-engine.js.map +1 -0
- package/dist/lib/dynamics-model.d.ts +107 -0
- package/dist/lib/dynamics-model.d.ts.map +1 -0
- package/dist/lib/dynamics-model.js +363 -0
- package/dist/lib/dynamics-model.js.map +1 -0
- package/dist/lib/eval-snapshot.d.ts.map +1 -1
- package/dist/lib/eval-snapshot.js +15 -4
- package/dist/lib/eval-snapshot.js.map +1 -1
- package/dist/lib/invariant-monitor.d.ts +50 -0
- package/dist/lib/invariant-monitor.d.ts.map +1 -0
- package/dist/lib/invariant-monitor.js +400 -0
- package/dist/lib/invariant-monitor.js.map +1 -0
- package/dist/lib/meta-orchestrator.d.ts +40 -3
- package/dist/lib/meta-orchestrator.d.ts.map +1 -1
- package/dist/lib/meta-orchestrator.js +181 -2
- package/dist/lib/meta-orchestrator.js.map +1 -1
- package/dist/lib/openclaw-sdk.d.ts +8 -0
- package/dist/lib/openclaw-sdk.d.ts.map +1 -1
- package/dist/lib/openclaw-sdk.js +11 -0
- package/dist/lib/openclaw-sdk.js.map +1 -1
- package/dist/lib/peter-parker-bridge.d.ts +37 -1
- package/dist/lib/peter-parker-bridge.d.ts.map +1 -1
- package/dist/lib/peter-parker-bridge.js +201 -1
- package/dist/lib/peter-parker-bridge.js.map +1 -1
- package/dist/lib/service-detector.d.ts +1 -1
- package/dist/lib/service-detector.d.ts.map +1 -1
- package/dist/lib/service-detector.js +26 -6
- package/dist/lib/service-detector.js.map +1 -1
- package/dist/lib/service-gtm.d.ts +1 -1
- package/dist/lib/service-gtm.d.ts.map +1 -1
- package/dist/lib/state-capture.d.ts +36 -0
- package/dist/lib/state-capture.d.ts.map +1 -0
- package/dist/lib/state-capture.js +541 -0
- package/dist/lib/state-capture.js.map +1 -0
- package/dist/lib/stratus-client.d.ts +78 -2
- package/dist/lib/stratus-client.d.ts.map +1 -1
- package/dist/lib/stratus-client.js +432 -1
- package/dist/lib/stratus-client.js.map +1 -1
- package/dist/lib/world-model-store.d.ts +172 -0
- package/dist/lib/world-model-store.d.ts.map +1 -0
- package/dist/lib/world-model-store.js +487 -0
- package/dist/lib/world-model-store.js.map +1 -0
- package/dist/types/world-model.d.ts +478 -0
- package/dist/types/world-model.d.ts.map +1 -0
- package/dist/types/world-model.js +80 -0
- package/dist/types/world-model.js.map +1 -0
- package/dist/utils/jfl-config.d.ts +5 -0
- package/dist/utils/jfl-config.d.ts.map +1 -1
- package/dist/utils/jfl-config.js +13 -1
- package/dist/utils/jfl-config.js.map +1 -1
- package/package.json +1 -1
- package/packages/pi/extensions/hud-tool.ts +2 -24
- package/packages/pi/extensions/index.ts +48 -25
- package/packages/pi/extensions/onboarding-v1.ts +455 -0
- package/packages/pi/extensions/onboarding-v2.ts +516 -0
- package/packages/pi/extensions/onboarding-v3.ts +675 -0
- package/packages/pi/extensions/pivot-tool.ts +59 -0
- package/packages/pi/extensions/session.ts +58 -0
- package/packages/pi/extensions/types.ts +2 -0
- package/packages/pi/skills/pivot/SKILL.md +91 -0
- package/template/.claude/settings.json +9 -0
- package/dist/dashboard-static/assets/index-Ck8f9dcM.js +0 -121
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Invariant Monitor
|
|
3
|
+
*
|
|
4
|
+
* Runtime TLA+ invariant checks translated to TypeScript.
|
|
5
|
+
* Checks system state against invariants defined in:
|
|
6
|
+
* - PeterParker.tla (agent orchestration invariants)
|
|
7
|
+
* - JFLSystem.tla (system-level cross-service invariants)
|
|
8
|
+
*
|
|
9
|
+
* Each invariant check returns violations with severity and suggested recovery.
|
|
10
|
+
*
|
|
11
|
+
* @purpose Runtime TLA+ invariant checking for world model safety
|
|
12
|
+
* @spec tla/PeterParker.tla, tla/JFLSystem.tla
|
|
13
|
+
*/
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// Invariant Implementations
|
|
16
|
+
// ============================================================================
|
|
17
|
+
/**
|
|
18
|
+
* NoAgentStranding: No agent can be stuck in an active state with hub down
|
|
19
|
+
* From PeterParker.tla: agentStatus[a] ∈ {"eval", "research", "commit"} ∧ hubStatus = "down"
|
|
20
|
+
*/
|
|
21
|
+
function checkNoAgentStranding(state) {
|
|
22
|
+
const hubDown = state.systemState.hubConnections === 0;
|
|
23
|
+
if (!hubDown)
|
|
24
|
+
return null;
|
|
25
|
+
// Check if any agent is in an active state
|
|
26
|
+
const worktreeAllocations = Object.entries(state.systemState.worktreeAllocation);
|
|
27
|
+
const activeAgents = worktreeAllocations.filter(([, path]) => path !== "none");
|
|
28
|
+
if (activeAgents.length === 0)
|
|
29
|
+
return null;
|
|
30
|
+
return {
|
|
31
|
+
description: `${activeAgents.length} agent(s) stranded with hub down: ${activeAgents.map(([a]) => a).join(", ")}`,
|
|
32
|
+
violatingState: {
|
|
33
|
+
systemState: {
|
|
34
|
+
activeAgents: activeAgents.map(([a]) => a),
|
|
35
|
+
hubConnections: 0,
|
|
36
|
+
worktreeAllocation: state.systemState.worktreeAllocation,
|
|
37
|
+
buildStatus: state.systemState.buildStatus,
|
|
38
|
+
fileLocks: state.systemState.fileLocks,
|
|
39
|
+
pendingEvals: state.systemState.pendingEvals,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
suggestedRecovery: "Release agent worktrees and return agents to idle state",
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* HumanAgentIsolation: No agent can run on a repo while human is editing it
|
|
47
|
+
* From JFLSystem.tla: humanEditing ⇒ ∀a: agentRepo[a] = humanEditRepo ⇒ agentStatus[a] ∉ {"running", "eval"}
|
|
48
|
+
*/
|
|
49
|
+
function checkHumanAgentIsolation(state) {
|
|
50
|
+
if (!state.contextState.humanActivity)
|
|
51
|
+
return null;
|
|
52
|
+
// If human is active, check if any agent has a worktree allocated
|
|
53
|
+
const worktreeAllocations = Object.entries(state.systemState.worktreeAllocation);
|
|
54
|
+
const activeAgents = worktreeAllocations.filter(([, path]) => path !== "none");
|
|
55
|
+
if (activeAgents.length === 0)
|
|
56
|
+
return null;
|
|
57
|
+
return {
|
|
58
|
+
description: `Agent(s) ${activeAgents.map(([a]) => a).join(", ")} running while human is editing`,
|
|
59
|
+
violatingState: {
|
|
60
|
+
contextState: {
|
|
61
|
+
humanActivity: true,
|
|
62
|
+
recentCommits: state.contextState.recentCommits,
|
|
63
|
+
openPRs: state.contextState.openPRs,
|
|
64
|
+
failingTests: state.contextState.failingTests,
|
|
65
|
+
codeChurn: state.contextState.codeChurn,
|
|
66
|
+
},
|
|
67
|
+
systemState: {
|
|
68
|
+
activeAgents: state.systemState.activeAgents,
|
|
69
|
+
worktreeAllocation: state.systemState.worktreeAllocation,
|
|
70
|
+
hubConnections: state.systemState.hubConnections,
|
|
71
|
+
buildStatus: state.systemState.buildStatus,
|
|
72
|
+
fileLocks: state.systemState.fileLocks,
|
|
73
|
+
pendingEvals: state.systemState.pendingEvals,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
suggestedRecovery: "Pause agent execution until human stops editing",
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* HubAvailability: Hub must be responsive for critical operations
|
|
81
|
+
* Note: This is a liveness check, not just state
|
|
82
|
+
*/
|
|
83
|
+
function checkHubAvailability(state) {
|
|
84
|
+
// Hub is considered available if connections > 0
|
|
85
|
+
if (state.systemState.hubConnections > 0)
|
|
86
|
+
return null;
|
|
87
|
+
// Check if there's pending work that needs hub
|
|
88
|
+
const hasPendingEvals = state.systemState.pendingEvals > 0;
|
|
89
|
+
const hasActiveAgents = state.systemState.activeAgents.length > 0;
|
|
90
|
+
if (!hasPendingEvals && !hasActiveAgents)
|
|
91
|
+
return null;
|
|
92
|
+
return {
|
|
93
|
+
description: `Hub unavailable with ${state.systemState.pendingEvals} pending evals and ${state.systemState.activeAgents.length} active agents`,
|
|
94
|
+
violatingState: {
|
|
95
|
+
systemState: {
|
|
96
|
+
hubConnections: 0,
|
|
97
|
+
pendingEvals: state.systemState.pendingEvals,
|
|
98
|
+
activeAgents: state.systemState.activeAgents,
|
|
99
|
+
worktreeAllocation: state.systemState.worktreeAllocation,
|
|
100
|
+
buildStatus: state.systemState.buildStatus,
|
|
101
|
+
fileLocks: state.systemState.fileLocks,
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
suggestedRecovery: "Restart hub with: jfl hub start",
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* WorktreeExclusivity: No two agents can share the same worktree
|
|
109
|
+
* From PeterParker.tla: ScopeIsolation invariant
|
|
110
|
+
*/
|
|
111
|
+
function checkWorktreeExclusivity(state) {
|
|
112
|
+
const allocations = state.systemState.worktreeAllocation;
|
|
113
|
+
const pathCounts = {};
|
|
114
|
+
for (const [agent, path] of Object.entries(allocations)) {
|
|
115
|
+
if (path === "none")
|
|
116
|
+
continue;
|
|
117
|
+
if (!pathCounts[path])
|
|
118
|
+
pathCounts[path] = [];
|
|
119
|
+
pathCounts[path].push(agent);
|
|
120
|
+
}
|
|
121
|
+
const conflicts = Object.entries(pathCounts).filter(([, agents]) => agents.length > 1);
|
|
122
|
+
if (conflicts.length === 0)
|
|
123
|
+
return null;
|
|
124
|
+
const conflictDesc = conflicts
|
|
125
|
+
.map(([path, agents]) => `${path}: ${agents.join(", ")}`)
|
|
126
|
+
.join("; ");
|
|
127
|
+
return {
|
|
128
|
+
description: `Worktree conflict(s): ${conflictDesc}`,
|
|
129
|
+
violatingState: {
|
|
130
|
+
systemState: {
|
|
131
|
+
worktreeAllocation: allocations,
|
|
132
|
+
activeAgents: state.systemState.activeAgents,
|
|
133
|
+
hubConnections: state.systemState.hubConnections,
|
|
134
|
+
buildStatus: state.systemState.buildStatus,
|
|
135
|
+
fileLocks: state.systemState.fileLocks,
|
|
136
|
+
pendingEvals: state.systemState.pendingEvals,
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
suggestedRecovery: "Release duplicate worktree allocations for conflicting agents",
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* TrainingBufferBounded: Training buffer must stay within size limits
|
|
144
|
+
* From PeterParker.tla: Len(trainingBuffer) < MaxBufferLen
|
|
145
|
+
*/
|
|
146
|
+
function checkTrainingBufferBounded(state) {
|
|
147
|
+
const MAX_BUFFER_SIZE = 50000; // Same as world-model-store default
|
|
148
|
+
// This check would need access to training buffer size
|
|
149
|
+
// For now, check if pending evals exceed a reasonable threshold
|
|
150
|
+
const MAX_PENDING = 100;
|
|
151
|
+
if (state.systemState.pendingEvals <= MAX_PENDING)
|
|
152
|
+
return null;
|
|
153
|
+
return {
|
|
154
|
+
description: `Pending evals (${state.systemState.pendingEvals}) exceeds limit (${MAX_PENDING})`,
|
|
155
|
+
violatingState: {
|
|
156
|
+
systemState: {
|
|
157
|
+
pendingEvals: state.systemState.pendingEvals,
|
|
158
|
+
activeAgents: state.systemState.activeAgents,
|
|
159
|
+
hubConnections: state.systemState.hubConnections,
|
|
160
|
+
worktreeAllocation: state.systemState.worktreeAllocation,
|
|
161
|
+
buildStatus: state.systemState.buildStatus,
|
|
162
|
+
fileLocks: state.systemState.fileLocks,
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
suggestedRecovery: "Clear eval queue or increase processing capacity",
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* ScopeIsolation: No overlapping file locks between agents
|
|
170
|
+
* From PeterParker.tla: fileLocks consistency
|
|
171
|
+
*/
|
|
172
|
+
function checkScopeIsolation(state) {
|
|
173
|
+
const locks = state.systemState.fileLocks;
|
|
174
|
+
// Check for duplicate locks
|
|
175
|
+
const uniqueLocks = new Set(locks);
|
|
176
|
+
if (uniqueLocks.size === locks.length)
|
|
177
|
+
return null;
|
|
178
|
+
const duplicates = locks.filter((lock, i) => locks.indexOf(lock) !== i);
|
|
179
|
+
return {
|
|
180
|
+
description: `Duplicate file locks detected: ${duplicates.join(", ")}`,
|
|
181
|
+
violatingState: {
|
|
182
|
+
systemState: {
|
|
183
|
+
fileLocks: locks,
|
|
184
|
+
activeAgents: state.systemState.activeAgents,
|
|
185
|
+
hubConnections: state.systemState.hubConnections,
|
|
186
|
+
worktreeAllocation: state.systemState.worktreeAllocation,
|
|
187
|
+
buildStatus: state.systemState.buildStatus,
|
|
188
|
+
pendingEvals: state.systemState.pendingEvals,
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
suggestedRecovery: "Release duplicate locks, ensure atomic lock acquisition",
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* LockRequired: Running agents must hold appropriate locks
|
|
196
|
+
* From JFLSystem.tla: agentStatus[a] ∈ {"running", "eval"} ⇒ a ∈ repoLocks[agentRepo[a]]
|
|
197
|
+
*/
|
|
198
|
+
function checkLockRequired(state) {
|
|
199
|
+
const activeAgents = Object.entries(state.systemState.worktreeAllocation)
|
|
200
|
+
.filter(([, path]) => path !== "none")
|
|
201
|
+
.map(([agent]) => agent);
|
|
202
|
+
if (activeAgents.length === 0)
|
|
203
|
+
return null;
|
|
204
|
+
// For this check, we'd need to correlate agents with their expected locks
|
|
205
|
+
// For now, we verify that if there are active agents, there are locks
|
|
206
|
+
if (state.systemState.fileLocks.length > 0)
|
|
207
|
+
return null;
|
|
208
|
+
return {
|
|
209
|
+
description: `Active agents (${activeAgents.join(", ")}) running without file locks`,
|
|
210
|
+
violatingState: {
|
|
211
|
+
systemState: {
|
|
212
|
+
activeAgents,
|
|
213
|
+
fileLocks: [],
|
|
214
|
+
hubConnections: state.systemState.hubConnections,
|
|
215
|
+
worktreeAllocation: state.systemState.worktreeAllocation,
|
|
216
|
+
buildStatus: state.systemState.buildStatus,
|
|
217
|
+
pendingEvals: state.systemState.pendingEvals,
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
suggestedRecovery: "Acquire appropriate file locks before agent execution",
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* EvalBeforeCommit: Eval must complete before commit
|
|
225
|
+
* This is checked during transition validation, not state
|
|
226
|
+
*/
|
|
227
|
+
function checkEvalBeforeCommit(_state) {
|
|
228
|
+
// This invariant is checked during transition recording, not state checking
|
|
229
|
+
// It ensures the sequence: scheduled → worktree → eval → research → commit
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
// ============================================================================
|
|
233
|
+
// Invariant Registry
|
|
234
|
+
// ============================================================================
|
|
235
|
+
const INVARIANTS = [
|
|
236
|
+
{
|
|
237
|
+
id: "NoAgentStranding",
|
|
238
|
+
name: "No Agent Stranding",
|
|
239
|
+
description: "No agent can be stuck in an active state with hub down",
|
|
240
|
+
severity: "critical",
|
|
241
|
+
source: "PeterParker.tla",
|
|
242
|
+
check: checkNoAgentStranding,
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
id: "HumanAgentIsolation",
|
|
246
|
+
name: "Human-Agent Isolation",
|
|
247
|
+
description: "No agent can run on a repo while human is editing it",
|
|
248
|
+
severity: "warning",
|
|
249
|
+
source: "JFLSystem.tla",
|
|
250
|
+
check: checkHumanAgentIsolation,
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
id: "HubAvailability",
|
|
254
|
+
name: "Hub Availability",
|
|
255
|
+
description: "Hub must be responsive for critical operations",
|
|
256
|
+
severity: "error",
|
|
257
|
+
source: "JFLSystem.tla",
|
|
258
|
+
check: checkHubAvailability,
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
id: "WorktreeExclusivity",
|
|
262
|
+
name: "Worktree Exclusivity",
|
|
263
|
+
description: "No two agents can share the same worktree",
|
|
264
|
+
severity: "critical",
|
|
265
|
+
source: "PeterParker.tla",
|
|
266
|
+
check: checkWorktreeExclusivity,
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
id: "TrainingBufferBounded",
|
|
270
|
+
name: "Training Buffer Bounded",
|
|
271
|
+
description: "Training buffer must stay within size limits",
|
|
272
|
+
severity: "warning",
|
|
273
|
+
source: "PeterParker.tla",
|
|
274
|
+
check: checkTrainingBufferBounded,
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
id: "ScopeIsolation",
|
|
278
|
+
name: "Scope Isolation",
|
|
279
|
+
description: "No overlapping file locks between agents",
|
|
280
|
+
severity: "error",
|
|
281
|
+
source: "PeterParker.tla",
|
|
282
|
+
check: checkScopeIsolation,
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
id: "LockRequired",
|
|
286
|
+
name: "Lock Required",
|
|
287
|
+
description: "Running agents must hold appropriate locks",
|
|
288
|
+
severity: "warning",
|
|
289
|
+
source: "JFLSystem.tla",
|
|
290
|
+
check: checkLockRequired,
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
id: "EvalBeforeCommit",
|
|
294
|
+
name: "Eval Before Commit",
|
|
295
|
+
description: "Eval must complete before commit",
|
|
296
|
+
severity: "error",
|
|
297
|
+
source: "PeterParker.tla",
|
|
298
|
+
check: checkEvalBeforeCommit,
|
|
299
|
+
},
|
|
300
|
+
];
|
|
301
|
+
// ============================================================================
|
|
302
|
+
// Public API
|
|
303
|
+
// ============================================================================
|
|
304
|
+
/**
|
|
305
|
+
* Check all invariants against the given state
|
|
306
|
+
* @param state - The WorldState to check
|
|
307
|
+
* @returns Array of any violations found
|
|
308
|
+
*/
|
|
309
|
+
export function checkInvariants(state) {
|
|
310
|
+
const violations = [];
|
|
311
|
+
for (const invariant of INVARIANTS) {
|
|
312
|
+
const result = invariant.check(state);
|
|
313
|
+
if (result) {
|
|
314
|
+
violations.push({
|
|
315
|
+
invariantId: invariant.id,
|
|
316
|
+
severity: invariant.severity,
|
|
317
|
+
description: result.description,
|
|
318
|
+
violatingState: result.violatingState,
|
|
319
|
+
suggestedRecovery: result.suggestedRecovery,
|
|
320
|
+
detectedAt: Date.now(),
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return violations;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Check a specific invariant
|
|
328
|
+
* @param invariantId - Which invariant to check
|
|
329
|
+
* @param state - The WorldState to check
|
|
330
|
+
* @returns Violation if found, null otherwise
|
|
331
|
+
*/
|
|
332
|
+
export function checkInvariant(invariantId, state) {
|
|
333
|
+
const invariant = INVARIANTS.find(i => i.id === invariantId);
|
|
334
|
+
if (!invariant) {
|
|
335
|
+
throw new Error(`Unknown invariant: ${invariantId}`);
|
|
336
|
+
}
|
|
337
|
+
const result = invariant.check(state);
|
|
338
|
+
if (!result)
|
|
339
|
+
return null;
|
|
340
|
+
return {
|
|
341
|
+
invariantId: invariant.id,
|
|
342
|
+
severity: invariant.severity,
|
|
343
|
+
description: result.description,
|
|
344
|
+
violatingState: result.violatingState,
|
|
345
|
+
suggestedRecovery: result.suggestedRecovery,
|
|
346
|
+
detectedAt: Date.now(),
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Get all invariant definitions (for documentation/introspection)
|
|
351
|
+
*/
|
|
352
|
+
export function getInvariantDefinitions() {
|
|
353
|
+
return INVARIANTS.map(i => ({
|
|
354
|
+
id: i.id,
|
|
355
|
+
name: i.name,
|
|
356
|
+
description: i.description,
|
|
357
|
+
severity: i.severity,
|
|
358
|
+
source: i.source,
|
|
359
|
+
}));
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Check if state has any critical violations
|
|
363
|
+
*/
|
|
364
|
+
export function hasCriticalViolations(state) {
|
|
365
|
+
const violations = checkInvariants(state);
|
|
366
|
+
return violations.some(v => v.severity === "critical");
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Get a summary of all violations
|
|
370
|
+
*/
|
|
371
|
+
export function getViolationSummary(violations) {
|
|
372
|
+
if (violations.length === 0) {
|
|
373
|
+
return "All invariants satisfied";
|
|
374
|
+
}
|
|
375
|
+
const bySeverity = {
|
|
376
|
+
critical: violations.filter(v => v.severity === "critical"),
|
|
377
|
+
error: violations.filter(v => v.severity === "error"),
|
|
378
|
+
warning: violations.filter(v => v.severity === "warning"),
|
|
379
|
+
};
|
|
380
|
+
const parts = [];
|
|
381
|
+
if (bySeverity.critical.length > 0) {
|
|
382
|
+
parts.push(`CRITICAL: ${bySeverity.critical.map(v => v.invariantId).join(", ")}`);
|
|
383
|
+
}
|
|
384
|
+
if (bySeverity.error.length > 0) {
|
|
385
|
+
parts.push(`ERROR: ${bySeverity.error.map(v => v.invariantId).join(", ")}`);
|
|
386
|
+
}
|
|
387
|
+
if (bySeverity.warning.length > 0) {
|
|
388
|
+
parts.push(`WARNING: ${bySeverity.warning.map(v => v.invariantId).join(", ")}`);
|
|
389
|
+
}
|
|
390
|
+
return parts.join("; ");
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Suggest recovery actions for all violations
|
|
394
|
+
*/
|
|
395
|
+
export function suggestRecoveryActions(violations) {
|
|
396
|
+
return violations
|
|
397
|
+
.filter(v => v.suggestedRecovery)
|
|
398
|
+
.map(v => `[${v.invariantId}] ${v.suggestedRecovery}`);
|
|
399
|
+
}
|
|
400
|
+
//# sourceMappingURL=invariant-monitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invariant-monitor.js","sourceRoot":"","sources":["../../src/lib/invariant-monitor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAkCH,+EAA+E;AAC/E,4BAA4B;AAC5B,+EAA+E;AAE/E;;;GAGG;AACH,SAAS,qBAAqB,CAAC,KAAiB;IAC9C,MAAM,OAAO,GAAG,KAAK,CAAC,WAAW,CAAC,cAAc,KAAK,CAAC,CAAA;IAEtD,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAA;IAEzB,2CAA2C;IAC3C,MAAM,mBAAmB,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAA;IAChF,MAAM,YAAY,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,MAAM,CAAC,CAAA;IAE9E,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IAE1C,OAAO;QACL,WAAW,EAAE,GAAG,YAAY,CAAC,MAA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IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACjF,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACzB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,UAAgC;IACrE,OAAO,UAAU;SACd,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,iBAAiB,CAAC;SAChC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,WAAW,KAAK,CAAC,CAAC,iBAAiB,EAAE,CAAC,CAAA;AAC1D,CAAC"}
|
|
@@ -2,14 +2,17 @@
|
|
|
2
2
|
* Meta Orchestrator
|
|
3
3
|
*
|
|
4
4
|
* Simple scheduler for running multiple scoped agents.
|
|
5
|
-
*
|
|
5
|
+
* Now integrated with World Model for predictive scheduling.
|
|
6
|
+
* Decides which agent to run next based on:
|
|
6
7
|
* - Round-robin baseline
|
|
7
8
|
* - Prioritize recently improving agents
|
|
8
9
|
* - 30% exploration (random selection)
|
|
10
|
+
* - World model predictions for expected outcome
|
|
9
11
|
*
|
|
10
|
-
* @purpose Schedule and coordinate multiple scoped RL agents
|
|
12
|
+
* @purpose Schedule and coordinate multiple scoped RL agents with world model integration
|
|
11
13
|
*/
|
|
12
14
|
import { type AgentConfig } from "./agent-config.js";
|
|
15
|
+
import type { WorldState, PredictionResult } from "../types/world-model.js";
|
|
13
16
|
export interface AgentPerformance {
|
|
14
17
|
agentName: string;
|
|
15
18
|
emaReward: number;
|
|
@@ -27,15 +30,19 @@ export interface OrchestratorState {
|
|
|
27
30
|
}
|
|
28
31
|
export interface ScheduleDecision {
|
|
29
32
|
agent: AgentConfig;
|
|
30
|
-
reason: "round_robin" | "prioritized" | "exploration" | "scope_impact";
|
|
33
|
+
reason: "round_robin" | "prioritized" | "exploration" | "scope_impact" | "world_model";
|
|
31
34
|
emaReward?: number;
|
|
32
35
|
impactPattern?: string;
|
|
36
|
+
prediction?: PredictionResult;
|
|
33
37
|
}
|
|
34
38
|
export declare class MetaOrchestrator {
|
|
35
39
|
private projectRoot;
|
|
36
40
|
private statePath;
|
|
37
41
|
private state;
|
|
38
42
|
private replayBuffer;
|
|
43
|
+
private dynamicsModel;
|
|
44
|
+
private worldModelStore;
|
|
45
|
+
private lastCapturedState;
|
|
39
46
|
constructor(projectRoot: string);
|
|
40
47
|
private loadState;
|
|
41
48
|
private saveState;
|
|
@@ -55,6 +62,36 @@ export declare class MetaOrchestrator {
|
|
|
55
62
|
impactPattern: string;
|
|
56
63
|
}>;
|
|
57
64
|
scheduleNext(): ScheduleDecision | null;
|
|
65
|
+
/**
|
|
66
|
+
* Schedule with world model predictions
|
|
67
|
+
* Uses dynamics model to predict outcomes and pick best agent
|
|
68
|
+
*/
|
|
69
|
+
scheduleNextWithPredictions(): Promise<ScheduleDecision | null>;
|
|
70
|
+
/**
|
|
71
|
+
* Record a state transition after an agent completes
|
|
72
|
+
* This builds the world model's training data
|
|
73
|
+
*/
|
|
74
|
+
recordTransition(agentName: string, reward: number, priorState?: WorldState): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Get world model statistics
|
|
77
|
+
*/
|
|
78
|
+
getWorldModelStats(): {
|
|
79
|
+
dynamicsModel: {
|
|
80
|
+
totalTransitions: number;
|
|
81
|
+
cachedPredictions: number;
|
|
82
|
+
avgConfidence?: number;
|
|
83
|
+
sourceDistribution: Record<string, number>;
|
|
84
|
+
};
|
|
85
|
+
store: {
|
|
86
|
+
transitionCount: number;
|
|
87
|
+
snapshotCount: number;
|
|
88
|
+
cachedPredictions: number;
|
|
89
|
+
violationCount: number;
|
|
90
|
+
counterfactualCount: number;
|
|
91
|
+
oldestTransition?: number;
|
|
92
|
+
newestTransition?: number;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
58
95
|
/**
|
|
59
96
|
* Record result after an agent finishes a round
|
|
60
97
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meta-orchestrator.d.ts","sourceRoot":"","sources":["../../src/lib/meta-orchestrator.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"meta-orchestrator.d.ts","sourceRoot":"","sources":["../../src/lib/meta-orchestrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAMzE,OAAO,KAAK,EAAE,UAAU,EAAgC,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAMzG,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,cAAc,EAAE,MAAM,CAAA;IACtB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,MAAM,EAAE,CAAA;CACxB;AAED,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;IAC9C,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,eAAe,EAAE,MAAM,CAAA;IACvB,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,WAAW,CAAA;IAClB,MAAM,EAAE,aAAa,GAAG,aAAa,GAAG,aAAa,GAAG,cAAc,GAAG,aAAa,CAAA;IACtF,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,UAAU,CAAC,EAAE,gBAAgB,CAAA;CAC9B;AAsCD,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,KAAK,CAAmB;IAChC,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,aAAa,CAAe;IACpC,OAAO,CAAC,eAAe,CAAiB;IACxC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