@the-vibe-company/armada 0.2.69 → 0.2.70
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 +1983 -460
- package/dist/plugin-fixtures/tracker/response.json +240 -2
- package/package.json +2 -1
package/dist/armada.js
CHANGED
|
@@ -6646,15 +6646,21 @@ var init_zod = __esm(() => {
|
|
|
6646
6646
|
});
|
|
6647
6647
|
|
|
6648
6648
|
// ../plugin-api/dist/runtime.js
|
|
6649
|
-
var RuntimeLaunchRefusal;
|
|
6649
|
+
var RuntimeLaunchRefusal, WorkerRuntimeGone, WorkerRuntimeAlive;
|
|
6650
6650
|
var init_runtime = __esm(() => {
|
|
6651
6651
|
RuntimeLaunchRefusal = class RuntimeLaunchRefusal extends Error {
|
|
6652
6652
|
name = "RuntimeLaunchRefusal";
|
|
6653
6653
|
};
|
|
6654
|
+
WorkerRuntimeGone = class WorkerRuntimeGone extends Error {
|
|
6655
|
+
name = "WorkerRuntimeGone";
|
|
6656
|
+
};
|
|
6657
|
+
WorkerRuntimeAlive = class WorkerRuntimeAlive extends Error {
|
|
6658
|
+
name = "WorkerRuntimeAlive";
|
|
6659
|
+
};
|
|
6654
6660
|
});
|
|
6655
6661
|
|
|
6656
6662
|
// ../plugin-api/dist/index.js
|
|
6657
|
-
var PLUGIN_API_VERSION = "0.
|
|
6663
|
+
var PLUGIN_API_VERSION = "0.3.0", SEAMS, name, contributionSchema, kinds, manifestSchema, pluginSettingSchema, pluginEventSchema, pluginEventInputSchema;
|
|
6658
6664
|
var init_dist = __esm(() => {
|
|
6659
6665
|
init_runtime();
|
|
6660
6666
|
init_zod();
|
|
@@ -9730,6 +9736,105 @@ var require_picomatch2 = __commonJS(function(exports, module) {
|
|
|
9730
9736
|
module.exports = picomatch;
|
|
9731
9737
|
});
|
|
9732
9738
|
|
|
9739
|
+
// ../plugins/claude/src/driver.ts
|
|
9740
|
+
var DRIVER;
|
|
9741
|
+
var init_driver = __esm(() => {
|
|
9742
|
+
DRIVER = String.raw`
|
|
9743
|
+
import { spawn } from "node:child_process";
|
|
9744
|
+
import { createInterface } from "node:readline";
|
|
9745
|
+
const options = JSON.parse(process.argv[1]);
|
|
9746
|
+
let child;
|
|
9747
|
+
let session;
|
|
9748
|
+
let finishing = false;
|
|
9749
|
+
let failed = false;
|
|
9750
|
+
let closed = false;
|
|
9751
|
+
let completed = 0;
|
|
9752
|
+
const waiting = [];
|
|
9753
|
+
const emit = (value) => console.log(JSON.stringify(value));
|
|
9754
|
+
const failure = () => {
|
|
9755
|
+
failed = true;
|
|
9756
|
+
emit({ type: "result", is_error: true, result: "Claude CLI turn could not be continued" });
|
|
9757
|
+
};
|
|
9758
|
+
function send(line) {
|
|
9759
|
+
if (failed) return;
|
|
9760
|
+
if (child || finishing) { waiting.push(line); return; }
|
|
9761
|
+
if (!child) start();
|
|
9762
|
+
if (!child || failed) return;
|
|
9763
|
+
child.stdin.write(line + "\n", (error) => { if (error) failure(); });
|
|
9764
|
+
}
|
|
9765
|
+
function start() {
|
|
9766
|
+
if (completed && !session) { failure(); return; }
|
|
9767
|
+
// A resumed print process starts fresh cumulative usage counters.
|
|
9768
|
+
if (completed) emit({ type: "armada_turn_start" });
|
|
9769
|
+
const cli = spawn(options.command, [...options.args, ...(session ? ["--resume", session] : [])], {
|
|
9770
|
+
stdio: ["pipe", "pipe", "pipe"], shell: false,
|
|
9771
|
+
});
|
|
9772
|
+
child = cli;
|
|
9773
|
+
let pending = "";
|
|
9774
|
+
let result = false;
|
|
9775
|
+
let retire;
|
|
9776
|
+
let kill;
|
|
9777
|
+
let retired = false;
|
|
9778
|
+
const event = (line) => {
|
|
9779
|
+
try {
|
|
9780
|
+
const value = JSON.parse(line);
|
|
9781
|
+
if (typeof value.session_id === "string" && value.session_id) session = value.session_id;
|
|
9782
|
+
if (value.type === "result") {
|
|
9783
|
+
result = true;
|
|
9784
|
+
completed++;
|
|
9785
|
+
finishing = true;
|
|
9786
|
+
cli.stdin.end();
|
|
9787
|
+
// Some print CLIs retain an idle process after their final result and EOF.
|
|
9788
|
+
// Retire only this completed subprocess; the supervisor's group pin stays alive.
|
|
9789
|
+
if (!retire) retire = setTimeout(() => {
|
|
9790
|
+
retired = true;
|
|
9791
|
+
cli.kill("SIGTERM");
|
|
9792
|
+
kill = setTimeout(() => cli.kill("SIGKILL"), 1000);
|
|
9793
|
+
}, 1000);
|
|
9794
|
+
}
|
|
9795
|
+
emit(value);
|
|
9796
|
+
if (value.type === "result") emit({ type: "armada_turn_state", completed });
|
|
9797
|
+
} catch { /* Non-JSON diagnostics cannot prove a completed turn. */ }
|
|
9798
|
+
};
|
|
9799
|
+
cli.stdout.setEncoding("utf8");
|
|
9800
|
+
cli.stdout.on("data", (chunk) => {
|
|
9801
|
+
const lines = (pending + chunk).split(/\r?\n/);
|
|
9802
|
+
pending = lines.pop() ?? "";
|
|
9803
|
+
if (pending.length > 1048576) { pending = ""; failure(); }
|
|
9804
|
+
for (const line of lines) event(line);
|
|
9805
|
+
});
|
|
9806
|
+
// Diagnostics stay available to the host's masked transcript/watchdog.
|
|
9807
|
+
cli.stderr.pipe(process.stderr);
|
|
9808
|
+
cli.stdin.on("error", () => { if (!result) failure(); });
|
|
9809
|
+
cli.once("error", failure);
|
|
9810
|
+
cli.once("close", (code) => {
|
|
9811
|
+
if (pending) event(pending);
|
|
9812
|
+
clearTimeout(retire);
|
|
9813
|
+
clearTimeout(kill);
|
|
9814
|
+
child = undefined;
|
|
9815
|
+
finishing = false;
|
|
9816
|
+
if ((!retired && code !== 0) || !result) failure();
|
|
9817
|
+
if (failed) { process.exitCode = 1; input.close(); return; }
|
|
9818
|
+
for (const line of waiting.splice(0)) send(line);
|
|
9819
|
+
if (closed && !child) process.exit(0);
|
|
9820
|
+
});
|
|
9821
|
+
}
|
|
9822
|
+
const input = createInterface({ input: process.stdin });
|
|
9823
|
+
input.on("line", (line) => {
|
|
9824
|
+
try {
|
|
9825
|
+
const value = JSON.parse(line);
|
|
9826
|
+
if (value.type !== "user" || value.message?.role !== "user") throw new Error();
|
|
9827
|
+
send(line);
|
|
9828
|
+
} catch { failure(); }
|
|
9829
|
+
});
|
|
9830
|
+
input.on("close", () => {
|
|
9831
|
+
closed = true;
|
|
9832
|
+
if (child) child.stdin.end();
|
|
9833
|
+
else process.exit(failed ? 1 : 0);
|
|
9834
|
+
});
|
|
9835
|
+
`;
|
|
9836
|
+
});
|
|
9837
|
+
|
|
9733
9838
|
// ../plugin-api/dist/cli-auth.js
|
|
9734
9839
|
import { execFile, spawn } from "node:child_process";
|
|
9735
9840
|
import { StringDecoder } from "node:string_decoder";
|
|
@@ -10076,7 +10181,13 @@ function claudeRuntime(options = {}, node) {
|
|
|
10076
10181
|
for (const line of lines) {
|
|
10077
10182
|
try {
|
|
10078
10183
|
const event = JSON.parse(line);
|
|
10079
|
-
if (event.type === "
|
|
10184
|
+
if (event.type === "armada_turn_state" && Number.isSafeInteger(event.completed) && event.completed >= 0) {
|
|
10185
|
+
value.turns = Math.max(0, (value.accepted ?? value.deliveries.size) - event.completed);
|
|
10186
|
+
value.activity = value.turns ? "working" : "idle";
|
|
10187
|
+
} else if (event.type === "armada_turn_start") {
|
|
10188
|
+
value.usageOffset = value.usage === "unknown" ? "unknown" : { ...value.usage };
|
|
10189
|
+
value.usageResetPending = true;
|
|
10190
|
+
} else if (event.type === "conversation_reset") {
|
|
10080
10191
|
const identity = `reset:${event.uuid ?? event.new_conversation_id}`;
|
|
10081
10192
|
if (!value.usageResults.has(identity)) {
|
|
10082
10193
|
value.usageResults.add(identity);
|
|
@@ -10192,19 +10303,28 @@ function claudeRuntime(options = {}, node) {
|
|
|
10192
10303
|
},
|
|
10193
10304
|
async launch(request) {
|
|
10194
10305
|
const stream = !request.command;
|
|
10306
|
+
const args = stream ? [
|
|
10307
|
+
...options.args ?? [],
|
|
10308
|
+
...![...options.args ?? [], ...request.args].some((arg) => arg === "--permission-mode" || arg.startsWith("--permission-mode=") || arg === "--dangerously-skip-permissions") ? ["--permission-mode", options.permissionMode ?? "bypassPermissions"] : [],
|
|
10309
|
+
"--add-dir",
|
|
10310
|
+
request.workspace.path,
|
|
10311
|
+
"--print",
|
|
10312
|
+
"--verbose",
|
|
10313
|
+
"--input-format",
|
|
10314
|
+
"stream-json",
|
|
10315
|
+
"--output-format",
|
|
10316
|
+
"stream-json",
|
|
10317
|
+
...request.args
|
|
10318
|
+
] : request.args;
|
|
10195
10319
|
const ref = await facilities().launch({
|
|
10196
10320
|
...request,
|
|
10197
|
-
command:
|
|
10321
|
+
command: stream ? "node" : request.command,
|
|
10198
10322
|
args: stream ? [
|
|
10199
|
-
|
|
10200
|
-
"--
|
|
10201
|
-
|
|
10202
|
-
"
|
|
10203
|
-
|
|
10204
|
-
"--output-format",
|
|
10205
|
-
"stream-json",
|
|
10206
|
-
...request.args
|
|
10207
|
-
] : request.args
|
|
10323
|
+
"--input-type=module",
|
|
10324
|
+
"--eval",
|
|
10325
|
+
DRIVER,
|
|
10326
|
+
JSON.stringify({ command: options.binary || options.command || "claude", args })
|
|
10327
|
+
] : args
|
|
10208
10328
|
});
|
|
10209
10329
|
workers.set(ref.handle, {
|
|
10210
10330
|
ref: { ...ref },
|
|
@@ -10278,13 +10398,14 @@ function activate(ctx) {
|
|
|
10278
10398
|
}
|
|
10279
10399
|
var same2 = (a, b) => a.project === b.project && a.ticket === b.ticket && a.session === b.session && a.generation === b.generation && a.handle === b.handle;
|
|
10280
10400
|
var init_src = __esm(() => {
|
|
10401
|
+
init_driver();
|
|
10281
10402
|
init_status();
|
|
10282
10403
|
});
|
|
10283
10404
|
|
|
10284
10405
|
// ../plugins/codex/src/driver.ts
|
|
10285
|
-
var
|
|
10286
|
-
var
|
|
10287
|
-
|
|
10406
|
+
var DRIVER2;
|
|
10407
|
+
var init_driver2 = __esm(() => {
|
|
10408
|
+
DRIVER2 = String.raw`
|
|
10288
10409
|
import { execFile, spawn } from "node:child_process";
|
|
10289
10410
|
import { createInterface } from "node:readline";
|
|
10290
10411
|
const options = JSON.parse(process.argv[1]);
|
|
@@ -10320,8 +10441,31 @@ input.on("line", (line) => {
|
|
|
10320
10441
|
input.on("close", () => { chain.finally(() => process.exit(failed ? 1 : 0)); });
|
|
10321
10442
|
async function turn(message) {
|
|
10322
10443
|
if (failed) throw new Error("CLI session is no longer usable");
|
|
10323
|
-
|
|
10324
|
-
const
|
|
10444
|
+
// Approval/sandbox switches are top-level flags; resume does not accept them after its subcommand.
|
|
10445
|
+
const globalArgs = [];
|
|
10446
|
+
const extraArgs = [];
|
|
10447
|
+
for (let i = 0; i < options.extraArgs.length; i++) {
|
|
10448
|
+
const arg = options.extraArgs[i];
|
|
10449
|
+
if (arg === "--approve-for-me") globalArgs.push(arg);
|
|
10450
|
+
else if (/^(?:-a|-s|--ask-for-approval|--sandbox)$/.test(arg)) {
|
|
10451
|
+
globalArgs.push(arg, options.extraArgs[++i]);
|
|
10452
|
+
} else if (/^(?:--ask-for-approval=|--sandbox=|-[as].+)/.test(arg)) globalArgs.push(arg);
|
|
10453
|
+
else extraArgs.push(arg);
|
|
10454
|
+
}
|
|
10455
|
+
const args = [...globalArgs, "exec", ...(session ? ["resume", session] : []), ...(options.model ? ["--model", options.model] : []), ...(options.effort ? ["-c", "model_reasoning_effort=" + JSON.stringify(options.effort)] : []), "-c", "check_for_update_on_startup=false", ...extraArgs, "--json", "-"];
|
|
10456
|
+
const child = spawn(options.command, args, { stdio: ["pipe", "pipe", "pipe"], shell: false });
|
|
10457
|
+
// Retain only a fixed marker; provider errors/stderr may contain credentials.
|
|
10458
|
+
let permissionDenied = false;
|
|
10459
|
+
let diagnosticTail = "";
|
|
10460
|
+
const permissionEvidence = (text) => {
|
|
10461
|
+
diagnosticTail = (diagnosticTail + text).slice(-4096);
|
|
10462
|
+
if (!permissionDenied && /requested permissions|(?:have|has)n['’]t granted|permission gate refused|permission (?:prompt|request)|Permission(?:Denied|Rejected|Required)(?:Error)?|approval (?:required|denied|request)/i.test(diagnosticTail)) {
|
|
10463
|
+
permissionDenied = true;
|
|
10464
|
+
emit("failure", { permission: true });
|
|
10465
|
+
}
|
|
10466
|
+
};
|
|
10467
|
+
child.stderr.setEncoding("utf8");
|
|
10468
|
+
child.stderr.on("data", permissionEvidence);
|
|
10325
10469
|
let pending = "";
|
|
10326
10470
|
let reply = "";
|
|
10327
10471
|
let completed = false;
|
|
@@ -10332,7 +10476,11 @@ async function turn(message) {
|
|
|
10332
10476
|
if (value.type === "thread.started" && typeof value.thread_id === "string") session = value.thread_id;
|
|
10333
10477
|
if (value.type === "item.completed" && value.item?.type === "agent_message") reply = typeof value.item.text === "string" ? value.item.text.slice(-8192) : "";
|
|
10334
10478
|
if (value.type === "turn.completed") completed = true;
|
|
10335
|
-
if (value.type === "turn.failed" || value.type === "error")
|
|
10479
|
+
if (value.type === "turn.failed" || value.type === "error") {
|
|
10480
|
+
turnFailed = true;
|
|
10481
|
+
if (typeof value.error?.message === "string") permissionEvidence(value.error.message);
|
|
10482
|
+
if (typeof value.message === "string") permissionEvidence(value.message);
|
|
10483
|
+
}
|
|
10336
10484
|
} catch { /* CLI progress diagnostics are not JSON events. */ }
|
|
10337
10485
|
};
|
|
10338
10486
|
child.stdout.setEncoding("utf8");
|
|
@@ -10351,7 +10499,7 @@ async function turn(message) {
|
|
|
10351
10499
|
if (pending) event(pending);
|
|
10352
10500
|
if (code !== 0 || turnFailed || !completed || !session) {
|
|
10353
10501
|
failed = true;
|
|
10354
|
-
emit("failure");
|
|
10502
|
+
emit("failure", permissionDenied ? { permission: true } : {});
|
|
10355
10503
|
} else emit("reply", { text: reply });
|
|
10356
10504
|
emit("done", { completed: ++completedTurns });
|
|
10357
10505
|
}
|
|
@@ -10501,13 +10649,24 @@ function codexRuntime(options = {}, node) {
|
|
|
10501
10649
|
} else
|
|
10502
10650
|
extraArgs.push(arg);
|
|
10503
10651
|
}
|
|
10652
|
+
const mode = options.permissionMode ?? "workspace-write";
|
|
10653
|
+
const has = (pattern) => extraArgs.some((arg) => pattern.test(arg));
|
|
10654
|
+
if (native && mode !== "default" && !has(/^--(?:full-auto|approve-for-me|dangerously-bypass-approvals-and-sandbox)(?:=|$)/)) {
|
|
10655
|
+
if (!has(/^(?:-a(?:$|=|never|on-request|untrusted|on-failure)|--ask-for-approval(?:=|$)|(?:--config=|-c)?approval_policy\s*=)/))
|
|
10656
|
+
extraArgs.push("-c", 'approval_policy="never"');
|
|
10657
|
+
if (!has(/^(?:-s(?:$|=|read-only|workspace-write|danger-full-access)|--sandbox(?:=|$)|(?:--config=|-c)?sandbox_mode\s*=)/)) {
|
|
10658
|
+
extraArgs.push("-c", `sandbox_mode=${JSON.stringify(mode)}`);
|
|
10659
|
+
if (mode === "workspace-write" && !has(/^(?:--config=|-c)?sandbox_workspace_write\.network_access\s*=/))
|
|
10660
|
+
extraArgs.push("-c", "sandbox_workspace_write.network_access=true");
|
|
10661
|
+
}
|
|
10662
|
+
}
|
|
10504
10663
|
const ref = await facilities().launch(native ? {
|
|
10505
10664
|
...request,
|
|
10506
10665
|
command: "node",
|
|
10507
10666
|
args: [
|
|
10508
10667
|
"--input-type=module",
|
|
10509
10668
|
"-e",
|
|
10510
|
-
|
|
10669
|
+
DRIVER2,
|
|
10511
10670
|
JSON.stringify({ command: options.binary ?? options.command ?? "codex", model, effort, extraArgs })
|
|
10512
10671
|
]
|
|
10513
10672
|
} : request);
|
|
@@ -10606,7 +10765,7 @@ function activate2(ctx) {
|
|
|
10606
10765
|
}
|
|
10607
10766
|
var same3 = (a, b) => a.project === b.project && a.ticket === b.ticket && a.session === b.session && a.generation === b.generation && a.handle === b.handle;
|
|
10608
10767
|
var init_src2 = __esm(() => {
|
|
10609
|
-
|
|
10768
|
+
init_driver2();
|
|
10610
10769
|
init_status2();
|
|
10611
10770
|
});
|
|
10612
10771
|
|
|
@@ -11403,22 +11562,35 @@ class GithubForge {
|
|
|
11403
11562
|
cursors.add(after);
|
|
11404
11563
|
}
|
|
11405
11564
|
context?.onDetails?.();
|
|
11406
|
-
|
|
11565
|
+
const held = await options.openPullRequests?.() ?? context?.openPullRequests;
|
|
11566
|
+
if (context)
|
|
11567
|
+
context.openPullRequests = held;
|
|
11568
|
+
const missing = [
|
|
11569
|
+
...new Set(held ? held.filter((pr) => pr.state === "open").map((pr) => pr.number) : previousOpen)
|
|
11570
|
+
].filter((number) => !pulls.has(number));
|
|
11571
|
+
for (const number of missing) {
|
|
11572
|
+
if (state.pausedUntil && Date.parse(state.pausedUntil) > Date.parse(at)) {
|
|
11573
|
+
if (context)
|
|
11574
|
+
context.reconciliationError = "GitHub reading failed";
|
|
11575
|
+
break;
|
|
11576
|
+
}
|
|
11407
11577
|
try {
|
|
11408
11578
|
const pr = await this.#isolated(number, signal, async (child) => {
|
|
11409
|
-
const
|
|
11410
|
-
|
|
11411
|
-
|
|
11412
|
-
return
|
|
11579
|
+
const response = await http.request(`${http.rest}/repos/${options.repository}/pulls/${number}`, child);
|
|
11580
|
+
const raw = await response.json();
|
|
11581
|
+
child.throwIfAborted();
|
|
11582
|
+
return terminalPull(raw, number, options.repository, tickets, token, held?.find((pr) => pr.number === number));
|
|
11413
11583
|
});
|
|
11414
|
-
|
|
11415
|
-
|
|
11416
|
-
|
|
11584
|
+
if (pr)
|
|
11585
|
+
pulls.set(number, pr);
|
|
11586
|
+
recovered(number);
|
|
11417
11587
|
} catch (error) {
|
|
11418
11588
|
signal.throwIfAborted();
|
|
11419
11589
|
failed(number, error);
|
|
11590
|
+
if (context)
|
|
11591
|
+
context.reconciliationError = error instanceof GithubReadError ? error.message : "GitHub reading failed";
|
|
11420
11592
|
}
|
|
11421
|
-
}
|
|
11593
|
+
}
|
|
11422
11594
|
await Promise.all([...pulls.values()].filter((pr) => pr.state === "open" && active.has(pr.ticket)).map(async (pr) => {
|
|
11423
11595
|
const prior = state.prs[pr.number] ?? emptyPr();
|
|
11424
11596
|
if (prior.abandoned || state.pausedUntil && Date.parse(state.pausedUntil) > Date.parse(at))
|
|
@@ -11440,6 +11612,43 @@ class GithubForge {
|
|
|
11440
11612
|
return [...pulls.values()].sort((a, b) => a.number - b.number);
|
|
11441
11613
|
}
|
|
11442
11614
|
}
|
|
11615
|
+
function terminalPull(raw, number, repository, tickets, token, held) {
|
|
11616
|
+
const fail = () => {
|
|
11617
|
+
throw new GithubReadError("GitHub returned an incomplete reading");
|
|
11618
|
+
};
|
|
11619
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
11620
|
+
return fail();
|
|
11621
|
+
const pr = raw;
|
|
11622
|
+
if (pr.number !== number || !["open", "closed"].includes(String(pr.state)))
|
|
11623
|
+
return fail();
|
|
11624
|
+
if (pr.state === "open")
|
|
11625
|
+
return;
|
|
11626
|
+
const head = pr.head;
|
|
11627
|
+
if (typeof pr.merged !== "boolean" || typeof pr.title !== "string" || typeof pr.html_url !== "string" || typeof pr.draft !== "boolean" || typeof head?.sha !== "string" || !head.sha || typeof head.ref !== "string")
|
|
11628
|
+
return fail();
|
|
11629
|
+
if (pr.merged && (typeof pr.merge_commit_sha !== "string" || !/^[0-9a-f]{40}$/i.test(pr.merge_commit_sha) || typeof pr.merged_at !== "string" || !exports_iso.datetime().safeParse(pr.merged_at).success))
|
|
11630
|
+
return fail();
|
|
11631
|
+
const clean = (value) => value.replaceAll(token, "[redacted]");
|
|
11632
|
+
const ticket = held?.ticket || [...head.ref.matchAll(/(?:^|[/_-])([a-z][a-z0-9]*-\d+)(?=[-_/]|$)/gi)].map((match) => (match[1] ?? "").toUpperCase()).find((id) => tickets.has(id)) || "";
|
|
11633
|
+
return {
|
|
11634
|
+
review: "none",
|
|
11635
|
+
checks: [],
|
|
11636
|
+
checksComplete: false,
|
|
11637
|
+
ci: held?.ci ?? "none",
|
|
11638
|
+
...held,
|
|
11639
|
+
number,
|
|
11640
|
+
repository,
|
|
11641
|
+
ticket: clean(ticket),
|
|
11642
|
+
title: clean(pr.title),
|
|
11643
|
+
url: clean(pr.html_url),
|
|
11644
|
+
head: clean(head.sha),
|
|
11645
|
+
headRef: clean(head.ref),
|
|
11646
|
+
draft: pr.draft,
|
|
11647
|
+
state: pr.merged ? "merged" : "closed",
|
|
11648
|
+
conflicting: false,
|
|
11649
|
+
...pr.merged ? { mergeCommit: clean(String(pr.merge_commit_sha).toLowerCase()), mergedAt: clean(String(pr.merged_at)) } : {}
|
|
11650
|
+
};
|
|
11651
|
+
}
|
|
11443
11652
|
function transitions(before, pr) {
|
|
11444
11653
|
const kinds = [];
|
|
11445
11654
|
if (pr.state === "open" && pr.conflicting && (!before?.conflicting || before.head !== pr.head))
|
|
@@ -11554,6 +11763,11 @@ class GithubReader {
|
|
|
11554
11763
|
previous.set(pr.number, pr);
|
|
11555
11764
|
}
|
|
11556
11765
|
} else if (event.kind.startsWith("pull-request.")) {
|
|
11766
|
+
if (event.kind !== "pull-request.commented") {
|
|
11767
|
+
const pr = event.payload;
|
|
11768
|
+
if (pr.repository === options.repository)
|
|
11769
|
+
previous.set(pr.number, pr);
|
|
11770
|
+
}
|
|
11557
11771
|
const key = fingerprint(event);
|
|
11558
11772
|
for (const [id, pending] of this.#pending) {
|
|
11559
11773
|
if (fingerprint(pending) !== key)
|
|
@@ -11574,7 +11788,13 @@ class GithubReader {
|
|
|
11574
11788
|
return { ok: true, changed: 0 };
|
|
11575
11789
|
draft = structuredClone(this.#state);
|
|
11576
11790
|
delete draft.pausedUntil;
|
|
11577
|
-
const context = {
|
|
11791
|
+
const context = {
|
|
11792
|
+
checkpoint: draft,
|
|
11793
|
+
at,
|
|
11794
|
+
events: [],
|
|
11795
|
+
onDetails: cancelDeadline,
|
|
11796
|
+
openPullRequests: [...previous.values()]
|
|
11797
|
+
};
|
|
11578
11798
|
this.#providerPending = true;
|
|
11579
11799
|
const reading = await Promise.race([
|
|
11580
11800
|
this.#forge.read([...previous.values()].filter((pr) => pr.state === "open").map((pr) => pr.number), controller.signal, context).finally(() => {
|
|
@@ -11585,11 +11805,16 @@ class GithubReader {
|
|
|
11585
11805
|
controller.signal.throwIfAborted();
|
|
11586
11806
|
let changed = 0;
|
|
11587
11807
|
for (const pr of reading) {
|
|
11588
|
-
const before = previous.get(pr.number);
|
|
11808
|
+
const before = context.openPullRequests?.find((held) => held.number === pr.number) ?? previous.get(pr.number);
|
|
11589
11809
|
if (pr.unresolvedThreads === undefined && before?.unresolvedThreads !== undefined)
|
|
11590
11810
|
pr.unresolvedThreads = before.unresolvedThreads;
|
|
11591
11811
|
if (JSON.stringify(before) === JSON.stringify(pr))
|
|
11592
11812
|
continue;
|
|
11813
|
+
if (pr.state !== "open") {
|
|
11814
|
+
await append(transitionEvent(pr.state === "merged" ? "pull-request.merged" : "pull-request.closed", pr, options.project, options.actor, at));
|
|
11815
|
+
changed++;
|
|
11816
|
+
continue;
|
|
11817
|
+
}
|
|
11593
11818
|
await append({
|
|
11594
11819
|
project: options.project,
|
|
11595
11820
|
actor: options.actor,
|
|
@@ -11637,7 +11862,7 @@ class GithubReader {
|
|
|
11637
11862
|
});
|
|
11638
11863
|
this.#state = draft;
|
|
11639
11864
|
}
|
|
11640
|
-
return { ok: true, changed };
|
|
11865
|
+
return context.reconciliationError ? { ok: false, error: context.reconciliationError } : { ok: true, changed };
|
|
11641
11866
|
} catch (error) {
|
|
11642
11867
|
if (draft && error instanceof GithubReadError && !controller.signal.aborted) {
|
|
11643
11868
|
const state = {
|
|
@@ -11690,8 +11915,9 @@ class GithubReader {
|
|
|
11690
11915
|
this.#controller?.abort();
|
|
11691
11916
|
}
|
|
11692
11917
|
}
|
|
11693
|
-
var WORKFLOW = `status conclusion commit { oid } workflowRun { databaseId runNumber runAttempt workflow { id } }`, FIELDS2, OPEN
|
|
11918
|
+
var WORKFLOW = `status conclusion commit { oid } workflowRun { databaseId runNumber runAttempt workflow { id } }`, FIELDS2, OPEN;
|
|
11694
11919
|
var init_github = __esm(() => {
|
|
11920
|
+
init_zod();
|
|
11695
11921
|
init_checkpoint();
|
|
11696
11922
|
init_http();
|
|
11697
11923
|
init_keychain();
|
|
@@ -11715,10 +11941,6 @@ query Pulls($owner: String!, $name: String!, $after: String) {
|
|
|
11715
11941
|
pageInfo { hasNextPage endCursor } nodes { ...P }
|
|
11716
11942
|
}
|
|
11717
11943
|
}
|
|
11718
|
-
}`;
|
|
11719
|
-
ONE = `${FIELDS2}
|
|
11720
|
-
query Pull($owner: String!, $name: String!, $number: Int!) {
|
|
11721
|
-
repository(owner: $owner, name: $name) { pullRequest(number: $number) { ...P } }
|
|
11722
11944
|
}`;
|
|
11723
11945
|
});
|
|
11724
11946
|
|
|
@@ -11949,9 +12171,20 @@ async function inspectGithub(options) {
|
|
|
11949
12171
|
const review = await readReviewThreads(options, threads);
|
|
11950
12172
|
const behindBy = await readBehindBy(options, base, head);
|
|
11951
12173
|
const required = await readRequiredChecks(options, raw.baseRef.name);
|
|
12174
|
+
const commit = object5(raw.commits.nodes.at(-1)?.commit);
|
|
12175
|
+
let headParents;
|
|
12176
|
+
if (commit.parents !== undefined) {
|
|
12177
|
+
const parents = object5(commit.parents);
|
|
12178
|
+
const nodes = array2(parents.nodes).map((node) => cleanSha(object5(node).oid));
|
|
12179
|
+
if (!Number.isSafeInteger(parents.totalCount) || parents.totalCount < nodes.length)
|
|
12180
|
+
throw new Error("invalid commit parents");
|
|
12181
|
+
if (parents.totalCount === nodes.length)
|
|
12182
|
+
headParents = nodes;
|
|
12183
|
+
}
|
|
11952
12184
|
const inspection = {
|
|
11953
12185
|
number: normalized.number,
|
|
11954
12186
|
head,
|
|
12187
|
+
...headParents ? { headParents } : {},
|
|
11955
12188
|
base,
|
|
11956
12189
|
baseRef: raw.baseRef.name,
|
|
11957
12190
|
state: normalized.state,
|
|
@@ -11979,6 +12212,7 @@ var SHA, REST_DEFAULT = "https://api.github.com", GRAPHQL_DEFAULT, INSPECT_QUERY
|
|
|
11979
12212
|
baseRef { name target { oid } }
|
|
11980
12213
|
mergeCommit { oid }
|
|
11981
12214
|
commits(last: 1) { nodes { commit { oid
|
|
12215
|
+
parents(first: 3) { totalCount nodes { oid } }
|
|
11982
12216
|
checkSuites(first: 50) { nodes { status conclusion commit { oid } workflowRun { databaseId runNumber runAttempt workflow { id } } } pageInfo { hasNextPage endCursor } }
|
|
11983
12217
|
statusCheckRollup { state contexts(first: 50) { pageInfo { hasNextPage endCursor } nodes {
|
|
11984
12218
|
__typename
|
|
@@ -12100,6 +12334,10 @@ function activate4(ctx) {
|
|
|
12100
12334
|
actor: "owner",
|
|
12101
12335
|
endpoint: config.endpoint,
|
|
12102
12336
|
token: (signal) => token(project, signal),
|
|
12337
|
+
openPullRequests: async () => {
|
|
12338
|
+
const tables = await ctx.events.fold(project);
|
|
12339
|
+
return (tables?.projects?.[project]?.pullRequests ?? []).filter((pr) => !("repository" in pr) || pr.repository === settings.repository);
|
|
12340
|
+
},
|
|
12103
12341
|
activeTickets: async () => {
|
|
12104
12342
|
const tables = await ctx.events.fold(project);
|
|
12105
12343
|
return new Set((tables?.projects?.[project]?.sessions ?? []).filter((session) => !["released", "merged"].includes(session.phase)).map((session) => session.ticket));
|
|
@@ -12147,6 +12385,31 @@ function activate4(ctx) {
|
|
|
12147
12385
|
throw new Error("GitHub inspection failed");
|
|
12148
12386
|
}
|
|
12149
12387
|
},
|
|
12388
|
+
async updateBranch({ project, number, expectedHead, signal, beforeWrite }) {
|
|
12389
|
+
try {
|
|
12390
|
+
const repository = config.projects?.[project]?.repository;
|
|
12391
|
+
if (!repository || !Number.isSafeInteger(number) || number <= 0 || !/^[a-f0-9]{40}$/i.test(expectedHead))
|
|
12392
|
+
throw new Error;
|
|
12393
|
+
const key = await token(project, signal);
|
|
12394
|
+
signal?.throwIfAborted();
|
|
12395
|
+
beforeWrite?.();
|
|
12396
|
+
const response = await fetch(`${restEndpoint(config.endpoint)}/repos/${repository}/pulls/${number}/update-branch`, {
|
|
12397
|
+
method: "PUT",
|
|
12398
|
+
redirect: "error",
|
|
12399
|
+
signal,
|
|
12400
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${key}` },
|
|
12401
|
+
body: JSON.stringify({ expected_head_sha: expectedHead })
|
|
12402
|
+
});
|
|
12403
|
+
signal?.throwIfAborted();
|
|
12404
|
+
if (response.status === 202)
|
|
12405
|
+
return { updated: true };
|
|
12406
|
+
if ([401, 403, 404, 409, 422].includes(response.status))
|
|
12407
|
+
return { updated: false };
|
|
12408
|
+
throw new Error;
|
|
12409
|
+
} catch {
|
|
12410
|
+
throw new Error("GitHub branch update failed");
|
|
12411
|
+
}
|
|
12412
|
+
},
|
|
12150
12413
|
async merge({ project, number, head, signal, beforeWrite }) {
|
|
12151
12414
|
try {
|
|
12152
12415
|
const repository = config.projects?.[project]?.repository;
|
|
@@ -12401,6 +12664,40 @@ var init_chat = __esm(() => {
|
|
|
12401
12664
|
var DELIVERIES_MINOR = 17;
|
|
12402
12665
|
var init_deliveries = () => {};
|
|
12403
12666
|
|
|
12667
|
+
// ../protocol/dist/import.js
|
|
12668
|
+
var IMPORT_MINOR = 27, trackerImportSchema, importPayloadSchemas, trackerImportRequestSchema, trackerImportResultSchema;
|
|
12669
|
+
var init_import = __esm(() => {
|
|
12670
|
+
init_zod();
|
|
12671
|
+
init_envelope();
|
|
12672
|
+
trackerImportSchema = object({
|
|
12673
|
+
id: identifier2,
|
|
12674
|
+
programRoot: identifier2,
|
|
12675
|
+
state: _enum(["running", "completed", "paused", "failed", "interrupted"]),
|
|
12676
|
+
imported: counter,
|
|
12677
|
+
skipped: counter,
|
|
12678
|
+
comments: counter,
|
|
12679
|
+
total: counter,
|
|
12680
|
+
pausedUntil: exports_iso.datetime().optional(),
|
|
12681
|
+
error: string2().optional()
|
|
12682
|
+
});
|
|
12683
|
+
importPayloadSchemas = {
|
|
12684
|
+
"tracker.import-started": trackerImportSchema,
|
|
12685
|
+
"tracker.import-progress": trackerImportSchema.extend({ source: identifier2.optional() }),
|
|
12686
|
+
"tracker.import-ended": trackerImportSchema
|
|
12687
|
+
};
|
|
12688
|
+
trackerImportRequestSchema = /* @__PURE__ */ requestSchema("tracker.import", {
|
|
12689
|
+
project: identifier2,
|
|
12690
|
+
programRoot: identifier2
|
|
12691
|
+
});
|
|
12692
|
+
trackerImportResultSchema = object({
|
|
12693
|
+
type: literal("tracker.import.result"),
|
|
12694
|
+
version: versionSchema,
|
|
12695
|
+
id: identifier2,
|
|
12696
|
+
project: identifier2,
|
|
12697
|
+
importId: identifier2
|
|
12698
|
+
});
|
|
12699
|
+
});
|
|
12700
|
+
|
|
12404
12701
|
// ../protocol/dist/readers.js
|
|
12405
12702
|
var READER_MINOR = 14, roomPresenceRequestSchema, readerUsageSchema;
|
|
12406
12703
|
var init_readers = __esm(() => {
|
|
@@ -12419,7 +12716,7 @@ var init_readers = __esm(() => {
|
|
|
12419
12716
|
});
|
|
12420
12717
|
|
|
12421
12718
|
// ../protocol/dist/models.js
|
|
12422
|
-
var modelKindSchema, modelConfigSchema, pluginCoordinatorModelSchema, piCoordinatorModelSchema, coordinatorModelSchema, modelKindEntrySchema, counter3, request4, modelProviderEntrySchema, modelsProvidersSchema, modelsLoginSchema, modelsLogoutSchema, modelsSelectSchema, modelsCatalogSchema, modelsRequestSchemas;
|
|
12719
|
+
var modelKindSchema, modelConfigSchema, pluginCoordinatorModelSchema, piCoordinatorModelSchema, coordinatorModelSchema, modelKindEntrySchema, MODEL_SCOPE_MINOR = 24, counter3, request4, modelProviderEntrySchema, modelsProvidersSchema, modelsLoginSchema, modelsLogoutSchema, modelsSelectSchema, modelsCatalogSchema, modelsRequestSchemas;
|
|
12423
12720
|
var init_models = __esm(() => {
|
|
12424
12721
|
init_zod();
|
|
12425
12722
|
modelKindSchema = string2().regex(/^[a-z][a-z0-9._-]*$/);
|
|
@@ -12461,7 +12758,8 @@ var init_models = __esm(() => {
|
|
|
12461
12758
|
modelsSelectSchema = object({
|
|
12462
12759
|
...request4,
|
|
12463
12760
|
type: literal("models.select"),
|
|
12464
|
-
...piCoordinatorModelSchema.shape
|
|
12761
|
+
...piCoordinatorModelSchema.shape,
|
|
12762
|
+
project: string2().min(1).optional()
|
|
12465
12763
|
});
|
|
12466
12764
|
modelsCatalogSchema = object({
|
|
12467
12765
|
...request4,
|
|
@@ -12540,7 +12838,7 @@ var init_rules = __esm(() => {
|
|
|
12540
12838
|
});
|
|
12541
12839
|
|
|
12542
12840
|
// ../protocol/dist/fleet.js
|
|
12543
|
-
var GITHUB_READER_MINOR = 18, text, integer2, phaseSchema, activePhaseSchema, shippingStageSchema, ciSchema, sessionRefSchema, workerLaunchCheckpointSchema, sessionStateSchema, flowStepSchema;
|
|
12841
|
+
var GITHUB_READER_MINOR = 18, INTERNAL_TRACKER_MINOR = 22, FOLLOW_UP_MINOR = 25, text, integer2, phaseSchema, activePhaseSchema, shippingStageSchema, internalTicketFieldsSchema, ticketCreatedSchema, ticketPatchSchema, ciSchema, sessionRefSchema, workerLaunchCheckpointSchema, followUpSchema, sessionStateSchema, flowStepSchema;
|
|
12544
12842
|
var init_fleet = __esm(() => {
|
|
12545
12843
|
init_zod();
|
|
12546
12844
|
text = string2();
|
|
@@ -12558,6 +12856,18 @@ var init_fleet = __esm(() => {
|
|
|
12558
12856
|
]);
|
|
12559
12857
|
activePhaseSchema = phaseSchema.exclude(["released", "merged"]);
|
|
12560
12858
|
shippingStageSchema = _enum(["review", "ci"]);
|
|
12859
|
+
internalTicketFieldsSchema = strictObject({
|
|
12860
|
+
title: string2().trim().min(1),
|
|
12861
|
+
description: text,
|
|
12862
|
+
labels: array(string2().min(1)),
|
|
12863
|
+
state: _enum(["backlog", "unstarted", "started", "completed", "canceled"]),
|
|
12864
|
+
parent: string2().min(1).nullable(),
|
|
12865
|
+
blockers: array(string2().min(1)),
|
|
12866
|
+
url: text.optional(),
|
|
12867
|
+
source: text.optional()
|
|
12868
|
+
});
|
|
12869
|
+
ticketCreatedSchema = internalTicketFieldsSchema.extend({ id: string2().min(1) });
|
|
12870
|
+
ticketPatchSchema = internalTicketFieldsSchema.partial();
|
|
12561
12871
|
ciSchema = _enum(["none", "pending", "success", "failure"]);
|
|
12562
12872
|
sessionRefSchema = object({
|
|
12563
12873
|
ticket: text,
|
|
@@ -12573,6 +12883,27 @@ var init_fleet = __esm(() => {
|
|
|
12573
12883
|
branch: text.optional(),
|
|
12574
12884
|
step: _enum(["preparing", "starting", "launched"])
|
|
12575
12885
|
});
|
|
12886
|
+
followUpSchema = object({
|
|
12887
|
+
cause: text,
|
|
12888
|
+
tool: text.optional(),
|
|
12889
|
+
candidate: text.optional(),
|
|
12890
|
+
args: record(string2(), json()).optional(),
|
|
12891
|
+
code: text,
|
|
12892
|
+
reason: text,
|
|
12893
|
+
facts: text,
|
|
12894
|
+
next: text,
|
|
12895
|
+
fix: text.optional(),
|
|
12896
|
+
toldOwnerAt: text.optional(),
|
|
12897
|
+
attempts: number2().int().positive(),
|
|
12898
|
+
lastAt: text,
|
|
12899
|
+
pr: integer2.optional(),
|
|
12900
|
+
session: text.optional(),
|
|
12901
|
+
generation: integer2.optional(),
|
|
12902
|
+
plugin: text.optional(),
|
|
12903
|
+
capability: text.optional(),
|
|
12904
|
+
readyToMerge: boolean2().optional(),
|
|
12905
|
+
head: text.optional()
|
|
12906
|
+
});
|
|
12576
12907
|
sessionStateSchema = _enum([
|
|
12577
12908
|
"blocked",
|
|
12578
12909
|
"waiting-for-owner",
|
|
@@ -12672,14 +13003,20 @@ function addProjectRequest() {
|
|
|
12672
13003
|
projectId: addProjectInputSchema.shape.id
|
|
12673
13004
|
});
|
|
12674
13005
|
}
|
|
12675
|
-
var PROJECTS_MINOR = 12, text2, identifier3, request6, projectSchema, addProjectInputSchema, inspectProjectRequestSchema, addProjectRequestSchema, removeProjectRequestSchema, projectInspectionSchema, projectsInspectionSchema, projectRequestSchemas;
|
|
13006
|
+
var PROJECTS_MINOR = 12, PROJECT_TRACKER_MINOR = 23, text2, identifier3, request6, projectSchema, addProjectInputSchema, inspectProjectRequestSchema, addProjectRequestSchema, removeProjectRequestSchema, projectInspectionSchema, projectsInspectionSchema, projectRequestSchemas;
|
|
12676
13007
|
var init_projects = __esm(() => {
|
|
12677
13008
|
init_zod();
|
|
12678
13009
|
init_envelope();
|
|
12679
13010
|
text2 = string2().trim().min(1).max(4096);
|
|
12680
13011
|
identifier3 = string2().trim().min(1).max(200);
|
|
12681
13012
|
request6 = { version: versionSchema, id: identifier3 };
|
|
12682
|
-
projectSchema = object({
|
|
13013
|
+
projectSchema = object({
|
|
13014
|
+
id: identifier3,
|
|
13015
|
+
name: text2,
|
|
13016
|
+
repository: text2,
|
|
13017
|
+
root: text2.optional(),
|
|
13018
|
+
tracker: identifier3.optional()
|
|
13019
|
+
});
|
|
12683
13020
|
addProjectInputSchema = /* @__PURE__ */ addProjectInput();
|
|
12684
13021
|
inspectProjectRequestSchema = /* @__PURE__ */ requestSchema("projects.inspect", { path: text2 });
|
|
12685
13022
|
addProjectRequestSchema = /* @__PURE__ */ addProjectRequest();
|
|
@@ -12804,13 +13141,69 @@ var init_session = __esm(() => {
|
|
|
12804
13141
|
});
|
|
12805
13142
|
});
|
|
12806
13143
|
|
|
13144
|
+
// ../protocol/dist/tickets.js
|
|
13145
|
+
function createRequest() {
|
|
13146
|
+
return object({
|
|
13147
|
+
...request8,
|
|
13148
|
+
...target2,
|
|
13149
|
+
type: literal("ticket.create"),
|
|
13150
|
+
title: fields.title,
|
|
13151
|
+
description: fields.description,
|
|
13152
|
+
labels: labels2.optional(),
|
|
13153
|
+
parent: fields.parent.optional(),
|
|
13154
|
+
blockers: fields.blockers.optional(),
|
|
13155
|
+
ready: boolean2().optional()
|
|
13156
|
+
});
|
|
13157
|
+
}
|
|
13158
|
+
function updateRequest() {
|
|
13159
|
+
return object({
|
|
13160
|
+
...request8,
|
|
13161
|
+
...target2,
|
|
13162
|
+
type: literal("ticket.update"),
|
|
13163
|
+
ticket: id6,
|
|
13164
|
+
title: fields.title.optional(),
|
|
13165
|
+
description: fields.description.optional(),
|
|
13166
|
+
labels: labels2.optional(),
|
|
13167
|
+
addLabels: labels2.optional(),
|
|
13168
|
+
removeLabels: labels2.optional(),
|
|
13169
|
+
state: _enum(["backlog", "unstarted", "started", "completed", "canceled"]).optional(),
|
|
13170
|
+
parent: fields.parent.optional(),
|
|
13171
|
+
blockers: fields.blockers.optional()
|
|
13172
|
+
});
|
|
13173
|
+
}
|
|
13174
|
+
var TICKETS_MINOR = 26, request8, id6, labels2, fields, target2, ticketCreateRequestSchema, ticketUpdateRequestSchema, ticketResultSchema, ticketRequestSchemas;
|
|
13175
|
+
var init_tickets = __esm(() => {
|
|
13176
|
+
init_zod();
|
|
13177
|
+
init_envelope();
|
|
13178
|
+
request8 = { version: versionSchema, id: identifier2 };
|
|
13179
|
+
id6 = string2().min(1).max(200).regex(/\S/);
|
|
13180
|
+
labels2 = array(id6).max(100);
|
|
13181
|
+
fields = {
|
|
13182
|
+
title: string2().min(1).max(4000).regex(/\S/),
|
|
13183
|
+
description: string2().max(1e5),
|
|
13184
|
+
labels: labels2,
|
|
13185
|
+
parent: id6.nullable(),
|
|
13186
|
+
blockers: array(id6).max(100)
|
|
13187
|
+
};
|
|
13188
|
+
target2 = { project: identifier2, requestId: identifier2.max(200) };
|
|
13189
|
+
ticketCreateRequestSchema = /* @__PURE__ */ createRequest();
|
|
13190
|
+
ticketUpdateRequestSchema = /* @__PURE__ */ updateRequest();
|
|
13191
|
+
ticketResultSchema = object({
|
|
13192
|
+
...request8,
|
|
13193
|
+
...target2,
|
|
13194
|
+
type: literal("ticket.result"),
|
|
13195
|
+
ticket: id6
|
|
13196
|
+
});
|
|
13197
|
+
ticketRequestSchemas = [ticketCreateRequestSchema, ticketUpdateRequestSchema];
|
|
13198
|
+
});
|
|
13199
|
+
|
|
12807
13200
|
// ../protocol/dist/usage.js
|
|
12808
13201
|
var init_usage = () => {};
|
|
12809
13202
|
|
|
12810
13203
|
// ../protocol/dist/index.js
|
|
12811
13204
|
function credentialsSetSchema() {
|
|
12812
13205
|
return object({
|
|
12813
|
-
...
|
|
13206
|
+
...request9,
|
|
12814
13207
|
type: literal("credentials.set"),
|
|
12815
13208
|
provider: modelProviderSchema,
|
|
12816
13209
|
target: _enum(["pi", "plugin"]).optional(),
|
|
@@ -12840,7 +13233,7 @@ function checkHistory(value, ctx) {
|
|
|
12840
13233
|
previous = event.seq;
|
|
12841
13234
|
}
|
|
12842
13235
|
}
|
|
12843
|
-
var REPLAY_MINOR = 21, WORKER_RECOVERY_MINOR = 15, PROTOCOL_VERSION, eventSchema,
|
|
13236
|
+
var REPLAY_MINOR = 21, WORKER_RECOVERY_MINOR = 15, PROTOCOL_VERSION, eventSchema, request9, listProjectsRequestSchema, subscribeRequestSchema, readSessionRequestSchema, historyRequestSchema, modelProviderSchema, credentialsStatusRequestSchema, credentialsSetRequestSchema, credentialsResultSchema, fleetShutdownRequestSchema, fleetShutdownResultSchema, clientMessageSchema, projectsResultSchema, snapshotSchema, subscribedSchema, history, sessionResultSchema, historyResultSchema, eventBatchSchema, errorSchema, serverMessageSchema, envelopeSchema, correlationSchema;
|
|
12844
13237
|
var init_dist2 = __esm(() => {
|
|
12845
13238
|
init_dist();
|
|
12846
13239
|
init_zod();
|
|
@@ -12850,6 +13243,7 @@ var init_dist2 = __esm(() => {
|
|
|
12850
13243
|
init_deliveries();
|
|
12851
13244
|
init_envelope();
|
|
12852
13245
|
init_fleet();
|
|
13246
|
+
init_import();
|
|
12853
13247
|
init_models();
|
|
12854
13248
|
init_plugins();
|
|
12855
13249
|
init_projects();
|
|
@@ -12857,10 +13251,12 @@ var init_dist2 = __esm(() => {
|
|
|
12857
13251
|
init_readers();
|
|
12858
13252
|
init_rules();
|
|
12859
13253
|
init_session();
|
|
13254
|
+
init_tickets();
|
|
12860
13255
|
init_account();
|
|
12861
13256
|
init_auth();
|
|
12862
13257
|
init_chat();
|
|
12863
13258
|
init_fleet();
|
|
13259
|
+
init_import();
|
|
12864
13260
|
init_models();
|
|
12865
13261
|
init_plugins();
|
|
12866
13262
|
init_projects();
|
|
@@ -12868,13 +13264,14 @@ var init_dist2 = __esm(() => {
|
|
|
12868
13264
|
init_readers();
|
|
12869
13265
|
init_rules();
|
|
12870
13266
|
init_session();
|
|
13267
|
+
init_tickets();
|
|
12871
13268
|
init_usage();
|
|
12872
13269
|
PROTOCOL_VERSION = {
|
|
12873
13270
|
major: 1,
|
|
12874
|
-
minor: Math.max(READER_MINOR, PROJECTS_MINOR, BRIEF_INSTRUCTIONS_MINOR, WORKER_RECOVERY_MINOR, GITHUB_READER_MINOR, DELIVERIES_MINOR, WATCHDOG_MINOR, USAGE_MINOR, REPLAY_MINOR)
|
|
13271
|
+
minor: Math.max(READER_MINOR, PROJECTS_MINOR, BRIEF_INSTRUCTIONS_MINOR, WORKER_RECOVERY_MINOR, GITHUB_READER_MINOR, DELIVERIES_MINOR, WATCHDOG_MINOR, USAGE_MINOR, REPLAY_MINOR, INTERNAL_TRACKER_MINOR, FOLLOW_UP_MINOR, PROJECT_TRACKER_MINOR, MODEL_SCOPE_MINOR, TICKETS_MINOR, IMPORT_MINOR)
|
|
12875
13272
|
};
|
|
12876
13273
|
eventSchema = pluginEventSchema;
|
|
12877
|
-
|
|
13274
|
+
request9 = { version: versionSchema, id: identifier2 };
|
|
12878
13275
|
listProjectsRequestSchema = /* @__PURE__ */ requestSchema("projects.list", {});
|
|
12879
13276
|
subscribeRequestSchema = /* @__PURE__ */ requestSchema("project.subscribe", {
|
|
12880
13277
|
project: identifier2,
|
|
@@ -12894,7 +13291,7 @@ var init_dist2 = __esm(() => {
|
|
|
12894
13291
|
credentialsStatusRequestSchema = /* @__PURE__ */ requestSchema("credentials.status", {});
|
|
12895
13292
|
credentialsSetRequestSchema = /* @__PURE__ */ credentialsSetSchema();
|
|
12896
13293
|
credentialsResultSchema = object({
|
|
12897
|
-
...
|
|
13294
|
+
...request9,
|
|
12898
13295
|
type: literal("credentials.result"),
|
|
12899
13296
|
provider: modelProviderSchema.nullable(),
|
|
12900
13297
|
config: modelConfigSchema.optional(),
|
|
@@ -12904,7 +13301,7 @@ var init_dist2 = __esm(() => {
|
|
|
12904
13301
|
});
|
|
12905
13302
|
fleetShutdownRequestSchema = /* @__PURE__ */ fleetShutdownRequest();
|
|
12906
13303
|
fleetShutdownResultSchema = object({
|
|
12907
|
-
...
|
|
13304
|
+
...request9,
|
|
12908
13305
|
type: literal("fleet.shutdown.result"),
|
|
12909
13306
|
project: identifier2,
|
|
12910
13307
|
ok: boolean2(),
|
|
@@ -12912,6 +13309,7 @@ var init_dist2 = __esm(() => {
|
|
|
12912
13309
|
failed: array(identifier2)
|
|
12913
13310
|
});
|
|
12914
13311
|
clientMessageSchema = /* @__PURE__ */ discriminatedUnion("type", [
|
|
13312
|
+
trackerImportRequestSchema,
|
|
12915
13313
|
fleetShutdownRequestSchema,
|
|
12916
13314
|
accountStatusRequestSchema,
|
|
12917
13315
|
accountLoginRequestSchema,
|
|
@@ -12933,16 +13331,17 @@ var init_dist2 = __esm(() => {
|
|
|
12933
13331
|
...projectRequestSchemas,
|
|
12934
13332
|
...authRequestSchemas,
|
|
12935
13333
|
...modelsRequestSchemas,
|
|
12936
|
-
...providerRequestSchemas
|
|
13334
|
+
...providerRequestSchemas,
|
|
13335
|
+
...ticketRequestSchemas
|
|
12937
13336
|
]);
|
|
12938
13337
|
projectsResultSchema = object({
|
|
12939
|
-
...
|
|
13338
|
+
...request9,
|
|
12940
13339
|
type: literal("projects.result"),
|
|
12941
13340
|
projects: array(projectSchema)
|
|
12942
13341
|
});
|
|
12943
13342
|
snapshotSchema = object({ seq: counter, state: json() });
|
|
12944
13343
|
subscribedSchema = object({
|
|
12945
|
-
...
|
|
13344
|
+
...request9,
|
|
12946
13345
|
type: literal("project.subscribed"),
|
|
12947
13346
|
subscriptionId: identifier2,
|
|
12948
13347
|
project: identifier2,
|
|
@@ -12950,9 +13349,9 @@ var init_dist2 = __esm(() => {
|
|
|
12950
13349
|
snapshot: snapshotSchema.optional()
|
|
12951
13350
|
});
|
|
12952
13351
|
history = { project: identifier2, seq: counter, events: array(eventSchema) };
|
|
12953
|
-
sessionResultSchema = object({ ...
|
|
13352
|
+
sessionResultSchema = object({ ...request9, ...history, type: literal("session.result"), sessionId: identifier2 }).superRefine(checkHistory);
|
|
12954
13353
|
historyResultSchema = object({
|
|
12955
|
-
...
|
|
13354
|
+
...request9,
|
|
12956
13355
|
type: literal("fleet.history.result"),
|
|
12957
13356
|
project: identifier2,
|
|
12958
13357
|
events: array(eventSchema),
|
|
@@ -12987,6 +13386,7 @@ var init_dist2 = __esm(() => {
|
|
|
12987
13386
|
message: identifier2
|
|
12988
13387
|
});
|
|
12989
13388
|
serverMessageSchema = discriminatedUnion("type", [
|
|
13389
|
+
trackerImportResultSchema,
|
|
12990
13390
|
fleetShutdownResultSchema,
|
|
12991
13391
|
accountResultSchema,
|
|
12992
13392
|
accountDeviceSchema,
|
|
@@ -13010,12 +13410,140 @@ var init_dist2 = __esm(() => {
|
|
|
13010
13410
|
projectsInspectionSchema,
|
|
13011
13411
|
...authResultSchemas,
|
|
13012
13412
|
modelsCatalogSchema,
|
|
13013
|
-
providersCatalogSchema
|
|
13413
|
+
providersCatalogSchema,
|
|
13414
|
+
ticketResultSchema
|
|
13014
13415
|
]);
|
|
13015
13416
|
envelopeSchema = object({ version: versionSchema });
|
|
13016
13417
|
correlationSchema = object({ id: identifier2 });
|
|
13017
13418
|
});
|
|
13018
13419
|
|
|
13420
|
+
// ../plugins/internal-tracker/src/index.ts
|
|
13421
|
+
var exports_src6 = {};
|
|
13422
|
+
__export(exports_src6, {
|
|
13423
|
+
activate: () => activate6
|
|
13424
|
+
});
|
|
13425
|
+
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
13426
|
+
function activate6(ctx) {
|
|
13427
|
+
const append = (project, build) => {
|
|
13428
|
+
if (!ctx.events.appendWith)
|
|
13429
|
+
throw new Error("Internal tracker requires atomic event append support");
|
|
13430
|
+
return ctx.events.appendWith(project, (tables) => build(tables));
|
|
13431
|
+
};
|
|
13432
|
+
const historyFor = async (project, ticket, signal) => {
|
|
13433
|
+
signal?.throwIfAborted();
|
|
13434
|
+
const history = await ctx.events.read(project, 0);
|
|
13435
|
+
signal?.throwIfAborted();
|
|
13436
|
+
if (!history.some((e) => e.kind === "ticket.created" && typeof e.payload === "object" && e.payload !== null && !Array.isArray(e.payload) && e.payload.id === ticket))
|
|
13437
|
+
throw new Error("Internal ticket not found");
|
|
13438
|
+
return history;
|
|
13439
|
+
};
|
|
13440
|
+
const provider = {
|
|
13441
|
+
async read({ signal }) {
|
|
13442
|
+
signal?.throwIfAborted();
|
|
13443
|
+
},
|
|
13444
|
+
async status() {
|
|
13445
|
+
return { installed: true, state: "connected" };
|
|
13446
|
+
},
|
|
13447
|
+
async create(request) {
|
|
13448
|
+
const { project, actor } = mutationSchema.parse(request);
|
|
13449
|
+
const fields = createSchema.parse(request);
|
|
13450
|
+
const prefix = project.toUpperCase().replace(/[^A-Z]/g, "").slice(0, 5);
|
|
13451
|
+
if (!prefix)
|
|
13452
|
+
throw new Error("Internal ticket project id must contain a letter");
|
|
13453
|
+
const events = await append(project, (tables) => {
|
|
13454
|
+
request.signal?.throwIfAborted();
|
|
13455
|
+
let highest = 0;
|
|
13456
|
+
for (const ticket of tables.projects[project]?.tickets ?? []) {
|
|
13457
|
+
if (!ticket.id.startsWith(`${prefix}-`))
|
|
13458
|
+
continue;
|
|
13459
|
+
const suffix = ticket.id.slice(prefix.length + 1);
|
|
13460
|
+
if (/^[0-9]+$/.test(suffix))
|
|
13461
|
+
highest = Math.max(highest, Number(suffix));
|
|
13462
|
+
}
|
|
13463
|
+
if (!Number.isSafeInteger(highest + 1))
|
|
13464
|
+
throw new Error("Internal ticket numbers exhausted");
|
|
13465
|
+
const payload = ticketCreatedSchema.parse({ ...fields, id: `${prefix}-${highest + 1}` });
|
|
13466
|
+
request.beforeWrite?.();
|
|
13467
|
+
return [{ project, actor, at: new Date().toISOString(), kind: "ticket.created", payload }];
|
|
13468
|
+
});
|
|
13469
|
+
return { id: ticketCreatedSchema.parse(events[0]?.payload).id };
|
|
13470
|
+
},
|
|
13471
|
+
async update(request) {
|
|
13472
|
+
const { project, actor } = mutationSchema.parse(request);
|
|
13473
|
+
const ticket = identity.parse(request.ticket);
|
|
13474
|
+
const patch = ticketPatchSchema.parse(request.patch);
|
|
13475
|
+
await historyFor(project, ticket, request.signal);
|
|
13476
|
+
await append(project, (tables) => {
|
|
13477
|
+
request.signal?.throwIfAborted();
|
|
13478
|
+
if (!tables.projects[project]?.tickets.some((t) => t.id === ticket))
|
|
13479
|
+
throw new Error("Internal ticket not found");
|
|
13480
|
+
request.beforeWrite?.();
|
|
13481
|
+
return [{ project, actor, at: new Date().toISOString(), kind: "ticket.edited", payload: { ticket, patch } }];
|
|
13482
|
+
});
|
|
13483
|
+
},
|
|
13484
|
+
async write(request) {
|
|
13485
|
+
const { project, actor } = mutationSchema.parse(request);
|
|
13486
|
+
const { ticket, phase, state, comment, commentId } = writeSchema.parse(request);
|
|
13487
|
+
const history = await historyFor(project, ticket, request.signal);
|
|
13488
|
+
if (phase !== undefined || state !== undefined)
|
|
13489
|
+
await append(project, (tables) => {
|
|
13490
|
+
request.signal?.throwIfAborted();
|
|
13491
|
+
const current = tables.projects[project]?.tickets.find((t) => t.id === ticket);
|
|
13492
|
+
if (!current)
|
|
13493
|
+
throw new Error("Internal ticket not found");
|
|
13494
|
+
const patch = {
|
|
13495
|
+
...phase !== undefined ? { labels: [...(current.labels ?? []).filter((label) => !phaseSchema.safeParse(label).success), phase] } : {},
|
|
13496
|
+
...state !== undefined ? { state } : {}
|
|
13497
|
+
};
|
|
13498
|
+
request.beforeWrite?.();
|
|
13499
|
+
return [{ project, actor, at: new Date().toISOString(), kind: "ticket.edited", payload: { ticket, patch } }];
|
|
13500
|
+
});
|
|
13501
|
+
if (comment !== undefined) {
|
|
13502
|
+
const id = commentId ?? randomUUID7();
|
|
13503
|
+
if (history.some((e) => e.kind === "ticket.commented" && typeof e.payload === "object" && e.payload !== null && !Array.isArray(e.payload) && e.payload.ticket === ticket && e.payload.id === id))
|
|
13504
|
+
return;
|
|
13505
|
+
await append(project, (tables) => {
|
|
13506
|
+
request.signal?.throwIfAborted();
|
|
13507
|
+
if (!tables.projects[project]?.tickets.some((t) => t.id === ticket))
|
|
13508
|
+
throw new Error("Internal ticket not found");
|
|
13509
|
+
request.beforeWrite?.();
|
|
13510
|
+
return [
|
|
13511
|
+
{
|
|
13512
|
+
project,
|
|
13513
|
+
actor,
|
|
13514
|
+
at: new Date().toISOString(),
|
|
13515
|
+
kind: "ticket.commented",
|
|
13516
|
+
payload: { ticket, id, body: comment, author: actor }
|
|
13517
|
+
}
|
|
13518
|
+
];
|
|
13519
|
+
});
|
|
13520
|
+
}
|
|
13521
|
+
request.signal?.throwIfAborted();
|
|
13522
|
+
}
|
|
13523
|
+
};
|
|
13524
|
+
ctx.register.tracker("internal", provider);
|
|
13525
|
+
}
|
|
13526
|
+
var identity, mutationSchema, createFields, createSchema, writeSchema;
|
|
13527
|
+
var init_src5 = __esm(() => {
|
|
13528
|
+
init_dist2();
|
|
13529
|
+
init_zod();
|
|
13530
|
+
identity = string2().trim().min(1);
|
|
13531
|
+
mutationSchema = object({ project: identity, actor: identity.default("coordinator") });
|
|
13532
|
+
createFields = ticketCreatedSchema.omit({ id: true }).extend({
|
|
13533
|
+
state: ticketCreatedSchema.shape.state.default("backlog"),
|
|
13534
|
+
parent: ticketCreatedSchema.shape.parent.default(null),
|
|
13535
|
+
blockers: ticketCreatedSchema.shape.blockers.default([])
|
|
13536
|
+
});
|
|
13537
|
+
createSchema = object(createFields.shape);
|
|
13538
|
+
writeSchema = object({
|
|
13539
|
+
ticket: identity,
|
|
13540
|
+
phase: phaseSchema.optional(),
|
|
13541
|
+
state: literal("completed").optional(),
|
|
13542
|
+
comment: string2().optional(),
|
|
13543
|
+
commentId: identity.optional()
|
|
13544
|
+
}).refine((r) => r.commentId === undefined || r.comment !== undefined, "commentId needs a comment");
|
|
13545
|
+
});
|
|
13546
|
+
|
|
13019
13547
|
// ../plugins/linear/src/checkpoint.ts
|
|
13020
13548
|
var status2, readingSchema, linearReaderCheckpointSchema;
|
|
13021
13549
|
var init_checkpoint2 = __esm(() => {
|
|
@@ -13176,6 +13704,178 @@ var init_budget = __esm(() => {
|
|
|
13176
13704
|
init_errors3();
|
|
13177
13705
|
});
|
|
13178
13706
|
|
|
13707
|
+
// ../plugins/linear/src/linear/mutations.ts
|
|
13708
|
+
function applicableLabel(labels, team) {
|
|
13709
|
+
return labels.find((label) => label.team?.id === team) ?? labels.find((label) => !label.team);
|
|
13710
|
+
}
|
|
13711
|
+
function linearMutations(options) {
|
|
13712
|
+
const { request } = options;
|
|
13713
|
+
let root;
|
|
13714
|
+
async function program(signal) {
|
|
13715
|
+
if (!root) {
|
|
13716
|
+
const data = await request(`query MutationRoot($id: String!) { issue(id: $id) { id team { ${stateFields} } } }`, { id: options.rootId }, signal);
|
|
13717
|
+
if (!data.issue?.id || !data.issue.team?.id)
|
|
13718
|
+
throw new LinearReadError("Linear program root unavailable");
|
|
13719
|
+
root = data.issue;
|
|
13720
|
+
}
|
|
13721
|
+
return root;
|
|
13722
|
+
}
|
|
13723
|
+
async function pages(query, variables, select, signal) {
|
|
13724
|
+
const nodes = [];
|
|
13725
|
+
const cursors = new Set;
|
|
13726
|
+
let after = null;
|
|
13727
|
+
for (let i = 0;i < 100; i++) {
|
|
13728
|
+
const connection = select(await request(query, { ...variables, after }, signal));
|
|
13729
|
+
if (!connection || !Array.isArray(connection.nodes) || typeof connection.pageInfo?.hasNextPage !== "boolean")
|
|
13730
|
+
throw new LinearReadError("Linear mutation lookup incomplete");
|
|
13731
|
+
nodes.push(...connection.nodes);
|
|
13732
|
+
if (!connection.pageInfo.hasNextPage)
|
|
13733
|
+
return nodes;
|
|
13734
|
+
after = connection.pageInfo.endCursor;
|
|
13735
|
+
if (!after || cursors.has(after))
|
|
13736
|
+
break;
|
|
13737
|
+
cursors.add(after);
|
|
13738
|
+
}
|
|
13739
|
+
throw new LinearReadError("Linear mutation lookup pagination did not advance");
|
|
13740
|
+
}
|
|
13741
|
+
async function labels(names, team, signal) {
|
|
13742
|
+
if (!names.length)
|
|
13743
|
+
return [];
|
|
13744
|
+
const candidates = await pages(`query TicketLabels($names: [String!]!, $after: String) {
|
|
13745
|
+
issueLabels(first: 100, after: $after, filter: { name: { in: $names } }) {
|
|
13746
|
+
nodes { ${labelFields} } pageInfo { hasNextPage endCursor }
|
|
13747
|
+
}
|
|
13748
|
+
}`, { names: [...new Set(names)] }, (data) => data.issueLabels, signal);
|
|
13749
|
+
return [...new Set(names)].map((name) => {
|
|
13750
|
+
const label = applicableLabel(candidates.filter((label) => label.name === name), team);
|
|
13751
|
+
if (!label)
|
|
13752
|
+
throw new LinearReadError(`Linear label not found: ${name}`);
|
|
13753
|
+
return label.id;
|
|
13754
|
+
});
|
|
13755
|
+
}
|
|
13756
|
+
function state(team, ...types) {
|
|
13757
|
+
if (team.states?.pageInfo?.hasNextPage !== false || !Array.isArray(team.states.nodes))
|
|
13758
|
+
throw new LinearReadError("Linear workflow states incomplete");
|
|
13759
|
+
const sorted = [...team.states.nodes].sort((a, b) => (a.position ?? Infinity) - (b.position ?? Infinity));
|
|
13760
|
+
for (const type of types) {
|
|
13761
|
+
const found = sorted.find((s) => s.type === type);
|
|
13762
|
+
if (found?.id)
|
|
13763
|
+
return found.id;
|
|
13764
|
+
}
|
|
13765
|
+
throw new LinearReadError(`Linear workflow state not found: ${types.join(" or ")}`);
|
|
13766
|
+
}
|
|
13767
|
+
async function blockers(ticket, desired, existing, mutation) {
|
|
13768
|
+
for (const relation of existing.filter((r) => r.type === "blocks" && !desired.includes(r.issue.identifier))) {
|
|
13769
|
+
const data = await request("mutation RemoveBlocker($id: String!) { issueRelationDelete(id: $id) { success } }", { id: relation.id }, mutation.signal, mutation.beforeWrite);
|
|
13770
|
+
if (!data.issueRelationDelete?.success)
|
|
13771
|
+
throw new LinearReadError("Linear refused to remove blocker relation");
|
|
13772
|
+
}
|
|
13773
|
+
for (const blocker of new Set(desired)) {
|
|
13774
|
+
if (existing.some((r) => r.type === "blocks" && r.issue.identifier === blocker))
|
|
13775
|
+
continue;
|
|
13776
|
+
const data = await request("mutation AddBlocker($input: IssueRelationCreateInput!) { issueRelationCreate(input: $input) { success } }", { input: { issueId: blocker, relatedIssueId: ticket, type: "blocks" } }, mutation.signal, mutation.beforeWrite);
|
|
13777
|
+
if (!data.issueRelationCreate?.success)
|
|
13778
|
+
throw new LinearReadError(`Linear refused blocker relation from ${blocker}`);
|
|
13779
|
+
}
|
|
13780
|
+
}
|
|
13781
|
+
const ticketBlockers = (ticket, signal) => pages(`query TicketBlockers($id: String!, $after: String) { issue(id: $id) { inverseRelations(first: 100, after: $after) {
|
|
13782
|
+
nodes { id type issue { identifier } } pageInfo { hasNextPage endCursor }
|
|
13783
|
+
} } }`, { id: ticket }, (data) => data.issue?.inverseRelations, signal);
|
|
13784
|
+
return {
|
|
13785
|
+
async create(mutation) {
|
|
13786
|
+
const { title, description, signal, beforeWrite } = mutation;
|
|
13787
|
+
const programRoot = await program(signal);
|
|
13788
|
+
const since = options.now().getTime() - HOUR2;
|
|
13789
|
+
const recent = await request(`query RecentTickets($team: ID!, $title: String!, $since: DateTimeOrDuration!) {
|
|
13790
|
+
issues(first: 50, filter: { team: { id: { eq: $team } }, title: { eq: $title }, createdAt: { gte: $since } }) {
|
|
13791
|
+
nodes { id identifier url title description createdAt parent { ${ancestors} } }
|
|
13792
|
+
}
|
|
13793
|
+
}`, { team: programRoot.team.id, title, since: new Date(since).toISOString() }, signal);
|
|
13794
|
+
if (!Array.isArray(recent.issues?.nodes))
|
|
13795
|
+
throw new LinearReadError("Linear recent ticket lookup incomplete");
|
|
13796
|
+
const duplicate = recent.issues.nodes.find((issue) => {
|
|
13797
|
+
if (issue.title !== title || (issue.description ?? "") !== description || Date.parse(issue.createdAt) < since || !Number.isFinite(Date.parse(issue.createdAt)))
|
|
13798
|
+
return false;
|
|
13799
|
+
let parent = issue.parent;
|
|
13800
|
+
for (let depth = 0;parent && depth < 11; depth++, parent = parent.parent)
|
|
13801
|
+
if (parent.id === programRoot.id)
|
|
13802
|
+
return true;
|
|
13803
|
+
return false;
|
|
13804
|
+
});
|
|
13805
|
+
if (duplicate) {
|
|
13806
|
+
if (mutation.blockers?.length) {
|
|
13807
|
+
const existing = await ticketBlockers(duplicate.id, signal);
|
|
13808
|
+
const desired = [
|
|
13809
|
+
...existing.filter((relation) => relation.type === "blocks").map((relation) => relation.issue.identifier),
|
|
13810
|
+
...mutation.blockers
|
|
13811
|
+
];
|
|
13812
|
+
await blockers(duplicate.id, desired, existing, mutation);
|
|
13813
|
+
}
|
|
13814
|
+
return { id: duplicate.identifier, url: duplicate.url };
|
|
13815
|
+
}
|
|
13816
|
+
const labelIds = await labels(mutation.labels, programRoot.team.id, signal);
|
|
13817
|
+
const data = await request("mutation CreateTicket($input: IssueCreateInput!) { issueCreate(input: $input) { success issue { id identifier url } } }", {
|
|
13818
|
+
input: {
|
|
13819
|
+
teamId: programRoot.team.id,
|
|
13820
|
+
title,
|
|
13821
|
+
description,
|
|
13822
|
+
parentId: mutation.parent ?? programRoot.id,
|
|
13823
|
+
labelIds,
|
|
13824
|
+
stateId: mutation.state ? state(programRoot.team, mutation.state) : state(programRoot.team, "backlog", "unstarted")
|
|
13825
|
+
}
|
|
13826
|
+
}, signal, beforeWrite);
|
|
13827
|
+
const issue = data.issueCreate?.issue;
|
|
13828
|
+
if (!data.issueCreate?.success || !issue?.id || !issue.identifier || !issue.url)
|
|
13829
|
+
throw new LinearReadError("Linear refused ticket creation");
|
|
13830
|
+
await blockers(issue.id, mutation.blockers ?? [], [], mutation);
|
|
13831
|
+
return { id: issue.identifier, url: issue.url };
|
|
13832
|
+
},
|
|
13833
|
+
async update(mutation) {
|
|
13834
|
+
const { patch, signal, beforeWrite } = mutation;
|
|
13835
|
+
const data = await request(`query EditTicket($id: String!) { issue(id: $id) {
|
|
13836
|
+
id team { ${stateFields} }
|
|
13837
|
+
labels(first: 250) { nodes { ${labelFields} } pageInfo { hasNextPage endCursor } }
|
|
13838
|
+
inverseRelations(first: 100) { nodes { id type issue { identifier } } pageInfo { hasNextPage endCursor } }
|
|
13839
|
+
} }`, { id: mutation.ticket }, signal);
|
|
13840
|
+
const issue = data.issue;
|
|
13841
|
+
if (!issue?.id || !issue.team?.id)
|
|
13842
|
+
throw new LinearReadError("Linear ticket unavailable");
|
|
13843
|
+
const input = {};
|
|
13844
|
+
if (patch.title !== undefined)
|
|
13845
|
+
input.title = patch.title;
|
|
13846
|
+
if (patch.description !== undefined)
|
|
13847
|
+
input.description = patch.description;
|
|
13848
|
+
if (patch.parent !== undefined)
|
|
13849
|
+
input.parentId = patch.parent;
|
|
13850
|
+
if (patch.state !== undefined)
|
|
13851
|
+
input.stateId = state(issue.team, patch.state);
|
|
13852
|
+
if (patch.labels !== undefined) {
|
|
13853
|
+
if (issue.labels?.pageInfo?.hasNextPage !== false || !Array.isArray(issue.labels.nodes))
|
|
13854
|
+
throw new LinearReadError("Linear ticket labels incomplete");
|
|
13855
|
+
const added = patch.labels.filter((name) => !issue.labels.nodes.some((label) => label.name === name));
|
|
13856
|
+
input.addedLabelIds = await labels(added, issue.team.id, signal);
|
|
13857
|
+
input.removedLabelIds = issue.labels.nodes.filter((label) => !patch.labels?.includes(label.name)).map((label) => label.id);
|
|
13858
|
+
}
|
|
13859
|
+
let existing = [];
|
|
13860
|
+
if (patch.blockers !== undefined) {
|
|
13861
|
+
existing = issue.inverseRelations?.pageInfo?.hasNextPage === false ? issue.inverseRelations.nodes : await ticketBlockers(issue.id, signal);
|
|
13862
|
+
}
|
|
13863
|
+
if (Object.keys(input).length) {
|
|
13864
|
+
const changed = await request("mutation UpdateTicket($id: String!, $input: IssueUpdateInput!) { issueUpdate(id: $id, input: $input) { success } }", { id: issue.id, input }, signal, beforeWrite);
|
|
13865
|
+
if (!changed.issueUpdate?.success)
|
|
13866
|
+
throw new LinearReadError("Linear refused ticket update");
|
|
13867
|
+
}
|
|
13868
|
+
if (patch.blockers !== undefined)
|
|
13869
|
+
await blockers(issue.id, patch.blockers, existing, mutation);
|
|
13870
|
+
}
|
|
13871
|
+
};
|
|
13872
|
+
}
|
|
13873
|
+
var HOUR2 = 3600000, stateFields = "id states(first: 100) { nodes { id type position } pageInfo { hasNextPage endCursor } }", labelFields = "id name parent { name } team { id }", ancestors;
|
|
13874
|
+
var init_mutations = __esm(() => {
|
|
13875
|
+
init_errors3();
|
|
13876
|
+
ancestors = Array.from({ length: 10 }).reduce((fields) => `id parent { ${fields} }`, "id");
|
|
13877
|
+
});
|
|
13878
|
+
|
|
13179
13879
|
// ../plugins/linear/src/linear/index.ts
|
|
13180
13880
|
import { createHash as createHash10 } from "node:crypto";
|
|
13181
13881
|
function linearTracker(options) {
|
|
@@ -13198,7 +13898,47 @@ function linearTracker(options) {
|
|
|
13198
13898
|
options.budgets.set(quota, budget);
|
|
13199
13899
|
}
|
|
13200
13900
|
}
|
|
13901
|
+
const request = async (query, variables, signal, beforeWrite) => {
|
|
13902
|
+
if (!key)
|
|
13903
|
+
await prepare();
|
|
13904
|
+
signal?.throwIfAborted();
|
|
13905
|
+
beforeWrite?.();
|
|
13906
|
+
budget.beforeRequest(options.project);
|
|
13907
|
+
let response;
|
|
13908
|
+
try {
|
|
13909
|
+
response = await options.fetch(options.endpoint ?? "https://api.linear.app/graphql", {
|
|
13910
|
+
method: "POST",
|
|
13911
|
+
redirect: "error",
|
|
13912
|
+
headers: { "Content-Type": "application/json", Authorization: key },
|
|
13913
|
+
body: JSON.stringify({ query, variables }),
|
|
13914
|
+
signal
|
|
13915
|
+
});
|
|
13916
|
+
} catch {
|
|
13917
|
+
budget.response(options.project);
|
|
13918
|
+
throw new LinearReadError("Linear network request failed");
|
|
13919
|
+
}
|
|
13920
|
+
signal?.throwIfAborted();
|
|
13921
|
+
budget.response(options.project, response.headers);
|
|
13922
|
+
if (response.status === 429 || response.headers.has("retry-after"))
|
|
13923
|
+
throw budget.pause(response.headers);
|
|
13924
|
+
let body;
|
|
13925
|
+
try {
|
|
13926
|
+
body = await response.json();
|
|
13927
|
+
} catch {
|
|
13928
|
+
if (!response.ok)
|
|
13929
|
+
throw new LinearReadError(`Linear answered ${response.status}`);
|
|
13930
|
+
throw new LinearReadError("Linear returned an invalid or incomplete response");
|
|
13931
|
+
}
|
|
13932
|
+
if (body.errors?.some((error) => error?.extensions?.code === "RATELIMITED"))
|
|
13933
|
+
throw budget.pause(response.headers);
|
|
13934
|
+
if (!response.ok)
|
|
13935
|
+
throw new LinearReadError(`Linear answered ${response.status}`);
|
|
13936
|
+
if (!body.data || body.errors?.length)
|
|
13937
|
+
throw new LinearReadError("Linear returned an invalid or incomplete response");
|
|
13938
|
+
return body.data;
|
|
13939
|
+
};
|
|
13201
13940
|
return {
|
|
13941
|
+
...linearMutations({ rootId: options.rootId, now: options.now, request }),
|
|
13202
13942
|
identity: JSON.stringify([
|
|
13203
13943
|
options.endpoint ?? "https://api.linear.app/graphql",
|
|
13204
13944
|
options.rootId,
|
|
@@ -13215,40 +13955,7 @@ function linearTracker(options) {
|
|
|
13215
13955
|
if (!key)
|
|
13216
13956
|
await prepare();
|
|
13217
13957
|
const startedAt = options.now().toISOString();
|
|
13218
|
-
|
|
13219
|
-
signal.throwIfAborted();
|
|
13220
|
-
budget.beforeRequest(options.project);
|
|
13221
|
-
let response;
|
|
13222
|
-
try {
|
|
13223
|
-
response = await options.fetch(options.endpoint ?? "https://api.linear.app/graphql", {
|
|
13224
|
-
method: "POST",
|
|
13225
|
-
headers: { "Content-Type": "application/json", Authorization: key },
|
|
13226
|
-
body: JSON.stringify({ query, variables }),
|
|
13227
|
-
signal
|
|
13228
|
-
});
|
|
13229
|
-
} catch {
|
|
13230
|
-
budget.response(options.project);
|
|
13231
|
-
throw new LinearReadError("Linear network request failed");
|
|
13232
|
-
}
|
|
13233
|
-
budget.response(options.project, response.headers);
|
|
13234
|
-
if (response.status === 429 || response.headers.has("retry-after"))
|
|
13235
|
-
throw budget.pause(response.headers);
|
|
13236
|
-
let body;
|
|
13237
|
-
try {
|
|
13238
|
-
body = await response.json();
|
|
13239
|
-
} catch {
|
|
13240
|
-
if (!response.ok)
|
|
13241
|
-
throw new LinearReadError(`Linear answered ${response.status}`);
|
|
13242
|
-
throw new LinearReadError("Linear returned an invalid or incomplete response");
|
|
13243
|
-
}
|
|
13244
|
-
if (body.errors?.some((error) => error?.extensions?.code === "RATELIMITED"))
|
|
13245
|
-
throw budget.pause(response.headers);
|
|
13246
|
-
if (!response.ok)
|
|
13247
|
-
throw new LinearReadError(`Linear answered ${response.status}`);
|
|
13248
|
-
if (!body.data || body.errors?.length)
|
|
13249
|
-
throw new LinearReadError("Linear returned an invalid or incomplete response");
|
|
13250
|
-
return body.data;
|
|
13251
|
-
}
|
|
13958
|
+
const gql = (query, variables) => request(query, variables, signal);
|
|
13252
13959
|
async function pages(query, field, variables) {
|
|
13253
13960
|
const result = [];
|
|
13254
13961
|
const cursors = new Set;
|
|
@@ -13454,7 +14161,7 @@ function linearTracker(options) {
|
|
|
13454
14161
|
}
|
|
13455
14162
|
};
|
|
13456
14163
|
}
|
|
13457
|
-
var
|
|
14164
|
+
var fields2 = `fragment F on Issue {
|
|
13458
14165
|
id identifier updatedAt title description branchName url state { type }
|
|
13459
14166
|
inverseRelations(first: 5) { pageInfo { hasNextPage endCursor } nodes { type issue { identifier state { type } } } } assignee { name } parent { identifier }
|
|
13460
14167
|
labels(first: 10) { pageInfo { hasNextPage endCursor } nodes { name parent { name } } }
|
|
@@ -13463,15 +14170,16 @@ var fields = `fragment F on Issue {
|
|
|
13463
14170
|
var init_linear = __esm(() => {
|
|
13464
14171
|
init_budget();
|
|
13465
14172
|
init_errors3();
|
|
14173
|
+
init_mutations();
|
|
13466
14174
|
init_errors3();
|
|
13467
14175
|
init_dist2();
|
|
13468
|
-
rootQuery = `${
|
|
13469
|
-
childrenQuery = `${
|
|
14176
|
+
rootQuery = `${fields2} query Root($id: String!) { issue(id: $id) { ...F } }`;
|
|
14177
|
+
childrenQuery = `${fields2} query Children($parents: [ID!], $after: String) {
|
|
13470
14178
|
issues(first: 50, after: $after, filter: { parent: { id: { in: $parents } } }) {
|
|
13471
14179
|
pageInfo { hasNextPage endCursor } nodes { ...F }
|
|
13472
14180
|
}
|
|
13473
14181
|
}`;
|
|
13474
|
-
changedQuery = `${
|
|
14182
|
+
changedQuery = `${fields2} query Changed($filter: IssueFilter, $commentFilter: CommentFilter,
|
|
13475
14183
|
$after: String, $commentsAfter: String, $readIssues: Boolean!, $readComments: Boolean!) {
|
|
13476
14184
|
issues(first: 25, after: $after, filter: $filter) @include(if: $readIssues) {
|
|
13477
14185
|
pageInfo { hasNextPage endCursor } nodes { ...F }
|
|
@@ -13499,13 +14207,20 @@ function status3(body) {
|
|
|
13499
14207
|
const summary = match[2]?.trim() ?? "";
|
|
13500
14208
|
if (!parsed.success)
|
|
13501
14209
|
return null;
|
|
13502
|
-
|
|
14210
|
+
const approval = parsed.data === "awaiting-approval" && /^approved[.!]?$/i.test(summary);
|
|
14211
|
+
return {
|
|
14212
|
+
phase: parsed.data,
|
|
14213
|
+
summary,
|
|
14214
|
+
approval,
|
|
14215
|
+
coordinator: /^(answer|note)\s*:/i.test(summary) || approval || /^acceptance: \d+ more runs allowed by the coordinator:/i.test(summary)
|
|
14216
|
+
};
|
|
13503
14217
|
}
|
|
13504
14218
|
function trackerChanges(project, history, reading) {
|
|
13505
14219
|
const tickets = new Map;
|
|
13506
14220
|
const reports = new Map;
|
|
13507
14221
|
const answered = new Set;
|
|
13508
|
-
const
|
|
14222
|
+
const items = new Map;
|
|
14223
|
+
const merges = new Map;
|
|
13509
14224
|
for (const event of history) {
|
|
13510
14225
|
if (event.project !== project)
|
|
13511
14226
|
continue;
|
|
@@ -13514,9 +14229,14 @@ function trackerChanges(project, history, reading) {
|
|
|
13514
14229
|
if (event.kind === "ticket.report-posted")
|
|
13515
14230
|
reports.set(event.payload.comment, event.payload);
|
|
13516
14231
|
if (event.kind === "inbox.opened" && event.payload.id.startsWith("linear:"))
|
|
13517
|
-
|
|
14232
|
+
items.set(event.payload.id, event.payload);
|
|
14233
|
+
if (event.kind === "merge.confirmed") {
|
|
14234
|
+
const confirmed = merges.get(event.payload.ticket) ?? [];
|
|
14235
|
+
confirmed.push(event.payload);
|
|
14236
|
+
merges.set(event.payload.ticket, confirmed);
|
|
14237
|
+
}
|
|
13518
14238
|
if (event.kind === "inbox.answered") {
|
|
13519
|
-
|
|
14239
|
+
items.delete(event.payload.id);
|
|
13520
14240
|
answered.add(event.payload.id);
|
|
13521
14241
|
}
|
|
13522
14242
|
}
|
|
@@ -13565,35 +14285,66 @@ function trackerChanges(project, history, reading) {
|
|
|
13565
14285
|
if (!equal(reports.get(comment.id), payload))
|
|
13566
14286
|
emit("ticket.report-posted", payload, comment.updatedAt, comment.author);
|
|
13567
14287
|
}
|
|
13568
|
-
|
|
14288
|
+
const pending = new Map;
|
|
13569
14289
|
for (const comment of comments) {
|
|
13570
14290
|
const s = status3(comment.body);
|
|
14291
|
+
if (/^approved\b/i.test(comment.body.trimStart()) || s?.approval)
|
|
14292
|
+
pending.delete("plan");
|
|
13571
14293
|
if (!s)
|
|
13572
14294
|
continue;
|
|
13573
|
-
if (
|
|
13574
|
-
|
|
13575
|
-
|
|
13576
|
-
|
|
14295
|
+
if (s.coordinator) {
|
|
14296
|
+
if (/^answer\s*:/i.test(s.summary)) {
|
|
14297
|
+
pending.delete("question");
|
|
14298
|
+
pending.delete("plan");
|
|
14299
|
+
}
|
|
14300
|
+
continue;
|
|
14301
|
+
}
|
|
14302
|
+
if (s.phase !== "blocked")
|
|
14303
|
+
pending.delete("question");
|
|
14304
|
+
else if (/^question\s*:/i.test(s.summary))
|
|
14305
|
+
pending.set("question", comment);
|
|
14306
|
+
if (s.phase !== "awaiting-approval")
|
|
14307
|
+
pending.delete("plan");
|
|
14308
|
+
else if (/^plan\b/i.test(s.summary) || /^## Plan[ \t]*$/m.test(comment.body))
|
|
14309
|
+
pending.set("plan", comment);
|
|
14310
|
+
if (s.phase === "ready-to-merge")
|
|
14311
|
+
pending.set("hand-back", comment);
|
|
14312
|
+
else
|
|
14313
|
+
pending.delete("hand-back");
|
|
13577
14314
|
}
|
|
13578
14315
|
if (phase !== "blocked")
|
|
13579
|
-
pending
|
|
13580
|
-
|
|
13581
|
-
|
|
13582
|
-
|
|
14316
|
+
pending.delete("question");
|
|
14317
|
+
if (phase !== "awaiting-approval")
|
|
14318
|
+
pending.delete("plan");
|
|
14319
|
+
if (phase !== "ready-to-merge")
|
|
14320
|
+
pending.delete("hand-back");
|
|
14321
|
+
const handBack = pending.get("hand-back");
|
|
14322
|
+
const handedHead = handBack?.body.match(/\bhead ([0-9a-f]{40})\b/i)?.[1]?.toLowerCase();
|
|
14323
|
+
const handedPr = handBack?.body.match(/\bPR #(\d+)/i)?.[1];
|
|
14324
|
+
if (handedHead && merges.get(source.id)?.some((merged) => merged.head === handedHead && (handedPr === undefined || Number(handedPr) === merged.pr)))
|
|
14325
|
+
pending.delete("hand-back");
|
|
14326
|
+
const identity = (comment) => `linear:${comment.id}:${comment.updatedAt}`;
|
|
14327
|
+
const wanted = new Set([...pending.values()].map(identity));
|
|
14328
|
+
for (const [id, item] of items) {
|
|
14329
|
+
if (item.ticket === source.id && !wanted.has(id))
|
|
13583
14330
|
emit("inbox.answered", { id, answer: "Superseded by a later Linear record" }, reading.startedAt);
|
|
13584
14331
|
}
|
|
13585
|
-
|
|
14332
|
+
for (const [kind, comment] of pending) {
|
|
14333
|
+
const id = identity(comment);
|
|
14334
|
+
if (items.has(id) || answered.has(id))
|
|
14335
|
+
continue;
|
|
13586
14336
|
emit("inbox.opened", {
|
|
13587
|
-
id
|
|
14337
|
+
id,
|
|
13588
14338
|
ticket: source.id,
|
|
13589
|
-
kind
|
|
13590
|
-
body: [
|
|
13591
|
-
(status3(
|
|
13592
|
-
...
|
|
14339
|
+
kind,
|
|
14340
|
+
body: kind === "question" ? [
|
|
14341
|
+
(status3(comment.body)?.summary ?? "").replace(/^question\s*:\s*/i, ""),
|
|
14342
|
+
...comment.body.trimStart().split(`
|
|
13593
14343
|
`).slice(1)
|
|
13594
14344
|
].join(`
|
|
13595
|
-
`).trim()
|
|
13596
|
-
},
|
|
14345
|
+
`).trim() : comment.body
|
|
14346
|
+
}, comment.updatedAt, comment.author);
|
|
14347
|
+
}
|
|
13597
14348
|
if (!equal(before, ticket))
|
|
13598
14349
|
emit("ticket.seen", ticket, reading.startedAt);
|
|
13599
14350
|
}
|
|
@@ -13601,8 +14352,8 @@ function trackerChanges(project, history, reading) {
|
|
|
13601
14352
|
for (const [id, ticket] of tickets) {
|
|
13602
14353
|
if (present.has(id) || ticket.reason === "No longer in tracker scope")
|
|
13603
14354
|
continue;
|
|
13604
|
-
for (const [key,
|
|
13605
|
-
if (
|
|
14355
|
+
for (const [key, item] of items)
|
|
14356
|
+
if (item.ticket === id)
|
|
13606
14357
|
emit("inbox.answered", { id: key, answer: "Ticket left tracker scope" }, reading.startedAt);
|
|
13607
14358
|
emit("ticket.seen", { ...ticket, status: "canceled", phase: "released", reason: "No longer in tracker scope" }, reading.startedAt);
|
|
13608
14359
|
}
|
|
@@ -13648,6 +14399,9 @@ class TrackerPoller {
|
|
|
13648
14399
|
const usage = this.#options.tracker.budget?.snapshot(this.#options.project);
|
|
13649
14400
|
return { ...this.#status, ...usage ? { usage, pausedUntil: usage.pausedUntil } : {} };
|
|
13650
14401
|
}
|
|
14402
|
+
get reading() {
|
|
14403
|
+
return this.#previous;
|
|
14404
|
+
}
|
|
13651
14405
|
start() {
|
|
13652
14406
|
if (this.#running)
|
|
13653
14407
|
return;
|
|
@@ -13902,32 +14656,35 @@ function linearConnection(secrets, endpoint = "https://api.linear.app/graphql",
|
|
|
13902
14656
|
}
|
|
13903
14657
|
|
|
13904
14658
|
// ../plugins/linear/src/index.ts
|
|
13905
|
-
var
|
|
13906
|
-
__export(
|
|
13907
|
-
activate: () =>
|
|
14659
|
+
var exports_src7 = {};
|
|
14660
|
+
__export(exports_src7, {
|
|
14661
|
+
activate: () => activate7
|
|
13908
14662
|
});
|
|
13909
|
-
function
|
|
14663
|
+
function activate7(ctx) {
|
|
13910
14664
|
const config = ctx.config.tracker?.linear;
|
|
13911
14665
|
const readers = new Map;
|
|
13912
14666
|
let pool = readerPools.get(ctx.events);
|
|
13913
14667
|
if (!pool) {
|
|
13914
|
-
pool = { budgets: new Map, pending: new Set };
|
|
14668
|
+
pool = { budgets: new Map, pending: new Set, projects: new Set };
|
|
13915
14669
|
readerPools.set(ctx.events, pool);
|
|
13916
14670
|
}
|
|
13917
14671
|
const { budgets, pending } = pool;
|
|
14672
|
+
for (const project of [...config.quotaProjects ?? [], ...Object.keys(config.projects ?? {})])
|
|
14673
|
+
pool.projects.add(project);
|
|
13918
14674
|
const trackers = new Map;
|
|
13919
|
-
const
|
|
14675
|
+
const programs = new Map;
|
|
14676
|
+
const trackerFor = (project, quotaOnly = false) => {
|
|
13920
14677
|
let tracker = trackers.get(project);
|
|
13921
14678
|
if (tracker)
|
|
13922
14679
|
return tracker;
|
|
13923
14680
|
const settings = config.projects?.[project];
|
|
13924
|
-
if (!settings)
|
|
14681
|
+
if (!settings && !quotaOnly)
|
|
13925
14682
|
throw new Error("Linear project is not configured");
|
|
13926
14683
|
tracker = linearTracker({
|
|
13927
14684
|
project,
|
|
13928
14685
|
budgets,
|
|
13929
|
-
rootId: settings
|
|
13930
|
-
phaseGroup: settings
|
|
14686
|
+
rootId: settings?.programRoot ?? "",
|
|
14687
|
+
phaseGroup: settings?.phaseGroup ?? "Agent phase",
|
|
13931
14688
|
endpoint: config.endpoint,
|
|
13932
14689
|
secrets: async () => ctx.secrets.get("LINEAR_API_KEY", project),
|
|
13933
14690
|
fetch: (...args) => fetch(...args),
|
|
@@ -13941,8 +14698,8 @@ function activate6(ctx) {
|
|
|
13941
14698
|
const restoreBudget = () => {
|
|
13942
14699
|
if (restoredBudget)
|
|
13943
14700
|
return restoredBudget;
|
|
13944
|
-
const attempt = Promise.all(
|
|
13945
|
-
const tracker = trackerFor(project);
|
|
14701
|
+
const attempt = Promise.all([...pool.projects].map(async (project) => {
|
|
14702
|
+
const tracker = trackerFor(project, true);
|
|
13946
14703
|
try {
|
|
13947
14704
|
await tracker.prepare?.();
|
|
13948
14705
|
} catch {
|
|
@@ -13981,8 +14738,111 @@ function activate6(ctx) {
|
|
|
13981
14738
|
signal?.removeEventListener("abort", stop);
|
|
13982
14739
|
}
|
|
13983
14740
|
};
|
|
14741
|
+
const mutate = async (request, action) => {
|
|
14742
|
+
await waitForRestore(request.signal);
|
|
14743
|
+
const tracker = trackerFor(request.project);
|
|
14744
|
+
await tracker.prepare?.();
|
|
14745
|
+
const before = JSON.stringify(tracker.budget?.snapshot(request.project));
|
|
14746
|
+
try {
|
|
14747
|
+
return await action(tracker);
|
|
14748
|
+
} finally {
|
|
14749
|
+
const usage = tracker.budget?.snapshot(request.project);
|
|
14750
|
+
if (JSON.stringify(usage) !== before && tracker.quota && tracker.identity)
|
|
14751
|
+
await ctx.events.append({
|
|
14752
|
+
project: request.project,
|
|
14753
|
+
kind: "coordinator.checkpoint",
|
|
14754
|
+
actor: "Linear",
|
|
14755
|
+
at: new Date().toISOString(),
|
|
14756
|
+
payload: {
|
|
14757
|
+
checkpoint: JSON.parse(JSON.stringify({
|
|
14758
|
+
format: "armada.linear-reader",
|
|
14759
|
+
version: 1,
|
|
14760
|
+
source: tracker.identity,
|
|
14761
|
+
quota: tracker.quota,
|
|
14762
|
+
usage
|
|
14763
|
+
}))
|
|
14764
|
+
}
|
|
14765
|
+
});
|
|
14766
|
+
}
|
|
14767
|
+
};
|
|
13984
14768
|
const provider = {
|
|
13985
14769
|
...linearConnection(ctx.secrets, config.endpoint),
|
|
14770
|
+
async readProgram({ project, programRoot, phaseGroup, signal }) {
|
|
14771
|
+
await waitForRestore(signal);
|
|
14772
|
+
signal?.throwIfAborted();
|
|
14773
|
+
const group = phaseGroup ?? config.projects?.[project]?.phaseGroup ?? "Agent phase";
|
|
14774
|
+
const identity = JSON.stringify([programRoot, group]);
|
|
14775
|
+
let program = programs.get(project);
|
|
14776
|
+
if (!program || program.root !== identity) {
|
|
14777
|
+
program?.reader.stop();
|
|
14778
|
+
const tracker = linearTracker({
|
|
14779
|
+
project,
|
|
14780
|
+
budgets,
|
|
14781
|
+
rootId: programRoot,
|
|
14782
|
+
phaseGroup: group,
|
|
14783
|
+
endpoint: config.endpoint,
|
|
14784
|
+
secrets: () => ctx.secrets.get("LINEAR_API_KEY", project),
|
|
14785
|
+
fetch: (...args) => fetch(...args),
|
|
14786
|
+
now: () => new Date,
|
|
14787
|
+
log: (line) => ctx.log.info(line)
|
|
14788
|
+
});
|
|
14789
|
+
program = {
|
|
14790
|
+
root: identity,
|
|
14791
|
+
reader: new TrackerPoller({
|
|
14792
|
+
project,
|
|
14793
|
+
tracker,
|
|
14794
|
+
store: {
|
|
14795
|
+
append: async (event) => event.kind === "coordinator.checkpoint" ? await ctx.events.append(event) : { ...event, seq: 0 },
|
|
14796
|
+
readSince: async (after) => await ctx.events.read(project, after)
|
|
14797
|
+
},
|
|
14798
|
+
clock: {
|
|
14799
|
+
now: () => new Date,
|
|
14800
|
+
set(callback, delay) {
|
|
14801
|
+
const timer = setTimeout(callback, delay);
|
|
14802
|
+
return () => clearTimeout(timer);
|
|
14803
|
+
}
|
|
14804
|
+
}
|
|
14805
|
+
})
|
|
14806
|
+
};
|
|
14807
|
+
programs.set(project, program);
|
|
14808
|
+
}
|
|
14809
|
+
const { reader } = program;
|
|
14810
|
+
const stop = () => reader.stop();
|
|
14811
|
+
signal?.addEventListener("abort", stop, { once: true });
|
|
14812
|
+
try {
|
|
14813
|
+
await reader.readNow();
|
|
14814
|
+
signal?.throwIfAborted();
|
|
14815
|
+
const status = reader.status;
|
|
14816
|
+
if (status.pausedUntil)
|
|
14817
|
+
return { pausedUntil: status.pausedUntil };
|
|
14818
|
+
if (status.error || !reader.reading)
|
|
14819
|
+
throw new Error(status.error ?? "Tracker read failed");
|
|
14820
|
+
return {
|
|
14821
|
+
reading: {
|
|
14822
|
+
tickets: reader.reading.tickets.map((ticket) => ({
|
|
14823
|
+
id: ticket.id,
|
|
14824
|
+
title: ticket.title,
|
|
14825
|
+
description: ticket.description ?? "",
|
|
14826
|
+
state: ticket.status === "triage" ? "backlog" : ticket.status,
|
|
14827
|
+
labels: [...ticket.labels],
|
|
14828
|
+
parent: ticket.parent,
|
|
14829
|
+
blockers: (ticket.blockers ?? []).map((blocker) => blocker.id),
|
|
14830
|
+
url: ticket.url,
|
|
14831
|
+
source: ticket.id
|
|
14832
|
+
})),
|
|
14833
|
+
comments: reader.reading.comments.map((comment) => ({
|
|
14834
|
+
id: comment.id,
|
|
14835
|
+
ticket: comment.ticket,
|
|
14836
|
+
body: comment.body,
|
|
14837
|
+
author: comment.author,
|
|
14838
|
+
at: comment.createdAt
|
|
14839
|
+
}))
|
|
14840
|
+
}
|
|
14841
|
+
};
|
|
14842
|
+
} finally {
|
|
14843
|
+
signal?.removeEventListener("abort", stop);
|
|
14844
|
+
}
|
|
14845
|
+
},
|
|
13986
14846
|
async read({ project, signal }) {
|
|
13987
14847
|
signal?.throwIfAborted();
|
|
13988
14848
|
await waitForRestore(signal);
|
|
@@ -14020,6 +14880,12 @@ function activate6(ctx) {
|
|
|
14020
14880
|
signal?.removeEventListener("abort", stop);
|
|
14021
14881
|
}
|
|
14022
14882
|
},
|
|
14883
|
+
create(request) {
|
|
14884
|
+
return mutate(request, (tracker) => tracker.create(request));
|
|
14885
|
+
},
|
|
14886
|
+
update(request) {
|
|
14887
|
+
return mutate(request, (tracker) => tracker.update(request));
|
|
14888
|
+
},
|
|
14023
14889
|
async write({ project, ticket, phase, state, comment, commentId, signal, beforeWrite }) {
|
|
14024
14890
|
try {
|
|
14025
14891
|
const settings = config.projects?.[project];
|
|
@@ -14109,7 +14975,7 @@ function activate6(ctx) {
|
|
|
14109
14975
|
cursors.add(after);
|
|
14110
14976
|
}
|
|
14111
14977
|
const applicable = candidates.filter((label) => label.name === phase && label.parent?.name === group);
|
|
14112
|
-
const label = applicable
|
|
14978
|
+
const label = applicableLabel(applicable, issue.team.id);
|
|
14113
14979
|
if (!label)
|
|
14114
14980
|
throw new Error;
|
|
14115
14981
|
const labelIds = issue.labels.nodes.filter((label) => label.parent?.name !== group).map((label) => label.id);
|
|
@@ -14161,9 +15027,10 @@ function activate6(ctx) {
|
|
|
14161
15027
|
ctx.register.tracker("linear", provider);
|
|
14162
15028
|
}
|
|
14163
15029
|
var readerPools;
|
|
14164
|
-
var
|
|
15030
|
+
var init_src6 = __esm(() => {
|
|
14165
15031
|
init_checkpoint2();
|
|
14166
15032
|
init_linear();
|
|
15033
|
+
init_mutations();
|
|
14167
15034
|
init_poll();
|
|
14168
15035
|
readerPools = new WeakMap;
|
|
14169
15036
|
});
|
|
@@ -25543,11 +26410,11 @@ function secretConnection(secrets, name, label, changed) {
|
|
|
25543
26410
|
}
|
|
25544
26411
|
|
|
25545
26412
|
// ../plugins/model-anthropic/src/index.ts
|
|
25546
|
-
var
|
|
25547
|
-
__export(
|
|
25548
|
-
activate: () =>
|
|
26413
|
+
var exports_src8 = {};
|
|
26414
|
+
__export(exports_src8, {
|
|
26415
|
+
activate: () => activate8
|
|
25549
26416
|
});
|
|
25550
|
-
async function
|
|
26417
|
+
async function activate8(ctx) {
|
|
25551
26418
|
const secrets = new Map;
|
|
25552
26419
|
for (const name of ["ANTHROPIC_API_KEY", "ARMADA_MODEL_API_KEY"])
|
|
25553
26420
|
secrets.set(name, await ctx.secrets.get(name));
|
|
@@ -25574,7 +26441,7 @@ async function activate7(ctx) {
|
|
|
25574
26441
|
});
|
|
25575
26442
|
}
|
|
25576
26443
|
var schema;
|
|
25577
|
-
var
|
|
26444
|
+
var init_src7 = __esm(() => {
|
|
25578
26445
|
init_dist7();
|
|
25579
26446
|
init_zod();
|
|
25580
26447
|
schema = strictObject({
|
|
@@ -30561,11 +31428,11 @@ var init_dist9 = __esm(() => {
|
|
|
30561
31428
|
});
|
|
30562
31429
|
|
|
30563
31430
|
// ../plugins/model-openai-compatible/src/index.ts
|
|
30564
|
-
var
|
|
30565
|
-
__export(
|
|
30566
|
-
activate: () =>
|
|
31431
|
+
var exports_src9 = {};
|
|
31432
|
+
__export(exports_src9, {
|
|
31433
|
+
activate: () => activate9
|
|
30567
31434
|
});
|
|
30568
|
-
async function
|
|
31435
|
+
async function activate9(ctx) {
|
|
30569
31436
|
const secrets = new Map;
|
|
30570
31437
|
for (const name of secretNames)
|
|
30571
31438
|
secrets.set(name, await ctx.secrets.get(name));
|
|
@@ -30600,7 +31467,7 @@ async function activate8(ctx) {
|
|
|
30600
31467
|
});
|
|
30601
31468
|
}
|
|
30602
31469
|
var secretNames, schema2;
|
|
30603
|
-
var
|
|
31470
|
+
var init_src8 = __esm(() => {
|
|
30604
31471
|
init_dist9();
|
|
30605
31472
|
init_zod();
|
|
30606
31473
|
secretNames = ["OPENAI_API_KEY", "ARMADA_MODEL_API_KEY", "ZAI_API_KEY", "AZURE_AI_API_KEY"];
|
|
@@ -30907,6 +31774,28 @@ var init_supervisor = __esm(() => {
|
|
|
30907
31774
|
}
|
|
30908
31775
|
}
|
|
30909
31776
|
|
|
31777
|
+
// The liveness contract (version 1) is written once the CLI runs inside the pinned
|
|
31778
|
+
// process group. A later host that finds this endpoint dead without a final record
|
|
31779
|
+
// may check whether that group still exists; without the contract it knows nothing.
|
|
31780
|
+
// The file names the group only: no command, environment, output or token.
|
|
31781
|
+
let contractWrite = Promise.resolve();
|
|
31782
|
+
function persistContract(group) {
|
|
31783
|
+
if (!config.paths.pin || !Number.isInteger(group) || group < 1) return;
|
|
31784
|
+
const temporary = config.paths.pin + ".tmp-" + crypto.randomBytes(6).toString("hex");
|
|
31785
|
+
contractWrite = (async () => {
|
|
31786
|
+
const contract = {
|
|
31787
|
+
version: 1,
|
|
31788
|
+
worker: config.worker,
|
|
31789
|
+
workspace: config.workspace,
|
|
31790
|
+
group,
|
|
31791
|
+
platform: process.platform,
|
|
31792
|
+
establishedAt: new Date().toISOString(),
|
|
31793
|
+
};
|
|
31794
|
+
await fs.promises.writeFile(temporary, JSON.stringify(contract), { flag: "wx", mode: 0o600 });
|
|
31795
|
+
await fs.promises.rename(temporary, config.paths.pin);
|
|
31796
|
+
})().catch(() => fs.promises.unlink(temporary).catch(() => {}));
|
|
31797
|
+
}
|
|
31798
|
+
|
|
30910
31799
|
let serverClosing = false;
|
|
30911
31800
|
function maybeCloseServer() {
|
|
30912
31801
|
if (serverClosing || !closed || activeConnections !== 0 || !launchAnswered || !server || !server.listening) return;
|
|
@@ -30918,7 +31807,10 @@ var init_supervisor = __esm(() => {
|
|
|
30918
31807
|
return;
|
|
30919
31808
|
}
|
|
30920
31809
|
server.close(() => {
|
|
30921
|
-
|
|
31810
|
+
// The group ended under this supervisor; its final record (if any) is the proof now.
|
|
31811
|
+
const removals = [fs.promises.unlink(config.paths.socket).catch(() => {})];
|
|
31812
|
+
if (config.paths.pin) removals.push(contractWrite.then(() => fs.promises.unlink(config.paths.pin)).catch(() => {}));
|
|
31813
|
+
Promise.all(removals).finally(() => {
|
|
30922
31814
|
// The final metadata is intentionally retained for a new host to adopt
|
|
30923
31815
|
// a completed worker once. It contains no command or environment data.
|
|
30924
31816
|
fs.promises.lstat(config.paths.state).catch(() => null).then((metadata) => {
|
|
@@ -31127,6 +32019,7 @@ var init_supervisor = __esm(() => {
|
|
|
31127
32019
|
}
|
|
31128
32020
|
if (message.type === "started") {
|
|
31129
32021
|
state = "running";
|
|
32022
|
+
persistContract(livePinPid());
|
|
31130
32023
|
resolveStarted();
|
|
31131
32024
|
} else if (message.type === "launch-error") {
|
|
31132
32025
|
startError = new Error(typeof message.message === "string" ? message.message : "worker failed to start");
|
|
@@ -31369,7 +32262,7 @@ var init_supervisor = __esm(() => {
|
|
|
31369
32262
|
if (!directory.isDirectory() || directory.isSymbolicLink() ||
|
|
31370
32263
|
(typeof process.getuid === "function" && directory.uid !== process.getuid()) ||
|
|
31371
32264
|
(directory.mode & 0o077) !== 0) throw new Error("local supervisor directory is not private");
|
|
31372
|
-
for (const path of [config.paths.socket, config.paths.state]) {
|
|
32265
|
+
for (const path of [config.paths.socket, config.paths.state, config.paths.pin].filter(Boolean)) {
|
|
31373
32266
|
try {
|
|
31374
32267
|
await fs.promises.lstat(path);
|
|
31375
32268
|
throw new Error("local supervisor endpoint already exists");
|
|
@@ -31392,29 +32285,79 @@ var init_supervisor = __esm(() => {
|
|
|
31392
32285
|
});
|
|
31393
32286
|
|
|
31394
32287
|
// ../plugins/node-local/src/test-merge.ts
|
|
31395
|
-
import { spawn as spawn2 } from "node:child_process";
|
|
32288
|
+
import { execFile as execFile4, spawn as spawn2 } from "node:child_process";
|
|
31396
32289
|
import { mkdtemp as mkdtemp2, rm as rm6 } from "node:fs/promises";
|
|
31397
32290
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
31398
|
-
import { join as join14 } from "node:path";
|
|
32291
|
+
import { join as join14, win32 } from "node:path";
|
|
31399
32292
|
async function testMerge(request) {
|
|
31400
32293
|
if (!/^[0-9a-f]{40}$/.test(request.base) || !/^[0-9a-f]{40}$/.test(request.head) || !request.commands.length)
|
|
31401
32294
|
throw new Error("invalid test merge request");
|
|
31402
32295
|
request.signal?.throwIfAborted();
|
|
31403
32296
|
const directory = await mkdtemp2(join14(tmpdir3(), "armada-merge-"));
|
|
31404
32297
|
const path = join14(directory, "worktree");
|
|
32298
|
+
let cleanupSafe = true;
|
|
31405
32299
|
const run = (file, args, cwd = request.repository, signal = request.signal) => new Promise((resolve, reject) => {
|
|
31406
32300
|
signal?.throwIfAborted();
|
|
31407
|
-
const
|
|
32301
|
+
const windows = process.platform === "win32";
|
|
32302
|
+
const child = spawn2(windows ? process.execPath : file, windows ? ["-e", windowsRunner, file, ...args] : args, {
|
|
32303
|
+
cwd,
|
|
32304
|
+
detached: !windows,
|
|
32305
|
+
stdio: windows ? ["ignore", "pipe", "pipe", "ipc"] : ["ignore", "pipe", "pipe"],
|
|
32306
|
+
windowsHide: true
|
|
32307
|
+
});
|
|
32308
|
+
let output = Buffer.alloc(0);
|
|
32309
|
+
let truncated = false;
|
|
32310
|
+
const capture = (chunk) => {
|
|
32311
|
+
truncated ||= output.length + chunk.length > 64 * 1024;
|
|
32312
|
+
output = Buffer.concat([output, chunk]).subarray(-64 * 1024);
|
|
32313
|
+
};
|
|
32314
|
+
const text = () => {
|
|
32315
|
+
let start = 0;
|
|
32316
|
+
while (start < output.length && ((output[start] ?? 0) & 192) === 128)
|
|
32317
|
+
start++;
|
|
32318
|
+
return output.subarray(start).toString("utf8");
|
|
32319
|
+
};
|
|
32320
|
+
child.stdout?.on("data", capture);
|
|
32321
|
+
child.stderr?.on("data", capture);
|
|
31408
32322
|
let stopped = false;
|
|
32323
|
+
let commandCode = null;
|
|
32324
|
+
let killed;
|
|
32325
|
+
let drainTimer;
|
|
31409
32326
|
const kill = () => {
|
|
32327
|
+
if (killed)
|
|
32328
|
+
return killed;
|
|
31410
32329
|
if (!child.pid)
|
|
31411
|
-
return;
|
|
31412
|
-
|
|
31413
|
-
|
|
31414
|
-
|
|
31415
|
-
|
|
32330
|
+
return Promise.resolve(true);
|
|
32331
|
+
if (windows) {
|
|
32332
|
+
const root = process.env.SystemRoot || process.env.WINDIR || "C:\\Windows";
|
|
32333
|
+
killed = new Promise((done) => {
|
|
32334
|
+
if (!win32.isAbsolute(root))
|
|
32335
|
+
return done(false);
|
|
32336
|
+
execFile4(win32.join(root, "System32", "taskkill.exe"), ["/PID", String(child.pid), "/T", "/F"], { timeout: 1e4, windowsHide: true }, (error) => done(!error));
|
|
32337
|
+
}).then((confirmed) => {
|
|
32338
|
+
if (!confirmed)
|
|
32339
|
+
cleanupSafe = false;
|
|
32340
|
+
return confirmed;
|
|
32341
|
+
});
|
|
32342
|
+
drainTimer = setTimeout(() => {
|
|
32343
|
+
cleanupSafe = false;
|
|
32344
|
+
stopped = true;
|
|
31416
32345
|
child.kill("SIGKILL");
|
|
32346
|
+
child.stdout?.destroy();
|
|
32347
|
+
child.stderr?.destroy();
|
|
32348
|
+
if (child.connected)
|
|
32349
|
+
child.disconnect();
|
|
32350
|
+
clearTimeout(timer);
|
|
32351
|
+
signal?.removeEventListener("abort", abort);
|
|
32352
|
+
reject(new CommandFailure(text(), false));
|
|
32353
|
+
}, 15000);
|
|
32354
|
+
return killed;
|
|
32355
|
+
}
|
|
32356
|
+
try {
|
|
32357
|
+
process.kill(-child.pid, "SIGKILL");
|
|
31417
32358
|
} catch {}
|
|
32359
|
+
killed = Promise.resolve(true);
|
|
32360
|
+
return killed;
|
|
31418
32361
|
};
|
|
31419
32362
|
const abort = () => {
|
|
31420
32363
|
stopped = true;
|
|
@@ -31422,19 +32365,29 @@ async function testMerge(request) {
|
|
|
31422
32365
|
};
|
|
31423
32366
|
const timer = setTimeout(abort, 15 * 60000);
|
|
31424
32367
|
signal?.addEventListener("abort", abort, { once: true });
|
|
31425
|
-
|
|
32368
|
+
if (windows)
|
|
32369
|
+
child.on("message", (message) => {
|
|
32370
|
+
if (message && typeof message === "object" && "code" in message) {
|
|
32371
|
+
commandCode = typeof message.code === "number" ? message.code : null;
|
|
32372
|
+
kill();
|
|
32373
|
+
}
|
|
32374
|
+
});
|
|
32375
|
+
child.once("exit", kill);
|
|
32376
|
+
child.once("error", () => {
|
|
31426
32377
|
clearTimeout(timer);
|
|
31427
32378
|
signal?.removeEventListener("abort", abort);
|
|
31428
|
-
reject(
|
|
32379
|
+
reject(new CommandFailure(text(), false));
|
|
31429
32380
|
});
|
|
31430
|
-
child.once("close", (code) => {
|
|
32381
|
+
child.once("close", async (code) => {
|
|
31431
32382
|
clearTimeout(timer);
|
|
31432
32383
|
signal?.removeEventListener("abort", abort);
|
|
31433
|
-
kill();
|
|
31434
|
-
|
|
31435
|
-
|
|
32384
|
+
const confirmed = await kill();
|
|
32385
|
+
clearTimeout(drainTimer);
|
|
32386
|
+
const exitCode = windows ? commandCode : code;
|
|
32387
|
+
if (!stopped && confirmed && exitCode === 0)
|
|
32388
|
+
resolve({ output: text(), truncated });
|
|
31436
32389
|
else
|
|
31437
|
-
reject(new
|
|
32390
|
+
reject(new CommandFailure(text(), !stopped && confirmed && exitCode !== null));
|
|
31438
32391
|
});
|
|
31439
32392
|
});
|
|
31440
32393
|
let added = false;
|
|
@@ -31467,32 +32420,72 @@ async function testMerge(request) {
|
|
|
31467
32420
|
], path);
|
|
31468
32421
|
for (const command of request.commands) {
|
|
31469
32422
|
step = command;
|
|
31470
|
-
await run("
|
|
32423
|
+
const prerequisites = await run("git", ["ls-files", "--others", "--directory", "-z"], path).catch(() => null);
|
|
32424
|
+
try {
|
|
32425
|
+
await run("sh", ["-c", command], path);
|
|
32426
|
+
} catch (error) {
|
|
32427
|
+
let baseCheck = "unavailable";
|
|
32428
|
+
if (error instanceof CommandFailure && error.exited && !request.signal?.aborted && prerequisites && !prerequisites.truncated) {
|
|
32429
|
+
try {
|
|
32430
|
+
const exclusions = prerequisites.output.split("\x00").filter(Boolean).flatMap((path) => ["-e", `/${path.replace(/[\\*?[\]!]/g, "\\$&")}`]);
|
|
32431
|
+
await run("git", ["reset", "--hard", request.base], path);
|
|
32432
|
+
await run("git", ["clean", "-ffdx", ...exclusions], path);
|
|
32433
|
+
try {
|
|
32434
|
+
await run("sh", ["-c", command], path);
|
|
32435
|
+
baseCheck = "passed";
|
|
32436
|
+
} catch (baseError) {
|
|
32437
|
+
if (baseError instanceof CommandFailure && baseError.exited && !request.signal?.aborted)
|
|
32438
|
+
baseCheck = "failed";
|
|
32439
|
+
}
|
|
32440
|
+
} catch {}
|
|
32441
|
+
}
|
|
32442
|
+
return { ok: false, step, output: error instanceof CommandFailure ? error.output : "", baseCheck };
|
|
32443
|
+
}
|
|
31471
32444
|
}
|
|
31472
32445
|
return { ok: true };
|
|
31473
|
-
} catch {
|
|
31474
|
-
return { ok: false, step, output:
|
|
32446
|
+
} catch (error) {
|
|
32447
|
+
return { ok: false, step, output: error instanceof CommandFailure ? error.output : "" };
|
|
31475
32448
|
} finally {
|
|
31476
|
-
|
|
31477
|
-
|
|
31478
|
-
|
|
31479
|
-
|
|
31480
|
-
|
|
32449
|
+
if (cleanupSafe) {
|
|
32450
|
+
try {
|
|
32451
|
+
if (added)
|
|
32452
|
+
await run("git", ["worktree", "remove", "--force", path], request.repository, null);
|
|
32453
|
+
} finally {
|
|
32454
|
+
if (cleanupSafe)
|
|
32455
|
+
await rm6(directory, { recursive: true, force: true });
|
|
32456
|
+
}
|
|
31481
32457
|
}
|
|
31482
32458
|
}
|
|
31483
32459
|
}
|
|
31484
|
-
var
|
|
32460
|
+
var CommandFailure, windowsRunner = `
|
|
32461
|
+
const { spawn } = require("node:child_process");
|
|
32462
|
+
setInterval(() => {}, 60000);
|
|
32463
|
+
const child = spawn(process.argv[1], process.argv.slice(2), { stdio: ["ignore", "inherit", "inherit"], windowsHide: true });
|
|
32464
|
+
child.once("error", () => process.send({ code: null }));
|
|
32465
|
+
child.once("exit", (code) => process.send({ code }));
|
|
32466
|
+
`;
|
|
32467
|
+
var init_test_merge = __esm(() => {
|
|
32468
|
+
CommandFailure = class CommandFailure extends Error {
|
|
32469
|
+
output;
|
|
32470
|
+
exited;
|
|
32471
|
+
constructor(output, exited) {
|
|
32472
|
+
super("local command failed");
|
|
32473
|
+
this.output = output;
|
|
32474
|
+
this.exited = exited;
|
|
32475
|
+
}
|
|
32476
|
+
};
|
|
32477
|
+
});
|
|
31485
32478
|
|
|
31486
32479
|
// ../plugins/node-local/src/index.ts
|
|
31487
|
-
var
|
|
31488
|
-
__export(
|
|
32480
|
+
var exports_src10 = {};
|
|
32481
|
+
__export(exports_src10, {
|
|
31489
32482
|
LocalNode: () => LocalNode,
|
|
31490
|
-
activate: () =>
|
|
32483
|
+
activate: () => activate10,
|
|
31491
32484
|
createLocalNode: () => createLocalNode,
|
|
31492
32485
|
plugin: () => plugin
|
|
31493
32486
|
});
|
|
31494
32487
|
import { execFile as execFileCallback, spawn as spawn3 } from "node:child_process";
|
|
31495
|
-
import { createHash as createHash11, randomUUID as
|
|
32488
|
+
import { createHash as createHash11, randomUUID as randomUUID8 } from "node:crypto";
|
|
31496
32489
|
import { appendFile, lstat as lstat2, mkdir as mkdir4, readFile as readFile6, realpath as realpath2, rmdir, unlink } from "node:fs/promises";
|
|
31497
32490
|
import { createConnection } from "node:net";
|
|
31498
32491
|
import { homedir as homedir4, tmpdir as tmpdir4 } from "node:os";
|
|
@@ -31571,7 +32564,7 @@ function supervisorPaths(workspaceRoot, handle) {
|
|
|
31571
32564
|
const digest = createHash11("sha256").update(workspaceRoot).update("\x00").update(handle).digest("hex").slice(0, 24);
|
|
31572
32565
|
const directory = join15(process.platform === "win32" ? tmpdir4() : "/tmp", `armada-nl-${digest}`);
|
|
31573
32566
|
const socket = process.platform === "win32" ? `\\\\.\\pipe\\armada-nl-${digest}` : join15(directory, "s");
|
|
31574
|
-
return { directory, socket, state: join15(directory, "state.json") };
|
|
32567
|
+
return { directory, socket, state: join15(directory, "state.json"), pin: join15(directory, "pin.json") };
|
|
31575
32568
|
}
|
|
31576
32569
|
async function privateDirectory(directory) {
|
|
31577
32570
|
try {
|
|
@@ -31695,8 +32688,56 @@ async function readFinalMetadata(paths, worker, workspace) {
|
|
|
31695
32688
|
}
|
|
31696
32689
|
async function removeFinalMetadata(paths) {
|
|
31697
32690
|
await unlink(paths.state).catch(() => {});
|
|
32691
|
+
await unlink(paths.pin).catch(() => {});
|
|
31698
32692
|
await rmdir(paths.directory).catch(() => {});
|
|
31699
32693
|
}
|
|
32694
|
+
async function readLivenessContract(paths, worker, workspace) {
|
|
32695
|
+
if (!await privateDirectory(paths.directory))
|
|
32696
|
+
return { kind: "none" };
|
|
32697
|
+
let text;
|
|
32698
|
+
try {
|
|
32699
|
+
const details = await lstat2(paths.pin);
|
|
32700
|
+
if (!details.isFile() || details.isSymbolicLink() || details.size > 64 * 1024)
|
|
32701
|
+
return { kind: "invalid", reason: "its liveness contract is not a private file" };
|
|
32702
|
+
text = await readFile6(paths.pin, "utf8");
|
|
32703
|
+
} catch (error) {
|
|
32704
|
+
if (isErrno(error, "ENOENT"))
|
|
32705
|
+
return { kind: "none" };
|
|
32706
|
+
return { kind: "invalid", reason: "its liveness contract could not be read" };
|
|
32707
|
+
}
|
|
32708
|
+
let contract;
|
|
32709
|
+
try {
|
|
32710
|
+
contract = JSON.parse(text);
|
|
32711
|
+
} catch {
|
|
32712
|
+
return { kind: "invalid", reason: "its liveness contract is not valid JSON" };
|
|
32713
|
+
}
|
|
32714
|
+
if (!contract || typeof contract !== "object" || contract.version !== 1)
|
|
32715
|
+
return { kind: "invalid", reason: "its liveness contract has an unknown version" };
|
|
32716
|
+
if (!contract.worker || typeof contract.worker !== "object" || !contract.workspace || typeof contract.workspace !== "object" || !sameWorker(contract.worker, worker) || !sameWorkspace(contract.workspace, workspace))
|
|
32717
|
+
return { kind: "invalid", reason: "its liveness contract belongs to another worker generation" };
|
|
32718
|
+
if (!Number.isInteger(contract.group) || contract.group < 2 || contract.platform !== process.platform)
|
|
32719
|
+
return { kind: "invalid", reason: "its liveness contract names no process group of this platform" };
|
|
32720
|
+
return { kind: "contract", contract };
|
|
32721
|
+
}
|
|
32722
|
+
async function unreachableWorker(paths, worker, workspace, error) {
|
|
32723
|
+
const finding = isErrno(error, "ENOENT") ? `no supervisor endpoint at ${paths.socket}` : `the supervisor endpoint ${paths.socket} refused the connection`;
|
|
32724
|
+
const head = `local worker ${worker.ticket} generation ${worker.generation} is unreachable: ${finding}, and no final record exists`;
|
|
32725
|
+
const read = await readLivenessContract(paths, worker, workspace);
|
|
32726
|
+
if (read.kind === "none")
|
|
32727
|
+
return new Error(`${head}; no liveness contract was recorded for it (launched before version 1 or ended before its CLI started), so its process tree may still run; nothing was signaled`);
|
|
32728
|
+
if (read.kind === "invalid")
|
|
32729
|
+
return new Error(`${head}; ${read.reason}, so its process tree may still run; nothing was signaled`);
|
|
32730
|
+
if (process.platform === "win32")
|
|
32731
|
+
return new Error(`${head}; process-group liveness cannot be checked on Windows, so its tree may still run`);
|
|
32732
|
+
try {
|
|
32733
|
+
process.kill(-read.contract.group, 0);
|
|
32734
|
+
return new WorkerRuntimeAlive(`${head}; its pinned process group still exists, so the worker's CLI or a descendant still runs; nothing was signaled`);
|
|
32735
|
+
} catch (probe) {
|
|
32736
|
+
if (isErrno(probe, "ESRCH"))
|
|
32737
|
+
return new WorkerRuntimeGone(`${head}; its liveness contract (version 1) names a process group that no longer exists: every process still pinned to it has ended; nothing was signaled`);
|
|
32738
|
+
return new Error(`${head}; its process group could not be inspected (${isErrno(probe, "EPERM") ? "EPERM" : "unknown error"}), so its tree may still run; nothing was signaled`);
|
|
32739
|
+
}
|
|
32740
|
+
}
|
|
31700
32741
|
function staleWorker() {
|
|
31701
32742
|
return new Error("worker reference is stale or mismatched; left the worker untouched");
|
|
31702
32743
|
}
|
|
@@ -31826,11 +32867,14 @@ class LocalNode {
|
|
|
31826
32867
|
cwd: source,
|
|
31827
32868
|
signal: request.signal
|
|
31828
32869
|
});
|
|
31829
|
-
const id =
|
|
32870
|
+
const id = randomUUID8();
|
|
31830
32871
|
const path = join15(workspaceRoot, projectRoot ? safePart(request.ticket, "ticket") : `${safePart(request.project, "project")}-${safePart(request.ticket, "ticket")}-${id}`);
|
|
31831
32872
|
if (projectRoot) {
|
|
31832
32873
|
await projectWorktreeRoot(projectRoot, path, request.signal);
|
|
31833
32874
|
await excludeWorktrees(source, workspaceRoot, request.signal);
|
|
32875
|
+
const kept = await this.#keptWorktree(source, path, workspaceRoot, request);
|
|
32876
|
+
if (kept)
|
|
32877
|
+
return kept;
|
|
31834
32878
|
} else
|
|
31835
32879
|
await mkdir4(workspaceRoot, { recursive: true });
|
|
31836
32880
|
const base = (await git(["rev-parse", "HEAD"], { cwd: source, signal: request.signal })).stdout.trim();
|
|
@@ -31885,7 +32929,7 @@ class LocalNode {
|
|
|
31885
32929
|
throw invalidInput("worker session is empty");
|
|
31886
32930
|
if (!Number.isInteger(request.worker.generation) || request.worker.generation < 1)
|
|
31887
32931
|
throw invalidInput("worker generation must be a positive integer");
|
|
31888
|
-
const handle = request.handle ??
|
|
32932
|
+
const handle = request.handle ?? randomUUID8();
|
|
31889
32933
|
if (!isUuid(handle))
|
|
31890
32934
|
throw invalidInput("worker handle must be a UUID");
|
|
31891
32935
|
if (!request.command || request.command.includes("\x00"))
|
|
@@ -31954,8 +32998,26 @@ class LocalNode {
|
|
|
31954
32998
|
throw error;
|
|
31955
32999
|
this.#applySnapshot(existing, final);
|
|
31956
33000
|
}
|
|
31957
|
-
} else
|
|
31958
|
-
|
|
33001
|
+
} else {
|
|
33002
|
+
try {
|
|
33003
|
+
await this.#refresh(existing, "adopt");
|
|
33004
|
+
} catch (error) {
|
|
33005
|
+
if (!supervisorUnavailable(error))
|
|
33006
|
+
throw error;
|
|
33007
|
+
const final = await readFinalMetadata(existing.paths, worker, workspace);
|
|
33008
|
+
if (final)
|
|
33009
|
+
this.#applySnapshot(existing, final);
|
|
33010
|
+
else {
|
|
33011
|
+
const verdict = await unreachableWorker(existing.paths, worker, workspace, error);
|
|
33012
|
+
if (verdict instanceof WorkerRuntimeGone) {
|
|
33013
|
+
existing.state = "failed";
|
|
33014
|
+
existing.closedValue = true;
|
|
33015
|
+
} else
|
|
33016
|
+
existing.state = "unknown";
|
|
33017
|
+
throw verdict;
|
|
33018
|
+
}
|
|
33019
|
+
}
|
|
33020
|
+
}
|
|
31959
33021
|
return { deliveries: existing.deliveries };
|
|
31960
33022
|
}
|
|
31961
33023
|
let snapshot;
|
|
@@ -31973,11 +33035,8 @@ class LocalNode {
|
|
|
31973
33035
|
if (!supervisorUnavailable(error))
|
|
31974
33036
|
throw error;
|
|
31975
33037
|
const final = await readFinalMetadata(paths, worker, workspace);
|
|
31976
|
-
if (!final)
|
|
31977
|
-
|
|
31978
|
-
throw error;
|
|
31979
|
-
throw staleWorker();
|
|
31980
|
-
}
|
|
33038
|
+
if (!final)
|
|
33039
|
+
throw recovery.starting ? error : await unreachableWorker(paths, worker, workspace, error);
|
|
31981
33040
|
snapshot = final;
|
|
31982
33041
|
}
|
|
31983
33042
|
const workspaceRecord = this.#workspaceFromMetadata(workspace, snapshot.provenance, worker.project);
|
|
@@ -32109,10 +33168,69 @@ class LocalNode {
|
|
|
32109
33168
|
}
|
|
32110
33169
|
#activeWorker(workspace) {
|
|
32111
33170
|
for (const record of this.#workers.values())
|
|
32112
|
-
if (record.workspace === workspace && !record.closedValue)
|
|
33171
|
+
if ((record.workspace === workspace || record.workspace.workspace.path === workspace.workspace.path) && !record.closedValue)
|
|
32113
33172
|
return record;
|
|
32114
33173
|
return;
|
|
32115
33174
|
}
|
|
33175
|
+
async#keptWorktree(source, path, workspaceRoot, request) {
|
|
33176
|
+
const previous = reuseAdmissions.get(path) ?? Promise.resolve();
|
|
33177
|
+
const operation = previous.catch(() => {}).then(async () => {
|
|
33178
|
+
try {
|
|
33179
|
+
if ((await lstat2(path)).isSymbolicLink())
|
|
33180
|
+
throw invalidInput("project worktree must not be a symbolic link");
|
|
33181
|
+
} catch (error) {
|
|
33182
|
+
if (isErrno(error, "ENOENT"))
|
|
33183
|
+
return;
|
|
33184
|
+
throw error;
|
|
33185
|
+
}
|
|
33186
|
+
const real = await realPathOf(path);
|
|
33187
|
+
const describe = `${path} already exists`;
|
|
33188
|
+
const listing = (await git(["worktree", "list", "--porcelain"], { cwd: source, signal: request.signal })).stdout;
|
|
33189
|
+
let entry;
|
|
33190
|
+
for (const block of listing.split(/\r?\n\r?\n/)) {
|
|
33191
|
+
const lines = block.split(/\r?\n/);
|
|
33192
|
+
const first = lines[0];
|
|
33193
|
+
if (!first?.startsWith("worktree "))
|
|
33194
|
+
continue;
|
|
33195
|
+
if (await realPathOf(first.slice("worktree ".length)) === real) {
|
|
33196
|
+
entry = lines;
|
|
33197
|
+
break;
|
|
33198
|
+
}
|
|
33199
|
+
}
|
|
33200
|
+
if (!entry)
|
|
33201
|
+
throw invalidInput(`${describe} but is not a worktree of ${source}; move it aside before launching ${request.ticket}`);
|
|
33202
|
+
const branch = entry.find((line) => line.startsWith("branch "))?.slice("branch ".length);
|
|
33203
|
+
if (entry.includes("detached") || entry.some((line) => line.startsWith("prunable")) || branch !== `refs/heads/${request.branch}`)
|
|
33204
|
+
throw invalidInput(`${describe} as a kept worktree on ${branch ? branch.replace(/^refs\/heads\//, "") : "(detached HEAD)"}, not ${request.branch}; move it aside or finish it before launching ${request.ticket}`);
|
|
33205
|
+
request.signal?.throwIfAborted();
|
|
33206
|
+
const current = (await git(["branch", "--show-current"], { cwd: path, signal: request.signal })).stdout.trim();
|
|
33207
|
+
const top = (await git(["rev-parse", "--show-toplevel"], { cwd: path, signal: request.signal })).stdout.trim();
|
|
33208
|
+
if (current !== request.branch || !top || await realPathOf(top) !== real)
|
|
33209
|
+
throw invalidInput(`${describe} but its checkout is not ${request.branch} at that path; inspect it before launching`);
|
|
33210
|
+
const busy = [...this.#workers.values()].find((record) => record.workspace.workspace.path === path && !record.closedValue);
|
|
33211
|
+
if (busy)
|
|
33212
|
+
throw new Error("workspace already has an active worker");
|
|
33213
|
+
const base = (await git(["rev-parse", "HEAD"], { cwd: source, signal: request.signal })).stdout.trim();
|
|
33214
|
+
const workspace = { id: randomUUID8(), path, node: "local" };
|
|
33215
|
+
this.#workspaces.set(workspace.id, {
|
|
33216
|
+
workspace: { ...workspace },
|
|
33217
|
+
workspaceRoot,
|
|
33218
|
+
repository: source,
|
|
33219
|
+
branch: request.branch,
|
|
33220
|
+
base,
|
|
33221
|
+
lock: Promise.resolve(),
|
|
33222
|
+
removed: false
|
|
33223
|
+
});
|
|
33224
|
+
return workspace;
|
|
33225
|
+
});
|
|
33226
|
+
reuseAdmissions.set(path, operation);
|
|
33227
|
+
try {
|
|
33228
|
+
return await operation;
|
|
33229
|
+
} finally {
|
|
33230
|
+
if (reuseAdmissions.get(path) === operation)
|
|
33231
|
+
reuseAdmissions.delete(path);
|
|
33232
|
+
}
|
|
33233
|
+
}
|
|
32116
33234
|
#record(ref, workspace, paths) {
|
|
32117
33235
|
return {
|
|
32118
33236
|
ref: { ...ref },
|
|
@@ -32239,16 +33357,21 @@ function supervisorUnavailable(error) {
|
|
|
32239
33357
|
return isErrno(error, "ENOENT") || isErrno(error, "ECONNREFUSED") || isErrno(error, "ECONNRESET") || isErrno(error, "EPIPE");
|
|
32240
33358
|
}
|
|
32241
33359
|
async function withWorkspaceLock(workspace, action) {
|
|
32242
|
-
const
|
|
33360
|
+
const key = workspace.workspace.path;
|
|
33361
|
+
const previous = pathLocks.get(key) ?? workspace.lock;
|
|
32243
33362
|
let release;
|
|
32244
|
-
|
|
33363
|
+
const lock = new Promise((resolvePromise) => {
|
|
32245
33364
|
release = resolvePromise;
|
|
32246
33365
|
});
|
|
33366
|
+
workspace.lock = lock;
|
|
33367
|
+
pathLocks.set(key, lock);
|
|
32247
33368
|
await previous;
|
|
32248
33369
|
try {
|
|
32249
33370
|
return await action();
|
|
32250
33371
|
} finally {
|
|
32251
33372
|
release();
|
|
33373
|
+
if (pathLocks.get(key) === lock)
|
|
33374
|
+
pathLocks.delete(key);
|
|
32252
33375
|
}
|
|
32253
33376
|
}
|
|
32254
33377
|
function createLocalNode(options = {}) {
|
|
@@ -32265,12 +33388,13 @@ function createLocalNode(options = {}) {
|
|
|
32265
33388
|
dispose: node.dispose.bind(node)
|
|
32266
33389
|
};
|
|
32267
33390
|
}
|
|
32268
|
-
function
|
|
33391
|
+
function activate10(ctx) {
|
|
32269
33392
|
const options = ctx.config.node?.local ?? {};
|
|
32270
33393
|
ctx.register.node("local", createLocalNode(options));
|
|
32271
33394
|
}
|
|
32272
|
-
var execute2, DEFAULT_OUTPUT_TAIL, DEFAULT_STOP_TIMEOUT_MS = 1000, DEFAULT_KILL_TIMEOUT_MS = 1000, MAX_OUTPUT_TAIL, MAX_SUPERVISOR_RESPONSE_BYTES, GIT_MAX_BUFFER, BASE_ENV_KEYS, WINDOWS_ENV_KEYS, excludeWrites, plugin;
|
|
32273
|
-
var
|
|
33395
|
+
var execute2, DEFAULT_OUTPUT_TAIL, DEFAULT_STOP_TIMEOUT_MS = 1000, DEFAULT_KILL_TIMEOUT_MS = 1000, MAX_OUTPUT_TAIL, MAX_SUPERVISOR_RESPONSE_BYTES, GIT_MAX_BUFFER, BASE_ENV_KEYS, WINDOWS_ENV_KEYS, excludeWrites, reuseAdmissions, pathLocks, plugin;
|
|
33396
|
+
var init_src9 = __esm(() => {
|
|
33397
|
+
init_dist();
|
|
32274
33398
|
init_guard();
|
|
32275
33399
|
init_supervisor();
|
|
32276
33400
|
init_test_merge();
|
|
@@ -32320,13 +33444,15 @@ var init_src8 = __esm(() => {
|
|
|
32320
33444
|
"NUMBER_OF_PROCESSORS"
|
|
32321
33445
|
]);
|
|
32322
33446
|
excludeWrites = new Map;
|
|
32323
|
-
|
|
33447
|
+
reuseAdmissions = new Map;
|
|
33448
|
+
pathLocks = new Map;
|
|
33449
|
+
plugin = { activate: activate10 };
|
|
32324
33450
|
});
|
|
32325
33451
|
|
|
32326
33452
|
// ../plugins/opencode/src/driver.ts
|
|
32327
|
-
var
|
|
32328
|
-
var
|
|
32329
|
-
|
|
33453
|
+
var DRIVER3;
|
|
33454
|
+
var init_driver3 = __esm(() => {
|
|
33455
|
+
DRIVER3 = String.raw`
|
|
32330
33456
|
import { execFile, spawn } from "node:child_process";
|
|
32331
33457
|
import { createInterface } from "node:readline";
|
|
32332
33458
|
const options = JSON.parse(process.argv[1]);
|
|
@@ -32365,7 +33491,19 @@ input.on("close", () => { chain.finally(() => process.exit(failed ? 1 : 0)); });
|
|
|
32365
33491
|
async function turn(message) {
|
|
32366
33492
|
if (failed) throw new Error("CLI session is no longer usable");
|
|
32367
33493
|
const args = ["run", ...(session ? ["--session", session] : []), ...(options.model ? ["--model", options.model] : []), ...(options.effort ? ["--variant", options.effort] : []), ...options.extraArgs, "--format", "json"];
|
|
32368
|
-
const child = spawn(options.command, args, { stdio: ["pipe", "pipe", "
|
|
33494
|
+
const child = spawn(options.command, args, { stdio: ["pipe", "pipe", "pipe"], shell: false });
|
|
33495
|
+
// Retain only a fixed marker; provider errors/stderr may contain credentials.
|
|
33496
|
+
let permissionDenied = false;
|
|
33497
|
+
let diagnosticTail = "";
|
|
33498
|
+
const permissionEvidence = (text) => {
|
|
33499
|
+
diagnosticTail = (diagnosticTail + text).slice(-4096);
|
|
33500
|
+
if (!permissionDenied && /requested permissions|(?:have|has)n['’]t granted|permission gate refused|permission (?:prompt|request)|Permission(?:Denied|Rejected|Required)(?:Error)?|approval (?:required|denied|request)/i.test(diagnosticTail)) {
|
|
33501
|
+
permissionDenied = true;
|
|
33502
|
+
emit("failure", { permission: true });
|
|
33503
|
+
}
|
|
33504
|
+
};
|
|
33505
|
+
child.stderr.setEncoding("utf8");
|
|
33506
|
+
child.stderr.on("data", permissionEvidence);
|
|
32369
33507
|
let pending = "";
|
|
32370
33508
|
let reply = "";
|
|
32371
33509
|
let completed = false;
|
|
@@ -32376,7 +33514,11 @@ async function turn(message) {
|
|
|
32376
33514
|
if (typeof value.sessionID === "string") session = value.sessionID;
|
|
32377
33515
|
if (value.type === "text" && typeof value.part?.text === "string") reply = (reply + value.part.text).slice(-8192);
|
|
32378
33516
|
if (value.type === "step_finish" && value.part?.reason === "stop") completed = true;
|
|
32379
|
-
if (value.type === "error")
|
|
33517
|
+
if (value.type === "error") {
|
|
33518
|
+
turnFailed = true;
|
|
33519
|
+
for (const detail of [value.error?.name, value.error?.message, value.error?.data?.message])
|
|
33520
|
+
if (typeof detail === "string") permissionEvidence(detail);
|
|
33521
|
+
}
|
|
32380
33522
|
} catch { /* CLI progress diagnostics are not JSON events. */ }
|
|
32381
33523
|
};
|
|
32382
33524
|
child.stdout.setEncoding("utf8");
|
|
@@ -32395,7 +33537,7 @@ async function turn(message) {
|
|
|
32395
33537
|
if (pending) event(pending);
|
|
32396
33538
|
if (code !== 0 || turnFailed || !completed || !session) {
|
|
32397
33539
|
failed = true;
|
|
32398
|
-
emit("failure");
|
|
33540
|
+
emit("failure", permissionDenied ? { permission: true } : {});
|
|
32399
33541
|
} else emit("reply", { text: reply });
|
|
32400
33542
|
emit("done", { completed: ++completedTurns });
|
|
32401
33543
|
}
|
|
@@ -32434,9 +33576,9 @@ var init_status4 = __esm(() => {
|
|
|
32434
33576
|
});
|
|
32435
33577
|
|
|
32436
33578
|
// ../plugins/opencode/src/index.ts
|
|
32437
|
-
var
|
|
32438
|
-
__export(
|
|
32439
|
-
activate: () =>
|
|
33579
|
+
var exports_src11 = {};
|
|
33580
|
+
__export(exports_src11, {
|
|
33581
|
+
activate: () => activate11,
|
|
32440
33582
|
opencodeRuntime: () => opencodeRuntime
|
|
32441
33583
|
});
|
|
32442
33584
|
function opencodeRuntime(options = {}, node) {
|
|
@@ -32514,10 +33656,14 @@ function opencodeRuntime(options = {}, node) {
|
|
|
32514
33656
|
const ref = await facilities().launch(native ? {
|
|
32515
33657
|
...request,
|
|
32516
33658
|
command: "node",
|
|
33659
|
+
env: {
|
|
33660
|
+
...request.env,
|
|
33661
|
+
...(options.permissionMode ?? "allow") === "default" || request.env.OPENCODE_PERMISSION !== undefined ? {} : { OPENCODE_PERMISSION: JSON.stringify({ "*": options.permissionMode ?? "allow" }) }
|
|
33662
|
+
},
|
|
32517
33663
|
args: [
|
|
32518
33664
|
"--input-type=module",
|
|
32519
33665
|
"-e",
|
|
32520
|
-
|
|
33666
|
+
DRIVER3,
|
|
32521
33667
|
JSON.stringify({ command: options.binary ?? options.command ?? "opencode", model, effort, extraArgs })
|
|
32522
33668
|
]
|
|
32523
33669
|
} : request);
|
|
@@ -32611,12 +33757,12 @@ function opencodeRuntime(options = {}, node) {
|
|
|
32611
33757
|
}
|
|
32612
33758
|
};
|
|
32613
33759
|
}
|
|
32614
|
-
function
|
|
33760
|
+
function activate11(ctx) {
|
|
32615
33761
|
ctx.register.runtime("opencode", opencodeRuntime(ctx.config.runtime?.opencode ?? {}));
|
|
32616
33762
|
}
|
|
32617
33763
|
var same5 = (a, b) => a.project === b.project && a.ticket === b.ticket && a.session === b.session && a.generation === b.generation && a.handle === b.handle;
|
|
32618
|
-
var
|
|
32619
|
-
|
|
33764
|
+
var init_src10 = __esm(() => {
|
|
33765
|
+
init_driver3();
|
|
32620
33766
|
init_status4();
|
|
32621
33767
|
});
|
|
32622
33768
|
|
|
@@ -32624,16 +33770,17 @@ var init_src9 = __esm(() => {
|
|
|
32624
33770
|
var BUNDLED_PLUGINS;
|
|
32625
33771
|
var init_catalog_generated = __esm(() => {
|
|
32626
33772
|
BUNDLED_PLUGINS = [
|
|
32627
|
-
{ id: "claude", manifest: { id: "claude", version: "0.1.0", pluginApi: "^0.2.0", description: "Run the official Claude CLI using host-selected node facilities.", enabledByDefault: true, contributions: { runtime: { claude: { config: { type: "object", properties: { command: { type: "string", minLength: 1 }, args: { type: "array", items: { type: "string" } }, binary: { type: "string", minLength: 1 } }, additionalProperties: false }, secrets: [] } } } }, load: () => Promise.resolve().then(() => (init_src(), exports_src)) },
|
|
32628
|
-
{ id: "codex", manifest: { id: "codex", version: "0.1.0", pluginApi: "^0.2.0", description: "Run the official codex CLI using host-selected node facilities.", enabledByDefault: true, contributions: { runtime: { codex: { config: { type: "object", properties: { command: { type: "string", minLength: 1 }, model: { type: "string", minLength: 1 }, effort: { type: "string", minLength: 1 }, extraArgs: { type: "array", items: { type: "string" } }, binary: { type: "string", minLength: 1 } }, additionalProperties: false }, secrets: [] } } } }, load: () => Promise.resolve().then(() => (init_src2(), exports_src2)) },
|
|
33773
|
+
{ id: "claude", manifest: { id: "claude", version: "0.1.0", pluginApi: "^0.2.0", description: "Run the official Claude CLI using host-selected node facilities.", enabledByDefault: true, contributions: { runtime: { claude: { config: { type: "object", properties: { command: { type: "string", minLength: 1 }, args: { type: "array", items: { type: "string" } }, binary: { type: "string", minLength: 1 }, permissionMode: { type: "string", enum: ["bypassPermissions", "acceptEdits", "default"], default: "bypassPermissions", description: "Worker permission mode. Applies after restarting Armada; explicit runtime arguments take precedence." } }, additionalProperties: false }, secrets: [] } } } }, load: () => Promise.resolve().then(() => (init_src(), exports_src)) },
|
|
33774
|
+
{ id: "codex", manifest: { id: "codex", version: "0.1.0", pluginApi: "^0.2.0", description: "Run the official codex CLI using host-selected node facilities.", enabledByDefault: true, contributions: { runtime: { codex: { config: { type: "object", properties: { command: { type: "string", minLength: 1 }, model: { type: "string", minLength: 1 }, effort: { type: "string", minLength: 1 }, extraArgs: { type: "array", items: { type: "string" } }, binary: { type: "string", minLength: 1 }, permissionMode: { type: "string", enum: ["workspace-write", "read-only", "default"], default: "workspace-write", description: "Worker permission mode. Applies after restarting Armada; explicit runtime arguments take precedence." } }, additionalProperties: false }, secrets: [] } } } }, load: () => Promise.resolve().then(() => (init_src2(), exports_src2)) },
|
|
32629
33775
|
{ id: "conductor", manifest: { id: "conductor", version: "0.1.0", pluginApi: "^0.2.0", description: "Run workers in Conductor using the desktop's Armada sign-in.", enabledByDefault: false, contributions: { runtime: { conductor: { config: { type: "object", properties: { binary: { type: "string", minLength: 1, description: "Path to the Conductor executable." }, defaultProfile: { type: "string", minLength: 1 }, profiles: { type: "object", additionalProperties: { type: "object", properties: { agent: { enum: ["claude", "codex", "opencode", "cursor"] }, model: { type: "string", minLength: 1 }, effort: { type: "string", minLength: 1 }, instructions: { type: "string", maxLength: 16000 } }, required: ["agent", "model", "effort"], additionalProperties: false } }, routing: { type: "array", items: { type: "object", properties: { labels: { type: "array", minItems: 1, items: { type: "string", minLength: 1 } }, profile: { type: "string", minLength: 1 } }, required: ["labels", "profile"], additionalProperties: false } } }, additionalProperties: false }, secrets: [] } } } }, load: () => Promise.resolve().then(() => (init_src3(), exports_src3)) },
|
|
32630
33776
|
{ id: "github", manifest: { id: "github", version: "0.1.0", pluginApi: "^0.2.0", enabledByDefault: true, description: "Read Github observations into the fleet event log.", contributions: { forge: { github: { config: { type: "object", properties: { projects: { type: "object", additionalProperties: { type: "object", properties: { repository: { type: "string", pattern: "^[\\w.-]+/[\\w.-]+$" } }, required: ["repository"], additionalProperties: false } }, endpoint: { type: "string" } }, additionalProperties: false }, secrets: ["GITHUB_TOKEN"] } } } }, load: () => Promise.resolve().then(() => (init_src4(), exports_src4)) },
|
|
32631
33777
|
{ id: "hello", manifest: { id: "hello", version: "0.1.0", pluginApi: "^0.2.0", description: "Proves the bundled plugin boot path without contributing a provider.", contributions: {}, enabledByDefault: false }, load: () => Promise.resolve().then(() => exports_src5) },
|
|
32632
|
-
{ id: "
|
|
32633
|
-
{ id: "
|
|
32634
|
-
{ id: "model-
|
|
32635
|
-
{ id: "
|
|
32636
|
-
{ id: "
|
|
33778
|
+
{ id: "internal-tracker", manifest: { id: "internal-tracker", version: "0.1.0", pluginApi: "^0.3.0", enabledByDefault: true, description: "Keep project tickets in the daemon event log, without credentials.", contributions: { tracker: { internal: { config: { type: "object", additionalProperties: false }, secrets: [] } } } }, load: () => Promise.resolve().then(() => (init_src5(), exports_src6)) },
|
|
33779
|
+
{ id: "linear", manifest: { id: "linear", version: "0.1.0", pluginApi: "^0.2.0", enabledByDefault: true, description: "Read Linear observations into the fleet event log.", contributions: { tracker: { linear: { config: { type: "object", properties: { projects: { type: "object", additionalProperties: { type: "object", properties: { programRoot: { type: "string", minLength: 1 }, phaseGroup: { type: "string", minLength: 1 }, runtimeGroup: { type: "string", minLength: 1 }, readyLabel: { type: "string", minLength: 1 } }, required: ["programRoot"], additionalProperties: false } }, endpoint: { type: "string" }, quotaProjects: { type: "array", items: { type: "string" } } }, additionalProperties: false }, secrets: ["LINEAR_API_KEY"] } } } }, load: () => Promise.resolve().then(() => (init_src6(), exports_src7)) },
|
|
33780
|
+
{ id: "model-anthropic", manifest: { id: "model-anthropic", version: "0.1.0", pluginApi: "^0.2.0", enabledByDefault: true, description: "Anthropic models for the coordinator.", contributions: { model: { anthropic: { description: "Anthropic", config: { type: "object", properties: { model: { type: "string", minLength: 1 }, baseURL: { type: "string", minLength: 1 }, apiKeySecret: { type: "string", enum: ["ANTHROPIC_API_KEY", "ARMADA_MODEL_API_KEY"] } }, additionalProperties: false }, secrets: ["ANTHROPIC_API_KEY", "ARMADA_MODEL_API_KEY"] } } } }, load: () => Promise.resolve().then(() => (init_src7(), exports_src8)) },
|
|
33781
|
+
{ id: "model-openai-compatible", manifest: { id: "model-openai-compatible", version: "0.1.0", pluginApi: "^0.2.0", enabledByDefault: true, description: "OpenAI-compatible endpoints models for the coordinator.", contributions: { model: { "openai-compatible": { description: "OpenAI compatible", config: { type: "object", properties: { model: { type: "string", minLength: 1 }, baseURL: { type: "string", minLength: 1 }, apiKeySecret: { type: ["string", "null"], enum: ["OPENAI_API_KEY", "ARMADA_MODEL_API_KEY", "ZAI_API_KEY", "AZURE_AI_API_KEY", null] }, apiKeyHeader: { type: "string", enum: ["authorization", "api-key"] }, supportsStructuredOutputs: { type: "boolean" } }, additionalProperties: false }, secrets: ["OPENAI_API_KEY", "ARMADA_MODEL_API_KEY", "ZAI_API_KEY", "AZURE_AI_API_KEY"] } } } }, load: () => Promise.resolve().then(() => (init_src8(), exports_src9)) },
|
|
33782
|
+
{ id: "node-local", manifest: { id: "node-local", version: "0.1.0", pluginApi: "^0.2.0", enabledByDefault: true, description: "Prepares local git worktrees and runs workers as local processes.", contributions: { node: { local: { config: { type: "object", properties: { workspaceRoot: { type: "string", minLength: 1 }, projects: { type: "object", additionalProperties: { type: "object", required: ["root"], properties: { root: { type: "string", minLength: 1 } }, additionalProperties: false } }, transport: { enum: ["auto", "pipe", "pty"] }, outputTail: { type: "integer", minimum: 1 }, stopTimeoutMs: { type: "integer", minimum: 1 }, killTimeoutMs: { type: "integer", minimum: 1 } }, additionalProperties: false }, secrets: [] } } } }, load: () => Promise.resolve().then(() => (init_src9(), exports_src10)) },
|
|
33783
|
+
{ id: "opencode", manifest: { id: "opencode", version: "0.1.0", pluginApi: "^0.2.0", description: "Run the official opencode CLI using host-selected node facilities.", enabledByDefault: true, contributions: { runtime: { opencode: { config: { type: "object", properties: { command: { type: "string", minLength: 1 }, model: { type: "string", minLength: 1 }, effort: { type: "string", minLength: 1 }, extraArgs: { type: "array", items: { type: "string" } }, binary: { type: "string", minLength: 1 }, permissionMode: { type: "string", enum: ["allow", "ask", "deny", "default"], default: "allow", description: "Worker permission mode. Applies after restarting Armada; explicit runtime arguments take precedence." } }, additionalProperties: false }, secrets: [] } } } }, load: () => Promise.resolve().then(() => (init_src10(), exports_src11)) }
|
|
32637
33784
|
];
|
|
32638
33785
|
});
|
|
32639
33786
|
|
|
@@ -41161,6 +42308,9 @@ function validateConfig(manifest, config, defaults) {
|
|
|
41161
42308
|
...saved,
|
|
41162
42309
|
...base.projects && {
|
|
41163
42310
|
projects: base.projects
|
|
42311
|
+
},
|
|
42312
|
+
...base.quotaProjects && {
|
|
42313
|
+
quotaProjects: base.quotaProjects
|
|
41164
42314
|
}
|
|
41165
42315
|
} : saved;
|
|
41166
42316
|
validateContribution(contribution.config, seam, kind, value);
|
|
@@ -41203,7 +42353,7 @@ async function loadPlugins(services, configPath = appConfigPath(), catalog = BUN
|
|
|
41203
42353
|
throw new Error(`invalid plugin version ${manifest.version}`);
|
|
41204
42354
|
if (!import_semver.validRange(manifest.pluginApi))
|
|
41205
42355
|
throw new Error(`invalid pluginApi range ${manifest.pluginApi}`);
|
|
41206
|
-
if (!import_semver.satisfies(
|
|
42356
|
+
if (![PLUGIN_API_VERSION, "0.2.0"].some((version) => import_semver.satisfies(version, manifest.pluginApi)))
|
|
41207
42357
|
throw new Error(`pluginApi ${manifest.pluginApi} excludes daemon Plugin API ${PLUGIN_API_VERSION}`);
|
|
41208
42358
|
const config = validateConfig(manifest, setting?.config ?? {}, defaults);
|
|
41209
42359
|
const declared = new Set(SEAMS.flatMap((seam) => Object.values(manifest.contributions[seam] ?? {}).flatMap((c) => c.secrets)));
|
|
@@ -41942,6 +43092,66 @@ var init_status5 = __esm(() => {
|
|
|
41942
43092
|
init_list();
|
|
41943
43093
|
});
|
|
41944
43094
|
|
|
43095
|
+
// ../daemon/src/merge/refusal.ts
|
|
43096
|
+
var init_refusal = () => {};
|
|
43097
|
+
// ../daemon/coordinator/follow-ups.ts
|
|
43098
|
+
function sameFollowUpAction(a, b) {
|
|
43099
|
+
return !!a && !!b && a.capability === b.capability && a.reason === b.reason && (a.fix ?? a.next) === (b.fix ?? b.next);
|
|
43100
|
+
}
|
|
43101
|
+
function recoverFollowUps(inbox, event, sessions) {
|
|
43102
|
+
for (const [id, item] of inbox) {
|
|
43103
|
+
const f = item.followUp;
|
|
43104
|
+
const current = sessions.get(item.ticket);
|
|
43105
|
+
if (item.kind !== "follow-up" || !f || event.seq <= item.seq)
|
|
43106
|
+
continue;
|
|
43107
|
+
let recovered = event.kind === "merge.confirmed" && event.payload.ticket === item.ticket && (!f.session || event.payload.session === f.session) && (f.pr === undefined || event.payload.pr === f.pr) && (!f.head || f.code === "branch_update" || event.payload.head === f.head) && current?.phase === "merged";
|
|
43108
|
+
if (f.code === "delivery_failed") {
|
|
43109
|
+
recovered ||= (event.kind === "delivery.sent" || event.kind === "delivery.failed" && event.payload.nextAt === null) && event.payload.id === f.args?.delivery;
|
|
43110
|
+
recovered ||= event.kind === "session.released" && event.payload.ticket === item.ticket && event.payload.session === f.session;
|
|
43111
|
+
}
|
|
43112
|
+
if (event.kind === "pull-request.seen")
|
|
43113
|
+
recovered = event.payload.number === f.pr && (event.payload.state === "merged" || f.code !== "branch_update" && !!f.head && event.payload.head !== f.head);
|
|
43114
|
+
if (f.code === "branch_update" && (event.kind === "pull-request.closed" || event.kind === "pull-request.merged"))
|
|
43115
|
+
recovered = event.payload.number === f.pr;
|
|
43116
|
+
if (event.kind === "ticket.seen" && event.payload.id === item.ticket && f.readyToMerge)
|
|
43117
|
+
recovered = current ? current.session === f.session && current.phase !== "ready-to-merge" : !!f.session?.startsWith("tracker:");
|
|
43118
|
+
if (event.kind === "session.reported" && event.payload.ticket === item.ticket && f.readyToMerge)
|
|
43119
|
+
recovered = !!current && current.session === f.session && current.phase !== "ready-to-merge";
|
|
43120
|
+
if (event.kind === "session.claimed" && event.payload.ticket === item.ticket)
|
|
43121
|
+
recovered = current?.session === event.payload.session && current.generation > (f.generation ?? -1);
|
|
43122
|
+
if (event.kind === "session.released" && event.payload.ticket === item.ticket && f.readyToMerge)
|
|
43123
|
+
recovered = !!current && current.session === f.session && current.phase === "released";
|
|
43124
|
+
if (event.kind === "coordinator.checkpoint") {
|
|
43125
|
+
const c = event.payload.checkpoint;
|
|
43126
|
+
if (c && typeof c === "object" && !Array.isArray(c) && c.format === "armada.worker" && c.version === 1 && c.type === "launch" && current?.session === c.session && c.ticket === item.ticket && typeof c.generation === "number" && c.generation > (f.generation ?? -1))
|
|
43127
|
+
recovered = true;
|
|
43128
|
+
}
|
|
43129
|
+
const availability = readProviders(event);
|
|
43130
|
+
if (availability)
|
|
43131
|
+
recovered = availability.providers.some((v) => f.plugin && v.id === f.plugin && v.enabled || f.capability && v.capabilities.includes(f.capability) && v.loaded);
|
|
43132
|
+
if (recovered)
|
|
43133
|
+
inbox.delete(id);
|
|
43134
|
+
}
|
|
43135
|
+
}
|
|
43136
|
+
function readProviders(event) {
|
|
43137
|
+
if (event.kind !== "coordinator.checkpoint")
|
|
43138
|
+
return;
|
|
43139
|
+
const parsed = providersSchema.safeParse(event.payload.checkpoint);
|
|
43140
|
+
return parsed.success ? parsed.data : undefined;
|
|
43141
|
+
}
|
|
43142
|
+
var providersSchema;
|
|
43143
|
+
var init_follow_ups = __esm(() => {
|
|
43144
|
+
init_zod();
|
|
43145
|
+
init_fold();
|
|
43146
|
+
init_refusal();
|
|
43147
|
+
providersSchema = object({
|
|
43148
|
+
format: literal("armada.tools"),
|
|
43149
|
+
version: literal(1),
|
|
43150
|
+
type: literal("providers"),
|
|
43151
|
+
providers: array(object({ id: string2(), enabled: boolean2(), loaded: boolean2(), capabilities: array(string2()) }))
|
|
43152
|
+
});
|
|
43153
|
+
});
|
|
43154
|
+
|
|
41945
43155
|
// ../../node_modules/.bun/typebox@1.3.27/node_modules/typebox/build/system/memory/metrics.mjs
|
|
41946
43156
|
var Metrics;
|
|
41947
43157
|
var init_metrics = __esm(() => {
|
|
@@ -44854,6 +46064,8 @@ function checkpointRules(checkpoint) {
|
|
|
44854
46064
|
return null;
|
|
44855
46065
|
if (c.version !== 1)
|
|
44856
46066
|
throw new Error("Unsupported native tools checkpoint");
|
|
46067
|
+
if (c.type === "wake-evidence" || c.type === "providers")
|
|
46068
|
+
return null;
|
|
44857
46069
|
const state = rulesStateSchema.safeParse(c.rules);
|
|
44858
46070
|
if (c.type !== "rules" || !state.success || state.data.revision < 1)
|
|
44859
46071
|
throw new Error("Invalid native tools checkpoint");
|
|
@@ -44892,6 +46104,7 @@ function applyDelivery(deliveries, e) {
|
|
|
44892
46104
|
}
|
|
44893
46105
|
}
|
|
44894
46106
|
}
|
|
46107
|
+
var deliveryFollowUpId = (id) => `follow-up:delivery:${id}`;
|
|
44895
46108
|
|
|
44896
46109
|
// ../daemon/src/rules.ts
|
|
44897
46110
|
function flowStep(phase, stage, pr, earlier) {
|
|
@@ -44959,8 +46172,8 @@ function normalizeUsage(raw, model, provider) {
|
|
|
44959
46172
|
if (!raw || typeof raw !== "object")
|
|
44960
46173
|
return "unknown";
|
|
44961
46174
|
const u = raw;
|
|
44962
|
-
const result = Object.fromEntries(
|
|
44963
|
-
if (
|
|
46175
|
+
const result = Object.fromEntries(fields3.map((k) => [k, Number.isSafeInteger(u[k]) && u[k] >= 0 ? u[k] : null]));
|
|
46176
|
+
if (fields3.every((k) => result[k] === null))
|
|
44964
46177
|
return "unknown";
|
|
44965
46178
|
return {
|
|
44966
46179
|
...result,
|
|
@@ -44975,18 +46188,18 @@ function modelUsage(message) {
|
|
|
44975
46188
|
if (m?.api === "armada-ai-sdk")
|
|
44976
46189
|
return "unknown";
|
|
44977
46190
|
const usage = normalizeUsage(m?.usage, m?.model, m?.provider);
|
|
44978
|
-
return usage !== "unknown" &&
|
|
46191
|
+
return usage !== "unknown" && fields3.every((key) => usage[key] === 0) ? "unknown" : usage;
|
|
44979
46192
|
}
|
|
44980
46193
|
function add(total, usage) {
|
|
44981
46194
|
if (usage === "unknown") {
|
|
44982
46195
|
total.unknown++;
|
|
44983
46196
|
return;
|
|
44984
46197
|
}
|
|
44985
|
-
if (
|
|
46198
|
+
if (fields3.some((k) => usage[k] !== null))
|
|
44986
46199
|
total.reported++;
|
|
44987
|
-
if (usage.incomplete ||
|
|
46200
|
+
if (usage.incomplete || fields3.some((k) => usage[k] === null))
|
|
44988
46201
|
total.unknown++;
|
|
44989
|
-
for (const k of
|
|
46202
|
+
for (const k of fields3)
|
|
44990
46203
|
if (usage[k] !== null)
|
|
44991
46204
|
total[k] = (total[k] ?? 0) + usage[k];
|
|
44992
46205
|
if (usage.model && !total.models.includes(usage.model))
|
|
@@ -45040,9 +46253,9 @@ function checkpointUsage(checkpoint, documents) {
|
|
|
45040
46253
|
continue;
|
|
45041
46254
|
const before = normalizeUsage(prior?.models[key], current.model, current.provider);
|
|
45042
46255
|
const delta = { ...current };
|
|
45043
|
-
for (const field of
|
|
46256
|
+
for (const field of fields3)
|
|
45044
46257
|
delta[field] = current[field] === null ? null : Math.max(0, current[field] - (before === "unknown" ? 0 : before[field] ?? 0));
|
|
45045
|
-
if (
|
|
46258
|
+
if (fields3.some((field) => (delta[field] ?? 0) > 0))
|
|
45046
46259
|
diffs.push(delta);
|
|
45047
46260
|
}
|
|
45048
46261
|
documents.set(id, { session, models });
|
|
@@ -45132,7 +46345,7 @@ function projectUsage(events, zone) {
|
|
|
45132
46345
|
const prior = previous.get(session);
|
|
45133
46346
|
const delta = { ...usage };
|
|
45134
46347
|
const cumulative = { ...usage };
|
|
45135
|
-
for (const k of
|
|
46348
|
+
for (const k of fields3) {
|
|
45136
46349
|
const amount = usage[k];
|
|
45137
46350
|
const floor = prior?.[k];
|
|
45138
46351
|
delta[k] = amount === null ? null : Math.max(0, amount - (floor ?? 0));
|
|
@@ -45145,11 +46358,11 @@ function projectUsage(events, zone) {
|
|
|
45145
46358
|
add(day.workers, delta);
|
|
45146
46359
|
row.totals = emptyTotals();
|
|
45147
46360
|
add(row.totals, cumulative);
|
|
45148
|
-
if (cumulative.incomplete ||
|
|
46361
|
+
if (cumulative.incomplete || fields3.some((k) => usage[k] === null))
|
|
45149
46362
|
row.totals.unknown = 1;
|
|
45150
46363
|
previous.set(session, cumulative);
|
|
45151
46364
|
const known = reported.get(day.day) ?? new Set;
|
|
45152
|
-
if (
|
|
46365
|
+
if (fields3.some((k) => usage[k] !== null))
|
|
45153
46366
|
known.add(session);
|
|
45154
46367
|
reported.set(day.day, known);
|
|
45155
46368
|
day.workersReported = known.size;
|
|
@@ -45158,7 +46371,7 @@ function projectUsage(events, zone) {
|
|
|
45158
46371
|
}
|
|
45159
46372
|
return { zone, days: [...days.values()], sessions: [...sessions.values()] };
|
|
45160
46373
|
}
|
|
45161
|
-
var
|
|
46374
|
+
var fields3, emptyTotals = () => ({
|
|
45162
46375
|
input: null,
|
|
45163
46376
|
output: null,
|
|
45164
46377
|
cacheRead: null,
|
|
@@ -45169,7 +46382,7 @@ var fields2, emptyTotals = () => ({
|
|
|
45169
46382
|
}), object8 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
45170
46383
|
var init_usage2 = __esm(() => {
|
|
45171
46384
|
init_usage_view();
|
|
45172
|
-
|
|
46385
|
+
fields3 = ["input", "output", "cacheRead", "cacheWrite"];
|
|
45173
46386
|
});
|
|
45174
46387
|
|
|
45175
46388
|
// ../daemon/src/fold.ts
|
|
@@ -45180,229 +46393,314 @@ function fold(events) {
|
|
|
45180
46393
|
if (!Number.isSafeInteger(source.seq) || source.seq <= seq)
|
|
45181
46394
|
throw new Error("events must have increasing positive sequence numbers");
|
|
45182
46395
|
seq = source.seq;
|
|
45183
|
-
|
|
45184
|
-
|
|
45185
|
-
|
|
45186
|
-
|
|
45187
|
-
|
|
45188
|
-
|
|
45189
|
-
|
|
45190
|
-
|
|
45191
|
-
|
|
45192
|
-
|
|
45193
|
-
|
|
45194
|
-
|
|
45195
|
-
|
|
45196
|
-
|
|
45197
|
-
|
|
45198
|
-
|
|
45199
|
-
|
|
45200
|
-
|
|
45201
|
-
|
|
45202
|
-
|
|
45203
|
-
runtime: "tracker",
|
|
45204
|
-
handle: "",
|
|
45205
|
-
phase: t.phase,
|
|
45206
|
-
reason: t.reason ?? t.phase,
|
|
45207
|
-
at: e.at,
|
|
45208
|
-
heartbeat: null,
|
|
45209
|
-
earlier: current ? [...current.earlier, current.phase] : []
|
|
45210
|
-
});
|
|
45211
|
-
else if (current)
|
|
45212
|
-
p.sessions.delete(t.id);
|
|
45213
|
-
}
|
|
45214
|
-
break;
|
|
46396
|
+
applyEvent(projects, source.kind === "coordinator.checkpoint" ? source : structuredClone(source));
|
|
46397
|
+
}
|
|
46398
|
+
return projectTables(projects, seq, events);
|
|
46399
|
+
}
|
|
46400
|
+
function applyEvent(projects, e) {
|
|
46401
|
+
let p = projects.get(e.project);
|
|
46402
|
+
if (!p) {
|
|
46403
|
+
p = empty();
|
|
46404
|
+
projects.set(e.project, p);
|
|
46405
|
+
}
|
|
46406
|
+
applyDelivery(p.deliveries, e);
|
|
46407
|
+
if (e.kind === "inbox.opened" && e.payload.followUp?.code === "delivery_failed")
|
|
46408
|
+
p.deliveryFollowUps.add(e.payload.id);
|
|
46409
|
+
switch (e.kind) {
|
|
46410
|
+
case "tracker.import-started":
|
|
46411
|
+
case "tracker.import-progress":
|
|
46412
|
+
case "tracker.import-ended": {
|
|
46413
|
+
if (e.kind === "tracker.import-started" || p.trackerImport?.id === e.payload.id) {
|
|
46414
|
+
const { source: _source, ...value } = e.payload;
|
|
46415
|
+
p.trackerImport = value;
|
|
45215
46416
|
}
|
|
45216
|
-
|
|
45217
|
-
|
|
45218
|
-
|
|
45219
|
-
|
|
45220
|
-
|
|
45221
|
-
case "pull-request.checks-red":
|
|
45222
|
-
case "pull-request.review-changed":
|
|
45223
|
-
case "pull-request.closed":
|
|
45224
|
-
case "pull-request.merged":
|
|
45225
|
-
case "pull-request.seen": {
|
|
45226
|
-
const priorHead = p.prs.get(e.payload.number)?.head ?? [...p.prs.values()].findLast((pr) => pr.ticket === e.payload.ticket)?.head;
|
|
45227
|
-
if (priorHead !== e.payload.head)
|
|
45228
|
-
clearProgressNotices(p, e.payload.ticket);
|
|
45229
|
-
if (e.payload.state === "merged" && p.prs.get(e.payload.number)?.state !== "merged")
|
|
45230
|
-
p.mergedAt.set(e.payload.number, { at: e.at, seq: e.seq });
|
|
45231
|
-
p.prs.delete(e.payload.number);
|
|
45232
|
-
p.prs.set(e.payload.number, { ...e.payload, conflicting: e.payload.state === "open" && e.payload.conflicting });
|
|
45233
|
-
break;
|
|
45234
|
-
}
|
|
45235
|
-
case "review-thread.opened":
|
|
45236
|
-
case "review-thread.resolved": {
|
|
45237
|
-
const pr = p.prs.get(e.payload.pr);
|
|
45238
|
-
if (pr)
|
|
45239
|
-
pr.unresolvedThreads = e.payload.unresolvedThreads;
|
|
46417
|
+
break;
|
|
46418
|
+
}
|
|
46419
|
+
case "ticket.seen": {
|
|
46420
|
+
const t = e.payload;
|
|
46421
|
+
if (p.internal.has(t.id))
|
|
45240
46422
|
break;
|
|
45241
|
-
|
|
45242
|
-
|
|
45243
|
-
|
|
45244
|
-
|
|
45245
|
-
if (
|
|
45246
|
-
p.sessions.set(
|
|
45247
|
-
|
|
45248
|
-
|
|
45249
|
-
|
|
45250
|
-
|
|
46423
|
+
p.tickets.set(t.id, t);
|
|
46424
|
+
const current = p.sessions.get(t.id);
|
|
46425
|
+
const trackerId = `tracker:${t.id}`;
|
|
46426
|
+
if (!current || current.session === trackerId) {
|
|
46427
|
+
if (t.phase)
|
|
46428
|
+
p.sessions.set(t.id, {
|
|
46429
|
+
ticket: t.id,
|
|
46430
|
+
session: trackerId,
|
|
46431
|
+
generation: 0,
|
|
46432
|
+
owner: t.owner ?? e.actor,
|
|
46433
|
+
runtime: "tracker",
|
|
46434
|
+
handle: "",
|
|
46435
|
+
phase: t.phase,
|
|
46436
|
+
reason: t.reason ?? t.phase,
|
|
45251
46437
|
at: e.at,
|
|
45252
46438
|
heartbeat: null,
|
|
45253
|
-
earlier: []
|
|
46439
|
+
earlier: current ? [...current.earlier, current.phase] : []
|
|
45254
46440
|
});
|
|
45255
|
-
if (
|
|
45256
|
-
|
|
45257
|
-
p.claims.add(e.payload.session);
|
|
45258
|
-
break;
|
|
45259
|
-
case "session.reported": {
|
|
45260
|
-
const s = active(p, e.payload);
|
|
45261
|
-
if (s) {
|
|
45262
|
-
if (s.phase !== e.payload.phase || s.reason.trim() !== e.payload.reason.trim())
|
|
45263
|
-
clearProgressNotices(p, e.payload.ticket);
|
|
45264
|
-
s.earlier.push(s.phase);
|
|
45265
|
-
s.phase = e.payload.phase;
|
|
45266
|
-
s.reason = e.payload.reason;
|
|
45267
|
-
s.at = e.at;
|
|
45268
|
-
if (e.payload.stage !== undefined)
|
|
45269
|
-
s.stage = e.payload.stage;
|
|
45270
|
-
}
|
|
45271
|
-
break;
|
|
46441
|
+
else if (current)
|
|
46442
|
+
p.sessions.delete(t.id);
|
|
45272
46443
|
}
|
|
45273
|
-
|
|
45274
|
-
|
|
45275
|
-
|
|
45276
|
-
|
|
45277
|
-
id: e.payload.id,
|
|
45278
|
-
ticket: s.ticket,
|
|
45279
|
-
kind: "liveness",
|
|
45280
|
-
actor: e.actor,
|
|
45281
|
-
at: e.at,
|
|
45282
|
-
seq: e.seq,
|
|
45283
|
-
body: `${s.ticket} ${e.payload.verdict}: ${e.payload.summary}; evidence: ${JSON.stringify(e.payload.evidence)}`
|
|
45284
|
-
});
|
|
45285
|
-
}
|
|
46444
|
+
break;
|
|
46445
|
+
}
|
|
46446
|
+
case "ticket.created": {
|
|
46447
|
+
if (p.internal.has(e.payload.id))
|
|
45286
46448
|
break;
|
|
45287
|
-
|
|
45288
|
-
|
|
45289
|
-
|
|
45290
|
-
|
|
45291
|
-
|
|
46449
|
+
p.internal.set(e.payload.id, e.payload);
|
|
46450
|
+
if (p.sessions.get(e.payload.id)?.session === `tracker:${e.payload.id}`)
|
|
46451
|
+
p.sessions.delete(e.payload.id);
|
|
46452
|
+
break;
|
|
46453
|
+
}
|
|
46454
|
+
case "ticket.edited": {
|
|
46455
|
+
const ticket = p.internal.get(e.payload.ticket);
|
|
46456
|
+
if (ticket)
|
|
46457
|
+
p.internal.set(ticket.id, { ...ticket, ...e.payload.patch });
|
|
46458
|
+
break;
|
|
46459
|
+
}
|
|
46460
|
+
case "ticket.commented": {
|
|
46461
|
+
if (!p.internal.has(e.payload.ticket))
|
|
45292
46462
|
break;
|
|
45293
|
-
|
|
45294
|
-
|
|
45295
|
-
|
|
45296
|
-
|
|
45297
|
-
|
|
46463
|
+
const comments = p.comments.get(e.payload.ticket) ?? new Map;
|
|
46464
|
+
if (!comments.has(e.payload.id))
|
|
46465
|
+
comments.set(e.payload.id, { body: e.payload.body, author: e.actor, at: e.at, seq: e.seq });
|
|
46466
|
+
p.comments.set(e.payload.ticket, comments);
|
|
46467
|
+
break;
|
|
46468
|
+
}
|
|
46469
|
+
case "pull-request.opened":
|
|
46470
|
+
case "pull-request.conflicting":
|
|
46471
|
+
case "pull-request.behind":
|
|
46472
|
+
case "pull-request.head-moved":
|
|
46473
|
+
case "pull-request.checks-green":
|
|
46474
|
+
case "pull-request.checks-red":
|
|
46475
|
+
case "pull-request.review-changed":
|
|
46476
|
+
case "pull-request.closed":
|
|
46477
|
+
case "pull-request.merged":
|
|
46478
|
+
case "pull-request.seen": {
|
|
46479
|
+
const priorHead = p.prs.get(e.payload.number)?.head ?? [...p.prs.values()].findLast((pr) => pr.ticket === e.payload.ticket)?.head;
|
|
46480
|
+
if (priorHead !== e.payload.head)
|
|
46481
|
+
clearProgressNotices(p, e.payload.ticket);
|
|
46482
|
+
if (e.payload.state === "merged" && p.prs.get(e.payload.number)?.state !== "merged")
|
|
46483
|
+
p.mergedAt.set(e.payload.number, { at: e.at, seq: e.seq });
|
|
46484
|
+
if (e.kind === "pull-request.merged" && e.payload.mergedAt) {
|
|
46485
|
+
const merged = p.mergedAt.get(e.payload.number) ?? { at: e.at, seq: e.seq };
|
|
46486
|
+
p.mergedAt.set(e.payload.number, { ...merged, at: e.payload.mergedAt });
|
|
46487
|
+
}
|
|
46488
|
+
p.prs.delete(e.payload.number);
|
|
46489
|
+
p.prs.set(e.payload.number, { ...e.payload, conflicting: e.payload.state === "open" && e.payload.conflicting });
|
|
46490
|
+
break;
|
|
46491
|
+
}
|
|
46492
|
+
case "review-thread.opened":
|
|
46493
|
+
case "review-thread.resolved": {
|
|
46494
|
+
const pr = p.prs.get(e.payload.pr);
|
|
46495
|
+
if (pr)
|
|
46496
|
+
pr.unresolvedThreads = e.payload.unresolvedThreads;
|
|
46497
|
+
break;
|
|
46498
|
+
}
|
|
46499
|
+
case "session.claimed":
|
|
46500
|
+
if (!Number.isSafeInteger(e.payload.generation) || e.payload.generation < 1)
|
|
46501
|
+
throw new Error("claim generation must be a positive safe integer");
|
|
46502
|
+
if (!p.claims.has(e.payload.session) && (e.payload.generation > (p.sessions.get(e.payload.ticket)?.generation ?? 0) || p.sessions.get(e.payload.ticket)?.session === e.payload.session && p.sessions.get(e.payload.ticket)?.claimSeq === undefined && !["released", "merged"].includes(p.sessions.get(e.payload.ticket)?.phase ?? "released")))
|
|
46503
|
+
p.sessions.set(e.payload.ticket, {
|
|
46504
|
+
...e.payload,
|
|
46505
|
+
claimSeq: e.seq,
|
|
46506
|
+
startedAt: p.sessions.get(e.payload.ticket)?.session === e.payload.session ? p.sessions.get(e.payload.ticket)?.startedAt ?? e.at : e.at,
|
|
46507
|
+
phase: "planning",
|
|
46508
|
+
reason: "Claimed",
|
|
46509
|
+
at: e.at,
|
|
46510
|
+
heartbeat: null,
|
|
46511
|
+
earlier: []
|
|
46512
|
+
});
|
|
46513
|
+
if (!p.claims.has(e.payload.session) && p.sessions.get(e.payload.ticket)?.session === e.payload.session)
|
|
46514
|
+
clearProgressNotices(p, e.payload.ticket);
|
|
46515
|
+
p.claims.add(e.payload.session);
|
|
46516
|
+
break;
|
|
46517
|
+
case "session.reported": {
|
|
46518
|
+
const s = active(p, e.payload);
|
|
46519
|
+
if (s) {
|
|
46520
|
+
if (s.phase !== e.payload.phase || s.reason.trim() !== e.payload.reason.trim())
|
|
45298
46521
|
clearProgressNotices(p, e.payload.ticket);
|
|
45299
|
-
|
|
45300
|
-
|
|
45301
|
-
|
|
45302
|
-
|
|
45303
|
-
|
|
46522
|
+
s.earlier.push(s.phase);
|
|
46523
|
+
s.phase = e.payload.phase;
|
|
46524
|
+
s.reason = e.payload.reason;
|
|
46525
|
+
s.at = e.at;
|
|
46526
|
+
if (e.payload.stage !== undefined)
|
|
46527
|
+
s.stage = e.payload.stage;
|
|
45304
46528
|
}
|
|
45305
|
-
|
|
45306
|
-
|
|
45307
|
-
|
|
45308
|
-
|
|
45309
|
-
|
|
45310
|
-
p.inbox.
|
|
45311
|
-
|
|
45312
|
-
|
|
45313
|
-
|
|
45314
|
-
|
|
45315
|
-
|
|
45316
|
-
|
|
45317
|
-
|
|
45318
|
-
|
|
45319
|
-
q.state = "running";
|
|
45320
|
-
break;
|
|
46529
|
+
break;
|
|
46530
|
+
}
|
|
46531
|
+
case "session.liveness": {
|
|
46532
|
+
const s = active(p, e.payload);
|
|
46533
|
+
if (s && s.generation === e.payload.generation && !["blocked", "awaiting-approval", "awaiting-validation", "ready-to-merge"].includes(s.phase)) {
|
|
46534
|
+
p.inbox.set(e.payload.id, {
|
|
46535
|
+
id: e.payload.id,
|
|
46536
|
+
ticket: s.ticket,
|
|
46537
|
+
kind: "liveness",
|
|
46538
|
+
actor: e.actor,
|
|
46539
|
+
at: e.at,
|
|
46540
|
+
seq: e.seq,
|
|
46541
|
+
body: `${s.ticket} ${e.payload.verdict}: ${e.payload.summary}; evidence: ${JSON.stringify(e.payload.evidence)}`
|
|
46542
|
+
});
|
|
45321
46543
|
}
|
|
45322
|
-
|
|
45323
|
-
|
|
45324
|
-
|
|
45325
|
-
|
|
45326
|
-
|
|
45327
|
-
|
|
45328
|
-
|
|
45329
|
-
|
|
45330
|
-
|
|
45331
|
-
|
|
45332
|
-
|
|
45333
|
-
|
|
45334
|
-
|
|
45335
|
-
|
|
45336
|
-
|
|
45337
|
-
|
|
45338
|
-
}
|
|
45339
|
-
break;
|
|
46544
|
+
break;
|
|
46545
|
+
}
|
|
46546
|
+
case "session.heartbeat": {
|
|
46547
|
+
const s = active(p, e.payload);
|
|
46548
|
+
if (s)
|
|
46549
|
+
s.heartbeat = e.at;
|
|
46550
|
+
break;
|
|
46551
|
+
}
|
|
46552
|
+
case "session.released": {
|
|
46553
|
+
const s = active(p, e.payload);
|
|
46554
|
+
if (s) {
|
|
46555
|
+
s.earlier.push(s.phase);
|
|
46556
|
+
clearProgressNotices(p, e.payload.ticket);
|
|
46557
|
+
s.phase = "released";
|
|
46558
|
+
s.reason = e.payload.reason;
|
|
46559
|
+
s.at = e.at;
|
|
45340
46560
|
}
|
|
45341
|
-
|
|
45342
|
-
|
|
45343
|
-
|
|
45344
|
-
|
|
45345
|
-
|
|
45346
|
-
|
|
45347
|
-
|
|
45348
|
-
|
|
45349
|
-
|
|
45350
|
-
|
|
45351
|
-
|
|
45352
|
-
|
|
45353
|
-
|
|
45354
|
-
|
|
45355
|
-
|
|
45356
|
-
|
|
46561
|
+
break;
|
|
46562
|
+
}
|
|
46563
|
+
case "inbox.opened": {
|
|
46564
|
+
const prior = p.inbox.get(e.payload.id);
|
|
46565
|
+
if (!prior || e.payload.kind === "follow-up" && prior.kind === "follow-up") {
|
|
46566
|
+
const changedAction = prior?.followUp && e.payload.followUp && !sameFollowUpAction(prior.followUp, e.payload.followUp);
|
|
46567
|
+
let followUp = e.payload.followUp;
|
|
46568
|
+
if (followUp && changedAction) {
|
|
46569
|
+
const { toldOwnerAt: _oldReceipt, ...detail } = followUp;
|
|
46570
|
+
followUp = detail;
|
|
46571
|
+
} else if (followUp && prior?.followUp?.toldOwnerAt)
|
|
46572
|
+
followUp = { ...followUp, toldOwnerAt: prior.followUp.toldOwnerAt };
|
|
46573
|
+
p.inbox.set(e.payload.id, {
|
|
46574
|
+
...e.payload,
|
|
46575
|
+
...followUp ? { followUp } : {},
|
|
46576
|
+
at: changedAction ? e.at : prior?.at ?? e.at,
|
|
46577
|
+
actor: e.actor,
|
|
46578
|
+
seq: e.seq
|
|
46579
|
+
});
|
|
45357
46580
|
}
|
|
45358
|
-
|
|
45359
|
-
|
|
45360
|
-
|
|
45361
|
-
|
|
45362
|
-
|
|
45363
|
-
|
|
45364
|
-
|
|
45365
|
-
|
|
45366
|
-
|
|
45367
|
-
|
|
45368
|
-
|
|
45369
|
-
|
|
45370
|
-
|
|
45371
|
-
|
|
45372
|
-
|
|
45373
|
-
|
|
45374
|
-
|
|
45375
|
-
|
|
45376
|
-
|
|
45377
|
-
|
|
45378
|
-
|
|
45379
|
-
|
|
45380
|
-
launched: "Launched; waiting for worker claim"
|
|
45381
|
-
}[l.step]
|
|
45382
|
-
});
|
|
45383
|
-
}
|
|
45384
|
-
const usage = linearUsageCheckpoint.safeParse(e.payload.checkpoint);
|
|
45385
|
-
if (usage.success)
|
|
45386
|
-
p.readers.linear = usage.data.usage;
|
|
45387
|
-
const reading = readerCheckpoint.safeParse(e.payload.checkpoint);
|
|
45388
|
-
if (reading.success && !reading.data.failures && Number.isFinite(Date.parse(e.at)))
|
|
45389
|
-
p.readAt[reading.data.provider] = e.at;
|
|
45390
|
-
const rules = checkpointRules(e.payload.checkpoint);
|
|
45391
|
-
if (rules)
|
|
45392
|
-
p.rules = rules;
|
|
46581
|
+
break;
|
|
46582
|
+
}
|
|
46583
|
+
case "inbox.answered":
|
|
46584
|
+
p.inbox.delete(e.payload.id);
|
|
46585
|
+
break;
|
|
46586
|
+
case "merge.queued":
|
|
46587
|
+
if (!p.queue.has(e.payload.id))
|
|
46588
|
+
p.queue.set(e.payload.id, { ...e.payload, at: e.at, seq: e.seq, state: "queued" });
|
|
46589
|
+
break;
|
|
46590
|
+
case "merge.started": {
|
|
46591
|
+
const q = p.queue.get(e.payload.id);
|
|
46592
|
+
if (q)
|
|
46593
|
+
q.state = "running";
|
|
46594
|
+
break;
|
|
46595
|
+
}
|
|
46596
|
+
case "merge.refused":
|
|
46597
|
+
case "merge.canceled":
|
|
46598
|
+
p.queue.delete(e.payload.id);
|
|
46599
|
+
break;
|
|
46600
|
+
case "merge.confirmed": {
|
|
46601
|
+
const q = p.queue.get(e.payload.id);
|
|
46602
|
+
if (q && (q.head !== e.payload.head || q.pr !== e.payload.pr || q.session !== e.payload.session || q.ticket !== e.payload.ticket))
|
|
45393
46603
|
break;
|
|
46604
|
+
p.queue.delete(e.payload.id);
|
|
46605
|
+
const s = active(p, e.payload);
|
|
46606
|
+
if (s) {
|
|
46607
|
+
s.earlier.push(s.phase);
|
|
46608
|
+
clearProgressNotices(p, e.payload.ticket);
|
|
46609
|
+
s.phase = "merged";
|
|
46610
|
+
s.reason = `Merged #${e.payload.pr}`;
|
|
46611
|
+
s.at = e.at;
|
|
45394
46612
|
}
|
|
45395
|
-
|
|
45396
|
-
|
|
45397
|
-
|
|
45398
|
-
|
|
45399
|
-
|
|
46613
|
+
break;
|
|
46614
|
+
}
|
|
46615
|
+
case "hold.opened":
|
|
46616
|
+
if (!p.holds.has(e.payload.id))
|
|
46617
|
+
p.holds.set(e.payload.id, { ...e.payload, at: e.at, actor: e.actor });
|
|
46618
|
+
break;
|
|
46619
|
+
case "hold.cleared":
|
|
46620
|
+
p.holds.delete(e.payload.id);
|
|
46621
|
+
break;
|
|
46622
|
+
case "validation.opened":
|
|
46623
|
+
if (!p.validations.has(e.payload.id))
|
|
46624
|
+
p.validations.set(e.payload.id, { ...e.payload, at: e.at, actor: e.actor, decision: null });
|
|
46625
|
+
break;
|
|
46626
|
+
case "validation.decided": {
|
|
46627
|
+
const v = p.validations.get(e.payload.id);
|
|
46628
|
+
if (v && !v.decision)
|
|
46629
|
+
v.decision = { decision: e.payload.decision, note: e.payload.note, at: e.at, actor: e.actor };
|
|
46630
|
+
break;
|
|
45400
46631
|
}
|
|
46632
|
+
case "coordinator.checkpoint": {
|
|
46633
|
+
const checkpoint = e.payload.checkpoint;
|
|
46634
|
+
const format = checkpoint && typeof checkpoint === "object" && !Array.isArray(checkpoint) ? checkpoint.format : undefined;
|
|
46635
|
+
const launch = format === "armada.worker" ? workerLaunchCheckpointSchema.safeParse(checkpoint) : null;
|
|
46636
|
+
if (launch?.success) {
|
|
46637
|
+
const l = launch.data;
|
|
46638
|
+
const current = p.sessions.get(l.ticket);
|
|
46639
|
+
if ((!current || l.generation > current.generation || current.session === l.session && !["released", "merged"].includes(current.phase)) && !p.claims.has(l.session))
|
|
46640
|
+
p.sessions.set(l.ticket, {
|
|
46641
|
+
ticket: l.ticket,
|
|
46642
|
+
launchSeq: current?.session === l.session ? current.launchSeq : e.seq,
|
|
46643
|
+
startedAt: current?.session === l.session ? current.startedAt : e.at,
|
|
46644
|
+
session: l.session,
|
|
46645
|
+
generation: l.generation,
|
|
46646
|
+
runtime: l.runtime,
|
|
46647
|
+
handle: l.handle ?? "",
|
|
46648
|
+
owner: e.actor,
|
|
46649
|
+
phase: "planning",
|
|
46650
|
+
at: e.at,
|
|
46651
|
+
heartbeat: null,
|
|
46652
|
+
earlier: [],
|
|
46653
|
+
reason: {
|
|
46654
|
+
preparing: "Preparing workspace",
|
|
46655
|
+
starting: "Starting worker CLI",
|
|
46656
|
+
launched: "Launched; waiting for worker claim"
|
|
46657
|
+
}[l.step]
|
|
46658
|
+
});
|
|
46659
|
+
}
|
|
46660
|
+
const usage = format === "armada.linear-reader" ? linearUsageCheckpoint.safeParse(checkpoint) : null;
|
|
46661
|
+
if (usage?.success)
|
|
46662
|
+
p.readers.linear = usage.data.usage;
|
|
46663
|
+
const reading = format === "armada.readers" ? readerCheckpoint.safeParse(checkpoint) : null;
|
|
46664
|
+
if (reading?.success && !reading.data.failures && Number.isFinite(Date.parse(e.at)))
|
|
46665
|
+
p.readAt[reading.data.provider] = e.at;
|
|
46666
|
+
const rules = checkpointRules(e.payload.checkpoint);
|
|
46667
|
+
if (rules)
|
|
46668
|
+
p.rules = rules;
|
|
46669
|
+
break;
|
|
46670
|
+
}
|
|
46671
|
+
case "coordinator.message":
|
|
46672
|
+
break;
|
|
46673
|
+
case "default-branch.seen":
|
|
46674
|
+
p.defaultBranch = e.payload;
|
|
46675
|
+
break;
|
|
45401
46676
|
}
|
|
46677
|
+
recoverFollowUps(p.inbox, e, p.sessions);
|
|
46678
|
+
}
|
|
46679
|
+
function projectTables(projects, seq, events) {
|
|
45402
46680
|
const tables = { seq, projects: Object.create(null) };
|
|
45403
46681
|
for (const [project, p] of projects) {
|
|
46682
|
+
for (const t of p.internal.values()) {
|
|
46683
|
+
const labelPhase = t.labels.map((label) => phaseSchema.safeParse(label)).find((result) => result.success)?.data ?? null;
|
|
46684
|
+
const phase = t.state === "completed" ? "merged" : t.state === "canceled" ? "released" : labelPhase;
|
|
46685
|
+
p.tickets.set(t.id, {
|
|
46686
|
+
id: t.id,
|
|
46687
|
+
title: t.title,
|
|
46688
|
+
description: t.description,
|
|
46689
|
+
labels: t.labels,
|
|
46690
|
+
status: t.state,
|
|
46691
|
+
phase,
|
|
46692
|
+
parent: t.parent,
|
|
46693
|
+
...t.url !== undefined ? { url: t.url } : {},
|
|
46694
|
+
...t.source !== undefined ? { source: t.source } : {},
|
|
46695
|
+
blockers: t.blockers.map((id) => ({
|
|
46696
|
+
id,
|
|
46697
|
+
status: p.internal.get(id)?.state ?? p.tickets.get(id)?.status ?? "unstarted"
|
|
46698
|
+
})),
|
|
46699
|
+
comments: [...p.comments.get(t.id)?.values() ?? []].sort((a, b) => Date.parse(b.at) - Date.parse(a.at) || b.seq - a.seq).slice(0, 12).map(({ body, author, at }) => ({ body, author, at }))
|
|
46700
|
+
});
|
|
46701
|
+
}
|
|
45404
46702
|
const sessions = [...p.sessions.values()].map((s) => {
|
|
45405
|
-
const pr = [...p.prs.values()].reverse().find((pr) => pr.ticket === s.ticket && pr.state !== "closed" && !(pr.state === "merged" && (s.claimSeq ?? s.launchSeq) !== undefined && (p.mergedAt.get(pr.number)?.seq ?? 0) < (s.claimSeq ?? s.launchSeq ?? 0)));
|
|
46703
|
+
const pr = [...p.prs.values()].reverse().find((pr) => pr.ticket === s.ticket && pr.state !== "closed" && !(pr.state === "merged" && (s.claimSeq ?? s.launchSeq) !== undefined && ((p.mergedAt.get(pr.number)?.seq ?? 0) < (s.claimSeq ?? s.launchSeq ?? 0) || s.startedAt !== undefined && Date.parse(p.mergedAt.get(pr.number)?.at ?? "") < Date.parse(s.startedAt))));
|
|
45406
46704
|
const validation = [...p.validations.values()].find((v) => v.ticket === s.ticket && v.session === s.session && !v.decision);
|
|
45407
46705
|
const decision = [...p.validations.values()].reverse().find((v) => v.ticket === s.ticket && v.session === s.session)?.decision;
|
|
45408
46706
|
const question = [...p.inbox.values()].find((i) => i.ticket === s.ticket && i.kind === "question");
|
|
@@ -45457,7 +46755,7 @@ function fold(events) {
|
|
|
45457
46755
|
const deliveries = [...p.deliveries.values()].filter((d) => !d.sentAt && sessions.some((s) => s.ticket === d.ticket && s.session === d.session && s.generation === d.generation && !["released", "merged"].includes(s.phase)));
|
|
45458
46756
|
const failures = deliveries.flatMap((d) => {
|
|
45459
46757
|
const session = sessions.find((s) => s.ticket === d.ticket && s.session === d.session && s.generation === d.generation);
|
|
45460
|
-
return d.failureSeq !== undefined && session && !["released", "merged"].includes(session.phase) ? [
|
|
46758
|
+
return d.failureSeq !== undefined && !p.deliveryFollowUps.has(deliveryFollowUpId(d.id)) && session && !["released", "merged"].includes(session.phase) ? [
|
|
45461
46759
|
{
|
|
45462
46760
|
id: `delivery:${d.id}`,
|
|
45463
46761
|
ticket: d.ticket,
|
|
@@ -45472,6 +46770,7 @@ function fold(events) {
|
|
|
45472
46770
|
tables.projects[project] = {
|
|
45473
46771
|
...p.defaultBranch ? { defaultBranch: p.defaultBranch } : {},
|
|
45474
46772
|
rules: p.rules,
|
|
46773
|
+
...p.trackerImport ? { trackerImport: p.trackerImport } : {},
|
|
45475
46774
|
...usage.days.length ? { usage } : {},
|
|
45476
46775
|
...Object.keys(p.readers).length ? { readers: p.readers } : {},
|
|
45477
46776
|
...Object.keys(p.readAt).length ? { readAt: p.readAt } : {},
|
|
@@ -45493,6 +46792,8 @@ var linearUsageCheckpoint, readerCheckpoint, empty = () => ({
|
|
|
45493
46792
|
readAt: Object.create(null),
|
|
45494
46793
|
readers: Object.create(null),
|
|
45495
46794
|
tickets: new Map,
|
|
46795
|
+
internal: new Map,
|
|
46796
|
+
comments: new Map,
|
|
45496
46797
|
prs: new Map,
|
|
45497
46798
|
mergedAt: new Map,
|
|
45498
46799
|
sessions: new Map,
|
|
@@ -45501,7 +46802,8 @@ var linearUsageCheckpoint, readerCheckpoint, empty = () => ({
|
|
|
45501
46802
|
queue: new Map,
|
|
45502
46803
|
holds: new Map,
|
|
45503
46804
|
validations: new Map,
|
|
45504
|
-
deliveries: new Map
|
|
46805
|
+
deliveries: new Map,
|
|
46806
|
+
deliveryFollowUps: new Set
|
|
45505
46807
|
}), active = (p, ref) => {
|
|
45506
46808
|
const session = p.sessions.get(ref.ticket);
|
|
45507
46809
|
return session?.session === ref.session && session.phase !== "released" && session.phase !== "merged" ? session : undefined;
|
|
@@ -45513,6 +46815,7 @@ var linearUsageCheckpoint, readerCheckpoint, empty = () => ({
|
|
|
45513
46815
|
var init_fold = __esm(() => {
|
|
45514
46816
|
init_dist2();
|
|
45515
46817
|
init_zod();
|
|
46818
|
+
init_follow_ups();
|
|
45516
46819
|
init_rules2();
|
|
45517
46820
|
init_rules3();
|
|
45518
46821
|
init_usage2();
|
|
@@ -45543,7 +46846,7 @@ var init_boot = __esm(() => {
|
|
|
45543
46846
|
});
|
|
45544
46847
|
|
|
45545
46848
|
// ../daemon/src/index.ts
|
|
45546
|
-
var
|
|
46849
|
+
var init_src11 = __esm(() => {
|
|
45547
46850
|
init_boot();
|
|
45548
46851
|
init_store();
|
|
45549
46852
|
init_fold();
|
|
@@ -56659,7 +57962,7 @@ You are a worker. You own exactly one ticket, named in your launch brief. You tu
|
|
|
56659
57962
|
|
|
56660
57963
|
- **Never merge**, never enable auto-merge, never approve your own plan. The coordinator merges.
|
|
56661
57964
|
- **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.
|
|
56662
|
-
- **The ticket is the source of truth.** Read it, its parent spec and the hand-back comments of its merged blockers in full before planning.
|
|
57965
|
+
- **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.
|
|
56663
57966
|
- **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.
|
|
56664
57967
|
- **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.
|
|
56665
57968
|
- **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.
|
|
@@ -61073,7 +62376,7 @@ ${attachments.join(`
|
|
|
61073
62376
|
};
|
|
61074
62377
|
}
|
|
61075
62378
|
// package.json
|
|
61076
|
-
var version2 = "0.2.
|
|
62379
|
+
var version2 = "0.2.70";
|
|
61077
62380
|
|
|
61078
62381
|
// src/io.ts
|
|
61079
62382
|
class UsageError extends Error {
|
|
@@ -71211,18 +72514,19 @@ class TransportUnavailable extends Error {
|
|
|
71211
72514
|
|
|
71212
72515
|
class BeforeConnect extends TransportUnavailable {
|
|
71213
72516
|
}
|
|
71214
|
-
var commands = new Set(["claim", "report", "heartbeat", "ask", "release"]);
|
|
72517
|
+
var commands = new Set(["ticket", "claim", "report", "heartbeat", "ask", "release"]);
|
|
71215
72518
|
async function localWorker(io, args) {
|
|
71216
72519
|
if (!commands.has(args.command) || !io.env.ARMADA_WORKER_SOCKET && !io.env.ARMADA_WORKER_TOKEN)
|
|
71217
72520
|
return null;
|
|
71218
72521
|
const expected = args.command === "claim" || args.command === "report" ? 1 : 0;
|
|
71219
|
-
|
|
71220
|
-
|
|
72522
|
+
const optionalArgument = args.command === "ask" || args.command === "ticket";
|
|
72523
|
+
if (optionalArgument ? args.rest.length > 1 : args.rest.length !== expected)
|
|
72524
|
+
throw new UsageError(`local ${args.command} takes ${optionalArgument ? "at most one positional argument" : `${expected} positional arguments`}`);
|
|
71221
72525
|
const socketPath = io.env.ARMADA_WORKER_SOCKET;
|
|
71222
72526
|
const token = io.env.ARMADA_WORKER_TOKEN;
|
|
71223
72527
|
if (!socketPath || !token)
|
|
71224
72528
|
throw new UsageError("local worker requires its issued socket and token");
|
|
71225
|
-
const ticket = args.options.ticket ?? (args.command === "claim" ? args.rest[0] : undefined) ?? io.env.ARMADA_TICKET;
|
|
72529
|
+
const ticket = args.options.ticket ?? (args.command === "claim" || args.command === "ticket" ? args.rest[0] : undefined) ?? io.env.ARMADA_TICKET;
|
|
71226
72530
|
if (!ticket)
|
|
71227
72531
|
throw new UsageError("local worker needs its ticket");
|
|
71228
72532
|
const now = () => (io.now?.() ?? new Date).getTime();
|
|
@@ -71246,23 +72550,34 @@ async function localWorker(io, args) {
|
|
|
71246
72550
|
"Content-Type": "application/json"
|
|
71247
72551
|
}
|
|
71248
72552
|
}, (res) => {
|
|
71249
|
-
|
|
72553
|
+
const scopeRefusal = args.command === "ticket" && res.statusCode === 409;
|
|
72554
|
+
if (res.statusCode !== 200 && !scopeRefusal) {
|
|
71250
72555
|
reject(new Error("Local worker authorization refused or generation ended"));
|
|
71251
72556
|
res.on("error", () => {});
|
|
71252
72557
|
res.destroy();
|
|
71253
72558
|
return;
|
|
71254
72559
|
}
|
|
71255
72560
|
let output = "";
|
|
72561
|
+
let bytes = 0;
|
|
72562
|
+
const limit = args.command === "ticket" && !scopeRefusal ? 16 * 1024 * 1024 : 65536;
|
|
72563
|
+
res.setEncoding("utf8");
|
|
71256
72564
|
res.on("data", (chunk) => {
|
|
72565
|
+
bytes += Buffer.byteLength(chunk);
|
|
72566
|
+
if (bytes > limit) {
|
|
72567
|
+
reject(new Error(args.command === "ticket" ? "Local ticket response exceeds 16 MiB" : "Invalid local worker response"));
|
|
72568
|
+
req.destroy();
|
|
72569
|
+
return;
|
|
72570
|
+
}
|
|
71257
72571
|
output += chunk;
|
|
71258
|
-
if (output.length > 65536)
|
|
71259
|
-
req.destroy(new Error("Invalid local worker response"));
|
|
71260
72572
|
});
|
|
71261
72573
|
res.on("end", () => {
|
|
71262
|
-
if (res.statusCode !== 200)
|
|
71263
|
-
return reject(new Error("Local worker authorization refused or generation ended"));
|
|
71264
72574
|
try {
|
|
71265
|
-
|
|
72575
|
+
const result = JSON.parse(output);
|
|
72576
|
+
if (scopeRefusal) {
|
|
72577
|
+
const own = result.ticket;
|
|
72578
|
+
return reject(new Error(result.code === "ticket-scope" && typeof own === "string" && own.length <= 200 && !/[\r\n]/.test(own) ? `your capability is for ${own}` : "Local worker authorization refused or generation ended"));
|
|
72579
|
+
}
|
|
72580
|
+
resolve(result);
|
|
71266
72581
|
} catch {
|
|
71267
72582
|
reject(new Error("Invalid local worker response"));
|
|
71268
72583
|
}
|
|
@@ -71398,11 +72713,42 @@ Options: ${args.options.options}`;
|
|
|
71398
72713
|
return 0;
|
|
71399
72714
|
}
|
|
71400
72715
|
const result = await call(body);
|
|
71401
|
-
|
|
72716
|
+
if (args.command === "ticket") {
|
|
72717
|
+
const detail = result;
|
|
72718
|
+
if (!detail.ticket || typeof detail.ticket.title !== "string")
|
|
72719
|
+
throw new Error("Invalid local ticket response");
|
|
72720
|
+
io.stdout(args.json ? `${JSON.stringify(detail.ticket)}
|
|
72721
|
+
` : renderTicket(detail));
|
|
72722
|
+
} else
|
|
72723
|
+
io.stdout(args.json ? `${JSON.stringify(result)}
|
|
71402
72724
|
` : `${ticket}: ${args.command} recorded by the local daemon.
|
|
71403
72725
|
`);
|
|
71404
72726
|
return 0;
|
|
71405
72727
|
}
|
|
72728
|
+
function renderTicket({ ticket, parent, internal }) {
|
|
72729
|
+
const lines = [
|
|
72730
|
+
`# ${ticket.id} — ${ticket.title}`,
|
|
72731
|
+
"",
|
|
72732
|
+
`State: ${ticket.status}`,
|
|
72733
|
+
`Labels: ${ticket.labels?.join(", ") || "none"}`,
|
|
72734
|
+
`Parent: ${parent ? `${parent.id} — ${parent.title} (${parent.status})` : ticket.parent ? `${ticket.parent} (state unavailable)` : "none"}`,
|
|
72735
|
+
`Blockers: ${ticket.blockers?.map((blocker) => `${blocker.id} (${blocker.status})`).join(", ") || "none"}`,
|
|
72736
|
+
"",
|
|
72737
|
+
"## Description",
|
|
72738
|
+
"",
|
|
72739
|
+
ticket.description ?? "",
|
|
72740
|
+
"",
|
|
72741
|
+
"## Comments",
|
|
72742
|
+
""
|
|
72743
|
+
];
|
|
72744
|
+
for (const comment of ticket.comments ?? [])
|
|
72745
|
+
lines.push(`### ${comment.author} — ${comment.at}`, "", comment.body, "");
|
|
72746
|
+
if (!internal && ticket.url)
|
|
72747
|
+
lines.push(`older comments are in Linear: [${ticket.id}](${ticket.url})`, "");
|
|
72748
|
+
return `${lines.join(`
|
|
72749
|
+
`).trimEnd()}
|
|
72750
|
+
`;
|
|
72751
|
+
}
|
|
71406
72752
|
|
|
71407
72753
|
// src/peek.ts
|
|
71408
72754
|
function requirePeekCoordinator(credentials) {
|
|
@@ -71672,8 +73018,8 @@ import { fileURLToPath, pathToFileURL as pathToFileURL2 } from "node:url";
|
|
|
71672
73018
|
init_dist();
|
|
71673
73019
|
init_guard();
|
|
71674
73020
|
import assert from "node:assert/strict";
|
|
71675
|
-
import { execFile as
|
|
71676
|
-
import { randomUUID as
|
|
73021
|
+
import { execFile as execFile5 } from "node:child_process";
|
|
73022
|
+
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
71677
73023
|
import { copyFile, mkdir as mkdir5, readFile as readFile7, rm as rm7, stat as stat2, writeFile as writeFile4 } from "node:fs/promises";
|
|
71678
73024
|
import { join as join16, relative as relative5 } from "node:path";
|
|
71679
73025
|
import { setTimeout as delay3 } from "node:timers/promises";
|
|
@@ -80223,13 +81569,51 @@ var originalGenerateCallId = createIdGenerator2({
|
|
|
80223
81569
|
var project = "plugin-conformance";
|
|
80224
81570
|
var ticket = "CHECK-1";
|
|
80225
81571
|
var head = "0123456789abcdef0123456789abcdef01234567";
|
|
80226
|
-
var execute3 = promisify2(
|
|
81572
|
+
var execute3 = promisify2(execFile5);
|
|
80227
81573
|
async function runSeamChecks(options) {
|
|
80228
81574
|
for (const seam of SEAMS) {
|
|
80229
81575
|
for (const kind of Object.keys(options.manifest.contributions[seam] ?? {})) {
|
|
80230
81576
|
const name = `${seam}.${kind}`;
|
|
80231
81577
|
if (seam === "tracker" || seam === "forge") {
|
|
80232
81578
|
const provider = options.registry.get(seam, kind);
|
|
81579
|
+
let trackerTicket = ticket;
|
|
81580
|
+
let created = false;
|
|
81581
|
+
if (seam === "tracker") {
|
|
81582
|
+
const tracker = options.registry.get("tracker", kind);
|
|
81583
|
+
if (!tracker?.create)
|
|
81584
|
+
options.skip?.(`${name}.create`, "not implemented");
|
|
81585
|
+
else {
|
|
81586
|
+
created = await options.check(`${name}.create`, async (signal) => {
|
|
81587
|
+
const result = await tracker.create({
|
|
81588
|
+
project,
|
|
81589
|
+
title: "Conformance ticket",
|
|
81590
|
+
description: "Created through the tracker seam",
|
|
81591
|
+
labels: ["ready-for-agent"],
|
|
81592
|
+
signal
|
|
81593
|
+
});
|
|
81594
|
+
assert(result.id, "create did not return a ticket identifier");
|
|
81595
|
+
trackerTicket = result.id;
|
|
81596
|
+
await tracker.read({ project, signal });
|
|
81597
|
+
assert(options.events.some((event) => event.project === project && (event.kind === "ticket.created" || event.kind === "ticket.seen") && contains(event.payload, { id: result.id, title: "Conformance ticket" })), "create did not make the ticket readable");
|
|
81598
|
+
});
|
|
81599
|
+
}
|
|
81600
|
+
if (!tracker?.update)
|
|
81601
|
+
options.skip?.(`${name}.update`, "not implemented");
|
|
81602
|
+
else if (created)
|
|
81603
|
+
await options.check(`${name}.update`, async (signal) => {
|
|
81604
|
+
await tracker.update({
|
|
81605
|
+
project,
|
|
81606
|
+
ticket: trackerTicket,
|
|
81607
|
+
patch: { title: "Edited conformance ticket", labels: ["ready-for-agent", "implementing"] },
|
|
81608
|
+
signal
|
|
81609
|
+
});
|
|
81610
|
+
await tracker.read({ project, signal });
|
|
81611
|
+
assert(options.events.some((event) => event.project === project && (event.kind === "ticket.edited" && contains(event.payload, {
|
|
81612
|
+
ticket: trackerTicket,
|
|
81613
|
+
patch: { title: "Edited conformance ticket" }
|
|
81614
|
+
}) || event.kind === "ticket.seen" && contains(event.payload, { id: trackerTicket, title: "Edited conformance ticket" }))), "update did not make the patch readable");
|
|
81615
|
+
});
|
|
81616
|
+
}
|
|
80233
81617
|
const ready = await options.check(`${name}.read-events`, async () => {
|
|
80234
81618
|
assert(provider, "provider was not registered");
|
|
80235
81619
|
const recording = JSON.parse(await readFile7(join16(options.fixtureRoot, seam, "response.json"), "utf8"));
|
|
@@ -80245,26 +81629,32 @@ async function runSeamChecks(options) {
|
|
|
80245
81629
|
const eventStart = options.events.length;
|
|
80246
81630
|
const requestStart = options.requests.length;
|
|
80247
81631
|
await provider.read({ project, signal: AbortSignal.timeout(4000) });
|
|
81632
|
+
if (created && options.requests.length === requestStart && options.events.length === eventStart)
|
|
81633
|
+
return;
|
|
80248
81634
|
assertContact(options, requestStart, seam);
|
|
80249
81635
|
for (const expected of recording.expectedEvents) {
|
|
80250
|
-
assert(options.events.slice(eventStart).some((event) => event.project === project && event.kind === expected.kind && contains(event.payload, expected.payload)), `read did not append the recorded ${expected.kind} payload for ${project}`);
|
|
81636
|
+
assert(options.events.slice(created ? 0 : eventStart).some((event) => event.project === project && event.kind === expected.kind && contains(event.payload, expected.payload)), `read did not append the recorded ${expected.kind} payload for ${project}`);
|
|
80251
81637
|
}
|
|
80252
81638
|
});
|
|
80253
81639
|
if (!ready)
|
|
80254
81640
|
continue;
|
|
80255
81641
|
if (seam === "tracker") {
|
|
80256
81642
|
await options.check(`${name}.write`, async () => {
|
|
80257
|
-
const comment = `conformance-write-${
|
|
81643
|
+
const comment = `conformance-write-${randomUUID9()}`;
|
|
80258
81644
|
const start = options.requests.length;
|
|
81645
|
+
const eventStart = options.events.length;
|
|
80259
81646
|
await options.registry.get("tracker", kind)?.write({
|
|
80260
81647
|
project,
|
|
80261
|
-
ticket,
|
|
81648
|
+
ticket: trackerTicket,
|
|
80262
81649
|
phase: "implementing",
|
|
80263
81650
|
comment,
|
|
80264
81651
|
signal: AbortSignal.timeout(4000)
|
|
80265
81652
|
});
|
|
80266
81653
|
const writes = writeRequests(options, start, seam);
|
|
80267
|
-
assert([comment, "implementing",
|
|
81654
|
+
assert([comment, "implementing", trackerTicket].every((value) => writes.some((request) => `${request.path} ${JSON.stringify(request.body)}`.includes(value))) || options.events.slice(eventStart).some((event) => event.project === project && event.kind === "ticket.commented" && contains(event.payload, { ticket: trackerTicket, body: comment })) && options.events.slice(eventStart).some((event) => event.project === project && event.kind === "ticket.edited" && contains(event.payload, {
|
|
81655
|
+
ticket: trackerTicket,
|
|
81656
|
+
patch: { labels: ["ready-for-agent", "implementing"] }
|
|
81657
|
+
})), "write did not record its phase and unique comment");
|
|
80268
81658
|
});
|
|
80269
81659
|
} else {
|
|
80270
81660
|
await options.check(`${name}.merge`, async () => {
|
|
@@ -80379,7 +81769,7 @@ async function workerChecks(options, seam, kind) {
|
|
|
80379
81769
|
"-m",
|
|
80380
81770
|
"Initialize fixture"
|
|
80381
81771
|
]);
|
|
80382
|
-
const branch = `${fixture.branchPrefix}-${
|
|
81772
|
+
const branch = `${fixture.branchPrefix}-${randomUUID9()}`;
|
|
80383
81773
|
workspace = await provider.prepare({
|
|
80384
81774
|
project,
|
|
80385
81775
|
ticket,
|
|
@@ -80407,10 +81797,43 @@ async function workerChecks(options, seam, kind) {
|
|
|
80407
81797
|
});
|
|
80408
81798
|
if (!launched || !worker || !workspace || !provider)
|
|
80409
81799
|
return;
|
|
81800
|
+
if (seam === "runtime" && ["claude", "codex", "opencode"].includes(kind) && hostNode && await stat2(join16(options.directory, `${kind}-worker.mjs`)).then(() => true, () => false)) {
|
|
81801
|
+
await options.check(`${name}.permissions`, async (signal) => {
|
|
81802
|
+
assert(provider && workspace);
|
|
81803
|
+
const native = await provider.launch({
|
|
81804
|
+
workspace,
|
|
81805
|
+
worker: { project, ticket, session: randomUUID9(), generation: 1 },
|
|
81806
|
+
command: "",
|
|
81807
|
+
args: [],
|
|
81808
|
+
env: { FAKE_AUTH: "yes" }
|
|
81809
|
+
});
|
|
81810
|
+
try {
|
|
81811
|
+
await provider.deliver(native, "permission-check", randomUUID9());
|
|
81812
|
+
let reply = "";
|
|
81813
|
+
await poll(provider, native, (observation) => {
|
|
81814
|
+
reply = observation.reply ?? "";
|
|
81815
|
+
return reply.includes("permission-check");
|
|
81816
|
+
}, undefined, signal);
|
|
81817
|
+
const launched = JSON.parse(reply);
|
|
81818
|
+
if (kind === "claude")
|
|
81819
|
+
assert.equal(launched.args[launched.args.indexOf("--permission-mode") + 1], "bypassPermissions");
|
|
81820
|
+
else if (kind === "codex") {
|
|
81821
|
+
assert(launched.args.includes('approval_policy="never"'));
|
|
81822
|
+
assert(launched.args.includes('sandbox_mode="workspace-write"'));
|
|
81823
|
+
assert(launched.args.includes("sandbox_workspace_write.network_access=true"));
|
|
81824
|
+
} else if (kind === "opencode")
|
|
81825
|
+
assert.deepEqual(launched.permission, { "*": "allow" });
|
|
81826
|
+
else
|
|
81827
|
+
throw new Error("Unknown native permission fixture");
|
|
81828
|
+
} finally {
|
|
81829
|
+
await provider.stop(native);
|
|
81830
|
+
}
|
|
81831
|
+
});
|
|
81832
|
+
}
|
|
80410
81833
|
await options.check(`${name}.deliver`, async (signal) => {
|
|
80411
81834
|
assert(worker);
|
|
80412
|
-
const nonce = `nonce-${
|
|
80413
|
-
await provider.deliver(worker, nonce,
|
|
81835
|
+
const nonce = `nonce-${randomUUID9()}`;
|
|
81836
|
+
await provider.deliver(worker, nonce, randomUUID9());
|
|
80414
81837
|
await poll(provider, worker, (observation) => observation.reply?.includes(`ARMADA_CONFORMANCE_ACK:${nonce}`) === true, undefined, signal);
|
|
80415
81838
|
});
|
|
80416
81839
|
const stopped = await options.check(`${name}.stop`, async () => {
|
|
@@ -80429,7 +81852,7 @@ async function workerChecks(options, seam, kind) {
|
|
|
80429
81852
|
}, signal);
|
|
80430
81853
|
await poll(provider, worker, (observation) => observation.state === "running" && observation.reply?.includes("ARMADA_CONFORMANCE_READY") === true, deadline, signal);
|
|
80431
81854
|
signal.throwIfAborted();
|
|
80432
|
-
await provider.deliver(worker, "exit",
|
|
81855
|
+
await provider.deliver(worker, "exit", randomUUID9());
|
|
80433
81856
|
await poll(provider, worker, (observation) => observation.state === "stopped", deadline, signal);
|
|
80434
81857
|
});
|
|
80435
81858
|
} finally {
|
|
@@ -80447,7 +81870,7 @@ async function workerChecks(options, seam, kind) {
|
|
|
80447
81870
|
}
|
|
80448
81871
|
}
|
|
80449
81872
|
async function launchWorker2(options, provider, workspace, remember, signal) {
|
|
80450
|
-
const session =
|
|
81873
|
+
const session = randomUUID9();
|
|
80451
81874
|
const worker = await provider.launch({
|
|
80452
81875
|
workspace,
|
|
80453
81876
|
worker: { project, ticket, session, generation: 1 },
|
|
@@ -80481,7 +81904,7 @@ async function poll(provider, worker, accepted, deadline = Date.now() + 3500, si
|
|
|
80481
81904
|
throw new Error(`worker observation did not reach the expected state (last state: ${state})`);
|
|
80482
81905
|
}
|
|
80483
81906
|
async function hostedWorkerChecks(options, provider, name) {
|
|
80484
|
-
const worker = { project, ticket, session:
|
|
81907
|
+
const worker = { project, ticket, session: randomUUID9(), generation: 1 };
|
|
80485
81908
|
let ref;
|
|
80486
81909
|
await options.check(`${name}.hosted-lifecycle`, async () => {
|
|
80487
81910
|
const workspace = await provider.prepare({
|
|
@@ -80497,13 +81920,13 @@ async function hostedWorkerChecks(options, provider, name) {
|
|
|
80497
81920
|
command: "",
|
|
80498
81921
|
args: [],
|
|
80499
81922
|
env: {},
|
|
80500
|
-
brief: `armada login --launch-token armada_launch_${
|
|
81923
|
+
brief: `armada login --launch-token armada_launch_${randomUUID9()} --api-url https://example.invalid`
|
|
80501
81924
|
}));
|
|
80502
81925
|
assert.equal(ref.session, worker.session);
|
|
80503
81926
|
assert.equal(ref.generation, worker.generation);
|
|
80504
81927
|
assert.equal((await provider.observe(ref)).state, "running");
|
|
80505
81928
|
const current = ref;
|
|
80506
|
-
const key =
|
|
81929
|
+
const key = randomUUID9();
|
|
80507
81930
|
await guarded2(current, () => {}, () => provider.deliver(current, "Continue fixture", key));
|
|
80508
81931
|
await guarded2(current, () => {}, () => provider.deliver(current, "Continue fixture", key));
|
|
80509
81932
|
await assert.rejects(guarded2(current, () => {
|
|
@@ -80655,9 +82078,19 @@ async function testPlugin(io, path, reportPath, json = false) {
|
|
|
80655
82078
|
events.push(event);
|
|
80656
82079
|
return structuredClone(event);
|
|
80657
82080
|
},
|
|
82081
|
+
appendWith: async (project, build) => {
|
|
82082
|
+
await Promise.resolve().then(() => init_src11());
|
|
82083
|
+
const tables = fold(events.filter((e) => e.project === project));
|
|
82084
|
+
const inputs = build(tables).map((input) => pluginEventInputSchema.parse(input));
|
|
82085
|
+
if (inputs.some((input) => input.project !== project))
|
|
82086
|
+
throw new Error("appendWith project mismatch");
|
|
82087
|
+
const appended = inputs.map((input, i) => ({ ...input, seq: events.length + i + 1 }));
|
|
82088
|
+
events.push(...appended);
|
|
82089
|
+
return structuredClone(appended);
|
|
82090
|
+
},
|
|
80658
82091
|
read: async (project, after) => structuredClone(events.filter((e) => e.project === project && e.seq > after)),
|
|
80659
82092
|
fold: async (project) => {
|
|
80660
|
-
await Promise.resolve().then(() =>
|
|
82093
|
+
await Promise.resolve().then(() => init_src11());
|
|
80661
82094
|
return fold(events.filter((e) => e.project === project));
|
|
80662
82095
|
}
|
|
80663
82096
|
},
|
|
@@ -80685,6 +82118,12 @@ async function testPlugin(io, path, reportPath, json = false) {
|
|
|
80685
82118
|
endpoint,
|
|
80686
82119
|
requests,
|
|
80687
82120
|
nodeCommand: "node",
|
|
82121
|
+
skip: (name, reason) => {
|
|
82122
|
+
report.checks.push({ name, passed: false, skipped: reason });
|
|
82123
|
+
if (!json)
|
|
82124
|
+
io.stdout(`SKIP ${name}: ${reason}
|
|
82125
|
+
`);
|
|
82126
|
+
},
|
|
80688
82127
|
check: async (name, action) => {
|
|
80689
82128
|
const result = { name, passed: false };
|
|
80690
82129
|
try {
|
|
@@ -80808,7 +82247,7 @@ ${"─".repeat(60)}
|
|
|
80808
82247
|
}
|
|
80809
82248
|
|
|
80810
82249
|
// src/relaunch.ts
|
|
80811
|
-
import { randomUUID as
|
|
82250
|
+
import { randomUUID as randomUUID10 } from "node:crypto";
|
|
80812
82251
|
import { basename as basename4, dirname as dirname14, join as join18 } from "node:path";
|
|
80813
82252
|
async function relaunch(io, config, credentials, args, version, configPath) {
|
|
80814
82253
|
const [input, ...extra] = args.rest;
|
|
@@ -80944,7 +82383,7 @@ async function relaunch(io, config, credentials, args, version, configPath) {
|
|
|
80944
82383
|
});
|
|
80945
82384
|
prepared.spec.from = mode === "in-place" ? { kind: "in-place", previous: old } : head ? { kind: "branch", head } : { kind: "base" };
|
|
80946
82385
|
if (mode === "fresh" && prepared.local) {
|
|
80947
|
-
const suffix =
|
|
82386
|
+
const suffix = randomUUID10().slice(0, 8);
|
|
80948
82387
|
const configHome = io.env.XDG_CONFIG_HOME ?? (io.env.HOME ? join18(io.env.HOME, ".config") : null);
|
|
80949
82388
|
const path = io.env.HERDR_CONFIG_PATH ?? (configHome ? join18(configHome, "herdr", "config.toml") : null);
|
|
80950
82389
|
const text = path ? await io.readFile(path).catch(() => null) : null;
|
|
@@ -81025,7 +82464,7 @@ async function relaunch(io, config, credentials, args, version, configPath) {
|
|
|
81025
82464
|
}
|
|
81026
82465
|
Object.assign(prepared.briefInput, await reservationsForBrief(() => fleet.reservations(), config.reservations.length > 0));
|
|
81027
82466
|
if (mode === "fresh" && old.runtime === "herdr" && !remoteHerdr && workspace?.ready && oldRuntime instanceof HerdrAdapter) {
|
|
81028
|
-
const retained = `armada-retained/${ticket.toLowerCase()}-${
|
|
82467
|
+
const retained = `armada-retained/${ticket.toLowerCase()}-${randomUUID10().slice(0, 8)}`;
|
|
81029
82468
|
try {
|
|
81030
82469
|
old = await guarded(fleet, old, "ended", () => oldRuntime.retainBranch(old, retained), {
|
|
81031
82470
|
allowHistorical: true
|
|
@@ -81081,7 +82520,7 @@ ${worker.watch.line}
|
|
|
81081
82520
|
if (dry)
|
|
81082
82521
|
return replace();
|
|
81083
82522
|
return withLaunchLease(io, fleet, ticket, async (launchLease) => {
|
|
81084
|
-
const holder = `relaunch:${
|
|
82523
|
+
const holder = `relaunch:${randomUUID10()}`;
|
|
81085
82524
|
const lock = { name: MERGE_LEASE, holder, ttlMs: 5 * 60000, throughHold: `relaunch exclusion: ${reason}` };
|
|
81086
82525
|
if (!(await fleet.acquireLease(lock)).acquired)
|
|
81087
82526
|
throw new UsageError(`${ticket}: a merge is in progress; nothing was changed`, `armada relaunch ${ticket} --reason "<why>"`);
|
|
@@ -81606,6 +83045,67 @@ ${created.url}
|
|
|
81606
83045
|
return 0;
|
|
81607
83046
|
}
|
|
81608
83047
|
|
|
83048
|
+
// src/tickets.ts
|
|
83049
|
+
init_dist2();
|
|
83050
|
+
import { randomUUID as randomUUID11 } from "node:crypto";
|
|
83051
|
+
async function importTickets(io, rest, project, address) {
|
|
83052
|
+
if (rest.length !== 2 || rest[0] !== "import" || !rest[1]?.trim() || !project)
|
|
83053
|
+
throw new UsageError("armada tickets import <program-root> --project <id>");
|
|
83054
|
+
const endpoint = address ?? io.env.ARMADA_DAEMON_URL;
|
|
83055
|
+
if (!endpoint)
|
|
83056
|
+
throw new UsageError("Set ARMADA_DAEMON_URL to the running daemon's loopback URL, or pass --api-url <url>");
|
|
83057
|
+
let url;
|
|
83058
|
+
try {
|
|
83059
|
+
url = new URL(endpoint);
|
|
83060
|
+
} catch {
|
|
83061
|
+
throw new UsageError("The daemon URL must be a loopback HTTP or WebSocket URL");
|
|
83062
|
+
}
|
|
83063
|
+
if (!["http:", "ws:"].includes(url.protocol) || url.hostname !== "127.0.0.1" || url.username || url.password || url.pathname !== "/" || url.search || url.hash)
|
|
83064
|
+
throw new UsageError("The daemon URL must be a loopback HTTP or WebSocket URL");
|
|
83065
|
+
url.protocol = "ws:";
|
|
83066
|
+
const id = randomUUID11();
|
|
83067
|
+
return new Promise((resolve, reject) => {
|
|
83068
|
+
const socket = new WebSocket(url);
|
|
83069
|
+
let importId;
|
|
83070
|
+
let settled = false;
|
|
83071
|
+
const finish = (error, code = 1) => {
|
|
83072
|
+
if (settled)
|
|
83073
|
+
return;
|
|
83074
|
+
settled = true;
|
|
83075
|
+
clearTimeout(timer);
|
|
83076
|
+
socket.close();
|
|
83077
|
+
if (error)
|
|
83078
|
+
reject(error);
|
|
83079
|
+
else
|
|
83080
|
+
resolve(code);
|
|
83081
|
+
};
|
|
83082
|
+
const timer = setTimeout(() => finish(new UsageError("Import did not finish within 60 seconds; check its progress in the room before retrying")), 60000);
|
|
83083
|
+
socket.addEventListener("open", () => socket.send(JSON.stringify({ version: PROTOCOL_VERSION, id, type: "tracker.import", project, programRoot: rest[1] })));
|
|
83084
|
+
socket.addEventListener("error", () => finish(new UsageError("Cannot reach the Armada daemon; start the app and check ARMADA_DAEMON_URL")));
|
|
83085
|
+
socket.addEventListener("close", () => finish(new UsageError("Daemon connection closed; check import progress in the room before retrying")));
|
|
83086
|
+
socket.addEventListener("message", (message) => {
|
|
83087
|
+
try {
|
|
83088
|
+
const frame = JSON.parse(String(message.data));
|
|
83089
|
+
if (frame.type === "error")
|
|
83090
|
+
return finish(new UsageError(typeof frame.message === "string" ? frame.message : "Daemon refused the import"));
|
|
83091
|
+
if (frame.type === "tracker.import.result" && frame.id === id && frame.project === project) {
|
|
83092
|
+
importId = frame.importId;
|
|
83093
|
+
socket.send(JSON.stringify({ version: PROTOCOL_VERSION, id: `${id}:progress`, type: "project.subscribe", project, after: 0 }));
|
|
83094
|
+
}
|
|
83095
|
+
const parsed = trackerImportSchema.safeParse(frame.snapshot?.state?.trackerImport);
|
|
83096
|
+
if (!parsed.success || parsed.data.id !== importId || parsed.data.state === "running")
|
|
83097
|
+
return;
|
|
83098
|
+
const result = parsed.data;
|
|
83099
|
+
io.stdout(`Linear import ${rest[1]}: ${result.state}; ${result.imported} imported, ${result.skipped} skipped, ${result.comments} comments${result.pausedUntil ? `; paused until ${result.pausedUntil}` : ""}${result.error ? `; ${result.error}` : ""}
|
|
83100
|
+
`);
|
|
83101
|
+
finish(undefined, result.state === "completed" ? 0 : 1);
|
|
83102
|
+
} catch {
|
|
83103
|
+
finish(new UsageError("Invalid daemon import response; check progress in the room"));
|
|
83104
|
+
}
|
|
83105
|
+
});
|
|
83106
|
+
});
|
|
83107
|
+
}
|
|
83108
|
+
|
|
81609
83109
|
// src/upgrade.ts
|
|
81610
83110
|
var ATTEMPTS = 5;
|
|
81611
83111
|
var WAIT_MS = 30000;
|
|
@@ -81828,6 +83328,18 @@ async function done(io, config, credentials, a) {
|
|
|
81828
83328
|
|
|
81829
83329
|
// src/cli.ts
|
|
81830
83330
|
var COMMAND_HELP = {
|
|
83331
|
+
tickets: ` tickets import <program-root> --project <id> [--api-url <url>]
|
|
83332
|
+
Import Linear into an internal project through the running daemon.
|
|
83333
|
+
ARMADA_DAEMON_URL supplies its loopback URL. No Linear writes.
|
|
83334
|
+
`,
|
|
83335
|
+
worker: ` worker Show the worker protocol commands:
|
|
83336
|
+
ticket [<id>] [--json]: read your ticket through its local capability
|
|
83337
|
+
claim, report, heartbeat, ask, release: work with the daemon
|
|
83338
|
+
`,
|
|
83339
|
+
ticket: ` ticket [<id>] Read your capability's ticket from the local daemon as Markdown.
|
|
83340
|
+
Defaults to ARMADA_TICKET; another ticket is refused.
|
|
83341
|
+
--json prints the protocol Ticket. No tracker or credential read.
|
|
83342
|
+
`,
|
|
81831
83343
|
plugin: ` plugin list [--json]
|
|
81832
83344
|
plugin enable|disable <id>
|
|
81833
83345
|
List bundled plugins or change a switch (restart the daemon to apply).
|
|
@@ -82263,6 +83775,7 @@ var CONFIG_OPTION = new Set([
|
|
|
82263
83775
|
"upgrade"
|
|
82264
83776
|
]);
|
|
82265
83777
|
var JSON_OPTION = new Set([
|
|
83778
|
+
"ticket",
|
|
82266
83779
|
"peek",
|
|
82267
83780
|
"skills",
|
|
82268
83781
|
...[...CONFIG_OPTION].filter((c) => c !== "run" && c !== "attach" && c !== "upgrade"),
|
|
@@ -82438,6 +83951,7 @@ var FLAG_OPTIONS = [
|
|
|
82438
83951
|
"rerun"
|
|
82439
83952
|
];
|
|
82440
83953
|
var COMMAND_OPTIONS = {
|
|
83954
|
+
tickets: ["api-url"],
|
|
82441
83955
|
plugin: ["report"],
|
|
82442
83956
|
acceptance: ["ticket", "name", "runs", "reason"],
|
|
82443
83957
|
doctor: ["deep"],
|
|
@@ -82728,9 +84242,18 @@ async function dispatch(argv, io) {
|
|
|
82728
84242
|
args.options.all = "true";
|
|
82729
84243
|
if (args.passthrough && args.command !== "run")
|
|
82730
84244
|
throw new UsageError(`-- does not apply to ${args.command}: only \`armada run\` runs a command`);
|
|
84245
|
+
if (args.command === "tickets")
|
|
84246
|
+
return await importTickets(io, args.rest, args.project, args.options["api-url"]);
|
|
82731
84247
|
const local = await localWorker(io, { ...args, command: args.command });
|
|
82732
84248
|
if (local !== null)
|
|
82733
84249
|
return local;
|
|
84250
|
+
if (args.command === "worker") {
|
|
84251
|
+
noExtra(args.rest);
|
|
84252
|
+
io.stdout(commandHelp("worker"));
|
|
84253
|
+
return 0;
|
|
84254
|
+
}
|
|
84255
|
+
if (args.command === "ticket")
|
|
84256
|
+
throw new UsageError("armada ticket requires a local worker capability");
|
|
82734
84257
|
if (args.command === "plugin")
|
|
82735
84258
|
return await pluginCommand(io, args.rest, args.json, args.options.report);
|
|
82736
84259
|
if (args.command === "secrets" || args.command === "run") {
|