mirror of
https://github.com/openai/codex.git
synced 2026-09-16 12:13:30 +00:00
fix: always load version from package.json at runtime
This commit is contained in:
@@ -72,6 +72,9 @@ if (isDevBuild) {
|
||||
esbuild
|
||||
.build({
|
||||
entryPoints: ["src/cli.tsx"],
|
||||
// Do not bundle the contents of package.json at build time: always read it
|
||||
// at runtime.
|
||||
external: ["../package.json"],
|
||||
bundle: true,
|
||||
format: "esm",
|
||||
platform: "node",
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { ResponseItem } from "openai/resources/responses/responses";
|
||||
import TerminalChat from "./components/chat/terminal-chat";
|
||||
import TerminalChatPastRollout from "./components/chat/terminal-chat-past-rollout";
|
||||
import { checkInGit } from "./utils/check-in-git";
|
||||
import { CLI_VERSION, type TerminalChatSession } from "./utils/session.js";
|
||||
import { CLI_VERSION, type TerminalChatSession } from "./session.js";
|
||||
import { onExit } from "./utils/terminal";
|
||||
import { ConfirmInput } from "@inkjs/ui";
|
||||
import { Box, Text, useApp, useStdin } from "ink";
|
||||
|
||||
@@ -10,12 +10,12 @@ import type {
|
||||
import MultilineTextEditor from "./multiline-editor";
|
||||
import { TerminalChatCommandReview } from "./terminal-chat-command-review.js";
|
||||
import TextCompletions from "./terminal-chat-completions.js";
|
||||
import { setSessionId } from "../../session.js";
|
||||
import { loadConfig } from "../../utils/config.js";
|
||||
import { getFileSystemSuggestions } from "../../utils/file-system-suggestions.js";
|
||||
import { expandFileTags } from "../../utils/file-tag-utils";
|
||||
import { createInputItem } from "../../utils/input-utils.js";
|
||||
import { log } from "../../utils/logger/log.js";
|
||||
import { setSessionId } from "../../utils/session.js";
|
||||
import { SLASH_COMMANDS, type SlashCommand } from "../../utils/slash-commands";
|
||||
import {
|
||||
loadCommandHistory,
|
||||
@@ -584,7 +584,7 @@ export default function TerminalChatInput({
|
||||
|
||||
try {
|
||||
const os = await import("node:os");
|
||||
const { CLI_VERSION } = await import("../../utils/session.js");
|
||||
const { CLI_VERSION } = await import("../../session.js");
|
||||
const { buildBugReportUrl } = await import(
|
||||
"../../utils/bug-report.js"
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { TerminalChatSession } from "../../utils/session.js";
|
||||
import type { TerminalChatSession } from "../../session.js";
|
||||
import type { ResponseItem } from "openai/resources/responses/responses";
|
||||
|
||||
import TerminalChatResponseItem from "./terminal-chat-response-item";
|
||||
|
||||
@@ -10,6 +10,7 @@ import TerminalMessageHistory from "./terminal-message-history.js";
|
||||
import { formatCommandForDisplay } from "../../format-command.js";
|
||||
import { useConfirmation } from "../../hooks/use-confirmation.js";
|
||||
import { useTerminalSize } from "../../hooks/use-terminal-size.js";
|
||||
import { CLI_VERSION } from "../../session.js";
|
||||
import { AgentLoop } from "../../utils/agent/agent-loop.js";
|
||||
import { ReviewDecision } from "../../utils/agent/review.js";
|
||||
import { generateCompactSummary } from "../../utils/compact-summary.js";
|
||||
@@ -24,7 +25,6 @@ import {
|
||||
uniqueById,
|
||||
} from "../../utils/model-utils.js";
|
||||
import { createOpenAIClient } from "../../utils/openai-client.js";
|
||||
import { CLI_VERSION } from "../../utils/session.js";
|
||||
import { shortCwd } from "../../utils/short-path.js";
|
||||
import { saveRollout } from "../../utils/storage/save-rollout.js";
|
||||
import ApprovalModeOverlay from "../approval-mode-overlay.js";
|
||||
|
||||
60
codex-cli/src/session.ts
Normal file
60
codex-cli/src/session.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
// Note that "../package.json" is marked external in build.mjs. This ensures
|
||||
// that the contents of package.json will always be read at runtime, which is
|
||||
// preferable so we do not have to make a temporary change to package.json in
|
||||
// the source tree to update the version number in the code.
|
||||
import pkg from "../package.json" with { type: "json" };
|
||||
|
||||
// Read the version directly from package.json.
|
||||
export const CLI_VERSION: string = (pkg as { version: string }).version;
|
||||
export const ORIGIN = "codex_cli_ts";
|
||||
|
||||
export type TerminalChatSession = {
|
||||
/** Globally unique session identifier */
|
||||
id: string;
|
||||
/** The OpenAI username associated with this session */
|
||||
user: string;
|
||||
/** Version identifier of the Codex CLI that produced the session */
|
||||
version: string;
|
||||
/** The model used for the conversation */
|
||||
model: string;
|
||||
/** ISO timestamp noting when the session was persisted */
|
||||
timestamp: string;
|
||||
/** Optional custom instructions that were active for the run */
|
||||
instructions: string;
|
||||
};
|
||||
|
||||
let sessionId = "";
|
||||
|
||||
/**
|
||||
* Update the globally tracked session identifier.
|
||||
* Passing an empty string clears the current session.
|
||||
*/
|
||||
export function setSessionId(id: string): void {
|
||||
sessionId = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the currently active session identifier, or an empty string when
|
||||
* no session is active.
|
||||
*/
|
||||
export function getSessionId(): string {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
let currentModel = "";
|
||||
|
||||
/**
|
||||
* Record the model that is currently being used for the conversation.
|
||||
* Setting an empty string clears the record so the next agent run can update it.
|
||||
*/
|
||||
export function setCurrentModel(model: string): void {
|
||||
currentModel = model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the model that was last supplied to {@link setCurrentModel}.
|
||||
* If no model has been recorded yet, an empty string is returned.
|
||||
*/
|
||||
export function getCurrentModel(): string {
|
||||
return currentModel;
|
||||
}
|
||||
@@ -11,6 +11,13 @@ import type {
|
||||
} from "openai/resources/responses/responses.mjs";
|
||||
import type { Reasoning } from "openai/resources.mjs";
|
||||
|
||||
import {
|
||||
ORIGIN,
|
||||
CLI_VERSION,
|
||||
getSessionId,
|
||||
setCurrentModel,
|
||||
setSessionId,
|
||||
} from "../../session.js";
|
||||
import {
|
||||
OPENAI_TIMEOUT_MS,
|
||||
OPENAI_ORGANIZATION,
|
||||
@@ -22,13 +29,6 @@ import {
|
||||
import { log } from "../logger/log.js";
|
||||
import { parseToolCallArguments } from "../parsers.js";
|
||||
import { responsesCreateViaChatCompletions } from "../responses.js";
|
||||
import {
|
||||
ORIGIN,
|
||||
CLI_VERSION,
|
||||
getSessionId,
|
||||
setCurrentModel,
|
||||
setSessionId,
|
||||
} from "../session.js";
|
||||
import { handleExecCommand } from "./handle-exec-command.js";
|
||||
import { HttpsProxyAgent } from "https-proxy-agent";
|
||||
import { randomUUID } from "node:crypto";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { AgentName } from "package-manager-detector";
|
||||
|
||||
import { detectInstallerByPath } from "./package-manager-detector";
|
||||
import { CLI_VERSION } from "./session";
|
||||
import { CLI_VERSION } from "../session";
|
||||
import boxen from "boxen";
|
||||
import chalk from "chalk";
|
||||
import { getLatestVersion } from "fast-npm-meta";
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
renderUpdateCommand,
|
||||
} from "../src/utils/check-updates";
|
||||
import { detectInstallerByPath } from "../src/utils/package-manager-detector";
|
||||
import { CLI_VERSION } from "../src/utils/session";
|
||||
import { CLI_VERSION } from "../src/session";
|
||||
|
||||
// In-memory FS mock
|
||||
let memfs: Record<string, string> = {};
|
||||
|
||||
Reference in New Issue
Block a user