@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,85 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "grep"
|
|
3
|
+
tags: [grep, search, core]
|
|
4
|
+
lastTested: null
|
|
5
|
+
lastTestPassed: null
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# grep
|
|
9
|
+
|
|
10
|
+
Search file contents for patterns, find imports, definitions, and TODO comments.
|
|
11
|
+
|
|
12
|
+
## Overview
|
|
13
|
+
|
|
14
|
+
The `grep` feature is a core feature, auto-enabled on every container. You can access it directly as a global or via `container.feature('grep')`. It wraps ripgrep with a structured API, providing methods for pattern search, import discovery, definition lookup, and TODO scanning. Results come back as arrays of match objects with file, line, and content info.
|
|
15
|
+
|
|
16
|
+
## Searching for a Pattern
|
|
17
|
+
|
|
18
|
+
Use `search()` to find occurrences of a pattern across files. Options let you filter by file type, limit results, and control case sensitivity.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
const results = await grep.search({ pattern: 'container', include: '*.ts', exclude: 'node_modules', maxResults: 5 })
|
|
22
|
+
console.log('Matches for "container" in .ts files (first 5):')
|
|
23
|
+
results.forEach(r => {
|
|
24
|
+
console.log(` ${r.file}:${r.line} ${r.content.trim().slice(0, 60)}`)
|
|
25
|
+
})
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Each match object contains `file`, `line`, and `content` fields.
|
|
29
|
+
|
|
30
|
+
## Counting Matches
|
|
31
|
+
|
|
32
|
+
Use `count()` to get just the number of matches without fetching all the details.
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
const total = await grep.count('container', { include: '*.ts', exclude: 'node_modules' })
|
|
36
|
+
console.log('Total "container" occurrences in .ts files:', total)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
This is much faster when you only need the total.
|
|
40
|
+
|
|
41
|
+
## Finding Import Statements
|
|
42
|
+
|
|
43
|
+
Use `imports()` to find all files that import a specific module or path.
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
const results = await grep.imports('path', { include: '*.ts', exclude: 'node_modules', maxResults: 5 })
|
|
47
|
+
console.log('Files importing "path" (first 5):')
|
|
48
|
+
results.forEach(r => {
|
|
49
|
+
console.log(` ${r.file}:${r.line} ${r.content.trim().slice(0, 70)}`)
|
|
50
|
+
})
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
This searches for both `import` and `require` patterns automatically.
|
|
54
|
+
|
|
55
|
+
## Finding Definitions
|
|
56
|
+
|
|
57
|
+
Use `definitions()` to locate where functions, classes, types, or variables are defined.
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
const defs = await grep.definitions('Feature', { include: '*.ts', exclude: 'node_modules', maxResults: 5 })
|
|
61
|
+
console.log('Definitions matching "Feature" (first 5):')
|
|
62
|
+
defs.forEach(d => {
|
|
63
|
+
console.log(` ${d.file}:${d.line} ${d.content.trim().slice(0, 70)}`)
|
|
64
|
+
})
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
This searches for `function`, `class`, `type`, `interface`, `const`, and `let` declarations.
|
|
68
|
+
|
|
69
|
+
## Finding TODOs
|
|
70
|
+
|
|
71
|
+
Use `todos()` to scan for TODO, FIXME, HACK, and XXX comments across the codebase.
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
const todos = await grep.todos({ include: '*.ts', exclude: 'node_modules', maxResults: 5 })
|
|
75
|
+
console.log('TODOs found in .ts files (first 5):')
|
|
76
|
+
todos.forEach(t => {
|
|
77
|
+
console.log(` ${t.file}:${t.line} ${t.content.trim().slice(0, 70)}`)
|
|
78
|
+
})
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
This is handy for tracking technical debt and outstanding work items.
|
|
82
|
+
|
|
83
|
+
## Summary
|
|
84
|
+
|
|
85
|
+
This demo covered pattern searching with structured results, counting matches efficiently, finding import statements, locating definitions by name, and scanning for TODO comments. The `grep` feature is the go-to tool for codebase analysis and discovery.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Ink Blocks — Poor Man's MDX
|
|
2
|
+
|
|
3
|
+
This example demonstrates rendering rich terminal UI inline in a markdown document using ink blocks.
|
|
4
|
+
|
|
5
|
+
## Blocks
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
const { Box, Text } = ink.components
|
|
9
|
+
const React = ink.React
|
|
10
|
+
|
|
11
|
+
function Greeting({ name, role }) {
|
|
12
|
+
return (
|
|
13
|
+
<Box borderStyle="round" padding={1}>
|
|
14
|
+
<Text color="green" bold>Hello {name}!</Text>
|
|
15
|
+
<Text dimColor> ({role})</Text>
|
|
16
|
+
</Box>
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function StatusBar({ items }) {
|
|
21
|
+
return (
|
|
22
|
+
<Box flexDirection="row" gap={2}>
|
|
23
|
+
{items.map((item, i) =>
|
|
24
|
+
<Text key={i} color={item.ok ? 'green' : 'red'}>{item.label}</Text>
|
|
25
|
+
)}
|
|
26
|
+
</Box>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function DelayedMessage({ message, delay, done }) {
|
|
31
|
+
const [visible, setVisible] = React.useState(false)
|
|
32
|
+
|
|
33
|
+
React.useEffect(() => {
|
|
34
|
+
const timer = setTimeout(() => {
|
|
35
|
+
setVisible(true)
|
|
36
|
+
done()
|
|
37
|
+
}, delay || 500)
|
|
38
|
+
return () => clearTimeout(timer)
|
|
39
|
+
}, [])
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<Box>
|
|
43
|
+
<Text dimColor={!visible} color={visible ? 'cyan' : undefined}>
|
|
44
|
+
{visible ? message : 'Loading...'}
|
|
45
|
+
</Text>
|
|
46
|
+
</Box>
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Report
|
|
52
|
+
|
|
53
|
+
Let's greet the admin:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
await render('Greeting', { name: 'Jon', role: 'admin' })
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Now let's check the system status:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
await render('StatusBar', { items: [
|
|
63
|
+
{ label: 'API', ok: true },
|
|
64
|
+
{ label: 'DB', ok: false },
|
|
65
|
+
{ label: 'Cache', ok: true },
|
|
66
|
+
]})
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Now an async block that waits for a timer before rendering:
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
await renderAsync('DelayedMessage', { message: 'Data loaded successfully!', delay: 1000 })
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
All done. Blocks rendered inline with the document flow.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Feature Registry
|
|
2
|
+
|
|
3
|
+
## Blocks
|
|
4
|
+
|
|
5
|
+
```tsx
|
|
6
|
+
const { Box, Text } = ink.components
|
|
7
|
+
const React = ink.React
|
|
8
|
+
|
|
9
|
+
function Table({ rows, columns }) {
|
|
10
|
+
const colWidth = Math.floor(70 / columns)
|
|
11
|
+
|
|
12
|
+
const chunked = []
|
|
13
|
+
for (let i = 0; i < rows.length; i += columns) {
|
|
14
|
+
chunked.push(rows.slice(i, i + columns))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<Box flexDirection="column">
|
|
19
|
+
<Box borderStyle="single" paddingX={1}>
|
|
20
|
+
<Text bold color="cyan">Available Features</Text>
|
|
21
|
+
</Box>
|
|
22
|
+
{chunked.map((row, ri) => (
|
|
23
|
+
<Box key={ri} flexDirection="row">
|
|
24
|
+
{row.map((item, ci) => (
|
|
25
|
+
<Box key={ci} width={colWidth} paddingX={1}>
|
|
26
|
+
<Text color="green">{item}</Text>
|
|
27
|
+
</Box>
|
|
28
|
+
))}
|
|
29
|
+
</Box>
|
|
30
|
+
))}
|
|
31
|
+
</Box>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Features
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
const features = container.features.available
|
|
40
|
+
await render('Table', { rows: features, columns: 3 })
|
|
41
|
+
```
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Ink"
|
|
3
|
+
tags: [ink, react, terminal, ui, components]
|
|
4
|
+
lastTested: null
|
|
5
|
+
lastTestPassed: null
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# ink
|
|
9
|
+
|
|
10
|
+
React-powered terminal UI via the Ink library. Build rich, interactive command-line interfaces using React components that render directly in the terminal.
|
|
11
|
+
|
|
12
|
+
## Overview
|
|
13
|
+
|
|
14
|
+
The `ink` feature exposes the Ink library (React for CLIs) through the container. It provides access to React itself, all Ink components (Box, Text, Spacer, etc.), all Ink hooks (useInput, useApp, useFocus, etc.), and a render/unmount lifecycle. Because Ink renders an interactive React tree in the terminal, it cannot be fully demonstrated in a non-interactive markdown runner. Runnable blocks cover setup and introspection; actual rendering is shown in skip blocks.
|
|
15
|
+
|
|
16
|
+
## Enabling the Feature
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
const ink = container.feature('ink', { enable: true })
|
|
20
|
+
console.log('Ink enabled:', ink.state.get('enabled'))
|
|
21
|
+
console.log('Currently mounted:', ink.isMounted)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Exploring the API
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
const docs = container.features.describe('ink')
|
|
28
|
+
console.log(docs)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Loading Modules
|
|
32
|
+
|
|
33
|
+
The `loadModules` method pre-loads React and Ink so that the sync getters work immediately.
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
const ink = container.feature('ink', { enable: true })
|
|
37
|
+
await ink.loadModules()
|
|
38
|
+
const componentNames = Object.keys(ink.components)
|
|
39
|
+
const hookNames = Object.keys(ink.hooks)
|
|
40
|
+
console.log('Components:', componentNames.join(', '))
|
|
41
|
+
console.log('Hooks:', hookNames.join(', '))
|
|
42
|
+
console.log('React available:', typeof ink.React.createElement)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Rendering a Component
|
|
46
|
+
|
|
47
|
+
Mount a React element to the terminal using `React.createElement`.
|
|
48
|
+
|
|
49
|
+
```ts skip
|
|
50
|
+
const { Box, Text } = ink.components
|
|
51
|
+
const { React } = ink
|
|
52
|
+
|
|
53
|
+
ink.render(
|
|
54
|
+
React.createElement(Box, { flexDirection: 'column' },
|
|
55
|
+
React.createElement(Text, { color: 'green' }, 'Hello from Ink'),
|
|
56
|
+
React.createElement(Text, { dimColor: true }, 'Powered by Luca')
|
|
57
|
+
)
|
|
58
|
+
)
|
|
59
|
+
await ink.waitUntilExit()
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The `render` method mounts the React tree and starts the Ink render loop. `waitUntilExit` returns a promise that resolves when the app exits (via `useApp().exit()` or `unmount()`).
|
|
63
|
+
|
|
64
|
+
## Using Hooks
|
|
65
|
+
|
|
66
|
+
Ink hooks like `useInput` and `useFocus` work inside functional components passed to `render`.
|
|
67
|
+
|
|
68
|
+
```ts skip
|
|
69
|
+
const { Text } = ink.components
|
|
70
|
+
const { React } = ink
|
|
71
|
+
const { useInput, useApp } = ink.hooks
|
|
72
|
+
|
|
73
|
+
function App() {
|
|
74
|
+
const { exit } = useApp()
|
|
75
|
+
useInput((input, key) => {
|
|
76
|
+
if (input === 'q') exit()
|
|
77
|
+
})
|
|
78
|
+
return React.createElement(Text, null, 'Press q to quit')
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
ink.render(React.createElement(App))
|
|
82
|
+
await ink.waitUntilExit()
|
|
83
|
+
console.log('App exited')
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Unmounting and Cleanup
|
|
87
|
+
|
|
88
|
+
Tear down the rendered app and clear terminal output.
|
|
89
|
+
|
|
90
|
+
```ts skip
|
|
91
|
+
ink.render(
|
|
92
|
+
React.createElement(ink.components.Text, null, 'Temporary UI')
|
|
93
|
+
)
|
|
94
|
+
ink.clear()
|
|
95
|
+
ink.unmount()
|
|
96
|
+
console.log('Mounted after unmount:', ink.isMounted)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The `clear` method erases all Ink-rendered content from the terminal. The `unmount` method tears down the React tree. Both are safe to call when no app is mounted.
|
|
100
|
+
|
|
101
|
+
## Summary
|
|
102
|
+
|
|
103
|
+
The `ink` feature brings React-based terminal UIs to Luca scripts. It provides the full Ink component and hook library, a render lifecycle with mount/unmount/rerender, and access to the React module itself. Best suited for interactive CLI tools and dashboards.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "IPC Socket"
|
|
3
|
+
tags: [ipcSocket, ipc, unix-socket, messaging]
|
|
4
|
+
lastTested: null
|
|
5
|
+
lastTestPassed: null
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# ipcSocket
|
|
9
|
+
|
|
10
|
+
Inter-process communication via Unix domain sockets. Supports both server and client modes with JSON message serialization, broadcast messaging, and event-driven message handling.
|
|
11
|
+
|
|
12
|
+
## Overview
|
|
13
|
+
|
|
14
|
+
The `ipcSocket` feature enables processes to communicate through file-system-based Unix domain sockets. A server listens on a socket path and accepts multiple client connections. Messages are automatically JSON-encoded with unique IDs. Both server and client emit `message` events for incoming data. Because IPC requires coordinating two processes (server and client), all socket operation examples use skip blocks.
|
|
15
|
+
|
|
16
|
+
## Enabling the Feature
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
const ipc = container.feature('ipcSocket', { enable: true })
|
|
20
|
+
console.log('IPC Socket enabled:', ipc.state.get('enabled'))
|
|
21
|
+
console.log('Current mode:', ipc.state.get('mode'))
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Exploring the API
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
const docs = container.features.describe('ipcSocket')
|
|
28
|
+
console.log(docs)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Checking Mode
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
const ipc = container.feature('ipcSocket')
|
|
35
|
+
console.log('Is server:', ipc.isServer)
|
|
36
|
+
console.log('Is client:', ipc.isClient)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Starting a Server
|
|
40
|
+
|
|
41
|
+
Listen on a Unix domain socket and handle incoming connections.
|
|
42
|
+
|
|
43
|
+
```ts skip
|
|
44
|
+
const server = await ipc.listen('/tmp/myapp.sock', true)
|
|
45
|
+
console.log('Server listening')
|
|
46
|
+
|
|
47
|
+
ipc.on('connection', (socket) => {
|
|
48
|
+
console.log('Client connected')
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
ipc.on('message', (data) => {
|
|
52
|
+
console.log('Received:', data)
|
|
53
|
+
ipc.broadcast({ reply: 'ACK', original: data })
|
|
54
|
+
})
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The second argument `true` removes any stale socket file before binding. Without it, the call throws if the socket file already exists.
|
|
58
|
+
|
|
59
|
+
## Connecting a Client
|
|
60
|
+
|
|
61
|
+
Connect to an existing server and exchange messages.
|
|
62
|
+
|
|
63
|
+
```ts skip
|
|
64
|
+
const socket = await ipc.connect('/tmp/myapp.sock')
|
|
65
|
+
console.log('Connected to server')
|
|
66
|
+
|
|
67
|
+
ipc.on('message', (data) => {
|
|
68
|
+
console.log('Server says:', data)
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
ipc.send({ type: 'hello', clientId: 'worker-1' })
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Messages sent via `ipc.send()` are automatically wrapped with a unique ID for tracking. The server receives the original data in the `message` event.
|
|
75
|
+
|
|
76
|
+
## Broadcasting Messages
|
|
77
|
+
|
|
78
|
+
Send a message to all connected clients from the server.
|
|
79
|
+
|
|
80
|
+
```ts skip
|
|
81
|
+
ipc.broadcast({
|
|
82
|
+
type: 'notification',
|
|
83
|
+
message: 'Deployment starting',
|
|
84
|
+
timestamp: Date.now()
|
|
85
|
+
})
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Each connected client receives the broadcast as a `message` event. Messages are JSON-encoded with a UUID for correlation.
|
|
89
|
+
|
|
90
|
+
## Stopping the Server
|
|
91
|
+
|
|
92
|
+
Gracefully shut down the server and disconnect all clients.
|
|
93
|
+
|
|
94
|
+
```ts skip
|
|
95
|
+
await ipc.stopServer()
|
|
96
|
+
console.log('Server stopped')
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The `stopServer` method closes the listener, destroys all active client connections, and resets internal state.
|
|
100
|
+
|
|
101
|
+
## Summary
|
|
102
|
+
|
|
103
|
+
The `ipcSocket` feature provides Unix domain socket IPC with JSON message serialization, multi-client support, broadcast messaging, and automatic socket cleanup. It works in either server or client mode within a single feature instance.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "JSON Tree"
|
|
3
|
+
tags: [jsonTree, json, files, data-loading]
|
|
4
|
+
lastTested: null
|
|
5
|
+
lastTestPassed: null
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# jsonTree
|
|
9
|
+
|
|
10
|
+
Load JSON files from directory structures into a nested object tree.
|
|
11
|
+
|
|
12
|
+
## Overview
|
|
13
|
+
|
|
14
|
+
The `jsonTree` feature is an on-demand feature that recursively scans a directory for `.json` files and builds a hierarchical JavaScript object from them. File paths are converted to camelCased property paths, so `config/database/production.json` becomes `tree.config.database.production`. This is useful when your project stores structured data across many JSON files and you want to access it all through a single unified object.
|
|
15
|
+
|
|
16
|
+
## Feature Documentation
|
|
17
|
+
|
|
18
|
+
Let us inspect the feature's built-in documentation.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
const desc = container.features.describe('jsonTree')
|
|
22
|
+
console.log(desc)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The key method is `loadTree(basePath, key?)` which scans a directory and populates the `tree` getter.
|
|
26
|
+
|
|
27
|
+
## Enabling the Feature
|
|
28
|
+
|
|
29
|
+
Enable jsonTree and check its initial state.
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
const jsonTree = container.feature('jsonTree', { enable: true })
|
|
33
|
+
console.log('jsonTree enabled:', jsonTree.state.enabled)
|
|
34
|
+
console.log('Initial tree:', JSON.stringify(jsonTree.tree))
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The tree starts empty until you load directories into it.
|
|
38
|
+
|
|
39
|
+
## How loadTree Works
|
|
40
|
+
|
|
41
|
+
The `loadTree(basePath, key?)` method recursively scans a directory for `.json` files, parses each one, and builds a nested object from the file paths. The optional `key` parameter controls where in the tree the data is stored.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
console.log('loadTree processing steps:')
|
|
45
|
+
console.log(' 1. Scans basePath recursively for *.json files')
|
|
46
|
+
console.log(' 2. Reads and parses each file with JSON.parse()')
|
|
47
|
+
console.log(' 3. Converts file paths to camelCased property paths')
|
|
48
|
+
console.log(' 4. Stores the result under the given key in feature state')
|
|
49
|
+
console.log('')
|
|
50
|
+
console.log('Example call: await jsonTree.loadTree("config", "appConfig")')
|
|
51
|
+
console.log(' config/db/prod.json => jsonTree.tree.appConfig.db.prod')
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
After calling `loadTree`, the data is accessible through the `tree` getter, which returns all loaded trees minus internal state properties.
|
|
55
|
+
|
|
56
|
+
## Inspecting the Tree Getter
|
|
57
|
+
|
|
58
|
+
The `tree` getter provides clean access to loaded data. Before any data is loaded, it returns an empty object.
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
console.log('Tree before loading:', JSON.stringify(jsonTree.tree))
|
|
62
|
+
console.log('Tree type:', typeof jsonTree.tree)
|
|
63
|
+
console.log('Tree is clean (no "enabled" key):', !('enabled' in jsonTree.tree))
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The getter filters out the internal `enabled` state property so you only see your loaded JSON data.
|
|
67
|
+
|
|
68
|
+
## Path Transformation Rules
|
|
69
|
+
|
|
70
|
+
The feature applies consistent transformations when building the tree:
|
|
71
|
+
|
|
72
|
+
- Directory names become nested object properties
|
|
73
|
+
- File names (without `.json`) become leaf properties
|
|
74
|
+
- All names are converted to camelCase
|
|
75
|
+
- Hyphens and dots in names are handled by the camelCase conversion
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
// Conceptual example of path mapping:
|
|
79
|
+
const mappings = {
|
|
80
|
+
'config/database/production.json': 'tree.config.database.production',
|
|
81
|
+
'data/user-profiles.json': 'tree.data.userProfiles',
|
|
82
|
+
'settings/app-config.json': 'tree.settings.appConfig',
|
|
83
|
+
}
|
|
84
|
+
for (const [file, path] of Object.entries(mappings)) {
|
|
85
|
+
console.log(`${file} => ${path}`)
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Summary
|
|
90
|
+
|
|
91
|
+
This demo covered the `jsonTree` feature, which scans directories for JSON files and builds a nested object tree from them. File paths are transformed into camelCased property paths, making it easy to access deeply nested configuration or data files through a single unified interface.
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Launcher App Command Listener"
|
|
3
|
+
tags: [launcherAppCommandListener, ipc, macos, voice, commands]
|
|
4
|
+
lastTested: null
|
|
5
|
+
lastTestPassed: null
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# launcherAppCommandListener
|
|
9
|
+
|
|
10
|
+
IPC transport for receiving commands from the LucaVoiceLauncher macOS app. Listens on a Unix domain socket using NDJSON and wraps incoming commands in a `CommandHandle` for structured acknowledgement, progress, and completion.
|
|
11
|
+
|
|
12
|
+
## Overview
|
|
13
|
+
|
|
14
|
+
Use the `launcherAppCommandListener` feature when you need to receive and process commands from the native macOS launcher app (voice commands, hotkeys, or text input). It provides the server side of the IPC protocol: listen for the app to connect, receive command events, and respond with acknowledgements, progress updates, and results.
|
|
15
|
+
|
|
16
|
+
Requires the LucaVoiceLauncher native macOS app to be running.
|
|
17
|
+
|
|
18
|
+
## Enabling the Feature
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
const listener = container.feature('launcherAppCommandListener', {
|
|
22
|
+
autoListen: false
|
|
23
|
+
})
|
|
24
|
+
console.log('Command Listener feature created')
|
|
25
|
+
console.log('Listening:', listener.isListening)
|
|
26
|
+
console.log('Client connected:', listener.isClientConnected)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## API Documentation
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
const info = await container.features.describe('launcherAppCommandListener')
|
|
33
|
+
console.log(info)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Listening for Commands
|
|
37
|
+
|
|
38
|
+
Start the IPC server and handle incoming commands with the `CommandHandle` API.
|
|
39
|
+
|
|
40
|
+
```ts skip
|
|
41
|
+
const listener = container.feature('launcherAppCommandListener', {
|
|
42
|
+
autoListen: true
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
listener.on('command', async (cmd) => {
|
|
46
|
+
console.log('Received command:', cmd.text)
|
|
47
|
+
|
|
48
|
+
cmd.ack('Working on it!')
|
|
49
|
+
// ... process the command ...
|
|
50
|
+
cmd.progress(0.5, 'Halfway there')
|
|
51
|
+
// ... finish processing ...
|
|
52
|
+
cmd.finish({ result: { action: 'completed' }, speech: 'All done!' })
|
|
53
|
+
})
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Each incoming command is wrapped in a `CommandHandle` that provides `ack()`, `progress()`, `finish()`, and `fail()` methods. The native app displays acknowledgements and speaks the `speech` text.
|
|
57
|
+
|
|
58
|
+
## Command Handle Lifecycle
|
|
59
|
+
|
|
60
|
+
The `CommandHandle` follows a structured lifecycle: acknowledge, optionally report progress, then finish or fail.
|
|
61
|
+
|
|
62
|
+
```ts skip
|
|
63
|
+
listener.on('command', async (cmd) => {
|
|
64
|
+
// Silent acknowledge
|
|
65
|
+
cmd.ack()
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
// Report progress (0-1 scale)
|
|
69
|
+
cmd.progress(0.25, 'Starting...')
|
|
70
|
+
cmd.progress(0.75, 'Almost done...')
|
|
71
|
+
|
|
72
|
+
// Finish with result and optional speech
|
|
73
|
+
cmd.finish({
|
|
74
|
+
result: { data: 'some result' },
|
|
75
|
+
speech: 'Task completed successfully'
|
|
76
|
+
})
|
|
77
|
+
} catch (err) {
|
|
78
|
+
// Report failure with optional speech
|
|
79
|
+
cmd.fail({
|
|
80
|
+
error: err.message,
|
|
81
|
+
speech: 'Sorry, that failed.'
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The native app uses the `speech` field for text-to-speech feedback to the user.
|
|
88
|
+
|
|
89
|
+
## Connection Events
|
|
90
|
+
|
|
91
|
+
Monitor the IPC connection state.
|
|
92
|
+
|
|
93
|
+
```ts skip
|
|
94
|
+
listener.on('listening', () => {
|
|
95
|
+
console.log('IPC server listening on:', listener.state.socketPath)
|
|
96
|
+
})
|
|
97
|
+
listener.on('clientConnected', () => {
|
|
98
|
+
console.log('Launcher app connected')
|
|
99
|
+
})
|
|
100
|
+
listener.on('clientDisconnected', () => {
|
|
101
|
+
console.log('Launcher app disconnected')
|
|
102
|
+
})
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
The `clientConnected` and `clientDisconnected` events fire as the native app connects and disconnects from the socket.
|
|
106
|
+
|
|
107
|
+
## Sending Messages
|
|
108
|
+
|
|
109
|
+
Send arbitrary NDJSON messages back to the connected app.
|
|
110
|
+
|
|
111
|
+
```ts skip
|
|
112
|
+
listener.send({ status: 'ready', message: 'Luca is online' })
|
|
113
|
+
listener.send({ notification: 'Task queue empty' })
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Use `send()` for custom protocol messages beyond the standard command lifecycle.
|
|
117
|
+
|
|
118
|
+
## Summary
|
|
119
|
+
|
|
120
|
+
The `launcherAppCommandListener` feature provides the IPC server for the LucaVoiceLauncher app. It receives voice, hotkey, and text commands, wrapping each in a `CommandHandle` with structured lifecycle methods (ack, progress, finish, fail). Key methods: `listen()`, `stop()`, `send()`. Key events: `command`, `clientConnected`, `clientDisconnected`.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "networking"
|
|
3
|
+
tags: [networking, ports, network, core]
|
|
4
|
+
lastTested: null
|
|
5
|
+
lastTestPassed: null
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# networking
|
|
9
|
+
|
|
10
|
+
Port discovery and availability checking for network services.
|
|
11
|
+
|
|
12
|
+
## Overview
|
|
13
|
+
|
|
14
|
+
The `networking` feature is a core feature, auto-enabled on every container. You can access it directly as a global or via `container.feature('networking')`. It provides async methods for finding available ports and checking whether a given port is already in use. Use it before starting servers to avoid port conflicts.
|
|
15
|
+
|
|
16
|
+
## Finding an Open Port
|
|
17
|
+
|
|
18
|
+
Use `findOpenPort()` to get the next available port starting from a given number. If the requested port is taken, it searches upward.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
const port = await networking.findOpenPort(3000)
|
|
22
|
+
console.log('Available port starting from 3000:', port)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
If port 3000 is free, you get 3000 back. If not, you get the next one that is.
|
|
26
|
+
|
|
27
|
+
## Checking Port Availability
|
|
28
|
+
|
|
29
|
+
Use `isPortOpen()` to check whether a specific port is available without claiming it.
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
const is3000Open = await networking.isPortOpen(3000)
|
|
33
|
+
console.log('Port 3000 available:', is3000Open)
|
|
34
|
+
|
|
35
|
+
const is80Open = await networking.isPortOpen(80)
|
|
36
|
+
console.log('Port 80 available:', is80Open)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Returns `true` if the port is free, `false` if something is already listening on it.
|
|
40
|
+
|
|
41
|
+
## Finding Multiple Ports
|
|
42
|
+
|
|
43
|
+
You can call `findOpenPort()` with different starting points to allocate several non-conflicting ports for a multi-service setup.
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
const apiPort = await networking.findOpenPort(8080)
|
|
47
|
+
const wsPort = await networking.findOpenPort(8090)
|
|
48
|
+
const devPort = await networking.findOpenPort(5173)
|
|
49
|
+
console.log('API server port:', apiPort)
|
|
50
|
+
console.log('WebSocket port:', wsPort)
|
|
51
|
+
console.log('Dev server port:', devPort)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Each call independently finds the next available port from its starting point.
|
|
55
|
+
|
|
56
|
+
## Summary
|
|
57
|
+
|
|
58
|
+
This demo covered finding available ports from a starting number, checking individual port availability, and allocating multiple ports for multi-service architectures. The `networking` feature eliminates port conflicts before they happen.
|