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
use clap::{Parser, Subcommand};
use dkp_core::config::DkpConfig;
use crate::output::OutputFormat;
/// Global flags extracted from `Cli` and passed into every command handler.
/// Separating this from `Cli` avoids borrow-after-partial-move in the dispatch match.
#[allow(dead_code)]
pub struct CmdCtx {
pub output: OutputFormat,
pub quiet: bool,
pub verbose: bool,
pub audience: Option<String>,
pub config: DkpConfig,
}
/// dkp — Domain Knowledge Pack management CLI
#[derive(Parser, Debug)]
#[command(
name = "dkp",
version,
about = "Manage, inspect, search, and deploy Domain Knowledge Packs",
propagate_version = true
)]
pub struct Cli {
/// Output format
#[arg(long, global = true, default_value = "plain", value_enum)]
pub output: OutputFormat,
/// Suppress informational output; print only results
#[arg(long, short = 'q', global = true)]
pub quiet: bool,
/// Print debug info (schema paths, provider calls, etc.)
#[arg(long, short = 'v', global = true)]
pub verbose: bool,
/// Filter content to assets tagged for a specific audience profile
#[arg(long, global = true, value_name = "ID")]
pub audience: Option<String>,
#[command(subcommand)]
pub command: Commands,
}
impl Cli {
/// Extract a `CmdCtx` from the parsed CLI, consuming the global flags.
/// Called before matching on `command` to avoid partial-move issues.
pub fn ctx(&self) -> CmdCtx {
CmdCtx {
output: self.output,
quiet: self.quiet,
verbose: self.verbose,
audience: self.audience.clone(),
config: DkpConfig::load(),
}
}
}
#[derive(Subcommand, Debug)]
pub enum Commands {
// ── Producer: Pack authoring ────────────────────────────────────────────
/// Scaffold a new DKP pack directory with all required files
Init(crate::cmd::init::InitArgs),
// ── Phase 1: Offline ────────────────────────────────────────────────────
/// Print a summary of a pack (name, version, asset counts, compliance)
Info(crate::cmd::info::InfoArgs),
/// List all packs under a root directory
List(crate::cmd::list::ListArgs),
/// Run schema and compliance checks; exit non-zero on failure
Validate(crate::cmd::validate::ValidateArgs),
/// Full-text BM25 search across machine assets (or registry with --registry)
Search(crate::cmd::search::SearchArgs),
/// Retrieve a specific asset or all assets of a type
Get(crate::cmd::get::GetArgs),
/// Print a ready-to-inject LLM context block
Inject(crate::cmd::inject::InjectArgs),
/// Convert machine assets to another format (okf, langchain, llamaindex, …)
Export(crate::cmd::export::ExportArgs),
/// OKF-specific operations (export, validate, stats, links, browse)
Okf(crate::cmd::okf::OkfArgs),
/// Retrieve the top-N most relevant retrieval chunks for a query
Chunk(crate::cmd::chunk::ChunkArgs),
// ── Phase 2: LLM-assisted ───────────────────────────────────────────────
/// Run eval set against baseline and grounded prompts; print delta report
Eval(crate::cmd::eval::EvalArgs),
/// Interactive grounded prompt REPL for testing a pack
Prompt(crate::cmd::prompt::PromptArgs),
/// Compare two pack versions and report what changed
Diff(crate::cmd::diff::DiffArgs),
// ── Phase 3: Producer tooling ───────────────────────────────────────────
/// Package a pack into a versioned archive with checksums.json
Build(crate::cmd::build::BuildArgs),
/// Pre-release compliance checklist (runs all gates, checks human fields)
#[command(name = "release-check")]
ReleaseCheck(crate::cmd::release_check::ReleaseCheckArgs),
/// Source and rights log operations
Rights(crate::cmd::rights::RightsArgs),
// ── Phase 4: MCP + TUI ──────────────────────────────────────────────────
/// Generate or regenerate machine/mcp_manifest.json
#[command(name = "mcp-manifest")]
McpManifest(crate::cmd::mcp_manifest::McpManifestArgs),
/// Start the pack as an MCP server (requires --features mcp)
#[cfg(feature = "mcp")]
Serve(crate::cmd::serve::ServeArgs),
/// Interactive TUI browser (requires --features tui)
#[cfg(feature = "tui")]
Tui(crate::cmd::tui::TuiArgs),
/// Browse a pack in a local web UI (requires --features webui)
#[cfg(feature = "webui")]
Webui(crate::cmd::webui::WebuiArgs),
// ── Procedures ─────────────────────────────────────────────────────────
/// Invoke a WASM/WASI procedure from machine/procedures/
Run(crate::cmd::run::RunArgs),
/// List, validate, and scaffold executable procedures
Procedures(crate::cmd::procedures::ProceduresArgs),
// ── Phase 5: Spec-derived ───────────────────────────────────────────────
/// Inspect and validate knowledge_graph.json
Graph(crate::cmd::graph::GraphArgs),
/// Inspect and validate cross_refs.json
#[command(name = "cross-refs")]
CrossRefs(crate::cmd::cross_refs::CrossRefsArgs),
/// Manage and validate the skills/ layer
Skills(crate::cmd::skills::SkillsArgs),
/// Manage and validate the l10n/ localization layer
L10n(crate::cmd::l10n::L10nArgs),
// ── Generation ─────────────────────────────────────────────────────────
/// Scaffold + LLM-generate a complete pack in one command
New(crate::cmd::new::NewArgs),
/// Run (or re-run) LLM generation on an existing pack
Generate(crate::cmd::generate::GenerateArgs),
/// Failure-aware chunk regeneration using eval results
Fix(crate::cmd::fix::FixArgs),
/// Generate evidence drafts for manual review gates
Review(crate::cmd::review::ReviewArgs),
// ── Phase 6: Registry ───────────────────────────────────────────────────
/// Generate an Ed25519 keypair for signing packs
Keygen(crate::cmd::keygen::KeygenArgs),
/// Sign a built archive with an Ed25519 private key
Sign(crate::cmd::sign::SignArgs),
/// Install a pack from the registry
Install(crate::cmd::registry::install::InstallArgs),
/// Remove an installed pack
Uninstall(crate::cmd::registry::uninstall::UninstallArgs),
/// Re-resolve and update installed packs to satisfy lock-file constraints
Update(crate::cmd::registry::update::UpdateArgs),
/// Publish a built and signed pack to the registry
Publish(crate::cmd::registry::publish::PublishArgs),
/// Mark a published version as yanked
Yank(crate::cmd::registry::yank::YankArgs),
/// Registry account and pack management (login, logout, keys, access)
Registry(crate::cmd::registry::account::RegistryArgs),
}