busybits 2.1.0 → 2.3.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/.claude-plugin/marketplace.json +1 -1
- package/CHANGELOG.md +16 -0
- package/dist/build.json +2 -2
- package/dist/cli/busybits.js +42 -3
- package/dist/client/bundle/{app-Y2N0l58V.css → app-Cn3BvqjA.css} +1 -1
- package/dist/client/bundle/app-DatmLMV4.js +24 -0
- package/dist/client/bundle/{city-SSVRvwxu.js → city-Obp81Tgi.js} +1 -1
- package/dist/client/bundle/{daystats-B5wgtYEK.js → daystats-Da82sNh9.js} +1 -1
- package/dist/client/bundle/{dom-DTwIMOMe.js → dom-DPKsIT1T.js} +1 -1
- package/dist/client/bundle/{en-C1UkXkY6.js → en-D6p_-oC0.js} +2 -2
- package/dist/client/bundle/{es-DrTXrvU-.js → es-aBALBWWq.js} +2 -2
- package/dist/client/bundle/{format-COWnO8aN.js → format-DS9qjIGc.js} +1 -1
- package/dist/client/bundle/{fr-DSvgQnax.js → fr-BE8l2fLL.js} +2 -2
- package/dist/client/bundle/{main-CjRdSA5N.js → main-Bv-qstsh.js} +2 -2
- package/dist/client/bundle/{ptypane-BU6MDOyh.js → ptypane-C7Nw8-Dx.js} +1 -1
- package/dist/client/bundle/room-name-Bf-U1Fyo.js +1 -0
- package/dist/client/bundle/{simulator-BhSq5TwZ.js → simulator-B4Usk2yH.js} +1 -1
- package/dist/client/bundle/{world-model-D6tSJZPE.js → world-model-CkevAUmh.js} +1 -1
- package/dist/client/bundle/{world-stream-pGb-glkT.js → world-stream-CuZouXr_.js} +1 -1
- package/dist/client/index.html +1 -1
- package/dist/server/index.js +732 -439
- package/mod/habblaud/.claude-plugin/plugin.json +1 -1
- package/mod/habblaud-mensagens/.claude-plugin/plugin.json +1 -1
- package/mod/habblaud-permissoes/.claude-plugin/plugin.json +1 -1
- package/mod/habblaud-pi/package.json +1 -1
- package/package.json +1 -1
- package/dist/client/bundle/app-BXRp9yel.js +0 -24
- package/dist/client/bundle/room-name-DefEKN7q.js +0 -1
package/dist/server/index.js
CHANGED
|
@@ -521,6 +521,7 @@ var EN = {
|
|
|
521
521
|
"O job falhou e vai sair do escrit\xF3rio.": "The job failed and is leaving the office.",
|
|
522
522
|
"Job do Agent Hub": "Agent Hub job",
|
|
523
523
|
"Agent Hub": "Agent Hub",
|
|
524
|
+
"Gentle Shell": "Gentle Shell",
|
|
524
525
|
"Somente leitura: o Agent Hub gerencia este job": "Read-only: Agent Hub owns this job",
|
|
525
526
|
"Na fila do Agent Hub": "Queued in Agent Hub",
|
|
526
527
|
"Erro": "Error",
|
|
@@ -3725,7 +3726,19 @@ var EN = {
|
|
|
3725
3726
|
"Itens deixados na sua mesa. Clique para abrir.": "Items left on your desk. Click to open.",
|
|
3726
3727
|
"na mesa": "on desk",
|
|
3727
3728
|
"Na sua mesa": "On your desk",
|
|
3728
|
-
"Mensageiro": "Courier"
|
|
3729
|
+
"Mensageiro": "Courier",
|
|
3730
|
+
"Padr\xE3o": "Default",
|
|
3731
|
+
"Padr\xE3o (ou escreva o modelo, ex.: gpt-5.5)": "Default (or type the model, e.g. gpt-5.5)",
|
|
3732
|
+
"Outro modelo": "Other model",
|
|
3733
|
+
"Carregando a lista de modelos\u2026": "Loading the model list\u2026",
|
|
3734
|
+
"Lista de modelos indispon\xEDvel: usa o padr\xE3o": "Model list unavailable: using the default",
|
|
3735
|
+
"Modelo inv\xE1lido: use letras, d\xEDgitos e . - _ / :": "Invalid model: use letters, digits and . - _ / :",
|
|
3736
|
+
"modelo inv\xE1lido": "invalid model",
|
|
3737
|
+
"modelo inv\xE1lido (use letras, d\xEDgitos e . - _ / :, at\xE9 {0} caracteres)": "invalid model (use letters, digits and . - _ / :, up to {0} characters)",
|
|
3738
|
+
"modelo desconhecido para o Claude Code": "unknown model for Claude Code",
|
|
3739
|
+
"a lista de modelos do Gentle Shell ainda n\xE3o carregou: abra o di\xE1logo de novo": "the Gentle Shell model list has not loaded yet: open the dialog again",
|
|
3740
|
+
"modelo desconhecido para o Gentle Shell": "unknown model for Gentle Shell",
|
|
3741
|
+
"no Docker o agente novo n\xE3o aceita escolher o modelo": "in Docker, a new agent cannot choose the model"
|
|
3729
3742
|
};
|
|
3730
3743
|
|
|
3731
3744
|
// shared/locales/es.ts
|
|
@@ -4223,6 +4236,7 @@ var ES = {
|
|
|
4223
4236
|
"O job falhou e vai sair do escrit\xF3rio.": "El trabajo fall\xF3 y saldr\xE1 de la oficina.",
|
|
4224
4237
|
"Job do Agent Hub": "Trabajo de Agent Hub",
|
|
4225
4238
|
"Agent Hub": "Agent Hub",
|
|
4239
|
+
"Gentle Shell": "Gentle Shell",
|
|
4226
4240
|
"Somente leitura: o Agent Hub gerencia este job": "Solo lectura: Agent Hub gestiona este trabajo",
|
|
4227
4241
|
"Na fila do Agent Hub": "En la cola de Agent Hub",
|
|
4228
4242
|
"Erro": "Error",
|
|
@@ -7427,7 +7441,19 @@ var ES = {
|
|
|
7427
7441
|
"Itens deixados na sua mesa. Clique para abrir.": "Elementos dejados en tu escritorio. Haz clic para abrir.",
|
|
7428
7442
|
"na mesa": "en el escritorio",
|
|
7429
7443
|
"Na sua mesa": "En tu escritorio",
|
|
7430
|
-
"Mensageiro": "Mensajero"
|
|
7444
|
+
"Mensageiro": "Mensajero",
|
|
7445
|
+
"Padr\xE3o": "Predeterminado",
|
|
7446
|
+
"Padr\xE3o (ou escreva o modelo, ex.: gpt-5.5)": "Predeterminado (o escribe el modelo, p. ej. gpt-5.5)",
|
|
7447
|
+
"Outro modelo": "Otro modelo",
|
|
7448
|
+
"Carregando a lista de modelos\u2026": "Cargando la lista de modelos\u2026",
|
|
7449
|
+
"Lista de modelos indispon\xEDvel: usa o padr\xE3o": "Lista de modelos no disponible: se usa el predeterminado",
|
|
7450
|
+
"Modelo inv\xE1lido: use letras, d\xEDgitos e . - _ / :": "Modelo no v\xE1lido: usa letras, d\xEDgitos y . - _ / :",
|
|
7451
|
+
"modelo inv\xE1lido": "modelo no v\xE1lido",
|
|
7452
|
+
"modelo inv\xE1lido (use letras, d\xEDgitos e . - _ / :, at\xE9 {0} caracteres)": "modelo no v\xE1lido (usa letras, d\xEDgitos y . - _ / :, hasta {0} caracteres)",
|
|
7453
|
+
"modelo desconhecido para o Claude Code": "modelo desconocido para Claude Code",
|
|
7454
|
+
"a lista de modelos do Gentle Shell ainda n\xE3o carregou: abra o di\xE1logo de novo": "la lista de modelos de Gentle Shell a\xFAn no se carg\xF3: abre el di\xE1logo de nuevo",
|
|
7455
|
+
"modelo desconhecido para o Gentle Shell": "modelo desconocido para Gentle Shell",
|
|
7456
|
+
"no Docker o agente novo n\xE3o aceita escolher o modelo": "en Docker, un agente nuevo no puede elegir el modelo"
|
|
7431
7457
|
};
|
|
7432
7458
|
|
|
7433
7459
|
// shared/locales/fr.ts
|
|
@@ -7918,6 +7944,7 @@ var FR = {
|
|
|
7918
7944
|
"O job falhou e vai sair do escrit\xF3rio.": "Le job a \xE9chou\xE9 et quitte le bureau.",
|
|
7919
7945
|
"Job do Agent Hub": "Job Agent Hub",
|
|
7920
7946
|
"Agent Hub": "Agent Hub",
|
|
7947
|
+
"Gentle Shell": "Gentle Shell",
|
|
7921
7948
|
"Somente leitura: o Agent Hub gerencia este job": "Lecture seule : Agent Hub g\xE8re ce job",
|
|
7922
7949
|
"Na fila do Agent Hub": "Dans la file d'attente d'Agent Hub",
|
|
7923
7950
|
"Erro": "Erreur",
|
|
@@ -11156,7 +11183,19 @@ Exemple :
|
|
|
11156
11183
|
"Itens deixados na sua mesa. Clique para abrir.": "\xC9l\xE9ments laiss\xE9s sur votre bureau. Cliquez pour ouvrir.",
|
|
11157
11184
|
"na mesa": "sur le bureau",
|
|
11158
11185
|
"Na sua mesa": "Sur votre bureau",
|
|
11159
|
-
"Mensageiro": "Coursier"
|
|
11186
|
+
"Mensageiro": "Coursier",
|
|
11187
|
+
"Padr\xE3o": "Par d\xE9faut",
|
|
11188
|
+
"Padr\xE3o (ou escreva o modelo, ex.: gpt-5.5)": "Par d\xE9faut (ou saisissez le mod\xE8le, ex. gpt-5.5)",
|
|
11189
|
+
"Outro modelo": "Autre mod\xE8le",
|
|
11190
|
+
"Carregando a lista de modelos\u2026": "Chargement de la liste des mod\xE8les\u2026",
|
|
11191
|
+
"Lista de modelos indispon\xEDvel: usa o padr\xE3o": "Liste des mod\xE8les indisponible : le mod\xE8le par d\xE9faut est utilis\xE9",
|
|
11192
|
+
"Modelo inv\xE1lido: use letras, d\xEDgitos e . - _ / :": "Mod\xE8le invalide : utilisez des lettres, des chiffres et . - _ / :",
|
|
11193
|
+
"modelo inv\xE1lido": "mod\xE8le invalide",
|
|
11194
|
+
"modelo inv\xE1lido (use letras, d\xEDgitos e . - _ / :, at\xE9 {0} caracteres)": "mod\xE8le invalide (utilisez des lettres, des chiffres et . - _ / :, jusqu'\xE0 {0} caract\xE8res)",
|
|
11195
|
+
"modelo desconhecido para o Claude Code": "mod\xE8le inconnu pour Claude Code",
|
|
11196
|
+
"a lista de modelos do Gentle Shell ainda n\xE3o carregou: abra o di\xE1logo de novo": "la liste des mod\xE8les de Gentle Shell n'est pas encore charg\xE9e : rouvrez la bo\xEEte de dialogue",
|
|
11197
|
+
"modelo desconhecido para o Gentle Shell": "mod\xE8le inconnu pour Gentle Shell",
|
|
11198
|
+
"no Docker o agente novo n\xE3o aceita escolher o modelo": "dans Docker, un nouvel agent ne peut pas choisir le mod\xE8le"
|
|
11160
11199
|
};
|
|
11161
11200
|
|
|
11162
11201
|
// shared/locales/all.ts
|
|
@@ -18743,9 +18782,9 @@ function validState(body2) {
|
|
|
18743
18782
|
const ptys2 = body2.ptys;
|
|
18744
18783
|
if (!isObj2(ptys2) || !isObj2(ptys2.status) || typeof ptys2.status.enabled !== "boolean" || !Array.isArray(ptys2.list))
|
|
18745
18784
|
return bad();
|
|
18746
|
-
const
|
|
18785
|
+
const num12 = (v) => v === void 0 || typeof v === "number" && Number.isFinite(v);
|
|
18747
18786
|
ptys2.list = ptys2.list.filter(
|
|
18748
|
-
(p) => isObj2(p) && isStr(p.id) && isStr(p.agentId) && isStr(p.account) && isStr(p.cwd) && typeof p.pid === "number" && Number.isFinite(p.pid) &&
|
|
18787
|
+
(p) => isObj2(p) && isStr(p.id) && isStr(p.agentId) && isStr(p.account) && isStr(p.cwd) && typeof p.pid === "number" && Number.isFinite(p.pid) && num12(p.startedAt) && num12(p.exitedAt) && num12(p.exitCode) && (p.fromAgent === void 0 || isStr(p.fromAgent)) && (p.resumed === void 0 || isStr(p.resumed))
|
|
18749
18788
|
).slice(0, 32);
|
|
18750
18789
|
}
|
|
18751
18790
|
return body2;
|
|
@@ -19118,14 +19157,14 @@ var CentralHub = class {
|
|
|
19118
19157
|
const now = this.now();
|
|
19119
19158
|
const id = `a-${now.toString(36)}-${++this.counter}-${randomBytes3(4).toString("hex")}`;
|
|
19120
19159
|
const timeoutMs = Math.max(1, opts.timeoutMs ?? ACTION_RESULT_TIMEOUT_MS);
|
|
19121
|
-
let
|
|
19160
|
+
let resolve15;
|
|
19122
19161
|
let reject2;
|
|
19123
19162
|
const result = new Promise((ok, fail3) => {
|
|
19124
|
-
|
|
19163
|
+
resolve15 = ok;
|
|
19125
19164
|
reject2 = fail3;
|
|
19126
19165
|
});
|
|
19127
19166
|
result.catch(() => void 0);
|
|
19128
|
-
const p = { id, machine, action: { ...action, id }, status: "queued", deadline: now + timeoutMs, timer: void 0, resolve:
|
|
19167
|
+
const p = { id, machine, action: { ...action, id }, status: "queued", deadline: now + timeoutMs, timer: void 0, resolve: resolve15, reject: reject2 };
|
|
19129
19168
|
this.pending.set(id, p);
|
|
19130
19169
|
this.rearm(p, timeoutMs);
|
|
19131
19170
|
this.hostWait(machine).wake();
|
|
@@ -19374,11 +19413,11 @@ function deliver(o, body2, res, ctx) {
|
|
|
19374
19413
|
}
|
|
19375
19414
|
var FANOUT_TIMEOUT_MS = 3e3;
|
|
19376
19415
|
function readOne(hub2, machine, path, search, timeoutMs, map) {
|
|
19377
|
-
return new Promise((
|
|
19416
|
+
return new Promise((resolve15) => {
|
|
19378
19417
|
const running = bufferedNow.get(machine) ?? 0;
|
|
19379
|
-
if (running >= BUFFERED_MAX) return
|
|
19418
|
+
if (running >= BUFFERED_MAX) return resolve15({ kind: "missing" });
|
|
19380
19419
|
const r = hub2.startRead(machine, path, search);
|
|
19381
|
-
if ("error" in r) return
|
|
19420
|
+
if ("error" in r) return resolve15({ kind: "missing" });
|
|
19382
19421
|
bufferedNow.set(machine, running + 1);
|
|
19383
19422
|
let done = false;
|
|
19384
19423
|
let body2;
|
|
@@ -19391,7 +19430,7 @@ function readOne(hub2, machine, path, search, timeoutMs, map) {
|
|
|
19391
19430
|
else bufferedNow.set(machine, n2);
|
|
19392
19431
|
if (cancel) r.cancel();
|
|
19393
19432
|
body2?.destroy();
|
|
19394
|
-
|
|
19433
|
+
resolve15(out);
|
|
19395
19434
|
};
|
|
19396
19435
|
const timer = setTimeout(() => finish({ kind: "missing" }, true), timeoutMs);
|
|
19397
19436
|
timer.unref();
|
|
@@ -20173,6 +20212,11 @@ function createApiHandler(deps) {
|
|
|
20173
20212
|
if (r) sendJson2(res, 200, r);
|
|
20174
20213
|
else sendJson2(res, 404, { error: tr("Esta sess\xE3o n\xE3o foi aberta pelo herdr.") });
|
|
20175
20214
|
}).catch((err) => fail3(res, err));
|
|
20215
|
+
} else if (path === "/api/spawn/models") {
|
|
20216
|
+
const provider = ["claude", "gentle-shell", "codex"].find((p) => p === url.searchParams.get("provider"));
|
|
20217
|
+
if (!isRead) methodNotAllowed4(res, "GET");
|
|
20218
|
+
else if (!provider) sendJson2(res, 400, { error: tr("provedor desconhecido") });
|
|
20219
|
+
else sendJson2(res, 200, deps.spawnModels?.(provider) ?? { free: false, state: "unavailable", models: [] });
|
|
20176
20220
|
} else if (path === "/api/spawn/folders") {
|
|
20177
20221
|
if (!isRead) methodNotAllowed4(res, "GET");
|
|
20178
20222
|
else (deps.spawnFolders ?? (async () => []))().then((folders) => sendJson2(res, 200, { folders }), (err) => fail3(res, err));
|
|
@@ -23988,14 +24032,14 @@ function handleRead(a, deps) {
|
|
|
23988
24032
|
if (active.size >= READ_OPEN_MAX) return Promise.resolve(refuse(a, 429, tr("leituras abertas demais nesta m\xE1quina")));
|
|
23989
24033
|
const request = deps.request ?? http3.request;
|
|
23990
24034
|
const host = `127.0.0.1:${deps.port}`;
|
|
23991
|
-
return new Promise((
|
|
24035
|
+
return new Promise((resolve15) => {
|
|
23992
24036
|
let out;
|
|
23993
24037
|
let upstream;
|
|
23994
24038
|
let settled = false;
|
|
23995
24039
|
const settle = (r) => {
|
|
23996
24040
|
if (settled) return;
|
|
23997
24041
|
settled = true;
|
|
23998
|
-
|
|
24042
|
+
resolve15(r);
|
|
23999
24043
|
};
|
|
24000
24044
|
const req = request({ host: readHost(deps.host), port: deps.port, method: "GET", path: target.path + target.search, headers: { Host: host, Accept: "*/*" } });
|
|
24001
24045
|
const close = () => {
|
|
@@ -27980,8 +28024,10 @@ var SlotAllocator = class {
|
|
|
27980
28024
|
|
|
27981
28025
|
// shared/room-name.ts
|
|
27982
28026
|
var AGENT_HUB_ROOM_ID = "agent-hub";
|
|
28027
|
+
var GENTLE_SHELL_ROOM_ID = "gentle-shell-delegated";
|
|
27983
28028
|
function roomDisplayName(room) {
|
|
27984
28029
|
if (room.id === AGENT_HUB_ROOM_ID) return tr("Agent Hub");
|
|
28030
|
+
if (room.id === GENTLE_SHELL_ROOM_ID) return tr("Gentle Shell");
|
|
27985
28031
|
if (room.custom && (!room.name.trim() || room.name.trim() === room.id)) return tr("Favoritos");
|
|
27986
28032
|
return room.name;
|
|
27987
28033
|
}
|
|
@@ -28265,6 +28311,7 @@ var Office = class {
|
|
|
28265
28311
|
}
|
|
28266
28312
|
roomName(roomId) {
|
|
28267
28313
|
if (roomId === AGENT_HUB_ROOM_ID) return tr("Agent Hub");
|
|
28314
|
+
if (roomId === GENTLE_SHELL_ROOM_ID) return tr("Gentle Shell");
|
|
28268
28315
|
const custom = this.customRooms.get(roomId);
|
|
28269
28316
|
if (custom) return roomDisplayName({ ...custom, custom: true });
|
|
28270
28317
|
return this.roomNames.get(roomId) ?? roomId.split("/").filter(Boolean).pop() ?? roomId;
|
|
@@ -29183,6 +29230,10 @@ var Office = class {
|
|
|
29183
29230
|
this.roomNames.set(id, tr("Agent Hub"));
|
|
29184
29231
|
continue;
|
|
29185
29232
|
}
|
|
29233
|
+
if (id === GENTLE_SHELL_ROOM_ID) {
|
|
29234
|
+
this.roomNames.set(id, tr("Gentle Shell"));
|
|
29235
|
+
continue;
|
|
29236
|
+
}
|
|
29186
29237
|
const custom = this.customRooms.get(id);
|
|
29187
29238
|
if (custom) {
|
|
29188
29239
|
this.roomNames.set(id, roomDisplayName({ ...custom, custom: true }));
|
|
@@ -30042,7 +30093,7 @@ function createInboxRoutes(service) {
|
|
|
30042
30093
|
if ("error" in r) throw new HttpError(429, tr("a mesa j\xE1 tem {0} itens abertos: resolva alguns antes de deixar outros", [INBOX_OPEN_MAX]));
|
|
30043
30094
|
sendJson2(res, r.created ? 201 : 200, { ok: true, item: r.item, created: r.created, ...r.created ? {} : { reopened: r.reopened } });
|
|
30044
30095
|
};
|
|
30045
|
-
const
|
|
30096
|
+
const resolve15 = async (res, id) => {
|
|
30046
30097
|
const r = await service.resolve(id);
|
|
30047
30098
|
if (!r.ok) throw new HttpError(r.status, r.status === 404 ? tr("item n\xE3o encontrado") : r.error);
|
|
30048
30099
|
sendJson2(res, 200, { ok: true, ...r.item ? { item: r.item } : {} });
|
|
@@ -30062,7 +30113,7 @@ function createInboxRoutes(service) {
|
|
|
30062
30113
|
return sendJson2(res, 404, { error: tr("item n\xE3o encontrado") });
|
|
30063
30114
|
}
|
|
30064
30115
|
req.resume();
|
|
30065
|
-
|
|
30116
|
+
resolve15(res, id).catch((err) => fail3(res, err));
|
|
30066
30117
|
} else if (method === "GET" || method === "HEAD") sendJson2(res, 200, service.frame());
|
|
30067
30118
|
else if (method === "POST") post(req, res).catch((err) => fail3(res, err));
|
|
30068
30119
|
else {
|
|
@@ -33268,7 +33319,7 @@ function detectGentleShellAccounts(dirs, opts = {}) {
|
|
|
33268
33319
|
}
|
|
33269
33320
|
|
|
33270
33321
|
// server/sources/gentle-shell/source.ts
|
|
33271
|
-
import { join as
|
|
33322
|
+
import { join as join26, resolve as resolve13, sep as sep5 } from "node:path";
|
|
33272
33323
|
|
|
33273
33324
|
// server/sources/gentle-shell/terminal.ts
|
|
33274
33325
|
var SEEN_MAX4 = 2e4;
|
|
@@ -33382,387 +33433,10 @@ function createGentleShellTerminalParser() {
|
|
|
33382
33433
|
return new GentleShellTerminalParser();
|
|
33383
33434
|
}
|
|
33384
33435
|
|
|
33385
|
-
// server/sources/gentle-shell/source.ts
|
|
33386
|
-
var PRESENCE_STALE_MS = 3e4;
|
|
33387
|
-
var FALLBACK_RECENT_MS2 = 30 * 6e4;
|
|
33388
|
-
var WORKING_QUIET_MS2 = 30 * 6e4;
|
|
33389
|
-
var TASK_STALE_MS = 30 * 6e4;
|
|
33390
|
-
var CLOSE_AFTER_MISSING_MS3 = 1500;
|
|
33391
|
-
var BACKLOG_MAX2 = 400;
|
|
33392
|
-
var ACTIVE_TASK = /* @__PURE__ */ new Set(["queued", "running", "waiting", "pending", "starting", "in_progress"]);
|
|
33393
|
-
var MAIN_ROLE2 = tr("Agente principal (Gentle Shell)");
|
|
33394
|
-
var SUB_ROLE2 = tr("Subagente (Gentle Shell)");
|
|
33395
|
-
function roleOf2(raw) {
|
|
33396
|
-
const r = raw?.trim();
|
|
33397
|
-
return r ? `${r[0].toUpperCase()}${r.slice(1)}` : SUB_ROLE2;
|
|
33398
|
-
}
|
|
33399
|
-
var GentleShellSource = class {
|
|
33400
|
-
constructor(opts) {
|
|
33401
|
-
this.opts = opts;
|
|
33402
|
-
this.now = opts.now ?? Date.now;
|
|
33403
|
-
this.tailBytes = opts.tailBytes ?? 2 * 1024 * 1024;
|
|
33404
|
-
const others = opts.accounts.entries();
|
|
33405
|
-
this.detected = detectGentleShellAccounts(opts.dirs, {
|
|
33406
|
-
taken: { shorts: [...others, ...opts.accounts.entriesOf("codex")].map((e) => e.detected.short), colors: [...others, ...opts.accounts.entriesOf("codex")].map((e) => e.detected.color) }
|
|
33407
|
-
});
|
|
33408
|
-
this.entries = opts.accounts.setProviderAccounts(
|
|
33409
|
-
"gentle-shell",
|
|
33410
|
-
opts.dirs.map((dir, i) => ({ dir, detected: this.detected[i] }))
|
|
33411
|
-
);
|
|
33412
|
-
this.accs = this.entries.map((e) => ({ id: e.id, dir: e.dir, configDir: e.detected.configDir, index: new SessionIndex(e.dir, this.now), tasks: new TaskStore(e.dir), recent: /* @__PURE__ */ new Map(), recentAt: -Infinity }));
|
|
33413
|
-
}
|
|
33414
|
-
opts;
|
|
33415
|
-
provider = "gentle-shell";
|
|
33416
|
-
accs = [];
|
|
33417
|
-
entries = [];
|
|
33418
|
-
detected = [];
|
|
33419
|
-
trackers = /* @__PURE__ */ new Map();
|
|
33420
|
-
timer = null;
|
|
33421
|
-
now;
|
|
33422
|
-
tailBytes;
|
|
33423
|
-
/** Contas do Gentle Shell (ids finais, no AccountsService). */
|
|
33424
|
-
accountEntries() {
|
|
33425
|
-
return this.entries;
|
|
33426
|
-
}
|
|
33427
|
-
start() {
|
|
33428
|
-
this.boot();
|
|
33429
|
-
this.timer = setInterval(() => this.safePoll(), this.opts.pollMs ?? 1e3);
|
|
33430
|
-
this.timer.unref?.();
|
|
33431
|
-
}
|
|
33432
|
-
/** Reconstrói as sessões abertas sem gerar avisos. Síncrono e curto. */
|
|
33433
|
-
boot() {
|
|
33434
|
-
this.opts.office.beginBoot();
|
|
33435
|
-
try {
|
|
33436
|
-
this.poll(true);
|
|
33437
|
-
} finally {
|
|
33438
|
-
this.opts.office.endBoot();
|
|
33439
|
-
}
|
|
33440
|
-
}
|
|
33441
|
-
stop() {
|
|
33442
|
-
if (this.timer) clearInterval(this.timer);
|
|
33443
|
-
this.timer = null;
|
|
33444
|
-
}
|
|
33445
|
-
sources() {
|
|
33446
|
-
return this.accs.map((acc) => {
|
|
33447
|
-
let sessions = 0;
|
|
33448
|
-
for (const t of this.trackers.values()) if (t.acc === acc && t.kind === "main" && t.inOffice) sessions++;
|
|
33449
|
-
const info = { label: acc.id, provider: "gentle-shell", path: acc.configDir, sessions, ok: !acc.error };
|
|
33450
|
-
if (acc.error) info.error = acc.error;
|
|
33451
|
-
return info;
|
|
33452
|
-
});
|
|
33453
|
-
}
|
|
33454
|
-
transcriptPathOf(agentId) {
|
|
33455
|
-
const t = this.trackers.get(agentId);
|
|
33456
|
-
return t?.inOffice ? t.path : void 0;
|
|
33457
|
-
}
|
|
33458
|
-
terminalParser(agentId) {
|
|
33459
|
-
return this.trackers.has(agentId) ? createGentleShellTerminalParser() : void 0;
|
|
33460
|
-
}
|
|
33461
|
-
watchedTranscripts() {
|
|
33462
|
-
return this.trackers.size;
|
|
33463
|
-
}
|
|
33464
|
-
// ---------------------------------------------------------------- polling
|
|
33465
|
-
safePoll() {
|
|
33466
|
-
try {
|
|
33467
|
-
this.poll(false);
|
|
33468
|
-
} catch (err) {
|
|
33469
|
-
log.warnOnce(`gentle-shell-poll:${errMsg(err)}`, tr("Gentle Shell: falha no ciclo de leitura: {0}", [errMsg(err)]));
|
|
33470
|
-
}
|
|
33471
|
-
}
|
|
33472
|
-
poll(boot = false) {
|
|
33473
|
-
const now = this.now();
|
|
33474
|
-
const seen = /* @__PURE__ */ new Set();
|
|
33475
|
-
for (const acc of this.accs) {
|
|
33476
|
-
for (const [sessionId, workspace] of this.presentSessions(acc, now)) {
|
|
33477
|
-
const key = `${acc.id}:${sessionId}`;
|
|
33478
|
-
let t = this.trackers.get(key);
|
|
33479
|
-
if (!t) {
|
|
33480
|
-
t = this.newTracker(acc, key, "main", sessionId);
|
|
33481
|
-
this.trackers.set(key, t);
|
|
33482
|
-
}
|
|
33483
|
-
if (workspace) t.workspace = workspace;
|
|
33484
|
-
try {
|
|
33485
|
-
this.syncMain(t, now);
|
|
33486
|
-
} catch (err) {
|
|
33487
|
-
log.warnOnce(`gentle-shell-session:${key}:${errMsg(err)}`, tr("Gentle Shell: sess\xE3o {0}: {1}", [key, errMsg(err)]));
|
|
33488
|
-
}
|
|
33489
|
-
seen.add(key);
|
|
33490
|
-
}
|
|
33491
|
-
}
|
|
33492
|
-
for (const [key, t] of [...this.trackers]) {
|
|
33493
|
-
if (t.kind !== "main" || seen.has(key)) continue;
|
|
33494
|
-
t.missingSince ??= now;
|
|
33495
|
-
if (!boot && now - t.missingSince < CLOSE_AFTER_MISSING_MS3) continue;
|
|
33496
|
-
this.leaveMain(t);
|
|
33497
|
-
this.trackers.delete(key);
|
|
33498
|
-
}
|
|
33499
|
-
for (const acc of this.accs) {
|
|
33500
|
-
try {
|
|
33501
|
-
this.syncSubs(acc, now);
|
|
33502
|
-
} catch (err) {
|
|
33503
|
-
log.warnOnce(`gentle-shell-tasks:${acc.id}:${errMsg(err)}`, tr("Gentle Shell: falha ao ler os subagentes: {0}", [errMsg(err)]));
|
|
33504
|
-
}
|
|
33505
|
-
}
|
|
33506
|
-
}
|
|
33507
|
-
/** Sessões abertas de uma conta (id → projeto da presença, quando houver). */
|
|
33508
|
-
presentSessions(acc, now) {
|
|
33509
|
-
const out = /* @__PURE__ */ new Map();
|
|
33510
|
-
acc.index.refresh();
|
|
33511
|
-
const presence = readPresence(acc.dir);
|
|
33512
|
-
if (presence) {
|
|
33513
|
-
const fresh = presence.filter((p) => now - p.heartbeat <= PRESENCE_STALE_MS);
|
|
33514
|
-
const known = new Set(fresh.flatMap((p) => p.sessionId ? [p.sessionId] : []));
|
|
33515
|
-
for (const p of fresh) {
|
|
33516
|
-
const id = this.sessionOf(acc, p, known);
|
|
33517
|
-
if (id) {
|
|
33518
|
-
out.set(id, p.workspace);
|
|
33519
|
-
known.add(id);
|
|
33520
|
-
}
|
|
33521
|
-
}
|
|
33522
|
-
return out;
|
|
33523
|
-
}
|
|
33524
|
-
if (now - acc.recentAt >= 1e4) {
|
|
33525
|
-
acc.recentAt = now;
|
|
33526
|
-
acc.recent = new Map(acc.index.all().map((f) => [f.sessionId, f.mtimeMs]));
|
|
33527
|
-
}
|
|
33528
|
-
for (const [sessionId, mtime] of acc.recent) {
|
|
33529
|
-
const t = this.trackers.get(`${acc.id}:${sessionId}`);
|
|
33530
|
-
if (now - Math.max(mtime, t?.lastWriteAt ?? 0) <= FALLBACK_RECENT_MS2) out.set(sessionId, void 0);
|
|
33531
|
-
}
|
|
33532
|
-
return out;
|
|
33533
|
-
}
|
|
33534
|
-
/** Sessão de uma encarnação: a do discovery ou, sem ela, o transcript mais recente do projeto ainda sem dono. */
|
|
33535
|
-
sessionOf(acc, p, taken) {
|
|
33536
|
-
if (p.sessionId) return p.sessionId;
|
|
33537
|
-
if (!p.workspace) return void 0;
|
|
33538
|
-
return acc.index.latestFor(p.workspace, taken)?.sessionId;
|
|
33539
|
-
}
|
|
33540
|
-
newTracker(acc, key, kind, rawId) {
|
|
33541
|
-
return { key, acc, kind, rawId, state: createPiState(), backlog: [], inOffice: false, status: kind === "sub" ? "working" : "idle", statusAt: 0 };
|
|
33542
|
-
}
|
|
33543
|
-
// ---------------------------------------------------------------- principais
|
|
33544
|
-
syncMain(t, now) {
|
|
33545
|
-
delete t.missingSince;
|
|
33546
|
-
if (t.inOffice && !this.opts.office.has(t.key)) t.inOffice = false;
|
|
33547
|
-
if (!t.tail) {
|
|
33548
|
-
const file = t.acc.index.find(t.rawId);
|
|
33549
|
-
if (!file) return;
|
|
33550
|
-
this.load(t, file.path);
|
|
33551
|
-
} else {
|
|
33552
|
-
this.pump(t);
|
|
33553
|
-
}
|
|
33554
|
-
const cwd = t.state.cwd ?? t.workspace;
|
|
33555
|
-
if (cwd && !t.inOffice && t.tail) this.enter(t, cwd, now);
|
|
33556
|
-
if (t.inOffice) {
|
|
33557
|
-
this.quietCheck(t, now);
|
|
33558
|
-
this.opts.office.fillWorkingActivity(t.key);
|
|
33559
|
-
}
|
|
33560
|
-
}
|
|
33561
|
-
enter(t, cwd, now) {
|
|
33562
|
-
const office2 = this.opts.office;
|
|
33563
|
-
office2.addMain({
|
|
33564
|
-
id: t.key,
|
|
33565
|
-
provider: "gentle-shell",
|
|
33566
|
-
account: t.acc.id,
|
|
33567
|
-
sessionId: t.rawId,
|
|
33568
|
-
cwd,
|
|
33569
|
-
role: MAIN_ROLE2,
|
|
33570
|
-
startedAt: t.state.startedAt ?? t.state.firstAt ?? now,
|
|
33571
|
-
status: t.status,
|
|
33572
|
-
waitingFor: t.waitingFor
|
|
33573
|
-
});
|
|
33574
|
-
t.inOffice = office2.has(t.key);
|
|
33575
|
-
if (!t.inOffice) return;
|
|
33576
|
-
office2.setStatus(t.key, t.status, t.waitingFor);
|
|
33577
|
-
this.flushBacklog(t);
|
|
33578
|
-
this.applySummary(t);
|
|
33579
|
-
}
|
|
33580
|
-
leaveMain(t) {
|
|
33581
|
-
if (!t.inOffice) return;
|
|
33582
|
-
this.opts.office.closeMain(t.key);
|
|
33583
|
-
t.inOffice = false;
|
|
33584
|
-
}
|
|
33585
|
-
// ---------------------------------------------------------------- subagentes
|
|
33586
|
-
syncSubs(acc, now) {
|
|
33587
|
-
const tasks = acc.tasks.read();
|
|
33588
|
-
const active2 = /* @__PURE__ */ new Map();
|
|
33589
|
-
for (const task of tasks) {
|
|
33590
|
-
if (!ACTIVE_TASK.has(task.status)) continue;
|
|
33591
|
-
if (now - (task.lastAt ?? task.startedAt ?? 0) > TASK_STALE_MS) continue;
|
|
33592
|
-
active2.set(`${acc.id}:${task.id}`, task);
|
|
33593
|
-
}
|
|
33594
|
-
for (const [key, task] of active2) {
|
|
33595
|
-
const parent = this.trackers.get(`${acc.id}:${task.parentSessionId}`);
|
|
33596
|
-
if (!parent?.inOffice || this.opts.office.isSubDone(parent.key)) continue;
|
|
33597
|
-
let t = this.trackers.get(key);
|
|
33598
|
-
if (!t) {
|
|
33599
|
-
t = this.newTracker(acc, key, "sub", task.id);
|
|
33600
|
-
this.trackers.set(key, t);
|
|
33601
|
-
}
|
|
33602
|
-
t.task = task;
|
|
33603
|
-
this.syncSub(t, parent, now);
|
|
33604
|
-
}
|
|
33605
|
-
for (const [key, t] of [...this.trackers]) {
|
|
33606
|
-
if (t.kind !== "sub" || t.acc !== acc) continue;
|
|
33607
|
-
const parent = this.trackers.get(`${acc.id}:${t.task?.parentSessionId}`);
|
|
33608
|
-
if (active2.has(key) && parent?.inOffice) continue;
|
|
33609
|
-
if (t.inOffice) this.opts.office.completeSub(t.key);
|
|
33610
|
-
this.trackers.delete(key);
|
|
33611
|
-
}
|
|
33612
|
-
}
|
|
33613
|
-
syncSub(t, parent, now) {
|
|
33614
|
-
const task = t.task;
|
|
33615
|
-
const path = this.subPath(t.acc, task);
|
|
33616
|
-
if (path && path !== t.path) this.load(t, path);
|
|
33617
|
-
else if (t.tail) this.pump(t);
|
|
33618
|
-
if (!t.inOffice) {
|
|
33619
|
-
const added = this.opts.office.addSub({
|
|
33620
|
-
id: t.key,
|
|
33621
|
-
parentId: parent.key,
|
|
33622
|
-
sessionId: task.id,
|
|
33623
|
-
role: roleOf2(task.agent),
|
|
33624
|
-
title: task.label,
|
|
33625
|
-
background: task.mode === "background",
|
|
33626
|
-
startedAt: task.startedAt ?? t.state.firstAt ?? now
|
|
33627
|
-
});
|
|
33628
|
-
if (!added) return;
|
|
33629
|
-
t.inOffice = true;
|
|
33630
|
-
this.flushBacklog(t);
|
|
33631
|
-
}
|
|
33632
|
-
if (this.opts.office.isSubDone(t.key)) this.opts.office.reactivateSub(t.key);
|
|
33633
|
-
this.applySummary(t);
|
|
33634
|
-
}
|
|
33635
|
-
/** Transcript do subagente (só dentro das pastas de sessões do Gentle Shell). */
|
|
33636
|
-
subPath(acc, task) {
|
|
33637
|
-
if (!task.sessionPath) return void 0;
|
|
33638
|
-
const p = resolve11(task.sessionPath);
|
|
33639
|
-
const roots = [join24(resolve11(acc.dir), SUB_SESSIONS_DIR), join24(resolve11(acc.dir), SESSIONS_DIR2)];
|
|
33640
|
-
return p.endsWith(".jsonl") && roots.some((r) => p.startsWith(r + sep5)) ? p : void 0;
|
|
33641
|
-
}
|
|
33642
|
-
// ---------------------------------------------------------------- transcript
|
|
33643
|
-
/** Lê o começo (cwd, título, modelo) e a janela do fim do transcript. */
|
|
33644
|
-
load(t, path) {
|
|
33645
|
-
const head = parsePiHead(readHeadLines(path));
|
|
33646
|
-
const tail = new FileTail(path);
|
|
33647
|
-
tail.seekTail(this.tailBytes);
|
|
33648
|
-
t.tail = tail;
|
|
33649
|
-
t.path = path;
|
|
33650
|
-
t.state = createPiState();
|
|
33651
|
-
t.state.sessionId = head.sessionId;
|
|
33652
|
-
t.state.cwd = head.cwd;
|
|
33653
|
-
t.state.startedAt = head.startedAt;
|
|
33654
|
-
t.state.model = head.model;
|
|
33655
|
-
t.state.title = head.title;
|
|
33656
|
-
t.backlog = [];
|
|
33657
|
-
for (let i = 0; i < 64; i++) {
|
|
33658
|
-
const r = tail.read();
|
|
33659
|
-
for (const line2 of r.lines) this.apply(t, parsePiLine(t.state, line2, { idPrefix: t.key, now: this.now() }), false);
|
|
33660
|
-
if (!r.more) break;
|
|
33661
|
-
}
|
|
33662
|
-
t.lastWriteAt = tail.mtimeMs;
|
|
33663
|
-
if (t.inOffice) {
|
|
33664
|
-
this.flushBacklog(t);
|
|
33665
|
-
this.statusToOffice(t);
|
|
33666
|
-
}
|
|
33667
|
-
}
|
|
33668
|
-
pump(t) {
|
|
33669
|
-
const tail = t.tail;
|
|
33670
|
-
if (!tail) return;
|
|
33671
|
-
for (let i = 0; i < 4; i++) {
|
|
33672
|
-
let r;
|
|
33673
|
-
try {
|
|
33674
|
-
r = tail.read();
|
|
33675
|
-
} catch (err) {
|
|
33676
|
-
log.warnOnce(`gentle-shell-read:${t.key}`, tr("Gentle Shell: transcript de {0} ileg\xEDvel ({1}).", [t.key, errMsg(err)]));
|
|
33677
|
-
return;
|
|
33678
|
-
}
|
|
33679
|
-
if (r.missing) {
|
|
33680
|
-
delete t.tail;
|
|
33681
|
-
delete t.path;
|
|
33682
|
-
return;
|
|
33683
|
-
}
|
|
33684
|
-
t.lastWriteAt = tail.mtimeMs;
|
|
33685
|
-
if (r.reset) {
|
|
33686
|
-
this.load(t, tail.path);
|
|
33687
|
-
return;
|
|
33688
|
-
}
|
|
33689
|
-
for (const line2 of r.lines) this.apply(t, parsePiLine(t.state, line2, { idPrefix: t.key, now: this.now() }), true);
|
|
33690
|
-
if (r.lines.length) this.applySummary(t);
|
|
33691
|
-
if (!r.more) break;
|
|
33692
|
-
}
|
|
33693
|
-
}
|
|
33694
|
-
/** Aplica um resultado de linha: ao vivo vai direto ao escritório; na carga inicial, fica no backlog. */
|
|
33695
|
-
apply(t, r, live) {
|
|
33696
|
-
if (t.kind === "main") {
|
|
33697
|
-
for (const sig of r.signals) {
|
|
33698
|
-
switch (sig.type) {
|
|
33699
|
-
case "turnStart":
|
|
33700
|
-
this.decide(t, "working", r.at, void 0, live);
|
|
33701
|
-
break;
|
|
33702
|
-
case "turnEnd":
|
|
33703
|
-
this.decide(t, "idle", r.at, void 0, live);
|
|
33704
|
-
break;
|
|
33705
|
-
case "waiting":
|
|
33706
|
-
this.decide(t, "waiting", r.at, sig.reason, live);
|
|
33707
|
-
break;
|
|
33708
|
-
case "progress":
|
|
33709
|
-
if (t.status === "waiting") this.decide(t, "working", r.at, void 0, live);
|
|
33710
|
-
break;
|
|
33711
|
-
}
|
|
33712
|
-
}
|
|
33713
|
-
}
|
|
33714
|
-
if (!live || !t.inOffice) {
|
|
33715
|
-
if (r.activities.length) {
|
|
33716
|
-
t.backlog.push(r);
|
|
33717
|
-
if (t.backlog.length > BACKLOG_MAX2) t.backlog.splice(0, t.backlog.length - BACKLOG_MAX2);
|
|
33718
|
-
}
|
|
33719
|
-
return;
|
|
33720
|
-
}
|
|
33721
|
-
this.toOffice(t, r, true);
|
|
33722
|
-
}
|
|
33723
|
-
toOffice(t, r, live) {
|
|
33724
|
-
for (const a of r.activities) this.opts.office.addActivity(t.key, a.activity, a.current, { feed: live });
|
|
33725
|
-
}
|
|
33726
|
-
flushBacklog(t) {
|
|
33727
|
-
const backlog = t.backlog;
|
|
33728
|
-
t.backlog = [];
|
|
33729
|
-
for (const r of backlog) this.toOffice(t, r, false);
|
|
33730
|
-
}
|
|
33731
|
-
/** Muda o status por uma borda do transcript: informação mais velha que a última decisão não vale. */
|
|
33732
|
-
decide(t, status2, at, waitingFor, live) {
|
|
33733
|
-
if (at < t.statusAt) return;
|
|
33734
|
-
t.statusAt = at;
|
|
33735
|
-
t.status = status2;
|
|
33736
|
-
if (waitingFor) t.waitingFor = waitingFor;
|
|
33737
|
-
else delete t.waitingFor;
|
|
33738
|
-
if (live) this.statusToOffice(t);
|
|
33739
|
-
}
|
|
33740
|
-
statusToOffice(t) {
|
|
33741
|
-
if (t.inOffice && t.kind === "main") this.opts.office.setStatus(t.key, t.status, t.waitingFor);
|
|
33742
|
-
}
|
|
33743
|
-
/** 'working' sem nenhuma escrita por muito tempo (turno morto num crash): vira 'idle'. */
|
|
33744
|
-
quietCheck(t, now) {
|
|
33745
|
-
if (t.status !== "working") return;
|
|
33746
|
-
if (now - Math.max(t.lastWriteAt ?? 0, t.statusAt) > WORKING_QUIET_MS2) this.decide(t, "idle", now, void 0, true);
|
|
33747
|
-
}
|
|
33748
|
-
applySummary(t) {
|
|
33749
|
-
if (!t.inOffice) return;
|
|
33750
|
-
const s2 = t.state;
|
|
33751
|
-
const summary = { tasks: s2.tasks, stats: { ...s2.stats } };
|
|
33752
|
-
const title = t.kind === "sub" ? t.task?.label ?? s2.title : s2.title;
|
|
33753
|
-
if (title) summary.title = title;
|
|
33754
|
-
const model = s2.model ?? t.task?.model;
|
|
33755
|
-
if (model) summary.model = model;
|
|
33756
|
-
if (s2.firstAt !== void 0) summary.firstAt = s2.firstAt;
|
|
33757
|
-
if (s2.lastAt !== void 0) summary.lastAt = s2.lastAt;
|
|
33758
|
-
this.opts.office.applyTranscript(t.key, summary);
|
|
33759
|
-
}
|
|
33760
|
-
};
|
|
33761
|
-
|
|
33762
33436
|
// server/sources/agent-hub/source.ts
|
|
33763
33437
|
import { closeSync as closeSync6, lstatSync as lstatSync2, openSync as openSync6, readFileSync as readFileSync21, readSync as readSync6, readdirSync as readdirSync15 } from "node:fs";
|
|
33764
33438
|
import { lstat, readdir as readdir3 } from "node:fs/promises";
|
|
33765
|
-
import { basename as basename9, dirname as dirname13, isAbsolute as isAbsolute5, join as
|
|
33439
|
+
import { basename as basename9, dirname as dirname13, isAbsolute as isAbsolute5, join as join25, resolve as resolve11 } from "node:path";
|
|
33766
33440
|
|
|
33767
33441
|
// server/sources/agent-hub/events/agy.ts
|
|
33768
33442
|
function object(value) {
|
|
@@ -33925,7 +33599,7 @@ function adaptAgentHubEvent(agent, text3, offset) {
|
|
|
33925
33599
|
|
|
33926
33600
|
// server/sources/agent-hub/terminal.ts
|
|
33927
33601
|
import { lstatSync, readFileSync as readFileSync20 } from "node:fs";
|
|
33928
|
-
import { join as
|
|
33602
|
+
import { join as join24 } from "node:path";
|
|
33929
33603
|
var SEEN_MAX5 = 2e4;
|
|
33930
33604
|
var MAX_PROMPT_BYTES = 128 * 1024;
|
|
33931
33605
|
var MAX_RESPONSE_BYTES = 128 * 1024;
|
|
@@ -33943,7 +33617,7 @@ function toMs7(v) {
|
|
|
33943
33617
|
}
|
|
33944
33618
|
function readPrompt(jobDir) {
|
|
33945
33619
|
if (!jobDir) return void 0;
|
|
33946
|
-
const path =
|
|
33620
|
+
const path = join24(jobDir, "prompt.txt");
|
|
33947
33621
|
try {
|
|
33948
33622
|
const st = lstatSync(path);
|
|
33949
33623
|
if (!st.isFile() || st.size > MAX_PROMPT_BYTES) return void 0;
|
|
@@ -33954,7 +33628,7 @@ function readPrompt(jobDir) {
|
|
|
33954
33628
|
}
|
|
33955
33629
|
function readResponse(jobDir) {
|
|
33956
33630
|
if (!jobDir) return void 0;
|
|
33957
|
-
const path =
|
|
33631
|
+
const path = join24(jobDir, "response.txt");
|
|
33958
33632
|
try {
|
|
33959
33633
|
const st = lstatSync(path);
|
|
33960
33634
|
if (!st.isFile() || st.size > MAX_RESPONSE_BYTES) return void 0;
|
|
@@ -34267,7 +33941,7 @@ function status(value) {
|
|
|
34267
33941
|
return value === "queued" || value === "running" || value === "succeeded" || value === "failed" || value === "cancelled" ? value : "unknown";
|
|
34268
33942
|
}
|
|
34269
33943
|
function readPrompt2(jobDir) {
|
|
34270
|
-
const path =
|
|
33944
|
+
const path = join25(jobDir, "prompt.txt");
|
|
34271
33945
|
try {
|
|
34272
33946
|
const st = lstatSync2(path);
|
|
34273
33947
|
if (!st.isFile() || st.size > MAX_PROMPT_BYTES2) return void 0;
|
|
@@ -34332,7 +34006,7 @@ function jobFiles(runsDir, now) {
|
|
|
34332
34006
|
const files = [];
|
|
34333
34007
|
for (const entry of entries) {
|
|
34334
34008
|
if (!entry.isDirectory()) continue;
|
|
34335
|
-
const path =
|
|
34009
|
+
const path = join25(runsDir, entry.name, "result.json");
|
|
34336
34010
|
try {
|
|
34337
34011
|
const file = jobFileOf(entry.name, path, lstatSync2(path), now);
|
|
34338
34012
|
if (file) files.push(file);
|
|
@@ -34355,7 +34029,7 @@ async function jobFilesAsync(runsDir, now) {
|
|
|
34355
34029
|
const files = [];
|
|
34356
34030
|
for (let i = 0; i < dirs.length; i += JOB_STAT_BATCH) {
|
|
34357
34031
|
const batch = await Promise.all(dirs.slice(i, i + JOB_STAT_BATCH).map(async (entry) => {
|
|
34358
|
-
const path =
|
|
34032
|
+
const path = join25(runsDir, entry.name, "result.json");
|
|
34359
34033
|
try {
|
|
34360
34034
|
return jobFileOf(entry.name, path, await lstat(path), now);
|
|
34361
34035
|
} catch {
|
|
@@ -34389,7 +34063,7 @@ function officeStatus(job) {
|
|
|
34389
34063
|
}
|
|
34390
34064
|
function deriveProject(cwd, repoRoot, repoName) {
|
|
34391
34065
|
const candidate = repoRoot || cwd;
|
|
34392
|
-
const gitPath =
|
|
34066
|
+
const gitPath = join25(candidate, ".git");
|
|
34393
34067
|
try {
|
|
34394
34068
|
const st = lstatSync2(gitPath);
|
|
34395
34069
|
if (st.isFile()) {
|
|
@@ -34398,11 +34072,11 @@ function deriveProject(cwd, repoRoot, repoName) {
|
|
|
34398
34072
|
if (match) {
|
|
34399
34073
|
let gitDir = match[1].trim();
|
|
34400
34074
|
if (!isAbsolute5(gitDir)) {
|
|
34401
|
-
gitDir =
|
|
34075
|
+
gitDir = resolve11(candidate, gitDir);
|
|
34402
34076
|
}
|
|
34403
34077
|
try {
|
|
34404
|
-
const commonRel = readFileSync21(
|
|
34405
|
-
const commonDir =
|
|
34078
|
+
const commonRel = readFileSync21(join25(gitDir, "commondir"), "utf8").trim();
|
|
34079
|
+
const commonDir = resolve11(gitDir, commonRel);
|
|
34406
34080
|
return basename9(dirname13(commonDir));
|
|
34407
34081
|
} catch {
|
|
34408
34082
|
const wtMatch = /^(.*)[/\\]\.git[/\\]worktrees[/\\][^/\\]+$/.exec(gitDir);
|
|
@@ -34470,7 +34144,7 @@ var AgentHubSource = class {
|
|
|
34470
34144
|
const tracker = this.trackers.get(agentId);
|
|
34471
34145
|
const jobId = tracker ? tracker.job.id : agentId.startsWith("agent-hub:") ? agentId.slice("agent-hub:".length) : void 0;
|
|
34472
34146
|
if (!jobId) return void 0;
|
|
34473
|
-
const path =
|
|
34147
|
+
const path = join25(this.opts.runsDir, jobId, "stdout.log");
|
|
34474
34148
|
try {
|
|
34475
34149
|
if (lstatSync2(path).isFile()) return path;
|
|
34476
34150
|
} catch {
|
|
@@ -34485,7 +34159,7 @@ var AgentHubSource = class {
|
|
|
34485
34159
|
const tracker = this.trackers.get(agentId);
|
|
34486
34160
|
const jobId = tracker ? tracker.job.id : agentId.startsWith("agent-hub:") ? agentId.slice("agent-hub:".length) : void 0;
|
|
34487
34161
|
if (!jobId) return void 0;
|
|
34488
|
-
const jobDir =
|
|
34162
|
+
const jobDir = join25(this.opts.runsDir, jobId);
|
|
34489
34163
|
return createAgentHubTerminalParser({
|
|
34490
34164
|
agent: tracker?.job.agent,
|
|
34491
34165
|
jobDir,
|
|
@@ -34510,8 +34184,8 @@ var AgentHubSource = class {
|
|
|
34510
34184
|
const list = this.opts.listFilesAsync ?? jobFilesAsync;
|
|
34511
34185
|
const files = await Promise.race([
|
|
34512
34186
|
list(this.opts.runsDir, this.now()),
|
|
34513
|
-
new Promise((
|
|
34514
|
-
timer = setTimeout(() =>
|
|
34187
|
+
new Promise((resolve15) => {
|
|
34188
|
+
timer = setTimeout(() => resolve15(void 0), limit);
|
|
34515
34189
|
timer.unref?.();
|
|
34516
34190
|
})
|
|
34517
34191
|
]);
|
|
@@ -34534,7 +34208,7 @@ var AgentHubSource = class {
|
|
|
34534
34208
|
if (!cached || cached.mtimeMs !== file.mtimeMs || cached.size !== file.size) {
|
|
34535
34209
|
let job2;
|
|
34536
34210
|
try {
|
|
34537
|
-
job2 = parseJob(readFileSync21(file.path, "utf8"), file.name, file.mtimeMs,
|
|
34211
|
+
job2 = parseJob(readFileSync21(file.path, "utf8"), file.name, file.mtimeMs, join25(this.opts.runsDir, file.name));
|
|
34538
34212
|
} catch {
|
|
34539
34213
|
job2 = void 0;
|
|
34540
34214
|
}
|
|
@@ -34654,7 +34328,7 @@ var AgentHubSource = class {
|
|
|
34654
34328
|
stats: { toolCalls: 0, tokensIn: 0, tokensOut: 0, subagents: 0 },
|
|
34655
34329
|
model: job.model
|
|
34656
34330
|
});
|
|
34657
|
-
const jobDir =
|
|
34331
|
+
const jobDir = join25(this.opts.runsDir, job.id);
|
|
34658
34332
|
if (job.status === "running" && !tracker.started) {
|
|
34659
34333
|
this.opts.office.addActivity(id, {
|
|
34660
34334
|
id: `${id}#started`,
|
|
@@ -34666,9 +34340,9 @@ var AgentHubSource = class {
|
|
|
34666
34340
|
}, true, { feed: !boot });
|
|
34667
34341
|
tracker.started = true;
|
|
34668
34342
|
}
|
|
34669
|
-
this.readOutput(tracker, id,
|
|
34343
|
+
this.readOutput(tracker, id, join25(jobDir, "stdout.log"), job.agent);
|
|
34670
34344
|
if (terminal) {
|
|
34671
|
-
this.readResponse(tracker, id,
|
|
34345
|
+
this.readResponse(tracker, id, join25(jobDir, "response.txt"), job.updatedAt ?? this.now());
|
|
34672
34346
|
const error = tracker.failure ?? job.error;
|
|
34673
34347
|
this.opts.office.finishMain(id, mappedStatus, error ? truncate(maskSecrets(error), 300) : void 0);
|
|
34674
34348
|
}
|
|
@@ -34777,6 +34451,529 @@ var AgentHubSource = class {
|
|
|
34777
34451
|
}
|
|
34778
34452
|
};
|
|
34779
34453
|
|
|
34454
|
+
// server/sources/gentle-shell/delegation.ts
|
|
34455
|
+
import { execFileSync } from "node:child_process";
|
|
34456
|
+
import { readdirSync as readdirSync16, readlinkSync } from "node:fs";
|
|
34457
|
+
import { basename as basename10, resolve as resolve12 } from "node:path";
|
|
34458
|
+
var START_BEFORE_MS2 = 1e4;
|
|
34459
|
+
var START_AFTER_MS2 = 6e4;
|
|
34460
|
+
var MAX_DEPTH = 32;
|
|
34461
|
+
var PID_ID2 = /:(\d+)$/;
|
|
34462
|
+
var AGENT_BIN = /^(claude|codex)(\.exe)?$/i;
|
|
34463
|
+
function knownAgentPids(agents2) {
|
|
34464
|
+
const out = /* @__PURE__ */ new Set();
|
|
34465
|
+
for (const a of agents2) {
|
|
34466
|
+
if (a.parentId || a.id.startsWith("@")) continue;
|
|
34467
|
+
const m = PID_ID2.exec(a.id);
|
|
34468
|
+
if (m) out.add(Number(m[1]));
|
|
34469
|
+
}
|
|
34470
|
+
return out;
|
|
34471
|
+
}
|
|
34472
|
+
function isGentleShell(args) {
|
|
34473
|
+
return args.slice(0, 2).some((a) => /^(gentle-shell|pi)(\.m?js)?$/.test(basename10(a)) || /[/\\]pi-coding-agent[/\\]/.test(a));
|
|
34474
|
+
}
|
|
34475
|
+
function printMode(args) {
|
|
34476
|
+
return args.some((a) => a === "-p" || a === "--print");
|
|
34477
|
+
}
|
|
34478
|
+
function classifyDelegation(cwd, startedAt2, known, table) {
|
|
34479
|
+
try {
|
|
34480
|
+
const want = resolve12(cwd);
|
|
34481
|
+
const cands = [];
|
|
34482
|
+
for (const pid of table.pids()) {
|
|
34483
|
+
const args = table.args(pid);
|
|
34484
|
+
if (!args || !isGentleShell(args)) continue;
|
|
34485
|
+
const pcwd = table.cwd(pid);
|
|
34486
|
+
if (pcwd && resolve12(pcwd) === want) cands.push(pid);
|
|
34487
|
+
}
|
|
34488
|
+
let use = cands;
|
|
34489
|
+
if (startedAt2 !== void 0) {
|
|
34490
|
+
const near = cands.filter((p) => {
|
|
34491
|
+
const s2 = table.startMs(p);
|
|
34492
|
+
return s2 !== void 0 && s2 >= startedAt2 - START_AFTER_MS2 && s2 <= startedAt2 + START_BEFORE_MS2;
|
|
34493
|
+
});
|
|
34494
|
+
if (near.length) use = near;
|
|
34495
|
+
}
|
|
34496
|
+
if (!use.length) return { delegated: false };
|
|
34497
|
+
const set = new Set(use);
|
|
34498
|
+
const ancestors = (pid) => {
|
|
34499
|
+
const out = [];
|
|
34500
|
+
let p = table.ppid(pid);
|
|
34501
|
+
for (let i = 0; p !== void 0 && p > 1 && i < MAX_DEPTH; i++) {
|
|
34502
|
+
out.push(p);
|
|
34503
|
+
p = table.ppid(p);
|
|
34504
|
+
}
|
|
34505
|
+
return out;
|
|
34506
|
+
};
|
|
34507
|
+
const agentAbove = (pid) => ancestors(pid).some((a) => known.has(a) || AGENT_BIN.test(basename10(table.args(a)?.[0] ?? "")));
|
|
34508
|
+
const roots = /* @__PURE__ */ new Map();
|
|
34509
|
+
for (const pid of use) {
|
|
34510
|
+
let root = pid;
|
|
34511
|
+
for (const a of ancestors(pid)) if (set.has(a)) root = a;
|
|
34512
|
+
const d = printMode(table.args(pid) ?? []) || agentAbove(pid);
|
|
34513
|
+
roots.set(root, (roots.get(root) ?? false) || d);
|
|
34514
|
+
}
|
|
34515
|
+
return { delegated: [...roots.values()].every(Boolean), pid: use[0] };
|
|
34516
|
+
} catch {
|
|
34517
|
+
return { delegated: false };
|
|
34518
|
+
}
|
|
34519
|
+
}
|
|
34520
|
+
var num11 = (s2) => /^\d+$/.test(s2) ? Number(s2) : void 0;
|
|
34521
|
+
function linuxProcTable(proc = realProc) {
|
|
34522
|
+
return {
|
|
34523
|
+
pids: () => {
|
|
34524
|
+
try {
|
|
34525
|
+
return readdirSync16("/proc").flatMap((n2) => num11(n2) !== void 0 ? [Number(n2)] : []);
|
|
34526
|
+
} catch {
|
|
34527
|
+
return [];
|
|
34528
|
+
}
|
|
34529
|
+
},
|
|
34530
|
+
args: (pid) => proc.cmdline(pid)?.split("\0").filter(Boolean),
|
|
34531
|
+
cwd: (pid) => {
|
|
34532
|
+
try {
|
|
34533
|
+
return readlinkSync(`/proc/${pid}/cwd`);
|
|
34534
|
+
} catch {
|
|
34535
|
+
return void 0;
|
|
34536
|
+
}
|
|
34537
|
+
},
|
|
34538
|
+
ppid: (pid) => {
|
|
34539
|
+
const stat3 = proc.stat(pid);
|
|
34540
|
+
if (!stat3) return void 0;
|
|
34541
|
+
return num11(stat3.slice(stat3.lastIndexOf(")") + 1).trim().split(/\s+/)[1] ?? "");
|
|
34542
|
+
},
|
|
34543
|
+
startMs: (pid) => processStartMs(pid, proc)
|
|
34544
|
+
};
|
|
34545
|
+
}
|
|
34546
|
+
function psProcTable(run3 = (c, a) => execFileSync(c, a, { encoding: "utf8", timeout: 1500, stdio: ["ignore", "pipe", "ignore"] })) {
|
|
34547
|
+
let rows2;
|
|
34548
|
+
const load = () => {
|
|
34549
|
+
if (rows2) return rows2;
|
|
34550
|
+
rows2 = /* @__PURE__ */ new Map();
|
|
34551
|
+
const now = Date.now();
|
|
34552
|
+
for (const line2 of run3("ps", ["-axo", "pid=,ppid=,etime=,command="]).split("\n")) {
|
|
34553
|
+
const m = /^\s*(\d+)\s+(\d+)\s+(?:(?:(\d+)-)?(?:(\d+):)?)(\d+):(\d+)\s+(.*)$/.exec(line2);
|
|
34554
|
+
if (!m) continue;
|
|
34555
|
+
const secs = Number(m[3] ?? 0) * 86400 + Number(m[4] ?? 0) * 3600 + Number(m[5]) * 60 + Number(m[6]);
|
|
34556
|
+
rows2.set(Number(m[1]), { ppid: Number(m[2]), startMs: now - secs * 1e3, args: m[7].split(/\s+/).filter(Boolean) });
|
|
34557
|
+
}
|
|
34558
|
+
return rows2;
|
|
34559
|
+
};
|
|
34560
|
+
const cwds = /* @__PURE__ */ new Map();
|
|
34561
|
+
return {
|
|
34562
|
+
pids: () => [...load().keys()],
|
|
34563
|
+
args: (pid) => load().get(pid)?.args,
|
|
34564
|
+
ppid: (pid) => load().get(pid)?.ppid,
|
|
34565
|
+
startMs: (pid) => load().get(pid)?.startMs,
|
|
34566
|
+
cwd: (pid) => {
|
|
34567
|
+
if (!cwds.has(pid)) {
|
|
34568
|
+
try {
|
|
34569
|
+
const out = run3("lsof", ["-a", "-d", "cwd", "-Fn", "-p", String(pid)]);
|
|
34570
|
+
cwds.set(pid, /^n(.+)$/m.exec(out)?.[1]);
|
|
34571
|
+
} catch {
|
|
34572
|
+
cwds.set(pid, void 0);
|
|
34573
|
+
}
|
|
34574
|
+
}
|
|
34575
|
+
return cwds.get(pid);
|
|
34576
|
+
}
|
|
34577
|
+
};
|
|
34578
|
+
}
|
|
34579
|
+
var EMPTY = { pids: () => [], args: () => void 0, cwd: () => void 0, ppid: () => void 0, startMs: () => void 0 };
|
|
34580
|
+
function defaultProcTable(platform = process.platform) {
|
|
34581
|
+
if (platform === "linux") return linuxProcTable();
|
|
34582
|
+
if (platform === "darwin") return psProcTable();
|
|
34583
|
+
return EMPTY;
|
|
34584
|
+
}
|
|
34585
|
+
|
|
34586
|
+
// server/sources/gentle-shell/source.ts
|
|
34587
|
+
var PRESENCE_STALE_MS = 3e4;
|
|
34588
|
+
var FALLBACK_RECENT_MS2 = 30 * 6e4;
|
|
34589
|
+
var WORKING_QUIET_MS2 = 30 * 6e4;
|
|
34590
|
+
var TASK_STALE_MS = 30 * 6e4;
|
|
34591
|
+
var CLOSE_AFTER_MISSING_MS3 = 1500;
|
|
34592
|
+
var BACKLOG_MAX2 = 400;
|
|
34593
|
+
var ACTIVE_TASK = /* @__PURE__ */ new Set(["queued", "running", "waiting", "pending", "starting", "in_progress"]);
|
|
34594
|
+
var MAIN_ROLE2 = tr("Agente principal (Gentle Shell)");
|
|
34595
|
+
var SUB_ROLE2 = tr("Subagente (Gentle Shell)");
|
|
34596
|
+
function roleOf2(raw) {
|
|
34597
|
+
const r = raw?.trim();
|
|
34598
|
+
return r ? `${r[0].toUpperCase()}${r.slice(1)}` : SUB_ROLE2;
|
|
34599
|
+
}
|
|
34600
|
+
var GentleShellSource = class {
|
|
34601
|
+
constructor(opts) {
|
|
34602
|
+
this.opts = opts;
|
|
34603
|
+
this.now = opts.now ?? Date.now;
|
|
34604
|
+
this.tailBytes = opts.tailBytes ?? 2 * 1024 * 1024;
|
|
34605
|
+
const others = opts.accounts.entries();
|
|
34606
|
+
this.detected = detectGentleShellAccounts(opts.dirs, {
|
|
34607
|
+
taken: { shorts: [...others, ...opts.accounts.entriesOf("codex")].map((e) => e.detected.short), colors: [...others, ...opts.accounts.entriesOf("codex")].map((e) => e.detected.color) }
|
|
34608
|
+
});
|
|
34609
|
+
this.entries = opts.accounts.setProviderAccounts(
|
|
34610
|
+
"gentle-shell",
|
|
34611
|
+
opts.dirs.map((dir, i) => ({ dir, detected: this.detected[i] }))
|
|
34612
|
+
);
|
|
34613
|
+
this.accs = this.entries.map((e) => ({ id: e.id, dir: e.dir, configDir: e.detected.configDir, index: new SessionIndex(e.dir, this.now), tasks: new TaskStore(e.dir), recent: /* @__PURE__ */ new Map(), recentAt: -Infinity }));
|
|
34614
|
+
}
|
|
34615
|
+
opts;
|
|
34616
|
+
provider = "gentle-shell";
|
|
34617
|
+
accs = [];
|
|
34618
|
+
entries = [];
|
|
34619
|
+
detected = [];
|
|
34620
|
+
trackers = /* @__PURE__ */ new Map();
|
|
34621
|
+
timer = null;
|
|
34622
|
+
now;
|
|
34623
|
+
tailBytes;
|
|
34624
|
+
procTable;
|
|
34625
|
+
/** Contas do Gentle Shell (ids finais, no AccountsService). */
|
|
34626
|
+
accountEntries() {
|
|
34627
|
+
return this.entries;
|
|
34628
|
+
}
|
|
34629
|
+
start() {
|
|
34630
|
+
this.boot();
|
|
34631
|
+
this.timer = setInterval(() => this.safePoll(), this.opts.pollMs ?? 1e3);
|
|
34632
|
+
this.timer.unref?.();
|
|
34633
|
+
}
|
|
34634
|
+
/** Reconstrói as sessões abertas sem gerar avisos. Síncrono e curto. */
|
|
34635
|
+
boot() {
|
|
34636
|
+
this.opts.office.beginBoot();
|
|
34637
|
+
try {
|
|
34638
|
+
this.poll(true);
|
|
34639
|
+
} finally {
|
|
34640
|
+
this.opts.office.endBoot();
|
|
34641
|
+
}
|
|
34642
|
+
}
|
|
34643
|
+
stop() {
|
|
34644
|
+
if (this.timer) clearInterval(this.timer);
|
|
34645
|
+
this.timer = null;
|
|
34646
|
+
}
|
|
34647
|
+
sources() {
|
|
34648
|
+
return this.accs.map((acc) => {
|
|
34649
|
+
let sessions = 0;
|
|
34650
|
+
for (const t of this.trackers.values()) if (t.acc === acc && t.kind === "main" && t.inOffice) sessions++;
|
|
34651
|
+
const info = { label: acc.id, provider: "gentle-shell", path: acc.configDir, sessions, ok: !acc.error };
|
|
34652
|
+
if (acc.error) info.error = acc.error;
|
|
34653
|
+
return info;
|
|
34654
|
+
});
|
|
34655
|
+
}
|
|
34656
|
+
transcriptPathOf(agentId) {
|
|
34657
|
+
const t = this.trackers.get(agentId);
|
|
34658
|
+
return t?.inOffice ? t.path : void 0;
|
|
34659
|
+
}
|
|
34660
|
+
terminalParser(agentId) {
|
|
34661
|
+
return this.trackers.has(agentId) ? createGentleShellTerminalParser() : void 0;
|
|
34662
|
+
}
|
|
34663
|
+
watchedTranscripts() {
|
|
34664
|
+
return this.trackers.size;
|
|
34665
|
+
}
|
|
34666
|
+
// ---------------------------------------------------------------- polling
|
|
34667
|
+
safePoll() {
|
|
34668
|
+
try {
|
|
34669
|
+
this.poll(false);
|
|
34670
|
+
} catch (err) {
|
|
34671
|
+
log.warnOnce(`gentle-shell-poll:${errMsg(err)}`, tr("Gentle Shell: falha no ciclo de leitura: {0}", [errMsg(err)]));
|
|
34672
|
+
}
|
|
34673
|
+
}
|
|
34674
|
+
poll(boot = false) {
|
|
34675
|
+
const now = this.now();
|
|
34676
|
+
const seen = /* @__PURE__ */ new Set();
|
|
34677
|
+
for (const acc of this.accs) {
|
|
34678
|
+
for (const [sessionId, workspace] of this.presentSessions(acc, now)) {
|
|
34679
|
+
const key = `${acc.id}:${sessionId}`;
|
|
34680
|
+
let t = this.trackers.get(key);
|
|
34681
|
+
if (!t) {
|
|
34682
|
+
t = this.newTracker(acc, key, "main", sessionId);
|
|
34683
|
+
this.trackers.set(key, t);
|
|
34684
|
+
}
|
|
34685
|
+
if (workspace) t.workspace = workspace;
|
|
34686
|
+
try {
|
|
34687
|
+
this.syncMain(t, now);
|
|
34688
|
+
} catch (err) {
|
|
34689
|
+
log.warnOnce(`gentle-shell-session:${key}:${errMsg(err)}`, tr("Gentle Shell: sess\xE3o {0}: {1}", [key, errMsg(err)]));
|
|
34690
|
+
}
|
|
34691
|
+
seen.add(key);
|
|
34692
|
+
}
|
|
34693
|
+
}
|
|
34694
|
+
for (const [key, t] of [...this.trackers]) {
|
|
34695
|
+
if (t.kind !== "main" || seen.has(key)) continue;
|
|
34696
|
+
t.missingSince ??= now;
|
|
34697
|
+
if (!boot && now - t.missingSince < CLOSE_AFTER_MISSING_MS3) continue;
|
|
34698
|
+
this.leaveMain(t);
|
|
34699
|
+
this.trackers.delete(key);
|
|
34700
|
+
}
|
|
34701
|
+
for (const acc of this.accs) {
|
|
34702
|
+
try {
|
|
34703
|
+
this.syncSubs(acc, now);
|
|
34704
|
+
} catch (err) {
|
|
34705
|
+
log.warnOnce(`gentle-shell-tasks:${acc.id}:${errMsg(err)}`, tr("Gentle Shell: falha ao ler os subagentes: {0}", [errMsg(err)]));
|
|
34706
|
+
}
|
|
34707
|
+
}
|
|
34708
|
+
}
|
|
34709
|
+
/** Sessões abertas de uma conta (id → projeto da presença, quando houver). */
|
|
34710
|
+
presentSessions(acc, now) {
|
|
34711
|
+
const out = /* @__PURE__ */ new Map();
|
|
34712
|
+
acc.index.refresh();
|
|
34713
|
+
const presence = readPresence(acc.dir);
|
|
34714
|
+
if (presence) {
|
|
34715
|
+
const fresh = presence.filter((p) => now - p.heartbeat <= PRESENCE_STALE_MS);
|
|
34716
|
+
const known = new Set(fresh.flatMap((p) => p.sessionId ? [p.sessionId] : []));
|
|
34717
|
+
for (const p of fresh) {
|
|
34718
|
+
const id = this.sessionOf(acc, p, known);
|
|
34719
|
+
if (id) {
|
|
34720
|
+
out.set(id, p.workspace);
|
|
34721
|
+
known.add(id);
|
|
34722
|
+
}
|
|
34723
|
+
}
|
|
34724
|
+
return out;
|
|
34725
|
+
}
|
|
34726
|
+
if (now - acc.recentAt >= 1e4) {
|
|
34727
|
+
acc.recentAt = now;
|
|
34728
|
+
acc.recent = new Map(acc.index.all().map((f) => [f.sessionId, f.mtimeMs]));
|
|
34729
|
+
}
|
|
34730
|
+
for (const [sessionId, mtime] of acc.recent) {
|
|
34731
|
+
const t = this.trackers.get(`${acc.id}:${sessionId}`);
|
|
34732
|
+
if (now - Math.max(mtime, t?.lastWriteAt ?? 0) <= FALLBACK_RECENT_MS2) out.set(sessionId, void 0);
|
|
34733
|
+
}
|
|
34734
|
+
return out;
|
|
34735
|
+
}
|
|
34736
|
+
/** Sessão de uma encarnação: a do discovery ou, sem ela, o transcript mais recente do projeto ainda sem dono. */
|
|
34737
|
+
sessionOf(acc, p, taken) {
|
|
34738
|
+
if (p.sessionId) return p.sessionId;
|
|
34739
|
+
if (!p.workspace) return void 0;
|
|
34740
|
+
return acc.index.latestFor(p.workspace, taken)?.sessionId;
|
|
34741
|
+
}
|
|
34742
|
+
newTracker(acc, key, kind, rawId) {
|
|
34743
|
+
return { key, acc, kind, rawId, state: createPiState(), backlog: [], inOffice: false, status: kind === "sub" ? "working" : "idle", statusAt: 0 };
|
|
34744
|
+
}
|
|
34745
|
+
// ---------------------------------------------------------------- principais
|
|
34746
|
+
syncMain(t, now) {
|
|
34747
|
+
delete t.missingSince;
|
|
34748
|
+
if (t.inOffice && !this.opts.office.has(t.key)) t.inOffice = false;
|
|
34749
|
+
if (!t.tail) {
|
|
34750
|
+
const file = t.acc.index.find(t.rawId);
|
|
34751
|
+
if (!file) return;
|
|
34752
|
+
this.load(t, file.path);
|
|
34753
|
+
} else {
|
|
34754
|
+
this.pump(t);
|
|
34755
|
+
}
|
|
34756
|
+
const cwd = t.state.cwd ?? t.workspace;
|
|
34757
|
+
if (cwd && !t.inOffice && t.tail) this.enter(t, cwd, now);
|
|
34758
|
+
if (t.inOffice) {
|
|
34759
|
+
this.quietCheck(t, now);
|
|
34760
|
+
this.opts.office.fillWorkingActivity(t.key);
|
|
34761
|
+
}
|
|
34762
|
+
}
|
|
34763
|
+
enter(t, cwd, now) {
|
|
34764
|
+
const office2 = this.opts.office;
|
|
34765
|
+
const delegated = this.delegatedOf(t, cwd);
|
|
34766
|
+
office2.addMain({
|
|
34767
|
+
id: t.key,
|
|
34768
|
+
provider: "gentle-shell",
|
|
34769
|
+
account: t.acc.id,
|
|
34770
|
+
sessionId: t.rawId,
|
|
34771
|
+
cwd,
|
|
34772
|
+
...delegated ? { roomId: GENTLE_SHELL_ROOM_ID, project: deriveProject(cwd) } : {},
|
|
34773
|
+
role: MAIN_ROLE2,
|
|
34774
|
+
startedAt: t.state.startedAt ?? t.state.firstAt ?? now,
|
|
34775
|
+
status: t.status,
|
|
34776
|
+
waitingFor: t.waitingFor
|
|
34777
|
+
});
|
|
34778
|
+
t.inOffice = office2.has(t.key);
|
|
34779
|
+
if (!t.inOffice) return;
|
|
34780
|
+
office2.setStatus(t.key, t.status, t.waitingFor);
|
|
34781
|
+
this.flushBacklog(t);
|
|
34782
|
+
this.applySummary(t);
|
|
34783
|
+
}
|
|
34784
|
+
/** Veredito de sessão delegada: uma varredura de processos por sessão, guardada no tracker. */
|
|
34785
|
+
delegatedOf(t, cwd) {
|
|
34786
|
+
if (t.delegated !== void 0) return t.delegated;
|
|
34787
|
+
this.procTable ??= this.opts.procTable ?? defaultProcTable();
|
|
34788
|
+
const known = knownAgentPids(this.opts.office.list());
|
|
34789
|
+
for (const o of this.trackers.values()) if (o.pid !== void 0 && o.delegated !== void 0) known.add(o.pid);
|
|
34790
|
+
const r = classifyDelegation(cwd, t.state.startedAt ?? t.state.firstAt, known, this.procTable);
|
|
34791
|
+
t.delegated = r.delegated;
|
|
34792
|
+
t.pid = r.pid;
|
|
34793
|
+
return r.delegated;
|
|
34794
|
+
}
|
|
34795
|
+
leaveMain(t) {
|
|
34796
|
+
if (!t.inOffice) return;
|
|
34797
|
+
this.opts.office.closeMain(t.key);
|
|
34798
|
+
t.inOffice = false;
|
|
34799
|
+
}
|
|
34800
|
+
// ---------------------------------------------------------------- subagentes
|
|
34801
|
+
syncSubs(acc, now) {
|
|
34802
|
+
const tasks = acc.tasks.read();
|
|
34803
|
+
const active2 = /* @__PURE__ */ new Map();
|
|
34804
|
+
for (const task of tasks) {
|
|
34805
|
+
if (!ACTIVE_TASK.has(task.status)) continue;
|
|
34806
|
+
if (now - (task.lastAt ?? task.startedAt ?? 0) > TASK_STALE_MS) continue;
|
|
34807
|
+
active2.set(`${acc.id}:${task.id}`, task);
|
|
34808
|
+
}
|
|
34809
|
+
for (const [key, task] of active2) {
|
|
34810
|
+
const parent = this.trackers.get(`${acc.id}:${task.parentSessionId}`);
|
|
34811
|
+
if (!parent?.inOffice || this.opts.office.isSubDone(parent.key)) continue;
|
|
34812
|
+
let t = this.trackers.get(key);
|
|
34813
|
+
if (!t) {
|
|
34814
|
+
t = this.newTracker(acc, key, "sub", task.id);
|
|
34815
|
+
this.trackers.set(key, t);
|
|
34816
|
+
}
|
|
34817
|
+
t.task = task;
|
|
34818
|
+
this.syncSub(t, parent, now);
|
|
34819
|
+
}
|
|
34820
|
+
for (const [key, t] of [...this.trackers]) {
|
|
34821
|
+
if (t.kind !== "sub" || t.acc !== acc) continue;
|
|
34822
|
+
const parent = this.trackers.get(`${acc.id}:${t.task?.parentSessionId}`);
|
|
34823
|
+
if (active2.has(key) && parent?.inOffice) continue;
|
|
34824
|
+
if (t.inOffice) this.opts.office.completeSub(t.key);
|
|
34825
|
+
this.trackers.delete(key);
|
|
34826
|
+
}
|
|
34827
|
+
}
|
|
34828
|
+
syncSub(t, parent, now) {
|
|
34829
|
+
const task = t.task;
|
|
34830
|
+
const path = this.subPath(t.acc, task);
|
|
34831
|
+
if (path && path !== t.path) this.load(t, path);
|
|
34832
|
+
else if (t.tail) this.pump(t);
|
|
34833
|
+
if (!t.inOffice) {
|
|
34834
|
+
const added = this.opts.office.addSub({
|
|
34835
|
+
id: t.key,
|
|
34836
|
+
parentId: parent.key,
|
|
34837
|
+
sessionId: task.id,
|
|
34838
|
+
role: roleOf2(task.agent),
|
|
34839
|
+
title: task.label,
|
|
34840
|
+
background: task.mode === "background",
|
|
34841
|
+
startedAt: task.startedAt ?? t.state.firstAt ?? now
|
|
34842
|
+
});
|
|
34843
|
+
if (!added) return;
|
|
34844
|
+
t.inOffice = true;
|
|
34845
|
+
this.flushBacklog(t);
|
|
34846
|
+
}
|
|
34847
|
+
if (this.opts.office.isSubDone(t.key)) this.opts.office.reactivateSub(t.key);
|
|
34848
|
+
this.applySummary(t);
|
|
34849
|
+
}
|
|
34850
|
+
/** Transcript do subagente (só dentro das pastas de sessões do Gentle Shell). */
|
|
34851
|
+
subPath(acc, task) {
|
|
34852
|
+
if (!task.sessionPath) return void 0;
|
|
34853
|
+
const p = resolve13(task.sessionPath);
|
|
34854
|
+
const roots = [join26(resolve13(acc.dir), SUB_SESSIONS_DIR), join26(resolve13(acc.dir), SESSIONS_DIR2)];
|
|
34855
|
+
return p.endsWith(".jsonl") && roots.some((r) => p.startsWith(r + sep5)) ? p : void 0;
|
|
34856
|
+
}
|
|
34857
|
+
// ---------------------------------------------------------------- transcript
|
|
34858
|
+
/** Lê o começo (cwd, título, modelo) e a janela do fim do transcript. */
|
|
34859
|
+
load(t, path) {
|
|
34860
|
+
const head = parsePiHead(readHeadLines(path));
|
|
34861
|
+
const tail = new FileTail(path);
|
|
34862
|
+
tail.seekTail(this.tailBytes);
|
|
34863
|
+
t.tail = tail;
|
|
34864
|
+
t.path = path;
|
|
34865
|
+
t.state = createPiState();
|
|
34866
|
+
t.state.sessionId = head.sessionId;
|
|
34867
|
+
t.state.cwd = head.cwd;
|
|
34868
|
+
t.state.startedAt = head.startedAt;
|
|
34869
|
+
t.state.model = head.model;
|
|
34870
|
+
t.state.title = head.title;
|
|
34871
|
+
t.backlog = [];
|
|
34872
|
+
for (let i = 0; i < 64; i++) {
|
|
34873
|
+
const r = tail.read();
|
|
34874
|
+
for (const line2 of r.lines) this.apply(t, parsePiLine(t.state, line2, { idPrefix: t.key, now: this.now() }), false);
|
|
34875
|
+
if (!r.more) break;
|
|
34876
|
+
}
|
|
34877
|
+
t.lastWriteAt = tail.mtimeMs;
|
|
34878
|
+
if (t.inOffice) {
|
|
34879
|
+
this.flushBacklog(t);
|
|
34880
|
+
this.statusToOffice(t);
|
|
34881
|
+
}
|
|
34882
|
+
}
|
|
34883
|
+
pump(t) {
|
|
34884
|
+
const tail = t.tail;
|
|
34885
|
+
if (!tail) return;
|
|
34886
|
+
for (let i = 0; i < 4; i++) {
|
|
34887
|
+
let r;
|
|
34888
|
+
try {
|
|
34889
|
+
r = tail.read();
|
|
34890
|
+
} catch (err) {
|
|
34891
|
+
log.warnOnce(`gentle-shell-read:${t.key}`, tr("Gentle Shell: transcript de {0} ileg\xEDvel ({1}).", [t.key, errMsg(err)]));
|
|
34892
|
+
return;
|
|
34893
|
+
}
|
|
34894
|
+
if (r.missing) {
|
|
34895
|
+
delete t.tail;
|
|
34896
|
+
delete t.path;
|
|
34897
|
+
return;
|
|
34898
|
+
}
|
|
34899
|
+
t.lastWriteAt = tail.mtimeMs;
|
|
34900
|
+
if (r.reset) {
|
|
34901
|
+
this.load(t, tail.path);
|
|
34902
|
+
return;
|
|
34903
|
+
}
|
|
34904
|
+
for (const line2 of r.lines) this.apply(t, parsePiLine(t.state, line2, { idPrefix: t.key, now: this.now() }), true);
|
|
34905
|
+
if (r.lines.length) this.applySummary(t);
|
|
34906
|
+
if (!r.more) break;
|
|
34907
|
+
}
|
|
34908
|
+
}
|
|
34909
|
+
/** Aplica um resultado de linha: ao vivo vai direto ao escritório; na carga inicial, fica no backlog. */
|
|
34910
|
+
apply(t, r, live) {
|
|
34911
|
+
if (t.kind === "main") {
|
|
34912
|
+
for (const sig of r.signals) {
|
|
34913
|
+
switch (sig.type) {
|
|
34914
|
+
case "turnStart":
|
|
34915
|
+
this.decide(t, "working", r.at, void 0, live);
|
|
34916
|
+
break;
|
|
34917
|
+
case "turnEnd":
|
|
34918
|
+
this.decide(t, "idle", r.at, void 0, live);
|
|
34919
|
+
break;
|
|
34920
|
+
case "waiting":
|
|
34921
|
+
this.decide(t, "waiting", r.at, sig.reason, live);
|
|
34922
|
+
break;
|
|
34923
|
+
case "progress":
|
|
34924
|
+
if (t.status === "waiting") this.decide(t, "working", r.at, void 0, live);
|
|
34925
|
+
break;
|
|
34926
|
+
}
|
|
34927
|
+
}
|
|
34928
|
+
}
|
|
34929
|
+
if (!live || !t.inOffice) {
|
|
34930
|
+
if (r.activities.length) {
|
|
34931
|
+
t.backlog.push(r);
|
|
34932
|
+
if (t.backlog.length > BACKLOG_MAX2) t.backlog.splice(0, t.backlog.length - BACKLOG_MAX2);
|
|
34933
|
+
}
|
|
34934
|
+
return;
|
|
34935
|
+
}
|
|
34936
|
+
this.toOffice(t, r, true);
|
|
34937
|
+
}
|
|
34938
|
+
toOffice(t, r, live) {
|
|
34939
|
+
for (const a of r.activities) this.opts.office.addActivity(t.key, a.activity, a.current, { feed: live });
|
|
34940
|
+
}
|
|
34941
|
+
flushBacklog(t) {
|
|
34942
|
+
const backlog = t.backlog;
|
|
34943
|
+
t.backlog = [];
|
|
34944
|
+
for (const r of backlog) this.toOffice(t, r, false);
|
|
34945
|
+
}
|
|
34946
|
+
/** Muda o status por uma borda do transcript: informação mais velha que a última decisão não vale. */
|
|
34947
|
+
decide(t, status2, at, waitingFor, live) {
|
|
34948
|
+
if (at < t.statusAt) return;
|
|
34949
|
+
t.statusAt = at;
|
|
34950
|
+
t.status = status2;
|
|
34951
|
+
if (waitingFor) t.waitingFor = waitingFor;
|
|
34952
|
+
else delete t.waitingFor;
|
|
34953
|
+
if (live) this.statusToOffice(t);
|
|
34954
|
+
}
|
|
34955
|
+
statusToOffice(t) {
|
|
34956
|
+
if (t.inOffice && t.kind === "main") this.opts.office.setStatus(t.key, t.status, t.waitingFor);
|
|
34957
|
+
}
|
|
34958
|
+
/** 'working' sem nenhuma escrita por muito tempo (turno morto num crash): vira 'idle'. */
|
|
34959
|
+
quietCheck(t, now) {
|
|
34960
|
+
if (t.status !== "working") return;
|
|
34961
|
+
if (now - Math.max(t.lastWriteAt ?? 0, t.statusAt) > WORKING_QUIET_MS2) this.decide(t, "idle", now, void 0, true);
|
|
34962
|
+
}
|
|
34963
|
+
applySummary(t) {
|
|
34964
|
+
if (!t.inOffice) return;
|
|
34965
|
+
const s2 = t.state;
|
|
34966
|
+
const summary = { tasks: s2.tasks, stats: { ...s2.stats } };
|
|
34967
|
+
const title = t.kind === "sub" ? t.task?.label ?? s2.title : s2.title;
|
|
34968
|
+
if (title) summary.title = title;
|
|
34969
|
+
const model = s2.model ?? t.task?.model;
|
|
34970
|
+
if (model) summary.model = model;
|
|
34971
|
+
if (s2.firstAt !== void 0) summary.firstAt = s2.firstAt;
|
|
34972
|
+
if (s2.lastAt !== void 0) summary.lastAt = s2.lastAt;
|
|
34973
|
+
this.opts.office.applyTranscript(t.key, summary);
|
|
34974
|
+
}
|
|
34975
|
+
};
|
|
34976
|
+
|
|
34780
34977
|
// server/build.ts
|
|
34781
34978
|
import { readFileSync as readFileSync22, statSync as statSync21 } from "node:fs";
|
|
34782
34979
|
import { join as join27 } from "node:path";
|
|
@@ -35046,8 +35243,8 @@ import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync16 } from "nod
|
|
|
35046
35243
|
import { dirname as dirname15, join as join29 } from "node:path";
|
|
35047
35244
|
|
|
35048
35245
|
// scripts/cli/layout.ts
|
|
35049
|
-
import { cpSync, existsSync as existsSync11, mkdirSync as mkdirSync15, readdirSync as
|
|
35050
|
-
import { isAbsolute as isAbsolute6, join as join28, relative as relative3, resolve as
|
|
35246
|
+
import { cpSync, existsSync as existsSync11, mkdirSync as mkdirSync15, readdirSync as readdirSync17, readFileSync as readFileSync24, realpathSync as realpathSync6, renameSync as renameSync14, rmSync as rmSync6, statSync as statSync22, symlinkSync, writeFileSync as writeFileSync14 } from "node:fs";
|
|
35247
|
+
import { isAbsolute as isAbsolute6, join as join28, relative as relative3, resolve as resolve14 } from "node:path";
|
|
35051
35248
|
function layoutOf(dir) {
|
|
35052
35249
|
return {
|
|
35053
35250
|
dir,
|
|
@@ -35089,10 +35286,10 @@ async function startUpdate(o) {
|
|
|
35089
35286
|
if (lockHolder(o.layout, o.alive) !== void 0) return { status: 409, error: tr("j\xE1 est\xE1 rodando uma atualiza\xE7\xE3o") };
|
|
35090
35287
|
const c = updateCommand({ bin: o.layout.bin, platform: o.platform, env: o.env, now: o.now });
|
|
35091
35288
|
const child = o.spawn(c.cmd, c.args, { detached: c.detached, stdio: "ignore", env: o.env });
|
|
35092
|
-
const failure = await new Promise((
|
|
35093
|
-
child.once?.("error", (err) =>
|
|
35094
|
-
child.once?.("spawn", () =>
|
|
35095
|
-
if (!child.once)
|
|
35289
|
+
const failure = await new Promise((resolve15) => {
|
|
35290
|
+
child.once?.("error", (err) => resolve15(err));
|
|
35291
|
+
child.once?.("spawn", () => resolve15(void 0));
|
|
35292
|
+
if (!child.once) resolve15(void 0);
|
|
35096
35293
|
});
|
|
35097
35294
|
if (failure) {
|
|
35098
35295
|
try {
|
|
@@ -35111,7 +35308,7 @@ async function startUpdate(o) {
|
|
|
35111
35308
|
import { spawn as spawnProcess } from "node:child_process";
|
|
35112
35309
|
|
|
35113
35310
|
// server/spawn/spawn.ts
|
|
35114
|
-
import { execFile as
|
|
35311
|
+
import { execFile as execFile5 } from "node:child_process";
|
|
35115
35312
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
35116
35313
|
import { statSync as statSync23 } from "node:fs";
|
|
35117
35314
|
import { isAbsolute as isAbsolute7 } from "node:path";
|
|
@@ -35127,6 +35324,87 @@ function isHerdrPaneId(s2) {
|
|
|
35127
35324
|
return typeof s2 === "string" && PANE_ID.test(s2);
|
|
35128
35325
|
}
|
|
35129
35326
|
|
|
35327
|
+
// server/spawn/models.ts
|
|
35328
|
+
import { execFile as execFile4 } from "node:child_process";
|
|
35329
|
+
var MODEL_MAX = 100;
|
|
35330
|
+
var MODEL_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._/:-]*$/;
|
|
35331
|
+
var CLAUDE_MODELS = ["opus", "sonnet", "haiku", "fable"];
|
|
35332
|
+
var LIST_TTL_MS = 10 * 6e4;
|
|
35333
|
+
var LIST_TIMEOUT_MS = 15e3;
|
|
35334
|
+
var LIST_FAIL_TTL_MS = 3e4;
|
|
35335
|
+
function parseListModels(text3) {
|
|
35336
|
+
const out = [];
|
|
35337
|
+
for (const line2 of text3.split("\n").slice(1)) {
|
|
35338
|
+
const [provider, model, ...rest] = line2.trim().split(/\s+/);
|
|
35339
|
+
if (!provider || !model || !rest.length) continue;
|
|
35340
|
+
const value = `${provider}/${model}`;
|
|
35341
|
+
if (value.length <= MODEL_MAX && MODEL_PATTERN.test(value) && !out.includes(value)) out.push(value);
|
|
35342
|
+
}
|
|
35343
|
+
return out;
|
|
35344
|
+
}
|
|
35345
|
+
function modelProblem(provider, model, offered) {
|
|
35346
|
+
if (!model || model.length > MODEL_MAX || !MODEL_PATTERN.test(model)) {
|
|
35347
|
+
return tr("modelo inv\xE1lido (use letras, d\xEDgitos e . - _ / :, at\xE9 {0} caracteres)", [MODEL_MAX]);
|
|
35348
|
+
}
|
|
35349
|
+
if (provider === "claude" && !CLAUDE_MODELS.includes(model)) return tr("modelo desconhecido para o Claude Code");
|
|
35350
|
+
if (provider === "gentle-shell") {
|
|
35351
|
+
if (!offered) return tr("a lista de modelos do Gentle Shell ainda n\xE3o carregou: abra o di\xE1logo de novo");
|
|
35352
|
+
if (!offered.includes(model)) return tr("modelo desconhecido para o Gentle Shell");
|
|
35353
|
+
}
|
|
35354
|
+
return void 0;
|
|
35355
|
+
}
|
|
35356
|
+
function createGentleModelLister(opts) {
|
|
35357
|
+
const now = opts.now ?? Date.now;
|
|
35358
|
+
const ttl = opts.ttlMs ?? LIST_TTL_MS;
|
|
35359
|
+
const failTtl = opts.failTtlMs ?? LIST_FAIL_TTL_MS;
|
|
35360
|
+
const timeoutMs = opts.timeoutMs ?? LIST_TIMEOUT_MS;
|
|
35361
|
+
let cache2;
|
|
35362
|
+
let failedAt;
|
|
35363
|
+
let inflight = false;
|
|
35364
|
+
const refresh = () => {
|
|
35365
|
+
inflight = true;
|
|
35366
|
+
let timer;
|
|
35367
|
+
const deadline = new Promise((_ok, no) => {
|
|
35368
|
+
timer = setTimeout(() => no(new Error("timeout")), timeoutMs);
|
|
35369
|
+
});
|
|
35370
|
+
Promise.race([opts.run(), deadline]).then((text3) => {
|
|
35371
|
+
const models = parseListModels(text3);
|
|
35372
|
+
if (!models.length) throw new Error("empty");
|
|
35373
|
+
cache2 = { models, at: now() };
|
|
35374
|
+
failedAt = void 0;
|
|
35375
|
+
}).catch(() => {
|
|
35376
|
+
failedAt = now();
|
|
35377
|
+
}).finally(() => {
|
|
35378
|
+
clearTimeout(timer);
|
|
35379
|
+
inflight = false;
|
|
35380
|
+
});
|
|
35381
|
+
};
|
|
35382
|
+
const failedRecently = () => failedAt !== void 0 && now() - failedAt <= failTtl;
|
|
35383
|
+
return {
|
|
35384
|
+
lookup() {
|
|
35385
|
+
const stale = !cache2 || now() - cache2.at > ttl;
|
|
35386
|
+
if (stale && !inflight && !failedRecently()) refresh();
|
|
35387
|
+
if (cache2) return { state: "ready", models: [...cache2.models] };
|
|
35388
|
+
return inflight ? { state: "loading" } : { state: "unavailable" };
|
|
35389
|
+
},
|
|
35390
|
+
peek: () => cache2 ? [...cache2.models] : void 0
|
|
35391
|
+
};
|
|
35392
|
+
}
|
|
35393
|
+
function createListModelsRunner(bin, timeoutMs = LIST_TIMEOUT_MS) {
|
|
35394
|
+
return () => new Promise((ok, no) => {
|
|
35395
|
+
const path = bin();
|
|
35396
|
+
if (!path) return no(new Error("gentle-shell not found"));
|
|
35397
|
+
const child = execFile4(path, ["--", "--list-models"], { timeout: timeoutMs, windowsHide: true, encoding: "utf8", maxBuffer: 1 << 20 }, (err, out) => err ? no(err) : ok(out));
|
|
35398
|
+
child.stdin?.end();
|
|
35399
|
+
});
|
|
35400
|
+
}
|
|
35401
|
+
function modelOptions(provider, gentle) {
|
|
35402
|
+
if (provider === "claude") return { free: false, state: "ready", models: [...CLAUDE_MODELS] };
|
|
35403
|
+
if (provider === "codex") return { free: true, state: "ready", models: [] };
|
|
35404
|
+
const l = gentle.lookup();
|
|
35405
|
+
return { free: false, state: l.state, models: l.state === "ready" ? l.models : [] };
|
|
35406
|
+
}
|
|
35407
|
+
|
|
35130
35408
|
// server/spawn/spawn.ts
|
|
35131
35409
|
var PROMPT_MAX = 8e3;
|
|
35132
35410
|
var FOLDER_MAX = 1024;
|
|
@@ -35141,7 +35419,7 @@ var MAX_OPEN3 = 5;
|
|
|
35141
35419
|
var ERROR_MAX4 = 300;
|
|
35142
35420
|
var PROVIDERS = ["claude", "gentle-shell", "codex"];
|
|
35143
35421
|
var PROVIDER_NAMES = { claude: "Claude Code", "gentle-shell": "Gentle Shell", codex: "Codex" };
|
|
35144
|
-
function parseSpawn(raw) {
|
|
35422
|
+
function parseSpawn(raw, offered = () => void 0) {
|
|
35145
35423
|
const r = raw && typeof raw === "object" ? raw : {};
|
|
35146
35424
|
const folder = typeof r.folder === "string" ? r.folder.trim() : "";
|
|
35147
35425
|
const prompt = typeof r.prompt === "string" ? r.prompt.replace(/\s+$/, "") : "";
|
|
@@ -35156,7 +35434,12 @@ function parseSpawn(raw) {
|
|
|
35156
35434
|
if (destination.kind === "background" && provider !== "claude") {
|
|
35157
35435
|
return { error: tr("{0} s\xF3 abre no herdr (n\xE3o tem modo em segundo plano)", [PROVIDER_NAMES[provider]]) };
|
|
35158
35436
|
}
|
|
35159
|
-
|
|
35437
|
+
const model = r.model === void 0 || r.model === null || r.model === "" ? void 0 : r.model;
|
|
35438
|
+
if (model !== void 0) {
|
|
35439
|
+
const problem = typeof model === "string" ? modelProblem(provider, model, offered(provider)) : tr("modelo inv\xE1lido");
|
|
35440
|
+
if (problem) return { error: problem };
|
|
35441
|
+
}
|
|
35442
|
+
return { folder, prompt, provider, destination, ...typeof model === "string" ? { model } : {} };
|
|
35160
35443
|
}
|
|
35161
35444
|
function parseDestination(raw) {
|
|
35162
35445
|
if (raw === void 0) return { kind: "background" };
|
|
@@ -35181,12 +35464,12 @@ function sessionName(prompt) {
|
|
|
35181
35464
|
return cut3 ? `Busybits: ${cut3}` : "Busybits";
|
|
35182
35465
|
}
|
|
35183
35466
|
function cliArgs(req) {
|
|
35184
|
-
const args = ["--bg", "-n", sessionName(req.prompt)];
|
|
35467
|
+
const args = ["--bg", "-n", sessionName(req.prompt), ...req.model ? ["--model", req.model] : []];
|
|
35185
35468
|
return req.prompt.trim() ? [...args, "--", req.prompt] : args;
|
|
35186
35469
|
}
|
|
35187
35470
|
function createCliRunner(bin, timeoutMs = CLI_TIMEOUT_MS) {
|
|
35188
35471
|
return (req) => new Promise((ok) => {
|
|
35189
|
-
const child =
|
|
35472
|
+
const child = execFile5(bin, cliArgs(req), { cwd: req.folder, timeout: timeoutMs, windowsHide: true, encoding: "utf8" }, (err, out, stderr) => {
|
|
35190
35473
|
const id = /backgrounded\s*·\s*([\w-]+)/.exec(out ?? "")?.[1];
|
|
35191
35474
|
if (!err && id) return ok({ ok: true, id });
|
|
35192
35475
|
const line2 = [stderr, out, err?.message].map((t) => (t ?? "").split("\n").map((l) => l.trim()).find(Boolean)).find(Boolean);
|
|
@@ -35219,7 +35502,7 @@ function folderProblem(folder, stat3 = statSync23) {
|
|
|
35219
35502
|
function createOpener(platform = process.platform, timeoutMs = OPEN_TIMEOUT_MS) {
|
|
35220
35503
|
const [bin, pre2] = platform === "darwin" ? ["open", []] : platform === "win32" ? ["cmd", ["/c", "start", '""']] : ["xdg-open", []];
|
|
35221
35504
|
return (url) => new Promise((ok) => {
|
|
35222
|
-
|
|
35505
|
+
execFile5(bin, [...pre2, url], { timeout: timeoutMs, windowsHide: true, encoding: "utf8" }, (err, _out, stderr) => {
|
|
35223
35506
|
if (!err) return ok({ ok: true });
|
|
35224
35507
|
const line2 = (stderr || err.message || "").split("\n").find((l) => l.trim()) ?? tr("falhou");
|
|
35225
35508
|
ok({ ok: false, error: `${bin}: ${line2.trim()}`.slice(0, ERROR_MAX4) });
|
|
@@ -35244,11 +35527,12 @@ var SpawnService = class {
|
|
|
35244
35527
|
}
|
|
35245
35528
|
submit(raw) {
|
|
35246
35529
|
this.prune();
|
|
35247
|
-
const req = parseSpawn(raw);
|
|
35530
|
+
const req = parseSpawn(raw, (p) => p === "gentle-shell" ? this.opts.gentleModels?.() : void 0);
|
|
35248
35531
|
if ("error" in req) return { error: "invalid", reason: req.error };
|
|
35249
35532
|
if (!this.opts.opener && (req.destination.kind !== "background" || req.provider !== "claude")) {
|
|
35250
35533
|
return { error: "invalid", reason: tr("no Docker o agente novo s\xF3 abre em segundo plano, com o Claude Code") };
|
|
35251
35534
|
}
|
|
35535
|
+
if (!this.opts.opener && req.model) return { error: "invalid", reason: tr("no Docker o agente novo n\xE3o aceita escolher o modelo") };
|
|
35252
35536
|
if (req.destination.kind !== "background" && !this.opts.herdr) return { error: "unavailable", reason: tr("o herdr n\xE3o est\xE1 dispon\xEDvel") };
|
|
35253
35537
|
if (!this.available()) {
|
|
35254
35538
|
return { error: "unavailable", reason: tr("o auxiliar do computador n\xE3o est\xE1 rodando: deixe npm run codex:bridge no ar (o Habblaud est\xE1 no Docker)") };
|
|
@@ -35319,13 +35603,13 @@ var SpawnService = class {
|
|
|
35319
35603
|
}
|
|
35320
35604
|
const prompt = promptWithAttachments(e.req.prompt, paths);
|
|
35321
35605
|
const dest = e.req.destination;
|
|
35322
|
-
if (dest.kind === "background") return this.resolve(e, await launch({ folder: e.req.folder, prompt }, opener, this.opts.cli));
|
|
35606
|
+
if (dest.kind === "background") return this.resolve(e, await launch({ folder: e.req.folder, prompt, ...e.req.model ? { model: e.req.model } : {} }, opener, this.opts.cli));
|
|
35323
35607
|
return this.resolveHerdr(e, dest, prompt);
|
|
35324
35608
|
}
|
|
35325
35609
|
async resolveHerdr(e, destination, prompt) {
|
|
35326
35610
|
const herdr2 = this.opts.herdr;
|
|
35327
35611
|
if (!herdr2) return this.resolve(e, { ok: false, error: tr("o herdr n\xE3o est\xE1 dispon\xEDvel") });
|
|
35328
|
-
const { provider, folder } = e.req;
|
|
35612
|
+
const { provider, folder, model } = e.req;
|
|
35329
35613
|
const recorded = /* @__PURE__ */ new Set();
|
|
35330
35614
|
const onPane = (paneId) => {
|
|
35331
35615
|
if (recorded.has(paneId)) return;
|
|
@@ -35339,7 +35623,7 @@ var SpawnService = class {
|
|
|
35339
35623
|
e.info.error = tr("o painel {0} do herdr foi criado, mas o agente n\xE3o come\xE7ou: {1}", [paneId, e.info.error ?? ""]).slice(0, ERROR_MAX4);
|
|
35340
35624
|
}
|
|
35341
35625
|
};
|
|
35342
|
-
const r = await herdr2({ provider, folder, prompt, destination }, onPane).catch((err) => ({
|
|
35626
|
+
const r = await herdr2({ provider, folder, prompt, destination, ...model ? { model } : {} }, onPane).catch((err) => ({
|
|
35343
35627
|
ok: false,
|
|
35344
35628
|
error: String(err?.message ?? err).slice(0, ERROR_MAX4)
|
|
35345
35629
|
}));
|
|
@@ -35380,7 +35664,7 @@ var SpawnService = class {
|
|
|
35380
35664
|
};
|
|
35381
35665
|
|
|
35382
35666
|
// server/herdr/cli.ts
|
|
35383
|
-
import { execFile as
|
|
35667
|
+
import { execFile as execFile6 } from "node:child_process";
|
|
35384
35668
|
import { join as join30 } from "node:path";
|
|
35385
35669
|
var HERDR_TIMEOUT_MS = 5e3;
|
|
35386
35670
|
var TIMEOUT_SLACK_MS = 5e3;
|
|
@@ -35435,7 +35719,7 @@ function errorOf(json) {
|
|
|
35435
35719
|
function createHerdrExec(bin, env, timeoutMs = HERDR_TIMEOUT_MS) {
|
|
35436
35720
|
return (args, callTimeout) => new Promise((ok) => {
|
|
35437
35721
|
try {
|
|
35438
|
-
const child =
|
|
35722
|
+
const child = execFile6(
|
|
35439
35723
|
bin,
|
|
35440
35724
|
[...args],
|
|
35441
35725
|
{ env, timeout: callTimeout ?? timeoutMs, windowsHide: true, encoding: "utf8", maxBuffer: 4 * 1024 * 1024 },
|
|
@@ -35658,8 +35942,13 @@ var BACKOFF_MAX_MS = 2e3;
|
|
|
35658
35942
|
var INBOX_WAIT_MS = 25e3;
|
|
35659
35943
|
var EARLY_MS2 = 5e3;
|
|
35660
35944
|
var GENTLE_SHELL_COMMAND = "gentle-shell";
|
|
35661
|
-
function providerArgs(provider, name) {
|
|
35662
|
-
|
|
35945
|
+
function providerArgs(provider, name, model) {
|
|
35946
|
+
if (provider === "claude") return model ? ["-n", name, "--model", model] : ["-n", name];
|
|
35947
|
+
return model ? ["-m", model] : [];
|
|
35948
|
+
}
|
|
35949
|
+
function gentleShellCommand(model, piArgs = []) {
|
|
35950
|
+
const args = [...piArgs, ...model ? ["--model", model] : []];
|
|
35951
|
+
return args.length ? `${GENTLE_SHELL_COMMAND} -- ${args.join(" ")}` : GENTLE_SHELL_COMMAND;
|
|
35663
35952
|
}
|
|
35664
35953
|
function agentName(provider, taken, tag) {
|
|
35665
35954
|
const prefix = provider === "gentle-shell" ? "gentle" : provider;
|
|
@@ -35696,6 +35985,7 @@ function matchGentle(agents2, known, folder, at) {
|
|
|
35696
35985
|
var message = (err) => err instanceof Error ? err.message : String(err);
|
|
35697
35986
|
var sleep = (ms) => new Promise((ok) => setTimeout(ok, ms));
|
|
35698
35987
|
async function launchInHerdr(client, req, opts = {}) {
|
|
35988
|
+
if (req.model !== void 0 && (req.model.length > MODEL_MAX || !MODEL_PATTERN.test(req.model))) return { ok: false, error: tr("modelo inv\xE1lido") };
|
|
35699
35989
|
const now = opts.now ?? Date.now;
|
|
35700
35990
|
const maxMs = opts.maxMs ?? HERDR_LAUNCH_MAX_MS;
|
|
35701
35991
|
const pollMs = opts.pollMs ?? POLL_MS2;
|
|
@@ -35799,10 +36089,10 @@ async function launchInHerdr(client, req, opts = {}) {
|
|
|
35799
36089
|
try {
|
|
35800
36090
|
if (state.over) return partial(late2);
|
|
35801
36091
|
if (req.provider === "gentle-shell") {
|
|
35802
|
-
await client.run(paneId,
|
|
36092
|
+
await client.run(paneId, gentleShellCommand(req.model));
|
|
35803
36093
|
} else {
|
|
35804
36094
|
const name = agentName(req.provider, names2, launchTag(now()));
|
|
35805
|
-
await client.startAgent(name, req.provider, paneId, providerArgs(req.provider, name), Math.min(START_MAX_MS, left()));
|
|
36095
|
+
await client.startAgent(name, req.provider, paneId, providerArgs(req.provider, name, req.model), Math.min(START_MAX_MS, left()));
|
|
35806
36096
|
}
|
|
35807
36097
|
if (req.prompt.trim() || req.provider === "gentle-shell") {
|
|
35808
36098
|
await retrying(() => client.waitIdle(paneId, Math.min(START_MAX_MS, left())), noAgentYet);
|
|
@@ -35849,7 +36139,7 @@ function detectProviders(env, find = {}) {
|
|
|
35849
36139
|
}
|
|
35850
36140
|
|
|
35851
36141
|
// server/spawn/attachments-prune.ts
|
|
35852
|
-
import { lstatSync as lstatSync3, readdirSync as
|
|
36142
|
+
import { lstatSync as lstatSync3, readdirSync as readdirSync18, rmSync as rmSync7 } from "node:fs";
|
|
35853
36143
|
import { join as join31 } from "node:path";
|
|
35854
36144
|
var ATTACHMENT_DIR_RE = /^\d{8}-\d{6}-[0-9a-f]+$/;
|
|
35855
36145
|
var DAY_MS2 = 864e5;
|
|
@@ -35860,7 +36150,7 @@ function pruneAttachments(root, days, now = Date.now(), remove = (p) => rmSync7(
|
|
|
35860
36150
|
const limit = now - days * DAY_MS2;
|
|
35861
36151
|
let names2;
|
|
35862
36152
|
try {
|
|
35863
|
-
names2 =
|
|
36153
|
+
names2 = readdirSync18(root);
|
|
35864
36154
|
} catch {
|
|
35865
36155
|
return out;
|
|
35866
36156
|
}
|
|
@@ -35997,7 +36287,7 @@ function recentFolders(sessions, rooms, limit = FOLDERS_LIMIT) {
|
|
|
35997
36287
|
}
|
|
35998
36288
|
|
|
35999
36289
|
// server/dictation/whisper.ts
|
|
36000
|
-
import { execFile as
|
|
36290
|
+
import { execFile as execFile7 } from "node:child_process";
|
|
36001
36291
|
import { existsSync as existsSync12, mkdtempSync as mkdtempSync2, readFileSync as readFileSync26, rmSync as rmSync8, writeFileSync as writeFileSync16 } from "node:fs";
|
|
36002
36292
|
import { homedir as homedir7, tmpdir } from "node:os";
|
|
36003
36293
|
import { delimiter as delimiter2, join as join32 } from "node:path";
|
|
@@ -36026,7 +36316,7 @@ function findWhisper(env = process.env, exists = existsSync12) {
|
|
|
36026
36316
|
}
|
|
36027
36317
|
function run2(bin, args, timeoutMs) {
|
|
36028
36318
|
return new Promise((ok) => {
|
|
36029
|
-
|
|
36319
|
+
execFile7(bin, args, { timeout: timeoutMs, encoding: "utf8", maxBuffer: 8 * 1024 * 1024 }, (err, _out, stderr) => {
|
|
36030
36320
|
if (!err) return ok({ ok: true });
|
|
36031
36321
|
const line2 = (stderr || err.message || "").split("\n").filter((l) => l.trim()).pop() ?? tr("falhou");
|
|
36032
36322
|
ok({ ok: false, error: line2.trim().slice(0, 300) });
|
|
@@ -40442,11 +40732,13 @@ var gentleInbox = () => messages && {
|
|
|
40442
40732
|
return { ok: false, retry: false, reason: "reason" in r ? r.reason : tr("o agente n\xE3o foi achado") };
|
|
40443
40733
|
}
|
|
40444
40734
|
};
|
|
40735
|
+
var gentleModels = createGentleModelLister({ run: createListModelsRunner(() => config.inDocker ? void 0 : findExecutable("gentle-shell", process.env)) });
|
|
40445
40736
|
var spawn = spawnOn ? new SpawnService(
|
|
40446
40737
|
config.inDocker ? { attachments } : {
|
|
40447
40738
|
opener: createOpener(),
|
|
40448
40739
|
cli: spawnBin ? createCliRunner(spawnBin) : void 0,
|
|
40449
40740
|
attachments,
|
|
40741
|
+
gentleModels: () => gentleModels.peek(),
|
|
40450
40742
|
herdr: herdrClient ? (r, onPane) => launchInHerdr(herdrClient, r, { onPane, inbox: gentleInbox() }) : void 0,
|
|
40451
40743
|
onHerdrLaunch: herdrLinks ? (r) => herdrLinks.record(r) : void 0
|
|
40452
40744
|
}
|
|
@@ -40589,6 +40881,7 @@ var api = createApiHandler({
|
|
|
40589
40881
|
dictation,
|
|
40590
40882
|
deliveries,
|
|
40591
40883
|
files: deliveryFiles,
|
|
40884
|
+
spawnModels: (provider) => modelOptions(provider, gentleModels),
|
|
40592
40885
|
spawnFolders: async () => {
|
|
40593
40886
|
const snap = hub.current();
|
|
40594
40887
|
const last = /* @__PURE__ */ new Map();
|