@standardagents/code 0.6.1 → 0.6.3
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 +49 -30
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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
|
}
|
|
@@ -3184,27 +3185,32 @@ var Tui = class _Tui {
|
|
|
3184
3185
|
const cols2 = Math.max(20, process.stdout.columns || 80);
|
|
3185
3186
|
const bg = "\x1B[48;5;238m";
|
|
3186
3187
|
const limit = Math.max(8, cols2 - 6);
|
|
3187
|
-
const
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
cur
|
|
3188
|
+
const wrapLine = (logical) => {
|
|
3189
|
+
const words = logical.replace(/[^\S\n]+/g, " ").trim().split(" ").filter(Boolean);
|
|
3190
|
+
if (!words.length) return [""];
|
|
3191
|
+
const out = [];
|
|
3192
|
+
let cur = "";
|
|
3193
|
+
for (let w of words) {
|
|
3194
|
+
while (w.length > limit) {
|
|
3195
|
+
if (cur) {
|
|
3196
|
+
out.push(cur);
|
|
3197
|
+
cur = "";
|
|
3198
|
+
}
|
|
3199
|
+
out.push(w.slice(0, limit));
|
|
3200
|
+
w = w.slice(limit);
|
|
3201
|
+
}
|
|
3202
|
+
if (!cur) cur = w;
|
|
3203
|
+
else if (cur.length + 1 + w.length <= limit) cur += " " + w;
|
|
3204
|
+
else {
|
|
3205
|
+
out.push(cur);
|
|
3206
|
+
cur = w;
|
|
3195
3207
|
}
|
|
3196
|
-
lines.push(w.slice(0, limit));
|
|
3197
|
-
w = w.slice(limit);
|
|
3198
|
-
}
|
|
3199
|
-
if (!cur) cur = w;
|
|
3200
|
-
else if (cur.length + 1 + w.length <= limit) cur += " " + w;
|
|
3201
|
-
else {
|
|
3202
|
-
lines.push(cur);
|
|
3203
|
-
cur = w;
|
|
3204
3208
|
}
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3209
|
+
if (cur || !out.length) out.push(cur);
|
|
3210
|
+
return out;
|
|
3211
|
+
};
|
|
3212
|
+
const lines = text.replace(/\r\n?/g, "\n").split("\n").flatMap(wrapLine);
|
|
3213
|
+
const innerW = 2 + Math.max(1, ...lines.map((l) => l.length));
|
|
3208
3214
|
this.print("");
|
|
3209
3215
|
lines.forEach((line, i) => {
|
|
3210
3216
|
const rowText = (i === 0 ? "\u276F " : " ") + line;
|
|
@@ -4252,20 +4258,30 @@ async function fetchLatest(currentVersion) {
|
|
|
4252
4258
|
clearTimeout(timeout);
|
|
4253
4259
|
}
|
|
4254
4260
|
}
|
|
4261
|
+
function isNewerVersion(candidate, current) {
|
|
4262
|
+
const parse = (v) => {
|
|
4263
|
+
const m = v.trim().replace(/^v/, "").match(/^(\d+)\.(\d+)\.(\d+)(?:-(.+))?$/);
|
|
4264
|
+
return m ? { nums: [Number(m[1]), Number(m[2]), Number(m[3])], pre: m[4] ?? null } : null;
|
|
4265
|
+
};
|
|
4266
|
+
const a = parse(candidate);
|
|
4267
|
+
const b = parse(current);
|
|
4268
|
+
if (!a || !b) return false;
|
|
4269
|
+
for (let i = 0; i < 3; i++) {
|
|
4270
|
+
if (a.nums[i] !== b.nums[i]) return a.nums[i] > b.nums[i];
|
|
4271
|
+
}
|
|
4272
|
+
return a.pre === null && b.pre !== null;
|
|
4273
|
+
}
|
|
4255
4274
|
async function checkForUpdate(currentVersion) {
|
|
4256
4275
|
if (!currentVersion) return null;
|
|
4257
4276
|
if (process.env.NO_UPDATE_NOTIFIER || process.env.CI) return null;
|
|
4258
4277
|
const cached = readCache();
|
|
4259
4278
|
if (cached && Date.now() - cached.timestamp < CACHE_TTL_MS) {
|
|
4260
|
-
|
|
4261
|
-
return { current: currentVersion, latest: cached.latest };
|
|
4262
|
-
}
|
|
4263
|
-
return null;
|
|
4279
|
+
return isNewerVersion(cached.latest, currentVersion) ? { current: currentVersion, latest: cached.latest } : null;
|
|
4264
4280
|
}
|
|
4265
4281
|
const latest = await fetchLatest(currentVersion);
|
|
4266
4282
|
if (!latest) return null;
|
|
4267
4283
|
writeCache(latest);
|
|
4268
|
-
return latest
|
|
4284
|
+
return isNewerVersion(latest, currentVersion) ? { current: currentVersion, latest } : null;
|
|
4269
4285
|
}
|
|
4270
4286
|
async function forceCheckForUpdate(currentVersion) {
|
|
4271
4287
|
if (!currentVersion) return null;
|
|
@@ -4273,7 +4289,7 @@ async function forceCheckForUpdate(currentVersion) {
|
|
|
4273
4289
|
const latest = await fetchLatest(currentVersion);
|
|
4274
4290
|
if (!latest) return null;
|
|
4275
4291
|
writeCache(latest);
|
|
4276
|
-
return latest
|
|
4292
|
+
return isNewerVersion(latest, currentVersion) ? { current: currentVersion, latest } : null;
|
|
4277
4293
|
}
|
|
4278
4294
|
function runUpdate(pm) {
|
|
4279
4295
|
return new Promise((resolve) => {
|
|
@@ -4742,14 +4758,17 @@ ${c.dim}Press Control-C again to exit${c.reset}
|
|
|
4742
4758
|
resumed = false;
|
|
4743
4759
|
}
|
|
4744
4760
|
}
|
|
4761
|
+
function isSilentMessage(m) {
|
|
4762
|
+
return m?.silent === true || m?.metadata?.silent === true;
|
|
4763
|
+
}
|
|
4745
4764
|
async function summarizeThreads(api, threads) {
|
|
4746
4765
|
return Promise.all(
|
|
4747
4766
|
threads.map(async (t) => {
|
|
4748
4767
|
let preview = "";
|
|
4749
4768
|
try {
|
|
4750
|
-
const msgs = await api.getMessages(t.id,
|
|
4751
|
-
const
|
|
4752
|
-
if (
|
|
4769
|
+
const msgs = await api.getMessages(t.id, 50, "desc");
|
|
4770
|
+
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];
|
|
4771
|
+
if (latest) preview = latest.text;
|
|
4753
4772
|
} catch {
|
|
4754
4773
|
}
|
|
4755
4774
|
const label = preview ? preview.length > 64 ? preview.slice(0, 63) + "\u2026" : preview : "(empty session)";
|