@aivin-labs/cli 1.0.60 → 1.0.62

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.
@@ -78,9 +78,41 @@ export function claudeAbsPath(abs, platform = process.platform) {
78
78
  * Cờ của job có hợp đồng kiểm trên 2.1.322 (11/11/2026): `--worktree`, `--max-budget-usd`, `--effort`, `--allowedTools`, `--add-dir`,
79
79
  * `--settings`, `--setting-sources`, `--strict-mcp-config`, `--permission-prompts none`.
80
80
  */
81
+ /**
82
+ * Hồ sơ tài khoản của agent lập trình (14/11/2026) — mỗi tài khoản một thư mục cấu hình riêng, truyền qua biến môi trường CHÍNH THỨC của agent
83
+ * (`profileEnv` của adapter: Claude Code `CLAUDE_CONFIG_DIR`; adapter Codex sau này `CODEX_HOME`). Chuyển tài khoản = chọn hồ sơ, không sao chép
84
+ * token, không đụng giao diện. Người dùng đăng nhập vào mỗi hồ sơ MỘT lần (máy không đăng nhập hộ). Thư mục: ~/.aivin/agent-profiles/<agent>/<tên>.
85
+ */
86
+ export const AGENT_PROFILES_DIR = path.join(REMOTE_CONFIG_DIR, 'agent-profiles');
87
+ const PROFILE_NAME_RE = /^[a-z0-9][a-z0-9_-]{0,39}$/i;
88
+
89
+ /** Thư mục hồ sơ `name` của adapter — tên sai / adapter không hỗ trợ / chưa tạo → lỗi kèm cách tạo. */
90
+ export function agentProfileDir(adapter, name, { root = AGENT_PROFILES_DIR } = {}) {
91
+ const n = String(name || '').trim();
92
+ if (!adapter.profileEnv) throw new DeviceToolError(DeviceErrorCode.INVALID_ARGS, `${adapter.label} has no account profiles on this device`);
93
+ if (!PROFILE_NAME_RE.test(n)) throw new DeviceToolError(DeviceErrorCode.INVALID_ARGS, 'account: letters, digits, - or _ (max 40)');
94
+ const dir = path.join(root, adapter.id, n);
95
+ if (!fs.existsSync(dir)) {
96
+ throw new DeviceToolError(DeviceErrorCode.NOT_FOUND, `No ${adapter.label} account profile "${n}" — the person creates it once: set ${adapter.profileEnv}=${dir}, run ${adapter.id} and sign in`);
97
+ }
98
+ return dir;
99
+ }
100
+
101
+ /** Hồ sơ đã có của từng adapter (tên thư mục). */
102
+ export function listAgentProfiles(adapters, { root = AGENT_PROFILES_DIR } = {}) {
103
+ const out = {};
104
+ for (const a of adapters) {
105
+ if (!a.profileEnv) continue;
106
+ const dir = path.join(root, a.id);
107
+ out[a.id] = fs.existsSync(dir) ? fs.readdirSync(dir, { withFileTypes: true }).filter((d) => d.isDirectory() && PROFILE_NAME_RE.test(d.name)).map((d) => d.name) : [];
108
+ }
109
+ return out;
110
+ }
111
+
81
112
  export const CLAUDE_ADAPTER = Object.freeze({
82
113
  id: 'claude',
83
114
  label: 'Claude Code',
115
+ profileEnv: 'CLAUDE_CONFIG_DIR',
84
116
  candidates({ env = process.env, platform = process.platform, home = os.homedir() } = {}) {
85
117
  const exe = platform === 'win32' ? 'claude.exe' : 'claude';
86
118
  const out = [...onPath(exe, env), path.join(home, '.local', 'bin', exe), path.join(home, '.claude', 'local', exe)];
@@ -226,6 +258,7 @@ function contractPrompt({ jobId, jobDir, contract, hasTestCheck, note }) {
226
258
 
227
259
  export function createAgentRunner({
228
260
  adapters = DEFAULT_AGENT_ADAPTERS, find = findAgentBinary, spawnImpl = spawn, now = Date.now, jobsDir = JOBS_DIR, measure = measureEvidence, probeFlags = helpFlags,
261
+ profilesRoot = AGENT_PROFILES_DIR,
229
262
  } = {}) {
230
263
  const found = new Map();
231
264
  const flagCache = new Map();
@@ -314,7 +347,7 @@ export function createAgentRunner({
314
347
  function remember(j) {
315
348
  if (!j.session_id) return;
316
349
  const list = loadSessions().filter((s) => !(s.agent === j.agent && s.session_id === j.session_id));
317
- list.unshift({ agent: j.agent, session_id: j.session_id, cwd: j.cwd, prompt: j.prompt.slice(0, 200), at: new Date(now()).toISOString(), ok: j.result?.ok });
350
+ list.unshift({ agent: j.agent, session_id: j.session_id, cwd: j.cwd, prompt: j.prompt.slice(0, 200), at: new Date(now()).toISOString(), ok: j.result?.ok, ...(j.account ? { account: j.account } : {}) });
318
351
  saveSessions(list);
319
352
  }
320
353
 
@@ -419,6 +452,8 @@ export function createAgentRunner({
419
452
  if (prompt.length > MAX_PROMPT_CHARS) throw invalid(`prompt is longer than ${MAX_PROMPT_CHARS} characters`);
420
453
  if ([...jobs.values()].filter((j) => RUNNING.has(j.status)).length >= MAX_JOBS) throw new DeviceToolError(AGENT_BUSY, `${MAX_JOBS} agent tasks are already running — wait or agent.stop one`);
421
454
  const adapter = adapterFor(args.agent ? String(args.agent) : undefined);
455
+ const account = args.account ? String(args.account).trim() : '';
456
+ const accountDir = account ? agentProfileDir(adapter, account, { root: profilesRoot }) : null;
422
457
  const jobId = `${adapter.id}-${randomUUID().slice(0, 8)}`;
423
458
 
424
459
  let cwd;
@@ -447,7 +482,7 @@ export function createAgentRunner({
447
482
  }
448
483
  const session = prev ? prev.session_id : String(args.session || 'new');
449
484
  const resume = session === 'new' ? undefined
450
- : session === 'continue' ? loadSessions().find((s) => s.agent === adapter.id && s.cwd === cwd)?.session_id
485
+ : session === 'continue' ? loadSessions().find((s) => s.agent === adapter.id && s.cwd === cwd && (s.account || '') === account)?.session_id
451
486
  : session;
452
487
  if (session === 'continue' && !resume) throw new DeviceToolError(DeviceErrorCode.NOT_FOUND, `No earlier ${adapter.label} session in this folder — use session "new"`);
453
488
  // Nói tiếp một phiên: agent đã có worktree từ lần đầu — không tạo thêm.
@@ -469,9 +504,11 @@ export function createAgentRunner({
469
504
  const j = {
470
505
  id: jobId, agent: adapter.id, status: 'running', prompt: prompt || `contract ${extra.contractId}`, cwd, cwdShown: args.cwd || cwd, mode: agentOpts.mode,
471
506
  session_id: resume, model: undefined, texts: [], tools: [], result: null, error: null, startedAt: now(), endedAt: 0, waiters: new Set(), child: null,
472
- abort: new AbortController(), ...extra,
507
+ abort: new AbortController(), ...extra, ...(account ? { account } : {}),
473
508
  };
474
- const child = spawnImpl(binaryOf(adapter).bin, argv, { cwd: spawnCwd || cwd, env: agentEnv(process.env), windowsHide: true, stdio: ['pipe', 'pipe', 'pipe'] });
509
+ // Hồ sơ tài khoản: thư mục cấu hình riêng qua biến môi trường chính thức của agent — phiên / đăng nhập / hạn mức của tài khoản đó.
510
+ const childEnv = accountDir ? { ...agentEnv(process.env), [adapter.profileEnv]: accountDir } : agentEnv(process.env);
511
+ const child = spawnImpl(binaryOf(adapter).bin, argv, { cwd: spawnCwd || cwd, env: childEnv, windowsHide: true, stdio: ['pipe', 'pipe', 'pipe'] });
475
512
  j.child = child;
476
513
  jobs.set(j.id, j);
477
514
  persist(j);
@@ -557,6 +594,7 @@ export function createAgentRunner({
557
594
 
558
595
  return {
559
596
  run, status, stop, sessions,
597
+ profiles: () => ({ profiles: listAgentProfiles(installed(), { root: profilesRoot }) }),
560
598
  installed: () => installed().map((a) => ({ id: a.id, label: a.label, version: binaryOf(a).version })),
561
599
  /** Còn job đang chạy / đang đo — daemon không tự khởi động lại để cập nhật lúc này. */
562
600
  hasRunning: () => [...jobs.values()].some((j) => RUNNING.has(j.status)),
@@ -579,6 +617,7 @@ export function buildAgentTools(runner) {
579
617
  project_config: bool('load the folder\'s own agent settings, hooks and MCP servers (default true; false for a folder you do not trust; always false with contract)'),
580
618
  contract: str('CONTRACT.md text issued by Aivin'), contract_sha256: str('sha256 of that CONTRACT.md'), test_check: str('TEST_CHECK.md text, when the contract names test_check'),
581
619
  continue_job: str('fix round: an earlier contract job — continue its session in its worktree (send the contract again)'),
620
+ account: str('run as this account profile of the agent (from agent.profiles) — its own sign-in, sessions and usage limits; default: the usual account of the agent'),
582
621
  wait_ms: num(`wait for the answer up to this long (default ${DEFAULT_WAIT_MS}, max ${MAX_WAIT_MS})`),
583
622
  }) },
584
623
  { name: 'agent.status', group: ToolGroup.PROC, read_only: true, handler: (a, c) => runner.status(a, c),
@@ -587,6 +626,9 @@ export function buildAgentTools(runner) {
587
626
  { name: 'agent.stop', group: ToolGroup.PROC, handler: (a) => runner.stop(a),
588
627
  description: 'Stop a running coding-agent task.',
589
628
  input_schema: schema({ job: str('job from agent.run') }, ['job']) },
629
+ { name: 'agent.profiles', group: ToolGroup.PROC, read_only: true, handler: () => runner.profiles(),
630
+ description: 'Account profiles of each installed coding agent on this computer (each has its own sign-in and usage limits). Pass one as account to agent.run to switch account without any UI. The person creates a profile once by signing in to it.',
631
+ input_schema: schema({}) },
590
632
  { name: 'agent.sessions', group: ToolGroup.PROC, read_only: true, handler: (a, c, e) => runner.sessions(a, c, e),
591
633
  description: 'Recent coding-agent sessions started from Aivin on this computer (agent, folder, first words of the task, when, ok) — to continue one.',
592
634
  input_schema: schema({ cwd: str('only sessions of this folder'), agent: str('only this agent') }) },
@@ -17,10 +17,8 @@ export function createCastTouchViewers() {
17
17
  }
18
18
 
19
19
  /**
20
- * Bộ quay có vẽ con trỏ vào khung hình không.
21
- * Đường JPEG: chỉ bỏ khi mọi người xem đều cảm ứng, còn người dùng chuột thì họ cần thấy con trỏ.
22
- * Đường video: theo từng người xem báo tự vẽ hay chưa, để lúc đang ghi hình con trỏ vẫn nằm trong bản ghi.
20
+ * Bộ quay không vẽ con trỏ vào khung hình (cả JPEG lẫn video) để tránh hiện tượng 2 con trỏ không đồng bộ với chuột của người xem.
23
21
  */
24
- export function shouldDrawCursorInFrame({ jpeg, localCursor, allTouch }) {
25
- return jpeg ? !allTouch : !localCursor;
22
+ export function shouldDrawCursorInFrame() {
23
+ return false;
26
24
  }
@@ -343,8 +343,8 @@ export function createDesktopCastManager({ dir = CAST_DIR, spawnImpl = spawn } =
343
343
  config({ jpeg: on });
344
344
  }
345
345
 
346
- /** Con trỏ lồng vào khung hình (mặc định) hay gửi riêng để FE tự vẽ. */
347
- let cursorInFrame = true;
346
+ /** Con trỏ không lồng vào khung hình mặc định (tránh hiện 2 con trỏ lệch nhau trên giao diện). */
347
+ let cursorInFrame = false;
348
348
  function setCursorInFrame(on) {
349
349
  if (cursorInFrame === on) return;
350
350
  cursorInFrame = on;
@@ -427,8 +427,8 @@ namespace AivinDesktopCast {
427
427
  public static class CursorTracker {
428
428
  const int POLL_MS = 15;
429
429
  const int MAX_SHAPE_SIDE = 128;
430
- /** Vẽ con trỏ vào khung hình (mặc định, đường JPEG / FE cũ) thay vì gửi riêng. */
431
- public static volatile bool DrawInFrame = true;
430
+ /** Không vẽ con trỏ vào khung hình (mặc định tắt để tránh hiện 2 con trỏ lệch nhịp giữa máy và trình duyệt). */
431
+ public static volatile bool DrawInFrame = false;
432
432
  /** Tăng mỗi khi con trỏ đổi — vòng quay dùng để gửi khung khi con trỏ nằm trong hình. */
433
433
  public static volatile int Seq = 0;
434
434
  static volatile bool forceEmit = false;
@@ -238,16 +238,6 @@ namespace AivinDesktopCast {
238
238
  var list = new System.Collections.Specialized.StringCollection();
239
239
  list.Add(filePath);
240
240
  data.SetFileDropList(list);
241
- string ext = Path.GetExtension(filePath).ToLowerInvariant();
242
- if (ext == ".png" || ext == ".jpg" || ext == ".jpeg" || ext == ".bmp" || ext == ".gif" || ext == ".webp") {
243
- try {
244
- using (var src = Image.FromFile(filePath)) {
245
- var bmp = new Bitmap(src.Width, src.Height, PixelFormat.Format32bppArgb);
246
- using (var g = Graphics.FromImage(bmp)) g.DrawImage(src, 0, 0, src.Width, src.Height);
247
- data.SetImage(bmp);
248
- }
249
- } catch { }
250
- }
251
241
  return data;
252
242
  }
253
243