agentpractices 0.0.1 → 1.0.1

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 (3) hide show
  1. package/README.md +127 -0
  2. package/dist/cli.js +9630 -0
  3. package/package.json +42 -5
package/README.md ADDED
@@ -0,0 +1,127 @@
1
+ # agentpractices
2
+
3
+ Pin the [agentpractices.dev](https://agentpractices.dev/) practices that govern a repository, vendor the exact versions agents read, and gate CI on a stale, tampered or expired state.
4
+
5
+ A project declares the practices that govern it in a hand-edited manifest, `agentpractices.toml`. The CLI resolves that manifest into a generated lock, `agentpractices.lock.json`, and pinned Markdown in `.agentpractices/BP-NNNN@<version>.md`. Agents read the pinned copies, never the live site.
6
+
7
+ ```sh
8
+ bunx agentpractices@1.0.1 init
9
+ git add agentpractices.toml agentpractices.lock.json .agentpractices .gitattributes
10
+ ```
11
+
12
+ `init` also adds `.gitattributes` lines so the byte-hashed files keep LF on every platform.
13
+
14
+ Phase 1 ships six commands: `init`, `add`, `remove`, `lock`, `sync` and `check`. `prime`, `update`, `outdated`, `tree`, `why`, `show`, `bindings` and `waive` are phase 2.
15
+
16
+ ## Commands
17
+
18
+ | Command | Does |
19
+ | --- | --- |
20
+ | `init [--catalog <url>] [--dry-run]` | Inspect the repository, write the manifest, vendor the selected practices, write the lock and add `.gitattributes` LF rules |
21
+ | `add <id…> [--mode enforce\|advise] [--bind <rule>=<check>]` | Add practices to `[select].include`, set the mode and add bindings, then relock. A deprecated practice cannot take `--mode` or `--bind`; configure its successor |
22
+ | `add --domain <d> \| --role <r> \| --stage <s>` | Widen the selection filters, relock, and report what newly resolved |
23
+ | `remove <id…> [--reason <text>]` | Drop explicit includes; when a filter still selects the practice, add it to `exclude` with `mode = "off"` and the reason. It also removes the practice's waivers |
24
+ | `lock [--upgrade] [--upgrade-practice <id>] [--allow major] [--locked]` | Resolve the manifest into the lock; `--locked` writes nothing and fails when the lock would change. An unreadable existing lock is rebuilt with a warning |
25
+ | `sync [--frozen]` | Make `.agentpractices/` match the lock; `--frozen` works offline and never fetches |
26
+ | `check [--locked\|--frozen] [--quiet]` | Validate the lock, the vendored bytes, bindings, waivers and catalogue freshness. Never writes |
27
+
28
+ Global flags: `--json`, `-q`/`--quiet`, `--dry-run` (for mutating commands), `--timeout <ms>`, `--root <dir>`, `-h`/`--help`, `--version`, `--plain`.
29
+
30
+ `check --locked` is an explicit alias for the default online check. `check --frozen` is the offline mode.
31
+
32
+ `lock --upgrade` moves a level unless its `[update]` policy is `manual`; a manual major needs `--allow major`. A skipped manual update is reported, not failed. The phase 2 `update` command applies the same policy through pull requests.
33
+
34
+ ## Exit codes
35
+
36
+ | Code | Meaning |
37
+ | --- | --- |
38
+ | `0` | Success |
39
+ | `1` | Config error, network failure or general failure |
40
+ | `2` | Stale lock; also a usage error (stderr distinguishes) |
41
+ | `3` | Integrity failure: a hash mismatch, or a changed hash under an unchanged version |
42
+
43
+ `check` reports every problem and exits by priority `3 > 1 > 2 > 0`. An integrity failure blocks agent work until a person reviews it.
44
+
45
+ ## JSON output
46
+
47
+ Every command supports `--json` on stdout. Failures print `{"error":{"kind","message","exitCode"}}` to stderr.
48
+
49
+ | Command | Shape |
50
+ | --- | --- |
51
+ | `init` | `{command, manifest, lock, practices:[{id,version,vendored}], dryRun}` |
52
+ | `add` | `{command, added:[id], newlySelected:[id], manifestChanged, lock:{added,removed,upgraded,kept}, dryRun}` |
53
+ | `remove` | `{command, removed:[id], excluded:[id], lock:{added,removed,upgraded,kept}, dryRun}` |
54
+ | `lock` | `{command, changed, added:[id], removed:[id], upgraded:[id], kept:[id], practices:[{id,version}], dryRun}` |
55
+ | `sync` | `{command, fetched:[id], deleted:[path], kept:[id], verified:[id], dryRun}` |
56
+ | `check` | `{command, ok, exitCode, problems:[{code,severity,message}], frozen}` |
57
+
58
+ `check` problems carry severity `config`, `stale`, `integrity` or `info`. `info` never changes the exit code: a `review_by` that has passed, or a patch/minor update whose policy is not `auto`.
59
+
60
+ ## The manifest and the lock
61
+
62
+ The manifest is hand-edited intent:
63
+
64
+ ```toml
65
+ schema = 1
66
+ catalog = "https://agentpractices.dev/catalog.json"
67
+ channel = "include-draft"
68
+
69
+ [select]
70
+ domains = ["D.AGT.*", "D.SWE.CLI"]
71
+ roles = ["implementer", "reviewer"]
72
+ stage = ["plan", "build", "verify"]
73
+
74
+ [update]
75
+ patch = "auto"
76
+ minor = "pr"
77
+ major = "manual"
78
+
79
+ [practice."BP-0042"]
80
+ mode = "enforce"
81
+ tighten = [4]
82
+ enforce = [{ rule = 2, check = "lint:cli-exit-codes" }]
83
+
84
+ [[waiver]]
85
+ practice = "BP-0042"
86
+ rule = 3
87
+ reason = "Legacy exit code 2 kept for v1 compatibility"
88
+ expires = "2027-03-31"
89
+ approved_by = "madeinoz67"
90
+ ```
91
+
92
+ The lock is generated, sorted and never hand-edited. It pins each practice's version, the catalogue's `content_hash`, the vendored file's `file_sha256`, the vendored path, the parsed `rules`, the effective `mode`, `tighten` and `enforce`, and the `selected_by` reasons. It records the catalogue's top-level metadata and `manifest_sha256`.
93
+
94
+ Protect `agentpractices.toml`, `agentpractices.lock.json` and `.agentpractices/` with CODEOWNERS; phase 1 `init` does not install that touchpoint. `add` and `remove` rewrite the manifest canonically; comments between tables are not preserved.
95
+
96
+ `content_hash` is **not** a hash of the raw bytes. It is `sha256:` + SHA-256 of a normalized JSON payload over the parsed frontmatter fields and body (title, description, domain, type, roles, stage, status, related, superseded_by, sources, body), exactly as the site computes it. The CLI recomputes it from the fetched Markdown and compares it to the catalogue. `file_sha256` is a separate SHA-256 of the exact vendored bytes, so a local edit is caught offline. `check` and `sync` recompute `content_hash` and `rules` from every vendored file, not only `file_sha256`, so editing one hash without the others fails. `check --frozen` is the offline gate: it verifies internal consistency and the lock against the manifest, but it cannot authenticate a lock and vendored file edited together. Run the online `check` in CI whenever the catalogue is reachable, and use `--frozen` for worktree setup and offline runs. A locked version that is behind the catalogue cannot be authenticated against the current catalogue; `check` reports that as informational (`W_UNAUTHENTICATED`), so keep the lock current, especially under `pr` and `manual` policies.
97
+
98
+ ## Security
99
+
100
+ - Every fetch is same-origin with the catalogue URL. Redirects are followed manually, and every hop is checked.
101
+ - Bodies are capped at 5 MB each; the catalogue at 20 MB. URLs with embedded credentials are refused.
102
+ - Fetched content is never executed. Only JSON, TOML and YAML are parsed, with safe parsers.
103
+ - Practice IDs and versions are validated before a path is built; vendored reads reject symlinks and non-regular files.
104
+ - A fetched page whose frontmatter `id` or `version` does not match the catalogue entry is rejected before anything is written.
105
+
106
+ `file:` catalogues are accepted for local and test use. The default is `https://agentpractices.dev/catalog.json`.
107
+
108
+ ## Release channels
109
+
110
+ The same build ships three ways at the same version as the `use-practices` plugin:
111
+
112
+ - npm: `bunx agentpractices@1.0.1`
113
+ - the `use-practices` Claude Code plugin (bundled single-file JS)
114
+ - compiled release binaries attached to GitHub releases, with a `SHA256SUMS` file
115
+
116
+ A release tag `v1.0.1` must match `packages/cli/package.json`'s version. Publishing uses npm Trusted Publishing (OIDC) from `release.yml`; configure the trusted publisher on npmjs.com. No long-lived npm token is used.
117
+
118
+ ## Develop
119
+
120
+ ```sh
121
+ bun install
122
+ bun test packages/cli/tests
123
+ bun scripts/build-cli.ts # writes dist/cli.js and the plugin bundle
124
+ bun scripts/build-cli.ts --check # fails when the committed plugin bundle is stale
125
+ ```
126
+
127
+ Every source file starts with `author: Stephen Eaton`. The CLI is MIT licensed.