clavarium 0.2.516-next.1 → 0.2.518-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/config/tools.json CHANGED
@@ -77,9 +77,9 @@
77
77
  "type:(Not logged in|Login expired|OAuth token (has )?expired|Invalid API key)[^\\n]{0,24}/login=/login",
78
78
  "keys:Select login method:=Enter",
79
79
  "link:https://(claude\\.ai|claude\\.com|console\\.anthropic\\.com)/\\S*oauth\\S*",
80
- "keys:OAuth error[\\s\\S]{0,160}Press Enter to retry=Enter",
81
80
  "code:Paste code here"
82
- ]
81
+ ],
82
+ "refused": "OAuth error"
83
83
  }
84
84
  },
85
85
  {
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.516-next.1",
3
+ "version": "0.2.518-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.516-next.1",
9
+ "version": "0.2.518-next.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.516-next.1",
3
+ "version": "0.2.518-next.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.",
@@ -53,8 +53,9 @@ export const OFFER_EVERY_MS = 6000;
53
53
  const SCREEN_LINES = 12;
54
54
  export const CODE_LINE = 'Once signed in, paste the code.';
55
55
  export const CODE_SENT = 'Code sent to the tool.';
56
+ export const CODE_REFUSED = 'Code refused. Paste it again.';
56
57
  /* How long its tool is given to leave its prompt once a code is typed: still there, the code was not accepted. */
57
- export const CODE_SETTLE_MS = 12_000;
58
+ export const CODE_SETTLE_MS = 30_000;
58
59
  export const NONE = 'none';
59
60
  const ASK_BYTES = 16_384;
60
61
  const LINK_MAX = 4000;
@@ -90,6 +91,9 @@ export class SigninHelp {
90
91
  #offered = new Map();
91
92
  #looked = new Map();
92
93
  #typing = new Set();
94
+ #settling = new Set();
95
+ /* Its end, for whoever waits for it (tests). */
96
+ settled = Promise.resolve();
93
97
  codeSettleMs = CODE_SETTLE_MS;
94
98
 
95
99
  /* `store`: { get(), set(v) } of { general, per: { name: companion | NONE } }. `conversations()`: [{ name, tool }].
@@ -189,7 +193,7 @@ export class SigninHelp {
189
193
  if (!CODE.test(code)) throw new Refusal(400, 'This is not a sign-in code.');
190
194
  const ask = this.#personsAsk(name);
191
195
  if (!ask) throw new Refusal(409, 'No sign-in is waiting for a code here.');
192
- if (this.#typing.has(name)) throw new Refusal(409, 'A code is already being sent.');
196
+ if (this.#typing.has(name) || this.#settling.has(name)) throw new Refusal(409, 'A code is already being sent.');
193
197
  this.#typing.add(name);
194
198
  try {
195
199
  const exec = (argv, options) => this.#exec(name, argv, options);
@@ -197,24 +201,36 @@ export class SigninHelp {
197
201
  if (!at) throw new Refusal(409, 'Its tool is not waiting for a code now.');
198
202
  const typed = await Promise.resolve(this.#type(name, code)).catch(() => false);
199
203
  if (!typed) throw new Refusal(502, 'The code could not be typed into the tool.');
200
- /* STILL AT ITS PROMPT (22-11, a wrong code on a real machine): the ask stays, so that the field can be used
201
- again and nothing else is typed into that prompt meanwhile. */
202
- const end = Date.now() + this.codeSettleMs;
203
- let waiting = await this.atCodePrompt(name, exec).catch(() => false);
204
- while (waiting && Date.now() < end) {
205
- await new Promise((r) => { setTimeout(r, 1000).unref?.(); });
206
- waiting = await this.atCodePrompt(name, exec).catch(() => false);
207
- }
208
- if (waiting) throw new Refusal(422, 'The tool did not accept this code.');
209
- /* Accepted: the ask is over, whatever comes next is not this code. */
210
- const dir = this.#chat(name);
211
- if (this.#own(dir)) { try { rmSync(join(dir, ASK), { force: true }); } catch { /* it runs out by itself */ } }
212
- this.#route(name, { id: ask.id, route: 'done' });
213
- this.#offered.delete(name); this.#looked.delete(name);
204
+ /* Sent: said at once. What its tool makes of it comes some 15 s later (seen on a real machine): watched. */
214
205
  this.#line(name, { kind: KIND, text: CODE_SENT, topic: 'Sign-in', brief: 'Code sent' });
206
+ this.#settling.add(name);
207
+ this.settled = this.#settle(name, ask, exec).catch(() => {}).finally(() => this.#settling.delete(name));
215
208
  return { ok: true };
216
209
  } finally { this.#typing.delete(name); }
217
210
  }
211
+ /* WHAT ITS TOOL MADE OF THE CODE. Refused, in its own words (`signin.refused`), or still at its prompt at the end:
212
+ back to its prompt, the ask stays, a line offers the field again. Otherwise the ask is over. While this runs
213
+ nothing else is typed into the tool (atCodePrompt answers yes). */
214
+ async #settle(name, ask, exec) {
215
+ const refused = this.#tool(name)?.signin?.refused;
216
+ const end = Date.now() + this.codeSettleMs;
217
+ const again = () => this.#line(name, { kind: KIND, text: CODE_REFUSED, level: 'needs-you', topic: 'Sign-in', brief: 'Code refused', actions: ['signincode'] });
218
+ for (;;) {
219
+ const seen = await exec(['tmux', '-L', SOCKET, 'capture-pane', '-p', '-t', `=${SESSION}:`], { timeoutMs: 10_000 }).catch(() => ({ code: 1, stdout: '' }));
220
+ if (refused && seen.code === 0 && String(seen.stdout).includes(refused)) {
221
+ await exec(['tmux', '-L', SOCKET, 'send-keys', '-t', `=${SESSION}:`, 'Enter'], { timeoutMs: 10_000 }).catch(() => {});
222
+ again();
223
+ return;
224
+ }
225
+ if (Date.now() >= end) break;
226
+ await new Promise((r) => { setTimeout(r, 1000).unref?.(); });
227
+ }
228
+ if (await this.#promptOnScreen(name, exec, 3).catch(() => false)) { again(); return; }
229
+ const dir = this.#chat(name);
230
+ if (this.#own(dir)) { try { rmSync(join(dir, ASK), { force: true }); } catch { /* it runs out by itself */ } }
231
+ this.#route(name, { id: ask.id, route: 'done' });
232
+ this.#offered.delete(name); this.#looked.delete(name);
233
+ }
218
234
  /* Its tool shows its prompt, its link told: one line in its chat, with the button that opens the field. */
219
235
  async #offerCode(name, ask) {
220
236
  if (ask.told !== true || !this.#exec || this.#offered.get(name) === ask.id || this.#open.has(name)) return;
@@ -228,15 +244,20 @@ export class SigninHelp {
228
244
  /* ITS TOOL IS AT ITS « PASTE THE CODE » PROMPT (22-11, seen on a real machine): a line typed now goes into that field
229
245
  and the sign-in fails. Asked of its screen, only while a sign-in is open and its tool has such a prompt. */
230
246
  async atCodePrompt(name, exec) {
247
+ if (this.#settling.has(name)) return true;
248
+ return this.#promptOnScreen(name, exec, 0);
249
+ }
250
+ /* `last`: only its last written lines: a prompt the tool has answered and moved on from stays higher up. */
251
+ async #promptOnScreen(name, exec, last) {
231
252
  const ask = this.#readAsk(name); if (!ask) return false;
232
253
  const at = Date.parse(ask.at); if (!Number.isFinite(at) || this.#now() - at > CODE_WAIT_MS) return false;
233
254
  const rules = (this.#tool(name)?.signin?.screen ?? []).filter((r) => String(r).startsWith('code:')).map((r) => String(r).slice(5));
234
255
  if (!rules.length) return false;
235
256
  const r = await exec(['tmux', '-L', SOCKET, 'capture-pane', '-p', '-t', `=${SESSION}:`], { timeoutMs: 10_000 });
236
257
  if (r.code !== 0) return false;
237
- /* As screen-watch reads it: the bottom of the screen, whatever the case. A prompt left higher up is over, and a
238
- code typed then would go to the AI as a message. */
239
- const bottom = String(r.stdout).replace(/\s+$/u, '').split('\n').slice(-SCREEN_LINES).join('\n');
258
+ /* As screen-watch reads it: the bottom of the screen, whatever the case. */
259
+ const lines = String(r.stdout).replace(/\s+$/u, '').split('\n');
260
+ const bottom = (last ? lines.filter((l) => l.trim()).slice(-last) : lines.slice(-SCREEN_LINES)).join('\n');
240
261
  return rules.some((p) => { try { return new RegExp(p, 'i').test(bottom); } catch { return false; } });
241
262
  }
242
263
  #readRoute(name) { try { return JSON.parse(readFileSync(join(this.#chat(name), ROUTE), 'utf8')); } catch { return null; } }
package/server/tools.mjs CHANGED
@@ -96,7 +96,9 @@ export function readTools(text) {
96
96
  }
97
97
  screen = Object.freeze([...rules]);
98
98
  }
99
- signin = Object.freeze({ senders: Object.freeze([...t.signin.senders]), links: Object.freeze([...t.signin.links]), ...(screen ? { screen } : {}) });
99
+ /* `refused`: the tool's own words when it turns a sign-in code down (signinhelp.mjs). */
100
+ if (t.signin.refused !== undefined && (typeof t.signin.refused !== 'string' || !t.signin.refused.trim() || t.signin.refused.length > 80)) throw new Error(`${t.id}: signin "refused" is a short text`);
101
+ signin = Object.freeze({ ...(t.signin.refused ? { refused: t.signin.refused } : {}), senders: Object.freeze([...t.signin.senders]), links: Object.freeze([...t.signin.links]), ...(screen ? { screen } : {}) });
100
102
  }
101
103
  /* Optional: the command that starts it taking up its last session
102
104
  ("claude --continue"); used instead of `command` once it has run on
package/web/app.js CHANGED
@@ -3987,7 +3987,7 @@
3987
3987
  if (many) void openGit(many[1], { commit: many[2], base: many[3], tab: Number(many[4]) > 1 ? 'commits' : 'changes' });
3988
3988
  else if (one) void openGit(one[1], { commit: one[2] });
3989
3989
  }
3990
- const SIGNIN_SAID = { 'Once signed in, paste the code.': 'set-signin-code-line', 'Code sent to the tool.': 'set-signin-code-sent' };
3990
+ const SIGNIN_SAID = { 'Once signed in, paste the code.': 'set-signin-code-line', 'Code sent to the tool.': 'set-signin-code-sent', 'Code refused. Paste it again.': 'set-signin-code-rejected' };
3991
3991
  function machineLines(data) {
3992
3992
  if (!Array.isArray(data?.messages)) return data;
3993
3993
  const kindOf = (id) => String(id).split(':')[0];
@@ -9117,7 +9117,7 @@
9117
9117
  try { status = (await fetch(`${API}/conversations/${encodeURIComponent(to)}/signin-code?c=${encodeURIComponent(to)}`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ code }) })).status; } catch { /* said below */ }
9118
9118
  send.disabled = false;
9119
9119
  if (status === 200) { box.close(); void thread?.refresh?.(); return; }
9120
- why.textContent = status === 400 ? uiSaid('set-signin-code-bad', 'This is not a code.') : status === 409 ? uiSaid('set-signin-code-late', 'The tool is no longer waiting for a code.') : status === 422 ? uiSaid('set-signin-code-rejected', 'Code not accepted. Paste it again.') : uiSaid('set-signin-code-failed', 'Not sent. Try again.');
9120
+ why.textContent = status === 400 ? uiSaid('set-signin-code-bad', 'This is not a code.') : status === 409 ? uiSaid('set-signin-code-late', 'The tool is no longer waiting for a code.') : uiSaid('set-signin-code-failed', 'Not sent. Try again.');
9121
9121
  why.hidden = false; input.focus();
9122
9122
  });
9123
9123
  }