feat(cli): wire CLI commands to mofa-kernel/foundation backend (issue #146)#2
Closed
Copilot wants to merge 1 commit intofeature/cli-backend-connections-146-rebasedfrom
Closed
Conversation
Copilot
AI
changed the title
[WIP] Check PR #219 for issue #146 resolution
feat(cli): wire CLI commands to mofa-kernel/foundation backend (issue #146)
Feb 22, 2026
12 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📋 Summary
All
mofa-clicommand handlers were empty stubs returningOk(()). This PR replaces every stub with real backend integration — agent lifecycle throughAgentRegistry, sessions throughSessionManager, plugins throughSimplePluginRegistry, and tools throughToolRegistry— plus file-backed persistence so state survives process restarts.🔗 Related Issues
Related to mofa-org#146
🧠 Context
CLI commands called
// TODO: Implementand returned immediately. No connection existed to the kernel/foundation service layer. A previous attempt built a parallel JSON-file backend that didn't touch existing registries; this PR wires directly to the established crates instead.🛠️ Changes
store.rs(new) — GenericPersistedStore<T>writing per-item.jsonfiles; safe filename sanitization prevents path traversalcontext.rs—CliContextnow ownsAgentRegistry,SessionManager,SimplePluginRegistry,ToolRegistry, and threePersistedStoreinstances; registersCliBaseAgentFactory; seeds and replays plugin/tool specs on startup; migrates legacy nested session dirsagent/start.rs—create_and_register()via selected factory (--typeflag added); atomic: rolls back in-memory registration if persistence failsagent/stop.rs—agent.shutdown()→ persist"Stopped"→registry.unregister(); restores persisted state if unregister failsagent/restart.rs— delegates tostop::run+start::runagent/list.rs— merges live registry entries withagent_storeso stopped-but-persisted agents appearplugin/uninstall.rs— marks specenabled=falseinplugin_storebefore unregistering; rollback on failuresession/export.rs,show.rs,list.rs— switched fromget_or_create()to newSessionManager::get()that returnsOptionwithout side-effectsmofa-foundation/session.rs— addedSessionManager::get(); fixedlist()to read canonical key from JSONL header (preserves_in keys, no more_→:corruption)🧪 How you Tested
cargo test -p mofa-cli— 37 unit + 4 integration tests, all passcargo test -p mofa-foundation— 203 tests pass📸 Screenshots / Logs (if applicable)
If breaking:
🧹 Checklist
Code Quality
cargo fmtruncargo clippypasses without warningsTesting
cargo testpasses locally without any errorDocumentation
PR Hygiene
main🚀 Deployment Notes (if applicable)
On first run after upgrade,
CliContext::new()creates~/.local/share/mofa/{agents,plugins,tools}/directories and seeds default plugin/tool specs. Existing session files under the legacysessions/sessions/nesting are migrated automatically.🧩 Additional Notes for Reviewers
PersistedStoresanitizes IDs to[a-zA-Z0-9\-_.]before constructing file paths — no additional validation needed at call sitesstart/stop/uninstallare best-effort; failure messages distinguish "operation failed" from "rollback also failed"SessionManager::get()is the canonical non-mutating lookup — callers that previously usedget_or_create()and then checkedis_empty()now get a properNoneinstead💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.