everything-gemini 1.1.1 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/ISSUE_TEMPLATE/bug_report.md +29 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +27 -0
- package/.github/ISSUE_TEMPLATE/subagent_proposal.md +29 -0
- package/.github/workflows/ci.yml +72 -1
- package/.github/workflows/release.yml +17 -2
- package/.vscode/extensions.json +8 -0
- package/.vscode/settings.json +3 -0
- package/CHANGELOG.md +167 -0
- package/CONTRIBUTING.md +85 -4
- package/README.md +139 -18
- package/SECURITY.md +38 -0
- package/action.yml +35 -0
- package/agents/browser-qa.md +1 -1
- package/agents/database-migrator.md +26 -0
- package/agents/documentation-writer.md +27 -0
- package/agents/incident-responder.md +34 -0
- package/agents/performance-tuner.md +27 -0
- package/agents/release-engineer.md +34 -0
- package/bin/everything-gemini +1550 -86
- package/docs/COMMUNITY_SUBMISSIONS.md +88 -0
- package/docs/LAUNCH_KIT.md +148 -22
- package/docs/architecture/progressive-disclosure.md +3 -3
- package/docs/index.html +401 -37
- package/docs/launch-kit.md +163 -0
- package/examples/cli-workflows/README.md +45 -0
- package/examples/cli-workflows/demo_workflow.sh +39 -0
- package/examples/python-sdk/README.md +28 -5
- package/examples/python-sdk/documentation_audit_pipeline.py +83 -0
- package/examples/python-sdk/incident_triage_pipeline.py +170 -0
- package/examples/python-sdk/multi_agent_pipeline.py +95 -0
- package/examples/python-sdk/release_readiness_audit.py +144 -0
- package/hooks/secret-scrubber/hooks.json +16 -0
- package/hooks/secret-scrubber/scripts/scrub-secrets.sh +62 -0
- package/mcp/README.md +20 -0
- package/mcp/mcp_config.example.json +35 -0
- package/package.json +3 -1
- package/plugins/core/rules/core-practices.md +63 -4
- package/plugins/python-ai/rules/ai-agent-patterns.md +67 -4
- package/plugins/security-shield/rules/zero-trust.md +60 -4
- package/plugins/web-fullstack/rules/frontend-standards.md +74 -4
- package/rules/paradigms/security-hardened.md +53 -10
- package/rules/paradigms/tdd.md +65 -8
- package/scripts/install.ps1 +14 -0
- package/scripts/install.sh +15 -1
- package/scripts/validate.sh +103 -12
- package/skills/agent-evals/SKILL.md +61 -0
- package/skills/apache-kafka-streams/SKILL.md +152 -0
- package/skills/argo-workflows/SKILL.md +151 -0
- package/skills/axum-web-service/SKILL.md +159 -0
- package/skills/cilium-ebpf-networking/SKILL.md +145 -0
- package/skills/clickhouse-analytics/SKILL.md +128 -0
- package/skills/dbt-transformation/SKILL.md +179 -0
- package/skills/debezium-cdc/SKILL.md +166 -0
- package/skills/docker-compose-orchestrator/SKILL.md +85 -0
- package/skills/duckdb-local-olap/SKILL.md +134 -0
- package/skills/fastapi-production/SKILL.md +157 -0
- package/skills/graphql-architect/SKILL.md +78 -0
- package/skills/grpc-connect-rpc/SKILL.md +176 -0
- package/skills/langgraph-orchestrator/SKILL.md +144 -0
- package/skills/litellm-proxy-gateway/SKILL.md +154 -0
- package/skills/nats-jetstream/SKILL.md +122 -0
- package/skills/open-telemetry-tracing/SKILL.md +151 -0
- package/skills/playwright-visual-regression/SKILL.md +124 -0
- package/skills/redis-cache-patterns/SKILL.md +159 -0
- package/skills/svelte-kit-architect/SKILL.md +190 -0
- package/skills/temporal-workflows/SKILL.md +158 -0
- package/skills/trpc-react-query/SKILL.md +169 -0
- package/skills/turborepo-monorepo/SKILL.md +199 -0
- package/skills/vllm-inference/SKILL.md +144 -0
- package/skills/wasm-rust-optimizer/SKILL.md +130 -0
- package/templates/full-power/hooks.json +14 -0
- package/templates/full-power/mcp_config.json +43 -0
- package/templates/recommended/hooks.json +14 -0
- package/tests/cli.test.js +383 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: turborepo-monorepo
|
|
3
|
+
description: >-
|
|
4
|
+
Architects, configures, and optimizes high-performance monorepo build systems using Turborepo, fine-grained task pipelines (turbo.json), remote caching, package boundary isolation, and Docker pruning.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Turborepo Monorepo Architecture & Task Pipelines
|
|
8
|
+
|
|
9
|
+
This skill guides structuring, optimizing, and maintaining multi-package JavaScript/TypeScript monorepos with Turborepo, leveraging incremental computation, hash-based task caching, remote cache synchronization, and isolated Docker container pruning.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## ⚡ Core Patterns
|
|
14
|
+
|
|
15
|
+
### 1. Production `turbo.json` Pipeline Specification
|
|
16
|
+
|
|
17
|
+
Define task dependencies, input hashes, cache retention, and environment variable tracking in root `turbo.json`:
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"$schema": "https://turbo.build/schema.json",
|
|
22
|
+
"ui": "tui",
|
|
23
|
+
"tasks": {
|
|
24
|
+
"topo": {
|
|
25
|
+
"dependsOn": ["^topo"]
|
|
26
|
+
},
|
|
27
|
+
"build": {
|
|
28
|
+
"dependsOn": ["^build"],
|
|
29
|
+
"inputs": ["$TURBO_DEFAULT$", ".env*", "!**/*.test.*"],
|
|
30
|
+
"outputs": [".next/**", "!.next/cache/**", "dist/**", "build/**"],
|
|
31
|
+
"env": ["NODE_ENV", "NEXT_PUBLIC_*", "API_BASE_URL"]
|
|
32
|
+
},
|
|
33
|
+
"test": {
|
|
34
|
+
"dependsOn": ["build"],
|
|
35
|
+
"inputs": ["src/**/*.tsx", "src/**/*.ts", "test/**/*.ts"],
|
|
36
|
+
"outputs": ["coverage/**"]
|
|
37
|
+
},
|
|
38
|
+
"lint": {
|
|
39
|
+
"dependsOn": ["^topo"],
|
|
40
|
+
"outputs": []
|
|
41
|
+
},
|
|
42
|
+
"dev": {
|
|
43
|
+
"cache": false,
|
|
44
|
+
"persistent": true
|
|
45
|
+
},
|
|
46
|
+
"typecheck": {
|
|
47
|
+
"dependsOn": ["^build"],
|
|
48
|
+
"outputs": []
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"globalEnv": ["CI", "PORT"],
|
|
52
|
+
"globalDependencies": [
|
|
53
|
+
"tsconfig.base.json",
|
|
54
|
+
".eslintrc.js",
|
|
55
|
+
"pnpm-lock.yaml"
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
### 2. Monorepo Workspace Directory Structure
|
|
63
|
+
|
|
64
|
+
Maintain strict package boundaries between deployable applications (`apps/*`) and shared internal libraries (`packages/*`):
|
|
65
|
+
|
|
66
|
+
```text
|
|
67
|
+
my-monorepo/
|
|
68
|
+
├── apps/
|
|
69
|
+
│ ├── web/ # Next.js / SvelteKit / React SPA
|
|
70
|
+
│ │ ├── package.json
|
|
71
|
+
│ │ └── tsconfig.json
|
|
72
|
+
│ └── api/ # Node.js / Express / Nest / Fastify
|
|
73
|
+
│ ├── package.json
|
|
74
|
+
│ └── tsconfig.json
|
|
75
|
+
├── packages/
|
|
76
|
+
│ ├── ui/ # Shared React design system
|
|
77
|
+
│ ├── database/ # Drizzle / Prisma / SQL migrations
|
|
78
|
+
│ ├── config-eslint/ # Internal shared ESLint rules
|
|
79
|
+
│ └── config-typescript/ # tsconfig.base.json definitions
|
|
80
|
+
├── turbo.json # Pipeline DAG orchestration
|
|
81
|
+
├── pnpm-workspace.yaml # Package manager workspaces
|
|
82
|
+
└── package.json # Root scripts and dev dependencies
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
### 3. Internal Package Definition with `package.json` Exports
|
|
88
|
+
|
|
89
|
+
Configure shared internal libraries using modern TypeScript `exports` without premature bundler compilation:
|
|
90
|
+
|
|
91
|
+
```json
|
|
92
|
+
{
|
|
93
|
+
"name": "@workspace/ui",
|
|
94
|
+
"version": "0.1.0",
|
|
95
|
+
"private": true,
|
|
96
|
+
"type": "module",
|
|
97
|
+
"exports": {
|
|
98
|
+
"./button": {
|
|
99
|
+
"types": "./src/button.tsx",
|
|
100
|
+
"default": "./src/button.tsx"
|
|
101
|
+
},
|
|
102
|
+
"./theme": {
|
|
103
|
+
"types": "./src/theme.ts",
|
|
104
|
+
"default": "./src/theme.ts"
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
"scripts": {
|
|
108
|
+
"lint": "eslint src/",
|
|
109
|
+
"typecheck": "tsc --noEmit"
|
|
110
|
+
},
|
|
111
|
+
"devDependencies": {
|
|
112
|
+
"@workspace/config-typescript": "workspace:*",
|
|
113
|
+
"typescript": "^5.4.0"
|
|
114
|
+
},
|
|
115
|
+
"peerDependencies": {
|
|
116
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
### 4. Remote Caching & CI/CD Acceleration
|
|
124
|
+
|
|
125
|
+
Enable zero-redundancy CI builds with Vercel or self-hosted Remote Cache (e.g. AWS S3 or MinIO):
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
# 1. Authenticate with remote cache provider
|
|
129
|
+
npx turbo login
|
|
130
|
+
|
|
131
|
+
# 2. Link repository to team space
|
|
132
|
+
npx turbo link
|
|
133
|
+
|
|
134
|
+
# 3. In CI environments, provide token and team identifier via environment
|
|
135
|
+
export TURBO_TOKEN="your-cache-secret-token"
|
|
136
|
+
export TURBO_TEAM="your-team-slug"
|
|
137
|
+
|
|
138
|
+
# 4. Run targeted pipeline with cache hit verification
|
|
139
|
+
turbo run build test lint --filter=...[origin/main]
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
### 5. Multi-Stage Docker Build Optimization via `turbo prune`
|
|
145
|
+
|
|
146
|
+
Generate a minimal build context containing only the target application and its direct internal dependencies:
|
|
147
|
+
|
|
148
|
+
```dockerfile
|
|
149
|
+
# Stage 1: Prune monorepo for target app
|
|
150
|
+
FROM node:20-alpine AS pruner
|
|
151
|
+
RUN apk add --no-cache libc6-compat
|
|
152
|
+
WORKDIR /app
|
|
153
|
+
RUN npm install -g turbo
|
|
154
|
+
COPY . .
|
|
155
|
+
RUN turbo prune web --docker
|
|
156
|
+
|
|
157
|
+
# Stage 2: Install dependencies from pruned lockfile
|
|
158
|
+
FROM node:20-alpine AS installer
|
|
159
|
+
RUN apk add --no-cache libc6-compat
|
|
160
|
+
WORKDIR /app
|
|
161
|
+
COPY .gitignore .gitignore
|
|
162
|
+
COPY --from=pruner /app/out/json/ .
|
|
163
|
+
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
|
|
164
|
+
RUN corepack enable && pnpm install --frozen-lockfile
|
|
165
|
+
|
|
166
|
+
# Stage 3: Build application
|
|
167
|
+
COPY --from=pruner /app/out/full/ .
|
|
168
|
+
COPY turbo.json turbo.json
|
|
169
|
+
RUN pnpm turbo run build --filter=web...
|
|
170
|
+
|
|
171
|
+
# Stage 4: Production Runner
|
|
172
|
+
FROM node:20-alpine AS runner
|
|
173
|
+
WORKDIR /app
|
|
174
|
+
ENV NODE_ENV=production
|
|
175
|
+
RUN addgroup --system --gid 1001 nodejs && adduser --system --uid 1001 nextjs
|
|
176
|
+
COPY --from=installer --chown=nextjs:nodejs /app/apps/web/.next/standalone ./
|
|
177
|
+
COPY --from=installer --chown=nextjs:nodejs /app/apps/web/.next/static ./apps/web/.next/static
|
|
178
|
+
USER nextjs
|
|
179
|
+
EXPOSE 3000
|
|
180
|
+
CMD ["node", "apps/web/server.js"]
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## 🎯 Verification & Diagnostics
|
|
186
|
+
|
|
187
|
+
1. **Inspect Task Graph**:
|
|
188
|
+
```bash
|
|
189
|
+
turbo run build --graph=build-graph.html
|
|
190
|
+
```
|
|
191
|
+
2. **Dry Run Pipeline**:
|
|
192
|
+
```bash
|
|
193
|
+
turbo run test --dry-run
|
|
194
|
+
```
|
|
195
|
+
3. **Targeted Subtree Execution**:
|
|
196
|
+
```bash
|
|
197
|
+
turbo run build --filter=web... # web and all its internal dependencies
|
|
198
|
+
turbo run test --filter=...api # api and all packages that depend on it
|
|
199
|
+
```
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: vllm-inference
|
|
3
|
+
description: >-
|
|
4
|
+
High-throughput LLM serving and inference optimization using vLLM, PagedAttention memory management, continuous batching, tensor parallelism, and OpenAI-compatible API architecture. Use when deploying open-weights models, optimizing GPU KV caches, scaling Ray clusters, or tuning inference throughput.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# vLLM Inference & Serving Architecture
|
|
8
|
+
|
|
9
|
+
A comprehensive runbook for deploying, tuning, and operating enterprise LLM inference infrastructure using **vLLM**, PagedAttention, and distributed GPU clusters.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 🎯 Architectural Principles
|
|
14
|
+
|
|
15
|
+
1. **PagedAttention**: Near-zero memory waste by allocating KV cache in non-contiguous physical blocks (virtual memory paging for LLMs).
|
|
16
|
+
2. **Continuous (Iteration-Level) Batching**: Requests join and exit the running batch dynamically at token generation boundaries rather than waiting for sequence completion.
|
|
17
|
+
3. **Tensor & Pipeline Parallelism**: Seamless multi-GPU sharding using Megatron-LM style tensor parallelism across NVLink or distributed Ray nodes.
|
|
18
|
+
4. **OpenAI Protocol Parity**: Fully compliant Drop-in replacement for Chat Completions, Completions, and Embedding endpoints.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## 🚀 Quickstart: Production Deployment
|
|
23
|
+
|
|
24
|
+
### 1. Standalone Docker Container Deployment
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
docker run --gpus all \
|
|
28
|
+
--shm-size 10.24gb \
|
|
29
|
+
-p 8000:8000 \
|
|
30
|
+
-v ~/.cache/huggingface:/root/.cache/huggingface \
|
|
31
|
+
--ipc=host \
|
|
32
|
+
vllm/vllm-openai:latest \
|
|
33
|
+
--model Qwen/Qwen2.5-72B-Instruct-AWQ \
|
|
34
|
+
--tensor-parallel-size 4 \
|
|
35
|
+
--max-model-len 32768 \
|
|
36
|
+
--gpu-memory-utilization 0.92 \
|
|
37
|
+
--kv-cache-dtype auto \
|
|
38
|
+
--enable-chunked-prefill \
|
|
39
|
+
--max-num-seqs 256
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 2. High-Performance Configuration Matrix
|
|
43
|
+
|
|
44
|
+
| Parameter | Recommended Setting | Architectural Rationale |
|
|
45
|
+
| :--- | :--- | :--- |
|
|
46
|
+
| `--gpu-memory-utilization` | `0.90` - `0.95` | Leaves ~5-10% GPU VRAM for CUDA context and PyTorch allocator overhead. |
|
|
47
|
+
| `--tensor-parallel-size` | Matches socket count (2, 4, 8) | Shards attention heads evenly across NVLink interconnects. |
|
|
48
|
+
| `--enable-chunked-prefill` | `true` | Prevents long prompt prefill passes from blocking decode iterations of active requests. |
|
|
49
|
+
| `--max-num-batched-tokens` | `4096` - `8192` | Balances prefill compute intensity with KV cache allocation throughput. |
|
|
50
|
+
| `--kv-cache-dtype` | `fp8` / `auto` | Halves KV memory consumption on Ada/Hopper architectures (H100/L40S). |
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## 🛠️ Python SDK Integration
|
|
55
|
+
|
|
56
|
+
Interact with vLLM via either offline batch processing or the OpenAI client.
|
|
57
|
+
|
|
58
|
+
### Pattern A: Offline High-Throughput Batch Processing
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from vllm import LLM, SamplingParams
|
|
62
|
+
|
|
63
|
+
# Configure model engine with tensor parallelism
|
|
64
|
+
llm = LLM(
|
|
65
|
+
model="mistralai/Mistral-7B-Instruct-v0.3",
|
|
66
|
+
tensor_parallel_size=2,
|
|
67
|
+
gpu_memory_utilization=0.90,
|
|
68
|
+
max_model_len=16384,
|
|
69
|
+
trust_remote_code=True,
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
sampling_params = SamplingParams(
|
|
73
|
+
temperature=0.7,
|
|
74
|
+
top_p=0.95,
|
|
75
|
+
max_tokens=1024,
|
|
76
|
+
presence_penalty=0.1,
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
prompts = [
|
|
80
|
+
"Analyze the following architectural bottleneck: ...",
|
|
81
|
+
"Generate a Terraform module for Cilium eBPF on GKE: ...",
|
|
82
|
+
]
|
|
83
|
+
|
|
84
|
+
outputs = llm.generate(prompts, sampling_params)
|
|
85
|
+
|
|
86
|
+
for output in outputs:
|
|
87
|
+
prompt = output.prompt
|
|
88
|
+
generated_text = output.outputs[0].text
|
|
89
|
+
print(f"Generated {len(output.outputs[0].token_ids)} tokens.")
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Pattern B: Async OpenAI Client Integration
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
from openai import AsyncOpenAI
|
|
96
|
+
import asyncio
|
|
97
|
+
|
|
98
|
+
client = AsyncOpenAI(
|
|
99
|
+
base_url="http://localhost:8000/v1",
|
|
100
|
+
api_key="token-internal-vllm",
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
async def stream_generation(prompt: str):
|
|
104
|
+
response = await client.chat.completions.create(
|
|
105
|
+
model="Qwen/Qwen2.5-72B-Instruct-AWQ",
|
|
106
|
+
messages=[{"role": "user", "content": prompt}],
|
|
107
|
+
temperature=0.2,
|
|
108
|
+
stream=True,
|
|
109
|
+
)
|
|
110
|
+
async for chunk in response:
|
|
111
|
+
delta = chunk.choices[0].delta.content or ""
|
|
112
|
+
print(delta, end="", flush=True)
|
|
113
|
+
|
|
114
|
+
asyncio.run(stream_generation("Summarize the benefits of continuous batching."))
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## 📈 Prometheus Observability & Metrics
|
|
120
|
+
|
|
121
|
+
vLLM exposes Prometheus metrics on `/metrics`:
|
|
122
|
+
|
|
123
|
+
```text
|
|
124
|
+
# Cache usage metrics
|
|
125
|
+
vllm:gpu_cache_usage_factor # Active KV cache allocation (target: < 0.85)
|
|
126
|
+
vllm:num_requests_waiting # Requests queued in prefill backlog (target: 0)
|
|
127
|
+
vllm:num_requests_running # Concurrently decoding requests
|
|
128
|
+
vllm:time_to_first_token_seconds # TTFT distribution histogram
|
|
129
|
+
vllm:time_per_output_token_seconds # Inter-token generation latency (target: < 25ms)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## 🛡️ Common Failure Modes & Mitigations
|
|
135
|
+
|
|
136
|
+
1. **CUDA Out of Memory (OOM) during Startup**:
|
|
137
|
+
- *Cause*: Model weights + KV cache exceeds total VRAM.
|
|
138
|
+
- *Fix*: Reduce `--gpu-memory-utilization` from 0.95 to 0.88, or enforce AWQ/GPTQ 4-bit quantization.
|
|
139
|
+
2. **Request Preemption Storms**:
|
|
140
|
+
- *Cause*: KV cache saturates (`gpu_cache_usage_factor = 1.0`), forcing vLLM to swap sequences to CPU memory.
|
|
141
|
+
- *Fix*: Reduce `--max-num-seqs` or enable `--kv-cache-dtype fp8` to double cache capacity.
|
|
142
|
+
3. **TTFT Spikes on Long Contexts**:
|
|
143
|
+
- *Cause*: Large prompt prefills starving active decode steps.
|
|
144
|
+
- *Fix*: Pass `--enable-chunked-prefill` and `--max-num-batched-tokens 2048`.
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: wasm-rust-optimizer
|
|
3
|
+
description: >-
|
|
4
|
+
Compiles and optimizes high-performance WebAssembly modules from Rust using wasm-pack, zero-copy memory buffers (Uint8Array), SIMD vectorization, and Web Worker thread pools.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# WebAssembly & Rust Performance Optimization
|
|
8
|
+
|
|
9
|
+
This skill guides compiling compute-intensive logic (image processing, cryptographic hashing, parser engines, physics calculations) into high-throughput WebAssembly (WASM) modules using Rust.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## ⚡ Rust & Cargo Configuration (`Cargo.toml`)
|
|
14
|
+
|
|
15
|
+
Configure the crate for minimal binary footprint and direct browser bindings:
|
|
16
|
+
|
|
17
|
+
```toml
|
|
18
|
+
[package]
|
|
19
|
+
name = "wasm-engine"
|
|
20
|
+
version = "0.1.0"
|
|
21
|
+
edition = "2021"
|
|
22
|
+
|
|
23
|
+
[lib]
|
|
24
|
+
crate-type = ["cdylib", "rlib"]
|
|
25
|
+
|
|
26
|
+
[dependencies]
|
|
27
|
+
wasm-bindgen = "0.2"
|
|
28
|
+
js-sys = "0.3"
|
|
29
|
+
web-sys = { version = "0.3", features = ["console"] }
|
|
30
|
+
|
|
31
|
+
[profile.release]
|
|
32
|
+
opt-level = 3
|
|
33
|
+
lto = true
|
|
34
|
+
codegen-units = 1
|
|
35
|
+
panic = "abort"
|
|
36
|
+
strip = true
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## 🚀 Zero-Copy Memory Transfer (Uint8Array)
|
|
42
|
+
|
|
43
|
+
Avoid JSON serialization overhead when passing gigabytes or megabytes of data between JavaScript and WebAssembly. Pass memory buffer pointers directly:
|
|
44
|
+
|
|
45
|
+
### 1. Rust Implementation (`src/lib.rs`)
|
|
46
|
+
|
|
47
|
+
```rust
|
|
48
|
+
use wasm_bindgen::prelude::*;
|
|
49
|
+
|
|
50
|
+
#[wasm_bindgen]
|
|
51
|
+
pub struct ImageProcessor {
|
|
52
|
+
buffer: Vec<u8>,
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
#[wasm_bindgen]
|
|
56
|
+
impl ImageProcessor {
|
|
57
|
+
#[wasm_bindgen(constructor)]
|
|
58
|
+
pub fn new(size: usize) -> Self {
|
|
59
|
+
Self {
|
|
60
|
+
buffer: vec![0u8; size],
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/// Exposes raw memory pointer for zero-copy JavaScript access
|
|
65
|
+
pub fn get_buffer_ptr(&self) -> *const u8 {
|
|
66
|
+
self.buffer.as_ptr()
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/// In-place high-performance pixel grayscale filter
|
|
70
|
+
pub fn process_grayscale(&mut self) {
|
|
71
|
+
// Fast in-place chunk iteration
|
|
72
|
+
for pixel in self.buffer.chunks_exact_mut(4) {
|
|
73
|
+
let r = pixel[0] as u32;
|
|
74
|
+
let g = pixel[1] as u32;
|
|
75
|
+
let b = pixel[2] as u32;
|
|
76
|
+
let gray = ((r * 77 + g * 150 + b * 29) >> 8) as u8;
|
|
77
|
+
pixel[0] = gray;
|
|
78
|
+
pixel[1] = gray;
|
|
79
|
+
pixel[2] = gray;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
### 2. JavaScript / TypeScript Client Integration
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import init, { ImageProcessor } from './pkg/wasm_engine.js';
|
|
91
|
+
|
|
92
|
+
export async function runProcessor(canvas: HTMLCanvasElement) {
|
|
93
|
+
const wasm = await init();
|
|
94
|
+
const ctx = canvas.getContext('2d')!;
|
|
95
|
+
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
|
96
|
+
const totalBytes = imageData.data.length;
|
|
97
|
+
|
|
98
|
+
// Instantiate Rust WASM processor
|
|
99
|
+
const processor = new ImageProcessor(totalBytes);
|
|
100
|
+
const ptr = processor.get_buffer_ptr();
|
|
101
|
+
|
|
102
|
+
// Create zero-copy views directly into WASM linear memory
|
|
103
|
+
const wasmMemoryView = new Uint8Array(wasm.memory.buffer, ptr, totalBytes);
|
|
104
|
+
wasmMemoryView.set(imageData.data);
|
|
105
|
+
|
|
106
|
+
// Execute native compiled computation
|
|
107
|
+
processor.process_grayscale();
|
|
108
|
+
|
|
109
|
+
// Read back transformed memory without cloning
|
|
110
|
+
imageData.data.set(wasmMemoryView);
|
|
111
|
+
ctx.putImageData(imageData, 0, 0);
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## 🛠️ Build & Optimization Workflow
|
|
118
|
+
|
|
119
|
+
1. **Compile with `wasm-pack`:**
|
|
120
|
+
```bash
|
|
121
|
+
wasm-pack build --target web --release
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
2. **Optimize with `wasm-opt` (Binaryen):**
|
|
125
|
+
```bash
|
|
126
|
+
wasm-opt -O4 -o pkg/wasm_engine_bg_opt.wasm pkg/wasm_engine_bg.wasm
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
3. **Non-Blocking Compute in Web Workers:**
|
|
130
|
+
Always instantiate large WASM modules inside dedicated Web Workers (`new Worker(new URL('./worker.ts', import.meta.url))`) to keep the UI thread rendering at a silky 60/120 FPS.
|
|
@@ -52,5 +52,19 @@
|
|
|
52
52
|
]
|
|
53
53
|
}
|
|
54
54
|
]
|
|
55
|
+
},
|
|
56
|
+
"secret-scrubber": {
|
|
57
|
+
"PreToolUse": [
|
|
58
|
+
{
|
|
59
|
+
"matcher": "write_to_file|replace_file_content|multi_replace_file_content",
|
|
60
|
+
"hooks": [
|
|
61
|
+
{
|
|
62
|
+
"type": "command",
|
|
63
|
+
"command": "bash ./hooks/secret-scrubber/scripts/scrub-secrets.sh",
|
|
64
|
+
"timeout": 10
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
]
|
|
55
69
|
}
|
|
56
70
|
}
|
|
@@ -10,6 +10,49 @@
|
|
|
10
10
|
"postgres": {
|
|
11
11
|
"command": "npx",
|
|
12
12
|
"args": ["-y", "@modelcontextprotocol/server-postgres", "${DATABASE_URL}"]
|
|
13
|
+
},
|
|
14
|
+
"memory": {
|
|
15
|
+
"command": "npx",
|
|
16
|
+
"args": ["-y", "@modelcontextprotocol/server-memory"]
|
|
17
|
+
},
|
|
18
|
+
"fetch": {
|
|
19
|
+
"command": "npx",
|
|
20
|
+
"args": ["-y", "@modelcontextprotocol/server-fetch"]
|
|
21
|
+
},
|
|
22
|
+
"redis": {
|
|
23
|
+
"command": "npx",
|
|
24
|
+
"args": ["-y", "@modelcontextprotocol/server-redis", "${REDIS_URL}"]
|
|
25
|
+
},
|
|
26
|
+
"docker": {
|
|
27
|
+
"command": "npx",
|
|
28
|
+
"args": ["-y", "@modelcontextprotocol/server-docker"]
|
|
29
|
+
},
|
|
30
|
+
"clickhouse": {
|
|
31
|
+
"command": "npx",
|
|
32
|
+
"args": ["-y", "@modelcontextprotocol/server-clickhouse", "${CLICKHOUSE_URL}"]
|
|
33
|
+
},
|
|
34
|
+
"sequential-thinking": {
|
|
35
|
+
"command": "npx",
|
|
36
|
+
"args": ["-y", "@modelcontextprotocol/server-sequential-thinking"]
|
|
37
|
+
},
|
|
38
|
+
"filesystem": {
|
|
39
|
+
"command": "npx",
|
|
40
|
+
"args": ["-y", "@modelcontextprotocol/server-filesystem", "./docs", "./src"]
|
|
41
|
+
},
|
|
42
|
+
"sentry": {
|
|
43
|
+
"command": "npx",
|
|
44
|
+
"args": ["-y", "@modelcontextprotocol/server-sentry"],
|
|
45
|
+
"env": {
|
|
46
|
+
"SENTRY_AUTH_TOKEN": "${SENTRY_AUTH_TOKEN}"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"slack": {
|
|
50
|
+
"command": "npx",
|
|
51
|
+
"args": ["-y", "@modelcontextprotocol/server-slack"],
|
|
52
|
+
"env": {
|
|
53
|
+
"SLACK_BOT_TOKEN": "${SLACK_BOT_TOKEN}",
|
|
54
|
+
"SLACK_TEAM_ID": "${SLACK_TEAM_ID}"
|
|
55
|
+
}
|
|
13
56
|
}
|
|
14
57
|
}
|
|
15
58
|
}
|
|
@@ -39,5 +39,19 @@
|
|
|
39
39
|
]
|
|
40
40
|
}
|
|
41
41
|
]
|
|
42
|
+
},
|
|
43
|
+
"secret-scrubber": {
|
|
44
|
+
"PreToolUse": [
|
|
45
|
+
{
|
|
46
|
+
"matcher": "write_to_file|replace_file_content|multi_replace_file_content",
|
|
47
|
+
"hooks": [
|
|
48
|
+
{
|
|
49
|
+
"type": "command",
|
|
50
|
+
"command": "bash ./hooks/secret-scrubber/scripts/scrub-secrets.sh",
|
|
51
|
+
"timeout": 10
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
]
|
|
42
56
|
}
|
|
43
57
|
}
|