Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b597496b3 | ||
|
|
8ce3f290ed | ||
|
|
8639188968 | ||
|
|
45ec073e6f |
No files matched your search
@@ -123,7 +123,7 @@
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
按工作区隔离浏览 Kimi Code 会话,支持活跃/已归档/全部筛选;流式逐行预览(20MB 字节上限,500 字符折叠);归档/取消归档/批量删除。
|
按工作区隔离浏览 Kimi Code 会话,支持活跃/已归档/全部筛选;流式逐行预览(20MB 字节上限,500 字符折叠);归档/取消归档/批量删除。归档写入 `state.json` 元数据(与 CLI v2 一致),旧版本物理归档目录 `.kcd-archive/` 仍可识别与恢复。
|
||||||
|
|
||||||
## 架构总览
|
## 架构总览
|
||||||
|
|
||||||
@@ -239,7 +239,7 @@
|
|||||||
|
|
||||||
- 按工作区隔离浏览 Kimi Code 会话,支持活跃/已归档/全部筛选
|
- 按工作区隔离浏览 Kimi Code 会话,支持活跃/已归档/全部筛选
|
||||||
- 流式逐行预览(20MB 字节上限,500 字符折叠可展开)
|
- 流式逐行预览(20MB 字节上限,500 字符折叠可展开)
|
||||||
- 归档 / 取消归档 / 批量删除
|
- 归档 / 取消归档 / 批量删除(归档写入 `state.json` 元数据,与 CLI v2 一致;旧版本物理归档目录 `.kcd-archive/` 仍可识别与恢复)
|
||||||
- 早期版本的"闪崩"已通过流式读取 + 限制解决
|
- 早期版本的"闪崩"已通过流式读取 + 限制解决
|
||||||
|
|
||||||
### 设置面板
|
### 设置面板
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "kimiswitch",
|
"name": "kimiswitch",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.7.10",
|
"version": "0.7.11",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
## v0.7.11
|
||||||
|
|
||||||
|
### 适配 kimi-code 0.39.1
|
||||||
|
|
||||||
|
- **修复:`[thinking]` 保留开关不再破坏思考配置**。此前在 UI 关闭"保留思考内容"会写入布尔 `keep = false`,而上游两个引擎都只接受字符串——v2 会把整个 `[thinking]` 节校验失败并丢弃。现改为写 `keep = "off"`,存量配置里的布尔值加载时自动归一化
|
||||||
|
- **修复:`loop_control` 不再触发上游废弃告警**。默认只写新键 `max_attempts_per_step` 并清理存量旧键 `max_retries_per_step`;仅检测到 `KIMI_CODE_LEGACY_FLAG`(v1 引擎)时才双写
|
||||||
|
- **思考强度移除 `max` 档**(上游已自动迁移为 `high`),存量配置显示归一
|
||||||
|
- **实验开关同步上游全集**:新增 remote-control;`wait_for` 与 persistence_minidb_readmodel 已在上游转正默认开启,UI 会标注"默认开启"(显式关闭优先)
|
||||||
|
|
||||||
|
### 会话归档与上游 v2 对齐
|
||||||
|
|
||||||
|
- **归档不再搬动文件**:改为在会话 `state.json` 写入 `archived`/`archivedAt` 元数据(与 CLI v2 的 `setArchived` 逐字段一致),CLI 侧与 Kimi Switch 侧归档状态从此互通
|
||||||
|
- 旧版本物理归档的会话(`.kcd-archive/` 目录)仍可识别为已归档并正常恢复
|
||||||
|
- 归档不再改写 `session_index.jsonl`(删除会话的行为不变)
|
||||||
|
|
||||||
|
### 子代理模型池修复
|
||||||
|
|
||||||
|
- **修复:模型池无法添加第二个条目**。从"仅默认模型"的隐式单条目形态添加条目时,默认模型现在会自动物化进池,不再被"默认模型不在模型池中"的校验拦截
|
||||||
|
|
||||||
|
### 模型数据同步
|
||||||
|
|
||||||
|
- models.dev 快照刷新至 **7482 个模型 / 207 个供应商**
|
||||||
Generated
+1
-1
@@ -1978,7 +1978,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kimiswitch"
|
name = "kimiswitch"
|
||||||
version = "0.7.10"
|
version = "0.7.11"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "kimiswitch"
|
name = "kimiswitch"
|
||||||
version = "0.7.10"
|
version = "0.7.11"
|
||||||
description = "Kimi Switch - model config manager"
|
description = "Kimi Switch - model config manager"
|
||||||
authors = ["codingplan.site"]
|
authors = ["codingplan.site"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|||||||
@@ -1293,21 +1293,24 @@ pub async fn kimi_oauth_poll(
|
|||||||
// Experimental feature env-var probe (Kimi Code secondary model etc.)
|
// Experimental feature env-var probe (Kimi Code secondary model etc.)
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
/// Read the Kimi Code experimental-feature environment variables that are
|
/// Read the Kimi Code environment variables that are currently set (non-empty)
|
||||||
/// currently set (non-empty) in this process's environment. The frontend
|
/// in this process's environment. The experimental-feature vars are used by the
|
||||||
/// uses the result to mark config.toml `[experimental]` toggles as locked:
|
/// frontend to mark config.toml `[experimental]` toggles as locked: env vars
|
||||||
/// env vars outrank the config file in Kimi Code's flag resolution.
|
/// outrank the config file in Kimi Code's flag resolution. `KIMI_CODE_LEGACY_FLAG`
|
||||||
|
/// is probed too — the AgentSettingsPanel uses it to decide whether to
|
||||||
|
/// dual-write the v1 engine's loop_control keys.
|
||||||
///
|
///
|
||||||
/// Truthy values per the CLI: `1` / `true` / `yes` / `on` (case-insensitive);
|
/// Truthy values per the CLI: `1` / `true` / `yes` / `on` (case-insensitive);
|
||||||
/// the raw values are returned and the truthy check happens on the frontend.
|
/// the raw values are returned and the truthy check happens on the frontend.
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn get_experimental_env_status() -> HashMap<String, String> {
|
pub fn get_experimental_env_status() -> HashMap<String, String> {
|
||||||
const VARS: [&str; 5] = [
|
const VARS: [&str; 6] = [
|
||||||
"KIMI_CODE_EXPERIMENTAL_FLAG",
|
"KIMI_CODE_EXPERIMENTAL_FLAG",
|
||||||
"KIMI_CODE_EXPERIMENTAL_SECONDARY_MODEL",
|
"KIMI_CODE_EXPERIMENTAL_SECONDARY_MODEL",
|
||||||
"KIMI_CODE_EXPERIMENTAL_TOOL_SELECT",
|
"KIMI_CODE_EXPERIMENTAL_TOOL_SELECT",
|
||||||
"KIMI_CODE_EXPERIMENTAL_ACP_V2",
|
|
||||||
"KIMI_CODE_EXPERIMENTAL_PERSISTENCE_MINIDB_READMODEL",
|
"KIMI_CODE_EXPERIMENTAL_PERSISTENCE_MINIDB_READMODEL",
|
||||||
|
"KIMI_CODE_EXPERIMENTAL_REMOTE_CONTROL",
|
||||||
|
"KIMI_CODE_LEGACY_FLAG",
|
||||||
];
|
];
|
||||||
let mut out = HashMap::new();
|
let mut out = HashMap::new();
|
||||||
for name in VARS {
|
for name in VARS {
|
||||||
|
|||||||
+343
-34
@@ -1234,6 +1234,49 @@ fn read_state_safe(session_dir: &Path) -> (Option<String>, Option<String>, Optio
|
|||||||
(None, None, None, None)
|
(None, None, None, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether a session is archived per its `state.json` metadata: the
|
||||||
|
/// kimi-code v2 engine writes `archived: true` (plus an `archivedAt` epoch-ms
|
||||||
|
/// timestamp) when archiving and clears both on restore. Unparseable or
|
||||||
|
/// missing state.json counts as not archived (and won't panic).
|
||||||
|
fn read_state_archived(session_dir: &Path) -> bool {
|
||||||
|
let sp = session_dir.join("state.json");
|
||||||
|
let Ok(content) = fs::read_to_string(&sp) else { return false };
|
||||||
|
let Ok(obj) = serde_json::from_str::<serde_json::Value>(&content) else { return false };
|
||||||
|
obj.get("archived").and_then(|v| v.as_bool()).unwrap_or(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set or clear the archived metadata on a session's `state.json`, preserving
|
||||||
|
/// every other field. Mirrors upstream kimi-code v2 `SessionMetadata.setArchived`:
|
||||||
|
/// archive writes `{ archived: true, archivedAt: Date.now() }` (epoch ms, same
|
||||||
|
/// `Date.now()` format as the CLI), restore writes `{ archived: false }` and
|
||||||
|
/// drops the `archivedAt` key; `updatedAt` is untouched in both cases.
|
||||||
|
/// The write is atomic (tmp file + rename), same pattern as the plugin store.
|
||||||
|
/// Missing or malformed state.json returns a descriptive error, never a panic.
|
||||||
|
fn set_session_archived_meta(session_dir: &Path, archived: bool) -> Result<(), String> {
|
||||||
|
let sp = session_dir.join("state.json");
|
||||||
|
let content = fs::read_to_string(&sp).map_err(|e| format!("read state.json: {e}"))?;
|
||||||
|
let mut obj: serde_json::Value =
|
||||||
|
serde_json::from_str(&content).map_err(|e| format!("parse state.json: {e}"))?;
|
||||||
|
let obj = obj
|
||||||
|
.as_object_mut()
|
||||||
|
.ok_or_else(|| "state.json is not a JSON object".to_string())?;
|
||||||
|
obj.insert("archived".into(), serde_json::Value::Bool(archived));
|
||||||
|
if archived {
|
||||||
|
let now_ms = std::time::SystemTime::now()
|
||||||
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
|
.unwrap_or_default()
|
||||||
|
.as_millis() as u64;
|
||||||
|
obj.insert("archivedAt".into(), serde_json::Value::Number(now_ms.into()));
|
||||||
|
} else {
|
||||||
|
obj.remove("archivedAt");
|
||||||
|
}
|
||||||
|
let out = serde_json::to_string(&obj).map_err(|e| format!("serialize state.json: {e}"))?;
|
||||||
|
let tmp = sp.with_file_name("state.json.tmp");
|
||||||
|
fs::write(&tmp, out).map_err(|e| format!("write state.json: {e}"))?;
|
||||||
|
fs::rename(&tmp, &sp).map_err(|e| format!("commit state.json: {e}"))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn humanize_workspace(id: &str) -> String {
|
fn humanize_workspace(id: &str) -> String {
|
||||||
let re = Regex::new(r"^wd_(.+)_[0-9a-fA-F]{8,}$").unwrap();
|
let re = Regex::new(r"^wd_(.+)_[0-9a-fA-F]{8,}$").unwrap();
|
||||||
if let Some(caps) = re.captures(id) {
|
if let Some(caps) = re.captures(id) {
|
||||||
@@ -1243,7 +1286,11 @@ fn humanize_workspace(id: &str) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list_sessions_in_dir(dir: &Path, workspace_id: &str, status: &str) -> Vec<SessionRow> {
|
/// List session rows under one directory. `in_archive_dir` marks `.kcd-archive`
|
||||||
|
/// (legacy physical archive); a session is additionally archived when its own
|
||||||
|
/// `state.json` carries `archived: true` — so CLI-v2 metadata-archived sessions
|
||||||
|
/// that still live at the active root are correctly classified.
|
||||||
|
fn list_sessions_in_dir(dir: &Path, workspace_id: &str, in_archive_dir: bool) -> Vec<SessionRow> {
|
||||||
let mut sessions = Vec::new();
|
let mut sessions = Vec::new();
|
||||||
if !dir.exists() { return sessions; }
|
if !dir.exists() { return sessions; }
|
||||||
let re = session_re();
|
let re = session_re();
|
||||||
@@ -1251,6 +1298,8 @@ fn list_sessions_in_dir(dir: &Path, workspace_id: &str, status: &str) -> Vec<Ses
|
|||||||
if !entry.file_type().map(|t| t.is_dir()).unwrap_or(false) { continue; }
|
if !entry.file_type().map(|t| t.is_dir()).unwrap_or(false) { continue; }
|
||||||
let name = entry.file_name().to_string_lossy().to_string();
|
let name = entry.file_name().to_string_lossy().to_string();
|
||||||
if !re.is_match(&name) { continue; }
|
if !re.is_match(&name) { continue; }
|
||||||
|
let archived = in_archive_dir || read_state_archived(&entry.path());
|
||||||
|
let status = if archived { "archived" } else { "active" };
|
||||||
let (title, work_dir, created_at, updated_at) = read_state_safe(&entry.path());
|
let (title, work_dir, created_at, updated_at) = read_state_safe(&entry.path());
|
||||||
let (bytes, files) = file_size_approx(&entry.path());
|
let (bytes, files) = file_size_approx(&entry.path());
|
||||||
let mtime = entry.path().metadata().ok().and_then(|m| m.modified().ok())
|
let mtime = entry.path().metadata().ok().and_then(|m| m.modified().ok())
|
||||||
@@ -1311,19 +1360,33 @@ fn list_sessions_cmd(home: &Path, status: &str, workspace_filter: Option<String>
|
|||||||
|
|
||||||
let active_dir = root.join(wid);
|
let active_dir = root.join(wid);
|
||||||
let arch_dir = archive_root.join(wid);
|
let arch_dir = archive_root.join(wid);
|
||||||
let active_all = list_sessions_in_dir(&active_dir, wid, "active");
|
// Merge both sources, deduping by session id (ids are UUIDs and never
|
||||||
let arch_all = list_sessions_in_dir(&arch_dir, wid, "archived");
|
// reused; a stale legacy copy under .kcd-archive loses to the entry at
|
||||||
let active_list = if status == "archived" { vec![] } else { active_all.clone() };
|
// the active root). Status comes from each row, so metadata-archived
|
||||||
let arch_list = if status == "active" { vec![] } else { arch_all.clone() };
|
// sessions surface in the archived filter and the archive-only counts.
|
||||||
|
let mut by_id: HashMap<String, SessionRow> = HashMap::new();
|
||||||
|
for row in list_sessions_in_dir(&active_dir, wid, false) {
|
||||||
|
by_id.insert(row.id.clone(), row);
|
||||||
|
}
|
||||||
|
for row in list_sessions_in_dir(&arch_dir, wid, true) {
|
||||||
|
by_id.entry(row.id.clone()).or_insert(row);
|
||||||
|
}
|
||||||
|
let all: Vec<SessionRow> = by_id.into_values().collect();
|
||||||
|
let active_count = all.iter().filter(|s| s.status == "active").count();
|
||||||
|
let archived_count = all.iter().filter(|s| s.status == "archived").count();
|
||||||
|
let listed: Vec<SessionRow> = match status {
|
||||||
|
"active" => all.iter().filter(|s| s.status == "active").cloned().collect(),
|
||||||
|
"archived" => all.iter().filter(|s| s.status == "archived").cloned().collect(),
|
||||||
|
_ => all,
|
||||||
|
};
|
||||||
|
|
||||||
let empty = active_all.is_empty() && arch_all.is_empty();
|
let empty = active_count == 0 && archived_count == 0;
|
||||||
workspaces.push(WorkspaceRow {
|
workspaces.push(WorkspaceRow {
|
||||||
id: wid.clone(), name, root: root_path,
|
id: wid.clone(), name, root: root_path,
|
||||||
created_at: None, last_opened_at: None,
|
created_at: None, last_opened_at: None,
|
||||||
active_count: active_all.len(), archived_count: arch_all.len(), empty,
|
active_count, archived_count, empty,
|
||||||
});
|
});
|
||||||
all_sessions.extend(active_list);
|
all_sessions.extend(listed);
|
||||||
all_sessions.extend(arch_list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
all_sessions.sort_by(|a, b| {
|
all_sessions.sort_by(|a, b| {
|
||||||
@@ -1356,38 +1419,57 @@ fn assert_safe_path(home: &Path, workspace_id: &str, session_id: &str) -> Result
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn archive_session_cmd(home: &Path, workspace_id: &str, session_id: &str) -> Result<ActionResponse, String> {
|
fn archive_session_cmd(home: &Path, workspace_id: &str, session_id: &str) -> Result<ActionResponse, String> {
|
||||||
let src = assert_safe_path(home, workspace_id, session_id)?;
|
let dir = assert_safe_path(home, workspace_id, session_id)?;
|
||||||
let dest = sessions_root(home).join(".kcd-archive").join(workspace_id).join(session_id);
|
if !dir.exists() { return Err("session not found".into()); }
|
||||||
if !src.exists() { return Err("session not found".into()); }
|
// Metadata archive, matching upstream kimi-code v2: write `archived: true`
|
||||||
if let Some(parent) = dest.parent() {
|
// + `archivedAt` into state.json, leave the session directory in place, and
|
||||||
fs::create_dir_all(parent).map_err(|e| format!("mkdir: {}", e))?;
|
// do NOT touch session_index.jsonl — archived state is derived from
|
||||||
|
// state.json, and the CLI reconciles its own index mirror. A session
|
||||||
|
// without a readable state.json gets a clear error rather than a panic.
|
||||||
|
let sp = dir.join("state.json");
|
||||||
|
if !sp.is_file() {
|
||||||
|
return Err(format!("session {session_id} has no state.json; cannot archive"));
|
||||||
}
|
}
|
||||||
fs::rename(&src, &dest).or_else(|_| {
|
set_session_archived_meta(&dir, true)?;
|
||||||
// cross-device fallback
|
|
||||||
fs_extra::dir::copy(&src, dest.parent().unwrap(), &Default::default()).ok();
|
|
||||||
fs::remove_dir_all(&src).ok();
|
|
||||||
Ok::<(), String>(())
|
|
||||||
}).map_err(|e: String| format!("move: {}", e))?;
|
|
||||||
scrub_session_index(home, session_id);
|
|
||||||
Ok(ActionResponse {
|
Ok(ActionResponse {
|
||||||
ok: true, workspace_id: workspace_id.to_string(),
|
ok: true, workspace_id: workspace_id.to_string(),
|
||||||
session_id: session_id.to_string(), status: Some("archived".into()),
|
session_id: session_id.to_string(), status: Some("archived".into()),
|
||||||
path: Some(dest.to_string_lossy().to_string()), deleted: None,
|
path: Some(dir.to_string_lossy().to_string()), deleted: None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unarchive_session_cmd(home: &Path, workspace_id: &str, session_id: &str) -> Result<ActionResponse, String> {
|
fn unarchive_session_cmd(home: &Path, workspace_id: &str, session_id: &str) -> Result<ActionResponse, String> {
|
||||||
let src = sessions_root(home).join(".kcd-archive").join(workspace_id).join(session_id);
|
|
||||||
let dest = assert_safe_path(home, workspace_id, session_id)?;
|
let dest = assert_safe_path(home, workspace_id, session_id)?;
|
||||||
if !src.exists() { return Err("archived session not found".into()); }
|
// 1) Legacy recovery: sessions physically moved to .kcd-archive by older
|
||||||
if let Some(parent) = dest.parent() {
|
// KimiSwitch versions are moved back, then their metadata flag is
|
||||||
fs::create_dir_all(parent).map_err(|e| format!("mkdir: {}", e))?;
|
// cleared per upstream restore semantics (archived:false + archivedAt
|
||||||
|
// dropped). A missing state.json is fine here — there is no flag.
|
||||||
|
let archived_dir = sessions_root(home).join(".kcd-archive").join(workspace_id).join(session_id);
|
||||||
|
if archived_dir.exists() {
|
||||||
|
if let Some(parent) = dest.parent() {
|
||||||
|
fs::create_dir_all(parent).map_err(|e| format!("mkdir: {}", e))?;
|
||||||
|
}
|
||||||
|
fs::rename(&archived_dir, &dest).or_else(|_| {
|
||||||
|
// cross-device fallback
|
||||||
|
fs_extra::dir::copy(&archived_dir, dest.parent().unwrap(), &Default::default()).ok();
|
||||||
|
fs::remove_dir_all(&archived_dir).ok();
|
||||||
|
Ok::<(), String>(())
|
||||||
|
}).map_err(|e: String| format!("move: {}", e))?;
|
||||||
|
// The move already restored the session; a corrupt state.json must not
|
||||||
|
// turn a successful restore into an error — the session simply lists
|
||||||
|
// as active with its flag intact.
|
||||||
|
if dest.join("state.json").is_file() {
|
||||||
|
let _ = set_session_archived_meta(&dest, false);
|
||||||
|
}
|
||||||
|
return Ok(ActionResponse {
|
||||||
|
ok: true, workspace_id: workspace_id.to_string(),
|
||||||
|
session_id: session_id.to_string(), status: Some("active".into()),
|
||||||
|
path: Some(dest.to_string_lossy().to_string()), deleted: None,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
fs::rename(&src, &dest).or_else(|_| {
|
// 2) Metadata-archived session: still at the active root, just clear the flag.
|
||||||
fs_extra::dir::copy(&src, dest.parent().unwrap(), &Default::default()).ok();
|
if !dest.exists() { return Err("archived session not found".into()); }
|
||||||
fs::remove_dir_all(&src).ok();
|
set_session_archived_meta(&dest, false)?;
|
||||||
Ok::<(), String>(())
|
|
||||||
}).map_err(|e: String| format!("move: {}", e))?;
|
|
||||||
Ok(ActionResponse {
|
Ok(ActionResponse {
|
||||||
ok: true, workspace_id: workspace_id.to_string(),
|
ok: true, workspace_id: workspace_id.to_string(),
|
||||||
session_id: session_id.to_string(), status: Some("active".into()),
|
session_id: session_id.to_string(), status: Some("active".into()),
|
||||||
@@ -1398,6 +1480,9 @@ fn unarchive_session_cmd(home: &Path, workspace_id: &str, session_id: &str) -> R
|
|||||||
fn delete_session_cmd(home: &Path, workspace_id: &str, session_id: &str, status_hint: Option<&str>) -> Result<ActionResponse, String> {
|
fn delete_session_cmd(home: &Path, workspace_id: &str, session_id: &str, status_hint: Option<&str>) -> Result<ActionResponse, String> {
|
||||||
let active = assert_safe_path(home, workspace_id, session_id)?;
|
let active = assert_safe_path(home, workspace_id, session_id)?;
|
||||||
let archived = sessions_root(home).join(".kcd-archive").join(workspace_id).join(session_id);
|
let archived = sessions_root(home).join(".kcd-archive").join(workspace_id).join(session_id);
|
||||||
|
// Metadata-archived sessions still live at the active root, so a
|
||||||
|
// status_hint of "archived" with no legacy .kcd-archive copy falls through
|
||||||
|
// to the default arm and removes the in-place directory.
|
||||||
let target = match status_hint {
|
let target = match status_hint {
|
||||||
Some("archived") if archived.exists() => archived,
|
Some("archived") if archived.exists() => archived,
|
||||||
Some("active") if active.exists() => active,
|
Some("active") if active.exists() => active,
|
||||||
@@ -1440,11 +1525,11 @@ fn delete_workspace_cmd(home: &Path, workspace_id: &str, _confirm: bool, _force:
|
|||||||
let arch_dir = root.join(".kcd-archive").join(workspace_id);
|
let arch_dir = root.join(".kcd-archive").join(workspace_id);
|
||||||
|
|
||||||
if active_dir.exists() {
|
if active_dir.exists() {
|
||||||
let active_list = list_sessions_in_dir(&active_dir, workspace_id, "active");
|
let active_list = list_sessions_in_dir(&active_dir, workspace_id, false);
|
||||||
if !active_list.is_empty() { return Err("workspace is not empty; archive/delete sessions first".into()); }
|
if !active_list.is_empty() { return Err("workspace is not empty; archive/delete sessions first".into()); }
|
||||||
}
|
}
|
||||||
if arch_dir.exists() {
|
if arch_dir.exists() {
|
||||||
let arch_list = list_sessions_in_dir(&arch_dir, workspace_id, "archived");
|
let arch_list = list_sessions_in_dir(&arch_dir, workspace_id, true);
|
||||||
if !arch_list.is_empty() { return Err("workspace is not empty; archive/delete sessions first".into()); }
|
if !arch_list.is_empty() { return Err("workspace is not empty; archive/delete sessions first".into()); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1546,6 +1631,10 @@ fn get_session_preview_cmd(home: &Path, workspace_id: &str, session_id: &str, st
|
|||||||
let archived = root.join(".kcd-archive").join(workspace_id).join(session_id);
|
let archived = root.join(".kcd-archive").join(workspace_id).join(session_id);
|
||||||
let session_dir = match status_hint {
|
let session_dir = match status_hint {
|
||||||
Some("archived") if archived.exists() => archived,
|
Some("archived") if archived.exists() => archived,
|
||||||
|
// Metadata-archived sessions stay at the active root (kimi-code v2
|
||||||
|
// writes state.json.archived, no physical move) — read them in place.
|
||||||
|
Some("archived") if active.exists() => active,
|
||||||
|
Some("active") if active.exists() => active,
|
||||||
_ => if active.exists() { active } else if archived.exists() { archived }
|
_ => if active.exists() { active } else if archived.exists() { archived }
|
||||||
else { return Err("session not found".into()); }
|
else { return Err("session not found".into()); }
|
||||||
};
|
};
|
||||||
@@ -1666,7 +1755,11 @@ fn get_session_preview_cmd(home: &Path, workspace_id: &str, session_id: &str, st
|
|||||||
Ok(PreviewResult {
|
Ok(PreviewResult {
|
||||||
workspace_id: workspace_id.to_string(),
|
workspace_id: workspace_id.to_string(),
|
||||||
session_id: session_id.to_string(),
|
session_id: session_id.to_string(),
|
||||||
status: if session_dir.to_string_lossy().contains(".kcd-archive") { "archived".into() } else { "active".into() },
|
status: if session_dir.to_string_lossy().contains(".kcd-archive") || read_state_archived(&session_dir) {
|
||||||
|
"archived".into()
|
||||||
|
} else {
|
||||||
|
"active".into()
|
||||||
|
},
|
||||||
title, work_dir, created_at, updated_at,
|
title, work_dir, created_at, updated_at,
|
||||||
message_count: messages.len(),
|
message_count: messages.len(),
|
||||||
truncated,
|
truncated,
|
||||||
@@ -1998,3 +2091,219 @@ mod pricing_tests {
|
|||||||
assert_eq!(ch, 0.11);
|
assert_eq!(ch, 0.11);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod session_tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
const WID: &str = "wd_proj_a1b2c3d4e5f6";
|
||||||
|
const SID: &str = "session_11111111-2222-3333-4444-555555555555";
|
||||||
|
|
||||||
|
fn setup_home() -> (tempfile::TempDir, PathBuf) {
|
||||||
|
let td = tempfile::tempdir().unwrap();
|
||||||
|
let home = td.path().join("home");
|
||||||
|
fs::create_dir_all(home.join("sessions").join(WID)).unwrap();
|
||||||
|
(td, home)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn active_dir(home: &Path) -> PathBuf {
|
||||||
|
home.join("sessions").join(WID)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn legacy_arch_dir(home: &Path) -> PathBuf {
|
||||||
|
home.join("sessions").join(".kcd-archive").join(WID)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_state(session_dir: &Path, archived: bool, archived_at: Option<u64>) {
|
||||||
|
let mut obj = serde_json::json!({
|
||||||
|
"id": SID,
|
||||||
|
"version": 2,
|
||||||
|
"cwd": "/tmp/work",
|
||||||
|
"createdAt": 1_700_000_000_000u64,
|
||||||
|
"updatedAt": 1_700_000_000_000u64,
|
||||||
|
"archived": archived,
|
||||||
|
"title": "test session",
|
||||||
|
});
|
||||||
|
let o = obj.as_object_mut().unwrap();
|
||||||
|
match archived_at {
|
||||||
|
Some(at) => { o.insert("archivedAt".into(), serde_json::json!(at)); }
|
||||||
|
None => { o.remove("archivedAt"); }
|
||||||
|
}
|
||||||
|
fs::write(session_dir.join("state.json"), serde_json::to_string(&obj).unwrap()).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_state_json(session_dir: &Path) -> serde_json::Value {
|
||||||
|
serde_json::from_str(&fs::read_to_string(session_dir.join("state.json")).unwrap()).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn metadata_archive_roundtrip() {
|
||||||
|
let (_td, home) = setup_home();
|
||||||
|
let dir = active_dir(&home).join(SID);
|
||||||
|
fs::create_dir_all(&dir).unwrap();
|
||||||
|
write_state(&dir, false, None);
|
||||||
|
|
||||||
|
// Fresh session lists as active.
|
||||||
|
let res = list_sessions_cmd(&home, "all", None);
|
||||||
|
assert_eq!(res.sessions.len(), 1);
|
||||||
|
assert_eq!(res.sessions[0].status, "active");
|
||||||
|
assert_eq!(res.workspaces[0].active_count, 1);
|
||||||
|
assert_eq!(res.workspaces[0].archived_count, 0);
|
||||||
|
|
||||||
|
// Archive is metadata-only: dir stays put, flag + epoch-ms archivedAt written.
|
||||||
|
let ar = archive_session_cmd(&home, WID, SID).unwrap();
|
||||||
|
assert_eq!(ar.status.as_deref(), Some("archived"));
|
||||||
|
assert!(dir.exists(), "metadata archive must not move the session dir");
|
||||||
|
assert!(!legacy_arch_dir(&home).join(SID).exists(), "nothing moves into .kcd-archive");
|
||||||
|
let st = read_state_json(&dir);
|
||||||
|
assert_eq!(st["archived"], true);
|
||||||
|
let archived_at = st["archivedAt"].as_u64().expect("archivedAt as epoch ms");
|
||||||
|
assert!(archived_at > 0, "archivedAt is a Date.now()-style epoch-ms number");
|
||||||
|
|
||||||
|
// List reflects the new status.
|
||||||
|
let res = list_sessions_cmd(&home, "all", None);
|
||||||
|
assert_eq!(res.sessions[0].status, "archived");
|
||||||
|
assert_eq!(res.workspaces[0].active_count, 0);
|
||||||
|
assert_eq!(res.workspaces[0].archived_count, 1);
|
||||||
|
assert!(list_sessions_cmd(&home, "active", None).sessions.is_empty());
|
||||||
|
assert_eq!(list_sessions_cmd(&home, "archived", None).sessions.len(), 1);
|
||||||
|
|
||||||
|
// Unarchive clears the flag in place (archived:false, archivedAt dropped).
|
||||||
|
let ur = unarchive_session_cmd(&home, WID, SID).unwrap();
|
||||||
|
assert_eq!(ur.status.as_deref(), Some("active"));
|
||||||
|
assert!(dir.exists(), "unarchive must not move the dir either");
|
||||||
|
let st = read_state_json(&dir);
|
||||||
|
assert_eq!(st["archived"], false);
|
||||||
|
assert!(st.get("archivedAt").is_none(), "archivedAt key removed on restore");
|
||||||
|
|
||||||
|
let res = list_sessions_cmd(&home, "all", None);
|
||||||
|
assert_eq!(res.sessions[0].status, "active");
|
||||||
|
assert_eq!(res.workspaces[0].active_count, 1);
|
||||||
|
assert_eq!(res.workspaces[0].archived_count, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn metadata_archive_preserves_other_state_fields() {
|
||||||
|
let (_td, home) = setup_home();
|
||||||
|
let dir = active_dir(&home).join(SID);
|
||||||
|
fs::create_dir_all(&dir).unwrap();
|
||||||
|
let mut obj = serde_json::json!({
|
||||||
|
"id": SID,
|
||||||
|
"version": 2,
|
||||||
|
"cwd": "/repo",
|
||||||
|
"createdAt": 1,
|
||||||
|
"updatedAt": 2,
|
||||||
|
"archived": false,
|
||||||
|
"title": "keep me",
|
||||||
|
"custom": { "goal": "x" },
|
||||||
|
"agents": { "main": { "type": "main" } },
|
||||||
|
});
|
||||||
|
obj.as_object_mut().unwrap().insert("someFutureField".into(), serde_json::json!([1, 2, 3]));
|
||||||
|
fs::write(dir.join("state.json"), serde_json::to_string(&obj).unwrap()).unwrap();
|
||||||
|
|
||||||
|
archive_session_cmd(&home, WID, SID).unwrap();
|
||||||
|
unarchive_session_cmd(&home, WID, SID).unwrap();
|
||||||
|
|
||||||
|
let st = read_state_json(&dir);
|
||||||
|
assert_eq!(st["title"], "keep me");
|
||||||
|
assert_eq!(st["custom"]["goal"], "x");
|
||||||
|
assert_eq!(st["agents"]["main"]["type"], "main");
|
||||||
|
assert_eq!(st["someFutureField"][0], 1);
|
||||||
|
assert_eq!(st["updatedAt"], 2, "updatedAt untouched, like upstream touchUpdatedAt:false");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn cli_archived_session_in_active_root_lists_as_archived() {
|
||||||
|
// A session already carrying archived:true in state.json while still
|
||||||
|
// living at the active root (written by kimi-code CLI v2 itself) must
|
||||||
|
// surface in the archived filter / counts.
|
||||||
|
let (_td, home) = setup_home();
|
||||||
|
let dir = active_dir(&home).join(SID);
|
||||||
|
fs::create_dir_all(&dir).unwrap();
|
||||||
|
write_state(&dir, true, Some(1_700_000_000_000u64));
|
||||||
|
fs::write(dir.join("wire.jsonl"), "").unwrap();
|
||||||
|
|
||||||
|
let res = list_sessions_cmd(&home, "all", None);
|
||||||
|
assert_eq!(res.sessions.len(), 1);
|
||||||
|
assert_eq!(res.sessions[0].status, "archived");
|
||||||
|
assert_eq!(res.workspaces[0].active_count, 0);
|
||||||
|
assert_eq!(res.workspaces[0].archived_count, 1);
|
||||||
|
assert!(list_sessions_cmd(&home, "active", None).sessions.is_empty());
|
||||||
|
assert_eq!(list_sessions_cmd(&home, "archived", None).sessions.len(), 1);
|
||||||
|
|
||||||
|
// Preview resolves it in place with status "archived".
|
||||||
|
let pv = get_session_preview_cmd(&home, WID, SID, Some("archived")).unwrap();
|
||||||
|
assert_eq!(pv.status, "archived");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn legacy_kcd_archive_dir_still_listed_and_restored() {
|
||||||
|
let (_td, home) = setup_home();
|
||||||
|
let arch_dir = legacy_arch_dir(&home).join(SID);
|
||||||
|
fs::create_dir_all(&arch_dir).unwrap();
|
||||||
|
write_state(&arch_dir, false, None);
|
||||||
|
|
||||||
|
// Legacy physical archive still shows as archived.
|
||||||
|
let res = list_sessions_cmd(&home, "all", None);
|
||||||
|
assert_eq!(res.sessions.len(), 1);
|
||||||
|
assert_eq!(res.sessions[0].status, "archived");
|
||||||
|
assert_eq!(res.workspaces[0].active_count, 0);
|
||||||
|
assert_eq!(res.workspaces[0].archived_count, 1);
|
||||||
|
assert!(list_sessions_cmd(&home, "active", None).sessions.is_empty());
|
||||||
|
|
||||||
|
// Unarchive moves it back and clears the flag.
|
||||||
|
let ur = unarchive_session_cmd(&home, WID, SID).unwrap();
|
||||||
|
assert_eq!(ur.status.as_deref(), Some("active"));
|
||||||
|
assert!(!arch_dir.exists(), "legacy .kcd-archive copy moved back");
|
||||||
|
let restored = active_dir(&home).join(SID);
|
||||||
|
assert!(restored.exists());
|
||||||
|
let st = read_state_json(&restored);
|
||||||
|
assert_eq!(st["archived"], false);
|
||||||
|
assert!(st.get("archivedAt").is_none());
|
||||||
|
|
||||||
|
let res = list_sessions_cmd(&home, "all", None);
|
||||||
|
assert_eq!(res.sessions[0].status, "active");
|
||||||
|
assert_eq!(res.workspaces[0].active_count, 1);
|
||||||
|
assert_eq!(res.workspaces[0].archived_count, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn corrupt_state_json_archive_errors_without_panic() {
|
||||||
|
let (_td, home) = setup_home();
|
||||||
|
let dir = active_dir(&home).join(SID);
|
||||||
|
fs::create_dir_all(&dir).unwrap();
|
||||||
|
fs::write(dir.join("state.json"), "{ this is not json").unwrap();
|
||||||
|
|
||||||
|
let err = archive_session_cmd(&home, WID, SID).unwrap_err();
|
||||||
|
assert!(err.contains("state.json"), "clear error mentioning state.json, got: {err}");
|
||||||
|
assert!(dir.exists(), "failed archive leaves the session dir in place");
|
||||||
|
assert_eq!(fs::read_to_string(dir.join("state.json")).unwrap(), "{ this is not json");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn missing_state_json_archive_errors_without_panic() {
|
||||||
|
let (_td, home) = setup_home();
|
||||||
|
let dir = active_dir(&home).join(SID);
|
||||||
|
fs::create_dir_all(&dir).unwrap();
|
||||||
|
|
||||||
|
let err = archive_session_cmd(&home, WID, SID).unwrap_err();
|
||||||
|
assert!(err.contains("no state.json"), "clear error, got: {err}");
|
||||||
|
assert!(dir.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn delete_session_covers_metadata_archived() {
|
||||||
|
// Status hint "archived" without a legacy .kcd-archive copy falls back
|
||||||
|
// to removing the metadata-archived in-place directory.
|
||||||
|
let (_td, home) = setup_home();
|
||||||
|
let dir = active_dir(&home).join(SID);
|
||||||
|
fs::create_dir_all(&dir).unwrap();
|
||||||
|
write_state(&dir, true, Some(1_700_000_000_000u64));
|
||||||
|
|
||||||
|
let del = delete_session_cmd(&home, WID, SID, Some("archived")).unwrap();
|
||||||
|
assert_eq!(del.deleted, Some(true));
|
||||||
|
assert!(!dir.exists(), "metadata-archived session deleted in place");
|
||||||
|
assert!(!legacy_arch_dir(&home).join(SID).exists());
|
||||||
|
assert!(list_sessions_cmd(&home, "all", None).sessions.is_empty());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"productName": "Kimi Switch",
|
"productName": "Kimi Switch",
|
||||||
"version": "0.7.10",
|
"version": "0.7.11",
|
||||||
"identifier": "com.kimiswitch.app",
|
"identifier": "com.kimiswitch.app",
|
||||||
"build": {
|
"build": {
|
||||||
"beforeDevCommand": "npm run dev",
|
"beforeDevCommand": "npm run dev",
|
||||||
|
|||||||
@@ -1,7 +1,14 @@
|
|||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
import { useTranslation } from "../i18n";
|
import { useTranslation } from "../i18n";
|
||||||
import type { TranslationKey } from "../i18n/zh";
|
import type { TranslationKey } from "../i18n/zh";
|
||||||
import { getAgentSettings, setAgentSettings } from "../lib/agent-settings";
|
import { getAgentSettings, setAgentSettings } from "../lib/agent-settings";
|
||||||
import type { AgentSettings, Hook, PermissionRule } from "../types";
|
import type {
|
||||||
|
AgentSettings,
|
||||||
|
ExperimentalEnvStatus,
|
||||||
|
Hook,
|
||||||
|
PermissionRule,
|
||||||
|
} from "../types";
|
||||||
import { Card, Checkbox, NumberField, Segmented } from "./ui/controls";
|
import { Card, Checkbox, NumberField, Segmented } from "./ui/controls";
|
||||||
|
|
||||||
interface AgentSettingsPanelProps {
|
interface AgentSettingsPanelProps {
|
||||||
@@ -9,12 +16,12 @@ interface AgentSettingsPanelProps {
|
|||||||
onChange: (nextRawOther: unknown) => void;
|
onChange: (nextRawOther: unknown) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const THINKING_LEVELS = ["low", "medium", "high", "max"] as const;
|
// Upstream removed the "max" effort tier (auto-migrates to "high").
|
||||||
|
const THINKING_LEVELS = ["low", "medium", "high"] as const;
|
||||||
const THINKING_LABELS: Record<(typeof THINKING_LEVELS)[number], TranslationKey> = {
|
const THINKING_LABELS: Record<(typeof THINKING_LEVELS)[number], TranslationKey> = {
|
||||||
low: "thinkingLow",
|
low: "thinkingLow",
|
||||||
medium: "thinkingMedium",
|
medium: "thinkingMedium",
|
||||||
high: "thinkingHigh",
|
high: "thinkingHigh",
|
||||||
max: "thinkingMax",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const PERMISSION_DECISIONS = ["allow", "deny", "ask"] as const;
|
const PERMISSION_DECISIONS = ["allow", "deny", "ask"] as const;
|
||||||
@@ -40,9 +47,23 @@ const COMMON_EVENTS = [
|
|||||||
export function AgentSettingsPanel({ rawOther, onChange }: AgentSettingsPanelProps) {
|
export function AgentSettingsPanel({ rawOther, onChange }: AgentSettingsPanelProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const settings = getAgentSettings(rawOther);
|
const settings = getAgentSettings(rawOther);
|
||||||
|
/**
|
||||||
|
* KIMI_CODE_LEGACY_FLAG=1 keeps the v1 loop_control keys dual-written for
|
||||||
|
* v1-engine users; the default (v2) writes only max_attempts_per_step.
|
||||||
|
*/
|
||||||
|
const [legacyV1, setLegacyV1] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
invoke<ExperimentalEnvStatus>("get_experimental_env_status")
|
||||||
|
.then((env) => {
|
||||||
|
const value = env?.KIMI_CODE_LEGACY_FLAG ?? "";
|
||||||
|
setLegacyV1(["1", "true", "yes", "on"].includes(value.trim().toLowerCase()));
|
||||||
|
})
|
||||||
|
.catch(() => setLegacyV1(false));
|
||||||
|
}, []);
|
||||||
|
|
||||||
const update = (patch: Partial<AgentSettings>) => {
|
const update = (patch: Partial<AgentSettings>) => {
|
||||||
onChange(setAgentSettings(rawOther, patch));
|
onChange(setAgentSettings(rawOther, patch, { legacyV1 }));
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateThinking = (patch: Partial<AgentSettings["thinking"]>) => {
|
const updateThinking = (patch: Partial<AgentSettings["thinking"]>) => {
|
||||||
@@ -95,7 +116,7 @@ export function AgentSettingsPanel({ rawOther, onChange }: AgentSettingsPanelPro
|
|||||||
label={t("thinkingKeep")}
|
label={t("thinkingKeep")}
|
||||||
checked={settings.thinking?.keep === "all"}
|
checked={settings.thinking?.keep === "all"}
|
||||||
disabled={!thinkingEnabled}
|
disabled={!thinkingEnabled}
|
||||||
onChange={(checked) => updateThinking({ keep: checked ? "all" : false })}
|
onChange={(checked) => updateThinking({ keep: checked ? "all" : "off" })}
|
||||||
/>
|
/>
|
||||||
<p className="text-xs text-content-muted">{t("thinkingContextHint")}</p>
|
<p className="text-xs text-content-muted">{t("thinkingContextHint")}</p>
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
forcedEnvValue,
|
forcedEnvValue,
|
||||||
getExperimentalFlags,
|
getExperimentalFlags,
|
||||||
getSubagentModelPool,
|
getSubagentModelPool,
|
||||||
|
isExperimentalFlagSet,
|
||||||
isFlagLockedByEnv,
|
isFlagLockedByEnv,
|
||||||
isMasterEnvOn,
|
isMasterEnvOn,
|
||||||
removeSubagentPoolEntry,
|
removeSubagentPoolEntry,
|
||||||
@@ -33,12 +34,12 @@ interface SubagentSettingsPageProps {
|
|||||||
onBack: () => void;
|
onBack: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const EFFORTS = ["low", "medium", "high", "max"] as const;
|
// Upstream removed the "max" effort tier (auto-migrates to "high").
|
||||||
|
const EFFORTS = ["low", "medium", "high"] as const;
|
||||||
const EFFORT_LABELS: Record<(typeof EFFORTS)[number], TranslationKey> = {
|
const EFFORT_LABELS: Record<(typeof EFFORTS)[number], TranslationKey> = {
|
||||||
low: "thinkingLow",
|
low: "thinkingLow",
|
||||||
medium: "thinkingMedium",
|
medium: "thinkingMedium",
|
||||||
high: "thinkingHigh",
|
high: "thinkingHigh",
|
||||||
max: "thinkingMax",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const FLAG_LABELS: Record<string, { name: TranslationKey; desc: TranslationKey }> = {
|
const FLAG_LABELS: Record<string, { name: TranslationKey; desc: TranslationKey }> = {
|
||||||
@@ -55,6 +56,7 @@ const FLAG_LABELS: Record<string, { name: TranslationKey; desc: TranslationKey }
|
|||||||
name: "flagAutoSessionTitle",
|
name: "flagAutoSessionTitle",
|
||||||
desc: "flagAutoSessionTitleDesc",
|
desc: "flagAutoSessionTitleDesc",
|
||||||
},
|
},
|
||||||
|
"remote-control": { name: "flagRemoteControl", desc: "flagRemoteControlDesc" },
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Validation-error i18n key per engine rule, for the pre-write self-check. */
|
/** Validation-error i18n key per engine rule, for the pre-write self-check. */
|
||||||
@@ -235,7 +237,9 @@ export function SubagentSettingsPage({
|
|||||||
? `${Math.round(n / 1000)}K`
|
? `${Math.round(n / 1000)}K`
|
||||||
: String(n);
|
: String(n);
|
||||||
const effortLabel = (e: string): string => {
|
const effortLabel = (e: string): string => {
|
||||||
const key = EFFORT_LABELS[e as (typeof EFFORTS)[number]];
|
// Stored "max" tiers from old configs are shown as "high" (upstream
|
||||||
|
// removed the tier; it auto-migrates to "high").
|
||||||
|
const key = EFFORT_LABELS[e === "max" ? "high" : (e as (typeof EFFORTS)[number])];
|
||||||
return key ? t(key) : e;
|
return key ? t(key) : e;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -297,15 +301,27 @@ export function SubagentSettingsPage({
|
|||||||
const renderFlagRow = (flag: ExperimentalFlagDef) => {
|
const renderFlagRow = (flag: ExperimentalFlagDef) => {
|
||||||
const labels = FLAG_LABELS[flag.id];
|
const labels = FLAG_LABELS[flag.id];
|
||||||
const locked = masterOn || isFlagLockedByEnv(env, flag);
|
const locked = masterOn || isFlagLockedByEnv(env, flag);
|
||||||
|
// An explicitly written flag (true or false) wins; an absent flag falls
|
||||||
|
// back to the upstream default (`defaultEnabled`).
|
||||||
|
const explicitlySet = isExperimentalFlagSet(rawOther, flag.id);
|
||||||
const on = masterOn
|
const on = masterOn
|
||||||
? true
|
? true
|
||||||
: isFlagLockedByEnv(env, flag)
|
: isFlagLockedByEnv(env, flag)
|
||||||
? forcedEnvValue(env, flag)
|
? forcedEnvValue(env, flag)
|
||||||
: flags[flag.id] === true;
|
: explicitlySet
|
||||||
|
? flags[flag.id] === true
|
||||||
|
: (flag.defaultEnabled ?? false);
|
||||||
return (
|
return (
|
||||||
<div key={flag.id} className="flex items-center gap-3">
|
<div key={flag.id} className="flex items-center gap-3">
|
||||||
<div className="flex-1 min-w-0">
|
<div className="flex-1 min-w-0">
|
||||||
<div className="text-sm text-content-primary">{t(labels.name)}</div>
|
<div className="flex items-center gap-2 text-sm text-content-primary">
|
||||||
|
{t(labels.name)}
|
||||||
|
{!locked && !explicitlySet && flag.defaultEnabled && (
|
||||||
|
<span className="shrink-0 text-xs text-blue-600 dark:text-blue-400 border border-blue-500/30 rounded px-1">
|
||||||
|
{t("flagDefaultOn")}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
<div className="text-xs text-content-muted">
|
<div className="text-xs text-content-muted">
|
||||||
{t(labels.desc)}
|
{t(labels.desc)}
|
||||||
<code className="ml-2">{flag.envVar}</code>
|
<code className="ml-2">{flag.envVar}</code>
|
||||||
|
|||||||
+3
-1
@@ -138,7 +138,6 @@ export const enTranslations: Record<TranslationKey, string> = {
|
|||||||
thinkingLow: "Low",
|
thinkingLow: "Low",
|
||||||
thinkingMedium: "Medium",
|
thinkingMedium: "Medium",
|
||||||
thinkingHigh: "High",
|
thinkingHigh: "High",
|
||||||
thinkingMax: "Max",
|
|
||||||
thinkingContextHint: "Thinking uses more context. Ensure the model context length and reserved size are sufficient.",
|
thinkingContextHint: "Thinking uses more context. Ensure the model context length and reserved size are sufficient.",
|
||||||
loopControlSettings: "Loop Control",
|
loopControlSettings: "Loop Control",
|
||||||
maxAttemptsPerStep: "Max attempts per step",
|
maxAttemptsPerStep: "Max attempts per step",
|
||||||
@@ -476,6 +475,9 @@ export const enTranslations: Record<TranslationKey, string> = {
|
|||||||
flagWaitForDesc: "The agent can wait for background tasks to finish within the current turn",
|
flagWaitForDesc: "The agent can wait for background tasks to finish within the current turn",
|
||||||
flagAutoSessionTitle: "Auto Session Title",
|
flagAutoSessionTitle: "Auto Session Title",
|
||||||
flagAutoSessionTitleDesc: "Generate session titles automatically via the managed chat_title tool",
|
flagAutoSessionTitleDesc: "Generate session titles automatically via the managed chat_title tool",
|
||||||
|
flagRemoteControl: "Remote Control",
|
||||||
|
flagRemoteControlDesc: "Enable the experimental remote control feature",
|
||||||
|
flagDefaultOn: "On by default",
|
||||||
lockedByEnv: "Locked by env var",
|
lockedByEnv: "Locked by env var",
|
||||||
masterEnvOnHint: "KIMI_CODE_EXPERIMENTAL_FLAG is set: all experimental features are forced on by the env var",
|
masterEnvOnHint: "KIMI_CODE_EXPERIMENTAL_FLAG is set: all experimental features are forced on by the env var",
|
||||||
secondaryModelSection: "Subagent Model (Secondary Model)",
|
secondaryModelSection: "Subagent Model (Secondary Model)",
|
||||||
|
|||||||
+3
-1
@@ -136,7 +136,6 @@ export const zhTranslations = {
|
|||||||
thinkingLow: "低",
|
thinkingLow: "低",
|
||||||
thinkingMedium: "中",
|
thinkingMedium: "中",
|
||||||
thinkingHigh: "高",
|
thinkingHigh: "高",
|
||||||
thinkingMax: "最大",
|
|
||||||
thinkingContextHint: "启用思考会占用更多上下文,请确保模型上下文长度和预留空间足够。",
|
thinkingContextHint: "启用思考会占用更多上下文,请确保模型上下文长度和预留空间足够。",
|
||||||
loopControlSettings: "循环控制",
|
loopControlSettings: "循环控制",
|
||||||
maxAttemptsPerStep: "单步最大尝试次数",
|
maxAttemptsPerStep: "单步最大尝试次数",
|
||||||
@@ -471,6 +470,9 @@ export const zhTranslations = {
|
|||||||
flagWaitForDesc: "代理可在当前回合内等待后台任务完成,而无需结束回合再被唤醒",
|
flagWaitForDesc: "代理可在当前回合内等待后台任务完成,而无需结束回合再被唤醒",
|
||||||
flagAutoSessionTitle: "自动会话标题",
|
flagAutoSessionTitle: "自动会话标题",
|
||||||
flagAutoSessionTitleDesc: "通过托管 chat_title 工具自动生成会话标题",
|
flagAutoSessionTitleDesc: "通过托管 chat_title 工具自动生成会话标题",
|
||||||
|
flagRemoteControl: "远程控制",
|
||||||
|
flagRemoteControlDesc: "启用实验性远程控制功能",
|
||||||
|
flagDefaultOn: "默认开启",
|
||||||
lockedByEnv: "被环境变量锁定",
|
lockedByEnv: "被环境变量锁定",
|
||||||
masterEnvOnHint: "KIMI_CODE_EXPERIMENTAL_FLAG 已设置:全部实验功能被环境变量强制开启",
|
masterEnvOnHint: "KIMI_CODE_EXPERIMENTAL_FLAG 已设置:全部实验功能被环境变量强制开启",
|
||||||
secondaryModelSection: "子代理模型(次主力模型)",
|
secondaryModelSection: "子代理模型(次主力模型)",
|
||||||
|
|||||||
@@ -0,0 +1,134 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { getAgentSettings, setAgentSettings } from "./agent-settings";
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Helpers — drill into the written `[thinking]` / `[loop_control]` sections
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
function thinkingOf(raw: unknown): Record<string, unknown> {
|
||||||
|
const t = (raw as { thinking?: unknown })?.thinking;
|
||||||
|
return t && typeof t === "object" && !Array.isArray(t)
|
||||||
|
? (t as Record<string, unknown>)
|
||||||
|
: {};
|
||||||
|
}
|
||||||
|
|
||||||
|
function loopOf(raw: unknown): Record<string, unknown> {
|
||||||
|
const l = (raw as { loop_control?: unknown })?.loop_control;
|
||||||
|
return l && typeof l === "object" && !Array.isArray(l)
|
||||||
|
? (l as Record<string, unknown>)
|
||||||
|
: {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Reading — legacy off values normalized to "off", "max" → "high"
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
describe("getAgentSettings — thinking.keep normalization", () => {
|
||||||
|
it("normalizes a legacy boolean `false` to \"off\"", () => {
|
||||||
|
expect(getAgentSettings({ thinking: { keep: false } }).thinking?.keep).toBe(
|
||||||
|
"off"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("normalizes the other legacy off values (0, null, \"no\", \"none\") to \"off\"", () => {
|
||||||
|
for (const v of [0, null, "no", "none"]) {
|
||||||
|
expect(
|
||||||
|
getAgentSettings({ thinking: { keep: v } }).thinking?.keep
|
||||||
|
).toBe("off");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps \"all\" and \"off\" as-is on read", () => {
|
||||||
|
expect(getAgentSettings({ thinking: { keep: "all" } }).thinking?.keep).toBe(
|
||||||
|
"all"
|
||||||
|
);
|
||||||
|
expect(getAgentSettings({ thinking: { keep: "off" } }).thinking?.keep).toBe(
|
||||||
|
"off"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps the default \"all\" when the key is absent", () => {
|
||||||
|
expect(getAgentSettings({}).thinking?.keep).toBe("all");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("getAgentSettings — effort \"max\" read mapping", () => {
|
||||||
|
it("normalizes a stored \"max\" to \"high\" on read", () => {
|
||||||
|
expect(getAgentSettings({ thinking: { effort: "max" } }).thinking?.effort).toBe(
|
||||||
|
"high"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Writing — keep: "all" round-trips, "off" is written for legacy off values,
|
||||||
|
// absent keep is not materialized
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
describe("setAgentSettings — keep serialization", () => {
|
||||||
|
it("round-trips keep = \"all\"", () => {
|
||||||
|
const raw = { thinking: { keep: "all" } };
|
||||||
|
const next = setAgentSettings(raw, { thinking: { keep: "all" } });
|
||||||
|
expect(thinkingOf(next).keep).toBe("all");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("writes \"off\" (string) for a legacy keep = false, never a boolean", () => {
|
||||||
|
const next = setAgentSettings({ thinking: { keep: false } }, {});
|
||||||
|
expect(thinkingOf(next).keep).toBe("off");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not write the keep key when it was never set (absent in raw and patch)", () => {
|
||||||
|
expect(thinkingOf(setAgentSettings({}, {}))).not.toHaveProperty("keep");
|
||||||
|
const next = setAgentSettings(
|
||||||
|
{ thinking: { enabled: true } },
|
||||||
|
{ thinking: { effort: "high" } }
|
||||||
|
);
|
||||||
|
expect(thinkingOf(next)).not.toHaveProperty("keep");
|
||||||
|
expect(thinkingOf(next).effort).toBe("high");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("writes the key when an absent raw config's keep is explicitly toggled off", () => {
|
||||||
|
const next = setAgentSettings({}, { thinking: { keep: "off" } });
|
||||||
|
expect(thinkingOf(next).keep).toBe("off");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// loop_control — v2 default writes only max_attempts_per_step; legacyV1 opts
|
||||||
|
// dual-writes; read fallback from the v1 key is preserved
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
describe("loop_control — v1/v2 key handling", () => {
|
||||||
|
const raw = { loop_control: { max_attempts_per_step: 5, max_retries_per_step: 5 } };
|
||||||
|
|
||||||
|
it("default (v2): a save strips the legacy max_retries_per_step key", () => {
|
||||||
|
const next = setAgentSettings(raw, { loop_control: { reserved_context_size: 60000 } });
|
||||||
|
expect(loopOf(next).max_attempts_per_step).toBe(5);
|
||||||
|
expect(loopOf(next)).not.toHaveProperty("max_retries_per_step");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("default (v2): a dual-write patch ends up with only the v2 key", () => {
|
||||||
|
const next = setAgentSettings(
|
||||||
|
raw,
|
||||||
|
{ loop_control: { max_attempts_per_step: 7, max_retries_per_step: 7 } }
|
||||||
|
);
|
||||||
|
expect(loopOf(next).max_attempts_per_step).toBe(7);
|
||||||
|
expect(loopOf(next)).not.toHaveProperty("max_retries_per_step");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("legacyV1: both keys are written", () => {
|
||||||
|
const next = setAgentSettings(
|
||||||
|
raw,
|
||||||
|
{ loop_control: { max_attempts_per_step: 7, max_retries_per_step: 7 } },
|
||||||
|
{ legacyV1: true }
|
||||||
|
);
|
||||||
|
expect(loopOf(next).max_attempts_per_step).toBe(7);
|
||||||
|
expect(loopOf(next).max_retries_per_step).toBe(7);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("read fallback keeps a max_retries_per_step-only config editable", () => {
|
||||||
|
const s = getAgentSettings({ loop_control: { max_retries_per_step: 4 } });
|
||||||
|
expect(s.loop_control?.max_attempts_per_step).toBe(4);
|
||||||
|
expect(s.loop_control?.max_retries_per_step).toBe(4);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -49,11 +49,24 @@ export function getAgentSettings(rawOther: unknown): AgentSettings {
|
|||||||
) {
|
) {
|
||||||
loop.max_attempts_per_step = sectionLoop.max_retries_per_step;
|
loop.max_attempts_per_step = sectionLoop.max_retries_per_step;
|
||||||
}
|
}
|
||||||
|
const thinking = {
|
||||||
|
...DEFAULT_SETTINGS.thinking,
|
||||||
|
...getSection<AgentSettings["thinking"]>(rawOther, "thinking"),
|
||||||
|
};
|
||||||
|
// Upstream engines only accept string off values ("off"/"none"/"no"; see
|
||||||
|
// KEEP_OFF_VALUES) — a `false` from an old config fails the v2 validator
|
||||||
|
// and the v1 strict parse. Normalize every legacy off value to "off" for
|
||||||
|
// display; the serialization path (setAgentSettings) writes the string.
|
||||||
|
if (thinking.keep !== undefined && thinking.keep !== "all") {
|
||||||
|
thinking.keep = "off";
|
||||||
|
}
|
||||||
|
// The "max" effort tier was removed upstream (auto-migrates to "high");
|
||||||
|
// old configs still carrying it are shown as "high" (not rewritten on read).
|
||||||
|
if (thinking.effort === "max") {
|
||||||
|
thinking.effort = "high";
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
thinking: {
|
thinking,
|
||||||
...DEFAULT_SETTINGS.thinking,
|
|
||||||
...getSection<AgentSettings["thinking"]>(rawOther, "thinking"),
|
|
||||||
},
|
|
||||||
loop_control: loop,
|
loop_control: loop,
|
||||||
background: {
|
background: {
|
||||||
...DEFAULT_SETTINGS.background,
|
...DEFAULT_SETTINGS.background,
|
||||||
@@ -70,7 +83,8 @@ export function getAgentSettings(rawOther: unknown): AgentSettings {
|
|||||||
|
|
||||||
export function setAgentSettings(
|
export function setAgentSettings(
|
||||||
rawOther: unknown,
|
rawOther: unknown,
|
||||||
patch: Partial<AgentSettings>
|
patch: Partial<AgentSettings>,
|
||||||
|
opts?: { legacyV1?: boolean }
|
||||||
): unknown {
|
): unknown {
|
||||||
const root = { ...asRecord(rawOther) };
|
const root = { ...asRecord(rawOther) };
|
||||||
const current = getAgentSettings(rawOther);
|
const current = getAgentSettings(rawOther);
|
||||||
@@ -84,6 +98,20 @@ export function setAgentSettings(
|
|||||||
hooks: patch.hooks ?? current.hooks ?? [],
|
hooks: patch.hooks ?? current.hooks ?? [],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// `keep` is only written when the source config explicitly carries it or the
|
||||||
|
// patch sets it — an absent key keeps the engine default ("all") instead of
|
||||||
|
// being materialized, so a plain save does not add the key.
|
||||||
|
const rawThinking = asRecord(getSection(rawOther, "thinking"));
|
||||||
|
const patchHasKeep = patch.thinking !== undefined && "keep" in patch.thinking;
|
||||||
|
if (!("keep" in rawThinking) && !patchHasKeep) {
|
||||||
|
delete next.thinking?.keep;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The v2 engine (default) only reads max_attempts_per_step; the legacy v1
|
||||||
|
// key is stripped on save unless KIMI_CODE_LEGACY_FLAG=1 (v1 engine compat).
|
||||||
|
if (!opts?.legacyV1) {
|
||||||
|
delete next.loop_control?.max_retries_per_step;
|
||||||
|
}
|
||||||
if (next.thinking) root.thinking = next.thinking;
|
if (next.thinking) root.thinking = next.thinking;
|
||||||
if (next.loop_control) root.loop_control = next.loop_control;
|
if (next.loop_control) root.loop_control = next.loop_control;
|
||||||
if (next.background) root.background = next.background;
|
if (next.background) root.background = next.background;
|
||||||
|
|||||||
+3480
-1360
File diff suppressed because it is too large.
Load diff
+3023
-1221
File diff suppressed because it is too large.
Load diff
@@ -231,6 +231,31 @@ describe("pool mutations", () => {
|
|||||||
expect(section(updated).default_model).toBe("kimi-k1");
|
expect(section(updated).default_model).toBe("kimi-k1");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("upsertSubagentPoolEntry materializes the implicit default into a new table", () => {
|
||||||
|
// Implicit single-entry form (default_model set, no models table): adding a
|
||||||
|
// second alias must pull the default into the table, otherwise the result
|
||||||
|
// violates "default_model must be a pool key" (rule 3) and gets rejected.
|
||||||
|
const raw = rawWith({ default_model: "kimi-k1", force: false });
|
||||||
|
const added = upsertSubagentPoolEntry(raw, "kimi-k2", "");
|
||||||
|
expect(modelsOf(added)).toEqual({ "kimi-k1": "", "kimi-k2": "" });
|
||||||
|
expect(section(added).default_model).toBe("kimi-k1");
|
||||||
|
const pool = getSubagentModelPool(added);
|
||||||
|
expect(pool).toBeDefined();
|
||||||
|
expect(
|
||||||
|
validateSubagentPool(pool!, ["kimi-k1", "kimi-k2"]),
|
||||||
|
).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("upsertSubagentPoolEntry upgrades a legacy `model`-only section to a valid pool", () => {
|
||||||
|
const raw = rawWith({ model: "kimi-k1" });
|
||||||
|
const added = upsertSubagentPoolEntry(raw, "kimi-k2", "K2");
|
||||||
|
expect(modelsOf(added)).toEqual({ "kimi-k1": "", "kimi-k2": "K2" });
|
||||||
|
expect(section(added).default_model).toBe("kimi-k1");
|
||||||
|
expect(section(added).model).toBe("kimi-k1");
|
||||||
|
const pool = getSubagentModelPool(added);
|
||||||
|
expect(validateSubagentPool(pool!, ["kimi-k1", "kimi-k2"])).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
it("removeSubagentPoolEntry keeps the default when removing a non-default alias", () => {
|
it("removeSubagentPoolEntry keeps the default when removing a non-default alias", () => {
|
||||||
const raw = rawWith({
|
const raw = rawWith({
|
||||||
default_model: "kimi-k1",
|
default_model: "kimi-k1",
|
||||||
|
|||||||
@@ -28,27 +28,36 @@ export interface ExperimentalFlagDef {
|
|||||||
id: string;
|
id: string;
|
||||||
/** Single-feature env var that can force the flag (locks the UI toggle). */
|
/** Single-feature env var that can force the flag (locks the UI toggle). */
|
||||||
envVar: string;
|
envVar: string;
|
||||||
|
/** Feature turned on by default upstream; an absent config key falls back
|
||||||
|
* to this, while an explicit `false` in `[experimental]` still wins. */
|
||||||
|
defaultEnabled?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Known experimental flags — mirrors the kimi-code v2 flag registry
|
/** Known experimental flags — mirrors the kimi-code v2 flag registry
|
||||||
* (the per-feature flag.ts files under packages/agent-core-v2/src:
|
* (the per-feature flag.ts files under packages/agent-core-v2/src:
|
||||||
* secondary-model, tool-select, persistence_minidb_readmodel, tower,
|
* secondary-model, tool-select, persistence_minidb_readmodel, tower,
|
||||||
* subagent_fork, wait_for, auto_session_title). `acp-v2` was removed
|
* subagent_fork, wait_for, auto_session_title, remote-control). `acp-v2` was
|
||||||
* upstream and is dropped here. */
|
* removed upstream and is dropped here. */
|
||||||
export const EXPERIMENTAL_FLAGS: ExperimentalFlagDef[] = [
|
export const EXPERIMENTAL_FLAGS: ExperimentalFlagDef[] = [
|
||||||
{ id: "secondary-model", envVar: "KIMI_CODE_EXPERIMENTAL_SECONDARY_MODEL" },
|
{ id: "secondary-model", envVar: "KIMI_CODE_EXPERIMENTAL_SECONDARY_MODEL" },
|
||||||
{ id: "tool-select", envVar: "KIMI_CODE_EXPERIMENTAL_TOOL_SELECT" },
|
{ id: "tool-select", envVar: "KIMI_CODE_EXPERIMENTAL_TOOL_SELECT" },
|
||||||
{
|
{
|
||||||
id: "persistence_minidb_readmodel",
|
id: "persistence_minidb_readmodel",
|
||||||
envVar: "KIMI_CODE_EXPERIMENTAL_PERSISTENCE_MINIDB_READMODEL",
|
envVar: "KIMI_CODE_EXPERIMENTAL_PERSISTENCE_MINIDB_READMODEL",
|
||||||
|
defaultEnabled: true,
|
||||||
},
|
},
|
||||||
{ id: "tower", envVar: "KIMI_CODE_EXPERIMENTAL_TOWER" },
|
{ id: "tower", envVar: "KIMI_CODE_EXPERIMENTAL_TOWER" },
|
||||||
{ id: "subagent_fork", envVar: "KIMI_CODE_EXPERIMENTAL_SUBAGENT_FORK" },
|
{ id: "subagent_fork", envVar: "KIMI_CODE_EXPERIMENTAL_SUBAGENT_FORK" },
|
||||||
{ id: "wait_for", envVar: "KIMI_CODE_EXPERIMENTAL_WAIT_FOR" },
|
{
|
||||||
|
id: "wait_for",
|
||||||
|
envVar: "KIMI_CODE_EXPERIMENTAL_WAIT_FOR",
|
||||||
|
defaultEnabled: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: "auto_session_title",
|
id: "auto_session_title",
|
||||||
envVar: "KIMI_CODE_EXPERIMENTAL_AUTO_SESSION_TITLE",
|
envVar: "KIMI_CODE_EXPERIMENTAL_AUTO_SESSION_TITLE",
|
||||||
},
|
},
|
||||||
|
{ id: "remote-control", envVar: "KIMI_CODE_EXPERIMENTAL_REMOTE_CONTROL" },
|
||||||
];
|
];
|
||||||
|
|
||||||
export const EXPERIMENTAL_MASTER_ENV = "KIMI_CODE_EXPERIMENTAL_FLAG";
|
export const EXPERIMENTAL_MASTER_ENV = "KIMI_CODE_EXPERIMENTAL_FLAG";
|
||||||
@@ -87,6 +96,15 @@ export function getExperimentalFlags(rawOther: unknown): Record<string, boolean>
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Whether a flag is explicitly written in `[experimental]` (true *or* false).
|
||||||
|
* An absent flag falls back to the upstream default (`defaultEnabled`). */
|
||||||
|
export function isExperimentalFlagSet(rawOther: unknown, id: string): boolean {
|
||||||
|
return Object.prototype.hasOwnProperty.call(
|
||||||
|
asRecord(asRecord(rawOther)["experimental"]),
|
||||||
|
id
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/** Set one flag in `[experimental]`. Removing all flags drops the section. */
|
/** Set one flag in `[experimental]`. Removing all flags drops the section. */
|
||||||
export function setExperimentalFlag(
|
export function setExperimentalFlag(
|
||||||
rawOther: unknown,
|
rawOther: unknown,
|
||||||
@@ -256,8 +274,11 @@ export function setSubagentModelPool(
|
|||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Add or update one alias in the pool `models` table. The rest of the
|
/** Add or update one alias in the pool `models` table. When the section is
|
||||||
* section (default, force, unknown fields) is preserved untouched. */
|
* the implicit single-entry form (a `default_model`/`model` but no table),
|
||||||
|
* the effective default is materialized into the table first — otherwise the
|
||||||
|
* new table would fail the engine rule "default_model must be a pool key".
|
||||||
|
* The rest of the section (force, unknown fields) is preserved untouched. */
|
||||||
export function upsertSubagentPoolEntry(
|
export function upsertSubagentPoolEntry(
|
||||||
rawOther: unknown,
|
rawOther: unknown,
|
||||||
alias: string,
|
alias: string,
|
||||||
@@ -269,8 +290,21 @@ export function upsertSubagentPoolEntry(
|
|||||||
for (const [k, v] of Object.entries(section)) next[k] = v;
|
for (const [k, v] of Object.entries(section)) next[k] = v;
|
||||||
const models: Record<string, unknown> = {};
|
const models: Record<string, unknown> = {};
|
||||||
for (const [k, v] of Object.entries(asRecord(next.models))) models[k] = v;
|
for (const [k, v] of Object.entries(asRecord(next.models))) models[k] = v;
|
||||||
|
const effectiveDefault =
|
||||||
|
typeof next.default_model === "string" && next.default_model !== ""
|
||||||
|
? next.default_model
|
||||||
|
: typeof next.model === "string" && next.model !== ""
|
||||||
|
? next.model
|
||||||
|
: undefined;
|
||||||
|
if (effectiveDefault !== undefined && !(effectiveDefault in models)) {
|
||||||
|
models[effectiveDefault] = "";
|
||||||
|
}
|
||||||
models[alias] = description;
|
models[alias] = description;
|
||||||
next.models = models;
|
next.models = models;
|
||||||
|
if (effectiveDefault !== undefined) {
|
||||||
|
next.default_model = effectiveDefault;
|
||||||
|
next.model = effectiveDefault;
|
||||||
|
}
|
||||||
root.secondary_model = next;
|
root.secondary_model = next;
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-1
@@ -100,7 +100,18 @@ export interface DiscoveredModel {
|
|||||||
|
|
||||||
export interface ThinkingConfig {
|
export interface ThinkingConfig {
|
||||||
enabled?: boolean;
|
enabled?: boolean;
|
||||||
|
/**
|
||||||
|
* Effort tier. `max` is read-compatible only — upstream removed the tier
|
||||||
|
* (old configs auto-migrate to `high`); the UI normalizes it and the
|
||||||
|
* serialization path never writes it.
|
||||||
|
*/
|
||||||
effort?: "low" | "medium" | "high" | "max";
|
effort?: "low" | "medium" | "high" | "max";
|
||||||
|
/**
|
||||||
|
* Keep thinking content. The legacy off values (`false`, `0`, "no", "none",
|
||||||
|
* `null`) are read-compatible — old configs may carry them; the UI
|
||||||
|
* normalizes them to `"off"` and the serialization path never emits a
|
||||||
|
* boolean (upstream engines only accept string off values).
|
||||||
|
*/
|
||||||
keep?: "all" | false | 0 | "no" | "off" | "none" | null;
|
keep?: "all" | false | 0 | "no" | "off" | "none" | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +120,8 @@ export interface LoopControlConfig {
|
|||||||
max_attempts_per_step?: number;
|
max_attempts_per_step?: number;
|
||||||
/** v2 engine key (kimi-code 0.33+): `max_steps_per_run` was renamed. */
|
/** v2 engine key (kimi-code 0.33+): `max_steps_per_run` was renamed. */
|
||||||
max_steps_per_turn?: number;
|
max_steps_per_turn?: number;
|
||||||
/** Legacy v1 key — written in sync so KIMI_CODE_LEGACY_FLAG=1 still works. */
|
/** Legacy v1 key — read fallback only; written/kept only when
|
||||||
|
* KIMI_CODE_LEGACY_FLAG=1 (v1 engine compat). v2 saves strip it. */
|
||||||
max_retries_per_step?: number;
|
max_retries_per_step?: number;
|
||||||
reserved_context_size?: number;
|
reserved_context_size?: number;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user