dsh-industry-research 0.1.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 +19 -0
- package/LICENSE +201 -0
- package/README.es.md +175 -0
- package/README.hi.md +175 -0
- package/README.md +175 -0
- package/README.pt.md +175 -0
- package/README.zh.md +175 -0
- package/THIRD_PARTY_NOTICES.md +21 -0
- package/cordis.patch.yml +44 -0
- package/lib/index.js +2080 -0
- package/lib/types/chain.d.ts +68 -0
- package/lib/types/chain.d.ts.map +1 -0
- package/lib/types/chain.js +88 -0
- package/lib/types/chain.js.map +1 -0
- package/lib/types/company.d.ts +121 -0
- package/lib/types/company.d.ts.map +1 -0
- package/lib/types/company.js +170 -0
- package/lib/types/company.js.map +1 -0
- package/lib/types/config.d.ts +72 -0
- package/lib/types/config.d.ts.map +1 -0
- package/lib/types/config.js +86 -0
- package/lib/types/config.js.map +1 -0
- package/lib/types/engine-bridge.d.ts +68 -0
- package/lib/types/engine-bridge.d.ts.map +1 -0
- package/lib/types/engine-bridge.js +18 -0
- package/lib/types/engine-bridge.js.map +1 -0
- package/lib/types/events.d.ts +79 -0
- package/lib/types/events.d.ts.map +1 -0
- package/lib/types/events.js +13 -0
- package/lib/types/events.js.map +1 -0
- package/lib/types/index.d.ts +58 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +111 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/paths.d.ts +45 -0
- package/lib/types/paths.d.ts.map +1 -0
- package/lib/types/paths.js +93 -0
- package/lib/types/paths.js.map +1 -0
- package/lib/types/report.d.ts +134 -0
- package/lib/types/report.d.ts.map +1 -0
- package/lib/types/report.js +278 -0
- package/lib/types/report.js.map +1 -0
- package/lib/types/sources.d.ts +55 -0
- package/lib/types/sources.d.ts.map +1 -0
- package/lib/types/sources.js +73 -0
- package/lib/types/sources.js.map +1 -0
- package/lib/types/timeline.d.ts +78 -0
- package/lib/types/timeline.d.ts.map +1 -0
- package/lib/types/timeline.js +129 -0
- package/lib/types/timeline.js.map +1 -0
- package/lib/types/toolkit.d.ts +61 -0
- package/lib/types/toolkit.d.ts.map +1 -0
- package/lib/types/toolkit.js +77 -0
- package/lib/types/toolkit.js.map +1 -0
- package/lib/types/tools/company.d.ts +36 -0
- package/lib/types/tools/company.d.ts.map +1 -0
- package/lib/types/tools/company.js +139 -0
- package/lib/types/tools/company.js.map +1 -0
- package/lib/types/tools/map.d.ts +44 -0
- package/lib/types/tools/map.d.ts.map +1 -0
- package/lib/types/tools/map.js +211 -0
- package/lib/types/tools/map.js.map +1 -0
- package/lib/types/tools/report.d.ts +61 -0
- package/lib/types/tools/report.d.ts.map +1 -0
- package/lib/types/tools/report.js +277 -0
- package/lib/types/tools/report.js.map +1 -0
- package/lib/types/tools/track.d.ts +46 -0
- package/lib/types/tools/track.d.ts.map +1 -0
- package/lib/types/tools/track.js +188 -0
- package/lib/types/tools/track.js.map +1 -0
- package/lib/types/version.d.ts +8 -0
- package/lib/types/version.d.ts.map +1 -0
- package/lib/types/version.js +8 -0
- package/lib/types/version.js.map +1 -0
- package/lib/types/web.d.ts +74 -0
- package/lib/types/web.d.ts.map +1 -0
- package/lib/types/web.js +60 -0
- package/lib/types/web.js.map +1 -0
- package/package.json +143 -0
- package/skills/company-research-method/SKILL.md +50 -0
- package/skills/industry-research-method/SKILL.md +57 -0
- package/skills/industry-research-method/references/frameworks.md +42 -0
- package/src/chain.ts +132 -0
- package/src/company.ts +238 -0
- package/src/config.ts +154 -0
- package/src/engine-bridge.ts +62 -0
- package/src/events.ts +82 -0
- package/src/index.ts +139 -0
- package/src/paths.ts +96 -0
- package/src/report.ts +326 -0
- package/src/sources.ts +95 -0
- package/src/timeline.ts +155 -0
- package/src/toolkit.ts +87 -0
- package/src/tools/company.ts +157 -0
- package/src/tools/map.ts +241 -0
- package/src/tools/report.ts +304 -0
- package/src/tools/track.ts +223 -0
- package/src/version.ts +8 -0
- package/src/web.ts +94 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `industry_map` tool: build or update one industry's chain map. The
|
|
3
|
+
* model authors the ChainMap (guided by the industry-research-method skill);
|
|
4
|
+
* the tool validates it (dangling edges, unsourced numbers, illegal tiers),
|
|
5
|
+
* persists `chain.json`, registers seed/web material as citable sources, and
|
|
6
|
+
* lists the explicit gap slots. Called without a `chain` argument it returns
|
|
7
|
+
* the current map plus the registered sources, so the model can iterate.
|
|
8
|
+
* @module dsh-industry-research/tools/map
|
|
9
|
+
*/
|
|
10
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
11
|
+
import { join } from 'node:path';
|
|
12
|
+
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
13
|
+
import { chainGaps, validateChainMap } from "../chain.js";
|
|
14
|
+
import { loadSources, registerSource, saveSources } from "../sources.js";
|
|
15
|
+
import { lookupWeb, requestSignal, webErrorMessage } from "../web.js";
|
|
16
|
+
import { resolveWorkspaceFile } from "../paths.js";
|
|
17
|
+
import { chainPathOf, industryDirOf, notesDirOf, sourcesPathOf, workspaceOf } from "../toolkit.js";
|
|
18
|
+
/** The ChainMap parameter schema (semantic checks live in {@link validateChainMap}). */
|
|
19
|
+
const CHAIN_PARAMETER = {
|
|
20
|
+
type: 'object',
|
|
21
|
+
properties: {
|
|
22
|
+
industry: { type: 'string', required: true, description: '行业显示名' },
|
|
23
|
+
nodes: {
|
|
24
|
+
type: 'array',
|
|
25
|
+
required: true,
|
|
26
|
+
items: {
|
|
27
|
+
type: 'object',
|
|
28
|
+
properties: {
|
|
29
|
+
id: { type: 'string', required: true, description: '节点 id(边引用用,如 upstream-1)' },
|
|
30
|
+
name: { type: 'string', required: true, description: '节点显示名(如 高粱种植)' },
|
|
31
|
+
tier: { type: 'string', enum: ['upstream', 'midstream', 'downstream'], required: true },
|
|
32
|
+
metrics: {
|
|
33
|
+
type: 'array',
|
|
34
|
+
required: true,
|
|
35
|
+
items: {
|
|
36
|
+
type: 'object',
|
|
37
|
+
properties: {
|
|
38
|
+
key: { type: 'string', required: true, description: '指标名(如 市场规模)' },
|
|
39
|
+
value: { type: 'number', description: '数值;缺省即待补槽位' },
|
|
40
|
+
unit: { type: 'string', description: '单位(如 亿元、%)' },
|
|
41
|
+
asOf: { type: 'string', description: '数值截止日期(ISO-8601)' },
|
|
42
|
+
sourceRef: { type: 'string', description: '来源引用:sources.json 的 ref(如 S1)、URL 或工作区路径;有 value 时必填' },
|
|
43
|
+
},
|
|
44
|
+
additionalProperties: false,
|
|
45
|
+
},
|
|
46
|
+
description: '指标槽位:有 value 必须带 sourceRef;无 value 即显式待补',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
additionalProperties: false,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
edges: {
|
|
53
|
+
type: 'array',
|
|
54
|
+
required: true,
|
|
55
|
+
items: {
|
|
56
|
+
type: 'object',
|
|
57
|
+
properties: {
|
|
58
|
+
from: { type: 'string', required: true, description: '源节点 id' },
|
|
59
|
+
to: { type: 'string', required: true, description: '目标节点 id' },
|
|
60
|
+
note: { type: 'string', description: '关系说明(如 原料供应)' },
|
|
61
|
+
},
|
|
62
|
+
additionalProperties: false,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
additionalProperties: false,
|
|
67
|
+
description: '模型撰写的产业链结构图;语义校验(悬空边、无来源数值)由工具执行',
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Build the `industry_map` tool definition.
|
|
71
|
+
* @param ctx - the plugin context (event emission + optional web lookup).
|
|
72
|
+
* @param config - the resolved plugin config.
|
|
73
|
+
* @returns the tool definition to register.
|
|
74
|
+
*/
|
|
75
|
+
export function buildIndustryMapTool(ctx, config) {
|
|
76
|
+
return defineTool({
|
|
77
|
+
name: 'industry_map',
|
|
78
|
+
description: '行业研究员的产业链建图工具:校验并落盘一份产业链结构图(上/中/下游节点 + 边 + 指标槽位),或在不带 chain 时返回当前图与已登记来源。每个有数值的指标必须带来源引用(sourceRef),缺数值的槽位即显式待补;禁止编造数据。仅供研究,不构成投资建议。',
|
|
79
|
+
parameters: {
|
|
80
|
+
industry: { type: 'string', required: true, description: '行业名(作为目录段,如「白酒」)' },
|
|
81
|
+
seed: { type: 'string', description: '自由文本笔记,写入该行业的 notes/ 并登记为来源' },
|
|
82
|
+
seedFiles: { type: 'array', items: { type: 'string' }, description: '工作区内已有笔记/材料文件的相对路径列表,登记为来源' },
|
|
83
|
+
web: { type: 'boolean', description: '是否做 web 辅助检索(默认 true;config.offline 时自动跳过)' },
|
|
84
|
+
chain: CHAIN_PARAMETER,
|
|
85
|
+
},
|
|
86
|
+
output: {
|
|
87
|
+
schema: {
|
|
88
|
+
type: 'object',
|
|
89
|
+
properties: {
|
|
90
|
+
industry: { type: 'string', required: true },
|
|
91
|
+
dir: { type: 'string', required: true },
|
|
92
|
+
chainPath: { type: 'string', required: true },
|
|
93
|
+
updated: { type: 'boolean', required: true },
|
|
94
|
+
chain: { type: 'json', required: true },
|
|
95
|
+
gaps: { type: 'array', items: { type: 'string' }, required: true },
|
|
96
|
+
sources: { type: 'array', items: { type: 'json' }, required: true },
|
|
97
|
+
seedRefs: { type: 'array', items: { type: 'string' }, required: true },
|
|
98
|
+
webDigest: { oneOf: [{ type: 'array', items: { type: 'json' } }, { type: 'null' }], required: true },
|
|
99
|
+
webNote: { oneOf: [{ type: 'string' }, { type: 'null' }], required: true },
|
|
100
|
+
},
|
|
101
|
+
additionalProperties: false,
|
|
102
|
+
},
|
|
103
|
+
render: (_args, value) => {
|
|
104
|
+
const current = value;
|
|
105
|
+
const lines = [
|
|
106
|
+
`行业「${current.industry}」产业链图:${current.updated ? '已校验并写入' : '未更新(仅读取)'} ${current.chainPath}`,
|
|
107
|
+
current.chain === null ? '当前无图:请撰写 chain 后再次调用。' : `节点 ${current.chain.nodes.length} / 边 ${current.chain.edges.length};缺口 ${current.gaps.length} 项。`,
|
|
108
|
+
];
|
|
109
|
+
if (current.gaps.length > 0)
|
|
110
|
+
lines.push(`缺口清单:${current.gaps.join(';')}`);
|
|
111
|
+
if (current.seedRefs.length > 0)
|
|
112
|
+
lines.push(`本次登记来源:${current.seedRefs.join(', ')}(共 ${current.sources.length} 条,可用于 sourceRef)`);
|
|
113
|
+
if (current.webDigest !== null && current.webDigest.length > 0) {
|
|
114
|
+
lines.push(`web 辅助检索 ${current.webDigest.length} 条:${current.webDigest.map(source => source.title ?? source.url).join(';')}`);
|
|
115
|
+
}
|
|
116
|
+
if (current.webNote !== null)
|
|
117
|
+
lines.push(`web 辅助未执行:${current.webNote}`);
|
|
118
|
+
return [{ type: 'text', text: lines.join('\n') }];
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
timeoutMs: Math.max(30_000, config.fetchTimeoutMs * 3),
|
|
122
|
+
async execute(args, exec) {
|
|
123
|
+
const cwd = workspaceOf(exec);
|
|
124
|
+
const { dir, name } = industryDirOf(config, cwd, args.industry);
|
|
125
|
+
const sourcesPath = sourcesPathOf(dir);
|
|
126
|
+
const registry = await loadSources(sourcesPath);
|
|
127
|
+
const now = new Date().toISOString();
|
|
128
|
+
const seedRefs = [];
|
|
129
|
+
if (args.seed !== undefined && args.seed.trim().length > 0) {
|
|
130
|
+
const notesDir = notesDirOf(dir);
|
|
131
|
+
await mkdir(notesDir, { recursive: true });
|
|
132
|
+
const notePath = join(notesDir, `seed-${now.replaceAll(':', '-')}.md`);
|
|
133
|
+
const noteContent = `# 种子笔记(${now})\n\n${args.seed.trim()}\n`;
|
|
134
|
+
await writeFile(notePath, noteContent, 'utf8');
|
|
135
|
+
seedRefs.push(registerSource(registry, notePath, noteContent, now, 'seed note'));
|
|
136
|
+
}
|
|
137
|
+
for (const file of args.seedFiles ?? []) {
|
|
138
|
+
const absolute = resolveWorkspaceFile(cwd, file);
|
|
139
|
+
const content = await readFile(absolute, 'utf8');
|
|
140
|
+
seedRefs.push(registerSource(registry, absolute, content, now, 'seed file'));
|
|
141
|
+
}
|
|
142
|
+
let webDigest = null;
|
|
143
|
+
let webNote = null;
|
|
144
|
+
if (args.web === false) {
|
|
145
|
+
webNote = '调用方指定 web: false';
|
|
146
|
+
}
|
|
147
|
+
else if (config.offline) {
|
|
148
|
+
webNote = 'config.offline 为 true';
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
const web = lookupWeb(ctx);
|
|
152
|
+
if (web === undefined) {
|
|
153
|
+
webNote = 'ctx.web 未挂载(可选能力;不影响建图)';
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
try {
|
|
157
|
+
const outcome = await web.search({ query: `${name} 产业链 上游 中游 下游 结构`, maxResults: 5 }, requestSignal(exec.signal, config.fetchTimeoutMs));
|
|
158
|
+
webDigest = [...outcome.sources];
|
|
159
|
+
for (const source of outcome.sources) {
|
|
160
|
+
const digest = `${source.title ?? ''}\n${source.snippet ?? ''}`;
|
|
161
|
+
seedRefs.push(registerSource(registry, source.url, digest, now, source.title));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
webNote = `web 检索失败:${webErrorMessage(error)}`;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (seedRefs.length > 0)
|
|
170
|
+
await saveSources(sourcesPath, registry);
|
|
171
|
+
const chainPath = chainPathOf(dir);
|
|
172
|
+
let updated = false;
|
|
173
|
+
if (args.chain !== undefined) {
|
|
174
|
+
const candidate = args.chain;
|
|
175
|
+
const problems = validateChainMap(candidate);
|
|
176
|
+
if (problems.length > 0) {
|
|
177
|
+
throw new Error(`chain 校验失败(${problems.length} 项):${problems.join(';')}`);
|
|
178
|
+
}
|
|
179
|
+
await mkdir(dir, { recursive: true });
|
|
180
|
+
await writeFile(chainPath, `${JSON.stringify(candidate, null, 2)}\n`, 'utf8');
|
|
181
|
+
updated = true;
|
|
182
|
+
}
|
|
183
|
+
let current = null;
|
|
184
|
+
try {
|
|
185
|
+
current = JSON.parse(await readFile(chainPath, 'utf8'));
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
if (error.code !== 'ENOENT')
|
|
189
|
+
throw error;
|
|
190
|
+
}
|
|
191
|
+
const gaps = current === null ? ['尚无产业链结构图:请基于 seed 与来源撰写 chain 后再次调用'] : chainGaps(current);
|
|
192
|
+
if (updated && current !== null) {
|
|
193
|
+
const payload = { industry: name, path: chainPath, nodes: current.nodes.length, edges: current.edges.length, gaps: gaps.length };
|
|
194
|
+
ctx.emit('industry-research/map', payload);
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
industry: name,
|
|
198
|
+
dir,
|
|
199
|
+
chainPath,
|
|
200
|
+
updated,
|
|
201
|
+
chain: current,
|
|
202
|
+
gaps,
|
|
203
|
+
sources: registry.items,
|
|
204
|
+
seedRefs,
|
|
205
|
+
webDigest,
|
|
206
|
+
webNote,
|
|
207
|
+
};
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.js","sourceRoot":"","sources":["../../../src/tools/map.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAEnD,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAEzD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAExE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAErE,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,UAAU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AChB,CAAC;YAED,IAAI,OAAO,GAAoB,IAAI,CAAA;YACnC,IAAI,CAAC;gBACH,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC,CAAa,CAAA;YACrE,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ;oBAAE,MAAM,KAAK,CAAA;YACrE,CAAC;YACD,MAAM,IAAI,GAAG,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,qCAAqC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;YAE5F,IAAI,OAAO,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;gBAChC,MAAM,OAAO,GAAoB,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,CAAA;gBACjJ,GAAG,CAAC,IAAI,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAA;YAC5C,CAAC;YAED,OAAO;gBACL,QAAQ,EAAE,IAAI;gBACd,GAAG;gBACH,SAAS;gBACT,OAAO;gBACP,KAAK,EAAE,OAAO;gBACd,IAAI;gBACJ,OAAO,EAAE,QAAQ,CAAC,KAAK;gBACvB,QAAQ;gBACR,SAAS;gBACT,OAAO;aACR,CAAA;QACH,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `industry_report` tool: assemble one industry's report from the
|
|
3
|
+
* workspace artifacts (chain map, timeline, company cards). With a mounted
|
|
4
|
+
* `ctx.researchReport` engine the evidence/sections/claims go to its
|
|
5
|
+
* `assemble` and the sealed directory plus per-claim verdicts come back;
|
|
6
|
+
* without one the builtin fallback renders versioned Markdown
|
|
7
|
+
* (`reports/<YYYYMMDD-HHmmss>/report.md` + `manifest.json` with the
|
|
8
|
+
* source-traceability table) and says so honestly (`engine:
|
|
9
|
+
* 'builtin-fallback'`). The model may author the draft (sections + claims) or
|
|
10
|
+
* leave it to the mechanical auto-draft.
|
|
11
|
+
* @module dsh-industry-research/tools/report
|
|
12
|
+
*/
|
|
13
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
14
|
+
import type { ResolvedConfig } from '../config.js';
|
|
15
|
+
import type { LoadedArtifacts } from '../report.js';
|
|
16
|
+
/** The canonical value returned by `industry_report`. */
|
|
17
|
+
export interface IndustryReportValue {
|
|
18
|
+
industry: string;
|
|
19
|
+
/** Which engine produced the report. */
|
|
20
|
+
engine: 'research-report' | 'builtin-fallback';
|
|
21
|
+
/** Absolute report directory (sealed engine dir or fallback dir). */
|
|
22
|
+
reportDir: string;
|
|
23
|
+
/** Absolute `report.md` path (fallback only; null on the engine path). */
|
|
24
|
+
reportPath: string | null;
|
|
25
|
+
/** Absolute `manifest.json` path (fallback only; null on the engine path). */
|
|
26
|
+
manifestPath: string | null;
|
|
27
|
+
/** SHA-256 of the engine's manifest (engine path only; null on fallback). */
|
|
28
|
+
sealHash: string | null;
|
|
29
|
+
/** Per-claim verdicts (engine path only; null on fallback). */
|
|
30
|
+
verdicts: Array<{
|
|
31
|
+
claimId: string;
|
|
32
|
+
status: 'verified' | 'unverified' | 'contradicted';
|
|
33
|
+
note?: string;
|
|
34
|
+
}> | null;
|
|
35
|
+
/** Claim count of the report. */
|
|
36
|
+
claims: number;
|
|
37
|
+
/** Evidence count of the report. */
|
|
38
|
+
evidence: number;
|
|
39
|
+
/** Artifact-level gaps recorded at assembly. */
|
|
40
|
+
gaps: string[];
|
|
41
|
+
/** ISO-8601 generation time. */
|
|
42
|
+
generatedAt: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Load every artifact a report assembles from. Missing artifacts are gaps,
|
|
46
|
+
* not failures; unreadable ones are gaps with the reason recorded.
|
|
47
|
+
* @param config - resolved plugin config.
|
|
48
|
+
* @param cwd - absolute workspace root.
|
|
49
|
+
* @param industry - validated industry argument.
|
|
50
|
+
* @param companies - optional company-name filter for card inclusion.
|
|
51
|
+
* @returns the loaded artifacts.
|
|
52
|
+
*/
|
|
53
|
+
export declare function loadArtifacts(config: ResolvedConfig, cwd: string, industry: string, companies?: readonly string[]): Promise<LoadedArtifacts>;
|
|
54
|
+
/**
|
|
55
|
+
* Build the `industry_report` tool definition.
|
|
56
|
+
* @param ctx - the plugin context (event emission + optional engine lookup).
|
|
57
|
+
* @param config - the resolved plugin config.
|
|
58
|
+
* @returns the tool definition to register.
|
|
59
|
+
*/
|
|
60
|
+
export declare function buildIndustryReportTool(ctx: Context, config: ResolvedConfig): import("@deepseek-ai/dsh-tools").ToolDefinition;
|
|
61
|
+
//# sourceMappingURL=report.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../../src/tools/report.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAGlD,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,cAAc,CAAA;AAWhE,yDAAyD;AACzD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAA;IAChB,wCAAwC;IACxC,MAAM,EAAE,iBAAiB,GAAG,kBAAkB,CAAA;IAC9C,qEAAqE;IACrE,SAAS,EAAE,MAAM,CAAA;IACjB,0EAA0E;IAC1E,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,8EAA8E;IAC9E,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,6EAA6E;IAC7E,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,+DAA+D;IAC/D,QAAQ,EAAE,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,UAAU,GAAG,YAAY,GAAG,cAAc,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,IAAI,CAAA;IAC9G,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAA;IACd,oCAAoC;IACpC,QAAQ,EAAE,MAAM,CAAA;IAChB,gDAAgD;IAChD,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,gCAAgC;IAChC,WAAW,EAAE,MAAM,CAAA;CACpB;AAgDD;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,eAAe,CAAC,CAkElJ;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,mDAqH3E"}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `industry_report` tool: assemble one industry's report from the
|
|
3
|
+
* workspace artifacts (chain map, timeline, company cards). With a mounted
|
|
4
|
+
* `ctx.researchReport` engine the evidence/sections/claims go to its
|
|
5
|
+
* `assemble` and the sealed directory plus per-claim verdicts come back;
|
|
6
|
+
* without one the builtin fallback renders versioned Markdown
|
|
7
|
+
* (`reports/<YYYYMMDD-HHmmss>/report.md` + `manifest.json` with the
|
|
8
|
+
* source-traceability table) and says so honestly (`engine:
|
|
9
|
+
* 'builtin-fallback'`). The model may author the draft (sections + claims) or
|
|
10
|
+
* leave it to the mechanical auto-draft.
|
|
11
|
+
* @module dsh-industry-research/tools/report
|
|
12
|
+
*/
|
|
13
|
+
import { readdir, readFile } from 'node:fs/promises';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
import { existsSync } from 'node:fs';
|
|
16
|
+
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
17
|
+
import { readCard } from "../company.js";
|
|
18
|
+
import { autoDraft, buildEvidence, reportDirName, validateDraft, writeFallbackReport } from "../report.js";
|
|
19
|
+
import { AUTO_SECTIONS } from "../report.js";
|
|
20
|
+
import { chainPathOf, companyDirOf, industryDirOf, reportsDirOf, timelinePathOf, workspaceOf } from "../toolkit.js";
|
|
21
|
+
import { lookupEngine } from "../engine-bridge.js";
|
|
22
|
+
import { chainGaps } from "../chain.js";
|
|
23
|
+
import { readTimeline } from "../timeline.js";
|
|
24
|
+
/** The draft parameter schema (semantic reference checks live in {@link validateDraft}). */
|
|
25
|
+
const DRAFT_PARAMETER = {
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
title: { type: 'string', description: '报告标题;缺省「<行业> 行业研究报告」' },
|
|
29
|
+
sections: {
|
|
30
|
+
type: 'array',
|
|
31
|
+
required: true,
|
|
32
|
+
items: {
|
|
33
|
+
type: 'object',
|
|
34
|
+
properties: {
|
|
35
|
+
heading: { type: 'string', required: true },
|
|
36
|
+
paragraphs: {
|
|
37
|
+
type: 'array',
|
|
38
|
+
required: true,
|
|
39
|
+
items: {
|
|
40
|
+
type: 'object',
|
|
41
|
+
properties: {
|
|
42
|
+
text: { type: 'string', required: true },
|
|
43
|
+
claimIds: { type: 'array', items: { type: 'string' }, description: '本段引用的 claim id 列表' },
|
|
44
|
+
},
|
|
45
|
+
additionalProperties: false,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
additionalProperties: false,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
claims: {
|
|
53
|
+
type: 'array',
|
|
54
|
+
required: true,
|
|
55
|
+
items: {
|
|
56
|
+
type: 'object',
|
|
57
|
+
properties: {
|
|
58
|
+
id: { type: 'string', required: true, description: 'claim id(如 C1)' },
|
|
59
|
+
text: { type: 'string', required: true, description: '断言内容(数字须与证据一致)' },
|
|
60
|
+
evidenceIds: { type: 'array', items: { type: 'string' }, required: true, description: '支撑证据 id(E-chain / E-timeline / E-company-<slug>)' },
|
|
61
|
+
},
|
|
62
|
+
additionalProperties: false,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
additionalProperties: false,
|
|
67
|
+
description: '模型撰写的报告草稿;缺省时由工具按已有材料机械组装',
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Load every artifact a report assembles from. Missing artifacts are gaps,
|
|
71
|
+
* not failures; unreadable ones are gaps with the reason recorded.
|
|
72
|
+
* @param config - resolved plugin config.
|
|
73
|
+
* @param cwd - absolute workspace root.
|
|
74
|
+
* @param industry - validated industry argument.
|
|
75
|
+
* @param companies - optional company-name filter for card inclusion.
|
|
76
|
+
* @returns the loaded artifacts.
|
|
77
|
+
*/
|
|
78
|
+
export async function loadArtifacts(config, cwd, industry, companies) {
|
|
79
|
+
const { root, dir } = industryDirOf(config, cwd, industry);
|
|
80
|
+
const gaps = [];
|
|
81
|
+
const artifacts = { cards: [], gaps };
|
|
82
|
+
const chainPath = chainPathOf(dir);
|
|
83
|
+
try {
|
|
84
|
+
const content = await readFile(chainPath, 'utf8');
|
|
85
|
+
const map = JSON.parse(content);
|
|
86
|
+
artifacts.chain = { path: chainPath, content, map };
|
|
87
|
+
gaps.push(...chainGaps(map));
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
if (error.code === 'ENOENT') {
|
|
91
|
+
gaps.push('缺少产业链结构图 chain.json(先运行 industry_map)');
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
gaps.push(`chain.json 读取/解析失败:${error instanceof Error ? error.message : String(error)}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const timelinePath = timelinePathOf(dir);
|
|
98
|
+
try {
|
|
99
|
+
const content = await readFile(timelinePath, 'utf8');
|
|
100
|
+
const { entries, corrupt } = await readTimeline(timelinePath);
|
|
101
|
+
if (entries.length > 0) {
|
|
102
|
+
artifacts.timeline = { path: timelinePath, content, entries };
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
gaps.push('timeline.jsonl 为空:尚无政策与动态条目(先运行 industry_track)');
|
|
106
|
+
}
|
|
107
|
+
if (corrupt > 0)
|
|
108
|
+
gaps.push(`timeline.jsonl 有 ${corrupt} 行损坏已跳过`);
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
if (error.code === 'ENOENT') {
|
|
112
|
+
gaps.push('缺少政策与动态 timeline.jsonl(先运行 industry_track)');
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const companiesDir = join(root, 'companies');
|
|
119
|
+
let slugs = [];
|
|
120
|
+
if (companies !== undefined && companies.length > 0) {
|
|
121
|
+
slugs = companies.map(company => companyDirOf(config, cwd, company).slug);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
try {
|
|
125
|
+
slugs = (await readdir(companiesDir, { withFileTypes: true })).filter(entry => entry.isDirectory()).map(entry => entry.name);
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
if (error.code !== 'ENOENT')
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
for (const slug of slugs) {
|
|
133
|
+
const cardJsonPath = join(companiesDir, slug, 'card.json');
|
|
134
|
+
try {
|
|
135
|
+
const content = await readFile(cardJsonPath, 'utf8');
|
|
136
|
+
const card = await readCard(cardJsonPath);
|
|
137
|
+
artifacts.cards.push({ path: cardJsonPath, content, card });
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
if (error.code === 'ENOENT') {
|
|
141
|
+
gaps.push(`公司「${slug}」无速览卡(先运行 company_scan)`);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
gaps.push(`公司「${slug}」的 card.json 读取/解析失败:${error instanceof Error ? error.message : String(error)}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (artifacts.cards.length === 0 && slugs.length === 0) {
|
|
149
|
+
gaps.push('尚无公司速览卡(可选:运行 company_scan 补充公司维度)');
|
|
150
|
+
}
|
|
151
|
+
return artifacts;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Build the `industry_report` tool definition.
|
|
155
|
+
* @param ctx - the plugin context (event emission + optional engine lookup).
|
|
156
|
+
* @param config - the resolved plugin config.
|
|
157
|
+
* @returns the tool definition to register.
|
|
158
|
+
*/
|
|
159
|
+
export function buildIndustryReportTool(ctx, config) {
|
|
160
|
+
return defineTool({
|
|
161
|
+
name: 'industry_report',
|
|
162
|
+
description: '行业研究员的报告组装工具:汇总产业链结构图、政策时间线与公司速览卡,产出可核查的行业研究报告。挂载 ctx.researchReport 引擎时提交其 assemble 封存并回传逐 claim 核查结论;否则走内置降级路径(版本化 Markdown + 来源回溯表,如实标注 engine: builtin-fallback)。数字均须对应来源证据;仅供研究,不构成投资建议。',
|
|
163
|
+
parameters: {
|
|
164
|
+
industry: { type: 'string', required: true, description: '行业名(作为目录段,如「白酒」)' },
|
|
165
|
+
sections: { type: 'array', items: { type: 'string', enum: [...AUTO_SECTIONS] }, description: `自动草稿包含哪些标准小节(${AUTO_SECTIONS.join('/')});提供 draft 时忽略` },
|
|
166
|
+
companies: { type: 'array', items: { type: 'string' }, description: '纳入报告的公司名列表;缺省纳入 companies/ 下全部速览卡' },
|
|
167
|
+
draft: DRAFT_PARAMETER,
|
|
168
|
+
},
|
|
169
|
+
output: {
|
|
170
|
+
schema: {
|
|
171
|
+
type: 'object',
|
|
172
|
+
properties: {
|
|
173
|
+
industry: { type: 'string', required: true },
|
|
174
|
+
engine: { type: 'string', enum: ['research-report', 'builtin-fallback'], required: true },
|
|
175
|
+
reportDir: { type: 'string', required: true },
|
|
176
|
+
reportPath: { oneOf: [{ type: 'string' }, { type: 'null' }], required: true },
|
|
177
|
+
manifestPath: { oneOf: [{ type: 'string' }, { type: 'null' }], required: true },
|
|
178
|
+
sealHash: { oneOf: [{ type: 'string' }, { type: 'null' }], required: true },
|
|
179
|
+
verdicts: { oneOf: [{ type: 'array', items: { type: 'json' } }, { type: 'null' }], required: true },
|
|
180
|
+
claims: { type: 'number', required: true },
|
|
181
|
+
evidence: { type: 'number', required: true },
|
|
182
|
+
gaps: { type: 'array', items: { type: 'string' }, required: true },
|
|
183
|
+
generatedAt: { type: 'string', required: true },
|
|
184
|
+
},
|
|
185
|
+
additionalProperties: false,
|
|
186
|
+
},
|
|
187
|
+
render: (_args, value) => {
|
|
188
|
+
const current = value;
|
|
189
|
+
const lines = current.engine === 'research-report'
|
|
190
|
+
? [
|
|
191
|
+
`行业「${current.industry}」研究报告已经独立核查引擎封存 → ${current.reportDir}`,
|
|
192
|
+
`sealHash:${current.sealHash ?? ''};claims ${current.claims} 条(verified ${(current.verdicts ?? []).filter(verdict => verdict.status === 'verified').length} 条)。`,
|
|
193
|
+
]
|
|
194
|
+
: [
|
|
195
|
+
`行业「${current.industry}」研究报告(builtin-fallback,未经过独立核查引擎)→ ${current.reportPath}`,
|
|
196
|
+
`claims ${current.claims} 条均标记 unverified;来源回溯表见 report.md 附录与 ${current.manifestPath ?? ''}。`,
|
|
197
|
+
];
|
|
198
|
+
if (current.gaps.length > 0)
|
|
199
|
+
lines.push(`缺口声明:${current.gaps.join(';')}`);
|
|
200
|
+
lines.push('仅供研究,不构成投资建议。');
|
|
201
|
+
return [{ type: 'text', text: lines.join('\n') }];
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
timeoutMs: 60_000,
|
|
205
|
+
async execute(args, exec) {
|
|
206
|
+
const cwd = workspaceOf(exec);
|
|
207
|
+
const { dir, name } = industryDirOf(config, cwd, args.industry);
|
|
208
|
+
const generatedAt = new Date().toISOString();
|
|
209
|
+
const artifacts = await loadArtifacts(config, cwd, name, args.companies);
|
|
210
|
+
const evidence = buildEvidence(artifacts, generatedAt);
|
|
211
|
+
const evidenceIds = new Set(evidence.map(item => item.id));
|
|
212
|
+
let draft;
|
|
213
|
+
if (args.draft !== undefined) {
|
|
214
|
+
draft = {
|
|
215
|
+
title: args.draft.title ?? `${name} 行业研究报告`,
|
|
216
|
+
sections: args.draft.sections,
|
|
217
|
+
claims: args.draft.claims,
|
|
218
|
+
};
|
|
219
|
+
const problems = validateDraft(draft, evidenceIds);
|
|
220
|
+
if (problems.length > 0) {
|
|
221
|
+
throw new Error(`draft 校验失败(${problems.length} 项):${problems.join(';')}(已登记证据:${[...evidenceIds].join(', ') || '无'})`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
const sections = (args.sections ?? [...AUTO_SECTIONS]);
|
|
226
|
+
draft = autoDraft(name, artifacts, sections);
|
|
227
|
+
}
|
|
228
|
+
const engine = lookupEngine(ctx);
|
|
229
|
+
let value;
|
|
230
|
+
if (engine !== undefined) {
|
|
231
|
+
const result = await engine.assemble({
|
|
232
|
+
title: draft.title,
|
|
233
|
+
topic: name,
|
|
234
|
+
evidence,
|
|
235
|
+
sections: draft.sections,
|
|
236
|
+
claims: draft.claims,
|
|
237
|
+
});
|
|
238
|
+
value = {
|
|
239
|
+
industry: name,
|
|
240
|
+
engine: 'research-report',
|
|
241
|
+
reportDir: result.reportDir,
|
|
242
|
+
reportPath: null,
|
|
243
|
+
manifestPath: null,
|
|
244
|
+
sealHash: result.sealHash,
|
|
245
|
+
verdicts: result.verdicts,
|
|
246
|
+
claims: draft.claims.length,
|
|
247
|
+
evidence: evidence.length,
|
|
248
|
+
gaps: artifacts.gaps,
|
|
249
|
+
generatedAt,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
const reportsDir = reportsDirOf(dir);
|
|
254
|
+
const dirName = reportDirName(new Date(), candidate => existsSync(join(reportsDir, candidate)));
|
|
255
|
+
const reportDir = join(reportsDir, dirName);
|
|
256
|
+
const { reportPath, manifestPath } = await writeFallbackReport(reportDir, name, draft, evidence, artifacts.gaps, generatedAt);
|
|
257
|
+
value = {
|
|
258
|
+
industry: name,
|
|
259
|
+
engine: 'builtin-fallback',
|
|
260
|
+
reportDir,
|
|
261
|
+
reportPath,
|
|
262
|
+
manifestPath,
|
|
263
|
+
sealHash: null,
|
|
264
|
+
verdicts: null,
|
|
265
|
+
claims: draft.claims.length,
|
|
266
|
+
evidence: evidence.length,
|
|
267
|
+
gaps: artifacts.gaps,
|
|
268
|
+
generatedAt,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
const payload = { industry: name, engine: value.engine, reportDir: value.reportDir, claims: value.claims, evidence: value.evidence };
|
|
272
|
+
ctx.emit('industry-research/report', payload);
|
|
273
|
+
return value;
|
|
274
|
+
},
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
//# sourceMappingURL=report.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report.js","sourceRoot":"","sources":["../../../src/tools/report.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEpC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAEnD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAE1G,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAE5C,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AACnH,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;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AAS,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAA;YACxJ,GAAG,CAAC,IAAI,CAAC,0BAA0B,EAAE,OAAO,CAAC,CAAA;YAC7C,OAAO,KAAK,CAAA;QACd,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `industry_track` tool: track public-source policy and news for one
|
|
3
|
+
* industry through `ctx.web` (never a hand-rolled fetch). Searches per topic,
|
|
4
|
+
* applies the host allow/block lists and the `since` filter, fetches page
|
|
5
|
+
* snapshots for a SHA-256 provenance hash within the configured fetch budget,
|
|
6
|
+
* and merges the surviving entries into `timeline.jsonl` (dedupe by
|
|
7
|
+
* normalized URL, capped by `timelineMaxEntries`). Fails loud when the web
|
|
8
|
+
* capability is unreachable; never fabricates an entry.
|
|
9
|
+
* @module dsh-industry-research/tools/track
|
|
10
|
+
*/
|
|
11
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
12
|
+
import type { ResolvedConfig } from '../config.js';
|
|
13
|
+
import type { TimelineEntry } from '../timeline.js';
|
|
14
|
+
/** The canonical value returned by `industry_track`. */
|
|
15
|
+
export interface IndustryTrackValue {
|
|
16
|
+
industry: string;
|
|
17
|
+
/** Absolute path of `timeline.jsonl`. */
|
|
18
|
+
path: string;
|
|
19
|
+
/** Entries appended by this call. */
|
|
20
|
+
added: TimelineEntry[];
|
|
21
|
+
/** Batch candidates dropped as duplicates of already-tracked URLs. */
|
|
22
|
+
duplicates: number;
|
|
23
|
+
/** Candidates dropped by the source allow/block lists. */
|
|
24
|
+
blocked: number;
|
|
25
|
+
/** Candidates dropped by the `since` filter. */
|
|
26
|
+
tooOld: number;
|
|
27
|
+
/** Sources whose snapshot fetch failed (kept as citation-only entries). */
|
|
28
|
+
fetchFailed: Array<{
|
|
29
|
+
url: string;
|
|
30
|
+
note: string;
|
|
31
|
+
}>;
|
|
32
|
+
/** Total entries retained after the merge. */
|
|
33
|
+
total: number;
|
|
34
|
+
/** Whether the retention cap dropped older entries. */
|
|
35
|
+
truncated: boolean;
|
|
36
|
+
/** Corrupt pre-existing lines skipped while reading the store. */
|
|
37
|
+
corruptSkipped: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Build the `industry_track` tool definition.
|
|
41
|
+
* @param ctx - the plugin context (event emission + optional web lookup).
|
|
42
|
+
* @param config - the resolved plugin config.
|
|
43
|
+
* @returns the tool definition to register.
|
|
44
|
+
*/
|
|
45
|
+
export declare function buildIndustryTrackTool(ctx: Context, config: ResolvedConfig): import("@deepseek-ai/dsh-tools").ToolDefinition;
|
|
46
|
+
//# sourceMappingURL=track.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"track.d.ts","sourceRoot":"","sources":["../../../src/tools/track.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAElD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAMnD,wDAAwD;AACxD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAA;IAChB,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAA;IACZ,qCAAqC;IACrC,KAAK,EAAE,aAAa,EAAE,CAAA;IACtB,sEAAsE;IACtE,UAAU,EAAE,MAAM,CAAA;IAClB,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAA;IACf,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAA;IACd,2EAA2E;IAC3E,WAAW,EAAE,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IACjD,8CAA8C;IAC9C,KAAK,EAAE,MAAM,CAAA;IACb,uDAAuD;IACvD,SAAS,EAAE,OAAO,CAAA;IAClB,kEAAkE;IAClE,cAAc,EAAE,MAAM,CAAA;CACvB;AAuBD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,mDAuJ1E"}
|