@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
69 lines • 3.06 kB
JavaScript
import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { bunVersionSatisfies, findBunBinary, processBunRuntimeOptions, } from "../../bun-runtime.js";
import { APP_COMMAND, APP_NAME, BRAND, detectInstallMethod, getAgentDir, PACKAGE_NAME, VERSION } from "../../config.js";
import { envValue } from "../../core/brand.js";
import { hasInheritedInspectorOption } from "../../inspector-policy.js";
import { buildRuntimeNotice, reinstallTarget, runtimeNoticeSkipReason, runtimePinEnvName, SKIP_RUNTIME_NOTICE_ENV_SUFFIX, } from "./runtime-notice.js";
export const RUNTIME_NOTICE_STATE_FILE = "runtime-notice.json";
export function readShownVersion(agentDir) {
let parsed;
try {
parsed = JSON.parse(readFileSync(join(agentDir, RUNTIME_NOTICE_STATE_FILE), "utf8"));
}
catch {
// Missing or unreadable state means the notice was never recorded as shown.
return undefined;
}
if (typeof parsed !== "object" || parsed === null || !("shownVersion" in parsed))
return undefined;
return typeof parsed.shownVersion === "string" ? parsed.shownVersion : undefined;
}
function recordShownVersion(agentDir, version) {
try {
mkdirSync(agentDir, { recursive: true });
writeFileSync(join(agentDir, RUNTIME_NOTICE_STATE_FILE), `${JSON.stringify({ shownVersion: version })}\n`);
}
catch {
// Best effort: a read-only agent dir only means the notice shows again next launch,
// which must never fail the interactive startup that is already underway.
}
}
export function detectBunAvailability(options) {
const bunPath = findBunBinary(options);
if (bunPath === undefined)
return { kind: "missing" };
const version = options.bunVersion(bunPath);
return version !== undefined && bunVersionSatisfies(version)
? { kind: "ready", version }
: { kind: "outdated", version };
}
function skipRequested() {
const value = envValue(SKIP_RUNTIME_NOTICE_ENV_SUFFIX);
return value !== undefined && value !== "" && value !== "0";
}
export function maybeShowRuntimeNotice(show) {
const agentDir = getAgentDir();
const skip = runtimeNoticeSkipReason({
versions: process.versions,
env: process.env,
hasInheritedInspectorOption: hasInheritedInspectorOption(),
skipRequested: skipRequested(),
engineVersion: VERSION,
shownVersion: readShownVersion(agentDir),
});
if (skip !== undefined)
return;
show(buildRuntimeNotice({
appName: APP_NAME,
appCommand: APP_COMMAND,
nodeVersion: process.version,
platform: process.platform,
installMethod: detectInstallMethod(),
target: reinstallTarget(BRAND, PACKAGE_NAME),
bun: detectBunAvailability(processBunRuntimeOptions(existsSync, realpathSync)),
pinEnvName: runtimePinEnvName(process.env),
}));
recordShownVersion(agentDir, VERSION);
}
//# sourceMappingURL=runtime-notice-presenter.js.map