locadex 0.0.2-alpha.1 → 0.0.2-alpha.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/.locadex-mcp-stdio.json +9 -0
- package/.locadex-mcp.json +2 -3
- package/LICENSE.md +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +44 -9
- package/dist/cli.js.map +1 -1
- package/dist/commands/i18n.d.ts +2 -1
- package/dist/commands/i18n.d.ts.map +1 -1
- package/dist/commands/i18n.js +255 -140
- package/dist/commands/i18n.js.map +1 -1
- package/dist/commands/setup.d.ts +1 -1
- package/dist/commands/setup.d.ts.map +1 -1
- package/dist/commands/setup.js +141 -86
- package/dist/commands/setup.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -68
- package/dist/index.js.map +1 -1
- package/dist/{utils/logging.d.ts → logging/console.d.ts} +9 -12
- package/dist/logging/console.d.ts.map +1 -0
- package/dist/logging/console.js +137 -0
- package/dist/logging/console.js.map +1 -0
- package/dist/logging/logger.d.ts +44 -0
- package/dist/logging/logger.d.ts.map +1 -0
- package/dist/logging/logger.js +142 -0
- package/dist/logging/logger.js.map +1 -0
- package/dist/mcp/debugger.d.ts +3 -0
- package/dist/mcp/debugger.d.ts.map +1 -0
- package/dist/mcp/debugger.js +37 -0
- package/dist/mcp/debugger.js.map +1 -0
- package/dist/mcp/getDocs.d.ts.map +1 -0
- package/dist/mcp/getDocs.js +56 -0
- package/dist/mcp/getDocs.js.map +1 -0
- package/dist/mcp/getGuide.d.ts +5 -0
- package/dist/mcp/getGuide.d.ts.map +1 -0
- package/dist/mcp/getGuide.js +17 -0
- package/dist/mcp/getGuide.js.map +1 -0
- package/dist/{tools → mcp/tools}/docs.d.ts +3 -0
- package/dist/mcp/tools/docs.d.ts.map +1 -0
- package/dist/mcp/tools/docs.js +86 -0
- package/dist/mcp/tools/docs.js.map +1 -0
- package/dist/mcp/tools/guides.d.ts +11 -0
- package/dist/mcp/tools/guides.d.ts.map +1 -0
- package/dist/mcp/tools/guides.js +118 -0
- package/dist/mcp/tools/guides.js.map +1 -0
- package/dist/mcp-sse.d.ts +3 -0
- package/dist/mcp-sse.d.ts.map +1 -0
- package/dist/mcp-sse.js +95 -0
- package/dist/mcp-sse.js.map +1 -0
- package/dist/mcp.d.ts +3 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +34 -0
- package/dist/mcp.js.map +1 -0
- package/dist/prompts/system.d.ts +4 -0
- package/dist/prompts/system.d.ts.map +1 -0
- package/dist/prompts/system.js +17 -0
- package/dist/prompts/system.js.map +1 -0
- package/dist/telemetry.d.ts +11 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +104 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/types/claude-sdk.d.ts +39 -0
- package/dist/types/claude-sdk.d.ts.map +1 -0
- package/dist/types/claude-sdk.js +5 -0
- package/dist/types/claude-sdk.js.map +1 -0
- package/dist/types/cli.d.ts +7 -0
- package/dist/types/cli.d.ts.map +1 -0
- package/dist/types/cli.js +5 -0
- package/dist/types/cli.js.map +1 -0
- package/dist/utils/agentManager.d.ts +34 -0
- package/dist/utils/agentManager.d.ts.map +1 -0
- package/dist/utils/agentManager.js +123 -0
- package/dist/utils/agentManager.js.map +1 -0
- package/dist/utils/claudeCode.d.ts +14 -6
- package/dist/utils/claudeCode.d.ts.map +1 -1
- package/dist/utils/claudeCode.js +170 -102
- package/dist/utils/claudeCode.js.map +1 -1
- package/dist/utils/dag/createDag.d.ts +24 -0
- package/dist/utils/dag/createDag.d.ts.map +1 -0
- package/dist/utils/dag/createDag.js +181 -0
- package/dist/utils/dag/createDag.js.map +1 -0
- package/dist/utils/debugLogger.d.ts +3 -0
- package/dist/utils/debugLogger.d.ts.map +1 -0
- package/dist/utils/debugLogger.js +36 -0
- package/dist/utils/debugLogger.js.map +1 -0
- package/dist/utils/fs/findConfigs.d.ts +11 -0
- package/dist/utils/fs/findConfigs.d.ts.map +1 -0
- package/dist/utils/fs/findConfigs.js +63 -0
- package/dist/utils/fs/findConfigs.js.map +1 -0
- package/dist/utils/fs/getFiles.d.ts +2 -0
- package/dist/utils/fs/getFiles.d.ts.map +1 -0
- package/dist/utils/fs/getFiles.js +8 -0
- package/dist/utils/fs/getFiles.js.map +1 -0
- package/dist/utils/fs/writeFiles.d.ts +2 -0
- package/dist/utils/fs/writeFiles.d.ts.map +1 -0
- package/dist/utils/fs/writeFiles.js +19 -0
- package/dist/utils/fs/writeFiles.js.map +1 -0
- package/dist/utils/getFiles.d.ts +30 -0
- package/dist/utils/getFiles.d.ts.map +1 -0
- package/dist/utils/getFiles.js +152 -0
- package/dist/utils/getFiles.js.map +1 -0
- package/dist/utils/getPaths.d.ts +1 -0
- package/dist/utils/getPaths.d.ts.map +1 -1
- package/dist/utils/getPaths.js +19 -3
- package/dist/utils/getPaths.js.map +1 -1
- package/dist/utils/mcpConfig.d.ts.map +1 -1
- package/dist/utils/mcpConfig.js +5 -2
- package/dist/utils/mcpConfig.js.map +1 -1
- package/dist/utils/shared.d.ts +4 -0
- package/dist/utils/shared.d.ts.map +1 -0
- package/dist/utils/shared.js +26 -0
- package/dist/utils/shared.js.map +1 -0
- package/dist/utils/stats.d.ts +25 -0
- package/dist/utils/stats.d.ts.map +1 -0
- package/dist/utils/stats.js +40 -0
- package/dist/utils/stats.js.map +1 -0
- package/dist/utils/validateConfig.d.ts +2 -0
- package/dist/utils/validateConfig.d.ts.map +1 -0
- package/dist/utils/validateConfig.js +12 -0
- package/dist/utils/validateConfig.js.map +1 -0
- package/guides/next/advanced/complicated-mapping-expressions.md +200 -0
- package/guides/next/advanced/interpolated-strings.md +162 -0
- package/guides/next/advanced/migrating.md +86 -0
- package/guides/next/advanced/ternary-operators.md +217 -0
- package/guides/next/advanced/var-outside-client-component.md +446 -0
- package/guides/next/advanced/var-outside-client-server-component.md +550 -0
- package/guides/next/advanced/var-outside-server-component.md +545 -0
- package/guides/next/basic/branches.md +310 -0
- package/guides/next/basic/client-side-components.md +221 -0
- package/guides/next/basic/jsx.md +268 -0
- package/guides/next/basic/server-side-components.md +165 -0
- package/guides/next/basic/strings.md +144 -0
- package/guides/next/basic/variables.md +161 -0
- package/guides/next/important/functions.md +37 -0
- package/package.json +27 -13
- package/dist/resources/docs.d.ts +0 -4
- package/dist/resources/docs.d.ts.map +0 -1
- package/dist/resources/docs.js +0 -176
- package/dist/resources/docs.js.map +0 -1
- package/dist/tools/docs.d.ts.map +0 -1
- package/dist/tools/docs.js +0 -140
- package/dist/tools/docs.js.map +0 -1
- package/dist/utils/getDocs.d.ts.map +0 -1
- package/dist/utils/getDocs.js +0 -113
- package/dist/utils/getDocs.js.map +0 -1
- package/dist/utils/logging.d.ts.map +0 -1
- package/dist/utils/logging.js +0 -226
- package/dist/utils/logging.js.map +0 -1
- /package/dist/{utils → mcp}/getDocs.d.ts +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claudeCode.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"claudeCode.d.ts","sourceRoot":"/","sources":["utils/claudeCode.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,WAAW,iBAAiB;IAChC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,sBAAsB,CAAC,EAAE,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;CAAG;AAmCzC,qBAAa,gBAAgB;IAOzB,OAAO,CAAC,OAAO;IANjB,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,SAAS,CAAqB;IACtC,OAAO,CAAC,OAAO,CAAiB;gBAG9B,OAAO,EAAE,cAAc,EACf,OAAO,GAAE;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,MAAM,CAAC;KACf;IAgBR,YAAY,IAAI,MAAM;IAIhB,GAAG,CACP,OAAO,EAAE,iBAAiB,EAC1B,GAAG,EAAE,qBAAqB,GACzB,OAAO,CAAC,MAAM,CAAC;IA4FlB,OAAO,CAAC,eAAe;CAiExB"}
|
package/dist/utils/claudeCode.js
CHANGED
|
@@ -1,114 +1,182 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
-
switch (op[0]) {
|
|
31
|
-
case 0: case 1: t = op; break;
|
|
32
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
-
default:
|
|
36
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
-
if (t[2]) _.ops.pop();
|
|
41
|
-
_.trys.pop(); continue;
|
|
1
|
+
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="241bc31c-ad73-55df-abfe-d38afdd90259")}catch(e){}}();
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { guides } from '../mcp/tools/guides.js';
|
|
6
|
+
import { logger } from '../logging/logger.js';
|
|
7
|
+
import { posthog } from '../telemetry.js';
|
|
8
|
+
const DEFAULT_ALLOWED_TOOLS = [
|
|
9
|
+
'mcp__locadex__fetch-docs',
|
|
10
|
+
'mcp__locadex__list-docs',
|
|
11
|
+
'Bash',
|
|
12
|
+
'Edit',
|
|
13
|
+
'MultiEdit',
|
|
14
|
+
'Write',
|
|
15
|
+
].concat(guides.map((guide) => `mcp__locadex__${guide.id}`));
|
|
16
|
+
const DISALLOWED_TOOLS = ['NotebookEdit', 'WebFetch', 'WebSearch'];
|
|
17
|
+
// Global tracking of all Claude processes
|
|
18
|
+
const activeClaudeProcesses = new Set();
|
|
19
|
+
// Setup global process termination handlers once
|
|
20
|
+
let handlersSetup = false;
|
|
21
|
+
const setupProcessHandlers = () => {
|
|
22
|
+
if (handlersSetup)
|
|
23
|
+
return;
|
|
24
|
+
handlersSetup = true;
|
|
25
|
+
const killAllClaudeProcesses = () => {
|
|
26
|
+
activeClaudeProcesses.forEach((proc) => {
|
|
27
|
+
if (!proc.killed) {
|
|
28
|
+
proc.kill('SIGTERM');
|
|
42
29
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
30
|
+
});
|
|
31
|
+
activeClaudeProcesses.clear();
|
|
32
|
+
};
|
|
33
|
+
process.on('SIGINT', killAllClaudeProcesses);
|
|
34
|
+
process.on('SIGTERM', killAllClaudeProcesses);
|
|
47
35
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
36
|
+
export class ClaudeCodeRunner {
|
|
37
|
+
options;
|
|
38
|
+
sessionId = '';
|
|
39
|
+
mcpConfig;
|
|
40
|
+
manager;
|
|
41
|
+
constructor(manager, options = {}) {
|
|
52
42
|
this.options = options;
|
|
43
|
+
this.manager = manager;
|
|
44
|
+
this.mcpConfig = options.mcpConfig;
|
|
53
45
|
// Ensure API key is set
|
|
54
46
|
if (!process.env.ANTHROPIC_API_KEY && !this.options.apiKey) {
|
|
55
47
|
throw new Error('ANTHROPIC_API_KEY environment variable or apiKey option is required');
|
|
56
48
|
}
|
|
49
|
+
// Setup global process handlers
|
|
50
|
+
setupProcessHandlers();
|
|
57
51
|
}
|
|
58
|
-
|
|
59
|
-
return
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
52
|
+
getSessionId() {
|
|
53
|
+
return this.sessionId;
|
|
54
|
+
}
|
|
55
|
+
async run(options, obs) {
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
const args = ['-p', options.prompt];
|
|
58
|
+
if (options.additionalSystemPrompt) {
|
|
59
|
+
args.push('--append-system-prompt', options.additionalSystemPrompt);
|
|
60
|
+
}
|
|
61
|
+
args.push('--output-format', 'stream-json');
|
|
62
|
+
args.push('--verbose');
|
|
63
|
+
if (options.sessionId) {
|
|
64
|
+
args.push('--resume', options.sessionId);
|
|
65
|
+
}
|
|
66
|
+
if (this.mcpConfig) {
|
|
67
|
+
args.push('--mcp-config', this.mcpConfig);
|
|
68
|
+
}
|
|
69
|
+
args.push('--allowedTools', [
|
|
70
|
+
...DEFAULT_ALLOWED_TOOLS,
|
|
71
|
+
...(options?.additionalAllowedTools || []),
|
|
72
|
+
].join(','));
|
|
73
|
+
args.push('--disallowedTools', DISALLOWED_TOOLS.join(','));
|
|
74
|
+
if (options.maxTurns) {
|
|
75
|
+
args.push('--max-turns', options.maxTurns.toString());
|
|
76
|
+
}
|
|
77
|
+
const env = { ...process.env };
|
|
78
|
+
if (this.options.apiKey) {
|
|
79
|
+
env.ANTHROPIC_API_KEY = this.options.apiKey;
|
|
80
|
+
}
|
|
81
|
+
const claude = spawn('npx', ['claude', ...args], {
|
|
82
|
+
stdio: ['inherit', 'pipe', 'pipe'],
|
|
83
|
+
env,
|
|
84
|
+
});
|
|
85
|
+
activeClaudeProcesses.add(claude);
|
|
86
|
+
const output = '';
|
|
87
|
+
const errorOutput = '';
|
|
88
|
+
let buffer = '';
|
|
89
|
+
claude.stdout?.on('data', (data) => {
|
|
90
|
+
buffer += data.toString();
|
|
91
|
+
const lines = buffer.split('\n');
|
|
92
|
+
// Keep the last incomplete line in buffer
|
|
93
|
+
buffer = lines.pop() || '';
|
|
94
|
+
for (const line of lines) {
|
|
95
|
+
if (line.trim()) {
|
|
96
|
+
try {
|
|
97
|
+
logger.debugMessage(`[Claude Code SDK] ${line}`);
|
|
98
|
+
const outputData = JSON.parse(line);
|
|
99
|
+
this.handleSDKOutput(outputData, obs);
|
|
79
100
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
env.ANTHROPIC_API_KEY = _this.options.apiKey;
|
|
101
|
+
catch (error) {
|
|
102
|
+
logger.debugMessage(`[Claude Code SDK] Failed to parse JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
83
103
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
claude.on('error', function (error) {
|
|
105
|
-
reject(new Error("Failed to run Claude Code: ".concat(error.message)));
|
|
106
|
-
});
|
|
107
|
-
})];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
claude.stderr?.on('data', () => {
|
|
108
|
+
logger.warning('An error occurred while running Claude Code');
|
|
109
|
+
});
|
|
110
|
+
claude.on('close', (code) => {
|
|
111
|
+
activeClaudeProcesses.delete(claude);
|
|
112
|
+
if (code === 0) {
|
|
113
|
+
resolve(output.trim());
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
reject(new Error(`Claude Code exited with code ${code}: ${errorOutput}`));
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
claude.on('error', (error) => {
|
|
120
|
+
activeClaudeProcesses.delete(claude);
|
|
121
|
+
reject(new Error(`Failed to run Claude Code: ${error.message}`));
|
|
108
122
|
});
|
|
109
123
|
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
124
|
+
}
|
|
125
|
+
handleSDKOutput(outputData, obs) {
|
|
126
|
+
if (outputData.type === 'assistant') {
|
|
127
|
+
const text = [];
|
|
128
|
+
const toolUses = [];
|
|
129
|
+
outputData.message.content.forEach((c) => {
|
|
130
|
+
if (c.type === 'text') {
|
|
131
|
+
text.push(c.text);
|
|
132
|
+
}
|
|
133
|
+
if (c.type === 'tool_use') {
|
|
134
|
+
toolUses.push(c.name);
|
|
135
|
+
if (c.name.startsWith('mcp__locadex__')) {
|
|
136
|
+
posthog.capture({
|
|
137
|
+
distinctId: this.sessionId
|
|
138
|
+
? createHash('sha256')
|
|
139
|
+
.update(this.sessionId)
|
|
140
|
+
.digest('base64url')
|
|
141
|
+
.slice(0, 8)
|
|
142
|
+
: 'anonymous',
|
|
143
|
+
event: 'tool_used',
|
|
144
|
+
properties: {
|
|
145
|
+
tool: c.name,
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
if (text.length > 0) {
|
|
152
|
+
logger.verboseMessage(text.join('').trim());
|
|
153
|
+
}
|
|
154
|
+
if (toolUses.length > 0) {
|
|
155
|
+
logger.debugMessage(`[Claude Code SDK] Used tools: ${toolUses.join(', ')}`);
|
|
156
|
+
}
|
|
157
|
+
this.manager.stats.updateStats({
|
|
158
|
+
newToolCalls: toolUses.length,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
else if (outputData.type === 'result') {
|
|
162
|
+
if (!outputData.is_error) {
|
|
163
|
+
logger.verboseMessage(`[Claude Code SDK] Finished\nCost: $${Number(outputData.cost_usd).toFixed(2)}\nDuration: ${Number(outputData.duration_ms) / 1000}s`);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
logger.verboseMessage(`[Claude Code SDK] Finished with error: ${outputData.subtype}\nCost: $${outputData.cost_usd}\nDuration: ${Number(outputData.duration_ms) / 1000}s`);
|
|
167
|
+
}
|
|
168
|
+
this.manager.stats.updateStats({
|
|
169
|
+
newCost: Number(outputData.cost_usd),
|
|
170
|
+
newWallDuration: Number(outputData.duration_ms),
|
|
171
|
+
newApiDuration: Number(outputData.duration_api_ms),
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
else if (outputData.type === 'system') {
|
|
175
|
+
if (outputData.subtype === 'init') {
|
|
176
|
+
this.sessionId = outputData.session_id;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=claudeCode.js.map
|
|
182
|
+
//# debugId=241bc31c-ad73-55df-abfe-d38afdd90259
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claudeCode.js","sourceRoot":"","sources":["../../src/utils/claudeCode.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oB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":3,"file":"claudeCode.js","sources":["utils/claudeCode.ts"],"sourceRoot":"/","sourcesContent":["import { spawn } from 'node:child_process';\nimport { createHash } from 'node:crypto';\nimport { ClaudeSDKMessage } from '../types/claude-sdk.js';\nimport { guides } from '../mcp/tools/guides.js';\nimport { SpinnerResult } from '@clack/prompts';\nimport { logger } from '../logging/logger.js';\nimport { posthog } from '../telemetry.js';\nimport { LocadexManager } from './agentManager.js';\n\nexport interface ClaudeCodeOptions {\n additionalSystemPrompt?: string;\n prompt: string;\n additionalAllowedTools?: string[];\n maxTurns?: number;\n sessionId?: string;\n}\n\nexport interface ClaudeCodeObservation {}\n\nconst DEFAULT_ALLOWED_TOOLS = [\n 'mcp__locadex__fetch-docs',\n 'mcp__locadex__list-docs',\n 'Bash',\n 'Edit',\n 'MultiEdit',\n 'Write',\n].concat(guides.map((guide) => `mcp__locadex__${guide.id}`));\n\nconst DISALLOWED_TOOLS = ['NotebookEdit', 'WebFetch', 'WebSearch'];\n\n// Global tracking of all Claude processes\nconst activeClaudeProcesses = new Set<any>();\n\n// Setup global process termination handlers once\nlet handlersSetup = false;\nconst setupProcessHandlers = () => {\n if (handlersSetup) return;\n handlersSetup = true;\n\n const killAllClaudeProcesses = () => {\n activeClaudeProcesses.forEach((proc) => {\n if (!proc.killed) {\n proc.kill('SIGTERM');\n }\n });\n activeClaudeProcesses.clear();\n };\n\n process.on('SIGINT', killAllClaudeProcesses);\n process.on('SIGTERM', killAllClaudeProcesses);\n};\n\nexport class ClaudeCodeRunner {\n private sessionId: string = '';\n private mcpConfig: string | undefined;\n private manager: LocadexManager;\n\n constructor(\n manager: LocadexManager,\n private options: {\n apiKey?: string;\n mcpConfig?: string;\n } = {}\n ) {\n this.manager = manager;\n this.mcpConfig = options.mcpConfig;\n\n // Ensure API key is set\n if (!process.env.ANTHROPIC_API_KEY && !this.options.apiKey) {\n throw new Error(\n 'ANTHROPIC_API_KEY environment variable or apiKey option is required'\n );\n }\n\n // Setup global process handlers\n setupProcessHandlers();\n }\n\n getSessionId(): string {\n return this.sessionId;\n }\n\n async run(\n options: ClaudeCodeOptions,\n obs: ClaudeCodeObservation\n ): Promise<string> {\n return new Promise((resolve, reject) => {\n const args = ['-p', options.prompt];\n\n if (options.additionalSystemPrompt) {\n args.push('--append-system-prompt', options.additionalSystemPrompt);\n }\n\n args.push('--output-format', 'stream-json');\n args.push('--verbose');\n if (options.sessionId) {\n args.push('--resume', options.sessionId);\n }\n\n if (this.mcpConfig) {\n args.push('--mcp-config', this.mcpConfig);\n }\n\n args.push(\n '--allowedTools',\n [\n ...DEFAULT_ALLOWED_TOOLS,\n ...(options?.additionalAllowedTools || []),\n ].join(',')\n );\n\n args.push('--disallowedTools', DISALLOWED_TOOLS.join(','));\n\n if (options.maxTurns) {\n args.push('--max-turns', options.maxTurns.toString());\n }\n\n const env = { ...process.env };\n if (this.options.apiKey) {\n env.ANTHROPIC_API_KEY = this.options.apiKey;\n }\n\n const claude = spawn('npx', ['claude', ...args], {\n stdio: ['inherit', 'pipe', 'pipe'],\n env,\n });\n\n activeClaudeProcesses.add(claude);\n\n const output = '';\n const errorOutput = '';\n\n let buffer = '';\n claude.stdout?.on('data', (data) => {\n buffer += data.toString();\n const lines = buffer.split('\\n');\n\n // Keep the last incomplete line in buffer\n buffer = lines.pop() || '';\n\n for (const line of lines) {\n if (line.trim()) {\n try {\n logger.debugMessage(`[Claude Code SDK] ${line}`);\n const outputData: ClaudeSDKMessage = JSON.parse(line);\n this.handleSDKOutput(outputData, obs);\n } catch (error) {\n logger.debugMessage(\n `[Claude Code SDK] Failed to parse JSON: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n }\n }\n });\n\n claude.stderr?.on('data', () => {\n logger.warning('An error occurred while running Claude Code');\n });\n\n claude.on('close', (code) => {\n activeClaudeProcesses.delete(claude);\n if (code === 0) {\n resolve(output.trim());\n } else {\n reject(\n new Error(`Claude Code exited with code ${code}: ${errorOutput}`)\n );\n }\n });\n\n claude.on('error', (error) => {\n activeClaudeProcesses.delete(claude);\n reject(new Error(`Failed to run Claude Code: ${error.message}`));\n });\n });\n }\n\n private handleSDKOutput(\n outputData: ClaudeSDKMessage,\n obs: ClaudeCodeObservation\n ) {\n if (outputData.type === 'assistant') {\n const text: string[] = [];\n const toolUses: string[] = [];\n outputData.message.content.forEach((c) => {\n if (c.type === 'text') {\n text.push(c.text);\n }\n if (c.type === 'tool_use') {\n toolUses.push(c.name);\n if (c.name.startsWith('mcp__locadex__')) {\n posthog.capture({\n distinctId: this.sessionId\n ? createHash('sha256')\n .update(this.sessionId)\n .digest('base64url')\n .slice(0, 8)\n : 'anonymous',\n event: 'tool_used',\n properties: {\n tool: c.name,\n },\n });\n }\n }\n });\n if (text.length > 0) {\n logger.verboseMessage(text.join('').trim());\n }\n if (toolUses.length > 0) {\n logger.debugMessage(\n `[Claude Code SDK] Used tools: ${toolUses.join(', ')}`\n );\n }\n this.manager.stats.updateStats({\n newToolCalls: toolUses.length,\n });\n } else if (outputData.type === 'result') {\n if (!outputData.is_error) {\n logger.verboseMessage(\n `[Claude Code SDK] Finished\\nCost: $${Number(outputData.cost_usd).toFixed(2)}\\nDuration: ${\n Number(outputData.duration_ms) / 1000\n }s`\n );\n } else {\n logger.verboseMessage(\n `[Claude Code SDK] Finished with error: ${outputData.subtype}\\nCost: $${outputData.cost_usd}\\nDuration: ${\n Number(outputData.duration_ms) / 1000\n }s`\n );\n }\n this.manager.stats.updateStats({\n newCost: Number(outputData.cost_usd),\n newWallDuration: Number(outputData.duration_ms),\n newApiDuration: Number(outputData.duration_api_ms),\n });\n } else if (outputData.type === 'system') {\n if (outputData.subtype === 'init') {\n this.sessionId = outputData.session_id;\n }\n }\n }\n}\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD,OAAO,EAAE,MAA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
5
|
+
};
|
|
6
|
+
export type DagNode = {
|
|
7
|
+
[filename: string]: DagNode;
|
|
8
|
+
};
|
|
9
|
+
export declare class Dag {
|
|
10
|
+
private dag;
|
|
11
|
+
private reverseDag;
|
|
12
|
+
private dependenciesMap;
|
|
13
|
+
private topologicalOrder;
|
|
14
|
+
constructor(dag: DagNode);
|
|
15
|
+
private buildMaps;
|
|
16
|
+
private buildTopologicalOrder;
|
|
17
|
+
getDependencies(filename: string): string[];
|
|
18
|
+
getDependents(filename: string): string[];
|
|
19
|
+
getDag(): DagNode;
|
|
20
|
+
getReverseDag(): Record<string, string[]>;
|
|
21
|
+
getTopologicalOrder(): string[];
|
|
22
|
+
}
|
|
23
|
+
export declare function createDag(directories: string[], options: DagOptions): Dag;
|
|
24
|
+
//# sourceMappingURL=createDag.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createDag.d.ts","sourceRoot":"/","sources":["utils/dag/createDag.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC7B,CAAC;AAEF,qBAAa,GAAG;IACd,OAAO,CAAC,GAAG,CAAU;IACrB,OAAO,CAAC,UAAU,CAA2B;IAC7C,OAAO,CAAC,eAAe,CAA2B;IAClD,OAAO,CAAC,gBAAgB,CAAW;gBAEvB,GAAG,EAAE,OAAO;IAQxB,OAAO,CAAC,SAAS;IAsCjB,OAAO,CAAC,qBAAqB;IAwB7B,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE;IAK3C,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE;IAKzC,MAAM,IAAI,OAAO;IAIjB,aAAa,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAIzC,mBAAmB,IAAI,MAAM,EAAE;CAGhC;AAED,wBAAgB,SAAS,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,UAAU,GAAG,GAAG,CAkCzE"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="cd961cb2-0d8b-56a7-b051-57bc0119565f")}catch(e){}}();
|
|
3
|
+
import { logger } from '../../logging/logger.js';
|
|
4
|
+
import dependencyTree from 'dependency-tree';
|
|
5
|
+
import * as fs from 'node:fs';
|
|
6
|
+
import * as path from 'node:path';
|
|
7
|
+
import { DAG_IGNORED_EXTENSIONS, DAG_IGNORED_FILES } from '../shared.js';
|
|
8
|
+
export class Dag {
|
|
9
|
+
dag;
|
|
10
|
+
reverseDag;
|
|
11
|
+
dependenciesMap;
|
|
12
|
+
topologicalOrder;
|
|
13
|
+
constructor(dag) {
|
|
14
|
+
this.dag = dag;
|
|
15
|
+
const { reverseDag, dependenciesMap } = this.buildMaps(dag);
|
|
16
|
+
this.reverseDag = reverseDag;
|
|
17
|
+
this.dependenciesMap = dependenciesMap;
|
|
18
|
+
this.topologicalOrder = this.buildTopologicalOrder();
|
|
19
|
+
}
|
|
20
|
+
buildMaps(dag) {
|
|
21
|
+
const reverseDag = {};
|
|
22
|
+
const dependenciesMap = {};
|
|
23
|
+
// Clean the file paths recursively
|
|
24
|
+
const cleanedDag = cleanFilePaths(dag);
|
|
25
|
+
function traverse(node, parent) {
|
|
26
|
+
for (const [filename, subtree] of Object.entries(node)) {
|
|
27
|
+
// Build dependencies map - direct dependencies are the keys of subtree
|
|
28
|
+
if (!dependenciesMap[filename]) {
|
|
29
|
+
dependenciesMap[filename] = Object.keys(subtree);
|
|
30
|
+
}
|
|
31
|
+
// Build reverse DAG - if we have a parent, parent depends on filename
|
|
32
|
+
// So filename has parent as a dependent
|
|
33
|
+
if (parent) {
|
|
34
|
+
if (!reverseDag[filename]) {
|
|
35
|
+
reverseDag[filename] = [];
|
|
36
|
+
}
|
|
37
|
+
reverseDag[filename].push(parent);
|
|
38
|
+
}
|
|
39
|
+
// Recursively traverse the subtree
|
|
40
|
+
if (typeof subtree === 'object' && subtree !== null) {
|
|
41
|
+
traverse(subtree, filename);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
traverse(cleanedDag);
|
|
46
|
+
return { reverseDag, dependenciesMap };
|
|
47
|
+
}
|
|
48
|
+
// No need to worry about cycles since the DAG is a tree
|
|
49
|
+
buildTopologicalOrder() {
|
|
50
|
+
const visited = new Set();
|
|
51
|
+
const result = [];
|
|
52
|
+
const dfs = (file) => {
|
|
53
|
+
if (visited.has(file))
|
|
54
|
+
return;
|
|
55
|
+
visited.add(file);
|
|
56
|
+
const dependencies = this.dependenciesMap[file] || [];
|
|
57
|
+
for (const dep of dependencies) {
|
|
58
|
+
dfs(dep);
|
|
59
|
+
}
|
|
60
|
+
result.push(file);
|
|
61
|
+
};
|
|
62
|
+
// Visit all files in the DAG
|
|
63
|
+
for (const file of Object.keys(this.dependenciesMap)) {
|
|
64
|
+
dfs(file);
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
// Get all direct dependencies of a file
|
|
69
|
+
getDependencies(filename) {
|
|
70
|
+
// return this.dependenciesMap[filename] || [];
|
|
71
|
+
return this.reverseDag[filename] || [];
|
|
72
|
+
}
|
|
73
|
+
// Get all children of a file
|
|
74
|
+
getDependents(filename) {
|
|
75
|
+
// return this.reverseDag[filename] || [];
|
|
76
|
+
return this.dependenciesMap[filename] || [];
|
|
77
|
+
}
|
|
78
|
+
getDag() {
|
|
79
|
+
return this.dag;
|
|
80
|
+
}
|
|
81
|
+
getReverseDag() {
|
|
82
|
+
return this.reverseDag;
|
|
83
|
+
}
|
|
84
|
+
getTopologicalOrder() {
|
|
85
|
+
return this.topologicalOrder;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export function createDag(directories, options) {
|
|
89
|
+
const allTrees = [];
|
|
90
|
+
const visited = {};
|
|
91
|
+
const nonExistent = [];
|
|
92
|
+
const files = discoverSourceFiles(directories);
|
|
93
|
+
logger.debugMessage(`Creating combined tree for ${files.length} files and ${directories.length} directories`);
|
|
94
|
+
files.forEach((file) => {
|
|
95
|
+
if (visited[file]) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const tree = dependencyTree({
|
|
100
|
+
directory: process.cwd(),
|
|
101
|
+
filename: file,
|
|
102
|
+
filter: (path) => !path.includes('node_modules'),
|
|
103
|
+
visited: visited,
|
|
104
|
+
nonExistent: nonExistent,
|
|
105
|
+
tsConfig: options.tsConfig,
|
|
106
|
+
webpackConfig: options.webpackConfig,
|
|
107
|
+
requireConfig: options.requireConfig,
|
|
108
|
+
});
|
|
109
|
+
allTrees.push(tree);
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
logger.debugMessage(`Failed to create tree for ${file}: ${error}`);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
return new Dag(mergeTrees(allTrees));
|
|
116
|
+
}
|
|
117
|
+
function cleanFilePath(filePath) {
|
|
118
|
+
return path.relative(process.cwd(), filePath);
|
|
119
|
+
}
|
|
120
|
+
function cleanFilePaths(dag) {
|
|
121
|
+
const result = {};
|
|
122
|
+
for (const [filename, subtree] of Object.entries(dag)) {
|
|
123
|
+
const cleanedFilename = cleanFilePath(filename);
|
|
124
|
+
result[cleanedFilename] = cleanFilePaths(subtree);
|
|
125
|
+
}
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
function mergeTrees(trees) {
|
|
129
|
+
const result = {};
|
|
130
|
+
function mergeTree(tree, target) {
|
|
131
|
+
if (typeof tree === 'object' && tree !== null) {
|
|
132
|
+
for (const [filename, subtree] of Object.entries(tree)) {
|
|
133
|
+
if (!target[filename]) {
|
|
134
|
+
target[filename] = {};
|
|
135
|
+
}
|
|
136
|
+
mergeTree(subtree, target[filename]);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// Process each tree
|
|
141
|
+
trees.forEach((tree) => {
|
|
142
|
+
mergeTree(tree, result);
|
|
143
|
+
});
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
function discoverSourceFiles(directories) {
|
|
147
|
+
const files = [];
|
|
148
|
+
const extensions = ['.ts', '.tsx', '.js', '.jsx'];
|
|
149
|
+
function walkDirectory(dir) {
|
|
150
|
+
if (!fs.existsSync(dir))
|
|
151
|
+
return;
|
|
152
|
+
const items = fs.readdirSync(dir);
|
|
153
|
+
for (const item of items) {
|
|
154
|
+
const fullPath = path.join(dir, item);
|
|
155
|
+
const stat = fs.statSync(fullPath);
|
|
156
|
+
if (stat.isDirectory()) {
|
|
157
|
+
// Skip node_modules and common build/cache directories
|
|
158
|
+
if (!['node_modules', '.next', 'dist', 'build', '.git'].includes(item)) {
|
|
159
|
+
walkDirectory(fullPath);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else if (stat.isFile()) {
|
|
163
|
+
const ext = path.extname(item);
|
|
164
|
+
// Skip blacklisted extensions and files
|
|
165
|
+
if (DAG_IGNORED_EXTENSIONS.includes(ext) ||
|
|
166
|
+
DAG_IGNORED_FILES.includes(item)) {
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (extensions.includes(ext)) {
|
|
170
|
+
files.push(fullPath);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
for (const directory of directories) {
|
|
176
|
+
walkDirectory(directory);
|
|
177
|
+
}
|
|
178
|
+
return files;
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=createDag.js.map
|
|
181
|
+
//# debugId=cd961cb2-0d8b-56a7-b051-57bc0119565f
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createDag.js","sources":["utils/dag/createDag.ts"],"sourceRoot":"/","sourcesContent":["import { logger } from '../../logging/logger.js';\nimport dependencyTree, { Tree } from 'dependency-tree';\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { DAG_IGNORED_EXTENSIONS, DAG_IGNORED_FILES } from '../shared.js';\n\nexport type DagOptions = {\n tsConfig?: string;\n webpackConfig?: string;\n requireConfig?: string;\n};\n\nexport type DagNode = {\n [filename: string]: DagNode;\n};\n\nexport class Dag {\n private dag: DagNode;\n private reverseDag: Record<string, string[]>;\n private dependenciesMap: Record<string, string[]>;\n private topologicalOrder: string[];\n\n constructor(dag: DagNode) {\n this.dag = dag;\n const { reverseDag, dependenciesMap } = this.buildMaps(dag);\n this.reverseDag = reverseDag;\n this.dependenciesMap = dependenciesMap;\n this.topologicalOrder = this.buildTopologicalOrder();\n }\n\n private buildMaps(dag: DagNode): {\n reverseDag: Record<string, string[]>;\n dependenciesMap: Record<string, string[]>;\n } {\n const reverseDag: Record<string, string[]> = {};\n const dependenciesMap: Record<string, string[]> = {};\n\n // Clean the file paths recursively\n const cleanedDag = cleanFilePaths(dag);\n\n function traverse(node: DagNode, parent?: string): void {\n for (const [filename, subtree] of Object.entries(node)) {\n // Build dependencies map - direct dependencies are the keys of subtree\n if (!dependenciesMap[filename]) {\n dependenciesMap[filename] = Object.keys(subtree);\n }\n\n // Build reverse DAG - if we have a parent, parent depends on filename\n // So filename has parent as a dependent\n if (parent) {\n if (!reverseDag[filename]) {\n reverseDag[filename] = [];\n }\n reverseDag[filename].push(parent);\n }\n\n // Recursively traverse the subtree\n if (typeof subtree === 'object' && subtree !== null) {\n traverse(subtree, filename);\n }\n }\n }\n\n traverse(cleanedDag);\n return { reverseDag, dependenciesMap };\n }\n\n // No need to worry about cycles since the DAG is a tree\n private buildTopologicalOrder(): string[] {\n const visited = new Set<string>();\n const result: string[] = [];\n\n const dfs = (file: string) => {\n if (visited.has(file)) return;\n visited.add(file);\n\n const dependencies = this.dependenciesMap[file] || [];\n for (const dep of dependencies) {\n dfs(dep);\n }\n\n result.push(file);\n };\n\n // Visit all files in the DAG\n for (const file of Object.keys(this.dependenciesMap)) {\n dfs(file);\n }\n\n return result;\n }\n // Get all direct dependencies of a file\n getDependencies(filename: string): string[] {\n // return this.dependenciesMap[filename] || [];\n return this.reverseDag[filename] || [];\n }\n // Get all children of a file\n getDependents(filename: string): string[] {\n // return this.reverseDag[filename] || [];\n return this.dependenciesMap[filename] || [];\n }\n\n getDag(): DagNode {\n return this.dag;\n }\n\n getReverseDag(): Record<string, string[]> {\n return this.reverseDag;\n }\n\n getTopologicalOrder(): string[] {\n return this.topologicalOrder;\n }\n}\n\nexport function createDag(directories: string[], options: DagOptions): Dag {\n const allTrees: Tree[] = [];\n const visited: dependencyTree.Tree = {};\n const nonExistent: string[] = [];\n\n const files = discoverSourceFiles(directories);\n\n logger.debugMessage(\n `Creating combined tree for ${files.length} files and ${directories.length} directories`\n );\n\n files.forEach((file) => {\n if (visited[file]) {\n return;\n }\n\n try {\n const tree = dependencyTree({\n directory: process.cwd(),\n filename: file,\n filter: (path: string) => !path.includes('node_modules'),\n visited: visited,\n nonExistent: nonExistent,\n tsConfig: options.tsConfig,\n webpackConfig: options.webpackConfig,\n requireConfig: options.requireConfig,\n });\n allTrees.push(tree);\n } catch (error) {\n logger.debugMessage(`Failed to create tree for ${file}: ${error}`);\n }\n });\n\n return new Dag(mergeTrees(allTrees));\n}\n\nfunction cleanFilePath(filePath: string): string {\n return path.relative(process.cwd(), filePath);\n}\n\nfunction cleanFilePaths(dag: DagNode): DagNode {\n const result: DagNode = {};\n\n for (const [filename, subtree] of Object.entries(dag)) {\n const cleanedFilename = cleanFilePath(filename);\n result[cleanedFilename] = cleanFilePaths(subtree);\n }\n\n return result;\n}\n\nfunction mergeTrees(trees: Tree[]): DagNode {\n const result: DagNode = {};\n\n function mergeTree(tree: Tree, target: DagNode): void {\n if (typeof tree === 'object' && tree !== null) {\n for (const [filename, subtree] of Object.entries(tree)) {\n if (!target[filename]) {\n target[filename] = {};\n }\n mergeTree(subtree, target[filename]);\n }\n }\n }\n\n // Process each tree\n trees.forEach((tree) => {\n mergeTree(tree, result);\n });\n\n return result;\n}\n\nfunction discoverSourceFiles(directories: string[]): string[] {\n const files: string[] = [];\n const extensions = ['.ts', '.tsx', '.js', '.jsx'];\n\n function walkDirectory(dir: string) {\n if (!fs.existsSync(dir)) return;\n\n const items = fs.readdirSync(dir);\n\n for (const item of items) {\n const fullPath = path.join(dir, item);\n const stat = fs.statSync(fullPath);\n\n if (stat.isDirectory()) {\n // Skip node_modules and common build/cache directories\n if (\n !['node_modules', '.next', 'dist', 'build', '.git'].includes(item)\n ) {\n walkDirectory(fullPath);\n }\n } else if (stat.isFile()) {\n const ext = path.extname(item);\n\n // Skip blacklisted extensions and files\n if (\n DAG_IGNORED_EXTENSIONS.includes(ext) ||\n DAG_IGNORED_FILES.includes(item)\n ) {\n continue;\n }\n\n if (extensions.includes(ext)) {\n files.push(fullPath);\n }\n }\n }\n }\n\n for (const directory of directories) {\n walkDirectory(directory);\n }\n\n return files;\n}\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,cAAwB,MAAM,iBAAiB,CAAC;AACvD,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAYzE,MAAM,OAAO,GAAG;IACN,GAAG,CAAU;IACb,UAAU,CAA2B;IACrC,eAAe,CAA2B;IAC1C,gBAAgB,CAAW;IAEnC,YAAY,GAAY;QACtB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf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ogger.ts"],"names":[],"mappings":"AAqBA,wBAAgB,QAAQ,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAgB7C;AAED,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="728d6d1d-2ed7-569b-8a04-bbe65558e2ba")}catch(e){}}();
|
|
3
|
+
import { existsSync, mkdirSync, appendFileSync } from 'node:fs';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { randomBytes } from 'node:crypto';
|
|
6
|
+
let debugLogPath = null;
|
|
7
|
+
function getDebugLogPath() {
|
|
8
|
+
if (!debugLogPath) {
|
|
9
|
+
const uniqueId = randomBytes(8).toString('hex');
|
|
10
|
+
const debugDir = join(process.cwd(), '.tmp', uniqueId);
|
|
11
|
+
if (!existsSync(debugDir)) {
|
|
12
|
+
mkdirSync(debugDir, { recursive: true });
|
|
13
|
+
}
|
|
14
|
+
debugLogPath = join(debugDir, 'out.txt');
|
|
15
|
+
}
|
|
16
|
+
return debugLogPath;
|
|
17
|
+
}
|
|
18
|
+
export function debugLog(...args) {
|
|
19
|
+
const logPath = getDebugLogPath();
|
|
20
|
+
const timestamp = new Date().toISOString();
|
|
21
|
+
const message = args.map(arg => typeof arg === 'object' ? JSON.stringify(arg, null, 2) : String(arg)).join(' ');
|
|
22
|
+
const logEntry = `[${timestamp}] ${message}\n`;
|
|
23
|
+
try {
|
|
24
|
+
appendFileSync(logPath, logEntry);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
// Fallback to console if file writing fails
|
|
28
|
+
console.error('Debug log write failed:', error);
|
|
29
|
+
console.log(...args);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function getDebugLogLocation() {
|
|
33
|
+
return getDebugLogPath();
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=debugLogger.js.map
|
|
36
|
+
//# debugId=728d6d1d-2ed7-569b-8a04-bbe65558e2ba
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debugLogger.js","sources":["utils/debugLogger.ts"],"sourceRoot":"/","sourcesContent":["import { writeFileSync, existsSync, mkdirSync, appendFileSync } from 'node:fs';\nimport { join, dirname } from 'node:path';\nimport { randomBytes } from 'node:crypto';\n\nlet debugLogPath: string | null = null;\n\nfunction getDebugLogPath(): string {\n if (!debugLogPath) {\n const uniqueId = randomBytes(8).toString('hex');\n const debugDir = join(process.cwd(), '.tmp', uniqueId);\n \n if (!existsSync(debugDir)) {\n mkdirSync(debugDir, { recursive: true });\n }\n \n debugLogPath = join(debugDir, 'out.txt');\n }\n \n return debugLogPath;\n}\n\nexport function debugLog(...args: any[]): void {\n const logPath = getDebugLogPath();\n const timestamp = new Date().toISOString();\n const message = args.map(arg => \n typeof arg === 'object' ? JSON.stringify(arg, null, 2) : String(arg)\n ).join(' ');\n \n const logEntry = `[${timestamp}] ${message}\\n`;\n \n try {\n appendFileSync(logPath, logEntry);\n } catch (error) {\n // Fallback to console if file writing fails\n console.error('Debug log write failed:', error);\n console.log(...args);\n }\n}\n\nexport function getDebugLogLocation(): string {\n return getDebugLogPath();\n}"],"names":[],"mappings":";;AAAA,OAAO,EAAiB,UAAU,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC/E,OAAO,EAAE,IAAI,EAAW,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,IAAI,YAAY,GAAkB,IAAI,CAAC;AAEvC,SAAS,eAAe;IACtB,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAA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-0,0 +1,11 @@
|
|
|
1
|
+
export declare function findTsConfig(): string | undefined;
|
|
2
|
+
export declare function findWebpackConfig(): string | undefined;
|
|
3
|
+
/**
|
|
4
|
+
* Resolve the file paths from the given file paths or default paths.
|
|
5
|
+
* @param {string[]} paths - The file paths to resolve.
|
|
6
|
+
* @param {string} errorMessage - The error message to throw if no paths are found.
|
|
7
|
+
* @returns {string[]} - The resolved file paths.
|
|
8
|
+
*/
|
|
9
|
+
export declare function findRequireConfig(): string | undefined;
|
|
10
|
+
export declare function findFilepaths(paths: string[]): string[];
|
|
11
|
+
//# sourceMappingURL=findConfigs.d.ts.map
|