myrmo-mcp 0.28.4 → 0.30.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/dist/doctor.js +39 -38
- package/dist/hooks/lookup.mjs +21 -3
- package/dist/hooks/on-failure.mjs +79 -17
- package/dist/hooks/redact.mjs +6 -2
- package/dist/i18n.d.ts +6 -0
- package/dist/i18n.js +28 -0
- package/dist/index.js +106 -23
- package/dist/init.js +43 -43
- package/dist/join.d.ts +17 -0
- package/dist/join.js +90 -0
- package/dist/server.d.ts +1 -1
- package/dist/server.js +5 -2
- package/dist/trail.v1.schema.json +5 -0
- package/dist/wizard.js +39 -38
- package/package.json +2 -2
package/dist/doctor.js
CHANGED
|
@@ -5,6 +5,7 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
import { claudeCodeSetUp } from "./init.js";
|
|
7
7
|
import { compareVersions, describeColony, VERSION, VERSION_SHAPE } from "./server.js";
|
|
8
|
+
import { t } from "./i18n.js";
|
|
8
9
|
const PUBLIC_HOSTS = new Set(["myrmo.dev", "www.myrmo.dev"]);
|
|
9
10
|
async function call(fetchImpl, url, key) {
|
|
10
11
|
try {
|
|
@@ -24,22 +25,22 @@ export async function diagnose(input) {
|
|
|
24
25
|
const fetchImpl = input.fetchImpl ?? fetch;
|
|
25
26
|
const major = Number((input.nodeVersion ?? process.versions.node).split(".")[0]);
|
|
26
27
|
checks.push(major >= 20
|
|
27
|
-
? { level: "ok", name: "Node.js", detail: `version ${input.nodeVersion ?? process.versions.node}` }
|
|
28
|
-
: { level: "fail", name: "Node.js", detail: `version ${input.nodeVersion ?? process.versions.node} is too old`, fix: "Install Node.js 20 or newer (node --version) and run the command again." });
|
|
28
|
+
? { level: "ok", name: "Node.js", detail: t(`version ${input.nodeVersion ?? process.versions.node}`, `versión ${input.nodeVersion ?? process.versions.node}`) }
|
|
29
|
+
: { level: "fail", name: "Node.js", detail: t(`version ${input.nodeVersion ?? process.versions.node} is too old`, `la versión ${input.nodeVersion ?? process.versions.node} es demasiado antigua`), fix: t("Install Node.js 20 or newer (node --version) and run the command again.", "Instala Node.js 20 o superior (node --version) y vuelve a ejecutar el comando.") });
|
|
29
30
|
let host = "";
|
|
30
31
|
try {
|
|
31
32
|
host = new URL(input.url).host;
|
|
32
33
|
}
|
|
33
34
|
catch {
|
|
34
|
-
checks.push({ level: "fail", name: "Colony address", detail: `"${input.url}" is not a web address`, fix: "Run the setup command again with --url http://<machine>:8080." });
|
|
35
|
+
checks.push({ level: "fail", name: t("Colony address", "Dirección de la colonia"), detail: t(`"${input.url}" is not a web address`, `"${input.url}" no es una dirección web`), fix: t("Run the setup command again with --url http://<machine>:8080.", "Vuelve a ejecutar el comando de configuración con --url http://<machine>:8080.") });
|
|
35
36
|
return checks;
|
|
36
37
|
}
|
|
37
38
|
const isPublic = PUBLIC_HOSTS.has(host);
|
|
38
39
|
checks.push({
|
|
39
40
|
level: isPublic ? "warn" : "ok",
|
|
40
|
-
name: "Colony",
|
|
41
|
-
detail: `${input.url}${isPublic ? " (the public colony)" : input.saved ? " (saved by init)" : " (from MYRMO_URL)"}`,
|
|
42
|
-
fix: isPublic ? "To use your team's colony, run the setup command you were sent (npx myrmo-mcp init --url ... --key ... --private)." : undefined,
|
|
41
|
+
name: t("Colony", "Colonia"),
|
|
42
|
+
detail: `${input.url}${isPublic ? t(" (the public colony)", " (la colonia pública)") : input.saved ? t(" (saved by init)", " (guardada por init)") : t(" (from MYRMO_URL)", " (de MYRMO_URL)")}`,
|
|
43
|
+
fix: isPublic ? t("To use your team's colony, run the setup command you were sent (npx myrmo-mcp init --url ... --key ... --private).", "Para usar la colonia de tu equipo, ejecuta el comando de configuración que te enviaron (npx myrmo-mcp init --url ... --key ... --private).") : undefined,
|
|
43
44
|
});
|
|
44
45
|
if (isPublic)
|
|
45
46
|
return checks;
|
|
@@ -48,11 +49,11 @@ export async function diagnose(input) {
|
|
|
48
49
|
const refused = ready.error === "ECONNREFUSED";
|
|
49
50
|
checks.push({
|
|
50
51
|
level: "fail",
|
|
51
|
-
name: "Reaching the colony",
|
|
52
|
-
detail: refused ? "the machine answered but nothing listens on that port" : `no answer (${ready.error})`,
|
|
52
|
+
name: t("Reaching the colony", "Llegar a la colonia"),
|
|
53
|
+
detail: refused ? t("the machine answered but nothing listens on that port", "la máquina respondió pero nada escucha en ese puerto") : t(`no answer (${ready.error})`, `sin respuesta (${ready.error})`),
|
|
53
54
|
fix: refused
|
|
54
|
-
? "Ask whoever runs the colony whether it is up
|
|
55
|
-
: "Check that you are on the team's network and that the address and port are right; from this machine try: curl " + input.url + "/readyz",
|
|
55
|
+
? t("Ask whoever runs the colony whether it is up.", "Pregunta a quien gestiona la colonia si está en marcha.")
|
|
56
|
+
: t("Check that you are on the team's network and that the address and port are right; from this machine try: curl ", "Comprueba que estás en la red del equipo y que la dirección y el puerto son correctos; desde esta máquina prueba: curl ") + input.url + "/readyz",
|
|
56
57
|
});
|
|
57
58
|
return checks;
|
|
58
59
|
}
|
|
@@ -68,42 +69,42 @@ export async function diagnose(input) {
|
|
|
68
69
|
const dockerNetwork = !!seen && /^172\.(1[6-9]|2\d|3[01])\./.test(seen);
|
|
69
70
|
checks.push({
|
|
70
71
|
level: "fail",
|
|
71
|
-
name: "Reaching the colony",
|
|
72
|
-
detail: `the colony refuses connections from this network (403)${seen ? `: it sees you as ${seen}` : ""}`,
|
|
72
|
+
name: t("Reaching the colony", "Llegar a la colonia"),
|
|
73
|
+
detail: t(`the colony refuses connections from this network (403)${seen ? `: it sees you as ${seen}` : ""}`, `la colonia rechaza las conexiones desde esta red (403)${seen ? `: te ve como ${seen}` : ""}`),
|
|
73
74
|
fix: dockerNetwork
|
|
74
|
-
? "You are probably on the colony's own machine: use its network address in the URL (not localhost or 127.0.0.1), and run the setup command again."
|
|
75
|
+
? t("You are probably on the colony's own machine: use its network address in the URL (not localhost or 127.0.0.1), and run the setup command again.", "Probablemente estás en la propia máquina de la colonia: usa su dirección de red en la URL (no localhost ni 127.0.0.1) y vuelve a ejecutar el comando de configuración.")
|
|
75
76
|
: seen
|
|
76
|
-
? `Tell whoever runs the colony to allow ${seen}. If that is not your machine's address, a router between you and the colony is translating it, and that shared address is the one to allow.`
|
|
77
|
-
: "Your machine is not in the networks the colony allows. Tell whoever runs it your address.",
|
|
77
|
+
? t(`Tell whoever runs the colony to allow ${seen}. If that is not your machine's address, a router between you and the colony is translating it, and that shared address is the one to allow.`, `Pide a quien gestiona la colonia que permita ${seen}. Si esa no es la dirección de tu máquina, un router entre tú y la colonia la está traduciendo, y es esa dirección compartida la que hay que permitir.`)
|
|
78
|
+
: t("Your machine is not in the networks the colony allows. Tell whoever runs it your address.", "Tu máquina no está en las redes que permite la colonia. Dile tu dirección a quien la gestiona."),
|
|
78
79
|
});
|
|
79
80
|
return checks;
|
|
80
81
|
}
|
|
81
82
|
checks.push(ready.status === 200
|
|
82
|
-
? { level: "ok", name: "Reaching the colony", detail: "it answers and reports itself ready" }
|
|
83
|
-
: { level: "fail", name: "Reaching the colony", detail: `it answered ${ready.status}`, fix: "It is up but not ready (it may still be starting). Try again in a minute, then tell whoever runs it." });
|
|
83
|
+
? { level: "ok", name: t("Reaching the colony", "Llegar a la colonia"), detail: t("it answers and reports itself ready", "responde y dice que está lista") }
|
|
84
|
+
: { level: "fail", name: t("Reaching the colony", "Llegar a la colonia"), detail: t(`it answered ${ready.status}`, `respondió ${ready.status}`), fix: t("It is up but not ready (it may still be starting). Try again in a minute, then tell whoever runs it.", "Está en marcha pero no lista (puede que aún esté arrancando). Inténtalo dentro de un minuto y, si sigue, díselo a quien la gestiona.") });
|
|
84
85
|
if (ready.status !== 200)
|
|
85
86
|
return checks;
|
|
86
87
|
const open = await call(fetchImpl, `${input.url.replace(/\/$/, "")}/v1/stats`, input.apiKey);
|
|
87
88
|
if ("error" in open) {
|
|
88
|
-
checks.push({ level: "fail", name: "Your access key", detail: `no answer (${open.error})`, fix: "Try again; if it persists tell whoever runs the colony." });
|
|
89
|
+
checks.push({ level: "fail", name: t("Your access key", "Tu clave de acceso"), detail: t(`no answer (${open.error})`, `sin respuesta (${open.error})`), fix: t("Try again; if it persists tell whoever runs the colony.", "Inténtalo otra vez; si sigue, díselo a quien gestiona la colonia.") });
|
|
89
90
|
}
|
|
90
91
|
else if (open.status === 401) {
|
|
91
92
|
checks.push(input.apiKey
|
|
92
|
-
? { level: "fail", name: "Your access key", detail: "the colony does not accept it (401)", fix: "The key was copied wrong or has been revoked. Ask for a new one and run the setup command again." }
|
|
93
|
-
: { level: "fail", name: "Your access key", detail: "this colony needs a key and none is set", fix: "Run the setup command you were sent: npx myrmo-mcp init --url <colony> --key <your key> --publish auto." });
|
|
93
|
+
? { level: "fail", name: t("Your access key", "Tu clave de acceso"), detail: t("the colony does not accept it (401)", "la colonia no la acepta (401)"), fix: t("The key was copied wrong or has been revoked. Ask for a new one and run the setup command again.", "La clave se copió mal o se ha revocado. Pide una nueva y vuelve a ejecutar el comando de configuración.") }
|
|
94
|
+
: { level: "fail", name: t("Your access key", "Tu clave de acceso"), detail: t("this colony needs a key and none is set", "esta colonia necesita una clave y no hay ninguna"), fix: t("Run the setup command you were sent: npx myrmo-mcp init --url <colony> --key <your key> --publish auto.", "Ejecuta el comando de configuración que te enviaron: npx myrmo-mcp init --url <colony> --key <your key> --publish auto.") });
|
|
94
95
|
}
|
|
95
96
|
else if (open.status === 200) {
|
|
96
|
-
checks.push(input.apiKey ? { level: "ok", name: "Your access key", detail: "accepted" } : { level: "warn", name: "Your access key", detail: "this colony does not ask for a key", fix: "If it should be private, tell whoever runs it." });
|
|
97
|
+
checks.push(input.apiKey ? { level: "ok", name: t("Your access key", "Tu clave de acceso"), detail: t("accepted", "aceptada") } : { level: "warn", name: t("Your access key", "Tu clave de acceso"), detail: t("this colony does not ask for a key", "esta colonia no pide clave"), fix: t("If it should be private, tell whoever runs it.", "Si debería ser privada, díselo a quien la gestiona.") });
|
|
97
98
|
}
|
|
98
99
|
else {
|
|
99
|
-
checks.push({ level: "fail", name: "Your access key", detail: `the colony answered ${open.status}`, fix: "Tell whoever runs the colony." });
|
|
100
|
+
checks.push({ level: "fail", name: t("Your access key", "Tu clave de acceso"), detail: t(`the colony answered ${open.status}`, `la colonia respondió ${open.status}`), fix: t("Tell whoever runs the colony.", "Díselo a quien gestiona la colonia.") });
|
|
100
101
|
}
|
|
101
102
|
// A key travels in every request: on plain HTTP anyone on the network path can read it.
|
|
102
103
|
try {
|
|
103
104
|
const u = new URL(input.url);
|
|
104
105
|
const local = ["localhost", "127.0.0.1", "::1", "[::1]"].includes(u.hostname);
|
|
105
106
|
if (u.protocol === "http:" && !local && input.apiKey) {
|
|
106
|
-
checks.push({ level: "warn", name: "Encryption", detail: "plain HTTP: your key and what you share cross the network unencrypted", fix: "Fine on a network you trust; elsewhere ask whoever runs the colony to put TLS (HTTPS) in front of it." });
|
|
107
|
+
checks.push({ level: "warn", name: t("Encryption", "Cifrado"), detail: t("plain HTTP: your key and what you share cross the network unencrypted", "HTTP sin cifrar: tu clave y lo que compartes cruzan la red sin cifrar"), fix: t("Fine on a network you trust; elsewhere ask whoever runs the colony to put TLS (HTTPS) in front of it.", "Vale en una red de confianza; en otro caso pide a quien gestiona la colonia que ponga TLS (HTTPS) delante.") });
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
110
|
catch {
|
|
@@ -111,18 +112,18 @@ export async function diagnose(input) {
|
|
|
111
112
|
}
|
|
112
113
|
const declared = input.declared?.profile;
|
|
113
114
|
checks.push(input.privateMode
|
|
114
|
-
? { level: "ok", name: "Private mode", detail: `agents keep your internal names in what they publish${declared === "organisation" ? " (the colony declares itself your organisation's)" : ""}` }
|
|
115
|
+
? { level: "ok", name: t("Private mode", "Modo privado"), detail: t(`agents keep your internal names in what they publish${declared === "organisation" ? " (the colony declares itself your organisation's)" : ""}`, `los agentes conservan tus nombres internos en lo que publican${declared === "organisation" ? " (la colonia se declara de tu organización)" : ""}`) }
|
|
115
116
|
: declared === "public"
|
|
116
|
-
? { level: "ok", name: "Private mode", detail: "off: the colony declares itself public, so internal names are removed" }
|
|
117
|
-
: { level: "warn", name: "Private mode", detail: "off: agents would strip internal names from what they publish", fix: declared === "organisation" ? "Set your access key (npx myrmo-mcp init --url <colony> --key <your key>)." : "This colony does not say what it is (an older server): run the setup command again with --private (or set MYRMO_PRIVATE=1)." });
|
|
117
|
+
? { level: "ok", name: t("Private mode", "Modo privado"), detail: t("off: the colony declares itself public, so internal names are removed", "desactivado: la colonia se declara pública, así que se quitan los nombres internos") }
|
|
118
|
+
: { level: "warn", name: t("Private mode", "Modo privado"), detail: t("off: agents would strip internal names from what they publish", "desactivado: los agentes quitarían los nombres internos de lo que publican"), fix: declared === "organisation" ? t("Set your access key (npx myrmo-mcp init --url <colony> --key <your key>).", "Configura tu clave de acceso (npx myrmo-mcp init --url <colony> --key <your key>).") : t("This colony does not say what it is (an older server): run the setup command again with --private (or set MYRMO_PRIVATE=1).", "Esta colonia no dice qué es (un servidor más antiguo): vuelve a ejecutar el comando de configuración con --private (o define MYRMO_PRIVATE=1).") });
|
|
118
119
|
if (input.declared?.profile === "organisation") {
|
|
119
|
-
checks.push({ level: "ok", name: "What the colony keeps", detail: describeColony(input.declared) });
|
|
120
|
+
checks.push({ level: "ok", name: t("What the colony keeps", "Lo que guarda la colonia"), detail: describeColony(input.declared) });
|
|
120
121
|
}
|
|
121
122
|
checks.push(input.publish === "auto"
|
|
122
|
-
? { level: "ok", name: "Publishing", detail: "agents publish what they solve, to this colony only" }
|
|
123
|
+
? { level: "ok", name: t("Publishing", "Publicación"), detail: t("agents publish what they solve, to this colony only", "los agentes publican lo que resuelven, solo en esta colonia") }
|
|
123
124
|
: input.publish === "ask"
|
|
124
|
-
? { level: "ok", name: "Publishing", detail: "you approve each trail before it is sent" }
|
|
125
|
-
: { level: "warn", name: "Publishing", detail: `agents do not publish (${input.publish})`, fix: "npx myrmo-mcp config publish auto (or ask, to approve each one)" });
|
|
125
|
+
? { level: "ok", name: t("Publishing", "Publicación"), detail: t("you approve each trail before it is sent", "apruebas cada rastro antes de enviarlo") }
|
|
126
|
+
: { level: "warn", name: t("Publishing", "Publicación"), detail: t(`agents do not publish (${input.publish})`, `los agentes no publican (${input.publish})`), fix: t("npx myrmo-mcp config publish auto (or ask, to approve each one)", "npx myrmo-mcp config publish auto (o ask, para aprobar cada uno)") });
|
|
126
127
|
// Is this client the one the colony was released with? An older one misses what came after it.
|
|
127
128
|
const version = await call(fetchImpl, `${input.url.replace(/\/+$/, "")}/v1/version`, input.apiKey);
|
|
128
129
|
if ("status" in version && version.status === 200) {
|
|
@@ -136,34 +137,34 @@ export async function diagnose(input) {
|
|
|
136
137
|
if (latest && !VERSION_SHAPE.test(latest))
|
|
137
138
|
latest = undefined;
|
|
138
139
|
if (latest && compareVersions(VERSION, latest) < 0) {
|
|
139
|
-
checks.push({ level: "warn", name: "Myrmo version", detail: `myrmo-mcp ${VERSION} here, ${latest} released with this colony`, fix: "Claude Code: claude plugin update myrmo@myrmo (or /plugin > Marketplaces > myrmo > Enable auto-update). Other clients: npx myrmo-mcp@latest init with the same options as the first time." });
|
|
140
|
+
checks.push({ level: "warn", name: t("Myrmo version", "Versión de Myrmo"), detail: t(`myrmo-mcp ${VERSION} here, ${latest} released with this colony`, `myrmo-mcp ${VERSION} aquí, ${latest} publicada con esta colonia`), fix: t("Claude Code: claude plugin update myrmo@myrmo (or /plugin > Marketplaces > myrmo > Enable auto-update). Other clients: npx myrmo-mcp@latest init with the same options as the first time.", "Claude Code: claude plugin update myrmo@myrmo (o /plugin > Marketplaces > myrmo > Enable auto-update). Otros clientes: npx myrmo-mcp@latest init con las mismas opciones que la primera vez.") });
|
|
140
141
|
}
|
|
141
142
|
else if (latest) {
|
|
142
|
-
checks.push({ level: "ok", name: "Myrmo version", detail: `myrmo-mcp ${VERSION}, up to date with this colony` });
|
|
143
|
+
checks.push({ level: "ok", name: t("Myrmo version", "Versión de Myrmo"), detail: t(`myrmo-mcp ${VERSION}, up to date with this colony`, `myrmo-mcp ${VERSION}, al día con esta colonia`) });
|
|
143
144
|
}
|
|
144
145
|
}
|
|
145
146
|
const claude = claudeCodeSetUp(input.home);
|
|
146
147
|
const gemini = join(input.home, ".gemini", "GEMINI.md");
|
|
147
148
|
const geminiRules = existsSync(gemini) && readFileSync(gemini, "utf8").includes("myrmo:start");
|
|
148
149
|
if (claude || geminiRules) {
|
|
149
|
-
checks.push({ level: "ok", name: "Agents", detail: [claude ? `Claude Code: ${claude}` : "", geminiRules ? "Gemini CLI / Antigravity: rules installed" : ""].filter(Boolean).join("; ") });
|
|
150
|
+
checks.push({ level: "ok", name: t("Agents", "Agentes"), detail: [claude ? `Claude Code: ${claude}` : "", geminiRules ? t("Gemini CLI / Antigravity: rules installed", "Gemini CLI / Antigravity: reglas instaladas") : ""].filter(Boolean).join("; ") });
|
|
150
151
|
}
|
|
151
152
|
else {
|
|
152
|
-
checks.push({ level: "fail", name: "Agents", detail: "no agent on this machine is set up to use Myrmo", fix: "Run the setup command again, then restart Claude Code or Antigravity." });
|
|
153
|
+
checks.push({ level: "fail", name: t("Agents", "Agentes"), detail: t("no agent on this machine is set up to use Myrmo", "ningún agente de esta máquina está configurado para usar Myrmo"), fix: t("Run the setup command again, then restart Claude Code or Antigravity.", "Vuelve a ejecutar el comando de configuración y reinicia Claude Code o Antigravity.") });
|
|
153
154
|
}
|
|
154
155
|
checks.push({
|
|
155
156
|
level: "ok",
|
|
156
157
|
name: "Claude Desktop",
|
|
157
|
-
detail: "if you use it here, enable only one Myrmo integration there (the Plugin, for the public colony, or an Extension, for this one) — never both at once",
|
|
158
|
-
fix: "With both on, a tool call can be answered by the wrong one, silently: https://myrmo.dev/docs/reference/mcp#claude-desktop-when-the-colony-sits-behind-another-machine",
|
|
158
|
+
detail: t("if you use it here, enable only one Myrmo integration there (the Plugin, for the public colony, or an Extension, for this one) — never both at once", "si lo usas aquí, activa allí una sola integración de Myrmo (el Plugin, para la colonia pública, o una Extension, para esta), nunca las dos a la vez"),
|
|
159
|
+
fix: t("With both on, a tool call can be answered by the wrong one, silently: https://myrmo.dev/docs/reference/mcp#claude-desktop-when-the-colony-sits-behind-another-machine", "Con las dos activadas, una llamada a una herramienta puede responderla la equivocada, en silencio: https://myrmo.dev/docs/es/reference/mcp#claude-desktop-when-the-colony-sits-behind-another-machine"),
|
|
159
160
|
});
|
|
160
161
|
return checks;
|
|
161
162
|
}
|
|
162
163
|
export function render(checks) {
|
|
163
|
-
const mark = { ok: "ok ", warn: "warn", fail: "FAIL" };
|
|
164
|
+
const mark = { ok: "ok ", warn: t("warn", "ojo "), fail: t("FAIL", "MAL ") };
|
|
164
165
|
const lines = checks.flatMap((c) => [`[${mark[c.level]}] ${c.name}: ${c.detail}`, ...(c.fix ? [` -> ${c.fix}`] : [])]);
|
|
165
166
|
const failed = checks.filter((c) => c.level === "fail").length;
|
|
166
167
|
const warned = checks.filter((c) => c.level === "warn").length;
|
|
167
|
-
lines.push("", failed ? `${failed} problem${failed > 1 ? "s" : ""} to fix, then run this again.` : warned ? "Works, with things worth a look." : "Everything is in place. Restart your agent if you have not since the setup.");
|
|
168
|
+
lines.push("", failed ? t(`${failed} problem${failed > 1 ? "s" : ""} to fix, then run this again.`, `${failed} problema${failed > 1 ? "s" : ""} que arreglar; después vuelve a ejecutar esto.`) : warned ? t("Works, with things worth a look.", "Funciona, con cosas que conviene mirar.") : t("Everything is in place. Restart your agent if you have not since the setup.", "Todo está en orden. Reinicia tu agente si no lo has hecho desde la configuración."));
|
|
168
169
|
return lines.join("\n");
|
|
169
170
|
}
|
package/dist/hooks/lookup.mjs
CHANGED
|
@@ -260,16 +260,32 @@ export async function lookupTask(task, { env = process.env, settings = {}, fetch
|
|
|
260
260
|
|
|
261
261
|
const KINDS = { procedure: "procedure", fact: "fact", fix: "known error" };
|
|
262
262
|
|
|
263
|
+
/**
|
|
264
|
+
* The hits worth showing unasked: a suggestion the agent did not ask for has to be clearly about the task, or it teaches
|
|
265
|
+
* the agent to ignore the next one. A hit below `min` is left out, and so is one far below the best (more than `spread`).
|
|
266
|
+
* Measured on an organisation's colony: the right entry scored 0.63 to 0.79, unrelated ones 0.55 to 0.59, so no single
|
|
267
|
+
* cut separates them, but the two together do. A hit without a score (an older colony) is kept.
|
|
268
|
+
*/
|
|
269
|
+
export function relevantHits(results, { min = 0.6, spread = 0.15 } = {}) {
|
|
270
|
+
const score = (hit) => Number(hit?.match?.score);
|
|
271
|
+
const scored = results.filter((hit) => Number.isFinite(score(hit)));
|
|
272
|
+
if (!scored.length) return results;
|
|
273
|
+
const best = Math.max(...scored.map(score));
|
|
274
|
+
return results.filter((hit) => !Number.isFinite(score(hit)) || (score(hit) >= min && score(hit) >= best - spread));
|
|
275
|
+
}
|
|
276
|
+
|
|
263
277
|
/**
|
|
264
278
|
* The short list for the agent, and the state that lets the Stop hook ask for reports on what was shown. No note when
|
|
265
279
|
* nothing matched.
|
|
266
280
|
*/
|
|
267
|
-
export function briefNote(task, body, state = {}, now = Date.now(), how = "") {
|
|
281
|
+
export function briefNote(task, body, state = {}, now = Date.now(), how = "", { min = 0.6, spread = 0.15 } = {}) {
|
|
268
282
|
// An entry already shown in this session is not shown again: the agent has it, and repeating an unrelated one on every
|
|
269
283
|
// prompt is noise.
|
|
270
284
|
const seen = Array.isArray(state.briefSeen) ? state.briefSeen : [];
|
|
271
285
|
const idOf = (hit) => String(hit?.trail_id ?? "").replace(/[^0-9a-fA-F-]/g, "").slice(0, 36);
|
|
272
|
-
const hits = (Array.isArray(body?.results) ? body.results : []
|
|
286
|
+
const hits = relevantHits(Array.isArray(body?.results) ? body.results : [], { min, spread })
|
|
287
|
+
.filter((hit) => !seen.includes(idOf(hit)))
|
|
288
|
+
.slice(0, 3);
|
|
273
289
|
if (!hits.length) return { note: null, state };
|
|
274
290
|
const ids = [];
|
|
275
291
|
const lines = hits.map((hit, i) => {
|
|
@@ -281,7 +297,9 @@ export function briefNote(task, body, state = {}, now = Date.now(), how = "") {
|
|
|
281
297
|
const about = clip(t.problem?.summary || t.problem?.error_message || t.problem?.error_type, 160);
|
|
282
298
|
const o = hit.outcomes ?? {};
|
|
283
299
|
const strength = Number(hit.strength ?? 0);
|
|
284
|
-
|
|
300
|
+
const due = /^\d{4}-\d{2}-\d{2}$/.exec(String(hit.review_due ?? ""))?.[0];
|
|
301
|
+
const review = due ? ` [review due since ${due}: may be out of date]` : "";
|
|
302
|
+
return `${i + 1}. [${kind}] ${about} (strength ${Number.isFinite(strength) ? strength.toFixed(2) : "?"}, worked ${num(o.worked, "0")}, failed ${num(o.failed, "0")})${review} id ${id}`;
|
|
285
303
|
});
|
|
286
304
|
const note = [
|
|
287
305
|
"Myrmo (your organisation's private colony) already has knowledge that may help with this task:",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
// 5. After a failed command, the hook searches the colony itself and shows a strong match (lookup.mjs).
|
|
22
22
|
// 6. When the user sends a request, the hook asks the colony what the organisation already knows about that task and
|
|
23
23
|
// shows a short list (UserPromptSubmit; lookup.mjs `briefNote`). MYRMO_HOOK_BRIEF=off turns only this off.
|
|
24
|
-
// 7. When the agent stops after a turn in which commands failed or knowledge was shown, it is asked once to report what
|
|
24
|
+
// 7. (In the public colony too, only for trails shown and not reported on.) When the agent stops after a turn in which commands failed or knowledge was shown, it is asked once to report what
|
|
25
25
|
// it relied on and to share what the next person's agent would need (Stop hook): what is learned in a session
|
|
26
26
|
// otherwise leaves with it.
|
|
27
27
|
//
|
|
@@ -51,6 +51,7 @@ const SHELLS = new Set(["Bash", "PowerShell"]);
|
|
|
51
51
|
const SEARCH_TOOL = /^mcp__.*myrmo_search$/;
|
|
52
52
|
const REPORT_TOOL = /^mcp__.*myrmo_report$/;
|
|
53
53
|
const PUBLISH_TOOL = /^mcp__.*myrmo_publish$/;
|
|
54
|
+
const BRIEF_TOOL = /^mcp__.*myrmo_brief$/;
|
|
54
55
|
// The id each trail is listed under in a search reply (`## Trail 1 of 2 · id <uuid>`).
|
|
55
56
|
const TRAIL_ID = /^## Trail \d+ of \d+ · id ([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/i;
|
|
56
57
|
|
|
@@ -183,6 +184,29 @@ function segmentsWithPipes(text) {
|
|
|
183
184
|
return out.map((w) => w.filter((x) => !/^\d*[<>]&?\d*$/.test(x) && !/^\d*>&\d+$/.test(x)));
|
|
184
185
|
}
|
|
185
186
|
|
|
187
|
+
// A tool saying it was called wrongly (a mistyped flag): the agent's own slip, fixed by reading the line, not knowledge to
|
|
188
|
+
// look up or share.
|
|
189
|
+
const USAGE_LINE = /\b(?:unknown (?:shorthand )?flag|unknown option|unrecognized option|invalid option|illegal option)\b|^\s*usage:/im;
|
|
190
|
+
|
|
191
|
+
/** Whether the command ends in a test whose "false" is an answer: `... ; [ -f x ] && echo found`, also as the last
|
|
192
|
+
* statement of a loop body. Exit 1 then says the condition did not hold, not that anything failed. */
|
|
193
|
+
export function endsInTest(command) {
|
|
194
|
+
const body = String(command).trim().replace(/(?:\s*;?\s*\b(?:done|fi)\b)+\s*$/, "");
|
|
195
|
+
const last = body.split(/;|\n|\bdo\b|\bthen\b/).at(-1)?.trim() ?? "";
|
|
196
|
+
// After `||` or a pipe the exit code is another command's: `test -d x || mkdir x` failing is mkdir failing.
|
|
197
|
+
if (/\|/.test(last)) return false;
|
|
198
|
+
const isTest = (part) => /^(?:\[\[?|test\b)/.test(part);
|
|
199
|
+
const parts = last.split(/&&/).map((part) => part.trim());
|
|
200
|
+
// `[ ... ]` alone, `[ ... ] && echo yes`, or a chain whose test comes right before the final echo.
|
|
201
|
+
return isTest(parts[0]) && parts.length <= 2
|
|
202
|
+
|| (parts.length >= 2 && isTest(parts.at(-2)) && /^(?:echo|printf|true|:)(?:\s|$)/.test(parts.at(-1)));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** A line in the shape a program gives its messages, `program: what happened`, and not data such as `key=value`. */
|
|
206
|
+
function toolMessage(line) {
|
|
207
|
+
return /^[\w.\/-]+:\s+\S/.test(line) && !/\w=\S/.test(line) ? line : "";
|
|
208
|
+
}
|
|
209
|
+
|
|
186
210
|
const HELP_LINE = /\[Help \d+\]|re-run maven|for more information about the errors|to see the full stack trace|^\[(?:ERROR|FATAL)\]\s*$/i;
|
|
187
211
|
|
|
188
212
|
/** The user's settings file (the same one the SDKs and the MCP server read). Missing or damaged means defaults. */
|
|
@@ -323,6 +347,11 @@ export function decide(input, { now = Date.now(), state = {}, env = process.env,
|
|
|
323
347
|
}
|
|
324
348
|
return quiet(state);
|
|
325
349
|
}
|
|
350
|
+
// The agent read the knowledge the hook suggested (myrmo_brief) or searched itself: only then may it be asked to report.
|
|
351
|
+
if (BRIEF_TOOL.test(String(tool)) || (SEARCH_TOOL.test(String(tool)) && state.brief && !state.brief.used)) {
|
|
352
|
+
if (state.brief && !state.brief.reported) state = { ...state, brief: { ...state.brief, used: true } };
|
|
353
|
+
if (BRIEF_TOOL.test(String(tool))) return quiet(state);
|
|
354
|
+
}
|
|
326
355
|
// 4b. The agent reported: nothing left to remind. A trail that worked for the open problem: what it cost with help.
|
|
327
356
|
if (REPORT_TOOL.test(String(tool))) {
|
|
328
357
|
const brief = state.brief ? { ...state.brief, reported: true } : state.brief;
|
|
@@ -336,7 +365,7 @@ export function decide(input, { now = Date.now(), state = {}, env = process.env,
|
|
|
336
365
|
}
|
|
337
366
|
// The agent shared what it learned: the failures so far need no further asking when it stops.
|
|
338
367
|
if (PUBLISH_TOOL.test(String(tool))) {
|
|
339
|
-
return quiet({ ...state, harvestedAt: Math.max(Number(state.harvestedAt ?? 0), Number(state.failures ?? 0)), publishedTs: now });
|
|
368
|
+
return quiet({ ...state, harvestedAt: Math.max(Number(state.harvestedAt ?? 0), Number(state.failures ?? 0)), harvestedResolved: Number(state.resolved ?? 0), publishedTs: now });
|
|
340
369
|
}
|
|
341
370
|
if (!SHELLS.has(tool)) return quiet(state);
|
|
342
371
|
|
|
@@ -357,10 +386,14 @@ export function decide(input, { now = Date.now(), state = {}, env = process.env,
|
|
|
357
386
|
// 1. A command failed.
|
|
358
387
|
if (failed) {
|
|
359
388
|
if (input.is_interrupt === true || STOPPED.has(code) || isProbe(command) || answered(command, code)) return quiet(state);
|
|
389
|
+
if (code === 1 && endsInTest(command)) return quiet(state);
|
|
360
390
|
const output = errorText.replace(/^Exit code \d+\r?\n?/, "");
|
|
361
|
-
// A company's own tools print errors in no
|
|
362
|
-
//
|
|
363
|
-
|
|
391
|
+
// A company's own tools print errors in shapes no pattern knows (`migrate: lock 'migrate' is held by ci-runner-17`):
|
|
392
|
+
// the loose patterns take a line that says something failed, or else a last line in the shape tools give their
|
|
393
|
+
// messages (`program: message`). Nothing else is quoted or looked up: the last line of a loop that printed data
|
|
394
|
+
// (`bucket-a objects=95`) is not an error, and searching for it only teaches the agent to ignore the note.
|
|
395
|
+
const line = lastErrorLine(output, { loose: true }) || toolMessage(lastLine(output));
|
|
396
|
+
if (line && USAGE_LINE.test(line)) return quiet(state);
|
|
364
397
|
const problem = openProblem(state, now) ?? (line ? { at: now, line } : null);
|
|
365
398
|
const next = { ...state, failed: { key: commandKey(command), at: now, line }, failures: (state.failures ?? 0) + 1, problem };
|
|
366
399
|
const sig = signature(line);
|
|
@@ -377,6 +410,11 @@ export function decide(input, { now = Date.now(), state = {}, env = process.env,
|
|
|
377
410
|
|
|
378
411
|
if (mode === "failures" || event === undefined || isProbe(command)) return quiet(state);
|
|
379
412
|
|
|
413
|
+
// A command that failed now works: something was solved, which is what the Stop hook may ask to share.
|
|
414
|
+
if (state.failed && !state.failed.resolved && commandKey(command) === state.failed.key && now - state.failed.at < PROBLEM_MS) {
|
|
415
|
+
state = { ...state, failed: { ...state.failed, resolved: true }, resolved: Number(state.resolved ?? 0) + 1 };
|
|
416
|
+
}
|
|
417
|
+
|
|
380
418
|
// 3b. A command that failed earlier now works, and Myrmo had nothing: the agent may have solved something new.
|
|
381
419
|
const nomatch = state.nomatch;
|
|
382
420
|
if (nomatch && !nomatch.nudged && now - nomatch.at < 45 * 60_000 && state.failed && commandKey(command) === state.failed.key && !spent) {
|
|
@@ -450,24 +488,46 @@ export function decide(input, { now = Date.now(), state = {}, env = process.env,
|
|
|
450
488
|
}
|
|
451
489
|
|
|
452
490
|
/**
|
|
453
|
-
*
|
|
454
|
-
*
|
|
455
|
-
*
|
|
456
|
-
*
|
|
491
|
+
* 6b. The agent is about to stop in the public colony, with trails shown to it and not reported on: ask once for the
|
|
492
|
+
* report, and nothing else. Measured on the public colony, 8 reports followed 235 searches that returned trails: the
|
|
493
|
+
* reminder after a failed command succeeds again rarely applies (a fix is often checked by another command), and
|
|
494
|
+
* without the outcome a trail can neither rise nor fade. Not after the reminder of case 4 (it already asked), not for
|
|
495
|
+
* trails shown more than 12 hours ago, and once per set of trails.
|
|
496
|
+
*/
|
|
497
|
+
function askToReport(state, now) {
|
|
498
|
+
const found = state.found;
|
|
499
|
+
const none = { reason: null, state };
|
|
500
|
+
if (!found || found.nudged || found.asked || !Array.isArray(found.ids) || !found.ids.length) return none;
|
|
501
|
+
if (now - found.at > 12 * 3_600_000) return none;
|
|
502
|
+
const reason =
|
|
503
|
+
`Myrmo: before you finish, call myrmo_report once for each trail it showed you (${found.ids.join(", ")}) that you tried: ` +
|
|
504
|
+
"worked, partially_worked, or failed if it was wrong or out of date, saying what changed; not_applicable if it was about something else. " +
|
|
505
|
+
"It is how good trails rise and stale ones fade. If you tried none, finish.";
|
|
506
|
+
return { reason, state: { ...state, found: { ...found, asked: true } } };
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* 6. The agent is about to stop. In a private colony, after a turn in which a failed command was made to work, ask it once
|
|
511
|
+
* to share what it learned before it finishes: Claude Code then continues with this as its next instruction. At most once
|
|
512
|
+
* every MYRMO_HARVEST_MINUTES (default 30) and three times a session, never while it is already continuing because of this
|
|
513
|
+
* hook, and only for what was solved since the last time it was asked. Knowledge the hook suggested is asked about only
|
|
514
|
+
* if the agent read it (myrmo_brief or myrmo_search): a suggestion it never opened was not relied on.
|
|
457
515
|
*/
|
|
458
516
|
export function decideStop(input, { now = Date.now(), state = {}, env = process.env, settings = {} } = {}) {
|
|
459
517
|
const none = { reason: null, state };
|
|
460
|
-
if (hookMode(env, settings) === "off" ||
|
|
518
|
+
if (hookMode(env, settings) === "off" || env.MYRMO_HARVEST === "off") return none;
|
|
461
519
|
if (input?.stop_hook_active === true) return none;
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
const
|
|
465
|
-
|
|
520
|
+
if (!privateColony(env, settings)) return askToReport(state, now);
|
|
521
|
+
const resolved = Number(state.resolved ?? 0);
|
|
522
|
+
const solvedSince = resolved > Number(state.harvestedResolved ?? 0);
|
|
523
|
+
// Knowledge shown at the start of the task, read by the agent and not reported on yet: worth asking once.
|
|
524
|
+
const shown = state.brief && state.brief.used && !state.brief.reported && !state.brief.asked ? state.brief : null;
|
|
525
|
+
if (!solvedSince && !shown) return none;
|
|
466
526
|
const minMs = Number(env.MYRMO_HARVEST_MINUTES ?? 30) * 60_000;
|
|
467
527
|
if ((state.harvests ?? 0) >= 3 || (state.harvestedTs && now - state.harvestedTs < minMs)) return none;
|
|
468
528
|
// Nothing new failed since this session last published: what is left is only reporting on what was shown, so ask that alone
|
|
469
529
|
// instead of asking again to share what was learned.
|
|
470
|
-
if (
|
|
530
|
+
if (!solvedSince && shown) {
|
|
471
531
|
const reason =
|
|
472
532
|
`Myrmo: before you finish, call myrmo_report for each entry it showed you for this task (${shown.ids.join(", ")}) that you actually relied on ` +
|
|
473
533
|
"(worked, partially_worked, or failed if it was wrong or out of date, saying what changed); skip the ones you did not use. If you used none, finish.";
|
|
@@ -486,7 +546,7 @@ export function decideStop(input, { now = Date.now(), state = {}, env = process.
|
|
|
486
546
|
"what, where something is configured), publish it with kind \"fact\". Keep internal names and addresses as printed; never include credentials or personal data. " +
|
|
487
547
|
"If nothing qualifies, say so in one line and finish.";
|
|
488
548
|
const brief = shown ? { ...shown, asked: true } : state.brief;
|
|
489
|
-
return { reason, state: { ...state, brief, harvestedAt: failures, harvestedTs: now, harvests: (state.harvests ?? 0) + 1 } };
|
|
549
|
+
return { reason, state: { ...state, brief, harvestedAt: Number(state.failures ?? 0), harvestedResolved: resolved, harvestedTs: now, harvests: (state.harvests ?? 0) + 1 } };
|
|
490
550
|
}
|
|
491
551
|
|
|
492
552
|
/** Without the file (a folder that cannot be trusted, a full disk) the notes are simply not throttled. */
|
|
@@ -515,7 +575,9 @@ async function main() {
|
|
|
515
575
|
const task = taskOf(input.prompt);
|
|
516
576
|
if (!task || hookMode(process.env, settings) === "off" || !briefEnabled(process.env, settings)) return;
|
|
517
577
|
const body = await lookupTask(task, { settings, agent: "myrmo-claude-code-hook/1" });
|
|
518
|
-
|
|
578
|
+
// MYRMO_HOOK_BRIEF_MIN: the lowest score a suggestion may have (default 0.6).
|
|
579
|
+
const min = Number(process.env.MYRMO_HOOK_BRIEF_MIN);
|
|
580
|
+
const out = briefNote(task, body, state, Date.now(), "", Number.isFinite(min) && min > 0 ? { min } : {});
|
|
519
581
|
save(file, state, out.state);
|
|
520
582
|
if (out.note) process.stdout.write(JSON.stringify({ hookSpecificOutput: { hookEventName: "UserPromptSubmit", additionalContext: out.note } }));
|
|
521
583
|
return;
|
package/dist/hooks/redact.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Generated from clients/typescript/packages/myrmo/src/redact.ts by clients/typescript/scripts/sync-plugin-redact.mjs.
|
|
2
2
|
// Do not edit: change the SDK, build it and run that script. The SDK's tests check that this copy is current.
|
|
3
3
|
// Client-side redaction: the same detectors the colony runs, applied before anything leaves the
|
|
4
|
-
// machine. Keep in sync with server
|
|
4
|
+
// machine. Keep in sync with the colony server's redaction and clients/python/src/myrmo/redact.py: all
|
|
5
5
|
// three must reproduce protocol/redact.v1.vectors.json exactly.
|
|
6
6
|
//
|
|
7
7
|
// Rules run in order, most specific first. A rule's replacement never matches a later rule (it
|
|
@@ -110,7 +110,11 @@ const CLI_NAMES = "password|passwd|pwd|pass|passphrase|secret|token|api[_-]?key|
|
|
|
110
110
|
// `"$PWD:/src"` and `$PATH:/opt/bin` expand a shell variable and go on with more text: the name gives no value.
|
|
111
111
|
// `$TOKEN=value` is still redacted, since what follows the `=` may well be a secret.
|
|
112
112
|
const expandsVariable = (name) => name.startsWith("$") && name.trimEnd().endsWith(":");
|
|
113
|
-
|
|
113
|
+
// `The secret: after the push, rotate it` is a sentence, not a value: after `name:` and a space, an unquoted common word
|
|
114
|
+
// is prose. The list is short on purpose; anything else after the colon is still redacted.
|
|
115
|
+
const PROSE_WORDS = new Set(["after", "before", "when", "then", "that", "this", "these", "those", "with", "without", "from", "into", "once", "until", "while", "where", "which", "what", "also", "only", "must", "should", "will", "would", "could", "have", "been", "does", "here", "there", "they", "them", "your", "every", "each", "never", "always", "cannot", "para", "pero", "como", "cuando", "antes", "desde", "hasta", "tras", "sobre", "este", "esta", "esto", "nunca", "siempre", "debe", "puede", "solo"]);
|
|
116
|
+
const proseAfterColon = (m) => /:[ \t]+$/.test(m[1]) && !m[2] && PROSE_WORDS.has(m[3].toLowerCase());
|
|
117
|
+
const assignment = (m) => (expandsVariable(m[1]) || isReference(m[3]) || proseAfterColon(m) ? null : m[1] + m[2] + full("secret"));
|
|
114
118
|
/** Replaces the value group with `<redacted:secret>`, keeping every group before and after it. */
|
|
115
119
|
const valueOnly = (valueGroup) => (m) => isReference(m[valueGroup])
|
|
116
120
|
? null
|
package/dist/i18n.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type Lang = "en" | "es";
|
|
2
|
+
export declare function language(env?: NodeJS.ProcessEnv): Lang;
|
|
3
|
+
/** The text in the person's language. */
|
|
4
|
+
export declare function t(en: string, es: string): string;
|
|
5
|
+
/** For tests and for `--lang`: print in this language from now on. */
|
|
6
|
+
export declare function setLanguage(lang: Lang): void;
|
package/dist/i18n.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// The language of what the commands print for a person (init, join, doctor, config, export): Spanish when MYRMO_LANG
|
|
2
|
+
// says so or the system's language is Spanish, English otherwise. What the server tells the agent stays English.
|
|
3
|
+
export function language(env = process.env) {
|
|
4
|
+
const explicit = env.MYRMO_LANG?.trim().toLowerCase();
|
|
5
|
+
if (explicit === "es" || explicit === "en")
|
|
6
|
+
return explicit;
|
|
7
|
+
// The first locale variable that names a language decides; C and POSIX name none.
|
|
8
|
+
for (const value of [env.LC_ALL, env.LC_MESSAGES, env.LANG]) {
|
|
9
|
+
if (!value || /^(C|POSIX)([._@]|$)/i.test(value))
|
|
10
|
+
continue;
|
|
11
|
+
return /^es([_.\-@]|$)/i.test(value) ? "es" : "en";
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
return /^es\b/i.test(Intl.DateTimeFormat().resolvedOptions().locale) ? "es" : "en";
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return "en";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
let current = language();
|
|
21
|
+
/** The text in the person's language. */
|
|
22
|
+
export function t(en, es) {
|
|
23
|
+
return current === "es" ? es : en;
|
|
24
|
+
}
|
|
25
|
+
/** For tests and for `--lang`: print in this language from now on. */
|
|
26
|
+
export function setLanguage(lang) {
|
|
27
|
+
current = lang;
|
|
28
|
+
}
|