@kya-os/create-molti 0.1.0-canary.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 (117) hide show
  1. package/dist/cli.d.ts +10 -0
  2. package/dist/cli.d.ts.map +1 -0
  3. package/dist/cli.js +83 -0
  4. package/dist/cli.js.map +1 -0
  5. package/dist/helpers/generate-identity.d.ts +22 -0
  6. package/dist/helpers/generate-identity.d.ts.map +1 -0
  7. package/dist/helpers/generate-identity.js +63 -0
  8. package/dist/helpers/generate-identity.js.map +1 -0
  9. package/dist/helpers/generate-molti-project.d.ts +31 -0
  10. package/dist/helpers/generate-molti-project.d.ts.map +1 -0
  11. package/dist/helpers/generate-molti-project.js +200 -0
  12. package/dist/helpers/generate-molti-project.js.map +1 -0
  13. package/dist/helpers/get-package-versions.d.ts +22 -0
  14. package/dist/helpers/get-package-versions.d.ts.map +1 -0
  15. package/dist/helpers/get-package-versions.js +60 -0
  16. package/dist/helpers/get-package-versions.js.map +1 -0
  17. package/dist/helpers/index.d.ts +12 -0
  18. package/dist/helpers/index.d.ts.map +1 -0
  19. package/dist/helpers/index.js +14 -0
  20. package/dist/helpers/index.js.map +1 -0
  21. package/dist/helpers/validate-name.d.ts +16 -0
  22. package/dist/helpers/validate-name.d.ts.map +1 -0
  23. package/dist/helpers/validate-name.js +31 -0
  24. package/dist/helpers/validate-name.js.map +1 -0
  25. package/dist/index.d.ts +12 -0
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/index.js +16 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/templates/auth-module.d.ts +7 -0
  30. package/dist/templates/auth-module.d.ts.map +1 -0
  31. package/dist/templates/auth-module.js +68 -0
  32. package/dist/templates/auth-module.js.map +1 -0
  33. package/dist/templates/dockerfile.d.ts +8 -0
  34. package/dist/templates/dockerfile.d.ts.map +1 -0
  35. package/dist/templates/dockerfile.js +40 -0
  36. package/dist/templates/dockerfile.js.map +1 -0
  37. package/dist/templates/gateway.d.ts +8 -0
  38. package/dist/templates/gateway.d.ts.map +1 -0
  39. package/dist/templates/gateway.js +112 -0
  40. package/dist/templates/gateway.js.map +1 -0
  41. package/dist/templates/github-workflow.d.ts +7 -0
  42. package/dist/templates/github-workflow.d.ts.map +1 -0
  43. package/dist/templates/github-workflow.js +48 -0
  44. package/dist/templates/github-workflow.js.map +1 -0
  45. package/dist/templates/health-module.d.ts +7 -0
  46. package/dist/templates/health-module.d.ts.map +1 -0
  47. package/dist/templates/health-module.js +62 -0
  48. package/dist/templates/health-module.js.map +1 -0
  49. package/dist/templates/identity-json.d.ts +15 -0
  50. package/dist/templates/identity-json.d.ts.map +1 -0
  51. package/dist/templates/identity-json.js +18 -0
  52. package/dist/templates/identity-json.js.map +1 -0
  53. package/dist/templates/identity-module.d.ts +8 -0
  54. package/dist/templates/identity-module.d.ts.map +1 -0
  55. package/dist/templates/identity-module.js +89 -0
  56. package/dist/templates/identity-module.js.map +1 -0
  57. package/dist/templates/moltbot-config.d.ts +7 -0
  58. package/dist/templates/moltbot-config.d.ts.map +1 -0
  59. package/dist/templates/moltbot-config.js +19 -0
  60. package/dist/templates/moltbot-config.js.map +1 -0
  61. package/dist/templates/package-json.d.ts +13 -0
  62. package/dist/templates/package-json.d.ts.map +1 -0
  63. package/dist/templates/package-json.js +34 -0
  64. package/dist/templates/package-json.js.map +1 -0
  65. package/dist/templates/readme.d.ts +14 -0
  66. package/dist/templates/readme.d.ts.map +1 -0
  67. package/dist/templates/readme.js +92 -0
  68. package/dist/templates/readme.js.map +1 -0
  69. package/dist/templates/startup-script.d.ts +8 -0
  70. package/dist/templates/startup-script.d.ts.map +1 -0
  71. package/dist/templates/startup-script.js +54 -0
  72. package/dist/templates/startup-script.js.map +1 -0
  73. package/dist/templates/tsconfig-template.d.ts +7 -0
  74. package/dist/templates/tsconfig-template.d.ts.map +1 -0
  75. package/dist/templates/tsconfig-template.js +22 -0
  76. package/dist/templates/tsconfig-template.js.map +1 -0
  77. package/dist/templates/types-module.d.ts +7 -0
  78. package/dist/templates/types-module.d.ts.map +1 -0
  79. package/dist/templates/types-module.js +73 -0
  80. package/dist/templates/types-module.js.map +1 -0
  81. package/dist/templates/worker-index.d.ts +8 -0
  82. package/dist/templates/worker-index.d.ts.map +1 -0
  83. package/dist/templates/worker-index.js +99 -0
  84. package/dist/templates/worker-index.js.map +1 -0
  85. package/dist/templates/wrangler.d.ts +16 -0
  86. package/dist/templates/wrangler.d.ts.map +1 -0
  87. package/dist/templates/wrangler.js +77 -0
  88. package/dist/templates/wrangler.js.map +1 -0
  89. package/dist/types.d.ts +61 -0
  90. package/dist/types.d.ts.map +1 -0
  91. package/dist/types.js +8 -0
  92. package/dist/types.js.map +1 -0
  93. package/package.json +50 -0
  94. package/scripts/validate-dependencies.js +38 -0
  95. package/src/cli.ts +98 -0
  96. package/src/helpers/generate-identity.ts +90 -0
  97. package/src/helpers/generate-molti-project.ts +239 -0
  98. package/src/helpers/get-package-versions.ts +78 -0
  99. package/src/helpers/index.ts +24 -0
  100. package/src/helpers/validate-name.ts +42 -0
  101. package/src/index.ts +18 -0
  102. package/src/templates/auth-module.ts +68 -0
  103. package/src/templates/dockerfile.ts +40 -0
  104. package/src/templates/gateway.ts +112 -0
  105. package/src/templates/github-workflow.ts +48 -0
  106. package/src/templates/health-module.ts +62 -0
  107. package/src/templates/identity-json.ts +29 -0
  108. package/src/templates/identity-module.ts +89 -0
  109. package/src/templates/moltbot-config.ts +23 -0
  110. package/src/templates/package-json.ts +46 -0
  111. package/src/templates/readme.ts +101 -0
  112. package/src/templates/startup-script.ts +54 -0
  113. package/src/templates/tsconfig-template.ts +26 -0
  114. package/src/templates/types-module.ts +73 -0
  115. package/src/templates/worker-index.ts +99 -0
  116. package/src/templates/wrangler.ts +89 -0
  117. package/src/types.ts +64 -0
@@ -0,0 +1,26 @@
1
+ /**
2
+ * tsconfig.json Template
3
+ *
4
+ * Generates TypeScript configuration for the scaffolded project.
5
+ */
6
+
7
+ export function generateTsconfig(): string {
8
+ return JSON.stringify(
9
+ {
10
+ compilerOptions: {
11
+ target: 'ES2022',
12
+ module: 'ESNext',
13
+ moduleResolution: 'bundler',
14
+ lib: ['ES2022', 'DOM', 'DOM.Iterable'],
15
+ types: ['@cloudflare/workers-types'],
16
+ strict: true,
17
+ noEmit: true,
18
+ skipLibCheck: true,
19
+ },
20
+ include: ['src/**/*'],
21
+ exclude: ['node_modules'],
22
+ },
23
+ null,
24
+ 2
25
+ );
26
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Types Module Template (src/types.ts)
3
+ *
4
+ * Generates the TypeScript type definitions for the Worker environment.
5
+ */
6
+
7
+ export function generateTypesModule(): string {
8
+ return `/**
9
+ * Moltworker Environment Types
10
+ */
11
+
12
+ export interface MoltbotEnv {
13
+ // Cloudflare bindings
14
+ Sandbox: DurableObjectNamespace;
15
+ ASSETS: Fetcher;
16
+ MOLTBOT_BUCKET: R2Bucket;
17
+ BROWSER: Fetcher;
18
+
19
+ // KV bindings (MCP-I identity)
20
+ NONCE_CACHE: KVNamespace;
21
+ PROOF_ARCHIVE: KVNamespace;
22
+
23
+ // MCP-I Identity
24
+ MCP_IDENTITY_AGENT_DID: string;
25
+ MCP_IDENTITY_PUBLIC_KEY: string;
26
+ MCP_IDENTITY_PRIVATE_KEY: string;
27
+
28
+ // AI Configuration
29
+ AI_GATEWAY_API_KEY?: string;
30
+ AI_GATEWAY_BASE_URL?: string;
31
+ ANTHROPIC_API_KEY?: string;
32
+ OPENAI_API_KEY?: string;
33
+
34
+ // Bot tokens
35
+ TELEGRAM_BOT_TOKEN?: string;
36
+ DISCORD_BOT_TOKEN?: string;
37
+ SLACK_BOT_TOKEN?: string;
38
+
39
+ // Cloudflare Access
40
+ CF_ACCESS_TEAM_DOMAIN?: string;
41
+ CF_ACCESS_AUD?: string;
42
+ MOLTBOT_GATEWAY_TOKEN?: string;
43
+
44
+ // R2 Storage
45
+ R2_ACCESS_KEY_ID?: string;
46
+ R2_SECRET_ACCESS_KEY?: string;
47
+ CF_ACCOUNT_ID?: string;
48
+
49
+ // AgentShield
50
+ AGENTSHIELD_API_KEY?: string;
51
+ AGENTSHIELD_API_URL?: string;
52
+ AGENTSHIELD_PROJECT_ID?: string;
53
+
54
+ // Runtime
55
+ DEV_MODE?: string;
56
+ SANDBOX_SLEEP_AFTER?: string;
57
+ MCPI_ENV?: string;
58
+ }
59
+
60
+ export interface AccessUser {
61
+ email: string;
62
+ name?: string;
63
+ }
64
+
65
+ export type AppEnv = {
66
+ Bindings: MoltbotEnv;
67
+ Variables: {
68
+ sandbox: any; // Sandbox type from @cloudflare/sandbox
69
+ accessUser?: AccessUser;
70
+ };
71
+ };
72
+ `;
73
+ }
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Worker Entry Point Template (src/index.ts)
3
+ *
4
+ * Generates the main Hono Worker that handles routing, auth,
5
+ * sandbox lifecycle, and proxy to the container.
6
+ */
7
+
8
+ export function generateWorkerIndex(projectName: string): string {
9
+ return `/**
10
+ * ${projectName} — Moltworker with MCP-I Identity
11
+ *
12
+ * Hono Worker that manages:
13
+ * - Sandbox (Container) lifecycle
14
+ * - CF Access authentication
15
+ * - Proxy to Moltbot gateway on port 18789
16
+ * - MCP-I identity proof generation
17
+ * - Health checks and status endpoints
18
+ */
19
+
20
+ import { Hono } from "hono";
21
+ import { getSandbox, buildSandboxOptions } from "@cloudflare/sandbox";
22
+ import type { MoltbotEnv, AppEnv } from "./types";
23
+ import { publicRoutes } from "./routes/public";
24
+ import { createAccessMiddleware } from "./auth";
25
+ import { ensureMoltbotGateway, MOLTBOT_PORT } from "./gateway";
26
+ import { getIdentityProvider } from "./identity";
27
+
28
+ const app = new Hono<AppEnv>();
29
+
30
+ // Initialize sandbox for all requests
31
+ app.use("*", async (c, next) => {
32
+ const options = buildSandboxOptions({
33
+ sleepAfter: Number(c.env.SANDBOX_SLEEP_AFTER) || 300,
34
+ });
35
+ const sandbox = getSandbox(c.env.Sandbox, "moltbot", options);
36
+ c.set("sandbox", sandbox);
37
+ await next();
38
+ });
39
+
40
+ // Public routes (no auth required)
41
+ app.route("/", publicRoutes);
42
+
43
+ // CF Access auth for protected routes
44
+ app.use("/api/*", createAccessMiddleware({ type: "api" }));
45
+ app.use("/_admin/*", createAccessMiddleware({ type: "admin" }));
46
+
47
+ // Proxy all other requests to Moltbot container
48
+ app.all("*", async (c) => {
49
+ const sandbox = c.get("sandbox");
50
+
51
+ try {
52
+ await ensureMoltbotGateway(sandbox, c.env as unknown as MoltbotEnv);
53
+ } catch {
54
+ return c.html(loadingPage(), 503);
55
+ }
56
+
57
+ // WebSocket upgrade
58
+ if (c.req.header("upgrade")?.toLowerCase() === "websocket") {
59
+ const ws = await sandbox.wsConnect(c.req.raw, MOLTBOT_PORT);
60
+ return new Response(null, {
61
+ status: 101,
62
+ webSocket: ws,
63
+ } as ResponseInit);
64
+ }
65
+
66
+ // HTTP proxy
67
+ const response = await sandbox.containerFetch(c.req.raw, MOLTBOT_PORT);
68
+ return response;
69
+ });
70
+
71
+ function loadingPage(): string {
72
+ return \`<!DOCTYPE html>
73
+ <html>
74
+ <head><title>${projectName} — Starting</title></head>
75
+ <body style="font-family:system-ui;display:flex;align-items:center;justify-content:center;height:100vh;margin:0;background:#0a0a0a;color:#e5e5e5">
76
+ <div style="text-align:center">
77
+ <h2>Starting ${projectName}...</h2>
78
+ <p>The agent container is warming up. This page will refresh automatically.</p>
79
+ <script>setTimeout(() => location.reload(), 3000)</script>
80
+ </div>
81
+ </body>
82
+ </html>\`;
83
+ }
84
+
85
+ // Export for scheduled handler (R2 backup)
86
+ export default {
87
+ fetch: app.fetch,
88
+ async scheduled(_event: ScheduledEvent, env: MoltbotEnv, _ctx: ExecutionContext) {
89
+ const options = buildSandboxOptions({ sleepAfter: 300 });
90
+ const sandbox = getSandbox(env.Sandbox, "moltbot", options);
91
+ // Scheduled backup can be added here
92
+ void sandbox;
93
+ },
94
+ };
95
+
96
+ // Export Durable Object class
97
+ export { Sandbox } from "@cloudflare/sandbox";
98
+ `;
99
+ }
@@ -0,0 +1,89 @@
1
+ /**
2
+ * wrangler.jsonc Template
3
+ *
4
+ * Generates Cloudflare Workers configuration with Container binding,
5
+ * R2 storage, Browser binding, and MCP-I identity vars.
6
+ */
7
+
8
+ import type { MoltiProjectOptions } from '../types.js';
9
+
10
+ interface WranglerOptions {
11
+ projectName: string;
12
+ agentDid: string;
13
+ publicKey: string;
14
+ agentShieldProjectId?: string;
15
+ instanceType: string;
16
+ }
17
+
18
+ export function generateWranglerJsonc(opts: WranglerOptions): string {
19
+ const { projectName, agentDid, publicKey, agentShieldProjectId, instanceType } = opts;
20
+
21
+ const agentShieldLine = agentShieldProjectId
22
+ ? ` // AgentShield Integration
23
+ "AGENTSHIELD_PROJECT_ID": "${agentShieldProjectId}",
24
+ "AGENTSHIELD_API_URL": "https://kya.vouched.id",`
25
+ : ` // AgentShield Integration (uncomment when configured)
26
+ // "AGENTSHIELD_PROJECT_ID": "your-project-id",
27
+ // "AGENTSHIELD_API_URL": "https://kya.vouched.id",`;
28
+
29
+ return `{
30
+ "name": "${projectName}",
31
+ "main": "src/index.ts",
32
+ "compatibility_date": "2025-05-06",
33
+ "compatibility_flags": ["nodejs_compat"],
34
+ "observability": { "enabled": true },
35
+
36
+ // Sandbox (Container) binding
37
+ "containers": [
38
+ {
39
+ "class_name": "Sandbox",
40
+ "image": "./Dockerfile",
41
+ "instance_type": "${instanceType}",
42
+ "max_instances": 1
43
+ }
44
+ ],
45
+
46
+ // Durable Object for Sandbox state
47
+ "durable_objects": {
48
+ "bindings": [
49
+ { "name": "Sandbox", "class_name": "Sandbox" }
50
+ ]
51
+ },
52
+
53
+ // R2 bucket for persistent storage
54
+ "r2_buckets": [
55
+ { "binding": "MOLTBOT_BUCKET", "bucket_name": "${projectName}-data" }
56
+ ],
57
+
58
+ // Browser binding for CDP
59
+ "browser": { "binding": "BROWSER" },
60
+
61
+ // KV for identity (nonce cache + proof archive)
62
+ "kv_namespaces": [
63
+ { "binding": "NONCE_CACHE" },
64
+ { "binding": "PROOF_ARCHIVE" }
65
+ ],
66
+
67
+ // Scheduled backup (every 5 minutes)
68
+ "triggers": {
69
+ "crons": ["*/5 * * * *"]
70
+ },
71
+
72
+ "vars": {
73
+ // MCP-I Identity (public — safe to commit)
74
+ "MCP_IDENTITY_AGENT_DID": "${agentDid}",
75
+ "MCP_IDENTITY_PUBLIC_KEY": "${publicKey}",
76
+
77
+ ${agentShieldLine}
78
+
79
+ "MCPI_ENV": "development"
80
+ }
81
+
82
+ // SECRETS (via wrangler secret or GitHub Secrets):
83
+ // - MCP_IDENTITY_PRIVATE_KEY
84
+ // - AGENTSHIELD_API_KEY
85
+ // - ANTHROPIC_API_KEY or OPENAI_API_KEY
86
+ // - CLOUDFLARE_API_TOKEN (for CI/CD)
87
+ }
88
+ `;
89
+ }
package/src/types.ts ADDED
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Types for @kya-os/create-molti
3
+ *
4
+ * Defines the configuration options and result types
5
+ * for scaffolding Moltworker projects with MCP-I identity.
6
+ */
7
+
8
+ /**
9
+ * Represents a generated file with its content
10
+ */
11
+ export interface GeneratedFile {
12
+ /** Relative path from project root (e.g., "src/index.ts") */
13
+ path: string;
14
+ /** File content as string */
15
+ content: string;
16
+ /** Encoding type */
17
+ encoding: 'utf-8' | 'base64';
18
+ }
19
+
20
+ /**
21
+ * Options for generating a Molti project
22
+ */
23
+ export interface MoltiProjectOptions {
24
+ /** Project name (used for package.json, wrangler config, container name) */
25
+ projectName: string;
26
+ /** Human-readable agent name (defaults to projectName) */
27
+ agentName?: string;
28
+ /** Agent description for metadata */
29
+ agentDescription?: string;
30
+ /** AgentShield project ID (for proof reporting) */
31
+ agentShieldProjectId?: string;
32
+ /** AgentShield API key (stored as GitHub Secret) */
33
+ agentShieldApiKey?: string;
34
+ /** Enable KTA reputation tracking */
35
+ enableReputation?: boolean;
36
+ /** Cloudflare Container instance type */
37
+ instanceType?: 'lite' | 'basic' | 'standard-1' | 'standard-2' | 'standard-3' | 'standard-4';
38
+ /** Skip identity generation (for testing) */
39
+ skipIdentity?: boolean;
40
+ }
41
+
42
+ /**
43
+ * Generated identity from Ed25519 keypair
44
+ */
45
+ export interface MoltiIdentity {
46
+ /** DID:key identifier (e.g., "did:key:z6Mk...") */
47
+ did: string;
48
+ /** Base64-encoded Ed25519 public key */
49
+ publicKey: string;
50
+ /** Base64-encoded Ed25519 private key */
51
+ privateKey: string;
52
+ }
53
+
54
+ /**
55
+ * Result of project generation
56
+ */
57
+ export interface MoltiGenerateResult {
58
+ /** All generated files */
59
+ files: GeneratedFile[];
60
+ /** Generated identity (DID, keys) */
61
+ identity: MoltiIdentity;
62
+ /** Secrets that should be added to GitHub Secrets (not committed to repo) */
63
+ secrets: Record<string, string>;
64
+ }