@adayacas/loopbreaker 0.3.0 → 0.4.1

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,15 +1,25 @@
1
+ import type { Target } from "./targets.js";
1
2
  import type { LoopbreakerConfig, Mode } from "./types.js";
2
3
  export interface InstallChoices {
3
4
  target: "global" | "project";
4
5
  pin: boolean;
5
6
  config?: LoopbreakerConfig;
6
7
  gitignore: boolean;
8
+ /** Herramientas elegidas. Solo está presente si el asistente preguntó por ellas. */
9
+ tools?: Target[];
7
10
  }
8
11
  export interface WizardIo {
9
12
  question(prompt: string): Promise<string>;
10
13
  }
14
+ export interface WizardOptions {
15
+ /** Preguntar qué herramientas proteger, con las detectadas como valor por defecto. */
16
+ askTools?: boolean;
17
+ detected?: Target[];
18
+ }
11
19
  export declare function parsePositive(text: string, def: number, min?: number): number;
12
20
  export declare function parseGlobs(text: string): string[];
21
+ /** "claude, codex" -> ["claude","codex"]; ignora lo desconocido. */
22
+ export declare function parseTools(text: string, def: Target[]): Target[];
13
23
  /** Respuestas ya normalizadas -> archivo .loopbreaker.json. Separado para poder testearlo. */
14
24
  export declare function buildConfig(a: {
15
25
  mode: Mode;
@@ -20,4 +30,4 @@ export declare function buildConfig(a: {
20
30
  denyGlobs?: string[];
21
31
  }): LoopbreakerConfig;
22
32
  /** Wizard de instalación. Sin TTY el CLI no lo llama y usa los mismos defaults. */
23
- export declare function runWizard(projectRoot: string, io: WizardIo, fixedTarget?: "global" | "project"): Promise<InstallChoices | undefined>;
33
+ export declare function runWizard(projectRoot: string, io: WizardIo, fixedTarget?: "global" | "project", opts?: WizardOptions): Promise<InstallChoices | undefined>;
@@ -1,4 +1,6 @@
1
1
  import { DEFAULT_INIT } from "./installer.js";
2
+ import { t } from "./messages.js";
3
+ import { TARGETS } from "./targets.js";
2
4
  export function parsePositive(text, def, min = 2) {
3
5
  const n = Number(text.trim());
4
6
  return Number.isInteger(n) && n >= min ? n : def;
@@ -9,6 +11,14 @@ export function parseGlobs(text) {
9
11
  .map((s) => s.trim())
10
12
  .filter(Boolean);
11
13
  }
14
+ /** "claude, codex" -> ["claude","codex"]; ignora lo desconocido. */
15
+ export function parseTools(text, def) {
16
+ const out = text
17
+ .split(",")
18
+ .map((s) => s.trim().toLowerCase())
19
+ .filter((s) => TARGETS.includes(s));
20
+ return out.length ? [...new Set(out)] : def;
21
+ }
12
22
  /** Respuestas ya normalizadas -> archivo .loopbreaker.json. Separado para poder testearlo. */
13
23
  export function buildConfig(a) {
14
24
  const cfg = {
@@ -24,35 +34,46 @@ export function buildConfig(a) {
24
34
  return cfg;
25
35
  }
26
36
  /** Wizard de instalación. Sin TTY el CLI no lo llama y usa los mismos defaults. */
27
- export async function runWizard(projectRoot, io, fixedTarget) {
37
+ export async function runWizard(projectRoot, io, fixedTarget, opts = {}) {
28
38
  const text = async (q) => (await io.question(`${q}: `)).trim();
29
39
  const ask = async (q, def) => (await text(`${q} [${def}]`)) || def;
30
40
  const yes = async (q, def) => {
31
- const a = (await text(`${q} (${def ? "S/n" : "s/N"})`)).toLowerCase();
41
+ const a = (await text(`${q} (${t(def ? "wiz.yesNo" : "wiz.noYes")})`)).toLowerCase();
32
42
  if (!a)
33
43
  return def;
34
44
  return ["s", "si", "sí", "y", "yes"].includes(a);
35
45
  };
36
46
  const num = async (q, def, min = 2) => parsePositive(await text(`${q} [${def}]`), def, min);
37
- const target = fixedTarget ?? ((await ask("¿Instalar global o solo en este proyecto? (global/proyecto)", "global")).toLowerCase().startsWith("p") ? "project" : "global");
38
- const pin = await yes("¿Fijar la versión exacta del plugin?", true);
47
+ let tools;
48
+ if (opts.askTools) {
49
+ const def = opts.detected?.length ? opts.detected : ["opencode"];
50
+ tools = parseTools(await ask(t("wiz.targets"), def.join(", ")), def);
51
+ }
52
+ const target = fixedTarget ?? ((await ask(t("wiz.scope"), "global")).toLowerCase().startsWith("p") ? "project" : "global");
53
+ const pin = await yes(t("wiz.pin"), true);
39
54
  let config;
40
- if (await yes("¿Crear .loopbreaker.json con ajustes del anti-bucles?", false)) {
41
- const mode = (await ask("Modo (block/warn)", "block")).toLowerCase() === "warn" ? "warn" : "block";
42
- const maxConsecutiveRepeats = await num("Repeticiones idénticas antes de bloquear", DEFAULT_INIT.maxConsecutiveRepeats ?? 3, 2);
43
- const stagnationRepeats = await num("Salidas idénticas para estancamiento", DEFAULT_INIT.stagnationRepeats ?? 3, 2);
44
- const hardStopAfter = await num("Bloqueos antes de parada dura", DEFAULT_INIT.hardStopAfter ?? 3, 1);
55
+ if (await yes(t("wiz.createCfg"), false)) {
56
+ const mode = (await ask(t("wiz.mode"), "block")).toLowerCase() === "warn" ? "warn" : "block";
57
+ const maxConsecutiveRepeats = await num(t("wiz.repeats"), DEFAULT_INIT.maxConsecutiveRepeats ?? 3, 2);
58
+ const stagnationRepeats = await num(t("wiz.stagnation"), DEFAULT_INIT.stagnationRepeats ?? 3, 2);
59
+ const hardStopAfter = await num(t("wiz.hardStop"), DEFAULT_INIT.hardStopAfter ?? 3, 1);
45
60
  let allowOnlyGlobs = [];
46
61
  let denyGlobs = [];
47
- if (await yes("¿Configurar alcance por globs? (disuasorio, no sandbox)", false)) {
48
- allowOnlyGlobs = parseGlobs(await text("allowOnlyGlobs separados por coma (vacío = sin límite)"));
49
- denyGlobs = parseGlobs(await text("denyGlobs separados por coma (vacío = ninguno)"));
62
+ if (await yes(t("wiz.askScope"), false)) {
63
+ allowOnlyGlobs = parseGlobs(await text(t("wiz.allow")));
64
+ denyGlobs = parseGlobs(await text(t("wiz.deny")));
50
65
  }
51
66
  config = buildConfig({ mode, maxConsecutiveRepeats, stagnationRepeats, hardStopAfter, allowOnlyGlobs, denyGlobs });
52
67
  }
53
- const gitignore = await yes("¿Añadir .opencode/ al .gitignore de este proyecto?", true);
54
- console.log(`\nResumen: ${target === "project" ? `proyecto (${projectRoot})` : "global"} | versión ${pin ? "fija" : "latest"} | .loopbreaker.json ${config ? "sí" : "no"} | .gitignore ${gitignore ? "sí" : "no"}`);
55
- if (!(await yes("¿Aplicar estos cambios?", true)))
68
+ const gitignore = await yes(t("wiz.gitignore"), true);
69
+ console.log(t("wiz.summary", {
70
+ tools: (tools ?? ["opencode"]).join(", "),
71
+ scope: target === "project" ? t("wiz.project", { root: projectRoot }) : t("wiz.global"),
72
+ pin: t(pin ? "wiz.fixed" : "wiz.latest"),
73
+ cfg: t(config ? "wiz.yes" : "wiz.no"),
74
+ gi: t(gitignore ? "wiz.yes" : "wiz.no"),
75
+ }));
76
+ if (!(await yes(t("wiz.apply"), true)))
56
77
  return undefined;
57
- return { target, pin, config, gitignore };
78
+ return { target, pin, config, gitignore, ...(tools ? { tools } : {}) };
58
79
  }
package/package.json CHANGED
@@ -9,13 +9,17 @@
9
9
  "bugs": {
10
10
  "url": "https://github.com/adayacas/loopbreaker/issues"
11
11
  },
12
- "version": "0.3.0",
12
+ "version": "0.4.1",
13
13
  "description": "Its an Opencode loopbreaker tool to stop ai models when the context overload, to save tokens and guard the healt processes",
14
14
  "type": "module",
15
15
  "main": "dist/src/index.js",
16
16
  "types": "dist/src/index.d.ts",
17
17
  "exports": {
18
- ".": "./dist/src/index.js"
18
+ ".": "./dist/src/index.js",
19
+ "./lib": {
20
+ "types": "./dist/src/lib.d.ts",
21
+ "default": "./dist/src/lib.js"
22
+ }
19
23
  },
20
24
  "bin": {
21
25
  "loopbreaker": "dist/src/cli.js"
@@ -23,6 +27,7 @@
23
27
  "files": [
24
28
  "dist/src",
25
29
  "README.md",
30
+ "CHANGELOG.md",
26
31
  "LICENSE"
27
32
  ],
28
33
  "scripts": {
@@ -41,6 +46,10 @@
41
46
  "keywords": [
42
47
  "opencode",
43
48
  "opencode-plugin",
49
+ "claude-code",
50
+ "codex",
51
+ "grok",
52
+ "hooks",
44
53
  "agent",
45
54
  "loop-detection",
46
55
  "circuit-breaker",
@@ -50,4 +59,4 @@
50
59
  "publishConfig": {
51
60
  "access": "public"
52
61
  }
53
- }
62
+ }