agent.libx.js 0.94.3 → 0.94.4

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/cli.js CHANGED
@@ -6576,11 +6576,12 @@ var SessionStore = class {
6576
6576
  constructor(cwd) {
6577
6577
  this.dir = join6(cwd, ".agent", "sessions");
6578
6578
  }
6579
- /** Sortable, human-readable id: `YYYYMMDD-HHMMSS-mmm`. */
6580
- newId(now5 = Date.now()) {
6579
+ /** Sortable, human-readable id: `YYYYMMDD-HHMMSS-<folder>`. */
6580
+ newId(now5 = Date.now(), cwd) {
6581
6581
  const d = new Date(now5);
6582
6582
  const p = (n, w = 2) => String(n).padStart(w, "0");
6583
- return `${d.getFullYear()}${p(d.getMonth() + 1)}${p(d.getDate())}-${p(d.getHours())}${p(d.getMinutes())}${p(d.getSeconds())}-${p(d.getMilliseconds(), 3)}`;
6583
+ const slug2 = (cwd ?? process.cwd()).split("/").pop()?.replace(/[^A-Za-z0-9_-]/g, "") || "session";
6584
+ return `${d.getFullYear()}${p(d.getMonth() + 1)}${p(d.getDate())}-${p(d.getHours())}${p(d.getMinutes())}${p(d.getSeconds())}-${slug2}`;
6584
6585
  }
6585
6586
  /** A session id must be one safe path segment — blocks `../`-style traversal via --resume/load/save. */
6586
6587
  safeId(id) {
@@ -9167,7 +9168,7 @@ async function runTurn(agent, store, session, task, cp, cwd = process.cwd(), sen
9167
9168
  const lastUser = res.messages.map((m2) => m2.role).lastIndexOf("user");
9168
9169
  const tools = res.messages.slice(lastUser).filter((m2) => m2.role === "tool").length;
9169
9170
  const ok = res.finishReason === "stop";
9170
- const shortId = session.meta.id.slice(-10);
9171
+ const shortId = session.meta.id.replace(/^\d{8}-/, "");
9171
9172
  const silentAbort = res.finishReason === "aborted" && !res.usage?.totalTokens;
9172
9173
  if (!silentAbort)
9173
9174
  err("\n" + (process.stderr.isTTY ? "\r\x1B[0J" : "") + (ok ? green(" \u2713 done") : red(` \u2717 ${res.finishReason}`)) + dim(` \xB7 ${res.steps} steps \xB7 ${tools} tools \xB7 ${tok}${secs}s \xB7 ${shortId}
@@ -9203,7 +9204,7 @@ function startSession(args, store, agent, cwd) {
9203
9204
  agent.transcript = data.messages;
9204
9205
  if (args.fork) {
9205
9206
  const now6 = Date.now();
9206
- const forked = { meta: { ...data.meta, id: args.sessionId ?? store.newId(now6), created: now6, updated: now6, turns: data.meta.turns }, messages: data.messages };
9207
+ const forked = { meta: { ...data.meta, id: args.sessionId ?? store.newId(now6, cwd), created: now6, updated: now6, turns: data.meta.turns }, messages: data.messages };
9207
9208
  err(dim(` forked ${data.meta.id} \u2192 ${forked.meta.id} (${data.meta.turns} turns)
9208
9209
  `));
9209
9210
  if (!args.task) printHistory(data.messages);
@@ -9218,7 +9219,7 @@ function startSession(args, store, agent, cwd) {
9218
9219
  `));
9219
9220
  }
9220
9221
  const now5 = Date.now();
9221
- const id = args.sessionId ?? store.newId(now5);
9222
+ const id = args.sessionId ?? store.newId(now5, cwd);
9222
9223
  if (!args.task) err(dim(` session ${id}
9223
9224
  `));
9224
9225
  return { meta: { id, created: now5, updated: now5, cwd, model: agent.options.model, turns: 0, title: "" }, messages: [] };