@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.
Files changed (114) hide show
  1. package/Booker/README.md +41 -0
  2. package/Booker/package.json +11 -0
  3. package/Booker/src/agent.js +15 -0
  4. package/Booker/src/calendar-adapter.js +75 -0
  5. package/Booker/src/index.js +4 -0
  6. package/Booker/src/intake-parser.js +96 -0
  7. package/Booker/src/validation.js +34 -0
  8. package/Booker/test/booker.test.js +35 -0
  9. package/CashHound/README.md +181 -0
  10. package/CashHound/package.json +21 -0
  11. package/CashHound/src/agent.js +621 -0
  12. package/CashHound/src/bank-reconciler.js +66 -0
  13. package/CashHound/src/dunning.js +380 -0
  14. package/CashHound/src/index.js +32 -0
  15. package/CashHound/src/invoice.js +371 -0
  16. package/CashHound/src/mobile.js +35 -0
  17. package/CashHound/src/npv-optimizer.js +259 -0
  18. package/CashHound/test/advanced.test.js +44 -0
  19. package/CashHound/test/cashhound.test.js +530 -0
  20. package/CashHound/test/mobile.test.js +25 -0
  21. package/CashHound/test/security.test.js +35 -0
  22. package/Clerk/README.md +30 -0
  23. package/Clerk/package.json +11 -0
  24. package/Clerk/src/agent.js +18 -0
  25. package/Clerk/src/index.js +2 -0
  26. package/Clerk/src/reconciliation.js +52 -0
  27. package/Clerk/test/clerk.test.js +39 -0
  28. package/LocalRoar/README.md +37 -0
  29. package/LocalRoar/package.json +13 -0
  30. package/LocalRoar/src/agent.js +70 -0
  31. package/LocalRoar/src/booking-router.js +74 -0
  32. package/LocalRoar/src/feedback-interceptor.js +47 -0
  33. package/LocalRoar/src/index.js +7 -0
  34. package/LocalRoar/src/lead-engine.js +52 -0
  35. package/LocalRoar/src/mobile.js +23 -0
  36. package/LocalRoar/src/review-booster.js +24 -0
  37. package/LocalRoar/src/route-density.js +46 -0
  38. package/LocalRoar/test/advanced.test.js +41 -0
  39. package/LocalRoar/test/localroar.test.js +59 -0
  40. package/LocalRoar/test/mobile.test.js +12 -0
  41. package/OmniLife/README.md +39 -0
  42. package/OmniLife/package.json +13 -0
  43. package/OmniLife/src/agent.js +47 -0
  44. package/OmniLife/src/bill-negotiator.js +43 -0
  45. package/OmniLife/src/browser-cancel.js +28 -0
  46. package/OmniLife/src/conflict-engine.js +49 -0
  47. package/OmniLife/src/index.js +6 -0
  48. package/OmniLife/src/mobile.js +18 -0
  49. package/OmniLife/src/subscription-manager.js +66 -0
  50. package/OmniLife/test/advanced.test.js +29 -0
  51. package/OmniLife/test/mobile.test.js +12 -0
  52. package/OmniLife/test/omnilife.test.js +71 -0
  53. package/PulseMD/README.md +42 -0
  54. package/PulseMD/package.json +13 -0
  55. package/PulseMD/src/agent.js +67 -0
  56. package/PulseMD/src/ambient-scribe.js +46 -0
  57. package/PulseMD/src/auth.js +63 -0
  58. package/PulseMD/src/charting.js +54 -0
  59. package/PulseMD/src/index.js +7 -0
  60. package/PulseMD/src/mobile.js +18 -0
  61. package/PulseMD/src/prior-auth.js +39 -0
  62. package/PulseMD/src/safety-guard.js +88 -0
  63. package/PulseMD/test/advanced.test.js +50 -0
  64. package/PulseMD/test/mobile.test.js +12 -0
  65. package/PulseMD/test/pulsemd.test.js +71 -0
  66. package/README.md +203 -2
  67. package/ResolveX/README.md +274 -0
  68. package/ResolveX/package.json +20 -0
  69. package/ResolveX/src/agent.js +679 -0
  70. package/ResolveX/src/carrier-listener.js +405 -0
  71. package/ResolveX/src/diagnosis.js +315 -0
  72. package/ResolveX/src/index.js +36 -0
  73. package/ResolveX/src/mobile.js +31 -0
  74. package/ResolveX/src/policy.js +325 -0
  75. package/ResolveX/src/vision.js +384 -0
  76. package/ResolveX/test/advanced.test.js +445 -0
  77. package/ResolveX/test/mobile.test.js +15 -0
  78. package/ResolveX/test/resolvex.test.js +428 -0
  79. package/SentinelMesh/README.md +51 -0
  80. package/SentinelMesh/package.json +13 -0
  81. package/SentinelMesh/src/governor.js +61 -0
  82. package/SentinelMesh/src/index.js +4 -0
  83. package/SentinelMesh/src/mobile.js +19 -0
  84. package/SentinelMesh/src/policy.js +63 -0
  85. package/SentinelMesh/src/sandbox.js +152 -0
  86. package/SentinelMesh/test/mobile.test.js +12 -0
  87. package/SentinelMesh/test/sentinel.test.js +135 -0
  88. package/Sidekick/README.md +43 -0
  89. package/Sidekick/package.json +11 -0
  90. package/Sidekick/src/agent.js +15 -0
  91. package/Sidekick/src/evidence.js +45 -0
  92. package/Sidekick/src/index.js +3 -0
  93. package/Sidekick/src/validation.js +15 -0
  94. package/Sidekick/test/sidekick.test.js +33 -0
  95. package/agent-os-mobile/README.md +26 -0
  96. package/agent-os-mobile/src/api.js +97 -0
  97. package/agent-os-mobile/src/biometric.js +41 -0
  98. package/agent-os-mobile/src/components/ApprovalStack.js +207 -0
  99. package/agent-os-mobile/src/components/OutcomeCard.js +98 -0
  100. package/agent-os-mobile/src/memory-graph.js +114 -0
  101. package/agent-os-mobile/src/screens/CashHoundMobileScreen.js +111 -0
  102. package/agent-os-mobile/src/screens/LocalRoarMobileScreen.js +183 -0
  103. package/agent-os-mobile/src/screens/OmniLifeMobileScreen.js +111 -0
  104. package/agent-os-mobile/src/screens/PulseMDMobileScreen.js +55 -0
  105. package/agent-os-mobile/src/screens/ResolveXMobileScreen.js +96 -0
  106. package/agent-os-mobile/src/screens/SentinelMeshMobileScreen.js +199 -0
  107. package/agent-os-mobile/src/self-healer.js +104 -0
  108. package/agent-os-mobile/src/speculative-verifier.js +69 -0
  109. package/agent-os-mobile/src/spekra-bridge.js +216 -0
  110. package/agent-os-mobile/src/swarm.js +72 -0
  111. package/agent-os-mobile/src/voice.js +51 -0
  112. package/bin/agentos.js +260 -0
  113. package/package.json +51 -4
  114. package/src/index.js +91 -0
@@ -0,0 +1,384 @@
1
+ /**
2
+ * ResolveX Computer Vision Damage Assessment Engine
3
+ * Evaluates photo evidence metadata, clarity, authentic device telemetry,
4
+ * and detects physical product damage to autonomously authorize replacements.
5
+ */
6
+
7
+ export const DamageType = Object.freeze({
8
+ CRACKED_SCREEN: 'CRACKED_SCREEN',
9
+ WATER_DAMAGE: 'WATER_DAMAGE',
10
+ SHATTERED_CASING: 'SHATTERED_CASING',
11
+ PHYSICAL_DEFORMATION: 'PHYSICAL_DEFORMATION',
12
+ });
13
+
14
+ export const DamageVerificationStatus = Object.freeze({
15
+ AUTHENTIC: 'AUTHENTIC',
16
+ FRAUDULENT: 'FRAUDULENT',
17
+ UNREADABLE: 'UNREADABLE',
18
+ INSUFFICIENT_EVIDENCE: 'INSUFFICIENT_EVIDENCE',
19
+ });
20
+
21
+ const DEFAULT_STOCK_DOMAINS = [
22
+ 'shutterstock.com',
23
+ 'gettyimages.com',
24
+ 'istockphoto.com',
25
+ 'stock.adobe.com',
26
+ 'unsplash.com',
27
+ 'pexels.com',
28
+ 'alamy.com',
29
+ 'depositphotos.com',
30
+ 'dreamstime.com',
31
+ ];
32
+
33
+ const KNOWN_MANIPULATION_SOFTWARE = [
34
+ /photoshop/i,
35
+ /gimp/i,
36
+ /midjourney/i,
37
+ /dall-e/i,
38
+ /stablediffusion/i,
39
+ /deepfake/i,
40
+ ];
41
+
42
+ let authIdCounter = 1;
43
+ function generateAuthCode(prefix = 'AUTH-REPL') {
44
+ const timestamp = Date.now().toString(36).toUpperCase();
45
+ const counter = (authIdCounter++).toString().padStart(4, '0');
46
+ const randomSuffix = Math.random().toString(36).substring(2, 6).toUpperCase();
47
+ return `${prefix}-${timestamp}-${counter}-${randomSuffix}`;
48
+ }
49
+
50
+ export class DamageVerifier {
51
+ constructor(options = {}) {
52
+ this.minClarityScore = options.minClarityScore ?? 0.60;
53
+ this.minWidth = options.minWidth ?? 640;
54
+ this.minHeight = options.minHeight ?? 480;
55
+ this.minFileSizeBytes = options.minFileSizeBytes ?? 15000;
56
+ this.confidenceThreshold = options.confidenceThreshold ?? 0.70;
57
+ this.stockDomains = options.stockDomains || DEFAULT_STOCK_DOMAINS;
58
+ this.knownFraudulentHashes = new Set(options.knownFraudulentHashes || []);
59
+ this.processedPhotos = new Map(); // hash -> { claimId, customerId, timestamp }
60
+ }
61
+
62
+ /**
63
+ * Evaluates photo evidence metadata, computes confidence, and detects fraud/readability.
64
+ * @param {Object} photo - Photo metadata object
65
+ * @returns {Object} Evaluation report
66
+ */
67
+ evaluatePhoto(photo = {}) {
68
+ const reasons = [];
69
+ const detectedDamageTypes = this._extractDamageTypes(photo);
70
+ const clarityScore = typeof photo.clarityScore === 'number' ? Math.max(0, Math.min(1, photo.clarityScore)) : 0;
71
+ const width = photo.width || 0;
72
+ const height = photo.height || 0;
73
+ const fileSizeBytes = photo.fileSizeBytes || photo.size || 0;
74
+ const exif = photo.exif || {};
75
+ const url = photo.url || '';
76
+ const imageHash = photo.imageHash || photo.hash || photo.photoId;
77
+
78
+ // 1. Check for Fraudulent Indicators
79
+ const fraudCheck = this._detectFraud({ photo, exif, url, imageHash });
80
+ if (fraudCheck.isFraudulent) {
81
+ reasons.push(...fraudCheck.reasons);
82
+ const confidenceScore = 0.05;
83
+ return {
84
+ valid: false,
85
+ status: DamageVerificationStatus.FRAUDULENT,
86
+ confidenceScore,
87
+ detectedDamageTypes,
88
+ reasons,
89
+ details: {
90
+ clarityScore,
91
+ resolution: { width, height },
92
+ fraudCheck,
93
+ isStockPhoto: fraudCheck.isStockPhoto,
94
+ },
95
+ };
96
+ }
97
+
98
+ // 2. Check for Unreadable / Poor Quality Image
99
+ const readabilityCheck = this._checkReadability({ clarityScore, width, height, fileSizeBytes });
100
+ if (!readabilityCheck.isReadable) {
101
+ reasons.push(...readabilityCheck.reasons);
102
+ const confidenceScore = Math.min(0.40, clarityScore * 0.5);
103
+ return {
104
+ valid: false,
105
+ status: DamageVerificationStatus.UNREADABLE,
106
+ confidenceScore: Number(confidenceScore.toFixed(2)),
107
+ detectedDamageTypes,
108
+ reasons,
109
+ details: {
110
+ clarityScore,
111
+ resolution: { width, height },
112
+ readabilityCheck,
113
+ },
114
+ };
115
+ }
116
+
117
+ // 3. Check for Detected Damage Evidence
118
+ if (detectedDamageTypes.length === 0) {
119
+ reasons.push('No recognized physical damage types detected in photo metadata');
120
+ return {
121
+ valid: false,
122
+ status: DamageVerificationStatus.INSUFFICIENT_EVIDENCE,
123
+ confidenceScore: 0.20,
124
+ detectedDamageTypes: [],
125
+ reasons,
126
+ details: {
127
+ clarityScore,
128
+ resolution: { width, height },
129
+ },
130
+ };
131
+ }
132
+
133
+ // 4. Compute Confidence Score for Authentic Damage
134
+ const confidenceScore = this._computeConfidence({
135
+ clarityScore,
136
+ width,
137
+ height,
138
+ exif,
139
+ detectedDamageTypes,
140
+ photo,
141
+ });
142
+
143
+ // Record photo hash if provided to prevent replay
144
+ if (imageHash) {
145
+ this.processedPhotos.set(imageHash, {
146
+ timestamp: Date.now(),
147
+ photoId: photo.photoId || photo.id,
148
+ });
149
+ }
150
+
151
+ const isAuthentic = confidenceScore >= this.confidenceThreshold;
152
+ if (!isAuthentic) {
153
+ reasons.push(`Confidence score (${confidenceScore}) below acceptance threshold (${this.confidenceThreshold})`);
154
+ }
155
+
156
+ return {
157
+ valid: isAuthentic,
158
+ status: isAuthentic ? DamageVerificationStatus.AUTHENTIC : DamageVerificationStatus.INSUFFICIENT_EVIDENCE,
159
+ confidenceScore,
160
+ detectedDamageTypes,
161
+ reasons,
162
+ details: {
163
+ clarityScore,
164
+ resolution: { width, height },
165
+ deviceModel: exif.deviceModel || null,
166
+ timestamp: exif.timestamp || null,
167
+ },
168
+ };
169
+ }
170
+
171
+ /**
172
+ * Generates automated replacement authorization payload for genuine damage.
173
+ * @param {Object} options
174
+ * @param {Object} options.evaluation - Damage evaluation result from evaluatePhoto
175
+ * @param {Object} options.claim - Customer claim details
176
+ * @param {Object} options.customer - Customer account details
177
+ * @param {Object} options.item - Product / hardware item details
178
+ * @returns {Object} Authorization payload
179
+ */
180
+ generateReplacementAuthorization({ evaluation, claim = {}, customer = {}, item = {} }) {
181
+ if (!evaluation || evaluation.status !== DamageVerificationStatus.AUTHENTIC) {
182
+ return {
183
+ authorized: false,
184
+ status: evaluation?.status === DamageVerificationStatus.FRAUDULENT
185
+ ? 'REJECTED_FRAUD_SUSPECTED'
186
+ : evaluation?.status === DamageVerificationStatus.UNREADABLE
187
+ ? 'REQUIRES_CLEARER_PHOTO'
188
+ : 'REQUIRES_MANUAL_REVIEW',
189
+ authorizationCode: null,
190
+ claimId: claim.id || claim.claimId || null,
191
+ customerId: customer.id || customer.customerId || null,
192
+ itemSku: item.sku || item.itemSku || null,
193
+ rejectionReason: evaluation ? evaluation.reasons.join('; ') : 'No valid evaluation provided',
194
+ damageAssessment: {
195
+ verifiedTypes: evaluation?.detectedDamageTypes || [],
196
+ confidenceScore: evaluation?.confidenceScore || 0,
197
+ status: evaluation?.status || DamageVerificationStatus.INSUFFICIENT_EVIDENCE,
198
+ },
199
+ replacementOrder: null,
200
+ requiresHumanReview: evaluation?.status === DamageVerificationStatus.FRAUDULENT || evaluation?.status === DamageVerificationStatus.INSUFFICIENT_EVIDENCE,
201
+ requiresPhotoReupload: evaluation?.status === DamageVerificationStatus.UNREADABLE,
202
+ };
203
+ }
204
+
205
+ const authorizationCode = generateAuthCode();
206
+ const returnLabelCode = `RET-LBL-${Date.now().toString(36).toUpperCase()}-${Math.random().toString(36).substring(2, 6).toUpperCase()}`;
207
+
208
+ return {
209
+ authorized: true,
210
+ status: 'APPROVED',
211
+ authorizationCode,
212
+ authorizedAt: new Date().toISOString(),
213
+ claimId: claim.id || claim.claimId || `CLM-${Date.now().toString(36).toUpperCase()}`,
214
+ customerId: customer.id || customer.customerId || 'CUST-ANON',
215
+ itemSku: item.sku || item.itemSku || item.productSku || 'SKU-GENERIC',
216
+ serialNumber: item.serialNumber || null,
217
+ damageAssessment: {
218
+ verifiedTypes: evaluation.detectedDamageTypes,
219
+ confidenceScore: evaluation.confidenceScore,
220
+ clarityScore: evaluation.details.clarityScore,
221
+ verificationStatus: evaluation.status,
222
+ },
223
+ replacementOrder: {
224
+ action: 'EXPEDITED_REPLACEMENT',
225
+ fulfillmentType: 'AUTONOMOUS_WAREHOUSE_DISPATCH',
226
+ shippingSpeed: 'NEXT_DAY_PRIORITY',
227
+ carrier: 'FedEx Priority Overnight',
228
+ returnRequired: true,
229
+ returnLabelCode,
230
+ estimatedDeliveryDays: 1,
231
+ },
232
+ summary: `Automated replacement authorized for authentic ${evaluation.detectedDamageTypes.join(', ')} damage (confidence: ${evaluation.confidenceScore}).`,
233
+ };
234
+ }
235
+
236
+ /**
237
+ * Convenience wrapper that evaluates photo and generates authorization in one step.
238
+ */
239
+ verifyDamageAndAuthorize({ photo, claim, customer, item }) {
240
+ const evaluation = this.evaluatePhoto(photo);
241
+ const authorization = this.generateReplacementAuthorization({
242
+ evaluation,
243
+ claim,
244
+ customer,
245
+ item,
246
+ });
247
+ return { evaluation, authorization };
248
+ }
249
+
250
+ _extractDamageTypes(photo) {
251
+ const raw = photo.detectedDamageTypes || photo.damageTypes || [];
252
+ const validTypes = new Set(Object.values(DamageType));
253
+ const extracted = [];
254
+
255
+ for (const item of raw) {
256
+ const typeStr = typeof item === 'string' ? item : item?.type;
257
+ if (typeStr && validTypes.has(typeStr) && !extracted.includes(typeStr)) {
258
+ extracted.push(typeStr);
259
+ }
260
+ }
261
+ return extracted;
262
+ }
263
+
264
+ _detectFraud({ photo, exif, url, imageHash }) {
265
+ const reasons = [];
266
+ let isStockPhoto = false;
267
+
268
+ // Direct stock photo flag
269
+ if (photo.isStockPhoto === true || exif.isStockPhoto === true) {
270
+ isStockPhoto = true;
271
+ reasons.push('Explicit stock photo flag detected in metadata');
272
+ }
273
+
274
+ // Watermark check
275
+ if (photo.watermarkDetected === true || exif.watermarkDetected === true) {
276
+ isStockPhoto = true;
277
+ reasons.push('Stock watermark detected in photo');
278
+ }
279
+
280
+ // Stock domains check in URL
281
+ if (url) {
282
+ const lowerUrl = url.toLowerCase();
283
+ for (const domain of this.stockDomains) {
284
+ if (lowerUrl.includes(domain)) {
285
+ isStockPhoto = true;
286
+ reasons.push(`Photo URL references known stock photography repository (${domain})`);
287
+ break;
288
+ }
289
+ }
290
+ }
291
+
292
+ // Source field check
293
+ if (photo.source === 'stock_library' || photo.source === 'web_search') {
294
+ isStockPhoto = true;
295
+ reasons.push(`Photo source marked as untrusted (${photo.source})`);
296
+ }
297
+
298
+ // Known fraudulent hashes
299
+ if (imageHash && this.knownFraudulentHashes.has(imageHash)) {
300
+ reasons.push('Image hash matches known fraudulent claim repository');
301
+ }
302
+
303
+ // Manipulated software check in EXIF
304
+ if (exif.software) {
305
+ for (const pattern of KNOWN_MANIPULATION_SOFTWARE) {
306
+ if (pattern.test(exif.software)) {
307
+ reasons.push(`Image altered using digital manipulation software (${exif.software})`);
308
+ break;
309
+ }
310
+ }
311
+ }
312
+
313
+ return {
314
+ isFraudulent: reasons.length > 0,
315
+ isStockPhoto,
316
+ reasons,
317
+ };
318
+ }
319
+
320
+ _checkReadability({ clarityScore, width, height, fileSizeBytes }) {
321
+ const reasons = [];
322
+
323
+ if (clarityScore < this.minClarityScore) {
324
+ reasons.push(`Image clarity score (${clarityScore}) is below minimum readable threshold (${this.minClarityScore})`);
325
+ }
326
+
327
+ if (width > 0 && width < this.minWidth) {
328
+ reasons.push(`Image width (${width}px) is below minimum threshold (${this.minWidth}px)`);
329
+ }
330
+
331
+ if (height > 0 && height < this.minHeight) {
332
+ reasons.push(`Image height (${height}px) is below minimum threshold (${this.minHeight}px)`);
333
+ }
334
+
335
+ if (fileSizeBytes > 0 && fileSizeBytes < this.minFileSizeBytes) {
336
+ reasons.push(`Image file size (${fileSizeBytes} bytes) is below readable quality limit (${this.minFileSizeBytes} bytes)`);
337
+ }
338
+
339
+ return {
340
+ isReadable: reasons.length === 0,
341
+ reasons,
342
+ };
343
+ }
344
+
345
+ _computeConfidence({ clarityScore, width, height, exif, detectedDamageTypes, photo }) {
346
+ // 1. Clarity weight (0.35)
347
+ const clarityContribution = clarityScore * 0.35;
348
+
349
+ // 2. Resolution & size weight (0.20)
350
+ let resScore = 0.70;
351
+ if (width >= 1920 && height >= 1080) {
352
+ resScore = 1.0;
353
+ } else if (width >= 1280 && height >= 720) {
354
+ resScore = 0.85;
355
+ }
356
+ const resolutionContribution = resScore * 0.20;
357
+
358
+ // 3. EXIF & Authenticity telemetry weight (0.25)
359
+ let exifScore = 0.50; // baseline for clean image without full camera telemetry
360
+ if (exif.deviceModel && exif.timestamp) {
361
+ exifScore = exif.gps ? 1.0 : 0.90;
362
+ } else if (exif.deviceModel || exif.cameraSerial) {
363
+ exifScore = 0.80;
364
+ }
365
+ const exifContribution = exifScore * 0.25;
366
+
367
+ // 4. Damage detection consistency weight (0.20)
368
+ let damageScore = 0.80;
369
+ if (Array.isArray(photo.detectedDamageTypes)) {
370
+ const confidences = photo.detectedDamageTypes
371
+ .filter((d) => typeof d === 'object' && typeof d.confidence === 'number')
372
+ .map((d) => d.confidence);
373
+ if (confidences.length > 0) {
374
+ damageScore = confidences.reduce((a, b) => a + b, 0) / confidences.length;
375
+ } else if (detectedDamageTypes.length >= 1) {
376
+ damageScore = 0.90;
377
+ }
378
+ }
379
+ const damageContribution = damageScore * 0.20;
380
+
381
+ const total = clarityContribution + resolutionContribution + exifContribution + damageContribution;
382
+ return Number(Math.min(1.0, Math.max(0, total)).toFixed(2));
383
+ }
384
+ }