M0: compilable skeleton — Kigi 0.1.0 fork surgery
Hard fork of xai-org/grok-build (Apache-2.0) re-targeted as Kigi, an
unofficial Kimi Code CLI community build.
Rename & identity
- 72 xai-*/xai-grok-* crates -> kigi-* (explicit: xai-grok-pager-bin ->
kigi-bin [binary `kigi`], xai-grok-pager -> kigi-tui; rest mechanical);
ptyctl, ptyctl-cli, third_party/ unchanged; proto package
xai.grok.tools.v1 -> kigi.tools.v1
- Config home ~/.kigi (KIGI_SHARE_DIR override), env prefix GROK_* ->
KIGI_*, `kigi --version` carries the unofficial-community-build notice
- clap identity, help text, startup banner, prompt templates rebranded
(templates re-encrypted)
Deletions (PRD removal list #5/#6/#7/#9/#10)
- voice input (xai-grok-voice) and all TUI wiring
- telemetry: Mixpanel client, external OTel stream, Sentry, OTLP layers,
trace/GCS/S3 upload queues (kigi-file-utils halved), workspace upload
module & dc_log, heap-profile uploader, auth-diagnostics uploader,
session-analytics halves of feedback; local zero-egress observability
preserved in new kigi-log crate (unified log, --debug firehose,
subsystem file logs, opt-in instrumentation)
- announcements (crate, remote-settings fields, TUI surfaces)
- plugin marketplace (crate, sources/browse/CTA/extensions-modal tab);
direct plugin install/uninstall/update via kigi-agent git_install kept
- relay/gateway/assets endpoints and features (agent relay, headless
relay transport, gateway bridge, LeaderEnvUrls); leader IPC socket now
~/.kigi/leader.sock + KIGI_LEADER_SOCKET, no ws-url derivation
- functional types rehomed instead of deleted: PermissionMode ->
kigi-config-types, McpInitStrategy -> kigi-mcp, PrCreationSource ->
session signals, TerminalDiagnostics -> kigi-pager-render, agent_id ->
shell util
Endpoints
- kigi-env rewritten: single production KigiEndpoints {coding_api_base_url
https://api.kimi.com/coding/v1 (KIGI_CODE_BASE_URL), oauth_host
https://auth.kimi.com (KIGI_OAUTH_HOST), update_base_url (GitHub
Releases API), upgrade_page_url}; GrokBuildEnvironment enum deleted
Toolchain & workspace hygiene
- Rust 1.97.0 pinned; edition 2024; full cargo update; git2 hoisted to
workspace at 0.21 (Option->Result API migration), quick-xml 0.41
- Root Cargo.toml hand-maintained (PRD §8.1): version 0.1.0 inherited by
all members, members sorted, unused deps pruned
- cargo-deny advisories gate (deny.toml with documented transitive
exceptions); CI workflow (check/clippy/fmt/deny/test, macOS+Linux)
- cross-crate test seams re-gated behind `test-support` cargo feature;
insta snapshot baselines renamed to the kigi_tui prefix
- clippy --workspace --all-targets: zero warnings; fmt clean
Fixes surfaced by the port
- updater probe/installer divergence (bin/kigi vs bin/grok symlink set)
- idle model-metadata refresh dead under KIGI_CODE_BASE_URL override
(new is_effective_coding_endpoint_url, loopback+override aware)
- macOS symlinked-TMPDIR fixture canonicalization (foreign_sessions,
fast-worktree); RSS measurement tests serialized via serial_test
Docs & legal (Apache §4)
- NOTICE added (upstream attribution + change statement); THIRD-PARTY
notices sustained; kigi-tools ported-code notices extended; README,
CONTRIBUTING, SECURITY, AGENTS.md rewritten
Out of scope for M0 (tracked): Kimi auth/inference (M1), search/fetch,
command parity, config import (M2), Computer Hub excision & final
brand-token sweep (M2), distribution & self-update rewrite (M3).
This commit is contained in:
@@ -0,0 +1,404 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct NotificationConfig {
|
||||
pub method: NotificationMethod,
|
||||
pub condition: NotificationCondition,
|
||||
pub idle_threshold_secs: u64,
|
||||
pub events: Vec<NotificationEventKind>,
|
||||
pub sleep_prevention: bool,
|
||||
pub progress_bar: bool,
|
||||
/// Show an automatic "where was I" session recap when you return to the
|
||||
/// terminal after being away. Only applies when the shell has rolled out
|
||||
/// session recap (`sessionRecap` on ACP initialize / remote settings). Manual
|
||||
/// `/recap` is gated by the shell flag alone, not this toggle.
|
||||
pub session_recap: bool,
|
||||
/// Minimum seconds the terminal must be unfocused ("stepped away") before
|
||||
/// the client requests an automatic recap. A short debounce against quick
|
||||
/// tab blips; the authoritative timing ("≥3 min since the last completed
|
||||
/// turn") is enforced agent-side.
|
||||
pub session_recap_threshold_secs: u64,
|
||||
pub title: TitleConfig,
|
||||
pub hooks: Vec<NotificationHook>,
|
||||
}
|
||||
|
||||
impl Default for NotificationConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
method: NotificationMethod::default(),
|
||||
condition: NotificationCondition::default(),
|
||||
idle_threshold_secs: 3,
|
||||
events: vec![
|
||||
NotificationEventKind::TurnComplete,
|
||||
NotificationEventKind::ApprovalRequired,
|
||||
],
|
||||
sleep_prevention: true,
|
||||
progress_bar: true,
|
||||
session_recap: true,
|
||||
session_recap_threshold_secs: 30,
|
||||
title: TitleConfig::default(),
|
||||
hooks: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum NotificationMethod {
|
||||
#[default]
|
||||
Auto,
|
||||
Osc9,
|
||||
Osc99,
|
||||
Osc777,
|
||||
Bel,
|
||||
None,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum NotificationCondition {
|
||||
#[default]
|
||||
Unfocused,
|
||||
Always,
|
||||
Never,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct TitleConfig {
|
||||
pub enabled: bool,
|
||||
pub items: Vec<TitleItem>,
|
||||
}
|
||||
|
||||
impl Default for TitleConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
enabled: true,
|
||||
items: vec![
|
||||
TitleItem::ActionRequired,
|
||||
TitleItem::Spinner,
|
||||
TitleItem::Activity,
|
||||
TitleItem::SessionName,
|
||||
TitleItem::Grok,
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum TitleItem {
|
||||
Spinner,
|
||||
Activity,
|
||||
SessionName,
|
||||
Cwd,
|
||||
Model,
|
||||
TurnTimer,
|
||||
Grok,
|
||||
ActionRequired,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum NotificationEventKind {
|
||||
TurnComplete,
|
||||
ApprovalRequired,
|
||||
SessionReady,
|
||||
TaskComplete,
|
||||
AgentError,
|
||||
}
|
||||
|
||||
impl NotificationEventKind {
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
Self::TurnComplete => "Turn complete",
|
||||
Self::ApprovalRequired => "Approval required",
|
||||
Self::SessionReady => "Session ready",
|
||||
Self::TaskComplete => "Task complete",
|
||||
Self::AgentError => "Agent error",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub struct NotificationHook {
|
||||
pub command: String,
|
||||
#[serde(default)]
|
||||
pub events: Vec<NotificationEventKind>,
|
||||
#[serde(default = "default_only_unfocused")]
|
||||
pub only_unfocused: bool,
|
||||
#[serde(default = "default_hook_timeout")]
|
||||
pub timeout_secs: u64,
|
||||
}
|
||||
|
||||
fn default_only_unfocused() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn default_hook_timeout() -> u64 {
|
||||
10
|
||||
}
|
||||
|
||||
impl NotificationConfig {
|
||||
/// Generate a commented TOML template for the `[ui.notifications]` section.
|
||||
///
|
||||
/// Mirrors the pattern used by `RawAppearanceConfig::to_toml_with_comments()`
|
||||
/// for `pager.toml`. The output is suitable for inclusion in documentation
|
||||
/// or as a starter config snippet.
|
||||
pub fn to_toml_with_comments() -> String {
|
||||
"\
|
||||
[ui.notifications]
|
||||
# Notification protocol: auto|osc9|osc99|osc777|bel|none
|
||||
# \"auto\" selects the best protocol for your terminal.
|
||||
method = \"auto\"
|
||||
# When to notify: unfocused|always|never
|
||||
# \"unfocused\" only fires when the terminal has lost focus.
|
||||
condition = \"unfocused\"
|
||||
# Minimum seconds the terminal must be unfocused before notifications fire.
|
||||
idle_threshold_secs = 3
|
||||
# Events that trigger notifications.
|
||||
# Options: turn_complete, approval_required, session_ready, task_complete, agent_error
|
||||
events = [\"turn_complete\", \"approval_required\"]
|
||||
# Prevent display sleep during agent turns (macOS/Linux).
|
||||
sleep_prevention = true
|
||||
# Show a progress indicator in the terminal tab (OSC 9;4).
|
||||
progress_bar = true
|
||||
# Show an automatic \"where was I\" session recap when you return after being away.
|
||||
# Shell session_recap is on by default; disable via [features] session_recap or
|
||||
# KIGI_SESSION_RECAP=0. Manual /recap uses only the shell flag.
|
||||
session_recap = true
|
||||
# Minimum seconds unfocused (\"stepped away\") before requesting a recap; a
|
||||
# debounce against quick tab blips. The \"3 min since the last turn\" timing is
|
||||
# enforced agent-side.
|
||||
session_recap_threshold_secs = 30
|
||||
|
||||
[ui.notifications.title]
|
||||
# Set the terminal/tab title to reflect agent state.
|
||||
enabled = true
|
||||
# Items shown in the title. Options: action-required, spinner, activity,
|
||||
# session-name, cwd, model, turn-timer, grok
|
||||
items = [\"action-required\", \"spinner\", \"activity\", \"session-name\", \"grok\"]
|
||||
|
||||
# [[ui.notifications.hooks]]
|
||||
# command = \"terminal-notifier -title 'Grok' -message '$KIGI_MESSAGE'\"
|
||||
# events = [\"turn_complete\", \"approval_required\"]
|
||||
# only_unfocused = true
|
||||
# timeout_secs = 10
|
||||
"
|
||||
.to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn config_round_trips_through_toml() {
|
||||
let config = NotificationConfig {
|
||||
method: NotificationMethod::Osc99,
|
||||
condition: NotificationCondition::Always,
|
||||
idle_threshold_secs: 10,
|
||||
events: vec![
|
||||
NotificationEventKind::TurnComplete,
|
||||
NotificationEventKind::AgentError,
|
||||
],
|
||||
sleep_prevention: false,
|
||||
progress_bar: false,
|
||||
session_recap: false,
|
||||
session_recap_threshold_secs: 90,
|
||||
title: TitleConfig {
|
||||
enabled: false,
|
||||
items: vec![TitleItem::Grok, TitleItem::Cwd],
|
||||
},
|
||||
hooks: vec![NotificationHook {
|
||||
command: "notify-send".into(),
|
||||
events: vec![NotificationEventKind::TurnComplete],
|
||||
only_unfocused: false,
|
||||
timeout_secs: 5,
|
||||
}],
|
||||
};
|
||||
|
||||
let toml_str = toml::to_string(&config).expect("serialize");
|
||||
let parsed: NotificationConfig = toml::from_str(&toml_str).expect("deserialize");
|
||||
|
||||
assert_eq!(config, parsed);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_fields_use_defaults() {
|
||||
let parsed: NotificationConfig = toml::from_str("").expect("deserialize empty");
|
||||
|
||||
assert_eq!(parsed.method, NotificationMethod::Auto);
|
||||
assert_eq!(parsed.condition, NotificationCondition::Unfocused);
|
||||
assert_eq!(parsed.idle_threshold_secs, 3);
|
||||
assert_eq!(
|
||||
parsed.events,
|
||||
vec![
|
||||
NotificationEventKind::TurnComplete,
|
||||
NotificationEventKind::ApprovalRequired,
|
||||
]
|
||||
);
|
||||
assert!(parsed.sleep_prevention);
|
||||
assert!(parsed.progress_bar);
|
||||
assert!(parsed.session_recap);
|
||||
assert_eq!(parsed.session_recap_threshold_secs, 30);
|
||||
assert!(parsed.title.enabled);
|
||||
assert!(parsed.hooks.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn partial_toml_merges_with_defaults() {
|
||||
let toml_str = r#"
|
||||
method = "bel"
|
||||
idle_threshold_secs = 60
|
||||
"#;
|
||||
let parsed: NotificationConfig = toml::from_str(toml_str).expect("deserialize partial");
|
||||
|
||||
assert_eq!(parsed.method, NotificationMethod::Bel);
|
||||
assert_eq!(parsed.idle_threshold_secs, 60);
|
||||
// Rest should be defaults
|
||||
assert_eq!(parsed.condition, NotificationCondition::Unfocused);
|
||||
assert!(parsed.sleep_prevention);
|
||||
assert!(parsed.progress_bar);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hook_defaults_applied() {
|
||||
let toml_str = r#"
|
||||
[[hooks]]
|
||||
command = "my-script.sh"
|
||||
"#;
|
||||
let parsed: NotificationConfig = toml::from_str(toml_str).expect("deserialize hooks");
|
||||
|
||||
assert_eq!(parsed.hooks.len(), 1);
|
||||
let hook = &parsed.hooks[0];
|
||||
assert_eq!(hook.command, "my-script.sh");
|
||||
assert!(hook.events.is_empty());
|
||||
assert!(hook.only_unfocused);
|
||||
assert_eq!(hook.timeout_secs, 10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_notification_methods_deserialize() {
|
||||
for (input, expected) in [
|
||||
("\"auto\"", NotificationMethod::Auto),
|
||||
("\"osc9\"", NotificationMethod::Osc9),
|
||||
("\"osc99\"", NotificationMethod::Osc99),
|
||||
("\"osc777\"", NotificationMethod::Osc777),
|
||||
("\"bel\"", NotificationMethod::Bel),
|
||||
("\"none\"", NotificationMethod::None),
|
||||
] {
|
||||
let parsed: NotificationMethod = toml::from_str(&format!("method = {input}\n"))
|
||||
.map(|c: MethodWrapper| c.method)
|
||||
.unwrap_or_else(|e| panic!("failed to parse {input}: {e}"));
|
||||
assert_eq!(parsed, expected, "mismatch for {input}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_conditions_deserialize() {
|
||||
for (input, expected) in [
|
||||
("\"unfocused\"", NotificationCondition::Unfocused),
|
||||
("\"always\"", NotificationCondition::Always),
|
||||
("\"never\"", NotificationCondition::Never),
|
||||
] {
|
||||
let parsed: NotificationCondition = toml::from_str(&format!("condition = {input}\n"))
|
||||
.map(|c: ConditionWrapper| c.condition)
|
||||
.unwrap_or_else(|e| panic!("failed to parse {input}: {e}"));
|
||||
assert_eq!(parsed, expected, "mismatch for {input}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn title_items_kebab_case() {
|
||||
let toml_str = r#"
|
||||
[title]
|
||||
enabled = true
|
||||
items = ["action-required", "turn-timer", "session-name"]
|
||||
"#;
|
||||
let parsed: NotificationConfig = toml::from_str(toml_str).expect("deserialize");
|
||||
assert_eq!(
|
||||
parsed.title.items,
|
||||
vec![
|
||||
TitleItem::ActionRequired,
|
||||
TitleItem::TurnTimer,
|
||||
TitleItem::SessionName,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn to_toml_with_comments_contains_all_sections() {
|
||||
let toml = NotificationConfig::to_toml_with_comments();
|
||||
assert!(toml.contains("[ui.notifications]"));
|
||||
assert!(toml.contains("[ui.notifications.title]"));
|
||||
assert!(toml.contains("[[ui.notifications.hooks]]"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn to_toml_with_comments_matches_defaults() {
|
||||
let template = NotificationConfig::to_toml_with_comments();
|
||||
let defaults = NotificationConfig::default();
|
||||
|
||||
assert!(
|
||||
template.contains(&format!(
|
||||
"idle_threshold_secs = {}",
|
||||
defaults.idle_threshold_secs
|
||||
)),
|
||||
"template idle_threshold_secs does not match default"
|
||||
);
|
||||
assert!(
|
||||
template.contains(&format!("sleep_prevention = {}", defaults.sleep_prevention)),
|
||||
"template sleep_prevention does not match default"
|
||||
);
|
||||
assert!(
|
||||
template.contains(&format!("progress_bar = {}", defaults.progress_bar)),
|
||||
"template progress_bar does not match default"
|
||||
);
|
||||
assert!(
|
||||
template.contains(&format!("enabled = {}", defaults.title.enabled)),
|
||||
"template title.enabled does not match default"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn to_toml_with_comments_hook_section_is_valid_toml() {
|
||||
let template = NotificationConfig::to_toml_with_comments();
|
||||
// Uncomment only TOML structural lines (table headers and key = value).
|
||||
// Doc-comment lines (plain English) are left as comments so they
|
||||
// don't produce parse errors.
|
||||
let uncommented: String = template
|
||||
.lines()
|
||||
.map(|line| {
|
||||
if let Some(stripped) = line.strip_prefix("# ") {
|
||||
let trimmed = stripped.trim_start();
|
||||
if trimmed.starts_with("[[") || trimmed.contains(" = ") {
|
||||
return format!("{stripped}\n");
|
||||
}
|
||||
}
|
||||
format!("{line}\n")
|
||||
})
|
||||
.collect();
|
||||
let parsed: toml::Value =
|
||||
toml::from_str(&uncommented).expect("uncommented template should be valid TOML");
|
||||
let hooks = parsed
|
||||
.get("ui")
|
||||
.and_then(|u| u.get("notifications"))
|
||||
.and_then(|n| n.get("hooks"))
|
||||
.expect("hooks key must exist after uncommenting");
|
||||
assert!(hooks.is_array(), "hooks should be an array of tables");
|
||||
}
|
||||
|
||||
// Helper wrappers for single-field deserialization tests
|
||||
#[derive(Deserialize)]
|
||||
struct MethodWrapper {
|
||||
method: NotificationMethod,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct ConditionWrapper {
|
||||
condition: NotificationCondition,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user