You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: workflows/agentic-wiki-writer.md
+31-10Lines changed: 31 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -238,12 +238,21 @@ If there is no `source-map.json` (first run), regenerate all pages.
238
238
239
239
### 3d. Build context and generate content
240
240
241
+
**MANDATORY CONSTRAINTS — read carefully before generating any content:**
242
+
243
+
-**Never generate more than 4 pages per `push-wiki` call.** If there are more than 4 pages to generate, process them in sequential batches of up to 4, calling `push-wiki` once per batch.
244
+
-**Never spawn a sub-agent or background agent to generate pages.** Generate all pages directly in the main conversation loop.
245
+
-**Each page must be kept under 3 KB of markdown.** Keep pages focused and concise.
246
+
-**Each `push-wiki` JSON payload must stay under 30 KB total.** If a batch would exceed 30 KB (including the sidebar), split it into a smaller batch.
247
+
-**If a `push-wiki` call fails with an API error**, it is likely a timeout caused by a large payload. Retry up to 2 times with progressively smaller batches (halving the batch size each retry, minimum 1 page per call). If a single-page call also fails, the error is unrecoverable — report it and stop.
248
+
241
249
For each page that needs regeneration:
242
250
243
251
1. Check MEMORY_DIR for cached summaries of the relevant source files (files named `summary--{path}.md`). If a file's hash matches (stored on the first line as `<!-- hash: ... -->`), use the cached summary to save context window space. If not, read the full file.
244
-
2. For files you read in full, write a condensed summary to MEMORY_DIR as `summary--{path}.md` (replace `/` with `--`). The summary should capture: exports, key types/interfaces, function signatures, class structure, and important constants. Keep summaries under 2KB each. Include the file's content hash on the first line: `<!-- hash: abc123 -->`.
245
-
3. Generate the content for each `*{ ... }*` instruction block, following the **Content Generation Guidelines** below.
246
-
4. Assemble the page: combine static text with generated content, normalizing heading levels (H4→H2, H5→H3, H6→H4 in the output).
252
+
2.**For source files longer than 500 lines**, do not read the entire file. Instead, use `head` to read the first 100 lines (for imports, exports, and top-level types), then use `grep` to find lines containing keywords from the page's instruction block (e.g., function names, class names, config keys), and use `head`/`tail` to read only those surrounding sections. For example: `grep -n "functionName\|ClassName" src/foo.ts | head -20` to locate relevant line numbers, then `head -n 150 src/foo.ts | tail -50` to extract that region.
253
+
3. For files you read in full, write a condensed summary to MEMORY_DIR as `summary--{path}.md` (replace `/` with `--`). The summary should capture: exports, key types/interfaces, function signatures, class structure, and important constants. Keep summaries under 2KB each. Include the file's content hash on the first line: `<!-- hash: abc123 -->`.
254
+
4. Generate the content for each `*{ ... }*` instruction block, following the **Content Generation Guidelines** below.
255
+
5. Assemble the page: combine static text with generated content, normalizing heading levels (H4→H2, H5→H3, H6→H4 in the output).
247
256
248
257
### 3e. Self-review
249
258
@@ -253,22 +262,34 @@ Before finalizing each page, review your generated content against the **Self-Re
253
262
254
263
**Do NOT write wiki page files to disk.** Do NOT create output directories. Do NOT use shell commands to write files.
255
264
256
-
Instead, construct ALL wiki page content as strings and pass them directly to the `push-wiki` safe-output as a single JSON object.
265
+
**Do NOT use sub-agents or background agents for page generation.** Generate all pages directly in the main conversation loop.
257
266
258
-
1. Build a JSON object mapping filenames to markdown content for every page.
259
-
2. Generate `_Sidebar.md` content following the **Sidebar Generation** rules below and include it in the same JSON object.
260
-
3. Pass the complete JSON object to the `push-wiki` safe-output.
267
+
Construct wiki page content as strings and pass them to the `push-wiki` safe-output as JSON objects. **Push in batches of at most 4 pages per call** to avoid API timeouts:
261
268
262
-
The JSON object should look like:
269
+
1. Divide the full list of pages into batches of up to 4 pages each.
270
+
2. For each batch, build a JSON object mapping filenames to markdown content.
271
+
3. Include `_Sidebar.md` (generated following the **Sidebar Generation** rules below) **only in the final batch**.
272
+
4. Before calling `push-wiki`, estimate the total JSON payload size. **If the payload exceeds 30 KB, reduce the batch size** (use 2 pages per call or fewer) until it fits.
273
+
5. Call `push-wiki` once per batch. Proceed to the next batch only after the current call succeeds.
274
+
6.**If a `push-wiki` call fails with an API or timeout error**, halve the current batch size (minimum 1 page per call) and retry up to 2 times. API errors during generation are most often caused by large response payloads, not transient network issues. If a single-page call still fails, the error is unrecoverable — report it and stop.
275
+
276
+
A single-batch JSON object looks like:
263
277
```json
264
278
{
265
279
"Home.md": "Welcome to the project...\n\n## Overview\n...",
0 commit comments