@ia-ccun/code-agent-cli 0.0.25 → 0.0.27
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 +20 -3
- package/config/agent/extensions/custom-footer.ts +26 -34
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -170,9 +170,26 @@ async function checkForUpdates() {
|
|
|
170
170
|
(latestParts[0] === localParts[0] && latestParts[1] === localParts[1] && latestParts[2] > localParts[2]);
|
|
171
171
|
|
|
172
172
|
if (needsUpdate) {
|
|
173
|
-
console.log('\n⚠️ 发现新版本 v%s → v%s', localVersion, latestVersion);
|
|
174
|
-
console.log('\n
|
|
175
|
-
console.log('
|
|
173
|
+
console.log('\n\x1b[38;2;243;139;168m⚠️ 发现新版本 v%s → v%s\x1b[0m', localVersion, latestVersion);
|
|
174
|
+
console.log('\n \x1b[38;2;166;227;161m运行以下命令更新:\x1b[0m');
|
|
175
|
+
console.log(' \x1b[36mnpm install -g @ia-ccun/code-agent-cli\x1b[0m\n');
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// 写入版本缓存
|
|
179
|
+
try {
|
|
180
|
+
const cacheDir = join(process.env.HOME || process.env.USERPROFILE, '.aicode-cli');
|
|
181
|
+
if (!existsSync(cacheDir)) {
|
|
182
|
+
execSync(`mkdir -p "${cacheDir}"`, { stdio: 'pipe' });
|
|
183
|
+
}
|
|
184
|
+
const cacheData = {
|
|
185
|
+
localVersion,
|
|
186
|
+
latestVersion,
|
|
187
|
+
needsUpdate,
|
|
188
|
+
timestamp: Date.now()
|
|
189
|
+
};
|
|
190
|
+
writeFileSync(versionCachePath, JSON.stringify(cacheData, null, 2));
|
|
191
|
+
} catch (e) {
|
|
192
|
+
// 忽略缓存写入失败
|
|
176
193
|
}
|
|
177
194
|
} catch (e) {
|
|
178
195
|
// 忽略检查失败
|
|
@@ -8,7 +8,6 @@
|
|
|
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";
|
|
12
11
|
|
|
13
12
|
function fmtTokens(n: number): string {
|
|
14
13
|
if (n < 1000) return n.toString();
|
|
@@ -20,34 +19,33 @@ function fmtTokens(n: number): string {
|
|
|
20
19
|
// #49bccf
|
|
21
20
|
const gold = (s: string) => `\x1b[38;2;73;188;207m${s}\x1b[0m`;
|
|
22
21
|
|
|
23
|
-
//
|
|
24
|
-
function
|
|
25
|
-
|
|
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 };
|
|
22
|
+
// 获取本地版本号
|
|
23
|
+
function getVersion() {
|
|
24
|
+
return process.env.AICODE_CLI_VERSION || null;
|
|
47
25
|
}
|
|
48
26
|
|
|
49
27
|
export default function (pi: ExtensionAPI) {
|
|
50
28
|
pi.on("session_start", async (_event, ctx) => {
|
|
29
|
+
// 检查版本更新并显示通知
|
|
30
|
+
const cachePath = process.env.AICODE_CLI_VERSION_CACHE;
|
|
31
|
+
if (cachePath) {
|
|
32
|
+
try {
|
|
33
|
+
const { existsSync, readFileSync } = await import("fs");
|
|
34
|
+
if (existsSync(cachePath)) {
|
|
35
|
+
const cache = JSON.parse(readFileSync(cachePath, 'utf-8'));
|
|
36
|
+
// 缓存有效期 1 小时
|
|
37
|
+
if (cache.needsUpdate && Date.now() - cache.timestamp < 3600000) {
|
|
38
|
+
// 显示版本更新提示
|
|
39
|
+
ctx.ui.showStatus(
|
|
40
|
+
`发现新版本 v${cache.localVersion} → v${cache.latestVersion},运行 npm install -g @ia-ccun/code-agent-cli 更新`
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
} catch (e) {
|
|
45
|
+
// 忽略
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
51
49
|
ctx.ui.setFooter((tui, theme, footerData) => {
|
|
52
50
|
const unsub = footerData.onBranchChange(() => tui.requestRender());
|
|
53
51
|
|
|
@@ -189,15 +187,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
189
187
|
segments.push(theme.fg("muted", quote));
|
|
190
188
|
|
|
191
189
|
// ── Version segment (rightmost) ─────────────────────────
|
|
192
|
-
const
|
|
193
|
-
if (
|
|
194
|
-
|
|
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
|
-
}
|
|
190
|
+
const version = getVersion();
|
|
191
|
+
if (version) {
|
|
192
|
+
segments.push(theme.fg("muted", `v${version}`));
|
|
201
193
|
}
|
|
202
194
|
|
|
203
195
|
const joined = segments.join(sep);
|