@suifei/dsh-ai-team 0.4.145 → 0.4.146
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 +5 -0
- package/LICENSE +21 -21
- package/README.md +19 -1
- package/client.js +118 -17
- package/cordis.patch.yml +31 -31
- package/icon.svg +12 -12
- package/index.js +7 -1
- package/lib/domain/ids.js +26 -26
- package/lib/domain/inbox.js +93 -93
- package/lib/domain/member-config.js +168 -168
- package/lib/host/decision-report.js +72 -72
- package/lib/host/default-workspace.js +69 -69
- package/lib/host/fault-adapter.js +50 -50
- 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/risk-view.js +99 -99
- 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/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/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
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Read the Human-decision table from a linked Markdown report.
|
|
5
|
-
*
|
|
6
|
-
* This is deliberately narrow: only a report containing a section titled
|
|
7
|
-
* `6.` / `六` with a table gets converted. The Inbox still points back to the
|
|
8
|
-
* source Thread; the table is exposed so Human does not have to open the report
|
|
9
|
-
* just to discover the questions.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
function stripMarkdown(value) {
|
|
13
|
-
return String(value ?? '')
|
|
14
|
-
.replace(/\*\*/g, '')
|
|
15
|
-
.replace(/`/g, '')
|
|
16
|
-
.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
|
|
17
|
-
.trim();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function findReportPath(text) {
|
|
21
|
-
if (typeof text !== 'string') return null;
|
|
22
|
-
// 三种写法都要认:反斜杠绝对路径、正斜杠绝对路径、以及带空格(含引号/代码
|
|
23
|
-
// 围栏)的路径。只匹配 `[A-Za-z]:\\...` 会让「E:/works/a b/report.md」这类
|
|
24
|
-
// 完全合法、且是本机常见输出的路径永远进不了 Inbox。
|
|
25
|
-
const patterns = [
|
|
26
|
-
/"[A-Za-z]:[\\/][^"<>|\r\n]+?\.md"/g,
|
|
27
|
-
/'[A-Za-z]:[\\/][^'<>|\r\n]+?\.md'/g,
|
|
28
|
-
/`[A-Za-z]:[\\/][^`<>|\r\n]+?\.md`/g,
|
|
29
|
-
/[A-Za-z]:[\\/][^\s"'<>|`]+?\.md\b/g,
|
|
30
|
-
];
|
|
31
|
-
// 命中多个时先看**哪个真的存在**:模型常先给示例路径、再给真实产物路径,文末
|
|
32
|
-
// 也可能附一段模板示例——单靠「取第一个/取最后一个」都会错一边。存在的路径
|
|
33
|
-
// 优先;都不存在时退回「最后一次提到」,那是模型的最终答复约定。
|
|
34
|
-
const hits = [];
|
|
35
|
-
for (const pattern of patterns) {
|
|
36
|
-
for (const match of text.matchAll(pattern)) {
|
|
37
|
-
hits.push({ index: match.index ?? 0, path: match[0].replace(/^["'`]|["'`]$/g, '') });
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if (hits.length === 0) return null;
|
|
41
|
-
hits.sort((a, b) => a.index - b.index);
|
|
42
|
-
const existing = hits.filter((hit) => {
|
|
43
|
-
try { return existsSync(hit.path); } catch { return false; }
|
|
44
|
-
});
|
|
45
|
-
return (existing.length > 0 ? existing[existing.length - 1] : hits[hits.length - 1]).path;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function parseDecisionQuestions(markdown) {
|
|
49
|
-
const lines = String(markdown ?? '').split(/\r?\n/);
|
|
50
|
-
const start = lines.findIndex((line) => /^##\s*(6|六)[.、\s]/.test(line) || /^##\s*(6|六)\s*$/.test(line));
|
|
51
|
-
if (start < 0) return [];
|
|
52
|
-
let end = lines.length;
|
|
53
|
-
for (let index = start + 1; index < lines.length; index += 1) {
|
|
54
|
-
if (/^##\s/.test(lines[index]) || /^---\s*$/.test(lines[index])) { end = index; break; }
|
|
55
|
-
}
|
|
56
|
-
const questions = [];
|
|
57
|
-
for (const line of lines.slice(start + 1, end)) {
|
|
58
|
-
if (!line.trim().startsWith('|')) continue;
|
|
59
|
-
const cells = line.split('|').slice(1, -1).map((cell) => cell.trim());
|
|
60
|
-
if (cells.length < 2) continue;
|
|
61
|
-
if (!/^\d+$/.test(stripMarkdown(cells[0]))) continue;
|
|
62
|
-
const text = stripMarkdown(cells[1]);
|
|
63
|
-
if (text === '') continue;
|
|
64
|
-
questions.push({
|
|
65
|
-
id: `q${questions.length + 1}`,
|
|
66
|
-
text,
|
|
67
|
-
...(cells[2] ? { recommendation: stripMarkdown(cells[2]) } : {}),
|
|
68
|
-
...(cells[3] ? { blocking: stripMarkdown(cells[3]) } : {}),
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
return questions;
|
|
72
|
-
}
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Read the Human-decision table from a linked Markdown report.
|
|
5
|
+
*
|
|
6
|
+
* This is deliberately narrow: only a report containing a section titled
|
|
7
|
+
* `6.` / `六` with a table gets converted. The Inbox still points back to the
|
|
8
|
+
* source Thread; the table is exposed so Human does not have to open the report
|
|
9
|
+
* just to discover the questions.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
function stripMarkdown(value) {
|
|
13
|
+
return String(value ?? '')
|
|
14
|
+
.replace(/\*\*/g, '')
|
|
15
|
+
.replace(/`/g, '')
|
|
16
|
+
.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
|
|
17
|
+
.trim();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function findReportPath(text) {
|
|
21
|
+
if (typeof text !== 'string') return null;
|
|
22
|
+
// 三种写法都要认:反斜杠绝对路径、正斜杠绝对路径、以及带空格(含引号/代码
|
|
23
|
+
// 围栏)的路径。只匹配 `[A-Za-z]:\\...` 会让「E:/works/a b/report.md」这类
|
|
24
|
+
// 完全合法、且是本机常见输出的路径永远进不了 Inbox。
|
|
25
|
+
const patterns = [
|
|
26
|
+
/"[A-Za-z]:[\\/][^"<>|\r\n]+?\.md"/g,
|
|
27
|
+
/'[A-Za-z]:[\\/][^'<>|\r\n]+?\.md'/g,
|
|
28
|
+
/`[A-Za-z]:[\\/][^`<>|\r\n]+?\.md`/g,
|
|
29
|
+
/[A-Za-z]:[\\/][^\s"'<>|`]+?\.md\b/g,
|
|
30
|
+
];
|
|
31
|
+
// 命中多个时先看**哪个真的存在**:模型常先给示例路径、再给真实产物路径,文末
|
|
32
|
+
// 也可能附一段模板示例——单靠「取第一个/取最后一个」都会错一边。存在的路径
|
|
33
|
+
// 优先;都不存在时退回「最后一次提到」,那是模型的最终答复约定。
|
|
34
|
+
const hits = [];
|
|
35
|
+
for (const pattern of patterns) {
|
|
36
|
+
for (const match of text.matchAll(pattern)) {
|
|
37
|
+
hits.push({ index: match.index ?? 0, path: match[0].replace(/^["'`]|["'`]$/g, '') });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (hits.length === 0) return null;
|
|
41
|
+
hits.sort((a, b) => a.index - b.index);
|
|
42
|
+
const existing = hits.filter((hit) => {
|
|
43
|
+
try { return existsSync(hit.path); } catch { return false; }
|
|
44
|
+
});
|
|
45
|
+
return (existing.length > 0 ? existing[existing.length - 1] : hits[hits.length - 1]).path;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function parseDecisionQuestions(markdown) {
|
|
49
|
+
const lines = String(markdown ?? '').split(/\r?\n/);
|
|
50
|
+
const start = lines.findIndex((line) => /^##\s*(6|六)[.、\s]/.test(line) || /^##\s*(6|六)\s*$/.test(line));
|
|
51
|
+
if (start < 0) return [];
|
|
52
|
+
let end = lines.length;
|
|
53
|
+
for (let index = start + 1; index < lines.length; index += 1) {
|
|
54
|
+
if (/^##\s/.test(lines[index]) || /^---\s*$/.test(lines[index])) { end = index; break; }
|
|
55
|
+
}
|
|
56
|
+
const questions = [];
|
|
57
|
+
for (const line of lines.slice(start + 1, end)) {
|
|
58
|
+
if (!line.trim().startsWith('|')) continue;
|
|
59
|
+
const cells = line.split('|').slice(1, -1).map((cell) => cell.trim());
|
|
60
|
+
if (cells.length < 2) continue;
|
|
61
|
+
if (!/^\d+$/.test(stripMarkdown(cells[0]))) continue;
|
|
62
|
+
const text = stripMarkdown(cells[1]);
|
|
63
|
+
if (text === '') continue;
|
|
64
|
+
questions.push({
|
|
65
|
+
id: `q${questions.length + 1}`,
|
|
66
|
+
text,
|
|
67
|
+
...(cells[2] ? { recommendation: stripMarkdown(cells[2]) } : {}),
|
|
68
|
+
...(cells[3] ? { blocking: stripMarkdown(cells[3]) } : {}),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return questions;
|
|
72
|
+
}
|
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 初装默认项目 / 新建项目对话框的「默认工作目录」解析。
|
|
3
|
-
*
|
|
4
|
-
* 规则(用户裁定):
|
|
5
|
-
* 1. 只有**没有指定**项目工作目录时才用默认目录;
|
|
6
|
-
* 2. 项目一旦切换过工作目录,就按项目自己的目录执行(本模块只负责默认值);
|
|
7
|
-
* 3. 默认值不能是插件自己的数据目录,否则成员会退化成「在账本目录里干活」;
|
|
8
|
-
* 4. 不能把用户主目录**根**当工作目录——必须是它下面的子目录(`~/works`);
|
|
9
|
-
* 5. 系统目录(Windows / Program Files)不当作团队工作目录——桌面启动器的
|
|
10
|
-
* cwd 可能就是程序目录。
|
|
11
|
-
*
|
|
12
|
-
* 跨平台:主目录一律来自调用方的 `homedir()`(Windows 是 `USERPROFILE`,
|
|
13
|
-
* Linux/macOS 是 `~`),本模块不自己判断平台,只用 `join` 拼路径。
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { statSync } from 'node:fs';
|
|
17
|
-
import { join, sep } from 'node:path';
|
|
18
|
-
|
|
19
|
-
const SYSTEM_DIR = /^[a-z]:[\\/](windows|program files|program files \(x86\))([\\/]|$)/i;
|
|
20
|
-
|
|
21
|
-
/** 用户主目录下的工作区子目录名(不给主目录根本身)。 */
|
|
22
|
-
export const WORKSPACE_SUBDIR = 'works';
|
|
23
|
-
|
|
24
|
-
const isDirectory = (value) => {
|
|
25
|
-
try { return statSync(value).isDirectory() === true; } catch { return false; }
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @param {{ configured?: string, cwd?: string, home?: string, dataDir?: string, excludeRoots?: string[] }} input
|
|
30
|
-
* @returns {string} 绝对目录;找不到任何可用目录时返回空串。
|
|
31
|
-
* 注意:返回的路径**可能尚不存在**——那是 `~/works` 建议值,调用方负责创建。
|
|
32
|
-
*/
|
|
33
|
-
export function resolveDefaultWorkspace({ configured = '', cwd = '', home = '', dataDir = '', excludeRoots = [], exists = undefined } = {}) {
|
|
34
|
-
const isDir = typeof exists === 'function' ? exists : isDirectory;
|
|
35
|
-
const explicit = typeof configured === 'string' ? configured.trim() : '';
|
|
36
|
-
const under = (value, root) => {
|
|
37
|
-
if (typeof root !== 'string' || root === '') return false;
|
|
38
|
-
const resolvedRoot = root.replace(/[\\/]+$/, '');
|
|
39
|
-
return value === resolvedRoot || value.startsWith(`${resolvedRoot}${sep}`) || value.startsWith(`${resolvedRoot}/`);
|
|
40
|
-
};
|
|
41
|
-
const excluded = (value) => {
|
|
42
|
-
// 插件数据目录永远不能当工作目录。
|
|
43
|
-
if (under(value, dataDir)) return true;
|
|
44
|
-
// `~/.dsh` 整棵树都不能当工作目录:桌面启动器的 cwd 就是 profile 目录
|
|
45
|
-
// (`…\.dsh\profiles\desktop`),把它当项目工作区是错的。
|
|
46
|
-
for (const root of excludeRoots) if (under(value, root)) return true;
|
|
47
|
-
return false;
|
|
48
|
-
};
|
|
49
|
-
// UNC 路径(`\\wsl.localhost\…`、`\\server\share`)不作自动建议:它通常来自启动器
|
|
50
|
-
// 的 cwd(从 WSL 目录里启动桌面端时就是这样),并不是用户的项目目录,而且成员
|
|
51
|
-
// 工具在 UNC 上读写既慢又容易出权限问题。显式配置不受此限。
|
|
52
|
-
const isUnc = (value) => /^\\\\[^\\]/.test(value);
|
|
53
|
-
for (const raw of [explicit, cwd]) {
|
|
54
|
-
if (typeof raw !== 'string' || raw === '') continue;
|
|
55
|
-
if (!isDir(raw)) continue;
|
|
56
|
-
if (excluded(raw)) continue;
|
|
57
|
-
// 显式配置的目录由用户负责;自动探测到的系统目录/UNC 一律跳过。
|
|
58
|
-
if (raw !== explicit && SYSTEM_DIR.test(raw)) continue;
|
|
59
|
-
if (raw !== explicit && isUnc(raw)) continue;
|
|
60
|
-
return raw;
|
|
61
|
-
}
|
|
62
|
-
// 兜底:用户主目录下的 `works` 子目录(跨平台由调用方传入 homedir)。
|
|
63
|
-
if (typeof home === 'string' && home !== '') {
|
|
64
|
-
const suggested = join(home, WORKSPACE_SUBDIR);
|
|
65
|
-
// 主目录本身被排除(例如 home 就落在 ~/.dsh 下)时不再兜底。
|
|
66
|
-
if (!excluded(suggested)) return suggested;
|
|
67
|
-
}
|
|
68
|
-
return '';
|
|
69
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 初装默认项目 / 新建项目对话框的「默认工作目录」解析。
|
|
3
|
+
*
|
|
4
|
+
* 规则(用户裁定):
|
|
5
|
+
* 1. 只有**没有指定**项目工作目录时才用默认目录;
|
|
6
|
+
* 2. 项目一旦切换过工作目录,就按项目自己的目录执行(本模块只负责默认值);
|
|
7
|
+
* 3. 默认值不能是插件自己的数据目录,否则成员会退化成「在账本目录里干活」;
|
|
8
|
+
* 4. 不能把用户主目录**根**当工作目录——必须是它下面的子目录(`~/works`);
|
|
9
|
+
* 5. 系统目录(Windows / Program Files)不当作团队工作目录——桌面启动器的
|
|
10
|
+
* cwd 可能就是程序目录。
|
|
11
|
+
*
|
|
12
|
+
* 跨平台:主目录一律来自调用方的 `homedir()`(Windows 是 `USERPROFILE`,
|
|
13
|
+
* Linux/macOS 是 `~`),本模块不自己判断平台,只用 `join` 拼路径。
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { statSync } from 'node:fs';
|
|
17
|
+
import { join, sep } from 'node:path';
|
|
18
|
+
|
|
19
|
+
const SYSTEM_DIR = /^[a-z]:[\\/](windows|program files|program files \(x86\))([\\/]|$)/i;
|
|
20
|
+
|
|
21
|
+
/** 用户主目录下的工作区子目录名(不给主目录根本身)。 */
|
|
22
|
+
export const WORKSPACE_SUBDIR = 'works';
|
|
23
|
+
|
|
24
|
+
const isDirectory = (value) => {
|
|
25
|
+
try { return statSync(value).isDirectory() === true; } catch { return false; }
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {{ configured?: string, cwd?: string, home?: string, dataDir?: string, excludeRoots?: string[] }} input
|
|
30
|
+
* @returns {string} 绝对目录;找不到任何可用目录时返回空串。
|
|
31
|
+
* 注意:返回的路径**可能尚不存在**——那是 `~/works` 建议值,调用方负责创建。
|
|
32
|
+
*/
|
|
33
|
+
export function resolveDefaultWorkspace({ configured = '', cwd = '', home = '', dataDir = '', excludeRoots = [], exists = undefined } = {}) {
|
|
34
|
+
const isDir = typeof exists === 'function' ? exists : isDirectory;
|
|
35
|
+
const explicit = typeof configured === 'string' ? configured.trim() : '';
|
|
36
|
+
const under = (value, root) => {
|
|
37
|
+
if (typeof root !== 'string' || root === '') return false;
|
|
38
|
+
const resolvedRoot = root.replace(/[\\/]+$/, '');
|
|
39
|
+
return value === resolvedRoot || value.startsWith(`${resolvedRoot}${sep}`) || value.startsWith(`${resolvedRoot}/`);
|
|
40
|
+
};
|
|
41
|
+
const excluded = (value) => {
|
|
42
|
+
// 插件数据目录永远不能当工作目录。
|
|
43
|
+
if (under(value, dataDir)) return true;
|
|
44
|
+
// `~/.dsh` 整棵树都不能当工作目录:桌面启动器的 cwd 就是 profile 目录
|
|
45
|
+
// (`…\.dsh\profiles\desktop`),把它当项目工作区是错的。
|
|
46
|
+
for (const root of excludeRoots) if (under(value, root)) return true;
|
|
47
|
+
return false;
|
|
48
|
+
};
|
|
49
|
+
// UNC 路径(`\\wsl.localhost\…`、`\\server\share`)不作自动建议:它通常来自启动器
|
|
50
|
+
// 的 cwd(从 WSL 目录里启动桌面端时就是这样),并不是用户的项目目录,而且成员
|
|
51
|
+
// 工具在 UNC 上读写既慢又容易出权限问题。显式配置不受此限。
|
|
52
|
+
const isUnc = (value) => /^\\\\[^\\]/.test(value);
|
|
53
|
+
for (const raw of [explicit, cwd]) {
|
|
54
|
+
if (typeof raw !== 'string' || raw === '') continue;
|
|
55
|
+
if (!isDir(raw)) continue;
|
|
56
|
+
if (excluded(raw)) continue;
|
|
57
|
+
// 显式配置的目录由用户负责;自动探测到的系统目录/UNC 一律跳过。
|
|
58
|
+
if (raw !== explicit && SYSTEM_DIR.test(raw)) continue;
|
|
59
|
+
if (raw !== explicit && isUnc(raw)) continue;
|
|
60
|
+
return raw;
|
|
61
|
+
}
|
|
62
|
+
// 兜底:用户主目录下的 `works` 子目录(跨平台由调用方传入 homedir)。
|
|
63
|
+
if (typeof home === 'string' && home !== '') {
|
|
64
|
+
const suggested = join(home, WORKSPACE_SUBDIR);
|
|
65
|
+
// 主目录本身被排除(例如 home 就落在 ~/.dsh 下)时不再兜底。
|
|
66
|
+
if (!excluded(suggested)) return suggested;
|
|
67
|
+
}
|
|
68
|
+
return '';
|
|
69
|
+
}
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Test-only LLM adapter. It is registered only when DSH_AI_TEAM_TEST=1 and
|
|
3
|
-
* lets the Host exercise the real agent loop's failure path with deterministic
|
|
4
|
-
* billing/network failures instead of external providers.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
export const FAULT_PROVIDER = 'ai-team-fault';
|
|
8
|
-
|
|
9
|
-
export function installFaultAdapter(llm, getMode) {
|
|
10
|
-
if (!llm || typeof llm.registerAdapter !== 'function') return () => {};
|
|
11
|
-
const model = { provider: FAULT_PROVIDER, id: 'fault', name: 'Fault model' };
|
|
12
|
-
const adapter = {
|
|
13
|
-
providerInfo(provider) {
|
|
14
|
-
return { id: provider, name: 'AI Team Fault' };
|
|
15
|
-
},
|
|
16
|
-
providerRetryPolicy() {
|
|
17
|
-
return undefined;
|
|
18
|
-
},
|
|
19
|
-
imageRequestPricing() {
|
|
20
|
-
return undefined;
|
|
21
|
-
},
|
|
22
|
-
imageRequestTarget() {
|
|
23
|
-
return { width: 0, height: 0, maxBytes: 0 };
|
|
24
|
-
},
|
|
25
|
-
async listModels() {
|
|
26
|
-
return [{ ...model }];
|
|
27
|
-
},
|
|
28
|
-
async resolveModel(provider, id) {
|
|
29
|
-
return { provider, id, name: id };
|
|
30
|
-
},
|
|
31
|
-
async prepareCall(provider, id) {
|
|
32
|
-
return {
|
|
33
|
-
model: { provider, id, name: id },
|
|
34
|
-
stream: () => streamFault(getMode()),
|
|
35
|
-
};
|
|
36
|
-
},
|
|
37
|
-
stream() {
|
|
38
|
-
return streamFault(getMode());
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
const dispose = llm.registerAdapter([FAULT_PROVIDER], adapter);
|
|
42
|
-
return typeof dispose === 'function' ? dispose : () => {};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async function* streamFault(mode) {
|
|
46
|
-
const failure = mode === 'billing'
|
|
47
|
-
? { message: 'Injected billing failure', code: 'BILLING', status: 402 }
|
|
48
|
-
: { message: 'Injected network reset', code: 'ECONNRESET' };
|
|
49
|
-
yield { type: 'finish', reason: { kind: 'error', failure } };
|
|
50
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Test-only LLM adapter. It is registered only when DSH_AI_TEAM_TEST=1 and
|
|
3
|
+
* lets the Host exercise the real agent loop's failure path with deterministic
|
|
4
|
+
* billing/network failures instead of external providers.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export const FAULT_PROVIDER = 'ai-team-fault';
|
|
8
|
+
|
|
9
|
+
export function installFaultAdapter(llm, getMode) {
|
|
10
|
+
if (!llm || typeof llm.registerAdapter !== 'function') return () => {};
|
|
11
|
+
const model = { provider: FAULT_PROVIDER, id: 'fault', name: 'Fault model' };
|
|
12
|
+
const adapter = {
|
|
13
|
+
providerInfo(provider) {
|
|
14
|
+
return { id: provider, name: 'AI Team Fault' };
|
|
15
|
+
},
|
|
16
|
+
providerRetryPolicy() {
|
|
17
|
+
return undefined;
|
|
18
|
+
},
|
|
19
|
+
imageRequestPricing() {
|
|
20
|
+
return undefined;
|
|
21
|
+
},
|
|
22
|
+
imageRequestTarget() {
|
|
23
|
+
return { width: 0, height: 0, maxBytes: 0 };
|
|
24
|
+
},
|
|
25
|
+
async listModels() {
|
|
26
|
+
return [{ ...model }];
|
|
27
|
+
},
|
|
28
|
+
async resolveModel(provider, id) {
|
|
29
|
+
return { provider, id, name: id };
|
|
30
|
+
},
|
|
31
|
+
async prepareCall(provider, id) {
|
|
32
|
+
return {
|
|
33
|
+
model: { provider, id, name: id },
|
|
34
|
+
stream: () => streamFault(getMode()),
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
stream() {
|
|
38
|
+
return streamFault(getMode());
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
const dispose = llm.registerAdapter([FAULT_PROVIDER], adapter);
|
|
42
|
+
return typeof dispose === 'function' ? dispose : () => {};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function* streamFault(mode) {
|
|
46
|
+
const failure = mode === 'billing'
|
|
47
|
+
? { message: 'Injected billing failure', code: 'BILLING', status: 402 }
|
|
48
|
+
: { message: 'Injected network reset', code: 'ECONNRESET' };
|
|
49
|
+
yield { type: 'finish', reason: { kind: 'error', failure } };
|
|
50
|
+
}
|
package/lib/host/people-view.js
CHANGED
|
@@ -10,10 +10,15 @@
|
|
|
10
10
|
|
|
11
11
|
import { isTaskBlocked } from '../ledger/fold.js';
|
|
12
12
|
|
|
13
|
+
/** 归档历史仍可读取,不参与日常人员池与批量操作。 */
|
|
14
|
+
export function peopleProjectIsArchived(project, runtime) {
|
|
15
|
+
return project?.archived === true || runtime.service?.state?.projects?.[runtime.id]?.status === 'archived';
|
|
16
|
+
}
|
|
17
|
+
|
|
13
18
|
const ACTIVE_TASK_STATUSES = new Set(['pending', 'in_progress', 'pending_acceptance']);
|
|
14
19
|
|
|
15
20
|
/**
|
|
16
|
-
* @param {Array<{id:string,name:string}>} registryEntries
|
|
21
|
+
* @param {Array<{id:string,name:string,archived?:boolean}>} registryEntries
|
|
17
22
|
* @param {Array<{id:string,service:{state:any}}>} runtimes
|
|
18
23
|
* @param {{ aliases?: Record<string,string> }} [options]
|
|
19
24
|
* @returns {Array<{name:string,role:string,projects:Array,failures:number,activeTasks:number}>}
|
|
@@ -42,7 +47,9 @@ export function aggregatePeople(registryEntries, runtimes, options = {}) {
|
|
|
42
47
|
return alias !== null && alias.startsWith('name:') ? alias.slice('name:'.length) : name;
|
|
43
48
|
};
|
|
44
49
|
for (const runtime of runtimes) {
|
|
45
|
-
const
|
|
50
|
+
const project = registryEntries.find((entry) => entry.id === runtime.id);
|
|
51
|
+
if (peopleProjectIsArchived(project, runtime)) continue;
|
|
52
|
+
const projectName = project?.name ?? runtime.id;
|
|
46
53
|
const state = runtime.service?.state;
|
|
47
54
|
if (state === undefined || state === null) continue;
|
|
48
55
|
// 本项目的活跃任务计数:按 owner/assignee 两个责任位累计,并按状态
|
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Last-line defense for the Team policy: every tool call from a managed member
|
|
3
|
-
* must run with danger-full-access. Activation and wake check once; this guard
|
|
4
|
-
* closes the "permission changed mid-turn" window by repairing before dispatch.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
export const TEAM_PERMISSION = 'danger-full-access';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 目标权限的**预设名**不该被硬编码:部署方可能把 danger-full-access 这一档
|
|
11
|
-
* 起成别的名字(例如 `full`)。名字不存在时 `set()` 会抛错,guard 进而拒绝
|
|
12
|
-
* 成员的每一次工具调用——整个团队被一个改名卡死。这里按「约定的名字 → 表里
|
|
13
|
-
* 第一个 sandbox 为 danger-full-access 的预设」解析,找不到才退回约定名。
|
|
14
|
-
*/
|
|
15
|
-
export function resolveTeamPreset(permissionPresets) {
|
|
16
|
-
const sandboxOf = (name) => {
|
|
17
|
-
try { return permissionPresets?.resolve?.(name)?.sandbox ?? null; } catch { return null; }
|
|
18
|
-
};
|
|
19
|
-
if (sandboxOf(TEAM_PERMISSION) === TEAM_PERMISSION) return TEAM_PERMISSION;
|
|
20
|
-
// 真实契约里没有 `list()`(用 cordis_inspect 核对过 service 签名):
|
|
21
|
-
// 目录是 `catalog()` → `{ options: PresetOption[], defaultOptions, defaultPreset }`,
|
|
22
|
-
// 每个 option 的 key 在 `value` 上。按 `list()` 读会永远拿不到候选,
|
|
23
|
-
// 于是「预设名可配置」这条修复静默失效。
|
|
24
|
-
let options = [];
|
|
25
|
-
try {
|
|
26
|
-
options = permissionPresets?.catalog?.()?.options ?? [];
|
|
27
|
-
} catch {
|
|
28
|
-
options = [];
|
|
29
|
-
}
|
|
30
|
-
if (!Array.isArray(options) || options.length === 0) {
|
|
31
|
-
try { options = permissionPresets?.list?.() ?? []; } catch { options = []; }
|
|
32
|
-
}
|
|
33
|
-
for (const entry of Array.isArray(options) ? options : []) {
|
|
34
|
-
const name = typeof entry === 'string' ? entry : (entry?.value ?? entry?.name ?? entry?.id);
|
|
35
|
-
if (typeof name !== 'string' || name === '') continue;
|
|
36
|
-
if (sandboxOf(name) === TEAM_PERMISSION) return name;
|
|
37
|
-
}
|
|
38
|
-
return TEAM_PERMISSION;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function createMemberPermissionGuard({ service, permissionPresets, sandboxPolicy }) {
|
|
42
|
-
return (execution) => {
|
|
43
|
-
const session = execution?.agent?.session;
|
|
44
|
-
if (session === undefined || session === null) return undefined;
|
|
45
|
-
const members = Object.values(service?.state?.members ?? {});
|
|
46
|
-
const member = members.find((entry) => entry.kind === 'agent' && entry.sessionId === execution.agent.id);
|
|
47
|
-
if (member === undefined) return undefined;
|
|
48
|
-
const presetName = resolveTeamPreset(permissionPresets);
|
|
49
|
-
if (sandboxPolicy?.overrideOf?.(session) !== TEAM_PERMISSION) {
|
|
50
|
-
try {
|
|
51
|
-
permissionPresets?.set?.(session, presetName);
|
|
52
|
-
} catch {
|
|
53
|
-
return `member ${member.name ?? member.id} cannot restore ${presetName}`;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (sandboxPolicy?.overrideOf?.(session) !== TEAM_PERMISSION) {
|
|
57
|
-
return `member ${member.name ?? member.id} is not ${TEAM_PERMISSION}`;
|
|
58
|
-
}
|
|
59
|
-
return undefined;
|
|
60
|
-
};
|
|
61
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Last-line defense for the Team policy: every tool call from a managed member
|
|
3
|
+
* must run with danger-full-access. Activation and wake check once; this guard
|
|
4
|
+
* closes the "permission changed mid-turn" window by repairing before dispatch.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export const TEAM_PERMISSION = 'danger-full-access';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 目标权限的**预设名**不该被硬编码:部署方可能把 danger-full-access 这一档
|
|
11
|
+
* 起成别的名字(例如 `full`)。名字不存在时 `set()` 会抛错,guard 进而拒绝
|
|
12
|
+
* 成员的每一次工具调用——整个团队被一个改名卡死。这里按「约定的名字 → 表里
|
|
13
|
+
* 第一个 sandbox 为 danger-full-access 的预设」解析,找不到才退回约定名。
|
|
14
|
+
*/
|
|
15
|
+
export function resolveTeamPreset(permissionPresets) {
|
|
16
|
+
const sandboxOf = (name) => {
|
|
17
|
+
try { return permissionPresets?.resolve?.(name)?.sandbox ?? null; } catch { return null; }
|
|
18
|
+
};
|
|
19
|
+
if (sandboxOf(TEAM_PERMISSION) === TEAM_PERMISSION) return TEAM_PERMISSION;
|
|
20
|
+
// 真实契约里没有 `list()`(用 cordis_inspect 核对过 service 签名):
|
|
21
|
+
// 目录是 `catalog()` → `{ options: PresetOption[], defaultOptions, defaultPreset }`,
|
|
22
|
+
// 每个 option 的 key 在 `value` 上。按 `list()` 读会永远拿不到候选,
|
|
23
|
+
// 于是「预设名可配置」这条修复静默失效。
|
|
24
|
+
let options = [];
|
|
25
|
+
try {
|
|
26
|
+
options = permissionPresets?.catalog?.()?.options ?? [];
|
|
27
|
+
} catch {
|
|
28
|
+
options = [];
|
|
29
|
+
}
|
|
30
|
+
if (!Array.isArray(options) || options.length === 0) {
|
|
31
|
+
try { options = permissionPresets?.list?.() ?? []; } catch { options = []; }
|
|
32
|
+
}
|
|
33
|
+
for (const entry of Array.isArray(options) ? options : []) {
|
|
34
|
+
const name = typeof entry === 'string' ? entry : (entry?.value ?? entry?.name ?? entry?.id);
|
|
35
|
+
if (typeof name !== 'string' || name === '') continue;
|
|
36
|
+
if (sandboxOf(name) === TEAM_PERMISSION) return name;
|
|
37
|
+
}
|
|
38
|
+
return TEAM_PERMISSION;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function createMemberPermissionGuard({ service, permissionPresets, sandboxPolicy }) {
|
|
42
|
+
return (execution) => {
|
|
43
|
+
const session = execution?.agent?.session;
|
|
44
|
+
if (session === undefined || session === null) return undefined;
|
|
45
|
+
const members = Object.values(service?.state?.members ?? {});
|
|
46
|
+
const member = members.find((entry) => entry.kind === 'agent' && entry.sessionId === execution.agent.id);
|
|
47
|
+
if (member === undefined) return undefined;
|
|
48
|
+
const presetName = resolveTeamPreset(permissionPresets);
|
|
49
|
+
if (sandboxPolicy?.overrideOf?.(session) !== TEAM_PERMISSION) {
|
|
50
|
+
try {
|
|
51
|
+
permissionPresets?.set?.(session, presetName);
|
|
52
|
+
} catch {
|
|
53
|
+
return `member ${member.name ?? member.id} cannot restore ${presetName}`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (sandboxPolicy?.overrideOf?.(session) !== TEAM_PERMISSION) {
|
|
57
|
+
return `member ${member.name ?? member.id} is not ${TEAM_PERMISSION}`;
|
|
58
|
+
}
|
|
59
|
+
return undefined;
|
|
60
|
+
};
|
|
61
|
+
}
|