@anytowork/cli 0.12.72 → 0.12.74
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 +15 -79
- package/package.json +1 -1
- package/src/api.js +17 -50
- package/src/apply-backoff.js +5 -2
- package/src/cli-parse.js +12 -131
- package/src/config.js +34 -5
- package/src/connect.js +22 -3
- package/src/error-map.js +56 -0
- package/src/exit-reasons.js +0 -9
- package/src/format.js +77 -144
- package/src/index.js +62 -112
- package/src/model-pledge.js +6 -6
- package/src/mt/collect.js +2 -26
- package/src/mt/commands.js +3 -84
- package/src/mt/format-check.js +2 -2
- package/src/mt/readers.js +1 -1
- package/src/mt/text.js +20 -89
- package/src/mt/wake-attribution.js +2 -2
- package/src/mt/workdirs.js +1 -18
- package/src/setup-commands.js +6 -6
- package/src/setup-hints.js +3 -19
- package/src/space-commands.js +2 -41
- package/src/space-sync.js +2 -2
- package/src/chat-commands.js +0 -685
- package/src/chat-state.js +0 -77
- package/src/hire-commands.js +0 -706
- package/src/listen-command.js +0 -79
- package/src/listener/commands.js +0 -183
- package/src/listener/config.js +0 -216
- package/src/listener/hire-wake.js +0 -60
- package/src/listener/install.js +0 -233
- package/src/listener/nudge.js +0 -88
- package/src/listener/prompt.js +0 -111
- package/src/listener/queue.js +0 -112
- package/src/listener/run-error.js +0 -81
- package/src/listener/run.js +0 -723
- package/src/listener/text.js +0 -103
- package/src/mt/inrun.js +0 -351
- package/src/mt/recipes.js +0 -478
- package/src/mt/sample.js +0 -708
- package/src/reply-hint.js +0 -21
- package/src/wb-rules-text.js +0 -169
package/src/chat-state.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
// The workbench "current session", kept on this computer (PRD 26 §7.4 / §9.3, contract v0.32 §7).
|
|
2
|
-
//
|
|
3
|
-
// Why it exists: after `anytowork chat read <session>` the Agent usually pulls / pushes files to do the work. The
|
|
4
|
-
// platform hangs those file actions on the Agent's branch in that session (the owner sees them in the Agent map),
|
|
5
|
-
// so `anytowork space` sends the session along. The Agent should not have to repeat the session id on every command.
|
|
6
|
-
//
|
|
7
|
-
// Rules:
|
|
8
|
-
// - one file per credentials directory, so every --profile (every Agent on this computer) has its own;
|
|
9
|
-
// - `chat read` sets it (reading another session switches to that one);
|
|
10
|
-
// - `chat result` (hand in the result) clears it; every other chat command, `chat send` included, keeps it alive
|
|
11
|
-
// (v0.33, D369: a quick "got it" reply must not make the pushes that follow fall out of this piece of work);
|
|
12
|
-
// - after 2 hours without any chat command it counts as gone (WB_CURRENT_SESSION_IDLE_H in the contract).
|
|
13
|
-
// A missing / broken file simply means "no current session"; it never stops a command.
|
|
14
|
-
|
|
15
|
-
import fs from 'node:fs';
|
|
16
|
-
import path from 'node:path';
|
|
17
|
-
import { atomicWriteFile } from './atomic-write.js';
|
|
18
|
-
import { resolveCredDir } from './profile.js';
|
|
19
|
-
|
|
20
|
-
/** How long the current session survives without any chat command (contract constant WB_CURRENT_SESSION_IDLE_H = 2). */
|
|
21
|
-
export const CURRENT_SESSION_IDLE_MS = 2 * 3600 * 1000;
|
|
22
|
-
|
|
23
|
-
/** File holding the current session ({credentials dir}/wb-current-session, JSON). */
|
|
24
|
-
export function currentSessionPath(opts = {}) {
|
|
25
|
-
return path.join(resolveCredDir(opts), 'wb-current-session');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function readRaw(opts) {
|
|
29
|
-
try {
|
|
30
|
-
const s = JSON.parse(fs.readFileSync(currentSessionPath(opts), 'utf8'));
|
|
31
|
-
if (!s || typeof s.session_id !== 'string' || !s.session_id) return null;
|
|
32
|
-
return s;
|
|
33
|
-
} catch {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** The current session id, or null when there is none / it is older than 2 hours (an old one is removed). */
|
|
39
|
-
export function readCurrentSession(opts = {}, nowMs = Date.now()) {
|
|
40
|
-
const s = readRaw(opts);
|
|
41
|
-
if (!s) return null;
|
|
42
|
-
const touched = Number(s.touched_at);
|
|
43
|
-
if (!Number.isFinite(touched) || nowMs - touched >= CURRENT_SESSION_IDLE_MS) {
|
|
44
|
-
clearCurrentSession(opts);
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
return s.session_id;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** Make `sessionId` the current session (chat read). Write failures are ignored: this is a convenience only. */
|
|
51
|
-
export function setCurrentSession(sessionId, opts = {}, nowMs = Date.now(), hireId = null) {
|
|
52
|
-
if (!sessionId) return;
|
|
53
|
-
try {
|
|
54
|
-
const o = { session_id: String(sessionId), touched_at: nowMs };
|
|
55
|
-
// v0.35.3: remember which hire this session belongs to (only when the platform said so), so `chat result` can
|
|
56
|
-
// remind a hired Agent to report usage.
|
|
57
|
-
if (hireId) o.hire_id = String(hireId);
|
|
58
|
-
atomicWriteFile(currentSessionPath(opts), JSON.stringify(o), 0o600);
|
|
59
|
-
} catch { /* keep going without it */ }
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** The hire id remembered with the current session, or null (not a hired session / no current session). */
|
|
63
|
-
export function readCurrentHire(opts = {}) {
|
|
64
|
-
const s = readRaw(opts);
|
|
65
|
-
return s && typeof s.hire_id === 'string' && s.hire_id ? s.hire_id : null;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** A chat command ran: restart the 2-hour clock of the current session (if there still is one). */
|
|
69
|
-
export function touchCurrentSession(opts = {}, nowMs = Date.now()) {
|
|
70
|
-
const id = readCurrentSession(opts, nowMs);
|
|
71
|
-
if (id) setCurrentSession(id, opts, nowMs, readCurrentHire(opts));
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** Forget the current session (the result was handed in). */
|
|
75
|
-
export function clearCurrentSession(opts = {}) {
|
|
76
|
-
try { fs.unlinkSync(currentSessionPath(opts)); } catch { /* already gone */ }
|
|
77
|
-
}
|