@anytowork/cli 0.12.28 → 0.12.29
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/package.json +1 -1
- package/src/listener/prompt.js +11 -1
- package/src/listener/run.js +10 -1
package/package.json
CHANGED
package/src/listener/prompt.js
CHANGED
|
@@ -21,9 +21,11 @@ function langOf(payload, env) {
|
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* @param {object} payload the `wb.wake` payload ({group, session, from, summary, rules, boundary, rewake, ...})
|
|
24
|
+
* @param {{profile?: string, dir?: string}|null} identity set when this Agent is not the default identity of the computer:
|
|
25
|
+
* an Agent that runs inside another process (a gateway) does not inherit our environment, so the prompt names it
|
|
24
26
|
* @returns {string}
|
|
25
27
|
*/
|
|
26
|
-
export function buildPrompt(payload, env = process.env) {
|
|
28
|
+
export function buildPrompt(payload, env = process.env, identity = null) {
|
|
27
29
|
const p = payload || {};
|
|
28
30
|
const lang = langOf(p, env);
|
|
29
31
|
const envLang = { ...env, ANYTOWORK_LANG: lang };
|
|
@@ -57,6 +59,14 @@ export function buildPrompt(payload, env = process.env) {
|
|
|
57
59
|
? `Session id ${sid}. This is an automatic call from the platform.`
|
|
58
60
|
: `会话编号 ${sid}。这是平台自动叫醒。`);
|
|
59
61
|
if (p.rewake === true) lines.push(REWAKE_LINE[lang]);
|
|
62
|
+
if (identity && (identity.profile || identity.dir)) {
|
|
63
|
+
const pf = identity.profile;
|
|
64
|
+
lines.push(lang === 'en'
|
|
65
|
+
? (pf ? `Your identity on this computer is "${pf}": put --profile ${pf} right after anytowork in every command (for example: anytowork --profile ${pf} chat read ${sid}), or the wrong identity is used.`
|
|
66
|
+
: `Your identity on this computer lives in ${identity.dir}: set ANYTOWORK_CONFIG_DIR=${identity.dir} for every anytowork command, or the wrong identity is used.`)
|
|
67
|
+
: (pf ? `你在这台电脑上的身份是「${pf}」:每条 anytowork 命令都要在 anytowork 后面加 --profile ${pf}(例如 anytowork --profile ${pf} chat read ${sid}),否则会用错身份。`
|
|
68
|
+
: `你在这台电脑上的身份放在 ${identity.dir}:每条 anytowork 命令都要设置环境变量 ANYTOWORK_CONFIG_DIR=${identity.dir},否则会用错身份。`));
|
|
69
|
+
}
|
|
60
70
|
return lines.join('\n');
|
|
61
71
|
}
|
|
62
72
|
|
package/src/listener/run.js
CHANGED
|
@@ -141,6 +141,14 @@ export class Listener {
|
|
|
141
141
|
this.credDir = resolveCredDir(this.credOpts);
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
+
/** Who this listener is when it is not the computer's default identity (named in the prompt, see buildPrompt). */
|
|
145
|
+
identity() {
|
|
146
|
+
const profile = this.credOpts && this.credOpts.profile ? this.credOpts.profile : null;
|
|
147
|
+
if (profile) return { profile };
|
|
148
|
+
const named = String(this.env.ANYTOWORK_CONFIG_DIR || this.env.LINGER_CONFIG_DIR || '').trim();
|
|
149
|
+
return named ? { dir: this.credDir } : null;
|
|
150
|
+
}
|
|
151
|
+
|
|
144
152
|
// ---- state helpers ---------------------------------------------------------------------------------
|
|
145
153
|
save() { writeState(this.state, this.credOpts); }
|
|
146
154
|
logLine(line) { appendLog(this.credOpts, line, this.nowMs()); }
|
|
@@ -243,7 +251,7 @@ export class Listener {
|
|
|
243
251
|
} catch { /* cannot tell: run it */ }
|
|
244
252
|
}
|
|
245
253
|
const promptFile = path.join(promptsDir(this.credOpts), `${job.wakeId || job.sid.slice(0, 8)}-${now0}.txt`);
|
|
246
|
-
const prompt = buildPrompt(job.payload, this.env);
|
|
254
|
+
const prompt = buildPrompt(job.payload, this.env, this.identity());
|
|
247
255
|
try {
|
|
248
256
|
fs.mkdirSync(path.dirname(promptFile), { recursive: true, mode: 0o700 });
|
|
249
257
|
fs.writeFileSync(promptFile, prompt, { mode: 0o600 });
|
|
@@ -339,6 +347,7 @@ export class Listener {
|
|
|
339
347
|
reconnectMs = RECONNECT_FIRST_MS;
|
|
340
348
|
if (data && data.next_cursor != null) { cursor = data.next_cursor; writeListenerCursor(cursor, this.credOpts); }
|
|
341
349
|
this.state.seenAt = this.nowMs();
|
|
350
|
+
if (this.state.seenAt - (this.lastSeenSave || 0) >= 30000) { this.lastSeenSave = this.state.seenAt; this.save(); } // lets `listen status` tell it is alive
|
|
342
351
|
const lis = data && data.listener;
|
|
343
352
|
if (lis && lis.allowed === false) {
|
|
344
353
|
// The platform asks to stop waking for now (for example the wake-ups are not being read). Check back later.
|