@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 +1 -1
- package/src/screens/REPL.tsx +10 -8
- package/src/sessions/compact.test.ts +18 -18
- package/src/sessions/compact.ts +14 -11
- package/src/version.ts +1 -1
package/package.json
CHANGED
package/src/screens/REPL.tsx
CHANGED
|
@@ -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,
|
|
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
|
-
|
|
266
|
-
|
|
267
|
-
|
|
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,
|
|
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('
|
|
108
|
-
test('
|
|
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: '
|
|
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(
|
|
114
|
+
new AIMessage('回答'.repeat(200)),
|
|
115
115
|
];
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
expect(
|
|
119
|
-
|
|
120
|
-
expect(
|
|
121
|
-
expect(
|
|
122
|
-
|
|
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
|
|
127
|
-
const
|
|
128
|
-
expect(
|
|
129
|
-
|
|
130
|
-
|
|
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
|
});
|
package/src/sessions/compact.ts
CHANGED
|
@@ -106,27 +106,30 @@ export async function compressSession(
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
* system messages are
|
|
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
|
|
114
|
+
export function transcriptEntries(
|
|
114
115
|
summary: string | null,
|
|
115
116
|
messages: BaseMessage[],
|
|
116
117
|
oldTurnsCount?: number,
|
|
117
|
-
): string {
|
|
118
|
-
const
|
|
119
|
-
const lines: string[] = [];
|
|
118
|
+
): { input: string; output: string }[] {
|
|
119
|
+
const entries: { input: string; output: string }[] = [];
|
|
120
120
|
if (summary) {
|
|
121
|
-
|
|
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')
|
|
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)
|
|
131
|
+
if (text) entries.push({ input: '', output: text });
|
|
129
132
|
}
|
|
130
133
|
}
|
|
131
|
-
return
|
|
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.
|
|
2
|
+
export const VERSION = '0.8.1';
|