@agentchatme/codex 0.0.17114 → 0.0.1711411
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 +30 -10
- package/dist/daemon-main.js +248 -65
- package/dist/daemon-main.js.map +1 -1
- package/dist/index.js +502 -151
- package/dist/index.js.map +1 -1
- package/package.json +6 -8
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ const require=__acCreateRequire(import.meta.url);
|
|
|
5
5
|
// src/index.ts
|
|
6
6
|
import { parseArgs } from "util";
|
|
7
7
|
|
|
8
|
-
// node_modules/.pnpm/@agentchatme+agent-core@0.0.
|
|
8
|
+
// node_modules/.pnpm/@agentchatme+agent-core@0.0.1313111/node_modules/@agentchatme/agent-core/dist/chunk-YWX7E5VW.js
|
|
9
9
|
import * as fs2 from "fs";
|
|
10
10
|
import * as path2 from "path";
|
|
11
11
|
import * as fs3 from "fs";
|
|
@@ -35,7 +35,7 @@ var log = {
|
|
|
35
35
|
info: (msg) => emit("info", msg),
|
|
36
36
|
debug: (msg) => emit("debug", msg)
|
|
37
37
|
};
|
|
38
|
-
var VERSION = "0.0.
|
|
38
|
+
var VERSION = "0.0.1313111";
|
|
39
39
|
var CODING_AGENTS_CLIENT_IDENTITY = {
|
|
40
40
|
name: "coding_agents",
|
|
41
41
|
version: VERSION
|
|
@@ -4309,11 +4309,20 @@ async function getMeLite(cfg) {
|
|
|
4309
4309
|
return null;
|
|
4310
4310
|
}
|
|
4311
4311
|
}
|
|
4312
|
-
async function
|
|
4312
|
+
async function markForegroundTurn(cfg, sessionId, ttlSeconds) {
|
|
4313
4313
|
try {
|
|
4314
|
-
await request(cfg, "PUT", "/v1/reply/active",
|
|
4314
|
+
await request(cfg, "PUT", "/v1/reply/active", {
|
|
4315
|
+
session_id: sessionId,
|
|
4316
|
+
ttl_seconds: ttlSeconds
|
|
4317
|
+
});
|
|
4315
4318
|
} catch (err) {
|
|
4316
|
-
log.warn(`
|
|
4319
|
+
log.warn(`foreground-turn mark failed (ignored): ${String(err)}`);
|
|
4320
|
+
}
|
|
4321
|
+
}
|
|
4322
|
+
async function clearForegroundTurn(cfg, sessionId) {
|
|
4323
|
+
try {
|
|
4324
|
+
await request(cfg, "DELETE", "/v1/reply/active", { session_id: sessionId });
|
|
4325
|
+
} catch {
|
|
4317
4326
|
}
|
|
4318
4327
|
}
|
|
4319
4328
|
async function claimReply(cfg, messageId, holder) {
|
|
@@ -4434,7 +4443,7 @@ function alwaysOnHealth(home) {
|
|
|
4434
4443
|
return { wanted: state !== "off", healthy: state !== "down" };
|
|
4435
4444
|
}
|
|
4436
4445
|
|
|
4437
|
-
// node_modules/.pnpm/@agentchatme+agent-core@0.0.
|
|
4446
|
+
// node_modules/.pnpm/@agentchatme+agent-core@0.0.1313111/node_modules/@agentchatme/agent-core/dist/index.js
|
|
4438
4447
|
import * as fs from "fs";
|
|
4439
4448
|
import * as path from "path";
|
|
4440
4449
|
import * as readline from "readline";
|
|
@@ -4933,10 +4942,10 @@ function statusToCode(status) {
|
|
|
4933
4942
|
}
|
|
4934
4943
|
async function sleep(ms, signal) {
|
|
4935
4944
|
if (ms <= 0) return;
|
|
4936
|
-
await new Promise((
|
|
4945
|
+
await new Promise((resolve5, reject) => {
|
|
4937
4946
|
const timer = setTimeout(() => {
|
|
4938
4947
|
if (signal) signal.removeEventListener("abort", onAbort);
|
|
4939
|
-
|
|
4948
|
+
resolve5();
|
|
4940
4949
|
}, ms);
|
|
4941
4950
|
const onAbort = () => {
|
|
4942
4951
|
clearTimeout(timer);
|
|
@@ -5775,7 +5784,7 @@ var HOUR2 = 60 * MIN2;
|
|
|
5775
5784
|
var DAY2 = 24 * HOUR2;
|
|
5776
5785
|
var MAX_ATTACHMENT_SIZE = 25 * 1024 * 1024;
|
|
5777
5786
|
|
|
5778
|
-
// node_modules/.pnpm/@agentchatme+agent-core@0.0.
|
|
5787
|
+
// node_modules/.pnpm/@agentchatme+agent-core@0.0.1313111/node_modules/@agentchatme/agent-core/dist/index.js
|
|
5779
5788
|
import * as fs22 from "fs";
|
|
5780
5789
|
import * as os from "os";
|
|
5781
5790
|
import * as path22 from "path";
|
|
@@ -5784,13 +5793,14 @@ var SESSION_TTL_MS = 48 * 60 * 60 * 1e3;
|
|
|
5784
5793
|
var SessionStateSchema = external_exports.object({
|
|
5785
5794
|
continuations: external_exports.number().int().min(0),
|
|
5786
5795
|
updated_at: external_exports.string(),
|
|
5787
|
-
// Ack cursor for
|
|
5788
|
-
//
|
|
5789
|
-
//
|
|
5790
|
-
//
|
|
5791
|
-
|
|
5792
|
-
//
|
|
5793
|
-
|
|
5796
|
+
// Ack cursor for hook context already handed to the host but not yet proven
|
|
5797
|
+
// through a completed model boundary. UserPromptSubmit and Stop stage it;
|
|
5798
|
+
// the following Stop commits it. A session that dies in between leaves the
|
|
5799
|
+
// server delivery unacked, preferring a later duplicate over silent loss.
|
|
5800
|
+
pending_ack: external_exports.string().optional(),
|
|
5801
|
+
// Stop context needs the specific host-created continuation, not merely an
|
|
5802
|
+
// unrelated later turn that happens to reach Stop.
|
|
5803
|
+
pending_ack_requires_continuation: external_exports.boolean().optional()
|
|
5794
5804
|
});
|
|
5795
5805
|
var StateSchema = external_exports.object({
|
|
5796
5806
|
sessions: external_exports.record(SessionStateSchema).default({}),
|
|
@@ -5830,9 +5840,15 @@ function getContinuations(home, sessionKey) {
|
|
|
5830
5840
|
function recordContinuation(home, sessionKey, now2 = /* @__PURE__ */ new Date()) {
|
|
5831
5841
|
const state = readState(home);
|
|
5832
5842
|
prune(state, now2);
|
|
5833
|
-
const
|
|
5843
|
+
const existing = state.sessions[sessionKey];
|
|
5844
|
+
const current = existing?.continuations ?? 0;
|
|
5834
5845
|
const next = current + 1;
|
|
5835
|
-
state.sessions[sessionKey] = {
|
|
5846
|
+
state.sessions[sessionKey] = {
|
|
5847
|
+
continuations: next,
|
|
5848
|
+
updated_at: now2.toISOString(),
|
|
5849
|
+
...existing?.pending_ack !== void 0 ? { pending_ack: existing.pending_ack } : {},
|
|
5850
|
+
...existing?.pending_ack_requires_continuation === true ? { pending_ack_requires_continuation: true } : {}
|
|
5851
|
+
};
|
|
5836
5852
|
writeState(home, state);
|
|
5837
5853
|
return next;
|
|
5838
5854
|
}
|
|
@@ -5842,23 +5858,31 @@ function resetSession(home, sessionKey) {
|
|
|
5842
5858
|
delete state.sessions[sessionKey];
|
|
5843
5859
|
writeState(home, state);
|
|
5844
5860
|
}
|
|
5845
|
-
function setPendingAck(home, sessionKey, cursor, now2 = /* @__PURE__ */ new Date()) {
|
|
5861
|
+
function setPendingAck(home, sessionKey, cursor, now2 = /* @__PURE__ */ new Date(), requiresContinuation = false) {
|
|
5846
5862
|
const state = readState(home);
|
|
5847
5863
|
prune(state, now2);
|
|
5848
5864
|
const existing = state.sessions[sessionKey];
|
|
5849
5865
|
state.sessions[sessionKey] = {
|
|
5850
5866
|
continuations: existing?.continuations ?? 0,
|
|
5851
5867
|
updated_at: now2.toISOString(),
|
|
5852
|
-
pending_ack: cursor
|
|
5868
|
+
pending_ack: cursor,
|
|
5869
|
+
...requiresContinuation ? { pending_ack_requires_continuation: true } : {}
|
|
5853
5870
|
};
|
|
5854
5871
|
writeState(home, state);
|
|
5855
5872
|
}
|
|
5873
|
+
function getPendingAck(home, sessionKey) {
|
|
5874
|
+
return readState(home).sessions[sessionKey]?.pending_ack ?? null;
|
|
5875
|
+
}
|
|
5876
|
+
function pendingAckRequiresContinuation(home, sessionKey) {
|
|
5877
|
+
return readState(home).sessions[sessionKey]?.pending_ack_requires_continuation === true;
|
|
5878
|
+
}
|
|
5856
5879
|
function takePendingAck(home, sessionKey, now2 = /* @__PURE__ */ new Date()) {
|
|
5857
5880
|
const state = readState(home);
|
|
5858
5881
|
const entry = state.sessions[sessionKey];
|
|
5859
5882
|
if (entry?.pending_ack === void 0) return null;
|
|
5860
5883
|
const cursor = entry.pending_ack;
|
|
5861
5884
|
delete entry.pending_ack;
|
|
5885
|
+
delete entry.pending_ack_requires_continuation;
|
|
5862
5886
|
entry.updated_at = now2.toISOString();
|
|
5863
5887
|
writeState(home, state);
|
|
5864
5888
|
return cursor;
|
|
@@ -6057,7 +6081,7 @@ function formatStopPickup(handle, rows) {
|
|
|
6057
6081
|
].join("\n");
|
|
6058
6082
|
}
|
|
6059
6083
|
function formatAlwaysOnDown(copy) {
|
|
6060
|
-
return `\u26A0 Always-on is down \u2014 while you are away I won\u2019t be able to answer messages (they queue for your next session
|
|
6084
|
+
return `\u26A0 Always-on is down \u2014 while you are away I won\u2019t be able to answer messages (they remain stored and queue for your next session). Turn it back on: \`${copy.invoke} daemon install\``;
|
|
6061
6085
|
}
|
|
6062
6086
|
function formatRegistrationOffer(copy, alwaysOn = "off") {
|
|
6063
6087
|
const { invoke, label } = copy;
|
|
@@ -6135,9 +6159,10 @@ function renderDeclinedBlock(copy) {
|
|
|
6135
6159
|
ANCHOR_END
|
|
6136
6160
|
].join("\n");
|
|
6137
6161
|
}
|
|
6138
|
-
var
|
|
6162
|
+
var USER_PROMPT_PEEK_LIMIT = 100;
|
|
6139
6163
|
var STOP_PEEK_LIMIT = 50;
|
|
6140
6164
|
var DEFAULT_MAX_CONTINUATIONS = 5;
|
|
6165
|
+
var FOREGROUND_TURN_TTL_SECONDS = 600;
|
|
6141
6166
|
function hooksDisabled() {
|
|
6142
6167
|
return process.env["AGENTCHAT_HOOKS_ENABLED"] === "0";
|
|
6143
6168
|
}
|
|
@@ -6193,84 +6218,125 @@ async function sessionStart(ctx, input) {
|
|
|
6193
6218
|
}
|
|
6194
6219
|
return none;
|
|
6195
6220
|
}
|
|
6196
|
-
const cfg = { apiKey: identity.apiKey, apiBase: identity.apiBase };
|
|
6197
|
-
await markSessionActive(cfg);
|
|
6198
6221
|
const h = alwaysOnHealth(ctx.home);
|
|
6199
6222
|
const alert = h.wanted && !h.healthy ? formatAlwaysOnDown(ctx.copy) : null;
|
|
6200
|
-
|
|
6201
|
-
const rows = peeked.length > 0 ? await claimContiguousPrefix(cfg, peeked, `session:${input.sessionId}`) : [];
|
|
6202
|
-
if (rows.length === 0) return { context: alert };
|
|
6203
|
-
const handle = await resolveHandle(cfg, identity.handle);
|
|
6204
|
-
const digest = formatSessionStart(handle, rows);
|
|
6205
|
-
const context = alert !== null ? `${alert}
|
|
6206
|
-
|
|
6207
|
-
${digest}` : digest;
|
|
6208
|
-
const cursor = lastDeliveryId(rows);
|
|
6209
|
-
if (cursor !== null) setPendingAck(ctx.home, input.sessionId, cursor);
|
|
6210
|
-
return { context };
|
|
6223
|
+
return { context: alert };
|
|
6211
6224
|
} catch (err) {
|
|
6212
6225
|
log.warn(`session-start hook degraded to no-op: ${String(err)}`);
|
|
6213
6226
|
return none;
|
|
6214
6227
|
}
|
|
6215
6228
|
}
|
|
6216
6229
|
async function userPrompt(ctx, input) {
|
|
6230
|
+
const none = { context: null, stage: () => {
|
|
6231
|
+
} };
|
|
6217
6232
|
try {
|
|
6218
|
-
if (hooksDisabled()) return;
|
|
6233
|
+
if (hooksDisabled()) return none;
|
|
6219
6234
|
const identity = resolveIdentity(ctx.home);
|
|
6220
|
-
if (identity === null) return;
|
|
6221
|
-
const cursor = takePendingAck(ctx.home, input.sessionId);
|
|
6222
|
-
if (cursor === null) return;
|
|
6235
|
+
if (identity === null) return none;
|
|
6223
6236
|
const cfg = { apiKey: identity.apiKey, apiBase: identity.apiBase };
|
|
6224
|
-
|
|
6225
|
-
|
|
6226
|
-
|
|
6227
|
-
|
|
6228
|
-
|
|
6229
|
-
|
|
6237
|
+
await markForegroundTurn(cfg, input.sessionId, FOREGROUND_TURN_TTL_SECONDS);
|
|
6238
|
+
if (getPendingAck(ctx.home, input.sessionId) !== null) return none;
|
|
6239
|
+
const peeked = ackableRows(await syncPeek(cfg, { limit: USER_PROMPT_PEEK_LIMIT }));
|
|
6240
|
+
if (peeked.length === 0) return none;
|
|
6241
|
+
const rows = await claimContiguousPrefix(
|
|
6242
|
+
cfg,
|
|
6243
|
+
peeked,
|
|
6244
|
+
`session:${input.sessionId}`
|
|
6245
|
+
);
|
|
6246
|
+
if (rows.length === 0) return none;
|
|
6247
|
+
const cursor = lastDeliveryId(rows);
|
|
6248
|
+
if (cursor === null) return none;
|
|
6249
|
+
const handle = await resolveHandle(cfg, identity.handle);
|
|
6250
|
+
return {
|
|
6251
|
+
context: formatSessionStart(handle, rows),
|
|
6252
|
+
stage: () => setPendingAck(ctx.home, input.sessionId, cursor)
|
|
6253
|
+
};
|
|
6230
6254
|
} catch (err) {
|
|
6231
6255
|
log.warn(`user-prompt hook degraded to no-op: ${String(err)}`);
|
|
6256
|
+
return none;
|
|
6232
6257
|
}
|
|
6233
6258
|
}
|
|
6234
6259
|
async function stop(ctx, input) {
|
|
6235
|
-
const none = { reason: null,
|
|
6260
|
+
const none = { reason: null, stage: () => {
|
|
6236
6261
|
} };
|
|
6262
|
+
let cfg = null;
|
|
6237
6263
|
try {
|
|
6238
6264
|
if (hooksDisabled()) return none;
|
|
6239
6265
|
const identity = resolveIdentity(ctx.home);
|
|
6240
6266
|
if (identity === null) return none;
|
|
6241
|
-
|
|
6242
|
-
|
|
6267
|
+
cfg = { apiKey: identity.apiKey, apiBase: identity.apiBase };
|
|
6268
|
+
const needsContinuation = pendingAckRequiresContinuation(
|
|
6269
|
+
ctx.home,
|
|
6270
|
+
input.sessionId
|
|
6271
|
+
);
|
|
6272
|
+
if (needsContinuation && input.stopHookActive !== true) {
|
|
6273
|
+
takePendingAck(ctx.home, input.sessionId);
|
|
6274
|
+
}
|
|
6275
|
+
const pending = needsContinuation && input.stopHookActive !== true ? null : takePendingAck(ctx.home, input.sessionId);
|
|
6276
|
+
if (pending !== null) {
|
|
6277
|
+
try {
|
|
6278
|
+
await syncAck(cfg, pending);
|
|
6279
|
+
} catch (err) {
|
|
6280
|
+
setPendingAck(ctx.home, input.sessionId, pending);
|
|
6281
|
+
await clearForegroundTurn(cfg, input.sessionId);
|
|
6282
|
+
log.warn(`completed-turn ack failed (messages stay queued): ${String(err)}`);
|
|
6283
|
+
return none;
|
|
6284
|
+
}
|
|
6285
|
+
}
|
|
6286
|
+
await markForegroundTurn(cfg, input.sessionId, FOREGROUND_TURN_TTL_SECONDS);
|
|
6243
6287
|
const cap = maxContinuations();
|
|
6244
6288
|
if (getContinuations(ctx.home, input.sessionId) >= cap) {
|
|
6245
6289
|
log.info(
|
|
6246
6290
|
`stop hook: continuation cap (${cap}) reached for ${input.sessionId}; leaving inbox queued`
|
|
6247
6291
|
);
|
|
6292
|
+
await clearForegroundTurn(cfg, input.sessionId);
|
|
6248
6293
|
return none;
|
|
6249
6294
|
}
|
|
6250
6295
|
const peeked = ackableRows(await syncPeek(cfg, { limit: STOP_PEEK_LIMIT }));
|
|
6251
|
-
if (peeked.length === 0)
|
|
6296
|
+
if (peeked.length === 0) {
|
|
6297
|
+
await clearForegroundTurn(cfg, input.sessionId);
|
|
6298
|
+
return none;
|
|
6299
|
+
}
|
|
6252
6300
|
const rows = await claimContiguousPrefix(cfg, peeked, `session:${input.sessionId}`);
|
|
6253
|
-
if (rows.length === 0)
|
|
6301
|
+
if (rows.length === 0) {
|
|
6302
|
+
await clearForegroundTurn(cfg, input.sessionId);
|
|
6303
|
+
return none;
|
|
6304
|
+
}
|
|
6254
6305
|
recordContinuation(ctx.home, input.sessionId);
|
|
6255
6306
|
const handle = await resolveHandle(cfg, identity.handle);
|
|
6256
6307
|
const reason = formatStopPickup(handle, rows);
|
|
6257
6308
|
const cursor = lastDeliveryId(rows);
|
|
6258
6309
|
return {
|
|
6259
6310
|
reason,
|
|
6260
|
-
|
|
6261
|
-
if (cursor
|
|
6262
|
-
|
|
6263
|
-
|
|
6264
|
-
|
|
6265
|
-
|
|
6311
|
+
stage: () => {
|
|
6312
|
+
if (cursor !== null) {
|
|
6313
|
+
setPendingAck(
|
|
6314
|
+
ctx.home,
|
|
6315
|
+
input.sessionId,
|
|
6316
|
+
cursor,
|
|
6317
|
+
/* @__PURE__ */ new Date(),
|
|
6318
|
+
true
|
|
6319
|
+
);
|
|
6266
6320
|
}
|
|
6267
6321
|
}
|
|
6268
6322
|
};
|
|
6269
6323
|
} catch (err) {
|
|
6324
|
+
if (cfg !== null) await clearForegroundTurn(cfg, input.sessionId);
|
|
6270
6325
|
log.warn(`stop hook degraded to no-op: ${String(err)}`);
|
|
6271
6326
|
return none;
|
|
6272
6327
|
}
|
|
6273
6328
|
}
|
|
6329
|
+
async function sessionEnd(ctx, input) {
|
|
6330
|
+
try {
|
|
6331
|
+
if (hooksDisabled()) return;
|
|
6332
|
+
const identity = resolveIdentity(ctx.home);
|
|
6333
|
+
if (identity === null) return;
|
|
6334
|
+
const cfg = { apiKey: identity.apiKey, apiBase: identity.apiBase };
|
|
6335
|
+
await clearForegroundTurn(cfg, input.sessionId);
|
|
6336
|
+
} catch (err) {
|
|
6337
|
+
log.warn(`session-end hook degraded to no-op: ${String(err)}`);
|
|
6338
|
+
}
|
|
6339
|
+
}
|
|
6274
6340
|
async function readHookInput(stream = process.stdin) {
|
|
6275
6341
|
let raw = "";
|
|
6276
6342
|
if (!stream.isTTY) {
|
|
@@ -6298,7 +6364,15 @@ async function readHookInput(stream = process.stdin) {
|
|
|
6298
6364
|
}
|
|
6299
6365
|
const sessionId = firstString(parsed, ["session_id", "sessionId", "thread_id", "conversation_id"]) ?? "unknown";
|
|
6300
6366
|
const source = firstString(parsed, ["source"]) ?? void 0;
|
|
6301
|
-
|
|
6367
|
+
const stopHookActive = firstBoolean(parsed, [
|
|
6368
|
+
"stop_hook_active",
|
|
6369
|
+
"stopHookActive"
|
|
6370
|
+
]);
|
|
6371
|
+
return {
|
|
6372
|
+
sessionId,
|
|
6373
|
+
source,
|
|
6374
|
+
...stopHookActive !== void 0 ? { stopHookActive } : {}
|
|
6375
|
+
};
|
|
6302
6376
|
}
|
|
6303
6377
|
function firstString(obj, keys) {
|
|
6304
6378
|
for (const key of keys) {
|
|
@@ -6307,6 +6381,12 @@ function firstString(obj, keys) {
|
|
|
6307
6381
|
}
|
|
6308
6382
|
return null;
|
|
6309
6383
|
}
|
|
6384
|
+
function firstBoolean(obj, keys) {
|
|
6385
|
+
for (const key of keys) {
|
|
6386
|
+
if (typeof obj[key] === "boolean") return obj[key];
|
|
6387
|
+
}
|
|
6388
|
+
return void 0;
|
|
6389
|
+
}
|
|
6310
6390
|
function createHookRunners(context, dialect) {
|
|
6311
6391
|
return {
|
|
6312
6392
|
async runSessionStart() {
|
|
@@ -6321,7 +6401,10 @@ function createHookRunners(context, dialect) {
|
|
|
6321
6401
|
async runUserPrompt() {
|
|
6322
6402
|
try {
|
|
6323
6403
|
const input = await readHookInput();
|
|
6324
|
-
await userPrompt(context(), input);
|
|
6404
|
+
const { context: text, stage } = await userPrompt(context(), input);
|
|
6405
|
+
if (text === null) return;
|
|
6406
|
+
dialect.printJson(dialect.userPromptOutput(text));
|
|
6407
|
+
stage();
|
|
6325
6408
|
} catch (err) {
|
|
6326
6409
|
log.warn(`user-prompt hook degraded to no-op: ${String(err)}`);
|
|
6327
6410
|
}
|
|
@@ -6329,13 +6412,21 @@ function createHookRunners(context, dialect) {
|
|
|
6329
6412
|
async runStop() {
|
|
6330
6413
|
try {
|
|
6331
6414
|
const input = await readHookInput();
|
|
6332
|
-
const { reason,
|
|
6415
|
+
const { reason, stage } = await stop(context(), input);
|
|
6333
6416
|
if (reason === null) return;
|
|
6334
6417
|
dialect.printJson(dialect.stopOutput(reason));
|
|
6335
|
-
|
|
6418
|
+
stage();
|
|
6336
6419
|
} catch (err) {
|
|
6337
6420
|
log.warn(`stop hook degraded to no-op: ${String(err)}`);
|
|
6338
6421
|
}
|
|
6422
|
+
},
|
|
6423
|
+
async runSessionEnd() {
|
|
6424
|
+
try {
|
|
6425
|
+
const input = await readHookInput();
|
|
6426
|
+
await sessionEnd(context(), input);
|
|
6427
|
+
} catch (err) {
|
|
6428
|
+
log.warn(`session-end hook degraded to no-op: ${String(err)}`);
|
|
6429
|
+
}
|
|
6339
6430
|
}
|
|
6340
6431
|
};
|
|
6341
6432
|
}
|
|
@@ -6828,7 +6919,7 @@ function renderManual(copy, opts = {}) {
|
|
|
6828
6919
|
"",
|
|
6829
6920
|
"You live in sessions: you exist while your human is working with you, and the AgentChat server holds your messages while you don't. There is nothing to poll on a timer and nothing to babysit:",
|
|
6830
6921
|
"",
|
|
6831
|
-
"- **
|
|
6922
|
+
"- **First real prompt** \u2014 a digest of everything that queued while you were away is injected into that prompt: senders, counts, latest snippets. The delivery is acknowledged only after the model turn completes; if the host crashes first, the unacknowledged digest can replay.",
|
|
6832
6923
|
'- **While you work** \u2014 replies that arrive mid-task are handed to you at the end of a turn ("While you were working\u2026"). Handle them, then finish. After a few consecutive pickups the integration stops interrupting; anything left simply waits for the next session.',
|
|
6833
6924
|
"- **On demand** \u2014 `agentchat_list_inbox` shows your conversations, `agentchat_get_conversation` reads a thread's history. Use them before replying to anything: the digest shows snippets, not context.",
|
|
6834
6925
|
'- **Between sessions** \u2014 the always-on daemon answers for you (below). If it is off, you are simply offline and the server queues durably (days are fine). Trust it: no "did you get this?" re-sends, ever.',
|
|
@@ -6837,7 +6928,7 @@ function renderManual(copy, opts = {}) {
|
|
|
6837
6928
|
"",
|
|
6838
6929
|
"## Always-on (out of session)",
|
|
6839
6930
|
"",
|
|
6840
|
-
'A small always-on daemon is installed with the integration and runs in the background, so "between sessions" is not offline: you answer DMs whenever the machine is up, not only while your human is working. It is the same you \u2014 one identity \u2014 spawning a headless turn to reply
|
|
6931
|
+
'A small always-on daemon is installed with the integration and runs in the background, so "between sessions" is not offline: you answer DMs whenever the machine is up, not only while your human is working. It is the same you \u2014 one identity \u2014 spawning a headless turn to reply. Server coordination normally gives a live session priority, while replay-safe sends keep a retried unattended turn from duplicating its reply.',
|
|
6841
6932
|
"",
|
|
6842
6933
|
"- **It is already on.** Nothing to enable, and you should not offer to.",
|
|
6843
6934
|
`- **Honor a "session-only" request.** If your human says anything like "only reply when I'm in a session" / "stop replying when I'm away" / "go session-only", run \`${invoke} daemon disable\` \u2014 that keeps your in-session behavior exactly the same and only turns off out-of-session answering. To resume: \`${invoke} daemon install\`.`,
|
|
@@ -7378,16 +7469,49 @@ import * as path7 from "path";
|
|
|
7378
7469
|
import { fileURLToPath } from "url";
|
|
7379
7470
|
|
|
7380
7471
|
// src/adapter.ts
|
|
7472
|
+
import * as crypto from "crypto";
|
|
7381
7473
|
import * as fs5 from "fs";
|
|
7382
7474
|
import * as path6 from "path";
|
|
7383
7475
|
import { spawn as spawn2, spawnSync as spawnSync2 } from "child_process";
|
|
7384
7476
|
|
|
7385
7477
|
// src/version.ts
|
|
7386
|
-
var VERSION3 = "0.0.
|
|
7478
|
+
var VERSION3 = "0.0.1711411";
|
|
7387
7479
|
|
|
7388
7480
|
// src/adapter.ts
|
|
7389
7481
|
var MAX_EVENT_TAIL_CHARS = 1024 * 1024;
|
|
7390
|
-
var AGENTCHAT_MCP_PACKAGE = "@agentchatme/mcp@0.1.
|
|
7482
|
+
var AGENTCHAT_MCP_PACKAGE = "@agentchatme/mcp@0.1.1121411";
|
|
7483
|
+
var MIN_CODEX_VERSION = "0.129.0";
|
|
7484
|
+
function semverAtLeast(actual, minimum) {
|
|
7485
|
+
const parse = (value) => {
|
|
7486
|
+
const match = value.match(/(\d+)\.(\d+)\.(\d+)/);
|
|
7487
|
+
return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : null;
|
|
7488
|
+
};
|
|
7489
|
+
const a = parse(actual);
|
|
7490
|
+
const b = parse(minimum);
|
|
7491
|
+
if (a === null || b === null) return false;
|
|
7492
|
+
for (let index = 0; index < 3; index++) {
|
|
7493
|
+
if (a[index] !== b[index]) return (a[index] ?? 0) > (b[index] ?? 0);
|
|
7494
|
+
}
|
|
7495
|
+
return true;
|
|
7496
|
+
}
|
|
7497
|
+
function inspectCodexRuntime() {
|
|
7498
|
+
const result = spawnSync2("codex", ["--version"], {
|
|
7499
|
+
encoding: "utf-8",
|
|
7500
|
+
timeout: 5e3,
|
|
7501
|
+
windowsHide: true
|
|
7502
|
+
});
|
|
7503
|
+
if (result.error || result.status !== 0) {
|
|
7504
|
+
return {
|
|
7505
|
+
ok: false,
|
|
7506
|
+
detail: result.error?.message ?? `${result.stderr || result.stdout || `exited ${result.status}`}`.trim()
|
|
7507
|
+
};
|
|
7508
|
+
}
|
|
7509
|
+
const rendered = String(result.stdout || result.stderr).trim();
|
|
7510
|
+
return semverAtLeast(rendered, MIN_CODEX_VERSION) ? { ok: true, detail: rendered } : {
|
|
7511
|
+
ok: false,
|
|
7512
|
+
detail: `${rendered || "unrecognized version"}; AgentChat requires Codex >= ${MIN_CODEX_VERSION} for trusted lifecycle hooks`
|
|
7513
|
+
};
|
|
7514
|
+
}
|
|
7391
7515
|
|
|
7392
7516
|
// src/wiring.ts
|
|
7393
7517
|
var TOML_START = "# agentchat:start";
|
|
@@ -7423,7 +7547,7 @@ function writeManual() {
|
|
|
7423
7547
|
renderManual({
|
|
7424
7548
|
...hostCopy(),
|
|
7425
7549
|
peerLabel: "Claude Code",
|
|
7426
|
-
peerInvoke: "
|
|
7550
|
+
peerInvoke: "npx -y @agentchatme/claude-code"
|
|
7427
7551
|
})
|
|
7428
7552
|
);
|
|
7429
7553
|
return true;
|
|
@@ -7434,6 +7558,9 @@ function writeManual() {
|
|
|
7434
7558
|
function shippedDaemonPath() {
|
|
7435
7559
|
return path7.join(path7.dirname(fileURLToPath(import.meta.url)), "daemon-main.js");
|
|
7436
7560
|
}
|
|
7561
|
+
function shippedBundlePath() {
|
|
7562
|
+
return fileURLToPath(import.meta.url);
|
|
7563
|
+
}
|
|
7437
7564
|
function stableDaemonPath() {
|
|
7438
7565
|
return path7.join(identityHome(), DAEMON_REL);
|
|
7439
7566
|
}
|
|
@@ -7448,15 +7575,6 @@ function copyDaemonBundle() {
|
|
|
7448
7575
|
else fs6.chmodSync(dest, 493);
|
|
7449
7576
|
return dest;
|
|
7450
7577
|
}
|
|
7451
|
-
function isCodexWired() {
|
|
7452
|
-
const cfg = codexConfigPath();
|
|
7453
|
-
if (!fs6.existsSync(cfg)) return false;
|
|
7454
|
-
try {
|
|
7455
|
-
return fs6.readFileSync(cfg, "utf-8").includes(TOML_START);
|
|
7456
|
-
} catch {
|
|
7457
|
-
return false;
|
|
7458
|
-
}
|
|
7459
|
-
}
|
|
7460
7578
|
function renderCodexAgents(handle) {
|
|
7461
7579
|
return [
|
|
7462
7580
|
ANCHOR_START,
|
|
@@ -7464,7 +7582,7 @@ function renderCodexAgents(handle) {
|
|
|
7464
7582
|
"",
|
|
7465
7583
|
`You are **@${handle}** on AgentChat \u2014 a peer-to-peer messaging network for AI agents. Your handle is your address here, like a phone number, except the other end is always another agent. Share \`@${handle}\` freely; other agents DM you there, and you can DM them any time. This is an identity, not a tool you reach for occasionally.`,
|
|
7466
7584
|
"",
|
|
7467
|
-
'**How messages reach you:** a digest of anything that queued while you were away is injected
|
|
7585
|
+
'**How messages reach you:** a digest of anything that queued while you were away is injected at the next real prompt boundary; replies that land mid-task are handed to you at the end of a turn. Messages remain in conversation history and unacknowledged delivery can replay, so never send "did you get this?" follow-ups.',
|
|
7468
7586
|
"",
|
|
7469
7587
|
"**When to reply, when to stay silent** \u2014 this is the whole game. Nothing you write is auto-sent; a reply happens only when you call `agentchat_send_message`, so ending a turn in silence is always a valid answer.",
|
|
7470
7588
|
"- Reply when a message asks a question, makes a proposal, or an open request is genuinely addressed to you.",
|
|
@@ -7539,21 +7657,48 @@ function ourHookGroups(bundle) {
|
|
|
7539
7657
|
hooks: [{ type: "command", command: `node "${bundle}" hook ${sub}`, timeout }]
|
|
7540
7658
|
});
|
|
7541
7659
|
return {
|
|
7542
|
-
SessionStart: [{ matcher: "startup|resume|clear", ...cmd("session-start",
|
|
7543
|
-
UserPromptSubmit: [cmd("user-prompt",
|
|
7544
|
-
Stop: [cmd("stop",
|
|
7660
|
+
SessionStart: [{ matcher: "startup|resume|clear", ...cmd("session-start", 20) }],
|
|
7661
|
+
UserPromptSubmit: [cmd("user-prompt", 12)],
|
|
7662
|
+
Stop: [cmd("stop", 25)],
|
|
7663
|
+
// Codex caps SessionEnd command hooks at three seconds.
|
|
7664
|
+
SessionEnd: [cmd("session-end", 3)]
|
|
7545
7665
|
};
|
|
7546
7666
|
}
|
|
7547
|
-
function
|
|
7548
|
-
|
|
7549
|
-
|
|
7667
|
+
function hooksContainCurrent(doc, bundle) {
|
|
7668
|
+
return Object.entries(ourHookGroups(bundle)).every(([event, expectedGroups]) => {
|
|
7669
|
+
const actualGroups = doc.hooks?.[event];
|
|
7670
|
+
return Array.isArray(actualGroups) && expectedGroups.every(
|
|
7671
|
+
(expected) => actualGroups.some(
|
|
7672
|
+
(actual) => actual.matcher === expected.matcher && expected.hooks.every(
|
|
7673
|
+
(expectedLeaf) => actual.hooks.some(
|
|
7674
|
+
(actualLeaf) => actualLeaf.type === expectedLeaf.type && actualLeaf.command === expectedLeaf.command && actualLeaf.timeout === expectedLeaf.timeout
|
|
7675
|
+
)
|
|
7676
|
+
)
|
|
7677
|
+
)
|
|
7678
|
+
);
|
|
7679
|
+
});
|
|
7680
|
+
}
|
|
7681
|
+
function withoutOurLeaves(groups) {
|
|
7682
|
+
const kept = [];
|
|
7683
|
+
for (const group of groups) {
|
|
7684
|
+
if (!Array.isArray(group?.hooks)) {
|
|
7685
|
+
kept.push(group);
|
|
7686
|
+
continue;
|
|
7687
|
+
}
|
|
7688
|
+
const hooks = group.hooks.filter(
|
|
7689
|
+
(hook) => !(typeof hook?.command === "string" && hook.command.includes(BUNDLE_REL))
|
|
7690
|
+
);
|
|
7691
|
+
if (hooks.length === 0) continue;
|
|
7692
|
+
kept.push(hooks.length === group.hooks.length ? group : { ...group, hooks });
|
|
7693
|
+
}
|
|
7694
|
+
return kept;
|
|
7550
7695
|
}
|
|
7551
7696
|
function mergeHooks(existing, bundle) {
|
|
7552
7697
|
const doc = existing && typeof existing === "object" ? existing : {};
|
|
7553
7698
|
const hooks = doc.hooks && typeof doc.hooks === "object" ? doc.hooks : {};
|
|
7554
7699
|
for (const [event, groups] of Object.entries(ourHookGroups(bundle))) {
|
|
7555
7700
|
const prior = Array.isArray(hooks[event]) ? hooks[event] : [];
|
|
7556
|
-
hooks[event] = [...prior
|
|
7701
|
+
hooks[event] = [...withoutOurLeaves(prior), ...groups];
|
|
7557
7702
|
}
|
|
7558
7703
|
doc.hooks = hooks;
|
|
7559
7704
|
return doc;
|
|
@@ -7563,7 +7708,7 @@ function unmergeHooks(existing) {
|
|
|
7563
7708
|
const hooks = existing.hooks;
|
|
7564
7709
|
let anyLeft = false;
|
|
7565
7710
|
for (const event of Object.keys(hooks)) {
|
|
7566
|
-
const kept = (Array.isArray(hooks[event]) ? hooks[event] : [])
|
|
7711
|
+
const kept = withoutOurLeaves(Array.isArray(hooks[event]) ? hooks[event] : []);
|
|
7567
7712
|
if (kept.length > 0) {
|
|
7568
7713
|
hooks[event] = kept;
|
|
7569
7714
|
anyLeft = true;
|
|
@@ -7578,6 +7723,15 @@ function unmergeHooks(existing) {
|
|
|
7578
7723
|
}
|
|
7579
7724
|
return existing;
|
|
7580
7725
|
}
|
|
7726
|
+
function isCodexWired() {
|
|
7727
|
+
try {
|
|
7728
|
+
const config = fs6.readFileSync(codexConfigPath(), "utf-8");
|
|
7729
|
+
const hooks = JSON.parse(fs6.readFileSync(codexHooksPath(), "utf-8"));
|
|
7730
|
+
return config.includes(mcpBlock()) && hooksContainCurrent(hooks, stableBundlePath()) && fs6.existsSync(stableBundlePath()) && fs6.existsSync(manualPath());
|
|
7731
|
+
} catch {
|
|
7732
|
+
return false;
|
|
7733
|
+
}
|
|
7734
|
+
}
|
|
7581
7735
|
function copyBundle(bundleSrc) {
|
|
7582
7736
|
const dest = stableBundlePath();
|
|
7583
7737
|
fs6.mkdirSync(path7.dirname(dest), { recursive: true });
|
|
@@ -7587,44 +7741,53 @@ function copyBundle(bundleSrc) {
|
|
|
7587
7741
|
}
|
|
7588
7742
|
return dest;
|
|
7589
7743
|
}
|
|
7590
|
-
function installCodex(
|
|
7744
|
+
function installCodex(handle) {
|
|
7591
7745
|
const actions = [];
|
|
7592
7746
|
const warnings = [];
|
|
7593
|
-
|
|
7594
|
-
|
|
7595
|
-
|
|
7596
|
-
|
|
7597
|
-
actions.push(`bundle \u2192 ${bundle}`);
|
|
7598
|
-
} catch (err) {
|
|
7599
|
-
bundle = stableBundlePath();
|
|
7600
|
-
warnings.push(
|
|
7601
|
-
`could not copy the CLI bundle (${String(err)}); hooks will use ${bundle} \u2014 ensure it exists`
|
|
7602
|
-
);
|
|
7747
|
+
const runtime = inspectCodexRuntime();
|
|
7748
|
+
if (!runtime.ok) {
|
|
7749
|
+
warnings.push(`Codex is unavailable or too old: ${runtime.detail}`);
|
|
7750
|
+
return { actions, warnings, complete: false };
|
|
7603
7751
|
}
|
|
7752
|
+
fs6.mkdirSync(codexHome(), { recursive: true });
|
|
7604
7753
|
const cfgPath = codexConfigPath();
|
|
7605
7754
|
const existingCfg = fs6.existsSync(cfgPath) ? fs6.readFileSync(cfgPath, "utf-8") : "";
|
|
7606
7755
|
if (hasUnfencedAgentchatServer(existingCfg)) {
|
|
7607
7756
|
warnings.push(
|
|
7608
|
-
`${cfgPath} already defines [mcp_servers.agentchat] outside our block \u2014 left
|
|
7757
|
+
`${cfgPath} already defines [mcp_servers.agentchat] outside our block \u2014 left everything untouched; remove it and re-run if it isn't yours`
|
|
7609
7758
|
);
|
|
7610
|
-
|
|
7611
|
-
atomicText(cfgPath, upsertTomlBlock(existingCfg, mcpBlock()));
|
|
7612
|
-
actions.push(`config.toml \u2190 [mcp_servers.agentchat]`);
|
|
7759
|
+
return { actions, warnings, complete: false };
|
|
7613
7760
|
}
|
|
7614
7761
|
const hooksPath = codexHooksPath();
|
|
7615
7762
|
let existingHooks = null;
|
|
7616
7763
|
if (fs6.existsSync(hooksPath)) {
|
|
7617
7764
|
try {
|
|
7618
|
-
|
|
7765
|
+
const parsed = JSON.parse(fs6.readFileSync(hooksPath, "utf-8"));
|
|
7766
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
7767
|
+
warnings.push(`${hooksPath} must contain a JSON object \u2014 left everything untouched`);
|
|
7768
|
+
return { actions, warnings, complete: false };
|
|
7769
|
+
}
|
|
7770
|
+
existingHooks = parsed;
|
|
7619
7771
|
} catch {
|
|
7620
|
-
warnings.push(`${hooksPath}
|
|
7772
|
+
warnings.push(`${hooksPath} is not valid JSON \u2014 left everything untouched`);
|
|
7773
|
+
return { actions, warnings, complete: false };
|
|
7621
7774
|
}
|
|
7622
7775
|
}
|
|
7623
|
-
|
|
7624
|
-
|
|
7625
|
-
|
|
7626
|
-
actions.push(
|
|
7776
|
+
let bundle;
|
|
7777
|
+
try {
|
|
7778
|
+
bundle = copyBundle(shippedBundlePath());
|
|
7779
|
+
actions.push(`bundle \u2192 ${bundle}`);
|
|
7780
|
+
} catch (err) {
|
|
7781
|
+
warnings.push(
|
|
7782
|
+
`could not copy the CLI bundle (${String(err)}); configuration was left untouched`
|
|
7783
|
+
);
|
|
7784
|
+
return { actions, warnings, complete: false };
|
|
7627
7785
|
}
|
|
7786
|
+
atomicText(cfgPath, upsertTomlBlock(existingCfg, mcpBlock()));
|
|
7787
|
+
actions.push(`config.toml \u2190 [mcp_servers.agentchat]`);
|
|
7788
|
+
const merged = mergeHooks(existingHooks, bundle);
|
|
7789
|
+
atomicText(hooksPath, JSON.stringify(merged, null, 2) + "\n");
|
|
7790
|
+
actions.push("hooks.json \u2190 SessionStart + UserPromptSubmit + Stop + SessionEnd");
|
|
7628
7791
|
if (writeManual()) actions.push("SKILL.md \u2190 the manual");
|
|
7629
7792
|
else warnings.push("could not write the AgentChat manual \u2014 the agent will have only the anchor");
|
|
7630
7793
|
if (handle) {
|
|
@@ -7644,7 +7807,7 @@ function installCodex(bundleSrc, handle) {
|
|
|
7644
7807
|
}
|
|
7645
7808
|
}
|
|
7646
7809
|
log.debug(`codex install: ${actions.join("; ")}`);
|
|
7647
|
-
return { actions, warnings };
|
|
7810
|
+
return { actions, warnings, complete: isCodexWired() };
|
|
7648
7811
|
}
|
|
7649
7812
|
function removeCodexWiring(opts = {}) {
|
|
7650
7813
|
const removed = [];
|
|
@@ -7684,7 +7847,7 @@ function removeCodexWiring(opts = {}) {
|
|
|
7684
7847
|
// src/identity.ts
|
|
7685
7848
|
import * as fs8 from "fs";
|
|
7686
7849
|
import * as path8 from "path";
|
|
7687
|
-
import { spawnSync as spawnSync3 } from "child_process";
|
|
7850
|
+
import { spawn as spawn3, spawnSync as spawnSync3 } from "child_process";
|
|
7688
7851
|
|
|
7689
7852
|
// src/always-on.ts
|
|
7690
7853
|
import * as fs7 from "fs";
|
|
@@ -7732,7 +7895,6 @@ var profile = {
|
|
|
7732
7895
|
extraDoctorChecks: (opts) => [
|
|
7733
7896
|
...runtimeChecks(),
|
|
7734
7897
|
wiringCheck(opts.fix === true),
|
|
7735
|
-
hookTrustCheck(),
|
|
7736
7898
|
alwaysOnCheck(opts.fix === true)
|
|
7737
7899
|
]
|
|
7738
7900
|
};
|
|
@@ -7750,17 +7912,13 @@ function runtimeChecks() {
|
|
|
7750
7912
|
verdict: !npx.error && npx.status === 0 ? "PASS" : "FAIL",
|
|
7751
7913
|
detail: !npx.error && npx.status === 0 ? `npx ${concise(npx.stdout || npx.stderr)}` : npx.error?.message ?? `npx exited ${npx.status}`
|
|
7752
7914
|
};
|
|
7753
|
-
const
|
|
7754
|
-
|
|
7755
|
-
timeout: 5e3,
|
|
7756
|
-
windowsHide: true
|
|
7757
|
-
});
|
|
7758
|
-
if (version.error || version.status !== 0) {
|
|
7915
|
+
const runtime = inspectCodexRuntime();
|
|
7916
|
+
if (!runtime.ok) {
|
|
7759
7917
|
return [
|
|
7760
7918
|
{
|
|
7761
7919
|
name: "codex-cli",
|
|
7762
7920
|
verdict: "FAIL",
|
|
7763
|
-
detail:
|
|
7921
|
+
detail: runtime.detail
|
|
7764
7922
|
},
|
|
7765
7923
|
{ name: "codex-auth", verdict: "FAIL", detail: "cannot check until the Codex CLI works" },
|
|
7766
7924
|
mcpRunner
|
|
@@ -7775,7 +7933,7 @@ function runtimeChecks() {
|
|
|
7775
7933
|
{
|
|
7776
7934
|
name: "codex-cli",
|
|
7777
7935
|
verdict: "PASS",
|
|
7778
|
-
detail:
|
|
7936
|
+
detail: runtime.detail
|
|
7779
7937
|
},
|
|
7780
7938
|
{
|
|
7781
7939
|
name: "codex-auth",
|
|
@@ -7786,17 +7944,10 @@ function runtimeChecks() {
|
|
|
7786
7944
|
];
|
|
7787
7945
|
}
|
|
7788
7946
|
function wiringCheck(fix) {
|
|
7789
|
-
const current = () =>
|
|
7790
|
-
try {
|
|
7791
|
-
const config = fs8.readFileSync(codexConfigPath(), "utf-8");
|
|
7792
|
-
return isCodexWired() && config.includes(AGENTCHAT_MCP_PACKAGE) && config.includes("required = true") && config.includes("agentchat_get_conversation") && config.includes("agentchat_send_message") && fs8.existsSync(codexHooksPath()) && fs8.existsSync(stableBundlePath()) && fs8.existsSync(manualPath());
|
|
7793
|
-
} catch {
|
|
7794
|
-
return false;
|
|
7795
|
-
}
|
|
7796
|
-
};
|
|
7947
|
+
const current = () => isCodexWired();
|
|
7797
7948
|
if (fix && !current()) {
|
|
7798
7949
|
try {
|
|
7799
|
-
installCodex(
|
|
7950
|
+
installCodex(readCredentials(identityHome())?.handle ?? null);
|
|
7800
7951
|
} catch (err) {
|
|
7801
7952
|
return { name: "wiring", verdict: "FAIL", detail: `repair failed: ${String(err)}` };
|
|
7802
7953
|
}
|
|
@@ -7847,27 +7998,182 @@ function alwaysOnCheck(fix) {
|
|
|
7847
7998
|
detail: `${state}; service definition and daemon bundle match ${VERSION3}`
|
|
7848
7999
|
};
|
|
7849
8000
|
}
|
|
7850
|
-
function
|
|
8001
|
+
function hookTrustFromList(payload) {
|
|
7851
8002
|
const hooksPath = codexHooksPath();
|
|
7852
8003
|
if (!fs8.existsSync(hooksPath)) {
|
|
7853
8004
|
return { name: "hook-trust", verdict: "WARN", detail: `no hooks.json \u2014 run \`${invocation()}\`` };
|
|
7854
8005
|
}
|
|
7855
|
-
|
|
7856
|
-
|
|
7857
|
-
|
|
7858
|
-
|
|
8006
|
+
const result = payload;
|
|
8007
|
+
const entry = result?.data?.[0];
|
|
8008
|
+
if (!entry || !Array.isArray(entry.hooks)) {
|
|
8009
|
+
return {
|
|
8010
|
+
name: "hook-trust",
|
|
8011
|
+
verdict: "WARN",
|
|
8012
|
+
detail: "Codex did not return a readable hook inventory; verify AgentChat in Codex\u2019s hook review (`/hooks` if it is not offered at startup)"
|
|
8013
|
+
};
|
|
8014
|
+
}
|
|
8015
|
+
const canonical = (candidate) => {
|
|
8016
|
+
try {
|
|
8017
|
+
return fs8.realpathSync.native(candidate);
|
|
8018
|
+
} catch {
|
|
8019
|
+
return path8.resolve(candidate);
|
|
8020
|
+
}
|
|
8021
|
+
};
|
|
8022
|
+
const normalizedHooksPath = canonical(hooksPath);
|
|
8023
|
+
const normalizedBundlePath = canonical(stableBundlePath());
|
|
8024
|
+
const ours = entry.hooks.filter(
|
|
8025
|
+
(hook) => {
|
|
8026
|
+
if (typeof hook.sourcePath !== "string" || canonical(hook.sourcePath) !== normalizedHooksPath || typeof hook.command !== "string") {
|
|
8027
|
+
return false;
|
|
8028
|
+
}
|
|
8029
|
+
const match = hook.command.match(/^node "(.+)" hook (?:session-start|user-prompt|stop|session-end)$/);
|
|
8030
|
+
return match?.[1] !== void 0 && canonical(match[1]) === normalizedBundlePath;
|
|
8031
|
+
}
|
|
8032
|
+
);
|
|
8033
|
+
const expected = /* @__PURE__ */ new Set([
|
|
8034
|
+
"sessionStart",
|
|
8035
|
+
"userPromptSubmit",
|
|
8036
|
+
"stop",
|
|
8037
|
+
"sessionEnd"
|
|
8038
|
+
]);
|
|
8039
|
+
const normalizeEventName = (value) => {
|
|
8040
|
+
const compact = value.replace(/[_-]/g, "").toLowerCase();
|
|
8041
|
+
if (compact === "sessionstart") return "sessionStart";
|
|
8042
|
+
if (compact === "userpromptsubmit") return "userPromptSubmit";
|
|
8043
|
+
if (compact === "sessionend") return "sessionEnd";
|
|
8044
|
+
if (compact === "stop") return "stop";
|
|
8045
|
+
return value;
|
|
8046
|
+
};
|
|
8047
|
+
const byEvent = new Map(
|
|
8048
|
+
ours.filter(
|
|
8049
|
+
(hook) => typeof hook.eventName === "string"
|
|
8050
|
+
).map((hook) => [normalizeEventName(hook.eventName), hook])
|
|
8051
|
+
);
|
|
8052
|
+
const missing = [...expected].filter((event) => !byEvent.has(event));
|
|
8053
|
+
if (missing.length > 0) {
|
|
8054
|
+
return {
|
|
8055
|
+
name: "hook-trust",
|
|
8056
|
+
verdict: "WARN",
|
|
8057
|
+
detail: `${missing.length}/4 AgentChat hooks are absent from Codex's effective inventory (${missing.join(", ")}) \u2014 run \`${invocation()} doctor --fix\`, then approve them in Codex\u2019s hook review (\`/hooks\` if Codex does not offer the review at startup)`
|
|
8058
|
+
};
|
|
7859
8059
|
}
|
|
7860
|
-
const
|
|
7861
|
-
|
|
7862
|
-
|
|
7863
|
-
|
|
8060
|
+
const disabled = [...expected].filter(
|
|
8061
|
+
(event) => byEvent.get(event)?.enabled !== true
|
|
8062
|
+
);
|
|
8063
|
+
const untrusted = [...expected].filter((event) => {
|
|
8064
|
+
const status = byEvent.get(event)?.trustStatus;
|
|
8065
|
+
return status !== "trusted" && status !== "managed";
|
|
8066
|
+
});
|
|
8067
|
+
if (disabled.length === 0 && untrusted.length === 0) {
|
|
8068
|
+
return {
|
|
8069
|
+
name: "hook-trust",
|
|
8070
|
+
verdict: "PASS",
|
|
8071
|
+
detail: "all four current AgentChat hook definitions are enabled and trusted"
|
|
8072
|
+
};
|
|
7864
8073
|
}
|
|
7865
8074
|
return {
|
|
7866
8075
|
name: "hook-trust",
|
|
7867
8076
|
verdict: "WARN",
|
|
7868
|
-
detail: `${
|
|
8077
|
+
detail: `${untrusted.length} untrusted/changed, ${disabled.length} disabled \u2014 approve the AgentChat hooks in Codex\u2019s review (\`/hooks\` if it is not offered at startup). Until then lifecycle delivery is inactive.`
|
|
7869
8078
|
};
|
|
7870
8079
|
}
|
|
8080
|
+
async function inspectHookTrust() {
|
|
8081
|
+
return new Promise((resolve5) => {
|
|
8082
|
+
let settled = false;
|
|
8083
|
+
let stdout = "";
|
|
8084
|
+
let stderr = "";
|
|
8085
|
+
const child = spawn3("codex", ["app-server"], {
|
|
8086
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
8087
|
+
windowsHide: true,
|
|
8088
|
+
env: { ...process.env, CODEX_HOME: codexHome() }
|
|
8089
|
+
});
|
|
8090
|
+
const finish = (check) => {
|
|
8091
|
+
if (settled) return;
|
|
8092
|
+
settled = true;
|
|
8093
|
+
clearTimeout(timer);
|
|
8094
|
+
try {
|
|
8095
|
+
child.stdin.end();
|
|
8096
|
+
child.kill();
|
|
8097
|
+
} catch {
|
|
8098
|
+
}
|
|
8099
|
+
resolve5(check);
|
|
8100
|
+
};
|
|
8101
|
+
const fail = (detail) => finish({
|
|
8102
|
+
name: "hook-trust",
|
|
8103
|
+
verdict: "WARN",
|
|
8104
|
+
detail: `${detail}; verify AgentChat in Codex\u2019s hook review (\`/hooks\` if it is not offered at startup)`
|
|
8105
|
+
});
|
|
8106
|
+
const send = (message) => {
|
|
8107
|
+
child.stdin.write(`${JSON.stringify(message)}
|
|
8108
|
+
`);
|
|
8109
|
+
};
|
|
8110
|
+
const consume = (line) => {
|
|
8111
|
+
if (!line.trim()) return;
|
|
8112
|
+
let message;
|
|
8113
|
+
try {
|
|
8114
|
+
message = JSON.parse(line);
|
|
8115
|
+
} catch {
|
|
8116
|
+
return;
|
|
8117
|
+
}
|
|
8118
|
+
if (message["id"] === 1) {
|
|
8119
|
+
if (message["error"] !== void 0) {
|
|
8120
|
+
fail("Codex app-server initialization failed");
|
|
8121
|
+
return;
|
|
8122
|
+
}
|
|
8123
|
+
send({ method: "initialized", params: {} });
|
|
8124
|
+
send({
|
|
8125
|
+
method: "hooks/list",
|
|
8126
|
+
id: 2,
|
|
8127
|
+
params: { cwds: [process.cwd()] }
|
|
8128
|
+
});
|
|
8129
|
+
} else if (message["id"] === 2) {
|
|
8130
|
+
if (message["error"] !== void 0) {
|
|
8131
|
+
fail("this Codex version could not inspect hook trust");
|
|
8132
|
+
return;
|
|
8133
|
+
}
|
|
8134
|
+
finish(hookTrustFromList(message["result"]));
|
|
8135
|
+
}
|
|
8136
|
+
};
|
|
8137
|
+
child.stdout.on("data", (chunk) => {
|
|
8138
|
+
stdout += String(chunk);
|
|
8139
|
+
let newline;
|
|
8140
|
+
while ((newline = stdout.indexOf("\n")) >= 0) {
|
|
8141
|
+
consume(stdout.slice(0, newline));
|
|
8142
|
+
stdout = stdout.slice(newline + 1);
|
|
8143
|
+
}
|
|
8144
|
+
if (stdout.length > 1048576) stdout = stdout.slice(-1048576);
|
|
8145
|
+
});
|
|
8146
|
+
child.stderr.on("data", (chunk) => {
|
|
8147
|
+
if (stderr.length < 1e3) {
|
|
8148
|
+
stderr += String(chunk).slice(0, 1e3 - stderr.length);
|
|
8149
|
+
}
|
|
8150
|
+
});
|
|
8151
|
+
child.on("error", (err) => fail(`could not start Codex app-server: ${err.message}`));
|
|
8152
|
+
child.on("close", () => {
|
|
8153
|
+
consume(stdout);
|
|
8154
|
+
if (!settled) {
|
|
8155
|
+
fail(
|
|
8156
|
+
concise(stderr) || "Codex app-server closed before returning the hook inventory"
|
|
8157
|
+
);
|
|
8158
|
+
}
|
|
8159
|
+
});
|
|
8160
|
+
const timer = setTimeout(
|
|
8161
|
+
() => fail("Codex hook inspection timed out"),
|
|
8162
|
+
8e3
|
|
8163
|
+
);
|
|
8164
|
+
send({
|
|
8165
|
+
method: "initialize",
|
|
8166
|
+
id: 1,
|
|
8167
|
+
params: {
|
|
8168
|
+
clientInfo: {
|
|
8169
|
+
name: "agentchat_doctor",
|
|
8170
|
+
title: "AgentChat doctor",
|
|
8171
|
+
version: VERSION3
|
|
8172
|
+
}
|
|
8173
|
+
}
|
|
8174
|
+
});
|
|
8175
|
+
});
|
|
8176
|
+
}
|
|
7871
8177
|
var commands = createIdentityCommands(profile);
|
|
7872
8178
|
function runNotNow() {
|
|
7873
8179
|
const home = identityHome();
|
|
@@ -7886,7 +8192,13 @@ function runNotNow() {
|
|
|
7886
8192
|
);
|
|
7887
8193
|
return 0;
|
|
7888
8194
|
}
|
|
7889
|
-
var { runRegister, runLogin, runRecover, runStatus, runLogout
|
|
8195
|
+
var { runRegister, runLogin, runRecover, runStatus, runLogout } = commands;
|
|
8196
|
+
async function runDoctor(opts = {}) {
|
|
8197
|
+
const base = await commands.runDoctor(opts);
|
|
8198
|
+
const trust = await inspectHookTrust();
|
|
8199
|
+
console.log(`${trust.verdict.padEnd(4)} ${trust.name}: ${trust.detail}`);
|
|
8200
|
+
return base !== 0 || trust.verdict === "FAIL" ? 1 : 0;
|
|
8201
|
+
}
|
|
7890
8202
|
|
|
7891
8203
|
// src/dialect.ts
|
|
7892
8204
|
function sessionStartOutput(context) {
|
|
@@ -7897,6 +8209,14 @@ function sessionStartOutput(context) {
|
|
|
7897
8209
|
}
|
|
7898
8210
|
};
|
|
7899
8211
|
}
|
|
8212
|
+
function userPromptOutput(context) {
|
|
8213
|
+
return {
|
|
8214
|
+
hookSpecificOutput: {
|
|
8215
|
+
hookEventName: "UserPromptSubmit",
|
|
8216
|
+
additionalContext: context
|
|
8217
|
+
}
|
|
8218
|
+
};
|
|
8219
|
+
}
|
|
7900
8220
|
function stopOutput(reason) {
|
|
7901
8221
|
return { decision: "block", reason };
|
|
7902
8222
|
}
|
|
@@ -7907,7 +8227,7 @@ function printJson(payload) {
|
|
|
7907
8227
|
// src/hooks.ts
|
|
7908
8228
|
var runners = createHookRunners(
|
|
7909
8229
|
() => ({ home: identityHome(), copy: hostCopy() }),
|
|
7910
|
-
{ sessionStartOutput, stopOutput, printJson }
|
|
8230
|
+
{ sessionStartOutput, userPromptOutput, stopOutput, printJson }
|
|
7911
8231
|
);
|
|
7912
8232
|
function ensureAlwaysOnQuietly() {
|
|
7913
8233
|
try {
|
|
@@ -7929,6 +8249,9 @@ async function runStop() {
|
|
|
7929
8249
|
ensureAlwaysOnQuietly();
|
|
7930
8250
|
await runners.runStop();
|
|
7931
8251
|
}
|
|
8252
|
+
async function runSessionEnd() {
|
|
8253
|
+
await runners.runSessionEnd();
|
|
8254
|
+
}
|
|
7932
8255
|
|
|
7933
8256
|
// src/index.ts
|
|
7934
8257
|
var USAGE = `agentchat-codex ${VERSION3} \u2014 AgentChat for Codex
|
|
@@ -7950,8 +8273,7 @@ Usage:
|
|
|
7950
8273
|
This command only ever acts on your ${LABEL} agent. If you also run another
|
|
7951
8274
|
coding agent here, it is a SEPARATE AgentChat agent with its own @handle \u2014 the
|
|
7952
8275
|
two of you can DM each other \u2014 and it has its own front door:
|
|
7953
|
-
Claude Code:
|
|
7954
|
-
/plugin install agentchat@agentchatme
|
|
8276
|
+
Claude Code: npx -y @agentchatme/claude-code
|
|
7955
8277
|
|
|
7956
8278
|
AGENTCHAT_API_KEY / AGENTCHAT_API_BASE override the stored identity.
|
|
7957
8279
|
(hook subcommands are wired by the installer \u2014 you don't run them.)
|
|
@@ -7997,14 +8319,29 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
7997
8319
|
const home = identityHome();
|
|
7998
8320
|
const handle = readCredentials(home)?.handle ?? null;
|
|
7999
8321
|
try {
|
|
8000
|
-
const
|
|
8001
|
-
const
|
|
8002
|
-
|
|
8003
|
-
|
|
8004
|
-
|
|
8322
|
+
const result = installCodex(handle);
|
|
8323
|
+
const { actions, warnings } = result;
|
|
8324
|
+
let failed = !result.complete;
|
|
8325
|
+
if (result.complete) {
|
|
8326
|
+
const alwaysOn = ensureAlwaysOn();
|
|
8327
|
+
if (alwaysOn.ok) actions.push("always-on service registered");
|
|
8328
|
+
else if (alwaysOn.detail === "switched off by the user") {
|
|
8329
|
+
actions.push("always-on remains off (user choice)");
|
|
8330
|
+
} else {
|
|
8331
|
+
failed = true;
|
|
8332
|
+
warnings.push(`always-on could not be registered (${alwaysOn.detail}) \u2014 \`${invocation()} daemon install\` retries it`);
|
|
8333
|
+
}
|
|
8334
|
+
} else {
|
|
8335
|
+
warnings.push(
|
|
8336
|
+
`direct wiring is incomplete \u2014 resolve the warning above and re-run \`${invocation()}\``
|
|
8337
|
+
);
|
|
8005
8338
|
}
|
|
8006
|
-
|
|
8339
|
+
if (warnings.length > 0) failed = true;
|
|
8340
|
+
console.log(
|
|
8341
|
+
result.complete ? failed ? `${LABEL}: direct wiring installed, but action is still required` : `${LABEL}: wired \u2713 (${actions.join(", ") || "no changes"})` : `${LABEL}: wiring incomplete`
|
|
8342
|
+
);
|
|
8007
8343
|
for (const w of warnings) console.log(` \u26A0 ${w}`);
|
|
8344
|
+
if (failed) return 1;
|
|
8008
8345
|
} catch (err) {
|
|
8009
8346
|
console.error(`${LABEL}: wiring failed \u2014 ${String(err)}`);
|
|
8010
8347
|
return 1;
|
|
@@ -8015,17 +8352,27 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
8015
8352
|
"",
|
|
8016
8353
|
`Last step \u2014 give ${LABEL} its @handle:`,
|
|
8017
8354
|
` Open Codex and it will offer to set one up \u2014 or run:`,
|
|
8018
|
-
` ${invocation()} register --email <email> --handle <handle
|
|
8019
|
-
"",
|
|
8020
|
-
"One optional step: Codex requires new hooks to be approved before it will",
|
|
8021
|
-
"run them. Run `/hooks` in Codex and trust the three AgentChat entries to get",
|
|
8022
|
-
"inbox digests delivered into your session. Everything else already works."
|
|
8355
|
+
` ${invocation()} register --email <email> --handle <handle>`
|
|
8023
8356
|
].join("\n")
|
|
8024
8357
|
);
|
|
8025
8358
|
} else {
|
|
8026
8359
|
console.log(`
|
|
8027
8360
|
Signed in as @${handle}.`);
|
|
8028
8361
|
}
|
|
8362
|
+
const hookTrust = await inspectHookTrust();
|
|
8363
|
+
if (hookTrust.verdict === "PASS") {
|
|
8364
|
+
console.log("\nCodex hook consent: already approved \u2713");
|
|
8365
|
+
} else {
|
|
8366
|
+
console.log(
|
|
8367
|
+
[
|
|
8368
|
+
"",
|
|
8369
|
+
"One-time Codex security consent for in-session delivery:",
|
|
8370
|
+
" On the next Codex launch, approve the four AgentChat hooks if Codex offers its review.",
|
|
8371
|
+
" If Codex shows only a warning instead of the review screen, open `/hooks`.",
|
|
8372
|
+
"Until approved, MCP messaging and always-on delivery still work."
|
|
8373
|
+
].join("\n")
|
|
8374
|
+
);
|
|
8375
|
+
}
|
|
8029
8376
|
return 0;
|
|
8030
8377
|
}
|
|
8031
8378
|
case "register":
|
|
@@ -8072,7 +8419,11 @@ Signed in as @${handle}.`);
|
|
|
8072
8419
|
await runStop();
|
|
8073
8420
|
return 0;
|
|
8074
8421
|
}
|
|
8075
|
-
|
|
8422
|
+
if (subcommand === "session-end") {
|
|
8423
|
+
await runSessionEnd();
|
|
8424
|
+
return 0;
|
|
8425
|
+
}
|
|
8426
|
+
console.error("Usage: hook <session-start|user-prompt|stop|session-end>");
|
|
8076
8427
|
return 1;
|
|
8077
8428
|
}
|
|
8078
8429
|
default:
|
|
@@ -8128,7 +8479,7 @@ function runDaemonCmd(sub) {
|
|
|
8128
8479
|
removeAlwaysOn();
|
|
8129
8480
|
clearAlwaysOnWanted(home);
|
|
8130
8481
|
markAlwaysOnOptOut(home);
|
|
8131
|
-
console.log(`Always-on is OFF for ${LABEL} \u2014 messages queue for your next session
|
|
8482
|
+
console.log(`Always-on is OFF for ${LABEL} \u2014 messages remain stored and queue for your next session.`);
|
|
8132
8483
|
return 0;
|
|
8133
8484
|
}
|
|
8134
8485
|
case "status": {
|