@ai-agent-forge/plugin-todo-set 0.88.16 → 0.88.17

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/agent-forge.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "packageFormatVersion": 1,
3
3
  "id": "agent-forge.plugin.todo-set",
4
- "pluginVersion": "0.88.16",
4
+ "pluginVersion": "0.88.17",
5
5
  "apiVersion": "1",
6
6
  "minHostVersion": "0.84.4",
7
7
  "platform": {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAGrF,MAAM,WAAW,UAAU;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,2FAA2F;IAC3F,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,MAAM,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,WAAW,CAAC;IACrD,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,SAAS;IACzB,KAAK,EAAE,UAAU,EAAE,CAAC;CACpB;AA+DD;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,MAAM,CAwB1F;AAyMD,wBAAgB,gBAAgB,CAC/B,GAAG,EAAE,aAAa,GAChB,OAAO,CAAC,SAAS,sBAAsB,EAAE,CAAC,GAAG,SAAS,sBAAsB,EAAE,CAsEhF","sourcesContent":["/**\n * Todo-set capability plugin: a self-contained todo state machine, extracted\n * from the host's `src/capabilities/todo-set.ts` (D-075 S4, first B-class\n * batch).\n *\n * Todos persist as append-only `todo.state` session entries and every change\n * is announced as a `todo.changed` event. `planId` is a soft reference: a\n * plain string whose target is checked ADVISORILY against the plan plugin's\n * LATEST `plan.state` snapshot (the same latest-snapshot semantics as this\n * plugin's own {@link loadState}); an unknown id yields a response warning,\n * never a failure (the same #10 pattern as the plan plugin's goalId check).\n * The plugin only consumes the public `session`, `events`, and `tools`\n * capabilities and never writes state owned by another plugin.\n */\n\nimport type { CapabilityAPI, DisposableRegistration } from \"@agent-forge/plugin-sdk\";\nimport { Type } from \"typebox\";\n\nexport interface TodoRecord {\n\tid: string;\n\t/** Soft reference: a plain string; unknown ids yield a response warning, not a failure. */\n\tplanId: string;\n\ttitle: string;\n\t/**\n\t * Lifecycle status. `cancelled` is terminal (voided: permanently retired,\n\t * no longer part of execution) and shares done's no-further-update guard.\n\t */\n\tstatus: \"pending\" | \"done\" | \"blocked\" | \"cancelled\";\n\trevision: number;\n\tevidence: string[];\n}\n\nexport interface TodoState {\n\ttodos: TodoRecord[];\n}\n\nconst stateEntry = \"todo.state\";\n/** Session protocol key of the plan plugin's snapshot entry (plugins/plan). */\nconst planStateEntry = \"plan.state\";\n\nconst todoSchema = Type.Object({\n\tid: Type.String({ description: \"Stable id of the todo to create or update\" }),\n\tplanId: Type.String({\n\t\tdescription:\n\t\t\t\"Soft reference to a plan id; an id unknown to this session's plan state yields a response warning, not a failure\",\n\t}),\n\ttitle: Type.String({ description: \"Human-readable todo title\" }),\n\trevision: Type.Integer({\n\t\tdescription: \"New revision counter; must be greater than the stored revision of an existing todo\",\n\t\tminimum: 0,\n\t}),\n\tstatus: Type.Optional(\n\t\tType.Union([Type.Literal(\"pending\"), Type.Literal(\"done\"), Type.Literal(\"blocked\"), Type.Literal(\"cancelled\")], {\n\t\t\tdescription:\n\t\t\t\t\"Next status; defaults to the stored status for existing todos, otherwise pending. done and cancelled are terminal: once a todo holds either status it can never be updated again, so finish every evidence reference before marking it done, and never mark done to avoid reporting unfinished work. Use blocked only for temporarily stuck work that may resume; use cancelled when the user retires or skips the todo\",\n\t\t}),\n\t),\n\tevidence: Type.Optional(\n\t\tType.Array(Type.String(), {\n\t\t\tdescription:\n\t\t\t\t\"Final evidence references; at least one is required when status is done or cancelled (for cancelled, cite the user's words that retired the todo). The list is fixed at that moment — a terminal todo cannot be updated to add later evidence such as a commit id\",\n\t\t}),\n\t),\n});\n\nfunction objectInput(first: unknown, second: unknown): Record<string, unknown> {\n\tconst value = first !== null && typeof first === \"object\" && !Array.isArray(first) ? first : second;\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) throw new Error(\"Todo input must be an object\");\n\treturn value as Record<string, unknown>;\n}\n\nfunction text(value: unknown, name: string): string {\n\tif (typeof value !== \"string\" || value.trim() === \"\") throw new Error(`${name} must be a non-empty string`);\n\treturn value;\n}\n\nfunction revision(value: unknown): number {\n\tif (!Number.isInteger(value) || (value as number) < 0) throw new Error(\"revision must be a non-negative integer\");\n\treturn value as number;\n}\n\nfunction evidence(value: unknown): string[] {\n\tif (value === undefined) return [];\n\tif (!Array.isArray(value) || value.some((item) => typeof item !== \"string\" || item.trim() === \"\")) {\n\t\tthrow new Error(\"evidence must be a string array\");\n\t}\n\treturn [...(value as string[])];\n}\n\nfunction loadState(api: CapabilityAPI): TodoState {\n\tconst entries = api.session?.getBranchEntries() ?? [];\n\tconst entry = [...entries].reverse().find((item) => item.customType === stateEntry);\n\tif (!entry?.data || typeof entry.data !== \"object\") return { todos: [] };\n\tconst data = entry.data as Partial<TodoState>;\n\treturn { todos: Array.isArray(data.todos) ? [...data.todos] : [] };\n}\n\n/**\n * `/todo` command text rendering: one line per todo (`id [status → planId]\n * title`) plus the evidence lines that justified completion. The leading count\n * line lists its non-zero segments in done → blocked → cancelled order. Plain\n * text only —\n * every host shape can render it, no TUI required (the same L1 contract as\n * the workflow plugin's `/workflow`). Collapsed tool blocks pass\n * `{ evidence: false }` to omit the evidence lines; the default keeps the\n * command output byte-for-byte stable.\n */\nexport function renderTodoState(state: TodoState, options?: { evidence?: boolean }): string {\n\tconst withEvidence = options?.evidence ?? true;\n\tif (state.todos.length === 0) return \"no todos in this session; create one with todo_update\";\n\tconst done = state.todos.filter((todo) => todo.status === \"done\").length;\n\tconst blocked = state.todos.filter((todo) => todo.status === \"blocked\").length;\n\tconst cancelled = state.todos.filter((todo) => todo.status === \"cancelled\").length;\n\t// Count segments in the fixed done → blocked → cancelled order; zero\n\t// segments are omitted (the rule blocked always had), so a total with no\n\t// countable status renders bare instead of with empty parentheses.\n\tconst segments: string[] = [];\n\tif (done > 0) segments.push(`${done} done`);\n\tif (blocked > 0) segments.push(`${blocked} blocked`);\n\tif (cancelled > 0) segments.push(`${cancelled} cancelled`);\n\tconst lines = [\n\t\tsegments.length > 0 ? `todos: ${state.todos.length} (${segments.join(\", \")})` : `todos: ${state.todos.length}`,\n\t];\n\t// Record fields only validate non-emptiness, so fold newlines to keep the\n\t// one-line-per-record shape whatever the model wrote.\n\tconst inline = (value: string): string => value.replace(/\\n/g, \" \");\n\tfor (const todo of state.todos) {\n\t\tlines.push(`- ${inline(todo.id)} [${todo.status} → ${inline(todo.planId)}] ${inline(todo.title)}`);\n\t\tif (withEvidence) for (const item of todo.evidence) lines.push(` evidence: ${inline(item)}`);\n\t}\n\treturn lines.join(\"\\n\");\n}\n\n/**\n * Structural slices of the host tool-render contracts the renderer needs.\n * Declared locally on purpose: this plugin must stay self-contained and must\n * not import `@agent-forge/tui` (the tool-definition.ts structural hosting\n * boundary), so renderResult talks to these shapes instead of the real\n * Theme/Component types.\n */\ninterface ToolResultTextPartLike {\n\treadonly type: string;\n\treadonly text?: string;\n}\n\ninterface ToolResultLike {\n\treadonly content: readonly ToolResultTextPartLike[];\n}\n\ninterface RenderResultOptionsLike {\n\treadonly expanded: boolean;\n\treadonly isPartial: boolean;\n}\n\ninterface ThemeLike {\n\tfg(color: string, text: string): string;\n}\n\ninterface RenderContextLike {\n\treadonly lastComponent?: unknown;\n}\n\n/**\n * Simplified East Asian width table: these ranges cover the CJK blocks state\n * titles realistically use and count as 2 columns each; every other code\n * point counts as 1. Not a full wcwidth — combining marks and ambiguous\n * widths fall back to 1, the safe (narrower) default for row folding.\n */\nfunction isWideCodePoint(code: number): boolean {\n\treturn (\n\t\t(code >= 0x1100 && code <= 0x115f) ||\n\t\t(code >= 0x2e80 && code <= 0xa4cf) ||\n\t\t(code >= 0xac00 && code <= 0xd7a3) ||\n\t\t(code >= 0xf900 && code <= 0xfaff) ||\n\t\t(code >= 0xfe30 && code <= 0xfe4f) ||\n\t\t(code >= 0xff00 && code <= 0xff60) ||\n\t\t(code >= 0xffe0 && code <= 0xffe6) ||\n\t\t(code >= 0x20000 && code <= 0x3fffd)\n\t);\n}\n\n/** Folds one logical line into rows of at most `width` display columns. */\nfunction wrapLine(line: string, width: number): string[] {\n\tif (width <= 0) return [line];\n\tconst rows: string[] = [];\n\tlet row = \"\";\n\tlet columns = 0;\n\tfor (const character of line) {\n\t\tconst cost = isWideCodePoint(character.codePointAt(0) ?? 0) ? 2 : 1;\n\t\tif (row !== \"\" && columns + cost > width) {\n\t\t\trows.push(row);\n\t\t\trow = character;\n\t\t\tcolumns = cost;\n\t\t} else {\n\t\t\trow += character;\n\t\t\tcolumns += cost;\n\t\t}\n\t}\n\trows.push(row);\n\treturn rows;\n}\n\n/**\n * Structural TUI component rendering a todo_update result as the plain state\n * listing: `warning: ` lines take the host theme's warning color, every other\n * row toolOutput (color is decided per logical line, so a wrapped warning\n * stays warning-colored). Rows are cached per width — the host may render the\n * same result repeatedly at one width — and dropped on text updates or\n * invalidate.\n */\nclass TodoResultComponent {\n\tprivate text: string;\n\tprivate readonly theme: ThemeLike;\n\tprivate readonly rowsByWidth = new Map<number, string[]>();\n\n\tconstructor(text: string, theme: ThemeLike) {\n\t\tthis.text = text;\n\t\tthis.theme = theme;\n\t}\n\n\tsetText(text: string): void {\n\t\tif (text === this.text) return;\n\t\tthis.text = text;\n\t\tthis.rowsByWidth.clear();\n\t}\n\n\trender(width: number): string[] {\n\t\tconst cached = this.rowsByWidth.get(width);\n\t\tif (cached) return cached;\n\t\tconst rows: string[] = [];\n\t\tfor (const line of this.text.split(\"\\n\")) {\n\t\t\tconst color = line.startsWith(\"warning: \") ? \"warning\" : \"toolOutput\";\n\t\t\tfor (const row of wrapLine(line, width)) rows.push(this.theme.fg(color, row));\n\t\t}\n\t\tthis.rowsByWidth.set(width, rows);\n\t\treturn rows;\n\t}\n\n\tinvalidate(): void {\n\t\tthis.rowsByWidth.clear();\n\t}\n}\n\n/**\n * Parses the text part the host serialized from this plugin's execute return\n * (capability-runtime-guards normalization): a `TodoState`, optionally with a\n * response-only `warning`. Anything else — a JSON.parse failure or a\n * different shape — returns undefined so the renderer falls back to the raw\n * text.\n */\nfunction parseTodoResultText(text: string): { state: TodoState; warning?: string } | undefined {\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(text);\n\t} catch {\n\t\treturn undefined;\n\t}\n\tif (parsed === null || typeof parsed !== \"object\" || Array.isArray(parsed)) return undefined;\n\tconst record = parsed as { todos?: unknown; warning?: unknown };\n\tif (!Array.isArray(record.todos)) return undefined;\n\tif (record.warning !== undefined && typeof record.warning !== \"string\") return undefined;\n\tconst state: TodoState = { todos: record.todos as TodoRecord[] };\n\treturn record.warning === undefined ? { state } : { state, warning: record.warning };\n}\n\n/**\n * renderResult for todo_update: re-renders the tool's own state payload as\n * the readable listing instead of the host's generic one-line JSON fallback.\n * Collapsed blocks show the summary and record lines only; expanded blocks\n * add the evidence lines; a response `warning` rides along as a final\n * warning-colored line. Non-state payloads and malformed records render\n * verbatim as toolOutput.\n */\nfunction renderTodoResult(\n\tresult: ToolResultLike,\n\toptions: RenderResultOptionsLike,\n\ttheme: ThemeLike,\n\tcontext: RenderContextLike,\n): TodoResultComponent | undefined {\n\tconst text = result.content.find((part) => part.type === \"text\")?.text;\n\tif (text === undefined || text === \"\") return undefined;\n\tconst parsed = parseTodoResultText(text);\n\tlet listing: string;\n\tif (parsed) {\n\t\t// The parse gate is envelope-level, so a parsed state may still hold\n\t\t// malformed records (null elements, a record missing evidence).\n\t\t// Rendering those must not throw out of the plugin: fall back to the\n\t\t// raw text, the same path as a parse failure.\n\t\ttry {\n\t\t\tlisting = renderTodoState(parsed.state, { evidence: options.expanded });\n\t\t\tif (parsed.warning !== undefined) {\n\t\t\t\t// Fold newlines like the record fields so the warning stays one line.\n\t\t\t\tlisting = `${listing}\\nwarning: ${parsed.warning.replace(/\\n/g, \" \")}`;\n\t\t\t}\n\t\t} catch {\n\t\t\tlisting = text;\n\t\t}\n\t} else {\n\t\tlisting = text;\n\t}\n\t// Reuse the host-provided component for this render slot (the ls.ts\n\t// precedent): same instance in, same instance out, with fresh text.\n\tif (context.lastComponent instanceof TodoResultComponent) {\n\t\tcontext.lastComponent.setText(listing);\n\t\treturn context.lastComponent;\n\t}\n\treturn new TodoResultComponent(listing, theme);\n}\n\n/**\n * Whether the session branch's LATEST `plan.state` snapshot knows a plan with\n * the given id (the same latest-snapshot semantics as {@link loadState} and\n * the same advisory pattern as the plan plugin's goalKnownToSession). The\n * check is advisory only (#10): a missing plan downgrades to a warning in the\n * tool response — the soft-reference write path never fails on it.\n */\nfunction planKnownToSession(api: CapabilityAPI, planId: string): boolean {\n\tconst entries = api.session?.getBranchEntries() ?? [];\n\tfor (let index = entries.length - 1; index >= 0; index -= 1) {\n\t\tconst entry = entries[index];\n\t\tif (entry.customType !== planStateEntry) continue;\n\t\tconst data = entry.data;\n\t\tif (!data || typeof data !== \"object\" || Array.isArray(data)) return false;\n\t\tconst plans = (data as { plans?: unknown }).plans;\n\t\tif (!Array.isArray(plans)) return false;\n\t\treturn plans.some(\n\t\t\t(plan) => plan !== null && typeof plan === \"object\" && (plan as { id?: unknown }).id === planId,\n\t\t);\n\t}\n\treturn false;\n}\n\nexport function createCapability(\n\tapi: CapabilityAPI,\n): Promise<readonly DisposableRegistration[]> | readonly DisposableRegistration[] {\n\tlet state = loadState(api);\n\tconst refreshState = (): TodoState => {\n\t\tif (api.session) state = loadState(api);\n\t\treturn state;\n\t};\n\n\tconst persist = async (): Promise<TodoState> => {\n\t\tapi.session?.appendEntry(stateEntry, state);\n\t\tawait api.publish({ type: \"todo.changed\", version: 1, correlationId: stateEntry, data: state });\n\t\treturn state;\n\t};\n\n\tconst tool = api.registerTool({\n\t\tname: \"todo_update\",\n\t\tlabel: \"Update todo\",\n\t\tdescription:\n\t\t\t\"Update a todo that softly references a plan by id. Create with status pending at revision 1, update unfinished items with a higher revision; marking done or cancelled is final and requires evidence, so commit the work first and then complete the todo\",\n\t\tparameters: todoSchema,\n\t\trenderResult: renderTodoResult,\n\t\texecute: async (first: unknown, second?: unknown) => {\n\t\t\trefreshState();\n\t\t\tconst input = objectInput(first, second);\n\t\t\tconst id = text(input.id, \"id\");\n\t\t\tconst planId = text(input.planId, \"planId\");\n\t\t\tconst title = text(input.title, \"title\");\n\t\t\tconst nextRevision = revision(input.revision);\n\t\t\tconst current = state.todos.find((item) => item.id === id);\n\t\t\tif (current && nextRevision <= current.revision) throw new Error(`stale todo revision: ${id}`);\n\t\t\tif (current?.status === \"done\" || current?.status === \"cancelled\") {\n\t\t\t\tthrow new Error(`todo is terminal and cannot be updated: ${id}`);\n\t\t\t}\n\t\t\tconst status =\n\t\t\t\tinput.status === undefined\n\t\t\t\t\t? (current?.status ?? \"pending\")\n\t\t\t\t\t: (text(input.status, \"status\") as TodoRecord[\"status\"]);\n\t\t\tif (![\"pending\", \"done\", \"blocked\", \"cancelled\"].includes(status)) throw new Error(\"invalid todo status\");\n\t\t\tconst values = evidence(input.evidence);\n\t\t\tif (status === \"done\" && values.length === 0) {\n\t\t\t\tthrow new Error(\"todo completion requires at least one evidence reference\");\n\t\t\t}\n\t\t\tif (status === \"cancelled\" && values.length === 0) {\n\t\t\t\tthrow new Error(\"todo cancellation requires at least one evidence reference\");\n\t\t\t}\n\t\t\tconst record: TodoRecord = { id, planId, title, status, revision: nextRevision, evidence: values };\n\t\t\tstate = { ...state, todos: [...state.todos.filter((item) => item.id !== id), record] };\n\t\t\tconst saved = await persist();\n\t\t\tif (planKnownToSession(api, planId)) return saved;\n\t\t\treturn {\n\t\t\t\t...saved,\n\t\t\t\twarning: `planId \"${planId}\" does not match any plan in this session's plan state; the todo keeps the soft reference, but the plan is unknown`,\n\t\t\t};\n\t\t},\n\t});\n\n\tconst command = api.registerCommand({\n\t\tname: \"todo\",\n\t\tdescription: \"Show this session's todos (status and plan reference)\",\n\t\texecute: async (args: string) => {\n\t\t\ttry {\n\t\t\t\tif (args.trim() !== \"\") return { status: \"error\" as const, message: \"Usage: /todo\" };\n\t\t\t\treturn { status: \"success\" as const, message: renderTodoState(refreshState()) };\n\t\t\t} catch (error) {\n\t\t\t\t// A slash command must not crash the host (memory /promote precedent).\n\t\t\t\treturn { status: \"error\" as const, message: error instanceof Error ? error.message : String(error) };\n\t\t\t}\n\t\t},\n\t});\n\n\treturn [tool, command];\n}\n"]}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAGrF,MAAM,WAAW,UAAU;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,2FAA2F;IAC3F,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,MAAM,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,WAAW,CAAC;IACrD,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,SAAS;IACzB,KAAK,EAAE,UAAU,EAAE,CAAC;CACpB;AA+DD;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,MAAM,CAwB1F;AAyMD,wBAAgB,gBAAgB,CAC/B,GAAG,EAAE,aAAa,GAChB,OAAO,CAAC,SAAS,sBAAsB,EAAE,CAAC,GAAG,SAAS,sBAAsB,EAAE,CAsEhF","sourcesContent":["/**\n * Todo-set capability plugin: a self-contained todo state machine, extracted\n * from the host's `src/capabilities/todo-set.ts` (D-075 S4, first B-class\n * batch).\n *\n * Todos persist as append-only `todo.state` session entries and every change\n * is announced as a `todo.changed` event. `planId` is a soft reference: a\n * plain string whose target is checked ADVISORILY against the plan plugin's\n * LATEST `plan.state` snapshot (the same latest-snapshot semantics as this\n * plugin's own {@link loadState}); an unknown id yields a response warning,\n * never a failure (the same #10 pattern as the plan plugin's goalId check).\n * The plugin only consumes the public `session`, `events`, and `tools`\n * capabilities and never writes state owned by another plugin.\n */\n\nimport type { CapabilityAPI, DisposableRegistration } from \"@agent-forge/plugin-sdk\";\nimport { Type } from \"typebox\";\n\nexport interface TodoRecord {\n\tid: string;\n\t/** Soft reference: a plain string; unknown ids yield a response warning, not a failure. */\n\tplanId: string;\n\ttitle: string;\n\t/**\n\t * Lifecycle status. `cancelled` is terminal (voided: permanently retired,\n\t * no longer part of execution) and shares done's no-further-update guard.\n\t */\n\tstatus: \"pending\" | \"done\" | \"blocked\" | \"cancelled\";\n\trevision: number;\n\tevidence: string[];\n}\n\nexport interface TodoState {\n\ttodos: TodoRecord[];\n}\n\nconst stateEntry = \"todo.state\";\n/** Session protocol key of the plan plugin's snapshot entry (plugins/plan). */\nconst planStateEntry = \"plan.state\";\n\nconst todoSchema = Type.Object({\n\tid: Type.String({ description: \"Stable id of the todo to create or update\" }),\n\tplanId: Type.String({\n\t\tdescription:\n\t\t\t\"Plan id this todo belongs to (required, non-empty). An unknown id only adds a response warning; the todo still persists\",\n\t}),\n\ttitle: Type.String({ description: \"Human-readable todo title\" }),\n\trevision: Type.Integer({\n\t\tdescription: \"New revision counter; must be greater than the stored revision of an existing todo\",\n\t\tminimum: 0,\n\t}),\n\tstatus: Type.Optional(\n\t\tType.Union([Type.Literal(\"pending\"), Type.Literal(\"done\"), Type.Literal(\"blocked\"), Type.Literal(\"cancelled\")], {\n\t\t\tdescription:\n\t\t\t\t\"Next status; defaults to the stored status for existing todos, otherwise pending. done and cancelled are terminal: once a todo holds either status it can never be updated again, so finish every evidence reference before marking it done, and never mark done to avoid reporting unfinished work. Use blocked only for temporarily stuck work that may resume; use cancelled when the user retires or skips the todo\",\n\t\t}),\n\t),\n\tevidence: Type.Optional(\n\t\tType.Array(Type.String(), {\n\t\t\tdescription:\n\t\t\t\t\"Final evidence references. This list REPLACES the stored list on every call — re-send existing references when updating. At least one is required when status is done or cancelled (for cancelled, cite the user's words that retired the todo). The list is fixed at that moment — a terminal todo cannot be updated to add later evidence such as a commit id\",\n\t\t}),\n\t),\n});\n\nfunction objectInput(first: unknown, second: unknown): Record<string, unknown> {\n\tconst value = first !== null && typeof first === \"object\" && !Array.isArray(first) ? first : second;\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) throw new Error(\"Todo input must be an object\");\n\treturn value as Record<string, unknown>;\n}\n\nfunction text(value: unknown, name: string): string {\n\tif (typeof value !== \"string\" || value.trim() === \"\") throw new Error(`${name} must be a non-empty string`);\n\treturn value;\n}\n\nfunction revision(value: unknown): number {\n\tif (!Number.isInteger(value) || (value as number) < 0) throw new Error(\"revision must be a non-negative integer\");\n\treturn value as number;\n}\n\nfunction evidence(value: unknown): string[] {\n\tif (value === undefined) return [];\n\tif (!Array.isArray(value) || value.some((item) => typeof item !== \"string\" || item.trim() === \"\")) {\n\t\tthrow new Error(\"evidence must be a string array\");\n\t}\n\treturn [...(value as string[])];\n}\n\nfunction loadState(api: CapabilityAPI): TodoState {\n\tconst entries = api.session?.getBranchEntries() ?? [];\n\tconst entry = [...entries].reverse().find((item) => item.customType === stateEntry);\n\tif (!entry?.data || typeof entry.data !== \"object\") return { todos: [] };\n\tconst data = entry.data as Partial<TodoState>;\n\treturn { todos: Array.isArray(data.todos) ? [...data.todos] : [] };\n}\n\n/**\n * `/todo` command text rendering: one line per todo (`id [status → planId]\n * title`) plus the evidence lines that justified completion. The leading count\n * line lists its non-zero segments in done → blocked → cancelled order. Plain\n * text only —\n * every host shape can render it, no TUI required (the same L1 contract as\n * the workflow plugin's `/workflow`). Collapsed tool blocks pass\n * `{ evidence: false }` to omit the evidence lines; the default keeps the\n * command output byte-for-byte stable.\n */\nexport function renderTodoState(state: TodoState, options?: { evidence?: boolean }): string {\n\tconst withEvidence = options?.evidence ?? true;\n\tif (state.todos.length === 0) return \"no todos in this session; create one with todo_update\";\n\tconst done = state.todos.filter((todo) => todo.status === \"done\").length;\n\tconst blocked = state.todos.filter((todo) => todo.status === \"blocked\").length;\n\tconst cancelled = state.todos.filter((todo) => todo.status === \"cancelled\").length;\n\t// Count segments in the fixed done → blocked → cancelled order; zero\n\t// segments are omitted (the rule blocked always had), so a total with no\n\t// countable status renders bare instead of with empty parentheses.\n\tconst segments: string[] = [];\n\tif (done > 0) segments.push(`${done} done`);\n\tif (blocked > 0) segments.push(`${blocked} blocked`);\n\tif (cancelled > 0) segments.push(`${cancelled} cancelled`);\n\tconst lines = [\n\t\tsegments.length > 0 ? `todos: ${state.todos.length} (${segments.join(\", \")})` : `todos: ${state.todos.length}`,\n\t];\n\t// Record fields only validate non-emptiness, so fold newlines to keep the\n\t// one-line-per-record shape whatever the model wrote.\n\tconst inline = (value: string): string => value.replace(/\\n/g, \" \");\n\tfor (const todo of state.todos) {\n\t\tlines.push(`- ${inline(todo.id)} [${todo.status} → ${inline(todo.planId)}] ${inline(todo.title)}`);\n\t\tif (withEvidence) for (const item of todo.evidence) lines.push(` evidence: ${inline(item)}`);\n\t}\n\treturn lines.join(\"\\n\");\n}\n\n/**\n * Structural slices of the host tool-render contracts the renderer needs.\n * Declared locally on purpose: this plugin must stay self-contained and must\n * not import `@agent-forge/tui` (the tool-definition.ts structural hosting\n * boundary), so renderResult talks to these shapes instead of the real\n * Theme/Component types.\n */\ninterface ToolResultTextPartLike {\n\treadonly type: string;\n\treadonly text?: string;\n}\n\ninterface ToolResultLike {\n\treadonly content: readonly ToolResultTextPartLike[];\n}\n\ninterface RenderResultOptionsLike {\n\treadonly expanded: boolean;\n\treadonly isPartial: boolean;\n}\n\ninterface ThemeLike {\n\tfg(color: string, text: string): string;\n}\n\ninterface RenderContextLike {\n\treadonly lastComponent?: unknown;\n}\n\n/**\n * Simplified East Asian width table: these ranges cover the CJK blocks state\n * titles realistically use and count as 2 columns each; every other code\n * point counts as 1. Not a full wcwidth — combining marks and ambiguous\n * widths fall back to 1, the safe (narrower) default for row folding.\n */\nfunction isWideCodePoint(code: number): boolean {\n\treturn (\n\t\t(code >= 0x1100 && code <= 0x115f) ||\n\t\t(code >= 0x2e80 && code <= 0xa4cf) ||\n\t\t(code >= 0xac00 && code <= 0xd7a3) ||\n\t\t(code >= 0xf900 && code <= 0xfaff) ||\n\t\t(code >= 0xfe30 && code <= 0xfe4f) ||\n\t\t(code >= 0xff00 && code <= 0xff60) ||\n\t\t(code >= 0xffe0 && code <= 0xffe6) ||\n\t\t(code >= 0x20000 && code <= 0x3fffd)\n\t);\n}\n\n/** Folds one logical line into rows of at most `width` display columns. */\nfunction wrapLine(line: string, width: number): string[] {\n\tif (width <= 0) return [line];\n\tconst rows: string[] = [];\n\tlet row = \"\";\n\tlet columns = 0;\n\tfor (const character of line) {\n\t\tconst cost = isWideCodePoint(character.codePointAt(0) ?? 0) ? 2 : 1;\n\t\tif (row !== \"\" && columns + cost > width) {\n\t\t\trows.push(row);\n\t\t\trow = character;\n\t\t\tcolumns = cost;\n\t\t} else {\n\t\t\trow += character;\n\t\t\tcolumns += cost;\n\t\t}\n\t}\n\trows.push(row);\n\treturn rows;\n}\n\n/**\n * Structural TUI component rendering a todo_update result as the plain state\n * listing: `warning: ` lines take the host theme's warning color, every other\n * row toolOutput (color is decided per logical line, so a wrapped warning\n * stays warning-colored). Rows are cached per width — the host may render the\n * same result repeatedly at one width — and dropped on text updates or\n * invalidate.\n */\nclass TodoResultComponent {\n\tprivate text: string;\n\tprivate readonly theme: ThemeLike;\n\tprivate readonly rowsByWidth = new Map<number, string[]>();\n\n\tconstructor(text: string, theme: ThemeLike) {\n\t\tthis.text = text;\n\t\tthis.theme = theme;\n\t}\n\n\tsetText(text: string): void {\n\t\tif (text === this.text) return;\n\t\tthis.text = text;\n\t\tthis.rowsByWidth.clear();\n\t}\n\n\trender(width: number): string[] {\n\t\tconst cached = this.rowsByWidth.get(width);\n\t\tif (cached) return cached;\n\t\tconst rows: string[] = [];\n\t\tfor (const line of this.text.split(\"\\n\")) {\n\t\t\tconst color = line.startsWith(\"warning: \") ? \"warning\" : \"toolOutput\";\n\t\t\tfor (const row of wrapLine(line, width)) rows.push(this.theme.fg(color, row));\n\t\t}\n\t\tthis.rowsByWidth.set(width, rows);\n\t\treturn rows;\n\t}\n\n\tinvalidate(): void {\n\t\tthis.rowsByWidth.clear();\n\t}\n}\n\n/**\n * Parses the text part the host serialized from this plugin's execute return\n * (capability-runtime-guards normalization): a `TodoState`, optionally with a\n * response-only `warning`. Anything else — a JSON.parse failure or a\n * different shape — returns undefined so the renderer falls back to the raw\n * text.\n */\nfunction parseTodoResultText(text: string): { state: TodoState; warning?: string } | undefined {\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(text);\n\t} catch {\n\t\treturn undefined;\n\t}\n\tif (parsed === null || typeof parsed !== \"object\" || Array.isArray(parsed)) return undefined;\n\tconst record = parsed as { todos?: unknown; warning?: unknown };\n\tif (!Array.isArray(record.todos)) return undefined;\n\tif (record.warning !== undefined && typeof record.warning !== \"string\") return undefined;\n\tconst state: TodoState = { todos: record.todos as TodoRecord[] };\n\treturn record.warning === undefined ? { state } : { state, warning: record.warning };\n}\n\n/**\n * renderResult for todo_update: re-renders the tool's own state payload as\n * the readable listing instead of the host's generic one-line JSON fallback.\n * Collapsed blocks show the summary and record lines only; expanded blocks\n * add the evidence lines; a response `warning` rides along as a final\n * warning-colored line. Non-state payloads and malformed records render\n * verbatim as toolOutput.\n */\nfunction renderTodoResult(\n\tresult: ToolResultLike,\n\toptions: RenderResultOptionsLike,\n\ttheme: ThemeLike,\n\tcontext: RenderContextLike,\n): TodoResultComponent | undefined {\n\tconst text = result.content.find((part) => part.type === \"text\")?.text;\n\tif (text === undefined || text === \"\") return undefined;\n\tconst parsed = parseTodoResultText(text);\n\tlet listing: string;\n\tif (parsed) {\n\t\t// The parse gate is envelope-level, so a parsed state may still hold\n\t\t// malformed records (null elements, a record missing evidence).\n\t\t// Rendering those must not throw out of the plugin: fall back to the\n\t\t// raw text, the same path as a parse failure.\n\t\ttry {\n\t\t\tlisting = renderTodoState(parsed.state, { evidence: options.expanded });\n\t\t\tif (parsed.warning !== undefined) {\n\t\t\t\t// Fold newlines like the record fields so the warning stays one line.\n\t\t\t\tlisting = `${listing}\\nwarning: ${parsed.warning.replace(/\\n/g, \" \")}`;\n\t\t\t}\n\t\t} catch {\n\t\t\tlisting = text;\n\t\t}\n\t} else {\n\t\tlisting = text;\n\t}\n\t// Reuse the host-provided component for this render slot (the ls.ts\n\t// precedent): same instance in, same instance out, with fresh text.\n\tif (context.lastComponent instanceof TodoResultComponent) {\n\t\tcontext.lastComponent.setText(listing);\n\t\treturn context.lastComponent;\n\t}\n\treturn new TodoResultComponent(listing, theme);\n}\n\n/**\n * Whether the session branch's LATEST `plan.state` snapshot knows a plan with\n * the given id (the same latest-snapshot semantics as {@link loadState} and\n * the same advisory pattern as the plan plugin's goalKnownToSession). The\n * check is advisory only (#10): a missing plan downgrades to a warning in the\n * tool response — the soft-reference write path never fails on it.\n */\nfunction planKnownToSession(api: CapabilityAPI, planId: string): boolean {\n\tconst entries = api.session?.getBranchEntries() ?? [];\n\tfor (let index = entries.length - 1; index >= 0; index -= 1) {\n\t\tconst entry = entries[index];\n\t\tif (entry.customType !== planStateEntry) continue;\n\t\tconst data = entry.data;\n\t\tif (!data || typeof data !== \"object\" || Array.isArray(data)) return false;\n\t\tconst plans = (data as { plans?: unknown }).plans;\n\t\tif (!Array.isArray(plans)) return false;\n\t\treturn plans.some(\n\t\t\t(plan) => plan !== null && typeof plan === \"object\" && (plan as { id?: unknown }).id === planId,\n\t\t);\n\t}\n\treturn false;\n}\n\nexport function createCapability(\n\tapi: CapabilityAPI,\n): Promise<readonly DisposableRegistration[]> | readonly DisposableRegistration[] {\n\tlet state = loadState(api);\n\tconst refreshState = (): TodoState => {\n\t\tif (api.session) state = loadState(api);\n\t\treturn state;\n\t};\n\n\tconst persist = async (): Promise<TodoState> => {\n\t\tapi.session?.appendEntry(stateEntry, state);\n\t\tawait api.publish({ type: \"todo.changed\", version: 1, correlationId: stateEntry, data: state });\n\t\treturn state;\n\t};\n\n\tconst tool = api.registerTool({\n\t\tname: \"todo_update\",\n\t\tlabel: \"Update todo\",\n\t\tdescription:\n\t\t\t\"Update a todo that softly references a plan by id. Create with status pending at revision 1, update unfinished items with a higher revision; marking done or cancelled is final and requires evidence, so commit the work first and then complete the todo\",\n\t\tparameters: todoSchema,\n\t\trenderResult: renderTodoResult,\n\t\texecute: async (first: unknown, second?: unknown) => {\n\t\t\trefreshState();\n\t\t\tconst input = objectInput(first, second);\n\t\t\tconst id = text(input.id, \"id\");\n\t\t\tconst planId = text(input.planId, \"planId\");\n\t\t\tconst title = text(input.title, \"title\");\n\t\t\tconst nextRevision = revision(input.revision);\n\t\t\tconst current = state.todos.find((item) => item.id === id);\n\t\t\tif (current && nextRevision <= current.revision) throw new Error(`stale todo revision: ${id}`);\n\t\t\tif (current?.status === \"done\" || current?.status === \"cancelled\") {\n\t\t\t\tthrow new Error(`todo is terminal and cannot be updated: ${id}`);\n\t\t\t}\n\t\t\tconst status =\n\t\t\t\tinput.status === undefined\n\t\t\t\t\t? (current?.status ?? \"pending\")\n\t\t\t\t\t: (text(input.status, \"status\") as TodoRecord[\"status\"]);\n\t\t\tif (![\"pending\", \"done\", \"blocked\", \"cancelled\"].includes(status)) throw new Error(\"invalid todo status\");\n\t\t\tconst values = evidence(input.evidence);\n\t\t\tif (status === \"done\" && values.length === 0) {\n\t\t\t\tthrow new Error(\"todo completion requires at least one evidence reference\");\n\t\t\t}\n\t\t\tif (status === \"cancelled\" && values.length === 0) {\n\t\t\t\tthrow new Error(\"todo cancellation requires at least one evidence reference\");\n\t\t\t}\n\t\t\tconst record: TodoRecord = { id, planId, title, status, revision: nextRevision, evidence: values };\n\t\t\tstate = { ...state, todos: [...state.todos.filter((item) => item.id !== id), record] };\n\t\t\tconst saved = await persist();\n\t\t\tif (planKnownToSession(api, planId)) return saved;\n\t\t\treturn {\n\t\t\t\t...saved,\n\t\t\t\twarning: `planId \"${planId}\" does not match any plan in this session's plan state; the todo keeps the soft reference, but the plan is unknown`,\n\t\t\t};\n\t\t},\n\t});\n\n\tconst command = api.registerCommand({\n\t\tname: \"todo\",\n\t\tdescription: \"Show this session's todos (status and plan reference)\",\n\t\texecute: async (args: string) => {\n\t\t\ttry {\n\t\t\t\tif (args.trim() !== \"\") return { status: \"error\" as const, message: \"Usage: /todo\" };\n\t\t\t\treturn { status: \"success\" as const, message: renderTodoState(refreshState()) };\n\t\t\t} catch (error) {\n\t\t\t\t// A slash command must not crash the host (memory /promote precedent).\n\t\t\t\treturn { status: \"error\" as const, message: error instanceof Error ? error.message : String(error) };\n\t\t\t}\n\t\t},\n\t});\n\n\treturn [tool, command];\n}\n"]}
package/dist/index.js CHANGED
@@ -19,7 +19,7 @@ const planStateEntry = "plan.state";
19
19
  const todoSchema = Type.Object({
20
20
  id: Type.String({ description: "Stable id of the todo to create or update" }),
21
21
  planId: Type.String({
22
- description: "Soft reference to a plan id; an id unknown to this session's plan state yields a response warning, not a failure",
22
+ description: "Plan id this todo belongs to (required, non-empty). An unknown id only adds a response warning; the todo still persists",
23
23
  }),
24
24
  title: Type.String({ description: "Human-readable todo title" }),
25
25
  revision: Type.Integer({
@@ -30,7 +30,7 @@ const todoSchema = Type.Object({
30
30
  description: "Next status; defaults to the stored status for existing todos, otherwise pending. done and cancelled are terminal: once a todo holds either status it can never be updated again, so finish every evidence reference before marking it done, and never mark done to avoid reporting unfinished work. Use blocked only for temporarily stuck work that may resume; use cancelled when the user retires or skips the todo",
31
31
  })),
32
32
  evidence: Type.Optional(Type.Array(Type.String(), {
33
- description: "Final evidence references; at least one is required when status is done or cancelled (for cancelled, cite the user's words that retired the todo). The list is fixed at that moment — a terminal todo cannot be updated to add later evidence such as a commit id",
33
+ description: "Final evidence references. This list REPLACES the stored list on every call — re-send existing references when updating. At least one is required when status is done or cancelled (for cancelled, cite the user's words that retired the todo). The list is fixed at that moment — a terminal todo cannot be updated to add later evidence such as a commit id",
34
34
  })),
35
35
  });
36
36
  function objectInput(first, second) {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAoB/B,MAAM,UAAU,GAAG,YAAY,CAAC;AAChC,+EAA+E;AAC/E,MAAM,cAAc,GAAG,YAAY,CAAC;AAEpC,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC;IAC9B,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,2CAA2C,EAAE,CAAC;IAC7E,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;QACnB,WAAW,EACV,kHAAkH;KACnH,CAAC;IACF,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,2BAA2B,EAAE,CAAC;IAChE,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC;QACtB,WAAW,EAAE,oFAAoF;QACjG,OAAO,EAAE,CAAC;KACV,CAAC;IACF,MAAM,EAAE,IAAI,CAAC,QAAQ,CACpB,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,SAA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AAK,CAAC;YAClD,OAAO;gBACN,GAAG,KAAK;gBACR,OAAO,EAAE,WAAW,MAAM,oHAAoH;aAC9I,CAAC;QAAA,CACF;KACD,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,GAAG,CAAC,eAAe,CAAC;QACnC,IAAI,EAAE,MAAM;QACZ,WAAW,EAAE,uDAAuD;QACpE,OAAO,EAAE,KAAK,EAAE,IAAY,EAAE,EAAE,CAAC;YAChC,IAAI,CAAC;gBACJ,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE;oBAAE,OAAO,EAAE,MAAM,EAAE,OAAgB,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;gBACrF,OAAO,EAAE,MAAM,EAAE,SAAkB,EAAE,OAAO,EAAE,eAAe,CAAC,YAAY,EAAE,CAAC,EAAE,CAAC;YACjF,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,uEAAuE;gBACvE,OAAO,EAAE,MAAM,EAAE,OAAgB,EAAE,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YACtG,CAAC;QAAA,CACD;KACD,CAAC,CAAC;IAEH,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAAA,CACvB","sourcesContent":["/**\n * Todo-set capability plugin: a self-contained todo state machine, extracted\n * from the host's `src/capabilities/todo-set.ts` (D-075 S4, first B-class\n * batch).\n *\n * Todos persist as append-only `todo.state` session entries and every change\n * is announced as a `todo.changed` event. `planId` is a soft reference: a\n * plain string whose target is checked ADVISORILY against the plan plugin's\n * LATEST `plan.state` snapshot (the same latest-snapshot semantics as this\n * plugin's own {@link loadState}); an unknown id yields a response warning,\n * never a failure (the same #10 pattern as the plan plugin's goalId check).\n * The plugin only consumes the public `session`, `events`, and `tools`\n * capabilities and never writes state owned by another plugin.\n */\n\nimport type { CapabilityAPI, DisposableRegistration } from \"@agent-forge/plugin-sdk\";\nimport { Type } from \"typebox\";\n\nexport interface TodoRecord {\n\tid: string;\n\t/** Soft reference: a plain string; unknown ids yield a response warning, not a failure. */\n\tplanId: string;\n\ttitle: string;\n\t/**\n\t * Lifecycle status. `cancelled` is terminal (voided: permanently retired,\n\t * no longer part of execution) and shares done's no-further-update guard.\n\t */\n\tstatus: \"pending\" | \"done\" | \"blocked\" | \"cancelled\";\n\trevision: number;\n\tevidence: string[];\n}\n\nexport interface TodoState {\n\ttodos: TodoRecord[];\n}\n\nconst stateEntry = \"todo.state\";\n/** Session protocol key of the plan plugin's snapshot entry (plugins/plan). */\nconst planStateEntry = \"plan.state\";\n\nconst todoSchema = Type.Object({\n\tid: Type.String({ description: \"Stable id of the todo to create or update\" }),\n\tplanId: Type.String({\n\t\tdescription:\n\t\t\t\"Soft reference to a plan id; an id unknown to this session's plan state yields a response warning, not a failure\",\n\t}),\n\ttitle: Type.String({ description: \"Human-readable todo title\" }),\n\trevision: Type.Integer({\n\t\tdescription: \"New revision counter; must be greater than the stored revision of an existing todo\",\n\t\tminimum: 0,\n\t}),\n\tstatus: Type.Optional(\n\t\tType.Union([Type.Literal(\"pending\"), Type.Literal(\"done\"), Type.Literal(\"blocked\"), Type.Literal(\"cancelled\")], {\n\t\t\tdescription:\n\t\t\t\t\"Next status; defaults to the stored status for existing todos, otherwise pending. done and cancelled are terminal: once a todo holds either status it can never be updated again, so finish every evidence reference before marking it done, and never mark done to avoid reporting unfinished work. Use blocked only for temporarily stuck work that may resume; use cancelled when the user retires or skips the todo\",\n\t\t}),\n\t),\n\tevidence: Type.Optional(\n\t\tType.Array(Type.String(), {\n\t\t\tdescription:\n\t\t\t\t\"Final evidence references; at least one is required when status is done or cancelled (for cancelled, cite the user's words that retired the todo). The list is fixed at that moment — a terminal todo cannot be updated to add later evidence such as a commit id\",\n\t\t}),\n\t),\n});\n\nfunction objectInput(first: unknown, second: unknown): Record<string, unknown> {\n\tconst value = first !== null && typeof first === \"object\" && !Array.isArray(first) ? first : second;\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) throw new Error(\"Todo input must be an object\");\n\treturn value as Record<string, unknown>;\n}\n\nfunction text(value: unknown, name: string): string {\n\tif (typeof value !== \"string\" || value.trim() === \"\") throw new Error(`${name} must be a non-empty string`);\n\treturn value;\n}\n\nfunction revision(value: unknown): number {\n\tif (!Number.isInteger(value) || (value as number) < 0) throw new Error(\"revision must be a non-negative integer\");\n\treturn value as number;\n}\n\nfunction evidence(value: unknown): string[] {\n\tif (value === undefined) return [];\n\tif (!Array.isArray(value) || value.some((item) => typeof item !== \"string\" || item.trim() === \"\")) {\n\t\tthrow new Error(\"evidence must be a string array\");\n\t}\n\treturn [...(value as string[])];\n}\n\nfunction loadState(api: CapabilityAPI): TodoState {\n\tconst entries = api.session?.getBranchEntries() ?? [];\n\tconst entry = [...entries].reverse().find((item) => item.customType === stateEntry);\n\tif (!entry?.data || typeof entry.data !== \"object\") return { todos: [] };\n\tconst data = entry.data as Partial<TodoState>;\n\treturn { todos: Array.isArray(data.todos) ? [...data.todos] : [] };\n}\n\n/**\n * `/todo` command text rendering: one line per todo (`id [status → planId]\n * title`) plus the evidence lines that justified completion. The leading count\n * line lists its non-zero segments in done → blocked → cancelled order. Plain\n * text only —\n * every host shape can render it, no TUI required (the same L1 contract as\n * the workflow plugin's `/workflow`). Collapsed tool blocks pass\n * `{ evidence: false }` to omit the evidence lines; the default keeps the\n * command output byte-for-byte stable.\n */\nexport function renderTodoState(state: TodoState, options?: { evidence?: boolean }): string {\n\tconst withEvidence = options?.evidence ?? true;\n\tif (state.todos.length === 0) return \"no todos in this session; create one with todo_update\";\n\tconst done = state.todos.filter((todo) => todo.status === \"done\").length;\n\tconst blocked = state.todos.filter((todo) => todo.status === \"blocked\").length;\n\tconst cancelled = state.todos.filter((todo) => todo.status === \"cancelled\").length;\n\t// Count segments in the fixed done → blocked → cancelled order; zero\n\t// segments are omitted (the rule blocked always had), so a total with no\n\t// countable status renders bare instead of with empty parentheses.\n\tconst segments: string[] = [];\n\tif (done > 0) segments.push(`${done} done`);\n\tif (blocked > 0) segments.push(`${blocked} blocked`);\n\tif (cancelled > 0) segments.push(`${cancelled} cancelled`);\n\tconst lines = [\n\t\tsegments.length > 0 ? `todos: ${state.todos.length} (${segments.join(\", \")})` : `todos: ${state.todos.length}`,\n\t];\n\t// Record fields only validate non-emptiness, so fold newlines to keep the\n\t// one-line-per-record shape whatever the model wrote.\n\tconst inline = (value: string): string => value.replace(/\\n/g, \" \");\n\tfor (const todo of state.todos) {\n\t\tlines.push(`- ${inline(todo.id)} [${todo.status} → ${inline(todo.planId)}] ${inline(todo.title)}`);\n\t\tif (withEvidence) for (const item of todo.evidence) lines.push(` evidence: ${inline(item)}`);\n\t}\n\treturn lines.join(\"\\n\");\n}\n\n/**\n * Structural slices of the host tool-render contracts the renderer needs.\n * Declared locally on purpose: this plugin must stay self-contained and must\n * not import `@agent-forge/tui` (the tool-definition.ts structural hosting\n * boundary), so renderResult talks to these shapes instead of the real\n * Theme/Component types.\n */\ninterface ToolResultTextPartLike {\n\treadonly type: string;\n\treadonly text?: string;\n}\n\ninterface ToolResultLike {\n\treadonly content: readonly ToolResultTextPartLike[];\n}\n\ninterface RenderResultOptionsLike {\n\treadonly expanded: boolean;\n\treadonly isPartial: boolean;\n}\n\ninterface ThemeLike {\n\tfg(color: string, text: string): string;\n}\n\ninterface RenderContextLike {\n\treadonly lastComponent?: unknown;\n}\n\n/**\n * Simplified East Asian width table: these ranges cover the CJK blocks state\n * titles realistically use and count as 2 columns each; every other code\n * point counts as 1. Not a full wcwidth — combining marks and ambiguous\n * widths fall back to 1, the safe (narrower) default for row folding.\n */\nfunction isWideCodePoint(code: number): boolean {\n\treturn (\n\t\t(code >= 0x1100 && code <= 0x115f) ||\n\t\t(code >= 0x2e80 && code <= 0xa4cf) ||\n\t\t(code >= 0xac00 && code <= 0xd7a3) ||\n\t\t(code >= 0xf900 && code <= 0xfaff) ||\n\t\t(code >= 0xfe30 && code <= 0xfe4f) ||\n\t\t(code >= 0xff00 && code <= 0xff60) ||\n\t\t(code >= 0xffe0 && code <= 0xffe6) ||\n\t\t(code >= 0x20000 && code <= 0x3fffd)\n\t);\n}\n\n/** Folds one logical line into rows of at most `width` display columns. */\nfunction wrapLine(line: string, width: number): string[] {\n\tif (width <= 0) return [line];\n\tconst rows: string[] = [];\n\tlet row = \"\";\n\tlet columns = 0;\n\tfor (const character of line) {\n\t\tconst cost = isWideCodePoint(character.codePointAt(0) ?? 0) ? 2 : 1;\n\t\tif (row !== \"\" && columns + cost > width) {\n\t\t\trows.push(row);\n\t\t\trow = character;\n\t\t\tcolumns = cost;\n\t\t} else {\n\t\t\trow += character;\n\t\t\tcolumns += cost;\n\t\t}\n\t}\n\trows.push(row);\n\treturn rows;\n}\n\n/**\n * Structural TUI component rendering a todo_update result as the plain state\n * listing: `warning: ` lines take the host theme's warning color, every other\n * row toolOutput (color is decided per logical line, so a wrapped warning\n * stays warning-colored). Rows are cached per width — the host may render the\n * same result repeatedly at one width — and dropped on text updates or\n * invalidate.\n */\nclass TodoResultComponent {\n\tprivate text: string;\n\tprivate readonly theme: ThemeLike;\n\tprivate readonly rowsByWidth = new Map<number, string[]>();\n\n\tconstructor(text: string, theme: ThemeLike) {\n\t\tthis.text = text;\n\t\tthis.theme = theme;\n\t}\n\n\tsetText(text: string): void {\n\t\tif (text === this.text) return;\n\t\tthis.text = text;\n\t\tthis.rowsByWidth.clear();\n\t}\n\n\trender(width: number): string[] {\n\t\tconst cached = this.rowsByWidth.get(width);\n\t\tif (cached) return cached;\n\t\tconst rows: string[] = [];\n\t\tfor (const line of this.text.split(\"\\n\")) {\n\t\t\tconst color = line.startsWith(\"warning: \") ? \"warning\" : \"toolOutput\";\n\t\t\tfor (const row of wrapLine(line, width)) rows.push(this.theme.fg(color, row));\n\t\t}\n\t\tthis.rowsByWidth.set(width, rows);\n\t\treturn rows;\n\t}\n\n\tinvalidate(): void {\n\t\tthis.rowsByWidth.clear();\n\t}\n}\n\n/**\n * Parses the text part the host serialized from this plugin's execute return\n * (capability-runtime-guards normalization): a `TodoState`, optionally with a\n * response-only `warning`. Anything else — a JSON.parse failure or a\n * different shape — returns undefined so the renderer falls back to the raw\n * text.\n */\nfunction parseTodoResultText(text: string): { state: TodoState; warning?: string } | undefined {\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(text);\n\t} catch {\n\t\treturn undefined;\n\t}\n\tif (parsed === null || typeof parsed !== \"object\" || Array.isArray(parsed)) return undefined;\n\tconst record = parsed as { todos?: unknown; warning?: unknown };\n\tif (!Array.isArray(record.todos)) return undefined;\n\tif (record.warning !== undefined && typeof record.warning !== \"string\") return undefined;\n\tconst state: TodoState = { todos: record.todos as TodoRecord[] };\n\treturn record.warning === undefined ? { state } : { state, warning: record.warning };\n}\n\n/**\n * renderResult for todo_update: re-renders the tool's own state payload as\n * the readable listing instead of the host's generic one-line JSON fallback.\n * Collapsed blocks show the summary and record lines only; expanded blocks\n * add the evidence lines; a response `warning` rides along as a final\n * warning-colored line. Non-state payloads and malformed records render\n * verbatim as toolOutput.\n */\nfunction renderTodoResult(\n\tresult: ToolResultLike,\n\toptions: RenderResultOptionsLike,\n\ttheme: ThemeLike,\n\tcontext: RenderContextLike,\n): TodoResultComponent | undefined {\n\tconst text = result.content.find((part) => part.type === \"text\")?.text;\n\tif (text === undefined || text === \"\") return undefined;\n\tconst parsed = parseTodoResultText(text);\n\tlet listing: string;\n\tif (parsed) {\n\t\t// The parse gate is envelope-level, so a parsed state may still hold\n\t\t// malformed records (null elements, a record missing evidence).\n\t\t// Rendering those must not throw out of the plugin: fall back to the\n\t\t// raw text, the same path as a parse failure.\n\t\ttry {\n\t\t\tlisting = renderTodoState(parsed.state, { evidence: options.expanded });\n\t\t\tif (parsed.warning !== undefined) {\n\t\t\t\t// Fold newlines like the record fields so the warning stays one line.\n\t\t\t\tlisting = `${listing}\\nwarning: ${parsed.warning.replace(/\\n/g, \" \")}`;\n\t\t\t}\n\t\t} catch {\n\t\t\tlisting = text;\n\t\t}\n\t} else {\n\t\tlisting = text;\n\t}\n\t// Reuse the host-provided component for this render slot (the ls.ts\n\t// precedent): same instance in, same instance out, with fresh text.\n\tif (context.lastComponent instanceof TodoResultComponent) {\n\t\tcontext.lastComponent.setText(listing);\n\t\treturn context.lastComponent;\n\t}\n\treturn new TodoResultComponent(listing, theme);\n}\n\n/**\n * Whether the session branch's LATEST `plan.state` snapshot knows a plan with\n * the given id (the same latest-snapshot semantics as {@link loadState} and\n * the same advisory pattern as the plan plugin's goalKnownToSession). The\n * check is advisory only (#10): a missing plan downgrades to a warning in the\n * tool response — the soft-reference write path never fails on it.\n */\nfunction planKnownToSession(api: CapabilityAPI, planId: string): boolean {\n\tconst entries = api.session?.getBranchEntries() ?? [];\n\tfor (let index = entries.length - 1; index >= 0; index -= 1) {\n\t\tconst entry = entries[index];\n\t\tif (entry.customType !== planStateEntry) continue;\n\t\tconst data = entry.data;\n\t\tif (!data || typeof data !== \"object\" || Array.isArray(data)) return false;\n\t\tconst plans = (data as { plans?: unknown }).plans;\n\t\tif (!Array.isArray(plans)) return false;\n\t\treturn plans.some(\n\t\t\t(plan) => plan !== null && typeof plan === \"object\" && (plan as { id?: unknown }).id === planId,\n\t\t);\n\t}\n\treturn false;\n}\n\nexport function createCapability(\n\tapi: CapabilityAPI,\n): Promise<readonly DisposableRegistration[]> | readonly DisposableRegistration[] {\n\tlet state = loadState(api);\n\tconst refreshState = (): TodoState => {\n\t\tif (api.session) state = loadState(api);\n\t\treturn state;\n\t};\n\n\tconst persist = async (): Promise<TodoState> => {\n\t\tapi.session?.appendEntry(stateEntry, state);\n\t\tawait api.publish({ type: \"todo.changed\", version: 1, correlationId: stateEntry, data: state });\n\t\treturn state;\n\t};\n\n\tconst tool = api.registerTool({\n\t\tname: \"todo_update\",\n\t\tlabel: \"Update todo\",\n\t\tdescription:\n\t\t\t\"Update a todo that softly references a plan by id. Create with status pending at revision 1, update unfinished items with a higher revision; marking done or cancelled is final and requires evidence, so commit the work first and then complete the todo\",\n\t\tparameters: todoSchema,\n\t\trenderResult: renderTodoResult,\n\t\texecute: async (first: unknown, second?: unknown) => {\n\t\t\trefreshState();\n\t\t\tconst input = objectInput(first, second);\n\t\t\tconst id = text(input.id, \"id\");\n\t\t\tconst planId = text(input.planId, \"planId\");\n\t\t\tconst title = text(input.title, \"title\");\n\t\t\tconst nextRevision = revision(input.revision);\n\t\t\tconst current = state.todos.find((item) => item.id === id);\n\t\t\tif (current && nextRevision <= current.revision) throw new Error(`stale todo revision: ${id}`);\n\t\t\tif (current?.status === \"done\" || current?.status === \"cancelled\") {\n\t\t\t\tthrow new Error(`todo is terminal and cannot be updated: ${id}`);\n\t\t\t}\n\t\t\tconst status =\n\t\t\t\tinput.status === undefined\n\t\t\t\t\t? (current?.status ?? \"pending\")\n\t\t\t\t\t: (text(input.status, \"status\") as TodoRecord[\"status\"]);\n\t\t\tif (![\"pending\", \"done\", \"blocked\", \"cancelled\"].includes(status)) throw new Error(\"invalid todo status\");\n\t\t\tconst values = evidence(input.evidence);\n\t\t\tif (status === \"done\" && values.length === 0) {\n\t\t\t\tthrow new Error(\"todo completion requires at least one evidence reference\");\n\t\t\t}\n\t\t\tif (status === \"cancelled\" && values.length === 0) {\n\t\t\t\tthrow new Error(\"todo cancellation requires at least one evidence reference\");\n\t\t\t}\n\t\t\tconst record: TodoRecord = { id, planId, title, status, revision: nextRevision, evidence: values };\n\t\t\tstate = { ...state, todos: [...state.todos.filter((item) => item.id !== id), record] };\n\t\t\tconst saved = await persist();\n\t\t\tif (planKnownToSession(api, planId)) return saved;\n\t\t\treturn {\n\t\t\t\t...saved,\n\t\t\t\twarning: `planId \"${planId}\" does not match any plan in this session's plan state; the todo keeps the soft reference, but the plan is unknown`,\n\t\t\t};\n\t\t},\n\t});\n\n\tconst command = api.registerCommand({\n\t\tname: \"todo\",\n\t\tdescription: \"Show this session's todos (status and plan reference)\",\n\t\texecute: async (args: string) => {\n\t\t\ttry {\n\t\t\t\tif (args.trim() !== \"\") return { status: \"error\" as const, message: \"Usage: /todo\" };\n\t\t\t\treturn { status: \"success\" as const, message: renderTodoState(refreshState()) };\n\t\t\t} catch (error) {\n\t\t\t\t// A slash command must not crash the host (memory /promote precedent).\n\t\t\t\treturn { status: \"error\" as const, message: error instanceof Error ? error.message : String(error) };\n\t\t\t}\n\t\t},\n\t});\n\n\treturn [tool, command];\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAoB/B,MAAM,UAAU,GAAG,YAAY,CAAC;AAChC,+EAA+E;AAC/E,MAAM,cAAc,GAAG,YAAY,CAAC;AAEpC,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC;IAC9B,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,2CAA2C,EAAE,CAAC;IAC7E,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;QACnB,WAAW,EACV,yHAAyH;KAC1H,CAAC;IACF,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,2BAA2B,EAAE,CAAC;IAChE,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC;QACtB,WAAW,EAAE,oFAAoF;QACjG,OAAO,EAAE,CAAC;KACV,CAAC;IACF,MAAM,EAAE,IAAI,CAAC,QAAQ,CACpB,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,EAAE;QAC/G,WAAW,EACV,yZAAyZ;KAC1Z,CAAC,CACF;IACD,QAAQ,EAAE,IAAI,CAAC,QAAQ,CACtB,IAAI,CA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AAC;QACnC,IAAI,EAAE,MAAM;QACZ,WAAW,EAAE,uDAAuD;QACpE,OAAO,EAAE,KAAK,EAAE,IAAY,EAAE,EAAE,CAAC;YAChC,IAAI,CAAC;gBACJ,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE;oBAAE,OAAO,EAAE,MAAM,EAAE,OAAgB,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;gBACrF,OAAO,EAAE,MAAM,EAAE,SAAkB,EAAE,OAAO,EAAE,eAAe,CAAC,YAAY,EAAE,CAAC,EAAE,CAAC;YACjF,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,uEAAuE;gBACvE,OAAO,EAAE,MAAM,EAAE,OAAgB,EAAE,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YACtG,CAAC;QAAA,CACD;KACD,CAAC,CAAC;IAEH,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAAA,CACvB","sourcesContent":["/**\n * Todo-set capability plugin: a self-contained todo state machine, extracted\n * from the host's `src/capabilities/todo-set.ts` (D-075 S4, first B-class\n * batch).\n *\n * Todos persist as append-only `todo.state` session entries and every change\n * is announced as a `todo.changed` event. `planId` is a soft reference: a\n * plain string whose target is checked ADVISORILY against the plan plugin's\n * LATEST `plan.state` snapshot (the same latest-snapshot semantics as this\n * plugin's own {@link loadState}); an unknown id yields a response warning,\n * never a failure (the same #10 pattern as the plan plugin's goalId check).\n * The plugin only consumes the public `session`, `events`, and `tools`\n * capabilities and never writes state owned by another plugin.\n */\n\nimport type { CapabilityAPI, DisposableRegistration } from \"@agent-forge/plugin-sdk\";\nimport { Type } from \"typebox\";\n\nexport interface TodoRecord {\n\tid: string;\n\t/** Soft reference: a plain string; unknown ids yield a response warning, not a failure. */\n\tplanId: string;\n\ttitle: string;\n\t/**\n\t * Lifecycle status. `cancelled` is terminal (voided: permanently retired,\n\t * no longer part of execution) and shares done's no-further-update guard.\n\t */\n\tstatus: \"pending\" | \"done\" | \"blocked\" | \"cancelled\";\n\trevision: number;\n\tevidence: string[];\n}\n\nexport interface TodoState {\n\ttodos: TodoRecord[];\n}\n\nconst stateEntry = \"todo.state\";\n/** Session protocol key of the plan plugin's snapshot entry (plugins/plan). */\nconst planStateEntry = \"plan.state\";\n\nconst todoSchema = Type.Object({\n\tid: Type.String({ description: \"Stable id of the todo to create or update\" }),\n\tplanId: Type.String({\n\t\tdescription:\n\t\t\t\"Plan id this todo belongs to (required, non-empty). An unknown id only adds a response warning; the todo still persists\",\n\t}),\n\ttitle: Type.String({ description: \"Human-readable todo title\" }),\n\trevision: Type.Integer({\n\t\tdescription: \"New revision counter; must be greater than the stored revision of an existing todo\",\n\t\tminimum: 0,\n\t}),\n\tstatus: Type.Optional(\n\t\tType.Union([Type.Literal(\"pending\"), Type.Literal(\"done\"), Type.Literal(\"blocked\"), Type.Literal(\"cancelled\")], {\n\t\t\tdescription:\n\t\t\t\t\"Next status; defaults to the stored status for existing todos, otherwise pending. done and cancelled are terminal: once a todo holds either status it can never be updated again, so finish every evidence reference before marking it done, and never mark done to avoid reporting unfinished work. Use blocked only for temporarily stuck work that may resume; use cancelled when the user retires or skips the todo\",\n\t\t}),\n\t),\n\tevidence: Type.Optional(\n\t\tType.Array(Type.String(), {\n\t\t\tdescription:\n\t\t\t\t\"Final evidence references. This list REPLACES the stored list on every call — re-send existing references when updating. At least one is required when status is done or cancelled (for cancelled, cite the user's words that retired the todo). The list is fixed at that moment — a terminal todo cannot be updated to add later evidence such as a commit id\",\n\t\t}),\n\t),\n});\n\nfunction objectInput(first: unknown, second: unknown): Record<string, unknown> {\n\tconst value = first !== null && typeof first === \"object\" && !Array.isArray(first) ? first : second;\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) throw new Error(\"Todo input must be an object\");\n\treturn value as Record<string, unknown>;\n}\n\nfunction text(value: unknown, name: string): string {\n\tif (typeof value !== \"string\" || value.trim() === \"\") throw new Error(`${name} must be a non-empty string`);\n\treturn value;\n}\n\nfunction revision(value: unknown): number {\n\tif (!Number.isInteger(value) || (value as number) < 0) throw new Error(\"revision must be a non-negative integer\");\n\treturn value as number;\n}\n\nfunction evidence(value: unknown): string[] {\n\tif (value === undefined) return [];\n\tif (!Array.isArray(value) || value.some((item) => typeof item !== \"string\" || item.trim() === \"\")) {\n\t\tthrow new Error(\"evidence must be a string array\");\n\t}\n\treturn [...(value as string[])];\n}\n\nfunction loadState(api: CapabilityAPI): TodoState {\n\tconst entries = api.session?.getBranchEntries() ?? [];\n\tconst entry = [...entries].reverse().find((item) => item.customType === stateEntry);\n\tif (!entry?.data || typeof entry.data !== \"object\") return { todos: [] };\n\tconst data = entry.data as Partial<TodoState>;\n\treturn { todos: Array.isArray(data.todos) ? [...data.todos] : [] };\n}\n\n/**\n * `/todo` command text rendering: one line per todo (`id [status → planId]\n * title`) plus the evidence lines that justified completion. The leading count\n * line lists its non-zero segments in done → blocked → cancelled order. Plain\n * text only —\n * every host shape can render it, no TUI required (the same L1 contract as\n * the workflow plugin's `/workflow`). Collapsed tool blocks pass\n * `{ evidence: false }` to omit the evidence lines; the default keeps the\n * command output byte-for-byte stable.\n */\nexport function renderTodoState(state: TodoState, options?: { evidence?: boolean }): string {\n\tconst withEvidence = options?.evidence ?? true;\n\tif (state.todos.length === 0) return \"no todos in this session; create one with todo_update\";\n\tconst done = state.todos.filter((todo) => todo.status === \"done\").length;\n\tconst blocked = state.todos.filter((todo) => todo.status === \"blocked\").length;\n\tconst cancelled = state.todos.filter((todo) => todo.status === \"cancelled\").length;\n\t// Count segments in the fixed done → blocked → cancelled order; zero\n\t// segments are omitted (the rule blocked always had), so a total with no\n\t// countable status renders bare instead of with empty parentheses.\n\tconst segments: string[] = [];\n\tif (done > 0) segments.push(`${done} done`);\n\tif (blocked > 0) segments.push(`${blocked} blocked`);\n\tif (cancelled > 0) segments.push(`${cancelled} cancelled`);\n\tconst lines = [\n\t\tsegments.length > 0 ? `todos: ${state.todos.length} (${segments.join(\", \")})` : `todos: ${state.todos.length}`,\n\t];\n\t// Record fields only validate non-emptiness, so fold newlines to keep the\n\t// one-line-per-record shape whatever the model wrote.\n\tconst inline = (value: string): string => value.replace(/\\n/g, \" \");\n\tfor (const todo of state.todos) {\n\t\tlines.push(`- ${inline(todo.id)} [${todo.status} → ${inline(todo.planId)}] ${inline(todo.title)}`);\n\t\tif (withEvidence) for (const item of todo.evidence) lines.push(` evidence: ${inline(item)}`);\n\t}\n\treturn lines.join(\"\\n\");\n}\n\n/**\n * Structural slices of the host tool-render contracts the renderer needs.\n * Declared locally on purpose: this plugin must stay self-contained and must\n * not import `@agent-forge/tui` (the tool-definition.ts structural hosting\n * boundary), so renderResult talks to these shapes instead of the real\n * Theme/Component types.\n */\ninterface ToolResultTextPartLike {\n\treadonly type: string;\n\treadonly text?: string;\n}\n\ninterface ToolResultLike {\n\treadonly content: readonly ToolResultTextPartLike[];\n}\n\ninterface RenderResultOptionsLike {\n\treadonly expanded: boolean;\n\treadonly isPartial: boolean;\n}\n\ninterface ThemeLike {\n\tfg(color: string, text: string): string;\n}\n\ninterface RenderContextLike {\n\treadonly lastComponent?: unknown;\n}\n\n/**\n * Simplified East Asian width table: these ranges cover the CJK blocks state\n * titles realistically use and count as 2 columns each; every other code\n * point counts as 1. Not a full wcwidth — combining marks and ambiguous\n * widths fall back to 1, the safe (narrower) default for row folding.\n */\nfunction isWideCodePoint(code: number): boolean {\n\treturn (\n\t\t(code >= 0x1100 && code <= 0x115f) ||\n\t\t(code >= 0x2e80 && code <= 0xa4cf) ||\n\t\t(code >= 0xac00 && code <= 0xd7a3) ||\n\t\t(code >= 0xf900 && code <= 0xfaff) ||\n\t\t(code >= 0xfe30 && code <= 0xfe4f) ||\n\t\t(code >= 0xff00 && code <= 0xff60) ||\n\t\t(code >= 0xffe0 && code <= 0xffe6) ||\n\t\t(code >= 0x20000 && code <= 0x3fffd)\n\t);\n}\n\n/** Folds one logical line into rows of at most `width` display columns. */\nfunction wrapLine(line: string, width: number): string[] {\n\tif (width <= 0) return [line];\n\tconst rows: string[] = [];\n\tlet row = \"\";\n\tlet columns = 0;\n\tfor (const character of line) {\n\t\tconst cost = isWideCodePoint(character.codePointAt(0) ?? 0) ? 2 : 1;\n\t\tif (row !== \"\" && columns + cost > width) {\n\t\t\trows.push(row);\n\t\t\trow = character;\n\t\t\tcolumns = cost;\n\t\t} else {\n\t\t\trow += character;\n\t\t\tcolumns += cost;\n\t\t}\n\t}\n\trows.push(row);\n\treturn rows;\n}\n\n/**\n * Structural TUI component rendering a todo_update result as the plain state\n * listing: `warning: ` lines take the host theme's warning color, every other\n * row toolOutput (color is decided per logical line, so a wrapped warning\n * stays warning-colored). Rows are cached per width — the host may render the\n * same result repeatedly at one width — and dropped on text updates or\n * invalidate.\n */\nclass TodoResultComponent {\n\tprivate text: string;\n\tprivate readonly theme: ThemeLike;\n\tprivate readonly rowsByWidth = new Map<number, string[]>();\n\n\tconstructor(text: string, theme: ThemeLike) {\n\t\tthis.text = text;\n\t\tthis.theme = theme;\n\t}\n\n\tsetText(text: string): void {\n\t\tif (text === this.text) return;\n\t\tthis.text = text;\n\t\tthis.rowsByWidth.clear();\n\t}\n\n\trender(width: number): string[] {\n\t\tconst cached = this.rowsByWidth.get(width);\n\t\tif (cached) return cached;\n\t\tconst rows: string[] = [];\n\t\tfor (const line of this.text.split(\"\\n\")) {\n\t\t\tconst color = line.startsWith(\"warning: \") ? \"warning\" : \"toolOutput\";\n\t\t\tfor (const row of wrapLine(line, width)) rows.push(this.theme.fg(color, row));\n\t\t}\n\t\tthis.rowsByWidth.set(width, rows);\n\t\treturn rows;\n\t}\n\n\tinvalidate(): void {\n\t\tthis.rowsByWidth.clear();\n\t}\n}\n\n/**\n * Parses the text part the host serialized from this plugin's execute return\n * (capability-runtime-guards normalization): a `TodoState`, optionally with a\n * response-only `warning`. Anything else — a JSON.parse failure or a\n * different shape — returns undefined so the renderer falls back to the raw\n * text.\n */\nfunction parseTodoResultText(text: string): { state: TodoState; warning?: string } | undefined {\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(text);\n\t} catch {\n\t\treturn undefined;\n\t}\n\tif (parsed === null || typeof parsed !== \"object\" || Array.isArray(parsed)) return undefined;\n\tconst record = parsed as { todos?: unknown; warning?: unknown };\n\tif (!Array.isArray(record.todos)) return undefined;\n\tif (record.warning !== undefined && typeof record.warning !== \"string\") return undefined;\n\tconst state: TodoState = { todos: record.todos as TodoRecord[] };\n\treturn record.warning === undefined ? { state } : { state, warning: record.warning };\n}\n\n/**\n * renderResult for todo_update: re-renders the tool's own state payload as\n * the readable listing instead of the host's generic one-line JSON fallback.\n * Collapsed blocks show the summary and record lines only; expanded blocks\n * add the evidence lines; a response `warning` rides along as a final\n * warning-colored line. Non-state payloads and malformed records render\n * verbatim as toolOutput.\n */\nfunction renderTodoResult(\n\tresult: ToolResultLike,\n\toptions: RenderResultOptionsLike,\n\ttheme: ThemeLike,\n\tcontext: RenderContextLike,\n): TodoResultComponent | undefined {\n\tconst text = result.content.find((part) => part.type === \"text\")?.text;\n\tif (text === undefined || text === \"\") return undefined;\n\tconst parsed = parseTodoResultText(text);\n\tlet listing: string;\n\tif (parsed) {\n\t\t// The parse gate is envelope-level, so a parsed state may still hold\n\t\t// malformed records (null elements, a record missing evidence).\n\t\t// Rendering those must not throw out of the plugin: fall back to the\n\t\t// raw text, the same path as a parse failure.\n\t\ttry {\n\t\t\tlisting = renderTodoState(parsed.state, { evidence: options.expanded });\n\t\t\tif (parsed.warning !== undefined) {\n\t\t\t\t// Fold newlines like the record fields so the warning stays one line.\n\t\t\t\tlisting = `${listing}\\nwarning: ${parsed.warning.replace(/\\n/g, \" \")}`;\n\t\t\t}\n\t\t} catch {\n\t\t\tlisting = text;\n\t\t}\n\t} else {\n\t\tlisting = text;\n\t}\n\t// Reuse the host-provided component for this render slot (the ls.ts\n\t// precedent): same instance in, same instance out, with fresh text.\n\tif (context.lastComponent instanceof TodoResultComponent) {\n\t\tcontext.lastComponent.setText(listing);\n\t\treturn context.lastComponent;\n\t}\n\treturn new TodoResultComponent(listing, theme);\n}\n\n/**\n * Whether the session branch's LATEST `plan.state` snapshot knows a plan with\n * the given id (the same latest-snapshot semantics as {@link loadState} and\n * the same advisory pattern as the plan plugin's goalKnownToSession). The\n * check is advisory only (#10): a missing plan downgrades to a warning in the\n * tool response — the soft-reference write path never fails on it.\n */\nfunction planKnownToSession(api: CapabilityAPI, planId: string): boolean {\n\tconst entries = api.session?.getBranchEntries() ?? [];\n\tfor (let index = entries.length - 1; index >= 0; index -= 1) {\n\t\tconst entry = entries[index];\n\t\tif (entry.customType !== planStateEntry) continue;\n\t\tconst data = entry.data;\n\t\tif (!data || typeof data !== \"object\" || Array.isArray(data)) return false;\n\t\tconst plans = (data as { plans?: unknown }).plans;\n\t\tif (!Array.isArray(plans)) return false;\n\t\treturn plans.some(\n\t\t\t(plan) => plan !== null && typeof plan === \"object\" && (plan as { id?: unknown }).id === planId,\n\t\t);\n\t}\n\treturn false;\n}\n\nexport function createCapability(\n\tapi: CapabilityAPI,\n): Promise<readonly DisposableRegistration[]> | readonly DisposableRegistration[] {\n\tlet state = loadState(api);\n\tconst refreshState = (): TodoState => {\n\t\tif (api.session) state = loadState(api);\n\t\treturn state;\n\t};\n\n\tconst persist = async (): Promise<TodoState> => {\n\t\tapi.session?.appendEntry(stateEntry, state);\n\t\tawait api.publish({ type: \"todo.changed\", version: 1, correlationId: stateEntry, data: state });\n\t\treturn state;\n\t};\n\n\tconst tool = api.registerTool({\n\t\tname: \"todo_update\",\n\t\tlabel: \"Update todo\",\n\t\tdescription:\n\t\t\t\"Update a todo that softly references a plan by id. Create with status pending at revision 1, update unfinished items with a higher revision; marking done or cancelled is final and requires evidence, so commit the work first and then complete the todo\",\n\t\tparameters: todoSchema,\n\t\trenderResult: renderTodoResult,\n\t\texecute: async (first: unknown, second?: unknown) => {\n\t\t\trefreshState();\n\t\t\tconst input = objectInput(first, second);\n\t\t\tconst id = text(input.id, \"id\");\n\t\t\tconst planId = text(input.planId, \"planId\");\n\t\t\tconst title = text(input.title, \"title\");\n\t\t\tconst nextRevision = revision(input.revision);\n\t\t\tconst current = state.todos.find((item) => item.id === id);\n\t\t\tif (current && nextRevision <= current.revision) throw new Error(`stale todo revision: ${id}`);\n\t\t\tif (current?.status === \"done\" || current?.status === \"cancelled\") {\n\t\t\t\tthrow new Error(`todo is terminal and cannot be updated: ${id}`);\n\t\t\t}\n\t\t\tconst status =\n\t\t\t\tinput.status === undefined\n\t\t\t\t\t? (current?.status ?? \"pending\")\n\t\t\t\t\t: (text(input.status, \"status\") as TodoRecord[\"status\"]);\n\t\t\tif (![\"pending\", \"done\", \"blocked\", \"cancelled\"].includes(status)) throw new Error(\"invalid todo status\");\n\t\t\tconst values = evidence(input.evidence);\n\t\t\tif (status === \"done\" && values.length === 0) {\n\t\t\t\tthrow new Error(\"todo completion requires at least one evidence reference\");\n\t\t\t}\n\t\t\tif (status === \"cancelled\" && values.length === 0) {\n\t\t\t\tthrow new Error(\"todo cancellation requires at least one evidence reference\");\n\t\t\t}\n\t\t\tconst record: TodoRecord = { id, planId, title, status, revision: nextRevision, evidence: values };\n\t\t\tstate = { ...state, todos: [...state.todos.filter((item) => item.id !== id), record] };\n\t\t\tconst saved = await persist();\n\t\t\tif (planKnownToSession(api, planId)) return saved;\n\t\t\treturn {\n\t\t\t\t...saved,\n\t\t\t\twarning: `planId \"${planId}\" does not match any plan in this session's plan state; the todo keeps the soft reference, but the plan is unknown`,\n\t\t\t};\n\t\t},\n\t});\n\n\tconst command = api.registerCommand({\n\t\tname: \"todo\",\n\t\tdescription: \"Show this session's todos (status and plan reference)\",\n\t\texecute: async (args: string) => {\n\t\t\ttry {\n\t\t\t\tif (args.trim() !== \"\") return { status: \"error\" as const, message: \"Usage: /todo\" };\n\t\t\t\treturn { status: \"success\" as const, message: renderTodoState(refreshState()) };\n\t\t\t} catch (error) {\n\t\t\t\t// A slash command must not crash the host (memory /promote precedent).\n\t\t\t\treturn { status: \"error\" as const, message: error instanceof Error ? error.message : String(error) };\n\t\t\t}\n\t\t},\n\t});\n\n\treturn [tool, command];\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-agent-forge/plugin-todo-set",
3
- "version": "0.88.16",
3
+ "version": "0.88.17",
4
4
  "description": "Todo-set capability plugin for Agent Forge (todo_update state machine over session entries)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "typebox": "1.3.27",
48
- "@ai-agent-forge/plugin-sdk": "^0.88.16"
48
+ "@ai-agent-forge/plugin-sdk": "^0.88.17"
49
49
  },
50
50
  "devDependencies": {
51
51
  "shx": "0.3.4",
package/plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "agent-forge.plugin.todo-set",
3
- "version": "0.88.16",
3
+ "version": "0.88.17",
4
4
  "apiVersion": "1-draft",
5
5
  "entry": "./dist/entry.js",
6
6
  "hostVersion": ">=0.84.4",