busybits 2.1.0 → 2.2.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 +8 -0
- package/dist/build.json +2 -2
- package/dist/cli/busybits.js +3 -0
- package/dist/client/bundle/app-BqhKcvbt.js +24 -0
- package/dist/client/bundle/{city-SSVRvwxu.js → city-DMPsypEv.js} +1 -1
- package/dist/client/bundle/{daystats-B5wgtYEK.js → daystats-BJLg6u8w.js} +1 -1
- package/dist/client/bundle/{dom-DTwIMOMe.js → dom-Co5ozWIR.js} +1 -1
- package/dist/client/bundle/{en-C1UkXkY6.js → en-DRc2Oulk.js} +1 -1
- package/dist/client/bundle/{es-DrTXrvU-.js → es-DslAKAxR.js} +1 -1
- package/dist/client/bundle/{format-COWnO8aN.js → format-k7wUh6fM.js} +1 -1
- package/dist/client/bundle/{fr-DSvgQnax.js → fr-Chqn4K83.js} +1 -1
- package/dist/client/bundle/{main-CjRdSA5N.js → main-DBC-FPBX.js} +2 -2
- package/dist/client/bundle/{ptypane-BU6MDOyh.js → ptypane-UBqz8-gA.js} +1 -1
- package/dist/client/bundle/room-name-B0XrI0hp.js +1 -0
- package/dist/client/bundle/{simulator-BhSq5TwZ.js → simulator-B0dhttuF.js} +1 -1
- package/dist/client/bundle/{world-model-D6tSJZPE.js → world-model-DZTQjqjZ.js} +1 -1
- package/dist/client/bundle/{world-stream-pGb-glkT.js → world-stream-EkZAApmC.js} +1 -1
- package/dist/client/index.html +1 -1
- package/dist/server/index.js +574 -418
- 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",
|
|
@@ -4223,6 +4224,7 @@ var ES = {
|
|
|
4223
4224
|
"O job falhou e vai sair do escrit\xF3rio.": "El trabajo fall\xF3 y saldr\xE1 de la oficina.",
|
|
4224
4225
|
"Job do Agent Hub": "Trabajo de Agent Hub",
|
|
4225
4226
|
"Agent Hub": "Agent Hub",
|
|
4227
|
+
"Gentle Shell": "Gentle Shell",
|
|
4226
4228
|
"Somente leitura: o Agent Hub gerencia este job": "Solo lectura: Agent Hub gestiona este trabajo",
|
|
4227
4229
|
"Na fila do Agent Hub": "En la cola de Agent Hub",
|
|
4228
4230
|
"Erro": "Error",
|
|
@@ -7918,6 +7920,7 @@ var FR = {
|
|
|
7918
7920
|
"O job falhou e vai sair do escrit\xF3rio.": "Le job a \xE9chou\xE9 et quitte le bureau.",
|
|
7919
7921
|
"Job do Agent Hub": "Job Agent Hub",
|
|
7920
7922
|
"Agent Hub": "Agent Hub",
|
|
7923
|
+
"Gentle Shell": "Gentle Shell",
|
|
7921
7924
|
"Somente leitura: o Agent Hub gerencia este job": "Lecture seule : Agent Hub g\xE8re ce job",
|
|
7922
7925
|
"Na fila do Agent Hub": "Dans la file d'attente d'Agent Hub",
|
|
7923
7926
|
"Erro": "Erreur",
|
|
@@ -18743,9 +18746,9 @@ function validState(body2) {
|
|
|
18743
18746
|
const ptys2 = body2.ptys;
|
|
18744
18747
|
if (!isObj2(ptys2) || !isObj2(ptys2.status) || typeof ptys2.status.enabled !== "boolean" || !Array.isArray(ptys2.list))
|
|
18745
18748
|
return bad();
|
|
18746
|
-
const
|
|
18749
|
+
const num12 = (v) => v === void 0 || typeof v === "number" && Number.isFinite(v);
|
|
18747
18750
|
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) &&
|
|
18751
|
+
(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
18752
|
).slice(0, 32);
|
|
18750
18753
|
}
|
|
18751
18754
|
return body2;
|
|
@@ -19118,14 +19121,14 @@ var CentralHub = class {
|
|
|
19118
19121
|
const now = this.now();
|
|
19119
19122
|
const id = `a-${now.toString(36)}-${++this.counter}-${randomBytes3(4).toString("hex")}`;
|
|
19120
19123
|
const timeoutMs = Math.max(1, opts.timeoutMs ?? ACTION_RESULT_TIMEOUT_MS);
|
|
19121
|
-
let
|
|
19124
|
+
let resolve15;
|
|
19122
19125
|
let reject2;
|
|
19123
19126
|
const result = new Promise((ok, fail3) => {
|
|
19124
|
-
|
|
19127
|
+
resolve15 = ok;
|
|
19125
19128
|
reject2 = fail3;
|
|
19126
19129
|
});
|
|
19127
19130
|
result.catch(() => void 0);
|
|
19128
|
-
const p = { id, machine, action: { ...action, id }, status: "queued", deadline: now + timeoutMs, timer: void 0, resolve:
|
|
19131
|
+
const p = { id, machine, action: { ...action, id }, status: "queued", deadline: now + timeoutMs, timer: void 0, resolve: resolve15, reject: reject2 };
|
|
19129
19132
|
this.pending.set(id, p);
|
|
19130
19133
|
this.rearm(p, timeoutMs);
|
|
19131
19134
|
this.hostWait(machine).wake();
|
|
@@ -19374,11 +19377,11 @@ function deliver(o, body2, res, ctx) {
|
|
|
19374
19377
|
}
|
|
19375
19378
|
var FANOUT_TIMEOUT_MS = 3e3;
|
|
19376
19379
|
function readOne(hub2, machine, path, search, timeoutMs, map) {
|
|
19377
|
-
return new Promise((
|
|
19380
|
+
return new Promise((resolve15) => {
|
|
19378
19381
|
const running = bufferedNow.get(machine) ?? 0;
|
|
19379
|
-
if (running >= BUFFERED_MAX) return
|
|
19382
|
+
if (running >= BUFFERED_MAX) return resolve15({ kind: "missing" });
|
|
19380
19383
|
const r = hub2.startRead(machine, path, search);
|
|
19381
|
-
if ("error" in r) return
|
|
19384
|
+
if ("error" in r) return resolve15({ kind: "missing" });
|
|
19382
19385
|
bufferedNow.set(machine, running + 1);
|
|
19383
19386
|
let done = false;
|
|
19384
19387
|
let body2;
|
|
@@ -19391,7 +19394,7 @@ function readOne(hub2, machine, path, search, timeoutMs, map) {
|
|
|
19391
19394
|
else bufferedNow.set(machine, n2);
|
|
19392
19395
|
if (cancel) r.cancel();
|
|
19393
19396
|
body2?.destroy();
|
|
19394
|
-
|
|
19397
|
+
resolve15(out);
|
|
19395
19398
|
};
|
|
19396
19399
|
const timer = setTimeout(() => finish({ kind: "missing" }, true), timeoutMs);
|
|
19397
19400
|
timer.unref();
|
|
@@ -23988,14 +23991,14 @@ function handleRead(a, deps) {
|
|
|
23988
23991
|
if (active.size >= READ_OPEN_MAX) return Promise.resolve(refuse(a, 429, tr("leituras abertas demais nesta m\xE1quina")));
|
|
23989
23992
|
const request = deps.request ?? http3.request;
|
|
23990
23993
|
const host = `127.0.0.1:${deps.port}`;
|
|
23991
|
-
return new Promise((
|
|
23994
|
+
return new Promise((resolve15) => {
|
|
23992
23995
|
let out;
|
|
23993
23996
|
let upstream;
|
|
23994
23997
|
let settled = false;
|
|
23995
23998
|
const settle = (r) => {
|
|
23996
23999
|
if (settled) return;
|
|
23997
24000
|
settled = true;
|
|
23998
|
-
|
|
24001
|
+
resolve15(r);
|
|
23999
24002
|
};
|
|
24000
24003
|
const req = request({ host: readHost(deps.host), port: deps.port, method: "GET", path: target.path + target.search, headers: { Host: host, Accept: "*/*" } });
|
|
24001
24004
|
const close = () => {
|
|
@@ -27980,8 +27983,10 @@ var SlotAllocator = class {
|
|
|
27980
27983
|
|
|
27981
27984
|
// shared/room-name.ts
|
|
27982
27985
|
var AGENT_HUB_ROOM_ID = "agent-hub";
|
|
27986
|
+
var GENTLE_SHELL_ROOM_ID = "gentle-shell-delegated";
|
|
27983
27987
|
function roomDisplayName(room) {
|
|
27984
27988
|
if (room.id === AGENT_HUB_ROOM_ID) return tr("Agent Hub");
|
|
27989
|
+
if (room.id === GENTLE_SHELL_ROOM_ID) return tr("Gentle Shell");
|
|
27985
27990
|
if (room.custom && (!room.name.trim() || room.name.trim() === room.id)) return tr("Favoritos");
|
|
27986
27991
|
return room.name;
|
|
27987
27992
|
}
|
|
@@ -28265,6 +28270,7 @@ var Office = class {
|
|
|
28265
28270
|
}
|
|
28266
28271
|
roomName(roomId) {
|
|
28267
28272
|
if (roomId === AGENT_HUB_ROOM_ID) return tr("Agent Hub");
|
|
28273
|
+
if (roomId === GENTLE_SHELL_ROOM_ID) return tr("Gentle Shell");
|
|
28268
28274
|
const custom = this.customRooms.get(roomId);
|
|
28269
28275
|
if (custom) return roomDisplayName({ ...custom, custom: true });
|
|
28270
28276
|
return this.roomNames.get(roomId) ?? roomId.split("/").filter(Boolean).pop() ?? roomId;
|
|
@@ -29183,6 +29189,10 @@ var Office = class {
|
|
|
29183
29189
|
this.roomNames.set(id, tr("Agent Hub"));
|
|
29184
29190
|
continue;
|
|
29185
29191
|
}
|
|
29192
|
+
if (id === GENTLE_SHELL_ROOM_ID) {
|
|
29193
|
+
this.roomNames.set(id, tr("Gentle Shell"));
|
|
29194
|
+
continue;
|
|
29195
|
+
}
|
|
29186
29196
|
const custom = this.customRooms.get(id);
|
|
29187
29197
|
if (custom) {
|
|
29188
29198
|
this.roomNames.set(id, roomDisplayName({ ...custom, custom: true }));
|
|
@@ -30042,7 +30052,7 @@ function createInboxRoutes(service) {
|
|
|
30042
30052
|
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
30053
|
sendJson2(res, r.created ? 201 : 200, { ok: true, item: r.item, created: r.created, ...r.created ? {} : { reopened: r.reopened } });
|
|
30044
30054
|
};
|
|
30045
|
-
const
|
|
30055
|
+
const resolve15 = async (res, id) => {
|
|
30046
30056
|
const r = await service.resolve(id);
|
|
30047
30057
|
if (!r.ok) throw new HttpError(r.status, r.status === 404 ? tr("item n\xE3o encontrado") : r.error);
|
|
30048
30058
|
sendJson2(res, 200, { ok: true, ...r.item ? { item: r.item } : {} });
|
|
@@ -30062,7 +30072,7 @@ function createInboxRoutes(service) {
|
|
|
30062
30072
|
return sendJson2(res, 404, { error: tr("item n\xE3o encontrado") });
|
|
30063
30073
|
}
|
|
30064
30074
|
req.resume();
|
|
30065
|
-
|
|
30075
|
+
resolve15(res, id).catch((err) => fail3(res, err));
|
|
30066
30076
|
} else if (method === "GET" || method === "HEAD") sendJson2(res, 200, service.frame());
|
|
30067
30077
|
else if (method === "POST") post(req, res).catch((err) => fail3(res, err));
|
|
30068
30078
|
else {
|
|
@@ -33268,7 +33278,7 @@ function detectGentleShellAccounts(dirs, opts = {}) {
|
|
|
33268
33278
|
}
|
|
33269
33279
|
|
|
33270
33280
|
// server/sources/gentle-shell/source.ts
|
|
33271
|
-
import { join as
|
|
33281
|
+
import { join as join26, resolve as resolve13, sep as sep5 } from "node:path";
|
|
33272
33282
|
|
|
33273
33283
|
// server/sources/gentle-shell/terminal.ts
|
|
33274
33284
|
var SEEN_MAX4 = 2e4;
|
|
@@ -33382,387 +33392,10 @@ function createGentleShellTerminalParser() {
|
|
|
33382
33392
|
return new GentleShellTerminalParser();
|
|
33383
33393
|
}
|
|
33384
33394
|
|
|
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
33395
|
// server/sources/agent-hub/source.ts
|
|
33763
33396
|
import { closeSync as closeSync6, lstatSync as lstatSync2, openSync as openSync6, readFileSync as readFileSync21, readSync as readSync6, readdirSync as readdirSync15 } from "node:fs";
|
|
33764
33397
|
import { lstat, readdir as readdir3 } from "node:fs/promises";
|
|
33765
|
-
import { basename as basename9, dirname as dirname13, isAbsolute as isAbsolute5, join as
|
|
33398
|
+
import { basename as basename9, dirname as dirname13, isAbsolute as isAbsolute5, join as join25, resolve as resolve11 } from "node:path";
|
|
33766
33399
|
|
|
33767
33400
|
// server/sources/agent-hub/events/agy.ts
|
|
33768
33401
|
function object(value) {
|
|
@@ -33925,7 +33558,7 @@ function adaptAgentHubEvent(agent, text3, offset) {
|
|
|
33925
33558
|
|
|
33926
33559
|
// server/sources/agent-hub/terminal.ts
|
|
33927
33560
|
import { lstatSync, readFileSync as readFileSync20 } from "node:fs";
|
|
33928
|
-
import { join as
|
|
33561
|
+
import { join as join24 } from "node:path";
|
|
33929
33562
|
var SEEN_MAX5 = 2e4;
|
|
33930
33563
|
var MAX_PROMPT_BYTES = 128 * 1024;
|
|
33931
33564
|
var MAX_RESPONSE_BYTES = 128 * 1024;
|
|
@@ -33943,7 +33576,7 @@ function toMs7(v) {
|
|
|
33943
33576
|
}
|
|
33944
33577
|
function readPrompt(jobDir) {
|
|
33945
33578
|
if (!jobDir) return void 0;
|
|
33946
|
-
const path =
|
|
33579
|
+
const path = join24(jobDir, "prompt.txt");
|
|
33947
33580
|
try {
|
|
33948
33581
|
const st = lstatSync(path);
|
|
33949
33582
|
if (!st.isFile() || st.size > MAX_PROMPT_BYTES) return void 0;
|
|
@@ -33954,7 +33587,7 @@ function readPrompt(jobDir) {
|
|
|
33954
33587
|
}
|
|
33955
33588
|
function readResponse(jobDir) {
|
|
33956
33589
|
if (!jobDir) return void 0;
|
|
33957
|
-
const path =
|
|
33590
|
+
const path = join24(jobDir, "response.txt");
|
|
33958
33591
|
try {
|
|
33959
33592
|
const st = lstatSync(path);
|
|
33960
33593
|
if (!st.isFile() || st.size > MAX_RESPONSE_BYTES) return void 0;
|
|
@@ -34267,7 +33900,7 @@ function status(value) {
|
|
|
34267
33900
|
return value === "queued" || value === "running" || value === "succeeded" || value === "failed" || value === "cancelled" ? value : "unknown";
|
|
34268
33901
|
}
|
|
34269
33902
|
function readPrompt2(jobDir) {
|
|
34270
|
-
const path =
|
|
33903
|
+
const path = join25(jobDir, "prompt.txt");
|
|
34271
33904
|
try {
|
|
34272
33905
|
const st = lstatSync2(path);
|
|
34273
33906
|
if (!st.isFile() || st.size > MAX_PROMPT_BYTES2) return void 0;
|
|
@@ -34332,7 +33965,7 @@ function jobFiles(runsDir, now) {
|
|
|
34332
33965
|
const files = [];
|
|
34333
33966
|
for (const entry of entries) {
|
|
34334
33967
|
if (!entry.isDirectory()) continue;
|
|
34335
|
-
const path =
|
|
33968
|
+
const path = join25(runsDir, entry.name, "result.json");
|
|
34336
33969
|
try {
|
|
34337
33970
|
const file = jobFileOf(entry.name, path, lstatSync2(path), now);
|
|
34338
33971
|
if (file) files.push(file);
|
|
@@ -34355,7 +33988,7 @@ async function jobFilesAsync(runsDir, now) {
|
|
|
34355
33988
|
const files = [];
|
|
34356
33989
|
for (let i = 0; i < dirs.length; i += JOB_STAT_BATCH) {
|
|
34357
33990
|
const batch = await Promise.all(dirs.slice(i, i + JOB_STAT_BATCH).map(async (entry) => {
|
|
34358
|
-
const path =
|
|
33991
|
+
const path = join25(runsDir, entry.name, "result.json");
|
|
34359
33992
|
try {
|
|
34360
33993
|
return jobFileOf(entry.name, path, await lstat(path), now);
|
|
34361
33994
|
} catch {
|
|
@@ -34389,7 +34022,7 @@ function officeStatus(job) {
|
|
|
34389
34022
|
}
|
|
34390
34023
|
function deriveProject(cwd, repoRoot, repoName) {
|
|
34391
34024
|
const candidate = repoRoot || cwd;
|
|
34392
|
-
const gitPath =
|
|
34025
|
+
const gitPath = join25(candidate, ".git");
|
|
34393
34026
|
try {
|
|
34394
34027
|
const st = lstatSync2(gitPath);
|
|
34395
34028
|
if (st.isFile()) {
|
|
@@ -34398,11 +34031,11 @@ function deriveProject(cwd, repoRoot, repoName) {
|
|
|
34398
34031
|
if (match) {
|
|
34399
34032
|
let gitDir = match[1].trim();
|
|
34400
34033
|
if (!isAbsolute5(gitDir)) {
|
|
34401
|
-
gitDir =
|
|
34034
|
+
gitDir = resolve11(candidate, gitDir);
|
|
34402
34035
|
}
|
|
34403
34036
|
try {
|
|
34404
|
-
const commonRel = readFileSync21(
|
|
34405
|
-
const commonDir =
|
|
34037
|
+
const commonRel = readFileSync21(join25(gitDir, "commondir"), "utf8").trim();
|
|
34038
|
+
const commonDir = resolve11(gitDir, commonRel);
|
|
34406
34039
|
return basename9(dirname13(commonDir));
|
|
34407
34040
|
} catch {
|
|
34408
34041
|
const wtMatch = /^(.*)[/\\]\.git[/\\]worktrees[/\\][^/\\]+$/.exec(gitDir);
|
|
@@ -34470,7 +34103,7 @@ var AgentHubSource = class {
|
|
|
34470
34103
|
const tracker = this.trackers.get(agentId);
|
|
34471
34104
|
const jobId = tracker ? tracker.job.id : agentId.startsWith("agent-hub:") ? agentId.slice("agent-hub:".length) : void 0;
|
|
34472
34105
|
if (!jobId) return void 0;
|
|
34473
|
-
const path =
|
|
34106
|
+
const path = join25(this.opts.runsDir, jobId, "stdout.log");
|
|
34474
34107
|
try {
|
|
34475
34108
|
if (lstatSync2(path).isFile()) return path;
|
|
34476
34109
|
} catch {
|
|
@@ -34485,7 +34118,7 @@ var AgentHubSource = class {
|
|
|
34485
34118
|
const tracker = this.trackers.get(agentId);
|
|
34486
34119
|
const jobId = tracker ? tracker.job.id : agentId.startsWith("agent-hub:") ? agentId.slice("agent-hub:".length) : void 0;
|
|
34487
34120
|
if (!jobId) return void 0;
|
|
34488
|
-
const jobDir =
|
|
34121
|
+
const jobDir = join25(this.opts.runsDir, jobId);
|
|
34489
34122
|
return createAgentHubTerminalParser({
|
|
34490
34123
|
agent: tracker?.job.agent,
|
|
34491
34124
|
jobDir,
|
|
@@ -34510,8 +34143,8 @@ var AgentHubSource = class {
|
|
|
34510
34143
|
const list = this.opts.listFilesAsync ?? jobFilesAsync;
|
|
34511
34144
|
const files = await Promise.race([
|
|
34512
34145
|
list(this.opts.runsDir, this.now()),
|
|
34513
|
-
new Promise((
|
|
34514
|
-
timer = setTimeout(() =>
|
|
34146
|
+
new Promise((resolve15) => {
|
|
34147
|
+
timer = setTimeout(() => resolve15(void 0), limit);
|
|
34515
34148
|
timer.unref?.();
|
|
34516
34149
|
})
|
|
34517
34150
|
]);
|
|
@@ -34534,7 +34167,7 @@ var AgentHubSource = class {
|
|
|
34534
34167
|
if (!cached || cached.mtimeMs !== file.mtimeMs || cached.size !== file.size) {
|
|
34535
34168
|
let job2;
|
|
34536
34169
|
try {
|
|
34537
|
-
job2 = parseJob(readFileSync21(file.path, "utf8"), file.name, file.mtimeMs,
|
|
34170
|
+
job2 = parseJob(readFileSync21(file.path, "utf8"), file.name, file.mtimeMs, join25(this.opts.runsDir, file.name));
|
|
34538
34171
|
} catch {
|
|
34539
34172
|
job2 = void 0;
|
|
34540
34173
|
}
|
|
@@ -34654,7 +34287,7 @@ var AgentHubSource = class {
|
|
|
34654
34287
|
stats: { toolCalls: 0, tokensIn: 0, tokensOut: 0, subagents: 0 },
|
|
34655
34288
|
model: job.model
|
|
34656
34289
|
});
|
|
34657
|
-
const jobDir =
|
|
34290
|
+
const jobDir = join25(this.opts.runsDir, job.id);
|
|
34658
34291
|
if (job.status === "running" && !tracker.started) {
|
|
34659
34292
|
this.opts.office.addActivity(id, {
|
|
34660
34293
|
id: `${id}#started`,
|
|
@@ -34666,9 +34299,9 @@ var AgentHubSource = class {
|
|
|
34666
34299
|
}, true, { feed: !boot });
|
|
34667
34300
|
tracker.started = true;
|
|
34668
34301
|
}
|
|
34669
|
-
this.readOutput(tracker, id,
|
|
34302
|
+
this.readOutput(tracker, id, join25(jobDir, "stdout.log"), job.agent);
|
|
34670
34303
|
if (terminal) {
|
|
34671
|
-
this.readResponse(tracker, id,
|
|
34304
|
+
this.readResponse(tracker, id, join25(jobDir, "response.txt"), job.updatedAt ?? this.now());
|
|
34672
34305
|
const error = tracker.failure ?? job.error;
|
|
34673
34306
|
this.opts.office.finishMain(id, mappedStatus, error ? truncate(maskSecrets(error), 300) : void 0);
|
|
34674
34307
|
}
|
|
@@ -34777,6 +34410,529 @@ var AgentHubSource = class {
|
|
|
34777
34410
|
}
|
|
34778
34411
|
};
|
|
34779
34412
|
|
|
34413
|
+
// server/sources/gentle-shell/delegation.ts
|
|
34414
|
+
import { execFileSync } from "node:child_process";
|
|
34415
|
+
import { readdirSync as readdirSync16, readlinkSync } from "node:fs";
|
|
34416
|
+
import { basename as basename10, resolve as resolve12 } from "node:path";
|
|
34417
|
+
var START_BEFORE_MS2 = 1e4;
|
|
34418
|
+
var START_AFTER_MS2 = 6e4;
|
|
34419
|
+
var MAX_DEPTH = 32;
|
|
34420
|
+
var PID_ID2 = /:(\d+)$/;
|
|
34421
|
+
var AGENT_BIN = /^(claude|codex)(\.exe)?$/i;
|
|
34422
|
+
function knownAgentPids(agents2) {
|
|
34423
|
+
const out = /* @__PURE__ */ new Set();
|
|
34424
|
+
for (const a of agents2) {
|
|
34425
|
+
if (a.parentId || a.id.startsWith("@")) continue;
|
|
34426
|
+
const m = PID_ID2.exec(a.id);
|
|
34427
|
+
if (m) out.add(Number(m[1]));
|
|
34428
|
+
}
|
|
34429
|
+
return out;
|
|
34430
|
+
}
|
|
34431
|
+
function isGentleShell(args) {
|
|
34432
|
+
return args.slice(0, 2).some((a) => /^(gentle-shell|pi)(\.m?js)?$/.test(basename10(a)) || /[/\\]pi-coding-agent[/\\]/.test(a));
|
|
34433
|
+
}
|
|
34434
|
+
function printMode(args) {
|
|
34435
|
+
return args.some((a) => a === "-p" || a === "--print");
|
|
34436
|
+
}
|
|
34437
|
+
function classifyDelegation(cwd, startedAt2, known, table) {
|
|
34438
|
+
try {
|
|
34439
|
+
const want = resolve12(cwd);
|
|
34440
|
+
const cands = [];
|
|
34441
|
+
for (const pid of table.pids()) {
|
|
34442
|
+
const args = table.args(pid);
|
|
34443
|
+
if (!args || !isGentleShell(args)) continue;
|
|
34444
|
+
const pcwd = table.cwd(pid);
|
|
34445
|
+
if (pcwd && resolve12(pcwd) === want) cands.push(pid);
|
|
34446
|
+
}
|
|
34447
|
+
let use = cands;
|
|
34448
|
+
if (startedAt2 !== void 0) {
|
|
34449
|
+
const near = cands.filter((p) => {
|
|
34450
|
+
const s2 = table.startMs(p);
|
|
34451
|
+
return s2 !== void 0 && s2 >= startedAt2 - START_AFTER_MS2 && s2 <= startedAt2 + START_BEFORE_MS2;
|
|
34452
|
+
});
|
|
34453
|
+
if (near.length) use = near;
|
|
34454
|
+
}
|
|
34455
|
+
if (!use.length) return { delegated: false };
|
|
34456
|
+
const set = new Set(use);
|
|
34457
|
+
const ancestors = (pid) => {
|
|
34458
|
+
const out = [];
|
|
34459
|
+
let p = table.ppid(pid);
|
|
34460
|
+
for (let i = 0; p !== void 0 && p > 1 && i < MAX_DEPTH; i++) {
|
|
34461
|
+
out.push(p);
|
|
34462
|
+
p = table.ppid(p);
|
|
34463
|
+
}
|
|
34464
|
+
return out;
|
|
34465
|
+
};
|
|
34466
|
+
const agentAbove = (pid) => ancestors(pid).some((a) => known.has(a) || AGENT_BIN.test(basename10(table.args(a)?.[0] ?? "")));
|
|
34467
|
+
const roots = /* @__PURE__ */ new Map();
|
|
34468
|
+
for (const pid of use) {
|
|
34469
|
+
let root = pid;
|
|
34470
|
+
for (const a of ancestors(pid)) if (set.has(a)) root = a;
|
|
34471
|
+
const d = printMode(table.args(pid) ?? []) || agentAbove(pid);
|
|
34472
|
+
roots.set(root, (roots.get(root) ?? false) || d);
|
|
34473
|
+
}
|
|
34474
|
+
return { delegated: [...roots.values()].every(Boolean), pid: use[0] };
|
|
34475
|
+
} catch {
|
|
34476
|
+
return { delegated: false };
|
|
34477
|
+
}
|
|
34478
|
+
}
|
|
34479
|
+
var num11 = (s2) => /^\d+$/.test(s2) ? Number(s2) : void 0;
|
|
34480
|
+
function linuxProcTable(proc = realProc) {
|
|
34481
|
+
return {
|
|
34482
|
+
pids: () => {
|
|
34483
|
+
try {
|
|
34484
|
+
return readdirSync16("/proc").flatMap((n2) => num11(n2) !== void 0 ? [Number(n2)] : []);
|
|
34485
|
+
} catch {
|
|
34486
|
+
return [];
|
|
34487
|
+
}
|
|
34488
|
+
},
|
|
34489
|
+
args: (pid) => proc.cmdline(pid)?.split("\0").filter(Boolean),
|
|
34490
|
+
cwd: (pid) => {
|
|
34491
|
+
try {
|
|
34492
|
+
return readlinkSync(`/proc/${pid}/cwd`);
|
|
34493
|
+
} catch {
|
|
34494
|
+
return void 0;
|
|
34495
|
+
}
|
|
34496
|
+
},
|
|
34497
|
+
ppid: (pid) => {
|
|
34498
|
+
const stat3 = proc.stat(pid);
|
|
34499
|
+
if (!stat3) return void 0;
|
|
34500
|
+
return num11(stat3.slice(stat3.lastIndexOf(")") + 1).trim().split(/\s+/)[1] ?? "");
|
|
34501
|
+
},
|
|
34502
|
+
startMs: (pid) => processStartMs(pid, proc)
|
|
34503
|
+
};
|
|
34504
|
+
}
|
|
34505
|
+
function psProcTable(run3 = (c, a) => execFileSync(c, a, { encoding: "utf8", timeout: 1500, stdio: ["ignore", "pipe", "ignore"] })) {
|
|
34506
|
+
let rows2;
|
|
34507
|
+
const load = () => {
|
|
34508
|
+
if (rows2) return rows2;
|
|
34509
|
+
rows2 = /* @__PURE__ */ new Map();
|
|
34510
|
+
const now = Date.now();
|
|
34511
|
+
for (const line2 of run3("ps", ["-axo", "pid=,ppid=,etime=,command="]).split("\n")) {
|
|
34512
|
+
const m = /^\s*(\d+)\s+(\d+)\s+(?:(?:(\d+)-)?(?:(\d+):)?)(\d+):(\d+)\s+(.*)$/.exec(line2);
|
|
34513
|
+
if (!m) continue;
|
|
34514
|
+
const secs = Number(m[3] ?? 0) * 86400 + Number(m[4] ?? 0) * 3600 + Number(m[5]) * 60 + Number(m[6]);
|
|
34515
|
+
rows2.set(Number(m[1]), { ppid: Number(m[2]), startMs: now - secs * 1e3, args: m[7].split(/\s+/).filter(Boolean) });
|
|
34516
|
+
}
|
|
34517
|
+
return rows2;
|
|
34518
|
+
};
|
|
34519
|
+
const cwds = /* @__PURE__ */ new Map();
|
|
34520
|
+
return {
|
|
34521
|
+
pids: () => [...load().keys()],
|
|
34522
|
+
args: (pid) => load().get(pid)?.args,
|
|
34523
|
+
ppid: (pid) => load().get(pid)?.ppid,
|
|
34524
|
+
startMs: (pid) => load().get(pid)?.startMs,
|
|
34525
|
+
cwd: (pid) => {
|
|
34526
|
+
if (!cwds.has(pid)) {
|
|
34527
|
+
try {
|
|
34528
|
+
const out = run3("lsof", ["-a", "-d", "cwd", "-Fn", "-p", String(pid)]);
|
|
34529
|
+
cwds.set(pid, /^n(.+)$/m.exec(out)?.[1]);
|
|
34530
|
+
} catch {
|
|
34531
|
+
cwds.set(pid, void 0);
|
|
34532
|
+
}
|
|
34533
|
+
}
|
|
34534
|
+
return cwds.get(pid);
|
|
34535
|
+
}
|
|
34536
|
+
};
|
|
34537
|
+
}
|
|
34538
|
+
var EMPTY = { pids: () => [], args: () => void 0, cwd: () => void 0, ppid: () => void 0, startMs: () => void 0 };
|
|
34539
|
+
function defaultProcTable(platform = process.platform) {
|
|
34540
|
+
if (platform === "linux") return linuxProcTable();
|
|
34541
|
+
if (platform === "darwin") return psProcTable();
|
|
34542
|
+
return EMPTY;
|
|
34543
|
+
}
|
|
34544
|
+
|
|
34545
|
+
// server/sources/gentle-shell/source.ts
|
|
34546
|
+
var PRESENCE_STALE_MS = 3e4;
|
|
34547
|
+
var FALLBACK_RECENT_MS2 = 30 * 6e4;
|
|
34548
|
+
var WORKING_QUIET_MS2 = 30 * 6e4;
|
|
34549
|
+
var TASK_STALE_MS = 30 * 6e4;
|
|
34550
|
+
var CLOSE_AFTER_MISSING_MS3 = 1500;
|
|
34551
|
+
var BACKLOG_MAX2 = 400;
|
|
34552
|
+
var ACTIVE_TASK = /* @__PURE__ */ new Set(["queued", "running", "waiting", "pending", "starting", "in_progress"]);
|
|
34553
|
+
var MAIN_ROLE2 = tr("Agente principal (Gentle Shell)");
|
|
34554
|
+
var SUB_ROLE2 = tr("Subagente (Gentle Shell)");
|
|
34555
|
+
function roleOf2(raw) {
|
|
34556
|
+
const r = raw?.trim();
|
|
34557
|
+
return r ? `${r[0].toUpperCase()}${r.slice(1)}` : SUB_ROLE2;
|
|
34558
|
+
}
|
|
34559
|
+
var GentleShellSource = class {
|
|
34560
|
+
constructor(opts) {
|
|
34561
|
+
this.opts = opts;
|
|
34562
|
+
this.now = opts.now ?? Date.now;
|
|
34563
|
+
this.tailBytes = opts.tailBytes ?? 2 * 1024 * 1024;
|
|
34564
|
+
const others = opts.accounts.entries();
|
|
34565
|
+
this.detected = detectGentleShellAccounts(opts.dirs, {
|
|
34566
|
+
taken: { shorts: [...others, ...opts.accounts.entriesOf("codex")].map((e) => e.detected.short), colors: [...others, ...opts.accounts.entriesOf("codex")].map((e) => e.detected.color) }
|
|
34567
|
+
});
|
|
34568
|
+
this.entries = opts.accounts.setProviderAccounts(
|
|
34569
|
+
"gentle-shell",
|
|
34570
|
+
opts.dirs.map((dir, i) => ({ dir, detected: this.detected[i] }))
|
|
34571
|
+
);
|
|
34572
|
+
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 }));
|
|
34573
|
+
}
|
|
34574
|
+
opts;
|
|
34575
|
+
provider = "gentle-shell";
|
|
34576
|
+
accs = [];
|
|
34577
|
+
entries = [];
|
|
34578
|
+
detected = [];
|
|
34579
|
+
trackers = /* @__PURE__ */ new Map();
|
|
34580
|
+
timer = null;
|
|
34581
|
+
now;
|
|
34582
|
+
tailBytes;
|
|
34583
|
+
procTable;
|
|
34584
|
+
/** Contas do Gentle Shell (ids finais, no AccountsService). */
|
|
34585
|
+
accountEntries() {
|
|
34586
|
+
return this.entries;
|
|
34587
|
+
}
|
|
34588
|
+
start() {
|
|
34589
|
+
this.boot();
|
|
34590
|
+
this.timer = setInterval(() => this.safePoll(), this.opts.pollMs ?? 1e3);
|
|
34591
|
+
this.timer.unref?.();
|
|
34592
|
+
}
|
|
34593
|
+
/** Reconstrói as sessões abertas sem gerar avisos. Síncrono e curto. */
|
|
34594
|
+
boot() {
|
|
34595
|
+
this.opts.office.beginBoot();
|
|
34596
|
+
try {
|
|
34597
|
+
this.poll(true);
|
|
34598
|
+
} finally {
|
|
34599
|
+
this.opts.office.endBoot();
|
|
34600
|
+
}
|
|
34601
|
+
}
|
|
34602
|
+
stop() {
|
|
34603
|
+
if (this.timer) clearInterval(this.timer);
|
|
34604
|
+
this.timer = null;
|
|
34605
|
+
}
|
|
34606
|
+
sources() {
|
|
34607
|
+
return this.accs.map((acc) => {
|
|
34608
|
+
let sessions = 0;
|
|
34609
|
+
for (const t of this.trackers.values()) if (t.acc === acc && t.kind === "main" && t.inOffice) sessions++;
|
|
34610
|
+
const info = { label: acc.id, provider: "gentle-shell", path: acc.configDir, sessions, ok: !acc.error };
|
|
34611
|
+
if (acc.error) info.error = acc.error;
|
|
34612
|
+
return info;
|
|
34613
|
+
});
|
|
34614
|
+
}
|
|
34615
|
+
transcriptPathOf(agentId) {
|
|
34616
|
+
const t = this.trackers.get(agentId);
|
|
34617
|
+
return t?.inOffice ? t.path : void 0;
|
|
34618
|
+
}
|
|
34619
|
+
terminalParser(agentId) {
|
|
34620
|
+
return this.trackers.has(agentId) ? createGentleShellTerminalParser() : void 0;
|
|
34621
|
+
}
|
|
34622
|
+
watchedTranscripts() {
|
|
34623
|
+
return this.trackers.size;
|
|
34624
|
+
}
|
|
34625
|
+
// ---------------------------------------------------------------- polling
|
|
34626
|
+
safePoll() {
|
|
34627
|
+
try {
|
|
34628
|
+
this.poll(false);
|
|
34629
|
+
} catch (err) {
|
|
34630
|
+
log.warnOnce(`gentle-shell-poll:${errMsg(err)}`, tr("Gentle Shell: falha no ciclo de leitura: {0}", [errMsg(err)]));
|
|
34631
|
+
}
|
|
34632
|
+
}
|
|
34633
|
+
poll(boot = false) {
|
|
34634
|
+
const now = this.now();
|
|
34635
|
+
const seen = /* @__PURE__ */ new Set();
|
|
34636
|
+
for (const acc of this.accs) {
|
|
34637
|
+
for (const [sessionId, workspace] of this.presentSessions(acc, now)) {
|
|
34638
|
+
const key = `${acc.id}:${sessionId}`;
|
|
34639
|
+
let t = this.trackers.get(key);
|
|
34640
|
+
if (!t) {
|
|
34641
|
+
t = this.newTracker(acc, key, "main", sessionId);
|
|
34642
|
+
this.trackers.set(key, t);
|
|
34643
|
+
}
|
|
34644
|
+
if (workspace) t.workspace = workspace;
|
|
34645
|
+
try {
|
|
34646
|
+
this.syncMain(t, now);
|
|
34647
|
+
} catch (err) {
|
|
34648
|
+
log.warnOnce(`gentle-shell-session:${key}:${errMsg(err)}`, tr("Gentle Shell: sess\xE3o {0}: {1}", [key, errMsg(err)]));
|
|
34649
|
+
}
|
|
34650
|
+
seen.add(key);
|
|
34651
|
+
}
|
|
34652
|
+
}
|
|
34653
|
+
for (const [key, t] of [...this.trackers]) {
|
|
34654
|
+
if (t.kind !== "main" || seen.has(key)) continue;
|
|
34655
|
+
t.missingSince ??= now;
|
|
34656
|
+
if (!boot && now - t.missingSince < CLOSE_AFTER_MISSING_MS3) continue;
|
|
34657
|
+
this.leaveMain(t);
|
|
34658
|
+
this.trackers.delete(key);
|
|
34659
|
+
}
|
|
34660
|
+
for (const acc of this.accs) {
|
|
34661
|
+
try {
|
|
34662
|
+
this.syncSubs(acc, now);
|
|
34663
|
+
} catch (err) {
|
|
34664
|
+
log.warnOnce(`gentle-shell-tasks:${acc.id}:${errMsg(err)}`, tr("Gentle Shell: falha ao ler os subagentes: {0}", [errMsg(err)]));
|
|
34665
|
+
}
|
|
34666
|
+
}
|
|
34667
|
+
}
|
|
34668
|
+
/** Sessões abertas de uma conta (id → projeto da presença, quando houver). */
|
|
34669
|
+
presentSessions(acc, now) {
|
|
34670
|
+
const out = /* @__PURE__ */ new Map();
|
|
34671
|
+
acc.index.refresh();
|
|
34672
|
+
const presence = readPresence(acc.dir);
|
|
34673
|
+
if (presence) {
|
|
34674
|
+
const fresh = presence.filter((p) => now - p.heartbeat <= PRESENCE_STALE_MS);
|
|
34675
|
+
const known = new Set(fresh.flatMap((p) => p.sessionId ? [p.sessionId] : []));
|
|
34676
|
+
for (const p of fresh) {
|
|
34677
|
+
const id = this.sessionOf(acc, p, known);
|
|
34678
|
+
if (id) {
|
|
34679
|
+
out.set(id, p.workspace);
|
|
34680
|
+
known.add(id);
|
|
34681
|
+
}
|
|
34682
|
+
}
|
|
34683
|
+
return out;
|
|
34684
|
+
}
|
|
34685
|
+
if (now - acc.recentAt >= 1e4) {
|
|
34686
|
+
acc.recentAt = now;
|
|
34687
|
+
acc.recent = new Map(acc.index.all().map((f) => [f.sessionId, f.mtimeMs]));
|
|
34688
|
+
}
|
|
34689
|
+
for (const [sessionId, mtime] of acc.recent) {
|
|
34690
|
+
const t = this.trackers.get(`${acc.id}:${sessionId}`);
|
|
34691
|
+
if (now - Math.max(mtime, t?.lastWriteAt ?? 0) <= FALLBACK_RECENT_MS2) out.set(sessionId, void 0);
|
|
34692
|
+
}
|
|
34693
|
+
return out;
|
|
34694
|
+
}
|
|
34695
|
+
/** Sessão de uma encarnação: a do discovery ou, sem ela, o transcript mais recente do projeto ainda sem dono. */
|
|
34696
|
+
sessionOf(acc, p, taken) {
|
|
34697
|
+
if (p.sessionId) return p.sessionId;
|
|
34698
|
+
if (!p.workspace) return void 0;
|
|
34699
|
+
return acc.index.latestFor(p.workspace, taken)?.sessionId;
|
|
34700
|
+
}
|
|
34701
|
+
newTracker(acc, key, kind, rawId) {
|
|
34702
|
+
return { key, acc, kind, rawId, state: createPiState(), backlog: [], inOffice: false, status: kind === "sub" ? "working" : "idle", statusAt: 0 };
|
|
34703
|
+
}
|
|
34704
|
+
// ---------------------------------------------------------------- principais
|
|
34705
|
+
syncMain(t, now) {
|
|
34706
|
+
delete t.missingSince;
|
|
34707
|
+
if (t.inOffice && !this.opts.office.has(t.key)) t.inOffice = false;
|
|
34708
|
+
if (!t.tail) {
|
|
34709
|
+
const file = t.acc.index.find(t.rawId);
|
|
34710
|
+
if (!file) return;
|
|
34711
|
+
this.load(t, file.path);
|
|
34712
|
+
} else {
|
|
34713
|
+
this.pump(t);
|
|
34714
|
+
}
|
|
34715
|
+
const cwd = t.state.cwd ?? t.workspace;
|
|
34716
|
+
if (cwd && !t.inOffice && t.tail) this.enter(t, cwd, now);
|
|
34717
|
+
if (t.inOffice) {
|
|
34718
|
+
this.quietCheck(t, now);
|
|
34719
|
+
this.opts.office.fillWorkingActivity(t.key);
|
|
34720
|
+
}
|
|
34721
|
+
}
|
|
34722
|
+
enter(t, cwd, now) {
|
|
34723
|
+
const office2 = this.opts.office;
|
|
34724
|
+
const delegated = this.delegatedOf(t, cwd);
|
|
34725
|
+
office2.addMain({
|
|
34726
|
+
id: t.key,
|
|
34727
|
+
provider: "gentle-shell",
|
|
34728
|
+
account: t.acc.id,
|
|
34729
|
+
sessionId: t.rawId,
|
|
34730
|
+
cwd,
|
|
34731
|
+
...delegated ? { roomId: GENTLE_SHELL_ROOM_ID, project: deriveProject(cwd) } : {},
|
|
34732
|
+
role: MAIN_ROLE2,
|
|
34733
|
+
startedAt: t.state.startedAt ?? t.state.firstAt ?? now,
|
|
34734
|
+
status: t.status,
|
|
34735
|
+
waitingFor: t.waitingFor
|
|
34736
|
+
});
|
|
34737
|
+
t.inOffice = office2.has(t.key);
|
|
34738
|
+
if (!t.inOffice) return;
|
|
34739
|
+
office2.setStatus(t.key, t.status, t.waitingFor);
|
|
34740
|
+
this.flushBacklog(t);
|
|
34741
|
+
this.applySummary(t);
|
|
34742
|
+
}
|
|
34743
|
+
/** Veredito de sessão delegada: uma varredura de processos por sessão, guardada no tracker. */
|
|
34744
|
+
delegatedOf(t, cwd) {
|
|
34745
|
+
if (t.delegated !== void 0) return t.delegated;
|
|
34746
|
+
this.procTable ??= this.opts.procTable ?? defaultProcTable();
|
|
34747
|
+
const known = knownAgentPids(this.opts.office.list());
|
|
34748
|
+
for (const o of this.trackers.values()) if (o.pid !== void 0 && o.delegated !== void 0) known.add(o.pid);
|
|
34749
|
+
const r = classifyDelegation(cwd, t.state.startedAt ?? t.state.firstAt, known, this.procTable);
|
|
34750
|
+
t.delegated = r.delegated;
|
|
34751
|
+
t.pid = r.pid;
|
|
34752
|
+
return r.delegated;
|
|
34753
|
+
}
|
|
34754
|
+
leaveMain(t) {
|
|
34755
|
+
if (!t.inOffice) return;
|
|
34756
|
+
this.opts.office.closeMain(t.key);
|
|
34757
|
+
t.inOffice = false;
|
|
34758
|
+
}
|
|
34759
|
+
// ---------------------------------------------------------------- subagentes
|
|
34760
|
+
syncSubs(acc, now) {
|
|
34761
|
+
const tasks = acc.tasks.read();
|
|
34762
|
+
const active2 = /* @__PURE__ */ new Map();
|
|
34763
|
+
for (const task of tasks) {
|
|
34764
|
+
if (!ACTIVE_TASK.has(task.status)) continue;
|
|
34765
|
+
if (now - (task.lastAt ?? task.startedAt ?? 0) > TASK_STALE_MS) continue;
|
|
34766
|
+
active2.set(`${acc.id}:${task.id}`, task);
|
|
34767
|
+
}
|
|
34768
|
+
for (const [key, task] of active2) {
|
|
34769
|
+
const parent = this.trackers.get(`${acc.id}:${task.parentSessionId}`);
|
|
34770
|
+
if (!parent?.inOffice || this.opts.office.isSubDone(parent.key)) continue;
|
|
34771
|
+
let t = this.trackers.get(key);
|
|
34772
|
+
if (!t) {
|
|
34773
|
+
t = this.newTracker(acc, key, "sub", task.id);
|
|
34774
|
+
this.trackers.set(key, t);
|
|
34775
|
+
}
|
|
34776
|
+
t.task = task;
|
|
34777
|
+
this.syncSub(t, parent, now);
|
|
34778
|
+
}
|
|
34779
|
+
for (const [key, t] of [...this.trackers]) {
|
|
34780
|
+
if (t.kind !== "sub" || t.acc !== acc) continue;
|
|
34781
|
+
const parent = this.trackers.get(`${acc.id}:${t.task?.parentSessionId}`);
|
|
34782
|
+
if (active2.has(key) && parent?.inOffice) continue;
|
|
34783
|
+
if (t.inOffice) this.opts.office.completeSub(t.key);
|
|
34784
|
+
this.trackers.delete(key);
|
|
34785
|
+
}
|
|
34786
|
+
}
|
|
34787
|
+
syncSub(t, parent, now) {
|
|
34788
|
+
const task = t.task;
|
|
34789
|
+
const path = this.subPath(t.acc, task);
|
|
34790
|
+
if (path && path !== t.path) this.load(t, path);
|
|
34791
|
+
else if (t.tail) this.pump(t);
|
|
34792
|
+
if (!t.inOffice) {
|
|
34793
|
+
const added = this.opts.office.addSub({
|
|
34794
|
+
id: t.key,
|
|
34795
|
+
parentId: parent.key,
|
|
34796
|
+
sessionId: task.id,
|
|
34797
|
+
role: roleOf2(task.agent),
|
|
34798
|
+
title: task.label,
|
|
34799
|
+
background: task.mode === "background",
|
|
34800
|
+
startedAt: task.startedAt ?? t.state.firstAt ?? now
|
|
34801
|
+
});
|
|
34802
|
+
if (!added) return;
|
|
34803
|
+
t.inOffice = true;
|
|
34804
|
+
this.flushBacklog(t);
|
|
34805
|
+
}
|
|
34806
|
+
if (this.opts.office.isSubDone(t.key)) this.opts.office.reactivateSub(t.key);
|
|
34807
|
+
this.applySummary(t);
|
|
34808
|
+
}
|
|
34809
|
+
/** Transcript do subagente (só dentro das pastas de sessões do Gentle Shell). */
|
|
34810
|
+
subPath(acc, task) {
|
|
34811
|
+
if (!task.sessionPath) return void 0;
|
|
34812
|
+
const p = resolve13(task.sessionPath);
|
|
34813
|
+
const roots = [join26(resolve13(acc.dir), SUB_SESSIONS_DIR), join26(resolve13(acc.dir), SESSIONS_DIR2)];
|
|
34814
|
+
return p.endsWith(".jsonl") && roots.some((r) => p.startsWith(r + sep5)) ? p : void 0;
|
|
34815
|
+
}
|
|
34816
|
+
// ---------------------------------------------------------------- transcript
|
|
34817
|
+
/** Lê o começo (cwd, título, modelo) e a janela do fim do transcript. */
|
|
34818
|
+
load(t, path) {
|
|
34819
|
+
const head = parsePiHead(readHeadLines(path));
|
|
34820
|
+
const tail = new FileTail(path);
|
|
34821
|
+
tail.seekTail(this.tailBytes);
|
|
34822
|
+
t.tail = tail;
|
|
34823
|
+
t.path = path;
|
|
34824
|
+
t.state = createPiState();
|
|
34825
|
+
t.state.sessionId = head.sessionId;
|
|
34826
|
+
t.state.cwd = head.cwd;
|
|
34827
|
+
t.state.startedAt = head.startedAt;
|
|
34828
|
+
t.state.model = head.model;
|
|
34829
|
+
t.state.title = head.title;
|
|
34830
|
+
t.backlog = [];
|
|
34831
|
+
for (let i = 0; i < 64; i++) {
|
|
34832
|
+
const r = tail.read();
|
|
34833
|
+
for (const line2 of r.lines) this.apply(t, parsePiLine(t.state, line2, { idPrefix: t.key, now: this.now() }), false);
|
|
34834
|
+
if (!r.more) break;
|
|
34835
|
+
}
|
|
34836
|
+
t.lastWriteAt = tail.mtimeMs;
|
|
34837
|
+
if (t.inOffice) {
|
|
34838
|
+
this.flushBacklog(t);
|
|
34839
|
+
this.statusToOffice(t);
|
|
34840
|
+
}
|
|
34841
|
+
}
|
|
34842
|
+
pump(t) {
|
|
34843
|
+
const tail = t.tail;
|
|
34844
|
+
if (!tail) return;
|
|
34845
|
+
for (let i = 0; i < 4; i++) {
|
|
34846
|
+
let r;
|
|
34847
|
+
try {
|
|
34848
|
+
r = tail.read();
|
|
34849
|
+
} catch (err) {
|
|
34850
|
+
log.warnOnce(`gentle-shell-read:${t.key}`, tr("Gentle Shell: transcript de {0} ileg\xEDvel ({1}).", [t.key, errMsg(err)]));
|
|
34851
|
+
return;
|
|
34852
|
+
}
|
|
34853
|
+
if (r.missing) {
|
|
34854
|
+
delete t.tail;
|
|
34855
|
+
delete t.path;
|
|
34856
|
+
return;
|
|
34857
|
+
}
|
|
34858
|
+
t.lastWriteAt = tail.mtimeMs;
|
|
34859
|
+
if (r.reset) {
|
|
34860
|
+
this.load(t, tail.path);
|
|
34861
|
+
return;
|
|
34862
|
+
}
|
|
34863
|
+
for (const line2 of r.lines) this.apply(t, parsePiLine(t.state, line2, { idPrefix: t.key, now: this.now() }), true);
|
|
34864
|
+
if (r.lines.length) this.applySummary(t);
|
|
34865
|
+
if (!r.more) break;
|
|
34866
|
+
}
|
|
34867
|
+
}
|
|
34868
|
+
/** Aplica um resultado de linha: ao vivo vai direto ao escritório; na carga inicial, fica no backlog. */
|
|
34869
|
+
apply(t, r, live) {
|
|
34870
|
+
if (t.kind === "main") {
|
|
34871
|
+
for (const sig of r.signals) {
|
|
34872
|
+
switch (sig.type) {
|
|
34873
|
+
case "turnStart":
|
|
34874
|
+
this.decide(t, "working", r.at, void 0, live);
|
|
34875
|
+
break;
|
|
34876
|
+
case "turnEnd":
|
|
34877
|
+
this.decide(t, "idle", r.at, void 0, live);
|
|
34878
|
+
break;
|
|
34879
|
+
case "waiting":
|
|
34880
|
+
this.decide(t, "waiting", r.at, sig.reason, live);
|
|
34881
|
+
break;
|
|
34882
|
+
case "progress":
|
|
34883
|
+
if (t.status === "waiting") this.decide(t, "working", r.at, void 0, live);
|
|
34884
|
+
break;
|
|
34885
|
+
}
|
|
34886
|
+
}
|
|
34887
|
+
}
|
|
34888
|
+
if (!live || !t.inOffice) {
|
|
34889
|
+
if (r.activities.length) {
|
|
34890
|
+
t.backlog.push(r);
|
|
34891
|
+
if (t.backlog.length > BACKLOG_MAX2) t.backlog.splice(0, t.backlog.length - BACKLOG_MAX2);
|
|
34892
|
+
}
|
|
34893
|
+
return;
|
|
34894
|
+
}
|
|
34895
|
+
this.toOffice(t, r, true);
|
|
34896
|
+
}
|
|
34897
|
+
toOffice(t, r, live) {
|
|
34898
|
+
for (const a of r.activities) this.opts.office.addActivity(t.key, a.activity, a.current, { feed: live });
|
|
34899
|
+
}
|
|
34900
|
+
flushBacklog(t) {
|
|
34901
|
+
const backlog = t.backlog;
|
|
34902
|
+
t.backlog = [];
|
|
34903
|
+
for (const r of backlog) this.toOffice(t, r, false);
|
|
34904
|
+
}
|
|
34905
|
+
/** Muda o status por uma borda do transcript: informação mais velha que a última decisão não vale. */
|
|
34906
|
+
decide(t, status2, at, waitingFor, live) {
|
|
34907
|
+
if (at < t.statusAt) return;
|
|
34908
|
+
t.statusAt = at;
|
|
34909
|
+
t.status = status2;
|
|
34910
|
+
if (waitingFor) t.waitingFor = waitingFor;
|
|
34911
|
+
else delete t.waitingFor;
|
|
34912
|
+
if (live) this.statusToOffice(t);
|
|
34913
|
+
}
|
|
34914
|
+
statusToOffice(t) {
|
|
34915
|
+
if (t.inOffice && t.kind === "main") this.opts.office.setStatus(t.key, t.status, t.waitingFor);
|
|
34916
|
+
}
|
|
34917
|
+
/** 'working' sem nenhuma escrita por muito tempo (turno morto num crash): vira 'idle'. */
|
|
34918
|
+
quietCheck(t, now) {
|
|
34919
|
+
if (t.status !== "working") return;
|
|
34920
|
+
if (now - Math.max(t.lastWriteAt ?? 0, t.statusAt) > WORKING_QUIET_MS2) this.decide(t, "idle", now, void 0, true);
|
|
34921
|
+
}
|
|
34922
|
+
applySummary(t) {
|
|
34923
|
+
if (!t.inOffice) return;
|
|
34924
|
+
const s2 = t.state;
|
|
34925
|
+
const summary = { tasks: s2.tasks, stats: { ...s2.stats } };
|
|
34926
|
+
const title = t.kind === "sub" ? t.task?.label ?? s2.title : s2.title;
|
|
34927
|
+
if (title) summary.title = title;
|
|
34928
|
+
const model = s2.model ?? t.task?.model;
|
|
34929
|
+
if (model) summary.model = model;
|
|
34930
|
+
if (s2.firstAt !== void 0) summary.firstAt = s2.firstAt;
|
|
34931
|
+
if (s2.lastAt !== void 0) summary.lastAt = s2.lastAt;
|
|
34932
|
+
this.opts.office.applyTranscript(t.key, summary);
|
|
34933
|
+
}
|
|
34934
|
+
};
|
|
34935
|
+
|
|
34780
34936
|
// server/build.ts
|
|
34781
34937
|
import { readFileSync as readFileSync22, statSync as statSync21 } from "node:fs";
|
|
34782
34938
|
import { join as join27 } from "node:path";
|
|
@@ -35046,8 +35202,8 @@ import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync16 } from "nod
|
|
|
35046
35202
|
import { dirname as dirname15, join as join29 } from "node:path";
|
|
35047
35203
|
|
|
35048
35204
|
// 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
|
|
35205
|
+
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";
|
|
35206
|
+
import { isAbsolute as isAbsolute6, join as join28, relative as relative3, resolve as resolve14 } from "node:path";
|
|
35051
35207
|
function layoutOf(dir) {
|
|
35052
35208
|
return {
|
|
35053
35209
|
dir,
|
|
@@ -35089,10 +35245,10 @@ async function startUpdate(o) {
|
|
|
35089
35245
|
if (lockHolder(o.layout, o.alive) !== void 0) return { status: 409, error: tr("j\xE1 est\xE1 rodando uma atualiza\xE7\xE3o") };
|
|
35090
35246
|
const c = updateCommand({ bin: o.layout.bin, platform: o.platform, env: o.env, now: o.now });
|
|
35091
35247
|
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)
|
|
35248
|
+
const failure = await new Promise((resolve15) => {
|
|
35249
|
+
child.once?.("error", (err) => resolve15(err));
|
|
35250
|
+
child.once?.("spawn", () => resolve15(void 0));
|
|
35251
|
+
if (!child.once) resolve15(void 0);
|
|
35096
35252
|
});
|
|
35097
35253
|
if (failure) {
|
|
35098
35254
|
try {
|
|
@@ -35849,7 +36005,7 @@ function detectProviders(env, find = {}) {
|
|
|
35849
36005
|
}
|
|
35850
36006
|
|
|
35851
36007
|
// server/spawn/attachments-prune.ts
|
|
35852
|
-
import { lstatSync as lstatSync3, readdirSync as
|
|
36008
|
+
import { lstatSync as lstatSync3, readdirSync as readdirSync18, rmSync as rmSync7 } from "node:fs";
|
|
35853
36009
|
import { join as join31 } from "node:path";
|
|
35854
36010
|
var ATTACHMENT_DIR_RE = /^\d{8}-\d{6}-[0-9a-f]+$/;
|
|
35855
36011
|
var DAY_MS2 = 864e5;
|
|
@@ -35860,7 +36016,7 @@ function pruneAttachments(root, days, now = Date.now(), remove = (p) => rmSync7(
|
|
|
35860
36016
|
const limit = now - days * DAY_MS2;
|
|
35861
36017
|
let names2;
|
|
35862
36018
|
try {
|
|
35863
|
-
names2 =
|
|
36019
|
+
names2 = readdirSync18(root);
|
|
35864
36020
|
} catch {
|
|
35865
36021
|
return out;
|
|
35866
36022
|
}
|