@aivin-labs/cli 1.0.75 → 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/client.mjs +68 -7
- package/bin/lib/remote/codingAgents.mjs +1065 -953
- package/bin/lib/remote/constants.mjs +2 -0
- package/bin/lib/remote/ephemeralAuth.mjs +99 -0
- package/bin/lib/remote/lightcodeAgent.mjs +1615 -0
- package/bin/lib/remote/localLlm.mjs +124 -2
- package/bin/lib/remote/localLlmLogin.mjs +293 -219
- package/bin/lib/remote/localLlmMembers.mjs +115 -96
- package/bin/lib/remote/localPolicy.mjs +345 -341
- package/bin/lib/remote/orgComputerLicense.mjs +99 -0
- package/bin/lib/remote/toolHandlers.mjs +18 -2
- 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ũ. */
|
|
@@ -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
|
+
}
|