@reconcrap/boss-recommend-mcp 2.0.45 → 2.0.47
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/bin/boss-recommend-mcp.js +4 -4
- package/config/screening-config.example.json +27 -27
- package/package.json +1 -1
- package/scripts/postinstall.cjs +44 -44
- package/skills/boss-chat/README.md +39 -39
- package/skills/boss-chat/SKILL.md +93 -93
- package/skills/boss-recommend-pipeline/README.md +12 -12
- package/skills/boss-recommend-pipeline/SKILL.md +180 -180
- package/skills/boss-recruit-pipeline/README.md +17 -17
- package/skills/boss-recruit-pipeline/SKILL.md +58 -58
- package/src/chat-mcp.js +1780 -1780
- package/src/chat-runtime-config.js +749 -749
- package/src/cli.js +3054 -3054
- package/src/core/boss-cards/index.js +199 -199
- package/src/core/browser/index.js +1453 -1446
- package/src/core/capture/index.js +1201 -1201
- package/src/core/cv-acquisition/index.js +238 -238
- package/src/core/cv-capture-target/index.js +299 -299
- package/src/core/greet-quota/index.js +54 -54
- package/src/core/infinite-list/index.js +1326 -1326
- package/src/core/reporting/legacy-csv.js +341 -341
- package/src/core/run/timing.js +33 -33
- package/src/core/screening/index.js +50 -3
- package/src/core/self-heal/index.js +973 -973
- package/src/core/self-heal/viewport.js +564 -564
- package/src/domains/chat/cards.js +137 -137
- package/src/domains/chat/constants.js +221 -221
- package/src/domains/chat/detail.js +1668 -1661
- package/src/domains/chat/index.js +7 -7
- package/src/domains/chat/jobs.js +592 -588
- package/src/domains/chat/page-guard.js +98 -98
- package/src/domains/chat/roots.js +56 -56
- package/src/domains/chat/run-service.js +1977 -1955
- package/src/domains/recommend/actions.js +457 -457
- package/src/domains/recommend/cards.js +243 -243
- package/src/domains/recommend/constants.js +165 -165
- package/src/domains/recommend/detail.js +36 -28
- package/src/domains/recommend/filters.js +610 -581
- package/src/domains/recommend/index.js +10 -10
- package/src/domains/recommend/jobs.js +316 -263
- package/src/domains/recommend/refresh.js +472 -472
- package/src/domains/recommend/roots.js +80 -80
- package/src/domains/recommend/run-service.js +75 -35
- package/src/domains/recommend/scopes.js +246 -245
- package/src/domains/recruit/actions.js +277 -277
- package/src/domains/recruit/cards.js +74 -74
- package/src/domains/recruit/constants.js +167 -167
- package/src/domains/recruit/detail.js +461 -460
- package/src/domains/recruit/index.js +9 -9
- package/src/domains/recruit/instruction-parser.js +451 -451
- package/src/domains/recruit/refresh.js +44 -44
- package/src/domains/recruit/roots.js +68 -68
- package/src/domains/recruit/run-service.js +1207 -1161
- package/src/domains/recruit/search.js +1202 -1149
- package/src/recommend-mcp.js +22 -22
- package/src/recruit-mcp.js +1338 -1338
|
@@ -1,238 +1,238 @@
|
|
|
1
|
-
export const CV_ACQUISITION_MODE_UNKNOWN = "unknown";
|
|
2
|
-
export const CV_ACQUISITION_MODE_NETWORK = "network";
|
|
3
|
-
export const CV_ACQUISITION_MODE_IMAGE = "image";
|
|
4
|
-
|
|
5
|
-
export const NETWORK_RESUME_WAIT_MS = 4200;
|
|
6
|
-
export const NETWORK_RESUME_RETRY_WAIT_MS = 2000;
|
|
7
|
-
export const NETWORK_RESUME_IMAGE_MODE_GRACE_MS = 1000;
|
|
8
|
-
export const DEFAULT_MAX_IMAGE_PAGES = 24;
|
|
9
|
-
|
|
10
|
-
const VALID_MODES = new Set([
|
|
11
|
-
CV_ACQUISITION_MODE_UNKNOWN,
|
|
12
|
-
CV_ACQUISITION_MODE_NETWORK,
|
|
13
|
-
CV_ACQUISITION_MODE_IMAGE
|
|
14
|
-
]);
|
|
15
|
-
|
|
16
|
-
function normalizeMode(mode) {
|
|
17
|
-
const normalized = String(mode || "").trim().toLowerCase();
|
|
18
|
-
return VALID_MODES.has(normalized) ? normalized : CV_ACQUISITION_MODE_UNKNOWN;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function positiveNumber(value, fallback) {
|
|
22
|
-
const parsed = Number(value);
|
|
23
|
-
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function nowIso() {
|
|
27
|
-
return new Date().toISOString();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function createCvAcquisitionState({
|
|
31
|
-
mode = CV_ACQUISITION_MODE_UNKNOWN
|
|
32
|
-
} = {}) {
|
|
33
|
-
return {
|
|
34
|
-
schema_version: 1,
|
|
35
|
-
mode: normalizeMode(mode),
|
|
36
|
-
attempts: 0,
|
|
37
|
-
network_hits: 0,
|
|
38
|
-
image_fallbacks: 0,
|
|
39
|
-
misses: 0,
|
|
40
|
-
last_result: null,
|
|
41
|
-
history: []
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function getCvNetworkWaitPlan(state = {}, {
|
|
46
|
-
networkWaitMs = NETWORK_RESUME_WAIT_MS,
|
|
47
|
-
networkRetryWaitMs = NETWORK_RESUME_RETRY_WAIT_MS,
|
|
48
|
-
imageModeGraceMs = NETWORK_RESUME_IMAGE_MODE_GRACE_MS
|
|
49
|
-
} = {}) {
|
|
50
|
-
const modeBefore = normalizeMode(state?.mode);
|
|
51
|
-
if (modeBefore === CV_ACQUISITION_MODE_IMAGE) {
|
|
52
|
-
return {
|
|
53
|
-
schema_version: 1,
|
|
54
|
-
mode_before: modeBefore,
|
|
55
|
-
reason: "previous_image_mode_short_network_grace",
|
|
56
|
-
initial_wait_ms: positiveNumber(imageModeGraceMs, NETWORK_RESUME_IMAGE_MODE_GRACE_MS),
|
|
57
|
-
retry_wait_ms: 0
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
schema_version: 1,
|
|
63
|
-
mode_before: modeBefore,
|
|
64
|
-
reason: "network_primary_full_wait",
|
|
65
|
-
initial_wait_ms: positiveNumber(networkWaitMs, NETWORK_RESUME_WAIT_MS),
|
|
66
|
-
retry_wait_ms: positiveNumber(networkRetryWaitMs, NETWORK_RESUME_RETRY_WAIT_MS)
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export async function waitForCvNetworkEvents(waitForNetworkEvents, recorder, {
|
|
71
|
-
waitPlan = getCvNetworkWaitPlan(),
|
|
72
|
-
minCount = 1,
|
|
73
|
-
requireLoaded = true,
|
|
74
|
-
intervalMs = 120
|
|
75
|
-
} = {}) {
|
|
76
|
-
if (typeof waitForNetworkEvents !== "function") {
|
|
77
|
-
throw new Error("waitForCvNetworkEvents requires a domain wait function");
|
|
78
|
-
}
|
|
79
|
-
const started = Date.now();
|
|
80
|
-
const stages = [];
|
|
81
|
-
|
|
82
|
-
const initial = await waitForNetworkEvents(recorder, {
|
|
83
|
-
minCount,
|
|
84
|
-
requireLoaded,
|
|
85
|
-
timeoutMs: waitPlan.initial_wait_ms,
|
|
86
|
-
intervalMs
|
|
87
|
-
});
|
|
88
|
-
stages.push({
|
|
89
|
-
stage: "initial",
|
|
90
|
-
...compactNetworkWait(initial)
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
if (!initial.ok && waitPlan.retry_wait_ms > 0) {
|
|
94
|
-
const retry = await waitForNetworkEvents(recorder, {
|
|
95
|
-
minCount,
|
|
96
|
-
requireLoaded,
|
|
97
|
-
timeoutMs: waitPlan.retry_wait_ms,
|
|
98
|
-
intervalMs
|
|
99
|
-
});
|
|
100
|
-
stages.push({
|
|
101
|
-
stage: "retry",
|
|
102
|
-
...compactNetworkWait(retry)
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const last = stages[stages.length - 1] || {};
|
|
107
|
-
return {
|
|
108
|
-
ok: stages.some((stage) => stage.ok),
|
|
109
|
-
elapsed_ms: Date.now() - started,
|
|
110
|
-
count: Math.max(...stages.map((stage) => Number(stage.count) || 0), 0),
|
|
111
|
-
total_event_count: last.total_event_count ?? last.count ?? 0,
|
|
112
|
-
wait_plan: waitPlan,
|
|
113
|
-
stages
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export function countParsedNetworkProfiles(detailResult = {}) {
|
|
118
|
-
return (detailResult?.parsed_network_profiles || []).filter((item) => item?.ok).length;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export function hasParsedNetworkProfile(detailResult = {}) {
|
|
122
|
-
return countParsedNetworkProfiles(detailResult) > 0;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export function summarizeImageEvidence(imageEvidence = null) {
|
|
126
|
-
if (!imageEvidence) return null;
|
|
127
|
-
return {
|
|
128
|
-
ok: imageEvidence.ok !== false,
|
|
129
|
-
source: imageEvidence.source || "",
|
|
130
|
-
elapsed_ms: imageEvidence.elapsed_ms || 0,
|
|
131
|
-
capture_count: imageEvidence.capture_count || imageEvidence.screenshot_count || 0,
|
|
132
|
-
screenshot_count: imageEvidence.screenshot_count || 0,
|
|
133
|
-
unique_screenshot_count: imageEvidence.unique_screenshot_count || 0,
|
|
134
|
-
dropped_duplicate_count: imageEvidence.dropped_duplicate_count || 0,
|
|
135
|
-
total_byte_length: imageEvidence.total_byte_length || 0,
|
|
136
|
-
original_total_byte_length: imageEvidence.original_total_byte_length || 0,
|
|
137
|
-
llm_screenshot_count: imageEvidence.llm_screenshot_count || 0,
|
|
138
|
-
llm_total_byte_length: imageEvidence.llm_total_byte_length || 0,
|
|
139
|
-
llm_original_total_byte_length: imageEvidence.llm_original_total_byte_length || 0,
|
|
140
|
-
llm_composition_error: imageEvidence.llm_composition_error || null,
|
|
141
|
-
optimization: imageEvidence.optimization || null,
|
|
142
|
-
scroll_anchor_plan: imageEvidence.scroll_anchor_plan || null,
|
|
143
|
-
stop_boundary_plan: imageEvidence.stop_boundary_plan || null,
|
|
144
|
-
stop_boundary_checks: imageEvidence.stop_boundary_checks || [],
|
|
145
|
-
stop_boundary_result: imageEvidence.stop_boundary_result || null,
|
|
146
|
-
error_code: imageEvidence.error_code || imageEvidence.code || null,
|
|
147
|
-
error: imageEvidence.error || null,
|
|
148
|
-
file_paths: imageEvidence.file_paths || [],
|
|
149
|
-
llm_file_paths: imageEvidence.llm_file_paths || [],
|
|
150
|
-
first_clip: imageEvidence.screenshots?.[0]?.clip || imageEvidence.clip || null
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export function recordCvNetworkHit(state, {
|
|
155
|
-
reason = "parsed_network_profile",
|
|
156
|
-
parsedNetworkProfileCount = 0,
|
|
157
|
-
waitResult = null
|
|
158
|
-
} = {}) {
|
|
159
|
-
return recordCvAcquisitionResult(state, {
|
|
160
|
-
source: CV_ACQUISITION_MODE_NETWORK,
|
|
161
|
-
reason,
|
|
162
|
-
parsed_network_profile_count: parsedNetworkProfileCount,
|
|
163
|
-
wait_result: waitResult
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export function recordCvImageFallback(state, {
|
|
168
|
-
reason = "network_miss_image_fallback",
|
|
169
|
-
parsedNetworkProfileCount = 0,
|
|
170
|
-
waitResult = null,
|
|
171
|
-
imageEvidence = null
|
|
172
|
-
} = {}) {
|
|
173
|
-
return recordCvAcquisitionResult(state, {
|
|
174
|
-
source: CV_ACQUISITION_MODE_IMAGE,
|
|
175
|
-
reason,
|
|
176
|
-
parsed_network_profile_count: parsedNetworkProfileCount,
|
|
177
|
-
wait_result: waitResult,
|
|
178
|
-
image_evidence: summarizeImageEvidence(imageEvidence)
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export function recordCvNetworkMiss(state, {
|
|
183
|
-
reason = "network_miss",
|
|
184
|
-
parsedNetworkProfileCount = 0,
|
|
185
|
-
waitResult = null
|
|
186
|
-
} = {}) {
|
|
187
|
-
return recordCvAcquisitionResult(state, {
|
|
188
|
-
source: "miss",
|
|
189
|
-
reason,
|
|
190
|
-
parsed_network_profile_count: parsedNetworkProfileCount,
|
|
191
|
-
wait_result: waitResult
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
export function compactCvAcquisitionState(state = {}) {
|
|
196
|
-
return {
|
|
197
|
-
mode: normalizeMode(state.mode),
|
|
198
|
-
attempts: Number(state.attempts) || 0,
|
|
199
|
-
network_hits: Number(state.network_hits) || 0,
|
|
200
|
-
image_fallbacks: Number(state.image_fallbacks) || 0,
|
|
201
|
-
misses: Number(state.misses) || 0,
|
|
202
|
-
last_result: state.last_result || null
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
function recordCvAcquisitionResult(state, result) {
|
|
207
|
-
if (!state || typeof state !== "object") {
|
|
208
|
-
throw new Error("CV acquisition state is required");
|
|
209
|
-
}
|
|
210
|
-
const recorded = {
|
|
211
|
-
schema_version: 1,
|
|
212
|
-
recorded_at: nowIso(),
|
|
213
|
-
...result
|
|
214
|
-
};
|
|
215
|
-
state.attempts = (Number(state.attempts) || 0) + 1;
|
|
216
|
-
if (result.source === CV_ACQUISITION_MODE_NETWORK) {
|
|
217
|
-
state.mode = CV_ACQUISITION_MODE_NETWORK;
|
|
218
|
-
state.network_hits = (Number(state.network_hits) || 0) + 1;
|
|
219
|
-
} else if (result.source === CV_ACQUISITION_MODE_IMAGE) {
|
|
220
|
-
state.mode = CV_ACQUISITION_MODE_IMAGE;
|
|
221
|
-
state.image_fallbacks = (Number(state.image_fallbacks) || 0) + 1;
|
|
222
|
-
} else {
|
|
223
|
-
state.misses = (Number(state.misses) || 0) + 1;
|
|
224
|
-
}
|
|
225
|
-
state.last_result = recorded;
|
|
226
|
-
if (!Array.isArray(state.history)) state.history = [];
|
|
227
|
-
state.history.push(recorded);
|
|
228
|
-
return compactCvAcquisitionState(state);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
function compactNetworkWait(waitResult = {}) {
|
|
232
|
-
return {
|
|
233
|
-
ok: Boolean(waitResult?.ok),
|
|
234
|
-
elapsed_ms: waitResult?.elapsed_ms || 0,
|
|
235
|
-
count: waitResult?.count || 0,
|
|
236
|
-
total_event_count: waitResult?.total_event_count ?? waitResult?.events?.length ?? 0
|
|
237
|
-
};
|
|
238
|
-
}
|
|
1
|
+
export const CV_ACQUISITION_MODE_UNKNOWN = "unknown";
|
|
2
|
+
export const CV_ACQUISITION_MODE_NETWORK = "network";
|
|
3
|
+
export const CV_ACQUISITION_MODE_IMAGE = "image";
|
|
4
|
+
|
|
5
|
+
export const NETWORK_RESUME_WAIT_MS = 4200;
|
|
6
|
+
export const NETWORK_RESUME_RETRY_WAIT_MS = 2000;
|
|
7
|
+
export const NETWORK_RESUME_IMAGE_MODE_GRACE_MS = 1000;
|
|
8
|
+
export const DEFAULT_MAX_IMAGE_PAGES = 24;
|
|
9
|
+
|
|
10
|
+
const VALID_MODES = new Set([
|
|
11
|
+
CV_ACQUISITION_MODE_UNKNOWN,
|
|
12
|
+
CV_ACQUISITION_MODE_NETWORK,
|
|
13
|
+
CV_ACQUISITION_MODE_IMAGE
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
function normalizeMode(mode) {
|
|
17
|
+
const normalized = String(mode || "").trim().toLowerCase();
|
|
18
|
+
return VALID_MODES.has(normalized) ? normalized : CV_ACQUISITION_MODE_UNKNOWN;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function positiveNumber(value, fallback) {
|
|
22
|
+
const parsed = Number(value);
|
|
23
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function nowIso() {
|
|
27
|
+
return new Date().toISOString();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function createCvAcquisitionState({
|
|
31
|
+
mode = CV_ACQUISITION_MODE_UNKNOWN
|
|
32
|
+
} = {}) {
|
|
33
|
+
return {
|
|
34
|
+
schema_version: 1,
|
|
35
|
+
mode: normalizeMode(mode),
|
|
36
|
+
attempts: 0,
|
|
37
|
+
network_hits: 0,
|
|
38
|
+
image_fallbacks: 0,
|
|
39
|
+
misses: 0,
|
|
40
|
+
last_result: null,
|
|
41
|
+
history: []
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function getCvNetworkWaitPlan(state = {}, {
|
|
46
|
+
networkWaitMs = NETWORK_RESUME_WAIT_MS,
|
|
47
|
+
networkRetryWaitMs = NETWORK_RESUME_RETRY_WAIT_MS,
|
|
48
|
+
imageModeGraceMs = NETWORK_RESUME_IMAGE_MODE_GRACE_MS
|
|
49
|
+
} = {}) {
|
|
50
|
+
const modeBefore = normalizeMode(state?.mode);
|
|
51
|
+
if (modeBefore === CV_ACQUISITION_MODE_IMAGE) {
|
|
52
|
+
return {
|
|
53
|
+
schema_version: 1,
|
|
54
|
+
mode_before: modeBefore,
|
|
55
|
+
reason: "previous_image_mode_short_network_grace",
|
|
56
|
+
initial_wait_ms: positiveNumber(imageModeGraceMs, NETWORK_RESUME_IMAGE_MODE_GRACE_MS),
|
|
57
|
+
retry_wait_ms: 0
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
schema_version: 1,
|
|
63
|
+
mode_before: modeBefore,
|
|
64
|
+
reason: "network_primary_full_wait",
|
|
65
|
+
initial_wait_ms: positiveNumber(networkWaitMs, NETWORK_RESUME_WAIT_MS),
|
|
66
|
+
retry_wait_ms: positiveNumber(networkRetryWaitMs, NETWORK_RESUME_RETRY_WAIT_MS)
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function waitForCvNetworkEvents(waitForNetworkEvents, recorder, {
|
|
71
|
+
waitPlan = getCvNetworkWaitPlan(),
|
|
72
|
+
minCount = 1,
|
|
73
|
+
requireLoaded = true,
|
|
74
|
+
intervalMs = 120
|
|
75
|
+
} = {}) {
|
|
76
|
+
if (typeof waitForNetworkEvents !== "function") {
|
|
77
|
+
throw new Error("waitForCvNetworkEvents requires a domain wait function");
|
|
78
|
+
}
|
|
79
|
+
const started = Date.now();
|
|
80
|
+
const stages = [];
|
|
81
|
+
|
|
82
|
+
const initial = await waitForNetworkEvents(recorder, {
|
|
83
|
+
minCount,
|
|
84
|
+
requireLoaded,
|
|
85
|
+
timeoutMs: waitPlan.initial_wait_ms,
|
|
86
|
+
intervalMs
|
|
87
|
+
});
|
|
88
|
+
stages.push({
|
|
89
|
+
stage: "initial",
|
|
90
|
+
...compactNetworkWait(initial)
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
if (!initial.ok && waitPlan.retry_wait_ms > 0) {
|
|
94
|
+
const retry = await waitForNetworkEvents(recorder, {
|
|
95
|
+
minCount,
|
|
96
|
+
requireLoaded,
|
|
97
|
+
timeoutMs: waitPlan.retry_wait_ms,
|
|
98
|
+
intervalMs
|
|
99
|
+
});
|
|
100
|
+
stages.push({
|
|
101
|
+
stage: "retry",
|
|
102
|
+
...compactNetworkWait(retry)
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const last = stages[stages.length - 1] || {};
|
|
107
|
+
return {
|
|
108
|
+
ok: stages.some((stage) => stage.ok),
|
|
109
|
+
elapsed_ms: Date.now() - started,
|
|
110
|
+
count: Math.max(...stages.map((stage) => Number(stage.count) || 0), 0),
|
|
111
|
+
total_event_count: last.total_event_count ?? last.count ?? 0,
|
|
112
|
+
wait_plan: waitPlan,
|
|
113
|
+
stages
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function countParsedNetworkProfiles(detailResult = {}) {
|
|
118
|
+
return (detailResult?.parsed_network_profiles || []).filter((item) => item?.ok).length;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function hasParsedNetworkProfile(detailResult = {}) {
|
|
122
|
+
return countParsedNetworkProfiles(detailResult) > 0;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function summarizeImageEvidence(imageEvidence = null) {
|
|
126
|
+
if (!imageEvidence) return null;
|
|
127
|
+
return {
|
|
128
|
+
ok: imageEvidence.ok !== false,
|
|
129
|
+
source: imageEvidence.source || "",
|
|
130
|
+
elapsed_ms: imageEvidence.elapsed_ms || 0,
|
|
131
|
+
capture_count: imageEvidence.capture_count || imageEvidence.screenshot_count || 0,
|
|
132
|
+
screenshot_count: imageEvidence.screenshot_count || 0,
|
|
133
|
+
unique_screenshot_count: imageEvidence.unique_screenshot_count || 0,
|
|
134
|
+
dropped_duplicate_count: imageEvidence.dropped_duplicate_count || 0,
|
|
135
|
+
total_byte_length: imageEvidence.total_byte_length || 0,
|
|
136
|
+
original_total_byte_length: imageEvidence.original_total_byte_length || 0,
|
|
137
|
+
llm_screenshot_count: imageEvidence.llm_screenshot_count || 0,
|
|
138
|
+
llm_total_byte_length: imageEvidence.llm_total_byte_length || 0,
|
|
139
|
+
llm_original_total_byte_length: imageEvidence.llm_original_total_byte_length || 0,
|
|
140
|
+
llm_composition_error: imageEvidence.llm_composition_error || null,
|
|
141
|
+
optimization: imageEvidence.optimization || null,
|
|
142
|
+
scroll_anchor_plan: imageEvidence.scroll_anchor_plan || null,
|
|
143
|
+
stop_boundary_plan: imageEvidence.stop_boundary_plan || null,
|
|
144
|
+
stop_boundary_checks: imageEvidence.stop_boundary_checks || [],
|
|
145
|
+
stop_boundary_result: imageEvidence.stop_boundary_result || null,
|
|
146
|
+
error_code: imageEvidence.error_code || imageEvidence.code || null,
|
|
147
|
+
error: imageEvidence.error || null,
|
|
148
|
+
file_paths: imageEvidence.file_paths || [],
|
|
149
|
+
llm_file_paths: imageEvidence.llm_file_paths || [],
|
|
150
|
+
first_clip: imageEvidence.screenshots?.[0]?.clip || imageEvidence.clip || null
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function recordCvNetworkHit(state, {
|
|
155
|
+
reason = "parsed_network_profile",
|
|
156
|
+
parsedNetworkProfileCount = 0,
|
|
157
|
+
waitResult = null
|
|
158
|
+
} = {}) {
|
|
159
|
+
return recordCvAcquisitionResult(state, {
|
|
160
|
+
source: CV_ACQUISITION_MODE_NETWORK,
|
|
161
|
+
reason,
|
|
162
|
+
parsed_network_profile_count: parsedNetworkProfileCount,
|
|
163
|
+
wait_result: waitResult
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function recordCvImageFallback(state, {
|
|
168
|
+
reason = "network_miss_image_fallback",
|
|
169
|
+
parsedNetworkProfileCount = 0,
|
|
170
|
+
waitResult = null,
|
|
171
|
+
imageEvidence = null
|
|
172
|
+
} = {}) {
|
|
173
|
+
return recordCvAcquisitionResult(state, {
|
|
174
|
+
source: CV_ACQUISITION_MODE_IMAGE,
|
|
175
|
+
reason,
|
|
176
|
+
parsed_network_profile_count: parsedNetworkProfileCount,
|
|
177
|
+
wait_result: waitResult,
|
|
178
|
+
image_evidence: summarizeImageEvidence(imageEvidence)
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function recordCvNetworkMiss(state, {
|
|
183
|
+
reason = "network_miss",
|
|
184
|
+
parsedNetworkProfileCount = 0,
|
|
185
|
+
waitResult = null
|
|
186
|
+
} = {}) {
|
|
187
|
+
return recordCvAcquisitionResult(state, {
|
|
188
|
+
source: "miss",
|
|
189
|
+
reason,
|
|
190
|
+
parsed_network_profile_count: parsedNetworkProfileCount,
|
|
191
|
+
wait_result: waitResult
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export function compactCvAcquisitionState(state = {}) {
|
|
196
|
+
return {
|
|
197
|
+
mode: normalizeMode(state.mode),
|
|
198
|
+
attempts: Number(state.attempts) || 0,
|
|
199
|
+
network_hits: Number(state.network_hits) || 0,
|
|
200
|
+
image_fallbacks: Number(state.image_fallbacks) || 0,
|
|
201
|
+
misses: Number(state.misses) || 0,
|
|
202
|
+
last_result: state.last_result || null
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function recordCvAcquisitionResult(state, result) {
|
|
207
|
+
if (!state || typeof state !== "object") {
|
|
208
|
+
throw new Error("CV acquisition state is required");
|
|
209
|
+
}
|
|
210
|
+
const recorded = {
|
|
211
|
+
schema_version: 1,
|
|
212
|
+
recorded_at: nowIso(),
|
|
213
|
+
...result
|
|
214
|
+
};
|
|
215
|
+
state.attempts = (Number(state.attempts) || 0) + 1;
|
|
216
|
+
if (result.source === CV_ACQUISITION_MODE_NETWORK) {
|
|
217
|
+
state.mode = CV_ACQUISITION_MODE_NETWORK;
|
|
218
|
+
state.network_hits = (Number(state.network_hits) || 0) + 1;
|
|
219
|
+
} else if (result.source === CV_ACQUISITION_MODE_IMAGE) {
|
|
220
|
+
state.mode = CV_ACQUISITION_MODE_IMAGE;
|
|
221
|
+
state.image_fallbacks = (Number(state.image_fallbacks) || 0) + 1;
|
|
222
|
+
} else {
|
|
223
|
+
state.misses = (Number(state.misses) || 0) + 1;
|
|
224
|
+
}
|
|
225
|
+
state.last_result = recorded;
|
|
226
|
+
if (!Array.isArray(state.history)) state.history = [];
|
|
227
|
+
state.history.push(recorded);
|
|
228
|
+
return compactCvAcquisitionState(state);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function compactNetworkWait(waitResult = {}) {
|
|
232
|
+
return {
|
|
233
|
+
ok: Boolean(waitResult?.ok),
|
|
234
|
+
elapsed_ms: waitResult?.elapsed_ms || 0,
|
|
235
|
+
count: waitResult?.count || 0,
|
|
236
|
+
total_event_count: waitResult?.total_event_count ?? waitResult?.events?.length ?? 0
|
|
237
|
+
};
|
|
238
|
+
}
|