attocode 0.1.2 → 0.1.4
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/CHANGELOG.md +51 -1
- package/README.md +180 -0
- package/dist/src/agent.d.ts +78 -1
- package/dist/src/agent.d.ts.map +1 -1
- package/dist/src/agent.js +639 -36
- package/dist/src/agent.js.map +1 -1
- package/dist/src/analysis/feedback-loop.d.ts +115 -0
- package/dist/src/analysis/feedback-loop.d.ts.map +1 -0
- package/dist/src/analysis/feedback-loop.js +226 -0
- package/dist/src/analysis/feedback-loop.js.map +1 -0
- package/dist/src/analysis/index.d.ts +9 -0
- package/dist/src/analysis/index.d.ts.map +1 -0
- package/dist/src/analysis/index.js +9 -0
- package/dist/src/analysis/index.js.map +1 -0
- package/dist/src/analysis/prompt-templates.d.ts +36 -0
- package/dist/src/analysis/prompt-templates.d.ts.map +1 -0
- package/dist/src/analysis/prompt-templates.js +198 -0
- package/dist/src/analysis/prompt-templates.js.map +1 -0
- package/dist/src/analysis/trace-summary.d.ts +56 -0
- package/dist/src/analysis/trace-summary.d.ts.map +1 -0
- package/dist/src/analysis/trace-summary.js +261 -0
- package/dist/src/analysis/trace-summary.js.map +1 -0
- package/dist/src/commands/agents-commands.d.ts +24 -0
- package/dist/src/commands/agents-commands.d.ts.map +1 -0
- package/dist/src/commands/agents-commands.js +284 -0
- package/dist/src/commands/agents-commands.js.map +1 -0
- package/dist/src/commands/handler.d.ts.map +1 -1
- package/dist/src/commands/handler.js +329 -21
- package/dist/src/commands/handler.js.map +1 -1
- package/dist/src/commands/init-commands.d.ts +35 -0
- package/dist/src/commands/init-commands.d.ts.map +1 -0
- package/dist/src/commands/init-commands.js +187 -0
- package/dist/src/commands/init-commands.js.map +1 -0
- package/dist/src/commands/skills-commands.d.ts +26 -0
- package/dist/src/commands/skills-commands.d.ts.map +1 -0
- package/dist/src/commands/skills-commands.js +309 -0
- package/dist/src/commands/skills-commands.js.map +1 -0
- package/dist/src/commands/types.d.ts +13 -2
- package/dist/src/commands/types.d.ts.map +1 -1
- package/dist/src/config.d.ts +3 -0
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js.map +1 -1
- package/dist/src/defaults.d.ts +31 -2
- package/dist/src/defaults.d.ts.map +1 -1
- package/dist/src/defaults.js +69 -2
- package/dist/src/defaults.js.map +1 -1
- package/dist/src/errors/index.d.ts +233 -0
- package/dist/src/errors/index.d.ts.map +1 -0
- package/dist/src/errors/index.js +427 -0
- package/dist/src/errors/index.js.map +1 -0
- package/dist/src/integrations/agent-registry.d.ts +68 -2
- package/dist/src/integrations/agent-registry.d.ts.map +1 -1
- package/dist/src/integrations/agent-registry.js +230 -23
- package/dist/src/integrations/agent-registry.js.map +1 -1
- package/dist/src/integrations/auto-compaction.d.ts +33 -0
- package/dist/src/integrations/auto-compaction.d.ts.map +1 -1
- package/dist/src/integrations/auto-compaction.js +47 -3
- package/dist/src/integrations/auto-compaction.js.map +1 -1
- package/dist/src/integrations/cancellation.d.ts +5 -0
- package/dist/src/integrations/cancellation.d.ts.map +1 -1
- package/dist/src/integrations/cancellation.js +7 -0
- package/dist/src/integrations/cancellation.js.map +1 -1
- package/dist/src/integrations/capabilities.d.ts +160 -0
- package/dist/src/integrations/capabilities.d.ts.map +1 -0
- package/dist/src/integrations/capabilities.js +426 -0
- package/dist/src/integrations/capabilities.js.map +1 -0
- package/dist/src/integrations/context-engineering.d.ts +6 -1
- package/dist/src/integrations/context-engineering.d.ts.map +1 -1
- package/dist/src/integrations/context-engineering.js +7 -0
- package/dist/src/integrations/context-engineering.js.map +1 -1
- package/dist/src/integrations/dead-letter-queue.d.ts +208 -0
- package/dist/src/integrations/dead-letter-queue.d.ts.map +1 -0
- package/dist/src/integrations/dead-letter-queue.js +458 -0
- package/dist/src/integrations/dead-letter-queue.js.map +1 -0
- package/dist/src/integrations/health-check.d.ts +218 -0
- package/dist/src/integrations/health-check.d.ts.map +1 -0
- package/dist/src/integrations/health-check.js +400 -0
- package/dist/src/integrations/health-check.js.map +1 -0
- package/dist/src/integrations/index.d.ts +11 -2
- package/dist/src/integrations/index.d.ts.map +1 -1
- package/dist/src/integrations/index.js +19 -2
- package/dist/src/integrations/index.js.map +1 -1
- package/dist/src/integrations/mcp-client.d.ts +9 -0
- package/dist/src/integrations/mcp-client.d.ts.map +1 -1
- package/dist/src/integrations/mcp-client.js +49 -7
- package/dist/src/integrations/mcp-client.js.map +1 -1
- package/dist/src/integrations/openrouter-pricing.d.ts +28 -3
- package/dist/src/integrations/openrouter-pricing.d.ts.map +1 -1
- package/dist/src/integrations/openrouter-pricing.js +57 -16
- package/dist/src/integrations/openrouter-pricing.js.map +1 -1
- package/dist/src/integrations/retry.d.ts +131 -0
- package/dist/src/integrations/retry.d.ts.map +1 -0
- package/dist/src/integrations/retry.js +233 -0
- package/dist/src/integrations/retry.js.map +1 -0
- package/dist/src/integrations/skill-executor.d.ts +113 -0
- package/dist/src/integrations/skill-executor.d.ts.map +1 -0
- package/dist/src/integrations/skill-executor.js +270 -0
- package/dist/src/integrations/skill-executor.js.map +1 -0
- package/dist/src/integrations/skills.d.ts +98 -7
- package/dist/src/integrations/skills.d.ts.map +1 -1
- package/dist/src/integrations/skills.js +210 -11
- package/dist/src/integrations/skills.js.map +1 -1
- package/dist/src/integrations/sqlite-store.d.ts +42 -0
- package/dist/src/integrations/sqlite-store.d.ts.map +1 -1
- package/dist/src/integrations/sqlite-store.js +111 -0
- package/dist/src/integrations/sqlite-store.js.map +1 -1
- package/dist/src/main.js +88 -7
- package/dist/src/main.js.map +1 -1
- package/dist/src/modes/repl.d.ts.map +1 -1
- package/dist/src/modes/repl.js +37 -1
- package/dist/src/modes/repl.js.map +1 -1
- package/dist/src/modes/tui.d.ts.map +1 -1
- package/dist/src/modes/tui.js +46 -5
- package/dist/src/modes/tui.js.map +1 -1
- package/dist/src/modes.d.ts.map +1 -1
- package/dist/src/modes.js +10 -3
- package/dist/src/modes.js.map +1 -1
- package/dist/src/persistence/schema.d.ts +4 -0
- package/dist/src/persistence/schema.d.ts.map +1 -1
- package/dist/src/persistence/schema.js +49 -0
- package/dist/src/persistence/schema.js.map +1 -1
- package/dist/src/providers/adapters/anthropic.d.ts +24 -2
- package/dist/src/providers/adapters/anthropic.d.ts.map +1 -1
- package/dist/src/providers/adapters/anthropic.js +184 -0
- package/dist/src/providers/adapters/anthropic.js.map +1 -1
- package/dist/src/tools/bash.d.ts.map +1 -1
- package/dist/src/tools/bash.js +7 -4
- package/dist/src/tools/bash.js.map +1 -1
- package/dist/src/tools/file.d.ts.map +1 -1
- package/dist/src/tools/file.js +31 -10
- package/dist/src/tools/file.js.map +1 -1
- package/dist/src/tools/permission.d.ts +12 -0
- package/dist/src/tools/permission.d.ts.map +1 -1
- package/dist/src/tools/permission.js +136 -0
- package/dist/src/tools/permission.js.map +1 -1
- package/dist/src/tools/registry.d.ts +23 -1
- package/dist/src/tools/registry.d.ts.map +1 -1
- package/dist/src/tools/registry.js +77 -17
- package/dist/src/tools/registry.js.map +1 -1
- package/dist/src/tools/standard.d.ts.map +1 -1
- package/dist/src/tools/standard.js +8 -0
- package/dist/src/tools/standard.js.map +1 -1
- package/dist/src/tools/types.d.ts +20 -1
- package/dist/src/tools/types.d.ts.map +1 -1
- package/dist/src/tools/types.js.map +1 -1
- package/dist/src/tracing/trace-collector.d.ts +198 -2
- package/dist/src/tracing/trace-collector.d.ts.map +1 -1
- package/dist/src/tracing/trace-collector.js +315 -3
- package/dist/src/tracing/trace-collector.js.map +1 -1
- package/dist/src/tracing/types.d.ts +470 -2
- package/dist/src/tracing/types.d.ts.map +1 -1
- package/dist/src/tracing/types.js +25 -0
- package/dist/src/tracing/types.js.map +1 -1
- package/dist/src/tui/app.d.ts.map +1 -1
- package/dist/src/tui/app.js +292 -18
- package/dist/src/tui/app.js.map +1 -1
- package/dist/src/tui/index.d.ts +1 -0
- package/dist/src/tui/index.d.ts.map +1 -1
- package/dist/src/tui/index.js +2 -0
- package/dist/src/tui/index.js.map +1 -1
- package/dist/src/tui/transparency-aggregator.d.ts +100 -0
- package/dist/src/tui/transparency-aggregator.d.ts.map +1 -0
- package/dist/src/tui/transparency-aggregator.js +234 -0
- package/dist/src/tui/transparency-aggregator.js.map +1 -0
- package/dist/src/types.d.ts +129 -0
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +6 -3
- package/dist/src/hello.d.ts +0 -2
- package/dist/src/hello.d.ts.map +0 -1
- package/dist/src/hello.js +0 -4
- package/dist/src/hello.js.map +0 -1
- package/dist/src/test-sqlite.d.ts +0 -2
- package/dist/src/test-sqlite.d.ts.map +0 -1
- package/dist/src/test-sqlite.js +0 -114
- package/dist/src/test-sqlite.js.map +0 -1
|
@@ -5,8 +5,11 @@
|
|
|
5
5
|
* Uses CommandContext.output for all output, making it mode-agnostic.
|
|
6
6
|
*/
|
|
7
7
|
import { persistenceDebug, saveCheckpointToStore, } from '../integrations/persistence.js';
|
|
8
|
-
import { formatServerList, getContextUsage, formatCompactionResult } from '../integrations/index.js';
|
|
8
|
+
import { formatServerList, getContextUsage, formatCompactionResult, formatCapabilitiesSummary, formatCapabilitiesList, formatSearchResults, } from '../integrations/index.js';
|
|
9
9
|
import { formatSessionsTable } from '../session-picker.js';
|
|
10
|
+
import { handleSkillsCommand } from './skills-commands.js';
|
|
11
|
+
import { handleAgentsCommand } from './agents-commands.js';
|
|
12
|
+
import { handleInitCommand } from './init-commands.js';
|
|
10
13
|
// =============================================================================
|
|
11
14
|
// ANSI COLOR UTILITIES
|
|
12
15
|
// =============================================================================
|
|
@@ -103,8 +106,29 @@ ${c('PERMISSIONS & SECURITY', 'bold')}
|
|
|
103
106
|
${c('/grants', 'cyan')} Show active permission grants
|
|
104
107
|
${c('/audit', 'cyan')} Show security audit log
|
|
105
108
|
|
|
106
|
-
${c('
|
|
107
|
-
${c('/skills', 'cyan')} List
|
|
109
|
+
${c('SKILLS & AGENTS', 'bold')}
|
|
110
|
+
${c('/skills', 'cyan')} List all skills with usage hints
|
|
111
|
+
${c('/skills new <name>', 'cyan')} Create a new skill in .attocode/skills/
|
|
112
|
+
${c('/skills info <name>', 'cyan')} Show detailed skill information
|
|
113
|
+
${c('/skills enable/disable', 'cyan')} Activate or deactivate a skill
|
|
114
|
+
${c('/agents', 'cyan')} List all available agents
|
|
115
|
+
${c('/agents new <name>', 'cyan')} Create a new agent in .attocode/agents/
|
|
116
|
+
${c('/agents info <name>', 'cyan')} Show detailed agent information
|
|
117
|
+
|
|
118
|
+
${c('INITIALIZATION', 'bold')}
|
|
119
|
+
${c('/init', 'cyan')} Initialize .attocode/ directory structure
|
|
120
|
+
|
|
121
|
+
${c('TRACE ANALYSIS', 'bold')}
|
|
122
|
+
${c('/trace', 'cyan')} Show current session trace summary
|
|
123
|
+
${c('/trace --analyze', 'cyan')} Run efficiency analysis on trace
|
|
124
|
+
${c('/trace issues', 'cyan')} List detected inefficiencies
|
|
125
|
+
${c('/trace fixes', 'cyan')} List pending improvements
|
|
126
|
+
${c('/trace export', 'cyan')} Export trace JSON for LLM analysis
|
|
127
|
+
|
|
128
|
+
${c('CAPABILITIES & DEBUGGING', 'bold')}
|
|
129
|
+
${c('/powers', 'cyan')} Show all agent capabilities
|
|
130
|
+
${c('/powers <type>', 'cyan')} List by type (tools, skills, agents, mcp, commands)
|
|
131
|
+
${c('/powers search <q>', 'cyan')} Search capabilities
|
|
108
132
|
${c('/sandbox', 'cyan')} Show sandbox modes available
|
|
109
133
|
${c('/shell', 'cyan')} Show PTY shell integration info
|
|
110
134
|
${c('/lsp', 'cyan')} Show LSP integration status
|
|
@@ -129,7 +153,33 @@ ${c('━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
|
129
153
|
*/
|
|
130
154
|
export async function handleCommand(cmd, args, ctx) {
|
|
131
155
|
const { agent, sessionId, output, integrations } = ctx;
|
|
132
|
-
const { sessionStore, mcpClient, compactor } = integrations;
|
|
156
|
+
const { sessionStore, mcpClient, compactor, skillExecutor } = integrations;
|
|
157
|
+
// Check for skill invocation before built-in commands
|
|
158
|
+
if (skillExecutor) {
|
|
159
|
+
const skillName = skillExecutor.isSkillInvocation(cmd);
|
|
160
|
+
if (skillName) {
|
|
161
|
+
const result = await skillExecutor.executeSkill(skillName, args, {
|
|
162
|
+
cwd: process.cwd(),
|
|
163
|
+
sessionId,
|
|
164
|
+
});
|
|
165
|
+
if (result.success) {
|
|
166
|
+
if (result.injectedPrompt) {
|
|
167
|
+
output.log(c(`Invoking skill: /${skillName}`, 'cyan'));
|
|
168
|
+
// Return skill invocation for the caller to handle
|
|
169
|
+
return {
|
|
170
|
+
type: 'skill',
|
|
171
|
+
skillName,
|
|
172
|
+
injectedPrompt: result.injectedPrompt,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
output.log(c(result.output, 'green'));
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
output.log(c(`Skill error: ${result.error}`, 'red'));
|
|
179
|
+
}
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
133
183
|
switch (cmd) {
|
|
134
184
|
// =========================================================================
|
|
135
185
|
// GENERAL COMMANDS
|
|
@@ -655,9 +705,16 @@ ${c('Progress:', 'bold')}
|
|
|
655
705
|
// =========================================================================
|
|
656
706
|
case '/agents':
|
|
657
707
|
try {
|
|
658
|
-
const
|
|
659
|
-
|
|
660
|
-
|
|
708
|
+
const { agentRegistry } = integrations;
|
|
709
|
+
if (agentRegistry) {
|
|
710
|
+
await handleAgentsCommand(args, ctx, agentRegistry);
|
|
711
|
+
}
|
|
712
|
+
else {
|
|
713
|
+
// Fallback to legacy display if no agentRegistry
|
|
714
|
+
const agentList = agent.formatAgentList();
|
|
715
|
+
output.log(c('\nAvailable Agents:', 'bold'));
|
|
716
|
+
output.log(agentList);
|
|
717
|
+
}
|
|
661
718
|
}
|
|
662
719
|
catch (error) {
|
|
663
720
|
output.log(c(`Error: ${error.message}`, 'red'));
|
|
@@ -1036,7 +1093,7 @@ ${c('Tip:', 'dim')} Use /mcp search <query> to load specific tools on-demand.
|
|
|
1036
1093
|
case '/compact':
|
|
1037
1094
|
try {
|
|
1038
1095
|
const state = agent.getState();
|
|
1039
|
-
const contextUsage = getContextUsage(state.messages,
|
|
1096
|
+
const contextUsage = getContextUsage(state.messages, agent.getMaxContextTokens());
|
|
1040
1097
|
if (args[0] === 'status') {
|
|
1041
1098
|
output.log(`
|
|
1042
1099
|
${c('Context Status:', 'bold')}
|
|
@@ -1108,7 +1165,7 @@ ${c(' Category Tokens % of Total', 'dim')}
|
|
|
1108
1165
|
.filter(m => m.role !== 'system')
|
|
1109
1166
|
.reduce((sum, m) => sum + estimateTokens(m.content), 0);
|
|
1110
1167
|
const totalTokens = baseTokens + convTokens;
|
|
1111
|
-
const contextLimit =
|
|
1168
|
+
const contextLimit = agent.getMaxContextTokens();
|
|
1112
1169
|
const percent = Math.round((totalTokens / contextLimit) * 100);
|
|
1113
1170
|
const shouldCompact = percent >= 80;
|
|
1114
1171
|
const bar = '='.repeat(Math.min(20, Math.round(percent / 5))) +
|
|
@@ -1168,20 +1225,25 @@ ${c('Note:', 'dim')} Theme switching is visual in TUI mode. REPL mode uses fixed
|
|
|
1168
1225
|
// =========================================================================
|
|
1169
1226
|
case '/skills':
|
|
1170
1227
|
try {
|
|
1171
|
-
const
|
|
1172
|
-
if (
|
|
1173
|
-
|
|
1174
|
-
output.log(c('Add .md files to .skills/ directory to create skills.', 'dim'));
|
|
1228
|
+
const { skillManager } = integrations;
|
|
1229
|
+
if (skillManager) {
|
|
1230
|
+
await handleSkillsCommand(args, ctx, skillManager);
|
|
1175
1231
|
}
|
|
1176
1232
|
else {
|
|
1177
|
-
|
|
1178
|
-
skills.
|
|
1179
|
-
|
|
1180
|
-
output.log(
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1233
|
+
// Fallback to legacy display if no skillManager
|
|
1234
|
+
const skills = agent.getSkills();
|
|
1235
|
+
if (skills.length === 0) {
|
|
1236
|
+
output.log(c('No skills loaded.', 'dim'));
|
|
1237
|
+
output.log(c('Add .md files to .attocode/skills/ directory to create skills.', 'dim'));
|
|
1238
|
+
}
|
|
1239
|
+
else {
|
|
1240
|
+
output.log(c('\nLoaded Skills:', 'bold'));
|
|
1241
|
+
skills.forEach((skill) => {
|
|
1242
|
+
const active = skill.active ? c('+', 'green') : c('o', 'dim');
|
|
1243
|
+
const invokable = skill.invokable ? c('[/]', 'magenta') : ' ';
|
|
1244
|
+
output.log(` ${active} ${invokable} ${c(skill.name, 'cyan')} - ${skill.description || 'No description'}`);
|
|
1245
|
+
});
|
|
1246
|
+
}
|
|
1185
1247
|
}
|
|
1186
1248
|
}
|
|
1187
1249
|
catch (error) {
|
|
@@ -1296,6 +1358,252 @@ ${c('Test it:', 'dim')}
|
|
|
1296
1358
|
`);
|
|
1297
1359
|
break;
|
|
1298
1360
|
// =========================================================================
|
|
1361
|
+
// CAPABILITIES DISCOVERY
|
|
1362
|
+
// =========================================================================
|
|
1363
|
+
case '/powers': {
|
|
1364
|
+
const capRegistry = agent.getCapabilitiesRegistry?.();
|
|
1365
|
+
if (!capRegistry) {
|
|
1366
|
+
output.log(c('Capabilities registry not available.', 'dim'));
|
|
1367
|
+
break;
|
|
1368
|
+
}
|
|
1369
|
+
capRegistry.refresh();
|
|
1370
|
+
const counts = capRegistry.getCounts();
|
|
1371
|
+
if (args.length === 0) {
|
|
1372
|
+
// Show summary
|
|
1373
|
+
output.log(c('\n' + formatCapabilitiesSummary(counts), 'reset'));
|
|
1374
|
+
output.log(c('\nUsage:', 'bold'));
|
|
1375
|
+
output.log(c(' /powers tools - List all tools', 'dim'));
|
|
1376
|
+
output.log(c(' /powers skills - List all skills', 'dim'));
|
|
1377
|
+
output.log(c(' /powers agents - List all agents', 'dim'));
|
|
1378
|
+
output.log(c(' /powers mcp - List MCP tools', 'dim'));
|
|
1379
|
+
output.log(c(' /powers commands - List commands', 'dim'));
|
|
1380
|
+
output.log(c(' /powers search <q> - Search all capabilities', 'dim'));
|
|
1381
|
+
}
|
|
1382
|
+
else if (args[0] === 'search' && args.length > 1) {
|
|
1383
|
+
const query = args.slice(1).join(' ');
|
|
1384
|
+
const results = capRegistry.search(query);
|
|
1385
|
+
output.log(c(`\nSearch: "${query}"\n`, 'cyan'));
|
|
1386
|
+
output.log(formatSearchResults(results));
|
|
1387
|
+
}
|
|
1388
|
+
else {
|
|
1389
|
+
// List by type
|
|
1390
|
+
const typeMap = {
|
|
1391
|
+
tools: 'tool',
|
|
1392
|
+
tool: 'tool',
|
|
1393
|
+
skills: 'skill',
|
|
1394
|
+
skill: 'skill',
|
|
1395
|
+
agents: 'agent',
|
|
1396
|
+
agent: 'agent',
|
|
1397
|
+
mcp: 'mcp_tool',
|
|
1398
|
+
'mcp-tools': 'mcp_tool',
|
|
1399
|
+
'mcp_tools': 'mcp_tool',
|
|
1400
|
+
commands: 'command',
|
|
1401
|
+
command: 'command',
|
|
1402
|
+
};
|
|
1403
|
+
const capType = typeMap[args[0]];
|
|
1404
|
+
if (capType) {
|
|
1405
|
+
const capabilities = capRegistry.getByType(capType);
|
|
1406
|
+
output.log(c('\n' + formatCapabilitiesList(capabilities, capType), 'reset'));
|
|
1407
|
+
}
|
|
1408
|
+
else {
|
|
1409
|
+
output.log(c(`Unknown capability type: ${args[0]}`, 'yellow'));
|
|
1410
|
+
output.log(c('Valid types: tools, skills, agents, mcp, commands', 'dim'));
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
break;
|
|
1414
|
+
}
|
|
1415
|
+
// =========================================================================
|
|
1416
|
+
// INITIALIZATION
|
|
1417
|
+
// =========================================================================
|
|
1418
|
+
case '/init':
|
|
1419
|
+
await handleInitCommand(args, ctx);
|
|
1420
|
+
break;
|
|
1421
|
+
// =========================================================================
|
|
1422
|
+
// TRACE ANALYSIS
|
|
1423
|
+
// =========================================================================
|
|
1424
|
+
case '/trace': {
|
|
1425
|
+
const traceCollector = agent.getTraceCollector();
|
|
1426
|
+
if (args.length === 0) {
|
|
1427
|
+
// Show current session trace summary
|
|
1428
|
+
if (!traceCollector) {
|
|
1429
|
+
output.log(c('Tracing is not enabled. Start agent with --trace to enable.', 'yellow'));
|
|
1430
|
+
break;
|
|
1431
|
+
}
|
|
1432
|
+
const data = traceCollector.getSessionTrace();
|
|
1433
|
+
if (!data || !data.iterations || data.iterations.length === 0) {
|
|
1434
|
+
output.log(c('No trace data collected yet.', 'dim'));
|
|
1435
|
+
break;
|
|
1436
|
+
}
|
|
1437
|
+
output.log(`
|
|
1438
|
+
${c('Trace Summary:', 'bold')}
|
|
1439
|
+
Session ID: ${data.sessionId}
|
|
1440
|
+
Status: ${data.status}
|
|
1441
|
+
Iterations: ${data.iterations.length}
|
|
1442
|
+
Duration: ${data.durationMs ? `${Math.round(data.durationMs / 1000)}s` : 'ongoing'}
|
|
1443
|
+
|
|
1444
|
+
${c('Metrics:', 'bold')}
|
|
1445
|
+
Input tokens: ${data.metrics.inputTokens.toLocaleString()}
|
|
1446
|
+
Output tokens: ${data.metrics.outputTokens.toLocaleString()}
|
|
1447
|
+
Cache hit: ${Math.round(data.metrics.avgCacheHitRate * 100)}%
|
|
1448
|
+
Tool calls: ${data.metrics.toolCalls}
|
|
1449
|
+
Errors: ${data.metrics.errors}
|
|
1450
|
+
Est. Cost: $${data.metrics.estimatedCost.toFixed(4)}
|
|
1451
|
+
|
|
1452
|
+
${c('Use:', 'dim')} /trace --analyze for efficiency analysis
|
|
1453
|
+
${c(' ', 'dim')} /trace issues to see detected inefficiencies
|
|
1454
|
+
`);
|
|
1455
|
+
}
|
|
1456
|
+
else if (args[0] === '--analyze' || args[0] === 'analyze') {
|
|
1457
|
+
// Run efficiency analysis
|
|
1458
|
+
if (!traceCollector) {
|
|
1459
|
+
output.log(c('Tracing is not enabled.', 'yellow'));
|
|
1460
|
+
break;
|
|
1461
|
+
}
|
|
1462
|
+
const data = traceCollector.getSessionTrace();
|
|
1463
|
+
if (!data || !data.iterations || data.iterations.length === 0) {
|
|
1464
|
+
output.log(c('No trace data to analyze.', 'dim'));
|
|
1465
|
+
break;
|
|
1466
|
+
}
|
|
1467
|
+
output.log(c('Analyzing trace...', 'cyan'));
|
|
1468
|
+
// Import analysis module dynamically
|
|
1469
|
+
const { createTraceSummaryGenerator } = await import('../analysis/trace-summary.js');
|
|
1470
|
+
const generator = createTraceSummaryGenerator(data);
|
|
1471
|
+
const summary = generator.generate();
|
|
1472
|
+
// Display analysis results
|
|
1473
|
+
output.log(`
|
|
1474
|
+
${c('Efficiency Analysis:', 'bold')}
|
|
1475
|
+
|
|
1476
|
+
${c('Anomalies Detected:', 'bold')} ${summary.anomalies.length}
|
|
1477
|
+
`);
|
|
1478
|
+
if (summary.anomalies.length === 0) {
|
|
1479
|
+
output.log(c(' No significant issues detected.', 'green'));
|
|
1480
|
+
}
|
|
1481
|
+
else {
|
|
1482
|
+
for (const anomaly of summary.anomalies) {
|
|
1483
|
+
const severityColor = anomaly.severity === 'high' ? 'red' :
|
|
1484
|
+
anomaly.severity === 'medium' ? 'yellow' : 'dim';
|
|
1485
|
+
output.log(` ${c(`[${anomaly.severity.toUpperCase()}]`, severityColor)} ${anomaly.type}`);
|
|
1486
|
+
output.log(` ${anomaly.description}`);
|
|
1487
|
+
output.log(c(` Evidence: ${anomaly.evidence}`, 'dim'));
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
output.log(`
|
|
1491
|
+
${c('Tool Patterns:', 'bold')}
|
|
1492
|
+
Unique tools used: ${Object.keys(summary.toolPatterns.frequency).length}
|
|
1493
|
+
Redundant calls: ${summary.toolPatterns.redundantCalls.length}
|
|
1494
|
+
Slow tools: ${summary.toolPatterns.slowTools.length}
|
|
1495
|
+
`);
|
|
1496
|
+
if (summary.codeLocations.length > 0) {
|
|
1497
|
+
output.log(c('Related Code Locations:', 'bold'));
|
|
1498
|
+
for (const loc of summary.codeLocations) {
|
|
1499
|
+
const rel = loc.relevance === 'primary' ? c('[PRIMARY]', 'cyan') :
|
|
1500
|
+
loc.relevance === 'secondary' ? c('[SECONDARY]', 'dim') : '';
|
|
1501
|
+
output.log(` ${rel} ${loc.file} - ${loc.component}`);
|
|
1502
|
+
output.log(c(` ${loc.description}`, 'dim'));
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
else if (args[0] === 'issues') {
|
|
1507
|
+
// List detected inefficiencies
|
|
1508
|
+
if (!traceCollector) {
|
|
1509
|
+
output.log(c('Tracing is not enabled.', 'yellow'));
|
|
1510
|
+
break;
|
|
1511
|
+
}
|
|
1512
|
+
const data = traceCollector.getSessionTrace();
|
|
1513
|
+
if (!data || !data.iterations || data.iterations.length === 0) {
|
|
1514
|
+
output.log(c('No trace data to analyze.', 'dim'));
|
|
1515
|
+
break;
|
|
1516
|
+
}
|
|
1517
|
+
const { createTraceSummaryGenerator } = await import('../analysis/trace-summary.js');
|
|
1518
|
+
const generator = createTraceSummaryGenerator(data);
|
|
1519
|
+
const summary = generator.generate();
|
|
1520
|
+
if (summary.anomalies.length === 0) {
|
|
1521
|
+
output.log(c('No issues detected in current session.', 'green'));
|
|
1522
|
+
}
|
|
1523
|
+
else {
|
|
1524
|
+
output.log(c('\nDetected Issues:', 'bold'));
|
|
1525
|
+
summary.anomalies.forEach((anomaly, i) => {
|
|
1526
|
+
const icon = anomaly.severity === 'high' ? c('!', 'red') :
|
|
1527
|
+
anomaly.severity === 'medium' ? c('*', 'yellow') : c('-', 'dim');
|
|
1528
|
+
output.log(` ${icon} ${i + 1}. ${anomaly.type} (${anomaly.severity})`);
|
|
1529
|
+
output.log(` ${anomaly.description}`);
|
|
1530
|
+
});
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
else if (args[0] === 'fixes') {
|
|
1534
|
+
// List pending improvements from feedback loop
|
|
1535
|
+
try {
|
|
1536
|
+
const { createFeedbackLoopManager } = await import('../analysis/feedback-loop.js');
|
|
1537
|
+
const feedbackManager = createFeedbackLoopManager();
|
|
1538
|
+
const pendingFixes = feedbackManager.getPendingFixes();
|
|
1539
|
+
const stats = feedbackManager.getSummaryStats();
|
|
1540
|
+
output.log(`
|
|
1541
|
+
${c('Feedback Loop Summary:', 'bold')}
|
|
1542
|
+
Total analyses: ${stats.totalAnalyses}
|
|
1543
|
+
Avg efficiency: ${stats.avgEfficiencyScore}%
|
|
1544
|
+
Total fixes: ${stats.totalFixes}
|
|
1545
|
+
Implemented: ${stats.implementedFixes}
|
|
1546
|
+
Verified: ${stats.verifiedFixes}
|
|
1547
|
+
Avg improvement: ${stats.avgImprovement}%
|
|
1548
|
+
`);
|
|
1549
|
+
if (pendingFixes.length === 0) {
|
|
1550
|
+
output.log(c('No pending fixes.', 'dim'));
|
|
1551
|
+
}
|
|
1552
|
+
else {
|
|
1553
|
+
output.log(c('Pending Fixes:', 'bold'));
|
|
1554
|
+
for (const fix of pendingFixes.slice(0, 10)) {
|
|
1555
|
+
output.log(` - ${fix.description}`);
|
|
1556
|
+
output.log(c(` ID: ${fix.id} | Created: ${new Date(fix.createdAt).toLocaleDateString()}`, 'dim'));
|
|
1557
|
+
}
|
|
1558
|
+
if (pendingFixes.length > 10) {
|
|
1559
|
+
output.log(c(` ... and ${pendingFixes.length - 10} more`, 'dim'));
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
feedbackManager.close();
|
|
1563
|
+
}
|
|
1564
|
+
catch (error) {
|
|
1565
|
+
output.log(c(`Error loading feedback data: ${error.message}`, 'red'));
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
else if (args[0] === 'compare' && args.length >= 3) {
|
|
1569
|
+
// Compare two sessions
|
|
1570
|
+
output.log(c(`Comparing sessions: ${args[1]} vs ${args[2]}`, 'cyan'));
|
|
1571
|
+
output.log(c('Use the trace dashboard for session comparison:', 'dim'));
|
|
1572
|
+
output.log(c(' npm run dashboard', 'dim'));
|
|
1573
|
+
output.log(c(` Then visit: http://localhost:5173/compare?a=${args[1]}&b=${args[2]}`, 'dim'));
|
|
1574
|
+
}
|
|
1575
|
+
else if (args[0] === 'export') {
|
|
1576
|
+
// Export current trace as JSON for LLM analysis
|
|
1577
|
+
if (!traceCollector) {
|
|
1578
|
+
output.log(c('Tracing is not enabled.', 'yellow'));
|
|
1579
|
+
break;
|
|
1580
|
+
}
|
|
1581
|
+
const data = traceCollector.getSessionTrace();
|
|
1582
|
+
if (!data) {
|
|
1583
|
+
output.log(c('No trace data to export.', 'dim'));
|
|
1584
|
+
break;
|
|
1585
|
+
}
|
|
1586
|
+
const { createTraceSummaryGenerator } = await import('../analysis/trace-summary.js');
|
|
1587
|
+
const generator = createTraceSummaryGenerator(data);
|
|
1588
|
+
const summary = generator.generate();
|
|
1589
|
+
const outFile = args[1] || `trace-${sessionId}.json`;
|
|
1590
|
+
const { writeFile } = await import('fs/promises');
|
|
1591
|
+
await writeFile(outFile, JSON.stringify(summary, null, 2), 'utf-8');
|
|
1592
|
+
output.log(c(`+ Trace exported to: ${outFile}`, 'green'));
|
|
1593
|
+
output.log(c(' This JSON is optimized for LLM analysis (~4000 tokens)', 'dim'));
|
|
1594
|
+
}
|
|
1595
|
+
else {
|
|
1596
|
+
output.log(c('Usage:', 'bold'));
|
|
1597
|
+
output.log(c(' /trace - Show current session trace summary', 'dim'));
|
|
1598
|
+
output.log(c(' /trace --analyze - Run efficiency analysis', 'dim'));
|
|
1599
|
+
output.log(c(' /trace issues - List detected inefficiencies', 'dim'));
|
|
1600
|
+
output.log(c(' /trace fixes - List pending improvements', 'dim'));
|
|
1601
|
+
output.log(c(' /trace export [file]- Export trace JSON for LLM analysis', 'dim'));
|
|
1602
|
+
output.log(c(' /trace compare <a> <b> - Compare two sessions (via dashboard)', 'dim'));
|
|
1603
|
+
}
|
|
1604
|
+
break;
|
|
1605
|
+
}
|
|
1606
|
+
// =========================================================================
|
|
1299
1607
|
// UNKNOWN COMMAND
|
|
1300
1608
|
// =========================================================================
|
|
1301
1609
|
default:
|