@intellectual-frontiers/ergonex 0.2.2 → 0.2.5
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/ergonex.mjs +574 -111
- package/package.json +1 -1
package/ergonex.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// bin/main.ts
|
|
3
|
-
import
|
|
3
|
+
import process7 from "node:process";
|
|
4
4
|
|
|
5
5
|
// ../ts/kernel/absurd.ts
|
|
6
6
|
function absurd(value) {
|
|
@@ -2965,7 +2965,7 @@ import * as nfs from "node:fs";
|
|
|
2965
2965
|
import * as fsp from "node:fs/promises";
|
|
2966
2966
|
import { tmpdir } from "node:os";
|
|
2967
2967
|
import { basename, dirname, isAbsolute, join, parse, relative, resolve, sep } from "node:path";
|
|
2968
|
-
import
|
|
2968
|
+
import process2 from "node:process";
|
|
2969
2969
|
import { fileURLToPath } from "node:url";
|
|
2970
2970
|
|
|
2971
2971
|
// ../ts/runtime/errors.ts
|
|
@@ -3135,12 +3135,12 @@ function info(s) {
|
|
|
3135
3135
|
atime: time(s.atimeMs),
|
|
3136
3136
|
birthtime: time(s.birthtimeMs),
|
|
3137
3137
|
ctime: time(s.ctimeMs),
|
|
3138
|
-
mode:
|
|
3139
|
-
uid:
|
|
3140
|
-
gid:
|
|
3138
|
+
mode: process2.platform === "win32" ? null : s.mode,
|
|
3139
|
+
uid: process2.platform === "win32" ? null : s.uid,
|
|
3140
|
+
gid: process2.platform === "win32" ? null : s.gid,
|
|
3141
3141
|
dev: s.dev,
|
|
3142
|
-
ino:
|
|
3143
|
-
nlink:
|
|
3142
|
+
ino: process2.platform === "win32" ? null : s.ino,
|
|
3143
|
+
nlink: process2.platform === "win32" ? null : s.nlink
|
|
3144
3144
|
};
|
|
3145
3145
|
}
|
|
3146
3146
|
var entry = (d) => ({
|
|
@@ -3161,7 +3161,7 @@ async function write2(path, data, o) {
|
|
|
3161
3161
|
if (o.create === false)
|
|
3162
3162
|
await fsp.access(file);
|
|
3163
3163
|
await fsp.writeFile(file, data, { flag: flag3(o), ...modeOf(o) });
|
|
3164
|
-
if (o.mode !== undefined &&
|
|
3164
|
+
if (o.mode !== undefined && process2.platform !== "win32")
|
|
3165
3165
|
await fsp.chmod(file, o.mode);
|
|
3166
3166
|
});
|
|
3167
3167
|
}
|
|
@@ -3234,7 +3234,7 @@ function rename2(from, to) {
|
|
|
3234
3234
|
return hostCall(p(from), () => fsp.rename(p(from), p(to)));
|
|
3235
3235
|
}
|
|
3236
3236
|
async function chmod2(path, mode) {
|
|
3237
|
-
if (
|
|
3237
|
+
if (process2.platform === "win32")
|
|
3238
3238
|
return;
|
|
3239
3239
|
await hostCall(p(path), () => fsp.chmod(p(path), mode));
|
|
3240
3240
|
}
|
|
@@ -3351,7 +3351,7 @@ import { spawn as spawn_ } from "node:child_process";
|
|
|
3351
3351
|
import { statSync as statSync3 } from "node:fs";
|
|
3352
3352
|
import * as os from "node:os";
|
|
3353
3353
|
import { basename as basename4, delimiter as delimiter3, join as join4, resolve as resolvePath } from "node:path";
|
|
3354
|
-
import
|
|
3354
|
+
import process3 from "node:process";
|
|
3355
3355
|
|
|
3356
3356
|
// ../ts/runtime/otel.ts
|
|
3357
3357
|
var RETRYABLE_STATUSES = new Set([429, 502, 503, 504]);
|
|
@@ -3458,32 +3458,32 @@ var UNTRACED = new WeakSet;
|
|
|
3458
3458
|
// ../ts/runtime/proc.ts
|
|
3459
3459
|
var env = {
|
|
3460
3460
|
get(key) {
|
|
3461
|
-
return
|
|
3461
|
+
return process3.env[key];
|
|
3462
3462
|
},
|
|
3463
3463
|
set(key, value) {
|
|
3464
|
-
|
|
3464
|
+
process3.env[key] = value;
|
|
3465
3465
|
},
|
|
3466
3466
|
delete(key) {
|
|
3467
|
-
Reflect.deleteProperty(
|
|
3467
|
+
Reflect.deleteProperty(process3.env, key);
|
|
3468
3468
|
},
|
|
3469
3469
|
has(key) {
|
|
3470
|
-
return
|
|
3470
|
+
return process3.env[key] !== undefined;
|
|
3471
3471
|
},
|
|
3472
3472
|
toObject() {
|
|
3473
3473
|
const out = {};
|
|
3474
|
-
for (const [k, v] of Object.entries(
|
|
3474
|
+
for (const [k, v] of Object.entries(process3.env))
|
|
3475
3475
|
if (v !== undefined)
|
|
3476
3476
|
out[k] = v;
|
|
3477
3477
|
return out;
|
|
3478
3478
|
}
|
|
3479
3479
|
};
|
|
3480
|
-
var args = Object.freeze(
|
|
3480
|
+
var args = Object.freeze(process3.argv.slice(2));
|
|
3481
3481
|
function cwd() {
|
|
3482
|
-
return
|
|
3482
|
+
return process3.cwd();
|
|
3483
3483
|
}
|
|
3484
|
-
var pid =
|
|
3484
|
+
var pid = process3.pid;
|
|
3485
3485
|
function execPath() {
|
|
3486
|
-
return
|
|
3486
|
+
return process3.execPath;
|
|
3487
3487
|
}
|
|
3488
3488
|
function osOf(platform) {
|
|
3489
3489
|
switch (platform) {
|
|
@@ -3540,30 +3540,30 @@ function tripleOf(os2, arch) {
|
|
|
3540
3540
|
}
|
|
3541
3541
|
}
|
|
3542
3542
|
var build = Object.freeze({
|
|
3543
|
-
os: osOf(
|
|
3544
|
-
arch: archOf(
|
|
3545
|
-
target: tripleOf(osOf(
|
|
3543
|
+
os: osOf(process3.platform),
|
|
3544
|
+
arch: archOf(process3.arch),
|
|
3545
|
+
target: tripleOf(osOf(process3.platform), archOf(process3.arch))
|
|
3546
3546
|
});
|
|
3547
3547
|
function runtimeName() {
|
|
3548
|
-
const v =
|
|
3548
|
+
const v = process3.versions;
|
|
3549
3549
|
if (v["bun"] !== undefined)
|
|
3550
3550
|
return "bun";
|
|
3551
3551
|
return "node";
|
|
3552
3552
|
}
|
|
3553
3553
|
function runtimeVersion() {
|
|
3554
|
-
const v =
|
|
3555
|
-
return v[runtimeName()] ??
|
|
3554
|
+
const v = process3.versions;
|
|
3555
|
+
return v[runtimeName()] ?? process3.version.replace(/^v/, "");
|
|
3556
3556
|
}
|
|
3557
3557
|
function isExecutable(path) {
|
|
3558
3558
|
try {
|
|
3559
3559
|
const s = statSync3(path);
|
|
3560
|
-
return s.isFile() && (
|
|
3560
|
+
return s.isFile() && (process3.platform === "win32" || (s.mode & 73) !== 0);
|
|
3561
3561
|
} catch {
|
|
3562
3562
|
return false;
|
|
3563
3563
|
}
|
|
3564
3564
|
}
|
|
3565
3565
|
function which(name, path = env.get("PATH") ?? "") {
|
|
3566
|
-
const windows =
|
|
3566
|
+
const windows = process3.platform === "win32";
|
|
3567
3567
|
const exts = windows ? ["", ...(env.get("PATHEXT") ?? ".EXE;.CMD;.BAT;.COM").split(";")] : [""];
|
|
3568
3568
|
const candidates = name.includes("/") || windows && name.includes("\\") ? [name] : path.split(delimiter3).filter((d) => d !== "").flatMap((d) => exts.map((e) => join4(d, `${name}${e}`)));
|
|
3569
3569
|
return candidates.find(isExecutable);
|
|
@@ -3582,7 +3582,7 @@ function signalNumber(name) {
|
|
|
3582
3582
|
return SIGNALS[name] ?? os.constants.signals[name] ?? 1;
|
|
3583
3583
|
}
|
|
3584
3584
|
var stdio = (s) => s === "inherit" ? "inherit" : s === "null" ? "ignore" : "pipe";
|
|
3585
|
-
var childEnv = (options) => options.clearEnv === true ? { ...options.env } : { ...
|
|
3585
|
+
var childEnv = (options) => options.clearEnv === true ? { ...options.env } : { ...process3.env, ...options.env };
|
|
3586
3586
|
function exitStatus(code, signal) {
|
|
3587
3587
|
const status = signal !== null ? 128 + signalNumber(signal) : code ?? 1;
|
|
3588
3588
|
return { code: status, success: status === 0, signal };
|
|
@@ -3731,9 +3731,9 @@ function dirsOf(app, env, os) {
|
|
|
3731
3731
|
// ../ts/runtime/discover.ts
|
|
3732
3732
|
import { readdir as readdir2, stat as stat2 } from "node:fs/promises";
|
|
3733
3733
|
import { join as join5, posix as posix3, win32 as win323 } from "node:path";
|
|
3734
|
-
import
|
|
3734
|
+
import process4 from "node:process";
|
|
3735
3735
|
function searchPlatform() {
|
|
3736
|
-
return
|
|
3736
|
+
return process4.platform === "win32" ? "windows" : "posix";
|
|
3737
3737
|
}
|
|
3738
3738
|
function pathExtensions(pathext) {
|
|
3739
3739
|
return (pathext ?? ".EXE;.CMD;.BAT;.COM").split(";").map((e) => e.trim().toUpperCase()).filter((e) => e !== "");
|
|
@@ -3741,8 +3741,8 @@ function pathExtensions(pathext) {
|
|
|
3741
3741
|
async function discoverPrograms(prefix, options = {}) {
|
|
3742
3742
|
const platform = options.platform ?? searchPlatform();
|
|
3743
3743
|
const rules = platform === "windows" ? win323 : posix3;
|
|
3744
|
-
const search = options.path ??
|
|
3745
|
-
const exts = pathExtensions(options.pathext ??
|
|
3744
|
+
const search = options.path ?? process4.env["PATH"] ?? "";
|
|
3745
|
+
const exts = pathExtensions(options.pathext ?? process4.env["PATHEXT"]);
|
|
3746
3746
|
const found = [];
|
|
3747
3747
|
const skipped = [];
|
|
3748
3748
|
const byName = new Map;
|
|
@@ -3952,11 +3952,11 @@ var exchangeDecoder = object({
|
|
|
3952
3952
|
});
|
|
3953
3953
|
// ../ts/runtime/lock.ts
|
|
3954
3954
|
import * as nfs2 from "node:fs";
|
|
3955
|
-
import
|
|
3955
|
+
import process5 from "node:process";
|
|
3956
3956
|
var holderDecoder = object({ pid: integer, command: string, since: string, token: string });
|
|
3957
3957
|
function processRuns(pid) {
|
|
3958
3958
|
try {
|
|
3959
|
-
|
|
3959
|
+
process5.kill(pid, 0);
|
|
3960
3960
|
return true;
|
|
3961
3961
|
} catch (e) {
|
|
3962
3962
|
return e instanceof Error && "code" in e && e.code === "EPERM";
|
|
@@ -3977,13 +3977,13 @@ function describeHolder(h, now = Date.now()) {
|
|
|
3977
3977
|
}
|
|
3978
3978
|
async function acquireLock(path, options) {
|
|
3979
3979
|
const holder = {
|
|
3980
|
-
pid:
|
|
3981
|
-
command: options.command ?? (
|
|
3980
|
+
pid: process5.pid,
|
|
3981
|
+
command: options.command ?? (process5.argv.slice(2).filter((a) => !a.startsWith("-")).slice(0, 3).join(" ") || "a run"),
|
|
3982
3982
|
since: new Date().toISOString(),
|
|
3983
3983
|
token: crypto.randomUUID()
|
|
3984
3984
|
};
|
|
3985
3985
|
const inherit = options.inheritEnv;
|
|
3986
|
-
if (inherit !== undefined &&
|
|
3986
|
+
if (inherit !== undefined && process5.env[inherit] === "1")
|
|
3987
3987
|
return { holder, release: () => {} };
|
|
3988
3988
|
const started = Date.now();
|
|
3989
3989
|
let told = false;
|
|
@@ -4017,15 +4017,15 @@ async function acquireLock(path, options) {
|
|
|
4017
4017
|
await sleep(options.pollMs ?? 250);
|
|
4018
4018
|
}
|
|
4019
4019
|
if (inherit !== undefined)
|
|
4020
|
-
|
|
4020
|
+
process5.env[inherit] = "1";
|
|
4021
4021
|
let released = false;
|
|
4022
4022
|
const release = () => {
|
|
4023
4023
|
if (released)
|
|
4024
4024
|
return;
|
|
4025
4025
|
released = true;
|
|
4026
4026
|
if (inherit !== undefined)
|
|
4027
|
-
Reflect.deleteProperty(
|
|
4028
|
-
|
|
4027
|
+
Reflect.deleteProperty(process5.env, inherit);
|
|
4028
|
+
process5.off("exit", release);
|
|
4029
4029
|
try {
|
|
4030
4030
|
const text = nfs2.readFileSync(path, "utf8");
|
|
4031
4031
|
if (text.includes(holder.token))
|
|
@@ -4036,12 +4036,12 @@ async function acquireLock(path, options) {
|
|
|
4036
4036
|
throw mapped;
|
|
4037
4037
|
}
|
|
4038
4038
|
};
|
|
4039
|
-
|
|
4039
|
+
process5.on("exit", release);
|
|
4040
4040
|
return { holder, release };
|
|
4041
4041
|
}
|
|
4042
4042
|
// ../ts/runtime/stdio.ts
|
|
4043
4043
|
import { writeSync as fdWriteSync } from "node:fs";
|
|
4044
|
-
import
|
|
4044
|
+
import process6 from "node:process";
|
|
4045
4045
|
import { Readable } from "node:stream";
|
|
4046
4046
|
function joined2(parts) {
|
|
4047
4047
|
const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));
|
|
@@ -4121,7 +4121,7 @@ function stdinOf(source) {
|
|
|
4121
4121
|
text: async () => new TextDecoder().decode(await bytes())
|
|
4122
4122
|
};
|
|
4123
4123
|
}
|
|
4124
|
-
var stdin = stdinOf(() => Readable.toWeb(
|
|
4124
|
+
var stdin = stdinOf(() => Readable.toWeb(process6.stdin));
|
|
4125
4125
|
var encoder2 = new TextEncoder;
|
|
4126
4126
|
var bytesOf = (data) => typeof data === "string" ? encoder2.encode(data) : data;
|
|
4127
4127
|
function pause() {
|
|
@@ -4173,8 +4173,8 @@ function stdoutOf(sink) {
|
|
|
4173
4173
|
}
|
|
4174
4174
|
};
|
|
4175
4175
|
}
|
|
4176
|
-
var stdout = stdoutOf({ fd: 1, stream: () =>
|
|
4177
|
-
var stderr = stdoutOf({ fd: 2, stream: () =>
|
|
4176
|
+
var stdout = stdoutOf({ fd: 1, stream: () => process6.stdout });
|
|
4177
|
+
var stderr = stdoutOf({ fd: 2, stream: () => process6.stderr });
|
|
4178
4178
|
// ../ts/runtime/tty.ts
|
|
4179
4179
|
import { isatty } from "node:tty";
|
|
4180
4180
|
var FD = { stdin: 0, stdout: 1, stderr: 2 };
|
|
@@ -4477,6 +4477,42 @@ function parseRemote(url, hostKinds = {}) {
|
|
|
4477
4477
|
return err({ kind: "local-path" });
|
|
4478
4478
|
return refOf(hostOfAuthority(text.slice(0, colon)), text.slice(colon + 1), hostKinds);
|
|
4479
4479
|
}
|
|
4480
|
+
var HOSTNAME = /^[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)+(?::\d+)?$/;
|
|
4481
|
+
function webPage(path) {
|
|
4482
|
+
const m = /^(.*?)\/(?:-\/)?(?:tree|blob|commits|raw)\/([^/?#]+)(?:[/?#].*)?$/s.exec(path);
|
|
4483
|
+
if (m === null)
|
|
4484
|
+
return { path };
|
|
4485
|
+
const branch = safeDecode(m[2] ?? "");
|
|
4486
|
+
return branch === undefined ? { path } : { path: m[1] ?? path, branch };
|
|
4487
|
+
}
|
|
4488
|
+
function readRemote(input, hostKinds = {}) {
|
|
4489
|
+
const text = input.trim();
|
|
4490
|
+
const strict = parseRemote(text, hostKinds);
|
|
4491
|
+
const asIs = () => strict.kind === "err" ? strict : ok({ ref: strict.value });
|
|
4492
|
+
const viaPage = (origin, path) => {
|
|
4493
|
+
const page = webPage(path);
|
|
4494
|
+
const r = parseRemote(`${origin}${page.path}`, hostKinds);
|
|
4495
|
+
return r.kind === "err" ? r : ok(page.branch === undefined ? { ref: r.value } : { ref: r.value, branch: page.branch });
|
|
4496
|
+
};
|
|
4497
|
+
const scheme = /^([A-Za-z][A-Za-z0-9+.-]*):\/\/([^/]*)(\/.*)?$/.exec(text);
|
|
4498
|
+
if (scheme !== null)
|
|
4499
|
+
return strict.kind === "err" && scheme[1]?.toLowerCase() === "file" ? strict : viaPage(`${scheme[1]}://${scheme[2]}`, scheme[3] ?? "");
|
|
4500
|
+
if (text === "" || /^[A-Za-z]:[\\/]/.test(text) || /^[/.~]/.test(text))
|
|
4501
|
+
return asIs();
|
|
4502
|
+
const named = /^(github|gitlab):([^/].*)$/i.exec(text);
|
|
4503
|
+
if (named !== null)
|
|
4504
|
+
return viaPage(`https://${(named[1] ?? "").toLowerCase()}.com/`, named[2] ?? "");
|
|
4505
|
+
const colon = text.indexOf(":");
|
|
4506
|
+
const slash = text.indexOf("/");
|
|
4507
|
+
if (colon >= 0 && (slash < 0 || colon < slash))
|
|
4508
|
+
return asIs();
|
|
4509
|
+
const first = slash < 0 ? text : text.slice(0, slash);
|
|
4510
|
+
if (slash >= 0 && HOSTNAME.test(first))
|
|
4511
|
+
return viaPage(`https://${first}`, text.slice(slash));
|
|
4512
|
+
if (/^[^/\s]+\/[^/\s]+$/.test(text))
|
|
4513
|
+
return viaPage("https://github.com/", text);
|
|
4514
|
+
return asIs();
|
|
4515
|
+
}
|
|
4480
4516
|
function cloneUrlOf(ref) {
|
|
4481
4517
|
return `https://${ref.host}/${ref.path.map(encodeURIComponent).join("/")}.git`;
|
|
4482
4518
|
}
|
|
@@ -4518,6 +4554,24 @@ var branchShape2 = object({ name: string, protected: boolean });
|
|
|
4518
4554
|
var protectedShape = object({ name: string, allow_force_push: boolean }, { code_owner_approval_required: boolean, push_access_levels: array(object({ access_level: integer })) });
|
|
4519
4555
|
var signatureShape = object({ verification_status: string });
|
|
4520
4556
|
// src/state.ts
|
|
4557
|
+
function holdsLocalWork(kind) {
|
|
4558
|
+
switch (kind) {
|
|
4559
|
+
case "Missing":
|
|
4560
|
+
case "Clean":
|
|
4561
|
+
case "Behind":
|
|
4562
|
+
return false;
|
|
4563
|
+
case "Dirty":
|
|
4564
|
+
case "Ahead":
|
|
4565
|
+
case "Diverged":
|
|
4566
|
+
case "Locked":
|
|
4567
|
+
case "Detached":
|
|
4568
|
+
case "WrongRemote":
|
|
4569
|
+
case "NotARepo":
|
|
4570
|
+
return true;
|
|
4571
|
+
default:
|
|
4572
|
+
return absurd(kind);
|
|
4573
|
+
}
|
|
4574
|
+
}
|
|
4521
4575
|
function describeRemote(remote) {
|
|
4522
4576
|
if (remote === undefined || remote.trim() === "")
|
|
4523
4577
|
return "(none)";
|
|
@@ -5040,7 +5094,7 @@ function checkFiles(files, repositories) {
|
|
|
5040
5094
|
}
|
|
5041
5095
|
|
|
5042
5096
|
// src/state-record.ts
|
|
5043
|
-
var ERGONEX_VERSION = "0.2.
|
|
5097
|
+
var ERGONEX_VERSION = "0.2.5";
|
|
5044
5098
|
var STATE_RECORD_PATH = ".ergonex/state.auto.json";
|
|
5045
5099
|
var EMPTY_RECORD = {
|
|
5046
5100
|
ergonex: ERGONEX_VERSION,
|
|
@@ -5802,7 +5856,7 @@ function decodeManifest(input, options = {}) {
|
|
|
5802
5856
|
const named = [];
|
|
5803
5857
|
for (const [i, entry] of raw.repositories.entries()) {
|
|
5804
5858
|
const at = `$.repositories[${i}]`;
|
|
5805
|
-
const remote =
|
|
5859
|
+
const remote = readRemote(entry.remote, hostKinds);
|
|
5806
5860
|
if (remote.kind === "err") {
|
|
5807
5861
|
issues.push({
|
|
5808
5862
|
rule: "ergonex/manifest-remote",
|
|
@@ -5811,7 +5865,7 @@ function decodeManifest(input, options = {}) {
|
|
|
5811
5865
|
});
|
|
5812
5866
|
continue;
|
|
5813
5867
|
}
|
|
5814
|
-
const ref = remote.value;
|
|
5868
|
+
const ref = remote.value.ref;
|
|
5815
5869
|
const path = repoPathOf(ref);
|
|
5816
5870
|
if (path.kind === "err") {
|
|
5817
5871
|
issues.push({
|
|
@@ -5829,8 +5883,9 @@ function decodeManifest(input, options = {}) {
|
|
|
5829
5883
|
});
|
|
5830
5884
|
}
|
|
5831
5885
|
let branch;
|
|
5832
|
-
|
|
5833
|
-
|
|
5886
|
+
const wantedBranch = entry.branch ?? remote.value.branch;
|
|
5887
|
+
if (wantedBranch !== undefined) {
|
|
5888
|
+
const b = branchName(wantedBranch);
|
|
5834
5889
|
if (b.kind === "err")
|
|
5835
5890
|
issues.push({
|
|
5836
5891
|
rule: "ergonex/manifest-branch",
|
|
@@ -5897,6 +5952,74 @@ function decodeManifest(input, options = {}) {
|
|
|
5897
5952
|
});
|
|
5898
5953
|
}
|
|
5899
5954
|
|
|
5955
|
+
// src/repositories.ts
|
|
5956
|
+
var REPOSITORIES_FILE = "repositories.ts";
|
|
5957
|
+
var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
5958
|
+
function entriesOf(value) {
|
|
5959
|
+
if (!Array.isArray(value))
|
|
5960
|
+
return err('repositories.ts must export an array of repositories as its default (`export default [{ remote: "..." }]`)');
|
|
5961
|
+
const out = [];
|
|
5962
|
+
for (const [i, e] of value.entries()) {
|
|
5963
|
+
if (!isRecord(e) || typeof e["remote"] !== "string")
|
|
5964
|
+
return err(`repositories.ts: entry ${i} has no \`remote\` text`);
|
|
5965
|
+
const branch = e["branch"];
|
|
5966
|
+
const group = e["group"];
|
|
5967
|
+
const worktrees = e["worktrees"];
|
|
5968
|
+
if (branch !== undefined && typeof branch !== "string")
|
|
5969
|
+
return err(`repositories.ts: entry ${i}: \`branch\` is not text`);
|
|
5970
|
+
if (group !== undefined && typeof group !== "string")
|
|
5971
|
+
return err(`repositories.ts: entry ${i}: \`group\` is not text`);
|
|
5972
|
+
if (worktrees !== undefined && (!Array.isArray(worktrees) || worktrees.some((w) => typeof w !== "string")))
|
|
5973
|
+
return err(`repositories.ts: entry ${i}: \`worktrees\` is not a list of text`);
|
|
5974
|
+
out.push({
|
|
5975
|
+
remote: e["remote"],
|
|
5976
|
+
...branch === undefined ? {} : { branch },
|
|
5977
|
+
...group === undefined ? {} : { group },
|
|
5978
|
+
...worktrees === undefined ? {} : { worktrees }
|
|
5979
|
+
});
|
|
5980
|
+
}
|
|
5981
|
+
return ok(out);
|
|
5982
|
+
}
|
|
5983
|
+
function withEntries(manifest, entries) {
|
|
5984
|
+
if (!isRecord(manifest))
|
|
5985
|
+
return manifest;
|
|
5986
|
+
const own = manifest["repositories"];
|
|
5987
|
+
if (!Array.isArray(own))
|
|
5988
|
+
return manifest;
|
|
5989
|
+
return { ...manifest, repositories: [...own, ...entries] };
|
|
5990
|
+
}
|
|
5991
|
+
var text2 = (s) => JSON.stringify(s);
|
|
5992
|
+
function line(e) {
|
|
5993
|
+
const parts = [`remote: ${text2(e.remote)}`];
|
|
5994
|
+
if (e.branch !== undefined)
|
|
5995
|
+
parts.push(`branch: ${text2(e.branch)}`);
|
|
5996
|
+
if (e.group !== undefined)
|
|
5997
|
+
parts.push(`group: ${text2(e.group)}`);
|
|
5998
|
+
if (e.worktrees !== undefined && e.worktrees.length > 0)
|
|
5999
|
+
parts.push(`worktrees: [${e.worktrees.map(text2).join(", ")}]`);
|
|
6000
|
+
return ` { ${parts.join(", ")} },`;
|
|
6001
|
+
}
|
|
6002
|
+
function renderRepositories(entries) {
|
|
6003
|
+
return [
|
|
6004
|
+
"/**",
|
|
6005
|
+
" * The repositories of this workspace that `ergonex add`, `ergonex remove` and `ergonex adopt` keep. They rewrite this file whole; you may edit it too, and the manifest `workspace.ts` can name more.",
|
|
6006
|
+
" * Run `ergonex plan` to see what would change and `ergonex apply` to bring the workspace to it.",
|
|
6007
|
+
" */",
|
|
6008
|
+
entries.length === 0 ? "export default [];" : ["export default [", ...entries.map(line), "];"].join(`
|
|
6009
|
+
`),
|
|
6010
|
+
""
|
|
6011
|
+
].join(`
|
|
6012
|
+
`);
|
|
6013
|
+
}
|
|
6014
|
+
function addEntries(entries, added) {
|
|
6015
|
+
const have = new Set(entries.map((e) => e.remote));
|
|
6016
|
+
return [...entries, ...added.filter((e) => !have.has(e.remote))];
|
|
6017
|
+
}
|
|
6018
|
+
function removeEntries(entries, remotes) {
|
|
6019
|
+
const gone = new Set(remotes);
|
|
6020
|
+
return entries.filter((e) => !gone.has(e.remote));
|
|
6021
|
+
}
|
|
6022
|
+
|
|
5900
6023
|
// src/templates/agents.ts
|
|
5901
6024
|
function agentsText(data) {
|
|
5902
6025
|
const { manifest } = data;
|
|
@@ -6265,24 +6388,42 @@ function loopbackFinding(today) {
|
|
|
6265
6388
|
function manifestPath(home) {
|
|
6266
6389
|
return join6(home, AREA, "workspace.ts");
|
|
6267
6390
|
}
|
|
6268
|
-
async function
|
|
6391
|
+
async function importDefault(path, name, shape) {
|
|
6269
6392
|
try {
|
|
6270
6393
|
const s = statSync4(path);
|
|
6271
6394
|
const url = `${toFileUrl2(path).href}?v=${s.size}-${s.mtime?.getTime() ?? 0}`;
|
|
6272
6395
|
const mod = await import(url);
|
|
6273
6396
|
const value = typeof mod === "object" && mod !== null ? Reflect.get(mod, "default") : undefined;
|
|
6274
6397
|
if (value === undefined)
|
|
6275
|
-
return err(
|
|
6398
|
+
return err(`${name} has no default export; it exports ${shape} as its default`);
|
|
6276
6399
|
return ok(value);
|
|
6277
6400
|
} catch (e) {
|
|
6278
|
-
return err(
|
|
6401
|
+
return err(`${name} could not be loaded: ${e instanceof Error ? e.message : String(e)}`);
|
|
6279
6402
|
}
|
|
6280
6403
|
}
|
|
6404
|
+
var importManifest = (path) => importDefault(path, "workspace.ts", "the manifest (`export default { repositories: [...] }`)");
|
|
6405
|
+
function repositoriesPath(home) {
|
|
6406
|
+
return join6(home, AREA, REPOSITORIES_FILE);
|
|
6407
|
+
}
|
|
6408
|
+
async function readRepositoryList(home) {
|
|
6409
|
+
const path = repositoriesPath(home);
|
|
6410
|
+
if (!existsSync2(path))
|
|
6411
|
+
return ok([]);
|
|
6412
|
+
const imported = await importDefault(path, "repositories.ts", "an array of repositories");
|
|
6413
|
+
return imported.kind === "err" ? imported : entriesOf(imported.value);
|
|
6414
|
+
}
|
|
6415
|
+
async function readRawManifest(home) {
|
|
6416
|
+
const imported = await importManifest(manifestPath(home));
|
|
6417
|
+
if (imported.kind === "err")
|
|
6418
|
+
return imported;
|
|
6419
|
+
const list = await readRepositoryList(home);
|
|
6420
|
+
return list.kind === "err" ? list : ok({ base: imported.value, list: list.value });
|
|
6421
|
+
}
|
|
6281
6422
|
async function readManifest(home, today, loopbackHttp = false) {
|
|
6282
6423
|
const path = manifestPath(home);
|
|
6283
6424
|
if (!existsSync2(path))
|
|
6284
6425
|
return err({ kind: "no-manifest", path });
|
|
6285
|
-
const imported = await
|
|
6426
|
+
const imported = await readRawManifest(home);
|
|
6286
6427
|
if (imported.kind === "err")
|
|
6287
6428
|
return err({
|
|
6288
6429
|
kind: "manifest",
|
|
@@ -6296,7 +6437,7 @@ async function readManifest(home, today, loopbackHttp = false) {
|
|
|
6296
6437
|
}
|
|
6297
6438
|
]
|
|
6298
6439
|
});
|
|
6299
|
-
const decoded = decodeManifest(imported.value, { loopbackHttp });
|
|
6440
|
+
const decoded = decodeManifest(withEntries(imported.value.base, imported.value.list), { loopbackHttp });
|
|
6300
6441
|
if (decoded.kind === "err")
|
|
6301
6442
|
return err({
|
|
6302
6443
|
kind: "manifest",
|
|
@@ -6913,48 +7054,49 @@ var APPLY_OPTIONS = {
|
|
|
6913
7054
|
help: "Wait for another run of ergonex on this workspace instead of refusing."
|
|
6914
7055
|
})
|
|
6915
7056
|
};
|
|
7057
|
+
async function applyLoaded(ctx, loaded, flags) {
|
|
7058
|
+
const s = await situate(ctx, loaded, { fetch: flags.fetch });
|
|
7059
|
+
if (s.kind === "err")
|
|
7060
|
+
return err({
|
|
7061
|
+
kind: "environment",
|
|
7062
|
+
message: `git cannot be run (${s.error.program} is not installed or not on the PATH)`
|
|
7063
|
+
});
|
|
7064
|
+
const done = await applyPlan(s.value, ctx, {
|
|
7065
|
+
allowDestructive: flags.allowDestructive,
|
|
7066
|
+
force: flags.force,
|
|
7067
|
+
wait: flags.wait
|
|
7068
|
+
});
|
|
7069
|
+
if (done.kind === "err")
|
|
7070
|
+
return err({
|
|
7071
|
+
kind: "environment",
|
|
7072
|
+
message: `another run of ergonex holds the workspace: ${done.error.holder}; run again when it ends, or give --wait`
|
|
7073
|
+
});
|
|
7074
|
+
const steps = done.value.steps;
|
|
7075
|
+
const lines = steps.filter((x) => x.status !== "skipped" || x.action.kind !== "Skip").map((x) => ` ${x.status.padEnd(7)} ${describeAction(x.action)}${x.detail === "" ? "" : ` (${x.detail})`}`);
|
|
7076
|
+
const changed = steps.filter((x) => x.status === "done").length;
|
|
7077
|
+
const findings = done.value.findings;
|
|
7078
|
+
return ok({
|
|
7079
|
+
text: textOf2([`apply ${s.value.planSha.slice(0, 12)}: ${changed} done, ${steps.filter((x) => x.status === "failed").length} failed`, ...lines], findings),
|
|
7080
|
+
data: {
|
|
7081
|
+
planSha256: s.value.planSha,
|
|
7082
|
+
steps: jsonOf(steps.map((x) => ({
|
|
7083
|
+
kind: x.action.kind,
|
|
7084
|
+
status: x.status,
|
|
7085
|
+
detail: x.detail
|
|
7086
|
+
})))
|
|
7087
|
+
},
|
|
7088
|
+
findings,
|
|
7089
|
+
facts: {
|
|
7090
|
+
planSha256: s.value.planSha,
|
|
7091
|
+
stateSha256: done.value.recordSha
|
|
7092
|
+
}
|
|
7093
|
+
});
|
|
7094
|
+
}
|
|
6916
7095
|
var apply = defineCommand({
|
|
6917
7096
|
name: "apply",
|
|
6918
7097
|
summary: "Carry out the plan: clone, fast-forward, configure and write generated files; never delete work, never change the host.",
|
|
6919
7098
|
options: APPLY_OPTIONS,
|
|
6920
|
-
run: (ctx, args) => withWorkspace(ctx,
|
|
6921
|
-
const s = await situate(ctx, loaded, { fetch: args.options.fetch });
|
|
6922
|
-
if (s.kind === "err")
|
|
6923
|
-
return err({
|
|
6924
|
-
kind: "environment",
|
|
6925
|
-
message: `git cannot be run (${s.error.program} is not installed or not on the PATH)`
|
|
6926
|
-
});
|
|
6927
|
-
const done = await applyPlan(s.value, ctx, {
|
|
6928
|
-
allowDestructive: args.options.allowDestructive,
|
|
6929
|
-
force: args.options.force,
|
|
6930
|
-
wait: args.options.wait
|
|
6931
|
-
});
|
|
6932
|
-
if (done.kind === "err")
|
|
6933
|
-
return err({
|
|
6934
|
-
kind: "environment",
|
|
6935
|
-
message: `another run of ergonex holds the workspace: ${done.error.holder}; run again when it ends, or give --wait`
|
|
6936
|
-
});
|
|
6937
|
-
const steps = done.value.steps;
|
|
6938
|
-
const lines = steps.filter((x) => x.status !== "skipped" || x.action.kind !== "Skip").map((x) => ` ${x.status.padEnd(7)} ${describeAction(x.action)}${x.detail === "" ? "" : ` (${x.detail})`}`);
|
|
6939
|
-
const changed = steps.filter((x) => x.status === "done").length;
|
|
6940
|
-
const findings = done.value.findings;
|
|
6941
|
-
return ok({
|
|
6942
|
-
text: textOf2([`apply ${s.value.planSha.slice(0, 12)}: ${changed} done, ${steps.filter((x) => x.status === "failed").length} failed`, ...lines], findings),
|
|
6943
|
-
data: {
|
|
6944
|
-
planSha256: s.value.planSha,
|
|
6945
|
-
steps: jsonOf(steps.map((x) => ({
|
|
6946
|
-
kind: x.action.kind,
|
|
6947
|
-
status: x.status,
|
|
6948
|
-
detail: x.detail
|
|
6949
|
-
})))
|
|
6950
|
-
},
|
|
6951
|
-
findings,
|
|
6952
|
-
facts: {
|
|
6953
|
-
planSha256: s.value.planSha,
|
|
6954
|
-
stateSha256: done.value.recordSha
|
|
6955
|
-
}
|
|
6956
|
-
});
|
|
6957
|
-
})
|
|
7099
|
+
run: (ctx, args) => withWorkspace(ctx, (loaded) => applyLoaded(ctx, loaded, args.options))
|
|
6958
7100
|
});
|
|
6959
7101
|
var planModule = {
|
|
6960
7102
|
name: "plan",
|
|
@@ -6967,6 +7109,314 @@ var applyModule = {
|
|
|
6967
7109
|
commands: [apply]
|
|
6968
7110
|
};
|
|
6969
7111
|
|
|
7112
|
+
// src/host/unmanaged.ts
|
|
7113
|
+
var DEPTH = 8;
|
|
7114
|
+
var SKIPPED = new Set([...WORKSPACE_FOLDERS.map((f) => f.toLowerCase()), "node_modules"]);
|
|
7115
|
+
async function originOf(folder) {
|
|
7116
|
+
const r = await run2(["git", "-C", folder, "config", "--get", "remote.origin.url"], {
|
|
7117
|
+
env: { GIT_TERMINAL_PROMPT: "0", LC_ALL: "C" }
|
|
7118
|
+
}).catch(() => {
|
|
7119
|
+
return;
|
|
7120
|
+
});
|
|
7121
|
+
return r !== undefined && r.success && r.stdout.trim() !== "" ? r.stdout.trim() : undefined;
|
|
7122
|
+
}
|
|
7123
|
+
async function findUnmanaged(home, managed, hostKinds) {
|
|
7124
|
+
const known = new Set(managed.map(foldKey));
|
|
7125
|
+
const found = [];
|
|
7126
|
+
const walk = async (logical, depth) => {
|
|
7127
|
+
const folder = logical === "" ? home : join6(home, ...logical.split("/"));
|
|
7128
|
+
let entries;
|
|
7129
|
+
try {
|
|
7130
|
+
entries = readDirSync2(folder);
|
|
7131
|
+
} catch {
|
|
7132
|
+
return;
|
|
7133
|
+
}
|
|
7134
|
+
entries.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
7135
|
+
if (entries.some((e) => e.name === ".git")) {
|
|
7136
|
+
if (logical === "" || known.has(foldKey(logical)))
|
|
7137
|
+
return;
|
|
7138
|
+
const origin = await originOf(folder);
|
|
7139
|
+
if (origin === undefined)
|
|
7140
|
+
return void found.push({ kind: "no-remote", path: logical });
|
|
7141
|
+
const read = readRemote(origin, hostKinds);
|
|
7142
|
+
if (read.kind === "err")
|
|
7143
|
+
return void found.push({ kind: "not-a-host", path: logical });
|
|
7144
|
+
const there = repoPathOf(read.value.ref);
|
|
7145
|
+
if (there.kind === "err")
|
|
7146
|
+
return void found.push({ kind: "not-a-host", path: logical });
|
|
7147
|
+
if (known.has(foldKey(there.value)))
|
|
7148
|
+
return void found.push({ kind: "misplaced", path: logical, belongsAt: there.value });
|
|
7149
|
+
return void found.push(foldKey(there.value) === foldKey(logical) ? { kind: "adoptable", path: logical, remote: cloneUrlOf(read.value.ref) } : { kind: "misplaced", path: logical, belongsAt: there.value });
|
|
7150
|
+
}
|
|
7151
|
+
if (depth >= DEPTH)
|
|
7152
|
+
return;
|
|
7153
|
+
for (const e of entries) {
|
|
7154
|
+
if (!e.isDirectory || e.isSymlink || SKIPPED.has(e.name.toLowerCase()) || e.name.startsWith("."))
|
|
7155
|
+
continue;
|
|
7156
|
+
if (!lstatSync3(join6(folder, e.name)).isDirectory)
|
|
7157
|
+
continue;
|
|
7158
|
+
await walk(logical === "" ? e.name : `${logical}/${e.name}`, depth + 1);
|
|
7159
|
+
}
|
|
7160
|
+
};
|
|
7161
|
+
await walk("", 0);
|
|
7162
|
+
return found;
|
|
7163
|
+
}
|
|
7164
|
+
|
|
7165
|
+
// src/host/repositories.ts
|
|
7166
|
+
async function writeRepositoryList(home, entries) {
|
|
7167
|
+
const path = repositoriesPath(home);
|
|
7168
|
+
await mkdir3(dirname4(path), { recursive: true });
|
|
7169
|
+
const next = `${path}.${process.pid}.tmp`;
|
|
7170
|
+
await writeTextFile2(next, renderRepositories(entries));
|
|
7171
|
+
await rename3(next, path);
|
|
7172
|
+
}
|
|
7173
|
+
|
|
7174
|
+
// src/commands/repos.ts
|
|
7175
|
+
function problemsOf(base, list) {
|
|
7176
|
+
const d = decodeManifest(withEntries(base, list));
|
|
7177
|
+
return d.kind === "err" ? d.error.map((i) => `${i.path}: ${i.message}`) : [];
|
|
7178
|
+
}
|
|
7179
|
+
async function thenApply(ctx, lines, data, apply) {
|
|
7180
|
+
if (!apply)
|
|
7181
|
+
return ok({ text: lines.join(`
|
|
7182
|
+
`), data: jsonOf(data), findings: [] });
|
|
7183
|
+
const loaded = await loadWorkspace(ctx);
|
|
7184
|
+
if (loaded.kind === "err")
|
|
7185
|
+
return ok({
|
|
7186
|
+
text: [...lines, "the manifest cannot be read now; run `ergonex plan`"].join(`
|
|
7187
|
+
`),
|
|
7188
|
+
data: jsonOf(data),
|
|
7189
|
+
findings: []
|
|
7190
|
+
});
|
|
7191
|
+
const done = await applyLoaded(ctx, loaded.value, { fetch: false, allowDestructive: false, force: false, wait: false });
|
|
7192
|
+
if (done.kind === "err")
|
|
7193
|
+
return done;
|
|
7194
|
+
return ok({
|
|
7195
|
+
...done.value,
|
|
7196
|
+
text: [...lines, done.value.text].join(`
|
|
7197
|
+
`),
|
|
7198
|
+
data: { ...jsonOf(data), ...done.value.data }
|
|
7199
|
+
});
|
|
7200
|
+
}
|
|
7201
|
+
var add = defineCommand({
|
|
7202
|
+
name: "add",
|
|
7203
|
+
summary: "Add repositories to the workspace: `ergonex add github.com/owner/repo`; --apply clones them.",
|
|
7204
|
+
options: {
|
|
7205
|
+
...GLOBAL_OPTIONS,
|
|
7206
|
+
apply: flag2({ help: "Then carry out the plan, as `ergonex apply` does: clone what is not there yet." }),
|
|
7207
|
+
branch: value2({ help: "The branch to keep checked out (a page's address, `.../tree/dev`, names it too).", valueName: "BRANCH" }),
|
|
7208
|
+
group: value2({ help: "A name that groups repositories together.", valueName: "GROUP" })
|
|
7209
|
+
},
|
|
7210
|
+
operands: [
|
|
7211
|
+
{
|
|
7212
|
+
name: "REMOTE",
|
|
7213
|
+
help: "A repository as you write it: `github.com/owner/repo`, `owner/repo` (GitHub), `gitlab:group/sub/repo`, `git@host:path.git` or an https address, with or without the scheme.",
|
|
7214
|
+
arity: "many"
|
|
7215
|
+
}
|
|
7216
|
+
],
|
|
7217
|
+
run: (ctx, args) => withWorkspace(ctx, async (loaded) => {
|
|
7218
|
+
if (args.positionals.length === 0)
|
|
7219
|
+
return err({ kind: "usage", message: "name a repository to add, for example `ergonex add github.com/owner/repo`" });
|
|
7220
|
+
const raw = await readRawManifest(loaded.home);
|
|
7221
|
+
if (raw.kind === "err")
|
|
7222
|
+
return err({ kind: "environment", message: raw.error });
|
|
7223
|
+
const bad = [];
|
|
7224
|
+
const wanted = [];
|
|
7225
|
+
for (const word of args.positionals) {
|
|
7226
|
+
const r = readRemote(word, loaded.manifest.hostKinds);
|
|
7227
|
+
if (r.kind === "err") {
|
|
7228
|
+
bad.push(`${word}: not a repository on a Git host (${r.error.kind === "local-path" ? "a path on this computer is not a remote" : r.error.kind})`);
|
|
7229
|
+
continue;
|
|
7230
|
+
}
|
|
7231
|
+
wanted.push({ ref: r.value.ref, branch: args.options.branch ?? r.value.branch });
|
|
7232
|
+
}
|
|
7233
|
+
if (bad.length > 0)
|
|
7234
|
+
return err({ kind: "usage", message: bad.join(`
|
|
7235
|
+
`) });
|
|
7236
|
+
const entries = [];
|
|
7237
|
+
const lines = [];
|
|
7238
|
+
for (const w of wanted) {
|
|
7239
|
+
const name = describeRef(w.ref);
|
|
7240
|
+
const have = loaded.manifest.repositories.find((r) => sameRepository(r.ref, w.ref));
|
|
7241
|
+
if (have !== undefined || entries.some((e) => foldKey(e.remote) === foldKey(cloneUrlOf(w.ref)))) {
|
|
7242
|
+
lines.push(` already in the manifest: ${name}`);
|
|
7243
|
+
continue;
|
|
7244
|
+
}
|
|
7245
|
+
entries.push({
|
|
7246
|
+
remote: cloneUrlOf(w.ref),
|
|
7247
|
+
...w.branch === undefined ? {} : { branch: w.branch },
|
|
7248
|
+
...args.options.group === undefined ? {} : { group: args.options.group }
|
|
7249
|
+
});
|
|
7250
|
+
lines.push(` added ${name} (${cloneUrlOf(w.ref)}${w.branch === undefined ? "" : `, branch ${w.branch}`})`);
|
|
7251
|
+
}
|
|
7252
|
+
if (entries.length === 0)
|
|
7253
|
+
return ok({ text: ["nothing to add:", ...lines].join(`
|
|
7254
|
+
`), data: { added: [] }, findings: [] });
|
|
7255
|
+
const next = addEntries(raw.value.list, entries);
|
|
7256
|
+
const problems = problemsOf(raw.value.base, next);
|
|
7257
|
+
if (problems.length > 0)
|
|
7258
|
+
return err({ kind: "usage", message: `nothing was added; the manifest would not accept it:
|
|
7259
|
+
${problems.join(`
|
|
7260
|
+
`)}` });
|
|
7261
|
+
await writeRepositoryList(loaded.home, next);
|
|
7262
|
+
const head = [`added ${entries.length} to .ergonex/repositories.ts:`, ...lines];
|
|
7263
|
+
const tail = args.options.apply ? [] : ["next: `ergonex plan` shows what would change, `ergonex apply` clones them (or add --apply next time)"];
|
|
7264
|
+
return thenApply(ctx, [...head, ...tail], { added: entries.map((e) => e.remote) }, args.options.apply);
|
|
7265
|
+
})
|
|
7266
|
+
});
|
|
7267
|
+
function resolveWord(repos, word, loaded) {
|
|
7268
|
+
const read = readRemote(word, loaded.manifest.hostKinds);
|
|
7269
|
+
if (read.kind === "ok") {
|
|
7270
|
+
const hit = repos.find((r) => sameRepository(r.ref, read.value.ref));
|
|
7271
|
+
if (hit !== undefined)
|
|
7272
|
+
return hit;
|
|
7273
|
+
}
|
|
7274
|
+
const key = foldKey(word);
|
|
7275
|
+
const exact = repos.filter((r) => foldKey(r.path) === key);
|
|
7276
|
+
const found = exact.length > 0 ? exact : repos.filter((r) => foldKey(r.path.split("/").at(-1) ?? "") === key);
|
|
7277
|
+
const [only, ...more] = found;
|
|
7278
|
+
if (only === undefined)
|
|
7279
|
+
return `${word} is not a repository of the manifest`;
|
|
7280
|
+
if (more.length > 0)
|
|
7281
|
+
return `${word} names more than one repository (${found.map((r) => r.path).join(", ")}); give its whole path`;
|
|
7282
|
+
return only;
|
|
7283
|
+
}
|
|
7284
|
+
var removeCommand = defineCommand({
|
|
7285
|
+
name: "remove",
|
|
7286
|
+
summary: "Take repositories out of the list; --delete also deletes the folder of one that holds no work that exists nowhere else.",
|
|
7287
|
+
options: {
|
|
7288
|
+
...GLOBAL_OPTIONS,
|
|
7289
|
+
delete: flag2({
|
|
7290
|
+
help: "Also delete the repository's folder, only where it is clean, fully pushed and has no worktree; otherwise nothing is removed."
|
|
7291
|
+
})
|
|
7292
|
+
},
|
|
7293
|
+
operands: [
|
|
7294
|
+
{
|
|
7295
|
+
name: "REPOSITORY",
|
|
7296
|
+
help: "A repository as you wrote it when you added it, its path in the workspace, or its name where that is only one.",
|
|
7297
|
+
arity: "many"
|
|
7298
|
+
}
|
|
7299
|
+
],
|
|
7300
|
+
run: (ctx, args) => withWorkspace(ctx, async (loaded) => {
|
|
7301
|
+
if (args.positionals.length === 0)
|
|
7302
|
+
return err({ kind: "usage", message: "name a repository to remove, for example `ergonex remove github.com/owner/repo`" });
|
|
7303
|
+
const raw = await readRawManifest(loaded.home);
|
|
7304
|
+
if (raw.kind === "err")
|
|
7305
|
+
return err({ kind: "environment", message: raw.error });
|
|
7306
|
+
const mine = new Map;
|
|
7307
|
+
for (const e of raw.value.list) {
|
|
7308
|
+
const r = readRemote(e.remote, loaded.manifest.hostKinds);
|
|
7309
|
+
if (r.kind === "ok")
|
|
7310
|
+
mine.set(describeRef(r.value.ref).toLowerCase(), e);
|
|
7311
|
+
}
|
|
7312
|
+
const problems = [];
|
|
7313
|
+
const targets = [];
|
|
7314
|
+
for (const word of args.positionals) {
|
|
7315
|
+
const hit = resolveWord(loaded.manifest.repositories, word, loaded);
|
|
7316
|
+
if (typeof hit === "string") {
|
|
7317
|
+
problems.push(hit);
|
|
7318
|
+
continue;
|
|
7319
|
+
}
|
|
7320
|
+
const entry = mine.get(describeRef(hit.ref).toLowerCase());
|
|
7321
|
+
if (entry === undefined) {
|
|
7322
|
+
problems.push(`${hit.path} is named in workspace.ts, which ergonex does not edit: remove its line there`);
|
|
7323
|
+
continue;
|
|
7324
|
+
}
|
|
7325
|
+
if (!targets.some((t) => t.repo.path === hit.path))
|
|
7326
|
+
targets.push({ repo: hit, entry });
|
|
7327
|
+
}
|
|
7328
|
+
const site = { home: loaded.home, places: loaded.places };
|
|
7329
|
+
const folders = [];
|
|
7330
|
+
if (args.options.delete) {
|
|
7331
|
+
for (const t of targets) {
|
|
7332
|
+
const folder = native(site, t.repo.path);
|
|
7333
|
+
const state = await observe(folder, t.repo.ref);
|
|
7334
|
+
if (state.kind === "err") {
|
|
7335
|
+
problems.push(`${t.repo.path}: cannot be looked at (${state.error.program} is not installed or not on the PATH)`);
|
|
7336
|
+
continue;
|
|
7337
|
+
}
|
|
7338
|
+
if (holdsLocalWork(state.value.kind)) {
|
|
7339
|
+
problems.push(`${t.repo.path} holds work that exists nowhere else (${state.value.kind}): commit and push it, or remove it by hand`);
|
|
7340
|
+
continue;
|
|
7341
|
+
}
|
|
7342
|
+
if (await exists2(native(site, `.worktrees/${t.repo.path}`))) {
|
|
7343
|
+
problems.push(`${t.repo.path} has worktrees: \`ergonex worktree prune\` first`);
|
|
7344
|
+
continue;
|
|
7345
|
+
}
|
|
7346
|
+
if (state.value.kind !== "Missing")
|
|
7347
|
+
folders.push(folder);
|
|
7348
|
+
}
|
|
7349
|
+
}
|
|
7350
|
+
if (problems.length > 0)
|
|
7351
|
+
return err({ kind: "usage", message: `nothing was removed:
|
|
7352
|
+
${problems.join(`
|
|
7353
|
+
`)}` });
|
|
7354
|
+
await writeRepositoryList(loaded.home, removeEntries(raw.value.list, targets.map((t) => t.entry.remote)));
|
|
7355
|
+
for (const f of folders)
|
|
7356
|
+
await remove2(f, { recursive: true });
|
|
7357
|
+
const lines = targets.map((t) => args.options.delete && folders.includes(native(site, t.repo.path)) ? ` removed ${t.repo.path} and deleted its folder` : args.options.delete ? ` removed ${t.repo.path} (it was not cloned)` : ` removed ${t.repo.path}; its folder stays on disk and is now unmanaged (give --delete to delete a clean one)`);
|
|
7358
|
+
return ok({
|
|
7359
|
+
text: [`removed ${targets.length} from .ergonex/repositories.ts:`, ...lines].join(`
|
|
7360
|
+
`),
|
|
7361
|
+
data: { removed: targets.map((t) => t.repo.path), deleted: folders.length },
|
|
7362
|
+
findings: []
|
|
7363
|
+
});
|
|
7364
|
+
})
|
|
7365
|
+
});
|
|
7366
|
+
var adopt = defineCommand({
|
|
7367
|
+
name: "adopt",
|
|
7368
|
+
summary: "Find the repositories under the root that the manifest does not name; --apply adds those that are where their remote puts them.",
|
|
7369
|
+
options: { ...GLOBAL_OPTIONS, apply: flag2({ help: "Add the adoptable repositories to the list." }) },
|
|
7370
|
+
run: (ctx, args) => withWorkspace(ctx, async (loaded) => {
|
|
7371
|
+
const found = await findUnmanaged(loaded.home, loaded.manifest.repositories.map((r) => r.path), loaded.manifest.hostKinds);
|
|
7372
|
+
if (found.length === 0)
|
|
7373
|
+
return ok({ text: "every repository under the root is in the manifest", data: { found: [] }, findings: [] });
|
|
7374
|
+
const lines = found.map((f) => {
|
|
7375
|
+
switch (f.kind) {
|
|
7376
|
+
case "adoptable":
|
|
7377
|
+
return ` ${f.path}: can be adopted (${f.remote})`;
|
|
7378
|
+
case "misplaced":
|
|
7379
|
+
return ` ${f.path}: is at the wrong path; its remote puts it at ${f.belongsAt} (move it there, ergonex never moves a repository)`;
|
|
7380
|
+
case "no-remote":
|
|
7381
|
+
return ` ${f.path}: has no remote called origin`;
|
|
7382
|
+
case "not-a-host":
|
|
7383
|
+
return ` ${f.path}: its origin is not a repository on a Git host`;
|
|
7384
|
+
default:
|
|
7385
|
+
return absurd(f);
|
|
7386
|
+
}
|
|
7387
|
+
});
|
|
7388
|
+
const adoptable = found.flatMap((f) => f.kind === "adoptable" ? [f] : []);
|
|
7389
|
+
if (!args.options.apply || adoptable.length === 0) {
|
|
7390
|
+
const tail = adoptable.length > 0 ? ["give --apply to add the ones that can be adopted"] : [];
|
|
7391
|
+
return ok({
|
|
7392
|
+
text: [`${found.length} not in the manifest:`, ...lines, ...tail].join(`
|
|
7393
|
+
`),
|
|
7394
|
+
data: jsonOf({ found }),
|
|
7395
|
+
findings: []
|
|
7396
|
+
});
|
|
7397
|
+
}
|
|
7398
|
+
const raw = await readRawManifest(loaded.home);
|
|
7399
|
+
if (raw.kind === "err")
|
|
7400
|
+
return err({ kind: "environment", message: raw.error });
|
|
7401
|
+
const next = addEntries(raw.value.list, adoptable.map((a) => ({ remote: a.remote })));
|
|
7402
|
+
const problems = problemsOf(raw.value.base, next);
|
|
7403
|
+
if (problems.length > 0)
|
|
7404
|
+
return err({ kind: "usage", message: `nothing was adopted; the manifest would not accept it:
|
|
7405
|
+
${problems.join(`
|
|
7406
|
+
`)}` });
|
|
7407
|
+
await writeRepositoryList(loaded.home, next);
|
|
7408
|
+
return ok({
|
|
7409
|
+
text: [`adopted ${adoptable.length} into .ergonex/repositories.ts; the others are not changed:`, ...lines].join(`
|
|
7410
|
+
`),
|
|
7411
|
+
data: jsonOf({ adopted: adoptable.map((a) => a.path), found }),
|
|
7412
|
+
findings: []
|
|
7413
|
+
});
|
|
7414
|
+
})
|
|
7415
|
+
});
|
|
7416
|
+
var addModule = { name: "add", summary: add.summary, commands: [add] };
|
|
7417
|
+
var removeModule = { name: "remove", summary: removeCommand.summary, commands: [removeCommand] };
|
|
7418
|
+
var adoptModule = { name: "adopt", summary: adopt.summary, commands: [adopt] };
|
|
7419
|
+
|
|
6970
7420
|
// src/token.ts
|
|
6971
7421
|
var READS = ["read:packages", "write:packages"];
|
|
6972
7422
|
function scopesOf(response) {
|
|
@@ -8695,7 +9145,8 @@ function globalInstall(l) {
|
|
|
8695
9145
|
var firstLine = (s) => s.split(`
|
|
8696
9146
|
`).find((l) => l.trim() !== "")?.trim() ?? "no reason given";
|
|
8697
9147
|
async function putOnPath(deps, launch) {
|
|
8698
|
-
const
|
|
9148
|
+
const found = deps.which("ergonex");
|
|
9149
|
+
const there = found !== undefined && launch.kind === "registry" && isRegistryCopy(found) ? undefined : found;
|
|
8699
9150
|
if (there !== undefined)
|
|
8700
9151
|
return {
|
|
8701
9152
|
lines: [`ergonex is already on your path (${there})`],
|
|
@@ -8784,7 +9235,7 @@ var init = defineCommand({
|
|
|
8784
9235
|
lines.push(...r.lines);
|
|
8785
9236
|
onPath = r.data;
|
|
8786
9237
|
}
|
|
8787
|
-
lines.push("next:
|
|
9238
|
+
lines.push("next: add a repository with `ergonex add github.com/owner/repo --apply`");
|
|
8788
9239
|
return ok({
|
|
8789
9240
|
text: lines.join(`
|
|
8790
9241
|
`),
|
|
@@ -10734,6 +11185,15 @@ var status2 = defineCommand({
|
|
|
10734
11185
|
return absurd(state);
|
|
10735
11186
|
}
|
|
10736
11187
|
}
|
|
11188
|
+
for (const u of await findUnmanaged(loaded.home, repos.map((r) => r.path), loaded.manifest.hostKinds)) {
|
|
11189
|
+
findings.push({
|
|
11190
|
+
ruleId: "ergonex/unmanaged-repository",
|
|
11191
|
+
severity: "Informational",
|
|
11192
|
+
message: u.kind === "adoptable" ? `${u.path} is a repository the manifest does not name; \`ergonex adopt --apply\` adds it` : u.kind === "misplaced" ? `${u.path} is a repository the manifest does not name and is not at the path its remote makes (${u.belongsAt}); see \`ergonex adopt\`` : `${u.path} is a repository the manifest does not name; see \`ergonex adopt\``,
|
|
11193
|
+
subject: u.path,
|
|
11194
|
+
firstSeen: ctx.today
|
|
11195
|
+
});
|
|
11196
|
+
}
|
|
10737
11197
|
const width = Math.max(0, ...rows.map((r) => r.path.length));
|
|
10738
11198
|
const lines = rows.map((r) => `${r.path.padEnd(width)} ${describeState(r.state).padEnd(12)} ahead ${r.ahead} behind ${r.behind} stashes ${r.stashes} untracked ${r.untracked} ${r.locked ? "locked" : "unlocked"}`);
|
|
10739
11199
|
return ok({
|
|
@@ -11100,6 +11560,9 @@ var worktreeModule = {
|
|
|
11100
11560
|
// src/commands/mod.ts
|
|
11101
11561
|
var BUILTIN_MODULES = [
|
|
11102
11562
|
initModule,
|
|
11563
|
+
addModule,
|
|
11564
|
+
removeModule,
|
|
11565
|
+
adoptModule,
|
|
11103
11566
|
planModule,
|
|
11104
11567
|
applyModule,
|
|
11105
11568
|
statusModule,
|
|
@@ -11700,7 +12163,7 @@ var TIER2_EVENTS = {
|
|
|
11700
12163
|
};
|
|
11701
12164
|
|
|
11702
12165
|
// ../ts/quality/pure/ledger.ts
|
|
11703
|
-
var
|
|
12166
|
+
var text3 = string;
|
|
11704
12167
|
var requirement2 = refine(string, "RequirementId", (s) => /^\S+ (?:FR|SC)-\d{3}[a-z]?$/.test(s) || /^objective:[a-z0-9.-]+$/.test(s));
|
|
11705
12168
|
var opener = tagged({
|
|
11706
12169
|
system: object({ kind: literal("system") }),
|
|
@@ -11717,7 +12180,7 @@ var events = tagged({
|
|
|
11717
12180
|
id: string,
|
|
11718
12181
|
requirement: requirement2,
|
|
11719
12182
|
cause,
|
|
11720
|
-
reason:
|
|
12183
|
+
reason: text3,
|
|
11721
12184
|
evidence: evidenceRef,
|
|
11722
12185
|
openedBy: opener,
|
|
11723
12186
|
day: dayDecoder
|
|
@@ -11732,7 +12195,7 @@ var events = tagged({
|
|
|
11732
12195
|
kind: literal("capa-opened"),
|
|
11733
12196
|
id: string,
|
|
11734
12197
|
nonconformance: string,
|
|
11735
|
-
action:
|
|
12198
|
+
action: text3,
|
|
11736
12199
|
test: object({ requirement: requirement2, name: string }),
|
|
11737
12200
|
correctiveRevision: string,
|
|
11738
12201
|
openedBy: opener,
|
|
@@ -11741,7 +12204,7 @@ var events = tagged({
|
|
|
11741
12204
|
"capa-verified": object({ kind: literal("capa-verified"), id: string, traceId: string, revision: string, day: dayDecoder }),
|
|
11742
12205
|
"capa-closed": object({ kind: literal("capa-closed"), id: string, decision, day: dayDecoder }),
|
|
11743
12206
|
"nonconformance-closed": object({ kind: literal("nonconformance-closed"), id: string, capa: string, day: dayDecoder }),
|
|
11744
|
-
statement: object({ kind: literal("statement"), requirement: requirement2, by, who: string, day: dayDecoder }, { note:
|
|
12207
|
+
statement: object({ kind: literal("statement"), requirement: requirement2, by, who: string, day: dayDecoder }, { note: text3 }),
|
|
11745
12208
|
review: object({ kind: literal("review"), requirement: requirement2, by, who: string, day: dayDecoder }, { sample: boolean }),
|
|
11746
12209
|
probe: object({ kind: literal("probe"), requirement: requirement2, outcome: literal("pass", "fail"), source: string, day: dayDecoder }),
|
|
11747
12210
|
...TIER2_EVENTS
|
|
@@ -12071,7 +12534,7 @@ async function writeRunEvidence(deps, facts) {
|
|
|
12071
12534
|
}
|
|
12072
12535
|
|
|
12073
12536
|
// src/ergonex.ts
|
|
12074
|
-
var
|
|
12537
|
+
var line2 = (text) => text.endsWith(`
|
|
12075
12538
|
`) ? text : `${text}
|
|
12076
12539
|
`;
|
|
12077
12540
|
function homeWord(words) {
|
|
@@ -12113,7 +12576,7 @@ async function main(argv, deps = {}) {
|
|
|
12113
12576
|
interact: deps.interact ?? terminalInteract(),
|
|
12114
12577
|
homeFor,
|
|
12115
12578
|
stdin: deps.stdin ?? (() => stdin2.text()),
|
|
12116
|
-
note: (t) => note(
|
|
12579
|
+
note: (t) => note(line2(t))
|
|
12117
12580
|
};
|
|
12118
12581
|
let command = "usage";
|
|
12119
12582
|
let words = argv;
|
|
@@ -12123,13 +12586,13 @@ async function main(argv, deps = {}) {
|
|
|
12123
12586
|
const [first, ...rest] = argv;
|
|
12124
12587
|
if (first === undefined) {
|
|
12125
12588
|
const root = homeFor(undefined);
|
|
12126
|
-
out(
|
|
12589
|
+
out(line2(guidanceFor({
|
|
12127
12590
|
home: root,
|
|
12128
12591
|
hasWorkspace: root !== undefined && existsSync2(join6(root, AREA))
|
|
12129
12592
|
})));
|
|
12130
12593
|
return 0;
|
|
12131
12594
|
} else if (first === "--help" || first === "-h") {
|
|
12132
|
-
out(
|
|
12595
|
+
out(line2(topHelp(builtins)));
|
|
12133
12596
|
return 0;
|
|
12134
12597
|
} else if (first.startsWith("-")) {
|
|
12135
12598
|
outcome = err({
|
|
@@ -12157,7 +12620,7 @@ async function main(argv, deps = {}) {
|
|
|
12157
12620
|
command = `${mine.name} ${d.command.name}`;
|
|
12158
12621
|
break;
|
|
12159
12622
|
case "help":
|
|
12160
|
-
out(
|
|
12623
|
+
out(line2([
|
|
12161
12624
|
`ergonex ${mine.name}: ${mine.summary}`,
|
|
12162
12625
|
"",
|
|
12163
12626
|
...mine.commands.map((c) => ` ergonex ${mine.name} ${c.name} ${c.summary}`)
|
|
@@ -12219,7 +12682,7 @@ async function main(argv, deps = {}) {
|
|
|
12219
12682
|
}
|
|
12220
12683
|
const loopback = executed !== undefined && loopbackAllowed(environment);
|
|
12221
12684
|
if (loopback)
|
|
12222
|
-
note(
|
|
12685
|
+
note(line2(LOOPBACK_NOTICE));
|
|
12223
12686
|
const globals = executed?.globals ?? {
|
|
12224
12687
|
json: false,
|
|
12225
12688
|
sarif: false,
|
|
@@ -12241,18 +12704,18 @@ async function main(argv, deps = {}) {
|
|
|
12241
12704
|
runFacts = r.runFacts;
|
|
12242
12705
|
noEvidence = r.noEvidence === true;
|
|
12243
12706
|
if (globals.sarif)
|
|
12244
|
-
out(
|
|
12707
|
+
out(line2(JSON.stringify(toSarif(findings), null, 2)));
|
|
12245
12708
|
else if (globals.json)
|
|
12246
|
-
out(
|
|
12709
|
+
out(line2(JSON.stringify({ command, status, exitCode: code, data: r.data, findings }, null, 2)));
|
|
12247
12710
|
else if (r.text !== "")
|
|
12248
|
-
out(
|
|
12711
|
+
out(line2(r.text));
|
|
12249
12712
|
} else {
|
|
12250
12713
|
status = outcome.error.kind === "usage" ? "Usage" : "Environment";
|
|
12251
12714
|
noEvidence = outcome.error.noEvidence === true;
|
|
12252
12715
|
code = exitCodeOf(status);
|
|
12253
12716
|
notRun = outcome.error.message.split(`
|
|
12254
12717
|
`)[0] ?? "";
|
|
12255
|
-
note(
|
|
12718
|
+
note(line2(`ergonex: ${executed === undefined ? "" : `${command}: `}${outcome.error.message}`));
|
|
12256
12719
|
}
|
|
12257
12720
|
const home = homeFor(globals.home);
|
|
12258
12721
|
const places = placed.kind === "ok" ? placed.value : undefined;
|
|
@@ -12280,7 +12743,7 @@ async function main(argv, deps = {}) {
|
|
|
12280
12743
|
end
|
|
12281
12744
|
}, regulated).then((w) => w.kind === "err" ? w.error.reason : undefined);
|
|
12282
12745
|
if (failure !== undefined) {
|
|
12283
|
-
note(
|
|
12746
|
+
note(line2(`ergonex: the evidence record could not be written (${failure}); the run is reported as a failure of the host`));
|
|
12284
12747
|
return exitCodeOf("Environment");
|
|
12285
12748
|
}
|
|
12286
12749
|
}
|
|
@@ -12290,4 +12753,4 @@ if (false)
|
|
|
12290
12753
|
;
|
|
12291
12754
|
|
|
12292
12755
|
// bin/main.ts
|
|
12293
|
-
|
|
12756
|
+
process7.exit(await main(process7.argv.slice(2)));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intellectual-frontiers/ergonex",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "Ergonex, the workspaces management of Intellectual Frontiers: one command that sets up, configures and operates a team's software repositories, package registries and builds, on Windows, macOS and Linux, with Bun by default and Node 26 as the backup.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|