@docsworth/cli 0.0.0-stage → 0.2.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 (91) hide show
  1. package/LICENSE +55 -0
  2. package/README.md +186 -2
  3. package/dist/cli.d.ts +11 -0
  4. package/dist/cli.js +409 -0
  5. package/dist/core/acl.d.ts +28 -0
  6. package/dist/core/acl.js +102 -0
  7. package/dist/core/audit-log.d.ts +133 -0
  8. package/dist/core/audit-log.js +290 -0
  9. package/dist/core/blocks.d.ts +35 -0
  10. package/dist/core/blocks.js +417 -0
  11. package/dist/core/codeowners.d.ts +62 -0
  12. package/dist/core/codeowners.js +133 -0
  13. package/dist/core/config.d.ts +96 -0
  14. package/dist/core/config.js +131 -0
  15. package/dist/core/coverage.d.ts +25 -0
  16. package/dist/core/coverage.js +41 -0
  17. package/dist/core/duration.d.ts +20 -0
  18. package/dist/core/duration.js +60 -0
  19. package/dist/core/errors.d.ts +11 -0
  20. package/dist/core/errors.js +13 -0
  21. package/dist/core/frontmatter.d.ts +17 -0
  22. package/dist/core/frontmatter.js +40 -0
  23. package/dist/core/gate.d.ts +17 -0
  24. package/dist/core/gate.js +25 -0
  25. package/dist/core/github.d.ts +152 -0
  26. package/dist/core/github.js +234 -0
  27. package/dist/core/host.d.ts +125 -0
  28. package/dist/core/host.js +22 -0
  29. package/dist/core/identity.d.ts +39 -0
  30. package/dist/core/identity.js +127 -0
  31. package/dist/core/init.d.ts +25 -0
  32. package/dist/core/init.js +86 -0
  33. package/dist/core/lint.d.ts +17 -0
  34. package/dist/core/lint.js +115 -0
  35. package/dist/core/mcp/audit-transport.d.ts +16 -0
  36. package/dist/core/mcp/audit-transport.js +238 -0
  37. package/dist/core/mcp/server.d.ts +19 -0
  38. package/dist/core/mcp/server.js +207 -0
  39. package/dist/core/mcp/text.d.ts +14 -0
  40. package/dist/core/mcp/text.js +43 -0
  41. package/dist/core/mirror-view.d.ts +68 -0
  42. package/dist/core/mirror-view.js +367 -0
  43. package/dist/core/new-page.d.ts +52 -0
  44. package/dist/core/new-page.js +49 -0
  45. package/dist/core/policy.d.ts +10 -0
  46. package/dist/core/policy.js +30 -0
  47. package/dist/core/polish.d.ts +42 -0
  48. package/dist/core/polish.js +1000 -0
  49. package/dist/core/references.d.ts +52 -0
  50. package/dist/core/references.js +1242 -0
  51. package/dist/core/repo.d.ts +42 -0
  52. package/dist/core/repo.js +116 -0
  53. package/dist/core/schema.d.ts +46 -0
  54. package/dist/core/schema.js +49 -0
  55. package/dist/core/search.d.ts +24 -0
  56. package/dist/core/search.js +98 -0
  57. package/dist/core/serve/auth.d.ts +23 -0
  58. package/dist/core/serve/auth.js +38 -0
  59. package/dist/core/serve/server.d.ts +22 -0
  60. package/dist/core/serve/server.js +138 -0
  61. package/dist/core/serve/sessions.d.ts +39 -0
  62. package/dist/core/serve/sessions.js +130 -0
  63. package/dist/core/serve/token.d.ts +10 -0
  64. package/dist/core/serve/token.js +96 -0
  65. package/dist/core/service.d.ts +375 -0
  66. package/dist/core/service.js +815 -0
  67. package/dist/core/sla.d.ts +16 -0
  68. package/dist/core/sla.js +20 -0
  69. package/dist/core/stale.d.ts +16 -0
  70. package/dist/core/stale.js +23 -0
  71. package/dist/core/tool-registry.d.ts +31 -0
  72. package/dist/core/tool-registry.js +77 -0
  73. package/dist/core/url.d.ts +4 -0
  74. package/dist/core/url.js +31 -0
  75. package/dist/core/version.d.ts +22 -0
  76. package/dist/core/version.js +32 -0
  77. package/dist/core/writes.d.ts +58 -0
  78. package/dist/core/writes.js +113 -0
  79. package/dist/web/assets/index-BglLMIyN.css +1 -0
  80. package/dist/web/assets/index-DugFPoRu.js +25 -0
  81. package/dist/web/index.html +14 -0
  82. package/docs/format-spec.md +311 -0
  83. package/package.json +75 -4
  84. package/plugin/.claude-plugin/plugin.json +8 -0
  85. package/plugin/.mcp.json +8 -0
  86. package/plugin/bin/docsworth-mcp.mjs +46 -0
  87. package/plugin/skills/draft-runbook/SKILL.md +75 -0
  88. package/plugin/skills/polish-page/SKILL.md +64 -0
  89. package/plugin/skills/update-after-incident/SKILL.md +59 -0
  90. package/plugin/skills/verify-page/SKILL.md +46 -0
  91. package/templates/github/knowledge.yml +51 -0
package/LICENSE ADDED
@@ -0,0 +1,55 @@
1
+ Apache License
2
+
3
+ Version 2.0, January 2004
4
+
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
16
+
17
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
18
+
19
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
20
+
21
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
22
+
23
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
24
+
25
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
26
+
27
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
28
+
29
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
30
+
31
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
32
+
33
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
34
+
35
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
36
+
37
+ You must give any other recipients of the Work or Derivative Works a copy of this License; and
38
+
39
+ You must cause any modified files to carry prominent notices stating that You changed the files; and
40
+
41
+ You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
42
+
43
+ If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
44
+
45
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
46
+
47
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
48
+
49
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
50
+
51
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
52
+
53
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
54
+
55
+ END OF TERMS AND CONDITIONS
package/README.md CHANGED
@@ -1,3 +1,187 @@
1
- # Temporary Holding Version
1
+ # Docsworth
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **Your runbooks, owned, verified and executable by every agent.**
4
+
5
+ Docsworth is a git-native knowledge layer for coding agents. Pages are markdown in your
6
+ own repo. Every page has exactly one owning team in CODEOWNERS and a review date. Agents
7
+ reach the pages through an MCP server that cites only pages a team has verified within
8
+ their review window. Everything else comes back as *excluded: past review date, owned by
9
+ platform*, so the gap is visible rather than silently stale.
10
+
11
+ - **Customer-owned git.** Plain markdown in your GitHub repo; no lock-in, and it reviews
12
+ like code.
13
+ - **Enforced ownership.** `docsworth lint` fails CI unless each page's CODEOWNERS rule names
14
+ exactly one team, and that team matches the page.
15
+ - **Citation gate.** Only `canonical` pages inside their SLA are citable. The gate is
16
+ fixed and not configurable.
17
+ - **PR-only writes.** Agents propose edits and owners verify pages through pull
18
+ requests. Nothing writes to the default branch.
19
+ - **Polish without drift.** Agents can restructure and reword a page as a `polish`
20
+ PR. The server refuses one that changes a code block, inline code, a link, a number
21
+ or a negation word. The check reads pages as CommonMark does, and is fuzzed against
22
+ CommonMark's reference parser: no miss in 1.5 million mutated pages.
23
+ - **Mirror, don't migrate.** Read-only Confluence and Notion mirror, scored for
24
+ freshness, ownership and overlap with canonical pages. With `mirror.serve`, agents
25
+ see it as context they may never cite.
26
+ - **Skills compiler.** Verified runbooks compile into `SKILL.md` files that agents
27
+ execute.
28
+ - **Agents read free.** No metering on reads.
29
+
30
+ ## 5-minute quickstart
31
+
32
+ You need Node 22.12+, a GitHub repo for your knowledge, and Claude Code.
33
+
34
+ Install the CLI from npm. It's `@docsworth/cli`: `agent-kb` and `docsworth` there are
35
+ not ours.
36
+
37
+ ```bash
38
+ npm install --global @docsworth/cli
39
+ ```
40
+
41
+ ```bash
42
+ cd your-knowledge-repo
43
+ docsworth init --team platform # config, CODEOWNERS, root map, a guide
44
+ docsworth lint . # 3 pages, 0 errors, 0 warnings
45
+ ```
46
+
47
+ Add `--ci` to `init` for a workflow that lints and compiles on every PR.
48
+
49
+ Install the Claude Code plugin from this repo's marketplace:
50
+
51
+ ```bash
52
+ claude plugin marketplace add docsworth/docsworth
53
+ ```
54
+
55
+ ```bash
56
+ claude plugin install docsworth@docsworth
57
+ ```
58
+
59
+ The plugin runs the published CLI through `npx`. To run your own install instead (Docsworth
60
+ pro needs it), set `DOCSWORTH_BIN` in Claude Code's environment to its absolute path, such
61
+ as `$(npm prefix -g)/bin/docsworth`.
62
+
63
+ Start Claude Code in the knowledge repo, or set `DOCSWORTH_KNOWLEDGE_DIR` to its path, then ask
64
+ *"How do I add a page to our knowledge base?"*. The answer cites
65
+ `guide-writing-pages`.
66
+
67
+ The server uses your own GitHub identity (`GITHUB_TOKEN`, `GH_TOKEN` or `gh auth
68
+ token`), so your repo and team permissions decide what you see.
69
+
70
+ ## Commands
71
+
72
+ | Command | What it does |
73
+ | --- | --- |
74
+ | `docsworth init [dir]` | Scaffold config, CODEOWNERS, `knowledge/index.md`, a glossary and a writing guide. Never overwrites. |
75
+ | `docsworth lint [dir]` | Frontmatter, CODEOWNERS ownership, links and duplicate ids. Exit 1 on errors; overdue pages only warn. |
76
+ | `docsworth stale [dir]` | Pages past their review SLA or without a team owner. |
77
+ | `docsworth coverage [dir] [--html f]` | Percentage team-owned and percentage verified within SLA, by team; optional static dashboard. |
78
+ | `docsworth digest [dir] [--send]` | Weekly per-team digest: due, overdue, most read by agents. Prints unless `--send`. |
79
+ | `docsworth mcp [dir]` | The MCP server (stdio): `search`, `read`, `list`, `stale`, `propose_edit`, `verify`, `draft_page`. Without `dir`, it serves `DOCSWORTH_KNOWLEDGE_DIR`, else the current directory. |
80
+ | `docsworth serve [dir]` | The web app at `127.0.0.1:4747` (overview, search, pages, teams, a link graph, capture), and the same server over HTTP for it and the browser extension, behind a token kept in your state directory (`--print-token`, `--rotate-token`, `--allow-extension <id>`). |
81
+ | `docsworth compile [dir] [--check]` | Canonical runbooks → `skills/<id>/SKILL.md`; `--check` exits 1 on drift. |
82
+ | `docsworth mirror [dir]` | Read-only Confluence and Notion mirror into `.knowledge/mirror`, scored. |
83
+ | `docsworth promote <mirror-id> --owner-team t` | Draft PR copying a mirrored page into `knowledge/`. |
84
+ | `docsworth audit [dir] [--bench d]` | Audit report: coverage, stale and overlapping pages, DIY accuracy score. |
85
+ | `docsworth bench run [dir]` | Citation benchmark: Claude on the raw wiki vs. the ungated layer vs. the gated layer. |
86
+
87
+ `--as-of YYYY-MM-DD` evaluates SLAs on a fixed date, for reproducible reports.
88
+
89
+ ## How it works
90
+
91
+ ```
92
+ knowledge/*.md ──lint (CI)──▶ CODEOWNERS: one team per page
93
+ │
94
+ ├─▶ docsworth mcp ──▶ ACL filter (your GitHub teams) ──▶ citation gate ──▶ agent
95
+ │ propose_edit / verify ──▶ PR only
96
+ ├─▶ docsworth compile ──▶ skills/<id>/SKILL.md
97
+ Confluence / Notion ──docsworth mirror──▶ .knowledge/mirror (scored, never citable) ──promote──▶ PR
98
+ ```
99
+
100
+ - [docs/format-spec.md](docs/format-spec.md): the format contract.
101
+ - [docs/security-model.md](docs/security-model.md): ACLs, writes and prompt injection.
102
+ Note that `acl` narrows what agents are served; it isn't confidentiality inside one
103
+ repo.
104
+ - [docs/enterprise/](docs/enterprise/README.md): for a security review. The two modes, what is
105
+ inherited from GitHub, a responsibility matrix, a data-flow diagram and a pre-filled
106
+ questionnaire. Vulnerabilities: [SECURITY.md](SECURITY.md).
107
+ - [docs/rollout.md](docs/rollout.md): org-wide rollout with managed settings.
108
+
109
+ ## Try it on the example
110
+
111
+ ```bash
112
+ npm install
113
+ ```
114
+
115
+ ```bash
116
+ npm run docsworth -- --as-of 2026-11-02 lint examples/acme
117
+ ```
118
+
119
+ ```bash
120
+ npm run docsworth -- --as-of 2026-11-02 coverage examples/acme --html coverage.html
121
+ ```
122
+
123
+ ```bash
124
+ npm run mirror-fixture -w @docsworth-pro/pro -- examples/acme
125
+ ```
126
+
127
+ ```bash
128
+ npm run docsworth -- --as-of 2026-11-02 audit examples/acme --out audit
129
+ ```
130
+
131
+ ## Browser extension
132
+
133
+ A side panel for Chrome (and other Chromium browsers) over `docsworth serve`. From the panel
134
+ you can search and read pages, or suggest an addition to one. From any page, right-click a
135
+ selection and choose **Save selection to Docsworth**. In Gmail, a **Save to Docsworth**
136
+ button beside a thread's subject opens the panel. The panel first shows the pages that may
137
+ already cover the thread, then a draft page filled from it. Nothing is written until you
138
+ open the draft PR. It isn't in the Chrome Web Store yet: build it and load it unpacked.
139
+
140
+ ```bash
141
+ npm run build -w @docsworth/extension
142
+ ```
143
+
144
+ 1. In Chrome, open `chrome://extensions`, turn on **Developer mode**, choose **Load
145
+ unpacked** and pick `packages/extension/dist`. Note the extension's id.
146
+ 2. Start the server so it answers the extension:
147
+
148
+ ```bash
149
+ docsworth serve --allow-extension <the extension's id>
150
+ ```
151
+
152
+ 3. Open the extension's options (its toolbar icon, then **Options**). Paste the link `serve`
153
+ printed, then choose **Connect**. Chrome forgets the token when it quits; paste it again
154
+ then (`docsworth serve --print-token` shows it).
155
+
156
+ What it can reach and keep, and why the token is safe from pages:
157
+ [docs/security-model.md](docs/security-model.md#the-browser-extension).
158
+
159
+ **Gmail checklist.** Gmail's markup isn't a contract. The tests run against Gmail-shaped
160
+ fixtures, so check these by hand, signed in, after loading a new build:
161
+
162
+ - [ ] An open thread shows **Save to Docsworth** beside its subject. The inbox list shows
163
+ none.
164
+ - [ ] Clicking it opens the side panel with "From Gmail", related pages, and a draft whose
165
+ title is the subject and whose body is the expanded messages, each with its sender's name
166
+ and no addresses.
167
+ - [ ] Moving to another thread moves the button with it. Clicking it while a draft is open
168
+ shows "Another capture is waiting" rather than replacing the draft.
169
+ - [ ] A thread with collapsed messages captures only the expanded ones: expand what you
170
+ want in the draft first.
171
+
172
+ ## Development
173
+
174
+ The one verify target is `npm test`: a typecheck and the vitest suite, including an MCP
175
+ end-to-end test and the ACL matrix. It also builds, packs and installs the real tarball.
176
+ See [AGENTS.md](AGENTS.md), and [docs/releasing.md](docs/releasing.md) for releases.
177
+
178
+ ## Status
179
+
180
+ v0.2. What's in it, and what hasn't been verified against the real thing yet, is in
181
+ [the release notes](docs/release-notes/v0.2.0.md).
182
+
183
+ ## License
184
+
185
+ Apache-2.0. Docsworth pro (`@docsworth-pro/pro`: the mirror connectors, digest, reports,
186
+ the SIEM audit sink and the benchmark) is a separate package under its own, proprietary
187
+ licence.
package/dist/cli.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from "commander";
3
+ declare const program: Command;
4
+ /** "Now" for every SLA computation; --as-of pins it for reproducible reports. */
5
+ export declare function now(): Date;
6
+ /**
7
+ * The change happened but its outcome isn't in a required log: say so, and exit 3 (done,
8
+ * audit degraded) so automation can tell it from success (0) and failure (2).
9
+ */
10
+ export declare const EXIT_AUDIT_DEGRADED = 3;
11
+ export { program };