clavarium 0.2.511-next.1 → 0.2.512-next.1
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/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/main.mjs +4 -2
- package/server/signinhelp.mjs +11 -0
- package/server/talk.mjs +5 -3
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.512-next.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "clavarium",
|
|
9
|
-
"version": "0.2.
|
|
9
|
+
"version": "0.2.512-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/main.mjs
CHANGED
|
@@ -502,8 +502,10 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
502
502
|
/* A wake-up typed is said in its chat (talk, made below: called only once a wake-up fires). */
|
|
503
503
|
/* Where its chat is on, what wakes a tool is an event it acknowledges: see dockets.mjs. */
|
|
504
504
|
let signinHelp = null;
|
|
505
|
+
const atCodePrompt = async (name) => { try { return (await signinHelp?.atCodePrompt(name, (argv, options) => vms.exec(name, argv, options))) === true; } catch { return false; } };
|
|
505
506
|
const dockets = new Dockets({ store: new Store(`${dataDir}/dockets.json`), resources: folders,
|
|
506
|
-
|
|
507
|
+
/* Not while its tool waits for a sign-in code: the line would go into that field; the docket tries again. */
|
|
508
|
+
say: async (name, line) => ((await atCodePrompt(name)) ? false : wakeups.say(name, line)),
|
|
507
509
|
event: (name, line) => talk.event(name, line),
|
|
508
510
|
alert: (message) => { void alerts.tell({ ...message, title: `${instance.name()}: ${message.title}` }); },
|
|
509
511
|
/* Not in a turn: its pulse ended, or is old (Parley's own measure). */
|
|
@@ -579,7 +581,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
579
581
|
/* A conversation with a tool on a screen that is not its terminal: see talk.mjs. */
|
|
580
582
|
/* Voice boxes: what the tool says in their conversation is read aloud (boxes.mjs). */
|
|
581
583
|
let boxes; let rooms; let machineList;
|
|
582
|
-
const talk = new Talk({ spoke: (name, text, to, how) => { void boxes?.agentSaid(name, text, to, how); }, inRoom: (name, entry, kind) => rooms?.answered(name, entry, kind), store: talkStore, words: new Store(`${dataDir}/talk-words.json`), keptDir: `${dataDir}/talk-kept`, vms, conversations: all, resources: folders, toolbox, warm: (name) => bridge?.warm(name), ...(talkEveryMs ? { listenEveryMs: talkEveryMs } : {}),
|
|
584
|
+
const talk = new Talk({ holdLine: atCodePrompt, spoke: (name, text, to, how) => { void boxes?.agentSaid(name, text, to, how); }, inRoom: (name, entry, kind) => rooms?.answered(name, entry, kind), store: talkStore, words: new Store(`${dataDir}/talk-words.json`), keptDir: `${dataDir}/talk-kept`, vms, conversations: all, resources: folders, toolbox, warm: (name) => bridge?.warm(name), ...(talkEveryMs ? { listenEveryMs: talkEveryMs } : {}),
|
|
583
585
|
...(rereadAfterMs === undefined ? {} : { rereadAfterMs }),
|
|
584
586
|
/* A line typed down the terminal already open when there is one, and
|
|
585
587
|
what is already known of a machine used instead of asking (talk.mjs). */
|
package/server/signinhelp.mjs
CHANGED
|
@@ -157,6 +157,17 @@ export class SigninHelp {
|
|
|
157
157
|
const route = this.#readRoute(name);
|
|
158
158
|
return route?.id === ask.id && route.route === 'person';
|
|
159
159
|
}
|
|
160
|
+
/* ITS TOOL IS AT ITS « PASTE THE CODE » PROMPT (22-11, seen on a real machine): a line typed now goes into that field
|
|
161
|
+
and the sign-in fails. Asked of its screen, only while a sign-in is open and its tool has such a prompt. */
|
|
162
|
+
async atCodePrompt(name, exec) {
|
|
163
|
+
const ask = this.#readAsk(name); if (!ask) return false;
|
|
164
|
+
const at = Date.parse(ask.at); if (!Number.isFinite(at) || this.#now() - at > CODE_WAIT_MS) return false;
|
|
165
|
+
const rules = (this.#tool(name)?.signin?.screen ?? []).filter((r) => String(r).startsWith('code:')).map((r) => String(r).slice(5));
|
|
166
|
+
if (!rules.length) return false;
|
|
167
|
+
const r = await exec(['tmux', '-L', SOCKET, 'capture-pane', '-p', '-t', `=${SESSION}:`], { timeoutMs: 10_000 });
|
|
168
|
+
if (r.code !== 0) return false;
|
|
169
|
+
return rules.some((p) => { try { return new RegExp(p).test(String(r.stdout)); } catch { return false; } });
|
|
170
|
+
}
|
|
160
171
|
#readRoute(name) { try { return JSON.parse(readFileSync(join(this.#chat(name), ROUTE), 'utf8')); } catch { return null; } }
|
|
161
172
|
#line(name, line) { try { this.#event(name, line); } catch { /* its chat may be off */ } }
|
|
162
173
|
#tool(name) { const id = this.#conversations().find((c) => c.name === name)?.tool; return this.#tools().find((t) => t.id === id); }
|
package/server/talk.mjs
CHANGED
|
@@ -237,7 +237,7 @@ const PART = /^[A-Za-z0-9._~-]{1,200}$/;
|
|
|
237
237
|
export class Talk {
|
|
238
238
|
#store; #words; #vms; #conversations; #resources; #toolbox; #warm; #alert; #spoke; #inRoom; #listening = new Map(); #every; #now;
|
|
239
239
|
#typedAt = new Map(); #nextTry = new Map(); #trying = new Map(); #ticking = new Map(); #timer; #lastLang = 'en'; #rereadAfter;
|
|
240
|
-
#terminal; #health; #ranAt = new Map(); #kept; #screen; #dropSecret; #log;
|
|
240
|
+
#terminal; #health; #ranAt = new Map(); #kept; #screen; #dropSecret; #log; #holdLine;
|
|
241
241
|
|
|
242
242
|
/* `alert({ title, body, url })`: told when the tool asks, or waits.
|
|
243
243
|
`words`: a store for the owner's choice of words (one record). */
|
|
@@ -247,8 +247,8 @@ export class Talk {
|
|
|
247
247
|
/* `keptDir`: where each conversation's thread is kept (its own folder),
|
|
248
248
|
in this server's data -- never in the work folder, which its machine
|
|
249
249
|
writes. Without it, the bridge folder is all there is. */
|
|
250
|
-
constructor({ store, words, vms, conversations, resources, toolbox = null, warm = async () => {}, alert = () => {}, spoke = () => {}, inRoom = () => {}, listenEveryMs = 2000, now = () => Date.now(), rereadAfterMs = REREAD_AFTER_MS, terminal = null, health = null, keptDir = null, screen = null, dropSecret = null, log = (line) => console.log(line) }) {
|
|
251
|
-
this.#log = log;
|
|
250
|
+
constructor({ store, words, vms, conversations, resources, toolbox = null, warm = async () => {}, alert = () => {}, spoke = () => {}, inRoom = () => {}, listenEveryMs = 2000, now = () => Date.now(), rereadAfterMs = REREAD_AFTER_MS, terminal = null, health = null, keptDir = null, screen = null, dropSecret = null, holdLine = null, log = (line) => console.log(line) }) {
|
|
251
|
+
this.#log = log; this.#holdLine = holdLine;
|
|
252
252
|
this.#terminal = terminal; this.#health = health; this.#kept = keptDir; this.#screen = screen; this.#dropSecret = dropSecret;
|
|
253
253
|
this.#store = store; this.#words = words; this.#vms = vms; this.#conversations = conversations; this.#resources = resources; this.#toolbox = toolbox; this.#warm = warm; this.#alert = alert; this.#spoke = spoke; this.#inRoom = inRoom; this.#every = listenEveryMs; this.#now = now; this.#rereadAfter = rereadAfterMs;
|
|
254
254
|
for (const s of store.all()) if (s.on === true) this.#listen(s.name);
|
|
@@ -827,6 +827,8 @@ export class Talk {
|
|
|
827
827
|
const quiet = this.#now() - (this.#typedAt.get(name) ?? 0);
|
|
828
828
|
if (quiet < TYPING_QUIET_MS) return waits('typing', TYPING_QUIET_MS - quiet + 100);
|
|
829
829
|
if (!(await this.#runs(name))) return waits('asleep', RETRY_MS);
|
|
830
|
+
/* At its sign-in code prompt: a line typed now would go into that field (signinhelp.mjs). It waits. */
|
|
831
|
+
if (await Promise.resolve(this.#holdLine?.(name)).catch(() => false)) return waits('signing-in', RETRY_MS);
|
|
830
832
|
if (renudge) this.#log(`talk: ${name}: still unread ${Math.round((this.#now() - Date.parse(r.typedAt ?? '')) / 1000)} s after its line: typed again (${(r.renudged ?? 0) + 1})`);
|
|
831
833
|
if (!(await this.#type(name, urgent ? URGENT : WAKE).catch((error) => { this.#log(`talk: ${name}: NOT typed: ${error?.message}`); return false; }))) return waits('failed', RETRY_MS);
|
|
832
834
|
this.#store.put({ ...this.#store.get(name), pending: false, woke: true, why: null, again: false, renudge: false, typedAt: new Date(this.#now()).toISOString(), toldRead: this.#readCount(name), toldUnread: unread, renudged: renudge ? (r.renudged ?? 0) + 1 : 0 });
|