@aiking/bridge-jtg3310 0.0.0-stage → 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/lib/index.js ADDED
@@ -0,0 +1,330 @@
1
+ /**
2
+ * @aiking/bridge-jtg3310 —— JTG/T 3310—2019《公路工程混凝土结构耐久性设计规范》插件
3
+ *
4
+ * 覆盖:第 5 章材料要求(26 条条文 + 11 张表)、6.3 裂缝控制(表 6.3.1)。
5
+ * 数据来自逐页渲染抄录(JSON 见 lib/material.json),模型按表号渲染,不硬编码数值。
6
+ *
7
+ * 边界:不含条文原文;保护层表 6.2.1 在耐久性评定插件(dsh-bd-eval 的 bd_load)中已实现,本插件不重复。
8
+ *
9
+ * @module @aiking/bridge-jtg3310
10
+ */
11
+
12
+ import { readFileSync } from 'node:fs';
13
+ import { fileURLToPath } from 'node:url';
14
+ import { dirname, join } from 'node:path';
15
+ import { defineTool } from '@deepseek-ai/dsh-tools';
16
+
17
+ const name = 'bridge-jtg3310';
18
+ const inject = ['tools', 'systemPrompt', 'skills'];
19
+ const HERE = dirname(fileURLToPath(import.meta.url));
20
+
21
+ function loadJson() {
22
+ try {
23
+ return JSON.parse(readFileSync(join(HERE, 'material.json'), 'utf8'));
24
+ } catch {
25
+ return { chapters: [] };
26
+ }
27
+ }
28
+
29
+ function loadRules() {
30
+ try {
31
+ return readFileSync(join(HERE, '..', 'rules', 'jtg3310.md'), 'utf8');
32
+ } catch {
33
+ return '';
34
+ }
35
+ }
36
+
37
+ const DATA = loadJson();
38
+ const ALL_TABLES = (DATA.chapters || []).flatMap((c) => c.tables || []);
39
+ const ALL_CLAUSES = (DATA.chapters || []).flatMap((c) => c.clauses || []);
40
+
41
+ function findTable(keyword) {
42
+ if (!keyword) return null;
43
+ return ALL_TABLES.find((t) => t.no.replace(/\s/g, '').includes(String(keyword).replace(/\s/g, '')))
44
+ || ALL_TABLES.find((t) => (t.name || '').includes(keyword));
45
+ }
46
+
47
+ function renderTable(t) {
48
+ const L = [];
49
+ L.push(`# ${t.no} ${t.name}`);
50
+ L.push('');
51
+ if (t.pdfPage) L.push(`> PDF 第 ${t.pdfPage} 页${t.printedPage ? ` / 印刷第 ${t.printedPage} 页` : ''}`);
52
+ L.push('');
53
+ const headers = (t.headerRows || []).filter((h) => h && h.some((c) => c));
54
+ const cols = Math.max(...t.rows.map((r) => r.length));
55
+ if (headers.length) {
56
+ for (const h of headers) L.push(`| ${Array.from({ length: cols }, (_, i) => h[i] || '').join(' | ')} |`);
57
+ L.push(`|${Array.from({ length: cols }, () => '---').join('|')}|`);
58
+ }
59
+ for (const r of t.rows) L.push(`| ${Array.from({ length: cols }, (_, i) => (r[i] === null || r[i] === undefined ? '—' : r[i])).join(' | ')} |`);
60
+ if (t.notes) {
61
+ L.push('');
62
+ L.push(`注:${t.notes}`);
63
+ }
64
+ return L.join('\n');
65
+ }
66
+
67
+ let BODY_CACHE = null;
68
+ function loadBody() {
69
+ if (BODY_CACHE) return BODY_CACHE;
70
+ try {
71
+ BODY_CACHE = JSON.parse(readFileSync(join(HERE, 'body.json'), 'utf8'));
72
+ } catch {
73
+ BODY_CACHE = { chapters: [] };
74
+ }
75
+ return BODY_CACHE;
76
+ }
77
+
78
+ function renderAny(t) {
79
+ const L = [];
80
+ L.push(`## ${t.no} ${t.name}`);
81
+ L.push('');
82
+ if (t.pdfPage) L.push(`> PDF 第 ${t.pdfPage} 页`);
83
+ L.push('');
84
+ const rows = t.rows || [];
85
+ if (!rows.length) return L.join('\n');
86
+ const cols = Math.max(...rows.map((r) => r.length));
87
+ if (t.headerRows) {
88
+ for (const h of t.headerRows) L.push(`| ${Array.from({ length: cols }, (_, i) => h[i] || '').join(' | ')} |`);
89
+ L.push(`|${Array.from({ length: cols }, () => '---').join('|')}|`);
90
+ } else {
91
+ L.push(`|${Array.from({ length: cols }, (_, i) => ` 列${i + 1} `).join('|')}|`);
92
+ L.push(`|${Array.from({ length: cols }, () => '---').join('|')}|`);
93
+ }
94
+ for (const r of rows) L.push(`| ${Array.from({ length: cols }, (_, i) => (r[i] === null || r[i] === undefined ? '—' : r[i])).join(' | ')} |`);
95
+ if (t.notes) {
96
+ L.push('');
97
+ L.push(`注:${Array.isArray(t.notes) ? t.notes.join(';') : t.notes}`);
98
+ }
99
+ return L.join('\n');
100
+ }
101
+
102
+ function apply(ctx) {
103
+ ctx.effect(function* () {
104
+ yield ctx.systemPrompt.section({
105
+ name: 'bridge-jtg3310:discipline',
106
+ order: 272,
107
+ text: [
108
+ '## 混凝土结构耐久性设计(JTG/T 3310—2019)纪律',
109
+ '',
110
+ '查材料指标(最低强度等级、水胶比、氯离子、碱含量、抗硫酸盐)、最大裂缝宽度限值时,必须调用 `j3310_table` / `j3310_material` / `j3310_crack`。',
111
+ '**表 5.3.2-1 的最低强度等级按「环境作用等级 × 构件部位」查**,不是只看环境类别;构件分上部(梁板塔)、下部(桥墩涵洞)、承台基础、素混凝土四类,数值不同。',
112
+ '本插件只收录第 5 章材料与 6.3 裂缝控制;**6.2 保护层最小厚度(表 6.2.1)在耐久性评定插件 `bd_load` 中实现**,不要重复查。',
113
+ '已知原文瑕疵:5.3.10 正文引用"表5.3.7"疑为笔误(应为表5.3.10);表5.3.4 表注缺序号 4;表5.3.2-1 的 Ⅳ-D 行 C40 与相邻档趋势不连续。引用时建议以纸质正版复核。',
114
+ ].join('\n'),
115
+ });
116
+ }, 'bridge-jtg3310 discipline');
117
+
118
+ const rules = loadRules();
119
+ if (rules) {
120
+ ctx.effect(function* () {
121
+ yield ctx.skills.register({
122
+ name: 'bridge-jtg3310-durability-design',
123
+ description: '混凝土耐久性设计要点:材料指标(最低强度等级/水胶比/氯离子/碱含量/抗硫酸盐)、最大裂缝宽度限值、与环境作用等级的对应',
124
+ whenToUse: '核对新建或维修工程的混凝土材料指标、裂缝宽度限值是否满足耐久性设计要求时',
125
+ source: 'bundled',
126
+ content: rules,
127
+ invocation: { modelInvocable: true, userInvocable: true },
128
+ });
129
+ }, 'bridge-jtg3310 skill');
130
+ }
131
+
132
+ ctx.tools.register(defineTool({
133
+ name: 'j3310_table',
134
+ description:
135
+ '按 JTG/T 3310—2019 查表:action=list 列出已收录的 11 张表(表号/表名/行数/PDF 页);action=show 用 keyword 指定表号或表名关键字(如"5.3.2-1""裂缝""抗冻")返回整表。'
136
+ + 'action=clause 用 keyword 检索条文原文(第 5 章材料 23 条 + 6.3 裂缝控制 3 条)。',
137
+ parameters: {
138
+ action: { type: 'string', enum: ['list', 'show', 'clause'], description: '查询方式。' },
139
+ keyword: { type: 'string', description: '表号/表名/条文号关键字(show 与 clause 用)。' },
140
+ },
141
+ output: { schema: { type: 'string' }, render: (_a, v) => [{ type: 'text', text: v }] },
142
+ async execute(args) {
143
+ if (args.action === 'list') {
144
+ const L = ['# JTG/T 3310—2019 已收录表格', '', '| 表号 | 表名 | 行数 | PDF 页 |', '|---|---|---|---|'];
145
+ for (const t of ALL_TABLES) L.push(`| ${t.no} | ${t.name} | ${t.rows.length} | ${t.pdfPage || '-'} |`);
146
+ L.push('');
147
+ L.push(`共 ${ALL_TABLES.length} 张表、${ALL_CLAUSES.length} 条条文。`);
148
+ return L.join('\n');
149
+ }
150
+ if (args.action === 'clause') {
151
+ const kw = String(args.keyword || '').trim();
152
+ const hits = ALL_CLAUSES.filter((c) => !kw || c.no.includes(kw) || (c.text || '').includes(kw));
153
+ if (!hits.length) return `未找到条文「${kw}」。已收录:${ALL_CLAUSES.map((c) => c.no).join('、')}`;
154
+ return hits.map((c) => [`## ${c.no}(PDF ${c.pdfPage})`, '', c.text].join('\n')).join('\n\n');
155
+ }
156
+ const t = findTable(args.keyword);
157
+ if (!t) return `未找到表「${args.keyword}」。已收录:${ALL_TABLES.map((x) => `${x.no} ${x.name}`).join(';')}`;
158
+ return renderTable(t);
159
+ },
160
+ }));
161
+
162
+ ctx.tools.register(defineTool({
163
+ name: 'j3310_material',
164
+ description:
165
+ '按 JTG/T 3310—2019 查混凝土材料指标:action=level 给环境作用等级(如"Ⅲ-D")返回表5.3.2-1 中该等级各构件部位的最低强度等级;'
166
+ + 'action=grade 给强度等级(如"C30")返回表5.3.3 的最大水胶比与胶凝材料用量;action=all 汇总返回氯离子含量(表5.3.7)、碱含量(表5.3.8)、抗硫酸盐(表5.3.10)、抗冻(表5.3.5)、抗氯离子渗透(表5.3.6)。'
167
+ + '注意:最低强度等级要按「环境作用等级 × 构件部位」取,不能只看环境类别。',
168
+ parameters: {
169
+ action: { type: 'string', enum: ['level', 'grade', 'all'], description: '查询方式。' },
170
+ level: { type: 'string', description: '环境作用等级,如 Ⅲ-D、Ⅴ-E(level 用)。' },
171
+ grade: { type: 'string', description: '混凝土强度等级,如 C30(grade 用)。' },
172
+ },
173
+ output: { schema: { type: 'string' }, render: (_a, v) => [{ type: 'text', text: v }] },
174
+ async execute(args) {
175
+ const L = [];
176
+ if (args.action === 'level') {
177
+ const t = findTable('5.3.2-1');
178
+ const lv = String(args.level || '').trim().toUpperCase().replace(/\./g, '-');
179
+ if (!t) return '未收录表 5.3.2-1';
180
+ const rows = t.rows.filter((r) => String(r[1] || '').toUpperCase().replace(/\./g, '-') === lv);
181
+ if (!rows.length) return `未找到环境作用等级「${args.level}」。可选:${[...new Set(t.rows.map((r) => r[1]))].join('、')}`;
182
+ L.push(`# 环境作用等级 ${args.level} 的最低强度等级(表 5.3.2-1)`);
183
+ L.push('');
184
+ for (const r of rows) {
185
+ L.push(`- 环境类别:${r[0]}`);
186
+ L.push(` - 预应力混凝土:${r[2]}`);
187
+ L.push(` - 钢筋混凝土·上部结构(梁、板、塔):${r[3]}`);
188
+ L.push(` - 钢筋混凝土·下部结构(桥墩、涵洞):${r[4]}`);
189
+ L.push(` - 钢筋混凝土·下部结构(承台、基础):${r[5]}`);
190
+ L.push(` - 素混凝土:${r[6]}`);
191
+ }
192
+ L.push('');
193
+ L.push('> 表注见 `j3310_table(action=show, keyword="5.3.2-1")`。');
194
+ } else if (args.action === 'grade') {
195
+ const t = findTable('5.3.3');
196
+ const gr = String(args.grade || '').trim().toUpperCase();
197
+ if (!t) return '未收录表 5.3.3';
198
+ const row = t.rows.find((r) => String(r[0] || '').toUpperCase() === gr);
199
+ if (!row) return `未找到强度等级「${args.grade}」。可选:${t.rows.map((r) => r[0]).join('、')}`;
200
+ L.push(`# ${gr} 的水胶比与胶凝材料用量(表 5.3.3)`);
201
+ L.push('');
202
+ L.push(`- 最大水胶比:${row[1]}`);
203
+ L.push(`- 最小胶凝材料用量:${row[2]}`);
204
+ L.push(`- 最大胶凝材料用量:${row[3]}`);
205
+ } else {
206
+ for (const key of ['5.3.7', '5.3.8', '5.3.10', '5.3.5', '5.3.6']) {
207
+ const t = findTable(key);
208
+ if (t) {
209
+ L.push(renderTable(t));
210
+ L.push('');
211
+ }
212
+ }
213
+ }
214
+ return L.join('\n').trim();
215
+ },
216
+ }));
217
+
218
+ ctx.tools.register(defineTool({
219
+ name: 'j3310_crack',
220
+ description:
221
+ '按 JTG/T 3310—2019 表 6.3.1 查最大裂缝宽度限值(mm):给环境作用等级返回该等级下「钢筋混凝土构件」与「B 类预应力混凝土构件」的限值;'
222
+ + '部分档位对预应力构件为"禁止使用"。action=list 列出全部 17 行。',
223
+ parameters: {
224
+ action: { type: 'string', enum: ['level', 'list'], description: '查询方式。' },
225
+ level: { type: 'string', description: '环境作用等级,如 Ⅱ-D、Ⅲ-E(level 用)。' },
226
+ },
227
+ output: { schema: { type: 'string' }, render: (_a, v) => [{ type: 'text', text: v }] },
228
+ async execute(args) {
229
+ const t = findTable('6.3.1');
230
+ if (!t) return '未收录表 6.3.1';
231
+ if (args.action === 'list') return renderTable(t);
232
+ const lv = String(args.level || '').trim().toUpperCase().replace(/\./g, '-');
233
+ const row = t.rows.find((r) => String(r[1] || '').toUpperCase().replace(/\./g, '-') === lv);
234
+ if (!row) return `未找到环境作用等级「${args.level}」。可选:${[...new Set(t.rows.map((r) => r[1]))].join('、')}`;
235
+ return [
236
+ `# 最大裂缝宽度限值(表 6.3.1)· 环境作用等级 ${args.level}`,
237
+ '',
238
+ `- 环境类别:${row[0]}`,
239
+ `- 钢筋混凝土构件:**${row[2]} mm**`,
240
+ `- B 类预应力混凝土构件:**${row[3]}${row[3] === '禁止使用' ? '' : ' mm'}**`,
241
+ ].join('\n');
242
+ },
243
+ }));
244
+ // ---- 4) 第 6 章构造/预应力防护 + 第 8 章防腐蚀附加措施 + 附录 A ----
245
+ ctx.tools.register(defineTool({
246
+ name: 'j3310_rule',
247
+ description:
248
+ '查 JTG/T 3310—2019 第 6 章(一般规定、构造措施、后张预应力防护、预制拼装)、第 8 章(防腐蚀附加措施:涂层钢筋/阻锈剂/表面处理/透水模板/电化学保护)与附录 A(耐久性设计计算方法与参数)的规则。'
249
+ + 'action=rules 列全部含量化值的条文(按节);action=search 按关键字检索;action=clause 按条文号查原文;action=table 按表号查整表;'
250
+ + 'action=pspa 用**后张预应力防护等级**(体内筋 PS1~PS5、锚头 PA1~PA5):列出防护措施类型表、附加防护措施表与 6.5.2/6.5.5 的基本防护组合要求。',
251
+ parameters: {
252
+ action: { type: 'string', enum: ['rules', 'search', 'clause', 'table', 'pspa'], description: '查询方式。' },
253
+ keyword: { type: 'string', description: 'search/clause/table 用关键字或编号。' },
254
+ },
255
+ output: { schema: { type: 'string' }, render: (_a, v) => [{ type: 'text', text: v }] },
256
+ async execute(args) {
257
+ const data = loadBody();
258
+ const chapters = data.chapters || [];
259
+ const allClauses = chapters.flatMap((c) => (c.clauses || []).map((x) => ({ ...x, section: c.title })));
260
+ const allTables = chapters.flatMap((c) => (c.tables || []).map((t) => ({ ...t, section: c.title })));
261
+ const L = [];
262
+
263
+ if (args.action === 'pspa') {
264
+ L.push('# 后张预应力混凝土桥梁防护等级(第 6.5 节)');
265
+ L.push('');
266
+ for (const no of ['6.5.2', '6.5.5']) {
267
+ const c = allClauses.find((x) => x.no === no);
268
+ if (c) {
269
+ L.push(`## 条文 ${c.no}(PDF ${c.pdfPage})`);
270
+ L.push('');
271
+ L.push(c.text);
272
+ L.push('');
273
+ }
274
+ }
275
+ for (const t of allTables.filter((t) => /6\.5\./.test(t.no))) {
276
+ L.push(renderAny(t));
277
+ L.push('');
278
+ }
279
+ L.push('> PS/PA 为防护措施等级编号;具体组合要求以 6.5.2(体内筋)与 6.5.5(锚头)条文为准。');
280
+ } else if (args.action === 'table') {
281
+ const kw = String(args.keyword || '').trim();
282
+ const hits = allTables.filter((t) => !kw || t.no.includes(kw) || (t.name || '').includes(kw));
283
+ if (!hits.length) return `未找到表「${kw}」。已收录:${allTables.map((t) => t.no).join('、')}`;
284
+ for (const t of hits) {
285
+ L.push(renderAny(t));
286
+ L.push('');
287
+ }
288
+ } else if (args.action === 'clause') {
289
+ const kw = String(args.keyword || '').trim();
290
+ const hit = allClauses.find((c) => c.no === kw) || allClauses.find((c) => c.no.startsWith(kw));
291
+ if (!hit) return `未找到条文「${kw}」。示例:${allClauses.slice(0, 8).map((c) => c.no).join('、')}`;
292
+ L.push(`# ${hit.no}(${hit.section}|PDF ${hit.pdfPage})`);
293
+ L.push('');
294
+ L.push(hit.text === null ? '(原文此条在 PDF 中缺失,已标记 uncertain)' : hit.text);
295
+ if (hit.numbers && hit.numbers.length) {
296
+ L.push('');
297
+ L.push(`**量化值**:${hit.numbers.join(';')}`);
298
+ }
299
+ } else if (args.action === 'search') {
300
+ const kw = String(args.keyword || '').trim();
301
+ const hits = allClauses.filter((c) => (c.text || '').includes(kw) || (c.numbers || []).some((n) => String(n).includes(kw)));
302
+ L.push(`# 检索「${kw}」:命中 ${hits.length} 条`);
303
+ L.push('');
304
+ for (const c of hits) {
305
+ L.push(`- **${c.no}**(${c.section}):${(c.text || '').slice(0, 120)}`);
306
+ if (c.numbers && c.numbers.length) L.push(` - 量化值:${c.numbers.join(';')}`);
307
+ }
308
+ } else {
309
+ L.push('# JTG/T 3310 含量化值的条文(第 6、8 章与附录 A)');
310
+ L.push('');
311
+ let total = 0;
312
+ for (const c of chapters) {
313
+ const withNums = (c.clauses || []).filter((x) => x.numbers && x.numbers.length);
314
+ if (!withNums.length) continue;
315
+ L.push(`## ${c.title}`);
316
+ L.push('');
317
+ L.push('| 条文 | 量化值 |');
318
+ L.push('|---|---|');
319
+ for (const x of withNums) L.push(`| ${x.no} | ${x.numbers.join(';')} |`);
320
+ L.push('');
321
+ total += withNums.length;
322
+ }
323
+ L.push(`> 共 ${allClauses.length} 条条文、${total} 条含量化值、${allTables.length} 张表。`);
324
+ }
325
+ return L.join('\n');
326
+ },
327
+ }));
328
+ }
329
+
330
+ export { apply, inject, name };