@agentchatme/agent-core 0.0.1313111111111 → 0.0.1313111111112
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/{adapter-types-CV0DSi4F.d.ts → adapter-types-C_kf-KtV.d.ts} +25 -1
- package/dist/{chunk-D62LD5UE.js → chunk-KIP2JKPQ.js} +131 -9
- package/dist/chunk-KIP2JKPQ.js.map +1 -0
- package/dist/daemon-entry.d.ts +6 -2
- package/dist/daemon-entry.js +52 -37
- package/dist/daemon-entry.js.map +1 -1
- package/dist/index.d.ts +29 -7
- package/dist/index.js +81 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-D62LD5UE.js.map +0 -1
package/dist/daemon-entry.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { T as TurnContext, a as TurnDisposition, R as RuntimeAdapter } from './adapter-types-
|
|
4
|
-
export { A as AutonomyMode, F as FullAutonomyTurnContext, P as PendingReason, b as PendingTurnRequest, S as SilentReason, c as TurnBatchContext, d as TurnMentionContext, e as TurnResult } from './adapter-types-
|
|
3
|
+
import { T as TurnContext, a as TurnDisposition, R as RuntimeAdapter } from './adapter-types-C_kf-KtV.js';
|
|
4
|
+
export { A as AutonomyMode, F as FullAutonomyTurnContext, P as PendingReason, b as PendingTurnRequest, S as SilentReason, c as TurnBatchContext, d as TurnMentionContext, e as TurnResult } from './adapter-types-C_kf-KtV.js';
|
|
5
5
|
|
|
6
6
|
declare const SyncRowSchema: z.ZodObject<{
|
|
7
7
|
id: z.ZodString;
|
|
@@ -214,11 +214,15 @@ declare class Daemon {
|
|
|
214
214
|
private readonly foregroundDeferrals;
|
|
215
215
|
private stopping;
|
|
216
216
|
private heartbeatTimer;
|
|
217
|
+
private readonly installation;
|
|
218
|
+
private mirroredPendingFingerprint;
|
|
219
|
+
private pendingMirrorSyncedAt;
|
|
217
220
|
constructor(cfg: DaemonConfig, adapter: RuntimeAdapter, ws?: AgentWsClient, // injectable for tests; defaults to a real socket
|
|
218
221
|
/** Called when the socket gives up for good (auth refused). The supervisor
|
|
219
222
|
* above decides what happens next — this class does not end the process. */
|
|
220
223
|
onTerminal?: ((failure: DaemonFailure) => void) | undefined);
|
|
221
224
|
start(): Promise<void>;
|
|
225
|
+
private syncPendingMirror;
|
|
222
226
|
stop(): void;
|
|
223
227
|
private onInbound;
|
|
224
228
|
/** Queue one already-tracked row and ensure exactly one worker for its conversation. */
|
package/dist/daemon-entry.js
CHANGED
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
CODING_AGENTS_CLIENT_HEADERS,
|
|
3
3
|
PendingReasonSchema,
|
|
4
4
|
acquireLeaderLock,
|
|
5
|
-
atomicWriteFile,
|
|
6
5
|
beat,
|
|
7
6
|
credentialsPath,
|
|
8
7
|
external_exports,
|
|
@@ -10,12 +9,17 @@ import {
|
|
|
10
9
|
fullAutonomyAllows,
|
|
11
10
|
getMeLite,
|
|
12
11
|
idle,
|
|
12
|
+
installationId,
|
|
13
|
+
listPendingRequests,
|
|
13
14
|
log,
|
|
15
|
+
notifyPendingRequest,
|
|
16
|
+
pendingRequestsFingerprint,
|
|
14
17
|
readFullAutonomyPolicy,
|
|
15
18
|
recordDaemonActivity,
|
|
16
|
-
|
|
17
|
-
resolveIdentity
|
|
18
|
-
|
|
19
|
+
recordPendingRequestWithStatus,
|
|
20
|
+
resolveIdentity,
|
|
21
|
+
syncPendingReviewMirror
|
|
22
|
+
} from "./chunk-KIP2JKPQ.js";
|
|
19
23
|
|
|
20
24
|
// src/daemon/ws-client.ts
|
|
21
25
|
import { WebSocket } from "ws";
|
|
@@ -558,8 +562,8 @@ function resolveTurnDisposition(sent, reported) {
|
|
|
558
562
|
}
|
|
559
563
|
|
|
560
564
|
// src/daemon/run.ts
|
|
561
|
-
import * as
|
|
562
|
-
import * as
|
|
565
|
+
import * as path2 from "path";
|
|
566
|
+
import * as fs from "fs";
|
|
563
567
|
|
|
564
568
|
// src/daemon/config.ts
|
|
565
569
|
import * as path from "path";
|
|
@@ -593,9 +597,6 @@ async function resolveDaemonConfig(opts) {
|
|
|
593
597
|
}
|
|
594
598
|
|
|
595
599
|
// src/daemon/loop.ts
|
|
596
|
-
import * as crypto from "crypto";
|
|
597
|
-
import * as fs from "fs";
|
|
598
|
-
import * as path2 from "path";
|
|
599
600
|
var MAX_TIMER_MS = 2147483647;
|
|
600
601
|
function positiveBoundedEnv(name, fallback) {
|
|
601
602
|
const parsed = Number(process.env[name]);
|
|
@@ -610,6 +611,7 @@ var MAX_BATCH_MESSAGES = 30;
|
|
|
610
611
|
var BATCH_SETTLE_MS = nonNegativeBoundedEnv("AGENTCHATD_BATCH_SETTLE_MS", 100);
|
|
611
612
|
var MENTION_PREVIEW_MAX = 280;
|
|
612
613
|
var HEARTBEAT_MS = 3e4;
|
|
614
|
+
var PENDING_MIRROR_REFRESH_MS = 12 * 60 * 6e4;
|
|
613
615
|
var SEEN_TTL_MS = 24 * 60 * 6e4;
|
|
614
616
|
var MAX_COMPLETED_SEEN = 1e4;
|
|
615
617
|
var PAUSE_AT_PENDING = Math.max(
|
|
@@ -649,27 +651,12 @@ function dispositionOf(result) {
|
|
|
649
651
|
if (result.disposition) return result.disposition;
|
|
650
652
|
return result.detail === "replied" ? { action: "replied" } : { action: "silent", reason: "other" };
|
|
651
653
|
}
|
|
652
|
-
function installationId(home) {
|
|
653
|
-
const file = path2.join(home, "daemon.installation-id");
|
|
654
|
-
try {
|
|
655
|
-
const existing = fs.readFileSync(file, "utf-8").trim();
|
|
656
|
-
if (/^[0-9a-f-]{36}$/i.test(existing)) return existing;
|
|
657
|
-
} catch {
|
|
658
|
-
}
|
|
659
|
-
const id = crypto.randomUUID();
|
|
660
|
-
try {
|
|
661
|
-
atomicWriteFile(file, `${id}
|
|
662
|
-
`, 384);
|
|
663
|
-
} catch (err) {
|
|
664
|
-
log.warn(`could not persist daemon installation id: ${String(err)}`);
|
|
665
|
-
}
|
|
666
|
-
return id;
|
|
667
|
-
}
|
|
668
654
|
var Daemon = class {
|
|
669
655
|
constructor(cfg, adapter, ws, onTerminal) {
|
|
670
656
|
this.cfg = cfg;
|
|
671
657
|
this.adapter = adapter;
|
|
672
658
|
this.onTerminal = onTerminal;
|
|
659
|
+
this.installation = installationId(cfg.home);
|
|
673
660
|
this.coord = new ReplyCoord({
|
|
674
661
|
apiKey: cfg.apiKey,
|
|
675
662
|
apiBase: cfg.apiBase,
|
|
@@ -706,18 +693,41 @@ var Daemon = class {
|
|
|
706
693
|
foregroundDeferrals = /* @__PURE__ */ new Map();
|
|
707
694
|
stopping = false;
|
|
708
695
|
heartbeatTimer = null;
|
|
696
|
+
installation;
|
|
697
|
+
mirroredPendingFingerprint = null;
|
|
698
|
+
pendingMirrorSyncedAt = 0;
|
|
709
699
|
async start() {
|
|
710
700
|
const pre = await this.adapter.preflight();
|
|
711
701
|
if (!pre.ok) {
|
|
712
702
|
throw new Error(`runtime (${this.adapter.name}) not ready: ${pre.detail}`);
|
|
713
703
|
}
|
|
714
704
|
log.info(`agentchat daemon up as @${this.cfg.handle} via ${this.adapter.name}; holding the wire`);
|
|
705
|
+
void this.syncPendingMirror(true);
|
|
715
706
|
this.ws.start();
|
|
716
707
|
this.heartbeatTimer = setInterval(() => {
|
|
717
|
-
if (this.ws.connected)
|
|
708
|
+
if (this.ws.connected) {
|
|
709
|
+
beat(this.cfg.home);
|
|
710
|
+
void this.syncPendingMirror();
|
|
711
|
+
}
|
|
718
712
|
}, HEARTBEAT_MS);
|
|
719
713
|
this.heartbeatTimer.unref();
|
|
720
714
|
}
|
|
715
|
+
async syncPendingMirror(force = false) {
|
|
716
|
+
const records = listPendingRequests(this.cfg.home, this.cfg.handle);
|
|
717
|
+
const fingerprint2 = pendingRequestsFingerprint(records);
|
|
718
|
+
if (!force && fingerprint2 === this.mirroredPendingFingerprint && Date.now() - this.pendingMirrorSyncedAt < PENDING_MIRROR_REFRESH_MS) return;
|
|
719
|
+
try {
|
|
720
|
+
await syncPendingReviewMirror(
|
|
721
|
+
{ apiKey: this.cfg.apiKey, apiBase: this.cfg.apiBase },
|
|
722
|
+
this.installation,
|
|
723
|
+
records
|
|
724
|
+
);
|
|
725
|
+
this.mirroredPendingFingerprint = fingerprint2;
|
|
726
|
+
this.pendingMirrorSyncedAt = Date.now();
|
|
727
|
+
} catch (err) {
|
|
728
|
+
log.warn(`pending-review dashboard mirror unavailable: ${String(err)}`);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
721
731
|
stop() {
|
|
722
732
|
this.stopping = true;
|
|
723
733
|
if (this.heartbeatTimer) clearInterval(this.heartbeatTimer);
|
|
@@ -910,7 +920,12 @@ var Daemon = class {
|
|
|
910
920
|
summary: disposition.pending.summary
|
|
911
921
|
};
|
|
912
922
|
try {
|
|
913
|
-
|
|
923
|
+
const persisted = recordPendingRequestWithStatus(
|
|
924
|
+
this.cfg.home,
|
|
925
|
+
pendingInput
|
|
926
|
+
);
|
|
927
|
+
if (persisted.changed) notifyPendingRequest(persisted.record);
|
|
928
|
+
await this.syncPendingMirror();
|
|
914
929
|
pendingPersistence = null;
|
|
915
930
|
} catch (err) {
|
|
916
931
|
pendingPersistence = { result, input: pendingInput };
|
|
@@ -1125,28 +1140,28 @@ function fingerprint(home) {
|
|
|
1125
1140
|
return id === null ? null : `${id.apiKey}:${id.handle ?? ""}`;
|
|
1126
1141
|
}
|
|
1127
1142
|
function boundDaemonLog(home) {
|
|
1128
|
-
const file =
|
|
1143
|
+
const file = path2.join(home, "daemon.log");
|
|
1129
1144
|
try {
|
|
1130
|
-
const size =
|
|
1145
|
+
const size = fs.statSync(file).size;
|
|
1131
1146
|
if (size <= MAX_LOG_BYTES) return;
|
|
1132
|
-
const fd =
|
|
1147
|
+
const fd = fs.openSync(file, "r");
|
|
1133
1148
|
try {
|
|
1134
1149
|
const keep = Buffer.alloc(Math.min(KEEP_LOG_BYTES, size));
|
|
1135
|
-
|
|
1136
|
-
|
|
1150
|
+
fs.readSync(fd, keep, 0, keep.length, size - keep.length);
|
|
1151
|
+
fs.writeFileSync(
|
|
1137
1152
|
file,
|
|
1138
1153
|
`[agentchat:info] older daemon log output truncated at ${(/* @__PURE__ */ new Date()).toISOString()}
|
|
1139
1154
|
${keep.toString("utf-8")}`
|
|
1140
1155
|
);
|
|
1141
1156
|
} finally {
|
|
1142
|
-
|
|
1157
|
+
fs.closeSync(fd);
|
|
1143
1158
|
}
|
|
1144
1159
|
} catch {
|
|
1145
1160
|
}
|
|
1146
1161
|
}
|
|
1147
1162
|
async function runDaemon(opts) {
|
|
1148
|
-
const home =
|
|
1149
|
-
const workdir = opts.workdir ??
|
|
1163
|
+
const home = path2.resolve(opts.home);
|
|
1164
|
+
const workdir = opts.workdir ?? path2.join(home, "daemon-workdir");
|
|
1150
1165
|
boundDaemonLog(home);
|
|
1151
1166
|
if (process.env["AGENTCHAT_LOG_LEVEL"] === void 0) process.env["AGENTCHAT_LOG_LEVEL"] = "info";
|
|
1152
1167
|
const lock = acquireLeaderLock(home);
|
|
@@ -1180,8 +1195,8 @@ async function runDaemon(opts) {
|
|
|
1180
1195
|
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
|
1181
1196
|
let nudged = false;
|
|
1182
1197
|
try {
|
|
1183
|
-
|
|
1184
|
-
const watcher =
|
|
1198
|
+
fs.mkdirSync(home, { recursive: true });
|
|
1199
|
+
const watcher = fs.watch(home, (_event, filename) => {
|
|
1185
1200
|
if (filename === null || String(filename).startsWith("credentials")) nudged = true;
|
|
1186
1201
|
});
|
|
1187
1202
|
watcher.on("error", (err) => {
|