glmcode 0.1.15 → 0.1.16
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/CHANGELOG.md +9 -0
- package/package.json +1 -1
- package/src/cli.js +58 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 0.1.16 (2026-08-29)
|
|
4
|
+
|
|
5
|
+
- **自适应布局**:监听终端尺寸变化(手机横竖屏切换 / 窗口拉伸),输入态下立即重绘,不再残留错乱;各元素仍按实时列宽/行高计算
|
|
6
|
+
- **启动画面不再浪费空白**:欢迎块(LOGO+提示+启动信息面板)整体**垂直居中**,中间区域填充常用命令、技能目录提示、兼容性说明,屏幕矮时自动紧凑回顶部
|
|
7
|
+
- **Ctrl+C / /exit 退出即"打开新页面"**:真正清屏,清掉本会话所有历史输出,只显示一张**会话总结页**:运行时长、执行过的指令列表、生成的文件列表、Token 消耗
|
|
8
|
+
- **会话统计**:自动记录本次会话运行过哪些指令、通过 write_file 生成了哪些文件、API 累计消耗的 token 数(从流式响应 usage 读取)
|
|
9
|
+
- 35 项 `--selftest` 全过;36x40 高屏 PTY+pyte 仿真验证:居中布局、菜单缩回无残留、退出清屏总结页全部正常
|
|
10
|
+
- 版本升级至 0.1.16
|
|
11
|
+
|
|
3
12
|
## 0.1.15 (2026-08-29)
|
|
4
13
|
|
|
5
14
|
- **命令菜单移至输入框下方**:菜单紧贴输入行正下方往下展开,状态栏仍固定在屏幕最底;缩回菜单时彻底擦除,不再残留"被缩回去的一行"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "glmcode",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"description": "GLM coding agent CLI with shell tools, skills (SKILL.md/zip auto-extract), streaming chat, slash-command menu and bottom status bar. Auto-installs its dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/src/cli.js
CHANGED
|
@@ -7,7 +7,7 @@ import {fileURLToPath} from "node:url";
|
|
|
7
7
|
import termkit from "terminal-kit";
|
|
8
8
|
const term = termkit.terminal;
|
|
9
9
|
|
|
10
|
-
const VERSION="0.1.
|
|
10
|
+
const VERSION="0.1.16";
|
|
11
11
|
const BASE_URL="https://open.bigmodel.cn/api/paas/v4";
|
|
12
12
|
const API_KEYS_URL="https://open.bigmodel.cn/usercenter/proj-mgmt/apikeys";
|
|
13
13
|
const HOME=os.homedir();
|
|
@@ -31,6 +31,8 @@ const DEFAULT_CONFIG={
|
|
|
31
31
|
|
|
32
32
|
let config={...DEFAULT_CONFIG};
|
|
33
33
|
let apiKey=null, messages=[], cwd=process.cwd(), thinkingEnabled=false, skills=new Map();
|
|
34
|
+
/* 会话统计:退出时生成耗费总结(运行了哪些指令/生成了哪些文件/耗了多少token) */
|
|
35
|
+
const SESSION={start:Date.now(),commands:[],files:[],tokens:0,calls:0};
|
|
34
36
|
|
|
35
37
|
function readJson(file,fallback={}){try{return JSON.parse(fs.readFileSync(file,"utf8"));}catch{return fallback;}}
|
|
36
38
|
function saveJson(file,v){fs.mkdirSync(DATA_DIR,{recursive:true,mode:0o700});fs.writeFileSync(file,JSON.stringify(v,null,2)+"\n",{mode:0o600});try{fs.chmodSync(file,0o600);}catch{}}
|
|
@@ -158,7 +160,7 @@ function execTool(name,args){
|
|
|
158
160
|
try{const r=spawnSync(file,shArgs,{cwd,encoding:"utf8",timeout:60000});return ((r.stdout||"")+(r.stderr?"\n[stderr]\n"+r.stderr:"")).slice(0,8000)||"(无输出)";}
|
|
159
161
|
catch(e){return `执行失败: ${e.message}`;}
|
|
160
162
|
}
|
|
161
|
-
if(name==="write_file"){try{const p=path.resolve(cwd,args.path);fs.mkdirSync(path.dirname(p),{recursive:true});fs.writeFileSync(p,args.content);return `已写入 ${p}`;}catch(e){return `写入失败: ${e.message}`;}}
|
|
163
|
+
if(name==="write_file"){try{const p=path.resolve(cwd,args.path);fs.mkdirSync(path.dirname(p),{recursive:true});fs.writeFileSync(p,args.content);SESSION.files.push(p);return `已写入 ${p}`;}catch(e){return `写入失败: ${e.message}`;}}
|
|
162
164
|
if(name==="read_file"){try{return fs.readFileSync(path.resolve(cwd,args.path),"utf8").slice(0,8000);}catch(e){return `读取失败: ${e.message}`;}}
|
|
163
165
|
if(name==="use_skill"){const s=skills.get(args.skill_name);return s?`技能已加载:${s.name}\n\n${s.content}`:`技能不存在:${args.skill_name}`;}
|
|
164
166
|
return "未知工具";
|
|
@@ -183,7 +185,8 @@ async function streamChat(){
|
|
|
183
185
|
line=line.trim();if(!line.startsWith("data:"))continue;
|
|
184
186
|
const data=line.slice(5).trim();if(data==="[DONE]")continue;
|
|
185
187
|
try{
|
|
186
|
-
const
|
|
188
|
+
const dj=JSON.parse(data);const d=dj.choices?.[0]?.delta||{};
|
|
189
|
+
if(dj.usage&&dj.usage.total_tokens){SESSION.tokens+=dj.usage.total_tokens;SESSION.calls++;}
|
|
187
190
|
if(d.reasoning_content&&thinkingEnabled)process.stdout.write(color(d.reasoning_content,C.gray));
|
|
188
191
|
if(d.content){content+=d.content;process.stdout.write(d.content);}
|
|
189
192
|
for(const tc of d.tool_calls||[]){
|
|
@@ -279,12 +282,12 @@ async function handleCommand(line){
|
|
|
279
282
|
else if(cmd==="/auth"){const a=loadAuth();console.log(a?`API Key: ${mask(a.key)}\n来源: ${a.source}`:"未检测到 API Key");}
|
|
280
283
|
else if(cmd==="/run"){if(!arg)console.log("用法: /run <命令>");else console.log(execTool("run_shell",{command:arg}));}
|
|
281
284
|
else if(cmd==="/install"){installProgram(arg)}
|
|
282
|
-
else if(cmd==="/exit"){
|
|
285
|
+
else if(cmd==="/exit"){showSummaryAndExit();process.exit(0);}
|
|
283
286
|
else console.log(color(`未知命令: ${cmd}(输入 / 查看全部)`,C.red));
|
|
284
287
|
}
|
|
285
288
|
|
|
286
289
|
function logo(){
|
|
287
|
-
const w=tw();
|
|
290
|
+
const w=tw(),h=th();
|
|
288
291
|
const art=[
|
|
289
292
|
" ██████╗ ██╗ ███╗ ███╗",
|
|
290
293
|
"██╔════╝ ██║ ████╗ ████║",
|
|
@@ -293,14 +296,28 @@ function logo(){
|
|
|
293
296
|
"╚██████╔╝███████╗██║ ╚═╝ ██║",
|
|
294
297
|
" ╚═════╝ ╚══════╝╚═╝ ╚═╝"
|
|
295
298
|
];
|
|
299
|
+
// 启动信息面板:填充中间空白区域,矮屏自动紧凑
|
|
300
|
+
const tip=truncW(" Coding Agent · v"+VERSION+" · 输入 / 弹菜单 · ↑↓ 选择 · 回车执行 · Ctrl+C 退出看总结",w);
|
|
301
|
+
const cmdKeys=[["/help","全部命令"],["/clear","清空对话"],["/skills","技能列表与目录"],["/skill","管理技能(可新建)"],["/model","切换模型"],["/exit","退出"]];
|
|
302
|
+
const panel=[""];
|
|
303
|
+
for(const [k,d] of cmdKeys)panel.push(" "+color(k,C.cyanB)+" "+color(truncW(d,Math.max(4,w-6)),C.gray));
|
|
304
|
+
panel.push("");
|
|
305
|
+
panel.push(truncW(" · 技能自动加载: ~/.glmcode/skills/ 或包内 skills/ · /skill new <名字> 新建",w));
|
|
306
|
+
panel.push(truncW(" · 全平台兼容 Linux/Android(termux)/Windows/macOS · 底部状态栏常驻",w));
|
|
307
|
+
const blockH=art.length+1+panel.length;
|
|
308
|
+
// 欢迎块整体垂直居中(底部恒留2行给输入行+状态栏);过矮/超屏则顶部紧凑
|
|
309
|
+
let start=Math.max(1,Math.floor((h-blockH-2)/2));
|
|
310
|
+
if(start+blockH>h-2)start=1;
|
|
311
|
+
term.moveTo(1,start);
|
|
296
312
|
for(const a of art)console.log(color(truncW(a,w),C.cyanB));
|
|
297
|
-
console.log(color(
|
|
298
|
-
console.log(
|
|
313
|
+
console.log(color(tip,C.gray));
|
|
314
|
+
for(const p of panel)console.log(truncW(p,w));
|
|
299
315
|
}
|
|
300
316
|
|
|
301
317
|
/* =============== 真 TUI:悬浮菜单 + 上下键 + 实时过滤 + 底部状态栏 =============== */
|
|
302
318
|
const PROMPT=()=>`${shortDir()} > `;
|
|
303
319
|
const TUI={input:"",cursor:0,items:[],sel:0,scroll:0,history:[],histIdx:-1};
|
|
320
|
+
let tuiActive=false; // 是否正处于输入等待态(resize 时仅此时才安全重绘)
|
|
304
321
|
function tw(){return (term.width>0&&isFinite(term.width))?term.width:40;}
|
|
305
322
|
function th(){return (term.height>0&&isFinite(term.height))?term.height:24;}
|
|
306
323
|
const MENU_MAX=4;
|
|
@@ -388,6 +405,7 @@ function refreshFilter(){
|
|
|
388
405
|
function tuiInput(){
|
|
389
406
|
return new Promise(resolve=>{
|
|
390
407
|
TUI.input="";TUI.cursor=0;TUI.items=[];TUI.sel=0;TUI.scroll=0;TUI.histIdx=-1;
|
|
408
|
+
tuiActive=true;
|
|
391
409
|
term.grabInput(true);
|
|
392
410
|
render();
|
|
393
411
|
const onKey=(name,matches,data)=>{
|
|
@@ -420,8 +438,9 @@ function tuiInput(){
|
|
|
420
438
|
term.removeListener("key",onKey);
|
|
421
439
|
term.grabInput(false);
|
|
422
440
|
term.hideCursor();
|
|
441
|
+
tuiActive=false;
|
|
423
442
|
term("\n");
|
|
424
|
-
if(v.trim())TUI.history.push(v.trim());
|
|
443
|
+
if(v.trim()){TUI.history.push(v.trim());SESSION.commands.push(v.trim());}
|
|
425
444
|
resolve(v);
|
|
426
445
|
}
|
|
427
446
|
else if(name==="BACKSPACE"){
|
|
@@ -436,7 +455,7 @@ function tuiInput(){
|
|
|
436
455
|
else if(name==="RIGHT"){if(TUI.cursor<TUI.input.length){TUI.cursor++;}render();}
|
|
437
456
|
else if(name==="HOME"){TUI.cursor=0;render();}
|
|
438
457
|
else if(name==="END"){TUI.cursor=TUI.input.length;render();}
|
|
439
|
-
else if(name==="CTRL_C"){term.removeListener("key",onKey);term.grabInput(false);term.hideCursor(true);term("\n");resolve(null);}
|
|
458
|
+
else if(name==="CTRL_C"){term.removeListener("key",onKey);term.grabInput(false);term.hideCursor(true);tuiActive=false;term("\n");resolve(null);}
|
|
440
459
|
else if(name==="CTRL_L"){term.clear();term.moveTo(1,1);render();}
|
|
441
460
|
};
|
|
442
461
|
// 防监听器累积:注册前先移除上一轮的 key 监听,杜绝按键被重复处理
|
|
@@ -445,9 +464,37 @@ function tuiInput(){
|
|
|
445
464
|
tuiInput._key=onKey;
|
|
446
465
|
});
|
|
447
466
|
}
|
|
467
|
+
function showSummaryAndExit(){
|
|
468
|
+
term.grabInput(false);term.hideCursor(true);
|
|
469
|
+
// 真正清屏:像打开新页面一样,清掉本会话所有输出
|
|
470
|
+
term.clear();term.moveTo(1,1);
|
|
471
|
+
const dur=Math.max(0,Math.round((Date.now()-SESSION.start)/1000));
|
|
472
|
+
const mm=String(Math.floor(dur/60)).padStart(2,"0"),ss=String(dur%60).padStart(2,"0");
|
|
473
|
+
const bar="=".repeat(Math.max(8,Math.min(tw()-2,42)));
|
|
474
|
+
console.log(color(bar,C.cyan));
|
|
475
|
+
console.log(color(" GLMCode 会话总结",C.cyanB));
|
|
476
|
+
console.log(color(bar,C.cyan));
|
|
477
|
+
console.log("");
|
|
478
|
+
console.log(` 时长: ${mm}:${ss} 模型: ${config.model}`);
|
|
479
|
+
console.log(` 执行指令: ${SESSION.commands.length} 条`);
|
|
480
|
+
if(SESSION.commands.length){
|
|
481
|
+
const shown=SESSION.commands.slice(-10);
|
|
482
|
+
for(const c of shown)console.log(color(" · "+truncW(c,Math.max(8,tw()-8)),C.gray));
|
|
483
|
+
if(SESSION.commands.length>shown.length)console.log(color(` … 还有 ${SESSION.commands.length-shown.length} 条`,C.gray));
|
|
484
|
+
}else console.log(color(" (无)",C.gray));
|
|
485
|
+
console.log(` 生成文件: ${SESSION.files.length} 个`);
|
|
486
|
+
if(SESSION.files.length){for(const f of SESSION.files.slice(-8))console.log(color(" · "+truncW(f,Math.max(8,tw()-8)),C.gray));}
|
|
487
|
+
else console.log(color(" (无)",C.gray));
|
|
488
|
+
console.log(` Token 消耗: ${SESSION.tokens}`);
|
|
489
|
+
console.log("");
|
|
490
|
+
console.log(color(" ✔ 已清屏,像打开新页面一样干净",C.green));
|
|
491
|
+
}
|
|
448
492
|
async function runTui(){
|
|
449
493
|
term.hideCursor();
|
|
450
494
|
term.clear();logo();
|
|
495
|
+
// 自适应:终端尺寸变化(手机横竖屏/窗口拉伸)时立即重绘,不残留不错乱
|
|
496
|
+
const onResize=()=>{if(tuiActive)render();};
|
|
497
|
+
term.on("resize",onResize);
|
|
451
498
|
while(true){
|
|
452
499
|
const input=await tuiInput();
|
|
453
500
|
if(input===null)break;
|
|
@@ -456,8 +503,9 @@ async function runTui(){
|
|
|
456
503
|
if(text.startsWith("/"))await handleCommand(text);
|
|
457
504
|
else await chat(text);
|
|
458
505
|
}
|
|
506
|
+
term.removeListener("resize",onResize);
|
|
459
507
|
term.grabInput(false);
|
|
460
|
-
|
|
508
|
+
showSummaryAndExit();
|
|
461
509
|
process.exit(0);
|
|
462
510
|
}
|
|
463
511
|
|