@agentchatme/cli 0.0.132 → 0.0.133

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
@@ -4466,6 +4466,23 @@ async function getMeLite(cfg) {
4466
4466
  return null;
4467
4467
  }
4468
4468
  }
4469
+ async function markSessionActive(cfg, ttlSeconds) {
4470
+ try {
4471
+ await request(cfg, "PUT", "/v1/reply/active", ttlSeconds !== void 0 ? { ttl_seconds: ttlSeconds } : {});
4472
+ } catch (err) {
4473
+ log.warn(`reply-active mark failed (ignored): ${String(err)}`);
4474
+ }
4475
+ }
4476
+ async function claimReply(cfg, messageId, holder) {
4477
+ try {
4478
+ const data = await request(cfg, "POST", "/v1/reply/claim", { message_id: messageId, holder });
4479
+ const parsed = external_exports.object({ claimed: external_exports.boolean() }).passthrough().safeParse(data);
4480
+ return parsed.success ? parsed.data.claimed : true;
4481
+ } catch (err) {
4482
+ log.warn(`reply-claim failed (surfacing anyway): ${String(err)}`);
4483
+ return true;
4484
+ }
4485
+ }
4469
4486
  function lastDeliveryId(rows) {
4470
4487
  for (let i = rows.length - 1; i >= 0; i--) {
4471
4488
  const id = rows[i]?.delivery_id;
@@ -4582,6 +4599,18 @@ function ackableRows(rows) {
4582
4599
  }
4583
4600
  return usable;
4584
4601
  }
4602
+ async function claimContiguousPrefix(cfg, rows, holder) {
4603
+ const won = await Promise.all(rows.map((r) => claimReply(cfg, r.id, holder)));
4604
+ const prefix = [];
4605
+ for (let i = 0; i < rows.length; i++) {
4606
+ if (!won[i]) break;
4607
+ prefix.push(rows[i]);
4608
+ }
4609
+ if (prefix.length < rows.length) {
4610
+ log.info(`coexistence: daemon owns ${rows.length - prefix.length} row(s); surfacing ${prefix.length}`);
4611
+ }
4612
+ return prefix;
4613
+ }
4585
4614
  async function runSessionStartHook(platform) {
4586
4615
  try {
4587
4616
  if (hooksDisabled()) return;
@@ -4598,7 +4627,10 @@ async function runSessionStartHook(platform) {
4598
4627
  return;
4599
4628
  }
4600
4629
  const cfg = { apiKey: identity.apiKey, apiBase: identity.apiBase };
4601
- const rows = ackableRows(await syncPeek(cfg, { limit: SESSION_START_PEEK_LIMIT }));
4630
+ await markSessionActive(cfg);
4631
+ const peeked = ackableRows(await syncPeek(cfg, { limit: SESSION_START_PEEK_LIMIT }));
4632
+ if (peeked.length === 0) return;
4633
+ const rows = await claimContiguousPrefix(cfg, peeked, `session:${input.sessionId}`);
4602
4634
  if (rows.length === 0) return;
4603
4635
  const handle = await resolveHandle(cfg, identity.handle);
4604
4636
  const context = formatSessionStart(handle, rows);
@@ -4640,13 +4672,16 @@ async function runStopHook(platform) {
4640
4672
  const identity = resolveIdentity();
4641
4673
  if (identity === null) return;
4642
4674
  const sessionKey = `${platform}:${input.sessionId}`;
4675
+ const cfg = { apiKey: identity.apiKey, apiBase: identity.apiBase };
4676
+ await markSessionActive(cfg);
4643
4677
  const cap = maxContinuations();
4644
4678
  if (getContinuations(sessionKey) >= cap) {
4645
4679
  log.info(`stop hook: continuation cap (${cap}) reached for ${sessionKey}; leaving inbox queued`);
4646
4680
  return;
4647
4681
  }
4648
- const cfg = { apiKey: identity.apiKey, apiBase: identity.apiBase };
4649
- const rows = ackableRows(await syncPeek(cfg, { limit: STOP_PEEK_LIMIT }));
4682
+ const peeked = ackableRows(await syncPeek(cfg, { limit: STOP_PEEK_LIMIT }));
4683
+ if (peeked.length === 0) return;
4684
+ const rows = await claimContiguousPrefix(cfg, peeked, `session:${input.sessionId}`);
4650
4685
  if (rows.length === 0) return;
4651
4686
  recordContinuation(sessionKey);
4652
4687
  const handle = await resolveHandle(cfg, identity.handle);
@@ -4670,7 +4705,7 @@ import * as fs5 from "fs";
4670
4705
  import * as path6 from "path";
4671
4706
  import * as readline from "readline/promises";
4672
4707
 
4673
- // ../node_modules/.pnpm/agentchatme@1.0.2/node_modules/agentchatme/dist/index.js
4708
+ // ../node_modules/.pnpm/agentchatme@1.0.2_ws@8.21.1/node_modules/agentchatme/dist/index.js
4674
4709
  var ErrorCode = {
4675
4710
  AGENT_NOT_FOUND: "AGENT_NOT_FOUND",
4676
4711
  AGENT_SUSPENDED: "AGENT_SUSPENDED",
@@ -6843,7 +6878,7 @@ import * as fs7 from "fs";
6843
6878
  import * as path8 from "path";
6844
6879
 
6845
6880
  // src/version.ts
6846
- var VERSION2 = "0.0.132";
6881
+ var VERSION2 = "0.0.133";
6847
6882
 
6848
6883
  // src/commands/doctor.ts
6849
6884
  function fmt(check) {