Skip to content

Commit df5c20d

Browse files
authored
feat(todos): add an opt-in queue overview (#7581)
* feat(todos): add an opt-in queue summary Signed-off-by: Lihua <1017343802@qq.com> * fix(todos): retain queue title truncation with explicit limits Signed-off-by: Lihua <1017343802@qq.com> --------- Signed-off-by: Lihua <1017343802@qq.com>
1 parent 4514c15 commit df5c20d

13 files changed

Lines changed: 395 additions & 9 deletions

‎docs/status-data-contract.md‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2772,3 +2772,37 @@ The public examples under `examples/` are sanitized and can be used for demos.
27722772
- Consumers should handle missing `run_history` as unavailable.
27732773
- Consumers should treat `contract.ok=false` as a stronger signal than an empty
27742774
attention queue.
2775+
## Explicit Todo queue overview
2776+
2777+
`loopx todo list --goal-id <goal-id> --summary` selects the versioned
2778+
`todo_list_summary_v0` overview. It leaves ordinary list output and the existing
2779+
`--thin` view unchanged. The overview is available in JSON and Markdown and
2780+
helps a reader choose which Todo to inspect; it is not execution admission.
2781+
2782+
The view reuses the canonical Todo query's role, status, Agent scope and stable
2783+
ordering. It shows at most eight records per role (sixteen for both roles).
2784+
`--limit` may lower that per-role cap. Agent-scoped hot reads retain their
2785+
existing omission of done records; explicit status/role reads retain their
2786+
existing selection. Blocked/deferred work and Monitors do not become runnable
2787+
merely because they appear in the overview.
2788+
2789+
One `todos` array contains `todo_id`, `role`, `title`, `status`, `priority`,
2790+
`claimed_by` and `title_truncated`. Titles are bounded to 180 Unicode code
2791+
points; canonical identities are retained. Markdown marks truncated titles
2792+
with `*`. `todo list --goal-id <goal-id> --todo-id <todo-id>` restores complete
2793+
requirements through the existing exact-read owner. `--summary` is mutually
2794+
exclusive with `--thin` and `--todo-id`.
2795+
2796+
`todo_count` and `matched_todo_count` cover the complete query match before
2797+
display limits, `returned_todo_count` is the number displayed, and
2798+
`omitted_todo_count` is their difference. `todo_list_summary_projection`
2799+
declares the version, per-role/text limits and full-detail routes. The compact
2800+
`authority_read` retains provider identity/revision/cursor and the canonical
2801+
read/fallback facts. The existing `projection_envelope` distinguishes complete
2802+
source coverage from display truncation. An unavailable source remains an
2803+
error, never a successful empty queue.
2804+
2805+
The new `todo_list_summary` output-budget variant has separate JSON/Markdown
2806+
ceilings. Existing default and thin budgets remain unchanged. App and Lark
2807+
callers keep their current full/exact views; this opt-in CLI projection does
2808+
not switch consumers, create writes, or replace quota/lease/acceptance checks.

‎loopx/cli_commands/todo_argument_validation.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
("--agent-id", "agent_id"),
8181
("--limit", "todo_limit"),
8282
("--thin", "todo_thin"),
83+
("--summary", "todo_summary"),
8384
("--state-file", "state_file"),
8485
("--execute", "execute"),
8586
("--provider-revision", "provider_revision"),
@@ -142,7 +143,7 @@
142143
# Read/claim subsets share validation and help. Update help reuses the mutable
143144
# field owner; other lifecycle commands retain full help until centralized.
144145
TODO_ACTION_FIELDS = {
145-
"list": frozenset({"role", "todo_id", "status", "agent_id", "todo_limit", "todo_thin", "state_file", "project", "dry_run"}),
146+
"list": frozenset({"role", "todo_id", "status", "agent_id", "todo_limit", "todo_thin", "todo_summary", "state_file", "project", "dry_run"}),
146147
"receipt": frozenset({"operation_id"}),
147148
"result-read": frozenset({"todo_id"}),
148149
"plan": frozenset({"text", "agent_id", "project"}),
@@ -693,6 +694,13 @@ def validate_shared_todo_options(args: argparse.Namespace) -> None:
693694
)
694695
if args.todo_thin and args.todo_command != "list":
695696
raise ValueError("--thin is supported only by todo list")
697+
if getattr(args, "todo_summary", False):
698+
if args.todo_command != "list":
699+
raise ValueError("--summary is supported only by todo list")
700+
if args.todo_thin:
701+
raise ValueError("todo list accepts either --summary or --thin")
702+
if args.todo_id:
703+
raise ValueError("Exact Todo reads return full requirements; remove --summary or omit --todo-id for a queue overview")
696704

697705

698706
def validate_capability_gap_options(args: argparse.Namespace) -> None:

‎loopx/cli_commands/todo_list.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def handle_todo_list_command(
3838
agent_id=args.agent_id,
3939
limit=args.todo_limit,
4040
thin=bool(args.todo_thin),
41+
**({"summary": True} if getattr(args, "todo_summary", False) else {}),
4142
project=Path(args.project).expanduser() if args.project else None,
4243
state_file=Path(args.state_file).expanduser() if args.state_file else None,
4344
runtime_root_arg=runtime_root_arg,

‎loopx/cli_commands/todo_registration.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,17 @@ def register_todo_command(
457457
"lower but not expand that bound."
458458
),
459459
)
460+
todo_parser.add_argument(
461+
"--summary",
462+
dest="todo_summary",
463+
action="store_true",
464+
help=(
465+
"For todo list, show a versioned queue overview with at most eight "
466+
"items per role; --limit can lower that bound. Use an exact "
467+
"--todo-id read for complete requirements. Cannot combine with "
468+
"--thin or --todo-id."
469+
),
470+
)
460471
todo_parser.add_argument("--project", help="Project root. Defaults to the registry goal repo.")
461472
todo_parser.add_argument("--state-file", help="Active goal state path. Defaults to the registry goal state_file.")
462473
todo_parser.add_argument("--dry-run", action="store_true", help="Preview the active-state edit without writing.")

‎loopx/control_plane/testing/cli_output_budget.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,20 @@ class CliOutputCommandClassification:
613613
max_chars={"json": 20_000, "markdown": 6_000},
614614
max_lines={"json": 600, "markdown": 60},
615615
),
616+
CliOutputModeVariantSpec(
617+
variant_id="todo_list_summary",
618+
parent_surface_id="todo_list",
619+
command="todo list --summary",
620+
output_formats=("json", "markdown"),
621+
semantic_json_keys=(
622+
"todos", "summary", "matched_todo_count", "returned_todo_count",
623+
"omitted_todo_count", "authority_read", "todo_list_summary_projection",
624+
"projection_envelope",
625+
),
626+
markdown_anchor="# LoopX Todo List Summary",
627+
max_chars={"json": 12_000, "markdown": 8_000},
628+
max_lines={"json": 320, "markdown": 40},
629+
),
616630
)
617631

618632

‎loopx/control_plane/todos/list_readback.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def list_goal_todos(
3232
runtime_root_arg: str | None = None,
3333
limit: int | None = None,
3434
thin: bool = False,
35+
summary: bool = False,
3536
read_scope: Literal["active", "completed_history"] = "active",
3637
json_references: bool = False,
3738
) -> dict[str, Any]:
@@ -44,6 +45,10 @@ def list_goal_todos(
4445
raise ValueError("todo_id must use the public token shape todo_<letters-digits-underscore-hyphen>")
4546
if normalized_todo_id and thin:
4647
raise ValueError("Exact Todo reads return full requirements; remove --thin or omit --todo-id for a bounded list")
48+
if summary and thin:
49+
raise ValueError("todo list accepts either --summary or --thin")
50+
if normalized_todo_id and summary:
51+
raise ValueError("Exact Todo reads return full requirements; remove --summary or omit --todo-id for a queue overview")
4752
normalized_agent_id = normalize_todo_claimed_by(agent_id) if agent_id else None
4853
if agent_id and not normalized_agent_id:
4954
raise ValueError("agent_id must be a public-safe agent token such as codex-main-control")
@@ -81,14 +86,16 @@ def list_goal_todos(
8186
from ..runtime.time import now_utc
8287

8388
now = now_utc()
84-
params = {"kind": "query",
89+
params: dict[str, Any] = {"kind": "query",
8590
"source": {"runtime_root": str(runtime_root.expanduser().resolve(strict=False)), "goal_id": goal_id},
8691
"rollout_events": list(rollout_events), "rollout_event_source": rollout_events.source,
8792
"observed_at": now.timestamp(), "evaluated_at": now.isoformat(),
8893
"query": {"goal_id": goal_id, "role": role, "status": normalize_todo_status(status),
8994
"todo_id": normalized_todo_id, "agent_id": normalized_agent_id, "limit": limit,
9095
"read_scope": read_scope, "json_references": json_references, "thin": thin,
9196
"state_file": str(resolved_state_file), "project": str(resolved_project) if resolved_project else None}}
97+
if summary:
98+
params["query"]["summary"] = True
9299
result = project_todo_read(params)
93100
if "payload" not in result:
94101
failure = result["canonical"]

‎loopx/control_plane/todos/markdown.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,44 @@ def _render_thin_todo_list(payload: dict[str, Any]) -> str:
150150
return "\n".join(lines)
151151

152152

153+
def _render_queue_summary(payload: dict[str, Any]) -> str:
154+
projection = payload["todo_list_summary_projection"]
155+
authority = payload.get("authority_read") or {}
156+
lines = ["# LoopX Todo List Summary", "",
157+
f"- goal_id: `{payload.get('goal_id')}`",
158+
f"- shown: `{payload.get('returned_todo_count')}` / `{payload.get('matched_todo_count')}`; omitted: `{payload.get('omitted_todo_count')}`",
159+
f"- item_limit_per_role: `{projection['item_limit_per_role']}`", ""]
160+
161+
def cell(value: Any) -> str:
162+
return " ".join(str(value if value is not None else "—").split()).replace("|", "\\|")
163+
164+
if payload["todos"]:
165+
lines.extend(["| Role | Priority | Status | Claimed by | Todo | ID |",
166+
"| --- | --- | --- | --- | --- | --- |"])
167+
for item in payload["todos"]:
168+
cells = [cell(item.get(key)) for key in (
169+
"role", "priority", "status", "claimed_by", "title", "todo_id")]
170+
if item.get("title_truncated"):
171+
cells[4] += " *"
172+
lines.append("| " + " | ".join(cells) + " |")
173+
else:
174+
lines.append("No matching Todos.")
175+
if any(item.get("title_truncated") for item in payload["todos"]):
176+
lines.extend(["", r"\* Title truncated; the exact read retains the full requirement."])
177+
lines.extend(["", f"- source: `{authority.get('source_authority')}` @ `{authority.get('provider_revision')}`",
178+
f"- full_detail: `{projection['full_detail_cold_paths'][0]}`",
179+
f"- readback: {projection['readback']}"])
180+
return "\n".join(lines)
181+
182+
153183
def render_todo_markdown(payload: dict[str, Any]) -> str:
154184
if payload.get("todo_detail_projection"):
155185
return _render_todo_detail(payload)
156186
if payload.get("command") == "project-markdown":
157187
return _render_todo_projection(payload)
158188
if payload.get("command") == "list":
189+
if payload.get("summary"):
190+
return _render_queue_summary(payload)
159191
if payload.get("thin"):
160192
return _render_thin_todo_list(payload)
161193

‎loopx/control_plane/todos/read_presentation.ts‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,18 @@ function compactThinValue(value: unknown): unknown {
3131
return value;
3232
}
3333

34+
function displayItems(items: unknown[], hideDone: boolean): unknown[] {
35+
return hideDone ? items.filter(row => !dict(row) || row.status !== "done") : items;
36+
}
37+
3438
export function compactTodoReadSummary(summary: JsonObject, role: string, limit: number | null): JsonObject {
3539
const result: JsonObject = {}, lanes: JsonObject = {};
3640
let omittedLanes = 0, omittedDicts = 0;
3741
for (const [key, value] of Object.entries(summary)) {
3842
if (Array.isArray(value)) {
3943
const cap = limit ?? (layout._RETAINED_LANE_LIMITS as Record<string, number>)[key];
4044
if (cap === undefined) {omittedLanes += Number(nonempty(value)); continue;}
41-
const retained = limit === null && key === "items" ? value.filter(row => !dict(row) || row.status !== "done") : value;
45+
const retained = displayItems(value, limit === null && key === "items");
4246
result[key] = retained.slice(0, cap).map(row => compactItem(row));
4347
if (retained.length > cap) lanes[key] = {shown: cap, total: retained.length};
4448
} else if (dict(value)) {
@@ -114,3 +118,36 @@ export function compactThinTodoReadSummary(summary: JsonObject, details: {
114118
omitted_nonempty_dict_count: omittedDicts, full_detail_cold_path: "todo list without --thin or active state"};
115119
return fields;
116120
}
121+
122+
/** An opt-in queue overview; selection, full requirements and admission stay upstream. */
123+
export function compactTodoQueueSummary(payload: JsonObject, hot: boolean): JsonObject {
124+
const limit = Math.min(8, typeof payload.explicit_limit === "number" ? payload.explicit_limit : 8);
125+
const projection = dict(payload.todo_list_projection) ? payload.todo_list_projection : {};
126+
const matched = Number(projection.matched_todo_count ?? payload.todo_count ?? 0);
127+
const todos: JsonObject[] = [];
128+
for (const role of ["user", "agent"]) {
129+
const group = payload[`${role}_todos`];
130+
if (!dict(group) || !Array.isArray(group.items)) continue;
131+
for (const row of displayItems(group.items, hot).filter(dict).slice(0, limit)) {
132+
const full = stripPythonWhitespace(String(row.title || row.text || ""));
133+
todos.push({todo_id: row.todo_id, role, title: compactText(full), status: row.status,
134+
priority: row.priority ?? null, claimed_by: row.claimed_by ?? null,
135+
title_truncated: Array.from(full).length > 180});
136+
}
137+
}
138+
const authority = dict(payload.authority_read) ? payload.authority_read : {};
139+
return {ok: payload.ok, dry_run: payload.dry_run, read_only: payload.read_only,
140+
command: payload.command, goal_id: payload.goal_id, role: payload.role,
141+
status_filter: payload.status_filter, source: payload.source,
142+
...(payload.agent_id_filter === undefined ? {} : {agent_id_filter: payload.agent_id_filter}),
143+
...(payload.unfiltered_todo_count === undefined ? {} : {unfiltered_todo_count: payload.unfiltered_todo_count}),
144+
todo_count: matched, matched_todo_count: matched, returned_todo_count: todos.length,
145+
omitted_todo_count: Math.max(0, matched - todos.length), summary: true, todos,
146+
authority_read: {source_authority: authority.source_authority, provider_revision: authority.provider_revision,
147+
cursor: authority.cursor, decision_read_from_provider: authority.decision_read_from_provider,
148+
legacy_fallback_used: authority.legacy_fallback_used},
149+
todo_list_summary_projection: {schema_version: "todo_list_summary_v0", item_limit_per_role: limit,
150+
item_text_limit: 180, counts_cover_full_match: true,
151+
full_detail_cold_paths: ["todo list --goal-id <goal-id> --todo-id <todo-id>", "todo list without --summary"],
152+
readback: "Queue overview only. Read the exact Todo for complete requirements; quota owns execution admission."}};
153+
}

‎loopx/control_plane/todos/read_transaction.ts‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/** Canonical provider IO and full-source summaries share one read transaction. */
22
import type {JsonObject} from "../effect_program.ts";
3-
import {requireJsonObject} from "../runtime_decode.ts";
3+
import {requireBoolean, requireJsonObject} from "../runtime_decode.ts";
4+
import {EffectRuntimeRequestError} from "../effect_runtime_errors.ts";
45
import {readCanonicalSnapshot} from "../coordination/canonical_snapshot_page.ts";
56
import {readLocalCoordinationTodoSource} from "../coordination/local_authority_read.ts";
67
import {LOCAL_COORDINATION_TODO_SNAPSHOT_PAGE_REQUEST_SCHEMA,
78
LOCAL_COORDINATION_TODO_LIST_RESULT_SCHEMA} from "../coordination/coordination_state_contract.generated.ts";
89
import {projectCanonicalTodoFields, selectTodoReadFields, projectTodoReadGroup, TODO_READ_RESULT} from "./read_projection.ts";
910
import {canonicalTodoReadItems, structureCanonicalTodo} from "./read_codec.ts";
10-
import {compactTodoReadSummary, compactThinTodoRead, todoReadProjectionContract} from "./read_presentation.ts";
11+
import {compactTodoReadSummary, compactThinTodoRead, compactTodoQueueSummary, todoReadProjectionContract} from "./read_presentation.ts";
1112
import {projectTodoContextPage} from "./context_projection.ts";
1213
import {sealProjectionEnvelope, PROJECTION_ENVELOPE_SEAL_REQUEST} from "../projection_envelope.ts";
1314

@@ -57,11 +58,14 @@ export async function readHistoricalTodoProjection(input: JsonObject): Promise<J
5758

5859
async function todoListPayload(input: JsonObject, original: JsonObject[], fields: JsonObject, canonical: JsonObject): Promise<JsonObject> {
5960
const query = requireJsonObject(input.query, "Todo list query");
61+
const summary = query.summary === undefined ? false : requireBoolean(query.summary, "Todo summary view");
62+
if (summary && (query.thin || query.todo_id)) throw new EffectRuntimeRequestError("Todo summary cannot be combined with thin or exact reads");
6063
const sourceName = "file_authority";
6164
const roles: unknown[] = query.role == null ? ["user", "agent"] : [query.role];
6265
const select = async (source: JsonObject) => selectTodoReadFields({...input, fields: source.fields,
6366
field_evaluations: source.field_evaluations, roles, status: query.status ?? null,
64-
todo_id: query.todo_id ?? null, agent_id: query.agent_id ?? null, limit: query.limit ?? null, source_name: sourceName});
67+
// The queue formatter applies its own row cap and needs the unshortened titles.
68+
todo_id: query.todo_id ?? null, agent_id: query.agent_id ?? null, limit: summary ? null : query.limit ?? null, source_name: sourceName});
6569
let selected = await select(fields);
6670
if (selected.rejection) return selected;
6771
let projection = requireJsonObject(selected.projection, "Todo read projection");
@@ -92,7 +96,7 @@ async function todoListPayload(input: JsonObject, original: JsonObject[], fields
9296
const matchedCount = todos.length;
9397
const hot = query.read_scope !== "completed_history" && query.agent_id && query.limit == null &&
9498
query.role == null && query.status == null && query.todo_id == null;
95-
if (hot) {
99+
if (hot && !summary) {
96100
const summaries = requireJsonObject(projection.summaries, "Todo summaries");
97101
for (const [key, summary] of Object.entries(summaries)) summaries[key] = compactTodoReadSummary(
98102
requireJsonObject(summary, "Todo summary"), key.replace(/_todos$/, ""), null);
@@ -126,7 +130,8 @@ async function todoListPayload(input: JsonObject, original: JsonObject[], fields
126130
Object.assign(payload, projection.summaries);
127131
// The existing formatter is composed here, so a public read never calls back
128132
// across runtimes for fields of the result it just received.
129-
const result = query.todo_id ? projectTodoContextPage({detail_payload: payload}) : query.thin ? compactThinTodoRead(payload) :
133+
const result = summary ? compactTodoQueueSummary(payload, Boolean(hot)) :
134+
query.todo_id ? projectTodoContextPage({detail_payload: payload}) : query.thin ? compactThinTodoRead(payload) :
130135
query.json_references ? projectTodoContextPage({list_payload: payload}) : payload;
131136
const shownCount = query.todo_id ? Number(result.todo !== null) : (result.todos as JsonObject[]).length;
132137
const observed = String(input.read_observed_at);

‎tests/control_plane/test_cli_output_budget.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,8 @@ def _mode_variant_commands(
689689
+ ["todo", "list", "--goal-id", GOAL_ID, "--limit", "3"],
690690
"todo_list_thin": common
691691
+ ["todo", "list", "--goal-id", GOAL_ID, "--thin"],
692+
"todo_list_summary": common
693+
+ ["todo", "list", "--goal-id", GOAL_ID, "--summary"],
692694
}
693695

694696

@@ -747,6 +749,7 @@ def test_manifest_covers_the_declared_agent_facing_surface_set() -> None:
747749
"heartbeat_prompt_full",
748750
"todo_list_limited",
749751
"todo_list_thin",
752+
"todo_list_summary",
750753
}
751754
assert set(CLI_OUTPUT_MODE_VARIANT_BY_ID) == expected_variants
752755
assert manifest["mode_variant_count"] == len(expected_variants)

0 commit comments

Comments
 (0)