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,9 @@
|
||||
pub mod command;
|
||||
pub mod session_lifecycle;
|
||||
pub mod turn_input;
|
||||
pub mod turn_lifecycle;
|
||||
|
||||
pub use command::LocalCommandContributor;
|
||||
pub use session_lifecycle::LocalSessionLifecycleContributor;
|
||||
pub use turn_input::LocalTurnInputContributor;
|
||||
pub use turn_lifecycle::LocalTurnLifecycleContributor;
|
||||
@@ -0,0 +1,27 @@
|
||||
use async_trait::async_trait;
|
||||
|
||||
use crate::send::contributors::command::{
|
||||
CommandAction, CommandContributor, CommandInvocation, CommandSpec,
|
||||
};
|
||||
|
||||
/// `?Send` twin of [`CommandContributor`] for single-threaded hosts like grok build's TUI agent, whose session state is `Rc`/`RefCell`-based and can
|
||||
/// never satisfy the `Send` bounds the send flavor bakes into its boxed hook futures.
|
||||
#[async_trait(?Send)]
|
||||
pub trait LocalCommandContributor {
|
||||
fn advertised_commands(&self) -> Vec<CommandSpec>;
|
||||
|
||||
async fn handle_command(&self, _input: &CommandInvocation<'_>)
|
||||
-> Result<CommandAction, String>;
|
||||
}
|
||||
|
||||
/// Send contributors work in single-threaded hosts as-is, so shared logic implements [`CommandContributor`] once and both hosts can register it.
|
||||
#[async_trait(?Send)]
|
||||
impl<T: CommandContributor> LocalCommandContributor for T {
|
||||
fn advertised_commands(&self) -> Vec<CommandSpec> {
|
||||
CommandContributor::advertised_commands(self)
|
||||
}
|
||||
|
||||
async fn handle_command(&self, input: &CommandInvocation<'_>) -> Result<CommandAction, String> {
|
||||
CommandContributor::handle_command(self, input).await
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
use async_trait::async_trait;
|
||||
|
||||
use crate::send::contributors::session_lifecycle::{SessionIdleInput, SessionLifecycleContributor};
|
||||
|
||||
/// `?Send` twin of [`SessionLifecycleContributor`].
|
||||
#[async_trait(?Send)]
|
||||
pub trait LocalSessionLifecycleContributor {
|
||||
/// Fired when the session settles idle (no running turn or queued work); the host owns the check.
|
||||
async fn on_session_idle(&self, _input: &SessionIdleInput) {}
|
||||
}
|
||||
|
||||
/// Send contributors are usable in single-threaded hosts as-is, so shared logic implements
|
||||
/// [`SessionLifecycleContributor`] once and both hosts can register it.
|
||||
#[async_trait(?Send)]
|
||||
impl<T: SessionLifecycleContributor> LocalSessionLifecycleContributor for T {
|
||||
async fn on_session_idle(&self, input: &SessionIdleInput) {
|
||||
SessionLifecycleContributor::on_session_idle(self, input).await;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
use async_trait::async_trait;
|
||||
|
||||
use crate::send::contributors::turn_input::{
|
||||
TurnInputContext, TurnInputContributor, TurnInputFragment,
|
||||
};
|
||||
|
||||
/// `?Send` twin of [`TurnInputContributor`] for single-threaded hosts like grok build's TUI agent, whose session state is `Rc`/`RefCell`-based
|
||||
/// and can never satisfy the `Send` bounds the send flavor bakes into its boxed hook futures.
|
||||
#[async_trait(?Send)]
|
||||
pub trait LocalTurnInputContributor {
|
||||
async fn contribute_turn_input(&self, _input: &TurnInputContext) -> Vec<TurnInputFragment> {
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
|
||||
/// Send contributors are usable in single-threaded hosts as-is, so shared logic implements [`TurnInputContributor`] once for both hosts.
|
||||
#[async_trait(?Send)]
|
||||
impl<T: TurnInputContributor> LocalTurnInputContributor for T {
|
||||
async fn contribute_turn_input(&self, input: &TurnInputContext) -> Vec<TurnInputFragment> {
|
||||
TurnInputContributor::contribute_turn_input(self, input).await
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
use async_trait::async_trait;
|
||||
|
||||
use crate::send::contributors::turn_lifecycle::{
|
||||
TurnAbortInput, TurnDoneInput, TurnErrorInput, TurnLifecycleContributor, TurnStartInput,
|
||||
};
|
||||
|
||||
/// `?Send` twin of [`TurnLifecycleContributor`] for single-threaded hosts like grok build's TUI
|
||||
/// agent, whose session state is `Rc`/`RefCell`-based and can never satisfy the `Send` bounds the
|
||||
/// send flavor bakes into its boxed hook futures.
|
||||
#[async_trait(?Send)]
|
||||
pub trait LocalTurnLifecycleContributor {
|
||||
async fn on_turn_start(&self, _input: &TurnStartInput) {}
|
||||
|
||||
async fn on_turn_done(&self, _input: &TurnDoneInput) {}
|
||||
|
||||
async fn on_turn_abort(&self, _input: &TurnAbortInput) {}
|
||||
|
||||
async fn on_turn_error(&self, _input: &TurnErrorInput<'_>) {}
|
||||
}
|
||||
|
||||
/// Send contributors are usable in single-threaded hosts as-is, so shared logic implements
|
||||
/// [`TurnLifecycleContributor`] once and both hosts can register it.
|
||||
#[async_trait(?Send)]
|
||||
impl<T: TurnLifecycleContributor> LocalTurnLifecycleContributor for T {
|
||||
async fn on_turn_start(&self, input: &TurnStartInput) {
|
||||
TurnLifecycleContributor::on_turn_start(self, input).await;
|
||||
}
|
||||
|
||||
async fn on_turn_done(&self, input: &TurnDoneInput) {
|
||||
TurnLifecycleContributor::on_turn_done(self, input).await;
|
||||
}
|
||||
|
||||
async fn on_turn_abort(&self, input: &TurnAbortInput) {
|
||||
TurnLifecycleContributor::on_turn_abort(self, input).await;
|
||||
}
|
||||
|
||||
async fn on_turn_error(&self, input: &TurnErrorInput<'_>) {
|
||||
TurnLifecycleContributor::on_turn_error(self, input).await;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::local::contributors::{
|
||||
LocalCommandContributor, LocalSessionLifecycleContributor, LocalTurnInputContributor,
|
||||
LocalTurnLifecycleContributor,
|
||||
};
|
||||
|
||||
/// Mutable registry used while hosts register typed runtime contributions.
|
||||
#[derive(Default)]
|
||||
pub struct LocalExtensionRegistryBuilder {
|
||||
turn_lifecycle_contributors: Vec<Rc<dyn LocalTurnLifecycleContributor>>,
|
||||
session_lifecycle_contributors: Vec<Rc<dyn LocalSessionLifecycleContributor>>,
|
||||
turn_input_contributors: Vec<Rc<dyn LocalTurnInputContributor>>,
|
||||
command_contributors: Vec<Rc<dyn LocalCommandContributor>>,
|
||||
}
|
||||
|
||||
impl LocalExtensionRegistryBuilder {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub fn turn_lifecycle_contributor(
|
||||
&mut self,
|
||||
contributor: Rc<dyn LocalTurnLifecycleContributor>,
|
||||
) {
|
||||
self.turn_lifecycle_contributors.push(contributor);
|
||||
}
|
||||
|
||||
pub fn session_lifecycle_contributor(
|
||||
&mut self,
|
||||
contributor: Rc<dyn LocalSessionLifecycleContributor>,
|
||||
) {
|
||||
self.session_lifecycle_contributors.push(contributor);
|
||||
}
|
||||
|
||||
pub fn turn_input_contributor(&mut self, contributor: Rc<dyn LocalTurnInputContributor>) {
|
||||
self.turn_input_contributors.push(contributor);
|
||||
}
|
||||
|
||||
pub fn command_contributor(&mut self, contributor: Rc<dyn LocalCommandContributor>) {
|
||||
self.command_contributors.push(contributor);
|
||||
}
|
||||
|
||||
/// Routes each advertised command to its one owner. Duplicate names are a composition bug:
|
||||
/// first registration wins, panics in debug builds, logs in release.
|
||||
pub fn build(self) -> LocalExtensionRegistry {
|
||||
let mut command_handlers: HashMap<String, Rc<dyn LocalCommandContributor>> = HashMap::new();
|
||||
for contributor in &self.command_contributors {
|
||||
for spec in contributor.advertised_commands() {
|
||||
if command_handlers.contains_key(&spec.name) {
|
||||
debug_assert!(false, "duplicate command contributed: /{}", spec.name);
|
||||
tracing::error!(command = %spec.name, "Duplicate command contributed; first registration wins");
|
||||
continue;
|
||||
}
|
||||
command_handlers.insert(spec.name, contributor.clone());
|
||||
}
|
||||
}
|
||||
|
||||
LocalExtensionRegistry {
|
||||
turn_lifecycle_contributors: self.turn_lifecycle_contributors,
|
||||
session_lifecycle_contributors: self.session_lifecycle_contributors,
|
||||
turn_input_contributors: self.turn_input_contributors,
|
||||
command_contributors: self.command_contributors,
|
||||
command_handlers,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Immutable typed registry produced after extensions are installed.
|
||||
#[derive(Default)]
|
||||
pub struct LocalExtensionRegistry {
|
||||
turn_lifecycle_contributors: Vec<Rc<dyn LocalTurnLifecycleContributor>>,
|
||||
session_lifecycle_contributors: Vec<Rc<dyn LocalSessionLifecycleContributor>>,
|
||||
turn_input_contributors: Vec<Rc<dyn LocalTurnInputContributor>>,
|
||||
command_contributors: Vec<Rc<dyn LocalCommandContributor>>,
|
||||
command_handlers: HashMap<String, Rc<dyn LocalCommandContributor>>,
|
||||
}
|
||||
|
||||
impl LocalExtensionRegistry {
|
||||
pub fn turn_lifecycle_contributors(&self) -> &[Rc<dyn LocalTurnLifecycleContributor>] {
|
||||
&self.turn_lifecycle_contributors
|
||||
}
|
||||
|
||||
pub fn session_lifecycle_contributors(&self) -> &[Rc<dyn LocalSessionLifecycleContributor>] {
|
||||
&self.session_lifecycle_contributors
|
||||
}
|
||||
|
||||
pub fn turn_input_contributors(&self) -> &[Rc<dyn LocalTurnInputContributor>] {
|
||||
&self.turn_input_contributors
|
||||
}
|
||||
|
||||
pub fn command_contributors(&self) -> &[Rc<dyn LocalCommandContributor>] {
|
||||
&self.command_contributors
|
||||
}
|
||||
|
||||
/// The one contributor owning `name`, or `None` when no extension advertised it.
|
||||
pub fn command_handler(&self, name: &str) -> Option<&Rc<dyn LocalCommandContributor>> {
|
||||
self.command_handlers.get(name)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user