@suifei/dsh-ai-team 0.4.145 → 0.4.147
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/CHANGELOG.md +11 -0
- package/LICENSE +21 -21
- package/README.md +31 -2
- package/client.js +551 -49
- package/cordis.patch.yml +31 -31
- package/icon.svg +12 -12
- package/index.js +105 -25
- package/lib/domain/ids.js +26 -26
- package/lib/domain/inbox.js +93 -93
- package/lib/domain/member-config.js +168 -168
- package/lib/domain/policy.js +8 -1
- package/lib/domain/task.js +2 -0
- package/lib/domain/team-blueprint.js +240 -0
- package/lib/host/decision-report.js +72 -72
- package/lib/host/default-roster.js +18 -0
- package/lib/host/default-workspace.js +69 -69
- package/lib/host/fault-adapter.js +50 -50
- package/lib/host/member-tools.js +6 -1
- package/lib/host/people-view.js +9 -2
- package/lib/host/permission-guard.js +61 -61
- package/lib/host/project-registry.js +104 -104
- package/lib/host/project-runtime.js +2 -2
- package/lib/host/risk-view.js +99 -99
- package/lib/host/service.js +195 -16
- package/lib/host/views.js +42 -1
- package/lib/host/waker.js +38 -8
- package/lib/host/weekly-view.js +86 -86
- package/lib/host/workspace-path.js +94 -94
- package/lib/ledger/checkpoint.js +415 -415
- package/lib/ledger/events.js +398 -398
- package/lib/ledger/fold.js +23 -0
- package/lib/ledger/namespace.js +124 -124
- package/lib/ledger/tools.js +118 -118
- package/lib/ledger/writer.js +1266 -1266
- package/lib/runtime/error-chain.js +31 -31
- package/lib/runtime/shell-guard.js +102 -102
- package/lib/runtime/skill-catalog.js +41 -41
- package/lib/runtime/skill-policy.js +12 -12
- package/lib/runtime/stop-guard.js +17 -2
- package/lib/skillopt/adopt-gate.js +108 -108
- package/lib/skillopt/gate-wiring.js +146 -146
- package/lib/skillopt/jobs.js +135 -135
- package/lib/skillopt/proposal-store.js +33 -33
- package/lib/skillopt/review-runner.js +107 -107
- package/lib/skillopt/rubric.js +189 -189
- package/lib/skillopt/subagent-text.js +101 -101
- package/lib/skillopt/tool-access.js +56 -56
- package/locale/en.json +6 -6
- package/locale/zh.json +6 -6
- package/package.json +1 -1
package/lib/host/weekly-view.js
CHANGED
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 项目周报投影(R-11 / 视图组合纪律):同一份账本投影的窗口聚合,产出
|
|
3
|
-
* 正向/负向两种解读共用的数据结构——正向 = 完成了什么、一次通过多少;
|
|
4
|
-
* 负向 = 哪些返工了、Human 介入了几次、多少任务仍受阻。纯计数投影,
|
|
5
|
-
* 无新事件、无新数据结构。
|
|
6
|
-
*
|
|
7
|
-
* 口径(全部来自既有投影字段):
|
|
8
|
-
* - completed:status=done 且 updatedAt 在窗口内(done 的 updatedAt 即验收时间);
|
|
9
|
-
* - reworked:reviewRound ≥ 2(经历过 task/changes-requested)且窗口内有动静;
|
|
10
|
-
* - humanTouches:Thread 中 authorId === humanId 的条目数(窗口内 at)+
|
|
11
|
-
* 已答复决策数(requiresDecision 且 state==='done',ackedAt 窗口内);
|
|
12
|
-
* - humanTasks:ownerId === humanId 的活跃任务数("交给人"的负担面)。
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
export function weeklyView(state, { now = Date.now(), weeks = 1 } = {}) {
|
|
16
|
-
const windowStart = now - weeks * 7 * 24 * 60 * 60 * 1000;
|
|
17
|
-
const humanId = state.humanMemberId
|
|
18
|
-
?? Object.values(state.members ?? {}).find((member) => member.kind === 'human')?.id
|
|
19
|
-
?? null;
|
|
20
|
-
|
|
21
|
-
const completed = [];
|
|
22
|
-
const reworked = [];
|
|
23
|
-
let createdCount = 0;
|
|
24
|
-
for (const task of Object.values(state.tasks ?? {})) {
|
|
25
|
-
if (task.tombstone === true) continue;
|
|
26
|
-
const touchedAt = Math.max(task.updatedAt ?? 0, task.createdAt ?? 0);
|
|
27
|
-
if (task.createdAt >= windowStart) createdCount += 1;
|
|
28
|
-
if (task.status === 'done' && (task.updatedAt ?? 0) >= windowStart) {
|
|
29
|
-
completed.push({
|
|
30
|
-
taskId: task.id,
|
|
31
|
-
number: task.number ?? null,
|
|
32
|
-
title: task.title ?? '',
|
|
33
|
-
ownerName: state.members?.[task.ownerId]?.name ?? task.ownerId ?? null,
|
|
34
|
-
reviewRound: task.reviewRound ?? 1,
|
|
35
|
-
updatedAt: task.updatedAt ?? null,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
if ((task.reviewRound ?? 0) >= 2 && touchedAt >= windowStart) {
|
|
39
|
-
reworked.push({
|
|
40
|
-
taskId: task.id,
|
|
41
|
-
number: task.number ?? null,
|
|
42
|
-
title: task.title ?? '',
|
|
43
|
-
reviewRound: task.reviewRound,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
let humanThreadMessages = 0;
|
|
49
|
-
for (const thread of Object.values(state.threads ?? {})) {
|
|
50
|
-
for (const entry of thread.entries ?? []) {
|
|
51
|
-
if ((entry.at ?? 0) >= windowStart && entry.authorId === humanId) humanThreadMessages += 1;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
let decisionsAnswered = 0;
|
|
55
|
-
for (const item of Object.values(state.inbox ?? {})) {
|
|
56
|
-
if (item.type !== 'decision_required' || item.requiresDecision !== true) continue;
|
|
57
|
-
if (item.state !== 'done' && item.state !== 'resolved') continue;
|
|
58
|
-
// PMO 自动答复(decision.auto === true)不是 Human 介入:周报的
|
|
59
|
-
// 「零 Human」口径若把自动决策算进去,就永远看不到真实的人工干预。
|
|
60
|
-
if (item.decision?.auto === true) continue;
|
|
61
|
-
if ((item.ackedAt ?? 0) >= windowStart) decisionsAnswered += 1;
|
|
62
|
-
}
|
|
63
|
-
const humanTasks = humanId === null ? 0
|
|
64
|
-
: Object.values(state.tasks ?? {}).filter((task) =>
|
|
65
|
-
task.tombstone !== true && ['pending', 'in_progress', 'pending_acceptance'].includes(task.status)
|
|
66
|
-
&& (task.ownerId === humanId || task.assigneeId === humanId)).length;
|
|
67
|
-
|
|
68
|
-
const completedTitles = completed.map((row) => '#' + (row.number ?? row.taskId) + ' ' + row.title);
|
|
69
|
-
return {
|
|
70
|
-
windowStart,
|
|
71
|
-
generatedAt: now,
|
|
72
|
-
weeks,
|
|
73
|
-
completedCount: completed.length,
|
|
74
|
-
createdCount,
|
|
75
|
-
reworkedCount: reworked.length,
|
|
76
|
-
humanThreadMessages,
|
|
77
|
-
decisionsAnswered,
|
|
78
|
-
humanTasks,
|
|
79
|
-
completed,
|
|
80
|
-
reworked,
|
|
81
|
-
// 正向解读的数据面:完成的清单与「零 Human 发言」的直通任务。
|
|
82
|
-
positive: { completedTitles, humanThreadMessages, decisionsAnswered },
|
|
83
|
-
// 负向解读的数据面:返工清单(reviewRound>=2)与仍然阻塞/待人的任务。
|
|
84
|
-
negative: { reworkedTitles: reworked.map((row) => '#' + (row.number ?? row.taskId) + ' ' + row.title), humanTasks },
|
|
85
|
-
};
|
|
86
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 项目周报投影(R-11 / 视图组合纪律):同一份账本投影的窗口聚合,产出
|
|
3
|
+
* 正向/负向两种解读共用的数据结构——正向 = 完成了什么、一次通过多少;
|
|
4
|
+
* 负向 = 哪些返工了、Human 介入了几次、多少任务仍受阻。纯计数投影,
|
|
5
|
+
* 无新事件、无新数据结构。
|
|
6
|
+
*
|
|
7
|
+
* 口径(全部来自既有投影字段):
|
|
8
|
+
* - completed:status=done 且 updatedAt 在窗口内(done 的 updatedAt 即验收时间);
|
|
9
|
+
* - reworked:reviewRound ≥ 2(经历过 task/changes-requested)且窗口内有动静;
|
|
10
|
+
* - humanTouches:Thread 中 authorId === humanId 的条目数(窗口内 at)+
|
|
11
|
+
* 已答复决策数(requiresDecision 且 state==='done',ackedAt 窗口内);
|
|
12
|
+
* - humanTasks:ownerId === humanId 的活跃任务数("交给人"的负担面)。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export function weeklyView(state, { now = Date.now(), weeks = 1 } = {}) {
|
|
16
|
+
const windowStart = now - weeks * 7 * 24 * 60 * 60 * 1000;
|
|
17
|
+
const humanId = state.humanMemberId
|
|
18
|
+
?? Object.values(state.members ?? {}).find((member) => member.kind === 'human')?.id
|
|
19
|
+
?? null;
|
|
20
|
+
|
|
21
|
+
const completed = [];
|
|
22
|
+
const reworked = [];
|
|
23
|
+
let createdCount = 0;
|
|
24
|
+
for (const task of Object.values(state.tasks ?? {})) {
|
|
25
|
+
if (task.tombstone === true) continue;
|
|
26
|
+
const touchedAt = Math.max(task.updatedAt ?? 0, task.createdAt ?? 0);
|
|
27
|
+
if (task.createdAt >= windowStart) createdCount += 1;
|
|
28
|
+
if (task.status === 'done' && (task.updatedAt ?? 0) >= windowStart) {
|
|
29
|
+
completed.push({
|
|
30
|
+
taskId: task.id,
|
|
31
|
+
number: task.number ?? null,
|
|
32
|
+
title: task.title ?? '',
|
|
33
|
+
ownerName: state.members?.[task.ownerId]?.name ?? task.ownerId ?? null,
|
|
34
|
+
reviewRound: task.reviewRound ?? 1,
|
|
35
|
+
updatedAt: task.updatedAt ?? null,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if ((task.reviewRound ?? 0) >= 2 && touchedAt >= windowStart) {
|
|
39
|
+
reworked.push({
|
|
40
|
+
taskId: task.id,
|
|
41
|
+
number: task.number ?? null,
|
|
42
|
+
title: task.title ?? '',
|
|
43
|
+
reviewRound: task.reviewRound,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let humanThreadMessages = 0;
|
|
49
|
+
for (const thread of Object.values(state.threads ?? {})) {
|
|
50
|
+
for (const entry of thread.entries ?? []) {
|
|
51
|
+
if ((entry.at ?? 0) >= windowStart && entry.authorId === humanId) humanThreadMessages += 1;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
let decisionsAnswered = 0;
|
|
55
|
+
for (const item of Object.values(state.inbox ?? {})) {
|
|
56
|
+
if (item.type !== 'decision_required' || item.requiresDecision !== true) continue;
|
|
57
|
+
if (item.state !== 'done' && item.state !== 'resolved') continue;
|
|
58
|
+
// PMO 自动答复(decision.auto === true)不是 Human 介入:周报的
|
|
59
|
+
// 「零 Human」口径若把自动决策算进去,就永远看不到真实的人工干预。
|
|
60
|
+
if (item.decision?.auto === true) continue;
|
|
61
|
+
if ((item.ackedAt ?? 0) >= windowStart) decisionsAnswered += 1;
|
|
62
|
+
}
|
|
63
|
+
const humanTasks = humanId === null ? 0
|
|
64
|
+
: Object.values(state.tasks ?? {}).filter((task) =>
|
|
65
|
+
task.tombstone !== true && ['pending', 'in_progress', 'pending_acceptance'].includes(task.status)
|
|
66
|
+
&& (task.ownerId === humanId || task.assigneeId === humanId)).length;
|
|
67
|
+
|
|
68
|
+
const completedTitles = completed.map((row) => '#' + (row.number ?? row.taskId) + ' ' + row.title);
|
|
69
|
+
return {
|
|
70
|
+
windowStart,
|
|
71
|
+
generatedAt: now,
|
|
72
|
+
weeks,
|
|
73
|
+
completedCount: completed.length,
|
|
74
|
+
createdCount,
|
|
75
|
+
reworkedCount: reworked.length,
|
|
76
|
+
humanThreadMessages,
|
|
77
|
+
decisionsAnswered,
|
|
78
|
+
humanTasks,
|
|
79
|
+
completed,
|
|
80
|
+
reworked,
|
|
81
|
+
// 正向解读的数据面:完成的清单与「零 Human 发言」的直通任务。
|
|
82
|
+
positive: { completedTitles, humanThreadMessages, decisionsAnswered },
|
|
83
|
+
// 负向解读的数据面:返工清单(reviewRound>=2)与仍然阻塞/待人的任务。
|
|
84
|
+
negative: { reworkedTitles: reworked.map((row) => '#' + (row.number ?? row.taskId) + ' ' + row.title), humanTasks },
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 工作目录的**平台形态**校验。
|
|
3
|
-
*
|
|
4
|
-
* 实机事故:DSH web 在 WSL(Linux)里启动,用户在目录框里填了 `D:\works\localservice`
|
|
5
|
-
* ——Windows 形态。POSIX 上这只是一串**带反斜杠的文件名**(相对路径),既不是那个盘,
|
|
6
|
-
* 也不会给出有用的报错;成员会话随后在错误目录里干活。
|
|
7
|
-
*
|
|
8
|
-
* 这里只判断「路径形态与宿主平台是否匹配」,存在性仍由调用方的 statSync 负责。
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { readFileSync } from 'node:fs';
|
|
12
|
-
|
|
13
|
-
const WINDOWS_DRIVE = /^[A-Za-z]:[\\/]/;
|
|
14
|
-
const WINDOWS_DRIVE_BARE = /^[A-Za-z]:$/;
|
|
15
|
-
const UNC = /^\\\\[^\\]/;
|
|
16
|
-
const BACKSLASH = /\\/;
|
|
17
|
-
|
|
18
|
-
/** 把 `D:\works\a` 这类 Windows 路径转换成 WSL 的 `/mnt/d/works/a`。 */
|
|
19
|
-
export function windowsToWsl(raw) {
|
|
20
|
-
const match = /^([A-Za-z]):[\\/]*(.*)$/.exec(String(raw ?? ''));
|
|
21
|
-
if (match === null) return null;
|
|
22
|
-
const drive = match[1].toLowerCase();
|
|
23
|
-
const rest = match[2].replace(/\\/g, '/').replace(/\/+/g, '/').replace(/\/$/, '');
|
|
24
|
-
return rest === '' ? `/mnt/${drive}` : `/mnt/${drive}/${rest}`;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** 宿主是否运行在 WSL 里(`/proc/version` 含 microsoft)。读不到就按普通 Linux 处理。 */
|
|
28
|
-
export function isWsl() {
|
|
29
|
-
if (process.platform !== 'linux') return false;
|
|
30
|
-
try {
|
|
31
|
-
return /microsoft/i.test(readFileSync('/proc/version', 'utf8'));
|
|
32
|
-
} catch {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** 'win32' | 'wsl' | 'posix' */
|
|
38
|
-
export function hostPlatform(platform = process.platform, wsl = undefined) {
|
|
39
|
-
if (platform === 'win32') return 'win32';
|
|
40
|
-
if (platform === 'linux' && (wsl ?? isWsl()) === true) return 'wsl';
|
|
41
|
-
return 'posix';
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* 校验路径形态是否与宿主平台兼容。
|
|
46
|
-
* @returns {{ ok: true } | { ok: false, code: string, message: string, suggestion?: string }}
|
|
47
|
-
*/
|
|
48
|
-
export function checkWorkspacePath(raw, options = {}) {
|
|
49
|
-
const value = typeof raw === 'string' ? raw.trim() : '';
|
|
50
|
-
if (value === '') return { ok: false, code: 'E_EMPTY', message: '工作目录不能为空' };
|
|
51
|
-
const platform = options.platform ?? process.platform;
|
|
52
|
-
const host = hostPlatform(platform, options.wsl);
|
|
53
|
-
if (host === 'win32') {
|
|
54
|
-
// Windows 上 POSIX 绝对路径(`/mnt/d/x`)不是有效盘符路径;Node 会把它解释成
|
|
55
|
-
// 当前盘根目录,容易落进意料之外的位置。直接给出明确提示。
|
|
56
|
-
if (value.startsWith('/') && !WINDOWS_DRIVE.test(value)) {
|
|
57
|
-
return {
|
|
58
|
-
ok: false,
|
|
59
|
-
code: 'E_PLATFORM_PATH',
|
|
60
|
-
message: `工作目录「${value}」是 POSIX 路径,而当前宿主是 Windows;请改用盘符路径,例如 D:/works/my-project`,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
return { ok: true };
|
|
64
|
-
}
|
|
65
|
-
// POSIX(含 WSL):Windows 形态一律拒绝,并给出可用的替代写法。
|
|
66
|
-
if (UNC.test(value)) {
|
|
67
|
-
return {
|
|
68
|
-
ok: false,
|
|
69
|
-
code: 'E_PLATFORM_PATH',
|
|
70
|
-
message: `工作目录「${value}」是 Windows UNC 路径(\\\\wsl.localhost\\…),Linux 宿主无法使用;请改用挂载点路径,例如 /home/<user>/works`,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
if (WINDOWS_DRIVE.test(value) || WINDOWS_DRIVE_BARE.test(value) || (BACKSLASH.test(value) && !value.startsWith('/'))) {
|
|
74
|
-
const suggestion = windowsToWsl(value);
|
|
75
|
-
const hint = host === 'wsl' && suggestion !== null
|
|
76
|
-
? `请改用 WSL 内的挂载路径:${suggestion}`
|
|
77
|
-
: '请改用 POSIX 路径,例如 /home/<user>/works/my-project';
|
|
78
|
-
return {
|
|
79
|
-
ok: false,
|
|
80
|
-
code: 'E_PLATFORM_PATH',
|
|
81
|
-
message: `工作目录「${value}」是 Windows 路径,而当前宿主是 Linux;${hint}`,
|
|
82
|
-
...(suggestion === null ? {} : { suggestion }),
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
return { ok: true };
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/** 目录输入框的示例路径(与宿主平台一致)。 */
|
|
89
|
-
export function workspaceExample(platform = process.platform, options = {}) {
|
|
90
|
-
const host = hostPlatform(platform, options.wsl);
|
|
91
|
-
if (host === 'win32') return 'D:/works/my-project';
|
|
92
|
-
if (host === 'wsl') return '/mnt/d/works/my-project';
|
|
93
|
-
return '/home/user/works/my-project';
|
|
94
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 工作目录的**平台形态**校验。
|
|
3
|
+
*
|
|
4
|
+
* 实机事故:DSH web 在 WSL(Linux)里启动,用户在目录框里填了 `D:\works\localservice`
|
|
5
|
+
* ——Windows 形态。POSIX 上这只是一串**带反斜杠的文件名**(相对路径),既不是那个盘,
|
|
6
|
+
* 也不会给出有用的报错;成员会话随后在错误目录里干活。
|
|
7
|
+
*
|
|
8
|
+
* 这里只判断「路径形态与宿主平台是否匹配」,存在性仍由调用方的 statSync 负责。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { readFileSync } from 'node:fs';
|
|
12
|
+
|
|
13
|
+
const WINDOWS_DRIVE = /^[A-Za-z]:[\\/]/;
|
|
14
|
+
const WINDOWS_DRIVE_BARE = /^[A-Za-z]:$/;
|
|
15
|
+
const UNC = /^\\\\[^\\]/;
|
|
16
|
+
const BACKSLASH = /\\/;
|
|
17
|
+
|
|
18
|
+
/** 把 `D:\works\a` 这类 Windows 路径转换成 WSL 的 `/mnt/d/works/a`。 */
|
|
19
|
+
export function windowsToWsl(raw) {
|
|
20
|
+
const match = /^([A-Za-z]):[\\/]*(.*)$/.exec(String(raw ?? ''));
|
|
21
|
+
if (match === null) return null;
|
|
22
|
+
const drive = match[1].toLowerCase();
|
|
23
|
+
const rest = match[2].replace(/\\/g, '/').replace(/\/+/g, '/').replace(/\/$/, '');
|
|
24
|
+
return rest === '' ? `/mnt/${drive}` : `/mnt/${drive}/${rest}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** 宿主是否运行在 WSL 里(`/proc/version` 含 microsoft)。读不到就按普通 Linux 处理。 */
|
|
28
|
+
export function isWsl() {
|
|
29
|
+
if (process.platform !== 'linux') return false;
|
|
30
|
+
try {
|
|
31
|
+
return /microsoft/i.test(readFileSync('/proc/version', 'utf8'));
|
|
32
|
+
} catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** 'win32' | 'wsl' | 'posix' */
|
|
38
|
+
export function hostPlatform(platform = process.platform, wsl = undefined) {
|
|
39
|
+
if (platform === 'win32') return 'win32';
|
|
40
|
+
if (platform === 'linux' && (wsl ?? isWsl()) === true) return 'wsl';
|
|
41
|
+
return 'posix';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 校验路径形态是否与宿主平台兼容。
|
|
46
|
+
* @returns {{ ok: true } | { ok: false, code: string, message: string, suggestion?: string }}
|
|
47
|
+
*/
|
|
48
|
+
export function checkWorkspacePath(raw, options = {}) {
|
|
49
|
+
const value = typeof raw === 'string' ? raw.trim() : '';
|
|
50
|
+
if (value === '') return { ok: false, code: 'E_EMPTY', message: '工作目录不能为空' };
|
|
51
|
+
const platform = options.platform ?? process.platform;
|
|
52
|
+
const host = hostPlatform(platform, options.wsl);
|
|
53
|
+
if (host === 'win32') {
|
|
54
|
+
// Windows 上 POSIX 绝对路径(`/mnt/d/x`)不是有效盘符路径;Node 会把它解释成
|
|
55
|
+
// 当前盘根目录,容易落进意料之外的位置。直接给出明确提示。
|
|
56
|
+
if (value.startsWith('/') && !WINDOWS_DRIVE.test(value)) {
|
|
57
|
+
return {
|
|
58
|
+
ok: false,
|
|
59
|
+
code: 'E_PLATFORM_PATH',
|
|
60
|
+
message: `工作目录「${value}」是 POSIX 路径,而当前宿主是 Windows;请改用盘符路径,例如 D:/works/my-project`,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return { ok: true };
|
|
64
|
+
}
|
|
65
|
+
// POSIX(含 WSL):Windows 形态一律拒绝,并给出可用的替代写法。
|
|
66
|
+
if (UNC.test(value)) {
|
|
67
|
+
return {
|
|
68
|
+
ok: false,
|
|
69
|
+
code: 'E_PLATFORM_PATH',
|
|
70
|
+
message: `工作目录「${value}」是 Windows UNC 路径(\\\\wsl.localhost\\…),Linux 宿主无法使用;请改用挂载点路径,例如 /home/<user>/works`,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (WINDOWS_DRIVE.test(value) || WINDOWS_DRIVE_BARE.test(value) || (BACKSLASH.test(value) && !value.startsWith('/'))) {
|
|
74
|
+
const suggestion = windowsToWsl(value);
|
|
75
|
+
const hint = host === 'wsl' && suggestion !== null
|
|
76
|
+
? `请改用 WSL 内的挂载路径:${suggestion}`
|
|
77
|
+
: '请改用 POSIX 路径,例如 /home/<user>/works/my-project';
|
|
78
|
+
return {
|
|
79
|
+
ok: false,
|
|
80
|
+
code: 'E_PLATFORM_PATH',
|
|
81
|
+
message: `工作目录「${value}」是 Windows 路径,而当前宿主是 Linux;${hint}`,
|
|
82
|
+
...(suggestion === null ? {} : { suggestion }),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return { ok: true };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** 目录输入框的示例路径(与宿主平台一致)。 */
|
|
89
|
+
export function workspaceExample(platform = process.platform, options = {}) {
|
|
90
|
+
const host = hostPlatform(platform, options.wsl);
|
|
91
|
+
if (host === 'win32') return 'D:/works/my-project';
|
|
92
|
+
if (host === 'wsl') return '/mnt/d/works/my-project';
|
|
93
|
+
return '/home/user/works/my-project';
|
|
94
|
+
}
|