Use this checklist when refactoring a UN SDK to ensure nothing is missed.
- Read
tests/AGENT_REFACTORING_INSTRUCTIONS.md - Study Python SDK (
un.py) as reference - Study JavaScript SDK (
un.js) as reference - Create test file
tests/test_un_{language}.{ext} - Run baseline tests:
python3 tests/test_sdk_library.py --languages {lang}
-
execute(language, code, opts)- Sync execution -
executeAsync(language, code, opts)- Async execution -
run(file, opts)- Run file sync -
runAsync(file, opts)- Run file async
-
wait(job_id, timeout)- Poll for completion -
getJob(job_id)- Get job status -
cancelJob(job_id)- Cancel running job -
listJobs(limit)- List active jobs
-
sessionSnapshot(session_id)- Create session snapshot -
serviceSnapshot(service_id)- Create service snapshot -
listSnapshots()- List all snapshots -
restoreSnapshot(snapshot_id)- Restore from snapshot -
deleteSnapshot(snapshot_id)- Delete snapshot
-
languages(cache_ttl)- Get supported languages -
languageInfo(language)- Get language details -
detectLanguage(filename)- Detect from extension -
image(code, format)- Generate images
- Load from function arguments (highest priority)
- Load from env vars:
UNSANDBOX_PUBLIC_KEY+UNSANDBOX_SECRET_KEY - Load from
~/.unsandbox/accounts.csv - Load from
./accounts.csv(local directory) - Raise error if no credentials found
- Test all 4 credential sources work
- Implement
_sign_request(secret, timestamp, method, endpoint, body) - Generate signature:
HMAC-SHA256(secret, "{timestamp}:{method}:{endpoint}:{body}") - Signature format: 64 lowercase hexadecimal characters
- Include headers in requests:
-
Authorization: Bearer {public_key} -
X-Timestamp: {unix_timestamp} -
X-Signature: {signature} -
Content-Type: application/json
-
- Test signature generation produces correct format
- Create cache directory:
~/.unsandbox/ - Cache location:
~/.unsandbox/languages.json - Cache TTL: 3600 seconds (1 hour)
- Check cache exists AND is fresh before API call
- Only update cache on successful API response
- Create directory if needed before writing
- Test cache is used (don't call API twice within 1 hour)
Define exception classes:
-
UnsandboxError- Base exception -
AuthenticationError- Invalid credentials -
ExecutionError- Code execution failed -
APIError- API communication error -
TimeoutError- Job polling timeout
Implement proper error handling:
- Handle network errors gracefully
- Handle invalid credentials
- Handle API errors (4xx, 5xx)
- Handle malformed responses
- Handle job timeout scenarios
- Python:
""" """triple quotes - JavaScript:
/** */JSDoc format with @param @returns - Go:
//line comments before functions - Ruby:
#line comments before methods - PHP:
/** */doc blocks - Java:
/** */Javadoc format - C/C++:
// //or/* */comments - All public functions documented
- All parameters documented
- Return types documented
- Examples in docstrings
- Follow language conventions
- Use language-idiomatic patterns
- Consistent naming (snake_case, camelCase, PascalCase as appropriate)
- Proper error handling throughout
- No hardcoded credentials
- No debugging print statements
- No commented-out code
- Full permacomputer public domain notice (35+ lines)
- Placed at very top of file
- Followed by blank line
- All license text preserved exactly
- Original CLI behavior preserved
- Can execute code files:
un {file} - Can execute inline code:
un -s language 'code' - Proper usage/help output
- Correct exit codes
- Error messages to stderr
- Output to stdout
- Support for all original flags/options
- Python:
if __name__ == '__main__': - JavaScript:
if (require.main === module): - Go: Separate main() function
- Ruby:
if __FILE__ == $0: - Other languages: Language-appropriate
- Create
tests/test_un_{language}.{ext} - Test credential loading (all 4 sources)
- Test HMAC signature generation
- Test function existence and signatures
- Test error handling for invalid inputs
- Tests pass:
python3 tests/test_sdk_library.py --languages {lang}
- Can import/require library:
import unorrequire('./un') - Can call each function without errors
- Credentials load correctly
- HMAC signatures generate correctly
- Cache is created and used
- CLI still works:
un.py test.pyornode un.js test.js
-
execute()works with real API -
executeAsync()works with real API -
wait()polls correctly - Examples execute successfully
- Update
unsandbox.com/priv/static/docs/examples/{language}/execute.txt - Update
unsandbox.com/priv/static/docs/examples/{language}/execute_async.txt - Show library import/require
- Show credential setup (env vars)
- Show proper HMAC authentication
- Show error handling
- Code runs successfully
- Explain complex logic
- Document public API
- Note any language-specific workarounds
- Explain credential priority system
- Explain cache invalidation
- Create feature branch (optional):
git checkout -b refactor/{language} - Implement and test incrementally
- Commit with clear message explaining changes
- Include test file in commit
- Run all tests before committing
- Push to main (or PR if using branches)
Refactor {Language} SDK: add library exports + HMAC auth + caching
- Implement execute, executeAsync, wait, getJob, cancelJob, listJobs
- Add 4-tier credential system (args > env > home > local)
- Add 1-hour cache for languages list
- Implement HMAC-SHA256 request signing
- Preserve original CLI functionality
- Language-specific docstrings
- Full test coverage
Before declaring complete:
-
git statusis clean (all changes committed) - Unit tests pass:
python3 tests/test_sdk_library.py --languages {lang} - Master test runner passes:
./tests/run_sdk_tests.sh --languages {lang} - CLI still works:
un.{ext} test.{ext} - Library imports work:
from un import executeorconst un = require('./un') - Examples in docs can be copied and executed
- No syntax errors in any files
- No hardcoded credentials
- No debug code or print statements
- Git history is clean and meaningful
- Build works without errors
- No build artifacts committed
- Can be run after compilation
- Tests include compilation step
- Documentation mentions compilation requirement
- No .class or compiled files committed
- Build files present if needed
- Tests work with build system
- Documentation mentions build tool
- Pure functions for calculations
- Monads for I/O and side effects
- Tests use language-specific patterns
- Documentation explains functional patterns
- Can run as CLI (not just web server)
- No web server dependency for CLI mode
- Tests work without web server
Fast (< 2 hours)
- Ruby, Perl, PHP, Lua, TCL, Shell/Bash, Deno
Medium (2-4 hours)
- Go, TypeScript, Crystal, Dart, Elixir, Scala, Kotlin
Slower (4+ hours)
- Rust (borrow checker learning curve), C++, Java, Fortran, COBOL
- AGENT_REFACTORING_INSTRUCTIONS.md - Detailed walkthrough
- SDK_TESTING_GUIDE.md - Testing patterns and examples
- un.py - Python reference implementation (canonical)
- un.js - JavaScript reference implementation
- tests/test_sdk_library.py - Python test framework
- tests/run_sdk_tests.sh - Master test runner
- tests/test_un_{lang}.{ext} - Language-specific test examples
Your SDK refactoring is done when:
✓ 8/8 passed (0 failed)
All unit tests pass, no failures, all functions tested.