@trans-ai/trans-code 0.5.0 → 0.6.1

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.
@@ -0,0 +1,31 @@
1
+ # 先输 key 再选模型 — 设计
2
+
3
+ 日期:2026-11-21 · 状态:已确认(会话内)
4
+
5
+ ## 意图
6
+
7
+ 内置厂商的 /models 流程改为"key 优先":首次使用先输 key,再展示**线上实时**模型列表,避免首次用户只看到可能过期的 curated 兜底。对齐 custom 网关流程已有的顺序(baseurl → key → live 列表)。
8
+
9
+ ## 行为
10
+
11
+ ```
12
+ /models → 选厂商(非 custom)
13
+ ├─ 已存 key → 直接进模型列表(实时拉取,现行为不变)
14
+ └─ 无 key → 先提示 apikey> → 用该 key 拉实时列表 → 选模型
15
+ ```
16
+
17
+ - 首次输入的 key 只存内存草稿,`applyModelSwitch` 验证通过才落盘(Esc 中途退出不留未验证 key)
18
+ - 选完模型:若 key 是本流程刚输的 → 直接验证(不重复问);老用户 → 保留现有"回车沿用"确认步(key 轮换入口不丢)
19
+ - 实时拉取失败/超时 → curated 兜底 + 提示行"(本地列表 · 保存 key 后显示线上实时列表)"
20
+
21
+ ## 同批打磨项
22
+
23
+ - A 新者优先排序:`listEndpointModels` 按版本号降序(数值段逐位比较,同版本基础名在前)
24
+ - B 切换提示:verify 探测到的实际模型与所选不符时,切换行追加"(实际生效 X)";`verifyModel` 返回值新增 `served` 字段
25
+ - C 兜底提示:`model_pick` 显示 curated 时标注本地列表来源
26
+
27
+ ## 测试
28
+
29
+ - A:model-list.test.ts 断言代表性集合的新者排序
30
+ - B:provider.test.ts 断言 `served` 返回与提示组合
31
+ - 流程重排为 REPL 状态机改动,靠 typecheck + 全套回归 + 手动验证
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trans-ai/trans-code",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
4
4
  "description": "AI-powered multi-model coding CLI",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -31,7 +31,7 @@ function stubModelsEndpoint(ids: string[]): string {
31
31
  }
32
32
 
33
33
  describe('listEndpointModels', () => {
34
- test('fetches the live model list from the endpoint', async () => {
34
+ test('fetches the live model list from the endpoint, newest generation first', async () => {
35
35
  const baseUrl = stubModelsEndpoint(['glm-5.1', 'glm-4.6', 'glm-5.3-flash']);
36
36
  const { saveConfig } = await import('../config.js');
37
37
  saveConfig({
@@ -40,13 +40,41 @@ describe('listEndpointModels', () => {
40
40
  });
41
41
 
42
42
  const models = await listEndpointModels('myhub');
43
- expect(models).toEqual(['glm-4.6', 'glm-5.1', 'glm-5.3-flash']); // sorted
43
+ expect(models).toEqual(['glm-5.3-flash', 'glm-5.1', 'glm-4.6']); // newest first
44
+ });
45
+
46
+ test('orders newest generation first: base name before variants, variants before older lines', async () => {
47
+ const baseUrl = stubModelsEndpoint([
48
+ 'glm-4.5-air',
49
+ 'glm-5.3-flashx-legal',
50
+ 'glm-4.6',
51
+ 'glm-5.3',
52
+ 'glm-5.3-flashx',
53
+ 'glm-5.3-flash',
54
+ 'glm-5-turbo',
55
+ ]);
56
+ const { saveConfig } = await import('../config.js');
57
+ saveConfig({
58
+ apiKeys: { custom: 'k' },
59
+ profiles: { gen: { baseUrl, model: 'glm-4.6', keyId: 'custom' } },
60
+ });
61
+
62
+ const models = await listEndpointModels('gen');
63
+ expect(models).toEqual([
64
+ 'glm-5.3',
65
+ 'glm-5.3-flash',
66
+ 'glm-5.3-flashx',
67
+ 'glm-5.3-flashx-legal',
68
+ 'glm-5-turbo',
69
+ 'glm-4.6',
70
+ 'glm-4.5-air',
71
+ ]);
44
72
  });
45
73
 
46
74
  test('override form queries an unsaved custom gateway with its key', async () => {
47
75
  const baseUrl = stubModelsEndpoint(['m1', 'm2']);
48
76
  const models = await listEndpointModels('', { baseUrl, apiKey: 'k' });
49
- expect(models).toEqual(['m1', 'm2']);
77
+ expect(models).toEqual(['m2', 'm1']); // newest-first heuristic: m2 > m1
50
78
  });
51
79
 
52
80
  test('returns an empty list on failure so callers can fall back', async () => {
@@ -13,6 +13,7 @@ import {
13
13
  vendorModelSpec,
14
14
  vendorModels,
15
15
  verifyModel,
16
+ switchNote,
16
17
  } from './provider.js';
17
18
 
18
19
  let configDir: string;
@@ -45,7 +46,7 @@ describe('GLM Coding Plan preset', () => {
45
46
  registerApiKey('glmc', 'test-key');
46
47
  const provider = createModel('glmc');
47
48
  expect(provider.config.baseUrl).toContain('/api/coding/');
48
- expect(provider.config.model).toBe('glm-4.6');
49
+ expect(provider.config.model).toBe('glm-5.3');
49
50
  });
50
51
 
51
52
  test('appears in the model list for /models', () => {
@@ -64,8 +65,24 @@ describe('vendor model lists', () => {
64
65
 
65
66
  test('glm lists the current model line', () => {
66
67
  const glm = vendorModels('glm');
68
+ // The glm-5.x generation is what the endpoints actually serve now;
69
+ // glm-4.6/4.5 live on as server-side aliases. glm-4-flash is retired.
70
+ expect(glm).toContain('glm-5.3');
71
+ expect(glm).toContain('glm-5.3-flash');
67
72
  expect(glm).toContain('glm-4.6');
68
- expect(glm).toContain('glm-4.5');
73
+ expect(glm).not.toContain('glm-4-flash');
74
+ });
75
+
76
+ test('glmc lists the current model line of the coding endpoint', () => {
77
+ const glmc = vendorModels('glmc');
78
+ expect(glmc).toContain('glm-5.3');
79
+ expect(glmc).toContain('glm-5.3-flash');
80
+ expect(glmc).toContain('glm-4.6');
81
+ });
82
+
83
+ test('registry defaults resolve to models the endpoints actually serve', () => {
84
+ expect(resolveModel('glm').model).toBe('glm-5.3');
85
+ expect(resolveModel('glmc').model).toBe('glm-5.3');
69
86
  });
70
87
 
71
88
  test('deepseek lists the current model line', () => {
@@ -121,3 +138,16 @@ describe('verifyModel', () => {
121
138
  expect(result.message).toMatch(/key/i);
122
139
  });
123
140
  });
141
+
142
+ describe('switchNote', () => {
143
+ test('plain switch line when the endpoint serves the picked name', () => {
144
+ expect(switchNote('glmc/glm-5.3', 'glm-5.3', 'glm-5.3')).toBe('已切换到 glmc/glm-5.3');
145
+ expect(switchNote('glmc/glm-5.3', 'glm-5.3', undefined)).toBe('已切换到 glmc/glm-5.3');
146
+ });
147
+
148
+ test('appends the effectively served model when it differs from the pick', () => {
149
+ expect(switchNote('glmc/glm-4.6', 'glm-4.6', 'glm-5.3-flash')).toBe(
150
+ '已切换到 glmc/glm-4.6(实际生效 glm-5.3-flash)',
151
+ );
152
+ });
153
+ });
@@ -44,9 +44,9 @@ const MODEL_REGISTRY: Record<ModelId, ModelConfig> = {
44
44
  envKey: 'DEEPSEEK_API_KEY',
45
45
  },
46
46
  glm: {
47
- name: 'GLM-4',
47
+ name: 'GLM',
48
48
  provider: 'openai',
49
- model: 'glm-4',
49
+ model: 'glm-5.3',
50
50
  baseUrl: 'https://open.bigmodel.cn/api/paas/v4',
51
51
  envKey: 'GLM_API_KEY',
52
52
  },
@@ -56,7 +56,7 @@ const MODEL_REGISTRY: Record<ModelId, ModelConfig> = {
56
56
  // The GLM Coding Plan subscription only bills against the dedicated
57
57
  // coding endpoint; the standard /api/paas/v4 endpoint answers 429
58
58
  // "余额不足或无可用资源包" because the plan is not applied there.
59
- model: 'glm-4.6',
59
+ model: 'glm-5.3',
60
60
  baseUrl: 'https://open.bigmodel.cn/api/coding/paas/v4',
61
61
  envKey: 'GLM_API_KEY',
62
62
  },
@@ -88,8 +88,8 @@ const VENDOR_MODELS: Partial<Record<ModelId, string[]>> = {
88
88
  opus: ['claude-opus-4-20250514', 'claude-sonnet-4-20250514'],
89
89
  gpt: ['gpt-4o', 'gpt-4o-mini'],
90
90
  deepseek: ['deepseek-v4-pro', 'deepseek-flash'],
91
- glm: ['glm-4.6', 'glm-4.5', 'glm-4.5-air', 'glm-4-flash'],
92
- glmc: ['glm-4.6', 'glm-4.5'],
91
+ glm: ['glm-5.3', 'glm-5.3-flash', 'glm-5.2', 'glm-5.1', 'glm-4.6', 'glm-4.5', 'glm-4.5-air'],
92
+ glmc: ['glm-5.3', 'glm-5.3-flash', 'glm-5.2', 'glm-4.6', 'glm-4.5'],
93
93
  minimax: ['MiniMax-Text-01'],
94
94
  kimi: ['moonshot-v1-128k', 'moonshot-v1-8k'],
95
95
  };
@@ -462,7 +462,7 @@ function buildChatModel(
462
462
  export async function verifyModel(
463
463
  spec: string,
464
464
  apiKeyOverride?: string,
465
- ): Promise<{ ok: boolean; message: string }> {
465
+ ): Promise<{ ok: boolean; message: string; served?: string }> {
466
466
  const resolved = resolveModel(spec);
467
467
  const apiKey = apiKeyOverride?.trim() || lookupApiKey(resolved.id);
468
468
  if (!apiKey) {
@@ -481,6 +481,7 @@ export async function verifyModel(
481
481
  const served = response?.response_metadata?.model_name;
482
482
  return {
483
483
  ok: true,
484
+ served,
484
485
  message: `连通正常${served ? `(实际模型 ${served})` : ''}`,
485
486
  };
486
487
  } catch (error) {
@@ -489,6 +490,18 @@ export async function verifyModel(
489
490
  }
490
491
  }
491
492
 
493
+ /**
494
+ * Switch-line copy for applyModelSwitch: appends the effectively served
495
+ * model when the gateway maps the picked name onto a different one
496
+ * (e.g. glm-4.6 → glm-5.3-flash).
497
+ */
498
+ export function switchNote(displayName: string, pickedModel: string, served?: string): string {
499
+ if (served && served !== pickedModel) {
500
+ return `已切换到 ${displayName}(实际生效 ${served})`;
501
+ }
502
+ return `已切换到 ${displayName}`;
503
+ }
504
+
492
505
  /** @deprecated Use createModel instead. Kept for the existing REPL. */
493
506
  export function createProviderWithKey(id: string, apiKey: string): TransProvider {
494
507
  const config = MODEL_REGISTRY[id as ModelId];
@@ -581,6 +594,25 @@ export function getRouting(): Record<string, string> {
581
594
  return { ...(loadConfig().routing ?? {}) };
582
595
  }
583
596
 
597
+ /**
598
+ * Newest-generation-first ordering for a live model list: numeric runs
599
+ * compare pairwise, descending ('glm-5.3' > 'glm-4.6' > 'glm-4.5-air');
600
+ * on a version tie the shorter base name leads ('glm-5.3' before
601
+ * 'glm-5.3-flashx'), then alphabetical.
602
+ */
603
+ function newestFirst(a: string, b: string): number {
604
+ const digits = (s: string): number[] => (s.match(/\d+/g) ?? []).map(Number);
605
+ const na = digits(a);
606
+ const nb = digits(b);
607
+ for (let i = 0; i < Math.max(na.length, nb.length); i++) {
608
+ const da = na[i] ?? -1;
609
+ const db = nb[i] ?? -1;
610
+ if (da !== db) return db - da;
611
+ }
612
+ if (a.length !== b.length) return a.length - b.length;
613
+ return a.localeCompare(b);
614
+ }
615
+
584
616
  /**
585
617
  * Live model list from an endpoint's OpenAI-compatible GET /models, so the
586
618
  * /models picker shows what the gateway actually serves (Zhipu's coding
@@ -590,7 +622,7 @@ export function getRouting(): Record<string, string> {
590
622
  */
591
623
  export async function listEndpointModels(
592
624
  specOrId: string,
593
- override?: { baseUrl: string; apiKey?: string },
625
+ override?: { baseUrl?: string; apiKey?: string },
594
626
  ): Promise<string[]> {
595
627
  try {
596
628
  const baseUrl = (override?.baseUrl ?? baseUrlFor(resolveModel(specOrId)))?.replace(/\/$/, '');
@@ -609,7 +641,7 @@ export async function listEndpointModels(
609
641
  const ids = (body.data ?? [])
610
642
  .map((entry) => entry?.id)
611
643
  .filter((id): id is string => typeof id === 'string' && id.length > 0);
612
- return [...new Set(ids)].sort();
644
+ return [...new Set(ids)].sort(newestFirst);
613
645
  } catch {
614
646
  return [];
615
647
  }
@@ -91,7 +91,7 @@ describe('role routing', () => {
91
91
  test('resolveRole maps a role through to the profile model', () => {
92
92
  setRouting('analysis', 'glmc');
93
93
  const resolved = resolveRole('analysis');
94
- expect(resolved?.model).toBe('glm-4.6');
94
+ expect(resolved?.model).toBe('glm-5.3');
95
95
  expect(resolved?.baseUrl).toContain('/api/coding/');
96
96
  });
97
97
 
@@ -1,4 +1,4 @@
1
- import { Box, Text, useInput, useApp } from 'ink';
1
+ import { Box, Text, useInput, useApp, useStdout } from 'ink';
2
2
  import { useState, useCallback, useEffect, useMemo, useRef } from 'react';
3
3
  import path from 'node:path';
4
4
  import { findCommand, getCommands, type CommandContext } from '../commands.js';
@@ -13,6 +13,7 @@ import {
13
13
  vendorModelSpec,
14
14
  vendorModels,
15
15
  verifyModel,
16
+ switchNote,
16
17
  type ModelId,
17
18
  } from '../provider/provider.js';
18
19
  import { loadConfig } from '../config.js';
@@ -34,6 +35,7 @@ import {
34
35
  slashQuery,
35
36
  } from './slash-completion.js';
36
37
  import { resolveSubmitInput } from './submit.js';
38
+ import { historyRule } from './history-rule.js';
37
39
  import { renderDiff } from './diff-render.js';
38
40
  import { createTurnStats, recordCall, shouldCollapse, summaryLine } from './turn-summary.js';
39
41
  import { buildSystemPrompt, INIT_PROMPT, loadProjectContext } from '../agent/system-prompt.js';
@@ -50,6 +52,7 @@ type PromptPhase =
50
52
  | 'model_pick'
51
53
  | 'model_name'
52
54
  | 'custom_baseurl'
55
+ | 'vendor_apikey'
53
56
  | 'model_apikey'
54
57
  | 'model_check'
55
58
  | 'permission';
@@ -62,6 +65,7 @@ interface REPLProps {
62
65
 
63
66
  export default function REPL({ ctx, updateNotice }: REPLProps) {
64
67
  const { exit } = useApp();
68
+ const { stdout } = useStdout();
65
69
  const [input, setInput] = useState('');
66
70
  // Multiple keystrokes can be handled in one React batch before a
67
71
  // re-render; closures over `input` would see stale values (e.g. the
@@ -101,6 +105,8 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
101
105
  const [keyHint, setKeyHint] = useState<string | null>(null);
102
106
  const [customBaseDraft, setCustomBaseDraft] = useState('');
103
107
  const [customKeyDraft, setCustomKeyDraft] = useState('');
108
+ // Key typed at the vendor step (first-time setup) before any model pick.
109
+ const [vendorKeyDraft, setVendorKeyDraft] = useState('');
104
110
 
105
111
  const models = getAvailableModels();
106
112
  // Bun's scheduler can drop the render flush for updates issued from the
@@ -405,19 +411,21 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
405
411
  );
406
412
 
407
413
  const applyModelSwitch = useCallback(
408
- (spec: string, displayName: string, apiKey: string, checkMessage: string) => {
414
+ (spec: string, displayName: string, apiKey: string, checkMessage: string, served?: string) => {
409
415
  registerApiKey(spec.split(':')[0]!, apiKey);
410
416
  ctx.setModelId(spec);
411
417
  setPreferredModel(spec);
418
+ const pickedModel = spec.split(':').pop() ?? displayName;
412
419
  addHistory({
413
420
  input: '••••••••',
414
- output: `${checkMessage} — 已切换到 ${displayName}`,
421
+ output: `${checkMessage} — ${switchNote(displayName, pickedModel, served)}`,
415
422
  });
416
423
  setPendingSpec(null);
417
424
  setPendingDisplayName('');
418
425
  setKeyHint(null);
419
426
  setCustomBaseDraft('');
420
427
  setCustomKeyDraft('');
428
+ setVendorKeyDraft('');
421
429
  setVendor(null);
422
430
  setPhase('idle');
423
431
  dragFlush();
@@ -435,7 +443,7 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
435
443
  setPhase('model_check');
436
444
  const result = await verifyModel(spec, apiKey);
437
445
  if (result.ok) {
438
- applyModelSwitch(spec, displayName, apiKey, `✓ ${result.message}`);
446
+ applyModelSwitch(spec, displayName, apiKey, `✓ ${result.message}`, result.served);
439
447
  return;
440
448
  }
441
449
  addHistory({
@@ -451,6 +459,35 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
451
459
 
452
460
  const handleApiKey = useCallback(
453
461
  async (value: string) => {
462
+ // Key-first vendor setup: the key unlocks the live model list before
463
+ // any model is picked (first-time use — no saved key yet).
464
+ if (phase === 'vendor_apikey') {
465
+ const apiKey = value.trim();
466
+ if (!apiKey) {
467
+ addHistory({ input: '••••••••', output: 'API key 不能为空。' });
468
+ return;
469
+ }
470
+ const vendor = pendingModel!;
471
+ setVendorKeyDraft(apiKey);
472
+ setPhase('model_pick');
473
+ setPickOptions(vendorModels(vendor));
474
+ setPickCursor(0);
475
+ setPickLive(false);
476
+ setPickLoading(true);
477
+ commitInput('');
478
+ const live = await listEndpointModels(vendor, { apiKey });
479
+ if (pendingModelRef.current === vendor) {
480
+ if (live.length > 0) {
481
+ setPickOptions(live);
482
+ setPickCursor(0);
483
+ setPickLive(true);
484
+ }
485
+ setPickLoading(false);
486
+ }
487
+ dragFlush();
488
+ return;
489
+ }
490
+
454
491
  // Custom-gateway setup: collect the key, then pick the model from the
455
492
  // gateway's live list instead of asking for a blind model name.
456
493
  if (pendingSpec === null && pendingModel === null && customBaseDraft) {
@@ -486,13 +523,14 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
486
523
  await finalizeSelection(spec, pendingDisplayName, apiKey);
487
524
  },
488
525
  [
526
+ phase,
489
527
  pendingSpec,
490
528
  pendingModel,
491
529
  pendingDisplayName,
492
530
  customBaseDraft,
493
531
  addHistory,
494
532
  finalizeSelection,
495
- commitInput,
533
+ commitInput,
496
534
  dragFlush,
497
535
  ],
498
536
  );
@@ -503,7 +541,7 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
503
541
  const trimmed = resolveSubmitInput(phase, raw);
504
542
  if (trimmed === null) return;
505
543
 
506
- if (phase === 'model_apikey' || phase === 'model_check') {
544
+ if (phase === 'vendor_apikey' || phase === 'model_apikey' || phase === 'model_check') {
507
545
  await handleApiKey(trimmed);
508
546
  commitInput('');
509
547
  return;
@@ -737,6 +775,14 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
737
775
  setPickOptions(vendorModels(selected.id));
738
776
  setPickCursor(0);
739
777
  setPickLive(false);
778
+ setVendorKeyDraft('');
779
+ // Key-first: without a saved key the live /models call would 401,
780
+ // so ask for the key up front and fetch the real list with it.
781
+ if (!lookupApiKey(selected.id)) {
782
+ setPhase('vendor_apikey');
783
+ commitInput('');
784
+ return;
785
+ }
740
786
  setPhase('model_pick');
741
787
  commitInput('');
742
788
 
@@ -788,6 +834,14 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
788
834
  // Custom gateway: model chosen from the live list.
789
835
  setCustomModel({ baseUrl: customBaseDraft, model: modelName });
790
836
  void finalizeSelection('custom', `custom/${modelName}`, customKeyDraft);
837
+ } else if (vendorKeyDraft) {
838
+ // Key-first flow: the key was just typed — verify without
839
+ // re-asking for it (applyModelSwitch persists it on success).
840
+ void finalizeSelection(
841
+ vendorModelSpec(pendingModel!, modelName),
842
+ `${pendingModel}/${modelName}`,
843
+ vendorKeyDraft,
844
+ );
791
845
  } else {
792
846
  beginKeyStep(vendorModelSpec(pendingModel!, modelName), `${pendingModel}/${modelName}`);
793
847
  }
@@ -907,6 +961,8 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
907
961
  ? 'baseurl> '
908
962
  : phase === 'model_apikey'
909
963
  ? keyHint ? `apikey (回车沿用 ${keyHint})> ` : 'apikey> '
964
+ : phase === 'vendor_apikey'
965
+ ? 'apikey> '
910
966
  : phase === 'permission'
911
967
  ? 'allow?> '
912
968
  : '> ';
@@ -916,9 +972,13 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
916
972
  {history.map((entry, i) => (
917
973
  <Box key={i} flexDirection="column">
918
974
  {entry.input && (
919
- <Box>
920
- <Text color="green">&gt; </Text>
921
- <Text>{entry.input}</Text>
975
+ <Box flexDirection="column">
976
+ <Text color="gray" dimColor>{historyRule(stdout?.columns ?? 80)}</Text>
977
+ <Box>
978
+ <Text color="green" bold>&gt; </Text>
979
+ <Text color="cyan" bold>{entry.input}</Text>
980
+ </Box>
981
+ <Text color="gray" dimColor>{historyRule(stdout?.columns ?? 80)}</Text>
922
982
  </Box>
923
983
  )}
924
984
  {entry.output && (
@@ -988,6 +1048,9 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
988
1048
  </Box>
989
1049
  {pickLoading && <Text color="gray" dimColor>… 正在从网关获取实时模型列表</Text>}
990
1050
  {!pickLoading && pickLive && <Text color="gray" dimColor>(网关实时列表)</Text>}
1051
+ {!pickLoading && !pickLive && (
1052
+ <Text color="gray" dimColor>(本地列表 · 保存 key 后显示线上实时列表)</Text>
1053
+ )}
991
1054
  <Text color="gray" dimColor>↑↓ 选择模型 · Enter 确认</Text>
992
1055
  </Box>
993
1056
  )}
@@ -0,0 +1,16 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+ import { historyRule } from './history-rule.js';
3
+
4
+ describe('historyRule', () => {
5
+ test('fills the terminal width minus a small margin', () => {
6
+ expect(historyRule(80)).toHaveLength(78);
7
+ expect(historyRule(120)).toHaveLength(118);
8
+ });
9
+
10
+ test('uses the box-drawing dash and never collapses on narrow terminals', () => {
11
+ expect(historyRule(80).startsWith('─')).toBe(true);
12
+ expect(historyRule(20)).toHaveLength(18);
13
+ expect(historyRule(4).length).toBeGreaterThanOrEqual(10); // clamped floor
14
+ expect(historyRule(0).length).toBeGreaterThanOrEqual(10);
15
+ });
16
+ });
@@ -0,0 +1,12 @@
1
+ /** Minimum rule length so narrow terminals still show a visible divider. */
2
+ const MIN_RULE = 10;
3
+ /** Right margin so the rule never wraps onto the next line. */
4
+ const MARGIN = 2;
5
+
6
+ /**
7
+ * The horizontal rule drawn around a user question in the chat history.
8
+ * Box-drawing dash repeated to the terminal width minus a small margin.
9
+ */
10
+ export function historyRule(columns: number): string {
11
+ return '─'.repeat(Math.max(MIN_RULE, columns - MARGIN));
12
+ }
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Auto-generated from package.json by scripts/sync-version.ts (npm version hook)
2
- export const VERSION = '0.5.0';
2
+ export const VERSION = '0.6.1';