Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/reference/protocols/quota-cli-hot-path-compaction-v0.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ projection. Candidate lists and peer action lists retain counts and point to
`--include-detail vision`; `--include-detail all` restores every supported
detail section.

On the complete Turn wire, the CLI channel can carry that reference with
`projection_view: "cli_channel"`. Its view contains `required`,
`required_before_closeout`, `recommended_action`, and the existing judge
fields `done`, `decision`, `reason`, `agent_judge_instruction`,
`evidence_read_instruction`, `registry_read_instruction`, `done_only_when`,
`continue_when`, and `otherwise` from the inline root. Resolve the reference
within the original packet. A different channel obligation or additional
field stays inline. Previously saved inline views and unqualified full-audit
references remain readable.

完整 Turn 包的 CLI 通道可以使用带 `projection_view: "cli_channel"` 的引用。
该视图只读取上文列出的字段,来源是同一原包内联的完整 Vision 审核。通道内容或
约束有差异时保留内联内容。以前保存的内联视图和完整审核引用仍可读取。

When a bounded next-action label still carries the complete Task again in
`agent_lane_next_action.title`, the default view may replace that exact duplicate
with `title_ref`. The reference resolves to `text` or `title` in the single
Expand Down
57 changes: 42 additions & 15 deletions loopx/control_plane/quota/turn_envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,18 +528,34 @@ function referenceExploreGuidance(payload: JsonObject): JsonObject {
work_context: {...context, sources}}}};
}

/** Keep the complete vision audit once. These existing projection references
* share identical facts only; a channel-specific obligation is never a summary
* of the root. The old display adapter delegates here before adding metadata. */
function visionAuditReference(audit: JsonObject): JsonObject {
/** Carry the existing CLI view exactly. A new or changed channel field keeps
* its original inline value unless the producer's entire view matches. */
function cliVisionAuditView(owner: JsonObject): JsonObject {
const fields = (value: JsonObject, keys: readonly string[]) =>
Object.fromEntries(keys.filter(key => Object.hasOwn(value, key)).map(key => [key, value[key]]));
const view = fields(owner, ["required", "required_before_closeout", "recommended_action"]);
const judge = object(owner.vision_gap_judge);
if (Object.keys(judge).length) view.vision_gap_judge = fields(judge, [
"done", "decision", "reason", "agent_judge_instruction", "evidence_read_instruction",
"registry_read_instruction", "done_only_when", "continue_when", "otherwise",
]);
return view;
}

function supportsCliVisionAuditView(owner: JsonObject): boolean {
return owner.schema_version === "vision_continuation_audit_v0" && owner.required === true;
}

function visionAuditReference(audit: JsonObject, cliView = false): JsonObject {
const reference: JsonObject = {projection_ref: "$.vision_continuation_audit"};
if (cliView) reference.projection_view = "cli_channel";
for (const key of ["schema_version", "required", "decision"]) {
if (Object.hasOwn(audit, key)) reference[key] = audit[key];
}
if (typeof audit.vision_gap_judge === "object" && audit.vision_gap_judge !== null &&
!Array.isArray(audit.vision_gap_judge)) {
const judge = object(audit.vision_gap_judge);
reference.vision_gap_judge = {projection_ref: "$.vision_continuation_audit.vision_gap_judge"};
reference.vision_gap_judge = cliView ? {} : {projection_ref: "$.vision_continuation_audit.vision_gap_judge"};
for (const key of ["done", "decision"]) {
if (Object.hasOwn(judge, key)) (reference.vision_gap_judge as JsonObject)[key] = judge[key];
}
Expand All @@ -566,12 +582,15 @@ function mapNestedVisionAudits(payload: JsonObject,

function requireVisionAuditReferences(payload: JsonObject): void {
const owner = object(payload.vision_continuation_audit);
const chained = Object.hasOwn(owner, "projection_ref") || Object.hasOwn(object(owner.vision_gap_judge), "projection_ref");
if (chained) throw new EffectRuntimeRequestError("Vision audit reference requires a complete inline root owner");
mapNestedVisionAudits(payload, audit => {
if (Object.hasOwn(audit, "projection_ref") || Object.hasOwn(object(audit.vision_gap_judge), "projection_ref")) {
if (!Object.keys(owner).length ||
JSON.stringify(canonicalValue(audit)) !== JSON.stringify(canonicalValue(visionAuditReference(owner)))) {
const hasReference = (audit: JsonObject) => Object.hasOwn(audit, "projection_ref") ||
Object.hasOwn(audit, "projection_view") || Object.hasOwn(object(audit.vision_gap_judge), "projection_ref");
if (hasReference(owner)) throw new EffectRuntimeRequestError("Vision audit reference requires a complete inline root owner");
mapNestedVisionAudits(payload, (audit, path) => {
if (hasReference(audit)) {
const cliView = audit.projection_view === "cli_channel" && path[1] === "cli_channel" &&
supportsCliVisionAuditView(owner);
const expected = cliView ? visionAuditReference(cliVisionAuditView(owner), true) : visionAuditReference(owner);
if (!Object.keys(owner).length || JSON.stringify(canonicalValue(audit)) !== JSON.stringify(canonicalValue(expected))) {
throw new EffectRuntimeRequestError("Vision audit reference must match its complete inline root owner without conflicting facts");
}
}
Expand All @@ -580,16 +599,24 @@ function requireVisionAuditReferences(payload: JsonObject): void {
}

function referenceVisionContinuation(payload: JsonObject,
identity = contextSourceIdentity(payload)): JsonObject {
identity = contextSourceIdentity(payload), shareCliView = false): JsonObject {
requireVisionAuditReferences(payload);
const owner = object(payload.vision_continuation_audit);
if (!Object.keys(owner).length) return payload;
const encoded = JSON.stringify(canonicalValue(owner)), reference = visionAuditReference(owner);
// A short audit is cheaper inline. Do not create a reference merely to count sharing.
if (Buffer.byteLength(encoded, "utf8") <= Buffer.byteLength(JSON.stringify(reference), "utf8")) return payload;
const source = identity(owner, ["vision_continuation_audit"]);
return mapNestedVisionAudits(payload, (audit, path) =>
identity(audit, path) === source ? structuredClone(reference) : audit);
return mapNestedVisionAudits(payload, (audit, path) => {
const candidate = identity(audit, path);
if (candidate === source) return structuredClone(reference);
if (!shareCliView || path[1] !== "cli_channel" || !supportsCliVisionAuditView(owner)) return audit;
const view = cliVisionAuditView(owner);
const scopedReference = visionAuditReference(view, true);
return candidate === identity(view, ["vision_continuation_audit"]) &&

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

完整包的同值去重通过预算。现有 App 原生选读仍请求 CLI 通道。File 和 SQLite 跟完正常首读与余量入口后均缺失原收尾步骤和先读登记材料的说明。请让现有渐进读计划在看到此引用时从同一摘要选读根 audit,带回原依赖时机。

Buffer.byteLength(JSON.stringify(scopedReference), "utf8") < Buffer.byteLength(candidate, "utf8")
? scopedReference : audit;
});
}

/** The verified current Task is the only owner of a shared lane title. Keep
Expand Down Expand Up @@ -2110,7 +2137,7 @@ export function composeCompleteTurnDecision(value: unknown): JsonObject {
source = referenceReplanAuthoring(source, sourceIdentity);
source = referenceExploreGuidance(source);
source = referenceCurrentTaskTitle(source);
source = referenceVisionContinuation(source, sourceIdentity);
source = referenceVisionContinuation(source, sourceIdentity, true);
source = referenceQuotaSummaryLanes(source, sourceIdentity);
requireCompleteDecisionSource(source);
const result: JsonObject = {...source, schema_version: COMPLETE_TURN_DECISION_VERSION,
Expand Down
Loading
Loading