@nuasite/agent-summary 0.0.3 → 0.0.6
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/README.md +56 -6
- package/package.json +2 -2
- package/{src → tests/cases/unit}/utils.test.ts +16 -8
- package/tests/tsconfig.json +10 -0
package/README.md
CHANGED
|
@@ -1,15 +1,65 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @nuasite/agent-summary
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@nuasite/agent-summary` is a tiny Astro integration that turns your built site into a machine-readable catalog (`AGENTS.md`) for agentic or LLM-driven tooling. During `astro build` it walks every generated HTML page, extracts lightweight metadata, captures redirects, and keeps several machine-friendly blocks in `AGENTS.md` up to date.
|
|
4
|
+
|
|
5
|
+
## What it does
|
|
6
|
+
- Discovers every concrete page emitted by Astro (skipping redirect-only routes).
|
|
7
|
+
- Reads the built HTML, normalizes the title/description, and records prominent headings as contextual breadcrumbs.
|
|
8
|
+
- Serializes each page (and redirect) into JSONL blocks bounded by dedicated `<page_summary*>` markers.
|
|
9
|
+
- Creates `AGENTS.md` if it does not exist, or replaces only the generated blocks when they already exist.
|
|
10
|
+
|
|
11
|
+
The resulting file can be fed directly into embeddings, vector stores, or custom command palettes so an agent always has a fresh summary of your documentation surface.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
4
14
|
|
|
5
15
|
```bash
|
|
6
|
-
bun
|
|
16
|
+
bun add -D @nuasite/agent-summary
|
|
17
|
+
# or: npm install -D @nuasite/agent-summary
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
1. Ensure there is an `AGENTS.md` at the project root (the integration will create one if it is missing).
|
|
22
|
+
2. Register the integration in your `astro.config.mjs`:
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { defineConfig } from 'astro/config'
|
|
26
|
+
import { agentsSummary } from '@nuasite/agent-summary'
|
|
27
|
+
|
|
28
|
+
export default defineConfig({
|
|
29
|
+
integrations: [
|
|
30
|
+
agentsSummary(),
|
|
31
|
+
],
|
|
32
|
+
})
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
3. Run your normal build (`bun run astro build`, `npm run build`, etc.). When the build finishes you should see a log similar to:
|
|
36
|
+
|
|
7
37
|
```
|
|
38
|
+
[agents-summary] Updated AGENTS.md with 42 page entries and 3 redirects.
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Generated blocks
|
|
42
|
+
|
|
43
|
+
`updateAgentsSummary` writes (or updates) sections inside `AGENTS.md`. You can keep anything you like before/between/after them; only the content between `<page_summary>` marker pair is ever rewritten.
|
|
44
|
+
|
|
45
|
+
JSONL excerpt:
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
<page_summary>
|
|
8
49
|
|
|
9
|
-
|
|
50
|
+
{"kind":"page","route":"/docs/getting-started","title":"Getting started","description":"Overview of the quickstart workflow.","headlines":[{"level":"h1","text":"Getting started"},{"level":"h2","text":"Install"}]}
|
|
51
|
+
{"kind":"redirect","route":"/old-path","to":"/docs/getting-started","status":"302"}
|
|
52
|
+
|
|
53
|
+
</page_summary>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Development
|
|
57
|
+
|
|
58
|
+
The package is written in TypeScript and tested with Bun:
|
|
10
59
|
|
|
11
60
|
```bash
|
|
12
|
-
bun
|
|
61
|
+
bun install
|
|
62
|
+
bun test packages/agent-summary/tests/cases/unit/utils.test.ts
|
|
13
63
|
```
|
|
14
64
|
|
|
15
|
-
|
|
65
|
+
`src/agent-summary-integration.ts` contains the integration entry point, while `src/utils.ts` focuses on parsing HTML, detecting redirects, and keeping `AGENTS.md` synchronized.
|
package/package.json
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
"description": "Create simple summary of the project for LLM.",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
|
-
"url": "git+https://github.com/nuasite/
|
|
6
|
+
"url": "git+https://github.com/nuasite/nuasite.git",
|
|
7
7
|
"directory": "packages/agent-summary"
|
|
8
8
|
},
|
|
9
9
|
"license": "Apache-2.0",
|
|
10
|
-
"version": "0.0.
|
|
10
|
+
"version": "0.0.6",
|
|
11
11
|
"module": "src/index.ts",
|
|
12
12
|
"types": "src/index.ts",
|
|
13
13
|
"type": "module",
|
|
@@ -2,9 +2,9 @@ import { afterAll, afterEach, beforeAll, describe, expect, it } from 'bun:test'
|
|
|
2
2
|
import { promises as fs } from 'node:fs'
|
|
3
3
|
import path from 'node:path'
|
|
4
4
|
import os from 'node:os'
|
|
5
|
-
import type { PageMeta, RedirectMeta } from '
|
|
5
|
+
import type { PageMeta, RedirectMeta } from '../../../src/types.ts'
|
|
6
6
|
|
|
7
|
-
const utilsModule = await import('
|
|
7
|
+
const utilsModule = await import('../../../src/utils.ts')
|
|
8
8
|
const {
|
|
9
9
|
decodeEntities,
|
|
10
10
|
sanitize,
|
|
@@ -162,10 +162,19 @@ describe('updateAgentsSummary', () => {
|
|
|
162
162
|
}
|
|
163
163
|
})
|
|
164
164
|
|
|
165
|
+
const blockBody = (content: string, start: string, end: string): string => {
|
|
166
|
+
const startIndex = content.indexOf(start)
|
|
167
|
+
if (startIndex === -1) {
|
|
168
|
+
return ''
|
|
169
|
+
}
|
|
170
|
+
const bodyStart = startIndex + start.length + 2
|
|
171
|
+
const endIndex = content.indexOf(`\n${end}`, bodyStart)
|
|
172
|
+
const body = content.slice(bodyStart, endIndex >= 0 ? endIndex : bodyStart)
|
|
173
|
+
return body.trimEnd()
|
|
174
|
+
}
|
|
175
|
+
|
|
165
176
|
const summaryLines = (content: string): string[] => {
|
|
166
|
-
const
|
|
167
|
-
const bodyEnd = content.indexOf(`\n\n${SUMMARY_END}`)
|
|
168
|
-
const body = content.slice(bodyStart, bodyEnd >= 0 ? bodyEnd : bodyStart)
|
|
177
|
+
const body = blockBody(content, SUMMARY_START, SUMMARY_END)
|
|
169
178
|
return body.length === 0 ? [] : body.split('\n')
|
|
170
179
|
}
|
|
171
180
|
|
|
@@ -193,8 +202,7 @@ describe('updateAgentsSummary', () => {
|
|
|
193
202
|
await updateAgentsSummary(pages, redirects)
|
|
194
203
|
|
|
195
204
|
const content = await fs.readFile(AGENTS_PATH, 'utf8')
|
|
196
|
-
expect(content.
|
|
197
|
-
expect(content.trimEnd().endsWith(`${SUMMARY_END}`)).toBe(true)
|
|
205
|
+
expect(content.includes(SUMMARY_START)).toBe(true)
|
|
198
206
|
|
|
199
207
|
const lines = summaryLines(content)
|
|
200
208
|
expect(lines).toEqual([
|
|
@@ -224,7 +232,7 @@ describe('updateAgentsSummary', () => {
|
|
|
224
232
|
|
|
225
233
|
const content = await fs.readFile(AGENTS_PATH, 'utf8')
|
|
226
234
|
expect(content.startsWith(prefix)).toBe(true)
|
|
227
|
-
expect(content.
|
|
235
|
+
expect(content).toContain(suffix)
|
|
228
236
|
const lines = summaryLines(content)
|
|
229
237
|
expect(lines).toEqual([
|
|
230
238
|
JSON.stringify({ kind: 'page', route: '/', title: 'Home', description: 'Home description', headlines: [] }),
|