@astralyn/pi 0.82.6 → 0.82.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/README.md +1 -1
- package/dist/cli/session-picker.d.ts.map +1 -1
- package/dist/cli/session-picker.js +11 -13
- package/dist/cli/session-picker.js.map +1 -1
- package/dist/core/extensions/types.d.ts +4 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +2 -2
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/tools/bash.d.ts +1 -5
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +16 -41
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +42 -11
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +6 -7
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +17 -8
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +3 -3
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +4 -4
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts +7 -0
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js +11 -0
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +2 -3
- package/dist/core/tools/write.js.map +1 -1
- package/dist/extensions/deepwiki/render.d.ts.map +1 -1
- package/dist/extensions/deepwiki/render.js +34 -22
- package/dist/extensions/deepwiki/render.js.map +1 -1
- package/dist/extensions/plan/constants.d.ts +32 -4
- package/dist/extensions/plan/constants.d.ts.map +1 -1
- package/dist/extensions/plan/constants.js +37 -6
- package/dist/extensions/plan/constants.js.map +1 -1
- package/dist/extensions/plan/index.d.ts +27 -0
- package/dist/extensions/plan/index.d.ts.map +1 -1
- package/dist/extensions/plan/index.js +150 -44
- package/dist/extensions/plan/index.js.map +1 -1
- package/dist/extensions/plan/schema.d.ts +5 -0
- package/dist/extensions/plan/schema.d.ts.map +1 -1
- package/dist/extensions/plan/schema.js.map +1 -1
- package/dist/extensions/plan/state.d.ts +11 -2
- package/dist/extensions/plan/state.d.ts.map +1 -1
- package/dist/extensions/plan/state.js +31 -9
- package/dist/extensions/plan/state.js.map +1 -1
- package/dist/extensions/plan/storage.d.ts +11 -3
- package/dist/extensions/plan/storage.d.ts.map +1 -1
- package/dist/extensions/plan/storage.js +45 -20
- package/dist/extensions/plan/storage.js.map +1 -1
- package/dist/extensions/plan/view.d.ts +15 -7
- package/dist/extensions/plan/view.d.ts.map +1 -1
- package/dist/extensions/plan/view.js +91 -16
- package/dist/extensions/plan/view.js.map +1 -1
- package/dist/extensions/question/dialog.d.ts.map +1 -1
- package/dist/extensions/question/dialog.js +29 -10
- package/dist/extensions/question/dialog.js.map +1 -1
- package/dist/extensions/question/index.d.ts.map +1 -1
- package/dist/extensions/question/index.js +7 -2
- package/dist/extensions/question/index.js.map +1 -1
- package/dist/extensions/question/render.d.ts +4 -8
- package/dist/extensions/question/render.d.ts.map +1 -1
- package/dist/extensions/question/render.js +202 -29
- package/dist/extensions/question/render.js.map +1 -1
- package/dist/extensions/question/results.d.ts.map +1 -1
- package/dist/extensions/question/results.js +1 -0
- package/dist/extensions/question/results.js.map +1 -1
- package/dist/extensions/question/schema.d.ts.map +1 -1
- package/dist/extensions/question/schema.js +2 -2
- package/dist/extensions/question/schema.js.map +1 -1
- package/dist/extensions/question/types.d.ts +1 -0
- package/dist/extensions/question/types.d.ts.map +1 -1
- package/dist/extensions/question/types.js +1 -1
- package/dist/extensions/question/types.js.map +1 -1
- package/dist/extensions/router/stream.d.ts +1 -0
- package/dist/extensions/router/stream.d.ts.map +1 -1
- package/dist/extensions/router/stream.js +44 -13
- package/dist/extensions/router/stream.js.map +1 -1
- package/dist/extensions/subagent/constants.d.ts +1 -0
- package/dist/extensions/subagent/constants.d.ts.map +1 -1
- package/dist/extensions/subagent/constants.js +1 -0
- package/dist/extensions/subagent/constants.js.map +1 -1
- package/dist/extensions/subagent/index.d.ts.map +1 -1
- package/dist/extensions/subagent/index.js +2 -0
- package/dist/extensions/subagent/index.js.map +1 -1
- package/dist/extensions/subagent/render.d.ts.map +1 -1
- package/dist/extensions/subagent/render.js +121 -48
- package/dist/extensions/subagent/render.js.map +1 -1
- package/dist/extensions/subagent/retry.d.ts +17 -0
- package/dist/extensions/subagent/retry.d.ts.map +1 -0
- package/dist/extensions/subagent/retry.js +41 -0
- package/dist/extensions/subagent/retry.js.map +1 -0
- package/dist/extensions/subagent/runner.d.ts.map +1 -1
- package/dist/extensions/subagent/runner.js +33 -5
- package/dist/extensions/subagent/runner.js.map +1 -1
- package/dist/extensions/subagent/sdk-runner.d.ts +6 -0
- package/dist/extensions/subagent/sdk-runner.d.ts.map +1 -1
- package/dist/extensions/subagent/sdk-runner.js +46 -24
- package/dist/extensions/subagent/sdk-runner.js.map +1 -1
- package/dist/extensions/subagent/types.d.ts +7 -0
- package/dist/extensions/subagent/types.d.ts.map +1 -1
- package/dist/extensions/subagent/types.js.map +1 -1
- package/dist/extensions/todo/index.d.ts.map +1 -1
- package/dist/extensions/todo/index.js +1 -1
- package/dist/extensions/todo/index.js.map +1 -1
- package/dist/extensions/todo/state.d.ts.map +1 -1
- package/dist/extensions/todo/state.js +10 -2
- package/dist/extensions/todo/state.js.map +1 -1
- package/dist/extensions/todo/view.d.ts +1 -1
- package/dist/extensions/todo/view.d.ts.map +1 -1
- package/dist/extensions/todo/view.js +179 -34
- package/dist/extensions/todo/view.js.map +1 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +2 -1
- package/dist/migrations.js.map +1 -1
- package/dist/modes/interactive/components/armin.d.ts.map +1 -1
- package/dist/modes/interactive/components/armin.js +5 -0
- package/dist/modes/interactive/components/armin.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts +1 -0
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js +4 -2
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/countdown-timer.d.ts +13 -6
- package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
- package/dist/modes/interactive/components/countdown-timer.js +54 -17
- package/dist/modes/interactive/components/countdown-timer.js.map +1 -1
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-selector.js +10 -6
- package/dist/modes/interactive/components/extension-selector.js.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.d.ts +11 -1
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.js +56 -0
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts +3 -0
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +52 -2
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +10 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +133 -18
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tool-group.d.ts +1 -0
- package/dist/modes/interactive/components/tool-group.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-group.js +5 -0
- package/dist/modes/interactive/components/tool-group.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts +10 -1
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +55 -2
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +5 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +72 -18
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +3 -2
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/utils/paths.d.ts +6 -0
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +8 -0
- package/dist/utils/paths.js.map +1 -1
- package/docs/bundled/README.md +1 -0
- package/docs/bundled/extensions/deepwiki.md +1 -1
- package/docs/bundled/extensions/plan.md +10 -9
- package/docs/bundled/extensions/question.md +7 -5
- package/docs/bundled/extensions/router.md +3 -4
- package/docs/bundled/extensions/statusline.md +0 -1
- package/docs/bundled/extensions/subagent.md +4 -3
- package/docs/bundled/extensions/todo.md +1 -1
- package/docs/bundled/tool-presentation.md +17 -16
- package/docs/extensions.md +20 -5
- package/docs/rpc.md +1 -1
- package/docs/usage.md +1 -1
- package/npm-shrinkwrap.json +6 -6
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../../src/extensions/todo/view.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AAEpE,OAAO,EAGN,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,UAAU,EACf,MAAM,aAAa,CAAC;AAGrB,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAKlD,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,UAAU,EAAE,KAAK,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAKpF,CAAC;AAQF,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,OAAO,CAEtG;AAYD,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,MAAM,EACb,eAAe,EAAE,WAAW,CAAC,MAAM,CAAC,GAClC,MAAM,EAAE,CAoBV;AA4DD,KAAK,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;AAqG/D;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,YAAY,GAAG,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,CAItG;AAED,UAAU,sBAAsB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;CAClC;AA6JD,4EAA4E;AAC5E,wBAAgB,mBAAmB,CAClC,IAAI,EAAE,YAAY,GAAG,SAAS,EAC9B,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,sBAAsB,GAC7B,MAAM,CASR;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAuB1D","sourcesContent":["import { truncateToWidth } from \"@earendil-works/pi-tui\";\nimport type { AgentToolResult } from \"../../core/extensions/types.ts\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { LIST_DISPLAY_MAX_ITEMS } from \"./constants.ts\";\nimport {\n\tTODO_DETAILS_SCHEMA_VERSION,\n\ttype TodoItem,\n\ttype TodoParams,\n\ttype TodoState,\n\ttype TodoStatus,\n} from \"./schema.ts\";\nimport { unresolvedDependencyIds } from \"./state.ts\";\n\nexport const STATUS_MARK: Record<TodoStatus, string> = {\n\tpending: \"[ ]\",\n\tin_progress: \"[>]\",\n\tcompleted: \"[x]\",\n\tdeleted: \"[-]\",\n};\n\nexport const STATUS_COLOR: Record<TodoStatus, \"dim\" | \"warning\" | \"success\" | \"muted\"> = {\n\tpending: \"dim\",\n\tin_progress: \"warning\",\n\tcompleted: \"success\",\n\tdeleted: \"muted\",\n};\n\nconst OVERLAY_BODY_MAX_ITEMS = 10;\n\nfunction visibleTodos(state: TodoState): TodoItem[] {\n\treturn state.items.filter((item) => item.status !== \"deleted\");\n}\n\nexport function hasVisibleOverlayItems(state: TodoState, hiddenCompleted: ReadonlySet<number>): boolean {\n\treturn visibleTodos(state).some((item) => item.status !== \"completed\" || !hiddenCompleted.has(item.id));\n}\n\nfunction todoCounts(items: TodoItem[]): { total: number; pending: number; inProgress: number; completed: number } {\n\tconst counts = { total: items.length, pending: 0, inProgress: 0, completed: 0 };\n\tfor (const item of items) {\n\t\tif (item.status === \"pending\") counts.pending++;\n\t\telse if (item.status === \"in_progress\") counts.inProgress++;\n\t\telse if (item.status === \"completed\") counts.completed++;\n\t}\n\treturn counts;\n}\n\nexport function renderOverlayLines(\n\tstate: TodoState,\n\ttheme: Theme,\n\twidth: number,\n\thiddenCompleted: ReadonlySet<number>,\n): string[] {\n\tconst allVisible = visibleTodos(state);\n\tconst visible = allVisible.filter((item) => item.status !== \"completed\" || !hiddenCompleted.has(item.id));\n\tif (!visible.length) return [];\n\n\tconst counts = todoCounts(allVisible);\n\tconst hasActive = visible.some((item) => item.status === \"pending\" || item.status === \"in_progress\");\n\tconst heading = `${theme.fg(hasActive ? \"accent\" : \"dim\", \"Todos\")} ${theme.fg(\"dim\", `(${counts.completed}/${counts.total})`)}`;\n\tconst lines = [truncateToWidth(heading, width, \"...\")];\n\n\tconst showIds = visible.some((item) => item.blockedBy?.length);\n\tconst body = chooseOverlayItems(visible, state, OVERLAY_BODY_MAX_ITEMS);\n\tfor (const item of body.items) {\n\t\tlines.push(truncateToWidth(` ${formatOverlayItem(item, state, theme, showIds)}`, width, \"...\"));\n\t}\n\tif (body.hidden.length > 0) {\n\t\tlines.push(truncateToWidth(theme.fg(\"dim\", ` ${formatHiddenSummary(body.hidden)}`), width, \"...\"));\n\t}\n\tlines.push(\"\");\n\treturn lines;\n}\n\nfunction byIdAsc(first: TodoItem, second: TodoItem): number {\n\treturn first.id - second.id;\n}\n\nfunction overlayPriority(state: TodoState, item: TodoItem): number {\n\tif (item.status === \"in_progress\") return 0;\n\tif (item.status === \"pending\" && unresolvedDependencyIds(state, item).length === 0) return 1;\n\tif (item.status === \"pending\") return 2;\n\treturn 3; // Completed items here are recent; older ones are hidden by TodoOverlay.\n}\n\nfunction chooseOverlayItems(\n\titems: TodoItem[],\n\tstate: TodoState,\n\tmaxBody: number,\n): { items: TodoItem[]; hidden: TodoItem[] } {\n\tconst prioritized = [...items].sort((first, second) => {\n\t\tconst priorityDelta = overlayPriority(state, first) - overlayPriority(state, second);\n\t\treturn priorityDelta || byIdAsc(first, second);\n\t});\n\tif (prioritized.length <= maxBody) return { items: prioritized, hidden: [] };\n\n\tconst shown = prioritized.slice(0, Math.max(1, maxBody - 1));\n\treturn { items: shown, hidden: prioritized.slice(shown.length) };\n}\n\nfunction formatHiddenSummary(items: TodoItem[]): string {\n\tconst counts = todoCounts(items);\n\tconst parts: string[] = [];\n\tif (counts.inProgress) parts.push(`${counts.inProgress} in progress`);\n\tif (counts.pending) parts.push(`${counts.pending} pending`);\n\tif (counts.completed) parts.push(`${counts.completed} completed`);\n\treturn `+${items.length} more${parts.length ? ` (${parts.join(\", \")})` : \"\"}`;\n}\n\nfunction formatOverlayItem(item: TodoItem, state: TodoState, theme: Theme, showId: boolean): string {\n\tlet text = theme.fg(STATUS_COLOR[item.status], STATUS_MARK[item.status]);\n\tif (showId) text += ` ${theme.fg(\"accent\", `#${item.id}`)}`;\n\tconst subject =\n\t\titem.status === \"completed\" ? theme.strikethrough(theme.fg(\"dim\", item.subject)) : theme.fg(\"text\", item.subject);\n\ttext += ` ${subject}`;\n\tif (item.status === \"in_progress\" && item.activeForm) text += ` ${theme.fg(\"dim\", `(${item.activeForm})`)}`;\n\n\tconst unresolved = unresolvedDependencyIds(state, item);\n\tif (unresolved.length) {\n\t\ttext += ` ${theme.fg(\"dim\", `blocked by ${unresolved.map((id) => `#${id}`).join(\",\")}`)}`;\n\t\tif (item.status === \"pending\" || item.status === \"in_progress\")\n\t\t\ttext += ` ${theme.fg(\"warning\", \"(deps incomplete)\")}`;\n\t}\n\treturn text;\n}\n\n// ---- tool call rendering ----------------------------------------------------\n// Collapsed todo calls join the `todo` tool group, so each row must survive as a\n// single headline with no result beneath it (ToolGroupComponent drops results and\n// appends one shared expand hint). Args come straight off the wire and can be\n// partial while the call streams, so every field is read defensively.\n\ntype TodoCallArgs = Partial<Record<keyof TodoParams, unknown>>;\n\nconst EDGE_PARAMS = [\"blockedBy\", \"addBlockedBy\", \"removeBlockedBy\", \"addBlocks\", \"removeBlocks\"] as const;\n\nfunction callText(value: unknown): string {\n\treturn typeof value === \"string\" ? value.trim() : \"\";\n}\n\nfunction callId(value: unknown): number | undefined {\n\treturn typeof value === \"number\" && Number.isInteger(value) ? value : undefined;\n}\n\nfunction callIds(value: unknown): number[] {\n\treturn Array.isArray(value) ? value.filter((entry): entry is number => typeof entry === \"number\") : [];\n}\n\nfunction callArrayLength(value: unknown): number | undefined {\n\treturn Array.isArray(value) ? value.length : undefined;\n}\n\nfunction callBatchSubjects(value: unknown): string {\n\tif (!Array.isArray(value)) return \"\";\n\tconst subjects: string[] = [];\n\tfor (const item of value.slice(0, 3)) {\n\t\tif (!item || typeof item !== \"object\" || Array.isArray(item)) continue;\n\t\tconst subject = callText((item as Record<string, unknown>).subject);\n\t\tif (subject) subjects.push(subject);\n\t}\n\treturn subjects.join(\"; \");\n}\n\nfunction callNonNegativeInteger(value: unknown): number | undefined {\n\treturn typeof value === \"number\" && Number.isInteger(value) && value >= 0 ? value : undefined;\n}\n\nfunction isTodoStatus(value: string): value is TodoStatus {\n\treturn Object.hasOwn(STATUS_MARK, value);\n}\n\nfunction formatCallHeadline(args: TodoCallArgs | undefined, theme: Theme): string {\n\tconst action = callText(args?.action);\n\tconst parts = [theme.fg(\"toolTitle\", theme.bold(action ? `todo ${action}` : \"todo\"))];\n\n\tif (action === \"create_many\") {\n\t\tconst count = callArrayLength(args?.items);\n\t\tif (count !== undefined) parts.push(theme.fg(\"dim\", `${count} tasks`));\n\t}\n\n\tconst id = callId(args?.id);\n\tif (id !== undefined) parts.push(theme.fg(\"accent\", `#${id}`));\n\n\tconst status = callText(args?.status);\n\tif (status && isTodoStatus(status)) parts.push(theme.fg(STATUS_COLOR[status], status));\n\n\tconst subject = callText(args?.subject);\n\tif (subject) parts.push(theme.fg(\"text\", subject));\n\n\t// Dependency-only updates would otherwise render as a bare `todo update #3`.\n\tconst hasEdgeChange = EDGE_PARAMS.some((key) => callIds(args?.[key]).length > 0);\n\tif (!status && !subject && hasEdgeChange) parts.push(theme.fg(\"dim\", \"dependencies\"));\n\n\treturn parts.join(\" \");\n}\n\nfunction formatCallDetails(args: TodoCallArgs | undefined, theme: Theme): string[] {\n\tconst lines: string[] = [];\n\tconst push = (label: string, value: string) => {\n\t\tif (value) lines.push(theme.fg(\"dim\", `${label}: ${value}`));\n\t};\n\n\tconst action = callText(args?.action);\n\tif (action === \"create_many\") {\n\t\tconst count = callArrayLength(args?.items);\n\t\tif (count !== undefined) {\n\t\t\tconst subjects = callBatchSubjects(args?.items);\n\t\t\tpush(\"batch\", `${count} tasks${subjects ? ` (${subjects})` : \"\"}`);\n\t\t}\n\t}\n\n\tpush(\"description\", callText(args?.description));\n\tpush(\"activeForm\", callText(args?.activeForm));\n\tpush(\"owner\", callText(args?.owner));\n\tfor (const key of EDGE_PARAMS) {\n\t\tconst ids = callIds(args?.[key]);\n\t\tif (ids.length) push(key, ids.map((id) => `#${id}`).join(\",\"));\n\t}\n\tif (args?.includeDeleted === true) push(\"includeDeleted\", \"true\");\n\tconst limit = callId(args?.limit);\n\tif (limit !== undefined) push(\"limit\", String(limit));\n\tconst afterId = callId(args?.afterId);\n\tif (afterId !== undefined) push(\"afterId\", String(afterId));\n\tpush(\"query\", callText(args?.query));\n\tif (args?.unblockedOnly === true) push(\"unblockedOnly\", \"true\");\n\tif (args?.confirm === true) push(\"confirm\", \"true\");\n\tconst expectedCount = callNonNegativeInteger(args?.expectedCount);\n\tif (expectedCount !== undefined) push(\"expectedCount\", String(expectedCount));\n\tconst metadata = args?.metadata;\n\tif (metadata && typeof metadata === \"object\") push(\"metadata\", Object.keys(metadata).join(\",\"));\n\treturn lines;\n}\n\n/**\n * One-line call summary when collapsed; the same headline plus the parameters\n * the result never echoes (description, activeForm, dependencies) when expanded.\n */\nexport function formatTodoCall(args: TodoCallArgs | undefined, theme: Theme, expanded: boolean): string {\n\tconst headline = formatCallHeadline(args, theme);\n\tif (!expanded) return headline;\n\treturn [headline, ...formatCallDetails(args, theme)].join(\"\\n\");\n}\n\ninterface TodoGroupRenderContext {\n\tisError: boolean;\n\tisPartial: boolean;\n\tresult?: AgentToolResult<unknown>;\n}\n\ninterface GroupTodoDetails {\n\taction: string;\n\toperation: Record<string, unknown>;\n\titems: unknown;\n}\n\nconst GROUP_FAILURE_MAX_LENGTH = 120;\nconst GROUP_MAX_IDS = 20;\nconst GROUP_MAX_SNAPSHOT_ITEMS = 10_000;\nconst TODO_ACTIONS = new Set([\"create\", \"create_many\", \"update\", \"list\", \"get\", \"delete\", \"clear\"]);\n\nfunction safeRecord(value: unknown): Record<string, unknown> | undefined {\n\ttry {\n\t\treturn value !== null && typeof value === \"object\" && !Array.isArray(value)\n\t\t\t? (value as Record<string, unknown>)\n\t\t\t: undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction safeValue(record: Record<string, unknown>, key: string): unknown {\n\ttry {\n\t\treturn record[key];\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction safeString(value: unknown): string | undefined {\n\treturn typeof value === \"string\" ? value : undefined;\n}\n\nfunction groupDetails(value: unknown): GroupTodoDetails | undefined {\n\tconst details = safeRecord(value);\n\tif (!details || safeValue(details, \"schemaVersion\") !== TODO_DETAILS_SCHEMA_VERSION) return undefined;\n\tconst action = safeString(safeValue(details, \"action\"));\n\tif (!action || !TODO_ACTIONS.has(action)) return undefined;\n\tconst operation = safeRecord(safeValue(details, \"operation\"));\n\tif (!operation || safeValue(operation, \"kind\") !== action) return undefined;\n\treturn { action, operation, items: safeValue(details, \"items\") };\n}\n\nfunction groupPositiveInteger(value: unknown): number | undefined {\n\treturn typeof value === \"number\" && Number.isSafeInteger(value) && value >= 1 ? value : undefined;\n}\n\nfunction groupIds(value: unknown): number[] | undefined {\n\ttry {\n\t\tif (!Array.isArray(value) || value.length === 0 || value.length > GROUP_MAX_IDS) return undefined;\n\t\tconst ids: number[] = [];\n\t\tfor (const valueAtIndex of value) {\n\t\t\tconst id = groupPositiveInteger(valueAtIndex);\n\t\t\tif (id === undefined) return undefined;\n\t\t\tids.push(id);\n\t\t}\n\t\treturn ids;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction groupNonNegativeInteger(value: unknown): number | undefined {\n\treturn typeof value === \"number\" && Number.isSafeInteger(value) && value >= 0 ? value : undefined;\n}\n\nfunction formatGroupStatusCounts(value: unknown, resultCount: unknown): string | undefined {\n\tconst count = groupNonNegativeInteger(resultCount);\n\tif (count === undefined) return undefined;\n\tif (count === 0) return \"no tasks\";\n\n\tconst rawCounts = safeRecord(value);\n\tif (!rawCounts) return undefined;\n\tconst parts: string[] = [];\n\tlet total = 0;\n\tfor (const status of [\"pending\", \"in_progress\", \"completed\", \"deleted\"] as const) {\n\t\tconst statusCount = groupNonNegativeInteger(safeValue(rawCounts, status));\n\t\tif (statusCount === undefined) continue;\n\t\ttotal += statusCount;\n\t\tif (statusCount > 0) parts.push(`${statusCount} ${status}`);\n\t}\n\treturn total === count && parts.length ? parts.join(\", \") : undefined;\n}\n\nfunction groupItemStatus(value: unknown, id: number): TodoStatus | undefined {\n\ttry {\n\t\tif (!Array.isArray(value) || value.length > GROUP_MAX_SNAPSHOT_ITEMS) return undefined;\n\t\tfor (const rawItem of value) {\n\t\t\tconst item = safeRecord(rawItem);\n\t\t\tif (!item || safeValue(item, \"id\") !== id) continue;\n\t\t\tconst status = safeString(safeValue(item, \"status\"));\n\t\t\treturn status && isTodoStatus(status) ? status : undefined;\n\t\t}\n\t} catch {\n\t\treturn undefined;\n\t}\n\treturn undefined;\n}\n\nfunction formatGroupFailure(result: AgentToolResult<unknown> | undefined): string {\n\ttry {\n\t\tfor (const block of result?.content.slice(0, 8) ?? []) {\n\t\t\tif (block.type !== \"text\" || typeof block.text !== \"string\") continue;\n\t\t\tconst reason = block.text\n\t\t\t\t.replace(/[\\u0000-\\u001f\\u007f-\\u009f]/g, \" \")\n\t\t\t\t.replace(/\\s+/g, \" \")\n\t\t\t\t.trim();\n\t\t\tif (!reason) continue;\n\t\t\treturn reason.length > GROUP_FAILURE_MAX_LENGTH ? `${reason.slice(0, GROUP_FAILURE_MAX_LENGTH - 1)}…` : reason;\n\t\t}\n\t} catch {\n\t\t// Tool results can come from historical or third-party sources.\n\t}\n\treturn \"tool failed\";\n}\n\nfunction formatTodoGroupSuccess(result: AgentToolResult<unknown>): string | undefined {\n\tconst details = groupDetails(result.details);\n\tif (!details) return undefined;\n\n\tswitch (details.action) {\n\t\tcase \"create\":\n\t\tcase \"create_many\": {\n\t\t\tconst ids = groupIds(safeValue(details.operation, \"ids\"));\n\t\t\tif (!ids || (details.action === \"create\" && ids.length !== 1)) return undefined;\n\t\t\treturn `todo created ${ids.length} ${ids.length === 1 ? \"task\" : \"tasks\"} ${ids.map((id) => `#${id}`).join(\", \")}`;\n\t\t}\n\t\tcase \"update\": {\n\t\t\tconst id = groupPositiveInteger(safeValue(details.operation, \"id\"));\n\t\t\tconst status = safeString(safeValue(details.operation, \"status\"));\n\t\t\treturn id !== undefined && status && isTodoStatus(status) ? `todo updated #${id} ${status}` : undefined;\n\t\t}\n\t\tcase \"list\": {\n\t\t\tconst counts = formatGroupStatusCounts(\n\t\t\t\tsafeValue(details.operation, \"statusCounts\"),\n\t\t\t\tsafeValue(details.operation, \"resultCount\"),\n\t\t\t);\n\t\t\treturn counts === undefined ? undefined : `todo list: ${counts}`;\n\t\t}\n\t\tcase \"get\": {\n\t\t\tconst id = groupPositiveInteger(safeValue(details.operation, \"id\"));\n\t\t\tconst status = id === undefined ? undefined : groupItemStatus(details.items, id);\n\t\t\treturn status ? `todo get #${id} ${status}` : undefined;\n\t\t}\n\t\tcase \"delete\": {\n\t\t\tconst id = groupPositiveInteger(safeValue(details.operation, \"id\"));\n\t\t\treturn id === undefined ? undefined : `todo deleted #${id}`;\n\t\t}\n\t\tcase \"clear\": {\n\t\t\tconst count = callNonNegativeInteger(safeValue(details.operation, \"count\"));\n\t\t\treturn count === undefined ? undefined : `todo cleared ${count} ${count === 1 ? \"task\" : \"tasks\"}`;\n\t\t}\n\t}\n}\n\n/** Compact result-aware summary used only by collapsed todo tool groups. */\nexport function formatTodoGroupCall(\n\targs: TodoCallArgs | undefined,\n\ttheme: Theme,\n\tcontext: TodoGroupRenderContext,\n): string {\n\tif (context.isError) {\n\t\treturn `${formatTodoCall(args, theme, false)} ${theme.fg(\"error\", `failed: ${formatGroupFailure(context.result)}`)}`;\n\t}\n\tif (!context.isPartial && context.result) {\n\t\tconst summary = formatTodoGroupSuccess(context.result);\n\t\tif (summary) return theme.fg(\"toolTitle\", summary);\n\t}\n\treturn formatTodoCall(args, theme, false);\n}\n\nexport function formatCommandList(state: TodoState): string {\n\tconst visible = visibleTodos(state);\n\tif (!visible.length) return \"No todos yet.\";\n\tconst lines: string[] = [];\n\tlet shown = 0;\n\tfor (const status of [\"in_progress\", \"pending\", \"completed\"] as const) {\n\t\tconst group = visible.filter((item) => item.status === status).sort(byIdAsc);\n\t\tif (!group.length || shown >= LIST_DISPLAY_MAX_ITEMS) continue;\n\t\tlines.push(status);\n\t\tfor (const item of group) {\n\t\t\tif (shown >= LIST_DISPLAY_MAX_ITEMS) break;\n\t\t\tconst active = item.status === \"in_progress\" && item.activeForm ? ` (${item.activeForm})` : \"\";\n\t\t\tconst owner = item.owner ? ` @${item.owner}` : \"\";\n\t\t\tconst unresolved = unresolvedDependencyIds(state, item);\n\t\t\tconst deps = unresolved.length ? ` blocked by ${unresolved.map((id) => `#${id}`).join(\",\")}` : \"\";\n\t\t\tlines.push(` ${STATUS_MARK[item.status]} #${item.id} ${item.subject}${active}${owner}${deps}`);\n\t\t\tshown++;\n\t\t}\n\t}\n\tif (visible.length > shown) {\n\t\tlines.push(`… and ${visible.length - shown} more; use todo list with limit and afterId to page.`);\n\t}\n\treturn lines.join(\"\\n\");\n}\n"]}
|
|
1
|
+
{"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../../src/extensions/todo/view.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AAEpE,OAAO,EAGN,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,UAAU,EACf,MAAM,aAAa,CAAC;AAGrB,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAKlD,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,UAAU,EAAE,KAAK,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAKpF,CAAC;AAQF,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,OAAO,CAEtG;AAYD,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,MAAM,EACb,eAAe,EAAE,WAAW,CAAC,MAAM,CAAC,GAClC,MAAM,EAAE,CAoBV;AA4DD,KAAK,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;AA4N/D;;;GAGG;AACH,wBAAgB,cAAc,CAC7B,IAAI,EAAE,YAAY,GAAG,SAAS,EAC9B,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,OAAO,EACjB,MAAM,CAAC,EAAE,eAAe,CAAC,OAAO,CAAC,GAC/B,MAAM,CAIR;AAED,UAAU,sBAAsB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;CAClC;AA4LD,4EAA4E;AAC5E,wBAAgB,mBAAmB,CAClC,IAAI,EAAE,YAAY,GAAG,SAAS,EAC9B,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,sBAAsB,GAC7B,MAAM,CASR;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAuB1D","sourcesContent":["import { truncateToWidth } from \"@earendil-works/pi-tui\";\nimport type { AgentToolResult } from \"../../core/extensions/types.ts\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { LIST_DISPLAY_MAX_ITEMS, TODO_MAX_BATCH_ITEMS, TODO_MAX_BLOCKED_BY } from \"./constants.ts\";\nimport {\n\tTODO_DETAILS_SCHEMA_VERSION,\n\ttype TodoItem,\n\ttype TodoParams,\n\ttype TodoState,\n\ttype TodoStatus,\n} from \"./schema.ts\";\nimport { unresolvedDependencyIds } from \"./state.ts\";\n\nexport const STATUS_MARK: Record<TodoStatus, string> = {\n\tpending: \"[ ]\",\n\tin_progress: \"[>]\",\n\tcompleted: \"[x]\",\n\tdeleted: \"[-]\",\n};\n\nexport const STATUS_COLOR: Record<TodoStatus, \"dim\" | \"warning\" | \"success\" | \"muted\"> = {\n\tpending: \"dim\",\n\tin_progress: \"warning\",\n\tcompleted: \"success\",\n\tdeleted: \"muted\",\n};\n\nconst OVERLAY_BODY_MAX_ITEMS = 10;\n\nfunction visibleTodos(state: TodoState): TodoItem[] {\n\treturn state.items.filter((item) => item.status !== \"deleted\");\n}\n\nexport function hasVisibleOverlayItems(state: TodoState, hiddenCompleted: ReadonlySet<number>): boolean {\n\treturn visibleTodos(state).some((item) => item.status !== \"completed\" || !hiddenCompleted.has(item.id));\n}\n\nfunction todoCounts(items: TodoItem[]): { total: number; pending: number; inProgress: number; completed: number } {\n\tconst counts = { total: items.length, pending: 0, inProgress: 0, completed: 0 };\n\tfor (const item of items) {\n\t\tif (item.status === \"pending\") counts.pending++;\n\t\telse if (item.status === \"in_progress\") counts.inProgress++;\n\t\telse if (item.status === \"completed\") counts.completed++;\n\t}\n\treturn counts;\n}\n\nexport function renderOverlayLines(\n\tstate: TodoState,\n\ttheme: Theme,\n\twidth: number,\n\thiddenCompleted: ReadonlySet<number>,\n): string[] {\n\tconst allVisible = visibleTodos(state);\n\tconst visible = allVisible.filter((item) => item.status !== \"completed\" || !hiddenCompleted.has(item.id));\n\tif (!visible.length) return [];\n\n\tconst counts = todoCounts(allVisible);\n\tconst hasActive = visible.some((item) => item.status === \"pending\" || item.status === \"in_progress\");\n\tconst heading = `${theme.fg(hasActive ? \"accent\" : \"dim\", \"Todos\")} ${theme.fg(\"dim\", `(${counts.completed}/${counts.total})`)}`;\n\tconst lines = [truncateToWidth(heading, width, \"...\")];\n\n\tconst showIds = visible.some((item) => item.blockedBy?.length);\n\tconst body = chooseOverlayItems(visible, state, OVERLAY_BODY_MAX_ITEMS);\n\tfor (const item of body.items) {\n\t\tlines.push(truncateToWidth(` ${formatOverlayItem(item, state, theme, showIds)}`, width, \"...\"));\n\t}\n\tif (body.hidden.length > 0) {\n\t\tlines.push(truncateToWidth(theme.fg(\"dim\", ` ${formatHiddenSummary(body.hidden)}`), width, \"...\"));\n\t}\n\tlines.push(\"\");\n\treturn lines;\n}\n\nfunction byIdAsc(first: TodoItem, second: TodoItem): number {\n\treturn first.id - second.id;\n}\n\nfunction overlayPriority(state: TodoState, item: TodoItem): number {\n\tif (item.status === \"in_progress\") return 0;\n\tif (item.status === \"pending\" && unresolvedDependencyIds(state, item).length === 0) return 1;\n\tif (item.status === \"pending\") return 2;\n\treturn 3; // Completed items here are recent; older ones are hidden by TodoOverlay.\n}\n\nfunction chooseOverlayItems(\n\titems: TodoItem[],\n\tstate: TodoState,\n\tmaxBody: number,\n): { items: TodoItem[]; hidden: TodoItem[] } {\n\tconst prioritized = [...items].sort((first, second) => {\n\t\tconst priorityDelta = overlayPriority(state, first) - overlayPriority(state, second);\n\t\treturn priorityDelta || byIdAsc(first, second);\n\t});\n\tif (prioritized.length <= maxBody) return { items: prioritized, hidden: [] };\n\n\tconst shown = prioritized.slice(0, Math.max(1, maxBody - 1));\n\treturn { items: shown, hidden: prioritized.slice(shown.length) };\n}\n\nfunction formatHiddenSummary(items: TodoItem[]): string {\n\tconst counts = todoCounts(items);\n\tconst parts: string[] = [];\n\tif (counts.inProgress) parts.push(`${counts.inProgress} in progress`);\n\tif (counts.pending) parts.push(`${counts.pending} pending`);\n\tif (counts.completed) parts.push(`${counts.completed} completed`);\n\treturn `+${items.length} more${parts.length ? ` (${parts.join(\", \")})` : \"\"}`;\n}\n\nfunction formatOverlayItem(item: TodoItem, state: TodoState, theme: Theme, showId: boolean): string {\n\tlet text = theme.fg(STATUS_COLOR[item.status], STATUS_MARK[item.status]);\n\tif (showId) text += ` ${theme.fg(\"accent\", `#${item.id}`)}`;\n\tconst subject =\n\t\titem.status === \"completed\" ? theme.strikethrough(theme.fg(\"dim\", item.subject)) : theme.fg(\"text\", item.subject);\n\ttext += ` ${subject}`;\n\tif (item.status === \"in_progress\" && item.activeForm) text += ` ${theme.fg(\"dim\", `(${item.activeForm})`)}`;\n\n\tconst unresolved = unresolvedDependencyIds(state, item);\n\tif (unresolved.length) {\n\t\ttext += ` ${theme.fg(\"dim\", `blocked by ${unresolved.map((id) => `#${id}`).join(\",\")}`)}`;\n\t\tif (item.status === \"pending\" || item.status === \"in_progress\")\n\t\t\ttext += ` ${theme.fg(\"warning\", \"(deps incomplete)\")}`;\n\t}\n\treturn text;\n}\n\n// ---- tool call rendering ----------------------------------------------------\n// Collapsed todo calls join the `todo` tool group, so each row must survive as a\n// single headline with no result beneath it (ToolGroupComponent drops results and\n// appends one shared expand hint). Args come straight off the wire and can be\n// partial while the call streams, so every field is read defensively.\n\ntype TodoCallArgs = Partial<Record<keyof TodoParams, unknown>>;\n\nconst EDGE_PARAMS = [\"blockedBy\", \"addBlockedBy\", \"removeBlockedBy\", \"addBlocks\", \"removeBlocks\"] as const;\n\nfunction callText(value: unknown): string {\n\treturn typeof value === \"string\" ? value.trim() : \"\";\n}\n\nfunction callSubject(value: unknown): string {\n\treturn callText(value).replace(/\\s+/g, \" \");\n}\n\nfunction callId(value: unknown): number | undefined {\n\treturn typeof value === \"number\" && Number.isInteger(value) ? value : undefined;\n}\n\nfunction callIds(value: unknown): number[] {\n\tif (!Array.isArray(value)) return [];\n\tconst ids: number[] = [];\n\tlet count: number;\n\ttry {\n\t\tcount = Math.min(value.length, TODO_MAX_BLOCKED_BY);\n\t} catch {\n\t\treturn ids;\n\t}\n\tfor (let index = 0; index < count; index++) {\n\t\tlet entry: unknown;\n\t\ttry {\n\t\t\tentry = value[index];\n\t\t} catch {\n\t\t\tcontinue;\n\t\t}\n\t\tif (typeof entry === \"number\" && Number.isSafeInteger(entry) && entry >= 1) ids.push(entry);\n\t}\n\treturn ids;\n}\n\nfunction callArrayLength(value: unknown): number | undefined {\n\ttry {\n\t\treturn Array.isArray(value) ? value.length : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nconst CALL_BATCH_SUBJECT_PREVIEW_COUNT = 2;\nconst CALL_SUBJECT_PREVIEW_WIDTH = 72;\nconst CALL_DESCRIPTION_PREVIEW_LENGTH = 120;\n\ninterface CallBatchItem {\n\tsubject: string;\n\tdescription: string;\n\tblockedBy: number[];\n\tblockedByKeys: string[];\n}\n\nfunction callStrings(value: unknown): string[] {\n\tif (!Array.isArray(value)) return [];\n\tconst strings: string[] = [];\n\tlet count: number;\n\ttry {\n\t\tcount = Math.min(value.length, TODO_MAX_BLOCKED_BY);\n\t} catch {\n\t\treturn strings;\n\t}\n\tfor (let index = 0; index < count; index++) {\n\t\tlet entry: unknown;\n\t\ttry {\n\t\t\tentry = value[index];\n\t\t} catch {\n\t\t\tcontinue;\n\t\t}\n\t\tconst text = callText(entry);\n\t\tif (text) strings.push(text);\n\t}\n\treturn strings;\n}\n\nfunction callBatchItems(value: unknown): CallBatchItem[] {\n\tif (!Array.isArray(value)) return [];\n\tlet count: number;\n\ttry {\n\t\tcount = Math.min(value.length, TODO_MAX_BATCH_ITEMS);\n\t} catch {\n\t\treturn [];\n\t}\n\tconst items: CallBatchItem[] = [];\n\tfor (let index = 0; index < count; index++) {\n\t\tlet valueAtIndex: unknown;\n\t\ttry {\n\t\t\tvalueAtIndex = value[index];\n\t\t} catch {\n\t\t\tvalueAtIndex = undefined;\n\t\t}\n\t\tconst item = safeRecord(valueAtIndex);\n\t\titems.push({\n\t\t\tsubject: item ? callSubject(safeValue(item, \"subject\")) : \"\",\n\t\t\tdescription: item ? callText(safeValue(item, \"description\")) : \"\",\n\t\t\tblockedBy: item ? callIds(safeValue(item, \"blockedBy\")) : [],\n\t\t\tblockedByKeys: item ? callStrings(safeValue(item, \"blockedByKeys\")) : [],\n\t\t});\n\t}\n\treturn items;\n}\n\nfunction formatSubjectPreview(subjects: string[], total: number): string {\n\tconst shown = subjects\n\t\t.slice(0, CALL_BATCH_SUBJECT_PREVIEW_COUNT)\n\t\t.filter(Boolean)\n\t\t.map((subject) => truncateToWidth(subject, CALL_SUBJECT_PREVIEW_WIDTH, \"…\"));\n\tif (!shown.length) return \"\";\n\tconst hidden = Math.max(0, total - shown.length);\n\treturn `${shown.join(\", \")}${hidden ? `, +${hidden} more` : \"\"}`;\n}\n\nfunction callBatchSubjectPreview(items: CallBatchItem[], total: number): string {\n\treturn formatSubjectPreview(\n\t\titems.map((item) => item.subject),\n\t\ttotal,\n\t);\n}\n\nfunction callDescriptionPreview(value: string): string {\n\tconst text = value.replace(/\\s+/g, \" \");\n\treturn text.length > CALL_DESCRIPTION_PREVIEW_LENGTH\n\t\t? `${text.slice(0, CALL_DESCRIPTION_PREVIEW_LENGTH - 1)}…`\n\t\t: text;\n}\n\nfunction callNonNegativeInteger(value: unknown): number | undefined {\n\treturn typeof value === \"number\" && Number.isInteger(value) && value >= 0 ? value : undefined;\n}\n\nfunction isTodoStatus(value: string): value is TodoStatus {\n\treturn Object.hasOwn(STATUS_MARK, value);\n}\n\nfunction formatCallHeadline(args: TodoCallArgs | undefined, theme: Theme): string {\n\tconst action = callText(args?.action);\n\tconst displayAction = action === \"create_many\" ? \"create\" : action;\n\tconst parts = [theme.fg(\"toolTitle\", theme.bold(displayAction ? `todo ${displayAction}` : \"todo\"))];\n\n\tif (action === \"create_many\") {\n\t\tconst items = callBatchItems(args?.items);\n\t\tconst count = callArrayLength(args?.items);\n\t\tif (count !== undefined) {\n\t\t\tparts.push(theme.fg(\"dim\", `${count} ${count === 1 ? \"task\" : \"tasks\"}`));\n\t\t\tconst preview = callBatchSubjectPreview(items, count);\n\t\t\tif (preview) {\n\t\t\t\tparts.push(theme.fg(\"dim\", \"·\"));\n\t\t\t\tparts.push(theme.fg(\"text\", preview));\n\t\t\t}\n\t\t}\n\t}\n\n\tconst id = callId(args?.id);\n\tif (id !== undefined) parts.push(theme.fg(\"accent\", `#${id}`));\n\n\tconst status = callText(args?.status);\n\tif (status && isTodoStatus(status)) parts.push(theme.fg(STATUS_COLOR[status], status));\n\n\tconst subject = callSubject(args?.subject);\n\tif (subject) parts.push(theme.fg(\"text\", subject));\n\n\t// Dependency-only updates would otherwise render as a bare `todo update #3`.\n\tconst hasEdgeChange = EDGE_PARAMS.some((key) => callIds(args?.[key]).length > 0);\n\tif (!status && !subject && hasEdgeChange) parts.push(theme.fg(\"dim\", \"dependencies\"));\n\n\treturn parts.join(\" \");\n}\n\nfunction batchResultIds(result: AgentToolResult<unknown> | undefined, count: number): number[] | undefined {\n\tconst details = groupDetails(result?.details);\n\tif (!details || details.action !== \"create_many\") return undefined;\n\tconst ids = groupIds(safeValue(details.operation, \"ids\"));\n\treturn ids?.length === count ? ids : undefined;\n}\n\nfunction formatCallDetails(args: TodoCallArgs | undefined, theme: Theme, result?: AgentToolResult<unknown>): string[] {\n\tconst lines: string[] = [];\n\tconst push = (label: string, value: string) => {\n\t\tif (value) lines.push(theme.fg(\"dim\", `${label}: ${value}`));\n\t};\n\n\tconst action = callText(args?.action);\n\tif (action === \"create_many\") {\n\t\tconst items = callBatchItems(args?.items);\n\t\tconst ids = batchResultIds(result, items.length);\n\t\tfor (const [index, item] of items.entries()) {\n\t\t\tconst dependencies = [...item.blockedBy.map((id) => `#${id}`), ...item.blockedByKeys];\n\t\t\tlet line = theme.fg(\"accent\", ids ? `#${ids[index]}` : `${index + 1}.`);\n\t\t\tif (item.subject) line += ` ${theme.fg(\"text\", item.subject)}`;\n\t\t\tif (dependencies.length) line += ` ${theme.fg(\"dim\", `· blocked by ${dependencies.join(\", \")}`)}`;\n\t\t\tlines.push(line);\n\t\t\tif (item.description) lines.push(` ${theme.fg(\"dim\", callDescriptionPreview(item.description))}`);\n\t\t}\n\t}\n\n\tpush(\"description\", callText(args?.description));\n\tpush(\"activeForm\", callText(args?.activeForm));\n\tpush(\"owner\", callText(args?.owner));\n\tfor (const key of EDGE_PARAMS) {\n\t\tconst ids = callIds(args?.[key]);\n\t\tif (ids.length) push(key, ids.map((id) => `#${id}`).join(\",\"));\n\t}\n\tif (args?.includeDeleted === true) push(\"includeDeleted\", \"true\");\n\tconst limit = callId(args?.limit);\n\tif (limit !== undefined) push(\"limit\", String(limit));\n\tconst afterId = callId(args?.afterId);\n\tif (afterId !== undefined) push(\"afterId\", String(afterId));\n\tpush(\"query\", callText(args?.query));\n\tif (args?.unblockedOnly === true) push(\"unblockedOnly\", \"true\");\n\tif (args?.confirm === true) push(\"confirm\", \"true\");\n\tconst expectedCount = callNonNegativeInteger(args?.expectedCount);\n\tif (expectedCount !== undefined) push(\"expectedCount\", String(expectedCount));\n\tconst metadata = args?.metadata;\n\tif (metadata && typeof metadata === \"object\") push(\"metadata\", Object.keys(metadata).join(\",\"));\n\treturn lines;\n}\n\n/**\n * One-line call summary when collapsed; the same headline plus the parameters\n * the result never echoes (description, activeForm, dependencies) when expanded.\n */\nexport function formatTodoCall(\n\targs: TodoCallArgs | undefined,\n\ttheme: Theme,\n\texpanded: boolean,\n\tresult?: AgentToolResult<unknown>,\n): string {\n\tconst headline = formatCallHeadline(args, theme);\n\tif (!expanded) return headline;\n\treturn [headline, ...formatCallDetails(args, theme, result)].join(\"\\n\");\n}\n\ninterface TodoGroupRenderContext {\n\tisError: boolean;\n\tisPartial: boolean;\n\tresult?: AgentToolResult<unknown>;\n}\n\ninterface GroupTodoDetails {\n\taction: string;\n\toperation: Record<string, unknown>;\n\titems: unknown;\n}\n\nconst GROUP_FAILURE_MAX_LENGTH = 120;\nconst GROUP_MAX_IDS = 20;\nconst GROUP_MAX_SNAPSHOT_ITEMS = 10_000;\nconst TODO_ACTIONS = new Set([\"create\", \"create_many\", \"update\", \"list\", \"get\", \"delete\", \"clear\"]);\n\nfunction safeRecord(value: unknown): Record<string, unknown> | undefined {\n\ttry {\n\t\treturn value !== null && typeof value === \"object\" && !Array.isArray(value)\n\t\t\t? (value as Record<string, unknown>)\n\t\t\t: undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction safeValue(record: Record<string, unknown>, key: string): unknown {\n\ttry {\n\t\treturn record[key];\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction safeString(value: unknown): string | undefined {\n\treturn typeof value === \"string\" ? value : undefined;\n}\n\nfunction groupDetails(value: unknown): GroupTodoDetails | undefined {\n\tconst details = safeRecord(value);\n\tif (!details || safeValue(details, \"schemaVersion\") !== TODO_DETAILS_SCHEMA_VERSION) return undefined;\n\tconst action = safeString(safeValue(details, \"action\"));\n\tif (!action || !TODO_ACTIONS.has(action)) return undefined;\n\tconst operation = safeRecord(safeValue(details, \"operation\"));\n\tif (!operation || safeValue(operation, \"kind\") !== action) return undefined;\n\treturn { action, operation, items: safeValue(details, \"items\") };\n}\n\nfunction groupPositiveInteger(value: unknown): number | undefined {\n\treturn typeof value === \"number\" && Number.isSafeInteger(value) && value >= 1 ? value : undefined;\n}\n\nfunction groupIds(value: unknown): number[] | undefined {\n\ttry {\n\t\tif (!Array.isArray(value) || value.length === 0 || value.length > GROUP_MAX_IDS) return undefined;\n\t\tconst ids: number[] = [];\n\t\tfor (const valueAtIndex of value) {\n\t\t\tconst id = groupPositiveInteger(valueAtIndex);\n\t\t\tif (id === undefined) return undefined;\n\t\t\tids.push(id);\n\t\t}\n\t\treturn ids;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction groupNonNegativeInteger(value: unknown): number | undefined {\n\treturn typeof value === \"number\" && Number.isSafeInteger(value) && value >= 0 ? value : undefined;\n}\n\nfunction formatGroupStatusCounts(value: unknown, resultCount: unknown): string | undefined {\n\tconst count = groupNonNegativeInteger(resultCount);\n\tif (count === undefined) return undefined;\n\tif (count === 0) return \"no tasks\";\n\n\tconst rawCounts = safeRecord(value);\n\tif (!rawCounts) return undefined;\n\tconst parts: string[] = [];\n\tlet total = 0;\n\tfor (const status of [\"pending\", \"in_progress\", \"completed\", \"deleted\"] as const) {\n\t\tconst statusCount = groupNonNegativeInteger(safeValue(rawCounts, status));\n\t\tif (statusCount === undefined) continue;\n\t\ttotal += statusCount;\n\t\tif (statusCount > 0) parts.push(`${statusCount} ${status}`);\n\t}\n\treturn total === count && parts.length ? parts.join(\", \") : undefined;\n}\n\nfunction groupItem(value: unknown, id: number): Record<string, unknown> | undefined {\n\ttry {\n\t\tif (!Array.isArray(value) || value.length > GROUP_MAX_SNAPSHOT_ITEMS) return undefined;\n\t\tfor (const rawItem of value) {\n\t\t\tconst item = safeRecord(rawItem);\n\t\t\tif (item && safeValue(item, \"id\") === id) return item;\n\t\t}\n\t} catch {\n\t\treturn undefined;\n\t}\n\treturn undefined;\n}\n\nfunction groupItemStatus(value: unknown, id: number): TodoStatus | undefined {\n\tconst item = groupItem(value, id);\n\tif (!item) return undefined;\n\tconst status = safeString(safeValue(item, \"status\"));\n\treturn status && isTodoStatus(status) ? status : undefined;\n}\n\nfunction groupItemSubject(value: unknown, id: number): string | undefined {\n\tconst item = groupItem(value, id);\n\tif (!item) return undefined;\n\tconst subject = callSubject(safeValue(item, \"subject\"));\n\treturn subject || undefined;\n}\n\nfunction formatGroupIds(ids: number[]): string {\n\tconst consecutive = ids.length > 1 && ids.every((id, index) => id === ids[0] + index);\n\treturn consecutive ? `#${ids[0]}–#${ids.at(-1)}` : ids.map((id) => `#${id}`).join(\", \");\n}\n\nfunction formatGroupFailure(result: AgentToolResult<unknown> | undefined): string {\n\ttry {\n\t\tfor (const block of result?.content.slice(0, 8) ?? []) {\n\t\t\tif (block.type !== \"text\" || typeof block.text !== \"string\") continue;\n\t\t\tconst reason = block.text\n\t\t\t\t.replace(/[\\u0000-\\u001f\\u007f-\\u009f]/g, \" \")\n\t\t\t\t.replace(/\\s+/g, \" \")\n\t\t\t\t.trim();\n\t\t\tif (!reason) continue;\n\t\t\treturn reason.length > GROUP_FAILURE_MAX_LENGTH ? `${reason.slice(0, GROUP_FAILURE_MAX_LENGTH - 1)}…` : reason;\n\t\t}\n\t} catch {\n\t\t// Tool results can come from historical or third-party sources.\n\t}\n\treturn \"tool failed\";\n}\n\nfunction formatTodoGroupSuccess(args: TodoCallArgs | undefined, result: AgentToolResult<unknown>): string | undefined {\n\tconst details = groupDetails(result.details);\n\tif (!details) return undefined;\n\n\tswitch (details.action) {\n\t\tcase \"create\": {\n\t\t\tconst ids = groupIds(safeValue(details.operation, \"ids\"));\n\t\t\tif (!ids || ids.length !== 1) return undefined;\n\t\t\tconst subject = groupItemSubject(details.items, ids[0]) ?? callSubject(args?.subject);\n\t\t\tconst preview = subject ? truncateToWidth(subject, CALL_SUBJECT_PREVIEW_WIDTH, \"…\") : \"\";\n\t\t\treturn `todo created #${ids[0]}${preview ? ` ${preview}` : \"\"}`;\n\t\t}\n\t\tcase \"create_many\": {\n\t\t\tconst ids = groupIds(safeValue(details.operation, \"ids\"));\n\t\t\tif (!ids) return undefined;\n\t\t\tconst callItems = callBatchItems(args?.items);\n\t\t\tconst subjects = ids.map(\n\t\t\t\t(id, index) => groupItemSubject(details.items, id) ?? callItems[index]?.subject ?? \"\",\n\t\t\t);\n\t\t\tconst preview = formatSubjectPreview(subjects, ids.length);\n\t\t\treturn `todo created ${formatGroupIds(ids)}${preview ? ` · ${preview}` : \"\"}`;\n\t\t}\n\t\tcase \"update\": {\n\t\t\tconst id = groupPositiveInteger(safeValue(details.operation, \"id\"));\n\t\t\tconst status = safeString(safeValue(details.operation, \"status\"));\n\t\t\treturn id !== undefined && status && isTodoStatus(status) ? `todo updated #${id} ${status}` : undefined;\n\t\t}\n\t\tcase \"list\": {\n\t\t\tconst counts = formatGroupStatusCounts(\n\t\t\t\tsafeValue(details.operation, \"statusCounts\"),\n\t\t\t\tsafeValue(details.operation, \"resultCount\"),\n\t\t\t);\n\t\t\treturn counts === undefined ? undefined : `todo list: ${counts}`;\n\t\t}\n\t\tcase \"get\": {\n\t\t\tconst id = groupPositiveInteger(safeValue(details.operation, \"id\"));\n\t\t\tconst status = id === undefined ? undefined : groupItemStatus(details.items, id);\n\t\t\treturn status ? `todo get #${id} ${status}` : undefined;\n\t\t}\n\t\tcase \"delete\": {\n\t\t\tconst id = groupPositiveInteger(safeValue(details.operation, \"id\"));\n\t\t\tif (id === undefined) return undefined;\n\t\t\tconst subject = groupItemSubject(details.items, id);\n\t\t\tconst preview = subject ? truncateToWidth(subject, CALL_SUBJECT_PREVIEW_WIDTH, \"…\") : \"\";\n\t\t\treturn `todo deleted #${id}${preview ? ` ${preview}` : \"\"}`;\n\t\t}\n\t\tcase \"clear\": {\n\t\t\tconst count = callNonNegativeInteger(safeValue(details.operation, \"count\"));\n\t\t\treturn count === undefined ? undefined : `todo cleared ${count} ${count === 1 ? \"task\" : \"tasks\"}`;\n\t\t}\n\t}\n}\n\n/** Compact result-aware summary used only by collapsed todo tool groups. */\nexport function formatTodoGroupCall(\n\targs: TodoCallArgs | undefined,\n\ttheme: Theme,\n\tcontext: TodoGroupRenderContext,\n): string {\n\tif (context.isError) {\n\t\treturn `${formatTodoCall(args, theme, false)} ${theme.fg(\"error\", `failed: ${formatGroupFailure(context.result)}`)}`;\n\t}\n\tif (!context.isPartial && context.result) {\n\t\tconst summary = formatTodoGroupSuccess(args, context.result);\n\t\tif (summary) return theme.fg(\"toolTitle\", summary);\n\t}\n\treturn formatTodoCall(args, theme, false);\n}\n\nexport function formatCommandList(state: TodoState): string {\n\tconst visible = visibleTodos(state);\n\tif (!visible.length) return \"No todos yet.\";\n\tconst lines: string[] = [];\n\tlet shown = 0;\n\tfor (const status of [\"in_progress\", \"pending\", \"completed\"] as const) {\n\t\tconst group = visible.filter((item) => item.status === status).sort(byIdAsc);\n\t\tif (!group.length || shown >= LIST_DISPLAY_MAX_ITEMS) continue;\n\t\tlines.push(status);\n\t\tfor (const item of group) {\n\t\t\tif (shown >= LIST_DISPLAY_MAX_ITEMS) break;\n\t\t\tconst active = item.status === \"in_progress\" && item.activeForm ? ` (${item.activeForm})` : \"\";\n\t\t\tconst owner = item.owner ? ` @${item.owner}` : \"\";\n\t\t\tconst unresolved = unresolvedDependencyIds(state, item);\n\t\t\tconst deps = unresolved.length ? ` blocked by ${unresolved.map((id) => `#${id}`).join(\",\")}` : \"\";\n\t\t\tlines.push(` ${STATUS_MARK[item.status]} #${item.id} ${item.subject}${active}${owner}${deps}`);\n\t\t\tshown++;\n\t\t}\n\t}\n\tif (visible.length > shown) {\n\t\tlines.push(`… and ${visible.length - shown} more; use todo list with limit and afterId to page.`);\n\t}\n\treturn lines.join(\"\\n\");\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { truncateToWidth } from "@earendil-works/pi-tui";
|
|
2
|
-
import { LIST_DISPLAY_MAX_ITEMS } from "./constants.js";
|
|
2
|
+
import { LIST_DISPLAY_MAX_ITEMS, TODO_MAX_BATCH_ITEMS, TODO_MAX_BLOCKED_BY } from "./constants.js";
|
|
3
3
|
import { TODO_DETAILS_SCHEMA_VERSION, } from "./schema.js";
|
|
4
4
|
import { unresolvedDependencyIds } from "./state.js";
|
|
5
5
|
export const STATUS_MARK = {
|
|
@@ -106,27 +106,119 @@ const EDGE_PARAMS = ["blockedBy", "addBlockedBy", "removeBlockedBy", "addBlocks"
|
|
|
106
106
|
function callText(value) {
|
|
107
107
|
return typeof value === "string" ? value.trim() : "";
|
|
108
108
|
}
|
|
109
|
+
function callSubject(value) {
|
|
110
|
+
return callText(value).replace(/\s+/g, " ");
|
|
111
|
+
}
|
|
109
112
|
function callId(value) {
|
|
110
113
|
return typeof value === "number" && Number.isInteger(value) ? value : undefined;
|
|
111
114
|
}
|
|
112
115
|
function callIds(value) {
|
|
113
|
-
|
|
116
|
+
if (!Array.isArray(value))
|
|
117
|
+
return [];
|
|
118
|
+
const ids = [];
|
|
119
|
+
let count;
|
|
120
|
+
try {
|
|
121
|
+
count = Math.min(value.length, TODO_MAX_BLOCKED_BY);
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return ids;
|
|
125
|
+
}
|
|
126
|
+
for (let index = 0; index < count; index++) {
|
|
127
|
+
let entry;
|
|
128
|
+
try {
|
|
129
|
+
entry = value[index];
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (typeof entry === "number" && Number.isSafeInteger(entry) && entry >= 1)
|
|
135
|
+
ids.push(entry);
|
|
136
|
+
}
|
|
137
|
+
return ids;
|
|
114
138
|
}
|
|
115
139
|
function callArrayLength(value) {
|
|
116
|
-
|
|
140
|
+
try {
|
|
141
|
+
return Array.isArray(value) ? value.length : undefined;
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
117
146
|
}
|
|
118
|
-
|
|
147
|
+
const CALL_BATCH_SUBJECT_PREVIEW_COUNT = 2;
|
|
148
|
+
const CALL_SUBJECT_PREVIEW_WIDTH = 72;
|
|
149
|
+
const CALL_DESCRIPTION_PREVIEW_LENGTH = 120;
|
|
150
|
+
function callStrings(value) {
|
|
119
151
|
if (!Array.isArray(value))
|
|
120
|
-
return
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
152
|
+
return [];
|
|
153
|
+
const strings = [];
|
|
154
|
+
let count;
|
|
155
|
+
try {
|
|
156
|
+
count = Math.min(value.length, TODO_MAX_BLOCKED_BY);
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
return strings;
|
|
160
|
+
}
|
|
161
|
+
for (let index = 0; index < count; index++) {
|
|
162
|
+
let entry;
|
|
163
|
+
try {
|
|
164
|
+
entry = value[index];
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
124
167
|
continue;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
168
|
+
}
|
|
169
|
+
const text = callText(entry);
|
|
170
|
+
if (text)
|
|
171
|
+
strings.push(text);
|
|
172
|
+
}
|
|
173
|
+
return strings;
|
|
174
|
+
}
|
|
175
|
+
function callBatchItems(value) {
|
|
176
|
+
if (!Array.isArray(value))
|
|
177
|
+
return [];
|
|
178
|
+
let count;
|
|
179
|
+
try {
|
|
180
|
+
count = Math.min(value.length, TODO_MAX_BATCH_ITEMS);
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
return [];
|
|
128
184
|
}
|
|
129
|
-
|
|
185
|
+
const items = [];
|
|
186
|
+
for (let index = 0; index < count; index++) {
|
|
187
|
+
let valueAtIndex;
|
|
188
|
+
try {
|
|
189
|
+
valueAtIndex = value[index];
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
valueAtIndex = undefined;
|
|
193
|
+
}
|
|
194
|
+
const item = safeRecord(valueAtIndex);
|
|
195
|
+
items.push({
|
|
196
|
+
subject: item ? callSubject(safeValue(item, "subject")) : "",
|
|
197
|
+
description: item ? callText(safeValue(item, "description")) : "",
|
|
198
|
+
blockedBy: item ? callIds(safeValue(item, "blockedBy")) : [],
|
|
199
|
+
blockedByKeys: item ? callStrings(safeValue(item, "blockedByKeys")) : [],
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
return items;
|
|
203
|
+
}
|
|
204
|
+
function formatSubjectPreview(subjects, total) {
|
|
205
|
+
const shown = subjects
|
|
206
|
+
.slice(0, CALL_BATCH_SUBJECT_PREVIEW_COUNT)
|
|
207
|
+
.filter(Boolean)
|
|
208
|
+
.map((subject) => truncateToWidth(subject, CALL_SUBJECT_PREVIEW_WIDTH, "…"));
|
|
209
|
+
if (!shown.length)
|
|
210
|
+
return "";
|
|
211
|
+
const hidden = Math.max(0, total - shown.length);
|
|
212
|
+
return `${shown.join(", ")}${hidden ? `, +${hidden} more` : ""}`;
|
|
213
|
+
}
|
|
214
|
+
function callBatchSubjectPreview(items, total) {
|
|
215
|
+
return formatSubjectPreview(items.map((item) => item.subject), total);
|
|
216
|
+
}
|
|
217
|
+
function callDescriptionPreview(value) {
|
|
218
|
+
const text = value.replace(/\s+/g, " ");
|
|
219
|
+
return text.length > CALL_DESCRIPTION_PREVIEW_LENGTH
|
|
220
|
+
? `${text.slice(0, CALL_DESCRIPTION_PREVIEW_LENGTH - 1)}…`
|
|
221
|
+
: text;
|
|
130
222
|
}
|
|
131
223
|
function callNonNegativeInteger(value) {
|
|
132
224
|
return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : undefined;
|
|
@@ -136,11 +228,19 @@ function isTodoStatus(value) {
|
|
|
136
228
|
}
|
|
137
229
|
function formatCallHeadline(args, theme) {
|
|
138
230
|
const action = callText(args?.action);
|
|
139
|
-
const
|
|
231
|
+
const displayAction = action === "create_many" ? "create" : action;
|
|
232
|
+
const parts = [theme.fg("toolTitle", theme.bold(displayAction ? `todo ${displayAction}` : "todo"))];
|
|
140
233
|
if (action === "create_many") {
|
|
234
|
+
const items = callBatchItems(args?.items);
|
|
141
235
|
const count = callArrayLength(args?.items);
|
|
142
|
-
if (count !== undefined)
|
|
143
|
-
parts.push(theme.fg("dim", `${count} tasks`));
|
|
236
|
+
if (count !== undefined) {
|
|
237
|
+
parts.push(theme.fg("dim", `${count} ${count === 1 ? "task" : "tasks"}`));
|
|
238
|
+
const preview = callBatchSubjectPreview(items, count);
|
|
239
|
+
if (preview) {
|
|
240
|
+
parts.push(theme.fg("dim", "·"));
|
|
241
|
+
parts.push(theme.fg("text", preview));
|
|
242
|
+
}
|
|
243
|
+
}
|
|
144
244
|
}
|
|
145
245
|
const id = callId(args?.id);
|
|
146
246
|
if (id !== undefined)
|
|
@@ -148,7 +248,7 @@ function formatCallHeadline(args, theme) {
|
|
|
148
248
|
const status = callText(args?.status);
|
|
149
249
|
if (status && isTodoStatus(status))
|
|
150
250
|
parts.push(theme.fg(STATUS_COLOR[status], status));
|
|
151
|
-
const subject =
|
|
251
|
+
const subject = callSubject(args?.subject);
|
|
152
252
|
if (subject)
|
|
153
253
|
parts.push(theme.fg("text", subject));
|
|
154
254
|
// Dependency-only updates would otherwise render as a bare `todo update #3`.
|
|
@@ -157,7 +257,14 @@ function formatCallHeadline(args, theme) {
|
|
|
157
257
|
parts.push(theme.fg("dim", "dependencies"));
|
|
158
258
|
return parts.join(" ");
|
|
159
259
|
}
|
|
160
|
-
function
|
|
260
|
+
function batchResultIds(result, count) {
|
|
261
|
+
const details = groupDetails(result?.details);
|
|
262
|
+
if (!details || details.action !== "create_many")
|
|
263
|
+
return undefined;
|
|
264
|
+
const ids = groupIds(safeValue(details.operation, "ids"));
|
|
265
|
+
return ids?.length === count ? ids : undefined;
|
|
266
|
+
}
|
|
267
|
+
function formatCallDetails(args, theme, result) {
|
|
161
268
|
const lines = [];
|
|
162
269
|
const push = (label, value) => {
|
|
163
270
|
if (value)
|
|
@@ -165,10 +272,18 @@ function formatCallDetails(args, theme) {
|
|
|
165
272
|
};
|
|
166
273
|
const action = callText(args?.action);
|
|
167
274
|
if (action === "create_many") {
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
275
|
+
const items = callBatchItems(args?.items);
|
|
276
|
+
const ids = batchResultIds(result, items.length);
|
|
277
|
+
for (const [index, item] of items.entries()) {
|
|
278
|
+
const dependencies = [...item.blockedBy.map((id) => `#${id}`), ...item.blockedByKeys];
|
|
279
|
+
let line = theme.fg("accent", ids ? `#${ids[index]}` : `${index + 1}.`);
|
|
280
|
+
if (item.subject)
|
|
281
|
+
line += ` ${theme.fg("text", item.subject)}`;
|
|
282
|
+
if (dependencies.length)
|
|
283
|
+
line += ` ${theme.fg("dim", `· blocked by ${dependencies.join(", ")}`)}`;
|
|
284
|
+
lines.push(line);
|
|
285
|
+
if (item.description)
|
|
286
|
+
lines.push(` ${theme.fg("dim", callDescriptionPreview(item.description))}`);
|
|
172
287
|
}
|
|
173
288
|
}
|
|
174
289
|
push("description", callText(args?.description));
|
|
@@ -204,11 +319,11 @@ function formatCallDetails(args, theme) {
|
|
|
204
319
|
* One-line call summary when collapsed; the same headline plus the parameters
|
|
205
320
|
* the result never echoes (description, activeForm, dependencies) when expanded.
|
|
206
321
|
*/
|
|
207
|
-
export function formatTodoCall(args, theme, expanded) {
|
|
322
|
+
export function formatTodoCall(args, theme, expanded, result) {
|
|
208
323
|
const headline = formatCallHeadline(args, theme);
|
|
209
324
|
if (!expanded)
|
|
210
325
|
return headline;
|
|
211
|
-
return [headline, ...formatCallDetails(args, theme)].join("\n");
|
|
326
|
+
return [headline, ...formatCallDetails(args, theme, result)].join("\n");
|
|
212
327
|
}
|
|
213
328
|
const GROUP_FAILURE_MAX_LENGTH = 120;
|
|
214
329
|
const GROUP_MAX_IDS = 20;
|
|
@@ -291,16 +406,14 @@ function formatGroupStatusCounts(value, resultCount) {
|
|
|
291
406
|
}
|
|
292
407
|
return total === count && parts.length ? parts.join(", ") : undefined;
|
|
293
408
|
}
|
|
294
|
-
function
|
|
409
|
+
function groupItem(value, id) {
|
|
295
410
|
try {
|
|
296
411
|
if (!Array.isArray(value) || value.length > GROUP_MAX_SNAPSHOT_ITEMS)
|
|
297
412
|
return undefined;
|
|
298
413
|
for (const rawItem of value) {
|
|
299
414
|
const item = safeRecord(rawItem);
|
|
300
|
-
if (
|
|
301
|
-
|
|
302
|
-
const status = safeString(safeValue(item, "status"));
|
|
303
|
-
return status && isTodoStatus(status) ? status : undefined;
|
|
415
|
+
if (item && safeValue(item, "id") === id)
|
|
416
|
+
return item;
|
|
304
417
|
}
|
|
305
418
|
}
|
|
306
419
|
catch {
|
|
@@ -308,6 +421,24 @@ function groupItemStatus(value, id) {
|
|
|
308
421
|
}
|
|
309
422
|
return undefined;
|
|
310
423
|
}
|
|
424
|
+
function groupItemStatus(value, id) {
|
|
425
|
+
const item = groupItem(value, id);
|
|
426
|
+
if (!item)
|
|
427
|
+
return undefined;
|
|
428
|
+
const status = safeString(safeValue(item, "status"));
|
|
429
|
+
return status && isTodoStatus(status) ? status : undefined;
|
|
430
|
+
}
|
|
431
|
+
function groupItemSubject(value, id) {
|
|
432
|
+
const item = groupItem(value, id);
|
|
433
|
+
if (!item)
|
|
434
|
+
return undefined;
|
|
435
|
+
const subject = callSubject(safeValue(item, "subject"));
|
|
436
|
+
return subject || undefined;
|
|
437
|
+
}
|
|
438
|
+
function formatGroupIds(ids) {
|
|
439
|
+
const consecutive = ids.length > 1 && ids.every((id, index) => id === ids[0] + index);
|
|
440
|
+
return consecutive ? `#${ids[0]}–#${ids.at(-1)}` : ids.map((id) => `#${id}`).join(", ");
|
|
441
|
+
}
|
|
311
442
|
function formatGroupFailure(result) {
|
|
312
443
|
try {
|
|
313
444
|
for (const block of result?.content.slice(0, 8) ?? []) {
|
|
@@ -327,17 +458,27 @@ function formatGroupFailure(result) {
|
|
|
327
458
|
}
|
|
328
459
|
return "tool failed";
|
|
329
460
|
}
|
|
330
|
-
function formatTodoGroupSuccess(result) {
|
|
461
|
+
function formatTodoGroupSuccess(args, result) {
|
|
331
462
|
const details = groupDetails(result.details);
|
|
332
463
|
if (!details)
|
|
333
464
|
return undefined;
|
|
334
465
|
switch (details.action) {
|
|
335
|
-
case "create":
|
|
466
|
+
case "create": {
|
|
467
|
+
const ids = groupIds(safeValue(details.operation, "ids"));
|
|
468
|
+
if (!ids || ids.length !== 1)
|
|
469
|
+
return undefined;
|
|
470
|
+
const subject = groupItemSubject(details.items, ids[0]) ?? callSubject(args?.subject);
|
|
471
|
+
const preview = subject ? truncateToWidth(subject, CALL_SUBJECT_PREVIEW_WIDTH, "…") : "";
|
|
472
|
+
return `todo created #${ids[0]}${preview ? ` ${preview}` : ""}`;
|
|
473
|
+
}
|
|
336
474
|
case "create_many": {
|
|
337
475
|
const ids = groupIds(safeValue(details.operation, "ids"));
|
|
338
|
-
if (!ids
|
|
476
|
+
if (!ids)
|
|
339
477
|
return undefined;
|
|
340
|
-
|
|
478
|
+
const callItems = callBatchItems(args?.items);
|
|
479
|
+
const subjects = ids.map((id, index) => groupItemSubject(details.items, id) ?? callItems[index]?.subject ?? "");
|
|
480
|
+
const preview = formatSubjectPreview(subjects, ids.length);
|
|
481
|
+
return `todo created ${formatGroupIds(ids)}${preview ? ` · ${preview}` : ""}`;
|
|
341
482
|
}
|
|
342
483
|
case "update": {
|
|
343
484
|
const id = groupPositiveInteger(safeValue(details.operation, "id"));
|
|
@@ -355,7 +496,11 @@ function formatTodoGroupSuccess(result) {
|
|
|
355
496
|
}
|
|
356
497
|
case "delete": {
|
|
357
498
|
const id = groupPositiveInteger(safeValue(details.operation, "id"));
|
|
358
|
-
|
|
499
|
+
if (id === undefined)
|
|
500
|
+
return undefined;
|
|
501
|
+
const subject = groupItemSubject(details.items, id);
|
|
502
|
+
const preview = subject ? truncateToWidth(subject, CALL_SUBJECT_PREVIEW_WIDTH, "…") : "";
|
|
503
|
+
return `todo deleted #${id}${preview ? ` ${preview}` : ""}`;
|
|
359
504
|
}
|
|
360
505
|
case "clear": {
|
|
361
506
|
const count = callNonNegativeInteger(safeValue(details.operation, "count"));
|
|
@@ -369,7 +514,7 @@ export function formatTodoGroupCall(args, theme, context) {
|
|
|
369
514
|
return `${formatTodoCall(args, theme, false)} ${theme.fg("error", `failed: ${formatGroupFailure(context.result)}`)}`;
|
|
370
515
|
}
|
|
371
516
|
if (!context.isPartial && context.result) {
|
|
372
|
-
const summary = formatTodoGroupSuccess(context.result);
|
|
517
|
+
const summary = formatTodoGroupSuccess(args, context.result);
|
|
373
518
|
if (summary)
|
|
374
519
|
return theme.fg("toolTitle", summary);
|
|
375
520
|
}
|