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
// Copyright (c) 2025, 2026 Julius ML
// Licensed under the MIT License. See LICENSE at the workspace root.
//! HTTP / gRPC / SSE / stdio daemon for post-cortex.
//!
//! Hosts:
//!
//! - the **rmcp Model Context Protocol** surface (streaming-HTTP +
//! stdio transports) via [`daemon::rmcp_server`] and
//! [`daemon::mcp_service`];
//! - the **tonic gRPC API** (canonical post-cortex wire surface) via
//! [`daemon::grpc_service`];
//! - the **axum HTTP server** with REST endpoints for the `pcx` CLI
//! client and the Server-Sent Events broadcast plumbing via
//! [`daemon::server`] and [`daemon::sse`];
//! - the **stdio bridge** that lets MCP hosts spawn the daemon as a
//! child process via [`daemon::stdio_proxy`];
//! - the unified **`pcx` CLI binary** (`[[bin]]`) under `src/bin/pcx`.
//!
//! The daemon owns no domain logic — every read / write / search /
//! manage operation delegates downward into
//! [`post_cortex_memory::ConversationMemorySystem`] (and, from Phase 7
//! onwards, through the
//! [`post_cortex_core::services::PostCortexService`] trait). Validation
//! that was historically duplicated between the gRPC and MCP layers
//! migrates to the trait impl in `post-cortex-memory::MemoryServiceImpl`.
// rustdoc::broken_intra_doc_links is warned (not denied) for the daemon
// because the migrated grpc_service / mcp_service files carry historical
// `[private_item]` references; cleanup is Phase 12 follow-up after the
// transport handlers migrate to call PostCortexService.
// The daemon's only unsafe is in two test cases that exercise env var
// overrides for DaemonConfig (`set_var` / `remove_var` are `unsafe fn`
// since Rust 1.85 because env mutation is racy in multi-threaded
// programs). Both blocks are gated under #[cfg(test)] and serialised by
// the test framework, so we relax `forbid` to `deny` and let those two
// blocks opt in via `#[allow(unsafe_code)]`.
// CoercionError carries rich context (path, expected type, hint, source)
// so consumers can render actionable validation messages. The lint
// flags every Result<_, CoercionError> as "Err variant very large", but
// boxing it would defeat the design — accept the warning at crate level.
// Some daemon types (CoerceFn signatures, gRPC handler tuples) are
// intentionally complex; refactoring them into separate type aliases
// would obscure the call site without changing behaviour.
// gRPC handler match arms include a wildcard branch even when the
// variants are exhaustive — leaving it in keeps the handlers
// forward-compatible if new request types land.
// Some pcx CLI handlers take many tuple-shaped command-line args.
/// Error types for the daemon crate.
pub use DaemonConfig;
pub use ;