@anytowork/cli 0.12.37 → 0.12.39
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/README.md +1 -1
- package/package.json +1 -1
- package/src/format.js +9 -0
- package/src/index.js +3 -2
- package/src/listener/prompt.js +6 -4
- package/src/profile.js +30 -8
package/README.md
CHANGED
|
@@ -51,7 +51,7 @@ anytowork profiles
|
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
存储位置:默认 profile 仍在 `~/.anytowork/`;具名 profile 在 `~/.anytowork/profiles/<名字>/`。
|
|
54
|
-
`--profile` 也可与 `ANYTOWORK_CONFIG_DIR`
|
|
54
|
+
`--profile` 也可与 `ANYTOWORK_CONFIG_DIR` 组合(根目录换成你指定的位置)。环境目录本身已是 `…/profiles/<名字>` 时,同名 `--profile` 直接用这个目录,不会叠成两份。
|
|
55
55
|
|
|
56
56
|
> 每个 Agent 都向主人要一个**新的**接入码、各自用自己的 `--profile` 接入;
|
|
57
57
|
> 主人在网页确认时,可以选择是新建一个 Agent,还是把它绑回一个已有的 Agent(登录失效后重新接入时用)。
|
package/package.json
CHANGED
package/src/format.js
CHANGED
|
@@ -114,6 +114,12 @@ function asJson(data) {
|
|
|
114
114
|
* @param {object} data { tasks, total }
|
|
115
115
|
* @param {object} opts { json }
|
|
116
116
|
*/
|
|
117
|
+
/** v0.38.0: the platform's `sim_notice` ({en, zh}) as one line; empty when the order carries none. */
|
|
118
|
+
function simNoticeText(n) {
|
|
119
|
+
if (!n || typeof n !== 'object') return '';
|
|
120
|
+
return [n.zh, n.en].filter(Boolean).join(' / ');
|
|
121
|
+
}
|
|
122
|
+
|
|
117
123
|
export function formatHall(data, { json = false } = {}) {
|
|
118
124
|
if (json) return asJson(data);
|
|
119
125
|
const tasks = data.tasks || [];
|
|
@@ -133,6 +139,7 @@ export function formatHall(data, { json = false } = {}) {
|
|
|
133
139
|
else if (t.my_application_status === 'pending') mark = ' 【已报名·等选人】';
|
|
134
140
|
else if (t.my_application_status === 'outranked') mark = ` 【${OUTRANKED_LABEL}】`;
|
|
135
141
|
lines.push(` • ${t.title} —— 赏金 ${bounty}${mark}`);
|
|
142
|
+
if (t.sim_notice) lines.push(` ⚠ ${simNoticeText(t.sim_notice)}`);
|
|
136
143
|
if (t.description) {
|
|
137
144
|
const desc = String(t.description).slice(0, 50);
|
|
138
145
|
lines.push(` ${desc}${String(t.description).length > 50 ? '…' : ''}`);
|
|
@@ -253,6 +260,7 @@ export function formatTaskApply(data, { json = false, env, sentPolicy = true } =
|
|
|
253
260
|
if (data.quote_cents != null) lines.push(` 我的报价(整单成交价):${moneyText(data.quote_cents, data.currency)}`);
|
|
254
261
|
if (data.status) lines.push(` 申请状态:${applicationStatusText(data.status)}`);
|
|
255
262
|
if (data.task_status) lines.push(` 任务当前状态:${data.task_status}`);
|
|
263
|
+
if (data.sim_notice) lines.push(` ⚠ ${simNoticeText(data.sim_notice)}`);
|
|
256
264
|
// v0.27.25: the models the platform stored (normalised names), the notes, and the promise reminder
|
|
257
265
|
lines.push(...describeApplyModels(data, env, { sentPolicy }));
|
|
258
266
|
return lines.join('\n');
|
|
@@ -518,6 +526,7 @@ export function formatTaskDetail(data, { json = false } = {}) {
|
|
|
518
526
|
// v0.20.0: when the platform sent the buyer-input shell, print that (prefixed); else the plain field.
|
|
519
527
|
if (data.title_input || data.title) lines.push(` 标题:${data.title_input ? shellText(data.title_input) : data.title}`);
|
|
520
528
|
if (data.status) lines.push(` 状态:${data.status}`);
|
|
529
|
+
if (data.sim_notice) lines.push(` ⚠ ${simNoticeText(data.sim_notice)}`);
|
|
521
530
|
// v0.26.58: after a refund the settled amount (paid - refunded) is the real number; the posted price stays as a note
|
|
522
531
|
const money = data.money;
|
|
523
532
|
if (money && money.has_payment && money.refund_cents > 0) {
|
package/src/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import { parseArgs } from './cli-parse.js';
|
|
|
12
12
|
import { buildAskQuestions, buildAnswers } from './collab-input.js';
|
|
13
13
|
import { RETIRED_COMMANDS } from './retired-commands.js';
|
|
14
14
|
import { resolveBaseUrl } from './config.js';
|
|
15
|
-
import { configRootFromEnv, defaultRootDir, isValidProfileName, profileDir, resolveCredDir } from './profile.js';
|
|
15
|
+
import { configRootFromEnv, defaultRootDir, isValidProfileName, profileRootFromEnv, profileDir, resolveCredDir } from './profile.js';
|
|
16
16
|
import { loadCredentials } from './credentials.js';
|
|
17
17
|
import { runAuthLogin } from './oauth.js';
|
|
18
18
|
import { runConnect } from './connect.js';
|
|
@@ -811,7 +811,8 @@ export async function run(argv, deps = {}) {
|
|
|
811
811
|
);
|
|
812
812
|
return 2;
|
|
813
813
|
}
|
|
814
|
-
|
|
814
|
+
// 环境目录可能已经是 <根>/profiles/<名>(监听拉起时就是这样):先还原成根目录,不再叠一层
|
|
815
|
+
profileDirPath = profileDir(flags.profile, { rootDir: profileRootFromEnv(env) });
|
|
815
816
|
}
|
|
816
817
|
|
|
817
818
|
if (command === 'auth:login') {
|
package/src/listener/prompt.js
CHANGED
|
@@ -70,11 +70,13 @@ export function buildPrompt(payload, env = process.env, identity = null, job = n
|
|
|
70
70
|
}
|
|
71
71
|
if (identity && (identity.profile || identity.dir)) {
|
|
72
72
|
const pf = identity.profile;
|
|
73
|
+
// v0.12.38: the wake-up already points anytowork at this login through the environment,
|
|
74
|
+
// so `--profile <name>` and a plain command reach the same credentials. Never ask the Agent to unset the env var.
|
|
73
75
|
lines.push(lang === 'en'
|
|
74
|
-
? (pf ? `Your identity on this computer is "${pf}"
|
|
75
|
-
: `Your identity on this computer lives in ${identity.dir}
|
|
76
|
-
: (pf ? `你在这台电脑上的身份是「${pf}
|
|
77
|
-
: `你在这台电脑上的身份放在 ${identity.dir}
|
|
76
|
+
? (pf ? `Your identity on this computer is "${pf}". This wake-up already points anytowork at that login, so a plain command uses it; writing anytowork --profile ${pf} chat read ${sid} means the same thing. Both spellings work.`
|
|
77
|
+
: `Your identity on this computer lives in ${identity.dir} (this wake-up already sets ANYTOWORK_CONFIG_DIR=${identity.dir}). Run anytowork commands as they are; no --profile is needed.`)
|
|
78
|
+
: (pf ? `你在这台电脑上的身份是「${pf}」。叫醒时已经把 anytowork 指向这份登录,直接运行命令就是它;写成 anytowork --profile ${pf} chat read ${sid} 也一样。两种写法等价,都能读到同一份登录。`
|
|
79
|
+
: `你在这台电脑上的身份放在 ${identity.dir}(叫醒时已经设好 ANYTOWORK_CONFIG_DIR=${identity.dir}),命令直接运行即可,不用再加 --profile。`));
|
|
78
80
|
}
|
|
79
81
|
return lines.join('\n');
|
|
80
82
|
}
|
package/src/profile.js
CHANGED
|
@@ -63,16 +63,38 @@ export function profileDir(name, opts = {}) {
|
|
|
63
63
|
* 目录优先级(越靠前越优先):
|
|
64
64
|
* 1. opts.dir 单测注入 / 调用方显式指定
|
|
65
65
|
* 2. flags.profile(--profile) 同机多 Agent 隔离(推荐)
|
|
66
|
-
* 3. ANYTOWORK_CONFIG_DIR
|
|
67
|
-
* 4. ~/.anytowork
|
|
68
|
-
* 注:--profile 优先级高于 ANYTOWORK_CONFIG_DIR
|
|
69
|
-
*
|
|
66
|
+
* 3. ANYTOWORK_CONFIG_DIR 旧版隔离手段(继续支持)
|
|
67
|
+
* 4. ~/.anytowork 默认
|
|
68
|
+
* 注:--profile 优先级高于 ANYTOWORK_CONFIG_DIR——显式开关应当压过环境变量。
|
|
69
|
+
* 两者不叠加:环境目录如果本身已经是 <根>/profiles/<名>,同名 profile 就直接用它
|
|
70
|
+
*(监听拉起时环境变量已指向这份登录,叫醒提示又建议加 --profile,叠一层就读不到凭证)。
|
|
70
71
|
*/
|
|
71
72
|
export function resolveCredDir({ dir, profile, env = process.env } = {}) {
|
|
72
73
|
if (dir) return dir;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
const fromEnv = configRootFromEnv(env);
|
|
75
|
+
if (profile == null || profile === '') return fromEnv;
|
|
76
|
+
const split = splitProfileEnvDir(fromEnv);
|
|
77
|
+
if (split.profile === profile) return fromEnv;
|
|
78
|
+
return profileDir(profile, { rootDir: split.root });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 拆开环境里给的目录:<根>/profiles/<名> → 根 + 名;<根>/profiles → 根;其他原样当根。
|
|
83
|
+
* 监听拉起的 Agent 同时拿到 ANYTOWORK_CONFIG_DIR=<根>/profiles/<名> 和叫醒提示里的
|
|
84
|
+
* --profile <名>,不拆开的话 --profile 会再拼一层 profiles/<名>。
|
|
85
|
+
*/
|
|
86
|
+
function splitProfileEnvDir(dirName) {
|
|
87
|
+
const name = path.basename(dirName);
|
|
88
|
+
const parent = path.dirname(dirName);
|
|
89
|
+
if (!name || parent === dirName) return { root: dirName, profile: null };
|
|
90
|
+
if (name === "profiles") return { root: parent, profile: null };
|
|
91
|
+
if (path.basename(parent) === "profiles" && isValidProfileName(name)) {
|
|
92
|
+
return { root: path.dirname(parent), profile: name };
|
|
76
93
|
}
|
|
77
|
-
return
|
|
94
|
+
return { root: dirName, profile: null };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** 环境变量指向的根目录(若它已是一个 profile 目录,还原成根目录)。 */
|
|
98
|
+
export function profileRootFromEnv(env = process.env) {
|
|
99
|
+
return splitProfileEnvDir(configRootFromEnv(env)).root;
|
|
78
100
|
}
|