@agentchatme/codex 0.0.17114 → 0.0.171141
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 +13 -5
- package/dist/daemon-main.js +68 -32
- package/dist/daemon-main.js.map +1 -1
- package/dist/index.js +170 -80
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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.13131/node_modules/@agentchatme/agent-core/dist/chunk-M2X5WY7Q.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.13131";
|
|
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.13131/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";
|
|
@@ -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.13131/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";
|
|
@@ -6138,6 +6147,7 @@ function renderDeclinedBlock(copy) {
|
|
|
6138
6147
|
var SESSION_START_PEEK_LIMIT = 100;
|
|
6139
6148
|
var STOP_PEEK_LIMIT = 50;
|
|
6140
6149
|
var DEFAULT_MAX_CONTINUATIONS = 5;
|
|
6150
|
+
var FOREGROUND_TURN_TTL_SECONDS = 600;
|
|
6141
6151
|
function hooksDisabled() {
|
|
6142
6152
|
return process.env["AGENTCHAT_HOOKS_ENABLED"] === "0";
|
|
6143
6153
|
}
|
|
@@ -6194,7 +6204,6 @@ async function sessionStart(ctx, input) {
|
|
|
6194
6204
|
return none;
|
|
6195
6205
|
}
|
|
6196
6206
|
const cfg = { apiKey: identity.apiKey, apiBase: identity.apiBase };
|
|
6197
|
-
await markSessionActive(cfg);
|
|
6198
6207
|
const h = alwaysOnHealth(ctx.home);
|
|
6199
6208
|
const alert = h.wanted && !h.healthy ? formatAlwaysOnDown(ctx.copy) : null;
|
|
6200
6209
|
const peeked = ackableRows(await syncPeek(cfg, { limit: SESSION_START_PEEK_LIMIT }));
|
|
@@ -6218,9 +6227,10 @@ async function userPrompt(ctx, input) {
|
|
|
6218
6227
|
if (hooksDisabled()) return;
|
|
6219
6228
|
const identity = resolveIdentity(ctx.home);
|
|
6220
6229
|
if (identity === null) return;
|
|
6230
|
+
const cfg = { apiKey: identity.apiKey, apiBase: identity.apiBase };
|
|
6231
|
+
await markForegroundTurn(cfg, input.sessionId, FOREGROUND_TURN_TTL_SECONDS);
|
|
6221
6232
|
const cursor = takePendingAck(ctx.home, input.sessionId);
|
|
6222
6233
|
if (cursor === null) return;
|
|
6223
|
-
const cfg = { apiKey: identity.apiKey, apiBase: identity.apiBase };
|
|
6224
6234
|
try {
|
|
6225
6235
|
await syncAck(cfg, cursor);
|
|
6226
6236
|
} catch (err) {
|
|
@@ -6234,43 +6244,64 @@ async function userPrompt(ctx, input) {
|
|
|
6234
6244
|
async function stop(ctx, input) {
|
|
6235
6245
|
const none = { reason: null, commit: async () => {
|
|
6236
6246
|
} };
|
|
6247
|
+
let cfg = null;
|
|
6237
6248
|
try {
|
|
6238
6249
|
if (hooksDisabled()) return none;
|
|
6239
6250
|
const identity = resolveIdentity(ctx.home);
|
|
6240
6251
|
if (identity === null) return none;
|
|
6241
|
-
|
|
6242
|
-
await
|
|
6252
|
+
cfg = { apiKey: identity.apiKey, apiBase: identity.apiBase };
|
|
6253
|
+
await markForegroundTurn(cfg, input.sessionId, FOREGROUND_TURN_TTL_SECONDS);
|
|
6243
6254
|
const cap = maxContinuations();
|
|
6244
6255
|
if (getContinuations(ctx.home, input.sessionId) >= cap) {
|
|
6245
6256
|
log.info(
|
|
6246
6257
|
`stop hook: continuation cap (${cap}) reached for ${input.sessionId}; leaving inbox queued`
|
|
6247
6258
|
);
|
|
6259
|
+
await clearForegroundTurn(cfg, input.sessionId);
|
|
6248
6260
|
return none;
|
|
6249
6261
|
}
|
|
6250
6262
|
const peeked = ackableRows(await syncPeek(cfg, { limit: STOP_PEEK_LIMIT }));
|
|
6251
|
-
if (peeked.length === 0)
|
|
6263
|
+
if (peeked.length === 0) {
|
|
6264
|
+
await clearForegroundTurn(cfg, input.sessionId);
|
|
6265
|
+
return none;
|
|
6266
|
+
}
|
|
6252
6267
|
const rows = await claimContiguousPrefix(cfg, peeked, `session:${input.sessionId}`);
|
|
6253
|
-
if (rows.length === 0)
|
|
6268
|
+
if (rows.length === 0) {
|
|
6269
|
+
await clearForegroundTurn(cfg, input.sessionId);
|
|
6270
|
+
return none;
|
|
6271
|
+
}
|
|
6254
6272
|
recordContinuation(ctx.home, input.sessionId);
|
|
6255
6273
|
const handle = await resolveHandle(cfg, identity.handle);
|
|
6256
6274
|
const reason = formatStopPickup(handle, rows);
|
|
6257
6275
|
const cursor = lastDeliveryId(rows);
|
|
6276
|
+
const claimedCfg = cfg;
|
|
6258
6277
|
return {
|
|
6259
6278
|
reason,
|
|
6260
6279
|
commit: async () => {
|
|
6261
6280
|
if (cursor === null) return;
|
|
6262
6281
|
try {
|
|
6263
|
-
await syncAck(
|
|
6282
|
+
await syncAck(claimedCfg, cursor);
|
|
6264
6283
|
} catch (err) {
|
|
6265
6284
|
log.warn(`stop ack failed (messages stay queued): ${String(err)}`);
|
|
6266
6285
|
}
|
|
6267
6286
|
}
|
|
6268
6287
|
};
|
|
6269
6288
|
} catch (err) {
|
|
6289
|
+
if (cfg !== null) await clearForegroundTurn(cfg, input.sessionId);
|
|
6270
6290
|
log.warn(`stop hook degraded to no-op: ${String(err)}`);
|
|
6271
6291
|
return none;
|
|
6272
6292
|
}
|
|
6273
6293
|
}
|
|
6294
|
+
async function sessionEnd(ctx, input) {
|
|
6295
|
+
try {
|
|
6296
|
+
if (hooksDisabled()) return;
|
|
6297
|
+
const identity = resolveIdentity(ctx.home);
|
|
6298
|
+
if (identity === null) return;
|
|
6299
|
+
const cfg = { apiKey: identity.apiKey, apiBase: identity.apiBase };
|
|
6300
|
+
await clearForegroundTurn(cfg, input.sessionId);
|
|
6301
|
+
} catch (err) {
|
|
6302
|
+
log.warn(`session-end hook degraded to no-op: ${String(err)}`);
|
|
6303
|
+
}
|
|
6304
|
+
}
|
|
6274
6305
|
async function readHookInput(stream = process.stdin) {
|
|
6275
6306
|
let raw = "";
|
|
6276
6307
|
if (!stream.isTTY) {
|
|
@@ -6336,6 +6367,14 @@ function createHookRunners(context, dialect) {
|
|
|
6336
6367
|
} catch (err) {
|
|
6337
6368
|
log.warn(`stop hook degraded to no-op: ${String(err)}`);
|
|
6338
6369
|
}
|
|
6370
|
+
},
|
|
6371
|
+
async runSessionEnd() {
|
|
6372
|
+
try {
|
|
6373
|
+
const input = await readHookInput();
|
|
6374
|
+
await sessionEnd(context(), input);
|
|
6375
|
+
} catch (err) {
|
|
6376
|
+
log.warn(`session-end hook degraded to no-op: ${String(err)}`);
|
|
6377
|
+
}
|
|
6339
6378
|
}
|
|
6340
6379
|
};
|
|
6341
6380
|
}
|
|
@@ -7383,7 +7422,7 @@ import * as path6 from "path";
|
|
|
7383
7422
|
import { spawn as spawn2, spawnSync as spawnSync2 } from "child_process";
|
|
7384
7423
|
|
|
7385
7424
|
// src/version.ts
|
|
7386
|
-
var VERSION3 = "0.0.
|
|
7425
|
+
var VERSION3 = "0.0.171141";
|
|
7387
7426
|
|
|
7388
7427
|
// src/adapter.ts
|
|
7389
7428
|
var MAX_EVENT_TAIL_CHARS = 1024 * 1024;
|
|
@@ -7423,7 +7462,7 @@ function writeManual() {
|
|
|
7423
7462
|
renderManual({
|
|
7424
7463
|
...hostCopy(),
|
|
7425
7464
|
peerLabel: "Claude Code",
|
|
7426
|
-
peerInvoke: "
|
|
7465
|
+
peerInvoke: "npx -y @agentchatme/claude-code"
|
|
7427
7466
|
})
|
|
7428
7467
|
);
|
|
7429
7468
|
return true;
|
|
@@ -7434,6 +7473,9 @@ function writeManual() {
|
|
|
7434
7473
|
function shippedDaemonPath() {
|
|
7435
7474
|
return path7.join(path7.dirname(fileURLToPath(import.meta.url)), "daemon-main.js");
|
|
7436
7475
|
}
|
|
7476
|
+
function shippedBundlePath() {
|
|
7477
|
+
return fileURLToPath(import.meta.url);
|
|
7478
|
+
}
|
|
7437
7479
|
function stableDaemonPath() {
|
|
7438
7480
|
return path7.join(identityHome(), DAEMON_REL);
|
|
7439
7481
|
}
|
|
@@ -7448,15 +7490,6 @@ function copyDaemonBundle() {
|
|
|
7448
7490
|
else fs6.chmodSync(dest, 493);
|
|
7449
7491
|
return dest;
|
|
7450
7492
|
}
|
|
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
7493
|
function renderCodexAgents(handle) {
|
|
7461
7494
|
return [
|
|
7462
7495
|
ANCHOR_START,
|
|
@@ -7539,21 +7572,47 @@ function ourHookGroups(bundle) {
|
|
|
7539
7572
|
hooks: [{ type: "command", command: `node "${bundle}" hook ${sub}`, timeout }]
|
|
7540
7573
|
});
|
|
7541
7574
|
return {
|
|
7542
|
-
SessionStart: [{ matcher: "startup|resume|clear", ...cmd("session-start",
|
|
7543
|
-
UserPromptSubmit: [cmd("user-prompt",
|
|
7544
|
-
Stop: [cmd("stop",
|
|
7575
|
+
SessionStart: [{ matcher: "startup|resume|clear", ...cmd("session-start", 20) }],
|
|
7576
|
+
UserPromptSubmit: [cmd("user-prompt", 12)],
|
|
7577
|
+
Stop: [cmd("stop", 25)],
|
|
7578
|
+
SessionEnd: [cmd("session-end", 10)]
|
|
7545
7579
|
};
|
|
7546
7580
|
}
|
|
7547
|
-
function
|
|
7548
|
-
|
|
7549
|
-
|
|
7581
|
+
function hooksContainCurrent(doc, bundle) {
|
|
7582
|
+
return Object.entries(ourHookGroups(bundle)).every(([event, expectedGroups]) => {
|
|
7583
|
+
const actualGroups = doc.hooks?.[event];
|
|
7584
|
+
return Array.isArray(actualGroups) && expectedGroups.every(
|
|
7585
|
+
(expected) => actualGroups.some(
|
|
7586
|
+
(actual) => actual.matcher === expected.matcher && expected.hooks.every(
|
|
7587
|
+
(expectedLeaf) => actual.hooks.some(
|
|
7588
|
+
(actualLeaf) => actualLeaf.type === expectedLeaf.type && actualLeaf.command === expectedLeaf.command && actualLeaf.timeout === expectedLeaf.timeout
|
|
7589
|
+
)
|
|
7590
|
+
)
|
|
7591
|
+
)
|
|
7592
|
+
);
|
|
7593
|
+
});
|
|
7594
|
+
}
|
|
7595
|
+
function withoutOurLeaves(groups) {
|
|
7596
|
+
const kept = [];
|
|
7597
|
+
for (const group of groups) {
|
|
7598
|
+
if (!Array.isArray(group?.hooks)) {
|
|
7599
|
+
kept.push(group);
|
|
7600
|
+
continue;
|
|
7601
|
+
}
|
|
7602
|
+
const hooks = group.hooks.filter(
|
|
7603
|
+
(hook) => !(typeof hook?.command === "string" && hook.command.includes(BUNDLE_REL))
|
|
7604
|
+
);
|
|
7605
|
+
if (hooks.length === 0) continue;
|
|
7606
|
+
kept.push(hooks.length === group.hooks.length ? group : { ...group, hooks });
|
|
7607
|
+
}
|
|
7608
|
+
return kept;
|
|
7550
7609
|
}
|
|
7551
7610
|
function mergeHooks(existing, bundle) {
|
|
7552
7611
|
const doc = existing && typeof existing === "object" ? existing : {};
|
|
7553
7612
|
const hooks = doc.hooks && typeof doc.hooks === "object" ? doc.hooks : {};
|
|
7554
7613
|
for (const [event, groups] of Object.entries(ourHookGroups(bundle))) {
|
|
7555
7614
|
const prior = Array.isArray(hooks[event]) ? hooks[event] : [];
|
|
7556
|
-
hooks[event] = [...prior
|
|
7615
|
+
hooks[event] = [...withoutOurLeaves(prior), ...groups];
|
|
7557
7616
|
}
|
|
7558
7617
|
doc.hooks = hooks;
|
|
7559
7618
|
return doc;
|
|
@@ -7563,7 +7622,7 @@ function unmergeHooks(existing) {
|
|
|
7563
7622
|
const hooks = existing.hooks;
|
|
7564
7623
|
let anyLeft = false;
|
|
7565
7624
|
for (const event of Object.keys(hooks)) {
|
|
7566
|
-
const kept = (Array.isArray(hooks[event]) ? hooks[event] : [])
|
|
7625
|
+
const kept = withoutOurLeaves(Array.isArray(hooks[event]) ? hooks[event] : []);
|
|
7567
7626
|
if (kept.length > 0) {
|
|
7568
7627
|
hooks[event] = kept;
|
|
7569
7628
|
anyLeft = true;
|
|
@@ -7578,6 +7637,15 @@ function unmergeHooks(existing) {
|
|
|
7578
7637
|
}
|
|
7579
7638
|
return existing;
|
|
7580
7639
|
}
|
|
7640
|
+
function isCodexWired() {
|
|
7641
|
+
try {
|
|
7642
|
+
const config = fs6.readFileSync(codexConfigPath(), "utf-8");
|
|
7643
|
+
const hooks = JSON.parse(fs6.readFileSync(codexHooksPath(), "utf-8"));
|
|
7644
|
+
return config.includes(mcpBlock()) && hooksContainCurrent(hooks, stableBundlePath()) && fs6.existsSync(stableBundlePath()) && fs6.existsSync(manualPath());
|
|
7645
|
+
} catch {
|
|
7646
|
+
return false;
|
|
7647
|
+
}
|
|
7648
|
+
}
|
|
7581
7649
|
function copyBundle(bundleSrc) {
|
|
7582
7650
|
const dest = stableBundlePath();
|
|
7583
7651
|
fs6.mkdirSync(path7.dirname(dest), { recursive: true });
|
|
@@ -7587,44 +7655,48 @@ function copyBundle(bundleSrc) {
|
|
|
7587
7655
|
}
|
|
7588
7656
|
return dest;
|
|
7589
7657
|
}
|
|
7590
|
-
function installCodex(
|
|
7658
|
+
function installCodex(handle) {
|
|
7591
7659
|
const actions = [];
|
|
7592
7660
|
const warnings = [];
|
|
7593
7661
|
fs6.mkdirSync(codexHome(), { recursive: true });
|
|
7594
|
-
let bundle;
|
|
7595
|
-
try {
|
|
7596
|
-
bundle = copyBundle(bundleSrc);
|
|
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
|
-
);
|
|
7603
|
-
}
|
|
7604
7662
|
const cfgPath = codexConfigPath();
|
|
7605
7663
|
const existingCfg = fs6.existsSync(cfgPath) ? fs6.readFileSync(cfgPath, "utf-8") : "";
|
|
7606
7664
|
if (hasUnfencedAgentchatServer(existingCfg)) {
|
|
7607
7665
|
warnings.push(
|
|
7608
|
-
`${cfgPath} already defines [mcp_servers.agentchat] outside our block \u2014 left
|
|
7666
|
+
`${cfgPath} already defines [mcp_servers.agentchat] outside our block \u2014 left everything untouched; remove it and re-run if it isn't yours`
|
|
7609
7667
|
);
|
|
7610
|
-
|
|
7611
|
-
atomicText(cfgPath, upsertTomlBlock(existingCfg, mcpBlock()));
|
|
7612
|
-
actions.push(`config.toml \u2190 [mcp_servers.agentchat]`);
|
|
7668
|
+
return { actions, warnings, complete: false };
|
|
7613
7669
|
}
|
|
7614
7670
|
const hooksPath = codexHooksPath();
|
|
7615
7671
|
let existingHooks = null;
|
|
7616
7672
|
if (fs6.existsSync(hooksPath)) {
|
|
7617
7673
|
try {
|
|
7618
|
-
|
|
7674
|
+
const parsed = JSON.parse(fs6.readFileSync(hooksPath, "utf-8"));
|
|
7675
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
7676
|
+
warnings.push(`${hooksPath} must contain a JSON object \u2014 left everything untouched`);
|
|
7677
|
+
return { actions, warnings, complete: false };
|
|
7678
|
+
}
|
|
7679
|
+
existingHooks = parsed;
|
|
7619
7680
|
} catch {
|
|
7620
|
-
warnings.push(`${hooksPath}
|
|
7681
|
+
warnings.push(`${hooksPath} is not valid JSON \u2014 left everything untouched`);
|
|
7682
|
+
return { actions, warnings, complete: false };
|
|
7621
7683
|
}
|
|
7622
7684
|
}
|
|
7623
|
-
|
|
7624
|
-
|
|
7625
|
-
|
|
7626
|
-
actions.push(
|
|
7685
|
+
let bundle;
|
|
7686
|
+
try {
|
|
7687
|
+
bundle = copyBundle(shippedBundlePath());
|
|
7688
|
+
actions.push(`bundle \u2192 ${bundle}`);
|
|
7689
|
+
} catch (err) {
|
|
7690
|
+
warnings.push(
|
|
7691
|
+
`could not copy the CLI bundle (${String(err)}); configuration was left untouched`
|
|
7692
|
+
);
|
|
7693
|
+
return { actions, warnings, complete: false };
|
|
7627
7694
|
}
|
|
7695
|
+
atomicText(cfgPath, upsertTomlBlock(existingCfg, mcpBlock()));
|
|
7696
|
+
actions.push(`config.toml \u2190 [mcp_servers.agentchat]`);
|
|
7697
|
+
const merged = mergeHooks(existingHooks, bundle);
|
|
7698
|
+
atomicText(hooksPath, JSON.stringify(merged, null, 2) + "\n");
|
|
7699
|
+
actions.push("hooks.json \u2190 SessionStart + UserPromptSubmit + Stop + SessionEnd");
|
|
7628
7700
|
if (writeManual()) actions.push("SKILL.md \u2190 the manual");
|
|
7629
7701
|
else warnings.push("could not write the AgentChat manual \u2014 the agent will have only the anchor");
|
|
7630
7702
|
if (handle) {
|
|
@@ -7644,7 +7716,7 @@ function installCodex(bundleSrc, handle) {
|
|
|
7644
7716
|
}
|
|
7645
7717
|
}
|
|
7646
7718
|
log.debug(`codex install: ${actions.join("; ")}`);
|
|
7647
|
-
return { actions, warnings };
|
|
7719
|
+
return { actions, warnings, complete: isCodexWired() };
|
|
7648
7720
|
}
|
|
7649
7721
|
function removeCodexWiring(opts = {}) {
|
|
7650
7722
|
const removed = [];
|
|
@@ -7786,17 +7858,10 @@ function runtimeChecks() {
|
|
|
7786
7858
|
];
|
|
7787
7859
|
}
|
|
7788
7860
|
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
|
-
};
|
|
7861
|
+
const current = () => isCodexWired();
|
|
7797
7862
|
if (fix && !current()) {
|
|
7798
7863
|
try {
|
|
7799
|
-
installCodex(
|
|
7864
|
+
installCodex(readCredentials(identityHome())?.handle ?? null);
|
|
7800
7865
|
} catch (err) {
|
|
7801
7866
|
return { name: "wiring", verdict: "FAIL", detail: `repair failed: ${String(err)}` };
|
|
7802
7867
|
}
|
|
@@ -7857,7 +7922,7 @@ function hookTrustCheck() {
|
|
|
7857
7922
|
cfg = fs8.readFileSync(codexConfigPath(), "utf-8");
|
|
7858
7923
|
} catch {
|
|
7859
7924
|
}
|
|
7860
|
-
const events = ["session_start", "user_prompt_submit", "stop"];
|
|
7925
|
+
const events = ["session_start", "user_prompt_submit", "stop", "session_end"];
|
|
7861
7926
|
const missing = events.filter((e) => !cfg.includes(`${hooksPath}:${e}`));
|
|
7862
7927
|
if (missing.length === 0) {
|
|
7863
7928
|
return { name: "hook-trust", verdict: "PASS", detail: "Codex has trusted the AgentChat hooks" };
|
|
@@ -7865,7 +7930,7 @@ function hookTrustCheck() {
|
|
|
7865
7930
|
return {
|
|
7866
7931
|
name: "hook-trust",
|
|
7867
7932
|
verdict: "WARN",
|
|
7868
|
-
detail: `${missing.length}/
|
|
7933
|
+
detail: `${missing.length}/4 hooks not trusted by Codex yet \u2014 run \`/hooks\` in Codex and approve them. Until then there is no inbox digest, no mid-task pickup and no delivery acks.`
|
|
7869
7934
|
};
|
|
7870
7935
|
}
|
|
7871
7936
|
var commands = createIdentityCommands(profile);
|
|
@@ -7929,6 +7994,9 @@ async function runStop() {
|
|
|
7929
7994
|
ensureAlwaysOnQuietly();
|
|
7930
7995
|
await runners.runStop();
|
|
7931
7996
|
}
|
|
7997
|
+
async function runSessionEnd() {
|
|
7998
|
+
await runners.runSessionEnd();
|
|
7999
|
+
}
|
|
7932
8000
|
|
|
7933
8001
|
// src/index.ts
|
|
7934
8002
|
var USAGE = `agentchat-codex ${VERSION3} \u2014 AgentChat for Codex
|
|
@@ -7950,8 +8018,7 @@ Usage:
|
|
|
7950
8018
|
This command only ever acts on your ${LABEL} agent. If you also run another
|
|
7951
8019
|
coding agent here, it is a SEPARATE AgentChat agent with its own @handle \u2014 the
|
|
7952
8020
|
two of you can DM each other \u2014 and it has its own front door:
|
|
7953
|
-
Claude Code:
|
|
7954
|
-
/plugin install agentchat@agentchatme
|
|
8021
|
+
Claude Code: npx -y @agentchatme/claude-code
|
|
7955
8022
|
|
|
7956
8023
|
AGENTCHAT_API_KEY / AGENTCHAT_API_BASE override the stored identity.
|
|
7957
8024
|
(hook subcommands are wired by the installer \u2014 you don't run them.)
|
|
@@ -7997,14 +8064,29 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
7997
8064
|
const home = identityHome();
|
|
7998
8065
|
const handle = readCredentials(home)?.handle ?? null;
|
|
7999
8066
|
try {
|
|
8000
|
-
const
|
|
8001
|
-
const
|
|
8002
|
-
|
|
8003
|
-
|
|
8004
|
-
|
|
8067
|
+
const result = installCodex(handle);
|
|
8068
|
+
const { actions, warnings } = result;
|
|
8069
|
+
let failed = !result.complete;
|
|
8070
|
+
if (result.complete) {
|
|
8071
|
+
const alwaysOn = ensureAlwaysOn();
|
|
8072
|
+
if (alwaysOn.ok) actions.push("always-on service registered");
|
|
8073
|
+
else if (alwaysOn.detail === "switched off by the user") {
|
|
8074
|
+
actions.push("always-on remains off (user choice)");
|
|
8075
|
+
} else {
|
|
8076
|
+
failed = true;
|
|
8077
|
+
warnings.push(`always-on could not be registered (${alwaysOn.detail}) \u2014 \`${invocation()} daemon install\` retries it`);
|
|
8078
|
+
}
|
|
8079
|
+
} else {
|
|
8080
|
+
warnings.push(
|
|
8081
|
+
`direct wiring is incomplete \u2014 resolve the warning above and re-run \`${invocation()}\``
|
|
8082
|
+
);
|
|
8005
8083
|
}
|
|
8006
|
-
|
|
8084
|
+
if (warnings.length > 0) failed = true;
|
|
8085
|
+
console.log(
|
|
8086
|
+
result.complete ? failed ? `${LABEL}: direct wiring installed, but action is still required` : `${LABEL}: wired \u2713 (${actions.join(", ") || "no changes"})` : `${LABEL}: wiring incomplete`
|
|
8087
|
+
);
|
|
8007
8088
|
for (const w of warnings) console.log(` \u26A0 ${w}`);
|
|
8089
|
+
if (failed) return 1;
|
|
8008
8090
|
} catch (err) {
|
|
8009
8091
|
console.error(`${LABEL}: wiring failed \u2014 ${String(err)}`);
|
|
8010
8092
|
return 1;
|
|
@@ -8015,17 +8097,21 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
8015
8097
|
"",
|
|
8016
8098
|
`Last step \u2014 give ${LABEL} its @handle:`,
|
|
8017
8099
|
` 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."
|
|
8100
|
+
` ${invocation()} register --email <email> --handle <handle>`
|
|
8023
8101
|
].join("\n")
|
|
8024
8102
|
);
|
|
8025
8103
|
} else {
|
|
8026
8104
|
console.log(`
|
|
8027
8105
|
Signed in as @${handle}.`);
|
|
8028
8106
|
}
|
|
8107
|
+
console.log(
|
|
8108
|
+
[
|
|
8109
|
+
"",
|
|
8110
|
+
"Required for in-session delivery: open `/hooks` in Codex and trust the",
|
|
8111
|
+
"four AgentChat entries. Codex skips SessionStart, UserPromptSubmit, Stop,",
|
|
8112
|
+
"and SessionEnd until the host records that approval."
|
|
8113
|
+
].join("\n")
|
|
8114
|
+
);
|
|
8029
8115
|
return 0;
|
|
8030
8116
|
}
|
|
8031
8117
|
case "register":
|
|
@@ -8072,7 +8158,11 @@ Signed in as @${handle}.`);
|
|
|
8072
8158
|
await runStop();
|
|
8073
8159
|
return 0;
|
|
8074
8160
|
}
|
|
8075
|
-
|
|
8161
|
+
if (subcommand === "session-end") {
|
|
8162
|
+
await runSessionEnd();
|
|
8163
|
+
return 0;
|
|
8164
|
+
}
|
|
8165
|
+
console.error("Usage: hook <session-start|user-prompt|stop|session-end>");
|
|
8076
8166
|
return 1;
|
|
8077
8167
|
}
|
|
8078
8168
|
default:
|