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,403 @@
|
||||
//! Round-trip every `ToolNotification` variant through serde_json and
|
||||
//! assert the wire shape is what consumers expect.
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use kigi_tool_runtime::{
|
||||
BashExecutionBackgrounded, BashExecutionComplete, BashExecutionFailed, BashExecutionTimeout,
|
||||
BashNotificationBase, BashOutputChunk, FileWritten, LspServerCrashed, LspServerFailed,
|
||||
LspServerReady, LspServerRetrying, LspServerStarting, MonitorEvent, PlanModeEntered,
|
||||
PlanModeExited, ScheduledTaskCreated, ScheduledTaskFired, ScheduledTaskRemoved, TaskKind,
|
||||
TaskSnapshot, ToolNotification, UserQuestionAsked,
|
||||
};
|
||||
|
||||
fn base() -> BashNotificationBase {
|
||||
BashNotificationBase {
|
||||
tool_call_id: "call-1".into(),
|
||||
command: "echo hi".into(),
|
||||
output: b"hi\n".to_vec(),
|
||||
total_bytes: 3,
|
||||
truncated: false,
|
||||
cwd: PathBuf::from("/tmp"),
|
||||
}
|
||||
}
|
||||
|
||||
fn round_trip(value: &ToolNotification) -> Value {
|
||||
let json = serde_json::to_value(value).expect("serialize");
|
||||
let back: ToolNotification = serde_json::from_value(json.clone()).expect("deserialize");
|
||||
assert_eq!(*value, back, "round-trip must match");
|
||||
json
|
||||
}
|
||||
|
||||
fn assert_type_tag(json: &Value, expected: &str) {
|
||||
assert_eq!(json["type"], json!(expected), "wire type tag mismatch");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bash_output_chunk_round_trip() {
|
||||
let n = ToolNotification::BashOutputChunk(BashOutputChunk { base: base() });
|
||||
let json = round_trip(&n);
|
||||
assert_type_tag(&json, "BashOutputChunk");
|
||||
assert_eq!(json["command"], json!("echo hi"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bash_execution_complete_round_trip() {
|
||||
let n = ToolNotification::BashExecutionComplete(BashExecutionComplete {
|
||||
base: base(),
|
||||
exit_code: Some(0),
|
||||
signal: None,
|
||||
});
|
||||
let json = round_trip(&n);
|
||||
assert_type_tag(&json, "BashExecutionComplete");
|
||||
assert_eq!(json["exit_code"], json!(0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bash_execution_complete_was_signaled_helper() {
|
||||
let none = BashExecutionComplete {
|
||||
base: base(),
|
||||
exit_code: Some(1),
|
||||
signal: None,
|
||||
};
|
||||
assert!(!none.was_signaled());
|
||||
let killed = BashExecutionComplete {
|
||||
base: base(),
|
||||
exit_code: None,
|
||||
signal: Some("SIGKILL".into()),
|
||||
};
|
||||
assert!(killed.was_signaled());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bash_execution_timeout_round_trip() {
|
||||
let n = ToolNotification::BashExecutionTimeout(BashExecutionTimeout {
|
||||
base: base(),
|
||||
elapsed: Duration::from_secs(30),
|
||||
timeout: Duration::from_secs(20),
|
||||
});
|
||||
let json = round_trip(&n);
|
||||
assert_type_tag(&json, "BashExecutionTimeout");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bash_execution_backgrounded_round_trip() {
|
||||
let n = ToolNotification::BashExecutionBackgrounded(BashExecutionBackgrounded {
|
||||
base: base(),
|
||||
output_file: PathBuf::from("/tmp/out.log"),
|
||||
task_id: "bg-1".into(),
|
||||
});
|
||||
let json = round_trip(&n);
|
||||
assert_type_tag(&json, "BashExecutionBackgrounded");
|
||||
assert_eq!(json["task_id"], json!("bg-1"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bash_execution_failed_round_trip() {
|
||||
let n = ToolNotification::BashExecutionFailed(BashExecutionFailed {
|
||||
tool_call_id: "call-2".into(),
|
||||
command: "missing".into(),
|
||||
cwd: PathBuf::from("/tmp"),
|
||||
error: "not found".into(),
|
||||
});
|
||||
let json = round_trip(&n);
|
||||
assert_type_tag(&json, "BashExecutionFailed");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn file_written_round_trip_includes_previous_content() {
|
||||
let n = ToolNotification::FileWritten(FileWritten {
|
||||
tool_call_id: "call-3".into(),
|
||||
absolute_path: PathBuf::from("/tmp/x"),
|
||||
content: "after".into(),
|
||||
previous_content: Some("before".into()),
|
||||
is_new_file: false,
|
||||
});
|
||||
let json = round_trip(&n);
|
||||
assert_type_tag(&json, "FileWritten");
|
||||
assert_eq!(json["previous_content"], json!("before"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn task_completed_round_trip() {
|
||||
let snap = TaskSnapshot {
|
||||
task_id: "t-1".into(),
|
||||
command: "echo".into(),
|
||||
display_command: None,
|
||||
cwd: "/tmp".into(),
|
||||
start_time: SystemTime::UNIX_EPOCH,
|
||||
end_time: Some(SystemTime::UNIX_EPOCH + Duration::from_secs(1)),
|
||||
output: "out".into(),
|
||||
output_file: PathBuf::from("/tmp/out"),
|
||||
truncated: false,
|
||||
exit_code: Some(0),
|
||||
signal: None,
|
||||
completed: true,
|
||||
kind: TaskKind::Bash,
|
||||
};
|
||||
assert!((snap.duration_secs() - 1.0).abs() < 0.001);
|
||||
let n = ToolNotification::TaskCompleted(snap);
|
||||
let json = round_trip(&n);
|
||||
assert_type_tag(&json, "TaskCompleted");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plan_mode_entered_round_trip() {
|
||||
let n = ToolNotification::PlanModeEntered(PlanModeEntered {
|
||||
tool_call_id: "call-4".into(),
|
||||
});
|
||||
let json = round_trip(&n);
|
||||
assert_type_tag(&json, "PlanModeEntered");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plan_mode_exited_round_trip() {
|
||||
let n = ToolNotification::PlanModeExited(PlanModeExited {
|
||||
tool_call_id: "call-5".into(),
|
||||
plan_content: Some("plan".into()),
|
||||
plan_file_path: ".kigi/plan.md".into(),
|
||||
});
|
||||
let json = round_trip(&n);
|
||||
assert_type_tag(&json, "PlanModeExited");
|
||||
assert_eq!(json["plan_file_path"], json!(".kigi/plan.md"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn user_question_asked_round_trip() {
|
||||
let n = ToolNotification::UserQuestionAsked(UserQuestionAsked {
|
||||
tool_call_id: "call-6".into(),
|
||||
questions_json: json!([{"q": "ok?"}]),
|
||||
});
|
||||
let json = round_trip(&n);
|
||||
assert_type_tag(&json, "UserQuestionAsked");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lsp_lifecycle_variants_round_trip() {
|
||||
let variants = vec![
|
||||
ToolNotification::LspServerStarting(LspServerStarting {
|
||||
server_name: "rust".into(),
|
||||
command: "rust-analyzer".into(),
|
||||
}),
|
||||
ToolNotification::LspServerReady(LspServerReady {
|
||||
server_name: "rust".into(),
|
||||
}),
|
||||
ToolNotification::LspServerCrashed(LspServerCrashed {
|
||||
server_name: "rust".into(),
|
||||
}),
|
||||
ToolNotification::LspServerRetrying(LspServerRetrying {
|
||||
server_name: "rust".into(),
|
||||
attempt: 1,
|
||||
max_restarts: 3,
|
||||
backoff_ms: 500,
|
||||
}),
|
||||
ToolNotification::LspServerFailed(LspServerFailed {
|
||||
server_name: "rust".into(),
|
||||
error: "init failed".into(),
|
||||
attempts: 0,
|
||||
}),
|
||||
];
|
||||
for v in &variants {
|
||||
round_trip(v);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scheduled_task_variants_round_trip() {
|
||||
let fired = ToolNotification::ScheduledTaskFired(ScheduledTaskFired {
|
||||
task_id: "s-1".into(),
|
||||
prompt: "do thing".into(),
|
||||
human_schedule: "every 5 minutes".into(),
|
||||
next_fire_at: Some("2025-01-01T00:00:00Z".into()),
|
||||
});
|
||||
round_trip(&fired);
|
||||
|
||||
let removed = ToolNotification::ScheduledTaskRemoved(ScheduledTaskRemoved {
|
||||
task_id: "s-1".into(),
|
||||
});
|
||||
round_trip(&removed);
|
||||
|
||||
let created = ToolNotification::ScheduledTaskCreated(ScheduledTaskCreated {
|
||||
task_id: "s-2".into(),
|
||||
prompt: "another".into(),
|
||||
human_schedule: "once".into(),
|
||||
next_fire_at: None,
|
||||
});
|
||||
round_trip(&created);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn monitor_event_round_trip() {
|
||||
let n = ToolNotification::MonitorEvent(MonitorEvent {
|
||||
task_id: "m-1".into(),
|
||||
description: "errors in deploy.log".into(),
|
||||
event_text: "<monitor-event>...</monitor-event>".into(),
|
||||
raw_text: "...".into(),
|
||||
});
|
||||
let json = round_trip(&n);
|
||||
assert_type_tag(&json, "MonitorEvent");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn task_kind_default_is_bash_and_round_trips() {
|
||||
assert_eq!(TaskKind::default(), TaskKind::Bash);
|
||||
let bash_json = serde_json::to_value(TaskKind::Bash).unwrap();
|
||||
let monitor_json = serde_json::to_value(TaskKind::Monitor).unwrap();
|
||||
assert_eq!(bash_json, json!("bash"));
|
||||
assert_eq!(monitor_json, json!("monitor"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn variant_count_matches_variant_name() {
|
||||
let all_variants: Vec<ToolNotification> = vec![
|
||||
ToolNotification::BashOutputChunk(BashOutputChunk { base: base() }),
|
||||
ToolNotification::BashExecutionComplete(BashExecutionComplete {
|
||||
base: base(),
|
||||
exit_code: None,
|
||||
signal: None,
|
||||
}),
|
||||
ToolNotification::BashExecutionTimeout(BashExecutionTimeout {
|
||||
base: base(),
|
||||
elapsed: Duration::ZERO,
|
||||
timeout: Duration::ZERO,
|
||||
}),
|
||||
ToolNotification::BashExecutionBackgrounded(BashExecutionBackgrounded {
|
||||
base: base(),
|
||||
output_file: PathBuf::new(),
|
||||
task_id: String::new(),
|
||||
}),
|
||||
ToolNotification::BashExecutionFailed(BashExecutionFailed {
|
||||
tool_call_id: String::new(),
|
||||
command: String::new(),
|
||||
cwd: PathBuf::new(),
|
||||
error: String::new(),
|
||||
}),
|
||||
ToolNotification::FileWritten(FileWritten {
|
||||
tool_call_id: String::new(),
|
||||
absolute_path: PathBuf::new(),
|
||||
content: String::new(),
|
||||
previous_content: None,
|
||||
is_new_file: true,
|
||||
}),
|
||||
ToolNotification::TaskCompleted(TaskSnapshot {
|
||||
task_id: String::new(),
|
||||
command: String::new(),
|
||||
display_command: None,
|
||||
cwd: String::new(),
|
||||
start_time: SystemTime::UNIX_EPOCH,
|
||||
end_time: None,
|
||||
output: String::new(),
|
||||
output_file: PathBuf::new(),
|
||||
truncated: false,
|
||||
exit_code: None,
|
||||
signal: None,
|
||||
completed: false,
|
||||
kind: TaskKind::Bash,
|
||||
}),
|
||||
ToolNotification::PlanModeEntered(PlanModeEntered {
|
||||
tool_call_id: String::new(),
|
||||
}),
|
||||
ToolNotification::PlanModeExited(PlanModeExited {
|
||||
tool_call_id: String::new(),
|
||||
plan_content: None,
|
||||
plan_file_path: String::new(),
|
||||
}),
|
||||
ToolNotification::UserQuestionAsked(UserQuestionAsked {
|
||||
tool_call_id: String::new(),
|
||||
questions_json: json!(null),
|
||||
}),
|
||||
ToolNotification::LspServerStarting(LspServerStarting {
|
||||
server_name: String::new(),
|
||||
command: String::new(),
|
||||
}),
|
||||
ToolNotification::LspServerReady(LspServerReady {
|
||||
server_name: String::new(),
|
||||
}),
|
||||
ToolNotification::LspServerCrashed(LspServerCrashed {
|
||||
server_name: String::new(),
|
||||
}),
|
||||
ToolNotification::LspServerRetrying(LspServerRetrying {
|
||||
server_name: String::new(),
|
||||
attempt: 0,
|
||||
max_restarts: 0,
|
||||
backoff_ms: 0,
|
||||
}),
|
||||
ToolNotification::LspServerFailed(LspServerFailed {
|
||||
server_name: String::new(),
|
||||
error: String::new(),
|
||||
attempts: 0,
|
||||
}),
|
||||
ToolNotification::ScheduledTaskFired(ScheduledTaskFired {
|
||||
task_id: String::new(),
|
||||
prompt: String::new(),
|
||||
human_schedule: String::new(),
|
||||
next_fire_at: None,
|
||||
}),
|
||||
ToolNotification::ScheduledTaskRemoved(ScheduledTaskRemoved {
|
||||
task_id: String::new(),
|
||||
}),
|
||||
ToolNotification::ScheduledTaskCreated(ScheduledTaskCreated {
|
||||
task_id: String::new(),
|
||||
prompt: String::new(),
|
||||
human_schedule: String::new(),
|
||||
next_fire_at: None,
|
||||
}),
|
||||
ToolNotification::MonitorEvent(MonitorEvent {
|
||||
task_id: String::new(),
|
||||
description: String::new(),
|
||||
event_text: String::new(),
|
||||
raw_text: String::new(),
|
||||
}),
|
||||
];
|
||||
let names: std::collections::HashSet<_> =
|
||||
all_variants.iter().map(|n| n.variant_name()).collect();
|
||||
assert_eq!(
|
||||
names.len(),
|
||||
19,
|
||||
"expected 19 distinct variant names; if you added a notification, extend the test list and `variant_name`"
|
||||
);
|
||||
assert_eq!(all_variants.len(), 19);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn handle_send_helpers_round_trip_through_channel() {
|
||||
use futures::stream::StreamExt;
|
||||
use kigi_tool_runtime::ToolNotificationHandle;
|
||||
|
||||
let (handle, mut rx) = ToolNotificationHandle::channel();
|
||||
handle.send_bash_output_chunk(BashOutputChunk { base: base() });
|
||||
handle.send_lsp_ready(LspServerReady {
|
||||
server_name: "rust".into(),
|
||||
});
|
||||
drop(handle);
|
||||
|
||||
let mut received = Vec::new();
|
||||
futures::executor::block_on(async {
|
||||
while let Some(item) = rx.next().await {
|
||||
received.push(item.variant_name());
|
||||
}
|
||||
});
|
||||
assert_eq!(received, vec!["BashOutputChunk", "LspServerReady"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn noop_handle_does_not_panic_or_record() {
|
||||
let handle = kigi_tool_runtime::ToolNotificationHandle::noop();
|
||||
handle.send_bash_output_chunk(BashOutputChunk { base: base() });
|
||||
handle.send_lsp_ready(LspServerReady {
|
||||
server_name: "x".into(),
|
||||
});
|
||||
// No assertion needed — the handle drops sends silently.
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn output_lossy_handles_invalid_utf8() {
|
||||
let mut b = base();
|
||||
b.output = vec![0xFF, b'a', b'b'];
|
||||
let cow = b.output_lossy();
|
||||
assert!(cow.contains("ab"));
|
||||
assert!(cow.contains('\u{FFFD}'));
|
||||
}
|
||||
Reference in New Issue
Block a user