symforge 11.7.0

SymForge — in-memory code intelligence MCP server for Claude Code, Codex, and Gemini CLI
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
//! CLI module — clap Parser types and subcommand dispatch for the `symforge` binary.
//!
//! Subcommands:
//!   `symforge init`               — configure Claude, Codex, or both
//!   `symforge analytics <cmd>`     — inspect or reset local analytics storage
//!   `symforge hook <subcommand>`  — hook scripts called by Claude Code
//!   `symforge daemon`             — shared project/session backend
//!   `symforge trust project-config` — audit, accept, or revoke project-config trust
//!   `symforge update`             — update the npm-managed SymForge install
//!
//! Plan 03 wires these into main.rs and handles the top-level dispatch.

pub mod admin;
pub mod analytics;
pub mod browser;
pub mod entry;
pub mod harness;
pub mod harness_apply;
pub mod harness_command;
pub mod hook;
pub mod init;
pub mod onboarding;
pub mod operator_profile;
pub mod serve;
pub mod setup;
pub mod trust;
pub mod update;
pub mod version;

use clap::{Parser, Subcommand, ValueEnum};

/// Top-level CLI parser for the `symforge` binary.
#[derive(Parser)]
#[command(
    name = "symforge",
    about = "SymForge MCP server and hook system",
    version
)]
pub struct Cli {
    #[command(subcommand)]
    pub command: Option<Commands>,
}

/// Top-level subcommands.
#[derive(Subcommand, Debug)]
pub enum Commands {
    /// Inspect, export, or reset local analytics storage
    Analytics {
        #[command(subcommand)]
        command: analytics::AnalyticsCommand,
    },
    /// Install SymForge integration for one MCP harness, or all installed harnesses
    Init {
        /// Client to configure
        #[arg(long, value_enum, default_value_t = InitClient::All)]
        client: InitClient,

        /// Scan known MCP harness configs and report per-client SymForge attach
        /// status instead of running the stdio install. Non-destructive: with
        /// `--scan` alone (no `--apply`) nothing is written.
        #[arg(long)]
        scan: bool,

        /// With `--scan`, write/refresh the SymForge HTTP attach entry into each
        /// discovered config (backup-then-atomic-write). Requires
        /// `--serve-url`. Without `--apply`, `--scan` is a dry-run preview.
        #[arg(long, requires = "scan")]
        apply: bool,

        /// The `symforge serve` attach URL to write (e.g. `http://127.0.0.1:8787/mcp`).
        #[arg(long, requires = "scan")]
        serve_url: Option<String>,

        /// The Bearer key for the attach URL (omit for a keyless loopback serve).
        #[arg(long, requires = "serve_url")]
        serve_key: Option<String>,
    },
    /// Run the shared local daemon that tracks project and session state
    Daemon,
    /// Serve the MCP surface over Streamable HTTP at `/mcp` (operator server)
    Serve(serve::ServeCliArgs),
    /// Guided operator setup wizard: scan harnesses, configure, start the dashboard
    Setup(setup::SetupCliArgs),
    /// Open (or start + open) the running operator dashboard
    Admin(admin::AdminCliArgs),
    /// Hook subcommands called by Claude Code (PostToolUse / SessionStart / UserPromptSubmit)
    Hook {
        #[command(subcommand)]
        subcommand: Option<HookSubcommand>,
    },
    /// Trust-control commands for project-local SymForge configuration
    Trust {
        #[command(subcommand)]
        subcommand: trust::TrustSubcommand,
    },
    /// Update the npm-managed SymForge install
    Update,
}

/// Supported `symforge init` targets.
#[derive(Clone, Copy, Debug, Eq, PartialEq, ValueEnum)]
pub enum InitClient {
    Claude,
    #[value(name = "claude-desktop", alias = "desktop")]
    ClaudeDesktop,
    Codex,
    Gemini,
    Grok,
    #[value(name = "kilo-code", alias = "kilo")]
    KiloCode,
    Cursor,
    /// Oh My Pi (`omp`). User config is `~/.omp/agent/mcp.json`.
    #[value(name = "omp", alias = "oh-my-pi")]
    Omp,
    /// Cline CLI `~/.cline/mcp.json`. The IDE globalStorage path is UNVERIFIED.
    #[value(name = "cline")]
    Cline,
    /// Roo Code project `.roo/mcp.json`. The global `mcp_settings.json` path is UNVERIFIED.
    #[value(name = "roo")]
    Roo,
    /// VS Code native `.vscode/mcp.json` (`servers`).
    #[value(name = "vscode")]
    VsCode,
    /// VS Code portable user file `~/.copilot/mcp-config.json` (`mcpServers`).
    #[value(name = "copilot", alias = "vscode-portable")]
    Copilot,
    /// Continue drop file `.continue/mcpServers/symforge.json`.
    #[value(name = "continue")]
    Continue,
    All,
}

/// Hook subcommands — one per Claude Code tool event type.
#[derive(Subcommand, Debug, Clone)]
pub enum HookSubcommand {
    /// PostToolUse hook for the Read tool — returns outline for the read file
    Read,
    /// PostToolUse hook for Edit/Write tools — returns impact (dependents) for the edited file
    Edit,
    /// PostToolUse hook for the Write tool — confirms indexing of new file
    Write,
    /// PostToolUse hook for the Grep tool — returns symbol-context for the search query
    Grep,
    /// SessionStart hook — returns repo map for the project
    #[command(name = "session-start")]
    SessionStart,
    /// UserPromptSubmit hook — injects targeted context from file/symbol hints in the prompt
    #[command(name = "prompt-submit")]
    PromptSubmit,
    /// PreToolUse hook — suggests SymForge alternatives before built-in tools execute
    #[command(name = "pre-tool")]
    PreTool,
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_init_defaults_to_all_clients() {
        let cli = Cli::parse_from(["symforge", "init"]);

        match cli.command {
            Some(Commands::Init { client, .. }) => assert_eq!(client, InitClient::All),
            _ => panic!("expected init command"),
        }
    }

    #[test]
    fn test_init_accepts_codex_client() {
        let cli = Cli::parse_from(["symforge", "init", "--client", "codex"]);

        match cli.command {
            Some(Commands::Init { client, .. }) => assert_eq!(client, InitClient::Codex),
            _ => panic!("expected init command"),
        }
    }

    #[test]
    fn test_init_accepts_gemini_client() {
        let cli = Cli::parse_from(["symforge", "init", "--client", "gemini"]);

        match cli.command {
            Some(Commands::Init { client, .. }) => assert_eq!(client, InitClient::Gemini),
            _ => panic!("expected init command"),
        }
    }

    #[test]
    fn test_init_accepts_grok_client() {
        let cli = Cli::try_parse_from(["symforge", "init", "--client", "grok"])
            .expect("grok must be a supported init client");

        match cli.command {
            Some(Commands::Init { client, .. }) => assert_eq!(format!("{client:?}"), "Grok"),
            _ => panic!("expected init command"),
        }
    }

    #[test]
    fn test_init_accepts_kilo_code_client() {
        let cli = Cli::parse_from(["symforge", "init", "--client", "kilo-code"]);

        match cli.command {
            Some(Commands::Init { client, .. }) => assert_eq!(client, InitClient::KiloCode),
            _ => panic!("expected init command"),
        }
    }

    #[test]
    fn test_init_accepts_omp_client() {
        let cli = Cli::parse_from(["symforge", "init", "--client", "omp"]);
        match cli.command {
            Some(Commands::Init { client, .. }) => assert_eq!(client, InitClient::Omp),
            _ => panic!("expected init command"),
        }

        let alias = Cli::parse_from(["symforge", "init", "--client", "oh-my-pi"]);
        match alias.command {
            Some(Commands::Init { client, .. }) => assert_eq!(client, InitClient::Omp),
            _ => panic!("expected init command"),
        }
    }

    #[test]
    fn test_init_accepts_matrix_client_names() {
        for (name, expected) in [
            ("cline", InitClient::Cline),
            ("roo", InitClient::Roo),
            ("vscode", InitClient::VsCode),
            ("copilot", InitClient::Copilot),
            ("vscode-portable", InitClient::Copilot),
            ("continue", InitClient::Continue),
        ] {
            let cli = Cli::parse_from(["symforge", "init", "--client", name]);
            match cli.command {
                Some(Commands::Init { client, .. }) => assert_eq!(client, expected, "{name}"),
                _ => panic!("expected init command"),
            }
        }
    }

    #[test]
    fn test_init_accepts_kilo_alias() {
        let cli = Cli::parse_from(["symforge", "init", "--client", "kilo"]);

        match cli.command {
            Some(Commands::Init { client, .. }) => assert_eq!(client, InitClient::KiloCode),
            _ => panic!("expected init command"),
        }
    }

    #[test]
    fn test_daemon_command_parses() {
        let cli = Cli::parse_from(["symforge", "daemon"]);

        match cli.command {
            Some(Commands::Daemon) => {}
            _ => panic!("expected daemon command"),
        }
    }

    #[test]
    fn test_serve_command_parses_with_defaults() {
        let cli = Cli::parse_from(["symforge", "serve"]);

        match cli.command {
            Some(Commands::Serve(args)) => {
                // No --listen: `listen` is `None` so the US1 free-port fallback
                // applies (prefer the default, else an OS-assigned free port).
                assert_eq!(args.listen, None);
                assert_eq!(args.api_key, None);
                assert_eq!(args.api_key_env, None);
            }
            _ => panic!("expected serve command"),
        }
    }

    #[test]
    fn test_serve_command_parses_flags() {
        let cli = Cli::parse_from([
            "symforge",
            "serve",
            "--listen",
            "0.0.0.0:9000",
            "--api-key-env",
            "SYMFORGE_KEY",
        ]);

        match cli.command {
            Some(Commands::Serve(args)) => {
                assert_eq!(args.listen.as_deref(), Some("0.0.0.0:9000"));
                assert_eq!(args.api_key, None);
                assert_eq!(args.api_key_env.as_deref(), Some("SYMFORGE_KEY"));
            }
            _ => panic!("expected serve command"),
        }
    }

    #[test]
    fn test_analytics_status_command_parses() {
        let cli = Cli::parse_from([
            "symforge",
            "analytics",
            "status",
            "--db-path",
            ".symforge/analytics.db",
        ]);

        match cli.command {
            Some(Commands::Analytics {
                command:
                    analytics::AnalyticsCommand::Status {
                        db_path: Some(db_path),
                    },
            }) => assert_eq!(db_path, std::path::PathBuf::from(".symforge/analytics.db")),
            _ => panic!("expected analytics status command"),
        }
    }

    #[test]
    fn test_hook_prompt_submit_command_parses() {
        let cli = Cli::parse_from(["symforge", "hook", "prompt-submit"]);

        match cli.command {
            Some(Commands::Hook {
                subcommand: Some(HookSubcommand::PromptSubmit),
            }) => {}
            _ => panic!("expected prompt-submit hook command"),
        }
    }

    #[test]
    fn test_hook_pre_tool_command_parses() {
        let cli = Cli::parse_from(["symforge", "hook", "pre-tool"]);

        match cli.command {
            Some(Commands::Hook {
                subcommand: Some(HookSubcommand::PreTool),
            }) => {}
            _ => panic!("expected pre-tool hook command"),
        }
    }

    #[test]
    fn test_trust_project_config_status_command_parses() {
        let cli = Cli::parse_from([
            "symforge",
            "trust",
            "project-config",
            "status",
            "--project",
            ".",
        ]);

        match cli.command {
            Some(Commands::Trust {
                subcommand:
                    trust::TrustSubcommand::ProjectConfig {
                        command: trust::ProjectConfigCommand::Status { project },
                    },
            }) => assert_eq!(project, std::path::PathBuf::from(".")),
            _ => panic!("expected trust project-config status command"),
        }
    }

    #[test]
    fn test_trust_project_config_accept_command_parses() {
        let hash = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
        let cli = Cli::parse_from([
            "symforge",
            "trust",
            "project-config",
            "accept",
            "--project",
            ".",
            "--hash",
            hash,
        ]);

        match cli.command {
            Some(Commands::Trust {
                subcommand:
                    trust::TrustSubcommand::ProjectConfig {
                        command:
                            trust::ProjectConfigCommand::Accept {
                                project,
                                hash: parsed_hash,
                            },
                    },
            }) => {
                assert_eq!(project, std::path::PathBuf::from("."));
                assert_eq!(parsed_hash, hash);
            }
            _ => panic!("expected trust project-config accept command"),
        }
    }

    #[test]
    fn test_update_command_parses() {
        let cli = Cli::parse_from(["symforge", "update"]);

        match cli.command {
            Some(Commands::Update) => {}
            _ => panic!("expected update command"),
        }
    }

    #[test]
    fn test_setup_command_parses_with_defaults() {
        let cli = Cli::parse_from(["symforge", "setup"]);

        match cli.command {
            Some(Commands::Setup(args)) => {
                assert!(!args.non_interactive);
                assert_eq!(args.installation_type, None);
                assert_eq!(args.port, None);
                assert!(args.harnesses.is_empty());
                assert!(!args.yes);
            }
            _ => panic!("expected setup command"),
        }
    }

    #[test]
    fn test_setup_command_parses_flags() {
        let cli = Cli::parse_from([
            "symforge",
            "setup",
            "--non-interactive",
            "--installation-type",
            "both",
            "--port",
            "8787",
            "--harnesses",
            "claude,codex",
            "--yes",
        ]);

        match cli.command {
            Some(Commands::Setup(args)) => {
                assert!(args.non_interactive);
                assert_eq!(args.installation_type, Some(setup::InstallationType::Both));
                assert_eq!(args.port, Some(8787));
                assert_eq!(args.harnesses, vec!["claude", "codex"]);
                assert!(args.yes);
            }
            _ => panic!("expected setup command"),
        }
    }

    #[test]
    fn test_admin_command_parses_with_defaults() {
        let cli = Cli::parse_from(["symforge", "admin"]);

        match cli.command {
            Some(Commands::Admin(args)) => assert!(!args.no_open),
            _ => panic!("expected admin command"),
        }
    }
}