@standardagents/code 0.6.1 → 0.6.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.
package/dist/index.js CHANGED
@@ -233,9 +233,10 @@ var ApiClient = class {
233
233
  body: JSON.stringify(body)
234
234
  });
235
235
  }
236
- async getMessages(threadId, limit = 50) {
236
+ async getMessages(threadId, limit = 50, order) {
237
+ const orderParam = order ? `&order=${order}` : "";
237
238
  const res = await this.json(
238
- `/api/threads/${threadId}/messages?limit=${limit}`
239
+ `/api/threads/${threadId}/messages?limit=${limit}${orderParam}`
239
240
  );
240
241
  return Array.isArray(res) ? res : res.messages || [];
241
242
  }
@@ -4252,20 +4253,30 @@ async function fetchLatest(currentVersion) {
4252
4253
  clearTimeout(timeout);
4253
4254
  }
4254
4255
  }
4256
+ function isNewerVersion(candidate, current) {
4257
+ const parse = (v) => {
4258
+ const m = v.trim().replace(/^v/, "").match(/^(\d+)\.(\d+)\.(\d+)(?:-(.+))?$/);
4259
+ return m ? { nums: [Number(m[1]), Number(m[2]), Number(m[3])], pre: m[4] ?? null } : null;
4260
+ };
4261
+ const a = parse(candidate);
4262
+ const b = parse(current);
4263
+ if (!a || !b) return false;
4264
+ for (let i = 0; i < 3; i++) {
4265
+ if (a.nums[i] !== b.nums[i]) return a.nums[i] > b.nums[i];
4266
+ }
4267
+ return a.pre === null && b.pre !== null;
4268
+ }
4255
4269
  async function checkForUpdate(currentVersion) {
4256
4270
  if (!currentVersion) return null;
4257
4271
  if (process.env.NO_UPDATE_NOTIFIER || process.env.CI) return null;
4258
4272
  const cached = readCache();
4259
4273
  if (cached && Date.now() - cached.timestamp < CACHE_TTL_MS) {
4260
- if (cached.latest !== currentVersion) {
4261
- return { current: currentVersion, latest: cached.latest };
4262
- }
4263
- return null;
4274
+ return isNewerVersion(cached.latest, currentVersion) ? { current: currentVersion, latest: cached.latest } : null;
4264
4275
  }
4265
4276
  const latest = await fetchLatest(currentVersion);
4266
4277
  if (!latest) return null;
4267
4278
  writeCache(latest);
4268
- return latest !== currentVersion ? { current: currentVersion, latest } : null;
4279
+ return isNewerVersion(latest, currentVersion) ? { current: currentVersion, latest } : null;
4269
4280
  }
4270
4281
  async function forceCheckForUpdate(currentVersion) {
4271
4282
  if (!currentVersion) return null;
@@ -4273,7 +4284,7 @@ async function forceCheckForUpdate(currentVersion) {
4273
4284
  const latest = await fetchLatest(currentVersion);
4274
4285
  if (!latest) return null;
4275
4286
  writeCache(latest);
4276
- return latest !== currentVersion ? { current: currentVersion, latest } : null;
4287
+ return isNewerVersion(latest, currentVersion) ? { current: currentVersion, latest } : null;
4277
4288
  }
4278
4289
  function runUpdate(pm) {
4279
4290
  return new Promise((resolve) => {
@@ -4742,14 +4753,17 @@ ${c.dim}Press Control-C again to exit${c.reset}
4742
4753
  resumed = false;
4743
4754
  }
4744
4755
  }
4756
+ function isSilentMessage(m) {
4757
+ return m?.silent === true || m?.metadata?.silent === true;
4758
+ }
4745
4759
  async function summarizeThreads(api, threads) {
4746
4760
  return Promise.all(
4747
4761
  threads.map(async (t) => {
4748
4762
  let preview = "";
4749
4763
  try {
4750
- const msgs = await api.getMessages(t.id, 30);
4751
- const users = msgs.filter((m) => m.role === "user" && typeof m.content === "string" && m.content.trim()).sort((a, b) => (a.created_at ?? 0) - (b.created_at ?? 0));
4752
- if (users[0]) preview = String(users[0].content).replace(/\s+/g, " ").trim();
4764
+ const msgs = await api.getMessages(t.id, 50, "desc");
4765
+ const latest = msgs.filter((m) => m.role === "user" && m.status !== "pending" && !isSilentMessage(m)).map((m) => ({ at: m.created_at ?? 0, text: messageText(m.content).replace(/\s+/g, " ").trim() })).filter((m) => m.text.length > 0).sort((a, b) => b.at - a.at)[0];
4766
+ if (latest) preview = latest.text;
4753
4767
  } catch {
4754
4768
  }
4755
4769
  const label = preview ? preview.length > 64 ? preview.slice(0, 63) + "\u2026" : preview : "(empty session)";