engine7 7.1.13 → 7.1.15

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/cli.mjs +41 -6
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -114,10 +114,19 @@ function collectAllFiles(dir) {
114
114
  }
115
115
  return files;
116
116
  }
117
- function collectRecentSessions(agentsDir, days = 7) {
117
+ function readMainSessionId(platformMapPath) {
118
+ try {
119
+ if (!fs.existsSync(platformMapPath)) return null;
120
+ const map = JSON.parse(fs.readFileSync(platformMapPath, "utf-8"));
121
+ return map["scope:main"] || null;
122
+ } catch {
123
+ return null;
124
+ }
125
+ }
126
+ function collectRecentSessions(agentsDir, _days = 7) {
118
127
  const files = [];
119
128
  if (!fs.existsSync(agentsDir)) return files;
120
- const cutoff = Date.now() - days * 24 * 60 * 60 * 1e3;
129
+ const sessionGroups = /* @__PURE__ */ new Map();
121
130
  function scanSessionsDir(dir) {
122
131
  try {
123
132
  const entries = fs.readdirSync(dir, { withFileTypes: true });
@@ -125,17 +134,43 @@ function collectRecentSessions(agentsDir, days = 7) {
125
134
  const fullPath = path.join(dir, entry.name);
126
135
  if (entry.isDirectory()) {
127
136
  scanSessionsDir(fullPath);
128
- } else if (entry.name.endsWith(".jsonl") || entry.name.match(/\.jsonl\.(archived|compaction)\./)) {
129
- const stat = fs.statSync(fullPath);
130
- if (stat.mtimeMs > cutoff) files.push(fullPath);
131
- } else if (entry.name === "platform-map.json" || entry.name === "session-index.json") {
137
+ continue;
138
+ }
139
+ if (entry.name === "platform-map.json" || entry.name === "session-index.json") {
132
140
  files.push(fullPath);
141
+ continue;
142
+ }
143
+ let sessionKey = null;
144
+ if (entry.name.endsWith(".jsonl")) {
145
+ sessionKey = entry.name.slice(0, -6);
146
+ } else {
147
+ const m = entry.name.match(/^(.+)\.jsonl\.(archived|compaction)\./);
148
+ if (m) sessionKey = m[1];
149
+ }
150
+ if (!sessionKey) continue;
151
+ if (!sessionGroups.has(sessionKey)) {
152
+ sessionGroups.set(sessionKey, { archived: [] });
153
+ }
154
+ const group = sessionGroups.get(sessionKey);
155
+ if (entry.name.endsWith(".jsonl")) {
156
+ group.jsonl = fullPath;
157
+ } else {
158
+ const stat = fs.statSync(fullPath);
159
+ group.archived.push({ file: fullPath, mtime: stat.mtimeMs });
133
160
  }
134
161
  }
135
162
  } catch {
136
163
  }
137
164
  }
138
165
  scanSessionsDir(agentsDir);
166
+ const mainSessionId = readMainSessionId(path.join(agentsDir, "main", "sessions", "platform-map.json"));
167
+ for (const [sessionKey, group] of sessionGroups) {
168
+ if (group.jsonl) files.push(group.jsonl);
169
+ if (mainSessionId && sessionKey.includes(mainSessionId)) {
170
+ group.archived.sort((a, b) => b.mtime - a.mtime);
171
+ if (group.archived.length > 0) files.push(group.archived[0].file);
172
+ }
173
+ }
139
174
  return files;
140
175
  }
141
176
  async function doExport(opts) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "engine7",
3
- "version": "7.1.13",
3
+ "version": "7.1.15",
4
4
  "type": "module",
5
5
  "description": "Engine 7 — Self-hosted AI agent engine",
6
6
  "main": "dist/main.mjs",