@ia-ccun/code-agent-cli 0.0.22 → 0.0.24
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/bin/cli.js +27 -1
- package/config/agent/extensions/custom-footer.ts +39 -0
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -18,6 +18,24 @@ import { generateBanner } from '../dist/banner.js';
|
|
|
18
18
|
const __filename = fileURLToPath(import.meta.url);
|
|
19
19
|
const __dirname = dirname(__filename);
|
|
20
20
|
|
|
21
|
+
// 获取本地版本号
|
|
22
|
+
function getLocalVersion() {
|
|
23
|
+
let rootDir = __dirname;
|
|
24
|
+
while (rootDir !== dirname(rootDir)) {
|
|
25
|
+
const pkgPath = join(rootDir, 'package.json');
|
|
26
|
+
if (existsSync(pkgPath)) {
|
|
27
|
+
return JSON.parse(readFileSync(pkgPath, 'utf-8')).version;
|
|
28
|
+
}
|
|
29
|
+
rootDir = dirname(rootDir);
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// 获取版本缓存文件路径
|
|
35
|
+
function getVersionCachePath() {
|
|
36
|
+
return join(process.env.HOME || process.env.USERPROFILE, '.aicode-cli', '.version-cache.json');
|
|
37
|
+
}
|
|
38
|
+
|
|
21
39
|
// 解析命令行参数
|
|
22
40
|
function parseArgs() {
|
|
23
41
|
const args = process.argv.slice(2);
|
|
@@ -142,7 +160,7 @@ async function checkForUpdates() {
|
|
|
142
160
|
|
|
143
161
|
// 获取当前 registry
|
|
144
162
|
const registry = execSync('npm config get registry', { encoding: 'utf8', stdio: 'pipe' }).trim();
|
|
145
|
-
const latestVersion = execSync(`npm view @
|
|
163
|
+
const latestVersion = execSync(`npm view @ia-ccun/code-agent-cli version --registry=${registry}`, { encoding: 'utf8', stdio: 'pipe' }).trim();
|
|
146
164
|
|
|
147
165
|
// 比较版本号
|
|
148
166
|
const localParts = localVersion.split('.').map(Number);
|
|
@@ -165,11 +183,19 @@ checkForUpdates();
|
|
|
165
183
|
// 获取 node_modules 中 pi-coding-agent 的 CLI 路径
|
|
166
184
|
const piAgentPath = new URL('../node_modules/@mariozechner/pi-coding-agent/dist/cli.js', import.meta.url);
|
|
167
185
|
|
|
186
|
+
// 获取本地版本号
|
|
187
|
+
const localVersion = getLocalVersion();
|
|
188
|
+
|
|
189
|
+
// 获取版本缓存文件路径
|
|
190
|
+
const versionCachePath = getVersionCachePath();
|
|
191
|
+
|
|
168
192
|
// 设置环境变量
|
|
169
193
|
const env = {
|
|
170
194
|
...process.env,
|
|
171
195
|
AICODE_CLI_CONFIG_DIR: config.configDir,
|
|
172
196
|
AICODE_CLI_NAME: config.name,
|
|
197
|
+
AICODE_CLI_VERSION: localVersion || '',
|
|
198
|
+
AICODE_CLI_VERSION_CACHE: versionCachePath,
|
|
173
199
|
PI_SKIP_VERSION_CHECK: '1'
|
|
174
200
|
};
|
|
175
201
|
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import type { AssistantMessage } from "@mariozechner/pi-ai";
|
|
9
9
|
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
10
10
|
import { truncateToWidth, visibleWidth } from "@mariozechner/pi-tui";
|
|
11
|
+
import { existsSync, readFileSync } from "fs";
|
|
11
12
|
|
|
12
13
|
function fmtTokens(n: number): string {
|
|
13
14
|
if (n < 1000) return n.toString();
|
|
@@ -19,6 +20,32 @@ function fmtTokens(n: number): string {
|
|
|
19
20
|
// Catppuccin Mocha Yellow — #f9e2af
|
|
20
21
|
const gold = (s: string) => `\x1b[38;2;166;227;161m${s}\x1b[0m`;
|
|
21
22
|
|
|
23
|
+
// 获取版本信息(从环境变量和缓存文件)
|
|
24
|
+
function getVersionInfo() {
|
|
25
|
+
const localVersion = process.env.AICODE_CLI_VERSION;
|
|
26
|
+
const cachePath = process.env.AICODE_CLI_VERSION_CACHE;
|
|
27
|
+
|
|
28
|
+
if (!localVersion) return null;
|
|
29
|
+
|
|
30
|
+
let needsUpdate = false;
|
|
31
|
+
let latestVersion = localVersion;
|
|
32
|
+
|
|
33
|
+
if (cachePath && existsSync(cachePath)) {
|
|
34
|
+
try {
|
|
35
|
+
const cache = JSON.parse(readFileSync(cachePath, 'utf-8'));
|
|
36
|
+
// 缓存有效期 1 小时
|
|
37
|
+
if (Date.now() - cache.timestamp < 3600000) {
|
|
38
|
+
latestVersion = cache.latestVersion;
|
|
39
|
+
needsUpdate = cache.needsUpdate;
|
|
40
|
+
}
|
|
41
|
+
} catch (e) {
|
|
42
|
+
// 忽略读取失败
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return { localVersion, latestVersion, needsUpdate };
|
|
47
|
+
}
|
|
48
|
+
|
|
22
49
|
export default function (pi: ExtensionAPI) {
|
|
23
50
|
pi.on("session_start", async (_event, ctx) => {
|
|
24
51
|
ctx.ui.setFooter((tui, theme, footerData) => {
|
|
@@ -161,6 +188,18 @@ export default function (pi: ExtensionAPI) {
|
|
|
161
188
|
segments.push(modelColored);
|
|
162
189
|
segments.push(theme.fg("muted", quote));
|
|
163
190
|
|
|
191
|
+
// ── Version segment (rightmost) ─────────────────────────
|
|
192
|
+
const versionInfo = getVersionInfo();
|
|
193
|
+
if (versionInfo) {
|
|
194
|
+
if (versionInfo.needsUpdate) {
|
|
195
|
+
// 红色警告色
|
|
196
|
+
segments.push(`\x1b[38;2;243;139;168mv${versionInfo.localVersion} ⚠️\x1b[0m`);
|
|
197
|
+
} else {
|
|
198
|
+
// 浅灰色
|
|
199
|
+
segments.push(theme.fg("muted", `v${versionInfo.localVersion}`));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
164
203
|
const joined = segments.join(sep);
|
|
165
204
|
return [truncateToWidth(joined, width)];
|
|
166
205
|
},
|