@spekra.in/agent-os 0.0.0-stage → 1.0.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/Booker/README.md +41 -0
- package/Booker/package.json +11 -0
- package/Booker/src/agent.js +15 -0
- package/Booker/src/calendar-adapter.js +75 -0
- package/Booker/src/index.js +4 -0
- package/Booker/src/intake-parser.js +96 -0
- package/Booker/src/validation.js +34 -0
- package/Booker/test/booker.test.js +35 -0
- package/CashHound/README.md +181 -0
- package/CashHound/package.json +21 -0
- package/CashHound/src/agent.js +621 -0
- package/CashHound/src/bank-reconciler.js +66 -0
- package/CashHound/src/dunning.js +380 -0
- package/CashHound/src/index.js +32 -0
- package/CashHound/src/invoice.js +371 -0
- package/CashHound/src/mobile.js +35 -0
- package/CashHound/src/npv-optimizer.js +259 -0
- package/CashHound/test/advanced.test.js +44 -0
- package/CashHound/test/cashhound.test.js +530 -0
- package/CashHound/test/mobile.test.js +25 -0
- package/CashHound/test/security.test.js +35 -0
- package/Clerk/README.md +30 -0
- package/Clerk/package.json +11 -0
- package/Clerk/src/agent.js +18 -0
- package/Clerk/src/index.js +2 -0
- package/Clerk/src/reconciliation.js +52 -0
- package/Clerk/test/clerk.test.js +39 -0
- package/LocalRoar/README.md +37 -0
- package/LocalRoar/package.json +13 -0
- package/LocalRoar/src/agent.js +70 -0
- package/LocalRoar/src/booking-router.js +74 -0
- package/LocalRoar/src/feedback-interceptor.js +47 -0
- package/LocalRoar/src/index.js +7 -0
- package/LocalRoar/src/lead-engine.js +52 -0
- package/LocalRoar/src/mobile.js +23 -0
- package/LocalRoar/src/review-booster.js +24 -0
- package/LocalRoar/src/route-density.js +46 -0
- package/LocalRoar/test/advanced.test.js +41 -0
- package/LocalRoar/test/localroar.test.js +59 -0
- package/LocalRoar/test/mobile.test.js +12 -0
- package/OmniLife/README.md +39 -0
- package/OmniLife/package.json +13 -0
- package/OmniLife/src/agent.js +47 -0
- package/OmniLife/src/bill-negotiator.js +43 -0
- package/OmniLife/src/browser-cancel.js +28 -0
- package/OmniLife/src/conflict-engine.js +49 -0
- package/OmniLife/src/index.js +6 -0
- package/OmniLife/src/mobile.js +18 -0
- package/OmniLife/src/subscription-manager.js +66 -0
- package/OmniLife/test/advanced.test.js +29 -0
- package/OmniLife/test/mobile.test.js +12 -0
- package/OmniLife/test/omnilife.test.js +71 -0
- package/PulseMD/README.md +42 -0
- package/PulseMD/package.json +13 -0
- package/PulseMD/src/agent.js +67 -0
- package/PulseMD/src/ambient-scribe.js +46 -0
- package/PulseMD/src/auth.js +63 -0
- package/PulseMD/src/charting.js +54 -0
- package/PulseMD/src/index.js +7 -0
- package/PulseMD/src/mobile.js +18 -0
- package/PulseMD/src/prior-auth.js +39 -0
- package/PulseMD/src/safety-guard.js +88 -0
- package/PulseMD/test/advanced.test.js +50 -0
- package/PulseMD/test/mobile.test.js +12 -0
- package/PulseMD/test/pulsemd.test.js +71 -0
- package/README.md +203 -2
- package/ResolveX/README.md +274 -0
- package/ResolveX/package.json +20 -0
- package/ResolveX/src/agent.js +679 -0
- package/ResolveX/src/carrier-listener.js +405 -0
- package/ResolveX/src/diagnosis.js +315 -0
- package/ResolveX/src/index.js +36 -0
- package/ResolveX/src/mobile.js +31 -0
- package/ResolveX/src/policy.js +325 -0
- package/ResolveX/src/vision.js +384 -0
- package/ResolveX/test/advanced.test.js +445 -0
- package/ResolveX/test/mobile.test.js +15 -0
- package/ResolveX/test/resolvex.test.js +428 -0
- package/SentinelMesh/README.md +51 -0
- package/SentinelMesh/package.json +13 -0
- package/SentinelMesh/src/governor.js +61 -0
- package/SentinelMesh/src/index.js +4 -0
- package/SentinelMesh/src/mobile.js +19 -0
- package/SentinelMesh/src/policy.js +63 -0
- package/SentinelMesh/src/sandbox.js +152 -0
- package/SentinelMesh/test/mobile.test.js +12 -0
- package/SentinelMesh/test/sentinel.test.js +135 -0
- package/Sidekick/README.md +43 -0
- package/Sidekick/package.json +11 -0
- package/Sidekick/src/agent.js +15 -0
- package/Sidekick/src/evidence.js +45 -0
- package/Sidekick/src/index.js +3 -0
- package/Sidekick/src/validation.js +15 -0
- package/Sidekick/test/sidekick.test.js +33 -0
- package/agent-os-mobile/README.md +26 -0
- package/agent-os-mobile/src/api.js +97 -0
- package/agent-os-mobile/src/biometric.js +41 -0
- package/agent-os-mobile/src/components/ApprovalStack.js +207 -0
- package/agent-os-mobile/src/components/OutcomeCard.js +98 -0
- package/agent-os-mobile/src/memory-graph.js +114 -0
- package/agent-os-mobile/src/screens/CashHoundMobileScreen.js +111 -0
- package/agent-os-mobile/src/screens/LocalRoarMobileScreen.js +183 -0
- package/agent-os-mobile/src/screens/OmniLifeMobileScreen.js +111 -0
- package/agent-os-mobile/src/screens/PulseMDMobileScreen.js +55 -0
- package/agent-os-mobile/src/screens/ResolveXMobileScreen.js +96 -0
- package/agent-os-mobile/src/screens/SentinelMeshMobileScreen.js +199 -0
- package/agent-os-mobile/src/self-healer.js +104 -0
- package/agent-os-mobile/src/speculative-verifier.js +69 -0
- package/agent-os-mobile/src/spekra-bridge.js +216 -0
- package/agent-os-mobile/src/swarm.js +72 -0
- package/agent-os-mobile/src/voice.js +51 -0
- package/bin/agentos.js +260 -0
- package/package.json +51 -4
- package/src/index.js +91 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { CashHoundAgent, Invoice, SettlementNpvOptimizer, BankFeedReconciler } from '../src/index.js';
|
|
4
|
+
|
|
5
|
+
test('CashHound NPV Optimizer: evaluates recovery probabilities and discount advantages', () => {
|
|
6
|
+
const optimizer = new SettlementNpvOptimizer(0.10);
|
|
7
|
+
|
|
8
|
+
// Severe overdue (90+ days) for high risk customer
|
|
9
|
+
const plan = optimizer.calculateOptimalSettlement(10000, 95, 'HIGH_RISK');
|
|
10
|
+
assert.equal(plan.agingBucket, '90+');
|
|
11
|
+
assert.equal(plan.recommendedDiscountPercent, 30); // 25 + 5
|
|
12
|
+
assert.equal(plan.settlementCashToday, 7000);
|
|
13
|
+
assert.equal(plan.shouldOfferSettlement, true);
|
|
14
|
+
assert.ok(plan.netRecoveryAdvantage > 0);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('CashHound Bank Reconciler: auto-matches ACH memo, settles invoice, and terminates dunning', () => {
|
|
18
|
+
const agent = new CashHoundAgent();
|
|
19
|
+
const inv = new Invoice({
|
|
20
|
+
id: 'INV-1094',
|
|
21
|
+
customer: { name: 'Acme Logistics' },
|
|
22
|
+
amount: 5000,
|
|
23
|
+
dueDate: '2026-10-01'
|
|
24
|
+
});
|
|
25
|
+
agent.registerInvoice(inv);
|
|
26
|
+
agent.runCycle('2026-11-15T00:00:00Z');
|
|
27
|
+
|
|
28
|
+
assert.equal(agent.getPendingApprovals().length, 1);
|
|
29
|
+
|
|
30
|
+
const reconciler = new BankFeedReconciler(agent);
|
|
31
|
+
const webhook = {
|
|
32
|
+
amount: 5000,
|
|
33
|
+
memo: 'Wire transfer payment for INV-1094 ref #9923',
|
|
34
|
+
sender: 'Acme Logistics'
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const receipt = reconciler.processWebhookEvent(webhook);
|
|
38
|
+
assert.equal(receipt.matched, true);
|
|
39
|
+
assert.equal(receipt.isFullyPaid, true);
|
|
40
|
+
assert.equal(inv.balance, 0);
|
|
41
|
+
|
|
42
|
+
// Pending dunning actions must now be empty
|
|
43
|
+
assert.equal(agent.getPendingApprovals().length, 0);
|
|
44
|
+
});
|
|
@@ -0,0 +1,530 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CashHound Comprehensive Automated Unit Tests
|
|
3
|
+
* Uses Node.js built-in `node:test` and `node:assert`.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { describe, it } from 'node:test';
|
|
7
|
+
import assert from 'node:assert/strict';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
Invoice,
|
|
11
|
+
AgingBuckets,
|
|
12
|
+
InvoiceStatus,
|
|
13
|
+
CustomerTier,
|
|
14
|
+
PriorityLevel,
|
|
15
|
+
DunningTier,
|
|
16
|
+
DunningTone,
|
|
17
|
+
generateDunningMessage,
|
|
18
|
+
calculateInstallmentPlan,
|
|
19
|
+
calculateSettlementOffer,
|
|
20
|
+
CashHoundAgent,
|
|
21
|
+
ActionStatus,
|
|
22
|
+
AgentDecisionType,
|
|
23
|
+
} from '../src/index.js';
|
|
24
|
+
|
|
25
|
+
describe('Invoice Model & Aging Classification', () => {
|
|
26
|
+
const asOf = new Date('2026-11-15T00:00:00Z');
|
|
27
|
+
|
|
28
|
+
it('correctly models invoice properties and calculates initial balance', () => {
|
|
29
|
+
const inv = new Invoice({
|
|
30
|
+
id: 'INV-101',
|
|
31
|
+
customer: { name: 'Acme Corp', email: 'billing@acme.com' },
|
|
32
|
+
amount: 1500,
|
|
33
|
+
dueDate: '2026-11-01',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
assert.equal(inv.id, 'INV-101');
|
|
37
|
+
assert.equal(inv.amount, 1500);
|
|
38
|
+
assert.equal(inv.amountPaid, 0);
|
|
39
|
+
assert.equal(inv.balance, 1500);
|
|
40
|
+
assert.equal(inv.status, InvoiceStatus.ISSUED);
|
|
41
|
+
assert.equal(inv.customer.tier, CustomerTier.STANDARD);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('classifies aging into current bucket when not yet overdue', () => {
|
|
45
|
+
const inv = new Invoice({
|
|
46
|
+
id: 'INV-CURR',
|
|
47
|
+
customer: { name: 'Alpha Ltd' },
|
|
48
|
+
amount: 800,
|
|
49
|
+
dueDate: '2026-11-20',
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const days = inv.getDaysPastDue(asOf);
|
|
53
|
+
assert.ok(days < 0, `Expected negative days, got ${days}`);
|
|
54
|
+
assert.equal(inv.getAgingBucket(asOf), AgingBuckets.CURRENT);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('classifies aging into 30+ bucket (1-30 days past due)', () => {
|
|
58
|
+
const inv = new Invoice({
|
|
59
|
+
id: 'INV-30',
|
|
60
|
+
customer: { name: 'Beta LLC' },
|
|
61
|
+
amount: 1200,
|
|
62
|
+
dueDate: '2026-10-31', // 15 days overdue
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const days = inv.getDaysPastDue(asOf);
|
|
66
|
+
assert.equal(days, 15);
|
|
67
|
+
assert.equal(inv.getAgingBucket(asOf), AgingBuckets.DAYS_30);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('classifies aging into 60+ bucket (31-60 days past due)', () => {
|
|
71
|
+
const inv = new Invoice({
|
|
72
|
+
id: 'INV-60',
|
|
73
|
+
customer: { name: 'Gamma Inc' },
|
|
74
|
+
amount: 2500,
|
|
75
|
+
dueDate: '2026-09-30', // 46 days overdue
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const days = inv.getDaysPastDue(asOf);
|
|
79
|
+
assert.ok(days >= 31 && days <= 60);
|
|
80
|
+
assert.equal(inv.getAgingBucket(asOf), AgingBuckets.DAYS_60);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('classifies aging into 90+ bucket (61+ days past due)', () => {
|
|
84
|
+
const inv = new Invoice({
|
|
85
|
+
id: 'INV-90',
|
|
86
|
+
customer: { name: 'Delta Co' },
|
|
87
|
+
amount: 3200,
|
|
88
|
+
dueDate: '2026-08-01', // > 100 days overdue
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const days = inv.getDaysPastDue(asOf);
|
|
92
|
+
assert.ok(days > 60);
|
|
93
|
+
assert.equal(inv.getAgingBucket(asOf), AgingBuckets.DAYS_90);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('handles dispute lifecycle: mark disputed and resolve dispute', () => {
|
|
97
|
+
const inv = new Invoice({
|
|
98
|
+
id: 'INV-DISP',
|
|
99
|
+
customer: { name: 'Omega Tech' },
|
|
100
|
+
amount: 2000,
|
|
101
|
+
dueDate: '2026-10-15',
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
assert.equal(inv.isDisputed(), false);
|
|
105
|
+
assert.equal(inv.isLegalDispute(), false);
|
|
106
|
+
|
|
107
|
+
inv.markDisputed({
|
|
108
|
+
reason: 'Billing hours discrepancy in phase 2',
|
|
109
|
+
isLegal: false,
|
|
110
|
+
notes: 'Customer queried 10 hours',
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
assert.equal(inv.isDisputed(), true);
|
|
114
|
+
assert.equal(inv.isLegalDispute(), false);
|
|
115
|
+
assert.equal(inv.status, InvoiceStatus.DISPUTED);
|
|
116
|
+
|
|
117
|
+
inv.resolveDispute({
|
|
118
|
+
resolution: 'Credit memo issued for 5 hours; balance agreed',
|
|
119
|
+
notes: 'Customer agreed to pay remainder',
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
assert.equal(inv.isDisputed(), false);
|
|
123
|
+
assert.equal(inv.status, InvoiceStatus.ISSUED);
|
|
124
|
+
assert.equal(inv.dispute.status, 'resolved');
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('flags legal disputes accurately', () => {
|
|
128
|
+
const inv = new Invoice({
|
|
129
|
+
id: 'INV-LEGAL',
|
|
130
|
+
customer: { name: 'Zeta Corp' },
|
|
131
|
+
amount: 15000,
|
|
132
|
+
dueDate: '2026-08-15',
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
inv.markDisputed({
|
|
136
|
+
reason: 'Notice of litigation received from outside counsel',
|
|
137
|
+
isLegal: true,
|
|
138
|
+
notes: 'Legal counsel involved',
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
assert.equal(inv.isLegalDispute(), true);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('calculates dynamic recovery priority score and level', () => {
|
|
145
|
+
const oldHighVal = new Invoice({
|
|
146
|
+
id: 'INV-HI-PRIO',
|
|
147
|
+
customer: { name: 'BigCorp', tier: CustomerTier.STANDARD },
|
|
148
|
+
amount: 12000,
|
|
149
|
+
dueDate: '2026-08-01', // 90+ bucket
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const prio = oldHighVal.calculatePriority(asOf);
|
|
153
|
+
assert.ok(prio.score >= 80, `Expected score >= 80, got ${prio.score}`);
|
|
154
|
+
assert.equal(prio.level, PriorityLevel.CRITICAL);
|
|
155
|
+
assert.ok(prio.reasons.length > 0);
|
|
156
|
+
|
|
157
|
+
const paidInv = new Invoice({
|
|
158
|
+
id: 'INV-PAID',
|
|
159
|
+
customer: { name: 'GoodClient' },
|
|
160
|
+
amount: 500,
|
|
161
|
+
amountPaid: 500,
|
|
162
|
+
dueDate: '2026-11-01',
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const paidPrio = paidInv.calculatePriority(asOf);
|
|
166
|
+
assert.equal(paidPrio.score, 0);
|
|
167
|
+
assert.equal(paidPrio.level, PriorityLevel.LOW);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
describe('Dunning Engine & Financial Calculators', () => {
|
|
172
|
+
const invoice = new Invoice({
|
|
173
|
+
id: 'INV-202',
|
|
174
|
+
customer: { name: 'Starlight Studios', email: 'ap@starlight.com', tier: CustomerTier.STANDARD },
|
|
175
|
+
amount: 3000,
|
|
176
|
+
dueDate: '2026-10-15',
|
|
177
|
+
});
|
|
178
|
+
const asOf = new Date('2026-11-15T00:00:00Z'); // 31 days overdue
|
|
179
|
+
|
|
180
|
+
it('generates polite Tier 1 courtesy notice for early overdue', () => {
|
|
181
|
+
const msg = generateDunningMessage(invoice, {
|
|
182
|
+
tier: DunningTier.TIER_1_COURTESY,
|
|
183
|
+
asOfDate: asOf,
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
assert.equal(msg.tier, DunningTier.TIER_1_COURTESY);
|
|
187
|
+
assert.equal(msg.tone, DunningTone.FRIENDLY);
|
|
188
|
+
assert.match(msg.subject, /Friendly reminder/);
|
|
189
|
+
assert.match(msg.body, /disregard this note/);
|
|
190
|
+
assert.ok(msg.paymentLink.includes('INV-202'));
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('generates firm Tier 3 urgent notice for 30+ days overdue', () => {
|
|
194
|
+
const msg = generateDunningMessage(invoice, {
|
|
195
|
+
tier: DunningTier.TIER_3_URGENT,
|
|
196
|
+
asOfDate: asOf,
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
assert.equal(msg.tier, DunningTier.TIER_3_URGENT);
|
|
200
|
+
assert.equal(msg.tone, DunningTone.URGENT);
|
|
201
|
+
assert.match(msg.subject, /Urgent:/);
|
|
202
|
+
assert.match(msg.body, /uninterrupted service/);
|
|
203
|
+
assert.ok(msg.installmentPlan);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('generates Tier 4 final demand with settlement offer for severe delinquency', () => {
|
|
207
|
+
const msg = generateDunningMessage(invoice, {
|
|
208
|
+
tier: DunningTier.TIER_4_FINAL_DEMAND,
|
|
209
|
+
asOfDate: asOf,
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
assert.equal(msg.tier, DunningTier.TIER_4_FINAL_DEMAND);
|
|
213
|
+
assert.equal(msg.tone, DunningTone.FORMAL);
|
|
214
|
+
assert.match(msg.subject, /FINAL DEMAND:/);
|
|
215
|
+
assert.match(msg.body, /legal recovery/);
|
|
216
|
+
assert.ok(msg.settlementOffer);
|
|
217
|
+
assert.match(msg.settlementOffer.terms, /settle invoice in full/);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it('protects VIP customer relationships with empathetic tone', () => {
|
|
221
|
+
const vipInvoice = new Invoice({
|
|
222
|
+
id: 'INV-VIP',
|
|
223
|
+
customer: { name: 'Key Partner Enterprise', tier: CustomerTier.VIP },
|
|
224
|
+
amount: 4000,
|
|
225
|
+
dueDate: '2026-10-15',
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
const msg = generateDunningMessage(vipInvoice, {
|
|
229
|
+
tier: DunningTier.TIER_2_REMINDER,
|
|
230
|
+
asOfDate: asOf,
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
assert.equal(msg.tone, DunningTone.EMPATHETIC);
|
|
234
|
+
assert.match(msg.body, /value our partnership/);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('calculates installment payment plans accurately', () => {
|
|
238
|
+
const plan = calculateInstallmentPlan(1200, {
|
|
239
|
+
numberOfInstallments: 3,
|
|
240
|
+
frequency: 'monthly',
|
|
241
|
+
startDate: '2026-11-20',
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
assert.equal(plan.originalBalance, 1200);
|
|
245
|
+
assert.equal(plan.totalPayable, 1200);
|
|
246
|
+
assert.equal(plan.numberOfInstallments, 3);
|
|
247
|
+
assert.equal(plan.schedule.length, 3);
|
|
248
|
+
assert.equal(plan.schedule[0].amount, 400);
|
|
249
|
+
assert.equal(plan.schedule[1].amount, 400);
|
|
250
|
+
assert.equal(plan.schedule[2].amount, 400);
|
|
251
|
+
assert.equal(plan.schedule[2].remainingBalanceAfter, 0);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it('calculates lump-sum settlement discount offers', () => {
|
|
255
|
+
const offer = calculateSettlementOffer(2000, {
|
|
256
|
+
discountPercentage: 20,
|
|
257
|
+
validityDays: 10,
|
|
258
|
+
asOfDate: '2026-11-15',
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
assert.equal(offer.originalBalance, 2000);
|
|
262
|
+
assert.equal(offer.discountPercentage, 20);
|
|
263
|
+
assert.equal(offer.discountAmount, 400);
|
|
264
|
+
assert.equal(offer.settlementAmount, 1600);
|
|
265
|
+
assert.equal(offer.validUntil, '2026-11-25');
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
describe('CashHound Decision State Machine & Approval Gates', () => {
|
|
270
|
+
const asOf = new Date('2026-11-15T00:00:00Z');
|
|
271
|
+
|
|
272
|
+
it('automatically dispatches safe reminders for low-risk accounts (<$5000)', () => {
|
|
273
|
+
const agent = new CashHoundAgent({
|
|
274
|
+
highValueThreshold: 5000,
|
|
275
|
+
autoSendSafeReminders: true,
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
const safeInv = new Invoice({
|
|
279
|
+
id: 'INV-SAFE-01',
|
|
280
|
+
customer: { name: 'Small Shop LLC', email: 'owner@smallshop.com' },
|
|
281
|
+
amount: 1200,
|
|
282
|
+
dueDate: '2026-11-01', // 14 days overdue
|
|
283
|
+
});
|
|
284
|
+
agent.registerInvoice(safeInv);
|
|
285
|
+
|
|
286
|
+
const result = agent.processInvoice(safeInv, asOf);
|
|
287
|
+
|
|
288
|
+
assert.equal(result.status, ActionStatus.AUTO_EXECUTED);
|
|
289
|
+
assert.equal(result.decision, AgentDecisionType.SAFE_REMINDER);
|
|
290
|
+
assert.equal(safeInv.communications.length, 1);
|
|
291
|
+
assert.equal(safeInv.communications[0].status, 'sent');
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it('flags high-value invoices (>=$5,000) for human approval before sending', () => {
|
|
295
|
+
const agent = new CashHoundAgent({
|
|
296
|
+
highValueThreshold: 5000,
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
const highValInv = new Invoice({
|
|
300
|
+
id: 'INV-HIGH-VAL',
|
|
301
|
+
customer: { name: 'MegaCorp Enterprises' },
|
|
302
|
+
amount: 7500,
|
|
303
|
+
dueDate: '2026-11-01', // 14 days overdue
|
|
304
|
+
});
|
|
305
|
+
agent.registerInvoice(highValInv);
|
|
306
|
+
|
|
307
|
+
const result = agent.processInvoice(highValInv, asOf);
|
|
308
|
+
|
|
309
|
+
assert.equal(result.status, ActionStatus.PENDING_APPROVAL);
|
|
310
|
+
assert.equal(result.decision, AgentDecisionType.REQUIRE_APPROVAL);
|
|
311
|
+
assert.ok(result.approvalReasons.some(r => r.includes('High-value invoice balance')));
|
|
312
|
+
// Must NOT have dispatched communication yet
|
|
313
|
+
assert.equal(highValInv.communications.length, 0);
|
|
314
|
+
|
|
315
|
+
// Verify it appears in pending approvals queue
|
|
316
|
+
const pending = agent.getPendingApprovals();
|
|
317
|
+
assert.equal(pending.length, 1);
|
|
318
|
+
assert.equal(pending[0].id, result.id);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it('flags legal dispute accounts for human approval', () => {
|
|
322
|
+
const agent = new CashHoundAgent();
|
|
323
|
+
|
|
324
|
+
const legalInv = new Invoice({
|
|
325
|
+
id: 'INV-LEGAL-GATE',
|
|
326
|
+
customer: { name: 'Disputed Corp' },
|
|
327
|
+
amount: 3000, // < 5000, but legal dispute
|
|
328
|
+
dueDate: '2026-10-01',
|
|
329
|
+
});
|
|
330
|
+
legalInv.markDisputed({
|
|
331
|
+
reason: 'Attorney letter received contesting deliverable',
|
|
332
|
+
isLegal: true,
|
|
333
|
+
});
|
|
334
|
+
agent.registerInvoice(legalInv);
|
|
335
|
+
|
|
336
|
+
const result = agent.processInvoice(legalInv, asOf);
|
|
337
|
+
|
|
338
|
+
assert.equal(result.status, ActionStatus.PENDING_APPROVAL);
|
|
339
|
+
assert.ok(result.approvalReasons.some(r => r.includes('Active legal dispute')));
|
|
340
|
+
assert.equal(legalInv.communications.length, 0);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it('enforces communication cooldown window to avoid customer spam', () => {
|
|
344
|
+
const agent = new CashHoundAgent({ cooldownDays: 7 });
|
|
345
|
+
|
|
346
|
+
const inv = new Invoice({
|
|
347
|
+
id: 'INV-COOLDOWN',
|
|
348
|
+
customer: { name: 'Fresh Start LLC' },
|
|
349
|
+
amount: 800,
|
|
350
|
+
dueDate: '2026-11-01',
|
|
351
|
+
});
|
|
352
|
+
agent.registerInvoice(inv);
|
|
353
|
+
|
|
354
|
+
// First reminder is sent
|
|
355
|
+
const res1 = agent.processInvoice(inv, asOf);
|
|
356
|
+
assert.equal(res1.status, ActionStatus.AUTO_EXECUTED);
|
|
357
|
+
|
|
358
|
+
// Next day inquiry
|
|
359
|
+
const nextDay = new Date('2026-11-16T00:00:00Z');
|
|
360
|
+
const res2 = agent.processInvoice(inv, nextDay);
|
|
361
|
+
assert.equal(res2.decision, AgentDecisionType.NO_ACTION);
|
|
362
|
+
assert.match(res2.reason, /cooldown window/);
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
it('allows human operator to approve pending actions', () => {
|
|
366
|
+
const agent = new CashHoundAgent({ highValueThreshold: 5000 });
|
|
367
|
+
|
|
368
|
+
const inv = new Invoice({
|
|
369
|
+
id: 'INV-APPROVE-TEST',
|
|
370
|
+
customer: { name: 'Enterprise Co' },
|
|
371
|
+
amount: 6000,
|
|
372
|
+
dueDate: '2026-11-01',
|
|
373
|
+
});
|
|
374
|
+
agent.registerInvoice(inv);
|
|
375
|
+
|
|
376
|
+
const action = agent.processInvoice(inv, asOf);
|
|
377
|
+
assert.equal(action.status, ActionStatus.PENDING_APPROVAL);
|
|
378
|
+
|
|
379
|
+
const executed = agent.approveAction(action.id, {
|
|
380
|
+
name: 'Sarah Controller',
|
|
381
|
+
email: 'sarah@company.com',
|
|
382
|
+
notes: 'Reviewed with account manager, safe to send',
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
assert.equal(executed.status, ActionStatus.APPROVED);
|
|
386
|
+
assert.equal(inv.communications.length, 1);
|
|
387
|
+
assert.equal(inv.communications[0].status, 'sent');
|
|
388
|
+
assert.equal(agent.getPendingApprovals().length, 0);
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it('allows human operator to reject pending actions with feedback', () => {
|
|
392
|
+
const agent = new CashHoundAgent({ highValueThreshold: 5000 });
|
|
393
|
+
|
|
394
|
+
const inv = new Invoice({
|
|
395
|
+
id: 'INV-REJECT-TEST',
|
|
396
|
+
customer: { name: 'Tech Partner' },
|
|
397
|
+
amount: 9000,
|
|
398
|
+
dueDate: '2026-11-01',
|
|
399
|
+
});
|
|
400
|
+
agent.registerInvoice(inv);
|
|
401
|
+
|
|
402
|
+
const action = agent.processInvoice(inv, asOf);
|
|
403
|
+
assert.equal(action.status, ActionStatus.PENDING_APPROVAL);
|
|
404
|
+
|
|
405
|
+
const rejected = agent.rejectAction(action.id, 'Holding reminder pending contract renewal discussion');
|
|
406
|
+
|
|
407
|
+
assert.equal(rejected.status, ActionStatus.REJECTED);
|
|
408
|
+
assert.equal(rejected.rejectedBy.reason, 'Holding reminder pending contract renewal discussion');
|
|
409
|
+
assert.equal(inv.communications.length, 0);
|
|
410
|
+
});
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
describe('Payment Reconciliation & Full Batch Cycle', () => {
|
|
414
|
+
const asOf = new Date('2026-11-15T00:00:00Z');
|
|
415
|
+
|
|
416
|
+
it('reconciles partial payment, updates balance, and cancels pending dunning actions', () => {
|
|
417
|
+
const agent = new CashHoundAgent({ highValueThreshold: 5000 });
|
|
418
|
+
|
|
419
|
+
const inv = new Invoice({
|
|
420
|
+
id: 'INV-RECON-01',
|
|
421
|
+
customer: { name: 'Apex Builders' },
|
|
422
|
+
amount: 8000,
|
|
423
|
+
dueDate: '2026-10-15',
|
|
424
|
+
});
|
|
425
|
+
agent.registerInvoice(inv);
|
|
426
|
+
|
|
427
|
+
// Creates pending action due to high value
|
|
428
|
+
const pendingAction = agent.processInvoice(inv, asOf);
|
|
429
|
+
assert.equal(pendingAction.status, ActionStatus.PENDING_APPROVAL);
|
|
430
|
+
|
|
431
|
+
// Customer sends partial wire payment of $5,000
|
|
432
|
+
const recon = agent.recordPayment('INV-RECON-01', {
|
|
433
|
+
amount: 5000,
|
|
434
|
+
method: 'wire',
|
|
435
|
+
reference: 'WIRE-998822',
|
|
436
|
+
date: asOf,
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
assert.equal(recon.initialBalance, 8000);
|
|
440
|
+
assert.equal(recon.amountPaid, 5000);
|
|
441
|
+
assert.equal(recon.remainingBalance, 3000);
|
|
442
|
+
assert.equal(recon.isFullyPaid, false);
|
|
443
|
+
assert.equal(inv.status, InvoiceStatus.PARTIALLY_PAID);
|
|
444
|
+
|
|
445
|
+
// Assert pending action was automatically cancelled
|
|
446
|
+
assert.ok(recon.cancelledActions.includes(pendingAction.id));
|
|
447
|
+
assert.equal(pendingAction.status, ActionStatus.CANCELLED);
|
|
448
|
+
|
|
449
|
+
// Verify receipt acknowledgment communication
|
|
450
|
+
assert.ok(recon.receiptCommunication);
|
|
451
|
+
assert.match(recon.receiptCommunication.subject, /Payment Received/);
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
it('reconciles full payment and marks invoice fully paid', () => {
|
|
455
|
+
const agent = new CashHoundAgent();
|
|
456
|
+
|
|
457
|
+
const inv = new Invoice({
|
|
458
|
+
id: 'INV-RECON-FULL',
|
|
459
|
+
customer: { name: 'Zenith Retail' },
|
|
460
|
+
amount: 1500,
|
|
461
|
+
dueDate: '2026-10-20',
|
|
462
|
+
});
|
|
463
|
+
agent.registerInvoice(inv);
|
|
464
|
+
|
|
465
|
+
const recon = agent.recordPayment('INV-RECON-FULL', {
|
|
466
|
+
amount: 1500,
|
|
467
|
+
method: 'ach',
|
|
468
|
+
reference: 'ACH-112233',
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
assert.equal(recon.remainingBalance, 0);
|
|
472
|
+
assert.equal(recon.isFullyPaid, true);
|
|
473
|
+
assert.equal(inv.status, InvoiceStatus.PAID);
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
it('executes a complete batch cycle over an entire invoice portfolio', () => {
|
|
477
|
+
const agent = new CashHoundAgent({
|
|
478
|
+
highValueThreshold: 5000,
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
// 1. Current invoice
|
|
482
|
+
agent.registerInvoice(new Invoice({
|
|
483
|
+
id: 'INV-PORT-1',
|
|
484
|
+
customer: { name: 'Customer 1' },
|
|
485
|
+
amount: 1000,
|
|
486
|
+
dueDate: '2026-11-25', // current
|
|
487
|
+
}));
|
|
488
|
+
|
|
489
|
+
// 2. Safe overdue invoice (< $5000)
|
|
490
|
+
agent.registerInvoice(new Invoice({
|
|
491
|
+
id: 'INV-PORT-2',
|
|
492
|
+
customer: { name: 'Customer 2' },
|
|
493
|
+
amount: 1500,
|
|
494
|
+
dueDate: '2026-11-01', // 30+ days bucket
|
|
495
|
+
}));
|
|
496
|
+
|
|
497
|
+
// 3. High value overdue invoice (>= $5000)
|
|
498
|
+
agent.registerInvoice(new Invoice({
|
|
499
|
+
id: 'INV-PORT-3',
|
|
500
|
+
customer: { name: 'Customer 3' },
|
|
501
|
+
amount: 8500,
|
|
502
|
+
dueDate: '2026-10-15', // 60+ days bucket, high value
|
|
503
|
+
}));
|
|
504
|
+
|
|
505
|
+
// 4. Overdue invoice with legal dispute
|
|
506
|
+
const legalInv = new Invoice({
|
|
507
|
+
id: 'INV-PORT-4',
|
|
508
|
+
customer: { name: 'Customer 4' },
|
|
509
|
+
amount: 2200,
|
|
510
|
+
dueDate: '2026-09-01', // 90+ days
|
|
511
|
+
});
|
|
512
|
+
legalInv.markDisputed({ reason: 'Legal claim filed', isLegal: true });
|
|
513
|
+
agent.registerInvoice(legalInv);
|
|
514
|
+
|
|
515
|
+
const report = agent.runCycle(asOf);
|
|
516
|
+
|
|
517
|
+
assert.equal(report.totalInvoices, 4);
|
|
518
|
+
assert.equal(report.totalOutstandingBalance, 13200);
|
|
519
|
+
assert.equal(report.actionsAutoSent, 1); // Customer 2 safe auto reminder
|
|
520
|
+
assert.equal(report.actionsFlaggedForApproval, 2); // Customer 3 (high value) & Customer 4 (legal)
|
|
521
|
+
assert.equal(report.noActionCount, 1); // Customer 1 (current)
|
|
522
|
+
assert.equal(report.flaggedHighValueCount, 1);
|
|
523
|
+
assert.equal(report.legalDisputeCount, 1);
|
|
524
|
+
|
|
525
|
+
// Audit trail verification
|
|
526
|
+
const auditLogs = agent.getAuditLog();
|
|
527
|
+
assert.ok(auditLogs.length > 5);
|
|
528
|
+
assert.ok(auditLogs.some(l => l.eventType === 'CYCLE_COMPLETED'));
|
|
529
|
+
});
|
|
530
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { CashHoundAgent, Invoice, CashHoundMobileAdapter } from '../src/index.js';
|
|
4
|
+
|
|
5
|
+
test('CashHound Mobile Adapter: formats mobile outcome cards and approval stack', () => {
|
|
6
|
+
const agent = new CashHoundAgent();
|
|
7
|
+
const inv = new Invoice({
|
|
8
|
+
id: 'INV-MOB-01',
|
|
9
|
+
customer: { name: 'Acme Mobile', email: 'acme@example.com' },
|
|
10
|
+
amount: 6000,
|
|
11
|
+
dueDate: '2026-10-01'
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
agent.registerInvoice(inv);
|
|
15
|
+
agent.runCycle('2026-11-15T00:00:00Z');
|
|
16
|
+
|
|
17
|
+
const mobile = new CashHoundMobileAdapter(agent);
|
|
18
|
+
const card = mobile.getMobileOutcomeCard();
|
|
19
|
+
assert.equal(card.title, 'CashHound Autonomous Collections');
|
|
20
|
+
assert.equal(card.approvalsPending, 1);
|
|
21
|
+
|
|
22
|
+
const stack = mobile.getMobileApprovalStack();
|
|
23
|
+
assert.equal(stack.length, 1);
|
|
24
|
+
assert.ok(stack[0].amountFormatted.includes('6000'));
|
|
25
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { Invoice, generateDunningMessage, calculateInstallmentPlan } from '../src/index.js';
|
|
4
|
+
|
|
5
|
+
test('CashHound Security: sanitizes URL parameters in dunning links and blocks insecure schemes', () => {
|
|
6
|
+
const inv = new Invoice({
|
|
7
|
+
id: 'INV#1001&attacker=evil.com',
|
|
8
|
+
customer: { name: 'Acme Test' },
|
|
9
|
+
amount: 1500,
|
|
10
|
+
dueDate: '2026-11-01'
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const msg = generateDunningMessage(inv);
|
|
14
|
+
assert.ok(msg.paymentLink.includes('INV%231001%26attacker%3Devil.com'));
|
|
15
|
+
assert.ok(!msg.paymentLink.includes('INV#1001'));
|
|
16
|
+
|
|
17
|
+
// Insecure http scheme should be rejected
|
|
18
|
+
assert.throws(() => {
|
|
19
|
+
generateDunningMessage(inv, { paymentPortalUrl: 'http://insecure-portal.com' });
|
|
20
|
+
}, /HTTPS required/);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('CashHound Security: enforces positive finite balance bounds on installment plans', () => {
|
|
24
|
+
assert.throws(() => {
|
|
25
|
+
calculateInstallmentPlan(-100);
|
|
26
|
+
}, /positive finite number/);
|
|
27
|
+
|
|
28
|
+
assert.throws(() => {
|
|
29
|
+
calculateInstallmentPlan(NaN);
|
|
30
|
+
}, /positive finite number/);
|
|
31
|
+
|
|
32
|
+
assert.throws(() => {
|
|
33
|
+
calculateInstallmentPlan(Infinity);
|
|
34
|
+
}, /positive finite number/);
|
|
35
|
+
});
|
package/Clerk/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Clerk — Settlement & Warranty Resolution Agent
|
|
2
|
+
|
|
3
|
+
**Clerk** resolves the financial and warranty closure for field visits, ensuring estimate reconciliation, invoice generation, and proof-backed payment verification.
|
|
4
|
+
|
|
5
|
+
## Capabilities
|
|
6
|
+
|
|
7
|
+
1. **Charge Reconciliation:** Verifies that reported work and parts charges exactly match accepted estimates. Blocks unapproved upcharges.
|
|
8
|
+
2. **Invoicing & Approvals:** Prepares verified invoice drafts and requires owner authorization prior to release.
|
|
9
|
+
3. **Payment Verification:** Matches incoming payment amount, currency (INR), and transaction reference against the specific invoice ID.
|
|
10
|
+
4. **Warranty Resolution:** Prepares warranty claim packages with bound technician evidence for insurer/manufacturer review.
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```javascript
|
|
15
|
+
import { settlementAgent, SettlementReconciler } from 'clerk-agent';
|
|
16
|
+
|
|
17
|
+
const reconciler = new SettlementReconciler();
|
|
18
|
+
const invoice = reconciler.issueInvoice('tenant-1', 'job-001', 150000, 'INR');
|
|
19
|
+
|
|
20
|
+
// Record and verify payment
|
|
21
|
+
reconciler.recordPayment('tenant-1', 'job-001', invoice.id, 150000, 'INR', 'pay_ref_123');
|
|
22
|
+
const check = reconciler.verifyPayment('tenant-1', 'job-001');
|
|
23
|
+
// check.verified === true
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Testing
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
npm test
|
|
30
|
+
```
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clerk: Settlement and Warranty Agent
|
|
3
|
+
* Resolves financial work, reconciles estimate against final charges, issues invoices or prepares warranty claims.
|
|
4
|
+
*/
|
|
5
|
+
export const settlementAgent = {
|
|
6
|
+
name: 'clerk',
|
|
7
|
+
next(job) {
|
|
8
|
+
if (job.report.amount !== job.input.amount) {
|
|
9
|
+
return { wait: 'blocked', reason: 'Report charges differ from accepted estimate; revise and reauthorize the estimate' };
|
|
10
|
+
}
|
|
11
|
+
if (job.report.warranty) {
|
|
12
|
+
if (!job.claim) return { tool: 'claim', permission: 'claim', reason: 'Prepare a simulated warranty case from the validated report' };
|
|
13
|
+
return { tool: 'verifyClaim', reason: 'Check case resolution evidence' };
|
|
14
|
+
}
|
|
15
|
+
if (!job.invoice) return { tool: 'invoice', permission: 'invoice', reason: 'Issue a simulated invoice for the accepted amount' };
|
|
16
|
+
return { tool: 'verifyPayment', reason: 'Verify payment against invoice amount' };
|
|
17
|
+
}
|
|
18
|
+
};
|