@soederpop/luca 0.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/CLAUDE.md +71 -0
- package/README.md +78 -0
- package/bun.lock +2928 -0
- package/bunfig.toml +3 -0
- package/commands/audit-docs.ts +740 -0
- package/commands/build-scaffolds.ts +154 -0
- package/commands/generate-api-docs.ts +114 -0
- package/commands/update-introspection.ts +67 -0
- package/docs/CLI.md +335 -0
- package/docs/README.md +88 -0
- package/docs/TABLE-OF-CONTENTS.md +157 -0
- package/docs/apis/clients/elevenlabs.md +84 -0
- package/docs/apis/clients/graph.md +56 -0
- package/docs/apis/clients/openai.md +69 -0
- package/docs/apis/clients/rest.md +41 -0
- package/docs/apis/clients/websocket.md +107 -0
- package/docs/apis/features/agi/assistant.md +471 -0
- package/docs/apis/features/agi/assistants-manager.md +154 -0
- package/docs/apis/features/agi/claude-code.md +602 -0
- package/docs/apis/features/agi/conversation-history.md +352 -0
- package/docs/apis/features/agi/conversation.md +333 -0
- package/docs/apis/features/agi/docs-reader.md +121 -0
- package/docs/apis/features/agi/openai-codex.md +318 -0
- package/docs/apis/features/agi/openapi.md +138 -0
- package/docs/apis/features/agi/semantic-search.md +387 -0
- package/docs/apis/features/agi/skills-library.md +216 -0
- package/docs/apis/features/node/container-link.md +133 -0
- package/docs/apis/features/node/content-db.md +313 -0
- package/docs/apis/features/node/disk-cache.md +379 -0
- package/docs/apis/features/node/dns.md +651 -0
- package/docs/apis/features/node/docker.md +705 -0
- package/docs/apis/features/node/downloader.md +81 -0
- package/docs/apis/features/node/esbuild.md +59 -0
- package/docs/apis/features/node/file-manager.md +182 -0
- package/docs/apis/features/node/fs.md +581 -0
- package/docs/apis/features/node/git.md +330 -0
- package/docs/apis/features/node/google-auth.md +174 -0
- package/docs/apis/features/node/google-calendar.md +187 -0
- package/docs/apis/features/node/google-docs.md +151 -0
- package/docs/apis/features/node/google-drive.md +225 -0
- package/docs/apis/features/node/google-sheets.md +179 -0
- package/docs/apis/features/node/grep.md +290 -0
- package/docs/apis/features/node/helpers.md +135 -0
- package/docs/apis/features/node/ink.md +334 -0
- package/docs/apis/features/node/ipc-socket.md +260 -0
- package/docs/apis/features/node/json-tree.md +86 -0
- package/docs/apis/features/node/launcher-app-command-listener.md +145 -0
- package/docs/apis/features/node/networking.md +281 -0
- package/docs/apis/features/node/nlp.md +133 -0
- package/docs/apis/features/node/opener.md +97 -0
- package/docs/apis/features/node/os.md +118 -0
- package/docs/apis/features/node/package-finder.md +402 -0
- package/docs/apis/features/node/postgres.md +212 -0
- package/docs/apis/features/node/proc.md +430 -0
- package/docs/apis/features/node/process-manager.md +210 -0
- package/docs/apis/features/node/python.md +278 -0
- package/docs/apis/features/node/repl.md +88 -0
- package/docs/apis/features/node/runpod.md +673 -0
- package/docs/apis/features/node/secure-shell.md +169 -0
- package/docs/apis/features/node/semantic-search.md +401 -0
- package/docs/apis/features/node/sqlite.md +211 -0
- package/docs/apis/features/node/telegram.md +254 -0
- package/docs/apis/features/node/tts.md +118 -0
- package/docs/apis/features/node/ui.md +703 -0
- package/docs/apis/features/node/vault.md +64 -0
- package/docs/apis/features/node/vm.md +84 -0
- package/docs/apis/features/node/window-manager.md +337 -0
- package/docs/apis/features/node/yaml-tree.md +85 -0
- package/docs/apis/features/node/yaml.md +176 -0
- package/docs/apis/features/web/asset-loader.md +47 -0
- package/docs/apis/features/web/container-link.md +133 -0
- package/docs/apis/features/web/esbuild.md +59 -0
- package/docs/apis/features/web/helpers.md +135 -0
- package/docs/apis/features/web/network.md +30 -0
- package/docs/apis/features/web/speech.md +55 -0
- package/docs/apis/features/web/vault.md +64 -0
- package/docs/apis/features/web/vm.md +84 -0
- package/docs/apis/features/web/voice.md +67 -0
- package/docs/apis/servers/express.md +127 -0
- package/docs/apis/servers/mcp.md +213 -0
- package/docs/apis/servers/websocket.md +99 -0
- package/docs/documentation-audit.md +134 -0
- package/docs/examples/content-db.md +77 -0
- package/docs/examples/disk-cache.md +83 -0
- package/docs/examples/docker.md +101 -0
- package/docs/examples/downloader.md +70 -0
- package/docs/examples/esbuild.md +80 -0
- package/docs/examples/file-manager.md +82 -0
- package/docs/examples/fs.md +83 -0
- package/docs/examples/git.md +85 -0
- package/docs/examples/google-auth.md +88 -0
- package/docs/examples/google-calendar.md +94 -0
- package/docs/examples/google-docs.md +82 -0
- package/docs/examples/google-drive.md +96 -0
- package/docs/examples/google-sheets.md +95 -0
- package/docs/examples/grep.md +85 -0
- package/docs/examples/ink-blocks.md +75 -0
- package/docs/examples/ink-renderer.md +41 -0
- package/docs/examples/ink.md +103 -0
- package/docs/examples/ipc-socket.md +103 -0
- package/docs/examples/json-tree.md +91 -0
- package/docs/examples/launcher-app-command-listener.md +120 -0
- package/docs/examples/networking.md +58 -0
- package/docs/examples/nlp.md +91 -0
- package/docs/examples/opener.md +78 -0
- package/docs/examples/os.md +72 -0
- package/docs/examples/package-finder.md +89 -0
- package/docs/examples/port-exposer.md +89 -0
- package/docs/examples/postgres.md +91 -0
- package/docs/examples/proc.md +81 -0
- package/docs/examples/process-manager.md +79 -0
- package/docs/examples/python.md +91 -0
- package/docs/examples/repl.md +93 -0
- package/docs/examples/runpod.md +119 -0
- package/docs/examples/secure-shell.md +92 -0
- package/docs/examples/sqlite.md +86 -0
- package/docs/examples/telegram.md +77 -0
- package/docs/examples/tts.md +86 -0
- package/docs/examples/ui.md +80 -0
- package/docs/examples/vault.md +70 -0
- package/docs/examples/vm.md +86 -0
- package/docs/examples/window-manager.md +125 -0
- package/docs/examples/yaml-tree.md +93 -0
- package/docs/examples/yaml.md +104 -0
- package/docs/ideas/class-registration-refactor-possibilities.md +197 -0
- package/docs/ideas/container-use-api.md +9 -0
- package/docs/ideas/easy-auth-for-express-servers-and-luca-serve.md +0 -0
- package/docs/ideas/feature-stacks.md +22 -0
- package/docs/ideas/luca-cli-self-sufficiency-demo.md +23 -0
- package/docs/ideas/mcp-design.md +9 -0
- package/docs/ideas/web-container-debugging-feature.md +13 -0
- package/docs/introspection-audit.md +49 -0
- package/docs/introspection.md +154 -0
- package/docs/mcp/readme.md +162 -0
- package/docs/models.ts +38 -0
- package/docs/philosophy.md +85 -0
- package/docs/principles.md +7 -0
- package/docs/prompts/audit-codebase-for-failures-to-use-the-container.md +34 -0
- package/docs/prompts/mcp-test-easy-command.md +27 -0
- package/docs/reports/assistant-bugs.md +38 -0
- package/docs/reports/attach-pattern-usage.md +18 -0
- package/docs/reports/code-audit-results.md +391 -0
- package/docs/reports/introspection-audit-tasks.md +378 -0
- package/docs/reports/luca-mcp-improvements.md +128 -0
- package/docs/scaffolds/client.md +140 -0
- package/docs/scaffolds/command.md +106 -0
- package/docs/scaffolds/endpoint.md +176 -0
- package/docs/scaffolds/feature.md +148 -0
- package/docs/scaffolds/server.md +187 -0
- package/docs/tasks/web-container-helper-discovery.md +71 -0
- package/docs/todos.md +1 -0
- package/docs/tutorials/01-getting-started.md +106 -0
- package/docs/tutorials/02-container.md +210 -0
- package/docs/tutorials/03-scripts.md +194 -0
- package/docs/tutorials/04-features-overview.md +196 -0
- package/docs/tutorials/05-state-and-events.md +171 -0
- package/docs/tutorials/06-servers.md +157 -0
- package/docs/tutorials/07-endpoints.md +198 -0
- package/docs/tutorials/08-commands.md +171 -0
- package/docs/tutorials/09-clients.md +162 -0
- package/docs/tutorials/10-creating-features.md +198 -0
- package/docs/tutorials/11-contentbase.md +191 -0
- package/docs/tutorials/12-assistants.md +215 -0
- package/docs/tutorials/13-introspection.md +147 -0
- package/docs/tutorials/14-type-system.md +174 -0
- package/docs/tutorials/15-project-patterns.md +222 -0
- package/docs/tutorials/16-google-features.md +534 -0
- package/docs/tutorials/17-tui-blocks.md +530 -0
- package/docs/tutorials/18-semantic-search.md +334 -0
- package/index.ts +1 -0
- package/luca.console.ts +9 -0
- package/main.py +6 -0
- package/package.json +154 -0
- package/pyproject.toml +7 -0
- package/scripts/animations/chrome-glitch.ts +55 -0
- package/scripts/animations/index.ts +16 -0
- package/scripts/animations/neon-pulse.ts +64 -0
- package/scripts/animations/types.ts +6 -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/telegram-ink-ui.ts +302 -0
- package/scripts/examples/using-assistant-with-mcp.ts +560 -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 +10 -0
- package/scripts/examples/using-openai-codex.ts +23 -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/examples/vm-loading-esm-modules.ts +16 -0
- package/scripts/scaffold.ts +391 -0
- package/scripts/scratch.ts +15 -0
- package/scripts/test-command-listener.ts +123 -0
- package/scripts/test-window-manager-lifecycle.ts +86 -0
- package/scripts/test-window-manager.ts +43 -0
- package/scripts/update-introspection-data.ts +58 -0
- package/src/agi/README.md +14 -0
- package/src/agi/container.server.ts +114 -0
- package/src/agi/endpoints/ask.ts +60 -0
- package/src/agi/endpoints/conversations/[id].ts +45 -0
- package/src/agi/endpoints/conversations.ts +31 -0
- package/src/agi/endpoints/experts.ts +37 -0
- package/src/agi/features/assistant.ts +767 -0
- package/src/agi/features/assistants-manager.ts +260 -0
- package/src/agi/features/claude-code.ts +1111 -0
- package/src/agi/features/conversation-history.ts +497 -0
- package/src/agi/features/conversation.ts +799 -0
- package/src/agi/features/openai-codex.ts +631 -0
- package/src/agi/features/openapi.ts +438 -0
- package/src/agi/features/skills-library.ts +425 -0
- package/src/agi/index.ts +6 -0
- package/src/agi/lib/token-counter.ts +122 -0
- package/src/browser.ts +25 -0
- package/src/bus.ts +100 -0
- package/src/cli/cli.ts +70 -0
- package/src/client.ts +461 -0
- package/src/clients/civitai/index.ts +541 -0
- package/src/clients/client-template.ts +41 -0
- package/src/clients/comfyui/index.ts +597 -0
- package/src/clients/elevenlabs/index.ts +291 -0
- package/src/clients/openai/index.ts +451 -0
- package/src/clients/supabase/index.ts +366 -0
- package/src/command.ts +164 -0
- package/src/commands/chat.ts +182 -0
- package/src/commands/console.ts +192 -0
- package/src/commands/describe.ts +433 -0
- package/src/commands/eval.ts +116 -0
- package/src/commands/help.ts +214 -0
- package/src/commands/index.ts +14 -0
- package/src/commands/mcp.ts +64 -0
- package/src/commands/prompt.ts +807 -0
- package/src/commands/run.ts +257 -0
- package/src/commands/sandbox-mcp.ts +439 -0
- package/src/commands/scaffold.ts +79 -0
- package/src/commands/serve.ts +172 -0
- package/src/container.ts +781 -0
- package/src/endpoint.ts +340 -0
- package/src/feature.ts +75 -0
- package/src/hash-object.ts +97 -0
- package/src/helper.ts +543 -0
- package/src/introspection/generated.agi.ts +23388 -0
- package/src/introspection/generated.node.ts +18899 -0
- package/src/introspection/generated.web.ts +2021 -0
- package/src/introspection/index.ts +256 -0
- package/src/introspection/scan.ts +912 -0
- package/src/node/container.ts +354 -0
- package/src/node/feature.ts +13 -0
- package/src/node/features/container-link.ts +558 -0
- package/src/node/features/content-db.ts +475 -0
- package/src/node/features/disk-cache.ts +382 -0
- package/src/node/features/dns.ts +655 -0
- package/src/node/features/docker.ts +912 -0
- package/src/node/features/downloader.ts +92 -0
- package/src/node/features/esbuild.ts +68 -0
- package/src/node/features/file-manager.ts +357 -0
- package/src/node/features/fs.ts +534 -0
- package/src/node/features/git.ts +492 -0
- package/src/node/features/google-auth.ts +502 -0
- package/src/node/features/google-calendar.ts +300 -0
- package/src/node/features/google-docs.ts +404 -0
- package/src/node/features/google-drive.ts +339 -0
- package/src/node/features/google-sheets.ts +279 -0
- package/src/node/features/grep.ts +406 -0
- package/src/node/features/helpers.ts +374 -0
- package/src/node/features/ink.ts +490 -0
- package/src/node/features/ipc-socket.ts +459 -0
- package/src/node/features/json-tree.ts +188 -0
- package/src/node/features/launcher-app-command-listener.ts +388 -0
- package/src/node/features/networking.ts +925 -0
- package/src/node/features/nlp.ts +211 -0
- package/src/node/features/opener.ts +166 -0
- package/src/node/features/os.ts +157 -0
- package/src/node/features/package-finder.ts +539 -0
- package/src/node/features/port-exposer.ts +342 -0
- package/src/node/features/postgres.ts +273 -0
- package/src/node/features/proc.ts +502 -0
- package/src/node/features/process-manager.ts +542 -0
- package/src/node/features/python.ts +444 -0
- package/src/node/features/repl.ts +194 -0
- package/src/node/features/runpod.ts +802 -0
- package/src/node/features/secure-shell.ts +248 -0
- package/src/node/features/semantic-search.ts +924 -0
- package/src/node/features/sqlite.ts +289 -0
- package/src/node/features/telegram.ts +342 -0
- package/src/node/features/tts.ts +184 -0
- package/src/node/features/ui.ts +857 -0
- package/src/node/features/vault.ts +164 -0
- package/src/node/features/vm.ts +312 -0
- package/src/node/features/window-manager.ts +804 -0
- package/src/node/features/yaml-tree.ts +149 -0
- package/src/node/features/yaml.ts +132 -0
- package/src/node.ts +70 -0
- package/src/react/index.ts +175 -0
- package/src/registry.ts +199 -0
- package/src/scaffolds/generated.ts +1613 -0
- package/src/scaffolds/template.ts +37 -0
- package/src/schemas/base.ts +255 -0
- package/src/server.ts +135 -0
- package/src/servers/express.ts +209 -0
- package/src/servers/mcp.ts +805 -0
- package/src/servers/socket.ts +120 -0
- package/src/state.ts +101 -0
- package/src/web/clients/socket.ts +82 -0
- package/src/web/container.ts +74 -0
- package/src/web/extension.ts +30 -0
- package/src/web/feature.ts +12 -0
- package/src/web/features/asset-loader.ts +64 -0
- package/src/web/features/container-link.ts +385 -0
- package/src/web/features/esbuild.ts +79 -0
- package/src/web/features/helpers.ts +267 -0
- package/src/web/features/network.ts +61 -0
- package/src/web/features/speech.ts +87 -0
- package/src/web/features/vault.ts +189 -0
- package/src/web/features/vm.ts +78 -0
- package/src/web/features/voice-recognition.ts +129 -0
- package/src/web/shims/isomorphic-vm.ts +149 -0
- package/test/bus.test.ts +134 -0
- package/test/clients-servers.test.ts +216 -0
- package/test/container-link.test.ts +274 -0
- package/test/features.test.ts +160 -0
- package/test/integration.test.ts +787 -0
- package/test/node-container.test.ts +121 -0
- package/test/rate-limit.test.ts +272 -0
- package/test/semantic-search.test.ts +550 -0
- package/test/state.test.ts +121 -0
- package/test-integration/assistant.test.ts +138 -0
- package/test-integration/assistants-manager.test.ts +123 -0
- package/test-integration/claude-code.test.ts +98 -0
- package/test-integration/conversation-history.test.ts +205 -0
- package/test-integration/conversation.test.ts +137 -0
- package/test-integration/elevenlabs.test.ts +55 -0
- package/test-integration/google-services.test.ts +80 -0
- package/test-integration/helpers.ts +89 -0
- package/test-integration/openai-codex.test.ts +93 -0
- package/test-integration/runpod.test.ts +58 -0
- package/test-integration/server-endpoints.test.ts +97 -0
- package/test-integration/skills-library.test.ts +157 -0
- package/test-integration/telegram.test.ts +46 -0
- package/tsconfig.json +58 -0
- package/uv.lock +8 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
---
|
|
2
|
+
tags: [dx, registration, metaprogramming]
|
|
3
|
+
status: spark
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Class Registration Refactor Possibilities
|
|
7
|
+
|
|
8
|
+
Exploring how static initialization blocks and class-level hooks could simplify helper registration, inspired by Ruby's `self.inherited(subclass)` pattern and how ActiveRecord::Base uses it.
|
|
9
|
+
|
|
10
|
+
## The Ruby Inspiration
|
|
11
|
+
|
|
12
|
+
In Ruby, when you write `class Post < ActiveRecord::Base`, the `inherited` hook fires automatically:
|
|
13
|
+
|
|
14
|
+
```ruby
|
|
15
|
+
class ActiveRecord::Base
|
|
16
|
+
def self.inherited(subclass)
|
|
17
|
+
subclass.table_name = subclass.name.tableize
|
|
18
|
+
subclass.establish_connection
|
|
19
|
+
# The parent configures the child at definition time
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
class Post < ActiveRecord::Base
|
|
24
|
+
end
|
|
25
|
+
# That's it. Full ORM-backed model. No registration call needed.
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The magic: `inherited` fires at **class definition time**, receives the subclass, and lets the parent **reach into the child and set it up**. The empty class that does everything.
|
|
29
|
+
|
|
30
|
+
## Current Luca Registration Pattern
|
|
31
|
+
|
|
32
|
+
Today, every helper requires explicit registration at the bottom of the file:
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
// src/node/features/fs.ts
|
|
36
|
+
import { features, Feature } from "../feature.js"
|
|
37
|
+
|
|
38
|
+
export class FS extends Feature {
|
|
39
|
+
static override shortcut = "features.fs" as const
|
|
40
|
+
static override stateSchema = FeatureStateSchema
|
|
41
|
+
static override optionsSchema = FeatureOptionsSchema
|
|
42
|
+
|
|
43
|
+
// ... methods ...
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default features.register("fs", FS)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
And for extension features (AGI, etc), there's the `attach` pattern:
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
export class Assistant extends Feature<AssistantState, AssistantOptions> {
|
|
53
|
+
static attach(container: Container<AvailableFeatures, any>) {
|
|
54
|
+
features.register('assistant', Assistant)
|
|
55
|
+
return container
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export default features.register('assistant', Assistant)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The registration is always a separate, imperative call disconnected from the class definition itself. The class doesn't know it's been registered. The registry doesn't know until that line runs.
|
|
63
|
+
|
|
64
|
+
## The Static Block Approach
|
|
65
|
+
|
|
66
|
+
ES2022 static initialization blocks let code run at **class definition time**, inside the class body. This is JavaScript's closest equivalent to Ruby's `inherited`:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
class Feature {
|
|
70
|
+
static registry: Registry
|
|
71
|
+
|
|
72
|
+
// This is our "inherited" hook
|
|
73
|
+
static __initSubclass(SubClass: typeof Feature, id: string) {
|
|
74
|
+
this.registry.register(id, SubClass)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### What it could look like for authors
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
// The dream: define, register, and export in one declaration
|
|
83
|
+
export default class FS extends Feature {
|
|
84
|
+
static {
|
|
85
|
+
Feature.register(this, "fs")
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
static override shortcut = "features.fs" as const
|
|
89
|
+
static override stateSchema = FeatureStateSchema
|
|
90
|
+
static override optionsSchema = FeatureOptionsSchema
|
|
91
|
+
|
|
92
|
+
async readFile(path: string) { /* ... */ }
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
No trailing `features.register()` call. No disconnect between the class and its registration. The class **declares itself** as a registered member of the system.
|
|
97
|
+
|
|
98
|
+
### The id could be derived from convention
|
|
99
|
+
|
|
100
|
+
If we adopt a naming convention (like ActiveRecord derives table names from class names), we could eliminate the explicit id entirely:
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
export default class DiskCache extends Feature {
|
|
104
|
+
static {
|
|
105
|
+
Feature.register(this) // id inferred as "diskCache" from class name
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
The `register` implementation:
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
class Feature {
|
|
114
|
+
static register(SubClass: typeof Feature, id?: string) {
|
|
115
|
+
// Convention: PascalCase class name -> camelCase registry id
|
|
116
|
+
const registryId = id ?? SubClass.name[0].toLowerCase() + SubClass.name.slice(1)
|
|
117
|
+
features.register(registryId, SubClass)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Going Further: The Base Class Does All The Work
|
|
123
|
+
|
|
124
|
+
What if the base classes (`Feature`, `Client`, `Server`) provided a static `register` that also handled module augmentation hints and the `attach` pattern?
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
// Before: 15+ lines of boilerplate per feature
|
|
128
|
+
import { z } from 'zod'
|
|
129
|
+
import { features, Feature } from '@soederpop/luca/feature'
|
|
130
|
+
import type { AvailableFeatures } from '@soederpop/luca/feature'
|
|
131
|
+
|
|
132
|
+
declare module '@soederpop/luca/feature' {
|
|
133
|
+
interface AvailableFeatures {
|
|
134
|
+
conversation: typeof Conversation
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export class Conversation extends Feature<ConversationState, ConversationOptions> {
|
|
139
|
+
static override shortcut = 'features.conversation' as const
|
|
140
|
+
static attach(container: Container<AvailableFeatures, any>) {
|
|
141
|
+
features.register('conversation', Conversation)
|
|
142
|
+
return container
|
|
143
|
+
}
|
|
144
|
+
// ...
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export default features.register('conversation', Conversation)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
// After: the class IS the registration
|
|
152
|
+
import { Feature } from '@soederpop/luca/feature'
|
|
153
|
+
|
|
154
|
+
export default class Conversation extends Feature<ConversationState, ConversationOptions> {
|
|
155
|
+
static {
|
|
156
|
+
Feature.register(this, 'conversation')
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// shortcut derived automatically from registry + id
|
|
160
|
+
// attach() provided by base class using the registered id
|
|
161
|
+
// ...
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
The base `Feature.register()` could:
|
|
166
|
+
1. Call `features.register(id, SubClass)`
|
|
167
|
+
2. Set `SubClass.shortcut` automatically (`features.${id}`)
|
|
168
|
+
3. Generate a default `attach()` that registers and returns the container
|
|
169
|
+
4. Emit a `"subclass:registered"` event on the registry for any other wiring
|
|
170
|
+
|
|
171
|
+
## Comparison With Other Approaches
|
|
172
|
+
|
|
173
|
+
| Approach | When it runs | Cooperation needed | Ceremony |
|
|
174
|
+
|----------|-------------|-------------------|----------|
|
|
175
|
+
| Ruby `inherited` | Class definition | None | Zero — just `extends` |
|
|
176
|
+
| Static block + `register` | Class definition | One line in static block | Minimal — inside the class |
|
|
177
|
+
| Trailing `registry.register()` | Module evaluation | Separate call after class | Moderate — disconnected |
|
|
178
|
+
| `defineFeature()` factory | Module evaluation | Wrap entire definition | Different paradigm entirely |
|
|
179
|
+
| Decorators (`@tracked`) | Class definition | One line above class | Minimal — but external |
|
|
180
|
+
|
|
181
|
+
The static block approach is the sweet spot for Luca: it's **standard JavaScript**, runs at **definition time**, lives **inside the class body**, and keeps the class as the primary authoring unit (unlike `defineFeature()` which replaces the class with a factory call).
|
|
182
|
+
|
|
183
|
+
## The `defineFeature` Relationship
|
|
184
|
+
|
|
185
|
+
This is complementary to the [`defineFeature()` idea](./luca-feature-authoring-dx.md), not a replacement. They solve different problems:
|
|
186
|
+
|
|
187
|
+
- **`defineFeature()`** reduces boilerplate for simple features that are mostly a bag of methods — you skip writing a class entirely
|
|
188
|
+
- **Static block registration** reduces boilerplate for full class-based helpers — you still write the class, but registration is self-contained
|
|
189
|
+
|
|
190
|
+
For complex features that need class inheritance, lifecycle hooks, and full OOP — the static block pattern is cleaner. For simple features that are essentially a named collection of functions — `defineFeature()` is cleaner.
|
|
191
|
+
|
|
192
|
+
## Open Questions
|
|
193
|
+
|
|
194
|
+
- **Registry detection**: Can `Feature.register(this)` figure out which registry to use automatically? The base class (`Feature` vs `Client` vs `Server`) already implies it. A shared `Helper.register(this)` could dispatch to the right registry.
|
|
195
|
+
- **Module augmentation**: The `declare module` blocks for TypeScript are the remaining boilerplate that can't be eliminated by runtime mechanics. Could a codegen step or a TS plugin handle this?
|
|
196
|
+
- **Import side effects**: Today, importing a feature file triggers registration. With static blocks, this is still true — but the registration is more visible and intentional. Is there value in making registration lazy or explicit via `container.use()`?
|
|
197
|
+
- **`attach()` consolidation**: Many `attach()` methods just call `register()` and return the container. If `Feature.register()` generates a default `attach()`, do we still need custom ones? The ones that do more (like wiring up other features) would still override.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# COntainer `.use()` API
|
|
2
|
+
|
|
3
|
+
Can we find a way to support using dynamic imports
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
container.use(import("whatever))
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
these are promises, but the expectation is the default has an attach method. if not, any function or class they export which has an attach property
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Feature Stacks
|
|
2
|
+
|
|
3
|
+
The number of features in the node container is getting a little absurd.
|
|
4
|
+
|
|
5
|
+
We have the `container.use` API. We can bundle / group features like the google related ones into their own folder's and start to build on our plugin / layers concept
|
|
6
|
+
|
|
7
|
+
The startup time for the luca cli is getting slower and I'm wondering if it is all of these features causing it.
|
|
8
|
+
|
|
9
|
+
## Group features into folders
|
|
10
|
+
|
|
11
|
+
- don't autoload all of them, let's make it trivial like to load these features into scripts or commands
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import container from '@soederpop/luca/agi'
|
|
15
|
+
import GoogleFeatures from '@soederpop/luca/features/google'
|
|
16
|
+
|
|
17
|
+
container.use(GoogleFeatures)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Feature Marketplace ( long term )
|
|
21
|
+
|
|
22
|
+
Long term as I'm the only one using this shit, but the ability to publish a server that other containers could load features from is cool. We have all the pieces on the frontend ( asset loader ) to go from a blankpage to a fully functional SPA
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Luca CLI Self Sufficiency Demo
|
|
2
|
+
|
|
3
|
+
With the `luca` cli you can have a project folder like:
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
- public/
|
|
7
|
+
- index.html
|
|
8
|
+
- commands/
|
|
9
|
+
- setup-db.ts
|
|
10
|
+
- endpoints/
|
|
11
|
+
- health.ts
|
|
12
|
+
- docs/
|
|
13
|
+
- models.ts
|
|
14
|
+
- luca.cli.ts
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
This should work without there necessarily being a `node_modules` folder here, because each of these things are loaded by luca, transpiled, and run through the VM.
|
|
18
|
+
|
|
19
|
+
Even the `contentDb` feature which depends on contentbase should work here.
|
|
20
|
+
|
|
21
|
+
This is what I mean by luca being a dependency injection framework.
|
|
22
|
+
|
|
23
|
+
The only downside of this is - how do we provide type support without them installing '@soederpop/luca'
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# MCP Design
|
|
2
|
+
|
|
3
|
+
I have a hunch that the best way to get coding assistants to be aware of our MCP is to have as verbose of tool descriptions as the spec allows, as this seems to be the primary form of guidance.
|
|
4
|
+
|
|
5
|
+
One neat trick I learned from the excalidraw and other mcps is to have a tool_call called read_me, which we can probably really tune the tool description for, to make sure it gets called as early on as possible by the MCP, and as a way to further refine how it understands to use tool calls.
|
|
6
|
+
|
|
7
|
+
## Current State
|
|
8
|
+
|
|
9
|
+
We've got a `luca sandbox-mcp` command in this project which can be used to eval snippets of code inside the luca vm, as well as some other tools. Claude code consistently fails to use them, however.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Web Container Debugging Feature
|
|
2
|
+
|
|
3
|
+
How cool would it be if, from an application that uses WebContainer, we had a client side feature called `serverPlug`
|
|
4
|
+
|
|
5
|
+
The `serverPlug` would `connect` to a remote server over an API endpoint, to register itself, with info about the url it is on, its container's uuid. The server would respond with a websocket url and other necessary info.
|
|
6
|
+
|
|
7
|
+
On the server side `NodeContainer` there's server side `serverPlug` feature which can act as a host, that accepts registrations. It spawns its own websocket server to handle communication.
|
|
8
|
+
|
|
9
|
+
From server side code, I can connect to any individual web container instance, and eval code inside its vm.
|
|
10
|
+
|
|
11
|
+
We need to think about auth, disconnection events, heartbeats, etc
|
|
12
|
+
|
|
13
|
+
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Introspection Audit
|
|
2
|
+
|
|
3
|
+
This audit is a periodic test, does the introspectAsText output actually help an LLM use that
|
|
4
|
+
particular feature.
|
|
5
|
+
|
|
6
|
+
## Files
|
|
7
|
+
|
|
8
|
+
- `src/node/features/*.ts` NodeContainer features
|
|
9
|
+
- `src/agi/features/*.ts` AGIContainer features
|
|
10
|
+
|
|
11
|
+
## Your Task
|
|
12
|
+
|
|
13
|
+
For each feature, you can run the following shell command:
|
|
14
|
+
|
|
15
|
+
```shell
|
|
16
|
+
luca describe feature-id
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
This command will accept diskCache, disk-cache. Generally you want to go with the shortcut that is defined on the feature class.
|
|
20
|
+
|
|
21
|
+
Your job is to take what you learn from that command, and build an idea of 3-4 example usecases of that feature.
|
|
22
|
+
|
|
23
|
+
Compile all of this into a document in docs/reports/introspection-audit-tasks.md.
|
|
24
|
+
|
|
25
|
+
I'd like the following format
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
# Introspection Audit Results
|
|
29
|
+
|
|
30
|
+
## Features
|
|
31
|
+
|
|
32
|
+
### [diskCache](src/node/features/disk-cache.ts)
|
|
33
|
+
|
|
34
|
+
The purpose of this feature is to provided a consistent disk backed key-value store for large blobs and json objects. It includes the ability to have an encrypted store that can only be read with a secret.
|
|
35
|
+
|
|
36
|
+
- securely set / get a key across processes
|
|
37
|
+
- query information about available keys
|
|
38
|
+
- check if a key is present, if not write to it
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Do that for every feature.
|
|
42
|
+
|
|
43
|
+
## Next Steps
|
|
44
|
+
|
|
45
|
+
Once we have this report written, I will review the use cases and descriptions to see how accurate they are and if I like them.
|
|
46
|
+
|
|
47
|
+
Then we will have you attempt to eval your code and see if it works. If it doesn't, sugggest how the documentation could be improved or how the API might be improved.
|
|
48
|
+
|
|
49
|
+
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# Introspection
|
|
2
|
+
|
|
3
|
+
Luca's introspection system lets you discover everything about a container and its helpers at runtime. This document is a runnable demo — every code block works in the Luca REPL or as a script.
|
|
4
|
+
|
|
5
|
+
## Container Introspection
|
|
6
|
+
|
|
7
|
+
The container knows what it is, what registries it has, and what's available in each one.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const info = container.inspect()
|
|
11
|
+
console.log(info.className)
|
|
12
|
+
console.log(info.registries.map(r => `${r.name}: ${r.available.length} available`))
|
|
13
|
+
console.log('factories:', info.factoryNames)
|
|
14
|
+
console.log('enabled features:', info.enabledFeatures)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
You can get the full introspection as markdown:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
console.log(container.inspectAsText())
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Or request a single section:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
console.log(container.inspectAsText('methods'))
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
console.log(container.inspectAsText('getters'))
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Querying Registries
|
|
34
|
+
|
|
35
|
+
Every registry exposes what's available and can describe its members.
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
console.log('features:', container.features.available)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
console.log('clients:', container.clients.available)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
console.log('servers:', container.servers.available)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Describe a single member — returns markdown documentation derived from the code:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
console.log(container.features.describe('git'))
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Describe everything in a registry at once:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
const allFeatureDocs = container.features.describeAll()
|
|
59
|
+
console.log(`${allFeatureDocs.length} features documented`)
|
|
60
|
+
console.log(allFeatureDocs[0].slice(0, 200) + '...')
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Helper Introspection — Structured Data
|
|
64
|
+
|
|
65
|
+
Every helper instance (feature, client, server, etc.) can introspect itself. The result is a typed object you can traverse programmatically.
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
const git = container.feature('git')
|
|
69
|
+
const data = git.introspect()
|
|
70
|
+
console.log(data.id)
|
|
71
|
+
console.log(data.description.slice(0, 100) + '...')
|
|
72
|
+
console.log('methods:', Object.keys(data.methods))
|
|
73
|
+
console.log('getters:', Object.keys(data.getters))
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Filtering by Section
|
|
77
|
+
|
|
78
|
+
Pass a section name to get just that part:
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
const git = container.feature('git')
|
|
82
|
+
const methodsOnly = git.introspect('methods')
|
|
83
|
+
console.log(Object.keys(methodsOnly.methods))
|
|
84
|
+
console.log(Object.keys(methodsOnly.getters)) // empty — filtered out
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Valid sections: `'methods'`, `'getters'`, `'events'`, `'state'`, `'options'`.
|
|
88
|
+
|
|
89
|
+
### Expanded Type Properties
|
|
90
|
+
|
|
91
|
+
When a method parameter uses a custom type, introspection resolves it to show the type's members:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
const git = container.feature('git')
|
|
95
|
+
const lsFiles = git.introspect('methods').methods.lsFiles
|
|
96
|
+
console.log(lsFiles.parameters.options.type) // "LsFilesOptions"
|
|
97
|
+
console.log(lsFiles.parameters.options.properties)
|
|
98
|
+
// { cached: { type: 'boolean', description: 'Show cached/staged files' }, ... }
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Helper Introspection — As Text
|
|
102
|
+
|
|
103
|
+
Get the full markdown documentation for a helper:
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
const git = container.feature('git')
|
|
107
|
+
console.log(git.introspectAsText())
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Or just one section:
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
const git = container.feature('git')
|
|
114
|
+
console.log(git.introspectAsText('methods'))
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
const git = container.feature('git')
|
|
119
|
+
console.log(git.introspectAsText('getters'))
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The heading depth can be controlled — useful when embedding in larger documents:
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
const git = container.feature('git')
|
|
126
|
+
console.log(git.introspectAsText('methods', 3)) // headings start at ###
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Inspecting State and Options
|
|
130
|
+
|
|
131
|
+
Features that declare Zod schemas for state and options expose them through introspection:
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
const git = container.feature('git')
|
|
135
|
+
const stateInfo = git.introspect('state')
|
|
136
|
+
console.log(stateInfo.state)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
const ui = container.feature('ui')
|
|
141
|
+
const stateInfo = ui.introspect('state')
|
|
142
|
+
console.log(stateInfo.state)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Putting It Together
|
|
146
|
+
|
|
147
|
+
A quick way to survey everything the container offers:
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
for (const name of container.registryNames) {
|
|
151
|
+
const registry = container[name]
|
|
152
|
+
console.log(`\n${name}: ${registry.available.join(', ')}`)
|
|
153
|
+
}
|
|
154
|
+
```
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# Luca Development Guide
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
## The Contract
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+
## Import Rule
|
|
10
|
+
|
|
11
|
+
All consumer code imports from `@soederpop/luca` only:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { Feature, features, z, FeatureStateSchema, FeatureOptionsSchema } from '@soederpop/luca'
|
|
15
|
+
import { Client, clients, RestClient, ClientStateSchema } from '@soederpop/luca/client'
|
|
16
|
+
import { Server, servers, ServerStateSchema } from '@soederpop/luca'
|
|
17
|
+
import { commands, CommandOptionsSchema } from '@soederpop/luca'
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Never import from `fs`, `path`, `crypto`, or other Node builtins. Never import third-party packages in consumer code. The only exception is inside helper implementations themselves — a feature that wraps a library may import it.
|
|
21
|
+
|
|
22
|
+
## Zod v4
|
|
23
|
+
|
|
24
|
+
This project uses **Zod v4** — import `z` from `@soederpop/luca`, never from `'zod'` directly. All option, state, and event schemas use Zod v4 syntax. Key patterns:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
// Extending base schemas (options, state, events)
|
|
28
|
+
export const MyStateSchema = FeatureStateSchema.extend({
|
|
29
|
+
count: z.number().default(0).describe('Number of items'),
|
|
30
|
+
label: z.string().optional().describe('Display label'),
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
// Events use z.tuple() for listener arguments
|
|
34
|
+
export const MyEventsSchema = FeatureEventsSchema.extend({
|
|
35
|
+
itemAdded: z.tuple([z.string().describe('key'), z.number().describe('index')]),
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
// Type inference
|
|
39
|
+
export type MyState = z.infer<typeof MyStateSchema>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Zod v4 differences from v3 that matter:
|
|
43
|
+
- `z.string().check(...)` replaces some v3 refinement patterns
|
|
44
|
+
- `.toJSONSchema()` is built-in on any schema — no external library needed
|
|
45
|
+
- Error customization uses `z.string({ error: "message" })` not `.refine()` for simple cases
|
|
46
|
+
- `z.interface()` exists for recursive/lazy object types
|
|
47
|
+
- Do NOT use `z.nativeEnum()` — use `z.enum()` instead
|
|
48
|
+
|
|
49
|
+
## Dependencies
|
|
50
|
+
|
|
51
|
+
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 `@soederpop/luca`.
|
|
52
|
+
|
|
53
|
+
## Discovering Capabilities
|
|
54
|
+
|
|
55
|
+
The container has registries for features, clients, servers, commands, and endpoints. **Do not guess** what is available — use your MCP tools to discover it:
|
|
56
|
+
|
|
57
|
+
1. **`find_capability`** — Overview of all features, clients, and servers with descriptions. Start here.
|
|
58
|
+
2. **`list_registry`** — List all names in a specific registry (features, clients, servers, commands, endpoints).
|
|
59
|
+
3. **`describe_helper`** — Full API docs for a specific helper (methods, options, state, events). Call this before writing code that uses a helper.
|
|
60
|
+
4. **`eval`** — Once you know what you need, prototype calls in the live sandbox before writing them into files.
|
|
61
|
+
|
|
62
|
+
## Mini Examples
|
|
63
|
+
|
|
64
|
+
### Feature with composition
|
|
65
|
+
|
|
66
|
+
Features access other features via `this.container.feature(...)`:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { z } from 'zod'
|
|
70
|
+
import { FeatureStateSchema, FeatureOptionsSchema, FeatureEventsSchema } from '@soederpop/luca'
|
|
71
|
+
import { Feature, features } from '@soederpop/luca'
|
|
72
|
+
import type { ContainerContext } from '@soederpop/luca'
|
|
73
|
+
|
|
74
|
+
export const ConfigStateSchema = FeatureStateSchema.extend({
|
|
75
|
+
loaded: z.boolean().default(false).describe('Whether config has been loaded'),
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
export const ConfigOptionsSchema = FeatureOptionsSchema.extend({
|
|
79
|
+
filePath: z.string().default('config.json').describe('Path to config file'),
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
export const ConfigEventsSchema = FeatureEventsSchema.extend({
|
|
83
|
+
configLoaded: z.tuple([z.record(z.unknown()).describe('parsed config')]),
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
export class Config extends Feature<z.infer<typeof ConfigStateSchema>, z.infer<typeof ConfigOptionsSchema>> {
|
|
87
|
+
static override shortcut = 'features.config' as const
|
|
88
|
+
static override stateSchema = ConfigStateSchema
|
|
89
|
+
static override optionsSchema = ConfigOptionsSchema
|
|
90
|
+
static override eventsSchema = ConfigEventsSchema
|
|
91
|
+
static override description = 'Loads and manages project configuration'
|
|
92
|
+
|
|
93
|
+
/** Load and parse the config file */
|
|
94
|
+
async load() {
|
|
95
|
+
const fs = this.container.feature('fs')
|
|
96
|
+
const raw = await fs.readFile(this.options.filePath)
|
|
97
|
+
const data = JSON.parse(raw)
|
|
98
|
+
this.state.set('loaded', true)
|
|
99
|
+
this.emit('configLoaded', data)
|
|
100
|
+
return data
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
declare module '@soederpop/luca' {
|
|
105
|
+
interface AvailableFeatures { config: typeof Config }
|
|
106
|
+
}
|
|
107
|
+
export default features.register('config', Config)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Client with composition
|
|
111
|
+
|
|
112
|
+
Clients access features and other clients via `this.container`:
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
import { z } from 'zod'
|
|
116
|
+
import { Client, clients, ClientStateSchema, ClientOptionsSchema, ClientEventsSchema } from '@soederpop/luca'
|
|
117
|
+
import type { ContainerContext } from '@soederpop/luca'
|
|
118
|
+
|
|
119
|
+
export const GithubOptionsSchema = ClientOptionsSchema.extend({
|
|
120
|
+
token: z.string().describe('GitHub personal access token'),
|
|
121
|
+
owner: z.string().describe('Repository owner'),
|
|
122
|
+
repo: z.string().describe('Repository name'),
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
export const GithubEventsSchema = ClientEventsSchema.extend({
|
|
126
|
+
issuesFetched: z.tuple([z.number().describe('count')]),
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
export class GithubClient extends Client<z.infer<typeof ClientStateSchema>, z.infer<typeof GithubOptionsSchema>> {
|
|
130
|
+
static override shortcut = 'clients.github' as const
|
|
131
|
+
static override optionsSchema = GithubOptionsSchema
|
|
132
|
+
static override eventsSchema = GithubEventsSchema
|
|
133
|
+
static override description = 'GitHub API client using container REST client'
|
|
134
|
+
|
|
135
|
+
/** Fetch open issues */
|
|
136
|
+
async issues() {
|
|
137
|
+
const rest = this.container.client('rest')
|
|
138
|
+
const res = await rest.get(`https://api.github.com/repos/${this.options.owner}/${this.options.repo}/issues`, {
|
|
139
|
+
headers: { Authorization: `token ${this.options.token}` },
|
|
140
|
+
})
|
|
141
|
+
this.emit('issuesFetched', res.data.length)
|
|
142
|
+
return res.data
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
declare module '@soederpop/luca' {
|
|
147
|
+
interface AvailableClients { github: typeof GithubClient }
|
|
148
|
+
}
|
|
149
|
+
export default clients.register('github', GithubClient)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Workflow
|
|
153
|
+
|
|
154
|
+
1. **`find_capability`** — Search what already exists before writing anything
|
|
155
|
+
2. **`describe_helper`** — Read the full API docs for the helper you need
|
|
156
|
+
3. **`eval`** — Prototype and test container API calls in the sandbox
|
|
157
|
+
4. **`scaffold`** — Generate correct boilerplate when building something new
|
|
158
|
+
5. **Write the file** — Using the patterns from the scaffold
|
|
159
|
+
|
|
160
|
+
## Portability
|
|
161
|
+
|
|
162
|
+
Code that only imports from `@soederpop/luca` can be copied between any luca project. That's the goal. Features, clients, servers, and commands written this way are portable building blocks.
|
package/docs/models.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineModel,
|
|
3
|
+
section,
|
|
4
|
+
hasMany,
|
|
5
|
+
belongsTo,
|
|
6
|
+
AstQuery,
|
|
7
|
+
z,
|
|
8
|
+
} from "contentbase";
|
|
9
|
+
|
|
10
|
+
export const Idea = defineModel("Idea", {
|
|
11
|
+
prefix: "ideas",
|
|
12
|
+
meta: z.object({
|
|
13
|
+
goal: z.string().optional().describe("Slug of the goal this idea is aligned to"),
|
|
14
|
+
tags: z.array(z.string()).default([]).describe("Arbitrary tags for categorizing the idea"),
|
|
15
|
+
status: z.enum(["spark", "exploring", "parked", "promoted"]).default("spark").describe("spark is a new raw idea, exploring means actively thinking about it, parked means on hold, promoted means it became a plan"),
|
|
16
|
+
}),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export const Tutorial = defineModel("Tutorial", {
|
|
20
|
+
prefix: "tutorials",
|
|
21
|
+
meta: z.object({
|
|
22
|
+
tags: z.array(z.string()).default([]).describe("Arbitrary tags for categorizing the tutorial"),
|
|
23
|
+
}),
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
export const Report = defineModel("Report", {
|
|
27
|
+
prefix: "reports",
|
|
28
|
+
meta: z.object({
|
|
29
|
+
tags: z.array(z.string()).default([]).describe("Arbitrary tags for categorizing the report"),
|
|
30
|
+
}),
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
export const Example = defineModel("Example", {
|
|
34
|
+
prefix: "examples",
|
|
35
|
+
meta: z.object({
|
|
36
|
+
tags: z.array(z.string()).default([]).describe("Arbitrary tags for categorizing the example"),
|
|
37
|
+
}),
|
|
38
|
+
})
|