@v587d/capital-generation 2.21.4 → 2.23.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 +15 -5
- package/automation/board.js +89 -22
- package/automation/client.js +3 -3
- package/automation/client.src.cjs +5 -1
- package/automation/index.js +45 -1
- package/automation/package.json +2 -1
- package/automation/route.js +8 -0
- package/automation/runner.js +3 -2
- package/automation/schema.js +4 -0
- package/automation/service.js +64 -1
- package/automation/storage.js +329 -0
- package/chart-ui/package.json +1 -1
- package/config/client.js +36 -5
- package/config/client.src.cjs +389 -2
- 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
package/config/client.src.cjs
CHANGED
|
@@ -56,6 +56,9 @@ const PADDLE_OCR_DEFAULT_REF = 'PADDLE_OCR_TOKEN'
|
|
|
56
56
|
const TABS_ID = 'capital-config-tabs'
|
|
57
57
|
/** Must match `SKILL_DOC_ROUTE` in `config/index.js`; drift = details never load. */
|
|
58
58
|
const SKILL_DOC_ROUTE = '/capital-skills'
|
|
59
|
+
/** Automation host routes; same auth plane as the workspace dropdown. */
|
|
60
|
+
const STORAGE_ROUTE = '/capital-automation/storage'
|
|
61
|
+
const STORAGE_CLEAR_ROUTE = '/capital-automation/storage/clear'
|
|
59
62
|
const DOC_URLS = {
|
|
60
63
|
fuyao: 'https://fuyao.aicubes.cn/docs/',
|
|
61
64
|
ftshare: 'https://market.ft.tech/gateway/doc/p/pb8eizu3',
|
|
@@ -85,6 +88,14 @@ const AUTOMATION_RANGES = {
|
|
|
85
88
|
maxSteps: { min: 100, max: 2_000, unit: 'automationUnitSteps' },
|
|
86
89
|
maxToolCalls: { min: 100, max: 5_000, unit: 'automationUnitCalls' },
|
|
87
90
|
}
|
|
91
|
+
const STORAGE_CATEGORY_LABELS = {
|
|
92
|
+
datasets: 'automationStorageDatasets',
|
|
93
|
+
profiles: 'automationStorageProfiles',
|
|
94
|
+
ocr: 'automationStorageOcr',
|
|
95
|
+
charts: 'automationStorageCharts',
|
|
96
|
+
runs: 'automationStorageRuns',
|
|
97
|
+
other: 'automationStorageOther',
|
|
98
|
+
}
|
|
88
99
|
const SELECTED_SKILL_FIELDS = SELECTED_SKILL_CATALOG.map(({ key }) => key)
|
|
89
100
|
// Stable orders: facet counts change with the other dimension, but chips must not jump under the cursor.
|
|
90
101
|
const SELECTED_SKILL_TRAITS = selectedSkillTraitOrder()
|
|
@@ -136,6 +147,37 @@ const zh = {
|
|
|
136
147
|
automationWorkspaceLoading: '工作区列表读取中…',
|
|
137
148
|
automationWorkspaceUnavailable: '工作区列表暂时读不到;任务仍会使用默认工作区,切回本格会重试。',
|
|
138
149
|
automationWorkspaceFallback: '专属默认工作区',
|
|
150
|
+
automationStorageGroup: '存储',
|
|
151
|
+
automationStorageWorkspace: '工作区数据',
|
|
152
|
+
automationStorageCache: '可清理缓存',
|
|
153
|
+
automationStorageAnalysis: '分析结果',
|
|
154
|
+
automationStorageRetained: '保留',
|
|
155
|
+
automationStorageSessions: '运行会话',
|
|
156
|
+
automationStorageSessionsHint: '由 DSH 管理,不随「清除数据缓存」删除',
|
|
157
|
+
automationStorageUnavailable: '占用读取失败;切回本格会重试。',
|
|
158
|
+
automationStorageRetry: '重试',
|
|
159
|
+
automationStorageStale: '刷新失败,显示上次结果。',
|
|
160
|
+
automationStorageEmpty: '暂无可清理缓存',
|
|
161
|
+
automationStorageClear: '清除数据缓存',
|
|
162
|
+
automationStorageClearing: '清除中…',
|
|
163
|
+
automationStorageConfirmTitle: '清除数据缓存',
|
|
164
|
+
automationStorageConfirmBody: '将删除 {path} 中 {size} 的 capital-data 缓存(含数据集、数据档案与 OCR)。capital-analysis 中的分析结果、任务、运行记录、简报、通知和运行会话都会保留。',
|
|
165
|
+
automationStorageConfirm: '清除 {size}',
|
|
166
|
+
automationStorageCancel: '取消',
|
|
167
|
+
automationStorageCleared: '已释放 {size}。',
|
|
168
|
+
automationStorageClearedPartial: '已释放 {size},另有 {failed} 个文件未能删除。',
|
|
169
|
+
automationStorageClearFailed: '清理失败,请稍后再试。',
|
|
170
|
+
automationStorageRunInProgress: '有运行正在进行,请结束后再清理。',
|
|
171
|
+
automationStorageActiveHint: '有运行正在进行,结束后可清理。',
|
|
172
|
+
automationStorageUnsafe: '缓存目录不是普通目录,已停止清理。',
|
|
173
|
+
automationStorageDatasets: '数据集',
|
|
174
|
+
automationStorageProfiles: '数据档案',
|
|
175
|
+
automationStorageOcr: 'OCR',
|
|
176
|
+
automationStorageCharts: '图表',
|
|
177
|
+
automationStorageRuns: '分析产物',
|
|
178
|
+
automationStorageOther: '其他',
|
|
179
|
+
automationStorageSessionCount: '{count} 个',
|
|
180
|
+
automationStorageUnreadable: '部分文件读不到,显示的是可读部分。',
|
|
139
181
|
windLabel: 'Wind Alice API Key',
|
|
140
182
|
windHint: 'Wind 金融信披类文档检索接口。保存后新自动模式会话生效。',
|
|
141
183
|
paddleocrLabel: 'PaddleOCR 文档解析 Token',
|
|
@@ -207,6 +249,37 @@ const en = {
|
|
|
207
249
|
automationWorkspaceLoading: 'Loading workspaces…',
|
|
208
250
|
automationWorkspaceUnavailable: 'The workspace list is unavailable; runs still use the default workspace. Re-entering this tab retries.',
|
|
209
251
|
automationWorkspaceFallback: 'Dedicated default workspace',
|
|
252
|
+
automationStorageGroup: 'Storage',
|
|
253
|
+
automationStorageWorkspace: 'Workspace data',
|
|
254
|
+
automationStorageCache: 'Clearable cache',
|
|
255
|
+
automationStorageAnalysis: 'Analysis results',
|
|
256
|
+
automationStorageRetained: 'Retained',
|
|
257
|
+
automationStorageSessions: 'Run sessions',
|
|
258
|
+
automationStorageSessionsHint: 'Managed by DSH; not removed by “Clear data cache”',
|
|
259
|
+
automationStorageUnavailable: 'Could not read usage; re-enter this tab to retry.',
|
|
260
|
+
automationStorageRetry: 'Retry',
|
|
261
|
+
automationStorageStale: 'Refresh failed; showing the previous result.',
|
|
262
|
+
automationStorageEmpty: 'No cache to clear',
|
|
263
|
+
automationStorageClear: 'Clear data cache',
|
|
264
|
+
automationStorageClearing: 'Clearing…',
|
|
265
|
+
automationStorageConfirmTitle: 'Clear data cache',
|
|
266
|
+
automationStorageConfirmBody: 'Delete {size} of capital-data cache from {path} (datasets, profiles, and OCR). Analysis results in capital-analysis, tasks, run records, briefs, notifications, and run sessions are kept.',
|
|
267
|
+
automationStorageConfirm: 'Clear {size}',
|
|
268
|
+
automationStorageCancel: 'Cancel',
|
|
269
|
+
automationStorageCleared: 'Freed {size}.',
|
|
270
|
+
automationStorageClearedPartial: 'Freed {size}; {failed} file(s) could not be removed.',
|
|
271
|
+
automationStorageClearFailed: 'Cleanup failed. Please try again.',
|
|
272
|
+
automationStorageRunInProgress: 'A run is in progress. Try again after it ends.',
|
|
273
|
+
automationStorageActiveHint: 'A run is in progress; cleanup is available after it ends.',
|
|
274
|
+
automationStorageUnsafe: 'The cache directory is not a regular directory; cleanup was stopped.',
|
|
275
|
+
automationStorageDatasets: 'Datasets',
|
|
276
|
+
automationStorageProfiles: 'Data profiles',
|
|
277
|
+
automationStorageOcr: 'OCR',
|
|
278
|
+
automationStorageCharts: 'Charts',
|
|
279
|
+
automationStorageRuns: 'Runs',
|
|
280
|
+
automationStorageOther: 'Other',
|
|
281
|
+
automationStorageSessionCount: '{count} sessions',
|
|
282
|
+
automationStorageUnreadable: 'Some files could not be read; showing readable data.',
|
|
210
283
|
windLabel: 'Wind Alice API Key',
|
|
211
284
|
windHint: 'Wind financial disclosure document retrieval interface. Takes effect in new Auto mode sessions.',
|
|
212
285
|
paddleocrLabel: 'PaddleOCR document token',
|
|
@@ -279,6 +352,37 @@ function installStyles() {
|
|
|
279
352
|
.capital-config-automation-group > .capital-config-group-label { color: var(--dsw-alias-label-secondary); font-size: 12px; font-weight: 500; line-height: 18px; }
|
|
280
353
|
.capital-config-number { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
|
|
281
354
|
.capital-config-workspace { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
|
|
355
|
+
.capital-config-storage { display: flex; flex-direction: column; min-width: 0; border: .5px solid var(--dsw-alias-border-l1); border-radius: 10px; background: var(--dsw-alias-bg-layer-2); }
|
|
356
|
+
.capital-config-storage-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 10px 14px; }
|
|
357
|
+
.capital-config-storage-head > .capital-config-storage-label { font-size: 12px; }
|
|
358
|
+
.capital-config-storage-head > .capital-config-storage-amount { font-size: 15px; font-weight: 600; line-height: 22px; }
|
|
359
|
+
.capital-config-storage-item { display: flex; flex-direction: column; gap: 6px; padding: 10px 14px; border-top: .5px solid var(--dsw-alias-border-l2); }
|
|
360
|
+
.capital-config-storage-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; min-width: 0; }
|
|
361
|
+
.capital-config-storage-value { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
|
|
362
|
+
.capital-config-storage-label { color: var(--dsw-alias-label-secondary); font-size: 12.5px; line-height: 20px; }
|
|
363
|
+
.capital-config-storage-amount { display: inline-flex; align-items: baseline; gap: 6px; color: var(--dsw-alias-label-primary); font-size: 13px; font-weight: 500; line-height: 20px; font-variant-numeric: tabular-nums; white-space: nowrap; }
|
|
364
|
+
.capital-config-storage-count { color: var(--dsw-alias-label-tertiary); font-size: 11.5px; font-weight: 400; }
|
|
365
|
+
.capital-config-storage-chips { display: flex; flex-wrap: wrap; gap: 4px; }
|
|
366
|
+
.capital-config-storage-chip { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 999px; background: var(--dsw-alias-bg-module-platform); color: var(--dsw-alias-label-secondary); font-size: 11px; line-height: 16px; white-space: nowrap; }
|
|
367
|
+
.capital-config-storage-badge { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 999px; background: var(--dsw-alias-state-success-tertiary); color: var(--dsw-alias-state-success-primary); font-size: 11px; font-weight: 500; line-height: 16px; white-space: nowrap; }
|
|
368
|
+
.capital-config-storage-meta { margin: 0; color: var(--dsw-alias-label-tertiary); font-size: 11.5px; line-height: 17px; overflow-wrap: anywhere; }
|
|
369
|
+
.capital-config-storage-meta[data-tone="warn"] { color: var(--dsw-alias-state-warn-primary); }
|
|
370
|
+
.capital-config-storage-foot { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; padding: 10px 14px; border-top: .5px solid var(--dsw-alias-border-l2); }
|
|
371
|
+
.capital-config-storage-status { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; margin-left: auto; min-width: 0; }
|
|
372
|
+
.capital-config-storage-retry { padding: 0; border: 0; background: transparent; color: var(--dsw-alias-brand-primary); font: inherit; font-size: 12px; line-height: 18px; cursor: pointer; }
|
|
373
|
+
.capital-config-storage-retry:hover { text-decoration: underline; }
|
|
374
|
+
.capital-config-storage-retry:focus-visible { outline: var(--dsw-focus-ring-width, 2px) solid var(--dsw-focus-ring-color, var(--dsw-alias-brand-primary)); outline-offset: 2px; }
|
|
375
|
+
.capital-config-storage-result { margin: 0; color: var(--dsw-alias-state-success-primary); font-size: 12px; line-height: 18px; }
|
|
376
|
+
.capital-config-cache-button { box-sizing: border-box; display: inline-flex; align-items: center; justify-content: center; height: 32px; padding: 0 14px; border: .5px solid var(--dsw-alias-border-l1); border-radius: 999px; background: transparent; color: var(--dsw-alias-label-primary); font: inherit; font-size: 12.5px; line-height: 20px; cursor: pointer; transition: background .15s, border-color .15s, opacity .15s; }
|
|
377
|
+
.capital-config-cache-button:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
|
|
378
|
+
.capital-config-cache-button[data-variant="danger"] { border-color: var(--dsw-alias-state-error-primary); color: var(--dsw-alias-state-error-primary); }
|
|
379
|
+
.capital-config-cache-button[data-variant="danger"]:hover:not(:disabled) { background: var(--dsw-alias-state-error-primary); color: var(--dsw-alias-bg-base); }
|
|
380
|
+
.capital-config-cache-button:focus-visible { outline: var(--dsw-focus-ring-width, 2px) solid var(--dsw-focus-ring-color, var(--dsw-alias-brand-primary)); outline-offset: 0; }
|
|
381
|
+
.capital-config-cache-button:disabled { opacity: .5; cursor: not-allowed; }
|
|
382
|
+
div.capital-config-cache-modal { width: min(480px, 100%); }
|
|
383
|
+
.capital-config-cache-modal-content { min-height: 0; overflow: auto; }
|
|
384
|
+
.capital-config-cache-modal-body { margin: 0; color: var(--dsw-alias-label-secondary); font-size: 12.5px; line-height: 20px; }
|
|
385
|
+
.capital-config-cache-actions { display: flex; justify-content: flex-end; gap: 8px; }
|
|
282
386
|
.capital-config-number-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; min-width: 0; }
|
|
283
387
|
.capital-config-number-head .capital-config-write-failed { font-size: 11px; line-height: 16px; }
|
|
284
388
|
.capital-config-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
|
|
@@ -449,6 +553,15 @@ class CapitalCardController {
|
|
|
449
553
|
this.workspaceDetails = null
|
|
450
554
|
this.workspacesInFlight = false
|
|
451
555
|
this.workspacesFailed = false
|
|
556
|
+
this.storage = null
|
|
557
|
+
this.storageInFlight = false
|
|
558
|
+
this.storageQueued = false
|
|
559
|
+
this.storageFailed = false
|
|
560
|
+
this.storageClearing = false
|
|
561
|
+
this.storageClearError = null
|
|
562
|
+
this.storageClearedBytes = null
|
|
563
|
+
this.storageClearedFailed = 0
|
|
564
|
+
this.storageRequestId = 0
|
|
452
565
|
// Row count is external: null = unknown, never 0; fetch only after the card is shown.
|
|
453
566
|
this.bundleRows = null
|
|
454
567
|
this.rowsRequested = false
|
|
@@ -511,6 +624,17 @@ class CapitalCardController {
|
|
|
511
624
|
writing: this.workspaceWriting,
|
|
512
625
|
failed: this.workspaceFailed,
|
|
513
626
|
}),
|
|
627
|
+
storage: {
|
|
628
|
+
data: this.storage,
|
|
629
|
+
loading: this.storageInFlight || (this.storage === null && this.storageFailed !== true),
|
|
630
|
+
failed: this.storageFailed,
|
|
631
|
+
unavailable: this.storageFailed && this.storage === null,
|
|
632
|
+
stale: this.storageFailed && this.storage !== null,
|
|
633
|
+
clearing: this.storageClearing,
|
|
634
|
+
error: this.storageClearError,
|
|
635
|
+
clearedBytes: this.storageClearedBytes,
|
|
636
|
+
clearedFailed: this.storageClearedFailed,
|
|
637
|
+
},
|
|
514
638
|
// `count === null` means unknown, not zero: the card decides whether to draw it.
|
|
515
639
|
components: { count: this.bundleRows },
|
|
516
640
|
}
|
|
@@ -725,6 +849,81 @@ class CapitalCardController {
|
|
|
725
849
|
this.store.set(this.projection())
|
|
726
850
|
}
|
|
727
851
|
|
|
852
|
+
/**
|
|
853
|
+
* Workspace usage is read from the automation route. Dirty cache is harmless: the
|
|
854
|
+
* server caps the scan and the card still allows a retry. A forced read merges with
|
|
855
|
+
* an in-flight one so a workspace switch cannot race an older response.
|
|
856
|
+
*/
|
|
857
|
+
async ensureStorage(force = false) {
|
|
858
|
+
if (this.storageInFlight) {
|
|
859
|
+
if (force) this.storageQueued = true
|
|
860
|
+
return
|
|
861
|
+
}
|
|
862
|
+
if (!force && this.storage !== null && !this.storageFailed) return
|
|
863
|
+
const requestId = (this.storageRequestId += 1)
|
|
864
|
+
this.storageInFlight = true
|
|
865
|
+
this.storageFailed = false
|
|
866
|
+
this.store.set(this.projection())
|
|
867
|
+
try {
|
|
868
|
+
if (typeof fetch !== 'function') throw new Error('fetch_unavailable')
|
|
869
|
+
const response = await fetch(STORAGE_ROUTE, { method: 'GET', cache: 'no-store', credentials: 'same-origin' })
|
|
870
|
+
if (!response?.ok) throw new Error(`http_${response?.status ?? 0}`)
|
|
871
|
+
const payload = await response.json()
|
|
872
|
+
const storage = payload?.storage
|
|
873
|
+
if (storage === null || typeof storage !== 'object' || Array.isArray(storage)) throw new Error('invalid_payload')
|
|
874
|
+
if (requestId === this.storageRequestId) {
|
|
875
|
+
this.storage = storage
|
|
876
|
+
this.storageFailed = false
|
|
877
|
+
}
|
|
878
|
+
} catch {
|
|
879
|
+
if (requestId === this.storageRequestId) this.storageFailed = true
|
|
880
|
+
} finally {
|
|
881
|
+
if (requestId === this.storageRequestId) this.storageInFlight = false
|
|
882
|
+
this.store.set(this.projection())
|
|
883
|
+
if (this.storageQueued) {
|
|
884
|
+
this.storageQueued = false
|
|
885
|
+
void this.ensureStorage(true)
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
async clearStorage() {
|
|
891
|
+
if (this.storageClearing) return 'ignored'
|
|
892
|
+
this.storageClearing = true
|
|
893
|
+
this.storageClearError = null
|
|
894
|
+
this.storageClearedBytes = null
|
|
895
|
+
this.storageClearedFailed = 0
|
|
896
|
+
this.store.set(this.projection())
|
|
897
|
+
try {
|
|
898
|
+
if (typeof fetch !== 'function') throw new Error('fetch_unavailable')
|
|
899
|
+
const response = await fetch(STORAGE_CLEAR_ROUTE, {
|
|
900
|
+
method: 'POST',
|
|
901
|
+
headers: { 'content-type': 'application/json' },
|
|
902
|
+
body: JSON.stringify({ confirm: true }),
|
|
903
|
+
credentials: 'same-origin',
|
|
904
|
+
})
|
|
905
|
+
const payload = await response.json().catch(() => null)
|
|
906
|
+
if (!response?.ok || payload?.ok !== true) {
|
|
907
|
+
const code = payload?.code
|
|
908
|
+
this.storageClearError = code === 'run_in_progress'
|
|
909
|
+
? 'run_in_progress'
|
|
910
|
+
: code === 'cache_root_unsafe' ? 'unsafe' : 'failed'
|
|
911
|
+
return 'failed'
|
|
912
|
+
}
|
|
913
|
+
const cleared = payload?.cleared
|
|
914
|
+
if (Number.isSafeInteger(cleared?.bytes) && cleared.bytes >= 0) this.storageClearedBytes = cleared.bytes
|
|
915
|
+
if (Array.isArray(cleared?.failed)) this.storageClearedFailed = cleared.failed.length
|
|
916
|
+
await this.ensureStorage(true)
|
|
917
|
+
return 'cleared'
|
|
918
|
+
} catch {
|
|
919
|
+
this.storageClearError = 'failed'
|
|
920
|
+
return 'failed'
|
|
921
|
+
} finally {
|
|
922
|
+
this.storageClearing = false
|
|
923
|
+
this.store.set(this.projection())
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
|
|
728
927
|
async writeAutomationWorkspace(value) {
|
|
729
928
|
if (this.workspaceWriting) return 'ignored'
|
|
730
929
|
const snapshot = this.scope.getSnapshot()
|
|
@@ -742,6 +941,15 @@ class CapitalCardController {
|
|
|
742
941
|
const landed = (this.scope.getSnapshot().value?.automation?.[AUTOMATION_WORKSPACE_FIELD] ?? '') === next
|
|
743
942
|
if (!landed) this.workspaceFailed = true
|
|
744
943
|
this.store.set(this.projection())
|
|
944
|
+
if (landed) {
|
|
945
|
+
// A different workspace has a different cache; drop the old numbers before refetching.
|
|
946
|
+
this.storage = null
|
|
947
|
+
this.storageFailed = false
|
|
948
|
+
this.storageClearError = null
|
|
949
|
+
this.storageClearedBytes = null
|
|
950
|
+
this.storageClearedFailed = 0
|
|
951
|
+
void this.ensureStorage(true)
|
|
952
|
+
}
|
|
745
953
|
return landed ? 'saved' : 'failed'
|
|
746
954
|
}
|
|
747
955
|
|
|
@@ -758,6 +966,8 @@ class CapitalCardController {
|
|
|
758
966
|
toggleSelectedSkillsMode: (auto) => this.toggleSelectedSkillsMode(auto),
|
|
759
967
|
ensureBundleRows: () => this.ensureBundleRows(),
|
|
760
968
|
ensureWorkspaces: () => this.ensureWorkspaces(),
|
|
969
|
+
ensureStorage: (force) => this.ensureStorage(force),
|
|
970
|
+
clearStorage: () => this.clearStorage(),
|
|
761
971
|
writeAutomationWorkspace: (value) => this.writeAutomationWorkspace(value),
|
|
762
972
|
}
|
|
763
973
|
}
|
|
@@ -956,6 +1166,53 @@ function SelectedSkillRow({ entry, state, disabled, onChange, t }) {
|
|
|
956
1166
|
* `data-capital-config-tab`, so when unavailable we draw neither tabs nor that
|
|
957
1167
|
* attribute and the host list stays visible.
|
|
958
1168
|
*/
|
|
1169
|
+
function formatBytes(value) {
|
|
1170
|
+
const bytes = typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : 0
|
|
1171
|
+
if (bytes < 1024) return `${Math.round(bytes)} B`
|
|
1172
|
+
const units = ['KB', 'MB', 'GB', 'TB']
|
|
1173
|
+
let size = bytes
|
|
1174
|
+
let unit = -1
|
|
1175
|
+
while (size >= 1024 && unit < units.length - 1) {
|
|
1176
|
+
size /= 1024
|
|
1177
|
+
unit += 1
|
|
1178
|
+
}
|
|
1179
|
+
return `${size.toFixed(1)} ${units[unit]}`
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
function ClearCacheModal({ open, bytes, displayPath, clearing, error, onCancel, onConfirm, t }) {
|
|
1183
|
+
const size = formatBytes(bytes)
|
|
1184
|
+
const errorText = error === 'run_in_progress'
|
|
1185
|
+
? t('automationStorageRunInProgress')
|
|
1186
|
+
: error === 'unsafe' ? t('automationStorageUnsafe') : error === 'failed' ? t('automationStorageClearFailed') : null
|
|
1187
|
+
return h(Modal, {
|
|
1188
|
+
open,
|
|
1189
|
+
onClose: () => { if (!clearing) onCancel() },
|
|
1190
|
+
title: t('automationStorageConfirmTitle'),
|
|
1191
|
+
closeLabel: t('automationStorageCancel'),
|
|
1192
|
+
className: 'capital-config-cache-modal',
|
|
1193
|
+
contentClassName: 'capital-config-cache-modal-content',
|
|
1194
|
+
footer: h('div', { className: 'capital-config-cache-actions' },
|
|
1195
|
+
h('button', {
|
|
1196
|
+
type: 'button',
|
|
1197
|
+
className: 'capital-config-cache-button',
|
|
1198
|
+
disabled: clearing,
|
|
1199
|
+
onClick: onCancel,
|
|
1200
|
+
}, t('automationStorageCancel')),
|
|
1201
|
+
h('button', {
|
|
1202
|
+
type: 'button',
|
|
1203
|
+
className: 'capital-config-cache-button',
|
|
1204
|
+
'data-variant': 'danger',
|
|
1205
|
+
'aria-busy': clearing ? 'true' : undefined,
|
|
1206
|
+
disabled: clearing,
|
|
1207
|
+
onClick: onConfirm,
|
|
1208
|
+
}, clearing ? t('automationStorageClearing') : t('automationStorageConfirm', { size })),
|
|
1209
|
+
),
|
|
1210
|
+
},
|
|
1211
|
+
h('p', { className: 'capital-config-cache-modal-body' },
|
|
1212
|
+
t('automationStorageConfirmBody', { size, path: displayPath || t('automationStorageWorkspace') })),
|
|
1213
|
+
errorText ? h('p', { role: 'alert', className: 'capital-config-write-failed' }, errorText) : null)
|
|
1214
|
+
}
|
|
1215
|
+
|
|
959
1216
|
function CapitalCard(props) {
|
|
960
1217
|
const t = props.t
|
|
961
1218
|
const state = props.useCapitalCard((snapshot) => snapshot)
|
|
@@ -963,13 +1220,16 @@ function CapitalCard(props) {
|
|
|
963
1220
|
const autoMode = state.selectedSkillsMode?.auto === true
|
|
964
1221
|
const locale = skillLocale()
|
|
965
1222
|
const [tab, setTab] = useState('sources')
|
|
1223
|
+
const [clearCacheOpen, setClearCacheOpen] = useState(false)
|
|
966
1224
|
const [traitFilter, setTraitFilter] = useState(SELECTED_SKILL_FILTER_ALL)
|
|
967
1225
|
const [presetFilter, setPresetFilter] = useState(SELECTED_SKILL_FILTER_ALL)
|
|
968
1226
|
// Fetch on mount: tab labels carry numbers; hooks must precede the unavailable return.
|
|
969
1227
|
useEffect(() => { props.ensureBundleRows() }, [])
|
|
970
|
-
// The workspace list
|
|
1228
|
+
// The workspace list and storage usage live behind the automation route; fetch when its tab opens.
|
|
971
1229
|
useEffect(() => {
|
|
972
|
-
if (tab
|
|
1230
|
+
if (tab !== 'automation') return
|
|
1231
|
+
props.ensureWorkspaces()
|
|
1232
|
+
props.ensureStorage()
|
|
973
1233
|
}, [tab])
|
|
974
1234
|
// Pinned order is snapshotted on tab entry so rows never move under the cursor.
|
|
975
1235
|
const enabledKeys = () => new Set(SELECTED_SKILL_CATALOG
|
|
@@ -1108,6 +1368,118 @@ function CapitalCard(props) {
|
|
|
1108
1368
|
? h('p', { id: workspacePathId, className: 'capital-config-hint' }, t('automationWorkspacePath', { path: workspaceState.current.path }))
|
|
1109
1369
|
: null,
|
|
1110
1370
|
)
|
|
1371
|
+
const storageState = state.storage ?? {
|
|
1372
|
+
data: null,
|
|
1373
|
+
loading: false,
|
|
1374
|
+
failed: false,
|
|
1375
|
+
unavailable: false,
|
|
1376
|
+
stale: false,
|
|
1377
|
+
clearing: false,
|
|
1378
|
+
error: null,
|
|
1379
|
+
clearedBytes: null,
|
|
1380
|
+
clearedFailed: 0,
|
|
1381
|
+
}
|
|
1382
|
+
const storageData = storageState.data
|
|
1383
|
+
const cacheBytes = Number.isSafeInteger(storageData?.cache?.bytes) ? storageData.cache.bytes : 0
|
|
1384
|
+
const analysisBytes = Number.isSafeInteger(storageData?.analysis?.bytes) ? storageData.analysis.bytes : 0
|
|
1385
|
+
const workspaceBytes = cacheBytes + analysisBytes
|
|
1386
|
+
const sessions = storageData?.sessions
|
|
1387
|
+
const sessionBytes = Number.isSafeInteger(sessions?.bytes) ? sessions.bytes : 0
|
|
1388
|
+
const sessionCount = Number.isSafeInteger(sessions?.count) ? sessions.count : 0
|
|
1389
|
+
const storageAmount = (value, truncated) => `${truncated === true ? '≥ ' : ''}${formatBytes(value)}`
|
|
1390
|
+
const chipsOf = (categories, ids) => ids
|
|
1391
|
+
.map((id) => ({ id, value: Number.isSafeInteger(categories?.[id]?.bytes) ? categories[id].bytes : 0 }))
|
|
1392
|
+
.filter((item) => item.value > 0)
|
|
1393
|
+
.map((item) => h('span', { key: item.id, className: 'capital-config-storage-chip' }, `${t(STORAGE_CATEGORY_LABELS[item.id])} ${formatBytes(item.value)}`))
|
|
1394
|
+
const cacheChips = storageData === null ? [] : chipsOf(storageData.cache?.categories, ['datasets', 'profiles', 'ocr', 'other'])
|
|
1395
|
+
const analysisChips = storageData === null ? [] : chipsOf(storageData.analysis?.categories, ['charts', 'runs', 'other'])
|
|
1396
|
+
const cacheBlocked = storageData?.canClear === false
|
|
1397
|
+
const canClearCache = cacheBytes > 0 && !cacheBlocked && storageState.loading !== true && storageState.clearing !== true
|
|
1398
|
+
const clearError = storageState.error === 'run_in_progress'
|
|
1399
|
+
? t('automationStorageRunInProgress')
|
|
1400
|
+
: storageState.error === 'unsafe' ? t('automationStorageUnsafe')
|
|
1401
|
+
: storageState.error === 'failed' ? t('automationStorageClearFailed') : null
|
|
1402
|
+
const cacheMetaTone = storageData?.cache?.unsafe === true || (storageData?.activeRuns ?? 0) > 0 ? 'warn' : undefined
|
|
1403
|
+
const cacheMeta = storageState.loading || storageState.unavailable || storageState.stale
|
|
1404
|
+
? null
|
|
1405
|
+
: storageData?.cache?.unsafe === true ? t('automationStorageUnsafe')
|
|
1406
|
+
: (storageData?.activeRuns ?? 0) > 0 ? t('automationStorageActiveHint')
|
|
1407
|
+
: cacheBytes === 0 ? t('automationStorageEmpty')
|
|
1408
|
+
: storageData?.cache?.unreadable > 0 ? t('automationStorageUnreadable') : null
|
|
1409
|
+
const footNote = storageState.unavailable ? t('automationStorageUnavailable') : storageState.stale ? t('automationStorageStale') : null
|
|
1410
|
+
const clearedHint = storageState.clearedBytes === null
|
|
1411
|
+
? null
|
|
1412
|
+
: storageState.clearedFailed > 0
|
|
1413
|
+
? t('automationStorageClearedPartial', { size: formatBytes(storageState.clearedBytes), failed: storageState.clearedFailed })
|
|
1414
|
+
: t('automationStorageCleared', { size: formatBytes(storageState.clearedBytes) })
|
|
1415
|
+
const storageSection = automationGroup('automationStorageGroup', [
|
|
1416
|
+
h('div', { className: 'capital-config-storage' },
|
|
1417
|
+
h('div', { className: 'capital-config-storage-head' },
|
|
1418
|
+
h('span', { className: 'capital-config-storage-label' }, t('automationStorageWorkspace')),
|
|
1419
|
+
h('span', { className: 'capital-config-storage-amount' }, storageData === null
|
|
1420
|
+
? '—'
|
|
1421
|
+
: storageAmount(workspaceBytes, storageData?.cache?.truncated === true || storageData?.analysis?.truncated === true)),
|
|
1422
|
+
),
|
|
1423
|
+
h('div', { className: 'capital-config-storage-item' },
|
|
1424
|
+
h('div', { className: 'capital-config-storage-row' },
|
|
1425
|
+
h('span', { className: 'capital-config-storage-label' }, t('automationStorageCache')),
|
|
1426
|
+
h('span', { className: 'capital-config-storage-amount' }, storageData === null
|
|
1427
|
+
? '—'
|
|
1428
|
+
: storageAmount(cacheBytes, storageData?.cache?.truncated === true)),
|
|
1429
|
+
),
|
|
1430
|
+
cacheChips.length > 0 ? h('div', { className: 'capital-config-storage-chips' }, ...cacheChips) : null,
|
|
1431
|
+
cacheMeta ? h('p', { className: 'capital-config-storage-meta', 'data-tone': cacheMetaTone }, cacheMeta) : null,
|
|
1432
|
+
),
|
|
1433
|
+
h('div', { className: 'capital-config-storage-item' },
|
|
1434
|
+
h('div', { className: 'capital-config-storage-row' },
|
|
1435
|
+
h('span', { className: 'capital-config-storage-label' }, t('automationStorageAnalysis')),
|
|
1436
|
+
h('span', { className: 'capital-config-storage-value' },
|
|
1437
|
+
h('span', { className: 'capital-config-storage-amount' }, storageData === null
|
|
1438
|
+
? '—'
|
|
1439
|
+
: storageAmount(analysisBytes, storageData?.analysis?.truncated === true)),
|
|
1440
|
+
storageData === null ? null : h('span', { className: 'capital-config-storage-badge' }, t('automationStorageRetained')),
|
|
1441
|
+
),
|
|
1442
|
+
),
|
|
1443
|
+
analysisChips.length > 0 ? h('div', { className: 'capital-config-storage-chips' }, ...analysisChips) : null,
|
|
1444
|
+
),
|
|
1445
|
+
h('div', { className: 'capital-config-storage-item' },
|
|
1446
|
+
h('div', { className: 'capital-config-storage-row' },
|
|
1447
|
+
h('span', { className: 'capital-config-storage-label' }, t('automationStorageSessions')),
|
|
1448
|
+
h('span', { className: 'capital-config-storage-value' },
|
|
1449
|
+
h('span', { className: 'capital-config-storage-amount' },
|
|
1450
|
+
storageData === null || sessions?.available === false ? '—' : formatBytes(sessionBytes),
|
|
1451
|
+
),
|
|
1452
|
+
storageData === null || sessions?.available === false
|
|
1453
|
+
? null
|
|
1454
|
+
: h('span', { className: 'capital-config-storage-count' }, t('automationStorageSessionCount', { count: sessionCount })),
|
|
1455
|
+
),
|
|
1456
|
+
),
|
|
1457
|
+
h('p', { className: 'capital-config-storage-meta' }, t('automationStorageSessionsHint')),
|
|
1458
|
+
),
|
|
1459
|
+
h('div', { className: 'capital-config-storage-foot' },
|
|
1460
|
+
h('button', {
|
|
1461
|
+
type: 'button',
|
|
1462
|
+
className: 'capital-config-cache-button',
|
|
1463
|
+
'data-variant': 'danger',
|
|
1464
|
+
'aria-busy': storageState.clearing ? 'true' : undefined,
|
|
1465
|
+
disabled: !canClearCache,
|
|
1466
|
+
onClick: () => setClearCacheOpen(true),
|
|
1467
|
+
}, storageState.clearing ? t('automationStorageClearing') : t('automationStorageClear')),
|
|
1468
|
+
h('div', { className: 'capital-config-storage-status' },
|
|
1469
|
+
clearedHint ? h('p', { role: 'status', className: 'capital-config-storage-result' }, clearedHint) : null,
|
|
1470
|
+
clearError && storageState.clearing !== true ? h('p', { role: 'alert', className: 'capital-config-write-failed' }, clearError) : null,
|
|
1471
|
+
footNote ? h('p', { className: 'capital-config-storage-meta' }, footNote) : null,
|
|
1472
|
+
storageState.unavailable || storageState.stale
|
|
1473
|
+
? h('button', {
|
|
1474
|
+
type: 'button',
|
|
1475
|
+
className: 'capital-config-storage-retry',
|
|
1476
|
+
onClick: () => props.ensureStorage(true),
|
|
1477
|
+
}, t('automationStorageRetry'))
|
|
1478
|
+
: null,
|
|
1479
|
+
),
|
|
1480
|
+
),
|
|
1481
|
+
),
|
|
1482
|
+
])
|
|
1111
1483
|
const automationSection = h('div', { className: 'capital-config-automation' },
|
|
1112
1484
|
workspaceSection,
|
|
1113
1485
|
automationGroup('automationScheduleGroup', [
|
|
@@ -1138,6 +1510,7 @@ function CapitalCard(props) {
|
|
|
1138
1510
|
),
|
|
1139
1511
|
state.automation?.inAppNotifications?.failed ? h('p', { role: 'status', className: 'capital-config-write-failed' }, t('saveFailed')) : null,
|
|
1140
1512
|
]),
|
|
1513
|
+
storageSection,
|
|
1141
1514
|
)
|
|
1142
1515
|
const modeSection = h('div', { className: 'capital-config-selected-mode' },
|
|
1143
1516
|
h('div', { className: 'capital-config-switch-row' },
|
|
@@ -1245,6 +1618,20 @@ function CapitalCard(props) {
|
|
|
1245
1618
|
)]),
|
|
1246
1619
|
// The panel is the host's rows list; keep the aria-controls target non-empty via sr-only.
|
|
1247
1620
|
panel('components', [h('span', { className: 'capital-config-sr-only' }, t('componentsHint'))]),
|
|
1621
|
+
clearCacheOpen ? h(ClearCacheModal, {
|
|
1622
|
+
open: true,
|
|
1623
|
+
bytes: cacheBytes,
|
|
1624
|
+
displayPath: storageData?.workspace?.displayPath ?? workspaceState.current?.path ?? '',
|
|
1625
|
+
clearing: storageState.clearing,
|
|
1626
|
+
error: storageState.error,
|
|
1627
|
+
onCancel: () => { if (!storageState.clearing) setClearCacheOpen(false) },
|
|
1628
|
+
onConfirm: () => {
|
|
1629
|
+
Promise.resolve(props.clearStorage()).then((result) => {
|
|
1630
|
+
if (result === 'cleared') setClearCacheOpen(false)
|
|
1631
|
+
})
|
|
1632
|
+
},
|
|
1633
|
+
t,
|
|
1634
|
+
}) : null,
|
|
1248
1635
|
)
|
|
1249
1636
|
}
|
|
1250
1637
|
|
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
|
+
}
|