@v587d/capital-generation 2.24.0 → 2.26.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 +49 -0
- package/README.md +9 -4
- package/THIRD_PARTY_NOTICES.md +20 -0
- package/automation/brief.js +21 -24
- package/automation/builtins.js +55 -54
- package/automation/client.js +11 -3
- package/automation/client.src.cjs +70 -8
- package/automation/package.json +1 -1
- package/chart-ui/package.json +1 -1
- package/config/client.js +21 -5
- package/config/client.src.cjs +264 -0
- package/config/package.json +1 -1
- package/cordis.patch.yml +9 -2
- package/lib/agents/role-tool-policy.d.ts +1 -1
- package/lib/agents/root-tool-policy.d.ts +3 -3
- package/lib/agents/root-tool-policy.js +2 -2
- package/lib/data-collector/catalog-taxonomy.js +4 -0
- package/lib/python-runtime/child-env.d.ts +11 -0
- package/lib/python-runtime/child-env.js +39 -0
- package/lib/python-runtime/errors.d.ts +8 -0
- package/lib/python-runtime/errors.js +34 -0
- package/lib/python-runtime/lock.d.ts +11 -0
- package/lib/python-runtime/lock.js +68 -0
- package/lib/python-runtime/manager.d.ts +61 -0
- package/lib/python-runtime/manager.js +517 -0
- package/lib/python-runtime/manifest.d.ts +5 -0
- package/lib/python-runtime/manifest.js +160 -0
- package/lib/python-runtime/paths.d.ts +20 -0
- package/lib/python-runtime/paths.js +156 -0
- package/lib/python-runtime/platform.d.ts +32 -0
- package/lib/python-runtime/platform.js +145 -0
- package/lib/python-runtime/pnpm.d.ts +24 -0
- package/lib/python-runtime/pnpm.js +115 -0
- package/lib/python-runtime/probe.d.ts +13 -0
- package/lib/python-runtime/probe.js +101 -0
- package/lib/python-runtime/routes.d.ts +6 -0
- package/lib/python-runtime/routes.js +152 -0
- package/lib/python-runtime/types.d.ts +105 -0
- package/lib/python-runtime/types.js +3 -0
- package/lib/python-runtime-entry.d.ts +10 -0
- package/lib/python-runtime-entry.js +60 -0
- package/lib/sources/eastmoney-http.js +346 -1
- package/lib/sources/tencent-http.js +248 -2
- package/lib/sources/tencent-public-core.js +1 -1
- package/lib/sources-entry.d.ts +1 -1
- package/lib/time/tools.js +2 -0
- package/lib/web-retriever/local-fetch.d.ts +1 -1
- package/lib/web-retriever/local-fetch.js +1 -1
- package/lib/web-retriever/sources.d.ts +16 -1
- package/lib/web-retriever/sources.js +133 -1
- package/lib/web-retriever/tools.js +41 -1
- package/lib/web-retriever/wind-client.d.ts +1 -1
- package/lib/web-retriever/wind-client.js +1 -1
- package/package.json +13 -1
- package/plugin-page/README.en.md +1 -7
- package/plugin-page/README.zh.md +1 -8
- package/preset/capital-generation/agent.patch.yml +12 -13
- package/preset/capital-generation/skills/capital-web-protocol/SKILL.md +10 -4
- package/python/worker.py +154 -0
- package/runtime/manifest.json +75 -0
- package/scripts/python-runtime.mjs +139 -0
- package/watchlist/client.js +83 -3
- package/watchlist/client.src.cjs +565 -1
- package/watchlist/package.json +1 -1
package/config/client.src.cjs
CHANGED
|
@@ -59,6 +59,8 @@ const SKILL_DOC_ROUTE = '/capital-skills'
|
|
|
59
59
|
/** Automation host routes; same auth plane as the workspace dropdown. */
|
|
60
60
|
const STORAGE_ROUTE = '/capital-automation/storage'
|
|
61
61
|
const STORAGE_CLEAR_ROUTE = '/capital-automation/storage/clear'
|
|
62
|
+
/** Host-plane python-runtime row; status is read-only until the user clicks prepare. */
|
|
63
|
+
const PYTHON_RUNTIME_ROUTE = '/python-runtime'
|
|
62
64
|
const DOC_URLS = {
|
|
63
65
|
fuyao: 'https://fuyao.aicubes.cn/docs/',
|
|
64
66
|
ftshare: 'https://market.ft.tech/gateway/doc/p/pb8eizu3',
|
|
@@ -117,6 +119,33 @@ const zh = {
|
|
|
117
119
|
titleUnsaved: '数据源 未保存',
|
|
118
120
|
componentsTitle: '包含的组件',
|
|
119
121
|
componentsHint: '组件清单由 DSH 绘制,显示在下方。',
|
|
122
|
+
pythonTitle: '分析环境',
|
|
123
|
+
pythonLoading: '读取分析环境…',
|
|
124
|
+
pythonHint: 'Python 运行时由本插件独立管理,不修改系统 Python,也不使用 DSH 桌面端运行时。首次准备需要联网下载约 55–60 MB,安装后可离线使用。',
|
|
125
|
+
pythonNotInstalled: '尚未准备',
|
|
126
|
+
pythonReady: '已就绪',
|
|
127
|
+
pythonBroken: '需要修复',
|
|
128
|
+
pythonInstalling: '准备中…',
|
|
129
|
+
pythonUnsupported: '当前平台不支持:{reason}',
|
|
130
|
+
pythonBase: '基础环境',
|
|
131
|
+
pythonParquet: 'Parquet 支持',
|
|
132
|
+
pythonPrepare: '准备分析环境',
|
|
133
|
+
pythonInstallParquet: '安装 Parquet 支持',
|
|
134
|
+
pythonRepair: '修复分析环境',
|
|
135
|
+
pythonCancel: '取消',
|
|
136
|
+
pythonVerify: '重新检测',
|
|
137
|
+
pythonVerifyOk: '自检通过。',
|
|
138
|
+
pythonRemove: '移除',
|
|
139
|
+
pythonRemoveConfirm: '移除后需要重新下载,确定移除?',
|
|
140
|
+
pythonRemoveYes: '确定移除',
|
|
141
|
+
pythonNotInstalledShort: '未安装',
|
|
142
|
+
pythonVersions: 'Python {python} · numpy {numpy} · pandas {pandas}',
|
|
143
|
+
pythonPath: '位置:{path}',
|
|
144
|
+
pythonParquetHint: '全市场 Parquet 数据需要 pyarrow;额外约 50 MB 下载、155 MB 磁盘。',
|
|
145
|
+
pythonLoadFailed: '读取分析环境状态失败;稍后重试。',
|
|
146
|
+
pythonPrepareFailed: '准备失败:{message}',
|
|
147
|
+
pythonJob: '{stage}:{message}',
|
|
148
|
+
pythonParquetReady: 'Parquet 支持已就绪。',
|
|
120
149
|
fuyaoLabel: 'Fuyao API Key',
|
|
121
150
|
fuyaoHint: '同花顺 Fuyao 结构化数据接口。保存后新自动模式会话生效。',
|
|
122
151
|
ftshareLabel: 'FTShare API Key',
|
|
@@ -219,6 +248,33 @@ const en = {
|
|
|
219
248
|
titleUnsaved: 'Data Sources unsaved',
|
|
220
249
|
componentsTitle: 'Components',
|
|
221
250
|
componentsHint: 'The component list is drawn by DSH and appears below.',
|
|
251
|
+
pythonTitle: 'Analysis environment',
|
|
252
|
+
pythonLoading: 'Reading the analysis environment…',
|
|
253
|
+
pythonHint: 'The Python runtime is private to this plugin. It does not modify system Python or use the DSH Desktop runtime. The first prepare downloads about 55–60 MB; after that it works offline.',
|
|
254
|
+
pythonNotInstalled: 'Not prepared',
|
|
255
|
+
pythonReady: 'Ready',
|
|
256
|
+
pythonBroken: 'Repair needed',
|
|
257
|
+
pythonInstalling: 'Preparing…',
|
|
258
|
+
pythonUnsupported: 'This platform is not supported: {reason}',
|
|
259
|
+
pythonBase: 'Base environment',
|
|
260
|
+
pythonParquet: 'Parquet support',
|
|
261
|
+
pythonPrepare: 'Prepare analysis environment',
|
|
262
|
+
pythonInstallParquet: 'Install Parquet support',
|
|
263
|
+
pythonRepair: 'Repair analysis environment',
|
|
264
|
+
pythonCancel: 'Cancel',
|
|
265
|
+
pythonVerify: 'Re-check',
|
|
266
|
+
pythonVerifyOk: 'Self-check passed.',
|
|
267
|
+
pythonRemove: 'Remove',
|
|
268
|
+
pythonRemoveConfirm: 'Removing means downloading it again. Remove?',
|
|
269
|
+
pythonRemoveYes: 'Remove',
|
|
270
|
+
pythonNotInstalledShort: 'Not installed',
|
|
271
|
+
pythonVersions: 'Python {python} · numpy {numpy} · pandas {pandas}',
|
|
272
|
+
pythonPath: 'Location: {path}',
|
|
273
|
+
pythonParquetHint: 'Market-wide Parquet data needs pyarrow; about 50 MB download and 155 MB on disk.',
|
|
274
|
+
pythonLoadFailed: 'Could not read the analysis environment state; try again shortly.',
|
|
275
|
+
pythonPrepareFailed: 'Prepare failed: {message}',
|
|
276
|
+
pythonJob: '{stage}: {message}',
|
|
277
|
+
pythonParquetReady: 'Parquet support is ready.',
|
|
222
278
|
fuyaoLabel: 'Fuyao API Key',
|
|
223
279
|
fuyaoHint: 'Tonghuashun Fuyao structured-data API. Takes effect in new Auto mode sessions.',
|
|
224
280
|
ftshareLabel: 'FTShare API Key',
|
|
@@ -339,6 +395,7 @@ function installStyles() {
|
|
|
339
395
|
[data-plugin-detail="${BUNDLE_NAME}"]:has(.capital-config-card[data-capital-config-tab="sources"]) section[data-plugin-rows] { display: none; }
|
|
340
396
|
[data-plugin-detail="${BUNDLE_NAME}"]:has(.capital-config-card[data-capital-config-tab="automation"]) section[data-plugin-rows] { display: none; }
|
|
341
397
|
[data-plugin-detail="${BUNDLE_NAME}"]:has(.capital-config-card[data-capital-config-tab="skills"]) section[data-plugin-rows] { display: none; }
|
|
398
|
+
[data-plugin-detail="${BUNDLE_NAME}"]:has(.capital-config-card[data-capital-config-tab="analysis"]) section[data-plugin-rows] { display: none; }
|
|
342
399
|
/* Internal roles must stay declared for delegation; hide their user-selectable cards in Settings. */
|
|
343
400
|
[data-agent-preset-id="capital-data-junior"],
|
|
344
401
|
[data-agent-preset-id="capital-visualization-specialist"] { display: none !important; }
|
|
@@ -379,6 +436,21 @@ function installStyles() {
|
|
|
379
436
|
.capital-config-cache-button[data-variant="danger"]:hover:not(:disabled) { background: var(--dsw-alias-state-error-primary); color: var(--dsw-alias-bg-base); }
|
|
380
437
|
.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
438
|
.capital-config-cache-button:disabled { opacity: .5; cursor: not-allowed; }
|
|
439
|
+
.capital-config-runtime { display: flex; flex-direction: column; gap: 12px; padding-top: 12px; }
|
|
440
|
+
.capital-config-runtime-head { display: flex; flex-direction: column; gap: 4px; }
|
|
441
|
+
.capital-config-runtime-title { display: flex; align-items: center; gap: 8px; color: var(--dsw-alias-label-primary); font-size: 13px; font-weight: 500; line-height: 20px; }
|
|
442
|
+
.capital-config-runtime-state { 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; font-weight: 500; line-height: 16px; }
|
|
443
|
+
.capital-config-runtime-state[data-tone="ready"] { background: var(--dsw-alias-state-success-tertiary); color: var(--dsw-alias-state-success-primary); }
|
|
444
|
+
.capital-config-runtime-state[data-tone="warn"] { background: var(--dsw-alias-state-warn-tertiary); color: var(--dsw-alias-state-warn-primary); }
|
|
445
|
+
.capital-config-runtime-state[data-tone="error"] { background: var(--dsw-alias-state-error-tertiary); color: var(--dsw-alias-state-error-primary); }
|
|
446
|
+
.capital-config-runtime-copy { margin: 0; color: var(--dsw-alias-label-tertiary); font-size: 12px; line-height: 18px; }
|
|
447
|
+
.capital-config-runtime-card { display: flex; flex-direction: column; gap: 8px; padding: 10px 14px; border: .5px solid var(--dsw-alias-border-l1); border-radius: 10px; background: var(--dsw-alias-bg-layer-2); }
|
|
448
|
+
.capital-config-runtime-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; min-width: 0; }
|
|
449
|
+
.capital-config-runtime-label { color: var(--dsw-alias-label-secondary); font-size: 12.5px; line-height: 20px; }
|
|
450
|
+
.capital-config-runtime-meta { color: var(--dsw-alias-label-tertiary); font-size: 11.5px; line-height: 17px; overflow-wrap: anywhere; }
|
|
451
|
+
.capital-config-runtime-actions { display: flex; flex-wrap: wrap; gap: 8px; }
|
|
452
|
+
.capital-config-runtime-notice { margin: 0; color: var(--dsw-alias-state-success-primary); font-size: 12px; line-height: 18px; }
|
|
453
|
+
.capital-config-runtime-error { margin: 0; color: var(--dsw-alias-state-error-primary); font-size: 12px; line-height: 18px; }
|
|
382
454
|
div.capital-config-cache-modal { width: min(480px, 100%); }
|
|
383
455
|
.capital-config-cache-modal-content { min-height: 0; overflow: auto; }
|
|
384
456
|
.capital-config-cache-modal-body { margin: 0; color: var(--dsw-alias-label-secondary); font-size: 12.5px; line-height: 20px; }
|
|
@@ -1213,6 +1285,196 @@ function ClearCacheModal({ open, bytes, displayPath, clearing, error, onCancel,
|
|
|
1213
1285
|
errorText ? h('p', { role: 'alert', className: 'capital-config-write-failed' }, errorText) : null)
|
|
1214
1286
|
}
|
|
1215
1287
|
|
|
1288
|
+
function PythonRuntimeSection({ t }) {
|
|
1289
|
+
const [status, setStatus] = useState(null)
|
|
1290
|
+
const [job, setJob] = useState(null)
|
|
1291
|
+
const [error, setError] = useState('')
|
|
1292
|
+
const [notice, setNotice] = useState('')
|
|
1293
|
+
const [removePack, setRemovePack] = useState('')
|
|
1294
|
+
const [busy, setBusy] = useState(false)
|
|
1295
|
+
|
|
1296
|
+
const load = async () => {
|
|
1297
|
+
try {
|
|
1298
|
+
const response = await fetch(`${PYTHON_RUNTIME_ROUTE}/status`, { method: 'GET', cache: 'no-store', credentials: 'same-origin' })
|
|
1299
|
+
const data = await response.json().catch(() => ({}))
|
|
1300
|
+
if (!response.ok) throw new Error(data?.error?.message || t('pythonLoadFailed'))
|
|
1301
|
+
setStatus(data)
|
|
1302
|
+
if (data.activeJob?.state === 'running') setJob(data.activeJob)
|
|
1303
|
+
setError('')
|
|
1304
|
+
} catch (failure) {
|
|
1305
|
+
setError(failure instanceof Error ? failure.message : t('pythonLoadFailed'))
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
useEffect(() => { load() }, [])
|
|
1310
|
+
useEffect(() => {
|
|
1311
|
+
if (job === null || job.state !== 'running') return undefined
|
|
1312
|
+
let cancelled = false
|
|
1313
|
+
const timer = setInterval(async () => {
|
|
1314
|
+
try {
|
|
1315
|
+
const response = await fetch(`${PYTHON_RUNTIME_ROUTE}/jobs/${encodeURIComponent(job.id)}`, { method: 'GET', cache: 'no-store', credentials: 'same-origin' })
|
|
1316
|
+
const data = await response.json().catch(() => ({}))
|
|
1317
|
+
if (cancelled || !response.ok || !data.job) return
|
|
1318
|
+
setJob(data.job)
|
|
1319
|
+
if (data.job.state !== 'running') {
|
|
1320
|
+
setJob(null)
|
|
1321
|
+
await load()
|
|
1322
|
+
}
|
|
1323
|
+
} catch {
|
|
1324
|
+
// Status polling is best-effort; the next tick retries.
|
|
1325
|
+
}
|
|
1326
|
+
}, 800)
|
|
1327
|
+
return () => { cancelled = true; clearInterval(timer) }
|
|
1328
|
+
}, [job?.id, job?.state])
|
|
1329
|
+
|
|
1330
|
+
const post = async (suffix, body) => {
|
|
1331
|
+
const response = await fetch(`${PYTHON_RUNTIME_ROUTE}${suffix}`, {
|
|
1332
|
+
method: 'POST',
|
|
1333
|
+
cache: 'no-store',
|
|
1334
|
+
credentials: 'same-origin',
|
|
1335
|
+
headers: { 'content-type': 'application/json' },
|
|
1336
|
+
body: JSON.stringify(body),
|
|
1337
|
+
})
|
|
1338
|
+
const data = await response.json().catch(() => ({}))
|
|
1339
|
+
if (!response.ok) throw new Error(data?.error?.message || t('pythonLoadFailed'))
|
|
1340
|
+
return data
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
const prepare = async (packs) => {
|
|
1344
|
+
setBusy(true); setError(''); setNotice('')
|
|
1345
|
+
try {
|
|
1346
|
+
const data = await post('/prepare', { packs })
|
|
1347
|
+
if (data.job) setJob(data.job)
|
|
1348
|
+
} catch (failure) {
|
|
1349
|
+
setError(t('pythonPrepareFailed', { message: failure instanceof Error ? failure.message : String(failure) }))
|
|
1350
|
+
} finally {
|
|
1351
|
+
setBusy(false)
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
const cancel = async () => {
|
|
1356
|
+
if (job === null) return
|
|
1357
|
+
try {
|
|
1358
|
+
await post('/cancel', { jobId: job.id })
|
|
1359
|
+
} catch (failure) {
|
|
1360
|
+
setError(failure instanceof Error ? failure.message : String(failure))
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
const verify = async () => {
|
|
1365
|
+
setBusy(true); setError(''); setNotice('')
|
|
1366
|
+
try {
|
|
1367
|
+
await post('/verify', {})
|
|
1368
|
+
setNotice(t('pythonVerifyOk'))
|
|
1369
|
+
await load()
|
|
1370
|
+
} catch (failure) {
|
|
1371
|
+
setError(failure instanceof Error ? failure.message : String(failure))
|
|
1372
|
+
} finally {
|
|
1373
|
+
setBusy(false)
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
const remove = async (pack) => {
|
|
1378
|
+
setBusy(true); setError(''); setNotice('')
|
|
1379
|
+
try {
|
|
1380
|
+
if (pack === 'base' && status?.parquet?.state === 'ready') await post('/remove', { pack: 'parquet', confirm: true })
|
|
1381
|
+
await post('/remove', { pack, confirm: true })
|
|
1382
|
+
setRemovePack('')
|
|
1383
|
+
await load()
|
|
1384
|
+
} catch (failure) {
|
|
1385
|
+
setError(failure instanceof Error ? failure.message : String(failure))
|
|
1386
|
+
} finally {
|
|
1387
|
+
setBusy(false)
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
if (status === null) {
|
|
1392
|
+
return h('section', { className: 'capital-config-runtime' },
|
|
1393
|
+
h('p', { className: 'capital-config-runtime-copy' }, error === '' ? t('pythonLoading') : error))
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
const supported = status.supported !== false
|
|
1397
|
+
const baseState = status.base?.state ?? 'not-installed'
|
|
1398
|
+
const parquetState = status.parquet?.state ?? 'not-installed'
|
|
1399
|
+
const baseReady = baseState === 'ready'
|
|
1400
|
+
const parquetReady = parquetState === 'ready'
|
|
1401
|
+
const baseTone = baseState === 'ready' ? 'ready' : baseState === 'broken' ? 'error' : baseState === 'installing' ? 'warn' : undefined
|
|
1402
|
+
const baseLabel = baseState === 'ready' ? t('pythonReady')
|
|
1403
|
+
: baseState === 'broken' ? t('pythonBroken')
|
|
1404
|
+
: baseState === 'installing' ? t('pythonInstalling') : t('pythonNotInstalled')
|
|
1405
|
+
const parquetLabel = parquetState === 'ready' ? t('pythonReady')
|
|
1406
|
+
: parquetState === 'broken' ? t('pythonBroken')
|
|
1407
|
+
: parquetState === 'installing' ? t('pythonInstalling') : t('pythonNotInstalledShort')
|
|
1408
|
+
|
|
1409
|
+
const button = (label, onClick, options = {}) => h('button', {
|
|
1410
|
+
type: 'button',
|
|
1411
|
+
className: 'capital-config-cache-button',
|
|
1412
|
+
disabled: busy || options.disabled === true,
|
|
1413
|
+
...(options.danger === true ? { 'data-variant': 'danger' } : {}),
|
|
1414
|
+
onClick,
|
|
1415
|
+
}, label)
|
|
1416
|
+
|
|
1417
|
+
return h('section', { className: 'capital-config-runtime' },
|
|
1418
|
+
h('div', { className: 'capital-config-runtime-head' },
|
|
1419
|
+
h('div', { className: 'capital-config-runtime-title' },
|
|
1420
|
+
t('pythonTitle'),
|
|
1421
|
+
h('span', { className: 'capital-config-runtime-state', 'data-tone': baseTone }, baseLabel),
|
|
1422
|
+
),
|
|
1423
|
+
h('p', { className: 'capital-config-runtime-copy' }, t('pythonHint')),
|
|
1424
|
+
),
|
|
1425
|
+
supported ? null : h('p', { className: 'capital-config-runtime-error' }, t('pythonUnsupported', { reason: status.reason ?? '' })),
|
|
1426
|
+
h('div', { className: 'capital-config-runtime-card' },
|
|
1427
|
+
h('div', { className: 'capital-config-runtime-row' },
|
|
1428
|
+
h('span', { className: 'capital-config-runtime-label' }, t('pythonBase')),
|
|
1429
|
+
h('span', { className: 'capital-config-runtime-state', 'data-tone': baseTone }, baseLabel),
|
|
1430
|
+
),
|
|
1431
|
+
baseReady
|
|
1432
|
+
? h('p', { className: 'capital-config-runtime-copy' }, t('pythonVersions', {
|
|
1433
|
+
python: status.python,
|
|
1434
|
+
numpy: status.base?.packages?.numpy ?? '—',
|
|
1435
|
+
pandas: status.base?.packages?.pandas ?? '—',
|
|
1436
|
+
}))
|
|
1437
|
+
: h('p', { className: 'capital-config-runtime-copy' }, t('pythonPath', { path: status.cacheRoot })),
|
|
1438
|
+
h('div', { className: 'capital-config-runtime-actions' },
|
|
1439
|
+
!baseReady && supported ? button(baseState === 'broken' ? t('pythonRepair') : t('pythonPrepare'), () => prepare(['base']), { disabled: job?.state === 'running' }) : null,
|
|
1440
|
+
baseReady ? button(t('pythonVerify'), verify, { disabled: job?.state === 'running' }) : null,
|
|
1441
|
+
removePack === 'base'
|
|
1442
|
+
? h('span', { className: 'capital-config-runtime-actions' },
|
|
1443
|
+
h('span', { className: 'capital-config-runtime-copy' }, t('pythonRemoveConfirm')),
|
|
1444
|
+
button(t('pythonRemoveYes'), () => remove('base'), { danger: true, disabled: busy }),
|
|
1445
|
+
button(t('pythonCancel'), () => setRemovePack(''), { disabled: busy }),
|
|
1446
|
+
)
|
|
1447
|
+
: baseReady ? button(t('pythonRemove'), () => setRemovePack('base'), { disabled: busy || job?.state === 'running' }) : null,
|
|
1448
|
+
),
|
|
1449
|
+
),
|
|
1450
|
+
h('div', { className: 'capital-config-runtime-card' },
|
|
1451
|
+
h('div', { className: 'capital-config-runtime-row' },
|
|
1452
|
+
h('span', { className: 'capital-config-runtime-label' }, t('pythonParquet')),
|
|
1453
|
+
h('span', { className: 'capital-config-runtime-state', 'data-tone': parquetReady ? 'ready' : undefined }, parquetLabel),
|
|
1454
|
+
),
|
|
1455
|
+
h('p', { className: 'capital-config-runtime-copy' }, parquetReady ? t('pythonParquetReady') : t('pythonParquetHint')),
|
|
1456
|
+
h('div', { className: 'capital-config-runtime-actions' },
|
|
1457
|
+
baseReady && supported && !parquetReady
|
|
1458
|
+
? button(t('pythonInstallParquet'), () => prepare(['parquet']), { disabled: job?.state === 'running' })
|
|
1459
|
+
: null,
|
|
1460
|
+
removePack === 'parquet'
|
|
1461
|
+
? h('span', { className: 'capital-config-runtime-actions' },
|
|
1462
|
+
h('span', { className: 'capital-config-runtime-copy' }, t('pythonRemoveConfirm')),
|
|
1463
|
+
button(t('pythonRemoveYes'), () => remove('parquet'), { danger: true, disabled: busy }),
|
|
1464
|
+
button(t('pythonCancel'), () => setRemovePack(''), { disabled: busy }),
|
|
1465
|
+
)
|
|
1466
|
+
: parquetReady ? button(t('pythonRemove'), () => setRemovePack('parquet'), { disabled: busy || job?.state === 'running' }) : null,
|
|
1467
|
+
),
|
|
1468
|
+
),
|
|
1469
|
+
error === '' ? null : h('p', { className: 'capital-config-runtime-error', role: 'alert' }, error),
|
|
1470
|
+
notice === '' ? null : h('p', { className: 'capital-config-runtime-notice', role: 'status' }, notice),
|
|
1471
|
+
job === null ? null : h('div', { className: 'capital-config-runtime-card' },
|
|
1472
|
+
h('p', { className: 'capital-config-runtime-copy', role: 'status' }, t('pythonJob', { stage: job.stage, message: job.message })),
|
|
1473
|
+
job.state === 'running' ? h('div', { className: 'capital-config-runtime-actions' }, button(t('pythonCancel'), cancel, { disabled: busy })) : null,
|
|
1474
|
+
),
|
|
1475
|
+
)
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1216
1478
|
function CapitalCard(props) {
|
|
1217
1479
|
const t = props.t
|
|
1218
1480
|
const state = props.useCapitalCard((snapshot) => snapshot)
|
|
@@ -1583,6 +1845,7 @@ function CapitalCard(props) {
|
|
|
1583
1845
|
{ value: 'automation', label: t('automationTitle') },
|
|
1584
1846
|
{ value: 'skills', label: t('selectedSkillsTitle') },
|
|
1585
1847
|
{ value: 'components', label: withCount(t('componentsTitle'), state.components?.count) },
|
|
1848
|
+
{ value: 'analysis', label: t('pythonTitle') },
|
|
1586
1849
|
]
|
|
1587
1850
|
const panel = (value, children) => h('section', {
|
|
1588
1851
|
id: `${TABS_ID}-${value}-panel`,
|
|
@@ -1618,6 +1881,7 @@ function CapitalCard(props) {
|
|
|
1618
1881
|
)]),
|
|
1619
1882
|
// The panel is the host's rows list; keep the aria-controls target non-empty via sr-only.
|
|
1620
1883
|
panel('components', [h('span', { className: 'capital-config-sr-only' }, t('componentsHint'))]),
|
|
1884
|
+
panel('analysis', [h(PythonRuntimeSection, { t })]),
|
|
1621
1885
|
clearCacheOpen ? h(ClearCacheModal, {
|
|
1622
1886
|
open: true,
|
|
1623
1887
|
bytes: cacheBytes,
|
package/config/package.json
CHANGED
package/cordis.patch.yml
CHANGED
|
@@ -66,13 +66,20 @@
|
|
|
66
66
|
# Root and role presets mount separately, so apply() runs several times per process. Shared state
|
|
67
67
|
# (chart source tokens, chart artifacts) and the agent/created listeners (root convergence, shell
|
|
68
68
|
# and fs guards) must exist exactly once, which only a host-plane provide gives.
|
|
69
|
-
# These
|
|
70
|
-
#
|
|
69
|
+
# These rows use package subpath entries (/runtime, /python-runtime and /policy): they are
|
|
70
|
+
# server-side, so the literal-path rule above doesn't apply — DSH composes its own
|
|
71
71
|
# @deepseek-ai/dsh-tool-subagent-control rows the same way.
|
|
72
72
|
- insert:
|
|
73
73
|
- id: capital-runtime
|
|
74
74
|
name: '@v587d/capital-generation/runtime'
|
|
75
75
|
|
|
76
|
+
# Plugin-private Python runtime. The row only provides the service and its local HTTP routes;
|
|
77
|
+
# the interpreter and third-party libraries live under the DSH home cache and are installed on
|
|
78
|
+
# demand. Never point this row at the host's dsh-primary-runtime.
|
|
79
|
+
- insert:
|
|
80
|
+
- id: python-runtime
|
|
81
|
+
name: '@v587d/capital-generation/python-runtime'
|
|
82
|
+
|
|
76
83
|
- insert:
|
|
77
84
|
- id: capital-policy
|
|
78
85
|
name: '@v587d/capital-generation/policy'
|
|
@@ -12,7 +12,7 @@ export declare const SIBLING_DENIED_TOOLS: readonly ["interrupt_agent", "list_ag
|
|
|
12
12
|
/** Full intended surface; only names that resolve as host-global are enforced by the allow-list.
|
|
13
13
|
* Scoped family-row tools stay visible regardless; they must remain in this list for review. */
|
|
14
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"];
|
|
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", "cninfo_announcements", "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
16
|
export declare const SPECIALIST_ROLE_TOOLS: readonly ["get_local_datetime", "resolve_data_time_range", "skill", "render_chart"];
|
|
17
17
|
/** Host-global allow-list plus residual per-name denies. */
|
|
18
18
|
export interface RoleSurface {
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Root Agent tool convergence on the root's own scope: preset-level deny would also hit
|
|
3
3
|
* children. Listeners must live on `ctx.root`; tagged standing-scope listeners miss agent/created.
|
|
4
4
|
*/
|
|
5
|
-
/** Outbound tools (search 2 + wind 2 + named sources
|
|
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"];
|
|
5
|
+
/** Outbound tools (search 2 + wind 2 + named sources 12); `ocr` is excluded because only its url form is restricted. */
|
|
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", "cninfo_announcements", "sseinfo_qa", "eastmoney_724", "eastmoney_stock_news", "eastmoney_reports", "eastmoney_announcements", "eastmoney_announcement_body", "sina_reports", "ths_eps_forecast"];
|
|
7
7
|
/** Generic host web entry points; the only outbound surface is web_retriever's named tools. */
|
|
8
8
|
export declare const HOST_WEB_DENIED_TOOLS: readonly ["web_fetch", "anysearch_batch_search", "anysearch_capabilities"];
|
|
9
9
|
export declare const OCR_TOOL_NAME = "ocr";
|
|
@@ -18,7 +18,7 @@ export declare const SHELL_TOOL_NAMES: readonly ["bash", "pwsh"];
|
|
|
18
18
|
* four tools on every Capital agent; the `team:policy` prompt section is host-owned and cannot be
|
|
19
19
|
* removed by a name deny, so Capital intentionally ignores that text. */
|
|
20
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"];
|
|
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", "cninfo_announcements", "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"];
|
|
22
22
|
export declare const CAPITAL_PRESET_ID = "capital-generation";
|
|
23
23
|
interface ToolRestriction {
|
|
24
24
|
allow?: readonly string[];
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { CAPITAL_PRESET_IDS, ROOT_PRESET_ID } from '../preset-ids.js';
|
|
6
6
|
import { readPresetClaim } from '../preset-claim.js';
|
|
7
|
-
/** Outbound tools (search 2 + wind 2 + named sources
|
|
7
|
+
/** Outbound tools (search 2 + wind 2 + named sources 12); `ocr` is excluded because only its url form is restricted. */
|
|
8
8
|
export const RETRIEVAL_DENIED_TOOLS = [
|
|
9
9
|
'anysearch_search', 'web_retriever_fetch',
|
|
10
10
|
'wind_docs_announcements', 'wind_docs_news',
|
|
11
|
-
'cls_telegraph', 'wscn_lives', 'cninfo_irm', 'sseinfo_qa',
|
|
11
|
+
'cls_telegraph', 'wscn_lives', 'cninfo_irm', 'cninfo_announcements', 'sseinfo_qa',
|
|
12
12
|
'eastmoney_724', 'eastmoney_stock_news', 'eastmoney_reports',
|
|
13
13
|
'eastmoney_announcements', 'eastmoney_announcement_body',
|
|
14
14
|
'sina_reports', 'ths_eps_forecast',
|
|
@@ -33,6 +33,8 @@ export const CATALOG_TOPIC_LABELS = {
|
|
|
33
33
|
export const CATALOG_TAXONOMY = {
|
|
34
34
|
// quote
|
|
35
35
|
'auction': 'quote',
|
|
36
|
+
'eastmoney_global_kline': 'quote',
|
|
37
|
+
'eastmoney_global_quote': 'quote',
|
|
36
38
|
'eastmoney_sector_rotation': 'quote',
|
|
37
39
|
'ftshare_ashare_quote': 'quote',
|
|
38
40
|
'ftshare_convertible_bond_kline': 'quote',
|
|
@@ -52,6 +54,7 @@ export const CATALOG_TAXONOMY = {
|
|
|
52
54
|
'tencent_ticks': 'quote',
|
|
53
55
|
'tencent_us_index_quote': 'quote',
|
|
54
56
|
'tencent_us_kline': 'quote',
|
|
57
|
+
'tencent_us_prepost_quote': 'quote',
|
|
55
58
|
'tencent_us_quote': 'quote',
|
|
56
59
|
// flow
|
|
57
60
|
'anomaly_list': 'flow',
|
|
@@ -61,6 +64,7 @@ export const CATALOG_TAXONOMY = {
|
|
|
61
64
|
'eastmoney_cashflow_rotation': 'flow',
|
|
62
65
|
'eastmoney_holder_number_snapshot': 'flow',
|
|
63
66
|
'eastmoney_main_capital_snapshot': 'flow',
|
|
67
|
+
'eastmoney_margin_total': 'flow',
|
|
64
68
|
'eastmoney_margin_trading': 'flow',
|
|
65
69
|
'eastmoney_top_buy_sell_market': 'flow',
|
|
66
70
|
'eastmoney_top_buy_sell_ticker': 'flow',
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface PythonEnvOptions {
|
|
2
|
+
pythonDir: string;
|
|
3
|
+
homeDir: string;
|
|
4
|
+
tempDir: string;
|
|
5
|
+
baseEnv?: Record<string, string | undefined>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Minimal environment for the private interpreter. `-I` already ignores PYTHON* variables; this
|
|
9
|
+
* also removes native-loader variables and keeps the child from reading the user's home/config.
|
|
10
|
+
*/
|
|
11
|
+
export declare function pythonChildEnv(options: PythonEnvOptions): Record<string, string>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { delimiter } from 'node:path';
|
|
2
|
+
import { minimalSystemPath } from './platform.js';
|
|
3
|
+
const REMOVE = [
|
|
4
|
+
'PYTHONPATH',
|
|
5
|
+
'PYTHONHOME',
|
|
6
|
+
'PYTHONSTARTUP',
|
|
7
|
+
'PYTHONEXECUTABLE',
|
|
8
|
+
'PYTHONUSERBASE',
|
|
9
|
+
'NODE_OPTIONS',
|
|
10
|
+
];
|
|
11
|
+
const REMOVE_PREFIX = ['PIP_', 'LD_', 'DYLD_'];
|
|
12
|
+
/**
|
|
13
|
+
* Minimal environment for the private interpreter. `-I` already ignores PYTHON* variables; this
|
|
14
|
+
* also removes native-loader variables and keeps the child from reading the user's home/config.
|
|
15
|
+
*/
|
|
16
|
+
export function pythonChildEnv(options) {
|
|
17
|
+
const base = options.baseEnv ?? process.env;
|
|
18
|
+
const env = {};
|
|
19
|
+
for (const [key, value] of Object.entries(base)) {
|
|
20
|
+
if (value === undefined)
|
|
21
|
+
continue;
|
|
22
|
+
if (REMOVE.includes(key) || REMOVE_PREFIX.some((prefix) => key.startsWith(prefix)))
|
|
23
|
+
continue;
|
|
24
|
+
if (key === 'PATH' || key === 'Path')
|
|
25
|
+
continue;
|
|
26
|
+
env[key] = value;
|
|
27
|
+
}
|
|
28
|
+
env.PATH = [options.pythonDir, minimalSystemPath(base)].join(delimiter);
|
|
29
|
+
env.HOME = options.homeDir;
|
|
30
|
+
env.USERPROFILE = options.homeDir;
|
|
31
|
+
env.TMPDIR = options.tempDir;
|
|
32
|
+
env.TEMP = options.tempDir;
|
|
33
|
+
env.TMP = options.tempDir;
|
|
34
|
+
env.PYTHONUTF8 = '1';
|
|
35
|
+
env.PYTHONIOENCODING = 'utf-8';
|
|
36
|
+
env.PYTHONNOUSERSITE = '1';
|
|
37
|
+
env.PYTHONDONTWRITEBYTECODE = '1';
|
|
38
|
+
return env;
|
|
39
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type PythonRuntimeErrorCode = 'unsupported-platform' | 'manifest-invalid' | 'runtime-not-ready' | 'runtime-locked' | 'pnpm-missing' | 'network' | 'not-found' | 'disk-space' | 'permission' | 'probe-failed' | 'timeout' | 'cancelled' | 'pack-invalid' | 'busy' | 'invalid-request' | 'unknown';
|
|
2
|
+
export declare class PythonRuntimeError extends Error {
|
|
3
|
+
readonly code: PythonRuntimeErrorCode;
|
|
4
|
+
readonly diagnostics?: string;
|
|
5
|
+
constructor(code: PythonRuntimeErrorCode, message?: string, diagnostics?: string);
|
|
6
|
+
}
|
|
7
|
+
export declare function isPythonRuntimeError(value: unknown): value is PythonRuntimeError;
|
|
8
|
+
export declare function messageOf(value: unknown): string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const MESSAGES = {
|
|
2
|
+
'unsupported-platform': '当前平台不在 Python 运行时的支持矩阵内。',
|
|
3
|
+
'manifest-invalid': 'Python 运行时 manifest 不可读或字段不合法。',
|
|
4
|
+
'runtime-not-ready': '分析环境尚未准备;请先在设置页准备,或运行 python-runtime CLI。',
|
|
5
|
+
'runtime-locked': '另一个进程正在安装 Python 运行时,请稍后重试。',
|
|
6
|
+
'pnpm-missing': '找不到可用的 pnpm;DSH 的包管理器不可用,无法自动安装运行时。',
|
|
7
|
+
'network': '无法连接 npm registry;请检查网络/代理,或使用离线运行时包。',
|
|
8
|
+
'not-found': '运行时包版本不存在,或当前镜像尚未同步。',
|
|
9
|
+
'disk-space': '磁盘空间不足,无法安装 Python 运行时。',
|
|
10
|
+
'permission': '没有权限写入或执行 Python 运行时缓存目录。',
|
|
11
|
+
'probe-failed': 'Python 运行时自检失败。',
|
|
12
|
+
timeout: 'Python 运行时操作超时。',
|
|
13
|
+
cancelled: 'Python 运行时操作已取消。',
|
|
14
|
+
'pack-invalid': '运行时包内容与 manifest 不一致。',
|
|
15
|
+
busy: '已有另一个 Python 运行时任务在进行。',
|
|
16
|
+
'invalid-request': 'Python 运行时请求不合法。',
|
|
17
|
+
unknown: 'Python 运行时操作失败。',
|
|
18
|
+
};
|
|
19
|
+
export class PythonRuntimeError extends Error {
|
|
20
|
+
code;
|
|
21
|
+
diagnostics;
|
|
22
|
+
constructor(code, message, diagnostics) {
|
|
23
|
+
super(message ?? MESSAGES[code]);
|
|
24
|
+
this.name = 'PythonRuntimeError';
|
|
25
|
+
this.code = code;
|
|
26
|
+
this.diagnostics = diagnostics;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function isPythonRuntimeError(value) {
|
|
30
|
+
return value instanceof PythonRuntimeError;
|
|
31
|
+
}
|
|
32
|
+
export function messageOf(value) {
|
|
33
|
+
return value instanceof Error ? value.message : String(value);
|
|
34
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface InstallLockOptions {
|
|
2
|
+
timeoutMs?: number;
|
|
3
|
+
staleMs?: number;
|
|
4
|
+
heartbeatMs?: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Cross-process install lock for one pack target. The directory itself is the lock; the
|
|
8
|
+
* heartbeat keeps a long download from looking stale, and a crashed owner expires by mtime.
|
|
9
|
+
*/
|
|
10
|
+
export declare function withInstallLock<T>(lockPath: string, fn: () => Promise<T>, options?: InstallLockOptions): Promise<T>;
|
|
11
|
+
export declare function readLockOwner(lockPath: string): Promise<string | undefined>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { mkdir, readFile, rm, stat, utimes, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
import { PythonRuntimeError } from './errors.js';
|
|
5
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
6
|
+
/**
|
|
7
|
+
* Cross-process install lock for one pack target. The directory itself is the lock; the
|
|
8
|
+
* heartbeat keeps a long download from looking stale, and a crashed owner expires by mtime.
|
|
9
|
+
*/
|
|
10
|
+
export async function withInstallLock(lockPath, fn, options = {}) {
|
|
11
|
+
const timeoutMs = options.timeoutMs ?? 15_000;
|
|
12
|
+
const staleMs = options.staleMs ?? 120_000;
|
|
13
|
+
const heartbeatMs = options.heartbeatMs ?? 20_000;
|
|
14
|
+
const started = Date.now();
|
|
15
|
+
for (;;) {
|
|
16
|
+
try {
|
|
17
|
+
await mkdir(lockPath, { recursive: false });
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
const code = error.code;
|
|
22
|
+
if (code !== 'EEXIST')
|
|
23
|
+
throw new PythonRuntimeError('permission', `无法创建运行时安装锁:${lockPath}`, String(error));
|
|
24
|
+
try {
|
|
25
|
+
const info = await stat(lockPath);
|
|
26
|
+
if (Date.now() - info.mtimeMs > staleMs) {
|
|
27
|
+
await rm(lockPath, { recursive: true, force: true });
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// The owner released it between the mkdir failure and stat; retry immediately.
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (Date.now() - started > timeoutMs) {
|
|
36
|
+
throw new PythonRuntimeError('runtime-locked', `等待运行时安装锁超时:${lockPath}`);
|
|
37
|
+
}
|
|
38
|
+
await sleep(250);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const ownerPath = join(lockPath, 'owner.json');
|
|
42
|
+
try {
|
|
43
|
+
await writeFile(ownerPath, JSON.stringify({ pid: process.pid, id: randomUUID(), at: new Date().toISOString() }), 'utf8');
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// The directory lock is authoritative; owner metadata is diagnostic only.
|
|
47
|
+
}
|
|
48
|
+
const heartbeat = setInterval(() => {
|
|
49
|
+
const now = new Date();
|
|
50
|
+
void utimes(lockPath, now, now).catch(() => undefined);
|
|
51
|
+
}, heartbeatMs);
|
|
52
|
+
heartbeat.unref?.();
|
|
53
|
+
try {
|
|
54
|
+
return await fn();
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
clearInterval(heartbeat);
|
|
58
|
+
await rm(lockPath, { recursive: true, force: true }).catch(() => undefined);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export async function readLockOwner(lockPath) {
|
|
62
|
+
try {
|
|
63
|
+
return await readFile(join(lockPath, 'owner.json'), 'utf8');
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
}
|