@discovery-tree/runner 0.1.21 → 0.1.22
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 +13 -0
- package/dist/cli.js +201 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -90,6 +90,8 @@ readable only by you (mode 0600) because it holds the runner token. `login` writ
|
|
|
90
90
|
| ------------------------------ | ------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
91
91
|
| `maxSessions` | `2` | Sessions with a running Claude Code at once (1 to 64). Further starts are refused as busy and retried by the server. `--max-sessions` overrides it. |
|
|
92
92
|
| `maxJobs` | `2` | [Jobs](#jobs) run at once (1 to 16), apart from sessions. `--max-jobs` overrides it. |
|
|
93
|
+
| `jobLogRetentionDays` | `30` | Days an ended job's log files are kept (0: for good). `--job-log-retention-days` overrides it. See [Jobs](#jobs). |
|
|
94
|
+
| `jobDataRetentionDays` | `0` (kept for good) | Days an ended job's data folder is kept (0: for good). `--job-data-retention-days` overrides it. |
|
|
93
95
|
| `reposDir` | `$XDG_DATA_HOME/discovery-tree/runner/repos` | Clone cache. `--repos-dir` overrides it. |
|
|
94
96
|
| `worktreesDir` | `$XDG_DATA_HOME/discovery-tree/runner/worktrees` | One worktree per session. |
|
|
95
97
|
| `permissionMode` | `auto` | Claude Code `--permission-mode`. See below. |
|
|
@@ -355,9 +357,20 @@ it leaves it running (the session's worktree stays until the job ends, then goes
|
|
|
355
357
|
runner's own (secrets in memory only, redacted from what is posted; never the runner's
|
|
356
358
|
token). On macOS and Linux the command runs in `/bin/sh`, in a process group of its own; on
|
|
357
359
|
Windows in Windows PowerShell (`powershell.exe`).
|
|
360
|
+
- **Its data folder.** Each job gets `<state>/jobs/<job id>/data/` (owner-only), its path in
|
|
361
|
+
`DT_JOB_DATA_DIR`, for what it produces (a recording, a report). It is outside every
|
|
362
|
+
session's checkout, so it stays when the checkout is removed (7 days after the job ends),
|
|
363
|
+
and a job taken up after a restart keeps it. Agents are told to write there, and to run
|
|
364
|
+
Python from a `.venv` in the folder the job runs in (`.venv/bin/python`, on Windows
|
|
365
|
+
`.venv\Scripts\python.exe`) rather than `python` from PATH.
|
|
358
366
|
- **Its log.** Everything it writes is in `<state>/jobs/<job id>/stdout.log` and `stderr.log`
|
|
359
367
|
(`dt-runner status` prints the state folder), kept after it ends. The runner posts the lines
|
|
360
368
|
to Discovery Tree, which keeps the newest 2,000.
|
|
369
|
+
- **Cleaning up.** When the runner starts, and once a day after, it removes the log files of
|
|
370
|
+
jobs that ended more than `jobLogRetentionDays` ago (default 30; 0 keeps them) and whose
|
|
371
|
+
last report reached Discovery Tree, and logs what it removed. Their data folders are kept
|
|
372
|
+
unless you set `jobDataRetentionDays`; a job's small `job.json` record always stays. A job
|
|
373
|
+
still running, or still reporting, is never touched.
|
|
361
374
|
- **Stopping it.** Stop it in Discovery Tree: the runner asks it to end (SIGTERM to its group;
|
|
362
375
|
`taskkill /T` on Windows) and kills what is left of it 10 seconds later.
|
|
363
376
|
- **The runner stopping.** Jobs keep running when the runner stops or restarts; the next
|
package/dist/cli.js
CHANGED
|
@@ -469,7 +469,7 @@ function treeJobCwdProblem(cwd) {
|
|
|
469
469
|
var MAX_JOB_REQUEST_PURPOSE_CHARS = 2e3;
|
|
470
470
|
var MAX_JOB_REQUEST_EXPECT_SECONDS = 366 * 24 * 3600;
|
|
471
471
|
var EXAMPLE_NAME = "Record Polymarket order books for 6 hours";
|
|
472
|
-
var EXAMPLE_COMMAND =
|
|
472
|
+
var EXAMPLE_COMMAND = '.venv/bin/python scripts/record_books.py --hours 6 --out "$DT_JOB_DATA_DIR/books"';
|
|
473
473
|
var EXAMPLE_CHECKOUT = "/absolute/path/of/your/checkout";
|
|
474
474
|
var JOB_REQUEST_INSTRUCTION = `## Jobs
|
|
475
475
|
|
|
@@ -486,7 +486,7 @@ cwd: .
|
|
|
486
486
|
url: http://localhost:8000
|
|
487
487
|
expect: 6h
|
|
488
488
|
---
|
|
489
|
-
Records
|
|
489
|
+
Records order books into $DT_JOB_DATA_DIR/books, which the backtest reads.
|
|
490
490
|
-->
|
|
491
491
|
|
|
492
492
|
Rules:
|
|
@@ -496,6 +496,19 @@ Rules:
|
|
|
496
496
|
directory. Say in your answer what you asked for; do not wait for it to start.
|
|
497
497
|
- \`name\`: what it does, one line.
|
|
498
498
|
- \`command\`: one line, exactly as you would type it in a shell here.
|
|
499
|
+
- Write what the job produces to the folder named by \`$DT_JOB_DATA_DIR\`
|
|
500
|
+
(\`$env:DT_JOB_DATA_DIR\` on Windows), not into your checkout: the job gets a data folder
|
|
501
|
+
of its own on this computer, which stays when the checkout is removed. Pass it in the
|
|
502
|
+
command (an output flag) or read it in the code, and have the job print the folder it
|
|
503
|
+
writes to as it starts, so its log says where the output is. It is set only for the job:
|
|
504
|
+
when you try the command here, set DT_JOB_DATA_DIR to a scratch folder first.
|
|
505
|
+
- Python: create a virtual environment in the folder the job runs in (\`cwd\`) during this
|
|
506
|
+
run (\`python3 -m venv .venv\`, then install with \`.venv/bin/pip\`) and call
|
|
507
|
+
\`.venv/bin/python\` (Windows \`.venv\\Scripts\\python.exe\`) directly in the command, never
|
|
508
|
+
\`python\` or \`python3\` from PATH: that may be another interpreter, without your packages,
|
|
509
|
+
or one the system refuses permission to run.
|
|
510
|
+
- The example is for macOS and Linux. On Windows the command runs in PowerShell:
|
|
511
|
+
\`.venv\\Scripts\\python.exe scripts\\record_books.py --hours 6 --out "$env:DT_JOB_DATA_DIR\\books"\`.
|
|
499
512
|
- \`checkout\`: the absolute path of your checkout, as \`git rev-parse --show-toplevel\` prints
|
|
500
513
|
it (or \`pwd\` in the folder you started in, when there is no repository).
|
|
501
514
|
- \`cwd\`: where to run it, relative to \`checkout\`: \`.\` for its root. Never absolute, never
|
|
@@ -512,8 +525,9 @@ Rules:
|
|
|
512
525
|
in a row the run is not told again, and the job says that automatic tries have stopped.
|
|
513
526
|
A later run of the same job that exits cleanly starts that count over.
|
|
514
527
|
- What the job writes in your checkout is kept for ${TREE_JOB_OUTPUT_KEPT_MS / 864e5} days after the job ends, then removed with
|
|
515
|
-
the checkout. Say where its output goes (below \`---\`), and
|
|
516
|
-
find it
|
|
528
|
+
the checkout; its data folder stays. Say where its output goes (below \`---\`), and say in a
|
|
529
|
+
DT-RESULT block where to find it: in the job's data folder (its log names the path), and
|
|
530
|
+
where in it, so it is collected.
|
|
517
531
|
- Do not write \`-->\` inside a block: it ends the block.`;
|
|
518
532
|
|
|
519
533
|
// ../contracts/src/environments.ts
|
|
@@ -660,8 +674,11 @@ function toolGrantRepositoryKey(url) {
|
|
|
660
674
|
return `${m[1]}/${m[2]}`.toLowerCase();
|
|
661
675
|
}
|
|
662
676
|
|
|
677
|
+
// ../contracts/src/run-activity.ts
|
|
678
|
+
var RUN_STUCK_TOOL_CALL_AFTER_MS = 15 * 6e4;
|
|
679
|
+
|
|
663
680
|
// src/version.ts
|
|
664
|
-
var RUNNER_VERSION = true ? "0.1.
|
|
681
|
+
var RUNNER_VERSION = true ? "0.1.22" : "0.0.0-dev";
|
|
665
682
|
var RUNNER_PLATFORM = `${process.platform}-${process.arch}`;
|
|
666
683
|
|
|
667
684
|
// src/api.ts
|
|
@@ -4400,6 +4417,8 @@ function configDirRules(configFile, platform = process.platform) {
|
|
|
4400
4417
|
var DEFAULT_SERVER_URL = "https://discovery-tree-backend.onrender.com";
|
|
4401
4418
|
var DEFAULT_MAX_SESSIONS = 2;
|
|
4402
4419
|
var DEFAULT_IDLE_TIMEOUT_MINUTES = 15;
|
|
4420
|
+
var DEFAULT_JOB_LOG_RETENTION_DAYS = 30;
|
|
4421
|
+
var JOB_RETENTION_DAYS_LIMIT = 3650;
|
|
4403
4422
|
async function readConfigFile(file) {
|
|
4404
4423
|
let raw;
|
|
4405
4424
|
try {
|
|
@@ -4454,6 +4473,14 @@ function resolveConfig(file, overrides = {}, env = process.env, paths = runnerPa
|
|
|
4454
4473
|
`maxJobs must be a whole number from 1 to ${RUNNER_MAX_JOBS_LIMIT} (got ${maxJobs}).`
|
|
4455
4474
|
);
|
|
4456
4475
|
}
|
|
4476
|
+
const jobLogRetentionDays = retentionDays(
|
|
4477
|
+
"jobLogRetentionDays",
|
|
4478
|
+
overrides.jobLogRetentionDays ?? file?.jobLogRetentionDays ?? DEFAULT_JOB_LOG_RETENTION_DAYS
|
|
4479
|
+
);
|
|
4480
|
+
const jobDataRetentionDays = retentionDays(
|
|
4481
|
+
"jobDataRetentionDays",
|
|
4482
|
+
overrides.jobDataRetentionDays ?? file?.jobDataRetentionDays ?? 0
|
|
4483
|
+
);
|
|
4457
4484
|
const inherit = file?.inheritClaudeCodePermissions;
|
|
4458
4485
|
if (inherit !== void 0 && typeof inherit !== "boolean") {
|
|
4459
4486
|
throw new Error(
|
|
@@ -4502,6 +4529,8 @@ function resolveConfig(file, overrides = {}, env = process.env, paths = runnerPa
|
|
|
4502
4529
|
name: file?.name ?? null,
|
|
4503
4530
|
maxSessions,
|
|
4504
4531
|
maxJobs,
|
|
4532
|
+
jobLogRetentionDays,
|
|
4533
|
+
jobDataRetentionDays,
|
|
4505
4534
|
reposDir: overrides.reposDir ?? file?.reposDir ?? join7(paths.dataDir, "repos"),
|
|
4506
4535
|
worktreesDir: file?.worktreesDir ?? join7(paths.dataDir, "worktrees"),
|
|
4507
4536
|
permissionMode: mode,
|
|
@@ -4521,6 +4550,18 @@ function resolveConfig(file, overrides = {}, env = process.env, paths = runnerPa
|
|
|
4521
4550
|
configFile: paths.configFile
|
|
4522
4551
|
};
|
|
4523
4552
|
}
|
|
4553
|
+
function retentionDays(key, days) {
|
|
4554
|
+
if (!Number.isInteger(days) || days < 0 || days > JOB_RETENTION_DAYS_LIMIT) {
|
|
4555
|
+
throw new Error(
|
|
4556
|
+
`${key} must be a whole number of days from 0 (keep for good) to ${JOB_RETENTION_DAYS_LIMIT} (got ${days}).`
|
|
4557
|
+
);
|
|
4558
|
+
}
|
|
4559
|
+
return days;
|
|
4560
|
+
}
|
|
4561
|
+
function numberFlag(value) {
|
|
4562
|
+
if (value === void 0) return void 0;
|
|
4563
|
+
return value.trim() ? Number(value) : Number.NaN;
|
|
4564
|
+
}
|
|
4524
4565
|
|
|
4525
4566
|
// src/daemon.ts
|
|
4526
4567
|
import { join as join16 } from "node:path";
|
|
@@ -4648,7 +4689,7 @@ function reportableSessionIds(ids, onDropped = () => void 0) {
|
|
|
4648
4689
|
// src/jobs/job-manager.ts
|
|
4649
4690
|
import { randomBytes as randomBytes3, scrypt, timingSafeEqual } from "node:crypto";
|
|
4650
4691
|
import { realpathSync } from "node:fs";
|
|
4651
|
-
import { mkdir as mkdir6, readFile as readFile8, readdir as readdir2, stat as stat4 } from "node:fs/promises";
|
|
4692
|
+
import { mkdir as mkdir6, readFile as readFile8, readdir as readdir2, rm as rm6, stat as stat4 } from "node:fs/promises";
|
|
4652
4693
|
import { basename, dirname as dirname8, isAbsolute as isAbsolute5, join as join11, resolve as resolve2, sep as sep3 } from "node:path";
|
|
4653
4694
|
|
|
4654
4695
|
// src/environment.ts
|
|
@@ -5762,6 +5803,9 @@ var CENSUS_INTERVAL_MS2 = 3e4;
|
|
|
5762
5803
|
var JOB_SECRETS_WAIT_MS = 9e4;
|
|
5763
5804
|
var JOB_SECRETS_END_WAIT_MS = 12e4;
|
|
5764
5805
|
var JOB_LOST_POSTING_MS = RUNNER_JOB_MISSING_GRACE_MS + 3e4;
|
|
5806
|
+
var JOB_DATA_DIR_NAME = "data";
|
|
5807
|
+
var JOB_DATA_DIR_ENV = "DT_JOB_DATA_DIR";
|
|
5808
|
+
var JOB_PRUNE_INTERVAL_MS = 24 * 36e5;
|
|
5765
5809
|
function secretWait() {
|
|
5766
5810
|
let end = () => void 0;
|
|
5767
5811
|
const over = new Promise((resolve4) => end = resolve4);
|
|
@@ -5783,6 +5827,9 @@ var JobManager = class {
|
|
|
5783
5827
|
queues = /* @__PURE__ */ new Map();
|
|
5784
5828
|
timer = null;
|
|
5785
5829
|
censusTimer = null;
|
|
5830
|
+
pruneTimer = null;
|
|
5831
|
+
/** The prune under way, so prunes never overlap. */
|
|
5832
|
+
pruning = null;
|
|
5786
5833
|
ticking = false;
|
|
5787
5834
|
shuttingDown = false;
|
|
5788
5835
|
/** Resolves when the runner begins to stop: an end waiting for secrets waits no more. */
|
|
@@ -5792,6 +5839,14 @@ var JobManager = class {
|
|
|
5792
5839
|
jobDir(jobId) {
|
|
5793
5840
|
return join11(this.root, jobId);
|
|
5794
5841
|
}
|
|
5842
|
+
/**
|
|
5843
|
+
* The folder a job writes its output to (`DT_JOB_DATA_DIR`): its own, apart from any
|
|
5844
|
+
* session's checkout, so it outlives the session's cleanup. Pruned only when the runner's
|
|
5845
|
+
* owner set `jobDataRetentionDays`.
|
|
5846
|
+
*/
|
|
5847
|
+
jobDataDir(jobId) {
|
|
5848
|
+
return join11(this.jobDir(jobId), JOB_DATA_DIR_NAME);
|
|
5849
|
+
}
|
|
5795
5850
|
/**
|
|
5796
5851
|
* Jobs the runner reports in `activeJobIds`: a live process, or an end not yet reported.
|
|
5797
5852
|
* Not a start still under way: the server takes a listed job as up, settling its
|
|
@@ -5903,6 +5958,106 @@ var JobManager = class {
|
|
|
5903
5958
|
}
|
|
5904
5959
|
this.ensureTimers();
|
|
5905
5960
|
}
|
|
5961
|
+
/**
|
|
5962
|
+
* Prunes settled jobs now, then once a day until the runner stops (see
|
|
5963
|
+
* {@link pruneSettledJobs}). Nothing to do when both retentions keep everything.
|
|
5964
|
+
*/
|
|
5965
|
+
startPruning() {
|
|
5966
|
+
if (this.shuttingDown || this.pruneTimer || !this.pruneEnabled()) return;
|
|
5967
|
+
const run = () => void this.pruneSettledJobs().catch(() => void 0);
|
|
5968
|
+
run();
|
|
5969
|
+
this.pruneTimer = setInterval(run, JOB_PRUNE_INTERVAL_MS);
|
|
5970
|
+
this.pruneTimer.unref?.();
|
|
5971
|
+
}
|
|
5972
|
+
pruneEnabled() {
|
|
5973
|
+
return retentionMs(this.opts.logRetentionDays) !== null || retentionMs(this.opts.dataRetentionDays) !== null;
|
|
5974
|
+
}
|
|
5975
|
+
/**
|
|
5976
|
+
* Removes what settled jobs left past their retention, counted from when each ended:
|
|
5977
|
+
* their log files after `logRetentionDays` (everything in the job's folder but `job.json`
|
|
5978
|
+
* and `data/`), and their `data/` after `dataRetentionDays`, each only when set (0 or
|
|
5979
|
+
* unset keeps it). `job.json` stays, so a start delivered again is still answered from it.
|
|
5980
|
+
* A job that is not settled (running, or its last report still to go) is never touched.
|
|
5981
|
+
* Logs what it removed.
|
|
5982
|
+
*/
|
|
5983
|
+
pruneSettledJobs(now = Date.now()) {
|
|
5984
|
+
if (this.pruning) return this.pruning;
|
|
5985
|
+
const run = this.prune(now).finally(() => {
|
|
5986
|
+
if (this.pruning === run) this.pruning = null;
|
|
5987
|
+
});
|
|
5988
|
+
this.pruning = run;
|
|
5989
|
+
return run;
|
|
5990
|
+
}
|
|
5991
|
+
async prune(now) {
|
|
5992
|
+
const result = { logs: [], data: [] };
|
|
5993
|
+
const logsMs = retentionMs(this.opts.logRetentionDays);
|
|
5994
|
+
const dataMs = retentionMs(this.opts.dataRetentionDays);
|
|
5995
|
+
if (logsMs === null && dataMs === null) return result;
|
|
5996
|
+
let entries = [];
|
|
5997
|
+
try {
|
|
5998
|
+
entries = await readdir2(this.root);
|
|
5999
|
+
} catch (err) {
|
|
6000
|
+
if (err.code !== "ENOENT") {
|
|
6001
|
+
this.opts.logger.warn("could not read the jobs folder to prune it", {
|
|
6002
|
+
error: err.message
|
|
6003
|
+
});
|
|
6004
|
+
}
|
|
6005
|
+
return result;
|
|
6006
|
+
}
|
|
6007
|
+
for (const entry of entries) {
|
|
6008
|
+
if (this.shuttingDown) break;
|
|
6009
|
+
if (!isRunnerSessionId(entry) || this.jobs.has(entry) || this.starting.has(entry)) continue;
|
|
6010
|
+
const dir = this.jobDir(entry);
|
|
6011
|
+
const record = await readJson(join11(dir, "job.json")).catch(() => null);
|
|
6012
|
+
if (!record || record.jobId !== entry || !record.settled) continue;
|
|
6013
|
+
const endedAt = Date.parse(record.ended?.at ?? record.createdAt);
|
|
6014
|
+
if (!Number.isFinite(endedAt)) continue;
|
|
6015
|
+
const age = now - endedAt;
|
|
6016
|
+
if (logsMs !== null && age > logsMs) {
|
|
6017
|
+
const files = await readdir2(dir).catch(() => []);
|
|
6018
|
+
const logs = files.filter((f) => f !== "job.json" && f !== JOB_DATA_DIR_NAME);
|
|
6019
|
+
const removed = await this.removeAll(
|
|
6020
|
+
entry,
|
|
6021
|
+
logs.map((f) => join11(dir, f))
|
|
6022
|
+
);
|
|
6023
|
+
if (removed.length) {
|
|
6024
|
+
result.logs.push(entry);
|
|
6025
|
+
this.opts.logger.info(
|
|
6026
|
+
`job ${entry}: removed its log files (${removed.join(", ")}), ended over ${this.opts.logRetentionDays} day(s) ago`
|
|
6027
|
+
);
|
|
6028
|
+
}
|
|
6029
|
+
}
|
|
6030
|
+
if (dataMs !== null && age > dataMs) {
|
|
6031
|
+
const dataDir = this.jobDataDir(entry);
|
|
6032
|
+
const exists3 = await stat4(dataDir).then(
|
|
6033
|
+
() => true,
|
|
6034
|
+
() => false
|
|
6035
|
+
);
|
|
6036
|
+
if (exists3 && (await this.removeAll(entry, [dataDir])).length) {
|
|
6037
|
+
result.data.push(entry);
|
|
6038
|
+
this.opts.logger.info(
|
|
6039
|
+
`job ${entry}: removed its data folder ${dataDir}, ended over ${this.opts.dataRetentionDays} day(s) ago`
|
|
6040
|
+
);
|
|
6041
|
+
}
|
|
6042
|
+
}
|
|
6043
|
+
}
|
|
6044
|
+
return result;
|
|
6045
|
+
}
|
|
6046
|
+
/** Removes each path (a folder with what is in it), returning the names of those that went. */
|
|
6047
|
+
async removeAll(jobId, paths) {
|
|
6048
|
+
const removed = [];
|
|
6049
|
+
for (const p of paths) {
|
|
6050
|
+
try {
|
|
6051
|
+
await rm6(p, { recursive: true, force: true });
|
|
6052
|
+
removed.push(basename(p));
|
|
6053
|
+
} catch (err) {
|
|
6054
|
+
this.opts.logger.warn(`job ${jobId}: could not remove ${p}`, {
|
|
6055
|
+
error: err.message
|
|
6056
|
+
});
|
|
6057
|
+
}
|
|
6058
|
+
}
|
|
6059
|
+
return removed;
|
|
6060
|
+
}
|
|
5906
6061
|
async restoreJob(record, table) {
|
|
5907
6062
|
const job = await this.openJob(record, null, null);
|
|
5908
6063
|
if (record.ended) {
|
|
@@ -6030,7 +6185,9 @@ var JobManager = class {
|
|
|
6030
6185
|
this.stopped.end();
|
|
6031
6186
|
if (this.timer) clearInterval(this.timer);
|
|
6032
6187
|
if (this.censusTimer) clearInterval(this.censusTimer);
|
|
6033
|
-
this.
|
|
6188
|
+
if (this.pruneTimer) clearInterval(this.pruneTimer);
|
|
6189
|
+
this.timer = this.censusTimer = this.pruneTimer = null;
|
|
6190
|
+
await this.pruning?.catch(() => void 0);
|
|
6034
6191
|
await Promise.allSettled([...this.queues.values()]);
|
|
6035
6192
|
await Promise.allSettled([...this.finishing]);
|
|
6036
6193
|
const jobs = [...this.jobs.values()];
|
|
@@ -6101,7 +6258,8 @@ var JobManager = class {
|
|
|
6101
6258
|
const environment = sessionEnvironment(cmd.environment);
|
|
6102
6259
|
const redactor = environment ? jobLineRedactor(environment) : null;
|
|
6103
6260
|
const dir = this.jobDir(id);
|
|
6104
|
-
|
|
6261
|
+
const dataDir = this.jobDataDir(id);
|
|
6262
|
+
await mkdir6(dataDir, { recursive: true, mode: 448 });
|
|
6105
6263
|
const record = {
|
|
6106
6264
|
jobId: id,
|
|
6107
6265
|
name,
|
|
@@ -6124,7 +6282,7 @@ var JobManager = class {
|
|
|
6124
6282
|
}
|
|
6125
6283
|
}
|
|
6126
6284
|
await saveRecord(dir, record);
|
|
6127
|
-
this.opts.logger.info(`job ${id}: starting "${name}"`, { cwd });
|
|
6285
|
+
this.opts.logger.info(`job ${id}: starting "${name}"`, { cwd, dataDir });
|
|
6128
6286
|
const shortLines = environment ? secretsWithShortLines(environment) : [];
|
|
6129
6287
|
if (environment?.unredacted.length || shortLines.length) {
|
|
6130
6288
|
this.opts.logger.warn(
|
|
@@ -6136,7 +6294,11 @@ var JobManager = class {
|
|
|
6136
6294
|
`job ${id}: left out of the job's environment (not a name it may set): ${environment.skipped.slice(0, 20).join(", ")}`
|
|
6137
6295
|
);
|
|
6138
6296
|
}
|
|
6139
|
-
const env = {
|
|
6297
|
+
const env = {
|
|
6298
|
+
...process.env,
|
|
6299
|
+
...environment?.env,
|
|
6300
|
+
[JOB_DATA_DIR_ENV]: resolve2(dataDir)
|
|
6301
|
+
};
|
|
6140
6302
|
delete env.DT_RUNNER_TOKEN;
|
|
6141
6303
|
let started;
|
|
6142
6304
|
try {
|
|
@@ -6485,7 +6647,7 @@ var JobManager = class {
|
|
|
6485
6647
|
}
|
|
6486
6648
|
signalGroup2(tree.pid, "SIGKILL");
|
|
6487
6649
|
}
|
|
6488
|
-
/** Its last report is through: the job is let go (its folder and log stay). */
|
|
6650
|
+
/** Its last report is through: the job is let go (its folder and log stay, until pruned). */
|
|
6489
6651
|
async settle(job) {
|
|
6490
6652
|
if (this.jobs.get(job.record.jobId) !== job || job.phase !== "ended") return;
|
|
6491
6653
|
this.jobs.delete(job.record.jobId);
|
|
@@ -6679,6 +6841,9 @@ function queueEndReport(outbox, ended) {
|
|
|
6679
6841
|
ended.status === "stopped" ? { status: "stopped", exitCode: ended.exitCode, signal: ended.signal } : { status: "exited", exitCode: ended.exitCode, signal: ended.signal }
|
|
6680
6842
|
);
|
|
6681
6843
|
}
|
|
6844
|
+
function retentionMs(days) {
|
|
6845
|
+
return typeof days === "number" && Number.isFinite(days) && days > 0 ? days * 864e5 : null;
|
|
6846
|
+
}
|
|
6682
6847
|
async function saveRecord(dir, record) {
|
|
6683
6848
|
await writeJsonAtomic(join11(dir, "job.json"), record);
|
|
6684
6849
|
}
|
|
@@ -6697,7 +6862,7 @@ function safeError(err, redactor) {
|
|
|
6697
6862
|
|
|
6698
6863
|
// src/session-manager.ts
|
|
6699
6864
|
import { existsSync as existsSync2, lstatSync } from "node:fs";
|
|
6700
|
-
import { mkdir as mkdir9, rm as
|
|
6865
|
+
import { mkdir as mkdir9, rm as rm8, writeFile as writeFile6 } from "node:fs/promises";
|
|
6701
6866
|
import { basename as basename3, dirname as dirname11, join as join15, resolve as resolve3 } from "node:path";
|
|
6702
6867
|
|
|
6703
6868
|
// src/prompt-images.ts
|
|
@@ -7460,7 +7625,7 @@ function ghError(command, res) {
|
|
|
7460
7625
|
}
|
|
7461
7626
|
|
|
7462
7627
|
// src/session-store.ts
|
|
7463
|
-
import { mkdir as mkdir8, readdir as readdir3, rm as
|
|
7628
|
+
import { mkdir as mkdir8, readdir as readdir3, rm as rm7 } from "node:fs/promises";
|
|
7464
7629
|
import { join as join14 } from "node:path";
|
|
7465
7630
|
var HANDLED_COMMAND_IDS_KEPT = 100;
|
|
7466
7631
|
var pendingWrites = /* @__PURE__ */ new Map();
|
|
@@ -7506,7 +7671,7 @@ var SessionStore = class {
|
|
|
7506
7671
|
}
|
|
7507
7672
|
async remove(sessionId) {
|
|
7508
7673
|
await pendingWrites.get(join14(this.dir(sessionId), "session.json"));
|
|
7509
|
-
await
|
|
7674
|
+
await rm7(this.dir(sessionId), { recursive: true, force: true });
|
|
7510
7675
|
}
|
|
7511
7676
|
/** Scratch working directory for a session without a repository. */
|
|
7512
7677
|
scratchDir(sessionId) {
|
|
@@ -9324,7 +9489,7 @@ var SessionManager = class {
|
|
|
9324
9489
|
})
|
|
9325
9490
|
);
|
|
9326
9491
|
}
|
|
9327
|
-
await
|
|
9492
|
+
await rm8(w.cwd, { recursive: true, force: true }).catch(() => void 0);
|
|
9328
9493
|
}
|
|
9329
9494
|
}
|
|
9330
9495
|
keptFile() {
|
|
@@ -9592,6 +9757,8 @@ var RunnerDaemon = class {
|
|
|
9592
9757
|
this.jobs = new JobManager({
|
|
9593
9758
|
stateDir: opts.config.stateDir,
|
|
9594
9759
|
maxJobs: opts.config.maxJobs,
|
|
9760
|
+
logRetentionDays: opts.config.jobLogRetentionDays,
|
|
9761
|
+
dataRetentionDays: opts.config.jobDataRetentionDays,
|
|
9595
9762
|
poster: this.api,
|
|
9596
9763
|
logger: opts.logger,
|
|
9597
9764
|
onUnauthorized: (err) => this.unauthorized(err),
|
|
@@ -9668,6 +9835,7 @@ var RunnerDaemon = class {
|
|
|
9668
9835
|
await this.jobs.restore();
|
|
9669
9836
|
await this.manager.restore();
|
|
9670
9837
|
await this.manager.releaseKeptForJobs();
|
|
9838
|
+
this.jobs.startPruning();
|
|
9671
9839
|
logger.info(`dt-runner ${RUNNER_VERSION} connected to ${config.server}`, {
|
|
9672
9840
|
maxSessions: config.maxSessions,
|
|
9673
9841
|
maxJobs: config.maxJobs,
|
|
@@ -10271,9 +10439,13 @@ Usage:
|
|
|
10271
10439
|
dt-runner login [--server <url>] [--name <name>] [--no-browser] [--yes]
|
|
10272
10440
|
Pair this computer with your Discovery Tree account.
|
|
10273
10441
|
--yes skips the "is this your account?" question.
|
|
10274
|
-
dt-runner start [--max-sessions <n>] [--max-jobs <n>] [--
|
|
10442
|
+
dt-runner start [--max-sessions <n>] [--max-jobs <n>] [--job-log-retention-days <n>]
|
|
10443
|
+
[--job-data-retention-days <n>] [--repos-dir <dir>] [--json] [--verbose]
|
|
10275
10444
|
Run: wait for agent sessions and run them with Claude Code,
|
|
10276
10445
|
and run the jobs you approve (up to --max-jobs at once).
|
|
10446
|
+
Ended jobs' logs are removed after --job-log-retention-days
|
|
10447
|
+
(default 30; 0 keeps them), their data folders after
|
|
10448
|
+
--job-data-retention-days (default 0: kept).
|
|
10277
10449
|
dt-runner status Show the configuration and check the connection.
|
|
10278
10450
|
dt-runner doctor Check Node.js, git and Claude Code on this computer.
|
|
10279
10451
|
dt-runner logout Forget this runner's token (deletes the config file).
|
|
@@ -10304,6 +10476,8 @@ async function main(argv) {
|
|
|
10304
10476
|
yes: { type: "boolean", short: "y" },
|
|
10305
10477
|
"max-sessions": { type: "string" },
|
|
10306
10478
|
"max-jobs": { type: "string" },
|
|
10479
|
+
"job-log-retention-days": { type: "string" },
|
|
10480
|
+
"job-data-retention-days": { type: "string" },
|
|
10307
10481
|
"repos-dir": { type: "string" },
|
|
10308
10482
|
json: { type: "boolean" },
|
|
10309
10483
|
verbose: { type: "boolean" },
|
|
@@ -10325,8 +10499,10 @@ async function main(argv) {
|
|
|
10325
10499
|
return login(values.server, values.name, !values["no-browser"], values.yes === true);
|
|
10326
10500
|
case "start":
|
|
10327
10501
|
return start({
|
|
10328
|
-
maxSessions:
|
|
10329
|
-
maxJobs:
|
|
10502
|
+
maxSessions: numberFlag(values["max-sessions"]),
|
|
10503
|
+
maxJobs: numberFlag(values["max-jobs"]),
|
|
10504
|
+
jobLogRetentionDays: numberFlag(values["job-log-retention-days"]),
|
|
10505
|
+
jobDataRetentionDays: numberFlag(values["job-data-retention-days"]),
|
|
10330
10506
|
reposDir: values["repos-dir"],
|
|
10331
10507
|
json: values.json,
|
|
10332
10508
|
verbose: values.verbose
|
|
@@ -10412,6 +10588,8 @@ async function start(opts) {
|
|
|
10412
10588
|
const config = resolveConfig(await readConfigFile(paths.configFile), {
|
|
10413
10589
|
maxSessions: opts.maxSessions,
|
|
10414
10590
|
maxJobs: opts.maxJobs,
|
|
10591
|
+
jobLogRetentionDays: opts.jobLogRetentionDays,
|
|
10592
|
+
jobDataRetentionDays: opts.jobDataRetentionDays,
|
|
10415
10593
|
reposDir: opts.reposDir
|
|
10416
10594
|
});
|
|
10417
10595
|
if (!config.token) {
|
|
@@ -10493,6 +10671,9 @@ async function start(opts) {
|
|
|
10493
10671
|
logger.info("dt-runner stopped");
|
|
10494
10672
|
return exit === "unauthorized" ? 1 : 0;
|
|
10495
10673
|
}
|
|
10674
|
+
function keptFor(days) {
|
|
10675
|
+
return days > 0 ? `kept ${days} day(s)` : "kept for good";
|
|
10676
|
+
}
|
|
10496
10677
|
async function status() {
|
|
10497
10678
|
const paths = runnerPaths();
|
|
10498
10679
|
const file = await readConfigFile(paths.configFile);
|
|
@@ -10509,6 +10690,8 @@ async function status() {
|
|
|
10509
10690
|
`Sessions: up to ${config.maxSessions} at once, permission mode ${config.permissionMode}`
|
|
10510
10691
|
);
|
|
10511
10692
|
console.log(`Jobs: up to ${config.maxJobs} at once`);
|
|
10693
|
+
console.log(`Job logs: ${keptFor(config.jobLogRetentionDays)} after a job ends`);
|
|
10694
|
+
console.log(`Job data: ${keptFor(config.jobDataRetentionDays)} after a job ends`);
|
|
10512
10695
|
console.log(`Repos: ${config.reposDir}`);
|
|
10513
10696
|
console.log(`Worktrees: ${config.worktreesDir}`);
|
|
10514
10697
|
console.log(`State: ${config.stateDir}`);
|
package/package.json
CHANGED