@cobola/dsh-geo 0.8.0 → 0.9.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 +30 -0
- package/README.md +20 -2
- package/bin/dsh-geo.js +66 -2
- package/docs/CI.md +1 -1
- package/docs/GENERATORS.md +75 -0
- package/docs/index.json +1 -1
- package/examples/geo-audit.yml +1 -1
- package/examples/geo-baseline.yml +1 -1
- package/lib/generate.js +178 -0
- package/lib/html.js +36 -5
- package/lib/mcp.js +58 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.0 - 2026-11-29
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- Add `generate-llms` and `generate-faq` (CLI) plus `geo_generate_llms` and
|
|
8
|
+
`geo_generate_faq` (MCP): build an llms.txt and FAQPage JSON-LD from the pages
|
|
9
|
+
that were actually crawled.
|
|
10
|
+
- Section extraction now groups each heading with the prose and lists that
|
|
11
|
+
follow it, which both generators read.
|
|
12
|
+
|
|
13
|
+
### Fixes
|
|
14
|
+
|
|
15
|
+
- The content container is now the largest `<article>`/`<main>` rather than the
|
|
16
|
+
first one. A decorative card placed before the real content used to make a
|
|
17
|
+
content-rich page look like a JavaScript shell (journal123.com scored 79.3
|
|
18
|
+
instead of 71.9 after this fix, because the false "content depends on
|
|
19
|
+
JavaScript" finding disappeared).
|
|
20
|
+
|
|
21
|
+
### Boundaries
|
|
22
|
+
|
|
23
|
+
- Both generators only extract: llms.txt sections come from real headings and
|
|
24
|
+
anchors, FAQ answers are each section's own prose, and a missing meta
|
|
25
|
+
description is stated rather than invented.
|
|
26
|
+
- A site with no question-shaped heading that has a real answer yields no FAQ
|
|
27
|
+
document (exit code 4) instead of a fabricated one.
|
|
28
|
+
- Both outputs state that Google Search does not use llms.txt, and that Google
|
|
29
|
+
restricted FAQ rich results to authoritative government and health sites in
|
|
30
|
+
August 2023.
|
|
31
|
+
|
|
32
|
+
|
|
3
33
|
## 0.8.0 - 2026-11-29
|
|
4
34
|
|
|
5
35
|
### Features
|
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
| 会话内结果卡 | 模型调用 `geo_scan` / `geo_fix_plan` 后,对话中直接显示分数、五维、平台参考分与优先修复,不用另开页面 |
|
|
24
24
|
| `geo_fix_plan`(DSH 工具) | 把最近一次(或指定的)报告变成按影响力排序的修复清单 |
|
|
25
25
|
| **设置 → GEO 体检**(面板) | 修改抓取页数、robots 策略、限速、超时、体积上限、报告目录、私有目标开关 |
|
|
26
|
-
| CLI(`dsh-geo`) | `scan` / `ci` / `mcp` / `fix-plan` / `history` / `diff
|
|
26
|
+
| CLI(`dsh-geo`) | `scan` / `ci` / `mcp` / `generate-llms` / `generate-faq` / `fix-plan` / `history` / `diff` |
|
|
27
27
|
| MCP server | `npx -y @cobola/dsh-geo mcp`,给 Cursor / Claude Code 等客户端直接调用 |
|
|
28
28
|
|
|
29
29
|
报告固定在会话工作区的 `.dsh-geo/` 下;报告可能包含页面正文摘录,上传 CI artifact 前请先审阅内容:
|
|
@@ -167,7 +167,7 @@ dsh-geo ci https://journal123.com \
|
|
|
167
167
|
|
|
168
168
|
```yaml
|
|
169
169
|
- uses: actions/checkout@v4
|
|
170
|
-
- uses: cobola/dsh-geo@v0.
|
|
170
|
+
- uses: cobola/dsh-geo@v0.9.0
|
|
171
171
|
with:
|
|
172
172
|
url: https://journal123.com
|
|
173
173
|
baseline: geo-baseline.json
|
|
@@ -201,6 +201,22 @@ CLI 也随 npm 包提供:`npx @cobola/dsh-geo --help`;完整参数见 `dsh-g
|
|
|
201
201
|
|
|
202
202
|
45 条可审计检查,维度内按权重归一化;`pass` 计 1、`warn` 计 0.5、`fail` 计 0、`skip` 移出分母。总分是五维加权平均。完整规则、阈值与修复建议见 **[docs/RULES.md](docs/RULES.md)**(由 `lib/rules.js` 生成)。
|
|
203
203
|
|
|
204
|
+
### 内容生成器(可选)
|
|
205
|
+
|
|
206
|
+
```sh
|
|
207
|
+
dsh-geo generate-llms https://journal123.com --out llms.txt
|
|
208
|
+
dsh-geo generate-faq https://journal123.com --out faq.json
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
两者都**只从真实抓取的页面里提取**:llms.txt 的分节来自页面真实标题与锚点,FAQ 的答案是那个小节自己的正文。站点没有可用的问句时,不生成 FAQ,退出码 `4`。
|
|
212
|
+
|
|
213
|
+
需要说清楚的两条平台事实,生成的文件里也会写明:
|
|
214
|
+
|
|
215
|
+
- **Google Search 不使用 llms.txt**,它服务于其他 agent 与工具;
|
|
216
|
+
- **Google 在 2023-08 把 FAQ 富媒体结果限制到权威政府/健康站点**,绝大多数站点已拿不到,这段标记仍合法但不再是富媒体机会。
|
|
217
|
+
|
|
218
|
+
细节见 [docs/GENERATORS.md](docs/GENERATORS.md)。
|
|
219
|
+
|
|
204
220
|
### 平台适配:单独计分,不进 Core 总分
|
|
205
221
|
|
|
206
222
|
| Profile | 状态 | 覆盖内容 |
|
|
@@ -263,6 +279,8 @@ lib/ci.js CI 审计、基线与质量门禁
|
|
|
263
279
|
lib/mcp.js stdio MCP server(零依赖手写 JSON-RPC)
|
|
264
280
|
bin/dsh-geo-mcp.js MCP 二进制入口
|
|
265
281
|
docs/MCP.md MCP 用法与协议行为
|
|
282
|
+
docs/GENERATORS.md 生成器:只提取,不编造
|
|
283
|
+
lib/generate.js llms.txt 与 FAQ JSON-LD 生成器
|
|
266
284
|
action.yml GitHub composite action
|
|
267
285
|
lib/score.js 评分聚合(纯函数)
|
|
268
286
|
lib/report.js 报告/修复清单/diff 生成
|
package/bin/dsh-geo.js
CHANGED
|
@@ -27,6 +27,8 @@ Usage:
|
|
|
27
27
|
dsh-geo scan <url> [options]
|
|
28
28
|
dsh-geo ci <url> [options]
|
|
29
29
|
dsh-geo mcp Serve the Model Context Protocol over stdio.
|
|
30
|
+
dsh-geo generate-llms <url> [--out <path>]
|
|
31
|
+
dsh-geo generate-faq <url> [--out <path>]
|
|
30
32
|
dsh-geo fix-plan [options]
|
|
31
33
|
dsh-geo history [options]
|
|
32
34
|
dsh-geo diff <before.json> <after.json> [--json]
|
|
@@ -37,6 +39,15 @@ mcp:
|
|
|
37
39
|
Register it in an MCP client as: npx -y @cobola/dsh-geo mcp
|
|
38
40
|
Reports are written to <cwd>/.dsh-geo/ for the directory you start it in.
|
|
39
41
|
|
|
42
|
+
generate-llms / generate-faq:
|
|
43
|
+
Build content from the pages that were actually crawled. Nothing is invented:
|
|
44
|
+
llms.txt sections come from real headings, and FAQ answers are each
|
|
45
|
+
section's own prose. Google Search does not use llms.txt, and FAQ rich
|
|
46
|
+
results have been limited to authoritative government and health sites since
|
|
47
|
+
August 2023; both outputs say so in their own text.
|
|
48
|
+
Exit code 4 when a FAQ document cannot be built because the site has no
|
|
49
|
+
question-shaped heading with a real answer.
|
|
50
|
+
|
|
40
51
|
ci options (for CI jobs):
|
|
41
52
|
--baseline <path> Compare against a committed baseline report.
|
|
42
53
|
--fail-under <score> Exit 3 when the total is below this score.
|
|
@@ -100,6 +111,7 @@ function defaults() {
|
|
|
100
111
|
jsonFile: null,
|
|
101
112
|
reportFile: null,
|
|
102
113
|
baselineOut: null,
|
|
114
|
+
out: null,
|
|
103
115
|
};
|
|
104
116
|
}
|
|
105
117
|
|
|
@@ -107,6 +119,7 @@ const VALUE_OPTIONS = new Set([
|
|
|
107
119
|
'dir', 'fail-under', 'max-pages', 'now', 'timeout', 'rate-limit',
|
|
108
120
|
'user-agent', 'report', 'limit',
|
|
109
121
|
'baseline', 'max-regression', 'summary-file', 'json-file', 'report-file', 'write-baseline',
|
|
122
|
+
'out',
|
|
110
123
|
]);
|
|
111
124
|
|
|
112
125
|
function parseArgs(argv) {
|
|
@@ -154,6 +167,7 @@ function parseArgs(argv) {
|
|
|
154
167
|
case 'json-file': options.jsonFile = value; break;
|
|
155
168
|
case 'report-file': options.reportFile = value; break;
|
|
156
169
|
case 'write-baseline': options.baselineOut = value; break;
|
|
170
|
+
case 'out': options.out = value; break;
|
|
157
171
|
default: throw new Error(`Unknown option: --${key}`);
|
|
158
172
|
}
|
|
159
173
|
}
|
|
@@ -169,7 +183,7 @@ function validate(options, commandName) {
|
|
|
169
183
|
}
|
|
170
184
|
if (options.now !== null && !Number.isFinite(Date.parse(options.now))) throw new Error(`--now is not a valid ISO time: ${options.now}`);
|
|
171
185
|
if (!Number.isInteger(options.limit) || options.limit < 1) throw new Error('--limit must be a positive integer');
|
|
172
|
-
if (!['scan', 'ci'].includes(commandName) && (options.maxPages !== 6 || options.now !== null || !options.respectRobots
|
|
186
|
+
if (!['scan', 'ci', 'generate-llms', 'generate-faq'].includes(commandName) && (options.maxPages !== 6 || options.now !== null || !options.respectRobots
|
|
173
187
|
|| options.allowPrivate || options.insecureTls || options.timeoutMs !== 10_000 || options.rateLimitMs !== 250)) {
|
|
174
188
|
throw new Error(`Scan-only options are not accepted by "${commandName}"`);
|
|
175
189
|
}
|
|
@@ -408,10 +422,60 @@ async function commandMcp(positionals, options) {
|
|
|
408
422
|
return 0;
|
|
409
423
|
}
|
|
410
424
|
|
|
425
|
+
async function commandGenerate(positionals, options) {
|
|
426
|
+
const kind = options.generateKind;
|
|
427
|
+
if (kind !== 'llms' && kind !== 'faq') throw new Error(`Unknown generator: ${kind}`);
|
|
428
|
+
const url = positionals[0];
|
|
429
|
+
if (!url) throw new Error('Missing <url>');
|
|
430
|
+
|
|
431
|
+
const { auditSite } = await import('../lib/audit.js');
|
|
432
|
+
const { generateLlmsTxt, generateFaqJsonLd, FAQ_NOTE } = await import('../lib/generate.js');
|
|
433
|
+
const { scan } = await auditSite(url, {
|
|
434
|
+
maxPages: options.maxPages,
|
|
435
|
+
respectRobots: options.respectRobots,
|
|
436
|
+
allowPrivate: options.allowPrivate,
|
|
437
|
+
insecureTls: options.insecureTls,
|
|
438
|
+
timeoutMs: options.timeoutMs,
|
|
439
|
+
rateLimitMs: options.rateLimitMs,
|
|
440
|
+
userAgent: options.userAgent,
|
|
441
|
+
now: options.now ?? undefined,
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
if (kind === 'llms') {
|
|
445
|
+
const result = generateLlmsTxt(scan);
|
|
446
|
+
if (options.out) {
|
|
447
|
+
await fs.mkdir(path.dirname(path.resolve(options.out)), { recursive: true });
|
|
448
|
+
await fs.writeFile(path.resolve(options.out), result.content, 'utf8');
|
|
449
|
+
process.stderr.write(`dsh-geo: wrote ${options.out} (${result.links} links from ${result.sourcePages} page(s))\n`);
|
|
450
|
+
} else {
|
|
451
|
+
process.stdout.write(result.content);
|
|
452
|
+
}
|
|
453
|
+
return 0;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
const result = generateFaqJsonLd(scan);
|
|
457
|
+
if (!result.json) {
|
|
458
|
+
process.stderr.write(`dsh-geo: ${result.skipped}\n`);
|
|
459
|
+
return 4;
|
|
460
|
+
}
|
|
461
|
+
const output = `${JSON.stringify(result.json, null, 2)}\n`;
|
|
462
|
+
process.stderr.write(`dsh-geo: ${FAQ_NOTE}\n`);
|
|
463
|
+
if (options.out) {
|
|
464
|
+
await fs.mkdir(path.dirname(path.resolve(options.out)), { recursive: true });
|
|
465
|
+
await fs.writeFile(path.resolve(options.out), output, 'utf8');
|
|
466
|
+
process.stderr.write(`dsh-geo: wrote ${options.out} (${result.items.length} item(s))\n`);
|
|
467
|
+
} else {
|
|
468
|
+
process.stdout.write(output);
|
|
469
|
+
}
|
|
470
|
+
return 0;
|
|
471
|
+
}
|
|
472
|
+
|
|
411
473
|
const COMMANDS = {
|
|
412
474
|
scan: commandScan,
|
|
413
475
|
ci: commandCi,
|
|
414
476
|
mcp: commandMcp,
|
|
477
|
+
'generate-llms': (pos, opts) => commandGenerate(pos, { ...opts, generateKind: 'llms' }),
|
|
478
|
+
'generate-faq': (pos, opts) => commandGenerate(pos, { ...opts, generateKind: 'faq' }),
|
|
415
479
|
'fix-plan': commandFixPlan,
|
|
416
480
|
history: commandHistory,
|
|
417
481
|
diff: commandDiff,
|
|
@@ -447,7 +511,7 @@ async function main(argv) {
|
|
|
447
511
|
validate(parsed.options, name);
|
|
448
512
|
return await handler(positionals, parsed.options);
|
|
449
513
|
} catch (error) {
|
|
450
|
-
const usageError = /Missing <url>|Unexpected argument|Scan-only options|diff needs exactly/.test(error.message);
|
|
514
|
+
const usageError = /Missing <url>|Unexpected argument|Scan-only options|diff needs exactly|Unknown generator/.test(error.message);
|
|
451
515
|
process.stderr.write(`dsh-geo: ${error.message}\n`);
|
|
452
516
|
return usageError ? 2 : 1;
|
|
453
517
|
}
|
package/docs/CI.md
CHANGED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# 内容生成器
|
|
2
|
+
|
|
3
|
+
两个生成器:`generate-llms` 与 `generate-faq`。它们从**实际抓取到的页面**里提取内容,不编造。
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
dsh-geo generate-llms https://journal123.com --out llms.txt
|
|
7
|
+
dsh-geo generate-faq https://journal123.com --out faq.json
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
也可以在 MCP 里调用:`geo_generate_llms`、`geo_generate_faq`。
|
|
11
|
+
|
|
12
|
+
## 为什么不编造
|
|
13
|
+
|
|
14
|
+
生成器的诱惑是“看起来内容更完整”:补一段摘要、凑几条 FAQ。但这个工具的整个前提是**证据可追溯**。如果生成器输出了站点上不存在的文字,那就是在向模型misrepresent 一个站点——这正好是我们在审计里批评的行为。
|
|
15
|
+
|
|
16
|
+
所以两个生成器都只做提取:
|
|
17
|
+
|
|
18
|
+
- **llms.txt 的分节**来自页面真实存在的 `<h2>`/`<h3>`,带真实 `id` 锚点;
|
|
19
|
+
- **FAQ 的答案**是那个小节自己的正文,不是重写的;
|
|
20
|
+
- 页面没有 meta description 时,输出会**明确说明缺失**,而不是编一句;
|
|
21
|
+
- 站点没有“问句式标题 + 真实答案”时,**不生成 FAQ 文档**,退出码 `4`。
|
|
22
|
+
|
|
23
|
+
## llms.txt
|
|
24
|
+
|
|
25
|
+
结构:
|
|
26
|
+
|
|
27
|
+
```text
|
|
28
|
+
# <站点名>
|
|
29
|
+
|
|
30
|
+
> <入口页的 meta description;没有就说明缺失>
|
|
31
|
+
|
|
32
|
+
Note: Google Search does not use this file. ...
|
|
33
|
+
|
|
34
|
+
## Pages
|
|
35
|
+
- [页面标题](URL)
|
|
36
|
+
|
|
37
|
+
## Sections
|
|
38
|
+
- [真实标题](URL#anchor) — 该小节正文摘录
|
|
39
|
+
|
|
40
|
+
## Machine-readable resources
|
|
41
|
+
- [sitemap](URL)
|
|
42
|
+
- [robots.txt](URL)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**重要**:Google Search 明确不使用 `llms.txt`。它服务于其他选择读取它的 agent 与工具。这句话写在生成的文件里,不只是文档里。
|
|
46
|
+
|
|
47
|
+
## FAQ JSON-LD
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{
|
|
51
|
+
"@context": "https://schema.org",
|
|
52
|
+
"@type": "FAQPage",
|
|
53
|
+
"mainEntity": [
|
|
54
|
+
{ "@type": "Question", "name": "...", "acceptedAnswer": { "@type": "Answer", "text": "..." } }
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**重要**:Google 在 2023-08 把 FAQ 富媒体搜索结果限制到权威政府与健康站点,绝大多数站点已不再获得该富媒体结果。这段标记仍然合法、是机器可读结构,但**不是富媒体机会**。这句话同样写在输出里。
|
|
60
|
+
|
|
61
|
+
参考:[Google: HowTo 和常见问题解答富媒体搜索结果方面的变化](https://developers.google.com/search/blog/2023/08/howto-faq-changes)
|
|
62
|
+
|
|
63
|
+
## 边界
|
|
64
|
+
|
|
65
|
+
- 生成器**不修改站点**,只输出文本或 JSON;
|
|
66
|
+
- 不发布、不写入站点仓库,你自己决定放哪里;
|
|
67
|
+
- 不生成内容、不扩充内容、不做“改写优化”;
|
|
68
|
+
- 产物需要人工审阅后再上线。
|
|
69
|
+
|
|
70
|
+
## 退出码
|
|
71
|
+
|
|
72
|
+
| 码 | 含义 |
|
|
73
|
+
|---|---|
|
|
74
|
+
| 0 | 生成成功 |
|
|
75
|
+
| 4 | 无法生成 FAQ(站点没有可用的问句标题与答案) |
|
package/docs/index.json
CHANGED
package/examples/geo-audit.yml
CHANGED
package/lib/generate.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content generators: llms.txt and FAQPage JSON-LD.
|
|
3
|
+
*
|
|
4
|
+
* Both generate from what the audited pages actually contain. Nothing here
|
|
5
|
+
* invents a section, a question, or an answer: a generator that produced text
|
|
6
|
+
* the site does not have would be a way to misrepresent a site to a model, and
|
|
7
|
+
* the audit's whole premise is that evidence must be traceable.
|
|
8
|
+
*
|
|
9
|
+
* Honest scoping, stated in the output itself:
|
|
10
|
+
* - Google Search does not use llms.txt. It is useful for other agents and
|
|
11
|
+
* tools; it is not a Google ranking mechanism.
|
|
12
|
+
* - Google restricted FAQ rich results to authoritative government and health
|
|
13
|
+
* sites in August 2023, so FAQPage markup no longer earns rich results for
|
|
14
|
+
* most sites. It is still valid, machine-readable structure; it is not a
|
|
15
|
+
* rich-result opportunity.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const QUESTION_START = /^(?:how|what|why|when|where|who|which|can|should|do|does|is|are|will)\b|^(?:如何|为何|为什么|怎么|怎样|什么|哪些|哪个|是否|能否)/i;
|
|
19
|
+
|
|
20
|
+
const LLMS_NOTE = 'Note: Google Search does not use this file. It is published for other AI agents and tools that choose to read it.';
|
|
21
|
+
const FAQ_NOTE = 'Note: Google restricted FAQ rich results to authoritative government and health sites in August 2023, so this markup does not earn rich results for most sites. It remains valid, machine-readable structure.';
|
|
22
|
+
|
|
23
|
+
function trimSlash(value) {
|
|
24
|
+
const url = new URL(value);
|
|
25
|
+
url.hash = '';
|
|
26
|
+
let path = url.pathname;
|
|
27
|
+
if (path.length > 1 && path.endsWith('/')) path = path.slice(0, -1);
|
|
28
|
+
return `${url.origin}${path}${url.search}`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function siteName(scan) {
|
|
32
|
+
try {
|
|
33
|
+
const host = new URL(scan.startUrl).hostname.replace(/^\.?www\./, '');
|
|
34
|
+
return host;
|
|
35
|
+
} catch {
|
|
36
|
+
return 'site';
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function pageTitle(page) {
|
|
41
|
+
const title = page.facts?.title ?? '';
|
|
42
|
+
return title.length > 0 ? title : page.path;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function isQuestion(heading) {
|
|
46
|
+
return QUESTION_START.test(heading) || /[??]\s*$/.test(heading);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function firstAnswer(section, maxLength = 320) {
|
|
50
|
+
const text = (section.paragraphs ?? []).join(' ').trim();
|
|
51
|
+
if (text.length === 0) return '';
|
|
52
|
+
return text.length > maxLength ? `${text.slice(0, maxLength)}…` : text;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Build an llms.txt from the audited pages.
|
|
57
|
+
*
|
|
58
|
+
* @param {object} scan - Scan artifact.
|
|
59
|
+
* @param {{maxLinks?: number}} [options]
|
|
60
|
+
* @returns {{content: string, sections: number, links: number, sourcePages: number}}
|
|
61
|
+
*/
|
|
62
|
+
export function generateLlmsTxt(scan, options = {}) {
|
|
63
|
+
const maxLinks = options.maxLinks ?? 60;
|
|
64
|
+
const pages = (scan.pages ?? []).filter((page) => page.facts && page.status === 200);
|
|
65
|
+
const lines = [];
|
|
66
|
+
const name = siteName(scan);
|
|
67
|
+
|
|
68
|
+
lines.push(`# ${name}`);
|
|
69
|
+
lines.push('');
|
|
70
|
+
const primary = pages.find((page) => page.depth === 0) ?? pages[0];
|
|
71
|
+
const description = primary?.facts?.description ?? '';
|
|
72
|
+
if (description) {
|
|
73
|
+
lines.push(`> ${description}`);
|
|
74
|
+
} else {
|
|
75
|
+
// Never invent a summary; state the absence instead.
|
|
76
|
+
lines.push(`> ${name} — generated index. No meta description was found on the entry page, so no summary is provided.`);
|
|
77
|
+
}
|
|
78
|
+
lines.push('');
|
|
79
|
+
lines.push(LLMS_NOTE);
|
|
80
|
+
lines.push('');
|
|
81
|
+
|
|
82
|
+
// Core pages: the entry page plus every crawled page that carries real content.
|
|
83
|
+
const withContent = pages.filter((page) => (page.facts.contentLength ?? page.facts.textLength) >= 200);
|
|
84
|
+
const core = (withContent.length > 0 ? withContent : pages).slice(0, maxLinks);
|
|
85
|
+
|
|
86
|
+
lines.push('## Pages');
|
|
87
|
+
lines.push('');
|
|
88
|
+
for (const page of core) {
|
|
89
|
+
lines.push(`- [${pageTitle(page)}](${trimSlash(page.url)})`);
|
|
90
|
+
}
|
|
91
|
+
if (pages.length > core.length) {
|
|
92
|
+
lines.push(`- … ${pages.length - core.length} more page(s) were crawled but not listed`);
|
|
93
|
+
}
|
|
94
|
+
lines.push('');
|
|
95
|
+
|
|
96
|
+
// Section-level index from the entry page: real headings only.
|
|
97
|
+
if (primary && (primary.facts.sections ?? []).length > 0) {
|
|
98
|
+
const headings = primary.facts.sections.filter((section) => section.level >= 2 && section.heading.length > 0);
|
|
99
|
+
if (headings.length > 0) {
|
|
100
|
+
lines.push('## Sections');
|
|
101
|
+
lines.push('');
|
|
102
|
+
for (const section of headings.slice(0, maxLinks)) {
|
|
103
|
+
const anchor = section.id ? `${trimSlash(primary.url)}#${section.id}` : trimSlash(primary.url);
|
|
104
|
+
const answer = firstAnswer(section, 160);
|
|
105
|
+
lines.push(`- [${section.heading}](${anchor})${answer ? ` — ${answer}` : ''}`);
|
|
106
|
+
}
|
|
107
|
+
lines.push('');
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const sitemap = scan.sitemap?.valid ? scan.sitemap.url : null;
|
|
112
|
+
lines.push('## Machine-readable resources');
|
|
113
|
+
lines.push('');
|
|
114
|
+
if (sitemap) lines.push(`- [sitemap](${trimSlash(sitemap)})`);
|
|
115
|
+
lines.push(`- [robots.txt](${trimSlash(new URL('/robots.txt', scan.origin).href)})`);
|
|
116
|
+
lines.push('');
|
|
117
|
+
|
|
118
|
+
const content = `${lines.join('\n').trimEnd()}\n`;
|
|
119
|
+
return {
|
|
120
|
+
content,
|
|
121
|
+
sections: (content.match(/^## /gm) ?? []).length,
|
|
122
|
+
links: (content.match(/^- \[/gm) ?? []).length,
|
|
123
|
+
sourcePages: core.length,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Build FAQPage JSON-LD from question-shaped headings that have a real answer.
|
|
129
|
+
*
|
|
130
|
+
* Only headings that already exist on a crawled page are used, and each answer
|
|
131
|
+
* is that section's own prose. A site with no question headings yields no
|
|
132
|
+
* document at all rather than a fabricated FAQ.
|
|
133
|
+
*
|
|
134
|
+
* @param {object} scan - Scan artifact.
|
|
135
|
+
* @param {{maxItems?: number}} [options]
|
|
136
|
+
* @returns {{json: object|null, items: Array<{question: string, answer: string, url: string}>, skipped: string|null}}
|
|
137
|
+
*/
|
|
138
|
+
export function generateFaqJsonLd(scan, options = {}) {
|
|
139
|
+
const maxItems = options.maxItems ?? 20;
|
|
140
|
+
const pages = (scan.pages ?? []).filter((page) => page.facts && page.status === 200);
|
|
141
|
+
const items = [];
|
|
142
|
+
|
|
143
|
+
for (const page of pages) {
|
|
144
|
+
for (const section of page.facts.sections ?? []) {
|
|
145
|
+
if (items.length >= maxItems) break;
|
|
146
|
+
if (!isQuestion(section.heading)) continue;
|
|
147
|
+
const answer = firstAnswer(section, 600);
|
|
148
|
+
// A question with no prose is not an FAQ entry; the answer must exist.
|
|
149
|
+
if (answer.length < 30) continue;
|
|
150
|
+
items.push({ question: section.heading, answer, url: trimSlash(page.url) });
|
|
151
|
+
}
|
|
152
|
+
if (items.length >= maxItems) break;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (items.length === 0) {
|
|
156
|
+
return {
|
|
157
|
+
json: null,
|
|
158
|
+
items: [],
|
|
159
|
+
skipped: 'No question-shaped heading with a real answer was found, so no FAQPage document was generated.',
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
json: {
|
|
165
|
+
'@context': 'https://schema.org',
|
|
166
|
+
'@type': 'FAQPage',
|
|
167
|
+
mainEntity: items.map((item) => ({
|
|
168
|
+
'@type': 'Question',
|
|
169
|
+
name: item.question,
|
|
170
|
+
acceptedAnswer: { '@type': 'Answer', text: item.answer },
|
|
171
|
+
})),
|
|
172
|
+
},
|
|
173
|
+
items,
|
|
174
|
+
skipped: null,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export { LLMS_NOTE, FAQ_NOTE, isQuestion };
|
package/lib/html.js
CHANGED
|
@@ -434,6 +434,11 @@ export function analyzeHtml(html, pageUrl) {
|
|
|
434
434
|
const paragraphs = [];
|
|
435
435
|
const snippetCandidates = [];
|
|
436
436
|
const headingIds = [];
|
|
437
|
+
// Sections group a heading with the prose that follows it. They are what the
|
|
438
|
+
// llms.txt and FAQ generators read: both must be able to quote the page, never
|
|
439
|
+
// invent content it does not contain.
|
|
440
|
+
const sections = [];
|
|
441
|
+
let currentSection = null;
|
|
437
442
|
let pendingHeading = null;
|
|
438
443
|
for (const node of nodes) {
|
|
439
444
|
const level = HEADING_LEVEL[node.tag];
|
|
@@ -446,6 +451,8 @@ export function analyzeHtml(html, pageUrl) {
|
|
|
446
451
|
if (id) headingIds.push(id);
|
|
447
452
|
lastHeading = level;
|
|
448
453
|
pendingHeading = headingText;
|
|
454
|
+
currentSection = { level, heading: headingText.slice(0, 300), id, paragraphs: [] };
|
|
455
|
+
sections.push(currentSection);
|
|
449
456
|
continue;
|
|
450
457
|
}
|
|
451
458
|
if (node.tag === 'p') {
|
|
@@ -454,19 +461,42 @@ export function analyzeHtml(html, pageUrl) {
|
|
|
454
461
|
if (!text) continue;
|
|
455
462
|
const words = countWords(text);
|
|
456
463
|
paragraphs.push({ text: text.slice(0, 1000), words, afterHeading: lastHeading });
|
|
464
|
+
if (currentSection) currentSection.paragraphs.push(text.slice(0, 1000));
|
|
457
465
|
if (pendingHeading !== null && words >= 30 && words <= 140) {
|
|
458
466
|
snippetCandidates.push({ heading: pendingHeading.slice(0, 200), words });
|
|
459
467
|
}
|
|
460
468
|
pendingHeading = null;
|
|
461
469
|
}
|
|
470
|
+
// A list or table directly under a heading carries answers too.
|
|
471
|
+
if (currentSection && (node.tag === 'ul' || node.tag === 'ol' || node.tag === 'dl' || node.tag === 'table')) {
|
|
472
|
+
const blockText = textOf(node);
|
|
473
|
+
if (blockText) currentSection.paragraphs.push(blockText.slice(0, 1000));
|
|
474
|
+
}
|
|
462
475
|
}
|
|
463
476
|
|
|
464
477
|
const bodyText = textOf(body ?? doc);
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
478
|
+
|
|
479
|
+
// Picking the first <article>/<main> is wrong on real pages: a card or a
|
|
480
|
+
// decorative wrapper often comes first, which makes a content-rich page look
|
|
481
|
+
// like a JavaScript shell. Take the largest candidate instead, and fall back
|
|
482
|
+
// to the body when no semantic container actually holds the content.
|
|
483
|
+
const containers = [];
|
|
484
|
+
walk(doc, (node) => {
|
|
485
|
+
if (node.tag === 'article' || node.tag === 'main') containers.push(node);
|
|
486
|
+
});
|
|
487
|
+
let contentRoot = null;
|
|
488
|
+
let contentText = '';
|
|
489
|
+
for (const candidate of containers) {
|
|
490
|
+
const text = textOf(candidate);
|
|
491
|
+
if (text.length > contentText.length) {
|
|
492
|
+
contentText = text;
|
|
493
|
+
contentRoot = candidate;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
if (contentText.length < bodyText.length * 0.5) {
|
|
497
|
+
contentRoot = body ?? doc;
|
|
498
|
+
contentText = bodyText;
|
|
499
|
+
}
|
|
470
500
|
const noscriptText = nodes
|
|
471
501
|
.filter((node) => node.tag === 'noscript')
|
|
472
502
|
.map((node) => textOf(node))
|
|
@@ -638,6 +668,7 @@ export function analyzeHtml(html, pageUrl) {
|
|
|
638
668
|
dataNosnippetCount: nodes.filter((node) => node.attrs && 'data-nosnippet' in node.attrs).length,
|
|
639
669
|
metaBingbot: (meta.bingbot ?? '').toLowerCase(),
|
|
640
670
|
questionHeadings,
|
|
671
|
+
sections: sections.filter((section) => section.heading.length > 0),
|
|
641
672
|
snippetBlockCount: snippetCandidates.length,
|
|
642
673
|
// A shell has scripts but no readable structure at all. This is a
|
|
643
674
|
// diagnostic; rules score the actual text length and heading structure.
|
package/lib/mcp.js
CHANGED
|
@@ -56,6 +56,34 @@ export const MCP_TOOLS = [
|
|
|
56
56
|
},
|
|
57
57
|
},
|
|
58
58
|
},
|
|
59
|
+
{
|
|
60
|
+
name: 'geo_generate_llms',
|
|
61
|
+
description:
|
|
62
|
+
'Build an llms.txt from the pages that were actually crawled: the page list and section index come from real headings, and nothing is invented. Google Search does not use llms.txt; the generated file says so. A generator, not a fix: review the output before publishing it.',
|
|
63
|
+
inputSchema: {
|
|
64
|
+
type: 'object',
|
|
65
|
+
properties: {
|
|
66
|
+
url: { type: 'string', description: 'Absolute http(s) URL of the site entry page.' },
|
|
67
|
+
max_pages: { type: 'integer', minimum: 1, maximum: 50, description: 'Pages to crawl (default 6).' },
|
|
68
|
+
now: { type: 'string', description: 'ISO-8601 reference time for freshness checks.' },
|
|
69
|
+
},
|
|
70
|
+
required: ['url'],
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: 'geo_generate_faq',
|
|
75
|
+
description:
|
|
76
|
+
'Build FAQPage JSON-LD from question-shaped headings that already have a real answer on the page. Returns no document when the site has none, instead of fabricating questions. Google restricted FAQ rich results to authoritative government and health sites in August 2023, so this markup does not earn rich results for most sites.',
|
|
77
|
+
inputSchema: {
|
|
78
|
+
type: 'object',
|
|
79
|
+
properties: {
|
|
80
|
+
url: { type: 'string', description: 'Absolute http(s) URL of the site entry page.' },
|
|
81
|
+
max_pages: { type: 'integer', minimum: 1, maximum: 50, description: 'Pages to crawl (default 6).' },
|
|
82
|
+
now: { type: 'string', description: 'ISO-8601 reference time for freshness checks.' },
|
|
83
|
+
},
|
|
84
|
+
required: ['url'],
|
|
85
|
+
},
|
|
86
|
+
},
|
|
59
87
|
{
|
|
60
88
|
name: 'geo_history',
|
|
61
89
|
description: 'List recent saved audits for this workspace, newest first, with totals and grades.',
|
|
@@ -143,6 +171,36 @@ export async function callTool(name, args, context) {
|
|
|
143
171
|
return { content: [{ type: 'text', text: lines.join('\n') }] };
|
|
144
172
|
}
|
|
145
173
|
|
|
174
|
+
if (name === 'geo_generate_llms' || name === 'geo_generate_faq') {
|
|
175
|
+
const url = assertString(input.url, 'url');
|
|
176
|
+
const { scan } = await auditSite(url, {
|
|
177
|
+
maxPages: input.max_pages,
|
|
178
|
+
now: input.now ?? undefined,
|
|
179
|
+
allowPrivate: context.allowPrivate === true,
|
|
180
|
+
insecureTls: context.insecureTls === true,
|
|
181
|
+
});
|
|
182
|
+
const { generateLlmsTxt, generateFaqJsonLd, FAQ_NOTE } = await import('./generate.js');
|
|
183
|
+
if (name === 'geo_generate_llms') {
|
|
184
|
+
const llms = generateLlmsTxt(scan);
|
|
185
|
+
return {
|
|
186
|
+
content: [{
|
|
187
|
+
type: 'text',
|
|
188
|
+
text: `${llms.content}\n---\n${llms.links} link(s) from ${llms.sourcePages} crawled page(s). Review before publishing; this tool does not change the site.`,
|
|
189
|
+
}],
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
const faq = generateFaqJsonLd(scan);
|
|
193
|
+
if (!faq.json) {
|
|
194
|
+
return { content: [{ type: 'text', text: faq.skipped }] };
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
content: [{
|
|
198
|
+
type: 'text',
|
|
199
|
+
text: `${JSON.stringify(faq.json, null, 2)}\n\n${faq.items.length} item(s). ${FAQ_NOTE}`,
|
|
200
|
+
}],
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
146
204
|
if (name === 'geo_history') {
|
|
147
205
|
const limit = input.limit === undefined ? 10 : input.limit;
|
|
148
206
|
if (!Number.isInteger(limit) || limit < 1 || limit > 50) throw new Error('limit must be an integer between 1 and 50');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cobola/dsh-geo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Read-only, reproducible GEO/SEO website audits for DeepSeek Harness: inspect crawlability and citation-ready structure, return evidence and prioritized fixes, and never edit the site or promise rankings.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|