@adayacas/loopbreaker 0.2.0 → 0.4.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.
@@ -0,0 +1,79 @@
1
+ import { DEFAULT_INIT } from "./installer.js";
2
+ import { t } from "./messages.js";
3
+ import { TARGETS } from "./targets.js";
4
+ export function parsePositive(text, def, min = 2) {
5
+ const n = Number(text.trim());
6
+ return Number.isInteger(n) && n >= min ? n : def;
7
+ }
8
+ export function parseGlobs(text) {
9
+ return text
10
+ .split(",")
11
+ .map((s) => s.trim())
12
+ .filter(Boolean);
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
+ }
22
+ /** Respuestas ya normalizadas -> archivo .loopbreaker.json. Separado para poder testearlo. */
23
+ export function buildConfig(a) {
24
+ const cfg = {
25
+ mode: a.mode,
26
+ maxConsecutiveRepeats: a.maxConsecutiveRepeats,
27
+ stagnationRepeats: a.stagnationRepeats,
28
+ hardStopAfter: a.hardStopAfter,
29
+ };
30
+ const allowOnlyGlobs = a.allowOnlyGlobs ?? [];
31
+ const denyGlobs = a.denyGlobs ?? [];
32
+ if (allowOnlyGlobs.length || denyGlobs.length)
33
+ cfg.scope = { allowOnlyGlobs, denyGlobs };
34
+ return cfg;
35
+ }
36
+ /** Wizard de instalación. Sin TTY el CLI no lo llama y usa los mismos defaults. */
37
+ export async function runWizard(projectRoot, io, fixedTarget, opts = {}) {
38
+ const text = async (q) => (await io.question(`${q}: `)).trim();
39
+ const ask = async (q, def) => (await text(`${q} [${def}]`)) || def;
40
+ const yes = async (q, def) => {
41
+ const a = (await text(`${q} (${t(def ? "wiz.yesNo" : "wiz.noYes")})`)).toLowerCase();
42
+ if (!a)
43
+ return def;
44
+ return ["s", "si", "sí", "y", "yes"].includes(a);
45
+ };
46
+ const num = async (q, def, min = 2) => parsePositive(await text(`${q} [${def}]`), def, min);
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);
54
+ let config;
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);
60
+ let allowOnlyGlobs = [];
61
+ let denyGlobs = [];
62
+ if (await yes(t("wiz.askScope"), false)) {
63
+ allowOnlyGlobs = parseGlobs(await text(t("wiz.allow")));
64
+ denyGlobs = parseGlobs(await text(t("wiz.deny")));
65
+ }
66
+ config = buildConfig({ mode, maxConsecutiveRepeats, stagnationRepeats, hardStopAfter, allowOnlyGlobs, denyGlobs });
67
+ }
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)))
77
+ return undefined;
78
+ return { target, pin, config, gitignore, ...(tools ? { tools } : {}) };
79
+ }
package/package.json CHANGED
@@ -1,20 +1,33 @@
1
1
  {
2
2
  "name": "@adayacas/loopbreaker",
3
- "version": "0.2.0",
4
- "description": "Loop breaker y guardián de alcance para agentes de OpenCode: corta bucles de herramientas y limita lo que el agente puede escribir por fase.",
3
+ "author": "Adrián Ayala Castrillón <adayacas@gmail.com>",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/adayacas/loopbreaker.git"
7
+ },
8
+ "homepage": "https://github.com/adayacas/loopbreaker#readme",
9
+ "bugs": {
10
+ "url": "https://github.com/adayacas/loopbreaker/issues"
11
+ },
12
+ "version": "0.4.0",
13
+ "description": "Its an Opencode loopbreaker tool to stop ai models when the context overload, to save tokens and guard the healt processes",
5
14
  "type": "module",
6
15
  "main": "dist/src/index.js",
7
16
  "types": "dist/src/index.d.ts",
8
17
  "exports": {
9
- ".": "./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
+ }
10
23
  },
11
24
  "bin": {
12
- "loopbreaker": "dist/src/cli.js",
13
- "aeg": "dist/src/cli.js"
25
+ "loopbreaker": "dist/src/cli.js"
14
26
  },
15
27
  "files": [
16
28
  "dist/src",
17
29
  "README.md",
30
+ "CHANGELOG.md",
18
31
  "LICENSE"
19
32
  ],
20
33
  "scripts": {
@@ -22,14 +35,6 @@
22
35
  "test": "tsc -p tsconfig.json && node --test \"dist/test/*.test.js\"",
23
36
  "prepublishOnly": "rm -rf dist && npm test && tsc -p tsconfig.build.json"
24
37
  },
25
- "peerDependencies": {
26
- "@opencode-ai/plugin": "*"
27
- },
28
- "peerDependenciesMeta": {
29
- "@opencode-ai/plugin": {
30
- "optional": true
31
- }
32
- },
33
38
  "devDependencies": {
34
39
  "typescript": "^5.6.0",
35
40
  "@types/node": "^22.0.0"
@@ -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",