algomath-extract 1.0.12 → 1.0.14

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/install.js CHANGED
@@ -73,7 +73,7 @@ console.log(GREEN + `
73
73
  ██╔══██║██║ ██║ ██║██║ ██║██║╚██╔╝██║██╔══██║ ██║ ██╔══██║
74
74
  ██║ ██║███████╗╚██████╔╝╚██████╔╝██║ ╚═╝ ██║██║ ██║ ██║ ██║ ██║
75
75
  ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝
76
- Framework Installer v1.0.11
76
+ Framework Installer v1.0.14
77
77
  Mathematical Algorithm Extraction & Code
78
78
  ` + RESET + '\n');
79
79
 
@@ -368,6 +368,20 @@ execSync(`sudo chown -R $(whoami) "${parentDir}"`, { stdio: 'inherit' });
368
368
  needsElevated = !isWritable(commandDir);
369
369
  }
370
370
 
371
+ // Clean old algo-*.md files first (to remove outdated commands)
372
+ const existingFiles = fs.readdirSync(commandDir).filter(f => f.startsWith('algo-') && f.endsWith('.md'));
373
+ for (const oldFile of existingFiles) {
374
+ const oldPath = path.join(commandDir, oldFile);
375
+ try {
376
+ fs.unlinkSync(oldPath);
377
+ } catch (e) {
378
+ // If can't delete, try with sudo
379
+ if (!isWindows) {
380
+ execSync(`sudo rm -f "${oldPath}"`, { stdio: 'pipe' });
381
+ }
382
+ }
383
+ }
384
+
371
385
  // Copy command files
372
386
  const sourceDir = path.join(__dirname, '..', 'commands');
373
387
  const files = fs.readdirSync(sourceDir).filter(f => f.endsWith('.md'));
@@ -4,6 +4,7 @@ argument-hint: "[file-path] [--auto] [--step] [--name <name>]"
4
4
  tools:
5
5
  read: true
6
6
  write: true
7
+ Bash: true
7
8
  ---
8
9
 
9
10
  <objective>
@@ -11,57 +12,78 @@ Extract algorithm from PDF or text file using LLM-powered parsing.
11
12
  Supports automatic extraction or step-by-step with review points.
12
13
  </objective>
13
14
 
14
- <execution_context>
15
- @/home/milgraph/Projects/algo_framework/src/extraction/pdf_processor.py
16
- @/home/milgraph/Projects/algo_framework/src/extraction/llm_extractor.py
17
- </execution_context>
15
+ <execution>
16
+ Execute the extraction by running:
17
+
18
+ **Option 1 - Using npx (no install required):**
19
+ ```bash
20
+ npx -p algomath-extract algoextract "$@"
21
+ ```
22
+
23
+ **Option 2 - If installed globally:**
24
+ ```bash
25
+ algoextract "$@"
26
+ ```
27
+
28
+ **Option 3 - If installed locally in project:**
29
+ ```bash
30
+ ./node_modules/.bin/algoextract "$@"
31
+ ```
32
+
33
+ This will:
34
+ 1. Parse the provided file or arguments
35
+ 2. Extract algorithm steps using LLM
36
+ 3. Save the structured algorithm to .algomath/algorithms/
37
+ 4. Display the extraction summary
38
+ </execution>
18
39
 
19
40
  <process>
20
41
  Execute extraction workflow:
21
42
 
43
+
22
44
  1. **Parse Arguments**
23
- - Check if file path provided
24
- - Determine mode: auto, step-by-step, or interactive
45
+ - Check if file path provided
46
+ - Determine mode: auto, step-by-step, or interactive
25
47
 
26
48
  2. **Extract Text from File**
27
- - Auto-detect file type (PDF, .txt, .md)
28
- - Use pdfplumber for PDFs
29
- - Handle encoding issues
30
- - Validate extraction success
49
+ - Auto-detect file type (PDF, .txt, .md)
50
+ - Use pdfplumber for PDFs
51
+ - Handle encoding issues
52
+ - Validate extraction success
31
53
 
32
54
  3. **Parse Algorithm Structure**
33
- - Use opencode LLM to parse text
34
- - Identify algorithm name
35
- - Extract inputs and outputs
36
- - Parse step-by-step procedure
37
- - Handle mathematical notation
55
+ - Use opencode LLM to parse text
56
+ - Identify algorithm name
57
+ - Extract inputs and outputs
58
+ - Parse step-by-step procedure
59
+ - Handle mathematical notation
38
60
 
39
61
  4. **Review Point (if step-by-step)**
40
- - Display extracted text
41
- - Ask user to confirm or edit
42
- - Apply user corrections
62
+ - Display extracted text
63
+ - Ask user to confirm or edit
64
+ - Apply user corrections
43
65
 
44
66
  5. **Generate Structured Steps**
45
- - Convert parsed text to Algorithm object
46
- - Validate step structure
47
- - Check for completeness
67
+ - Convert parsed text to Algorithm object
68
+ - Validate step structure
69
+ - Check for completeness
48
70
 
49
71
  6. **Review Point (if step-by-step)**
50
- - Display structured steps
51
- - Show inputs, outputs, step list
52
- - Allow editing
72
+ - Display structured steps
73
+ - Show inputs, outputs, step list
74
+ - Allow editing
53
75
 
54
76
  7. **Save Algorithm**
55
- - Create directory: .algomath/algorithms/{name}/
56
- - Save source.txt (original text)
57
- - Save steps.json (structured)
58
- - Save metadata.json (info)
77
+ - Create directory: .algomath/algorithms/{name}/
78
+ - Save source.txt (original text)
79
+ - Save steps.json (structured)
80
+ - Save metadata.json (info)
59
81
 
60
82
  8. **Display Summary**
61
- - Show algorithm name
62
- - Show step count
63
- - Display next steps
64
- - Suggest: /algo-generate
83
+ - Show algorithm name
84
+ - Show step count
85
+ - Display next steps
86
+ - Suggest: /algo-generate
65
87
  </process>
66
88
 
67
89
  <examples>
@@ -4,6 +4,7 @@ argument-hint: "[--review] [--template-only] [--llm-only]"
4
4
  tools:
5
5
  read: true
6
6
  write: true
7
+ Bash: true
7
8
  ---
8
9
 
9
10
  <objective>
@@ -11,87 +12,111 @@ Generate executable Python code from structured algorithm steps.
11
12
  Supports template-based generation (fast, reliable) or LLM-enhanced (for complex expressions).
12
13
  </objective>
13
14
 
14
- <execution_context>
15
- @/home/milgraph/Projects/algo_framework/src/generation/code_generator.py
16
- @/home/milgraph/Projects/algo_framework/src/generation/llm_generator.py
17
- </execution_context>
15
+ <execution>
16
+ Execute the code generation by running:
17
+
18
+ **Option 1 - Using npx (no install required):**
19
+ ```bash
20
+ npx -p algomath-extract algogenerate "$@"
21
+ ```
22
+
23
+ **Option 2 - If installed globally:**
24
+ ```bash
25
+ algogenerate "$@"
26
+ ```
27
+
28
+ **Option 3 - If installed locally in project:**
29
+ ```bash
30
+ ./node_modules/.bin/algogenerate "$@"
31
+ ```
32
+
33
+ This will:
34
+ 1. Load the extracted algorithm from .algomath/algorithms/
35
+ 2. Generate Python code using template or LLM
36
+ 3. Save generated code to .algomath/generated/
37
+ 4. Display generation summary
38
+ </execution>
18
39
 
19
40
  <process>
20
41
  Execute code generation workflow:
21
42
 
43
+
22
44
  1. **Load Algorithm**
23
- - Read steps.json from current algorithm
24
- - Validate step structure
25
- - Check for completeness
45
+ - Read steps.json from current algorithm
46
+ - Validate step structure
47
+ - Check for completeness
26
48
 
27
49
  2. **Select Generation Mode**
28
- - Default: Hybrid (template + LLM for complex parts)
29
- - --template-only: Rule-based only (faster)
30
- - --llm-only: Full LLM generation (slower, more accurate)
50
+ - Default: Hybrid (template + LLM for complex parts)
51
+ - --template-only: Rule-based only (faster)
52
+ - --llm-only: Full LLM generation (slower, more accurate)
31
53
 
32
54
  3. **Generate Function Signature**
33
- - Extract inputs and outputs
34
- - Add type hints
35
- - Generate docstring
36
-
37
- 4. **Generate Step Code**
38
- - Convert each step to Python
39
- - Handle loops, conditionals, assignments
40
- - Preserve variable names
41
- - Add comments explaining logic
42
-
43
- 5. **Review Point (if --review)**
44
- - Display generated code
45
- - Syntax highlighting
46
- - Ask for approval
47
- - Allow editing
48
-
49
- 6. **Validate Code**
50
- - Syntax check with Python parser
51
- - Check for common errors
52
- - Ensure all variables defined
53
-
54
- 7. **Save Code**
55
- - Write to .algomath/algorithms/{name}/generated.py
56
- - Update metadata.json
55
+ - Extract inputs and outputs
56
+ - Add type hints
57
+ - Create docstring
58
+
59
+ 4. **Generate Step Implementation**
60
+ - Convert each step to Python code
61
+ - Handle mathematical operations
62
+ - Manage variable scope
63
+ - Add error handling
64
+
65
+ 5. **Add Helper Functions**
66
+ - Generate necessary imports
67
+ - Create utility functions
68
+ - Add validation
69
+
70
+ 6. **Review Point (if --review)**
71
+ - Display generated code
72
+ - Ask for approval
73
+ - Allow regeneration with feedback
74
+
75
+ 7. **Save Generated Code**
76
+ - Save to .algomath/generated/{name}.py
77
+ - Create __init__.py for imports
78
+ - Add requirements.txt if needed
57
79
 
58
80
  8. **Display Summary**
59
- - Show generated file path
60
- - Line count
61
- - Next steps: /algo-run
81
+ - Show file path
82
+ - Display code preview
83
+ - Suggest: /algo-run
62
84
  </process>
63
85
 
64
86
  <examples>
65
87
 
66
- **Generate with default hybrid mode:**
88
+ **Generate with review:**
67
89
  /algo-generate
68
90
 
69
- **Generate with review:**
70
- /algo-generate --review
91
+ **Auto-generate:**
92
+ /algo-generate --auto
71
93
 
72
- **Template-based only (faster):**
94
+ **Template-only (faster):**
73
95
  /algo-generate --template-only
74
96
 
75
- **LLM-enhanced only (better for complex):**
97
+ **LLM-enhanced (better for complex math):**
76
98
  /algo-generate --llm-only
77
99
 
78
100
  </examples>
79
101
 
80
102
  <options>
81
103
 
82
- --review
83
- Show generated code for review before saving
104
+ --auto
105
+ Skip review, generate automatically
84
106
 
85
107
  --template-only
86
- Use rule-based generation only (no LLM)
108
+ Use only template-based generation (faster, no LLM)
87
109
 
88
110
  --llm-only
89
- Use LLM for all generation (slower but more accurate)
111
+ Use only LLM generation (slower, handles complex expressions)
112
+
113
+ --review
114
+ Force review mode even in auto mode
90
115
 
91
116
  </options>
92
117
 
93
118
  <next_steps>
94
119
  /algo-run - Execute the generated code
95
- /algo-verify - Verify execution results
96
- /algo-status - Check algorithm state
120
+ /algo-verify - Verify the generated code
121
+ /algo-status - Check current state
97
122
  </next_steps>
@@ -10,9 +10,22 @@ tools:
10
10
  Display help information, available commands, and usage examples.
11
11
  </objective>
12
12
 
13
- <execution_context>
14
- @/home/milgraph/Projects/algo_framework/README.md
15
- </execution_context>
13
+ <execution>
14
+ Show help by running:
15
+ ```bash
16
+ npx algomath-extract algohelp "$@"
17
+ ```
18
+
19
+ Or if algomath-extract is installed globally:
20
+ ```bash
21
+ algohelp "$@"
22
+ ```
23
+
24
+ This will display:
25
+ 1. Available commands and their descriptions
26
+ 2. Usage examples
27
+ 3. Workflow information
28
+ </execution>
16
29
 
17
30
  <process>
18
31
  Display help:
@@ -10,9 +10,22 @@ tools:
10
10
  Display list of all saved algorithms with their status and basic info.
11
11
  </objective>
12
12
 
13
- <execution_context>
14
- @/home/milgraph/Projects/algo_framework/src/cli/commands.py
15
- </execution_context>
13
+ <execution>
14
+ List algorithms by running:
15
+ ```bash
16
+ npx algomath-extract algolist "$@"
17
+ ```
18
+
19
+ Or if algomath-extract is installed globally:
20
+ ```bash
21
+ algolist "$@"
22
+ ```
23
+
24
+ This will:
25
+ 1. Scan .algomath/algorithms/ directory
26
+ 2. List all saved algorithms
27
+ 3. Display status and basic info for each
28
+ </execution>
16
29
 
17
30
  <process>
18
31
  List algorithms:
@@ -4,6 +4,7 @@ argument-hint: "[--skip] [--timeout <seconds>]"
4
4
  tools:
5
5
  read: true
6
6
  write: true
7
+ Bash: true
7
8
  ---
8
9
 
9
10
  <objective>
@@ -11,71 +12,89 @@ Execute generated Python code in a safe sandboxed environment.
11
12
  Captures stdout, stderr, and execution results.
12
13
  </objective>
13
14
 
14
- <execution_context>
15
- @/home/milgraph/Projects/algo_framework/src/execution/sandbox.py
16
- </execution_context>
15
+ <execution>
16
+ Execute the generated code by running:
17
+
18
+ **Option 1 - Using npx (no install required):**
19
+ ```bash
20
+ npx -p algomath-extract algorun "$@"
21
+ ```
22
+
23
+ **Option 2 - If installed globally:**
24
+ ```bash
25
+ algorun "$@"
26
+ ```
27
+
28
+ **Option 3 - If installed locally in project:**
29
+ ```bash
30
+ ./node_modules/.bin/algorun "$@"
31
+ ```
32
+
33
+ This will:
34
+ 1. Load the generated Python code
35
+ 2. Execute in a sandboxed environment
36
+ 3. Capture output and results
37
+ 4. Display execution summary
38
+ </execution>
17
39
 
18
40
  <process>
19
41
  Execute code in sandbox:
20
42
 
43
+
21
44
  1. **Load Generated Code**
22
- - Read generated.py from current algorithm
23
- - Validate code exists
24
- - Check syntax
45
+ - Read generated.py from current algorithm
46
+ - Validate code exists
47
+ - Check for syntax errors
25
48
 
26
- 2. **Create Sandbox**
27
- - Create isolated temp directory
28
- - Copy code to sandbox
29
- - Set resource limits
49
+ 2. **Prepare Execution**
50
+ - Create isolated sandbox
51
+ - Set resource limits
52
+ - Prepare input data
53
+ - Set timeout (default: 30s)
30
54
 
31
55
  3. **Execute Code**
32
- - Run in subprocess with timeout (default 30s)
33
- - Capture stdout and stderr
34
- - Monitor resource usage
35
- - Handle exceptions
36
-
37
- 4. **Process Results**
38
- - Capture output
39
- - Record execution time
40
- - Check for errors
41
- - Format results
42
-
43
- 5. **Save Results**
44
- - Write to execution.log
45
- - Update metadata.json
46
- - Update state to EXECUTION_COMPLETE
47
-
48
- 6. **Display Results**
49
- - Show output
50
- - Show execution time
51
- - Show status (success/error)
52
- - Suggest next steps
56
+ - Run in subprocess
57
+ - Capture stdout/stderr
58
+ - Monitor execution
59
+ - Handle timeouts
60
+
61
+ 4. **Capture Results**
62
+ - Save output to execution.log
63
+ - Capture return code
64
+ - Record execution time
65
+ - Store any generated files
66
+
67
+ 5. **Display Results**
68
+ - Show stdout
69
+ - Show stderr (if any)
70
+ - Display execution time
71
+ - Show success/failure status
53
72
  </process>
54
73
 
55
74
  <examples>
56
75
 
57
- **Execute code:**
76
+ **Execute current algorithm:**
58
77
  /algo-run
59
78
 
60
- **Skip execution:**
61
- /algo-run --skip
62
-
63
- **Custom timeout:**
79
+ **Execute with custom timeout:**
64
80
  /algo-run --timeout 60
65
81
 
82
+ **Skip execution (for testing):**
83
+ /algo-run --skip
84
+
66
85
  </examples>
67
86
 
68
87
  <options>
69
88
 
70
89
  --skip
71
- Skip execution and proceed directly to verification
90
+ Skip execution, just validate
72
91
 
73
92
  --timeout <seconds>
74
- Maximum execution time (default: 30)
93
+ Set execution timeout (default: 30)
75
94
 
76
95
  </options>
77
96
 
78
97
  <next_steps>
79
98
  /algo-verify - Verify execution results
80
- /algo-status - Check algorithm state
99
+ /algo-status - Check current state
81
100
  </next_steps>
@@ -11,9 +11,22 @@ Display current algorithm state, progress, and available next steps.
11
11
  Shows workflow state, completion status, and suggestions.
12
12
  </objective>
13
13
 
14
- <execution_context>
15
- @/home/milgraph/Projects/algo_framework/src/cli/commands.py
16
- </execution_context>
14
+ <execution>
15
+ Check status by running:
16
+ ```bash
17
+ npx algomath-extract algostatus "$@"
18
+ ```
19
+
20
+ Or if algomath-extract is installed globally:
21
+ ```bash
22
+ algostatus "$@"
23
+ ```
24
+
25
+ This will:
26
+ 1. Load current algorithm state
27
+ 2. Display progress and completion status
28
+ 3. Show available next steps
29
+ </execution>
17
30
 
18
31
  <process>
19
32
  Display status:
@@ -4,6 +4,7 @@ argument-hint: "[--step <N>] [--detailed] [--diagnostic] [--expected <value>]"
4
4
  tools:
5
5
  read: true
6
6
  write: true
7
+ Bash: true
7
8
  ---
8
9
 
9
10
  <objective>
@@ -11,94 +12,107 @@ Verify execution results, compare to expected values, explain algorithm behavior
11
12
  and identify potential edge cases.
12
13
  </objective>
13
14
 
14
- <execution_context>
15
- @/home/milgraph/Projects/algo_framework/src/verification/checker.py
16
- @/home/milgraph/Projects/algo_framework/src/verification/explainer.py
17
- @/home/milgraph/Projects/algo_framework/src/verification/edge_cases.py
18
- </execution_context>
15
+ <execution>
16
+ Execute verification by running:
17
+
18
+ **Option 1 - Using npx (no install required):**
19
+ ```bash
20
+ npx -p algomath-extract algoverify "$@"
21
+ ```
22
+
23
+ **Option 2 - If installed globally:**
24
+ ```bash
25
+ algoverify "$@"
26
+ ```
27
+
28
+ **Option 3 - If installed locally in project:**
29
+ ```bash
30
+ ./node_modules/.bin/algoverify "$@"
31
+ ```
32
+
33
+ This will:
34
+ 1. Load execution results and algorithm steps
35
+ 2. Verify correctness against expected values
36
+ 3. Generate explanation of algorithm behavior
37
+ 4. Identify edge cases and potential issues
38
+ </execution>
19
39
 
20
40
  <process>
21
41
  Execute verification workflow:
22
42
 
43
+
23
44
  1. **Load Execution Results**
24
- - Read execution.log
25
- - Load algorithm steps
26
- - Get generated code
27
-
28
- 2. **Verify Execution**
29
- - Check if execution succeeded
30
- - Verify no errors
31
- - Validate output present
32
-
33
- 3. **Compare Results (if --expected)**
34
- - Compare actual vs expected output
35
- - Support numeric tolerance for floats
36
- - Show differences
37
-
38
- 4. **Generate Explanation**
39
- - Brief mode: 1-2 sentence summary
40
- - Detailed mode: Step-by-step walkthrough
41
- - Step mode: Explain specific step N
42
-
43
- 5. **Detect Edge Cases**
44
- - Empty inputs
45
- - Boundary values
46
- - Division by zero
47
- - Array bounds
48
- - Infinite loops
49
-
50
- 6. **Diagnostic Mode (if failed)**
51
- - Analyze error
52
- - Suggest fixes
53
- - Explain failure point
54
-
55
- 7. **Save Report**
56
- - Write to verification.log
57
- - Update state to VERIFIED
58
-
59
- 8. **Display Summary**
60
- - Execution status
61
- - Explanation
62
- - Edge cases found
63
- - Next steps
45
+ - Read execution.log
46
+ - Load algorithm steps
47
+ - Check execution status
48
+
49
+ 2. **Check Results**
50
+ - Compare output to expected
51
+ - Validate return codes
52
+ - Check for errors
53
+ - Verify output format
54
+
55
+ 3. **Generate Explanation**
56
+ - Explain what the algorithm does
57
+ - Describe each step
58
+ - Show data flow
59
+ - Explain mathematical concepts
60
+
61
+ 4. **Identify Edge Cases**
62
+ - Empty inputs
63
+ - Single element
64
+ - Maximum values
65
+ - Boundary conditions
66
+ - Error conditions
67
+
68
+ 5. **Suggest Tests**
69
+ - Propose test cases
70
+ - Suggest inputs to try
71
+ - Recommend validations
72
+
73
+ 6. **Display Summary**
74
+ - Show verification status
75
+ - Display explanation
76
+ - List edge cases
77
+ - Suggest improvements
64
78
  </process>
65
79
 
66
80
  <examples>
67
81
 
68
- **Verify results:**
82
+ **Verify current algorithm:**
69
83
  /algo-verify
70
84
 
71
- **Explain specific step:**
72
- /algo-verify --step 3
85
+ **Verify specific step:**
86
+ /algo-verify --step 5
73
87
 
74
- **Detailed explanation:**
88
+ **Detailed verification:**
75
89
  /algo-verify --detailed
76
90
 
77
- **Compare with expected:**
78
- /algo-verify --expected "42"
79
-
80
- **Diagnostic for failed runs:**
91
+ **Diagnostic mode:**
81
92
  /algo-verify --diagnostic
82
93
 
94
+ **Compare to expected:**
95
+ /algo-verify --expected "[1, 2, 3]"
96
+
83
97
  </examples>
84
98
 
85
99
  <options>
86
100
 
87
101
  --step <N>
88
- Explain step number N in detail
102
+ Explain specific step number
89
103
 
90
104
  --detailed
91
- Show detailed step-by-step explanation
105
+ Show detailed verification
92
106
 
93
107
  --diagnostic
94
- Run diagnostic mode for failed executions
108
+ Run diagnostic checks
95
109
 
96
110
  --expected <value>
97
- Expected output for comparison
111
+ Compare to expected output
98
112
 
99
113
  </options>
100
114
 
101
115
  <next_steps>
102
- /algo-extract - Start with new algorithm
103
116
  /algo-status - Check current state
117
+ /algo-list - View all algorithms
104
118
  </next_steps>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "algomath-extract",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "AlgoMath Framework - Transform AI assistants into reliable mathematical problem-solving environments",
5
5
  "main": "index.js",
6
6
  "bin": {