@iaforged/context-code 1.2.9 → 1.2.10
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 +119 -119
- package/context-bootstrap.js +26 -26
- package/dist/src/QueryEngine.js +394 -327
- package/dist/src/bridge/bridgeUI.js +1 -1
- package/dist/src/buddy/prompt.js +4 -4
- package/dist/src/cli/handlers/auth.js +126 -9
- package/dist/src/cli/print.js +35 -1
- package/dist/src/commands/agent/agent.js +28 -2
- package/dist/src/commands/agent/agentStore.js +8 -1
- package/dist/src/commands/agent/index.js +1 -1
- package/dist/src/commands/bridge-kick.js +9 -9
- package/dist/src/commands/commit.js +34 -34
- package/dist/src/commands/init-verifiers.js +3 -3
- package/dist/src/commands/init.js +88 -88
- package/dist/src/commands/insights.js +787 -787
- package/dist/src/commands/install.js +19 -19
- package/dist/src/commands/login/login.js +21 -12
- package/dist/src/commands/logout/logout.js +9 -0
- package/dist/src/commands/model/model.js +9 -4
- package/dist/src/commands/orchestrate/SwarmUI.js +50 -0
- package/dist/src/commands/orchestrate/index.js +2 -2
- package/dist/src/commands/orchestrate/orchestrate.js +708 -12
- package/dist/src/commands/pr_comments/index.js +33 -33
- package/dist/src/commands/profile/index.js +1 -1
- package/dist/src/commands/profile/profile.js +52 -3
- package/dist/src/commands/provider/index.js +1 -1
- package/dist/src/commands/provider/provider.js +117 -45
- package/dist/src/commands/resumen/index.js +9 -0
- package/dist/src/commands/resumen/resumen.js +29 -0
- package/dist/src/commands/security-review.js +190 -190
- package/dist/src/commands/swarm-auto/index.js +9 -0
- package/dist/src/commands/swarm-auto/swarmAuto.js +111 -0
- package/dist/src/commands/swarm-init/index.js +9 -0
- package/dist/src/commands/swarm-init/swarmInit.js +72 -0
- package/dist/src/commands/team/team.js +39 -6
- package/dist/src/commands.js +14 -0
- package/dist/src/components/LogoV2/CondensedLogo.js +2 -2
- package/dist/src/components/PromptInput/PromptInputQueuedCommands.js +3 -3
- package/dist/src/components/agents/agentFileUtils.js +6 -6
- package/dist/src/components/permissions/hooks.js +5 -5
- package/dist/src/constants/outputStyles.js +83 -83
- package/dist/src/core/agents/blueprints.js +58 -0
- package/dist/src/core/agents/cliAdapter.js +61 -0
- package/dist/src/core/agents/registry.js +93 -0
- package/dist/src/core/agents/runtime.js +4 -0
- package/dist/src/core/agents/runtime.smoke.js +42 -0
- package/dist/src/core/agents/swarm.smoke.js +48 -0
- package/dist/src/core/agents/swarmTools.js +38 -0
- package/dist/src/core/auth/index.js +2 -0
- package/dist/src/core/auth/loginCliAdapter.js +24 -0
- package/dist/src/core/auth/loginCore.js +67 -0
- package/dist/src/core/auth/logoutCliAdapter.js +34 -0
- package/dist/src/core/auth/logoutCore.js +52 -0
- package/dist/src/core/auth/preflight.smoke.js +151 -0
- package/dist/src/core/index.js +21 -0
- package/dist/src/core/mcp/blueprints.js +27 -0
- package/dist/src/core/mcp/common.js +14 -0
- package/dist/src/core/mcp/runtime.js +67 -0
- package/dist/src/core/mcp/runtime.smoke.js +50 -0
- package/dist/src/core/mcp/swarmClient.js +40 -0
- package/dist/src/core/mcp/swarmSetup.js +43 -0
- package/dist/src/core/providers/cliAdapter.js +39 -0
- package/dist/src/core/providers/contracts.js +1 -0
- package/dist/src/core/providers/index.js +3 -0
- package/dist/src/core/providers/llmCore.js +123 -0
- package/dist/src/core/providers/providerCore.js +141 -0
- package/dist/src/core/providers/providerModelCompatibility.js +98 -0
- package/dist/src/core/providers/providerParitySmoke.js +83 -0
- package/dist/src/core/providers/providerProfileModelSmoke.js +80 -0
- package/dist/src/core/query/contracts.js +1 -0
- package/dist/src/core/query/runtime.js +117 -0
- package/dist/src/core/query/runtime.smoke.js +39 -0
- package/dist/src/core/query/timelineThinking.smoke.js +25 -0
- package/dist/src/core/query/wiring.smoke.js +76 -0
- package/dist/src/core/skills/cliAdapter.js +38 -0
- package/dist/src/core/skills/index.js +52 -0
- package/dist/src/core/skills/runtime.smoke.js +53 -0
- package/dist/src/core/tasks/runtime.js +205 -0
- package/dist/src/core/tasks/runtime.smoke.js +63 -0
- package/dist/src/core/tasks/sdkAdapter.js +4 -0
- package/dist/src/core/tools/contracts.js +3 -0
- package/dist/src/core/tools/fileResolution.js +112 -0
- package/dist/src/core/tools/fileResolution.smoke.js +33 -0
- package/dist/src/core/tools/filesCore.js +51 -0
- package/dist/src/core/tools/filesCore.smoke.js +108 -0
- package/dist/src/core/tools/gitCore.js +20 -0
- package/dist/src/core/tools/imageParity.smoke.js +36 -0
- package/dist/src/core/tools/notebookParity.smoke.js +68 -0
- package/dist/src/core/tools/registry.js +22 -0
- package/dist/src/core/tools/runtime.smoke.js +32 -0
- package/dist/src/core/tools/shellCore.js +60 -0
- package/dist/src/core/types/agentContext.js +9 -0
- package/dist/src/core/types/auth.js +3 -0
- package/dist/src/core/types/command.js +13 -0
- package/dist/src/core/types/provider.js +3 -0
- package/dist/src/core/types/sdkEvent.js +10 -0
- package/dist/src/core/types/swarm.js +1 -0
- package/dist/src/cost-tracker.js +3 -3
- package/dist/src/hooks/useAwaySummary.js +22 -9
- package/dist/src/main.js +32 -2
- package/dist/src/screens/REPL.js +9 -0
- package/dist/src/services/AgentSummary/agentSummary.js +10 -10
- package/dist/src/services/autoDream/autoDream.js +5 -5
- package/dist/src/services/autoDream/consolidationPrompt.js +49 -49
- package/dist/src/services/compact/prompt.js +238 -238
- package/dist/src/services/limits/sessionCounter.js +17 -17
- package/dist/src/services/mcp/client.js +27 -1
- package/dist/src/services/orchestration/execution/AgentTaskExecutor.js +39 -20
- package/dist/src/services/orchestration/execution/OrchestrationExecutionRuntime.js +65 -58
- package/dist/src/skills/bundled/loop.js +57 -57
- package/dist/src/skills/bundled/remember.js +53 -53
- package/dist/src/skills/bundled/simplify.js +49 -49
- package/dist/src/skills/bundled/skillify.js +2 -2
- package/dist/src/state/onChangeAppState.js +6 -0
- package/dist/src/tasks/LocalAgentTask/LocalAgentTask.js +5 -5
- package/dist/src/tasks/LocalMainSessionTask.js +5 -5
- package/dist/src/tasks/LocalShellTask/LocalShellTask.js +13 -13
- package/dist/src/tools/AgentTool/forkSubagent.js +25 -25
- package/dist/src/tools/AskUserQuestionTool/prompt.js +29 -29
- package/dist/src/tools/BashTool/BashTool.js +27 -2
- package/dist/src/tools/BriefTool/prompt.js +14 -14
- package/dist/src/tools/EnterPlanModeTool/EnterPlanModeTool.js +12 -12
- package/dist/src/tools/EnterPlanModeTool/prompt.js +140 -140
- package/dist/src/tools/ExitPlanModeTool/ExitPlanModeV2Tool.js +18 -18
- package/dist/src/tools/ExitPlanModeTool/prompt.js +23 -23
- package/dist/src/tools/ExitWorktreeTool/prompt.js +29 -29
- package/dist/src/tools/FileEditTool/prompt.js +7 -7
- package/dist/src/tools/FileReadTool/FileReadTool.js +18 -1
- package/dist/src/tools/FileWriteTool/prompt.js +6 -6
- package/dist/src/tools/GlobTool/prompt.js +4 -4
- package/dist/src/tools/GrepTool/prompt.js +10 -10
- package/dist/src/tools/LSPTool/prompt.js +18 -18
- package/dist/src/tools/ListMcpResourcesTool/prompt.js +15 -15
- package/dist/src/tools/PowerShellTool/PowerShellTool.js +25 -2
- package/dist/src/tools/ReadMcpResourceTool/prompt.js +13 -13
- package/dist/src/tools/SendMessageTool/prompt.js +36 -36
- package/dist/src/tools/SkillTool/prompt.js +21 -21
- package/dist/src/tools/SleepTool/prompt.js +10 -10
- package/dist/src/tools/TaskCreateTool/prompt.js +41 -41
- package/dist/src/tools/TaskGetTool/prompt.js +21 -21
- package/dist/src/tools/TaskListTool/prompt.js +30 -30
- package/dist/src/tools/TaskOutputTool/TaskOutputTool.js +8 -8
- package/dist/src/tools/TaskStopTool/prompt.js +5 -5
- package/dist/src/tools/TaskUpdateTool/prompt.js +74 -74
- package/dist/src/tools/TodoWriteTool/prompt.js +178 -178
- package/dist/src/tools/ToolSearchTool/prompt.js +9 -9
- package/dist/src/tools/WebFetchTool/WebFetchTool.js +9 -9
- package/dist/src/tools/WebFetchTool/prompt.js +31 -31
- package/dist/src/tools/WebSearchTool/prompt.js +26 -26
- package/dist/src/utils/agentContext.js +2 -0
- package/dist/src/utils/agenticSessionSearch.js +38 -38
- package/dist/src/utils/config.js +2 -0
- package/dist/src/utils/genericProcessUtils.js +21 -21
- package/dist/src/utils/heapDumpService.js +4 -4
- package/dist/src/utils/mcpValidation.js +2 -2
- package/dist/src/utils/model/modelStrings.js +1 -1
- package/dist/src/utils/model/providers.js +5 -0
- package/dist/src/utils/orchestration/store/providerAgentStore.js +22 -22
- package/dist/src/utils/orchestration/store/providerWorkspaceStore.js +10 -10
- package/dist/src/utils/orchestration/store/runStore.js +68 -68
- package/dist/src/utils/orchestration/store/teamStore.js +28 -28
- package/dist/src/utils/permissions/permissionExplainer.js +6 -6
- package/dist/src/utils/permissions/permissionsDb.js +43 -43
- package/dist/src/utils/sdkEventQueue.js +2 -0
- package/dist/src/utils/secureStorage/sqliteStorage.js +12 -12
- package/dist/src/utils/standardMcp/common.js +15 -0
- package/dist/src/utils/standardMcp/setup.js +52 -0
- package/dist/src/utils/swarm/teammatePromptAddendum.js +10 -10
- package/dist/src/utils/task/framework.js +6 -6
- package/package.json +1 -1
- package/dist/src/commands/usage/index.js +0 -7
- package/dist/src/commands/usage/usage.js +0 -5
|
@@ -1,13 +1,709 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { Box, Text, useInput } from '../../ink.js';
|
|
4
|
+
import { createGlobalOrchestratorRuntime, createSquadOrchestratorRuntime, resumeOrchestrationRun, } from '../../services/orchestration/index.js';
|
|
5
|
+
import { createOrchestrationMessage, createOrchestrationRun, createOrchestrationTask, getOrchestrationRunById, getProviderAgentById, getProviderWorkspaceById, getTeamByName, listOrchestrationMessages, listOrchestrationTasks, listTeamDomainMembers, listTeamDomains, } from '../../utils/orchestration/store/index.js';
|
|
6
|
+
import { activityManager } from '../../utils/activityManager.js';
|
|
7
|
+
import { manuallyExtractSessionMemory } from '../../services/sessionMemory/sessionMemory.js';
|
|
8
|
+
import { createUserMessage, createAssistantMessage } from '../../utils/messages.js';
|
|
9
|
+
function parseArgs(args) {
|
|
10
|
+
const trimmed = args.trim();
|
|
11
|
+
if (!trimmed) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const [teamName, ...rest] = trimmed.split(/\s+/);
|
|
15
|
+
const objective = rest.join(' ').trim();
|
|
16
|
+
if (!teamName || !objective) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return { teamName, objective };
|
|
13
20
|
}
|
|
21
|
+
function roleFromDuty(duty) {
|
|
22
|
+
const normalized = duty?.trim().toLowerCase();
|
|
23
|
+
switch (normalized) {
|
|
24
|
+
case 'planner':
|
|
25
|
+
case 'plan':
|
|
26
|
+
case 'planning':
|
|
27
|
+
return 'planner';
|
|
28
|
+
case 'validator':
|
|
29
|
+
case 'reviewer':
|
|
30
|
+
case 'review':
|
|
31
|
+
case 'qa':
|
|
32
|
+
return 'validator';
|
|
33
|
+
case 'researcher':
|
|
34
|
+
case 'research':
|
|
35
|
+
case 'investigator':
|
|
36
|
+
return 'researcher';
|
|
37
|
+
case 'observer':
|
|
38
|
+
case 'watcher':
|
|
39
|
+
return 'observer';
|
|
40
|
+
default:
|
|
41
|
+
return 'executor';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function buildAgentLabel(provider, name) {
|
|
45
|
+
return `${provider}/${name}`;
|
|
46
|
+
}
|
|
47
|
+
function appendUniqueMember(members, candidate) {
|
|
48
|
+
if (members.some(member => member.id === candidate.id)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
members.push(candidate);
|
|
52
|
+
}
|
|
53
|
+
async function buildDomainContexts(teamId) {
|
|
54
|
+
const domains = await listTeamDomains(teamId);
|
|
55
|
+
const contexts = [];
|
|
56
|
+
for (const domain of domains) {
|
|
57
|
+
const warnings = [];
|
|
58
|
+
const members = [];
|
|
59
|
+
const workspace = domain.workspaceId
|
|
60
|
+
? await getProviderWorkspaceById(domain.workspaceId)
|
|
61
|
+
: null;
|
|
62
|
+
const workspaceLabel = workspace
|
|
63
|
+
? `${workspace.displayName} (${workspace.provider})`
|
|
64
|
+
: 'sin workspace';
|
|
65
|
+
const workspaceEnabled = workspace?.isEnabled ?? false;
|
|
66
|
+
if (!workspace) {
|
|
67
|
+
warnings.push('No tiene workspace asignado.');
|
|
68
|
+
}
|
|
69
|
+
else if (!workspace.isEnabled) {
|
|
70
|
+
warnings.push(`El workspace ${workspace.displayName} esta deshabilitado.`);
|
|
71
|
+
}
|
|
72
|
+
const localOrchestrator = domain.localOrchestratorAgentId
|
|
73
|
+
? await getProviderAgentById(domain.localOrchestratorAgentId)
|
|
74
|
+
: null;
|
|
75
|
+
if (domain.localOrchestratorAgentId && !localOrchestrator) {
|
|
76
|
+
warnings.push('El orquestador local configurado ya no existe.');
|
|
77
|
+
}
|
|
78
|
+
const leadAgent = domain.leadAgentId
|
|
79
|
+
? await getProviderAgentById(domain.leadAgentId)
|
|
80
|
+
: null;
|
|
81
|
+
if (domain.leadAgentId && !leadAgent) {
|
|
82
|
+
warnings.push('El lead agent configurado ya no existe.');
|
|
83
|
+
}
|
|
84
|
+
if (localOrchestrator) {
|
|
85
|
+
const orchestratorWorkspace = await getProviderWorkspaceById(localOrchestrator.workspaceId);
|
|
86
|
+
appendUniqueMember(members, {
|
|
87
|
+
id: localOrchestrator.id,
|
|
88
|
+
name: buildAgentLabel(orchestratorWorkspace?.provider ?? 'unknown', localOrchestrator.name),
|
|
89
|
+
role: 'planner',
|
|
90
|
+
providerHint: orchestratorWorkspace?.provider,
|
|
91
|
+
enabled: localOrchestrator.isEnabled,
|
|
92
|
+
});
|
|
93
|
+
if (!localOrchestrator.isEnabled) {
|
|
94
|
+
warnings.push(`El orquestador local ${localOrchestrator.name} esta deshabilitado.`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (leadAgent) {
|
|
98
|
+
const leadWorkspace = await getProviderWorkspaceById(leadAgent.workspaceId);
|
|
99
|
+
appendUniqueMember(members, {
|
|
100
|
+
id: leadAgent.id,
|
|
101
|
+
name: buildAgentLabel(leadWorkspace?.provider ?? 'unknown', leadAgent.name),
|
|
102
|
+
role: leadAgent.isOrchestrator ? 'planner' : 'executor',
|
|
103
|
+
providerHint: leadWorkspace?.provider,
|
|
104
|
+
enabled: leadAgent.isEnabled,
|
|
105
|
+
});
|
|
106
|
+
if (!leadAgent.isEnabled) {
|
|
107
|
+
warnings.push(`El lead agent ${leadAgent.name} esta deshabilitado.`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const domainMembers = await listTeamDomainMembers(domain.id);
|
|
111
|
+
for (const member of domainMembers) {
|
|
112
|
+
const agent = await getProviderAgentById(member.agentId);
|
|
113
|
+
if (!agent) {
|
|
114
|
+
warnings.push(`Un miembro del equipo ya no existe: ${member.agentId}`);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const memberWorkspace = await getProviderWorkspaceById(agent.workspaceId);
|
|
118
|
+
appendUniqueMember(members, {
|
|
119
|
+
id: agent.id,
|
|
120
|
+
name: buildAgentLabel(memberWorkspace?.provider ?? 'unknown', agent.name),
|
|
121
|
+
role: roleFromDuty(member.duty),
|
|
122
|
+
providerHint: memberWorkspace?.provider,
|
|
123
|
+
enabled: agent.isEnabled,
|
|
124
|
+
});
|
|
125
|
+
if (!agent.isEnabled) {
|
|
126
|
+
warnings.push(`El miembro ${agent.name} esta deshabilitado.`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const assignedAgent = localOrchestrator ?? leadAgent ?? null;
|
|
130
|
+
if (!assignedAgent) {
|
|
131
|
+
warnings.push('No hay agente asignable para este equipo.');
|
|
132
|
+
}
|
|
133
|
+
const assignedWorkspace = assignedAgent
|
|
134
|
+
? await getProviderWorkspaceById(assignedAgent.workspaceId)
|
|
135
|
+
: null;
|
|
136
|
+
const localOrchestratorWorkspace = localOrchestrator
|
|
137
|
+
? await getProviderWorkspaceById(localOrchestrator.workspaceId)
|
|
138
|
+
: null;
|
|
139
|
+
const leadAgentWorkspace = leadAgent
|
|
140
|
+
? await getProviderWorkspaceById(leadAgent.workspaceId)
|
|
141
|
+
: null;
|
|
142
|
+
contexts.push({
|
|
143
|
+
domainId: domain.id,
|
|
144
|
+
domainName: domain.domainName,
|
|
145
|
+
selectionMode: domain.selectionMode,
|
|
146
|
+
required: domain.required,
|
|
147
|
+
workspaceLabel,
|
|
148
|
+
workspaceEnabled,
|
|
149
|
+
localOrchestratorId: localOrchestrator?.id ?? null,
|
|
150
|
+
localOrchestratorLabel: localOrchestrator && localOrchestratorWorkspace
|
|
151
|
+
? buildAgentLabel(localOrchestratorWorkspace.provider, localOrchestrator.name)
|
|
152
|
+
: localOrchestrator?.name ?? null,
|
|
153
|
+
leadAgentId: leadAgent?.id ?? null,
|
|
154
|
+
leadAgentLabel: leadAgent && leadAgentWorkspace
|
|
155
|
+
? buildAgentLabel(leadAgentWorkspace.provider, leadAgent.name)
|
|
156
|
+
: leadAgent?.name ?? null,
|
|
157
|
+
assignedAgentId: assignedAgent?.id ?? null,
|
|
158
|
+
assignedAgentLabel: assignedAgent && assignedWorkspace
|
|
159
|
+
? buildAgentLabel(assignedWorkspace.provider, assignedAgent.name)
|
|
160
|
+
: assignedAgent?.name ?? null,
|
|
161
|
+
members,
|
|
162
|
+
validationWarnings: warnings,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
return contexts;
|
|
166
|
+
}
|
|
167
|
+
function buildGlobalSummary(goal, planSummary, contexts) {
|
|
168
|
+
const lines = [
|
|
169
|
+
`Objetivo: ${goal}`,
|
|
170
|
+
`Resumen global: ${planSummary}`,
|
|
171
|
+
`Equipos detectados: ${contexts.length}`,
|
|
172
|
+
'',
|
|
173
|
+
'Equipos planificados:',
|
|
174
|
+
];
|
|
175
|
+
for (const context of contexts) {
|
|
176
|
+
lines.push(`- ${context.domainName} -> workspace=${context.workspaceLabel} | assigned=${context.assignedAgentLabel ?? 'sin asignar'} | members=${context.members.length} | mode=${context.selectionMode}`);
|
|
177
|
+
}
|
|
178
|
+
return lines.join('\n');
|
|
179
|
+
}
|
|
180
|
+
function buildDomainInstructions(teamName, objective, context, squadPlanSummary) {
|
|
181
|
+
const lines = [
|
|
182
|
+
`Team: ${teamName}`,
|
|
183
|
+
`Equipo: ${context.domainName}`,
|
|
184
|
+
`Objetivo global: ${objective}`,
|
|
185
|
+
`Workspace: ${context.workspaceLabel}`,
|
|
186
|
+
`Modo de seleccion: ${context.selectionMode}`,
|
|
187
|
+
`Resumen del squad: ${squadPlanSummary}`,
|
|
188
|
+
'',
|
|
189
|
+
'Miembros del escuadron:',
|
|
190
|
+
];
|
|
191
|
+
if (context.members.length === 0) {
|
|
192
|
+
lines.push('- sin miembros');
|
|
193
|
+
lines.push('');
|
|
194
|
+
lines.push('Autonomia del escuadron:');
|
|
195
|
+
lines.push(`- El orquestador/lead del equipo ${context.domainName} debe asumir roles internos temporales segun la funcion principal del equipo.`);
|
|
196
|
+
lines.push('- Debe explicar que roles asumio, que hizo cada rol y que falta para completar el equipo.');
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
for (const member of context.members) {
|
|
200
|
+
lines.push(`- ${member.name} [${member.role}]${member.enabled ? '' : ' (disabled)'}`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (context.validationWarnings.length > 0) {
|
|
204
|
+
lines.push('');
|
|
205
|
+
lines.push('Advertencias:');
|
|
206
|
+
for (const warning of context.validationWarnings) {
|
|
207
|
+
lines.push(`- ${warning}`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
lines.push('');
|
|
211
|
+
lines.push('Fase 2 temprana: esta tarea representa la delegacion inicial persistida en SQLite; la ejecucion distribuida real llegara en una fase posterior.');
|
|
212
|
+
return lines.join('\n');
|
|
213
|
+
}
|
|
214
|
+
function formatIssues(prefix, issues) {
|
|
215
|
+
if (issues.length === 0) {
|
|
216
|
+
return [];
|
|
217
|
+
}
|
|
218
|
+
return issues.map(issue => `- ${prefix}: ${issue.severity} -> ${issue.message}`);
|
|
219
|
+
}
|
|
220
|
+
function buildConfigurationChecklist(teamName, contexts) {
|
|
221
|
+
const lines = [];
|
|
222
|
+
for (const context of contexts) {
|
|
223
|
+
if (!context.workspaceEnabled) {
|
|
224
|
+
lines.push(`- ${context.domainName}: habilita el workspace/proveedor antes de ejecutar.`);
|
|
225
|
+
}
|
|
226
|
+
if (!context.localOrchestratorId) {
|
|
227
|
+
lines.push(`- ${context.domainName}: falta orquestador local. Usa /team equipo ${teamName} ${context.domainName} <provider>/<agent>`);
|
|
228
|
+
}
|
|
229
|
+
if (!context.leadAgentId) {
|
|
230
|
+
lines.push(`- ${context.domainName}: falta lead. Usa /team equipo ${teamName} ${context.domainName} <provider>/<agent>`);
|
|
231
|
+
}
|
|
232
|
+
if (context.members.length === 0 && context.assignedAgentId) {
|
|
233
|
+
lines.push(`- ${context.domainName}: modo autonomo. ${context.assignedAgentLabel ?? 'el orquestador local'} asignara roles internos; miembros extra son opcionales.`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return lines;
|
|
237
|
+
}
|
|
238
|
+
async function planRun(args) {
|
|
239
|
+
const parsed = parseArgs(args);
|
|
240
|
+
if (!parsed) {
|
|
241
|
+
return { error: 'Uso: /orchestrate <team> <objetivo>' };
|
|
242
|
+
}
|
|
243
|
+
const team = await getTeamByName(parsed.teamName);
|
|
244
|
+
if (!team) {
|
|
245
|
+
return { error: `No existe el team ${parsed.teamName}.` };
|
|
246
|
+
}
|
|
247
|
+
if (!team.isEnabled) {
|
|
248
|
+
return { error: `El team ${team.name} esta deshabilitado.` };
|
|
249
|
+
}
|
|
250
|
+
if (!team.globalOrchestratorAgentId) {
|
|
251
|
+
return {
|
|
252
|
+
error: `El team ${team.name} no tiene orquestador global. Usa /team orchestrator primero.`,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
const globalAgent = await getProviderAgentById(team.globalOrchestratorAgentId);
|
|
256
|
+
if (!globalAgent) {
|
|
257
|
+
return { error: `El orquestador global configurado ya no existe para ${team.name}.` };
|
|
258
|
+
}
|
|
259
|
+
const globalWorkspace = await getProviderWorkspaceById(globalAgent.workspaceId);
|
|
260
|
+
const globalLabel = globalWorkspace
|
|
261
|
+
? `${globalWorkspace.provider}/${globalAgent.name}`
|
|
262
|
+
: globalAgent.name;
|
|
263
|
+
const domains = await listTeamDomains(team.id);
|
|
264
|
+
if (domains.length === 0) {
|
|
265
|
+
return {
|
|
266
|
+
error: `El team ${team.name} no tiene equipos configurados. Usa /team equipo primero.`,
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
const globalRuntime = createGlobalOrchestratorRuntime('phase-2-early');
|
|
270
|
+
const globalValidation = await globalRuntime.validate({
|
|
271
|
+
objective: parsed.objective,
|
|
272
|
+
scope: 'global',
|
|
273
|
+
context: `team:${team.name}`,
|
|
274
|
+
notes: `domains:${domains.length}`,
|
|
275
|
+
});
|
|
276
|
+
if (!globalValidation.valid) {
|
|
277
|
+
return {
|
|
278
|
+
error: [
|
|
279
|
+
`La orquestacion fue rechazada para ${team.name}.`,
|
|
280
|
+
...formatIssues('global', globalValidation.issues),
|
|
281
|
+
].join('\n'),
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
const domainContexts = await buildDomainContexts(team.id);
|
|
285
|
+
const configurationChecklist = buildConfigurationChecklist(team.name, domainContexts);
|
|
286
|
+
const globalPlan = await globalRuntime.plan({
|
|
287
|
+
objective: parsed.objective,
|
|
288
|
+
scope: 'global',
|
|
289
|
+
context: `team:${team.name}`,
|
|
290
|
+
notes: `domains:${domainContexts.length}`,
|
|
291
|
+
allowExecution: false,
|
|
292
|
+
});
|
|
293
|
+
const run = await createOrchestrationRun({
|
|
294
|
+
teamId: team.id,
|
|
295
|
+
goal: parsed.objective,
|
|
296
|
+
globalOrchestratorAgentId: globalAgent.id,
|
|
297
|
+
status: 'planned',
|
|
298
|
+
});
|
|
299
|
+
await createOrchestrationMessage({
|
|
300
|
+
runId: run.id,
|
|
301
|
+
fromAgentId: globalAgent.id,
|
|
302
|
+
messageType: 'global-plan',
|
|
303
|
+
content: buildGlobalSummary(parsed.objective, globalPlan.summary, domainContexts),
|
|
304
|
+
});
|
|
305
|
+
const taskSummaries = [];
|
|
306
|
+
let readyCount = 0;
|
|
307
|
+
let blockedCount = 0;
|
|
308
|
+
const validationWarnings = [...formatIssues('global', globalValidation.issues)];
|
|
309
|
+
for (const context of domainContexts) {
|
|
310
|
+
const squadRuntime = createSquadOrchestratorRuntime(context.members);
|
|
311
|
+
const squadValidation = await squadRuntime.validate({
|
|
312
|
+
objective: parsed.objective,
|
|
313
|
+
squadName: context.domainName,
|
|
314
|
+
members: context.members,
|
|
315
|
+
scope: 'squad',
|
|
316
|
+
context: `team:${team.name};domain:${context.domainName}`,
|
|
317
|
+
});
|
|
318
|
+
const squadPlan = await squadRuntime.plan({
|
|
319
|
+
objective: parsed.objective,
|
|
320
|
+
squadName: context.domainName,
|
|
321
|
+
members: context.members,
|
|
322
|
+
scope: 'squad',
|
|
323
|
+
context: `team:${team.name};domain:${context.domainName}`,
|
|
324
|
+
allowExecution: false,
|
|
325
|
+
});
|
|
326
|
+
const taskStatus = context.assignedAgentId && context.workspaceEnabled && squadValidation.valid
|
|
327
|
+
? 'ready'
|
|
328
|
+
: 'blocked';
|
|
329
|
+
if (taskStatus === 'ready') {
|
|
330
|
+
readyCount += 1;
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
blockedCount += 1;
|
|
334
|
+
}
|
|
335
|
+
const task = await createOrchestrationTask({
|
|
336
|
+
runId: run.id,
|
|
337
|
+
scopeType: 'domain',
|
|
338
|
+
teamDomainId: context.domainId,
|
|
339
|
+
assignedAgentId: context.assignedAgentId,
|
|
340
|
+
title: `Equipo ${context.domainName}`,
|
|
341
|
+
instructions: buildDomainInstructions(team.name, parsed.objective, context, squadPlan.summary),
|
|
342
|
+
status: taskStatus,
|
|
343
|
+
resultSummary: taskStatus === 'blocked'
|
|
344
|
+
? 'Pendiente por validacion/configuracion del equipo.'
|
|
345
|
+
: 'Delegacion inicial preparada.',
|
|
346
|
+
});
|
|
347
|
+
await createOrchestrationMessage({
|
|
348
|
+
runId: run.id,
|
|
349
|
+
taskId: task.id,
|
|
350
|
+
fromAgentId: globalAgent.id,
|
|
351
|
+
toAgentId: context.assignedAgentId,
|
|
352
|
+
messageType: 'squad-plan',
|
|
353
|
+
content: [
|
|
354
|
+
`Equipo: ${context.domainName}`,
|
|
355
|
+
`Asignado: ${context.assignedAgentLabel ?? 'sin asignar'}`,
|
|
356
|
+
`Resumen: ${squadPlan.summary}`,
|
|
357
|
+
'',
|
|
358
|
+
...context.validationWarnings.map(warning => `- ${warning}`),
|
|
359
|
+
...formatIssues('squad', squadValidation.issues),
|
|
360
|
+
]
|
|
361
|
+
.filter(Boolean)
|
|
362
|
+
.join('\n'),
|
|
363
|
+
});
|
|
364
|
+
validationWarnings.push(...context.validationWarnings.map(warning => `- ${context.domainName}: warning -> ${warning}`), ...formatIssues(context.domainName, squadValidation.issues));
|
|
365
|
+
taskSummaries.push(`- ${context.domainName} -> ${task.status} | assigned=${context.assignedAgentLabel ?? 'sin asignar'} | task=${task.id}`);
|
|
366
|
+
}
|
|
367
|
+
return {
|
|
368
|
+
ok: {
|
|
369
|
+
run,
|
|
370
|
+
team,
|
|
371
|
+
globalLabel,
|
|
372
|
+
taskSummaries,
|
|
373
|
+
validationWarnings,
|
|
374
|
+
configurationChecklist,
|
|
375
|
+
hasReadyTasks: readyCount > 0,
|
|
376
|
+
hasBlockedTasks: blockedCount > 0,
|
|
377
|
+
readyCount,
|
|
378
|
+
blockedCount,
|
|
379
|
+
domainContexts,
|
|
380
|
+
},
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
function buildPlanOnlyMessage(plan) {
|
|
384
|
+
const lines = [
|
|
385
|
+
`Ejecucion creada: ${plan.run.id}`,
|
|
386
|
+
`Team: ${plan.team.name}`,
|
|
387
|
+
`Objetivo: ${plan.run.goal}`,
|
|
388
|
+
`Orquestador global: ${plan.globalLabel}`,
|
|
389
|
+
`Estado inicial: ${plan.run.status}`,
|
|
390
|
+
'',
|
|
391
|
+
'Tareas por equipo:',
|
|
392
|
+
...plan.taskSummaries,
|
|
393
|
+
];
|
|
394
|
+
if (plan.validationWarnings.length > 0) {
|
|
395
|
+
lines.push('', 'Advertencias y validaciones:');
|
|
396
|
+
lines.push(...plan.validationWarnings);
|
|
397
|
+
}
|
|
398
|
+
if (plan.configurationChecklist.length > 0) {
|
|
399
|
+
lines.push('', 'Estado de configuracion del equipo:');
|
|
400
|
+
lines.push(...plan.configurationChecklist);
|
|
401
|
+
}
|
|
402
|
+
lines.push('', 'Siguientes pasos:');
|
|
403
|
+
lines.push(`- Revisar plan: /run show ${plan.run.id}`);
|
|
404
|
+
if (plan.hasReadyTasks) {
|
|
405
|
+
lines.push(`- Ejecutar tareas listas: /run resume ${plan.run.id}`);
|
|
406
|
+
}
|
|
407
|
+
if (plan.hasBlockedTasks) {
|
|
408
|
+
lines.push(`- Si hay equipos blocked, asigna un agente con /team equipo <team> <equipo> <provider>/<agent> y luego usa /run retry ${plan.run.id}`);
|
|
409
|
+
}
|
|
410
|
+
return lines.join('\n');
|
|
411
|
+
}
|
|
412
|
+
function buildExecutionReport(plan, finalRun, finalTasks, finalMessages, errorMessage) {
|
|
413
|
+
const counts = {};
|
|
414
|
+
for (const task of finalTasks) {
|
|
415
|
+
counts[task.status] = (counts[task.status] ?? 0) + 1;
|
|
416
|
+
}
|
|
417
|
+
const countsLine = Object.entries(counts)
|
|
418
|
+
.map(([status, n]) => `${status}=${n}`)
|
|
419
|
+
.sort()
|
|
420
|
+
.join(' | ');
|
|
421
|
+
const lines = [
|
|
422
|
+
`Ejecucion finalizada: ${finalRun.id}`,
|
|
423
|
+
`Team: ${plan.team.name}`,
|
|
424
|
+
`Objetivo: ${finalRun.goal}`,
|
|
425
|
+
`Estado final: ${finalRun.status}`,
|
|
426
|
+
`Resumen tareas: ${countsLine || 'sin tareas'}`,
|
|
427
|
+
];
|
|
428
|
+
const reportMessages = finalMessages
|
|
429
|
+
.filter(message => ['run-report', 'task.completed', 'domain-report', 'global.consolidated-report'].includes(message.messageType))
|
|
430
|
+
.slice(-10);
|
|
431
|
+
if (reportMessages.length > 0) {
|
|
432
|
+
lines.push('', 'Reportes y Resultados:');
|
|
433
|
+
for (const message of reportMessages) {
|
|
434
|
+
if (message.messageType === 'global.consolidated-report') {
|
|
435
|
+
lines.push(`\n[REPORTE EJECUTIVO]`);
|
|
436
|
+
lines.push(message.content);
|
|
437
|
+
}
|
|
438
|
+
else {
|
|
439
|
+
const head = message.content.split('\n').slice(0, 4).join('\n');
|
|
440
|
+
lines.push(`- [${message.messageType}] ${head}${message.content.split('\n').length > 4 ? '...' : ''}`);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
if (errorMessage) {
|
|
445
|
+
lines.push('', `❌ Error durante la ejecucion: ${errorMessage}`);
|
|
446
|
+
}
|
|
447
|
+
lines.push('', `Siguientes pasos: /run show ${finalRun.id} | /run messages ${finalRun.id} | /run task <task-id>`);
|
|
448
|
+
return lines.join('\n');
|
|
449
|
+
}
|
|
450
|
+
function buildInitialDomainExecutionView(plan) {
|
|
451
|
+
return plan.domainContexts.map(context => {
|
|
452
|
+
const isReady = Boolean(context.assignedAgentId && context.workspaceEnabled);
|
|
453
|
+
return {
|
|
454
|
+
domainName: context.domainName,
|
|
455
|
+
agentLabel: context.assignedAgentLabel ?? 'sin asignar',
|
|
456
|
+
status: isReady ? 'waiting' : 'blocked',
|
|
457
|
+
detail: isReady
|
|
458
|
+
? 'en espera de ejecucion'
|
|
459
|
+
: context.validationWarnings[0] ?? 'requiere configuracion',
|
|
460
|
+
progressPercent: 0,
|
|
461
|
+
};
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
function toDomainStatus(phase) {
|
|
465
|
+
switch (phase) {
|
|
466
|
+
case 'dispatching':
|
|
467
|
+
return 'dispatching';
|
|
468
|
+
case 'executing':
|
|
469
|
+
return 'executing';
|
|
470
|
+
case 'completed':
|
|
471
|
+
return 'completed';
|
|
472
|
+
case 'failed':
|
|
473
|
+
return 'failed';
|
|
474
|
+
case 'blocked':
|
|
475
|
+
return 'blocked';
|
|
476
|
+
default:
|
|
477
|
+
return 'waiting';
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
function formatDomainStatus(status) {
|
|
481
|
+
switch (status) {
|
|
482
|
+
case 'waiting':
|
|
483
|
+
return 'en cola';
|
|
484
|
+
case 'dispatching':
|
|
485
|
+
return 'asignando';
|
|
486
|
+
case 'executing':
|
|
487
|
+
return 'trabajando';
|
|
488
|
+
case 'completed':
|
|
489
|
+
return 'terminado';
|
|
490
|
+
case 'failed':
|
|
491
|
+
return 'fallo';
|
|
492
|
+
case 'blocked':
|
|
493
|
+
return 'bloqueado';
|
|
494
|
+
case 'skipped':
|
|
495
|
+
return 'omitido';
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
function statusColor(status) {
|
|
499
|
+
switch (status) {
|
|
500
|
+
case 'completed':
|
|
501
|
+
return 'green';
|
|
502
|
+
case 'dispatching':
|
|
503
|
+
case 'executing':
|
|
504
|
+
return 'cyan';
|
|
505
|
+
case 'blocked':
|
|
506
|
+
case 'skipped':
|
|
507
|
+
return 'yellow';
|
|
508
|
+
case 'failed':
|
|
509
|
+
return 'red';
|
|
510
|
+
default:
|
|
511
|
+
return undefined;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
function PlanReview({ plan, onDone, context, }) {
|
|
515
|
+
const [phase, setPhase] = React.useState('review');
|
|
516
|
+
const [progress, setProgress] = React.useState(null);
|
|
517
|
+
const [domainStates, setDomainStates] = React.useState(() => buildInitialDomainExecutionView(plan));
|
|
518
|
+
const [messages, setMessages] = React.useState([]);
|
|
519
|
+
const [error, setError] = React.useState(null);
|
|
520
|
+
const [finalReport, setFinalReport] = React.useState(null);
|
|
521
|
+
React.useEffect(() => {
|
|
522
|
+
if (phase !== 'executing')
|
|
523
|
+
return;
|
|
524
|
+
let cancelled = false;
|
|
525
|
+
void (async () => {
|
|
526
|
+
let errorMessage = null;
|
|
527
|
+
try {
|
|
528
|
+
await resumeOrchestrationRun(plan.run.id, {
|
|
529
|
+
onProgress: event => {
|
|
530
|
+
if (cancelled)
|
|
531
|
+
return;
|
|
532
|
+
const nextProgress = {
|
|
533
|
+
taskId: event.taskId,
|
|
534
|
+
phase: event.phase,
|
|
535
|
+
domainName: event.domainName,
|
|
536
|
+
agentLabel: event.agentLabel,
|
|
537
|
+
detail: event.detail,
|
|
538
|
+
output: event.output,
|
|
539
|
+
progressPercent: event.progressPercent,
|
|
540
|
+
};
|
|
541
|
+
setProgress(nextProgress);
|
|
542
|
+
context.setAppState(prev => ({
|
|
543
|
+
...prev,
|
|
544
|
+
orchestrationActivity: {
|
|
545
|
+
runId: plan.run.id,
|
|
546
|
+
teamName: plan.team.name,
|
|
547
|
+
domainName: event.domainName ?? undefined,
|
|
548
|
+
agentLabel: event.agentLabel ?? undefined,
|
|
549
|
+
phase: event.phase,
|
|
550
|
+
detail: event.detail ?? undefined,
|
|
551
|
+
progressPercent: event.progressPercent ?? undefined,
|
|
552
|
+
updatedAt: Date.now(),
|
|
553
|
+
}
|
|
554
|
+
}));
|
|
555
|
+
if (event.output) {
|
|
556
|
+
setMessages(prev => [
|
|
557
|
+
...prev,
|
|
558
|
+
{
|
|
559
|
+
agent: event.agentLabel || event.domainName || 'Sistema',
|
|
560
|
+
content: event.output,
|
|
561
|
+
},
|
|
562
|
+
]);
|
|
563
|
+
}
|
|
564
|
+
if (event.domainName) {
|
|
565
|
+
setDomainStates(prev => prev.map(domain => {
|
|
566
|
+
if (domain.domainName !== event.domainName) {
|
|
567
|
+
return domain;
|
|
568
|
+
}
|
|
569
|
+
return {
|
|
570
|
+
...domain,
|
|
571
|
+
agentLabel: event.agentLabel ?? domain.agentLabel,
|
|
572
|
+
status: toDomainStatus(event.phase),
|
|
573
|
+
detail: event.detail ?? domain.detail,
|
|
574
|
+
progressPercent: event.progressPercent == null
|
|
575
|
+
? domain.progressPercent
|
|
576
|
+
: Math.round(event.progressPercent),
|
|
577
|
+
};
|
|
578
|
+
}));
|
|
579
|
+
}
|
|
580
|
+
},
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
catch (e) {
|
|
584
|
+
errorMessage = e instanceof Error ? e.message : String(e);
|
|
585
|
+
if (!cancelled) {
|
|
586
|
+
setError(errorMessage);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
if (cancelled)
|
|
590
|
+
return;
|
|
591
|
+
try {
|
|
592
|
+
const [finalTasks, finalMessages, finalRun] = await Promise.all([
|
|
593
|
+
listOrchestrationTasks(plan.run.id),
|
|
594
|
+
listOrchestrationMessages(plan.run.id),
|
|
595
|
+
getOrchestrationRunById(plan.run.id),
|
|
596
|
+
]);
|
|
597
|
+
const report = buildExecutionReport(plan, finalRun ?? plan.run, finalTasks, finalMessages, errorMessage);
|
|
598
|
+
setFinalReport(report);
|
|
599
|
+
context.setAppState(prev => ({
|
|
600
|
+
...prev,
|
|
601
|
+
orchestrationActivity: {
|
|
602
|
+
runId: plan.run.id,
|
|
603
|
+
teamName: plan.team.name,
|
|
604
|
+
phase: 'finished',
|
|
605
|
+
detail: 'ejecucion finalizada',
|
|
606
|
+
progressPercent: 100,
|
|
607
|
+
updatedAt: Date.now(),
|
|
608
|
+
}
|
|
609
|
+
}));
|
|
610
|
+
// Indexar en SessionMemory para persistencia histórica
|
|
611
|
+
if (context.messages && context.toolUseContext) {
|
|
612
|
+
const runMsg = `Ejecución de orquestación finalizada: ${plan.run.id}. Objetivo: ${plan.run.goal}. Resultado: ${finalRun?.status ?? 'desconocido'}.`;
|
|
613
|
+
const reportMsg = `Reporte consolidado:\n${report}`;
|
|
614
|
+
const virtualMessages = [
|
|
615
|
+
...context.messages,
|
|
616
|
+
createUserMessage({ content: `/orchestrate ${plan.team.name} ${plan.run.goal}` }),
|
|
617
|
+
createAssistantMessage({ content: runMsg }),
|
|
618
|
+
createAssistantMessage({ content: reportMsg })
|
|
619
|
+
];
|
|
620
|
+
void manuallyExtractSessionMemory(virtualMessages, context.toolUseContext).catch(err => {
|
|
621
|
+
console.error('Error al indexar reporte en SessionMemory:', err);
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
setPhase('finished');
|
|
625
|
+
}
|
|
626
|
+
catch (e) {
|
|
627
|
+
setPhase('done');
|
|
628
|
+
const fallbackErr = e instanceof Error ? e.message : String(e);
|
|
629
|
+
onDone([
|
|
630
|
+
buildPlanOnlyMessage(plan),
|
|
631
|
+
'',
|
|
632
|
+
`No se pudo recolectar el reporte final: ${fallbackErr}`,
|
|
633
|
+
errorMessage ? `Error de ejecucion previo: ${errorMessage}` : null,
|
|
634
|
+
]
|
|
635
|
+
.filter(Boolean)
|
|
636
|
+
.join('\n'));
|
|
637
|
+
}
|
|
638
|
+
})();
|
|
639
|
+
return () => {
|
|
640
|
+
cancelled = true;
|
|
641
|
+
};
|
|
642
|
+
}, [phase, plan, context]);
|
|
643
|
+
// Lifecycle management for global activity state (signals and global AppState)
|
|
644
|
+
React.useEffect(() => {
|
|
645
|
+
activityManager.startCLIActivity('orchestration_execution');
|
|
646
|
+
return () => {
|
|
647
|
+
logForDebugging('PlanReview lifecycle effect cleanup: ending CLI activity and clearing orchestrationActivity');
|
|
648
|
+
activityManager.endCLIActivity('orchestration_execution');
|
|
649
|
+
context.setAppState(prev => ({
|
|
650
|
+
...prev,
|
|
651
|
+
orchestrationActivity: undefined
|
|
652
|
+
}));
|
|
653
|
+
};
|
|
654
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
655
|
+
}, [context.setAppState]);
|
|
656
|
+
useInput((_input, key) => {
|
|
657
|
+
if (phase === 'review') {
|
|
658
|
+
if (key.return) {
|
|
659
|
+
setDomainStates(buildInitialDomainExecutionView(plan));
|
|
660
|
+
setProgress(null);
|
|
661
|
+
setError(null);
|
|
662
|
+
setPhase('executing');
|
|
663
|
+
}
|
|
664
|
+
else if (key.escape) {
|
|
665
|
+
onDone(buildPlanOnlyMessage(plan));
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
else if (phase === 'finished') {
|
|
669
|
+
if (key.return || key.escape) {
|
|
670
|
+
setPhase('done');
|
|
671
|
+
onDone(finalReport || 'Ejecucion completada.');
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
}, { isActive: phase === 'review' || phase === 'finished' });
|
|
675
|
+
if (phase === 'review') {
|
|
676
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { bold: true, children: ["Plan listo para ", plan.team.name] }), _jsxs(Text, { children: ["Ejecucion: ", plan.run.id] }), _jsxs(Text, { children: ["Objetivo: ", plan.run.goal] }), _jsxs(Text, { children: ["Orquestador global: ", plan.globalLabel] }), _jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsx(Text, { bold: true, children: "Tareas por equipo" }), plan.taskSummaries.map((line, i) => (_jsx(Text, { children: line }, i)))] }), _jsx(Box, { marginTop: 1, flexDirection: "column", children: _jsxs(Text, { children: ["Listas: ", _jsx(Text, { color: "green", children: plan.readyCount }), " | Bloqueadas:", ' ', _jsx(Text, { color: plan.blockedCount > 0 ? 'yellow' : undefined, children: plan.blockedCount })] }) }), plan.validationWarnings.length > 0 ? (_jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsx(Text, { bold: true, color: "yellow", children: "Advertencias" }), plan.validationWarnings.map((line, i) => (_jsx(Text, { color: "yellow", children: line }, i)))] })) : null, plan.configurationChecklist.length > 0 ? (_jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsx(Text, { bold: true, children: "Estado de configuracion" }), plan.configurationChecklist.map((line, i) => (_jsx(Text, { children: line }, i)))] })) : null, _jsx(Box, { marginTop: 1, children: _jsxs(Text, { dimColor: true, children: ["[Enter] Ejecutar ahora", plan.hasBlockedTasks ? ' (las bloqueadas se omiten)' : '', " | [Esc] Solo planificar"] }) })] }));
|
|
677
|
+
}
|
|
678
|
+
if (phase === 'executing') {
|
|
679
|
+
const progressLine = progress
|
|
680
|
+
? [
|
|
681
|
+
progress.phase,
|
|
682
|
+
progress.domainName ? `equipo=${progress.domainName}` : null,
|
|
683
|
+
progress.agentLabel ? `agente=${progress.agentLabel}` : null,
|
|
684
|
+
progress.detail,
|
|
685
|
+
progress.progressPercent != null ? `${Math.round(progress.progressPercent)}%` : null,
|
|
686
|
+
]
|
|
687
|
+
.filter(Boolean)
|
|
688
|
+
.join(' | ')
|
|
689
|
+
: 'preparando ejecucion...';
|
|
690
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { bold: true, children: ["Ejecutando orquestacion ", plan.run.id] }), _jsxs(Text, { children: ["Team: ", plan.team.name] }), _jsx(Text, { children: progressLine }), _jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsx(Text, { bold: true, underline: true, children: "Equipos y agentes" }), domainStates.map(domain => (_jsxs(Text, { color: statusColor(domain.status), children: [domain.domainName.padEnd(12), " | ", formatDomainStatus(domain.status).padEnd(10), " | ", domain.progressPercent.toString().padStart(3), "% | ", domain.agentLabel] }, domain.domainName)))] }), messages.length > 0 && (_jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsx(Text, { bold: true, underline: true, children: "Actividad del Swarm (ultimos mensajes)" }), messages.slice(-5).map((msg, i) => (_jsxs(Box, { flexDirection: "column", paddingLeft: 1, marginBottom: 1, children: [_jsxs(Text, { bold: true, color: "cyan", children: ["[", msg.agent, "]"] }), _jsx(Text, { dimColor: true, children: msg.content.length > 200 ? msg.content.substring(0, 200) + '...' : msg.content })] }, i)))] })), _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: "La ejecucion avanza por equipos listos; las tareas bloqueadas quedan para corregir y reintentar." }) }), error ? _jsxs(Text, { color: "red", children: ["Error: ", error] }) : null] }));
|
|
691
|
+
}
|
|
692
|
+
if (phase === 'finished') {
|
|
693
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, color: "green", children: "\u00A1Orquestacion Finalizada!" }), _jsxs(Text, { children: ["Team: ", plan.team.name] }), _jsx(Box, { marginTop: 1, padding: 1, borderStyle: "round", borderColor: "green", children: _jsx(Text, { children: finalReport }) }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: "[Enter/Esc] Salir y volver al prompt" }) })] }));
|
|
694
|
+
}
|
|
695
|
+
return (_jsx(Box, { flexDirection: "column", children: _jsxs(Text, { children: ["Ejecucion ", plan.run.id, " terminada."] }) }));
|
|
696
|
+
}
|
|
697
|
+
export const call = async (onDone, _context, args) => {
|
|
698
|
+
const result = await planRun(args ?? '');
|
|
699
|
+
if ('error' in result) {
|
|
700
|
+
onDone(result.error);
|
|
701
|
+
return null;
|
|
702
|
+
}
|
|
703
|
+
const plan = result.ok;
|
|
704
|
+
if (!plan.hasReadyTasks) {
|
|
705
|
+
onDone(buildPlanOnlyMessage(plan));
|
|
706
|
+
return null;
|
|
707
|
+
}
|
|
708
|
+
return _jsx(PlanReview, { plan: plan, onDone: onDone, context: _context });
|
|
709
|
+
};
|