opencode-forgekeeper 5.0.0 → 5.0.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 (2) hide show
  1. package/dist/index.js +42 -13
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -6092,12 +6092,15 @@ function closedFeedback(lookup) {
6092
6092
  // packages/forgekeeper/src/feedback-discovery.ts
6093
6093
  var RECENT_ACTIVITY = 3 * 24 * 60 * 60000;
6094
6094
  var DISCOVERY_INTERVAL = 5 * 60000;
6095
+ var RECONCILE_INTERVAL2 = 24 * 60 * 60000;
6095
6096
  function createFeedbackDiscovery(options) {
6096
6097
  let stopped = false;
6097
6098
  let running;
6098
6099
  let full = false;
6099
6100
  const pending = new Set;
6100
- const watched = new Set;
6101
+ const activityBySession = new Map;
6102
+ const retry = new Set;
6103
+ let scannedAt;
6101
6104
  const refresh = (id) => {
6102
6105
  if (stopped)
6103
6106
  return Promise.resolve();
@@ -6114,34 +6117,52 @@ function createFeedbackDiscovery(options) {
6114
6117
  const changed = [...pending];
6115
6118
  pending.clear();
6116
6119
  if (await options.paused()) {
6117
- watched.clear();
6120
+ scannedAt = undefined;
6121
+ activityBySession.clear();
6122
+ retry.clear();
6118
6123
  if (!stopped)
6119
6124
  options.watch([]);
6120
6125
  continue;
6121
6126
  }
6122
- const ids = scan ? await options.candidates() : changed;
6123
- if (scan)
6124
- watched.clear();
6125
- await mapLimit(ids, CONCURRENCY, async (id2) => {
6127
+ const at = (options.now ?? Date.now)();
6128
+ const rebuild = scan && (scannedAt === undefined || at - scannedAt >= RECONCILE_INTERVAL2 || at < scannedAt);
6129
+ const ids = rebuild ? await options.candidates() : new Set([...changed, ...scan ? retry : []]);
6130
+ if (rebuild) {
6131
+ activityBySession.clear();
6132
+ retry.clear();
6133
+ scannedAt = at;
6134
+ }
6135
+ await mapLimit([...ids], CONCURRENCY, async (id2) => {
6126
6136
  if (stopped)
6127
6137
  return;
6128
6138
  try {
6129
- watched.delete(id2);
6130
- if (!scan && !await options.candidate(id2))
6139
+ activityBySession.delete(id2);
6140
+ retry.delete(id2);
6141
+ if (!rebuild && !await options.candidate(id2))
6131
6142
  return;
6132
6143
  const session = await options.session(id2);
6133
6144
  if (session.parentID || session.time.archived !== undefined || session.location.directory !== options.directory || linkedOwner({ ...session, id: session.id ?? id2 }))
6134
6145
  return;
6135
6146
  const activity2 = await options.activity(id2);
6136
- const age = (options.now ?? Date.now)() - (activity2 ?? -Infinity);
6137
- if (age >= 0 && age <= RECENT_ACTIVITY)
6138
- watched.add(id2);
6147
+ if (activity2 !== undefined)
6148
+ activityBySession.set(id2, activity2);
6139
6149
  } catch (error) {
6150
+ if (options.missing?.(error))
6151
+ return;
6152
+ retry.add(id2);
6140
6153
  options.error(error);
6141
6154
  }
6142
6155
  });
6156
+ const watched = [];
6157
+ const now = (options.now ?? Date.now)();
6158
+ for (const [id2, activity2] of activityBySession) {
6159
+ if (now - activity2 > RECENT_ACTIVITY)
6160
+ activityBySession.delete(id2);
6161
+ else if (activity2 <= now)
6162
+ watched.push(id2);
6163
+ }
6143
6164
  if (!stopped)
6144
- options.watch([...watched]);
6165
+ options.watch(watched);
6145
6166
  }
6146
6167
  })().catch(options.error).finally(() => {
6147
6168
  running = undefined;
@@ -7499,6 +7520,7 @@ async function setupStatus(ctx, settings, deps, host2) {
7499
7520
  const hasTarget = (targets) => !!classifyTargets(targetOutput(targets))?.some((target2) => target2.kind === "merge-request");
7500
7521
  const discovery = createFeedbackDiscovery({
7501
7522
  directory,
7523
+ missing: missingSession,
7502
7524
  candidate: async (id) => hasTarget(await host2.storedTargets(id)),
7503
7525
  candidates: async () => (await scanAll("sessions/")).flatMap(({ key: key2, value }) => {
7504
7526
  const targets = value.targets ?? [];
@@ -8223,6 +8245,11 @@ async function setupServer(ctx, lookups, status2) {
8223
8245
  types: [
8224
8246
  "session.renamed",
8225
8247
  "session.moved",
8248
+ "session.archived",
8249
+ "session.unarchived",
8250
+ "session.deleted",
8251
+ "session.compaction.ended",
8252
+ "session.execution.started",
8226
8253
  "session.execution.succeeded",
8227
8254
  "session.execution.failed",
8228
8255
  "session.execution.interrupted",
@@ -8239,10 +8266,12 @@ async function setupServer(ctx, lookups, status2) {
8239
8266
  watcher?.titleChanged(sessionID).catch(() => {});
8240
8267
  if (type === "session.moved" && sessionID)
8241
8268
  watcher?.sessionMoved(sessionID);
8269
+ if (sessionID && (type === "session.archived" || type === "session.unarchived" || type === "session.deleted" || type === "session.compaction.ended" || type === "session.execution.started" || type === "session.execution.interrupted"))
8270
+ watcher?.discovery.refresh(sessionID);
8242
8271
  if (sessionID && (type === "session.execution.succeeded" || type === "session.execution.failed"))
8243
8272
  watcher?.turnEnded(sessionID);
8244
8273
  const reason2 = event.data?.reason;
8245
- if (sessionID && type.startsWith("session.execution.") && !(type === "session.execution.interrupted" && reason2 === "shutdown"))
8274
+ if (sessionID && (type === "session.execution.succeeded" || type === "session.execution.failed" || type === "session.execution.interrupted") && !(type === "session.execution.interrupted" && reason2 === "shutdown"))
8246
8275
  watcher?.executionEnded(sessionID, type === "session.execution.succeeded" ? "succeeded" : "failed", event.created ?? Date.now());
8247
8276
  if (type === "vcs.branch.updated") {
8248
8277
  const location = event.location;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-forgekeeper",
3
- "version": "5.0.0",
3
+ "version": "5.0.1",
4
4
  "description": "OpenCode plugin that tracks each session's GitHub and GitLab issues and PRs/MRs: title prefixes, a PR/MR status footer, and review notifications",
5
5
  "author": {
6
6
  "name": "Pedro Pombeiro",