clementine-agent 1.0.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/.env.example +44 -0
- package/LICENSE +21 -0
- package/README.md +795 -0
- package/dist/agent/agent-manager.d.ts +69 -0
- package/dist/agent/agent-manager.js +441 -0
- package/dist/agent/assistant.d.ts +225 -0
- package/dist/agent/assistant.js +3888 -0
- package/dist/agent/auto-update.d.ts +32 -0
- package/dist/agent/auto-update.js +186 -0
- package/dist/agent/daily-planner.d.ts +24 -0
- package/dist/agent/daily-planner.js +379 -0
- package/dist/agent/execution-advisor.d.ts +10 -0
- package/dist/agent/execution-advisor.js +272 -0
- package/dist/agent/hooks.d.ts +45 -0
- package/dist/agent/hooks.js +564 -0
- package/dist/agent/insight-engine.d.ts +66 -0
- package/dist/agent/insight-engine.js +225 -0
- package/dist/agent/intent-classifier.d.ts +48 -0
- package/dist/agent/intent-classifier.js +214 -0
- package/dist/agent/link-extractor.d.ts +19 -0
- package/dist/agent/link-extractor.js +90 -0
- package/dist/agent/mcp-bridge.d.ts +62 -0
- package/dist/agent/mcp-bridge.js +435 -0
- package/dist/agent/metacognition.d.ts +66 -0
- package/dist/agent/metacognition.js +221 -0
- package/dist/agent/orchestrator.d.ts +81 -0
- package/dist/agent/orchestrator.js +790 -0
- package/dist/agent/profiles.d.ts +22 -0
- package/dist/agent/profiles.js +91 -0
- package/dist/agent/prompt-cache.d.ts +24 -0
- package/dist/agent/prompt-cache.js +68 -0
- package/dist/agent/prompt-evolver.d.ts +28 -0
- package/dist/agent/prompt-evolver.js +279 -0
- package/dist/agent/role-scaffolds.d.ts +28 -0
- package/dist/agent/role-scaffolds.js +433 -0
- package/dist/agent/safe-restart.d.ts +41 -0
- package/dist/agent/safe-restart.js +150 -0
- package/dist/agent/self-improve.d.ts +66 -0
- package/dist/agent/self-improve.js +1706 -0
- package/dist/agent/session-event-log.d.ts +114 -0
- package/dist/agent/session-event-log.js +233 -0
- package/dist/agent/skill-extractor.d.ts +72 -0
- package/dist/agent/skill-extractor.js +435 -0
- package/dist/agent/source-mods.d.ts +61 -0
- package/dist/agent/source-mods.js +230 -0
- package/dist/agent/source-preflight.d.ts +25 -0
- package/dist/agent/source-preflight.js +100 -0
- package/dist/agent/stall-guard.d.ts +62 -0
- package/dist/agent/stall-guard.js +109 -0
- package/dist/agent/strategic-planner.d.ts +60 -0
- package/dist/agent/strategic-planner.js +352 -0
- package/dist/agent/team-bus.d.ts +89 -0
- package/dist/agent/team-bus.js +556 -0
- package/dist/agent/team-router.d.ts +26 -0
- package/dist/agent/team-router.js +37 -0
- package/dist/agent/tool-loop-detector.d.ts +59 -0
- package/dist/agent/tool-loop-detector.js +242 -0
- package/dist/agent/workflow-runner.d.ts +36 -0
- package/dist/agent/workflow-runner.js +317 -0
- package/dist/agent/workflow-variables.d.ts +16 -0
- package/dist/agent/workflow-variables.js +62 -0
- package/dist/channels/discord-agent-bot.d.ts +101 -0
- package/dist/channels/discord-agent-bot.js +881 -0
- package/dist/channels/discord-bot-manager.d.ts +80 -0
- package/dist/channels/discord-bot-manager.js +262 -0
- package/dist/channels/discord-utils.d.ts +51 -0
- package/dist/channels/discord-utils.js +293 -0
- package/dist/channels/discord.d.ts +12 -0
- package/dist/channels/discord.js +1832 -0
- package/dist/channels/slack-agent-bot.d.ts +73 -0
- package/dist/channels/slack-agent-bot.js +320 -0
- package/dist/channels/slack-bot-manager.d.ts +66 -0
- package/dist/channels/slack-bot-manager.js +236 -0
- package/dist/channels/slack-utils.d.ts +39 -0
- package/dist/channels/slack-utils.js +189 -0
- package/dist/channels/slack.d.ts +11 -0
- package/dist/channels/slack.js +196 -0
- package/dist/channels/telegram.d.ts +10 -0
- package/dist/channels/telegram.js +235 -0
- package/dist/channels/webhook.d.ts +9 -0
- package/dist/channels/webhook.js +78 -0
- package/dist/channels/whatsapp.d.ts +11 -0
- package/dist/channels/whatsapp.js +181 -0
- package/dist/cli/chat.d.ts +14 -0
- package/dist/cli/chat.js +220 -0
- package/dist/cli/cron.d.ts +17 -0
- package/dist/cli/cron.js +552 -0
- package/dist/cli/dashboard.d.ts +15 -0
- package/dist/cli/dashboard.js +17677 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.js +2474 -0
- package/dist/cli/routes/delegations.d.ts +19 -0
- package/dist/cli/routes/delegations.js +154 -0
- package/dist/cli/routes/digest.d.ts +17 -0
- package/dist/cli/routes/digest.js +375 -0
- package/dist/cli/routes/goals.d.ts +14 -0
- package/dist/cli/routes/goals.js +258 -0
- package/dist/cli/routes/workflows.d.ts +18 -0
- package/dist/cli/routes/workflows.js +97 -0
- package/dist/cli/setup.d.ts +8 -0
- package/dist/cli/setup.js +619 -0
- package/dist/cli/tunnel.d.ts +35 -0
- package/dist/cli/tunnel.js +141 -0
- package/dist/config.d.ts +145 -0
- package/dist/config.js +278 -0
- package/dist/events/bus.d.ts +43 -0
- package/dist/events/bus.js +136 -0
- package/dist/gateway/cron-scheduler.d.ts +166 -0
- package/dist/gateway/cron-scheduler.js +1767 -0
- package/dist/gateway/delivery-queue.d.ts +30 -0
- package/dist/gateway/delivery-queue.js +110 -0
- package/dist/gateway/heartbeat-scheduler.d.ts +99 -0
- package/dist/gateway/heartbeat-scheduler.js +1298 -0
- package/dist/gateway/heartbeat.d.ts +3 -0
- package/dist/gateway/heartbeat.js +3 -0
- package/dist/gateway/lanes.d.ts +24 -0
- package/dist/gateway/lanes.js +76 -0
- package/dist/gateway/notifications.d.ts +29 -0
- package/dist/gateway/notifications.js +75 -0
- package/dist/gateway/router.d.ts +210 -0
- package/dist/gateway/router.js +1330 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1015 -0
- package/dist/memory/chunker.d.ts +28 -0
- package/dist/memory/chunker.js +226 -0
- package/dist/memory/consolidation.d.ts +44 -0
- package/dist/memory/consolidation.js +171 -0
- package/dist/memory/context-assembler.d.ts +50 -0
- package/dist/memory/context-assembler.js +149 -0
- package/dist/memory/embeddings.d.ts +38 -0
- package/dist/memory/embeddings.js +180 -0
- package/dist/memory/graph-store.d.ts +66 -0
- package/dist/memory/graph-store.js +613 -0
- package/dist/memory/mmr.d.ts +21 -0
- package/dist/memory/mmr.js +75 -0
- package/dist/memory/search.d.ts +26 -0
- package/dist/memory/search.js +67 -0
- package/dist/memory/store.d.ts +530 -0
- package/dist/memory/store.js +2022 -0
- package/dist/security/integrity.d.ts +24 -0
- package/dist/security/integrity.js +58 -0
- package/dist/security/patterns.d.ts +34 -0
- package/dist/security/patterns.js +110 -0
- package/dist/security/scanner.d.ts +32 -0
- package/dist/security/scanner.js +263 -0
- package/dist/tools/admin-tools.d.ts +12 -0
- package/dist/tools/admin-tools.js +1278 -0
- package/dist/tools/external-tools.d.ts +11 -0
- package/dist/tools/external-tools.js +1327 -0
- package/dist/tools/goal-tools.d.ts +9 -0
- package/dist/tools/goal-tools.js +159 -0
- package/dist/tools/mcp-server.d.ts +13 -0
- package/dist/tools/mcp-server.js +141 -0
- package/dist/tools/memory-tools.d.ts +10 -0
- package/dist/tools/memory-tools.js +568 -0
- package/dist/tools/session-tools.d.ts +6 -0
- package/dist/tools/session-tools.js +146 -0
- package/dist/tools/shared.d.ts +216 -0
- package/dist/tools/shared.js +340 -0
- package/dist/tools/team-tools.d.ts +6 -0
- package/dist/tools/team-tools.js +447 -0
- package/dist/tools/tool-meta.d.ts +34 -0
- package/dist/tools/tool-meta.js +133 -0
- package/dist/tools/vault-tools.d.ts +8 -0
- package/dist/tools/vault-tools.js +457 -0
- package/dist/types.d.ts +716 -0
- package/dist/types.js +16 -0
- package/dist/vault-migrations/0001-add-execution-framework.d.ts +10 -0
- package/dist/vault-migrations/0001-add-execution-framework.js +47 -0
- package/dist/vault-migrations/0002-add-agentic-communication.d.ts +12 -0
- package/dist/vault-migrations/0002-add-agentic-communication.js +79 -0
- package/dist/vault-migrations/0003-update-execution-pipeline-narration.d.ts +11 -0
- package/dist/vault-migrations/0003-update-execution-pipeline-narration.js +73 -0
- package/dist/vault-migrations/helpers.d.ts +14 -0
- package/dist/vault-migrations/helpers.js +44 -0
- package/dist/vault-migrations/runner.d.ts +14 -0
- package/dist/vault-migrations/runner.js +139 -0
- package/dist/vault-migrations/types.d.ts +42 -0
- package/dist/vault-migrations/types.js +9 -0
- package/install.sh +320 -0
- package/package.json +84 -0
- package/scripts/postinstall.js +125 -0
- package/vault/00-System/AGENTS.md +66 -0
- package/vault/00-System/CRON.md +71 -0
- package/vault/00-System/HEARTBEAT.md +58 -0
- package/vault/00-System/MEMORY.md +16 -0
- package/vault/00-System/SOUL.md +96 -0
- package/vault/05-Tasks/TASKS.md +19 -0
- package/vault/06-Templates/_Daily-Template.md +28 -0
- package/vault/06-Templates/_People-Template.md +22 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clementine TypeScript — Metacognitive Monitor.
|
|
3
|
+
*
|
|
4
|
+
* Tracks reasoning quality signals during query/cron/unleashed execution.
|
|
5
|
+
* Detects stuck loops, circular reasoning, confidence drops, and strategy
|
|
6
|
+
* mismatches. Injects guidance when the agent appears to need a nudge.
|
|
7
|
+
*
|
|
8
|
+
* This is the foundation layer — everything else (user model, self-improve,
|
|
9
|
+
* skills) works better when the agent can evaluate its own thinking.
|
|
10
|
+
*/
|
|
11
|
+
import { createHash } from 'node:crypto';
|
|
12
|
+
// ── Tool categories ─────────────────────────────────────────────────
|
|
13
|
+
const READ_TOOLS = new Set([
|
|
14
|
+
'Read', 'Glob', 'Grep', 'memory_read', 'memory_search', 'memory_recall',
|
|
15
|
+
'transcript_search', 'vault_stats', 'task_list', 'goal_list', 'goal_get',
|
|
16
|
+
'workspace_list', 'workspace_info', 'cron_list', 'team_list',
|
|
17
|
+
'outlook_inbox', 'outlook_search', 'outlook_calendar', 'github_prs',
|
|
18
|
+
'rss_fetch', 'WebSearch', 'WebFetch',
|
|
19
|
+
]);
|
|
20
|
+
const ACTION_TOOLS = new Set([
|
|
21
|
+
'Write', 'Edit', 'Bash', 'Agent', 'Task', 'delegate_task',
|
|
22
|
+
'memory_write', 'note_create', 'note_take',
|
|
23
|
+
'task_add', 'task_update', 'goal_create', 'goal_update', 'goal_work',
|
|
24
|
+
'add_cron_job', 'create_agent', 'update_agent', 'delete_agent',
|
|
25
|
+
'team_message', 'discord_channel_send', 'outlook_draft', 'outlook_send',
|
|
26
|
+
'set_timer', 'self_restart', 'feedback_log', 'teach_skill', 'create_tool',
|
|
27
|
+
]);
|
|
28
|
+
// ── MetacognitiveMonitor ────────────────────────────────────────────
|
|
29
|
+
export class MetacognitiveMonitor {
|
|
30
|
+
toolCalls = [];
|
|
31
|
+
uniqueTools = new Set();
|
|
32
|
+
consecutiveReads = 0;
|
|
33
|
+
turnCount = 0;
|
|
34
|
+
outputCharCount = 0;
|
|
35
|
+
interventionCount = 0;
|
|
36
|
+
signals = [];
|
|
37
|
+
confidence = 'high';
|
|
38
|
+
/**
|
|
39
|
+
* Record a tool call. Returns a signal if the pattern is concerning.
|
|
40
|
+
*/
|
|
41
|
+
recordToolCall(name, input) {
|
|
42
|
+
const inputHash = createHash('sha256').update(JSON.stringify(input)).digest('hex').slice(0, 12);
|
|
43
|
+
this.toolCalls.push({ name, inputHash, timestamp: Date.now() });
|
|
44
|
+
this.uniqueTools.add(name);
|
|
45
|
+
// Normalize MCP tool names: "mcp__clementine-tools__memory_write" → "memory_write"
|
|
46
|
+
const normalizedName = name.replace(/^mcp__[^_]+__/, '');
|
|
47
|
+
// Track read/action balance (check both raw and normalized names)
|
|
48
|
+
if (READ_TOOLS.has(name) || READ_TOOLS.has(normalizedName)) {
|
|
49
|
+
this.consecutiveReads++;
|
|
50
|
+
}
|
|
51
|
+
else if (ACTION_TOOLS.has(name) || ACTION_TOOLS.has(normalizedName)) {
|
|
52
|
+
this.consecutiveReads = 0;
|
|
53
|
+
}
|
|
54
|
+
// Signal: too many consecutive reads without action
|
|
55
|
+
// Fires on every read past the threshold (not just once) so the stall breaker stays active
|
|
56
|
+
if (this.consecutiveReads >= 12) {
|
|
57
|
+
this.confidence = 'low';
|
|
58
|
+
if (!this.signals.includes('research_without_action'))
|
|
59
|
+
this.signals.push('research_without_action');
|
|
60
|
+
this.interventionCount++;
|
|
61
|
+
return {
|
|
62
|
+
type: 'intervene',
|
|
63
|
+
reason: 'research_without_action',
|
|
64
|
+
guidance: `You've done ${this.consecutiveReads} consecutive reads without acting. STOP reading and either act on what you have or tell the user what's blocking you.`,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (this.consecutiveReads >= 8) {
|
|
68
|
+
this.confidence = 'medium';
|
|
69
|
+
if (!this.signals.includes('research_without_action'))
|
|
70
|
+
this.signals.push('research_without_action');
|
|
71
|
+
return {
|
|
72
|
+
type: 'warn',
|
|
73
|
+
reason: 'research_without_action',
|
|
74
|
+
guidance: `You've done ${this.consecutiveReads} consecutive reads without acting. Pick a strategy: ` +
|
|
75
|
+
`(1) Delegate — spawn sub-agents via the Agent tool for parallel work. ` +
|
|
76
|
+
`(2) Plan — respond with [PLAN_NEEDED: description] for complex tasks. ` +
|
|
77
|
+
`(3) Act on partial info — start editing with what you know. ` +
|
|
78
|
+
`(4) Ask the user a specific question if scope is unclear.`,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
// Signal: same tool + similar input called 3+ times
|
|
82
|
+
const recentSame = this.toolCalls
|
|
83
|
+
.slice(-10)
|
|
84
|
+
.filter(t => t.name === name && t.inputHash === inputHash);
|
|
85
|
+
if (recentSame.length >= 3) {
|
|
86
|
+
this.confidence = 'low';
|
|
87
|
+
const signal = {
|
|
88
|
+
type: 'intervene',
|
|
89
|
+
reason: 'circular_reasoning',
|
|
90
|
+
guidance: `You've called ${name} with the same input ${recentSame.length} times. Try a different approach or tool.`,
|
|
91
|
+
};
|
|
92
|
+
if (!this.signals.includes('circular_reasoning'))
|
|
93
|
+
this.signals.push('circular_reasoning');
|
|
94
|
+
this.interventionCount++;
|
|
95
|
+
return signal;
|
|
96
|
+
}
|
|
97
|
+
// Signal: excessive tool calls (>20 in a single execution)
|
|
98
|
+
if (this.toolCalls.length > 20 && this.outputCharCount < 200) {
|
|
99
|
+
this.confidence = 'low';
|
|
100
|
+
if (!this.signals.includes('high_effort_low_output')) {
|
|
101
|
+
this.signals.push('high_effort_low_output');
|
|
102
|
+
return {
|
|
103
|
+
type: 'warn',
|
|
104
|
+
reason: 'high_effort_low_output',
|
|
105
|
+
guidance: 'You\'ve made 20+ tool calls with minimal output. Step back and simplify your approach.',
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return { type: 'ok' };
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Assess the quality of the current turn after the assistant responds.
|
|
113
|
+
*/
|
|
114
|
+
assessTurn(responseText, toolCallsThisTurn) {
|
|
115
|
+
this.turnCount++;
|
|
116
|
+
this.outputCharCount += responseText.length;
|
|
117
|
+
// Reset consecutive reads if the agent produced substantial output
|
|
118
|
+
if (responseText.length > 100 && toolCallsThisTurn === 0) {
|
|
119
|
+
this.consecutiveReads = 0;
|
|
120
|
+
}
|
|
121
|
+
const efficiency = this.turnCount > 0
|
|
122
|
+
? Math.min(1, this.outputCharCount / (this.turnCount * 500))
|
|
123
|
+
: 0;
|
|
124
|
+
// Detect turns with no progress
|
|
125
|
+
if (responseText.length < 20 && toolCallsThisTurn === 0) {
|
|
126
|
+
if (!this.signals.includes('empty_turn'))
|
|
127
|
+
this.signals.push('empty_turn');
|
|
128
|
+
}
|
|
129
|
+
// Build guidance if confidence is low
|
|
130
|
+
let guidance;
|
|
131
|
+
if (this.confidence === 'low' && this.interventionCount < 3) {
|
|
132
|
+
guidance = this.buildGuidance();
|
|
133
|
+
if (guidance)
|
|
134
|
+
this.interventionCount++;
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
confidence: this.confidence,
|
|
138
|
+
efficiency,
|
|
139
|
+
signals: [...this.signals],
|
|
140
|
+
guidance,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Get the final metacognitive summary for this execution.
|
|
145
|
+
*/
|
|
146
|
+
getSummary() {
|
|
147
|
+
const efficiency = this.turnCount > 0
|
|
148
|
+
? Math.min(1, this.outputCharCount / (this.turnCount * 500))
|
|
149
|
+
: 0;
|
|
150
|
+
return {
|
|
151
|
+
efficiency: Math.round(efficiency * 100) / 100,
|
|
152
|
+
toolCallCount: this.toolCalls.length,
|
|
153
|
+
uniqueTools: this.uniqueTools.size,
|
|
154
|
+
stuckDetected: this.signals.includes('circular_reasoning') || this.signals.includes('research_without_action'),
|
|
155
|
+
interventionCount: this.interventionCount,
|
|
156
|
+
confidenceFinal: this.confidence,
|
|
157
|
+
signals: [...this.signals],
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Build contextual guidance based on current signals.
|
|
162
|
+
*/
|
|
163
|
+
buildGuidance() {
|
|
164
|
+
if (this.signals.includes('circular_reasoning')) {
|
|
165
|
+
return '[SELF-CHECK: You appear to be going in circles. Try a completely different approach to this problem.]';
|
|
166
|
+
}
|
|
167
|
+
if (this.signals.includes('research_without_action')) {
|
|
168
|
+
return '[SELF-CHECK: You\'ve been researching extensively. Time to act on what you\'ve gathered — deliver a result with what you know.]';
|
|
169
|
+
}
|
|
170
|
+
if (this.signals.includes('high_effort_low_output')) {
|
|
171
|
+
return '[SELF-CHECK: High effort, low output. Can you accomplish this more directly? Simplify your approach.]';
|
|
172
|
+
}
|
|
173
|
+
return undefined;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Detect when the agent's text promises action but no tools were called.
|
|
177
|
+
* Call this after the query completes with the full response text.
|
|
178
|
+
*
|
|
179
|
+
* @returns A signal if the response looks like a stall (promised action, didn't deliver).
|
|
180
|
+
*/
|
|
181
|
+
detectPromiseWithoutAction(responseText, toolCallCount) {
|
|
182
|
+
if (toolCallCount > 2)
|
|
183
|
+
return { type: 'ok' };
|
|
184
|
+
const lower = responseText.toLowerCase();
|
|
185
|
+
const ACTION_PROMISES = [
|
|
186
|
+
/\blet me (?:read|grab|check|pull|get|look at|open|find|fetch|load)\b/,
|
|
187
|
+
/\bi'?ll (?:read|grab|check|pull|get|look at|open|find|fetch|start|work on)\b/,
|
|
188
|
+
/\bstarting (?:with|on|now)\b/,
|
|
189
|
+
/\bstill (?:on it|working|reading|looking)\b/,
|
|
190
|
+
/\bgive me (?:a moment|a sec|one moment)\b/,
|
|
191
|
+
/\bworking on (?:it|that|this)\b/,
|
|
192
|
+
/\blet me (?:take|have) a look\b/,
|
|
193
|
+
];
|
|
194
|
+
const promisedAction = ACTION_PROMISES.some((rx) => rx.test(lower));
|
|
195
|
+
if (!promisedAction)
|
|
196
|
+
return { type: 'ok' };
|
|
197
|
+
// The agent said it would do something but made 0-2 tool calls — likely stalled
|
|
198
|
+
if (!this.signals.includes('promise_without_action')) {
|
|
199
|
+
this.signals.push('promise_without_action');
|
|
200
|
+
}
|
|
201
|
+
this.confidence = 'low';
|
|
202
|
+
this.interventionCount++;
|
|
203
|
+
return {
|
|
204
|
+
type: 'intervene',
|
|
205
|
+
reason: 'promise_without_action',
|
|
206
|
+
guidance: 'You said you would take action but did not follow through. ' +
|
|
207
|
+
'Do not promise to read/grab/check something without actually doing it in the same turn.',
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
/** Reset for a new execution (e.g., new phase in unleashed). */
|
|
211
|
+
reset() {
|
|
212
|
+
this.toolCalls = [];
|
|
213
|
+
this.uniqueTools.clear();
|
|
214
|
+
this.consecutiveReads = 0;
|
|
215
|
+
this.turnCount = 0;
|
|
216
|
+
this.outputCharCount = 0;
|
|
217
|
+
this.signals = [];
|
|
218
|
+
// Keep interventionCount and confidence across phases for learning
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=metacognition.js.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clementine TypeScript — Plan Orchestrator.
|
|
3
|
+
*
|
|
4
|
+
* Decomposes a task into steps, runs independent steps in parallel
|
|
5
|
+
* via concurrent query() calls, then synthesizes a final response.
|
|
6
|
+
*/
|
|
7
|
+
import type { PersonalAssistant } from './assistant.js';
|
|
8
|
+
import type { AgentProfile, PlanStep, ExecutionPlan, PlanProgressUpdate } from '../types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Compute execution waves from a dependency graph via topological sort.
|
|
11
|
+
* Steps with empty dependsOn = wave 0. Steps whose deps are all in wave N = wave N+1.
|
|
12
|
+
*/
|
|
13
|
+
export declare function computeWaves(steps: PlanStep[]): PlanStep[][];
|
|
14
|
+
/**
|
|
15
|
+
* Run promises with a concurrency limit.
|
|
16
|
+
*/
|
|
17
|
+
export declare function settledWithLimit<T>(tasks: (() => Promise<T>)[], limit: number): Promise<PromiseSettledResult<T>[]>;
|
|
18
|
+
/** Persistent state for a plan execution — survives interruptions. */
|
|
19
|
+
interface PlanState {
|
|
20
|
+
id: string;
|
|
21
|
+
goal: string;
|
|
22
|
+
status: 'planning' | 'executing' | 'synthesizing' | 'complete' | 'failed';
|
|
23
|
+
startedAt: string;
|
|
24
|
+
updatedAt: string;
|
|
25
|
+
plan?: ExecutionPlan;
|
|
26
|
+
totalWaves: number;
|
|
27
|
+
wavesCompleted: number;
|
|
28
|
+
results: Record<string, string>;
|
|
29
|
+
errors: Array<{
|
|
30
|
+
stepId: string;
|
|
31
|
+
error: string;
|
|
32
|
+
}>;
|
|
33
|
+
retries: Record<string, number>;
|
|
34
|
+
}
|
|
35
|
+
export declare class PlanOrchestrator {
|
|
36
|
+
private assistant;
|
|
37
|
+
private stepStatuses;
|
|
38
|
+
private stepStartTimes;
|
|
39
|
+
private startTime;
|
|
40
|
+
private stateId;
|
|
41
|
+
private agentProfiles;
|
|
42
|
+
constructor(assistant: PersonalAssistant);
|
|
43
|
+
private saveState;
|
|
44
|
+
private cleanupState;
|
|
45
|
+
/** Load a previously interrupted plan state (for future resumability). */
|
|
46
|
+
static loadState(stateId: string): PlanState | null;
|
|
47
|
+
/**
|
|
48
|
+
* Main entry: plan → approve → execute → synthesize → return final response.
|
|
49
|
+
*/
|
|
50
|
+
run(taskDescription: string, onProgress?: (updates: PlanProgressUpdate[]) => Promise<void>, onApproval?: (planSummary: string, steps: PlanStep[]) => Promise<boolean | string>, availableAgents?: AgentProfile[]): Promise<string>;
|
|
51
|
+
/**
|
|
52
|
+
* Goal-backward verification pass using Haiku after plan synthesis.
|
|
53
|
+
* Verifies outcomes rather than just rating quality:
|
|
54
|
+
* - Did each step produce a real result?
|
|
55
|
+
* - Is the synthesized output substantive (not restating the question)?
|
|
56
|
+
* - Are there gaps between request and output?
|
|
57
|
+
*/
|
|
58
|
+
private runReflection;
|
|
59
|
+
/**
|
|
60
|
+
* Get formatted progress lines for display.
|
|
61
|
+
*/
|
|
62
|
+
getProgressLines(): string[];
|
|
63
|
+
/**
|
|
64
|
+
* Inter-wave spot-check: verify that step results contain substance.
|
|
65
|
+
* Catches empty outputs, error-only results, and placeholder/stub responses
|
|
66
|
+
* before downstream waves try to build on them.
|
|
67
|
+
*/
|
|
68
|
+
private spotCheckWaveResults;
|
|
69
|
+
/** Check if a step has downstream dependents in the plan. */
|
|
70
|
+
private hasDependents;
|
|
71
|
+
/** Fast Haiku call to decide how to repair a failed critical step. */
|
|
72
|
+
private getRepairDecision;
|
|
73
|
+
private generatePlan;
|
|
74
|
+
private parseJsonFromResponse;
|
|
75
|
+
private buildStepPrompt;
|
|
76
|
+
private buildSynthesisPrompt;
|
|
77
|
+
private runSingleStep;
|
|
78
|
+
private getAllUpdates;
|
|
79
|
+
}
|
|
80
|
+
export {};
|
|
81
|
+
//# sourceMappingURL=orchestrator.d.ts.map
|