luca 2.0.0 → 3.0.2
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.
- package/.github/workflows/release.yaml +170 -0
- package/AGENTS.md +99 -0
- package/CLAUDE.md +123 -0
- package/CNAME +1 -0
- package/README.md +275 -9
- package/RUNME.md +56 -0
- package/assistants/codingAssistant/ABOUT.md +5 -0
- package/assistants/codingAssistant/CORE.md +33 -0
- package/assistants/codingAssistant/hooks.ts +21 -0
- package/assistants/codingAssistant/tools.ts +12 -0
- package/assistants/inkbot/ABOUT.md +16 -0
- package/assistants/inkbot/CORE.md +330 -0
- package/assistants/inkbot/hooks.ts +6 -0
- package/assistants/inkbot/tools.ts +53 -0
- package/assistants/researcher/ABOUT.md +5 -0
- package/assistants/researcher/CORE.md +46 -0
- package/assistants/researcher/hooks.ts +16 -0
- package/assistants/researcher/tools.ts +237 -0
- package/bun.lock +2667 -0
- package/bunfig.toml +3 -0
- package/commands/audit-docs.ts +740 -0
- package/commands/build-bootstrap.ts +117 -0
- package/commands/build-python-bridge.ts +42 -0
- package/commands/build-scaffolds.ts +175 -0
- package/commands/bundle-consumer-project.ts +521 -0
- package/commands/generate-api-docs.ts +114 -0
- package/commands/inkbot.ts +874 -0
- package/commands/release.ts +80 -0
- package/commands/try-all-challenges.ts +543 -0
- package/commands/try-challenge.ts +100 -0
- package/dist/agi/container.server.d.ts +63 -0
- package/dist/agi/container.server.d.ts.map +1 -0
- package/dist/agi/endpoints/ask.d.ts +20 -0
- package/dist/agi/endpoints/ask.d.ts.map +1 -0
- package/dist/agi/endpoints/conversations/[id].d.ts +27 -0
- package/dist/agi/endpoints/conversations/[id].d.ts.map +1 -0
- package/dist/agi/endpoints/conversations.d.ts +18 -0
- package/dist/agi/endpoints/conversations.d.ts.map +1 -0
- package/dist/agi/endpoints/experts.d.ts +8 -0
- package/dist/agi/endpoints/experts.d.ts.map +1 -0
- package/dist/agi/feature.d.ts +9 -0
- package/dist/agi/feature.d.ts.map +1 -0
- package/dist/agi/features/assistant.d.ts +509 -0
- package/dist/agi/features/assistant.d.ts.map +1 -0
- package/dist/agi/features/assistants-manager.d.ts +236 -0
- package/dist/agi/features/assistants-manager.d.ts.map +1 -0
- package/dist/agi/features/autonomous-assistant.d.ts +281 -0
- package/dist/agi/features/autonomous-assistant.d.ts.map +1 -0
- package/dist/agi/features/browser-use.d.ts +479 -0
- package/dist/agi/features/browser-use.d.ts.map +1 -0
- package/dist/agi/features/claude-code.d.ts +824 -0
- package/dist/agi/features/claude-code.d.ts.map +1 -0
- package/dist/agi/features/conversation-history.d.ts +245 -0
- package/dist/agi/features/conversation-history.d.ts.map +1 -0
- package/dist/agi/features/conversation.d.ts +464 -0
- package/dist/agi/features/conversation.d.ts.map +1 -0
- package/dist/agi/features/docs-reader.d.ts +72 -0
- package/dist/agi/features/docs-reader.d.ts.map +1 -0
- package/dist/agi/features/file-tools.d.ts +110 -0
- package/dist/agi/features/file-tools.d.ts.map +1 -0
- package/dist/agi/features/luca-coder.d.ts +323 -0
- package/dist/agi/features/luca-coder.d.ts.map +1 -0
- package/dist/agi/features/openai-codex.d.ts +381 -0
- package/dist/agi/features/openai-codex.d.ts.map +1 -0
- package/dist/agi/features/openapi.d.ts +200 -0
- package/dist/agi/features/openapi.d.ts.map +1 -0
- package/dist/agi/features/skills-library.d.ts +167 -0
- package/dist/agi/features/skills-library.d.ts.map +1 -0
- package/dist/agi/index.d.ts +5 -0
- package/dist/agi/index.d.ts.map +1 -0
- package/dist/agi/lib/interceptor-chain.d.ts +44 -0
- package/dist/agi/lib/interceptor-chain.d.ts.map +1 -0
- package/dist/agi/lib/token-counter.d.ts +13 -0
- package/dist/agi/lib/token-counter.d.ts.map +1 -0
- package/dist/bootstrap/generated.d.ts +5 -0
- package/dist/bootstrap/generated.d.ts.map +1 -0
- package/dist/browser.d.ts +12 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/bus.d.ts +29 -0
- package/dist/bus.d.ts.map +1 -0
- package/dist/cli/build-info.d.ts +4 -0
- package/dist/cli/build-info.d.ts.map +1 -0
- package/dist/cli/cli.d.ts +3 -12
- package/dist/cli/cli.d.ts.map +1 -0
- package/dist/client.d.ts +60 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/clients/civitai/index.d.ts +472 -0
- package/dist/clients/civitai/index.d.ts.map +1 -0
- package/dist/clients/client-template.d.ts +30 -0
- package/dist/clients/client-template.d.ts.map +1 -0
- package/dist/clients/comfyui/index.d.ts +281 -0
- package/dist/clients/comfyui/index.d.ts.map +1 -0
- package/dist/clients/elevenlabs/index.d.ts +197 -0
- package/dist/clients/elevenlabs/index.d.ts.map +1 -0
- package/dist/clients/graph.d.ts +64 -0
- package/dist/clients/graph.d.ts.map +1 -0
- package/dist/clients/openai/index.d.ts +247 -0
- package/dist/clients/openai/index.d.ts.map +1 -0
- package/dist/clients/rest.d.ts +92 -0
- package/dist/clients/rest.d.ts.map +1 -0
- package/dist/clients/supabase/index.d.ts +176 -0
- package/dist/clients/supabase/index.d.ts.map +1 -0
- package/dist/clients/websocket.d.ts +127 -0
- package/dist/clients/websocket.d.ts.map +1 -0
- package/dist/command.d.ts +163 -0
- package/dist/command.d.ts.map +1 -0
- package/dist/commands/bootstrap.d.ts +20 -0
- package/dist/commands/bootstrap.d.ts.map +1 -0
- package/dist/commands/chat.d.ts +37 -0
- package/dist/commands/chat.d.ts.map +1 -0
- package/dist/commands/code.d.ts +28 -0
- package/dist/commands/code.d.ts.map +1 -0
- package/dist/commands/console.d.ts +22 -0
- package/dist/commands/console.d.ts.map +1 -0
- package/dist/commands/describe.d.ts +50 -0
- package/dist/commands/describe.d.ts.map +1 -0
- package/dist/commands/eval.d.ts +23 -0
- package/dist/commands/eval.d.ts.map +1 -0
- package/dist/commands/help.d.ts +25 -0
- package/dist/commands/help.d.ts.map +1 -0
- package/dist/commands/index.d.ts +18 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/introspect.d.ts +24 -0
- package/dist/commands/introspect.d.ts.map +1 -0
- package/dist/commands/mcp.d.ts +35 -0
- package/dist/commands/mcp.d.ts.map +1 -0
- package/dist/commands/prompt.d.ts +38 -0
- package/dist/commands/prompt.d.ts.map +1 -0
- package/dist/commands/run.d.ts +24 -0
- package/dist/commands/run.d.ts.map +1 -0
- package/dist/commands/sandbox-mcp.d.ts +34 -0
- package/dist/commands/sandbox-mcp.d.ts.map +1 -0
- package/dist/commands/save-api-docs.d.ts +21 -0
- package/dist/commands/save-api-docs.d.ts.map +1 -0
- package/dist/commands/scaffold.d.ts +24 -0
- package/dist/commands/scaffold.d.ts.map +1 -0
- package/dist/commands/select.d.ts +22 -0
- package/dist/commands/select.d.ts.map +1 -0
- package/dist/commands/serve.d.ts +29 -0
- package/dist/commands/serve.d.ts.map +1 -0
- package/dist/container-describer.d.ts +144 -0
- package/dist/container-describer.d.ts.map +1 -0
- package/dist/container.d.ts +451 -0
- package/dist/container.d.ts.map +1 -0
- package/dist/endpoint.d.ts +113 -0
- package/dist/endpoint.d.ts.map +1 -0
- package/dist/feature.d.ts +47 -0
- package/dist/feature.d.ts.map +1 -0
- package/dist/graft.d.ts +29 -0
- package/dist/graft.d.ts.map +1 -0
- package/dist/hash-object.d.ts +8 -0
- package/dist/hash-object.d.ts.map +1 -0
- package/dist/helper.d.ts +209 -0
- package/dist/helper.d.ts.map +1 -0
- package/dist/introspection/generated.node.d.ts +44623 -0
- package/dist/introspection/generated.node.d.ts.map +1 -0
- package/dist/introspection/generated.web.d.ts +1412 -0
- package/dist/introspection/generated.web.d.ts.map +1 -0
- package/dist/introspection/index.d.ts +156 -0
- package/dist/introspection/index.d.ts.map +1 -0
- package/dist/introspection/scan.d.ts +147 -0
- package/dist/introspection/scan.d.ts.map +1 -0
- package/dist/node/container.d.ts +256 -0
- package/dist/node/container.d.ts.map +1 -0
- package/dist/node/feature.d.ts +9 -0
- package/dist/node/feature.d.ts.map +1 -0
- package/dist/node/features/container-link.d.ts +213 -0
- package/dist/node/features/container-link.d.ts.map +1 -0
- package/dist/node/features/content-db.d.ts +354 -0
- package/dist/node/features/content-db.d.ts.map +1 -0
- package/dist/node/features/disk-cache.d.ts +236 -0
- package/dist/node/features/disk-cache.d.ts.map +1 -0
- package/dist/node/features/dns.d.ts +511 -0
- package/dist/node/features/dns.d.ts.map +1 -0
- package/dist/node/features/docker.d.ts +485 -0
- package/dist/node/features/docker.d.ts.map +1 -0
- package/dist/node/features/downloader.d.ts +73 -0
- package/dist/node/features/downloader.d.ts.map +1 -0
- package/dist/node/features/figlet-fonts.d.ts +4 -0
- package/dist/node/features/figlet-fonts.d.ts.map +1 -0
- package/dist/node/features/file-manager.d.ts +177 -0
- package/dist/node/features/file-manager.d.ts.map +1 -0
- package/dist/node/features/fs.d.ts +635 -0
- package/dist/node/features/fs.d.ts.map +1 -0
- package/dist/node/features/git.d.ts +329 -0
- package/dist/node/features/git.d.ts.map +1 -0
- package/dist/node/features/google-auth.d.ts +200 -0
- package/dist/node/features/google-auth.d.ts.map +1 -0
- package/dist/node/features/google-calendar.d.ts +194 -0
- package/dist/node/features/google-calendar.d.ts.map +1 -0
- package/dist/node/features/google-docs.d.ts +138 -0
- package/dist/node/features/google-docs.d.ts.map +1 -0
- package/dist/node/features/google-drive.d.ts +202 -0
- package/dist/node/features/google-drive.d.ts.map +1 -0
- package/dist/node/features/google-mail.d.ts +221 -0
- package/dist/node/features/google-mail.d.ts.map +1 -0
- package/dist/node/features/google-sheets.d.ts +157 -0
- package/dist/node/features/google-sheets.d.ts.map +1 -0
- package/dist/node/features/grep.d.ts +207 -0
- package/dist/node/features/grep.d.ts.map +1 -0
- package/dist/node/features/helpers.d.ts +236 -0
- package/dist/node/features/helpers.d.ts.map +1 -0
- package/dist/node/features/ink.d.ts +332 -0
- package/dist/node/features/ink.d.ts.map +1 -0
- package/dist/node/features/ipc-socket.d.ts +298 -0
- package/dist/node/features/ipc-socket.d.ts.map +1 -0
- package/dist/node/features/json-tree.d.ts +140 -0
- package/dist/node/features/json-tree.d.ts.map +1 -0
- package/dist/node/features/networking.d.ts +373 -0
- package/dist/node/features/networking.d.ts.map +1 -0
- package/dist/node/features/nlp.d.ts +125 -0
- package/dist/node/features/nlp.d.ts.map +1 -0
- package/dist/node/features/opener.d.ts +93 -0
- package/dist/node/features/opener.d.ts.map +1 -0
- package/dist/node/features/os.d.ts +168 -0
- package/dist/node/features/os.d.ts.map +1 -0
- package/dist/node/features/package-finder.d.ts +419 -0
- package/dist/node/features/package-finder.d.ts.map +1 -0
- package/dist/node/features/postgres.d.ts +173 -0
- package/dist/node/features/postgres.d.ts.map +1 -0
- package/dist/node/features/proc.d.ts +285 -0
- package/dist/node/features/proc.d.ts.map +1 -0
- package/dist/node/features/process-manager.d.ts +427 -0
- package/dist/node/features/process-manager.d.ts.map +1 -0
- package/dist/node/features/python.d.ts +477 -0
- package/dist/node/features/python.d.ts.map +1 -0
- package/dist/node/features/redis.d.ts +247 -0
- package/dist/node/features/redis.d.ts.map +1 -0
- package/dist/node/features/repl.d.ts +84 -0
- package/dist/node/features/repl.d.ts.map +1 -0
- package/dist/node/features/runpod.d.ts +527 -0
- package/dist/node/features/runpod.d.ts.map +1 -0
- package/dist/node/features/secure-shell.d.ts +145 -0
- package/dist/node/features/secure-shell.d.ts.map +1 -0
- package/dist/node/features/semantic-search.d.ts +207 -0
- package/dist/node/features/semantic-search.d.ts.map +1 -0
- package/dist/node/features/sqlite.d.ts +180 -0
- package/dist/node/features/sqlite.d.ts.map +1 -0
- package/dist/node/features/telegram.d.ts +173 -0
- package/dist/node/features/telegram.d.ts.map +1 -0
- package/dist/node/features/transpiler.d.ts +51 -0
- package/dist/node/features/transpiler.d.ts.map +1 -0
- package/dist/node/features/tts.d.ts +108 -0
- package/dist/node/features/tts.d.ts.map +1 -0
- package/dist/node/features/ui.d.ts +562 -0
- package/dist/node/features/ui.d.ts.map +1 -0
- package/dist/node/features/vault.d.ts +90 -0
- package/dist/node/features/vault.d.ts.map +1 -0
- package/dist/node/features/vm.d.ts +285 -0
- package/dist/node/features/vm.d.ts.map +1 -0
- package/dist/node/features/yaml-tree.d.ts +118 -0
- package/dist/node/features/yaml-tree.d.ts.map +1 -0
- package/dist/node/features/yaml.d.ts +127 -0
- package/dist/node/features/yaml.d.ts.map +1 -0
- package/dist/node.d.ts +67 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/python/generated.d.ts +2 -0
- package/dist/python/generated.d.ts.map +1 -0
- package/dist/react/index.d.ts +36 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/registry.d.ts +97 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/scaffolds/generated.d.ts +13 -0
- package/dist/scaffolds/generated.d.ts.map +1 -0
- package/dist/scaffolds/template.d.ts +11 -0
- package/dist/scaffolds/template.d.ts.map +1 -0
- package/dist/schemas/base.d.ts +254 -0
- package/dist/schemas/base.d.ts.map +1 -0
- package/dist/selector.d.ts +130 -0
- package/dist/selector.d.ts.map +1 -0
- package/dist/server.d.ts +89 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/servers/express.d.ts +104 -0
- package/dist/servers/express.d.ts.map +1 -0
- package/dist/servers/mcp.d.ts +201 -0
- package/dist/servers/mcp.d.ts.map +1 -0
- package/dist/servers/socket.d.ts +121 -0
- package/dist/servers/socket.d.ts.map +1 -0
- package/dist/state.d.ts +24 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/web/clients/socket.d.ts +37 -0
- package/dist/web/clients/socket.d.ts.map +1 -0
- package/dist/web/container.d.ts +55 -0
- package/dist/web/container.d.ts.map +1 -0
- package/dist/web/extension.d.ts +4 -0
- package/dist/web/extension.d.ts.map +1 -0
- package/dist/web/feature.d.ts +8 -0
- package/dist/web/feature.d.ts.map +1 -0
- package/dist/web/features/asset-loader.d.ts +35 -0
- package/dist/web/features/asset-loader.d.ts.map +1 -0
- package/dist/web/features/container-link.d.ts +167 -0
- package/dist/web/features/container-link.d.ts.map +1 -0
- package/dist/web/features/esbuild.d.ts +51 -0
- package/dist/web/features/esbuild.d.ts.map +1 -0
- package/dist/web/features/helpers.d.ts +140 -0
- package/dist/web/features/helpers.d.ts.map +1 -0
- package/dist/web/features/network.d.ts +69 -0
- package/dist/web/features/network.d.ts.map +1 -0
- package/dist/web/features/speech.d.ts +71 -0
- package/dist/web/features/speech.d.ts.map +1 -0
- package/dist/web/features/vault.d.ts +62 -0
- package/dist/web/features/vault.d.ts.map +1 -0
- package/dist/web/features/vm.d.ts +48 -0
- package/dist/web/features/vm.d.ts.map +1 -0
- package/dist/web/features/voice-recognition.d.ts +96 -0
- package/dist/web/features/voice-recognition.d.ts.map +1 -0
- package/dist/web/shims/isomorphic-vm.d.ts +22 -0
- package/dist/web/shims/isomorphic-vm.d.ts.map +1 -0
- package/index.html +1457 -0
- package/index.ts +1 -0
- package/install.sh +84 -0
- package/luca.cli.ts +16 -0
- package/luca.console.ts +9 -0
- package/main.py +6 -0
- package/package.json +219 -58
- package/public/index.html +1457 -0
- package/public/slides-ai-native.html +902 -0
- package/public/slides-intro.html +974 -0
- package/pyproject.toml +7 -0
- package/scripts/build-web.ts +28 -0
- package/scripts/examples/ask-luca-expert.ts +42 -0
- package/scripts/examples/assistant-questions.ts +12 -0
- package/scripts/examples/excalidraw-expert.ts +75 -0
- package/scripts/examples/expert-chat.ts +0 -0
- package/scripts/examples/file-manager.ts +14 -0
- package/scripts/examples/ideas.ts +12 -0
- package/scripts/examples/interactive-chat.ts +20 -0
- package/scripts/examples/openai-tool-calls.ts +113 -0
- package/scripts/examples/opening-a-web-browser.ts +5 -0
- package/scripts/examples/telegram-bot.ts +79 -0
- package/scripts/examples/using-assistant-with-mcp.ts +555 -0
- package/scripts/examples/using-claude-code.ts +10 -0
- package/scripts/examples/using-contentdb.ts +35 -0
- package/scripts/examples/using-conversations.ts +35 -0
- package/scripts/examples/using-disk-cache.ts +10 -0
- package/scripts/examples/using-docker-shell.ts +75 -0
- package/scripts/examples/using-elevenlabs.ts +25 -0
- package/scripts/examples/using-google-calendar.ts +57 -0
- package/scripts/examples/using-google-docs.ts +74 -0
- package/scripts/examples/using-google-drive.ts +74 -0
- package/scripts/examples/using-google-sheets.ts +89 -0
- package/scripts/examples/using-nlp.ts +55 -0
- package/scripts/examples/using-ollama.ts +11 -0
- package/scripts/examples/using-postgres.ts +55 -0
- package/scripts/examples/using-runpod.ts +32 -0
- package/scripts/examples/using-tts.ts +40 -0
- package/scripts/scaffold.ts +391 -0
- package/scripts/scratch.ts +15 -0
- package/scripts/stamp-build.sh +12 -0
- package/scripts/test-assistant-hooks.ts +13 -0
- package/scripts/test-docs-reader.ts +10 -0
- package/scripts/test-linux-binary.sh +80 -0
- package/scripts/update-introspection-data.ts +58 -0
- package/src/agi/README.md +14 -0
- package/src/agi/container.server.ts +156 -0
- package/src/agi/feature.ts +13 -0
- package/src/agi/features/agent-memory.ts +694 -0
- package/src/agi/features/assistant.ts +1653 -0
- package/src/agi/features/assistants-manager.ts +534 -0
- package/src/agi/features/autonomous-assistant.ts +431 -0
- package/src/agi/features/browser-use.ts +672 -0
- package/src/agi/features/claude-code.ts +1584 -0
- package/src/agi/features/coding-tools.ts +175 -0
- package/src/agi/features/conversation-history.ts +672 -0
- package/src/agi/features/conversation.ts +1494 -0
- package/src/agi/features/docs-reader.ts +167 -0
- package/src/agi/features/file-tools.ts +340 -0
- package/src/agi/features/luca-coder.ts +641 -0
- package/src/agi/features/mcp-bridge.ts +532 -0
- package/src/agi/features/openai-codex.ts +651 -0
- package/src/agi/features/openapi.ts +445 -0
- package/src/agi/features/skills-library.ts +557 -0
- package/src/agi/index.ts +6 -0
- package/src/agi/lib/interceptor-chain.ts +89 -0
- package/src/agi/lib/token-counter.ts +202 -0
- package/src/bootstrap/generated.ts +9791 -0
- package/src/browser.ts +25 -0
- package/src/bus.ts +122 -0
- package/src/cli/build-info.ts +4 -0
- package/src/cli/cli.ts +355 -0
- package/src/client.ts +170 -0
- package/src/clients/civitai/index.ts +537 -0
- package/src/clients/client-template.ts +41 -0
- package/src/clients/comfyui/index.ts +604 -0
- package/src/clients/elevenlabs/index.ts +317 -0
- package/src/clients/graph.ts +87 -0
- package/src/clients/openai/index.ts +456 -0
- package/src/clients/rest.ts +207 -0
- package/src/clients/supabase/index.ts +357 -0
- package/src/clients/voicebox/index.ts +300 -0
- package/src/clients/websocket.ts +251 -0
- package/src/command.ts +506 -0
- package/src/commands/bootstrap.ts +244 -0
- package/src/commands/chat.ts +309 -0
- package/src/commands/code.ts +371 -0
- package/src/commands/console.ts +189 -0
- package/src/commands/describe.ts +243 -0
- package/src/commands/eval.ts +67 -0
- package/src/commands/help.ts +240 -0
- package/src/commands/index.ts +19 -0
- package/src/commands/introspect.ts +218 -0
- package/src/commands/mcp.ts +64 -0
- package/src/commands/prompt.ts +1014 -0
- package/src/commands/run.ts +278 -0
- package/src/commands/sandbox-mcp.ts +343 -0
- package/src/commands/save-api-docs.ts +51 -0
- package/src/commands/scaffold.ts +225 -0
- package/src/commands/select.ts +99 -0
- package/src/commands/serve.ts +208 -0
- package/src/container-describer.ts +1091 -0
- package/src/container.ts +1199 -0
- package/src/endpoint.ts +365 -0
- package/src/entity.ts +173 -0
- package/src/feature.ts +118 -0
- package/src/graft.ts +181 -0
- package/src/hash-object.ts +97 -0
- package/src/helper.ts +849 -0
- package/src/introspection/generated.agi.ts +41200 -0
- package/src/introspection/generated.node.ts +28773 -0
- package/src/introspection/generated.web.ts +2272 -0
- package/src/introspection/index.ts +296 -0
- package/src/introspection/scan.ts +1136 -0
- package/src/node/container.ts +409 -0
- package/src/node/feature.ts +13 -0
- package/src/node/features/container-link.ts +559 -0
- package/src/node/features/content-db.ts +849 -0
- package/src/node/features/disk-cache.ts +388 -0
- package/src/node/features/display-result.ts +57 -0
- package/src/node/features/dns.ts +669 -0
- package/src/node/features/docker.ts +921 -0
- package/src/node/features/downloader.ts +79 -0
- package/src/node/features/figlet-fonts.ts +600 -0
- package/src/node/features/file-manager.ts +535 -0
- package/src/node/features/fs.ts +1050 -0
- package/src/node/features/git.ts +592 -0
- package/src/node/features/google-auth.ts +504 -0
- package/src/node/features/google-calendar.ts +306 -0
- package/src/node/features/google-docs.ts +412 -0
- package/src/node/features/google-drive.ts +346 -0
- package/src/node/features/google-mail.ts +540 -0
- package/src/node/features/google-sheets.ts +286 -0
- package/src/node/features/grep.ts +427 -0
- package/src/node/features/helpers.ts +762 -0
- package/src/node/features/ink.ts +490 -0
- package/src/node/features/ipc-socket.ts +649 -0
- package/src/node/features/json-tree.ts +170 -0
- package/src/node/features/networking.ts +961 -0
- package/src/node/features/nlp.ts +212 -0
- package/src/node/features/opener.ts +180 -0
- package/src/node/features/os.ts +403 -0
- package/src/node/features/package-finder.ts +540 -0
- package/src/node/features/postgres.ts +289 -0
- package/src/node/features/proc.ts +503 -0
- package/src/node/features/process-manager.ts +844 -0
- package/src/node/features/python.ts +912 -0
- package/src/node/features/redis.ts +446 -0
- package/src/node/features/repl.ts +212 -0
- package/src/node/features/runpod.ts +811 -0
- package/src/node/features/secure-shell.ts +261 -0
- package/src/node/features/semantic-search.ts +935 -0
- package/src/node/features/sqlite.ts +289 -0
- package/src/node/features/telegram.ts +343 -0
- package/src/node/features/transpiler.ts +160 -0
- package/src/node/features/tts.ts +185 -0
- package/src/node/features/ui.ts +791 -0
- package/src/node/features/vault.ts +153 -0
- package/src/node/features/vm.ts +462 -0
- package/src/node/features/yaml-tree.ts +148 -0
- package/src/node/features/yaml.ts +133 -0
- package/src/node.ts +76 -0
- package/src/python/bridge.py +220 -0
- package/src/python/generated.ts +226 -0
- package/src/react/index.ts +175 -0
- package/src/registry.ts +210 -0
- package/src/scaffolds/generated.ts +1814 -0
- package/src/scaffolds/template.ts +46 -0
- package/src/schemas/base.ts +296 -0
- package/src/selector.ts +352 -0
- package/src/server.ts +229 -0
- package/src/servers/express.ts +283 -0
- package/src/servers/mcp.ts +802 -0
- package/src/servers/socket.ts +258 -0
- package/src/state.ts +101 -0
- package/src/web/clients/socket.ts +99 -0
- package/src/web/container.ts +75 -0
- package/src/web/extension.ts +30 -0
- package/src/web/feature.ts +12 -0
- package/src/web/features/asset-loader.ts +72 -0
- package/src/web/features/container-link.ts +382 -0
- package/src/web/features/esbuild.ts +93 -0
- package/src/web/features/helpers.ts +291 -0
- package/src/web/features/network.ts +85 -0
- package/src/web/features/speech.ts +104 -0
- package/src/web/features/vault.ts +207 -0
- package/src/web/features/vm.ts +85 -0
- package/src/web/features/voice-recognition.ts +161 -0
- package/src/web/shims/isomorphic-vm.ts +149 -0
- package/tsconfig.build.json +12 -0
- package/tsconfig.json +58 -0
- package/uv.lock +8 -0
- package/LICENSE +0 -21
- package/dist/cli/cli.js +0 -48
- package/dist/cli/common.d.ts +0 -2
- package/dist/cli/common.js +0 -6
- package/dist/cli/index.d.ts +0 -2
- package/dist/cli/index.js +0 -5
- package/dist/cli/run.d.ts +0 -1
- package/dist/cli/run.js +0 -38
- package/dist/core/index.d.ts +0 -4
- package/dist/core/index.js +0 -32
- package/dist/core/read.d.ts +0 -2
- package/dist/core/read.js +0 -29
- package/dist/core/request.d.ts +0 -1
- package/dist/core/request.js +0 -2
- package/dist/core/write.d.ts +0 -2
- package/dist/core/write.js +0 -21
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -5
- package/dist/utils/common.d.ts +0 -9
- package/dist/utils/common.js +0 -57
- package/dist/utils/consts.d.ts +0 -3
- package/dist/utils/consts.js +0 -11
- package/dist/utils/dict.d.ts +0 -1
- package/dist/utils/dict.js +0 -7
- package/dist/utils/index.d.ts +0 -5
- package/dist/utils/index.js +0 -21
- package/dist/utils/log.d.ts +0 -1
- package/dist/utils/log.js +0 -5
- package/dist/utils/types.d.ts +0 -1
- package/dist/utils/types.js +0 -2
- package/dist/utils/utils.test.d.ts +0 -1
- package/dist/utils/utils.test.js +0 -7
|
@@ -0,0 +1,1814 @@
|
|
|
1
|
+
// Auto-generated scaffold and MCP readme content
|
|
2
|
+
// Source: docs/scaffolds/*.md, docs/examples/assistant/, and docs/mcp/readme.md
|
|
3
|
+
//
|
|
4
|
+
// Do not edit manually. Run: luca build-scaffolds
|
|
5
|
+
|
|
6
|
+
export interface ScaffoldSection {
|
|
7
|
+
heading: string
|
|
8
|
+
code: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ScaffoldData {
|
|
12
|
+
sections: ScaffoldSection[]
|
|
13
|
+
full: string
|
|
14
|
+
tutorial: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const scaffolds: Record<string, ScaffoldData> = {
|
|
18
|
+
feature: {
|
|
19
|
+
sections: [
|
|
20
|
+
{ heading: "Imports", code: `import { z } from 'zod'
|
|
21
|
+
import { FeatureStateSchema, FeatureOptionsSchema, FeatureEventsSchema } from 'luca'
|
|
22
|
+
import { Feature } from 'luca'` },
|
|
23
|
+
{ heading: "Schemas", code: `export const {{PascalName}}StateSchema = FeatureStateSchema.extend({
|
|
24
|
+
// Add your state fields here. These are observable — changes emit events.
|
|
25
|
+
// Example: itemCount: z.number().default(0).describe('Number of items stored'),
|
|
26
|
+
})
|
|
27
|
+
export type {{PascalName}}State = z.infer<typeof {{PascalName}}StateSchema>
|
|
28
|
+
|
|
29
|
+
export const {{PascalName}}OptionsSchema = FeatureOptionsSchema.extend({
|
|
30
|
+
// Add constructor options here. Validated when the feature is created.
|
|
31
|
+
// Example: directory: z.string().optional().describe('Storage directory path'),
|
|
32
|
+
})
|
|
33
|
+
export type {{PascalName}}Options = z.infer<typeof {{PascalName}}OptionsSchema>
|
|
34
|
+
|
|
35
|
+
export const {{PascalName}}EventsSchema = FeatureEventsSchema.extend({
|
|
36
|
+
// Each key is an event name. Value is z.tuple() of listener arguments.
|
|
37
|
+
// Example: itemAdded: z.tuple([z.string().describe('Item key')]).describe('Emitted when an item is added'),
|
|
38
|
+
})` },
|
|
39
|
+
{ heading: "Class", code: `/**
|
|
40
|
+
* {{description}}
|
|
41
|
+
* \`\`\`typescript
|
|
42
|
+
* const {{camelName}} = container.feature('{{camelName}}')
|
|
43
|
+
* \`\`\`
|
|
44
|
+
*
|
|
45
|
+
* @extends Feature
|
|
46
|
+
*/
|
|
47
|
+
export class {{PascalName}} extends Feature<{{PascalName}}State, {{PascalName}}Options> {
|
|
48
|
+
static override shortcut = 'features.{{camelName}}' as const
|
|
49
|
+
static override stateSchema = {{PascalName}}StateSchema
|
|
50
|
+
static override optionsSchema = {{PascalName}}OptionsSchema
|
|
51
|
+
static override eventsSchema = {{PascalName}}EventsSchema
|
|
52
|
+
|
|
53
|
+
static { Feature.register(this, '{{camelName}}') }
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Called after the feature is initialized. Use this for any setup logic
|
|
57
|
+
* instead of overriding the constructor.
|
|
58
|
+
*/
|
|
59
|
+
async afterInitialize() {
|
|
60
|
+
// Set up initial state, start background tasks, etc.
|
|
61
|
+
}
|
|
62
|
+
}` },
|
|
63
|
+
{ heading: "Module Augmentation", code: `declare module 'luca' {
|
|
64
|
+
interface AvailableFeatures {
|
|
65
|
+
{{camelName}}: typeof {{PascalName}}
|
|
66
|
+
}
|
|
67
|
+
}` },
|
|
68
|
+
{ heading: "Registration", code: `// Inside the class:
|
|
69
|
+
static { Feature.register(this, '{{camelName}}') }
|
|
70
|
+
|
|
71
|
+
// At module level:
|
|
72
|
+
export default {{PascalName}}` },
|
|
73
|
+
{ heading: "Complete Example", code: `import { z } from 'zod'
|
|
74
|
+
import { FeatureStateSchema, FeatureOptionsSchema } from 'luca'
|
|
75
|
+
import { Feature } from 'luca'
|
|
76
|
+
|
|
77
|
+
declare module 'luca' {
|
|
78
|
+
interface AvailableFeatures {
|
|
79
|
+
{{camelName}}: typeof {{PascalName}}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export const {{PascalName}}StateSchema = FeatureStateSchema.extend({})
|
|
84
|
+
export type {{PascalName}}State = z.infer<typeof {{PascalName}}StateSchema>
|
|
85
|
+
|
|
86
|
+
export const {{PascalName}}OptionsSchema = FeatureOptionsSchema.extend({})
|
|
87
|
+
export type {{PascalName}}Options = z.infer<typeof {{PascalName}}OptionsSchema>
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* {{description}}
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* \`\`\`typescript
|
|
94
|
+
* const {{camelName}} = container.feature('{{camelName}}')
|
|
95
|
+
* \`\`\`
|
|
96
|
+
*
|
|
97
|
+
* @extends Feature
|
|
98
|
+
*/
|
|
99
|
+
export class {{PascalName}} extends Feature<{{PascalName}}State, {{PascalName}}Options> {
|
|
100
|
+
static override shortcut = 'features.{{camelName}}' as const
|
|
101
|
+
static override stateSchema = {{PascalName}}StateSchema
|
|
102
|
+
static override optionsSchema = {{PascalName}}OptionsSchema
|
|
103
|
+
static { Feature.register(this, '{{camelName}}') }
|
|
104
|
+
|
|
105
|
+
async afterInitialize() {
|
|
106
|
+
// Setup logic goes here — not in the constructor
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export default {{PascalName}}` }
|
|
111
|
+
],
|
|
112
|
+
full: `import { z } from 'zod'
|
|
113
|
+
import { FeatureStateSchema, FeatureOptionsSchema } from 'luca'
|
|
114
|
+
import { Feature } from 'luca'
|
|
115
|
+
|
|
116
|
+
declare module 'luca' {
|
|
117
|
+
interface AvailableFeatures {
|
|
118
|
+
{{camelName}}: typeof {{PascalName}}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export const {{PascalName}}StateSchema = FeatureStateSchema.extend({})
|
|
123
|
+
export type {{PascalName}}State = z.infer<typeof {{PascalName}}StateSchema>
|
|
124
|
+
|
|
125
|
+
export const {{PascalName}}OptionsSchema = FeatureOptionsSchema.extend({})
|
|
126
|
+
export type {{PascalName}}Options = z.infer<typeof {{PascalName}}OptionsSchema>
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* {{description}}
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* \`\`\`typescript
|
|
133
|
+
* const {{camelName}} = container.feature('{{camelName}}')
|
|
134
|
+
* \`\`\`
|
|
135
|
+
*
|
|
136
|
+
* @extends Feature
|
|
137
|
+
*/
|
|
138
|
+
export class {{PascalName}} extends Feature<{{PascalName}}State, {{PascalName}}Options> {
|
|
139
|
+
static override shortcut = 'features.{{camelName}}' as const
|
|
140
|
+
static override stateSchema = {{PascalName}}StateSchema
|
|
141
|
+
static override optionsSchema = {{PascalName}}OptionsSchema
|
|
142
|
+
static { Feature.register(this, '{{camelName}}') }
|
|
143
|
+
|
|
144
|
+
async afterInitialize() {
|
|
145
|
+
// Setup logic goes here — not in the constructor
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export default {{PascalName}}`,
|
|
150
|
+
tutorial: `# Building a Feature
|
|
151
|
+
|
|
152
|
+
A feature is a container-managed capability — something your application needs that lives on the machine (file I/O, caching, encryption, etc). Features are lazy-loaded, observable, and self-documenting.
|
|
153
|
+
|
|
154
|
+
When to build a feature:
|
|
155
|
+
- You need a reusable local capability (not a network call — that's a client)
|
|
156
|
+
- You want state management, events, and introspection for free
|
|
157
|
+
- You're wrapping a library so the rest of the codebase uses a uniform interface
|
|
158
|
+
|
|
159
|
+
## Imports
|
|
160
|
+
|
|
161
|
+
\`\`\`ts
|
|
162
|
+
import { z } from 'zod'
|
|
163
|
+
import { FeatureStateSchema, FeatureOptionsSchema, FeatureEventsSchema } from 'luca'
|
|
164
|
+
import { Feature } from 'luca'
|
|
165
|
+
\`\`\`
|
|
166
|
+
|
|
167
|
+
These are the only imports your feature file needs from luca. If your feature wraps a third-party library, import it here too — feature implementations are the ONE place where direct library imports are allowed.
|
|
168
|
+
|
|
169
|
+
The use of dynamic imports is encouraged here, only import libraries you need when the feature is used, and only when necessary in the lifecycle of the feature if it can be done.
|
|
170
|
+
|
|
171
|
+
feature's have built in ways to check if their requirements are supported and can be enabled cautiously.
|
|
172
|
+
|
|
173
|
+
## Schemas
|
|
174
|
+
|
|
175
|
+
Define the shape of your feature's state, options, and events using Zod. Every field must have a \`.describe()\` — this becomes the documentation.
|
|
176
|
+
|
|
177
|
+
\`\`\`ts
|
|
178
|
+
export const {{PascalName}}StateSchema = FeatureStateSchema.extend({
|
|
179
|
+
// Add your state fields here. These are observable — changes emit events.
|
|
180
|
+
// Example: itemCount: z.number().default(0).describe('Number of items stored'),
|
|
181
|
+
})
|
|
182
|
+
export type {{PascalName}}State = z.infer<typeof {{PascalName}}StateSchema>
|
|
183
|
+
|
|
184
|
+
export const {{PascalName}}OptionsSchema = FeatureOptionsSchema.extend({
|
|
185
|
+
// Add constructor options here. Validated when the feature is created.
|
|
186
|
+
// Example: directory: z.string().optional().describe('Storage directory path'),
|
|
187
|
+
})
|
|
188
|
+
export type {{PascalName}}Options = z.infer<typeof {{PascalName}}OptionsSchema>
|
|
189
|
+
|
|
190
|
+
export const {{PascalName}}EventsSchema = FeatureEventsSchema.extend({
|
|
191
|
+
// Each key is an event name. Value is z.tuple() of listener arguments.
|
|
192
|
+
// Example: itemAdded: z.tuple([z.string().describe('Item key')]).describe('Emitted when an item is added'),
|
|
193
|
+
})
|
|
194
|
+
\`\`\`
|
|
195
|
+
|
|
196
|
+
## Class
|
|
197
|
+
|
|
198
|
+
The class extends \`Feature\` with your state and options types. Static properties drive registration and introspection. Every public method needs a JSDoc block with \`@param\`, \`@returns\`, and \`@example\`.
|
|
199
|
+
|
|
200
|
+
Running \`luca introspect\` captures JSDoc blocks and Zod schemas and includes them in the description whenever somebody calls \`container.features.describe('{{camelName}}')\` or \`luca describe {{camelName}}\`.
|
|
201
|
+
|
|
202
|
+
\`\`\`ts
|
|
203
|
+
/**
|
|
204
|
+
* {{description}}
|
|
205
|
+
* \`\`\`typescript
|
|
206
|
+
* const {{camelName}} = container.feature('{{camelName}}')
|
|
207
|
+
* \`\`\`
|
|
208
|
+
*
|
|
209
|
+
* @extends Feature
|
|
210
|
+
*/
|
|
211
|
+
export class {{PascalName}} extends Feature<{{PascalName}}State, {{PascalName}}Options> {
|
|
212
|
+
static override shortcut = 'features.{{camelName}}' as const
|
|
213
|
+
static override stateSchema = {{PascalName}}StateSchema
|
|
214
|
+
static override optionsSchema = {{PascalName}}OptionsSchema
|
|
215
|
+
static override eventsSchema = {{PascalName}}EventsSchema
|
|
216
|
+
|
|
217
|
+
static { Feature.register(this, '{{camelName}}') }
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Called after the feature is initialized. Use this for any setup logic
|
|
221
|
+
* instead of overriding the constructor.
|
|
222
|
+
*/
|
|
223
|
+
async afterInitialize() {
|
|
224
|
+
// Set up initial state, start background tasks, etc.
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
\`\`\`
|
|
228
|
+
|
|
229
|
+
**Important**: You almost never need to override the constructor. Use \`afterInitialize()\` for any setup logic — it runs after the feature is fully wired into the container and has access to \`this.container\`, \`this.options\`, \`this.state\`, etc.
|
|
230
|
+
|
|
231
|
+
## Module Augmentation
|
|
232
|
+
|
|
233
|
+
This is what gives \`container.feature('yourName')\` TypeScript autocomplete. Without it, the feature works but TypeScript won't know about it.
|
|
234
|
+
|
|
235
|
+
\`\`\`ts
|
|
236
|
+
declare module 'luca' {
|
|
237
|
+
interface AvailableFeatures {
|
|
238
|
+
{{camelName}}: typeof {{PascalName}}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
\`\`\`
|
|
242
|
+
|
|
243
|
+
## Registration
|
|
244
|
+
|
|
245
|
+
Registration happens inside the class body using a static block. The default export is just the class itself.
|
|
246
|
+
|
|
247
|
+
\`\`\`ts
|
|
248
|
+
// Inside the class:
|
|
249
|
+
static { Feature.register(this, '{{camelName}}') }
|
|
250
|
+
|
|
251
|
+
// At module level:
|
|
252
|
+
export default {{PascalName}}
|
|
253
|
+
\`\`\`
|
|
254
|
+
|
|
255
|
+
## Complete Example
|
|
256
|
+
|
|
257
|
+
Here's a minimal but complete feature. This is what a real feature file looks like:
|
|
258
|
+
|
|
259
|
+
\`\`\`ts
|
|
260
|
+
import { z } from 'zod'
|
|
261
|
+
import { FeatureStateSchema, FeatureOptionsSchema } from 'luca'
|
|
262
|
+
import { Feature } from 'luca'
|
|
263
|
+
|
|
264
|
+
declare module 'luca' {
|
|
265
|
+
interface AvailableFeatures {
|
|
266
|
+
{{camelName}}: typeof {{PascalName}}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export const {{PascalName}}StateSchema = FeatureStateSchema.extend({})
|
|
271
|
+
export type {{PascalName}}State = z.infer<typeof {{PascalName}}StateSchema>
|
|
272
|
+
|
|
273
|
+
export const {{PascalName}}OptionsSchema = FeatureOptionsSchema.extend({})
|
|
274
|
+
export type {{PascalName}}Options = z.infer<typeof {{PascalName}}OptionsSchema>
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* {{description}}
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* \`\`\`typescript
|
|
281
|
+
* const {{camelName}} = container.feature('{{camelName}}')
|
|
282
|
+
* \`\`\`
|
|
283
|
+
*
|
|
284
|
+
* @extends Feature
|
|
285
|
+
*/
|
|
286
|
+
export class {{PascalName}} extends Feature<{{PascalName}}State, {{PascalName}}Options> {
|
|
287
|
+
static override shortcut = 'features.{{camelName}}' as const
|
|
288
|
+
static override stateSchema = {{PascalName}}StateSchema
|
|
289
|
+
static override optionsSchema = {{PascalName}}OptionsSchema
|
|
290
|
+
static { Feature.register(this, '{{camelName}}') }
|
|
291
|
+
|
|
292
|
+
async afterInitialize() {
|
|
293
|
+
// Setup logic goes here — not in the constructor
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export default {{PascalName}}
|
|
298
|
+
\`\`\`
|
|
299
|
+
|
|
300
|
+
## Conventions
|
|
301
|
+
|
|
302
|
+
- **Naming**: PascalCase for class, camelCase for registration ID. The file name should be kebab-case (e.g. \`disk-cache.ts\`).
|
|
303
|
+
- **JSDoc**: Every public method, getter, and the class itself needs a JSDoc block. Include \`@example\` with working code.
|
|
304
|
+
- **Describe everything**: Every Zod field needs \`.describe()\`. Every event tuple argument needs \`.describe()\`. This IS the documentation.
|
|
305
|
+
- **No Node builtins in consumer code**: If your feature wraps \`fs\` or \`crypto\`, that's fine inside the feature. But code that USES your feature should never import those directly.
|
|
306
|
+
- **State is observable**: Use \`this.state.set()\` and \`this.state.get()\`. Don't use plain instance properties for data that should be reactive.
|
|
307
|
+
- **Events for lifecycle**: Emit events for significant state changes so consumers can react.
|
|
308
|
+
`,
|
|
309
|
+
},
|
|
310
|
+
client: {
|
|
311
|
+
sections: [
|
|
312
|
+
{ heading: "Imports", code: `import { z } from 'zod'
|
|
313
|
+
import { Client, RestClient } from 'luca/client'
|
|
314
|
+
import { ClientStateSchema, ClientOptionsSchema, ClientEventsSchema } from 'luca'` },
|
|
315
|
+
{ heading: "Schemas", code: `export const {{PascalName}}StateSchema = ClientStateSchema.extend({
|
|
316
|
+
// Add your state fields here.
|
|
317
|
+
// Example: authenticated: z.boolean().default(false).describe('Whether API auth is configured'),
|
|
318
|
+
})
|
|
319
|
+
export type {{PascalName}}State = z.infer<typeof {{PascalName}}StateSchema>
|
|
320
|
+
|
|
321
|
+
export const {{PascalName}}OptionsSchema = ClientOptionsSchema.extend({
|
|
322
|
+
// Add constructor options here.
|
|
323
|
+
// Example: apiKey: z.string().optional().describe('API key for authentication'),
|
|
324
|
+
})
|
|
325
|
+
export type {{PascalName}}Options = z.infer<typeof {{PascalName}}OptionsSchema>` },
|
|
326
|
+
{ heading: "Class", code: `/**
|
|
327
|
+
* {{description}}
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* \`\`\`typescript
|
|
331
|
+
* const {{camelName}} = container.client('{{camelName}}')
|
|
332
|
+
* \`\`\`
|
|
333
|
+
*
|
|
334
|
+
* @extends RestClient
|
|
335
|
+
*/
|
|
336
|
+
export class {{PascalName}} extends RestClient<{{PascalName}}State, {{PascalName}}Options> {
|
|
337
|
+
static override shortcut = 'clients.{{camelName}}' as const
|
|
338
|
+
static override stateSchema = {{PascalName}}StateSchema
|
|
339
|
+
static override optionsSchema = {{PascalName}}OptionsSchema
|
|
340
|
+
static { Client.register(this, '{{camelName}}') }
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Called after the client is initialized. Use this for any setup logic
|
|
344
|
+
* instead of overriding the constructor.
|
|
345
|
+
*/
|
|
346
|
+
async afterInitialize() {
|
|
347
|
+
// Set up default headers, configure auth, etc.
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// Add API methods here. Each wraps an endpoint.
|
|
351
|
+
// Example:
|
|
352
|
+
// async listItems(): Promise<Item[]> {
|
|
353
|
+
// return this.get('/items')
|
|
354
|
+
// }
|
|
355
|
+
}` },
|
|
356
|
+
{ heading: "Module Augmentation", code: `declare module 'luca/client' {
|
|
357
|
+
interface AvailableClients {
|
|
358
|
+
{{camelName}}: typeof {{PascalName}}
|
|
359
|
+
}
|
|
360
|
+
}` },
|
|
361
|
+
{ heading: "Registration", code: `// Inside the class:
|
|
362
|
+
static { Client.register(this, '{{camelName}}') }
|
|
363
|
+
|
|
364
|
+
// At module level:
|
|
365
|
+
export default {{PascalName}}` },
|
|
366
|
+
{ heading: "Complete Example", code: `import { z } from 'zod'
|
|
367
|
+
import { Client, RestClient } from 'luca/client'
|
|
368
|
+
import { ClientStateSchema, ClientOptionsSchema } from 'luca'
|
|
369
|
+
|
|
370
|
+
declare module 'luca/client' {
|
|
371
|
+
interface AvailableClients {
|
|
372
|
+
{{camelName}}: typeof {{PascalName}}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
export const {{PascalName}}StateSchema = ClientStateSchema.extend({})
|
|
377
|
+
export type {{PascalName}}State = z.infer<typeof {{PascalName}}StateSchema>
|
|
378
|
+
|
|
379
|
+
export const {{PascalName}}OptionsSchema = ClientOptionsSchema.extend({
|
|
380
|
+
baseURL: z.string().default('https://api.example.com').describe('API base URL'),
|
|
381
|
+
})
|
|
382
|
+
export type {{PascalName}}Options = z.infer<typeof {{PascalName}}OptionsSchema>
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* {{description}}
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* \`\`\`typescript
|
|
389
|
+
* const {{camelName}} = container.client('{{camelName}}')
|
|
390
|
+
* \`\`\`
|
|
391
|
+
*
|
|
392
|
+
* @extends RestClient
|
|
393
|
+
*/
|
|
394
|
+
export class {{PascalName}} extends RestClient<{{PascalName}}State, {{PascalName}}Options> {
|
|
395
|
+
static override shortcut = 'clients.{{camelName}}' as const
|
|
396
|
+
static override stateSchema = {{PascalName}}StateSchema
|
|
397
|
+
static override optionsSchema = {{PascalName}}OptionsSchema
|
|
398
|
+
static { Client.register(this, '{{camelName}}') }
|
|
399
|
+
|
|
400
|
+
async afterInitialize() {
|
|
401
|
+
// Setup logic goes here — not in the constructor
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
export default {{PascalName}}` }
|
|
406
|
+
],
|
|
407
|
+
full: `import { z } from 'zod'
|
|
408
|
+
import { Client, RestClient } from 'luca/client'
|
|
409
|
+
import { ClientStateSchema, ClientOptionsSchema } from 'luca'
|
|
410
|
+
|
|
411
|
+
declare module 'luca/client' {
|
|
412
|
+
interface AvailableClients {
|
|
413
|
+
{{camelName}}: typeof {{PascalName}}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
export const {{PascalName}}StateSchema = ClientStateSchema.extend({})
|
|
418
|
+
export type {{PascalName}}State = z.infer<typeof {{PascalName}}StateSchema>
|
|
419
|
+
|
|
420
|
+
export const {{PascalName}}OptionsSchema = ClientOptionsSchema.extend({
|
|
421
|
+
baseURL: z.string().default('https://api.example.com').describe('API base URL'),
|
|
422
|
+
})
|
|
423
|
+
export type {{PascalName}}Options = z.infer<typeof {{PascalName}}OptionsSchema>
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* {{description}}
|
|
427
|
+
*
|
|
428
|
+
* @example
|
|
429
|
+
* \`\`\`typescript
|
|
430
|
+
* const {{camelName}} = container.client('{{camelName}}')
|
|
431
|
+
* \`\`\`
|
|
432
|
+
*
|
|
433
|
+
* @extends RestClient
|
|
434
|
+
*/
|
|
435
|
+
export class {{PascalName}} extends RestClient<{{PascalName}}State, {{PascalName}}Options> {
|
|
436
|
+
static override shortcut = 'clients.{{camelName}}' as const
|
|
437
|
+
static override stateSchema = {{PascalName}}StateSchema
|
|
438
|
+
static override optionsSchema = {{PascalName}}OptionsSchema
|
|
439
|
+
static { Client.register(this, '{{camelName}}') }
|
|
440
|
+
|
|
441
|
+
async afterInitialize() {
|
|
442
|
+
// Setup logic goes here — not in the constructor
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
export default {{PascalName}}`,
|
|
447
|
+
tutorial: `# Building a Client
|
|
448
|
+
|
|
449
|
+
A client is a container-managed connection to an external service. Clients handle network communication — HTTP APIs, WebSocket connections, GraphQL endpoints. They extend \`RestClient\` (for HTTP), \`WebSocketClient\` (for WS), or the base \`Client\` class.
|
|
450
|
+
|
|
451
|
+
When to build a client:
|
|
452
|
+
- You need to talk to an external API or service
|
|
453
|
+
- You want connection management, error handling, and observability for free
|
|
454
|
+
- You're wrapping an API so the rest of the codebase uses \`container.client('name')\`
|
|
455
|
+
|
|
456
|
+
## Imports
|
|
457
|
+
|
|
458
|
+
\`\`\`ts
|
|
459
|
+
import { z } from 'zod'
|
|
460
|
+
import { Client, RestClient } from 'luca/client'
|
|
461
|
+
import { ClientStateSchema, ClientOptionsSchema, ClientEventsSchema } from 'luca'
|
|
462
|
+
\`\`\`
|
|
463
|
+
|
|
464
|
+
Use \`RestClient\` for HTTP APIs (most common). It gives you \`get\`, \`post\`, \`put\`, \`patch\`, \`delete\` methods that handle JSON, headers, and error wrapping.
|
|
465
|
+
|
|
466
|
+
## Schemas
|
|
467
|
+
|
|
468
|
+
\`\`\`ts
|
|
469
|
+
export const {{PascalName}}StateSchema = ClientStateSchema.extend({
|
|
470
|
+
// Add your state fields here.
|
|
471
|
+
// Example: authenticated: z.boolean().default(false).describe('Whether API auth is configured'),
|
|
472
|
+
})
|
|
473
|
+
export type {{PascalName}}State = z.infer<typeof {{PascalName}}StateSchema>
|
|
474
|
+
|
|
475
|
+
export const {{PascalName}}OptionsSchema = ClientOptionsSchema.extend({
|
|
476
|
+
// Add constructor options here.
|
|
477
|
+
// Example: apiKey: z.string().optional().describe('API key for authentication'),
|
|
478
|
+
})
|
|
479
|
+
export type {{PascalName}}Options = z.infer<typeof {{PascalName}}OptionsSchema>
|
|
480
|
+
\`\`\`
|
|
481
|
+
|
|
482
|
+
## Class
|
|
483
|
+
|
|
484
|
+
Running \`luca introspect\` captures JSDoc blocks and Zod schemas and includes them in the description whenever somebody calls \`container.clients.describe('{{camelName}}')\` or \`luca describe {{camelName}}\`.
|
|
485
|
+
|
|
486
|
+
\`\`\`ts
|
|
487
|
+
/**
|
|
488
|
+
* {{description}}
|
|
489
|
+
*
|
|
490
|
+
* @example
|
|
491
|
+
* \`\`\`typescript
|
|
492
|
+
* const {{camelName}} = container.client('{{camelName}}')
|
|
493
|
+
* \`\`\`
|
|
494
|
+
*
|
|
495
|
+
* @extends RestClient
|
|
496
|
+
*/
|
|
497
|
+
export class {{PascalName}} extends RestClient<{{PascalName}}State, {{PascalName}}Options> {
|
|
498
|
+
static override shortcut = 'clients.{{camelName}}' as const
|
|
499
|
+
static override stateSchema = {{PascalName}}StateSchema
|
|
500
|
+
static override optionsSchema = {{PascalName}}OptionsSchema
|
|
501
|
+
static { Client.register(this, '{{camelName}}') }
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Called after the client is initialized. Use this for any setup logic
|
|
505
|
+
* instead of overriding the constructor.
|
|
506
|
+
*/
|
|
507
|
+
async afterInitialize() {
|
|
508
|
+
// Set up default headers, configure auth, etc.
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// Add API methods here. Each wraps an endpoint.
|
|
512
|
+
// Example:
|
|
513
|
+
// async listItems(): Promise<Item[]> {
|
|
514
|
+
// return this.get('/items')
|
|
515
|
+
// }
|
|
516
|
+
}
|
|
517
|
+
\`\`\`
|
|
518
|
+
|
|
519
|
+
**Important**: You almost never need to override the constructor. Use \`afterInitialize()\` for setup logic — it runs after the client is fully wired into the container. Set \`baseURL\` via the options schema default instead of constructor manipulation.
|
|
520
|
+
|
|
521
|
+
## Module Augmentation
|
|
522
|
+
|
|
523
|
+
\`\`\`ts
|
|
524
|
+
declare module 'luca/client' {
|
|
525
|
+
interface AvailableClients {
|
|
526
|
+
{{camelName}}: typeof {{PascalName}}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
\`\`\`
|
|
530
|
+
|
|
531
|
+
## Registration
|
|
532
|
+
|
|
533
|
+
Registration happens inside the class body using a static block. The default export is just the class itself.
|
|
534
|
+
|
|
535
|
+
\`\`\`ts
|
|
536
|
+
// Inside the class:
|
|
537
|
+
static { Client.register(this, '{{camelName}}') }
|
|
538
|
+
|
|
539
|
+
// At module level:
|
|
540
|
+
export default {{PascalName}}
|
|
541
|
+
\`\`\`
|
|
542
|
+
|
|
543
|
+
## Complete Example
|
|
544
|
+
|
|
545
|
+
\`\`\`ts
|
|
546
|
+
import { z } from 'zod'
|
|
547
|
+
import { Client, RestClient } from 'luca/client'
|
|
548
|
+
import { ClientStateSchema, ClientOptionsSchema } from 'luca'
|
|
549
|
+
|
|
550
|
+
declare module 'luca/client' {
|
|
551
|
+
interface AvailableClients {
|
|
552
|
+
{{camelName}}: typeof {{PascalName}}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
export const {{PascalName}}StateSchema = ClientStateSchema.extend({})
|
|
557
|
+
export type {{PascalName}}State = z.infer<typeof {{PascalName}}StateSchema>
|
|
558
|
+
|
|
559
|
+
export const {{PascalName}}OptionsSchema = ClientOptionsSchema.extend({
|
|
560
|
+
baseURL: z.string().default('https://api.example.com').describe('API base URL'),
|
|
561
|
+
})
|
|
562
|
+
export type {{PascalName}}Options = z.infer<typeof {{PascalName}}OptionsSchema>
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* {{description}}
|
|
566
|
+
*
|
|
567
|
+
* @example
|
|
568
|
+
* \`\`\`typescript
|
|
569
|
+
* const {{camelName}} = container.client('{{camelName}}')
|
|
570
|
+
* \`\`\`
|
|
571
|
+
*
|
|
572
|
+
* @extends RestClient
|
|
573
|
+
*/
|
|
574
|
+
export class {{PascalName}} extends RestClient<{{PascalName}}State, {{PascalName}}Options> {
|
|
575
|
+
static override shortcut = 'clients.{{camelName}}' as const
|
|
576
|
+
static override stateSchema = {{PascalName}}StateSchema
|
|
577
|
+
static override optionsSchema = {{PascalName}}OptionsSchema
|
|
578
|
+
static { Client.register(this, '{{camelName}}') }
|
|
579
|
+
|
|
580
|
+
async afterInitialize() {
|
|
581
|
+
// Setup logic goes here — not in the constructor
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
export default {{PascalName}}
|
|
586
|
+
\`\`\`
|
|
587
|
+
|
|
588
|
+
## Conventions
|
|
589
|
+
|
|
590
|
+
- **Extend RestClient for HTTP**: It gives you typed HTTP methods. Only use base \`Client\` if you need a non-HTTP protocol.
|
|
591
|
+
- **Set baseURL via options schema**: Use a Zod \`.default()\` on the \`baseURL\` field rather than overriding the constructor.
|
|
592
|
+
- **Use \`afterInitialize()\`**: For any setup logic (auth, default headers, etc.) instead of overriding the constructor.
|
|
593
|
+
- **Wrap endpoints as methods**: Each API endpoint gets a method. Keep them thin — just map to HTTP calls.
|
|
594
|
+
- **JSDoc everything**: Every public method needs \`@param\`, \`@returns\`, \`@example\`. Run \`luca introspect\` after changes to update generated docs.
|
|
595
|
+
- **Auth in options**: Pass API keys, tokens via options schema. Check them in \`afterInitialize()\` or a setup method.
|
|
596
|
+
`,
|
|
597
|
+
},
|
|
598
|
+
server: {
|
|
599
|
+
sections: [
|
|
600
|
+
{ heading: "Imports", code: `import { z } from 'zod'
|
|
601
|
+
import { Server } from 'luca'
|
|
602
|
+
import { ServerStateSchema, ServerOptionsSchema, ServerEventsSchema } from 'luca'
|
|
603
|
+
import type { NodeContainer } from 'luca'
|
|
604
|
+
import type { ServersInterface } from 'luca'` },
|
|
605
|
+
{ heading: "Schemas", code: `export const {{PascalName}}StateSchema = ServerStateSchema.extend({
|
|
606
|
+
// Add your state fields here.
|
|
607
|
+
// Example: connectionCount: z.number().default(0).describe('Active connections'),
|
|
608
|
+
})
|
|
609
|
+
export type {{PascalName}}State = z.infer<typeof {{PascalName}}StateSchema>
|
|
610
|
+
|
|
611
|
+
export const {{PascalName}}OptionsSchema = ServerOptionsSchema.extend({
|
|
612
|
+
// Add constructor options here. port and host come from ServerOptionsSchema.
|
|
613
|
+
// Example: cors: z.boolean().default(true).describe('Enable CORS'),
|
|
614
|
+
})
|
|
615
|
+
export type {{PascalName}}Options = z.infer<typeof {{PascalName}}OptionsSchema>
|
|
616
|
+
|
|
617
|
+
export const {{PascalName}}EventsSchema = ServerEventsSchema.extend({
|
|
618
|
+
// Add your events here.
|
|
619
|
+
// Example: connection: z.tuple([z.string().describe('Client ID')]).describe('New client connected'),
|
|
620
|
+
})` },
|
|
621
|
+
{ heading: "Class", code: `/**
|
|
622
|
+
* {{description}}
|
|
623
|
+
*
|
|
624
|
+
* @example
|
|
625
|
+
* \`\`\`typescript
|
|
626
|
+
* const {{camelName}} = container.server('{{camelName}}', { port: 3000 })
|
|
627
|
+
* await {{camelName}}.start()
|
|
628
|
+
* \`\`\`
|
|
629
|
+
*
|
|
630
|
+
* @extends Server
|
|
631
|
+
*/
|
|
632
|
+
export class {{PascalName}} extends Server<{{PascalName}}State, {{PascalName}}Options> {
|
|
633
|
+
static override shortcut = 'servers.{{camelName}}' as const
|
|
634
|
+
static override stateSchema = {{PascalName}}StateSchema
|
|
635
|
+
static override optionsSchema = {{PascalName}}OptionsSchema
|
|
636
|
+
static override eventsSchema = {{PascalName}}EventsSchema
|
|
637
|
+
static { Server.register(this, '{{camelName}}') }
|
|
638
|
+
|
|
639
|
+
static override attach(container: NodeContainer & ServersInterface) {
|
|
640
|
+
return container
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
override async configure() {
|
|
644
|
+
if (this.isConfigured) return this
|
|
645
|
+
// Set up the underlying server here
|
|
646
|
+
this.state.set('configured', true)
|
|
647
|
+
return this
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
override async start(options?: { port?: number }) {
|
|
651
|
+
if (this.isListening) return this
|
|
652
|
+
if (!this.isConfigured) await this.configure()
|
|
653
|
+
|
|
654
|
+
const port = options?.port || this.options.port || 3000
|
|
655
|
+
// Start listening here
|
|
656
|
+
this.state.set('port', port)
|
|
657
|
+
this.state.set('listening', true)
|
|
658
|
+
return this
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
override async stop() {
|
|
662
|
+
if (this.isStopped) return this
|
|
663
|
+
// Clean up connections here
|
|
664
|
+
this.state.set('listening', false)
|
|
665
|
+
this.state.set('stopped', true)
|
|
666
|
+
return this
|
|
667
|
+
}
|
|
668
|
+
}` },
|
|
669
|
+
{ heading: "Module Augmentation", code: `declare module 'luca' {
|
|
670
|
+
interface AvailableServers {
|
|
671
|
+
{{camelName}}: typeof {{PascalName}}
|
|
672
|
+
}
|
|
673
|
+
}` },
|
|
674
|
+
{ heading: "Registration", code: `// Inside the class:
|
|
675
|
+
static { Server.register(this, '{{camelName}}') }
|
|
676
|
+
|
|
677
|
+
// At module level:
|
|
678
|
+
export default {{PascalName}}` },
|
|
679
|
+
{ heading: "Complete Example", code: `import { z } from 'zod'
|
|
680
|
+
import { Server } from 'luca'
|
|
681
|
+
import { ServerStateSchema, ServerOptionsSchema, ServerEventsSchema } from 'luca'
|
|
682
|
+
import type { NodeContainer } from 'luca'
|
|
683
|
+
import type { ServersInterface } from 'luca'
|
|
684
|
+
|
|
685
|
+
declare module 'luca' {
|
|
686
|
+
interface AvailableServers {
|
|
687
|
+
{{camelName}}: typeof {{PascalName}}
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
export const {{PascalName}}StateSchema = ServerStateSchema.extend({})
|
|
692
|
+
export type {{PascalName}}State = z.infer<typeof {{PascalName}}StateSchema>
|
|
693
|
+
|
|
694
|
+
export const {{PascalName}}OptionsSchema = ServerOptionsSchema.extend({})
|
|
695
|
+
export type {{PascalName}}Options = z.infer<typeof {{PascalName}}OptionsSchema>
|
|
696
|
+
|
|
697
|
+
export const {{PascalName}}EventsSchema = ServerEventsSchema.extend({})
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* {{description}}
|
|
701
|
+
*
|
|
702
|
+
* @example
|
|
703
|
+
* \`\`\`typescript
|
|
704
|
+
* const {{camelName}} = container.server('{{camelName}}', { port: 3000 })
|
|
705
|
+
* await {{camelName}}.start()
|
|
706
|
+
* \`\`\`
|
|
707
|
+
*
|
|
708
|
+
* @extends Server
|
|
709
|
+
*/
|
|
710
|
+
export class {{PascalName}} extends Server<{{PascalName}}State, {{PascalName}}Options> {
|
|
711
|
+
static override shortcut = 'servers.{{camelName}}' as const
|
|
712
|
+
static override stateSchema = {{PascalName}}StateSchema
|
|
713
|
+
static override optionsSchema = {{PascalName}}OptionsSchema
|
|
714
|
+
static override eventsSchema = {{PascalName}}EventsSchema
|
|
715
|
+
static { Server.register(this, '{{camelName}}') }
|
|
716
|
+
|
|
717
|
+
static override attach(container: NodeContainer & ServersInterface) {
|
|
718
|
+
return container
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
override async configure() {
|
|
722
|
+
if (this.isConfigured) return this
|
|
723
|
+
this.state.set('configured', true)
|
|
724
|
+
return this
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
override async start(options?: { port?: number }) {
|
|
728
|
+
if (this.isListening) return this
|
|
729
|
+
if (!this.isConfigured) await this.configure()
|
|
730
|
+
const port = options?.port || this.options.port || 3000
|
|
731
|
+
this.state.set('port', port)
|
|
732
|
+
this.state.set('listening', true)
|
|
733
|
+
return this
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
override async stop() {
|
|
737
|
+
if (this.isStopped) return this
|
|
738
|
+
this.state.set('listening', false)
|
|
739
|
+
this.state.set('stopped', true)
|
|
740
|
+
return this
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
export default {{PascalName}}` }
|
|
745
|
+
],
|
|
746
|
+
full: `import { z } from 'zod'
|
|
747
|
+
import { Server } from 'luca'
|
|
748
|
+
import { ServerStateSchema, ServerOptionsSchema, ServerEventsSchema } from 'luca'
|
|
749
|
+
import type { NodeContainer } from 'luca'
|
|
750
|
+
import type { ServersInterface } from 'luca'
|
|
751
|
+
|
|
752
|
+
declare module 'luca' {
|
|
753
|
+
interface AvailableServers {
|
|
754
|
+
{{camelName}}: typeof {{PascalName}}
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
export const {{PascalName}}StateSchema = ServerStateSchema.extend({})
|
|
759
|
+
export type {{PascalName}}State = z.infer<typeof {{PascalName}}StateSchema>
|
|
760
|
+
|
|
761
|
+
export const {{PascalName}}OptionsSchema = ServerOptionsSchema.extend({})
|
|
762
|
+
export type {{PascalName}}Options = z.infer<typeof {{PascalName}}OptionsSchema>
|
|
763
|
+
|
|
764
|
+
export const {{PascalName}}EventsSchema = ServerEventsSchema.extend({})
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* {{description}}
|
|
768
|
+
*
|
|
769
|
+
* @example
|
|
770
|
+
* \`\`\`typescript
|
|
771
|
+
* const {{camelName}} = container.server('{{camelName}}', { port: 3000 })
|
|
772
|
+
* await {{camelName}}.start()
|
|
773
|
+
* \`\`\`
|
|
774
|
+
*
|
|
775
|
+
* @extends Server
|
|
776
|
+
*/
|
|
777
|
+
export class {{PascalName}} extends Server<{{PascalName}}State, {{PascalName}}Options> {
|
|
778
|
+
static override shortcut = 'servers.{{camelName}}' as const
|
|
779
|
+
static override stateSchema = {{PascalName}}StateSchema
|
|
780
|
+
static override optionsSchema = {{PascalName}}OptionsSchema
|
|
781
|
+
static override eventsSchema = {{PascalName}}EventsSchema
|
|
782
|
+
static { Server.register(this, '{{camelName}}') }
|
|
783
|
+
|
|
784
|
+
static override attach(container: NodeContainer & ServersInterface) {
|
|
785
|
+
return container
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
override async configure() {
|
|
789
|
+
if (this.isConfigured) return this
|
|
790
|
+
this.state.set('configured', true)
|
|
791
|
+
return this
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
override async start(options?: { port?: number }) {
|
|
795
|
+
if (this.isListening) return this
|
|
796
|
+
if (!this.isConfigured) await this.configure()
|
|
797
|
+
const port = options?.port || this.options.port || 3000
|
|
798
|
+
this.state.set('port', port)
|
|
799
|
+
this.state.set('listening', true)
|
|
800
|
+
return this
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
override async stop() {
|
|
804
|
+
if (this.isStopped) return this
|
|
805
|
+
this.state.set('listening', false)
|
|
806
|
+
this.state.set('stopped', true)
|
|
807
|
+
return this
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
export default {{PascalName}}`,
|
|
812
|
+
tutorial: `# Building a Server
|
|
813
|
+
|
|
814
|
+
A server is a container-managed listener — something that accepts connections and handles requests. Servers manage their own lifecycle (configure, start, stop) and expose observable state.
|
|
815
|
+
|
|
816
|
+
When to build a server:
|
|
817
|
+
- You need to accept incoming connections (HTTP, WebSocket, custom protocol)
|
|
818
|
+
- You want lifecycle management, port handling, and observability for free
|
|
819
|
+
- You're wrapping a server library so the codebase uses \`container.server('name')\`
|
|
820
|
+
|
|
821
|
+
## Imports
|
|
822
|
+
|
|
823
|
+
\`\`\`ts
|
|
824
|
+
import { z } from 'zod'
|
|
825
|
+
import { Server } from 'luca'
|
|
826
|
+
import { ServerStateSchema, ServerOptionsSchema, ServerEventsSchema } from 'luca'
|
|
827
|
+
import type { NodeContainer } from 'luca'
|
|
828
|
+
import type { ServersInterface } from 'luca'
|
|
829
|
+
\`\`\`
|
|
830
|
+
|
|
831
|
+
## Schemas
|
|
832
|
+
|
|
833
|
+
\`\`\`ts
|
|
834
|
+
export const {{PascalName}}StateSchema = ServerStateSchema.extend({
|
|
835
|
+
// Add your state fields here.
|
|
836
|
+
// Example: connectionCount: z.number().default(0).describe('Active connections'),
|
|
837
|
+
})
|
|
838
|
+
export type {{PascalName}}State = z.infer<typeof {{PascalName}}StateSchema>
|
|
839
|
+
|
|
840
|
+
export const {{PascalName}}OptionsSchema = ServerOptionsSchema.extend({
|
|
841
|
+
// Add constructor options here. port and host come from ServerOptionsSchema.
|
|
842
|
+
// Example: cors: z.boolean().default(true).describe('Enable CORS'),
|
|
843
|
+
})
|
|
844
|
+
export type {{PascalName}}Options = z.infer<typeof {{PascalName}}OptionsSchema>
|
|
845
|
+
|
|
846
|
+
export const {{PascalName}}EventsSchema = ServerEventsSchema.extend({
|
|
847
|
+
// Add your events here.
|
|
848
|
+
// Example: connection: z.tuple([z.string().describe('Client ID')]).describe('New client connected'),
|
|
849
|
+
})
|
|
850
|
+
\`\`\`
|
|
851
|
+
|
|
852
|
+
## Class
|
|
853
|
+
|
|
854
|
+
Running \`luca introspect\` captures JSDoc blocks and Zod schemas and includes them in the description whenever somebody calls \`container.servers.describe('{{camelName}}')\` or \`luca describe {{camelName}}\`.
|
|
855
|
+
|
|
856
|
+
\`\`\`ts
|
|
857
|
+
/**
|
|
858
|
+
* {{description}}
|
|
859
|
+
*
|
|
860
|
+
* @example
|
|
861
|
+
* \`\`\`typescript
|
|
862
|
+
* const {{camelName}} = container.server('{{camelName}}', { port: 3000 })
|
|
863
|
+
* await {{camelName}}.start()
|
|
864
|
+
* \`\`\`
|
|
865
|
+
*
|
|
866
|
+
* @extends Server
|
|
867
|
+
*/
|
|
868
|
+
export class {{PascalName}} extends Server<{{PascalName}}State, {{PascalName}}Options> {
|
|
869
|
+
static override shortcut = 'servers.{{camelName}}' as const
|
|
870
|
+
static override stateSchema = {{PascalName}}StateSchema
|
|
871
|
+
static override optionsSchema = {{PascalName}}OptionsSchema
|
|
872
|
+
static override eventsSchema = {{PascalName}}EventsSchema
|
|
873
|
+
static { Server.register(this, '{{camelName}}') }
|
|
874
|
+
|
|
875
|
+
static override attach(container: NodeContainer & ServersInterface) {
|
|
876
|
+
return container
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
override async configure() {
|
|
880
|
+
if (this.isConfigured) return this
|
|
881
|
+
// Set up the underlying server here
|
|
882
|
+
this.state.set('configured', true)
|
|
883
|
+
return this
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
override async start(options?: { port?: number }) {
|
|
887
|
+
if (this.isListening) return this
|
|
888
|
+
if (!this.isConfigured) await this.configure()
|
|
889
|
+
|
|
890
|
+
const port = options?.port || this.options.port || 3000
|
|
891
|
+
// Start listening here
|
|
892
|
+
this.state.set('port', port)
|
|
893
|
+
this.state.set('listening', true)
|
|
894
|
+
return this
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
override async stop() {
|
|
898
|
+
if (this.isStopped) return this
|
|
899
|
+
// Clean up connections here
|
|
900
|
+
this.state.set('listening', false)
|
|
901
|
+
this.state.set('stopped', true)
|
|
902
|
+
return this
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
\`\`\`
|
|
906
|
+
|
|
907
|
+
## Module Augmentation
|
|
908
|
+
|
|
909
|
+
\`\`\`ts
|
|
910
|
+
declare module 'luca' {
|
|
911
|
+
interface AvailableServers {
|
|
912
|
+
{{camelName}}: typeof {{PascalName}}
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
\`\`\`
|
|
916
|
+
|
|
917
|
+
## Registration
|
|
918
|
+
|
|
919
|
+
Registration happens inside the class body using a static block. The default export is just the class itself.
|
|
920
|
+
|
|
921
|
+
\`\`\`ts
|
|
922
|
+
// Inside the class:
|
|
923
|
+
static { Server.register(this, '{{camelName}}') }
|
|
924
|
+
|
|
925
|
+
// At module level:
|
|
926
|
+
export default {{PascalName}}
|
|
927
|
+
\`\`\`
|
|
928
|
+
|
|
929
|
+
## Complete Example
|
|
930
|
+
|
|
931
|
+
\`\`\`ts
|
|
932
|
+
import { z } from 'zod'
|
|
933
|
+
import { Server } from 'luca'
|
|
934
|
+
import { ServerStateSchema, ServerOptionsSchema, ServerEventsSchema } from 'luca'
|
|
935
|
+
import type { NodeContainer } from 'luca'
|
|
936
|
+
import type { ServersInterface } from 'luca'
|
|
937
|
+
|
|
938
|
+
declare module 'luca' {
|
|
939
|
+
interface AvailableServers {
|
|
940
|
+
{{camelName}}: typeof {{PascalName}}
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
export const {{PascalName}}StateSchema = ServerStateSchema.extend({})
|
|
945
|
+
export type {{PascalName}}State = z.infer<typeof {{PascalName}}StateSchema>
|
|
946
|
+
|
|
947
|
+
export const {{PascalName}}OptionsSchema = ServerOptionsSchema.extend({})
|
|
948
|
+
export type {{PascalName}}Options = z.infer<typeof {{PascalName}}OptionsSchema>
|
|
949
|
+
|
|
950
|
+
export const {{PascalName}}EventsSchema = ServerEventsSchema.extend({})
|
|
951
|
+
|
|
952
|
+
/**
|
|
953
|
+
* {{description}}
|
|
954
|
+
*
|
|
955
|
+
* @example
|
|
956
|
+
* \`\`\`typescript
|
|
957
|
+
* const {{camelName}} = container.server('{{camelName}}', { port: 3000 })
|
|
958
|
+
* await {{camelName}}.start()
|
|
959
|
+
* \`\`\`
|
|
960
|
+
*
|
|
961
|
+
* @extends Server
|
|
962
|
+
*/
|
|
963
|
+
export class {{PascalName}} extends Server<{{PascalName}}State, {{PascalName}}Options> {
|
|
964
|
+
static override shortcut = 'servers.{{camelName}}' as const
|
|
965
|
+
static override stateSchema = {{PascalName}}StateSchema
|
|
966
|
+
static override optionsSchema = {{PascalName}}OptionsSchema
|
|
967
|
+
static override eventsSchema = {{PascalName}}EventsSchema
|
|
968
|
+
static { Server.register(this, '{{camelName}}') }
|
|
969
|
+
|
|
970
|
+
static override attach(container: NodeContainer & ServersInterface) {
|
|
971
|
+
return container
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
override async configure() {
|
|
975
|
+
if (this.isConfigured) return this
|
|
976
|
+
this.state.set('configured', true)
|
|
977
|
+
return this
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
override async start(options?: { port?: number }) {
|
|
981
|
+
if (this.isListening) return this
|
|
982
|
+
if (!this.isConfigured) await this.configure()
|
|
983
|
+
const port = options?.port || this.options.port || 3000
|
|
984
|
+
this.state.set('port', port)
|
|
985
|
+
this.state.set('listening', true)
|
|
986
|
+
return this
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
override async stop() {
|
|
990
|
+
if (this.isStopped) return this
|
|
991
|
+
this.state.set('listening', false)
|
|
992
|
+
this.state.set('stopped', true)
|
|
993
|
+
return this
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
export default {{PascalName}}
|
|
998
|
+
\`\`\`
|
|
999
|
+
|
|
1000
|
+
## Conventions
|
|
1001
|
+
|
|
1002
|
+
- **Lifecycle**: Implement \`configure()\`, \`start()\`, and \`stop()\`. Check guards (\`isConfigured\`, \`isListening\`, \`isStopped\`) at the top of each.
|
|
1003
|
+
- **Use \`afterInitialize()\`**: For any setup logic instead of overriding the constructor. Lifecycle methods (\`configure\`, \`start\`, \`stop\`) handle the server's runtime phases.
|
|
1004
|
+
- **State tracking**: Set \`configured\`, \`listening\`, \`stopped\`, and \`port\` on the state. This powers the introspection system.
|
|
1005
|
+
- **attach() is static**: It runs when the container first loads the server class. Use it for container-level setup if needed.
|
|
1006
|
+
- **Port from options**: Accept port via options schema and respect it in \`start()\`. Allow override via start options.
|
|
1007
|
+
- **JSDoc everything**: Every public method needs \`@param\`, \`@returns\`, \`@example\`. Run \`luca introspect\` after changes to update generated docs.
|
|
1008
|
+
`,
|
|
1009
|
+
},
|
|
1010
|
+
command: {
|
|
1011
|
+
sections: [
|
|
1012
|
+
{ heading: "Imports", code: `import { z } from 'zod'
|
|
1013
|
+
import type { ContainerContext } from 'luca'` },
|
|
1014
|
+
{ heading: "Positional Arguments", code: `// luca {{kebabName}} ./src => options.target === './src'
|
|
1015
|
+
export const positionals = ['target']` },
|
|
1016
|
+
{ heading: "Args Schema", code: `export const argsSchema = z.object({
|
|
1017
|
+
// Positional: first arg after command name (via positionals array above)
|
|
1018
|
+
// target: z.string().optional().describe('The target to operate on'),
|
|
1019
|
+
|
|
1020
|
+
// Flags: passed as --flag on the CLI
|
|
1021
|
+
// verbose: z.boolean().default(false).describe('Enable verbose output'),
|
|
1022
|
+
// output: z.string().optional().describe('Output file path'),
|
|
1023
|
+
})` },
|
|
1024
|
+
{ heading: "Description", code: `export const description = '{{description}}'` },
|
|
1025
|
+
{ heading: "Handler", code: `export default async function {{camelName}}(options: z.infer<typeof argsSchema>, context: ContainerContext) {
|
|
1026
|
+
const { container } = context
|
|
1027
|
+
const fs = container.feature('fs')
|
|
1028
|
+
|
|
1029
|
+
// options.target is set from the first positional arg (via positionals export)
|
|
1030
|
+
// options.verbose, options.output, etc. come from --flags
|
|
1031
|
+
|
|
1032
|
+
// Your implementation here
|
|
1033
|
+
}` },
|
|
1034
|
+
{ heading: "Complete Example", code: `import { z } from 'zod'
|
|
1035
|
+
import type { ContainerContext } from 'luca'
|
|
1036
|
+
|
|
1037
|
+
export const description = '{{description}}'
|
|
1038
|
+
|
|
1039
|
+
// Map positional args to named options: luca {{kebabName}} myTarget => options.target === 'myTarget'
|
|
1040
|
+
export const positionals = ['target']
|
|
1041
|
+
|
|
1042
|
+
export const argsSchema = z.object({
|
|
1043
|
+
target: z.string().optional().describe('The target to operate on'),
|
|
1044
|
+
})
|
|
1045
|
+
|
|
1046
|
+
export default async function {{camelName}}(options: z.infer<typeof argsSchema>, context: ContainerContext) {
|
|
1047
|
+
const { container } = context
|
|
1048
|
+
const fs = container.feature('fs')
|
|
1049
|
+
|
|
1050
|
+
console.log('{{kebabName}} running...', options.target)
|
|
1051
|
+
}` },
|
|
1052
|
+
{ heading: "Container Properties", code: `export default async function {{camelName}}(options: z.infer<typeof argsSchema>, context: ContainerContext) {
|
|
1053
|
+
const { container } = context
|
|
1054
|
+
|
|
1055
|
+
// Current working directory
|
|
1056
|
+
container.cwd // '/path/to/project'
|
|
1057
|
+
|
|
1058
|
+
// Path utilities (scoped to cwd)
|
|
1059
|
+
container.paths.resolve('src') // '/path/to/project/src'
|
|
1060
|
+
container.paths.join('a', 'b') // '/path/to/project/a/b'
|
|
1061
|
+
container.paths.relative('src') // 'src'
|
|
1062
|
+
|
|
1063
|
+
// Package manifest (parsed package.json)
|
|
1064
|
+
container.manifest.name // 'my-project'
|
|
1065
|
+
container.manifest.version // '1.0.0'
|
|
1066
|
+
|
|
1067
|
+
// Raw CLI arguments (from minimist) — prefer positionals export for positional args
|
|
1068
|
+
container.argv // { _: ['{{kebabName}}', ...], verbose: true, ... }
|
|
1069
|
+
}` }
|
|
1070
|
+
],
|
|
1071
|
+
full: `import { z } from 'zod'
|
|
1072
|
+
import type { ContainerContext } from 'luca'
|
|
1073
|
+
|
|
1074
|
+
export const description = '{{description}}'
|
|
1075
|
+
|
|
1076
|
+
// Map positional args to named options: luca {{kebabName}} myTarget => options.target === 'myTarget'
|
|
1077
|
+
export const positionals = ['target']
|
|
1078
|
+
|
|
1079
|
+
export const argsSchema = z.object({
|
|
1080
|
+
target: z.string().optional().describe('The target to operate on'),
|
|
1081
|
+
})
|
|
1082
|
+
|
|
1083
|
+
export default async function {{camelName}}(options: z.infer<typeof argsSchema>, context: ContainerContext) {
|
|
1084
|
+
const { container } = context
|
|
1085
|
+
const fs = container.feature('fs')
|
|
1086
|
+
|
|
1087
|
+
console.log('{{kebabName}} running...', options.target)
|
|
1088
|
+
}`,
|
|
1089
|
+
tutorial: `# Building a Command
|
|
1090
|
+
|
|
1091
|
+
A command extends the \`luca\` CLI. Commands live in a project's \`commands/\` folder and are automatically discovered. They are Helper subclasses under the hood — the framework grafts your module exports into a Command class at runtime.
|
|
1092
|
+
|
|
1093
|
+
When to build a command:
|
|
1094
|
+
- You need a CLI task for a project (build scripts, generators, automation)
|
|
1095
|
+
- You want argument parsing, help text, and container access for free
|
|
1096
|
+
- The task should be runnable via \`luca yourCommand\`
|
|
1097
|
+
|
|
1098
|
+
## Imports
|
|
1099
|
+
|
|
1100
|
+
\`\`\`ts
|
|
1101
|
+
import { z } from 'zod'
|
|
1102
|
+
import type { ContainerContext } from 'luca'
|
|
1103
|
+
\`\`\`
|
|
1104
|
+
|
|
1105
|
+
## Positional Arguments
|
|
1106
|
+
|
|
1107
|
+
Export a \`positionals\` array to map CLI positional args into named options fields. The first positional (\`_[0]\`) is always the command name — \`positionals\` maps \`_[1]\`, \`_[2]\`, etc.
|
|
1108
|
+
|
|
1109
|
+
\`\`\`ts
|
|
1110
|
+
// luca {{kebabName}} ./src => options.target === './src'
|
|
1111
|
+
export const positionals = ['target']
|
|
1112
|
+
\`\`\`
|
|
1113
|
+
|
|
1114
|
+
## Args Schema
|
|
1115
|
+
|
|
1116
|
+
Define your command's arguments and flags with Zod. Each field becomes a \`--flag\` on the CLI. Fields named in \`positionals\` also accept positional args.
|
|
1117
|
+
|
|
1118
|
+
\`\`\`ts
|
|
1119
|
+
export const argsSchema = z.object({
|
|
1120
|
+
// Positional: first arg after command name (via positionals array above)
|
|
1121
|
+
// target: z.string().optional().describe('The target to operate on'),
|
|
1122
|
+
|
|
1123
|
+
// Flags: passed as --flag on the CLI
|
|
1124
|
+
// verbose: z.boolean().default(false).describe('Enable verbose output'),
|
|
1125
|
+
// output: z.string().optional().describe('Output file path'),
|
|
1126
|
+
})
|
|
1127
|
+
\`\`\`
|
|
1128
|
+
|
|
1129
|
+
## Description
|
|
1130
|
+
|
|
1131
|
+
Export a description string for \`luca --help\` display:
|
|
1132
|
+
|
|
1133
|
+
\`\`\`ts
|
|
1134
|
+
export const description = '{{description}}'
|
|
1135
|
+
\`\`\`
|
|
1136
|
+
|
|
1137
|
+
## Handler
|
|
1138
|
+
|
|
1139
|
+
Export a default async function. It receives parsed options and the container context. Use the container for all I/O. Positional args declared in the \`positionals\` export are available as named fields on \`options\`.
|
|
1140
|
+
|
|
1141
|
+
\`\`\`ts
|
|
1142
|
+
export default async function {{camelName}}(options: z.infer<typeof argsSchema>, context: ContainerContext) {
|
|
1143
|
+
const { container } = context
|
|
1144
|
+
const fs = container.feature('fs')
|
|
1145
|
+
|
|
1146
|
+
// options.target is set from the first positional arg (via positionals export)
|
|
1147
|
+
// options.verbose, options.output, etc. come from --flags
|
|
1148
|
+
|
|
1149
|
+
// Your implementation here
|
|
1150
|
+
}
|
|
1151
|
+
\`\`\`
|
|
1152
|
+
|
|
1153
|
+
## Complete Example
|
|
1154
|
+
|
|
1155
|
+
\`\`\`ts
|
|
1156
|
+
import { z } from 'zod'
|
|
1157
|
+
import type { ContainerContext } from 'luca'
|
|
1158
|
+
|
|
1159
|
+
export const description = '{{description}}'
|
|
1160
|
+
|
|
1161
|
+
// Map positional args to named options: luca {{kebabName}} myTarget => options.target === 'myTarget'
|
|
1162
|
+
export const positionals = ['target']
|
|
1163
|
+
|
|
1164
|
+
export const argsSchema = z.object({
|
|
1165
|
+
target: z.string().optional().describe('The target to operate on'),
|
|
1166
|
+
})
|
|
1167
|
+
|
|
1168
|
+
export default async function {{camelName}}(options: z.infer<typeof argsSchema>, context: ContainerContext) {
|
|
1169
|
+
const { container } = context
|
|
1170
|
+
const fs = container.feature('fs')
|
|
1171
|
+
|
|
1172
|
+
console.log('{{kebabName}} running...', options.target)
|
|
1173
|
+
}
|
|
1174
|
+
\`\`\`
|
|
1175
|
+
|
|
1176
|
+
## Container Properties
|
|
1177
|
+
|
|
1178
|
+
The \`context.container\` object provides useful properties beyond features:
|
|
1179
|
+
|
|
1180
|
+
\`\`\`ts
|
|
1181
|
+
export default async function {{camelName}}(options: z.infer<typeof argsSchema>, context: ContainerContext) {
|
|
1182
|
+
const { container } = context
|
|
1183
|
+
|
|
1184
|
+
// Current working directory
|
|
1185
|
+
container.cwd // '/path/to/project'
|
|
1186
|
+
|
|
1187
|
+
// Path utilities (scoped to cwd)
|
|
1188
|
+
container.paths.resolve('src') // '/path/to/project/src'
|
|
1189
|
+
container.paths.join('a', 'b') // '/path/to/project/a/b'
|
|
1190
|
+
container.paths.relative('src') // 'src'
|
|
1191
|
+
|
|
1192
|
+
// Package manifest (parsed package.json)
|
|
1193
|
+
container.manifest.name // 'my-project'
|
|
1194
|
+
container.manifest.version // '1.0.0'
|
|
1195
|
+
|
|
1196
|
+
// Raw CLI arguments (from minimist) — prefer positionals export for positional args
|
|
1197
|
+
container.argv // { _: ['{{kebabName}}', ...], verbose: true, ... }
|
|
1198
|
+
}
|
|
1199
|
+
\`\`\`
|
|
1200
|
+
|
|
1201
|
+
## Conventions
|
|
1202
|
+
|
|
1203
|
+
- **File location**: \`commands/{{kebabName}}.ts\` in the project root. The \`luca\` CLI discovers these automatically.
|
|
1204
|
+
- **Naming**: kebab-case for filename. \`luca {{kebabName}}\` maps to \`commands/{{kebabName}}.ts\`.
|
|
1205
|
+
- **Use the container**: Never import \`fs\`, \`path\`, \`child_process\` directly. Use \`container.feature('fs')\`, \`container.paths\`, \`container.feature('proc')\`.
|
|
1206
|
+
- **Positional args**: Export \`positionals = ['name1', 'name2']\` to map CLI positional args into named options fields. For raw access, use \`container.argv._\` where \`_[0]\` is the command name.
|
|
1207
|
+
- **Exit codes**: Return nothing for success. Throw for errors — the CLI catches and reports them.
|
|
1208
|
+
- **Help text**: Use \`.describe()\` on every schema field — it powers \`luca {{kebabName}} --help\`.
|
|
1209
|
+
`,
|
|
1210
|
+
},
|
|
1211
|
+
endpoint: {
|
|
1212
|
+
sections: [
|
|
1213
|
+
{ heading: "Required Exports", code: `export const path = '/api/{{camelName}}'
|
|
1214
|
+
export const description = '{{description}}'
|
|
1215
|
+
export const tags = ['{{camelName}}']` },
|
|
1216
|
+
{ heading: "Handler Functions", code: `export async function get(params: any, ctx: any) {
|
|
1217
|
+
const fs = ctx.container.feature('fs')
|
|
1218
|
+
// Your logic here
|
|
1219
|
+
return { message: 'ok' }
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
export async function post(params: any, ctx: any) {
|
|
1223
|
+
// Create something
|
|
1224
|
+
return { created: true }
|
|
1225
|
+
}` },
|
|
1226
|
+
{ heading: "Validation Schemas", code: `import { z } from 'zod'
|
|
1227
|
+
|
|
1228
|
+
export const getSchema = z.object({
|
|
1229
|
+
q: z.string().optional().describe('Search query'),
|
|
1230
|
+
limit: z.number().default(20).describe('Max results'),
|
|
1231
|
+
})
|
|
1232
|
+
|
|
1233
|
+
export const postSchema = z.object({
|
|
1234
|
+
title: z.string().min(1).describe('Item title'),
|
|
1235
|
+
body: z.string().min(1).describe('Item content'),
|
|
1236
|
+
})` },
|
|
1237
|
+
{ heading: "Rate Limiting", code: `// Global rate limit for all methods
|
|
1238
|
+
export const rateLimit = { maxRequests: 100, windowSeconds: 60 }
|
|
1239
|
+
|
|
1240
|
+
// Per-method rate limit
|
|
1241
|
+
export const postRateLimit = { maxRequests: 10, windowSeconds: 1 }` },
|
|
1242
|
+
{ heading: "Delete Handler", code: `// Use a local name, then re-export as \`delete\`
|
|
1243
|
+
const del = async (params: any, ctx: any) => {
|
|
1244
|
+
return { deleted: true }
|
|
1245
|
+
}
|
|
1246
|
+
export { del as delete }` },
|
|
1247
|
+
{ heading: "Complete Example", code: `export const path = '/api/{{camelName}}'
|
|
1248
|
+
export const description = '{{description}}'
|
|
1249
|
+
export const tags = ['{{camelName}}']
|
|
1250
|
+
|
|
1251
|
+
export async function get(params: any, ctx: any) {
|
|
1252
|
+
return { items: [], total: 0 }
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
export async function post(params: any, ctx: any) {
|
|
1256
|
+
return { item: { id: '1', ...params }, message: 'Created' }
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
const del = async (params: any, ctx: any) => {
|
|
1260
|
+
const { id } = ctx.params
|
|
1261
|
+
return { message: \`Deleted \${id}\` }
|
|
1262
|
+
}
|
|
1263
|
+
export { del as delete }` },
|
|
1264
|
+
{ heading: "Dynamic Route Example", code: `// endpoints/{{camelName}}/[id].ts
|
|
1265
|
+
export const path = '/api/{{camelName}}/:id'
|
|
1266
|
+
export const description = 'Get, update, or delete a specific item'
|
|
1267
|
+
export const tags = ['{{camelName}}']
|
|
1268
|
+
|
|
1269
|
+
export async function get(params: any, ctx: any) {
|
|
1270
|
+
const { id } = ctx.params
|
|
1271
|
+
return { item: { id } }
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
export async function put(params: any, ctx: any) {
|
|
1275
|
+
const { id } = ctx.params
|
|
1276
|
+
return { item: { id, ...params }, message: 'Updated' }
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
const del = async (params: any, ctx: any) => {
|
|
1280
|
+
const { id } = ctx.params
|
|
1281
|
+
return { message: \`Deleted \${id}\` }
|
|
1282
|
+
}
|
|
1283
|
+
export { del as delete }` }
|
|
1284
|
+
],
|
|
1285
|
+
full: `export const path = '/api/{{camelName}}'
|
|
1286
|
+
export const description = '{{description}}'
|
|
1287
|
+
export const tags = ['{{camelName}}']
|
|
1288
|
+
|
|
1289
|
+
export async function get(params: any, ctx: any) {
|
|
1290
|
+
return { items: [], total: 0 }
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
export async function post(params: any, ctx: any) {
|
|
1294
|
+
return { item: { id: '1', ...params }, message: 'Created' }
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
const del = async (params: any, ctx: any) => {
|
|
1298
|
+
const { id } = ctx.params
|
|
1299
|
+
return { message: \`Deleted \${id}\` }
|
|
1300
|
+
}
|
|
1301
|
+
export { del as delete }`,
|
|
1302
|
+
tutorial: `# Building an Endpoint
|
|
1303
|
+
|
|
1304
|
+
An endpoint is a route handler that \`luca serve\` auto-discovers and mounts on an Express server. Endpoints live in \`endpoints/\` and follow a file-based routing convention — each file becomes an API route with automatic validation, OpenAPI spec generation, and rate limiting.
|
|
1305
|
+
|
|
1306
|
+
When to build an endpoint:
|
|
1307
|
+
- You need a REST API route (GET, POST, PUT, PATCH, DELETE)
|
|
1308
|
+
- You want Zod validation, OpenAPI docs, and rate limiting for free
|
|
1309
|
+
- You're building an API that \`luca serve\` manages
|
|
1310
|
+
|
|
1311
|
+
## File Location
|
|
1312
|
+
|
|
1313
|
+
Endpoints go in \`endpoints/\` at your project root:
|
|
1314
|
+
- \`endpoints/health.ts\` → \`/health\`
|
|
1315
|
+
- \`endpoints/posts.ts\` → \`/api/posts\`
|
|
1316
|
+
- \`endpoints/posts/[id].ts\` → \`/api/posts/:id\` (requires \`path\` export)
|
|
1317
|
+
|
|
1318
|
+
Run \`luca serve\` and they're automatically discovered and mounted.
|
|
1319
|
+
|
|
1320
|
+
## Imports
|
|
1321
|
+
|
|
1322
|
+
Endpoints are lightweight — just exports and handler functions. No imports are required.
|
|
1323
|
+
|
|
1324
|
+
If your project has \`luca\` as an npm dependency, you can import \`z\` from \`zod\` and \`EndpointContext\` from \`luca\` for type safety. Otherwise, use \`any\` types — the framework handles validation and context injection for you.
|
|
1325
|
+
|
|
1326
|
+
Access framework capabilities through the \`ctx\` parameter:
|
|
1327
|
+
- \`ctx.container.feature('fs')\` for file operations
|
|
1328
|
+
- \`ctx.container.feature('yaml')\` for YAML parsing
|
|
1329
|
+
- \`ctx.container.feature('sqlite')\` for database access
|
|
1330
|
+
|
|
1331
|
+
## Required Exports
|
|
1332
|
+
|
|
1333
|
+
Every endpoint MUST export a \`path\` string:
|
|
1334
|
+
|
|
1335
|
+
\`\`\`ts
|
|
1336
|
+
export const path = '/api/{{camelName}}'
|
|
1337
|
+
export const description = '{{description}}'
|
|
1338
|
+
export const tags = ['{{camelName}}']
|
|
1339
|
+
\`\`\`
|
|
1340
|
+
|
|
1341
|
+
## Handler Functions
|
|
1342
|
+
|
|
1343
|
+
Export named functions for each HTTP method you support. Each receives validated parameters and a context object:
|
|
1344
|
+
|
|
1345
|
+
\`\`\`ts
|
|
1346
|
+
export async function get(params: any, ctx: any) {
|
|
1347
|
+
const fs = ctx.container.feature('fs')
|
|
1348
|
+
// Your logic here
|
|
1349
|
+
return { message: 'ok' }
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
export async function post(params: any, ctx: any) {
|
|
1353
|
+
// Create something
|
|
1354
|
+
return { created: true }
|
|
1355
|
+
}
|
|
1356
|
+
\`\`\`
|
|
1357
|
+
|
|
1358
|
+
The \`EndpointContext\` gives you:
|
|
1359
|
+
- \`ctx.container\` — the luca container (access any feature, client, etc.)
|
|
1360
|
+
- \`ctx.request\` — Express request object
|
|
1361
|
+
- \`ctx.response\` — Express response object
|
|
1362
|
+
- \`ctx.query\` — parsed query string
|
|
1363
|
+
- \`ctx.body\` — parsed request body
|
|
1364
|
+
- \`ctx.params\` — URL parameters (\`:id\`, etc.)
|
|
1365
|
+
|
|
1366
|
+
Return any object — it's automatically JSON-serialized as the response.
|
|
1367
|
+
|
|
1368
|
+
## Validation Schemas
|
|
1369
|
+
|
|
1370
|
+
If \`zod\` is available (via \`luca\` dependency or \`node_modules\`), export Zod schemas to validate parameters for each method. Name them \`{method}Schema\`:
|
|
1371
|
+
|
|
1372
|
+
\`\`\`ts
|
|
1373
|
+
import { z } from 'zod'
|
|
1374
|
+
|
|
1375
|
+
export const getSchema = z.object({
|
|
1376
|
+
q: z.string().optional().describe('Search query'),
|
|
1377
|
+
limit: z.number().default(20).describe('Max results'),
|
|
1378
|
+
})
|
|
1379
|
+
|
|
1380
|
+
export const postSchema = z.object({
|
|
1381
|
+
title: z.string().min(1).describe('Item title'),
|
|
1382
|
+
body: z.string().min(1).describe('Item content'),
|
|
1383
|
+
})
|
|
1384
|
+
\`\`\`
|
|
1385
|
+
|
|
1386
|
+
Invalid requests automatically return 400 with Zod error details. Schemas also feed the auto-generated OpenAPI spec. If zod is not available, skip schema exports — the endpoint still works, you just lose automatic validation.
|
|
1387
|
+
|
|
1388
|
+
## Rate Limiting
|
|
1389
|
+
|
|
1390
|
+
Export rate limit config to protect endpoints:
|
|
1391
|
+
|
|
1392
|
+
\`\`\`ts
|
|
1393
|
+
// Global rate limit for all methods
|
|
1394
|
+
export const rateLimit = { maxRequests: 100, windowSeconds: 60 }
|
|
1395
|
+
|
|
1396
|
+
// Per-method rate limit
|
|
1397
|
+
export const postRateLimit = { maxRequests: 10, windowSeconds: 1 }
|
|
1398
|
+
\`\`\`
|
|
1399
|
+
|
|
1400
|
+
## Delete Handler
|
|
1401
|
+
|
|
1402
|
+
\`delete\` is a reserved word in JS, so you can't use it as a function name directly. Use a named export alias:
|
|
1403
|
+
|
|
1404
|
+
\`\`\`ts
|
|
1405
|
+
// Use a local name, then re-export as \`delete\`
|
|
1406
|
+
const del = async (params: any, ctx: any) => {
|
|
1407
|
+
return { deleted: true }
|
|
1408
|
+
}
|
|
1409
|
+
export { del as delete }
|
|
1410
|
+
\`\`\`
|
|
1411
|
+
|
|
1412
|
+
You can also export \`deleteSchema\` and \`deleteRateLimit\` for validation and rate limiting on DELETE.
|
|
1413
|
+
|
|
1414
|
+
## Complete Example
|
|
1415
|
+
|
|
1416
|
+
A CRUD endpoint for a resource (no external imports needed):
|
|
1417
|
+
|
|
1418
|
+
\`\`\`ts
|
|
1419
|
+
export const path = '/api/{{camelName}}'
|
|
1420
|
+
export const description = '{{description}}'
|
|
1421
|
+
export const tags = ['{{camelName}}']
|
|
1422
|
+
|
|
1423
|
+
export async function get(params: any, ctx: any) {
|
|
1424
|
+
return { items: [], total: 0 }
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
export async function post(params: any, ctx: any) {
|
|
1428
|
+
return { item: { id: '1', ...params }, message: 'Created' }
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
const del = async (params: any, ctx: any) => {
|
|
1432
|
+
const { id } = ctx.params
|
|
1433
|
+
return { message: \`Deleted \${id}\` }
|
|
1434
|
+
}
|
|
1435
|
+
export { del as delete }
|
|
1436
|
+
\`\`\`
|
|
1437
|
+
|
|
1438
|
+
## Dynamic Route Example
|
|
1439
|
+
|
|
1440
|
+
For routes with URL parameters, create a nested file:
|
|
1441
|
+
|
|
1442
|
+
\`\`\`ts
|
|
1443
|
+
// endpoints/{{camelName}}/[id].ts
|
|
1444
|
+
export const path = '/api/{{camelName}}/:id'
|
|
1445
|
+
export const description = 'Get, update, or delete a specific item'
|
|
1446
|
+
export const tags = ['{{camelName}}']
|
|
1447
|
+
|
|
1448
|
+
export async function get(params: any, ctx: any) {
|
|
1449
|
+
const { id } = ctx.params
|
|
1450
|
+
return { item: { id } }
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
export async function put(params: any, ctx: any) {
|
|
1454
|
+
const { id } = ctx.params
|
|
1455
|
+
return { item: { id, ...params }, message: 'Updated' }
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
const del = async (params: any, ctx: any) => {
|
|
1459
|
+
const { id } = ctx.params
|
|
1460
|
+
return { message: \`Deleted \${id}\` }
|
|
1461
|
+
}
|
|
1462
|
+
export { del as delete }
|
|
1463
|
+
\`\`\`
|
|
1464
|
+
|
|
1465
|
+
## Conventions
|
|
1466
|
+
|
|
1467
|
+
- **File = route**: The file path maps to the URL path. \`endpoints/users.ts\` serves \`/api/users\`.
|
|
1468
|
+
- **Export \`path\`**: Every endpoint must export a \`path\` string. This is the mounted route.
|
|
1469
|
+
- **Use Zod schemas**: Name them \`getSchema\`, \`postSchema\`, etc. They validate AND document.
|
|
1470
|
+
- **Use the container**: Access features via \`ctx.container.feature('fs')\`, not Node.js imports.
|
|
1471
|
+
- **Return objects**: Handler return values are JSON-serialized. Use \`ctx.response\` only for streaming or custom status codes.
|
|
1472
|
+
- **OpenAPI for free**: Your \`path\`, \`description\`, \`tags\`, and schemas automatically generate an OpenAPI spec at \`/openapi.json\`.
|
|
1473
|
+
`,
|
|
1474
|
+
},
|
|
1475
|
+
selector: {
|
|
1476
|
+
sections: [
|
|
1477
|
+
{ heading: "Imports", code: `import { z } from 'zod'
|
|
1478
|
+
import type { ContainerContext } from 'luca'` },
|
|
1479
|
+
{ heading: "Args Schema", code: `export const argsSchema = z.object({
|
|
1480
|
+
// Add your input arguments here.
|
|
1481
|
+
// Example: field: z.string().optional().describe('Specific field to return'),
|
|
1482
|
+
})` },
|
|
1483
|
+
{ heading: "Description", code: `export const description = '{{description}}'` },
|
|
1484
|
+
{ heading: "Caching", code: `export function cacheKey(args: z.infer<typeof argsSchema>, context: ContainerContext) {
|
|
1485
|
+
return context.container.git.currentCommitSha
|
|
1486
|
+
}` },
|
|
1487
|
+
{ heading: "Caching", code: `export const cacheable = false` },
|
|
1488
|
+
{ heading: "Handler", code: `export async function run(args: z.infer<typeof argsSchema>, context: ContainerContext) {
|
|
1489
|
+
const { container } = context
|
|
1490
|
+
// Query and return your data
|
|
1491
|
+
return { /* your data */ }
|
|
1492
|
+
}` },
|
|
1493
|
+
{ heading: "Complete Example", code: `import { z } from 'zod'
|
|
1494
|
+
import type { ContainerContext } from 'luca'
|
|
1495
|
+
|
|
1496
|
+
export const description = '{{description}}'
|
|
1497
|
+
|
|
1498
|
+
export const argsSchema = z.object({})
|
|
1499
|
+
|
|
1500
|
+
export async function run(args: z.infer<typeof argsSchema>, context: ContainerContext) {
|
|
1501
|
+
const { container } = context
|
|
1502
|
+
|
|
1503
|
+
// Return your data here
|
|
1504
|
+
return {}
|
|
1505
|
+
}` }
|
|
1506
|
+
],
|
|
1507
|
+
full: `import { z } from 'zod'
|
|
1508
|
+
import type { ContainerContext } from 'luca'
|
|
1509
|
+
|
|
1510
|
+
export const description = '{{description}}'
|
|
1511
|
+
|
|
1512
|
+
export const argsSchema = z.object({})
|
|
1513
|
+
|
|
1514
|
+
export async function run(args: z.infer<typeof argsSchema>, context: ContainerContext) {
|
|
1515
|
+
const { container } = context
|
|
1516
|
+
|
|
1517
|
+
// Return your data here
|
|
1518
|
+
return {}
|
|
1519
|
+
}`,
|
|
1520
|
+
tutorial: `# Building a Selector
|
|
1521
|
+
|
|
1522
|
+
A selector returns data. Where commands perform actions, selectors query and return structured results with built-in caching. Selectors live in a project's \`selectors/\` folder and are automatically discovered.
|
|
1523
|
+
|
|
1524
|
+
When to build a selector:
|
|
1525
|
+
- You need to query project data (package info, file listings, config values)
|
|
1526
|
+
- The result benefits from caching (keyed by git SHA or custom key)
|
|
1527
|
+
- You want the data available via \`container.select('name')\` or \`luca select name\`
|
|
1528
|
+
|
|
1529
|
+
## Imports
|
|
1530
|
+
|
|
1531
|
+
\`\`\`ts
|
|
1532
|
+
import { z } from 'zod'
|
|
1533
|
+
import type { ContainerContext } from 'luca'
|
|
1534
|
+
\`\`\`
|
|
1535
|
+
|
|
1536
|
+
## Args Schema
|
|
1537
|
+
|
|
1538
|
+
Define the selector's input arguments with Zod.
|
|
1539
|
+
|
|
1540
|
+
\`\`\`ts
|
|
1541
|
+
export const argsSchema = z.object({
|
|
1542
|
+
// Add your input arguments here.
|
|
1543
|
+
// Example: field: z.string().optional().describe('Specific field to return'),
|
|
1544
|
+
})
|
|
1545
|
+
\`\`\`
|
|
1546
|
+
|
|
1547
|
+
## Description
|
|
1548
|
+
|
|
1549
|
+
Export a description string for discoverability:
|
|
1550
|
+
|
|
1551
|
+
\`\`\`ts
|
|
1552
|
+
export const description = '{{description}}'
|
|
1553
|
+
\`\`\`
|
|
1554
|
+
|
|
1555
|
+
## Caching
|
|
1556
|
+
|
|
1557
|
+
Selectors cache by default. The default cache key is \`hashObject({ selectorName, args, gitSha })\` — same args + same commit = cache hit.
|
|
1558
|
+
|
|
1559
|
+
To customize the cache key:
|
|
1560
|
+
|
|
1561
|
+
\`\`\`ts
|
|
1562
|
+
export function cacheKey(args: z.infer<typeof argsSchema>, context: ContainerContext) {
|
|
1563
|
+
return context.container.git.currentCommitSha
|
|
1564
|
+
}
|
|
1565
|
+
\`\`\`
|
|
1566
|
+
|
|
1567
|
+
To disable caching:
|
|
1568
|
+
|
|
1569
|
+
\`\`\`ts
|
|
1570
|
+
export const cacheable = false
|
|
1571
|
+
\`\`\`
|
|
1572
|
+
|
|
1573
|
+
## Handler
|
|
1574
|
+
|
|
1575
|
+
Export a \`run\` function that returns data. It receives parsed args and the container context.
|
|
1576
|
+
|
|
1577
|
+
\`\`\`ts
|
|
1578
|
+
export async function run(args: z.infer<typeof argsSchema>, context: ContainerContext) {
|
|
1579
|
+
const { container } = context
|
|
1580
|
+
// Query and return your data
|
|
1581
|
+
return { /* your data */ }
|
|
1582
|
+
}
|
|
1583
|
+
\`\`\`
|
|
1584
|
+
|
|
1585
|
+
## Complete Example
|
|
1586
|
+
|
|
1587
|
+
\`\`\`ts
|
|
1588
|
+
import { z } from 'zod'
|
|
1589
|
+
import type { ContainerContext } from 'luca'
|
|
1590
|
+
|
|
1591
|
+
export const description = '{{description}}'
|
|
1592
|
+
|
|
1593
|
+
export const argsSchema = z.object({})
|
|
1594
|
+
|
|
1595
|
+
export async function run(args: z.infer<typeof argsSchema>, context: ContainerContext) {
|
|
1596
|
+
const { container } = context
|
|
1597
|
+
|
|
1598
|
+
// Return your data here
|
|
1599
|
+
return {}
|
|
1600
|
+
}
|
|
1601
|
+
\`\`\`
|
|
1602
|
+
|
|
1603
|
+
## Conventions
|
|
1604
|
+
|
|
1605
|
+
- **File location**: \`selectors/{{kebabName}}.ts\` in the project root. Discovered automatically.
|
|
1606
|
+
- **Naming**: kebab-case for filename. \`luca select {{kebabName}}\` maps to \`selectors/{{kebabName}}.ts\`.
|
|
1607
|
+
- **Use the container**: Never import \`fs\`, \`path\` directly. Use \`container.feature('fs')\`, \`container.paths\`.
|
|
1608
|
+
- **Return data**: The \`run\` function must return the data. It gets wrapped in \`{ data, cached, cacheKey }\` by the framework.
|
|
1609
|
+
- **Caching**: On by default. Override \`cacheKey()\` for custom invalidation, or set \`cacheable = false\` to skip.
|
|
1610
|
+
- **CLI**: \`luca select {{kebabName}}\` runs the selector and prints JSON. Use \`--json\` for data only, \`--no-cache\` to force fresh.
|
|
1611
|
+
`,
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
export const assistantFiles: Record<string, string> = {
|
|
1616
|
+
"CORE.md": `# Luca Assistant Example
|
|
1617
|
+
|
|
1618
|
+
You are currently an example / template "Assistant" provided by the Luca framework. ( You'll probably have no idea what that is, don't worry, it doesn't matter ).
|
|
1619
|
+
|
|
1620
|
+
You are what gets scaffolded when a user writes the \`luca scaffold assistant\` command.
|
|
1621
|
+
|
|
1622
|
+
In luca, an Assistant is backed by a folder which has a few components:
|
|
1623
|
+
|
|
1624
|
+
- CORE.md -- this is a markdown file that will get injected into the system prompt of a chat completion call
|
|
1625
|
+
- tools.ts -- this file is expected to export functions, and a schemas object whose keys are the names of the functions that get exported, and whose values are zod v4 schemas that describe the parameters
|
|
1626
|
+
- hooks.ts -- this file is expexted to export functions, whose names match the events emitted by the luca assistant helper
|
|
1627
|
+
|
|
1628
|
+
Currently, the user is chatting with you from the \`luca chat\` CLI.
|
|
1629
|
+
|
|
1630
|
+
You should tell them what each of these files is and how to edit them.
|
|
1631
|
+
|
|
1632
|
+
It is also important for them to know that the luca \`container\` is globally available for them in the context of the \`tools.ts\` and \`hooks.ts\` files.
|
|
1633
|
+
|
|
1634
|
+
`,
|
|
1635
|
+
"tools.ts": `import { z } from 'zod'
|
|
1636
|
+
|
|
1637
|
+
export const schemas = {
|
|
1638
|
+
README: z.object({}).describe('CALL THIS README FUNCTION AS EARLY AS POSSIBLE')
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1641
|
+
export function README(options: z.infer<typeof schemas.README>) {
|
|
1642
|
+
return 'YO YO'
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1645
|
+
`,
|
|
1646
|
+
"hooks.ts": `export function started() {
|
|
1647
|
+
console.log('Assistant started!')
|
|
1648
|
+
}
|
|
1649
|
+
`
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
export const mcpReadme = `# Luca Development Guide
|
|
1653
|
+
|
|
1654
|
+
You are working in a **luca project**. The luca container provides all capabilities your code needs. Do not install npm packages or import Node.js builtins directly.
|
|
1655
|
+
|
|
1656
|
+
## The Contract
|
|
1657
|
+
|
|
1658
|
+
Every capability goes through the container. If you need something that doesn't exist, build it as a feature, client, or server. If it wraps a third-party library, the helper IS the interface — consumer code never imports the library directly.
|
|
1659
|
+
|
|
1660
|
+
## Import Rule
|
|
1661
|
+
|
|
1662
|
+
All consumer code imports from \`luca\` only:
|
|
1663
|
+
|
|
1664
|
+
\`\`\`ts
|
|
1665
|
+
import { Feature, features, z, FeatureStateSchema, FeatureOptionsSchema } from 'luca'
|
|
1666
|
+
import { Client, clients, RestClient, ClientStateSchema } from 'luca/client'
|
|
1667
|
+
import { Server, servers, ServerStateSchema } from 'luca'
|
|
1668
|
+
import { commands, CommandOptionsSchema } from 'luca'
|
|
1669
|
+
\`\`\`
|
|
1670
|
+
|
|
1671
|
+
Never import from \`fs\`, \`path\`, \`crypto\`, or other Node builtins. Never import third-party packages in consumer code. If a container feature wraps the functionality, use it.
|
|
1672
|
+
|
|
1673
|
+
## Zod v4
|
|
1674
|
+
|
|
1675
|
+
This project uses **Zod v4** — import \`z\` from \`luca\`, never from \`'zod'\` directly. All option, state, and event schemas use Zod v4 syntax. Key patterns:
|
|
1676
|
+
|
|
1677
|
+
\`\`\`ts
|
|
1678
|
+
// Extending base schemas (options, state, events)
|
|
1679
|
+
export const MyStateSchema = FeatureStateSchema.extend({
|
|
1680
|
+
count: z.number().default(0).describe('Number of items'),
|
|
1681
|
+
label: z.string().optional().describe('Display label'),
|
|
1682
|
+
})
|
|
1683
|
+
|
|
1684
|
+
// Events use z.tuple() for listener arguments
|
|
1685
|
+
export const MyEventsSchema = FeatureEventsSchema.extend({
|
|
1686
|
+
itemAdded: z.tuple([z.string().describe('key'), z.number().describe('index')]),
|
|
1687
|
+
})
|
|
1688
|
+
|
|
1689
|
+
// Type inference
|
|
1690
|
+
export type MyState = z.infer<typeof MyStateSchema>
|
|
1691
|
+
\`\`\`
|
|
1692
|
+
|
|
1693
|
+
Zod v4 differences from v3 that matter:
|
|
1694
|
+
- \`z.string().check(...)\` replaces some v3 refinement patterns
|
|
1695
|
+
- \`.toJSONSchema()\` is built-in on any schema — no external library needed
|
|
1696
|
+
- Error customization uses \`z.string({ error: "message" })\` not \`.refine()\` for simple cases
|
|
1697
|
+
- \`z.interface()\` exists for recursive/lazy object types
|
|
1698
|
+
- Do NOT use \`z.nativeEnum()\` — use \`z.enum()\` instead
|
|
1699
|
+
|
|
1700
|
+
## Dependencies
|
|
1701
|
+
|
|
1702
|
+
If the project has \`node_modules\` and a package manager, helper implementations can import third-party libraries internally. If not (e.g. running via the \`luca\` binary's VM), all code must import only from \`luca\`.
|
|
1703
|
+
|
|
1704
|
+
## Discovering Capabilities
|
|
1705
|
+
|
|
1706
|
+
The container has registries for features, clients, servers, commands, and endpoints. **Do not guess** what is available — use your MCP tools to discover it:
|
|
1707
|
+
|
|
1708
|
+
1. **\`find_capability\`** — Overview of all features, clients, and servers with descriptions. Start here.
|
|
1709
|
+
2. **\`list_registry\`** — List all names in a specific registry (features, clients, servers, commands, endpoints).
|
|
1710
|
+
3. **\`describe_helper\`** — Full API docs for a specific helper (methods, options, state, events). Call this before writing code that uses a helper.
|
|
1711
|
+
4. **\`eval\`** — Once you know what you need, prototype calls in the live sandbox before writing them into files.
|
|
1712
|
+
|
|
1713
|
+
## Mini Examples
|
|
1714
|
+
|
|
1715
|
+
### Feature with composition
|
|
1716
|
+
|
|
1717
|
+
Features access other features via \`this.container.feature(...)\`:
|
|
1718
|
+
|
|
1719
|
+
\`\`\`ts
|
|
1720
|
+
import { z } from 'zod'
|
|
1721
|
+
import { FeatureStateSchema, FeatureOptionsSchema, FeatureEventsSchema } from 'luca'
|
|
1722
|
+
import { Feature, features } from 'luca'
|
|
1723
|
+
import type { ContainerContext } from 'luca'
|
|
1724
|
+
|
|
1725
|
+
export const ConfigStateSchema = FeatureStateSchema.extend({
|
|
1726
|
+
loaded: z.boolean().default(false).describe('Whether config has been loaded'),
|
|
1727
|
+
})
|
|
1728
|
+
|
|
1729
|
+
export const ConfigOptionsSchema = FeatureOptionsSchema.extend({
|
|
1730
|
+
filePath: z.string().default('config.json').describe('Path to config file'),
|
|
1731
|
+
})
|
|
1732
|
+
|
|
1733
|
+
export const ConfigEventsSchema = FeatureEventsSchema.extend({
|
|
1734
|
+
configLoaded: z.tuple([z.record(z.unknown()).describe('parsed config')]),
|
|
1735
|
+
})
|
|
1736
|
+
|
|
1737
|
+
export class Config extends Feature<z.infer<typeof ConfigStateSchema>, z.infer<typeof ConfigOptionsSchema>> {
|
|
1738
|
+
static override shortcut = 'features.config' as const
|
|
1739
|
+
static override stateSchema = ConfigStateSchema
|
|
1740
|
+
static override optionsSchema = ConfigOptionsSchema
|
|
1741
|
+
static override eventsSchema = ConfigEventsSchema
|
|
1742
|
+
static override description = 'Loads and manages project configuration'
|
|
1743
|
+
|
|
1744
|
+
/** Load and parse the config file */
|
|
1745
|
+
async load() {
|
|
1746
|
+
const fs = this.container.feature('fs')
|
|
1747
|
+
const raw = await fs.readFile(this.options.filePath)
|
|
1748
|
+
const data = JSON.parse(raw)
|
|
1749
|
+
this.state.set('loaded', true)
|
|
1750
|
+
this.emit('configLoaded', data)
|
|
1751
|
+
return data
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
|
|
1755
|
+
declare module 'luca' {
|
|
1756
|
+
interface AvailableFeatures { config: typeof Config }
|
|
1757
|
+
}
|
|
1758
|
+
export default features.register('config', Config)
|
|
1759
|
+
\`\`\`
|
|
1760
|
+
|
|
1761
|
+
### Client with composition
|
|
1762
|
+
|
|
1763
|
+
Clients access features and other clients via \`this.container\`:
|
|
1764
|
+
|
|
1765
|
+
\`\`\`ts
|
|
1766
|
+
import { z } from 'zod'
|
|
1767
|
+
import { Client, clients, ClientStateSchema, ClientOptionsSchema, ClientEventsSchema } from 'luca'
|
|
1768
|
+
import type { ContainerContext } from 'luca'
|
|
1769
|
+
|
|
1770
|
+
export const GithubOptionsSchema = ClientOptionsSchema.extend({
|
|
1771
|
+
token: z.string().describe('GitHub personal access token'),
|
|
1772
|
+
owner: z.string().describe('Repository owner'),
|
|
1773
|
+
repo: z.string().describe('Repository name'),
|
|
1774
|
+
})
|
|
1775
|
+
|
|
1776
|
+
export const GithubEventsSchema = ClientEventsSchema.extend({
|
|
1777
|
+
issuesFetched: z.tuple([z.number().describe('count')]),
|
|
1778
|
+
})
|
|
1779
|
+
|
|
1780
|
+
export class GithubClient extends Client<z.infer<typeof ClientStateSchema>, z.infer<typeof GithubOptionsSchema>> {
|
|
1781
|
+
static override shortcut = 'clients.github' as const
|
|
1782
|
+
static override optionsSchema = GithubOptionsSchema
|
|
1783
|
+
static override eventsSchema = GithubEventsSchema
|
|
1784
|
+
static override description = 'GitHub API client using container REST client'
|
|
1785
|
+
|
|
1786
|
+
/** Fetch open issues */
|
|
1787
|
+
async issues() {
|
|
1788
|
+
const rest = this.container.client('rest')
|
|
1789
|
+
const res = await rest.get(\`https://api.github.com/repos/\${this.options.owner}/\${this.options.repo}/issues\`, {
|
|
1790
|
+
headers: { Authorization: \`token \${this.options.token}\` },
|
|
1791
|
+
})
|
|
1792
|
+
this.emit('issuesFetched', res.data.length)
|
|
1793
|
+
return res.data
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
declare module 'luca' {
|
|
1798
|
+
interface AvailableClients { github: typeof GithubClient }
|
|
1799
|
+
}
|
|
1800
|
+
export default clients.register('github', GithubClient)
|
|
1801
|
+
\`\`\`
|
|
1802
|
+
|
|
1803
|
+
## Workflow
|
|
1804
|
+
|
|
1805
|
+
1. **\`find_capability\`** — Search what already exists before writing anything
|
|
1806
|
+
2. **\`describe_helper\`** — Read the full API docs for the helper you need
|
|
1807
|
+
3. **\`eval\`** — Prototype and test container API calls in the sandbox
|
|
1808
|
+
4. **\`scaffold\`** — Generate correct boilerplate when building something new
|
|
1809
|
+
5. **Write the file** — Using the patterns from the scaffold
|
|
1810
|
+
|
|
1811
|
+
## Portability
|
|
1812
|
+
|
|
1813
|
+
Code that only imports from \`luca\` can be copied between any luca project. That's the goal. Features, clients, servers, and commands written this way are portable building blocks.
|
|
1814
|
+
`
|