@agentchatme/codex 0.0.14 → 0.0.15

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.1/node_modules/@agentchatme/agent-core/dist/chunk-4UOOWYCI.js
8
+ // node_modules/.pnpm/@agentchatme+agent-core@0.0.11/node_modules/@agentchatme/agent-core/dist/chunk-NEGTEBFK.js
9
9
  import * as fs2 from "fs";
10
10
  import * as path2 from "path";
11
11
  import * as fs3 from "fs";
@@ -4303,17 +4303,39 @@ function clearAlwaysOnWanted(home) {
4303
4303
  function alwaysOnWanted(home) {
4304
4304
  return fs4.existsSync(path4.join(home, ALWAYS_ON_WANTED));
4305
4305
  }
4306
- function alwaysOnHealth(home) {
4307
- if (!alwaysOnWanted(home)) return { wanted: false, healthy: true };
4306
+ var ALWAYS_ON_OPTOUT = "always-on.optout";
4307
+ function markAlwaysOnOptOut(home) {
4308
+ try {
4309
+ fs4.mkdirSync(home, { recursive: true });
4310
+ fs4.writeFileSync(path4.join(home, ALWAYS_ON_OPTOUT), (/* @__PURE__ */ new Date()).toISOString());
4311
+ } catch {
4312
+ }
4313
+ }
4314
+ function clearAlwaysOnOptOut(home) {
4315
+ try {
4316
+ fs4.rmSync(path4.join(home, ALWAYS_ON_OPTOUT), { force: true });
4317
+ } catch {
4318
+ }
4319
+ }
4320
+ function alwaysOnOptedOut(home) {
4321
+ return fs4.existsSync(path4.join(home, ALWAYS_ON_OPTOUT));
4322
+ }
4323
+ function alwaysOnState(home) {
4324
+ if (!alwaysOnWanted(home)) return "off";
4325
+ if (!fs4.existsSync(path4.join(home, "credentials"))) return "idle";
4308
4326
  try {
4309
4327
  const age = Date.now() - fs4.statSync(path4.join(home, HEARTBEAT_FILE)).mtimeMs;
4310
- return { wanted: true, healthy: age <= HEARTBEAT_STALE_MS };
4328
+ return age <= HEARTBEAT_STALE_MS ? "connected" : "down";
4311
4329
  } catch {
4312
- return { wanted: true, healthy: false };
4330
+ return "down";
4313
4331
  }
4314
4332
  }
4333
+ function alwaysOnHealth(home) {
4334
+ const state = alwaysOnState(home);
4335
+ return { wanted: state !== "off", healthy: state !== "down" };
4336
+ }
4315
4337
 
4316
- // node_modules/.pnpm/@agentchatme+agent-core@0.0.1/node_modules/@agentchatme/agent-core/dist/index.js
4338
+ // node_modules/.pnpm/@agentchatme+agent-core@0.0.11/node_modules/@agentchatme/agent-core/dist/index.js
4317
4339
  import * as fs from "fs";
4318
4340
  import * as path from "path";
4319
4341
  import * as readline from "readline";
@@ -5601,7 +5623,7 @@ var HOUR = 60 * MIN;
5601
5623
  var DAY = 24 * HOUR;
5602
5624
  var MAX_ATTACHMENT_SIZE = 25 * 1024 * 1024;
5603
5625
 
5604
- // node_modules/.pnpm/@agentchatme+agent-core@0.0.1/node_modules/@agentchatme/agent-core/dist/index.js
5626
+ // node_modules/.pnpm/@agentchatme+agent-core@0.0.11/node_modules/@agentchatme/agent-core/dist/index.js
5605
5627
  import * as fs22 from "fs";
5606
5628
  import * as os from "os";
5607
5629
  import * as path22 from "path";
@@ -5809,7 +5831,8 @@ function formatRegistrationOffer(copy) {
5809
5831
  ` \u2022 They have its API key (ac_\u2026): ${invoke} login --api-key <ac_\u2026>`,
5810
5832
  ` \u2022 They lost the key: ${invoke} recover --email <email>, then relay the emailed 6-digit code: ${invoke} recover --code <code>`,
5811
5833
  "",
5812
- `Then, either way, turn on always-on so you stay reachable when they're away: ${invoke} daemon install (on by default; they can say "go session-only" any time \u2192 ${invoke} daemon disable).`,
5834
+ "",
5835
+ "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.",
5813
5836
  "",
5814
5837
  "Do not push the offer \u2014 one short ask is plenty. If declined, drop the topic for the rest of the session."
5815
5838
  ].join("\n");
@@ -7127,8 +7150,26 @@ var { runSessionStart, runUserPrompt, runStop } = createHookRunners(
7127
7150
  { sessionStartOutput, stopOutput, printJson }
7128
7151
  );
7129
7152
 
7153
+ // src/always-on.ts
7154
+ function ensureAlwaysOn(opts = {}) {
7155
+ const home = identityHome();
7156
+ if (!opts.force && alwaysOnOptedOut(home)) return { ok: false, detail: "switched off by the user" };
7157
+ if (!opts.force && alwaysOnWanted(home)) return { ok: true };
7158
+ try {
7159
+ const entry = copyDaemonBundle();
7160
+ installService({ label: SERVICE_LABEL, home, entry, env: serviceEnv() });
7161
+ markAlwaysOnWanted(home);
7162
+ return { ok: true };
7163
+ } catch (err) {
7164
+ return { ok: false, detail: String(err instanceof Error ? err.message : err) };
7165
+ }
7166
+ }
7167
+ function removeAlwaysOn() {
7168
+ uninstallService({ label: SERVICE_LABEL, home: identityHome() });
7169
+ }
7170
+
7130
7171
  // src/version.ts
7131
- var VERSION2 = "0.0.14";
7172
+ var VERSION2 = "0.0.15";
7132
7173
 
7133
7174
  // src/index.ts
7134
7175
  var USAGE = `agentchat-codex ${VERSION2} \u2014 AgentChat for Codex
@@ -7195,6 +7236,11 @@ async function main(argv = process.argv.slice(2)) {
7195
7236
  const handle = readCredentials(home)?.handle ?? null;
7196
7237
  try {
7197
7238
  const { actions, warnings } = installCodex(process.argv[1] ?? "", handle);
7239
+ const alwaysOn = ensureAlwaysOn();
7240
+ if (alwaysOn.ok) actions.push("always-on service registered");
7241
+ else if (alwaysOn.detail !== "switched off by the user") {
7242
+ warnings.push(`always-on could not be registered (${alwaysOn.detail}) \u2014 \`${invocation()} daemon install\` retries it`);
7243
+ }
7198
7244
  console.log(`${LABEL}: wired \u2713 (${actions.join(", ") || "no changes"})`);
7199
7245
  for (const w of warnings) console.log(` \u26A0 ${w}`);
7200
7246
  } catch (err) {
@@ -7271,41 +7317,34 @@ function runDaemonCmd(sub) {
7271
7317
  switch (sub) {
7272
7318
  case "install":
7273
7319
  case "enable": {
7274
- if (readCredentials(home) === null) {
7275
- console.error(`No AgentChat identity yet. Register first: ${invocation()} register`);
7276
- return 1;
7277
- }
7278
- try {
7279
- const entry = copyDaemonBundle();
7280
- installService({ label: SERVICE_LABEL, home, entry, env: serviceEnv() });
7281
- } catch (err) {
7282
- console.error(`Could not install the always-on service: ${String(err)}`);
7320
+ clearAlwaysOnOptOut(home);
7321
+ const r = ensureAlwaysOn({ force: true });
7322
+ if (!r.ok) {
7323
+ console.error(`Could not turn on always-on: ${r.detail}`);
7283
7324
  return 1;
7284
7325
  }
7285
- markAlwaysOnWanted(home);
7286
7326
  console.log(
7287
- [
7288
- `Always-on is ON for ${LABEL} \u2014 you'll answer DMs even when no session is open (while this machine is up).`,
7289
- `Prefer session-only? ${invocation()} daemon disable`
7290
- ].join("\n")
7327
+ `Always-on is ON for ${LABEL} \u2014 you'll answer DMs even when no session is open (while this machine is up).`
7291
7328
  );
7292
7329
  return 0;
7293
7330
  }
7294
7331
  case "disable":
7295
7332
  case "uninstall": {
7296
- uninstallService({ label: SERVICE_LABEL, home });
7333
+ removeAlwaysOn();
7297
7334
  clearAlwaysOnWanted(home);
7335
+ markAlwaysOnOptOut(home);
7298
7336
  console.log(`Always-on is OFF for ${LABEL} \u2014 messages queue for your next session; nothing is lost.`);
7299
7337
  return 0;
7300
7338
  }
7301
7339
  case "status": {
7302
- const h = alwaysOnHealth(home);
7303
- console.log(
7304
- [
7305
- serviceStatus({ label: SERVICE_LABEL, home }),
7306
- h.wanted ? h.healthy ? "always-on: wanted and beating \u2713" : "always-on: wanted but NOT beating \u2014 the daemon is down" : "always-on: not enabled (session-only)"
7307
- ].join("\n")
7308
- );
7340
+ const state = alwaysOnState(home);
7341
+ const line = {
7342
+ off: "always-on: off \u2014 this agent only answers while a session is open",
7343
+ idle: "always-on: idle \u2014 running, waiting for a sign-in",
7344
+ connected: "always-on: connected \u2713 \u2014 answering DMs with no session open",
7345
+ down: "always-on: NOT running \u2014 signed in, but no daemon is connected"
7346
+ }[state];
7347
+ console.log([serviceStatus({ label: SERVICE_LABEL, home }), line].join("\n"));
7309
7348
  return 0;
7310
7349
  }
7311
7350
  default: