context_bar/lib.rs
1//! ContextBar — Zed extension entry point + engine re-exports.
2//!
3//! The reusable engine now lives in the `context-bar-core` crate. This crate
4//! is the thin host layer: it re-exports the engine modules under their
5//! historical paths (so `context_bar::usage_signal`, `crate::context_engine`,
6//! … keep resolving for the CLI binary, the example, and the wasm glue below)
7//! and adds the Zed extension surface.
8//!
9//! ## Verified
10//! - Extension loads in Zed Preview.
11//! - `process:exec` can shell out to `git` inside the worktree.
12//! - Engine writes `.context-bar/{state.json,brief-*.md,AGENT.md}` artifacts.
13//! - `run_slash_command` receives a `Worktree` and is the strongest verified
14//! hook to wire automatic refresh into.
15//!
16//! ## Unverified / explicitly isolated behind seams
17//! - Zed has no public always-on HUD primitive yet. The HUD layer is expected
18//! to consume `state.json` directly when a hook exists.
19//! - `zed_extension_api` 0.7 exposes no load-time or worktree-open hook, so
20//! the first refresh fires on the first agent interaction that reaches the
21//! extension (any slash command). After that, [`auto_refresh::refresh`]
22//! keeps the surface fresh idempotently. Once a real load hook ships, the
23//! call site moves; the function does not.
24//! - Codex ACP threads in Zed Preview do not currently invoke extension slash
25//! commands. Agents are therefore expected to read `.context-bar/AGENT.md`
26//! from the filesystem (Codex/Claude conventions) until a richer
27//! automatic-context hook is verified.
28//! - The seam for both cases is [`context_engine::assemble`], which takes
29//! pre-collected signals and is decoupled from `zed::Worktree`.
30
31// Engine, re-exported under the historical module paths so existing consumers
32// (`context_bar::<mod>` in the bin/example, `crate::<mod>` in the wasm glue)
33// need no import changes after the workspace split.
34pub use context_bar_core::{
35 agent_context, context_engine, detail_html, git_signal, hud, i18n, live, report, state_writer,
36 time_windows, usage_signal,
37};
38
39// CLI-only engine module (see context-bar-core); excluded from the wasm extension.
40#[cfg(not(target_arch = "wasm32"))]
41pub use context_bar_core::claude_statusline;
42
43#[cfg(target_arch = "wasm32")]
44pub mod auto_refresh;
45
46#[cfg(target_arch = "wasm32")]
47mod slash_commands;
48
49#[cfg(target_arch = "wasm32")]
50mod extension {
51 use super::{auto_refresh, slash_commands};
52 use zed_extension_api::{self as zed, Result};
53
54 struct ContextHud;
55
56 impl zed::Extension for ContextHud {
57 fn new() -> Self {
58 Self
59 }
60
61 fn run_slash_command(
62 &self,
63 command: zed::SlashCommand,
64 _args: Vec<String>,
65 worktree: Option<&zed::Worktree>,
66 ) -> Result<zed::SlashCommandOutput> {
67 // Auto-refresh runs as a side effect of any worktree-bearing
68 // entry point so the agent-visible artifacts stay current without
69 // the user explicitly invoking a command. Idempotent and cheap.
70 if let Some(worktree) = worktree {
71 auto_refresh::refresh(worktree);
72 }
73 slash_commands::run(command, worktree)
74 }
75 }
76
77 zed::register_extension!(ContextHud);
78}