@turri-dev/cli 0.5.2-next.2bba3d7 → 0.6.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.
@@ -1,11 +1,14 @@
1
+ import { spawn } from "node:child_process";
1
2
  import { existsSync } from "node:fs";
3
+ import { join, relative, resolve } from "node:path";
2
4
  import { createInterface } from "node:readline/promises";
3
5
  import { BEDROCK_DEFAULT, BEDROCK_IN_REGION, VENDORS, bedrockDefaultModels, bedrockMakers, bedrockModels, bedrockModelsIn, bedrockPlaceOf, hasBedrockPreset, makerLabel, piModelCatalogue, bedrockMakerOf, bedrockRegionOf, priced, vendorOf } from "@turri-dev/core/models";
4
- import { initConfig } from "@turri-dev/core/project";
6
+ import { globalModels, initConfig } from "@turri-dev/core/project";
5
7
  import { brand } from "./brand.js";
6
8
  const USAGE = [
7
9
  "usage: turri init-config [--vendor anthropic|openai|google|amazon-bedrock|other] [--maker <maker>] [--region <geography>]",
8
10
  " [--harness-model <spec> --coding-model <spec> [--judge-model <spec>]] [--force] [--global | folder]",
11
+ " turri init-config --existing-codebase [options] [codebase]",
9
12
  "",
10
13
  "Write a quick start config.turri.yaml in the folder, the current one by default: the model you talk to and the one that",
11
14
  "writes the code, from the vendor you use. Asked when --vendor is not given and this is a terminal; otherwise other -",
@@ -15,12 +18,18 @@ const USAGE = [
15
18
  "pair or the catalogue's offered first. --harness-model and --coding-model name the two instead, as provider/model-id",
16
19
  "without a thinking level - amazon-bedrock/global.xai.grok-4.7 - any pi's catalogue has; --judge-model the strong one",
17
20
  "the judging examples name, the harness model unless given. The vendor, maker and region are read from them.",
21
+ "With none of these, and your global config naming both models, the project takes them from there: nothing is asked,",
22
+ "and its file names no models of its own.",
18
23
  "A config.turri.yaml already there keeps everything but its two models; --force writes the whole of it again. A new",
19
24
  "one takes from a config.yaml beside it - another tool's, say - the keys turri reads too, its testing scripts say, and leaves",
20
25
  "config.yaml as it is.",
21
26
  "",
22
27
  "--global writes your global config instead, ~/.turri/config.turri.yaml: turri reads it under every project's",
23
28
  "config.turri.yaml, and a project's own file overrides any key of it.",
29
+ "",
30
+ "--existing-codebase sets turri up to work on a codebase you have - the folder named, the current one by default: the",
31
+ "project goes in plain/ inside it, its config.turri.yaml saying build-into: .., so every module is built in the codebase",
32
+ "itself, on the code there. Then it asks whether to start turri in plain/.",
24
33
  ].join("\n");
25
34
  /** Ask until the answer is one `read` takes. */
26
35
  async function askUntil(rl, prompt, read, again) {
@@ -131,15 +140,22 @@ export async function main(args) {
131
140
  const taken = new Set(Object.values(flags).flatMap((flag) => flag.at));
132
141
  const rest = args.filter((arg, index) => !arg.startsWith("-") && !taken.has(index));
133
142
  const global = args.includes("--global");
143
+ const existingCodebase = args.includes("--existing-codebase");
144
+ if (global && existingCodebase) {
145
+ console.error(`--existing-codebase writes a project's config, --global yours: give one.\n\n${USAGE}`);
146
+ return 1;
147
+ }
134
148
  if (global && rest[0] !== undefined) {
135
149
  console.error(`--global writes ~/.turri/config.turri.yaml: name no folder with it.\n\n${USAGE}`);
136
150
  return 1;
137
151
  }
138
- const folder = rest[0] ?? process.cwd();
139
- if (!existsSync(folder)) {
140
- console.error(`${folder} does not exist.`);
152
+ const given = rest[0] ?? process.cwd();
153
+ if (!existsSync(given)) {
154
+ console.error(`${given} does not exist.`);
141
155
  return 1;
142
156
  }
157
+ // An existing codebase: the project is plain/ in it, built into the codebase around it.
158
+ const folder = existingCodebase ? join(resolve(given), PROJECT_FOLDER) : given;
143
159
  let vendor;
144
160
  if (flags.vendor.value !== undefined) {
145
161
  vendor = vendorOf(flags.vendor.value);
@@ -176,6 +192,8 @@ export async function main(args) {
176
192
  }
177
193
  }
178
194
  const force = args.includes("--force");
195
+ // A project's config with nothing said of the models: your global config's, when it names both - nothing asked.
196
+ const fromGlobal = !global && named === undefined && vendor === undefined && maker === undefined && region === undefined ? globalModels() : undefined;
179
197
  const asking = process.stdin.isTTY && process.stdout.isTTY && named === undefined;
180
198
  let chosen;
181
199
  try {
@@ -190,6 +208,8 @@ export async function main(args) {
190
208
  throw error;
191
209
  }
192
210
  async function chooseVendor() {
211
+ if (fromGlobal !== undefined)
212
+ return { models: fromGlobal };
193
213
  if (named !== undefined) {
194
214
  return {
195
215
  ...(vendor !== undefined ? { vendor } : {}),
@@ -212,7 +232,41 @@ export async function main(args) {
212
232
  ...(chosen.bedrock !== undefined ? { bedrock: chosen.bedrock } : {}),
213
233
  ...(chosen.models !== undefined ? { models: chosen.models } : {}),
214
234
  ...(read !== undefined ? { catalogue: read } : {}),
235
+ ...(existingCodebase ? { buildInto: ".." } : {}),
236
+ ...(fromGlobal !== undefined ? { modelsFromGlobal: true } : {}),
215
237
  });
216
238
  (result.written ? console.log : console.error)(result.message);
217
- return result.written ? 0 : 1;
239
+ if (!result.written)
240
+ return 1;
241
+ if (existingCodebase && process.stdin.isTTY && process.stdout.isTTY && (await askToStart(folder)))
242
+ return startTurriIn(folder);
243
+ return 0;
244
+ }
245
+ /** The project's folder in an existing codebase. */
246
+ const PROJECT_FOLDER = "plain";
247
+ /** Ask whether to start turri in the project's folder now: Enter is yes. */
248
+ async function askToStart(folder) {
249
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
250
+ try {
251
+ const answer = (await rl.question(`${brand.bold(brand.accent(`Start turri in ${relative(process.cwd(), folder) || "."} now?`))} ${brand.muted("[Y/n]")} `)).trim().toLowerCase();
252
+ return answer === "" || answer === "y" || answer === "yes";
253
+ }
254
+ catch {
255
+ // Ctrl+C or Ctrl+D: not now.
256
+ return false;
257
+ }
258
+ finally {
259
+ rl.close();
260
+ }
261
+ }
262
+ /** turri's chat in `folder`, as `turri` there starts it - the same Node, its options, this CLI - until it ends. */
263
+ function startTurriIn(folder) {
264
+ const child = spawn(process.execPath, [...process.execArgv, process.argv[1]], { cwd: folder, stdio: "inherit", env: process.env });
265
+ return new Promise((done) => {
266
+ child.on("exit", (code, signal) => done(code ?? (signal !== null ? 1 : 0)));
267
+ child.on("error", (error) => {
268
+ console.error(`turri could not start in ${folder}: ${error.message}`);
269
+ done(1);
270
+ });
271
+ });
218
272
  }
package/docs/config.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  A project says how its \*\*\*plain is built in `config.turri.yaml`, at the project root. Everything in it is optional: with no file at all, turri finds the testing scripts on its own, turns conformance tests on wherever a module has test reqs, and runs on [pi](https://pi.dev)'s configured model. A project whose parts are on different stacks - a backend and a frontend - gives a module a file of its own, `config.turri.<module>.yaml`, beside it, which builds that module and those built on it (see [a module's own config](#a-modules-own-config)). turri never writes a `config.yaml`: it may be another tool's, and is read only by a project that has no file of turri's yet (see [the old config.yaml](#the-old-configyaml)). A key in `config.turri.yaml` or a module's file that turri reads nothing of - a setting it no longer has, like `test-advisor`, or one misspelt - is named in a warning under the banner as turri starts, rather than ignored without a word. A key turri has renamed is renamed in the file itself as turri first reads or writes the project's config - `release-after-pulse`, now `launch-after-pulse` - its value and its comment kept, and the banner says so; a file that sets the new name too is left as it is, the banner saying the old one does nothing.
4
4
 
5
- `turri init-config` starts one: the two models, a strong one to talk to and a smaller one to write the code. It asks which vendor's models you use - `--vendor` says it without asking, and with neither, as from a script, it is `other`:
5
+ `turri init-config` starts one: the two models, a strong one to talk to and a smaller one to write the code. With your global `~/.turri/config.turri.yaml` naming both, and none of `--vendor`, `--maker`, `--region` or the models given, it asks nothing: the project's file names no models of its own - its two lines commented, saying so - and runs on the global ones. It asks which vendor's models you use - `--vendor` says it without asking, and with neither, as from a script, it is `other`:
6
6
 
7
7
  | vendor | harness-model | coding-model | key [pi](https://pi.dev) reads |
8
8
  | --- | --- | --- | --- |
@@ -18,6 +18,8 @@ Amazon Bedrock asks three more things, from [pi](https://pi.dev)'s catalogue: wh
18
18
 
19
19
  `--harness-model` and `--coding-model` name the two models instead, for any vendor: provider/model-id without a thinking level - `turri init-config --harness-model amazon-bedrock/global.xai.grok-4.7 --coding-model amazon-bedrock/global.xai.grok-4.6`. They are written wherever the vendor's own would be - the two models with their thinking, the commented-out `judge-model` and `models:` examples - and the vendor, maker and geography are read from them. `--judge-model` names the strong one the judging examples use, the harness model unless given. Each is checked against [pi](https://pi.dev)'s catalogue first: one it does not have, or that is not a chat model, is named, with the closest it has, and nothing is written.
20
20
 
21
+ `--existing-codebase [codebase]` sets turri up to work on a codebase you have - the folder named, the current one by default: the project goes in `plain/` inside it, its `config.turri.yaml` saying `build-into: ..`, so every module is built in the codebase itself, on the code there, never over it (see [building into a folder](https://github.com/turri-oss/turri-core/blob/main/docs/regenerating.md#building-into-a-folder) in the core's docs). In a terminal it then asks whether to start turri in `plain/`; Enter starts it.
22
+
21
23
  Each is written with how hard it thinks - `harness-model: openai/gpt-6-astra:medium`, `coding-model: openai/gpt-6-luna:low` - so the file shows it. The reviews and judges of a regeneration run on the coding model but think medium (see [models per role](#models-per-role)).
22
24
 
23
25
  They are an example, not a requirement - any model [pi](https://pi.dev) supports works, signed in any way [pi](https://pi.dev) supports; `other` is the starting point for another provider. What we recommend is that split, a capable model to talk to and a smaller, cheaper one for the coding. Once written, it says what to do next: the key to set in your shell - or `/login` in turri, which [pi](https://pi.dev) keeps in `~/.pi/agent/auth.json` - and that the file belongs to that folder: turri reads the nearest `config.turri.yaml` upwards from where it starts, so one written anywhere else is not seen.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turri-dev/cli",
3
- "version": "0.5.2-next.2bba3d7",
3
+ "version": "0.6.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {