Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

fix(kimi): match kimi-code device headers, keep User-Agent graff/<version> (#617)

justracha6ae6f73563f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9f0f28c6..8c5b148e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,6 +17,9 @@ current is part of cutting a release.
gets a job id, matching grok-build. Esc still kills; the cancelled
result tells the model to use `run_in_background`. Subagents keep the
#93 120s kill. (#620)
+- Kimi Coding keeps User-Agent `graff/<version>` (Moonshot forbids spoofing)
+ and matches kimi-code's X-Msh device fields: hostname, `Windows ${release}
+ ${arch}` / `macOS ${product} ${arch}`, kernel `os.release()` (#617)
## v0.0.275 (2026-08-24)
diff --git a/docs/adr/0023-kimi-identity-is-graff.md b/docs/adr/0023-kimi-identity-is-graff.md
new file mode 100644
index 00000000..88edfec1
--- /dev/null
+++ b/docs/adr/0023-kimi-identity-is-graff.md
@@ -0,0 +1,40 @@
+# 0023. Kimi Coding identity is graff, device fields follow kimi-code
+
+Status: accepted 2026-08-25
+
+## Context
+
+[#617](https://github.com/justrach/codegraff/issues/617) is a Windows 5xx on
+`graff --model kimi` after a successful `graff login kimi`. The first-party
+Kimi CLI on the same machine succeeds.
+
+[MoonshotAI/kimi-code](https://github.com/MoonshotAI/kimi-code)
+`packages/oauth/src/identity.ts` sends:
+
+- User-Agent `kimi-code-cli/<semver>`
+- `X-Msh-Platform: kimi_code_cli`
+- `X-Msh-Device-Name`: hostname
+- `X-Msh-Device-Model`: `Windows ${release()} ${arch}` / `macOS ${productVersion} ${arch}`
+- `X-Msh-Os-Version`: `os.release()` (kernel), not the Zig OS tag
+
+Moonshot's third-party docs forbid spoofing User-Agent. Graff already used the
+Kimi Code OAuth client and `kimi_code_cli` platform (login works). It sent
+`User-Agent: graff/<version>` with `X-Msh-Device-Name: graff` and Zig tags
+(`windows x86_64`, `os_version=windows`) that do not match kimi-code's Node
+shapes. That Windows-only mismatch is the header gap #617 can actually close
+without impersonating the first-party CLI.
+
+## Decision
+
+- User-Agent stays `graff/<version>`. Do not send `kimi-code-cli/` or
+ `claude-code/`.
+- `X-Msh-Platform` stays `kimi_code_cli` because that is the OAuth client
+ graff already uses.
+- Device headers match kimi-code's field shapes: hostname, Node `os.arch()`
+ names (`x64`/`arm64`), `Windows ${release} ${arch}` / `macOS ${product} ${arch}`,
+ kernel `os.release()`.
+
+## Cost
+
+A future Kimi allowlist that requires `kimi-code-cli` in User-Agent will still
+fail honestly. Spoofing would be a membership violation; this ADR forbids it.
diff --git a/docs/adr/README.md b/docs/adr/README.md
index 91dc24d8..ad6dcb3a 100644
--- a/docs/adr/README.md
+++ b/docs/adr/README.md
@@ -33,6 +33,7 @@ record only when you need the evidence or the edge cases.
| [0020](0020-transcript-shows-decisions.md) | Transcript shows decisions: one interpreted tool line, collapsed infra failures, compact WORKING; raw output is `/debug` / TUI-fold. |
| [0021](0021-transcript-is-the-task-not-the-bus.md) | Transcript is the task, not the event bus: bookkeeping is silent, todos are WORKING, subagents are scouts. |
| [0022](0022-foreground-bash-auto-backgrounds.md) | Root foreground `bash` auto-backgrounds after 120s (or `timeout` ms); it is not killed. Subagents still kill at 120s (#93). |
+| [0023](0023-kimi-identity-is-graff.md) | Kimi Coding User-Agent is `graff/<version>`, not a spoofed `kimi-code-cli` token. X-Msh device fields follow kimi-code's shapes. |
## When to write one
diff --git a/src/cli.zig b/src/cli.zig
index 810cc2ea..6d78b3b9 100644
--- a/src/cli.zig
+++ b/src/cli.zig
@@ -23,6 +23,7 @@ pub const changelog_text =
\\──────────
\\0.0.276
\\ • foreground bash auto-backgrounds after 120s instead of waiting forever (#620)
+ \\ • Kimi identity: graff/<version> User-Agent; device headers match kimi-code (#617)
\\
\\0.0.275
\\ • OpenRouter requests carry app attribution (categories: cli-agent, programming-app)
diff --git a/src/http_headers.zig b/src/http_headers.zig
index 3866b3a4..f50fb218 100644
--- a/src/http_headers.zig
+++ b/src/http_headers.zig
@@ -480,3 +480,22 @@ test "xai login tokens send X-XAI-Token-Auth; API keys do not" {
try std.testing.expect(!std.mem.eql(u8, h.name, "X-XAI-Token-Auth"));
}
}
+
+test "Kimi chat sends graff identity and kimi-code device headers (#617)" {
+ const io = std.testing.io;
+ var buf: [12]std.http.Header = undefined;
+ const p: Provider = .{ .id = "kimi", .kind = .openai, .auth = .bearer, .url = "", .api_key = "k", .model = "k3", .context = 256_000 };
+ const headers = providerHeaders(io, p, "Bearer k", &buf);
+ try std.testing.expectEqualStrings("kimi_code_cli", headerValue(headers, "X-Msh-Platform").?);
+ try std.testing.expect(headerValue(headers, "X-Msh-Device-Name").?.len > 0);
+ try std.testing.expect(!std.mem.eql(u8, headerValue(headers, "X-Msh-Device-Name").?, "unknown"));
+ const model = headerValue(headers, "X-Msh-Device-Model").?;
+ const prefix = switch (@import("builtin").os.tag) {
+ .windows => "Windows ",
+ .macos => "macOS ",
+ .linux => "Linux ",
+ else => "",
+ };
+ if (prefix.len != 0) try std.testing.expect(std.mem.startsWith(u8, model, prefix));
+ try std.testing.expect(!std.mem.eql(u8, headerValue(headers, "X-Msh-Os-Version").?, @tagName(@import("builtin").os.tag)));
+}
diff --git a/src/kimi_catalog.zig b/src/kimi_catalog.zig
index 6c2b23e4..5a547af5 100644
--- a/src/kimi_catalog.zig
+++ b/src/kimi_catalog.zig
@@ -3,103 +3,23 @@
//! baking each K2/K3 rollout into the OAuth client.
const std = @import("std");
-const builtin = @import("builtin");
const Io = std.Io;
const Allocator = std.mem.Allocator;
const Value = std.json.Value;
const pricing = @import("pricing.zig");
const util = @import("util.zig");
+const identity = @import("kimi_identity.zig");
pub const models_url = "https://api.kimi.com/coding/v1/models";
-pub const user_agent = "graff/" ++ @import("build_options").version;
-pub const platform = "kimi_code_cli";
-pub const version = @import("build_options").version;
-pub const device_model = @tagName(builtin.os.tag) ++ " " ++ @tagName(builtin.cpu.arch);
-pub const os_version = @tagName(builtin.os.tag);
-pub var device_id: []const u8 = "unknown";
+pub const user_agent = identity.user_agent;
+pub const platform = identity.platform;
+pub const version = identity.version;
+pub const initIdentity = identity.initIdentity;
+pub const identityHeaders = identity.identityHeaders;
pub var catalog_source: []const u8 = "baked offline fallback";
var catalog_attempted = false;
-const private_file_permissions: Io.File.Permissions = if (Io.File.Permissions.has_executable_bit) @enumFromInt(0o600) else .default_file;
-const private_dir_permissions: Io.File.Permissions = if (Io.File.Permissions.has_executable_bit) @enumFromInt(0o700) else .default_dir;
-
-fn secureDir(io: Io, path: []const u8) void {
- // iterate=true: a default openDir can yield an O_PATH handle on Linux, and
- // fchmod on O_PATH fails EBADF — which std.Io treats as a programmer-bug
- // panic, not a catchable error. A readable handle chmods fine everywhere.
- const dir = Io.Dir.cwd().openDir(io, path, .{ .iterate = true }) catch return;
- defer dir.close(io);
- // Dir.setPermissions panics on Windows in Zig 0.17 (`dirSetPermissionsWindows`).
- if (builtin.os.tag != .windows) dir.setPermissions(io, private_dir_permissions) catch {};
-}
-
-fn validDeviceId(value: []const u8) bool {
- if (value.len != 36) return false;
- for (value, 0..) |c, i| {
- if (i == 8 or i == 13 or i == 18 or i == 23) {
- if (c != '-') return false;
- } else if (!std.ascii.isHex(c)) return false;
- }
- return true;
-}
-
-/// Kimi Code sends a stable random device id with its X-Msh identity headers.
-/// Graff owns a separate ~/.kimi/device_id so it never mutates another CLI's
-/// credential store or impersonates that installation.
-pub fn initIdentity(io: Io, arena: Allocator, home: []const u8) void {
- if (!std.mem.eql(u8, device_id, "unknown") or home.len == 0) return;
- const dir = std.fmt.allocPrint(arena, "{s}/.kimi", .{home}) catch return;
- const path = std.fmt.allocPrint(arena, "{s}/device_id", .{dir}) catch return;
- if (Io.Dir.cwd().readFileAlloc(io, path, arena, .limited(128))) |raw| {
- const value = std.mem.trim(u8, raw, " \t\r\n");
- if (validDeviceId(value)) {
- device_id = arena.dupe(u8, value) catch "unknown";
- secureDir(io, dir);
- const file = Io.Dir.cwd().openFile(io, path, .{ .mode = .read_only }) catch return;
- defer file.close(io);
- file.setPermissions(io, private_file_permissions) catch {};
- return;
- }
- } else |_| {}
- var random: [16]u8 = undefined;
- io.random(&random);
- random[6] = (random[6] & 0x0f) | 0x40;
- random[8] = (random[8] & 0x3f) | 0x80;
- const hex = std.fmt.bytesToHex(random, .lower);
- const id = arena.alloc(u8, 36) catch return;
- @memcpy(id[0..8], hex[0..8]);
- id[8] = '-';
- @memcpy(id[9..13], hex[8..12]);
- id[13] = '-';
- @memcpy(id[14..18], hex[12..16]);
- id[18] = '-';
- @memcpy(id[19..23], hex[16..20]);
- id[23] = '-';
- @memcpy(id[24..36], hex[20..32]);
- device_id = id;
- Io.Dir.cwd().createDir(io, dir, private_dir_permissions) catch {};
- secureDir(io, dir);
- const file = Io.Dir.cwd().createFile(io, path, .{ .permissions = private_file_permissions }) catch return;
- defer file.close(io);
- file.setPermissions(io, private_file_permissions) catch {};
- var buf: [64]u8 = undefined;
- var writer = file.writer(io, &buf);
- writer.interface.print("{s}\n", .{id}) catch return;
- writer.interface.flush() catch {};
-}
-
-pub fn identityHeaders(buf: []std.http.Header) []std.http.Header {
- if (buf.len < 6) return buf[0..0];
- buf[0] = .{ .name = "X-Msh-Platform", .value = platform };
- buf[1] = .{ .name = "X-Msh-Version", .value = version };
- buf[2] = .{ .name = "X-Msh-Device-Name", .value = "graff" };
- buf[3] = .{ .name = "X-Msh-Device-Model", .value = device_model };
- buf[4] = .{ .name = "X-Msh-Os-Version", .value = os_version };
- buf[5] = .{ .name = "X-Msh-Device-Id", .value = device_id };
- return buf[0..6];
-}
-
fn validModelId(id: []const u8) bool {
if (id.len == 0 or id.len > 256) return false;
for (id) |c| if (!(std.ascii.isAlphanumeric(c) or c == '-' or c == '_' or c == '.' or c == '/')) return false;
diff --git a/src/kimi_identity.zig b/src/kimi_identity.zig
new file mode 100644
index 00000000..4c6cdeb6
--- /dev/null
+++ b/src/kimi_identity.zig
@@ -0,0 +1,275 @@
+//! Kimi Coding request identity. Field *shapes* follow MoonshotAI/kimi-code
+//! `packages/oauth/src/identity.ts` (hostname, Node-style device model,
+//! `os.release()`). The product token stays `graff/<version>`: Moonshot treats
+//! a spoofed User-Agent as a violation, and a host must state its own name.
+
+const std = @import("std");
+const builtin = @import("builtin");
+const Io = std.Io;
+const Allocator = std.mem.Allocator;
+
+pub const user_agent = "graff/" ++ @import("build_options").version;
+pub const platform = "kimi_code_cli";
+pub const version = @import("build_options").version;
+
+pub var device_id: []const u8 = "unknown";
+pub var device_name: []const u8 = "unknown";
+pub var device_model: []const u8 = "unknown";
+pub var os_version: []const u8 = "unknown";
+
+var device_name_buf: [256]u8 = undefined;
+var device_model_buf: [128]u8 = undefined;
+var os_version_buf: [128]u8 = undefined;
+var host_fields_ready = false;
+
+const private_file_permissions: Io.File.Permissions = if (Io.File.Permissions.has_executable_bit) @enumFromInt(0o600) else .default_file;
+const private_dir_permissions: Io.File.Permissions = if (Io.File.Permissions.has_executable_bit) @enumFromInt(0o700) else .default_dir;
+
+/// Node `os.arch()` names. kimi-code puts these in `X-Msh-Device-Model`.
+pub fn nodeArch(tag: std.Target.Cpu.Arch) []const u8 {
+ return switch (tag) {
+ .x86_64 => "x64",
+ .x86 => "ia32",
+ .aarch64 => "arm64",
+ .arm, .armeb, .thumb, .thumbeb => "arm",
+ else => @tagName(tag),
+ };
+}
+
+/// kimi-code `deviceModel()`: `Windows ${release} ${arch}`, `macOS ${product} ${arch}`,
+/// otherwise `${type} ${release} ${arch}`.
+pub fn formatDeviceModel(
+ buf: []u8,
+ os_tag: std.Target.Os.Tag,
+ release: []const u8,
+ macos_product: ?[]const u8,
+ arch: []const u8,
+) []const u8 {
+ const rel = if (release.len == 0) "unknown" else release;
+ const printed = switch (os_tag) {
+ .windows => std.fmt.bufPrint(buf, "Windows {s} {s}", .{ rel, arch }),
+ .macos => std.fmt.bufPrint(buf, "macOS {s} {s}", .{ macos_product orelse rel, arch }),
+ .linux => std.fmt.bufPrint(buf, "Linux {s} {s}", .{ rel, arch }),
+ .freebsd => std.fmt.bufPrint(buf, "FreeBSD {s} {s}", .{ rel, arch }),
+ else => std.fmt.bufPrint(buf, "{s} {s} {s}", .{ @tagName(os_tag), rel, arch }),
+ };
+ return printed catch "unknown";
+}
+
+/// kimi-code `asciiHeader`: printable ASCII, trimmed, else `unknown`.
+pub fn persistAscii(buf: []u8, value: []const u8) []const u8 {
+ var n: usize = 0;
+ for (value) |c| {
+ if (c >= 0x20 and c <= 0x7E) {
+ if (n == buf.len) break;
+ buf[n] = c;
+ n += 1;
+ }
+ }
+ const trimmed = std.mem.trim(u8, buf[0..n], " \t\r\n");
+ return if (trimmed.len == 0) "unknown" else trimmed;
+}
+
+fn secureDir(io: Io, path: []const u8) void {
+ const dir = Io.Dir.cwd().openDir(io, path, .{ .iterate = true }) catch return;
+ defer dir.close(io);
+ if (builtin.os.tag != .windows) dir.setPermissions(io, private_dir_permissions) catch {};
+}
+
+fn validDeviceId(value: []const u8) bool {
+ if (value.len != 36) return false;
+ for (value, 0..) |c, i| {
+ if (i == 8 or i == 13 or i == 18 or i == 23) {
+ if (c != '-') return false;
+ } else if (!std.ascii.isHex(c)) return false;
+ }
+ return true;
+}
+
+fn readHostname(buf: []u8) []const u8 {
+ if (comptime builtin.os.tag == .windows) return windowsHostname(buf);
+ if (comptime builtin.os.tag == .wasi) return "unknown";
+ const uts = std.posix.uname();
+ const host = std.mem.sliceTo(&uts.nodename, 0);
+ const n = @min(host.len, buf.len);
+ @memcpy(buf[0..n], host[0..n]);
+ return buf[0..n];
+}
+
+fn readOsRelease(buf: []u8) []const u8 {
+ if (comptime builtin.os.tag == .windows) return windowsRelease(buf);
+ if (comptime builtin.os.tag == .wasi) return "unknown";
+ const uts = std.posix.uname();
+ const rel = std.mem.sliceTo(&uts.release, 0);
+ const n = @min(rel.len, buf.len);
+ @memcpy(buf[0..n], rel[0..n]);
+ return buf[0..n];
+}
+
+fn windowsHostname(buf: []u8) []const u8 {
+ if (comptime builtin.os.tag != .windows) return "unknown";
+ const w = std.os.windows;
+ const GetComputerNameExA = struct {
+ extern "kernel32" fn GetComputerNameExA(NameType: u32, lpBuffer: ?[*]u8, nSize: *u32) callconv(.winapi) w.BOOL;
+ }.GetComputerNameExA;
+ var size: u32 = @intCast(buf.len);
+ if (GetComputerNameExA(1, buf.ptr, &size).toBool() and size > 0)
+ return buf[0..@min(size, buf.len)];
+ return "unknown";
+}
+
+fn windowsRelease(buf: []u8) []const u8 {
+ if (comptime builtin.os.tag != .windows) return "unknown";
+ var info: std.os.windows.RTL_OSVERSIONINFOW = undefined;
+ info.dwOSVersionInfoSize = @sizeOf(@TypeOf(info));
+ _ = std.os.windows.ntdll.RtlGetVersion(&info);
+ return std.fmt.bufPrint(buf, "{d}.{d}.{d}", .{
+ info.dwMajorVersion,
+ info.dwMinorVersion,
+ info.dwBuildNumber,
+ }) catch "unknown";
+}
+
+fn readMacosProduct(buf: []u8) ?[]const u8 {
+ if (comptime builtin.os.tag != .macos) return null;
+ const sysctlbyname = struct {
+ extern "c" fn sysctlbyname(name: [*:0]const u8, oldp: ?*anyopaque, oldlenp: ?*usize, newp: ?*anyopaque, newlen: usize) c_int;
+ }.sysctlbyname;
+ var len: usize = buf.len;
+ if (sysctlbyname("kern.osproductversion", buf.ptr, &len, null, 0) != 0) return null;
+ if (len == 0) return null;
+ const n = if (buf[len - 1] == 0) len - 1 else len;
+ return if (n == 0) null else buf[0..n];
+}
+
+pub fn fillHostFields() void {
+ if (host_fields_ready) return;
+ host_fields_ready = true;
+ const arch = nodeArch(builtin.cpu.arch);
+ var host_raw: [256]u8 = undefined;
+ var rel_raw: [128]u8 = undefined;
+ var product_raw: [64]u8 = undefined;
+ device_name = persistAscii(&device_name_buf, readHostname(&host_raw));
+ os_version = persistAscii(&os_version_buf, readOsRelease(&rel_raw));
+ const product = readMacosProduct(&product_raw);
+ device_model = formatDeviceModel(&device_model_buf, builtin.os.tag, os_version, product, arch);
+}
+
+/// Kimi Code sends a stable random device id with its X-Msh identity headers.
+/// Graff owns a separate ~/.kimi/device_id so it never mutates another CLI's
+/// credential store or impersonates that installation.
+pub fn initIdentity(io: Io, arena: Allocator, home: []const u8) void {
+ fillHostFields();
+ if (!std.mem.eql(u8, device_id, "unknown") or home.len == 0) return;
+ const dir = std.fmt.allocPrint(arena, "{s}/.kimi", .{home}) catch return;
+ const path = std.fmt.allocPrint(arena, "{s}/device_id", .{dir}) catch return;
+ if (Io.Dir.cwd().readFileAlloc(io, path, arena, .limited(128))) |raw| {
+ const value = std.mem.trim(u8, raw, " \t\r\n");
+ if (validDeviceId(value)) {
+ device_id = arena.dupe(u8, value) catch "unknown";
+ secureDir(io, dir);
+ const file = Io.Dir.cwd().openFile(io, path, .{ .mode = .read_only }) catch return;
+ defer file.close(io);
+ file.setPermissions(io, private_file_permissions) catch {};
+ return;
+ }
+ } else |_| {}
+ var random: [16]u8 = undefined;
+ io.random(&random);
+ random[6] = (random[6] & 0x0f) | 0x40;
+ random[8] = (random[8] & 0x3f) | 0x80;
+ const hex = std.fmt.bytesToHex(random, .lower);
+ const id = arena.alloc(u8, 36) catch return;
+ @memcpy(id[0..8], hex[0..8]);
+ id[8] = '-';
+ @memcpy(id[9..13], hex[8..12]);
+ id[13] = '-';
+ @memcpy(id[14..18], hex[12..16]);
+ id[18] = '-';
+ @memcpy(id[19..23], hex[16..20]);
+ id[23] = '-';
+ @memcpy(id[24..36], hex[20..32]);
+ device_id = id;
+ Io.Dir.cwd().createDir(io, dir, private_dir_permissions) catch {};
+ secureDir(io, dir);
+ const file = Io.Dir.cwd().createFile(io, path, .{ .permissions = private_file_permissions }) catch return;
+ defer file.close(io);
+ file.setPermissions(io, private_file_permissions) catch {};
+ var buf: [64]u8 = undefined;
+ var writer = file.writer(io, &buf);
+ writer.interface.print("{s}\n", .{id}) catch return;
+ writer.interface.flush() catch {};
+}
+
+pub fn identityHeaders(buf: []std.http.Header) []std.http.Header {
+ fillHostFields();
+ if (buf.len < 6) return buf[0..0];
+ buf[0] = .{ .name = "X-Msh-Platform", .value = platform };
+ buf[1] = .{ .name = "X-Msh-Version", .value = version };
+ buf[2] = .{ .name = "X-Msh-Device-Name", .value = device_name };
+ buf[3] = .{ .name = "X-Msh-Device-Model", .value = device_model };
+ buf[4] = .{ .name = "X-Msh-Os-Version", .value = os_version };
+ buf[5] = .{ .name = "X-Msh-Device-Id", .value = device_id };
+ return buf[0..6];
+}
+
+test "user_agent is graff/<version>, not a spoofed kimi-code-cli token" {
+ try std.testing.expect(std.mem.startsWith(u8, user_agent, "graff/"));
+ try std.testing.expect(std.mem.indexOf(u8, user_agent, "kimi-code-cli") == null);
+ try std.testing.expect(std.mem.indexOf(u8, user_agent, "claude-code") == null);
+}
+
+test "nodeArch matches Node os.arch() names kimi-code puts in Device-Model" {
+ try std.testing.expectEqualStrings("x64", nodeArch(.x86_64));
+ try std.testing.expectEqualStrings("arm64", nodeArch(.aarch64));
+ try std.testing.expectEqualStrings("ia32", nodeArch(.x86));
+}
+
+test "formatDeviceModel matches kimi-code deviceModel() on Windows, macOS, Linux" {
+ var buf: [64]u8 = undefined;
+ try std.testing.expectEqualStrings(
+ "Windows 10.0.26100 x64",
+ formatDeviceModel(&buf, .windows, "10.0.26100", null, "x64"),
+ );
+ try std.testing.expectEqualStrings(
+ "macOS 15.4.1 arm64",
+ formatDeviceModel(&buf, .macos, "24.4.0", "15.4.1", "arm64"),
+ );
+ try std.testing.expectEqualStrings(
+ "macOS 24.4.0 arm64",
+ formatDeviceModel(&buf, .macos, "24.4.0", null, "arm64"),
+ );
+ try std.testing.expectEqualStrings(
+ "Linux 6.8.0-101-generic x64",
+ formatDeviceModel(&buf, .linux, "6.8.0-101-generic", null, "x64"),
+ );
+}
+
+test "persistAscii strips non-ASCII and falls back like kimi-code asciiHeader" {
+ var buf: [32]u8 = undefined;
+ try std.testing.expectEqualStrings("host", persistAscii(&buf, " host "));
+ try std.testing.expectEqualStrings("abc", persistAscii(&buf, "ab\x80c"));
+ try std.testing.expectEqualStrings("unknown", persistAscii(&buf, "\x80\x81"));
+ try std.testing.expectEqualStrings("unknown", persistAscii(&buf, " "));
+}
+
+test "identityHeaders use hostname and Node-shaped model, not zig os tags" {
+ var headers: [6]std.http.Header = undefined;
+ const got = identityHeaders(&headers);
+ try std.testing.expectEqual(@as(usize, 6), got.len);
+ try std.testing.expectEqualStrings("X-Msh-Platform", got[0].name);
+ try std.testing.expectEqualStrings("kimi_code_cli", got[0].value);
+ try std.testing.expectEqualStrings(version, got[1].value);
+ try std.testing.expectEqualStrings(device_name, got[2].value);
+ try std.testing.expect(device_name.len > 0);
+ try std.testing.expect(!std.mem.eql(u8, device_name, "unknown"));
+ const prefix = switch (builtin.os.tag) {
+ .windows => "Windows ",
+ .macos => "macOS ",
+ .linux => "Linux ",
+ else => "",
+ };
+ if (prefix.len != 0) try std.testing.expect(std.mem.startsWith(u8, got[3].value, prefix));
+ try std.testing.expect(std.mem.endsWith(u8, got[3].value, nodeArch(builtin.cpu.arch)));
+ try std.testing.expect(!std.mem.eql(u8, got[4].value, @tagName(builtin.os.tag)));
+}
diff --git a/src/main.zig b/src/main.zig
index daa7e1f9..ce1b54ee 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -562,8 +562,8 @@ pub const Agent = agent_mod.Agent;
const messages_mod = @import("messages.zig");
/// A base64-encoded image staged by `/image`, sent with the next user turn.
const vision = @import("vision.zig"); // staged-image type, /image·/paste stagers, macOS clipboard grab
-/// User-Agent for outbound provider calls. The Kimi for Coding plan gates access by User-Agent (a graff/* or bare UA gets `access_terminated`), so
-/// graff identifies as claude-code/1.0.0 — a user's Kimi Code key then works here the same as in Kimi CLI or Claude Code. Other providers keep the default.
+/// User-Agent for outbound Kimi Coding calls is `graff/<version>` (Moonshot forbids spoofing).
+/// Device headers follow kimi-code's X-Msh-* shapes. Other providers keep the default UA.
pub const kimi_user_agent = @import("kimi_catalog.zig").user_agent;
// HTTP transport (auth headers, raw POST, 5xx-body capture, watchdogs) lives in http.zig.
const http = @import("http.zig");