clavarium 0.2.517-next.1 → 0.2.519-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 +2 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/conversations.mjs +3 -1
- package/server/signinhelp.mjs +39 -21
- package/server/tools.mjs +3 -1
- package/web/app.js +2 -2
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
|
{
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.519-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.519-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/conversations.mjs
CHANGED
|
@@ -303,7 +303,7 @@ export class Conversations {
|
|
|
303
303
|
return this.#store.all().sort((a, b) => order.indexOf(a.name) - order.indexOf(b.name)).map((c) => {
|
|
304
304
|
const tool = this.#tools.find((t) => t.id === c.tool);
|
|
305
305
|
/* An AI tool has an instruction file; a shell has none: what is dictated there is never marked. */
|
|
306
|
-
return { ...c, ...(c.lentTo && !this.#borrowed.has(c.name) ? { lentTo: undefined } : {}), rank: order.indexOf(c.name), ...(c.group ? { groupRank: groups.indexOf(c.group) } : {}), toolLabel: tool?.label ?? c.tool, memoryMinMb: tool?.memoryMb, resumes: Boolean(tool?.resume), switches: canSwitch(tool), rights: Boolean(tool?.rights), ai: Boolean(tool?.instructions), voiceMark: Boolean(tool?.instructions) && c.voiceMark !== false, cpus: c.cpus ?? 1, hostCpus: availableParallelism() };
|
|
306
|
+
return { ...c, ...(c.lentTo && !this.#borrowed.has(c.name) ? { lentTo: undefined } : {}), rank: order.indexOf(c.name), ...(c.group ? { groupRank: groups.indexOf(c.group) } : {}), toolLabel: tool?.label ?? c.tool, memoryMinMb: tool?.memoryMb, resumes: Boolean(tool?.resume), switches: canSwitch(tool) && !c.sharedMachine, rights: Boolean(tool?.rights), ai: Boolean(tool?.instructions), voiceMark: Boolean(tool?.instructions) && c.voiceMark !== false, cpus: c.cpus ?? 1, hostCpus: availableParallelism() };
|
|
307
307
|
});
|
|
308
308
|
}
|
|
309
309
|
|
|
@@ -979,6 +979,8 @@ export class Conversations {
|
|
|
979
979
|
const target = this.#tools.find((t) => t.id === to);
|
|
980
980
|
if (typeof to !== 'string' || !target) throw new Refusal(400, 'This AI is not offered here.');
|
|
981
981
|
if (to === c.tool) throw new Refusal(409, `It already runs ${target.label}.`);
|
|
982
|
+
/* Not tried on a real shared machine yet (22-11): refused rather than promised. */
|
|
983
|
+
if (c.sharedMachine) throw new Refusal(409, 'Changing its AI needs its own machine.');
|
|
982
984
|
if (!canSwitch(from)) throw new Refusal(409, `${from?.label ?? c.tool} cannot be changed for another AI.`);
|
|
983
985
|
if (!canSwitch(target)) throw new Refusal(400, `A conversation cannot change to ${target.label}.`);
|
|
984
986
|
if (c.lentTo || this.#store.all().some((x) => x.copyOf === name && x.phase === 'building')) throw new Refusal(409, 'It is being copied: change its AI after.', { retry: true });
|
package/server/signinhelp.mjs
CHANGED
|
@@ -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 =
|
|
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,25 +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
|
-
/*
|
|
201
|
-
again and nothing else is typed into that prompt meanwhile. */
|
|
202
|
-
const end = Date.now() + this.codeSettleMs;
|
|
203
|
-
const still = () => this.atCodePrompt(name, exec, { last: 3 }).catch(() => false);
|
|
204
|
-
let waiting = await still();
|
|
205
|
-
while (waiting && Date.now() < end) {
|
|
206
|
-
await new Promise((r) => { setTimeout(r, 1000).unref?.(); });
|
|
207
|
-
waiting = await still();
|
|
208
|
-
}
|
|
209
|
-
if (waiting) throw new Refusal(422, 'The tool did not accept this code.');
|
|
210
|
-
/* Accepted: the ask is over, whatever comes next is not this code. */
|
|
211
|
-
const dir = this.#chat(name);
|
|
212
|
-
if (this.#own(dir)) { try { rmSync(join(dir, ASK), { force: true }); } catch { /* it runs out by itself */ } }
|
|
213
|
-
this.#route(name, { id: ask.id, route: 'done' });
|
|
214
|
-
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. */
|
|
215
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));
|
|
216
208
|
return { ok: true };
|
|
217
209
|
} finally { this.#typing.delete(name); }
|
|
218
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
|
+
}
|
|
219
234
|
/* Its tool shows its prompt, its link told: one line in its chat, with the button that opens the field. */
|
|
220
235
|
async #offerCode(name, ask) {
|
|
221
236
|
if (ask.told !== true || !this.#exec || this.#offered.get(name) === ask.id || this.#open.has(name)) return;
|
|
@@ -228,17 +243,20 @@ export class SigninHelp {
|
|
|
228
243
|
}
|
|
229
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
|
|
230
245
|
and the sign-in fails. Asked of its screen, only while a sign-in is open and its tool has such a prompt. */
|
|
231
|
-
async atCodePrompt(name, exec
|
|
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) {
|
|
232
252
|
const ask = this.#readAsk(name); if (!ask) return false;
|
|
233
253
|
const at = Date.parse(ask.at); if (!Number.isFinite(at) || this.#now() - at > CODE_WAIT_MS) return false;
|
|
234
254
|
const rules = (this.#tool(name)?.signin?.screen ?? []).filter((r) => String(r).startsWith('code:')).map((r) => String(r).slice(5));
|
|
235
255
|
if (!rules.length) return false;
|
|
236
256
|
const r = await exec(['tmux', '-L', SOCKET, 'capture-pane', '-p', '-t', `=${SESSION}:`], { timeoutMs: 10_000 });
|
|
237
257
|
if (r.code !== 0) return false;
|
|
238
|
-
/* As screen-watch reads it: the bottom of the screen, whatever the case.
|
|
239
|
-
code typed then would go to the AI as a message. */
|
|
258
|
+
/* As screen-watch reads it: the bottom of the screen, whatever the case. */
|
|
240
259
|
const lines = String(r.stdout).replace(/\s+$/u, '').split('\n');
|
|
241
|
-
/* `last`: only its last written lines: a prompt the tool has answered and moved on from stays higher up. */
|
|
242
260
|
const bottom = (last ? lines.filter((l) => l.trim()).slice(-last) : lines.slice(-SCREEN_LINES)).join('\n');
|
|
243
261
|
return rules.some((p) => { try { return new RegExp(p, 'i').test(bottom); } catch { return false; } });
|
|
244
262
|
}
|
package/server/tools.mjs
CHANGED
|
@@ -96,7 +96,9 @@ export function readTools(text) {
|
|
|
96
96
|
}
|
|
97
97
|
screen = Object.freeze([...rules]);
|
|
98
98
|
}
|
|
99
|
-
|
|
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.') :
|
|
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
|
}
|