xibecode 1.0.2 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/chat.d.ts +0 -1
- package/dist/commands/chat.d.ts.map +1 -1
- package/dist/commands/chat.js +10 -7
- package/dist/commands/chat.js.map +1 -1
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +5 -3
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/diagnostics.js +1 -1
- package/dist/commands/diagnostics.js.map +1 -1
- package/dist/commands/mcp.js +1 -1
- package/dist/commands/mcp.js.map +1 -1
- package/dist/commands/resume.js +1 -1
- package/dist/commands/resume.js.map +1 -1
- package/dist/commands/run-pr.d.ts.map +1 -1
- package/dist/commands/run-pr.js +13 -10
- package/dist/commands/run-pr.js.map +1 -1
- package/dist/commands/run.d.ts.map +1 -1
- package/dist/commands/run.js +17 -14
- package/dist/commands/run.js.map +1 -1
- package/dist/commands/skills.d.ts.map +1 -1
- package/dist/commands/skills.js +3 -2
- package/dist/commands/skills.js.map +1 -1
- package/dist/components/AssistantMarkdown.js +1 -1
- package/dist/components/AssistantMarkdown.js.map +1 -1
- package/dist/index.js +2 -39
- package/dist/index.js.map +1 -1
- package/dist/ui/claude-style-chat.d.ts.map +1 -1
- package/dist/ui/claude-style-chat.js +15 -11
- package/dist/ui/claude-style-chat.js.map +1 -1
- package/dist/utils/built-in-skills-dir.d.ts +7 -0
- package/dist/utils/built-in-skills-dir.d.ts.map +1 -0
- package/dist/utils/built-in-skills-dir.js +11 -0
- package/dist/utils/built-in-skills-dir.js.map +1 -0
- package/dist/utils/config.d.ts +2 -119
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +3 -88
- package/dist/utils/config.js.map +1 -1
- package/package.json +11 -26
- package/dist/commands/punycode.d.ts +0 -5
- package/dist/commands/punycode.d.ts.map +0 -1
- package/dist/commands/punycode.js +0 -48
- package/dist/commands/punycode.js.map +0 -1
- package/dist/commands/tui.d.ts +0 -9
- package/dist/commands/tui.d.ts.map +0 -1
- package/dist/commands/tui.js +0 -83
- package/dist/commands/tui.js.map +0 -1
- package/dist/core/agent-tool-policies.d.ts +0 -5
- package/dist/core/agent-tool-policies.d.ts.map +0 -1
- package/dist/core/agent-tool-policies.js +0 -18
- package/dist/core/agent-tool-policies.js.map +0 -1
- package/dist/core/agent.d.ts +0 -181
- package/dist/core/agent.d.ts.map +0 -1
- package/dist/core/agent.js +0 -1777
- package/dist/core/agent.js.map +0 -1
- package/dist/core/background-agent.d.ts +0 -23
- package/dist/core/background-agent.d.ts.map +0 -1
- package/dist/core/background-agent.js +0 -175
- package/dist/core/background-agent.js.map +0 -1
- package/dist/core/code-graph.d.ts +0 -18
- package/dist/core/code-graph.d.ts.map +0 -1
- package/dist/core/code-graph.js +0 -105
- package/dist/core/code-graph.js.map +0 -1
- package/dist/core/conflict-solver.d.ts +0 -26
- package/dist/core/conflict-solver.d.ts.map +0 -1
- package/dist/core/conflict-solver.js +0 -108
- package/dist/core/conflict-solver.js.map +0 -1
- package/dist/core/context-compactor.d.ts +0 -10
- package/dist/core/context-compactor.d.ts.map +0 -1
- package/dist/core/context-compactor.js +0 -158
- package/dist/core/context-compactor.js.map +0 -1
- package/dist/core/context-pruner.d.ts +0 -19
- package/dist/core/context-pruner.d.ts.map +0 -1
- package/dist/core/context-pruner.js +0 -103
- package/dist/core/context-pruner.js.map +0 -1
- package/dist/core/context.d.ts +0 -82
- package/dist/core/context.d.ts.map +0 -1
- package/dist/core/context.js +0 -273
- package/dist/core/context.js.map +0 -1
- package/dist/core/conversation-recovery.d.ts +0 -9
- package/dist/core/conversation-recovery.d.ts.map +0 -1
- package/dist/core/conversation-recovery.js +0 -15
- package/dist/core/conversation-recovery.js.map +0 -1
- package/dist/core/debug-workflow.d.ts +0 -9
- package/dist/core/debug-workflow.d.ts.map +0 -1
- package/dist/core/debug-workflow.js +0 -19
- package/dist/core/debug-workflow.js.map +0 -1
- package/dist/core/docs-scraper.d.ts +0 -40
- package/dist/core/docs-scraper.d.ts.map +0 -1
- package/dist/core/docs-scraper.js +0 -386
- package/dist/core/docs-scraper.js.map +0 -1
- package/dist/core/editor.d.ts +0 -87
- package/dist/core/editor.d.ts.map +0 -1
- package/dist/core/editor.js +0 -377
- package/dist/core/editor.js.map +0 -1
- package/dist/core/export.d.ts +0 -11
- package/dist/core/export.d.ts.map +0 -1
- package/dist/core/export.js +0 -54
- package/dist/core/export.js.map +0 -1
- package/dist/core/history-manager.d.ts +0 -75
- package/dist/core/history-manager.d.ts.map +0 -1
- package/dist/core/history-manager.js +0 -146
- package/dist/core/history-manager.js.map +0 -1
- package/dist/core/marketplace-client.d.ts +0 -52
- package/dist/core/marketplace-client.d.ts.map +0 -1
- package/dist/core/marketplace-client.js +0 -71
- package/dist/core/marketplace-client.js.map +0 -1
- package/dist/core/mcp/mcp-config.d.ts +0 -10
- package/dist/core/mcp/mcp-config.d.ts.map +0 -1
- package/dist/core/mcp/mcp-config.js +0 -70
- package/dist/core/mcp/mcp-config.js.map +0 -1
- package/dist/core/mcp/mcp-policy.d.ts +0 -17
- package/dist/core/mcp/mcp-policy.d.ts.map +0 -1
- package/dist/core/mcp/mcp-policy.js +0 -56
- package/dist/core/mcp/mcp-policy.js.map +0 -1
- package/dist/core/mcp/oauth-flow.d.ts +0 -30
- package/dist/core/mcp/oauth-flow.d.ts.map +0 -1
- package/dist/core/mcp/oauth-flow.js +0 -230
- package/dist/core/mcp/oauth-flow.js.map +0 -1
- package/dist/core/mcp/oauth-store.d.ts +0 -13
- package/dist/core/mcp/oauth-store.d.ts.map +0 -1
- package/dist/core/mcp/oauth-store.js +0 -68
- package/dist/core/mcp/oauth-store.js.map +0 -1
- package/dist/core/mcp/resolve-mcp-servers.d.ts +0 -16
- package/dist/core/mcp/resolve-mcp-servers.d.ts.map +0 -1
- package/dist/core/mcp/resolve-mcp-servers.js +0 -83
- package/dist/core/mcp/resolve-mcp-servers.js.map +0 -1
- package/dist/core/mcp-client.d.ts +0 -99
- package/dist/core/mcp-client.d.ts.map +0 -1
- package/dist/core/mcp-client.js +0 -315
- package/dist/core/mcp-client.js.map +0 -1
- package/dist/core/memory-promotions.d.ts +0 -15
- package/dist/core/memory-promotions.d.ts.map +0 -1
- package/dist/core/memory-promotions.js +0 -38
- package/dist/core/memory-promotions.js.map +0 -1
- package/dist/core/memory.d.ts +0 -32
- package/dist/core/memory.d.ts.map +0 -1
- package/dist/core/memory.js +0 -121
- package/dist/core/memory.js.map +0 -1
- package/dist/core/modes.d.ts +0 -432
- package/dist/core/modes.d.ts.map +0 -1
- package/dist/core/modes.js +0 -1088
- package/dist/core/modes.js.map +0 -1
- package/dist/core/pattern-miner.d.ts +0 -43
- package/dist/core/pattern-miner.d.ts.map +0 -1
- package/dist/core/pattern-miner.js +0 -123
- package/dist/core/pattern-miner.js.map +0 -1
- package/dist/core/permission-store.d.ts +0 -15
- package/dist/core/permission-store.d.ts.map +0 -1
- package/dist/core/permission-store.js +0 -30
- package/dist/core/permission-store.js.map +0 -1
- package/dist/core/permissions.d.ts +0 -33
- package/dist/core/permissions.d.ts.map +0 -1
- package/dist/core/permissions.js +0 -141
- package/dist/core/permissions.js.map +0 -1
- package/dist/core/plan-artifacts.d.ts +0 -10
- package/dist/core/plan-artifacts.d.ts.map +0 -1
- package/dist/core/plan-artifacts.js +0 -60
- package/dist/core/plan-artifacts.js.map +0 -1
- package/dist/core/plan-session.d.ts +0 -25
- package/dist/core/plan-session.d.ts.map +0 -1
- package/dist/core/plan-session.js +0 -99
- package/dist/core/plan-session.js.map +0 -1
- package/dist/core/planMode.d.ts +0 -51
- package/dist/core/planMode.d.ts.map +0 -1
- package/dist/core/planMode.js +0 -245
- package/dist/core/planMode.js.map +0 -1
- package/dist/core/plugins.d.ts +0 -96
- package/dist/core/plugins.d.ts.map +0 -1
- package/dist/core/plugins.js +0 -202
- package/dist/core/plugins.js.map +0 -1
- package/dist/core/session-bridge.d.ts +0 -128
- package/dist/core/session-bridge.d.ts.map +0 -1
- package/dist/core/session-bridge.js +0 -328
- package/dist/core/session-bridge.js.map +0 -1
- package/dist/core/session-manager.d.ts +0 -80
- package/dist/core/session-manager.d.ts.map +0 -1
- package/dist/core/session-manager.js +0 -166
- package/dist/core/session-manager.js.map +0 -1
- package/dist/core/session-memory.d.ts +0 -45
- package/dist/core/session-memory.d.ts.map +0 -1
- package/dist/core/session-memory.js +0 -103
- package/dist/core/session-memory.js.map +0 -1
- package/dist/core/skill-selection.d.ts +0 -36
- package/dist/core/skill-selection.d.ts.map +0 -1
- package/dist/core/skill-selection.js +0 -172
- package/dist/core/skill-selection.js.map +0 -1
- package/dist/core/skills-sh-client.d.ts +0 -19
- package/dist/core/skills-sh-client.d.ts.map +0 -1
- package/dist/core/skills-sh-client.js +0 -75
- package/dist/core/skills-sh-client.js.map +0 -1
- package/dist/core/skills.d.ts +0 -97
- package/dist/core/skills.d.ts.map +0 -1
- package/dist/core/skills.js +0 -339
- package/dist/core/skills.js.map +0 -1
- package/dist/core/swarm.d.ts +0 -34
- package/dist/core/swarm.d.ts.map +0 -1
- package/dist/core/swarm.js +0 -111
- package/dist/core/swarm.js.map +0 -1
- package/dist/core/task-status.d.ts +0 -13
- package/dist/core/task-status.d.ts.map +0 -1
- package/dist/core/task-status.js +0 -17
- package/dist/core/task-status.js.map +0 -1
- package/dist/core/tool-orchestrator.d.ts +0 -30
- package/dist/core/tool-orchestrator.d.ts.map +0 -1
- package/dist/core/tool-orchestrator.js +0 -89
- package/dist/core/tool-orchestrator.js.map +0 -1
- package/dist/core/tools.d.ts +0 -462
- package/dist/core/tools.d.ts.map +0 -1
- package/dist/core/tools.js +0 -2916
- package/dist/core/tools.js.map +0 -1
- package/dist/core/transcript-cleanup.d.ts +0 -8
- package/dist/core/transcript-cleanup.d.ts.map +0 -1
- package/dist/core/transcript-cleanup.js +0 -52
- package/dist/core/transcript-cleanup.js.map +0 -1
- package/dist/core/visual-feedback.d.ts +0 -20
- package/dist/core/visual-feedback.d.ts.map +0 -1
- package/dist/core/visual-feedback.js +0 -117
- package/dist/core/visual-feedback.js.map +0 -1
- package/dist/tools/browser.d.ts +0 -120
- package/dist/tools/browser.d.ts.map +0 -1
- package/dist/tools/browser.js +0 -439
- package/dist/tools/browser.js.map +0 -1
- package/dist/tools/test-generator.d.ts +0 -157
- package/dist/tools/test-generator.d.ts.map +0 -1
- package/dist/tools/test-generator.js +0 -893
- package/dist/tools/test-generator.js.map +0 -1
- package/dist/tui/InkApp.d.ts +0 -21
- package/dist/tui/InkApp.d.ts.map +0 -1
- package/dist/tui/InkApp.js +0 -146
- package/dist/tui/InkApp.js.map +0 -1
- package/dist/tui/MarkdownMessage.d.ts +0 -16
- package/dist/tui/MarkdownMessage.d.ts.map +0 -1
- package/dist/tui/MarkdownMessage.js +0 -63
- package/dist/tui/MarkdownMessage.js.map +0 -1
- package/dist/tui/blessed-chat.d.ts +0 -9
- package/dist/tui/blessed-chat.d.ts.map +0 -1
- package/dist/tui/blessed-chat.js +0 -887
- package/dist/tui/blessed-chat.js.map +0 -1
- package/dist/tui/markdown-to-blessed.d.ts +0 -6
- package/dist/tui/markdown-to-blessed.d.ts.map +0 -1
- package/dist/tui/markdown-to-blessed.js +0 -26
- package/dist/tui/markdown-to-blessed.js.map +0 -1
- package/dist/ui/ink/App.d.ts +0 -25
- package/dist/ui/ink/App.d.ts.map +0 -1
- package/dist/ui/ink/App.js +0 -372
- package/dist/ui/ink/App.js.map +0 -1
- package/dist/utils/at-references.d.ts +0 -14
- package/dist/utils/at-references.d.ts.map +0 -1
- package/dist/utils/at-references.js +0 -47
- package/dist/utils/at-references.js.map +0 -1
- package/dist/utils/auto-memory.d.ts +0 -24
- package/dist/utils/auto-memory.d.ts.map +0 -1
- package/dist/utils/auto-memory.js +0 -153
- package/dist/utils/auto-memory.js.map +0 -1
- package/dist/utils/git.d.ts +0 -89
- package/dist/utils/git.d.ts.map +0 -1
- package/dist/utils/git.js +0 -444
- package/dist/utils/git.js.map +0 -1
- package/dist/utils/mcp-servers-file.d.ts +0 -46
- package/dist/utils/mcp-servers-file.d.ts.map +0 -1
- package/dist/utils/mcp-servers-file.js +0 -212
- package/dist/utils/mcp-servers-file.js.map +0 -1
- package/dist/utils/safety.d.ts +0 -60
- package/dist/utils/safety.d.ts.map +0 -1
- package/dist/utils/safety.js +0 -254
- package/dist/utils/safety.js.map +0 -1
- package/dist/utils/smithery.d.ts +0 -25
- package/dist/utils/smithery.d.ts.map +0 -1
- package/dist/utils/smithery.js +0 -50
- package/dist/utils/smithery.js.map +0 -1
- package/dist/utils/testRunner.d.ts +0 -44
- package/dist/utils/testRunner.d.ts.map +0 -1
- package/dist/utils/testRunner.js +0 -270
- package/dist/utils/testRunner.js.map +0 -1
- package/dist/webui/server.d.ts +0 -99
- package/dist/webui/server.d.ts.map +0 -1
- package/dist/webui/server.js +0 -2619
- package/dist/webui/server.js.map +0 -1
- package/webui-dist/assets/index-CSla6Lzy.css +0 -32
- package/webui-dist/assets/index-G_Z4gzPy.js +0 -457
- package/webui-dist/assets/index-G_Z4gzPy.js.map +0 -1
- package/webui-dist/assets/xterm-Da5jL1MD.js +0 -10
- package/webui-dist/assets/xterm-Da5jL1MD.js.map +0 -1
- package/webui-dist/assets/xterm-addon-fit-CMeqLIvm.js +0 -2
- package/webui-dist/assets/xterm-addon-fit-CMeqLIvm.js.map +0 -1
- package/webui-dist/assets/xterm-addon-web-links-D6m8jNVE.js +0 -2
- package/webui-dist/assets/xterm-addon-web-links-D6m8jNVE.js.map +0 -1
- package/webui-dist/index.html +0 -15
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
function messageText(message) {
|
|
2
|
-
if (typeof message.content === 'string') {
|
|
3
|
-
return message.content;
|
|
4
|
-
}
|
|
5
|
-
if (Array.isArray(message.content)) {
|
|
6
|
-
return message.content
|
|
7
|
-
.map((block) => {
|
|
8
|
-
if (block?.type === 'text')
|
|
9
|
-
return String(block.text || '');
|
|
10
|
-
if (block?.type === 'tool_use')
|
|
11
|
-
return `[tool_use:${String(block.name || 'unknown')}]`;
|
|
12
|
-
if (block?.type === 'tool_result')
|
|
13
|
-
return `[tool_result:${String(block.tool_use_id || 'unknown')}]`;
|
|
14
|
-
return String(block?.content ?? '');
|
|
15
|
-
})
|
|
16
|
-
.join('\n');
|
|
17
|
-
}
|
|
18
|
-
return '';
|
|
19
|
-
}
|
|
20
|
-
function shouldPreserve(message) {
|
|
21
|
-
const text = messageText(message);
|
|
22
|
-
return (text.includes('[[PLAN_READY]]') ||
|
|
23
|
-
text.includes('[[TASK_COMPLETE') ||
|
|
24
|
-
text.includes('[SYSTEM]') ||
|
|
25
|
-
text.includes('Plan approved'));
|
|
26
|
-
}
|
|
27
|
-
function parseToolResultFacts(message) {
|
|
28
|
-
if (!Array.isArray(message.content))
|
|
29
|
-
return [];
|
|
30
|
-
const facts = [];
|
|
31
|
-
for (const block of message.content) {
|
|
32
|
-
if (block?.type !== 'tool_result')
|
|
33
|
-
continue;
|
|
34
|
-
const raw = typeof block.content === 'string' ? block.content : JSON.stringify(block.content ?? {});
|
|
35
|
-
let payload = null;
|
|
36
|
-
try {
|
|
37
|
-
payload = JSON.parse(raw);
|
|
38
|
-
}
|
|
39
|
-
catch {
|
|
40
|
-
payload = null;
|
|
41
|
-
}
|
|
42
|
-
if (!payload || typeof payload !== 'object')
|
|
43
|
-
continue;
|
|
44
|
-
if (typeof payload.path === 'string') {
|
|
45
|
-
facts.push(`Touched file: ${payload.path}`);
|
|
46
|
-
}
|
|
47
|
-
if (typeof payload.linesChanged === 'number') {
|
|
48
|
-
facts.push(`Edited ${payload.linesChanged} line(s)`);
|
|
49
|
-
}
|
|
50
|
-
if (typeof payload.exitCode === 'number') {
|
|
51
|
-
facts.push(`Command exit code: ${payload.exitCode}`);
|
|
52
|
-
}
|
|
53
|
-
if (typeof payload.totalFiles === 'number') {
|
|
54
|
-
facts.push(`Context files: ${payload.totalFiles}`);
|
|
55
|
-
}
|
|
56
|
-
if (typeof payload.match_count === 'number') {
|
|
57
|
-
facts.push(`Search matches: ${payload.match_count}`);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return facts;
|
|
61
|
-
}
|
|
62
|
-
function buildGroundedFacts(messages) {
|
|
63
|
-
const out = [];
|
|
64
|
-
for (const message of messages) {
|
|
65
|
-
const text = messageText(message);
|
|
66
|
-
if (text.includes('[[TASK_COMPLETE')) {
|
|
67
|
-
out.push('Task completion marker observed');
|
|
68
|
-
}
|
|
69
|
-
for (const fact of parseToolResultFacts(message)) {
|
|
70
|
-
out.push(fact);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return Array.from(new Set(out)).slice(-12);
|
|
74
|
-
}
|
|
75
|
-
function summarizeText(text, maxLen = 120) {
|
|
76
|
-
const clean = text.replace(/\s+/g, ' ').trim();
|
|
77
|
-
if (clean.length <= maxLen)
|
|
78
|
-
return clean;
|
|
79
|
-
return `${clean.slice(0, maxLen - 1)}…`;
|
|
80
|
-
}
|
|
81
|
-
function buildConversationSummary(messages) {
|
|
82
|
-
const userTurns = [];
|
|
83
|
-
const assistantTurns = [];
|
|
84
|
-
for (const message of messages) {
|
|
85
|
-
const text = messageText(message);
|
|
86
|
-
if (!text)
|
|
87
|
-
continue;
|
|
88
|
-
if (message.role === 'user') {
|
|
89
|
-
userTurns.push(summarizeText(text));
|
|
90
|
-
}
|
|
91
|
-
else if (message.role === 'assistant') {
|
|
92
|
-
assistantTurns.push(summarizeText(text));
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
const latestUser = userTurns.slice(-4);
|
|
96
|
-
const latestAssistant = assistantTurns.slice(-4);
|
|
97
|
-
const sections = [];
|
|
98
|
-
if (latestUser.length > 0) {
|
|
99
|
-
sections.push('Recent user intents:\n' +
|
|
100
|
-
latestUser.map((line, idx) => `${idx + 1}. ${line}`).join('\n'));
|
|
101
|
-
}
|
|
102
|
-
if (latestAssistant.length > 0) {
|
|
103
|
-
sections.push('Recent assistant outcomes:\n' +
|
|
104
|
-
latestAssistant.map((line, idx) => `${idx + 1}. ${line}`).join('\n'));
|
|
105
|
-
}
|
|
106
|
-
return sections.join('\n\n').trim();
|
|
107
|
-
}
|
|
108
|
-
export function compactConversation(messages, keepRecentCount = 16) {
|
|
109
|
-
if (messages.length <= keepRecentCount) {
|
|
110
|
-
return {
|
|
111
|
-
messages,
|
|
112
|
-
droppedCount: 0,
|
|
113
|
-
summaryNotice: '',
|
|
114
|
-
groundedFacts: [],
|
|
115
|
-
conversationSummary: '',
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
const older = messages.slice(0, -keepRecentCount);
|
|
119
|
-
const recent = messages.slice(-keepRecentCount);
|
|
120
|
-
const preserved = older.filter(shouldPreserve);
|
|
121
|
-
const groundedFacts = buildGroundedFacts(older);
|
|
122
|
-
const conversationSummary = buildConversationSummary(older);
|
|
123
|
-
const droppedCount = messages.length - (recent.length + preserved.length);
|
|
124
|
-
const summaryNotice = `Conversation was compacted: dropped ${droppedCount} stale messages, ` +
|
|
125
|
-
`kept ${preserved.length} critical and ${recent.length} recent messages.`;
|
|
126
|
-
const compacted = [
|
|
127
|
-
{
|
|
128
|
-
role: 'assistant',
|
|
129
|
-
content: summaryNotice,
|
|
130
|
-
},
|
|
131
|
-
...(groundedFacts.length > 0
|
|
132
|
-
? [
|
|
133
|
-
{
|
|
134
|
-
role: 'assistant',
|
|
135
|
-
content: `[Grounded Facts Ledger]\n${groundedFacts.map((fact) => `- ${fact}`).join('\n')}`,
|
|
136
|
-
},
|
|
137
|
-
]
|
|
138
|
-
: []),
|
|
139
|
-
...(conversationSummary
|
|
140
|
-
? [
|
|
141
|
-
{
|
|
142
|
-
role: 'assistant',
|
|
143
|
-
content: `[Conversation Summary]\n${conversationSummary}`,
|
|
144
|
-
},
|
|
145
|
-
]
|
|
146
|
-
: []),
|
|
147
|
-
...preserved,
|
|
148
|
-
...recent,
|
|
149
|
-
];
|
|
150
|
-
return {
|
|
151
|
-
messages: compacted,
|
|
152
|
-
droppedCount,
|
|
153
|
-
summaryNotice,
|
|
154
|
-
groundedFacts,
|
|
155
|
-
conversationSummary,
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
//# sourceMappingURL=context-compactor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context-compactor.js","sourceRoot":"","sources":["../../src/core/context-compactor.ts"],"names":[],"mappings":"AAUA,SAAS,WAAW,CAAC,OAAqB;IACxC,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,OAAO,CAAC,OAAO,CAAC;IACzB,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACnC,OAAO,OAAO,CAAC,OAAO;aACnB,GAAG,CAAC,CAAC,KAAU,EAAE,EAAE;YAClB,IAAI,KAAK,EAAE,IAAI,KAAK,MAAM;gBAAE,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;YAC5D,IAAI,KAAK,EAAE,IAAI,KAAK,UAAU;gBAAE,OAAO,aAAa,MAAM,CAAC,KAAK,CAAC,IAAI,IAAI,SAAS,CAAC,GAAG,CAAC;YACvF,IAAI,KAAK,EAAE,IAAI,KAAK,aAAa;gBAAE,OAAO,gBAAgB,MAAM,CAAC,KAAK,CAAC,WAAW,IAAI,SAAS,CAAC,GAAG,CAAC;YACpG,OAAO,MAAM,CAAC,KAAK,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC;QACtC,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,SAAS,cAAc,CAAC,OAAqB;IAC3C,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IAClC,OAAO,CACL,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC;QAC/B,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC;QAChC,IAAI,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E,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;iBAC3F;aACF;YACH,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,mBAAmB;YACrB,CAAC,CAAC;gBACE;oBACE,IAAI,EAAE,WAAoB;oBAC1B,OAAO,EAAE,2BAA2B,mBAAmB,EAAE;iBAC1D;aACF;YACH,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,SAAS;QACZ,GAAG,MAAM;KACV,CAAC;IAEF,OAAO;QACL,QAAQ,EAAE,SAAS;QACnB,YAAY;QACZ,aAAa;QACb,aAAa;QACb,mBAAmB;KACpB,CAAC;AACJ,CAAC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lightweight context pruning: score files by relevance to the task
|
|
3
|
-
* so we can cap what gets suggested to the agent and reduce tokens.
|
|
4
|
-
*/
|
|
5
|
-
export interface PruneOptions {
|
|
6
|
-
maxFiles?: number;
|
|
7
|
-
extensions?: string[];
|
|
8
|
-
/** If true, include a simple content snippet (first 500 chars) in scoring. */
|
|
9
|
-
useContent?: boolean;
|
|
10
|
-
/** If true, augment with PKG-style code graph (AST/import-based relevance). Requires CodeGraph. */
|
|
11
|
-
usePkgStyleContext?: boolean;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* List candidate files in workingDir (by extensions), optionally read a small
|
|
15
|
-
* content preview, score by relevance to the task, and return top maxFiles paths.
|
|
16
|
-
* When usePkgStyleContext is true, augments with PKG-style code graph (AST) results.
|
|
17
|
-
*/
|
|
18
|
-
export declare function pruneContext(workingDir: string, task: string, options?: PruneOptions): Promise<string[]>;
|
|
19
|
-
//# sourceMappingURL=context-pruner.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context-pruner.d.ts","sourceRoot":"","sources":["../../src/core/context-pruner.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,8EAA8E;IAC9E,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,mGAAmG;IACnG,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAwCD;;;;GAIG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,MAAM,EAAE,CAAC,CAmDnB"}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lightweight context pruning: score files by relevance to the task
|
|
3
|
-
* so we can cap what gets suggested to the agent and reduce tokens.
|
|
4
|
-
*/
|
|
5
|
-
import * as fs from 'fs/promises';
|
|
6
|
-
import * as path from 'path';
|
|
7
|
-
import fg from 'fast-glob';
|
|
8
|
-
const DEFAULT_MAX_FILES = 40;
|
|
9
|
-
const DEFAULT_EXTENSIONS = ['*.ts', '*.tsx', '*.js', '*.jsx', '*.mjs', '*.cjs', '*.py', '*.go', '*.rs', '*.java', '*.md', '*.json'];
|
|
10
|
-
const IGNORE_DIRS = ['node_modules', '.git', 'dist', 'build', '.next', 'coverage', '__pycache__', '.venv', 'vendor'];
|
|
11
|
-
/**
|
|
12
|
-
* Extract meaningful words from the task (ignore stopwords, short tokens).
|
|
13
|
-
*/
|
|
14
|
-
function taskWords(task) {
|
|
15
|
-
const stop = new Set(['the', 'and', 'for', 'with', 'this', 'that', 'from', 'have', 'has', 'can', 'will', 'are', 'was', 'were', 'been', 'being', 'into', 'through', 'during', 'before', 'after', 'when', 'where', 'which', 'what', 'your', 'need', 'add', 'fix', 'make', 'use', 'file', 'files', 'code']);
|
|
16
|
-
const normalized = task.toLowerCase().replace(/[^\w\s]/g, ' ');
|
|
17
|
-
const words = new Set();
|
|
18
|
-
for (const w of normalized.split(/\s+/)) {
|
|
19
|
-
if (w.length >= 2 && !stop.has(w))
|
|
20
|
-
words.add(w);
|
|
21
|
-
}
|
|
22
|
-
return words;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Score a file path (and optionally a content snippet) against task words.
|
|
26
|
-
* Returns a number >= 0; higher = more relevant.
|
|
27
|
-
*/
|
|
28
|
-
function scorePathAndContent(filePath, content, words) {
|
|
29
|
-
const pathLower = filePath.toLowerCase().replace(/\\/g, '/');
|
|
30
|
-
const pathParts = pathLower.split('/');
|
|
31
|
-
let score = 0;
|
|
32
|
-
for (const w of words) {
|
|
33
|
-
if (pathLower.includes(w)) {
|
|
34
|
-
// Prefer matches in filename over deep path
|
|
35
|
-
const fileName = pathParts[pathParts.length - 1] ?? '';
|
|
36
|
-
if (fileName.includes(w))
|
|
37
|
-
score += 3;
|
|
38
|
-
else
|
|
39
|
-
score += 1;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (content) {
|
|
43
|
-
const contentLower = content.toLowerCase();
|
|
44
|
-
for (const w of words) {
|
|
45
|
-
if (contentLower.includes(w))
|
|
46
|
-
score += 1;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return score;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* List candidate files in workingDir (by extensions), optionally read a small
|
|
53
|
-
* content preview, score by relevance to the task, and return top maxFiles paths.
|
|
54
|
-
* When usePkgStyleContext is true, augments with PKG-style code graph (AST) results.
|
|
55
|
-
*/
|
|
56
|
-
export async function pruneContext(workingDir, task, options = {}) {
|
|
57
|
-
const maxFiles = options.maxFiles ?? DEFAULT_MAX_FILES;
|
|
58
|
-
const extensions = options.extensions ?? DEFAULT_EXTENSIONS;
|
|
59
|
-
const useContent = options.useContent ?? false;
|
|
60
|
-
const usePkgStyleContext = options.usePkgStyleContext ?? false;
|
|
61
|
-
const words = taskWords(task);
|
|
62
|
-
const patterns = extensions.map(ext => `**/${ext}`);
|
|
63
|
-
const ignore = IGNORE_DIRS.map(d => `**/${d}/**`);
|
|
64
|
-
const files = words.size > 0
|
|
65
|
-
? await fg(patterns, { cwd: workingDir, absolute: false, ignore, onlyFiles: true })
|
|
66
|
-
: [];
|
|
67
|
-
const scored = [];
|
|
68
|
-
for (const rel of files) {
|
|
69
|
-
let content = null;
|
|
70
|
-
if (useContent) {
|
|
71
|
-
try {
|
|
72
|
-
const full = path.join(workingDir, rel);
|
|
73
|
-
const buf = await fs.readFile(full, 'utf-8').catch(() => '');
|
|
74
|
-
content = buf.slice(0, 500);
|
|
75
|
-
}
|
|
76
|
-
catch {
|
|
77
|
-
// skip content
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
const score = scorePathAndContent(rel, content, words);
|
|
81
|
-
scored.push({ path: rel, score });
|
|
82
|
-
}
|
|
83
|
-
scored.sort((a, b) => b.score - a.score);
|
|
84
|
-
const withScore = scored.filter(s => s.score > 0);
|
|
85
|
-
let top = withScore.length > 0
|
|
86
|
-
? withScore.slice(0, maxFiles).map(s => s.path)
|
|
87
|
-
: scored.slice(0, maxFiles).map(s => s.path);
|
|
88
|
-
if (usePkgStyleContext && task.trim().length > 0) {
|
|
89
|
-
try {
|
|
90
|
-
const { CodeGraph } = await import('./code-graph.js');
|
|
91
|
-
const codeGraph = new CodeGraph(workingDir);
|
|
92
|
-
const graphResults = await codeGraph.search(task.trim().slice(0, 100));
|
|
93
|
-
const graphPaths = [...new Set(graphResults.map(r => r.filePath).filter(Boolean))];
|
|
94
|
-
const combined = [...new Set([...top, ...graphPaths])].slice(0, maxFiles);
|
|
95
|
-
top = combined;
|
|
96
|
-
}
|
|
97
|
-
catch {
|
|
98
|
-
// Non-fatal: fall back to keyword-only
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return top;
|
|
102
|
-
}
|
|
103
|
-
//# sourceMappingURL=context-pruner.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context-pruner.js","sourceRoot":"","sources":["../../src/core/context-pruner.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,E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OAAO,CAAC,CAAC,CAAC,CAAC;YACnF,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;YAC1E,GAAG,GAAG,QAAQ,CAAC;QACjB,CAAC;QAAC,MAAM,CAAC;YACP,uCAAuC;QACzC,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/core/context.d.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
export interface FileContext {
|
|
2
|
-
path: string;
|
|
3
|
-
content: string;
|
|
4
|
-
lines: number;
|
|
5
|
-
size: number;
|
|
6
|
-
language?: string;
|
|
7
|
-
}
|
|
8
|
-
export interface ContextWindow {
|
|
9
|
-
files: FileContext[];
|
|
10
|
-
totalTokens: number;
|
|
11
|
-
maxTokens: number;
|
|
12
|
-
}
|
|
13
|
-
export declare class ContextManager {
|
|
14
|
-
private workingDir;
|
|
15
|
-
private maxContextTokens;
|
|
16
|
-
private loadedFiles;
|
|
17
|
-
private excludePatterns;
|
|
18
|
-
constructor(workingDir: string, maxTokens?: number);
|
|
19
|
-
/**
|
|
20
|
-
* Smart context builder - automatically includes relevant files
|
|
21
|
-
*/
|
|
22
|
-
buildContext(primaryFiles?: string[]): Promise<ContextWindow>;
|
|
23
|
-
/**
|
|
24
|
-
* Load a single file with metadata
|
|
25
|
-
*/
|
|
26
|
-
loadFile(filePath: string): Promise<FileContext | null>;
|
|
27
|
-
/**
|
|
28
|
-
* Find files related to the given files (imports, configs, tests)
|
|
29
|
-
*/
|
|
30
|
-
private findRelatedFiles;
|
|
31
|
-
/**
|
|
32
|
-
* Extract import statements from code
|
|
33
|
-
*/
|
|
34
|
-
private extractImports;
|
|
35
|
-
/**
|
|
36
|
-
* Resolve import path to actual file
|
|
37
|
-
*/
|
|
38
|
-
private resolveImport;
|
|
39
|
-
/**
|
|
40
|
-
* Find test file for a given source file
|
|
41
|
-
*/
|
|
42
|
-
private findTestFile;
|
|
43
|
-
/**
|
|
44
|
-
* Find config files in directory
|
|
45
|
-
*/
|
|
46
|
-
private findConfigFiles;
|
|
47
|
-
/**
|
|
48
|
-
* Search for files matching pattern
|
|
49
|
-
*/
|
|
50
|
-
searchFiles(pattern: string, options?: {
|
|
51
|
-
maxResults?: number;
|
|
52
|
-
}): Promise<string[]>;
|
|
53
|
-
/**
|
|
54
|
-
* Get file chunk for large files (prevents token overflow)
|
|
55
|
-
*/
|
|
56
|
-
getFileChunk(filePath: string, startLine: number, endLine: number): Promise<string>;
|
|
57
|
-
/**
|
|
58
|
-
* Detect programming language from file extension
|
|
59
|
-
*/
|
|
60
|
-
private detectLanguage;
|
|
61
|
-
/**
|
|
62
|
-
* Estimate token count (rough approximation: 1 token ≈ 4 chars)
|
|
63
|
-
*/
|
|
64
|
-
private estimateTokens;
|
|
65
|
-
/**
|
|
66
|
-
* Check if file exists
|
|
67
|
-
*/
|
|
68
|
-
private fileExists;
|
|
69
|
-
/**
|
|
70
|
-
* Clear loaded files cache
|
|
71
|
-
*/
|
|
72
|
-
clearCache(): void;
|
|
73
|
-
/**
|
|
74
|
-
* Get loaded files summary
|
|
75
|
-
*/
|
|
76
|
-
getSummary(): {
|
|
77
|
-
fileCount: number;
|
|
78
|
-
totalSize: number;
|
|
79
|
-
files: string[];
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/core/context.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED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ETED
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs/promises';
|
|
2
|
-
import * as path from 'path';
|
|
3
|
-
import fg from 'fast-glob';
|
|
4
|
-
export class ContextManager {
|
|
5
|
-
workingDir;
|
|
6
|
-
maxContextTokens = 100000; // ~100k tokens
|
|
7
|
-
loadedFiles = new Map();
|
|
8
|
-
// Files to exclude from context
|
|
9
|
-
excludePatterns = [
|
|
10
|
-
'**/node_modules/**',
|
|
11
|
-
'**/dist/**',
|
|
12
|
-
'**/build/**',
|
|
13
|
-
'**/.git/**',
|
|
14
|
-
'**/coverage/**',
|
|
15
|
-
'**/*.min.js',
|
|
16
|
-
'**/*.map',
|
|
17
|
-
'**/package-lock.json',
|
|
18
|
-
'**/yarn.lock',
|
|
19
|
-
];
|
|
20
|
-
constructor(workingDir, maxTokens) {
|
|
21
|
-
this.workingDir = workingDir;
|
|
22
|
-
if (maxTokens)
|
|
23
|
-
this.maxContextTokens = maxTokens;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Smart context builder - automatically includes relevant files
|
|
27
|
-
*/
|
|
28
|
-
async buildContext(primaryFiles = []) {
|
|
29
|
-
const context = {
|
|
30
|
-
files: [],
|
|
31
|
-
totalTokens: 0,
|
|
32
|
-
maxTokens: this.maxContextTokens,
|
|
33
|
-
};
|
|
34
|
-
// Load primary files first (highest priority)
|
|
35
|
-
for (const filePath of primaryFiles) {
|
|
36
|
-
const fileContext = await this.loadFile(filePath);
|
|
37
|
-
if (fileContext) {
|
|
38
|
-
context.files.push(fileContext);
|
|
39
|
-
context.totalTokens += this.estimateTokens(fileContext.content);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
// Auto-discover related files
|
|
43
|
-
const relatedFiles = await this.findRelatedFiles(primaryFiles);
|
|
44
|
-
for (const filePath of relatedFiles) {
|
|
45
|
-
if (context.totalTokens >= this.maxContextTokens * 0.8) {
|
|
46
|
-
break; // Stop at 80% capacity
|
|
47
|
-
}
|
|
48
|
-
if (!this.loadedFiles.has(filePath)) {
|
|
49
|
-
const fileContext = await this.loadFile(filePath);
|
|
50
|
-
if (fileContext) {
|
|
51
|
-
context.files.push(fileContext);
|
|
52
|
-
context.totalTokens += this.estimateTokens(fileContext.content);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return context;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Load a single file with metadata
|
|
60
|
-
*/
|
|
61
|
-
async loadFile(filePath) {
|
|
62
|
-
const fullPath = path.resolve(this.workingDir, filePath);
|
|
63
|
-
try {
|
|
64
|
-
const content = await fs.readFile(fullPath, 'utf-8');
|
|
65
|
-
const stats = await fs.stat(fullPath);
|
|
66
|
-
// Skip binary files or very large files
|
|
67
|
-
if (stats.size > 1024 * 1024) { // 1MB limit
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
|
-
const fileContext = {
|
|
71
|
-
path: filePath,
|
|
72
|
-
content,
|
|
73
|
-
lines: content.split('\n').length,
|
|
74
|
-
size: stats.size,
|
|
75
|
-
language: this.detectLanguage(filePath),
|
|
76
|
-
};
|
|
77
|
-
this.loadedFiles.set(filePath, fileContext);
|
|
78
|
-
return fileContext;
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Find files related to the given files (imports, configs, tests)
|
|
86
|
-
*/
|
|
87
|
-
async findRelatedFiles(files) {
|
|
88
|
-
const related = new Set();
|
|
89
|
-
for (const file of files) {
|
|
90
|
-
const fileContext = this.loadedFiles.get(file);
|
|
91
|
-
if (!fileContext)
|
|
92
|
-
continue;
|
|
93
|
-
// Find imports/requires
|
|
94
|
-
const imports = this.extractImports(fileContext.content);
|
|
95
|
-
for (const imp of imports) {
|
|
96
|
-
const resolved = await this.resolveImport(imp, file);
|
|
97
|
-
if (resolved)
|
|
98
|
-
related.add(resolved);
|
|
99
|
-
}
|
|
100
|
-
// Find test files
|
|
101
|
-
const testFile = this.findTestFile(file);
|
|
102
|
-
if (testFile) {
|
|
103
|
-
const exists = await this.fileExists(testFile);
|
|
104
|
-
if (exists)
|
|
105
|
-
related.add(testFile);
|
|
106
|
-
}
|
|
107
|
-
// Find config files in same directory
|
|
108
|
-
const dir = path.dirname(file);
|
|
109
|
-
const configs = await this.findConfigFiles(dir);
|
|
110
|
-
configs.forEach(c => related.add(c));
|
|
111
|
-
}
|
|
112
|
-
return Array.from(related);
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Extract import statements from code
|
|
116
|
-
*/
|
|
117
|
-
extractImports(content) {
|
|
118
|
-
const imports = [];
|
|
119
|
-
// ES6 imports
|
|
120
|
-
const es6Regex = /import\s+.*?\s+from\s+['"](.+?)['"]/g;
|
|
121
|
-
let match;
|
|
122
|
-
while ((match = es6Regex.exec(content)) !== null) {
|
|
123
|
-
imports.push(match[1]);
|
|
124
|
-
}
|
|
125
|
-
// CommonJS requires
|
|
126
|
-
const cjsRegex = /require\s*\(\s*['"](.+?)['"]\s*\)/g;
|
|
127
|
-
while ((match = cjsRegex.exec(content)) !== null) {
|
|
128
|
-
imports.push(match[1]);
|
|
129
|
-
}
|
|
130
|
-
return imports;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Resolve import path to actual file
|
|
134
|
-
*/
|
|
135
|
-
async resolveImport(importPath, fromFile) {
|
|
136
|
-
// Skip node_modules
|
|
137
|
-
if (!importPath.startsWith('.'))
|
|
138
|
-
return null;
|
|
139
|
-
const dir = path.dirname(fromFile);
|
|
140
|
-
const extensions = ['.ts', '.tsx', '.js', '.jsx', ''];
|
|
141
|
-
for (const ext of extensions) {
|
|
142
|
-
const resolved = path.join(dir, importPath + ext);
|
|
143
|
-
if (await this.fileExists(resolved)) {
|
|
144
|
-
return resolved;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return null;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Find test file for a given source file
|
|
151
|
-
*/
|
|
152
|
-
findTestFile(filePath) {
|
|
153
|
-
const parsed = path.parse(filePath);
|
|
154
|
-
const testPatterns = [
|
|
155
|
-
`${parsed.name}.test${parsed.ext}`,
|
|
156
|
-
`${parsed.name}.spec${parsed.ext}`,
|
|
157
|
-
path.join('__tests__', `${parsed.name}${parsed.ext}`),
|
|
158
|
-
];
|
|
159
|
-
for (const pattern of testPatterns) {
|
|
160
|
-
const testPath = path.join(parsed.dir, pattern);
|
|
161
|
-
return testPath;
|
|
162
|
-
}
|
|
163
|
-
return null;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Find config files in directory
|
|
167
|
-
*/
|
|
168
|
-
async findConfigFiles(dir) {
|
|
169
|
-
const configPatterns = [
|
|
170
|
-
'package.json',
|
|
171
|
-
'tsconfig.json',
|
|
172
|
-
'.eslintrc*',
|
|
173
|
-
'.prettierrc*',
|
|
174
|
-
];
|
|
175
|
-
const configs = [];
|
|
176
|
-
for (const pattern of configPatterns) {
|
|
177
|
-
const configPath = path.join(dir, pattern);
|
|
178
|
-
if (await this.fileExists(configPath)) {
|
|
179
|
-
configs.push(configPath);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
return configs;
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Search for files matching pattern
|
|
186
|
-
*/
|
|
187
|
-
async searchFiles(pattern, options) {
|
|
188
|
-
const maxResults = options?.maxResults || 100;
|
|
189
|
-
try {
|
|
190
|
-
const files = await fg(pattern, {
|
|
191
|
-
cwd: this.workingDir,
|
|
192
|
-
ignore: this.excludePatterns,
|
|
193
|
-
absolute: false,
|
|
194
|
-
onlyFiles: true,
|
|
195
|
-
});
|
|
196
|
-
return files.slice(0, maxResults);
|
|
197
|
-
}
|
|
198
|
-
catch (error) {
|
|
199
|
-
return [];
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Get file chunk for large files (prevents token overflow)
|
|
204
|
-
*/
|
|
205
|
-
async getFileChunk(filePath, startLine, endLine) {
|
|
206
|
-
const fullPath = path.resolve(this.workingDir, filePath);
|
|
207
|
-
const content = await fs.readFile(fullPath, 'utf-8');
|
|
208
|
-
const lines = content.split('\n');
|
|
209
|
-
const chunk = lines.slice(startLine - 1, endLine).join('\n');
|
|
210
|
-
return chunk;
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Detect programming language from file extension
|
|
214
|
-
*/
|
|
215
|
-
detectLanguage(filePath) {
|
|
216
|
-
const ext = path.extname(filePath).toLowerCase();
|
|
217
|
-
const langMap = {
|
|
218
|
-
'.ts': 'typescript',
|
|
219
|
-
'.tsx': 'typescript',
|
|
220
|
-
'.js': 'javascript',
|
|
221
|
-
'.jsx': 'javascript',
|
|
222
|
-
'.py': 'python',
|
|
223
|
-
'.java': 'java',
|
|
224
|
-
'.cpp': 'cpp',
|
|
225
|
-
'.c': 'c',
|
|
226
|
-
'.go': 'go',
|
|
227
|
-
'.rs': 'rust',
|
|
228
|
-
'.rb': 'ruby',
|
|
229
|
-
'.php': 'php',
|
|
230
|
-
'.swift': 'swift',
|
|
231
|
-
'.kt': 'kotlin',
|
|
232
|
-
};
|
|
233
|
-
return langMap[ext] || 'plaintext';
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Estimate token count (rough approximation: 1 token ≈ 4 chars)
|
|
237
|
-
*/
|
|
238
|
-
estimateTokens(text) {
|
|
239
|
-
return Math.ceil(text.length / 4);
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Check if file exists
|
|
243
|
-
*/
|
|
244
|
-
async fileExists(filePath) {
|
|
245
|
-
const fullPath = path.resolve(this.workingDir, filePath);
|
|
246
|
-
try {
|
|
247
|
-
await fs.access(fullPath);
|
|
248
|
-
return true;
|
|
249
|
-
}
|
|
250
|
-
catch {
|
|
251
|
-
return false;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Clear loaded files cache
|
|
256
|
-
*/
|
|
257
|
-
clearCache() {
|
|
258
|
-
this.loadedFiles.clear();
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Get loaded files summary
|
|
262
|
-
*/
|
|
263
|
-
getSummary() {
|
|
264
|
-
let totalSize = 0;
|
|
265
|
-
const files = [];
|
|
266
|
-
for (const [path, context] of this.loadedFiles) {
|
|
267
|
-
files.push(path);
|
|
268
|
-
totalSize += context.size;
|
|
269
|
-
}
|
|
270
|
-
return { fileCount: files.length, totalSize, files };
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
//# sourceMappingURL=context.js.map
|