@reconcrap/boss-recommend-mcp 2.0.47 → 2.0.48
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 +1586 -1453
- 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/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 -1668
- package/src/domains/chat/index.js +7 -7
- package/src/domains/chat/jobs.js +592 -592
- 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 -1977
- 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/filters.js +610 -610
- package/src/domains/recommend/index.js +10 -10
- package/src/domains/recommend/jobs.js +316 -316
- package/src/domains/recommend/refresh.js +472 -472
- package/src/domains/recommend/roots.js +80 -80
- package/src/domains/recommend/scopes.js +246 -246
- 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 -461
- 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 -1207
- package/src/domains/recruit/search.js +1202 -1202
- package/src/recommend-mcp.js +22 -22
- package/src/recruit-mcp.js +1338 -1338
|
@@ -1,749 +1,749 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import os from "node:os";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import process from "node:process";
|
|
5
|
-
import { normalizeHumanBehaviorOptions } from "./core/browser/index.js";
|
|
6
|
-
|
|
7
|
-
const BOSS_CHAT_RUNTIME_SUBDIR = "boss-chat";
|
|
8
|
-
const TARGET_COUNT_WRAPPER_KEYS = ["target_count", "targetCount", "value", "count", "limit"];
|
|
9
|
-
const SCREEN_CONFIG_TEMPLATE_DEFAULTS = Object.freeze({
|
|
10
|
-
baseUrl: "https://api.openai.com/v1",
|
|
11
|
-
apiKey: "replace-with-your-api-key",
|
|
12
|
-
model: "gpt-4.1-mini"
|
|
13
|
-
});
|
|
14
|
-
const LLM_THINKING_LEVELS = new Set(["off", "minimal", "low", "medium", "high", "auto", "current"]);
|
|
15
|
-
|
|
16
|
-
export const TARGET_COUNT_CANONICAL_ALL = "all";
|
|
17
|
-
export const TARGET_COUNT_ACCEPTED_EXAMPLES = [TARGET_COUNT_CANONICAL_ALL, -1, 20, "全部候选人"];
|
|
18
|
-
|
|
19
|
-
function normalizeText(value) {
|
|
20
|
-
return String(value || "").replace(/\s+/g, " ").trim();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function getStateHome() {
|
|
24
|
-
return process.env.BOSS_RECOMMEND_HOME
|
|
25
|
-
? path.resolve(process.env.BOSS_RECOMMEND_HOME)
|
|
26
|
-
: path.join(os.homedir(), ".boss-recommend-mcp");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function getCodexHome() {
|
|
30
|
-
return process.env.CODEX_HOME
|
|
31
|
-
? path.resolve(process.env.CODEX_HOME)
|
|
32
|
-
: path.join(os.homedir(), ".codex");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function pathExists(targetPath) {
|
|
36
|
-
try {
|
|
37
|
-
return Boolean(targetPath) && fs.existsSync(targetPath);
|
|
38
|
-
} catch {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function isRootDirectory(workspaceRoot) {
|
|
44
|
-
const root = path.resolve(String(workspaceRoot || ""));
|
|
45
|
-
return path.parse(root).root.toLowerCase() === root.toLowerCase();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function isEphemeralNpxWorkspaceRoot(workspaceRoot) {
|
|
49
|
-
const root = path.resolve(String(workspaceRoot || ""));
|
|
50
|
-
const normalized = root.replace(/\\/g, "/").toLowerCase();
|
|
51
|
-
return (
|
|
52
|
-
normalized.includes("/appdata/local/npm-cache/_npx/")
|
|
53
|
-
|| normalized.includes("/node_modules/@reconcrap/boss-recommend-mcp")
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function isSystemDirectoryWorkspaceRoot(workspaceRoot) {
|
|
58
|
-
const root = path.resolve(String(workspaceRoot || ""));
|
|
59
|
-
const normalized = root.replace(/\\/g, "/").toLowerCase();
|
|
60
|
-
if (process.platform === "win32") {
|
|
61
|
-
return (
|
|
62
|
-
normalized.endsWith("/windows")
|
|
63
|
-
|| normalized.endsWith("/windows/system32")
|
|
64
|
-
|| normalized.endsWith("/windows/syswow64")
|
|
65
|
-
|| normalized.endsWith("/program files")
|
|
66
|
-
|| normalized.endsWith("/program files (x86)")
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
return (
|
|
70
|
-
normalized === "/system"
|
|
71
|
-
|| normalized.startsWith("/system/")
|
|
72
|
-
|| normalized === "/usr"
|
|
73
|
-
|| normalized.startsWith("/usr/")
|
|
74
|
-
|| normalized === "/bin"
|
|
75
|
-
|| normalized.startsWith("/bin/")
|
|
76
|
-
|| normalized === "/sbin"
|
|
77
|
-
|| normalized.startsWith("/sbin/")
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function shouldIgnoreWorkspaceConfigRoot(workspaceRoot) {
|
|
82
|
-
const root = path.resolve(String(workspaceRoot || process.cwd()));
|
|
83
|
-
const home = path.resolve(os.homedir());
|
|
84
|
-
return (
|
|
85
|
-
isEphemeralNpxWorkspaceRoot(root)
|
|
86
|
-
|| isRootDirectory(root)
|
|
87
|
-
|| root.toLowerCase() === home.toLowerCase()
|
|
88
|
-
|| isSystemDirectoryWorkspaceRoot(root)
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function resolveWorkspaceConfigCandidates(workspaceRoot) {
|
|
93
|
-
const root = path.resolve(String(workspaceRoot || process.cwd()));
|
|
94
|
-
if (shouldIgnoreWorkspaceConfigRoot(root)) return [];
|
|
95
|
-
const directPath = path.join(root, "config", "screening-config.json");
|
|
96
|
-
const nestedPath = path.join(root, "boss-recommend-mcp", "config", "screening-config.json");
|
|
97
|
-
const candidates = [directPath];
|
|
98
|
-
if (path.basename(root).toLowerCase() !== "boss-recommend-mcp") {
|
|
99
|
-
candidates.push(nestedPath);
|
|
100
|
-
}
|
|
101
|
-
return Array.from(new Set(candidates));
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function getUserConfigPath() {
|
|
105
|
-
return path.join(getStateHome(), "screening-config.json");
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function getLegacyUserConfigPath() {
|
|
109
|
-
return path.join(getCodexHome(), "boss-recommend-mcp", "screening-config.json");
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function getUserCalibrationPath() {
|
|
113
|
-
return path.join(getCodexHome(), "boss-recommend-mcp", "favorite-calibration.json");
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function buildScreenConfigCandidateMap(workspaceRoot) {
|
|
117
|
-
return {
|
|
118
|
-
env_path: process.env.BOSS_RECOMMEND_SCREEN_CONFIG
|
|
119
|
-
? path.resolve(process.env.BOSS_RECOMMEND_SCREEN_CONFIG)
|
|
120
|
-
: null,
|
|
121
|
-
workspace_paths: resolveWorkspaceConfigCandidates(workspaceRoot),
|
|
122
|
-
user_path: getUserConfigPath(),
|
|
123
|
-
legacy_path: getLegacyUserConfigPath()
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function resolveScreenConfigCandidates(workspaceRoot) {
|
|
128
|
-
const candidateMap = buildScreenConfigCandidateMap(workspaceRoot);
|
|
129
|
-
return [
|
|
130
|
-
candidateMap.env_path,
|
|
131
|
-
candidateMap.user_path,
|
|
132
|
-
...candidateMap.workspace_paths,
|
|
133
|
-
candidateMap.legacy_path
|
|
134
|
-
].filter(Boolean);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function canWriteDirectory(targetDir) {
|
|
138
|
-
try {
|
|
139
|
-
fs.mkdirSync(targetDir, { recursive: true });
|
|
140
|
-
fs.accessSync(targetDir, fs.constants.W_OK);
|
|
141
|
-
return true;
|
|
142
|
-
} catch {
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function resolveWritableScreenConfigPath(workspaceRoot) {
|
|
148
|
-
const candidateMap = buildScreenConfigCandidateMap(workspaceRoot);
|
|
149
|
-
const workspacePreferred = candidateMap.workspace_paths?.[0] || null;
|
|
150
|
-
if (candidateMap.env_path) return candidateMap.env_path;
|
|
151
|
-
if (candidateMap.user_path && canWriteDirectory(path.dirname(candidateMap.user_path))) {
|
|
152
|
-
return candidateMap.user_path;
|
|
153
|
-
}
|
|
154
|
-
if (workspacePreferred && canWriteDirectory(path.dirname(workspacePreferred))) {
|
|
155
|
-
return workspacePreferred;
|
|
156
|
-
}
|
|
157
|
-
if (workspacePreferred) return workspacePreferred;
|
|
158
|
-
return candidateMap.user_path || candidateMap.legacy_path;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function resolveScreenConfigPath(workspaceRoot) {
|
|
162
|
-
const candidateMap = buildScreenConfigCandidateMap(workspaceRoot);
|
|
163
|
-
if (candidateMap.env_path) return candidateMap.env_path;
|
|
164
|
-
if (candidateMap.user_path && pathExists(candidateMap.user_path)) return candidateMap.user_path;
|
|
165
|
-
const existingWorkspacePath = candidateMap.workspace_paths.find((item) => pathExists(item));
|
|
166
|
-
if (existingWorkspacePath) return existingWorkspacePath;
|
|
167
|
-
return resolveWritableScreenConfigPath(workspaceRoot) || candidateMap.legacy_path;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function readJsonFile(filePath) {
|
|
171
|
-
if (!filePath || !pathExists(filePath)) return null;
|
|
172
|
-
try {
|
|
173
|
-
return JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
174
|
-
} catch {
|
|
175
|
-
return null;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function isUsableFeaturedCalibrationFile(filePath) {
|
|
180
|
-
const parsed = readJsonFile(filePath);
|
|
181
|
-
return Boolean(
|
|
182
|
-
parsed
|
|
183
|
-
&& typeof parsed === "object"
|
|
184
|
-
&& !Array.isArray(parsed)
|
|
185
|
-
&& parsed.favoritePosition
|
|
186
|
-
&& Number.isFinite(parsed.favoritePosition.pageX)
|
|
187
|
-
&& Number.isFinite(parsed.favoritePosition.pageY)
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function resolveFeaturedCalibrationPath(workspaceRoot) {
|
|
192
|
-
const fromEnv = normalizeText(process.env.BOSS_RECOMMEND_CALIBRATION_FILE || "");
|
|
193
|
-
if (fromEnv) return path.resolve(fromEnv);
|
|
194
|
-
|
|
195
|
-
const configResolution = resolveBossScreeningConfig(workspaceRoot);
|
|
196
|
-
const configPath = configResolution.config_path || resolveScreenConfigPath(workspaceRoot) || getUserConfigPath();
|
|
197
|
-
const config = readJsonFile(configPath);
|
|
198
|
-
const calibrationFile = normalizeText(config?.calibrationFile || "");
|
|
199
|
-
if (calibrationFile && configPath) {
|
|
200
|
-
return path.resolve(path.dirname(configPath), calibrationFile);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return getUserCalibrationPath();
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
function resolveRecruitCalibrationScriptPath(workspaceRoot) {
|
|
207
|
-
const fromEnv = normalizeText(process.env.BOSS_RECOMMEND_RECRUIT_CALIBRATION_SCRIPT || "");
|
|
208
|
-
const workspaceResolved = path.resolve(String(workspaceRoot || process.cwd()));
|
|
209
|
-
const appData = process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming");
|
|
210
|
-
const candidates = [
|
|
211
|
-
fromEnv,
|
|
212
|
-
path.join(workspaceResolved, "..", "..", "boss recruit pipeline", "boss-recruit-mcp", "vendor", "boss-screen-cli", "calibrate-favorite-position-v2.cjs"),
|
|
213
|
-
path.join(workspaceResolved, "..", "boss recruit pipeline", "boss-recruit-mcp", "vendor", "boss-screen-cli", "calibrate-favorite-position-v2.cjs"),
|
|
214
|
-
path.join(appData, "npm", "node_modules", "@reconcrap", "boss-recruit-mcp", "vendor", "boss-screen-cli", "calibrate-favorite-position-v2.cjs")
|
|
215
|
-
].filter(Boolean).map((item) => path.resolve(item));
|
|
216
|
-
|
|
217
|
-
for (const candidate of new Set(candidates)) {
|
|
218
|
-
if (pathExists(candidate)) return candidate;
|
|
219
|
-
}
|
|
220
|
-
return null;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
function parsePositiveInteger(raw, fallback = null) {
|
|
224
|
-
const parsed = Number.parseInt(String(raw || ""), 10);
|
|
225
|
-
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
function parseConfigNumber(raw, fallback = null) {
|
|
229
|
-
if (raw === undefined || raw === null || raw === "") return fallback;
|
|
230
|
-
const parsed = Number(raw);
|
|
231
|
-
return Number.isFinite(parsed) ? parsed : fallback;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
function parseConfigBoolean(raw, fallback = false) {
|
|
235
|
-
if (typeof raw === "boolean") return raw;
|
|
236
|
-
const normalized = normalizeText(raw).toLowerCase();
|
|
237
|
-
if (["true", "1", "yes", "y", "on", "enabled"].includes(normalized)) return true;
|
|
238
|
-
if (["false", "0", "no", "n", "off", "disabled"].includes(normalized)) return false;
|
|
239
|
-
return fallback;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
function readFirstOwn(source, keys = []) {
|
|
243
|
-
if (!source || typeof source !== "object") return undefined;
|
|
244
|
-
for (const key of keys) {
|
|
245
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) return source[key];
|
|
246
|
-
}
|
|
247
|
-
return undefined;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
function parseOptionalConfigBoolean(raw) {
|
|
251
|
-
if (raw === undefined || raw === null || raw === "") return null;
|
|
252
|
-
return parseConfigBoolean(raw, null);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
function applyHumanBehaviorProfileDefaults(target, profileRaw) {
|
|
256
|
-
const defaults = normalizeHumanBehaviorOptions(String(profileRaw || ""));
|
|
257
|
-
Object.assign(target, {
|
|
258
|
-
enabled: defaults.enabled,
|
|
259
|
-
profile: defaults.profile,
|
|
260
|
-
clickMovement: defaults.clickMovement,
|
|
261
|
-
textEntry: defaults.textEntry,
|
|
262
|
-
listScrollJitter: defaults.listScrollJitter,
|
|
263
|
-
shortRest: defaults.shortRest,
|
|
264
|
-
batchRest: defaults.batchRest,
|
|
265
|
-
actionCooldown: defaults.actionCooldown
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
export function resolveHumanBehaviorForRun(args = {}, config = {}) {
|
|
270
|
-
const base = normalizeHumanBehaviorOptions(config.humanBehavior || config.human_behavior || null, {
|
|
271
|
-
legacyEnabled: config.humanRestEnabled === true
|
|
272
|
-
});
|
|
273
|
-
const override = {};
|
|
274
|
-
const rawBehavior = readFirstOwn(args, ["human_behavior", "humanBehavior"]);
|
|
275
|
-
if (typeof rawBehavior === "boolean") {
|
|
276
|
-
override.enabled = rawBehavior;
|
|
277
|
-
} else if (typeof rawBehavior === "string") {
|
|
278
|
-
applyHumanBehaviorProfileDefaults(override, rawBehavior);
|
|
279
|
-
} else if (rawBehavior && typeof rawBehavior === "object" && !Array.isArray(rawBehavior)) {
|
|
280
|
-
const rawProfile = readFirstOwn(rawBehavior, ["profile", "mode", "behaviorProfile", "behavior_profile"]);
|
|
281
|
-
if (rawProfile !== undefined) applyHumanBehaviorProfileDefaults(override, rawProfile);
|
|
282
|
-
Object.assign(override, rawBehavior);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
const profile = readFirstOwn(args, ["human_behavior_profile", "humanBehaviorProfile"]);
|
|
286
|
-
if (profile !== undefined) applyHumanBehaviorProfileDefaults(override, profile);
|
|
287
|
-
const enabled = parseOptionalConfigBoolean(readFirstOwn(args, [
|
|
288
|
-
"human_behavior_enabled",
|
|
289
|
-
"humanBehaviorEnabled"
|
|
290
|
-
]));
|
|
291
|
-
if (enabled !== null) {
|
|
292
|
-
override.enabled = enabled;
|
|
293
|
-
if (enabled === true && !override.profile) applyHumanBehaviorProfileDefaults(override, "paced");
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
const safePacing = parseOptionalConfigBoolean(readFirstOwn(args, ["safe_pacing", "safePacing"]));
|
|
297
|
-
if (safePacing === true) {
|
|
298
|
-
applyHumanBehaviorProfileDefaults(override, "paced");
|
|
299
|
-
} else if (safePacing === false) {
|
|
300
|
-
override.enabled = false;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
const batchRest = parseOptionalConfigBoolean(readFirstOwn(args, [
|
|
304
|
-
"batch_rest_enabled",
|
|
305
|
-
"batchRestEnabled",
|
|
306
|
-
"batch_rest"
|
|
307
|
-
]));
|
|
308
|
-
if (batchRest === true) {
|
|
309
|
-
applyHumanBehaviorProfileDefaults(override, "paced_with_rests");
|
|
310
|
-
} else if (batchRest === false) {
|
|
311
|
-
override.batchRest = false;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
return normalizeHumanBehaviorOptions({
|
|
315
|
-
...base,
|
|
316
|
-
...override
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
function normalizeLlmThinkingLevel(raw, fallback = "low") {
|
|
321
|
-
const normalized = normalizeText(raw).toLowerCase();
|
|
322
|
-
return LLM_THINKING_LEVELS.has(normalized) ? normalized : fallback;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
function firstConfiguredValue(...values) {
|
|
326
|
-
for (const value of values) {
|
|
327
|
-
if (value === undefined || value === null) continue;
|
|
328
|
-
if (typeof value === "string" && !value.trim()) continue;
|
|
329
|
-
return value;
|
|
330
|
-
}
|
|
331
|
-
return "";
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
function resolveRawLlmModelEntries(config = {}) {
|
|
335
|
-
if (Array.isArray(config.llmModels) && config.llmModels.length > 0) return config.llmModels;
|
|
336
|
-
if (Array.isArray(config.models) && config.models.length > 0) return config.models;
|
|
337
|
-
return [config];
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
function normalizeScreeningLlmModel(config = {}, rawEntry = {}, index = 0) {
|
|
341
|
-
const entry = typeof rawEntry === "string"
|
|
342
|
-
? { model: rawEntry }
|
|
343
|
-
: (rawEntry && typeof rawEntry === "object" && !Array.isArray(rawEntry) ? rawEntry : {});
|
|
344
|
-
return {
|
|
345
|
-
name: normalizeText(firstConfiguredValue(entry.name, entry.label, entry.id, entry.providerName, entry.provider)),
|
|
346
|
-
baseUrl: normalizeText(firstConfiguredValue(entry.baseUrl, entry.base_url, config.baseUrl, config.base_url)).replace(/\/+$/, ""),
|
|
347
|
-
apiKey: normalizeText(firstConfiguredValue(entry.apiKey, entry.api_key, config.apiKey, config.api_key)),
|
|
348
|
-
model: normalizeText(firstConfiguredValue(entry.model, entry.modelName, entry.model_name, typeof rawEntry === "string" ? rawEntry : "", config.model)),
|
|
349
|
-
openaiOrganization: normalizeText(firstConfiguredValue(entry.openaiOrganization, entry.organization, config.openaiOrganization, config.organization)),
|
|
350
|
-
openaiProject: normalizeText(firstConfiguredValue(entry.openaiProject, entry.project, config.openaiProject, config.project)),
|
|
351
|
-
llmThinkingLevel: normalizeLlmThinkingLevel(
|
|
352
|
-
firstConfiguredValue(entry.llmThinkingLevel, entry.thinkingLevel, entry.reasoningEffort, config.llmThinkingLevel, config.thinkingLevel, config.reasoningEffort),
|
|
353
|
-
"low"
|
|
354
|
-
),
|
|
355
|
-
llmTimeoutMs: parsePositiveInteger(firstConfiguredValue(entry.llmTimeoutMs, entry.timeoutMs, config.llmTimeoutMs, config.timeoutMs), null),
|
|
356
|
-
llmMaxRetries: parsePositiveInteger(firstConfiguredValue(entry.llmMaxRetries, entry.maxRetries, config.llmMaxRetries, config.maxRetries), null),
|
|
357
|
-
llmMaxTokens: parsePositiveInteger(firstConfiguredValue(entry.llmMaxTokens, entry.maxTokens, config.llmMaxTokens, config.maxTokens), null),
|
|
358
|
-
llmMaxCompletionTokens: parsePositiveInteger(
|
|
359
|
-
firstConfiguredValue(entry.llmMaxCompletionTokens, entry.maxCompletionTokens, config.llmMaxCompletionTokens, config.maxCompletionTokens),
|
|
360
|
-
null
|
|
361
|
-
),
|
|
362
|
-
llmImageLimit: parsePositiveInteger(firstConfiguredValue(entry.llmImageLimit, entry.imageLimit, config.llmImageLimit, config.imageLimit), null),
|
|
363
|
-
llmImageDetail: normalizeText(firstConfiguredValue(entry.llmImageDetail, entry.imageDetail, config.llmImageDetail, config.imageDetail)),
|
|
364
|
-
temperature: parseConfigNumber(firstConfiguredValue(entry.temperature, config.temperature), null),
|
|
365
|
-
topP: parseConfigNumber(firstConfiguredValue(entry.topP, entry.top_p, config.topP, config.top_p), null),
|
|
366
|
-
llmProviderIndex: index
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
function normalizeScreeningLlmModels(config = {}) {
|
|
371
|
-
return resolveRawLlmModelEntries(config).map((entry, index) => normalizeScreeningLlmModel(config, entry, index));
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
function resolveConfigPathValue(raw, configDir) {
|
|
375
|
-
const normalized = normalizeText(raw);
|
|
376
|
-
if (!normalized) return "";
|
|
377
|
-
return path.isAbsolute(normalized)
|
|
378
|
-
? path.resolve(normalized)
|
|
379
|
-
: path.resolve(configDir || process.cwd(), normalized);
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
function validateScreeningConfig(config) {
|
|
383
|
-
if (!config || typeof config !== "object" || Array.isArray(config)) {
|
|
384
|
-
return {
|
|
385
|
-
ok: false,
|
|
386
|
-
reason: "INVALID_OR_MISSING_CONFIG",
|
|
387
|
-
message: "screening-config.json 缺失或格式无效。请填写 baseUrl、apiKey、model。"
|
|
388
|
-
};
|
|
389
|
-
}
|
|
390
|
-
const llmModels = normalizeScreeningLlmModels(config);
|
|
391
|
-
const missing = [];
|
|
392
|
-
for (const [index, llmModel] of llmModels.entries()) {
|
|
393
|
-
const prefix = llmModels.length > 1 ? `llmModels[${index}]` : "";
|
|
394
|
-
if (!llmModel.baseUrl) missing.push(prefix ? `${prefix}.baseUrl` : "baseUrl");
|
|
395
|
-
if (!llmModel.apiKey) missing.push(prefix ? `${prefix}.apiKey` : "apiKey");
|
|
396
|
-
if (!llmModel.model) missing.push(prefix ? `${prefix}.model` : "model");
|
|
397
|
-
}
|
|
398
|
-
if (missing.length > 0) {
|
|
399
|
-
return {
|
|
400
|
-
ok: false,
|
|
401
|
-
reason: "MISSING_REQUIRED_FIELDS",
|
|
402
|
-
message: `screening-config.json 缺少必填字段:${missing.join(", ")}。`
|
|
403
|
-
};
|
|
404
|
-
}
|
|
405
|
-
const placeholderModel = llmModels.find((item) => /^replace-with/i.test(item.apiKey) || item.apiKey === SCREEN_CONFIG_TEMPLATE_DEFAULTS.apiKey);
|
|
406
|
-
if (placeholderModel) {
|
|
407
|
-
return {
|
|
408
|
-
ok: false,
|
|
409
|
-
reason: "PLACEHOLDER_API_KEY",
|
|
410
|
-
message: "screening-config.json 的 apiKey 仍是模板占位符,请填写真实 API Key。"
|
|
411
|
-
};
|
|
412
|
-
}
|
|
413
|
-
const firstModel = llmModels[0] || {};
|
|
414
|
-
if (
|
|
415
|
-
llmModels.length === 1
|
|
416
|
-
&& firstModel.baseUrl === SCREEN_CONFIG_TEMPLATE_DEFAULTS.baseUrl
|
|
417
|
-
&& firstModel.apiKey === SCREEN_CONFIG_TEMPLATE_DEFAULTS.apiKey
|
|
418
|
-
&& firstModel.model === SCREEN_CONFIG_TEMPLATE_DEFAULTS.model
|
|
419
|
-
) {
|
|
420
|
-
return {
|
|
421
|
-
ok: false,
|
|
422
|
-
reason: "PLACEHOLDER_TEMPLATE_VALUES",
|
|
423
|
-
message: "screening-config.json 仍是默认模板值,请填写 baseUrl、apiKey、model。"
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
return { ok: true, reason: "OK", message: "screening-config.json 校验通过。" };
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
export function resolveBossChatDataDir() {
|
|
430
|
-
if (process.env.BOSS_CHAT_HOME) {
|
|
431
|
-
return {
|
|
432
|
-
data_dir: path.resolve(process.env.BOSS_CHAT_HOME),
|
|
433
|
-
data_dir_source: "env:BOSS_CHAT_HOME"
|
|
434
|
-
};
|
|
435
|
-
}
|
|
436
|
-
const stateHome = getStateHome();
|
|
437
|
-
const source = process.env.BOSS_RECOMMEND_HOME
|
|
438
|
-
? "default:env:BOSS_RECOMMEND_HOME"
|
|
439
|
-
: "default:user_home";
|
|
440
|
-
return {
|
|
441
|
-
data_dir: path.join(stateHome, BOSS_CHAT_RUNTIME_SUBDIR),
|
|
442
|
-
data_dir_source: source
|
|
443
|
-
};
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
export function getBossChatDataDir() {
|
|
447
|
-
return resolveBossChatDataDir().data_dir;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
export function getLegacyBossChatWorkspaceDataDir(workspaceRoot) {
|
|
451
|
-
const root = path.resolve(String(workspaceRoot || ""));
|
|
452
|
-
if (!root || isRootDirectory(root) || isSystemDirectoryWorkspaceRoot(root)) return null;
|
|
453
|
-
return path.join(root, ".boss-chat");
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
export function resolveBossChatRuntimeLayout(workspaceRoot) {
|
|
457
|
-
const resolvedDataDir = resolveBossChatDataDir();
|
|
458
|
-
const legacyWorkspaceDir = getLegacyBossChatWorkspaceDataDir(workspaceRoot);
|
|
459
|
-
const migrationSourceDir = legacyWorkspaceDir && pathExists(legacyWorkspaceDir) && !pathExists(resolvedDataDir.data_dir)
|
|
460
|
-
? legacyWorkspaceDir
|
|
461
|
-
: null;
|
|
462
|
-
return {
|
|
463
|
-
workspace_root: workspaceRoot ? path.resolve(String(workspaceRoot)) : null,
|
|
464
|
-
data_dir: resolvedDataDir.data_dir,
|
|
465
|
-
data_dir_source: resolvedDataDir.data_dir_source,
|
|
466
|
-
legacy_workspace_dir: legacyWorkspaceDir,
|
|
467
|
-
migration_source_dir: migrationSourceDir,
|
|
468
|
-
migration_pending: Boolean(migrationSourceDir)
|
|
469
|
-
};
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
export function getBossScreenConfigResolution(workspaceRoot) {
|
|
473
|
-
const candidateMap = buildScreenConfigCandidateMap(workspaceRoot);
|
|
474
|
-
const workspaceRootResolved = path.resolve(String(workspaceRoot || process.cwd()));
|
|
475
|
-
return {
|
|
476
|
-
resolved_path: resolveScreenConfigPath(workspaceRoot) || null,
|
|
477
|
-
candidate_paths: resolveScreenConfigCandidates(workspaceRoot),
|
|
478
|
-
workspace_root: workspaceRootResolved,
|
|
479
|
-
workspace_ephemeral: isEphemeralNpxWorkspaceRoot(workspaceRootResolved),
|
|
480
|
-
workspace_ignored_for_config: shouldIgnoreWorkspaceConfigRoot(workspaceRootResolved),
|
|
481
|
-
writable_path: resolveWritableScreenConfigPath(workspaceRoot),
|
|
482
|
-
legacy_path: candidateMap.legacy_path
|
|
483
|
-
};
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
export function getFeaturedCalibrationResolution(workspaceRoot) {
|
|
487
|
-
const calibrationPath = resolveFeaturedCalibrationPath(workspaceRoot);
|
|
488
|
-
return {
|
|
489
|
-
calibration_path: calibrationPath,
|
|
490
|
-
calibration_exists: pathExists(calibrationPath),
|
|
491
|
-
calibration_usable: isUsableFeaturedCalibrationFile(calibrationPath),
|
|
492
|
-
calibration_script_path: resolveRecruitCalibrationScriptPath(workspaceRoot)
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
export function resolveBossScreeningConfig(workspaceRoot) {
|
|
497
|
-
const candidatePaths = resolveScreenConfigCandidates(workspaceRoot);
|
|
498
|
-
const configPath = resolveScreenConfigPath(workspaceRoot) || null;
|
|
499
|
-
const configDir = configPath ? path.dirname(configPath) : null;
|
|
500
|
-
if (!configPath || !pathExists(configPath)) {
|
|
501
|
-
return {
|
|
502
|
-
ok: false,
|
|
503
|
-
error: {
|
|
504
|
-
code: "SCREEN_CONFIG_ERROR",
|
|
505
|
-
message: `screening-config.json 不存在。请先完成 recommend 配置。${configPath ? ` (path: ${configPath})` : ""}`,
|
|
506
|
-
retryable: true
|
|
507
|
-
},
|
|
508
|
-
config_path: configPath,
|
|
509
|
-
config_dir: configDir,
|
|
510
|
-
candidate_paths: candidatePaths
|
|
511
|
-
};
|
|
512
|
-
}
|
|
513
|
-
const parsed = readJsonFile(configPath);
|
|
514
|
-
const validation = validateScreeningConfig(parsed);
|
|
515
|
-
if (!validation.ok) {
|
|
516
|
-
return {
|
|
517
|
-
ok: false,
|
|
518
|
-
error: {
|
|
519
|
-
code: "SCREEN_CONFIG_ERROR",
|
|
520
|
-
message: `${validation.message} (path: ${configPath})`,
|
|
521
|
-
retryable: true
|
|
522
|
-
},
|
|
523
|
-
config_path: configPath,
|
|
524
|
-
config_dir: configDir,
|
|
525
|
-
candidate_paths: candidatePaths
|
|
526
|
-
};
|
|
527
|
-
}
|
|
528
|
-
const llmModels = normalizeScreeningLlmModels(parsed);
|
|
529
|
-
const primaryLlmModel = llmModels[0] || {};
|
|
530
|
-
const greetingText = normalizeText(
|
|
531
|
-
parsed.greetingMessage
|
|
532
|
-
|| parsed.greeting_message
|
|
533
|
-
|| parsed.greetingText
|
|
534
|
-
|| parsed.greeting_text
|
|
535
|
-
|| parsed.greeting
|
|
536
|
-
);
|
|
537
|
-
const humanRestEnabled = parseConfigBoolean(parsed.humanRestEnabled, false);
|
|
538
|
-
const humanBehavior = normalizeHumanBehaviorOptions(parsed.humanBehavior || parsed.human_behavior || null, {
|
|
539
|
-
legacyEnabled: humanRestEnabled
|
|
540
|
-
});
|
|
541
|
-
return {
|
|
542
|
-
ok: true,
|
|
543
|
-
config: {
|
|
544
|
-
...primaryLlmModel,
|
|
545
|
-
baseUrl: primaryLlmModel.baseUrl,
|
|
546
|
-
apiKey: primaryLlmModel.apiKey,
|
|
547
|
-
model: primaryLlmModel.model,
|
|
548
|
-
openaiOrganization: primaryLlmModel.openaiOrganization,
|
|
549
|
-
openaiProject: primaryLlmModel.openaiProject,
|
|
550
|
-
llmModels,
|
|
551
|
-
greetingMessage: greetingText,
|
|
552
|
-
greetingText,
|
|
553
|
-
debugPort: parsePositiveInteger(parsed.debugPort, 9222),
|
|
554
|
-
outputDir: resolveConfigPathValue(parsed.outputDir, configDir),
|
|
555
|
-
humanRestEnabled,
|
|
556
|
-
humanBehavior
|
|
557
|
-
},
|
|
558
|
-
config_path: configPath,
|
|
559
|
-
config_dir: configDir,
|
|
560
|
-
candidate_paths: candidatePaths
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
export function resolveBossConfiguredOutputDir(workspaceRoot, fallbackDir = "") {
|
|
565
|
-
const configResolution = resolveBossScreeningConfig(workspaceRoot);
|
|
566
|
-
const configuredDir = configResolution.ok ? normalizeText(configResolution.config.outputDir) : "";
|
|
567
|
-
if (configuredDir) return configuredDir;
|
|
568
|
-
return fallbackDir ? path.resolve(fallbackDir) : "";
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
function isUnlimitedTargetCountToken(value) {
|
|
572
|
-
const token = normalizeText(value).toLowerCase();
|
|
573
|
-
if (!token) return false;
|
|
574
|
-
const compact = token.replace(/\s+/g, "");
|
|
575
|
-
const withoutAnnotation = compact.replace(/[((【[].*?[))】\]]/gu, "");
|
|
576
|
-
const knownTokens = new Set([
|
|
577
|
-
"all",
|
|
578
|
-
"unlimited",
|
|
579
|
-
"infinity",
|
|
580
|
-
"inf",
|
|
581
|
-
"max",
|
|
582
|
-
"full",
|
|
583
|
-
"allcandidates",
|
|
584
|
-
"全部",
|
|
585
|
-
"全量",
|
|
586
|
-
"不限",
|
|
587
|
-
"扫到底",
|
|
588
|
-
"全部候选人",
|
|
589
|
-
"所有候选人",
|
|
590
|
-
"全部人选",
|
|
591
|
-
"所有人选",
|
|
592
|
-
"直到完成所有人选"
|
|
593
|
-
]);
|
|
594
|
-
if (knownTokens.has(token) || knownTokens.has(compact) || knownTokens.has(withoutAnnotation)) return true;
|
|
595
|
-
if (/^(?:all|unlimited|infinity|inf|max|full)(?:candidate|candidates)?$/i.test(compact)) return true;
|
|
596
|
-
if (/^(?:all|unlimited|infinity|inf|max|full)(?:候选人|人选|牛人|人才|人员)?$/iu.test(withoutAnnotation)) return true;
|
|
597
|
-
if (/^(?:全部|所有|全量|不限)(?:候选人|人选|牛人|人才|人员)?$/u.test(compact)) return true;
|
|
598
|
-
if (!/\d/.test(compact) && /(?:扫到底|全部候选人|所有候选人|全部人选|所有人选)/u.test(compact)) return true;
|
|
599
|
-
return false;
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
function getWrappedTargetCountValue(value) {
|
|
603
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return value;
|
|
604
|
-
for (const key of TARGET_COUNT_WRAPPER_KEYS) {
|
|
605
|
-
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
606
|
-
return value[key];
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
return value;
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
export function getBossChatTargetCountValue(input = {}) {
|
|
613
|
-
if (!input || typeof input !== "object" || Array.isArray(input)) return undefined;
|
|
614
|
-
if (Object.prototype.hasOwnProperty.call(input, "target_count") && input.target_count !== undefined && input.target_count !== null) {
|
|
615
|
-
return input.target_count;
|
|
616
|
-
}
|
|
617
|
-
if (Object.prototype.hasOwnProperty.call(input, "targetCount") && input.targetCount !== undefined && input.targetCount !== null) {
|
|
618
|
-
return input.targetCount;
|
|
619
|
-
}
|
|
620
|
-
if (Object.prototype.hasOwnProperty.call(input, "target_count")) return input.target_count;
|
|
621
|
-
if (Object.prototype.hasOwnProperty.call(input, "targetCount")) return input.targetCount;
|
|
622
|
-
return undefined;
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
function cloneForDiagnostics(value) {
|
|
626
|
-
if (value === undefined) return undefined;
|
|
627
|
-
if (value === null || ["string", "number", "boolean"].includes(typeof value)) return value;
|
|
628
|
-
try {
|
|
629
|
-
return JSON.parse(JSON.stringify(value));
|
|
630
|
-
} catch {
|
|
631
|
-
return String(value);
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
export function buildTargetCountCompatibilityHints({
|
|
636
|
-
argumentName = "target_count",
|
|
637
|
-
recommendedArgumentPatch = { target_count: TARGET_COUNT_CANONICAL_ALL },
|
|
638
|
-
includeOptions = true
|
|
639
|
-
} = {}) {
|
|
640
|
-
const normalizedArgumentName = normalizeText(argumentName) || "target_count";
|
|
641
|
-
const clonedRecommendedPatch = cloneForDiagnostics(recommendedArgumentPatch)
|
|
642
|
-
|| { target_count: TARGET_COUNT_CANONICAL_ALL };
|
|
643
|
-
const literal = `${normalizedArgumentName}="${TARGET_COUNT_CANONICAL_ALL}"`;
|
|
644
|
-
const base = {
|
|
645
|
-
argument_name: normalizedArgumentName,
|
|
646
|
-
answer_format: `${normalizedArgumentName} = 正整数 | "${TARGET_COUNT_CANONICAL_ALL}"`,
|
|
647
|
-
canonical_unlimited_value: TARGET_COUNT_CANONICAL_ALL,
|
|
648
|
-
recommended_value: TARGET_COUNT_CANONICAL_ALL,
|
|
649
|
-
recommended_argument_patch: clonedRecommendedPatch,
|
|
650
|
-
accepted_examples: TARGET_COUNT_ACCEPTED_EXAMPLES.slice()
|
|
651
|
-
};
|
|
652
|
-
if (!includeOptions) return base;
|
|
653
|
-
return {
|
|
654
|
-
...base,
|
|
655
|
-
options: [
|
|
656
|
-
{
|
|
657
|
-
label: `扫到底(必须传 ${literal},推荐)`,
|
|
658
|
-
value: TARGET_COUNT_CANONICAL_ALL,
|
|
659
|
-
canonical_value: TARGET_COUNT_CANONICAL_ALL,
|
|
660
|
-
argument_patch: cloneForDiagnostics(clonedRecommendedPatch)
|
|
661
|
-
},
|
|
662
|
-
{
|
|
663
|
-
label: `不限(等价于 ${literal})`,
|
|
664
|
-
value: "unlimited",
|
|
665
|
-
canonical_value: TARGET_COUNT_CANONICAL_ALL,
|
|
666
|
-
argument_patch: cloneForDiagnostics(clonedRecommendedPatch)
|
|
667
|
-
},
|
|
668
|
-
{
|
|
669
|
-
label: `全部候选人(等价于 ${literal})`,
|
|
670
|
-
value: "全部候选人",
|
|
671
|
-
canonical_value: TARGET_COUNT_CANONICAL_ALL,
|
|
672
|
-
argument_patch: cloneForDiagnostics(clonedRecommendedPatch)
|
|
673
|
-
},
|
|
674
|
-
{
|
|
675
|
-
label: `所有候选人(等价于 ${literal})`,
|
|
676
|
-
value: "所有候选人",
|
|
677
|
-
canonical_value: TARGET_COUNT_CANONICAL_ALL,
|
|
678
|
-
argument_patch: cloneForDiagnostics(clonedRecommendedPatch)
|
|
679
|
-
}
|
|
680
|
-
]
|
|
681
|
-
};
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
export function normalizeTargetCountInput(value) {
|
|
685
|
-
if (value === undefined || value === null) {
|
|
686
|
-
return {
|
|
687
|
-
provided: false,
|
|
688
|
-
targetCount: null,
|
|
689
|
-
cliArg: null,
|
|
690
|
-
publicValue: null,
|
|
691
|
-
rawValue: value,
|
|
692
|
-
parseError: null
|
|
693
|
-
};
|
|
694
|
-
}
|
|
695
|
-
const unwrapped = getWrappedTargetCountValue(value);
|
|
696
|
-
if (unwrapped !== value) {
|
|
697
|
-
return normalizeTargetCountInput(unwrapped);
|
|
698
|
-
}
|
|
699
|
-
const raw = normalizeText(unwrapped);
|
|
700
|
-
if (!raw) {
|
|
701
|
-
return {
|
|
702
|
-
provided: false,
|
|
703
|
-
targetCount: null,
|
|
704
|
-
cliArg: null,
|
|
705
|
-
publicValue: null,
|
|
706
|
-
rawValue: value,
|
|
707
|
-
parseError: null
|
|
708
|
-
};
|
|
709
|
-
}
|
|
710
|
-
if (isUnlimitedTargetCountToken(raw)) {
|
|
711
|
-
return {
|
|
712
|
-
provided: true,
|
|
713
|
-
targetCount: null,
|
|
714
|
-
cliArg: "-1",
|
|
715
|
-
publicValue: TARGET_COUNT_CANONICAL_ALL,
|
|
716
|
-
rawValue: cloneForDiagnostics(value),
|
|
717
|
-
parseError: null
|
|
718
|
-
};
|
|
719
|
-
}
|
|
720
|
-
const parsed = Number.parseInt(String(raw), 10);
|
|
721
|
-
if (Number.isFinite(parsed) && parsed === -1) {
|
|
722
|
-
return {
|
|
723
|
-
provided: true,
|
|
724
|
-
targetCount: null,
|
|
725
|
-
cliArg: "-1",
|
|
726
|
-
publicValue: TARGET_COUNT_CANONICAL_ALL,
|
|
727
|
-
rawValue: cloneForDiagnostics(value),
|
|
728
|
-
parseError: null
|
|
729
|
-
};
|
|
730
|
-
}
|
|
731
|
-
if (Number.isFinite(parsed) && parsed > 0) {
|
|
732
|
-
return {
|
|
733
|
-
provided: true,
|
|
734
|
-
targetCount: parsed,
|
|
735
|
-
cliArg: String(parsed),
|
|
736
|
-
publicValue: parsed,
|
|
737
|
-
rawValue: cloneForDiagnostics(value),
|
|
738
|
-
parseError: null
|
|
739
|
-
};
|
|
740
|
-
}
|
|
741
|
-
return {
|
|
742
|
-
provided: false,
|
|
743
|
-
targetCount: null,
|
|
744
|
-
cliArg: null,
|
|
745
|
-
publicValue: null,
|
|
746
|
-
rawValue: cloneForDiagnostics(value),
|
|
747
|
-
parseError: "target_count must be a positive integer, -1, or one of: all, unlimited, 全部, 不限, 扫到底, 全量, 全部候选人, 所有候选人"
|
|
748
|
-
};
|
|
749
|
-
}
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import { normalizeHumanBehaviorOptions } from "./core/browser/index.js";
|
|
6
|
+
|
|
7
|
+
const BOSS_CHAT_RUNTIME_SUBDIR = "boss-chat";
|
|
8
|
+
const TARGET_COUNT_WRAPPER_KEYS = ["target_count", "targetCount", "value", "count", "limit"];
|
|
9
|
+
const SCREEN_CONFIG_TEMPLATE_DEFAULTS = Object.freeze({
|
|
10
|
+
baseUrl: "https://api.openai.com/v1",
|
|
11
|
+
apiKey: "replace-with-your-api-key",
|
|
12
|
+
model: "gpt-4.1-mini"
|
|
13
|
+
});
|
|
14
|
+
const LLM_THINKING_LEVELS = new Set(["off", "minimal", "low", "medium", "high", "auto", "current"]);
|
|
15
|
+
|
|
16
|
+
export const TARGET_COUNT_CANONICAL_ALL = "all";
|
|
17
|
+
export const TARGET_COUNT_ACCEPTED_EXAMPLES = [TARGET_COUNT_CANONICAL_ALL, -1, 20, "全部候选人"];
|
|
18
|
+
|
|
19
|
+
function normalizeText(value) {
|
|
20
|
+
return String(value || "").replace(/\s+/g, " ").trim();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getStateHome() {
|
|
24
|
+
return process.env.BOSS_RECOMMEND_HOME
|
|
25
|
+
? path.resolve(process.env.BOSS_RECOMMEND_HOME)
|
|
26
|
+
: path.join(os.homedir(), ".boss-recommend-mcp");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function getCodexHome() {
|
|
30
|
+
return process.env.CODEX_HOME
|
|
31
|
+
? path.resolve(process.env.CODEX_HOME)
|
|
32
|
+
: path.join(os.homedir(), ".codex");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function pathExists(targetPath) {
|
|
36
|
+
try {
|
|
37
|
+
return Boolean(targetPath) && fs.existsSync(targetPath);
|
|
38
|
+
} catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function isRootDirectory(workspaceRoot) {
|
|
44
|
+
const root = path.resolve(String(workspaceRoot || ""));
|
|
45
|
+
return path.parse(root).root.toLowerCase() === root.toLowerCase();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function isEphemeralNpxWorkspaceRoot(workspaceRoot) {
|
|
49
|
+
const root = path.resolve(String(workspaceRoot || ""));
|
|
50
|
+
const normalized = root.replace(/\\/g, "/").toLowerCase();
|
|
51
|
+
return (
|
|
52
|
+
normalized.includes("/appdata/local/npm-cache/_npx/")
|
|
53
|
+
|| normalized.includes("/node_modules/@reconcrap/boss-recommend-mcp")
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function isSystemDirectoryWorkspaceRoot(workspaceRoot) {
|
|
58
|
+
const root = path.resolve(String(workspaceRoot || ""));
|
|
59
|
+
const normalized = root.replace(/\\/g, "/").toLowerCase();
|
|
60
|
+
if (process.platform === "win32") {
|
|
61
|
+
return (
|
|
62
|
+
normalized.endsWith("/windows")
|
|
63
|
+
|| normalized.endsWith("/windows/system32")
|
|
64
|
+
|| normalized.endsWith("/windows/syswow64")
|
|
65
|
+
|| normalized.endsWith("/program files")
|
|
66
|
+
|| normalized.endsWith("/program files (x86)")
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
return (
|
|
70
|
+
normalized === "/system"
|
|
71
|
+
|| normalized.startsWith("/system/")
|
|
72
|
+
|| normalized === "/usr"
|
|
73
|
+
|| normalized.startsWith("/usr/")
|
|
74
|
+
|| normalized === "/bin"
|
|
75
|
+
|| normalized.startsWith("/bin/")
|
|
76
|
+
|| normalized === "/sbin"
|
|
77
|
+
|| normalized.startsWith("/sbin/")
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function shouldIgnoreWorkspaceConfigRoot(workspaceRoot) {
|
|
82
|
+
const root = path.resolve(String(workspaceRoot || process.cwd()));
|
|
83
|
+
const home = path.resolve(os.homedir());
|
|
84
|
+
return (
|
|
85
|
+
isEphemeralNpxWorkspaceRoot(root)
|
|
86
|
+
|| isRootDirectory(root)
|
|
87
|
+
|| root.toLowerCase() === home.toLowerCase()
|
|
88
|
+
|| isSystemDirectoryWorkspaceRoot(root)
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function resolveWorkspaceConfigCandidates(workspaceRoot) {
|
|
93
|
+
const root = path.resolve(String(workspaceRoot || process.cwd()));
|
|
94
|
+
if (shouldIgnoreWorkspaceConfigRoot(root)) return [];
|
|
95
|
+
const directPath = path.join(root, "config", "screening-config.json");
|
|
96
|
+
const nestedPath = path.join(root, "boss-recommend-mcp", "config", "screening-config.json");
|
|
97
|
+
const candidates = [directPath];
|
|
98
|
+
if (path.basename(root).toLowerCase() !== "boss-recommend-mcp") {
|
|
99
|
+
candidates.push(nestedPath);
|
|
100
|
+
}
|
|
101
|
+
return Array.from(new Set(candidates));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function getUserConfigPath() {
|
|
105
|
+
return path.join(getStateHome(), "screening-config.json");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function getLegacyUserConfigPath() {
|
|
109
|
+
return path.join(getCodexHome(), "boss-recommend-mcp", "screening-config.json");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function getUserCalibrationPath() {
|
|
113
|
+
return path.join(getCodexHome(), "boss-recommend-mcp", "favorite-calibration.json");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function buildScreenConfigCandidateMap(workspaceRoot) {
|
|
117
|
+
return {
|
|
118
|
+
env_path: process.env.BOSS_RECOMMEND_SCREEN_CONFIG
|
|
119
|
+
? path.resolve(process.env.BOSS_RECOMMEND_SCREEN_CONFIG)
|
|
120
|
+
: null,
|
|
121
|
+
workspace_paths: resolveWorkspaceConfigCandidates(workspaceRoot),
|
|
122
|
+
user_path: getUserConfigPath(),
|
|
123
|
+
legacy_path: getLegacyUserConfigPath()
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function resolveScreenConfigCandidates(workspaceRoot) {
|
|
128
|
+
const candidateMap = buildScreenConfigCandidateMap(workspaceRoot);
|
|
129
|
+
return [
|
|
130
|
+
candidateMap.env_path,
|
|
131
|
+
candidateMap.user_path,
|
|
132
|
+
...candidateMap.workspace_paths,
|
|
133
|
+
candidateMap.legacy_path
|
|
134
|
+
].filter(Boolean);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function canWriteDirectory(targetDir) {
|
|
138
|
+
try {
|
|
139
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
140
|
+
fs.accessSync(targetDir, fs.constants.W_OK);
|
|
141
|
+
return true;
|
|
142
|
+
} catch {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function resolveWritableScreenConfigPath(workspaceRoot) {
|
|
148
|
+
const candidateMap = buildScreenConfigCandidateMap(workspaceRoot);
|
|
149
|
+
const workspacePreferred = candidateMap.workspace_paths?.[0] || null;
|
|
150
|
+
if (candidateMap.env_path) return candidateMap.env_path;
|
|
151
|
+
if (candidateMap.user_path && canWriteDirectory(path.dirname(candidateMap.user_path))) {
|
|
152
|
+
return candidateMap.user_path;
|
|
153
|
+
}
|
|
154
|
+
if (workspacePreferred && canWriteDirectory(path.dirname(workspacePreferred))) {
|
|
155
|
+
return workspacePreferred;
|
|
156
|
+
}
|
|
157
|
+
if (workspacePreferred) return workspacePreferred;
|
|
158
|
+
return candidateMap.user_path || candidateMap.legacy_path;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function resolveScreenConfigPath(workspaceRoot) {
|
|
162
|
+
const candidateMap = buildScreenConfigCandidateMap(workspaceRoot);
|
|
163
|
+
if (candidateMap.env_path) return candidateMap.env_path;
|
|
164
|
+
if (candidateMap.user_path && pathExists(candidateMap.user_path)) return candidateMap.user_path;
|
|
165
|
+
const existingWorkspacePath = candidateMap.workspace_paths.find((item) => pathExists(item));
|
|
166
|
+
if (existingWorkspacePath) return existingWorkspacePath;
|
|
167
|
+
return resolveWritableScreenConfigPath(workspaceRoot) || candidateMap.legacy_path;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function readJsonFile(filePath) {
|
|
171
|
+
if (!filePath || !pathExists(filePath)) return null;
|
|
172
|
+
try {
|
|
173
|
+
return JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
174
|
+
} catch {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function isUsableFeaturedCalibrationFile(filePath) {
|
|
180
|
+
const parsed = readJsonFile(filePath);
|
|
181
|
+
return Boolean(
|
|
182
|
+
parsed
|
|
183
|
+
&& typeof parsed === "object"
|
|
184
|
+
&& !Array.isArray(parsed)
|
|
185
|
+
&& parsed.favoritePosition
|
|
186
|
+
&& Number.isFinite(parsed.favoritePosition.pageX)
|
|
187
|
+
&& Number.isFinite(parsed.favoritePosition.pageY)
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function resolveFeaturedCalibrationPath(workspaceRoot) {
|
|
192
|
+
const fromEnv = normalizeText(process.env.BOSS_RECOMMEND_CALIBRATION_FILE || "");
|
|
193
|
+
if (fromEnv) return path.resolve(fromEnv);
|
|
194
|
+
|
|
195
|
+
const configResolution = resolveBossScreeningConfig(workspaceRoot);
|
|
196
|
+
const configPath = configResolution.config_path || resolveScreenConfigPath(workspaceRoot) || getUserConfigPath();
|
|
197
|
+
const config = readJsonFile(configPath);
|
|
198
|
+
const calibrationFile = normalizeText(config?.calibrationFile || "");
|
|
199
|
+
if (calibrationFile && configPath) {
|
|
200
|
+
return path.resolve(path.dirname(configPath), calibrationFile);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return getUserCalibrationPath();
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function resolveRecruitCalibrationScriptPath(workspaceRoot) {
|
|
207
|
+
const fromEnv = normalizeText(process.env.BOSS_RECOMMEND_RECRUIT_CALIBRATION_SCRIPT || "");
|
|
208
|
+
const workspaceResolved = path.resolve(String(workspaceRoot || process.cwd()));
|
|
209
|
+
const appData = process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming");
|
|
210
|
+
const candidates = [
|
|
211
|
+
fromEnv,
|
|
212
|
+
path.join(workspaceResolved, "..", "..", "boss recruit pipeline", "boss-recruit-mcp", "vendor", "boss-screen-cli", "calibrate-favorite-position-v2.cjs"),
|
|
213
|
+
path.join(workspaceResolved, "..", "boss recruit pipeline", "boss-recruit-mcp", "vendor", "boss-screen-cli", "calibrate-favorite-position-v2.cjs"),
|
|
214
|
+
path.join(appData, "npm", "node_modules", "@reconcrap", "boss-recruit-mcp", "vendor", "boss-screen-cli", "calibrate-favorite-position-v2.cjs")
|
|
215
|
+
].filter(Boolean).map((item) => path.resolve(item));
|
|
216
|
+
|
|
217
|
+
for (const candidate of new Set(candidates)) {
|
|
218
|
+
if (pathExists(candidate)) return candidate;
|
|
219
|
+
}
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function parsePositiveInteger(raw, fallback = null) {
|
|
224
|
+
const parsed = Number.parseInt(String(raw || ""), 10);
|
|
225
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function parseConfigNumber(raw, fallback = null) {
|
|
229
|
+
if (raw === undefined || raw === null || raw === "") return fallback;
|
|
230
|
+
const parsed = Number(raw);
|
|
231
|
+
return Number.isFinite(parsed) ? parsed : fallback;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function parseConfigBoolean(raw, fallback = false) {
|
|
235
|
+
if (typeof raw === "boolean") return raw;
|
|
236
|
+
const normalized = normalizeText(raw).toLowerCase();
|
|
237
|
+
if (["true", "1", "yes", "y", "on", "enabled"].includes(normalized)) return true;
|
|
238
|
+
if (["false", "0", "no", "n", "off", "disabled"].includes(normalized)) return false;
|
|
239
|
+
return fallback;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function readFirstOwn(source, keys = []) {
|
|
243
|
+
if (!source || typeof source !== "object") return undefined;
|
|
244
|
+
for (const key of keys) {
|
|
245
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) return source[key];
|
|
246
|
+
}
|
|
247
|
+
return undefined;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function parseOptionalConfigBoolean(raw) {
|
|
251
|
+
if (raw === undefined || raw === null || raw === "") return null;
|
|
252
|
+
return parseConfigBoolean(raw, null);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function applyHumanBehaviorProfileDefaults(target, profileRaw) {
|
|
256
|
+
const defaults = normalizeHumanBehaviorOptions(String(profileRaw || ""));
|
|
257
|
+
Object.assign(target, {
|
|
258
|
+
enabled: defaults.enabled,
|
|
259
|
+
profile: defaults.profile,
|
|
260
|
+
clickMovement: defaults.clickMovement,
|
|
261
|
+
textEntry: defaults.textEntry,
|
|
262
|
+
listScrollJitter: defaults.listScrollJitter,
|
|
263
|
+
shortRest: defaults.shortRest,
|
|
264
|
+
batchRest: defaults.batchRest,
|
|
265
|
+
actionCooldown: defaults.actionCooldown
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export function resolveHumanBehaviorForRun(args = {}, config = {}) {
|
|
270
|
+
const base = normalizeHumanBehaviorOptions(config.humanBehavior || config.human_behavior || null, {
|
|
271
|
+
legacyEnabled: config.humanRestEnabled === true
|
|
272
|
+
});
|
|
273
|
+
const override = {};
|
|
274
|
+
const rawBehavior = readFirstOwn(args, ["human_behavior", "humanBehavior"]);
|
|
275
|
+
if (typeof rawBehavior === "boolean") {
|
|
276
|
+
override.enabled = rawBehavior;
|
|
277
|
+
} else if (typeof rawBehavior === "string") {
|
|
278
|
+
applyHumanBehaviorProfileDefaults(override, rawBehavior);
|
|
279
|
+
} else if (rawBehavior && typeof rawBehavior === "object" && !Array.isArray(rawBehavior)) {
|
|
280
|
+
const rawProfile = readFirstOwn(rawBehavior, ["profile", "mode", "behaviorProfile", "behavior_profile"]);
|
|
281
|
+
if (rawProfile !== undefined) applyHumanBehaviorProfileDefaults(override, rawProfile);
|
|
282
|
+
Object.assign(override, rawBehavior);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const profile = readFirstOwn(args, ["human_behavior_profile", "humanBehaviorProfile"]);
|
|
286
|
+
if (profile !== undefined) applyHumanBehaviorProfileDefaults(override, profile);
|
|
287
|
+
const enabled = parseOptionalConfigBoolean(readFirstOwn(args, [
|
|
288
|
+
"human_behavior_enabled",
|
|
289
|
+
"humanBehaviorEnabled"
|
|
290
|
+
]));
|
|
291
|
+
if (enabled !== null) {
|
|
292
|
+
override.enabled = enabled;
|
|
293
|
+
if (enabled === true && !override.profile) applyHumanBehaviorProfileDefaults(override, "paced");
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const safePacing = parseOptionalConfigBoolean(readFirstOwn(args, ["safe_pacing", "safePacing"]));
|
|
297
|
+
if (safePacing === true) {
|
|
298
|
+
applyHumanBehaviorProfileDefaults(override, "paced");
|
|
299
|
+
} else if (safePacing === false) {
|
|
300
|
+
override.enabled = false;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const batchRest = parseOptionalConfigBoolean(readFirstOwn(args, [
|
|
304
|
+
"batch_rest_enabled",
|
|
305
|
+
"batchRestEnabled",
|
|
306
|
+
"batch_rest"
|
|
307
|
+
]));
|
|
308
|
+
if (batchRest === true) {
|
|
309
|
+
applyHumanBehaviorProfileDefaults(override, "paced_with_rests");
|
|
310
|
+
} else if (batchRest === false) {
|
|
311
|
+
override.batchRest = false;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return normalizeHumanBehaviorOptions({
|
|
315
|
+
...base,
|
|
316
|
+
...override
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function normalizeLlmThinkingLevel(raw, fallback = "low") {
|
|
321
|
+
const normalized = normalizeText(raw).toLowerCase();
|
|
322
|
+
return LLM_THINKING_LEVELS.has(normalized) ? normalized : fallback;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function firstConfiguredValue(...values) {
|
|
326
|
+
for (const value of values) {
|
|
327
|
+
if (value === undefined || value === null) continue;
|
|
328
|
+
if (typeof value === "string" && !value.trim()) continue;
|
|
329
|
+
return value;
|
|
330
|
+
}
|
|
331
|
+
return "";
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function resolveRawLlmModelEntries(config = {}) {
|
|
335
|
+
if (Array.isArray(config.llmModels) && config.llmModels.length > 0) return config.llmModels;
|
|
336
|
+
if (Array.isArray(config.models) && config.models.length > 0) return config.models;
|
|
337
|
+
return [config];
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function normalizeScreeningLlmModel(config = {}, rawEntry = {}, index = 0) {
|
|
341
|
+
const entry = typeof rawEntry === "string"
|
|
342
|
+
? { model: rawEntry }
|
|
343
|
+
: (rawEntry && typeof rawEntry === "object" && !Array.isArray(rawEntry) ? rawEntry : {});
|
|
344
|
+
return {
|
|
345
|
+
name: normalizeText(firstConfiguredValue(entry.name, entry.label, entry.id, entry.providerName, entry.provider)),
|
|
346
|
+
baseUrl: normalizeText(firstConfiguredValue(entry.baseUrl, entry.base_url, config.baseUrl, config.base_url)).replace(/\/+$/, ""),
|
|
347
|
+
apiKey: normalizeText(firstConfiguredValue(entry.apiKey, entry.api_key, config.apiKey, config.api_key)),
|
|
348
|
+
model: normalizeText(firstConfiguredValue(entry.model, entry.modelName, entry.model_name, typeof rawEntry === "string" ? rawEntry : "", config.model)),
|
|
349
|
+
openaiOrganization: normalizeText(firstConfiguredValue(entry.openaiOrganization, entry.organization, config.openaiOrganization, config.organization)),
|
|
350
|
+
openaiProject: normalizeText(firstConfiguredValue(entry.openaiProject, entry.project, config.openaiProject, config.project)),
|
|
351
|
+
llmThinkingLevel: normalizeLlmThinkingLevel(
|
|
352
|
+
firstConfiguredValue(entry.llmThinkingLevel, entry.thinkingLevel, entry.reasoningEffort, config.llmThinkingLevel, config.thinkingLevel, config.reasoningEffort),
|
|
353
|
+
"low"
|
|
354
|
+
),
|
|
355
|
+
llmTimeoutMs: parsePositiveInteger(firstConfiguredValue(entry.llmTimeoutMs, entry.timeoutMs, config.llmTimeoutMs, config.timeoutMs), null),
|
|
356
|
+
llmMaxRetries: parsePositiveInteger(firstConfiguredValue(entry.llmMaxRetries, entry.maxRetries, config.llmMaxRetries, config.maxRetries), null),
|
|
357
|
+
llmMaxTokens: parsePositiveInteger(firstConfiguredValue(entry.llmMaxTokens, entry.maxTokens, config.llmMaxTokens, config.maxTokens), null),
|
|
358
|
+
llmMaxCompletionTokens: parsePositiveInteger(
|
|
359
|
+
firstConfiguredValue(entry.llmMaxCompletionTokens, entry.maxCompletionTokens, config.llmMaxCompletionTokens, config.maxCompletionTokens),
|
|
360
|
+
null
|
|
361
|
+
),
|
|
362
|
+
llmImageLimit: parsePositiveInteger(firstConfiguredValue(entry.llmImageLimit, entry.imageLimit, config.llmImageLimit, config.imageLimit), null),
|
|
363
|
+
llmImageDetail: normalizeText(firstConfiguredValue(entry.llmImageDetail, entry.imageDetail, config.llmImageDetail, config.imageDetail)),
|
|
364
|
+
temperature: parseConfigNumber(firstConfiguredValue(entry.temperature, config.temperature), null),
|
|
365
|
+
topP: parseConfigNumber(firstConfiguredValue(entry.topP, entry.top_p, config.topP, config.top_p), null),
|
|
366
|
+
llmProviderIndex: index
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
function normalizeScreeningLlmModels(config = {}) {
|
|
371
|
+
return resolveRawLlmModelEntries(config).map((entry, index) => normalizeScreeningLlmModel(config, entry, index));
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function resolveConfigPathValue(raw, configDir) {
|
|
375
|
+
const normalized = normalizeText(raw);
|
|
376
|
+
if (!normalized) return "";
|
|
377
|
+
return path.isAbsolute(normalized)
|
|
378
|
+
? path.resolve(normalized)
|
|
379
|
+
: path.resolve(configDir || process.cwd(), normalized);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function validateScreeningConfig(config) {
|
|
383
|
+
if (!config || typeof config !== "object" || Array.isArray(config)) {
|
|
384
|
+
return {
|
|
385
|
+
ok: false,
|
|
386
|
+
reason: "INVALID_OR_MISSING_CONFIG",
|
|
387
|
+
message: "screening-config.json 缺失或格式无效。请填写 baseUrl、apiKey、model。"
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
const llmModels = normalizeScreeningLlmModels(config);
|
|
391
|
+
const missing = [];
|
|
392
|
+
for (const [index, llmModel] of llmModels.entries()) {
|
|
393
|
+
const prefix = llmModels.length > 1 ? `llmModels[${index}]` : "";
|
|
394
|
+
if (!llmModel.baseUrl) missing.push(prefix ? `${prefix}.baseUrl` : "baseUrl");
|
|
395
|
+
if (!llmModel.apiKey) missing.push(prefix ? `${prefix}.apiKey` : "apiKey");
|
|
396
|
+
if (!llmModel.model) missing.push(prefix ? `${prefix}.model` : "model");
|
|
397
|
+
}
|
|
398
|
+
if (missing.length > 0) {
|
|
399
|
+
return {
|
|
400
|
+
ok: false,
|
|
401
|
+
reason: "MISSING_REQUIRED_FIELDS",
|
|
402
|
+
message: `screening-config.json 缺少必填字段:${missing.join(", ")}。`
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
const placeholderModel = llmModels.find((item) => /^replace-with/i.test(item.apiKey) || item.apiKey === SCREEN_CONFIG_TEMPLATE_DEFAULTS.apiKey);
|
|
406
|
+
if (placeholderModel) {
|
|
407
|
+
return {
|
|
408
|
+
ok: false,
|
|
409
|
+
reason: "PLACEHOLDER_API_KEY",
|
|
410
|
+
message: "screening-config.json 的 apiKey 仍是模板占位符,请填写真实 API Key。"
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
const firstModel = llmModels[0] || {};
|
|
414
|
+
if (
|
|
415
|
+
llmModels.length === 1
|
|
416
|
+
&& firstModel.baseUrl === SCREEN_CONFIG_TEMPLATE_DEFAULTS.baseUrl
|
|
417
|
+
&& firstModel.apiKey === SCREEN_CONFIG_TEMPLATE_DEFAULTS.apiKey
|
|
418
|
+
&& firstModel.model === SCREEN_CONFIG_TEMPLATE_DEFAULTS.model
|
|
419
|
+
) {
|
|
420
|
+
return {
|
|
421
|
+
ok: false,
|
|
422
|
+
reason: "PLACEHOLDER_TEMPLATE_VALUES",
|
|
423
|
+
message: "screening-config.json 仍是默认模板值,请填写 baseUrl、apiKey、model。"
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
return { ok: true, reason: "OK", message: "screening-config.json 校验通过。" };
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
export function resolveBossChatDataDir() {
|
|
430
|
+
if (process.env.BOSS_CHAT_HOME) {
|
|
431
|
+
return {
|
|
432
|
+
data_dir: path.resolve(process.env.BOSS_CHAT_HOME),
|
|
433
|
+
data_dir_source: "env:BOSS_CHAT_HOME"
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
const stateHome = getStateHome();
|
|
437
|
+
const source = process.env.BOSS_RECOMMEND_HOME
|
|
438
|
+
? "default:env:BOSS_RECOMMEND_HOME"
|
|
439
|
+
: "default:user_home";
|
|
440
|
+
return {
|
|
441
|
+
data_dir: path.join(stateHome, BOSS_CHAT_RUNTIME_SUBDIR),
|
|
442
|
+
data_dir_source: source
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
export function getBossChatDataDir() {
|
|
447
|
+
return resolveBossChatDataDir().data_dir;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
export function getLegacyBossChatWorkspaceDataDir(workspaceRoot) {
|
|
451
|
+
const root = path.resolve(String(workspaceRoot || ""));
|
|
452
|
+
if (!root || isRootDirectory(root) || isSystemDirectoryWorkspaceRoot(root)) return null;
|
|
453
|
+
return path.join(root, ".boss-chat");
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
export function resolveBossChatRuntimeLayout(workspaceRoot) {
|
|
457
|
+
const resolvedDataDir = resolveBossChatDataDir();
|
|
458
|
+
const legacyWorkspaceDir = getLegacyBossChatWorkspaceDataDir(workspaceRoot);
|
|
459
|
+
const migrationSourceDir = legacyWorkspaceDir && pathExists(legacyWorkspaceDir) && !pathExists(resolvedDataDir.data_dir)
|
|
460
|
+
? legacyWorkspaceDir
|
|
461
|
+
: null;
|
|
462
|
+
return {
|
|
463
|
+
workspace_root: workspaceRoot ? path.resolve(String(workspaceRoot)) : null,
|
|
464
|
+
data_dir: resolvedDataDir.data_dir,
|
|
465
|
+
data_dir_source: resolvedDataDir.data_dir_source,
|
|
466
|
+
legacy_workspace_dir: legacyWorkspaceDir,
|
|
467
|
+
migration_source_dir: migrationSourceDir,
|
|
468
|
+
migration_pending: Boolean(migrationSourceDir)
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
export function getBossScreenConfigResolution(workspaceRoot) {
|
|
473
|
+
const candidateMap = buildScreenConfigCandidateMap(workspaceRoot);
|
|
474
|
+
const workspaceRootResolved = path.resolve(String(workspaceRoot || process.cwd()));
|
|
475
|
+
return {
|
|
476
|
+
resolved_path: resolveScreenConfigPath(workspaceRoot) || null,
|
|
477
|
+
candidate_paths: resolveScreenConfigCandidates(workspaceRoot),
|
|
478
|
+
workspace_root: workspaceRootResolved,
|
|
479
|
+
workspace_ephemeral: isEphemeralNpxWorkspaceRoot(workspaceRootResolved),
|
|
480
|
+
workspace_ignored_for_config: shouldIgnoreWorkspaceConfigRoot(workspaceRootResolved),
|
|
481
|
+
writable_path: resolveWritableScreenConfigPath(workspaceRoot),
|
|
482
|
+
legacy_path: candidateMap.legacy_path
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
export function getFeaturedCalibrationResolution(workspaceRoot) {
|
|
487
|
+
const calibrationPath = resolveFeaturedCalibrationPath(workspaceRoot);
|
|
488
|
+
return {
|
|
489
|
+
calibration_path: calibrationPath,
|
|
490
|
+
calibration_exists: pathExists(calibrationPath),
|
|
491
|
+
calibration_usable: isUsableFeaturedCalibrationFile(calibrationPath),
|
|
492
|
+
calibration_script_path: resolveRecruitCalibrationScriptPath(workspaceRoot)
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
export function resolveBossScreeningConfig(workspaceRoot) {
|
|
497
|
+
const candidatePaths = resolveScreenConfigCandidates(workspaceRoot);
|
|
498
|
+
const configPath = resolveScreenConfigPath(workspaceRoot) || null;
|
|
499
|
+
const configDir = configPath ? path.dirname(configPath) : null;
|
|
500
|
+
if (!configPath || !pathExists(configPath)) {
|
|
501
|
+
return {
|
|
502
|
+
ok: false,
|
|
503
|
+
error: {
|
|
504
|
+
code: "SCREEN_CONFIG_ERROR",
|
|
505
|
+
message: `screening-config.json 不存在。请先完成 recommend 配置。${configPath ? ` (path: ${configPath})` : ""}`,
|
|
506
|
+
retryable: true
|
|
507
|
+
},
|
|
508
|
+
config_path: configPath,
|
|
509
|
+
config_dir: configDir,
|
|
510
|
+
candidate_paths: candidatePaths
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
const parsed = readJsonFile(configPath);
|
|
514
|
+
const validation = validateScreeningConfig(parsed);
|
|
515
|
+
if (!validation.ok) {
|
|
516
|
+
return {
|
|
517
|
+
ok: false,
|
|
518
|
+
error: {
|
|
519
|
+
code: "SCREEN_CONFIG_ERROR",
|
|
520
|
+
message: `${validation.message} (path: ${configPath})`,
|
|
521
|
+
retryable: true
|
|
522
|
+
},
|
|
523
|
+
config_path: configPath,
|
|
524
|
+
config_dir: configDir,
|
|
525
|
+
candidate_paths: candidatePaths
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
const llmModels = normalizeScreeningLlmModels(parsed);
|
|
529
|
+
const primaryLlmModel = llmModels[0] || {};
|
|
530
|
+
const greetingText = normalizeText(
|
|
531
|
+
parsed.greetingMessage
|
|
532
|
+
|| parsed.greeting_message
|
|
533
|
+
|| parsed.greetingText
|
|
534
|
+
|| parsed.greeting_text
|
|
535
|
+
|| parsed.greeting
|
|
536
|
+
);
|
|
537
|
+
const humanRestEnabled = parseConfigBoolean(parsed.humanRestEnabled, false);
|
|
538
|
+
const humanBehavior = normalizeHumanBehaviorOptions(parsed.humanBehavior || parsed.human_behavior || null, {
|
|
539
|
+
legacyEnabled: humanRestEnabled
|
|
540
|
+
});
|
|
541
|
+
return {
|
|
542
|
+
ok: true,
|
|
543
|
+
config: {
|
|
544
|
+
...primaryLlmModel,
|
|
545
|
+
baseUrl: primaryLlmModel.baseUrl,
|
|
546
|
+
apiKey: primaryLlmModel.apiKey,
|
|
547
|
+
model: primaryLlmModel.model,
|
|
548
|
+
openaiOrganization: primaryLlmModel.openaiOrganization,
|
|
549
|
+
openaiProject: primaryLlmModel.openaiProject,
|
|
550
|
+
llmModels,
|
|
551
|
+
greetingMessage: greetingText,
|
|
552
|
+
greetingText,
|
|
553
|
+
debugPort: parsePositiveInteger(parsed.debugPort, 9222),
|
|
554
|
+
outputDir: resolveConfigPathValue(parsed.outputDir, configDir),
|
|
555
|
+
humanRestEnabled,
|
|
556
|
+
humanBehavior
|
|
557
|
+
},
|
|
558
|
+
config_path: configPath,
|
|
559
|
+
config_dir: configDir,
|
|
560
|
+
candidate_paths: candidatePaths
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
export function resolveBossConfiguredOutputDir(workspaceRoot, fallbackDir = "") {
|
|
565
|
+
const configResolution = resolveBossScreeningConfig(workspaceRoot);
|
|
566
|
+
const configuredDir = configResolution.ok ? normalizeText(configResolution.config.outputDir) : "";
|
|
567
|
+
if (configuredDir) return configuredDir;
|
|
568
|
+
return fallbackDir ? path.resolve(fallbackDir) : "";
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
function isUnlimitedTargetCountToken(value) {
|
|
572
|
+
const token = normalizeText(value).toLowerCase();
|
|
573
|
+
if (!token) return false;
|
|
574
|
+
const compact = token.replace(/\s+/g, "");
|
|
575
|
+
const withoutAnnotation = compact.replace(/[((【[].*?[))】\]]/gu, "");
|
|
576
|
+
const knownTokens = new Set([
|
|
577
|
+
"all",
|
|
578
|
+
"unlimited",
|
|
579
|
+
"infinity",
|
|
580
|
+
"inf",
|
|
581
|
+
"max",
|
|
582
|
+
"full",
|
|
583
|
+
"allcandidates",
|
|
584
|
+
"全部",
|
|
585
|
+
"全量",
|
|
586
|
+
"不限",
|
|
587
|
+
"扫到底",
|
|
588
|
+
"全部候选人",
|
|
589
|
+
"所有候选人",
|
|
590
|
+
"全部人选",
|
|
591
|
+
"所有人选",
|
|
592
|
+
"直到完成所有人选"
|
|
593
|
+
]);
|
|
594
|
+
if (knownTokens.has(token) || knownTokens.has(compact) || knownTokens.has(withoutAnnotation)) return true;
|
|
595
|
+
if (/^(?:all|unlimited|infinity|inf|max|full)(?:candidate|candidates)?$/i.test(compact)) return true;
|
|
596
|
+
if (/^(?:all|unlimited|infinity|inf|max|full)(?:候选人|人选|牛人|人才|人员)?$/iu.test(withoutAnnotation)) return true;
|
|
597
|
+
if (/^(?:全部|所有|全量|不限)(?:候选人|人选|牛人|人才|人员)?$/u.test(compact)) return true;
|
|
598
|
+
if (!/\d/.test(compact) && /(?:扫到底|全部候选人|所有候选人|全部人选|所有人选)/u.test(compact)) return true;
|
|
599
|
+
return false;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
function getWrappedTargetCountValue(value) {
|
|
603
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return value;
|
|
604
|
+
for (const key of TARGET_COUNT_WRAPPER_KEYS) {
|
|
605
|
+
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
606
|
+
return value[key];
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
return value;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
export function getBossChatTargetCountValue(input = {}) {
|
|
613
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) return undefined;
|
|
614
|
+
if (Object.prototype.hasOwnProperty.call(input, "target_count") && input.target_count !== undefined && input.target_count !== null) {
|
|
615
|
+
return input.target_count;
|
|
616
|
+
}
|
|
617
|
+
if (Object.prototype.hasOwnProperty.call(input, "targetCount") && input.targetCount !== undefined && input.targetCount !== null) {
|
|
618
|
+
return input.targetCount;
|
|
619
|
+
}
|
|
620
|
+
if (Object.prototype.hasOwnProperty.call(input, "target_count")) return input.target_count;
|
|
621
|
+
if (Object.prototype.hasOwnProperty.call(input, "targetCount")) return input.targetCount;
|
|
622
|
+
return undefined;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
function cloneForDiagnostics(value) {
|
|
626
|
+
if (value === undefined) return undefined;
|
|
627
|
+
if (value === null || ["string", "number", "boolean"].includes(typeof value)) return value;
|
|
628
|
+
try {
|
|
629
|
+
return JSON.parse(JSON.stringify(value));
|
|
630
|
+
} catch {
|
|
631
|
+
return String(value);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
export function buildTargetCountCompatibilityHints({
|
|
636
|
+
argumentName = "target_count",
|
|
637
|
+
recommendedArgumentPatch = { target_count: TARGET_COUNT_CANONICAL_ALL },
|
|
638
|
+
includeOptions = true
|
|
639
|
+
} = {}) {
|
|
640
|
+
const normalizedArgumentName = normalizeText(argumentName) || "target_count";
|
|
641
|
+
const clonedRecommendedPatch = cloneForDiagnostics(recommendedArgumentPatch)
|
|
642
|
+
|| { target_count: TARGET_COUNT_CANONICAL_ALL };
|
|
643
|
+
const literal = `${normalizedArgumentName}="${TARGET_COUNT_CANONICAL_ALL}"`;
|
|
644
|
+
const base = {
|
|
645
|
+
argument_name: normalizedArgumentName,
|
|
646
|
+
answer_format: `${normalizedArgumentName} = 正整数 | "${TARGET_COUNT_CANONICAL_ALL}"`,
|
|
647
|
+
canonical_unlimited_value: TARGET_COUNT_CANONICAL_ALL,
|
|
648
|
+
recommended_value: TARGET_COUNT_CANONICAL_ALL,
|
|
649
|
+
recommended_argument_patch: clonedRecommendedPatch,
|
|
650
|
+
accepted_examples: TARGET_COUNT_ACCEPTED_EXAMPLES.slice()
|
|
651
|
+
};
|
|
652
|
+
if (!includeOptions) return base;
|
|
653
|
+
return {
|
|
654
|
+
...base,
|
|
655
|
+
options: [
|
|
656
|
+
{
|
|
657
|
+
label: `扫到底(必须传 ${literal},推荐)`,
|
|
658
|
+
value: TARGET_COUNT_CANONICAL_ALL,
|
|
659
|
+
canonical_value: TARGET_COUNT_CANONICAL_ALL,
|
|
660
|
+
argument_patch: cloneForDiagnostics(clonedRecommendedPatch)
|
|
661
|
+
},
|
|
662
|
+
{
|
|
663
|
+
label: `不限(等价于 ${literal})`,
|
|
664
|
+
value: "unlimited",
|
|
665
|
+
canonical_value: TARGET_COUNT_CANONICAL_ALL,
|
|
666
|
+
argument_patch: cloneForDiagnostics(clonedRecommendedPatch)
|
|
667
|
+
},
|
|
668
|
+
{
|
|
669
|
+
label: `全部候选人(等价于 ${literal})`,
|
|
670
|
+
value: "全部候选人",
|
|
671
|
+
canonical_value: TARGET_COUNT_CANONICAL_ALL,
|
|
672
|
+
argument_patch: cloneForDiagnostics(clonedRecommendedPatch)
|
|
673
|
+
},
|
|
674
|
+
{
|
|
675
|
+
label: `所有候选人(等价于 ${literal})`,
|
|
676
|
+
value: "所有候选人",
|
|
677
|
+
canonical_value: TARGET_COUNT_CANONICAL_ALL,
|
|
678
|
+
argument_patch: cloneForDiagnostics(clonedRecommendedPatch)
|
|
679
|
+
}
|
|
680
|
+
]
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
export function normalizeTargetCountInput(value) {
|
|
685
|
+
if (value === undefined || value === null) {
|
|
686
|
+
return {
|
|
687
|
+
provided: false,
|
|
688
|
+
targetCount: null,
|
|
689
|
+
cliArg: null,
|
|
690
|
+
publicValue: null,
|
|
691
|
+
rawValue: value,
|
|
692
|
+
parseError: null
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
const unwrapped = getWrappedTargetCountValue(value);
|
|
696
|
+
if (unwrapped !== value) {
|
|
697
|
+
return normalizeTargetCountInput(unwrapped);
|
|
698
|
+
}
|
|
699
|
+
const raw = normalizeText(unwrapped);
|
|
700
|
+
if (!raw) {
|
|
701
|
+
return {
|
|
702
|
+
provided: false,
|
|
703
|
+
targetCount: null,
|
|
704
|
+
cliArg: null,
|
|
705
|
+
publicValue: null,
|
|
706
|
+
rawValue: value,
|
|
707
|
+
parseError: null
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
if (isUnlimitedTargetCountToken(raw)) {
|
|
711
|
+
return {
|
|
712
|
+
provided: true,
|
|
713
|
+
targetCount: null,
|
|
714
|
+
cliArg: "-1",
|
|
715
|
+
publicValue: TARGET_COUNT_CANONICAL_ALL,
|
|
716
|
+
rawValue: cloneForDiagnostics(value),
|
|
717
|
+
parseError: null
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
const parsed = Number.parseInt(String(raw), 10);
|
|
721
|
+
if (Number.isFinite(parsed) && parsed === -1) {
|
|
722
|
+
return {
|
|
723
|
+
provided: true,
|
|
724
|
+
targetCount: null,
|
|
725
|
+
cliArg: "-1",
|
|
726
|
+
publicValue: TARGET_COUNT_CANONICAL_ALL,
|
|
727
|
+
rawValue: cloneForDiagnostics(value),
|
|
728
|
+
parseError: null
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
if (Number.isFinite(parsed) && parsed > 0) {
|
|
732
|
+
return {
|
|
733
|
+
provided: true,
|
|
734
|
+
targetCount: parsed,
|
|
735
|
+
cliArg: String(parsed),
|
|
736
|
+
publicValue: parsed,
|
|
737
|
+
rawValue: cloneForDiagnostics(value),
|
|
738
|
+
parseError: null
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
return {
|
|
742
|
+
provided: false,
|
|
743
|
+
targetCount: null,
|
|
744
|
+
cliArg: null,
|
|
745
|
+
publicValue: null,
|
|
746
|
+
rawValue: cloneForDiagnostics(value),
|
|
747
|
+
parseError: "target_count must be a positive integer, -1, or one of: all, unlimited, 全部, 不限, 扫到底, 全量, 全部候选人, 所有候选人"
|
|
748
|
+
};
|
|
749
|
+
}
|