|
| 1 | +# Client Tools M1 Pending Predicate Implementation Plan |
| 2 | + |
| 3 | +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. |
| 4 | +
|
| 5 | +**Goal:** Extract the duplicated client-tool `pending` predicate into a pure shared `@threadplane/chat` helper without changing adapter behavior. |
| 6 | + |
| 7 | +**Architecture:** Add one pure function in chat's client-tools package that receives plain inputs (`isLoading`, `toolCalls`, `catalogNames`, `resolvedIds`) and returns the same filtered tool-call list both adapters compute today. AG-UI and LangGraph keep their own signals, result application, and transport-specific continuation logic. |
| 8 | + |
| 9 | +**Tech Stack:** TypeScript, Angular computed signals, Vitest, Nx, existing `@threadplane/chat` public API generation. |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## Scope Guard |
| 14 | + |
| 15 | +M1 is spec §6 only. Do not add `settle()`, batching, abort signals, durable stores, max-turn guards, or continuation policy changes. Adapter behavior must remain byte-for-byte equivalent at the observable level: `pending()` is still empty while loading, excludes non-catalog calls, excludes calls with `result !== undefined`, excludes locally resolved ids, and keeps current resolve semantics. |
| 16 | + |
| 17 | +Because `selectPendingClientToolCalls` is exported from `@threadplane/chat`, run `npm run generate-api-docs` and include the generated API docs diff. |
| 18 | + |
| 19 | +## File Structure |
| 20 | + |
| 21 | +- Create: `libs/chat/src/lib/client-tools/select-pending-client-tool-calls.ts` |
| 22 | + - Owns the pure predicate and its input interface. |
| 23 | +- Create: `libs/chat/src/lib/client-tools/select-pending-client-tool-calls.spec.ts` |
| 24 | + - Covers loading, catalog filtering, result filtering, resolved-id filtering, multiple matches, and input immutability expectations. |
| 25 | +- Modify: `libs/chat/src/lib/client-tools/index.ts` |
| 26 | + - Export the helper and input type. |
| 27 | +- Modify: `libs/chat/src/public-api.ts` |
| 28 | + - Re-export the helper from the package public API. |
| 29 | +- Modify: `libs/ag-ui/src/lib/client-tools.ts` |
| 30 | + - Import and use the helper inside the existing `computed`, leaving `catalog` and `resolvedIds` signals local. |
| 31 | +- Modify: `libs/langgraph/src/lib/client-tools.ts` |
| 32 | + - Import and use the helper inside the existing `computed`, leaving `catalog`, `resolvedIds`, and `applyClientResult` local. |
| 33 | +- Generated: website API docs touched by `npm run generate-api-docs`. |
| 34 | + |
| 35 | +## Task 1: Shared Predicate |
| 36 | + |
| 37 | +**Files:** |
| 38 | +- Create: `libs/chat/src/lib/client-tools/select-pending-client-tool-calls.spec.ts` |
| 39 | +- Create: `libs/chat/src/lib/client-tools/select-pending-client-tool-calls.ts` |
| 40 | +- Modify: `libs/chat/src/lib/client-tools/index.ts` |
| 41 | +- Modify: `libs/chat/src/public-api.ts` |
| 42 | + |
| 43 | +- [x] **Step 1: Write the failing shared predicate tests** |
| 44 | + |
| 45 | +Tests should import `selectPendingClientToolCalls` from `./select-pending-client-tool-calls` and assert: |
| 46 | + |
| 47 | +```ts |
| 48 | +expect(selectPendingClientToolCalls({ |
| 49 | + isLoading: true, |
| 50 | + toolCalls: [{ id: 'c1', name: 'get_weather', args: {}, status: 'complete' }], |
| 51 | + catalogNames: new Set(['get_weather']), |
| 52 | + resolvedIds: new Set(), |
| 53 | +})).toEqual([]); |
| 54 | +``` |
| 55 | + |
| 56 | +Also cover catalog mismatch, existing `result`, local `resolvedIds`, multiple included calls, and stable reference behavior for matching tool-call objects. |
| 57 | + |
| 58 | +- [x] **Step 2: Run the red test** |
| 59 | + |
| 60 | +Run: `npx vitest run src/lib/client-tools/select-pending-client-tool-calls.spec.ts --config vite.config.mts` from `libs/chat`. |
| 61 | + |
| 62 | +Expected: fail because the helper file does not exist. |
| 63 | + |
| 64 | +- [x] **Step 3: Implement the pure helper** |
| 65 | + |
| 66 | +Create: |
| 67 | + |
| 68 | +```ts |
| 69 | +export interface SelectPendingClientToolCallsInput { |
| 70 | + isLoading: boolean; |
| 71 | + toolCalls: readonly ToolCall[]; |
| 72 | + catalogNames: ReadonlySet<string>; |
| 73 | + resolvedIds: ReadonlySet<string>; |
| 74 | +} |
| 75 | + |
| 76 | +export function selectPendingClientToolCalls( |
| 77 | + input: SelectPendingClientToolCallsInput, |
| 78 | +): readonly ToolCall[] { |
| 79 | + if (input.isLoading) return []; |
| 80 | + return input.toolCalls.filter( |
| 81 | + (tc) => |
| 82 | + input.catalogNames.has(tc.name) && |
| 83 | + tc.result === undefined && |
| 84 | + !input.resolvedIds.has(tc.id), |
| 85 | + ); |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +- [x] **Step 4: Export the helper** |
| 90 | + |
| 91 | +Export from `libs/chat/src/lib/client-tools/index.ts` and `libs/chat/src/public-api.ts`. |
| 92 | + |
| 93 | +- [x] **Step 5: Run the shared predicate tests** |
| 94 | + |
| 95 | +Run: `npx vitest run src/lib/client-tools/select-pending-client-tool-calls.spec.ts --config vite.config.mts` from `libs/chat`. |
| 96 | + |
| 97 | +Expected: pass. |
| 98 | + |
| 99 | +## Task 2: Adapter Wiring |
| 100 | + |
| 101 | +**Files:** |
| 102 | +- Modify: `libs/ag-ui/src/lib/client-tools.ts` |
| 103 | +- Modify: `libs/langgraph/src/lib/client-tools.ts` |
| 104 | +- Test: `libs/ag-ui/src/lib/client-tools.spec.ts` |
| 105 | +- Test: `libs/langgraph/src/lib/client-tools.spec.ts` |
| 106 | + |
| 107 | +- [x] **Step 1: Replace AG-UI inline predicate** |
| 108 | + |
| 109 | +Inside `pending: computed(() => ...)`, keep building local `catalogNames` and reading local `resolvedIds`, then return `selectPendingClientToolCalls({ isLoading: store.isLoading(), toolCalls: store.toolCalls(), catalogNames, resolvedIds: done })`. |
| 110 | + |
| 111 | +- [x] **Step 2: Run AG-UI focused tests** |
| 112 | + |
| 113 | +Run: `npx vitest run src/lib/client-tools.spec.ts --config vite.config.mts` from `libs/ag-ui`. |
| 114 | + |
| 115 | +Expected: pass with unchanged behavior. |
| 116 | + |
| 117 | +- [x] **Step 3: Replace LangGraph inline predicate** |
| 118 | + |
| 119 | +Inside `const pending = computed(...)`, keep building local `catalogNames` and reading local `resolvedIds`, then return the shared helper. |
| 120 | + |
| 121 | +- [x] **Step 4: Run LangGraph focused tests** |
| 122 | + |
| 123 | +Run: `npx vitest run src/lib/client-tools.spec.ts --config vite.config.mts` from `libs/langgraph`. |
| 124 | + |
| 125 | +Expected: pass with unchanged behavior. |
| 126 | + |
| 127 | +## Task 3: Docs and Verification |
| 128 | + |
| 129 | +**Files:** |
| 130 | +- Generated API docs under `apps/website/content/docs/**` as produced by the repo generator. |
| 131 | + |
| 132 | +- [x] **Step 1: Regenerate API docs** |
| 133 | + |
| 134 | +Run: `npm run generate-api-docs`. |
| 135 | + |
| 136 | +Expected: generated docs include `selectPendingClientToolCalls` and `SelectPendingClientToolCallsInput`. |
| 137 | + |
| 138 | +- [x] **Step 2: Run project tests** |
| 139 | + |
| 140 | +Run: |
| 141 | + |
| 142 | +```bash |
| 143 | +npx nx test chat |
| 144 | +npx nx test ag-ui |
| 145 | +npx nx test langgraph |
| 146 | +``` |
| 147 | + |
| 148 | +Expected: all pass. |
| 149 | + |
| 150 | +- [x] **Step 3: Run lint and count errors** |
| 151 | + |
| 152 | +Run: |
| 153 | + |
| 154 | +```bash |
| 155 | +npx nx lint chat 2>&1 | tee /tmp/threadplane-chat-m1-lint.log; grep -cE ' error ' /tmp/threadplane-chat-m1-lint.log |
| 156 | +npx nx lint ag-ui 2>&1 | tee /tmp/threadplane-ag-ui-m1-lint.log; grep -cE ' error ' /tmp/threadplane-ag-ui-m1-lint.log |
| 157 | +npx nx lint langgraph 2>&1 | tee /tmp/threadplane-langgraph-m1-lint.log; grep -cE ' error ' /tmp/threadplane-langgraph-m1-lint.log |
| 158 | +``` |
| 159 | + |
| 160 | +Expected: each grep count is `0`. |
| 161 | + |
| 162 | +- [x] **Step 4: Diff audit** |
| 163 | + |
| 164 | +Run: |
| 165 | + |
| 166 | +```bash |
| 167 | +git diff --check |
| 168 | +git diff --name-only |
| 169 | +rg -n "hashbrown|copilotkit|chatgpt|claude" libs docs apps/website/content/docs || true |
| 170 | +``` |
| 171 | + |
| 172 | +Expected: no whitespace errors; changed files match M1 scope; forbidden external names are absent from code and generated docs except already-existing design/plan markdown where allowed. |
0 commit comments