@agentchatme/codex 0.7.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/daemon-main.js +384 -79
- package/dist/daemon-main.js.map +1 -1
- package/dist/index.js +405 -81
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/daemon-main.js
CHANGED
|
@@ -4244,7 +4244,7 @@ var init_wrapper = __esm({
|
|
|
4244
4244
|
import { parseArgs } from "util";
|
|
4245
4245
|
import * as path13 from "path";
|
|
4246
4246
|
|
|
4247
|
-
// node_modules/.pnpm/@agentchatme+agent-core@0.7.
|
|
4247
|
+
// node_modules/.pnpm/@agentchatme+agent-core@0.7.1/node_modules/@agentchatme/agent-core/dist/chunk-5KMQ23O6.js
|
|
4248
4248
|
var import_cross_spawn = __toESM(require_cross_spawn(), 1);
|
|
4249
4249
|
import { randomBytes } from "crypto";
|
|
4250
4250
|
import * as fs from "fs";
|
|
@@ -4252,6 +4252,7 @@ import * as path from "path";
|
|
|
4252
4252
|
import * as fs2 from "fs";
|
|
4253
4253
|
import * as os from "os";
|
|
4254
4254
|
import * as path2 from "path";
|
|
4255
|
+
import { spawn as nodeSpawn } from "child_process";
|
|
4255
4256
|
var __defProp2 = Object.defineProperty;
|
|
4256
4257
|
var __export2 = (target, all) => {
|
|
4257
4258
|
for (var name in all)
|
|
@@ -4572,7 +4573,7 @@ function runSpawned(spec, captureBytes) {
|
|
|
4572
4573
|
} catch {
|
|
4573
4574
|
}
|
|
4574
4575
|
};
|
|
4575
|
-
const classify = (code, signal, note) => {
|
|
4576
|
+
const classify = (code, signal, note, exitedAt) => {
|
|
4576
4577
|
const tail = redactDiagnostic(stderrTail);
|
|
4577
4578
|
const extra = `${note ? ` (${note})` : ""}${tail ? `: ${tail}` : ""}`;
|
|
4578
4579
|
if (timedOut) {
|
|
@@ -4585,9 +4586,10 @@ function runSpawned(spec, captureBytes) {
|
|
|
4585
4586
|
if (code === 0) return note ? { state: "ok", exitCode: 0, detail: note } : { state: "ok", exitCode: 0 };
|
|
4586
4587
|
const exit = code === null ? `signal ${signal ?? "unknown"}` : `exit ${code}`;
|
|
4587
4588
|
if (stdoutBytes === 0) {
|
|
4588
|
-
const ranMs = spawnedAt === null ? 0 :
|
|
4589
|
+
const ranMs = spawnedAt === null ? 0 : Math.max(0, exitedAt - spawnedAt);
|
|
4589
4590
|
if (spawnedAt !== null && ranMs >= notStartedWithinMs) {
|
|
4590
|
-
|
|
4591
|
+
const refused = tail.includes("API Error");
|
|
4592
|
+
return { state: "failed", ...refused ? {} : { silent: true }, exitCode: code, detail: `${exit} after ${Math.round(ranMs / 1e3)} s with nothing on stdout (it ran, then ended)${extra}` };
|
|
4591
4593
|
}
|
|
4592
4594
|
return { state: "not_started", exitCode: code, detail: `${exit} with nothing on stdout${extra}` };
|
|
4593
4595
|
}
|
|
@@ -4598,7 +4600,8 @@ function runSpawned(spec, captureBytes) {
|
|
|
4598
4600
|
return;
|
|
4599
4601
|
}
|
|
4600
4602
|
try {
|
|
4601
|
-
|
|
4603
|
+
const spawner = spec.shell === true ? nodeSpawn : spawnCommand;
|
|
4604
|
+
child = spawner(spec.command, [...spec.args], {
|
|
4602
4605
|
cwd: spec.cwd,
|
|
4603
4606
|
env: spec.env,
|
|
4604
4607
|
stdio: [spec.stdin === null ? "ignore" : "pipe", "pipe", "pipe"],
|
|
@@ -4691,21 +4694,22 @@ function runSpawned(spec, captureBytes) {
|
|
|
4691
4694
|
classify(
|
|
4692
4695
|
exited.code,
|
|
4693
4696
|
exited.signal,
|
|
4694
|
-
process.platform === "win32" ? "a process the run started kept its output open after it exited; its children were swept (taskkill) and the run detached from it \u2014 a process the sweep cannot see can survive" : "a process the run started kept its output open after it exited; the run's process group was signalled (SIGKILL) and the run detached from it \u2014 a process that left the group can survive"
|
|
4697
|
+
process.platform === "win32" ? "a process the run started kept its output open after it exited; its children were swept (taskkill) and the run detached from it \u2014 a process the sweep cannot see can survive" : "a process the run started kept its output open after it exited; the run's process group was signalled (SIGKILL) and the run detached from it \u2014 a process that left the group can survive",
|
|
4698
|
+
exited.at
|
|
4695
4699
|
)
|
|
4696
4700
|
);
|
|
4697
4701
|
});
|
|
4698
4702
|
});
|
|
4699
4703
|
proc.on("close", (code, signal) => {
|
|
4700
|
-
finish(classify(code, signal, null));
|
|
4704
|
+
finish(classify(code, signal, null, exited?.at ?? Date.now()));
|
|
4701
4705
|
});
|
|
4702
4706
|
});
|
|
4703
4707
|
}
|
|
4704
4708
|
|
|
4705
|
-
// node_modules/.pnpm/@agentchatme+agent-core@0.7.
|
|
4709
|
+
// node_modules/.pnpm/@agentchatme+agent-core@0.7.1/node_modules/@agentchatme/agent-core/dist/chunk-AQTRC7G4.js
|
|
4706
4710
|
import * as path3 from "path";
|
|
4707
4711
|
|
|
4708
|
-
// node_modules/.pnpm/agentchatme@1.5.
|
|
4712
|
+
// node_modules/.pnpm/agentchatme@1.5.1_ws@8.21.1/node_modules/agentchatme/dist/index.js
|
|
4709
4713
|
var __defProp3 = Object.defineProperty;
|
|
4710
4714
|
var __export3 = (target, all) => {
|
|
4711
4715
|
for (var name in all)
|
|
@@ -5011,7 +5015,7 @@ function createAgentChatError(body, status, headers) {
|
|
|
5011
5015
|
return new AgentChatError(body, status, requestId);
|
|
5012
5016
|
}
|
|
5013
5017
|
}
|
|
5014
|
-
var VERSION = "1.5.
|
|
5018
|
+
var VERSION = "1.5.1";
|
|
5015
5019
|
function detectRuntime() {
|
|
5016
5020
|
const g = globalThis;
|
|
5017
5021
|
if (typeof g.Bun?.version === "string") return `bun/${g.Bun.version}`;
|
|
@@ -9518,6 +9522,7 @@ function readResult(text2) {
|
|
|
9518
9522
|
}
|
|
9519
9523
|
var TRAY_LIMIT = 50;
|
|
9520
9524
|
var SILENT_MEMORY = 1e3;
|
|
9525
|
+
var CONVERSATION_KEY = "conversation:";
|
|
9521
9526
|
var PACE_MS = 6e4;
|
|
9522
9527
|
var TURN_OVERDUE_MS = 30 * 6e4;
|
|
9523
9528
|
var NO_PROGRESS_BACKOFF_MS = 1e3;
|
|
@@ -9540,30 +9545,98 @@ var Pacer = class {
|
|
|
9540
9545
|
paceMs;
|
|
9541
9546
|
now;
|
|
9542
9547
|
until = /* @__PURE__ */ new Map();
|
|
9548
|
+
/** Orders holds and tray reads: a read lifts only holds older than its start. */
|
|
9549
|
+
seq = 0;
|
|
9550
|
+
/** A D5 pace. It never replaces a could-not-process hold at the same anchor (that input stays held). */
|
|
9543
9551
|
hold(key, anchor) {
|
|
9544
|
-
this.until.
|
|
9545
|
-
|
|
9546
|
-
|
|
9547
|
-
|
|
9548
|
-
|
|
9549
|
-
|
|
9550
|
-
|
|
9551
|
-
|
|
9552
|
-
|
|
9552
|
+
const prior = this.until.get(key);
|
|
9553
|
+
if (prior?.failure !== void 0 && prior.anchor === anchor) return;
|
|
9554
|
+
this.set(key, { anchor, until: this.now() + this.paceMs });
|
|
9555
|
+
}
|
|
9556
|
+
/** Could not process: hold the key at this anchor until a newer message moves it (held again at it: since the first time). */
|
|
9557
|
+
holdFailed(key, anchor, reason) {
|
|
9558
|
+
const prior = this.until.get(key);
|
|
9559
|
+
const since = prior?.failure !== void 0 && prior.anchor === anchor ? prior.failure.since : this.now();
|
|
9560
|
+
this.set(key, { anchor, until: Number.POSITIVE_INFINITY, failure: { reason, since, seq: ++this.seq } });
|
|
9561
|
+
}
|
|
9562
|
+
/** What holds the key at this anchor now: a pace, a could-not-process hold, or nothing (a stale entry goes). */
|
|
9563
|
+
check(key, anchor) {
|
|
9553
9564
|
const entry = this.until.get(key);
|
|
9554
|
-
if (!entry) return
|
|
9565
|
+
if (!entry) return null;
|
|
9555
9566
|
if (entry.anchor !== anchor || this.now() >= entry.until) {
|
|
9556
9567
|
this.until.delete(key);
|
|
9557
|
-
return
|
|
9568
|
+
return null;
|
|
9558
9569
|
}
|
|
9559
|
-
return
|
|
9570
|
+
return entry.failure ? "failed" : "paced";
|
|
9560
9571
|
}
|
|
9572
|
+
held(key, anchor) {
|
|
9573
|
+
return this.check(key, anchor) !== null;
|
|
9574
|
+
}
|
|
9575
|
+
/** A could-not-process hold on the key at exactly this anchor; changes nothing (a queued run's anchor may be older than the card's). */
|
|
9576
|
+
heldFailedAt(key, anchor) {
|
|
9577
|
+
const entry = this.until.get(key);
|
|
9578
|
+
return entry?.failure !== void 0 && entry.anchor === anchor;
|
|
9579
|
+
}
|
|
9580
|
+
/** Lift whatever holds the key (a pace or a could-not-process hold). */
|
|
9561
9581
|
release(key) {
|
|
9562
9582
|
this.until.delete(key);
|
|
9563
9583
|
}
|
|
9584
|
+
/** Lift a pace; a could-not-process hold stays. */
|
|
9585
|
+
releasePace(key) {
|
|
9586
|
+
if (this.until.get(key)?.failure === void 0) this.until.delete(key);
|
|
9587
|
+
}
|
|
9564
9588
|
releaseInvites() {
|
|
9565
9589
|
for (const key of [...this.until.keys()]) if (key.startsWith("invite:")) this.until.delete(key);
|
|
9566
9590
|
}
|
|
9591
|
+
/** Taken before a tray read: `keepFailedOn` lifts only holds made before it. */
|
|
9592
|
+
mark() {
|
|
9593
|
+
return this.seq;
|
|
9594
|
+
}
|
|
9595
|
+
/**
|
|
9596
|
+
* After a tray read from `mark` (`anchors`: each card's key and anchor):
|
|
9597
|
+
* a hold whose card shows another anchor is over (a newer message came),
|
|
9598
|
+
* and, on a complete tray (`complete`: not truncated), so is one whose
|
|
9599
|
+
* card is gone (read meanwhile: a verdict, a mark-read). Only holds made
|
|
9600
|
+
* before the read started: a read that began earlier says nothing of a
|
|
9601
|
+
* later hold.
|
|
9602
|
+
*/
|
|
9603
|
+
keepFailedOn(anchors, mark, complete) {
|
|
9604
|
+
for (const [key, entry] of this.until) {
|
|
9605
|
+
if (entry.failure === void 0 || entry.failure.seq > mark) continue;
|
|
9606
|
+
const shown = anchors.get(key);
|
|
9607
|
+
if (shown === void 0 ? complete : shown !== entry.anchor) this.until.delete(key);
|
|
9608
|
+
}
|
|
9609
|
+
}
|
|
9610
|
+
/** The could-not-process holds, oldest first (by `since`). */
|
|
9611
|
+
failed() {
|
|
9612
|
+
const out = [];
|
|
9613
|
+
for (const [key, entry] of this.until) {
|
|
9614
|
+
if (entry.failure !== void 0 && entry.anchor !== null) {
|
|
9615
|
+
out.push({ key, anchor: entry.anchor, reason: entry.failure.reason, since: entry.failure.since });
|
|
9616
|
+
}
|
|
9617
|
+
}
|
|
9618
|
+
return out.sort((a, b) => a.since - b.since);
|
|
9619
|
+
}
|
|
9620
|
+
set(key, entry) {
|
|
9621
|
+
this.until.delete(key);
|
|
9622
|
+
this.until.set(key, entry);
|
|
9623
|
+
let paces = 0;
|
|
9624
|
+
let holds = 0;
|
|
9625
|
+
for (const held of this.until.values()) {
|
|
9626
|
+
if (held.failure === void 0) paces += 1;
|
|
9627
|
+
else holds += 1;
|
|
9628
|
+
}
|
|
9629
|
+
for (const [key2, held] of this.until) {
|
|
9630
|
+
if (paces <= SILENT_MEMORY && holds <= SILENT_MEMORY) break;
|
|
9631
|
+
if (held.failure === void 0 && paces > SILENT_MEMORY) {
|
|
9632
|
+
this.until.delete(key2);
|
|
9633
|
+
paces -= 1;
|
|
9634
|
+
} else if (held.failure !== void 0 && holds > SILENT_MEMORY) {
|
|
9635
|
+
this.until.delete(key2);
|
|
9636
|
+
holds -= 1;
|
|
9637
|
+
}
|
|
9638
|
+
}
|
|
9639
|
+
}
|
|
9567
9640
|
};
|
|
9568
9641
|
function clears(completion, failure) {
|
|
9569
9642
|
return completion.kind === failure.source && completion.conversations.has(failure.conversationId);
|
|
@@ -9648,16 +9721,25 @@ var ReceiveLoop = class {
|
|
|
9648
9721
|
rerunsCapped: 0,
|
|
9649
9722
|
runtimeChecksOk: 0,
|
|
9650
9723
|
runtimeChecksFailed: 0,
|
|
9651
|
-
splitsStopped: 0
|
|
9724
|
+
splitsStopped: 0,
|
|
9725
|
+
startsHeld: 0
|
|
9652
9726
|
};
|
|
9653
9727
|
/** Conversations whose verdict a gate call is recording right now (an abandoned cycle's included). */
|
|
9654
9728
|
recordsInFlight = /* @__PURE__ */ new Set();
|
|
9729
|
+
/**
|
|
9730
|
+
* Could not process: conversations whose report is out on another's
|
|
9731
|
+
* completion (`takeDue`): held out of the gate and of new runs, and a run
|
|
9732
|
+
* or turn of theirs waiting for a slot waits, until the server answers.
|
|
9733
|
+
*/
|
|
9734
|
+
reporting = /* @__PURE__ */ new Map();
|
|
9655
9735
|
/** Turns holding a slot (admitted, not yet ended or released). */
|
|
9656
9736
|
slotted = /* @__PURE__ */ new Set();
|
|
9657
9737
|
handle;
|
|
9658
9738
|
started = false;
|
|
9659
9739
|
stopped = false;
|
|
9660
9740
|
heldWhileRunning = false;
|
|
9741
|
+
/** A cycle left a card out because its could-not-process report was out: `letGo` reads the tray again. */
|
|
9742
|
+
heldWhileReporting = false;
|
|
9661
9743
|
activeTurns = 0;
|
|
9662
9744
|
noProgressStreak = 0;
|
|
9663
9745
|
moreTimer = null;
|
|
@@ -9855,7 +9937,13 @@ var ReceiveLoop = class {
|
|
|
9855
9937
|
processingFailures: {
|
|
9856
9938
|
...this.failureCounts,
|
|
9857
9939
|
awaitingEvidence: this.awaitingEvidence.size,
|
|
9858
|
-
lastRuntimeCheck: this.lastRuntimeCheck === null ? null : { ...this.lastRuntimeCheck }
|
|
9940
|
+
lastRuntimeCheck: this.lastRuntimeCheck === null ? null : { ...this.lastRuntimeCheck },
|
|
9941
|
+
held: this.pacer.failed().map(({ key, anchor, reason, since }) => ({
|
|
9942
|
+
conversationId: key.slice(CONVERSATION_KEY.length),
|
|
9943
|
+
anchor,
|
|
9944
|
+
since: new Date(since).toISOString(),
|
|
9945
|
+
reason
|
|
9946
|
+
}))
|
|
9859
9947
|
},
|
|
9860
9948
|
lastError: this.lastError
|
|
9861
9949
|
};
|
|
@@ -9885,7 +9973,7 @@ var ReceiveLoop = class {
|
|
|
9885
9973
|
const id = typeof payload.conversation_id === "string" ? payload.conversation_id : void 0;
|
|
9886
9974
|
const named = Array.isArray(payload.conversation_ids) ? payload.conversation_ids.filter((x) => typeof x === "string") : [];
|
|
9887
9975
|
if (reason === "unanswered") {
|
|
9888
|
-
for (const conversationId of named) this.pacer.
|
|
9976
|
+
for (const conversationId of named) this.pacer.releasePace(`${CONVERSATION_KEY}${conversationId}`);
|
|
9889
9977
|
this.pacer.releaseInvites();
|
|
9890
9978
|
}
|
|
9891
9979
|
this.wakeFrom("wake_frame", id, {
|
|
@@ -10065,20 +10153,22 @@ var ReceiveLoop = class {
|
|
|
10065
10153
|
}
|
|
10066
10154
|
}
|
|
10067
10155
|
async gateCallCycle(run3) {
|
|
10156
|
+
const mark = this.pacer.mark();
|
|
10068
10157
|
const tray = await this.readTray();
|
|
10069
10158
|
if (run3.stale()) return this.summary("abandoned");
|
|
10070
10159
|
if (tray === null) return this.summary("tray_failed", { failure: this.lastError });
|
|
10071
10160
|
const cards = cardsOf(tray);
|
|
10161
|
+
this.forgetCleared(tray, mark);
|
|
10072
10162
|
const invites = trayInvites(tray);
|
|
10073
10163
|
const unheld = this.unheld(cards);
|
|
10074
10164
|
const heldByTurns = cards.length - unheld.length;
|
|
10075
10165
|
if (heldByTurns > 0) this.heldWhileRunning = true;
|
|
10076
|
-
const gateCards
|
|
10166
|
+
const { open: gateCards, paced: pacedCards, heldAfterFailure } = this.paceCards(unheld);
|
|
10077
10167
|
const openInvites = invites.filter((invite) => !this.tracker.inviteRunning(invite.invite_id));
|
|
10078
10168
|
const owedInvites = openInvites.filter((invite) => !this.pacer.held(`invite:${invite.invite_id}`, null));
|
|
10079
|
-
const paced =
|
|
10169
|
+
const paced = pacedCards + (openInvites.length - owedInvites.length);
|
|
10080
10170
|
const owedCards = gateCards.filter((card) => card.muted !== true);
|
|
10081
|
-
const base = { cards: cards.length, invites: invites.length, heldByTurns, paced, truncated: tray.truncated === true };
|
|
10171
|
+
const base = { cards: cards.length, invites: invites.length, heldByTurns, paced, heldAfterFailure, truncated: tray.truncated === true };
|
|
10082
10172
|
if (cards.length === 0 && invites.length === 0) return this.summary("empty", base);
|
|
10083
10173
|
if (owedCards.length === 0 && owedInvites.length === 0) return this.summary("nothing_owed", base);
|
|
10084
10174
|
const texts = await this.options.texts.ensure();
|
|
@@ -10101,7 +10191,8 @@ var ReceiveLoop = class {
|
|
|
10101
10191
|
chunksOk: 0,
|
|
10102
10192
|
chunksFailed: 0,
|
|
10103
10193
|
splitCallsOk: 0,
|
|
10104
|
-
splitCallsFailed: 0
|
|
10194
|
+
splitCallsFailed: 0,
|
|
10195
|
+
heldAfterFailure
|
|
10105
10196
|
};
|
|
10106
10197
|
let heldDuringGate = 0;
|
|
10107
10198
|
let splitStopped = false;
|
|
@@ -10110,6 +10201,7 @@ var ReceiveLoop = class {
|
|
|
10110
10201
|
if (owedCards.length > 0) {
|
|
10111
10202
|
const gate = await this.gateInChunks(run3, tray, gateCards, texts);
|
|
10112
10203
|
heldDuringGate = gate.held;
|
|
10204
|
+
tally.heldAfterFailure += gate.heldAfterFailure;
|
|
10113
10205
|
tally.gated = gate.gated;
|
|
10114
10206
|
tally.reply = gate.verdicts.reply;
|
|
10115
10207
|
tally.dismiss = gate.verdicts.dismiss;
|
|
@@ -10132,7 +10224,7 @@ var ReceiveLoop = class {
|
|
|
10132
10224
|
} else if (tally.chunksFailed + tally.splitCallsFailed > 0) {
|
|
10133
10225
|
outcome = "fail_closed";
|
|
10134
10226
|
} else if (owedInvites.length === 0 && !run3.stale()) {
|
|
10135
|
-
return this.summary("nothing_owed", { ...base, heldByTurns: heldByTurns + heldDuringGate });
|
|
10227
|
+
return this.summary("nothing_owed", { ...base, heldByTurns: heldByTurns + heldDuringGate, heldAfterFailure: tally.heldAfterFailure });
|
|
10136
10228
|
}
|
|
10137
10229
|
}
|
|
10138
10230
|
for (const invite of owedInvites) {
|
|
@@ -10149,10 +10241,54 @@ var ReceiveLoop = class {
|
|
|
10149
10241
|
/**
|
|
10150
10242
|
* Held out of the gate: a running or waiting turn, or a verdict still being
|
|
10151
10243
|
* recorded (an abandoned cycle's last call): gating it again could record
|
|
10152
|
-
* the same verdict twice (a second defer climbs the ladder).
|
|
10244
|
+
* the same verdict twice (a second defer climbs the ladder). Also a
|
|
10245
|
+
* conversation whose could-not-process report is out (`reporting`): its
|
|
10246
|
+
* answer may hold it.
|
|
10153
10247
|
*/
|
|
10154
10248
|
unheld(cards) {
|
|
10155
|
-
return this.tracker.withoutRunning(cards).filter((card) =>
|
|
10249
|
+
return this.tracker.withoutRunning(cards).filter((card) => {
|
|
10250
|
+
if (this.recordsInFlight.has(card.conversation_id)) return false;
|
|
10251
|
+
if (!this.reporting.has(card.conversation_id)) return true;
|
|
10252
|
+
this.heldWhileReporting = true;
|
|
10253
|
+
return false;
|
|
10254
|
+
});
|
|
10255
|
+
}
|
|
10256
|
+
/**
|
|
10257
|
+
* The cards neither paced (D5) nor held after a could-not-process answer
|
|
10258
|
+
* (`none` / `paused` through the anchor they still show), and how many of
|
|
10259
|
+
* each were left out. A card whose anchor moved is no longer held.
|
|
10260
|
+
*/
|
|
10261
|
+
paceCards(cards) {
|
|
10262
|
+
const open = [];
|
|
10263
|
+
let paced = 0;
|
|
10264
|
+
let heldAfterFailure = 0;
|
|
10265
|
+
for (const card of cards) {
|
|
10266
|
+
const state = this.pacer.check(`${CONVERSATION_KEY}${card.conversation_id}`, anchorFrom(card));
|
|
10267
|
+
if (state === "paced") paced += 1;
|
|
10268
|
+
else if (state === "failed") heldAfterFailure += 1;
|
|
10269
|
+
else open.push(card);
|
|
10270
|
+
}
|
|
10271
|
+
return { open, paced, heldAfterFailure };
|
|
10272
|
+
}
|
|
10273
|
+
/** Held after a could-not-process answer, at the anchor this card still shows. */
|
|
10274
|
+
heldAfterFailure(card) {
|
|
10275
|
+
return this.pacer.check(`${CONVERSATION_KEY}${card.conversation_id}`, anchorFrom(card)) === "failed";
|
|
10276
|
+
}
|
|
10277
|
+
/**
|
|
10278
|
+
* A tray read after `mark`, every card on it (a turn's included): a held
|
|
10279
|
+
* conversation whose card shows a newer anchor is no longer held, and on
|
|
10280
|
+
* a complete tray (not truncated) neither is one whose card is gone (read
|
|
10281
|
+
* meanwhile: a verdict, a mark-read). A truncated tray proves nothing
|
|
10282
|
+
* about the cards it does not show.
|
|
10283
|
+
*/
|
|
10284
|
+
forgetCleared(tray, mark) {
|
|
10285
|
+
const anchors = new Map(cardsOf(tray).map((card) => [`${CONVERSATION_KEY}${card.conversation_id}`, anchorFrom(card)]));
|
|
10286
|
+
this.pacer.keepFailedOn(anchors, mark, tray.truncated !== true);
|
|
10287
|
+
}
|
|
10288
|
+
/** The start of a run or reply turn: held after a could-not-process answer at the anchor it was started for. */
|
|
10289
|
+
failureHeld(handle) {
|
|
10290
|
+
const turn = handle.turn;
|
|
10291
|
+
return turn.kind === "reply" && this.pacer.heldFailedAt(`${CONVERSATION_KEY}${turn.conversationId}`, turn.anchor);
|
|
10156
10292
|
}
|
|
10157
10293
|
/**
|
|
10158
10294
|
* The gate in chunks (contract v1 §3.6): the cards, in tray order, split
|
|
@@ -10186,6 +10322,7 @@ var ReceiveLoop = class {
|
|
|
10186
10322
|
const out = {
|
|
10187
10323
|
gated: 0,
|
|
10188
10324
|
held: 0,
|
|
10325
|
+
heldAfterFailure: 0,
|
|
10189
10326
|
reply: [],
|
|
10190
10327
|
verdicts: { reply: 0, dismiss: 0, defer: 0 },
|
|
10191
10328
|
undecided: 0,
|
|
@@ -10231,7 +10368,9 @@ var ReceiveLoop = class {
|
|
|
10231
10368
|
const of = Math.ceil(chunked.length / size);
|
|
10232
10369
|
for (let index2 = 1; index2 <= of; index2++) {
|
|
10233
10370
|
if (run3.stale()) break;
|
|
10234
|
-
const
|
|
10371
|
+
const slice = chunked.slice((index2 - 1) * size, index2 * size);
|
|
10372
|
+
const planned = slice.filter((card) => !this.heldAfterFailure(card));
|
|
10373
|
+
out.heldAfterFailure += slice.length - planned.length;
|
|
10235
10374
|
const chunk = this.unheld(planned);
|
|
10236
10375
|
out.held += planned.length - chunk.length;
|
|
10237
10376
|
if (chunk.length < planned.length) this.heldWhileRunning = true;
|
|
@@ -10265,7 +10404,7 @@ var ReceiveLoop = class {
|
|
|
10265
10404
|
if (report.outcome === "decided") {
|
|
10266
10405
|
const through = decidedBy(result);
|
|
10267
10406
|
for (const id of through) this.gateAlone.delete(id);
|
|
10268
|
-
await run3.exclude(() => this.reportDue(this.completed("gate", through)));
|
|
10407
|
+
await run3.exclude(() => this.reportDue(this.takeDue(this.completed("gate", through))));
|
|
10269
10408
|
continue;
|
|
10270
10409
|
}
|
|
10271
10410
|
this.failedAttempt("gate", chunk.filter((card) => card.muted !== true).map((card) => card.conversation_id));
|
|
@@ -10286,7 +10425,7 @@ var ReceiveLoop = class {
|
|
|
10286
10425
|
if (run3.stale()) break splitting;
|
|
10287
10426
|
const { card, reruns } = queue.shift();
|
|
10288
10427
|
const id = card.conversation_id;
|
|
10289
|
-
if (decided.has(id) || split.skip.has(id)) continue;
|
|
10428
|
+
if (decided.has(id) || split.skip.has(id) || this.heldAfterFailure(card)) continue;
|
|
10290
10429
|
if (this.unheld([card]).length === 0) {
|
|
10291
10430
|
if (!gated.has(id)) out.held += 1;
|
|
10292
10431
|
this.heldWhileRunning = true;
|
|
@@ -10317,7 +10456,7 @@ var ReceiveLoop = class {
|
|
|
10317
10456
|
if (report.outcome === "decided") {
|
|
10318
10457
|
failuresInARow = 0;
|
|
10319
10458
|
this.gateAlone.delete(id);
|
|
10320
|
-
await run3.exclude(() => this.reportDue(this.completed("gate", decidedBy(result))));
|
|
10459
|
+
await run3.exclude(() => this.reportDue(this.takeDue(this.completed("gate", decidedBy(result)))));
|
|
10321
10460
|
continue;
|
|
10322
10461
|
}
|
|
10323
10462
|
this.rememberGateAlone(id);
|
|
@@ -10382,12 +10521,14 @@ var ReceiveLoop = class {
|
|
|
10382
10521
|
}
|
|
10383
10522
|
}
|
|
10384
10523
|
async singleRunCycle(run3) {
|
|
10524
|
+
const mark = this.pacer.mark();
|
|
10385
10525
|
const tray = await this.readTray();
|
|
10386
10526
|
if (run3.stale()) return this.summary("abandoned");
|
|
10387
10527
|
let cards = null;
|
|
10388
10528
|
let invites = null;
|
|
10389
10529
|
let base = { cards: 0, invites: 0, heldByTurns: 0, truncated: false };
|
|
10390
10530
|
if (tray !== null) {
|
|
10531
|
+
this.forgetCleared(tray, mark);
|
|
10391
10532
|
cards = cardsOf(tray).filter((card) => card.muted !== true).length;
|
|
10392
10533
|
invites = trayInvites(tray).length;
|
|
10393
10534
|
base = { cards: cardsOf(tray).length, invites, heldByTurns: 0, truncated: tray.truncated === true };
|
|
@@ -10435,17 +10576,17 @@ ${texts.invite_prompt.trim()}` : texts.wake_instruction.trim();
|
|
|
10435
10576
|
const unheld = this.unheld(cards);
|
|
10436
10577
|
const heldByTurns = cards.length - unheld.length;
|
|
10437
10578
|
if (heldByTurns > 0) this.heldWhileRunning = true;
|
|
10438
|
-
const runCards
|
|
10579
|
+
const { open: runCards, paced: pacedCards, heldAfterFailure } = this.paceCards(unheld);
|
|
10439
10580
|
const openInvites = invites.filter((invite) => !this.tracker.inviteRunning(invite.invite_id));
|
|
10440
10581
|
const owedInvites = openInvites.filter((invite) => !this.pacer.held(`invite:${invite.invite_id}`, null));
|
|
10441
|
-
const paced =
|
|
10582
|
+
const paced = pacedCards + (openInvites.length - owedInvites.length);
|
|
10442
10583
|
const owedCards = runCards.filter((card) => card.muted !== true && card.preview != null);
|
|
10443
|
-
const base = { cards: cards.length, invites: invites.length, heldByTurns, paced, truncated: tray.truncated === true };
|
|
10584
|
+
const base = { cards: cards.length, invites: invites.length, heldByTurns, paced, heldAfterFailure, truncated: tray.truncated === true };
|
|
10444
10585
|
if (owedCards.length === 0 && owedInvites.length === 0) return this.summary("nothing_owed", base);
|
|
10445
10586
|
const unready = await this.checkReady();
|
|
10446
10587
|
if (run3.stale()) return this.summary("abandoned", base);
|
|
10447
10588
|
if (unready !== null) return this.summary("tools_unavailable", { ...base, failure: unready });
|
|
10448
|
-
const tally = { turnsStarted: 0, turnsRefused: 0, turnsQueued: 0 };
|
|
10589
|
+
const tally = { turnsStarted: 0, turnsRefused: 0, turnsQueued: 0, heldAfterFailure };
|
|
10449
10590
|
const failedLast = owedCards.filter((card) => this.awaitingEvidence.has(card.conversation_id));
|
|
10450
10591
|
for (const card of owedCards.filter((card2) => !failedLast.includes(card2))) {
|
|
10451
10592
|
if (run3.stale()) break;
|
|
@@ -10489,6 +10630,8 @@ ${texts.invite_prompt.trim()}` : texts.wake_instruction.trim();
|
|
|
10489
10630
|
const held = this.tracker.holds(handle);
|
|
10490
10631
|
let completion = null;
|
|
10491
10632
|
let failure = null;
|
|
10633
|
+
let due = [];
|
|
10634
|
+
let ended = false;
|
|
10492
10635
|
try {
|
|
10493
10636
|
this.countRunEnd(end);
|
|
10494
10637
|
this.emit({ type: "run", end, kind: "conversation", conversationId: attempt.conversationId });
|
|
@@ -10502,8 +10645,10 @@ ${texts.invite_prompt.trim()}` : texts.wake_instruction.trim();
|
|
|
10502
10645
|
failure = { ...attempt, outcome: end.timedOut === true ? "timed_out" : "failed", failedAt: this.now(), holding: handle };
|
|
10503
10646
|
}
|
|
10504
10647
|
}
|
|
10648
|
+
ended = true;
|
|
10505
10649
|
} finally {
|
|
10506
10650
|
if (failure === null) this.tracker.end(handle);
|
|
10651
|
+
if (ended && !this.stopped && completion !== null) due = this.takeDue(completion);
|
|
10507
10652
|
this.releaseSlot(handle);
|
|
10508
10653
|
if (failure === null) this.afterTurnEnded();
|
|
10509
10654
|
}
|
|
@@ -10515,7 +10660,7 @@ ${texts.invite_prompt.trim()}` : texts.wake_instruction.trim();
|
|
|
10515
10660
|
this.afterTurnEnded();
|
|
10516
10661
|
}
|
|
10517
10662
|
}
|
|
10518
|
-
|
|
10663
|
+
await this.reportDue(due);
|
|
10519
10664
|
await this.checkParked("run");
|
|
10520
10665
|
}
|
|
10521
10666
|
/** The invite run: one run for the pending invites, holding each of them until it ends. */
|
|
@@ -10555,6 +10700,8 @@ ${texts.invite_prompt.trim()}` : texts.wake_instruction.trim();
|
|
|
10555
10700
|
const end = await done;
|
|
10556
10701
|
const held = this.tracker.holds(slot);
|
|
10557
10702
|
let completion = null;
|
|
10703
|
+
let due = [];
|
|
10704
|
+
let ended = false;
|
|
10558
10705
|
try {
|
|
10559
10706
|
this.countRunEnd(end);
|
|
10560
10707
|
this.emit({ type: "run", end, kind: "invite" });
|
|
@@ -10564,12 +10711,14 @@ ${texts.invite_prompt.trim()}` : texts.wake_instruction.trim();
|
|
|
10564
10711
|
for (const invite of invites) this.pacer.hold(`invite:${invite.invite_id}`, null);
|
|
10565
10712
|
}
|
|
10566
10713
|
if (this.options.dismissIgnoredInvites !== false) await this.afterRunInvites(invites, end);
|
|
10714
|
+
ended = true;
|
|
10567
10715
|
} finally {
|
|
10568
10716
|
endAll();
|
|
10717
|
+
if (ended && !this.stopped && completion !== null) due = this.takeDue(completion);
|
|
10569
10718
|
this.releaseSlot(slot);
|
|
10570
10719
|
this.afterTurnEnded();
|
|
10571
10720
|
}
|
|
10572
|
-
|
|
10721
|
+
await this.reportDue(due);
|
|
10573
10722
|
await this.checkParked("run");
|
|
10574
10723
|
}
|
|
10575
10724
|
/** The runtime's `startRun`, never rejecting: a throw is a run that did not start. */
|
|
@@ -10662,7 +10811,13 @@ invite_id: ${invite.invite_id}`,
|
|
|
10662
10811
|
* hands its slot on the same way.
|
|
10663
10812
|
*/
|
|
10664
10813
|
async launch(handle, admit, drop) {
|
|
10665
|
-
if (this.
|
|
10814
|
+
if (this.failureHeld(handle)) {
|
|
10815
|
+
this.tracker.end(handle);
|
|
10816
|
+
drop?.();
|
|
10817
|
+
this.failureCounts.startsHeld += 1;
|
|
10818
|
+
return "held";
|
|
10819
|
+
}
|
|
10820
|
+
if (this.waiting.length > 0 || this.activeTurns >= this.maxTurns || this.awaitsAnswer(handle)) {
|
|
10666
10821
|
this.waiting.push({ handle, admit, ...drop ? { drop } : {} });
|
|
10667
10822
|
this.counts.turnsQueued += 1;
|
|
10668
10823
|
if (this.activeTurns < this.maxTurns) void this.pump();
|
|
@@ -10687,16 +10842,29 @@ invite_id: ${invite.invite_id}`,
|
|
|
10687
10842
|
if (options.pump !== false) void this.pump();
|
|
10688
10843
|
}
|
|
10689
10844
|
async pump() {
|
|
10690
|
-
while (this.
|
|
10691
|
-
const
|
|
10845
|
+
while (this.activeTurns < this.maxTurns && !this.stopped) {
|
|
10846
|
+
const index = this.waiting.findIndex((w) => !this.awaitsAnswer(w.handle));
|
|
10847
|
+
if (index < 0) break;
|
|
10848
|
+
const next = this.waiting.splice(index, 1)[0];
|
|
10692
10849
|
if (!this.tracker.holds(next.handle)) continue;
|
|
10850
|
+
if (this.failureHeld(next.handle)) {
|
|
10851
|
+
this.tracker.end(next.handle);
|
|
10852
|
+
next.drop?.();
|
|
10853
|
+
this.failureCounts.startsHeld += 1;
|
|
10854
|
+
continue;
|
|
10855
|
+
}
|
|
10693
10856
|
await this.admitInSlot(next.handle, next.admit);
|
|
10694
10857
|
}
|
|
10695
10858
|
}
|
|
10859
|
+
awaitsAnswer(handle) {
|
|
10860
|
+
return handle.turn.kind === "reply" && this.reporting.has(handle.turn.conversationId);
|
|
10861
|
+
}
|
|
10696
10862
|
async afterReplyTurn(handle, attempt, done) {
|
|
10697
10863
|
const reply = attempt.reply;
|
|
10698
10864
|
let completion = null;
|
|
10699
10865
|
let failure = null;
|
|
10866
|
+
let due = [];
|
|
10867
|
+
let ended = false;
|
|
10700
10868
|
try {
|
|
10701
10869
|
const end = await this.tracker.confirmedEnd(handle, done);
|
|
10702
10870
|
if (end === null || !this.tracker.holds(handle)) return;
|
|
@@ -10706,8 +10874,10 @@ invite_id: ${invite.invite_id}`,
|
|
|
10706
10874
|
if (end.status === "failed" && recorded?.freshRead === true && recorded.outcome.reason === "turn_failed") {
|
|
10707
10875
|
failure = { ...attempt, outcome: end.timedOut === true ? "timed_out" : "failed", failedAt: this.now(), holding: handle };
|
|
10708
10876
|
}
|
|
10877
|
+
ended = true;
|
|
10709
10878
|
} finally {
|
|
10710
10879
|
if (failure === null) this.tracker.end(handle);
|
|
10880
|
+
if (ended && !this.stopped && completion !== null) due = this.takeDue(completion);
|
|
10711
10881
|
this.releaseSlot(handle);
|
|
10712
10882
|
if (failure === null) this.afterTurnEnded();
|
|
10713
10883
|
}
|
|
@@ -10719,7 +10889,7 @@ invite_id: ${invite.invite_id}`,
|
|
|
10719
10889
|
this.afterTurnEnded();
|
|
10720
10890
|
}
|
|
10721
10891
|
}
|
|
10722
|
-
|
|
10892
|
+
await this.track(this.reportDue(due));
|
|
10723
10893
|
await this.track(this.checkParked("turn"));
|
|
10724
10894
|
}
|
|
10725
10895
|
async recordReplyOutcome(handle, reply, end) {
|
|
@@ -10841,11 +11011,15 @@ invite_id: ${invite.invite_id}`,
|
|
|
10841
11011
|
return completion;
|
|
10842
11012
|
}
|
|
10843
11013
|
/**
|
|
10844
|
-
*
|
|
10845
|
-
*
|
|
10846
|
-
*
|
|
11014
|
+
* The failures this completion is the evidence for (each once), taken off
|
|
11015
|
+
* the waiting list. Their conversations are held from now until the
|
|
11016
|
+
* server has answered (`reporting`): no gate, and a run or turn of theirs
|
|
11017
|
+
* waiting for a slot waits for the answer, so it never starts on the input
|
|
11018
|
+
* the answer is about. Take them before the completed work's slot frees.
|
|
11019
|
+
* One that waited past `AWAITING_EVIDENCE_MS` is dropped instead: a
|
|
11020
|
+
* completion that late says little about the runtime when it failed.
|
|
10847
11021
|
*/
|
|
10848
|
-
|
|
11022
|
+
takeDue(completion) {
|
|
10849
11023
|
const now2 = this.now();
|
|
10850
11024
|
const due = [];
|
|
10851
11025
|
for (const failure of [...this.awaitingEvidence.values()]) {
|
|
@@ -10855,10 +11029,49 @@ invite_id: ${invite.invite_id}`,
|
|
|
10855
11029
|
}
|
|
10856
11030
|
if (evidences(completion, failure)) {
|
|
10857
11031
|
this.awaitingEvidence.delete(failure.conversationId);
|
|
11032
|
+
this.holdForReport(failure);
|
|
10858
11033
|
due.push(failure);
|
|
10859
11034
|
}
|
|
10860
11035
|
}
|
|
10861
|
-
|
|
11036
|
+
return due;
|
|
11037
|
+
}
|
|
11038
|
+
/** Report what `takeDue` took, letting go of each conversation once its answer is in: what waits for it goes on (or was dropped). */
|
|
11039
|
+
async reportDue(due) {
|
|
11040
|
+
const held = [...due];
|
|
11041
|
+
try {
|
|
11042
|
+
while (held.length > 0) {
|
|
11043
|
+
const failure = held[0];
|
|
11044
|
+
await this.reportFailure(failure, "other_run_completed");
|
|
11045
|
+
held.shift();
|
|
11046
|
+
this.letGo([failure]);
|
|
11047
|
+
}
|
|
11048
|
+
} finally {
|
|
11049
|
+
this.letGo(held);
|
|
11050
|
+
}
|
|
11051
|
+
}
|
|
11052
|
+
/** A report for this failure is due: its conversation is held until `letGo` (counted: two reports out hold it until both are answered). */
|
|
11053
|
+
holdForReport(failure) {
|
|
11054
|
+
this.reporting.set(failure.conversationId, (this.reporting.get(failure.conversationId) ?? 0) + 1);
|
|
11055
|
+
}
|
|
11056
|
+
/**
|
|
11057
|
+
* The answers are in (or the report is off): those conversations are no
|
|
11058
|
+
* longer held for it, what waits for them goes on, and a card a cycle left
|
|
11059
|
+
* out meanwhile for a report is read again (only then: a wake for
|
|
11060
|
+
* anything else could spin while a turn runs).
|
|
11061
|
+
*/
|
|
11062
|
+
letGo(failures) {
|
|
11063
|
+
if (failures.length === 0) return;
|
|
11064
|
+
for (const { conversationId } of failures) {
|
|
11065
|
+
const left = (this.reporting.get(conversationId) ?? 0) - 1;
|
|
11066
|
+
if (left > 0) this.reporting.set(conversationId, left);
|
|
11067
|
+
else this.reporting.delete(conversationId);
|
|
11068
|
+
}
|
|
11069
|
+
if (this.stopped) return;
|
|
11070
|
+
if (this.waiting.length > 0) void this.pump();
|
|
11071
|
+
if (this.heldWhileReporting) {
|
|
11072
|
+
this.heldWhileReporting = false;
|
|
11073
|
+
this.wakeFrom("more");
|
|
11074
|
+
}
|
|
10862
11075
|
}
|
|
10863
11076
|
/** An attempt of this kind failed for these conversations (whatever comes of it): see `failingSince`. */
|
|
10864
11077
|
failedAttempt(kind, conversations) {
|
|
@@ -10911,17 +11124,24 @@ invite_id: ${invite.invite_id}`,
|
|
|
10911
11124
|
failure.outcome !== "timed_out" && !this.checkedFailures.has(failure) && this.now() - failure.failedAt <= AWAITING_EVIDENCE_MS && [...failing].every((id) => id === failure.conversationId)
|
|
10912
11125
|
);
|
|
10913
11126
|
if (due.length === 0) return;
|
|
10914
|
-
for (const failure of due) this.checkedFailures.add(failure);
|
|
10915
|
-
const ok = await this.runtimeCheck();
|
|
10916
11127
|
for (const failure of due) {
|
|
10917
|
-
|
|
10918
|
-
|
|
11128
|
+
this.checkedFailures.add(failure);
|
|
11129
|
+
this.holdForReport(failure);
|
|
11130
|
+
}
|
|
11131
|
+
try {
|
|
11132
|
+
const ok = await this.runtimeCheck();
|
|
11133
|
+
for (const failure of due) {
|
|
11134
|
+
if (this.stopped || this.awaitingEvidence.get(failure.conversationId) !== failure) continue;
|
|
11135
|
+
if (!ok) {
|
|
11136
|
+
this.awaitingEvidence.delete(failure.conversationId);
|
|
11137
|
+
continue;
|
|
11138
|
+
}
|
|
11139
|
+
if (![...failing].every((id) => id === failure.conversationId)) continue;
|
|
10919
11140
|
this.awaitingEvidence.delete(failure.conversationId);
|
|
10920
|
-
|
|
11141
|
+
await this.reportFailure(failure, "runtime_check");
|
|
10921
11142
|
}
|
|
10922
|
-
|
|
10923
|
-
this.
|
|
10924
|
-
await this.reportFailure(failure, "runtime_check");
|
|
11143
|
+
} finally {
|
|
11144
|
+
this.letGo(due);
|
|
10925
11145
|
}
|
|
10926
11146
|
}
|
|
10927
11147
|
/** Nothing of this kind is running or queued: the runtime check may be asked now. */
|
|
@@ -10995,10 +11215,29 @@ invite_id: ${invite.invite_id}`,
|
|
|
10995
11215
|
next = this.rerun(failure, result.action === "hidden");
|
|
10996
11216
|
}
|
|
10997
11217
|
}
|
|
10998
|
-
if (result.action === "paused") this.
|
|
11218
|
+
if (result.action === "none" || result.action === "paused") this.holdFailed(failure, result.action);
|
|
10999
11219
|
if (next === "stop" || next === "rerun_capped") this.activeSplit?.skip.add(failure.conversationId);
|
|
11000
11220
|
this.emit({ type: "processing_failure", ...base, result, next });
|
|
11001
11221
|
}
|
|
11222
|
+
/**
|
|
11223
|
+
* The server answered `none` or `paused`: the conversation is held at the
|
|
11224
|
+
* anchor the report read through, so no later cycle (a message elsewhere,
|
|
11225
|
+
* a wake frame, a reconnect, an `unanswered` re-wake, a turn's end) runs it
|
|
11226
|
+
* again on the same input. A newer message moves its anchor and lifts the
|
|
11227
|
+
* hold (`paceCards`); a card read meanwhile leaves the tray, and the hold
|
|
11228
|
+
* with it (`forgetCleared`). What waits for it does not start: a run or
|
|
11229
|
+
* reply turn queued at that anchor (after `paused`, the server's mute, any),
|
|
11230
|
+
* and a reply turn to start again after the gate.
|
|
11231
|
+
*/
|
|
11232
|
+
holdFailed(failure, reason) {
|
|
11233
|
+
const id = failure.conversationId;
|
|
11234
|
+
const anchor = failure.anchor;
|
|
11235
|
+
this.pacer.holdFailed(`${CONVERSATION_KEY}${id}`, anchor, reason);
|
|
11236
|
+
this.dropWaiting(id, reason === "paused" ? null : anchor);
|
|
11237
|
+
this.turnRerunsAfterGate = this.turnRerunsAfterGate.filter(
|
|
11238
|
+
({ reply }) => reply.conversationId !== id || reason !== "paused" && anchorFrom(reply.card) !== anchor
|
|
11239
|
+
);
|
|
11240
|
+
}
|
|
11002
11241
|
/**
|
|
11003
11242
|
* Run the conversation again after a `retry` or `hidden` answer, after the
|
|
11004
11243
|
* others already queued, and say what was done. Its run or reply turn takes
|
|
@@ -11056,14 +11295,20 @@ invite_id: ${invite.invite_id}`,
|
|
|
11056
11295
|
else void this.startReplyTurn(reply, texts, reruns);
|
|
11057
11296
|
}
|
|
11058
11297
|
}
|
|
11059
|
-
/**
|
|
11060
|
-
|
|
11298
|
+
/**
|
|
11299
|
+
* A held conversation: a run or turn still waiting for a slot for it does
|
|
11300
|
+
* not start; with an `anchor`, only one for that anchor (one queued for a
|
|
11301
|
+
* newer message is new input, and goes on).
|
|
11302
|
+
*/
|
|
11303
|
+
dropWaiting(conversationId, anchor) {
|
|
11061
11304
|
for (const entry of [...this.waiting]) {
|
|
11062
11305
|
const turn = entry.handle.turn;
|
|
11063
11306
|
if (turn.kind !== "reply" || turn.conversationId !== conversationId) continue;
|
|
11307
|
+
if (anchor !== null && turn.anchor !== anchor) continue;
|
|
11064
11308
|
this.waiting.splice(this.waiting.indexOf(entry), 1);
|
|
11065
11309
|
this.tracker.end(entry.handle);
|
|
11066
11310
|
entry.drop?.();
|
|
11311
|
+
this.failureCounts.startsHeld += 1;
|
|
11067
11312
|
}
|
|
11068
11313
|
}
|
|
11069
11314
|
rememberGateAlone(conversationId) {
|
|
@@ -11112,6 +11357,7 @@ invite_id: ${invite.invite_id}`,
|
|
|
11112
11357
|
turnsQueued: 0,
|
|
11113
11358
|
heldByTurns: 0,
|
|
11114
11359
|
paced: 0,
|
|
11360
|
+
heldAfterFailure: 0,
|
|
11115
11361
|
chunksOk: 0,
|
|
11116
11362
|
chunksFailed: 0,
|
|
11117
11363
|
splitCallsOk: 0,
|
|
@@ -11207,6 +11453,7 @@ function timeoutOption(value, fallback, name) {
|
|
|
11207
11453
|
return value;
|
|
11208
11454
|
}
|
|
11209
11455
|
function launchKey(launch) {
|
|
11456
|
+
if (launch === "held") return "heldAfterFailure";
|
|
11210
11457
|
return launch === "started" ? "turnsStarted" : launch === "queued" ? "turnsQueued" : "turnsRefused";
|
|
11211
11458
|
}
|
|
11212
11459
|
function trayInvites(tray) {
|
|
@@ -11691,7 +11938,7 @@ var HOUR = 60 * MIN;
|
|
|
11691
11938
|
var DAY = 24 * HOUR;
|
|
11692
11939
|
var MAX_ATTACHMENT_SIZE = 25 * 1024 * 1024;
|
|
11693
11940
|
|
|
11694
|
-
// node_modules/.pnpm/@agentchatme+agent-core@0.7.
|
|
11941
|
+
// node_modules/.pnpm/@agentchatme+agent-core@0.7.1/node_modules/@agentchatme/agent-core/dist/chunk-AQTRC7G4.js
|
|
11695
11942
|
import * as path22 from "path";
|
|
11696
11943
|
import * as path32 from "path";
|
|
11697
11944
|
import * as path4 from "path";
|
|
@@ -15968,6 +16215,7 @@ function writeIntegrationStatus(home, status) {
|
|
|
15968
16215
|
log.debug(`integration status write failed: ${String(err)}`);
|
|
15969
16216
|
}
|
|
15970
16217
|
}
|
|
16218
|
+
var INTEGRATION_STATUS_STALE_MS = 3 * 6e4;
|
|
15971
16219
|
function isRunnerFactory(source) {
|
|
15972
16220
|
return typeof source.create === "function";
|
|
15973
16221
|
}
|
|
@@ -16384,8 +16632,8 @@ function standbyWaiting(lockFile, home, now2 = Date.now()) {
|
|
|
16384
16632
|
return false;
|
|
16385
16633
|
}
|
|
16386
16634
|
|
|
16387
|
-
// node_modules/.pnpm/@agentchatme+agent-core@0.7.
|
|
16388
|
-
var VERSION2 = "0.7.
|
|
16635
|
+
// node_modules/.pnpm/@agentchatme+agent-core@0.7.1/node_modules/@agentchatme/agent-core/dist/chunk-4PCDVXAR.js
|
|
16636
|
+
var VERSION2 = "0.7.1";
|
|
16389
16637
|
var HOSTED_MCP_PATH2 = integration_exports.HOSTED_MCP_PATH;
|
|
16390
16638
|
function hostedMcpUrl2(apiBase) {
|
|
16391
16639
|
return integration_exports.hostedMcpUrl(apiBase);
|
|
@@ -16452,7 +16700,7 @@ function runProbe(command, args, options) {
|
|
|
16452
16700
|
});
|
|
16453
16701
|
}
|
|
16454
16702
|
|
|
16455
|
-
// node_modules/.pnpm/@agentchatme+agent-core@0.7.
|
|
16703
|
+
// node_modules/.pnpm/@agentchatme+agent-core@0.7.1/node_modules/@agentchatme/agent-core/dist/index.js
|
|
16456
16704
|
var StateSchema = external_exports.object({
|
|
16457
16705
|
// Set when the user has said "not now" to setting up a handle. PERMANENT
|
|
16458
16706
|
// until they change their mind, because the prompt that needs suppressing
|
|
@@ -16471,7 +16719,7 @@ var MARKER_LINES = /* @__PURE__ */ new Set([
|
|
|
16471
16719
|
var UTF8 = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
16472
16720
|
var NO_TEXTS = Object.freeze({ identityLine: null, identityLineTemplate: null, manual: null });
|
|
16473
16721
|
|
|
16474
|
-
// node_modules/.pnpm/@agentchatme+agent-core@0.7.
|
|
16722
|
+
// node_modules/.pnpm/@agentchatme+agent-core@0.7.1/node_modules/@agentchatme/agent-core/dist/daemon-entry.js
|
|
16475
16723
|
import * as path23 from "path";
|
|
16476
16724
|
import * as fs3 from "fs";
|
|
16477
16725
|
import * as path9 from "path";
|
|
@@ -16911,14 +17159,15 @@ ${this.options.manualPointer}` : request.prompt,
|
|
|
16911
17159
|
}
|
|
16912
17160
|
if (outcome.state !== "ok") {
|
|
16913
17161
|
log.warn(
|
|
16914
|
-
`run ${outcome.state} ${subject}${outcome.detail ? `: ${outcome.detail}` : ""} \u2014 ${kind
|
|
17162
|
+
`run ${outcome.state} ${subject}${outcome.detail ? `: ${outcome.detail}` : ""} \u2014 ${kind !== "conversation" ? "the cards stay on the tray; the next wake (or the server's re-wake) finds them" : outcome.state === "failed" && outcome.silent === true ? "its card stays on the tray; a silent failure counts as a timeout: it is reported (could not process) only once another conversation's run completes, and the server decides what follows" : "its card stays on the tray; if the runtime otherwise works, the failure is reported (could not process) and the server decides what follows"}`
|
|
16915
17163
|
);
|
|
16916
17164
|
}
|
|
16917
17165
|
this.noteRunHealth(outcome, this.lastRun.ended_at);
|
|
16918
17166
|
this.writeStatus();
|
|
16919
17167
|
if (outcome.state === "ok") return { status: "completed" };
|
|
16920
17168
|
if (outcome.state === "not_started") return { status: "not_started", ...outcome.detail !== void 0 ? { detail: outcome.detail } : {} };
|
|
16921
|
-
|
|
17169
|
+
const timedOut = outcome.state === "timed_out" || outcome.state === "failed" && outcome.silent === true;
|
|
17170
|
+
return { status: "failed", ...timedOut ? { timedOut: true } : {}, ...outcome.detail !== void 0 ? { detail: outcome.detail } : {} };
|
|
16922
17171
|
}
|
|
16923
17172
|
/**
|
|
16924
17173
|
* The runner's runtime check (a minimal model call, no peer content, no
|
|
@@ -17095,7 +17344,7 @@ ${this.options.manualPointer}` : request.prompt,
|
|
|
17095
17344
|
if (result === null) {
|
|
17096
17345
|
log.warn(`could not process: ${what} \u2014 the report failed (${event.error ?? "no detail"}); nothing more is done for it now: its card stays on the tray and the server re-wakes it`);
|
|
17097
17346
|
} else {
|
|
17098
|
-
const hidden = result.hidden_message_ids.length;
|
|
17347
|
+
const hidden = result.hidden_count ?? result.hidden_message_ids.length;
|
|
17099
17348
|
const answered = result.action === "retry" ? "retry (the first failure for these messages)" : result.action === "hidden" ? `hidden (${hidden} message(s) are now a note for this agent, still unread)` : result.action === "paused" ? `paused until ${result.paused_until ?? "?"}${hidden > 0 ? ` (${hidden} more message(s) hidden)` : ""} \u2014 no run starts there until then` : "none (nothing left to act on)";
|
|
17100
17349
|
const next = event.next === "rerun" ? "it runs again after the others" : event.next === "running" ? "its next run is under way already" : event.next === "rerun_capped" ? "not run again in this cycle (3 re-runs already); the server re-wakes it" : "nothing more for it";
|
|
17101
17350
|
(result.action === "paused" ? log.warn : log.info)(`could not process: ${what} \u2192 server: ${answered}; ${next}`);
|
|
@@ -17469,7 +17718,7 @@ import * as os3 from "os";
|
|
|
17469
17718
|
import * as path10 from "path";
|
|
17470
17719
|
|
|
17471
17720
|
// src/version.ts
|
|
17472
|
-
var VERSION3 = "0.7.
|
|
17721
|
+
var VERSION3 = "0.7.2";
|
|
17473
17722
|
|
|
17474
17723
|
// src/host.ts
|
|
17475
17724
|
function codexHome() {
|
|
@@ -17501,7 +17750,7 @@ var CLIENT = { runtime: "codex", version: VERSION3 };
|
|
|
17501
17750
|
var MCP_SERVER_NAME = "agentchat";
|
|
17502
17751
|
var API_KEY_ENV = "AGENTCHAT_API_KEY";
|
|
17503
17752
|
|
|
17504
|
-
// node_modules/.pnpm/@agentchatme+agent-core@0.7.
|
|
17753
|
+
// node_modules/.pnpm/@agentchatme+agent-core@0.7.1/node_modules/@agentchatme/agent-core/dist/presets.js
|
|
17505
17754
|
import * as fs22 from "fs";
|
|
17506
17755
|
import * as os4 from "os";
|
|
17507
17756
|
import * as path11 from "path";
|
|
@@ -17835,8 +18084,18 @@ function claudeProfileArgs(profile, workdir) {
|
|
|
17835
18084
|
}
|
|
17836
18085
|
var RUNTIME_CHECK_SETTINGS = JSON.stringify({
|
|
17837
18086
|
env: { CLAUDE_CODE_DISABLE_CLAUDE_MDS: "1", CLAUDE_CODE_DISABLE_AUTO_MEMORY: "1" },
|
|
17838
|
-
disableAllHooks: true
|
|
18087
|
+
disableAllHooks: true,
|
|
18088
|
+
verbose: false,
|
|
18089
|
+
viewMode: "default",
|
|
18090
|
+
language: "english"
|
|
17839
18091
|
});
|
|
18092
|
+
function lastResultMessage(messages) {
|
|
18093
|
+
for (let i = messages.length - 1; i >= 0; i -= 1) {
|
|
18094
|
+
const m = messages[i];
|
|
18095
|
+
if (m !== null && typeof m === "object" && !Array.isArray(m) && m["type"] === "result") return m;
|
|
18096
|
+
}
|
|
18097
|
+
return null;
|
|
18098
|
+
}
|
|
17840
18099
|
function claudeRuntimeCheckJudge(stdout) {
|
|
17841
18100
|
const text2 = stdout.trim();
|
|
17842
18101
|
let parsed = null;
|
|
@@ -17848,9 +18107,22 @@ function claudeRuntimeCheckJudge(stdout) {
|
|
|
17848
18107
|
parsed = null;
|
|
17849
18108
|
}
|
|
17850
18109
|
}
|
|
18110
|
+
if (Array.isArray(parsed)) {
|
|
18111
|
+
parsed = lastResultMessage(parsed);
|
|
18112
|
+
if (parsed === null) return "its answer is a list of messages with no result";
|
|
18113
|
+
}
|
|
17851
18114
|
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return "its answer is not a JSON result";
|
|
17852
18115
|
const r = parsed;
|
|
17853
|
-
if (r["type"] === "result" && r["subtype"] === "success" && r["is_error"] === false)
|
|
18116
|
+
if (r["type"] === "result" && r["subtype"] === "success" && r["is_error"] === false) {
|
|
18117
|
+
const turns = r["num_turns"];
|
|
18118
|
+
if (typeof turns !== "number" || !(turns >= 1)) return `the result has no turn (num_turns ${typeof turns === "number" ? turns : "?"})`;
|
|
18119
|
+
const usage = r["usage"];
|
|
18120
|
+
if (usage !== void 0 && usage !== null) {
|
|
18121
|
+
const tokens = typeof usage === "object" && !Array.isArray(usage) ? usage["output_tokens"] : void 0;
|
|
18122
|
+
if (typeof tokens !== "number" || !(tokens >= 1)) return `the result has no output (usage.output_tokens ${typeof tokens === "number" ? tokens : "?"})`;
|
|
18123
|
+
}
|
|
18124
|
+
return null;
|
|
18125
|
+
}
|
|
17854
18126
|
const facts = [
|
|
17855
18127
|
`type ${typeof r["type"] === "string" ? r["type"] : "?"}`,
|
|
17856
18128
|
`subtype ${typeof r["subtype"] === "string" ? r["subtype"] : "?"}`,
|
|
@@ -18336,8 +18608,6 @@ function codexRuntimeCheckArgs(dir, agentchatUrl) {
|
|
|
18336
18608
|
"--sandbox",
|
|
18337
18609
|
"read-only",
|
|
18338
18610
|
"-c",
|
|
18339
|
-
'model_reasoning_effort="low"',
|
|
18340
|
-
"-c",
|
|
18341
18611
|
'web_search="disabled"',
|
|
18342
18612
|
...CODEX_RUNTIME_CHECK_DISABLED_FEATURES.flatMap((feature) => ["--disable", feature]),
|
|
18343
18613
|
...agentchatUrl !== void 0 ? ["-c", `${table}.url=${JSON.stringify(agentchatUrl)}`] : [],
|
|
@@ -18349,6 +18619,37 @@ function codexRuntimeCheckArgs(dir, agentchatUrl) {
|
|
|
18349
18619
|
function codexRuntimeCheckWorkdir(codexHome2) {
|
|
18350
18620
|
return path24.join(codexHome2, RUNTIME_CHECK_DIR);
|
|
18351
18621
|
}
|
|
18622
|
+
function jsonObject(value) {
|
|
18623
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
18624
|
+
}
|
|
18625
|
+
function codexRuntimeCheckJudge(stdout) {
|
|
18626
|
+
let events = 0;
|
|
18627
|
+
let completed = false;
|
|
18628
|
+
let failed = false;
|
|
18629
|
+
let answered = false;
|
|
18630
|
+
for (const line of stdout.split(/\r?\n/)) {
|
|
18631
|
+
if (line.trim().length === 0) continue;
|
|
18632
|
+
let event;
|
|
18633
|
+
try {
|
|
18634
|
+
event = jsonObject(JSON.parse(line));
|
|
18635
|
+
} catch {
|
|
18636
|
+
continue;
|
|
18637
|
+
}
|
|
18638
|
+
if (event === null) continue;
|
|
18639
|
+
events += 1;
|
|
18640
|
+
if (event["type"] === "turn.completed") completed = true;
|
|
18641
|
+
else if (event["type"] === "turn.failed") failed = true;
|
|
18642
|
+
else if (event["type"] === "item.completed") {
|
|
18643
|
+
const item = jsonObject(event["item"]);
|
|
18644
|
+
if (item !== null && item["type"] === "agent_message" && typeof item["text"] === "string" && item["text"].trim().length > 0) answered = true;
|
|
18645
|
+
}
|
|
18646
|
+
}
|
|
18647
|
+
if (events === 0) return "its answer holds no JSON event";
|
|
18648
|
+
if (failed) return "the turn failed (turn.failed)";
|
|
18649
|
+
if (!completed) return "the turn did not complete (no turn.completed)";
|
|
18650
|
+
if (!answered) return "the turn completed with no agent message";
|
|
18651
|
+
return null;
|
|
18652
|
+
}
|
|
18352
18653
|
function codexClientHeadersToml(clientVersion = VERSION2) {
|
|
18353
18654
|
const pairs = Object.entries(clientHeadersOf({ runtime: "codex", version: clientVersion })).map(([name, value]) => `${JSON.stringify(name)} = ${JSON.stringify(value)}`);
|
|
18354
18655
|
return `{ ${pairs.join(", ")} }`;
|
|
@@ -18674,9 +18975,11 @@ var CodexRunner = class {
|
|
|
18674
18975
|
/**
|
|
18675
18976
|
* Does the model answer right now, through this runner's binary, sign-in,
|
|
18676
18977
|
* CODEX_HOME and environment? One `codex exec` with a fixed prompt in its
|
|
18677
|
-
* own empty folder, read-only, with the hosted AgentChat server switched
|
|
18678
|
-
*
|
|
18679
|
-
*
|
|
18978
|
+
* own empty folder, read-only, with the hosted AgentChat server switched
|
|
18979
|
+
* off and the user's hooks on, as in the runs (`codexRuntimeCheckArgs`),
|
|
18980
|
+
* and no key in its environment; ok only on exit 0 with a completed turn
|
|
18981
|
+
* that holds an agent message (`codexRuntimeCheckJudge`). Its output is
|
|
18982
|
+
* read for that alone and never logged. Never throws.
|
|
18680
18983
|
*/
|
|
18681
18984
|
async checkRuntime(options = {}) {
|
|
18682
18985
|
if (this.options.refuse !== void 0) return { ok: false, detail: this.options.refuse };
|
|
@@ -18689,6 +18992,8 @@ var CodexRunner = class {
|
|
|
18689
18992
|
// The runs' environment; runRuntimeCheck takes every key variable out, this runner's own included.
|
|
18690
18993
|
env: this.env(),
|
|
18691
18994
|
keyEnv: this.options.keyEnv,
|
|
18995
|
+
// Exit 0 is not enough: the events must show a completed turn with the model's answer.
|
|
18996
|
+
judge: codexRuntimeCheckJudge,
|
|
18692
18997
|
...options.signal !== void 0 ? { signal: options.signal } : {}
|
|
18693
18998
|
});
|
|
18694
18999
|
}
|