document360-writer 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.
Files changed (65) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +66 -0
  3. package/dist/agent.d.ts +6 -0
  4. package/dist/agent.js +92 -0
  5. package/dist/agent.js.map +1 -0
  6. package/dist/cli.d.ts +2 -0
  7. package/dist/cli.js +26 -0
  8. package/dist/cli.js.map +1 -0
  9. package/dist/commands/audit.d.ts +2 -0
  10. package/dist/commands/audit.js +12 -0
  11. package/dist/commands/audit.js.map +1 -0
  12. package/dist/commands/clear.d.ts +2 -0
  13. package/dist/commands/clear.js +6 -0
  14. package/dist/commands/clear.js.map +1 -0
  15. package/dist/commands/exit.d.ts +2 -0
  16. package/dist/commands/exit.js +4 -0
  17. package/dist/commands/exit.js.map +1 -0
  18. package/dist/commands/help.d.ts +2 -0
  19. package/dist/commands/help.js +27 -0
  20. package/dist/commands/help.js.map +1 -0
  21. package/dist/commands/index.d.ts +18 -0
  22. package/dist/commands/index.js +38 -0
  23. package/dist/commands/index.js.map +1 -0
  24. package/dist/commands/init.d.ts +2 -0
  25. package/dist/commands/init.js +85 -0
  26. package/dist/commands/init.js.map +1 -0
  27. package/dist/commands/load.d.ts +2 -0
  28. package/dist/commands/load.js +20 -0
  29. package/dist/commands/load.js.map +1 -0
  30. package/dist/commands/mcp.d.ts +2 -0
  31. package/dist/commands/mcp.js +83 -0
  32. package/dist/commands/mcp.js.map +1 -0
  33. package/dist/commands/publish.d.ts +2 -0
  34. package/dist/commands/publish.js +19 -0
  35. package/dist/commands/publish.js.map +1 -0
  36. package/dist/commands/save.d.ts +2 -0
  37. package/dist/commands/save.js +29 -0
  38. package/dist/commands/save.js.map +1 -0
  39. package/dist/commands/screenshot.d.ts +2 -0
  40. package/dist/commands/screenshot.js +20 -0
  41. package/dist/commands/screenshot.js.map +1 -0
  42. package/dist/config.d.ts +40 -0
  43. package/dist/config.js +42 -0
  44. package/dist/config.js.map +1 -0
  45. package/dist/lib/colors.d.ts +8 -0
  46. package/dist/lib/colors.js +10 -0
  47. package/dist/lib/colors.js.map +1 -0
  48. package/dist/lib/messageQueue.d.ts +9 -0
  49. package/dist/lib/messageQueue.js +40 -0
  50. package/dist/lib/messageQueue.js.map +1 -0
  51. package/dist/lib/paths.d.ts +10 -0
  52. package/dist/lib/paths.js +38 -0
  53. package/dist/lib/paths.js.map +1 -0
  54. package/dist/repl.d.ts +5 -0
  55. package/dist/repl.js +132 -0
  56. package/dist/repl.js.map +1 -0
  57. package/package.json +54 -0
  58. package/skills/CLAUDE.md +92 -0
  59. package/skills/analyze-codebase/SKILL.md +35 -0
  60. package/skills/audit-docs/SKILL.md +48 -0
  61. package/skills/emit-screenshot-spec/SKILL.md +82 -0
  62. package/skills/gather-context-from-mcp/SKILL.md +29 -0
  63. package/skills/propose-structure/SKILL.md +51 -0
  64. package/skills/publish-to-d360/SKILL.md +39 -0
  65. package/skills/write-article/SKILL.md +93 -0
@@ -0,0 +1,48 @@
1
+ # Skill: audit-docs
2
+
3
+ **Activate when** the user runs `/audit` or asks "what's stale", "what's missing", "where are the gaps".
4
+
5
+ **Goal:** produce a table of articles that need attention, with a concrete reason per row.
6
+
7
+ ## What to do
8
+
9
+ 1. Read `.d360-writer.json` for the `captureDir`, `outputDir`, and `authoritativeSourceFiles` list.
10
+ 2. Read every existing article under the docs root (typically `user-docs/`).
11
+ 3. Read recent git history: `git log --since="30 days ago" --name-only --pretty=format:"%h %s"`. If `d360-category-map.json` exists, prefer commits since its mtime.
12
+ 4. For each commit, identify which articles describe the affected code paths. Cross-reference using the authoritative source files list and the article-to-code links you can infer.
13
+ 5. For each existing article, check whether its claims still match the source code. Look for: renamed components, changed UI strings, removed features, added features.
14
+
15
+ ## Output format
16
+
17
+ A single markdown table. Nothing else.
18
+
19
+ | Article path | Action | Reason | Scope |
20
+ |---|---|---|---|
21
+ | `03-foo/02-bar.md` | update | commit `abc123` renamed the "Bar" dialog to "Settings" | small |
22
+ | `04-baz/06-new-feature.md` | create | commit `def456` shipped a feature with no doc | full article |
23
+ | `02-spec/04-old-thing.md` | delete | commit `ghi789` removed the feature; no replacement | full deletion |
24
+
25
+ ## Action values
26
+
27
+ - `create` — article doesn't exist, but the feature it would describe is real and shipped.
28
+ - `update` — article exists but disagrees with current code.
29
+ - `delete` — article describes a removed feature.
30
+ - `keep` — explicitly noted as up-to-date and intentional. Don't include `keep` rows unless the user asked for them.
31
+
32
+ ## Scope values
33
+
34
+ - `small` — a UI string, a step renumbering, a one-line clarification.
35
+ - `medium` — a section rewrite or a new screenshot.
36
+ - `full article` — net-new article or near-complete rewrite.
37
+ - `full deletion` — remove from disk and from D360.
38
+
39
+ ## Rules
40
+
41
+ - Quote the commit hash for every claim. No vague "the code changed."
42
+ - Do not start fixing anything. The audit is the deliverable.
43
+ - If the codebase has zero existing articles, redirect the user to `propose-structure` instead and emit nothing.
44
+ - If the audit has zero rows, say so plainly: "All articles are in sync with the codebase as of `<HEAD-sha>`."
45
+
46
+ End your output with:
47
+
48
+ > Want me to start working through these? Reply with `yes` or strike rows you want to defer.
@@ -0,0 +1,82 @@
1
+ # Skill: emit-screenshot-spec
2
+
3
+ **Activate when** you've just emitted a `<!-- SCREENSHOT ... -->` placeholder block in an article, OR the user runs `/screenshot <id>`.
4
+
5
+ **Goal:** generate a Playwright `.spec.ts` file in the configured `captureDir` that the `document360-capture` (alias `d360-capture`) CLI can execute end-to-end against the user's running product.
6
+
7
+ ## Where the spec lands
8
+
9
+ `<captureDir>/<placeholder.id>.spec.ts` — read `captureDir` from `.d360-writer.json` (default: `user-docs/_capture`).
10
+
11
+ ## Spec template
12
+
13
+ ```typescript
14
+ import { test } from '@playwright/test';
15
+ import { waitPastLogin, dumpAnnotations, type Placeholder } from 'document360-capture/helpers';
16
+
17
+ const PLACEHOLDER: Placeholder = {
18
+ id: '<placeholder.id>',
19
+ saveTo: '<placeholder.save-to>',
20
+ highlight: [
21
+ // one stable selector per placeholder.highlight entry
22
+ ],
23
+ annotations: [
24
+ // { target: '<stable selector>', label: '1', text: '<short text>' }
25
+ ],
26
+ redact: [
27
+ // one stable selector per placeholder.redact entry
28
+ ],
29
+ };
30
+
31
+ test('<placeholder.id>', async ({ page }) => {
32
+ await page.goto(process.env.CAPTURE_START_URL!);
33
+ await waitPastLogin(page, new RegExp(process.env.CAPTURE_AUTH_BOUNDARY!));
34
+
35
+ // Translated from placeholder.steps — one Playwright action per step.
36
+ // Use STABLE selectors only.
37
+ // ...
38
+
39
+ await page.waitForSelector('<target state selector>', { state: 'visible' });
40
+ await page.waitForTimeout(500);
41
+
42
+ await page.locator('<capture target selector>').screenshot({ path: PLACEHOLDER.saveTo });
43
+ await dumpAnnotations(page, PLACEHOLDER);
44
+ });
45
+ ```
46
+
47
+ ## Selector quality rule (non-negotiable)
48
+
49
+ Use stable selectors in this priority order:
50
+
51
+ 1. `[data-testid="..."]` — best.
52
+ 2. `[aria-label="..."]` — good.
53
+ 3. `<role>:has-text("...")` / `role=button[name="..."]` — acceptable when unique.
54
+ 4. Visible text (`text=...`, `:has-text(...)`) — acceptable for top-level nav and unique buttons.
55
+
56
+ **Never** use CSS classes, `nth-child`, deep DOM paths, or auto-generated IDs (`#mui-12345`).
57
+
58
+ ## TODO escape hatch (when stable selectors don't exist)
59
+
60
+ If a required interaction has no stable selector, do NOT write a fragile one. Instead:
61
+
62
+ 1. Use `test.skip(...)` instead of `test(...)`.
63
+ 2. Add a top-of-file comment: `// TODO: add data-testid="<suggested-name>" to <ComponentName> at <src/.../File.tsx>. Capture spec disabled until then.`
64
+ 3. Tell the user which file + component to fix, plus the `data-testid` value you'd recommend.
65
+
66
+ The manual intern path in the placeholder still works — only the automated capture is blocked.
67
+
68
+ ## Capture region (the placeholder's `capture` field)
69
+
70
+ | `capture` value | Spec uses |
71
+ |---|---|
72
+ | `full-page` | `await page.screenshot({ path, fullPage: true })` |
73
+ | `main-panel` | a stable container selector (read it from the project's main layout source) |
74
+ | `modal-only` | `page.locator('[role="dialog"]').first().screenshot(...)` |
75
+ | `panel-left` / `panel-right` | the project's named-panel selector |
76
+ | `sidebar` | the project's sidebar selector |
77
+
78
+ ## After writing the spec
79
+
80
+ - Report the spec's path.
81
+ - If you used the TODO escape hatch, surface the blocking selectors so the dev can fix them in one pass.
82
+ - Remind the user: `d360-capture auth --env <env>` once per machine, then `d360-capture capture <id>` to actually take the screenshot.
@@ -0,0 +1,29 @@
1
+ # Skill: gather-context-from-mcp
2
+
3
+ **Activate when** the user asks you to write an article and they have connected MCP servers beyond Document360 — Notion, GitHub, Sentry, Slack, etc.
4
+
5
+ **Goal:** enrich the article's source material with external context that lives outside the codebase.
6
+
7
+ ## What to do
8
+
9
+ 1. Inspect the connected MCP servers (the SDK exposes them — query tool names that match `mcp__<server>__*`).
10
+ 2. For each server, identify if it has relevant material:
11
+ - **Notion**: design docs, RFCs, retrospectives that explain why a feature exists.
12
+ - **GitHub**: PR descriptions, issue threads, commit messages with deeper context than the diff alone.
13
+ - **Sentry / observability**: real error signatures that justify a troubleshooting section.
14
+ - **Slack** (if connected): public-channel decisions or recent customer support patterns.
15
+ 3. Pull the minimum needed to ground specific claims. Don't dump entire docs.
16
+ 4. Cite the source. Every claim you draw from an external source goes into the article's `## Tips & notes` or `## Related articles` section with a link or reference.
17
+
18
+ ## When you should NOT activate
19
+
20
+ - If the user hasn't connected any MCP servers beyond Document360. The source repo is enough.
21
+ - If the user explicitly says "stay close to the code".
22
+ - For short reference articles (CLI commands, config keys) where external context would just add noise.
23
+
24
+ ## Rules
25
+
26
+ - Never paste raw MCP responses into the article. Distill into the article's voice.
27
+ - Never include private identifiers (email addresses, internal URLs, customer names) unless they're meant to be public.
28
+ - If an MCP server returns no relevant results, silently skip it and continue with the code-only sourcing.
29
+ - Cap each external query at one round-trip per source per article — don't keep digging.
@@ -0,0 +1,51 @@
1
+ # Skill: propose-structure
2
+
3
+ **Activate when** the user has approved the codebase analysis and asks to "propose a structure", "outline the docs", or "what folders / articles should we have".
4
+
5
+ **Goal:** produce a concrete documentation folder structure plus a flat list of proposed articles, ready for the user to approve before generation.
6
+
7
+ ## Folder structure rules
8
+
9
+ - Numbered prefix per category: `01-getting-started`, `02-<primary-surface>`, etc.
10
+ - Lowercase, kebab-case.
11
+ - The first category is always `01-getting-started`. The last is always `99-troubleshooting-and-faq` (use `09-` or higher if you have fewer than 10 categories).
12
+ - Between 4 and 12 categories. If you can't justify 4, the repo isn't ready for a structured docs site; recommend a single README instead.
13
+ - Categories should map to the product's user-visible surfaces, not its internal code structure.
14
+
15
+ ## Article list rules
16
+
17
+ - 2–8 articles per category.
18
+ - Numbered prefix per article within a category: `01-what-is-x.md`, `02-install.md`, etc.
19
+ - Each article entry includes: the path, a one-sentence purpose, and the source files the article would draw from.
20
+
21
+ ## Output format
22
+
23
+ Use a markdown tree for the folder layout. Use a table for the article list:
24
+
25
+ ```
26
+ user-docs/
27
+ ├── 01-getting-started/
28
+ ├── 02-<surface-a>/
29
+ ├── 03-<surface-b>/
30
+ ├── ...
31
+ └── 99-troubleshooting-and-faq/
32
+ ```
33
+
34
+ | Path | Purpose | Source files |
35
+ |---|---|---|
36
+ | `01-getting-started/01-what-is-<product>.md` | Define what the product is for end users | `README.md`, `src/pages/...` |
37
+ | ... | ... | ... |
38
+
39
+ ## What you do NOT do
40
+
41
+ - Do not start writing articles. That's `write-article`.
42
+ - Do not create the folders yet — wait for the user to approve.
43
+ - Do not invent features that aren't in the code.
44
+
45
+ End your output with:
46
+
47
+ > Want me to proceed with article generation? Reply with `yes`, or strike any rows you don't want.
48
+
49
+ ## After approval
50
+
51
+ Once the user approves, create the empty folders (don't write file contents) and a single `AGENT-PLAN.md` at the repo's docs root that pins the approved table. The user can edit it; subsequent `write-article` invocations should respect it.
@@ -0,0 +1,39 @@
1
+ # Skill: publish-to-d360
2
+
3
+ **Activate when** the user runs `/publish <path>` or explicitly asks to publish one or more articles to Document360.
4
+
5
+ **Goal:** dual-write each approved article — keep the source markdown in git, push the publish-form markdown to Document360 as a draft via the Document360 MCP server.
6
+
7
+ ## Preconditions
8
+
9
+ - A Document360 MCP server must be registered. Check `/mcp list` mentally — the user's `~/.document360-writer/mcp.json` must contain an entry. If not, stop and tell the user to run `/mcp add document360 http <your-d360-mcp-url>`.
10
+ - `.d360-writer.json` must have `d360.projectId` and `d360.projectVersionId` populated. If not, ask the user to run `/init` first or set them manually.
11
+ - `<repo>/d360-category-map.json` is the source of truth for article IDs. Create it as `{ "projectId": "...", "projectVersionId": "...", "categories": {}, "articles": {} }` if missing.
12
+
13
+ ## Per-article steps
14
+
15
+ 1. Read the local `.md` file.
16
+ 2. Compute the publish form:
17
+ - Strip the H1 line.
18
+ - Strip every `<!-- SCREENSHOT ... -->` block. Keep the visible `[Screenshot: ...]` line.
19
+ - Convert relative `[link](../foo/bar.md)` to plain text like `See "foo" → "bar"`.
20
+ 3. Look up the article path in `d360-category-map.json` `articles` table.
21
+ 4. If found, call the D360 MCP `update-article` tool with `articleId`, `title` (from the H1 you stripped), `content` (the publish form), `contentType: 0`.
22
+ 5. If not found, call `create-article` with `categoryId` (resolve from the path's parent folder via `categories` table), `title`, `content`, `contentType: 0`. Capture the returned `articleId` and write it back into `d360-category-map.json`.
23
+ 6. Never overwrite a published article without confirming with the user.
24
+
25
+ ## After all articles
26
+
27
+ Report:
28
+ - Articles created: count + paths + new D360 article IDs.
29
+ - Articles updated: count + paths + existing IDs.
30
+ - Any failures + reason.
31
+ - A reminder: **all writes are DRAFTS. Publish manually in the Document360 portal** at the configured `helpCenterBaseUrl`.
32
+
33
+ ## Rules
34
+
35
+ - Never commit. The user handles git.
36
+ - Never publish past draft. The user reviews and publishes in D360.
37
+ - Never fabricate D360 IDs. If a UUID is missing, ask.
38
+ - If a `create-article` call fails because the category doesn't exist in D360, ask the user whether to create it via `create-category` first.
39
+ - Always update `d360-category-map.json` with new IDs in the same turn as the create.
@@ -0,0 +1,93 @@
1
+ # Skill: write-article
2
+
3
+ **Activate when** the user asks to write, draft, or generate a specific article — by topic name, by file path, or by reference to the approved plan.
4
+
5
+ **Goal:** produce one publishable article that follows the system-prompt article structure exactly, grounded in the actual source code, and with screenshot placeholders where the user benefits from seeing the UI.
6
+
7
+ ## Before writing — gather
8
+
9
+ 1. Read the source files relevant to this article. Don't skip this. The whole point of this tool is that articles are grounded in code.
10
+ 2. Read `AGENT-PLAN.md` if present, to confirm the article's purpose matches the approved plan.
11
+ 3. Read 1–2 existing articles in the same category, if any, to match voice and structure.
12
+ 4. If `gather-context-from-mcp` is appropriate (the user has connected Notion / GitHub / etc. and the article would benefit from external context), invoke it.
13
+
14
+ ## Article skeleton (system-prompt-mandated)
15
+
16
+ ```
17
+ # <Article title>
18
+
19
+ <one-paragraph intro>
20
+
21
+ ## Prerequisites
22
+ - <role/permissions, if any>
23
+ - <required state>
24
+
25
+ ## Steps
26
+ 1. ...
27
+ 2. ...
28
+
29
+ ## Tips & notes
30
+ - ...
31
+
32
+ ## Related articles
33
+ - ...
34
+ ```
35
+
36
+ ## Screenshot placeholders
37
+
38
+ When the article describes a UI flow that benefits from a visual, embed one or more screenshot placeholders. Each placeholder is two parts:
39
+
40
+ 1. An HTML comment block with capture instructions (stripped before D360 publish).
41
+ 2. A visible `[Screenshot: ...]` line (kept in both local and D360).
42
+
43
+ Example:
44
+
45
+ ```markdown
46
+ <!-- SCREENSHOT
47
+ id: <kebab-case-stable-id>
48
+ title: "<short title>"
49
+ page-url: <relative path or URL>
50
+ prerequisites:
51
+ - <plain-English state setup>
52
+ steps:
53
+ 1. <numbered actions with EXACT button labels>
54
+ capture: <full-page | main-panel | modal-only | panel-left | panel-right | sidebar>
55
+ device: desktop
56
+ viewport: 1440x900
57
+ highlight:
58
+ - <thing to draw attention to>
59
+ annotations:
60
+ - <numbered callouts with short text>
61
+ redact:
62
+ - <regions to hide (emails, real tokens, etc.)>
63
+ save-to: user-docs/_screenshots/<id>.raw.png
64
+ auto-capture-script: user-docs/_capture/<id>.spec.ts
65
+ notes:
66
+ - <edge cases>
67
+ -->
68
+ [Screenshot: <short reader-facing description>]
69
+ > 🤖 Auto-capture: `d360-capture capture <id>`
70
+ > Sign in to Chromium when prompted; the script does the rest.
71
+ ```
72
+
73
+ Every field must be filled. If a field doesn't apply, write "none" or "n/a" — never omit.
74
+
75
+ **The `prerequisites` and `steps` fields must be detailed enough for a junior intern to capture the screenshot without further instruction.** If you can't write them that clearly, you don't understand the screen well enough — read more source code.
76
+
77
+ For every screenshot placeholder you generate, also invoke `emit-screenshot-spec` so the matching `.spec.ts` lands in `<captureDir>/<id>.spec.ts`.
78
+
79
+ ## Writing rules (re-emphasis from system prompt)
80
+
81
+ - Second person, imperative. No marketing language. No "simply", "just", "easily".
82
+ - Quote exact UI strings. Read the React/HTML/etc. source.
83
+ - State role-gating in **Prerequisites**, not in Steps.
84
+ - Markdown only. One H1.
85
+
86
+ ## Output
87
+
88
+ Write the article directly to its file path. Do not paste the markdown into the chat; the user wants the file on disk so they can review and iterate.
89
+
90
+ After writing, report:
91
+ - File path
92
+ - Number of screenshot placeholders emitted (and a note that matching `.spec.ts` files were generated)
93
+ - Any source files you couldn't find — the user may need to clarify