@trans-ai/trans-code 0.0.0-stage → 0.1.0
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/README.md +203 -2
- package/bin/transcode.ts +4 -0
- package/docs/ACP.md +231 -0
- package/package.json +42 -4
- package/src/acp/protocol.ts +115 -0
- package/src/acp/server.ts +202 -0
- package/src/acp/session.ts +269 -0
- package/src/acp/transport.ts +216 -0
- package/src/agent/loop.ts +334 -0
- package/src/agent/system-prompt.ts +86 -0
- package/src/agent/tools.ts +483 -0
- package/src/cli.ts +53 -0
- package/src/commands.ts +61 -0
- package/src/main.tsx +62 -0
- package/src/provider/provider.ts +373 -0
- package/src/screens/REPL.tsx +282 -0
- package/src/tui/cli.tsx +2 -0
- package/src/tui/keyed-stdin.ts +83 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Ink reads stdin in paused mode ('readable' event + read() loop) and
|
|
5
|
+
* treats each chunk as a single keypress. Burst input (paste, terminal
|
|
6
|
+
* multiplexer send-keys, fast typing coalesced by the runtime) therefore
|
|
7
|
+
* arrives glued — e.g. "help\r" — and keys like Enter/Escape silently
|
|
8
|
+
* stop working. Bun's stdin layer makes this worse by merging even
|
|
9
|
+
* time-separated writes into one chunk.
|
|
10
|
+
*
|
|
11
|
+
* This proxy reads the real stdin in flowing mode, splits every buffer
|
|
12
|
+
* into discrete keystrokes (one escape sequence, or one character per
|
|
13
|
+
* key), and hands them to Ink ONE PER read() call — chunk coalescing is
|
|
14
|
+
* impossible on any runtime.
|
|
15
|
+
*
|
|
16
|
+
* Implements exactly the subset of the stdin API Ink uses:
|
|
17
|
+
* addListener/removeListener('readable'), read(), setEncoding(),
|
|
18
|
+
* setRawMode(), ref(), unref(), isTTY.
|
|
19
|
+
*/
|
|
20
|
+
class KeyedStdin extends EventEmitter {
|
|
21
|
+
readonly isTTY = true;
|
|
22
|
+
private queue: string[] = [];
|
|
23
|
+
private readonly realStdin: NodeJS.ReadStream & {
|
|
24
|
+
setRawMode(mode: boolean): unknown;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
constructor(realStdin: NodeJS.ReadStream & { setRawMode(mode: boolean): unknown }) {
|
|
28
|
+
super();
|
|
29
|
+
this.realStdin = realStdin;
|
|
30
|
+
realStdin.setEncoding('utf8');
|
|
31
|
+
realStdin.on('data', (chunk: string) => {
|
|
32
|
+
if (!chunk) return;
|
|
33
|
+
if (chunk.charCodeAt(0) === 0x1b) {
|
|
34
|
+
// Escape sequences arrive atomically — keep as one key.
|
|
35
|
+
this.pushKey(chunk);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
// Plain characters: enqueue one key per character (for..of splits
|
|
39
|
+
// by code point, so multi-byte input (e.g. CJK) stays intact).
|
|
40
|
+
for (const ch of chunk) this.pushKey(ch);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
setEncoding(_encoding: string): void {
|
|
45
|
+
// Chunks pushed in the constructor are already strings.
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
setRawMode(mode: boolean): void {
|
|
49
|
+
this.realStdin.setRawMode(mode);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
ref(): void {
|
|
53
|
+
// Real stdin stays ref'd for the lifetime of the process.
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Ink calls unref() when the last raw-mode consumer unmounts. The
|
|
58
|
+
* flowing-mode listener on the real stdin keeps the event loop alive,
|
|
59
|
+
* so it must be parked here or the process never exits after `exit`.
|
|
60
|
+
*/
|
|
61
|
+
unref(): void {
|
|
62
|
+
this.realStdin.pause();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Always returns at most one keystroke — never a merged chunk. */
|
|
66
|
+
read(): string | null {
|
|
67
|
+
return this.queue.shift() ?? null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
pushKey(key: string): void {
|
|
71
|
+
this.queue.push(key);
|
|
72
|
+
// Emit synchronously — every 'readable' sees exactly one queued key,
|
|
73
|
+
// and there is no scheduling window in which listeners can change.
|
|
74
|
+
this.emit('readable');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function createKeyedStdin(): NodeJS.ReadStream {
|
|
79
|
+
const proxy = new KeyedStdin(
|
|
80
|
+
process.stdin as NodeJS.ReadStream & { setRawMode(mode: boolean): unknown },
|
|
81
|
+
);
|
|
82
|
+
return proxy as unknown as NodeJS.ReadStream;
|
|
83
|
+
}
|
package/src/version.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const VERSION = '0.1.0';
|