superagent-skill 0.5.0 → 0.5.1

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.
Files changed (3) hide show
  1. package/README.md +2 -1
  2. package/lib/cli.mjs +28 -12
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -136,7 +136,8 @@ Done and tested: the domain, file-backed state, the settings file, three agent r
136
136
  the GitHub notification poller, the GitLab Source (to-dos, merge request review and merge), the Feishu Source, worktree
137
137
  creation per ticket, the round loop, and delivery of the agent's report back to the conversation. The Feishu path is
138
138
  proven with a stand-in `lark-cli` and once end to end against a real Feishu bot; the GitLab path is proven with a
139
- stand-in `glab` and against the API's documented shapes, not yet against a live GitLab account.
139
+ stand-in `glab` and on GitLab 19.4.3 (`gitlab.sitinai.com`): an issue to-do became a ticket and a note, and a merge
140
+ request was reviewed, squash-merged and answered.
140
141
 
141
142
  ## Install once
142
143
 
package/lib/cli.mjs CHANGED
@@ -2010,12 +2010,11 @@ function deliver(engine, repo, delivered, log) {
2010
2010
  delivered.add(`${ticket.id}@${report.at}`);
2011
2011
  const text = deliverable(String(report.summary));
2012
2012
  try {
2013
- engine.reply({
2013
+ if (!engine.reply({
2014
2014
  purpose: "result",
2015
2015
  ticketId: ticket.id,
2016
2016
  text
2017
- });
2018
- log(`Answered ticket ${ticket.id} in its conversation`);
2017
+ }).reused) log(`Answered ticket ${ticket.id} in its conversation`);
2019
2018
  } catch (error) {
2020
2019
  log(`Could not answer ticket ${ticket.id}: ${error.message}`);
2021
2020
  }
@@ -2081,9 +2080,13 @@ function record(engine, repo, finished, log) {
2081
2080
  }
2082
2081
  }
2083
2082
  /** Posts the messages the Engine queued, one comment per message. */
2084
- async function send(channel, clis, log, attentionConfig) {
2083
+ async function send(channel, clis, log, attentionConfig, sent) {
2085
2084
  const quiet = isQuietHours(/* @__PURE__ */ new Date(), attentionConfig?.quietHours);
2086
2085
  const present = await isUserPresent(attentionConfig?.idleSecondsThreshold);
2086
+ const done = (message) => {
2087
+ channel.withdraw(message.id);
2088
+ sent?.(message.id);
2089
+ };
2087
2090
  for (const message of channel.drain()) {
2088
2091
  if (message.channel.source === "twitter") {
2089
2092
  const address = message.channel.address;
@@ -2095,6 +2098,7 @@ async function send(channel, clis, log, attentionConfig) {
2095
2098
  try {
2096
2099
  await replyTweet(clis.twitter, address.tweetUrl, message.text);
2097
2100
  log(`Replied to tweet ${address.tweetUrl}`);
2101
+ done(message);
2098
2102
  } catch (error) {
2099
2103
  log(`Could not reply to tweet ${address.tweetUrl}: ${error.message}`);
2100
2104
  }
@@ -2111,6 +2115,7 @@ async function send(channel, clis, log, attentionConfig) {
2111
2115
  else log(`User is away; dispatched notification to mobile in ${address.chatId}`);
2112
2116
  try {
2113
2117
  await reply(clis.feishu, address.messageId, message.text, message.id);
2118
+ done(message);
2114
2119
  } catch (error) {
2115
2120
  log(`Could not answer in ${address.chatId}: ${error.message}`);
2116
2121
  }
@@ -2135,6 +2140,7 @@ async function send(channel, clis, log, attentionConfig) {
2135
2140
  body: message.text
2136
2141
  });
2137
2142
  log(`Posted a note on ${url}`);
2143
+ done(message);
2138
2144
  } catch (error) {
2139
2145
  log(`Could not post on ${url}: ${error.message}`);
2140
2146
  }
@@ -2154,6 +2160,7 @@ async function send(channel, clis, log, attentionConfig) {
2154
2160
  `body=${message.text}`
2155
2161
  ]);
2156
2162
  log(`Posted a message on ${address.repository}#${address.number}`);
2163
+ done(message);
2157
2164
  } catch (error) {
2158
2165
  log(`Could not post on ${address.repository}#${address.number}: ${error.message}`);
2159
2166
  }
@@ -2164,19 +2171,28 @@ const pollKey = "github:poll";
2164
2171
  const seenKey = (id) => `github:seen:${id}`;
2165
2172
  /** Lines one round reads from the stream at most, so a chat that keeps talking does not hold a round open. */
2166
2173
  const MAX_LINES = 500;
2167
- /** A failed save of the last round must not stop the next one. */
2168
- function outbox() {
2174
+ /**
2175
+ * The outbox of one run, plus the ids earlier runs already posted.
2176
+ *
2177
+ * A message goes out once, and a process that started later must know it: the id is deterministic
2178
+ * (`key('reply', triggerId, text)`), but the map alone forgets it at exit, so `poll --once` from cron re-posted every
2179
+ * ready report. The id of a posted message is kept in the state directory for the same reason the ticket is.
2180
+ */
2181
+ function outbox(repo) {
2169
2182
  const messages = /* @__PURE__ */ new Map();
2183
+ const sentKey = (id) => `outbox:${id}`;
2184
+ const sent = (id) => repo.getMeta(sentKey(id)) === true;
2170
2185
  return {
2171
2186
  send: (message) => {
2172
- if (!messages.has(message.id)) messages.set(message.id, message);
2187
+ if (!messages.has(message.id) && !sent(message.id)) messages.set(message.id, message);
2173
2188
  },
2174
- status: (id) => messages.has(id) ? "pending" : void 0,
2189
+ status: (id) => messages.has(id) ? "pending" : sent(id) ? "sent" : void 0,
2175
2190
  withdraw: (id) => {
2176
2191
  messages.delete(id);
2177
2192
  },
2178
- /** Everything queued so far, for the caller to deliver in order. */
2179
- drain: () => [...messages.values()].sort((a, b) => a.id.localeCompare(b.id))
2193
+ /** A caller posts what is waiting; the message stays until the post succeeds, so a failed one is retried next round. */
2194
+ drain: () => [...messages.values()].sort((a, b) => a.id.localeCompare(b.id)),
2195
+ sent
2180
2196
  };
2181
2197
  }
2182
2198
  /**
@@ -2478,7 +2494,7 @@ async function runLoop(options) {
2478
2494
  const repository = github?.repository ?? gitlab?.project ?? settings.checkout;
2479
2495
  await writeEnvironment(accounts, settings.executor.blockedCommands);
2480
2496
  const standing = await standingRules();
2481
- const channel = outbox();
2497
+ const channel = outbox(repo);
2482
2498
  const scope = sourceScope(settings);
2483
2499
  const decided = new WorkQueue();
2484
2500
  const finished = new WorkQueue();
@@ -2811,7 +2827,7 @@ async function runLoop(options) {
2811
2827
  } } : {},
2812
2828
  ...feishu ? { feishu: feishu.cli } : {},
2813
2829
  ...twitter ? { twitter: twitter.cli } : {}
2814
- }, log, settings.attention);
2830
+ }, log, settings.attention, (id) => repo.setMeta(`outbox:${id}`, true));
2815
2831
  await repo.flush();
2816
2832
  await sync();
2817
2833
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "superagent-skill",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "type": "module",
5
5
  "description": "A headless, file-backed agent that turns requests from GitHub issues, Feishu chats, or Twitter mentions into tickets and runs each ticket on a configurable coding agent: Claude Code, Codex or opencode.",
6
6
  "bin": {