hunter-mate 0.1.5 → 0.1.6
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.
|
@@ -4,5 +4,10 @@ export interface ConfigOptions {
|
|
|
4
4
|
watchFolder?: string;
|
|
5
5
|
lang?: string;
|
|
6
6
|
}
|
|
7
|
-
export declare function runConfig(options: ConfigOptions):
|
|
7
|
+
export declare function runConfig(options: ConfigOptions): {
|
|
8
|
+
serverUrl: string;
|
|
9
|
+
saasUrl: string;
|
|
10
|
+
lang: string;
|
|
11
|
+
watchFolder?: string;
|
|
12
|
+
};
|
|
8
13
|
export declare const configCommand: Command;
|
package/dist/commands/doctor.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Command } from 'commander';
|
|
|
2
2
|
import axios from 'axios';
|
|
3
3
|
import * as fs from 'fs';
|
|
4
4
|
import * as path from 'path';
|
|
5
|
-
import { loadConfig } from '../config.js';
|
|
5
|
+
import { loadConfig, saveConfig, normalizeConfig, CONFIG_FILE } from '../config.js';
|
|
6
6
|
import { runInit } from './init.js';
|
|
7
7
|
import { runStart } from './server.js';
|
|
8
8
|
import { runInstall } from './install.js';
|
|
@@ -84,6 +84,31 @@ export async function runDoctor(opts) {
|
|
|
84
84
|
}
|
|
85
85
|
if (!initResult)
|
|
86
86
|
initResult = runInit();
|
|
87
|
+
// ── 1.5) 配置 URL 兼容性(部署形态收敛自检:子路径 → 根路径等) ──
|
|
88
|
+
try {
|
|
89
|
+
if (fs.existsSync(CONFIG_FILE())) {
|
|
90
|
+
const rawCfg = JSON.parse(fs.readFileSync(CONFIG_FILE(), 'utf-8'));
|
|
91
|
+
const { changed, migrated } = normalizeConfig(rawCfg);
|
|
92
|
+
if (!changed) {
|
|
93
|
+
checks.push({ key: 'config_url_schema', status: 'ok', detail: '配置 URL 已为最新规范形态(无已知废弃路径前缀)' });
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
const detail = migrated.map((m) => `${m.key}: ${m.from} → ${m.to}`).join('; ');
|
|
97
|
+
if (autoHeal) {
|
|
98
|
+
saveConfig(rawCfg); // 写入规范化结果(内部也会 normalize)
|
|
99
|
+
checks.push({ key: 'config_url_schema', status: 'ok', detail: `检测到已废弃路径并自动修复: ${detail}` });
|
|
100
|
+
healed.push('normalize_config_urls');
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
checks.push({ key: 'config_url_schema', status: 'warn', detail: `配置含已废弃路径前缀: ${detail}` });
|
|
104
|
+
hints.push('运行 hunter-mate doctor 自动修复');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (e) {
|
|
110
|
+
checks.push({ key: 'config_url_schema', status: 'skip', detail: `跳过(读取配置失败): ${e.message}` });
|
|
111
|
+
}
|
|
87
112
|
// ── 2) 扩展安装检测 + 自动安装 ──
|
|
88
113
|
const manifestPath = path.join(initResult.extensionDir, 'manifest.json');
|
|
89
114
|
let extInstalled = fs.existsSync(manifestPath);
|
package/dist/config.d.ts
CHANGED
|
@@ -6,6 +6,41 @@ export interface HunterMateConfig {
|
|
|
6
6
|
lang: string;
|
|
7
7
|
watchFolder?: string;
|
|
8
8
|
}
|
|
9
|
+
export declare const CONFIG_DIR: () => string;
|
|
10
|
+
export declare const CONFIG_FILE: () => string;
|
|
11
|
+
/**
|
|
12
|
+
* 已知废弃的 URL 路径前缀(按部署形态演进顺序追加)。
|
|
13
|
+
* 每当 nginx / 服务端路径收敛(如子路径 → 根路径)时,把旧前缀加到这里,
|
|
14
|
+
* loadConfig() / saveConfig() 会自动剥离,doctor 会自检并给出 healed 记录。
|
|
15
|
+
* 匹配规则:字符串中任何一段形如 `{host}{prefix}` 都会被替换为 `{host}/`,
|
|
16
|
+
* 且自动处理尾斜杠(例如 https://host/llm-research/foo → https://host/foo)。
|
|
17
|
+
*/
|
|
18
|
+
export declare const DEPRECATED_URL_PATH_PREFIXES: string[];
|
|
19
|
+
/**
|
|
20
|
+
* 规范化 URL 字符串: 剥离所有已知废弃的子路径前缀。
|
|
21
|
+
* 例: normalizeUrlValue('https://dev-ops.hiredchina.com/llm-research/errors')
|
|
22
|
+
* → 'https://dev-ops.hiredchina.com/errors'
|
|
23
|
+
*/
|
|
24
|
+
export declare function normalizeUrlValue(value: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* 对 config 对象所有 string 字段应用 URL 规范化。
|
|
27
|
+
* 返回 { config, changed } 便于调用方决定是否持久化。
|
|
28
|
+
* 深度 1 层足够(配置文件是扁平 key-value)。
|
|
29
|
+
*/
|
|
30
|
+
export declare function normalizeConfig<T extends Record<string, any>>(raw: T): {
|
|
31
|
+
config: T;
|
|
32
|
+
changed: boolean;
|
|
33
|
+
migrated: Array<{
|
|
34
|
+
key: string;
|
|
35
|
+
from: string;
|
|
36
|
+
to: string;
|
|
37
|
+
}>;
|
|
38
|
+
};
|
|
9
39
|
export declare function ensureConfigDir(): void;
|
|
10
40
|
export declare function loadConfig(): HunterMateConfig;
|
|
11
|
-
export declare function saveConfig(config: Partial<HunterMateConfig>):
|
|
41
|
+
export declare function saveConfig(config: Partial<HunterMateConfig>): {
|
|
42
|
+
serverUrl: string;
|
|
43
|
+
saasUrl: string;
|
|
44
|
+
lang: string;
|
|
45
|
+
watchFolder?: string;
|
|
46
|
+
};
|
package/dist/config.js
CHANGED
|
@@ -2,13 +2,67 @@ import * as fs from 'fs';
|
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
import { createJsonConfigStore } from '@chromepilot/kit';
|
|
4
4
|
const HOME = () => process.env.HUNTER_MATE_HOME || process.env.HOME || process.env.USERPROFILE || '.';
|
|
5
|
-
const CONFIG_DIR = () => path.join(HOME(), '.hunter-mate');
|
|
6
|
-
const CONFIG_FILE = () => path.join(CONFIG_DIR(), 'config.json');
|
|
5
|
+
export const CONFIG_DIR = () => path.join(HOME(), '.hunter-mate');
|
|
6
|
+
export const CONFIG_FILE = () => path.join(CONFIG_DIR(), 'config.json');
|
|
7
|
+
/**
|
|
8
|
+
* 已知废弃的 URL 路径前缀(按部署形态演进顺序追加)。
|
|
9
|
+
* 每当 nginx / 服务端路径收敛(如子路径 → 根路径)时,把旧前缀加到这里,
|
|
10
|
+
* loadConfig() / saveConfig() 会自动剥离,doctor 会自检并给出 healed 记录。
|
|
11
|
+
* 匹配规则:字符串中任何一段形如 `{host}{prefix}` 都会被替换为 `{host}/`,
|
|
12
|
+
* 且自动处理尾斜杠(例如 https://host/llm-research/foo → https://host/foo)。
|
|
13
|
+
*/
|
|
14
|
+
export const DEPRECATED_URL_PATH_PREFIXES = [
|
|
15
|
+
'/llm-research', // 2026-08-21 dev-ops 从子路径部署收敛到根路径
|
|
16
|
+
];
|
|
17
|
+
/**
|
|
18
|
+
* 规范化 URL 字符串: 剥离所有已知废弃的子路径前缀。
|
|
19
|
+
* 例: normalizeUrlValue('https://dev-ops.hiredchina.com/llm-research/errors')
|
|
20
|
+
* → 'https://dev-ops.hiredchina.com/errors'
|
|
21
|
+
*/
|
|
22
|
+
export function normalizeUrlValue(value) {
|
|
23
|
+
if (typeof value !== 'string')
|
|
24
|
+
return value;
|
|
25
|
+
let out = value;
|
|
26
|
+
for (const prefix of DEPRECATED_URL_PATH_PREFIXES) {
|
|
27
|
+
// 匹配 host/<prefix> 形式,支持 <prefix>/... 和 <prefix> 结尾
|
|
28
|
+
// e.g. https://host/llm-research → https://host/
|
|
29
|
+
// https://host/llm-research/x → https://host/x
|
|
30
|
+
const re = new RegExp(`(${prefix})(/|$)`, 'g');
|
|
31
|
+
out = out.replace(re, '/$2');
|
|
32
|
+
}
|
|
33
|
+
// 合并多余的连续斜杠(上面的替换可能产生 "//")
|
|
34
|
+
// 协议里的 :// 不动,只处理 host 之后的部分
|
|
35
|
+
out = out.replace(/^(https?:\/\/)(.*)/, (_m, scheme, rest) => {
|
|
36
|
+
return scheme + rest.replace(/\/{2,}/g, '/');
|
|
37
|
+
});
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 对 config 对象所有 string 字段应用 URL 规范化。
|
|
42
|
+
* 返回 { config, changed } 便于调用方决定是否持久化。
|
|
43
|
+
* 深度 1 层足够(配置文件是扁平 key-value)。
|
|
44
|
+
*/
|
|
45
|
+
export function normalizeConfig(raw) {
|
|
46
|
+
const migrated = [];
|
|
47
|
+
const out = { ...raw };
|
|
48
|
+
for (const key of Object.keys(out)) {
|
|
49
|
+
const value = out[key];
|
|
50
|
+
// 覆盖类型定义之外的自定义字段(如用户手动添加的 apiBase 等)
|
|
51
|
+
if (typeof value === 'string' && (value.startsWith('http://') || value.startsWith('https://') || value.includes('/llm-research'))) {
|
|
52
|
+
const normalized = normalizeUrlValue(value);
|
|
53
|
+
if (normalized !== value) {
|
|
54
|
+
migrated.push({ key, from: value, to: normalized });
|
|
55
|
+
out[key] = normalized;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return { config: out, changed: migrated.length > 0, migrated };
|
|
60
|
+
}
|
|
7
61
|
const store = createJsonConfigStore({
|
|
8
62
|
configPath: CONFIG_FILE,
|
|
9
63
|
defaults: {
|
|
10
64
|
serverUrl: 'http://localhost:34570',
|
|
11
|
-
saasUrl: 'https://dev-ops.hiredchina.com
|
|
65
|
+
saasUrl: 'https://dev-ops.hiredchina.com',
|
|
12
66
|
lang: 'zh-CN',
|
|
13
67
|
},
|
|
14
68
|
});
|
|
@@ -18,8 +72,23 @@ export function ensureConfigDir() {
|
|
|
18
72
|
}
|
|
19
73
|
}
|
|
20
74
|
export function loadConfig() {
|
|
21
|
-
|
|
75
|
+
const raw = store.load();
|
|
76
|
+
const { config: normalized, changed } = normalizeConfig(raw);
|
|
77
|
+
if (changed) {
|
|
78
|
+
// 配置含有已废弃路径,自动静默迁移并保存,用户下次读取一定是规范形态。
|
|
79
|
+
try {
|
|
80
|
+
fs.writeFileSync(CONFIG_FILE(), JSON.stringify(normalized, null, 2));
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
/* read-only fs, ignore */
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return normalized;
|
|
22
87
|
}
|
|
23
88
|
export function saveConfig(config) {
|
|
24
|
-
|
|
89
|
+
const current = loadConfig(); // 已规范化(必要时已写回)
|
|
90
|
+
const { config: next } = normalizeConfig({ ...current, ...config });
|
|
91
|
+
ensureConfigDir();
|
|
92
|
+
fs.writeFileSync(CONFIG_FILE(), JSON.stringify(next, null, 2));
|
|
93
|
+
return next;
|
|
25
94
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hunter-mate",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "HiredChina 猎头 Agent 数据助手 CLI:人才库/客户/职位数据访问,浏览器录制解析简历,server/扩展一致性自愈",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"open": "^8.4.0",
|
|
32
32
|
"uuid": "^9.0.0",
|
|
33
33
|
"ws": "^8.21.3",
|
|
34
|
-
"@hunter-mate/shared": "0.1.
|
|
34
|
+
"@hunter-mate/shared": "0.1.5"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/better-sqlite3": "^7.6.0",
|