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:
commit
d6c20fc13f
2612 files changed
+1353757
No files matched your search
@@ -0,0 +1,164 @@
|
||||
//! Registration payloads, descriptions, transports, and outcomes.
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
HookKind, IdError, NotificationSchemas, ServerId, SessionId, ToolCapabilities, ToolId, UserId,
|
||||
};
|
||||
|
||||
/// Whether a registered tool runs in-process or behind a remote connection.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum TransportKind {
|
||||
Local,
|
||||
Remote,
|
||||
}
|
||||
|
||||
/// A single tool's wire description plus optional schema and capability
|
||||
/// metadata. The `tool_id` is **not** stored explicitly — it is derived
|
||||
/// from `description.{namespace, name}` via [`Self::derive_tool_id`].
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ToolDescriptionWithSchema {
|
||||
pub description: kigi_tool_types::ToolDescription,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub input_schema: Option<serde_json::Value>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub capabilities: Option<ToolCapabilities>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub notification_schemas: Option<NotificationSchemas>,
|
||||
}
|
||||
|
||||
impl ToolDescriptionWithSchema {
|
||||
/// Derive the canonical `ToolId`.
|
||||
///
|
||||
/// Namespaced descriptions render as `"{namespace}:{name}"`; otherwise
|
||||
/// the bare `name`. The result is run through [`ToolId::new`], so an
|
||||
/// invalid name or namespace surfaces as an [`IdError`].
|
||||
pub fn derive_tool_id(&self) -> Result<ToolId, IdError> {
|
||||
match &self.description.namespace {
|
||||
Some(ns) => ToolId::new(format!("{ns}:{}", self.description.name)),
|
||||
None => ToolId::new(self.description.name.as_str()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Single-tool registration. Wire-level sugar for a one-tool
|
||||
/// `register_server`.
|
||||
///
|
||||
/// `sessions` carries the per-tool session set with three-state
|
||||
/// semantics, modelled after `if_match_generation: Option<u64>`:
|
||||
///
|
||||
/// - `None` (field omitted on the wire) — "no change". For a
|
||||
/// first-time registration the computer hub treats this as the empty
|
||||
/// set; for a re-registration the existing session bindings are
|
||||
/// preserved untouched. Use this for heartbeat-style re-register
|
||||
/// flows that re-send the description without revisiting the
|
||||
/// session set.
|
||||
/// - `Some(vec![])` (explicit empty array) — "unbind every session".
|
||||
/// The tool stays registered against the connection but becomes
|
||||
/// unreachable from any session until [`crate::Method::BindToolSession`]
|
||||
/// adds a new binding.
|
||||
/// - `Some(vec![s1, ...])` — replace the per-tool session set with
|
||||
/// exactly the listed ids. Each id MUST already be in the
|
||||
/// connection's bound-session set (validated by the router);
|
||||
/// a missing id rejects the entire registration.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ToolRegistration {
|
||||
/// MUST equal `description.derive_tool_id()`. Carried explicitly so
|
||||
/// receivers can route without re-deriving. The IC service router
|
||||
/// enforces this at register-tool time and rejects mismatches with
|
||||
/// `InvalidRequest`.
|
||||
pub tool_id: ToolId,
|
||||
/// Per-tool session set. See struct doc-comment for the
|
||||
/// `None` / `Some(vec![])` / `Some(vec![...])` semantics.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub sessions: Option<Vec<SessionId>>,
|
||||
pub user_id: UserId,
|
||||
/// `None` → computer hub synthesises `auto:tool:{tool_id}`.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub server_id: Option<ServerId>,
|
||||
pub description: kigi_tool_types::ToolDescription,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub input_schema: Option<serde_json::Value>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub capabilities: Option<ToolCapabilities>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub notification_schemas: Option<NotificationSchemas>,
|
||||
pub transport_kind: TransportKind,
|
||||
/// Optimistic-concurrency precondition. `None` → last-writer-wins.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub if_match_generation: Option<u64>,
|
||||
/// Opaque metadata supplied by the tool server at registration time.
|
||||
/// Propagated to `ServerInfo.metadata` in `servers.list` responses.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub metadata: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
impl ToolRegistration {
|
||||
/// Derive the canonical `ToolId` from `description.{namespace, name}`.
|
||||
/// The `tool_id` payload field MUST equal this value; the IC service
|
||||
/// router enforces the invariant at register-tool time.
|
||||
pub fn derive_tool_id(&self) -> Result<ToolId, IdError> {
|
||||
match &self.description.namespace {
|
||||
Some(ns) => ToolId::new(format!("{ns}:{}", self.description.name)),
|
||||
None => ToolId::new(self.description.name.as_str()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Multi-tool registration. The whole batch shares one `server_id` and one
|
||||
/// `sessions` value; per-tool outcomes are reported individually via
|
||||
/// [`RegistrationOutcome`].
|
||||
///
|
||||
/// `sessions` follows the same three-state semantics as
|
||||
/// [`ToolRegistration::sessions`]: `None` means "no change" (preserves
|
||||
/// existing per-tool session bindings on a re-register), `Some(vec![])`
|
||||
/// means "unbind every session for every tool in this batch", and
|
||||
/// `Some(vec![...])` means "replace each tool's session set with
|
||||
/// exactly these ids".
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ToolServerRegistration {
|
||||
pub server_id: ServerId,
|
||||
/// Per-batch session set. See struct doc-comment for `None` /
|
||||
/// `Some(vec![])` / `Some(vec![...])` semantics.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub sessions: Option<Vec<SessionId>>,
|
||||
pub user_id: UserId,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub title: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "String::is_empty")]
|
||||
pub description: String,
|
||||
pub tools: Vec<ToolDescriptionWithSchema>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub hooks: Vec<HookKind>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub if_match_generation: Option<u64>,
|
||||
/// Opaque metadata supplied by the tool server at registration time.
|
||||
/// Applied to every tool in the batch and propagated to
|
||||
/// `ServerInfo.metadata` in `servers.list` responses.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub metadata: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
/// Per-tool result from a `register_tool` or `register_server` call.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(tag = "outcome", rename_all = "snake_case")]
|
||||
pub enum RegistrationOutcome {
|
||||
Registered {
|
||||
tool_id: ToolId,
|
||||
generation: u64,
|
||||
},
|
||||
Updated {
|
||||
tool_id: ToolId,
|
||||
generation: u64,
|
||||
},
|
||||
Shadowed {
|
||||
tool_id: ToolId,
|
||||
reason: String,
|
||||
},
|
||||
Rejected {
|
||||
tool_id: ToolId,
|
||||
code: String,
|
||||
message: String,
|
||||
},
|
||||
}
|
||||
Reference in new issue
Block a user