locadex 0.1.0-alpha.4 → 0.1.0-alpha.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/tasks/i18n.d.ts.map +1 -1
- package/dist/tasks/i18n.js +9 -9
- package/dist/tasks/i18n.js.map +1 -1
- package/dist/tasks/setup.d.ts.map +1 -1
- package/dist/tasks/setup.js +4 -4
- package/dist/tasks/setup.js.map +1 -1
- package/dist/utils/claudeCode.d.ts +1 -1
- package/dist/utils/claudeCode.d.ts.map +1 -1
- package/dist/utils/claudeCode.js +23 -28
- package/dist/utils/claudeCode.js.map +1 -1
- package/dist/utils/locadexManager.d.ts +3 -0
- package/dist/utils/locadexManager.d.ts.map +1 -1
- package/dist/utils/locadexManager.js +28 -11
- package/dist/utils/locadexManager.js.map +1 -1
- package/dist/utils/packages/installPackage.d.ts.map +1 -1
- package/dist/utils/packages/installPackage.js +12 -4
- package/dist/utils/packages/installPackage.js.map +1 -1
- package/package.json +1 -1
package/dist/tasks/i18n.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i18n.d.ts","sourceRoot":"/","sources":["tasks/i18n.ts"],"names":[],"mappings":"AAgCA,wBAAsB,QAAQ,
|
|
1
|
+
{"version":3,"file":"i18n.d.ts","sourceRoot":"/","sources":["tasks/i18n.ts"],"names":[],"mappings":"AAgCA,wBAAsB,QAAQ,kBAsT7B"}
|
package/dist/tasks/i18n.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
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]="
|
|
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]="f99eaeb7-c766-572e-a2a4-a4b5c61d53b1")}catch(e){}}();
|
|
3
3
|
import { createSpinner } from '../logging/console.js';
|
|
4
4
|
import { allMcpPrompt } from '../prompts/system.js';
|
|
5
5
|
import { exit } from '../utils/shutdown.js';
|
|
@@ -66,7 +66,7 @@ export async function i18nTask() {
|
|
|
66
66
|
logger.progressBar.start(`Processing ${taskQueue.length} files...`);
|
|
67
67
|
// Main parallel processing loop
|
|
68
68
|
let processedCount = 0;
|
|
69
|
-
const
|
|
69
|
+
const agentAbortController = manager.getAgentAbortController();
|
|
70
70
|
let firstError = null;
|
|
71
71
|
// Mutex for task queue access
|
|
72
72
|
let taskQueueMutex = Promise.resolve();
|
|
@@ -82,9 +82,9 @@ export async function i18nTask() {
|
|
|
82
82
|
});
|
|
83
83
|
};
|
|
84
84
|
const processTask = async () => {
|
|
85
|
-
while (taskQueue.length > 0 && !
|
|
85
|
+
while (taskQueue.length > 0 && !agentAbortController.signal.aborted) {
|
|
86
86
|
// Check if we should abort early
|
|
87
|
-
if (
|
|
87
|
+
if (agentAbortController.signal.aborted) {
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
90
90
|
// Get an available agent atomically
|
|
@@ -93,7 +93,7 @@ export async function i18nTask() {
|
|
|
93
93
|
// No available agents, wait a bit (but check for abort)
|
|
94
94
|
await new Promise((resolve) => {
|
|
95
95
|
const timeout = global.setTimeout(resolve, 100);
|
|
96
|
-
|
|
96
|
+
agentAbortController.signal.addEventListener('abort', () => {
|
|
97
97
|
global.clearTimeout(timeout);
|
|
98
98
|
resolve(undefined);
|
|
99
99
|
});
|
|
@@ -129,7 +129,7 @@ export async function i18nTask() {
|
|
|
129
129
|
await agent.run({
|
|
130
130
|
prompt,
|
|
131
131
|
sessionId,
|
|
132
|
-
}, {});
|
|
132
|
+
}, {}, agentAbortController);
|
|
133
133
|
reports.push(agent.generateReport());
|
|
134
134
|
manager.markAgentFree(agentId);
|
|
135
135
|
}
|
|
@@ -138,7 +138,7 @@ export async function i18nTask() {
|
|
|
138
138
|
if (!firstError) {
|
|
139
139
|
firstError = new Error(`[i18n] Error in claude i18n process (agent ${agentId}): ${error}`);
|
|
140
140
|
logger.debugMessage(firstError.message);
|
|
141
|
-
|
|
141
|
+
agentAbortController.abort();
|
|
142
142
|
manager.cleanupAgents();
|
|
143
143
|
}
|
|
144
144
|
manager.markAgentFree(agentId);
|
|
@@ -185,7 +185,7 @@ export async function i18nTask() {
|
|
|
185
185
|
logger.spinner.start('Fixing errors...');
|
|
186
186
|
const fixPrompt = getFixPrompt();
|
|
187
187
|
try {
|
|
188
|
-
await cleanupAgent.run({ prompt: fixPrompt, sessionId: cleanupAgent.getSessionId() }, {});
|
|
188
|
+
await cleanupAgent.run({ prompt: fixPrompt, sessionId: cleanupAgent.getSessionId() }, {}, manager.getAgentAbortController());
|
|
189
189
|
reports.push(`## Fixed errors\n${cleanupAgent.generateReport()}`);
|
|
190
190
|
}
|
|
191
191
|
catch (error) {
|
|
@@ -333,4 +333,4 @@ ${allMcpPrompt}
|
|
|
333
333
|
return prompt;
|
|
334
334
|
}
|
|
335
335
|
//# sourceMappingURL=i18n.js.map
|
|
336
|
-
//# debugId=
|
|
336
|
+
//# debugId=f99eaeb7-c766-572e-a2a4-a4b5c61d53b1
|
package/dist/tasks/i18n.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i18n.js","sources":["tasks/i18n.ts"],"sourceRoot":"/","sourcesContent":["import { createSpinner } from '../logging/console.js';\nimport { allMcpPrompt } from '../prompts/system.js';\nimport { exit } from '../utils/shutdown.js';\n\nimport { logger } from '../logging/logger.js';\nimport { createDag } from '../utils/dag/createDag.js';\nimport {\n findTsConfig,\n findWebpackConfig,\n findRequireConfig,\n} from '../utils/fs/findConfigs.js';\nimport { LocadexManager } from '../utils/locadexManager.js';\nimport {\n addFilesToManager,\n markFileAsEdited,\n markFileAsInProgress,\n} from '../utils/dag/getFiles.js';\nimport { outro } from '@clack/prompts';\nimport chalk from 'chalk';\nimport { appendFileSync } from 'node:fs';\nimport { validateInitialConfig } from '../utils/config.js';\nimport { detectFormatter, formatFiles } from 'gtx-cli/hooks/postProcess';\nimport { generateSettings } from 'gtx-cli/config/generateSettings';\nimport path from 'node:path';\nimport { findSourceFiles } from '../utils/dag/matchFiles.js';\nimport {\n getChangedFiles,\n updateLockfile,\n cleanupLockfile,\n} from '../utils/lockfile.js';\nimport { installClaudeCode } from '../utils/packages/installPackage.js';\n\nexport async function i18nTask() {\n await validateInitialConfig();\n\n const gtSettings = await generateSettings({});\n if (gtSettings.framework !== 'next-app') {\n logger.error(\n 'Currently, locadex only supports Next.js App Router. Please use Next.js App Router.'\n );\n await exit(1);\n }\n\n // Install claude-code if not installed\n await installClaudeCode();\n\n // Init message\n const spinner = createSpinner();\n spinner.start('Initializing Locadex...');\n const manager = LocadexManager.getInstance();\n\n const config = manager.getConfig();\n\n const allFiles = findSourceFiles(\n config.matchingFiles,\n config.matchingExtensions\n );\n\n // Get lockfile path from manager\n const lockfilePath = manager.getLockFilePath();\n\n // Filter files to only include those with changed content hashes\n const changedFiles = getChangedFiles(allFiles, lockfilePath);\n\n if (changedFiles.length === 0) {\n spinner.stop('No files have changed since last run');\n outro(chalk.green('✅ Locadex i18n complete - no changes detected!'));\n await exit(0);\n }\n\n logger.verboseMessage(\n `Processing ${changedFiles.length} changed files out of ${allFiles.length} total files`\n );\n\n const dag = createDag(changedFiles, {\n tsConfig: findTsConfig(),\n webpackConfig: findWebpackConfig(),\n requireConfig: findRequireConfig(),\n });\n\n const filesStateFilePath = manager.getFilesStateFilePath();\n const concurrency = manager.getMaxConcurrency();\n const batchSize = manager.getBatchSize();\n\n // Create the list of files (aka tasks) to process\n const taskQueue = [...dag.getTopologicalOrder()];\n const topologicalOrder = [...dag.getTopologicalOrder()];\n\n // Add files to manager\n const stateFilePath = addFilesToManager(filesStateFilePath, taskQueue);\n spinner.stop('Locadex initialized');\n\n logger.verboseMessage(\n `Number of files to process: ${dag.getTopologicalOrder().length}`\n );\n logger.message(`Using ${concurrency} concurrent agents`);\n logger.debugMessage(`Track progress here: ${stateFilePath}`);\n logger.debugMessage(`Order:\\n${taskQueue.join('\\n')}`);\n\n logger.initializeProgressBar(taskQueue.length);\n\n const fileProcessingStartTime = Date.now();\n logger.progressBar.start(`Processing ${taskQueue.length} files...`);\n\n // Main parallel processing loop\n let processedCount = 0;\n const abortController = new AbortController();\n let firstError: Error | null = null;\n\n // Mutex for task queue access\n let taskQueueMutex = Promise.resolve();\n\n // Shared across all agents\n const reports: string[] = [];\n\n // Helper function to safely get tasks from queue\n const getNextTasks = async (batchSize: number): Promise<string[]> => {\n return new Promise((resolve) => {\n taskQueueMutex = taskQueueMutex.then(() => {\n const tasks = taskQueue.splice(0, batchSize);\n resolve(tasks);\n });\n });\n };\n\n const processTask = async (): Promise<void> => {\n while (taskQueue.length > 0 && !abortController.signal.aborted) {\n // Check if we should abort early\n if (abortController.signal.aborted) {\n return;\n }\n\n // Get an available agent atomically\n const agentInfo = await manager.getAvailableAgent();\n if (!agentInfo) {\n // No available agents, wait a bit (but check for abort)\n await new Promise((resolve) => {\n const timeout = global.setTimeout(resolve, 100);\n abortController.signal.addEventListener('abort', () => {\n global.clearTimeout(timeout);\n resolve(undefined);\n });\n });\n continue;\n }\n\n const { id: agentId, agent, sessionId } = agentInfo;\n\n // Get the next batch of tasks (thread-safe)\n const tasks = await getNextTasks(batchSize);\n if (tasks.length === 0) {\n manager.markAgentFree(agentId);\n break;\n }\n\n logger.debugMessage(\n `Using agent ${agentId} for ${batchSize} files. Files: ${tasks.join(\n ', '\n )}`\n );\n\n // Mark tasks as in progress\n await Promise.all(\n tasks.map((task) => markFileAsInProgress(task, filesStateFilePath))\n );\n\n // Construct prompt\n const dependencies = Object.fromEntries(\n tasks.map((task) => [\n task,\n Array.from(new Set(dag.getDependencies(task))),\n ])\n );\n const dependents = Object.fromEntries(\n tasks.map((task) => [\n task,\n Array.from(new Set(dag.getDependents(task))),\n ])\n );\n const prompt = getPrompt({\n targetFile: tasks,\n dependencyFiles: dependencies,\n dependentFiles: dependents,\n });\n\n // Claude call\n try {\n await agent.run(\n {\n prompt,\n sessionId,\n },\n {}\n );\n reports.push(agent.generateReport());\n manager.markAgentFree(agentId);\n } catch (error) {\n // Capture the first error and signal all other agents to abort\n if (!firstError) {\n firstError = new Error(\n `[i18n] Error in claude i18n process (agent ${agentId}): ${error}`\n );\n logger.debugMessage(firstError.message);\n abortController.abort();\n manager.cleanupAgents();\n }\n manager.markAgentFree(agentId);\n return; // Exit this agent's processing immediately\n }\n\n // Mark tasks as complete\n await Promise.all(\n tasks.map((task) => markFileAsEdited(task, filesStateFilePath))\n );\n processedCount += tasks.length;\n logger.progressBar.advance(\n tasks.length,\n `Processed ${Number((processedCount / topologicalOrder.length) * 100).toFixed(2)}% of files`\n );\n manager.stats.updateStats({\n newProcessedFiles: tasks.length,\n });\n }\n };\n\n // Create agent pool\n manager.createAgentPool();\n\n // Start parallel processing\n const processingPromises = Array.from({ length: concurrency }, () =>\n processTask()\n );\n\n try {\n await Promise.all(processingPromises);\n } catch (error) {\n // This shouldn't happen since we handle errors within processTask\n logger.debugMessage(\n `[i18n] Unexpected error in parallel processing: ${error}`\n );\n if (!firstError) {\n firstError = new Error(\n `Unexpected error in parallel processing: ${error}`\n );\n }\n }\n\n logger.progressBar.stop(\n `Processed ${topologicalOrder.length} files [${Math.round(\n (Date.now() - fileProcessingStartTime) / 1000\n )}s]`\n );\n\n // TODO: uncomment\n // // Always clean up the file list when done, regardless of success or failure\n // logger.info(`Cleaning up file list: ${stateFilePath}`);\n // cleanUp(stateFilePath);\n\n // If there was an error, clean up and exit with code 1\n if (firstError) {\n manager.cleanupAgents();\n logger.error(firstError.message);\n outro(chalk.red('❌ Locadex i18n failed!'));\n await exit(1);\n }\n\n // Create a clean agent for cleanup\n const cleanupAgent = manager.createSingleAgent('claude_cleanup_agent');\n logger.initializeSpinner();\n logger.spinner.start('Fixing errors...');\n const fixPrompt = getFixPrompt();\n try {\n await cleanupAgent.run(\n { prompt: fixPrompt, sessionId: cleanupAgent.getSessionId() },\n {}\n );\n reports.push(`## Fixed errors\\n${cleanupAgent.generateReport()}`);\n } catch (error) {\n manager.cleanupAgents();\n logger.debugMessage(\n `[claude_cleanup_agent] Fixing errors failed: ${error}`\n );\n manager.stats.recordTelemetry(false);\n outro(chalk.red('❌ Locadex i18n failed!'));\n await exit(1);\n }\n logger.spinner.stop('Fixed errors');\n\n // Generate report\n const reportSummary = `# Summary of locadex i18n changes\n${reports.join('\\n')}`;\n const summaryFilePath = path.join(\n manager.getWorkingDir(),\n 'locadex-report.md'\n );\n appendFileSync(summaryFilePath, reportSummary);\n logger.step(`Saved summary of changes to: ${summaryFilePath}`);\n\n // cleanup\n\n const formatter = await detectFormatter();\n if (formatter) {\n await formatFiles(topologicalOrder, formatter);\n }\n\n // Update lockfile with processed files\n updateLockfile(changedFiles, lockfilePath);\n\n // Clean up stale entries from lockfile\n cleanupLockfile(allFiles, lockfilePath);\n\n logger.message(`Updated lockfile with ${changedFiles.length} files`);\n\n // Clean up after successful completion\n manager.cleanup();\n\n logger.info(\n chalk.dim(\n `Total Cost: $${manager.stats.getStats().totalCost.toFixed(2)}\nTotal wall time: ${Math.round(\n (Date.now() - manager.stats.getStats().startTime) / 1000\n )}s\nTotal files processed: ${manager.stats.getStats().processedFiles}`\n )\n );\n\n const finalStats = manager.stats.getStats();\n\n // Record telemetry for final stats\n manager.stats.recordTelemetry(true);\n\n logger.verboseMessage(\n `Total input tokens: ${finalStats.inputTokens}\nTotal cached input tokens: ${finalStats.cachedInputTokens}\nTotal output tokens: ${finalStats.outputTokens}\nTotal turns: ${finalStats.turns}`\n );\n\n outro(chalk.green('✅ Locadex i18n complete!'));\n await exit(0);\n}\n\nfunction getPrompt({\n targetFile,\n dependencyFiles,\n dependentFiles,\n}: {\n targetFile: string[];\n dependencyFiles: Record<string, string[]>;\n dependentFiles: Record<string, string[]>;\n}) {\n const prompt = `# Task: Internationalize the target file(s) using gt-next.\n\n## INSTRUCTIONS\n\n- You are given a list of target files and their corresponding dependency/dependent files.\n- The project is already setup for internationalization. Do not try to setup the project again for i18n.\n\n## Workflow:\n1. **Gather context** Read the target files closely (you should not have to read the dependency/dependent files).\n2. **Evaluate if i18n is necessary** Evaluate if the target files need to be internationalized using gt-next \n - If the target files have no relevant content, are already internationalized, or contain build-time code (e.g. nextjs plugins) they should never be internationalized.\n**IMPORTANT**: IF NONE OF THE TARGET FILES NEED TO BE INTERNATIONALIZED, YOUR TASK IS COMPLETE AND YOU MAY RETURN.\n3. **Identify the tools to use** Given the contents of the files, ask yourself which tools and guides you need to use to get the necessary knowledge to internationalize the target files. Here are some helpful questions to evaluate for tool selection:\n - 3.a. Does this file contain a component? If so, is it a server-side component or a client-side component?\n - 3.b. Is the content that needs to be i18ned being used in this same file, or is it being used in another file?\n - 3.c. Is there any string interpolation that needs to be i18ned?\n - 3.d. Is there any conditional logic or rendering that needs to be i18ned?\n - 3.e. Is the content that needs to be i18ned HTML/JSX or a string?\n4. **Internationalize** You now have the necessary knowledge. Internationalize the files using the information from the tools provided to you.\n - 4.a. Do not worry about running tsc. We will do that later.\n\n## RULES:\n- ALWAYS use the <T> component to internationalize HTML/JSX content.\n- ALWAYS use getGT() or useGT() and getDict() or useDict() to internationalize string content (strings created with '', \"\", or \\`\\`).\n - When possible, avoid using getDict() or useDict(); getGT() and useGT() are preferred.\n- DO NOT internationalize non-user facing content or content that is functional, such as ids, class names, error strings, logical strings, etc.\n- Do not add i18n middleware to the app.\n- When adding 'useGT()' or 'useDict()' to a client component, you must add 'use client' to the top of the file.\n- Always adhere to the guides provided via the 'mcp__locadex__' tools.\n - These guides provide additional knowledge about how to internationalize the content.\n- Minimize the footprint of your changes.\n- Focus on internationalizing the content of the target files.\n- NEVER move internationalized content to a different file. All content MUST remain in the same file where it came from.\n- NEVER CREATE OR REMOVE ANY FILES (especially .bak files)\n- Internationalize all user facing content in the target files. \n- NEVER EDIT FILES THAT ARE NOT GIVEN TO YOU.\n\n## TARGET FILE INFORMATION\n${targetFile.map(\n (file, index) => `\nTARGET FILE ${index + 1}:\n${file}\n\nDEPENDENCY FILES (files imported by target file ${index + 1}):\n${dependencyFiles[file].length > 0 ? ` ${dependencyFiles[file].join(', ')}` : 'none'}\n\nDEPENDENT FILES (files that import target file ${index + 1}):\n${dependentFiles[file].length > 0 ? ` ${dependentFiles[file].join(', ')}` : 'none'}\n`\n)}\n\n---\n\n## MCP TOOLS\n\n${allMcpPrompt}\n\n## Final output\n- When you are done, please return a brief summary of the files you modified, following this format.\n- **DO NOT** include any other text in your response. \n- If there were issues with some files, please include the issues in the list of changes for that file.\n\n[file 1 path]\n- List of changes to file 1\n`;\n\n return prompt;\n}\n\n// check (dry run and ts check) should be at the end\n\nfunction getFixPrompt() {\n const prompt = `# Task: Fix internationalization errors in the project.\n\n## INSTRUCTIONS\n\nPreviously, you helped me internationalize a set of files in this project.\nYour new task is as follows:\n\n1. Run the gt-next validator.\n2. Fix all errors output by the gt-next validator.\n3. Whenever you are finished with your changes, run the gt-next validator.\n4. Repeat steps 1-3 until there are no more errors, or until you believe that you have fixed all errors.\n5. If the project is setup with linting, lint the project and fix all lint errors.\n\n## RULES:\n- ONLY modify files that are relevant to the internationalization of the project.\n- ONLY fix errors that result from your current or previous implementation.\n- Resolve unused imports from 'gt-next'. \n - In particular, if a file contains user-facing content that should be internationalized and is not, you should internationalize it.\n- Resolve missing imports from 'gt-next'. If a file is missing an import from 'gt-next', add it.\n\nTo run the gt-next validator, run the following command:\n'npx locadex translate --dry-run'\n\n## MCP TOOLS\n\n${allMcpPrompt}\n\n## Final output\n- When you are done, please return a brief summary of the files you modified, following this format.\n- **DO NOT** include any other text in your response. \n- If there were issues with some files, please include the issues in the list of changes for that file.\n\n[file 1 path]\n- List of changes to file 1\n`;\n\n return prompt;\n}\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,aA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;;;;;;;;;;;;;;;;;;;EAyBf,YAAY;;;;;;;;;CASb,CAAC;IAEA,OAAO,MAAM,CAAC;AAChB,CAAC","debug_id":"fcae1e88-fef0-5f8c-af05-ed774539bc74"}
|
|
1
|
+
{"version":3,"file":"i18n.js","sources":["tasks/i18n.ts"],"sourceRoot":"/","sourcesContent":["import { createSpinner } from '../logging/console.js';\nimport { allMcpPrompt } from '../prompts/system.js';\nimport { exit } from '../utils/shutdown.js';\n\nimport { logger } from '../logging/logger.js';\nimport { createDag } from '../utils/dag/createDag.js';\nimport {\n findTsConfig,\n findWebpackConfig,\n findRequireConfig,\n} from '../utils/fs/findConfigs.js';\nimport { LocadexManager } from '../utils/locadexManager.js';\nimport {\n addFilesToManager,\n markFileAsEdited,\n markFileAsInProgress,\n} from '../utils/dag/getFiles.js';\nimport { outro } from '@clack/prompts';\nimport chalk from 'chalk';\nimport { appendFileSync } from 'node:fs';\nimport { validateInitialConfig } from '../utils/config.js';\nimport { detectFormatter, formatFiles } from 'gtx-cli/hooks/postProcess';\nimport { generateSettings } from 'gtx-cli/config/generateSettings';\nimport path from 'node:path';\nimport { findSourceFiles } from '../utils/dag/matchFiles.js';\nimport {\n getChangedFiles,\n updateLockfile,\n cleanupLockfile,\n} from '../utils/lockfile.js';\nimport { installClaudeCode } from '../utils/packages/installPackage.js';\n\nexport async function i18nTask() {\n await validateInitialConfig();\n\n const gtSettings = await generateSettings({});\n if (gtSettings.framework !== 'next-app') {\n logger.error(\n 'Currently, locadex only supports Next.js App Router. Please use Next.js App Router.'\n );\n await exit(1);\n }\n\n // Install claude-code if not installed\n await installClaudeCode();\n\n // Init message\n const spinner = createSpinner();\n spinner.start('Initializing Locadex...');\n const manager = LocadexManager.getInstance();\n\n const config = manager.getConfig();\n\n const allFiles = findSourceFiles(\n config.matchingFiles,\n config.matchingExtensions\n );\n\n // Get lockfile path from manager\n const lockfilePath = manager.getLockFilePath();\n\n // Filter files to only include those with changed content hashes\n const changedFiles = getChangedFiles(allFiles, lockfilePath);\n\n if (changedFiles.length === 0) {\n spinner.stop('No files have changed since last run');\n outro(chalk.green('✅ Locadex i18n complete - no changes detected!'));\n await exit(0);\n }\n\n logger.verboseMessage(\n `Processing ${changedFiles.length} changed files out of ${allFiles.length} total files`\n );\n\n const dag = createDag(changedFiles, {\n tsConfig: findTsConfig(),\n webpackConfig: findWebpackConfig(),\n requireConfig: findRequireConfig(),\n });\n\n const filesStateFilePath = manager.getFilesStateFilePath();\n const concurrency = manager.getMaxConcurrency();\n const batchSize = manager.getBatchSize();\n\n // Create the list of files (aka tasks) to process\n const taskQueue = [...dag.getTopologicalOrder()];\n const topologicalOrder = [...dag.getTopologicalOrder()];\n\n // Add files to manager\n const stateFilePath = addFilesToManager(filesStateFilePath, taskQueue);\n spinner.stop('Locadex initialized');\n\n logger.verboseMessage(\n `Number of files to process: ${dag.getTopologicalOrder().length}`\n );\n logger.message(`Using ${concurrency} concurrent agents`);\n logger.debugMessage(`Track progress here: ${stateFilePath}`);\n logger.debugMessage(`Order:\\n${taskQueue.join('\\n')}`);\n\n logger.initializeProgressBar(taskQueue.length);\n\n const fileProcessingStartTime = Date.now();\n logger.progressBar.start(`Processing ${taskQueue.length} files...`);\n\n // Main parallel processing loop\n let processedCount = 0;\n const agentAbortController = manager.getAgentAbortController();\n let firstError: Error | null = null;\n\n // Mutex for task queue access\n let taskQueueMutex = Promise.resolve();\n\n // Shared across all agents\n const reports: string[] = [];\n\n // Helper function to safely get tasks from queue\n const getNextTasks = async (batchSize: number): Promise<string[]> => {\n return new Promise((resolve) => {\n taskQueueMutex = taskQueueMutex.then(() => {\n const tasks = taskQueue.splice(0, batchSize);\n resolve(tasks);\n });\n });\n };\n\n const processTask = async (): Promise<void> => {\n while (taskQueue.length > 0 && !agentAbortController.signal.aborted) {\n // Check if we should abort early\n if (agentAbortController.signal.aborted) {\n return;\n }\n\n // Get an available agent atomically\n const agentInfo = await manager.getAvailableAgent();\n if (!agentInfo) {\n // No available agents, wait a bit (but check for abort)\n await new Promise((resolve) => {\n const timeout = global.setTimeout(resolve, 100);\n agentAbortController.signal.addEventListener('abort', () => {\n global.clearTimeout(timeout);\n resolve(undefined);\n });\n });\n continue;\n }\n\n const { id: agentId, agent, sessionId } = agentInfo;\n\n // Get the next batch of tasks (thread-safe)\n const tasks = await getNextTasks(batchSize);\n if (tasks.length === 0) {\n manager.markAgentFree(agentId);\n break;\n }\n\n logger.debugMessage(\n `Using agent ${agentId} for ${batchSize} files. Files: ${tasks.join(\n ', '\n )}`\n );\n\n // Mark tasks as in progress\n await Promise.all(\n tasks.map((task) => markFileAsInProgress(task, filesStateFilePath))\n );\n\n // Construct prompt\n const dependencies = Object.fromEntries(\n tasks.map((task) => [\n task,\n Array.from(new Set(dag.getDependencies(task))),\n ])\n );\n const dependents = Object.fromEntries(\n tasks.map((task) => [\n task,\n Array.from(new Set(dag.getDependents(task))),\n ])\n );\n const prompt = getPrompt({\n targetFile: tasks,\n dependencyFiles: dependencies,\n dependentFiles: dependents,\n });\n\n // Claude call\n try {\n await agent.run(\n {\n prompt,\n sessionId,\n },\n {},\n agentAbortController\n );\n reports.push(agent.generateReport());\n manager.markAgentFree(agentId);\n } catch (error) {\n // Capture the first error and signal all other agents to abort\n if (!firstError) {\n firstError = new Error(\n `[i18n] Error in claude i18n process (agent ${agentId}): ${error}`\n );\n logger.debugMessage(firstError.message);\n agentAbortController.abort();\n manager.cleanupAgents();\n }\n manager.markAgentFree(agentId);\n return; // Exit this agent's processing immediately\n }\n\n // Mark tasks as complete\n await Promise.all(\n tasks.map((task) => markFileAsEdited(task, filesStateFilePath))\n );\n processedCount += tasks.length;\n logger.progressBar.advance(\n tasks.length,\n `Processed ${Number((processedCount / topologicalOrder.length) * 100).toFixed(2)}% of files`\n );\n manager.stats.updateStats({\n newProcessedFiles: tasks.length,\n });\n }\n };\n\n // Create agent pool\n manager.createAgentPool();\n\n // Start parallel processing\n const processingPromises = Array.from({ length: concurrency }, () =>\n processTask()\n );\n\n try {\n await Promise.all(processingPromises);\n } catch (error) {\n // This shouldn't happen since we handle errors within processTask\n logger.debugMessage(\n `[i18n] Unexpected error in parallel processing: ${error}`\n );\n if (!firstError) {\n firstError = new Error(\n `Unexpected error in parallel processing: ${error}`\n );\n }\n }\n\n logger.progressBar.stop(\n `Processed ${topologicalOrder.length} files [${Math.round(\n (Date.now() - fileProcessingStartTime) / 1000\n )}s]`\n );\n\n // TODO: uncomment\n // // Always clean up the file list when done, regardless of success or failure\n // logger.info(`Cleaning up file list: ${stateFilePath}`);\n // cleanUp(stateFilePath);\n\n // If there was an error, clean up and exit with code 1\n if (firstError) {\n manager.cleanupAgents();\n logger.error(firstError.message);\n outro(chalk.red('❌ Locadex i18n failed!'));\n await exit(1);\n }\n\n // Create a clean agent for cleanup\n const cleanupAgent = manager.createSingleAgent('claude_cleanup_agent');\n logger.initializeSpinner();\n logger.spinner.start('Fixing errors...');\n const fixPrompt = getFixPrompt();\n try {\n await cleanupAgent.run(\n { prompt: fixPrompt, sessionId: cleanupAgent.getSessionId() },\n {},\n manager.getAgentAbortController()\n );\n reports.push(`## Fixed errors\\n${cleanupAgent.generateReport()}`);\n } catch (error) {\n manager.cleanupAgents();\n logger.debugMessage(\n `[claude_cleanup_agent] Fixing errors failed: ${error}`\n );\n manager.stats.recordTelemetry(false);\n outro(chalk.red('❌ Locadex i18n failed!'));\n await exit(1);\n }\n logger.spinner.stop('Fixed errors');\n\n // Generate report\n const reportSummary = `# Summary of locadex i18n changes\n${reports.join('\\n')}`;\n const summaryFilePath = path.join(\n manager.getWorkingDir(),\n 'locadex-report.md'\n );\n appendFileSync(summaryFilePath, reportSummary);\n logger.step(`Saved summary of changes to: ${summaryFilePath}`);\n\n // cleanup\n\n const formatter = await detectFormatter();\n if (formatter) {\n await formatFiles(topologicalOrder, formatter);\n }\n\n // Update lockfile with processed files\n updateLockfile(changedFiles, lockfilePath);\n\n // Clean up stale entries from lockfile\n cleanupLockfile(allFiles, lockfilePath);\n\n logger.message(`Updated lockfile with ${changedFiles.length} files`);\n\n // Clean up after successful completion\n manager.cleanup();\n\n logger.info(\n chalk.dim(\n `Total Cost: $${manager.stats.getStats().totalCost.toFixed(2)}\nTotal wall time: ${Math.round(\n (Date.now() - manager.stats.getStats().startTime) / 1000\n )}s\nTotal files processed: ${manager.stats.getStats().processedFiles}`\n )\n );\n\n const finalStats = manager.stats.getStats();\n\n // Record telemetry for final stats\n manager.stats.recordTelemetry(true);\n\n logger.verboseMessage(\n `Total input tokens: ${finalStats.inputTokens}\nTotal cached input tokens: ${finalStats.cachedInputTokens}\nTotal output tokens: ${finalStats.outputTokens}\nTotal turns: ${finalStats.turns}`\n );\n\n outro(chalk.green('✅ Locadex i18n complete!'));\n await exit(0);\n}\n\nfunction getPrompt({\n targetFile,\n dependencyFiles,\n dependentFiles,\n}: {\n targetFile: string[];\n dependencyFiles: Record<string, string[]>;\n dependentFiles: Record<string, string[]>;\n}) {\n const prompt = `# Task: Internationalize the target file(s) using gt-next.\n\n## INSTRUCTIONS\n\n- You are given a list of target files and their corresponding dependency/dependent files.\n- The project is already setup for internationalization. Do not try to setup the project again for i18n.\n\n## Workflow:\n1. **Gather context** Read the target files closely (you should not have to read the dependency/dependent files).\n2. **Evaluate if i18n is necessary** Evaluate if the target files need to be internationalized using gt-next \n - If the target files have no relevant content, are already internationalized, or contain build-time code (e.g. nextjs plugins) they should never be internationalized.\n**IMPORTANT**: IF NONE OF THE TARGET FILES NEED TO BE INTERNATIONALIZED, YOUR TASK IS COMPLETE AND YOU MAY RETURN.\n3. **Identify the tools to use** Given the contents of the files, ask yourself which tools and guides you need to use to get the necessary knowledge to internationalize the target files. Here are some helpful questions to evaluate for tool selection:\n - 3.a. Does this file contain a component? If so, is it a server-side component or a client-side component?\n - 3.b. Is the content that needs to be i18ned being used in this same file, or is it being used in another file?\n - 3.c. Is there any string interpolation that needs to be i18ned?\n - 3.d. Is there any conditional logic or rendering that needs to be i18ned?\n - 3.e. Is the content that needs to be i18ned HTML/JSX or a string?\n4. **Internationalize** You now have the necessary knowledge. Internationalize the files using the information from the tools provided to you.\n - 4.a. Do not worry about running tsc. We will do that later.\n\n## RULES:\n- ALWAYS use the <T> component to internationalize HTML/JSX content.\n- ALWAYS use getGT() or useGT() and getDict() or useDict() to internationalize string content (strings created with '', \"\", or \\`\\`).\n - When possible, avoid using getDict() or useDict(); getGT() and useGT() are preferred.\n- DO NOT internationalize non-user facing content or content that is functional, such as ids, class names, error strings, logical strings, etc.\n- Do not add i18n middleware to the app.\n- When adding 'useGT()' or 'useDict()' to a client component, you must add 'use client' to the top of the file.\n- Always adhere to the guides provided via the 'mcp__locadex__' tools.\n - These guides provide additional knowledge about how to internationalize the content.\n- Minimize the footprint of your changes.\n- Focus on internationalizing the content of the target files.\n- NEVER move internationalized content to a different file. All content MUST remain in the same file where it came from.\n- NEVER CREATE OR REMOVE ANY FILES (especially .bak files)\n- Internationalize all user facing content in the target files. \n- NEVER EDIT FILES THAT ARE NOT GIVEN TO YOU.\n\n## TARGET FILE INFORMATION\n${targetFile.map(\n (file, index) => `\nTARGET FILE ${index + 1}:\n${file}\n\nDEPENDENCY FILES (files imported by target file ${index + 1}):\n${dependencyFiles[file].length > 0 ? ` ${dependencyFiles[file].join(', ')}` : 'none'}\n\nDEPENDENT FILES (files that import target file ${index + 1}):\n${dependentFiles[file].length > 0 ? ` ${dependentFiles[file].join(', ')}` : 'none'}\n`\n)}\n\n---\n\n## MCP TOOLS\n\n${allMcpPrompt}\n\n## Final output\n- When you are done, please return a brief summary of the files you modified, following this format.\n- **DO NOT** include any other text in your response. \n- If there were issues with some files, please include the issues in the list of changes for that file.\n\n[file 1 path]\n- List of changes to file 1\n`;\n\n return prompt;\n}\n\n// check (dry run and ts check) should be at the end\n\nfunction getFixPrompt() {\n const prompt = `# Task: Fix internationalization errors in the project.\n\n## INSTRUCTIONS\n\nPreviously, you helped me internationalize a set of files in this project.\nYour new task is as follows:\n\n1. Run the gt-next validator.\n2. Fix all errors output by the gt-next validator.\n3. Whenever you are finished with your changes, run the gt-next validator.\n4. Repeat steps 1-3 until there are no more errors, or until you believe that you have fixed all errors.\n5. If the project is setup with linting, lint the project and fix all lint errors.\n\n## RULES:\n- ONLY modify files that are relevant to the internationalization of the project.\n- ONLY fix errors that result from your current or previous implementation.\n- Resolve unused imports from 'gt-next'. \n - In particular, if a file contains user-facing content that should be internationalized and is not, you should internationalize it.\n- Resolve missing imports from 'gt-next'. If a file is missing an import from 'gt-next', add it.\n\nTo run the gt-next validator, run the following command:\n'npx locadex translate --dry-run'\n\n## MCP TOOLS\n\n${allMcpPrompt}\n\n## Final output\n- When you are done, please return a brief summary of the files you modified, following this format.\n- **DO NOT** include any other text in your response. \n- If there were issues with some files, please include the issues in the list of changes for that file.\n\n[file 1 path]\n- List of changes to file 1\n`;\n\n return prompt;\n}\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC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IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;cACL,KAAK,GAAG,CAAC;EACrB,IAAI;;kDAE4C,KAAK,GAAG,CAAC;EACzD,eAAe,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM;;iDAEnC,KAAK,GAAG,CAAC;EACxD,cAAc,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM;CACjF,CACA;;;;;;EAMC,YAAY;;;;;;;;;CASb,CAAC;IAEA,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,oDAAoD;AAEpD,SAAS,YAAY;IACnB,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;EAyBf,YAAY;;;;;;;;;CASb,CAAC;IAEA,OAAO,MAAM,CAAC;AAChB,CAAC","debug_id":"f99eaeb7-c766-572e-a2a4-a4b5c61d53b1"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.d.ts","sourceRoot":"/","sources":["tasks/setup.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"/","sources":["tasks/setup.ts"],"names":[],"mappings":"AAqBA,wBAAsB,SAAS,CAC7B,aAAa,EAAE,OAAO,EACtB,uBAAuB,CAAC,EAAE,MAAM,iBAgHjC"}
|
package/dist/tasks/setup.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
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]="
|
|
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]="7dd3d8e8-23a0-5206-8ded-2204a89f3ba9")}catch(e){}}();
|
|
3
3
|
import { createSpinner, promptConfirm } from '../logging/console.js';
|
|
4
4
|
import { getPackageJson, isPackageInstalled } from 'gtx-cli/utils/packageJson';
|
|
5
5
|
import { getPackageManager } from 'gtx-cli/utils/packageManager';
|
|
6
|
-
import { installPackage
|
|
6
|
+
import { installPackage } from 'gtx-cli/utils/installPackage';
|
|
7
7
|
import chalk from 'chalk';
|
|
8
8
|
import { logger } from '../logging/logger.js';
|
|
9
9
|
import { findFilepaths } from '../utils/fs/findConfigs.js';
|
|
@@ -106,7 +106,7 @@ async function setupLocaleSelector() {
|
|
|
106
106
|
// Fix prompt
|
|
107
107
|
const localeSelectorPrompt = getLocaleSelectorPrompt();
|
|
108
108
|
try {
|
|
109
|
-
await agent.run({ prompt: localeSelectorPrompt }, {});
|
|
109
|
+
await agent.run({ prompt: localeSelectorPrompt }, {}, manager.getAgentAbortController());
|
|
110
110
|
// Generate report
|
|
111
111
|
const report = agent.generateReport();
|
|
112
112
|
const reportSummary = `# Summary of locadex setup changes
|
|
@@ -158,4 +158,4 @@ function MyComponent() {
|
|
|
158
158
|
return prompt;
|
|
159
159
|
}
|
|
160
160
|
//# sourceMappingURL=setup.js.map
|
|
161
|
-
//# debugId=
|
|
161
|
+
//# debugId=7dd3d8e8-23a0-5206-8ded-2204a89f3ba9
|
package/dist/tasks/setup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.js","sources":["tasks/setup.ts"],"sourceRoot":"/","sourcesContent":["import { createSpinner, promptConfirm } from '../logging/console.js';\nimport { getPackageJson, isPackageInstalled } from 'gtx-cli/utils/packageJson';\nimport { getPackageManager } from 'gtx-cli/utils/packageManager';\nimport {\n installPackage,\n installPackageGlobal,\n} from 'gtx-cli/utils/installPackage';\nimport chalk from 'chalk';\nimport { logger } from '../logging/logger.js';\nimport { findFilepaths } from '../utils/fs/findConfigs.js';\nimport { wrapContentNext } from 'gtx-cli/next/parse/wrapContent';\nimport { handleInitGT } from 'gtx-cli/next/parse/handleInitGT';\nimport { detectFormatter, formatFiles } from 'gtx-cli/hooks/postProcess';\nimport { createOrUpdateConfig } from 'gtx-cli/fs/config/setupConfig';\nimport { i18nTask } from '../tasks/i18n.js';\nimport { validateInitialConfig } from '../utils/config.js';\nimport { getNextDirectories } from '../utils/fs/getFiles.js';\nimport { LocadexManager } from '../utils/locadexManager.js';\nimport { outro } from '@clack/prompts';\nimport { appendFileSync } from 'node:fs';\nimport path from 'node:path';\nimport { exit } from '../utils/shutdown.js';\nimport { installClaudeCode } from '../utils/packages/installPackage.js';\n\nexport async function setupTask(\n bypassPrompts: boolean,\n specifiedPackageManager?: string\n) {\n await validateInitialConfig();\n\n if (!bypassPrompts) {\n const answer = await promptConfirm({\n message: chalk.yellow(\n `Locadex will modify files! Make sure you have committed or stashed any changes. Do you want to continue?`\n ),\n defaultValue: true,\n cancelMessage: 'Operation cancelled.',\n });\n if (!answer) {\n logger.info('Operation cancelled.');\n await exit(0);\n }\n }\n\n const packageJson = await getPackageJson();\n const packageManager = await getPackageManager(specifiedPackageManager);\n\n const spinner = createSpinner('timer');\n\n spinner.start(`Installing gt-next with ${packageManager.name}...`);\n\n await installPackage('gt-next', packageManager);\n\n spinner.stop('Automatically installed gt-next.');\n\n const nextConfigPath = findFilepaths([\n './next.config.js',\n './next.config.ts',\n './next.config.mjs',\n './next.config.mts',\n ])[0];\n\n if (!nextConfigPath) {\n logger.error('No next.config.[js|ts|mjs|mts] file found.');\n await exit(1);\n }\n\n const errors: string[] = [];\n const warnings: string[] = [];\n let filesUpdated: string[] = [];\n\n const babel = createSpinner();\n\n babel.start('Wrapping <GTProvider> tags...');\n\n // Wrap all JSX elements in the src directory with a <T> tag, with unique ids\n const { filesUpdated: filesUpdatedNext } = await wrapContentNext(\n {\n src: getNextDirectories(),\n config: nextConfigPath,\n disableIds: true,\n disableFormatting: true,\n skipTs: true,\n addGTProvider: true,\n },\n 'gt-next',\n errors,\n warnings\n );\n filesUpdated = [...filesUpdated, ...filesUpdatedNext];\n\n babel.stop(`Modified ${filesUpdated.length} files.`);\n\n // Add the withGTConfig() function to the next.config.js file\n await handleInitGT(nextConfigPath, errors, warnings, filesUpdated);\n logger.step(`Added withGTConfig() to your ${nextConfigPath} file.`);\n\n // Create gt.config.json\n await createOrUpdateConfig('gt.config.json', {\n defaultLocale: 'en',\n locales: ['es', 'fr', 'de', 'ja', 'zh'],\n framework: 'next-app',\n });\n\n logger.success(\n `Feel free to edit ${chalk.cyan(\n 'gt.config.json'\n )} to customize your translation setup. Docs: https://generaltranslation.com/docs/cli/reference/config`\n );\n\n // Install claude-code if not installed\n await installClaudeCode();\n\n // Install locadex if not installed\n const isLocadexInstalled = packageJson\n ? isPackageInstalled('locadex', packageJson, true, true)\n : true; // if no package.json, we can't install it\n\n if (!isLocadexInstalled) {\n const packageManager = await getPackageManager();\n const spinner = createSpinner();\n spinner.start(\n `Installing locadex as a dev dependency with ${packageManager.name}...`\n );\n await installPackage('locadex', packageManager, true);\n spinner.stop(chalk.green('Installed locadex.'));\n }\n\n // Set up locale selector\n await setupLocaleSelector();\n\n const formatter = await detectFormatter();\n if (formatter && filesUpdated.length > 0) {\n await formatFiles(filesUpdated, formatter);\n }\n\n // Run i18n command\n await i18nTask();\n}\n\nasync function setupLocaleSelector() {\n logger.initializeSpinner();\n logger.spinner.start('Creating locale selector...');\n\n // Create agent\n const manager = LocadexManager.getInstance();\n\n const agent = manager.createSingleAgent('claude_setup_agent');\n\n // Fix prompt\n const localeSelectorPrompt = getLocaleSelectorPrompt();\n try {\n await agent.run({ prompt: localeSelectorPrompt }, {});\n\n // Generate report\n const report = agent.generateReport();\n const reportSummary = `# Summary of locadex setup changes\n${report}`;\n const summaryFilePath = path.join(\n manager.getWorkingDir(),\n 'locadex-report.md'\n );\n appendFileSync(summaryFilePath, reportSummary);\n } catch (error) {\n logger.debugMessage(`[setup] Adding locale selector failed: ${error}`);\n outro(chalk.red('❌ Locadex setup failed!'));\n await exit(1);\n }\n\n logger.spinner.stop('Locale selector setup complete');\n}\n\nfunction getLocaleSelectorPrompt() {\n const prompt = `# Task: Add a locale selector to the project\n\n## Instructions\n- The locale selector should be a dropdown that allows the user to select the locale.\n\n## LOCALE SELECTOR USAGE\n(1) Import the locale selector component from 'gt-next/client'\n(2) Add the locale selector to the project\n\nFor example:\nimport { LocaleSelector } from 'gt-next/client';\n\nfunction MyComponent() {\n return (\n <div>\n <LocaleSelector />\n <p>Hello, world!</p>\n </div>\n );\n}\n\n## ADVICE\n- The locale selector should be added to a header or footer or some other very obvious place in the project.\n- Scan across files to find the best place to add the locale selector.\n\n## Final output\n- When you are done, please return a brief summary of the files you modified, following this format.\n- **DO NOT** include any other text in your response. \n- If there were issues with some files, please include the issues in the list of changes for that file.\n\n[file 1 path]\n- List of changes to file 1\n`;\n return prompt;\n}\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EACL,cAAc,GAEf,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,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6BAA6B,CAAC,CAAC;IAEpD,eAAe;IACf,MAAM,OAAO,GAAG,cAAc,CAAC,WAAW,EAAE,CAAC;IAE7C,MAAM,KAAK,GAAG,OAAO,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,CAAC;IAE9D,aAAa;IACb,MAAM,oBAAoB,GAAG,uBAAuB,EAAE,CAAC;IACvD,IAAI,CAAC;QACH,MAAM,KAAK,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,oBAAoB,EAAE,EAAE,EAAE,CAAC,CAAC;QAEtD,kBAAkB;QAClB,MAAM,MAAM,GAAG,KAAK,CAAC,cAAc,EAAE,CAAC;QACtC,MAAM,aAAa,GAAG;EACxB,MAAM,EAAE,CAAC;QACP,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAC/B,OAAO,CAAC,aAAa,EAAE,EACvB,mBAAmB,CACpB,CAAC;QACF,cAAc,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC;IACjD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,YAAY,CAAC,0CAA0C,KAAK,EAAE,CAAC,CAAC;QACvE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC,CAAC;QAC5C,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC;IAChB,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;AACxD,CAAC;AAED,SAAS,uBAAuB;IAC9B,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgChB,CAAC;IACA,OAAO,MAAM,CAAC;AAChB,CAAC","debug_id":"27647c83-2550-5be2-84a3-f1fc917a4f85"}
|
|
1
|
+
{"version":3,"file":"setup.js","sources":["tasks/setup.ts"],"sourceRoot":"/","sourcesContent":["import { createSpinner, promptConfirm } from '../logging/console.js';\nimport { getPackageJson, isPackageInstalled } from 'gtx-cli/utils/packageJson';\nimport { getPackageManager } from 'gtx-cli/utils/packageManager';\nimport { installPackage } from 'gtx-cli/utils/installPackage';\nimport chalk from 'chalk';\nimport { logger } from '../logging/logger.js';\nimport { findFilepaths } from '../utils/fs/findConfigs.js';\nimport { wrapContentNext } from 'gtx-cli/next/parse/wrapContent';\nimport { handleInitGT } from 'gtx-cli/next/parse/handleInitGT';\nimport { detectFormatter, formatFiles } from 'gtx-cli/hooks/postProcess';\nimport { createOrUpdateConfig } from 'gtx-cli/fs/config/setupConfig';\nimport { i18nTask } from '../tasks/i18n.js';\nimport { validateInitialConfig } from '../utils/config.js';\nimport { getNextDirectories } from '../utils/fs/getFiles.js';\nimport { LocadexManager } from '../utils/locadexManager.js';\nimport { outro } from '@clack/prompts';\nimport { appendFileSync } from 'node:fs';\nimport path from 'node:path';\nimport { exit } from '../utils/shutdown.js';\nimport { installClaudeCode } from '../utils/packages/installPackage.js';\n\nexport async function setupTask(\n bypassPrompts: boolean,\n specifiedPackageManager?: string\n) {\n await validateInitialConfig();\n\n if (!bypassPrompts) {\n const answer = await promptConfirm({\n message: chalk.yellow(\n `Locadex will modify files! Make sure you have committed or stashed any changes. Do you want to continue?`\n ),\n defaultValue: true,\n cancelMessage: 'Operation cancelled.',\n });\n if (!answer) {\n logger.info('Operation cancelled.');\n await exit(0);\n }\n }\n\n const packageJson = await getPackageJson();\n const packageManager = await getPackageManager(specifiedPackageManager);\n\n const spinner = createSpinner('timer');\n\n spinner.start(`Installing gt-next with ${packageManager.name}...`);\n\n await installPackage('gt-next', packageManager);\n\n spinner.stop('Automatically installed gt-next.');\n\n const nextConfigPath = findFilepaths([\n './next.config.js',\n './next.config.ts',\n './next.config.mjs',\n './next.config.mts',\n ])[0];\n\n if (!nextConfigPath) {\n logger.error('No next.config.[js|ts|mjs|mts] file found.');\n await exit(1);\n }\n\n const errors: string[] = [];\n const warnings: string[] = [];\n let filesUpdated: string[] = [];\n\n const babel = createSpinner();\n\n babel.start('Wrapping <GTProvider> tags...');\n\n // Wrap all JSX elements in the src directory with a <T> tag, with unique ids\n const { filesUpdated: filesUpdatedNext } = await wrapContentNext(\n {\n src: getNextDirectories(),\n config: nextConfigPath,\n disableIds: true,\n disableFormatting: true,\n skipTs: true,\n addGTProvider: true,\n },\n 'gt-next',\n errors,\n warnings\n );\n filesUpdated = [...filesUpdated, ...filesUpdatedNext];\n\n babel.stop(`Modified ${filesUpdated.length} files.`);\n\n // Add the withGTConfig() function to the next.config.js file\n await handleInitGT(nextConfigPath, errors, warnings, filesUpdated);\n logger.step(`Added withGTConfig() to your ${nextConfigPath} file.`);\n\n // Create gt.config.json\n await createOrUpdateConfig('gt.config.json', {\n defaultLocale: 'en',\n locales: ['es', 'fr', 'de', 'ja', 'zh'],\n framework: 'next-app',\n });\n\n logger.success(\n `Feel free to edit ${chalk.cyan(\n 'gt.config.json'\n )} to customize your translation setup. Docs: https://generaltranslation.com/docs/cli/reference/config`\n );\n\n // Install claude-code if not installed\n await installClaudeCode();\n\n // Install locadex if not installed\n const isLocadexInstalled = packageJson\n ? isPackageInstalled('locadex', packageJson, true, true)\n : true; // if no package.json, we can't install it\n\n if (!isLocadexInstalled) {\n const packageManager = await getPackageManager();\n const spinner = createSpinner();\n spinner.start(\n `Installing locadex as a dev dependency with ${packageManager.name}...`\n );\n await installPackage('locadex', packageManager, true);\n spinner.stop(chalk.green('Installed locadex.'));\n }\n\n // Set up locale selector\n await setupLocaleSelector();\n\n const formatter = await detectFormatter();\n if (formatter && filesUpdated.length > 0) {\n await formatFiles(filesUpdated, formatter);\n }\n\n // Run i18n command\n await i18nTask();\n}\n\nasync function setupLocaleSelector() {\n logger.initializeSpinner();\n logger.spinner.start('Creating locale selector...');\n\n // Create agent\n const manager = LocadexManager.getInstance();\n\n const agent = manager.createSingleAgent('claude_setup_agent');\n\n // Fix prompt\n const localeSelectorPrompt = getLocaleSelectorPrompt();\n try {\n await agent.run(\n { prompt: localeSelectorPrompt },\n {},\n manager.getAgentAbortController()\n );\n\n // Generate report\n const report = agent.generateReport();\n const reportSummary = `# Summary of locadex setup changes\n${report}`;\n const summaryFilePath = path.join(\n manager.getWorkingDir(),\n 'locadex-report.md'\n );\n appendFileSync(summaryFilePath, reportSummary);\n } catch (error) {\n logger.debugMessage(`[setup] Adding locale selector failed: ${error}`);\n outro(chalk.red('❌ Locadex setup failed!'));\n await exit(1);\n }\n\n logger.spinner.stop('Locale selector setup complete');\n}\n\nfunction getLocaleSelectorPrompt() {\n const prompt = `# Task: Add a locale selector to the project\n\n## Instructions\n- The locale selector should be a dropdown that allows the user to select the locale.\n\n## LOCALE SELECTOR USAGE\n(1) Import the locale selector component from 'gt-next/client'\n(2) Add the locale selector to the project\n\nFor example:\nimport { LocaleSelector } from 'gt-next/client';\n\nfunction MyComponent() {\n return (\n <div>\n <LocaleSelector />\n <p>Hello, world!</p>\n </div>\n );\n}\n\n## ADVICE\n- The locale selector should be added to a header or footer or some other very obvious place in the project.\n- Scan across files to find the best place to add the locale selector.\n\n## Final output\n- When you are done, please return a brief summary of the files you modified, following this format.\n- **DO NOT** include any other text in your response. \n- If there were issues with some files, please include the issues in the list of changes for that file.\n\n[file 1 path]\n- List of changes to file 1\n`;\n return prompt;\n}\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,eAAe,E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AAC,6BAA6B,CAAC,CAAC;IAEpD,eAAe;IACf,MAAM,OAAO,GAAG,cAAc,CAAC,WAAW,EAAE,CAAC;IAE7C,MAAM,KAAK,GAAG,OAAO,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,CAAC;IAE9D,aAAa;IACb,MAAM,oBAAoB,GAAG,uBAAuB,EAAE,CAAC;IACvD,IAAI,CAAC;QACH,MAAM,KAAK,CAAC,GAAG,CACb,EAAE,MAAM,EAAE,oBAAoB,EAAE,EAChC,EAAE,EACF,OAAO,CAAC,uBAAuB,EAAE,CAClC,CAAC;QAEF,kBAAkB;QAClB,MAAM,MAAM,GAAG,KAAK,CAAC,cAAc,EAAE,CAAC;QACtC,MAAM,aAAa,GAAG;EACxB,MAAM,EAAE,CAAC;QACP,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAC/B,OAAO,CAAC,aAAa,EAAE,EACvB,mBAAmB,CACpB,CAAC;QACF,cAAc,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC;IACjD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,YAAY,CAAC,0CAA0C,KAAK,EAAE,CAAC,CAAC;QACvE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC,CAAC;QAC5C,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC;IAChB,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;AACxD,CAAC;AAED,SAAS,uBAAuB;IAC9B,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgChB,CAAC;IACA,OAAO,MAAM,CAAC;AAChB,CAAC","debug_id":"7dd3d8e8-23a0-5206-8ded-2204a89f3ba9"}
|
|
@@ -22,7 +22,7 @@ export declare class ClaudeCodeRunner {
|
|
|
22
22
|
mcpConfig?: string;
|
|
23
23
|
});
|
|
24
24
|
getSessionId(): string;
|
|
25
|
-
run(options: ClaudeCodeOptions, obs: ClaudeCodeObservation): Promise<string>;
|
|
25
|
+
run(options: ClaudeCodeOptions, obs: ClaudeCodeObservation, controller: AbortController): Promise<string>;
|
|
26
26
|
private handleSDKOutput;
|
|
27
27
|
generateReport(): string;
|
|
28
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claudeCode.d.ts","sourceRoot":"/","sources":["utils/claudeCode.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAIrD,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;
|
|
1
|
+
{"version":3,"file":"claudeCode.d.ts","sourceRoot":"/","sources":["utils/claudeCode.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAIrD,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;AAczC,eAAO,MAAM,sBAAsB,YAElC,CAAC;AAEF,qBAAa,gBAAgB;IASzB,OAAO,CAAC,OAAO;IARjB,OAAO,CAAC,EAAE,CAAS;IACnB,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,SAAS,CAAqB;IACtC,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,OAAO,CAAgB;gBAG7B,OAAO,EAAE,cAAc,EACf,OAAO,EAAE;QACf,EAAE,EAAE,MAAM,CAAC;QACX,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB;IAgBH,YAAY,IAAI,MAAM;IAIhB,GAAG,CACP,OAAO,EAAE,iBAAiB,EAC1B,GAAG,EAAE,qBAAqB,EAC1B,UAAU,EAAE,eAAe,GAC1B,OAAO,CAAC,MAAM,CAAC;IAsIlB,OAAO,CAAC,eAAe;IAmEvB,cAAc,IAAI,MAAM;CAGzB"}
|
package/dist/utils/claudeCode.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
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]="
|
|
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]="9224d302-8aa2-52e4-bb5a-7376ff85f7e3")}catch(e){}}();
|
|
3
3
|
import { spawn } from 'node:child_process';
|
|
4
4
|
import { guides } from '../mcp/tools/guides.js';
|
|
5
5
|
import { logger } from '../logging/logger.js';
|
|
@@ -15,25 +15,9 @@ const DEFAULT_ALLOWED_TOOLS = [
|
|
|
15
15
|
'Write',
|
|
16
16
|
].concat(guides.map((guide) => `mcp__locadex__${guide.id}`));
|
|
17
17
|
const DISALLOWED_TOOLS = ['NotebookEdit', 'WebFetch', 'WebSearch'];
|
|
18
|
-
//
|
|
19
|
-
const activeClaudeProcesses = new Set();
|
|
20
|
-
// Function to kill all active Claude processes
|
|
18
|
+
// Legacy function for backward compatibility
|
|
21
19
|
export const killAllClaudeProcesses = () => {
|
|
22
|
-
|
|
23
|
-
if (!proc.killed) {
|
|
24
|
-
proc.kill('SIGTERM');
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
activeClaudeProcesses.clear();
|
|
28
|
-
};
|
|
29
|
-
// Setup global process termination handlers once
|
|
30
|
-
let handlersSetup = false;
|
|
31
|
-
const setupProcessHandlers = () => {
|
|
32
|
-
if (handlersSetup)
|
|
33
|
-
return;
|
|
34
|
-
handlersSetup = true;
|
|
35
|
-
process.on('SIGINT', killAllClaudeProcesses);
|
|
36
|
-
process.on('SIGTERM', killAllClaudeProcesses);
|
|
20
|
+
// No-op since we now use AbortController
|
|
37
21
|
};
|
|
38
22
|
export class ClaudeCodeRunner {
|
|
39
23
|
options;
|
|
@@ -51,13 +35,12 @@ export class ClaudeCodeRunner {
|
|
|
51
35
|
if (!process.env.ANTHROPIC_API_KEY && !this.options.apiKey) {
|
|
52
36
|
throw new Error('ANTHROPIC_API_KEY environment variable or apiKey option is required');
|
|
53
37
|
}
|
|
54
|
-
//
|
|
55
|
-
setupProcessHandlers();
|
|
38
|
+
// AbortController handles cleanup automatically
|
|
56
39
|
}
|
|
57
40
|
getSessionId() {
|
|
58
41
|
return this.sessionId;
|
|
59
42
|
}
|
|
60
|
-
async run(options, obs) {
|
|
43
|
+
async run(options, obs, controller) {
|
|
61
44
|
this.changes = [];
|
|
62
45
|
return Sentry.startSpan({
|
|
63
46
|
name: 'claude-code-exec',
|
|
@@ -90,11 +73,18 @@ export class ClaudeCodeRunner {
|
|
|
90
73
|
if (this.options.apiKey) {
|
|
91
74
|
env.ANTHROPIC_API_KEY = this.options.apiKey;
|
|
92
75
|
}
|
|
76
|
+
logger.debugMessage(`[${this.id}] Spawning Claude Code with additional args: ${JSON.stringify({
|
|
77
|
+
maxTurns: options.maxTurns,
|
|
78
|
+
sessionId: options.sessionId,
|
|
79
|
+
mcpConfig: this.mcpConfig,
|
|
80
|
+
additionalAllowedTools: options.additionalAllowedTools,
|
|
81
|
+
}, null, 2)}`);
|
|
93
82
|
const claude = spawn('claude', args, {
|
|
94
83
|
stdio: ['inherit', 'pipe', 'pipe'],
|
|
95
84
|
env,
|
|
85
|
+
signal: controller.signal,
|
|
96
86
|
});
|
|
97
|
-
|
|
87
|
+
logger.debugMessage(`[${this.id}] Spawned claude code process`);
|
|
98
88
|
const output = '';
|
|
99
89
|
const errorOutput = '';
|
|
100
90
|
let buffer = '';
|
|
@@ -120,7 +110,6 @@ export class ClaudeCodeRunner {
|
|
|
120
110
|
logger.debugMessage(`[${this.id}] ${data.toString().trim()}`);
|
|
121
111
|
});
|
|
122
112
|
claude.on('close', (code) => {
|
|
123
|
-
activeClaudeProcesses.delete(claude);
|
|
124
113
|
if (code === 0) {
|
|
125
114
|
resolve(output.trim());
|
|
126
115
|
}
|
|
@@ -130,9 +119,15 @@ export class ClaudeCodeRunner {
|
|
|
130
119
|
}
|
|
131
120
|
});
|
|
132
121
|
claude.on('error', (error) => {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
122
|
+
// Check if this is an AbortError
|
|
123
|
+
if (error.name === 'AbortError') {
|
|
124
|
+
logger.debugMessage(`[${this.id}] Claude Code process was aborted`);
|
|
125
|
+
reject(new Error(`[${this.id}] Claude Code process was aborted`));
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
logger.debugMessage(`[${this.id}] failed to run Claude Code: ${error.message}`);
|
|
129
|
+
reject(new Error(`[${this.id}] failed to run Claude Code: ${error.message}`));
|
|
130
|
+
}
|
|
136
131
|
});
|
|
137
132
|
}));
|
|
138
133
|
}
|
|
@@ -198,4 +193,4 @@ export class ClaudeCodeRunner {
|
|
|
198
193
|
}
|
|
199
194
|
}
|
|
200
195
|
//# sourceMappingURL=claudeCode.js.map
|
|
201
|
-
//# debugId=
|
|
196
|
+
//# debugId=9224d302-8aa2-52e4-bb5a-7376ff85f7e3
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claudeCode.js","sources":["utils/claudeCode.ts"],"sourceRoot":"/","sourcesContent":["import { spawn } from 'node:child_process';\nimport { ClaudeSDKMessage } from '../types/claude-sdk.js';\nimport { guides } from '../mcp/tools/guides.js';\nimport { logger } from '../logging/logger.js';\nimport { posthog } from '../telemetry.js';\nimport { LocadexManager } from './locadexManager.js';\nimport { getSessionId } from './session.js';\nimport * as Sentry from '@sentry/node';\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// Function to kill all active Claude processes\nexport const killAllClaudeProcesses = () => {\n activeClaudeProcesses.forEach((proc) => {\n if (!proc.killed) {\n proc.kill('SIGTERM');\n }\n });\n activeClaudeProcesses.clear();\n};\n\n// Setup global process termination handlers once\nlet handlersSetup = false;\nconst setupProcessHandlers = () => {\n if (handlersSetup) return;\n handlersSetup = true;\n\n process.on('SIGINT', killAllClaudeProcesses);\n process.on('SIGTERM', killAllClaudeProcesses);\n};\n\nexport class ClaudeCodeRunner {\n private id: string;\n private sessionId: string = '';\n private mcpConfig: string | undefined;\n private manager: LocadexManager;\n private changes: string[] = [];\n\n constructor(\n manager: LocadexManager,\n private options: {\n id: string;\n apiKey?: string;\n mcpConfig?: string;\n }\n ) {\n this.manager = manager;\n this.id = options.id;\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 this.changes = [];\n return Sentry.startSpan(\n {\n name: 'claude-code-exec',\n op: 'claude-code.exec',\n attributes: {\n 'process.command': 'claude',\n },\n },\n () =>\n 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('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(`[${this.id}] ${line}`);\n const outputData: ClaudeSDKMessage = JSON.parse(line);\n this.handleSDKOutput(outputData, obs);\n } catch (error) {\n logger.debugMessage(\n `[${this.id}] Failed to parse JSON: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n }\n }\n });\n\n claude.stderr?.on('data', (data) => {\n logger.debugMessage(`[${this.id}] ${data.toString().trim()}`);\n });\n\n claude.on('close', (code) => {\n activeClaudeProcesses.delete(claude);\n if (code === 0) {\n resolve(output.trim());\n } else {\n logger.debugMessage(\n `[${this.id}] Claude Code exited with code ${code}: ${errorOutput}`\n );\n reject(\n new Error(\n `[${this.id}] Claude Code exited with code ${code}: ${errorOutput}`\n )\n );\n }\n });\n\n claude.on('error', (error) => {\n activeClaudeProcesses.delete(claude);\n logger.debugMessage(\n `[${this.id}] failed to run Claude Code: ${error.message}`\n );\n reject(\n new Error(\n `[${this.id}] failed to run Claude Code: ${error.message}`\n )\n );\n });\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: getSessionId(),\n event: 'tool_used',\n properties: {\n tool: c.name,\n },\n });\n }\n }\n });\n if (text.length > 0) {\n logger.verboseMessage(`[${this.id}] ${text.join('').trim()}`);\n }\n if (toolUses.length > 0) {\n logger.debugMessage(`[${this.id}] used tools: ${toolUses.join(', ')}`);\n }\n this.manager.stats.updateStats({\n newToolCalls: toolUses.length,\n newInputTokens: outputData.message.usage.input_tokens,\n newOutputTokens: outputData.message.usage.output_tokens,\n newCachedInputTokens:\n outputData.message.usage.cache_read_input_tokens ?? 0,\n });\n } else if (outputData.type === 'result') {\n if (!outputData.is_error) {\n logger.verboseMessage(\n `[${this.id}] finished task.\\nCost: $${Number(outputData.cost_usd).toFixed(2)}\\nDuration: ${\n Number(outputData.duration_ms) / 1000\n }s`\n );\n } else {\n logger.verboseMessage(\n `[${this.id}] finished task with error: ${outputData.subtype}\\nCost: $${outputData.cost_usd}\\nDuration: ${\n Number(outputData.duration_ms) / 1000\n }s`\n );\n }\n if (outputData.subtype === 'success') {\n this.changes.push(outputData.result);\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 newTurns: Number(outputData.num_turns),\n });\n } else if (outputData.type === 'system') {\n if (outputData.subtype === 'init') {\n this.sessionId = outputData.session_id;\n }\n }\n }\n\n generateReport(): string {\n return this.changes.join('\\n');\n }\n}\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AAYvC,MAAM,qBAAqB,GAAG;IAC5B,0BAA0B;IAC1B,yBAAyB;IACzB,MAAM;IACN,MAAM;IACN,WAAW;IACX,OAAO;CACR,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,iBAAiB,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAE7D,MAAM,gBAAgB,GAAG,CAAC,cAAc,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;AAEnE,0CAA0C;AAC1C,MAAM,qBAAqB,GAAG,IAAI,GAAG,EAAO,CAAC;AAE7C,+CAA+C;AAC/C,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,qBAAqB,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACrC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACvB,CAAC;IACH,CAAC,CAAC,CAAC;IACH,qBAAqB,CAAC,KAAK,EAAE,CAAC;AAChC,CAAC,CAAC;AAEF,iDAAiD;AACjD,IAAI,aAAa,GAAG,KAAK,CAAC;AAC1B,MAAM,oBA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AAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;CACF","debug_id":"6d5939a4-358d-5c84-9b82-40f12427ee02"}
|
|
1
|
+
{"version":3,"file":"claudeCode.js","sources":["utils/claudeCode.ts"],"sourceRoot":"/","sourcesContent":["import { spawn } from 'node:child_process';\nimport { ClaudeSDKMessage } from '../types/claude-sdk.js';\nimport { guides } from '../mcp/tools/guides.js';\nimport { logger } from '../logging/logger.js';\nimport { posthog } from '../telemetry.js';\nimport { LocadexManager } from './locadexManager.js';\nimport { getSessionId } from './session.js';\nimport * as Sentry from '@sentry/node';\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// Legacy function for backward compatibility\nexport const killAllClaudeProcesses = () => {\n // No-op since we now use AbortController\n};\n\nexport class ClaudeCodeRunner {\n private id: string;\n private sessionId: string = '';\n private mcpConfig: string | undefined;\n private manager: LocadexManager;\n private changes: string[] = [];\n\n constructor(\n manager: LocadexManager,\n private options: {\n id: string;\n apiKey?: string;\n mcpConfig?: string;\n }\n ) {\n this.manager = manager;\n this.id = options.id;\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 // AbortController handles cleanup automatically\n }\n\n getSessionId(): string {\n return this.sessionId;\n }\n\n async run(\n options: ClaudeCodeOptions,\n obs: ClaudeCodeObservation,\n controller: AbortController\n ): Promise<string> {\n this.changes = [];\n return Sentry.startSpan(\n {\n name: 'claude-code-exec',\n op: 'claude-code.exec',\n attributes: {\n 'process.command': 'claude',\n },\n },\n () =>\n 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 logger.debugMessage(\n `[${this.id}] Spawning Claude Code with additional args: ${JSON.stringify(\n {\n maxTurns: options.maxTurns,\n sessionId: options.sessionId,\n mcpConfig: this.mcpConfig,\n additionalAllowedTools: options.additionalAllowedTools,\n },\n null,\n 2\n )}`\n );\n\n const claude = spawn('claude', args, {\n stdio: ['inherit', 'pipe', 'pipe'],\n env,\n signal: controller.signal,\n });\n\n logger.debugMessage(`[${this.id}] Spawned claude code process`);\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(`[${this.id}] ${line}`);\n const outputData: ClaudeSDKMessage = JSON.parse(line);\n this.handleSDKOutput(outputData, obs);\n } catch (error) {\n logger.debugMessage(\n `[${this.id}] Failed to parse JSON: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n }\n }\n });\n\n claude.stderr?.on('data', (data) => {\n logger.debugMessage(`[${this.id}] ${data.toString().trim()}`);\n });\n\n claude.on('close', (code) => {\n if (code === 0) {\n resolve(output.trim());\n } else {\n logger.debugMessage(\n `[${this.id}] Claude Code exited with code ${code}: ${errorOutput}`\n );\n reject(\n new Error(\n `[${this.id}] Claude Code exited with code ${code}: ${errorOutput}`\n )\n );\n }\n });\n\n claude.on('error', (error) => {\n // Check if this is an AbortError\n if (error.name === 'AbortError') {\n logger.debugMessage(\n `[${this.id}] Claude Code process was aborted`\n );\n reject(new Error(`[${this.id}] Claude Code process was aborted`));\n } else {\n logger.debugMessage(\n `[${this.id}] failed to run Claude Code: ${error.message}`\n );\n reject(\n new Error(\n `[${this.id}] failed to run Claude Code: ${error.message}`\n )\n );\n }\n });\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: getSessionId(),\n event: 'tool_used',\n properties: {\n tool: c.name,\n },\n });\n }\n }\n });\n if (text.length > 0) {\n logger.verboseMessage(`[${this.id}] ${text.join('').trim()}`);\n }\n if (toolUses.length > 0) {\n logger.debugMessage(`[${this.id}] used tools: ${toolUses.join(', ')}`);\n }\n this.manager.stats.updateStats({\n newToolCalls: toolUses.length,\n newInputTokens: outputData.message.usage.input_tokens,\n newOutputTokens: outputData.message.usage.output_tokens,\n newCachedInputTokens:\n outputData.message.usage.cache_read_input_tokens ?? 0,\n });\n } else if (outputData.type === 'result') {\n if (!outputData.is_error) {\n logger.verboseMessage(\n `[${this.id}] finished task.\\nCost: $${Number(outputData.cost_usd).toFixed(2)}\\nDuration: ${\n Number(outputData.duration_ms) / 1000\n }s`\n );\n } else {\n logger.verboseMessage(\n `[${this.id}] finished task with error: ${outputData.subtype}\\nCost: $${outputData.cost_usd}\\nDuration: ${\n Number(outputData.duration_ms) / 1000\n }s`\n );\n }\n if (outputData.subtype === 'success') {\n this.changes.push(outputData.result);\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 newTurns: Number(outputData.num_turns),\n });\n } else if (outputData.type === 'system') {\n if (outputData.subtype === 'init') {\n this.sessionId = outputData.session_id;\n }\n }\n }\n\n generateReport(): string {\n return this.changes.join('\\n');\n }\n}\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AAYvC,MAAM,qBAAqB,GAAG;IAC5B,0BAA0B;IAC1B,yBAAyB;IACzB,MAAM;IACN,MAAM;IACN,WAAW;IACX,OAAO;CACR,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,iBAAiB,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAE7D,MAAM,gBAAgB,GAAG,CAAC,cAAc,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;AAEnE,6CAA6C;AAC7C,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,yCAAyC;AAC3C,CAAC,CAAC;AAEF,MAAM,OAAO,gBAAgB;IASjB;IARF,EAAE,CAAS;IACX,SAAS,GAAW,EAAE,CAAC;IACvB,SAAS,CAAqB;IAC9B,OAAO,CAAiB;IACxB,OAAO,GAAa,E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AAO,KAAK,MAAM,EAAE,CAAC;gBAClC,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,UAAU,CAAC;YACzC,CAAC;QACH,CAAC;IACH,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;CACF","debug_id":"9224d302-8aa2-52e4-bb5a-7376ff85f7e3"}
|
|
@@ -30,6 +30,8 @@ export declare class LocadexManager {
|
|
|
30
30
|
private maxConcurrency;
|
|
31
31
|
private batchSize;
|
|
32
32
|
private agentPool;
|
|
33
|
+
private agentAbortController;
|
|
34
|
+
private mcpAbortController;
|
|
33
35
|
private agentMutex;
|
|
34
36
|
private config;
|
|
35
37
|
stats: AgentStats;
|
|
@@ -67,5 +69,6 @@ export declare class LocadexManager {
|
|
|
67
69
|
getLockFilePath(): string;
|
|
68
70
|
cleanup(): void;
|
|
69
71
|
getWorkingDir(): string;
|
|
72
|
+
getAgentAbortController(): AbortController;
|
|
70
73
|
}
|
|
71
74
|
//# sourceMappingURL=locadexManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locadexManager.d.ts","sourceRoot":"/","sources":["utils/locadexManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAA0B,MAAM,iBAAiB,CAAC;AAU3E,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAM5D,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,KAAK,GAAG,OAAO,CAAC;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;I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AK,IAAI,IAAI;IAOpB,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,gBAAgB;IAQ/C,eAAe,IAAI,IAAI;IAajB,iBAAiB,IAAI,OAAO,CAAC;QACjC,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,EAAE,gBAAgB,CAAC;QACxB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,IAAI,CAAC;IAmBT,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAOpC,YAAY,IAAI,GAAG,CACjB,MAAM,EACN;QAAE,KAAK,EAAE,gBAAgB,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,CAC/D;IAID,aAAa,IAAI,IAAI;IAkBrB,qBAAqB,IAAI,MAAM;IAG/B,mBAAmB,IAAI,MAAM;IAG7B,iBAAiB,IAAI,MAAM;IAG3B,YAAY,IAAI,MAAM;IAGtB,SAAS,IAAI,aAAa;IAI1B,eAAe,IAAI,MAAM;IAIzB,OAAO,IAAI,IAAI;IAmBf,aAAa,IAAI,MAAM;IAIvB,uBAAuB,IAAI,eAAe;CAG3C"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
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]="
|
|
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]="48754f99-2dd6-5fec-a692-2367d5023c12")}catch(e){}}();
|
|
3
3
|
import { ClaudeCodeRunner, killAllClaudeProcesses } from './claudeCode.js';
|
|
4
4
|
import { fromPackageRoot } from './getPaths.js';
|
|
5
5
|
import fs from 'node:fs';
|
|
@@ -44,6 +44,8 @@ export class LocadexManager {
|
|
|
44
44
|
maxConcurrency;
|
|
45
45
|
batchSize;
|
|
46
46
|
agentPool;
|
|
47
|
+
agentAbortController;
|
|
48
|
+
mcpAbortController;
|
|
47
49
|
agentMutex = Promise.resolve();
|
|
48
50
|
config;
|
|
49
51
|
stats;
|
|
@@ -53,6 +55,8 @@ export class LocadexManager {
|
|
|
53
55
|
this.agentPool = new Map();
|
|
54
56
|
this.stats = new AgentStats();
|
|
55
57
|
this.mcpTransport = params.mcpTransport;
|
|
58
|
+
this.agentAbortController = new AbortController();
|
|
59
|
+
this.mcpAbortController = new AbortController();
|
|
56
60
|
const cwd = process.cwd();
|
|
57
61
|
this.locadexDirectory = path.resolve(cwd, '.locadex');
|
|
58
62
|
this.workingDir = path.resolve(this.locadexDirectory, 'runs', Date.now().toString());
|
|
@@ -122,10 +126,16 @@ export class LocadexManager {
|
|
|
122
126
|
PORT: port.toString(),
|
|
123
127
|
},
|
|
124
128
|
stdio: 'inherit',
|
|
129
|
+
signal: this.mcpAbortController.signal,
|
|
125
130
|
});
|
|
126
131
|
this.mcpProcess.on('error', async (error) => {
|
|
127
|
-
|
|
128
|
-
|
|
132
|
+
if (error.name === 'AbortError') {
|
|
133
|
+
logger.debugMessage('MCP server was closed');
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
logger.error(`MCP server failed to start: ${error.message}`);
|
|
137
|
+
await exit(1);
|
|
138
|
+
}
|
|
129
139
|
});
|
|
130
140
|
this.mcpProcess.on('exit', async (code, signal) => {
|
|
131
141
|
if (code !== 0 && code !== null) {
|
|
@@ -134,7 +144,7 @@ export class LocadexManager {
|
|
|
134
144
|
}
|
|
135
145
|
if (signal) {
|
|
136
146
|
logger.error(`MCP server was killed with signal ${signal}`);
|
|
137
|
-
await exit(
|
|
147
|
+
await exit(0);
|
|
138
148
|
}
|
|
139
149
|
});
|
|
140
150
|
}
|
|
@@ -207,11 +217,13 @@ export class LocadexManager {
|
|
|
207
217
|
}
|
|
208
218
|
cleanupAgents() {
|
|
209
219
|
logger.debugMessage('Cleaning up all Claude Code agents and processes');
|
|
210
|
-
//
|
|
220
|
+
// Abort all active processes
|
|
221
|
+
this.agentAbortController.abort();
|
|
222
|
+
// Mark agents as free
|
|
211
223
|
for (const agentData of this.agentPool.values()) {
|
|
212
224
|
agentData.busy = false;
|
|
213
225
|
}
|
|
214
|
-
// Kill all active Claude Code processes
|
|
226
|
+
// Kill all active Claude Code processes (fallback)
|
|
215
227
|
killAllClaudeProcesses();
|
|
216
228
|
// Clear the agent pool
|
|
217
229
|
this.agentPool.clear();
|
|
@@ -237,13 +249,15 @@ export class LocadexManager {
|
|
|
237
249
|
cleanup() {
|
|
238
250
|
// Clean up agents first (if not already done)
|
|
239
251
|
this.cleanupAgents();
|
|
240
|
-
// Clean up MCP process
|
|
252
|
+
// Clean up MCP process using abort controller
|
|
241
253
|
if (this.mcpProcess && !this.mcpProcess.killed) {
|
|
242
|
-
logger.debugMessage('
|
|
243
|
-
this.
|
|
254
|
+
logger.debugMessage('Terminating MCP process via abort controller');
|
|
255
|
+
this.mcpAbortController.abort();
|
|
256
|
+
// Give the process a moment to handle the abort signal gracefully
|
|
244
257
|
setTimeout(() => {
|
|
245
258
|
if (this.mcpProcess && !this.mcpProcess.killed) {
|
|
246
|
-
|
|
259
|
+
logger.debugMessage('Force killing MCP process as fallback');
|
|
260
|
+
this.mcpProcess.kill('SIGTERM');
|
|
247
261
|
}
|
|
248
262
|
}, 1000);
|
|
249
263
|
}
|
|
@@ -251,6 +265,9 @@ export class LocadexManager {
|
|
|
251
265
|
getWorkingDir() {
|
|
252
266
|
return this.workingDir;
|
|
253
267
|
}
|
|
268
|
+
getAgentAbortController() {
|
|
269
|
+
return this.agentAbortController;
|
|
270
|
+
}
|
|
254
271
|
}
|
|
255
272
|
//# sourceMappingURL=locadexManager.js.map
|
|
256
|
-
//# debugId=
|
|
273
|
+
//# debugId=48754f99-2dd6-5fec-a692-2367d5023c12
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locadexManager.js","sources":["utils/locadexManager.ts"],"sourceRoot":"/","sourcesContent":["import { ClaudeCodeRunner, killAllClaudeProcesses } from './claudeCode.js';\nimport { fromPackageRoot } from './getPaths.js';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { FileEntry } from './dag/getFiles.js';\nimport { logger } from '../logging/logger.js';\nimport { addToGitIgnore } from './fs/writeFiles.js';\nimport { spawn } from 'node:child_process';\nimport type { ChildProcess } from 'node:child_process';\nimport { setTimeout } from 'node:timers';\nimport { AgentStats } from './stats.js';\nimport { CliOptions, LocadexConfig } from '../types/cli.js';\nimport { findAvailablePort } from '../mcp/getPort.js';\nimport { createConfig, getConfig } from './config.js';\nimport { gracefulShutdown, exit } from './shutdown.js';\nimport { LOCKFILE_NAME } from './lockfile.js';\n\nexport interface LocadexRunMetadata {\n createdAt: string;\n locadexVersion: string;\n workingDirectory: string;\n projectName: string;\n transport: 'sse' | 'stdio';\n tempDirectory: string;\n nodeVersion: string;\n platform: string;\n arch: string;\n logFile: string;\n batchSize: number;\n maxConcurrency: number;\n [key: string]: any;\n}\n\nconst mcpStdioConfig = {\n mcpServers: {\n locadex: {\n command: 'npx',\n args: ['locadex-mcp'],\n env: {},\n },\n },\n};\nconst mcpSseConfig = {\n mcpServers: {\n locadex: {\n type: 'sse',\n url: 'http://localhost:8888/sse',\n },\n },\n};\n\nexport class LocadexManager {\n private static instance: LocadexManager | undefined;\n private mcpProcess: ChildProcess | undefined;\n private mcpTransport: 'sse' | 'stdio';\n private mcpConfigPath: string;\n private filesStateFilePath: string;\n private metadataFilePath: string;\n private lockFilePath: string;\n private workingDir: string;\n private locadexDirectory: string;\n private apiKey?: string;\n private maxConcurrency: number;\n private batchSize: number;\n private agentPool: Map<\n string,\n { agent: ClaudeCodeRunner; sessionId?: string; busy: boolean }\n >;\n private agentMutex = Promise.resolve();\n private config: LocadexConfig;\n stats: AgentStats;\n logFile: string;\n\n private constructor(params: {\n mcpTransport: 'sse' | 'stdio';\n apiKey?: string;\n metadata: Partial<LocadexRunMetadata>;\n options: Partial<LocadexConfig>;\n }) {\n this.apiKey = params.apiKey || process.env.ANTHROPIC_API_KEY;\n this.agentPool = new Map();\n this.stats = new AgentStats();\n this.mcpTransport = params.mcpTransport;\n\n const cwd = process.cwd();\n this.locadexDirectory = path.resolve(cwd, '.locadex');\n this.workingDir = path.resolve(\n this.locadexDirectory,\n 'runs',\n Date.now().toString()\n );\n fs.mkdirSync(this.workingDir, { recursive: true });\n\n this.config = getConfig(this.locadexDirectory, params.options);\n\n createConfig(this.locadexDirectory, {\n batchSize: this.config.batchSize,\n maxConcurrency: this.config.maxConcurrency,\n matchingFiles: this.config.matchingFiles,\n matchingExtensions: this.config.matchingExtensions,\n });\n\n addToGitIgnore(cwd, '.locadex/runs');\n\n this.maxConcurrency = this.config.maxConcurrency;\n this.batchSize = this.config.batchSize;\n this.mcpConfigPath = path.resolve(this.workingDir, 'mcp.json');\n this.filesStateFilePath = path.resolve(this.workingDir, 'files-state.json');\n this.metadataFilePath = path.resolve(this.workingDir, 'metadata.json');\n this.logFile = path.resolve(this.workingDir, 'log.txt');\n this.lockFilePath = path.resolve(this.locadexDirectory, LOCKFILE_NAME);\n\n // Create files-state.json\n const filesState: FileEntry[] = [];\n fs.writeFileSync(\n this.filesStateFilePath,\n JSON.stringify(filesState, null, 2)\n );\n\n // Create metadata.json\n const metadata: LocadexRunMetadata = {\n createdAt: new Date().toISOString(),\n locadexVersion: JSON.parse(\n fs.readFileSync(fromPackageRoot('package.json'), 'utf8')\n ).version,\n workingDirectory: cwd,\n projectName: path.basename(cwd),\n transport: params.mcpTransport,\n tempDirectory: this.workingDir,\n nodeVersion: process.version,\n platform: process.platform,\n arch: process.arch,\n logFile: this.logFile,\n batchSize: this.config.batchSize,\n maxConcurrency: this.config.maxConcurrency,\n ...params.metadata,\n };\n fs.writeFileSync(this.metadataFilePath, JSON.stringify(metadata, null, 2));\n\n // Register cleanup with graceful shutdown\n gracefulShutdown.addHandler({\n name: 'locadex-manager-cleanup',\n handler: () => this.cleanup(),\n timeout: 5000,\n });\n }\n\n async startMcpServer() {\n if (this.mcpTransport === 'stdio') {\n mcpStdioConfig.mcpServers.locadex.env = {\n LOCADEX_FILES_STATE_FILE_PATH: this.filesStateFilePath,\n LOCADEX_LOG_FILE_PATH: this.logFile,\n };\n fs.writeFileSync(\n this.mcpConfigPath,\n JSON.stringify(mcpStdioConfig, null, 2)\n );\n } else {\n // First, search for an available port\n const port = await findAvailablePort(8888);\n mcpSseConfig.mcpServers.locadex.url = `http://localhost:${port}/sse`;\n fs.writeFileSync(\n this.mcpConfigPath,\n JSON.stringify(mcpSseConfig, null, 2)\n );\n\n this.mcpProcess = spawn('node', [fromPackageRoot('dist/mcp-sse.js')], {\n env: {\n ...process.env,\n LOCADEX_FILES_STATE_FILE_PATH: this.filesStateFilePath,\n LOCADEX_VERBOSE: logger.verbose ? 'true' : 'false',\n LOCADEX_DEBUG: logger.debug ? 'true' : 'false',\n LOCADEX_LOG_FILE_PATH: this.logFile,\n PORT: port.toString(),\n },\n stdio: 'inherit',\n });\n\n this.mcpProcess.on('error', async (error) => {\n logger.error(`MCP server failed to start: ${error.message}`);\n await exit(1);\n });\n\n this.mcpProcess.on('exit', async (code, signal) => {\n if (code !== 0 && code !== null) {\n logger.error(`MCP server exited with code ${code}`);\n await exit(code as 0 | 1);\n }\n if (signal) {\n logger.error(`MCP server was killed with signal ${signal}`);\n await exit(1);\n }\n });\n }\n }\n\n static getInstance(): LocadexManager {\n if (!LocadexManager.instance) {\n throw new Error('LocadexManager not initialized');\n }\n return LocadexManager.instance;\n }\n\n static initialize(params: {\n mcpTransport: 'sse' | 'stdio';\n apiKey?: string;\n metadata: Partial<LocadexRunMetadata>;\n cliOptions: CliOptions;\n options: Partial<LocadexConfig>;\n }): void {\n if (!LocadexManager.instance) {\n LocadexManager.instance = new LocadexManager(params);\n logger.initialize(params.cliOptions, LocadexManager.instance.logFile);\n\n logger.debugMessage(\n `Locadex loaded with config: ${JSON.stringify(\n LocadexManager.instance.config,\n null,\n 2\n )}`\n );\n LocadexManager.instance.startMcpServer();\n }\n }\n\n static reset(): void {\n if (LocadexManager.instance) {\n LocadexManager.instance.cleanup();\n LocadexManager.instance = undefined;\n }\n }\n\n createSingleAgent(id: string): ClaudeCodeRunner {\n return new ClaudeCodeRunner(this, {\n apiKey: this.apiKey,\n mcpConfig: this.mcpConfigPath,\n id,\n });\n }\n\n createAgentPool(): void {\n if (this.agentPool.size === 0) {\n for (let i = 0; i < this.maxConcurrency; i++) {\n const agentId = `claude_task_agent_${i + 1}`;\n this.agentPool.set(agentId, {\n agent: this.createSingleAgent(agentId),\n sessionId: undefined,\n busy: false,\n });\n }\n }\n }\n\n async getAvailableAgent(): Promise<{\n id: string;\n agent: ClaudeCodeRunner;\n sessionId?: string;\n } | null> {\n return new Promise((resolve) => {\n this.agentMutex = this.agentMutex.then(() => {\n for (const [id, agentData] of this.agentPool) {\n if (!agentData.busy) {\n agentData.busy = true;\n resolve({\n id,\n agent: agentData.agent,\n sessionId: agentData.sessionId,\n });\n return;\n }\n }\n resolve(null);\n });\n });\n }\n\n markAgentFree(agentId: string): void {\n const agentData = this.agentPool.get(agentId);\n if (agentData) {\n agentData.busy = false;\n }\n }\n\n getAgentPool(): Map<\n string,\n { agent: ClaudeCodeRunner; sessionId?: string; busy: boolean }\n > {\n return this.agentPool;\n }\n\n cleanupAgents(): void {\n logger.debugMessage('Cleaning up all Claude Code agents and processes');\n\n // Mark all agents as free\n for (const agentData of this.agentPool.values()) {\n agentData.busy = false;\n }\n\n // Kill all active Claude Code processes\n killAllClaudeProcesses();\n\n // Clear the agent pool\n this.agentPool.clear();\n }\n\n getFilesStateFilePath(): string {\n return this.filesStateFilePath;\n }\n getMetadataFilePath(): string {\n return this.metadataFilePath;\n }\n getMaxConcurrency(): number {\n return this.maxConcurrency;\n }\n getBatchSize(): number {\n return this.batchSize;\n }\n getConfig(): LocadexConfig {\n return this.config;\n }\n\n getLockFilePath(): string {\n return this.lockFilePath;\n }\n\n cleanup(): void {\n // Clean up agents first (if not already done)\n this.cleanupAgents();\n\n // Clean up MCP process\n if (this.mcpProcess && !this.mcpProcess.killed) {\n logger.debugMessage('Killing MCP process');\n this.mcpProcess.kill('SIGTERM');\n setTimeout(() => {\n if (this.mcpProcess && !this.mcpProcess.killed) {\n this.mcpProcess.kill('SIGKILL');\n }\n }, 1000);\n }\n }\n\n getWorkingDir(): string {\n return this.workingDir;\n }\n}\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAkB9C,MAAM,cAAc,GAAG;IACrB,UAAU,EAAE;QACV,OAAO,EAAE;YACP,OAAO,EAAE,KAAK;YACd,IAAI,EAAE,CAAC,aAAa,CAAC;YACrB,GAAG,EAAE,EAAE;SACR;KACF;CACF,CAAC;AACF,MAAM,YAAY,GAAG;IACnB,UAAU,EA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,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBAClC,CAAC;YACH,CAAC,EAAE,IAAI,CAAC,CAAC;QACX,CAAC;IACH,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;CACF","debug_id":"bb7c0ee1-f264-5d56-b315-179d269584e2"}
|
|
1
|
+
{"version":3,"file":"locadexManager.js","sources":["utils/locadexManager.ts"],"sourceRoot":"/","sourcesContent":["import { ClaudeCodeRunner, killAllClaudeProcesses } from './claudeCode.js';\nimport { fromPackageRoot } from './getPaths.js';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { FileEntry } from './dag/getFiles.js';\nimport { logger } from '../logging/logger.js';\nimport { addToGitIgnore } from './fs/writeFiles.js';\nimport { spawn } from 'node:child_process';\nimport type { ChildProcess } from 'node:child_process';\nimport { setTimeout } from 'node:timers';\nimport { AgentStats } from './stats.js';\nimport { CliOptions, LocadexConfig } from '../types/cli.js';\nimport { findAvailablePort } from '../mcp/getPort.js';\nimport { createConfig, getConfig } from './config.js';\nimport { gracefulShutdown, exit } from './shutdown.js';\nimport { LOCKFILE_NAME } from './lockfile.js';\n\nexport interface LocadexRunMetadata {\n createdAt: string;\n locadexVersion: string;\n workingDirectory: string;\n projectName: string;\n transport: 'sse' | 'stdio';\n tempDirectory: string;\n nodeVersion: string;\n platform: string;\n arch: string;\n logFile: string;\n batchSize: number;\n maxConcurrency: number;\n [key: string]: any;\n}\n\nconst mcpStdioConfig = {\n mcpServers: {\n locadex: {\n command: 'npx',\n args: ['locadex-mcp'],\n env: {},\n },\n },\n};\nconst mcpSseConfig = {\n mcpServers: {\n locadex: {\n type: 'sse',\n url: 'http://localhost:8888/sse',\n },\n },\n};\n\nexport class LocadexManager {\n private static instance: LocadexManager | undefined;\n private mcpProcess: ChildProcess | undefined;\n private mcpTransport: 'sse' | 'stdio';\n private mcpConfigPath: string;\n private filesStateFilePath: string;\n private metadataFilePath: string;\n private lockFilePath: string;\n private workingDir: string;\n private locadexDirectory: string;\n private apiKey?: string;\n private maxConcurrency: number;\n private batchSize: number;\n private agentPool: Map<\n string,\n { agent: ClaudeCodeRunner; sessionId?: string; busy: boolean }\n >;\n private agentAbortController: AbortController;\n private mcpAbortController: AbortController;\n private agentMutex = Promise.resolve();\n private config: LocadexConfig;\n stats: AgentStats;\n logFile: string;\n\n private constructor(params: {\n mcpTransport: 'sse' | 'stdio';\n apiKey?: string;\n metadata: Partial<LocadexRunMetadata>;\n options: Partial<LocadexConfig>;\n }) {\n this.apiKey = params.apiKey || process.env.ANTHROPIC_API_KEY;\n this.agentPool = new Map();\n this.stats = new AgentStats();\n this.mcpTransport = params.mcpTransport;\n this.agentAbortController = new AbortController();\n this.mcpAbortController = new AbortController();\n\n const cwd = process.cwd();\n this.locadexDirectory = path.resolve(cwd, '.locadex');\n this.workingDir = path.resolve(\n this.locadexDirectory,\n 'runs',\n Date.now().toString()\n );\n fs.mkdirSync(this.workingDir, { recursive: true });\n\n this.config = getConfig(this.locadexDirectory, params.options);\n\n createConfig(this.locadexDirectory, {\n batchSize: this.config.batchSize,\n maxConcurrency: this.config.maxConcurrency,\n matchingFiles: this.config.matchingFiles,\n matchingExtensions: this.config.matchingExtensions,\n });\n\n addToGitIgnore(cwd, '.locadex/runs');\n\n this.maxConcurrency = this.config.maxConcurrency;\n this.batchSize = this.config.batchSize;\n this.mcpConfigPath = path.resolve(this.workingDir, 'mcp.json');\n this.filesStateFilePath = path.resolve(this.workingDir, 'files-state.json');\n this.metadataFilePath = path.resolve(this.workingDir, 'metadata.json');\n this.logFile = path.resolve(this.workingDir, 'log.txt');\n this.lockFilePath = path.resolve(this.locadexDirectory, LOCKFILE_NAME);\n\n // Create files-state.json\n const filesState: FileEntry[] = [];\n fs.writeFileSync(\n this.filesStateFilePath,\n JSON.stringify(filesState, null, 2)\n );\n\n // Create metadata.json\n const metadata: LocadexRunMetadata = {\n createdAt: new Date().toISOString(),\n locadexVersion: JSON.parse(\n fs.readFileSync(fromPackageRoot('package.json'), 'utf8')\n ).version,\n workingDirectory: cwd,\n projectName: path.basename(cwd),\n transport: params.mcpTransport,\n tempDirectory: this.workingDir,\n nodeVersion: process.version,\n platform: process.platform,\n arch: process.arch,\n logFile: this.logFile,\n batchSize: this.config.batchSize,\n maxConcurrency: this.config.maxConcurrency,\n ...params.metadata,\n };\n fs.writeFileSync(this.metadataFilePath, JSON.stringify(metadata, null, 2));\n\n // Register cleanup with graceful shutdown\n gracefulShutdown.addHandler({\n name: 'locadex-manager-cleanup',\n handler: () => this.cleanup(),\n timeout: 5000,\n });\n }\n\n async startMcpServer() {\n if (this.mcpTransport === 'stdio') {\n mcpStdioConfig.mcpServers.locadex.env = {\n LOCADEX_FILES_STATE_FILE_PATH: this.filesStateFilePath,\n LOCADEX_LOG_FILE_PATH: this.logFile,\n };\n fs.writeFileSync(\n this.mcpConfigPath,\n JSON.stringify(mcpStdioConfig, null, 2)\n );\n } else {\n // First, search for an available port\n const port = await findAvailablePort(8888);\n mcpSseConfig.mcpServers.locadex.url = `http://localhost:${port}/sse`;\n fs.writeFileSync(\n this.mcpConfigPath,\n JSON.stringify(mcpSseConfig, null, 2)\n );\n\n this.mcpProcess = spawn('node', [fromPackageRoot('dist/mcp-sse.js')], {\n env: {\n ...process.env,\n LOCADEX_FILES_STATE_FILE_PATH: this.filesStateFilePath,\n LOCADEX_VERBOSE: logger.verbose ? 'true' : 'false',\n LOCADEX_DEBUG: logger.debug ? 'true' : 'false',\n LOCADEX_LOG_FILE_PATH: this.logFile,\n PORT: port.toString(),\n },\n stdio: 'inherit',\n signal: this.mcpAbortController.signal,\n });\n\n this.mcpProcess.on('error', async (error) => {\n if (error.name === 'AbortError') {\n logger.debugMessage('MCP server was closed');\n } else {\n logger.error(`MCP server failed to start: ${error.message}`);\n await exit(1);\n }\n });\n\n this.mcpProcess.on('exit', async (code, signal) => {\n if (code !== 0 && code !== null) {\n logger.error(`MCP server exited with code ${code}`);\n await exit(code as 0 | 1);\n }\n if (signal) {\n logger.error(`MCP server was killed with signal ${signal}`);\n await exit(0);\n }\n });\n }\n }\n\n static getInstance(): LocadexManager {\n if (!LocadexManager.instance) {\n throw new Error('LocadexManager not initialized');\n }\n return LocadexManager.instance;\n }\n\n static initialize(params: {\n mcpTransport: 'sse' | 'stdio';\n apiKey?: string;\n metadata: Partial<LocadexRunMetadata>;\n cliOptions: CliOptions;\n options: Partial<LocadexConfig>;\n }): void {\n if (!LocadexManager.instance) {\n LocadexManager.instance = new LocadexManager(params);\n logger.initialize(params.cliOptions, LocadexManager.instance.logFile);\n\n logger.debugMessage(\n `Locadex loaded with config: ${JSON.stringify(\n LocadexManager.instance.config,\n null,\n 2\n )}`\n );\n LocadexManager.instance.startMcpServer();\n }\n }\n\n static reset(): void {\n if (LocadexManager.instance) {\n LocadexManager.instance.cleanup();\n LocadexManager.instance = undefined;\n }\n }\n\n createSingleAgent(id: string): ClaudeCodeRunner {\n return new ClaudeCodeRunner(this, {\n apiKey: this.apiKey,\n mcpConfig: this.mcpConfigPath,\n id,\n });\n }\n\n createAgentPool(): void {\n if (this.agentPool.size === 0) {\n for (let i = 0; i < this.maxConcurrency; i++) {\n const agentId = `claude_task_agent_${i + 1}`;\n this.agentPool.set(agentId, {\n agent: this.createSingleAgent(agentId),\n sessionId: undefined,\n busy: false,\n });\n }\n }\n }\n\n async getAvailableAgent(): Promise<{\n id: string;\n agent: ClaudeCodeRunner;\n sessionId?: string;\n } | null> {\n return new Promise((resolve) => {\n this.agentMutex = this.agentMutex.then(() => {\n for (const [id, agentData] of this.agentPool) {\n if (!agentData.busy) {\n agentData.busy = true;\n resolve({\n id,\n agent: agentData.agent,\n sessionId: agentData.sessionId,\n });\n return;\n }\n }\n resolve(null);\n });\n });\n }\n\n markAgentFree(agentId: string): void {\n const agentData = this.agentPool.get(agentId);\n if (agentData) {\n agentData.busy = false;\n }\n }\n\n getAgentPool(): Map<\n string,\n { agent: ClaudeCodeRunner; sessionId?: string; busy: boolean }\n > {\n return this.agentPool;\n }\n\n cleanupAgents(): void {\n logger.debugMessage('Cleaning up all Claude Code agents and processes');\n\n // Abort all active processes\n this.agentAbortController.abort();\n\n // Mark agents as free\n for (const agentData of this.agentPool.values()) {\n agentData.busy = false;\n }\n\n // Kill all active Claude Code processes (fallback)\n killAllClaudeProcesses();\n\n // Clear the agent pool\n this.agentPool.clear();\n }\n\n getFilesStateFilePath(): string {\n return this.filesStateFilePath;\n }\n getMetadataFilePath(): string {\n return this.metadataFilePath;\n }\n getMaxConcurrency(): number {\n return this.maxConcurrency;\n }\n getBatchSize(): number {\n return this.batchSize;\n }\n getConfig(): LocadexConfig {\n return this.config;\n }\n\n getLockFilePath(): string {\n return this.lockFilePath;\n }\n\n cleanup(): void {\n // Clean up agents first (if not already done)\n this.cleanupAgents();\n\n // Clean up MCP process using abort controller\n if (this.mcpProcess && !this.mcpProcess.killed) {\n logger.debugMessage('Terminating MCP process via abort controller');\n this.mcpAbortController.abort();\n\n // Give the process a moment to handle the abort signal gracefully\n setTimeout(() => {\n if (this.mcpProcess && !this.mcpProcess.killed) {\n logger.debugMessage('Force killing MCP process as fallback');\n this.mcpProcess.kill('SIGTERM');\n }\n }, 1000);\n }\n }\n\n getWorkingDir(): string {\n return this.workingDir;\n }\n\n getAgentAbortController(): AbortController {\n return this.agentAbortController;\n }\n}\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa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ec-a692-2367d5023c12"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"installPackage.d.ts","sourceRoot":"/","sources":["utils/packages/installPackage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"installPackage.d.ts","sourceRoot":"/","sources":["utils/packages/installPackage.ts"],"names":[],"mappings":"AAQA,wBAAsB,iBAAiB,kBAqBtC"}
|
|
@@ -1,22 +1,30 @@
|
|
|
1
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]="
|
|
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]="4315bb3c-f91e-59a8-82ba-0b76e35bae44")}catch(e){}}();
|
|
3
3
|
import { getPackageInfo } from 'gtx-cli/utils/packageInfo';
|
|
4
4
|
import { createSpinner } from '../../logging/console.js';
|
|
5
5
|
import chalk from 'chalk';
|
|
6
6
|
import { installPackageGlobal } from 'gtx-cli/utils/installPackage';
|
|
7
7
|
import { logger } from '../../logging/logger.js';
|
|
8
8
|
import { CLAUDE_CODE_VERSION } from '../shared.js';
|
|
9
|
+
import { exit } from '../shutdown.js';
|
|
9
10
|
export async function installClaudeCode() {
|
|
10
11
|
const claudeCodeInfo = await getPackageInfo('@anthropic-ai/claude-code');
|
|
11
12
|
if (!claudeCodeInfo) {
|
|
12
13
|
const spinner = createSpinner();
|
|
13
14
|
spinner.start('Installing claude-code...');
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
try {
|
|
16
|
+
await installPackageGlobal('@anthropic-ai/claude-code', CLAUDE_CODE_VERSION);
|
|
17
|
+
spinner.stop(chalk.green('Installed claude-code.'));
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
spinner.stop(chalk.red('Failed to install claude-code.'));
|
|
21
|
+
logger.error('Claude Code installation failed. Please install it manually and try again.');
|
|
22
|
+
await exit(1);
|
|
23
|
+
}
|
|
16
24
|
}
|
|
17
25
|
else {
|
|
18
26
|
logger.step(`claude-code is already installed: v${claudeCodeInfo.version}`);
|
|
19
27
|
}
|
|
20
28
|
}
|
|
21
29
|
//# sourceMappingURL=installPackage.js.map
|
|
22
|
-
//# debugId=
|
|
30
|
+
//# debugId=4315bb3c-f91e-59a8-82ba-0b76e35bae44
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"installPackage.js","sources":["utils/packages/installPackage.ts"],"sourceRoot":"/","sourcesContent":["import { getPackageInfo } from 'gtx-cli/utils/packageInfo';\nimport { createSpinner } from '../../logging/console.js';\nimport chalk from 'chalk';\nimport { installPackageGlobal } from 'gtx-cli/utils/installPackage';\nimport { logger } from '../../logging/logger.js';\nimport { CLAUDE_CODE_VERSION } from '../shared.js';\n\nexport async function installClaudeCode() {\n const claudeCodeInfo = await getPackageInfo('@anthropic-ai/claude-code');\n if (!claudeCodeInfo) {\n const spinner = createSpinner();\n spinner.start('Installing claude-code...');\n await installPackageGlobal(\n
|
|
1
|
+
{"version":3,"file":"installPackage.js","sources":["utils/packages/installPackage.ts"],"sourceRoot":"/","sourcesContent":["import { getPackageInfo } from 'gtx-cli/utils/packageInfo';\nimport { createSpinner } from '../../logging/console.js';\nimport chalk from 'chalk';\nimport { installPackageGlobal } from 'gtx-cli/utils/installPackage';\nimport { logger } from '../../logging/logger.js';\nimport { CLAUDE_CODE_VERSION } from '../shared.js';\nimport { exit } from '../shutdown.js';\n\nexport async function installClaudeCode() {\n const claudeCodeInfo = await getPackageInfo('@anthropic-ai/claude-code');\n if (!claudeCodeInfo) {\n const spinner = createSpinner();\n spinner.start('Installing claude-code...');\n try {\n await installPackageGlobal(\n '@anthropic-ai/claude-code',\n CLAUDE_CODE_VERSION\n );\n spinner.stop(chalk.green('Installed claude-code.'));\n } catch (error) {\n spinner.stop(chalk.red('Failed to install claude-code.'));\n logger.error(\n 'Claude Code installation failed. Please install it manually and try again.'\n );\n await exit(1);\n }\n } else {\n logger.step(`claude-code is already installed: v${claudeCodeInfo.version}`);\n }\n}\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,MAAM,CAAC,KAAK,UAAU,iBAAiB;IACrC,MAAM,cAAc,GAAG,MAAM,cAAc,CAAC,2BAA2B,CAAC,CAAC;IACzE,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,MAAM,OAAO,GAAG,aAAa,EAAE,CAAC;QAChC,OAAO,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAC3C,IAAI,CAAC;YACH,MAAM,oBAAoB,CACxB,2BAA2B,EAC3B,mBAAmB,CACpB,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC,CAAC;QACtD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC,CAAC;YAC1D,MAAM,CAAC,KAAK,CACV,4EAA4E,CAC7E,CAAC;YACF,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC;QAChB,CAAC;IACH,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,IAAI,CAAC,sCAAsC,cAAc,CAAC,OAAO,EAAE,CAAC,CAAC;IAC9E,CAAC;AACH,CAAC","debug_id":"4315bb3c-f91e-59a8-82ba-0b76e35bae44"}
|