Files
zeekay 1b367e2b62 chore: rebase the tree onto upstream master
The tree was a debranded snapshot of upstream taken around 2026-02-20, and
upstream has moved about five months since. This replaces it with upstream
master, mechanically re-derived: bin/debrand does the rename, and the
pipeline and squashed migrations are restored from the shipped tree.

Not a merge. The previous import replaced the tree wholesale in a single
commit, so there is no shared content history to merge against. Reproducing
the rename on the new tree is what actually converges.

What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints,
compose files, LLM.md, and insights/migrations. The squashed initial
migration is load-bearing — the live database records it by name, so
upstream's ~918 individual migrations cannot come back.

Nine products are dropped as unreferenced. Twenty-one more that we do not run
are kept anyway because the core app still imports them; unpicking those is a
refactor and does not belong in a rebase.

This base does not build yet, and the reasons are not in the rename:
upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against
our 4.2, and the dependency manifests still name upstream packages that we
republish under our own names. Those are decisions, not renames.
2026-08-01 15:44:40 -07:00

89 lines
3.1 KiB
JavaScript

/**
* MCP definition discovery and schema path resolution.
*
* Shared by generate-orval-schemas.mjs and generate-tools.ts.
* MCP-specific: knows about services/mcp/definitions/ and products/*\/mcp/.
*/
import fs from 'node:fs'
import path from 'node:path'
/**
* Resolve the OpenAPI schema path, respecting OPENAPI_SCHEMA_PATH env override.
*
* @param {string} repoRoot - absolute path to the repository root
* @returns {string} absolute path to the OpenAPI JSON schema file
*/
export function resolveSchemaPath(repoRoot) {
const defaultPath = path.resolve(repoRoot, 'frontend', 'tmp', 'openapi.json')
return process.env.OPENAPI_SCHEMA_PATH ? path.resolve(repoRoot, process.env.OPENAPI_SCHEMA_PATH) : defaultPath
}
/**
* Discover all MCP YAML definition files.
*
* Scans:
* - services/mcp/definitions/*.yaml — core MCP tool configs
* - products/*\/mcp/*.yaml — per-product tool configs
*
* @param {object} opts
* @param {string} opts.definitionsDir - absolute path to services/mcp/definitions/
* @param {string} opts.productsDir - absolute path to the products/ directory
* @returns {{ moduleName: string, filePath: string }[]}
*/
export function discoverDefinitions({ definitionsDir, productsDir }) {
const sources = []
if (fs.existsSync(definitionsDir)) {
for (const file of fs.readdirSync(definitionsDir)) {
if (!file.endsWith('.yaml') && !file.endsWith('.yml')) {
continue
}
sources.push({
moduleName: file.replace(/\.ya?ml$/, ''),
filePath: path.join(definitionsDir, file),
})
}
}
if (fs.existsSync(productsDir)) {
for (const product of fs.readdirSync(productsDir, { withFileTypes: true })) {
if (!product.isDirectory() || product.name.startsWith('_')) {
continue
}
const mcpDir = path.join(productsDir, product.name, 'mcp')
if (!fs.existsSync(mcpDir)) {
continue
}
for (const file of fs.readdirSync(mcpDir)) {
if (!file.endsWith('.yaml') && !file.endsWith('.yml')) {
continue
}
const moduleName =
file === 'tools.yaml' || file === 'tools.yml' ? product.name : file.replace(/\.ya?ml$/, '')
sources.push({
moduleName,
filePath: path.join(mcpDir, file),
})
}
}
}
return sources.sort((a, b) => a.moduleName.localeCompare(b.moduleName))
}
/**
* Returns true if the parsed YAML has the shape of a query wrapper config
* (has `wrappers` key instead of `tools`).
*/
export function isQueryWrappersConfig(parsed) {
return typeof parsed === 'object' && parsed !== null && 'wrappers' in parsed && !('tools' in parsed)
}
/**
* Returns true if the parsed YAML has the shape of a category config
* (has `tools` key instead of `wrappers`).
*/
export function isToolsConfig(parsed) {
return typeof parsed === 'object' && parsed !== null && 'tools' in parsed
}