@agentchatme/codex 0.0.17 → 0.0.17111

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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.13/node_modules/@agentchatme/agent-core/dist/chunk-NEGTEBFK.js
8
+ // node_modules/.pnpm/@agentchatme+agent-core@0.0.1311/node_modules/@agentchatme/agent-core/dist/chunk-ER4AFPH7.js
9
9
  import * as fs2 from "fs";
10
10
  import * as path2 from "path";
11
11
  import * as fs3 from "fs";
@@ -35,6 +35,15 @@ var log = {
35
35
  info: (msg) => emit("info", msg),
36
36
  debug: (msg) => emit("debug", msg)
37
37
  };
38
+ var VERSION = "0.0.1311";
39
+ var CODING_AGENTS_CLIENT_IDENTITY = {
40
+ name: "coding_agents",
41
+ version: VERSION
42
+ };
43
+ var CODING_AGENTS_CLIENT_HEADERS = {
44
+ "X-AgentChat-Client": CODING_AGENTS_CLIENT_IDENTITY.name,
45
+ "X-AgentChat-Client-Version": CODING_AGENTS_CLIENT_IDENTITY.version
46
+ };
38
47
  function atomicWriteFile(filePath, data, mode) {
39
48
  const dir = path2.dirname(filePath);
40
49
  fs2.mkdirSync(dir, { recursive: true, mode: 448 });
@@ -4201,6 +4210,7 @@ async function request(cfg, method, pathname, body) {
4201
4210
  const res = await fetch(url, {
4202
4211
  method,
4203
4212
  headers: {
4213
+ ...CODING_AGENTS_CLIENT_HEADERS,
4204
4214
  authorization: `Bearer ${cfg.apiKey}`,
4205
4215
  ...body !== void 0 ? { "content-type": "application/json" } : {}
4206
4216
  },
@@ -4290,7 +4300,7 @@ var HEARTBEAT_STALE_MS = 3 * 6e4;
4290
4300
  function markAlwaysOnWanted(home) {
4291
4301
  try {
4292
4302
  fs4.mkdirSync(home, { recursive: true });
4293
- fs4.writeFileSync(path4.join(home, ALWAYS_ON_WANTED), "");
4303
+ fs4.writeFileSync(path4.join(home, ALWAYS_ON_WANTED), (/* @__PURE__ */ new Date()).toISOString());
4294
4304
  } catch {
4295
4305
  }
4296
4306
  }
@@ -4320,27 +4330,36 @@ function clearAlwaysOnOptOut(home) {
4320
4330
  function alwaysOnOptedOut(home) {
4321
4331
  return fs4.existsSync(path4.join(home, ALWAYS_ON_OPTOUT));
4322
4332
  }
4333
+ var STARTUP_GRACE_MS = 9e4;
4323
4334
  function alwaysOnState(home) {
4324
4335
  if (!alwaysOnWanted(home)) return "off";
4325
4336
  if (!fs4.existsSync(path4.join(home, "credentials"))) return "idle";
4337
+ let beating = false;
4326
4338
  try {
4327
4339
  const age = Date.now() - fs4.statSync(path4.join(home, HEARTBEAT_FILE)).mtimeMs;
4328
- return age <= HEARTBEAT_STALE_MS ? "connected" : "down";
4340
+ beating = age <= HEARTBEAT_STALE_MS;
4341
+ } catch {
4342
+ beating = false;
4343
+ }
4344
+ if (beating) return "connected";
4345
+ try {
4346
+ const since = Date.now() - fs4.statSync(path4.join(home, ALWAYS_ON_WANTED)).mtimeMs;
4347
+ if (since <= STARTUP_GRACE_MS) return "starting";
4329
4348
  } catch {
4330
- return "down";
4331
4349
  }
4350
+ return "down";
4332
4351
  }
4333
4352
  function alwaysOnHealth(home) {
4334
4353
  const state = alwaysOnState(home);
4335
4354
  return { wanted: state !== "off", healthy: state !== "down" };
4336
4355
  }
4337
4356
 
4338
- // node_modules/.pnpm/@agentchatme+agent-core@0.0.13/node_modules/@agentchatme/agent-core/dist/index.js
4357
+ // node_modules/.pnpm/@agentchatme+agent-core@0.0.1311/node_modules/@agentchatme/agent-core/dist/index.js
4339
4358
  import * as fs from "fs";
4340
4359
  import * as path from "path";
4341
4360
  import * as readline from "readline";
4342
4361
 
4343
- // node_modules/.pnpm/agentchatme@1.0.22_ws@8.21.1/node_modules/agentchatme/dist/index.js
4362
+ // node_modules/.pnpm/agentchatme@1.0.221_ws@8.21.1/node_modules/agentchatme/dist/index.js
4344
4363
  var ErrorCode = {
4345
4364
  AGENT_NOT_FOUND: "AGENT_NOT_FOUND",
4346
4365
  AGENT_SUSPENDED: "AGENT_SUSPENDED",
@@ -4546,7 +4565,7 @@ function createAgentChatError(body, status, headers) {
4546
4565
  return new AgentChatError(body, status, requestId);
4547
4566
  }
4548
4567
  }
4549
- var VERSION = "1.0.22";
4568
+ var VERSION2 = "1.0.221";
4550
4569
  function detectRuntime() {
4551
4570
  const g = globalThis;
4552
4571
  if (typeof g.Bun?.version === "string") return `bun/${g.Bun.version}`;
@@ -4560,7 +4579,7 @@ function detectRuntime() {
4560
4579
  return "unknown";
4561
4580
  }
4562
4581
  function defaultUserAgent() {
4563
- return `agentchat-ts/${VERSION} ${detectRuntime()}`;
4582
+ return `agentchat-ts/${VERSION2} ${detectRuntime()}`;
4564
4583
  }
4565
4584
  var REQUEST_ID_HEADER = "x-request-id";
4566
4585
  var DEFAULT_RETRY_POLICY = {
@@ -4879,6 +4898,16 @@ async function* paginate(fetchPage, options) {
4879
4898
  if (page.items.length === 0) return;
4880
4899
  }
4881
4900
  }
4901
+ var DEFAULT_CLIENT_IDENTITY = {
4902
+ name: "typescript_sdk",
4903
+ version: VERSION2
4904
+ };
4905
+ function clientIdentityHeaders(identity = DEFAULT_CLIENT_IDENTITY) {
4906
+ return {
4907
+ "X-AgentChat-Client": identity.name,
4908
+ ...identity.version ? { "X-AgentChat-Client-Version": identity.version } : {}
4909
+ };
4910
+ }
4882
4911
  var DEFAULT_BASE_URL = "https://api.agentchat.me";
4883
4912
  function parseBacklogWarning(header) {
4884
4913
  if (!header) return null;
@@ -4915,7 +4944,8 @@ var AgentChatClient = class _AgentChatClient {
4915
4944
  timeoutMs: options.timeoutMs,
4916
4945
  retry: options.retry,
4917
4946
  hooks: options.hooks,
4918
- fetch: options.fetch
4947
+ fetch: options.fetch,
4948
+ defaultHeaders: clientIdentityHeaders(options.clientIdentity)
4919
4949
  });
4920
4950
  this.onBacklogWarning = options.onBacklogWarning;
4921
4951
  }
@@ -4966,7 +4996,10 @@ var AgentChatClient = class _AgentChatClient {
4966
4996
  * returned `pending_id` and the OTP code.
4967
4997
  */
4968
4998
  static async register(options) {
4969
- const http = new HttpTransport({ baseUrl: options.baseUrl ?? DEFAULT_BASE_URL });
4999
+ const http = new HttpTransport({
5000
+ baseUrl: options.baseUrl ?? DEFAULT_BASE_URL,
5001
+ defaultHeaders: clientIdentityHeaders(options.clientIdentity)
5002
+ });
4970
5003
  const res = await http.request("POST", "/v1/register", {
4971
5004
  body: {
4972
5005
  email: options.email,
@@ -4986,12 +5019,19 @@ var AgentChatClient = class _AgentChatClient {
4986
5019
  */
4987
5020
  static async verify(pendingId, code, options) {
4988
5021
  const baseUrl = options?.baseUrl ?? DEFAULT_BASE_URL;
4989
- const http = new HttpTransport({ baseUrl });
5022
+ const http = new HttpTransport({
5023
+ baseUrl,
5024
+ defaultHeaders: clientIdentityHeaders(options?.clientIdentity)
5025
+ });
4990
5026
  const res = await http.request("POST", "/v1/register/verify", {
4991
5027
  body: { pending_id: pendingId, code },
4992
5028
  retry: "never"
4993
5029
  });
4994
- const client = new _AgentChatClient({ apiKey: res.data.api_key, baseUrl });
5030
+ const client = new _AgentChatClient({
5031
+ apiKey: res.data.api_key,
5032
+ baseUrl,
5033
+ clientIdentity: options?.clientIdentity
5034
+ });
4995
5035
  return { agent: res.data.agent, apiKey: res.data.api_key, client };
4996
5036
  }
4997
5037
  /**
@@ -5002,7 +5042,10 @@ var AgentChatClient = class _AgentChatClient {
5002
5042
  */
5003
5043
  static async recover(email, options) {
5004
5044
  const baseUrl = options?.baseUrl ?? DEFAULT_BASE_URL;
5005
- const http = new HttpTransport({ baseUrl });
5045
+ const http = new HttpTransport({
5046
+ baseUrl,
5047
+ defaultHeaders: clientIdentityHeaders(options?.clientIdentity)
5048
+ });
5006
5049
  const res = await http.request(
5007
5050
  "POST",
5008
5051
  "/v1/agents/recover",
@@ -5012,13 +5055,20 @@ var AgentChatClient = class _AgentChatClient {
5012
5055
  }
5013
5056
  static async recoverVerify(pendingId, code, options) {
5014
5057
  const baseUrl = options?.baseUrl ?? DEFAULT_BASE_URL;
5015
- const http = new HttpTransport({ baseUrl });
5058
+ const http = new HttpTransport({
5059
+ baseUrl,
5060
+ defaultHeaders: clientIdentityHeaders(options?.clientIdentity)
5061
+ });
5016
5062
  const res = await http.request(
5017
5063
  "POST",
5018
5064
  "/v1/agents/recover/verify",
5019
5065
  { body: { pending_id: pendingId, code }, retry: "never" }
5020
5066
  );
5021
- const client = new _AgentChatClient({ apiKey: res.data.api_key, baseUrl });
5067
+ const client = new _AgentChatClient({
5068
+ apiKey: res.data.api_key,
5069
+ baseUrl,
5070
+ clientIdentity: options?.clientIdentity
5071
+ });
5022
5072
  return { handle: res.data.handle, apiKey: res.data.api_key, client };
5023
5073
  }
5024
5074
  // ─── Agent profile ────────────────────────────────────────────────────────
@@ -5623,7 +5673,7 @@ var HOUR = 60 * MIN;
5623
5673
  var DAY = 24 * HOUR;
5624
5674
  var MAX_ATTACHMENT_SIZE = 25 * 1024 * 1024;
5625
5675
 
5626
- // node_modules/.pnpm/@agentchatme+agent-core@0.0.13/node_modules/@agentchatme/agent-core/dist/index.js
5676
+ // node_modules/.pnpm/@agentchatme+agent-core@0.0.1311/node_modules/@agentchatme/agent-core/dist/index.js
5627
5677
  import * as fs22 from "fs";
5628
5678
  import * as os from "os";
5629
5679
  import * as path22 from "path";
@@ -5916,29 +5966,45 @@ function formatStopPickup(handle, rows) {
5916
5966
  function formatAlwaysOnDown(copy) {
5917
5967
  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, nothing is lost). Turn it back on: \`${copy.invoke} daemon install\``;
5918
5968
  }
5919
- function formatRegistrationOffer(copy) {
5969
+ function formatRegistrationOffer(copy, alwaysOn = "off") {
5920
5970
  const { invoke, label } = copy;
5921
5971
  return [
5922
- `The AgentChat plugin is installed but this ${label} agent has no AgentChat identity yet.`,
5972
+ `This ${label} agent is on AgentChat but has no handle yet \u2014 no address other agents can reach it at.`,
5923
5973
  "",
5924
- "AgentChat gives you (the agent) a handle other agents can DM. If the user would like that, offer to set it up \u2014 and FIRST ask whether they already have an AgentChat account (e.g. from another machine, or a Hermes / OpenClaw agent), so you sign them in instead of creating a duplicate:",
5925
- `This ${label} agent gets its OWN handle \u2014 separate from any other coding agent on this machine, which is exactly what lets them DM each other. Use an email not already tied to another agent.`,
5974
+ "If the moment is right, offer it in ONE plain sentence and let them answer. Do not paste this block,",
5975
+ "do not list the commands, do not walk them through steps. You run the commands; they just talk to you.",
5926
5976
  "",
5927
- "NEW to AgentChat (most people):",
5928
- " 1. Ask for their email + a desired handle (3\u201330 chars, lowercase letters/digits/hyphens, must start with a letter).",
5929
- ` 2. Run: ${invoke} register --email <email> --handle <handle>`,
5930
- ` 3. A 6-digit code lands in their email; ask for it, then run: ${invoke} register --code <code>`,
5931
- "",
5932
- "ALREADY have an AgentChat agent \u2014 sign in, do NOT register a second one:",
5933
- ` \u2022 They have its API key (ac_\u2026): ${invoke} login --api-key <ac_\u2026>`,
5934
- ` \u2022 They lost the key: ${invoke} recover --email <email>, then relay the emailed 6-digit code: ${invoke} recover --code <code>`,
5977
+ "All you need from them is an email and a handle they like (3\u201330 characters, lowercase letters, digits",
5978
+ "and hyphens, starting with a letter). Ask first whether they already have an AgentChat account \u2014 from",
5979
+ "another machine, or a Hermes or OpenClaw agent \u2014 so you sign that one in instead of creating a second.",
5980
+ `Either way this ${label} agent ends up with its own handle, separate from any other coding agent here,`,
5981
+ "which is what lets them message each other.",
5935
5982
  "",
5983
+ "Commands \u2014 yours to run, not to show:",
5984
+ ` new account ${invoke} register --email <email> --handle <handle>`,
5985
+ ` then, with the 6-digit code they were emailed: ${invoke} register --code <code>`,
5986
+ ` has an API key ${invoke} login --api-key <ac_\u2026>`,
5987
+ ` lost the key ${invoke} recover --email <email>, then ${invoke} recover --code <code>`,
5936
5988
  "",
5937
- "Always-on is already running \u2014 this agent answers DMs even when no session is open. There is nothing to switch on, so do not offer to.",
5989
+ alwaysOnNote(alwaysOn, invoke),
5938
5990
  "",
5939
- "Do not push the offer \u2014 one short ask is plenty. If declined, drop the topic for the rest of the session."
5991
+ `One ask is plenty. If they decline or change the subject, drop it \u2014 and \`${invoke} register --not-now\``,
5992
+ "stops it being raised in future sessions too."
5940
5993
  ].join("\n");
5941
5994
  }
5995
+ function alwaysOnNote(state, invoke) {
5996
+ switch (state) {
5997
+ case "connected":
5998
+ return "Always-on is running: this agent answers DMs even with no session open. Nothing to switch on.";
5999
+ case "idle":
6000
+ case "starting":
6001
+ return "Always-on is set up and will start answering DMs on its own as soon as there is a handle. Nothing to switch on.";
6002
+ case "off":
6003
+ return "Always-on is not set up here, so DMs are only seen during a session.";
6004
+ case "down":
6005
+ return `Always-on is registered but not running \u2014 \`${invoke} daemon status\` says why. DMs are only seen during a session until it recovers.`;
6006
+ }
6007
+ }
5942
6008
  function renderUnregisteredBlock(copy) {
5943
6009
  const { invoke, label } = copy;
5944
6010
  return [
@@ -6024,7 +6090,7 @@ async function sessionStart(ctx, input) {
6024
6090
  if (identity === null) {
6025
6091
  if (shouldOfferRegistration(ctx.home)) {
6026
6092
  recordRegistrationOffer(ctx.home);
6027
- return { context: formatRegistrationOffer(ctx.copy) };
6093
+ return { context: formatRegistrationOffer(ctx.copy, alwaysOnState(ctx.home)) };
6028
6094
  }
6029
6095
  return none;
6030
6096
  }
@@ -6260,7 +6326,8 @@ function createIdentityCommands(profile2) {
6260
6326
  }
6261
6327
  try {
6262
6328
  const result = await AgentChatClient.verify(pending.pending_id, code, {
6263
- baseUrl: pending.api_base ?? apiBase
6329
+ baseUrl: pending.api_base ?? apiBase,
6330
+ clientIdentity: CODING_AGENTS_CLIENT_IDENTITY
6264
6331
  });
6265
6332
  writeCredentials(home, {
6266
6333
  api_key: result.apiKey,
@@ -6333,7 +6400,8 @@ function createIdentityCommands(profile2) {
6333
6400
  handle,
6334
6401
  ...opts.displayName ? { display_name: opts.displayName } : {},
6335
6402
  ...opts.description ? { description: opts.description } : {},
6336
- baseUrl: apiBase
6403
+ baseUrl: apiBase,
6404
+ clientIdentity: CODING_AGENTS_CLIENT_IDENTITY
6337
6405
  });
6338
6406
  writePending(home, {
6339
6407
  kind: "register",
@@ -6371,7 +6439,11 @@ function createIdentityCommands(profile2) {
6371
6439
  return 1;
6372
6440
  }
6373
6441
  try {
6374
- const client = new AgentChatClient({ apiKey, baseUrl: apiBase });
6442
+ const client = new AgentChatClient({
6443
+ apiKey,
6444
+ baseUrl: apiBase,
6445
+ clientIdentity: CODING_AGENTS_CLIENT_IDENTITY
6446
+ });
6375
6447
  const me = await client.getMe();
6376
6448
  writeCredentials(home, {
6377
6449
  api_key: apiKey,
@@ -6403,7 +6475,8 @@ function createIdentityCommands(profile2) {
6403
6475
  }
6404
6476
  try {
6405
6477
  const result = await AgentChatClient.recoverVerify(pending.pending_id, code, {
6406
- baseUrl: pending.api_base ?? apiBase
6478
+ baseUrl: pending.api_base ?? apiBase,
6479
+ clientIdentity: CODING_AGENTS_CLIENT_IDENTITY
6407
6480
  });
6408
6481
  writeCredentials(home, {
6409
6482
  api_key: result.apiKey,
@@ -6439,7 +6512,10 @@ function createIdentityCommands(profile2) {
6439
6512
  return 1;
6440
6513
  }
6441
6514
  try {
6442
- const result = await AgentChatClient.recover(email, { baseUrl: apiBase });
6515
+ const result = await AgentChatClient.recover(email, {
6516
+ baseUrl: apiBase,
6517
+ clientIdentity: CODING_AGENTS_CLIENT_IDENTITY
6518
+ });
6443
6519
  if (!result.pending_id) {
6444
6520
  console.log("If an agent is registered with that email, a recovery code was sent to it.");
6445
6521
  return 0;
@@ -6488,7 +6564,11 @@ function createIdentityCommands(profile2) {
6488
6564
  return 0;
6489
6565
  }
6490
6566
  try {
6491
- const client = new AgentChatClient({ apiKey: identity.apiKey, baseUrl: identity.apiBase });
6567
+ const client = new AgentChatClient({
6568
+ apiKey: identity.apiKey,
6569
+ baseUrl: identity.apiBase,
6570
+ clientIdentity: CODING_AGENTS_CLIENT_IDENTITY
6571
+ });
6492
6572
  const me = await client.getMe();
6493
6573
  const rows = await syncPeek({ apiKey: identity.apiKey, apiBase: identity.apiBase }, { limit: 100 });
6494
6574
  const unread = rows.length === 100 ? "100+" : String(rows.length);
@@ -6575,7 +6655,11 @@ function createIdentityCommands(profile2) {
6575
6655
  const identity = resolveIdentity(home);
6576
6656
  if (identity !== null) {
6577
6657
  try {
6578
- const client = new AgentChatClient({ apiKey: identity.apiKey, baseUrl: identity.apiBase });
6658
+ const client = new AgentChatClient({
6659
+ apiKey: identity.apiKey,
6660
+ baseUrl: identity.apiBase,
6661
+ clientIdentity: CODING_AGENTS_CLIENT_IDENTITY
6662
+ });
6579
6663
  const started = Date.now();
6580
6664
  const me = await client.getMe();
6581
6665
  const verdict = (me.status ?? "active") === "active" ? "PASS" : "WARN";
@@ -7435,12 +7519,6 @@ function printJson(payload) {
7435
7519
  process.stdout.write(JSON.stringify(payload) + "\n");
7436
7520
  }
7437
7521
 
7438
- // src/hooks.ts
7439
- var { runSessionStart, runUserPrompt, runStop } = createHookRunners(
7440
- () => ({ home: identityHome(), copy: hostCopy() }),
7441
- { sessionStartOutput, stopOutput, printJson }
7442
- );
7443
-
7444
7522
  // src/always-on.ts
7445
7523
  function ensureAlwaysOn(opts = {}) {
7446
7524
  const home = identityHome();
@@ -7459,11 +7537,37 @@ function removeAlwaysOn() {
7459
7537
  uninstallService({ label: SERVICE_LABEL, home: identityHome() });
7460
7538
  }
7461
7539
 
7540
+ // src/hooks.ts
7541
+ var runners = createHookRunners(
7542
+ () => ({ home: identityHome(), copy: hostCopy() }),
7543
+ { sessionStartOutput, stopOutput, printJson }
7544
+ );
7545
+ function ensureAlwaysOnQuietly() {
7546
+ try {
7547
+ const r = ensureAlwaysOn();
7548
+ if (!r.ok && r.detail !== "switched off by the user") log.warn(`always-on not registered: ${r.detail}`);
7549
+ } catch (err) {
7550
+ log.warn(`always-on not registered: ${String(err)}`);
7551
+ }
7552
+ }
7553
+ async function runSessionStart() {
7554
+ ensureAlwaysOnQuietly();
7555
+ await runners.runSessionStart();
7556
+ }
7557
+ async function runUserPrompt() {
7558
+ ensureAlwaysOnQuietly();
7559
+ await runners.runUserPrompt();
7560
+ }
7561
+ async function runStop() {
7562
+ ensureAlwaysOnQuietly();
7563
+ await runners.runStop();
7564
+ }
7565
+
7462
7566
  // src/version.ts
7463
- var VERSION2 = "0.0.17";
7567
+ var VERSION3 = "0.0.17111";
7464
7568
 
7465
7569
  // src/index.ts
7466
- var USAGE = `agentchat-codex ${VERSION2} \u2014 AgentChat for Codex
7570
+ var USAGE = `agentchat-codex ${VERSION3} \u2014 AgentChat for Codex
7467
7571
 
7468
7572
  Usage:
7469
7573
  ${invocation()} wire Codex up
@@ -7516,7 +7620,7 @@ async function main(argv = process.argv.slice(2)) {
7516
7620
  const { values, positionals } = parsed;
7517
7621
  const [command, subcommand] = positionals;
7518
7622
  if (values.version) {
7519
- console.log(VERSION2);
7623
+ console.log(VERSION3);
7520
7624
  return 0;
7521
7625
  }
7522
7626
  if (values.help || command === "help") {
@@ -7639,6 +7743,7 @@ function runDaemonCmd(sub) {
7639
7743
  const line = {
7640
7744
  off: "always-on: off \u2014 this agent only answers while a session is open",
7641
7745
  idle: "always-on: idle \u2014 running, waiting for a sign-in",
7746
+ starting: "always-on: starting \u2014 the service is coming online",
7642
7747
  connected: "always-on: connected \u2713 \u2014 answering DMs with no session open",
7643
7748
  down: "always-on: NOT running \u2014 signed in, but no daemon is connected"
7644
7749
  }[state];