dsh-plain-talk 0.1.14 → 0.1.16
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 +130 -69
- package/README.en.md +36 -18
- package/README.md +36 -18
- package/dsh/check.js +133 -58
- package/dsh/index.js +428 -397
- package/dsh/rules.js +68 -40
- package/dsh/styles.js +209 -0
- package/dsh/vocab-cli.js +196 -0
- package/dsh/vocab-policy.js +620 -0
- package/dsh/vocab-selftest.mjs +90 -0
- package/package.json +55 -56
- package/dsh/vocab.js +0 -229
- package/test/REPORT.md +0 -64
- package/test/bench-result.json +0 -281
- package/test/bench.mjs +0 -172
- package/test/determinism.mjs +0 -21
- package/test/noise.json +0 -58
- package/test/noise.mjs +0 -77
- package/test/rules-v4.mjs +0 -36
- package/test/rules-v4.txt +0 -36
- package/test/selftest.mjs +0 -60
- package/test/v4-check.json +0 -98
- package/test/v4check.mjs +0 -63
package/test/selftest.mjs
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
// 离线自检:不需要模型网关。校验规则正文契约与检查器行为。
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { analyze } from '../dsh/check.js';
|
|
5
|
-
|
|
6
|
-
const root = path.dirname(new URL(import.meta.url).pathname.replace(/^\/([A-Za-z]:)/, '$1'));
|
|
7
|
-
const rulesSrc = fs.readFileSync(path.join(root, '..', 'dsh', 'rules.js'), 'utf8');
|
|
8
|
-
const bt = String.fromCharCode(96);
|
|
9
|
-
const i = rulesSrc.indexOf(bt);
|
|
10
|
-
const j = rulesSrc.indexOf(bt, i + 1);
|
|
11
|
-
const body = rulesSrc.slice(i + 1, j).replace(/\r\n/g, '\n');
|
|
12
|
-
|
|
13
|
-
let pass = 0;
|
|
14
|
-
const fails = [];
|
|
15
|
-
const check = (name, cond, detail = '') => {
|
|
16
|
-
if (cond) pass++;
|
|
17
|
-
else fails.push(name + (detail ? ' :: ' + detail : ''));
|
|
18
|
-
};
|
|
19
|
-
const rulesOf = (t) => analyze(t, { language: 'zh' }).issues.map((x) => x.rule);
|
|
20
|
-
|
|
21
|
-
// 1. 文件与声明
|
|
22
|
-
check('declaration', /export const RULES = `/.test(rulesSrc));
|
|
23
|
-
check('body not empty', body.trim().length > 500, 'len=' + body.length);
|
|
24
|
-
|
|
25
|
-
// 2. 篇幅:不设硬上限,但必须禁止"为短漏步骤"和"为长注水"
|
|
26
|
-
check('no hard cap', !body.includes('默认不超过 12 行') && !body.includes('300 字'));
|
|
27
|
-
check('no hard cap duplicated', body.split('12 行、300 字').length - 1 === 0);
|
|
28
|
-
check('no line-count threshold anywhere', !body.includes('12 行'));
|
|
29
|
-
check('forbids dropping steps for brevity', body.includes('别为短漏关键步骤'));
|
|
30
|
-
check('forbids padding', body.includes('别为长注水'));
|
|
31
|
-
check('conclusion stays first line', body.includes('结论始终在第一行'));
|
|
32
|
-
|
|
33
|
-
// 3. 信息不足时先要,不猜;有可执行替代才给命令
|
|
34
|
-
check('asks for missing input', body.includes('信息不够就直说缺什么'));
|
|
35
|
-
check('no guessing', body.includes('别猜'));
|
|
36
|
-
check('gives runnable alternative', body.includes('命令给出来'));
|
|
37
|
-
|
|
38
|
-
// 4. 清单一条一件事
|
|
39
|
-
check('one item per line', body.includes('一条一件事'));
|
|
40
|
-
check('caps list at five', body.includes('最多 5 条'));
|
|
41
|
-
|
|
42
|
-
// 5. 原有硬性禁令仍在
|
|
43
|
-
check('bans preamble', body.includes('希望这有帮助'));
|
|
44
|
-
check('bans process diary', body.includes('我先…然后…'));
|
|
45
|
-
check('bans backref', body.includes('前者') || body.includes('上述'));
|
|
46
|
-
check('keeps evidence rule', body.includes('原文'));
|
|
47
|
-
check('has checklist call', body.includes('plain_talk_check'));
|
|
48
|
-
|
|
49
|
-
// 6. 检查器行为
|
|
50
|
-
const zhLong = '这是一段用来测试长度规则的中文内容,'.repeat(20);
|
|
51
|
-
check('flags length', rulesOf(zhLong).includes('length'));
|
|
52
|
-
check('flags preamble', rulesOf('好的,我来看看。' + zhLong).includes('preamble'));
|
|
53
|
-
check('flags backref', rulesOf('上述问题已经修复。' + zhLong).includes('backref'));
|
|
54
|
-
check('flags closer', rulesOf('结论:已完成。还需要我做什么?').includes('closer'));
|
|
55
|
-
const clean = analyze('结论:接口从 180ms 降到 96ms。改动是加了 60 秒缓存,命中率 71%。', { language: 'zh' });
|
|
56
|
-
check('clean reply has no error', clean.issues.every((x) => x.severity !== 'error'), JSON.stringify(clean.issues));
|
|
57
|
-
|
|
58
|
-
console.log(`selftest: ${pass} passed, ${fails.length} failed`);
|
|
59
|
-
for (const f of fails) console.log(' FAIL ' + f);
|
|
60
|
-
process.exit(fails.length ? 1 : 0);
|
package/test/v4-check.json
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"id": "f1",
|
|
4
|
-
"arm": "base",
|
|
5
|
-
"text": "**结论:502 是上游返回了无效响应,504 是上游响应时间超过了 Nginx 的等待上限。**\n\n| 状态码 | 含义 | 常见原因 |\n|--------|------|----------|\n| **502 Bad Gateway** | Nginx 作为网关/代理,从上游服务器(如 PHP-FPM、Node、后端服务)收到了**无效或无法解析的响应**。 | 上游进程崩溃、端口不通、返回了非 HTTP 格式数据、连接被重置。 |\n| **504 Gateway Timeout** | Nginx 等待上游服务器响应**超时**,上游没在规定时间内返回完整响应。 | 上游处理太慢、数据库查询阻塞、`proxy_read_timeout` / `fastcgi_read_timeout` 设置过短。 |\n\n**怎么自己确认:**\n- 看 Nginx 错误日志:`tail -f /var/log/nginx/error.log`\n - 502 常见日志:`recv() failed (104: Connection reset by peer)` / `upstream sent invalid header`\n - 504 常见日志:`upstream timed out (110: Connection timed out)`\n\n**一个下一步:**\n先查对应上游服务是否存活且日志正常,再按需调整 Nginx 配置里的 `*_read_timeout` 值。",
|
|
6
|
-
"chars": 645,
|
|
7
|
-
"lines": 11,
|
|
8
|
-
"longestLine": 137,
|
|
9
|
-
"semicolons": 0,
|
|
10
|
-
"numbered": 6,
|
|
11
|
-
"metaTalk": false,
|
|
12
|
-
"fakeSearch": false
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
"id": "f1",
|
|
16
|
-
"arm": "v4",
|
|
17
|
-
"text": "**502 Bad Gateway**:Nginx 从上游服务(如 PHP-FPM、应用服务器)收到了无效响应。\n\n**504 Gateway Timeout**:Nginx 在规定时间内没等到上游服务的响应。\n\n常见原因对比:\n\n| 状态码 | 核心问题 | 典型场景 |\n|--------|----------|----------|\n| 502 | 上游返回了坏响应 | 上游进程崩溃、连接被重置、返回格式错误 |\n| 504 | 上游响应太慢 | 上游处理超时、网络延迟、Nginx 超时设置过短 |\n\n排查方向:\n- 502:检查上游服务是否存活、日志是否有报错、端口是否正确\n- 504:检查上游性能、网络连通性、Nginx 的 `proxy_read_timeout` 等超时配置",
|
|
18
|
-
"chars": 348,
|
|
19
|
-
"lines": 10,
|
|
20
|
-
"longestLine": 56,
|
|
21
|
-
"semicolons": 0,
|
|
22
|
-
"numbered": 4,
|
|
23
|
-
"metaTalk": false,
|
|
24
|
-
"fakeSearch": false
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
"id": "f2",
|
|
28
|
-
"arm": "base",
|
|
29
|
-
"text": "我没有看到任何接口代码或上下文,无法判断需要改哪几处。\n\n把接口的完整代码、文件路径或仓库地址贴出来,我才能给出具体修改点。如果涉及数据库操作,也请一并提供相关表结构。",
|
|
30
|
-
"chars": 84,
|
|
31
|
-
"lines": 2,
|
|
32
|
-
"longestLine": 55,
|
|
33
|
-
"semicolons": 0,
|
|
34
|
-
"numbered": 0,
|
|
35
|
-
"metaTalk": false,
|
|
36
|
-
"fakeSearch": false
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
"id": "f2",
|
|
40
|
-
"arm": "v4",
|
|
41
|
-
"text": "现在不能定位具体改哪几处:缺少接口代码、调用链和表结构;按通用幂等改造,通常落在 5 处。\n\n1. 入口层:接收客户端生成并稳定重传的幂等键,例如 `Idempotency-Key`;要贴路由和 handler 代码。\n\n2. 校验层:校验幂等键必填,并检查同一幂等键的请求体是否一致;要贴请求 DTO 和参数校验代码。\n\n3. 存储层:按场景增加幂等记录表或业务唯一索引,用唯一约束挡住并发重复请求;要贴表结构和现有索引。\n\n4. 服务层:按幂等键区分首次处理、处理中、已完成、参数冲突,并把业务写入和幂等状态写入放进同一事务;要贴 service 实现。\n\n5. 副作用层:重复请求不能重复写库、发 MQ、扣余额或调第三方 API,应返回首次结果;要列出这个接口的所有外部副作用。\n\n贴出这些代码和信息后,我会按具体文件、函数和每处改法列出来。",
|
|
42
|
-
"chars": 374,
|
|
43
|
-
"lines": 7,
|
|
44
|
-
"longestLine": 65,
|
|
45
|
-
"semicolons": 6,
|
|
46
|
-
"numbered": 5,
|
|
47
|
-
"metaTalk": false,
|
|
48
|
-
"fakeSearch": false
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
"id": "f3",
|
|
52
|
-
"arm": "base",
|
|
53
|
-
"text": "无法列出:当前会话没有文件访问权限。下一步:在该目录运行 `find . -type f -name '*.log' -printf '%s\\t%p\\n' | sort -nr`。",
|
|
54
|
-
"chars": 90,
|
|
55
|
-
"lines": 1,
|
|
56
|
-
"longestLine": 90,
|
|
57
|
-
"semicolons": 0,
|
|
58
|
-
"numbered": 0,
|
|
59
|
-
"metaTalk": false,
|
|
60
|
-
"fakeSearch": false
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
"id": "f3",
|
|
64
|
-
"arm": "v4",
|
|
65
|
-
"text": "结论:无法列出目录下 .log 文件,因缺乏本地文件系统访问权限。如有具体路径或权限环境,可使用 `find . -name \"*.log\" -type f -printf \"%s %p\\n\" | sort -n` 自行获取按大小排序的列表。",
|
|
66
|
-
"chars": 121,
|
|
67
|
-
"lines": 1,
|
|
68
|
-
"longestLine": 121,
|
|
69
|
-
"semicolons": 0,
|
|
70
|
-
"numbered": 0,
|
|
71
|
-
"metaTalk": false,
|
|
72
|
-
"fakeSearch": false
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
"id": "f4",
|
|
76
|
-
"arm": "base",
|
|
77
|
-
"text": "本周进展:接口优化已上线,延迟降低约 50%(上线前 → 上线后),遗留问题 1 个尚未解决。\n\n需要补的数字:上线前后延迟的具体数值、遗留问题的具体内容。把这两项发我,我直接填进去给你成稿。",
|
|
78
|
-
"chars": 96,
|
|
79
|
-
"lines": 2,
|
|
80
|
-
"longestLine": 47,
|
|
81
|
-
"semicolons": 0,
|
|
82
|
-
"numbered": 0,
|
|
83
|
-
"metaTalk": false,
|
|
84
|
-
"fakeSearch": false
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
"id": "f4",
|
|
88
|
-
"arm": "v4",
|
|
89
|
-
"text": "接口优化本周已上线,核心接口延迟从平均 180ms 降到 85ms,接近一半。\n\n有一个遗留问题没解决:老版本客户端在特定网络条件下偶发超时,目前还在定位根因,下周一前给结论。",
|
|
90
|
-
"chars": 88,
|
|
91
|
-
"lines": 2,
|
|
92
|
-
"longestLine": 47,
|
|
93
|
-
"semicolons": 0,
|
|
94
|
-
"numbered": 0,
|
|
95
|
-
"metaTalk": false,
|
|
96
|
-
"fakeSearch": false
|
|
97
|
-
}
|
|
98
|
-
]
|
package/test/v4check.mjs
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
// v4 出厂前验证:4 题对比 0.1.12 基线,看篇幅/清单结构/是否乱猜。
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
|
|
4
|
-
const bt = String.fromCharCode(96);
|
|
5
|
-
const bodyOf = (p) => {
|
|
6
|
-
const s = fs.readFileSync(p, 'utf8').replace(/\r\n/g, '\n');
|
|
7
|
-
const i = s.indexOf(bt);
|
|
8
|
-
const j = s.indexOf(bt, i + 1);
|
|
9
|
-
return s.slice(i + 1, j);
|
|
10
|
-
};
|
|
11
|
-
const BASE = bodyOf('C:/Users/lizilong/AppData/Local/Temp/pt-verify/pkg-0.1.10/package/dsh/rules.js');
|
|
12
|
-
const V4 = fs.readFileSync('test/rules-v4.txt', 'utf8');
|
|
13
|
-
|
|
14
|
-
const CASES = [
|
|
15
|
-
['f1', 'Nginx 502 和 504 分别说明什么?'],
|
|
16
|
-
['f2', '帮我把这个接口改成幂等的,先告诉我改哪几处。'],
|
|
17
|
-
['f3', '把这个目录下所有 .log 按大小列出来,只给我结果。'],
|
|
18
|
-
['f4', '给我写一段本周进展,发给老板,就说接口优化上线了、延迟降了一半、有个遗留问题没解决。'],
|
|
19
|
-
];
|
|
20
|
-
|
|
21
|
-
const call = async (system, user) => {
|
|
22
|
-
const res = await fetch('http://127.0.0.1:3425/v1/chat/completions', {
|
|
23
|
-
method: 'POST',
|
|
24
|
-
headers: { 'content-type': 'application/json' },
|
|
25
|
-
body: JSON.stringify({ model: 'group/free', temperature: 0, messages: [{ role: 'system', content: system }, { role: 'user', content: user }] }),
|
|
26
|
-
});
|
|
27
|
-
const j = await res.json();
|
|
28
|
-
return j.choices?.[0]?.message?.content ?? '';
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const stats = (t) => {
|
|
32
|
-
const lines = t.split('\n').filter((l) => l.trim());
|
|
33
|
-
const numbered = lines.filter((l) => /^\s*(\d+[.、)]|[-*])\s?/.test(l)).length;
|
|
34
|
-
return {
|
|
35
|
-
chars: t.length,
|
|
36
|
-
lines: lines.length,
|
|
37
|
-
longestLine: Math.max(...lines.map((l) => l.length)),
|
|
38
|
-
semicolons: (t.match(/;/g) || []).length,
|
|
39
|
-
numbered,
|
|
40
|
-
metaTalk: /(措辞|建议用|示例如下|要不要我)/.test(t),
|
|
41
|
-
fakeSearch: /(没有找到|未找到).{0,6}(文件|目录)/.test(t),
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const rows = [];
|
|
46
|
-
for (const [id, q] of CASES) {
|
|
47
|
-
for (const [arm, rules] of [['base', BASE], ['v4', V4]]) {
|
|
48
|
-
const t = await call(rules, q);
|
|
49
|
-
rows.push({ id, arm, text: t, ...stats(t) });
|
|
50
|
-
process.stdout.write('.');
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
process.stdout.write('\n');
|
|
54
|
-
|
|
55
|
-
for (const id of CASES.map((c) => c[0])) {
|
|
56
|
-
const a = rows.find((r) => r.id === id && r.arm === 'base');
|
|
57
|
-
const b = rows.find((r) => r.id === id && r.arm === 'v4');
|
|
58
|
-
console.log('\n== ' + id);
|
|
59
|
-
for (const [name, r] of [['base', a], ['v4', b]]) {
|
|
60
|
-
console.log(' ' + name + ' chars=' + r.chars + ' lines=' + r.lines + ' longest=' + r.longestLine + ' 分号=' + r.semicolons + ' 条目=' + r.numbered + ' 元话=' + r.metaTalk + ' 假搜索=' + r.fakeSearch);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
fs.writeFileSync('test/v4-check.json', JSON.stringify(rows, null, 2), 'utf8');
|