omo-web 0.1.1 → 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/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
- const loaded = await this.#loadContent(candidate.file.path);
6957
- parsed += 1;
6958
- bytes += loaded.bytes;
6959
- if (loaded.cwd !== candidate.file.root || !await this.#rootMatches(candidate.file))
6960
- continue;
6961
- sessions.push({
6962
- id: loaded.sessionId,
6963
- name: nameOf(loaded.entries, loaded.cwd),
6964
- cwd: loaded.cwd,
6965
- updatedAt: loaded.updatedAt,
6966
- nativeSessionId: loaded.sessionId,
6967
- ...candidate.file.workspaceKey === undefined ? {} : { workspaceKey: candidate.file.workspaceKey }
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 = [];
@@ -8586,24 +8668,45 @@ class SessionBranches {
8586
8668
  import { link, lstat as lstat6, mkdir, readFile as readFile2, readdir as readdir3, realpath as realpath6, rename, unlink as unlink2, writeFile as writeFile2 } from "fs/promises";
8587
8669
  import { dirname as dirname4, join as join6, resolve as resolve5 } from "path";
8588
8670
 
8671
+ // src/command-ownership.ts
8672
+ var terminalOnlyCommands = [
8673
+ "scoped-models",
8674
+ "favorite-models",
8675
+ "task-kill",
8676
+ "login",
8677
+ "logout",
8678
+ "trust",
8679
+ "export",
8680
+ "import",
8681
+ "share",
8682
+ "reload",
8683
+ "keybindings",
8684
+ "changelog",
8685
+ "quit",
8686
+ "exit",
8687
+ "bug",
8688
+ "debug"
8689
+ ];
8690
+ var dedicatedCommands = [
8691
+ "dag",
8692
+ "tasks",
8693
+ "todo",
8694
+ "reasoning",
8695
+ "efforts",
8696
+ "compact",
8697
+ "settings",
8698
+ "setting"
8699
+ ];
8700
+
8589
8701
  // src/commands.ts
8590
8702
  var str = (value) => typeof value === "string" ? value : "";
8591
8703
  var SHORT_NAME = /^[A-Za-z0-9_-]{1,64}$/;
8592
8704
  var SKILL_NAME = /^skill:[A-Za-z0-9-]{1,64}$/;
8593
- var localRuntimeCommands = new Set([
8594
- "/dag",
8595
- "/tasks",
8596
- "/task-kill",
8597
- "/todo",
8598
- "/reasoning",
8599
- "/efforts",
8600
- "/scoped-models",
8601
- "/favorite-models"
8602
- ]);
8705
+ var reservedCommands = new Set([...dedicatedCommands, ...terminalOnlyCommands].map((name) => `/${name}`));
8603
8706
  function refuseRuntimeCommandRelay(text) {
8604
8707
  const head = text.split(/\s/u, 1)[0];
8605
- if (head && localRuntimeCommands.has(head)) {
8606
- throw new WebError(400, "runtime_command_local", "\u8BE5\u547D\u4EE4\u7531 Web \u672C\u5730\u67E5\u770B\u5165\u53E3\u5904\u7406\uFF1B\u539F\u751F\u4FEE\u6539\u8BF7\u5728\u672C\u673A OmO \u7EC8\u7AEF\u64CD\u4F5C\u3002");
8708
+ if (head && reservedCommands.has(head)) {
8709
+ throw new WebError(400, "runtime_command_local", "\u8BF7\u5728 Web \u4F7F\u7528\u8BE5\u547D\u4EE4\u7684\u4E13\u7528\u5165\u53E3\uFF0C\u6216\u5728\u672C\u673A OmO \u7EC8\u7AEF\u6267\u884C\u7EC8\u7AEF\u4E13\u7528\u547D\u4EE4\u3002");
8607
8710
  }
8608
8711
  }
8609
8712
  function isCommandSource(value) {
@@ -10665,9 +10768,14 @@ ${source.nativeSessionId}`;
10665
10768
  case "autoCompaction":
10666
10769
  await request("set_auto_compaction", { enabled: action.enabled });
10667
10770
  break;
10668
- case "compact":
10771
+ case "compact": {
10772
+ const current = state(await request("get_state"));
10773
+ if (row.archived || current.isStreaming === true || current.isCompacting === true || typeof current.pendingMessageCount === "number" && current.pendingMessageCount > 0 || this.#live.get(id)?.running) {
10774
+ throw new WebError(409, "session_busy", "\u8BF7\u7B49\u4F1A\u8BDD\u7A7A\u95F2\u4E14\u961F\u5217\u6E05\u7A7A\u540E\u518D\u538B\u7F29\uFF0C\u6216\u5148\u53D6\u6D88\u5F52\u6863\u3002");
10775
+ }
10669
10776
  await request("compact", { customInstructions: action.instructions }, 180000);
10670
10777
  break;
10778
+ }
10671
10779
  case "clearQueue":
10672
10780
  await request("clear_queue");
10673
10781
  break;
@@ -11813,6 +11921,20 @@ import { open as open8 } from "fs/promises";
11813
11921
  import { isIP } from "net";
11814
11922
  import { createSecureContext } from "tls";
11815
11923
 
11924
+ // packaging/npm/access-policy.js
11925
+ var passwordPattern = /^[\x20-\x7e]{1,128}$/;
11926
+ var recommendedPasswordLength = 20;
11927
+ function parseProxyOrigin(value) {
11928
+ try {
11929
+ const url = new URL(value);
11930
+ return url.protocol === "https:" && url.origin === value ? url : undefined;
11931
+ } catch (error) {
11932
+ if (!(error instanceof TypeError))
11933
+ throw error;
11934
+ return;
11935
+ }
11936
+ }
11937
+
11816
11938
  // packaging/npm/listen-address.js
11817
11939
  import { networkInterfaces } from "os";
11818
11940
  var loopbackAddress = "127.0.0.1";
@@ -11912,7 +12034,6 @@ class WebAccessConfigError extends Error {
11912
12034
  this.setting = setting;
11913
12035
  }
11914
12036
  }
11915
- var passwordSchema = string2().regex(/^[\x20-\x7e]{20,128}$/);
11916
12037
  var MAX_AUTH_FAILURES = 5;
11917
12038
  var MAX_TRACKED_ADDRESSES = 1024;
11918
12039
  var AUTH_COOLDOWN_MS = 30000;
@@ -12006,13 +12127,19 @@ async function loadWebAccess(env, port) {
12006
12127
  const {
12007
12128
  OMO_WEB_PASSWORD_FILE: passwordFile,
12008
12129
  OMO_WEB_ORIGIN: originSetting,
12130
+ OMO_WEB_PROXY_ORIGIN: proxySetting,
12009
12131
  OMO_WEB_TLS_CERT: certFile,
12010
12132
  OMO_WEB_TLS_KEY: keyFile
12011
12133
  } = env;
12012
12134
  const publicBinding = isRemoteAddress(host);
12013
- const unprotected = publicBinding && passwordFile === undefined;
12135
+ const proxyOrigin = proxySetting === undefined ? undefined : parseProxyOrigin(proxySetting);
12136
+ if (proxySetting !== undefined && !proxyOrigin) {
12137
+ throw new WebAccessConfigError("OMO_WEB_PROXY_ORIGIN", cliTr("\u586B\u5199\u4EE3\u7406\u5BF9\u5916\u7684\u5B8C\u6574 HTTPS origin\uFF0C\u4E0D\u80FD\u542B\u8DEF\u5F84\u3001\u5C3E\u90E8\u659C\u6760\u6216\u51ED\u636E\u3002", "Use the proxy's canonical HTTPS origin, without a path, trailing slash, or credentials."));
12138
+ }
12139
+ const exposed = publicBinding || proxyOrigin !== undefined;
12140
+ const unprotected = exposed && passwordFile === undefined;
12014
12141
  if (unprotected && env.OMO_WEB_ALLOW_UNAUTHENTICATED !== "1") {
12015
- throw new WebAccessConfigError("OMO_WEB_PASSWORD_FILE", cliTr("\u975E\u672C\u673A\u76D1\u542C\u5FC5\u987B\u914D\u7F6E\u5BC6\u7801\u6587\u4EF6\uFF0C\u6216\u663E\u5F0F\u8BBE\u7F6E OMO_WEB_ALLOW_UNAUTHENTICATED=1\u3002", "Non-loopback listening requires a password file or explicit OMO_WEB_ALLOW_UNAUTHENTICATED=1."));
12142
+ throw new WebAccessConfigError("OMO_WEB_PASSWORD_FILE", cliTr("\u975E\u672C\u673A\u76D1\u542C\u6216\u4EE3\u7406\u5165\u53E3\u5FC5\u987B\u914D\u7F6E\u5BC6\u7801\u6587\u4EF6\uFF0C\u6216\u663E\u5F0F\u8BBE\u7F6E OMO_WEB_ALLOW_UNAUTHENTICATED=1\u3002", "Non-loopback listening or a proxy origin requires a password file or explicit OMO_WEB_ALLOW_UNAUTHENTICATED=1."));
12016
12143
  }
12017
12144
  let origin;
12018
12145
  let tls;
@@ -12033,24 +12160,30 @@ async function loadWebAccess(env, port) {
12033
12160
  origin = url.origin;
12034
12161
  }
12035
12162
  let digest;
12163
+ let weakPassword = false;
12036
12164
  if (passwordFile !== undefined) {
12037
12165
  const bytes = await fileBytes(passwordFile, "OMO_WEB_PASSWORD_FILE");
12038
- const password = passwordSchema.safeParse(bytes.toString("latin1").replace(/(?:\r\n|\n|\r)$/, ""));
12039
- if (!password.success) {
12040
- throw new WebAccessConfigError("OMO_WEB_PASSWORD_FILE", cliTr("\u5BC6\u7801\u5FC5\u987B\u662F 20\u2013128 \u4E2A\u53EF\u6253\u5370 ASCII \u5B57\u7B26\uFF0C\u53EA\u5141\u8BB8\u5355\u4E2A\u672B\u5C3E\u6362\u884C\u3002", "The password must be 20\u2013128 printable ASCII characters with at most one trailing line ending."));
12166
+ const password = bytes.toString("latin1").replace(/(?:\r\n|\n|\r)$/, "");
12167
+ if (!passwordPattern.test(password)) {
12168
+ throw new WebAccessConfigError("OMO_WEB_PASSWORD_FILE", cliTr("\u5BC6\u7801\u5FC5\u987B\u662F 1\u2013128 \u4E2A\u53EF\u6253\u5370 ASCII \u5B57\u7B26\uFF0C\u53EA\u5141\u8BB8\u5355\u4E2A\u672B\u5C3E\u6362\u884C\u3002", "The password must be 1\u2013128 printable ASCII characters with at most one trailing line ending."));
12041
12169
  }
12042
- const credentials = Buffer.from(`omo:${password.data}`).toString("base64");
12170
+ weakPassword = password.length < recommendedPasswordLength;
12171
+ const credentials = Buffer.from(`omo:${password}`).toString("base64");
12043
12172
  digest = createHash4("sha256").update(credentials).digest();
12044
12173
  }
12045
- const limiter = publicBinding && digest ? authFailureLimiter() : undefined;
12174
+ const limiter = exposed && digest ? authFailureLimiter() : undefined;
12046
12175
  return {
12047
12176
  hostname: host,
12048
12177
  origin,
12049
12178
  tls,
12050
12179
  unprotected,
12180
+ weakPassword,
12181
+ proxyOrigin,
12051
12182
  authorize(request, expected, token, address) {
12052
12183
  const requestOrigin = request.headers.get("Origin");
12053
- if (request.headers.get("Host") !== expected.host || requestOrigin !== null && requestOrigin !== expected.origin || ["cross-site", "same-site"].includes(request.headers.get("Sec-Fetch-Site") ?? "")) {
12184
+ const authority = request.headers.get("Host");
12185
+ const matches = (url) => authority === url.host && (requestOrigin === null || requestOrigin === url.origin);
12186
+ if (!matches(expected) && !(proxyOrigin && matches(proxyOrigin)) || ["cross-site", "same-site"].includes(request.headers.get("Sec-Fetch-Site") ?? "")) {
12054
12187
  throw new WebError(403, "origin_refused", "\u53EA\u63A5\u53D7\u540C\u6E90\u8BF7\u6C42\u3002");
12055
12188
  }
12056
12189
  if (digest) {
@@ -12061,7 +12194,7 @@ async function loadWebAccess(env, port) {
12061
12194
  if (retryAfter !== undefined) {
12062
12195
  return new Response(null, { status: 429, headers: { ...headers, "Retry-After": String(retryAfter) } });
12063
12196
  }
12064
- if (!encoded || encoded.length < 30 || encoded.length > 178 || !timingSafeEqual2(createHash4("sha256").update(encoded).digest(), digest)) {
12197
+ if (!encoded || encoded.length < 8 || encoded.length > 176 || !timingSafeEqual2(createHash4("sha256").update(encoded).digest(), digest)) {
12065
12198
  if (source)
12066
12199
  limiter?.record(source);
12067
12200
  return new Response(null, { status: 401, headers: { ...headers, "WWW-Authenticate": 'Basic realm="OmO Web"' } });
@@ -12070,7 +12203,7 @@ async function loadWebAccess(env, port) {
12070
12203
  if (request.method === "POST") {
12071
12204
  const provided = request.headers.get("X-OmO-Token") ?? "";
12072
12205
  const bytes = provided.length === token.length ? Buffer.from(provided) : undefined;
12073
- if (requestOrigin !== expected.origin || bytes?.length !== token.length || !timingSafeEqual2(bytes, token)) {
12206
+ if (requestOrigin === null || bytes?.length !== token.length || !timingSafeEqual2(bytes, token)) {
12074
12207
  throw new WebError(403, "token_refused", "\u8BF7\u5237\u65B0\u9875\u9762\u540E\u91CD\u8BD5\u3002");
12075
12208
  }
12076
12209
  } else if (request.method !== "GET") {
@@ -12460,6 +12593,8 @@ data: ${JSON.stringify(event)}
12460
12593
  return {
12461
12594
  url: new URL(url),
12462
12595
  unprotected: access.unprotected,
12596
+ weakPassword: access.weakPassword,
12597
+ proxyOrigin: access.proxyOrigin?.origin,
12463
12598
  fetch,
12464
12599
  stop() {
12465
12600
  closing ??= (async () => {
@@ -12511,8 +12646,12 @@ var app = await startApp({
12511
12646
  process.exit(1);
12512
12647
  });
12513
12648
  if (app.unprotected)
12514
- console.warn(cliTr("\u8B66\u544A\uFF1A\u975E\u672C\u673A\u76D1\u542C\u672A\u8BBE\u5BC6\u7801\u3002\u80FD\u8BBF\u95EE\u6B64\u5730\u5740\u7684\u4EBA\u90FD\u80FD\u8BFB\u53D6\u4F1A\u8BDD\u5E76\u901A\u8FC7 OmO \u64CD\u4F5C\u672C\u673A\u3002\u4EC5\u5728\u53D7\u9650\u79C1\u7F51\u6216 VPN \u5185\u4F7F\u7528\u3002", "Warning: non-loopback listening without a password. Anyone who can reach this address can read sessions and run tools through OmO. Use only on a restricted private network or VPN."));
12649
+ console.warn(cliTr("\u8B66\u544A\uFF1A\u975E\u672C\u673A\u5165\u53E3\u672A\u8BBE\u5BC6\u7801\u3002\u80FD\u8BBF\u95EE\u6B64\u5730\u5740\u7684\u4EBA\u90FD\u80FD\u8BFB\u53D6\u4F1A\u8BDD\u5E76\u901A\u8FC7 OmO \u64CD\u4F5C\u672C\u673A\u3002\u4EC5\u5728\u53D7\u9650\u79C1\u7F51\u6216 VPN \u5185\u4F7F\u7528\u3002", "Warning: remote access without a password. Anyone who can reach this address can read sessions and run tools through OmO. Use only on a restricted private network or VPN."));
12650
+ if (app.weakPassword)
12651
+ console.warn(cliTr("OmO Web warning: \u5BC6\u7801\u8F83\u77ED\uFF0C\u5EFA\u8BAE\u4F7F\u7528\u81F3\u5C11 20 \u4E2A\u5B57\u7B26\u3002", "OmO Web warning: short password. Use at least 20 characters for better protection."));
12515
12652
  console.log(`OmO Web: ${app.url.href}`);
12653
+ if (app.proxyOrigin)
12654
+ console.log(`${cliTr("\u4EE3\u7406\u5165\u53E3", "Proxy origin")}: ${app.proxyOrigin}`);
12516
12655
  console.log(`${cliTr("\u5DE5\u4F5C\u76EE\u5F55", "Working directories")}: ${workspaces.join(", ")}`);
12517
12656
  var halt = () => {
12518
12657
  app.stop().catch((error) => {
package/package.json CHANGED
@@ -29,5 +29,5 @@
29
29
  "dist/server.js",
30
30
  "public"
31
31
  ],
32
- "version": "0.1.1"
32
+ "version": "0.1.3"
33
33
  }