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,138 @@
|
||||
//! Data-driven scripted responses for the mock inference server: plain
|
||||
//! status/header/body triples queued per path and rendered to HTTP at serve
|
||||
//! time. Pure data — no router or handler types in the public surface.
|
||||
|
||||
use std::convert::Infallible;
|
||||
|
||||
use axum::Json;
|
||||
use axum::http::{HeaderName, HeaderValue, StatusCode};
|
||||
use axum::response::sse::{KeepAlive, Sse};
|
||||
use axum::response::{IntoResponse, Response};
|
||||
use futures_util::stream;
|
||||
use serde_json::Value;
|
||||
|
||||
/// One SSE event as data: optional `event:` name plus the `data:` payload.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SseEvent {
|
||||
pub event: Option<String>,
|
||||
pub data: String,
|
||||
}
|
||||
|
||||
impl SseEvent {
|
||||
/// Event with a `data:` payload only.
|
||||
pub fn data(data: impl Into<String>) -> Self {
|
||||
Self {
|
||||
event: None,
|
||||
data: data.into(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Event with an `event:` name and a `data:` payload.
|
||||
pub fn with_event(event: impl Into<String>, data: impl Into<String>) -> Self {
|
||||
Self {
|
||||
event: Some(event.into()),
|
||||
data: data.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Body of a [`ScriptedResponse`].
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ScriptedBody {
|
||||
Json(Value),
|
||||
Sse(Vec<SseEvent>),
|
||||
/// Raw body bytes, served verbatim (byte-controllable malformed SSE etc.).
|
||||
Raw(String),
|
||||
}
|
||||
|
||||
/// A scripted reply for a single request on one path, consumed FIFO.
|
||||
/// Takes precedence over the response mode AND the required-auth check —
|
||||
/// a script is full control over the next reply.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ScriptedResponse {
|
||||
pub status: u16,
|
||||
pub headers: Vec<(String, String)>,
|
||||
pub body: ScriptedBody,
|
||||
}
|
||||
|
||||
impl ScriptedResponse {
|
||||
/// 200 SSE response built from an event list.
|
||||
pub fn sse(events: Vec<SseEvent>) -> Self {
|
||||
Self {
|
||||
status: 200,
|
||||
headers: Vec::new(),
|
||||
body: ScriptedBody::Sse(events),
|
||||
}
|
||||
}
|
||||
|
||||
/// JSON body with the given status.
|
||||
pub fn json(status: u16, body: Value) -> Self {
|
||||
Self {
|
||||
status,
|
||||
headers: Vec::new(),
|
||||
body: ScriptedBody::Json(body),
|
||||
}
|
||||
}
|
||||
|
||||
/// Raw text body with the given status.
|
||||
pub fn text(status: u16, body: impl Into<String>) -> Self {
|
||||
Self {
|
||||
status,
|
||||
headers: Vec::new(),
|
||||
body: ScriptedBody::Raw(body.into()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Validate status and headers eagerly so a bad script panics at the
|
||||
/// enqueue call site rather than far away at serve time.
|
||||
pub(crate) fn validate(&self) {
|
||||
StatusCode::from_u16(self.status).expect("invalid scripted status code");
|
||||
for (name, value) in &self.headers {
|
||||
HeaderName::from_bytes(name.as_bytes()).expect("invalid scripted header name");
|
||||
HeaderValue::from_str(value).expect("invalid scripted header value");
|
||||
}
|
||||
}
|
||||
|
||||
/// Render to HTTP with SSE events paced by `delay` (sleep before each
|
||||
/// event, mirroring the fixed/echo `paced_events` pacing) so
|
||||
/// `set_chunk_delay` also holds scripted turns open. `None` streams
|
||||
/// instantly. Non-SSE bodies ignore the delay.
|
||||
pub(crate) fn into_response_paced(self, delay: Option<std::time::Duration>) -> Response {
|
||||
use futures_util::StreamExt as _;
|
||||
let mut resp = match self.body {
|
||||
ScriptedBody::Json(v) => Json(v).into_response(),
|
||||
ScriptedBody::Raw(s) => s.into_response(),
|
||||
ScriptedBody::Sse(events) => {
|
||||
let events: Vec<axum::response::sse::Event> = events
|
||||
.into_iter()
|
||||
.map(|e| {
|
||||
let ev = axum::response::sse::Event::default().data(e.data);
|
||||
match e.event {
|
||||
Some(name) => ev.event(name),
|
||||
None => ev,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
let stream = stream::iter(events.into_iter().map(Ok::<_, Infallible>)).then(
|
||||
move |event| async move {
|
||||
if let Some(d) = delay {
|
||||
tokio::time::sleep(d).await;
|
||||
}
|
||||
event
|
||||
},
|
||||
);
|
||||
Sse::new(stream)
|
||||
.keep_alive(KeepAlive::default())
|
||||
.into_response()
|
||||
}
|
||||
};
|
||||
*resp.status_mut() = StatusCode::from_u16(self.status).expect("valid scripted status code");
|
||||
for (k, v) in self.headers {
|
||||
resp.headers_mut().insert(
|
||||
HeaderName::from_bytes(k.as_bytes()).expect("valid scripted header name"),
|
||||
HeaderValue::from_str(&v).expect("valid scripted header value"),
|
||||
);
|
||||
}
|
||||
resp
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user