@telpin-sistemas/orqen 0.0.0-stage → 0.1.3
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/README.md +99 -2
- package/dist/ai-worker.js +22 -0
- package/dist/commands/bootstrap.js +260 -0
- package/dist/commands/environment.js +119 -0
- package/dist/commands/eval.js +218 -0
- package/dist/commands/init.js +384 -0
- package/dist/commands/spec.js +100 -0
- package/dist/commands/swarm.js +180 -0
- package/dist/commands/tutorial.js +171 -0
- package/dist/commands/update.js +128 -0
- package/dist/commands/workflow.js +599 -0
- package/dist/connectors/asana.js +91 -0
- package/dist/connectors/config.js +99 -0
- package/dist/connectors/describe.js +13 -0
- package/dist/connectors/github.js +215 -0
- package/dist/connectors/index.js +23 -0
- package/dist/connectors/jira.js +119 -0
- package/dist/connectors/legacy.js +60 -0
- package/dist/connectors/types.js +41 -0
- package/dist/eval/cases.js +82 -0
- package/dist/eval/fake-jira.js +104 -0
- package/dist/eval/run.js +206 -0
- package/dist/index.js +152 -0
- package/dist/lib/agent.js +262 -0
- package/dist/lib/config.js +115 -0
- package/dist/lib/connectors-edit.js +79 -0
- package/dist/lib/connectors-setup.js +176 -0
- package/dist/lib/detect.js +448 -0
- package/dist/lib/env.js +52 -0
- package/dist/lib/general-settings.js +36 -0
- package/dist/lib/kit.js +241 -0
- package/dist/lib/lang.js +45 -0
- package/dist/lib/openspec.js +150 -0
- package/dist/lib/proc.js +91 -0
- package/dist/lib/processes.js +219 -0
- package/dist/lib/provider-credentials.js +37 -0
- package/dist/lib/repo-summary.js +116 -0
- package/dist/lib/stack.js +81 -0
- package/dist/lib/stage-guides.js +17 -0
- package/dist/lib/system.js +44 -0
- package/dist/lib/template-assets.js +3 -0
- package/dist/lib/tools-repository.js +60 -0
- package/dist/lib/tools.js +181 -0
- package/dist/lib/usage.js +136 -0
- package/dist/sdd/common.js +120 -0
- package/dist/sdd/index.js +20 -0
- package/dist/sdd/openspec.js +76 -0
- package/dist/sdd/speckit.js +46 -0
- package/dist/sdd/types.js +6 -0
- package/dist/swarm/git.js +161 -0
- package/dist/swarm/plan.js +163 -0
- package/dist/swarm/run.js +255 -0
- package/dist/template/.agents/.claude-plugin/plugin.json +6 -0
- package/dist/template/.agents/commands/analyze.md +35 -0
- package/dist/template/.agents/commands/approve.md +53 -0
- package/dist/template/.agents/commands/code-review.md +7 -0
- package/dist/template/.agents/commands/e2e-review.md +7 -0
- package/dist/template/.agents/commands/implement.md +60 -0
- package/dist/template/.agents/commands/list.md +27 -0
- package/dist/template/.agents/commands/pr.md +23 -0
- package/dist/template/.agents/commands/review.md +32 -0
- package/dist/template/.agents/commands/support.md +35 -0
- package/dist/template/.agents/commands/tutorial.md +33 -0
- package/dist/template/.agents/skills/grilling/SKILL.md +29 -0
- package/dist/template/AGENTS.md +145 -0
- package/dist/template/env.example +27 -0
- package/dist/template/openspec/config.yaml +27 -0
- package/dist/template/orqen/work/README.md +3 -0
- package/dist/template/stages/analysis.md +41 -0
- package/dist/template/stages/delivery.md +11 -0
- package/dist/template/stages/development.md +14 -0
- package/dist/template/stages/execution.md +16 -0
- package/dist/template/stages/specification.md +14 -0
- package/dist/template/stages/support.md +34 -0
- package/dist/template/stages/testing.md +11 -0
- package/dist/template/stages/verification.md +11 -0
- package/dist/tutorial/app.js +158 -0
- package/dist/tutorial/content.js +288 -0
- package/dist/tutorial/render.js +42 -0
- package/dist/ui/console.js +61 -0
- package/dist/ui/logo.js +541 -0
- package/dist/workflow/board.js +82 -0
- package/dist/workflow/config.js +94 -0
- package/dist/workflow/factory.js +54 -0
- package/dist/workflow/openspec.js +99 -0
- package/dist/workflow/process.js +1047 -0
- package/dist/workflow/schemas.js +114 -0
- package/dist/workflow/sql.js +18 -0
- package/dist/workflow/states.js +72 -0
- package/dist/workflow/store.js +55 -0
- package/dist/workflow/workspace.js +213 -0
- package/package.json +45 -4
package/README.md
CHANGED
|
@@ -1,3 +1,100 @@
|
|
|
1
|
-
#
|
|
1
|
+
# orqen CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
```sh
|
|
4
|
+
pnpm add -g @telpin-sistemas/orqen # or: npm i -g @telpin-sistemas/orqen
|
|
5
|
+
orqen init # Run from the repository you want to initialize
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
## Initialize a repository
|
|
9
|
+
|
|
10
|
+
`orqen init [dir]` runs the following setup:
|
|
11
|
+
|
|
12
|
+
1. Displays the ORQEN logo and checks Node (20.12 or later), Git, and a package manager. The animation needs a terminal with at least 92 columns and 23 rows. Press Enter to continue. Non-interactive terminals, CI, `--yes`, and `--no-animation` use the static logo.
|
|
13
|
+
2. Detects components and services from manifests such as `package.json`, `pom.xml`, and `pyproject.toml`, as well as Prisma and `.env.example`, including the command that starts each part (`npm run dev`, `npm start`…).
|
|
14
|
+
3. Uses an installed AI agent to review a short repository summary in the background. It validates the proposal with Zod. Use `--deep` to let the agent explore the repository or `--no-ai` to use automatic detection only.
|
|
15
|
+
4. Lets you confirm or edit components, the command that starts each part, tests, migrations, and seed commands.
|
|
16
|
+
5. Finds a compatible OpenSpec installation (version 2.x), installs it if needed, and runs `openspec init` for the selected tools with English artifact output.
|
|
17
|
+
6. Configures the connectors: the requests system the client sees and an optional issues system for the team (Jira, GitHub or Asana). It asks for the project/filter and the account, checks them against the tool and, if the check fails, lets you fix them, save them anyway or skip (`orqen connectors setup` later). The selection goes to `orqen/config.yaml`; provider accounts go to `~/.orqen/providers.env`, shared across repositories (Enter keeps an existing token). Existing connectors and general settings are kept by default. `orqen connectors` checks the configured resources.
|
|
18
|
+
7. Writes the environment configuration (no Docker in between), agent instructions, plugin, stage guides, and manifest. It merges the OpenSpec workflow rules with the repository's existing configuration.
|
|
19
|
+
|
|
20
|
+
`init` configures an existing project without requesting, cloning or reading the external stack catalog. It reuses any database scripts already installed in the project; new service scripts come from `bootstrap`.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
Other options include `--agent "<command>"`, `--tools claude,codex`, `--no-openspec`, `--no-connectors` (skip the step), and `--connectors <file|->` (connectors as JSON, same format as `orqen connectors set`, for non-interactive runs; `--yes` alone keeps the current ones). Non-interactive runs use the defaults. If a managed file conflicts, `--yes` writes the proposed version alongside the original.
|
|
24
|
+
|
|
25
|
+
## Create a new project
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
orqen bootstrap "Payments Platform" [--tools-repo @company/tools] [--stack <id>] [--dir ./payments] [--yes]
|
|
29
|
+
orqen bootstrap --list
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Asks the name, folder and stack; checks the stack requirements and asks its parameters (ports, Java package); creates the
|
|
33
|
+
folder and Git repository; generates the code (official generators plus the stack skeleton); copies the environment scripts
|
|
34
|
+
to `orqen/tools/` (e.g. `orqen/tools/db.mjs`, the database in Docker); runs `orqen init` with the stack and environments already known;
|
|
35
|
+
and offers the initial commit.
|
|
36
|
+
|
|
37
|
+
On first use, `bootstrap` asks for your GitHub stack repository (for example `@company/stacks`); its name can be anything. Git clones it into `cli/tools/` beside this CLI installation using your own HTTPS credential helper or SSH key. You need access to that repository. The clone is reused, ignored by Git and excluded from the npm package; no catalog is bundled. Each stack has `<id>/tool.yaml` and its scaffold, with shared scripts in `_shared/`.
|
|
38
|
+
|
|
39
|
+
For non-interactive first use of `bootstrap`, pass `--tools-repo @company/tools` or set `ORQEN_TOOLS_REPO`. HTTPS and SSH GitHub URLs are also accepted. To refresh it, use `git -C tools pull --ff-only` from the CLI installation directory. To select a different repository, move the existing clone aside first.
|
|
40
|
+
|
|
41
|
+
## Update an installation
|
|
42
|
+
|
|
43
|
+
`orqen update [dir]` checks for a newer CLI, a compatible OpenSpec update, and kit changes. The kit updates files that still match the manifest. For edited files, you can keep the existing version, replace it, or write a copy with the `.orqen-new` suffix.
|
|
44
|
+
|
|
45
|
+
Use `--no-cli`, `--no-openspec`, or `--no-kit` to skip a step. Run `orqen init` again when you need to detect the stack or regenerate the environment.
|
|
46
|
+
|
|
47
|
+
## Work with an environment
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
orqen env setup
|
|
51
|
+
orqen env up [--all]
|
|
52
|
+
orqen env test [unitarios|integracion|e2e|visual]
|
|
53
|
+
orqen env status
|
|
54
|
+
orqen env down
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`up` starts the processes in `entornos.procesos` in the background (`--all` includes the `cuando: e2e` ones, such as the frontend), waits until each one responds on its port, URL, or log line, then runs migrations and seed commands. `down` stops what orqen started; `status` shows what is running and where each log is (`orqen/state/logs/`). The test commands receive variables from `entornos.variables` in `orqen/config.yaml`. The values `unitarios` and `integracion` select unit and integration tests.
|
|
58
|
+
|
|
59
|
+
## Split a task across a swarm of agents
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
orqen swarm "Add CSV export to the payments list, with date filters and tests"
|
|
63
|
+
orqen swarm --file task.md --parallel 6 --plan-only # write the plan only
|
|
64
|
+
orqen swarm --plan orqen/state/swarm/<run>/plan.json # run a reviewed plan
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
A planner model (default Opus) splits the task into a dependency graph of small subtasks, each with the files it touches and a fast test. After the person confirms, subtasks run in parallel in separate git worktrees: the small model (default Haiku) gets two attempts, then the subtask escalates to the large model (default Sonnet) with the failure output. Each passing subtask is committed and merged into `orqen/swarm-<run>`; dependents start on top of merged code. Finally the plan's `finalTest` runs on the integration branch, and the large model fixes it if needed. The report and every attempt's log are in `orqen/state/swarm/<run>/`. Run `orqen swarm --help` for all options.
|
|
68
|
+
|
|
69
|
+
## Process a request
|
|
70
|
+
|
|
71
|
+
```sh
|
|
72
|
+
orqen list requests
|
|
73
|
+
orqen analyze SOP-1234
|
|
74
|
+
orqen status DEV-442
|
|
75
|
+
orqen take DEV-442
|
|
76
|
+
orqen complete DEV-442 output.json
|
|
77
|
+
orqen cycle --loop
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`orqen take` in `DEVELOPMENT` prepares the branch, dependencies, and services. The agent context includes connection variables and test commands under `environment`. If preparation fails, see `environment.detail` or `environment.output`. `orqen complete` stops the environment after development.
|
|
81
|
+
|
|
82
|
+
In `TESTING`, taking the stage starts the full environment, runs the configured suite, and shuts everything down. `orqen cycle --loop` dispatches eligible requests using `AGENT_CMD`. Analysis always requires an analyst.
|
|
83
|
+
|
|
84
|
+
In the full lane, QA runs `/orqen:review <KEY>` in `QA_REVIEW` and records the decision with `orqen review <KEY> approve|reject`; the direct and light lanes skip QA. Run `orqen pr <KEY>` to inspect the integration target or add an explanation file to open the PR to `DEVEL_BRANCH`; testing opens no PR, so this is the PR the senior reviews. In `CODE_REVIEW`, the senior runs `/orqen:code-review <KEY>`, and `orqen code-review <KEY> <report.md> --verdict <approve|minor|reject>` records the report under `orqen/work/<KEY>/round-N/` and comments it on the internal ticket (or the external one) without changing the stage.
|
|
85
|
+
|
|
86
|
+
For an existing checkout, the CLI also reads `cli/.env` and its local state under `cli/.state/`. Use `template/env.example` as the starting point for that configuration.
|
|
87
|
+
|
|
88
|
+
## Develop locally
|
|
89
|
+
|
|
90
|
+
From this directory:
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
npm ci
|
|
94
|
+
npm run dev -- --help
|
|
95
|
+
npm run test:e2e # Complete CLI journeys through CLOSED; local external-service fixtures
|
|
96
|
+
npm test
|
|
97
|
+
npm run typecheck
|
|
98
|
+
npm run build
|
|
99
|
+
npm run setup # Build and link the local CLI as orqen
|
|
100
|
+
```
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run quick stack analysis for orqen init in a detached process.
|
|
3
|
+
*
|
|
4
|
+
* Keep the agent and its subprocesses separate from the terminal
|
|
5
|
+
* while the user answers setup prompts. The worker writes its result
|
|
6
|
+
* to a file for the main process.
|
|
7
|
+
*
|
|
8
|
+
* Internal usage: node ai-worker.js <job.json>
|
|
9
|
+
* job.json = { repo, comando, deteccion, salida }
|
|
10
|
+
*/
|
|
11
|
+
import { readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
12
|
+
import { explorarRapido } from "./lib/agent.js";
|
|
13
|
+
const trabajo = JSON.parse(readFileSync(process.argv[2], "utf8"));
|
|
14
|
+
let r;
|
|
15
|
+
try {
|
|
16
|
+
r = await explorarRapido(trabajo.repo, trabajo.comando, trabajo.deteccion, { timeoutMs: trabajo.timeoutMs });
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
r = { ok: false, errores: [e.message], salida: "" };
|
|
20
|
+
}
|
|
21
|
+
writeFileSync(trabajo.salida + ".tmp", JSON.stringify(r));
|
|
22
|
+
renameSync(trabajo.salida + ".tmp", trabajo.salida); // Rename atomically so init reads a complete result.
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* orqen bootstrap: bootstrap a new project from a tool of the catalog.
|
|
3
|
+
*
|
|
4
|
+
* 1. Ask the project name, the folder and the stack (tool).
|
|
5
|
+
* 2. Check the stack requirements (node, mvn, docker…) and ask its parameters (ports, Java package…).
|
|
6
|
+
* 3. Create the folder and the Git repo, generate the code (official generators + the tool's skeleton)
|
|
7
|
+
* and copy the tool scripts to orqen/tools/ (e.g. orqen/tools/db.mjs to run the database in Docker).
|
|
8
|
+
* 4. Run `orqen init` with the stack and environments already known (no detection or AI needed).
|
|
9
|
+
* 5. Offer the initial commit.
|
|
10
|
+
*/
|
|
11
|
+
import { existsSync, mkdirSync, readdirSync, writeFileSync } from "node:fs";
|
|
12
|
+
import { join, resolve } from "node:path";
|
|
13
|
+
import { ejecutar } from "../lib/proc.js";
|
|
14
|
+
import { puertoAbierto } from "../lib/processes.js";
|
|
15
|
+
import { cargarTool, chequearRequisitos, copiarCarpeta, instalarTools, listarTools, parametrosDe, render, TOOLS_DIR, validarParametro, variablesBase, } from "../lib/tools.js";
|
|
16
|
+
import { prepararTools } from "../lib/tools-repository.js";
|
|
17
|
+
import { VERSION_CLI } from "../lib/system.js";
|
|
18
|
+
import { mostrarLogo } from "../ui/logo.js";
|
|
19
|
+
import { azul, confirmar, elegir, gris, interactivo, magenta, p, pc, textoValidado, tick } from "../ui/console.js";
|
|
20
|
+
import { init } from "./init.js";
|
|
21
|
+
import { spawn } from "node:child_process";
|
|
22
|
+
/** Missing requirements that prevent creating the code: the commands its generators run, and node. */
|
|
23
|
+
export function bloqueantes(tool, req) {
|
|
24
|
+
const paraCrear = new Set(tool.scaffold.flatMap((s) => ("correr" in s ? [s.correr.split(/\s+/)[0]] : [])));
|
|
25
|
+
return req.filter((r) => !r.ok && (paraCrear.has(r.comando) || r.comando === "node"));
|
|
26
|
+
}
|
|
27
|
+
/** `orqen bootstrap --list --json` and `--describe <stack> --json`, for tools such as orqen-gui. Errors are JSON too. */
|
|
28
|
+
async function bootstrapJson(o) {
|
|
29
|
+
const fail = (error, extra = {}) => { console.log(JSON.stringify({ error, ...extra })); process.exitCode = 1; };
|
|
30
|
+
try {
|
|
31
|
+
await prepararTools(o.toolsRepo, true);
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
return fail(e.message, { needsRepo: !existsSync(TOOLS_DIR) });
|
|
35
|
+
}
|
|
36
|
+
const stacks = listarTools();
|
|
37
|
+
if (!o.describir)
|
|
38
|
+
return console.log(JSON.stringify({ stacks, dir: TOOLS_DIR }));
|
|
39
|
+
const stack = stacks.find((t) => t.id === o.describir);
|
|
40
|
+
if (!stack)
|
|
41
|
+
return fail(`Unknown stack "${o.describir}". Available: ${stacks.map((t) => t.id).join(", ")}`);
|
|
42
|
+
const base = variablesBase(o.nombre || "Project");
|
|
43
|
+
const vars = { ...base };
|
|
44
|
+
const parametros = [];
|
|
45
|
+
for (const prm of parametrosDe(stack.id, base)) {
|
|
46
|
+
const defecto = prm.tipo === "puerto" ? String(await puertoLibre(Number(prm.defecto))) : prm.defecto;
|
|
47
|
+
vars[prm.id] = defecto;
|
|
48
|
+
parametros.push({ id: prm.id, pregunta: prm.pregunta, tipo: prm.tipo, defecto, enUso: prm.tipo === "puerto" && defecto !== prm.defecto ? prm.defecto : undefined });
|
|
49
|
+
}
|
|
50
|
+
if (vars.PAQUETE)
|
|
51
|
+
vars.PAQUETE_RUTA = vars.PAQUETE.replaceAll(".", "/");
|
|
52
|
+
let tool;
|
|
53
|
+
try {
|
|
54
|
+
tool = cargarTool(stack.id, vars);
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
return fail(e.message);
|
|
58
|
+
}
|
|
59
|
+
const req = chequearRequisitos(tool);
|
|
60
|
+
const bloquea = new Set(bloqueantes(tool, req).map((r) => r.comando));
|
|
61
|
+
console.log(JSON.stringify({
|
|
62
|
+
stack, carpeta: base.PROYECTO_ID, parametros,
|
|
63
|
+
requisitos: req.map((r) => ({ ...r, bloquea: bloquea.has(r.comando) })),
|
|
64
|
+
procesos: tool.entornos.procesos.map((x) => ({ nombre: x.nombre, comando: x.comando, ruta: x.ruta, cuando: x.cuando })),
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
const vacio = (dir) => !existsSync(dir) || readdirSync(dir).length === 0;
|
|
68
|
+
/** Next free port from `desde`. */
|
|
69
|
+
async function puertoLibre(desde) {
|
|
70
|
+
for (let n = desde; n < desde + 50; n++)
|
|
71
|
+
if (!(await puertoAbierto(n, 300)))
|
|
72
|
+
return n;
|
|
73
|
+
return desde;
|
|
74
|
+
}
|
|
75
|
+
/** Run a shell command in the project, keeping the last output lines for errors. */
|
|
76
|
+
function correr(cmd, cwd) {
|
|
77
|
+
return new Promise((ok) => {
|
|
78
|
+
let salida = "";
|
|
79
|
+
const h = spawn(cmd, { cwd, shell: true, windowsHide: true, stdio: ["ignore", "pipe", "pipe"], env: { ...process.env, CI: "1" } });
|
|
80
|
+
h.stdout?.on("data", (d) => (salida = (salida + d).slice(-8000)));
|
|
81
|
+
h.stderr?.on("data", (d) => (salida = (salida + d).slice(-8000)));
|
|
82
|
+
h.on("error", (e) => ok({ ok: false, cola: e.message }));
|
|
83
|
+
h.on("close", (c) => ok({ ok: c === 0, cola: salida.split(/\r?\n/).filter(Boolean).slice(-15).join("\n") }));
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
export async function bootstrap(o) {
|
|
87
|
+
if (o.json && (o.listar || o.describir))
|
|
88
|
+
return bootstrapJson(o);
|
|
89
|
+
const yes = !!o.yes || !interactivo();
|
|
90
|
+
if (!o.listar) {
|
|
91
|
+
await mostrarLogo({
|
|
92
|
+
animar: !o.sinAnimacion && !o.yes, esperarTecla: true,
|
|
93
|
+
bienvenida: [
|
|
94
|
+
"Bootstrap will:",
|
|
95
|
+
" • Ask the name and the stack, and generate the code with the official generators",
|
|
96
|
+
" • Add the tools that start its environments (database in Docker, servers…)",
|
|
97
|
+
" • Leave the repository ready for agents (orqen init, OpenSpec, connectors)",
|
|
98
|
+
],
|
|
99
|
+
});
|
|
100
|
+
p.intro(`${azul("orqen")} ${magenta("bootstrap")} ${gris(`v${VERSION_CLI}`)}`);
|
|
101
|
+
if (!o.yes && !interactivo())
|
|
102
|
+
p.log.warn("Non-interactive terminal. Using defaults as with --yes.");
|
|
103
|
+
}
|
|
104
|
+
// 1. Name, folder and stack.
|
|
105
|
+
await prepararTools(o.toolsRepo, yes);
|
|
106
|
+
const tools = listarTools();
|
|
107
|
+
if (!tools.length) {
|
|
108
|
+
p.cancel(`No tools found in ${TOOLS_DIR}.`);
|
|
109
|
+
process.exitCode = 1;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (o.listar) {
|
|
113
|
+
for (const t of tools)
|
|
114
|
+
console.log(`${pc.bold(t.id.padEnd(24))} ${t.nombre}\n${" ".repeat(25)}${gris(t.descripcion)}`);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const nombre = o.nombre ?? (yes ? "" : await textoValidado("Project name", "", (v) => (/^[\p{L}\p{N}][\p{L}\p{N} _.-]*$/u.test(v) ? undefined : "Use letters, numbers, spaces, dots, dashes or underscores"), "Plataforma de Pagos"));
|
|
118
|
+
if (!nombre) {
|
|
119
|
+
p.cancel("A project name is required (orqen bootstrap <name>).");
|
|
120
|
+
process.exitCode = 1;
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const base = variablesBase(nombre);
|
|
124
|
+
const dir = resolve(o.dir ?? (yes ? base.PROYECTO_ID : await textoValidado("Folder", base.PROYECTO_ID, (v) => (v ? undefined : "Required"))));
|
|
125
|
+
if (!vacio(dir)) {
|
|
126
|
+
p.cancel(`${dir} already exists and is not empty. Choose another folder (--dir).`);
|
|
127
|
+
process.exitCode = 1;
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
let stackId = o.stack;
|
|
131
|
+
if (stackId && !tools.some((t) => t.id === stackId)) {
|
|
132
|
+
p.cancel(`Unknown stack "${stackId}". Available: ${tools.map((t) => t.id).join(", ")}`);
|
|
133
|
+
process.exitCode = 1;
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
stackId ??= await elegir("Stack", tools.map((t) => ({ value: t.id, label: t.nombre, hint: t.descripcion })), tools[0].id, yes);
|
|
137
|
+
// 2. Parameters (ports are checked against what is already running) and requirements.
|
|
138
|
+
const vars = { ...base };
|
|
139
|
+
for (const prm of parametrosDe(stackId, base)) {
|
|
140
|
+
let def = prm.defecto;
|
|
141
|
+
if (prm.tipo === "puerto") {
|
|
142
|
+
const libre = await puertoLibre(Number(def));
|
|
143
|
+
if (String(libre) !== def)
|
|
144
|
+
p.log.info(`Port ${def} is in use: proposing ${libre} for "${prm.pregunta}".`);
|
|
145
|
+
def = String(libre);
|
|
146
|
+
}
|
|
147
|
+
const dado = o.parametros?.[prm.id];
|
|
148
|
+
if (dado !== undefined) {
|
|
149
|
+
const error = validarParametro(prm.tipo, dado);
|
|
150
|
+
if (error) {
|
|
151
|
+
p.cancel(`${prm.pregunta}: ${error}`);
|
|
152
|
+
process.exitCode = 1;
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
vars[prm.id] = dado ?? (yes ? def : await textoValidado(prm.pregunta, def, (v) => validarParametro(prm.tipo, v)));
|
|
157
|
+
}
|
|
158
|
+
if (vars.PAQUETE)
|
|
159
|
+
vars.PAQUETE_RUTA = vars.PAQUETE.replaceAll(".", "/");
|
|
160
|
+
let tool;
|
|
161
|
+
try {
|
|
162
|
+
tool = cargarTool(stackId, vars);
|
|
163
|
+
}
|
|
164
|
+
catch (e) {
|
|
165
|
+
p.cancel(e.message);
|
|
166
|
+
process.exitCode = 1;
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const req = chequearRequisitos(tool);
|
|
170
|
+
p.note(req.map((r) => `${tick(r.ok, r.comando !== "docker")} ${r.comando.padEnd(8)} ${gris(r.detalle)}`).join("\n"), "Requirements");
|
|
171
|
+
// To create the code you need the commands its generators run; Docker is only needed to run the database.
|
|
172
|
+
const bloquean = bloqueantes(tool, req);
|
|
173
|
+
if (bloquean.length && !o.sinComandos) {
|
|
174
|
+
p.cancel(bloquean.map((r) => `${r.comando}: ${r.ayuda ?? r.detalle}`).join("\n"));
|
|
175
|
+
process.exitCode = 1;
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
for (const r of req.filter((r) => !r.ok && !bloquean.includes(r)))
|
|
179
|
+
p.log.warn(`${r.comando}: ${r.ayuda ?? r.detalle}. The project is created anyway; you need it to run it.`);
|
|
180
|
+
p.note([
|
|
181
|
+
`${pc.bold(vars.PROYECTO)} ${gris(dir)}`,
|
|
182
|
+
`${tool.nombre} ${gris(`(${tool.id})`)}`,
|
|
183
|
+
...tool.parametros.map((x) => `${x.pregunta}: ${pc.cyan(vars[x.id])}`),
|
|
184
|
+
"",
|
|
185
|
+
gris("How it will start:"),
|
|
186
|
+
...tool.entornos.procesos.map((x) => ` ${x.nombre}: ${x.comando}${x.ruta !== "." ? gris(` (in ${x.ruta})`) : ""}${x.cuando === "e2e" ? gris(" [e2e only]") : ""}`),
|
|
187
|
+
].join("\n"), "New project");
|
|
188
|
+
if (!(await confirmar("Create it?", true, yes))) {
|
|
189
|
+
p.outro("Canceled. Nothing was created.");
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
// 3. Folder, Git and code.
|
|
193
|
+
mkdirSync(dir, { recursive: true });
|
|
194
|
+
ejecutar("git", ["init", "-q", "-b", "main"], { cwd: dir });
|
|
195
|
+
const s = p.spinner();
|
|
196
|
+
for (const paso of tool.scaffold) {
|
|
197
|
+
if ("copiar" in paso) {
|
|
198
|
+
const n = copiarCarpeta(join(TOOLS_DIR, stackId, paso.copiar), dir, vars).length;
|
|
199
|
+
p.log.success(`Project skeleton (${n} files)`);
|
|
200
|
+
}
|
|
201
|
+
else if ("archivo" in paso) {
|
|
202
|
+
const ruta = join(dir, render(paso.archivo, vars));
|
|
203
|
+
mkdirSync(join(ruta, ".."), { recursive: true });
|
|
204
|
+
writeFileSync(ruta, paso.contenido);
|
|
205
|
+
}
|
|
206
|
+
else if (!o.sinComandos) {
|
|
207
|
+
const inicio = Date.now(), etiqueta = paso.descripcion ?? paso.correr;
|
|
208
|
+
// Without a terminal (CI, tests) a spinner floods the output with frames: plain log lines instead.
|
|
209
|
+
const tty = interactivo();
|
|
210
|
+
if (tty)
|
|
211
|
+
s.start(`${etiqueta}…`);
|
|
212
|
+
else
|
|
213
|
+
p.log.step(`${etiqueta}…`);
|
|
214
|
+
const reloj = tty ? setInterval(() => s.message(`${etiqueta}… ${Math.round((Date.now() - inicio) / 1000)}s`), 1000) : undefined;
|
|
215
|
+
const r = await correr(paso.correr, paso.en ? join(dir, paso.en) : dir);
|
|
216
|
+
clearInterval(reloj);
|
|
217
|
+
if (!r.ok) {
|
|
218
|
+
if (tty)
|
|
219
|
+
s.error(`Failed: ${paso.correr}`);
|
|
220
|
+
else
|
|
221
|
+
p.log.error(`Failed: ${paso.correr}`);
|
|
222
|
+
p.log.message(gris(r.cola));
|
|
223
|
+
p.cancel(`The project folder was left at ${dir} so you can check what happened. Delete it to start over.`);
|
|
224
|
+
process.exitCode = 1;
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const fin = `${etiqueta} ${gris(`(${Math.round((Date.now() - inicio) / 1000)}s)`)}`;
|
|
228
|
+
if (tty)
|
|
229
|
+
s.stop(fin);
|
|
230
|
+
else
|
|
231
|
+
p.log.success(fin);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const scripts = instalarTools(dir, tool, vars);
|
|
235
|
+
p.log.success(`Environment tools: ${scripts.join(", ")}`);
|
|
236
|
+
// 4. orqen init with the known stack and environments.
|
|
237
|
+
p.log.step("Preparing the repository for agents (orqen init)…");
|
|
238
|
+
await init({
|
|
239
|
+
dir, yes, sinAnimacion: true, sinLogo: true, sinOpenspec: o.sinOpenspec, herramientas: o.herramientas,
|
|
240
|
+
predefinido: { stack: tool.stack, entornos: tool.entornos },
|
|
241
|
+
});
|
|
242
|
+
if (process.exitCode)
|
|
243
|
+
return;
|
|
244
|
+
// 5. Initial commit.
|
|
245
|
+
if (await confirmar("Make the initial commit?", true, yes)) {
|
|
246
|
+
ejecutar("git", ["add", "-A"], { cwd: dir });
|
|
247
|
+
const c = ejecutar("git", ["commit", "-q", "-m", `Create ${vars.PROYECTO} with orqen (${tool.id})`], { cwd: dir });
|
|
248
|
+
if (c.codigo === 0)
|
|
249
|
+
p.log.success("Initial commit created on main");
|
|
250
|
+
else
|
|
251
|
+
p.log.warn(`Could not commit (${(c.stderr || c.stdout).trim().split("\n")[0]}). Configure git user.name and user.email and commit by hand.`);
|
|
252
|
+
}
|
|
253
|
+
p.note([
|
|
254
|
+
`${pc.bold("1.")} ${pc.cyan(`cd ${dir}`)}`,
|
|
255
|
+
`${pc.bold("2.")} ${pc.cyan("orqen env up")} ${gris("starts the database and the backend and runs the migrations (--all: also the frontend)")}`,
|
|
256
|
+
`${pc.bold("3.")} ${pc.cyan("orqen env test")} ${gris("· orqen env down when you are done")}`,
|
|
257
|
+
`${pc.bold("4.")} ${gris("Push it to your Git remote and start working on requests: /orqen:analyze <KEY> (new to orqen? run /orqen:tutorial in Claude Code)")}`,
|
|
258
|
+
].join("\n"), "Next steps");
|
|
259
|
+
p.outro(`${magenta("//")} ${pc.bold(`${vars.PROYECTO} is ready.`)}`);
|
|
260
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* orqen env: start the project and run its tests without a person at the keyboard (used by the workflow and agents).
|
|
3
|
+
* setup install dependencies (entornos.preparar)
|
|
4
|
+
* up [--all] start the processes (npm run dev, npm start…) and wait until they are ready; then migrations and seed.
|
|
5
|
+
* --all: also the processes that are only for e2e / visual tests (e.g. the frontend)
|
|
6
|
+
* test [type...] unitarios / integracion / e2e / visual with the variables in entornos.variables
|
|
7
|
+
* `-- <args>`: appended to the command of the requested type (e.g. only the e2e of a change)
|
|
8
|
+
* status which processes are running
|
|
9
|
+
* down stop the processes orqen started
|
|
10
|
+
*/
|
|
11
|
+
import { resolve } from "node:path";
|
|
12
|
+
import { leerConfig } from "../lib/config.js";
|
|
13
|
+
import { ejecutarLinea } from "../lib/proc.js";
|
|
14
|
+
import { bajarProcesos, estadoProcesos, levantarProcesos } from "../lib/processes.js";
|
|
15
|
+
import { pc } from "../ui/console.js";
|
|
16
|
+
const TIPOS = ["unitarios", "integracion", "e2e", "visual"];
|
|
17
|
+
const titulo = (s) => console.log(`\n${pc.bold(pc.magenta("▸"))} ${pc.bold(s)}`);
|
|
18
|
+
async function correr(repo, cfg, lineas, etiqueta) {
|
|
19
|
+
const env = { ...process.env, ...cfg.entornos.variables };
|
|
20
|
+
for (const l of lineas) {
|
|
21
|
+
titulo(`${etiqueta}: ${l}`);
|
|
22
|
+
const c = await ejecutarLinea(l, { cwd: repo, env });
|
|
23
|
+
if (c !== 0) {
|
|
24
|
+
console.error(pc.red(`✘ ${etiqueta} failed (exit code ${c}): ${l}`));
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
/** Quotes an argument for the shell line only when it needs it. */
|
|
31
|
+
const citar = (a) => /^[\w@%+=:,./-]+$/.test(a) ? a : `"${a.replace(/(["\\$`])/g, "\\$1")}"`;
|
|
32
|
+
export async function entorno(sub, resto, o) {
|
|
33
|
+
const repo = resolve(o.dir ?? process.cwd());
|
|
34
|
+
const cfg = leerConfig(repo);
|
|
35
|
+
const e = cfg.entornos;
|
|
36
|
+
let ok = true;
|
|
37
|
+
switch (sub) {
|
|
38
|
+
case "setup":
|
|
39
|
+
ok = await correr(repo, cfg, e.preparar, "install dependencies");
|
|
40
|
+
break;
|
|
41
|
+
case "up": {
|
|
42
|
+
if (!e.procesos.length)
|
|
43
|
+
console.log(pc.dim("No processes configured in orqen/config.yaml (entornos.procesos)."));
|
|
44
|
+
const r = await levantarProcesos(repo, e.procesos, e.variables, { todos: o.todos, alAvanzar: (m) => titulo(m) });
|
|
45
|
+
if (!r.ok) {
|
|
46
|
+
console.error(pc.red(`✘ ${r.detalle}`));
|
|
47
|
+
if (r.salida)
|
|
48
|
+
console.error(pc.dim(r.salida));
|
|
49
|
+
ok = false;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
ok = await correr(repo, cfg, e.migrar, "run migrations") && await correr(repo, cfg, e.seed, "seed");
|
|
53
|
+
if (ok) {
|
|
54
|
+
console.log(pc.green(`\n✔ ${r.detalle}`));
|
|
55
|
+
const vars = Object.entries(e.variables);
|
|
56
|
+
if (vars.length)
|
|
57
|
+
console.log(pc.dim(vars.map(([k, v]) => ` ${k}=${v}`).join("\n")));
|
|
58
|
+
console.log(pc.dim(" To stop them: orqen env down"));
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
case "test": {
|
|
63
|
+
const pedidos = (resto.length ? resto : TIPOS.filter((t) => e.tests[t]));
|
|
64
|
+
const invalidos = pedidos.filter((t) => !TIPOS.includes(t));
|
|
65
|
+
if (invalidos.length)
|
|
66
|
+
throw new Error(`Invalid test type: ${invalidos.join(", ")}. Options: ${TIPOS.join(", ")}`);
|
|
67
|
+
if (!pedidos.length)
|
|
68
|
+
throw new Error("No test commands are configured in orqen/config.yaml (entornos.tests).");
|
|
69
|
+
const extra = o.extra ?? [];
|
|
70
|
+
if (extra.length && !resto.length)
|
|
71
|
+
throw new Error("Name the test type the arguments after `--` are for, e.g. orqen env test e2e -- tests/login.spec.ts");
|
|
72
|
+
const resultados = [];
|
|
73
|
+
for (const t of pedidos) {
|
|
74
|
+
const cmd = e.tests[t];
|
|
75
|
+
if (!cmd) {
|
|
76
|
+
resultados.push([t, null]);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const linea = extra.length ? `${cmd} ${extra.map(citar).join(" ")}` : cmd;
|
|
80
|
+
resultados.push([t, await correr(repo, cfg, [linea], `tests ${t}`)]);
|
|
81
|
+
}
|
|
82
|
+
console.log("\n" + resultados.map(([t, r]) => `${r === null ? pc.yellow("–") : r ? pc.green("✔") : pc.red("✘")} ${t}${r === null ? pc.dim(" (no command configured in orqen/config.yaml)") : ""}`).join("\n"));
|
|
83
|
+
ok = resultados.every(([, r]) => r !== false);
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
case "status": {
|
|
87
|
+
const st = await estadoProcesos(repo, e.procesos);
|
|
88
|
+
if (o.json) {
|
|
89
|
+
console.log(JSON.stringify({ processes: st, variables: e.variables, tests: e.tests }, null, 2));
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
if (!st.length)
|
|
93
|
+
console.log(pc.dim("No processes configured in orqen/config.yaml (entornos.procesos)."));
|
|
94
|
+
for (const x of st)
|
|
95
|
+
console.log(`${x.corriendo ? pc.green("●") : pc.dim("○")} ${x.nombre.padEnd(16)} ${pc.dim(x.comando)}${x.puerto ? pc.dim(` :${x.puerto}`) : ""}${x.cuando === "e2e" ? pc.dim(" (e2e only)") : ""}${x.log ? pc.dim(`\n log: ${x.log}`) : ""}`);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
case "down": {
|
|
99
|
+
const bajados = bajarProcesos(repo);
|
|
100
|
+
console.log(bajados.length ? pc.green(`✔ Stopped: ${bajados.join(", ")}`) : pc.dim("No processes started by orqen are running."));
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
default:
|
|
104
|
+
console.log([
|
|
105
|
+
"Usage: orqen env <command>",
|
|
106
|
+
" setup install dependencies (entornos.preparar)",
|
|
107
|
+
" up [--all] start the processes and wait until they are ready, then migrate and seed (--all: include e2e-only processes)",
|
|
108
|
+
" test [type...] unitarios | integracion | e2e | visual (default: all configured tests)",
|
|
109
|
+
" -- <args>: appended to that type's command, e.g. orqen env test e2e -- tests/login.spec.ts",
|
|
110
|
+
" status show which processes are running and where their logs are",
|
|
111
|
+
" down stop the processes orqen started",
|
|
112
|
+
].join("\n"));
|
|
113
|
+
if (sub)
|
|
114
|
+
process.exitCode = 1;
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (!ok)
|
|
118
|
+
process.exitCode = 1;
|
|
119
|
+
}
|