Develop #1
No files matched your search
@@ -1,2 +1,3 @@
|
|||||||
/target
|
/target
|
||||||
.superpowers/
|
.superpowers/
|
||||||
|
.specs/
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
# matcha — green-tea CLI · Design
|
|
||||||
|
|
||||||
**Date:** 2026-07-11
|
|
||||||
**Status:** Approved (brainstorming), pending spec review
|
|
||||||
**Repo:** `Green-Tea/matcha` (separate repo, Rust — created by Diego)
|
|
||||||
**Relates to:** `Green-Tea/core` (the green-tea framework)
|
|
||||||
|
|
||||||
## 1. What it is
|
|
||||||
|
|
||||||
`matcha` is the developer-experience CLI for the green-tea HTTP framework. A
|
|
||||||
single **native binary written in Rust**, distributed independently of the
|
|
||||||
framework. It does not require a JS runtime to *install or operate*; it only
|
|
||||||
*delegates* to the project's runtime when it needs to run or type-check the
|
|
||||||
project.
|
|
||||||
|
|
||||||
**Name rationale:** matcha *is* premium green tea — on-brand, distinctive, no
|
|
||||||
CLI collision (`gt`=Graphite, `tea`=Gitea's CLI, `gtea`≈gitea were all ruled
|
|
||||||
out). Crate `matcha`, brew `matcha`, repo `Green-Tea/matcha`.
|
|
||||||
|
|
||||||
## 2. Command surface
|
|
||||||
|
|
||||||
```
|
|
||||||
matcha new <name> [--template-url gh:owner/repo] # scaffold a project
|
|
||||||
matcha run # detect runtime, run in watch
|
|
||||||
matcha create <module|controller|step> <Name> # generate a piece + auto-wire
|
|
||||||
matcha add <sse|stream|buffer> # add a capability to a file
|
|
||||||
```
|
|
||||||
|
|
||||||
`new` scaffolds **projects**; `create` scaffolds **pieces inside** a project.
|
|
||||||
This split retires the earlier ambiguous `create app`.
|
|
||||||
|
|
||||||
## 3. `matcha new`
|
|
||||||
|
|
||||||
- No flag → **official `starter` template, embedded in the binary**
|
|
||||||
(`include_dir!`), zero network.
|
|
||||||
- `--template-url gh:owner/repo` → `git clone --depth 1` of the given repo.
|
|
||||||
`git` is ubiquitous on dev machines, so the binary carries **no HTTP/TLS
|
|
||||||
dependency**. This opens a bring-your-own-template ecosystem while we
|
|
||||||
maintain only one official template.
|
|
||||||
- Token substitution on copy is minimal: `{{project_name}}`. Nothing more.
|
|
||||||
|
|
||||||
### The official `starter` (the "wow")
|
|
||||||
|
|
||||||
A live app the moment you run it — the create-react-app effect:
|
|
||||||
|
|
||||||
- Serves an `index.html` showing the **green-tea logo** (demonstrates
|
|
||||||
`@Html` static serving).
|
|
||||||
- A `@Sse('/zen')` endpoint that streams a **rotating zen message every 30
|
|
||||||
seconds** (demonstrates live streaming). The page subscribes via
|
|
||||||
`EventSource('/zen')` and updates the zen line under the logo, untouched by
|
|
||||||
the user.
|
|
||||||
|
|
||||||
Faithful to the real framework API (verified in `core`):
|
|
||||||
|
|
||||||
```ts
|
|
||||||
@Route('/')
|
|
||||||
class HomeController {
|
|
||||||
@Get('/')
|
|
||||||
@Html('public/index.html')
|
|
||||||
home() {}
|
|
||||||
|
|
||||||
@Sse('/zen')
|
|
||||||
zen() {
|
|
||||||
const messages = [/* zen lines */];
|
|
||||||
return (async function* () {
|
|
||||||
for (let i = 0; ; i++) {
|
|
||||||
yield { zen: messages[i % messages.length] };
|
|
||||||
await new Promise((r) => setTimeout(r, 30_000));
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Starter layout:
|
|
||||||
|
|
||||||
```
|
|
||||||
<name>/
|
|
||||||
src/app.module.ts # @Module wiring HomeController
|
|
||||||
src/controllers/home.controller.ts
|
|
||||||
public/index.html # logo + EventSource('/zen')
|
|
||||||
<runtime config> # deno.json | package.json | ...
|
|
||||||
matcha.toml # optional runtime override
|
|
||||||
```
|
|
||||||
|
|
||||||
## 4. `matcha run` — runtime detection
|
|
||||||
|
|
||||||
Precedence (first match wins):
|
|
||||||
|
|
||||||
1. `matcha.toml` `runtime` field — explicit override
|
|
||||||
2. `deno.json(c)` → **deno**
|
|
||||||
3. `bun.lock(b)` → **bun**
|
|
||||||
4. `package.json` → **node**
|
|
||||||
|
|
||||||
Runs the project's entry in watch mode by wrapping the detected runtime.
|
|
||||||
**Edge is not a `run` target in v1** — it deploys, it does not run locally.
|
|
||||||
|
|
||||||
## 5. `create` / `add` — codegen
|
|
||||||
|
|
||||||
Three distinct jobs, three tools:
|
|
||||||
|
|
||||||
- **Edit** → `tree-sitter` + `tree-sitter-typescript` (in-process, no runtime).
|
|
||||||
Inserts the `import` and adds the class to the right `@Module` array
|
|
||||||
(`controllers` / `providers` / steps) via range-based splice that preserves
|
|
||||||
the file's existing formatting byte-for-byte.
|
|
||||||
- **Syntax check** → re-parse with tree-sitter. If an `ERROR` node appears, the
|
|
||||||
edit broke structure → **revert, leave the file untouched**. Free, in-process.
|
|
||||||
- **Semantic check (optional)** → if a `tsconfig` / `deno.json` is present, run
|
|
||||||
`tsc --noEmit` / `deno check` with the detected runtime. Behind `--check`
|
|
||||||
(or automatic when config is present). This is the lazy-correct alternative
|
|
||||||
to an LSP: an LSP is built for interactive editing, cannot insert into an
|
|
||||||
array, and would reintroduce a runtime dependency — a one-shot `tsc`/`deno
|
|
||||||
check` gives the same diagnostics with none of the plumbing.
|
|
||||||
|
|
||||||
**Idempotent:** if the piece is already registered, do not duplicate.
|
|
||||||
|
|
||||||
**Agreed fallback:** if auto-wire proves fragile ("truena como ejote"),
|
|
||||||
degrade to emit-only — write the file and print "add it to your module."
|
|
||||||
Auto-wire stays, but is allowed to become opt-in rather than a blocker.
|
|
||||||
|
|
||||||
## 6. Architecture (Rust)
|
|
||||||
|
|
||||||
- Command parsing: `clap`.
|
|
||||||
- Templates: `include_dir!` embeds the starter; `--template-url` shells to
|
|
||||||
`git clone --depth 1`.
|
|
||||||
- Codegen: `tree-sitter` + `tree-sitter-typescript`, range-based edits.
|
|
||||||
- Validation: spawn detected runtime for `tsc --noEmit` / `deno check`.
|
|
||||||
- Runtime detection: filesystem probes in the precedence order above.
|
|
||||||
|
|
||||||
Each command is an isolated unit: parse args → do one job → report. No shared
|
|
||||||
mutable state between commands.
|
|
||||||
|
|
||||||
## 7. Out of scope for v1 (YAGNI)
|
|
||||||
|
|
||||||
Template catalog (one starter + BYO url is enough), edge as a `run` target,
|
|
||||||
plugin system, custom LSP, custom bundler/dev-server.
|
|
||||||
|
|
||||||
## 8. Open handoff items
|
|
||||||
|
|
||||||
- Diego creates the `Green-Tea/matcha` repo; this spec moves there.
|
|
||||||
- green-tea logo asset for the starter (`assets/` in `core` has branding).
|
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,152 +0,0 @@
|
|||||||
# matcha — multi-runtime starter (node/deno/bun) · Spec
|
|
||||||
|
|
||||||
**Date:** 2026-07-12
|
|
||||||
**Branch:** `feature/matcha-multi-runtime` (off `develop`)
|
|
||||||
**Goal:** `matcha new <name> --runtime <node|deno|bun>` scaffolds the starter for the chosen runtime. Shared app files are written once; only `main.ts` + runtime config + `matcha.toml` differ per runtime. Default runtime: **node** (green-tea is developed node-first; Node is the reference implementation. deno/bun via `--runtime`).
|
|
||||||
|
|
||||||
## Verified framework facts (from Green-Tea/core)
|
|
||||||
- `@green-tea/core` imports `reflect-metadata` internally (`src/index.ts:6`) — consumers need NO explicit import; it installs transitively with the package.
|
|
||||||
- Serve per runtime: Node `app.listen(3000)`; Deno `Deno.serve({ port }, app.fetch)`; Bun `Bun.serve({ port, fetch: app.fetch })`. Starter has no WebSocket, so `app.fetch` is sufficient (no `serveDeno`/`serveBun`).
|
|
||||||
- `@Module` requires `mountpoint`. Package version pin: `^26.7.0-beta.0`.
|
|
||||||
|
|
||||||
## New template layout (replaces `template/starter/`)
|
|
||||||
```
|
|
||||||
template/
|
|
||||||
shared/
|
|
||||||
public/index.html
|
|
||||||
src/app.module.ts
|
|
||||||
src/controllers/home.controller.ts
|
|
||||||
runtimes/
|
|
||||||
deno/ { matcha.toml, deno.json, src/main.ts }
|
|
||||||
node/ { matcha.toml, package.json, tsconfig.json, src/main.ts }
|
|
||||||
bun/ { matcha.toml, package.json, tsconfig.json, src/main.ts }
|
|
||||||
```
|
|
||||||
`write_starter` writes `shared` then overlays the chosen runtime dir on top (both go into the same project dir; `src/main.ts` from the overlay lands beside `src/app.module.ts` from shared). Token substitution `{{project_name}}` applies to every copied file (now also `package.json` "name").
|
|
||||||
|
|
||||||
## Exact file contents
|
|
||||||
|
|
||||||
### shared/ (moved verbatim from current `template/starter/`)
|
|
||||||
- `public/index.html` — unchanged (keep `{{project_name}}` title + `EventSource('/zen')`).
|
|
||||||
- `src/app.module.ts` — unchanged (`@Module({ mountpoint: '/', controllers: [HomeController] })`).
|
|
||||||
- `src/controllers/home.controller.ts` — unchanged (`@Route('/')`, `@Get('/') @Html('public/index.html')`, `@Sse('/zen')` rotating zen every 30s).
|
|
||||||
|
|
||||||
### runtimes/deno/ (moved from current starter)
|
|
||||||
- `matcha.toml`: `runtime = "deno"`
|
|
||||||
- `deno.json` (unchanged from current starter):
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"compilerOptions": { "experimentalDecorators": true },
|
|
||||||
"unstable": ["sloppy-imports"],
|
|
||||||
"imports": { "@green-tea/core": "npm:@green-tea/core@^26.7.0-beta.0" },
|
|
||||||
"tasks": { "dev": "deno run --watch --allow-net --allow-read --allow-env src/main.ts" }
|
|
||||||
}
|
|
||||||
```
|
|
||||||
- `src/main.ts`:
|
|
||||||
```ts
|
|
||||||
import { createApp } from '@green-tea/core';
|
|
||||||
import { AppModule } from './app.module';
|
|
||||||
|
|
||||||
const app = createApp({ modules: [AppModule] });
|
|
||||||
|
|
||||||
Deno.serve({ port: 8000 }, app.fetch);
|
|
||||||
console.log('🍵 green-tea running on http://localhost:8000');
|
|
||||||
```
|
|
||||||
|
|
||||||
### runtimes/node/
|
|
||||||
- `matcha.toml`: `runtime = "node"`
|
|
||||||
- `package.json`:
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"name": "{{project_name}}",
|
|
||||||
"type": "module",
|
|
||||||
"private": true,
|
|
||||||
"scripts": { "dev": "tsx watch src/main.ts" },
|
|
||||||
"dependencies": { "@green-tea/core": "^26.7.0-beta.0" },
|
|
||||||
"devDependencies": { "tsx": "^4", "typescript": "^5" }
|
|
||||||
}
|
|
||||||
```
|
|
||||||
- `tsconfig.json`:
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "es2020",
|
|
||||||
"module": "esnext",
|
|
||||||
"moduleResolution": "bundler",
|
|
||||||
"experimentalDecorators": true,
|
|
||||||
"strict": true,
|
|
||||||
"skipLibCheck": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
- `src/main.ts`:
|
|
||||||
```ts
|
|
||||||
import { createApp } from '@green-tea/core';
|
|
||||||
import { AppModule } from './app.module';
|
|
||||||
|
|
||||||
const app = createApp({ modules: [AppModule] });
|
|
||||||
|
|
||||||
app.listen(3000);
|
|
||||||
console.log('🍵 green-tea running on http://localhost:3000');
|
|
||||||
```
|
|
||||||
|
|
||||||
### runtimes/bun/
|
|
||||||
- `matcha.toml`: `runtime = "bun"`
|
|
||||||
- `package.json`:
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"name": "{{project_name}}",
|
|
||||||
"type": "module",
|
|
||||||
"private": true,
|
|
||||||
"scripts": { "dev": "bun --watch run src/main.ts" },
|
|
||||||
"dependencies": { "@green-tea/core": "^26.7.0-beta.0" }
|
|
||||||
}
|
|
||||||
```
|
|
||||||
- `tsconfig.json`:
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "esnext",
|
|
||||||
"module": "esnext",
|
|
||||||
"moduleResolution": "bundler",
|
|
||||||
"experimentalDecorators": true,
|
|
||||||
"strict": true,
|
|
||||||
"skipLibCheck": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
- `src/main.ts`:
|
|
||||||
```ts
|
|
||||||
import { createApp } from '@green-tea/core';
|
|
||||||
import { AppModule } from './app.module';
|
|
||||||
|
|
||||||
const app = createApp({ modules: [AppModule] });
|
|
||||||
|
|
||||||
Bun.serve({ port: 8000, fetch: app.fetch });
|
|
||||||
console.log('🍵 green-tea running on http://localhost:8000');
|
|
||||||
```
|
|
||||||
|
|
||||||
## Code changes
|
|
||||||
|
|
||||||
### `src/template.rs`
|
|
||||||
- Replace the single `STARTER` embed with `SHARED` + three runtime overlays (`include_dir!` each).
|
|
||||||
- `pub fn write_starter(dest: &Path, project_name: &str, runtime: Runtime) -> io::Result<()>` — write `SHARED`, then the overlay for `runtime`. Keep `write_dir` substitution logic.
|
|
||||||
|
|
||||||
### `src/cli.rs`
|
|
||||||
- `Command::New` gains `#[arg(long, default_value = "deno", value_parser = ["node", "deno", "bun"])] runtime: String`.
|
|
||||||
|
|
||||||
### `src/cmd_new.rs`
|
|
||||||
- `run(name, template_url, runtime: &str)`: parse `runtime` via `Runtime::from_str` (already in `runtime.rs`); for the starter (no `--template-url`) path, call `write_starter(dest, name, rt)`. `--template-url` path ignores `--runtime`.
|
|
||||||
|
|
||||||
### `src/cmd_run.rs`
|
|
||||||
- Change the Bun mapping from `("bun", vec!["--watch", "run", "dev"])` to `("bun", vec!["run", "dev"])` so all three uniformly run their `dev` script (deno.json/package.json define the watch). Update the `bun_watch` unit test accordingly.
|
|
||||||
|
|
||||||
### `src/main.rs`
|
|
||||||
- Pass the new `runtime` arg through the `Command::New` dispatch.
|
|
||||||
|
|
||||||
## Tests
|
|
||||||
- `template.rs`: parametrize the write test — assert deno writes `deno.json` + `src/main.ts` containing `Deno.serve`; node writes `package.json` (with substituted name) + `tsconfig.json` + `main.ts` containing `app.listen`; bun writes `package.json` + `main.ts` containing `Bun.serve`. All three write the shared `src/app.module.ts` and `public/index.html`.
|
|
||||||
- `tests/new.rs`: `matcha new demo --runtime node` produces `package.json` with `"name": "demo"` and no `deno.json`; default (no flag) produces `deno.json`.
|
|
||||||
- `cmd_run.rs`: bun mapping test expects `("bun", vec!["run", "dev"])`.
|
|
||||||
|
|
||||||
## Out of scope
|
|
||||||
Edge starter (deploy target, not `run`). Per-runtime lockfiles. `serveDeno`/`serveBun` (no WS in starter).
|
|
||||||
Reference in new issue
Block a user