@koalaauto/agentchannel 3.17.0 → 3.18.0

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/dist/src/cli.js CHANGED
@@ -346,8 +346,19 @@ async function dispatch(p, io) {
346
346
  await runSetup({ env, out: io.out, err: io.err, exec: io.exec ?? defaultExec, cwd: io.cwd ?? process.cwd() }, { yes: false, dryRun: true, service: !!v.service, zh: zhJ, join: { hub: inv.hub } });
347
347
  return 0;
348
348
  }
349
- const cfId = env.ACH_CF_ID || inv.cf_id;
350
- const cfSecret = env.ACH_CF_SECRET || inv.cf_secret;
349
+ let cfId = env.ACH_CF_ID || inv.cf_id;
350
+ let cfSecret = env.ACH_CF_SECRET || inv.cf_secret;
351
+ if (!cfId || !cfSecret) {
352
+ // a line without the front-door token, on a machine that already reaches this hub: use the token stored here
353
+ try {
354
+ const saved = loadConfig(env);
355
+ if (saved.hub === inv.hub && saved.cfId && saved.cfSecret)
356
+ ({ cfId, cfSecret } = saved);
357
+ }
358
+ catch {
359
+ /* nothing stored */
360
+ }
361
+ }
351
362
  // exchange the one-time join token for the agent key
352
363
  let key;
353
364
  try {
@@ -367,6 +378,12 @@ async function dispatch(p, io) {
367
378
  io.err(isZh(env) ? `ach join:${e.message}。换一个名字再运行:加上 --name <名字>(小写字母、数字和 -)。邀请还没有用掉。` : `ach join: ${e.message}. Run it again with --name <name> (lowercase letters, digits and -); the invite is still unused.`);
368
379
  return 1;
369
380
  }
381
+ if (e instanceof HubError && e.code === 'cf_access') {
382
+ io.err(isZh(env)
383
+ ? `ach join:请求被 ${hubHost} 前面的 Cloudflare Access 拦下了,这行没有带可用的访问令牌。邀请还没有用掉。请在面板重新生成接入命令(打开「包含 Cloudflare 访问令牌」),或先设置 ACH_CF_ID 和 ACH_CF_SECRET 再运行这一行。`
384
+ : `ach join: Cloudflare Access in front of ${hubHost} blocked the request: this line carries no working access token. The invite is still unused. Make a new join command in the panel (with "Include the Cloudflare access token" on), or set ACH_CF_ID and ACH_CF_SECRET and run this line again.`);
385
+ return 1;
386
+ }
370
387
  const used = e instanceof HubError && (e.status === 410 || e.status === 401);
371
388
  // run again on the same machine (e.g. after installing Claude Code): keep the key saved by the first run
372
389
  let again;
@@ -20,6 +20,12 @@ export function parseLinkRepo(v) {
20
20
  }
21
21
  /** Who is calling, on every request: the hub records the release per agent and may refuse a protocol below its floor (426 client_too_old). */
22
22
  export const CLIENT_HEADERS = { 'x-ach-client': `ach-cli/${VERSION}`, 'x-ach-proto': String(CLIENT_PROTO) };
23
+ /** A response from Cloudflare Access (its login page or challenge), not from the hub behind it. */
24
+ function accessBlocked(res) {
25
+ if (/^https:\/\/[^/]+\.cloudflareaccess\.com\//.test(res.url ?? ''))
26
+ return true;
27
+ return /^Cloudflare-Access\b/i.test(res.headers?.get?.('www-authenticate') ?? '');
28
+ }
23
29
  export class HubError extends Error {
24
30
  status;
25
31
  code;
@@ -120,6 +126,11 @@ export class Client {
120
126
  headers: this.headers(!multipart),
121
127
  body: multipart ? await attachmentForm(body, files) : body === undefined ? undefined : JSON.stringify(body),
122
128
  });
129
+ // Cloudflare Access in front of the hub answers with its login page (a redirect followed to *.cloudflareaccess.com,
130
+ // or a challenge header) instead of the hub's JSON: say so, instead of failing later on a missing field
131
+ if (accessBlocked(res)) {
132
+ throw new HubError(403, `${method} ${path}: blocked by Cloudflare Access in front of ${new URL(url).host}: no valid access token (use a join line that includes it, or set ACH_CF_ID and ACH_CF_SECRET)`, 'cf_access');
133
+ }
123
134
  const text = await res.text();
124
135
  let data = undefined;
125
136
  if (text) {
@@ -221,9 +221,9 @@ export function agentInvitePrompt(line, lang = 'en') {
221
221
  if (lang === 'zh') {
222
222
  return (`请帮我接入团队的 AgentChannel:在这个项目的目录里运行 \`${line}\`。` +
223
223
  `它会保存这个智能体的密钥,并把 AgentChannel 接入你自己,不会安装别的东西;这行只能用一次。` +
224
- `完成后告诉我收件箱里有什么。如果出错,运行 \`${npx} doctor\`,按提示修好再继续。`);
224
+ `完成后告诉我收件箱里有什么。如果这行报错,先把报错原文告诉我,再运行 \`${npx} doctor\`,按提示修好再继续。`);
225
225
  }
226
226
  return (`Please connect me to my team's AgentChannel: run \`${line}\` in this project's directory. ` +
227
227
  `It stores this agent's key and adds AgentChannel to you; it installs nothing else (the line works once). ` +
228
- `Then tell me what is in my inbox. If anything fails, run \`${npx} doctor\`, fix what it says, and continue.`);
228
+ `Then tell me what is in my inbox. If the line fails, tell me its exact error first, then run \`${npx} doctor\`, fix what it says, and continue.`);
229
229
  }
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "3.17.0";
1
+ export declare const VERSION = "3.18.0";
2
2
  /** The npm package (scripts/release.mjs keeps it and VERSION in step with package.json). */
3
3
  export declare const PKG_NAME = "@koalaauto/agentchannel";
4
4
  /**
@@ -1,4 +1,4 @@
1
- export const VERSION = '3.17.0';
1
+ export const VERSION = '3.18.0';
2
2
  /** The npm package (scripts/release.mjs keeps it and VERSION in step with package.json). */
3
3
  export const PKG_NAME = '@koalaauto/agentchannel';
4
4
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koalaauto/agentchannel",
3
- "version": "3.17.0",
3
+ "version": "3.18.0",
4
4
  "description": "Hand work between your team's agents (Claude Code, Codex) and follow it in one panel: the ach CLI, MCP server and runner for AgentChannel v2",
5
5
  "keywords": [
6
6
  "agentchannel",