@v587d/capital-generation 2.21.4 → 2.22.0
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 +21 -0
- package/README.md +5 -5
- package/automation/board.js +89 -22
- package/automation/client.js +3 -3
- package/automation/client.src.cjs +5 -1
- package/automation/index.js +35 -0
- package/automation/package.json +1 -1
- package/automation/runner.js +3 -2
- package/chart-ui/package.json +1 -1
- package/config/package.json +1 -1
- package/lib/agents/messaging-policy.d.ts +21 -0
- package/lib/agents/messaging-policy.js +100 -0
- package/lib/agents/role-tool-policy.d.ts +23 -7
- package/lib/agents/role-tool-policy.js +118 -33
- package/lib/agents/root-tool-policy.d.ts +13 -2
- package/lib/agents/root-tool-policy.js +87 -28
- package/lib/agents/wait-for-agents.d.ts +7 -3
- package/lib/agents/wait-for-agents.js +4 -3
- package/lib/collector-runtime.js +2 -2
- package/lib/data-collector/tools.d.ts +1 -1
- package/lib/data-collector/tools.js +31 -3
- package/lib/data-collector/upstream-retry.d.ts +48 -0
- package/lib/data-collector/upstream-retry.js +192 -0
- package/lib/policy-entry.d.ts +3 -3
- package/lib/policy-entry.js +3 -1
- package/lib/web-retriever/local-fetch.d.ts +1 -1
- package/lib/web-retriever/local-fetch.js +1 -1
- package/lib/web-retriever/wind-client.d.ts +1 -1
- package/lib/web-retriever/wind-client.js +1 -1
- package/package.json +6 -6
- package/preset/capital-generation/README.md +2 -1
- package/preset/capital-generation/agent.patch.yml +58 -44
- package/preset/capital-generation/skills/capital-data-profile/SKILL.md +2 -2
- package/preset/capital-generation/skills/capital-data-protocol/SKILL.md +20 -8
- package/preset/capital-generation/skills/capital-data-query/SKILL.md +2 -2
- package/preset/capital-generation/skills/capital-equity-research/SKILL.md +1 -1
- package/preset/capital-generation/skills/capital-event-impact/SKILL.md +1 -1
- package/preset/capital-generation/skills/capital-orchestration/SKILL.md +70 -72
- package/preset/capital-generation/skills/capital-portfolio-review/SKILL.md +1 -1
- package/preset/capital-generation/skills/capital-visualization-protocol/SKILL.md +1 -0
- package/watchlist/package.json +1 -1
|
@@ -86,7 +86,7 @@ const BOARD_UI_KEY = 'capital-automation:board-ui:v3'
|
|
|
86
86
|
const BOARD_PANEL_KEYS = ['todo', 'stocks', 'gaps', 'health']
|
|
87
87
|
const BOARD_TODO_PERIODS = ['today', 'future', 'expired']
|
|
88
88
|
const BOARD_STOCK_PAGE_SIZE = 12
|
|
89
|
-
const BOARD_STOCK_ROLES = ['holding', 'risk', 'event', 'watch']
|
|
89
|
+
const BOARD_STOCK_ROLES = ['holding', 'risk', 'event', 'watch', 'other']
|
|
90
90
|
const BOARD_BRIEF_HIGHLIGHT_MS = 3_000
|
|
91
91
|
const BOARD_PANEL_IDS = {
|
|
92
92
|
'capital-automation-todo': 'todo',
|
|
@@ -212,10 +212,12 @@ const zh = {
|
|
|
212
212
|
roleWatch: '关注',
|
|
213
213
|
roleEvent: '事件',
|
|
214
214
|
roleRisk: '风险',
|
|
215
|
+
roleOther: '其他',
|
|
215
216
|
roleHoldingHint: '自选清单里标记为持仓',
|
|
216
217
|
roleWatchHint: '在自选清单里关注,未标记持仓',
|
|
217
218
|
roleEventHint: '近期运行提到需要跟踪的事件或催化',
|
|
218
219
|
roleRiskHint: '近期运行提示存在风险',
|
|
220
|
+
roleOtherHint: '近期运行提到,不在自选清单里',
|
|
219
221
|
gapEmpty: '最近运行没有报告数据缺口',
|
|
220
222
|
gapSeen: '{n} 次运行',
|
|
221
223
|
gapAll: '查看全部',
|
|
@@ -5536,6 +5538,7 @@ function boardRoleLabel(role) {
|
|
|
5536
5538
|
if (role === 'holding') return zh.board.roleHolding
|
|
5537
5539
|
if (role === 'watch') return zh.board.roleWatch
|
|
5538
5540
|
if (role === 'event') return zh.board.roleEvent
|
|
5541
|
+
if (role === 'other') return zh.board.roleOther
|
|
5539
5542
|
return zh.board.roleRisk
|
|
5540
5543
|
}
|
|
5541
5544
|
|
|
@@ -5543,6 +5546,7 @@ function boardRoleHint(role) {
|
|
|
5543
5546
|
if (role === 'holding') return zh.board.roleHoldingHint
|
|
5544
5547
|
if (role === 'watch') return zh.board.roleWatchHint
|
|
5545
5548
|
if (role === 'event') return zh.board.roleEventHint
|
|
5549
|
+
if (role === 'other') return zh.board.roleOtherHint
|
|
5546
5550
|
return zh.board.roleRiskHint
|
|
5547
5551
|
}
|
|
5548
5552
|
|
package/automation/index.js
CHANGED
|
@@ -109,6 +109,7 @@ export function createAutomationRuntime(options) {
|
|
|
109
109
|
scheduler,
|
|
110
110
|
asks,
|
|
111
111
|
now,
|
|
112
|
+
loadWatchlist: watchlistLoader(ctx, logger),
|
|
112
113
|
})
|
|
113
114
|
watches = createTodoWatchService({
|
|
114
115
|
store,
|
|
@@ -158,6 +159,40 @@ export function createAutomationRuntime(options) {
|
|
|
158
159
|
return { store, runner, scheduler, briefs, watches, asks, service, calendar, workspaces, profile: { displayName, runDir, ownerDir } }
|
|
159
160
|
}
|
|
160
161
|
|
|
162
|
+
/**
|
|
163
|
+
* Radar tiering reads the user's watchlist panel. The watchlist row may settle after this
|
|
164
|
+
* one, so only a successful lookup is cached; a failed read retries next time and the
|
|
165
|
+
* radar falls back to brief tags instead of claiming an empty list.
|
|
166
|
+
*/
|
|
167
|
+
function watchlistLoader(ctx, logger) {
|
|
168
|
+
let service
|
|
169
|
+
let warned = false
|
|
170
|
+
return async () => {
|
|
171
|
+
if (service === undefined) {
|
|
172
|
+
try {
|
|
173
|
+
const candidate = ctx.get('capitalWatchlist')
|
|
174
|
+
if (typeof candidate?.list === 'function') service = candidate
|
|
175
|
+
} catch {
|
|
176
|
+
service = undefined
|
|
177
|
+
}
|
|
178
|
+
if (service === undefined && !warned) {
|
|
179
|
+
warned = true
|
|
180
|
+
logger?.warn?.('capital-automation: 自选股服务不可用,个股动态按简报标签排序')
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (service === undefined) return undefined
|
|
184
|
+
try {
|
|
185
|
+
return await service.list()
|
|
186
|
+
} catch (error) {
|
|
187
|
+
if (!warned) {
|
|
188
|
+
warned = true
|
|
189
|
+
logger?.warn?.(`capital-automation: 自选股清单读取失败,个股动态按简报标签排序(${sanitizeMessage(String(error))})`)
|
|
190
|
+
}
|
|
191
|
+
return undefined
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
161
196
|
function authorizeFactory(ctx) {
|
|
162
197
|
return (req) => {
|
|
163
198
|
let connection
|
package/automation/package.json
CHANGED
package/automation/runner.js
CHANGED
|
@@ -425,8 +425,9 @@ export function createRunRunner(options) {
|
|
|
425
425
|
try {
|
|
426
426
|
if (entry.finished) return
|
|
427
427
|
const subagents = service(ctx, 'subagents')
|
|
428
|
-
|
|
429
|
-
|
|
428
|
+
const waitTree = subagents?.waitForTreeWork ?? subagents?.waitForChildren
|
|
429
|
+
if (typeof waitTree === 'function' && entry.agent !== undefined) {
|
|
430
|
+
const joined = await waitTree.call(subagents, entry.agent).catch(() => true)
|
|
430
431
|
if (joined && !entry.finished && entry.cancelRequested === undefined) {
|
|
431
432
|
armIdle(entry)
|
|
432
433
|
return
|
package/chart-ui/package.json
CHANGED
package/config/package.json
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Call-level `send_message` target guard. rc.2 lets any two members of one subagent tree message
|
|
3
|
+
* each other; Capital keeps the main-agent relay: root -> direct child only, child -> lead only,
|
|
4
|
+
* specialist -> none. The target map is explicit so a future data-junior -> data-analyst link is a
|
|
5
|
+
* one-line addition, not a policy rewrite. Non-Capital presets fail open.
|
|
6
|
+
*/
|
|
7
|
+
import type { GuardedExecution, PolicyContext } from './root-tool-policy.js';
|
|
8
|
+
export declare const MESSAGE_TOOL_NAME = "send_message";
|
|
9
|
+
export declare const ROOT_MESSAGE_DENIED: string;
|
|
10
|
+
export declare const LEAF_MESSAGE_DENIED = "send_message \u53EA\u80FD\u53D1\u7ED9 `lead`\uFF1A\u53F6\u5B50\u89D2\u8272\u4E0D\u76F4\u63A5\u627E\u5144\u5F1F\u6216\u5B59 Agent\uFF0C\u6750\u6599\u4E0E\u8BF7\u6C42\u90FD\u7ECF\u4E3B Agent \u4E2D\u7EE7\u3002";
|
|
11
|
+
export declare const SPECIALIST_MESSAGE_DENIED = "visualization_specialist \u4E0D\u76F4\u63A5\u53D1\u6D88\u606F\uFF1A\u628A\u56FE\u8868\u7ED3\u679C\u4F5C\u4E3A\u6700\u7EC8\u7B54\u590D\u8FD4\u56DE data_junior\uFF0C\u7531\u5B83\u6C47\u603B\u3002";
|
|
12
|
+
/** Allowed targets per role preset. Empty means no messaging at all. Extend junior when the analyst link ships. */
|
|
13
|
+
export declare const ROLE_MESSAGE_TARGETS: Readonly<Record<string, readonly string[]>>;
|
|
14
|
+
/** The host owns the required-field error; the guard only judges a target it can actually read. */
|
|
15
|
+
export declare function sendMessageTargetOf(exec: GuardedExecution | undefined): string | undefined;
|
|
16
|
+
/** Root may address a direct child only: no tree path, and never itself. */
|
|
17
|
+
export declare function isDirectChildName(name: string): boolean;
|
|
18
|
+
/** Read identity per call because a created-time gate misses manually opened modes; fail open otherwise. */
|
|
19
|
+
export declare function sendMessageGuardReasonFor(ctx: PolicyContext): (exec: GuardedExecution | undefined) => string | undefined;
|
|
20
|
+
/** Installs once per root; the same probe channel makes denials visible through dc_status. */
|
|
21
|
+
export declare function registerSendMessageGuard(ctx: PolicyContext): void;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { recordGuardDecision } from './root-tool-policy.js';
|
|
2
|
+
import { readPresetClaim } from '../preset-claim.js';
|
|
3
|
+
import { CAPITAL_PRESET_IDS, ROLE_PRESET_IDS, ROOT_PRESET_ID } from '../preset-ids.js';
|
|
4
|
+
export const MESSAGE_TOOL_NAME = 'send_message';
|
|
5
|
+
export const ROOT_MESSAGE_DENIED = 'send_message 只能发给你的直系子 Agent:目标名不能是 `lead`,也不能含 `/`(孙 Agent 走 data_junior 中继)。'
|
|
6
|
+
+ '重新调用 list_agents() 取直系 name 后再发。';
|
|
7
|
+
export const LEAF_MESSAGE_DENIED = 'send_message 只能发给 `lead`:叶子角色不直接找兄弟或孙 Agent,材料与请求都经主 Agent 中继。';
|
|
8
|
+
export const SPECIALIST_MESSAGE_DENIED = 'visualization_specialist 不直接发消息:把图表结果作为最终答复返回 data_junior,由它汇总。';
|
|
9
|
+
/** Allowed targets per role preset. Empty means no messaging at all. Extend junior when the analyst link ships. */
|
|
10
|
+
export const ROLE_MESSAGE_TARGETS = {
|
|
11
|
+
[ROLE_PRESET_IDS.collector]: ['lead'],
|
|
12
|
+
[ROLE_PRESET_IDS.junior]: ['lead'],
|
|
13
|
+
[ROLE_PRESET_IDS.retriever]: ['lead'],
|
|
14
|
+
[ROLE_PRESET_IDS.specialist]: [],
|
|
15
|
+
[ROLE_PRESET_IDS.analyst]: ['lead'],
|
|
16
|
+
};
|
|
17
|
+
function isRecord(value) {
|
|
18
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
19
|
+
}
|
|
20
|
+
/** The host owns the required-field error; the guard only judges a target it can actually read. */
|
|
21
|
+
export function sendMessageTargetOf(exec) {
|
|
22
|
+
if (exec?.name !== MESSAGE_TOOL_NAME)
|
|
23
|
+
return undefined;
|
|
24
|
+
const args = isRecord(exec.arguments) ? exec.arguments : undefined;
|
|
25
|
+
const target = args?.agent;
|
|
26
|
+
return typeof target === 'string' && target.length > 0 ? target : undefined;
|
|
27
|
+
}
|
|
28
|
+
/** Root may address a direct child only: no tree path, and never itself. */
|
|
29
|
+
export function isDirectChildName(name) {
|
|
30
|
+
return name !== 'lead' && !name.includes('/');
|
|
31
|
+
}
|
|
32
|
+
/** Read identity per call because a created-time gate misses manually opened modes; fail open otherwise. */
|
|
33
|
+
export function sendMessageGuardReasonFor(ctx) {
|
|
34
|
+
return (exec) => {
|
|
35
|
+
const target = sendMessageTargetOf(exec);
|
|
36
|
+
if (target === undefined)
|
|
37
|
+
return undefined;
|
|
38
|
+
const claim = readPresetClaim(ctx, exec?.agent);
|
|
39
|
+
if (claim.registryMissing || claim.failed || claim.claim === undefined)
|
|
40
|
+
return undefined;
|
|
41
|
+
if (!CAPITAL_PRESET_IDS.includes(claim.claim))
|
|
42
|
+
return undefined;
|
|
43
|
+
if (claim.claim === ROOT_PRESET_ID) {
|
|
44
|
+
return isDirectChildName(target) ? undefined : ROOT_MESSAGE_DENIED;
|
|
45
|
+
}
|
|
46
|
+
const allowed = ROLE_MESSAGE_TARGETS[claim.claim] ?? [];
|
|
47
|
+
if (allowed.length === 0)
|
|
48
|
+
return SPECIALIST_MESSAGE_DENIED;
|
|
49
|
+
return allowed.includes(target) ? undefined : LEAF_MESSAGE_DENIED;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const installedGuardRoots = new WeakSet();
|
|
53
|
+
/** Installs once per root; the same probe channel makes denials visible through dc_status. */
|
|
54
|
+
export function registerSendMessageGuard(ctx) {
|
|
55
|
+
const ref = ctx.root ?? ctx;
|
|
56
|
+
if (installedGuardRoots.has(ref))
|
|
57
|
+
return;
|
|
58
|
+
installedGuardRoots.add(ref);
|
|
59
|
+
const reason = sendMessageGuardReasonFor(ctx);
|
|
60
|
+
const install = () => {
|
|
61
|
+
let tools;
|
|
62
|
+
try {
|
|
63
|
+
tools = (ctx.get?.('tools') ?? ctx.tools);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
if (tools === undefined || typeof tools.guard !== 'function') {
|
|
69
|
+
ctx.logger?.warn('capital-generation: send_message 的目标闸门没装上(guard 面不可用):子 Agent 仍可跨层发消息');
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
const dispose = tools.guard((execution) => {
|
|
74
|
+
const denied = reason(execution);
|
|
75
|
+
if (denied !== undefined)
|
|
76
|
+
recordGuardDecision(ctx, execution, MESSAGE_TOOL_NAME);
|
|
77
|
+
return denied;
|
|
78
|
+
});
|
|
79
|
+
return typeof dispose === 'function' ? dispose : undefined;
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
if (typeof ctx.effect === 'function') {
|
|
86
|
+
ctx.effect(() => {
|
|
87
|
+
const dispose = install() ?? (() => { });
|
|
88
|
+
return () => {
|
|
89
|
+
try {
|
|
90
|
+
dispose();
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
installedGuardRoots.delete(ref);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}, 'capital-generation.send-message-guard()');
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
install();
|
|
100
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Role tool surfaces by mounted role preset.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Role tool surfaces by mounted role preset. Family rows define scoped tools; host-global tools
|
|
3
|
+
* are intersected with an explicit allow-list so a new dsh-base tool cannot leak into a leaf.
|
|
4
|
+
* Identity is the preset id, not root/child. Listeners live on `ctx.root`.
|
|
5
5
|
*/
|
|
6
6
|
import type { AgentLike, GuardedExecution, PolicyContext } from './root-tool-policy.js';
|
|
7
7
|
import { type RolePresetId } from '../preset-ids.js';
|
|
@@ -9,13 +9,23 @@ export { ROLE_PRESET_IDS, ROLE_PRESET_ID_LIST, type RolePresetId } from '../pres
|
|
|
9
9
|
/** Registered together with `send_message` by `tool-subagent-control`; no host switch, so leaf roles deny these by name.
|
|
10
10
|
* 0.2.2 moved `list_agents` into the same main entry, so the welded set grew from one to two names. */
|
|
11
11
|
export declare const SIBLING_DENIED_TOOLS: readonly ["interrupt_agent", "list_agents"];
|
|
12
|
-
/**
|
|
12
|
+
/** Full intended surface; only names that resolve as host-global are enforced by the allow-list.
|
|
13
|
+
* Scoped family-row tools stay visible regardless; they must remain in this list for review. */
|
|
14
|
+
export declare const COLLECTOR_ROLE_TOOLS: readonly ["send_message", "skill", "get_local_datetime", "resolve_data_time_range", "request_data", "list_capabilities", "describe_capability", "dc_status"];
|
|
15
|
+
export declare const RETRIEVER_ROLE_TOOLS: readonly ["send_message", "skill", "get_local_datetime", "resolve_data_time_range", "anysearch_search", "web_retriever_fetch", "wind_docs_announcements", "wind_docs_news", "cls_telegraph", "wscn_lives", "cninfo_irm", "sseinfo_qa", "eastmoney_724", "eastmoney_stock_news", "eastmoney_reports", "eastmoney_announcements", "eastmoney_announcement_body", "sina_reports", "ths_eps_forecast", "ocr", "anysearch_batch_search", "anysearch_capabilities"];
|
|
16
|
+
export declare const SPECIALIST_ROLE_TOOLS: readonly ["get_local_datetime", "resolve_data_time_range", "skill", "render_chart"];
|
|
17
|
+
/** Host-global allow-list plus residual per-name denies. */
|
|
13
18
|
export interface RoleSurface {
|
|
19
|
+
/** Intended tools; the host-global subset is enforced as `restrict({ allow })`. */
|
|
20
|
+
readonly allowTools?: readonly string[];
|
|
14
21
|
/** Sibling names welded into a needed row that this persona must not have. */
|
|
15
22
|
readonly denySiblings?: readonly string[];
|
|
23
|
+
/** Host-global Team tools; denied on every Capital role because the rows stay mounted. */
|
|
24
|
+
readonly denyTeam?: readonly string[];
|
|
16
25
|
}
|
|
17
|
-
/** Leaf roles need `send_message`, so they inherit the welded `interrupt_agent` / `list_agents
|
|
18
|
-
*
|
|
26
|
+
/** Leaf roles need `send_message`, so they inherit the welded `interrupt_agent` / `list_agents`.
|
|
27
|
+
* Junior runs only through PTC (run_code is reserved and cannot be named by restrict), so its
|
|
28
|
+
* surface is already narrowed by the executor and no allow-list is applied. */
|
|
19
29
|
export declare const ROLE_TOOL_SURFACES: Record<RolePresetId, RoleSurface>;
|
|
20
30
|
/** Role preset id only, undefined for root and other presets; failure means "do not converge". */
|
|
21
31
|
export declare function rolePresetIdOf(ctx: PolicyContext, agent: AgentLike | undefined): RolePresetId | undefined;
|
|
@@ -32,11 +42,17 @@ export interface RolePolicyResult {
|
|
|
32
42
|
denied: string[];
|
|
33
43
|
/** Names invisible here and skipped harmlessly (their row is not mounted). */
|
|
34
44
|
failed: string[];
|
|
45
|
+
/** Global tools kept by the allow-list; omitted when the surface has no allow-list. */
|
|
46
|
+
allowedGlobals?: string[];
|
|
47
|
+
/** Global tools hidden by the allow-list; omitted when the surface has no allow-list. */
|
|
48
|
+
removedGlobals?: string[];
|
|
49
|
+
/** True when the allow-list could not be applied (no definitions view or restrict rejected it). */
|
|
50
|
+
allowFailed?: boolean;
|
|
35
51
|
}
|
|
36
52
|
export declare function rolePolicyProbes(): RolePolicyProbe[];
|
|
37
53
|
/** Test-only: clears records and the dedupe table. */
|
|
38
54
|
export declare function resetRolePolicyProbes(): void;
|
|
39
|
-
/** Tolerant
|
|
55
|
+
/** Tolerant deny plus host-global allow-list: invisible names are recorded, never thrown. */
|
|
40
56
|
export declare function restrictRoleAgentTools(agent: AgentLike | undefined, surface: RoleSurface): RolePolicyResult;
|
|
41
57
|
/** Call-level residual guard: created-time restrict misses manually opened role modes, so
|
|
42
58
|
* read identity per call. Fail open unless a role preset is confirmed. */
|
|
@@ -1,23 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Role tool surfaces by mounted role preset.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Role tool surfaces by mounted role preset. Family rows define scoped tools; host-global tools
|
|
3
|
+
* are intersected with an explicit allow-list so a new dsh-base tool cannot leak into a leaf.
|
|
4
|
+
* Identity is the preset id, not root/child. Listeners live on `ctx.root`.
|
|
5
5
|
*/
|
|
6
|
-
import { isRootAgent, recordGuardDecision } from './root-tool-policy.js';
|
|
6
|
+
import { isRootAgent, OCR_TOOL_NAME, recordGuardDecision, RETRIEVAL_DENIED_TOOLS, TEAM_DENIED_TOOLS } from './root-tool-policy.js';
|
|
7
7
|
import { readPresetClaim } from '../preset-claim.js';
|
|
8
8
|
import { ROLE_PRESET_ID_LIST, ROLE_PRESET_IDS } from '../preset-ids.js';
|
|
9
9
|
export { ROLE_PRESET_IDS, ROLE_PRESET_ID_LIST } from '../preset-ids.js';
|
|
10
10
|
/** Registered together with `send_message` by `tool-subagent-control`; no host switch, so leaf roles deny these by name.
|
|
11
11
|
* 0.2.2 moved `list_agents` into the same main entry, so the welded set grew from one to two names. */
|
|
12
12
|
export const SIBLING_DENIED_TOOLS = ['interrupt_agent', 'list_agents'];
|
|
13
|
-
/**
|
|
14
|
-
|
|
13
|
+
/** Shared leaf capabilities that are host-global in rc.2, not preset-scoped. */
|
|
14
|
+
const ROLE_MESSAGING_TOOLS = ['send_message', 'skill'];
|
|
15
|
+
const ROLE_TIME_TOOLS = ['get_local_datetime', 'resolve_data_time_range'];
|
|
16
|
+
/** Full intended surface; only names that resolve as host-global are enforced by the allow-list.
|
|
17
|
+
* Scoped family-row tools stay visible regardless; they must remain in this list for review. */
|
|
18
|
+
export const COLLECTOR_ROLE_TOOLS = [
|
|
19
|
+
...ROLE_MESSAGING_TOOLS, ...ROLE_TIME_TOOLS,
|
|
20
|
+
'request_data', 'list_capabilities', 'describe_capability', 'dc_status',
|
|
21
|
+
];
|
|
22
|
+
export const RETRIEVER_ROLE_TOOLS = [
|
|
23
|
+
...ROLE_MESSAGING_TOOLS, ...ROLE_TIME_TOOLS, ...RETRIEVAL_DENIED_TOOLS,
|
|
24
|
+
OCR_TOOL_NAME, 'anysearch_batch_search', 'anysearch_capabilities',
|
|
25
|
+
];
|
|
26
|
+
export const SPECIALIST_ROLE_TOOLS = [
|
|
27
|
+
...ROLE_TIME_TOOLS, 'skill', 'render_chart',
|
|
28
|
+
];
|
|
29
|
+
/** Every role denies Team tools. Only control-row roles also deny the welded sibling names. */
|
|
30
|
+
const DENY_TEAM = { denyTeam: TEAM_DENIED_TOOLS };
|
|
31
|
+
/** Leaf roles need `send_message`, so they inherit the welded `interrupt_agent` / `list_agents`.
|
|
32
|
+
* Junior runs only through PTC (run_code is reserved and cannot be named by restrict), so its
|
|
33
|
+
* surface is already narrowed by the executor and no allow-list is applied. */
|
|
15
34
|
export const ROLE_TOOL_SURFACES = {
|
|
16
|
-
[ROLE_PRESET_IDS.collector]: { denySiblings: SIBLING_DENIED_TOOLS },
|
|
17
|
-
[ROLE_PRESET_IDS.junior]: { denySiblings: SIBLING_DENIED_TOOLS },
|
|
18
|
-
[ROLE_PRESET_IDS.retriever]: { denySiblings: SIBLING_DENIED_TOOLS },
|
|
19
|
-
[ROLE_PRESET_IDS.specialist]: {},
|
|
20
|
-
[ROLE_PRESET_IDS.analyst]: { denySiblings: SIBLING_DENIED_TOOLS },
|
|
35
|
+
[ROLE_PRESET_IDS.collector]: { allowTools: COLLECTOR_ROLE_TOOLS, denySiblings: SIBLING_DENIED_TOOLS, ...DENY_TEAM },
|
|
36
|
+
[ROLE_PRESET_IDS.junior]: { denySiblings: SIBLING_DENIED_TOOLS, ...DENY_TEAM },
|
|
37
|
+
[ROLE_PRESET_IDS.retriever]: { allowTools: RETRIEVER_ROLE_TOOLS, denySiblings: SIBLING_DENIED_TOOLS, ...DENY_TEAM },
|
|
38
|
+
[ROLE_PRESET_IDS.specialist]: { allowTools: SPECIALIST_ROLE_TOOLS, ...DENY_TEAM },
|
|
39
|
+
[ROLE_PRESET_IDS.analyst]: { denySiblings: SIBLING_DENIED_TOOLS, ...DENY_TEAM },
|
|
21
40
|
};
|
|
22
41
|
/** Role preset id only, undefined for root and other presets; failure means "do not converge". */
|
|
23
42
|
export function rolePresetIdOf(ctx, agent) {
|
|
@@ -33,14 +52,20 @@ const installedRoots = new WeakSet();
|
|
|
33
52
|
/** Call-level guard installs independently of the listener. */
|
|
34
53
|
const installedGuardRoots = new WeakSet();
|
|
35
54
|
export function rolePolicyProbes() {
|
|
36
|
-
return probes.map((probe) => ({
|
|
55
|
+
return probes.map((probe) => ({
|
|
56
|
+
...probe,
|
|
57
|
+
denied: [...probe.denied],
|
|
58
|
+
failed: [...probe.failed],
|
|
59
|
+
...(probe.allowedGlobals === undefined ? {} : { allowedGlobals: [...probe.allowedGlobals] }),
|
|
60
|
+
...(probe.removedGlobals === undefined ? {} : { removedGlobals: [...probe.removedGlobals] }),
|
|
61
|
+
}));
|
|
37
62
|
}
|
|
38
63
|
/** Test-only: clears records and the dedupe table. */
|
|
39
64
|
export function resetRolePolicyProbes() {
|
|
40
65
|
probes.length = 0;
|
|
41
66
|
handled.clear();
|
|
42
67
|
}
|
|
43
|
-
/** Tolerant
|
|
68
|
+
/** Tolerant deny plus host-global allow-list: invisible names are recorded, never thrown. */
|
|
44
69
|
export function restrictRoleAgentTools(agent, surface) {
|
|
45
70
|
const denied = [];
|
|
46
71
|
const failed = [];
|
|
@@ -54,7 +79,30 @@ export function restrictRoleAgentTools(agent, surface) {
|
|
|
54
79
|
if (tools === undefined || typeof tools.restrict !== 'function') {
|
|
55
80
|
return { outcome: 'unavailable', denied, failed };
|
|
56
81
|
}
|
|
57
|
-
|
|
82
|
+
let allowedGlobals;
|
|
83
|
+
let removedGlobals;
|
|
84
|
+
let allowFailed = false;
|
|
85
|
+
if (surface.allowTools !== undefined) {
|
|
86
|
+
try {
|
|
87
|
+
const restrictable = tools.view?.(agent)?.restrictableNames;
|
|
88
|
+
if (restrictable === undefined) {
|
|
89
|
+
// Without the pre-restriction view we cannot tell inherited tools from the role's own
|
|
90
|
+
// scoped rows; an allow-list built from the global view would hide send_message.
|
|
91
|
+
allowFailed = true;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
const names = new Set(restrictable);
|
|
95
|
+
allowedGlobals = [...new Set(surface.allowTools)].filter((name) => names.has(name)).sort();
|
|
96
|
+
removedGlobals = [...names].filter((name) => !allowedGlobals.includes(name)).sort();
|
|
97
|
+
if (names.size > 0)
|
|
98
|
+
tools.restrict({ allow: allowedGlobals });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
allowFailed = true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
for (const name of [...(surface.denySiblings ?? []), ...(surface.denyTeam ?? [])]) {
|
|
58
106
|
try {
|
|
59
107
|
tools.restrict({ deny: [name] });
|
|
60
108
|
denied.push(name);
|
|
@@ -63,7 +111,14 @@ export function restrictRoleAgentTools(agent, surface) {
|
|
|
63
111
|
failed.push(name);
|
|
64
112
|
}
|
|
65
113
|
}
|
|
66
|
-
return {
|
|
114
|
+
return {
|
|
115
|
+
outcome: 'restricted',
|
|
116
|
+
denied,
|
|
117
|
+
failed,
|
|
118
|
+
...(allowedGlobals === undefined ? {} : { allowedGlobals }),
|
|
119
|
+
...(removedGlobals === undefined ? {} : { removedGlobals }),
|
|
120
|
+
...(allowFailed ? { allowFailed } : {}),
|
|
121
|
+
};
|
|
67
122
|
}
|
|
68
123
|
/** Call-level residual guard: created-time restrict misses manually opened role modes, so
|
|
69
124
|
* read identity per call. Fail open unless a role preset is confirmed. */
|
|
@@ -144,39 +199,64 @@ export function registerRoleToolPolicy(ctx) {
|
|
|
144
199
|
return;
|
|
145
200
|
installedRoots.add(listenCtx);
|
|
146
201
|
const install = () => {
|
|
202
|
+
const seenAgents = new Map();
|
|
203
|
+
const converge = (agent, presetId) => {
|
|
204
|
+
const id = typeof agent?.session?.id === 'string' ? agent.session.id : undefined;
|
|
205
|
+
if (id !== undefined && handled.has(id))
|
|
206
|
+
return;
|
|
207
|
+
const surface = ROLE_TOOL_SURFACES[presetId];
|
|
208
|
+
const result = restrictRoleAgentTools(agent, surface);
|
|
209
|
+
if (id !== undefined)
|
|
210
|
+
handled.add(id);
|
|
211
|
+
probes.push({ agentId: id, root: isRootAgent(agent), presetId, ...result });
|
|
212
|
+
if (probes.length > MAX_PROBES)
|
|
213
|
+
probes.shift();
|
|
214
|
+
if (result.outcome === 'unavailable') {
|
|
215
|
+
ctx.logger?.warn(`capital-generation: 角色 ${presetId} 的工具收敛没装上(restrict 面不可用):该 child 仍看得见 ${[...SIBLING_DENIED_TOOLS, ...TEAM_DENIED_TOOLS].join(' / ')}`);
|
|
216
|
+
}
|
|
217
|
+
else if (result.allowFailed) {
|
|
218
|
+
ctx.logger?.warn(`capital-generation: 角色 ${presetId} 的宿主全局工具白名单没装上(definitions/allow 面不可用):该 child 仍可能看到未授权的宿主工具`);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
147
221
|
const stopCreated = listenCtx.on?.('agent/created', (payload) => {
|
|
148
222
|
try {
|
|
149
223
|
const agent = payload?.agent;
|
|
150
224
|
const id = typeof agent?.session?.id === 'string' ? agent.session.id : undefined;
|
|
151
|
-
if (id !== undefined
|
|
152
|
-
|
|
225
|
+
if (id !== undefined)
|
|
226
|
+
seenAgents.set(id, agent);
|
|
153
227
|
const presetId = rolePresetIdOf(ctx, agent);
|
|
154
228
|
if (presetId === undefined)
|
|
155
229
|
return;
|
|
156
|
-
|
|
157
|
-
if (surface.denySiblings === undefined || surface.denySiblings.length === 0) {
|
|
158
|
-
if (id !== undefined)
|
|
159
|
-
handled.add(id);
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
const result = restrictRoleAgentTools(agent, surface);
|
|
163
|
-
if (id !== undefined)
|
|
164
|
-
handled.add(id);
|
|
165
|
-
probes.push({ agentId: id, root: isRootAgent(agent), presetId, ...result });
|
|
166
|
-
if (probes.length > MAX_PROBES)
|
|
167
|
-
probes.shift();
|
|
168
|
-
if (result.outcome === 'unavailable') {
|
|
169
|
-
ctx.logger?.warn(`capital-generation: 角色 ${presetId} 的兄弟名字收敛没装上(restrict 面不可用):该 child 仍看得见 ${SIBLING_DENIED_TOOLS.join(' / ')}`);
|
|
170
|
-
}
|
|
230
|
+
converge(agent, presetId);
|
|
171
231
|
}
|
|
172
232
|
catch (error) {
|
|
173
233
|
ctx.logger?.warn(`capital-generation: 角色工具面收敛异常:${error instanceof Error ? error.message : String(error)}`);
|
|
174
234
|
}
|
|
175
235
|
});
|
|
236
|
+
// Manually opened role presets are selected after agent/created; the preset event is the
|
|
237
|
+
// only point where the agent exists and the role identity is known.
|
|
238
|
+
const onAny = listenCtx.on;
|
|
239
|
+
const stopPreset = onAny?.('agent-preset/selected', (sessionId, presetId) => {
|
|
240
|
+
if (typeof sessionId !== 'string' || typeof presetId !== 'string')
|
|
241
|
+
return;
|
|
242
|
+
if (!ROLE_PRESET_ID_LIST.includes(presetId))
|
|
243
|
+
return;
|
|
244
|
+
try {
|
|
245
|
+
const agents = ctx.get?.('agents');
|
|
246
|
+
const agent = seenAgents.get(sessionId) ?? agents?.get?.(sessionId);
|
|
247
|
+
if (agent !== undefined)
|
|
248
|
+
converge(agent, presetId);
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
ctx.logger?.warn(`capital-generation: 角色 preset 选择后收敛异常:${error instanceof Error ? error.message : String(error)}`);
|
|
252
|
+
}
|
|
253
|
+
});
|
|
176
254
|
const stopDisposed = listenCtx.on?.('agent/disposed', (payload) => {
|
|
177
255
|
const id = typeof payload?.agent?.session?.id === 'string' ? payload.agent.session.id : undefined;
|
|
178
|
-
if (id !== undefined)
|
|
256
|
+
if (id !== undefined) {
|
|
179
257
|
handled.delete(id);
|
|
258
|
+
seenAgents.delete(id);
|
|
259
|
+
}
|
|
180
260
|
});
|
|
181
261
|
return () => {
|
|
182
262
|
try {
|
|
@@ -184,6 +264,11 @@ export function registerRoleToolPolicy(ctx) {
|
|
|
184
264
|
stopCreated();
|
|
185
265
|
}
|
|
186
266
|
catch { /* ignore */ }
|
|
267
|
+
try {
|
|
268
|
+
if (typeof stopPreset === 'function')
|
|
269
|
+
stopPreset();
|
|
270
|
+
}
|
|
271
|
+
catch { /* ignore */ }
|
|
187
272
|
try {
|
|
188
273
|
if (typeof stopDisposed === 'function')
|
|
189
274
|
stopDisposed();
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/** Outbound tools (search 2 + wind 2 + named sources 11); `ocr` is excluded because only its url form is restricted. */
|
|
6
6
|
export declare const RETRIEVAL_DENIED_TOOLS: readonly ["anysearch_search", "web_retriever_fetch", "wind_docs_announcements", "wind_docs_news", "cls_telegraph", "wscn_lives", "cninfo_irm", "sseinfo_qa", "eastmoney_724", "eastmoney_stock_news", "eastmoney_reports", "eastmoney_announcements", "eastmoney_announcement_body", "sina_reports", "ths_eps_forecast"];
|
|
7
|
+
/** Generic host web entry points; the only outbound surface is web_retriever's named tools. */
|
|
8
|
+
export declare const HOST_WEB_DENIED_TOOLS: readonly ["web_fetch", "anysearch_batch_search", "anysearch_capabilities"];
|
|
7
9
|
export declare const OCR_TOOL_NAME = "ocr";
|
|
8
10
|
/** Name-level deny cannot express the form distinction; this is a call-level guard. */
|
|
9
11
|
export declare const OCR_ROOT_URL_DENIED: string;
|
|
@@ -12,16 +14,25 @@ export declare function ocrUrlFormRequested(exec: GuardedExecution | undefined):
|
|
|
12
14
|
export declare function ocrFormGuardReasonFor(ctx: PolicyContext): (exec: GuardedExecution | undefined) => string | undefined;
|
|
13
15
|
/** Mounted as a platform pair; recognize both everywhere or the other platform's gate is dead. */
|
|
14
16
|
export declare const SHELL_TOOL_NAMES: readonly ["bash", "pwsh"];
|
|
15
|
-
|
|
17
|
+
/** dsh-base mounts Agent Team globally. We keep the rows (other modes may use them) and deny the
|
|
18
|
+
* four tools on every Capital agent; the `team:policy` prompt section is host-owned and cannot be
|
|
19
|
+
* removed by a name deny, so Capital intentionally ignores that text. */
|
|
20
|
+
export declare const TEAM_DENIED_TOOLS: readonly ["team_task_create", "team_task_list", "team_task_get", "team_task_update"];
|
|
21
|
+
export declare const ROOT_AGENT_DENIED_TOOLS: readonly ["render_chart", "prepare_chart_source", "team_task_create", "team_task_list", "team_task_get", "team_task_update", "anysearch_search", "web_retriever_fetch", "wind_docs_announcements", "wind_docs_news", "cls_telegraph", "wscn_lives", "cninfo_irm", "sseinfo_qa", "eastmoney_724", "eastmoney_stock_news", "eastmoney_reports", "eastmoney_announcements", "eastmoney_announcement_body", "sina_reports", "ths_eps_forecast", "web_fetch", "anysearch_batch_search", "anysearch_capabilities", "write", "edit"];
|
|
16
22
|
export declare const CAPITAL_PRESET_ID = "capital-generation";
|
|
17
23
|
interface ToolRestriction {
|
|
18
24
|
allow?: readonly string[];
|
|
19
25
|
deny?: readonly string[];
|
|
20
26
|
}
|
|
27
|
+
interface ToolViewLike {
|
|
28
|
+
readonly restrictableNames?: ReadonlySet<string>;
|
|
29
|
+
}
|
|
21
30
|
/** `guard` only returns a deny string, so listener order can never turn a deny into an allow. */
|
|
22
31
|
interface RestrictedToolRuntime {
|
|
23
32
|
restrict?(filter: ToolRestriction): unknown;
|
|
24
33
|
guard?(guard: (execution: GuardedExecution) => string | undefined): unknown;
|
|
34
|
+
/** Runtime view of inherited global/ancestor tools; used to skip names absent from this scope. */
|
|
35
|
+
view?(scope?: unknown): ToolViewLike | undefined;
|
|
25
36
|
}
|
|
26
37
|
export interface GuardedExecution {
|
|
27
38
|
readonly name?: string;
|
|
@@ -87,7 +98,7 @@ export declare const FS_WRITE_READ_ONLY: string;
|
|
|
87
98
|
export declare function fsWriteGuardReasonFor(ctx: PolicyContext): (execution: GuardedExecution) => string | undefined;
|
|
88
99
|
export declare function registerFsWriteGuard(ctx: PolicyContext): void;
|
|
89
100
|
export interface RootToolPolicyOptions {
|
|
90
|
-
/** Host policy
|
|
101
|
+
/** false = record only. Host policy now keeps deny on: host-global tools are not closed by rows. */
|
|
91
102
|
deny?: boolean;
|
|
92
103
|
}
|
|
93
104
|
export declare function registerRootToolPolicy(ctx: PolicyContext, options?: RootToolPolicyOptions): void;
|