clavarium 0.2.241-beta.1 → 0.2.242-beta.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.
@@ -31,7 +31,7 @@
31
31
  */
32
32
  import { spawnSync } from 'node:child_process';
33
33
  import { randomUUID } from 'node:crypto';
34
- import { existsSync, readFileSync, renameSync, statSync, writeFileSync } from 'node:fs';
34
+ import { existsSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
35
35
  import { dirname, join } from 'node:path';
36
36
  import { fileURLToPath } from 'node:url';
37
37
 
@@ -138,6 +138,8 @@ if (main) {
138
138
  if (CODE.test(code)) {
139
139
  spawnSync('tmux', [...tmux, 'send-keys', '-t', pane, '-l', '--', code], { timeout: 5000 });
140
140
  spawnSync('tmux', [...tmux, 'send-keys', '-t', pane, 'Enter'], { timeout: 5000 });
141
+ /* Typed: the ask is over, so the next message that looks like a code is a secret again (#394). */
142
+ try { rmSync(`${chat}/signin-ask.json`, { force: true }); } catch { /* left: it runs out on the server's side */ }
141
143
  awaiting = null; return;
142
144
  }
143
145
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.241-beta.1",
3
+ "version": "0.2.242-beta.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.241-beta.1",
9
+ "version": "0.2.242-beta.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.241-beta.1",
3
+ "version": "0.2.242-beta.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "A conversation is a VM with a terminal in it. Everything else is a folder.",
package/server/main.mjs CHANGED
@@ -592,6 +592,8 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
592
592
  the chat shows as stars; the value reaches the machine as
593
593
  /run/secrets/<name>, and is swept after a few minutes. */
594
594
  screen: async (conversation, text) => {
595
+ /* A sign-in code its tool waits for (#394): left whole, screen-watch types it in. */
596
+ if (signinHelp?.awaitsCode(conversation, text)) return text;
595
597
  const hits = scan(text);
596
598
  if (!hits.length) return text;
597
599
  let out = ''; let last = 0; let any = false;
@@ -40,6 +40,8 @@ export const ROUTE = 'signin-route.json';
40
40
  export const CHAT = '.parley';
41
41
  export const DOCKET = '.docket';
42
42
  export const WAIT_MS = 10 * 60_000;
43
+ /* How long after its tool asked a code pasted by the person is taken as that code (and not as a secret). */
44
+ export const CODE_WAIT_MS = 30 * 60_000;
43
45
  export const TICK_MS = 3000;
44
46
  export const NONE = 'none';
45
47
  const ASK_BYTES = 16_384;
@@ -143,6 +145,18 @@ export class SigninHelp {
143
145
  if (!this.#own(dir)) return;
144
146
  try { writeFileSync(join(dir, `.${ROUTE}.new`), JSON.stringify(route)); renameSync(join(dir, `.${ROUTE}.new`), join(dir, ROUTE)); } catch { /* its chat folder cannot be written: screen-watch tells the person itself */ }
145
147
  }
148
+ /* A CODE AWAITED FROM THE PERSON (20-11, #394): its tool asked to sign in, the link was told to the person (not
149
+ handed to a companion), a short while ago. Then a message that is nothing but a code is that code: typed into
150
+ the tool by screen-watch, never lifted out as a secret (19-11: « code#state » kept as two secrets, the tool
151
+ never got it). */
152
+ awaitsCode(name, text) {
153
+ if (!CODE.test(String(text ?? '').trim())) return false;
154
+ const ask = this.#readAsk(name); if (!ask) return false;
155
+ const at = Date.parse(ask.at); if (!Number.isFinite(at) || this.#now() - at > CODE_WAIT_MS || at > this.#now() + 60_000) return false;
156
+ if (ask.told === true) return true;
157
+ const route = this.#readRoute(name);
158
+ return route?.id === ask.id && route.route === 'person';
159
+ }
146
160
  #readRoute(name) { try { return JSON.parse(readFileSync(join(this.#chat(name), ROUTE), 'utf8')); } catch { return null; } }
147
161
  #line(name, line) { try { this.#event(name, line); } catch { /* its chat may be off */ } }
148
162
  #tool(name) { const id = this.#conversations().find((c) => c.name === name)?.tool; return this.#tools().find((t) => t.id === id); }