ont-run 0.0.1

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.
Files changed (54) hide show
  1. package/README.md +228 -0
  2. package/bin/ont.ts +5 -0
  3. package/dist/bin/ont.d.ts +2 -0
  4. package/dist/bin/ont.js +13667 -0
  5. package/dist/index.js +23152 -0
  6. package/dist/src/browser/server.d.ts +16 -0
  7. package/dist/src/browser/transform.d.ts +87 -0
  8. package/dist/src/cli/commands/init.d.ts +12 -0
  9. package/dist/src/cli/commands/review.d.ts +17 -0
  10. package/dist/src/cli/index.d.ts +1 -0
  11. package/dist/src/cli/utils/config-loader.d.ts +13 -0
  12. package/dist/src/config/categorical.d.ts +76 -0
  13. package/dist/src/config/define.d.ts +46 -0
  14. package/dist/src/config/index.d.ts +4 -0
  15. package/dist/src/config/schema.d.ts +162 -0
  16. package/dist/src/config/types.d.ts +94 -0
  17. package/dist/src/index.d.ts +37 -0
  18. package/dist/src/lockfile/differ.d.ts +11 -0
  19. package/dist/src/lockfile/hasher.d.ts +31 -0
  20. package/dist/src/lockfile/index.d.ts +53 -0
  21. package/dist/src/lockfile/types.d.ts +90 -0
  22. package/dist/src/runtime/index.d.ts +28 -0
  23. package/dist/src/server/api/index.d.ts +20 -0
  24. package/dist/src/server/api/middleware.d.ts +34 -0
  25. package/dist/src/server/api/router.d.ts +18 -0
  26. package/dist/src/server/mcp/index.d.ts +23 -0
  27. package/dist/src/server/mcp/tools.d.ts +35 -0
  28. package/dist/src/server/resolver.d.ts +30 -0
  29. package/dist/src/server/start.d.ts +37 -0
  30. package/package.json +63 -0
  31. package/src/browser/server.ts +2567 -0
  32. package/src/browser/transform.ts +473 -0
  33. package/src/cli/commands/init.ts +226 -0
  34. package/src/cli/commands/review.ts +126 -0
  35. package/src/cli/index.ts +19 -0
  36. package/src/cli/utils/config-loader.ts +78 -0
  37. package/src/config/categorical.ts +101 -0
  38. package/src/config/define.ts +78 -0
  39. package/src/config/index.ts +23 -0
  40. package/src/config/schema.ts +196 -0
  41. package/src/config/types.ts +121 -0
  42. package/src/index.ts +53 -0
  43. package/src/lockfile/differ.ts +242 -0
  44. package/src/lockfile/hasher.ts +175 -0
  45. package/src/lockfile/index.ts +159 -0
  46. package/src/lockfile/types.ts +95 -0
  47. package/src/runtime/index.ts +114 -0
  48. package/src/server/api/index.ts +92 -0
  49. package/src/server/api/middleware.ts +118 -0
  50. package/src/server/api/router.ts +102 -0
  51. package/src/server/mcp/index.ts +182 -0
  52. package/src/server/mcp/tools.ts +199 -0
  53. package/src/server/resolver.ts +109 -0
  54. package/src/server/start.ts +151 -0
@@ -0,0 +1,90 @@
1
+ /**
2
+ * A field that references another function for its options
3
+ */
4
+ export interface FieldReference {
5
+ /** Path to the field in the schema, e.g., "status" or "filters.country" */
6
+ path: string;
7
+ /** Name of the function that provides options for this field */
8
+ functionName: string;
9
+ }
10
+ /**
11
+ * Snapshot of a function's shape (what matters for security review)
12
+ */
13
+ export interface FunctionShape {
14
+ /** Description of the function */
15
+ description: string;
16
+ /** Sorted list of access groups */
17
+ access: string[];
18
+ /** Sorted list of entities this function relates to */
19
+ entities: string[];
20
+ /** JSON Schema representation of the input schema */
21
+ inputsSchema: Record<string, unknown>;
22
+ /** JSON Schema representation of the output schema */
23
+ outputsSchema?: Record<string, unknown>;
24
+ /** Fields that reference other functions for their options */
25
+ fieldReferences?: FieldReference[];
26
+ }
27
+ /**
28
+ * Complete snapshot of the ontology
29
+ */
30
+ export interface OntologySnapshot {
31
+ /** Name of the ontology */
32
+ name: string;
33
+ /** Sorted list of access group names */
34
+ accessGroups: string[];
35
+ /** Sorted list of entity names */
36
+ entities?: string[];
37
+ /** Function shapes keyed by name */
38
+ functions: Record<string, FunctionShape>;
39
+ }
40
+ /**
41
+ * The ont.lock file structure
42
+ */
43
+ export interface Lockfile {
44
+ /** Lockfile format version */
45
+ version: number;
46
+ /** SHA256 hash of the ontology */
47
+ hash: string;
48
+ /** When this was approved */
49
+ approvedAt: string;
50
+ /** The full ontology snapshot */
51
+ ontology: OntologySnapshot;
52
+ }
53
+ /**
54
+ * A single change in a function
55
+ */
56
+ export interface FunctionChange {
57
+ name: string;
58
+ type: "added" | "removed" | "modified";
59
+ oldAccess?: string[];
60
+ newAccess?: string[];
61
+ oldDescription?: string;
62
+ newDescription?: string;
63
+ inputsChanged?: boolean;
64
+ outputsChanged?: boolean;
65
+ entitiesChanged?: boolean;
66
+ oldEntities?: string[];
67
+ newEntities?: string[];
68
+ fieldReferencesChanged?: boolean;
69
+ }
70
+ /**
71
+ * Diff between old and new ontology
72
+ */
73
+ export interface OntologyDiff {
74
+ /** Whether there are any changes */
75
+ hasChanges: boolean;
76
+ /** Added access groups */
77
+ addedGroups: string[];
78
+ /** Removed access groups */
79
+ removedGroups: string[];
80
+ /** Added entities */
81
+ addedEntities: string[];
82
+ /** Removed entities */
83
+ removedEntities: string[];
84
+ /** Function changes */
85
+ functions: FunctionChange[];
86
+ /** The new ontology (for writing to lockfile on approve) */
87
+ newOntology: OntologySnapshot;
88
+ /** The new hash */
89
+ newHash: string;
90
+ }
@@ -0,0 +1,28 @@
1
+ type AnyHono = {
2
+ fetch: (request: Request, ...args: any[]) => Response | Promise<Response>;
3
+ };
4
+ /**
5
+ * Check if we're running in Bun
6
+ */
7
+ export declare function isBun(): boolean;
8
+ /**
9
+ * Check if we're running in Node.js
10
+ */
11
+ export declare function isNode(): boolean;
12
+ /**
13
+ * Get the current runtime name
14
+ */
15
+ export declare function getRuntime(): "bun" | "node" | "unknown";
16
+ export interface ServerHandle {
17
+ port: number;
18
+ stop: () => void | Promise<void>;
19
+ }
20
+ /**
21
+ * Start an HTTP server using the appropriate runtime
22
+ */
23
+ export declare function serve(app: AnyHono, port: number): Promise<ServerHandle>;
24
+ /**
25
+ * Find an available port starting from the given port
26
+ */
27
+ export declare function findAvailablePort(startPort?: number): Promise<number>;
28
+ export {};
@@ -0,0 +1,20 @@
1
+ import { Hono } from "hono";
2
+ import type { OntologyConfig } from "../../config/types.js";
3
+ import { type OntologyVariables } from "./middleware.js";
4
+ export interface ApiServerOptions {
5
+ /** The ontology configuration */
6
+ config: OntologyConfig;
7
+ /** Directory containing the ontology.config.ts (for resolving resolver paths) */
8
+ configDir: string;
9
+ /** Environment to use (e.g., 'dev', 'prod') */
10
+ env: string;
11
+ /** Enable CORS (default: true) */
12
+ cors?: boolean;
13
+ }
14
+ /**
15
+ * Create the Hono API app from an OntologyConfig
16
+ */
17
+ export declare function createApiApp(options: ApiServerOptions): Hono<{
18
+ Variables: OntologyVariables;
19
+ }>;
20
+ export { getFunctionsInfo } from "./router.js";
@@ -0,0 +1,34 @@
1
+ import type { OntologyConfig, ResolverContext, EnvironmentConfig } from "../../config/types.js";
2
+ /**
3
+ * Context variables added by middleware
4
+ */
5
+ export interface OntologyVariables {
6
+ resolverContext: ResolverContext;
7
+ accessGroups: string[];
8
+ }
9
+ /**
10
+ * Create auth middleware that calls the user's auth function
11
+ * and sets the access groups on the context
12
+ */
13
+ export declare function createAuthMiddleware(config: OntologyConfig): import("hono").MiddlewareHandler<{
14
+ Variables: OntologyVariables;
15
+ }, string, {}, Response>;
16
+ /**
17
+ * Create context middleware that builds the ResolverContext
18
+ */
19
+ export declare function createContextMiddleware(env: string, envConfig: EnvironmentConfig): import("hono").MiddlewareHandler<{
20
+ Variables: OntologyVariables;
21
+ }, string, {}, Response>;
22
+ /**
23
+ * Create access control middleware for a specific function
24
+ */
25
+ export declare function createAccessControlMiddleware(requiredAccess: string[]): import("hono").MiddlewareHandler<{
26
+ Variables: OntologyVariables;
27
+ }, string, {}, Response>;
28
+ /**
29
+ * Error handling middleware
30
+ */
31
+ export declare function errorHandler(): import("hono").MiddlewareHandler<any, any, {}, Response | (Response & import("hono").TypedResponse<{
32
+ error: string;
33
+ message: string;
34
+ }, 401 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 | -1, "json">)>;
@@ -0,0 +1,18 @@
1
+ import { Hono } from "hono";
2
+ import type { OntologyConfig } from "../../config/types.js";
3
+ import { type OntologyVariables } from "./middleware.js";
4
+ /**
5
+ * Create API routes from function definitions
6
+ */
7
+ export declare function createApiRoutes(config: OntologyConfig, configDir: string): Hono<{
8
+ Variables: OntologyVariables;
9
+ }>;
10
+ /**
11
+ * Get info about all available functions (for introspection)
12
+ */
13
+ export declare function getFunctionsInfo(config: OntologyConfig): Array<{
14
+ name: string;
15
+ description: string;
16
+ access: string[];
17
+ path: string;
18
+ }>;
@@ -0,0 +1,23 @@
1
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
+ import type { OntologyConfig } from "../../config/types.js";
3
+ export interface McpServerOptions {
4
+ /** The ontology configuration */
5
+ config: OntologyConfig;
6
+ /** Directory containing the ontology.config.ts */
7
+ configDir: string;
8
+ /** Environment to use */
9
+ env: string;
10
+ /** Port for the MCP HTTP server */
11
+ port?: number;
12
+ }
13
+ /**
14
+ * Create the MCP server instance with per-request authentication
15
+ */
16
+ export declare function createMcpServer(options: McpServerOptions): Server;
17
+ /**
18
+ * Start the MCP server as an HTTP server with Streamable HTTP transport
19
+ */
20
+ export declare function startMcpServer(options: McpServerOptions): Promise<{
21
+ port: number;
22
+ }>;
23
+ export { generateMcpTools, filterToolsByAccess } from "./tools.js";
@@ -0,0 +1,35 @@
1
+ import type { OntologyConfig, EnvironmentConfig } from "../../config/types.js";
2
+ import { type Logger } from "../resolver.js";
3
+ /**
4
+ * Field reference info for MCP tools
5
+ */
6
+ export interface McpFieldReference {
7
+ /** Path to the field in the schema */
8
+ path: string;
9
+ /** Name of the function that provides options */
10
+ functionName: string;
11
+ }
12
+ /**
13
+ * MCP Tool definition
14
+ */
15
+ export interface McpTool {
16
+ name: string;
17
+ description: string;
18
+ inputSchema: Record<string, unknown>;
19
+ outputSchema?: Record<string, unknown>;
20
+ access: string[];
21
+ entities: string[];
22
+ fieldReferences?: McpFieldReference[];
23
+ }
24
+ /**
25
+ * Generate MCP tool definitions from ontology config
26
+ */
27
+ export declare function generateMcpTools(config: OntologyConfig): McpTool[];
28
+ /**
29
+ * Filter tools by access groups
30
+ */
31
+ export declare function filterToolsByAccess(tools: McpTool[], accessGroups: string[]): McpTool[];
32
+ /**
33
+ * Create a tool executor function that accepts per-request access groups
34
+ */
35
+ export declare function createToolExecutor(config: OntologyConfig, configDir: string, env: string, envConfig: EnvironmentConfig, logger: Logger): (toolName: string, args: unknown, accessGroups: string[]) => Promise<unknown>;
@@ -0,0 +1,30 @@
1
+ import type { ResolverFunction, OntologyConfig } from "../config/types.js";
2
+ /**
3
+ * Load a resolver from a file path.
4
+ * The path is relative to the config file location.
5
+ *
6
+ * @param resolverPath - Path to the resolver file (relative to configDir)
7
+ * @param configDir - Directory containing the ontology.config.ts
8
+ */
9
+ export declare function loadResolver(resolverPath: string, configDir: string): Promise<ResolverFunction>;
10
+ /**
11
+ * Clear the resolver cache (useful for hot reloading)
12
+ */
13
+ export declare function clearResolverCache(): void;
14
+ /**
15
+ * Check which resolvers are missing and return their paths
16
+ */
17
+ export declare function findMissingResolvers(config: OntologyConfig, configDir: string): string[];
18
+ /**
19
+ * Logger type returned by createLogger
20
+ */
21
+ export type Logger = ReturnType<typeof createLogger>;
22
+ /**
23
+ * Create a logger for a resolver context
24
+ */
25
+ export declare function createLogger(debug?: boolean): {
26
+ info: (message: string, ...args: unknown[]) => void;
27
+ warn: (message: string, ...args: unknown[]) => void;
28
+ error: (message: string, ...args: unknown[]) => void;
29
+ debug: (message: string, ...args: unknown[]) => void;
30
+ };
@@ -0,0 +1,37 @@
1
+ import { type ServerHandle } from "../runtime/index.js";
2
+ export interface StartOntOptions {
3
+ /** Port for API server (default: 3000) */
4
+ port?: number;
5
+ /** Port for MCP server (default: 3001) */
6
+ mcpPort?: number;
7
+ /** Environment to use (default: 'dev') */
8
+ env?: string;
9
+ /** Mode: 'development' warns on lockfile issues, 'production' fails. Auto-detected from NODE_ENV if not set. */
10
+ mode?: "development" | "production";
11
+ /** Set to true to only start the API server */
12
+ apiOnly?: boolean;
13
+ /** Set to true to only start the MCP server */
14
+ mcpOnly?: boolean;
15
+ }
16
+ export interface StartOntResult {
17
+ api?: ServerHandle;
18
+ mcp?: {
19
+ port: number;
20
+ };
21
+ }
22
+ /**
23
+ * Start the ont API and MCP servers.
24
+ *
25
+ * Automatically discovers ontology.config.ts and handles lockfile validation.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * import { startOnt } from 'ont-run';
30
+ *
31
+ * await startOnt({
32
+ * port: 3000,
33
+ * mcpPort: 3001,
34
+ * });
35
+ * ```
36
+ */
37
+ export declare function startOnt(options?: StartOntOptions): Promise<StartOntResult>;
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "ont-run",
3
+ "version": "0.0.1",
4
+ "description": "Ontology-enforced API framework for AI coding agents",
5
+ "type": "module",
6
+ "bin": {
7
+ "ont": "./dist/bin/ont.js"
8
+ },
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/src/index.d.ts",
12
+ "bun": "./src/index.ts",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "src",
19
+ "bin"
20
+ ],
21
+ "scripts": {
22
+ "dev": "bun run bin/ont.ts",
23
+ "build": "bun build ./src/index.ts --outdir ./dist --target node",
24
+ "build:cli": "bun build ./bin/ont.ts --outfile ./dist/bin/ont.js --target node --external @modelcontextprotocol/sdk",
25
+ "build:types": "tsc --declaration --emitDeclarationOnly",
26
+ "prepublishOnly": "bun run build && bun run build:cli && bun run build:types",
27
+ "docs": "cd docs && bun run dev",
28
+ "docs:build": "cd docs && bun run build",
29
+ "docs:preview": "cd docs && bun run preview"
30
+ },
31
+ "dependencies": {
32
+ "@hono/node-server": "^1.19.8",
33
+ "@modelcontextprotocol/sdk": "^1.0.0",
34
+ "citty": "^0.1.6",
35
+ "consola": "^3.2.0",
36
+ "hono": "^4.6.0",
37
+ "open": "^10.0.0",
38
+ "zod": "^3.24.0",
39
+ "zod-to-json-schema": "^3.23.0"
40
+ },
41
+ "devDependencies": {
42
+ "@types/bun": "latest",
43
+ "typescript": "^5.5.0"
44
+ },
45
+ "peerDependencies": {
46
+ "bun": ">=1.0.0"
47
+ },
48
+ "peerDependenciesMeta": {
49
+ "bun": {
50
+ "optional": true
51
+ }
52
+ },
53
+ "keywords": [
54
+ "api",
55
+ "framework",
56
+ "access-control",
57
+ "ai-agents",
58
+ "hono",
59
+ "zod",
60
+ "typescript"
61
+ ],
62
+ "license": "MIT"
63
+ }