Skip to content

A local plugin for image-heavy chats in Codex, Claude Code and other agents: earlier images stop going out with every message, and the model fetches the one it needs by its ID, also after compaction.

fix(platform): 判断“是不是被直接运行的脚本”时按真实路径比较

chipfighter74408ee9e5c6
diff --git a/plugin/src/cam.ts b/plugin/src/cam.ts
index beae18b..6020d3c 100644
--- a/plugin/src/cam.ts
+++ b/plugin/src/cam.ts
@@ -13,10 +13,10 @@ import { spawn } from "node:child_process";
import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
-import { pathToFileURL } from "node:url";
import { findCodexCli, runCodex } from "./codexcli.ts";
import { codexHome, MCP_BEGIN, noProxyStatus, persistedEnv, proxyStatus } from "./codexconfig.ts";
import { buildOf, DEFAULT_PORT, engineHealth, ensureEngine } from "./engine.ts";
+import { isEntryPoint } from "./entry.ts";
import { MARKETPLACE, PLUGIN, PLUGIN_ID, planInstall, planUninstall, pluginStatus, type Plan } from "./install.ts";
import { applySelection, loadPanelState, type PanelState } from "./panel-state.ts";
import { dataDir, selectionDirOf } from "./paths.ts";
@@ -217,4 +217,4 @@ async function main(): Promise<void> {
else throw new Error(`unknown command ${command}`);
}
-if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) await main();
+if (isEntryPoint(import.meta.url)) await main();
diff --git a/plugin/src/entry.ts b/plugin/src/entry.ts
new file mode 100644
index 0000000..2d16d88
--- /dev/null
+++ b/plugin/src/entry.ts
@@ -0,0 +1,16 @@
+// Purpose: v0.1 — whether a module is the script Node was started with. Node loads that script by its real path, while
+// process.argv[1] keeps the path as it was given; the two differ when the path goes through a symlink (macOS's /var,
+// or a ~/.codex that links somewhere else), and the script would then silently do nothing.
+// Input: the module's import.meta.url. Output: true or false.
+
+import { realpathSync } from "node:fs";
+import { fileURLToPath } from "node:url";
+
+export function isEntryPoint(moduleUrl: string): boolean {
+ if (!process.argv[1]) return false;
+ try {
+ return realpathSync(process.argv[1]) === realpathSync(fileURLToPath(moduleUrl));
+ } catch {
+ return false;
+ }
+}
diff --git a/plugin/src/plugin-server.ts b/plugin/src/plugin-server.ts
index d8849dc..b00f4c7 100644
--- a/plugin/src/plugin-server.ts
+++ b/plugin/src/plugin-server.ts
@@ -11,9 +11,10 @@
import { appendFileSync, mkdirSync, readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { createInterface } from "node:readline";
-import { fileURLToPath, pathToFileURL } from "node:url";
+import { fileURLToPath } from "node:url";
import { codexHome } from "./codexconfig.ts";
import { DEFAULT_PORT, ensureEngine } from "./engine.ts";
+import { isEntryPoint } from "./entry.ts";
import { applySelection, imageFor, loadPanelState, type PanelState } from "./panel-state.ts";
import { dataDir } from "./paths.ts";
@@ -161,4 +162,4 @@ function main(): void {
});
}
-if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) main();
+if (isEntryPoint(import.meta.url)) main();
diff --git a/plugin/src/proxy.ts b/plugin/src/proxy.ts
index 9978580..c1b0496 100644
--- a/plugin/src/proxy.ts
+++ b/plugin/src/proxy.ts
@@ -17,11 +17,11 @@ import net from "node:net";
import { join } from "node:path";
import type { Duplex } from "node:stream";
import tls from "node:tls";
-import { pathToFileURL } from "node:url";
import zlib from "node:zlib";
import { codexHome } from "./codexconfig.ts";
import { buildOf, DEFAULT_PORT, ENGINE_SERVICE, engineHealth, versionOf, watchForCodex } from "./engine.ts";
import { findImages, type ImageRef } from "./images.ts";
+import { isEntryPoint } from "./entry.ts";
import { dataDir, proxyLogDirOf } from "./paths.ts";
import { recordRequest } from "./request-stats.ts";
import { rewriteItems, type Described } from "./rewrite.ts";
@@ -473,4 +473,4 @@ async function main(): Promise<void> {
}
}
-if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) await main();
+if (isEntryPoint(import.meta.url)) await main();