DevelopOther
@holtkeeper/api-surface
The api-surface analyzer and analysis kind: reads the public API of every npm package and Go package in a checkout (each entry point, every exported name with its declaration and doc comment) so agents and people can look it up without reading the sources. Run on release tags it keeps one record per version; the server serves the records to agents over MCP and diffs them between versions. Purely syntactic: npm packages are read with the oxc parser, Go packages with the line scanner of @holtkeeper/go-source. Nothing is installed, built or type-checked, no Go toolchain is needed, and it works on TypeScript sources and published declaration files alike.
Public API
Section titled “Public API”-
apiSurfaceAnalyzer—Analyzer<ApiSurfaceData, ApiSurfaceOptions>, kindapi-surface, scoperepo, needscheckout,appliesTo: apiSurfaceApplies. Options (apiSurfaceOptionsSchema; lists also accept a comma-separated string, as the flags pass them):packages: string[](--packages) — glob patterns of package names to keep, e.g.@acme/*; every package when empty.exclude: string[](--exclude) — glob patterns of package folders to skip, e.g.examples/*.includePrivate: boolean— include npm packages with"private": true(defaulttrue: workspace packages of a monorepo are often private yet imported by its apps).includeInternal: boolean— include Go packages underinternal/, markedprivate: true(defaulttrue, so agents working inside a service see its packages).
packagesandexcludeapply to Go packages too (import paths and folders relative to the checkout). -
apiSurfaceApplies— the analyzer’s applicability: a rootpackage.json, orhasGoModule().hasGoModule(depth = 4)applies with a rootgo.modorgo.work, or, when the forge client can list the tree (listFiles), ago.modat mostdepthfolders deep outsidevendor/,testdata/,node_modules/and hidden folders; withoutlistFilesa repository whose onlygo.modis nested does not apply. -
apiSurfaceAnalysis— theAnalysisKind(schema: apiSurfaceDataSchema,summarize,toReport);apiSurfaceReport(data, options)builds the report directly. Metrics: packages, exports, documented share (better: 'up'), deprecated, with Go modulesgoImportable,goInternalandgoMainpackage counts, and, against the previous record, removed exports. Sections: packages (with an Ecosystem column when there are Go packages, and the “internal only” line for a Go service), changes since the previous record (with semver warnings), Go modules (importable, internal andmainpackage counts per module), undocumented exports, unreadable files. -
branchApiChanges(options)— public API changes of a merge request against its base commit, as Markdown for a review prompt; nothing stored (below). -
extractApi({ dir, packages?, exclude?, includePrivate? }): Promise<ApiPackage[]>— the npm extraction. -
extractGoApi({ dir, includeInternal?, packages?, exclude?, versions?, resolveVersions?, depth? }): Promise<{ packages, modules }>— the Go extraction (below);modulesareApiGoModules. -
goModuleVersions(tags, modules, ref?)— module directory → version from git tags;tagsAtHead(runner, dir, log?, signal?)—git tag --points-at HEADthrough aCommandRunner, empty on failure. -
findPackages(dir),resolveEntry(packageDir, target)andexpandWildcard(packageDir, wildcard)— package discovery and entry point resolution (below). -
diffPackage(before, after): PackageDiffanddiffApi(before, after): PackageDiff[]— differences between versions;versionBump(from, to)andnormalizeSignature(signature)are the pieces they use.declaredMembers(signature)— top-level member names of a declaration; for a Gostructorinterfacetype its fields (embedded types by type name) and methods (moved here from@holtkeeper/usages). -
renderPackage(pkg, options),renderSymbol(symbol, { docs?, ecosystem? }),renderDiff(diff)— Markdown for LLM agents. Go packages get a line on how to import them (import "path", names aspkg.Name, internal packages say who may import them) andgocode fences; npm onests.fenceLanguage(ecosystem)names the fence;importPath(name, subpath)gives the specifier code imports an entry with (for a Go module and a./sub/pkgsubpath, the package’s import path). -
goInternalOnly(data)— the “internal only” line for checkouts whose Go modules have no importable package,undefinedotherwise. -
Model:
ApiSurfaceData { packages, go? },ApiPackage { name, version?, description?, private, dir, ecosystem?, module?, entries, problems? }(ecosystemabsent means npm),ApiGoModule { path, dir, version?, packages, internalPackages, mainPackages },ApiEntry { subpath, file?, symbols, truncated? },ApiSymbol { name, kind, signature, doc?, deprecated?, file, line };apiTotals(packages),documentedPercent(totals),apiSymbolKinds,isApiSymbolKind(value).
Merge request API changes (ephemeral)
Section titled “Merge request API changes (ephemeral)”branchApiChanges({ dir, baseSha, changedFiles, runner, signal?, maxChars?, consumed? }): Promise<string | undefined> computes, inside a review run, how a merge request changes the public API, and returns a Markdown section for the review prompt starting with branchApiHeading (## Public API changes (computed: base → head)). Nothing is stored: no analysis record is written, both sides are extracted on the fly.
- Which packages — only those containing a changed file (
diris the head checkout): an npm package counts for a changed file in its folder (the deepest package folder wins), a Go package for a changed non-test.gofile in its directory. Packages without an entry point are left out, as are packagesconsumed(name, ecosystem)rejects when the filter is given. With nothing left it resolves toundefinedwithout running git. - Base side — a detached git worktree of
baseShain the system temp folder (git worktree add --detach, through theCommandRunner), from which the same packages are extracted. The worktree is always removed afterwards (git worktree remove --force, the temp folder deleted,git worktree prune), also on errors and aborts. - Output — per package with differences: name, ecosystem, folder, removed / changed (old → new declaration, one line each) / deprecated / added exports with
file:line(base location for removals, head location otherwise), the release it needs (majorwhen exports were removed or declarations changed, since a changed declaration may break callers;minorwhen exports were only added or deprecated) and, for npm, whether thepackage.jsonversion change is enough. Go versions come from tags and are not compared. The section ends with an instruction to check usages of removed or changed exports, stays withinmaxChars(default 6000) and says “… N more changes” when cut. - Failure —
undefinedwhen nothing differs, the base commit cannot be checked out or extraction fails; it never rejects, except with the abort reason whensignalaborts (checked between steps).
How the npm API is read
Section titled “How the npm API is read”- Packages — the root
package.jsonplus every workspace thatworkspaces(array or{ packages }) orpnpm-workspace.yamllists, negated patterns excluded; packages without anameare skipped. - Entry points — each subpath of
exports(./package.jsonskipped), conditions tried in the ordertypes,typings,import,module,node,default,require; withoutexports,types/typings/module/main, thensrc/index.ts,index.ts. A target resolves to the file itself when it is TypeScript, else a declaration next to it, else the source a build would have compiled it from (dist/x.js→src/x.ts, thenx.tsorx.d.tsat the package root forrootDir: "."builds; alsolib,build,out,esm,cjs), else the JavaScript file. Wildcard subpaths ("./*": "./dist/*") count only when no other entry point resolves: each module file, or folder with an index, in the target’s folder or its source folder becomes an entry (./usePrevious); folders without an index are searched two levels deep (./desktop/Button), skipping tests, stories, configs,indexand names starting with.or_, at most 200. A folder mapping that repeats an entry point of the same name (./services/next to./services) is dropped (withoutFolderTwins(entries), exported; the server also applies it to records stored before). Packages with no entry point that resolves to a file are left out, e.g. an app withoutexportsor a library whose build output is missing and whose sources live elsewhere. - Exports — declarations exported in place,
export { a as b },export { x } from,export * from(explicit exports win over star exports,defaultis never re-exported by a star),export * as ns from(a namespace listing its names) andexport default/export =. Relative specifiers are followed across files (./a.jsfinds./a.ts, folders findindex); re-exports of other packages stay asreexportentries naming the package. Cycles are cut. - Declarations — functions and overloads without bodies, classes without method bodies, private members or initializers (member doc comments kept as one line), interfaces, type aliases, enums and namespaces in full, constants as
const name: Type,const f = (a: T): R => …or a short initializer. Lint directive comments (// oxlint-…,// eslint-…,// @ts-…) are dropped; the doc comment is the/** */block right before the declaration, even with such a comment in between.@deprecatedtext becomesdeprecated. - Caps — 1000 symbols per entry point (the rest counted in
truncated), 3000 characters per declaration, 1500 per doc comment, so one record stays a few hundred kilobytes for a large monorepo.
How the Go API is read
Section titled “How the Go API is read”- Modules —
discoverGoModulesfrom@holtkeeper/go-source: theusefolders of a rootgo.work, else everygo.modup to 4 folders deep (skippingvendor,testdata,node_modulesand hidden folders). - Files — each module’s
.gofiles except_test.go, without the subtrees of nested modules,vendor/,testdata/,node_modules/and./_folders, at most 20 000 files per module. - Packages —
goModuleApiper module: oneApiPackageper library package directory, named by its full import path, with the single entry.,ecosystem: 'Go'andmoduleset;dir, entry and symbolfilepaths are relative to the checkout. Methods areType.Method. Packages underinternal/are listed withprivate: true(unlessincludeInternalis off);package maindirectories are never listed, only counted. - Modules in the record —
data.go.moduleslists every module found with its importable, internal andmainpackage counts, so a service made ofcmd/andinternal/reads as “internal only” instead of empty. It is absent when the checkout has no Go module. - Versions —
git tag --points-at HEADin the checkout (job checkouts carry every tag), mapped to modules by Go’s rules (goModuleTags):vX.Y.Zreleases the root module,dir/vX.Y.Zthe module atdir, the highest tag per module wins. When the run’srefis itself a Go module tag, only the module it releases gets a version. Packages of modules without a matching tag get no version; the analysis never uses the commit as a version. Git runs only when there are Go modules, and a failing git only loses the versions.
Versions and diffs
Section titled “Versions and diffs”Each record describes one ref: a release tag (from the default tag trigger or an analysis backfill, POST /api/analyses/backfill) or the default branch (the weekly api-weekly schedule). diffPackage keys symbols by subpath and name: a missing one is removed, a declaration that differs after normalizeSignature (comments and layout ignored) is changed, a newly @deprecated one deprecated, a new one added. required is the bump the changes call for (major when anything was removed, minor for additions, changes or deprecations); bumped is what the version numbers did, where a minor bump of a 0.x version counts as major. Go pseudo-versions (v0.0.0-20240101000000-abcdef123456) and +incompatible versions are not semver: bumped stays unset for them. PackageDiff.ecosystem is Go for Go packages, so renderDiff fences them as Go. A changed declaration whose declaredMembers lose names lists them in ApiChange.removedMembers and counts as breaking: PackageDiff.breaking is true and required is major, the same as a removal; renderDiff marks the change (breaking) and lists Members removed:. semverWarning is set when exports were removed, or members of a changed declaration, without that bump. A changed declaration may still be compatible (an optional parameter added); the diff shows both versions instead of guessing.