@the-vibe-company/armada 0.2.71 → 0.2.73
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 +213 -45
- package/package.json +1 -1
package/dist/armada.js
CHANGED
|
@@ -9743,13 +9743,23 @@ var init_driver = __esm(() => {
|
|
|
9743
9743
|
import { spawn } from "node:child_process";
|
|
9744
9744
|
import { createInterface } from "node:readline";
|
|
9745
9745
|
const options = JSON.parse(process.argv[1]);
|
|
9746
|
+
// The grace after a final result; tests shorten it, production keeps one second.
|
|
9747
|
+
const retireMs = Number.isSafeInteger(options.retireMs) && options.retireMs > 0 ? options.retireMs : 1000;
|
|
9746
9748
|
let child;
|
|
9747
9749
|
let session;
|
|
9748
9750
|
let finishing = false;
|
|
9749
9751
|
let failed = false;
|
|
9750
9752
|
let closed = false;
|
|
9753
|
+
let results = 0;
|
|
9751
9754
|
let completed = 0;
|
|
9755
|
+
// Set while the current process may take one more line: its first turn, or a held process.
|
|
9756
|
+
let accept;
|
|
9757
|
+
// Ends the current process's input once, from any path.
|
|
9758
|
+
let endInput;
|
|
9752
9759
|
const waiting = [];
|
|
9760
|
+
// Frames that mean the process is running a turn again after a result.
|
|
9761
|
+
const turnFrames = new Set(["assistant", "user", "stream_event"]);
|
|
9762
|
+
const turnSystem = new Set(["init", "thinking_tokens", "turn_starting"]);
|
|
9753
9763
|
const emit = (value) => console.log(JSON.stringify(value));
|
|
9754
9764
|
const failure = () => {
|
|
9755
9765
|
failed = true;
|
|
@@ -9757,15 +9767,15 @@ const failure = () => {
|
|
|
9757
9767
|
};
|
|
9758
9768
|
function send(line) {
|
|
9759
9769
|
if (failed) return;
|
|
9760
|
-
if (child
|
|
9761
|
-
if (!child) start();
|
|
9770
|
+
if (!child && !finishing) start();
|
|
9762
9771
|
if (!child || failed) return;
|
|
9763
|
-
|
|
9772
|
+
if (accept) accept(line);
|
|
9773
|
+
else waiting.push(line);
|
|
9764
9774
|
}
|
|
9765
9775
|
function start() {
|
|
9766
|
-
if (
|
|
9776
|
+
if (results && !session) { failure(); return; }
|
|
9767
9777
|
// A resumed print process starts fresh cumulative usage counters.
|
|
9768
|
-
if (
|
|
9778
|
+
if (results) emit({ type: "armada_turn_start" });
|
|
9769
9779
|
const cli = spawn(options.command, [...options.args, ...(session ? ["--resume", session] : [])], {
|
|
9770
9780
|
stdio: ["pipe", "pipe", "pipe"], shell: false,
|
|
9771
9781
|
});
|
|
@@ -9775,22 +9785,63 @@ function start() {
|
|
|
9775
9785
|
let retire;
|
|
9776
9786
|
let kill;
|
|
9777
9787
|
let retired = false;
|
|
9788
|
+
let lines = 0;
|
|
9789
|
+
let open = true;
|
|
9790
|
+
let held = false;
|
|
9791
|
+
// A result arrived and no turn has started since.
|
|
9792
|
+
let quiet = false;
|
|
9793
|
+
let lateLine = false;
|
|
9794
|
+
const tasks = new Set();
|
|
9795
|
+
const into = (line) => {
|
|
9796
|
+
lines++;
|
|
9797
|
+
if (held) lateLine = true;
|
|
9798
|
+
cli.stdin.write(line + "\n", (error) => { if (error) failure(); });
|
|
9799
|
+
};
|
|
9800
|
+
endInput = () => { if (open) { open = false; cli.stdin.end(); } };
|
|
9801
|
+
// No more input for this process; retire it unless another turn begins first.
|
|
9802
|
+
const settle = () => {
|
|
9803
|
+
held = false;
|
|
9804
|
+
accept = undefined;
|
|
9805
|
+
finishing = true;
|
|
9806
|
+
endInput();
|
|
9807
|
+
// Some print CLIs retain an idle process after their final result and EOF.
|
|
9808
|
+
// Retire only this completed subprocess; the supervisor's group pin stays alive.
|
|
9809
|
+
// A line written while held may start its turn after the CLI's own: allow it longer.
|
|
9810
|
+
if (!retire && !retired && !tasks.size) retire = setTimeout(() => {
|
|
9811
|
+
retired = true;
|
|
9812
|
+
cli.kill("SIGTERM");
|
|
9813
|
+
kill = setTimeout(() => cli.kill("SIGKILL"), retireMs);
|
|
9814
|
+
}, lateLine ? retireMs * 30 : retireMs);
|
|
9815
|
+
};
|
|
9816
|
+
// One line per turn: later input waits in the driver for this turn's result.
|
|
9817
|
+
const once = (line) => { accept = undefined; into(line); };
|
|
9818
|
+
accept = once;
|
|
9778
9819
|
const event = (line) => {
|
|
9779
9820
|
try {
|
|
9780
9821
|
const value = JSON.parse(line);
|
|
9781
9822
|
if (typeof value.session_id === "string" && value.session_id) session = value.session_id;
|
|
9823
|
+
if (value.type === "system" && value.subtype === "background_tasks_changed" && Array.isArray(value.tasks)) {
|
|
9824
|
+
tasks.clear();
|
|
9825
|
+
for (const task of value.tasks) if (typeof task?.task_id === "string") tasks.add(task.task_id);
|
|
9826
|
+
// Tasks that end without a turn of their own leave nothing to hold for.
|
|
9827
|
+
if (quiet && !tasks.size) settle();
|
|
9828
|
+
} else if (!retired && (turnFrames.has(value.type) || (value.type === "system" && turnSystem.has(value.subtype)))) {
|
|
9829
|
+
// Another turn began before the retire fired: neither SIGTERM nor SIGKILL is scheduled now.
|
|
9830
|
+
clearTimeout(retire);
|
|
9831
|
+
retire = undefined;
|
|
9832
|
+
held = false;
|
|
9833
|
+
quiet = false;
|
|
9834
|
+
}
|
|
9782
9835
|
if (value.type === "result") {
|
|
9783
9836
|
result = true;
|
|
9784
|
-
|
|
9785
|
-
|
|
9786
|
-
|
|
9787
|
-
|
|
9788
|
-
|
|
9789
|
-
|
|
9790
|
-
|
|
9791
|
-
|
|
9792
|
-
kill = setTimeout(() => cli.kill("SIGKILL"), 1000);
|
|
9793
|
-
}, 1000);
|
|
9837
|
+
quiet = true;
|
|
9838
|
+
results++;
|
|
9839
|
+
if (tasks.size && open && !closed) {
|
|
9840
|
+
// Held: background work continues in this process, and input reaches it directly.
|
|
9841
|
+
held = true;
|
|
9842
|
+
if (waiting.length) for (const queued of waiting.splice(0)) into(queued);
|
|
9843
|
+
else accept = once;
|
|
9844
|
+
} else settle();
|
|
9794
9845
|
}
|
|
9795
9846
|
emit(value);
|
|
9796
9847
|
if (value.type === "result") emit({ type: "armada_turn_state", completed });
|
|
@@ -9812,8 +9863,13 @@ function start() {
|
|
|
9812
9863
|
clearTimeout(retire);
|
|
9813
9864
|
clearTimeout(kill);
|
|
9814
9865
|
child = undefined;
|
|
9866
|
+
accept = undefined;
|
|
9867
|
+
endInput = undefined;
|
|
9815
9868
|
finishing = false;
|
|
9816
9869
|
if ((!retired && code !== 0) || !result) failure();
|
|
9870
|
+
// Every line this process took is settled once it ends.
|
|
9871
|
+
completed += lines;
|
|
9872
|
+
emit({ type: "armada_turn_state", completed });
|
|
9817
9873
|
if (failed) { process.exitCode = 1; input.close(); return; }
|
|
9818
9874
|
for (const line of waiting.splice(0)) send(line);
|
|
9819
9875
|
if (closed && !child) process.exit(0);
|
|
@@ -9829,7 +9885,7 @@ input.on("line", (line) => {
|
|
|
9829
9885
|
});
|
|
9830
9886
|
input.on("close", () => {
|
|
9831
9887
|
closed = true;
|
|
9832
|
-
if (child)
|
|
9888
|
+
if (child) endInput?.();
|
|
9833
9889
|
else process.exit(failed ? 1 : 0);
|
|
9834
9890
|
});
|
|
9835
9891
|
`;
|
|
@@ -10772,7 +10828,7 @@ var init_src2 = __esm(() => {
|
|
|
10772
10828
|
});
|
|
10773
10829
|
|
|
10774
10830
|
// ../plugin-api/dist/guard.js
|
|
10775
|
-
import { AsyncLocalStorage as
|
|
10831
|
+
import { AsyncLocalStorage as AsyncLocalStorage3 } from "node:async_hooks";
|
|
10776
10832
|
async function guarded2(target, check, act) {
|
|
10777
10833
|
await check();
|
|
10778
10834
|
return guards2.run({ target, check }, async () => {
|
|
@@ -10794,7 +10850,7 @@ var init_guard = __esm(() => {
|
|
|
10794
10850
|
key = Symbol.for("@armada/plugin-api/guard/v1");
|
|
10795
10851
|
shared = globalThis;
|
|
10796
10852
|
if (!shared[key])
|
|
10797
|
-
shared[key] = new
|
|
10853
|
+
shared[key] = new AsyncLocalStorage3;
|
|
10798
10854
|
guards2 = shared[key];
|
|
10799
10855
|
});
|
|
10800
10856
|
|
|
@@ -46959,7 +47015,12 @@ import { basename as basename6, dirname as dirname16, join as join19, resolve as
|
|
|
46959
47015
|
// ../core/src/merge.ts
|
|
46960
47016
|
var import_picomatch3 = __toESM(require_picomatch2(), 1);
|
|
46961
47017
|
|
|
47018
|
+
// ../core/src/armada-api.ts
|
|
47019
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
47020
|
+
|
|
46962
47021
|
// ../core/src/http.ts
|
|
47022
|
+
var TRANSIENT_CODE = /^(?:ECONNRESET|ECONNREFUSED|EPIPE|ETIMEDOUT|EAI_AGAIN|ENETUNREACH|EHOSTUNREACH|UND_ERR_(?:CONNECT_TIMEOUT|HEADERS_TIMEOUT|BODY_TIMEOUT|SOCKET)|ConnectionClosed|ConnectionRefused)$/;
|
|
47023
|
+
|
|
46963
47024
|
class UnreadableAnswer extends Error {
|
|
46964
47025
|
status;
|
|
46965
47026
|
constructor(status) {
|
|
@@ -46981,10 +47042,13 @@ class HttpRequestError extends Error {
|
|
|
46981
47042
|
attempts;
|
|
46982
47043
|
transient;
|
|
46983
47044
|
name = "HttpRequestError";
|
|
47045
|
+
code;
|
|
46984
47046
|
constructor(error, timeoutMs, attempts, transient = false) {
|
|
46985
47047
|
super(`${networkReason(error, timeoutMs)}${attempts > 1 ? `; failed after ${attempts} attempts (${attempts === 2 ? "one retry" : `${attempts - 1} retries`})` : ""}`);
|
|
46986
47048
|
this.attempts = attempts;
|
|
46987
47049
|
this.transient = transient;
|
|
47050
|
+
const code = codeOf(error);
|
|
47051
|
+
this.code = code && TRANSIENT_CODE.test(code) ? code : error instanceof Error && error.name === "TimeoutError" ? "TimeoutError" : "network";
|
|
46988
47052
|
}
|
|
46989
47053
|
}
|
|
46990
47054
|
function networkReason(err, timeoutMs) {
|
|
@@ -47011,7 +47075,7 @@ function transient(error) {
|
|
|
47011
47075
|
return true;
|
|
47012
47076
|
const code = codeOf(error);
|
|
47013
47077
|
if (code)
|
|
47014
|
-
return
|
|
47078
|
+
return TRANSIENT_CODE.test(code);
|
|
47015
47079
|
return error instanceof TypeError && error.message === "fetch failed";
|
|
47016
47080
|
}
|
|
47017
47081
|
var retryStatus = (status) => [408, 429, 500, 502, 503, 504].includes(status);
|
|
@@ -47056,11 +47120,23 @@ async function wait(ms, opts, signal) {
|
|
|
47056
47120
|
async function httpRequest(url, init, opts, read) {
|
|
47057
47121
|
init.signal?.throwIfAborted();
|
|
47058
47122
|
const doFetch = opts.fetch ?? fetch;
|
|
47059
|
-
const attempts = opts.retry ? opts.retryStatus ? 3 : 2 : 1;
|
|
47123
|
+
const attempts = opts.retry ? opts.remainingMs ? Number.MAX_SAFE_INTEGER : opts.retryStatus ? 3 : 2 : 1;
|
|
47060
47124
|
let transportRetries = 0;
|
|
47061
47125
|
let waitedMs = 0;
|
|
47126
|
+
let lastError;
|
|
47062
47127
|
for (let attempt = 1;attempt <= attempts; attempt++) {
|
|
47063
|
-
|
|
47128
|
+
init.signal?.throwIfAborted();
|
|
47129
|
+
const remaining = () => opts.remainingMs?.() ?? Number.POSITIVE_INFINITY;
|
|
47130
|
+
const checkBudget = () => {
|
|
47131
|
+
if (remaining() <= 0)
|
|
47132
|
+
throw lastError ?? new HttpRequestError(new DOMException("deadline", "TimeoutError"), 0, attempt);
|
|
47133
|
+
};
|
|
47134
|
+
checkBudget();
|
|
47135
|
+
await opts.beforeAttempt?.();
|
|
47136
|
+
init.signal?.throwIfAborted();
|
|
47137
|
+
checkBudget();
|
|
47138
|
+
const requestLimit = opts.retry ? Math.min(opts.timeoutMs ?? 30000, attempt === 1 ? 5000 : 1e4) : opts.timeoutMs ?? 30000;
|
|
47139
|
+
const limit = Math.max(1, Math.floor(Math.min(requestLimit, remaining())));
|
|
47064
47140
|
const deadline = (opts.timeoutSignal ?? AbortSignal.timeout)(limit);
|
|
47065
47141
|
const controller = new AbortController;
|
|
47066
47142
|
const signal = init.signal ? AbortSignal.any([controller.signal, init.signal]) : controller.signal;
|
|
@@ -47090,15 +47166,16 @@ async function httpRequest(url, init, opts, read) {
|
|
|
47090
47166
|
}
|
|
47091
47167
|
if (opts.retry && opts.retryStatus?.(response.status)) {
|
|
47092
47168
|
const after = retryAfterMs(response.headers.get("Retry-After"), opts.now ?? (() => new Date));
|
|
47093
|
-
const
|
|
47094
|
-
if (response.status === 429 && after !== null && after >
|
|
47169
|
+
const waitBudget = Math.min(opts.remainingMs ? remaining() : 14000 - waitedMs, 1e4);
|
|
47170
|
+
if (response.status === 429 && after !== null && after > waitBudget)
|
|
47095
47171
|
throw new HttpStatusError(429, `${after / 1000} s`);
|
|
47096
47172
|
if (attempt < attempts) {
|
|
47173
|
+
lastError = new HttpStatusError(response.status, "the confirmed request budget expires");
|
|
47097
47174
|
const base = attempt === 1 ? 1000 : 3000;
|
|
47098
47175
|
const jitter = base * (0.8 + (opts.random ?? Math.random)() * 0.4);
|
|
47099
47176
|
pause = {
|
|
47100
47177
|
status: response.status,
|
|
47101
|
-
ms: Math.
|
|
47178
|
+
ms: Math.max(0, Math.min(waitBudget, Math.max(after ?? 0, Math.round(jitter))))
|
|
47102
47179
|
};
|
|
47103
47180
|
await response.body?.cancel().catch(() => {});
|
|
47104
47181
|
return;
|
|
@@ -47107,6 +47184,7 @@ async function httpRequest(url, init, opts, read) {
|
|
|
47107
47184
|
return read(response);
|
|
47108
47185
|
})()
|
|
47109
47186
|
]);
|
|
47187
|
+
checkBudget();
|
|
47110
47188
|
if (!pause)
|
|
47111
47189
|
return answer;
|
|
47112
47190
|
} catch (error) {
|
|
@@ -47118,11 +47196,18 @@ async function httpRequest(url, init, opts, read) {
|
|
|
47118
47196
|
const transport = fetchFailed || deadline.aborted || transient(cause) || unreadable;
|
|
47119
47197
|
if (!transport)
|
|
47120
47198
|
throw error;
|
|
47121
|
-
|
|
47199
|
+
const failure = new HttpRequestError(cause, limit, attempt, retryable);
|
|
47200
|
+
lastError = failure;
|
|
47201
|
+
if (attempt < attempts && (transportRetries < 1 || opts.remainingMs) && (!response || response.ok) && retryable) {
|
|
47122
47202
|
transportRetries++;
|
|
47123
|
-
|
|
47203
|
+
pause = {
|
|
47204
|
+
status: null,
|
|
47205
|
+
code: failure.code,
|
|
47206
|
+
ms: transportRetries === 1 ? 0 : Math.max(0, Math.min(1e4, remaining(), 3000))
|
|
47207
|
+
};
|
|
47208
|
+
} else {
|
|
47209
|
+
throw failure;
|
|
47124
47210
|
}
|
|
47125
|
-
throw new HttpRequestError(cause, limit, attempt, retryable);
|
|
47126
47211
|
} finally {
|
|
47127
47212
|
deadline.removeEventListener("abort", onDeadline);
|
|
47128
47213
|
controller.abort();
|
|
@@ -47130,7 +47215,8 @@ async function httpRequest(url, init, opts, read) {
|
|
|
47130
47215
|
response.body.cancel().catch(() => {});
|
|
47131
47216
|
}
|
|
47132
47217
|
if (pause) {
|
|
47133
|
-
|
|
47218
|
+
if (pause.status !== null || opts.remainingMs)
|
|
47219
|
+
opts.onRetry?.(`${opts.service ?? "Service"} ${pause.status === null ? `unreachable (${pause.code})` : `answered ${pause.status}`}; trying again in ${Math.round(pause.ms / 100) / 10} s (${opts.remainingMs ? "attempt " : ""}${attempt + 1}${opts.remainingMs ? "" : `/${attempts}`})`);
|
|
47134
47220
|
waitedMs += pause.ms;
|
|
47135
47221
|
await wait(pause.ms, opts, init.signal);
|
|
47136
47222
|
}
|
|
@@ -47172,14 +47258,20 @@ class ArmadaApiError extends Error {
|
|
|
47172
47258
|
signedOut;
|
|
47173
47259
|
status;
|
|
47174
47260
|
upgrade;
|
|
47175
|
-
|
|
47261
|
+
transient;
|
|
47262
|
+
constructor(message, next = null, signedOut = false, status = null, upgrade = null, transient = false) {
|
|
47176
47263
|
super(message);
|
|
47177
47264
|
this.next = next;
|
|
47178
47265
|
this.signedOut = signedOut;
|
|
47179
47266
|
this.status = status;
|
|
47180
47267
|
this.upgrade = upgrade;
|
|
47268
|
+
this.transient = transient;
|
|
47181
47269
|
}
|
|
47182
47270
|
}
|
|
47271
|
+
var fleetRequests = new AsyncLocalStorage;
|
|
47272
|
+
function withArmadaFleetRequest(request, act) {
|
|
47273
|
+
return fleetRequests.run(request, act);
|
|
47274
|
+
}
|
|
47183
47275
|
var LOGIN_NEXT = "armada login";
|
|
47184
47276
|
var TIMEOUT_MS = 30000;
|
|
47185
47277
|
function apiBaseUrl(value) {
|
|
@@ -47205,7 +47297,7 @@ function armadaApi(opts) {
|
|
|
47205
47297
|
const host = base.host;
|
|
47206
47298
|
let serverCli = null;
|
|
47207
47299
|
async function call(method, path, init = {}) {
|
|
47208
|
-
const limit = init.timeoutMs ?? timeoutMs;
|
|
47300
|
+
const limit = Math.min(init.timeoutMs ?? timeoutMs, init.request ? 15000 : Number.POSITIVE_INFINITY);
|
|
47209
47301
|
const headers = { Accept: "application/json" };
|
|
47210
47302
|
if (init.body)
|
|
47211
47303
|
headers["Content-Type"] = "application/json";
|
|
@@ -47218,9 +47310,11 @@ function armadaApi(opts) {
|
|
|
47218
47310
|
return httpRequest(new URL(`api/cli/${path}`, base).toString(), {
|
|
47219
47311
|
method,
|
|
47220
47312
|
headers,
|
|
47313
|
+
signal: init.request?.signal,
|
|
47221
47314
|
...init.body ? { body: JSON.stringify(init.body) } : {}
|
|
47222
47315
|
}, {
|
|
47223
47316
|
...opts,
|
|
47317
|
+
...init.request,
|
|
47224
47318
|
timeoutMs: limit,
|
|
47225
47319
|
retry: init.retry ?? method === "GET",
|
|
47226
47320
|
retryStatus: (status) => retryStatus(status) && (path !== "credentials" || status !== 429),
|
|
@@ -47251,7 +47345,7 @@ function armadaApi(opts) {
|
|
|
47251
47345
|
if (err instanceof HttpStatusError)
|
|
47252
47346
|
throw new ArmadaApiError(`Armada (${host}) ${err.message}`, "the same command after the rate limit expires", false, err.status);
|
|
47253
47347
|
if (err instanceof HttpRequestError)
|
|
47254
|
-
throw new ArmadaApiError(`Armada (${host}) unreachable: ${err.message} (${method} ${path})`, "the same command again once it answers, or check ARMADA_API_URL");
|
|
47348
|
+
throw new ArmadaApiError(`Armada (${host}) unreachable: ${init.request ? err.code : err.message} (${method} ${path})`, "the same command again once it answers, or check ARMADA_API_URL", false, null, null, err.transient);
|
|
47255
47349
|
throw err;
|
|
47256
47350
|
});
|
|
47257
47351
|
}
|
|
@@ -47345,11 +47439,14 @@ function armadaApi(opts) {
|
|
|
47345
47439
|
] : []);
|
|
47346
47440
|
},
|
|
47347
47441
|
async fleet(signIn, op, body, timeoutMs) {
|
|
47442
|
+
const context = fleetRequests.getStore();
|
|
47443
|
+
const request = context?.operation === op ? context : undefined;
|
|
47348
47444
|
const { status, body: answer } = await call("POST", `fleet/${op}`, {
|
|
47349
47445
|
signIn,
|
|
47350
47446
|
body,
|
|
47351
47447
|
...timeoutMs ? { timeoutMs } : {},
|
|
47352
|
-
|
|
47448
|
+
request,
|
|
47449
|
+
retry: request?.retry ?? [
|
|
47353
47450
|
"job/list",
|
|
47354
47451
|
"events/latest",
|
|
47355
47452
|
"events/state",
|
|
@@ -47370,8 +47467,11 @@ function armadaApi(opts) {
|
|
|
47370
47467
|
});
|
|
47371
47468
|
if (status === 304)
|
|
47372
47469
|
return null;
|
|
47373
|
-
if (status !== 200)
|
|
47470
|
+
if (status !== 200) {
|
|
47471
|
+
if (request)
|
|
47472
|
+
throw new ArmadaApiError(`Armada refused fleet/${op} (HTTP ${status})`, status === 401 ? LOGIN_NEXT : null, status === 401, status);
|
|
47374
47473
|
throw refusal(status, answer, status === 401 ? null : "Armada refused");
|
|
47474
|
+
}
|
|
47375
47475
|
if (!("result" in answer))
|
|
47376
47476
|
throw new ArmadaApiError(`Armada (${host}) answered fleet/${op} in a shape this CLI does not know`);
|
|
47377
47477
|
return answer.result;
|
|
@@ -57821,6 +57921,7 @@ async function readProjectConfig(p, opts) {
|
|
|
57821
57921
|
// ../core/src/queue-drain.ts
|
|
57822
57922
|
var TTL_MS = 10 * 60000;
|
|
57823
57923
|
var POLL_MS = 30000;
|
|
57924
|
+
var MARGIN_MS = 30000;
|
|
57824
57925
|
var BACKOFF_MS2 = [60000, 5 * 60000, 15 * 60000];
|
|
57825
57926
|
var PROGRESS_MAX = 300;
|
|
57826
57927
|
|
|
@@ -57829,20 +57930,76 @@ class TakenOver extends Refusal {
|
|
|
57829
57930
|
super("the queue was taken over", "armada merge --drain after its current holder finishes");
|
|
57830
57931
|
}
|
|
57831
57932
|
}
|
|
57832
|
-
var temporary = (err) => err instanceof ArmadaApiError ? !err.signedOut && !err.upgrade && (err.status ===
|
|
57933
|
+
var temporary = (err) => err instanceof ArmadaApiError ? !err.signedOut && !err.upgrade && (err.transient || err.status === 429 || err.status !== null && err.status >= 500) : err instanceof MergeStateError ? err.transient || !err.pull : err instanceof Error && ("transient" in err) && err.transient === true;
|
|
57833
57934
|
async function drainMergeQueue(ctx, fleet, opts) {
|
|
57935
|
+
const duration = opts.monotonic ?? (() => performance.now());
|
|
57936
|
+
const acquiredAt = duration();
|
|
57834
57937
|
const lease = { name: MERGE_QUEUE_LEASE, holder: ctx.holder, ttlMs: TTL_MS };
|
|
57835
57938
|
const got = await fleet.acquireLease(lease);
|
|
57836
57939
|
if (!got.acquired)
|
|
57837
57940
|
throw new Refusal(`drained by ${got.held?.holder ?? "another coordinator"} until ${got.held?.expiresAt ?? "unknown"}`, "armada merge --drain once that coordinator finishes");
|
|
57838
57941
|
let pulseError = null;
|
|
57942
|
+
let confirmedUntil = acquiredAt + TTL_MS;
|
|
57943
|
+
let renewing = null;
|
|
57944
|
+
const controller = new AbortController;
|
|
57945
|
+
const signal = opts.signal ? AbortSignal.any([controller.signal, opts.signal]) : controller.signal;
|
|
57839
57946
|
let pulse = Promise.resolve();
|
|
57840
57947
|
let stopPulse;
|
|
57948
|
+
const request = (operation, act, fence = false) => {
|
|
57949
|
+
const began = duration();
|
|
57950
|
+
const until = confirmedUntil;
|
|
57951
|
+
let notified = false;
|
|
57952
|
+
return withArmadaFleetRequest({
|
|
57953
|
+
operation,
|
|
57954
|
+
signal,
|
|
57955
|
+
retry: true,
|
|
57956
|
+
remainingMs: () => Math.min(until, confirmedUntil) - duration() - MARGIN_MS,
|
|
57957
|
+
beforeAttempt: fence ? tick : undefined,
|
|
57958
|
+
sleep: ctx.sleep,
|
|
57959
|
+
onRetry: (message) => {
|
|
57960
|
+
if (notified)
|
|
57961
|
+
return;
|
|
57962
|
+
notified = true;
|
|
57963
|
+
ctx.progress?.(`Armada unreachable, ${operation === "lease/renew" ? "renewing the lease" : operation} again: ${message}; elapsed ${Math.ceil((duration() - began) / 1000)} s; remaining ${Math.max(0, Math.floor((until - duration() - MARGIN_MS) / 1000))} s`);
|
|
57964
|
+
}
|
|
57965
|
+
}, async () => {
|
|
57966
|
+
const answer = await act();
|
|
57967
|
+
if (operation === "holds" && !Array.isArray(answer))
|
|
57968
|
+
throw new Refusal("Armada returned an invalid hold answer; nothing was merged", "armada merge --drain once Armada answers");
|
|
57969
|
+
return answer;
|
|
57970
|
+
}).catch((error) => {
|
|
57971
|
+
if (!(operation === "queue/progress" && error instanceof ArmadaApiError && error.status === 404))
|
|
57972
|
+
pulseError ??= error;
|
|
57973
|
+
throw error;
|
|
57974
|
+
});
|
|
57975
|
+
};
|
|
57841
57976
|
const tick = async () => {
|
|
57977
|
+
signal.throwIfAborted();
|
|
57978
|
+
if (pulseError)
|
|
57979
|
+
throw pulseError;
|
|
57980
|
+
if (duration() >= confirmedUntil - MARGIN_MS) {
|
|
57981
|
+
pulseError = new Refusal("the queue lease expired; nothing was merged", "armada merge --drain once Armada answers");
|
|
57982
|
+
throw pulseError;
|
|
57983
|
+
}
|
|
57984
|
+
if (!renewing) {
|
|
57985
|
+
const started = duration();
|
|
57986
|
+
renewing = request("lease/renew", () => fleet.renewLease(lease)).then((held) => {
|
|
57987
|
+
if (held === false)
|
|
57988
|
+
throw new TakenOver;
|
|
57989
|
+
if (held !== true)
|
|
57990
|
+
throw new Refusal("Armada returned an invalid lease renewal; nothing was merged", "armada merge --drain once Armada answers");
|
|
57991
|
+
confirmedUntil = started + TTL_MS;
|
|
57992
|
+
}).catch((error) => {
|
|
57993
|
+
pulseError = error;
|
|
57994
|
+
throw error;
|
|
57995
|
+
}).finally(() => {
|
|
57996
|
+
renewing = null;
|
|
57997
|
+
});
|
|
57998
|
+
}
|
|
57999
|
+
await renewing;
|
|
58000
|
+
signal.throwIfAborted();
|
|
57842
58001
|
if (pulseError)
|
|
57843
58002
|
throw pulseError;
|
|
57844
|
-
if (!await fleet.renewLease(lease))
|
|
57845
|
-
throw new TakenOver;
|
|
57846
58003
|
};
|
|
57847
58004
|
const sleep = async (ms) => {
|
|
57848
58005
|
for (let remaining = ms;remaining > 0; remaining -= POLL_MS) {
|
|
@@ -57859,8 +58016,9 @@ async function drainMergeQueue(ctx, fleet, opts) {
|
|
|
57859
58016
|
if (mutations && !mutations.includes(key))
|
|
57860
58017
|
return value.bind(target);
|
|
57861
58018
|
return async (...args) => {
|
|
58019
|
+
await recorded;
|
|
57862
58020
|
await tick();
|
|
57863
|
-
const result = await Reflect.apply(value, target, args);
|
|
58021
|
+
const result = key === "holds" ? await request("holds", () => Reflect.apply(value, target, args), true) : await Reflect.apply(value, target, args);
|
|
57864
58022
|
if (!mutations)
|
|
57865
58023
|
await tick();
|
|
57866
58024
|
return result;
|
|
@@ -57877,7 +58035,14 @@ async function drainMergeQueue(ctx, fleet, opts) {
|
|
|
57877
58035
|
if (!entry || !detail || detail === shown)
|
|
57878
58036
|
return;
|
|
57879
58037
|
shown = detail;
|
|
57880
|
-
recorded = recorded.then(
|
|
58038
|
+
recorded = recorded.then(async () => {
|
|
58039
|
+
const held = await request("queue/progress", () => fleet.queueProgress({ id: entry.id, holder: ctx.holder, detail }), true);
|
|
58040
|
+
if (held !== true)
|
|
58041
|
+
throw new TakenOver;
|
|
58042
|
+
}).then(() => {}, (error) => {
|
|
58043
|
+
if (!(error instanceof ArmadaApiError && error.status === 404))
|
|
58044
|
+
pulseError = error;
|
|
58045
|
+
});
|
|
57881
58046
|
};
|
|
57882
58047
|
const run = {
|
|
57883
58048
|
...ctx,
|
|
@@ -57914,12 +58079,13 @@ async function drainMergeQueue(ctx, fleet, opts) {
|
|
|
57914
58079
|
});
|
|
57915
58080
|
for (;; ) {
|
|
57916
58081
|
await tick();
|
|
57917
|
-
const next = await fleet.queueNext({ holder: ctx.holder });
|
|
58082
|
+
const next = await request("queue/next", () => fleet.queueNext({ holder: ctx.holder }), true);
|
|
57918
58083
|
if ("refused" in next)
|
|
57919
58084
|
throw new TakenOver;
|
|
58085
|
+
await tick();
|
|
57920
58086
|
const entry = next.entry;
|
|
57921
58087
|
if (!entry) {
|
|
57922
|
-
const pending = (await fleet.queueList()).find(queueOpen);
|
|
58088
|
+
const pending = (await request("queue/list", () => fleet.queueList(), true)).find(queueOpen);
|
|
57923
58089
|
if (!pending) {
|
|
57924
58090
|
ctx.progress?.("queue empty");
|
|
57925
58091
|
return;
|
|
@@ -57980,6 +58146,7 @@ async function drainMergeQueue(ctx, fleet, opts) {
|
|
|
57980
58146
|
} finally {
|
|
57981
58147
|
stopPulse?.();
|
|
57982
58148
|
current = null;
|
|
58149
|
+
controller.abort();
|
|
57983
58150
|
await Promise.all([pulse, recorded]);
|
|
57984
58151
|
await fleet.releaseLease(lease).catch(() => {});
|
|
57985
58152
|
}
|
|
@@ -58056,6 +58223,7 @@ You are a worker. You own exactly one ticket, named in your launch brief. You tu
|
|
|
58056
58223
|
- **A listing is not an answer.** The coordinator's watch reminds about unanswered questions, plans and hand-backs after doubling intervals. Only the coordinator can \`armada ack\` a dismissible notice with a reason; it cannot skip your question, plan or hand-back. A ticket comment saying \`note: acknowledged\` does not change your phase or answer you.
|
|
58057
58224
|
- **The ticket is the source of truth.** On a local V2 worker, run \`armada ticket\` (or \`armada ticket <your-id>\`) to read it through your capability; \`--json\` prints the protocol Ticket. Another ticket id is refused. Internal tickets include all recorded comments; Linear tickets include the folded comments, with older comments linked in Linear. Read it, its parent spec and the hand-back comments of its merged blockers in full before planning.
|
|
58058
58225
|
- **Report a milestone once.** A second report with nothing new is noise; the heartbeat proves you are alive. Use the report vocabulary below for the plan, real implementation progress, blockers, tests, shipping and the hand-back.
|
|
58226
|
+
- **A turn is the unit of work** on a local worker (launched by the Armada daemon, for example through the Claude runtime): never end a turn to wait for a background task or subagent, because a turn that ends can stop them and nothing resumes you until a message arrives. Run \`verify\`, CI watches (\`gh run watch\`, \`gh pr checks --watch\`) and reviews in the foreground with a timeout, or poll them within the same turn, and end the turn only with a report, a question or a hand-back.
|
|
58059
58227
|
- **Keep going on setup choices.** When setup needs a choice (an install fallback, a retry, a missing tool), take the safe option, say which in your next report, and go on. Never stop to ask about it.
|
|
58060
58228
|
- **Stop by impact, not effort.** There is no budget of attempts. Failing tests, many files and layout defects are reasons to keep going. Stop and ask only when the fix breaks a contract another ticket or caller relies on, moves a module's responsibility, or a design choice the ticket does not settle remains; name the interface and who it affects. Never widen the ticket to avoid asking. Decide reversible technical choices yourself and record each one, with its reason, on the ticket and in the pull request.
|
|
58061
58229
|
- **Work only in your own branch and worktree.** Never touch another agent's checkout, and stop only the processes you started.
|
|
@@ -58084,7 +58252,7 @@ Reporting any phase other than \`ready-to-merge\` clears your previous hand-back
|
|
|
58084
58252
|
## Steps
|
|
58085
58253
|
|
|
58086
58254
|
1. **Install, sign in and claim**, with the exact commands your brief starts with. Install the Armada version it names; if npm refuses it, use the brief's fallback command, else the newest published one, and say so in your first report. Run \`armada skill armada-worker\` to read this skill, then the brief's \`armada login --launch-token <token>\` once, before the claim: it signs this workspace in for your ticket only, and Armada then gives your commands their keys (do not ask for one). The token works once, within the hour. If it is refused, or a later command says you were cut off from Armada, stop and say so in your reply. A token shown as \`armada_launch_••••\` is masked and signs nobody in. Then run the brief's \`armada claim …\`. A claim refused because another worker holds the ticket: stop, the older claim wins. After the claim, Armada checks that you can read the repository, push your branch and sign commits; if it reports \`blocked\`, keep the claim, stop and quote the reason.
|
|
58087
|
-
2. **Start the heartbeat** with the brief's line, right after the claim. It pings Armada only, never Linear, so you do not need reports to stay alive. Pass the agent's PID (\`$PPID\` in its command shell), never the shell's \`$$\`; it stops when that process exits or your session ends. \`--background\` detaches it on Conductor and
|
|
58255
|
+
2. **Start the heartbeat** with the brief's line, right after the claim. It pings Armada only, never Linear, so you do not need reports to stay alive. Pass the agent's PID (\`$PPID\` in its command shell), never the shell's \`$$\`; it stops when that process exits or your session ends. \`--background\` detaches it on Conductor, herdr and local workers; on guided Claude Code (a coordinator's subagent), run it in the subagent's background Bash without \`--background\`. While you wait in \`awaiting-approval\`, \`blocked\` or \`awaiting-validation\`, no heartbeat or report is needed. On resume, report your working phase and run the heartbeat line again with the current \`$PPID\`. If the runtime cannot keep a background process, report at least every 15 minutes during active work and say so on the ticket.
|
|
58088
58256
|
3. **Branch.** Use the branch named after the ticket (the brief names it), from the latest default branch.
|
|
58089
58257
|
4. **Plan.** Write what changes, how it is tested, and the checks a person could observe when it is done. Declare the paths you will change with \`--paths "packages/core/src/file.ts,skills/**"\` (at most 50, relative, no \`..\`). Armada prints the overlaps with other workers in flight. **Declare them in your plan and proceed additively; ask the coordinator only when you must change a contract another in-flight ticket relies on.** Reserve any migration number or shared name now. Your brief's "Plan" line says whether the plan needs approval; follow it:
|
|
58090
58258
|
- Pre-approved: \`armada report implementing --message "progress: plan ready" --plan-file -\` (or \`--plan-file <path>\`), then go on.
|
|
@@ -62469,7 +62637,7 @@ ${attachments.join(`
|
|
|
62469
62637
|
};
|
|
62470
62638
|
}
|
|
62471
62639
|
// package.json
|
|
62472
|
-
var version2 = "0.2.
|
|
62640
|
+
var version2 = "0.2.73";
|
|
62473
62641
|
|
|
62474
62642
|
// src/io.ts
|
|
62475
62643
|
class UsageError extends Error {
|
|
@@ -63974,7 +64142,7 @@ async function outgoingRedactor(io, config, credentials) {
|
|
|
63974
64142
|
}
|
|
63975
64143
|
|
|
63976
64144
|
// src/runtimes/adapter.ts
|
|
63977
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
64145
|
+
import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
|
|
63978
64146
|
import { createHash as createHash6 } from "node:crypto";
|
|
63979
64147
|
|
|
63980
64148
|
// src/runtimes/claude-code.ts
|
|
@@ -69134,11 +69302,11 @@ function sharesRuntimeWorkspace(ref, other) {
|
|
|
69134
69302
|
return ref.handle === other.handle || ref.runtime === "conductor" && runtimeNameOf(other.runtime) === "conductor" && ref.handle.split("/")[0] === other.handle.split("/")[0];
|
|
69135
69303
|
}
|
|
69136
69304
|
var stale = (ticket) => new RuntimeError(`${ticket}'s claim changed; left the runtime untouched`, "stale", "armada inbox");
|
|
69137
|
-
var leases = new
|
|
69305
|
+
var leases = new AsyncLocalStorage2;
|
|
69138
69306
|
function withRuntimeLease(check, act) {
|
|
69139
69307
|
return leases.run(check, act);
|
|
69140
69308
|
}
|
|
69141
|
-
var guards = new
|
|
69309
|
+
var guards = new AsyncLocalStorage2;
|
|
69142
69310
|
function same(a, b) {
|
|
69143
69311
|
return a.ticket === b.ticket && a.runtime === b.runtime && a.handle === b.handle && a.claimedAt === b.claimedAt && a.launchId === b.launchId && a.releasedAt === b.releasedAt && (a.claimedAt === null || (a.branch ?? null) === (b.branch ?? null));
|
|
69144
69312
|
}
|