@tracehound/core 1.3.0 → 1.4.3

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 (53) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +17 -30
  3. package/dist/core/agent.d.ts +8 -2
  4. package/dist/core/agent.d.ts.map +1 -1
  5. package/dist/core/agent.js +35 -7
  6. package/dist/core/agent.js.map +1 -1
  7. package/dist/core/evidence-worker-pool.d.ts +27 -0
  8. package/dist/core/evidence-worker-pool.d.ts.map +1 -0
  9. package/dist/core/evidence-worker-pool.js +87 -0
  10. package/dist/core/evidence-worker-pool.js.map +1 -0
  11. package/dist/core/evidence-worker.d.ts +20 -0
  12. package/dist/core/evidence-worker.d.ts.map +1 -0
  13. package/dist/core/evidence-worker.js +32 -0
  14. package/dist/core/evidence-worker.js.map +1 -0
  15. package/dist/core/hound-ipc.d.ts.map +1 -1
  16. package/dist/core/hound-ipc.js +14 -6
  17. package/dist/core/hound-ipc.js.map +1 -1
  18. package/dist/core/hound-pool.d.ts.map +1 -1
  19. package/dist/core/hound-pool.js +7 -1
  20. package/dist/core/hound-pool.js.map +1 -1
  21. package/dist/core/hound-process.js +2 -2
  22. package/dist/core/hound-process.js.map +1 -1
  23. package/dist/core/quarantine.d.ts +5 -0
  24. package/dist/core/quarantine.d.ts.map +1 -1
  25. package/dist/core/quarantine.js +7 -0
  26. package/dist/core/quarantine.js.map +1 -1
  27. package/dist/core/rate-limiter.d.ts +3 -0
  28. package/dist/core/rate-limiter.d.ts.map +1 -1
  29. package/dist/core/rate-limiter.js +21 -1
  30. package/dist/core/rate-limiter.js.map +1 -1
  31. package/dist/core/tracehound.d.ts.map +1 -1
  32. package/dist/core/tracehound.js +33 -3
  33. package/dist/core/tracehound.js.map +1 -1
  34. package/dist/index.d.ts +14 -14
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +13 -13
  37. package/dist/index.js.map +1 -1
  38. package/dist/types/config.d.ts +2 -0
  39. package/dist/types/config.d.ts.map +1 -1
  40. package/dist/types/config.js.map +1 -1
  41. package/package.json +4 -2
  42. package/dist/core/hound-worker.d.ts +0 -14
  43. package/dist/core/hound-worker.d.ts.map +0 -1
  44. package/dist/core/hound-worker.js +0 -112
  45. package/dist/core/hound-worker.js.map +0 -1
  46. package/dist/core/license-manager.d.ts +0 -128
  47. package/dist/core/license-manager.d.ts.map +0 -1
  48. package/dist/core/license-manager.js +0 -219
  49. package/dist/core/license-manager.js.map +0 -1
  50. package/dist/core/tier-capacity.d.ts +0 -58
  51. package/dist/core/tier-capacity.d.ts.map +0 -1
  52. package/dist/core/tier-capacity.js +0 -89
  53. package/dist/core/tier-capacity.js.map +0 -1
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026-2027 Erdem Arslan <me@erdem.work>
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md CHANGED
@@ -28,15 +28,10 @@ The main entry point. Orchestrates the threat detection flow.
28
28
  - **Fail-safe:** Defaults to "clean" on error.
29
29
 
30
30
  ```ts
31
- import {
32
- createAgent,
33
- createQuarantine,
34
- createRateLimiter,
35
- createEvidenceFactory,
36
- } from '@tracehound/core'
37
-
38
- const agent = createAgent({ maxPayloadSize: 1_000_000 })
39
- const result = agent.intercept(scent)
31
+ import { createTracehound } from '@tracehound/core'
32
+
33
+ const th = createTracehound({ maxPayloadSize: 1_000_000 })
34
+ const result = th.agent.intercept(scent)
40
35
  ```
41
36
 
42
37
  ### 2. Hound Pool (`IHoundPool`)
@@ -74,26 +69,18 @@ Background task management.
74
69
  ## Usage Example
75
70
 
76
71
  ```ts
77
- import {
78
- createAgent,
79
- createQuarantine,
80
- createRateLimiter,
81
- createEvidenceFactory,
82
- createHoundPool,
83
- AuditChain,
84
- } from '@tracehound/core'
85
-
86
- // 1. Setup Dependencies
87
- const auditChain = new AuditChain()
88
- const quarantine = createQuarantine({ maxCount: 1000 }, auditChain)
89
- const rateLimiter = createRateLimiter({ windowMs: 60000, maxRequests: 100 })
90
- const factory = createEvidenceFactory()
91
-
92
- // 2. Create Agent
93
- const agent = createAgent({ maxPayloadSize: 1_000_000 }, quarantine, rateLimiter, factory)
94
-
95
- // 3. Intercept Traffic
96
- const result = agent.intercept({
72
+ import { createTracehound } from '@tracehound/core'
73
+
74
+ // 1. Create Tracehound Instance
75
+ const th = createTracehound({
76
+ maxPayloadSize: 1_000_000,
77
+ quarantine: { maxCount: 1000 },
78
+ rateLimit: { windowMs: 60000, maxRequests: 100 },
79
+ houndPool: { poolSize: 4 }, // Automatically provisions process-separated workers
80
+ })
81
+
82
+ // 2. Intercept Traffic
83
+ const result = th.agent.intercept({
97
84
  id: 'req-1',
98
85
  source: '192.168.1.1',
99
86
  payload: { user: 'input' },
@@ -122,4 +109,4 @@ if (result.status === 'quarantined') {
122
109
 
123
110
  ## License
124
111
 
125
- Open-Core — this package is the open-source substrate of the Tracehound ecosystem. See the root [PRICING.md](../../docs/PRICING.md) for details on the commercial satellite packages.
112
+ Open-Core — this package is the open-source substrate of the Tracehound ecosystem.
@@ -12,8 +12,11 @@
12
12
  import type { InterceptResult } from '../types/result.js';
13
13
  import type { Scent } from '../types/scent.js';
14
14
  import type { IEvidenceFactory } from './evidence-factory.js';
15
+ import type { IHoundPool } from './hound-pool.js';
16
+ import type { INotificationEmitter } from './notification-emitter.js';
15
17
  import type { Quarantine } from './quarantine.js';
16
18
  import type { IRateLimiter } from './rate-limiter.js';
19
+ import type { IWatcher } from './watcher.js';
17
20
  /**
18
21
  * Agent configuration (subset of TracehoundConfig).
19
22
  */
@@ -68,8 +71,11 @@ export declare class Agent implements IAgent {
68
71
  private readonly quarantine;
69
72
  private readonly rateLimiter;
70
73
  private readonly evidenceFactory;
74
+ private readonly houndPool?;
75
+ private readonly watcher?;
76
+ private readonly notifications?;
71
77
  private readonly stats;
72
- constructor(config: AgentConfig, quarantine: Quarantine, rateLimiter: IRateLimiter, evidenceFactory: IEvidenceFactory);
78
+ constructor(config: AgentConfig, quarantine: Quarantine, rateLimiter: IRateLimiter, evidenceFactory: IEvidenceFactory, houndPool?: IHoundPool | undefined, watcher?: IWatcher | undefined, notifications?: INotificationEmitter | undefined);
73
79
  intercept(scent: Scent): InterceptResult;
74
80
  /**
75
81
  * Get current agent statistics.
@@ -85,5 +91,5 @@ export declare class Agent implements IAgent {
85
91
  * @param evidenceFactory - Evidence factory instance
86
92
  * @returns Agent instance
87
93
  */
88
- export declare function createAgent(config: AgentConfig, quarantine: Quarantine, rateLimiter: IRateLimiter, evidenceFactory: IEvidenceFactory): IAgent;
94
+ export declare function createAgent(config: AgentConfig, quarantine: Quarantine, rateLimiter: IRateLimiter, evidenceFactory: IEvidenceFactory, houndPool?: IHoundPool, watcher?: IWatcher, notifications?: INotificationEmitter): IAgent;
89
95
  //# sourceMappingURL=agent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/core/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,EAAE,YAAY,EAAmB,MAAM,mBAAmB,CAAA;AAEtE;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,oCAAoC;IACpC,cAAc,EAAE,MAAM,CAAA;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB;;;;;;;;;;;;;OAaG;IACH,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,eAAe,CAAA;CACzC;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,iCAAiC;IACjC,eAAe,EAAE,MAAM,CAAA;IACvB,+BAA+B;IAC/B,UAAU,EAAE,MAAM,CAAA;IAClB,mBAAmB;IACnB,gBAAgB,EAAE,MAAM,CAAA;IACxB,kCAAkC;IAClC,kBAAkB,EAAE,MAAM,CAAA;IAC1B,yBAAyB;IACzB,YAAY,EAAE,MAAM,CAAA;IACpB,+BAA+B;IAC/B,gBAAgB,EAAE,MAAM,CAAA;IACxB,aAAa;IACb,UAAU,EAAE,MAAM,CAAA;CACnB;AAED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B,WAAW,CACzB,MAAM,EAAE,WAAW,EACnB,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,YAAY,EACzB,eAAe,EAAE,gBAAgB,EACjC,SAAS,CAAC,EAAE,UAAU,EACtB,OAAO,CAAC,EAAE,QAAQ,EAClB,aAAa,CAAC,EAAE,oBAAoB,GACnC,MAAM,CAUR"}
@@ -17,6 +17,9 @@ export class Agent {
17
17
  quarantine;
18
18
  rateLimiter;
19
19
  evidenceFactory;
20
+ houndPool;
21
+ watcher;
22
+ notifications;
20
23
  stats = {
21
24
  totalIntercepts: 0,
22
25
  cleanCount: 0,
@@ -26,11 +29,14 @@ export class Agent {
26
29
  quarantinedCount: 0,
27
30
  errorCount: 0,
28
31
  };
29
- constructor(config, quarantine, rateLimiter, evidenceFactory) {
32
+ constructor(config, quarantine, rateLimiter, evidenceFactory, houndPool, watcher, notifications) {
30
33
  this.config = config;
31
34
  this.quarantine = quarantine;
32
35
  this.rateLimiter = rateLimiter;
33
36
  this.evidenceFactory = evidenceFactory;
37
+ this.houndPool = houndPool;
38
+ this.watcher = watcher;
39
+ this.notifications = notifications;
34
40
  // Validate config
35
41
  if (config.maxPayloadSize <= 0) {
36
42
  throw new Error('maxPayloadSize must be positive');
@@ -43,10 +49,12 @@ export class Agent {
43
49
  const rateResult = this.rateLimiter.check(scent.source);
44
50
  if (!rateResult.allowed) {
45
51
  this.stats.rateLimitedCount++;
46
- return {
47
- status: 'rate_limited',
48
- retryAfter: rateResult.retryAfter,
49
- };
52
+ const retryAfter = rateResult.retryAfter;
53
+ this.notifications?.emit('rate_limit.exceeded', {
54
+ source: scent.source,
55
+ retryAfterMs: retryAfter,
56
+ });
57
+ return { status: 'rate_limited', retryAfter };
50
58
  }
51
59
  // Step 2: Check for threat signal
52
60
  if (!scent.threat) {
@@ -55,6 +63,8 @@ export class Agent {
55
63
  this.stats.cleanCount++;
56
64
  return { status: 'clean' };
57
65
  }
66
+ // Record threat in Watcher (observability) — before any further processing
67
+ this.watcher?.recordThreat(scent.threat.category, scent.threat.severity);
58
68
  // Step 3: Create evidence via factory
59
69
  // Factory handles: validation, encoding, hashing, signature generation
60
70
  const creationResult = this.evidenceFactory.create(scent, scent.threat, this.config.maxPayloadSize);
@@ -97,6 +107,24 @@ export class Agent {
97
107
  signature,
98
108
  };
99
109
  }
110
+ // Forward quarantined evidence to HoundPool for async processing.
111
+ // This is the canonical wiring point: evidence is still typed as Evidence
112
+ // here (not yet narrowed to EvidenceHandle), enabling direct activation.
113
+ this.houndPool?.activate(evidence);
114
+ // Emit observability events — fire-and-forget, must not throw
115
+ const qStats = this.quarantine.stats;
116
+ this.notifications?.emit('threat.detected', {
117
+ scentId: scent.id,
118
+ category: scent.threat.category,
119
+ severity: scent.threat.severity,
120
+ source: scent.source,
121
+ });
122
+ this.notifications?.emit('evidence.quarantined', {
123
+ signature,
124
+ severity: scent.threat.severity,
125
+ sizeBytes: qStats.bytes,
126
+ });
127
+ this.watcher?.updateQuarantine(qStats.count, qStats.bytes, this.quarantine.maxBytes);
100
128
  // Success
101
129
  this.stats.quarantinedCount++;
102
130
  return {
@@ -135,7 +163,7 @@ export class Agent {
135
163
  * @param evidenceFactory - Evidence factory instance
136
164
  * @returns Agent instance
137
165
  */
138
- export function createAgent(config, quarantine, rateLimiter, evidenceFactory) {
139
- return new Agent(config, quarantine, rateLimiter, evidenceFactory);
166
+ export function createAgent(config, quarantine, rateLimiter, evidenceFactory, houndPool, watcher, notifications) {
167
+ return new Agent(config, quarantine, rateLimiter, evidenceFactory, houndPool, watcher, notifications);
140
168
  }
141
169
  //# sourceMappingURL=agent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent.js","sourceRoot":"","sources":["../../src/core/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA0DH;;GAEG;AACH,MAAM,OAAO,KAAK;IAYG;IACA;IACA;IACA;IAdF,KAAK,GAAe;QACnC,eAAe,EAAE,CAAC;QAClB,UAAU,EAAE,CAAC;QACb,gBAAgB,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AAA;QACH,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAA;YAEvB,MAAM,eAAe,GAAoB;gBACvC,KAAK,EAAE,OAAO;gBACd,IAAI,EAAE,kBAAkB;gBACxB,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,gCAAgC;gBAClF,OAAO,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,EAAE;gBAC9B,WAAW,EAAE,KAAK;aACnB,CAAA;YAED,OAAO;gBACL,MAAM,EAAE,OAAO;gBACf,KAAK,EAAE,eAAe;aACvB,CAAA;QACH,CAAC;IACH,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,CAAA;IAC1B,CAAC;CACF;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CACzB,MAAmB,EACnB,UAAsB,EACtB,WAAyB,EACzB,eAAiC;IAEjC,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,CAAC,CAAA;AACpE,CAAC"}
1
+ {"version":3,"file":"agent.js","sourceRoot":"","sources":["../../src/core/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA6DH;;GAEG;AACH,MAAM,OAAO,KAAK;IAYG;IACA;IACA;IACA;IACA;IACA;IACA;IAjBF,KAAK,GAAe;QACnC,eAAe,EAAE,CAAC;QAClB,UAAU,EAAE,CAAC;QACb,gBAAgB,EAAE,CAAC;QACnB,kBAAkB,EAAE,CAAC;QACrB,YAAY,EAAE,CAAC;QACf,gBAAgB,EAAE,CAAC;QACnB,UAAU,EAAE,CAAC;KACd,CAAA;IAED,YACmB,MAAmB,EACnB,UAAsB,EACtB,WAAyB,EACzB,eAAiC,EACjC,SAAsB,EACtB,OAAkB,EAClB,aAAoC;QANpC,WAAM,GA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OAAO,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,EAAE;gBAC9B,WAAW,EAAE,KAAK;aACnB,CAAA;YAED,OAAO;gBACL,MAAM,EAAE,OAAO;gBACf,KAAK,EAAE,eAAe;aACvB,CAAA;QACH,CAAC;IACH,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,CAAA;IAC1B,CAAC;CACF;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CACzB,MAAmB,EACnB,UAAsB,EACtB,WAAyB,EACzB,eAAiC,EACjC,SAAsB,EACtB,OAAkB,EAClB,aAAoC;IAEpC,OAAO,IAAI,KAAK,CACd,MAAM,EACN,UAAU,EACV,WAAW,EACX,eAAe,EACf,SAAS,EACT,OAAO,EACP,aAAa,CACd,CAAA;AACH,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { Scent, ThreatSignal } from '../types/scent.js';
2
+ import type { HotPathCodec } from '../utils/binary-codec.js';
3
+ import type { IHoundPool } from './hound-pool.js';
4
+ import type { Quarantine } from './quarantine.js';
5
+ export interface EvidenceWorkerPoolOptions {
6
+ poolSize?: number;
7
+ quarantine: Quarantine;
8
+ maxPayloadSize: number;
9
+ codec?: HotPathCodec;
10
+ houndPool?: IHoundPool;
11
+ }
12
+ export declare class EvidenceWorkerPool {
13
+ private readonly options;
14
+ private workers;
15
+ private nextWorkerIndex;
16
+ private pendingJobs;
17
+ constructor(options: EvidenceWorkerPoolOptions);
18
+ /**
19
+ * Dispatches a scent to the worker pool for async Hash and Evidence creation.
20
+ * Does NOT return a promise to avoid blocking the caller. It internally
21
+ * updates the Quarantine cache once the true Hash is ready.
22
+ */
23
+ dispatch(scent: Scent, threat: ThreatSignal, temporarySignature: string): void;
24
+ private handleWorkerMessage;
25
+ shutdown(): Promise<void>;
26
+ }
27
+ //# sourceMappingURL=evidence-worker-pool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evidence-worker-pool.d.ts","sourceRoot":"","sources":["../../src/core/evidence-worker-pool.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAG5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,UAAU,CAAA;IACtB,cAAc,EAAE,MAAM,CAAA;IACtB,KAAK,CAAC,EAAE,YAAY,CAAA;IACpB,SAAS,CAAC,EAAE,UAAU,CAAA;CACvB;AAED,qBAAa,kBAAkB;IAcjB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAbpC,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,eAAe,CAAI;IAC3B,OAAO,CAAC,WAAW,CAShB;gBAE0B,OAAO,EAAE,yBAAyB;IAyB/D;;;;OAIG;IACI,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,GAAG,IAAI;IA2BrF,OAAO,CAAC,mBAAmB;IAwCd,QAAQ;CAItB"}
@@ -0,0 +1,87 @@
1
+ import { dirname, join } from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { Worker } from 'node:worker_threads';
4
+ import { Evidence } from './evidence.js';
5
+ export class EvidenceWorkerPool {
6
+ options;
7
+ workers = [];
8
+ nextWorkerIndex = 0;
9
+ pendingJobs = new Map();
10
+ constructor(options) {
11
+ this.options = options;
12
+ const size = options.poolSize || 2;
13
+ const __filename = fileURLToPath(import.meta.url);
14
+ const __dirname = dirname(__filename);
15
+ // We assume the compiled .js file is next to us in dist
16
+ // EXCEPT during testing/benchmarking with tsx, where we load the .ts file
17
+ const ext = process.env['VITEST'] || __filename.endsWith('.ts') ? '.ts' : '.js';
18
+ const workerScript = join(__dirname, `evidence-worker${ext}`);
19
+ for (let i = 0; i < size; i++) {
20
+ const worker = new Worker(workerScript);
21
+ worker.on('message', (result) => {
22
+ this.handleWorkerMessage(result);
23
+ });
24
+ worker.on('error', (err) => {
25
+ console.error(`EvidenceWorkerPool Worker Error:`, err);
26
+ });
27
+ this.workers.push(worker);
28
+ }
29
+ }
30
+ /**
31
+ * Dispatches a scent to the worker pool for async Hash and Evidence creation.
32
+ * Does NOT return a promise to avoid blocking the caller. It internally
33
+ * updates the Quarantine cache once the true Hash is ready.
34
+ */
35
+ dispatch(scent, threat, temporarySignature) {
36
+ if (this.workers.length === 0)
37
+ return;
38
+ const worker = this.workers[this.nextWorkerIndex];
39
+ if (!worker)
40
+ return;
41
+ this.nextWorkerIndex = (this.nextWorkerIndex + 1) % this.workers.length;
42
+ // Register job to backfill Quarantine later
43
+ this.pendingJobs.set(scent.id, {
44
+ resolve: () => { }, // Handled directly in message listener now
45
+ reject: () => { },
46
+ temporarySignature,
47
+ threat,
48
+ timestamp: scent.timestamp,
49
+ });
50
+ const msg = {
51
+ id: scent.id,
52
+ scent,
53
+ threat,
54
+ maxPayloadSize: this.options.maxPayloadSize,
55
+ };
56
+ worker.postMessage(msg);
57
+ }
58
+ handleWorkerMessage(result) {
59
+ const job = this.pendingJobs.get(result.id);
60
+ if (!job)
61
+ return;
62
+ this.pendingJobs.delete(result.id);
63
+ if (!result.ok || !result.bytes || !result.hash || !result.signature) {
64
+ // Worker failed (e.g., payload too large check failed inside worker)
65
+ // We must purge the temporary evidence from Quarantine
66
+ this.options.quarantine.purge(job.temporarySignature, 'error');
67
+ return;
68
+ }
69
+ let finalBytes = result.bytes;
70
+ let compressed = false;
71
+ if (this.options.codec) {
72
+ finalBytes = this.options.codec.encode(result.bytes);
73
+ compressed = true;
74
+ }
75
+ // Build the TRUE Evidence Object
76
+ const trueEvidence = new Evidence(finalBytes.buffer.slice(finalBytes.byteOffset, finalBytes.byteOffset + finalBytes.byteLength), result.signature, result.hash, job.threat.severity, job.timestamp, compressed);
77
+ // Backfill Quarantine: Replace the temporary UUID signature with the True Signature
78
+ this.options.quarantine.replace(job.temporarySignature, trueEvidence);
79
+ // Notify WAF via HoundPool now that parsing and hashing are complete
80
+ this.options.houndPool?.activate(trueEvidence);
81
+ }
82
+ async shutdown() {
83
+ await Promise.all(this.workers.map((w) => w.terminate()));
84
+ this.workers = [];
85
+ }
86
+ }
87
+ //# sourceMappingURL=evidence-worker-pool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evidence-worker-pool.js","sourceRoot":"","sources":["../../src/core/evidence-worker-pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAI5C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAYxC,MAAM,OAAO,kBAAkB;IAcA;IAbrB,OAAO,GAAa,EAAE,CAAA;IACtB,eAAe,GAAG,CAAC,CAAA;IACnB,WAAW,GAAG,IAAI,GAAG,EAS1B,CAAA;IAEH,YAA6B,OAAkC;QAAlC,YAAO,GAAP,OAAO,CAA2B;QAC7D,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAA;QAClC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QACjD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;QAErC,wDAAwD;QACxD,0EAA0E;QAC1E,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC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C,IAAI,EACX,GAAG,CAAC,MAAM,CAAC,QAAQ,EACnB,GAAG,CAAC,SAAS,EACb,UAAU,CACX,CAAA;QAED,oFAAoF;QACpF,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,YAAY,CAAC,CAAA;QAErE,qEAAqE;QACrE,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAA;IAChD,CAAC;IAEM,KAAK,CAAC,QAAQ;QACnB,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAA;QACzD,IAAI,CAAC,OAAO,GAAG,EAAE,CAAA;IACnB,CAAC;CACF"}
@@ -0,0 +1,20 @@
1
+ import type { Scent, ThreatSignal } from '../types/scent.js';
2
+ export interface EvidenceWorkerMessage {
3
+ id: string;
4
+ scent: Scent;
5
+ threat: ThreatSignal;
6
+ maxPayloadSize: number;
7
+ }
8
+ export interface EvidenceWorkerResult {
9
+ id: string;
10
+ ok: boolean;
11
+ hash?: string;
12
+ signature?: string;
13
+ size?: number;
14
+ bytes?: Uint8Array;
15
+ error?: {
16
+ code: string;
17
+ message: string;
18
+ };
19
+ }
20
+ //# sourceMappingURL=evidence-worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evidence-worker.d.ts","sourceRoot":"","sources":["../../src/core/evidence-worker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAI5D,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,KAAK,CAAA;IACZ,MAAM,EAAE,YAAY,CAAA;IACpB,cAAc,EAAE,MAAM,CAAA;CACvB;AAED,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,MAAM,CAAA;IACV,EAAE,EAAE,OAAO,CAAA;IACX,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,UAAU,CAAA;IAClB,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,MAAM,CAAA;KAChB,CAAA;CACF"}
@@ -0,0 +1,32 @@
1
+ import { parentPort } from 'node:worker_threads';
2
+ import { encodePayload } from '../utils/encode.js';
3
+ import { hashBuffer } from '../utils/hash.js';
4
+ if (parentPort) {
5
+ parentPort.on('message', (msg) => {
6
+ try {
7
+ const encoded = encodePayload(msg.scent.payload, msg.maxPayloadSize);
8
+ const hash = hashBuffer(encoded.bytes);
9
+ const signature = `${msg.threat.category}:${hash}`;
10
+ const result = {
11
+ id: msg.id,
12
+ ok: true,
13
+ hash,
14
+ signature,
15
+ size: encoded.size,
16
+ bytes: encoded.bytes,
17
+ };
18
+ parentPort.postMessage(result, [result.bytes.buffer]);
19
+ }
20
+ catch (err) {
21
+ parentPort.postMessage({
22
+ id: msg.id,
23
+ ok: false,
24
+ error: {
25
+ code: err.code || 'UNKNOWN_WORKER_ERROR',
26
+ message: err.message || 'Error processing evidence in worker',
27
+ },
28
+ });
29
+ }
30
+ });
31
+ }
32
+ //# sourceMappingURL=evidence-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evidence-worker.js","sourceRoot":"","sources":["../../src/core/evidence-worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAEhD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAsB7C,IAAI,UAAU,EAAE,CAAC;IACf,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,GAA0B,EAAE,EAA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AE,QAAQ,CAAA;IACd,KAAK,EAAE,WAAW,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,SAAS,CAAA;IACf,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,MAAM,YAAY,GAAG,kBAAkB,GAAG,mBAAmB,CAAA;AAEnE;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,WAAW,CAAA;IACpB,aAAa,EAAE,MAAM,CAAA;CACtB;AAgBD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,CAiB1D;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,CA8BhE;AAmBD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CA2BpE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,WAAW,GAAG,YAAY,CAqCrE;AAmBD;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,EAAE,CAAA;IAElC;;OAEG;IACH,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAE9B;;OAEG;IACH,KAAK,IAAI,IAAI,CAAA;CACd;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,aAAa,CAqCnD"}
@@ -176,12 +176,20 @@ export function createMessageParser() {
176
176
  buffer = Buffer.concat([buffer, chunk]);
177
177
  const messages = [];
178
178
  // Parse all complete messages
179
- while (true) {
180
- const result = tryParseMessage(buffer);
181
- if (!result)
182
- break;
183
- messages.push(result.payload);
184
- buffer = buffer.subarray(result.bytesConsumed);
179
+ try {
180
+ while (true) {
181
+ const result = tryParseMessage(buffer);
182
+ if (!result)
183
+ break;
184
+ messages.push(result.payload);
185
+ buffer = buffer.subarray(result.bytesConsumed);
186
+ }
187
+ }
188
+ catch (error) {
189
+ // Safety invariant: malformed frames MUST NOT keep parser
190
+ // in a corrupted/amplifying buffered state.
191
+ buffer = Buffer.alloc(0);
192
+ throw error;
185
193
  }
186
194
  return messages;
187
195
  },