omo-web 0.1.2 → 0.1.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/app.js +5 -5
- package/dist/server.js +97 -15
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -6948,24 +6948,38 @@ class CliHistory {
|
|
|
6948
6948
|
for (const candidate of candidates) {
|
|
6949
6949
|
if (sessions.length >= CLI_HISTORY_LIMITS.maxSessions || parsed >= CLI_HISTORY_LIMITS.maxListFiles || bytes >= CLI_HISTORY_LIMITS.maxListBytes)
|
|
6950
6950
|
break;
|
|
6951
|
-
if (candidate.size > CLI_HISTORY_LIMITS.maxFileBytes)
|
|
6952
|
-
continue;
|
|
6953
6951
|
try {
|
|
6954
6952
|
if (!await this.#rootMatches(candidate.file))
|
|
6955
6953
|
continue;
|
|
6956
|
-
|
|
6957
|
-
|
|
6958
|
-
|
|
6959
|
-
|
|
6960
|
-
|
|
6961
|
-
|
|
6962
|
-
|
|
6963
|
-
|
|
6964
|
-
|
|
6965
|
-
|
|
6966
|
-
|
|
6967
|
-
|
|
6968
|
-
|
|
6954
|
+
if (candidate.size <= CLI_HISTORY_LIMITS.maxFileBytes) {
|
|
6955
|
+
const loaded = await this.#loadContent(candidate.file.path);
|
|
6956
|
+
parsed += 1;
|
|
6957
|
+
bytes += loaded.bytes;
|
|
6958
|
+
if (loaded.cwd !== candidate.file.root || !await this.#rootMatches(candidate.file))
|
|
6959
|
+
continue;
|
|
6960
|
+
sessions.push({
|
|
6961
|
+
id: loaded.sessionId,
|
|
6962
|
+
name: nameOf(loaded.entries, loaded.cwd),
|
|
6963
|
+
cwd: loaded.cwd,
|
|
6964
|
+
updatedAt: loaded.updatedAt,
|
|
6965
|
+
nativeSessionId: loaded.sessionId,
|
|
6966
|
+
...candidate.file.workspaceKey === undefined ? {} : { workspaceKey: candidate.file.workspaceKey }
|
|
6967
|
+
});
|
|
6968
|
+
} else {
|
|
6969
|
+
const oversized = await this.#summarizeOversized(candidate.file.path);
|
|
6970
|
+
parsed += 1;
|
|
6971
|
+
bytes += oversized.sampledBytes;
|
|
6972
|
+
if (oversized.cwd !== candidate.file.root || !await this.#rootMatches(candidate.file))
|
|
6973
|
+
continue;
|
|
6974
|
+
sessions.push({
|
|
6975
|
+
id: oversized.sessionId,
|
|
6976
|
+
name: oversized.name,
|
|
6977
|
+
cwd: oversized.cwd,
|
|
6978
|
+
updatedAt: oversized.updatedAt,
|
|
6979
|
+
nativeSessionId: oversized.sessionId,
|
|
6980
|
+
...candidate.file.workspaceKey === undefined ? {} : { workspaceKey: candidate.file.workspaceKey }
|
|
6981
|
+
});
|
|
6982
|
+
}
|
|
6969
6983
|
} catch {
|
|
6970
6984
|
continue;
|
|
6971
6985
|
}
|
|
@@ -7125,6 +7139,61 @@ class CliHistory {
|
|
|
7125
7139
|
});
|
|
7126
7140
|
}
|
|
7127
7141
|
}
|
|
7142
|
+
async#summarizeOversized(path) {
|
|
7143
|
+
const window = CLI_HISTORY_LIMITS.maxHeaderBytes;
|
|
7144
|
+
let handle;
|
|
7145
|
+
try {
|
|
7146
|
+
handle = await open3(path, constants2.O_RDONLY | constants2.O_NOFOLLOW | constants2.O_NONBLOCK);
|
|
7147
|
+
const target = await handle.stat();
|
|
7148
|
+
if (!target.isFile() || target.size <= CLI_HISTORY_LIMITS.maxFileBytes)
|
|
7149
|
+
throw invalid();
|
|
7150
|
+
const headText = await readAt(handle, 0, window);
|
|
7151
|
+
const cut = headText.lastIndexOf(`
|
|
7152
|
+
`);
|
|
7153
|
+
if (cut < 0)
|
|
7154
|
+
throw invalid();
|
|
7155
|
+
const { header, entries } = parse4(headText.slice(0, cut));
|
|
7156
|
+
if (!header || typeof header.cwd !== "string")
|
|
7157
|
+
throw invalid();
|
|
7158
|
+
const tailLen = Math.min(target.size - window, window);
|
|
7159
|
+
const tailText = await readAt(handle, target.size - tailLen, tailLen);
|
|
7160
|
+
const first = tailText.indexOf(`
|
|
7161
|
+
`);
|
|
7162
|
+
const tailEntries = [];
|
|
7163
|
+
for (const lineText of (first < 0 ? "" : tailText.slice(first + 1)).split(`
|
|
7164
|
+
`)) {
|
|
7165
|
+
if (!lineText.trim())
|
|
7166
|
+
continue;
|
|
7167
|
+
let parsed;
|
|
7168
|
+
try {
|
|
7169
|
+
parsed = JSON.parse(lineText);
|
|
7170
|
+
} catch {
|
|
7171
|
+
continue;
|
|
7172
|
+
}
|
|
7173
|
+
const entry = record2(parsed);
|
|
7174
|
+
if (typeof entry.id !== "string" || !entry.id || entry.type === "session")
|
|
7175
|
+
continue;
|
|
7176
|
+
tailEntries.push(entry);
|
|
7177
|
+
}
|
|
7178
|
+
return {
|
|
7179
|
+
sessionId: header.id,
|
|
7180
|
+
cwd: header.cwd,
|
|
7181
|
+
name: nameOf([...entries, ...tailEntries], header.cwd),
|
|
7182
|
+
updatedAt: Math.floor(target.mtimeMs),
|
|
7183
|
+
sampledBytes: window + tailLen
|
|
7184
|
+
};
|
|
7185
|
+
} catch (error) {
|
|
7186
|
+
if (error instanceof WebError)
|
|
7187
|
+
throw error;
|
|
7188
|
+
if (error?.code === "ELOOP")
|
|
7189
|
+
throw invalid();
|
|
7190
|
+
throw notFound();
|
|
7191
|
+
} finally {
|
|
7192
|
+
await handle?.close().catch(() => {
|
|
7193
|
+
return;
|
|
7194
|
+
});
|
|
7195
|
+
}
|
|
7196
|
+
}
|
|
7128
7197
|
}
|
|
7129
7198
|
function sessionDirName(cwd) {
|
|
7130
7199
|
return `--${cwd.replace(/^[/\\]/, "").replace(/[/\\:]/g, "-")}--`;
|
|
@@ -7180,6 +7249,19 @@ async function readPrefix(handle, cap) {
|
|
|
7180
7249
|
}
|
|
7181
7250
|
return Buffer.concat(chunks).toString("utf8");
|
|
7182
7251
|
}
|
|
7252
|
+
async function readAt(handle, offset, length) {
|
|
7253
|
+
const chunks = [];
|
|
7254
|
+
let total = 0;
|
|
7255
|
+
const scratch = Buffer.allocUnsafe(16384);
|
|
7256
|
+
while (total < length) {
|
|
7257
|
+
const { bytesRead } = await handle.read(scratch, 0, Math.min(scratch.length, length - total), offset + total);
|
|
7258
|
+
if (bytesRead === 0)
|
|
7259
|
+
break;
|
|
7260
|
+
chunks.push(Buffer.from(scratch.subarray(0, bytesRead)));
|
|
7261
|
+
total += bytesRead;
|
|
7262
|
+
}
|
|
7263
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
7264
|
+
}
|
|
7183
7265
|
function parse4(text) {
|
|
7184
7266
|
let header;
|
|
7185
7267
|
const entries = [];
|
package/package.json
CHANGED