@aivin-labs/cli 1.0.68 → 1.0.78
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/bin/cli.mjs +74 -2
- package/bin/lib/docHandoff.mjs +111 -0
- package/bin/lib/openFile.mjs +41 -10
- package/bin/lib/remote/agentContract.mjs +26 -0
- package/bin/lib/remote/agentEvidence.mjs +2 -1
- package/bin/lib/remote/agentPreview.mjs +151 -0
- package/bin/lib/remote/client.mjs +75 -7
- package/bin/lib/remote/codingAgents.mjs +372 -106
- package/bin/lib/remote/constants.mjs +2 -0
- package/bin/lib/remote/desktop/desktopCast.mjs +3 -1
- package/bin/lib/remote/desktop/desktopCastCaptureSource.mjs +23 -4
- package/bin/lib/remote/desktop/desktopCastSource.mjs +2 -0
- package/bin/lib/remote/desktop/desktopWebRtc.mjs +2 -3
- package/bin/lib/remote/ephemeralAuth.mjs +99 -0
- package/bin/lib/remote/lightcodeAgent.mjs +1615 -0
- package/bin/lib/remote/localLlm.mjs +748 -576
- package/bin/lib/remote/localLlmLogin.mjs +293 -0
- package/bin/lib/remote/localLlmMembers.mjs +115 -0
- package/bin/lib/remote/localPolicy.mjs +345 -341
- package/bin/lib/remote/mascot/ask.mjs +30 -9
- package/bin/lib/remote/mascot/askHostSource.mjs +22 -8
- package/bin/lib/remote/mascot/emojiSource.mjs +60 -3
- package/bin/lib/remote/mascot/hostSource.mjs +9 -3
- package/bin/lib/remote/mascot/index.mjs +4 -2
- package/bin/lib/remote/mascot/localOpen.mjs +79 -0
- package/bin/lib/remote/mascot/strings.mjs +8 -5
- package/bin/lib/remote/orgComputerLicense.mjs +99 -0
- package/bin/lib/remote/toolHandlers.mjs +44 -4
- package/package.json +1 -1
|
@@ -47,6 +47,8 @@ export const DeviceEvent = Object.freeze({
|
|
|
47
47
|
EMBED: 'device:embed',
|
|
48
48
|
/** CLI → BE: sự kiện của một theo dõi (tệp mới / dòng log khớp) → BE chạy Automation Job gắn với nó. */
|
|
49
49
|
EVENT: 'device:event',
|
|
50
|
+
/** CLI → BE (21/11/2026): sự kiện đẩy từ LightCode (`job.finished`, `job.attention` — kể cả deploy xong / cần hỗ trợ). */
|
|
51
|
+
LIGHTCODE_EVENT: 'device:lightcode_event',
|
|
50
52
|
/** CLI → BE (29/10/2026): lời gọi đang chờ người bấm xác nhận trên máy — `{ call_id, extra_ms }`, BE lùi hạn chờ kết quả bấy nhiêu. */
|
|
51
53
|
HOLD: 'device:hold',
|
|
52
54
|
/** CLI → BE: đã lưu token mới BE cấp trong ack của HELLO (`rotate_token`) — BE bỏ token cũ. */
|
|
@@ -291,7 +291,9 @@ export function createDesktopCastManager({ dir = CAST_DIR, spawnImpl = spawn } =
|
|
|
291
291
|
} else if (msg.t === 'cursor_hidden') {
|
|
292
292
|
cursorHidden = msg.hidden === true;
|
|
293
293
|
} else if (msg.t === 'clipboard') {
|
|
294
|
-
|
|
294
|
+
// Ảnh / chụp màn hình: không kèm chữ, vẫn báo để người xem biết máy vừa copy.
|
|
295
|
+
const text = typeof msg.text === 'string' ? msg.text : '';
|
|
296
|
+
if (text || msg.changed === true) onClipboard?.(text ? { text } : {});
|
|
295
297
|
} else if (msg.t === 'secure_desktop') {
|
|
296
298
|
onSecureDesktop?.({ active: msg.active === true });
|
|
297
299
|
} else if (msg.t === 'capture') {
|
|
@@ -863,19 +863,36 @@ namespace AivinDesktopCast {
|
|
|
863
863
|
}
|
|
864
864
|
}
|
|
865
865
|
|
|
866
|
-
/**
|
|
866
|
+
/**
|
|
867
|
+
* Đồng bộ bộ nhớ tạm giữa máy từ xa và trình duyệt điều khiển. Mọi lần người dùng máy copy (kể cả ảnh, ảnh chụp màn hình) đều báo:
|
|
868
|
+
* người xem cần biết bên nào copy sau cùng để Ctrl + V dán đúng bên. Chữ thì gửi kèm nội dung.
|
|
869
|
+
*/
|
|
867
870
|
public static class ClipboardSync {
|
|
868
871
|
const uint CF_UNICODETEXT = 13;
|
|
869
872
|
const uint GMEM_MOVEABLE = 0x0002;
|
|
870
873
|
const int MAX_CHARS = 65536;
|
|
874
|
+
const long OWN_WRITE_TICKS = 1500 * TimeSpan.TicksPerMillisecond;
|
|
871
875
|
static readonly object syncGate = new object();
|
|
872
876
|
static uint lastSeq = 0;
|
|
873
877
|
static string lastText = "";
|
|
878
|
+
static long ownUntil = 0;
|
|
874
879
|
|
|
875
880
|
public static void Init() {
|
|
876
881
|
try { lastSeq = Native.GetClipboardSequenceNumber(); } catch { }
|
|
877
882
|
}
|
|
878
883
|
|
|
884
|
+
/** Lệnh dán của người xem sắp ghi clipboard: lần đổi đó không phải người dùng máy copy, không báo. */
|
|
885
|
+
public static void ExpectOwnWrite() {
|
|
886
|
+
lock (syncGate) { ownUntil = DateTime.UtcNow.Ticks + OWN_WRITE_TICKS; }
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
/** Đã ghi xong: nhận số thứ tự hiện tại là của mình. */
|
|
890
|
+
public static void OwnWriteDone() {
|
|
891
|
+
lock (syncGate) {
|
|
892
|
+
try { lastSeq = Native.GetClipboardSequenceNumber(); } catch { }
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
|
|
879
896
|
public static void Poll() {
|
|
880
897
|
uint seq;
|
|
881
898
|
try { seq = Native.GetClipboardSequenceNumber(); } catch { return; }
|
|
@@ -884,12 +901,14 @@ namespace AivinDesktopCast {
|
|
|
884
901
|
lock (syncGate) {
|
|
885
902
|
if (seq == lastSeq) return;
|
|
886
903
|
lastSeq = seq;
|
|
904
|
+
if (DateTime.UtcNow.Ticks < ownUntil) return;
|
|
887
905
|
text = ReadTextUnsafe();
|
|
888
|
-
if (string.IsNullOrEmpty(text) || text == lastText)
|
|
889
|
-
lastText = text;
|
|
906
|
+
if (string.IsNullOrEmpty(text) || text == lastText) text = null;
|
|
907
|
+
else lastText = text;
|
|
890
908
|
}
|
|
891
909
|
var msg = Out.Msg("clipboard");
|
|
892
|
-
msg["
|
|
910
|
+
msg["changed"] = true;
|
|
911
|
+
if (text != null) msg["text"] = text;
|
|
893
912
|
Out.Send(msg);
|
|
894
913
|
}
|
|
895
914
|
|
|
@@ -189,6 +189,7 @@ namespace AivinDesktopCast {
|
|
|
189
189
|
public static class CastPaste {
|
|
190
190
|
public static bool Run(Func<System.Windows.Forms.DataObject> build, bool notifyOnFail) {
|
|
191
191
|
bool ok = false;
|
|
192
|
+
ClipboardSync.ExpectOwnWrite();
|
|
192
193
|
var sta = new Thread(() => {
|
|
193
194
|
try {
|
|
194
195
|
System.Windows.Forms.Clipboard.SetDataObject(build(), true, 10, 100);
|
|
@@ -198,6 +199,7 @@ namespace AivinDesktopCast {
|
|
|
198
199
|
sta.SetApartmentState(ApartmentState.STA);
|
|
199
200
|
sta.Start();
|
|
200
201
|
bool done = sta.Join(3000) && ok;
|
|
202
|
+
if (done) ClipboardSync.OwnWriteDone();
|
|
201
203
|
if (done) PressPaste();
|
|
202
204
|
else if (notifyOnFail) Out.Send(Out.Msg("paste_failed"));
|
|
203
205
|
return done;
|
|
@@ -371,11 +371,10 @@ export function createDesktopWebRtc({ emitSignal = () => {}, emitStatus = () =>
|
|
|
371
371
|
}
|
|
372
372
|
}
|
|
373
373
|
|
|
374
|
-
/**
|
|
374
|
+
/** Máy từ xa vừa copy (chữ thì kèm nội dung) → báo trình duyệt người xem qua kênh điều khiển: Ctrl + V sau đó dán của máy. */
|
|
375
375
|
function pushClipboard(clip) {
|
|
376
376
|
const text = typeof clip?.text === 'string' ? clip.text : '';
|
|
377
|
-
|
|
378
|
-
const packet = JSON.stringify({ t: 'clipboard', text });
|
|
377
|
+
const packet = JSON.stringify(text ? { t: 'clipboard', text } : { t: 'clipboard' });
|
|
379
378
|
for (const peer of peers.values()) {
|
|
380
379
|
if (peer.inputChannel?.readyState !== 'open') continue;
|
|
381
380
|
try { peer.inputChannel.send(packet); } catch { /* kênh vừa đóng */ }
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Môi giới biến xác thực ngắn hạn cho lệnh trên Cloud Computer (21/11/2026).
|
|
3
|
+
*
|
|
4
|
+
* Bảo mật:
|
|
5
|
+
* - Chỉ nhận đúng tập tên biến đã duyệt (`ALLOWED_AUTH_ENV_KEYS`), bỏ qua mọi tên biến hệ thống (`PATH`, `LD_PRELOAD`, `NODE_OPTIONS`…).
|
|
6
|
+
* - Không ghi token ra đĩa: với `git`, dùng cơ chế `GIT_CONFIG_COUNT` + `http.<origin>.extraheader` truyền hoàn toàn qua môi trường tiến trình con.
|
|
7
|
+
* - Che sạch cả token gốc lẫn chuỗi Basic base64 khỏi stdout, stderr và luồng stream trước khi gửi về BE.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export const ALLOWED_AUTH_ENV_KEYS = new Set([
|
|
11
|
+
'GH_TOKEN',
|
|
12
|
+
'GITHUB_TOKEN',
|
|
13
|
+
'GITLAB_TOKEN',
|
|
14
|
+
'GL_TOKEN',
|
|
15
|
+
'CLOUDFLARE_API_TOKEN',
|
|
16
|
+
'CLOUDFLARE_ACCOUNT_ID',
|
|
17
|
+
'VERCEL_TOKEN',
|
|
18
|
+
'VERCEL_ORG_ID',
|
|
19
|
+
'VERCEL_PROJECT_ID',
|
|
20
|
+
'NETLIFY_AUTH_TOKEN',
|
|
21
|
+
'NPM_TOKEN',
|
|
22
|
+
'GOOGLE_OAUTH_ACCESS_TOKEN',
|
|
23
|
+
'LINEAR_API_KEY',
|
|
24
|
+
'NOTION_TOKEN',
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
const MAX_AUTH_VARS = 16;
|
|
28
|
+
const MAX_AUTH_VAL_LEN = 4096;
|
|
29
|
+
|
|
30
|
+
/** Lọc sạch map `call.auth_env` BE gửi xuống; trả null nếu không có biến hợp lệ nào. */
|
|
31
|
+
export function sanitizeAuthEnv(raw) {
|
|
32
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;
|
|
33
|
+
const out = {};
|
|
34
|
+
let count = 0;
|
|
35
|
+
for (const [key, val] of Object.entries(raw)) {
|
|
36
|
+
if (count >= MAX_AUTH_VARS) break;
|
|
37
|
+
if (!ALLOWED_AUTH_ENV_KEYS.has(key)) continue;
|
|
38
|
+
if (typeof val !== 'string') continue;
|
|
39
|
+
const clean = val.trim();
|
|
40
|
+
if (!clean || clean.length > MAX_AUTH_VAL_LEN || /[\r\n\0]/.test(clean)) continue;
|
|
41
|
+
out[key] = clean;
|
|
42
|
+
count += 1;
|
|
43
|
+
}
|
|
44
|
+
return count ? out : null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Xây biến môi trường tạm cho lệnh shell từ `authEnv`:
|
|
49
|
+
* - Giữ các biến trong `authEnv`.
|
|
50
|
+
* - Nếu lệnh gọi `git` và có token GitHub / GitLab → gắn thêm `GIT_TERMINAL_PROMPT=0` và `GIT_CONFIG_*` (không chạm `~/.gitconfig`).
|
|
51
|
+
* Trả `{ env, secrets }` (secrets gồm cả chuỗi base64 header để che sạch nếu lệnh in ra).
|
|
52
|
+
*/
|
|
53
|
+
export function buildCommandAuthEnv(authEnv, command = '') {
|
|
54
|
+
const clean = sanitizeAuthEnv(authEnv);
|
|
55
|
+
if (!clean) return { env: {}, secrets: [] };
|
|
56
|
+
const env = { ...clean };
|
|
57
|
+
const secretSet = new Set();
|
|
58
|
+
|
|
59
|
+
for (const [k, v] of Object.entries(clean)) {
|
|
60
|
+
if (!/_ID$/.test(k) && v.length >= 6) secretSet.add(v);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (/\bgit\b/i.test(String(command || ''))) {
|
|
64
|
+
const configs = [];
|
|
65
|
+
const ghToken = clean.GITHUB_TOKEN || clean.GH_TOKEN;
|
|
66
|
+
if (ghToken) {
|
|
67
|
+
const b64 = Buffer.from(`x-access-token:${ghToken}`, 'utf8').toString('base64');
|
|
68
|
+
secretSet.add(b64);
|
|
69
|
+
configs.push(['http.https://github.com/.extraheader', `AUTHORIZATION: basic ${b64}`]);
|
|
70
|
+
}
|
|
71
|
+
const glToken = clean.GITLAB_TOKEN || clean.GL_TOKEN;
|
|
72
|
+
if (glToken) {
|
|
73
|
+
const b64 = Buffer.from(`oauth2:${glToken}`, 'utf8').toString('base64');
|
|
74
|
+
secretSet.add(b64);
|
|
75
|
+
configs.push(['http.https://gitlab.com/.extraheader', `AUTHORIZATION: basic ${b64}`]);
|
|
76
|
+
}
|
|
77
|
+
if (configs.length) {
|
|
78
|
+
env.GIT_TERMINAL_PROMPT = '0';
|
|
79
|
+
env.GIT_CONFIG_COUNT = String(configs.length);
|
|
80
|
+
configs.forEach(([k, v], i) => {
|
|
81
|
+
env[`GIT_CONFIG_KEY_${i}`] = k;
|
|
82
|
+
env[`GIT_CONFIG_VALUE_${i}`] = v;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return { env, secrets: [...secretSet] };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Che mọi giá trị bí mật khỏi chuỗi đầu ra trước khi trả về BE. */
|
|
91
|
+
export function redactAuthText(text, secrets) {
|
|
92
|
+
if (!text || !Array.isArray(secrets) || !secrets.length) return text;
|
|
93
|
+
let out = String(text);
|
|
94
|
+
const ordered = secrets.filter((s) => typeof s === 'string' && s.length >= 6).sort((a, b) => b.length - a.length);
|
|
95
|
+
for (const s of ordered) {
|
|
96
|
+
if (out.includes(s)) out = out.split(s).join('[REDACTED]');
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}
|