@agentchatme/codex 0.0.17113 → 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 +18 -5
- package/dist/daemon-main.js +390 -149
- package/dist/daemon-main.js.map +1 -1
- package/dist/index.js +294 -150
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
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
|
|
@@ -44,6 +44,25 @@ var CODING_AGENTS_CLIENT_HEADERS = {
|
|
|
44
44
|
"X-AgentChat-Client": CODING_AGENTS_CLIENT_IDENTITY.name,
|
|
45
45
|
"X-AgentChat-Client-Version": CODING_AGENTS_CLIENT_IDENTITY.version
|
|
46
46
|
};
|
|
47
|
+
var SEC = 1e3;
|
|
48
|
+
var MIN = 60 * SEC;
|
|
49
|
+
var HOUR = 60 * MIN;
|
|
50
|
+
var DAY = 24 * HOUR;
|
|
51
|
+
function relativeAge(ms) {
|
|
52
|
+
if (ms < 45 * SEC) return "just now";
|
|
53
|
+
if (ms < 90 * SEC) return "1 minute ago";
|
|
54
|
+
if (ms < 45 * MIN) return `${Math.round(ms / MIN)} minutes ago`;
|
|
55
|
+
if (ms < 90 * MIN) return "1 hour ago";
|
|
56
|
+
if (ms < 22 * HOUR) return `${Math.round(ms / HOUR)} hours ago`;
|
|
57
|
+
if (ms < 36 * HOUR) return "1 day ago";
|
|
58
|
+
return `${Math.round(ms / DAY)} days ago`;
|
|
59
|
+
}
|
|
60
|
+
function relativeWhen(createdAt, now2 = Date.now()) {
|
|
61
|
+
if (!createdAt) return "";
|
|
62
|
+
const t = Date.parse(createdAt);
|
|
63
|
+
if (Number.isNaN(t)) return "";
|
|
64
|
+
return relativeAge(Math.max(0, now2 - t));
|
|
65
|
+
}
|
|
47
66
|
function atomicWriteFile(filePath, data, mode) {
|
|
48
67
|
const dir = path2.dirname(filePath);
|
|
49
68
|
fs2.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
@@ -4204,8 +4223,11 @@ var SyncRowSchema = external_exports.object({
|
|
|
4204
4223
|
// fallback against a future server-side rename).
|
|
4205
4224
|
sender: external_exports.string().optional(),
|
|
4206
4225
|
sender_handle: external_exports.string().optional(),
|
|
4226
|
+
seq: external_exports.number().optional(),
|
|
4207
4227
|
type: external_exports.string().optional(),
|
|
4208
4228
|
content: external_exports.record(external_exports.unknown()).optional(),
|
|
4229
|
+
metadata: external_exports.record(external_exports.unknown()).optional(),
|
|
4230
|
+
status: external_exports.string().optional(),
|
|
4209
4231
|
created_at: external_exports.string().optional()
|
|
4210
4232
|
}).passthrough();
|
|
4211
4233
|
function contextOf(row) {
|
|
@@ -4287,11 +4309,20 @@ async function getMeLite(cfg) {
|
|
|
4287
4309
|
return null;
|
|
4288
4310
|
}
|
|
4289
4311
|
}
|
|
4290
|
-
async function
|
|
4312
|
+
async function markForegroundTurn(cfg, sessionId, ttlSeconds) {
|
|
4291
4313
|
try {
|
|
4292
|
-
await request(cfg, "PUT", "/v1/reply/active",
|
|
4314
|
+
await request(cfg, "PUT", "/v1/reply/active", {
|
|
4315
|
+
session_id: sessionId,
|
|
4316
|
+
ttl_seconds: ttlSeconds
|
|
4317
|
+
});
|
|
4293
4318
|
} catch (err) {
|
|
4294
|
-
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 {
|
|
4295
4326
|
}
|
|
4296
4327
|
}
|
|
4297
4328
|
async function claimReply(cfg, messageId, holder) {
|
|
@@ -4304,6 +4335,28 @@ async function claimReply(cfg, messageId, holder) {
|
|
|
4304
4335
|
return true;
|
|
4305
4336
|
}
|
|
4306
4337
|
}
|
|
4338
|
+
async function claimReplyBatch(cfg, messageIds, holder) {
|
|
4339
|
+
if (messageIds.length === 0) return 0;
|
|
4340
|
+
try {
|
|
4341
|
+
const data = await request(cfg, "POST", "/v1/reply/claim-batch", {
|
|
4342
|
+
message_ids: messageIds,
|
|
4343
|
+
holder
|
|
4344
|
+
});
|
|
4345
|
+
const parsed = external_exports.object({ claimed_count: external_exports.number().int().min(0).max(messageIds.length) }).passthrough().safeParse(data);
|
|
4346
|
+
return parsed.success ? parsed.data.claimed_count : messageIds.length;
|
|
4347
|
+
} catch (err) {
|
|
4348
|
+
if (!/AgentChat API (404|405)\b/.test(String(err))) {
|
|
4349
|
+
log.warn(`reply-batch-claim failed (surfacing all): ${String(err)}`);
|
|
4350
|
+
return messageIds.length;
|
|
4351
|
+
}
|
|
4352
|
+
}
|
|
4353
|
+
let claimed = 0;
|
|
4354
|
+
for (const messageId of messageIds) {
|
|
4355
|
+
if (!await claimReply(cfg, messageId, holder)) break;
|
|
4356
|
+
claimed += 1;
|
|
4357
|
+
}
|
|
4358
|
+
return claimed;
|
|
4359
|
+
}
|
|
4307
4360
|
function lastDeliveryId(rows) {
|
|
4308
4361
|
for (let i = rows.length - 1; i >= 0; i--) {
|
|
4309
4362
|
const id = rows[i]?.delivery_id;
|
|
@@ -4390,12 +4443,12 @@ function alwaysOnHealth(home) {
|
|
|
4390
4443
|
return { wanted: state !== "off", healthy: state !== "down" };
|
|
4391
4444
|
}
|
|
4392
4445
|
|
|
4393
|
-
// 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
|
|
4394
4447
|
import * as fs from "fs";
|
|
4395
4448
|
import * as path from "path";
|
|
4396
4449
|
import * as readline from "readline";
|
|
4397
4450
|
|
|
4398
|
-
// node_modules/.pnpm/agentchatme@1.0.
|
|
4451
|
+
// node_modules/.pnpm/agentchatme@1.0.2212_ws@8.21.1/node_modules/agentchatme/dist/index.js
|
|
4399
4452
|
var ErrorCode = {
|
|
4400
4453
|
AGENT_NOT_FOUND: "AGENT_NOT_FOUND",
|
|
4401
4454
|
AGENT_SUSPENDED: "AGENT_SUSPENDED",
|
|
@@ -4601,7 +4654,7 @@ function createAgentChatError(body, status, headers) {
|
|
|
4601
4654
|
return new AgentChatError(body, status, requestId);
|
|
4602
4655
|
}
|
|
4603
4656
|
}
|
|
4604
|
-
var VERSION2 = "1.0.
|
|
4657
|
+
var VERSION2 = "1.0.2212";
|
|
4605
4658
|
function detectRuntime() {
|
|
4606
4659
|
const g = globalThis;
|
|
4607
4660
|
if (typeof g.Bun?.version === "string") return `bun/${g.Bun.version}`;
|
|
@@ -4655,8 +4708,8 @@ var HttpTransport = class {
|
|
|
4655
4708
|
}
|
|
4656
4709
|
this.fetchFn = f.bind(globalThis);
|
|
4657
4710
|
}
|
|
4658
|
-
async request(method,
|
|
4659
|
-
const url = `${this.baseUrl}${
|
|
4711
|
+
async request(method, path9, opts = {}) {
|
|
4712
|
+
const url = `${this.baseUrl}${path9}`;
|
|
4660
4713
|
const policy = resolveRetryPolicy(opts.retry, this.retry);
|
|
4661
4714
|
const canRetry = isRetryEligible(method, opts.idempotencyKey, opts.retry);
|
|
4662
4715
|
const maxAttempts = canRetry ? policy.maxRetries + 1 : 1;
|
|
@@ -4986,31 +5039,31 @@ var AgentChatClient = class _AgentChatClient {
|
|
|
4986
5039
|
this.onBacklogWarning = options.onBacklogWarning;
|
|
4987
5040
|
}
|
|
4988
5041
|
// ─── Internal request helpers ─────────────────────────────────────────────
|
|
4989
|
-
async get(
|
|
4990
|
-
const res = await this.http.request("GET",
|
|
5042
|
+
async get(path9, opts) {
|
|
5043
|
+
const res = await this.http.request("GET", path9, this.toRequestOpts(opts));
|
|
4991
5044
|
return res.data;
|
|
4992
5045
|
}
|
|
4993
|
-
async del(
|
|
4994
|
-
const res = await this.http.request("DELETE",
|
|
5046
|
+
async del(path9, opts) {
|
|
5047
|
+
const res = await this.http.request("DELETE", path9, this.toRequestOpts(opts));
|
|
4995
5048
|
return res.data;
|
|
4996
5049
|
}
|
|
4997
|
-
async post(
|
|
4998
|
-
const res = await this.http.request("POST",
|
|
5050
|
+
async post(path9, body, opts) {
|
|
5051
|
+
const res = await this.http.request("POST", path9, {
|
|
4999
5052
|
...this.toRequestOpts(opts),
|
|
5000
5053
|
body
|
|
5001
5054
|
});
|
|
5002
5055
|
return res.data;
|
|
5003
5056
|
}
|
|
5004
|
-
async patch(
|
|
5005
|
-
const res = await this.http.request("PATCH",
|
|
5057
|
+
async patch(path9, body, opts) {
|
|
5058
|
+
const res = await this.http.request("PATCH", path9, {
|
|
5006
5059
|
...this.toRequestOpts(opts),
|
|
5007
5060
|
body
|
|
5008
5061
|
});
|
|
5009
5062
|
return res.data;
|
|
5010
5063
|
}
|
|
5011
|
-
async put(
|
|
5064
|
+
async put(path9, body, opts) {
|
|
5012
5065
|
const headers = opts?.contentType ? { "Content-Type": opts.contentType } : void 0;
|
|
5013
|
-
const res = await this.http.request("PUT",
|
|
5066
|
+
const res = await this.http.request("PUT", path9, {
|
|
5014
5067
|
...this.toRequestOpts(opts),
|
|
5015
5068
|
body,
|
|
5016
5069
|
rawBody: opts?.rawBody,
|
|
@@ -5216,6 +5269,7 @@ var AgentChatClient = class _AgentChatClient {
|
|
|
5216
5269
|
* most one:
|
|
5217
5270
|
* - `beforeSeq` — backwards scrollback (rows with seq < N, newest first)
|
|
5218
5271
|
* - `afterSeq` — forwards gap-fill (rows with seq > N, oldest first)
|
|
5272
|
+
* - `aroundMessageId` — backwards window ending at that exact message
|
|
5219
5273
|
*
|
|
5220
5274
|
* `afterSeq` is the path `RealtimeClient` uses for in-order recovery
|
|
5221
5275
|
* when a per-conversation seq gap is detected. Application code usually
|
|
@@ -5226,6 +5280,9 @@ var AgentChatClient = class _AgentChatClient {
|
|
|
5226
5280
|
params.set("limit", String(options?.limit ?? 50));
|
|
5227
5281
|
if (options?.beforeSeq !== void 0) params.set("before_seq", String(options.beforeSeq));
|
|
5228
5282
|
if (options?.afterSeq !== void 0) params.set("after_seq", String(options.afterSeq));
|
|
5283
|
+
if (options?.aroundMessageId !== void 0) {
|
|
5284
|
+
params.set("around_message_id", options.aroundMessageId);
|
|
5285
|
+
}
|
|
5229
5286
|
return this.get(
|
|
5230
5287
|
`/v1/messages/${encodeURIComponent(conversationId)}?${params.toString()}`,
|
|
5231
5288
|
options
|
|
@@ -5243,10 +5300,10 @@ var AgentChatClient = class _AgentChatClient {
|
|
|
5243
5300
|
* Idempotent — hiding an already-hidden message is a success no-op.
|
|
5244
5301
|
*/
|
|
5245
5302
|
/**
|
|
5246
|
-
* Mark
|
|
5247
|
-
*
|
|
5248
|
-
*
|
|
5249
|
-
* fanned out to the sender via WebSocket + webhook.
|
|
5303
|
+
* Mark one message as read for the caller. This updates that message's
|
|
5304
|
+
* recipient envelope only; it does not implicitly mark earlier messages,
|
|
5305
|
+
* so a conversation can legitimately contain unread gaps. A `message.read`
|
|
5306
|
+
* event is fanned out to the sender via WebSocket + webhook.
|
|
5250
5307
|
*
|
|
5251
5308
|
* Realtime clients also have a WebSocket shortcut (`message.read_ack`
|
|
5252
5309
|
* frame) that bypasses this HTTP call. The REST method exists for
|
|
@@ -5283,6 +5340,17 @@ var AgentChatClient = class _AgentChatClient {
|
|
|
5283
5340
|
opts
|
|
5284
5341
|
);
|
|
5285
5342
|
}
|
|
5343
|
+
/**
|
|
5344
|
+
* Fetch compact server-authored room metadata: group summary or DM
|
|
5345
|
+
* counterparty, contact memory, and the exact unread seq boundary.
|
|
5346
|
+
* Message bodies stay on `getMessages`.
|
|
5347
|
+
*/
|
|
5348
|
+
getConversationContext(conversationId, opts) {
|
|
5349
|
+
return this.get(
|
|
5350
|
+
`/v1/conversations/${encodeURIComponent(conversationId)}/context`,
|
|
5351
|
+
opts
|
|
5352
|
+
);
|
|
5353
|
+
}
|
|
5286
5354
|
/**
|
|
5287
5355
|
* Hide a conversation from the caller's inbox (soft-delete, caller-scoped).
|
|
5288
5356
|
* The other side's view is untouched — by design, matching the
|
|
@@ -5296,8 +5364,15 @@ var AgentChatClient = class _AgentChatClient {
|
|
|
5296
5364
|
opts
|
|
5297
5365
|
);
|
|
5298
5366
|
}
|
|
5299
|
-
listConversations(
|
|
5300
|
-
|
|
5367
|
+
listConversations(options) {
|
|
5368
|
+
const params = new URLSearchParams();
|
|
5369
|
+
if (options?.limit !== void 0) params.set("limit", String(options.limit));
|
|
5370
|
+
if (options?.offset !== void 0) params.set("offset", String(options.offset));
|
|
5371
|
+
const qs = params.toString();
|
|
5372
|
+
return this.get(
|
|
5373
|
+
`/v1/conversations${qs ? `?${qs}` : ""}`,
|
|
5374
|
+
options
|
|
5375
|
+
);
|
|
5301
5376
|
}
|
|
5302
5377
|
// ─── Groups ───────────────────────────────────────────────────────────────
|
|
5303
5378
|
/**
|
|
@@ -5703,13 +5778,13 @@ var AgentChatClient = class _AgentChatClient {
|
|
|
5703
5778
|
);
|
|
5704
5779
|
}
|
|
5705
5780
|
};
|
|
5706
|
-
var
|
|
5707
|
-
var
|
|
5708
|
-
var
|
|
5709
|
-
var
|
|
5781
|
+
var SEC2 = 1e3;
|
|
5782
|
+
var MIN2 = 60 * SEC2;
|
|
5783
|
+
var HOUR2 = 60 * MIN2;
|
|
5784
|
+
var DAY2 = 24 * HOUR2;
|
|
5710
5785
|
var MAX_ATTACHMENT_SIZE = 25 * 1024 * 1024;
|
|
5711
5786
|
|
|
5712
|
-
// 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
|
|
5713
5788
|
import * as fs22 from "fs";
|
|
5714
5789
|
import * as os from "os";
|
|
5715
5790
|
import * as path22 from "path";
|
|
@@ -5906,25 +5981,6 @@ function stripAllBlocks(existing, start, end) {
|
|
|
5906
5981
|
}
|
|
5907
5982
|
return text;
|
|
5908
5983
|
}
|
|
5909
|
-
var SEC2 = 1e3;
|
|
5910
|
-
var MIN2 = 60 * SEC2;
|
|
5911
|
-
var HOUR2 = 60 * MIN2;
|
|
5912
|
-
var DAY2 = 24 * HOUR2;
|
|
5913
|
-
function relativeAge(ms) {
|
|
5914
|
-
if (ms < 45 * SEC2) return "just now";
|
|
5915
|
-
if (ms < 90 * SEC2) return "1 minute ago";
|
|
5916
|
-
if (ms < 45 * MIN2) return `${Math.round(ms / MIN2)} minutes ago`;
|
|
5917
|
-
if (ms < 90 * MIN2) return "1 hour ago";
|
|
5918
|
-
if (ms < 22 * HOUR2) return `${Math.round(ms / HOUR2)} hours ago`;
|
|
5919
|
-
if (ms < 36 * HOUR2) return "1 day ago";
|
|
5920
|
-
return `${Math.round(ms / DAY2)} days ago`;
|
|
5921
|
-
}
|
|
5922
|
-
function relativeWhen(createdAt, now2 = Date.now()) {
|
|
5923
|
-
if (!createdAt) return "";
|
|
5924
|
-
const t = Date.parse(createdAt);
|
|
5925
|
-
if (Number.isNaN(t)) return "";
|
|
5926
|
-
return relativeAge(Math.max(0, now2 - t));
|
|
5927
|
-
}
|
|
5928
5984
|
var SNIPPET_MAX = 140;
|
|
5929
5985
|
function snippetOf(row) {
|
|
5930
5986
|
const content = row.content ?? {};
|
|
@@ -5945,9 +6001,11 @@ function digestConversations(rows, selfHandle = null) {
|
|
|
5945
6001
|
existing.count += 1;
|
|
5946
6002
|
if (!existing.senders.includes(sender)) existing.senders.push(sender);
|
|
5947
6003
|
existing.latestSnippet = snippetOf(row);
|
|
6004
|
+
existing.latestMessageId = row.id;
|
|
5948
6005
|
existing.latestCreatedAt = row.created_at ?? existing.latestCreatedAt;
|
|
5949
6006
|
existing.groupName = ctx.groupName ?? existing.groupName;
|
|
5950
6007
|
existing.mentionsYou = existing.mentionsYou || mentionsSelf;
|
|
6008
|
+
if (mentionsSelf) existing.mentionedMessageIds.push(row.id);
|
|
5951
6009
|
} else {
|
|
5952
6010
|
byConversation.set(row.conversation_id, {
|
|
5953
6011
|
conversationId: row.conversation_id,
|
|
@@ -5955,9 +6013,11 @@ function digestConversations(rows, selfHandle = null) {
|
|
|
5955
6013
|
senders: [sender],
|
|
5956
6014
|
count: 1,
|
|
5957
6015
|
latestSnippet: snippetOf(row),
|
|
6016
|
+
latestMessageId: row.id,
|
|
5958
6017
|
latestCreatedAt: row.created_at,
|
|
5959
6018
|
groupName: ctx.groupName,
|
|
5960
|
-
mentionsYou: mentionsSelf
|
|
6019
|
+
mentionsYou: mentionsSelf,
|
|
6020
|
+
mentionedMessageIds: mentionsSelf ? [row.id] : []
|
|
5961
6021
|
});
|
|
5962
6022
|
}
|
|
5963
6023
|
}
|
|
@@ -5971,7 +6031,9 @@ function digestLines(digests) {
|
|
|
5971
6031
|
const age = relativeWhen(d.latestCreatedAt);
|
|
5972
6032
|
const recency = age ? `, latest ${age}` : "";
|
|
5973
6033
|
const mention = d.mentionsYou ? " \u2014 mentions you" : "";
|
|
5974
|
-
|
|
6034
|
+
const attentionIds = d.mentionedMessageIds.slice(-30);
|
|
6035
|
+
const attention = attentionIds.length > 0 ? `, attention_message_ids=${JSON.stringify(attentionIds)}${d.mentionedMessageIds.length > attentionIds.length ? ` (+${d.mentionedMessageIds.length - attentionIds.length} older mentions in history)` : ""}` : "";
|
|
6036
|
+
return `${i + 1}. ${who} (${count}, ${kind}${recency}${mention}), latest_message_id=${d.latestMessageId}${attention}, preview=${JSON.stringify(d.latestSnippet)}`;
|
|
5975
6037
|
});
|
|
5976
6038
|
}
|
|
5977
6039
|
function formatSessionStart(handle, rows) {
|
|
@@ -5986,7 +6048,7 @@ function formatSessionStart(handle, rows) {
|
|
|
5986
6048
|
"",
|
|
5987
6049
|
...digestLines(digests),
|
|
5988
6050
|
"",
|
|
5989
|
-
"Triage per your AgentChat skill: read a conversation with agentchat_get_conversation before replying; reply only where an open request is addressed to you; finished conversations get silence, not acknowledgments. Mention anything the user should know about."
|
|
6051
|
+
"Triage per your AgentChat skill: read a conversation with agentchat_get_conversation before replying, passing its latest_message_id as around_message_id and any listed attention_message_ids exactly; reply only where an open request is addressed to you; finished conversations get silence, not acknowledgments. Mention anything the user should know about."
|
|
5990
6052
|
].join("\n");
|
|
5991
6053
|
}
|
|
5992
6054
|
function formatStopPickup(handle, rows) {
|
|
@@ -6000,7 +6062,7 @@ function formatStopPickup(handle, rows) {
|
|
|
6000
6062
|
"",
|
|
6001
6063
|
...digestLines(digests),
|
|
6002
6064
|
"",
|
|
6003
|
-
"Handle these per your AgentChat skill,
|
|
6065
|
+
"Handle these per your AgentChat skill, opening each conversation with agentchat_get_conversation, its latest_message_id as around_message_id, and any listed attention_message_ids exactly. Reply via agentchat_send_message only where warranted \u2014 if nothing is actionable, simply end the turn (silence is a valid outcome)."
|
|
6004
6066
|
].join("\n");
|
|
6005
6067
|
}
|
|
6006
6068
|
function formatAlwaysOnDown(copy) {
|
|
@@ -6085,6 +6147,7 @@ function renderDeclinedBlock(copy) {
|
|
|
6085
6147
|
var SESSION_START_PEEK_LIMIT = 100;
|
|
6086
6148
|
var STOP_PEEK_LIMIT = 50;
|
|
6087
6149
|
var DEFAULT_MAX_CONTINUATIONS = 5;
|
|
6150
|
+
var FOREGROUND_TURN_TTL_SECONDS = 600;
|
|
6088
6151
|
function hooksDisabled() {
|
|
6089
6152
|
return process.env["AGENTCHAT_HOOKS_ENABLED"] === "0";
|
|
6090
6153
|
}
|
|
@@ -6113,12 +6176,12 @@ function ackableRows(rows) {
|
|
|
6113
6176
|
return usable;
|
|
6114
6177
|
}
|
|
6115
6178
|
async function claimContiguousPrefix(cfg, rows, holder) {
|
|
6116
|
-
const
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
|
|
6120
|
-
|
|
6121
|
-
|
|
6179
|
+
const claimed = await claimReplyBatch(
|
|
6180
|
+
cfg,
|
|
6181
|
+
rows.map((row) => row.id),
|
|
6182
|
+
holder
|
|
6183
|
+
);
|
|
6184
|
+
const prefix = rows.slice(0, claimed);
|
|
6122
6185
|
if (prefix.length < rows.length) {
|
|
6123
6186
|
log.info(
|
|
6124
6187
|
`coexistence: daemon owns ${rows.length - prefix.length} row(s); surfacing ${prefix.length}`
|
|
@@ -6141,7 +6204,6 @@ async function sessionStart(ctx, input) {
|
|
|
6141
6204
|
return none;
|
|
6142
6205
|
}
|
|
6143
6206
|
const cfg = { apiKey: identity.apiKey, apiBase: identity.apiBase };
|
|
6144
|
-
await markSessionActive(cfg);
|
|
6145
6207
|
const h = alwaysOnHealth(ctx.home);
|
|
6146
6208
|
const alert = h.wanted && !h.healthy ? formatAlwaysOnDown(ctx.copy) : null;
|
|
6147
6209
|
const peeked = ackableRows(await syncPeek(cfg, { limit: SESSION_START_PEEK_LIMIT }));
|
|
@@ -6165,9 +6227,10 @@ async function userPrompt(ctx, input) {
|
|
|
6165
6227
|
if (hooksDisabled()) return;
|
|
6166
6228
|
const identity = resolveIdentity(ctx.home);
|
|
6167
6229
|
if (identity === null) return;
|
|
6230
|
+
const cfg = { apiKey: identity.apiKey, apiBase: identity.apiBase };
|
|
6231
|
+
await markForegroundTurn(cfg, input.sessionId, FOREGROUND_TURN_TTL_SECONDS);
|
|
6168
6232
|
const cursor = takePendingAck(ctx.home, input.sessionId);
|
|
6169
6233
|
if (cursor === null) return;
|
|
6170
|
-
const cfg = { apiKey: identity.apiKey, apiBase: identity.apiBase };
|
|
6171
6234
|
try {
|
|
6172
6235
|
await syncAck(cfg, cursor);
|
|
6173
6236
|
} catch (err) {
|
|
@@ -6181,43 +6244,64 @@ async function userPrompt(ctx, input) {
|
|
|
6181
6244
|
async function stop(ctx, input) {
|
|
6182
6245
|
const none = { reason: null, commit: async () => {
|
|
6183
6246
|
} };
|
|
6247
|
+
let cfg = null;
|
|
6184
6248
|
try {
|
|
6185
6249
|
if (hooksDisabled()) return none;
|
|
6186
6250
|
const identity = resolveIdentity(ctx.home);
|
|
6187
6251
|
if (identity === null) return none;
|
|
6188
|
-
|
|
6189
|
-
await
|
|
6252
|
+
cfg = { apiKey: identity.apiKey, apiBase: identity.apiBase };
|
|
6253
|
+
await markForegroundTurn(cfg, input.sessionId, FOREGROUND_TURN_TTL_SECONDS);
|
|
6190
6254
|
const cap = maxContinuations();
|
|
6191
6255
|
if (getContinuations(ctx.home, input.sessionId) >= cap) {
|
|
6192
6256
|
log.info(
|
|
6193
6257
|
`stop hook: continuation cap (${cap}) reached for ${input.sessionId}; leaving inbox queued`
|
|
6194
6258
|
);
|
|
6259
|
+
await clearForegroundTurn(cfg, input.sessionId);
|
|
6195
6260
|
return none;
|
|
6196
6261
|
}
|
|
6197
6262
|
const peeked = ackableRows(await syncPeek(cfg, { limit: STOP_PEEK_LIMIT }));
|
|
6198
|
-
if (peeked.length === 0)
|
|
6263
|
+
if (peeked.length === 0) {
|
|
6264
|
+
await clearForegroundTurn(cfg, input.sessionId);
|
|
6265
|
+
return none;
|
|
6266
|
+
}
|
|
6199
6267
|
const rows = await claimContiguousPrefix(cfg, peeked, `session:${input.sessionId}`);
|
|
6200
|
-
if (rows.length === 0)
|
|
6268
|
+
if (rows.length === 0) {
|
|
6269
|
+
await clearForegroundTurn(cfg, input.sessionId);
|
|
6270
|
+
return none;
|
|
6271
|
+
}
|
|
6201
6272
|
recordContinuation(ctx.home, input.sessionId);
|
|
6202
6273
|
const handle = await resolveHandle(cfg, identity.handle);
|
|
6203
6274
|
const reason = formatStopPickup(handle, rows);
|
|
6204
6275
|
const cursor = lastDeliveryId(rows);
|
|
6276
|
+
const claimedCfg = cfg;
|
|
6205
6277
|
return {
|
|
6206
6278
|
reason,
|
|
6207
6279
|
commit: async () => {
|
|
6208
6280
|
if (cursor === null) return;
|
|
6209
6281
|
try {
|
|
6210
|
-
await syncAck(
|
|
6282
|
+
await syncAck(claimedCfg, cursor);
|
|
6211
6283
|
} catch (err) {
|
|
6212
6284
|
log.warn(`stop ack failed (messages stay queued): ${String(err)}`);
|
|
6213
6285
|
}
|
|
6214
6286
|
}
|
|
6215
6287
|
};
|
|
6216
6288
|
} catch (err) {
|
|
6289
|
+
if (cfg !== null) await clearForegroundTurn(cfg, input.sessionId);
|
|
6217
6290
|
log.warn(`stop hook degraded to no-op: ${String(err)}`);
|
|
6218
6291
|
return none;
|
|
6219
6292
|
}
|
|
6220
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
|
+
}
|
|
6221
6305
|
async function readHookInput(stream = process.stdin) {
|
|
6222
6306
|
let raw = "";
|
|
6223
6307
|
if (!stream.isTTY) {
|
|
@@ -6283,6 +6367,14 @@ function createHookRunners(context, dialect) {
|
|
|
6283
6367
|
} catch (err) {
|
|
6284
6368
|
log.warn(`stop hook degraded to no-op: ${String(err)}`);
|
|
6285
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
|
+
}
|
|
6286
6378
|
}
|
|
6287
6379
|
};
|
|
6288
6380
|
}
|
|
@@ -7321,24 +7413,25 @@ function serviceEnv() {
|
|
|
7321
7413
|
|
|
7322
7414
|
// src/wiring.ts
|
|
7323
7415
|
import * as fs6 from "fs";
|
|
7324
|
-
import * as
|
|
7416
|
+
import * as path7 from "path";
|
|
7325
7417
|
import { fileURLToPath } from "url";
|
|
7326
7418
|
|
|
7327
7419
|
// src/adapter.ts
|
|
7328
7420
|
import * as fs5 from "fs";
|
|
7421
|
+
import * as path6 from "path";
|
|
7329
7422
|
import { spawn as spawn2, spawnSync as spawnSync2 } from "child_process";
|
|
7330
7423
|
|
|
7331
7424
|
// src/version.ts
|
|
7332
|
-
var VERSION3 = "0.0.
|
|
7425
|
+
var VERSION3 = "0.0.171141";
|
|
7333
7426
|
|
|
7334
7427
|
// src/adapter.ts
|
|
7335
7428
|
var MAX_EVENT_TAIL_CHARS = 1024 * 1024;
|
|
7336
|
-
var AGENTCHAT_MCP_PACKAGE = "@agentchatme/mcp@0.1.
|
|
7429
|
+
var AGENTCHAT_MCP_PACKAGE = "@agentchatme/mcp@0.1.11214";
|
|
7337
7430
|
|
|
7338
7431
|
// src/wiring.ts
|
|
7339
7432
|
var TOML_START = "# agentchat:start";
|
|
7340
7433
|
var TOML_END = "# agentchat:end";
|
|
7341
|
-
var BUNDLE_REL =
|
|
7434
|
+
var BUNDLE_REL = path7.join("bin", "agentchat.mjs");
|
|
7342
7435
|
function atomicText(file, data) {
|
|
7343
7436
|
let mode = 384;
|
|
7344
7437
|
try {
|
|
@@ -7348,18 +7441,18 @@ function atomicText(file, data) {
|
|
|
7348
7441
|
atomicWriteFile(file, data, mode);
|
|
7349
7442
|
}
|
|
7350
7443
|
function codexConfigPath() {
|
|
7351
|
-
return
|
|
7444
|
+
return path7.join(codexHome(), "config.toml");
|
|
7352
7445
|
}
|
|
7353
7446
|
function codexHooksPath() {
|
|
7354
|
-
return
|
|
7447
|
+
return path7.join(codexHome(), "hooks.json");
|
|
7355
7448
|
}
|
|
7356
7449
|
function stableBundlePath() {
|
|
7357
|
-
return
|
|
7450
|
+
return path7.join(identityHome(), BUNDLE_REL);
|
|
7358
7451
|
}
|
|
7359
|
-
var DAEMON_REL =
|
|
7452
|
+
var DAEMON_REL = path7.join("bin", "agentchat-daemon.mjs");
|
|
7360
7453
|
var MANUAL_REL = "SKILL.md";
|
|
7361
7454
|
function manualPath() {
|
|
7362
|
-
return
|
|
7455
|
+
return path7.join(identityHome(), MANUAL_REL);
|
|
7363
7456
|
}
|
|
7364
7457
|
function writeManual() {
|
|
7365
7458
|
try {
|
|
@@ -7369,7 +7462,7 @@ function writeManual() {
|
|
|
7369
7462
|
renderManual({
|
|
7370
7463
|
...hostCopy(),
|
|
7371
7464
|
peerLabel: "Claude Code",
|
|
7372
|
-
peerInvoke: "
|
|
7465
|
+
peerInvoke: "npx -y @agentchatme/claude-code"
|
|
7373
7466
|
})
|
|
7374
7467
|
);
|
|
7375
7468
|
return true;
|
|
@@ -7378,10 +7471,13 @@ function writeManual() {
|
|
|
7378
7471
|
}
|
|
7379
7472
|
}
|
|
7380
7473
|
function shippedDaemonPath() {
|
|
7381
|
-
return
|
|
7474
|
+
return path7.join(path7.dirname(fileURLToPath(import.meta.url)), "daemon-main.js");
|
|
7475
|
+
}
|
|
7476
|
+
function shippedBundlePath() {
|
|
7477
|
+
return fileURLToPath(import.meta.url);
|
|
7382
7478
|
}
|
|
7383
7479
|
function stableDaemonPath() {
|
|
7384
|
-
return
|
|
7480
|
+
return path7.join(identityHome(), DAEMON_REL);
|
|
7385
7481
|
}
|
|
7386
7482
|
function copyDaemonBundle() {
|
|
7387
7483
|
const src = shippedDaemonPath();
|
|
@@ -7389,20 +7485,11 @@ function copyDaemonBundle() {
|
|
|
7389
7485
|
throw new Error(`the daemon bundle is missing from this install (expected ${src})`);
|
|
7390
7486
|
}
|
|
7391
7487
|
const dest = stableDaemonPath();
|
|
7392
|
-
fs6.mkdirSync(
|
|
7393
|
-
if (
|
|
7488
|
+
fs6.mkdirSync(path7.dirname(dest), { recursive: true });
|
|
7489
|
+
if (path7.resolve(src) !== path7.resolve(dest)) atomicCopyFile(src, dest);
|
|
7394
7490
|
else fs6.chmodSync(dest, 493);
|
|
7395
7491
|
return dest;
|
|
7396
7492
|
}
|
|
7397
|
-
function isCodexWired() {
|
|
7398
|
-
const cfg = codexConfigPath();
|
|
7399
|
-
if (!fs6.existsSync(cfg)) return false;
|
|
7400
|
-
try {
|
|
7401
|
-
return fs6.readFileSync(cfg, "utf-8").includes(TOML_START);
|
|
7402
|
-
} catch {
|
|
7403
|
-
return false;
|
|
7404
|
-
}
|
|
7405
|
-
}
|
|
7406
7493
|
function renderCodexAgents(handle) {
|
|
7407
7494
|
return [
|
|
7408
7495
|
ANCHOR_START,
|
|
@@ -7485,21 +7572,47 @@ function ourHookGroups(bundle) {
|
|
|
7485
7572
|
hooks: [{ type: "command", command: `node "${bundle}" hook ${sub}`, timeout }]
|
|
7486
7573
|
});
|
|
7487
7574
|
return {
|
|
7488
|
-
SessionStart: [{ matcher: "startup|resume|clear", ...cmd("session-start",
|
|
7489
|
-
UserPromptSubmit: [cmd("user-prompt",
|
|
7490
|
-
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)]
|
|
7491
7579
|
};
|
|
7492
7580
|
}
|
|
7493
|
-
function
|
|
7494
|
-
|
|
7495
|
-
|
|
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;
|
|
7496
7609
|
}
|
|
7497
7610
|
function mergeHooks(existing, bundle) {
|
|
7498
7611
|
const doc = existing && typeof existing === "object" ? existing : {};
|
|
7499
7612
|
const hooks = doc.hooks && typeof doc.hooks === "object" ? doc.hooks : {};
|
|
7500
7613
|
for (const [event, groups] of Object.entries(ourHookGroups(bundle))) {
|
|
7501
7614
|
const prior = Array.isArray(hooks[event]) ? hooks[event] : [];
|
|
7502
|
-
hooks[event] = [...prior
|
|
7615
|
+
hooks[event] = [...withoutOurLeaves(prior), ...groups];
|
|
7503
7616
|
}
|
|
7504
7617
|
doc.hooks = hooks;
|
|
7505
7618
|
return doc;
|
|
@@ -7509,7 +7622,7 @@ function unmergeHooks(existing) {
|
|
|
7509
7622
|
const hooks = existing.hooks;
|
|
7510
7623
|
let anyLeft = false;
|
|
7511
7624
|
for (const event of Object.keys(hooks)) {
|
|
7512
|
-
const kept = (Array.isArray(hooks[event]) ? hooks[event] : [])
|
|
7625
|
+
const kept = withoutOurLeaves(Array.isArray(hooks[event]) ? hooks[event] : []);
|
|
7513
7626
|
if (kept.length > 0) {
|
|
7514
7627
|
hooks[event] = kept;
|
|
7515
7628
|
anyLeft = true;
|
|
@@ -7524,53 +7637,66 @@ function unmergeHooks(existing) {
|
|
|
7524
7637
|
}
|
|
7525
7638
|
return existing;
|
|
7526
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
|
+
}
|
|
7527
7649
|
function copyBundle(bundleSrc) {
|
|
7528
7650
|
const dest = stableBundlePath();
|
|
7529
|
-
fs6.mkdirSync(
|
|
7530
|
-
const srcResolved =
|
|
7531
|
-
if (srcResolved !==
|
|
7651
|
+
fs6.mkdirSync(path7.dirname(dest), { recursive: true });
|
|
7652
|
+
const srcResolved = path7.resolve(bundleSrc);
|
|
7653
|
+
if (srcResolved !== path7.resolve(dest)) {
|
|
7532
7654
|
atomicCopyFile(srcResolved, dest);
|
|
7533
7655
|
}
|
|
7534
7656
|
return dest;
|
|
7535
7657
|
}
|
|
7536
|
-
function installCodex(
|
|
7658
|
+
function installCodex(handle) {
|
|
7537
7659
|
const actions = [];
|
|
7538
7660
|
const warnings = [];
|
|
7539
7661
|
fs6.mkdirSync(codexHome(), { recursive: true });
|
|
7540
|
-
let bundle;
|
|
7541
|
-
try {
|
|
7542
|
-
bundle = copyBundle(bundleSrc);
|
|
7543
|
-
actions.push(`bundle \u2192 ${bundle}`);
|
|
7544
|
-
} catch (err) {
|
|
7545
|
-
bundle = stableBundlePath();
|
|
7546
|
-
warnings.push(
|
|
7547
|
-
`could not copy the CLI bundle (${String(err)}); hooks will use ${bundle} \u2014 ensure it exists`
|
|
7548
|
-
);
|
|
7549
|
-
}
|
|
7550
7662
|
const cfgPath = codexConfigPath();
|
|
7551
7663
|
const existingCfg = fs6.existsSync(cfgPath) ? fs6.readFileSync(cfgPath, "utf-8") : "";
|
|
7552
7664
|
if (hasUnfencedAgentchatServer(existingCfg)) {
|
|
7553
7665
|
warnings.push(
|
|
7554
|
-
`${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`
|
|
7555
7667
|
);
|
|
7556
|
-
|
|
7557
|
-
atomicText(cfgPath, upsertTomlBlock(existingCfg, mcpBlock()));
|
|
7558
|
-
actions.push(`config.toml \u2190 [mcp_servers.agentchat]`);
|
|
7668
|
+
return { actions, warnings, complete: false };
|
|
7559
7669
|
}
|
|
7560
7670
|
const hooksPath = codexHooksPath();
|
|
7561
7671
|
let existingHooks = null;
|
|
7562
7672
|
if (fs6.existsSync(hooksPath)) {
|
|
7563
7673
|
try {
|
|
7564
|
-
|
|
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;
|
|
7565
7680
|
} catch {
|
|
7566
|
-
warnings.push(`${hooksPath}
|
|
7681
|
+
warnings.push(`${hooksPath} is not valid JSON \u2014 left everything untouched`);
|
|
7682
|
+
return { actions, warnings, complete: false };
|
|
7567
7683
|
}
|
|
7568
7684
|
}
|
|
7569
|
-
|
|
7570
|
-
|
|
7571
|
-
|
|
7572
|
-
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 };
|
|
7573
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");
|
|
7574
7700
|
if (writeManual()) actions.push("SKILL.md \u2190 the manual");
|
|
7575
7701
|
else warnings.push("could not write the AgentChat manual \u2014 the agent will have only the anchor");
|
|
7576
7702
|
if (handle) {
|
|
@@ -7590,7 +7716,7 @@ function installCodex(bundleSrc, handle) {
|
|
|
7590
7716
|
}
|
|
7591
7717
|
}
|
|
7592
7718
|
log.debug(`codex install: ${actions.join("; ")}`);
|
|
7593
|
-
return { actions, warnings };
|
|
7719
|
+
return { actions, warnings, complete: isCodexWired() };
|
|
7594
7720
|
}
|
|
7595
7721
|
function removeCodexWiring(opts = {}) {
|
|
7596
7722
|
const removed = [];
|
|
@@ -7629,7 +7755,7 @@ function removeCodexWiring(opts = {}) {
|
|
|
7629
7755
|
|
|
7630
7756
|
// src/identity.ts
|
|
7631
7757
|
import * as fs8 from "fs";
|
|
7632
|
-
import * as
|
|
7758
|
+
import * as path8 from "path";
|
|
7633
7759
|
import { spawnSync as spawnSync3 } from "child_process";
|
|
7634
7760
|
|
|
7635
7761
|
// src/always-on.ts
|
|
@@ -7732,17 +7858,10 @@ function runtimeChecks() {
|
|
|
7732
7858
|
];
|
|
7733
7859
|
}
|
|
7734
7860
|
function wiringCheck(fix) {
|
|
7735
|
-
const current = () =>
|
|
7736
|
-
try {
|
|
7737
|
-
const config = fs8.readFileSync(codexConfigPath(), "utf-8");
|
|
7738
|
-
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());
|
|
7739
|
-
} catch {
|
|
7740
|
-
return false;
|
|
7741
|
-
}
|
|
7742
|
-
};
|
|
7861
|
+
const current = () => isCodexWired();
|
|
7743
7862
|
if (fix && !current()) {
|
|
7744
7863
|
try {
|
|
7745
|
-
installCodex(
|
|
7864
|
+
installCodex(readCredentials(identityHome())?.handle ?? null);
|
|
7746
7865
|
} catch (err) {
|
|
7747
7866
|
return { name: "wiring", verdict: "FAIL", detail: `repair failed: ${String(err)}` };
|
|
7748
7867
|
}
|
|
@@ -7803,7 +7922,7 @@ function hookTrustCheck() {
|
|
|
7803
7922
|
cfg = fs8.readFileSync(codexConfigPath(), "utf-8");
|
|
7804
7923
|
} catch {
|
|
7805
7924
|
}
|
|
7806
|
-
const events = ["session_start", "user_prompt_submit", "stop"];
|
|
7925
|
+
const events = ["session_start", "user_prompt_submit", "stop", "session_end"];
|
|
7807
7926
|
const missing = events.filter((e) => !cfg.includes(`${hooksPath}:${e}`));
|
|
7808
7927
|
if (missing.length === 0) {
|
|
7809
7928
|
return { name: "hook-trust", verdict: "PASS", detail: "Codex has trusted the AgentChat hooks" };
|
|
@@ -7811,7 +7930,7 @@ function hookTrustCheck() {
|
|
|
7811
7930
|
return {
|
|
7812
7931
|
name: "hook-trust",
|
|
7813
7932
|
verdict: "WARN",
|
|
7814
|
-
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.`
|
|
7815
7934
|
};
|
|
7816
7935
|
}
|
|
7817
7936
|
var commands = createIdentityCommands(profile);
|
|
@@ -7821,7 +7940,7 @@ function runNotNow() {
|
|
|
7821
7940
|
try {
|
|
7822
7941
|
writeAnchor(anchorFile(), renderDeclinedBlock({ invoke: invocation(), label: LABEL }));
|
|
7823
7942
|
} catch (err) {
|
|
7824
|
-
console.error(`Recorded, but could not update ${
|
|
7943
|
+
console.error(`Recorded, but could not update ${path8.basename(anchorFile())}: ${String(err)}`);
|
|
7825
7944
|
return 1;
|
|
7826
7945
|
}
|
|
7827
7946
|
console.log(
|
|
@@ -7875,6 +7994,9 @@ async function runStop() {
|
|
|
7875
7994
|
ensureAlwaysOnQuietly();
|
|
7876
7995
|
await runners.runStop();
|
|
7877
7996
|
}
|
|
7997
|
+
async function runSessionEnd() {
|
|
7998
|
+
await runners.runSessionEnd();
|
|
7999
|
+
}
|
|
7878
8000
|
|
|
7879
8001
|
// src/index.ts
|
|
7880
8002
|
var USAGE = `agentchat-codex ${VERSION3} \u2014 AgentChat for Codex
|
|
@@ -7896,8 +8018,7 @@ Usage:
|
|
|
7896
8018
|
This command only ever acts on your ${LABEL} agent. If you also run another
|
|
7897
8019
|
coding agent here, it is a SEPARATE AgentChat agent with its own @handle \u2014 the
|
|
7898
8020
|
two of you can DM each other \u2014 and it has its own front door:
|
|
7899
|
-
Claude Code:
|
|
7900
|
-
/plugin install agentchat@agentchatme
|
|
8021
|
+
Claude Code: npx -y @agentchatme/claude-code
|
|
7901
8022
|
|
|
7902
8023
|
AGENTCHAT_API_KEY / AGENTCHAT_API_BASE override the stored identity.
|
|
7903
8024
|
(hook subcommands are wired by the installer \u2014 you don't run them.)
|
|
@@ -7943,14 +8064,29 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
7943
8064
|
const home = identityHome();
|
|
7944
8065
|
const handle = readCredentials(home)?.handle ?? null;
|
|
7945
8066
|
try {
|
|
7946
|
-
const
|
|
7947
|
-
const
|
|
7948
|
-
|
|
7949
|
-
|
|
7950
|
-
|
|
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
|
+
);
|
|
7951
8083
|
}
|
|
7952
|
-
|
|
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
|
+
);
|
|
7953
8088
|
for (const w of warnings) console.log(` \u26A0 ${w}`);
|
|
8089
|
+
if (failed) return 1;
|
|
7954
8090
|
} catch (err) {
|
|
7955
8091
|
console.error(`${LABEL}: wiring failed \u2014 ${String(err)}`);
|
|
7956
8092
|
return 1;
|
|
@@ -7961,17 +8097,21 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
7961
8097
|
"",
|
|
7962
8098
|
`Last step \u2014 give ${LABEL} its @handle:`,
|
|
7963
8099
|
` Open Codex and it will offer to set one up \u2014 or run:`,
|
|
7964
|
-
` ${invocation()} register --email <email> --handle <handle
|
|
7965
|
-
"",
|
|
7966
|
-
"One optional step: Codex requires new hooks to be approved before it will",
|
|
7967
|
-
"run them. Run `/hooks` in Codex and trust the three AgentChat entries to get",
|
|
7968
|
-
"inbox digests delivered into your session. Everything else already works."
|
|
8100
|
+
` ${invocation()} register --email <email> --handle <handle>`
|
|
7969
8101
|
].join("\n")
|
|
7970
8102
|
);
|
|
7971
8103
|
} else {
|
|
7972
8104
|
console.log(`
|
|
7973
8105
|
Signed in as @${handle}.`);
|
|
7974
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
|
+
);
|
|
7975
8115
|
return 0;
|
|
7976
8116
|
}
|
|
7977
8117
|
case "register":
|
|
@@ -8018,7 +8158,11 @@ Signed in as @${handle}.`);
|
|
|
8018
8158
|
await runStop();
|
|
8019
8159
|
return 0;
|
|
8020
8160
|
}
|
|
8021
|
-
|
|
8161
|
+
if (subcommand === "session-end") {
|
|
8162
|
+
await runSessionEnd();
|
|
8163
|
+
return 0;
|
|
8164
|
+
}
|
|
8165
|
+
console.error("Usage: hook <session-start|user-prompt|stop|session-end>");
|
|
8022
8166
|
return 1;
|
|
8023
8167
|
}
|
|
8024
8168
|
default:
|