ZCode 目前在首次持久化 session 时直接从用户输入截断得到 session.title。这个标题稳定、便宜,但对长 prompt、带上下文的需求、中文/英文混合输入和文件附件场景不够可读。
核心约束:
ModelRole.Lite。如果未配置 model.lite,必须使用当前默认/main 模型,不能报错或强制用户配置第二模型。SessionStorePort,并由 SQLite adapter 持久化。--prompt、SDK/测试宿主默认开启标题生成。它们只有在显式传入 runtimeConfig.titleGeneration 时才会触发。/rename 命令,但数据库和 port 必须为 custom 标题保留不可覆盖语义。SessionInfo 增加可选标题元数据:
type SessionTitleSource = "default" | "first_input" | "generated" | "custom";
interface SessionInfo {
title: string;
titleSource?: SessionTitleSource;
titleMessageID?: MessageId;
time: {
titleUpdated?: number;
};
}
SQLite session 表增加:
| 字段 | 类型 | 说明 |
|---|---|---|
title_source |
text not null default first_input |
标题来源。 |
title_message_id |
text null | 生成/设置标题所依据的 user message。 |
time_title_updated |
integer null | 标题最近更新时间。 |
SessionStorePort.updateSession 支持标题 CAS:
interface UpdateSessionInput {
title?: string;
titleSource?: SessionTitleSource;
titleMessageID?: MessageId | null;
expectedTitleSources?: SessionTitleSource[];
}
当 expectedTitleSources 不为空且当前 title_source 不在列表中时,adapter 必须 no-op 并返回当前 session。AI 标题写入使用 ["default", "first_input", "generated"],因此用户自定义 custom 不会被迟到的 AI 结果覆盖。
标题生成由 core runtime 发起,但必须由外层宿主显式启用。第一版只有 CLI TUI 入口传入 runtimeConfig.titleGeneration;headless --prompt、ZCode app-server session、workflow child 和外部 SDK 宿主默认不传这个配置。
启用后仍需满足:
sessionStore 和 modelAdapter 都存在。titleGeneration.enabled !== false。parentSessionId,taskType 缺省或为 interactive。custom。第一版在主 turn 完成后启动异步 sidecar 请求;它不进入主 TurnResult.usage,但会发自己的 model request/model complete/session title event。
bootstrap 不做全局自动启用。它只在已经存在 runtimeConfig.titleGeneration 时补齐标题模型引用和 provider options。
CLI TUI 入口创建 app 时传入:
runtimeConfig: {
titleGeneration: {},
}
headless --prompt 和 --target 不传 titleGeneration,因此不会多发一个后台模型请求,也不会影响脚本输出和退出时机。app-server 会话同样不传 titleGeneration,避免协议客户端在一次 prompt 之外收到额外成本、事件和模型调用;未来若 ZCode protocol client 明确需要标题,可先设计协议能力和展示语义,再显式打开。
测试或外部宿主注入自定义 modelAdapter 时,除非显式传入 runtimeConfig.titleGeneration,否则不自动发起标题请求,避免破坏宿主自定义模型调用编排。
当入口显式启用标题生成时,bootstrap 生成 titleGeneration.modelRef。
模型选择顺序:
model.lite,使用 model.lite 的 provider/model。model.lite,使用当前默认/main provider/model。modelRef.role 都是 lite,表示请求用途是轻量 sidecar。provider options 与最终 provider/model 对齐;model.lite 没有配置时复用默认/main provider options。发送标题请求前会做 title 专用转换:
effort、reasoningEffort、reasoning_effort;禁止在删除后根据空 options 反推模型能力。thinking,改为 thinking.type = "disabled",并移除 effort。none 的 GPT 基础模型写入 reasoningEffort = "none";其他模型只移除继承的 effort,不伪造 provider 不支持的禁用值。thinking.type = "disabled" 或 enable_thinking = false。GLM-5.2 以及明确支持 none 的 GPT 基础模型如果原始 options 仅有 effort,则转换为 canonical reasoningEffort = "none"。apiFormat 写入官方关闭参数:OpenAI Chat 使用 openaiCompatible.thinking.type = "disabled",Anthropic 使用 anthropic.thinking.type = "disabled",Responses 使用 openai.reasoningEffort = "none"。这只影响 title sidecar,不改变主请求或模型档位。none 或其他关闭字段。其余没有 reasoning options 的模型保持原样。这样主对话仍可使用用户选择的思考强度;标题、goal summary title 这些共享 title sidecar 的短请求不会继承主链路的 high/max thinking。
系统 prompt 要求:
清洗逻辑:
<think>...</think>。这是兼容模型未遵守禁用字段的输出清洗,不代表请求侧允许继承 thinking。{ "title": "..." };兼容模型把 JSON 包在完整 Markdown fenced code block(语言标记为 json)中的返回;失败则取首个非空文本行。新增 session_title_updated:
interface SessionTitleUpdatedPayload {
messageID?: MessageId;
modelRef?: ModelRef;
previousTitle: string;
source: SessionTitleSource;
title: string;
}
标题生成还应发普通 model_request / model_complete,querySource: "session_title",以便 debug 和成本分析能看到这次 sidecar 请求。
session_title_generation.skipped,原因是 title_source_changed。最低覆盖:
first_input。createSession 写入 title_source,updateSession 可以更新 generated 标题。model.lite 时,标题请求使用 main provider/model 且 role 为 lite。model.lite 时,标题请求使用 lite provider/model。titleGeneration,不会触发标题模型请求。