@nera-static/mcp 1.2.0 → 1.3.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nera",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Create, edit, build, validate, preview and publish websites made with Nera, a static site generator: the Nera skill plus the Nera MCP server, which works only inside the sites folder you pick on enable.",
5
5
  "author": {
6
6
  "name": "Michael Becker"
@@ -29,7 +29,7 @@
29
29
  "command": "npx",
30
30
  "args": [
31
31
  "-y",
32
- "@nera-static/mcp@1.2.0",
32
+ "@nera-static/mcp@1.3.0",
33
33
  "--root",
34
34
  "${user_config.root}"
35
35
  ]
package/CHANGELOG.md CHANGED
@@ -5,6 +5,26 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.3.0] - 2026-11-19
9
+
10
+ ### Changed
11
+
12
+ - `publish` learns that `nera publish` waits for the user (the GitHub sign-in code, the app installation, the Netlify authorization) and that the step is done from the CLI's JSON event lines on stderr instead of matching its human log lines, so a change in the CLI's wording no longer breaks it. An event still counts only for a known step, an `https://` page on that step's host and, for the GitHub sign-in, a code of the user-code shape. Its inputs and result shape are unchanged, and the last progress line it reports never shows an event line.
13
+ - `publish` refuses a site whose own `@nera-static/nera` is older than 1.27.0 (or whose version cannot be read) before it starts anything, with a hint to run `npm update` in the site: an older CLI writes no event lines, so the sign-in code would never reach the assistant. A publish already running is still reported.
14
+ - Requires `@nera-static/nera` ^1.27.0 (was ^1.26.0), the first release whose `publish --json` writes the event lines.
15
+
16
+ ## [1.2.1] - 2026-11-19
17
+
18
+ ### Changed
19
+
20
+ - `add_plugin` installs the plugin with `addPlugin()` from `@nera-static/nera` inside the server instead of running `npm install`, its own config copy and the package's template script itself. Its inputs, refusals and result shape are unchanged; the result's `log` holds `addPlugin`'s progress lines, while npm's and the template script's output goes to the server's log (stderr). Cancelling the call stops the running command, and with `NERA_MCP_RUNTIME=bundled` it gets the same environment as every other command.
21
+ - `add_plugin` refuses a config folder or `config/<name>.yaml` that is a symbolic link out of the site before anything is installed.
22
+ - Requires `@nera-static/nera` ^1.26.0 (was ^1.25.0), the first release with `addPlugin`.
23
+
24
+ ### Fixed
25
+
26
+ - `add_plugin` accepts `plugin-<name>` (e.g. `plugin-tags`) like the CLI; it used to ask npm for `@nera-static/plugin-plugin-tags`.
27
+
8
28
  ## [1.2.0] - 2026-11-18
9
29
 
10
30
  ### Added
package/README.md CHANGED
@@ -106,13 +106,13 @@ A **site** is a folder under the root (or the root itself) whose `package.json`
106
106
  | `get_site` | A site's configuration, pages, plugins and theme |
107
107
  | `read_page`, `write_page`, `delete_page` | A Markdown page with its frontmatter; `write_page` refuses frontmatter without `layout` |
108
108
  | `read_file`, `write_file` | Configuration, templates and assets inside a site |
109
- | `add_plugin` | Installs an `@nera-static/plugin-*`, copies its default config and publishes its templates |
109
+ | `add_plugin` | Installs an official plugin (`@nera-static/plugin-<name>`, `plugin-<name>` or `<name>`) as `nera add` does: the package, its default config and its templates |
110
110
  | `build` | `nera build`, optionally with the output checks (`check: true`) |
111
111
  | `validate` | `nera validate`: the site's layouts, includes and YAML, as `{ file, line, severity, rule, message }` records |
112
112
  | `preview` | Starts `nera dev` and returns the local address; `stop: true` stops it |
113
113
  | `publish` | `nera publish` to GitHub Pages or Netlify; returns the sign-in code for you, then the live address |
114
114
 
115
- `create_site`, `validate` and the catalogs call `@nera-static/nera`'s own functions inside the server; `build`, `preview`, `publish` and `add_plugin` run commands, through the site's own `@nera-static/nera` when it has one installed, so the assistant gets the same results as you do in a terminal. A preview or a publish keeps running between calls and stops when the client closes the server.
115
+ `create_site`, `add_plugin`, `validate` and the catalogs call `@nera-static/nera`'s own functions inside the server; `build`, `preview` and `publish` run commands, through the site's own `@nera-static/nera` when it has one installed, so the assistant gets the same results as you do in a terminal. A preview or a publish keeps running between calls and stops when the client closes the server.
116
116
 
117
117
  ### Resources
118
118
 
@@ -141,7 +141,7 @@ A **site** is a folder under the root (or the root itself) whose `package.json`
141
141
  ## Compatibility
142
142
 
143
143
  - Node.js 22.12 or later
144
- - Brings `@nera-static/nera` 1.25.0 for sites that have none installed. A site with its own CLI installed runs that one: `build` needs 1.9.0 or later (`--json`), `publish` 1.19.0 (1.20.0 for Netlify). `npm update` in the site brings it up to date.
144
+ - Brings `@nera-static/nera` 1.27.0 for sites that have none installed. A site with its own CLI installed runs that one: `build` needs 1.9.0 or later (`--json`), `publish` 1.27.0 or later for GitHub Pages and Netlify alike (its sign-in events), and refuses an older one. `npm update` in the site brings it up to date.
145
145
 
146
146
  ## License
147
147
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nera-static/mcp",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "A local MCP server for Nera: lets an AI assistant create, edit, build, validate, preview and publish Nera static sites under one folder",
5
5
  "type": "module",
6
6
  "files": [
@@ -47,7 +47,7 @@
47
47
  "dependencies": {
48
48
  "@modelcontextprotocol/sdk": "^1.32.2",
49
49
  "@nera-static/core": "^4.18.3",
50
- "@nera-static/nera": "^1.25.0",
50
+ "@nera-static/nera": "^1.27.0",
51
51
  "yaml": "^2.9.1",
52
52
  "zod": "^4.6.7"
53
53
  },
@@ -37,8 +37,9 @@ Eleventy, Hugo, Astro or Jekyll; do not apply their conventions.
37
37
  frontmatter that names its `layout`. Site name, language and texts for
38
38
  templates go in `config/app.yaml`. Shared markup goes in `theme/views/`.
39
39
  3. **Plugins.** Look for a plugin before writing a feature (see below).
40
- Install it, configure it in `config/<name>.yaml`, copy its templates with
41
- its own binary and include them in a layout.
40
+ `npx nera add <name>` installs it, copies its default `config/<name>.yaml`
41
+ (an existing one is kept) and its templates; configure it there and
42
+ include the templates in a layout.
42
43
  4. **Validate.** `npx nera validate` and fix every error it reports. It
43
44
  finds broken layouts and includes and pages the build would skip.
44
45
  5. **Build and check.** `npx nera build --check` and fix what it reports
@@ -78,8 +79,14 @@ and refreshes `AGENTS.md` and this skill.
78
79
 
79
80
  ## Look for a plugin before writing a feature
80
81
 
81
- Features come from npm packages named `@nera-static/plugin-<name>`. An
82
- installed plugin loads on the next build, with nothing to register. Do not
82
+ Features come from npm packages named `@nera-static/plugin-<name>`. Add one
83
+ with `npx nera add <name>` (e.g. `npx nera add sitemap`): it installs the
84
+ package, copies the plugin's default `config/<name>.yaml` when the site has
85
+ none and copies its templates into `theme/views/vendor/plugin-<name>/`, if
86
+ it has any. That copy is skipped when the folder already exists;
87
+ `npx nera-<name> --force`, the plugin's own binary, overwrites it. Templates
88
+ are not used until you include them. An added plugin loads on the next
89
+ build, with nothing to register. Do not
83
90
  hand-write navigation, a contact form, tags, search, pagination, image
84
91
  handling, a sitemap, a feed or a consent banner: a plugin exists for each.
85
92
  The catalog: https://github.com/seebaermichi/nera/blob/main/PLUGINS.md
@@ -89,7 +96,7 @@ feed, images, link-attributes, navigation, one-page, page-navigation,
89
96
  page-pagination, popular-content, search, simple-page-list, sitemap,
90
97
  social-media-links, stacks, statistics, tags. Each plugin's README (on npm, or
91
98
  `github.com/seebaermichi/nera-plugin-<name>`) lists its config keys and its
92
- template binary. Read it before you configure the plugin.
99
+ templates. Read it before you configure the plugin.
93
100
 
94
101
  A feature no plugin covers can be a local plugin in
95
102
  `src/plugins/<name>/index.js`; see the tutorial
@@ -21,24 +21,24 @@ different files.
21
21
  `pages/posts/first-post.md`, each with `layout`, `title`, `description`,
22
22
  `date` (`2026-10-12`) and `tags` (`tags: travel, food` or a YAML list).
23
23
  A post is served at `/posts/first-post.html`.
24
- 3. Post list: `npm install @nera-static/plugin-simple-page-list`, set
25
- `page_path: /posts`, `sortBy: date` and `sortOrder: descending` in
26
- `config/simple-page-list.yaml`, run
27
- `npx nera-simple-page-list`, and include the list in the template of the
28
- home page (data: `app.pageList`).
29
- 4. Tags: `npm install @nera-static/plugin-tags`. It builds a page per tag
30
- at `/tags/<tag>.html`. Run `npx nera-tags` and include
31
- `partials/tag-links` in the post template and `partials/tag-cloud` where
32
- you want all tags.
33
- 5. Previous/next: `npm install @nera-static/plugin-page-pagination`, give
34
- each post a `pagination_order` number, run `npx nera-page-pagination`
35
- and include it in the post template. It links pages of the same folder.
24
+ 3. Post list: `npx nera add simple-page-list`. Its copied
25
+ `config/simple-page-list.yaml` already lists `page_paths: [/posts]`,
26
+ newest `date` first; include the published template in the home page's
27
+ template (data: `app.pageList.posts`).
28
+ 4. Tags: `npx nera add tags`. It builds a page per tag at
29
+ `/tags/<tag>.html`. Include the published `partials/tag-links` in the
30
+ post template and `partials/tag-cloud` where you want all tags. Delete
31
+ the sample `tag_overview_*_image` lines and `tag_overview_meta` from the
32
+ copied `config/tags.yaml`: they point at images the site does not have.
33
+ 5. Previous/next: `npx nera add page-pagination`, give each post a
34
+ `pagination_order` number and include the published template in the post
35
+ template. It links pages of the same folder.
36
36
  6. A post template of its own: `theme/views/pages/post.pug`, extending
37
37
  `../layouts/layout` like `pages/default.pug`, with exactly one `main`.
38
38
  Posts then use `layout: pages/post.pug`.
39
- 7. Sitemap: `npm install @nera-static/plugin-sitemap` and set `origin` in
40
- `config/app.yaml`. It also writes `robots.txt`.
41
- 8. Menu: `@nera-static/plugin-navigation`, as in
39
+ 7. Sitemap: `npx nera add sitemap` and set `origin` in `config/app.yaml`.
40
+ It also writes `robots.txt`.
41
+ 8. Menu: `npx nera add navigation`, as in
42
42
  [business-site](business-site.md).
43
43
  9. `npx nera validate`, then `npx nera build --check`; fix what they report.
44
44
 
@@ -48,7 +48,8 @@ before step 3, 4 or 5.
48
48
  ## Files touched
49
49
 
50
50
  `pages/posts/*.md`, `pages/index.md`, `config/app.yaml`,
51
- `config/simple-page-list.yaml`, `config/tags.yaml` (optional),
51
+ `config/simple-page-list.yaml`, `config/tags.yaml`,
52
+ `config/page-pagination.yaml`, `config/sitemap.yaml`,
52
53
  `theme/views/pages/post.pug`, `theme/views/vendor/plugin-*/`,
53
54
  `package.json`.
54
55
 
@@ -24,16 +24,16 @@ below build the site by hand instead, with different files.
24
24
  `pages/imprint.md` and `pages/privacy.md` as placeholders, linked from
25
25
  the layout's footer: replace their text, or write them if they are
26
26
  missing.
27
- 4. Menu: `npm install @nera-static/plugin-navigation`, list the pages in
28
- `config/navigation.yaml` (`href` ending in `.html`, `name`; groups such
29
- as `main:` and `footer:`; a footer menu replaces the layout's own
30
- imprint and privacy links, so keep only one of the two), run
31
- `npx nera-navigation` and include a menu in
27
+ 4. Menu: `npx nera add navigation`, then replace the sample entry in the
28
+ copied `config/navigation.yaml` with the pages (`href` ending in
29
+ `.html`, `name`; groups such as `main:` and `footer:`; a footer menu
30
+ replaces the layout's own imprint and privacy links, so keep only one of
31
+ the two), and include a published menu in
32
32
  `theme/views/layouts/layout.pug` (see the plugin README for the mixins).
33
33
  5. Contact form: follow [contact-form](contact-form.md).
34
- 6. Optional, for search engines: `@nera-static/plugin-sitemap` (needs
35
- `origin`) and `@nera-static/plugin-canonical-links`. Social profiles:
36
- `@nera-static/plugin-social-media-links`.
34
+ 6. Optional, for search engines: `npx nera add sitemap` (needs `origin`)
35
+ and `npx nera add canonical-links`. Social profiles:
36
+ `npx nera add social-media-links`.
37
37
  7. Styles: a CSS file in `theme/assets/css/`, linked from the layout's
38
38
  `head` (`link(rel="stylesheet" href="/css/main.css")`).
39
39
  8. `npx nera validate`, then `npx nera build --check`; fix what they report.
@@ -6,10 +6,14 @@ Do not hand-write a `<form>` or post to a third-party service.
6
6
 
7
7
  ## Steps
8
8
 
9
- 1. `npm install @nera-static/plugin-contact-form`
10
- 2. Create `config/contact-form.yaml`. `recipient` and at least one field
11
- are required; without them the form does not render and the build only
12
- warns:
9
+ 1. `npx nera add contact-form` installs the plugin, copies its default
10
+ `config/contact-form.yaml`, the form to
11
+ `theme/views/vendor/plugin-contact-form/` and its script to
12
+ `theme/assets/js/contact-form.js`.
13
+ 2. Edit the copied `config/contact-form.yaml`: put the real address in
14
+ `recipient` (the copy has the placeholder `hello@example.com`).
15
+ `recipient` and at least one field are required; without them the form
16
+ does not render and the build only warns. A minimal config:
13
17
 
14
18
  ```yaml
15
19
  recipient: hello@example.com
@@ -31,10 +35,7 @@ Do not hand-write a `<form>` or post to a third-party service.
31
35
  Field types: `text`, `email`, `tel`, `textarea`, `select`, `checkbox`,
32
36
  `radio`. The README lists the optional keys (subject, labels, honeypot,
33
37
  `consent_text` with a link to the privacy page).
34
- 3. `npx nera-contact-form` copies the form to
35
- `theme/views/vendor/plugin-contact-form/` and its script to
36
- `theme/assets/js/contact-form.js`.
37
- 4. A page template for the contact page, `theme/views/pages/contact.pug`:
38
+ 3. A page template for the contact page, `theme/views/pages/contact.pug`:
38
39
 
39
40
  ```pug
40
41
  extends ../layouts/layout
@@ -45,9 +46,9 @@ Do not hand-write a `<form>` or post to a third-party service.
45
46
  include /vendor/plugin-contact-form/contact-form
46
47
  ```
47
48
 
48
- 5. `pages/contact.md` with `layout: pages/contact.pug`, a `title` and a
49
+ 4. `pages/contact.md` with `layout: pages/contact.pug`, a `title` and a
49
50
  short text above the form.
50
- 6. `npx nera validate`, then `npx nera build --check`. Open
51
+ 5. `npx nera validate`, then `npx nera build --check`. Open
51
52
  `/contact.html` with `npm run dev` and submit once: the mail client
52
53
  should open with the message filled in.
53
54
 
@@ -6,7 +6,8 @@ Responsive images with `@nera-static/plugin-images`: each picture becomes a
6
6
 
7
7
  ## Steps
8
8
 
9
- 1. `npm install @nera-static/plugin-images`
9
+ 1. `npx nera add images` installs the plugin and copies its `picture`
10
+ mixin to `theme/views/vendor/plugin-images/`.
10
11
  2. Put the originals in the assets folder, e.g. `theme/assets/images/`.
11
12
  They are referenced without `theme/assets`: `/images/photo.jpg`.
12
13
  3. In Markdown, write images as usual; the plugin rewrites them:
@@ -14,8 +15,7 @@ Responsive images with `@nera-static/plugin-images`: each picture becomes a
14
15
  (`![Alt](/images/pier.jpg "Caption")`), and query parameters crop or
15
16
  size one image (`?w=800&ratio=16:9`, see the README).
16
17
  4. In frontmatter, `image: /images/hero.jpg` gets precomputed variants for
17
- templates. Run `npx nera-images` to copy the `picture` mixin to
18
- `theme/views/vendor/plugin-images/`, then in a template:
18
+ templates. Show them with the copied `picture` mixin in a template:
19
19
 
20
20
  ```pug
21
21
  include /vendor/plugin-images/picture
@@ -24,17 +24,16 @@ instead, with different files.
24
24
  `title`, `description`, `date` and `image: /images/<file>.jpg` (the cover
25
25
  picture). Show more photos in the body with
26
26
  `![Alt text](/images/<file>.jpg "Caption")`.
27
- 4. Project list: `npm install @nera-static/plugin-simple-page-list`, set
28
- `page_path: /projects` in `config/simple-page-list.yaml`, run
29
- `npx nera-simple-page-list`, and render `app.pageList` on the home page.
30
- For a grid with cover images, loop over `app.pageList` in your own Pug
31
- template instead of the published one.
27
+ 4. Project list: `npx nera add simple-page-list`, change `page_paths` in
28
+ the copied `config/simple-page-list.yaml` to `[/projects]`, and render
29
+ `app.pageList.projects` on the home page. For a grid with cover images,
30
+ loop over it in your own Pug template instead of the published one.
32
31
  5. A project template, `theme/views/pages/project.pug`, extending
33
32
  `../layouts/layout`, that shows the cover with the images plugin's
34
33
  `+picture` mixin and then `content`, with exactly one `main`.
35
- 6. Optional: `@nera-static/plugin-tags` to group projects by kind,
36
- `@nera-static/plugin-page-pagination` for previous/next project,
37
- `@nera-static/plugin-social-media-links`, `@nera-static/plugin-sitemap`.
34
+ 6. Optional, each with `npx nera add <name>`: `tags` to group projects by
35
+ kind, `page-pagination` for previous/next project, `social-media-links`,
36
+ `sitemap`.
38
37
  7. `npx nera validate`, then `npx nera build --check`. The check reports
39
38
  images without alt text; describe what each picture shows.
40
39
 
@@ -5,13 +5,12 @@ JSON index, a small script searches it in the browser. No backend.
5
5
 
6
6
  ## Steps
7
7
 
8
- 1. `npm install @nera-static/plugin-search`. It works without config;
9
- `config/search.yaml` can change the indexed `fields` or set
10
- `group_by_lang: true` for one index per language.
11
- 2. `npx nera-search` copies the search template to
12
- `theme/views/vendor/plugin-search/` and its script to
8
+ 1. `npx nera add search` installs the plugin, copies its default
9
+ `config/search.yaml` (change the indexed `fields` there, or set
10
+ `group_by_lang: true` for one index per language), the search template
11
+ to `theme/views/vendor/plugin-search/` and its script to
13
12
  `theme/assets/js/search.js`.
14
- 3. A page template for the search page, `theme/views/pages/search.pug`:
13
+ 2. A page template for the search page, `theme/views/pages/search.pug`:
15
14
 
16
15
  ```pug
17
16
  extends ../layouts/layout
@@ -22,27 +21,27 @@ JSON index, a small script searches it in the browser. No backend.
22
21
  include /vendor/plugin-search/search.pug
23
22
  ```
24
23
 
25
- 4. `pages/search.md` with `layout: pages/search.pug`, a `title` and a
24
+ 3. `pages/search.md` with `layout: pages/search.pug`, a `title` and a
26
25
  `# Search` heading, and `show_title: false` in `config/search.yaml`, so
27
- that heading is the page's only `h1` (without the key the template adds
28
- its own and `nera build --check` warns `a11y-h1`). Link the page from
29
- the menu.
30
- 5. The template's input is already labelled (`aria-label`, default
26
+ that heading is the page's only `h1` (with the copy's `show_title: true`
27
+ the template adds its own and `nera build --check` warns `a11y-h1`).
28
+ Link the page from the menu.
29
+ 4. The template's input is already labelled (`aria-label`, default
31
30
  "Search"). To translate the template, add `search_label`, `search_title`
32
31
  and `search_placeholder` to the site's translations. A copy published
33
32
  before plugin-search 2.3.0 lacks both: refresh it with
34
33
  `npx nera-search --force` if it was never edited.
35
- 6. The index is written to `theme/assets/search-index.json` on every build
34
+ 5. The index is written to `theme/assets/search-index.json` on every build
36
35
  and served as `/search-index.json`. It is generated: add
37
36
  `theme/assets/search-index*.json` to `.gitignore`.
38
- 7. Only pages with a `layout` are indexed. If other plugins add pages (tags),
37
+ 6. Only pages with a `layout` are indexed. If other plugins add pages (tags),
39
38
  run search last with `config/plugin-order.yaml` as the README shows.
40
- 8. `npx nera validate`, then `npx nera build --check`; try a query with
39
+ 7. `npx nera validate`, then `npx nera build --check`; try a query with
41
40
  `npm run dev`.
42
41
 
43
42
  ## Files touched
44
43
 
45
- `package.json`, `config/search.yaml` (optional), `pages/search.md`,
44
+ `package.json`, `config/search.yaml`, `pages/search.md`,
46
45
  `theme/views/pages/search.pug`, `theme/views/vendor/plugin-search/`,
47
46
  `theme/assets/js/search.js`, `.gitignore`.
48
47
 
package/src/runner.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { spawn as nodeSpawn } from 'node:child_process'
2
- import { existsSync } from 'node:fs'
2
+ import { existsSync, readFileSync } from 'node:fs'
3
3
  import { createRequire } from 'node:module'
4
4
  import path from 'node:path'
5
5
  import { activeShim, npmScripts, ownNpm, withPathPrefix } from './runtime.js'
@@ -27,6 +27,23 @@ export function neraBin(cwd) {
27
27
  return path.join(path.dirname(require.resolve('@nera-static/nera/package.json')), 'bin', 'nera.js')
28
28
  }
29
29
 
30
+ /**
31
+ * The version of the `@nera-static/nera` whose script `neraBin(cwd)` names:
32
+ * the `version` of the `package.json` two folders above it. Read synchronously,
33
+ * so a caller can check it and start a run without yielding in between.
34
+ *
35
+ * @param {string} cwd
36
+ * @returns {string|null} null when the file cannot be read or carries no string `version`
37
+ */
38
+ export function neraVersion(cwd) {
39
+ try {
40
+ const { version } = JSON.parse(readFileSync(path.join(path.dirname(neraBin(cwd)), '..', 'package.json'), 'utf8'))
41
+ return typeof version === 'string' ? version : null
42
+ } catch {
43
+ return null
44
+ }
45
+ }
46
+
30
47
  /**
31
48
  * How to start npm without a shell: its `npm-cli.js` from the server's own
32
49
  * `node_modules/npm` (the Desktop extension bundles one) or next to the running
package/src/server.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
2
- import { createSite as neraCreateSite } from '@nera-static/nera'
2
+ import { addPlugin as neraAddPlugin, createSite as neraCreateSite } from '@nera-static/nera'
3
3
  import pkg from '../package.json' with { type: 'json' }
4
4
  import { registerCatalogTools } from './catalog.js'
5
5
  import { realRoot } from './paths.js'
@@ -19,8 +19,9 @@ import { registerSiteTools } from './tools/sites.js'
19
19
  *
20
20
  * @param {object} options
21
21
  * @param {string} options.root the folder the server may work in; every path a tool takes is checked against it
22
- * @param {ReturnType<typeof createRunner>} [options.runner] runs the `nera`, `npm` and `node` commands (injected so tests spawn nothing)
22
+ * @param {ReturnType<typeof createRunner>} [options.runner] runs the `nera` commands `build` starts (injected so tests spawn nothing)
23
23
  * @param {typeof neraCreateSite} [options.createSite] writes a new site's files for `create_site` (the CLI's `createSite`; injected so tests need no network for package and GitHub starters)
24
+ * @param {typeof neraAddPlugin} [options.addPlugin] installs a plugin for `add_plugin` (the CLI's `addPlugin`; injected so tests need no network)
24
25
  * @param {typeof fetch} [options.fetch] fetches the npm registry catalogs (injected so tests stay offline)
25
26
  * @param {string} [options.docsFile] the bundled `llms-full.txt` (default: the package's `docs/`; injected so tests can point at a missing one)
26
27
  * @param {ReturnType<typeof createProcesses>} [options.processes] tracks the children that outlive a call (`preview`, `publish`); all are stopped when the server closes
@@ -28,8 +29,8 @@ import { registerSiteTools } from './tools/sites.js'
28
29
  * @returns {Promise<McpServer>}
29
30
  * @throws {import('./paths.js').PathError} when `root` does not exist or is not a folder
30
31
  */
31
- export async function createServer({ root, runner = createRunner(), createSite = neraCreateSite, fetch = globalThis.fetch, docsFile, processes = createProcesses(), timing }) {
32
- const ctx = { root: await realRoot(root), runner, createSite, fetch, docsFile, processes, timing }
32
+ export async function createServer({ root, runner = createRunner(), createSite = neraCreateSite, addPlugin = neraAddPlugin, fetch = globalThis.fetch, docsFile, processes = createProcesses(), timing }) {
33
+ const ctx = { root: await realRoot(root), runner, createSite, addPlugin, fetch, docsFile, processes, timing }
33
34
  const server = new McpServer(
34
35
  { name: pkg.name, version: pkg.version },
35
36
  {
package/src/tools/cli.js CHANGED
@@ -2,7 +2,7 @@ import fs from 'node:fs/promises'
2
2
  import path from 'node:path'
3
3
  import { hasErrors, validate } from '@nera-static/nera'
4
4
  import { z } from 'zod'
5
- import { PathError, resolveInRoot } from '../paths.js'
5
+ import { resolveInRoot } from '../paths.js'
6
6
  import { ok, tool, ToolError } from '../results.js'
7
7
  import { childEnv } from '../runner.js'
8
8
  import { relativeTo, resolveSite, siteFolders, siteInput } from './sites.js'
@@ -58,67 +58,24 @@ async function starterArg(ctx, starter) {
58
58
  }
59
59
 
60
60
  /**
61
- * The npm package of an `add_plugin` spec: `@nera-static/plugin-<name>` or
62
- * just `<name>`; anything else (another scope, a version, a path, a URL) is
61
+ * The npm package of an `add_plugin` spec, in the same forms the CLI's
62
+ * addPlugin takes: `@nera-static/plugin-<name>`, `plugin-<name>` or just
63
+ * `<name>`; anything else (another scope, a version, a path, a URL) is
63
64
  * refused.
64
65
  */
65
66
  function pluginPackage(spec) {
66
- const name = spec.startsWith(`${PLUGIN_SCOPE}plugin-`) ? spec.slice(`${PLUGIN_SCOPE}plugin-`.length) : spec
67
+ const name = spec.replace(new RegExp(`^(${PLUGIN_SCOPE}plugin-|plugin-)`), '')
67
68
  if (!PLUGIN_NAME.test(name) || NOT_PLUGINS.has(name)) {
68
- throw new ToolError(`"${spec}" is not a Nera plugin. Pass an official plugin as \`@nera-static/plugin-<name>\` or just \`<name>\` (e.g. \`sitemap\`); call list_plugins for the catalog.`)
69
+ throw new ToolError(`"${spec}" is not a Nera plugin. Pass an official plugin as \`@nera-static/plugin-<name>\`, \`plugin-<name>\` or just \`<name>\` (e.g. \`sitemap\`); call list_plugins for the catalog.`)
69
70
  }
70
71
  return { name, pkg: `${PLUGIN_SCOPE}plugin-${name}` }
71
72
  }
72
73
 
73
- /**
74
- * Copies the plugin's default `config/<name>.yaml` into the site's config
75
- * folder when the site has none, so the model can read and edit it.
76
- *
77
- * @returns {Promise<{ file: string, status: 'copied'|'kept'|'none' }>}
78
- */
79
- async function copyDefaultConfig(dir, packageDir, configFolder, name) {
80
- const target = await resolveInRoot(dir, path.join(configFolder, `${name}.yaml`), { label: 'plugin config file' })
81
- const file = relativeTo(dir, target)
82
- let source
83
- try {
84
- source = await resolveInRoot(dir, path.join(packageDir, 'config', `${name}.yaml`), { label: 'plugin default config' })
85
- await fs.access(source)
86
- } catch (error) {
87
- if (error instanceof PathError || error.code === 'ENOENT') return { file, status: 'none' }
88
- throw error
89
- }
90
- await fs.mkdir(path.dirname(target), { recursive: true })
91
- try {
92
- await fs.copyFile(source, target, fs.constants.COPYFILE_EXCL)
93
- return { file, status: 'copied' }
94
- } catch (error) {
95
- if (error.code === 'EEXIST') return { file, status: 'kept' }
96
- throw error
97
- }
98
- }
99
-
100
- /**
101
- * The package's template-publishing script (the `bin` entry that points at
102
- * `publish-template.js`), checked to stay inside the site, or null.
103
- */
104
- async function publishTemplateScript(dir, packageDir) {
105
- let pkg
106
- try {
107
- pkg = JSON.parse(await fs.readFile(path.join(dir, packageDir, 'package.json'), 'utf8'))
108
- } catch {
109
- return null
110
- }
111
- const bins = typeof pkg.bin === 'string' ? [pkg.bin] : Object.values(pkg.bin ?? {})
112
- const script = bins.find((bin) => typeof bin === 'string' && path.basename(bin) === 'publish-template.js')
113
- if (!script) return null
114
- return resolveInRoot(dir, path.join(packageDir, script), { label: 'plugin template script' })
115
- }
116
-
117
74
  /**
118
75
  * Registers `create_site`, `build`, `validate` and `add_plugin`.
119
76
  *
120
77
  * @param {import('@modelcontextprotocol/sdk/server/mcp.js').McpServer} server
121
- * @param {{ root: string, runner: ReturnType<typeof import('../runner.js').createRunner>, createSite: typeof import('@nera-static/nera').createSite }} ctx `create_site` installs through `createSite`, the other tools through `runner`
78
+ * @param {{ root: string, runner: ReturnType<typeof import('../runner.js').createRunner>, createSite: typeof import('@nera-static/nera').createSite, addPlugin: typeof import('@nera-static/nera').addPlugin }} ctx `create_site` installs through `createSite`, `add_plugin` through `addPlugin`, `build` through `runner`
122
79
  */
123
80
  export function registerCliTools(server, ctx) {
124
81
  server.registerTool('create_site', {
@@ -225,38 +182,41 @@ export function registerCliTools(server, ctx) {
225
182
  description: 'Installs an official Nera plugin into a site (npm install), copies its default configuration to `config/<name>.yaml` when the site has none, and copies its Pug templates to `views/vendor/plugin-<name>/` when it ships any. Call list_plugins for the catalog. Afterwards read the plugin\'s config with read_file and include its templates in a layout with write_file, then validate.',
226
183
  inputSchema: {
227
184
  site: siteInput,
228
- plugin: z.string().describe('The plugin, as `@nera-static/plugin-<name>` or just `<name>` (e.g. `sitemap`, `tags`).'),
185
+ plugin: z.string().describe('The plugin, as `@nera-static/plugin-<name>`, `plugin-<name>` or just `<name>` (e.g. `sitemap`, `tags`).'),
229
186
  },
230
187
  }, tool(async ({ site, plugin }, { signal }) => {
231
188
  const { name, pkg } = pluginPackage(plugin)
232
189
  const resolved = await resolveSite(ctx, site)
233
- const install = await ctx.runner('npm', ['install', pkg], { cwd: resolved.dir, signal })
234
- if (install.code !== 0) {
235
- throw new ToolError(`Installing ${pkg} failed: ${failureText(install)}`)
236
- }
237
-
238
- const packageDir = path.join('node_modules', ...pkg.split('/'))
190
+ // addPlugin writes `<folders.config>/<name>.yaml` without checking
191
+ // where it leads, so a config folder or file that is a symbolic link
192
+ // out of the site is refused here, before npm runs.
239
193
  const { model } = await siteFolders(resolved.dir)
240
- const config = await copyDefaultConfig(resolved.dir, packageDir, model.folders.config, name)
194
+ await resolveInRoot(resolved.dir, path.join(model.folders.config, `${name}.yaml`), { label: 'plugin config file' })
241
195
 
242
- let templates = 'none'
243
- const script = await publishTemplateScript(resolved.dir, packageDir)
244
- if (script) {
245
- const publish = await ctx.runner('node', [script], { cwd: resolved.dir, signal })
246
- if (publish.code !== 0) {
247
- throw new ToolError(`${pkg} is installed, but copying its templates failed: ${failureText(publish)}`)
248
- }
249
- templates = 'published'
196
+ // As for create_site: every progress line is collected for the
197
+ // result, npm's and the template script's output goes to stderr
198
+ // (addPlugin's default), `env` is a child's and the call's signal
199
+ // stops the running child.
200
+ const lines = []
201
+ let added
202
+ try {
203
+ added = await ctx.addPlugin(pkg, { cwd: resolved.dir, signal, env: childEnv(), log: (line) => lines.push(line) })
204
+ } catch (error) {
205
+ // A command that ran and failed (npm install, the template
206
+ // script) carries its exit code; its own output is not captured.
207
+ const childFailed = !signal.aborted && typeof error.cause?.code === 'number'
208
+ throw new ToolError(childFailed ? `${error.message}\nThe command's own output is in the server's log. Fix what it reports (for npm often the network connection), then call add_plugin again.` : error.message)
250
209
  }
251
210
 
211
+ const { config, templates } = added
252
212
  const steps = [
253
213
  config.status === 'copied' ? `its configuration is in ${config.file}` : null,
254
214
  config.status === 'kept' ? `the site's own ${config.file} was kept` : null,
255
215
  templates === 'published' ? 'its templates are in the site\'s views/vendor folder' : null,
256
216
  ].filter(Boolean)
257
217
  return ok(
258
- { site: resolved.site, plugin: pkg, config, templates, log: tail(install.stdout) },
259
- `Installed ${pkg} in "${resolved.site}"${steps.length ? `; ${steps.join(', ')}` : ''}. Then call validate.`,
218
+ { site: resolved.site, plugin: added.plugin, config, templates, log: tail(lines.join('\n')) },
219
+ `Installed ${added.plugin} in "${resolved.site}"${steps.length ? `; ${steps.join(', ')}` : ''}. Then call validate.`,
260
220
  )
261
221
  }))
262
222
  }
@@ -1,6 +1,7 @@
1
1
  import { z } from 'zod'
2
2
  import { freePort } from '../processes.js'
3
3
  import { ok, tool, ToolError } from '../results.js'
4
+ import { neraVersion } from '../runner.js'
4
5
  import { failureText } from './cli.js'
5
6
  import { resolveSite, siteInput } from './sites.js'
6
7
 
@@ -12,6 +13,8 @@ export const PUBLISH_WAIT_MS = 30 * 1000
12
13
  const PUBLISH_TARGETS = ['github-pages', 'netlify']
13
14
  /** How much of the CLI's last progress line a status carries. */
14
15
  const PROGRESS_MAX = 300
16
+ /** The first `@nera-static/nera` whose `publish --json` writes the event lines `pendingAction` reads. */
17
+ const PUBLISH_CLI_FLOOR = '1.27.0'
15
18
 
16
19
  /** Terminal colour codes (ESC [ … m), in case a child ignores NO_COLOR. Built from a string so the source holds no control character. */
17
20
  const ANSI = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*[A-Za-z]`, 'g')
@@ -19,33 +22,19 @@ const ANSI = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*[A-Za-z]`, 'g')
19
22
  const LOCAL_URL = /Local:\s+(https?:\/\/[^\s]+)/
20
23
 
21
24
  /**
22
- * The lines of `nera publish` that ask the user to do something in the
23
- * browser, and the lines that say it is done. Only these fixed shapes are
24
- * read: the GitHub user code and verification page (the code is what the
25
- * user types; it is not a credential — the device code and the tokens never
26
- * appear in the CLI's output), the GitHub App installation page, and the
27
- * Netlify authorization page.
25
+ * The browser steps `nera publish --json` (@nera-static/nera ≥ 1.27.0)
26
+ * announces as event lines on stderr, `{"event":"action_required","action":
27
+ * {kind,code?,url}}` and `{"event":"action_done","kind"}`, and the host each
28
+ * one's page must be on. An event counts only in this shape: a known kind, an
29
+ * `https://` page on its host and, for the GitHub sign-in, a user code of the
30
+ * user-code shape (what the user types; it is not a credential — the device
31
+ * code and the tokens never appear in the CLI's output).
28
32
  */
29
- const ACTIONS = [
30
- {
31
- kind: 'github_sign_in',
32
- match: /To sign in to GitHub, enter the code ([A-Z0-9]{4,8}-[A-Z0-9]{4,8}) at (https:\/\/github\.com\/\S+)/,
33
- action: ([, code, url]) => ({ kind: 'github_sign_in', code, url }),
34
- done: /^Signed in as /,
35
- },
36
- {
37
- kind: 'github_app_install',
38
- match: /Install it at (https:\/\/github\.com\/apps\/\S+)/,
39
- action: ([, url]) => ({ kind: 'github_app_install', url }),
40
- done: /^Nera Static is installed on /,
41
- },
42
- {
43
- kind: 'netlify_sign_in',
44
- match: /To sign in to Netlify, open (https:\/\/app\.netlify\.com\/\S+) and choose "Authorize"/,
45
- action: ([, url]) => ({ kind: 'netlify_sign_in', url }),
46
- done: /^Signed in to Netlify/,
47
- },
48
- ]
33
+ const ACTIONS = {
34
+ github_sign_in: { host: 'github.com', code: /^[A-Z0-9]{4,8}-[A-Z0-9]{4,8}$/ },
35
+ github_app_install: { host: 'github.com' },
36
+ netlify_sign_in: { host: 'app.netlify.com' },
37
+ }
49
38
 
50
39
  const INSTRUCTIONS = {
51
40
  github_sign_in: ({ code, url }) => `Ask the user to open ${url} and enter the code ${code}, then call publish again.`,
@@ -58,8 +47,49 @@ function lines(text) {
58
47
  }
59
48
 
60
49
  /**
61
- * What a running `nera publish` waits for: the last browser step it asked
62
- * for that it has not reported done since, or null.
50
+ * The event a line of `nera publish --json` carries, or null for a log line
51
+ * (and for a line that starts with `{` but is no JSON object with a string
52
+ * `event`). Never throws: it runs inside `waitFor`'s predicate.
53
+ *
54
+ * @param {string} line
55
+ * @returns {{ event: string, [key: string]: unknown }|null}
56
+ */
57
+ function eventOf(line) {
58
+ if (!line.startsWith('{')) return null
59
+ try {
60
+ const parsed = JSON.parse(line)
61
+ return typeof parsed?.event === 'string' ? parsed : null
62
+ } catch {
63
+ return null
64
+ }
65
+ }
66
+
67
+ /** Whether `url` is one `https://` address, without whitespace, on exactly `host`. */
68
+ function onHost(url, host) {
69
+ if (typeof url !== 'string' || /\s/.test(url)) return false
70
+ try {
71
+ const parsed = new URL(url)
72
+ return parsed.protocol === 'https:' && parsed.hostname === host
73
+ } catch {
74
+ return false
75
+ }
76
+ }
77
+
78
+ /** The action of an `action_required` event, reduced to `kind`, `code?` and `url`, or null when it is not of a known shape. */
79
+ function knownAction(action) {
80
+ const kind = action?.kind
81
+ if (typeof kind !== 'string' || !Object.hasOwn(ACTIONS, kind)) return null
82
+ const known = ACTIONS[kind]
83
+ if (!onHost(action.url, known.host)) return null
84
+ if (!known.code) return { kind, url: action.url }
85
+ if (typeof action.code !== 'string' || !known.code.test(action.code)) return null
86
+ return { kind, code: action.code, url: action.url }
87
+ }
88
+
89
+ /**
90
+ * What a running `nera publish` waits for: the last browser step an
91
+ * `action_required` event asked for with no later `action_done` of the same
92
+ * kind, or null. Log lines never count, whatever they say.
63
93
  *
64
94
  * @param {string} stderr the CLI's log (`--json` mode logs to stderr)
65
95
  * @returns {{ kind: string, code?: string, url: string }|null}
@@ -67,20 +97,44 @@ function lines(text) {
67
97
  export function pendingAction(stderr) {
68
98
  let pending = null
69
99
  for (const line of lines(stderr)) {
70
- for (const known of ACTIONS) {
71
- const found = line.match(known.match)
72
- if (found) pending = known.action(found)
73
- else if (pending?.kind === known.kind && known.done.test(line)) pending = null
74
- }
100
+ const event = eventOf(line)
101
+ if (event?.event === 'action_required') pending = knownAction(event.action) ?? pending
102
+ else if (event?.event === 'action_done' && pending?.kind === event.kind) pending = null
75
103
  }
76
104
  return pending
77
105
  }
78
106
 
107
+ /** The CLI's last log line, the event lines skipped, cut to PROGRESS_MAX. */
79
108
  function lastProgress(stderr) {
80
- const last = lines(stderr).at(-1) ?? ''
109
+ const last = lines(stderr).findLast((line) => eventOf(line) === null) ?? ''
81
110
  return last.length > PROGRESS_MAX ? `${last.slice(0, PROGRESS_MAX)}…` : last
82
111
  }
83
112
 
113
+ /** `x.y.z` with an optional `-prerelease` (and `+build`, ignored), or null. */
114
+ function parseVersion(version) {
115
+ const match = typeof version === 'string' && version.match(/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/)
116
+ return match ? { numbers: match.slice(1, 4).map(Number), prerelease: match[4] !== undefined } : null
117
+ }
118
+
119
+ /**
120
+ * Whether `version` is `floor` or later, by semver precedence: major, minor
121
+ * and patch compared as numbers, and a prerelease of a version (`1.27.0-beta.1`)
122
+ * below that version. Anything that is no `x.y.z` version is not.
123
+ *
124
+ * @param {string|null} version
125
+ * @param {string} floor an `x.y.z` version without a prerelease
126
+ * @returns {boolean}
127
+ */
128
+ export function meetsFloor(version, floor) {
129
+ const have = parseVersion(version)
130
+ if (!have) return false
131
+ const need = parseVersion(floor).numbers
132
+ for (let i = 0; i < 3; i++) {
133
+ if (have.numbers[i] !== need[i]) return have.numbers[i] > need[i]
134
+ }
135
+ return !have.prerelease
136
+ }
137
+
84
138
  /**
85
139
  * The local address `nera dev` serves on, once Vite has printed it.
86
140
  *
@@ -209,6 +263,12 @@ export function registerLongRunningTools(server, ctx) {
209
263
  const key = `publish:${resolved.dir}`
210
264
  let run = ctx.processes.get(key)
211
265
  if (!run) {
266
+ // an older CLI announces no browser step as an event, so the user would never see the sign-in code
267
+ const version = neraVersion(resolved.dir)
268
+ if (!meetsFloor(version, PUBLISH_CLI_FLOOR)) {
269
+ const runs = version ? `@nera-static/nera ${version}` : 'a @nera-static/nera whose version cannot be read'
270
+ throw new ToolError(`Publishing "${resolved.site}" runs ${runs}; publish needs ${PUBLISH_CLI_FLOOR} or later. Run \`npm update\` in the site, then call publish again.`)
271
+ }
212
272
  run = ctx.processes.start(key, 'nera', publishArgs(options), { cwd: resolved.dir })
213
273
  }
214
274
  const before = pendingAction(run.stderr)