coauthored 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/PRIVACY.md +107 -0
- package/README.md +113 -3
- package/THIRD_PARTY_LICENSES.md +105 -0
- package/dist/cli/analytics/anchors.js +39 -0
- package/dist/cli/analytics/archetypes.js +193 -0
- package/dist/cli/analytics/content/analyzer.js +945 -0
- package/dist/cli/analytics/content/classify.js +115 -0
- package/dist/cli/analytics/content/demo-corpus.js +301 -0
- package/dist/cli/analytics/content/sketch.js +54 -0
- package/dist/cli/analytics/dataset.js +321 -0
- package/dist/cli/analytics/demo-fixtures.js +531 -0
- package/dist/cli/analytics/fdr.js +183 -0
- package/dist/cli/analytics/helicorder.js +66 -0
- package/dist/cli/analytics/insights.js +589 -0
- package/dist/cli/analytics/models.js +75 -0
- package/dist/cli/analytics/pricing.js +121 -0
- package/dist/cli/analytics/probable-cause.js +115 -0
- package/dist/cli/analytics/report-builder.js +162 -0
- package/dist/cli/analytics/statistics.js +91 -0
- package/dist/cli/analytics/time.js +252 -0
- package/dist/cli/cli/args.js +105 -0
- package/dist/cli/cli/browser.js +71 -0
- package/dist/cli/cli/index.js +20 -0
- package/dist/cli/cli/main.js +520 -0
- package/dist/cli/cli/phrase-review.js +78 -0
- package/dist/cli/cli/server.js +481 -0
- package/dist/cli/cli/terminal.js +363 -0
- package/dist/cli/ingest/adapters/aider.js +116 -0
- package/dist/cli/ingest/adapters/claude-code.js +139 -0
- package/dist/cli/ingest/adapters/cline-roo.js +89 -0
- package/dist/cli/ingest/adapters/codex-cli.js +240 -0
- package/dist/cli/ingest/adapters/content.js +99 -0
- package/dist/cli/ingest/adapters/cursor-ide.js +149 -0
- package/dist/cli/ingest/adapters/gemini-cli.js +208 -0
- package/dist/cli/ingest/adapters/index.js +18 -0
- package/dist/cli/ingest/adapters/opencode.js +203 -0
- package/dist/cli/ingest/adapters/pi-agent.js +85 -0
- package/dist/cli/ingest/adapters/shared.js +484 -0
- package/dist/cli/ingest/content-sink.js +31 -0
- package/dist/cli/ingest/discovery.js +50 -0
- package/dist/cli/ingest/message-digests.js +61 -0
- package/dist/cli/ingest/pipeline.js +155 -0
- package/dist/cli/ingest/safe-fs.js +284 -0
- package/dist/cli/ingest/sqlite-stage.js +139 -0
- package/dist/cli/ingest/time-window.js +34 -0
- package/dist/cli/ingest/tool-map.js +24 -0
- package/dist/cli/ingest/types.js +1 -0
- package/dist/cli/ingest/worker.js +97 -0
- package/dist/cli/report/content/emoji-names.js +3956 -0
- package/dist/cli/report/content/insights.js +41 -0
- package/dist/cli/report/content/lexicons.js +112 -0
- package/dist/cli/report/content/policy.js +77 -0
- package/dist/cli/report/content/redact.js +164 -0
- package/dist/cli/report/content/stopwords.js +8848 -0
- package/dist/cli/report/content/suppression.js +2617 -0
- package/dist/cli/report/content/validate.js +152 -0
- package/dist/cli/report/copy-lint.js +105 -0
- package/dist/cli/report/share.js +132 -0
- package/dist/cli/report/types.js +1 -0
- package/dist/cli/report/validators.js +334 -0
- package/dist/web/assets/Archivo-VF-BohoA-Sn.woff2 +0 -0
- package/dist/web/assets/DelaGothicOne-subset-CpoJGhTq.woff2 +0 -0
- package/dist/web/assets/Film-Dq8Xxn7U.css +1 -0
- package/dist/web/assets/MartianMono-VF-CmJ1nXx9.woff2 +0 -0
- package/dist/web/assets/app-DEQgytaq.js +38 -0
- package/dist/web/assets/bricolage-grotesque-latin-700-normal-gtcctNPv.woff2 +0 -0
- package/dist/web/assets/bricolage-grotesque-latin-800-normal-J50vIsBe.woff2 +0 -0
- package/dist/web/assets/chorus-D7bfON5Z.ogg +0 -0
- package/dist/web/assets/chorus-bass-CBTKpMv_.ogg +0 -0
- package/dist/web/assets/chorus-drums-BOzgLSoq.ogg +0 -0
- package/dist/web/assets/chorus-harmony-DnJYs_tp.ogg +0 -0
- package/dist/web/assets/chorus-lead-CFpg5DC1.ogg +0 -0
- package/dist/web/assets/chunk-BNfsY4o8.js +1 -0
- package/dist/web/assets/chunk-BSm8IhPY.js +1 -0
- package/dist/web/assets/chunk-Bi6EQAkf.js +1 -0
- package/dist/web/assets/chunk-BmDwUWlX.js +1 -0
- package/dist/web/assets/chunk-Ds4joAI5.js +46 -0
- package/dist/web/assets/chunk-V3YGpFIw.js +1 -0
- package/dist/web/assets/chunk-XGhNFWse.js +1 -0
- package/dist/web/assets/dialogue-card-A5zmbNhu.ogg +0 -0
- package/dist/web/assets/groove-bass-BFNelLKi.ogg +0 -0
- package/dist/web/assets/groove-drums-BY1SBntR.ogg +0 -0
- package/dist/web/assets/groove-harmony-C0CrBzu3.ogg +0 -0
- package/dist/web/assets/groove-lead-CEYPzm5U.ogg +0 -0
- package/dist/web/assets/groove-ln-zQmTb.ogg +0 -0
- package/dist/web/assets/guess-high-CL6mF18x.ogg +0 -0
- package/dist/web/assets/guess-low-C3UnKayZ.ogg +0 -0
- package/dist/web/assets/higher-BevsMIWl.ogg +0 -0
- package/dist/web/assets/identity-0EPS3msD.ogg +0 -0
- package/dist/web/assets/index-DpT0dtHc.css +1 -0
- package/dist/web/assets/intro-DeRh6kUx.ogg +0 -0
- package/dist/web/assets/intro-bass-D63IPU0H.ogg +0 -0
- package/dist/web/assets/intro-drums-Dt9QO534.ogg +0 -0
- package/dist/web/assets/intro-harmony-DBsMG9jJ.ogg +0 -0
- package/dist/web/assets/intro-lead-DWcWS1ia.ogg +0 -0
- package/dist/web/assets/jar-coin-rtCvspuq.ogg +0 -0
- package/dist/web/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
- package/dist/web/assets/ledger-tick-C1rQgQGX.ogg +0 -0
- package/dist/web/assets/night-B_bMOZcf.ogg +0 -0
- package/dist/web/assets/night-bass-B-7Ay9ME.ogg +0 -0
- package/dist/web/assets/night-drums-zEtqWXX3.ogg +0 -0
- package/dist/web/assets/night-harmony-C5Ix2yce.ogg +0 -0
- package/dist/web/assets/night-lead-B7KMlRyj.ogg +0 -0
- package/dist/web/assets/ourturn-DX78hTEz.ogg +0 -0
- package/dist/web/assets/plus-jakarta-sans-latin-400-normal-Dhut76fR.woff2 +0 -0
- package/dist/web/assets/plus-jakarta-sans-latin-500-normal-Bf-nb4oT.woff2 +0 -0
- package/dist/web/assets/plus-jakarta-sans-latin-600-normal-DLTa1BUW.woff2 +0 -0
- package/dist/web/assets/plus-jakarta-sans-latin-700-normal-CfpNZvy6.woff2 +0 -0
- package/dist/web/assets/reveal-BmWAGHih.ogg +0 -0
- package/dist/web/assets/review-split-Dac4zagw.ogg +0 -0
- package/dist/web/assets/shutter-uhz2Y9S9.ogg +0 -0
- package/dist/web/assets/soclose-CiUFR5St.ogg +0 -0
- package/dist/web/assets/stinger-TnnzHAMN.ogg +0 -0
- package/dist/web/assets/stomp-mzIk4cGm.ogg +0 -0
- package/dist/web/assets/syne-latin-700-normal-AF3Rs61n.woff2 +0 -0
- package/dist/web/assets/syne-latin-800-normal-EehdNYzx.woff2 +0 -0
- package/dist/web/assets/tension-BHvWG5ru.ogg +0 -0
- package/dist/web/assets/tension-bass-4G-2qA9W.ogg +0 -0
- package/dist/web/assets/tension-drums-D7sdehJr.ogg +0 -0
- package/dist/web/assets/tension-harmony-FyPldmLb.ogg +0 -0
- package/dist/web/assets/tension-lead-C5uoFMR8.ogg +0 -0
- package/dist/web/assets/why-clock-Dzs1A_ym.ogg +0 -0
- package/dist/web/favicon.svg +1 -0
- package/dist/web/index.html +16 -0
- package/dist/web/licenses/OFL-Archivo.txt +93 -0
- package/dist/web/licenses/OFL-DelaGothic.txt +93 -0
- package/dist/web/licenses/OFL-MartianMono.txt +93 -0
- package/package.json +63 -6
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
import { createHmac } from 'node:crypto';
|
|
2
|
+
import { basename, dirname, join, relative } from 'node:path';
|
|
3
|
+
import { toolArgumentText } from './content.js';
|
|
4
|
+
import { INJECTED_USER_TEXT } from '../../report/content/policy.js';
|
|
5
|
+
import { normalizeContentText } from '../../report/content/redact.js';
|
|
6
|
+
import { hmacProjectId, IngestError, readBoundedJson, safePath, streamJsonlRecords, streamTextLines, walkFiles, within, } from '../safe-fs.js';
|
|
7
|
+
import { stageSqliteReadOnly } from '../sqlite-stage.js';
|
|
8
|
+
import { parseWindows } from '../time-window.js';
|
|
9
|
+
import { mapToolName } from '../tool-map.js';
|
|
10
|
+
export const obj = (value) => value !== null && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
11
|
+
export const str = (...values) => values.find((value) => typeof value === 'string' && value.length > 0);
|
|
12
|
+
export const arr = (value) => Array.isArray(value) ? value : [];
|
|
13
|
+
export const count = (value) => typeof value === 'number' && Number.isSafeInteger(value) && value > 0 ? value : 0;
|
|
14
|
+
export const hasCounts = (value, fields) => fields.some(field => typeof value[field] === 'number' && Number.isSafeInteger(value[field]) && value[field] >= 0);
|
|
15
|
+
export const segments = (path) => path.toLowerCase().split(/[\\/]/);
|
|
16
|
+
export function parseJson(value) {
|
|
17
|
+
if (value instanceof Uint8Array) {
|
|
18
|
+
try {
|
|
19
|
+
value = new TextDecoder('utf-8', { fatal: true }).decode(value);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (typeof value !== 'string')
|
|
26
|
+
return value;
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(value);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function timestamp(...values) {
|
|
35
|
+
for (const value of values) {
|
|
36
|
+
let ts = NaN;
|
|
37
|
+
if (typeof value === 'number') {
|
|
38
|
+
if (Number.isFinite(value)) {
|
|
39
|
+
ts = Math.abs(value) < 1e11 ? value * 1000 : value;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else if (typeof value === 'string') {
|
|
43
|
+
const trimmed = value.trim();
|
|
44
|
+
if (/^\d{4}-\d\d-\d\d[T ]/.test(trimmed)) {
|
|
45
|
+
const normalized = trimmed[10] === 'T' ? trimmed : trimmed.replace(/^(\d{4}-\d\d-\d\d) (\d\d:\d\d:\d\d(?:\.\d+)?)\s*([+-]\d\d:?\d\d|Z)?$/i, '$1T$2$3');
|
|
46
|
+
ts = Date.parse(normalized);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (Number.isFinite(ts) && Math.abs(ts) <= 8.64e15)
|
|
50
|
+
return ts;
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
export function defineAdapter(spec) {
|
|
55
|
+
const version = '1.0.0';
|
|
56
|
+
return {
|
|
57
|
+
id: spec.id, displayName: spec.displayName, tier: spec.tier, version, defaultRetentionDays: spec.defaultRetentionDays,
|
|
58
|
+
async discover(options) {
|
|
59
|
+
const locations = [];
|
|
60
|
+
for (const root of new Set(options.customInputDir ? [options.customInputDir] : spec.roots(options))) {
|
|
61
|
+
const { files, limited } = await walkFiles(root, path => spec.matches(path, root) ||
|
|
62
|
+
(!options.customInputDir && Boolean(spec.configuredMatch?.(path, root, options))));
|
|
63
|
+
if (!files.length)
|
|
64
|
+
continue;
|
|
65
|
+
const canonicalPath = (await safePath(root)).path;
|
|
66
|
+
let earliestMtimeMs = Infinity;
|
|
67
|
+
let latestMtimeMs = -Infinity;
|
|
68
|
+
let totalBytes = 0;
|
|
69
|
+
let hasSqlite = false;
|
|
70
|
+
let hasWal = false;
|
|
71
|
+
for (const entry of files) {
|
|
72
|
+
earliestMtimeMs = Math.min(earliestMtimeMs, Number(entry.stat.mtimeMs));
|
|
73
|
+
latestMtimeMs = Math.max(latestMtimeMs, Number(entry.stat.mtimeMs));
|
|
74
|
+
totalBytes += Number(entry.stat.size);
|
|
75
|
+
if (!isSqlite(spec.id, entry.path))
|
|
76
|
+
continue;
|
|
77
|
+
hasSqlite = true;
|
|
78
|
+
try {
|
|
79
|
+
const wal = await safePath(entry.path + '-wal', dirname(entry.path));
|
|
80
|
+
if (wal.stat.isFile()) {
|
|
81
|
+
hasWal = true;
|
|
82
|
+
totalBytes += Number(wal.stat.size);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
// A missing or unsafe sidecar is assessed again during staging.
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const notes = [];
|
|
90
|
+
if (hasWal)
|
|
91
|
+
notes.push('SQLite WAL sidecar present');
|
|
92
|
+
if (limited)
|
|
93
|
+
notes.push('Discovery reached its directory scan limit');
|
|
94
|
+
if (spec.defaultRetentionDays)
|
|
95
|
+
notes.push(`${spec.defaultRetentionDays}-day default retention may limit history`);
|
|
96
|
+
locations.push({
|
|
97
|
+
candidateId: '', channelLabel: '', harness: spec.id, displayName: spec.displayName, tier: spec.tier,
|
|
98
|
+
canonicalPath, fileCount: files.length, totalBytes, earliestMtimeMs, latestMtimeMs,
|
|
99
|
+
snapshotMethod: hasWal ? 'sqlite-wal-pair-copy' : hasSqlite ? 'sqlite-quiescent-copy' : 'stream-readonly',
|
|
100
|
+
notes, hasCredentialRiskWarning: hasSqlite,
|
|
101
|
+
sourceFiles: files.map(file => file.path), walkLimited: limited,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return locations;
|
|
105
|
+
},
|
|
106
|
+
async parse(ctx) {
|
|
107
|
+
const state = new ParseState(ctx, version, spec.defaultRetentionDays);
|
|
108
|
+
const root = ctx.candidate.canonicalPath;
|
|
109
|
+
await safePath(root);
|
|
110
|
+
const source = ctx.candidate;
|
|
111
|
+
const walking = source.sourceFiles ? undefined : await walkFiles(root, path => spec.matches(path, root), ctx.signal);
|
|
112
|
+
const files = source.sourceFiles ?? walking?.files.map(file => file.path) ?? [];
|
|
113
|
+
if (files.some(path => !within(root, path)))
|
|
114
|
+
throw new IngestError('UNSAFE_PATH');
|
|
115
|
+
state.result.summary.filesSeen = files.length;
|
|
116
|
+
if (source.walkLimited || walking?.limited)
|
|
117
|
+
state.result.summary.failureCodes.push('WALK_LIMIT');
|
|
118
|
+
if (!files.length)
|
|
119
|
+
state.result.summary.failureCodes.push('NO_SOURCE_FILES');
|
|
120
|
+
await spec.parse(state, files);
|
|
121
|
+
state.progress();
|
|
122
|
+
return state.finish();
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function isSqlite(harness, path) {
|
|
127
|
+
return harness === 'cursor-ide' || (harness === 'opencode' && !/\.json$/i.test(path));
|
|
128
|
+
}
|
|
129
|
+
export function ideUserRoot(product, { homeDir, env, platform }) {
|
|
130
|
+
if (platform === 'win32')
|
|
131
|
+
return join(env.APPDATA || join(homeDir, 'AppData', 'Roaming'), product, 'User');
|
|
132
|
+
if (platform === 'darwin')
|
|
133
|
+
return join(homeDir, 'Library', 'Application Support', product, 'User');
|
|
134
|
+
return join(env.XDG_CONFIG_HOME || join(homeDir, '.config'), product, 'User');
|
|
135
|
+
}
|
|
136
|
+
export function emptyCapabilities() {
|
|
137
|
+
return {
|
|
138
|
+
humanPromptTimestamps: 'absent', agentRequestTimestamps: 'absent', tokenBreakdown: 'absent',
|
|
139
|
+
cacheTokens: 'absent', reasoningTokens: 'absent', modelIds: 'absent', toolNames: 'absent',
|
|
140
|
+
toolErrors: 'absent', subagentSpawns: 'absent', compactions: 'absent', interrupts: 'absent',
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
export function emptyResult(candidate, adapterVersion) {
|
|
144
|
+
return {
|
|
145
|
+
sessions: [], humanPrompts: [], agentRequests: [], toolCalls: [], compactions: [], interrupts: [],
|
|
146
|
+
summary: {
|
|
147
|
+
candidateId: candidate.candidateId, harness: candidate.harness, displayName: candidate.displayName,
|
|
148
|
+
adapterVersion, snapshotMethod: candidate.snapshotMethod, filesSeen: 0, filesOk: 0, filesQuarantined: 0,
|
|
149
|
+
linesSeen: 0, linesSkipped: 0, bytesRead: 0, earliestEventTsMs: null, latestEventTsMs: null,
|
|
150
|
+
likelyRetentionTruncated: false, capabilities: emptyCapabilities(), failureCodes: [],
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
const providers = new Set(['anthropic', 'openai', 'google', 'deepseek', 'openrouter', 'azure', 'amazon-bedrock',
|
|
155
|
+
'bedrock', 'vertex', 'xai', 'groq', 'mistral', 'ollama', 'together', 'qwen', 'zai', 'github-copilot']);
|
|
156
|
+
const publicModelIds = [
|
|
157
|
+
/^claude-(?:(?:opus|sonnet|haiku)-\d+(?:[.-]\d)?|\d+(?:[.-]\d)?-(?:opus|sonnet|haiku))(?:-20\d{6}|-latest|-1m)*$/,
|
|
158
|
+
/^gpt-(?:\d+(?:\.\d+)?o?|oss-\d+b)(?:-(?:codex|spark|max|mini|nano|sol|astra|terra|luna|pro|chat|latest|preview|20\d{2}-\d\d-\d\d))*$/,
|
|
159
|
+
/^(?:codex-mini|o[134])(?:-(?:mini|high|medium|low|preview|pro|latest|20\d{2}-\d\d-\d\d))*$/,
|
|
160
|
+
/^gemini-\d(?:\.\d+)?-(?:pro|flash-lite|flash|neon)(?:-(?:preview|exp|latest|\d{2}-\d{2}|\d{3}))*$/,
|
|
161
|
+
/^deepseek-(?:v\d(?:\.\d+)?|r\d|chat|reasoner|flash)(?:-(?:exp|pro|flash|speciale|\d{4}))*$/,
|
|
162
|
+
/^grok-\d(?:\.\d+)?(?:-(?:mini|fast|reasoning|non-reasoning|beta|\d{4}))*$/,
|
|
163
|
+
/^(?:qwen\d(?:\.\d+)?|llama-?\d(?:\.\d+)?|mistral-(?:small|medium|large))(?:-(?:coder|instruct|thinking|\d+(?:\.\d+)?b|latest|\d{4}))*$/,
|
|
164
|
+
];
|
|
165
|
+
function modelMetadata(model, provider) {
|
|
166
|
+
const candidate = typeof model === 'string' && model.length <= 120 ? model.toLowerCase().trim()
|
|
167
|
+
.replace(/^openrouter\//, '')
|
|
168
|
+
.replace(/^(?:models\/|(?:anthropic|openai|google|deepseek|together|meta-llama|qwen|x-ai|mistralai)\/)/, '')
|
|
169
|
+
.replace(/^(?:(?:us|eu|apac|global)\.)?anthropic\./, '')
|
|
170
|
+
.replace(/-v\d+:\d+$/, '')
|
|
171
|
+
.replace(/@(20\d{6})$/, '-$1')
|
|
172
|
+
.replace(/\[1m\]$/, '-1m') : '';
|
|
173
|
+
// Public model families are recognized explicitly. Local aliases can contain private names.
|
|
174
|
+
const modelId = publicModelIds.some(pattern => pattern.test(candidate)) ? candidate : 'unknown';
|
|
175
|
+
const family = modelId.match(/claude-(?:\d+(?:[.-]\d+)?-)?(opus|sonnet|haiku)/)?.[1]
|
|
176
|
+
?? modelId.match(/gemini-\d(?:\.\d+)?-(pro|flash|neon)/)?.[1];
|
|
177
|
+
const modelFamily = family ? `${modelId.split('-')[0]}-${family}` : /codex/.test(modelId) ? 'gpt-codex' :
|
|
178
|
+
/-(?:sol|astra|terra|luna)(?:-|$)/.test(modelId) ? `gpt-${modelId.match(/-(sol|astra|terra|luna)(?:-|$)/)?.[1]}` :
|
|
179
|
+
/^gpt-\d/.test(modelId) ? modelId.match(/^gpt-\d+/)[0] : modelId.split('-')[0];
|
|
180
|
+
const inferred = modelId.startsWith('claude-') ? 'anthropic' :
|
|
181
|
+
modelId.startsWith('gemini-') ? 'google' :
|
|
182
|
+
modelId.startsWith('gpt-oss-') ? 'together' :
|
|
183
|
+
/^(gpt-|codex-|o[134])/.test(modelId) ? 'openai' :
|
|
184
|
+
modelId.startsWith('deepseek-') ? 'deepseek' : 'unknown';
|
|
185
|
+
const normalizedProvider = typeof provider === 'string' ? provider.trim().toLowerCase() : '';
|
|
186
|
+
return { modelId, modelFamily, provider: providers.has(normalizedProvider) ? normalizedProvider : inferred };
|
|
187
|
+
}
|
|
188
|
+
export const tokens = (inputUncached, output, cacheRead = 0, cacheWrite5m = 0, cacheWrite1h = 0, reasoning = 0) => ({ inputUncached, output, cacheRead, cacheWrite5m, cacheWrite1h, reasoning });
|
|
189
|
+
export const eventKeys = new WeakMap();
|
|
190
|
+
export const requestQualities = new WeakMap();
|
|
191
|
+
export const requestGroups = new WeakMap();
|
|
192
|
+
export const sessionWindows = new WeakMap();
|
|
193
|
+
export class ParseState {
|
|
194
|
+
ctx;
|
|
195
|
+
retentionDays;
|
|
196
|
+
result;
|
|
197
|
+
sessions = new Map();
|
|
198
|
+
requests = new Map();
|
|
199
|
+
seen = new Set();
|
|
200
|
+
toolEvents = new Map();
|
|
201
|
+
sessionIds = new Map();
|
|
202
|
+
projectHmacs = new Map();
|
|
203
|
+
unknownModels = false;
|
|
204
|
+
unknownToolErrors = false;
|
|
205
|
+
lastProgressMs = -Infinity;
|
|
206
|
+
completedBytes = 0;
|
|
207
|
+
streamedFileBytes = 0;
|
|
208
|
+
constructor(ctx, version, retentionDays) {
|
|
209
|
+
this.ctx = ctx;
|
|
210
|
+
this.retentionDays = retentionDays;
|
|
211
|
+
this.result = emptyResult(ctx.candidate, version);
|
|
212
|
+
}
|
|
213
|
+
get harness() { return this.ctx.candidate.harness; }
|
|
214
|
+
get summary() { return this.result.summary; }
|
|
215
|
+
get capabilities() { return this.summary.capabilities; }
|
|
216
|
+
observed(ts) {
|
|
217
|
+
const window = parseWindows.get(this.ctx);
|
|
218
|
+
return !window || (ts >= window.start && ts < window.end);
|
|
219
|
+
}
|
|
220
|
+
opaque(...parts) {
|
|
221
|
+
return createHmac('sha256', this.ctx.hmacSecret).update(JSON.stringify([this.harness, ...parts])).digest('hex').slice(0, 32);
|
|
222
|
+
}
|
|
223
|
+
sessionIdFor(key) {
|
|
224
|
+
let id = this.sessionIds.get(key);
|
|
225
|
+
if (id === undefined) {
|
|
226
|
+
id = this.opaque('session', key);
|
|
227
|
+
this.sessionIds.set(key, id);
|
|
228
|
+
}
|
|
229
|
+
return id;
|
|
230
|
+
}
|
|
231
|
+
projectHmacFor(cwd) {
|
|
232
|
+
let hmac = this.projectHmacs.get(cwd);
|
|
233
|
+
if (hmac === undefined) {
|
|
234
|
+
// R2: the project folder the metadata already knows also vetoes open vocabulary (content mode only).
|
|
235
|
+
this.ctx.content?.identifiers(cwd, 'path');
|
|
236
|
+
hmac = hmacProjectId(cwd, this.ctx.hmacSecret);
|
|
237
|
+
this.projectHmacs.set(cwd, hmac);
|
|
238
|
+
}
|
|
239
|
+
return hmac;
|
|
240
|
+
}
|
|
241
|
+
session(key, tsMs, cwd, isSubagent = false, parent) {
|
|
242
|
+
if (tsMs === undefined)
|
|
243
|
+
return;
|
|
244
|
+
const prior = this.sessions.get(key);
|
|
245
|
+
if (prior) {
|
|
246
|
+
prior.startTsMs = Math.min(tsMs, prior.startTsMs);
|
|
247
|
+
prior.endTsMs = Math.max(tsMs, prior.endTsMs);
|
|
248
|
+
if (cwd)
|
|
249
|
+
prior.projectHmac = this.projectHmacFor(cwd);
|
|
250
|
+
if (isSubagent)
|
|
251
|
+
prior.isSubagent = true;
|
|
252
|
+
if (parent && parent !== key)
|
|
253
|
+
prior.parentSessionId = this.sessionIdFor(parent);
|
|
254
|
+
this.addToWindow(prior, tsMs);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const session = {
|
|
258
|
+
sessionId: this.sessionIdFor(key), harness: this.harness,
|
|
259
|
+
projectHmac: cwd ? this.projectHmacFor(cwd) : '',
|
|
260
|
+
startTsMs: tsMs, endTsMs: tsMs, isSubagent, sourceCandidateId: this.ctx.candidate.candidateId,
|
|
261
|
+
};
|
|
262
|
+
if (parent && parent !== key)
|
|
263
|
+
session.parentSessionId = this.sessionIdFor(parent);
|
|
264
|
+
this.sessions.set(key, session);
|
|
265
|
+
this.addToWindow(session, tsMs);
|
|
266
|
+
}
|
|
267
|
+
addToWindow(session, ts) {
|
|
268
|
+
if (!this.observed(ts))
|
|
269
|
+
return;
|
|
270
|
+
const previous = sessionWindows.get(session);
|
|
271
|
+
if (previous) {
|
|
272
|
+
previous.start = Math.min(previous.start, ts);
|
|
273
|
+
previous.end = Math.max(previous.end, ts);
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
sessionWindows.set(session, { start: ts, end: ts });
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
event(list, key, event) {
|
|
280
|
+
const opaque = this.opaque(list, key);
|
|
281
|
+
if (this.seen.has(opaque))
|
|
282
|
+
return;
|
|
283
|
+
this.seen.add(opaque);
|
|
284
|
+
if (this.ctx.crossCandidateEvents !== false)
|
|
285
|
+
eventKeys.set(event, opaque);
|
|
286
|
+
this.result[list].push(event);
|
|
287
|
+
}
|
|
288
|
+
base(session, tsMs) {
|
|
289
|
+
this.session(session, tsMs);
|
|
290
|
+
return { sessionId: this.sessionIdFor(session), harness: this.harness, tsMs };
|
|
291
|
+
}
|
|
292
|
+
content(role, session, tsMs, eventKey, text, sharedKey = false) {
|
|
293
|
+
const sink = this.ctx.content;
|
|
294
|
+
if (!sink || !this.observed(tsMs) || (role === 'user' && this.sessions.get(session)?.isSubagent))
|
|
295
|
+
return;
|
|
296
|
+
if (text === null)
|
|
297
|
+
sink.skip();
|
|
298
|
+
else if (typeof text === 'string' && text) {
|
|
299
|
+
if (role === 'user' && INJECTED_USER_TEXT.test(normalizeContentText(text.slice(0, 512))))
|
|
300
|
+
return;
|
|
301
|
+
sink.add(role, this.sessionIdFor(session), tsMs, JSON.stringify([role, sharedKey ? null : session, eventKey]), text);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
prompt(session, ts, id) {
|
|
305
|
+
if (this.observed(ts))
|
|
306
|
+
this.capabilities.humanPromptTimestamps = 'present';
|
|
307
|
+
this.event('humanPrompts', JSON.stringify([session, id]), this.base(session, ts));
|
|
308
|
+
}
|
|
309
|
+
request(session, ts, key, usage, options = {}) {
|
|
310
|
+
const metadata = modelMetadata(options.model, options.provider);
|
|
311
|
+
if (this.observed(ts)) {
|
|
312
|
+
this.capabilities.agentRequestTimestamps = 'present';
|
|
313
|
+
this.capabilities.tokenBreakdown = 'present';
|
|
314
|
+
if (options.cache)
|
|
315
|
+
this.capabilities.cacheTokens = 'present';
|
|
316
|
+
if (options.reasoning)
|
|
317
|
+
this.capabilities.reasoningTokens = 'present';
|
|
318
|
+
if (metadata.modelId !== 'unknown')
|
|
319
|
+
this.capabilities.modelIds = 'present';
|
|
320
|
+
else
|
|
321
|
+
this.unknownModels = true;
|
|
322
|
+
}
|
|
323
|
+
const dedupeKey = this.opaque('request', key);
|
|
324
|
+
const event = {
|
|
325
|
+
...this.base(session, ts), ...metadata, ...usage, dedupeKey,
|
|
326
|
+
isSubagent: this.sessions.get(session)?.isSubagent ?? false,
|
|
327
|
+
};
|
|
328
|
+
if (options.contextFill !== false) {
|
|
329
|
+
event.contextFillTokens = usage.inputUncached + usage.cacheRead + usage.cacheWrite5m + usage.cacheWrite1h;
|
|
330
|
+
}
|
|
331
|
+
const quality = options.quality ?? 0;
|
|
332
|
+
requestQualities.set(event, quality);
|
|
333
|
+
if (options.coverageGroup)
|
|
334
|
+
requestGroups.set(event, this.opaque('request-group', options.coverageGroup));
|
|
335
|
+
const prior = this.requests.get(dedupeKey);
|
|
336
|
+
if (!prior || quality > prior.quality || (quality === prior.quality && usage.output > prior.event.output)) {
|
|
337
|
+
this.requests.set(dedupeKey, { quality, event });
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
tool(session, ts, id, name, isError = null) {
|
|
341
|
+
const mapped = mapToolName(name);
|
|
342
|
+
if (this.observed(ts)) {
|
|
343
|
+
if (typeof name === 'string')
|
|
344
|
+
this.capabilities.toolNames = 'present';
|
|
345
|
+
if (mapped.isSubagentSpawn)
|
|
346
|
+
this.capabilities.subagentSpawns = 'present';
|
|
347
|
+
if (isError === null)
|
|
348
|
+
this.unknownToolErrors = true;
|
|
349
|
+
else
|
|
350
|
+
this.capabilities.toolErrors = 'present';
|
|
351
|
+
}
|
|
352
|
+
const key = JSON.stringify([session, id]);
|
|
353
|
+
const prior = this.toolEvents.get(key);
|
|
354
|
+
if (prior) {
|
|
355
|
+
if (isError !== null && prior.isError === null)
|
|
356
|
+
prior.isError = isError;
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
const event = { ...this.base(session, ts), ...mapped, isError };
|
|
360
|
+
this.toolEvents.set(key, event);
|
|
361
|
+
this.event('toolCalls', key, event);
|
|
362
|
+
}
|
|
363
|
+
compact(session, ts, id, trigger) {
|
|
364
|
+
if (this.observed(ts))
|
|
365
|
+
this.capabilities.compactions = 'present';
|
|
366
|
+
this.event('compactions', JSON.stringify([session, id]), {
|
|
367
|
+
...this.base(session, ts), trigger: trigger === 'auto' || trigger === 'manual' ? trigger : 'unknown',
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
interrupt(session, ts, id) {
|
|
371
|
+
if (this.observed(ts))
|
|
372
|
+
this.capabilities.interrupts = 'present';
|
|
373
|
+
this.event('interrupts', JSON.stringify([session, id]), this.base(session, ts));
|
|
374
|
+
}
|
|
375
|
+
/** R2: path words in tool arguments feed the open-vocabulary veto. Content mode only; never counted or stored. */
|
|
376
|
+
identifiers(value) {
|
|
377
|
+
const sink = this.ctx.content;
|
|
378
|
+
if (sink)
|
|
379
|
+
toolArgumentText(value, (text, kind) => sink.identifiers(text, kind));
|
|
380
|
+
}
|
|
381
|
+
async file(path, parse) {
|
|
382
|
+
this.ctx.signal?.throwIfAborted();
|
|
383
|
+
// R2: session and project folder names inside the recorder root (for example Claude's encoded project folders).
|
|
384
|
+
if (this.ctx.content)
|
|
385
|
+
this.ctx.content.identifiers(relative(this.ctx.candidate.canonicalPath, dirname(path)), 'path');
|
|
386
|
+
const previousBytes = this.summary.bytesRead;
|
|
387
|
+
try {
|
|
388
|
+
await parse(stats => {
|
|
389
|
+
this.summary.bytesRead += stats.bytesRead ?? 0;
|
|
390
|
+
this.summary.linesSeen += stats.linesSeen ?? 0;
|
|
391
|
+
this.summary.linesSkipped += stats.linesSkipped ?? 0;
|
|
392
|
+
});
|
|
393
|
+
this.summary.filesOk++;
|
|
394
|
+
}
|
|
395
|
+
catch (error) {
|
|
396
|
+
if (this.ctx.signal?.aborted)
|
|
397
|
+
throw error;
|
|
398
|
+
this.summary.filesQuarantined++;
|
|
399
|
+
if (error instanceof IngestError)
|
|
400
|
+
this.summary.bytesRead += error.bytesRead;
|
|
401
|
+
const code = error instanceof IngestError ? error.code : 'PARSE_FAILED';
|
|
402
|
+
if (!this.summary.failureCodes.includes(code))
|
|
403
|
+
this.summary.failureCodes.push(code);
|
|
404
|
+
}
|
|
405
|
+
this.completedBytes += Math.max(this.streamedFileBytes, this.summary.bytesRead - previousBytes);
|
|
406
|
+
this.streamedFileBytes = 0;
|
|
407
|
+
this.progress();
|
|
408
|
+
}
|
|
409
|
+
progress(fileBytes = 0) {
|
|
410
|
+
if (!this.ctx.onProgress)
|
|
411
|
+
return;
|
|
412
|
+
this.lastProgressMs = performance.now();
|
|
413
|
+
const { filesOk, filesQuarantined, filesSeen } = this.summary;
|
|
414
|
+
const { humanPrompts, toolCalls, compactions, interrupts } = this.result;
|
|
415
|
+
this.ctx.onProgress(filesOk + filesQuarantined, filesSeen, humanPrompts.length + toolCalls.length + compactions.length + interrupts.length + this.requests.size, this.completedBytes + fileBytes);
|
|
416
|
+
}
|
|
417
|
+
lineOptions() {
|
|
418
|
+
return {
|
|
419
|
+
root: this.ctx.candidate.canonicalPath, signal: this.ctx.signal,
|
|
420
|
+
onBytesProcessed: this.ctx.onProgress && ((bytes) => {
|
|
421
|
+
this.streamedFileBytes = bytes;
|
|
422
|
+
if (performance.now() - this.lastProgressMs >= 250)
|
|
423
|
+
this.progress(bytes);
|
|
424
|
+
}),
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
jsonl(path, visit) {
|
|
428
|
+
return this.file(path, async (add) => add(await streamJsonlRecords(path, {
|
|
429
|
+
...this.lineOptions(),
|
|
430
|
+
onRecord: (value, ordinal) => visit(obj(value), ordinal),
|
|
431
|
+
})));
|
|
432
|
+
}
|
|
433
|
+
json(path, visit) {
|
|
434
|
+
return this.file(path, async (add) => {
|
|
435
|
+
const { value, bytesRead } = await readBoundedJson(path, this.ctx.candidate.canonicalPath, this.ctx.signal);
|
|
436
|
+
add({ bytesRead });
|
|
437
|
+
visit(value);
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
text(path, visit) {
|
|
441
|
+
return this.file(path, async (add) => add(await streamTextLines(path, this.lineOptions(), visit)));
|
|
442
|
+
}
|
|
443
|
+
sqlite(path, visit) {
|
|
444
|
+
return this.file(path, async (add) => {
|
|
445
|
+
const stage = await stageSqliteReadOnly(path, this.ctx.stagingDir, this.ctx.signal);
|
|
446
|
+
add({ bytesRead: stage.bytesRead });
|
|
447
|
+
if (stage.hasWal)
|
|
448
|
+
this.summary.snapshotMethod = 'sqlite-wal-pair-copy';
|
|
449
|
+
try {
|
|
450
|
+
visit(stage.stagedPath);
|
|
451
|
+
}
|
|
452
|
+
finally {
|
|
453
|
+
await stage.cleanup();
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
finish() {
|
|
458
|
+
this.result.sessions = [...this.sessions.values()];
|
|
459
|
+
this.result.agentRequests = [...this.requests.values()].map(row => row.event);
|
|
460
|
+
const subagents = new Set(this.result.sessions.filter(session => session.isSubagent).map(session => session.sessionId));
|
|
461
|
+
for (const request of this.result.agentRequests)
|
|
462
|
+
if (subagents.has(request.sessionId))
|
|
463
|
+
request.isSubagent = true;
|
|
464
|
+
if (this.unknownModels && this.capabilities.modelIds === 'present')
|
|
465
|
+
this.capabilities.modelIds = 'partial';
|
|
466
|
+
if (this.unknownToolErrors && this.capabilities.toolErrors === 'present')
|
|
467
|
+
this.capabilities.toolErrors = 'partial';
|
|
468
|
+
for (const session of this.result.sessions) {
|
|
469
|
+
this.summary.earliestEventTsMs = Math.min(this.summary.earliestEventTsMs ?? Infinity, session.startTsMs);
|
|
470
|
+
this.summary.latestEventTsMs = Math.max(this.summary.latestEventTsMs ?? -Infinity, session.endTsMs);
|
|
471
|
+
}
|
|
472
|
+
const { earliestEventTsMs, latestEventTsMs } = this.summary;
|
|
473
|
+
if (this.retentionDays && earliestEventTsMs !== null && latestEventTsMs !== null) {
|
|
474
|
+
const day = 86_400_000;
|
|
475
|
+
const maxAge = this.retentionDays * day;
|
|
476
|
+
if (latestEventTsMs - earliestEventTsMs <= maxAge + day && Math.abs(Date.now() - earliestEventTsMs - maxAge) <= 7 * day) {
|
|
477
|
+
this.summary.likelyRetentionTruncated = true;
|
|
478
|
+
this.summary.retentionNote = `Observed history starts near the ${this.retentionDays}-day default retention cutoff.`;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
return this.result;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
export const fileSession = (path) => basename(path).replace(/\.[^.]+$/, '');
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createHmac } from 'node:crypto';
|
|
2
|
+
import { MessageDigests } from './message-digests.js';
|
|
3
|
+
export function contentSink(analyzer, hmacSecret, window) {
|
|
4
|
+
const seen = new MessageDigests();
|
|
5
|
+
return harness => ({
|
|
6
|
+
add(role, session, ts, eventKey, text) {
|
|
7
|
+
if (!(ts >= window.start && ts < window.end))
|
|
8
|
+
return;
|
|
9
|
+
try {
|
|
10
|
+
const digest = createHmac('sha256', hmacSecret).update(`${harness}\0${eventKey}`).digest();
|
|
11
|
+
if (!seen.add(digest)) {
|
|
12
|
+
analyzer.duplicateMessagesSkipped++;
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
analyzer.add({ role, session, ts, text, harness });
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
analyzer.disable();
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
skip() { analyzer.deferredMessagesSkipped++; },
|
|
22
|
+
identifiers(text, kind) {
|
|
23
|
+
try {
|
|
24
|
+
analyzer.learnIdentifiers(text, kind);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
analyzer.disable();
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { ALL_ADAPTERS, getAdapter } from './adapters/index.js';
|
|
5
|
+
import { yearWindow } from './time-window.js';
|
|
6
|
+
export async function discoverRecorders(options) {
|
|
7
|
+
yearWindow(options.year, options.timezone);
|
|
8
|
+
const adapterOptions = {
|
|
9
|
+
customInputDir: options.customInputDir ?? options.inputDir, homeDir: options.homeDir ?? homedir(),
|
|
10
|
+
env: { ...(options.env ?? process.env), COAUTHORED_AIDER_ANALYTICS_LOG: undefined }, platform: options.platform ?? process.platform,
|
|
11
|
+
};
|
|
12
|
+
const discovered = await Promise.all(ALL_ADAPTERS.map(adapter => adapter.discover(adapterOptions)));
|
|
13
|
+
if (options.analyticsLog) {
|
|
14
|
+
discovered.push(await getAdapter('aider').discover({
|
|
15
|
+
...adapterOptions, customInputDir: undefined,
|
|
16
|
+
env: { ...adapterOptions.env, COAUTHORED_AIDER_ANALYTICS_LOG: resolve(options.analyticsLog) },
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
19
|
+
const seen = new Set();
|
|
20
|
+
const locations = discovered.flat().filter(location => {
|
|
21
|
+
const path = (options.platform ?? process.platform) === 'win32' ? location.canonicalPath.toLowerCase() : location.canonicalPath;
|
|
22
|
+
const key = JSON.stringify([location.harness, path]);
|
|
23
|
+
if (seen.has(key))
|
|
24
|
+
return false;
|
|
25
|
+
seen.add(key);
|
|
26
|
+
return true;
|
|
27
|
+
});
|
|
28
|
+
const candidates = locations.map((location, index) => {
|
|
29
|
+
const number = String(index + 1).padStart(2, '0');
|
|
30
|
+
location.candidateId = `rec_${number}`;
|
|
31
|
+
location.channelLabel = `CH${index + 1}`;
|
|
32
|
+
const { candidateId, harness, displayName, tier, channelLabel, fileCount, totalBytes, earliestMtimeMs, latestMtimeMs, snapshotMethod, notes, hasCredentialRiskWarning } = location;
|
|
33
|
+
return { candidateId, harness, displayName, tier, channelLabel, fileCount, totalBytes, earliestMtimeMs,
|
|
34
|
+
latestMtimeMs, snapshotMethod, notes: [...notes], hasCredentialRiskWarning };
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
locations,
|
|
38
|
+
plan: {
|
|
39
|
+
planId: `plan_${randomBytes(16).toString('hex')}`, generatedAtIso: new Date().toISOString(),
|
|
40
|
+
year: options.year, timezone: options.timezone, candidates,
|
|
41
|
+
neverReadManifest: [
|
|
42
|
+
'Prompt text and user messages',
|
|
43
|
+
'Assistant responses, generated code, and diffs',
|
|
44
|
+
'Tool arguments, file paths, and command output',
|
|
45
|
+
'Authentication, account, and provider credential table rows',
|
|
46
|
+
'Settings files and unrelated environment variables',
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Exact membership for the first 128 bits of a uniformly distributed HMAC.
|
|
2
|
+
// Sharding keeps table growth from copying the entire scan's index at once.
|
|
3
|
+
export class MessageDigests {
|
|
4
|
+
shards = Array(256);
|
|
5
|
+
hasZero = false;
|
|
6
|
+
add(digest) {
|
|
7
|
+
const a = digest.readUInt32LE(0);
|
|
8
|
+
const b = digest.readUInt32LE(4);
|
|
9
|
+
const c = digest.readUInt32LE(8);
|
|
10
|
+
const d = digest.readUInt32LE(12);
|
|
11
|
+
if (!(a | b | c | d)) {
|
|
12
|
+
if (this.hasZero)
|
|
13
|
+
return false;
|
|
14
|
+
this.hasZero = true;
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
const shard = a & 255;
|
|
18
|
+
return (this.shards[shard] ??= new DigestShard()).add(a, b, c, d);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
class DigestShard {
|
|
22
|
+
words = new Uint32Array(32 * 4);
|
|
23
|
+
size = 0;
|
|
24
|
+
add(a, b, c, d) {
|
|
25
|
+
const slot = findSlot(this.words, a, b, c, d);
|
|
26
|
+
if (this.words[slot] | this.words[slot + 1] | this.words[slot + 2] | this.words[slot + 3])
|
|
27
|
+
return false;
|
|
28
|
+
this.words[slot] = a;
|
|
29
|
+
this.words[slot + 1] = b;
|
|
30
|
+
this.words[slot + 2] = c;
|
|
31
|
+
this.words[slot + 3] = d;
|
|
32
|
+
// Grow at seven-eighths occupancy, with four words per slot.
|
|
33
|
+
if (++this.size * 32 >= this.words.length * 7)
|
|
34
|
+
this.grow();
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
grow() {
|
|
38
|
+
const old = this.words;
|
|
39
|
+
const words = new Uint32Array(old.length * 2);
|
|
40
|
+
for (let i = 0; i < old.length; i += 4) {
|
|
41
|
+
const a = old[i], b = old[i + 1], c = old[i + 2], d = old[i + 3];
|
|
42
|
+
if (!(a | b | c | d))
|
|
43
|
+
continue;
|
|
44
|
+
const slot = findSlot(words, a, b, c, d);
|
|
45
|
+
words[slot] = a;
|
|
46
|
+
words[slot + 1] = b;
|
|
47
|
+
words[slot + 2] = c;
|
|
48
|
+
words[slot + 3] = d;
|
|
49
|
+
}
|
|
50
|
+
this.words = words;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function findSlot(words, a, b, c, d) {
|
|
54
|
+
const mask = words.length - 4;
|
|
55
|
+
// Skip the shard byte and place the slot on a four-word boundary.
|
|
56
|
+
for (let i = (a >>> 6) & mask;; i = (i + 4) & mask) {
|
|
57
|
+
const w = words[i], x = words[i + 1], y = words[i + 2], z = words[i + 3];
|
|
58
|
+
if (!(w | x | y | z) || (a === w && b === x && c === y && d === z))
|
|
59
|
+
return i;
|
|
60
|
+
}
|
|
61
|
+
}
|