Skip to content

Commit 05650cc

Browse files
feat: Enhanced CLI integration with Codex and Claude tools
- Add claude-sm and codex-sm wrapper scripts for unified experience - Implement comprehensive onboarding flow with multiple auth methods - Add db, login, and migrate commands for database operations - Enhance Railway server with full API implementation - Improve frame management with better error handling - Update database adapters for improved reliability - Add RLM workflow documentation and usage guides - Include deployment scripts for Railway setup
1 parent 579024e commit 05650cc

24 files changed

Lines changed: 2746 additions & 1542 deletions

RLM_LINEAR_WORKFLOW.md

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# RLM + Linear Task Workflow
2+
3+
## Quick Start: Using RLM for Linear Tasks
4+
5+
### Step 1: Sync Linear Tasks
6+
```bash
7+
# Pull latest tasks from Linear
8+
npm run linear:sync
9+
10+
# View available tasks
11+
stackmemory tasks list --status todo --limit 10
12+
```
13+
14+
### Step 2: Pick a Task and Use RLM
15+
```bash
16+
# Basic format
17+
stackmemory skills rlm "[TASK-ID] Task description from Linear"
18+
19+
# Real example
20+
stackmemory skills rlm "[STA-102] Implement Two-Tier Storage System with Redis hot tier for recent traces and S3 cold tier for archival"
21+
```
22+
23+
### Step 3: RLM Will Automatically:
24+
1. **Decompose** the task into subtasks
25+
2. **Plan** the implementation approach
26+
3. **Execute** subtasks (currently mock mode)
27+
4. **Review** the implementation (3 stages)
28+
5. **Verify** quality threshold (85%+)
29+
6. **Save** context to database
30+
31+
## Working Examples
32+
33+
### Example 1: API Endpoint Implementation
34+
```bash
35+
stackmemory skills rlm "Create REST API endpoint for user profile management with CRUD operations, validation, and authentication"
36+
```
37+
38+
### Example 2: Bug Fix with Root Cause Analysis
39+
```bash
40+
stackmemory skills rlm "Debug and fix memory leak in frame manager during long sessions - investigate root cause and implement solution"
41+
```
42+
43+
### Example 3: Refactoring Task
44+
```bash
45+
stackmemory skills rlm "Refactor Linear sync service to use GraphQL instead of REST API while maintaining backward compatibility"
46+
```
47+
48+
### Example 4: Test Suite Creation
49+
```bash
50+
stackmemory skills rlm "Create comprehensive test suite for dual-stack manager including unit tests, integration tests, and performance benchmarks"
51+
```
52+
53+
## Current Capabilities (Mock Mode)
54+
55+
The RLM currently operates in **mock mode** for testing, which means:
56+
- ✅ Task decomposition works
57+
- ✅ Planning phase executes
58+
- ✅ Review stages run
59+
- ✅ Quality metrics calculated
60+
- ✅ Context persisted to database
61+
- ⚠️ Actual code generation is simulated
62+
- ⚠️ Subagents return mock responses
63+
64+
## Production Mode (Future)
65+
66+
To enable real AI-powered execution:
67+
68+
1. Set API credentials:
69+
```bash
70+
export ANTHROPIC_API_KEY="your-key"
71+
```
72+
73+
2. Disable mock mode in code:
74+
```typescript
75+
// In src/integrations/claude-code/subagent-client.ts
76+
const client = new ClaudeCodeSubagentClient(false); // false = real mode
77+
```
78+
79+
## Monitoring RLM Execution
80+
81+
### Check Progress
82+
```bash
83+
# View execution status
84+
stackmemory status
85+
86+
# List created frames
87+
stackmemory context list
88+
89+
# View specific frame details
90+
stackmemory context get <frame-id>
91+
```
92+
93+
### Debug Mode
94+
```bash
95+
# Enable debug output
96+
export DEBUG_TRACE=true
97+
export STACKMEMORY_DEBUG=true
98+
stackmemory skills rlm "Your task"
99+
```
100+
101+
## Integration with Linear
102+
103+
### Complete Workflow
104+
```bash
105+
# 1. Morning sync
106+
npm run linear:sync
107+
108+
# 2. Pick highest priority task
109+
stackmemory tasks list --status todo --priority high
110+
111+
# 3. Work on it with RLM
112+
stackmemory skills rlm "[STA-XXX] Full task description"
113+
114+
# 4. Review results
115+
stackmemory status
116+
stackmemory context list
117+
118+
# 5. Update Linear (when real mode enabled)
119+
# The system will automatically update Linear task status
120+
```
121+
122+
## Tips for Best Results
123+
124+
1. **Include Task ID**: Always prefix with [STA-XXX] for tracking
125+
2. **Full Description**: Copy complete task description from Linear
126+
3. **Add Constraints**: Mention specific requirements or limitations
127+
4. **Specify Tech Stack**: Include libraries/frameworks to use
128+
5. **Define Success**: Clear acceptance criteria
129+
130+
## Troubleshooting
131+
132+
### Common Issues
133+
134+
1. **"Cannot find module"**: Run `npm install` and `npm run build`
135+
2. **"Database error"**: Check `stackmemory status`
136+
3. **"No tasks found"**: Run `npm run linear:sync`
137+
4. **Quality threshold not met**: Task too vague, add more details
138+
139+
### Test RLM System
140+
```bash
141+
# Run comprehensive tests
142+
./scripts/test-rlm-comprehensive.sh
143+
144+
# Should see: ✨ All tests passed! (100% success rate)
145+
```
146+
147+
## Summary
148+
149+
The RLM orchestrator transforms complex Linear tasks into manageable, quality-assured implementations through:
150+
- Intelligent task decomposition
151+
- Parallel execution where possible
152+
- Multi-stage quality reviews
153+
- Persistent context for collaboration
154+
155+
Use it for any Linear task that would benefit from systematic breakdown and quality assurance!

bin/claude-sm

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#!/usr/bin/env node
2-
32
/**
4-
* Claude-SM CLI Launcher
5-
* Wrapper script to launch Claude with StackMemory and worktree support
3+
* Claude-SM CLI Launcher (ESM)
4+
* Delegates to built CLI in dist without requiring tsx.
65
*/
7-
8-
// Compile and run the TypeScript version if needed
9-
require('tsx');
10-
require('../dist/src/cli/claude-sm.js');
6+
import('../dist/cli/claude-sm.js');

bin/codex-sm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env node
2+
/**
3+
* Codex-SM CLI Launcher (ESM)
4+
* Delegates to built CLI in dist without requiring tsx.
5+
*/
6+
import('../dist/cli/codex-sm.js');

claude-api-wrapper.cjs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env node
2+
3+
// Simple Claude API wrapper that mimics the Claude CLI interface
4+
// but uses the Anthropic API directly with the API key from environment
5+
6+
const Anthropic = require('@anthropic-ai/sdk');
7+
const fs = require('fs');
8+
const path = require('path');
9+
10+
// Get API key from environment
11+
const apiKey = process.env.ANTHROPIC_API_KEY;
12+
13+
if (!apiKey) {
14+
console.error('Error: ANTHROPIC_API_KEY environment variable not set');
15+
process.exit(1);
16+
}
17+
18+
// Parse command line arguments
19+
const args = process.argv.slice(2);
20+
let prompt = '';
21+
let printMode = false;
22+
let outputFormat = 'text';
23+
24+
for (let i = 0; i < args.length; i++) {
25+
if (args[i] === '-p' || args[i] === '--print') {
26+
printMode = true;
27+
} else if (args[i] === '--output-format') {
28+
outputFormat = args[++i];
29+
} else if (args[i] === '--dangerously-skip-permissions') {
30+
// Ignore this flag
31+
} else if (!args[i].startsWith('-')) {
32+
// This is the prompt
33+
prompt = args.slice(i).join(' ');
34+
break;
35+
}
36+
}
37+
38+
// If no prompt provided, read from stdin
39+
if (!prompt) {
40+
prompt = fs.readFileSync(0, 'utf-8');
41+
}
42+
43+
if (!prompt) {
44+
console.error('Error: No prompt provided');
45+
process.exit(1);
46+
}
47+
48+
// Initialize Anthropic client
49+
const anthropic = new Anthropic({
50+
apiKey: apiKey,
51+
});
52+
53+
// Main function to call the API
54+
async function callClaude() {
55+
try {
56+
const message = await anthropic.messages.create({
57+
model: 'claude-3-5-sonnet-20241022',
58+
max_tokens: 4096,
59+
messages: [
60+
{
61+
role: 'user',
62+
content: prompt
63+
}
64+
]
65+
});
66+
67+
// Output based on format
68+
if (outputFormat === 'json' || outputFormat === 'stream-json') {
69+
console.log(JSON.stringify({
70+
structured_output: {
71+
content: message.content[0].text,
72+
model: message.model,
73+
usage: message.usage
74+
}
75+
}));
76+
} else {
77+
// Text output
78+
console.log(message.content[0].text);
79+
}
80+
81+
} catch (error) {
82+
console.error('Error calling Claude API:', error.message);
83+
process.exit(1);
84+
}
85+
}
86+
87+
callClaude();

claude-api-wrapper.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env node
2+
3+
// Simple Claude API wrapper that mimics the Claude CLI interface
4+
// but uses the Anthropic API directly with the API key from environment
5+
6+
const Anthropic = require('@anthropic-ai/sdk');
7+
const fs = require('fs');
8+
const path = require('path');
9+
10+
// Get API key from environment
11+
const apiKey = process.env.ANTHROPIC_API_KEY;
12+
13+
if (!apiKey) {
14+
console.error('Error: ANTHROPIC_API_KEY environment variable not set');
15+
process.exit(1);
16+
}
17+
18+
// Parse command line arguments
19+
const args = process.argv.slice(2);
20+
let prompt = '';
21+
let printMode = false;
22+
let outputFormat = 'text';
23+
24+
for (let i = 0; i < args.length; i++) {
25+
if (args[i] === '-p' || args[i] === '--print') {
26+
printMode = true;
27+
} else if (args[i] === '--output-format') {
28+
outputFormat = args[++i];
29+
} else if (args[i] === '--dangerously-skip-permissions') {
30+
// Ignore this flag
31+
} else if (!args[i].startsWith('-')) {
32+
// This is the prompt
33+
prompt = args.slice(i).join(' ');
34+
break;
35+
}
36+
}
37+
38+
// If no prompt provided, read from stdin
39+
if (!prompt) {
40+
prompt = fs.readFileSync(0, 'utf-8');
41+
}
42+
43+
if (!prompt) {
44+
console.error('Error: No prompt provided');
45+
process.exit(1);
46+
}
47+
48+
// Initialize Anthropic client
49+
const anthropic = new Anthropic({
50+
apiKey: apiKey,
51+
});
52+
53+
// Main function to call the API
54+
async function callClaude() {
55+
try {
56+
const message = await anthropic.messages.create({
57+
model: 'claude-3-5-sonnet-20241022',
58+
max_tokens: 4096,
59+
messages: [
60+
{
61+
role: 'user',
62+
content: prompt
63+
}
64+
]
65+
});
66+
67+
// Output based on format
68+
if (outputFormat === 'json' || outputFormat === 'stream-json') {
69+
console.log(JSON.stringify({
70+
structured_output: {
71+
content: message.content[0].text,
72+
model: message.model,
73+
usage: message.usage
74+
}
75+
}));
76+
} else {
77+
// Text output
78+
console.log(message.content[0].text);
79+
}
80+
81+
} catch (error) {
82+
console.error('Error calling Claude API:', error.message);
83+
process.exit(1);
84+
}
85+
}
86+
87+
callClaude();

0 commit comments

Comments
 (0)