@arcteninc/core 0.0.59 → 0.0.61

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcteninc/core",
3
- "version": "0.0.59",
3
+ "version": "0.0.61",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -20,21 +20,21 @@
20
20
  },
21
21
  "sideEffects": false,
22
22
  "bin": {
23
- "arcten-extract-types": "./scripts/cli-extract-types-auto.js",
24
- "arcten-update-core": "./scripts/update-core.js"
23
+ "arcten": "./scripts/arcten-cli.cjs"
25
24
  },
26
25
  "files": [
27
26
  "dist",
28
27
  "scripts/cli-extract-types-auto.ts",
29
28
  "scripts/cli-extract-types-auto.js",
30
- "scripts/postinstall-check-version.js",
31
- "scripts/update-core.js"
29
+ "scripts/arcten-cli.cjs",
30
+ "scripts/postinstall-check-version.cjs",
31
+ "scripts/update-core.cjs"
32
32
  ],
33
33
  "scripts": {
34
34
  "dev": "vite build --watch",
35
35
  "build": "vite build",
36
36
  "prepublishOnly": "bun run build",
37
- "postinstall": "node scripts/postinstall-check-version.js"
37
+ "postinstall": "node scripts/postinstall-check-version.cjs"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "ai": "^6.0.0-beta.94",
@@ -0,0 +1,132 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Arcten CLI - Unified command interface
4
+ * Usage: arcten <command> [options]
5
+ *
6
+ * Commands:
7
+ * extract-types, tools Extract tool metadata from your project
8
+ * update Update @arcteninc/core to latest version
9
+ * help Show help message
10
+ */
11
+
12
+ const { spawn } = require('child_process');
13
+ const path = require('path');
14
+ const fs = require('fs');
15
+
16
+ const commands = {
17
+ 'extract-types': () => require('./cli-extract-types-auto.js'),
18
+ 'tools': () => require('./cli-extract-types-auto.js'), // Alias
19
+ 'update': () => require('./update-core.js'),
20
+ 'help': showHelp,
21
+ '--help': showHelp,
22
+ '-h': showHelp,
23
+ };
24
+
25
+ function showHelp() {
26
+ console.log(`
27
+ 📦 Arcten CLI
28
+
29
+ Usage: arcten <command> [options]
30
+
31
+ Commands:
32
+ extract-types, tools Extract tool metadata from your project
33
+ Alias: arcten tools
34
+
35
+ update Update @arcteninc/core to latest version
36
+ Updates package.json and shows next steps
37
+
38
+ help Show this help message
39
+
40
+ Examples:
41
+ arcten tools Extract tool types (same as arcten extract-types)
42
+ arcten update Update @arcteninc/core to latest version
43
+ arcten help Show help
44
+
45
+ For more information, visit https://github.com/arcteninc/core
46
+ `);
47
+ process.exit(0);
48
+ }
49
+
50
+ function main() {
51
+ const args = process.argv.slice(2);
52
+
53
+ if (args.length === 0) {
54
+ showHelp();
55
+ return;
56
+ }
57
+
58
+ const command = args[0];
59
+ const commandArgs = args.slice(1);
60
+
61
+ if (!commands[command]) {
62
+ console.error(`❌ Unknown command: ${command}`);
63
+ console.error(`\nRun 'arcten help' for available commands`);
64
+ process.exit(1);
65
+ }
66
+
67
+ try {
68
+ const commandHandler = commands[command];
69
+ if (typeof commandHandler === 'function' && commandHandler !== showHelp) {
70
+ // For commands that are modules, we need to handle them differently
71
+ // Since they're designed to run as standalone scripts, we'll spawn them
72
+ let scriptPath;
73
+ let runner = 'node';
74
+
75
+ if (command === 'update') {
76
+ scriptPath = path.join(__dirname, 'update-core.cjs');
77
+ } else {
78
+ // For extract-types/tools, try .js first, fallback to .ts with bun
79
+ const jsPath = path.join(__dirname, 'cli-extract-types-auto.js');
80
+ const tsPath = path.join(__dirname, 'cli-extract-types-auto.ts');
81
+
82
+ if (fs.existsSync(jsPath)) {
83
+ scriptPath = jsPath;
84
+ } else if (fs.existsSync(tsPath)) {
85
+ scriptPath = tsPath;
86
+ runner = 'bun'; // Use bun for TypeScript files
87
+ } else {
88
+ console.error(`❌ Script not found: ${jsPath} or ${tsPath}`);
89
+ process.exit(1);
90
+ }
91
+ }
92
+
93
+ if (!fs.existsSync(scriptPath)) {
94
+ console.error(`❌ Script not found: ${scriptPath}`);
95
+ process.exit(1);
96
+ }
97
+
98
+ // Spawn the script with remaining args
99
+ const child = spawn(runner, [scriptPath, ...commandArgs], {
100
+ stdio: 'inherit',
101
+ cwd: process.cwd(),
102
+ shell: true // Use shell to find bun/node in PATH
103
+ });
104
+
105
+ child.on('error', (error) => {
106
+ console.error(`❌ Failed to run command:`, error.message);
107
+ if (runner === 'bun' && error.code === 'ENOENT') {
108
+ console.error(`\n💡 Bun not found. Install it: https://bun.sh`);
109
+ console.error(` Or ensure cli-extract-types-auto.js is compiled`);
110
+ }
111
+ process.exit(1);
112
+ });
113
+
114
+ child.on('exit', (code) => {
115
+ process.exit(code || 0);
116
+ });
117
+ } else {
118
+ // For help command
119
+ commandHandler();
120
+ }
121
+ } catch (error) {
122
+ console.error(`❌ Error running command:`, error.message);
123
+ process.exit(1);
124
+ }
125
+ }
126
+
127
+ if (require.main === module) {
128
+ main();
129
+ }
130
+
131
+ module.exports = { main };
132
+
File without changes
@@ -83,7 +83,6 @@ async function findToolUsageFiles(projectRoot: string): Promise<string[]> {
83
83
  ignore: ['**/node_modules/**', '**/dist/**', '**/.next/**', '**/build/**'],
84
84
  });
85
85
 
86
- console.log(`📂 Found ${files.length} TypeScript files to scan`);
87
86
  return files;
88
87
  }
89
88
 
@@ -1382,10 +1381,11 @@ async function extractFunctionMetadata(
1382
1381
  * Main function
1383
1382
  */
1384
1383
  async function autoDiscoverAndExtract(projectRoot: string, outputPath: string) {
1385
- console.log(`\n🔍 Auto-discovering tools in: ${projectRoot}\n`);
1384
+ console.log(`\n🔍 Discovering tools in your project...\n`);
1386
1385
 
1387
1386
  // Find all TypeScript files
1388
1387
  const files = await findToolUsageFiles(projectRoot);
1388
+ console.log(`📂 Scanning ${files.length} TypeScript file${files.length !== 1 ? 's' : ''}...`);
1389
1389
 
1390
1390
  // Read tsconfig
1391
1391
  const configPath = ts.findConfigFile(projectRoot, ts.sys.fileExists, 'tsconfig.json');
@@ -1420,19 +1420,34 @@ async function autoDiscoverAndExtract(projectRoot: string, outputPath: string) {
1420
1420
  }
1421
1421
  }
1422
1422
 
1423
- console.log(`✓ Found ${allToolUsages.length} usage site(s) with ${allToolNames.size} unique tool(s)`);
1424
- allToolUsages.forEach(usage => {
1425
- console.log(` - ${usage.component} in ${path.relative(projectRoot, usage.file)}`);
1426
- console.log(` Tools: ${Array.from(usage.toolNames).join(', ')}`);
1423
+ if (allToolUsages.length === 0) {
1424
+ console.log(`\n⚠️ No tool usages found in ArctenAgent or useAgent components`);
1425
+ console.log(`\n💡 Make sure you're using tools like this:`);
1426
+ console.log(` <ArctenAgent safeTools={[getLocation, resetPassword]} />`);
1427
+ console.log(` or`);
1428
+ console.log(` useAgent({ safeTools: [getLocation, resetPassword] })\n`);
1429
+ return;
1430
+ }
1431
+
1432
+ console.log(`\n✨ Found ${allToolUsages.length} usage site${allToolUsages.length !== 1 ? 's' : ''} with ${allToolNames.size} unique tool${allToolNames.size !== 1 ? 's' : ''}:`);
1433
+ allToolUsages.forEach((usage, idx) => {
1434
+ const relativePath = path.relative(projectRoot, usage.file);
1435
+ const tools = Array.from(usage.toolNames);
1436
+ console.log(`\n ${idx + 1}. ${usage.component} in ${relativePath}`);
1437
+ console.log(` Tools: ${tools.map(t => `\x1b[36m${t}\x1b[0m`).join(', ')}`);
1427
1438
  });
1428
1439
 
1429
1440
  // Extract metadata for discovered tools
1430
- console.log(`\n📝 Extracting types for discovered tools...\n`);
1441
+ console.log(`\n📝 Extracting type metadata...\n`);
1431
1442
 
1432
1443
  const functionsMap: Record<string, FunctionMetadata> = {};
1433
1444
  const discoveredFrom: string[] = [];
1434
1445
 
1435
- for (const toolName of allToolNames) {
1446
+ const toolNamesArray = Array.from(allToolNames);
1447
+ let successCount = 0;
1448
+ let warningCount = 0;
1449
+
1450
+ for (const toolName of toolNamesArray) {
1436
1451
  let found = false;
1437
1452
 
1438
1453
  // Search in all files for the definition
@@ -1445,8 +1460,10 @@ async function autoDiscoverAndExtract(projectRoot: string, outputPath: string) {
1445
1460
  if (metadata) {
1446
1461
  functionsMap[toolName] = metadata;
1447
1462
  discoveredFrom.push(path.relative(projectRoot, result.sourceFile.fileName));
1448
- console.log(` ✓ ${toolName} (from ${path.relative(projectRoot, result.sourceFile.fileName)})`);
1463
+ const relativePath = path.relative(projectRoot, result.sourceFile.fileName);
1464
+ console.log(` ✓ \x1b[32m${toolName}\x1b[0m \x1b[90m(${relativePath})\x1b[0m`);
1449
1465
  found = true;
1466
+ successCount++;
1450
1467
  break;
1451
1468
  }
1452
1469
  }
@@ -1454,7 +1471,8 @@ async function autoDiscoverAndExtract(projectRoot: string, outputPath: string) {
1454
1471
  }
1455
1472
 
1456
1473
  if (!found) {
1457
- console.log(` ⚠ ${toolName} (definition not found)`);
1474
+ console.log(` \x1b[33m${toolName}\x1b[0m \x1b[90m(definition not found)\x1b[0m`);
1475
+ warningCount++;
1458
1476
  }
1459
1477
  }
1460
1478
 
@@ -1505,11 +1523,24 @@ export const toolMetadata = ${JSON.stringify(output, null, 2)} as const;
1505
1523
  `;
1506
1524
 
1507
1525
  fs.writeFileSync(outputPath, tsContent);
1508
- console.log(`\n✅ Generated metadata for ${Object.keys(functionsMap).length} tool(s)`);
1509
- console.log(`📁 Output: ${outputPath}`);
1510
- console.log(`\n💡 Usage in your component:`);
1511
- console.log(` import { toolMetadata } from './.arcten/tool-metadata';`);
1512
- console.log(` useAgent({ tools: [...], toolMetadata: toolMetadata.functions })\n`);
1526
+
1527
+ const relativeOutput = path.relative(projectRoot, outputPath);
1528
+
1529
+ console.log(`\n${'='.repeat(60)}`);
1530
+ if (successCount > 0) {
1531
+ console.log(`✅ Successfully extracted ${successCount} tool${successCount !== 1 ? 's' : ''}`);
1532
+ }
1533
+ if (warningCount > 0) {
1534
+ console.log(`⚠️ ${warningCount} tool${warningCount !== 1 ? 's' : ''} not found (check function names)`);
1535
+ }
1536
+ console.log(`📁 Output: \x1b[36m${relativeOutput}\x1b[0m`);
1537
+ console.log(`${'='.repeat(60)}\n`);
1538
+
1539
+ if (successCount > 0) {
1540
+ console.log(`💡 Usage in your component:`);
1541
+ console.log(` import { toolMetadata } from './.arcten/tool-metadata';`);
1542
+ console.log(` useAgent({ tools: [...], toolMetadata: toolMetadata.functions })\n`);
1543
+ }
1513
1544
  }
1514
1545
 
1515
1546
  // CLI
@@ -137,7 +137,7 @@ function main() {
137
137
  console.log(` Consider updating to '^${latestVersion}' in package.json`);
138
138
  console.log(` Then run 'npm install' to get the latest version`);
139
139
  }
140
- console.log(` Or use: npx arcten-update-core`);
140
+ console.log(` Or use: \x1b[36mnpx arcten update\x1b[0m`);
141
141
  }
142
142
 
143
143
  // Restore original directory
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
3
  * Manual update command for @arcteninc/core
4
- * Usage: npx arcten-update-core
4
+ * Usage: arcten update
5
5
  *
6
6
  * This allows users to explicitly update their package.json
7
7
  */
@@ -9,8 +9,9 @@
9
9
  const fs = require('fs');
10
10
  const path = require('path');
11
11
  const { execSync } = require('child_process');
12
+ const { findPackageJson } = require('./postinstall-check-version.cjs');
12
13
 
13
- function findPackageJson(startPath = process.cwd()) {
14
+ function findPackageJsonLocal(startPath = process.cwd()) {
14
15
  let currentPath = startPath;
15
16
 
16
17
  while (currentPath !== path.dirname(currentPath)) {
@@ -64,8 +65,7 @@ function updateVersion(packageJsonPath, packageJson, latestVersion) {
64
65
 
65
66
  if (updated) {
66
67
  fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n');
67
- console.log(`✅ Updated @arcteninc/core to ^${latestVersion} in package.json`);
68
- console.log(` Run 'npm install' to install the latest version`);
68
+ console.log(`✅ Updated to \x1b[32m^${latestVersion}\x1b[0m in package.json\n`);
69
69
  return true;
70
70
  }
71
71
 
@@ -102,18 +102,18 @@ function main() {
102
102
  const current = currentVersionMatch[1];
103
103
 
104
104
  if (current === latestVersion) {
105
- console.log(`✅ Already on latest version: ${latestVersion}`);
105
+ console.log(`\n✅ Already on latest version: \x1b[32m${latestVersion}\x1b[0m\n`);
106
106
  return;
107
107
  }
108
108
 
109
- console.log(`📦 Updating @arcteninc/core:`);
110
- console.log(` Current: ${current}`);
111
- console.log(` Latest: ${latestVersion}`);
109
+ console.log(`\n📦 Updating @arcteninc/core\n`);
110
+ console.log(` Current: \x1b[33m${current}\x1b[0m`);
111
+ console.log(` Latest: \x1b[32m${latestVersion}\x1b[0m\n`);
112
112
 
113
113
  if (updateVersion(packageJsonPath, packageJson, latestVersion)) {
114
- console.log(`\n💡 Next steps:`);
114
+ console.log(`💡 Next steps:`);
115
115
  console.log(` 1. Review the changes in package.json`);
116
- console.log(` 2. Run 'npm install' to install the update`);
116
+ console.log(` 2. Run \x1b[36mnpm install\x1b[0m to install the update\n`);
117
117
  }
118
118
  }
119
119