Skip to content
This repository was archived by the owner on Dec 3, 2026. It is now read-only.

feat: streaming events: records, progress and warnings as they happen; --json-stream - #166

Closed
gold-silver-copper wants to merge 5 commits into
mainfrom
feat/stream-events
Closed

gold-silver-copper wants to merge 5 commits into
mainfrom
feat/stream-events

Conversation

@gold-silver-copper

@gold-silver-copper gold-silver-copper commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on gitkb/meta#165 (this branch holds its commit too and targets main; its own change is the last commit, git diff refactor/request-envelope...feat/stream-events: +683/−34 in 15 files). This is item K30a, moved out of #165 by that PR's size tripwire.

What changes for a user

  • A command can show what it finds as it goes: a plugin sends events (record, progress, warning) while it runs, and meta shows records and warnings as they arrive (progress only on a terminal's stderr).
  • meta --json is unchanged: one Envelope. Records and warnings that arrived as events are in it, in arrival order (before the response's own); progress is left out.
  • meta --json-stream … (new, one of meta's options, before the command): one {"event": …} line per event as it happens, including a step event as each step of a plan ends (exec, raw meta git …, any plugin's plan), then {"envelope": …}: the same Envelope --json prints. It conflicts with --json.
$ meta --json-stream exec -- true
{"event":{"type":"step","project":".","path":"/w","argv":["true"],"exit_code":0,"stdout":"","stderr":""}}
{"event":{"type":"step","project":"a",…}}
{"event":{"type":"step","project":"b",…}}
{"envelope":{"success":true,"command":"exec","results":[…],"skipped":[],"warnings":[]}}

The protocol (SDK)

  • meta_plugin::event::Event (serde tag type): Record(ProjectResult) (the same type as Results.records), Progress { done, total?, project?, message? }, Warning(Warning) (the same type as warnings[]), Step(ProjectResult) (meta's own: a plugin that sends one fails).
  • The channel: META_EVENTS names a per-call path; one JSON event per line, at most 64 KiB (event::MAX_LINE). A Rust plugin uses Ctx::{emit, record, progress}; a script printf '%s\n' "$event" >> "$META_EVENTS". Without the variable (a test calling the plugin directly) Ctx keeps records for the response.
  • A call still ends with its one Response; there is no result or error event.

Decisions taken alone

  • Unix: a FIFO; Windows: a followed file. The design asked for a pipe handed to the child. std can't pass an extra inherited fd or handle without unsafe (pre_exec, CreateNamedPipeW), and the workspace forbids unsafe_code; the design's own tripwire allows a per-call path in META_EVENTS. On Unix meta makes a FIFO (nix::unistd::mkfifo; rustix has no mkfifoat on macOS) in the call's private folder and reads it non-blocking from a thread (10 ms idle wait, cut short when the call ends), so a writer blocks while meta is behind and nothing piles up. On Windows there is no named-pipe server without FFI, so it is a file meta follows: no backpressure there (recorded; a stream command that never ends, PR 5a, would grow the file).
  • The SDK's process owner strips META_REQUEST, META_RESPONSE and META_EVENTS from every program it starts, unless the caller set them (meta calling a plugin): a plugin's git or hook can't write its answer (part of RT-13, early).
  • loop_lib::LoopConfig::on_done tells the host as each step ends; only --json-stream uses it.

Tests

+3 cargo tests (meta_cli/tests/plugin_routing.rs), +1 SDK unit test:

  • a_record_a_plugin_streams_is_shown_before_it_ends: a script plugin's record is on meta's stdout while the plugin still waits.
  • json_folds_what_a_plugin_streamed_into_its_one_envelope: streamed records and warnings in the Envelope, progress dropped; a plugin's step event fails it (plugin-failed).
  • json_stream_is_a_line_per_event_then_the_envelope_json_prints: one step line per repo, last line equal to --json's Envelope.

box2 at cae59c9: fmt and clippy -D warnings clean; cargo test --workspace 638 passed, 0 failed (one hints test failed in the first full run and passed in 3 single reruns and a second full run: not explained, recorded); bats tests/ 618/618. 50 meta project list calls on box2: 0.41 s (not benched before).

CI and the 10-minute macOS ceiling: at e0349a4 the macOS integration job took 10m44s, over the ceiling. The events reader waited out its 10 ms poll at the end of every plugin call; cae59c9 wakes it when the call ends. The ceiling was not raised. CI at cae59c9 (run 41939742520): all jobs green. The macOS integration job took 10m35s on its first attempt (over the 10-minute ceiling) and 8m45s on a rerun of the same head (job 126962227910). Identical code, so the 1m50s gap is the runner: in the bats log, context (no plugin call, no code from this PR on its path) took 13.0 s and then 10.4 s. #165's job in the same window took 7m58s.

Per-command cost, one quick check on box2 (debug builds of #165 a40f382 and this head, same machine, 20 interleaved runs each, median wall time, 3-repo workspace):

Command #165 #166 Difference
meta --version 3.2 ms 3.4 ms +0.2
meta context 10.3 ms 9.7 ms −0.6
meta -r project list (a plugin call) 10.1 ms 10.6 ms +0.5
meta git status (a plugin call) 15.2 ms 15.3 ms +0.1

No cost found beyond noise, so no fix: commands that start no plugin run none of this PR's code, and a plugin call adds a FIFO, a reader thread and a wake-up at its end (cae59c9 removed the up-to-10 ms wait there). Not measured on macOS itself (no Mac here). Owner decision: the slowdown is accepted for now; these numbers are a note for the later performance pass.

Also carries #165's a40f382 (meta#161's three round-6 must-fixes), so this branch holds them too.

Not verified

Windows (CI's job is the check; meta_plugin and loop_lib were checked for x86_64-pc-windows-gnu on box2). MCP progress (PR 10) and output = "stream" (PR 5a) are later PRs.

Try it

cd ~/code/gitkb-dev/harmony/open-source/meta && git fetch origin && git checkout feat/stream-events && make install
cd ~/code/gitkb-dev/harmony && meta --json-stream exec -- git rev-parse --short HEAD

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…olved invocation

Every `meta --json` command prints one Envelope (`meta_plugin::Envelope`):
success, command, results (one row per repo a step ran in, or per record a
command returned), skipped, warnings, message and error with a code from a
closed set. The 27 JSON shapes are gone, and so is loop_lib's JsonOutput.
`meta --fields a,b.c --json` keeps only those fields of each row.

The host resolves each invocation once and sends plugins a Request: cwd,
the workspace (root, config, listed root, members, worktree dir and hooks),
the scope, the worktree set, the selected projects (name, path, abs, repo,
tags, depends_on, present, nested), depth, plugin and data dirs and a closed
`meta` of options. Plugins stop finding the workspace from the process's
working directory, so --config and --primary reach every command. Paths
that aren't UTF-8 cross the wire (path_bytes in the Envelope).

Plugins answer with one Response (plan, results, message, delegate or
error, each with warnings and skipped); the request and response travel in
files (META_REQUEST, META_RESPONSE), so a plugin keeps the terminal and
never prints JSON. Plan steps take ok_codes and secret_env; ErrorCode gains
auth, network, rate-limited (retry_after) and failed.

meta-git, meta-project, meta-cargo and meta-mcp are ported; docs, skills
and tests read the Envelope.
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

  • Run on-demand review

This review includes 86 billable files and costs up to $21.50.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 59 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 111 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Team
  • Run ID: 14758992-c1a5-426a-bdf2-f7de6dd81307
Commits

Reviewing files that changed from the base of the PR and between b5d4f72 and cae59c9.

Files ignored due to path filters: 1

  • Cargo.lock is excluded by !**/*.lock
Files selected for processing: 86

  • README.md
  • claude-plugin/skills/meta-exec/SKILL.md
  • claude-plugin/skills/meta-plugins/SKILL.md
  • docs/advanced_usage.md
  • docs/architecture_overview.md
  • docs/faq_troubleshooting.md
  • docs/plugin_development.md
  • loop_cli/src/main.rs
  • loop_lib/src/lib.rs
  • loop_lib/src/tests.rs
  • meta_cli/Cargo.toml
  • meta_cli/src/context.rs
  • meta_cli/src/events.rs
  • meta_cli/src/invoke.rs
  • meta_cli/src/main.rs
  • meta_cli/src/report.rs
  • meta_cli/src/run_list.rs
  • meta_cli/src/shipped-skills.txt
  • meta_cli/src/subprocess_plugins.rs
  • meta_cli/tests/checkout.rs
  • meta_cli/tests/docs.rs
  • meta_cli/tests/git_env.rs
  • meta_cli/tests/hints.rs
  • meta_cli/tests/plugin_discovery.rs
  • meta_cli/tests/plugin_routing.rs
  • meta_cli/tests/single_source.rs
  • meta_core/src/repo_filter.rs
  • meta_core/src/worktree.rs
  • meta_git_cli/src/clone.rs
  • meta_git_cli/src/clone_missing.rs
  • meta_git_cli/src/commands/worktree/add.rs
  • meta_git_cli/src/commands/worktree/cli_types.rs
  • meta_git_cli/src/commands/worktree/create.rs
  • meta_git_cli/src/commands/worktree/diff.rs
  • meta_git_cli/src/commands/worktree/exec.rs
  • meta_git_cli/src/commands/worktree/list.rs
  • meta_git_cli/src/commands/worktree/mod.rs
  • meta_git_cli/src/commands/worktree/prune.rs
  • meta_git_cli/src/commands/worktree/remove.rs
  • meta_git_cli/src/commands/worktree/status.rs
  • meta_git_cli/src/commit.rs
  • meta_git_cli/src/helpers.rs
  • meta_git_cli/src/lib.rs
  • meta_git_cli/src/main.rs
  • meta_git_cli/src/ssh.rs
  • meta_git_cli/src/update.rs
  • meta_git_cli/tests/arguments.rs
  • meta_git_cli/tests/races.rs
  • meta_git_cli/tests/recursive_inventory.rs
  • meta_git_cli/tests/safety.rs
  • meta_git_lib/src/worktree/helpers.rs
  • meta_git_lib/src/worktree/types.rs
  • meta_mcp/Cargo.toml
  • meta_mcp/src/tools.rs
  • meta_mcp/tests/cli.rs
  • meta_plugin/Cargo.toml
  • meta_plugin/examples/meta-hello.rs
  • meta_plugin/src/args.rs
  • meta_plugin/src/envelope.rs
  • meta_plugin/src/event.rs
  • meta_plugin/src/exit.rs
  • meta_plugin/src/lib.rs
  • meta_plugin/src/out.rs
  • meta_plugin/src/process.rs
  • meta_plugin/src/request.rs
  • meta_plugin/src/response.rs
  • meta_plugin/src/serve.rs
  • meta_plugin/src/testing.rs
  • meta_plugin/src/wire_path.rs
  • meta_plugin/tests/example_plugin.rs
  • meta_project_cli/Cargo.toml
  • meta_project_cli/src/lib.rs
  • meta_project_cli/src/main.rs
  • meta_rust_cli/src/lib.rs
  • meta_rust_cli/src/main.rs
  • tests/context.bats
  • tests/dry_run.bats
  • tests/exec.bats
  • tests/git.bats
  • tests/mcp.bats
  • tests/plugin_install.bats
  • tests/project_list.bats
  • tests/url_credentials.bats
  • tests/worktree.bats
  • tests/worktree_cloud.bats
  • tests/worktree_edge_cases.bats
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@gold-silver-copper
gold-silver-copper force-pushed the feat/stream-events branch 2 times, most recently from 377e4f2 to e0349a4 Compare November 4, 2026 22:34
- `meta -rv git clone URL d --meta-depth 1` suggested
  `meta -rv -r --depth 1 ...`, which clap refuses (-r twice). Whether -r
  or --depth was typed before the command is now read cluster-aware
  (MetaOptions::typed_has), so `-rv` counts as -r.
- From a nested meta repo, `meta -r --tag backend --exclude api exec`
  said it "names a repo outside" and gave an -A line that runs in repos
  nobody named, whenever -A's selection succeeded. The -A tip now comes
  only when one --include/--exclude value or --tag names nothing where
  -r starts but something -A reaches; it says "a repo or tag".
- `meta project lsit --json` suggested `meta project list --json`, which
  fails, and `meta --json project lsit` dropped --json. The near-miss line
  now keeps meta's options typed before the command and moves the ones
  typed after it there (MetaOptions::lift).

Each has a test that fails without the fix.

Fixes the round-6 must-fixes of [[tasks/harmony-3074]].
…; --json-stream

A plugin writes events (meta_plugin::Event: record, progress, warning) to
the file META_EVENTS names, one JSON line each, at most 64 KiB; in Rust
through Ctx::{emit, record, progress}. On Unix it is a FIFO meta reads as
it goes, so a writer waits while meta is behind; on Windows a file meta
follows. meta shows records and warnings as they arrive (progress on a
terminal only), folds them into its one Envelope under --json, and under
the new --json-stream prints one {"event": …} line each, a step event as
each step of a plan ends, then {"envelope": …} as the last line. A plugin
that writes a step event, an unreadable line or one too long fails with
plugin-failed. Programs a plugin starts never get META_REQUEST,
META_RESPONSE or META_EVENTS.
@gold-silver-copper

Copy link
Copy Markdown
Contributor Author

Folded into gitkb/meta#165

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant