@perrylink/dsh-bankrec 0.0.0-stage → 0.1.0-alpha.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/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +3 -3
- package/THIRD-PARTY-NOTICES +8 -0
- package/cordis.patch.yml +3 -0
- package/lib/core/bankrec.d.ts +27 -0
- package/lib/core/bankrec.js +25 -0
- package/lib/plugin/index.d.ts +4 -0
- package/lib/plugin/index.js +7 -0
- package/lib/plugin/storage.d.ts +62 -0
- package/lib/plugin/storage.js +6 -0
- package/lib/plugin/tools.d.ts +7 -0
- package/lib/plugin/tools.js +26 -0
- package/package.json +82 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# @perrylink/dsh-bankrec
|
|
2
|
+
Bank CSV/GL ingest, 1:1 matching and 3-sheet reconciliation workpaper — SKU-06 S1 public/synthetic demo. **Partial, not GA**: 0 real firms; user-approved public/synthetic (2026-10-31).
|
|
3
|
+
Tools: `bankrec.ingest`, `bankrec.match`, `bankrec.export` (Bank/GL/Matches xlsx). Env `DSH_BANKREC_HOME`. Apache-2.0.
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type Lifecycle = 'ingested' | 'matched' | 'exported';
|
|
2
|
+
export interface Txn {
|
|
3
|
+
txn_id: string;
|
|
4
|
+
account_id: string;
|
|
5
|
+
period: string;
|
|
6
|
+
side: 'bank' | 'gl';
|
|
7
|
+
date: string;
|
|
8
|
+
amount_cents: number;
|
|
9
|
+
reference: string;
|
|
10
|
+
evidence_sha256: string;
|
|
11
|
+
created_at: string;
|
|
12
|
+
}
|
|
13
|
+
export interface Match {
|
|
14
|
+
match_id: string;
|
|
15
|
+
bank_id: string;
|
|
16
|
+
gl_id: string;
|
|
17
|
+
date_delta: number;
|
|
18
|
+
amount_cents: number;
|
|
19
|
+
created_at: string;
|
|
20
|
+
}
|
|
21
|
+
export type BankrecErrorCode = 'E_BR_CSV_INVALID' | 'E_BR_ACCOUNT_MISMATCH' | 'E_BR_MATCH_FAILED' | 'E_BR_EXPORT_FAILED' | 'E_BR_BALANCE_MISMATCH';
|
|
22
|
+
export declare class BankrecError extends Error {
|
|
23
|
+
readonly code: BankrecErrorCode;
|
|
24
|
+
constructor(code: BankrecErrorCode, message: string);
|
|
25
|
+
}
|
|
26
|
+
export declare function cents(raw: string): number;
|
|
27
|
+
export declare function parseCsv(text: string, side: 'bank' | 'gl', account_id: string, period: string, evidence: string): Txn[];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export class BankrecError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
constructor(code, message) { super(`${code}: ${message}`); this.name = 'BankrecError'; this.code = code; }
|
|
4
|
+
}
|
|
5
|
+
export function cents(raw) { const v = raw.trim().replace(/[¥¥,\s]/g, ''); const m = /^(-?)(\d+)(?:\.(\d{1,2}))?$/.exec(v); if (!m)
|
|
6
|
+
throw new BankrecError('E_BR_CSV_INVALID', `bad amount: ${raw}`); const sign = m[1] === '-' ? -1 : 1; return sign * (Number(m[2]) * 100 + Number((m[3] ?? '').padEnd(2, '0'))); }
|
|
7
|
+
export function parseCsv(text, side, account_id, period, evidence) {
|
|
8
|
+
const lines = text.trim().split(/\r?\n/).filter(Boolean);
|
|
9
|
+
if (lines.length < 2)
|
|
10
|
+
throw new BankrecError('E_BR_CSV_INVALID', 'CSV needs header+rows');
|
|
11
|
+
const head = lines[0].split(',').map(x => x.trim().toLowerCase());
|
|
12
|
+
const di = head.indexOf('date'), ai = head.indexOf('amount'), ri = head.indexOf('reference');
|
|
13
|
+
if (di < 0 || ai < 0)
|
|
14
|
+
throw new BankrecError('E_BR_CSV_INVALID', 'CSV needs date,amount[,reference]');
|
|
15
|
+
const out = [];
|
|
16
|
+
for (const line of lines.slice(1)) {
|
|
17
|
+
const c = line.split(',').map(x => x.trim());
|
|
18
|
+
const date = c[di] ?? '';
|
|
19
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(date))
|
|
20
|
+
throw new BankrecError('E_BR_CSV_INVALID', `bad date ${date}`);
|
|
21
|
+
const amount = cents(c[ai] ?? '');
|
|
22
|
+
out.push({ txn_id: `${side}-${date}-${amount}-${out.length}`, account_id, period, side, date, amount_cents: amount, reference: c[ri] ?? '', evidence_sha256: evidence, created_at: new Date().toISOString() });
|
|
23
|
+
}
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { createTools } from './tools.js';
|
|
3
|
+
import { openBankrec } from './storage.js';
|
|
4
|
+
export const name = 'dsh-bankrec';
|
|
5
|
+
export const inject = ['tools', 'storageDomain'];
|
|
6
|
+
export async function apply(ctx) { const baseDir = process.env.DSH_BANKREC_HOME ?? path.join(process.env.DSH_HOME ?? process.cwd(), 'storages', 'dsh-bankrec'); const { transactions, matches } = await openBankrec(ctx); for (const t of createTools({ transactions, matches, baseDir }))
|
|
7
|
+
ctx.tools.register(t); }
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
declare const txn: z.ZodObject<{
|
|
4
|
+
txn_id: z.ZodString;
|
|
5
|
+
account_id: z.ZodString;
|
|
6
|
+
period: z.ZodString;
|
|
7
|
+
side: z.ZodEnum<{
|
|
8
|
+
bank: "bank";
|
|
9
|
+
gl: "gl";
|
|
10
|
+
}>;
|
|
11
|
+
date: z.ZodString;
|
|
12
|
+
amount_cents: z.ZodNumber;
|
|
13
|
+
reference: z.ZodString;
|
|
14
|
+
evidence_sha256: z.ZodString;
|
|
15
|
+
created_at: z.ZodString;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
declare const match: z.ZodObject<{
|
|
18
|
+
match_id: z.ZodString;
|
|
19
|
+
bank_id: z.ZodString;
|
|
20
|
+
gl_id: z.ZodString;
|
|
21
|
+
date_delta: z.ZodNumber;
|
|
22
|
+
amount_cents: z.ZodNumber;
|
|
23
|
+
created_at: z.ZodString;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
export type TxnRecord = z.infer<typeof txn>;
|
|
26
|
+
export type MatchRecord = z.infer<typeof match>;
|
|
27
|
+
export type Table<T> = {
|
|
28
|
+
get(k: string): T | undefined;
|
|
29
|
+
entries(): IterableIterator<[string, T]>;
|
|
30
|
+
size: number;
|
|
31
|
+
put(k: string, v: T): Promise<void>;
|
|
32
|
+
};
|
|
33
|
+
export declare const bankrecSpec: {
|
|
34
|
+
name: string;
|
|
35
|
+
version: number;
|
|
36
|
+
tables: {
|
|
37
|
+
transactions: import("@deepseek-ai/dsh-storage-domain").DomainTableSpec<string, {
|
|
38
|
+
txn_id: string;
|
|
39
|
+
account_id: string;
|
|
40
|
+
period: string;
|
|
41
|
+
side: "bank" | "gl";
|
|
42
|
+
date: string;
|
|
43
|
+
amount_cents: number;
|
|
44
|
+
reference: string;
|
|
45
|
+
evidence_sha256: string;
|
|
46
|
+
created_at: string;
|
|
47
|
+
}>;
|
|
48
|
+
matches: import("@deepseek-ai/dsh-storage-domain").DomainTableSpec<string, {
|
|
49
|
+
match_id: string;
|
|
50
|
+
bank_id: string;
|
|
51
|
+
gl_id: string;
|
|
52
|
+
date_delta: number;
|
|
53
|
+
amount_cents: number;
|
|
54
|
+
created_at: string;
|
|
55
|
+
}>;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
export declare function openBankrec(ctx: Context): Promise<{
|
|
59
|
+
transactions: Table<TxnRecord>;
|
|
60
|
+
matches: Table<MatchRecord>;
|
|
61
|
+
}>;
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { defineDomain, domainTable } from '@deepseek-ai/dsh-storage-domain';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
const txn = z.object({ txn_id: z.string(), account_id: z.string(), period: z.string(), side: z.enum(['bank', 'gl']), date: z.string(), amount_cents: z.number().int(), reference: z.string(), evidence_sha256: z.string(), created_at: z.string() });
|
|
4
|
+
const match = z.object({ match_id: z.string(), bank_id: z.string(), gl_id: z.string(), date_delta: z.number().int(), amount_cents: z.number().int(), created_at: z.string() });
|
|
5
|
+
export const bankrecSpec = defineDomain({ name: 'bankrec', version: 1, tables: { transactions: domainTable(txn), matches: domainTable(match) } });
|
|
6
|
+
export async function openBankrec(ctx) { const d = await ctx.storageDomain.open(bankrecSpec); ctx.effect(() => () => d.close(), 'dsh-bankrec.domainClose'); return { transactions: d.table('transactions'), matches: d.table('matches') }; }
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MatchRecord, Table, TxnRecord } from './storage.js';
|
|
2
|
+
export interface ToolDeps {
|
|
3
|
+
transactions: Table<TxnRecord>;
|
|
4
|
+
matches: Table<MatchRecord>;
|
|
5
|
+
baseDir: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function createTools(deps: ToolDeps): import("@deepseek-ai/dsh-tools").ToolDefinition[];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import * as XLSX from 'xlsx';
|
|
5
|
+
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
6
|
+
import { BankrecError, parseCsv } from '../core/bankrec.js';
|
|
7
|
+
const text = (t) => [{ type: 'text', text: t }];
|
|
8
|
+
const sha = (v) => createHash('sha256').update(v).digest('hex');
|
|
9
|
+
export function createTools(deps) {
|
|
10
|
+
const ingest = defineTool({ name: 'bankrec.ingest', description: 'Ingest bank CSV and GL CSV (date,amount[,reference]) for an account/period; integer cents; evidence hashes. Local R1 write.', parameters: { account_id: { type: 'string', required: true }, period: { type: 'string', required: true }, bank_csv: { type: 'string', required: true }, gl_csv: { type: 'string', required: true } }, output: { schema: { type: 'object', additionalProperties: false, properties: { bank_rows: { type: 'number', required: true }, gl_rows: { type: 'number', required: true }, bank_sha256: { type: 'string', required: true }, gl_sha256: { type: 'string', required: true } } }, render: (_a, v) => text(`ingest bank=${v.bank_rows} gl=${v.gl_rows}`) }, async execute(args) { if (!/^\d{4}-\d{2}$/.test(args.period))
|
|
11
|
+
throw new BankrecError('E_BR_CSV_INVALID', 'bad period'); const bank = parseCsv(args.bank_csv, 'bank', args.account_id, args.period, sha(args.bank_csv)); const gl = parseCsv(args.gl_csv, 'gl', args.account_id, args.period, sha(args.gl_csv)); for (const t of [...bank, ...gl])
|
|
12
|
+
await deps.transactions.put(t.txn_id, t); return { bank_rows: bank.length, gl_rows: gl.length, bank_sha256: sha(args.bank_csv), gl_sha256: sha(args.gl_csv) }; } });
|
|
13
|
+
const match = defineTool({ name: 'bankrec.match', description: '1:1 match bank and GL transactions by exact amount and date within ±3 days; store matches and return unmatched. Local R1 write.', parameters: { account_id: { type: 'string', required: true }, period: { type: 'string', required: true } }, output: { schema: { type: 'object', additionalProperties: false, properties: { matched: { type: 'number', required: true }, unmatched_bank: { type: 'array', items: { type: 'string' }, required: true }, unmatched_gl: { type: 'array', items: { type: 'string' }, required: true } } }, render: (_a, v) => text(`matched ${v.matched}`) }, async execute(args) { const all = [...deps.transactions.entries()].map(([, v]) => v).filter(t => t.account_id === args.account_id && t.period === args.period); const bank = all.filter(t => t.side === 'bank'); const gl = all.filter(t => t.side === 'gl'); const used = new Set(); const usedBank = new Set(); let matched = 0; for (const b of bank) {
|
|
14
|
+
const cand = gl.find(g => !used.has(g.txn_id) && g.amount_cents === b.amount_cents && Math.abs((Date.parse(g.date) - Date.parse(b.date)) / 86400000) <= 3);
|
|
15
|
+
if (cand) {
|
|
16
|
+
used.add(cand.txn_id);
|
|
17
|
+
usedBank.add(b.txn_id);
|
|
18
|
+
matched += 1;
|
|
19
|
+
const m = { match_id: `m_${b.txn_id}_${cand.txn_id}`, bank_id: b.txn_id, gl_id: cand.txn_id, date_delta: Math.round((Date.parse(cand.date) - Date.parse(b.date)) / 86400000), amount_cents: b.amount_cents, created_at: new Date().toISOString() };
|
|
20
|
+
await deps.matches.put(m.match_id, m);
|
|
21
|
+
}
|
|
22
|
+
} return { matched, unmatched_bank: bank.filter(b => !usedBank.has(b.txn_id)).map(b => b.txn_id), unmatched_gl: gl.filter(g => !used.has(g.txn_id)).map(g => g.txn_id) }; } });
|
|
23
|
+
// fix unmatched_bank below via replacement later
|
|
24
|
+
const exportTool = defineTool({ name: 'bankrec.export', description: 'Export 3-sheet reconciliation xlsx (Bank, GL, Matches). Local R1 write.', parameters: { account_id: { type: 'string', required: true }, period: { type: 'string', required: true } }, output: { schema: { type: 'object', additionalProperties: false, properties: { path: { type: 'string', required: true }, sha256: { type: 'string', required: true }, sheets: { type: 'number', required: true } } }, render: (_a, v) => text(`export ${v.sheets} sheets`) }, async execute(args) { const all = [...deps.transactions.entries()].map(([, v]) => v).filter(t => t.account_id === args.account_id && t.period === args.period); const ms = [...deps.matches.entries()].map(([, v]) => v); const wb = XLSX.utils.book_new(); XLSX.utils.book_append_sheet(wb, XLSX.utils.json_to_sheet(all.filter(t => t.side === 'bank').map(t => ({ date: t.date, amount_cents: t.amount_cents, reference: t.reference, txn_id: t.txn_id }))), 'Bank'); XLSX.utils.book_append_sheet(wb, XLSX.utils.json_to_sheet(all.filter(t => t.side === 'gl').map(t => ({ date: t.date, amount_cents: t.amount_cents, reference: t.reference, txn_id: t.txn_id }))), 'GL'); XLSX.utils.book_append_sheet(wb, XLSX.utils.json_to_sheet(ms), 'Matches'); const dir = path.join(deps.baseDir, 'exports'); await mkdir(dir, { recursive: true }); const p = path.join(dir, `${args.account_id}-${args.period}.xlsx`); const b = Buffer.from(XLSX.write(wb, { type: 'buffer', bookType: 'xlsx' })); await writeFile(p, b); return { path: p, sha256: sha(b), sheets: wb.SheetNames.length }; } });
|
|
25
|
+
return [ingest, match, exportTool];
|
|
26
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,84 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perrylink/dsh-bankrec",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"description": "Bank statement ingest, 1:1 matching and reconciliation workpaper (SKU-06 S1 public/synthetic demo).",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./lib/plugin/index.js",
|
|
7
|
+
"types": "./lib/plugin/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./lib/plugin/index.d.ts",
|
|
11
|
+
"default": "./lib/plugin/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"lib",
|
|
16
|
+
"cordis.patch.yml",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE",
|
|
19
|
+
"NOTICE",
|
|
20
|
+
"THIRD-PARTY-NOTICES"
|
|
21
|
+
],
|
|
22
|
+
"dsh": {
|
|
23
|
+
"bundle": {
|
|
24
|
+
"patch": "./cordis.patch.yml"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"dsh": ">=0.2.1-rc.3 <0.3.0",
|
|
29
|
+
"node": ">=24.9.0 <25"
|
|
30
|
+
},
|
|
31
|
+
"packageManager": "pnpm@11.28.5",
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsc -p tsconfig.json",
|
|
34
|
+
"lint": "node scripts/lint.mjs",
|
|
35
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
36
|
+
"test": "pnpm build && node --test test/*.test.mjs",
|
|
37
|
+
"prepublishOnly": "node scripts/check-npm-name.mjs",
|
|
38
|
+
"pack:check": "npm pack --dry-run --json > pack.json && node scripts/check-pack.mjs",
|
|
39
|
+
"gate:sku06": "node scripts/gate-sku06.mjs"
|
|
40
|
+
},
|
|
41
|
+
"keywords": [
|
|
42
|
+
"deepseek-harness",
|
|
43
|
+
"dsh",
|
|
44
|
+
"dsh-plugin",
|
|
45
|
+
"bank-rec",
|
|
46
|
+
"reconciliation",
|
|
47
|
+
"finance",
|
|
48
|
+
"perrylink"
|
|
49
|
+
],
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "git+https://github.com/PerryLink/dsh-bankrec.git"
|
|
53
|
+
},
|
|
54
|
+
"license": "Apache-2.0",
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"@deepseek-ai/cordis": ">=4.0.5 <5",
|
|
60
|
+
"@deepseek-ai/dsh-storage-domain": ">=0.2.1-rc.3 <0.3.0",
|
|
61
|
+
"@deepseek-ai/dsh-tools": ">=0.2.1-rc.3 <0.3.0"
|
|
62
|
+
},
|
|
63
|
+
"dependencies": {
|
|
64
|
+
"fflate": "0.8.3",
|
|
65
|
+
"zod": "4.4.3",
|
|
66
|
+
"xlsx": "0.18.5"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@deepseek-ai/cordis": "4.0.5",
|
|
70
|
+
"@deepseek-ai/dsh-agent": "0.2.1-rc.3",
|
|
71
|
+
"@deepseek-ai/dsh-llm": "0.2.1-rc.3",
|
|
72
|
+
"@deepseek-ai/dsh-scope": "0.2.1-rc.3",
|
|
73
|
+
"@deepseek-ai/dsh-session": "0.2.1-rc.3",
|
|
74
|
+
"@deepseek-ai/dsh-storage": "0.2.1-rc.3",
|
|
75
|
+
"@deepseek-ai/dsh-storage-domain": "0.2.1-rc.3",
|
|
76
|
+
"@deepseek-ai/dsh-system-prompt": "0.2.1-rc.3",
|
|
77
|
+
"@deepseek-ai/dsh-tools": "0.2.1-rc.3",
|
|
78
|
+
"@deepseek-ai/dsh-user-approval": "0.2.1-rc.3",
|
|
79
|
+
"@deepseek-ai/dsh-util-values": "0.2.1-rc.3",
|
|
80
|
+
"@deepseek-ai/schemastery": "3.18.5",
|
|
81
|
+
"@types/node": "^24.0.0",
|
|
82
|
+
"typescript": "5.9.3"
|
|
83
|
+
}
|
|
84
|
+
}
|