@slicedearth/whoisleuth-cli 1.45.0 → 2.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 (268) hide show
  1. package/DISCLOSURE +7 -3
  2. package/NOTICE +5 -4
  3. package/README.md +74 -124
  4. package/SECURITY.md +6 -3
  5. package/bin/whoisleuth.mjs +7 -4
  6. package/cli/archive-inspect.mjs +28 -10
  7. package/cli/arguments.mjs +450 -173
  8. package/cli/artifact-structure.mjs +2507 -0
  9. package/cli/artifact-verify.mjs +286 -64
  10. package/cli/bounded-json.mjs +1 -0
  11. package/cli/bulk-checkpoint.mjs +35 -23
  12. package/cli/bulk-command-runner.mjs +2 -5
  13. package/cli/bulk.mjs +9 -2
  14. package/cli/case-pack.mjs +435 -46
  15. package/cli/ci-report.mjs +6 -1
  16. package/cli/collection-preflight.mjs +2 -2
  17. package/cli/command-catalogue.mjs +12 -3
  18. package/cli/command-reference.mjs +948 -106
  19. package/cli/completion.mjs +504 -218
  20. package/cli/config-profile.mjs +13 -3
  21. package/cli/ct-event-intake.mjs +32 -2
  22. package/cli/discover.mjs +7 -1
  23. package/cli/discovery-observation-snapshot.mjs +24 -28
  24. package/cli/discovery-scan-command-runner.mjs +13 -14
  25. package/cli/discovery-scan.mjs +17 -3
  26. package/cli/discovery-snapshot.mjs +15 -7
  27. package/cli/discovery-workflow.mjs +2 -3
  28. package/cli/doctor.mjs +2 -2
  29. package/cli/domain-control-monitor.mjs +215 -36
  30. package/cli/domain-control-observations.mjs +34 -17
  31. package/cli/errors.mjs +8 -3
  32. package/cli/evidence-command-runner.mjs +17 -11
  33. package/cli/evidence-signing.mjs +68 -50
  34. package/cli/export-evidence.mjs +11 -4
  35. package/cli/external-observation-mapping.mjs +3 -3
  36. package/cli/formatters/html.mjs +3 -3
  37. package/cli/formatters/json.mjs +20 -32
  38. package/cli/formatters/terminal.mjs +586 -22
  39. package/cli/input.mjs +62 -0
  40. package/cli/interactive-launcher.mjs +226 -0
  41. package/cli/interchange-report.mjs +226 -0
  42. package/cli/investigation-manifest.mjs +16 -17
  43. package/cli/investigation-plan.mjs +167 -16
  44. package/cli/investigation-run.mjs +80 -24
  45. package/cli/local-mmdb-review.mjs +45 -14
  46. package/cli/lookalike-calibration.mjs +3 -1
  47. package/cli/lookup-brief.mjs +13 -8
  48. package/cli/lookup-browser.mjs +844 -0
  49. package/cli/lookup-command-runner.mjs +96 -33
  50. package/cli/lookup-diff.mjs +11 -2
  51. package/cli/lookup-plan.mjs +1 -0
  52. package/cli/mail-review.mjs +206 -94
  53. package/cli/manual.mjs +5 -5
  54. package/cli/network-command-runner.mjs +78 -0
  55. package/cli/offline-evidence-review.mjs +45 -14
  56. package/cli/open-asset-model-bridge.mjs +1 -1
  57. package/cli/output-file.mjs +70 -14
  58. package/cli/page-compare.mjs +18 -10
  59. package/cli/progress-events.mjs +2 -1
  60. package/cli/progress.mjs +3 -3
  61. package/cli/registry-cohort.mjs +343 -61
  62. package/cli/registry-doctor.mjs +67 -28
  63. package/cli/registry-support.mjs +2 -1
  64. package/cli/retained-artifact-diff.mjs +375 -0
  65. package/cli/risk-calibration.mjs +89 -40
  66. package/cli/runner.mjs +322 -246
  67. package/cli/saved-lookup.mjs +439 -49
  68. package/cli/sharing-review.mjs +18 -7
  69. package/cli/source-reliability.mjs +75 -36
  70. package/cli/terminal-presentation.mjs +43 -18
  71. package/docs/cli-reference.md +125 -1334
  72. package/docs/cli.md +87 -236
  73. package/frontend/src/lib/analysis/domain-control-manifest-core.js +3 -0
  74. package/frontend/src/lib/analysis/domain-control-records.js +3 -0
  75. package/lib/application-version.mjs +3 -0
  76. package/lib/availability.mjs +72 -52
  77. package/lib/bounded-contract-normalizers.mjs +2 -4
  78. package/lib/bounded-file.mjs +91 -4
  79. package/lib/bounded-json.mjs +287 -0
  80. package/lib/browser-library-profile.mjs +1 -1
  81. package/lib/certificate-extension-profile.mjs +2 -1
  82. package/lib/classify.mjs +56 -5
  83. package/lib/client-behavior-profile.mjs +1 -1
  84. package/lib/credential-surface-profile.mjs +1 -1
  85. package/lib/cryptographic-assurance.mjs +173 -0
  86. package/lib/ct-query.mjs +3 -3
  87. package/lib/ct-search.mjs +120 -64
  88. package/lib/distributed-operation-budget.mjs +4 -2
  89. package/lib/dns-delegation-health.mjs +9 -6
  90. package/lib/dns-intelligence.mjs +4 -3
  91. package/lib/dns-resolver-selection.mjs +6 -4
  92. package/lib/dnssec-chain-validation.mjs +1052 -0
  93. package/lib/dnssec-evidence-validation.mjs +23 -10
  94. package/lib/domain-assurance.mjs +12 -12
  95. package/lib/domain-change-packet.mjs +7 -5
  96. package/lib/domain-control-flight-recorder.mjs +442 -78
  97. package/lib/domain-control-manifest.mjs +314 -171
  98. package/lib/domain-posture-analysis.mjs +5 -2
  99. package/lib/domain-posture.mjs +7 -4
  100. package/lib/encrypted-dns-contract.mjs +2 -3
  101. package/lib/evidence-export.mjs +1243 -88
  102. package/lib/evidence-report-markdown.mjs +3 -0
  103. package/lib/evidence-report.mjs +5 -0
  104. package/lib/external-intelligence-risk.mjs +26 -10
  105. package/lib/favicon.mjs +8 -5
  106. package/lib/feature-policy.mjs +1 -1
  107. package/lib/homepage-metadata-contract.mjs +290 -0
  108. package/lib/hostname.mjs +1 -1
  109. package/lib/html-signals.mjs +89 -5
  110. package/lib/http-evidence-bounds.mjs +3 -0
  111. package/lib/http-intelligence.mjs +332 -6
  112. package/lib/interchange-fidelity-registry.mjs +124 -0
  113. package/lib/local-geoip-evidence.mjs +2 -1
  114. package/lib/lookup-cache.mjs +6 -4
  115. package/lib/lookup-network-evidence-bounds.mjs +9 -0
  116. package/lib/lookup.mjs +27 -4
  117. package/lib/observed-network-context.mjs +1 -1
  118. package/lib/outbound-identity.mjs +2 -3
  119. package/lib/page-fingerprints.mjs +2 -2
  120. package/lib/page-role-profile.mjs +1 -1
  121. package/lib/perceptual-hash.mjs +12 -4
  122. package/lib/portable-generator.mjs +29 -0
  123. package/lib/provider-policy-admission.mjs +11 -4
  124. package/lib/rdap-bootstrap.mjs +76 -16
  125. package/lib/rdap-client.mjs +20 -12
  126. package/lib/rdap-normalization.mjs +324 -80
  127. package/lib/rdap-registrar.mjs +5 -1
  128. package/lib/rdap-transport.mjs +2 -2
  129. package/lib/rdap-validation.mjs +65 -14
  130. package/lib/rdap.mjs +2 -2
  131. package/lib/registrable-domain.mjs +36 -0
  132. package/lib/registry-capabilities.mjs +3 -0
  133. package/lib/registry-capability-catalogue.mjs +12 -2
  134. package/lib/registry-comparison.mjs +28 -11
  135. package/lib/registry-insights.mjs +7 -0
  136. package/lib/response-policy.mjs +27 -4
  137. package/lib/risk-calibration-summary.mjs +340 -0
  138. package/lib/risk-scoring.mjs +4 -3
  139. package/lib/rpki-evidence.mjs +9 -8
  140. package/lib/safe-fetch.mjs +121 -50
  141. package/lib/security-txt.mjs +27 -4
  142. package/lib/service-binding-dns.mjs +6 -1
  143. package/lib/smtp-transport-review.mjs +787 -0
  144. package/lib/sslbl-certificates.generated.mjs +136 -134
  145. package/lib/sslbl-intelligence.mjs +6 -8
  146. package/lib/static-html-analysis.mjs +301 -4
  147. package/lib/structured-data-identity.mjs +51 -19
  148. package/lib/threat-intelligence-fixtures.mjs +2 -4
  149. package/lib/threat-intelligence-manifests.mjs +2 -7
  150. package/lib/threat-intelligence-runtime.mjs +5 -15
  151. package/lib/threat-intelligence-types.mjs +21 -1
  152. package/lib/threatfox-intelligence.mjs +7 -3
  153. package/lib/tls-intelligence.mjs +15 -9
  154. package/lib/tlsa-evidence.mjs +37 -7
  155. package/lib/urlhaus-intelligence.mjs +4 -2
  156. package/lib/urlscan-intelligence.mjs +6 -5
  157. package/lib/website-security-posture.mjs +1 -1
  158. package/lib/website-technology.mjs +1 -1
  159. package/lib/whois-authority.mjs +43 -8
  160. package/lib/whois-chain.mjs +25 -3
  161. package/lib/whois-normalization.mjs +3 -1
  162. package/lib/whois-transport.mjs +12 -3
  163. package/lib/zone-intent-review.mjs +1 -1
  164. package/package.json +12 -4
  165. package/packages/cases/case-brand-profile-references.mjs +85 -0
  166. package/{frontend/src/lib/analysis/case-evidence-model.js → packages/cases/case-evidence-model.mjs} +43 -14
  167. package/packages/cases/case-investigation-branch-model.mjs +132 -0
  168. package/packages/cases/case-migration-model.mjs +476 -0
  169. package/{frontend/src/lib/analysis/case-model.js → packages/cases/case-model.mjs} +3 -3
  170. package/{frontend/src/lib/analysis/case-record-contracts.js → packages/cases/case-record-contracts.mjs} +3 -19
  171. package/{frontend/src/lib/analysis/case-record-core.js → packages/cases/case-record-core.mjs} +58 -31
  172. package/packages/cases/case-record-model.mjs +9 -0
  173. package/{frontend/src/lib/analysis/case-record-operations.js → packages/cases/case-record-operations.mjs} +106 -33
  174. package/{frontend/src/lib/analysis/case-report.js → packages/cases/case-report.mjs} +143 -16
  175. package/packages/cases/case-response-model.mjs +1604 -0
  176. package/packages/cases/case-response-packet.mjs +1312 -0
  177. package/{frontend/src/lib/analysis/case-storage-model.js → packages/cases/case-storage-model.mjs} +2 -2
  178. package/{frontend/src/lib/analysis/http-summary.js → packages/cases/http-summary.mjs} +1 -1
  179. package/packages/cases/opaque-reference-id.mjs +9 -0
  180. package/packages/comparison/comparison-ledger-bulk.mjs +366 -0
  181. package/packages/comparison/comparison-ledger-contract.mjs +241 -0
  182. package/packages/comparison/comparison-ledger-json.mjs +80 -0
  183. package/packages/comparison/comparison-ledger-serialization.mjs +52 -0
  184. package/packages/comparison/favicon-similarity.mjs +78 -0
  185. package/{frontend/src/lib/analysis/page-similarity.js → packages/comparison/page-similarity.mjs} +4 -3
  186. package/{frontend/src/lib/analysis/relationship-evidence.js → packages/comparison/relationship-evidence.mjs} +6 -7
  187. package/packages/contracts/analyst-review-state-contract.mjs +61 -0
  188. package/packages/contracts/analyst-review-state.mjs +50 -0
  189. package/packages/contracts/case-portability.mjs +1310 -0
  190. package/packages/contracts/cli-command-catalogue.mjs +2 -0
  191. package/packages/contracts/cli-lookup.mjs +394 -0
  192. package/packages/contracts/domain-control-flight-recorder.mjs +461 -0
  193. package/packages/contracts/domain-control-manifest.mjs +1027 -0
  194. package/packages/contracts/domain-control-monitor.mjs +310 -0
  195. package/packages/contracts/domain-control-review.mjs +828 -0
  196. package/packages/contracts/domain-name.mjs +4 -0
  197. package/packages/contracts/external-observation-interchange.mjs +224 -0
  198. package/packages/contracts/extracted-domain-lifecycle.mjs +218 -0
  199. package/packages/contracts/investigation-portability.mjs +331 -0
  200. package/packages/contracts/offline-comparison.mjs +160 -0
  201. package/packages/contracts/risk-calibration.mjs +1288 -0
  202. package/packages/contracts/schema-compatibility.mjs +71 -0
  203. package/packages/contracts/schema-lifecycle.mjs +1702 -0
  204. package/packages/contracts/sslbl-snapshot.mjs +17 -0
  205. package/packages/contracts/workspace-portability.mjs +1347 -0
  206. package/packages/evidence/artifact-integrity.mjs +65 -0
  207. package/packages/evidence/decision-fact.mjs +735 -0
  208. package/packages/evidence/domain-control-runtime.mjs +547 -0
  209. package/packages/evidence/domain-name.mjs +41 -0
  210. package/packages/evidence/observation.mjs +384 -0
  211. package/{frontend/src/lib/analysis/external-findings-import.js → packages/interchange/external-findings-import.mjs} +86 -20
  212. package/packages/interchange/retained-text.mjs +8 -0
  213. package/{frontend/src/lib/analysis/acquisition-decision-packet.js → packages/investigation/acquisition-decision-packet.mjs} +11 -8
  214. package/{frontend/src/lib/analysis/bulk-domain-comparison.js → packages/investigation/bulk-domain-comparison.mjs} +28 -9
  215. package/{frontend/src/lib/analysis/bulk-mail-exposure.js → packages/investigation/bulk-mail-exposure.mjs} +67 -18
  216. package/{frontend/src/lib/analysis/bulk-review-export.js → packages/investigation/bulk-review-export.mjs} +10 -9
  217. package/packages/investigation/bulk-review-policy.mjs +1 -0
  218. package/{frontend/src/lib/analysis/investigation-capsule.js → packages/investigation/investigation-capsule.mjs} +50 -18
  219. package/packages/investigation/lookup-artefact-inputs.mjs +1 -0
  220. package/{frontend/src/lib/analysis/lookup-asset-graph.js → packages/investigation/lookup-asset-graph.mjs} +4 -2
  221. package/packages/investigation/lookup-claim-passport.mjs +232 -0
  222. package/packages/investigation/lookup-claim-readiness.mjs +287 -0
  223. package/packages/investigation/lookup-investigation-brief.mjs +172 -0
  224. package/packages/monitoring/analyst-review-state.mjs +680 -0
  225. package/{frontend/src/lib/analysis/brand-profile-model.js → packages/workspace/brand-profile-model.mjs} +97 -50
  226. package/{frontend/src/lib/analysis/bulk-review-model.js → packages/workspace/bulk-review-model.mjs} +15 -15
  227. package/{frontend/src/lib/analysis/bulk-session-model.js → packages/workspace/bulk-session-model.mjs} +179 -39
  228. package/{frontend/src/lib/analysis/bulk-sort.js → packages/workspace/bulk-sort.mjs} +12 -5
  229. package/{frontend/src/lib/analysis/campaign-model.js → packages/workspace/campaign-model.mjs} +20 -22
  230. package/{frontend/src/lib/analysis/detection-rule-model.js → packages/workspace/detection-rule-model.mjs} +15 -17
  231. package/packages/workspace/hostile-input.mjs +172 -0
  232. package/{frontend/src/lib/analysis/investigation-guide.js → packages/workspace/investigation-guide.mjs} +51 -46
  233. package/{frontend/src/lib/analysis/investigation-template-model.js → packages/workspace/investigation-template-model.mjs} +15 -15
  234. package/{frontend/src/lib/analysis/page-baseline.js → packages/workspace/page-baseline.mjs} +6 -13
  235. package/{frontend/src/lib/analysis/relationship-observation-model.js → packages/workspace/relationship-observation-model.mjs} +13 -17
  236. package/{frontend/src/lib/analysis/shortlist-model.js → packages/workspace/shortlist-model.mjs} +20 -18
  237. package/{frontend/src/lib/analysis/watchlist-history.js → packages/workspace/watchlist-history.mjs} +9 -16
  238. package/{frontend/src/lib/analysis/watchlist-store.js → packages/workspace/watchlist-store.mjs} +24 -17
  239. package/{frontend/src/lib/analysis/website-snapshot-model.js → packages/workspace/website-snapshot-model.mjs} +18 -12
  240. package/{frontend/src/lib/analysis/workspace-archive-crypto.js → packages/workspace/workspace-archive-crypto.mjs} +49 -19
  241. package/{frontend/src/lib/analysis/workspace-archive.js → packages/workspace/workspace-archive.mjs} +195 -84
  242. package/third-party-notices.txt +112 -5834
  243. package/frontend/src/lib/analysis/artifact-integrity.js +0 -21
  244. package/frontend/src/lib/analysis/bulk-retry-plan.js +0 -79
  245. package/frontend/src/lib/analysis/bulk-source-coverage.js +0 -76
  246. package/frontend/src/lib/analysis/case-migration-model.js +0 -253
  247. package/frontend/src/lib/analysis/case-record-model.js +0 -7
  248. package/frontend/src/lib/analysis/case-response-model.js +0 -669
  249. package/frontend/src/lib/analysis/case-response-packet.js +0 -573
  250. package/frontend/src/lib/analysis/lookup-decision-support.js +0 -487
  251. package/frontend/src/lib/analysis/lookup-investigation-brief.js +0 -153
  252. package/frontend/src/lib/analysis/lookup-presentation.js +0 -58
  253. package/frontend/src/lib/analysis/lookup-response.js +0 -2
  254. package/frontend/src/lib/analysis/lookup-source-refresh.js +0 -277
  255. package/frontend/src/lib/analysis/lookup-summary-model.js +0 -398
  256. package/frontend/src/lib/analysis/scoring.js +0 -55
  257. package/frontend/src/lib/analysis/utils.js +0 -232
  258. package/frontend/src/lib/analysis/visualization-bounds.js +0 -26
  259. package/frontend/src/lib/analysis/visualization-force-graph.js +0 -352
  260. package/frontend/src/lib/analysis/visualization-matrix.js +0 -88
  261. package/frontend/src/lib/analysis/visualization-models.js +0 -369
  262. package/frontend/src/lib/analysis/visualization-time-series.js +0 -144
  263. package/lib/bounded-json-response.mjs +0 -157
  264. package/lib/lookup-response-contract.mjs +0 -346
  265. package/lib/observation.mjs +0 -114
  266. /package/{frontend/src/lib/analysis/acquisition-due-diligence.js → packages/investigation/acquisition-due-diligence.mjs} +0 -0
  267. /package/{frontend/src/lib/analysis/evidence-coverage-ledger.js → packages/investigation/evidence-coverage-ledger.mjs} +0 -0
  268. /package/{frontend/src/lib/analysis/dns-record-normalization.js → packages/workspace/dns-record-normalization.mjs} +0 -0
@@ -1,669 +0,0 @@
1
- // Bounded, framework-neutral analyst response records. These records are
2
- // deliberately separate from collected evidence snapshots: a pin describes a
3
- // fact selected by an analyst, a decision records analyst reasoning, and an
4
- // action records a reviewed external or internal follow-up.
5
- export const MAX_CASE_EVIDENCE_PINS = 40;
6
- export const MAX_CASE_CHECKPOINT_FACTS = 20;
7
- export const MAX_CASE_DECISIONS = 30;
8
- export const MAX_CASE_ACTIONS = 50;
9
- export const MAX_CASE_ASSERTIONS = 50;
10
- export const MAX_CASE_MANUAL_TRAIL_EVENTS = 80;
11
- export const MAX_CASE_SIGHTINGS = 80;
12
- export const MAX_RESPONSE_LABEL_LENGTH = 80;
13
- export const MAX_RESPONSE_VALUE_LENGTH = 1000;
14
- export const MAX_RESPONSE_RATIONALE_LENGTH = 2000;
15
- export const MAX_RESPONSE_RECIPIENT_LENGTH = 320;
16
- export const MAX_RESPONSE_REFERENCE_LENGTH = 500;
17
- export const MAX_RESPONSE_LIMITATIONS = 8;
18
- export const MAX_RESPONSE_LIMITATION_LENGTH = 240;
19
- export const MAX_DECISION_PIN_REFERENCES = 20;
20
- export const MAX_TRAIL_TARGET_LENGTH = 500;
21
- export const MAX_ASSERTION_PROVENANCE_LABELS = 20;
22
- export const MAX_ASSERTION_PROVENANCE_MARKINGS = 12;
23
- export const CASE_EVIDENCE_RELATION_STANCES = ['supports', 'contradicts', 'unresolved'];
24
- export const CASE_PIN_COMPLETENESS = ['complete', 'partial', 'inconclusive', 'unknown'];
25
- export const CASE_TRANSITION_EXPECTATIONS = ['preserve', 'change', 'review'];
26
- export const CASE_ACTION_TYPES = [
27
- 'registrar_report',
28
- 'registry_report',
29
- 'network_hosting_report',
30
- 'security_contact_report',
31
- 'defensive_control',
32
- 'internal_review',
33
- ];
34
- export const CASE_ACTION_STATES = [
35
- 'planned',
36
- 'ready_for_review',
37
- 'submitted',
38
- 'acknowledged',
39
- 'resolved',
40
- 'closed',
41
- ];
42
- export const CASE_ASSERTION_KINDS = [
43
- 'verified_fact',
44
- 'hypothesis',
45
- 'unknown',
46
- 'contradiction',
47
- 'next_step',
48
- ];
49
- export const CASE_ASSERTION_STATES = ['open', 'resolved'];
50
- export const CASE_ASSERTION_EXTERNAL_FORMATS = ['stix', 'misp'];
51
- export const CASE_ASSERTION_EXTERNAL_ENTITY_TYPES = [
52
- 'asn',
53
- 'certificate',
54
- 'domain',
55
- 'hostname',
56
- 'ipv4',
57
- 'ipv6',
58
- 'url',
59
- ];
60
- export const CASE_MANUAL_TRAIL_KINDS = ['pivot', 'review', 'handoff'];
61
- export const CASE_SIGHTING_STATES = [
62
- 'observed_by_deployment',
63
- 'reported_by_provider',
64
- 'analyst_confirmed',
65
- 'not_reproduced',
66
- 'expired',
67
- ];
68
- export const CASE_SIGHTING_CATEGORIES = [
69
- 'registration',
70
- 'delegation',
71
- 'certificate',
72
- 'mail',
73
- 'website',
74
- 'infrastructure',
75
- 'other',
76
- ];
77
- const SAFE_ID_RE = /^[A-Za-z0-9_-]{1,64}$/u;
78
- const CONTROL_RE = /[\u0000-\u001f\u007f]/u;
79
- const CONTROL_REPLACE_RE = /[\u0000-\u001f\u007f]+/gu;
80
- const COMPLETENESS = new Set(CASE_PIN_COMPLETENESS);
81
- const TRANSITION_EXPECTATIONS = new Set(CASE_TRANSITION_EXPECTATIONS);
82
- const ACTION_TYPES = new Set(CASE_ACTION_TYPES);
83
- const ACTION_STATES = new Set(CASE_ACTION_STATES);
84
- const ASSERTION_KINDS = new Set(CASE_ASSERTION_KINDS);
85
- const ASSERTION_STATES = new Set(CASE_ASSERTION_STATES);
86
- const EVIDENCE_RELATION_STANCES = new Set(CASE_EVIDENCE_RELATION_STANCES);
87
- const ASSERTION_EXTERNAL_FORMATS = new Set(CASE_ASSERTION_EXTERNAL_FORMATS);
88
- const ASSERTION_EXTERNAL_ENTITY_TYPES = new Set(CASE_ASSERTION_EXTERNAL_ENTITY_TYPES);
89
- const TRAIL_KINDS = new Set(CASE_MANUAL_TRAIL_KINDS);
90
- const SIGHTING_STATES = new Set(CASE_SIGHTING_STATES);
91
- const SIGHTING_CATEGORIES = new Set(CASE_SIGHTING_CATEGORIES);
92
- function record(value) {
93
- return value && typeof value === 'object' && !Array.isArray(value)
94
- ? value
95
- : {};
96
- }
97
- function text(value, maximum) {
98
- if (typeof value !== 'string')
99
- return '';
100
- return value.replace(CONTROL_REPLACE_RE, ' ').trim().slice(0, maximum);
101
- }
102
- function iso(value, fallback) {
103
- if (typeof value === 'string' && value.length <= 64 && !CONTROL_RE.test(value)) {
104
- const parsed = Date.parse(value);
105
- if (Number.isFinite(parsed))
106
- return new Date(parsed).toISOString();
107
- }
108
- return fallback;
109
- }
110
- function optionalIso(value) {
111
- if (typeof value !== 'string' || value.length > 64 || CONTROL_RE.test(value))
112
- return null;
113
- const parsed = Date.parse(value);
114
- return Number.isFinite(parsed) ? new Date(parsed).toISOString() : null;
115
- }
116
- function hash(value) {
117
- let result = 2166136261 >>> 0;
118
- for (let index = 0; index < value.length; index += 1) {
119
- result ^= value.charCodeAt(index);
120
- result = Math.imul(result, 16777619);
121
- }
122
- return (result >>> 0).toString(36);
123
- }
124
- function deterministicId(prefix, value) {
125
- return `${prefix}-${hash(JSON.stringify(value))}`;
126
- }
127
- function freshId(prefix) {
128
- if (typeof globalThis.crypto?.randomUUID === 'function')
129
- return globalThis.crypto.randomUUID();
130
- return `${prefix}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
131
- }
132
- function safeId(value, prefix, raw) {
133
- return typeof value === 'string' && SAFE_ID_RE.test(value)
134
- ? value
135
- : deterministicId(prefix, raw);
136
- }
137
- function limitations(value) {
138
- if (!Array.isArray(value))
139
- return [];
140
- const unique = new Set();
141
- for (const item of value.slice(0, MAX_RESPONSE_LIMITATIONS * 2)) {
142
- const normalized = text(item, MAX_RESPONSE_LIMITATION_LENGTH);
143
- if (normalized)
144
- unique.add(normalized);
145
- if (unique.size >= MAX_RESPONSE_LIMITATIONS)
146
- break;
147
- }
148
- return [...unique];
149
- }
150
- function sourceSchema(value) {
151
- const item = record(value);
152
- const collection = text(item.collection, 80);
153
- const schema = text(item.schema, 120);
154
- const version = typeof item.version === 'number'
155
- && Number.isSafeInteger(item.version)
156
- && item.version > 0
157
- && item.version <= 10_000
158
- ? item.version
159
- : null;
160
- return collection && schema && version !== null ? { collection, schema, version } : null;
161
- }
162
- function uniqueIds(value, validIds) {
163
- if (!Array.isArray(value))
164
- return [];
165
- const unique = new Set();
166
- for (const item of value.slice(0, MAX_DECISION_PIN_REFERENCES * 2)) {
167
- if (typeof item !== 'string' || !SAFE_ID_RE.test(item) || (validIds && !validIds.has(item)))
168
- continue;
169
- unique.add(item);
170
- if (unique.size >= MAX_DECISION_PIN_REFERENCES)
171
- break;
172
- }
173
- return [...unique];
174
- }
175
- function normalizeEvidenceRelations(value, legacyIds, validIds) {
176
- const output = new Map();
177
- if (Array.isArray(value)) {
178
- for (const raw of value.slice(0, MAX_DECISION_PIN_REFERENCES * 2)) {
179
- const item = record(raw);
180
- const evidencePinId = typeof item.evidencePinId === 'string' && SAFE_ID_RE.test(item.evidencePinId)
181
- ? item.evidencePinId
182
- : '';
183
- if (!evidencePinId || (validIds && !validIds.has(evidencePinId)))
184
- continue;
185
- if (typeof item.stance !== 'string' || !EVIDENCE_RELATION_STANCES.has(item.stance))
186
- continue;
187
- if (!output.has(evidencePinId))
188
- output.set(evidencePinId, item.stance);
189
- if (output.size >= MAX_DECISION_PIN_REFERENCES)
190
- break;
191
- }
192
- }
193
- if (!output.size) {
194
- for (const evidencePinId of legacyIds)
195
- output.set(evidencePinId, 'supports');
196
- }
197
- return [...output].map(([evidencePinId, stance]) => ({ evidencePinId, stance }));
198
- }
199
- function normalizePin(raw, fallback) {
200
- const item = record(raw);
201
- const label = text(item.label, MAX_RESPONSE_LABEL_LENGTH);
202
- const value = text(item.value, MAX_RESPONSE_VALUE_LENGTH);
203
- if (!label || !value)
204
- return null;
205
- const createdAt = iso(item.createdAt, fallback);
206
- return {
207
- id: safeId(item.id, 'pin', { label, value, createdAt }),
208
- checkpointId: typeof item.checkpointId === 'string' && SAFE_ID_RE.test(item.checkpointId)
209
- ? item.checkpointId
210
- : null,
211
- field: text(item.field, 120) || null,
212
- category: text(item.category, 80) || null,
213
- label,
214
- value,
215
- source: text(item.source, MAX_RESPONSE_LABEL_LENGTH) || 'analyst_selected',
216
- sourceState: text(item.sourceState, 40) || null,
217
- sourceSchema: sourceSchema(item.sourceSchema),
218
- observedAt: iso(item.observedAt, createdAt),
219
- collectionDepth: item.collectionDepth === 'deep' || item.collectionDepth === 'fast'
220
- ? item.collectionDepth
221
- : 'unknown',
222
- completeness: typeof item.completeness === 'string' && COMPLETENESS.has(item.completeness)
223
- ? item.completeness
224
- : 'unknown',
225
- truncated: typeof item.truncated === 'boolean' ? item.truncated : null,
226
- transitionExpectation: typeof item.transitionExpectation === 'string'
227
- && TRANSITION_EXPECTATIONS.has(item.transitionExpectation)
228
- ? item.transitionExpectation
229
- : null,
230
- limitations: limitations(item.limitations),
231
- createdAt,
232
- };
233
- }
234
- export function normalizeCaseEvidencePins(raw, fallback) {
235
- if (!Array.isArray(raw))
236
- return [];
237
- const byId = new Map();
238
- for (const item of raw.slice(0, MAX_CASE_EVIDENCE_PINS * 2)) {
239
- const normalized = normalizePin(item, fallback);
240
- if (normalized && !byId.has(normalized.id))
241
- byId.set(normalized.id, normalized);
242
- }
243
- return [...byId.values()]
244
- .sort((left, right) => Date.parse(left.createdAt) - Date.parse(right.createdAt))
245
- .slice(-MAX_CASE_EVIDENCE_PINS);
246
- }
247
- export function appendCaseEvidencePin(current, raw, now) {
248
- const item = record(raw);
249
- const created = normalizePin({ ...item, id: freshId('pin'), createdAt: now }, now);
250
- if (!created)
251
- throw new Error('An evidence pin requires a label and value.');
252
- return normalizeCaseEvidencePins([...current, created], now);
253
- }
254
- export function appendCaseEvidencePins(current, raw, now) {
255
- if (!Array.isArray(raw) || !raw.length)
256
- throw new Error('An evidence checkpoint requires at least one selected fact.');
257
- let output = [...current];
258
- let added = 0;
259
- for (const item of raw.slice(0, MAX_CASE_CHECKPOINT_FACTS)) {
260
- output = appendCaseEvidencePin(output, item, now);
261
- added += 1;
262
- }
263
- if (!added)
264
- throw new Error('An evidence checkpoint requires at least one valid selected fact.');
265
- return output;
266
- }
267
- function normalizeDecision(raw, fallback, validPinIds) {
268
- const item = record(raw);
269
- const summary = text(item.summary, MAX_RESPONSE_LABEL_LENGTH);
270
- const rationale = text(item.rationale, MAX_RESPONSE_RATIONALE_LENGTH);
271
- if (!summary || !rationale)
272
- return null;
273
- const createdAt = iso(item.createdAt, fallback);
274
- return {
275
- id: safeId(item.id, 'decision', { summary, rationale, createdAt }),
276
- summary,
277
- rationale,
278
- evidencePinIds: uniqueIds(item.evidencePinIds, validPinIds),
279
- createdAt,
280
- };
281
- }
282
- export function normalizeCaseDecisions(raw, fallback, validPinIds) {
283
- if (!Array.isArray(raw))
284
- return [];
285
- const byId = new Map();
286
- for (const item of raw.slice(0, MAX_CASE_DECISIONS * 2)) {
287
- const normalized = normalizeDecision(item, fallback, validPinIds);
288
- if (normalized && !byId.has(normalized.id))
289
- byId.set(normalized.id, normalized);
290
- }
291
- return [...byId.values()]
292
- .sort((left, right) => Date.parse(left.createdAt) - Date.parse(right.createdAt))
293
- .slice(-MAX_CASE_DECISIONS);
294
- }
295
- export function appendCaseDecision(current, raw, now, validPinIds) {
296
- const item = record(raw);
297
- const created = normalizeDecision({ ...item, id: freshId('decision'), createdAt: now }, now, validPinIds);
298
- if (!created)
299
- throw new Error('A decision requires a summary and rationale.');
300
- return normalizeCaseDecisions([...current, created], now, validPinIds);
301
- }
302
- function normalizeAction(raw, fallback) {
303
- const item = record(raw);
304
- const recipient = text(item.recipient, MAX_RESPONSE_RECIPIENT_LENGTH);
305
- if (!recipient)
306
- return null;
307
- const createdAt = iso(item.createdAt, fallback);
308
- const updatedAt = iso(item.updatedAt, createdAt);
309
- return {
310
- id: safeId(item.id, 'action', { recipient, createdAt }),
311
- type: typeof item.type === 'string' && ACTION_TYPES.has(item.type)
312
- ? item.type
313
- : 'internal_review',
314
- recipient,
315
- contactSource: text(item.contactSource, MAX_RESPONSE_LABEL_LENGTH) || 'analyst_supplied',
316
- contactLimitations: limitations(item.contactLimitations),
317
- dueAt: optionalIso(item.dueAt),
318
- state: typeof item.state === 'string' && ACTION_STATES.has(item.state)
319
- ? item.state
320
- : 'planned',
321
- reference: text(item.reference, MAX_RESPONSE_REFERENCE_LENGTH) || null,
322
- followUpAt: optionalIso(item.followUpAt),
323
- outcome: text(item.outcome, MAX_RESPONSE_RATIONALE_LENGTH) || null,
324
- createdAt,
325
- updatedAt,
326
- };
327
- }
328
- export function normalizeCaseActions(raw, fallback) {
329
- if (!Array.isArray(raw))
330
- return [];
331
- const byId = new Map();
332
- for (const item of raw.slice(0, MAX_CASE_ACTIONS * 2)) {
333
- const normalized = normalizeAction(item, fallback);
334
- if (!normalized)
335
- continue;
336
- const existing = byId.get(normalized.id);
337
- if (!existing || Date.parse(normalized.updatedAt) >= Date.parse(existing.updatedAt)) {
338
- byId.set(normalized.id, normalized);
339
- }
340
- }
341
- return [...byId.values()]
342
- .sort((left, right) => Date.parse(left.createdAt) - Date.parse(right.createdAt))
343
- .slice(-MAX_CASE_ACTIONS);
344
- }
345
- export function appendCaseAction(current, raw, now) {
346
- const item = record(raw);
347
- const created = normalizeAction({ ...item, id: freshId('action'), createdAt: now, updatedAt: now }, now);
348
- if (!created)
349
- throw new Error('An action requires a recipient or internal owner.');
350
- return normalizeCaseActions([...current, created], now);
351
- }
352
- export function updateCaseAction(current, raw, now) {
353
- const patch = record(raw);
354
- const id = typeof patch.id === 'string' && SAFE_ID_RE.test(patch.id) ? patch.id : '';
355
- const existing = current.find((item) => item.id === id);
356
- if (!existing)
357
- throw new Error('That case action no longer exists.');
358
- const updated = normalizeAction({ ...existing, ...patch, id, createdAt: existing.createdAt, updatedAt: now }, now);
359
- if (!updated)
360
- throw new Error('An action requires a recipient or internal owner.');
361
- return normalizeCaseActions(current.map((item) => item.id === id ? updated : item), now);
362
- }
363
- export function buildCaseActionOutcomeSummary(actions, nowRaw = new Date().toISOString()) {
364
- const now = optionalIso(nowRaw) ?? new Date().toISOString();
365
- const nowTime = Date.parse(now);
366
- const terminal = new Set(['closed', 'resolved']);
367
- const active = actions.filter((item) => !terminal.has(item.state));
368
- const latestOutcomes = actions
369
- .filter((item) => Boolean(item.outcome))
370
- .sort((left, right) => Date.parse(right.updatedAt) - Date.parse(left.updatedAt))
371
- .slice(0, 5)
372
- .map((item) => ({
373
- actionId: item.id,
374
- recipient: item.recipient,
375
- state: item.state,
376
- outcome: item.outcome ?? '',
377
- updatedAt: item.updatedAt,
378
- }));
379
- return {
380
- total: actions.length,
381
- active: active.length,
382
- submitted: actions.filter((item) => item.state === 'submitted').length,
383
- acknowledged: actions.filter((item) => item.state === 'acknowledged').length,
384
- resolved: actions.filter((item) => item.state === 'resolved').length,
385
- closed: actions.filter((item) => item.state === 'closed').length,
386
- overdue: active.filter((item) => item.dueAt && Date.parse(item.dueAt) < nowTime).length,
387
- followUpDue: active.filter((item) => item.followUpAt && Date.parse(item.followUpAt) <= nowTime).length,
388
- withOutcome: actions.filter((item) => Boolean(item.outcome)).length,
389
- latestOutcomes,
390
- };
391
- }
392
- export function mergeCaseEvidencePins(local, imported, fallback) {
393
- return normalizeCaseEvidencePins([...local, ...imported], fallback);
394
- }
395
- export function mergeCaseDecisions(local, imported, fallback, validPinIds) {
396
- return normalizeCaseDecisions([...local, ...imported], fallback, validPinIds);
397
- }
398
- export function mergeCaseActions(local, imported, fallback) {
399
- return normalizeCaseActions([...local, ...imported], fallback);
400
- }
401
- function assertionProvenanceList(value, maximum) {
402
- if (!Array.isArray(value))
403
- return [];
404
- const output = new Set();
405
- for (const item of value.slice(0, maximum * 2)) {
406
- const normalized = text(item, MAX_RESPONSE_LIMITATION_LENGTH);
407
- if (normalized)
408
- output.add(normalized);
409
- if (output.size >= maximum)
410
- break;
411
- }
412
- return [...output];
413
- }
414
- function normalizeAssertionProvenance(value) {
415
- const item = record(value);
416
- const sourceName = text(item.sourceName, 120);
417
- const sourceDigestSha256 = text(item.sourceDigestSha256, 64).toLowerCase();
418
- const entityValue = text(item.entityValue, MAX_RESPONSE_VALUE_LENGTH);
419
- if (item.origin !== 'external_import'
420
- || typeof item.format !== 'string'
421
- || !ASSERTION_EXTERNAL_FORMATS.has(item.format)
422
- || typeof item.entityType !== 'string'
423
- || !ASSERTION_EXTERNAL_ENTITY_TYPES.has(item.entityType)
424
- || !sourceName
425
- || !/^[0-9a-f]{64}$/u.test(sourceDigestSha256)
426
- || !entityValue) {
427
- return null;
428
- }
429
- const confidence = typeof item.confidence === 'number'
430
- && Number.isInteger(item.confidence)
431
- && item.confidence >= 0
432
- && item.confidence <= 100
433
- ? item.confidence
434
- : null;
435
- return {
436
- origin: 'external_import',
437
- format: item.format,
438
- sourceName,
439
- sourceDigestSha256,
440
- publisher: text(item.publisher, 160) || null,
441
- externalId: text(item.externalId, 200) || null,
442
- entityType: item.entityType,
443
- entityValue,
444
- observedAt: optionalIso(item.observedAt),
445
- createdAt: optionalIso(item.createdAt),
446
- modifiedAt: optionalIso(item.modifiedAt),
447
- confidence,
448
- labels: assertionProvenanceList(item.labels, MAX_ASSERTION_PROVENANCE_LABELS),
449
- markings: assertionProvenanceList(item.markings, MAX_ASSERTION_PROVENANCE_MARKINGS),
450
- };
451
- }
452
- function normalizeAssertion(raw, fallback, validPinIds) {
453
- const item = record(raw);
454
- const statement = text(item.statement, MAX_RESPONSE_RATIONALE_LENGTH);
455
- if (!statement)
456
- return null;
457
- const createdAt = iso(item.createdAt, fallback);
458
- const provenance = normalizeAssertionProvenance(item.provenance);
459
- const legacyIds = uniqueIds(item.evidencePinIds, validPinIds);
460
- const evidenceRelations = normalizeEvidenceRelations(item.evidenceRelations, legacyIds, validPinIds);
461
- return {
462
- id: safeId(item.id, 'assertion', { statement, createdAt }),
463
- kind: typeof item.kind === 'string' && ASSERTION_KINDS.has(item.kind)
464
- ? item.kind
465
- : 'hypothesis',
466
- statement,
467
- rationale: text(item.rationale, MAX_RESPONSE_RATIONALE_LENGTH) || null,
468
- evidencePinIds: evidenceRelations.map((relation) => relation.evidencePinId),
469
- evidenceRelations,
470
- state: typeof item.state === 'string' && ASSERTION_STATES.has(item.state)
471
- ? item.state
472
- : 'open',
473
- createdAt,
474
- updatedAt: iso(item.updatedAt, createdAt),
475
- ...(provenance ? { provenance } : {}),
476
- };
477
- }
478
- export function normalizeCaseAssertions(raw, fallback, validPinIds) {
479
- if (!Array.isArray(raw))
480
- return [];
481
- const byId = new Map();
482
- for (const item of raw.slice(0, MAX_CASE_ASSERTIONS * 2)) {
483
- const normalized = normalizeAssertion(item, fallback, validPinIds);
484
- if (!normalized)
485
- continue;
486
- const existing = byId.get(normalized.id);
487
- if (!existing || Date.parse(normalized.updatedAt) >= Date.parse(existing.updatedAt)) {
488
- byId.set(normalized.id, normalized);
489
- }
490
- }
491
- return [...byId.values()]
492
- .sort((left, right) => Date.parse(left.createdAt) - Date.parse(right.createdAt))
493
- .slice(-MAX_CASE_ASSERTIONS);
494
- }
495
- export function appendCaseAssertion(current, raw, now, validPinIds) {
496
- const item = record(raw);
497
- const created = normalizeAssertion({
498
- ...item,
499
- id: freshId('assertion'),
500
- createdAt: now,
501
- updatedAt: now,
502
- }, now, validPinIds);
503
- if (!created)
504
- throw new Error('An analyst assertion requires a statement.');
505
- return normalizeCaseAssertions([...current, created], now, validPinIds);
506
- }
507
- export function updateCaseAssertion(current, raw, now, validPinIds) {
508
- const patch = record(raw);
509
- const id = typeof patch.id === 'string' && SAFE_ID_RE.test(patch.id) ? patch.id : '';
510
- const existing = current.find((item) => item.id === id);
511
- if (!existing)
512
- throw new Error('That analyst assertion no longer exists.');
513
- const updated = normalizeAssertion({
514
- ...existing,
515
- ...patch,
516
- id,
517
- createdAt: existing.createdAt,
518
- updatedAt: now,
519
- }, now, validPinIds);
520
- if (!updated)
521
- throw new Error('An analyst assertion requires a statement.');
522
- return normalizeCaseAssertions(current.map((item) => item.id === id ? updated : item), now, validPinIds);
523
- }
524
- function normalizeManualTrailEvent(raw, fallback) {
525
- const item = record(raw);
526
- const summary = text(item.summary, MAX_RESPONSE_RATIONALE_LENGTH);
527
- if (!summary)
528
- return null;
529
- const createdAt = iso(item.createdAt, fallback);
530
- return {
531
- id: safeId(item.id, 'trail', { summary, createdAt }),
532
- kind: typeof item.kind === 'string' && TRAIL_KINDS.has(item.kind)
533
- ? item.kind
534
- : 'review',
535
- summary,
536
- target: text(item.target, MAX_TRAIL_TARGET_LENGTH) || null,
537
- createdAt,
538
- };
539
- }
540
- export function normalizeCaseManualTrail(raw, fallback) {
541
- if (!Array.isArray(raw))
542
- return [];
543
- const byId = new Map();
544
- for (const item of raw.slice(0, MAX_CASE_MANUAL_TRAIL_EVENTS * 2)) {
545
- const normalized = normalizeManualTrailEvent(item, fallback);
546
- if (normalized && !byId.has(normalized.id))
547
- byId.set(normalized.id, normalized);
548
- }
549
- return [...byId.values()]
550
- .sort((left, right) => Date.parse(left.createdAt) - Date.parse(right.createdAt))
551
- .slice(-MAX_CASE_MANUAL_TRAIL_EVENTS);
552
- }
553
- export function appendCaseManualTrailEvent(current, raw, now) {
554
- const item = record(raw);
555
- const created = normalizeManualTrailEvent({ ...item, id: freshId('trail'), createdAt: now }, now);
556
- if (!created)
557
- throw new Error('An investigation-trail entry requires a summary.');
558
- return normalizeCaseManualTrail([...current, created], now);
559
- }
560
- export function mergeCaseAssertions(local, imported, fallback, validPinIds) {
561
- return normalizeCaseAssertions([...local, ...imported], fallback, validPinIds);
562
- }
563
- export function mergeCaseManualTrail(local, imported, fallback) {
564
- return normalizeCaseManualTrail([...local, ...imported], fallback);
565
- }
566
- function sightingSourceClass(state) {
567
- if (state === 'observed_by_deployment')
568
- return 'deployment';
569
- if (state === 'reported_by_provider')
570
- return 'provider';
571
- return 'analyst';
572
- }
573
- function normalizeCaseSighting(raw, fallback, validPinIds) {
574
- const item = record(raw);
575
- if (typeof item.state !== 'string' || !SIGHTING_STATES.has(item.state))
576
- return null;
577
- const state = item.state;
578
- const source = text(item.source, MAX_RESPONSE_LABEL_LENGTH);
579
- if (!source)
580
- return null;
581
- const createdAt = iso(item.createdAt, fallback);
582
- const evidencePinId = typeof item.evidencePinId === 'string'
583
- && SAFE_ID_RE.test(item.evidencePinId)
584
- && (!validPinIds || validPinIds.has(item.evidencePinId))
585
- ? item.evidencePinId
586
- : null;
587
- return {
588
- id: safeId(item.id, 'sighting', { state, source, createdAt }),
589
- state,
590
- sourceClass: sightingSourceClass(state),
591
- category: typeof item.category === 'string' && SIGHTING_CATEGORIES.has(item.category)
592
- ? item.category
593
- : 'other',
594
- source,
595
- observedAt: iso(item.observedAt, createdAt),
596
- completeness: typeof item.completeness === 'string' && COMPLETENESS.has(item.completeness)
597
- ? item.completeness
598
- : 'unknown',
599
- evidencePinId,
600
- limitations: limitations(item.limitations),
601
- createdAt,
602
- };
603
- }
604
- export function normalizeCaseSightings(raw, fallback, validPinIds) {
605
- if (!Array.isArray(raw))
606
- return [];
607
- const byId = new Map();
608
- for (const item of raw.slice(0, MAX_CASE_SIGHTINGS * 2)) {
609
- const normalized = normalizeCaseSighting(item, fallback, validPinIds);
610
- if (normalized && !byId.has(normalized.id))
611
- byId.set(normalized.id, normalized);
612
- }
613
- return [...byId.values()]
614
- .sort((left, right) => Date.parse(left.observedAt) - Date.parse(right.observedAt) || left.id.localeCompare(right.id))
615
- .slice(-MAX_CASE_SIGHTINGS);
616
- }
617
- export function appendCaseSighting(current, raw, now, validPinIds) {
618
- const item = record(raw);
619
- const created = normalizeCaseSighting({
620
- ...item,
621
- id: freshId('sighting'),
622
- createdAt: now,
623
- }, now, validPinIds);
624
- if (!created)
625
- throw new Error('A sighting requires a source and explicit source-qualified state.');
626
- return normalizeCaseSightings([...current, created], now, validPinIds);
627
- }
628
- export function mergeCaseSightings(local, imported, fallback, validPinIds) {
629
- return normalizeCaseSightings([...local, ...imported], fallback, validPinIds);
630
- }
631
- export function buildCaseInvestigationTrail(input) {
632
- return [
633
- ...(input.assertions ?? []).map((item) => ({
634
- id: `assertion:${item.id}`,
635
- kind: 'assertion',
636
- label: `${item.kind.replaceAll('_', ' ')} · ${item.state}`,
637
- detail: item.statement,
638
- createdAt: item.updatedAt,
639
- })),
640
- ...(input.decisions ?? []).map((item) => ({
641
- id: `decision:${item.id}`,
642
- kind: 'decision',
643
- label: 'analyst decision',
644
- detail: item.summary,
645
- createdAt: item.createdAt,
646
- })),
647
- ...(input.actions ?? []).map((item) => ({
648
- id: `action:${item.id}`,
649
- kind: 'action',
650
- label: `${item.type.replaceAll('_', ' ')} · ${item.state}`,
651
- detail: item.recipient,
652
- createdAt: item.updatedAt,
653
- })),
654
- ...(input.manualTrail ?? []).map((item) => ({
655
- id: `manual:${item.id}`,
656
- kind: 'manual',
657
- label: item.kind.replaceAll('_', ' '),
658
- detail: item.target ? `${item.summary} · ${item.target}` : item.summary,
659
- createdAt: item.createdAt,
660
- })),
661
- ...(input.sightings ?? []).map((item) => ({
662
- id: `sighting:${item.id}`,
663
- kind: 'sighting',
664
- label: `${item.state.replaceAll('_', ' ')} · ${item.category}`,
665
- detail: `${item.source} · ${item.completeness}`,
666
- createdAt: item.observedAt,
667
- })),
668
- ].sort((left, right) => Date.parse(right.createdAt) - Date.parse(left.createdAt) || left.id.localeCompare(right.id));
669
- }