@dizzlkheinz/ynab-mcpb 0.16.0 → 0.17.0
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/.code/agents/0098661e-0fa3-4990-beb9-c0cbf3f123aa/status.txt +1 -0
- package/.code/agents/1324/exec-call_tIpx9uV1TpARbAMZonRQm8AO.txt +757 -0
- package/.code/agents/1572/exec-call_GjVFBFOWcY7lE0idc5nWlLNh.txt +781 -0
- package/.code/agents/1846/exec-call_1YNAVD18RjrMN7JnfkkQhUP3.txt +766 -0
- package/.code/agents/1846/exec-call_lh3lDzE4WJAh1lFiomiiZ73D.txt +766 -0
- package/.code/agents/2038/exec-call_DYwOukaYsL8VCONWmV2rUW5u.txt +766 -0
- package/.code/agents/2038/exec-call_c7fOQ7UrpVcTtvdfGBRM146V.txt +652 -0
- package/.code/agents/2038/exec-call_ySNyq9Mm55jWE480s54r5QcA.txt +766 -0
- package/.code/agents/2256/exec-call_AtPcRWPmFPMcmX6qOFm1fCEY.txt +766 -0
- package/.code/agents/2454/exec-call_aFJpupwjfZeOBm7ixI5Vc8z2.txt +766 -0
- package/.code/agents/2454/exec-call_wogZ4HfXTodTEXvdgXlVUBpv.txt +766 -0
- package/.code/agents/2e905864-aa07-4314-bcf9-c5b32277e4ac/result.txt +36 -0
- package/.code/agents/3073/exec-call_Peeagc9DxGYLgE6pNdMZhqIE.txt +766 -0
- package/.code/agents/3073/exec-call_d2YSE3hXF08KRSoUM3qd8Z3x.txt +766 -0
- package/.code/agents/335aa031-466d-4fb7-925f-3cd864e264d0/result.txt +191 -0
- package/.code/agents/3364/exec-call_NbhIrsM5HhyDZDmJZG5CuCYL.txt +766 -0
- package/.code/agents/3364/exec-call_cKtJg0NrXiwXEFwlsE3uPZRA.txt +766 -0
- package/.code/agents/36d98414-5cde-4d9d-9a67-a240a18c1f07/result.txt +189 -0
- package/.code/agents/4604e866-b7b8-44f5-992f-2f683b0a523b/status.txt +1 -0
- package/.code/agents/5f8dc01c-47b3-4163-b0b3-aa31be89fcdc/status.txt +1 -0
- package/.code/agents/7/exec-call_HltHpkDox0Zm1vGEjdksUgpE.txt +1120 -0
- package/.code/agents/7/exec-call_LCATrOPPAgbxW9Q1z0XaVi2E.txt +2646 -0
- package/.code/agents/7/exec-call_W8DeRfNG9hvbgVFvf0clBf6R.txt +2646 -0
- package/.code/agents/94a0ddf3-a304-4ec3-913e-3cceef509948/error.txt +1 -0
- package/.code/agents/e2c752b7-711d-423a-af57-f53c809deb84/result.txt +160 -0
- package/.code/agents/e6601719-c31f-4a0e-8c71-d70787d0ab71/status.txt +1 -0
- package/.code/agents/f250b7ed-5bd5-4036-aa8c-ce63caee7d61/result.txt +20 -0
- package/AGENTS.md +1 -36
- package/CLAUDE.md +131 -51
- package/NUL +0 -1
- package/README.md +27 -14
- package/dist/bundle/index.cjs +41 -41
- package/dist/server/YNABMCPServer.js +28 -381
- package/dist/server/config.d.ts +2 -0
- package/dist/server/config.js +1 -0
- package/dist/tools/accountTools.d.ts +2 -0
- package/dist/tools/accountTools.js +45 -0
- package/dist/tools/adapters.d.ts +12 -0
- package/dist/tools/adapters.js +25 -0
- package/dist/tools/budgetTools.d.ts +2 -0
- package/dist/tools/budgetTools.js +30 -0
- package/dist/tools/categoryTools.d.ts +2 -0
- package/dist/tools/categoryTools.js +45 -0
- package/dist/tools/monthTools.d.ts +2 -0
- package/dist/tools/monthTools.js +32 -0
- package/dist/tools/payeeTools.d.ts +2 -0
- package/dist/tools/payeeTools.js +32 -0
- package/dist/tools/reconciliation/index.d.ts +2 -0
- package/dist/tools/reconciliation/index.js +33 -0
- package/dist/tools/schemas/common.d.ts +3 -0
- package/dist/tools/schemas/common.js +3 -0
- package/dist/tools/schemas/outputs/comparisonOutputs.d.ts +1 -1
- package/dist/tools/transactionTools.d.ts +2 -0
- package/dist/tools/transactionTools.js +129 -0
- package/dist/tools/utilityTools.d.ts +3 -1
- package/dist/tools/utilityTools.js +32 -2
- package/dist/types/index.d.ts +1 -0
- package/dist/types/toolRegistration.d.ts +27 -0
- package/dist/types/toolRegistration.js +1 -0
- package/package.json +2 -2
- package/scripts/run-domain-integration-tests.js +4 -1
- package/src/__tests__/workflows.e2e.test.ts +1 -7
- package/src/server/YNABMCPServer.ts +33 -519
- package/src/server/__tests__/toolRegistration.test.ts +236 -0
- package/src/server/config.ts +1 -0
- package/src/tools/__tests__/adapters.test.ts +113 -0
- package/src/tools/__tests__/transactionTools.test.ts +90 -17
- package/src/tools/__tests__/utilityTools.test.ts +7 -7
- package/src/tools/accountTools.ts +53 -0
- package/src/tools/adapters.ts +74 -0
- package/src/tools/budgetTools.ts +37 -0
- package/src/tools/categoryTools.ts +53 -0
- package/src/tools/monthTools.ts +39 -0
- package/src/tools/payeeTools.ts +39 -0
- package/src/tools/reconciliation/index.ts +45 -0
- package/src/tools/schemas/common.ts +18 -0
- package/src/tools/transactionTools.ts +150 -0
- package/src/tools/utilityTools.ts +42 -2
- package/src/types/index.ts +3 -0
- package/src/types/toolRegistration.ts +88 -0
- package/.dxtignore +0 -57
- package/.github/workflows/pr-description-check.yml +0 -88
- package/CODEREVIEW_RESPONSE.md +0 -128
- package/SCHEMA_IMPROVEMENT_SUMMARY.md +0 -120
- package/TESTING_NOTES.md +0 -217
- package/accountactivity-merged.csv +0 -149
- package/bundle-analysis.html +0 -13110
- package/docs/README.md +0 -72
- package/docs/getting-started/CONFIGURATION.md +0 -175
- package/docs/getting-started/INSTALLATION.md +0 -333
- package/docs/getting-started/QUICKSTART.md +0 -282
- package/docs/guides/ARCHITECTURE.md +0 -533
- package/docs/guides/DEPLOYMENT.md +0 -189
- package/docs/guides/INTEGRATION_TESTING.md +0 -730
- package/docs/guides/TESTING.md +0 -591
- package/docs/plans/2025-11-20-reloadable-config-token-validation.md +0 -93
- package/docs/plans/2025-11-21-fix-transaction-cached-property.md +0 -362
- package/docs/plans/2025-11-21-reconciliation-error-handling.md +0 -90
- package/docs/plans/2025-11-21-v014-hardening.md +0 -153
- package/docs/plans/reconciliation-v2-redesign.md +0 -1571
- package/docs/reconciliation-flow.md +0 -83
- package/docs/reference/EXAMPLES.md +0 -946
- package/docs/reference/TOOLS.md +0 -348
- package/docs/reference/TROUBLESHOOTING.md +0 -481
- package/fix-types.sh +0 -17
- package/test-csv-sample.csv +0 -28
- package/test-exports/sample_bank_statement.csv +0 -7
- package/test-reconcile-autodetect.js +0 -40
- package/test-reconcile-tool.js +0 -152
- package/test-reconcile-with-csv.cjs +0 -89
- package/test-statement.csv +0 -8
- package/test_debug.js +0 -47
- package/test_mcp_tools.mjs +0 -75
- package/test_simple.mjs +0 -16
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Type definitions for the tool factory registration pattern.
|
|
3
|
+
* Provides ToolContext for dependency injection and typed handler signatures
|
|
4
|
+
* used by domain-specific tool factory functions.
|
|
5
|
+
* @module types/toolRegistration
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
9
|
+
import * as ynab from 'ynab';
|
|
10
|
+
import type {
|
|
11
|
+
ToolRegistry,
|
|
12
|
+
ToolExecutionPayload,
|
|
13
|
+
DefaultArgumentResolver,
|
|
14
|
+
} from '../server/toolRegistry.js';
|
|
15
|
+
import type { DeltaFetcher } from '../tools/deltaFetcher.js';
|
|
16
|
+
import type { DeltaCache } from '../server/deltaCache.js';
|
|
17
|
+
import type { ServerKnowledgeStore } from '../server/serverKnowledgeStore.js';
|
|
18
|
+
import type { DiagnosticManager } from '../server/diagnostics.js';
|
|
19
|
+
import type { CacheManager } from '../server/cacheManager.js';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Context object passed to tool factory functions. Contains the dependencies
|
|
23
|
+
* required by tool adapters and handlers.
|
|
24
|
+
*
|
|
25
|
+
* @stable This interface is part of the public tool registration contract.
|
|
26
|
+
* Changes to this interface may affect all domain tool factories.
|
|
27
|
+
*/
|
|
28
|
+
export interface ToolContext {
|
|
29
|
+
ynabAPI: ynab.API;
|
|
30
|
+
deltaFetcher: DeltaFetcher;
|
|
31
|
+
deltaCache: DeltaCache;
|
|
32
|
+
serverKnowledgeStore: ServerKnowledgeStore;
|
|
33
|
+
getDefaultBudgetId: () => string | undefined;
|
|
34
|
+
setDefaultBudget: (budgetId: string) => void;
|
|
35
|
+
cacheManager: CacheManager;
|
|
36
|
+
diagnosticManager?: DiagnosticManager;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Factory function signature for registering a domain's tools.
|
|
41
|
+
*/
|
|
42
|
+
export type ToolFactory = (registry: ToolRegistry, context: ToolContext) => void;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Common adapter signature used within tool factories.
|
|
46
|
+
*/
|
|
47
|
+
export type Adapter<TInput extends Record<string, unknown>> = (
|
|
48
|
+
payload: ToolExecutionPayload<TInput>,
|
|
49
|
+
) => Promise<CallToolResult>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Generic handler signature used by adapter helpers.
|
|
53
|
+
*/
|
|
54
|
+
export type Handler<TInput extends Record<string, unknown>> = (
|
|
55
|
+
api: ynab.API,
|
|
56
|
+
params: TInput,
|
|
57
|
+
) => Promise<CallToolResult>;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Handler signature for operations that require delta fetching.
|
|
61
|
+
*/
|
|
62
|
+
export type DeltaHandler<TInput extends Record<string, unknown>> = (
|
|
63
|
+
api: ynab.API,
|
|
64
|
+
deltaFetcher: DeltaFetcher,
|
|
65
|
+
params: TInput,
|
|
66
|
+
) => Promise<CallToolResult>;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Handler signature for write operations that update caches and knowledge stores.
|
|
70
|
+
*/
|
|
71
|
+
export type WriteHandler<TInput extends Record<string, unknown>> = (
|
|
72
|
+
api: ynab.API,
|
|
73
|
+
deltaCache: DeltaCache,
|
|
74
|
+
serverKnowledgeStore: ServerKnowledgeStore,
|
|
75
|
+
params: TInput,
|
|
76
|
+
) => Promise<CallToolResult>;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Handler signature for tools that do not accept input parameters.
|
|
80
|
+
*/
|
|
81
|
+
export type NoInputHandler = (api: ynab.API) => Promise<CallToolResult>;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Helper type for default argument resolver factories.
|
|
85
|
+
*/
|
|
86
|
+
export type BudgetIdResolverFactory = <
|
|
87
|
+
TInput extends { budget_id?: string | undefined },
|
|
88
|
+
>() => DefaultArgumentResolver<TInput>;
|
package/.dxtignore
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
node_modules/
|
|
2
|
-
src/
|
|
3
|
-
**/__tests__/
|
|
4
|
-
**/*.test.*
|
|
5
|
-
coverage/
|
|
6
|
-
*.log
|
|
7
|
-
.*/
|
|
8
|
-
**/*.map
|
|
9
|
-
tsconfig*.json
|
|
10
|
-
vitest.config.ts
|
|
11
|
-
vitest-reporters/
|
|
12
|
-
eslint.config.js
|
|
13
|
-
test-results.json
|
|
14
|
-
test-results/
|
|
15
|
-
README.md
|
|
16
|
-
|
|
17
|
-
# Sensitive credential files
|
|
18
|
-
.chunkhound.json
|
|
19
|
-
.mcp.json
|
|
20
|
-
.env*
|
|
21
|
-
|
|
22
|
-
# Build metadata
|
|
23
|
-
meta.json
|
|
24
|
-
bundle-analysis.html
|
|
25
|
-
|
|
26
|
-
# Development-only markdown files
|
|
27
|
-
AGENTS.md
|
|
28
|
-
TESTING_NOTES.md
|
|
29
|
-
CODEREVIEW_RESPONSE.md
|
|
30
|
-
SCHEMA_IMPROVEMENT_SUMMARY.md
|
|
31
|
-
|
|
32
|
-
# Test files and data
|
|
33
|
-
test_*.js
|
|
34
|
-
test_*.mjs
|
|
35
|
-
test-*.js
|
|
36
|
-
test-*.cjs
|
|
37
|
-
test-*.csv
|
|
38
|
-
test-exports/
|
|
39
|
-
accountactivity-merged.csv
|
|
40
|
-
|
|
41
|
-
# Temporary and development files
|
|
42
|
-
temp/
|
|
43
|
-
tmp/
|
|
44
|
-
fix-types.sh
|
|
45
|
-
NUL
|
|
46
|
-
package-lock.json
|
|
47
|
-
|
|
48
|
-
# Development plans (keep user-facing docs)
|
|
49
|
-
docs/plans/
|
|
50
|
-
docs/bulk-transaction-operations-plan.md
|
|
51
|
-
docs/delta-request-plan.md
|
|
52
|
-
docs/reconciliation-flow.md
|
|
53
|
-
|
|
54
|
-
# Scripts (not needed for distribution)
|
|
55
|
-
scripts/
|
|
56
|
-
|
|
57
|
-
# keep dist/, manifest.json, CHANGELOG.md, CLAUDE.md, LICENSE, docs/ (except plans)
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
name: PR Description Check
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
pull_request:
|
|
5
|
-
types: [opened, edited, synchronize]
|
|
6
|
-
|
|
7
|
-
permissions:
|
|
8
|
-
contents: read
|
|
9
|
-
issues: write
|
|
10
|
-
pull-requests: read
|
|
11
|
-
|
|
12
|
-
jobs:
|
|
13
|
-
check-description:
|
|
14
|
-
runs-on: ubuntu-latest
|
|
15
|
-
steps:
|
|
16
|
-
- name: Check PR Description Format
|
|
17
|
-
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
|
|
18
|
-
with:
|
|
19
|
-
script: |
|
|
20
|
-
const body = context.payload.pull_request.body || '';
|
|
21
|
-
|
|
22
|
-
// Required sections from template
|
|
23
|
-
const requiredSections = [
|
|
24
|
-
'Type of change',
|
|
25
|
-
'Public API surface checklist',
|
|
26
|
-
'Versioning and release'
|
|
27
|
-
];
|
|
28
|
-
|
|
29
|
-
const missingSections = requiredSections.filter(section =>
|
|
30
|
-
!body.includes(section)
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
if (missingSections.length > 0) {
|
|
34
|
-
// Build comment as array to avoid YAML indentation issues
|
|
35
|
-
const commentLines = [
|
|
36
|
-
'⚠️ **PR Description Check Failed**',
|
|
37
|
-
'',
|
|
38
|
-
'The PR description is missing required sections from the template:',
|
|
39
|
-
...missingSections.map(s => `- ${s}`),
|
|
40
|
-
'',
|
|
41
|
-
'Please update the description to include these sections. You can view the template at:',
|
|
42
|
-
`https://github.com/${context.repo.owner}/${context.repo.repo}/blob/master/.github/pull_request_template.md`,
|
|
43
|
-
'',
|
|
44
|
-
'Or run this command to update it:',
|
|
45
|
-
'```bash',
|
|
46
|
-
`gh pr edit ${context.payload.pull_request.number} --body-file .github/pull_request_template.md`,
|
|
47
|
-
'```'
|
|
48
|
-
];
|
|
49
|
-
const comment = commentLines.join('\n');
|
|
50
|
-
|
|
51
|
-
// Upsert comment: update existing bot comment or create new one
|
|
52
|
-
const botCommentPrefix = '⚠️ **PR Description Check Failed**';
|
|
53
|
-
// Paginate through all comments to handle PRs with >30 comments
|
|
54
|
-
const comments = await github.paginate(
|
|
55
|
-
github.rest.issues.listComments,
|
|
56
|
-
{
|
|
57
|
-
owner: context.repo.owner,
|
|
58
|
-
repo: context.repo.repo,
|
|
59
|
-
issue_number: context.payload.pull_request.number,
|
|
60
|
-
per_page: 100
|
|
61
|
-
}
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
const existingComment = comments.find(
|
|
65
|
-
c => c.user.type === 'Bot' && c.body.startsWith(botCommentPrefix)
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
if (existingComment) {
|
|
69
|
-
await github.rest.issues.updateComment({
|
|
70
|
-
owner: context.repo.owner,
|
|
71
|
-
repo: context.repo.repo,
|
|
72
|
-
comment_id: existingComment.id,
|
|
73
|
-
body: comment
|
|
74
|
-
});
|
|
75
|
-
} else {
|
|
76
|
-
await github.rest.issues.createComment({
|
|
77
|
-
owner: context.repo.owner,
|
|
78
|
-
repo: context.repo.repo,
|
|
79
|
-
issue_number: context.payload.pull_request.number,
|
|
80
|
-
body: comment
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Fail the check
|
|
85
|
-
core.setFailed(`Missing required sections: ${missingSections.join(', ')}`);
|
|
86
|
-
} else {
|
|
87
|
-
console.log('✅ All required sections present in PR description');
|
|
88
|
-
}
|
package/CODEREVIEW_RESPONSE.md
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
# Code Review Response: reconciliationOutputs.ts
|
|
2
|
-
|
|
3
|
-
## Summary
|
|
4
|
-
|
|
5
|
-
CodeRabbit provided two suggestions for improving `src/tools/schemas/outputs/reconciliationOutputs.ts`. After technical analysis of the codebase, I've determined:
|
|
6
|
-
|
|
7
|
-
1. **Feedback #1 (ExecutionActionRecordSchema typing)**: Already implemented ✅
|
|
8
|
-
2. **Feedback #2 (discrepancy_direction validation)**: Not implementing - technically sound but violates architectural principles ❌
|
|
9
|
-
|
|
10
|
-
## Feedback #1: Stronger Typing for Transaction Field
|
|
11
|
-
|
|
12
|
-
**Suggestion:** Use discriminated unions instead of `z.record(z.string(), z.unknown())` for the transaction field in `ExecutionActionRecordSchema`.
|
|
13
|
-
|
|
14
|
-
**Status:** ✅ **Already Implemented**
|
|
15
|
-
|
|
16
|
-
### Analysis
|
|
17
|
-
|
|
18
|
-
The CodeRabbit feedback appears to be outdated. The current implementation (lines 431-479) already uses a discriminated union with strong typing:
|
|
19
|
-
|
|
20
|
-
```typescript
|
|
21
|
-
export const ExecutionActionRecordSchema = z.discriminatedUnion('type', [
|
|
22
|
-
// Successful transaction creation
|
|
23
|
-
z.object({
|
|
24
|
-
type: z.literal('create_transaction'),
|
|
25
|
-
transaction: CreatedTransactionSchema.nullable(),
|
|
26
|
-
// ...
|
|
27
|
-
}),
|
|
28
|
-
// Failed transaction creation
|
|
29
|
-
z.object({
|
|
30
|
-
type: z.literal('create_transaction_failed'),
|
|
31
|
-
transaction: TransactionCreationPayloadSchema,
|
|
32
|
-
// ...
|
|
33
|
-
}),
|
|
34
|
-
// ... other action types
|
|
35
|
-
]);
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
Each action type has its own specific schema:
|
|
39
|
-
|
|
40
|
-
- `CreatedTransactionSchema` - for successful creations (line 371)
|
|
41
|
-
- `TransactionCreationPayloadSchema` - for failed/dry-run creations (line 387)
|
|
42
|
-
- `TransactionUpdatePayloadSchema` - for status/date changes (line 402)
|
|
43
|
-
- `DuplicateDetectionPayloadSchema` - for duplicate detection (line 412)
|
|
44
|
-
|
|
45
|
-
This provides full type safety without the drawbacks of loose typing.
|
|
46
|
-
|
|
47
|
-
## Feedback #2: Validate discrepancy_direction Against Actual Discrepancy
|
|
48
|
-
|
|
49
|
-
**Suggestion:** Add a Zod refinement to ensure `discrepancy_direction` matches the sign of `balance.discrepancy.amount`.
|
|
50
|
-
|
|
51
|
-
**Status:** ❌ **Not Implementing**
|
|
52
|
-
|
|
53
|
-
### Analysis
|
|
54
|
-
|
|
55
|
-
While technically correct, this validation violates architectural principles and provides minimal benefit:
|
|
56
|
-
|
|
57
|
-
#### Current Implementation (reconcileAdapter.ts:122-135)
|
|
58
|
-
|
|
59
|
-
The `convertBalanceInfo` function deterministically derives `discrepancy_direction` from `discrepancyMilli`:
|
|
60
|
-
|
|
61
|
-
```typescript
|
|
62
|
-
const convertBalanceInfo = (analysis: ReconciliationAnalysis) => {
|
|
63
|
-
const discrepancyMilli = analysis.balance_info.discrepancy.value_milliunits;
|
|
64
|
-
const direction =
|
|
65
|
-
discrepancyMilli === 0 ? 'balanced' : discrepancyMilli > 0 ? 'ynab_higher' : 'bank_higher';
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
current_cleared: analysis.balance_info.current_cleared,
|
|
69
|
-
// ...
|
|
70
|
-
discrepancy: analysis.balance_info.discrepancy,
|
|
71
|
-
discrepancy_direction: direction,
|
|
72
|
-
on_track: analysis.balance_info.on_track,
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
This logic is:
|
|
78
|
-
|
|
79
|
-
- **Simple and obvious**: Direct mapping from sign to direction
|
|
80
|
-
- **Well-tested**: Part of the adapter layer
|
|
81
|
-
- **Single point of truth**: Consistency enforced at construction time
|
|
82
|
-
|
|
83
|
-
#### Why Not Add Schema Validation?
|
|
84
|
-
|
|
85
|
-
1. **Violates Single Responsibility Principle**
|
|
86
|
-
The schema's job is to validate structure, not business logic consistency. The adapter already enforces this invariant at construction time.
|
|
87
|
-
|
|
88
|
-
2. **Adds Runtime Overhead**
|
|
89
|
-
Schema validation runs on every payload validation. This adds unnecessary computation for a condition that should never occur if the adapter works correctly.
|
|
90
|
-
|
|
91
|
-
3. **Couples Schema to Business Logic**
|
|
92
|
-
The schema would need to know the thresholds and logic for determining direction. This creates tight coupling between layers that should be independent.
|
|
93
|
-
|
|
94
|
-
4. **Limited Bug Detection Value**
|
|
95
|
-
If the adapter logic is broken, we'd want to fix the adapter, not catch it at validation time. Schema validation wouldn't prevent the bug, just detect it later in the pipeline.
|
|
96
|
-
|
|
97
|
-
5. **Test Coverage Sufficient**
|
|
98
|
-
The adapter has comprehensive test coverage. Adding redundant validation at the schema level doesn't improve reliability.
|
|
99
|
-
|
|
100
|
-
### Alternative Considered
|
|
101
|
-
|
|
102
|
-
If we were truly concerned about this invariant, the better approach would be:
|
|
103
|
-
|
|
104
|
-
1. Add unit tests specifically for the `convertBalanceInfo` function
|
|
105
|
-
2. Add integration tests that verify the full payload structure
|
|
106
|
-
3. Add a comment in the schema documenting the expected relationship
|
|
107
|
-
|
|
108
|
-
But given the simplicity of the current implementation and existing test coverage, none of these are necessary.
|
|
109
|
-
|
|
110
|
-
### Recommendation
|
|
111
|
-
|
|
112
|
-
**Accept Feedback #1 as already implemented.**
|
|
113
|
-
**Respectfully decline Feedback #2** - the adapter already enforces consistency, and adding schema-level validation would violate architectural principles without meaningful benefit.
|
|
114
|
-
|
|
115
|
-
---
|
|
116
|
-
|
|
117
|
-
## Files Changed
|
|
118
|
-
|
|
119
|
-
- `src/tools/schemas/outputs/reconciliationOutputs.ts` - No changes required (already has strong typing)
|
|
120
|
-
- `CODEREVIEW_RESPONSE.md` - This document
|
|
121
|
-
|
|
122
|
-
## Tests
|
|
123
|
-
|
|
124
|
-
All existing tests pass:
|
|
125
|
-
|
|
126
|
-
- ✅ `npm run type-check` - TypeScript compilation successful
|
|
127
|
-
- ✅ `npm run test:unit -- reconciliationOutputs` - 26/26 tests passing
|
|
128
|
-
- ✅ No regressions in related tests
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
# ExecutionActionRecord Schema Type Safety Improvements
|
|
2
|
-
|
|
3
|
-
## Summary
|
|
4
|
-
|
|
5
|
-
Addressed CodeRabbit's feedback about weak typing in `ExecutionActionRecordSchema` by replacing the generic `z.record(z.string(), z.unknown())` transaction field with a discriminated union based on action type.
|
|
6
|
-
|
|
7
|
-
## Problem
|
|
8
|
-
|
|
9
|
-
The original schema at line 370 in `reconciliationOutputs.ts` used:
|
|
10
|
-
|
|
11
|
-
```typescript
|
|
12
|
-
export const ExecutionActionRecordSchema = z.object({
|
|
13
|
-
type: z.string(),
|
|
14
|
-
transaction: z.record(z.string(), z.unknown()).nullable(),
|
|
15
|
-
// ...
|
|
16
|
-
});
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
This provided no type safety for transaction data, making the code prone to runtime errors if assumptions about transaction structure were incorrect.
|
|
20
|
-
|
|
21
|
-
## Solution
|
|
22
|
-
|
|
23
|
-
Implemented a **discriminated union** based on the `type` field, with each action type having its own strongly-typed transaction schema:
|
|
24
|
-
|
|
25
|
-
### Action Types & Transaction Schemas
|
|
26
|
-
|
|
27
|
-
1. **`create_transaction`** - Successful transaction creation
|
|
28
|
-
- Transaction: `CreatedTransactionSchema.nullable()`
|
|
29
|
-
- Full YNAB API transaction response with `.passthrough()` for additional fields
|
|
30
|
-
- Optional fields: `bulk_chunk_index`, `correlation_key`
|
|
31
|
-
|
|
32
|
-
2. **`create_transaction_failed`** - Failed transaction creation
|
|
33
|
-
- Transaction: `TransactionCreationPayloadSchema` (required)
|
|
34
|
-
- The request payload that failed to create
|
|
35
|
-
- Optional fields: `bulk_chunk_index`, `correlation_key`
|
|
36
|
-
|
|
37
|
-
3. **`create_transaction_duplicate`** - Duplicate detection
|
|
38
|
-
- Transaction: `DuplicateDetectionPayloadSchema` (required)
|
|
39
|
-
- Contains `transaction_id` (nullable) and optional `import_id`
|
|
40
|
-
- Required fields: `bulk_chunk_index`, `duplicate: true`
|
|
41
|
-
- Optional: `correlation_key`
|
|
42
|
-
|
|
43
|
-
4. **`update_transaction`** - Transaction update (status/date)
|
|
44
|
-
- Transaction: Union of `CreatedTransactionSchema.nullable()` (real execution) or `TransactionUpdatePayloadSchema` (dry run)
|
|
45
|
-
- Handles both full transaction responses and minimal update payloads
|
|
46
|
-
|
|
47
|
-
5. **`balance_checkpoint`** - Balance alignment checkpoint
|
|
48
|
-
- Transaction: `z.null()` (always null)
|
|
49
|
-
- No optional fields
|
|
50
|
-
|
|
51
|
-
6. **`bulk_create_fallback`** - Bulk operation fallback to sequential
|
|
52
|
-
- Transaction: `z.null()` (always null)
|
|
53
|
-
- Required: `bulk_chunk_index`
|
|
54
|
-
|
|
55
|
-
### Helper Schemas
|
|
56
|
-
|
|
57
|
-
**`CreatedTransactionSchema`**
|
|
58
|
-
|
|
59
|
-
- Validates YNAB API transaction responses
|
|
60
|
-
- Uses `.passthrough()` to allow additional API fields
|
|
61
|
-
- Required: `id`, `date`, `amount`
|
|
62
|
-
- Optional: `memo`, `cleared`, `approved`, `payee_name`, `category_name`, `import_id`
|
|
63
|
-
|
|
64
|
-
**`TransactionCreationPayloadSchema`**
|
|
65
|
-
|
|
66
|
-
- Validates transaction creation requests
|
|
67
|
-
- Required: `account_id`, `date`, `amount`
|
|
68
|
-
- Optional: `payee_name`, `memo`, `cleared`, `approved`, `import_id`
|
|
69
|
-
|
|
70
|
-
**`TransactionUpdatePayloadSchema`**
|
|
71
|
-
|
|
72
|
-
- Validates transaction update requests
|
|
73
|
-
- Required: `transaction_id`
|
|
74
|
-
- Optional: `new_date`, `cleared`
|
|
75
|
-
|
|
76
|
-
**`DuplicateDetectionPayloadSchema`**
|
|
77
|
-
|
|
78
|
-
- Validates duplicate detection metadata
|
|
79
|
-
- Required: `transaction_id` (nullable)
|
|
80
|
-
- Optional: `import_id`
|
|
81
|
-
|
|
82
|
-
## Benefits
|
|
83
|
-
|
|
84
|
-
1. **Type Safety** - Compile-time checking of transaction field structure
|
|
85
|
-
2. **Self-Documenting** - Schema clearly shows what data each action type contains
|
|
86
|
-
3. **Runtime Validation** - Zod catches malformed data before it causes issues
|
|
87
|
-
4. **Better Errors** - Discriminated union provides clear validation error messages
|
|
88
|
-
5. **Flexibility** - `.passthrough()` on `CreatedTransactionSchema` allows future YNAB API additions
|
|
89
|
-
6. **Zero Breaking Changes** - Backward compatible, all existing data validates correctly
|
|
90
|
-
|
|
91
|
-
## Testing
|
|
92
|
-
|
|
93
|
-
Created comprehensive test suite (`reconciliationOutputs.test.ts`) with 26 passing tests covering:
|
|
94
|
-
|
|
95
|
-
- All 6 action types with valid data
|
|
96
|
-
- Negative cases (wrong types, missing required fields)
|
|
97
|
-
- Discriminated union behavior (unknown types, type mismatches)
|
|
98
|
-
- Helper schema validation
|
|
99
|
-
- Edge cases (null transactions, passthrough fields)
|
|
100
|
-
|
|
101
|
-
## Files Changed
|
|
102
|
-
|
|
103
|
-
1. `src/tools/schemas/outputs/reconciliationOutputs.ts` - Schema definitions
|
|
104
|
-
2. `src/tools/schemas/outputs/__tests__/reconciliationOutputs.test.ts` - New test suite
|
|
105
|
-
|
|
106
|
-
## Verification
|
|
107
|
-
|
|
108
|
-
- ✅ TypeScript compilation passes (`npm run type-check`)
|
|
109
|
-
- ✅ All 26 new schema tests pass
|
|
110
|
-
- ✅ Build succeeds (`npm run build`)
|
|
111
|
-
- ✅ MCPB package generation succeeds
|
|
112
|
-
- ✅ No runtime changes to executor.ts needed (schemas match actual usage)
|
|
113
|
-
|
|
114
|
-
## Implementation Notes
|
|
115
|
-
|
|
116
|
-
The discriminated union matches exactly how the executor currently constructs action records (verified by analyzing `src/tools/reconciliation/executor.ts` lines 226-580). No changes to runtime code were needed, proving this is a pure type-safety enhancement.
|
|
117
|
-
|
|
118
|
-
## Follow-up Opportunities
|
|
119
|
-
|
|
120
|
-
Consider applying the same pattern to other schemas with generic `z.record()` fields if similar type safety concerns exist elsewhere in the codebase.
|