Separate byte budgets for the user-global and project instruction chains
用户全局指令链与项目指令链分别使用字节预算
`dsh-agent-instructions` rendered the user-global and project files as one chain under one `maxBytes`, the rule of the [original workspace-context decision](../../archived/feature/2026-06-24-workspace-context.md). Rendering omits the broadest files first, and user-global files are the broadest, so a large project chain removed them: under the shipped 65,536-byte budget, 20 KiB user-global, 30 KiB project root, and 20
English
Problem
dsh-agent-instructions rendered the user-global and project files as one chain under one maxBytes, the rule of the original workspace-context decision. Rendering omits the broadest files first, and user-global files are the broadest, so a large project chain removed them: under the shipped 65,536-byte budget, 20 KiB user-global, 30 KiB project root, and 20 KiB nested files rendered without the user-global file.
Decision
The renderer splits the loaded files into the user-global and project chains, keeping their order, and renders each under the same maxBytes: omit the broadest files, truncate the last file, then fall back to the compact intro, to the notice with an empty heading, and to the notice alone. The project chain keeps the result it has when rendered alone; user-global files are omitted or truncated only beyond their own budget, except in the fallback below.
When all files fit maxBytes together, or only one chain has files, the output is unchanged byte for byte. Otherwise one <system-reminder> frame of at most twice maxBytes holds the merged notice when a file was omitted or truncated, one intro when a chain kept its frame, and the rendered sections in loaded order, with user-global files first in a baseline. If a chain renders without a frame and the merged frame would exceed that bound, all files render as one chain under one maxBytes, which can omit a user-global file that fit its own budget; this needs a budget of a few hundred bytes or a notice that nearly fills or exceeds maxBytes. Reconciliation batches apply the same split.
The maxBytes key and the baseline identity are unchanged, so a resumed session keeps its visible baseline and receives a user-global file that baseline omitted as one additional-instructions transition.
Alternatives considered
One budget that gives user-global files priority. A large user-global file then truncates or omits the project root file, and bytes near the limit decide which chain loses content.
One budget with a user-global share. The project chain still shrinks, and no measurement supports a share size.
A configuration field for the second chain. No deployment needs different sizes, and the field would join the baseline identity, so resumed sessions would resend their baselines.
The Codex layout: an unbounded user-global file and a root-first project chain. Output has no bound, and the project chain keeps its broadest files, not its most specific ones.
Consequences
- A baseline or batch holding both chains can reach twice
maxBytes; deployments that sizedmaxBytesas a total budget halve it, per the upgrade guide. - User-global instructions survive a large project chain.
- The
agent-instructions-budgetsnapshot shows a truncated user-global file beside the whole project file;agent-instructions-budget-chainsshows two chains that fit only separately. - The package README,
Config.maxBytesJSDoc, and configuration catalog state the per-chain bound.
中文
问题
dsh-agent-instructions 曾把用户全局文件与项目文件作为一条指令链,在一个 maxBytes 内渲染,这是最初的工作区上下文决策定下的规则。渲染会最先省略最宽泛的文件,而用户全局文件最宽泛,因此较大的项目指令链会移除它们:在默认的 65,536 字节预算下,20 KiB 的用户全局文件、30 KiB 的项目根文件与 20 KiB 的嵌套文件一起渲染时,用户全局文件被省略。
决策
渲染器把已加载的文件分成用户全局指令链与项目指令链,各自保持原有顺序,并分别在同一个 maxBytes 内渲染:先省略最宽泛的文件,再截断最后一个文件,然后依次退回到精简引言、带空标题的通知和仅含通知的文本。项目指令链的结果与它单独渲染时相同;用户全局文件只有超出自身预算时才会被省略或截断,下文的回退情形除外。
所有文件合起来能放进 maxBytes,或只有一条链有文件时,输出逐字节不变。其他情况下,一个至多为 maxBytes 两倍的 <system-reminder> 框架包含合并后的通知(仅当有文件被省略或截断时)、一段引言(仅当某条链保留了框架时),以及按加载顺序排列的渲染段落,因此基线中用户全局文件在前。若某条链在没有框架的情况下渲染,且合并后的框架会超过该上限,则所有文件作为一条链在一个 maxBytes 内渲染,这可能省略一个本可放进自身预算的用户全局文件;这只会在预算只有几百字节,或通知接近或超过 maxBytes 时发生。对账批次采用同样的拆分。
maxBytes 配置键与基线标识都不变,因此恢复的会话保留其可见基线;该基线曾省略的用户全局文件会以一次附加指令变更的形式加入。
备选方案
一个预算,并优先保留用户全局文件。 较大的用户全局文件会截断或省略项目根文件,而且临界值附近的字节差异就决定哪条链丢失内容。
一个预算,并为用户全局文件划出份额。 项目指令链仍会缩小,而且没有测量数据支撑份额的大小。
为第二条链增加配置字段。 没有部署需要为两条链设定不同大小,而且该字段会进入基线标识,使恢复的会话重新发送基线。
采用 Codex 的布局:不设上限的用户全局文件,加上从根目录开始保留的项目指令链。 输出没有上限,项目指令链会保留最宽泛的文件,而不是最具体的文件。
影响
- 同时包含两条链的基线或批次最多可达
maxBytes的两倍;把maxBytes当作总预算设定的部署应将其减半,见升级指南。 - 用户全局指令不会因项目指令链较大而被移除。
agent-instructions-budgetsnapshot 显示被截断的用户全局文件与完整的项目文件;agent-instructions-budget-chains显示两条只能各自放下的链。- 包 README、
Config.maxBytes的 JSDoc 与配置目录说明了按链计算的上限。