agentosity 0.2.1 → 0.2.2

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +51 -34
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentosity",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Agentosity — AI-native is a number now. Automatic attendance for your AI agents (stdio MCP lifecycle + activity probes) + human clock-out CLI.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/index.js CHANGED
@@ -25,10 +25,9 @@ export async function main(argv) {
25
25
  default:
26
26
  console.log(`agentosity — AI-native is a number now.
27
27
 
28
- 两步开始:
29
- npx agentosity login # 1. 弹浏览器登录
30
- npx agentosity init "<公司名>" # 2. 绑定公司 + 自动接入所有 harness
31
- (无浏览器环境:login <邮箱> 收验证码,再 login <邮箱> <验证码>)
28
+ 一步开始:
29
+ npx agentosity init 登录 网页选公司 → 自动接入所有 harness,全程引导
30
+ (无浏览器环境:login <邮箱> 收验证码登录后,init "<公司名>")
32
31
 
33
32
  其他:
34
33
  npx agentosity radar 进程雷达:补录本机未接入 MCP 的 Agent 会话(常驻)
@@ -39,38 +38,52 @@ export async function main(argv) {
39
38
  }
40
39
  }
41
40
 
42
- async function init(company) {
43
- const pre = loadConfig();
44
- if (!pre.accessToken) {
45
- console.error(`Agentosity 需要登录使用:
46
- npx agentosity login <邮箱> # 收验证码
47
- npx agentosity login <邮箱> <验证码> # 登录
48
- 然后再跑 init。`);
41
+ async function init(companyArg) {
42
+ // 防占位符事故:范例文本被原样粘贴执行
43
+ if (companyArg && /你的公司名|公司名|your ?company|company ?name/i.test(companyArg)) {
44
+ console.error("「" + companyArg + "」看起来是示例占位符,不是真实公司名。直接跑 npx agentosity init(不带参数),公司在网页上选。");
49
45
  process.exit(1);
50
46
  }
51
- if (!company) {
52
- console.error('用法:npx agentosity init "你的公司名"');
53
- process.exit(1);
54
- }
55
- saveConfig({ company });
56
47
 
57
- // 服务端绑定公司(唯一真相;改绑每周一次)
58
- const created = await post("/api/companies", { name: company });
59
- if (created?.id) {
60
- const bind = await post("/api/profile", { companyId: created.id }, { method: "PUT" });
61
- if (bind?.error) console.log(`⚠️ ${bind.error}(本地归属仍按「${company}」记)`);
62
- else console.log(`✅ 公司已绑定:${created.name ?? company}`);
48
+ // 1. 登录(没有就当场走浏览器授权)
49
+ let cfg = loadConfig();
50
+ if (!cfg.accessToken) {
51
+ await browserLogin(); // 失败会自行退出
52
+ cfg = loadConfig();
63
53
  } else {
64
- console.log(`⚠️ 公司绑定暂未同步(网络?),本地归属按「${company}」记`);
54
+ console.log(`✓ 已登录 ${cfg.email ?? ""}`);
55
+ }
56
+
57
+ // 2. 公司绑定(统一收口网页;--company 仅供无浏览器环境)
58
+ let prof = await get(`/api/profile?device=${cfg.deviceId ?? ""}`);
59
+ if (!prof?.company && companyArg) {
60
+ const created = await post("/api/companies", { name: companyArg });
61
+ if (created?.id) await post("/api/profile", { companyId: created.id }, { method: "PUT" });
62
+ prof = await get(`/api/profile?device=${cfg.deviceId ?? ""}`);
63
+ }
64
+ if (!prof?.company) {
65
+ const url = `${apiBase()}/checkin`;
66
+ console.log(`在网页上选择你的公司…\n打不开就手动访问:${url}`);
67
+ await openBrowser(url);
68
+ for (let i = 0; i < 150 && !prof?.company; i++) {
69
+ await new Promise((r) => setTimeout(r, 2000));
70
+ prof = await get(`/api/profile?device=${cfg.deviceId ?? ""}`);
71
+ }
72
+ if (!prof?.company) {
73
+ console.error("等待超时。在网页上绑定公司后,重新跑 npx agentosity init");
74
+ process.exit(1);
75
+ }
65
76
  }
77
+ console.log(`✓ 公司:${prof.company.name}`);
78
+ saveConfig({ company: prof.company.name }); // 本地缓存,考勤/雷达归属用
66
79
 
67
- // 全家 harness 自动接入
80
+ // 3. 全家 harness 自动接入
68
81
  console.log("\n接入 Agent 考勤:");
69
82
  const results = installAllHarnesses();
70
83
  console.log(formatInstallResults(results) || " (未发现已安装的 harness)");
71
84
 
72
85
  console.log(`
73
- 从现在起,新开的 Agent 会话会自动考勤——模型零参与,只上报时长,不读任何内容。
86
+ 完成。从现在起,新开的 Agent 会话会自动考勤——模型零参与,只上报时长,不读任何内容。
74
87
  已开着的老会话不会被追踪(配置只对新会话生效),要收编它们:npx agentosity radar
75
88
 
76
89
  看榜:${apiBase()}/agents`);
@@ -99,6 +112,18 @@ async function login(email, code) {
99
112
  }
100
113
  }
101
114
 
115
+ async function openBrowser(url) {
116
+ try {
117
+ const { spawn } = await import("node:child_process");
118
+ const opener = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
119
+ const child = spawn(opener, [url], { stdio: "ignore", detached: true, shell: process.platform === "win32" });
120
+ child.on("error", () => {});
121
+ child.unref();
122
+ } catch {
123
+ /* 打不开浏览器就靠打印的 URL */
124
+ }
125
+ }
126
+
102
127
  async function browserLogin() {
103
128
  const cfg = saveConfig({}); // 确保 deviceId 存在
104
129
  const start = await post("/api/device/start", {});
@@ -108,15 +133,7 @@ async function browserLogin() {
108
133
  }
109
134
  const url = `${apiBase()}/login?device=${start.code}`;
110
135
  console.log(`在浏览器里完成登录…\n打不开就手动访问:${url}`);
111
- try {
112
- const { spawn } = await import("node:child_process");
113
- const opener = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
114
- const child = spawn(opener, [url], { stdio: "ignore", detached: true, shell: process.platform === "win32" });
115
- child.on("error", () => {});
116
- child.unref();
117
- } catch {
118
- /* 打不开浏览器就靠上面打印的 URL */
119
- }
136
+ await openBrowser(url);
120
137
  for (let i = 0; i < 150; i++) {
121
138
  await new Promise((r) => setTimeout(r, 2000));
122
139
  const poll = await post(`/api/device/poll?code=${start.code}`, undefined, { method: "GET" });