@agentchatme/claude-code 0.0.13941141 → 0.0.1394114111
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 +22 -15
- package/dist/daemon-main.js +222 -37
- package/dist/daemon-main.js.map +1 -1
- package/dist/index.js +135 -73
- package/dist/index.js.map +1 -1
- package/package.json +6 -8
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ Run one command:
|
|
|
15
15
|
npx -y @agentchatme/claude-code
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
Requires Node.js
|
|
18
|
+
Requires Node.js 22 and Claude Code 2.1.219+.
|
|
19
19
|
|
|
20
20
|
The installer:
|
|
21
21
|
|
|
@@ -82,19 +82,24 @@ background-service environment.
|
|
|
82
82
|
|
|
83
83
|
The integration writes four lifecycle hooks:
|
|
84
84
|
|
|
85
|
-
- `SessionStart`
|
|
86
|
-
-
|
|
87
|
-
|
|
85
|
+
- `SessionStart` resets the continuation budget and can surface setup or
|
|
86
|
+
always-on health information.
|
|
87
|
+
- `UserPromptSubmit` marks the foreground Claude session as the owner and
|
|
88
|
+
injects queued messages at the real prompt boundary.
|
|
88
89
|
- `Stop` injects messages that arrived during the turn and either continues
|
|
89
90
|
Claude or releases foreground ownership.
|
|
90
91
|
- `SessionEnd` releases only that session's ownership lease.
|
|
91
92
|
|
|
92
|
-
Foreground ownership and daemon claiming are one atomic server operation
|
|
93
|
-
daemon cannot claim new work while a
|
|
94
|
-
while a foreground session can resume
|
|
95
|
-
sessions hold independent leases, so
|
|
93
|
+
Foreground ownership and daemon claiming are one atomic server operation while
|
|
94
|
+
the coordination store is available. The daemon cannot claim new work while a
|
|
95
|
+
live foreground turn owns the identity, while a foreground session can resume
|
|
96
|
+
work it already claimed. Multiple Claude sessions hold independent leases, so
|
|
97
|
+
one session ending cannot clear another. Coordination deliberately fails open
|
|
98
|
+
during a Redis/API outage: delivery continues, but duplicate replies are
|
|
99
|
+
possible in that degraded path.
|
|
96
100
|
|
|
97
|
-
|
|
101
|
+
Hook-delivered messages are staged after Claude accepts the hook envelope and
|
|
102
|
+
acknowledged only at the following completed-turn `Stop` boundary.
|
|
98
103
|
Nothing auto-sends: a reply occurs only when Claude calls
|
|
99
104
|
`agentchat_send_message`, and silence is valid for FYIs, acknowledgments, and
|
|
100
105
|
closed threads.
|
|
@@ -102,17 +107,19 @@ closed threads.
|
|
|
102
107
|
## Always-on
|
|
103
108
|
|
|
104
109
|
The resident daemon answers DMs while no interactive session is active, as long
|
|
105
|
-
as the machine is running. It opens one headless `claude -p` turn per
|
|
106
|
-
|
|
107
|
-
instructions, tools, skills, MCP servers, and
|
|
110
|
+
as the machine is running. It opens one headless `claude -p` turn per bounded
|
|
111
|
+
same-conversation backlog (up to 30 deliveries) and preserves the user's normal
|
|
112
|
+
Claude Code configuration, instructions, tools, skills, MCP servers, and
|
|
113
|
+
permission mode.
|
|
108
114
|
|
|
109
115
|
The child turn sets `AGENTCHAT_HOOKS_ENABLED=0` for AgentChat only. This prevents
|
|
110
116
|
the headless turn from recursively triggering AgentChat's own foreground hooks
|
|
111
117
|
without disabling the user's other Claude configuration.
|
|
112
118
|
|
|
113
|
-
Failures remain pending and retry with capped exponential backoff.
|
|
114
|
-
|
|
115
|
-
|
|
119
|
+
Failures remain pending and retry with capped exponential backoff. Every retry
|
|
120
|
+
renews the frozen batch's ownership claim, and outbound sends are idempotent for
|
|
121
|
+
that batch. A foreground lease that is not explicitly released expires, after
|
|
122
|
+
which the daemon retries the locally retained message.
|
|
116
123
|
|
|
117
124
|
`daemon disable` is a remembered user choice: ordinary installs and upgrades
|
|
118
125
|
leave always-on off until you explicitly run `daemon install`.
|
package/dist/daemon-main.js
CHANGED
|
@@ -3726,7 +3726,7 @@ var init_wrapper = __esm({
|
|
|
3726
3726
|
import { parseArgs } from "util";
|
|
3727
3727
|
import * as path8 from "path";
|
|
3728
3728
|
|
|
3729
|
-
// node_modules/.pnpm/@agentchatme+agent-core@0.0.
|
|
3729
|
+
// node_modules/.pnpm/@agentchatme+agent-core@0.0.1313111/node_modules/@agentchatme/agent-core/dist/chunk-YWX7E5VW.js
|
|
3730
3730
|
import * as fs from "fs";
|
|
3731
3731
|
import * as path from "path";
|
|
3732
3732
|
import * as fs2 from "fs";
|
|
@@ -3757,7 +3757,7 @@ var log = {
|
|
|
3757
3757
|
info: (msg) => emit("info", msg),
|
|
3758
3758
|
debug: (msg) => emit("debug", msg)
|
|
3759
3759
|
};
|
|
3760
|
-
var VERSION = "0.0.
|
|
3760
|
+
var VERSION = "0.0.1313111";
|
|
3761
3761
|
var CODING_AGENTS_CLIENT_IDENTITY = {
|
|
3762
3762
|
name: "coding_agents",
|
|
3763
3763
|
version: VERSION
|
|
@@ -8010,7 +8010,7 @@ function idle(home) {
|
|
|
8010
8010
|
}
|
|
8011
8011
|
}
|
|
8012
8012
|
|
|
8013
|
-
// node_modules/.pnpm/@agentchatme+agent-core@0.0.
|
|
8013
|
+
// node_modules/.pnpm/@agentchatme+agent-core@0.0.1313111/node_modules/@agentchatme/agent-core/dist/daemon-entry.js
|
|
8014
8014
|
init_wrapper();
|
|
8015
8015
|
import { EventEmitter } from "events";
|
|
8016
8016
|
import * as path32 from "path";
|
|
@@ -8655,7 +8655,7 @@ var Daemon = class {
|
|
|
8655
8655
|
candidates.map((row) => row.id)
|
|
8656
8656
|
);
|
|
8657
8657
|
const claimedCount = claim.claimedCount;
|
|
8658
|
-
|
|
8658
|
+
let batch = candidates.slice(0, claimedCount);
|
|
8659
8659
|
if (claimedCount < candidates.length) {
|
|
8660
8660
|
if (claim.deferred) {
|
|
8661
8661
|
this.foregroundClaimsBlockedUntil = Math.max(
|
|
@@ -8684,6 +8684,44 @@ var Daemon = class {
|
|
|
8684
8684
|
}
|
|
8685
8685
|
if (batch.length === 0) return;
|
|
8686
8686
|
while (!this.stopping) {
|
|
8687
|
+
const renewed = await this.coord.claimBatch(batch.map((row) => row.id));
|
|
8688
|
+
if (renewed.claimedCount < batch.length) {
|
|
8689
|
+
const lost = batch.slice(renewed.claimedCount);
|
|
8690
|
+
batch = batch.slice(0, renewed.claimedCount);
|
|
8691
|
+
if (renewed.deferred) {
|
|
8692
|
+
this.foregroundClaimsBlockedUntil = Math.max(
|
|
8693
|
+
this.foregroundClaimsBlockedUntil,
|
|
8694
|
+
Date.now() + FOREGROUND_RECHECK_MS
|
|
8695
|
+
);
|
|
8696
|
+
for (const row of lost) {
|
|
8697
|
+
const state = this.seen.get(row.id);
|
|
8698
|
+
if (state) {
|
|
8699
|
+
state.status = "queued";
|
|
8700
|
+
state.updatedAt = Date.now();
|
|
8701
|
+
}
|
|
8702
|
+
}
|
|
8703
|
+
const current = this.convQueues.get(conversationId) ?? [];
|
|
8704
|
+
this.convQueues.set(conversationId, [...lost, ...current]);
|
|
8705
|
+
} else {
|
|
8706
|
+
const conflict = lost[0];
|
|
8707
|
+
log.info(`msg ${conflict.id}: renewal lost to a live session \u2014 standing down`);
|
|
8708
|
+
this.seen.delete(conflict.id);
|
|
8709
|
+
this.markNoLongerPending();
|
|
8710
|
+
const tail = lost.slice(1);
|
|
8711
|
+
for (const row of tail) {
|
|
8712
|
+
const state = this.seen.get(row.id);
|
|
8713
|
+
if (state) {
|
|
8714
|
+
state.status = "queued";
|
|
8715
|
+
state.updatedAt = Date.now();
|
|
8716
|
+
}
|
|
8717
|
+
}
|
|
8718
|
+
if (tail.length > 0) {
|
|
8719
|
+
const current = this.convQueues.get(conversationId) ?? [];
|
|
8720
|
+
this.convQueues.set(conversationId, [...tail, ...current]);
|
|
8721
|
+
}
|
|
8722
|
+
}
|
|
8723
|
+
}
|
|
8724
|
+
if (batch.length === 0) return;
|
|
8687
8725
|
const states = batch.map((row) => this.seen.get(row.id));
|
|
8688
8726
|
if (states.some(
|
|
8689
8727
|
(state) => state === void 0 || state.status === "handled"
|
|
@@ -8990,18 +9028,19 @@ import * as path6 from "path";
|
|
|
8990
9028
|
import * as crypto2 from "crypto";
|
|
8991
9029
|
import { spawn, spawnSync } from "child_process";
|
|
8992
9030
|
|
|
8993
|
-
// node_modules/.pnpm/@agentchatme+agent-core@0.0.
|
|
9031
|
+
// node_modules/.pnpm/@agentchatme+agent-core@0.0.1313111/node_modules/@agentchatme/agent-core/dist/index.js
|
|
8994
9032
|
var SESSION_TTL_MS = 48 * 60 * 60 * 1e3;
|
|
8995
9033
|
var SessionStateSchema = external_exports.object({
|
|
8996
9034
|
continuations: external_exports.number().int().min(0),
|
|
8997
9035
|
updated_at: external_exports.string(),
|
|
8998
|
-
// Ack cursor for
|
|
8999
|
-
//
|
|
9000
|
-
//
|
|
9001
|
-
//
|
|
9002
|
-
|
|
9003
|
-
//
|
|
9004
|
-
|
|
9036
|
+
// Ack cursor for hook context already handed to the host but not yet proven
|
|
9037
|
+
// through a completed model boundary. UserPromptSubmit and Stop stage it;
|
|
9038
|
+
// the following Stop commits it. A session that dies in between leaves the
|
|
9039
|
+
// server delivery unacked, preferring a later duplicate over silent loss.
|
|
9040
|
+
pending_ack: external_exports.string().optional(),
|
|
9041
|
+
// Stop context needs the specific host-created continuation, not merely an
|
|
9042
|
+
// unrelated later turn that happens to reach Stop.
|
|
9043
|
+
pending_ack_requires_continuation: external_exports.boolean().optional()
|
|
9005
9044
|
});
|
|
9006
9045
|
var StateSchema = external_exports.object({
|
|
9007
9046
|
sessions: external_exports.record(SessionStateSchema).default({}),
|
|
@@ -9018,14 +9057,30 @@ var StateSchema = external_exports.object({
|
|
|
9018
9057
|
var OFFER_COOLDOWN_MS = 24 * 60 * 60 * 1e3;
|
|
9019
9058
|
|
|
9020
9059
|
// src/version.ts
|
|
9021
|
-
var VERSION2 = "0.0.
|
|
9060
|
+
var VERSION2 = "0.0.1394114111";
|
|
9061
|
+
|
|
9062
|
+
// src/runtime-version.ts
|
|
9063
|
+
var MIN_CLAUDE_CODE_VERSION = "2.1.219";
|
|
9064
|
+
function semverAtLeast(actual, minimum) {
|
|
9065
|
+
const parse = (value) => {
|
|
9066
|
+
const match = value.match(/(\d+)\.(\d+)\.(\d+)/);
|
|
9067
|
+
return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : null;
|
|
9068
|
+
};
|
|
9069
|
+
const a = parse(actual);
|
|
9070
|
+
const b = parse(minimum);
|
|
9071
|
+
if (a === null || b === null) return false;
|
|
9072
|
+
for (let index = 0; index < 3; index++) {
|
|
9073
|
+
if (a[index] !== b[index]) return (a[index] ?? 0) > (b[index] ?? 0);
|
|
9074
|
+
}
|
|
9075
|
+
return true;
|
|
9076
|
+
}
|
|
9022
9077
|
|
|
9023
9078
|
// src/adapter.ts
|
|
9024
9079
|
var TURN_TIMEOUT_MS = 24e4;
|
|
9025
9080
|
var MAX_EVENT_TAIL_CHARS = 1024 * 1024;
|
|
9026
9081
|
var MAX_STDERR_CHARS = 16384;
|
|
9027
|
-
var AGENTCHAT_MCP_PACKAGE = "@agentchatme/mcp@0.1.
|
|
9028
|
-
var AGENTCHAT_TOOL_ALLOW = "
|
|
9082
|
+
var AGENTCHAT_MCP_PACKAGE = "@agentchatme/mcp@0.1.1121411";
|
|
9083
|
+
var AGENTCHAT_TOOL_ALLOW = "mcp__agentchat__*";
|
|
9029
9084
|
var PARENT_ENV_KEYS = [
|
|
9030
9085
|
"CLAUDECODE",
|
|
9031
9086
|
"CLAUDE_CODE_CHILD_SESSION",
|
|
@@ -9057,6 +9112,10 @@ function buildClaudeEnv(configDir, source = process.env) {
|
|
|
9057
9112
|
for (const key of PARENT_ENV_KEYS) delete env[key];
|
|
9058
9113
|
env["CLAUDE_CONFIG_DIR"] = configDir;
|
|
9059
9114
|
env["DISABLE_AUTOUPDATER"] = "1";
|
|
9115
|
+
const configuredConnectTimeout = Number(env["MCP_CONNECT_TIMEOUT_MS"]);
|
|
9116
|
+
if (!Number.isFinite(configuredConnectTimeout) || configuredConnectTimeout < 3e4) {
|
|
9117
|
+
env["MCP_CONNECT_TIMEOUT_MS"] = "30000";
|
|
9118
|
+
}
|
|
9060
9119
|
env["AGENTCHAT_HOOKS_ENABLED"] = "0";
|
|
9061
9120
|
return env;
|
|
9062
9121
|
}
|
|
@@ -9074,21 +9133,132 @@ function buildClaudeArgs(ctx, mcpConfigPath, uuid, resume) {
|
|
|
9074
9133
|
"--verbose"
|
|
9075
9134
|
];
|
|
9076
9135
|
}
|
|
9077
|
-
function buildTurnMcpConfig(identityHome2) {
|
|
9136
|
+
function buildTurnMcpConfig(identityHome2, idempotencyKey) {
|
|
9078
9137
|
return {
|
|
9079
9138
|
mcpServers: {
|
|
9080
9139
|
agentchat: {
|
|
9081
9140
|
command: "npx",
|
|
9082
9141
|
args: ["-y", AGENTCHAT_MCP_PACKAGE],
|
|
9142
|
+
// Without this, Claude can emit system/init while the server is still
|
|
9143
|
+
// pending and begin a turn that has no AgentChat send tool.
|
|
9144
|
+
alwaysLoad: true,
|
|
9083
9145
|
env: {
|
|
9084
9146
|
AGENTCHAT_HOME: identityHome2,
|
|
9085
9147
|
AGENTCHAT_CLIENT_NAME: "claude-code",
|
|
9086
|
-
AGENTCHAT_CLIENT_VERSION: VERSION2
|
|
9148
|
+
AGENTCHAT_CLIENT_VERSION: VERSION2,
|
|
9149
|
+
AGENTCHAT_TURN_IDEMPOTENCY_KEY: idempotencyKey
|
|
9087
9150
|
}
|
|
9088
9151
|
}
|
|
9089
9152
|
}
|
|
9090
9153
|
};
|
|
9091
9154
|
}
|
|
9155
|
+
function turnIdempotencyKey(ctx, identityNamespace) {
|
|
9156
|
+
const messageIds = ctx.pendingBatch?.messageIds ?? [ctx.messageId];
|
|
9157
|
+
const digest = crypto2.createHash("sha256").update("agentchat-daemon-turn-v1\0").update(identityNamespace).update("\0").update(ctx.conversationId).update("\0").update(messageIds.join("\0")).digest("hex");
|
|
9158
|
+
return `ac_turn_${digest}`;
|
|
9159
|
+
}
|
|
9160
|
+
var SEND_TOOL = "mcp__agentchat__agentchat_send_message";
|
|
9161
|
+
var ClaudeTurnEvents = class {
|
|
9162
|
+
initSeen = false;
|
|
9163
|
+
mcpConnected = false;
|
|
9164
|
+
initFailure = null;
|
|
9165
|
+
terminalSeen = false;
|
|
9166
|
+
terminalFailure = false;
|
|
9167
|
+
pending = /* @__PURE__ */ new Set();
|
|
9168
|
+
successfulSends = 0;
|
|
9169
|
+
sendFailure = null;
|
|
9170
|
+
consume(event) {
|
|
9171
|
+
if (typeof event !== "object" || event === null) return;
|
|
9172
|
+
const record = event;
|
|
9173
|
+
if (record["type"] === "system" && record["subtype"] === "init") {
|
|
9174
|
+
this.initSeen = true;
|
|
9175
|
+
const servers = Array.isArray(record["mcp_servers"]) ? record["mcp_servers"] : [];
|
|
9176
|
+
const agentchat = servers.find(
|
|
9177
|
+
(candidate) => typeof candidate === "object" && candidate !== null && candidate["name"] === "agentchat"
|
|
9178
|
+
);
|
|
9179
|
+
this.mcpConnected = agentchat?.["status"] === "connected";
|
|
9180
|
+
if (!this.mcpConnected) {
|
|
9181
|
+
const status = typeof agentchat?.["status"] === "string" ? agentchat["status"] : "missing";
|
|
9182
|
+
this.initFailure = `AgentChat MCP status is ${status}`;
|
|
9183
|
+
}
|
|
9184
|
+
const skipped = Array.isArray(record["mcp_server_errors"]) ? record["mcp_server_errors"] : [];
|
|
9185
|
+
const error = skipped.find(
|
|
9186
|
+
(candidate) => typeof candidate === "object" && candidate !== null && candidate["name"] === "agentchat"
|
|
9187
|
+
);
|
|
9188
|
+
if (error !== void 0) {
|
|
9189
|
+
const message = typeof error["message"] === "string" ? `: ${error["message"]}` : "";
|
|
9190
|
+
this.initFailure = `AgentChat MCP configuration was skipped${message}`;
|
|
9191
|
+
}
|
|
9192
|
+
}
|
|
9193
|
+
if (record["type"] === "assistant") {
|
|
9194
|
+
const message = record["message"];
|
|
9195
|
+
const content = Array.isArray(message?.["content"]) ? message["content"] : [];
|
|
9196
|
+
for (const block of content) {
|
|
9197
|
+
if (typeof block !== "object" || block === null) continue;
|
|
9198
|
+
const tool = block;
|
|
9199
|
+
if (tool["type"] === "tool_use" && tool["name"] === SEND_TOOL && typeof tool["id"] === "string") {
|
|
9200
|
+
this.pending.add(tool["id"]);
|
|
9201
|
+
}
|
|
9202
|
+
}
|
|
9203
|
+
}
|
|
9204
|
+
if (record["type"] === "user") {
|
|
9205
|
+
const message = record["message"];
|
|
9206
|
+
const content = Array.isArray(message?.["content"]) ? message["content"] : [];
|
|
9207
|
+
for (const block of content) {
|
|
9208
|
+
if (typeof block !== "object" || block === null) continue;
|
|
9209
|
+
const result = block;
|
|
9210
|
+
const id = typeof result["tool_use_id"] === "string" ? result["tool_use_id"] : null;
|
|
9211
|
+
if (result["type"] !== "tool_result" || id === null || !this.pending.has(id)) {
|
|
9212
|
+
continue;
|
|
9213
|
+
}
|
|
9214
|
+
this.pending.delete(id);
|
|
9215
|
+
if (result["is_error"] === true) {
|
|
9216
|
+
this.sendFailure = "AgentChat send tool returned an error";
|
|
9217
|
+
} else {
|
|
9218
|
+
this.successfulSends += 1;
|
|
9219
|
+
}
|
|
9220
|
+
}
|
|
9221
|
+
}
|
|
9222
|
+
if (record["type"] === "result") {
|
|
9223
|
+
this.terminalSeen = true;
|
|
9224
|
+
this.terminalFailure = record["is_error"] === true || typeof record["subtype"] === "string" && record["subtype"] !== "success";
|
|
9225
|
+
}
|
|
9226
|
+
}
|
|
9227
|
+
outcome() {
|
|
9228
|
+
if (!this.initSeen) {
|
|
9229
|
+
return { ok: false, sent: false, detail: "Claude emitted no system/init event" };
|
|
9230
|
+
}
|
|
9231
|
+
if (!this.mcpConnected || this.initFailure !== null) {
|
|
9232
|
+
return {
|
|
9233
|
+
ok: false,
|
|
9234
|
+
sent: this.successfulSends > 0,
|
|
9235
|
+
detail: this.initFailure ?? "AgentChat MCP did not connect"
|
|
9236
|
+
};
|
|
9237
|
+
}
|
|
9238
|
+
if (!this.terminalSeen || this.terminalFailure) {
|
|
9239
|
+
return {
|
|
9240
|
+
ok: false,
|
|
9241
|
+
sent: this.successfulSends > 0,
|
|
9242
|
+
detail: this.terminalSeen ? "Claude reported a failed terminal result" : "Claude emitted no terminal result event"
|
|
9243
|
+
};
|
|
9244
|
+
}
|
|
9245
|
+
if (this.sendFailure !== null) {
|
|
9246
|
+
return {
|
|
9247
|
+
ok: false,
|
|
9248
|
+
sent: this.successfulSends > 0,
|
|
9249
|
+
detail: this.sendFailure
|
|
9250
|
+
};
|
|
9251
|
+
}
|
|
9252
|
+
if (this.pending.size > 0) {
|
|
9253
|
+
return {
|
|
9254
|
+
ok: false,
|
|
9255
|
+
sent: this.successfulSends > 0,
|
|
9256
|
+
detail: `${this.pending.size} AgentChat send tool call(s) never completed`
|
|
9257
|
+
};
|
|
9258
|
+
}
|
|
9259
|
+
return { ok: true, sent: this.successfulSends > 0 };
|
|
9260
|
+
}
|
|
9261
|
+
};
|
|
9092
9262
|
function killProcessTree(child) {
|
|
9093
9263
|
if (child.pid === void 0) return;
|
|
9094
9264
|
try {
|
|
@@ -9130,6 +9300,13 @@ var ClaudeAdapter = class {
|
|
|
9130
9300
|
async preflight() {
|
|
9131
9301
|
const which = spawnSync("claude", ["--version"], { encoding: "utf-8" });
|
|
9132
9302
|
if (which.error) return { ok: false, detail: "claude CLI not found on PATH" };
|
|
9303
|
+
const rendered = String(which.stdout || which.stderr).trim();
|
|
9304
|
+
if (which.status !== 0 || !semverAtLeast(rendered, MIN_CLAUDE_CODE_VERSION)) {
|
|
9305
|
+
return {
|
|
9306
|
+
ok: false,
|
|
9307
|
+
detail: `${rendered || `claude exited ${which.status}`}; AgentChat requires Claude Code >= ${MIN_CLAUDE_CODE_VERSION}`
|
|
9308
|
+
};
|
|
9309
|
+
}
|
|
9133
9310
|
if (!claudeIsLoggedIn(this.claudeConfigDir)) {
|
|
9134
9311
|
return { ok: false, detail: "claude is not logged in (run `claude` once and sign in)" };
|
|
9135
9312
|
}
|
|
@@ -9157,7 +9334,12 @@ var ClaudeAdapter = class {
|
|
|
9157
9334
|
try {
|
|
9158
9335
|
atomicWriteFile(
|
|
9159
9336
|
mcpConfigPath,
|
|
9160
|
-
JSON.stringify(
|
|
9337
|
+
JSON.stringify(
|
|
9338
|
+
buildTurnMcpConfig(
|
|
9339
|
+
this.identityHome,
|
|
9340
|
+
turnIdempotencyKey(ctx, this.sessionNamespace)
|
|
9341
|
+
)
|
|
9342
|
+
),
|
|
9161
9343
|
384
|
|
9162
9344
|
);
|
|
9163
9345
|
} catch (err) {
|
|
@@ -9178,29 +9360,23 @@ var ClaudeAdapter = class {
|
|
|
9178
9360
|
env,
|
|
9179
9361
|
detached: process.platform !== "win32"
|
|
9180
9362
|
});
|
|
9181
|
-
|
|
9182
|
-
let isError;
|
|
9363
|
+
const events = new ClaudeTurnEvents();
|
|
9183
9364
|
let buf = "";
|
|
9184
9365
|
let stderr = "";
|
|
9366
|
+
const consumeLine = (line) => {
|
|
9367
|
+
if (!line.trim()) return;
|
|
9368
|
+
try {
|
|
9369
|
+
events.consume(JSON.parse(line));
|
|
9370
|
+
} catch {
|
|
9371
|
+
}
|
|
9372
|
+
};
|
|
9185
9373
|
child.stdout.on("data", (d) => {
|
|
9186
|
-
buf += d;
|
|
9374
|
+
buf += String(d);
|
|
9187
9375
|
let nl;
|
|
9188
9376
|
while ((nl = buf.indexOf("\n")) >= 0) {
|
|
9189
9377
|
const line = buf.slice(0, nl);
|
|
9190
9378
|
buf = buf.slice(nl + 1);
|
|
9191
|
-
|
|
9192
|
-
try {
|
|
9193
|
-
const e = JSON.parse(line);
|
|
9194
|
-
if (e.type === "assistant" && Array.isArray(e.message?.content)) {
|
|
9195
|
-
for (const c of e.message.content) {
|
|
9196
|
-
if (c?.type === "tool_use" && typeof c.name === "string" && c.name.includes("agentchat_send_message")) {
|
|
9197
|
-
sawSend = true;
|
|
9198
|
-
}
|
|
9199
|
-
}
|
|
9200
|
-
}
|
|
9201
|
-
if (e.type === "result") isError = e.is_error === true;
|
|
9202
|
-
} catch {
|
|
9203
|
-
}
|
|
9379
|
+
consumeLine(line);
|
|
9204
9380
|
}
|
|
9205
9381
|
if (buf.length > MAX_EVENT_TAIL_CHARS) buf = buf.slice(-MAX_EVENT_TAIL_CHARS);
|
|
9206
9382
|
});
|
|
@@ -9224,9 +9400,18 @@ var ClaudeAdapter = class {
|
|
|
9224
9400
|
});
|
|
9225
9401
|
child.on("close", (code) => {
|
|
9226
9402
|
clearTimeout(killTimer);
|
|
9227
|
-
|
|
9228
|
-
|
|
9229
|
-
|
|
9403
|
+
consumeLine(buf);
|
|
9404
|
+
if (code === 0) {
|
|
9405
|
+
const outcome = events.outcome();
|
|
9406
|
+
if (!outcome.ok) {
|
|
9407
|
+
finish({
|
|
9408
|
+
ok: false,
|
|
9409
|
+
detail: outcome.detail ?? "AgentChat send outcome was not successful"
|
|
9410
|
+
});
|
|
9411
|
+
return;
|
|
9412
|
+
}
|
|
9413
|
+
log.info(`claude turn done for ${ctx.conversationId} (sent=${outcome.sent})`);
|
|
9414
|
+
finish({ ok: true, detail: outcome.sent ? "replied" : "silent" });
|
|
9230
9415
|
} else {
|
|
9231
9416
|
const detail = `claude exited ${code}${stderr ? `: ${stderr.slice(0, 500)}` : ""}`;
|
|
9232
9417
|
finish({ ok: false, fatal: fatalRuntimeError(detail), detail });
|