@trans-ai/trans-code 0.8.0 → 0.8.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trans-ai/trans-code",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "AI-powered multi-model coding CLI",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -30,7 +30,7 @@ import {
30
30
  type SessionRecord,
31
31
  } from '../sessions/store.js';
32
32
  import { listProjectSessions, resolveResumeTarget } from '../sessions/resume.js';
33
- import { KEEP_TURNS, compressSession, renderTranscript, splitTurns } from '../sessions/compact.js';
33
+ import { KEEP_TURNS, compressSession, transcriptEntries, splitTurns } from '../sessions/compact.js';
34
34
  import { walkFiles } from '../agent/tools/fs-utils.js';
35
35
  import { applyCompletion, filterFiles, mentionQuery } from './file-completion.js';
36
36
  import {
@@ -262,10 +262,11 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
262
262
  }
263
263
  }
264
264
  applyResume(finalRecord, inputLine);
265
- addHistory({
266
- input: inputLine,
267
- output: renderTranscript(summaryRef.current, messagesRef.current, oldTurns || undefined),
268
- });
265
+ // Restore in the original conversation form: each message becomes a
266
+ // history entry (rule-framed questions, full-length replies).
267
+ for (const entry of transcriptEntries(summaryRef.current, messagesRef.current, oldTurns || undefined)) {
268
+ addHistory(entry);
269
+ }
269
270
  dragFlush();
270
271
  };
271
272
 
@@ -770,10 +771,11 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
770
771
  saveSession(outcome.record);
771
772
  addHistory({
772
773
  input: trimmed,
773
- output:
774
- `已压缩:旧 ${turns.length - KEEP_TURNS} 轮提炼为前情提要,保留最近 ${KEEP_TURNS} 轮。\n` +
775
- renderTranscript(summaryRef.current, messagesRef.current),
774
+ output: `已压缩:旧 ${turns.length - KEEP_TURNS} 轮提炼为前情提要,保留最近 ${KEEP_TURNS} 轮。`,
776
775
  });
776
+ for (const entry of transcriptEntries(summaryRef.current, messagesRef.current)) {
777
+ addHistory(entry);
778
+ }
777
779
  } else {
778
780
  addHistory({ input: trimmed, output: `⚠ 压缩失败(${outcome.error ?? '未知'}),会话保持原样。` });
779
781
  }
@@ -1,7 +1,7 @@
1
1
  import { describe, expect, test } from 'bun:test';
2
2
  import { AIMessage, HumanMessage, SystemMessage, ToolMessage, type BaseMessage } from '@langchain/core/messages';
3
3
  import type { SessionRecord } from './store.js';
4
- import { KEEP_TURNS, TRANSCRIPT_LIMIT, compressSession, renderTranscript, splitTurns } from './compact.js';
4
+ import { KEEP_TURNS, TRANSCRIPT_LIMIT, compressSession, transcriptEntries, splitTurns } from './compact.js';
5
5
 
6
6
  function turn(n: number, text = 'x'): BaseMessage[] {
7
7
  return [new HumanMessage(`问题${n}:${text}`), new AIMessage(`回答${n}:${text}`)];
@@ -104,29 +104,29 @@ describe('compressSession', () => {
104
104
  });
105
105
  });
106
106
 
107
- describe('renderTranscript', () => {
108
- test('renders summary block plus human/ai pairs, skipping tool/system, capping line length', () => {
107
+ describe('transcriptEntries', () => {
108
+ test('digest first, then per-message entries: human→input, ai→output, full content, tool/system skipped', () => {
109
109
  const messages: BaseMessage[] = [
110
110
  new SystemMessage('sys'),
111
111
  new HumanMessage('问题甲'),
112
- new AIMessage({ content: '调用', tool_calls: [{ id: 't1', name: 'bash', args: {} }] }),
112
+ new AIMessage({ content: '', tool_calls: [{ id: 't1', name: 'bash', args: {} }] }),
113
113
  new ToolMessage({ content: 'out', tool_call_id: 't1', name: 'bash' }),
114
- new AIMessage('回答'.repeat(100)),
114
+ new AIMessage('回答'.repeat(200)),
115
115
  ];
116
- const out = renderTranscript('前情文本', messages);
117
- expect(out).toContain('前情提要');
118
- expect(out).toContain('前情文本');
119
- expect(out).toContain('你: 问题甲');
120
- expect(out).toContain('AI:');
121
- expect(out).not.toContain('工具');
122
- const longest = Math.max(...out.split('\n').map((l) => l.length));
123
- expect(longest).toBeLessThanOrEqual(140);
116
+ const entries = transcriptEntries('前情文本', messages, 3);
117
+ // digest entry
118
+ expect(entries[0]).toEqual({ input: '', output: '📝 前情提要(旧 3 轮)\n前情文本' });
119
+ const rest = entries.slice(1);
120
+ expect(rest).toHaveLength(2);
121
+ expect(rest[0]).toEqual({ input: '问题甲', output: '' });
122
+ expect(rest[1]).toEqual({ input: '', output: '回答'.repeat(200) });
124
123
  });
125
124
 
126
- test('null summary renders turns only', () => {
127
- const out = renderTranscript(null, turn(1, '正文'));
128
- expect(out).not.toContain('前情提要');
129
- expect(out).toContain('你: 问题1:正文');
130
- expect(out).toContain('AI: 回答1:正文');
125
+ test('null summary yields turn entries only, no digest', () => {
126
+ const entries = transcriptEntries(null, turn(1, '正文'));
127
+ expect(entries).toEqual([
128
+ { input: '问题1:正文', output: '' },
129
+ { input: '', output: '回答1:正文' },
130
+ ]);
131
131
  });
132
132
  });
@@ -106,27 +106,30 @@ export async function compressSession(
106
106
  }
107
107
 
108
108
  /**
109
- * Render the resumed view: optional digest block (with the count of
110
- * compressed turns) plus the kept window as 你:/AI: lines. Tool activity and
111
- * system messages are not replayed.
109
+ * History entries for the restored view: optional digest first, then one
110
+ * entry per message — human turns as `input` (rule-framed highlight), AI
111
+ * replies as full-length `output`. Tool activity and system messages are
112
+ * not replayed. Rendering is the existing per-entry chat form.
112
113
  */
113
- export function renderTranscript(
114
+ export function transcriptEntries(
114
115
  summary: string | null,
115
116
  messages: BaseMessage[],
116
117
  oldTurnsCount?: number,
117
- ): string {
118
- const cap = (text: string): string => (text.length > 120 ? `${text.slice(0, 120)}…` : text);
119
- const lines: string[] = [];
118
+ ): { input: string; output: string }[] {
119
+ const entries: { input: string; output: string }[] = [];
120
120
  if (summary) {
121
- lines.push(`📝 前情提要${oldTurnsCount ? `(旧 ${oldTurnsCount} 轮)` : ''}`, summary, '');
121
+ entries.push({
122
+ input: '',
123
+ output: `📝 前情提要${oldTurnsCount ? `(旧 ${oldTurnsCount} 轮)` : ''}\n${summary}`,
124
+ });
122
125
  }
123
126
  for (const message of messages) {
124
127
  const kind = message.getType();
125
- if (kind === 'human') lines.push(`你: ${cap(contentText(message.content))}`);
128
+ if (kind === 'human') entries.push({ input: contentText(message.content), output: '' });
126
129
  else if (kind === 'ai') {
127
130
  const text = contentText(message.content);
128
- if (text) lines.push(`AI: ${cap(text)}`);
131
+ if (text) entries.push({ input: '', output: text });
129
132
  }
130
133
  }
131
- return lines.join('\n');
134
+ return entries;
132
135
  }
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.8.0';
2
+ export const VERSION = '0.8.1';