@xh/hoist-docs 1.0.0 → 1.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
@@ -37,17 +37,25 @@ The agent launches it over stdio. On start it:
37
37
  - reads the index inside each installed package that declares one (`hoistDocs` in its
38
38
  `package.json`): `@xh/hoist`, `@xh/hoist-chat-kit` if the app uses it, and any other library
39
39
  that ships an index;
40
- - fetches hoist-core's index for `hoistCoreVersion` in `gradle.properties` from Maven - Maven
41
- Central for releases, Sonatype's snapshot repository for snapshots, or an organization's mirror
40
+ - fetches hoist-core's index from Maven for the app's hoist-core version - Maven Central for
41
+ releases, Sonatype's snapshot repository for snapshots, or an organization's mirror
42
42
  (`HOIST_DOCS_MAVEN_REPO`, `HOIST_DOCS_MAVEN_SNAPSHOT_REPO`, with `HOIST_DOCS_MAVEN_USER` and
43
- `HOIST_DOCS_MAVEN_PASSWORD` if needed) - and caches it in
44
- `~/.cache/hoist-docs`;
43
+ `HOIST_DOCS_MAVEN_PASSWORD` if needed) - and caches it in `~/.cache/hoist-docs`;
44
+ - fetches, from the same repository, the index of each Grails library listed in
45
+ `hoistDocsLibraries` in `gradle.properties`, such as the organization's own plugin (see
46
+ [Shipping an index with a library](#shipping-an-index-with-a-library));
45
47
  - serves them.
46
48
 
49
+ The tool finds the hoist-core version in `gradle.lockfile`, else in `hoistCoreVersion` in
50
+ `gradle.properties`. An app that gets hoist-core through its organization's own Grails plugin
51
+ needs a committed `gradle.lockfile`, which lists hoist-core along with the plugin. To create one,
52
+ turn on dependency locking in `build.gradle` (`dependencyLocking { lockAllConfigurations() }`),
53
+ run `./gradlew dependencies --write-locks`, and commit `gradle.lockfile`.
54
+
47
55
  Every index is exactly the installed build, snapshots included. After a Hoist upgrade, restart the
48
56
  agent.
49
57
 
50
- The Maven fetch is the tool's only network call. Set the variables above in the `env` of the
58
+ Maven is the tool's only network access. Set the variables above in the `env` of the
51
59
  `.mcp.json` entry, or in the developer's environment. Behind an HTTP proxy, also set
52
60
  `NODE_USE_ENV_PROXY=1`, since Node ignores `HTTPS_PROXY` without it.
53
61
 
@@ -88,9 +96,9 @@ catalog.search('grid column renderer');
88
96
 
89
97
  ## Development
90
98
 
91
- Development requires Node 24 and pnpm; the published package runs on Node 20 or later. Node runs
92
- the TypeScript source directly; the published package is
93
- compiled (`pnpm build`, run automatically on pack).
99
+ Development requires Node 24 and pnpm. Node runs the TypeScript source directly. The published
100
+ packages, the tool and the TypeScript builder, are compiled (`pnpm build`, run automatically on
101
+ pack) and run on Node 20 or later.
94
102
 
95
103
  ```bash
96
104
  pnpm install
@@ -121,6 +129,7 @@ needs a JDK 17 or later). Each takes a library checkout and writes `<library>-<v
121
129
  pnpm build:react --root <hoist-react checkout> [--version 91.0.0]
122
130
  pnpm build:react --root <hoist-chat-kit checkout> --library chat-kit [--version 2.0.0]
123
131
  pnpm build:core --root <hoist-core checkout> [--version 45.0.0]
132
+ pnpm build:core --root <plugin checkout> --library acme --name com.acme:acme-hoist [--version 3.2.0]
124
133
  ```
125
134
 
126
135
  A TypeScript library's checkout needs its dependencies installed first, for type resolution.
@@ -136,15 +145,43 @@ version it is about to publish, for releases and snapshots alike.
136
145
  ```json
137
146
  "hoistDocs": {"id": "react", "index": "hoist-docs/index.json.gz"}
138
147
  ```
139
- An organization's own library does the same and is found the same way. Agent instructions in an
140
- index are used only from `@xh` packages.
148
+ An organization's own library does the same and is found the same way.
141
149
  - **hoist-core**, and any Grails library: depend on `io.xh:hoist-docs-builder` in a
142
150
  `docsBuilder` configuration, run it from a `JavaExec` task, and attach its output to the Maven
143
151
  publication with classifier `docs-index` and extension `json.gz` (see `buildDocsIndex` in
144
152
  hoist-core's `build.gradle`).
145
153
 
146
- The library also needs its docs and a `docs/doc-registry.json`. An XH library gets a row in
147
- `src/libraries.ts` and a golden set in `test/golden/`.
154
+ A Grails library other than hoist-core, such as an organization's own plugin, sets up the same
155
+ task with builder 2.0.0 or later and names itself in the builder's arguments:
156
+
157
+ ```groovy
158
+ args '--root', projectDir.absolutePath, '--version', version,
159
+ '--library', 'acme', '--name', 'com.acme:acme-hoist',
160
+ '--description', 'Acme extensions to hoist-core',
161
+ '--file', docsIndexFile.get().asFile.absolutePath
162
+ ```
163
+
164
+ The id prefixes the library's doc ids (`acme:docs/entitlements.md`) and is the `library`
165
+ argument agents pass. Use lowercase letters, digits and `-`, and do not reuse `react`, `core` or
166
+ `chat-kit`.
167
+
168
+ Each app that uses the library lists it in `gradle.properties`, comma-separated, and the tool
169
+ serves the version its `gradle.lockfile` locks:
170
+
171
+ ```properties
172
+ hoistDocsLibraries=com.acme:acme-hoist
173
+ ```
174
+
175
+ The tool asks `HOIST_DOCS_MAVEN_REPO` (or `HOIST_DOCS_MAVEN_SNAPSHOT_REPO`, for a snapshot) for
176
+ the index, so point those at the repository that hosts the library.
177
+
178
+ The library also needs its docs and a `docs/doc-registry.json`. Its `mcpInstructions` there go
179
+ into its index as agent guidance, for example "Read acme:docs/upgrade-notes.md before
180
+ hoist-react's upgrade notes." The tool passes that guidance to the agent from XH's libraries and
181
+ from libraries the app chose itself: listed in `client-app/package.json`, or in
182
+ `hoistDocsLibraries`. An npm library that arrives only through another is served, but its
183
+ guidance is dropped. An XH library gets a row in `src/libraries.ts`
184
+ and a golden set in `test/golden/`.
148
185
 
149
186
  ## Publishing
150
187
 
@@ -157,6 +194,7 @@ The library also needs its docs and a `docs/doc-registry.json`. An XH library ge
157
194
  version for the run, as hoist-react's does. Hotfixes run from their own branch with `is-hotfix`
158
195
  checked. Entries follow [`docs/changelog-format.md`](docs/changelog-format.md).
159
196
  - **Snapshots**: every push to `develop` publishes all three through the `Deploy Snapshot` workflow -
160
- the npm packages as `<version>.<timestamp>` under the `next` dist-tag, the Grails builder as
161
- `1.0.0-SNAPSHOT` to Sonatype's snapshot repository. Libraries depend on the builder's `next` (or,
162
- for hoist-core, its `-SNAPSHOT`), so each of their builds uses the newest builder.
197
+ the npm packages as `<version>.<timestamp>` under the `next` dist-tag, the Grails builder at
198
+ `package.json`'s `-SNAPSHOT` version to Sonatype's snapshot repository. Libraries depend on the
199
+ builder's `next` (or, for hoist-core, its `-SNAPSHOT`), so each of their builds uses the newest
200
+ builder.
@@ -17,15 +17,16 @@ export interface IndexFileSpec {
17
17
  version: string;
18
18
  path: string;
19
19
  /**
20
- * False for an index from outside the `@xh` scope, whose agent instructions are dropped, so a
21
- * dependency cannot steer the agent. Default true.
20
+ * False for an index neither from XH nor chosen by the app, whose agent instructions are
21
+ * dropped, so a dependency cannot steer the agent. Default true.
22
22
  */
23
23
  trusted?: boolean;
24
24
  }
25
25
  /** A library the project uses whose index could not be loaded, served without it. */
26
26
  export interface UnavailableLibrary {
27
27
  libraryId: string;
28
- version: string;
28
+ /** Absent when the version the project uses could not be found. */
29
+ version?: string;
29
30
  reason: string;
30
31
  }
31
32
  /** Fetch the built-in libraries' indexes from their own channels as they are asked for. */
package/dist/cli.js CHANGED
@@ -97,8 +97,9 @@ export async function main(argv, deps = {}) {
97
97
  }
98
98
  /**
99
99
  * The indexes to serve: an explicit directory (--index-dir, else a non-empty INDEX_DIR), else the
100
- * project's own - every index its installed packages ship, plus hoist-core's from Maven. In a
101
- * library checkout, libraries not installed there get their newest published snapshots.
100
+ * project's own - every index its installed packages ship, hoist-core's from Maven, and those of
101
+ * the Grails libraries it lists in `hoistDocsLibraries`. In a library checkout, libraries not
102
+ * installed there get their newest published snapshots.
102
103
  *
103
104
  * @param opts.skip - library ids not to resolve, e.g. those read from checkouts instead.
104
105
  * @param opts.lenient - skip any library that fails with a warning, rather than only optional
@@ -119,7 +120,14 @@ async function projectStore(args, deps, opts = {}) {
119
120
  version: i.version,
120
121
  path: i.path,
121
122
  trusted: i.trusted
122
- })), source = builtInSource(deps), unavailable = [];
123
+ })), maven = mavenSource(deps), source = builtInSource(deps, maven), unavailable = [];
124
+ for (const { libraryId, reason } of detected.missing) {
125
+ if (skip.has(libraryId))
126
+ continue;
127
+ log.warn(reason);
128
+ if (opts.partial)
129
+ unavailable.push({ libraryId, reason });
130
+ }
123
131
  for (const [libraryId, version] of Object.entries(detected.versions)) {
124
132
  if (skip.has(libraryId) || specs.some(s => s.libraryId === libraryId))
125
133
  continue;
@@ -157,10 +165,31 @@ async function projectStore(args, deps, opts = {}) {
157
165
  }
158
166
  }
159
167
  }
160
- if (!specs.length && unavailable.length && !opts.lenient)
161
- throw unavailable[0].error;
168
+ for (const { group, artifact, version } of detected.gradleLibraries) {
169
+ const coords = `${group}:${artifact}:${version}`;
170
+ try {
171
+ const path = await maven.resolve(group, artifact, version),
172
+ // Loaded here, so an index this tool cannot read is skipped, not fatal later.
173
+ id = new LibraryIndex(LibraryIndex.readJson(path)).id;
174
+ if (skip.has(id))
175
+ continue;
176
+ if (libraryDef(id) || specs.some(s => s.libraryId === id)) {
177
+ throw new Error(`its index has id '${id}', which another library already uses. Build it with --library and an id of its own.`);
178
+ }
179
+ specs.push({ libraryId: id, version, path });
180
+ }
181
+ catch (e) {
182
+ const reason = `hoistDocsLibraries lists ${coords}, but it was not loaded: ${e.message}`;
183
+ log.warn(reason);
184
+ if (opts.partial)
185
+ unavailable.push({ libraryId: artifact, version, reason });
186
+ }
187
+ }
188
+ const failed = unavailable.find(u => u.error);
189
+ if (!specs.length && failed && !opts.lenient)
190
+ throw failed.error;
162
191
  if (!specs.length && !opts.lenient) {
163
- throw new Error(`No Hoist versions found in ${root}: expected an installed @xh/hoist (client-app/node_modules) or hoistCoreVersion in gradle.properties. Run from the project root, or pass --project.`);
192
+ throw new Error(`No Hoist versions found in ${root}: expected an installed @xh/hoist (client-app/node_modules) or a hoist-core version in gradle.lockfile or gradle.properties. Run from the project root, or pass --project.`);
164
193
  }
165
194
  return new IndexStore(specs, {
166
195
  unavailable: unavailable.map(({ libraryId, version, reason }) => ({
@@ -171,11 +200,15 @@ async function projectStore(args, deps, opts = {}) {
171
200
  });
172
201
  }
173
202
  /** The built-in libraries' own channels: npm packages and Maven artifacts. */
174
- function builtInSource(deps) {
175
- const cache = new IndexCache(deps.cacheDir), maven = deps.mavenFetcher
203
+ function builtInSource(deps, maven = mavenSource(deps)) {
204
+ const cache = new IndexCache(deps.cacheDir);
205
+ return new BuiltInSource(new NpmSource(deps.registry ?? new NpmRegistry(), cache), maven);
206
+ }
207
+ function mavenSource(deps) {
208
+ const cache = new IndexCache(deps.cacheDir);
209
+ return deps.mavenFetcher
176
210
  ? new MavenSource({ cache, fetcher: deps.mavenFetcher })
177
211
  : MavenSource.fromEnv(process.env, cache);
178
- return new BuiltInSource(new NpmSource(deps.registry ?? new NpmRegistry(), cache), maven);
179
212
  }
180
213
  /** Write `<out>/<libraryId>.json` docs payloads, plus `<out>/index.json` listing them. */
181
214
  async function exportDocs(args, deps) {
@@ -34,8 +34,8 @@ export declare class LibraryIndex {
34
34
  private _docSearch;
35
35
  private _symbolSearch;
36
36
  /**
37
- * @param opts.trusted - false to drop the index's agent instructions, for an index from outside
38
- * the `@xh` scope. Default true.
37
+ * @param opts.trusted - false to drop the index's agent instructions, for an index neither from
38
+ * XH nor chosen by the app. Default true.
39
39
  */
40
40
  constructor(json: IndexFile, opts?: {
41
41
  trusted?: boolean;
@@ -43,8 +43,8 @@ export class LibraryIndex {
43
43
  _docSearch = null;
44
44
  _symbolSearch = null;
45
45
  /**
46
- * @param opts.trusted - false to drop the index's agent instructions, for an index from outside
47
- * the `@xh` scope. Default true.
46
+ * @param opts.trusted - false to drop the index's agent instructions, for an index neither from
47
+ * XH nor chosen by the app. Default true.
48
48
  */
49
49
  constructor(json, opts = {}) {
50
50
  if (json.schemaVersion !== SCHEMA_VERSION) {
@@ -4,7 +4,7 @@ export interface InstalledIndex {
4
4
  version: string;
5
5
  path: string;
6
6
  packageName: string;
7
- /** True for `@xh` packages, the only ones whose index may carry agent instructions. */
7
+ /** True for packages whose index may carry agent instructions: `@xh`, and those the app lists. */
8
8
  trusted: boolean;
9
9
  }
10
10
  /**
@@ -14,7 +14,11 @@ export interface InstalledIndex {
14
14
  *
15
15
  * Looks at the direct entries of `client-app/node_modules` and `node_modules` under `root` (and
16
16
  * their `@scope/` folders), the first finding of a package winning. Two packages claiming the same
17
- * id keep the `@xh` one, else the first, with a note.
17
+ * id keep the `@xh` one, else a trusted one, else the first, with a note.
18
+ *
19
+ * An index may give the agent instructions if its package is XH's, or one the app lists in the
20
+ * `package.json` beside that `node_modules`. Trust goes by the folder a package is installed in,
21
+ * which is what `package.json` names, not by the name the package gives itself.
18
22
  */
19
23
  export declare function findInstalledIndexes(root: string): {
20
24
  indexes: InstalledIndex[];
@@ -5,9 +5,9 @@
5
5
  * Copyright © 2026 Extremely Heavy Industries Inc.
6
6
  */
7
7
  import { existsSync, readdirSync, readFileSync } from 'node:fs';
8
- import { join, resolve, sep } from 'node:path';
9
- /** The scope whose packages are trusted to give the agent instructions. */
10
- const TRUSTED_SCOPE = '@xh/';
8
+ import { dirname, join, relative, resolve, sep } from 'node:path';
9
+ /** XH's scope, whose packages are always trusted to give the agent instructions. */
10
+ const XH_SCOPE = '@xh/';
11
11
  /**
12
12
  * Find every installed package that ships a Hoist Docs index, declared in its `package.json`:
13
13
  *
@@ -15,7 +15,11 @@ const TRUSTED_SCOPE = '@xh/';
15
15
  *
16
16
  * Looks at the direct entries of `client-app/node_modules` and `node_modules` under `root` (and
17
17
  * their `@scope/` folders), the first finding of a package winning. Two packages claiming the same
18
- * id keep the `@xh` one, else the first, with a note.
18
+ * id keep the `@xh` one, else a trusted one, else the first, with a note.
19
+ *
20
+ * An index may give the agent instructions if its package is XH's, or one the app lists in the
21
+ * `package.json` beside that `node_modules`. Trust goes by the folder a package is installed in,
22
+ * which is what `package.json` names, not by the name the package gives itself.
19
23
  */
20
24
  export function findInstalledIndexes(root) {
21
25
  const projectRoot = resolve(root), notes = [], byPackage = new Map();
@@ -23,6 +27,7 @@ export function findInstalledIndexes(root) {
23
27
  join(projectRoot, 'client-app', 'node_modules'),
24
28
  join(projectRoot, 'node_modules')
25
29
  ]) {
30
+ const listed = dependencyNames(dirname(dir));
26
31
  for (const pkgDir of packageDirs(dir)) {
27
32
  const pkg = readJson(join(pkgDir, 'package.json')), decl = pkg?.hoistDocs;
28
33
  if (!pkg?.name || !decl || byPackage.has(pkg.name))
@@ -40,12 +45,13 @@ export function findInstalledIndexes(root) {
40
45
  notes.push(`${pkg.name} ${pkg.version} declares a Hoist Docs index at ${decl.index}, but it is missing.`);
41
46
  continue;
42
47
  }
48
+ const folder = relative(dir, pkgDir).split(sep).join('/');
43
49
  byPackage.set(pkg.name, {
44
50
  libraryId: decl.id,
45
51
  version: pkg.version,
46
52
  path,
47
53
  packageName: pkg.name,
48
- trusted: pkg.name.startsWith(TRUSTED_SCOPE)
54
+ trusted: folder.startsWith(XH_SCOPE) || listed.has(folder)
49
55
  });
50
56
  }
51
57
  }
@@ -56,7 +62,7 @@ export function findInstalledIndexes(root) {
56
62
  byId.set(idx.libraryId, idx);
57
63
  continue;
58
64
  }
59
- const keep = !prev.trusted && idx.trusted ? idx : prev, drop = keep === prev ? idx : prev;
65
+ const rank = (i) => i.trusted ? (i.packageName.startsWith(XH_SCOPE) ? 2 : 1) : 0, keep = rank(idx) > rank(prev) ? idx : prev, drop = keep === prev ? idx : prev;
60
66
  byId.set(idx.libraryId, keep);
61
67
  notes.push(`${drop.packageName} and ${keep.packageName} both ship a Hoist Docs index with id '${idx.libraryId}' - serving ${keep.packageName}'s.`);
62
68
  }
@@ -65,6 +71,11 @@ export function findInstalledIndexes(root) {
65
71
  //------------------------
66
72
  // Implementation
67
73
  //------------------------
74
+ /** Every dependency a `package.json` in `dir` lists, of any kind. */
75
+ function dependencyNames(dir) {
76
+ const pkg = readJson(join(dir, 'package.json')), kinds = ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies'];
77
+ return new Set(kinds.flatMap(k => Object.keys(pkg?.[k] ?? {})));
78
+ }
68
79
  /** Package folders directly in a node_modules folder, including one level into `@scope/` folders. */
69
80
  function packageDirs(nodeModules) {
70
81
  const ret = [];
@@ -6,6 +6,22 @@ export interface ProjectVersions {
6
6
  notes: string[];
7
7
  /** The library, if `root` is a checkout of a built-in library itself. */
8
8
  checkout?: string;
9
+ /** Libraries a Grails project must use but whose version was not found, with why. */
10
+ missing: Array<{
11
+ libraryId: string;
12
+ reason: string;
13
+ }>;
14
+ /**
15
+ * Grails libraries the project lists in `hoistDocsLibraries` in `gradle.properties`, such as
16
+ * an organization's own plugins, with the versions `gradle.lockfile` locks.
17
+ */
18
+ gradleLibraries: GradleLibrary[];
19
+ }
20
+ /** A Grails library whose `docs-index` Maven artifact the project asks to be served. */
21
+ export interface GradleLibrary {
22
+ group: string;
23
+ artifact: string;
24
+ version: string;
9
25
  }
10
26
  /**
11
27
  * Version standing for a library's newest published snapshot: npm's `next` dist-tag, or the
@@ -16,8 +32,8 @@ export declare const LATEST_SNAPSHOT = "latest-snapshot";
16
32
  /**
17
33
  * Find the versions of the built-in libraries the project at `root` uses. An npm library's is the
18
34
  * exact version installed in `client-app/node_modules` (or `node_modules`), rather than the range
19
- * in package.json, since that is the code the app actually runs; hoist-core's is
20
- * `hoistCoreVersion` from `gradle.properties`.
35
+ * in package.json, since that is the code the app actually runs. hoist-core's is the version in
36
+ * `gradle.lockfile`, else `hoistCoreVersion` from `gradle.properties`.
21
37
  *
22
38
  * A checkout of a built-in library itself is served its own newest published snapshot - for
23
39
  * hoist-core, the newest build of its own snapshot line - plus the other libraries as installed
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * Copyright © 2026 Extremely Heavy Industries Inc.
6
6
  */
7
- import { readFileSync } from 'node:fs';
7
+ import { existsSync, readFileSync } from 'node:fs';
8
8
  import { join, resolve } from 'node:path';
9
9
  import { LIBRARIES } from '../libraries.js';
10
10
  /**
@@ -16,24 +16,30 @@ export const LATEST_SNAPSHOT = 'latest-snapshot';
16
16
  /**
17
17
  * Find the versions of the built-in libraries the project at `root` uses. An npm library's is the
18
18
  * exact version installed in `client-app/node_modules` (or `node_modules`), rather than the range
19
- * in package.json, since that is the code the app actually runs; hoist-core's is
20
- * `hoistCoreVersion` from `gradle.properties`.
19
+ * in package.json, since that is the code the app actually runs. hoist-core's is the version in
20
+ * `gradle.lockfile`, else `hoistCoreVersion` from `gradle.properties`.
21
21
  *
22
22
  * A checkout of a built-in library itself is served its own newest published snapshot - for
23
23
  * hoist-core, the newest build of its own snapshot line - plus the other libraries as installed
24
24
  * there, else, for hoist-react and hoist-core, their newest published snapshots.
25
25
  */
26
26
  export function detectProjectVersions(root) {
27
- const projectRoot = resolve(root), checkout = detectCheckout(projectRoot), ret = { versions: {}, notes: [] };
27
+ const projectRoot = resolve(root), checkout = detectCheckout(projectRoot), isGrails = ['build.gradle', 'build.gradle.kts'].some(f => existsSync(join(projectRoot, f))), ret = { versions: {}, notes: [], missing: [], gradleLibraries: [] };
28
28
  if (checkout)
29
29
  ret.checkout = checkout.library;
30
+ else
31
+ ret.gradleLibraries = gradleLibraries(projectRoot, ret.notes);
30
32
  for (const lib of LIBRARIES) {
31
33
  const version = checkout?.library === lib.id
32
34
  ? checkout.version
33
35
  : (installedVersion(projectRoot, lib, ret.notes) ??
34
36
  (checkout && !lib.optional ? LATEST_SNAPSHOT : null));
35
- if (version)
37
+ if (version) {
36
38
  ret.versions[lib.id] = version;
39
+ }
40
+ else if (isGrails && 'gradleProperty' in lib.installed && !lib.optional) {
41
+ ret.missing.push({ libraryId: lib.id, reason: missingReason(projectRoot, lib) });
42
+ }
37
43
  }
38
44
  return ret;
39
45
  }
@@ -43,7 +49,11 @@ export function detectProjectVersions(root) {
43
49
  /** The version of `lib` the project uses, or null. Notes a declared but uninstalled package. */
44
50
  function installedVersion(root, lib, notes) {
45
51
  if ('gradleProperty' in lib.installed) {
46
- return gradleProperty(root, lib.installed.gradleProperty);
52
+ const property = lib.installed.gradleProperty, locked = lib.maven && lockedVersion(root, lib.maven.group, lib.maven.artifact), set = gradleProperty(root, property);
53
+ if (locked && set && locked !== set) {
54
+ notes.push(`gradle.lockfile locks ${lib.packageName} ${locked}, but gradle.properties sets ${property}=${set}. Serving ${locked}, the version Gradle resolves. Run ./gradlew dependencies --write-locks, then restart.`);
55
+ }
56
+ return locked || set;
47
57
  }
48
58
  const name = lib.installed.npm;
49
59
  for (const dir of [join(root, 'client-app'), root]) {
@@ -79,11 +89,84 @@ function detectCheckout(root) {
79
89
  function rootProjectName(settings) {
80
90
  return /^\s*rootProject\.name\s*=\s*['"]([^'"]+)['"]/m.exec(settings)?.[1] ?? null;
81
91
  }
92
+ /**
93
+ * The libraries listed in `hoistDocsLibraries`, comma-separated `group:artifact` entries, each at
94
+ * the version `gradle.lockfile` locks. Notes an entry that is malformed or not locked.
95
+ */
96
+ function gradleLibraries(root, notes) {
97
+ const listed = gradleProperty(root, 'hoistDocsLibraries');
98
+ if (!listed)
99
+ return [];
100
+ const ret = [];
101
+ for (const entry of listed
102
+ .split(',')
103
+ .map(e => e.trim())
104
+ .filter(Boolean)) {
105
+ const [group, artifact, ...rest] = entry.split(':');
106
+ if (!group || !artifact || rest.length) {
107
+ notes.push(`hoistDocsLibraries in gradle.properties lists '${entry}' - expected group:artifact, with the version left to gradle.lockfile. Skipped.`);
108
+ continue;
109
+ }
110
+ const builtIn = LIBRARIES.find(l => l.maven?.group === group && l.maven.artifact === artifact);
111
+ if (builtIn) {
112
+ notes.push(`hoistDocsLibraries in gradle.properties lists ${entry}, which is found without it - ignored.`);
113
+ continue;
114
+ }
115
+ const version = lockedVersion(root, group, artifact);
116
+ if (!version) {
117
+ notes.push(`hoistDocsLibraries in gradle.properties lists ${entry}, but gradle.lockfile does not lock it. Skipped. ${lockAdvice(root)}`);
118
+ continue;
119
+ }
120
+ ret.push({ group, artifact, version });
121
+ }
122
+ return ret;
123
+ }
124
+ /** Why no version of `lib`, a Grails library, was found, and how to fix it. */
125
+ function missingReason(root, lib) {
126
+ const property = 'gradleProperty' in lib.installed ? lib.installed.gradleProperty : '';
127
+ return `No ${lib.packageName} version found: gradle.lockfile does not list it, and gradle.properties does not set ${property}. A lockfile lists it even when it comes through another plugin. ${lockAdvice(root)}`;
128
+ }
129
+ /**
130
+ * How to write the lock state. `--write-locks` writes nothing until the build turns dependency
131
+ * locking on, so a project without a lockfile needs that step first.
132
+ */
133
+ function lockAdvice(root) {
134
+ return existsSync(join(root, 'gradle.lockfile'))
135
+ ? 'Run ./gradlew dependencies --write-locks, then restart.'
136
+ : 'Turn on dependency locking in build.gradle (dependencyLocking { lockAllConfigurations() }), run ./gradlew dependencies --write-locks, commit gradle.lockfile, then restart.';
137
+ }
138
+ /**
139
+ * The version of `group:artifact` in the project's `gradle.lockfile`, or null. A lockfile lists
140
+ * every module Gradle resolved, those brought in by other dependencies included, so it is exact
141
+ * even when the build file names no version. Prefers the version the app runs with, should
142
+ * configurations differ.
143
+ */
144
+ function lockedVersion(root, group, artifact) {
145
+ const text = readText(join(root, 'gradle.lockfile'));
146
+ if (!text)
147
+ return null;
148
+ const prefix = `${group}:${artifact}:`, locks = text
149
+ .split('\n')
150
+ .map(l => l.trim())
151
+ .filter(l => l.startsWith(prefix))
152
+ .map(l => {
153
+ const [version, configs = ''] = l.slice(prefix.length).split('=');
154
+ return { version, configs: configs.split(',') };
155
+ });
156
+ for (const config of ['runtimeClasspath', 'compileClasspath']) {
157
+ const lock = locks.find(l => l.configs.includes(config));
158
+ if (lock)
159
+ return lock.version;
160
+ }
161
+ return locks[0]?.version || null;
162
+ }
82
163
  function gradleProperty(root, name) {
83
164
  const props = readText(join(root, 'gradle.properties'));
84
165
  if (!props)
85
166
  return null;
86
- return new RegExp(`^\\s*${name}\\s*[=:]\\s*(\\S+)\\s*$`, 'm').exec(props)?.[1] ?? null;
167
+ // Spaces and tabs only around the separator, so an empty value does not take the next line.
168
+ return (new RegExp(`^[ \\t]*${name}[ \\t]*[=:][ \\t]*(\\S.*?)[ \\t]*$`, 'm').exec(props)?.[1] ??
169
+ null);
87
170
  }
88
171
  function readText(path) {
89
172
  try {
package/dist/mcp.js CHANGED
@@ -144,6 +144,14 @@ function librariesFor(store, library, version) {
144
144
  function isMultiVersion(store) {
145
145
  return store.onDemand || store.libraryIds().some(id => store.versions(id).length > 1);
146
146
  }
147
+ /** Items joined as `a, b or c`. */
148
+ function orList(items) {
149
+ return items.length > 1 ? `${items.slice(0, -1).join(', ')} or ${items.at(-1)}` : items[0];
150
+ }
151
+ /** A library that did not load, with its version when that was found. */
152
+ function unavailableName(u) {
153
+ return u.version ? `${u.libraryId} ${u.version}` : u.libraryId;
154
+ }
147
155
  function pingText(store, config) {
148
156
  const multiVersion = isMultiVersion(store);
149
157
  return [
@@ -156,10 +164,7 @@ function pingText(store, config) {
156
164
  return multiVersion ? `${line} Versions: ${store.versions(l.id).join(', ')}` : line;
157
165
  }),
158
166
  ...(store.unavailable.length
159
- ? [
160
- 'Not loaded:',
161
- ...store.unavailable.map(u => `- ${u.libraryId} ${u.version}: ${u.reason}`)
162
- ]
167
+ ? ['Not loaded:', ...store.unavailable.map(u => `- ${unavailableName(u)}: ${u.reason}`)]
163
168
  : [])
164
169
  ].join('\n');
165
170
  }
@@ -192,7 +197,7 @@ function instructions(store) {
192
197
  const libs = store.latest(), versionNote = isMultiVersion(store)
193
198
  ? "Pass library and version together to query another release - match the versions in the project's package.json and gradle.properties."
194
199
  : 'These are the Hoist versions this project uses.';
195
- const others = libs.filter(l => l.id !== 'react' && l.id !== 'core'), ids = libs.map(l => `"${l.id}"`), choice = ids.length > 1 ? `${ids.slice(0, -1).join(', ')} or ${ids.at(-1)}` : ids[0], prefixes = others.length
200
+ const others = libs.filter(l => l.id !== 'react' && l.id !== 'core'), serverLibs = libs.filter(l => l.language === 'groovy'), manyServerLibs = serverLibs.some(l => l.id !== 'core'), choice = orList(libs.map(l => `"${l.id}"`)), prefixes = others.length
196
201
  ? `, and ${others.map(l => `${l.label ?? l.name} ids a "${l.id}:" prefix`).join(', ')}`
197
202
  : '';
198
203
  return [
@@ -200,10 +205,10 @@ function instructions(store) {
200
205
  'Do not guess at Hoist APIs, prop names, or framework conventions - consult these tools first. For how-to and concept questions start with hoist-search-docs, which returns ranked sections - read one with hoist-read-doc {id, section} rather than loading the whole doc; hoist-list-docs browses the catalog. For exact names, signatures, props, and config keys start with hoist-search-symbols: one strong keyword (an API name like GridModel or persistWith; camelCase names match their parts) returns one line per hit with its import path. Then call hoist-get-symbol for the import line, signature, JSDoc, and a member summary, and hoist-get-members with filter when you need member docs.',
201
206
  'These tools show what an API promises, not how it works. When a question turns on runtime behavior - ordering, timing, defaults applied in code, edge cases, a suspected framework bug - or the docs and JSDoc leave it open, read the implementation rather than stopping at the reference. Symbol results give each file path within its library: @xh/hoist ships its TypeScript source in node_modules/@xh/hoist, and a sibling checkout of a library (e.g. ../hoist-react, ../hoist-core) is the place to read it when one exists; otherwise hoist-core source is at github.com/xh/hoist-core.',
202
207
  `Libraries loaded: ${libs.map(l => `${l.id} (${l.name} ${l.version})`).join(', ')}. Every tool searches all of them unless you pass library: ${choice}. ${versionNote} hoist-core doc ids carry a "core:" prefix (core:docs/caching.md)${prefixes}.`,
203
- 'Match library to the code being written: client TypeScript (client-app/) is react or another client library, server Groovy or Java (grails-app/, src/main/) is core. Some names, such as Timer, exist on both sides; for a generic name or unclear context, search unscoped and check the library of each hit.',
208
+ `Match library to the code being written: client TypeScript (client-app/) is react or another client library, server Groovy or Java (grails-app/, src/main/) is ${manyServerLibs ? orList(serverLibs.map(l => `${l.id} (${l.name})`)) : 'core'}. Some names, such as Timer, exist on both sides${manyServerLibs ? ", and a server library can define classes with the same names as hoist-core's, such as a BaseService subclass. For" : '; for'} a generic name or unclear context, search unscoped and check the library of each hit.`,
204
209
  ...(store.unavailable.length
205
210
  ? [
206
- `Not loaded: ${store.unavailable.map(u => `${u.libraryId} ${u.version}`).join(', ')} (hoist-ping says why). For those, read the library's own docs and source for that version instead.`
211
+ `Not loaded: ${store.unavailable.map(unavailableName).join(', ')} (hoist-ping says why). For those, read the library's own docs and source for ${store.unavailable.every(u => u.version) ? 'that version' : 'the version the project uses'} instead.`
207
212
  ]
208
213
  : []),
209
214
  ...others
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xh/hoist-docs",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Hoist documentation and API reference for AI coding agents, over MCP",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",