Download packages/schema-engine/src/generators/documentation.ts from AnthropicallyHuggingFaces/ProjectOS: direct link, hf CLI and curl.
- Browser
- Download file 11.2 kB
-
https://huggingface.co/spaces/AnthropicallyHuggingFaces/ProjectOS/resolve/main/packages/schema-engine/src/generators/documentation.ts
- Command line
-
hf download hf://spaces/AnthropicallyHuggingFaces/ProjectOS/packages/schema-engine/src/generators/documentation.ts
-
curl -L -o documentation.ts https://huggingface.co/spaces/AnthropicallyHuggingFaces/ProjectOS/resolve/main/packages/schema-engine/src/generators/documentation.ts
11.2 kB
| import type { GeneratedProjectCatalog, StorageConfiguration } from '../index.js'; | |
| import type { SymbolAliasRegistry } from '../symbols/symbol-resolver.js'; | |
| export type DocumentationInput = { | |
| project: GeneratedProjectCatalog; | |
| storage: StorageConfiguration; | |
| symbols: SymbolAliasRegistry; | |
| bootstrap: { schema: string; schematron: string; output: string }; | |
| }; | |
| const cell = (value: unknown): string => String(value ?? '').replaceAll('|', '\\|').replaceAll('\n', ' '); | |
| const table = (headers: string[], rows: unknown[][]): string => [ | |
| `| ${headers.join(' | ')} |`, | |
| `| ${headers.map(() => '---').join(' | ')} |`, | |
| ...rows.map((row) => `| ${row.map(cell).join(' | ')} |`) | |
| ].join('\n'); | |
| const bullets = (items: Array<{ name: string; description: string }>): string => | |
| items.map((item) => `- **${cell(item.name)}** — ${cell(item.description) || 'No description supplied.'}`).join('\n') || '- None configured.'; | |
| function fabric(project: GeneratedProjectCatalog, name: string) { | |
| return project.fabrics.find((item) => item.name.toLowerCase() === name.toLowerCase()); | |
| } | |
| export function generateDocumentation(input: DocumentationInput, enabledOutputs: string[]): Record<string, string> { | |
| const { project, storage, symbols, bootstrap } = input; | |
| const outputs: Record<string, string> = {}; | |
| const common = `<!-- Generated by ProjectOS Schema Engine from bootstrap.xml. -->\n# `; | |
| const projectHeading = `${project.name} ${project.version}`; | |
| const renderers: Record<string, () => string> = { | |
| Architecture: () => `${common}Architecture\n\n${projectHeading} runs in **${project.mode}** mode. Its runtime route is schema validation → bootstrap validation → fabrics and registries → council and MCP initialization → dashboard.\n\n## Decision flow\n\n${project.steps.map((step, index) => `${index + 1}. **${cell(step.name)}** — ${cell(step.description)}`).join('\n')}\n\n## Project lifecycle\n\n${table(['Stage', 'Purpose'], project.stages.map((stage) => [stage.name, stage.description]))}\n\n## Fabrics\n\n${table(['Fabric', 'Purpose'], project.fabrics.map((item) => [item.name, item.description]))}\n`, | |
| Bootstrap: () => `${common}Bootstrap\n\nThe human-authored source of truth is \`bootstrap.xml\`. The schema engine validates it against \`${bootstrap.schema}\` and \`${bootstrap.schematron}\`, then generates runtime, registry, storage, documentation, snapshot, and release artifacts under \`${bootstrap.output}\` plus the repository's \`generated/\` and \`release/\` directories.\n\n## Manifest sections\n\nDecision flow, lifecycle, fabrics, councils, agents, models, storage, governance, knowledge, permissions, workspaces, MCP server trust, naming conventions, language profiles, and documentation outputs are all declared in the bootstrap manifest.\n`, | |
| Schema: () => `${common}Schema\n\n## Validation inputs\n\n- XSD: \`${bootstrap.schema}\`\n- Schematron: \`${bootstrap.schematron}\`\n\nThe XSD enforces manifest structure, typed values, positive dimensions and retention periods, and unique registry keys. Schematron enforces cross-section rules for storage provider dependencies, migration backups, canon retention, MCP registry completeness, and symbol alias collisions.\n\n## Canonical symbols\n\n${table(['Canonical symbol', 'Aliases'], Object.entries(symbols).map(([name, aliases]) => [name, aliases.join(', ')]))}\n`, | |
| Agents: () => `${common}Agents\n\n${bullets(project.agents)}\n`, | |
| Councils: () => `${common}Councils\n\n${project.councils.map((item) => `## ${cell(item.name)}\n\n${cell(item.description)}\n\nMembers: ${item.capabilities.map(cell).join(', ') || 'None configured.'}`).join('\n\n')}\n`, | |
| Fabrics: () => `${common}Fabrics\n\n${project.fabrics.map((item) => `## ${cell(item.name)}\n\n${cell(item.description)}\n\nCapabilities: ${item.capabilities.map(cell).join(', ') || 'None declared.'}`).join('\n\n')}\n`, | |
| Storage: () => `${common}Storage\n\n## Providers\n\n${storage.providers.map((provider) => `- ${cell(provider)}`).join('\n') || '- None enabled.'}\n\n## Vector stores\n\n${table(['Provider', 'Dimensions'], storage.vectorStores.map((item) => [item.provider, item.dimensions]))}\n\n## Retention\n\n- Snapshots: ${storage.retention.snapshotDays} days\n- Archives: ${storage.retention.archiveYears} years\n- Canon retained permanently: ${storage.retention.keepCanonForever ? 'yes' : 'no'}\n\n## Migration policy\n\n- Automatic migration: ${storage.migration.autoMigrate ? 'enabled' : 'disabled'}\n- Backup before migration: ${storage.migration.backupBeforeMigration ? 'required' : 'not required'}\n- Validate after migration: ${storage.migration.validateSchema ? 'enabled' : 'disabled'}\n\nSQLite tables are declared in \`packages/storage-fabric/sqlite/schema.sql\`; PostgreSQL and pgvector tables are declared in \`packages/storage-fabric/pgvector/schema.sql\`.\n`, | |
| Knowledge: () => `${common}Knowledge\n\n${bullets(project.knowledge)}\n`, | |
| Canon: () => `${common}Canon\n\nCanon stores verified, governed knowledge as versioned \`canon_entries\` and \`canon_revisions\`. Promotion records the source snapshot and preserves revision history. Permanent retention is required by the bootstrap policy.\n\nThe promotion service commits the canon revision, Frontier status transition, and post-promotion snapshot together after Logic validation and Governance approval.\n`, | |
| Frontier: () => `${common}Frontier\n\nThe Frontier tracks research that has not yet been accepted into canon. Candidate records and observations are stored in \`frontier_items\` and \`frontier_observations\`; promotion requires Logic validation and Governance approval before changing status and creating a canon entry.\n`, | |
| Delta: () => `${common}Delta\n\nDelta compares declared current and target requirement sets, persists each run in \`delta_runs\`, records missing values in \`delta_gaps\`, and links open dependency blockers through \`delta_dependencies\`. A run is complete only when the target has no gaps and no open blockers.\n`, | |
| Dependency: () => `${common}Dependency\n\nDependency Fabric records missing models, datasets, permissions, tools, and infrastructure in \`dependency_findings\`. Open findings are deduplicated by project, category, and name; they can be resolved or waived without erasing history. Current model routes: ${Object.keys(project.models).length}; workspace routes: ${Object.keys(project.workspaces).length}.\n`, | |
| Governance: () => `${common}Governance\n\n${bullets(project.governance)}\n\nPromotion and other governed actions create auditable records in \`governance_reviews\`; a pending or rejected review does not authorize execution or canon promotion.\n\n## Permission rules\n\n${table(['ID', 'Resource', 'Action', 'Effect', 'Approval'], project.permissions.map((rule) => [rule.id, rule.resource, rule.action, rule.effect, rule.requiresApproval]))}\n`, | |
| Identity: () => `${common}Identity\n\n${fabric(project, 'Identity')?.description ?? 'Identity maps people and services to accountable actors, roles, and ownership.'}\n\nIdentity remains an integration boundary; provider credentials and directory connectors are configured separately.\n`, | |
| Trust: () => `${common}Trust\n\n${fabric(project, 'Trust')?.description ?? 'Trust evaluates the provenance and reliability of sources, datasets, models, and actions.'}\n\nTrust checks are evaluated before governed execution and knowledge promotion.\n`, | |
| Runtime: () => `${common}Runtime\n\n- Profile: ${cell(project.runtime.profile)}\n- Snapshots: ${project.runtime.snapshots}\n- Automatic routing: ${project.runtime.automaticRouting}\n- Consolidation: ${project.runtime.consolidation}\n- Startup order: ${project.runtime.startupOrder.join(' → ')}\n`, | |
| Database: () => `${common}Database\n\nLocal storage: ${cell(project.storage.local)}\n\nEnterprise storage: ${cell(project.storage.enterprise)}\n\nNormalized tables cover projects, events, snapshots, canon entries and revisions, frontier items and observations, archives, embeddings, dependency findings, delta runs and gaps, blockers, and governance reviews. The PostgreSQL schema includes pgvector HNSW cosine search; SQLite stores embedding arrays as JSON until sqlite-vec is installed.\n`, | |
| API: () => `${common}API\n\nThe local API provides health, state, and planning routes. Current routes include \`GET /api/health\`, \`GET /api/state\`, \`POST /api/plans/draft\`, and \`POST /api/state/{projects|policies|plans|snapshots}\`. Existing state routes remain on the compatibility \`app_state\` table while normalized repository migration proceeds.\n`, | |
| MCP: () => `${common}MCP\n\nThe registry separates adapters from profile membership and declares the authentication method for each server. Secrets are referenced by environment-variable name or an OS keyring profile; secret values are never generated into configuration or release files. GitHub's default OAuth flow requires browser approval rather than a saved PAT.\n\n## Server library\n\n${table(['Entry', 'Adapter', 'Trust', 'Access', 'Authentication', 'Credential reference'], project.mcpServers.map((server) => [server.name, server.adapter, server.trust, server.accessMode, server.authMode, server.credentialRef ?? 'None']))}\n\n## Profiles\n\n${table(['Profile', 'Enabled', 'Servers', 'Purpose'], project.mcpProfiles.map((profile) => [profile.name, profile.enabled, profile.servers.join(', '), profile.description]))}\n\nThe ProjectOS MCP Fabric validates credential references and connects selected profiles. GitHub and PostgreSQL write access are disabled by default.\n`, | |
| Workspaces: () => `${common}Workspaces\n\n${table(['Role', 'Workspace'], Object.entries(project.workspaces))}\n`, | |
| Models: () => `${common}Models\n\n${table(['Role', 'Provider'], Object.entries(project.models))}\n`, | |
| Providers: () => `${common}Providers\n\n## Storage providers\n\n${storage.providers.map((provider) => `- ${cell(provider)}`).join('\n') || '- None enabled.'}\n\n## Model providers\n\n${[...new Set(Object.values(project.models))].map((provider) => `- ${cell(provider)}`).join('\n') || '- None configured.'}\n`, | |
| Snapshots: () => `${common}Snapshots\n\nSnapshots capture project state, events, canon entries and revisions, frontier records and observations, archives, embeddings, dependency findings, delta runs and gaps, and governance reviews with a schema version and content checksum. The configured retention period is ${storage.retention.snapshotDays} days. Snapshot and item records are stored in \`snapshots\` and \`snapshot_items\`; the release snapshot manifest hashes bootstrap, runtime, and storage configuration.\n`, | |
| Archive: () => `${common}Archive\n\nArchived resources are preserved in \`archive_records\` with a payload checksum, source snapshot, reason, and retention deadline. The configured archive retention is ${storage.retention.archiveYears} years. Canon records are retained permanently.\n` | |
| }; | |
| for (const name of enabledOutputs) { | |
| const render = renderers[name]; | |
| if (!render) throw new Error(`No documentation template exists for enabled output "${name}".`); | |
| outputs[`docs/${name.toUpperCase()}.md`] = render(); | |
| } | |
| return outputs; | |
| } | |