algomath-extract 1.0.0

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.
Files changed (90) hide show
  1. package/README.md +260 -0
  2. package/bin/algo-extract.js +143 -0
  3. package/bin/algo-generate.js +102 -0
  4. package/bin/algo-help.js +136 -0
  5. package/bin/algo-list.js +56 -0
  6. package/bin/algo-run.js +141 -0
  7. package/bin/algo-status.js +88 -0
  8. package/bin/algo-verify.js +189 -0
  9. package/bin/install.js +349 -0
  10. package/package.json +57 -0
  11. package/requirements.txt +20 -0
  12. package/src/__pycache__/intent.cpython-313.pyc +0 -0
  13. package/src/cli/__pycache__/commands.cpython-313.pyc +0 -0
  14. package/src/cli/cli_entry.py +106 -0
  15. package/src/cli/commands.py +339 -0
  16. package/src/execution/__init__.py +74 -0
  17. package/src/execution/__pycache__/__init__.cpython-313.pyc +0 -0
  18. package/src/execution/__pycache__/display.cpython-313.pyc +0 -0
  19. package/src/execution/__pycache__/errors.cpython-313.pyc +0 -0
  20. package/src/execution/__pycache__/executor.cpython-313.pyc +0 -0
  21. package/src/execution/__pycache__/sandbox.cpython-313.pyc +0 -0
  22. package/src/execution/display.py +261 -0
  23. package/src/execution/errors.py +158 -0
  24. package/src/execution/executor.py +253 -0
  25. package/src/execution/sandbox.py +333 -0
  26. package/src/extraction/__init__.py +102 -0
  27. package/src/extraction/__pycache__/__init__.cpython-313.pyc +0 -0
  28. package/src/extraction/__pycache__/boundaries.cpython-313.pyc +0 -0
  29. package/src/extraction/__pycache__/errors.cpython-313.pyc +0 -0
  30. package/src/extraction/__pycache__/llm_extraction.cpython-313.pyc +0 -0
  31. package/src/extraction/__pycache__/notation.cpython-313.pyc +0 -0
  32. package/src/extraction/__pycache__/parser.cpython-313.pyc +0 -0
  33. package/src/extraction/__pycache__/pdf_processor.cpython-313.pyc +0 -0
  34. package/src/extraction/__pycache__/prompts.cpython-313.pyc +0 -0
  35. package/src/extraction/__pycache__/review.cpython-313.pyc +0 -0
  36. package/src/extraction/__pycache__/schema.cpython-313.pyc +0 -0
  37. package/src/extraction/__pycache__/validation.cpython-313.pyc +0 -0
  38. package/src/extraction/boundaries.py +281 -0
  39. package/src/extraction/errors.py +156 -0
  40. package/src/extraction/llm_extraction.py +225 -0
  41. package/src/extraction/notation.py +240 -0
  42. package/src/extraction/parser.py +402 -0
  43. package/src/extraction/pdf_processor.py +281 -0
  44. package/src/extraction/prompts.py +90 -0
  45. package/src/extraction/review.py +298 -0
  46. package/src/extraction/schema.py +173 -0
  47. package/src/extraction/validation.py +202 -0
  48. package/src/generation/__init__.py +79 -0
  49. package/src/generation/__pycache__/__init__.cpython-313.pyc +0 -0
  50. package/src/generation/__pycache__/code_generator.cpython-313.pyc +0 -0
  51. package/src/generation/__pycache__/errors.cpython-313.pyc +0 -0
  52. package/src/generation/__pycache__/hybrid.cpython-313.pyc +0 -0
  53. package/src/generation/__pycache__/llm_generator.cpython-313.pyc +0 -0
  54. package/src/generation/__pycache__/persistence.cpython-313.pyc +0 -0
  55. package/src/generation/__pycache__/prompts.cpython-313.pyc +0 -0
  56. package/src/generation/__pycache__/review.cpython-313.pyc +0 -0
  57. package/src/generation/__pycache__/templates.cpython-313.pyc +0 -0
  58. package/src/generation/__pycache__/types.cpython-313.pyc +0 -0
  59. package/src/generation/__pycache__/validation.cpython-313.pyc +0 -0
  60. package/src/generation/code_generator.py +375 -0
  61. package/src/generation/errors.py +84 -0
  62. package/src/generation/hybrid.py +210 -0
  63. package/src/generation/llm_generator.py +223 -0
  64. package/src/generation/persistence.py +221 -0
  65. package/src/generation/prompts.py +202 -0
  66. package/src/generation/review.py +254 -0
  67. package/src/generation/templates.py +208 -0
  68. package/src/generation/types.py +196 -0
  69. package/src/generation/validation.py +278 -0
  70. package/src/intent.py +323 -0
  71. package/src/verification/__init__.py +63 -0
  72. package/src/verification/__pycache__/__init__.cpython-313.pyc +0 -0
  73. package/src/verification/__pycache__/checker.cpython-313.pyc +0 -0
  74. package/src/verification/__pycache__/comparison.cpython-313.pyc +0 -0
  75. package/src/verification/__pycache__/explainer.cpython-313.pyc +0 -0
  76. package/src/verification/__pycache__/static_analysis.cpython-313.pyc +0 -0
  77. package/src/verification/checker.py +220 -0
  78. package/src/verification/comparison.py +492 -0
  79. package/src/verification/explainer.py +414 -0
  80. package/src/verification/static_analysis.py +540 -0
  81. package/src/workflows/__init__.py +21 -0
  82. package/src/workflows/__pycache__/__init__.cpython-313.pyc +0 -0
  83. package/src/workflows/__pycache__/extract.cpython-313.pyc +0 -0
  84. package/src/workflows/__pycache__/generate.cpython-313.pyc +0 -0
  85. package/src/workflows/__pycache__/run.cpython-313.pyc +0 -0
  86. package/src/workflows/__pycache__/verify.cpython-313.pyc +0 -0
  87. package/src/workflows/extract.py +181 -0
  88. package/src/workflows/generate.py +155 -0
  89. package/src/workflows/run.py +187 -0
  90. package/src/workflows/verify.py +334 -0
@@ -0,0 +1,141 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * AlgoMath Run Command
5
+ *
6
+ * Execute generated Python code
7
+ * Usage: /algo-run [--skip]
8
+ */
9
+
10
+ const { Command } = require('commander');
11
+ const chalk = require('chalk');
12
+ const ora = require('ora');
13
+ const { spawn } = require('child_process');
14
+ const path = require('path');
15
+
16
+ const program = new Command();
17
+
18
+ program
19
+ .name('algo-run')
20
+ .description('Execute generated Python code')
21
+ .option('--skip', 'Skip execution and proceed directly to verification')
22
+ .action(async (options) => {
23
+ console.log(chalk.blue.bold('╔════════════════════════════════════════╗'));
24
+ console.log(chalk.blue.bold('║ AlgoMath - Execute Code ║'));
25
+ console.log(chalk.blue.bold('╚════════════════════════════════════════╝'));
26
+ console.log();
27
+
28
+ try {
29
+ if (options.skip) {
30
+ console.log(chalk.yellow('⚠ Skipping execution (proceeding to verification)'));
31
+ console.log();
32
+ }
33
+
34
+ const spinner = ora(options.skip ? 'Skipping...' : 'Executing code...').start();
35
+
36
+ const pythonScript = path.join(__dirname, '..', 'src', 'cli', 'cli_entry.py');
37
+ const args = ['run'];
38
+ if (options.skip) {
39
+ args.push('--skip');
40
+ }
41
+
42
+ const result = await runPython(pythonScript, args);
43
+
44
+ if (options.skip) {
45
+ spinner.succeed('Execution skipped');
46
+ } else {
47
+ spinner.succeed('Execution complete!');
48
+ }
49
+
50
+ const output = JSON.parse(result);
51
+ displayResult(output);
52
+
53
+ } catch (error) {
54
+ console.error(chalk.red('Error:'), error.message);
55
+ process.exit(1);
56
+ }
57
+ });
58
+
59
+ function runPython(script, args) {
60
+ return new Promise((resolve, reject) => {
61
+ const python = spawn('python3', [script, ...args], {
62
+ cwd: path.join(__dirname, '..')
63
+ });
64
+
65
+ let output = '';
66
+ let error = '';
67
+
68
+ python.stdout.on('data', (data) => {
69
+ output += data.toString();
70
+ });
71
+
72
+ python.stderr.on('data', (data) => {
73
+ error += data.toString();
74
+ });
75
+
76
+ python.on('close', (code) => {
77
+ if (code !== 0) {
78
+ reject(new Error(error || `Python process exited with code ${code}`));
79
+ } else {
80
+ resolve(output);
81
+ }
82
+ });
83
+ });
84
+ }
85
+
86
+ function displayResult(output) {
87
+ console.log();
88
+
89
+ if (output.status === 'success') {
90
+ console.log(chalk.green.bold('✓ Code executed successfully'));
91
+ console.log();
92
+
93
+ if (output.stdout) {
94
+ console.log(chalk.cyan('Output:'));
95
+ console.log(chalk.white(output.stdout));
96
+ console.log();
97
+ }
98
+
99
+ console.log(chalk.cyan('Runtime:'), output.runtime_seconds || 'N/A', 'seconds');
100
+ console.log();
101
+
102
+ if (output.next_steps) {
103
+ console.log(chalk.gray('Next steps:'));
104
+ output.next_steps.forEach(step => {
105
+ console.log(chalk.gray(` • ${step}`));
106
+ });
107
+ }
108
+ } else if (output.status === 'skipped') {
109
+ console.log(chalk.yellow('⚠ Execution skipped'));
110
+ console.log(chalk.gray(output.message));
111
+ console.log();
112
+
113
+ if (output.next_steps) {
114
+ console.log(chalk.gray('Next steps:'));
115
+ output.next_steps.forEach(step => {
116
+ console.log(chalk.gray(` • ${step}`));
117
+ });
118
+ }
119
+ } else {
120
+ console.log(chalk.red('✗ Execution failed'));
121
+ console.log(chalk.red('Error:'), output.message);
122
+ if (output.stderr) {
123
+ console.log();
124
+ console.log(chalk.gray('Error details:'));
125
+ console.log(chalk.gray(output.stderr));
126
+ }
127
+ console.log();
128
+
129
+ if (output.next_steps) {
130
+ console.log(chalk.gray('Next steps:'));
131
+ output.next_steps.forEach(step => {
132
+ console.log(chalk.gray(` • ${step}`));
133
+ });
134
+ }
135
+ }
136
+
137
+ console.log();
138
+ console.log(chalk.blue('Use /algo-verify to check results and verify correctness'));
139
+ }
140
+
141
+ program.parse();
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * algo-status command
5
+ *
6
+ * Usage: npx algomath status
7
+ */
8
+
9
+ const { execSync } = require('child_process');
10
+ const path = require('path');
11
+
12
+ async function main() {
13
+ console.log('\n╔════════════════════════════════════════════════════╗');
14
+ console.log('║ AlgoMath Status ║');
15
+ console.log('╚════════════════════════════════════════════════════╝\n');
16
+
17
+ try {
18
+ // Check Python
19
+ const pythonInfo = checkPython();
20
+ console.log(`Python: ${pythonInfo ? pythonInfo.version : '❌ Not found'}\n`);
21
+
22
+ // Check dependencies
23
+ const depsOk = checkPythonDeps();
24
+ console.log(`Dependencies: ${depsOk ? '✓ Installed' : '⚠️ Missing'}\n`);
25
+
26
+ // Check workspace
27
+ const workspace = process.cwd();
28
+ console.log(`Workspace: ${workspace}\n`);
29
+
30
+ // Check saved algorithms
31
+ console.log('Saved Algorithms:');
32
+ listAlgorithms();
33
+
34
+ } catch (error) {
35
+ console.error('Error:', error.message);
36
+ process.exit(1);
37
+ }
38
+ }
39
+
40
+ function checkPython() {
41
+ try {
42
+ const version = execSync('python3 --version', { encoding: 'utf8', stdio: 'pipe' });
43
+ return { version: version.trim() };
44
+ } catch (e) {
45
+ try {
46
+ const version = execSync('python --version', { encoding: 'utf8', stdio: 'pipe' });
47
+ return { version: version.trim() };
48
+ } catch (e2) {
49
+ return null;
50
+ }
51
+ }
52
+ }
53
+
54
+ function checkPythonDeps() {
55
+ const pythonCmd = checkPython() ? 'python3' : null;
56
+ if (!pythonCmd) return false;
57
+
58
+ try {
59
+ execSync(`${pythonCmd} -c "import pdfplumber; import fitz; import pydantic"`, { stdio: 'pipe' });
60
+ return true;
61
+ } catch (e) {
62
+ return false;
63
+ }
64
+ }
65
+
66
+ function listAlgorithms() {
67
+ const fs = require('fs');
68
+ const homeDir = require('os').homedir();
69
+ const algorithmsDir = path.join(homeDir, '.algomath', 'algorithms');
70
+
71
+ if (!fs.existsSync(algorithmsDir)) {
72
+ console.log(' No algorithms found\n');
73
+ return;
74
+ }
75
+
76
+ const algorithms = fs.readdirSync(algorithmsDir)
77
+ .filter(f => f.endsWith('.json'))
78
+ .map(f => f.replace('.json', ''));
79
+
80
+ if (algorithms.length === 0) {
81
+ console.log(' No algorithms found\n');
82
+ } else {
83
+ algorithms.forEach(name => console.log(` - ${name}`));
84
+ console.log();
85
+ }
86
+ }
87
+
88
+ main();
@@ -0,0 +1,189 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * AlgoMath Verify Command
5
+ *
6
+ * Verify execution results and explain algorithm behavior
7
+ * Usage: /algo-verify [--step N] [--detailed] [--diagnostic]
8
+ */
9
+
10
+ const { Command } = require('commander');
11
+ const inquirer = require('inquirer');
12
+ const chalk = require('chalk');
13
+ const ora = require('ora');
14
+ const { spawn } = require('child_process');
15
+ const path = require('path');
16
+
17
+ const program = new Command();
18
+
19
+ program
20
+ .name('algo-verify')
21
+ .description('Verify execution results and explain algorithm behavior')
22
+ .option('-s, --step <number>', 'Explain specific step number', parseInt)
23
+ .option('-d, --detailed', 'Show detailed step-by-step explanation')
24
+ .option('--diagnostic', 'Run diagnostic mode for failed executions')
25
+ .action(async (options) => {
26
+ console.log(chalk.blue.bold('╔════════════════════════════════════════╗'));
27
+ console.log(chalk.blue.bold('║ AlgoMath - Verify Results ║'));
28
+ console.log(chalk.blue.bold('╚════════════════════════════════════════╝'));
29
+ console.log();
30
+
31
+ try {
32
+ // If step is specified, explain that step
33
+ if (options.step !== undefined) {
34
+ console.log(chalk.cyan(`Explaining step ${options.step}...`));
35
+ console.log();
36
+ } else if (options.diagnostic) {
37
+ console.log(chalk.yellow('Running diagnostic mode...'));
38
+ console.log();
39
+ }
40
+
41
+ const spinner = ora('Verifying...').start();
42
+
43
+ const pythonScript = path.join(__dirname, '..', 'src', 'cli', 'cli_entry.py');
44
+ const args = ['verify'];
45
+
46
+ if (options.step !== undefined) {
47
+ args.push('--step', options.step.toString());
48
+ }
49
+ if (options.detailed) {
50
+ args.push('--detailed');
51
+ }
52
+ if (options.diagnostic) {
53
+ args.push('--diagnostic');
54
+ }
55
+
56
+ const result = await runPython(pythonScript, args);
57
+
58
+ spinner.succeed('Verification complete!');
59
+
60
+ const output = JSON.parse(result);
61
+ displayResult(output, options);
62
+
63
+ } catch (error) {
64
+ console.error(chalk.red('Error:'), error.message);
65
+ process.exit(1);
66
+ }
67
+ });
68
+
69
+ function runPython(script, args) {
70
+ return new Promise((resolve, reject) => {
71
+ const python = spawn('python3', [script, ...args], {
72
+ cwd: path.join(__dirname, '..')
73
+ });
74
+
75
+ let output = '';
76
+ let error = '';
77
+
78
+ python.stdout.on('data', (data) => {
79
+ output += data.toString();
80
+ });
81
+
82
+ python.stderr.on('data', (data) => {
83
+ error += data.toString();
84
+ });
85
+
86
+ python.on('close', (code) => {
87
+ if (code !== 0) {
88
+ reject(new Error(error || `Python process exited with code ${code}`));
89
+ } else {
90
+ resolve(output);
91
+ }
92
+ });
93
+ });
94
+ }
95
+
96
+ function displayResult(output, options) {
97
+ console.log();
98
+
99
+ if (output.status === 'verified' || output.status === 'already_verified') {
100
+ console.log(chalk.green.bold('✓ Verification complete'));
101
+ console.log();
102
+
103
+ if (output.message) {
104
+ console.log(chalk.white(output.message));
105
+ console.log();
106
+ }
107
+
108
+ // Show verification report if available
109
+ if (output.verification_report) {
110
+ const report = output.verification_report;
111
+
112
+ if (report.summary) {
113
+ console.log(chalk.cyan('Summary:'));
114
+ console.log(chalk.white(report.summary));
115
+ console.log();
116
+ }
117
+
118
+ if (report.execution) {
119
+ console.log(chalk.cyan('Execution:'));
120
+ console.log(chalk.white(` Status: ${report.execution.status}`));
121
+ console.log(chalk.white(` Runtime: ${report.execution.runtime}s`));
122
+ console.log();
123
+ }
124
+
125
+ if (report.explanation && options.detailed) {
126
+ console.log(chalk.cyan('Explanation:'));
127
+ console.log(chalk.white(report.explanation.text || report.explanation));
128
+ console.log();
129
+ }
130
+
131
+ if (report.edge_cases && report.edge_cases.length > 0) {
132
+ console.log(chalk.cyan('Edge Cases:'));
133
+ report.edge_cases.forEach(ec => {
134
+ const icon = ec.severity === 'error' ? '✗' : '⚠';
135
+ console.log(chalk.white(` ${icon} ${ec.description}`));
136
+ });
137
+ console.log();
138
+ }
139
+ }
140
+
141
+ if (output.next_steps) {
142
+ console.log(chalk.gray('Next steps:'));
143
+ output.next_steps.forEach(step => {
144
+ if (step) console.log(chalk.gray(` • ${step}`));
145
+ });
146
+ }
147
+ } else if (output.status === 'diagnostic_complete') {
148
+ console.log(chalk.yellow.bold('⚠ Diagnostic Report'));
149
+ console.log();
150
+
151
+ if (output.diagnostic_report) {
152
+ const diag = output.diagnostic_report;
153
+
154
+ if (diag.failure_point) {
155
+ console.log(chalk.cyan('Failure point:'), diag.failure_point);
156
+ }
157
+
158
+ if (diag.possible_fixes && diag.possible_fixes.length > 0) {
159
+ console.log(chalk.cyan('Possible fixes:'));
160
+ diag.possible_fixes.forEach(fix => {
161
+ console.log(chalk.white(` • ${fix}`));
162
+ });
163
+ }
164
+ }
165
+
166
+ console.log();
167
+ if (output.next_steps) {
168
+ console.log(chalk.gray('Next steps:'));
169
+ output.next_steps.forEach(step => {
170
+ console.log(chalk.gray(` • ${step}`));
171
+ });
172
+ }
173
+ } else {
174
+ console.log(chalk.yellow('⚠'), output.message);
175
+ console.log();
176
+
177
+ if (output.next_steps) {
178
+ console.log(chalk.gray('Next steps:'));
179
+ output.next_steps.forEach(step => {
180
+ console.log(chalk.gray(` • ${step}`));
181
+ });
182
+ }
183
+ }
184
+
185
+ console.log();
186
+ console.log(chalk.blue('Use /algo-extract to start with a new algorithm'));
187
+ }
188
+
189
+ program.parse();