cueme 0.1.8 → 0.1.10
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 +4 -2
- package/src/cli.js +83 -0
- package/src/handler.js +23 -10
- package/src/io.js +14 -34
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cueme",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "Cue command protocol adapter (stdin/stdout JSON)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"files": [
|
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
"prepare": "node -c src/cli.js && node -c src/handler.js"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"better-sqlite3": "^12.6.0"
|
|
25
|
+
"better-sqlite3": "^12.6.0",
|
|
26
|
+
"chardet": "^2.1.1",
|
|
27
|
+
"iconv-lite": "^0.7.2"
|
|
26
28
|
}
|
|
27
29
|
}
|
package/src/cli.js
CHANGED
|
@@ -102,6 +102,7 @@ async function main() {
|
|
|
102
102
|
' cueme proto init',
|
|
103
103
|
' cueme proto ls',
|
|
104
104
|
' cueme proto path <agent>',
|
|
105
|
+
' cueme fix <issue>',
|
|
105
106
|
' cueme join <agent_runtime>',
|
|
106
107
|
' cueme cue <agent_id> -',
|
|
107
108
|
' cueme pause <agent_id> [prompt|-]',
|
|
@@ -138,6 +139,88 @@ async function main() {
|
|
|
138
139
|
return;
|
|
139
140
|
}
|
|
140
141
|
|
|
142
|
+
if (sub === 'fix') {
|
|
143
|
+
const issue = pos[0];
|
|
144
|
+
if (!issue) {
|
|
145
|
+
process.stderr.write('error: missing <issue>\n');
|
|
146
|
+
process.stderr.write('Available fixes:\n');
|
|
147
|
+
process.stderr.write(' powershell_utf-8 Fix PowerShell encoding for Chinese characters\n');
|
|
148
|
+
process.exitCode = 2;
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (issue === 'powershell_utf-8') {
|
|
153
|
+
if (process.platform !== 'win32') {
|
|
154
|
+
process.stderr.write('This fix is only for Windows PowerShell\n');
|
|
155
|
+
process.exitCode = 1;
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const { execSync } = require('child_process');
|
|
160
|
+
const os = require('os');
|
|
161
|
+
const path = require('path');
|
|
162
|
+
|
|
163
|
+
try {
|
|
164
|
+
// Get PowerShell profile path
|
|
165
|
+
const profilePath = path.join(
|
|
166
|
+
os.homedir(),
|
|
167
|
+
'Documents',
|
|
168
|
+
'WindowsPowerShell',
|
|
169
|
+
'Microsoft.PowerShell_profile.ps1'
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
const encodingConfig = [
|
|
173
|
+
'$utf8NoBom = New-Object System.Text.UTF8Encoding($false)',
|
|
174
|
+
'[Console]::InputEncoding = $utf8NoBom',
|
|
175
|
+
'[Console]::OutputEncoding = $utf8NoBom',
|
|
176
|
+
'$OutputEncoding = $utf8NoBom',
|
|
177
|
+
].join('\n');
|
|
178
|
+
|
|
179
|
+
// Create PowerShell script to fix encoding
|
|
180
|
+
const psScript = [
|
|
181
|
+
`$profilePath = '${profilePath.replace(/\\/g, '\\')}'`,
|
|
182
|
+
`$encodingConfig = @'`,
|
|
183
|
+
encodingConfig,
|
|
184
|
+
`'@`,
|
|
185
|
+
'',
|
|
186
|
+
'$profileDir = Split-Path -Parent $profilePath',
|
|
187
|
+
'if (!(Test-Path $profileDir)) {',
|
|
188
|
+
' New-Item -Path $profileDir -ItemType Directory -Force | Out-Null',
|
|
189
|
+
'}',
|
|
190
|
+
'',
|
|
191
|
+
'if (!(Test-Path $profilePath)) {',
|
|
192
|
+
' New-Item -Path $profilePath -ItemType File -Force | Out-Null',
|
|
193
|
+
' Write-Host "Created PowerShell profile"',
|
|
194
|
+
'}',
|
|
195
|
+
'',
|
|
196
|
+
'$content = Get-Content $profilePath -Raw -ErrorAction SilentlyContinue',
|
|
197
|
+
'if ($content -notlike "*utf8NoBom*") {',
|
|
198
|
+
' Add-Content -Path $profilePath -Value "`n$encodingConfig"',
|
|
199
|
+
' Write-Host "Added UTF-8 encoding to PowerShell profile"',
|
|
200
|
+
' Write-Host "Please restart PowerShell for changes to take effect"',
|
|
201
|
+
'} else {',
|
|
202
|
+
' Write-Host "UTF-8 encoding already configured"',
|
|
203
|
+
'}',
|
|
204
|
+
].join('; ');
|
|
205
|
+
|
|
206
|
+
execSync(`powershell -NoProfile -Command "${psScript}"`, {
|
|
207
|
+
stdio: 'inherit',
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
} catch (err) {
|
|
211
|
+
process.stderr.write(`Failed to fix PowerShell encoding: ${err.message}\n`);
|
|
212
|
+
process.exitCode = 1;
|
|
213
|
+
}
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
process.stderr.write(`error: unknown issue: ${issue}\n`);
|
|
218
|
+
process.stderr.write('Available fixes:\n');
|
|
219
|
+
process.stderr.write(' powershell_utf-8 Fix PowerShell encoding for Chinese characters\n');
|
|
220
|
+
process.exitCode = 2;
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
|
|
141
224
|
if (sub === 'join') {
|
|
142
225
|
const agentRuntime = pos[0];
|
|
143
226
|
if (!agentRuntime) {
|
package/src/handler.js
CHANGED
|
@@ -139,20 +139,33 @@ async function handleJoin(db, agent_runtime) {
|
|
|
139
139
|
const project_dir = process.cwd();
|
|
140
140
|
const agent_terminal = detectAgentTerminal();
|
|
141
141
|
const normalized_runtime = normalizeAgentRuntime(agent_runtime);
|
|
142
|
+
|
|
143
|
+
let message =
|
|
144
|
+
`agent_id=${agent_id}\n` +
|
|
145
|
+
`project_dir=${project_dir}\n` +
|
|
146
|
+
`agent_terminal=${agent_terminal}\n` +
|
|
147
|
+
`agent_runtime=${normalized_runtime}\n\n`;
|
|
148
|
+
|
|
149
|
+
// Windows PowerShell encoding fix reminder
|
|
150
|
+
if (process.platform === 'win32') {
|
|
151
|
+
message +=
|
|
152
|
+
'Windows detected. To fix encoding issues with Chinese characters:\n' +
|
|
153
|
+
'1. Run: cueme fix powershell_utf-8\n' +
|
|
154
|
+
'2. Restart your terminal\n\n';
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
message +=
|
|
158
|
+
'Use this agent_id when calling: cueme cue <agent_id> -\n' +
|
|
159
|
+
'Then provide stdin with tag-block envelope (stdin MUST NOT be empty):\n' +
|
|
160
|
+
'<cueme_prompt>\n...\n</cueme_prompt>\n' +
|
|
161
|
+
'<cueme_payload>\n...\n</cueme_payload>\n\n' +
|
|
162
|
+
'Remember this agent_id (but do NOT store it in any memory module). Before ending this session, call cue to provide a final summary, ask a question, or make a request.';
|
|
163
|
+
|
|
142
164
|
return {
|
|
143
165
|
ok: true,
|
|
144
166
|
data: {
|
|
145
167
|
agent_id,
|
|
146
|
-
message
|
|
147
|
-
`agent_id=${agent_id}\n` +
|
|
148
|
-
`project_dir=${project_dir}\n` +
|
|
149
|
-
`agent_terminal=${agent_terminal}\n` +
|
|
150
|
-
`agent_runtime=${normalized_runtime}\n\n` +
|
|
151
|
-
'Use this agent_id when calling: cueme cue <agent_id> -\n' +
|
|
152
|
-
'Then provide stdin with tag-block envelope (stdin MUST NOT be empty):\n' +
|
|
153
|
-
'<cueme_prompt>\n...\n</cueme_prompt>\n' +
|
|
154
|
-
'<cueme_payload>\n...\n</cueme_payload>\n\n' +
|
|
155
|
-
'Remember this agent_id (but do NOT store it in any memory module). Before ending this session, call cue to provide a final summary, ask a question, or make a request.',
|
|
168
|
+
message,
|
|
156
169
|
},
|
|
157
170
|
};
|
|
158
171
|
}
|
package/src/io.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
const chardet = require('chardet');
|
|
2
|
+
const iconv = require('iconv-lite');
|
|
3
|
+
|
|
1
4
|
function readAllStdin() {
|
|
2
5
|
if (process.stdin.isTTY) return Promise.resolve('');
|
|
3
6
|
return new Promise((resolve, reject) => {
|
|
@@ -9,7 +12,7 @@ function readAllStdin() {
|
|
|
9
12
|
const buf = Buffer.concat(chunks);
|
|
10
13
|
if (!buf || buf.length === 0) return resolve('');
|
|
11
14
|
|
|
12
|
-
// BOM detection
|
|
15
|
+
// BOM detection (fast path for common cases)
|
|
13
16
|
if (buf.length >= 3 && buf[0] === 0xef && buf[1] === 0xbb && buf[2] === 0xbf) {
|
|
14
17
|
return resolve(buf.slice(3).toString('utf8'));
|
|
15
18
|
}
|
|
@@ -26,42 +29,19 @@ function readAllStdin() {
|
|
|
26
29
|
return resolve(swapped.toString('utf16le'));
|
|
27
30
|
}
|
|
28
31
|
|
|
29
|
-
//
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
for (let i = 0; i < sampleLen; i += 1) {
|
|
39
|
-
if (i % 2 === 0) {
|
|
40
|
-
evenTotal += 1;
|
|
41
|
-
if (buf[i] === 0x00) evenZeros += 1;
|
|
42
|
-
} else {
|
|
43
|
-
oddTotal += 1;
|
|
44
|
-
if (buf[i] === 0x00) oddZeros += 1;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const oddZeroRatio = oddTotal > 0 ? oddZeros / oddTotal : 0;
|
|
49
|
-
const evenZeroRatio = evenTotal > 0 ? evenZeros / evenTotal : 0;
|
|
50
|
-
|
|
51
|
-
if (oddZeroRatio > 0.6 && evenZeroRatio < 0.2) {
|
|
52
|
-
return resolve(buf.toString('utf16le'));
|
|
53
|
-
}
|
|
54
|
-
} else {
|
|
55
|
-
let zeros = 0;
|
|
56
|
-
for (let i = 0; i < sampleLen; i += 1) {
|
|
57
|
-
if (buf[i] === 0x00) zeros += 1;
|
|
58
|
-
}
|
|
59
|
-
const zeroRatio = zeros / sampleLen;
|
|
60
|
-
if (zeroRatio > 0.2) {
|
|
61
|
-
return resolve(buf.toString('utf16le'));
|
|
32
|
+
// Use chardet for automatic encoding detection
|
|
33
|
+
const detected = chardet.detect(buf);
|
|
34
|
+
|
|
35
|
+
if (detected && detected !== 'UTF-8') {
|
|
36
|
+
try {
|
|
37
|
+
return resolve(iconv.decode(buf, detected));
|
|
38
|
+
} catch {
|
|
39
|
+
// Fallback to UTF-8 if decode fails
|
|
40
|
+
return resolve(buf.toString('utf8'));
|
|
62
41
|
}
|
|
63
42
|
}
|
|
64
43
|
|
|
44
|
+
// Default to UTF-8
|
|
65
45
|
return resolve(buf.toString('utf8'));
|
|
66
46
|
});
|
|
67
47
|
process.stdin.on('error', reject);
|