superagent-skill 0.5.0 → 0.5.2

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 +4 -3
  2. package/lib/cli.mjs +62 -21
  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
 
@@ -153,8 +154,8 @@ pnpm install && pnpm build
153
154
  ln -sf "$PWD/bin/superagent.js" ~/.local/bin/superagent # a directory on PATH
154
155
  ```
155
156
 
156
- Start the loop from that directory: `superagent poll` keeps running, and `superagent poll --once` runs one round, which
157
- is what a cron entry calls each minute.
157
+ Start the loop from that directory: `superagent poll` keeps running, and `superagent poll . --once` runs one round,
158
+ waits for the turns it started, posts their reports, and exits — which is what a cron entry calls each minute.
158
159
 
159
160
  `checkout` names the repository the tickets change, and `executor.agent` names the coding agent. The Sources are
160
161
  optional, but at least one must be on; `github` and `gitlab` cannot both be, because one installation serves one forge.
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
  /**
@@ -2245,6 +2261,17 @@ var AgentExecutor = class {
2245
2261
  }
2246
2262
  });
2247
2263
  }
2264
+ /** Resolves when no turn runs and none waits for a slot, which a one-round process waits on before it exits. */
2265
+ idle() {
2266
+ if (!this.active.size && !this.pending.length) return Promise.resolve();
2267
+ return new Promise((resolve) => {
2268
+ const timer = setInterval(() => {
2269
+ if (this.active.size || this.pending.length) return;
2270
+ clearInterval(timer);
2271
+ resolve();
2272
+ }, 50);
2273
+ });
2274
+ }
2248
2275
  async execute(ticket, assignment, controller) {
2249
2276
  const { settings, runner, stateDir, accounts, site, repo, log } = this.options;
2250
2277
  const directory = ticket.execution?.directory ?? join(stateDir, "work", ticket.id);
@@ -2478,7 +2505,19 @@ async function runLoop(options) {
2478
2505
  const repository = github?.repository ?? gitlab?.project ?? settings.checkout;
2479
2506
  await writeEnvironment(accounts, settings.executor.blockedCommands);
2480
2507
  const standing = await standingRules();
2481
- const channel = outbox();
2508
+ const channel = outbox(repo);
2509
+ const destinations = {
2510
+ ...github ? { github: github.cli } : {},
2511
+ ...gitlab ? { gitlab: {
2512
+ cli: gitlab.cli,
2513
+ host: gitlab.host
2514
+ } } : {},
2515
+ ...feishu ? { feishu: feishu.cli } : {},
2516
+ ...twitter ? { twitter: twitter.cli } : {}
2517
+ };
2518
+ const markSent = (id) => {
2519
+ repo.setMeta(`outbox:${id}`, true);
2520
+ };
2482
2521
  const scope = sourceScope(settings);
2483
2522
  const decided = new WorkQueue();
2484
2523
  const finished = new WorkQueue();
@@ -2803,15 +2842,7 @@ async function runLoop(options) {
2803
2842
  inRound.clear();
2804
2843
  deliver(engine, repo, delivered, log);
2805
2844
  await repo.flush();
2806
- await send(channel, {
2807
- ...github ? { github: github.cli } : {},
2808
- ...gitlab ? { gitlab: {
2809
- cli: gitlab.cli,
2810
- host: gitlab.host
2811
- } } : {},
2812
- ...feishu ? { feishu: feishu.cli } : {},
2813
- ...twitter ? { twitter: twitter.cli } : {}
2814
- }, log, settings.attention);
2845
+ await send(channel, destinations, log, settings.attention, markSent);
2815
2846
  await repo.flush();
2816
2847
  await sync();
2817
2848
  } catch (error) {
@@ -2828,6 +2859,13 @@ async function runLoop(options) {
2828
2859
  left -= Date.now() - began;
2829
2860
  }
2830
2861
  }
2862
+ if (options.once && options.finish) {
2863
+ await executor.idle();
2864
+ deliver(engine, repo, delivered, log);
2865
+ await repo.flush();
2866
+ await send(channel, destinations, log, settings.attention, markSent);
2867
+ await repo.flush();
2868
+ }
2831
2869
  stop.abort();
2832
2870
  if (options.once && !process.env.VITEST) setImmediate(() => process.exit(process.exitCode ?? 0));
2833
2871
  }
@@ -3408,7 +3446,10 @@ async function poll(dir, once) {
3408
3446
  repo,
3409
3447
  signal: controller.signal,
3410
3448
  log,
3411
- ...once ? { once: true } : {}
3449
+ ...once ? {
3450
+ once: true,
3451
+ finish: true
3452
+ } : {}
3412
3453
  });
3413
3454
  return 0;
3414
3455
  } 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.2",
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": {