Skip to content

Comments

feat(cli): implement local persistent state for agent tracking#229

Merged
lijingrs merged 1 commit intomofa-org:mainfrom
Kayd-06:fix/cli-agent-persistence
Feb 23, 2026
Merged

feat(cli): implement local persistent state for agent tracking#229
lijingrs merged 1 commit intomofa-org:mainfrom
Kayd-06:fix/cli-agent-persistence

Conversation

@Kayd-06
Copy link
Contributor

@Kayd-06 Kayd-06 commented Feb 22, 2026

📋 Summary

Implements a JSON-based local persistence layer for the MoFA CLI. Agents started via mofa agent start are now recorded to a local state file so that mofa agent list can display real data instead of hardcoded mock entries.

🔗 Related Issues

Closes #227


🧠 Context

The mofa agent commands (list, start, etc.) currently use hardcoded mock data, making it impossible to track agent lifecycle across terminal sessions. This is a prerequisite for functional CLI-based agent management.


🛠️ Changes

  • Added [crates/mofa-cli/src/utils/state.rs] CliState struct with JSON load/save and corruption recovery (renames to state.json.bak)
  • Updated agent start to persist agent metadata on invocation
  • Updated agent list to read from the local state file
  • Added chrono dependency for timestamps and uptime calculation

🧪 How you Tested

  1. cargo test -p mofa-cli -- utils::state (2 unit tests pass)
  2. cargo run -p mofa-cli -- agent start test-agent
  3. cargo run -p mofa-cli -- agent list (verified agent appears with uptime)

⚠️ Breaking Changes

  • No breaking changes
  • Breaking change (describe below)

If breaking:


🧹 Checklist

Code Quality

  • Code follows Rust idioms and project conventions
  • cargo fmt run
  • cargo clippy passes without warnings

Testing

  • Tests added/updated
  • cargo test passes locally without any error

Documentation

  • Public APIs documented
  • README / docs updated (if needed)

PR Hygiene

  • PR is small and focused (one logical change)
  • Branch is up to date with main
  • No unrelated commits
  • Commit messages explain why, not only what

🧩 Additional Notes for Reviewers

Clippy Notes

cargo clippy was executed across the workspace. Pre-existing warnings are present in mofa-kernel, but this PR does not introduce any new warnings.

This PR tracks logical CLI state only. OS-level process management (PID monitoring, daemonization) is explicitly out of scope.
State file location: %APPDATA%/mofa/state.json (Windows).

@Kayd-06 Kayd-06 force-pushed the fix/cli-agent-persistence branch from a348265 to 50d9e88 Compare February 22, 2026 10:55
@lijingrs
Copy link
Collaborator

Your forked code is outdated. Please sync the fork to the latest version and merge the main branch into your current branch.

@Kayd-06 Kayd-06 force-pushed the fix/cli-agent-persistence branch from 50d9e88 to 09968ad Compare February 22, 2026 11:30
@Kayd-06 Kayd-06 force-pushed the fix/cli-agent-persistence branch from 09968ad to 6fe1022 Compare February 22, 2026 11:38
@lijingrs lijingrs merged commit 7b6447a into mofa-org:main Feb 23, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CLI] Agent commands use mock data instead of persistent state

2 participants