mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-09-19 10:02:04 +08:00
feat(kilo-gateway): add KILOCODE_VERSION support to editor header
- introduce ENV_VERSION constant in kilo-gateway and export it - modify getEditorNameHeader to append version when provided - export ENV_VERSION from gateway index for external use - initialize ENV_VERSION from Installation.VERSION in opencode startup - update tests to verify editor header with and without version
This commit is contained in:
@@ -58,6 +58,9 @@ export const DEFAULT_EDITOR_NAME = "Kilo CLI"
|
||||
/** Environment variable name for custom editor name */
|
||||
export const ENV_EDITOR_NAME = "KILOCODE_EDITOR_NAME"
|
||||
|
||||
/** Environment variable name for version (set by CLI at startup) */
|
||||
export const ENV_VERSION = "KILOCODE_VERSION"
|
||||
|
||||
/** Tester header value for suppressing warnings */
|
||||
export const TESTER_SUPPRESS_VALUE = "SUPPRESS"
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
CONTENT_TYPE,
|
||||
DEFAULT_EDITOR_NAME,
|
||||
ENV_EDITOR_NAME,
|
||||
ENV_VERSION,
|
||||
TESTER_SUPPRESS_VALUE,
|
||||
ENV_FEATURE, // kilocode_change
|
||||
} from "./api/constants.js"
|
||||
@@ -45,10 +46,13 @@ export const DEFAULT_HEADERS = {
|
||||
|
||||
/**
|
||||
* Get editor name header value
|
||||
* Defaults to "opencode" but can be customized
|
||||
* Defaults to "Kilo CLI" but can be customized via KILOCODE_EDITOR_NAME.
|
||||
* Appends the version from KILOCODE_VERSION when available.
|
||||
*/
|
||||
export function getEditorNameHeader(): string {
|
||||
return process.env[ENV_EDITOR_NAME] ?? DEFAULT_EDITOR_NAME
|
||||
const name = process.env[ENV_EDITOR_NAME] ?? DEFAULT_EDITOR_NAME
|
||||
const version = process.env[ENV_VERSION]
|
||||
return version ? `${name} ${version}` : name
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -93,6 +93,7 @@ export {
|
||||
HEADER_FEATURE,
|
||||
DEFAULT_EDITOR_NAME,
|
||||
ENV_EDITOR_NAME,
|
||||
ENV_VERSION,
|
||||
TESTER_SUPPRESS_VALUE,
|
||||
ENV_FEATURE,
|
||||
} from "./api/constants.js"
|
||||
|
||||
@@ -31,7 +31,7 @@ import { SessionCommand } from "./cli/cmd/session"
|
||||
// kilocode_change start - Import telemetry, instance disposal, and legacy migration
|
||||
import { Telemetry } from "@kilocode/kilo-telemetry"
|
||||
import { Instance } from "./project/instance" // kilocode_change
|
||||
import { migrateLegacyKiloAuth, ENV_FEATURE } from "@kilocode/kilo-gateway"
|
||||
import { migrateLegacyKiloAuth, ENV_FEATURE, ENV_VERSION } from "@kilocode/kilo-gateway"
|
||||
|
||||
// kilocode_change - set feature for tracking. 'serve' is spawned by other services
|
||||
// (extension, cloud) which set their own KILOCODE_FEATURE env var. Direct CLI use
|
||||
@@ -41,6 +41,11 @@ if (!process.env[ENV_FEATURE]) {
|
||||
const isServe = process.argv.includes("serve")
|
||||
process.env[ENV_FEATURE] = isServe ? "unknown" : "cli"
|
||||
}
|
||||
|
||||
// kilocode_change - set version so kilo-gateway can include it in the editor name header
|
||||
if (!process.env[ENV_VERSION]) {
|
||||
process.env[ENV_VERSION] = Installation.VERSION
|
||||
}
|
||||
import { Config } from "./config/config"
|
||||
import { Auth } from "./auth"
|
||||
// kilocode_change end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// kilocode_change - new file
|
||||
import { describe, it, expect, afterEach } from "bun:test"
|
||||
import { buildKiloHeaders, getFeatureHeader, getEditorNameHeader } from "@kilocode/kilo-gateway"
|
||||
import { HEADER_FEATURE, ENV_FEATURE } from "@kilocode/kilo-gateway"
|
||||
import { HEADER_FEATURE, ENV_FEATURE, ENV_VERSION, DEFAULT_EDITOR_NAME } from "@kilocode/kilo-gateway"
|
||||
|
||||
describe("getFeatureHeader", () => {
|
||||
const original = process.env[ENV_FEATURE]
|
||||
@@ -30,6 +30,28 @@ describe("getFeatureHeader", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("getEditorNameHeader", () => {
|
||||
const originalVersion = process.env[ENV_VERSION]
|
||||
|
||||
afterEach(() => {
|
||||
if (originalVersion === undefined) {
|
||||
delete process.env[ENV_VERSION]
|
||||
} else {
|
||||
process.env[ENV_VERSION] = originalVersion
|
||||
}
|
||||
})
|
||||
|
||||
it("returns default editor name without version when KILOCODE_VERSION is not set", () => {
|
||||
delete process.env[ENV_VERSION]
|
||||
expect(getEditorNameHeader()).toBe(DEFAULT_EDITOR_NAME)
|
||||
})
|
||||
|
||||
it("appends version when KILOCODE_VERSION is set", () => {
|
||||
process.env[ENV_VERSION] = "1.2.3"
|
||||
expect(getEditorNameHeader()).toBe(`${DEFAULT_EDITOR_NAME} 1.2.3`)
|
||||
})
|
||||
})
|
||||
|
||||
describe("buildKiloHeaders", () => {
|
||||
const original = process.env[ENV_FEATURE]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user