Skip to content

Add read-only native sub-agent flow MiniApp - #69

Merged
MyPrototypeWhat merged 2 commits into
MiniMax-AI:mainfrom
Huixin615:feat/agent-flow
Oct 26, 2026
Merged

MyPrototypeWhat merged 2 commits into
MiniMax-AI:mainfrom
Huixin615:feat/agent-flow

Conversation

@Huixin615

@Huixin615 Huixin615 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add Agent Flow, a Mini App for inspecting native task calls and sub-agent lifecycle events recorded by this plugin's Hooks.

  • Show task-call and sub-agent running intervals, tool-return status, and overlapping child execution.
  • Link a task call to a child only when their structured child session IDs match, or a Hook explicitly provides the parent session ID. The UI does not infer relationships from nearby timestamps.
  • Let the user import the plugin-generated JSONL file and select a recorded session. “View latest record” selects the newest imported session with task calls; it does not claim to identify the currently open chat.

Changes since the review of bc50fa1

The implementation that accessed Host-internal data has been removed:

  • No access to the Host runtime SQLite database, v2/sessions files, or session history.
  • No /api/sessions or /api/task endpoints derived from those stores.
  • The Mini App's Node process serves only its own static files and checks the loopback Host header. The browser reads an event file only after the user selects it.

Instead, MiniMax Code's SessionStart, PreToolUse(task), PostToolUse(task), SubagentStart, and SubagentStop Hooks send events to this plugin's recorder. The recorder writes bounded event metadata to the runtime-provided PLUGIN_DATA directory.

Data & limitations

Records contain timestamps, SHA-256 digests of opaque IDs, agent type, a task title truncated to 160 characters, and whether a tool response field was present. A task title may contain user-supplied or sensitive text. Full task instructions, tool-result bodies, and child final replies are not stored. Records stay on the user's machine until the user deletes them.

The imported file is parsed in the page's memory; the page does not scan Host sessions or automatically refresh the file. A PostToolUse event shows that a tool call returned, not that the parent Agent adopted its result. Events without an explicit association are excluded from the selected session's child view. Events from before the Hooks were installed cannot be reconstructed.

Requires MiniMax Code 3.1.4 or later and node on the Hook process's PATH. The documented macOS file location is a manual file-picker hint, not a path accessed by plugin code. Windows has not been manually tested.

Validation

  • node --test plugins/huixin615/agent-flow/tests/*.test.mjs: 10/10 passed.
  • npm run check: agent-flow: OK, repository validation passed, and 69 repository tests passed.
  • Manually tested on MiniMax Code 3.1.4/macOS: two native task calls and two sub-agent lifecycles were recorded. Each call linked to its child by an exact structured session ID match, and the child running intervals overlapped.
  • No real session records, imported event files, or runtime caches are included in this PR.

@MyPrototypeWhat MyPrototypeWhat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Huixin615 — thanks for the first contribution. I looked at bc50fa1.

There is one repository red line that blocks merge on this revision.

Must fix

  1. Please remove direct access to the Host’s local runtime store and session history (read-only still counts)

Community plugins must not open MiniMax Code’s internal runtime database or its session store files. Disclosure in README / Data & access does not make that path allowed. The PR description and the code agree on the source; this is not a “docs say X, code does Y” gap:

  • miniapp/node/data.mjs:28-31 (dataHome): resolves MAVIS_HOME or ~/.minimax — not context.dataDir.
  • miniapp/node/data.mjs:34-50 (withDb): import('node:sqlite') then DatabaseSync(join(home, 'v2', 'sqlite', 'runtime-state.sqlite'), { readOnly: true }).
  • Queries on that store include conversation / task indexes: data.mjs:53-60 and data.mjs:71-80 (local_runtime_sessions), data.mjs:74-75 / data.mjs:143-144 (local_runtime_background_tasks).
  • Session history files are read next: data.mjs:192-226 (historyRows) opens …/v2/sessions/<historyDir>/messages.jsonl under the same home root (with path checks and a symlink reject).
  • Those history rows feed the UI: task instructions and parent-result matching (data.mjs:235-277, data.mjs:326-337), plus child final text / tool names (data.mjs:347-365 → /api/task in server.mjs:43-46).
  • server.mjs never uses context.dataDir; the live data path is entirely outside the plugin’s private directory.

So “read-only,” “no outbound network,” “no Agent turns,” and “no writes to Host files” can all be true and still leave the red line intact: the Mini App opens and queries Host-internal runtime state and session history. Please remove that whole path (SQLite open, history file reads, and any API that depends on them). After it is gone, wait for a compliant way to get this data before rebuilding, or narrow the Mini App so it does not need Host-internal stores. Please align README Data & access with whatever remains.

What the page currently surfaces from that path (worth knowing until it is removed): conversation titles and ids (/api/sessions), task instruction text, child final replies, and tool names. Anything a user pasted into a prompt or a child wrote back can appear in the local page JSON.

Optional (non-blocking; fine to park while the red line is open)

  • Loopback Host checks on GET: server.mjs:26-32 serves HTML/CSS/JS and the APIs with method checks only. Other plugins in the gallery also guard loopback Host on requests; worth matching when you have a Host-safe data path.

Happy to re-review once the Host-internal store / session-history access is gone.

@Huixin615

Copy link
Copy Markdown
Contributor Author

@MyPrototypeWhat Thanks for your review. I have updated it. Could your please take another look when you have time? Thanks you very much!

@MyPrototypeWhat MyPrototypeWhat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 1241df7.

Thanks for the rework, @Huixin615. Last round's must-fix is resolved: miniapp/node/data.mjs and its tests are deleted, the Mini App Node process now serves only its own static assets (miniapp/node/server.mjs:47-51), and the plugin no longer reads SQLite or session history.

The loopback Host/Origin check has been added (server.mjs:22-32, applied at :44). hooks is an allowed manifest field (docs/package-contract.md:57), and the hooks write only to the plugin's own hook data folder (hooks/record.mjs:47-49).

Optional

  • Storage path in the READMEs. The path at README.md:13 and README.zh-CN.md:13 is correct for a default install, and the README already presents it as a reference. It will differ when MiniMax Code runs with a profile or a custom data directory, so consider adding one sentence saying so and pointing users to the agent-flow-events.jsonl picker in that case.
  • Task titles are stored in plaintext. hooks/normalize.mjs:39-40 keeps up to 160 characters of description/title/name from every task call, and these lines are kept until the user deletes them (README.zh-CN.md:25 discloses this, which is good). Because this is the only free text the plugin persists, consider either making it opt-in or shortening it further. You could also store only a digest by default and let the page show "untitled task #n".
  • Lock handling. hooks/record.mjs:9-25 deletes a lock older than 10 s and then retries, and if every attempt fails it silently drops the event (:26). That is acceptable for an observer, but a short note in the README that events can be dropped under contention would set expectations correctly.
  • Rotation is unbounded. record.mjs:30-32 rotates at 8 MiB but never prunes old agent-flow-events-*.jsonl files. Keeping only the last N would cap disk use.

Notes

  • node scripts/validate.mjs (Node 22): plugins/huixin615/agent-flow: OK, repository OK.
  • node --test plugins/huixin615/agent-flow/tests/*.test.mjs (Node 22): 10/10 pass.
  • CI for this head is waiting for maintainer approval to run.
  • Hook payload handling looks careful. normalize.mjs hashes every identifier with SHA-256 (:4-5, :31-42). It reads tool_response only for structured child-session IDs and never its text (:7-17). It does not keep tool output, child replies, full instructions, or workspace paths. Payloads over 256 KiB are rejected (record.mjs:5, :42-45).

Copy link
Copy Markdown
Collaborator

This now conflicts with main after #71 merged. Could you rebase? Happy to merge once it's clean.

@Huixin615

Copy link
Copy Markdown
Contributor Author

@MyPrototypeWhat Thanks again for your reivew. I have resolved it.

@MyPrototypeWhat
MyPrototypeWhat merged commit 6d1fb27 into MiniMax-AI:main Oct 26, 2026
1 check 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.

2 participants