agent-kitchen 0.7.0 → 0.9.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/README.md +10 -7
- package/dist/cli.js +13 -9
- package/dist/commands/sync.d.ts +6 -3
- package/dist/commands/sync.js +139 -58
- package/dist/commit-texts.js +1 -1
- package/dist/menu.d.ts +6 -8
- package/dist/menu.js +13 -18
- package/dist/pr-clone.d.ts +68 -0
- package/dist/pr-clone.js +254 -0
- package/dist/progress.d.ts +6 -6
- package/dist/progress.js +8 -8
- package/dist/repo.d.ts +7 -0
- package/dist/repo.js +10 -0
- package/dist/texts/catalog.d.ts +10 -2
- package/dist/texts/es.js +8 -1
- package/package.json +1 -1
- package/dist/git-finish.d.ts +0 -53
- package/dist/git-finish.js +0 -252
package/README.md
CHANGED
|
@@ -48,7 +48,8 @@ Si npm o GitHub no responden, la pieza se muestra pero no se ofrece actualizarla
|
|
|
48
48
|
npx agent-kitchen apply # pregunta, en una terminal (Enter: todo lo sugerido)
|
|
49
49
|
npx agent-kitchen apply --dry-run # solo muestra qué haría
|
|
50
50
|
npx agent-kitchen apply --yes # hace lo sugerido sin preguntar
|
|
51
|
-
npx agent-kitchen apply --
|
|
51
|
+
npx agent-kitchen apply --pr # en una copia de origin, y abre un PR en draft
|
|
52
|
+
npx agent-kitchen apply --here # en tu copia, sin commit
|
|
52
53
|
npx agent-kitchen apply --verbose # muestra la salida de cada herramienta
|
|
53
54
|
npx agent-kitchen apply --skip claude-cloud # deja fuera una pieza (o varias, con comas)
|
|
54
55
|
npx agent-kitchen apply --pieces # cambia qué piezas usa el repo (solo en una terminal)
|
|
@@ -59,14 +60,16 @@ npx agent-kitchen doctor # revisa cada pieza con su propio
|
|
|
59
60
|
|
|
60
61
|
- **Sin terminal y sin `--yes`** (por ejemplo, desde un agente), solo muestra lo que ofrecería.
|
|
61
62
|
- **Corre en el checkout principal,** no en un worktree, y desde tu terminal. Dentro de una sesión de Claude, el sandbox de `claude-repo-guard` no deja escribir `.claude/settings.json`.
|
|
62
|
-
|
|
63
|
+
**Dónde trabaja.** En una terminal, sin `--pr` ni `--here`, lo primero que pregunta es dónde aplicar los cambios. Con `--yes`, sin terminal o sin remoto `origin`, trabaja en tu copia.
|
|
63
64
|
|
|
64
|
-
**`--
|
|
65
|
+
**`--pr`** deja los cambios en un PR sin tocar tu copia:
|
|
65
66
|
|
|
66
|
-
- **
|
|
67
|
-
- **Al terminar,**
|
|
68
|
-
- **
|
|
69
|
-
- **
|
|
67
|
+
- **Parte de origin, no de tu copia.** Hace `git fetch` y clona el repo en una carpeta temporal en `origin/<base>`: `baseBranch` de `.agents/flow.json`, si no la rama por defecto de `origin`, si no `main`. Da igual si tu copia está atrás, en otra rama o con cambios: ni sus archivos ni su `node_modules` cambian. Es un clon y no un worktree porque `issue-flow apply` no corre en un worktree; el clon comparte los objetos del repo, así que no copia el historial.
|
|
68
|
+
- **Al terminar,** instala las dependencias en el clon (los hooks del repo pueden necesitarlas) y hace el commit con los hooks, el nombre y la firma de tu repo. El lockfile entra solo si cambió `package.json`.
|
|
69
|
+
- **Sube la rama directo a origin.** Tu repo empuja el commit a `chore/agent-kitchen-apply-<fecha>` sin crear una rama local, y abre el PR en draft con `@ramon-sg/github-rest`. Tras el merge, `git fetch --prune` limpia la referencia `origin/chore/…`.
|
|
70
|
+
- **Si algo falla antes del push** (un paso, el install o el commit), no sube nada y deja el clon para revisarlo; la salida dice dónde está. Si el push funciona y el PR falla, la salida dice qué correr.
|
|
71
|
+
|
|
72
|
+
**`--here`** trabaja en tu copia, como `ng update` o `copier update`. Avisa si tu copia tiene cambios sin commit o si tu rama está atrás de origin según el último fetch. Si los pasos cambiaron `package.json`, corre el `install` de tu gestor de paquetes al final. Te queda revisar el diff y hacer commit.
|
|
70
73
|
|
|
71
74
|
**`doctor`** corre el doctor de cada herramienta en la versión del repo: `issue-flow doctor --json`, `skills-manager check` y `claude-repo-guard doctor --json`. Además revisa que `skills-manager` esté al menos en 1.2.0, que las skills del flujo estén en la tag de su CLI, qué labels del flujo le faltan a GitHub (con `·`), que `.claude/cloud.json` fije una versión exacta y, en macOS, `weakerNetworkIsolation`. En un repo con `package.json`, también la línea de `AGENTS.md` y, si hay `CLAUDE.md`, su `@AGENTS.md`. Lo que no está instalado o tiene una versión nueva solo se anota con `·`. Sale con 1 si algo falla (`✗`).
|
|
72
75
|
|
package/dist/cli.js
CHANGED
|
@@ -21,18 +21,20 @@ const PACKAGE = "agent-kitchen";
|
|
|
21
21
|
const HANDED_OVER = "AGENT_KITCHEN_HANDED_OVER";
|
|
22
22
|
/** Usage text. */
|
|
23
23
|
const USAGE = `Uso:
|
|
24
|
-
agent-kitchen apply [--yes | --dry-run] [--
|
|
25
|
-
agent-kitchen apply --pieces [--
|
|
24
|
+
agent-kitchen apply [--yes | --dry-run] [--pr | --here] [--verbose] [--skip <pieza>,...]
|
|
25
|
+
agent-kitchen apply --pieces [--pr | --here]
|
|
26
26
|
agent-kitchen doctor
|
|
27
27
|
|
|
28
28
|
agent-kitchen revisa cada pieza de las herramientas de agentes del repo (${pieceNames().join(", ")}),
|
|
29
29
|
muestra qué tiene el repo y la última versión de cada una, y apply ofrece instalar lo que falta
|
|
30
30
|
y actualizar lo que está atrasado. En una terminal pregunta una vez: hacer todo lo sugerido,
|
|
31
31
|
o elegir los pasos y las skills. --yes hace lo sugerido sin preguntar; sin terminal solo lo
|
|
32
|
-
muestra. --verbose muestra la salida de cada herramienta.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
muestra. --verbose muestra la salida de cada herramienta.
|
|
33
|
+
--pr trabaja en una copia temporal de origin/<base> recién bajada, sin tocar tu copia: instala
|
|
34
|
+
las dependencias, hace el commit, sube una rama nueva a origin y abre un PR en draft. --here
|
|
35
|
+
trabaja en tu copia y deja los cambios sin commit; si los pasos cambiaron package.json, corre
|
|
36
|
+
el install. En una terminal, sin ninguna de las dos, pregunta; con --yes o sin terminal, usa
|
|
37
|
+
--here. apply --pieces elige qué piezas usa el repo y lo guarda en .agents/kitchen.json
|
|
36
38
|
(en una terminal, sin --yes ni --dry-run). Córrelo en la copia principal del
|
|
37
39
|
repo, desde tu terminal. Sin subcomando hace lo mismo que apply, por ahora.
|
|
38
40
|
|
|
@@ -82,7 +84,7 @@ async function main(argv) {
|
|
|
82
84
|
const { values, positionals } = parseArgs({
|
|
83
85
|
args: argv,
|
|
84
86
|
allowPositionals: true,
|
|
85
|
-
options: { yes: { type: "boolean" }, "dry-run": { type: "boolean" }, commit: { type: "boolean" }, verbose: { type: "boolean", short: "v" }, skip: { type: "string" }, pieces: { type: "boolean" }, help: { type: "boolean", short: "h" }, version: { type: "boolean" } },
|
|
87
|
+
options: { yes: { type: "boolean" }, "dry-run": { type: "boolean" }, commit: { type: "boolean" }, pr: { type: "boolean" }, here: { type: "boolean" }, verbose: { type: "boolean", short: "v" }, skip: { type: "string" }, pieces: { type: "boolean" }, help: { type: "boolean", short: "h" }, version: { type: "boolean" } },
|
|
86
88
|
});
|
|
87
89
|
if (values.help === true) {
|
|
88
90
|
out.stdout(`${USAGE}\n`);
|
|
@@ -100,14 +102,16 @@ async function main(argv) {
|
|
|
100
102
|
if (rest.length > 0 || (command !== undefined && command !== "doctor" && command !== "apply"))
|
|
101
103
|
throw new UsageError(`no existe el comando ${positionals.join(" ")}.`);
|
|
102
104
|
if (command === "doctor") {
|
|
103
|
-
if (values.yes !== undefined || values["dry-run"] !== undefined || values.skip !== undefined || values.verbose !== undefined || values.commit !== undefined || values.pieces !== undefined)
|
|
105
|
+
if (values.yes !== undefined || values["dry-run"] !== undefined || values.skip !== undefined || values.verbose !== undefined || values.commit !== undefined || values.pr !== undefined || values.here !== undefined || values.pieces !== undefined)
|
|
104
106
|
throw new UsageError("doctor no lleva opciones.");
|
|
105
107
|
return doctor(process.cwd(), out);
|
|
106
108
|
}
|
|
109
|
+
if (values.commit !== undefined)
|
|
110
|
+
throw new UsageError("--commit ya no existe: usa --pr para abrir un PR desde una copia de origin, o --here para dejar los cambios sin commit en tu copia.");
|
|
107
111
|
if (command === undefined)
|
|
108
112
|
out.stderr("agent-kitchen: usa 'agent-kitchen apply'; sin subcomando dejará de instalar en una versión mayor.\n");
|
|
109
113
|
const skip = (values.skip ?? "").split(",").map((name) => name.trim()).filter((name) => name !== "");
|
|
110
|
-
return sync({ cwd: process.cwd(), yes: values.yes ?? false, dryRun: values["dry-run"] ?? false, verbose: values.verbose ?? false, skip,
|
|
114
|
+
return sync({ cwd: process.cwd(), yes: values.yes ?? false, dryRun: values["dry-run"] ?? false, verbose: values.verbose ?? false, skip, pr: values.pr ?? false, here: values.here ?? false, pieces: values.pieces ?? false }, out);
|
|
111
115
|
}
|
|
112
116
|
try {
|
|
113
117
|
process.exitCode = await main(process.argv.slice(2));
|
package/dist/commands/sync.d.ts
CHANGED
|
@@ -7,7 +7,10 @@ export interface SyncOptions {
|
|
|
7
7
|
dryRun: boolean;
|
|
8
8
|
verbose: boolean;
|
|
9
9
|
skip: string[];
|
|
10
|
-
|
|
10
|
+
/** Work in a clone of origin and open a PR. */
|
|
11
|
+
pr: boolean;
|
|
12
|
+
/** Work in the checkout, leaving the changes uncommitted. */
|
|
13
|
+
here: boolean;
|
|
11
14
|
/** Ask which pieces the repo uses, save the answer, then go on as usual. */
|
|
12
15
|
pieces: boolean;
|
|
13
16
|
}
|
|
@@ -26,7 +29,7 @@ export declare function pieceNames(): string[];
|
|
|
26
29
|
*/
|
|
27
30
|
export declare function noStepsMessage(why: "leave" | "none", wrote: boolean): string;
|
|
28
31
|
/**
|
|
29
|
-
* What the commit of `--
|
|
32
|
+
* What the commit of `--pr` lists: the steps that worked, and the decisions file if this
|
|
30
33
|
* run wrote it, in the commit's texts (not the interface's).
|
|
31
34
|
* @param done - The steps that worked.
|
|
32
35
|
* @param wrote - Whether the decisions file was written in this run.
|
|
@@ -40,6 +43,6 @@ export declare function commitLabels(done: Pick<Step, "text">[], wrote: boolean)
|
|
|
40
43
|
* @param out - Where to write and ask.
|
|
41
44
|
* @returns 0, or 1 if a step failed or the person cancelled.
|
|
42
45
|
* @throws KitError outside the main checkout or with a broken file; UsageError for an unknown piece.
|
|
43
|
-
* @example await sync({ cwd, yes: false, dryRun: true, verbose: false, skip: [],
|
|
46
|
+
* @example await sync({ cwd, yes: false, dryRun: true, verbose: false, skip: [], pr: false, here: false, pieces: false }, out)
|
|
44
47
|
*/
|
|
45
48
|
export declare function sync(options: SyncOptions, out: Output): Promise<number>;
|
package/dist/commands/sync.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file `agent-kitchen apply [--yes] [--dry-run] [--
|
|
3
|
-
* that changes the repo (and, for now, also the bare `agent-kitchen`).
|
|
4
|
-
*
|
|
2
|
+
* @file `agent-kitchen apply [--yes] [--dry-run] [--pr | --here] [--verbose] [--skip <piece>,...]`:
|
|
3
|
+
* the one command that changes the repo (and, for now, also the bare `agent-kitchen`).
|
|
4
|
+
* First it settles where to work: `--pr` in a clone of `origin/<base>` that ends in a PR in
|
|
5
|
+
* draft (see pr-clone.ts), `--here` in the person's checkout, leaving the changes uncommitted.
|
|
6
|
+
* In a terminal, without either, it asks; with `--yes` or without a terminal, or without an
|
|
7
|
+
* origin, it works here. Here it warns if the checkout has changes or is behind its upstream.
|
|
8
|
+
* Then it looks at each piece (the version of skills-manager, the issue flow, claude-cloud,
|
|
5
9
|
* claude-repo-guard, the skills, the rule in AGENTS.md) with
|
|
6
10
|
* every lookup at once, shows what the repo has, and offers the steps that install what is
|
|
7
11
|
* missing or update what is behind. In a terminal it asks first, all in one go: everything
|
|
@@ -11,10 +15,10 @@
|
|
|
11
15
|
* flow's version), one line each, with the
|
|
12
16
|
* tools' output only when one fails; one that fails does not stop the rest. With `--yes`
|
|
13
17
|
* it does what is suggested without asking (and keeps the repo's own skills); without a
|
|
14
|
-
* terminal it only shows the steps.
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* the
|
|
18
|
+
* terminal it only shows the steps. Here, it installs at the end if the steps changed
|
|
19
|
+
* package.json. In the clone it always installs (the repo's hooks may need node_modules),
|
|
20
|
+
* commits, pushes and opens the PR, also when the only change is the decisions file below;
|
|
21
|
+
* if a step, the install or the commit fails, nothing is pushed and the clone is kept.
|
|
18
22
|
* What the repo decided of each piece, in `.agents/kitchen.json`, is respected: a piece set to
|
|
19
23
|
* false is left out as with `--skip`, and one with no decision is marked as new. Without
|
|
20
24
|
* asking (`--yes` or no terminal), a new piece that is not installed is left out for the run.
|
|
@@ -24,8 +28,8 @@
|
|
|
24
28
|
* uses, writes all of them to the file, and then goes on as usual.
|
|
25
29
|
*/
|
|
26
30
|
import { DECIDABLE, decide, DECISIONS, off, readDecisions, undecided, writeDecisions } from "../decisions.js";
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
31
|
+
import { behindUpstream, baseBranch, changedPaths, cloneFromOrigin, originUrl, publish, removeClone } from "../pr-clone.js";
|
|
32
|
+
import { askPath, askPieces, askPlace, askReplace, askSkills, askSteps } from "../menu.js";
|
|
29
33
|
import { KitError, UsageError, warn } from "../output.js";
|
|
30
34
|
import { cloudStatus, NAME as CLOUD } from "../pieces/cloud.js";
|
|
31
35
|
import { guardStatus, NAME as GUARD } from "../pieces/guard.js";
|
|
@@ -33,11 +37,11 @@ import { issueFlowStatus, NAME as FLOW } from "../pieces/issue-flow.js";
|
|
|
33
37
|
import { keepOwn, NAME as SKILLS, ownInPick, skillsStatus } from "../pieces/skills.js";
|
|
34
38
|
import { agentsMdStatus, NAME as AGENTS_MD } from "../pieces/agents-md.js";
|
|
35
39
|
import { NAME as SKILLS_MANAGER, skillsManagerStatus } from "../pieces/skills-manager.js";
|
|
36
|
-
import { mainCheckout, packageManager } from "../repo.js";
|
|
40
|
+
import { mainCheckout, packageManager, packageText } from "../repo.js";
|
|
37
41
|
import { download, failedOutput, runInstall, setVerbose } from "../tools.js";
|
|
38
42
|
import { commitLine, DECISIONS_LINE } from "../commit-texts.js";
|
|
39
43
|
import { progressFor } from "../progress.js";
|
|
40
|
-
import { stepLabel, ui } from "../texts/index.js";
|
|
44
|
+
import { phrases, stepLabel, ui } from "../texts/index.js";
|
|
41
45
|
/** Every piece, in the order its steps run. */
|
|
42
46
|
const PIECES = [SKILLS_MANAGER, FLOW, CLOUD, GUARD, SKILLS, AGENTS_MD];
|
|
43
47
|
/**
|
|
@@ -95,7 +99,7 @@ function printStatus(statuses, decidedOff, out) {
|
|
|
95
99
|
* @param saved - What was read, or null if there is no file.
|
|
96
100
|
* @param statuses - What each piece found.
|
|
97
101
|
* @param chosen - The steps the person picked.
|
|
98
|
-
* @param commits - Whether
|
|
102
|
+
* @param commits - Whether the run ends in a PR, so the file need not be committed by hand.
|
|
99
103
|
* @param out - Where to write.
|
|
100
104
|
* @returns True if the file was written.
|
|
101
105
|
*/
|
|
@@ -121,14 +125,14 @@ export function noStepsMessage(why, wrote) {
|
|
|
121
125
|
}
|
|
122
126
|
/**
|
|
123
127
|
* The line that says the decisions were saved.
|
|
124
|
-
* @param commits - Whether
|
|
128
|
+
* @param commits - Whether the run ends in a PR, so the file need not be committed by hand.
|
|
125
129
|
* @returns The line.
|
|
126
130
|
*/
|
|
127
131
|
function savedMessage(commits) {
|
|
128
132
|
return `${ui.saved(DECISIONS, commits)}\n`;
|
|
129
133
|
}
|
|
130
134
|
/**
|
|
131
|
-
* What the commit of `--
|
|
135
|
+
* What the commit of `--pr` lists: the steps that worked, and the decisions file if this
|
|
132
136
|
* run wrote it, in the commit's texts (not the interface's).
|
|
133
137
|
* @param done - The steps that worked.
|
|
134
138
|
* @param wrote - Whether the decisions file was written in this run.
|
|
@@ -143,7 +147,7 @@ export function commitLabels(done, wrote) {
|
|
|
143
147
|
* Asks which pieces the repo uses and writes the answer for every decidable piece.
|
|
144
148
|
* @param root - The repo.
|
|
145
149
|
* @param saved - What was read, or null if there is no file.
|
|
146
|
-
* @param commits - Whether
|
|
150
|
+
* @param commits - Whether the run ends in a PR.
|
|
147
151
|
* @param out - Where to write.
|
|
148
152
|
* @returns False if the person cancelled.
|
|
149
153
|
*/
|
|
@@ -278,13 +282,45 @@ async function runStep(root, step, progress, out) {
|
|
|
278
282
|
out.stderr(failure);
|
|
279
283
|
return ok;
|
|
280
284
|
}
|
|
285
|
+
/**
|
|
286
|
+
* Settles where to work: the flag, or the person's answer in a terminal, or the checkout.
|
|
287
|
+
* @param root - The repo.
|
|
288
|
+
* @param options - The options.
|
|
289
|
+
* @param out - Where to write and ask.
|
|
290
|
+
* @returns The place, or null if the person cancelled.
|
|
291
|
+
* @throws KitError with `--pr` and no origin.
|
|
292
|
+
*/
|
|
293
|
+
async function choosePlace(root, options, out) {
|
|
294
|
+
if (options.pr) {
|
|
295
|
+
if (originUrl(root) === null)
|
|
296
|
+
throw new KitError("--pr necesita un remoto origin, y este repo no tiene. Usa --here.");
|
|
297
|
+
return "pr";
|
|
298
|
+
}
|
|
299
|
+
if (options.here || options.yes || options.dryRun || !out.interactive || originUrl(root) === null)
|
|
300
|
+
return "here";
|
|
301
|
+
return askPlace(baseBranch(root));
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Warns about what the checkout already has before working on it: changes that will mix with
|
|
305
|
+
* the run's, or a branch behind its upstream.
|
|
306
|
+
* @param root - The repo.
|
|
307
|
+
* @param out - Where to write.
|
|
308
|
+
*/
|
|
309
|
+
function warnHere(root, out) {
|
|
310
|
+
const changed = changedPaths(root);
|
|
311
|
+
if (changed.length > 0)
|
|
312
|
+
warn(out, `tu copia tiene cambios sin commit (${changed.length === 1 ? changed[0] : `${changed.length} archivos`}); los de apply se mezclarán con ellos.`);
|
|
313
|
+
const behind = behindUpstream(root);
|
|
314
|
+
if (behind > 0)
|
|
315
|
+
warn(out, `tu rama está ${behind} ${behind === 1 ? "commit" : "commits"} atrás de origin, según el último fetch; corre git pull antes, o usa --pr.`);
|
|
316
|
+
}
|
|
281
317
|
/**
|
|
282
318
|
* Runs the command; see the file's header.
|
|
283
319
|
* @param options - The options.
|
|
284
320
|
* @param out - Where to write and ask.
|
|
285
321
|
* @returns 0, or 1 if a step failed or the person cancelled.
|
|
286
322
|
* @throws KitError outside the main checkout or with a broken file; UsageError for an unknown piece.
|
|
287
|
-
* @example await sync({ cwd, yes: false, dryRun: true, verbose: false, skip: [],
|
|
323
|
+
* @example await sync({ cwd, yes: false, dryRun: true, verbose: false, skip: [], pr: false, here: false, pieces: false }, out)
|
|
288
324
|
*/
|
|
289
325
|
export async function sync(options, out) {
|
|
290
326
|
const unknown = options.skip.find((name) => !pieceNames().includes(name));
|
|
@@ -292,21 +328,51 @@ export async function sync(options, out) {
|
|
|
292
328
|
throw new UsageError(`no existe la pieza ${unknown}; son ${pieceNames().join(", ")}.`);
|
|
293
329
|
if (options.yes && options.dryRun)
|
|
294
330
|
throw new UsageError("usa --yes o --dry-run, no los dos.");
|
|
331
|
+
if (options.pr && options.here)
|
|
332
|
+
throw new UsageError("usa --pr o --here, no los dos.");
|
|
295
333
|
if (options.pieces && (options.yes || options.dryRun))
|
|
296
334
|
throw new UsageError("usa --pieces solo, sin --yes ni --dry-run.");
|
|
297
335
|
if (options.pieces && !out.interactive)
|
|
298
336
|
throw new UsageError("--pieces pregunta qué piezas usa el repo; córrelo en una terminal.");
|
|
299
337
|
const root = mainCheckout(options.cwd, "agent-kitchen apply");
|
|
300
|
-
const base = options.commit ? baseBranch(root) : null;
|
|
301
|
-
if (base !== null)
|
|
302
|
-
checkReady(root, base);
|
|
303
338
|
setVerbose(options.verbose);
|
|
339
|
+
const place = await choosePlace(root, options, out);
|
|
340
|
+
if (place === null) {
|
|
341
|
+
out.stdout("No se cambió nada.\n");
|
|
342
|
+
return 1;
|
|
343
|
+
}
|
|
344
|
+
if (place === "here") {
|
|
345
|
+
if (!options.dryRun)
|
|
346
|
+
warnHere(root, out);
|
|
347
|
+
return applyIn({ kind: "here", root }, options, out);
|
|
348
|
+
}
|
|
349
|
+
const base = baseBranch(root);
|
|
350
|
+
out.stdout(`${ui.cloning(base)}\n`);
|
|
351
|
+
const work = { kind: "pr", root: cloneFromOrigin(root, base), repo: root, base, keep: false };
|
|
352
|
+
try {
|
|
353
|
+
return await applyIn(work, options, out);
|
|
354
|
+
}
|
|
355
|
+
finally {
|
|
356
|
+
if (!work.keep)
|
|
357
|
+
removeClone(work.root);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Looks at the pieces, asks, runs the steps and ends as the place says.
|
|
362
|
+
* @param work - Where to work.
|
|
363
|
+
* @param options - The options.
|
|
364
|
+
* @param out - Where to write and ask.
|
|
365
|
+
* @returns 0, or 1 if a step failed or the person cancelled.
|
|
366
|
+
*/
|
|
367
|
+
async function applyIn(work, options, out) {
|
|
368
|
+
const { root } = work;
|
|
369
|
+
const pr = work.kind === "pr";
|
|
304
370
|
let saved = readDecisions(root);
|
|
305
371
|
let wrote = false;
|
|
306
372
|
for (const warning of saved?.warnings ?? [])
|
|
307
373
|
warn(out, warning);
|
|
308
374
|
if (options.pieces) {
|
|
309
|
-
if (!(await choosePieces(root, saved,
|
|
375
|
+
if (!(await choosePieces(root, saved, pr, out))) {
|
|
310
376
|
out.stdout("No se cambió nada.\n");
|
|
311
377
|
return 0;
|
|
312
378
|
}
|
|
@@ -337,18 +403,18 @@ export async function sync(options, out) {
|
|
|
337
403
|
}
|
|
338
404
|
printStatus(statuses, off(saved).filter((name) => !options.skip.includes(name)), out);
|
|
339
405
|
const steps = statuses.flatMap((status) => status.steps);
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
const endWithoutSteps = async () => (
|
|
406
|
+
const progress = progressFor(out, options.verbose);
|
|
407
|
+
// In a clone, a run that only wrote the decisions file still ends in a PR.
|
|
408
|
+
const endWithoutSteps = async () => (work.kind === "pr" && wrote ? openPr(work, commitLabels([], true), [], progress, out) : 0);
|
|
343
409
|
if (steps.length === 0) {
|
|
344
410
|
if (saves)
|
|
345
|
-
wrote = saveDecisions(root, saved, statuses, [],
|
|
411
|
+
wrote = saveDecisions(root, saved, statuses, [], pr, out) || wrote;
|
|
346
412
|
out.stdout(`${ui.upToDate}\n`);
|
|
347
413
|
return endWithoutSteps();
|
|
348
414
|
}
|
|
349
415
|
const chosen = await chooseSteps(root, steps, options, out);
|
|
350
416
|
if (saves && Array.isArray(chosen))
|
|
351
|
-
wrote = saveDecisions(root, saved, statuses, chosen,
|
|
417
|
+
wrote = saveDecisions(root, saved, statuses, chosen, pr, out) || wrote;
|
|
352
418
|
if (chosen === "leave") {
|
|
353
419
|
out.stdout(noStepsMessage("leave", wrote));
|
|
354
420
|
return endWithoutSteps();
|
|
@@ -367,59 +433,74 @@ export async function sync(options, out) {
|
|
|
367
433
|
out.stdout(noStepsMessage("none", wrote));
|
|
368
434
|
return endWithoutSteps();
|
|
369
435
|
}
|
|
436
|
+
const pkgBefore = packageText(root);
|
|
370
437
|
const failedSteps = [];
|
|
371
438
|
for (const step of chosen) {
|
|
372
439
|
if (!(await runStep(root, step, progress, out)))
|
|
373
440
|
failedSteps.push(step);
|
|
374
441
|
}
|
|
375
442
|
const failed = failedSteps.map(stepLabel);
|
|
376
|
-
if (
|
|
377
|
-
return
|
|
378
|
-
|
|
443
|
+
if (work.kind === "pr")
|
|
444
|
+
return openPr(work, commitLabels(chosen.filter((step) => !failedSteps.includes(step)), wrote), failed, progress, out);
|
|
445
|
+
const installFailed = packageText(root) !== pkgBefore ? !(await install(root, progress, out)) : false;
|
|
446
|
+
if (installFailed)
|
|
447
|
+
failed.push(phrases({ kind: "install-deps", manager: packageManager(root) }).menu);
|
|
448
|
+
out.stdout(`\n${ui.summary(failed)} ${ui.next(installFailed ? packageManager(root) : null)}\n`);
|
|
379
449
|
return failed.length === 0 ? 0 : 1;
|
|
380
450
|
}
|
|
381
451
|
/**
|
|
382
|
-
*
|
|
383
|
-
* the branch with a PR under --yes) and what git did.
|
|
452
|
+
* Runs the repo's install with the same progress as a step, and shows its output if it fails.
|
|
384
453
|
* @param root - The repo.
|
|
385
|
-
* @param
|
|
454
|
+
* @param progress - How progress is shown.
|
|
455
|
+
* @param out - Where to write.
|
|
456
|
+
* @returns Whether it worked.
|
|
457
|
+
*/
|
|
458
|
+
async function install(root, progress, out) {
|
|
459
|
+
const text = { kind: "install-deps", manager: packageManager(root) };
|
|
460
|
+
progress.start(text);
|
|
461
|
+
const installed = await runInstall(root, text.manager);
|
|
462
|
+
progress.stop(text, installed.ok);
|
|
463
|
+
if (!installed.ok)
|
|
464
|
+
out.stderr(failedOutput(installed.output));
|
|
465
|
+
return installed.ok;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* The end of a run in a clone: the install, the changes, the commit, the push and the PR.
|
|
469
|
+
* Nothing is pushed if a step, the install or the commit failed; the clone is kept then.
|
|
470
|
+
* @param work - The clone.
|
|
386
471
|
* @param done - What the commit lists: the steps that worked, and the decisions file if written.
|
|
387
472
|
* @param failed - The steps that failed, as the interface names them.
|
|
388
473
|
* @param progress - How progress is shown, for the install.
|
|
389
|
-
* @param
|
|
390
|
-
* @
|
|
391
|
-
* @returns 0, or 1 if a step, the install or git failed.
|
|
474
|
+
* @param out - Where to write.
|
|
475
|
+
* @returns 0, or 1 if a step, the install, git or the PR failed.
|
|
392
476
|
*/
|
|
393
|
-
async function
|
|
477
|
+
async function openPr(work, done, failed, progress, out) {
|
|
394
478
|
const summary = ui.summary(failed);
|
|
395
|
-
const
|
|
396
|
-
if (
|
|
397
|
-
out.stdout(`\n${summary}
|
|
479
|
+
const before = changedPaths(work.root);
|
|
480
|
+
if (before.length === 0) {
|
|
481
|
+
out.stdout(`\n${summary} ${ui.noChanges}\n`);
|
|
398
482
|
return failed.length === 0 ? 0 : 1;
|
|
399
483
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
progress.start(text);
|
|
405
|
-
const installed = await runInstall(root, manager);
|
|
406
|
-
progress.stop(text, installed.ok);
|
|
407
|
-
if (!installed.ok) {
|
|
408
|
-
out.stderr(failedOutput(installed.output));
|
|
409
|
-
out.stdout(`\n${summary} No commiteé: el install falló y los cambios quedan sin commit.\n`);
|
|
410
|
-
return 1;
|
|
411
|
-
}
|
|
484
|
+
if (failed.length > 0) {
|
|
485
|
+
work.keep = true;
|
|
486
|
+
out.stdout(`\n${summary} ${ui.prNotOpened("step", work.root)}\n`);
|
|
487
|
+
return 1;
|
|
412
488
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
out.stdout("
|
|
489
|
+
// A clone starts without node_modules, and the repo's hooks may need them.
|
|
490
|
+
if (packageText(work.root) !== null && !(await install(work.root, progress, out))) {
|
|
491
|
+
work.keep = true;
|
|
492
|
+
out.stdout(`\n${summary} ${ui.prNotOpened("install", work.root)}\n`);
|
|
417
493
|
return 1;
|
|
418
494
|
}
|
|
419
|
-
|
|
420
|
-
const
|
|
421
|
-
|
|
495
|
+
// Only a changed package.json brings the lockfile along; an install that only rewrites it stays out.
|
|
496
|
+
const paths = before.includes("package.json") ? changedPaths(work.root) : before;
|
|
497
|
+
out.stdout(`\n${summary} ${ui.changes}\n${paths.map((path) => ` ${path}`).join("\n")}\n`);
|
|
498
|
+
const result = await publish(work.repo, work.root, { base: work.base, steps: done, paths });
|
|
422
499
|
for (const line of result.lines)
|
|
423
500
|
out.stdout(`${line}\n`);
|
|
424
|
-
|
|
501
|
+
if (!result.pushed) {
|
|
502
|
+
work.keep = true;
|
|
503
|
+
out.stdout(`${ui.prNotOpened("git", work.root)}\n`);
|
|
504
|
+
}
|
|
505
|
+
return result.ok ? 0 : 1;
|
|
425
506
|
}
|
package/dist/commit-texts.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file The texts of the commit and the PR of `apply --
|
|
2
|
+
* @file The texts of the commit and the PR of `apply --pr`. They are always in Spanish,
|
|
3
3
|
* whatever language the interface shows: a repo's history should not change language with the
|
|
4
4
|
* terminal of whoever ran the command. A step reads as its Spanish menu order.
|
|
5
5
|
*/
|
package/dist/menu.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { FinishChoice } from "./git-finish.js";
|
|
2
1
|
import type { Candidate, Step } from "./piece.js";
|
|
3
2
|
/** What the person wants after seeing the table. */
|
|
4
3
|
export type Path = "all" | "pick" | "leave";
|
|
@@ -77,13 +76,12 @@ export declare function askSkills(candidates: Candidate[], ticked: string[]): Pr
|
|
|
77
76
|
* @example await askReplace(["planning"])
|
|
78
77
|
*/
|
|
79
78
|
export declare function askReplace(own: string[]): Promise<boolean | null>;
|
|
79
|
+
/** Where apply works: a PR from a clone of origin, or the person's checkout. */
|
|
80
|
+
export type Place = "pr" | "here";
|
|
80
81
|
/**
|
|
81
|
-
* Asks,
|
|
82
|
-
* cancelling leaves them too.
|
|
82
|
+
* Asks, before anything else, where to apply the changes.
|
|
83
83
|
* @param base - The base branch.
|
|
84
|
-
* @
|
|
85
|
-
* @
|
|
86
|
-
* @returns The answer.
|
|
87
|
-
* @example await askFinish("main", "chore/agent-kitchen-apply-2026-11-01", false) // "pr"
|
|
84
|
+
* @returns The answer, or null if the person cancelled.
|
|
85
|
+
* @example await askPlace("main") // "pr"
|
|
88
86
|
*/
|
|
89
|
-
export declare function
|
|
87
|
+
export declare function askPlace(base: string): Promise<Place | null>;
|
package/dist/menu.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file The questions, in Spanish (`@clack/prompts`), all asked before any step runs:
|
|
3
|
-
* quick path (do everything suggested, pick, or leave), the
|
|
4
|
-
* skills of a step grouped by catalog with their description,
|
|
5
|
-
* repo's own skills. They only run with a terminal.
|
|
2
|
+
* @file The questions, in Spanish (`@clack/prompts`), all asked before any step runs: where to
|
|
3
|
+
* apply (a PR or the checkout), the quick path (do everything suggested, pick, or leave), the
|
|
4
|
+
* checkbox menu of the steps, the skills of a step grouped by catalog with their description,
|
|
5
|
+
* and whether to replace the repo's own skills. They only run with a terminal.
|
|
6
6
|
*/
|
|
7
7
|
import { styleText } from "node:util";
|
|
8
8
|
import { confirm, groupMultiselect, isCancel, MULTISELECT_INSTRUCTIONS, multiselect, select, SELECT_INSTRUCTIONS } from "@clack/prompts";
|
|
@@ -123,25 +123,20 @@ export async function askReplace(own) {
|
|
|
123
123
|
return isCancel(answer) ? null : answer;
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
126
|
-
* Asks,
|
|
127
|
-
* cancelling leaves them too.
|
|
126
|
+
* Asks, before anything else, where to apply the changes.
|
|
128
127
|
* @param base - The base branch.
|
|
129
|
-
* @
|
|
130
|
-
* @
|
|
131
|
-
* @returns The answer.
|
|
132
|
-
* @example await askFinish("main", "chore/agent-kitchen-apply-2026-11-01", false) // "pr"
|
|
128
|
+
* @returns The answer, or null if the person cancelled.
|
|
129
|
+
* @example await askPlace("main") // "pr"
|
|
133
130
|
*/
|
|
134
|
-
export async function
|
|
131
|
+
export async function askPlace(base) {
|
|
135
132
|
spanishKeys();
|
|
136
133
|
const answer = await select({
|
|
137
|
-
message:
|
|
138
|
-
initialValue: "
|
|
134
|
+
message: "¿Dónde aplico los cambios?",
|
|
135
|
+
initialValue: "pr",
|
|
139
136
|
options: [
|
|
140
|
-
{ value: "
|
|
141
|
-
{ value: "
|
|
142
|
-
{ value: "branch", label: `Commit en una rama nueva, ${branch}`, hint: `${base} queda como está` },
|
|
143
|
-
{ value: "pr", label: "Commit en una rama nueva, push y PR", hint: `contra ${base}` },
|
|
137
|
+
{ value: "pr", label: "En un PR nuevo", hint: `recomendado · parte de origin/${base}, no toca tu copia` },
|
|
138
|
+
{ value: "here", label: "En tu copia, sin commit", hint: "los revisas con git diff y haces commit tú" },
|
|
144
139
|
],
|
|
145
140
|
});
|
|
146
|
-
return isCancel(answer) ?
|
|
141
|
+
return isCancel(answer) ? null : answer;
|
|
147
142
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The base branch, as issue-flow takes it: `baseBranch` of `.agents/flow.json`, or origin's
|
|
3
|
+
* default as git knows it, or `main`.
|
|
4
|
+
* @param root - The repo.
|
|
5
|
+
* @returns The branch.
|
|
6
|
+
* @example baseBranch(root) // "main"
|
|
7
|
+
*/
|
|
8
|
+
export declare function baseBranch(root: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Origin's URL.
|
|
11
|
+
* @param root - The repo.
|
|
12
|
+
* @returns The URL, or null if the repo has no origin.
|
|
13
|
+
*/
|
|
14
|
+
export declare function originUrl(root: string): string | null;
|
|
15
|
+
/**
|
|
16
|
+
* The files that differ from HEAD, tracked or not, one by one, without the repo's worktrees.
|
|
17
|
+
* @param root - The repo.
|
|
18
|
+
* @returns Their paths.
|
|
19
|
+
* @example changedPaths(root) // ["package.json", "package-lock.json"]
|
|
20
|
+
*/
|
|
21
|
+
export declare function changedPaths(root: string): string[];
|
|
22
|
+
/**
|
|
23
|
+
* How many commits the current branch is behind its upstream, as the last fetch saw it.
|
|
24
|
+
* @param root - The repo.
|
|
25
|
+
* @returns The count, or 0 without an upstream.
|
|
26
|
+
*/
|
|
27
|
+
export declare function behindUpstream(root: string): number;
|
|
28
|
+
/**
|
|
29
|
+
* The branch for today's changes: a new name, also against origin's branches.
|
|
30
|
+
* @param root - The repo, just fetched.
|
|
31
|
+
* @param date - Today.
|
|
32
|
+
* @returns `chore/agent-kitchen-apply-AAAA-MM-DD`, or with `-2`, `-3`… if taken.
|
|
33
|
+
* @example branchName(root, new Date()) // "chore/agent-kitchen-apply-2026-11-01"
|
|
34
|
+
*/
|
|
35
|
+
export declare function branchName(root: string, date: Date): string;
|
|
36
|
+
/**
|
|
37
|
+
* Fetches origin and clones the repo at `origin/<base>` into a temporary folder.
|
|
38
|
+
* @param root - The repo.
|
|
39
|
+
* @param base - The base branch.
|
|
40
|
+
* @returns The clone's folder.
|
|
41
|
+
* @throws KitError if the repo has no origin, the fetch fails or origin has no such branch.
|
|
42
|
+
*/
|
|
43
|
+
export declare function cloneFromOrigin(root: string, base: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Deletes the clone.
|
|
46
|
+
* @param clone - Its folder.
|
|
47
|
+
*/
|
|
48
|
+
export declare function removeClone(clone: string): void;
|
|
49
|
+
/** What `publish` needs to know. */
|
|
50
|
+
export interface PublishOptions {
|
|
51
|
+
base: string;
|
|
52
|
+
steps: string[];
|
|
53
|
+
paths: string[];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Commits the clone's changes, pushes them from the repo to a new branch of origin and opens
|
|
57
|
+
* the PR. Until the push works, the commit lives only in the clone, which the caller keeps.
|
|
58
|
+
* @param root - The repo.
|
|
59
|
+
* @param clone - The clone, with the changes.
|
|
60
|
+
* @param options - The base, the steps that ran (for the commit and the PR) and the files to commit (the ones shown).
|
|
61
|
+
* @returns The lines to show, whether it all worked and whether the changes reached origin.
|
|
62
|
+
* @example await publish(root, clone, { base: "main", steps, paths })
|
|
63
|
+
*/
|
|
64
|
+
export declare function publish(root: string, clone: string, options: PublishOptions): Promise<{
|
|
65
|
+
ok: boolean;
|
|
66
|
+
pushed: boolean;
|
|
67
|
+
lines: string[];
|
|
68
|
+
}>;
|