@discovery-tree/runner 0.1.22 → 0.1.23
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 +19 -18
- package/dist/cli.js +163 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -86,23 +86,24 @@ readable only by you (mode 0600) because it holds the runner token. `login` writ
|
|
|
86
86
|
}
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
-
| Option | Default | Meaning
|
|
90
|
-
| ------------------------------ | ------------------------------------------------ |
|
|
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
|
-
| `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.
|
|
95
|
-
| `
|
|
96
|
-
| `
|
|
97
|
-
| `
|
|
98
|
-
| `
|
|
99
|
-
| `
|
|
100
|
-
| `
|
|
101
|
-
| `
|
|
102
|
-
| `
|
|
103
|
-
| `
|
|
104
|
-
| `
|
|
105
|
-
| `
|
|
89
|
+
| Option | Default | Meaning |
|
|
90
|
+
| ------------------------------ | ------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
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
|
+
| `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. |
|
|
95
|
+
| `jobShell` | `powershell` | Windows only: the shell jobs run in: `powershell` (5.1, no `&&`), `pwsh` (PowerShell 7) or `cmd`. Not on the PATH: jobs are refused. `--job-shell` overrides it. |
|
|
96
|
+
| `reposDir` | `$XDG_DATA_HOME/discovery-tree/runner/repos` | Clone cache. `--repos-dir` overrides it. |
|
|
97
|
+
| `worktreesDir` | `$XDG_DATA_HOME/discovery-tree/runner/worktrees` | One worktree per session. |
|
|
98
|
+
| `permissionMode` | `auto` | Claude Code `--permission-mode`. See below. |
|
|
99
|
+
| `allowedTools` | a development allow-list | Replaces the default `--allowedTools` list. |
|
|
100
|
+
| `extraAllowedTools` | `[]` | Added to the allow-list. |
|
|
101
|
+
| `disallowedTools` | credential locations (see below) | Replaces the default `--disallowedTools` deny list. Deny rules win over the allow-list. |
|
|
102
|
+
| `extraDisallowedTools` | `[]` | Added to the deny list. |
|
|
103
|
+
| `loadProjectSettings` | `false` | `true` lets Claude Code load the repository's own `.claude/settings.json` / `settings.local.json` (hooks, permissions). See below. |
|
|
104
|
+
| `inheritClaudeCodePermissions` | `true` | Start each run with the permission rules you approved in your own Claude Code for that repository (see below). `false` turns it off. |
|
|
105
|
+
| `gitProtocol` | `https` | `ssh` clones `git@github.com:owner/repo.git` instead. The cached clone's `origin` URL is rewritten to match on every session start (see below). |
|
|
106
|
+
| `idleTimeoutMinutes` | `15` | An idle Claude Code process is ended after this long; the next message resumes it. |
|
|
106
107
|
|
|
107
108
|
Environment variables: `DT_SERVER_URL` (server), `DT_RUNNER_TOKEN` (token; overrides the file),
|
|
108
109
|
`DT_RUNNER_CLAUDE_BIN` (the `claude` binary to run).
|
|
@@ -356,7 +357,7 @@ it leaves it running (the session's worktree stays until the job ends, then goes
|
|
|
356
357
|
- **Where it runs.** In the directory you approved, with the tree's environment over the
|
|
357
358
|
runner's own (secrets in memory only, redacted from what is posted; never the runner's
|
|
358
359
|
token). On macOS and Linux the command runs in `/bin/sh`, in a process group of its own; on
|
|
359
|
-
Windows in Windows PowerShell (`powershell.exe`).
|
|
360
|
+
Windows in Windows PowerShell (`powershell.exe`) unless you set `jobShell` (below).
|
|
360
361
|
- **Its data folder.** Each job gets `<state>/jobs/<job id>/data/` (owner-only), its path in
|
|
361
362
|
`DT_JOB_DATA_DIR`, for what it produces (a recording, a report). It is outside every
|
|
362
363
|
session's checkout, so it stays when the checkout is removed (7 days after the job ends),
|
package/dist/cli.js
CHANGED
|
@@ -583,6 +583,7 @@ var ENV_SETUP_SCRIPT_MAX_LENGTH = 16 * 1024;
|
|
|
583
583
|
|
|
584
584
|
// ../contracts/src/tree-autonomy.ts
|
|
585
585
|
var MAX_AUTO_RETRY_DELAY_MINUTES = 24 * 60;
|
|
586
|
+
var MAX_AUTO_DECIDE_GRACE_MINUTES = 7 * 24 * 60;
|
|
586
587
|
|
|
587
588
|
// ../contracts/src/shared-artifacts.ts
|
|
588
589
|
var SHARED_ARTIFACT_TEXT_MAX_BYTES = 1024 * 1024;
|
|
@@ -678,7 +679,7 @@ function toolGrantRepositoryKey(url) {
|
|
|
678
679
|
var RUN_STUCK_TOOL_CALL_AFTER_MS = 15 * 6e4;
|
|
679
680
|
|
|
680
681
|
// src/version.ts
|
|
681
|
-
var RUNNER_VERSION = true ? "0.1.
|
|
682
|
+
var RUNNER_VERSION = true ? "0.1.23" : "0.0.0-dev";
|
|
682
683
|
var RUNNER_PLATFORM = `${process.platform}-${process.arch}`;
|
|
683
684
|
|
|
684
685
|
// src/api.ts
|
|
@@ -3931,6 +3932,7 @@ function applyCursorPermissions(cwd, rules) {
|
|
|
3931
3932
|
if (read === "unreadable") return;
|
|
3932
3933
|
const hadPermissions = read !== null && isObject2(read.permissions);
|
|
3933
3934
|
const hadAllow = hadPermissions && Array.isArray(read.permissions.allow);
|
|
3935
|
+
const hadDeny = hadPermissions && Array.isArray(read.permissions.deny);
|
|
3934
3936
|
const config = read ?? {};
|
|
3935
3937
|
const permissions = permissionsOf(config);
|
|
3936
3938
|
const previous = new Set(marker?.added ?? []);
|
|
@@ -3942,10 +3944,19 @@ function applyCursorPermissions(cwd, rules) {
|
|
|
3942
3944
|
}
|
|
3943
3945
|
if (!keepOutOfCommits(cwd)) return;
|
|
3944
3946
|
permissions.allow = [...own, ...added];
|
|
3947
|
+
if (permissions.deny === void 0) permissions.deny = [];
|
|
3945
3948
|
config.permissions = permissions;
|
|
3946
3949
|
const written = `${JSON.stringify(config, null, 2)}
|
|
3947
3950
|
`;
|
|
3948
|
-
const next = marker ? { ...marker, added, written } : {
|
|
3951
|
+
const next = marker ? { ...marker, added, written } : {
|
|
3952
|
+
added,
|
|
3953
|
+
created: read === null,
|
|
3954
|
+
original: text,
|
|
3955
|
+
written,
|
|
3956
|
+
hadPermissions,
|
|
3957
|
+
hadAllow,
|
|
3958
|
+
hadDeny
|
|
3959
|
+
};
|
|
3949
3960
|
mkdirSync(dirname4(file), { recursive: true });
|
|
3950
3961
|
writeFileSync(join6(cwd, MARKER), `${JSON.stringify(next)}
|
|
3951
3962
|
`);
|
|
@@ -3972,6 +3983,8 @@ function removeCursorPermissions(cwd) {
|
|
|
3972
3983
|
const allow = allowOf(permissions).filter((r) => !added.has(r));
|
|
3973
3984
|
if (allow.length || marker.hadAllow) permissions.allow = allow;
|
|
3974
3985
|
else delete permissions.allow;
|
|
3986
|
+
const deny = permissions.deny;
|
|
3987
|
+
if (!marker.hadDeny && Array.isArray(deny) && deny.length === 0) delete permissions.deny;
|
|
3975
3988
|
if (Object.keys(permissions).length || marker.hadPermissions)
|
|
3976
3989
|
read.permissions = permissions;
|
|
3977
3990
|
else delete read.permissions;
|
|
@@ -4007,18 +4020,31 @@ function readMarker(cwd) {
|
|
|
4007
4020
|
try {
|
|
4008
4021
|
const m = JSON.parse(readFileSync(join6(cwd, MARKER), "utf8"));
|
|
4009
4022
|
if (!Array.isArray(m.added) || typeof m.written !== "string") return null;
|
|
4023
|
+
const original = typeof m.original === "string" ? m.original : null;
|
|
4010
4024
|
return {
|
|
4011
4025
|
added: m.added.filter((r) => typeof r === "string"),
|
|
4012
4026
|
created: m.created === true,
|
|
4013
|
-
original
|
|
4027
|
+
original,
|
|
4014
4028
|
written: m.written,
|
|
4015
4029
|
hadPermissions: m.hadPermissions === true,
|
|
4016
|
-
hadAllow: m.hadAllow === true
|
|
4030
|
+
hadAllow: m.hadAllow === true,
|
|
4031
|
+
// A marker from before the runner wrote `deny` (0.1.21) says nothing of it: the file as
|
|
4032
|
+
// it was before the runner first wrote it does.
|
|
4033
|
+
hadDeny: typeof m.hadDeny === "boolean" ? m.hadDeny : originalHadDeny(original)
|
|
4017
4034
|
};
|
|
4018
4035
|
} catch {
|
|
4019
4036
|
return null;
|
|
4020
4037
|
}
|
|
4021
4038
|
}
|
|
4039
|
+
function originalHadDeny(original) {
|
|
4040
|
+
if (original === null) return false;
|
|
4041
|
+
try {
|
|
4042
|
+
const parsed = JSON.parse(original);
|
|
4043
|
+
return Array.isArray(parsed?.permissions?.deny);
|
|
4044
|
+
} catch {
|
|
4045
|
+
return false;
|
|
4046
|
+
}
|
|
4047
|
+
}
|
|
4022
4048
|
var isObject2 = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
4023
4049
|
function readConfig(file) {
|
|
4024
4050
|
if (!existsSync(file)) return null;
|
|
@@ -4113,6 +4139,9 @@ var cursorDriver = {
|
|
|
4113
4139
|
if (cursorResumeNotFound(stderr)) {
|
|
4114
4140
|
return " The Cursor chat to resume was not found on this computer.";
|
|
4115
4141
|
}
|
|
4142
|
+
if (cursorConfigInvalid(stderr)) {
|
|
4143
|
+
return " The Cursor Agent CLI rejected a config file: check the worktree\u2019s `.cursor/cli.json` and `~/.cursor/cli-config.json` on the runner\u2019s computer (each `permissions` needs both `allow` and `deny` lists).";
|
|
4144
|
+
}
|
|
4116
4145
|
return "";
|
|
4117
4146
|
},
|
|
4118
4147
|
resumeNotFound: (stderr) => cursorResumeNotFound(stderr)
|
|
@@ -4122,6 +4151,9 @@ function cursorResumeNotFound(text) {
|
|
|
4122
4151
|
text
|
|
4123
4152
|
);
|
|
4124
4153
|
}
|
|
4154
|
+
function cursorConfigInvalid(text) {
|
|
4155
|
+
return /Invalid input: expected \w+, received \w+/.test(text);
|
|
4156
|
+
}
|
|
4125
4157
|
function turnErrorMessage3(turn) {
|
|
4126
4158
|
if (turn.isError && looksLikeCursorSignInFailure(turn.text)) {
|
|
4127
4159
|
return `The Cursor Agent CLI could not sign in (${turn.text.slice(0, 200)}). ${cursorSignInFix()} Then send a message here to try again.`;
|
|
@@ -4417,6 +4449,8 @@ function configDirRules(configFile, platform = process.platform) {
|
|
|
4417
4449
|
var DEFAULT_SERVER_URL = "https://discovery-tree-backend.onrender.com";
|
|
4418
4450
|
var DEFAULT_MAX_SESSIONS = 2;
|
|
4419
4451
|
var DEFAULT_IDLE_TIMEOUT_MINUTES = 15;
|
|
4452
|
+
var JOB_SHELLS = ["powershell", "pwsh", "cmd"];
|
|
4453
|
+
var DEFAULT_JOB_SHELL = "powershell";
|
|
4420
4454
|
var DEFAULT_JOB_LOG_RETENTION_DAYS = 30;
|
|
4421
4455
|
var JOB_RETENTION_DAYS_LIMIT = 3650;
|
|
4422
4456
|
async function readConfigFile(file) {
|
|
@@ -4481,6 +4515,7 @@ function resolveConfig(file, overrides = {}, env = process.env, paths = runnerPa
|
|
|
4481
4515
|
"jobDataRetentionDays",
|
|
4482
4516
|
overrides.jobDataRetentionDays ?? file?.jobDataRetentionDays ?? 0
|
|
4483
4517
|
);
|
|
4518
|
+
const jobShell = jobShellOf(overrides.jobShell ?? file?.jobShell);
|
|
4484
4519
|
const inherit = file?.inheritClaudeCodePermissions;
|
|
4485
4520
|
if (inherit !== void 0 && typeof inherit !== "boolean") {
|
|
4486
4521
|
throw new Error(
|
|
@@ -4531,6 +4566,7 @@ function resolveConfig(file, overrides = {}, env = process.env, paths = runnerPa
|
|
|
4531
4566
|
maxJobs,
|
|
4532
4567
|
jobLogRetentionDays,
|
|
4533
4568
|
jobDataRetentionDays,
|
|
4569
|
+
jobShell,
|
|
4534
4570
|
reposDir: overrides.reposDir ?? file?.reposDir ?? join7(paths.dataDir, "repos"),
|
|
4535
4571
|
worktreesDir: file?.worktreesDir ?? join7(paths.dataDir, "worktrees"),
|
|
4536
4572
|
permissionMode: mode,
|
|
@@ -4550,6 +4586,17 @@ function resolveConfig(file, overrides = {}, env = process.env, paths = runnerPa
|
|
|
4550
4586
|
configFile: paths.configFile
|
|
4551
4587
|
};
|
|
4552
4588
|
}
|
|
4589
|
+
function jobShellOf(value) {
|
|
4590
|
+
if (value === void 0) return DEFAULT_JOB_SHELL;
|
|
4591
|
+
const name = typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
4592
|
+
const shell = JOB_SHELLS.find((s) => s === name);
|
|
4593
|
+
if (!shell) {
|
|
4594
|
+
throw new Error(
|
|
4595
|
+
`jobShell must be one of ${JOB_SHELLS.join(", ")} (got ${typeof value === "string" ? `"${value}"` : JSON.stringify(value)}).`
|
|
4596
|
+
);
|
|
4597
|
+
}
|
|
4598
|
+
return shell;
|
|
4599
|
+
}
|
|
4553
4600
|
function retentionDays(key, days) {
|
|
4554
4601
|
if (!Number.isInteger(days) || days < 0 || days > JOB_RETENTION_DAYS_LIMIT) {
|
|
4555
4602
|
throw new Error(
|
|
@@ -5424,9 +5471,9 @@ var JobOutbox = class _JobOutbox {
|
|
|
5424
5471
|
|
|
5425
5472
|
// src/jobs/job-process.ts
|
|
5426
5473
|
import { execFile, spawn as spawn4 } from "node:child_process";
|
|
5427
|
-
import { closeSync, openSync, readFileSync as readFileSync2, readdirSync } from "node:fs";
|
|
5474
|
+
import { closeSync, existsSync as existsSync2, openSync, readFileSync as readFileSync2, readdirSync } from "node:fs";
|
|
5428
5475
|
import { readFile as readFile7, writeFile as writeFile4 } from "node:fs/promises";
|
|
5429
|
-
import { dirname as dirname7, join as join10 } from "node:path";
|
|
5476
|
+
import { dirname as dirname7, join as join10, win32 } from "node:path";
|
|
5430
5477
|
|
|
5431
5478
|
// src/lock.ts
|
|
5432
5479
|
import { mkdir as mkdir5, open as open2, readFile as readFile6, rm as rm5 } from "node:fs/promises";
|
|
@@ -5489,6 +5536,31 @@ async function acquireDaemonLock(stateDir, pid = process.pid) {
|
|
|
5489
5536
|
|
|
5490
5537
|
// src/jobs/job-process.ts
|
|
5491
5538
|
var JOB_IS_WINDOWS = process.platform === "win32";
|
|
5539
|
+
function jobShellProgram(shell) {
|
|
5540
|
+
return shell === "cmd" ? "cmd.exe" : shell === "pwsh" ? "pwsh.exe" : "powershell.exe";
|
|
5541
|
+
}
|
|
5542
|
+
function findJobShell(shell, env = process.env) {
|
|
5543
|
+
const program = jobShellProgram(shell);
|
|
5544
|
+
const pathKey = Object.keys(env).find((k) => k.toLowerCase() === "path");
|
|
5545
|
+
const dirs = (pathKey ? env[pathKey] ?? "" : "").split(";").map((d) => d.trim().replace(/^"|"$/g, ""));
|
|
5546
|
+
const root = env.SystemRoot ?? env.SYSTEMROOT ?? env.windir;
|
|
5547
|
+
if (root) {
|
|
5548
|
+
const system32 = win32.join(root, "System32");
|
|
5549
|
+
if (shell === "cmd") dirs.push(system32);
|
|
5550
|
+
if (shell === "powershell") dirs.push(win32.join(system32, "WindowsPowerShell", "v1.0"));
|
|
5551
|
+
}
|
|
5552
|
+
for (const dir of dirs) {
|
|
5553
|
+
if (!dir) continue;
|
|
5554
|
+
const candidate = win32.join(dir, program);
|
|
5555
|
+
if (existsSync2(candidate)) return candidate;
|
|
5556
|
+
}
|
|
5557
|
+
return null;
|
|
5558
|
+
}
|
|
5559
|
+
function jobShellProblem(shell, env = process.env) {
|
|
5560
|
+
if (!JOB_IS_WINDOWS || findJobShell(shell, env)) return null;
|
|
5561
|
+
const others = ["powershell", "pwsh", "cmd"].filter((s) => s !== shell);
|
|
5562
|
+
return `The job shell "${shell}" (${jobShellProgram(shell)}) is not on this computer's PATH, so jobs are refused. Install it, or set jobShell to ${others.map((s) => `"${s}"`).join(" or ")} in the runner's config (or start with --job-shell).`;
|
|
5563
|
+
}
|
|
5492
5564
|
var POWERSHELL_FLAGS = [
|
|
5493
5565
|
"-NoLogo",
|
|
5494
5566
|
"-NoProfile",
|
|
@@ -5530,29 +5602,58 @@ function powershellCommandScript(command) {
|
|
|
5530
5602
|
"if ($dtRunnerOk) { exit 0 } elseif ($dtRunnerLast) { exit $dtRunnerLast } else { exit 1 }"
|
|
5531
5603
|
].join("\n");
|
|
5532
5604
|
}
|
|
5533
|
-
function powershellJobScript(commandFile, exitFile) {
|
|
5605
|
+
function powershellJobScript(commandFile, exitFile, host = "powershell.exe") {
|
|
5534
5606
|
return [
|
|
5535
5607
|
"$ErrorActionPreference = 'Continue'",
|
|
5536
5608
|
"$ProgressPreference = 'SilentlyContinue'",
|
|
5537
5609
|
"try { [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding $false } catch {}",
|
|
5538
|
-
`&
|
|
5610
|
+
`& ${psQuote(host)} ${POWERSHELL_FLAGS.join(" ")} -File ${psQuote(commandFile)}`,
|
|
5539
5611
|
"$dtRunnerCode = $LASTEXITCODE",
|
|
5540
5612
|
"if ($null -eq $dtRunnerCode) { $dtRunnerCode = 1 }",
|
|
5541
5613
|
`try { [IO.File]::WriteAllText(${psQuote(exitFile)}, [string]$dtRunnerCode) } catch {}`,
|
|
5542
5614
|
"exit $dtRunnerCode"
|
|
5543
5615
|
].join("\n");
|
|
5544
5616
|
}
|
|
5617
|
+
function batchPath(path) {
|
|
5618
|
+
return path.replace(/%/g, "%%");
|
|
5619
|
+
}
|
|
5620
|
+
function cmdCommandScript(command) {
|
|
5621
|
+
return [
|
|
5622
|
+
"@echo off",
|
|
5623
|
+
"@chcp 65001 >nul",
|
|
5624
|
+
command.replace(/\r?\n/g, "\r\n"),
|
|
5625
|
+
"exit /b %ERRORLEVEL%",
|
|
5626
|
+
""
|
|
5627
|
+
].join("\r\n");
|
|
5628
|
+
}
|
|
5629
|
+
function cmdJobScript(commandFile, exitFile, cmdPath = "cmd.exe") {
|
|
5630
|
+
const tmp = `${exitFile}.tmp`;
|
|
5631
|
+
return [
|
|
5632
|
+
"@echo off",
|
|
5633
|
+
// Before any path: `cmd` reads this file in the OEM code page until then, and the state
|
|
5634
|
+
// folder may be under a user name with an accented letter.
|
|
5635
|
+
"@chcp 65001 >nul",
|
|
5636
|
+
`"${batchPath(cmdPath)}" /d /s /c ""${batchPath(commandFile)}""`,
|
|
5637
|
+
'set "DT_RUNNER_CODE=%ERRORLEVEL%"',
|
|
5638
|
+
// The code is written next to the file and renamed, so a half-written one is never read.
|
|
5639
|
+
`>"${batchPath(tmp)}" echo %DT_RUNNER_CODE%`,
|
|
5640
|
+
`move /y "${batchPath(tmp)}" "${batchPath(exitFile)}" >nul`,
|
|
5641
|
+
"exit /b %DT_RUNNER_CODE%",
|
|
5642
|
+
""
|
|
5643
|
+
].join("\r\n");
|
|
5644
|
+
}
|
|
5545
5645
|
function psLiteralPath(path) {
|
|
5546
5646
|
return `([WildcardPattern]::Escape(${psQuote(path)}))`;
|
|
5547
5647
|
}
|
|
5548
5648
|
function windowsLauncherScript(input) {
|
|
5549
|
-
const
|
|
5649
|
+
const shell = input.shell ?? DEFAULT_JOB_SHELL;
|
|
5650
|
+
const args = shell === "cmd" ? ["/d", "/s", "/c", `""${input.scriptFile}""`].join(" ") : [...POWERSHELL_FLAGS, "-File", `"${input.scriptFile}"`].join(" ");
|
|
5550
5651
|
return [
|
|
5551
5652
|
"$ErrorActionPreference = 'Stop'",
|
|
5552
5653
|
"$ProgressPreference = 'SilentlyContinue'",
|
|
5553
5654
|
// Started here: Start-Process takes the current location as the job's directory.
|
|
5554
5655
|
`Set-Location -LiteralPath ${psQuote(input.cwd)}`,
|
|
5555
|
-
`$p = Start-Process -FilePath
|
|
5656
|
+
`$p = Start-Process -FilePath ${psQuote(input.shellPath ?? jobShellProgram(shell))} -ArgumentList ${psQuote(args)} -NoNewWindow -PassThru -RedirectStandardOutput ${psLiteralPath(input.stdoutFile)} -RedirectStandardError ${psLiteralPath(input.stderrFile)}`,
|
|
5556
5657
|
// A command that is over already has no start time to read: now is close enough.
|
|
5557
5658
|
"$dtRunnerAt = $null",
|
|
5558
5659
|
"try { $dtRunnerAt = ([DateTimeOffset]$p.StartTime).ToUnixTimeMilliseconds() } catch { $dtRunnerAt = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds() }",
|
|
@@ -5588,21 +5689,32 @@ async function spawnJob(input) {
|
|
|
5588
5689
|
return { pid: child.pid, startedAt: Date.now() - 500, child, exited };
|
|
5589
5690
|
}
|
|
5590
5691
|
async function spawnWindowsJob(input) {
|
|
5692
|
+
const shell = input.shell ?? DEFAULT_JOB_SHELL;
|
|
5693
|
+
const shellPath = findJobShell(shell, process.env);
|
|
5694
|
+
if (!shellPath) throw new Error(jobShellProblem(shell, process.env) ?? `${shell} was not found.`);
|
|
5591
5695
|
const dir = dirname7(input.exitFile);
|
|
5592
|
-
const
|
|
5593
|
-
const
|
|
5594
|
-
const
|
|
5595
|
-
|
|
5696
|
+
const cmd = shell === "cmd";
|
|
5697
|
+
const scriptFile = join10(dir, cmd ? "job.cmd" : "job.ps1");
|
|
5698
|
+
const commandFile = join10(dir, cmd ? "command.cmd" : "command.ps1");
|
|
5699
|
+
if (cmd) {
|
|
5700
|
+
await writeFile4(commandFile, cmdCommandScript(input.command), { mode: 384 });
|
|
5701
|
+
} else {
|
|
5702
|
+
await writeFile4(commandFile, "\uFEFF" + powershellCommandScript(input.command), {
|
|
5703
|
+
mode: 384
|
|
5704
|
+
});
|
|
5705
|
+
}
|
|
5596
5706
|
for (const f of [input.stdoutFile, input.stderrFile]) await writeFile4(f, "", { flag: "a" });
|
|
5597
|
-
await writeFile4(
|
|
5598
|
-
|
|
5599
|
-
|
|
5707
|
+
await writeFile4(
|
|
5708
|
+
scriptFile,
|
|
5709
|
+
cmd ? cmdJobScript(commandFile, input.exitFile, shellPath) : "\uFEFF" + powershellJobScript(commandFile, input.exitFile, shellPath),
|
|
5710
|
+
{ mode: 384 }
|
|
5711
|
+
);
|
|
5600
5712
|
const launcher = spawn4(
|
|
5601
5713
|
"powershell.exe",
|
|
5602
5714
|
[
|
|
5603
5715
|
...POWERSHELL_FLAGS,
|
|
5604
5716
|
"-EncodedCommand",
|
|
5605
|
-
encoded(windowsLauncherScript({ ...input, scriptFile }))
|
|
5717
|
+
encoded(windowsLauncherScript({ ...input, scriptFile, shell, shellPath }))
|
|
5606
5718
|
],
|
|
5607
5719
|
// Piped (nothing inherited), so Node gives it a console without a window.
|
|
5608
5720
|
{ cwd: input.cwd, env: input.env, stdio: ["ignore", "pipe", "pipe"], windowsHide: true }
|
|
@@ -5815,6 +5927,8 @@ var JobManager = class {
|
|
|
5815
5927
|
constructor(opts) {
|
|
5816
5928
|
this.opts = opts;
|
|
5817
5929
|
this.root = join11(opts.stateDir, "jobs");
|
|
5930
|
+
const problem = this.shellProblem();
|
|
5931
|
+
if (problem) opts.logger.error(problem);
|
|
5818
5932
|
}
|
|
5819
5933
|
jobs = /* @__PURE__ */ new Map();
|
|
5820
5934
|
/** Folders being removed now, with how many removals hold each (see `holdForRemoval`). */
|
|
@@ -5835,6 +5949,13 @@ var JobManager = class {
|
|
|
5835
5949
|
/** Resolves when the runner begins to stop: an end waiting for secrets waits no more. */
|
|
5836
5950
|
stopped = secretWait();
|
|
5837
5951
|
root;
|
|
5952
|
+
/** Why jobs cannot run in the job shell (not on the PATH), when they cannot. */
|
|
5953
|
+
shellProblem() {
|
|
5954
|
+
return (this.opts.checkJobShell ?? ((s) => jobShellProblem(s)))(this.shell);
|
|
5955
|
+
}
|
|
5956
|
+
get shell() {
|
|
5957
|
+
return this.opts.jobShell ?? DEFAULT_JOB_SHELL;
|
|
5958
|
+
}
|
|
5838
5959
|
/** The folder a job's record, log and outbox live in. */
|
|
5839
5960
|
jobDir(jobId) {
|
|
5840
5961
|
return join11(this.root, jobId);
|
|
@@ -6216,6 +6337,8 @@ var JobManager = class {
|
|
|
6216
6337
|
if (this.shuttingDown) {
|
|
6217
6338
|
return { ok: false, retryable: true, error: "The runner is shutting down." };
|
|
6218
6339
|
}
|
|
6340
|
+
const shellProblem = this.shellProblem();
|
|
6341
|
+
if (shellProblem) return { ok: false, error: shellProblem };
|
|
6219
6342
|
const command = typeof cmd.command === "string" ? cmd.command : "";
|
|
6220
6343
|
if (!command.trim() || command.includes("\0")) {
|
|
6221
6344
|
return { ok: false, error: "The job has no command to run." };
|
|
@@ -6308,7 +6431,8 @@ var JobManager = class {
|
|
|
6308
6431
|
env,
|
|
6309
6432
|
stdoutFile: join11(dir, "stdout.log"),
|
|
6310
6433
|
stderrFile: join11(dir, "stderr.log"),
|
|
6311
|
-
exitFile: join11(dir, "exit-code")
|
|
6434
|
+
exitFile: join11(dir, "exit-code"),
|
|
6435
|
+
shell: this.shell
|
|
6312
6436
|
});
|
|
6313
6437
|
} catch (err) {
|
|
6314
6438
|
const error = safeError(err, redactor);
|
|
@@ -6861,7 +6985,7 @@ function safeError(err, redactor) {
|
|
|
6861
6985
|
}
|
|
6862
6986
|
|
|
6863
6987
|
// src/session-manager.ts
|
|
6864
|
-
import { existsSync as
|
|
6988
|
+
import { existsSync as existsSync3, lstatSync } from "node:fs";
|
|
6865
6989
|
import { mkdir as mkdir9, rm as rm8, writeFile as writeFile6 } from "node:fs/promises";
|
|
6866
6990
|
import { basename as basename3, dirname as dirname11, join as join15, resolve as resolve3 } from "node:path";
|
|
6867
6991
|
|
|
@@ -9171,9 +9295,9 @@ var SessionManager = class {
|
|
|
9171
9295
|
dir: fromEntry.dir,
|
|
9172
9296
|
repoDir: fromEntry.repoDir
|
|
9173
9297
|
} : void 0);
|
|
9174
|
-
const keptReference = candidate &&
|
|
9298
|
+
const keptReference = candidate && existsSync3(candidate.dir) ? candidate : void 0;
|
|
9175
9299
|
const referenceHold = !reference?.url ? null : this.opts.jobs ? this.opts.jobs.holdForRemoval(referenceDir) : () => void 0;
|
|
9176
|
-
if (reference?.url && keepWorkspace && (keptReference ||
|
|
9300
|
+
if (reference?.url && keepWorkspace && (keptReference || existsSync3(referenceDir))) {
|
|
9177
9301
|
if (keptReference) record.referenceRepository = keptReference;
|
|
9178
9302
|
referenceHold?.();
|
|
9179
9303
|
this.opts.logger.info(
|
|
@@ -9757,6 +9881,7 @@ var RunnerDaemon = class {
|
|
|
9757
9881
|
this.jobs = new JobManager({
|
|
9758
9882
|
stateDir: opts.config.stateDir,
|
|
9759
9883
|
maxJobs: opts.config.maxJobs,
|
|
9884
|
+
jobShell: opts.config.jobShell,
|
|
9760
9885
|
logRetentionDays: opts.config.jobLogRetentionDays,
|
|
9761
9886
|
dataRetentionDays: opts.config.jobDataRetentionDays,
|
|
9762
9887
|
poster: this.api,
|
|
@@ -10440,12 +10565,14 @@ Usage:
|
|
|
10440
10565
|
Pair this computer with your Discovery Tree account.
|
|
10441
10566
|
--yes skips the "is this your account?" question.
|
|
10442
10567
|
dt-runner start [--max-sessions <n>] [--max-jobs <n>] [--job-log-retention-days <n>]
|
|
10443
|
-
[--job-data-retention-days <n>] [--
|
|
10568
|
+
[--job-data-retention-days <n>] [--job-shell powershell|pwsh|cmd]
|
|
10569
|
+
[--repos-dir <dir>] [--json] [--verbose]
|
|
10444
10570
|
Run: wait for agent sessions and run them with Claude Code,
|
|
10445
10571
|
and run the jobs you approve (up to --max-jobs at once).
|
|
10446
10572
|
Ended jobs' logs are removed after --job-log-retention-days
|
|
10447
10573
|
(default 30; 0 keeps them), their data folders after
|
|
10448
10574
|
--job-data-retention-days (default 0: kept).
|
|
10575
|
+
On Windows, jobs run in --job-shell (default powershell).
|
|
10449
10576
|
dt-runner status Show the configuration and check the connection.
|
|
10450
10577
|
dt-runner doctor Check Node.js, git and Claude Code on this computer.
|
|
10451
10578
|
dt-runner logout Forget this runner's token (deletes the config file).
|
|
@@ -10478,6 +10605,7 @@ async function main(argv) {
|
|
|
10478
10605
|
"max-jobs": { type: "string" },
|
|
10479
10606
|
"job-log-retention-days": { type: "string" },
|
|
10480
10607
|
"job-data-retention-days": { type: "string" },
|
|
10608
|
+
"job-shell": { type: "string" },
|
|
10481
10609
|
"repos-dir": { type: "string" },
|
|
10482
10610
|
json: { type: "boolean" },
|
|
10483
10611
|
verbose: { type: "boolean" },
|
|
@@ -10503,6 +10631,7 @@ async function main(argv) {
|
|
|
10503
10631
|
maxJobs: numberFlag(values["max-jobs"]),
|
|
10504
10632
|
jobLogRetentionDays: numberFlag(values["job-log-retention-days"]),
|
|
10505
10633
|
jobDataRetentionDays: numberFlag(values["job-data-retention-days"]),
|
|
10634
|
+
jobShell: values["job-shell"],
|
|
10506
10635
|
reposDir: values["repos-dir"],
|
|
10507
10636
|
json: values.json,
|
|
10508
10637
|
verbose: values.verbose
|
|
@@ -10585,13 +10714,20 @@ async function login(server, name, openBrowser, yes) {
|
|
|
10585
10714
|
async function start(opts) {
|
|
10586
10715
|
const logger = createLogger({ json: opts.json, verbose: opts.verbose });
|
|
10587
10716
|
const paths = runnerPaths();
|
|
10588
|
-
const
|
|
10717
|
+
const file = await readConfigFile(paths.configFile);
|
|
10718
|
+
const config = resolveConfig(file, {
|
|
10589
10719
|
maxSessions: opts.maxSessions,
|
|
10590
10720
|
maxJobs: opts.maxJobs,
|
|
10591
10721
|
jobLogRetentionDays: opts.jobLogRetentionDays,
|
|
10592
10722
|
jobDataRetentionDays: opts.jobDataRetentionDays,
|
|
10723
|
+
jobShell: opts.jobShell,
|
|
10593
10724
|
reposDir: opts.reposDir
|
|
10594
10725
|
});
|
|
10726
|
+
if (process.platform !== "win32" && (opts.jobShell !== void 0 || file?.jobShell !== void 0)) {
|
|
10727
|
+
logger.warn(
|
|
10728
|
+
`jobShell "${config.jobShell}" is ignored: jobs run in /bin/sh here. It only chooses the shell on Windows.`
|
|
10729
|
+
);
|
|
10730
|
+
}
|
|
10595
10731
|
if (!config.token) {
|
|
10596
10732
|
logger.error(`This computer is not paired yet. Run \`${runnerCommand("login")}\` first.`);
|
|
10597
10733
|
return 1;
|
|
@@ -10692,6 +10828,9 @@ async function status() {
|
|
|
10692
10828
|
console.log(`Jobs: up to ${config.maxJobs} at once`);
|
|
10693
10829
|
console.log(`Job logs: ${keptFor(config.jobLogRetentionDays)} after a job ends`);
|
|
10694
10830
|
console.log(`Job data: ${keptFor(config.jobDataRetentionDays)} after a job ends`);
|
|
10831
|
+
console.log(
|
|
10832
|
+
`Job shell: ${process.platform === "win32" ? config.jobShell : `/bin/sh (jobShell "${config.jobShell}" only applies on Windows)`}`
|
|
10833
|
+
);
|
|
10695
10834
|
console.log(`Repos: ${config.reposDir}`);
|
|
10696
10835
|
console.log(`Worktrees: ${config.worktreesDir}`);
|
|
10697
10836
|
console.log(`State: ${config.stateDir}`);
|
package/package.json
CHANGED