repo-cortex 0.1.0-bootstrap.0 → 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.
package/README.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # repo-cortex
2
2
 
3
- Give a repository a **cortex**: a small `cortex/` folder of plain Markdown that holds the why behind the project. It holds decisions and their reasons, open questions, why each milestone exists, and where things stand right now. A fresh agent session (or a new teammate) reads it on demand and starts planning without being re-briefed.
3
+ A **cortex** is a small `cortex/` folder of plain Markdown in a repository that holds the why behind the project: decisions and their reasons, open questions, why each milestone exists, and where things stand now. A fresh agent session or a new teammate reads it on demand, when planning or asking why, and starts work without being re-briefed.
4
+
5
+ repo-cortex helps you build one. It's for repository maintainers, for new maintainers and contributors, and for any agent that reads skills.
6
+
7
+ **Status:** early. What's on npm is a bootstrap build, `0.1.0-bootstrap.0`, not the 0.1.0 release. The release is part of the [Publish package prep milestone](https://github.com/alanbsmith/repo-cortex/milestone/2).
8
+
9
+ ## Why a cortex
4
10
 
5
11
  The code and the tracker say what and when. They rarely say why. The cortex is where the why goes, and it's kept honest by a few rules:
6
12
 
@@ -16,21 +22,48 @@ The code and the tracker say what and when. They rarely say why. The cortex is w
16
22
 
17
23
  ## Quick start
18
24
 
19
- With Claude Code (or another agent that reads skills), install the skill into the repo and ask for a cortex:
25
+ With the npm build, you need Node.js 24 or later. Run its commands from the root of the repo you want a cortex in.
26
+
27
+ ### With an agent
28
+
29
+ With Claude Code, install the skill into your repo:
20
30
 
21
31
  ```bash
22
- npx repo-cortex skill # into .claude/skills/; --global for ~/.claude/skills/
32
+ npx repo-cortex skill
23
33
  ```
24
34
 
35
+ The skill goes into `.claude/skills/`. Use `--global` to install it into `~/.claude/skills/` instead. For another agent that reads skills, copy the installed `build-cortex` folder to where it looks for them.
36
+
37
+ The installed skill calls `npx repo-cortex@0.1`, not bare `npx repo-cortex`, with the range of the version that installed it, so a later release with different commands can't break it. The commands in the files `init` writes and in the `snippet` paragraph are pinned the same way. To update an installed skill, run `npx repo-cortex@latest skill --force`. A prerelease pins its exact version.
38
+
39
+ Then start a session in your repo and ask:
40
+
25
41
  > Build a cortex for this repo.
26
42
 
27
- By hand:
43
+ ### By hand
28
44
 
29
45
  ```bash
30
- npx repo-cortex init --public --milestones # scaffold cortex/ with TODO(cortex) markers
31
- npx repo-cortex snippet # the paragraph for CLAUDE.md or AGENTS.md
46
+ npx repo-cortex init --public --milestones
47
+ npx repo-cortex snippet
32
48
  npx repo-cortex decision "Use pnpm over npm" --status accepted --decided-by owner
33
- npx repo-cortex check # until it's clean; add it to CI
49
+ npx repo-cortex check
50
+ ```
51
+
52
+ 1. `init` scaffolds `cortex/` with `TODO(cortex)` markers. Use `--private` for a private repo, and leave out `--milestones` if you don't work in milestones.
53
+ 2. `snippet` prints the paragraph to add to your CLAUDE.md or AGENTS.md.
54
+ 3. `decision` starts a decision. Replace the example title with a choice you made.
55
+ 4. `check` warns about each marker until you fill it in. Run it again until it's clean, then add it to CI.
56
+
57
+ ### From a clone
58
+
59
+ To run the latest source instead of the npm build, you need Node.js 26 and pnpm ([CONTRIBUTING.md](CONTRIBUTING.md#setup) has the details). Clone repo-cortex next to your repo, then run the same commands as `pnpm cortex <command>`, with `-C` pointing at your repo. Start in the folder that holds your repo:
60
+
61
+ ```bash
62
+ git clone https://github.com/alanbsmith/repo-cortex
63
+ cd repo-cortex
64
+ pnpm install
65
+ pnpm cortex init -C ../your-repo --public --milestones
66
+ pnpm cortex check -C ../your-repo
34
67
  ```
35
68
 
36
69
  ## What a cortex looks like
@@ -52,6 +85,8 @@ Every file starts with front matter: a one-line `summary:` so a session can choo
52
85
 
53
86
  ## Commands
54
87
 
88
+ Run each as `npx repo-cortex <command>`. `npx repo-cortex --help` lists every option.
89
+
55
90
  | Command | Does |
56
91
  | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
57
92
  | `init` | Scaffold a cortex from the templates. Never overwrites without `--force`. |
@@ -67,7 +102,7 @@ Every command takes `--dir <folder>` (default: `$CORTEX_DIR`, else `cortex`) and
67
102
 
68
103
  Errors: missing `README.md`, `now.md`, `open-questions.md` or `decisions/`; missing or malformed front matter, including a date that isn't a real date; a link, anchor or backticked repo path in a living file that goes nowhere; a file the README doesn't link; a decision's bad file name, duplicate number, unknown status, or supersession that doesn't point both ways.
69
104
 
70
- Warnings: a decision's text changed since `main`; a decision on `main` that was deleted or renamed; a `proposed` decision already on `main`; a new decision with no `decided-by:`; a decision without a numbered title, **Decision:** or **Why:**; an `updated:` date in the future; `now.md` more than 21 days older than the last commit; an open question with no "Reopen when"; a milestone file missing Why / Why now / Done when / Log; a leftover `TODO(cortex)`.
105
+ Warnings: a decision's text changed since `main`; a decision on `main` that was deleted or renamed; a `proposed` decision already on `main`; a new decision with no `decided-by:`; a decision without a numbered title, **Decision:** or **Why:**; an `updated:` date in the future; `now.md` more than 21 days older than the last commit; an open question with no "Reopen when"; a milestone file missing Why / Why now / Done when / Log, unless it sets `layout: free`; a leftover `TODO(cortex)`.
71
106
 
72
107
  Some warnings are marked `(info)`, and `--strict` never fails on them, because the rules forbid the fix or the change may be fine: a stale link or path in a decision (its text never changes), a small edit to a merged decision (a typo fix is allowed), shape warnings on a merged decision, and a missing `origin/main` to compare with (in CI, check out with `fetch-depth: 0`).
73
108
 
@@ -75,14 +110,13 @@ Exit codes: 0 ok, 1 the check failed, 2 a usage error, 70 a bug in repo-cortex.
75
110
 
76
111
  It checks shape and freshness, not truth. A repo with its own docs drift check should add the cortex to it for repo-specific checks such as commands and flags.
77
112
 
78
- ## Contributing
79
-
80
- [CONTRIBUTING.md](CONTRIBUTING.md) says how to set up, change and submit work, and how the project is run. [cortex/](cortex/README.md) has the reasons behind it.
81
-
82
- ## Security
113
+ ## Project links
83
114
 
84
- Please report a vulnerability privately, not in a public issue. [SECURITY.md](SECURITY.md) says how.
115
+ - **Vision:** [what we're building and why](https://github.com/alanbsmith/repo-cortex/discussions/26), a pinned discussion. Check a plan or a pull request against it.
116
+ - **Contributing:** [CONTRIBUTING.md](CONTRIBUTING.md) says how to set up, change and submit work, and how the project is run.
117
+ - **Reasons:** [cortex/](cortex/README.md) is this project's own cortex.
118
+ - **Security:** please report a vulnerability privately, not in a public issue. [SECURITY.md](SECURITY.md) says how.
85
119
 
86
120
  ## License
87
121
 
88
- MIT
122
+ [MIT](LICENSE)
package/dist/init.js CHANGED
@@ -4,6 +4,7 @@ import { basename, dirname, join, relative } from "node:path";
4
4
  import { TEMPLATES, readTemplate, render, } from "./template.js";
5
5
  import { decisionNumber, decisionsDir } from "./decision-model.js";
6
6
  import { UsageError } from "./errors.js";
7
+ import { pinnedCli } from "./pin.js";
7
8
  import { DEFAULT_DIR, originRepo, toPosix, today } from "./repo.js";
8
9
  /** ` --dir <dir>` when the cortex isn't where every command looks by default, so copied commands find it. */
9
10
  export const dirFlag = (dir) => dir === DEFAULT_DIR ? "" : ` --dir ${dir}`;
@@ -19,6 +20,7 @@ export function init(opts) {
19
20
  const vars = {
20
21
  dir,
21
22
  dirFlag: dirFlag(dir),
23
+ cli: pinnedCli(opts.version),
22
24
  date: opts.date ?? today(),
23
25
  repo,
24
26
  owner,
@@ -75,4 +77,8 @@ function templateFiles(abs, base = abs) {
75
77
  .toSorted();
76
78
  }
77
79
  /** The paragraph to add to CLAUDE.md or AGENTS.md. */
78
- export const snippet = (dir) => render(readTemplate("snippet.md"), { dir, dirFlag: dirFlag(dir) });
80
+ export const snippet = (dir, version) => render(readTemplate("snippet.md"), {
81
+ dir,
82
+ dirFlag: dirFlag(dir),
83
+ cli: pinnedCli(version),
84
+ });
package/dist/pin.js ADDED
@@ -0,0 +1,28 @@
1
+ /** The CLI version a skill or a cortex names in its `npx` commands, so a later release can't change what they call. */
2
+ import { readFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { packageDir } from "./package-dir.js";
5
+ export const packageVersion = JSON.parse(readFileSync(join(packageDir, "package.json"), "utf8")).version;
6
+ const SEMVER = /^(\d+)\.(\d+)\.(\d+)(-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
7
+ /**
8
+ * The npm range that holds back what decision 0013 calls breaking. In 0.x a minor may break, so
9
+ * 0.1.4 gives `0.1` (>=0.1.0 <0.2.0); from 1.0 only a major does, so 1.4.2 gives `1`. Neither has a `^`, which
10
+ * some shells treat as special. A prerelease gets itself, without build metadata: a range such as `0.2`
11
+ * doesn't match `0.2.0-alpha.3`. Build metadata never changes the range.
12
+ */
13
+ export function versionRange(version) {
14
+ const m = version.match(SEMVER);
15
+ if (!m)
16
+ throw new Error(`"${version}" isn't a valid semantic version, like 0.1.0.`);
17
+ const [, major, minor, patch, prerelease] = m;
18
+ if (prerelease)
19
+ return `${major}.${minor}.${patch}${prerelease}`;
20
+ return major === "0" ? `${major}.${minor}` : major;
21
+ }
22
+ /** `npx repo-cortex@<range>`: the command that installs and runs a CLI this version can stand behind. */
23
+ export const pinnedCli = (version = packageVersion) => `npx repo-cortex@${versionRange(version)}`;
24
+ /**
25
+ * Replace each unpinned `npx repo-cortex` command in some Markdown. A command ends at whitespace, the end of
26
+ * the line, a backtick or a quote; `npx repo-cortex.tgz`, `npx repo-cortex/bin/x.js` and other mentions stay.
27
+ */
28
+ export const pinCommands = (markdown, version = packageVersion) => markdown.replace(/\bnpx repo-cortex(?=\s|$|[`"'])/gm, () => pinnedCli(version));
package/dist/skill.js CHANGED
@@ -1,10 +1,11 @@
1
1
  /** `repo-cortex skill`: copy the bundled skills into a project's or the user's .claude/skills/. */
2
- import { cpSync, existsSync, readdirSync, rmSync } from "node:fs";
2
+ import { cpSync, existsSync, readFileSync, readdirSync, rmSync, writeFileSync, } from "node:fs";
3
3
  import { homedir } from "node:os";
4
4
  import { join } from "node:path";
5
5
  import { packageDir } from "./package-dir.js";
6
+ import { pinCommands } from "./pin.js";
6
7
  const SKILLS = join(packageDir, "skills");
7
- export function installSkills({ root, global = false, force = false, }) {
8
+ export function installSkills({ root, global = false, force = false, version, }) {
8
9
  const target = global
9
10
  ? join(homedir(), ".claude", "skills")
10
11
  : join(root, ".claude", "skills");
@@ -22,7 +23,19 @@ export function installSkills({ root, global = false, force = false, }) {
22
23
  // Replace, not merge, so a file removed from the skill doesn't linger in the installed copy.
23
24
  rmSync(dest, { recursive: true, force: true });
24
25
  cpSync(join(SKILLS, entry.name), dest, { recursive: true });
26
+ // The copy outlives this version of the CLI, so its commands name the version that wrote it.
27
+ for (const file of markdownFiles(dest)) {
28
+ writeFileSync(file, pinCommands(readFileSync(file, "utf8"), version));
29
+ }
25
30
  installed.push(entry.name);
26
31
  }
27
32
  return { installed, skipped, target };
28
33
  }
34
+ function markdownFiles(dir) {
35
+ return readdirSync(dir, { withFileTypes: true }).flatMap((e) => {
36
+ const path = join(dir, e.name);
37
+ if (e.isDirectory())
38
+ return markdownFiles(path);
39
+ return e.name.endsWith(".md") ? [path] : [];
40
+ });
41
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repo-cortex",
3
- "version": "0.1.0-bootstrap.0",
3
+ "version": "0.1.0",
4
4
  "description": "Give a repository a cortex: a small folder of plain Markdown that holds the why behind a project (decisions, open questions, current focus) so a fresh agent session doesn't need re-briefing.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -12,6 +12,7 @@
12
12
  "bugs": {
13
13
  "url": "https://github.com/alanbsmith/repo-cortex/issues"
14
14
  },
15
+ "homepage": "https://github.com/alanbsmith/repo-cortex#readme",
15
16
  "keywords": [
16
17
  "agents",
17
18
  "claude",
@@ -34,6 +35,10 @@
34
35
  "README.md",
35
36
  "LICENSE"
36
37
  ],
38
+ "publishConfig": {
39
+ "access": "public",
40
+ "provenance": true
41
+ },
37
42
  "devDependencies": {
38
43
  "@commitlint/cli": "^21.3.0",
39
44
  "@commitlint/config-conventional": "^21.3.0",
@@ -68,12 +68,12 @@ gh project item-list {{project}} --owner {{owner}} --format json --limit 200
68
68
  To see every decision at once, read each one's summary and status instead of opening the files:
69
69
 
70
70
  ```bash
71
- npx repo-cortex list{{dirFlag}}
71
+ {{cli}} list{{dirFlag}}
72
72
  ```
73
73
 
74
74
  ## Keeping it current
75
75
 
76
- - **A decision's text is never edited.** Record a change of mind as a new decision with `supersedes:` (`npx repo-cortex decision "<title>" --supersedes <number>{{dirFlag}}`). Only two things on an old decision may change: typo fixes, and its front matter, where it gets `status: superseded` and `superseded-by:` once the new decision is accepted.
76
+ - **A decision's text is never edited.** Record a change of mind as a new decision with `supersedes:` (`{{cli}} decision "<title>" --supersedes <number>{{dirFlag}}`). Only two things on an old decision may change: typo fixes, and its front matter, where it gets `status: superseded` and `superseded-by:` once the new decision is accepted.
77
77
  - **Every other file is rewritten in place.** Update its `updated:` date. Git history is its record of changes.
78
78
  - **Undecided goes in open-questions.md.** When a question is settled, write the decision and delete the entry.
79
79
  - **Never invent a reason.** If nobody knows why something was chosen, the decision says so, or the question goes in open-questions.md.
@@ -82,7 +82,7 @@ npx repo-cortex list{{dirFlag}}
82
82
  <!-- if:public -->
83
83
  - **This repo is public.** Write nothing here you wouldn't put in a PR description.<!-- if:related --> Check [related-projects.md](related-projects.md) before you describe another project.<!-- endif:related -->
84
84
  <!-- endif:public -->
85
- - **Check it.** `npx repo-cortex check{{dirFlag}}` finds broken links, moved paths, missing front matter and a stale `now.md`.
85
+ - **Check it.** `{{cli}} check{{dirFlag}}` finds broken links, moved paths, missing front matter and a stale `now.md`.
86
86
 
87
87
  ### Front matter
88
88
 
@@ -15,4 +15,4 @@ links: ["README.md"]
15
15
 
16
16
  **Weighed:** putting the reasons in the agent instructions file, which loads in every session and would grow with every decision; and a wiki or docs site, which sits outside code review and drifts from the code.
17
17
 
18
- **Consequences:** sessions that plan start at `{{dir}}/README.md`. Each session that moves the focus or makes a decision updates the cortex before it ends, and `npx repo-cortex check{{dirFlag}}` keeps it honest.
18
+ **Consequences:** sessions that plan start at `{{dir}}/README.md`. Each session that moves the focus or makes a decision updates the cortex before it ends, and `{{cli}} check{{dirFlag}}` keeps it honest.
@@ -1,3 +1,3 @@
1
1
  ## The cortex
2
2
 
3
- For planning or "why" questions, start at `{{dir}}/README.md` and open only the files it points to; don't grep the repo first. At the end of a session, update `{{dir}}/now.md` if the focus moved, add a line to the milestone's log in `{{dir}}/milestones/` if there is one, and record any decision you made in `{{dir}}/decisions/` as `status: proposed` (`npx repo-cortex decision "<title>"{{dirFlag}}`). Run `npx repo-cortex check{{dirFlag}}` after editing the cortex.
3
+ For planning or "why" questions, start at `{{dir}}/README.md` and open only the files it points to; don't grep the repo first. At the end of a session, update `{{dir}}/now.md` if the focus moved, add a line to the milestone's log in `{{dir}}/milestones/` if there is one, and record any decision you made in `{{dir}}/decisions/` as `status: proposed` (`{{cli}} decision "<title>"{{dirFlag}}`). Run `{{cli}} check{{dirFlag}}` after editing the cortex.