@the-vibe-company/armada 0.2.32 → 0.2.33
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/dist/armada.js +234 -32
- package/package.json +1 -1
package/dist/armada.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// src/main.ts
|
|
4
4
|
import { spawn as spawn2, spawnSync } from "node:child_process";
|
|
5
5
|
import { createReadStream } from "node:fs";
|
|
6
|
-
import { open as open2, readFile as
|
|
6
|
+
import { open as open2, readFile as readFile4 } from "node:fs/promises";
|
|
7
7
|
import { hostname as hostname2 } from "node:os";
|
|
8
8
|
import { isatty } from "node:tty";
|
|
9
9
|
|
|
@@ -4518,6 +4518,19 @@ function transientFailure(err) {
|
|
|
4518
4518
|
return s >= 500 || s === 408 || s === 429;
|
|
4519
4519
|
return /\bunreachable\b|\bHTTP (?:5\d\d|408|429) without JSON\b/.test(err.message);
|
|
4520
4520
|
}
|
|
4521
|
+
async function untilAborted(signal, work) {
|
|
4522
|
+
signal?.throwIfAborted();
|
|
4523
|
+
if (!signal)
|
|
4524
|
+
return await work();
|
|
4525
|
+
return new Promise((resolve, reject) => {
|
|
4526
|
+
const abort = () => reject(signal.reason);
|
|
4527
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
4528
|
+
Promise.resolve().then(() => {
|
|
4529
|
+
signal.throwIfAborted();
|
|
4530
|
+
return work();
|
|
4531
|
+
}).then(resolve, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
4532
|
+
});
|
|
4533
|
+
}
|
|
4521
4534
|
async function watchInbox(fleet, o) {
|
|
4522
4535
|
const query = {
|
|
4523
4536
|
coordinator: o.coordinator,
|
|
@@ -4545,14 +4558,14 @@ async function watchInbox(fleet, o) {
|
|
|
4545
4558
|
for (;; ) {
|
|
4546
4559
|
let read;
|
|
4547
4560
|
try {
|
|
4548
|
-
read = await fleet.inbox({ ...query, etag });
|
|
4561
|
+
read = await untilAborted(o.signal, () => fleet.inbox({ ...query, etag }));
|
|
4549
4562
|
} catch (err) {
|
|
4550
4563
|
if (!transientFailure(err))
|
|
4551
4564
|
throw err;
|
|
4552
4565
|
const wait = WATCH_BACKOFF_MS[Math.min(failures, WATCH_BACKOFF_MS.length - 1)] ?? pollMs;
|
|
4553
4566
|
failures++;
|
|
4554
4567
|
o.onRetry?.(`${err.message}; still watching, next try in ${wait / 1000} s`);
|
|
4555
|
-
await o.sleep(wait);
|
|
4568
|
+
await untilAborted(o.signal, () => o.sleep(wait));
|
|
4556
4569
|
continue;
|
|
4557
4570
|
}
|
|
4558
4571
|
failures = 0;
|
|
@@ -4563,16 +4576,16 @@ async function watchInbox(fleet, o) {
|
|
|
4563
4576
|
known = new Set(items.map(entryKey));
|
|
4564
4577
|
for (const w of read.warnings)
|
|
4565
4578
|
warnings.add(w);
|
|
4566
|
-
await o.onRead?.({ items, inFlight });
|
|
4579
|
+
await untilAborted(o.signal, () => o.onRead?.({ items, inFlight }));
|
|
4567
4580
|
}
|
|
4568
|
-
const release = await o.release?.() ?? null;
|
|
4581
|
+
const release = await untilAborted(o.signal, () => o.release?.()) ?? null;
|
|
4569
4582
|
if (release)
|
|
4570
4583
|
items = [...items, { ...release, new: true }];
|
|
4571
4584
|
if (items.some((e) => e.new))
|
|
4572
4585
|
return report("items");
|
|
4573
4586
|
if (read && inFlight !== null && !inFlight.length && !items.length)
|
|
4574
4587
|
return report("nothing");
|
|
4575
|
-
await o.sleep(inFlight !== null && !inFlight.length ? idlePollMs : pollMs);
|
|
4588
|
+
await untilAborted(o.signal, () => o.sleep(inFlight !== null && !inFlight.length ? idlePollMs : pollMs));
|
|
4576
4589
|
}
|
|
4577
4590
|
}
|
|
4578
4591
|
function releaseEntry(running, latest, at) {
|
|
@@ -4807,16 +4820,42 @@ async function updateWatchState(paths, project, patch) {
|
|
|
4807
4820
|
`, 384);
|
|
4808
4821
|
return state;
|
|
4809
4822
|
}
|
|
4810
|
-
async function
|
|
4823
|
+
async function readWatchLockInfo(paths, project) {
|
|
4811
4824
|
try {
|
|
4812
|
-
const
|
|
4813
|
-
|
|
4825
|
+
const raw = JSON.parse(await readFile(watchFiles(paths, project).lock, "utf8"));
|
|
4826
|
+
const pid = typeof raw === "number" ? raw : raw?.pid;
|
|
4827
|
+
if (!Number.isSafeInteger(pid) || pid <= 0)
|
|
4828
|
+
return null;
|
|
4829
|
+
const i = raw?.identity;
|
|
4830
|
+
const verified = i && [i.project, i.configPath, i.started, i.command, i.cwd].every((v) => typeof v === "string" && v);
|
|
4831
|
+
return {
|
|
4832
|
+
pid,
|
|
4833
|
+
identity: verified ? {
|
|
4834
|
+
project: i.project,
|
|
4835
|
+
configPath: i.configPath,
|
|
4836
|
+
started: i.started,
|
|
4837
|
+
command: i.command,
|
|
4838
|
+
cwd: i.cwd
|
|
4839
|
+
} : null
|
|
4840
|
+
};
|
|
4814
4841
|
} catch (err) {
|
|
4815
|
-
if (missing(err))
|
|
4842
|
+
if (missing(err) || err instanceof SyntaxError)
|
|
4816
4843
|
return null;
|
|
4817
4844
|
throw err;
|
|
4818
4845
|
}
|
|
4819
4846
|
}
|
|
4847
|
+
async function readWatchLock(paths, project) {
|
|
4848
|
+
return (await readWatchLockInfo(paths, project))?.pid ?? null;
|
|
4849
|
+
}
|
|
4850
|
+
function sameWatchLock(a, b) {
|
|
4851
|
+
if (a?.pid !== b.pid)
|
|
4852
|
+
return false;
|
|
4853
|
+
const left = a.identity;
|
|
4854
|
+
const right = b.identity;
|
|
4855
|
+
if (!left || !right)
|
|
4856
|
+
return left === right;
|
|
4857
|
+
return ["project", "configPath", "started", "command", "cwd"].every((field) => left[field] === right[field]);
|
|
4858
|
+
}
|
|
4820
4859
|
function processAlive(pid) {
|
|
4821
4860
|
try {
|
|
4822
4861
|
process.kill(pid, 0);
|
|
@@ -4825,11 +4864,11 @@ function processAlive(pid) {
|
|
|
4825
4864
|
return err.code === "EPERM";
|
|
4826
4865
|
}
|
|
4827
4866
|
}
|
|
4828
|
-
async function takeWatchLock(paths, project, pid, alive = processAlive) {
|
|
4867
|
+
async function takeWatchLock(paths, project, pid, alive = processAlive, identity) {
|
|
4829
4868
|
const { lock } = watchFiles(paths, project);
|
|
4830
4869
|
await mkdir(dirname(lock), { recursive: true, mode: 448 });
|
|
4831
4870
|
const tmp = `${lock}.${randomBytes(6).toString("hex")}.tmp`;
|
|
4832
|
-
await writeFile(tmp, `${pid}
|
|
4871
|
+
await writeFile(tmp, `${identity ? JSON.stringify({ pid, identity }) : pid}
|
|
4833
4872
|
`, { mode: 384 });
|
|
4834
4873
|
try {
|
|
4835
4874
|
for (let attempt = 0;attempt < 3; attempt++) {
|
|
@@ -4851,8 +4890,9 @@ async function takeWatchLock(paths, project, pid, alive = processAlive) {
|
|
|
4851
4890
|
await rm(tmp, { force: true });
|
|
4852
4891
|
}
|
|
4853
4892
|
}
|
|
4854
|
-
async function releaseWatchLock(paths, project, pid) {
|
|
4855
|
-
|
|
4893
|
+
async function releaseWatchLock(paths, project, pid, identity) {
|
|
4894
|
+
const held = await readWatchLockInfo(paths, project).catch(() => null);
|
|
4895
|
+
if (identity ? sameWatchLock(held, { pid, identity }) : held?.pid === pid)
|
|
4856
4896
|
await rm(watchFiles(paths, project).lock, { force: true });
|
|
4857
4897
|
}
|
|
4858
4898
|
async function runningWatch(paths, project, alive = processAlive) {
|
|
@@ -5761,6 +5801,7 @@ Repeat from step 1.
|
|
|
5761
5801
|
|
|
5762
5802
|
You only learn of something new when a command you run ends. So while a worker is in flight, always have exactly one \`armada watch\` running, in the background (in Claude Code, a Bash command with \`run_in_background\`; in another runtime, its own way of running a command in the background). It waits until something needs you (a question, a plan, a request, a hand-back, a silent worker or one that never started, you have not been shown yet), prints it and exits, and you are woken. Armada being down or a command time limit does not end it, and it tells the dashboard you are at work.
|
|
5763
5803
|
|
|
5804
|
+
- \`armada inbox\` and \`armada status\` run fine while a watch runs: never stop it to read the inbox or the fleet. To stop this project's watch, use \`armada watch --stop\`, never \`pkill\` or \`killall\` patterns: those can kill other projects' watches on the same machine.
|
|
5764
5805
|
- Start it as soon as a worker is in flight, and start it again right after acting on what it returned. Never end your turn with a worker in flight and no watch running: that is how a hand-back sits unmerged.
|
|
5765
5806
|
- The last line of \`armada inbox\`, \`armada watch\`, \`armada merge\` and \`armada brief\` says whether to: \`2 workers in flight (ABC-1, ABC-2) — keep watching: armada watch\`, \`armada watch is already running (pid …)\`, or \`nothing to watch\`. Follow it. A second \`armada watch\` on the same project only says the first one is running.
|
|
5766
5807
|
- \`armada watch\` exits with "nothing to watch" when no worker is in flight and nothing is open: the round is over.
|
|
@@ -5798,6 +5839,7 @@ Armada never calls a runtime. This guide tells a coordinator running inside Clau
|
|
|
5798
5839
|
- A worker is one background subagent. Its Armada handle is its name: the ticket id in lowercase (\`abc-12\` for ABC-12), which the brief's claim line already uses. The worker's claim comment carries it, so \`armada status\` and the ticket lead back to the subagent.
|
|
5799
5840
|
- **It shares your machine and environment**: your \`gh\` sign-in for its pushes, your installed \`armada\`, and every environment variable of your session. A worker needs no key: the prompt of \`armada brief\` carries a one-time launch token, and its first command exchanges it for a session limited to its ticket, kept in the machine's credentials file next to your own sign-in. Because it inherits your environment, an \`ARMADA_TICKET\` of yours is not its ticket: the brief tells it to pass \`--ticket\` to every command.
|
|
5800
5841
|
- Run \`armada watch\` in the background while a worker is in flight, as the coordinator skill says: a worker's question, plan or hand-back reaches your inbox, not your conversation. The task notification Claude Code sends when a subagent stops is a hint to look, not the record.
|
|
5842
|
+
- \`armada inbox\` and \`armada status\` run fine while a watch runs: never stop it to read the inbox or the fleet. To stop this project's watch, use \`armada watch --stop\`, never \`pkill\` or \`killall\` patterns: those can kill other projects' watches on the same machine.
|
|
5801
5843
|
|
|
5802
5844
|
## Launch
|
|
5803
5845
|
|
|
@@ -9859,7 +9901,7 @@ ${attachments.join(`
|
|
|
9859
9901
|
};
|
|
9860
9902
|
}
|
|
9861
9903
|
// package.json
|
|
9862
|
-
var version = "0.2.
|
|
9904
|
+
var version = "0.2.33";
|
|
9863
9905
|
|
|
9864
9906
|
// src/attach.ts
|
|
9865
9907
|
import { resolve } from "node:path";
|
|
@@ -10828,29 +10870,100 @@ async function watch(io, config, credentials, a, configPath) {
|
|
|
10828
10870
|
throw err;
|
|
10829
10871
|
}
|
|
10830
10872
|
}
|
|
10873
|
+
async function stopWatch(io, project, json) {
|
|
10874
|
+
const paths = machinePaths(io.env);
|
|
10875
|
+
const lock = paths ? await readWatchLockInfo(paths, project) : null;
|
|
10876
|
+
const print = (pid) => {
|
|
10877
|
+
const line = pid === null ? `no watch running for ${project}` : `Stopped armada watch for ${project} (pid ${pid}).`;
|
|
10878
|
+
io.stdout(json ? `${JSON.stringify({ project, stopped: pid, line }, null, 2)}
|
|
10879
|
+
` : `${line}
|
|
10880
|
+
`);
|
|
10881
|
+
};
|
|
10882
|
+
if (!paths || !lock) {
|
|
10883
|
+
print(null);
|
|
10884
|
+
return 0;
|
|
10885
|
+
}
|
|
10886
|
+
if (!alive(io)(lock.pid)) {
|
|
10887
|
+
await releaseWatchLock(paths, project, lock.pid, lock.identity ?? undefined);
|
|
10888
|
+
print(null);
|
|
10889
|
+
return 0;
|
|
10890
|
+
}
|
|
10891
|
+
const identity = lock.identity;
|
|
10892
|
+
let configProject = null;
|
|
10893
|
+
if (identity) {
|
|
10894
|
+
try {
|
|
10895
|
+
const text = await io.readFile(identity.configPath);
|
|
10896
|
+
if (text !== null)
|
|
10897
|
+
configProject = parseConfig(text, identity.configPath).project.slug;
|
|
10898
|
+
} catch {}
|
|
10899
|
+
}
|
|
10900
|
+
const process2 = identity ? await io.inspectProcess?.(lock.pid) : null;
|
|
10901
|
+
const isWatch = identity && /(?:^|\s)(?:\S*\/)?(?:armada(?:\.js)?|packages\/cli\/src\/(?:main|bin)\.ts)\s+(?:(?:--json|--all)\s+|--config(?:=\S+|\s+\S+)\s+)*watch(?:\s|$)/.test(identity.command) && !/(?:^|\s)--stop(?:\s|$)/.test(identity.command);
|
|
10902
|
+
if (!identity || identity.project !== project || configProject !== project || !isWatch || !process2 || process2.started !== identity.started || process2.command !== identity.command || process2.cwd !== identity.cwd || !io.signalProcess || !sameWatchLock(await readWatchLockInfo(paths, project), lock)) {
|
|
10903
|
+
throw new Refusal(`cannot verify armada watch for ${project} (pid ${lock.pid}); left the process and lock untouched`, "armada watch --help");
|
|
10904
|
+
}
|
|
10905
|
+
try {
|
|
10906
|
+
await io.signalProcess(lock.pid, "SIGTERM");
|
|
10907
|
+
} catch (err) {
|
|
10908
|
+
if (err.code !== "ESRCH")
|
|
10909
|
+
throw err;
|
|
10910
|
+
await releaseWatchLock(paths, project, lock.pid, identity);
|
|
10911
|
+
print(null);
|
|
10912
|
+
return 0;
|
|
10913
|
+
}
|
|
10914
|
+
await releaseWatchLock(paths, project, lock.pid, identity);
|
|
10915
|
+
print(lock.pid);
|
|
10916
|
+
return 0;
|
|
10917
|
+
}
|
|
10831
10918
|
async function watchUntil(io, config, credentials, json, configPath) {
|
|
10832
10919
|
requireSignIn(credentials);
|
|
10833
|
-
const { fleet, warning } = liveFleet(io, config, credentials);
|
|
10834
|
-
if (!fleet)
|
|
10835
|
-
throw new Refusal(`the inbox is on Armada, which cannot be reached: ${warning ?? "no answer"}`, "armada whoami");
|
|
10836
10920
|
const project = config.project.slug;
|
|
10837
10921
|
const paths = machinePaths(io.env);
|
|
10838
10922
|
const pid = io.pid ?? process.pid;
|
|
10839
|
-
|
|
10840
|
-
|
|
10841
|
-
|
|
10842
|
-
|
|
10843
|
-
|
|
10923
|
+
const controller = new AbortController;
|
|
10924
|
+
let stoppedBy = null;
|
|
10925
|
+
let unsubscribe;
|
|
10926
|
+
let identity;
|
|
10927
|
+
let taken = false;
|
|
10928
|
+
try {
|
|
10929
|
+
unsubscribe = io.onSignal?.((signal) => {
|
|
10930
|
+
if (stoppedBy)
|
|
10931
|
+
return;
|
|
10932
|
+
stoppedBy = signal;
|
|
10933
|
+
controller.abort(new Error("watch stopped"));
|
|
10934
|
+
});
|
|
10935
|
+
controller.signal.throwIfAborted();
|
|
10936
|
+
const inspected = await io.inspectProcess?.(pid);
|
|
10937
|
+
identity = inspected ? { ...inspected, project, configPath } : undefined;
|
|
10938
|
+
controller.signal.throwIfAborted();
|
|
10939
|
+
if (paths) {
|
|
10940
|
+
const lock = await takeWatchLock(paths, project, pid, alive(io), identity);
|
|
10941
|
+
taken = lock.taken;
|
|
10942
|
+
controller.signal.throwIfAborted();
|
|
10943
|
+
if (!lock.taken) {
|
|
10944
|
+
const line = `armada watch is already running for ${project} (pid ${lock.pid}): its output arrives when it ends.`;
|
|
10945
|
+
io.stdout(json ? `${JSON.stringify({ project, running: lock.pid, line }, null, 2)}
|
|
10844
10946
|
` : `${line}
|
|
10845
10947
|
`);
|
|
10846
|
-
|
|
10948
|
+
return 0;
|
|
10949
|
+
}
|
|
10847
10950
|
}
|
|
10848
|
-
|
|
10849
|
-
|
|
10951
|
+
const fetch2 = io.fetch;
|
|
10952
|
+
const watchingIo = {
|
|
10953
|
+
...io,
|
|
10954
|
+
fetch: fetch2 ? (url, init) => fetch2(url, {
|
|
10955
|
+
...init,
|
|
10956
|
+
signal: init?.signal ? AbortSignal.any([init.signal, controller.signal]) : controller.signal
|
|
10957
|
+
}) : undefined
|
|
10958
|
+
};
|
|
10959
|
+
const { fleet, warning } = liveFleet(watchingIo, config, credentials);
|
|
10960
|
+
if (!fleet)
|
|
10961
|
+
throw new Refusal(`the inbox is on Armada, which cannot be reached: ${warning ?? "no answer"}`, "armada whoami");
|
|
10850
10962
|
const before = paths ? await readWatchState(paths, project) : null;
|
|
10851
10963
|
await remember(io, project, { root: dirname2(configPath), stopped: null });
|
|
10852
10964
|
const report = await watchInbox(fleet, {
|
|
10853
10965
|
project,
|
|
10966
|
+
signal: controller.signal,
|
|
10854
10967
|
coordinator: coordinatorHandle(io),
|
|
10855
10968
|
facts: detectCoordinator(io),
|
|
10856
10969
|
silentAfterMinutes: config.policy.silentAfterMinutes,
|
|
@@ -10858,19 +10971,28 @@ async function watchUntil(io, config, credentials, json, configPath) {
|
|
|
10858
10971
|
notStartedMinutes: config.policy.notStartedMinutes,
|
|
10859
10972
|
seen: before?.seen ?? [],
|
|
10860
10973
|
now: io.now ?? (() => new Date),
|
|
10861
|
-
sleep: io.sleep ?? ((ms) => new Promise((done) =>
|
|
10974
|
+
sleep: io.sleep ?? ((ms) => new Promise((done) => {
|
|
10975
|
+
const timer = setTimeout(finish, ms);
|
|
10976
|
+
function finish() {
|
|
10977
|
+
clearTimeout(timer);
|
|
10978
|
+
controller.signal.removeEventListener("abort", finish);
|
|
10979
|
+
done();
|
|
10980
|
+
}
|
|
10981
|
+
controller.signal.addEventListener("abort", finish, { once: true });
|
|
10982
|
+
})),
|
|
10862
10983
|
onRead: async ({ inFlight }) => {
|
|
10863
10984
|
if (inFlight)
|
|
10864
10985
|
await remember(io, project, { inFlight, readAt: now(io).toISOString() });
|
|
10865
10986
|
},
|
|
10866
10987
|
onRetry: (message) => io.stderr(`armada: warning: ${message}
|
|
10867
10988
|
`),
|
|
10868
|
-
release: pendingRelease(
|
|
10989
|
+
release: pendingRelease(watchingIo, version, before?.seen ?? [])
|
|
10869
10990
|
});
|
|
10870
10991
|
await remember(io, project, shown(io, report.items, report.inFlight));
|
|
10871
10992
|
for (const e of report.items)
|
|
10872
10993
|
if (e.kind === "version" && e.version)
|
|
10873
10994
|
await rememberRelease(io, e.version);
|
|
10995
|
+
controller.signal.throwIfAborted();
|
|
10874
10996
|
const open = report.items.filter((e) => e.kind !== "version").length;
|
|
10875
10997
|
const next = rearm({ inFlight: report.inFlight, open, running: null, act: true });
|
|
10876
10998
|
if (json)
|
|
@@ -10885,11 +11007,20 @@ async function watchUntil(io, config, credentials, json, configPath) {
|
|
|
10885
11007
|
for (const w of report.warnings)
|
|
10886
11008
|
io.stderr(`armada: warning: ${w}
|
|
10887
11009
|
`);
|
|
10888
|
-
|
|
11010
|
+
} catch (err) {
|
|
11011
|
+
if (!stoppedBy)
|
|
11012
|
+
throw err;
|
|
10889
11013
|
} finally {
|
|
10890
|
-
if (paths)
|
|
10891
|
-
await releaseWatchLock(paths, project, pid).catch(() => {});
|
|
11014
|
+
if (paths && taken)
|
|
11015
|
+
await releaseWatchLock(paths, project, pid, identity).catch(() => {});
|
|
11016
|
+
unsubscribe?.();
|
|
10892
11017
|
}
|
|
11018
|
+
if (stoppedBy) {
|
|
11019
|
+
io.stdout(`armada watch for ${project} stopped by ${stoppedBy} (pid ${pid})
|
|
11020
|
+
`);
|
|
11021
|
+
return stoppedBy === "SIGINT" ? 130 : stoppedBy === "SIGTERM" ? 143 : 129;
|
|
11022
|
+
}
|
|
11023
|
+
return 0;
|
|
10893
11024
|
}
|
|
10894
11025
|
async function hookStop(io, rest, findConfig) {
|
|
10895
11026
|
if (rest[0] !== "stop" || rest.length > 1)
|
|
@@ -12665,6 +12796,8 @@ var COMMAND_HELP = {
|
|
|
12665
12796
|
when no worker is in flight and nothing is open. Armada being down or a
|
|
12666
12797
|
command time limit does not end it: it keeps asking. One per project on
|
|
12667
12798
|
this machine. Needs a sign-in to Armada
|
|
12799
|
+
watch --stop Stop only this project's verified watch and release its lock. Local,
|
|
12800
|
+
no sign-in needed. Never stop a watch just to read inbox or status
|
|
12668
12801
|
`,
|
|
12669
12802
|
answer: ` answer <item|ticket> "<answer>"
|
|
12670
12803
|
Coordinator: record an answer already delivered in the worker's
|
|
@@ -12867,6 +13000,7 @@ var VALUE_OPTIONS = [
|
|
|
12867
13000
|
"validation-reason"
|
|
12868
13001
|
];
|
|
12869
13002
|
var FLAG_OPTIONS = [
|
|
13003
|
+
"stop",
|
|
12870
13004
|
"background",
|
|
12871
13005
|
"dry-run",
|
|
12872
13006
|
"no-lock",
|
|
@@ -12889,6 +13023,7 @@ var COMMAND_OPTIONS = {
|
|
|
12889
13023
|
release: ["ticket", "reason"],
|
|
12890
13024
|
ask: ["ticket", "options", "message", "message-file"],
|
|
12891
13025
|
inbox: ["wait", "timeout"],
|
|
13026
|
+
watch: ["stop"],
|
|
12892
13027
|
answer: ["note", "message", "message-file"],
|
|
12893
13028
|
init: ["program-root", "name", "slug", "no-stop-hook"],
|
|
12894
13029
|
merge: ["ticket", "no-ticket", "dry-run", "no-lock", "wait", "timeout", "reason", "ask-owner"],
|
|
@@ -13111,6 +13246,11 @@ async function dispatch(argv, io) {
|
|
|
13111
13246
|
if (args.command === "watch") {
|
|
13112
13247
|
const { path, text } = await findConfig(io, args.config, "watch");
|
|
13113
13248
|
const config = parseConfig(text, path);
|
|
13249
|
+
if (args.options.stop === "true") {
|
|
13250
|
+
if (args.rest.length)
|
|
13251
|
+
throw new UsageError(`unexpected argument ${args.rest[0]}`);
|
|
13252
|
+
return await stopWatch(io, config.project.slug, args.json);
|
|
13253
|
+
}
|
|
13114
13254
|
const { credentials } = await loadCredentials(io, { project: config.project.slug });
|
|
13115
13255
|
await recordPresence(io, config, credentials);
|
|
13116
13256
|
return await watch(io, config, credentials, args, path);
|
|
@@ -13227,6 +13367,53 @@ function echo(before, after) {
|
|
|
13227
13367
|
return "\b \b".repeat(before.length - common) + after.slice(common);
|
|
13228
13368
|
}
|
|
13229
13369
|
|
|
13370
|
+
// src/process.ts
|
|
13371
|
+
import { readFile as readFile3, readlink as readlink2 } from "node:fs/promises";
|
|
13372
|
+
async function inspectProcess(exec, pid, system = {
|
|
13373
|
+
platform: process.platform,
|
|
13374
|
+
cwd: process.cwd(),
|
|
13375
|
+
readFile: (path) => readFile3(path, "utf8"),
|
|
13376
|
+
readlink: readlink2
|
|
13377
|
+
}) {
|
|
13378
|
+
if (!Number.isSafeInteger(pid) || pid <= 0)
|
|
13379
|
+
return null;
|
|
13380
|
+
try {
|
|
13381
|
+
const options = { cwd: system.cwd };
|
|
13382
|
+
const commandArgs = ["-ww", "-p", String(pid), "-o", "command="];
|
|
13383
|
+
if (system.platform === "linux") {
|
|
13384
|
+
const before = await system.readFile(`/proc/${pid}/stat`);
|
|
13385
|
+
const [command, cwd, boot] = await Promise.all([
|
|
13386
|
+
exec("ps", commandArgs, options),
|
|
13387
|
+
system.readlink(`/proc/${pid}/cwd`),
|
|
13388
|
+
system.readFile("/proc/sys/kernel/random/boot_id")
|
|
13389
|
+
]);
|
|
13390
|
+
const after = await system.readFile(`/proc/${pid}/stat`);
|
|
13391
|
+
const start = (stat) => stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19];
|
|
13392
|
+
const started = start(before);
|
|
13393
|
+
if (command.code || !command.stdout.trim() || !boot.trim() || !started || started !== start(after))
|
|
13394
|
+
return null;
|
|
13395
|
+
return { started: `${boot.trim()}/${started}`, command: command.stdout.trim(), cwd };
|
|
13396
|
+
}
|
|
13397
|
+
if (system.platform === "darwin") {
|
|
13398
|
+
const startArgs = ["-p", String(pid), "-o", "lstart="];
|
|
13399
|
+
const before = await exec("ps", startArgs, options);
|
|
13400
|
+
const [command, cwd] = await Promise.all([
|
|
13401
|
+
exec("ps", commandArgs, options),
|
|
13402
|
+
exec("lsof", ["-a", "-p", String(pid), "-d", "cwd", "-Fn"], options)
|
|
13403
|
+
]);
|
|
13404
|
+
const after = await exec("ps", startArgs, options);
|
|
13405
|
+
const path = cwd.stdout.split(`
|
|
13406
|
+
`).find((line) => line.startsWith("n/"))?.slice(1);
|
|
13407
|
+
if (before.code || after.code || command.code || cwd.code || !command.stdout.trim() || !before.stdout.trim() || before.stdout.trim() !== after.stdout.trim() || !path)
|
|
13408
|
+
return null;
|
|
13409
|
+
return { started: before.stdout.trim(), command: command.stdout.trim(), cwd: path };
|
|
13410
|
+
}
|
|
13411
|
+
return null;
|
|
13412
|
+
} catch {
|
|
13413
|
+
return null;
|
|
13414
|
+
}
|
|
13415
|
+
}
|
|
13416
|
+
|
|
13230
13417
|
// src/spawn.ts
|
|
13231
13418
|
import { spawn } from "node:child_process";
|
|
13232
13419
|
import { constants } from "node:os";
|
|
@@ -13372,7 +13559,7 @@ var code = await run(process.argv.slice(2), {
|
|
|
13372
13559
|
ttyName: process.stdin.isTTY ? spawnSync("tty", [], { encoding: "utf8", stdio: ["inherit", "pipe", "ignore"] }).stdout?.trim() || null : null,
|
|
13373
13560
|
cwd: process.cwd(),
|
|
13374
13561
|
env: process.env,
|
|
13375
|
-
readFile: (path) =>
|
|
13562
|
+
readFile: (path) => readFile4(path, "utf8").catch((err) => {
|
|
13376
13563
|
if (err.code === "ENOENT" || err.code === "ENOTDIR")
|
|
13377
13564
|
return null;
|
|
13378
13565
|
throw err;
|
|
@@ -13409,6 +13596,21 @@ var code = await run(process.argv.slice(2), {
|
|
|
13409
13596
|
},
|
|
13410
13597
|
stderr: (t) => process.stderr.write(t),
|
|
13411
13598
|
ghToken,
|
|
13599
|
+
fetch: (url, init) => fetch(url, init),
|
|
13600
|
+
inspectProcess: (pid) => inspectProcess(exec, pid),
|
|
13601
|
+
signalProcess: (pid, signal) => {
|
|
13602
|
+
process.kill(pid, signal);
|
|
13603
|
+
},
|
|
13604
|
+
onSignal: (handler) => {
|
|
13605
|
+
const signals = ["SIGTERM", "SIGINT", "SIGHUP"];
|
|
13606
|
+
const listeners = signals.map((signal) => ({ signal, listener: () => handler(signal) }));
|
|
13607
|
+
for (const { signal, listener } of listeners)
|
|
13608
|
+
process.on(signal, listener);
|
|
13609
|
+
return () => {
|
|
13610
|
+
for (const { signal, listener } of listeners)
|
|
13611
|
+
process.off(signal, listener);
|
|
13612
|
+
};
|
|
13613
|
+
},
|
|
13412
13614
|
interactive: isatty(0) && isatty(2),
|
|
13413
13615
|
prompt,
|
|
13414
13616
|
gitBranch,
|