@agentchatme/claude-code 0.0.1394114111111111 → 0.0.1394114111111112
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/daemon-main.js +133 -25
- package/dist/daemon-main.js.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/daemon-main.js
CHANGED
|
@@ -4227,7 +4227,7 @@ var require_cross_spawn = __commonJS({
|
|
|
4227
4227
|
import { parseArgs } from "util";
|
|
4228
4228
|
import * as path8 from "path";
|
|
4229
4229
|
|
|
4230
|
-
// node_modules/.pnpm/@agentchatme+agent-core@0.0.
|
|
4230
|
+
// node_modules/.pnpm/@agentchatme+agent-core@0.0.131311111111/node_modules/@agentchatme/agent-core/dist/chunk-CRHJICEC.js
|
|
4231
4231
|
import * as fs from "fs";
|
|
4232
4232
|
import * as path from "path";
|
|
4233
4233
|
import * as fs2 from "fs";
|
|
@@ -4258,7 +4258,7 @@ var log = {
|
|
|
4258
4258
|
info: (msg) => emit("info", msg),
|
|
4259
4259
|
debug: (msg) => emit("debug", msg)
|
|
4260
4260
|
};
|
|
4261
|
-
var VERSION = "0.0.
|
|
4261
|
+
var VERSION = "0.0.131311111111";
|
|
4262
4262
|
var CODING_AGENTS_CLIENT_IDENTITY = {
|
|
4263
4263
|
name: "coding_agents",
|
|
4264
4264
|
version: VERSION
|
|
@@ -8511,7 +8511,7 @@ function idle(home) {
|
|
|
8511
8511
|
}
|
|
8512
8512
|
}
|
|
8513
8513
|
|
|
8514
|
-
// node_modules/.pnpm/@agentchatme+agent-core@0.0.
|
|
8514
|
+
// node_modules/.pnpm/@agentchatme+agent-core@0.0.131311111111/node_modules/@agentchatme/agent-core/dist/daemon-entry.js
|
|
8515
8515
|
init_wrapper();
|
|
8516
8516
|
import { EventEmitter } from "events";
|
|
8517
8517
|
import * as path32 from "path";
|
|
@@ -9004,6 +9004,10 @@ var FOREGROUND_RECHECK_MS = positiveBoundedEnv(
|
|
|
9004
9004
|
"AGENTCHATD_FOREGROUND_RECHECK_MS",
|
|
9005
9005
|
2e3
|
|
9006
9006
|
);
|
|
9007
|
+
var FOREGROUND_RECHECK_MAX_MS = Math.max(
|
|
9008
|
+
FOREGROUND_RECHECK_MS,
|
|
9009
|
+
positiveBoundedEnv("AGENTCHATD_FOREGROUND_RECHECK_MAX_MS", 15e3)
|
|
9010
|
+
);
|
|
9007
9011
|
var delay = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
9008
9012
|
function retryDelay(attempt) {
|
|
9009
9013
|
return Math.min(RETRY_BASE_MS * 2 ** Math.min(20, Math.max(0, attempt - 1)), RETRY_MAX_MS);
|
|
@@ -9069,6 +9073,11 @@ var Daemon = class {
|
|
|
9069
9073
|
// conversation shares this window so a large multi-conversation backlog
|
|
9070
9074
|
// cannot turn into one polling loop per conversation.
|
|
9071
9075
|
foregroundClaimsBlockedUntil = 0;
|
|
9076
|
+
foregroundDeferralRounds = 0;
|
|
9077
|
+
// Log one start and one resolution per deferred conversation. Repeated
|
|
9078
|
+
// rechecks remain visible through the resolution count without flooding the
|
|
9079
|
+
// resident daemon log every few seconds.
|
|
9080
|
+
foregroundDeferrals = /* @__PURE__ */ new Map();
|
|
9072
9081
|
stopping = false;
|
|
9073
9082
|
heartbeatTimer = null;
|
|
9074
9083
|
async start() {
|
|
@@ -9157,23 +9166,29 @@ var Daemon = class {
|
|
|
9157
9166
|
);
|
|
9158
9167
|
const claimedCount = claim.claimedCount;
|
|
9159
9168
|
let batch = candidates.slice(0, claimedCount);
|
|
9169
|
+
if (!claim.deferred && claimedCount > 0) {
|
|
9170
|
+
this.finishForegroundDeferral(conversationId, "daemon-resumed");
|
|
9171
|
+
}
|
|
9160
9172
|
if (claimedCount < candidates.length) {
|
|
9161
9173
|
if (claim.deferred) {
|
|
9162
|
-
this.foregroundClaimsBlockedUntil = Math.max(
|
|
9163
|
-
this.foregroundClaimsBlockedUntil,
|
|
9164
|
-
Date.now() + FOREGROUND_RECHECK_MS
|
|
9165
|
-
);
|
|
9166
9174
|
const deferred = candidates.slice(claimedCount);
|
|
9167
9175
|
if (deferred.length > 0) {
|
|
9168
9176
|
const current = this.convQueues.get(conversationId) ?? [];
|
|
9169
9177
|
this.convQueues.set(conversationId, [...deferred, ...current]);
|
|
9170
9178
|
}
|
|
9171
|
-
|
|
9172
|
-
|
|
9173
|
-
|
|
9179
|
+
const deferredHead = deferred[0];
|
|
9180
|
+
if (deferredHead) {
|
|
9181
|
+
this.noteForegroundDeferral(conversationId, deferredHead.id);
|
|
9182
|
+
}
|
|
9174
9183
|
} else {
|
|
9175
9184
|
const conflict = candidates[claimedCount];
|
|
9176
|
-
|
|
9185
|
+
const summarized = this.finishForegroundDeferral(
|
|
9186
|
+
conversationId,
|
|
9187
|
+
"foreground-owned"
|
|
9188
|
+
);
|
|
9189
|
+
if (!summarized) {
|
|
9190
|
+
log.info(`msg ${conflict.id}: claimed by the live session \u2014 standing down`);
|
|
9191
|
+
}
|
|
9177
9192
|
this.seen.delete(conflict.id);
|
|
9178
9193
|
this.markNoLongerPending();
|
|
9179
9194
|
const unclaimedTail = candidates.slice(claimedCount + 1);
|
|
@@ -9190,10 +9205,6 @@ var Daemon = class {
|
|
|
9190
9205
|
const lost = batch.slice(renewed.claimedCount);
|
|
9191
9206
|
batch = batch.slice(0, renewed.claimedCount);
|
|
9192
9207
|
if (renewed.deferred) {
|
|
9193
|
-
this.foregroundClaimsBlockedUntil = Math.max(
|
|
9194
|
-
this.foregroundClaimsBlockedUntil,
|
|
9195
|
-
Date.now() + FOREGROUND_RECHECK_MS
|
|
9196
|
-
);
|
|
9197
9208
|
for (const row of lost) {
|
|
9198
9209
|
const state = this.seen.get(row.id);
|
|
9199
9210
|
if (state) {
|
|
@@ -9203,9 +9214,17 @@ var Daemon = class {
|
|
|
9203
9214
|
}
|
|
9204
9215
|
const current = this.convQueues.get(conversationId) ?? [];
|
|
9205
9216
|
this.convQueues.set(conversationId, [...lost, ...current]);
|
|
9217
|
+
const lostHead = lost[0];
|
|
9218
|
+
if (lostHead) this.noteForegroundDeferral(conversationId, lostHead.id);
|
|
9206
9219
|
} else {
|
|
9207
9220
|
const conflict = lost[0];
|
|
9208
|
-
|
|
9221
|
+
const summarized = this.finishForegroundDeferral(
|
|
9222
|
+
conversationId,
|
|
9223
|
+
"foreground-owned"
|
|
9224
|
+
);
|
|
9225
|
+
if (!summarized) {
|
|
9226
|
+
log.info(`msg ${conflict.id}: renewal lost to a live session \u2014 standing down`);
|
|
9227
|
+
}
|
|
9209
9228
|
this.seen.delete(conflict.id);
|
|
9210
9229
|
this.markNoLongerPending();
|
|
9211
9230
|
const tail = lost.slice(1);
|
|
@@ -9285,6 +9304,41 @@ var Daemon = class {
|
|
|
9285
9304
|
await delay(remaining);
|
|
9286
9305
|
}
|
|
9287
9306
|
}
|
|
9307
|
+
noteForegroundDeferral(conversationId, messageId) {
|
|
9308
|
+
const now = Date.now();
|
|
9309
|
+
if (now >= this.foregroundClaimsBlockedUntil) {
|
|
9310
|
+
this.foregroundDeferralRounds += 1;
|
|
9311
|
+
}
|
|
9312
|
+
const retryMs = Math.min(
|
|
9313
|
+
FOREGROUND_RECHECK_MS * 2 ** Math.min(20, Math.max(0, this.foregroundDeferralRounds - 1)),
|
|
9314
|
+
FOREGROUND_RECHECK_MAX_MS
|
|
9315
|
+
);
|
|
9316
|
+
this.foregroundClaimsBlockedUntil = Math.max(
|
|
9317
|
+
this.foregroundClaimsBlockedUntil,
|
|
9318
|
+
now + retryMs
|
|
9319
|
+
);
|
|
9320
|
+
const prior = this.foregroundDeferrals.get(conversationId);
|
|
9321
|
+
if (prior) {
|
|
9322
|
+
prior.claims += 1;
|
|
9323
|
+
return;
|
|
9324
|
+
}
|
|
9325
|
+
this.foregroundDeferrals.set(conversationId, { messageId, claims: 1 });
|
|
9326
|
+
log.info(`msg ${messageId}: foreground turn owns priority \u2014 daemon waiting`);
|
|
9327
|
+
}
|
|
9328
|
+
finishForegroundDeferral(conversationId, outcome) {
|
|
9329
|
+
const deferred = this.foregroundDeferrals.get(conversationId);
|
|
9330
|
+
if (!deferred) return false;
|
|
9331
|
+
this.foregroundDeferrals.delete(conversationId);
|
|
9332
|
+
if (this.foregroundDeferrals.size === 0) {
|
|
9333
|
+
this.foregroundDeferralRounds = 0;
|
|
9334
|
+
this.foregroundClaimsBlockedUntil = 0;
|
|
9335
|
+
}
|
|
9336
|
+
const resolution = outcome === "daemon-resumed" ? "foreground priority ended \u2014 daemon resumed" : "foreground session claimed delivery \u2014 daemon stood down";
|
|
9337
|
+
log.info(
|
|
9338
|
+
`msg ${deferred.messageId}: ${resolution} after ${deferred.claims} deferred claim(s)`
|
|
9339
|
+
);
|
|
9340
|
+
return true;
|
|
9341
|
+
}
|
|
9288
9342
|
turnContext(batch) {
|
|
9289
9343
|
const focus = batch[batch.length - 1];
|
|
9290
9344
|
const oldest = batch[0];
|
|
@@ -9529,7 +9583,7 @@ import * as os from "os";
|
|
|
9529
9583
|
import * as path6 from "path";
|
|
9530
9584
|
import * as crypto2 from "crypto";
|
|
9531
9585
|
|
|
9532
|
-
// node_modules/.pnpm/@agentchatme+agent-core@0.0.
|
|
9586
|
+
// node_modules/.pnpm/@agentchatme+agent-core@0.0.131311111111/node_modules/@agentchatme/agent-core/dist/index.js
|
|
9533
9587
|
var import_cross_spawn = __toESM(require_cross_spawn(), 1);
|
|
9534
9588
|
var SESSION_TTL_MS = 48 * 60 * 60 * 1e3;
|
|
9535
9589
|
var SessionStateSchema = external_exports.object({
|
|
@@ -9561,7 +9615,7 @@ var spawnCommand = import_cross_spawn.default;
|
|
|
9561
9615
|
var spawnCommandSync = import_cross_spawn.default.sync;
|
|
9562
9616
|
|
|
9563
9617
|
// src/version.ts
|
|
9564
|
-
var VERSION2 = "0.0.
|
|
9618
|
+
var VERSION2 = "0.0.1394114111111112";
|
|
9565
9619
|
|
|
9566
9620
|
// src/runtime-version.ts
|
|
9567
9621
|
var MIN_CLAUDE_CODE_VERSION = "2.1.219";
|
|
@@ -9583,6 +9637,7 @@ function semverAtLeast(actual, minimum) {
|
|
|
9583
9637
|
var TURN_TIMEOUT_MS = 24e4;
|
|
9584
9638
|
var MAX_EVENT_TAIL_CHARS = 1024 * 1024;
|
|
9585
9639
|
var MAX_STDERR_CHARS = 16384;
|
|
9640
|
+
var MAX_DIAGNOSTIC_CHARS = 500;
|
|
9586
9641
|
var AGENTCHAT_MCP_PACKAGE = "@agentchatme/mcp@0.1.1121411";
|
|
9587
9642
|
var AGENTCHAT_TOOL_ALLOW = "mcp__agentchat__*";
|
|
9588
9643
|
var PARENT_ENV_KEYS = [
|
|
@@ -9668,6 +9723,44 @@ function turnIdempotencyKey(ctx, identityNamespace) {
|
|
|
9668
9723
|
return `ac_turn_${digest}`;
|
|
9669
9724
|
}
|
|
9670
9725
|
var SEND_TOOL = "mcp__agentchat__agentchat_send_message";
|
|
9726
|
+
function boundedDiagnostic(value) {
|
|
9727
|
+
return value.replace(/\u001B\[[0-?]*[ -/]*[@-~]/g, "").replace(/\b(api[_ -]?key\s*[:=]\s*)\S+/gi, "$1[redacted]").replace(/\b(Bearer)\s+[A-Za-z0-9._~-]{8,}\b/gi, "$1 [redacted]").replace(/\bac_[A-Za-z0-9_-]{8,}\b/g, "[redacted AgentChat key]").replace(/\bsk-ant-[A-Za-z0-9_-]{8,}\b/g, "[redacted Anthropic key]").replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/g, "").replace(/\s+/g, " ").trim().slice(0, MAX_DIAGNOSTIC_CHARS);
|
|
9728
|
+
}
|
|
9729
|
+
function diagnosticToken(value) {
|
|
9730
|
+
if (typeof value !== "string" && typeof value !== "number") return null;
|
|
9731
|
+
const rendered = String(value).trim();
|
|
9732
|
+
return /^[A-Za-z0-9_.:/-]{1,80}$/.test(rendered) ? rendered : null;
|
|
9733
|
+
}
|
|
9734
|
+
function nestedErrorDetail(value) {
|
|
9735
|
+
if (typeof value === "string") return boundedDiagnostic(value) || null;
|
|
9736
|
+
if (typeof value !== "object" || value === null) return null;
|
|
9737
|
+
const error = value;
|
|
9738
|
+
const labels = ["type", "code", "name", "status", "status_code"].flatMap((key) => {
|
|
9739
|
+
const token = diagnosticToken(error[key]);
|
|
9740
|
+
return token === null ? [] : [`${key}=${token}`];
|
|
9741
|
+
});
|
|
9742
|
+
const message = typeof error["message"] === "string" ? boundedDiagnostic(error["message"]) : "";
|
|
9743
|
+
return boundedDiagnostic(
|
|
9744
|
+
[...labels, ...message ? [message] : []].join(labels.length > 0 ? "; " : "")
|
|
9745
|
+
) || null;
|
|
9746
|
+
}
|
|
9747
|
+
function controlFailureDetail(record) {
|
|
9748
|
+
const type = diagnosticToken(record["type"]);
|
|
9749
|
+
const subtype = diagnosticToken(record["subtype"]);
|
|
9750
|
+
const terminalFailure = type === "result" && (record["is_error"] === true || subtype !== null && subtype !== "success");
|
|
9751
|
+
const controlFailure = type === "error" || type === "system" && subtype !== null && /error|fail/i.test(subtype);
|
|
9752
|
+
if (!terminalFailure && !controlFailure) return null;
|
|
9753
|
+
const label = terminalFailure ? `terminal result ${subtype ?? "reported an error"}` : `stream ${[type, subtype].filter(Boolean).join("/") || "error"}`;
|
|
9754
|
+
const error = nestedErrorDetail(record["error"]);
|
|
9755
|
+
const permissionDenials = Array.isArray(record["permission_denials"]) ? record["permission_denials"].length : 0;
|
|
9756
|
+
return boundedDiagnostic(
|
|
9757
|
+
[
|
|
9758
|
+
label,
|
|
9759
|
+
...error ? [error] : [],
|
|
9760
|
+
...permissionDenials > 0 ? [`${permissionDenials} permission denial(s)`] : []
|
|
9761
|
+
].join("; ")
|
|
9762
|
+
);
|
|
9763
|
+
}
|
|
9671
9764
|
var ClaudeTurnEvents = class {
|
|
9672
9765
|
initSeen = false;
|
|
9673
9766
|
mcpConnected = false;
|
|
@@ -9678,9 +9771,11 @@ var ClaudeTurnEvents = class {
|
|
|
9678
9771
|
successfulSends = 0;
|
|
9679
9772
|
sendFailure = null;
|
|
9680
9773
|
runtimeAuthFailure = null;
|
|
9774
|
+
controlFailure = null;
|
|
9681
9775
|
consume(event) {
|
|
9682
9776
|
if (typeof event !== "object" || event === null) return;
|
|
9683
9777
|
const record = event;
|
|
9778
|
+
this.controlFailure ??= controlFailureDetail(record);
|
|
9684
9779
|
if (record["type"] === "system" && record["subtype"] === "init") {
|
|
9685
9780
|
this.initSeen = true;
|
|
9686
9781
|
const servers = Array.isArray(record["mcp_servers"]) ? record["mcp_servers"] : [];
|
|
@@ -9697,8 +9792,8 @@ var ClaudeTurnEvents = class {
|
|
|
9697
9792
|
(candidate) => typeof candidate === "object" && candidate !== null && candidate["name"] === "agentchat"
|
|
9698
9793
|
);
|
|
9699
9794
|
if (error !== void 0) {
|
|
9700
|
-
const message = typeof error["message"] === "string" ?
|
|
9701
|
-
this.initFailure = `AgentChat MCP configuration was skipped${message}`;
|
|
9795
|
+
const message = typeof error["message"] === "string" ? boundedDiagnostic(error["message"]) : "";
|
|
9796
|
+
this.initFailure = `AgentChat MCP configuration was skipped${message ? `: ${message}` : ""}`;
|
|
9702
9797
|
}
|
|
9703
9798
|
}
|
|
9704
9799
|
if (record["type"] === "assistant") {
|
|
@@ -9708,7 +9803,7 @@ var ClaudeTurnEvents = class {
|
|
|
9708
9803
|
if (typeof block !== "object" || block === null) continue;
|
|
9709
9804
|
const tool = block;
|
|
9710
9805
|
if (tool["type"] === "text" && typeof tool["text"] === "string" && fatalRuntimeError(tool["text"])) {
|
|
9711
|
-
this.runtimeAuthFailure = tool["text"]
|
|
9806
|
+
this.runtimeAuthFailure = boundedDiagnostic(tool["text"]);
|
|
9712
9807
|
}
|
|
9713
9808
|
if (tool["type"] === "tool_use" && tool["name"] === SEND_TOOL && typeof tool["id"] === "string") {
|
|
9714
9809
|
this.pending.add(tool["id"]);
|
|
@@ -9778,6 +9873,20 @@ var ClaudeTurnEvents = class {
|
|
|
9778
9873
|
fatalDetail() {
|
|
9779
9874
|
return this.runtimeAuthFailure;
|
|
9780
9875
|
}
|
|
9876
|
+
/** A bounded, non-peer-text explanation of how far the Claude protocol got
|
|
9877
|
+
* before a non-zero process exit. */
|
|
9878
|
+
exitDetail() {
|
|
9879
|
+
if (this.runtimeAuthFailure) return this.runtimeAuthFailure;
|
|
9880
|
+
if (this.controlFailure) return this.controlFailure;
|
|
9881
|
+
if (this.initFailure) return boundedDiagnostic(this.initFailure);
|
|
9882
|
+
if (this.terminalSeen && this.terminalFailure) {
|
|
9883
|
+
return "Claude emitted a failed terminal result";
|
|
9884
|
+
}
|
|
9885
|
+
if (this.initSeen) {
|
|
9886
|
+
return this.mcpConnected ? "Claude exited after initialization with AgentChat MCP connected but no successful terminal result" : "Claude exited after initialization before AgentChat MCP connected";
|
|
9887
|
+
}
|
|
9888
|
+
return "Claude exited before the system/init event";
|
|
9889
|
+
}
|
|
9781
9890
|
};
|
|
9782
9891
|
function killProcessTree(child) {
|
|
9783
9892
|
if (child.pid === void 0) return;
|
|
@@ -9802,7 +9911,8 @@ function fatalRuntimeError(detail) {
|
|
|
9802
9911
|
}
|
|
9803
9912
|
function classifyClaudeExit(code, stderr, events) {
|
|
9804
9913
|
const structured = events.fatalDetail();
|
|
9805
|
-
const
|
|
9914
|
+
const diagnostics = [structured, boundedDiagnostic(stderr), events.exitDetail()].filter((value) => Boolean(value)).filter((value, index, values) => values.indexOf(value) === index);
|
|
9915
|
+
const diagnostic = boundedDiagnostic(diagnostics.join("; "));
|
|
9806
9916
|
const detail = `claude exited ${code ?? "without a status"}${diagnostic ? `: ${diagnostic}` : ""}`;
|
|
9807
9917
|
return {
|
|
9808
9918
|
ok: false,
|
|
@@ -9911,9 +10021,7 @@ var ClaudeAdapter = class {
|
|
|
9911
10021
|
if (buf.length > MAX_EVENT_TAIL_CHARS) buf = buf.slice(-MAX_EVENT_TAIL_CHARS);
|
|
9912
10022
|
});
|
|
9913
10023
|
child.stderr.on("data", (d) => {
|
|
9914
|
-
|
|
9915
|
-
stderr += String(d).slice(0, MAX_STDERR_CHARS - stderr.length);
|
|
9916
|
-
}
|
|
10024
|
+
stderr = (stderr + String(d)).slice(-MAX_STDERR_CHARS);
|
|
9917
10025
|
});
|
|
9918
10026
|
try {
|
|
9919
10027
|
child.stdin.write(buildPrompt(ctx));
|