querysub 0.356.0 → 0.358.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 (76) hide show
  1. package/.cursorrules +9 -0
  2. package/bin/movelogs.js +4 -0
  3. package/package.json +13 -6
  4. package/scripts/postinstall.js +23 -0
  5. package/src/-a-archives/archiveCache.ts +10 -12
  6. package/src/-a-archives/archives.ts +29 -0
  7. package/src/-a-archives/archivesBackBlaze.ts +60 -12
  8. package/src/-a-archives/archivesDisk.ts +39 -13
  9. package/src/-a-archives/archivesLimitedCache.ts +21 -0
  10. package/src/-a-archives/archivesMemoryCache.ts +374 -0
  11. package/src/-a-archives/archivesPrivateFileSystem.ts +22 -0
  12. package/src/-g-core-values/NodeCapabilities.ts +3 -0
  13. package/src/0-path-value-core/auditLogs.ts +5 -1
  14. package/src/0-path-value-core/pathValueCore.ts +7 -7
  15. package/src/4-dom/qreact.tsx +1 -0
  16. package/src/4-querysub/Querysub.ts +1 -5
  17. package/src/config.ts +5 -0
  18. package/src/deployManager/components/MachineDetailPage.tsx +43 -2
  19. package/src/deployManager/components/MachinesListPage.tsx +10 -2
  20. package/src/deployManager/machineApplyMainCode.ts +3 -3
  21. package/src/deployManager/machineSchema.ts +39 -0
  22. package/src/diagnostics/MachineThreadInfo.tsx +235 -0
  23. package/src/diagnostics/NodeViewer.tsx +5 -3
  24. package/src/diagnostics/logs/FastArchiveAppendable.ts +79 -42
  25. package/src/diagnostics/logs/FastArchiveController.ts +102 -63
  26. package/src/diagnostics/logs/FastArchiveViewer.tsx +36 -8
  27. package/src/diagnostics/logs/IndexedLogs/BufferIndex.ts +462 -0
  28. package/src/diagnostics/logs/IndexedLogs/BufferIndexCPP.cpp +327 -0
  29. package/src/diagnostics/logs/IndexedLogs/BufferIndexCPP.d.ts +18 -0
  30. package/src/diagnostics/logs/IndexedLogs/BufferIndexCPP.js +1 -0
  31. package/src/diagnostics/logs/IndexedLogs/BufferIndexHelpers.ts +222 -0
  32. package/src/diagnostics/logs/IndexedLogs/BufferIndexLogsOptimizationConstants.ts +22 -0
  33. package/src/diagnostics/logs/IndexedLogs/BufferIndexWAT.wat +1145 -0
  34. package/src/diagnostics/logs/IndexedLogs/BufferIndexWAT.wat.d.ts +178 -0
  35. package/src/diagnostics/logs/IndexedLogs/BufferListStreamer.ts +208 -0
  36. package/src/diagnostics/logs/IndexedLogs/BufferUnitIndex.ts +716 -0
  37. package/src/diagnostics/logs/IndexedLogs/BufferUnitSet.ts +146 -0
  38. package/src/diagnostics/logs/IndexedLogs/FilePathSelector.tsx +569 -0
  39. package/src/diagnostics/logs/IndexedLogs/FindProgressTracker.ts +45 -0
  40. package/src/diagnostics/logs/IndexedLogs/IndexedLogs.ts +685 -0
  41. package/src/diagnostics/logs/IndexedLogs/LogStreamer.ts +47 -0
  42. package/src/diagnostics/logs/IndexedLogs/LogViewer3.tsx +901 -0
  43. package/src/diagnostics/logs/IndexedLogs/TimeFileTree.ts +236 -0
  44. package/src/diagnostics/logs/IndexedLogs/binding.gyp +23 -0
  45. package/src/diagnostics/logs/IndexedLogs/moveIndexLogsToPublic.ts +251 -0
  46. package/src/diagnostics/logs/IndexedLogs/moveLogsEntry.ts +10 -0
  47. package/src/diagnostics/logs/LogViewer2.tsx +120 -55
  48. package/src/diagnostics/logs/TimeRangeSelector.tsx +5 -2
  49. package/src/diagnostics/logs/diskLogger.ts +32 -48
  50. package/src/diagnostics/logs/errorNotifications/ErrorNotificationController.ts +3 -2
  51. package/src/diagnostics/logs/errorNotifications/errorDigests.tsx +1 -0
  52. package/src/diagnostics/logs/errorNotifications2/errorNotifications2.ts +0 -0
  53. package/src/diagnostics/logs/lifeCycleAnalysis/LifeCyclePages.tsx +150 -0
  54. package/src/diagnostics/logs/lifeCycleAnalysis/lifeCycles.tsx +150 -15
  55. package/src/diagnostics/logs/lifeCycleAnalysis/test.ts +0 -0
  56. package/src/diagnostics/logs/lifeCycleAnalysis/test.wat +106 -0
  57. package/src/diagnostics/logs/lifeCycleAnalysis/test.wat.d.ts +2 -0
  58. package/src/diagnostics/logs/lifeCycleAnalysis/testHoist.ts +5 -0
  59. package/src/diagnostics/logs/logViewerExtractField.ts +2 -3
  60. package/src/diagnostics/managementPages.tsx +10 -0
  61. package/src/diagnostics/trackResources.ts +1 -1
  62. package/src/functional/limitProcessing.ts +39 -0
  63. package/src/misc/lz4_wasm_nodejs.d.ts +34 -0
  64. package/src/misc/lz4_wasm_nodejs.js +178 -0
  65. package/src/misc/lz4_wasm_nodejs_bg.js +94 -0
  66. package/src/misc/lz4_wasm_nodejs_bg.wasm +0 -0
  67. package/src/misc/lz4_wasm_nodejs_bg.wasm.d.ts +15 -0
  68. package/src/storage/CompressedStream.ts +13 -0
  69. package/src/storage/LZ4.ts +32 -0
  70. package/src/storage/ZSTD.ts +10 -0
  71. package/src/wat/watCompiler.ts +1716 -0
  72. package/src/wat/watGrammar.pegjs +93 -0
  73. package/src/wat/watHandler.ts +179 -0
  74. package/src/wat/watInstructions.txt +707 -0
  75. package/src/zip.ts +3 -89
  76. package/src/diagnostics/logs/lifeCycleAnalysis/spec.md +0 -125
@@ -0,0 +1,146 @@
1
+ import { formatPercent, formatNumber } from "socket-function/src/formatting/format";
2
+ import { red } from "socket-function/src/formatting/logColors";
3
+ import { measureFnc } from "socket-function/src/profiling/measure";
4
+ import { Unit } from "./BufferIndexHelpers";
5
+
6
+ export class UnitSet {
7
+ // Hash-based set for checking unit membership (no positions stored)
8
+ // Similar to the hash table approach in UnitRefList.encode, but only stores presence
9
+
10
+ @measureFnc
11
+ static encode(blocks: Buffer[][]): Buffer {
12
+ const MAX_FILL_RATIO = 0.35;
13
+
14
+ // First pass: count total units
15
+ let totalUnits = 0;
16
+ for (let blockIndex = 0; blockIndex < blocks.length; blockIndex++) {
17
+ const block = blocks[blockIndex];
18
+ for (let bufferIndex = 0; bufferIndex < block.length; bufferIndex++) {
19
+ const buffer = block[bufferIndex];
20
+ if (buffer.length >= 4) {
21
+ totalUnits += buffer.length - 3;
22
+ }
23
+ }
24
+ }
25
+
26
+ if (totalUnits === 0) {
27
+ return Buffer.from(new Uint32Array([0]).buffer);
28
+ }
29
+
30
+ function tryEncodeWithRatio(estimatedUniqueRatio: number): { hashTable: Uint32Array; collisions: number; totalInserts: number; } | undefined {
31
+ const HASH_FACTOR = 2;
32
+ const estimatedUnique = Math.max(Math.ceil(totalUnits / estimatedUniqueRatio), 16);
33
+ const desiredCapacity = estimatedUnique * HASH_FACTOR;
34
+ const hashTableCount = Math.pow(2, Math.ceil(Math.log2(desiredCapacity)));
35
+
36
+ const maxUniqueCount = Math.floor(hashTableCount * MAX_FILL_RATIO);
37
+
38
+ // Each entry is just a single uint32 (the unit value, 0 means empty)
39
+ const hashTable = new Uint32Array(hashTableCount);
40
+
41
+ function getHashIndex(unit: number): number {
42
+ const hash = Math.imul(unit, 2654435761);
43
+ return (hash >>> 16) & (hashTableCount - 1);
44
+ }
45
+
46
+ function getNextIndex(index: number): number {
47
+ return (index + 1) & (hashTableCount - 1);
48
+ }
49
+
50
+ let uniqueCount = 0;
51
+ let collisions = 0;
52
+ let totalInserts = 0;
53
+
54
+ // Iterate and add to hash table directly (no first pass)
55
+ for (let blockIndex = 0; blockIndex < blocks.length; blockIndex++) {
56
+ const block = blocks[blockIndex];
57
+ for (let bufferIndex = 0; bufferIndex < block.length; bufferIndex++) {
58
+ const buffer = block[bufferIndex];
59
+ // Extract units directly
60
+ for (let i = 0; i <= buffer.length - 4; i++) {
61
+ const unit = buffer.readUint32LE(i);
62
+ if (!unit) continue;
63
+
64
+ totalInserts++;
65
+ let index = getHashIndex(unit);
66
+ // Linear probing
67
+ while (true) {
68
+ if (hashTable[index] === 0) {
69
+ // Empty slot - insert
70
+ hashTable[index] = unit;
71
+ uniqueCount++;
72
+ if (uniqueCount > maxUniqueCount) {
73
+ return undefined; // Failed, exceeded fill ratio
74
+ }
75
+ break;
76
+ }
77
+ if (hashTable[index] === unit) {
78
+ // Already present
79
+ break;
80
+ }
81
+ // Collision, probe next
82
+ collisions++;
83
+ index = getNextIndex(index);
84
+ }
85
+ }
86
+ }
87
+ }
88
+
89
+ return { hashTable, collisions, totalInserts };
90
+ }
91
+
92
+ // Try with increasingly conservative ratios until we succeed
93
+ let ratio = 1000;
94
+ let result: ReturnType<typeof tryEncodeWithRatio>;
95
+ while (true) {
96
+ result = tryEncodeWithRatio(ratio);
97
+ if (result) break;
98
+ ratio /= 2;
99
+ }
100
+
101
+ const collisionRate = result.totalInserts > 0 ? result.collisions / result.totalInserts : 0;
102
+
103
+ if (collisionRate > 0.5) {
104
+ console.warn(red(`WARNING: UnitSet collision rate is over 50%: ${formatPercent(collisionRate)}`));
105
+ }
106
+
107
+ // Store capacity as first uint32, followed by the hash table
108
+ const output = new Uint32Array(1 + result.hashTable.length);
109
+ output[0] = result.hashTable.length;
110
+ output.set(result.hashTable, 1);
111
+
112
+ return Buffer.from(output.buffer);
113
+ }
114
+
115
+ @measureFnc
116
+ static has(data: Buffer, unit: Unit): boolean {
117
+ const hashTableCount = data.readUInt32LE(0);
118
+
119
+ if (hashTableCount === 0) return false;
120
+
121
+ function getHashIndex(unit: number): number {
122
+ const hash = Math.imul(unit, 2654435761);
123
+ return (hash >>> 16) & (hashTableCount - 1);
124
+ }
125
+
126
+ function getNextIndex(index: number): number {
127
+ return (index + 1) & (hashTableCount - 1);
128
+ }
129
+
130
+ let index = getHashIndex(unit);
131
+ const maxProbes = hashTableCount;
132
+
133
+ for (let probes = 0; probes < maxProbes; probes++) {
134
+ const value = data.readUInt32LE((1 + index) * 4);
135
+ if (value === 0) return false; // Empty slot, unit not present
136
+ if (value === unit) return true; // Found it
137
+ index = getNextIndex(index);
138
+ }
139
+
140
+ return false; // Shouldn't reach here if hash table isn't full
141
+ }
142
+ }
143
+
144
+
145
+
146
+