2.3 KiB
2.3 KiB
Complete Implementation Plan for Onyx Phase 1
Milestone 1: Action Log and onx init
Action Log Implementation
-
Create oplog binary format (
internal/storage/oplog.go
)type OplogEntry struct { ID uint64 ParentID uint64 Timestamp int64 Command string StateBefore map[string]string StateAfter map[string]string }
-
Implement oplog writer (
internal/storage/oplog_writer.go
)OpenOplog(path string) (*OplogWriter, error)
AppendEntry(entry *OplogEntry) error
- Use binary encoding (gob or protobuf)
- Implement file locking for concurrent access
-
Implement oplog reader (
internal/storage/oplog_reader.go
)ReadLastEntry() (*OplogEntry, error)
ReadEntry(id uint64) (*OplogEntry, error)
GetUndoStack() ([]*OplogEntry, error)
-
Create transactional wrapper (
internal/core/transaction.go
)func ExecuteWithTransaction(repo *Repository, cmd string, fn func() error) error { // 1. Capture state_before // 2. Create oplog entry // 3. Execute fn() // 4. Capture state_after // 5. Finalize oplog entry // 6. Handle rollback on error }
onx init Command
-
Implement init command (
internal/commands/init.go
)- Create .git directory (via go-git)
- Create .onx directory structure
- Initialize empty oplog file
- Create default workstreams.json
- Create workspace pointer file
- Add .onx to .gitignore
-
Create CLI structure (
cmd/onx/main.go
)func main() { rootCmd := &cobra.Command{ Use: "onx", Short: "The iPhone of Version Control", } rootCmd.AddCommand(commands.InitCmd()) rootCmd.Execute() }
onx undo Command
-
Implement undo logic (
internal/commands/undo.go
)- Read last oplog entry
- Restore all refs from state_before
- Update workspace pointer
- Mark entry as undone in oplog
- Perform git checkout to restore working directory
-
Add undo tests (
internal/commands/undo_test.go
)- Test undo after init
- Test sequential undos
- Test undo with nothing to undo