Prereq
Verify command -v lens succeeds. If it returns non-zero, tell the user "lens CLI not found. Install with npm i -g lens-engine." and stop.
Dispatch
- If
$ARGUMENTS contains a positional token that is not a flag (i.e. a description), go to Passthrough.
- Otherwise (empty, or only flags like
--template <name>), go to Exploration.
Passthrough
Run:
lens init $ARGUMENTS
Stream stdout/stderr. Surface non-zero exit clearly. Stop.
Exploration
The user invoked /lens:init without a description. Survey the repo, propose a template, draft the intent, confirm, then invoke the CLI.
1. Survey (read-only)
- Read whichever of
package.json, Cargo.toml, pyproject.toml, go.mod, Gemfile, build.gradle exists (name, description, scripts, dependencies).
- Read
README.md (first ~200 lines) if present.
Glob top-level layout: *, src/*, app/*, cmd/*.
Glob/Grep for structural markers (a package.json bin field, .proto files, etc.).
2. Pick a template
The six shipped templates are webapp, cli, library, pipeline, protocol, blank. Use this signal order (first strong match wins):
- cli —
package.json has bin; or src/cli/ exists; or the entrypoint starts with a shebang.
- webapp —
src/routes/, src/app/api/, prisma/, src/controllers/, or similar route/DB layout.
- protocol —
.proto files, proto/, messages/, or state-machine naming.
- pipeline —
airflow/, dagster/, prefect/, src/jobs/, or src/workers/.
- library — has
exports/main in package.json, no bin, no server/route directories, tests-centric layout.
- blank — no strong match.
3. Draft the intent
Write 3–6 sentences describing the system. Ground it in what the README and manifest actually say — prefer quoting the README's own phrasing. Do not invent features that aren't in the source.
4. Confirm with the user
Use AskUserQuestion with two questions:
- Template — options: your chosen template labeled "(Recommended)", one alternative if the repo straddles two, and
blank.
- Intent — paste the drafted intent. Options: "Use this intent", "Let me edit". If the user picks "Let me edit", ask for the revised intent as free text before continuing.
5. Invoke
Run:
lens init --template <chosen> "<intent>"
Stream output. If it exits non-zero, surface the error; do not proceed to step 6.
6. Follow-up
After lens init succeeds, tell the user:
Lens files were populated from your intent. For an existing codebase, run /lens:pull next to reflect the actual implementation into the lenses. Then review .lenses/, commit, and start iterating.
Do not auto-run lens pull — it invokes the runner and can take a minute or more, so users should opt in.
1---2name: init3description: Prereq4---56## Prereq78Verify `command -v lens` succeeds. If it returns non-zero, tell the user "lens CLI not found. Install with `npm i -g lens-engine`." and stop.910## Dispatch1112- If `$ARGUMENTS` contains a positional token that is not a flag (i.e. a description), go to **Passthrough**.13- Otherwise (empty, or only flags like `--template <name>`), go to **Exploration**.1415## Passthrough1617Run:1819 lens init $ARGUMENTS2021Stream stdout/stderr. Surface non-zero exit clearly. Stop.2223## Exploration2425The user invoked `/lens:init` without a description. Survey the repo, propose a template, draft the intent, confirm, then invoke the CLI.2627### 1. Survey (read-only)2829- Read whichever of `package.json`, `Cargo.toml`, `pyproject.toml`, `go.mod`, `Gemfile`, `build.gradle` exists (name, description, scripts, dependencies).30- Read `README.md` (first ~200 lines) if present.31- `Glob` top-level layout: `*`, `src/*`, `app/*`, `cmd/*`.32- `Glob`/`Grep` for structural markers (a `package.json` `bin` field, `.proto` files, etc.).3334### 2. Pick a template3536The six shipped templates are `webapp`, `cli`, `library`, `pipeline`, `protocol`, `blank`. Use this signal order (first strong match wins):3738- **cli** — `package.json` has `bin`; or `src/cli/` exists; or the entrypoint starts with a shebang.39- **webapp** — `src/routes/`, `src/app/api/`, `prisma/`, `src/controllers/`, or similar route/DB layout.40- **protocol** — `.proto` files, `proto/`, `messages/`, or state-machine naming.41- **pipeline** — `airflow/`, `dagster/`, `prefect/`, `src/jobs/`, or `src/workers/`.42- **library** — has `exports`/`main` in package.json, no `bin`, no server/route directories, tests-centric layout.43- **blank** — no strong match.4445### 3. Draft the intent4647Write 3–6 sentences describing the system. Ground it in what the README and manifest actually say — prefer quoting the README's own phrasing. Do not invent features that aren't in the source.4849### 4. Confirm with the user5051Use `AskUserQuestion` with two questions:52531. **Template** — options: your chosen template labeled "(Recommended)", one alternative if the repo straddles two, and `blank`.542. **Intent** — paste the drafted intent. Options: "Use this intent", "Let me edit". If the user picks "Let me edit", ask for the revised intent as free text before continuing.5556### 5. Invoke5758Run:5960 lens init --template <chosen> "<intent>"6162Stream output. If it exits non-zero, surface the error; do not proceed to step 6.6364### 6. Follow-up6566After `lens init` succeeds, tell the user:6768> Lens files were populated from your intent. For an existing codebase, run `/lens:pull` next to reflect the actual implementation into the lenses. Then review `.lenses/`, commit, and start iterating.6970Do not auto-run `lens pull` — it invokes the runner and can take a minute or more, so users should opt in.