context-foundry 2.5.4 → 2.5.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/bin/cfd.js DELETED
@@ -1,170 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * Context Foundry Daemon CLI - npm wrapper for Python engine
5
- *
6
- * This shim delegates to the Python CLI via `python3 -m context_foundry.daemon.cli`.
7
- * We invoke the module directly to avoid PATH conflicts (the npm-installed `cfd`
8
- * command would otherwise find itself via `which cfd`, causing infinite recursion).
9
- */
10
-
11
- const { spawn, spawnSync } = require('child_process');
12
-
13
- // ANSI colors
14
- const colors = {
15
- red: '\x1b[31m',
16
- green: '\x1b[32m',
17
- yellow: '\x1b[33m',
18
- cyan: '\x1b[36m',
19
- reset: '\x1b[0m',
20
- bold: '\x1b[1m'
21
- };
22
-
23
- function error(msg) {
24
- console.error(`${colors.red}Error: ${msg}${colors.reset}`);
25
- }
26
-
27
- function log(msg, color = '') {
28
- console.log(`${color}${msg}${colors.reset}`);
29
- }
30
-
31
- /**
32
- * Find Python 3.10+ command
33
- */
34
- function findPython() {
35
- const pythonCommands = ['python3', 'python'];
36
-
37
- for (const cmd of pythonCommands) {
38
- try {
39
- const result = spawnSync(cmd, ['--version'], { encoding: 'utf-8' });
40
- if (result.status === 0) {
41
- const version = result.stdout.trim() || result.stderr.trim();
42
- const match = version.match(/Python (\d+)\.(\d+)/);
43
- if (match) {
44
- const major = parseInt(match[1], 10);
45
- const minor = parseInt(match[2], 10);
46
- if (major === 3 && minor >= 10) {
47
- return { cmd, version: `${major}.${minor}` };
48
- }
49
- }
50
- }
51
- } catch (e) {
52
- // Continue to next command
53
- }
54
- }
55
- return null;
56
- }
57
-
58
- /**
59
- * Check if context-foundry Python package is installed
60
- */
61
- function checkPythonPackage(pythonCmd) {
62
- const result = spawnSync(pythonCmd, ['-c', 'import context_foundry.daemon.cli'], {
63
- encoding: 'utf-8',
64
- stdio: ['pipe', 'pipe', 'pipe']
65
- });
66
- return result.status === 0;
67
- }
68
-
69
- /**
70
- * Install context-foundry via pipx (preferred) or pip with --user
71
- */
72
- function installPackage(pythonCmd) {
73
- // Try pipx first (best for CLI tools on macOS/Linux)
74
- const pipxCheck = spawnSync('which', ['pipx'], { encoding: 'utf-8' });
75
- if (pipxCheck.status === 0) {
76
- log(`${colors.yellow}Installing context-foundry via pipx...${colors.reset}`);
77
- const pipx = spawnSync('pipx', ['install', 'context-foundry'], {
78
- stdio: 'inherit'
79
- });
80
- if (pipx.status === 0) return true;
81
- // If pipx fails (already installed, etc), try reinstall
82
- const pipxReinstall = spawnSync('pipx', ['reinstall', 'context-foundry'], {
83
- stdio: 'inherit'
84
- });
85
- if (pipxReinstall.status === 0) return true;
86
- }
87
-
88
- // Fallback: pip with --user flag (avoids PEP 668 errors)
89
- log(`${colors.yellow}Installing context-foundry via pip --user...${colors.reset}`);
90
- const pip = spawnSync(pythonCmd, ['-m', 'pip', 'install', '--user', 'context-foundry'], {
91
- stdio: 'inherit'
92
- });
93
- if (pip.status === 0) return true;
94
-
95
- // Last resort: suggest pipx installation
96
- log(`\n${colors.yellow}Tip: Install pipx for better Python CLI tool management:${colors.reset}`);
97
- log(` ${colors.cyan}brew install pipx && pipx ensurepath${colors.reset}`);
98
- return false;
99
- }
100
-
101
- /**
102
- * Run the Python CLI module with all arguments
103
- */
104
- function runPythonCli(pythonCmd, args) {
105
- // Call the Python module directly - this avoids PATH issues entirely
106
- const proc = spawn(pythonCmd, ['-m', 'context_foundry.daemon.cli', ...args], {
107
- stdio: 'inherit',
108
- env: process.env
109
- });
110
-
111
- proc.on('error', (err) => {
112
- error(`Failed to start Python: ${err.message}`);
113
- process.exit(1);
114
- });
115
-
116
- proc.on('close', (code) => {
117
- process.exit(code || 0);
118
- });
119
- }
120
-
121
- function showHelp() {
122
- log(`
123
- ${colors.cyan}${colors.bold}Context Foundry Daemon (cfd)${colors.reset}
124
-
125
- ${colors.yellow}Usage:${colors.reset}
126
- cfd start Start the daemon
127
- cfd stop Stop the daemon
128
- cfd status Get daemon status
129
- cfd submit Submit a job
130
- cfd list List jobs
131
- cfd logs <job-id> Show job logs
132
- cfd --help Full help
133
-
134
- ${colors.yellow}More Info:${colors.reset}
135
- https://github.com/context-foundry/context-foundry
136
- `);
137
- }
138
-
139
- // Main entry point
140
- function main() {
141
- const args = process.argv.slice(2);
142
-
143
- // Find Python 3.10+
144
- const python = findPython();
145
- if (!python) {
146
- error('Python 3.10+ is required but not found.');
147
- log('\nPlease install Python 3.10 or later:', colors.yellow);
148
- log(' brew install python@3.12', colors.cyan);
149
- process.exit(1);
150
- }
151
-
152
- // Check if context-foundry is installed
153
- if (!checkPythonPackage(python.cmd)) {
154
- log(`${colors.yellow}context-foundry Python package not found.${colors.reset}`);
155
-
156
- if (!installPackage(python.cmd)) {
157
- error('Failed to install context-foundry via pip.');
158
- log('\nTry manually:', colors.yellow);
159
- log(' pip install context-foundry', colors.cyan);
160
- process.exit(1);
161
- }
162
-
163
- log(`${colors.green}Successfully installed!${colors.reset}\n`);
164
- }
165
-
166
- // Run the Python CLI
167
- runPythonCli(python.cmd, args);
168
- }
169
-
170
- main();