duckhunt-runner 0.10.2 → 0.12.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/README.md +141 -38
- package/dist/announced-capabilities.d.ts +10 -0
- package/dist/announced-capabilities.d.ts.map +1 -0
- package/dist/announced-capabilities.js +27 -0
- package/dist/announced-capabilities.js.map +1 -0
- package/dist/aws-env.d.ts +21 -0
- package/dist/aws-env.d.ts.map +1 -0
- package/dist/aws-env.js +80 -0
- package/dist/aws-env.js.map +1 -0
- package/dist/aws.d.ts.map +1 -1
- package/dist/aws.js +3 -2
- package/dist/aws.js.map +1 -1
- package/dist/claim.d.ts +14 -0
- package/dist/claim.d.ts.map +1 -1
- package/dist/claim.js +40 -3
- package/dist/claim.js.map +1 -1
- package/dist/claude-args.d.ts +3 -1
- package/dist/claude-args.d.ts.map +1 -1
- package/dist/claude-args.js +19 -4
- package/dist/claude-args.js.map +1 -1
- package/dist/claude.d.ts +7 -1
- package/dist/claude.d.ts.map +1 -1
- package/dist/claude.js +33 -7
- package/dist/claude.js.map +1 -1
- package/dist/config.d.ts +13 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +23 -0
- package/dist/config.js.map +1 -1
- package/dist/conversation-gc.d.ts +9 -2
- package/dist/conversation-gc.d.ts.map +1 -1
- package/dist/conversation-gc.js +13 -6
- package/dist/conversation-gc.js.map +1 -1
- package/dist/daemon.d.ts +8 -1
- package/dist/daemon.d.ts.map +1 -1
- package/dist/daemon.js +173 -49
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +11 -3
- package/dist/index.js.map +1 -1
- package/dist/logout.d.ts +16 -0
- package/dist/logout.d.ts.map +1 -0
- package/dist/logout.js +78 -0
- package/dist/logout.js.map +1 -0
- package/dist/machine.d.ts +18 -0
- package/dist/machine.d.ts.map +1 -0
- package/dist/machine.js +52 -0
- package/dist/machine.js.map +1 -0
- package/dist/oauth.d.ts +4 -0
- package/dist/oauth.d.ts.map +1 -1
- package/dist/oauth.js +49 -4
- package/dist/oauth.js.map +1 -1
- package/dist/repos.d.ts.map +1 -1
- package/dist/repos.js +9 -3
- package/dist/repos.js.map +1 -1
- package/dist/run-mcp-config.d.ts +7 -0
- package/dist/run-mcp-config.d.ts.map +1 -1
- package/dist/run-mcp-config.js +34 -0
- package/dist/run-mcp-config.js.map +1 -1
- package/dist/secret-paths.d.ts +8 -0
- package/dist/secret-paths.d.ts.map +1 -0
- package/dist/secret-paths.js +77 -0
- package/dist/secret-paths.js.map +1 -0
- package/dist/server-state.d.ts +40 -0
- package/dist/server-state.d.ts.map +1 -0
- package/dist/server-state.js +76 -0
- package/dist/server-state.js.map +1 -0
- package/dist/status.d.ts +3 -0
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +58 -8
- package/dist/status.js.map +1 -1
- package/dist/worktree.d.ts +9 -0
- package/dist/worktree.d.ts.map +1 -1
- package/dist/worktree.js +14 -6
- package/dist/worktree.js.map +1 -1
- package/package.json +1 -1
package/dist/conversation-gc.js
CHANGED
|
@@ -7,9 +7,12 @@
|
|
|
7
7
|
// contiene NO se borra nunca; se conserva y se avisa en el log. con runs en paralelo el gc corre
|
|
8
8
|
// mientras otros slots trabajan: nunca toca el worktree de un run en vuelo (lo reclamó este daemon
|
|
9
9
|
// y el server aún podría darlo por cerrado) y cada borrado va bajo el lock git de su checkout.
|
|
10
|
+
// worktree_report (0.11.0, t#465 P12): de cada conversación que se conserva por guardar trabajo sale un
|
|
11
|
+
// recuento (KeptWorktree: ficheros sin commitear y commits sin subir, nunca paths) que el daemon anuncia
|
|
12
|
+
// en cada claim hasta la siguiente recogida; el hilo de esa conversación lo enseña con «pedir commit».
|
|
10
13
|
import fs from 'node:fs';
|
|
11
14
|
import path from 'node:path';
|
|
12
|
-
import { CONVERSATION_WORKTREE_PREFIX, RUN_WORKTREE_PREFIX, removeCleanWorktree,
|
|
15
|
+
import { CONVERSATION_WORKTREE_PREFIX, RUN_WORKTREE_PREFIX, describeWork, removeCleanWorktree, worktreeWork, worktreesDir } from './worktree.js';
|
|
13
16
|
// inactividad tras la que un worktree se puede borrar aunque el server lo dé por abierto
|
|
14
17
|
// (AGENT_CONVERSATION_IDLE_TTL_MS del server).
|
|
15
18
|
export const CONVERSATION_IDLE_TTL_MS = 7 * 24 * 60 * 60_000;
|
|
@@ -50,26 +53,30 @@ export function chunk(items, size = CONVERSATIONS_QUERY_MAX) {
|
|
|
50
53
|
}
|
|
51
54
|
/**
|
|
52
55
|
* borra los worktrees seleccionados que no guarden trabajo. secuencial (git bloquea el repo por
|
|
53
|
-
* operación). devuelve cuántos
|
|
56
|
+
* operación). devuelve cuántos borró y el recuento de las conversaciones conservadas; conservar o
|
|
57
|
+
* fallar se loguea, nunca lanza.
|
|
54
58
|
*/
|
|
55
59
|
export async function removeWorktrees(targets, env) {
|
|
56
|
-
|
|
60
|
+
const out = { removed: 0, kept: [] };
|
|
57
61
|
// i/o secuencial: cada `git worktree remove` toca el mismo repositorio.
|
|
58
62
|
for (const c of targets) {
|
|
59
63
|
const name = path.basename(c.dir);
|
|
60
64
|
try {
|
|
61
|
-
const
|
|
65
|
+
const work = await worktreeWork(c.dir, env);
|
|
66
|
+
const keep = describeWork(work);
|
|
62
67
|
if (keep) {
|
|
63
68
|
console.warn(`[runner] worktree ${c.dir} conservado: ${keep} (bórralo a mano con \`git worktree remove\` cuando ya no lo necesites)`);
|
|
69
|
+
if (c.kind === 'conversation')
|
|
70
|
+
out.kept.push({ runId: c.runId, ...work });
|
|
64
71
|
continue;
|
|
65
72
|
}
|
|
66
73
|
await removeCleanWorktree(c.repoPath, c.dir, env);
|
|
67
|
-
removed++;
|
|
74
|
+
out.removed++;
|
|
68
75
|
}
|
|
69
76
|
catch (err) {
|
|
70
77
|
console.error(`[runner] no se pudo recoger el worktree ${name}: ${err.message}`);
|
|
71
78
|
}
|
|
72
79
|
}
|
|
73
|
-
return
|
|
80
|
+
return out;
|
|
74
81
|
}
|
|
75
82
|
//# sourceMappingURL=conversation-gc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation-gc.js","sourceRoot":"","sources":["../src/conversation-gc.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,wFAAwF;AACxF,qFAAqF;AACrF,oFAAoF;AACpF,oGAAoG;AACpG,kGAAkG;AAClG,iGAAiG;AACjG,mGAAmG;AACnG,+FAA+F;
|
|
1
|
+
{"version":3,"file":"conversation-gc.js","sourceRoot":"","sources":["../src/conversation-gc.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,wFAAwF;AACxF,qFAAqF;AACrF,oFAAoF;AACpF,oGAAoG;AACpG,kGAAkG;AAClG,iGAAiG;AACjG,mGAAmG;AACnG,+FAA+F;AAC/F,wGAAwG;AACxG,yGAAyG;AACzG,uGAAuG;AAEvG,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,4BAA4B,EAAE,mBAAmB,EAAE,YAAY,EAAE,mBAAmB,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAGjJ,yFAAyF;AACzF,+CAA+C;AAC/C,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC;AAC7D,uDAAuD;AACvD,MAAM,CAAC,MAAM,2BAA2B,GAAG,EAAE,GAAG,MAAM,CAAC;AACvD,2EAA2E;AAC3E,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAU3C,MAAM,YAAY,GAAG,OAAO,CAAC;AAE7B,SAAS,WAAW,CAAC,QAAgB,EAAE,IAAY;IACjD,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,4BAA4B,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IAClI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IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;YAC5C,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;YAChC,IAAI,IAAI,EAAE,CAAC;gBACT,OAAO,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,GAAG,gBAAgB,IAAI,yEAAyE,CAAC,CAAC;gBACtI,IAAI,CAAC,CAAC,IAAI,KAAK,cAAc;oBAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;gBAC1E,SAAS;YACX,CAAC;YACD,MAAM,mBAAmB,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;YAClD,GAAG,CAAC,OAAO,EAAE,CAAC;QAChB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,2CAA2C,IAAI,KAAM,GAAa,CAAC,OAAO,EAAE,CAAC,CAAC;QAC9F,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/daemon.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type RunnerConfig } from './config.js';
|
|
2
|
+
export declare const EXIT_CODE_UNPAIRED = 78;
|
|
2
3
|
export interface DaemonOptions {
|
|
3
4
|
verboseLog?: boolean;
|
|
4
5
|
}
|
|
@@ -26,6 +27,9 @@ export declare class RunnerDaemon {
|
|
|
26
27
|
private lastRepoHealthAt;
|
|
27
28
|
private repoHealthRun;
|
|
28
29
|
private runConfigDeny;
|
|
30
|
+
private secretDeny;
|
|
31
|
+
private keptWorktrees;
|
|
32
|
+
private serverState;
|
|
29
33
|
constructor(cfg: RunnerConfig, opts?: DaemonOptions);
|
|
30
34
|
private get slots();
|
|
31
35
|
private api;
|
|
@@ -34,6 +38,10 @@ export declare class RunnerDaemon {
|
|
|
34
38
|
/** loop principal: gc → claim → ejecutar en un slot libre → repetir, hasta SIGINT/SIGTERM.
|
|
35
39
|
* devuelve el exit code tras esperar el cierre de los runs en vuelo. */
|
|
36
40
|
run(): Promise<number>;
|
|
41
|
+
private adoptMachineId;
|
|
42
|
+
private stopUnpaired;
|
|
43
|
+
private recordServerState;
|
|
44
|
+
private replacementDelivered;
|
|
37
45
|
private idle;
|
|
38
46
|
private installSignalHandlers;
|
|
39
47
|
private claim;
|
|
@@ -47,7 +55,6 @@ export declare class RunnerDaemon {
|
|
|
47
55
|
private prepareWorkdir;
|
|
48
56
|
private holdCwd;
|
|
49
57
|
private startHeartbeat;
|
|
50
|
-
private envFor;
|
|
51
58
|
private executeRun;
|
|
52
59
|
private runAttempts;
|
|
53
60
|
private spawnClaude;
|
package/dist/daemon.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"daemon.d.ts","sourceRoot":"","sources":["../src/daemon.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"daemon.d.ts","sourceRoot":"","sources":["../src/daemon.ts"],"names":[],"mappings":"AA4EA,OAAO,EAYL,KAAK,YAAY,EAElB,MAAM,aAAa,CAAC;AA2DrB,eAAO,MAAM,kBAAkB,KAAK,CAAC;AA2BrC,MAAM,WAAW,aAAa;IAC5B,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAKD,qBAAa,YAAY;IA4CrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IA3CvB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAoB;IACzC,OAAO,CAAC,MAAM,CAAuD;IACrE,OAAO,CAAC,MAAM,CAAS;IAGvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;IAE9C,OAAO,CAAC,GAAG,CAAc;IAEzB,OAAO,CAAC,UAAU,CAAmB;IAErC,OAAO,CAAC,iBAAiB,CAAS;IAElC,OAAO,CA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ist/daemon.js
CHANGED
|
@@ -44,26 +44,52 @@
|
|
|
44
44
|
// arrancar se borran los que dejó un daemon muerto. y antes de cada segmento con shell de lectura se
|
|
45
45
|
// revisan los symlinks commiteados del cwd: si alguno sale de él, ese segmento va sin shell
|
|
46
46
|
// (read-shell-guard.ts; los paths solo al log local, al feed el recuento).
|
|
47
|
+
// - ciclo de vida (0.11.0, t#465 P12): reclama con el machine id de la config (machine.ts; lo genera al
|
|
48
|
+
// arrancar si no lo hay) y, hasta su primer claim aceptado, con el client_id que su `login` reemplaza:
|
|
49
|
+
// duckhunt adopta así la fila de esta máquina en vez de dejar una fantasma. guarda lo que el server dice
|
|
50
|
+
// de ella (bloque runner, motivo de la cabecera, worktrees conservados) en server-state.json para
|
|
51
|
+
// `status`. con todos los slots ocupados el loop no reclama: la adopción de un `login` llega con el
|
|
52
|
+
// siguiente claim (al liberarse uno); mientras, los latidos ya van con la credencial nueva. si el refresh
|
|
53
|
+
// de la credencial se rechaza (desvinculada desde duckhunt o con `logout`, revocada o caducada), lo vea el
|
|
54
|
+
// claim o el latido de un run, para: corta sus runs, no reintenta y sale con EXIT_CODE_UNPAIRED (un
|
|
55
|
+
// servicio puede no reiniciarlo con ese código: sin `login` no vuelve).
|
|
56
|
+
// - endurecimiento de lectura (0.11.0): secret_paths (secret-paths.ts) al deny de todo kit de lectura,
|
|
57
|
+
// aws_strict (aws-env.ts: una cuenta sin mapear corre con la aws vacía) y seed_budget (claude-args.ts).
|
|
58
|
+
// el gc anuncia en cada claim lo que conservó por guardar trabajo (worktree_report, recuentos; una
|
|
59
|
+
// conversación que vuelve a reclamarse deja de anunciarse en el acto, sin esperar al siguiente gc). al
|
|
60
|
+
// arrancar barre una vez los mcp-config que los daemons < 0.10.2 dejaban en el tmpdir.
|
|
61
|
+
// - modelo por run (0.12.0, t#465): anuncia `model` si el cli lista --model (announced-capabilities.ts)
|
|
62
|
+
// y pasa a claude el del claim; sin él, `defaults.model` de la config; sin ninguno, el default del cli.
|
|
63
|
+
// el claim manda sobre la config porque es la elección de la persona para esa conversación (su
|
|
64
|
+
// default de ajustes, el composer, el hilo o la acción de una regla); la config queda como el default
|
|
65
|
+
// de la máquina. también al reanudar: --model con --resume cambia el modelo de la sesión desde ese
|
|
66
|
+
// turno, y el reintento desde cero usa el mismo. el modelo que se reporta en /status es el que de
|
|
67
|
+
// verdad usó el bucle principal (claude.ts::reportedModel).
|
|
47
68
|
import { execFile, spawn } from 'node:child_process';
|
|
48
69
|
import fs from 'node:fs';
|
|
49
70
|
import os from 'node:os';
|
|
50
71
|
import path from 'node:path';
|
|
51
72
|
import readline from 'node:readline';
|
|
52
73
|
import { promisify } from 'node:util';
|
|
53
|
-
import { refreshAccess } from './oauth.js';
|
|
74
|
+
import { CredentialRejectedError, refreshAccess } from './oauth.js';
|
|
54
75
|
import { AccessTokenSource } from './access-token.js';
|
|
55
|
-
import { concurrency, logsDir, mergeEntries, parseConfig, readConfigText, runConfigDir, saveConfig, scratchDir, } from './config.js';
|
|
76
|
+
import { concurrency, logsDir, mergeEntries, parseConfig, readConfigText, runConfigDir, saveConfig, scratchDir, splitConfig, } from './config.js';
|
|
77
|
+
import { ensureMachineId } from './machine.js';
|
|
78
|
+
import { secretPathsDeny } from './secret-paths.js';
|
|
79
|
+
import { runAwsEnv, clearRunAwsConfigs, writeEmptyAwsConfig } from './aws-env.js';
|
|
80
|
+
import { CLAIM_OUTCOME, parseRunnerBlock, serverStateChanged, writeServerState, } from './server-state.js';
|
|
56
81
|
import { consumeStreamLine, detectClaude, newStreamState } from './claude.js';
|
|
57
|
-
import { buildClaudeArgs
|
|
82
|
+
import { buildClaudeArgs } from './claude-args.js';
|
|
83
|
+
import { announcedCapabilities } from './announced-capabilities.js';
|
|
58
84
|
import { mirroredDeny, READ_MIRRORED_TOOLS, settingsFilesFor, WRITE_TOOLS } from './user-permissions.js';
|
|
59
|
-
import { claimRunId, EVENTS_DEFAULTS, parseClaim, PROMPT_PROFILE, RUN_ISOLATION, RUN_KIND
|
|
85
|
+
import { claimRunId, EVENTS_DEFAULTS, parseClaim, PROMPT_PROFILE, RUN_ISOLATION, RUN_KIND } from './claim.js';
|
|
60
86
|
import { EventUploader } from './event-uploader.js';
|
|
61
87
|
import { clip, feedEventsFromStream, systemEvent } from './feed.js';
|
|
62
88
|
import { scrubEnv } from './scrub-env.js';
|
|
63
89
|
import { clampReport, reportFor } from './status-report.js';
|
|
64
90
|
import { prepareCheckout, prepareConversationWorktree, prepareRunWorktree, removeRunWorktree, touchWorktree } from './worktree.js';
|
|
65
91
|
import { readShellGuard, readShellLog, readShellNote } from './read-shell-guard.js';
|
|
66
|
-
import { clearRunMcpConfigs, runConfigDeny, writeRunMcpConfig } from './run-mcp-config.js';
|
|
92
|
+
import { clearLegacyTmpConfigs, clearRunMcpConfigs, runConfigDeny, writeRunMcpConfig } from './run-mcp-config.js';
|
|
67
93
|
import { chunk, CONVERSATION_GC_INTERVAL_MS, listWorktreeCandidates, removeWorktrees, selectForRemoval } from './conversation-gc.js';
|
|
68
94
|
import { KeyedMutex } from './keyed-mutex.js';
|
|
69
95
|
import { describeFinding, REPO_HEALTH_INTERVAL_MS, repoChoices, repoFindings, repoIssues, scanRepos } from './repo-health.js';
|
|
@@ -95,6 +121,10 @@ const STATUS_POST_BACKOFF_MS = 2_000;
|
|
|
95
121
|
const SHUTDOWN_GRACE_MS = 20_000;
|
|
96
122
|
const EXIT_CODE_SIGINT = 130;
|
|
97
123
|
const EXIT_CODE_SIGTERM = 143;
|
|
124
|
+
// la credencial ya no vale (desvinculada, revocada o caducada): EX_CONFIG de sysexits, sin `login` no vuelve.
|
|
125
|
+
export const EXIT_CODE_UNPAIRED = 78;
|
|
126
|
+
// cabecera del 204 (o del 200 sin trabajo de un server >= t#465 P12) con el motivo de no recibir trabajo.
|
|
127
|
+
const RUNNER_STATE_HEADER = 'x-duckhunt-runner-state';
|
|
98
128
|
// topes de lo que el claim anuncia (RUNNER_CLAUDE_VERSION_MAX_CHARS) y de la nota de workdir.
|
|
99
129
|
const CLAUDE_VERSION_MAX_CHARS = 80;
|
|
100
130
|
const WORKDIR_MAX_CHARS = 300;
|
|
@@ -143,10 +173,16 @@ export class RunnerDaemon {
|
|
|
143
173
|
repoHealthRun = null;
|
|
144
174
|
// Read negado del directorio de mcp-configs: lo lleva todo kit (se calcula al arrancar).
|
|
145
175
|
runConfigDeny = [];
|
|
176
|
+
// Read negado de las rutas reales de las credenciales de la máquina: todo kit de lectura (al arrancar).
|
|
177
|
+
secretDeny = [];
|
|
178
|
+
// conversaciones que el último gc conservó por guardar trabajo (null = aún no recogió: no se anuncia).
|
|
179
|
+
keptWorktrees = null;
|
|
180
|
+
// lo último escrito en server-state.json.
|
|
181
|
+
serverState = null;
|
|
146
182
|
constructor(cfg, opts = {}) {
|
|
147
183
|
this.opts = opts;
|
|
148
|
-
const {
|
|
149
|
-
this.credential =
|
|
184
|
+
const { credential, local } = splitConfig(cfg);
|
|
185
|
+
this.credential = credential;
|
|
150
186
|
this.cfg = local;
|
|
151
187
|
this.auth = new AccessTokenSource(async () => {
|
|
152
188
|
const { access, credential, saved } = await refreshAccess(this.credential);
|
|
@@ -181,19 +217,9 @@ export class RunnerDaemon {
|
|
|
181
217
|
return this.cfg.label ?? os.hostname();
|
|
182
218
|
}
|
|
183
219
|
// capacidades que se anuncian: prompt solo si el cli puede cumplir su perfil (permission mode
|
|
184
|
-
// explícito, sin mcp del repo, deny list y settings solo del usuario en lectura).
|
|
220
|
+
// explícito, sin mcp del repo, deny list y settings solo del usuario en lectura), model solo con --model.
|
|
185
221
|
capabilities() {
|
|
186
|
-
return
|
|
187
|
-
...(this.hasAws ? [RUNNER_CAPABILITY.aws] : []),
|
|
188
|
-
// read_shell y native_memory van con prompt: exigen poder cumplir el perfil read (parseClaim lo
|
|
189
|
-
// valida) y pasar el deny espejado (--disallowedTools).
|
|
190
|
-
...(PROMPT_REQUIRED_FLAGS.every((f) => this.claude.supported.has(f))
|
|
191
|
-
? [RUNNER_CAPABILITY.prompt, RUNNER_CAPABILITY.readShell, RUNNER_CAPABILITY.nativeMemory]
|
|
192
|
-
: []),
|
|
193
|
-
RUNNER_CAPABILITY.events,
|
|
194
|
-
RUNNER_CAPABILITY.checkout,
|
|
195
|
-
...(this.cfg.defaults.remoteRepoEdits === false ? [] : [RUNNER_CAPABILITY.repoEdit]),
|
|
196
|
-
];
|
|
222
|
+
return announcedCapabilities({ hasAws: this.hasAws, supported: this.claude.supported, remoteRepoEdits: this.cfg.defaults.remoteRepoEdits });
|
|
197
223
|
}
|
|
198
224
|
/** loop principal: gc → claim → ejecutar en un slot libre → repetir, hasta SIGINT/SIGTERM.
|
|
199
225
|
* devuelve el exit code tras esperar el cierre de los runs en vuelo. */
|
|
@@ -205,9 +231,16 @@ export class RunnerDaemon {
|
|
|
205
231
|
this.hasAws = await execFileP('aws', ['--version']).then(() => true, () => false);
|
|
206
232
|
// lanza si la ruta no cabe en una regla de permisos: sin ese deny el daemon no arranca.
|
|
207
233
|
this.runConfigDeny = runConfigDeny(runConfigDir());
|
|
208
|
-
const stale = clearRunMcpConfigs();
|
|
234
|
+
const stale = clearRunMcpConfigs() + clearRunAwsConfigs();
|
|
209
235
|
if (stale > 0)
|
|
210
|
-
console.log(`[runner] ${stale}
|
|
236
|
+
console.log(`[runner] ${stale} config(s) de runs anteriores borrada(s)`);
|
|
237
|
+
const legacy = clearLegacyTmpConfigs();
|
|
238
|
+
if (legacy > 0)
|
|
239
|
+
console.log(`[runner] ${legacy} mcp-config(s) de daemons < 0.10.2 borrado(s) del tmpdir`);
|
|
240
|
+
const secrets = secretPathsDeny(process.env);
|
|
241
|
+
this.secretDeny = secrets.rules;
|
|
242
|
+
secrets.skipped.forEach((p) => console.warn(`[runner] secret_paths: ${p} no cabe en una regla de permisos de claude: queda solo la lista genérica del server`));
|
|
243
|
+
this.adoptMachineId();
|
|
211
244
|
this.installSignalHandlers();
|
|
212
245
|
console.log(`[runner] duckhunt-runner ${runnerVersion() ?? '?'} · ${this.label()} → ${this.credential.baseUrl} (claude ${this.claude.version}, aws cli ${this.hasAws ? 'sí' : 'no'}, ${Object.keys(this.cfg.repos).length} repos, ${Object.keys(this.cfg.aws).length} cuentas aws, capacidades ${this.capabilities().join(',')}, ${this.slots} slot${this.slots === 1 ? '' : 's'}, poll ${CLAIM_POLL_MS / 1000}s)`);
|
|
213
246
|
await this.refreshRepoHealth();
|
|
@@ -233,6 +266,56 @@ export class RunnerDaemon {
|
|
|
233
266
|
console.log('[runner] detenido');
|
|
234
267
|
return this.exitCode;
|
|
235
268
|
}
|
|
269
|
+
// el machine id de la config o uno nuevo que se guarda (config de 0.10). una config que no se puede
|
|
270
|
+
// escribir (montada de solo lectura) reclama sin él: duckhunt la reconoce igual por su credencial.
|
|
271
|
+
adoptMachineId() {
|
|
272
|
+
if (this.cfg.machineId)
|
|
273
|
+
return;
|
|
274
|
+
try {
|
|
275
|
+
this.cfg = { ...this.cfg, machineId: ensureMachineId() };
|
|
276
|
+
}
|
|
277
|
+
catch (err) {
|
|
278
|
+
console.warn(`[runner] no se pudo guardar el machine id en la config: ${err.message} — reclamo sin él`);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
// la credencial ya no vale: se para (sin reintentar), se cortan los runs (duckhunt ya los canceló al
|
|
282
|
+
// desvincular; sin credencial no pueden ni latir) y se sale con EXIT_CODE_UNPAIRED.
|
|
283
|
+
stopUnpaired(err) {
|
|
284
|
+
if (this.stopping)
|
|
285
|
+
return;
|
|
286
|
+
console.error(`[runner] ${err.message}. el daemon se detiene`);
|
|
287
|
+
this.recordServerState(CLAIM_OUTCOME.unpaired, null);
|
|
288
|
+
this.stopping = true;
|
|
289
|
+
this.exitCode = EXIT_CODE_UNPAIRED;
|
|
290
|
+
this.leases.forEach((lease) => lease.kill('cancel'));
|
|
291
|
+
this.wake?.();
|
|
292
|
+
}
|
|
293
|
+
// guarda lo que el server acaba de decir de esta máquina para `status` (solo si cambió o envejeció).
|
|
294
|
+
recordServerState(state, runner) {
|
|
295
|
+
const next = { at: Date.now(), baseUrl: this.credential.baseUrl, clientId: this.credential.clientId, state, runner, kept: this.keptWorktrees };
|
|
296
|
+
if (!serverStateChanged(this.serverState, next))
|
|
297
|
+
return;
|
|
298
|
+
try {
|
|
299
|
+
writeServerState(next);
|
|
300
|
+
this.serverState = next;
|
|
301
|
+
}
|
|
302
|
+
catch (err) {
|
|
303
|
+
console.error(`[runner] no se pudo guardar el estado del server: ${err.message}`);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
// el server aceptó un claim con el replacesClientId de esta credencial: ya adoptó (o no tenía nada que
|
|
307
|
+
// adoptar), así que deja de mandarse. el fichero solo se toca si sigue siendo de la misma credencial.
|
|
308
|
+
replacementDelivered(clientId, replaces) {
|
|
309
|
+
if (this.credential.clientId !== clientId || this.credential.replacesClientId !== replaces)
|
|
310
|
+
return;
|
|
311
|
+
this.credential = { baseUrl: this.credential.baseUrl, clientId, refreshToken: this.credential.refreshToken };
|
|
312
|
+
try {
|
|
313
|
+
saveConfig((current) => (current.clientId === clientId && current.replacesClientId === replaces ? { replacesClientId: undefined } : null));
|
|
314
|
+
}
|
|
315
|
+
catch (err) {
|
|
316
|
+
console.error(`[runner] no se pudo quitar replacesClientId de la config: ${err.message} — se reenvía al reiniciar (inocuo)`);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
236
319
|
// espera interrumpible por una señal de parada.
|
|
237
320
|
idle(ms) {
|
|
238
321
|
return new Promise((resolve) => {
|
|
@@ -270,6 +353,8 @@ export class RunnerDaemon {
|
|
|
270
353
|
// --- claim ---
|
|
271
354
|
async claim() {
|
|
272
355
|
let res;
|
|
356
|
+
// la credencial de la que sale este claim y a quién reemplaza (hasta que el server lo acepte).
|
|
357
|
+
const { clientId, replacesClientId } = this.credential;
|
|
273
358
|
try {
|
|
274
359
|
res = await this.api('/claim', {
|
|
275
360
|
runnerLabel: this.label(),
|
|
@@ -281,17 +366,28 @@ export class RunnerDaemon {
|
|
|
281
366
|
slots: this.slots,
|
|
282
367
|
...(runnerVersion() ? { version: runnerVersion() } : {}),
|
|
283
368
|
...(this.claude.version ? { claudeVersion: this.claude.version.slice(0, CLAUDE_VERSION_MAX_CHARS) } : {}),
|
|
369
|
+
...(this.cfg.machineId ? { machine: { id: this.cfg.machineId } } : {}),
|
|
370
|
+
...(replacesClientId ? { replacesClientId } : {}),
|
|
371
|
+
...(this.keptWorktrees ? { keptWorktrees: this.keptWorktrees } : {}),
|
|
284
372
|
});
|
|
285
373
|
}
|
|
286
374
|
catch (err) {
|
|
287
|
-
|
|
375
|
+
if (err instanceof CredentialRejectedError)
|
|
376
|
+
this.stopUnpaired(err);
|
|
377
|
+
else
|
|
378
|
+
console.error(`[runner] claim inaccesible: ${err.message}`);
|
|
288
379
|
return null;
|
|
289
380
|
}
|
|
381
|
+
if (res.ok && replacesClientId)
|
|
382
|
+
this.replacementDelivered(clientId, replacesClientId);
|
|
290
383
|
if (Number(res.headers.get(REPO_COMMANDS_HEADER)) > 0)
|
|
291
384
|
void this.syncRepoCommands();
|
|
292
|
-
|
|
293
|
-
|
|
385
|
+
const header = res.headers.get(RUNNER_STATE_HEADER);
|
|
386
|
+
// 204 = nada que hacer, de un server anterior a t#465 P12 (o en pausa, sin slot, actualizar: la cabecera).
|
|
387
|
+
if (res.status === 204) {
|
|
388
|
+
this.recordServerState(header, null);
|
|
294
389
|
return null;
|
|
390
|
+
}
|
|
295
391
|
if (res.status !== 200) {
|
|
296
392
|
console.error(`[runner] claim falló: http ${res.status} ${await res.text().catch(() => '')}`);
|
|
297
393
|
return null;
|
|
@@ -300,6 +396,12 @@ export class RunnerDaemon {
|
|
|
300
396
|
console.error(`[runner] claim con json ilegible: ${err.message}`);
|
|
301
397
|
return null;
|
|
302
398
|
});
|
|
399
|
+
// sin trabajo con la fila de esta máquina (server >= t#465 P12): 200 { run: null, runner, state }.
|
|
400
|
+
if (raw !== null && typeof raw === 'object' && 'run' in raw && raw.run === null) {
|
|
401
|
+
this.recordServerState(header, parseRunnerBlock(raw));
|
|
402
|
+
return null;
|
|
403
|
+
}
|
|
404
|
+
this.recordServerState(CLAIM_OUTCOME.claimed, parseRunnerBlock(raw));
|
|
303
405
|
try {
|
|
304
406
|
return parseClaim(raw);
|
|
305
407
|
}
|
|
@@ -319,6 +421,10 @@ export class RunnerDaemon {
|
|
|
319
421
|
start(claim) {
|
|
320
422
|
const lease = new RunLease(claim.run.id);
|
|
321
423
|
this.leases.add(lease);
|
|
424
|
+
// la conversación vuelve a trabajar en su worktree («pedir commit» o cualquier mensaje): deja de
|
|
425
|
+
// anunciarse como conservada, o su hilo volvería a enseñar los recuentos viejos hasta el siguiente gc.
|
|
426
|
+
if (this.keptWorktrees?.some((k) => k.runId === claim.run.id))
|
|
427
|
+
this.keptWorktrees = this.keptWorktrees.filter((k) => k.runId !== claim.run.id);
|
|
322
428
|
if (this.stopping)
|
|
323
429
|
lease.kill('shutdown');
|
|
324
430
|
void this.executeRun(claim, lease)
|
|
@@ -445,7 +551,8 @@ export class RunnerDaemon {
|
|
|
445
551
|
console.error(`[runner] ${err.message} — sigo con la config cargada`);
|
|
446
552
|
return;
|
|
447
553
|
}
|
|
448
|
-
const {
|
|
554
|
+
const { credential, local } = splitConfig(next);
|
|
555
|
+
const { baseUrl, clientId } = credential;
|
|
449
556
|
if (this.credentialUnsaved || (clientId !== this.credential.clientId && baseUrl === this.credential.baseUrl))
|
|
450
557
|
this.auth.reset();
|
|
451
558
|
if (JSON.stringify(local) === JSON.stringify(this.cfg))
|
|
@@ -484,16 +591,23 @@ export class RunnerDaemon {
|
|
|
484
591
|
this.lastGcAt = Date.now();
|
|
485
592
|
try {
|
|
486
593
|
const candidates = listWorktreeCandidates(Object.values(this.cfg.repos).map((r) => r.path));
|
|
487
|
-
if (candidates.length === 0)
|
|
594
|
+
if (candidates.length === 0) {
|
|
595
|
+
this.keptWorktrees = [];
|
|
488
596
|
return;
|
|
597
|
+
}
|
|
489
598
|
const open = await this.openConversations(candidates.filter((c) => c.kind === 'conversation').map((c) => c.runId));
|
|
490
599
|
const inFlight = new Set([...this.leases].map((lease) => lease.runId));
|
|
491
600
|
const targets = selectForRemoval(candidates, open, Date.now(), inFlight);
|
|
492
|
-
if (targets.length === 0)
|
|
601
|
+
if (targets.length === 0) {
|
|
602
|
+
this.keptWorktrees = [];
|
|
493
603
|
return;
|
|
604
|
+
}
|
|
494
605
|
const env = scrubEnv(process.env);
|
|
495
606
|
const byRepo = targets.reduce((acc, c) => acc.set(c.repoPath, [...(acc.get(c.repoPath) ?? []), c]), new Map());
|
|
496
|
-
const
|
|
607
|
+
const collected = await Promise.all([...byRepo].map(([repoPath, group]) => this.gitLocks.run(path.resolve(repoPath), () => removeWorktrees(group, env))));
|
|
608
|
+
const removed = collected.reduce((n, c) => n + c.removed, 0);
|
|
609
|
+
// lo que se anuncia al server: recuentos por conversación, nunca paths (worktree_report).
|
|
610
|
+
this.keptWorktrees = collected.flatMap((c) => c.kept).sort((a, b) => a.runId - b.runId);
|
|
497
611
|
if (removed > 0)
|
|
498
612
|
console.log(`[runner] gc: ${removed} worktree(s) recogido(s)`);
|
|
499
613
|
}
|
|
@@ -567,31 +681,32 @@ export class RunnerDaemon {
|
|
|
567
681
|
lease.kill('cancel');
|
|
568
682
|
}
|
|
569
683
|
})
|
|
570
|
-
.catch((err) =>
|
|
684
|
+
.catch((err) => {
|
|
685
|
+
// con los slots llenos el loop no reclama: el latido es quien se entera de que la credencial murió.
|
|
686
|
+
if (err instanceof CredentialRejectedError)
|
|
687
|
+
this.stopUnpaired(err);
|
|
688
|
+
else
|
|
689
|
+
console.error(`[runner] heartbeat del run ${runId} falló: ${err.message}`);
|
|
690
|
+
});
|
|
571
691
|
}, Math.max(MIN_HEARTBEAT_MS, heartbeatMs));
|
|
572
692
|
}
|
|
573
|
-
// --- env del run: el del usuario saneado + perfil aws mapeado ---
|
|
574
|
-
envFor(run) {
|
|
575
|
-
const env = { ...scrubEnv(process.env), AWS_PAGER: '' };
|
|
576
|
-
const accountId = run.aws?.accountId;
|
|
577
|
-
const account = accountId && Object.hasOwn(this.cfg.aws, accountId) ? this.cfg.aws[accountId] : undefined;
|
|
578
|
-
if (account) {
|
|
579
|
-
env.AWS_PROFILE = account.profile;
|
|
580
|
-
const region = account.region ?? run.aws?.region ?? undefined;
|
|
581
|
-
if (region)
|
|
582
|
-
env.AWS_DEFAULT_REGION = region;
|
|
583
|
-
}
|
|
584
|
-
else if (run.aws?.region) {
|
|
585
|
-
env.AWS_DEFAULT_REGION = run.aws.region;
|
|
586
|
-
}
|
|
587
|
-
return env;
|
|
588
|
-
}
|
|
589
693
|
// --- ejecución ---
|
|
590
694
|
async executeRun(claim, lease) {
|
|
591
695
|
const { run } = claim;
|
|
592
696
|
const tag = `run ${run.id}`;
|
|
593
|
-
console.log(`[runner] ${tag} reclamado (${run.kind}${run.profile ? `, perfil ${run.profile}` : ''}, entry ${run.entryId}${claim.tier ? `, tier ${claim.tier}` : ''}${run.repo ? `, repo ${run.repo}${run.branch ? `@${run.branch}` : ''}` : ''}${run.sessionId ? `, sesión ${run.sessionId}` : ''})`);
|
|
594
|
-
|
|
697
|
+
console.log(`[runner] ${tag} reclamado (${run.kind}${run.profile ? `, perfil ${run.profile}` : ''}, entry ${run.entryId}${claim.tier ? `, tier ${claim.tier}` : ''}${run.repo ? `, repo ${run.repo}${run.branch ? `@${run.branch}` : ''}` : ''}${run.sessionId ? `, sesión ${run.sessionId}` : ''}${run.model ? `, modelo ${run.model}` : ''})`);
|
|
698
|
+
// env del run: el del usuario saneado + el perfil aws de su cuenta; una cuenta que esta máquina no
|
|
699
|
+
// mapea, con la aws vacía del propio run (aws_strict), que se borra al cerrar el segmento.
|
|
700
|
+
let awsDir = null;
|
|
701
|
+
const dropAwsDir = () => {
|
|
702
|
+
if (awsDir !== null)
|
|
703
|
+
fs.rmSync(awsDir, { recursive: true, force: true });
|
|
704
|
+
};
|
|
705
|
+
const aws = runAwsEnv({ ...scrubEnv(process.env), AWS_PAGER: '' }, run.aws, this.cfg.aws, () => (awsDir = writeEmptyAwsConfig(run.id)));
|
|
706
|
+
const env = aws.env;
|
|
707
|
+
const awsWarnings = aws.unmapped
|
|
708
|
+
? [`cuenta aws ${aws.unmapped} sin mapear en esta máquina: la aws cli corre sin credenciales (\`duckhunt-runner aws add ${aws.unmapped} <perfil>\`)`]
|
|
709
|
+
: [];
|
|
595
710
|
// identidad del proceso en cada llamada del run (servers anteriores a los segmentos: nada).
|
|
596
711
|
const seg = run.segment !== null ? { segment: run.segment } : {};
|
|
597
712
|
const heartbeat = this.startHeartbeat(lease, claim.heartbeatMs, seg);
|
|
@@ -602,6 +717,7 @@ export class RunnerDaemon {
|
|
|
602
717
|
}
|
|
603
718
|
catch (err) {
|
|
604
719
|
clearInterval(heartbeat);
|
|
720
|
+
dropAwsDir();
|
|
605
721
|
await feed?.close();
|
|
606
722
|
await this.postStatus(run.id, { status: 'failed', error: `no se pudo preparar el directorio del run: ${err.message}`, ...seg });
|
|
607
723
|
return;
|
|
@@ -617,7 +733,7 @@ export class RunnerDaemon {
|
|
|
617
733
|
feed?.push(systemEvent(text, ctx));
|
|
618
734
|
};
|
|
619
735
|
note(prepared.note);
|
|
620
|
-
[...claim.warnings, ...prepared.warnings].forEach(note);
|
|
736
|
+
[...claim.warnings, ...prepared.warnings, ...awsWarnings].forEach(note);
|
|
621
737
|
const releaseCwd = await this.holdCwd(run, prepared, lease, note);
|
|
622
738
|
// mcp-config con el token per-run (run-mcp-config.ts: 0600 en un directorio 0700; se borra al terminar).
|
|
623
739
|
let mcpFile = null;
|
|
@@ -632,6 +748,7 @@ export class RunnerDaemon {
|
|
|
632
748
|
finally {
|
|
633
749
|
if (mcpFile !== null)
|
|
634
750
|
fs.rmSync(mcpFile, { force: true });
|
|
751
|
+
dropAwsDir();
|
|
635
752
|
releaseCwd();
|
|
636
753
|
clearInterval(heartbeat);
|
|
637
754
|
}
|
|
@@ -674,12 +791,14 @@ export class RunnerDaemon {
|
|
|
674
791
|
mcpConfigFile: mcpFile,
|
|
675
792
|
supported: this.claude.supported,
|
|
676
793
|
resumeSessionId,
|
|
677
|
-
|
|
794
|
+
// el que pide duckhunt para esta conversación; si no pide ninguno, el default de la máquina.
|
|
795
|
+
model: run.model ?? this.cfg.defaults.model,
|
|
678
796
|
configBudgetUsd: this.cfg.defaults.maxBudgetUsd,
|
|
679
797
|
skipPermissions: prepared.repoCfg?.dangerouslySkipPermissions === true,
|
|
680
798
|
payingWithApiKey: !!process.env.ANTHROPIC_API_KEY,
|
|
681
799
|
mirroredDeny: deny,
|
|
682
800
|
runConfigDeny: this.runConfigDeny,
|
|
801
|
+
secretPathsDeny: this.secretDeny,
|
|
683
802
|
withoutShell: shell.dropShell,
|
|
684
803
|
});
|
|
685
804
|
// reanudar o no lo decide el server: manda sessionId solo cuando hay sesión que retomar.
|
|
@@ -801,10 +920,15 @@ export class RunnerDaemon {
|
|
|
801
920
|
const body = clampReport(report);
|
|
802
921
|
// i/o secuencial con backoff exponencial.
|
|
803
922
|
for (let attempt = 1; attempt <= STATUS_POST_ATTEMPTS; attempt++) {
|
|
923
|
+
let rejected = false;
|
|
804
924
|
const res = await this.api(`/runs/${runId}/status`, body).catch((err) => {
|
|
925
|
+
rejected = err instanceof CredentialRejectedError;
|
|
805
926
|
console.error(`[runner] status post falló (intento ${attempt}/${STATUS_POST_ATTEMPTS}): ${err.message}`);
|
|
806
927
|
return null;
|
|
807
928
|
});
|
|
929
|
+
// sin credencial no hay reintento que valga (duckhunt ya lo cerró al desvincular la máquina).
|
|
930
|
+
if (rejected)
|
|
931
|
+
return;
|
|
808
932
|
// 409 = el server ya cerró el run (cancel del usuario, sweeper): benigno.
|
|
809
933
|
if (res && (res.ok || res.status === HTTP_CONFLICT))
|
|
810
934
|
return;
|