@v587d/capital-generation 2.21.3 → 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 +31 -0
- package/README.md +5 -5
- package/automation/board.js +89 -22
- package/automation/brief.js +60 -28
- package/automation/client.js +3 -3
- package/automation/client.src.cjs +5 -1
- package/automation/index.js +35 -0
- package/automation/json-text.js +69 -0
- package/automation/package.json +1 -1
- package/automation/runner.js +3 -2
- package/automation/watch.js +1 -59
- 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
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared extraction for model-authored JSON. Briefs and TODO verdicts both arrive as an
|
|
3
|
+
* object wrapped in prose or a code fence, and models occasionally leave a trailing comma
|
|
4
|
+
* before `]`/`}`; one implementation keeps both readers on the same rules.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
function parseValue(text) {
|
|
8
|
+
try {
|
|
9
|
+
return JSON.parse(text)
|
|
10
|
+
} catch {
|
|
11
|
+
return undefined
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function stripTrailingCommas(text) {
|
|
16
|
+
let output = ''
|
|
17
|
+
let inString = false
|
|
18
|
+
let escaped = false
|
|
19
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
20
|
+
const char = text[index]
|
|
21
|
+
if (inString) {
|
|
22
|
+
output += char
|
|
23
|
+
if (escaped) escaped = false
|
|
24
|
+
else if (char === '\\') escaped = true
|
|
25
|
+
else if (char === '"') inString = false
|
|
26
|
+
continue
|
|
27
|
+
}
|
|
28
|
+
if (char === '"') {
|
|
29
|
+
inString = true
|
|
30
|
+
output += char
|
|
31
|
+
continue
|
|
32
|
+
}
|
|
33
|
+
if (char === ',') {
|
|
34
|
+
let next = index + 1
|
|
35
|
+
while (next < text.length && /\s/.test(text[next])) next += 1
|
|
36
|
+
if (text[next] === ']' || text[next] === '}') continue
|
|
37
|
+
}
|
|
38
|
+
output += char
|
|
39
|
+
}
|
|
40
|
+
return output
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Parse any JSON value, retrying once with string-aware trailing-comma removal. */
|
|
44
|
+
export function parseJsonValue(text) {
|
|
45
|
+
const direct = parseValue(text)
|
|
46
|
+
if (direct !== undefined) return direct
|
|
47
|
+
return parseValue(stripTrailingCommas(text))
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Narrow a model reply to the JSON text it carries: the last code fence when one exists,
|
|
52
|
+
* otherwise the outermost `{...}` after a prose preamble. Truncated text is returned as-is so
|
|
53
|
+
* the caller can report a parse failure instead of silently accepting half an object.
|
|
54
|
+
*/
|
|
55
|
+
export function extractJsonText(raw) {
|
|
56
|
+
const text = String(raw ?? '').replace(/^\uFEFF/, '').trim()
|
|
57
|
+
const fences = [...text.matchAll(/```(?:json)?\s*([\s\S]*?)\s*```/gi)]
|
|
58
|
+
if (fences.length > 0) return fences.at(-1)[1].trim()
|
|
59
|
+
const start = text.indexOf('{')
|
|
60
|
+
if (start < 0) return text
|
|
61
|
+
const end = text.lastIndexOf('}')
|
|
62
|
+
return end > start ? text.slice(start, end + 1) : text.slice(start)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The extracted reply when it is a JSON object, otherwise undefined. */
|
|
66
|
+
export function extractJsonObject(raw) {
|
|
67
|
+
const value = parseJsonValue(extractJsonText(raw))
|
|
68
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value) ? value : undefined
|
|
69
|
+
}
|
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/automation/watch.js
CHANGED
|
@@ -7,6 +7,7 @@ import { createHash } from 'node:crypto'
|
|
|
7
7
|
import { isDeepStrictEqual } from 'node:util'
|
|
8
8
|
|
|
9
9
|
import { includesQuote, sourceBlocksOf } from './brief.js'
|
|
10
|
+
import { extractJsonObject } from './json-text.js'
|
|
10
11
|
import { sanitizeMessage } from './redact.js'
|
|
11
12
|
import { localPartsAt } from './time.js'
|
|
12
13
|
|
|
@@ -91,65 +92,6 @@ function decisionCovers(decision, lastSeenAt) {
|
|
|
91
92
|
return seenAt <= decidedAt
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
function parseObject(text) {
|
|
95
|
-
try {
|
|
96
|
-
const value = JSON.parse(text)
|
|
97
|
-
return value !== null && typeof value === 'object' && !Array.isArray(value) ? value : undefined
|
|
98
|
-
} catch {
|
|
99
|
-
return undefined
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Models occasionally leave a trailing comma before `]`/`}`; JSON.parse then drops the whole
|
|
105
|
-
* verdict block and every candidate silently falls back to insufficient.
|
|
106
|
-
*/
|
|
107
|
-
function stripTrailingCommas(text) {
|
|
108
|
-
let output = ''
|
|
109
|
-
let inString = false
|
|
110
|
-
let escaped = false
|
|
111
|
-
for (let index = 0; index < text.length; index += 1) {
|
|
112
|
-
const char = text[index]
|
|
113
|
-
if (inString) {
|
|
114
|
-
output += char
|
|
115
|
-
if (escaped) escaped = false
|
|
116
|
-
else if (char === '\\') escaped = true
|
|
117
|
-
else if (char === '"') inString = false
|
|
118
|
-
continue
|
|
119
|
-
}
|
|
120
|
-
if (char === '"') {
|
|
121
|
-
inString = true
|
|
122
|
-
output += char
|
|
123
|
-
continue
|
|
124
|
-
}
|
|
125
|
-
if (char === ',') {
|
|
126
|
-
let next = index + 1
|
|
127
|
-
while (next < text.length && /\s/.test(text[next])) next += 1
|
|
128
|
-
if (text[next] === ']' || text[next] === '}') continue
|
|
129
|
-
}
|
|
130
|
-
output += char
|
|
131
|
-
}
|
|
132
|
-
return output
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Validate the verifier's result block against the evidence text it claims to quote. A quote
|
|
137
|
-
* that exists in neither the tool output nor the final answer is a fabrication and is dropped.
|
|
138
|
-
*/
|
|
139
|
-
function extractJsonObject(raw) {
|
|
140
|
-
let text = String(raw ?? '').trim()
|
|
141
|
-
const fences = [...text.matchAll(/```(?:json)?\s*([\s\S]*?)\s*```/gi)]
|
|
142
|
-
if (fences.length > 0) {
|
|
143
|
-
text = fences.at(-1)[1].trim()
|
|
144
|
-
} else {
|
|
145
|
-
// A verifier may wrap the JSON in a short prose preamble; keep the outermost object.
|
|
146
|
-
const start = text.indexOf('{')
|
|
147
|
-
const end = text.lastIndexOf('}')
|
|
148
|
-
if (start >= 0 && end > start) text = text.slice(start, end + 1)
|
|
149
|
-
}
|
|
150
|
-
return parseObject(text) ?? parseObject(stripTrailingCommas(text))
|
|
151
|
-
}
|
|
152
|
-
|
|
153
95
|
/**
|
|
154
96
|
* The verifier authors the board card in the same final answer as its verdicts, so the brief
|
|
155
97
|
* costs no extra model call. Validation and fallback live in `verifierBriefContent`.
|
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. */
|