@standardagents/code 0.6.0 → 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
  }
@@ -796,13 +797,7 @@ var Bridge = class {
796
797
  this.hooks.onStatus?.(callKey, null);
797
798
  }
798
799
  if (result.ok) {
799
- const display = req.tool === "bash" ? `bash: ${highlightBash(oneLineCommand(String(req.args.command ?? ""), Math.max(40, (process.stdout.columns || 80) - 20)))}` : summary;
800
- let detail;
801
- if (req.tool === "edit_file") {
802
- detail = diffLines(String(req.args.old_string ?? ""), String(req.args.new_string ?? ""));
803
- } else if (req.tool === "write_file") {
804
- detail = newFileLines(String(req.args.content ?? ""));
805
- }
800
+ const { display, detail } = activityPresentation(req, summary);
806
801
  this.hooks.onActivity(`\u2713 ${display}${detailSuffix(req.tool, result.result)}`, detail);
807
802
  this.respond(req, true, result.result ?? "");
808
803
  } else {
@@ -820,6 +815,35 @@ function permissionKey(req) {
820
815
  if (action === "list_tools") return `mcp:${server}/list`;
821
816
  return `mcp:${server}/${String(a.tool || "?")}`;
822
817
  }
818
+ var DIM2 = "\x1B[2m";
819
+ var RESET2 = "\x1B[0m";
820
+ function activityPresentation(req, summary) {
821
+ const a = req.args;
822
+ const cols2 = Math.max(40, process.stdout.columns || 80);
823
+ if (req.tool === "bash") {
824
+ return { display: `bash: ${highlightBash(oneLineCommand(String(a.command ?? ""), cols2 - 20))}` };
825
+ }
826
+ if (req.tool === "edit_file") {
827
+ return { display: summary, detail: diffLines(String(a.old_string ?? ""), String(a.new_string ?? "")) };
828
+ }
829
+ if (req.tool === "write_file") {
830
+ return { display: summary, detail: newFileLines(String(a.content ?? "")) };
831
+ }
832
+ if (req.tool === "background_process") {
833
+ const action = String(a.action || "list");
834
+ const id = a.id ? ` ${String(a.id)}` : "";
835
+ const display = action === "start" ? "bg start" : `bg ${action}${id}`;
836
+ const detail = [];
837
+ if (action === "start" && a.command) {
838
+ detail.push(` ${DIM2}${oneLineCommand(String(a.command), cols2 - 8)}${RESET2}`);
839
+ }
840
+ if (typeof a.description === "string" && a.description.trim()) {
841
+ detail.push(` ${DIM2}${oneLineCommand(a.description, cols2 - 8)}${RESET2}`);
842
+ }
843
+ return { display, detail: detail.length ? detail : void 0 };
844
+ }
845
+ return { display: summary };
846
+ }
823
847
  function describe(req) {
824
848
  const a = req.args;
825
849
  switch (req.tool) {
@@ -846,6 +870,12 @@ function describe(req) {
846
870
  return `skill ${a.skill}: run ${a.entry}`;
847
871
  case "bash":
848
872
  return `bash: ${oneLineCommand(String(a.command ?? ""), 80)}`;
873
+ case "background_process": {
874
+ const action = String(a.action || "list");
875
+ if (action === "start") return `bg start: ${oneLineCommand(String(a.command ?? ""), 80)}`;
876
+ if (action === "list") return "bg list";
877
+ return `bg ${action}${a.id ? ` ${String(a.id)}` : ""}`;
878
+ }
849
879
  default:
850
880
  return `${req.tool} ${JSON.stringify(a).slice(0, 80)}`;
851
881
  }
@@ -1889,7 +1919,7 @@ var LAZY_MS = 320;
1889
1919
  var LAZY_PERIOD = 200;
1890
1920
  var FAST_PERIOD = 70;
1891
1921
  var BOLD = "\x1B[1m";
1892
- var DIM2 = "\x1B[2m";
1922
+ var DIM3 = "\x1B[2m";
1893
1923
  var OFF = "\x1B[22m";
1894
1924
  function glyphAt(slot, bucket) {
1895
1925
  let h = (slot + 1) * 2654435761 ^ (bucket + 1) * 40503;
@@ -1961,7 +1991,7 @@ var WordMill = class {
1961
1991
  } else if (t < s.land) {
1962
1992
  const age = t - s.start;
1963
1993
  const period = age < LAZY_MS ? LAZY_PERIOD : FAST_PERIOD;
1964
- out += `${DIM2}${glyphAt(i, Math.floor(t / period))}${OFF}`;
1994
+ out += `${DIM3}${glyphAt(i, Math.floor(t / period))}${OFF}`;
1965
1995
  } else {
1966
1996
  const ch = target[i];
1967
1997
  if (ch) out += `${BOLD}${ch}${OFF}`;
@@ -3053,7 +3083,8 @@ var Tui = class _Tui {
3053
3083
  const t = s.length > max ? s.slice(0, Math.max(0, max - 1)) + "\u2026" : s;
3054
3084
  return wrap ? `${lead}${wrap}${t}${C.reset}` : `${lead}${t}`;
3055
3085
  };
3056
- const realLines = (text) => text.replace(/\r/g, "").split("\n").filter((l) => l.trim() !== "");
3086
+ const leakedMarkup = /<\/?[||]DSML[||]|^\s*\[\/?SESSION\]\s*<?\s*$/;
3087
+ const realLines = (text) => text.replace(/\r/g, "").split("\n").filter((l) => l.trim() !== "" && !leakedMarkup.test(l));
3057
3088
  if (this.streamResponse) {
3058
3089
  const all = realLines(this.streamResponse);
3059
3090
  const shown = all.slice(-20);
@@ -3501,7 +3532,7 @@ function appendHistory(store, threadId, history, text) {
3501
3532
  var ESC = "\x1B[";
3502
3533
  var R = ESC + "0m";
3503
3534
  var BOLD2 = ESC + "1m";
3504
- var DIM3 = ESC + "2m";
3535
+ var DIM4 = ESC + "2m";
3505
3536
  var ITAL = ESC + "3m";
3506
3537
  var UNDER = ESC + "4m";
3507
3538
  var TEAL = ESC + "38;5;37m";
@@ -3523,11 +3554,11 @@ function inline(s) {
3523
3554
  });
3524
3555
  s = s.replace(
3525
3556
  /\[([^\]]+)\]\(([^)\s]+)\)/g,
3526
- (_, text, url) => `${CYAN}${UNDER}${text}${R} ${DIM3}${url}${R}`
3557
+ (_, text, url) => `${CYAN}${UNDER}${text}${R} ${DIM4}${url}${R}`
3527
3558
  );
3528
3559
  s = s.replace(/\*\*([^*]+)\*\*/g, (_, t) => `${BOLD2}${t}${R}`);
3529
3560
  s = s.replace(/\*([^*\n]+)\*/g, (_, t) => `${ITAL}${t}${R}`);
3530
- s = s.replace(/~~([^~]+)~~/g, (_, t) => `${DIM3}${t}${R}`);
3561
+ s = s.replace(/~~([^~]+)~~/g, (_, t) => `${DIM4}${t}${R}`);
3531
3562
  s = s.replace(/\x00(\d+)\x00/g, (_, i) => `${TEAL}${codes[+i].replace(/ /g, String.fromCharCode(160))}${R}`);
3532
3563
  return s;
3533
3564
  }
@@ -3632,7 +3663,7 @@ function renderMarkdown(src, cols2 = 80) {
3632
3663
  const quote = line.match(/^\s*>\s?(.*)$/);
3633
3664
  if (quote) {
3634
3665
  for (const ln of wrapStyled(inline(quote[1]), Math.max(8, cols2 - 2))) {
3635
- out.push(`${GRAY}\u2502${R} ${DIM3}${ln}${R}`);
3666
+ out.push(`${GRAY}\u2502${R} ${DIM4}${ln}${R}`);
3636
3667
  }
3637
3668
  i++;
3638
3669
  continue;
@@ -4098,7 +4129,7 @@ var REGISTRY_URL = `https://registry.npmjs.org/${encodeURIComponent(PKG_NAME)}`;
4098
4129
  var CACHE_REL_DIR = ".config/standardagents-cli";
4099
4130
  var CACHE_FILE = "update-check.json";
4100
4131
  var STATE_FILE = "auto-update.json";
4101
- var CACHE_TTL_MS = 1e3 * 60 * 60 * 24;
4132
+ var CACHE_TTL_MS = 1e3 * 60 * 60 * 6;
4102
4133
  var CHECK_TIMEOUT_MS = 4e3;
4103
4134
  var IN_FLIGHT_TTL_MS = 15 * 60 * 1e3;
4104
4135
  function cacheDir() {
@@ -4222,20 +4253,30 @@ async function fetchLatest(currentVersion) {
4222
4253
  clearTimeout(timeout);
4223
4254
  }
4224
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
+ }
4225
4269
  async function checkForUpdate(currentVersion) {
4226
4270
  if (!currentVersion) return null;
4227
4271
  if (process.env.NO_UPDATE_NOTIFIER || process.env.CI) return null;
4228
4272
  const cached = readCache();
4229
4273
  if (cached && Date.now() - cached.timestamp < CACHE_TTL_MS) {
4230
- if (cached.latest !== currentVersion) {
4231
- return { current: currentVersion, latest: cached.latest };
4232
- }
4233
- return null;
4274
+ return isNewerVersion(cached.latest, currentVersion) ? { current: currentVersion, latest: cached.latest } : null;
4234
4275
  }
4235
4276
  const latest = await fetchLatest(currentVersion);
4236
4277
  if (!latest) return null;
4237
4278
  writeCache(latest);
4238
- return latest !== currentVersion ? { current: currentVersion, latest } : null;
4279
+ return isNewerVersion(latest, currentVersion) ? { current: currentVersion, latest } : null;
4239
4280
  }
4240
4281
  async function forceCheckForUpdate(currentVersion) {
4241
4282
  if (!currentVersion) return null;
@@ -4243,7 +4284,7 @@ async function forceCheckForUpdate(currentVersion) {
4243
4284
  const latest = await fetchLatest(currentVersion);
4244
4285
  if (!latest) return null;
4245
4286
  writeCache(latest);
4246
- return latest !== currentVersion ? { current: currentVersion, latest } : null;
4287
+ return isNewerVersion(latest, currentVersion) ? { current: currentVersion, latest } : null;
4247
4288
  }
4248
4289
  function runUpdate(pm) {
4249
4290
  return new Promise((resolve) => {
@@ -4708,17 +4749,21 @@ ${c.dim}Press Control-C again to exit${c.reset}
4708
4749
  await runInteractive(tui, api, threadId, projectDir, machine, resumed, historySeed);
4709
4750
  historySeed = threadId;
4710
4751
  threadId = await api.createThread(AGENT_ID, tags);
4752
+ await api.kvSet(threadId, "lease_supersedes", historySeed);
4711
4753
  resumed = false;
4712
4754
  }
4713
4755
  }
4756
+ function isSilentMessage(m) {
4757
+ return m?.silent === true || m?.metadata?.silent === true;
4758
+ }
4714
4759
  async function summarizeThreads(api, threads) {
4715
4760
  return Promise.all(
4716
4761
  threads.map(async (t) => {
4717
4762
  let preview = "";
4718
4763
  try {
4719
- const msgs = await api.getMessages(t.id, 30);
4720
- 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));
4721
- 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;
4722
4767
  } catch {
4723
4768
  }
4724
4769
  const label = preview ? preview.length > 64 ? preview.slice(0, 63) + "\u2026" : preview : "(empty session)";