algomath-extract 1.0.0 → 1.0.2

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.
@@ -0,0 +1,99 @@
1
+ ---
2
+ description: "Extract algorithm from PDF or text file"
3
+ argument-hint: "[file-path] [--auto] [--step] [--name <name>]"
4
+ tools:
5
+ read: true
6
+ write: true
7
+ ---
8
+
9
+ <objective>
10
+ Extract algorithm from PDF or text file using LLM-powered parsing.
11
+ Supports automatic extraction or step-by-step with review points.
12
+ </objective>
13
+
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>
18
+
19
+ <process>
20
+ Execute extraction workflow:
21
+
22
+ 1. **Parse Arguments**
23
+ - Check if file path provided
24
+ - Determine mode: auto, step-by-step, or interactive
25
+
26
+ 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
31
+
32
+ 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
38
+
39
+ 4. **Review Point (if step-by-step)**
40
+ - Display extracted text
41
+ - Ask user to confirm or edit
42
+ - Apply user corrections
43
+
44
+ 5. **Generate Structured Steps**
45
+ - Convert parsed text to Algorithm object
46
+ - Validate step structure
47
+ - Check for completeness
48
+
49
+ 6. **Review Point (if step-by-step)**
50
+ - Display structured steps
51
+ - Show inputs, outputs, step list
52
+ - Allow editing
53
+
54
+ 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)
59
+
60
+ 8. **Display Summary**
61
+ - Show algorithm name
62
+ - Show step count
63
+ - Display next steps
64
+ - Suggest: /algo-generate
65
+ </process>
66
+
67
+ <examples>
68
+
69
+ **Extract from PDF (interactive):**
70
+ /algo-extract research_paper.pdf
71
+
72
+ **Auto-extract (no prompts):**
73
+ /algo-extract --auto research_paper.pdf
74
+
75
+ **Extract from text file:**
76
+ /algo-extract algorithm.txt
77
+
78
+ **Specify algorithm name:**
79
+ /algo-extract research.pdf --name "Dijkstra Shortest Path"
80
+
81
+ </examples>
82
+
83
+ <options>
84
+
85
+ --auto
86
+ Skip review points, extract automatically
87
+
88
+ --step
89
+ Enable step-by-step mode with review at each stage
90
+
91
+ --name <name>
92
+ Specify algorithm name (optional)
93
+
94
+ </options>
95
+
96
+ <next_steps>
97
+ /algo-generate - Generate Python code from extracted steps
98
+ /algo-status - Check current algorithm state
99
+ </next_steps>
@@ -0,0 +1,97 @@
1
+ ---
2
+ description: "Generate Python code from extracted algorithm steps"
3
+ argument-hint: "[--review] [--template-only] [--llm-only]"
4
+ tools:
5
+ read: true
6
+ write: true
7
+ ---
8
+
9
+ <objective>
10
+ Generate executable Python code from structured algorithm steps.
11
+ Supports template-based generation (fast, reliable) or LLM-enhanced (for complex expressions).
12
+ </objective>
13
+
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>
18
+
19
+ <process>
20
+ Execute code generation workflow:
21
+
22
+ 1. **Load Algorithm**
23
+ - Read steps.json from current algorithm
24
+ - Validate step structure
25
+ - Check for completeness
26
+
27
+ 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)
31
+
32
+ 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
57
+
58
+ 8. **Display Summary**
59
+ - Show generated file path
60
+ - Line count
61
+ - Next steps: /algo-run
62
+ </process>
63
+
64
+ <examples>
65
+
66
+ **Generate with default hybrid mode:**
67
+ /algo-generate
68
+
69
+ **Generate with review:**
70
+ /algo-generate --review
71
+
72
+ **Template-based only (faster):**
73
+ /algo-generate --template-only
74
+
75
+ **LLM-enhanced only (better for complex):**
76
+ /algo-generate --llm-only
77
+
78
+ </examples>
79
+
80
+ <options>
81
+
82
+ --review
83
+ Show generated code for review before saving
84
+
85
+ --template-only
86
+ Use rule-based generation only (no LLM)
87
+
88
+ --llm-only
89
+ Use LLM for all generation (slower but more accurate)
90
+
91
+ </options>
92
+
93
+ <next_steps>
94
+ /algo-run - Execute the generated code
95
+ /algo-verify - Verify execution results
96
+ /algo-status - Check algorithm state
97
+ </next_steps>
@@ -0,0 +1,62 @@
1
+ ---
2
+ description: "Show help and available commands"
3
+ argument-hint: "[command]"
4
+ tools:
5
+ read: true
6
+ write: false
7
+ ---
8
+
9
+ <objective>
10
+ Display help information, available commands, and usage examples.
11
+ </objective>
12
+
13
+ <execution_context>
14
+ @/home/milgraph/Projects/algo_framework/README.md
15
+ </execution_context>
16
+
17
+ <process>
18
+ Display help:
19
+
20
+ 1. **Show Welcome Banner**
21
+ - AlgoMath logo/name
22
+ - Version
23
+ - Brief description
24
+
25
+ 2. **List Commands**
26
+ - /algo-extract - Extract from PDF/text
27
+ - /algo-generate - Generate Python code
28
+ - /algo-run - Execute code
29
+ - /algo-verify - Verify results
30
+ - /algo-status - Check current state
31
+ - /algo-list - List saved algorithms
32
+ - /algo-help - This help
33
+
34
+ 3. **Show Workflow**
35
+ ```
36
+ PDF/Text → Extract → Generate → Run → Verify
37
+ ```
38
+
39
+ 4. **Show Examples**
40
+ - Basic usage
41
+ - Common flags
42
+ - Tips
43
+
44
+ 5. **Show Documentation Links**
45
+ - User guide
46
+ - Examples
47
+ - Troubleshooting
48
+ </process>
49
+
50
+ <examples>
51
+
52
+ **Show general help:**
53
+ /algo-help
54
+
55
+ **Show help for specific command:**
56
+ /algo-help extract
57
+
58
+ </examples>
59
+
60
+ <next_steps>
61
+ /algo-extract - Start with a new algorithm
62
+ </next_steps>
@@ -0,0 +1,60 @@
1
+ ---
2
+ description: "List all saved algorithms"
3
+ argument-hint: "[--detailed]"
4
+ tools:
5
+ read: true
6
+ write: false
7
+ ---
8
+
9
+ <objective>
10
+ Display list of all saved algorithms with their status and basic info.
11
+ </objective>
12
+
13
+ <execution_context>
14
+ @/home/milgraph/Projects/algo_framework/src/cli/commands.py
15
+ </execution_context>
16
+
17
+ <process>
18
+ List algorithms:
19
+
20
+ 1. **Scan Algorithms Directory**
21
+ - Read .algomath/algorithms/
22
+ - Find all algorithm folders
23
+
24
+ 2. **Load Metadata**
25
+ - Read metadata.json from each
26
+ - Extract name, state, timestamps
27
+
28
+ 3. **Display List**
29
+ - Algorithm name
30
+ - Current state
31
+ - Step count
32
+ - Last modified date
33
+ - Status indicators
34
+
35
+ 4. **Detailed View (if --detailed)**
36
+ - Show full path
37
+ - Show all files present
38
+ - Show execution results
39
+ - Show verification status
40
+
41
+ 5. **Sort and Format**
42
+ - Sort by last modified
43
+ - Format as table or list
44
+ - Color code by status
45
+ </process>
46
+
47
+ <examples>
48
+
49
+ **List algorithms:**
50
+ /algo-list
51
+
52
+ **Detailed list:**
53
+ /algo-list --detailed
54
+
55
+ </examples>
56
+
57
+ <next_steps>
58
+ /algo-extract - Create new algorithm
59
+ /algo-status - Check specific algorithm
60
+ </next_steps>
@@ -0,0 +1,81 @@
1
+ ---
2
+ description: "Execute generated Python code"
3
+ argument-hint: "[--skip] [--timeout <seconds>]"
4
+ tools:
5
+ read: true
6
+ write: true
7
+ ---
8
+
9
+ <objective>
10
+ Execute generated Python code in a safe sandboxed environment.
11
+ Captures stdout, stderr, and execution results.
12
+ </objective>
13
+
14
+ <execution_context>
15
+ @/home/milgraph/Projects/algo_framework/src/execution/sandbox.py
16
+ </execution_context>
17
+
18
+ <process>
19
+ Execute code in sandbox:
20
+
21
+ 1. **Load Generated Code**
22
+ - Read generated.py from current algorithm
23
+ - Validate code exists
24
+ - Check syntax
25
+
26
+ 2. **Create Sandbox**
27
+ - Create isolated temp directory
28
+ - Copy code to sandbox
29
+ - Set resource limits
30
+
31
+ 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
53
+ </process>
54
+
55
+ <examples>
56
+
57
+ **Execute code:**
58
+ /algo-run
59
+
60
+ **Skip execution:**
61
+ /algo-run --skip
62
+
63
+ **Custom timeout:**
64
+ /algo-run --timeout 60
65
+
66
+ </examples>
67
+
68
+ <options>
69
+
70
+ --skip
71
+ Skip execution and proceed directly to verification
72
+
73
+ --timeout <seconds>
74
+ Maximum execution time (default: 30)
75
+
76
+ </options>
77
+
78
+ <next_steps>
79
+ /algo-verify - Verify execution results
80
+ /algo-status - Check algorithm state
81
+ </next_steps>
@@ -0,0 +1,71 @@
1
+ ---
2
+ description: "Show current algorithm state and progress"
3
+ argument-hint: "[--verbose]"
4
+ tools:
5
+ read: true
6
+ write: false
7
+ ---
8
+
9
+ <objective>
10
+ Display current algorithm state, progress, and available next steps.
11
+ Shows workflow state, completion status, and suggestions.
12
+ </objective>
13
+
14
+ <execution_context>
15
+ @/home/milgraph/Projects/algo_framework/src/cli/commands.py
16
+ </execution_context>
17
+
18
+ <process>
19
+ Display status:
20
+
21
+ 1. **Load Current State**
22
+ - Read context manager state
23
+ - Get current algorithm name
24
+ - Get workflow state
25
+
26
+ 2. **Display Progress**
27
+ - State: IDLE → EXTRACTED → STEPS → CODE → EXECUTED → VERIFIED
28
+ - Show completion percentage
29
+ - Visual progress bar
30
+
31
+ 3. **Show Algorithm Info**
32
+ - Name
33
+ - Step count (if extracted)
34
+ - Code generated (yes/no)
35
+ - Executed (yes/no)
36
+ - Verified (yes/no)
37
+
38
+ 4. **Show Data Status**
39
+ - Source text present
40
+ - Steps structured
41
+ - Code generated
42
+ - Results captured
43
+
44
+ 5. **Suggest Next Steps**
45
+ Based on current state:
46
+ - IDLE: /algo-extract
47
+ - EXTRACTED: /algo-generate
48
+ - CODE_GENERATED: /algo-run
49
+ - EXECUTION_COMPLETE: /algo-verify
50
+ - VERIFIED: Done! /algo-extract for new
51
+
52
+ 6. **Display in Verbose Mode (if --verbose)**
53
+ - Full algorithm details
54
+ - Step list
55
+ - File paths
56
+ - Timestamps
57
+ </process>
58
+
59
+ <examples>
60
+
61
+ **Show status:**
62
+ /algo-status
63
+
64
+ **Verbose status:**
65
+ /algo-status --verbose
66
+
67
+ </examples>
68
+
69
+ <next_steps>
70
+ Depends on current state - displayed dynamically
71
+ </next_steps>
@@ -0,0 +1,104 @@
1
+ ---
2
+ description: "Verify execution results and explain algorithm behavior"
3
+ argument-hint: "[--step <N>] [--detailed] [--diagnostic] [--expected <value>]"
4
+ tools:
5
+ read: true
6
+ write: true
7
+ ---
8
+
9
+ <objective>
10
+ Verify execution results, compare to expected values, explain algorithm behavior,
11
+ and identify potential edge cases.
12
+ </objective>
13
+
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>
19
+
20
+ <process>
21
+ Execute verification workflow:
22
+
23
+ 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
64
+ </process>
65
+
66
+ <examples>
67
+
68
+ **Verify results:**
69
+ /algo-verify
70
+
71
+ **Explain specific step:**
72
+ /algo-verify --step 3
73
+
74
+ **Detailed explanation:**
75
+ /algo-verify --detailed
76
+
77
+ **Compare with expected:**
78
+ /algo-verify --expected "42"
79
+
80
+ **Diagnostic for failed runs:**
81
+ /algo-verify --diagnostic
82
+
83
+ </examples>
84
+
85
+ <options>
86
+
87
+ --step <N>
88
+ Explain step number N in detail
89
+
90
+ --detailed
91
+ Show detailed step-by-step explanation
92
+
93
+ --diagnostic
94
+ Run diagnostic mode for failed executions
95
+
96
+ --expected <value>
97
+ Expected output for comparison
98
+
99
+ </options>
100
+
101
+ <next_steps>
102
+ /algo-extract - Start with new algorithm
103
+ /algo-status - Check current state
104
+ </next_steps>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "algomath-extract",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "AlgoMath Framework - Transform AI assistants into reliable mathematical problem-solving environments",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -33,6 +33,7 @@
33
33
  "files": [
34
34
  "bin/",
35
35
  "scripts/",
36
+ "commands/",
36
37
  "src/",
37
38
  "requirements.txt",
38
39
  "README.md"
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * AlgoMath Post-Install Hook
5
+ *
6
+ * Runs automatically after npm install
7
+ */
8
+
9
+ console.log('\n╔════════════════════════════════════════════════════╗');
10
+ console.log('║ AlgoMath Post-Install ║');
11
+ console.log('╚════════════════════════════════════════════════════╝\n');
12
+
13
+ console.log('AlgoMath has been installed successfully!\n');
14
+ console.log('To install the opencode commands, run:');
15
+ console.log(' npx algomath-extract --opencode\n');
16
+ console.log('Or manually:');
17
+ console.log(' node node_modules/algomath-extract/bin/install.js --opencode\n');
18
+
19
+ console.log('Then try:');
20
+ console.log(' /algo-help\n');