clavarium 0.2.143-next.1 → 0.2.145-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/gitaccess.mjs +32 -0
- package/server/gitkeeper.mjs +8 -5
- package/server/gitpush.mjs +15 -2
- package/server/main.mjs +7 -2
- package/server/talk.mjs +18 -1
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.145-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.145-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/gitaccess.mjs
CHANGED
|
@@ -83,6 +83,38 @@ export function explain(stderr) {
|
|
|
83
83
|
return String(text).trim().split('\n').filter(Boolean).pop()?.slice(0, 300) ?? '';
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
/* What the remote's own hooks said (pre-receive, update: the "remote:" lines of a push), for a
|
|
87
|
+
person and for the agent: colours and control characters out, git's progress lines out, the
|
|
88
|
+
last REMOTE_LINES lines, REMOTE_CHARS characters at most. Text of the remote: data, quoted. */
|
|
89
|
+
export const REMOTE_ALL = 64 * 1024;
|
|
90
|
+
/* All of it, cleaned the same way, for a file the agent reads (REMOTE_ALL characters at most, the end kept). */
|
|
91
|
+
export function remoteAll(stderr) {
|
|
92
|
+
const text = String(stderr ?? '').split(/\r?\n|\r/).filter((l) => /^remote:/.test(l))
|
|
93
|
+
.map((l) => l.replace(/^remote:\s?/, '').replace(/\x1b\[[0-9;?]*[ -\/]*[@-~]/g, '').replace(/[\x00-\x08\x0b-\x1f\x7f]/g, '').trimEnd()).join('\n').trim();
|
|
94
|
+
return text.length > REMOTE_ALL ? `…${text.slice(-REMOTE_ALL)}` : text;
|
|
95
|
+
}
|
|
96
|
+
export const REMOTE_LINES = 20;
|
|
97
|
+
export const REMOTE_CHARS = 1500;
|
|
98
|
+
export function remoteSaid(stderr) {
|
|
99
|
+
const lines = String(stderr ?? '').split(/\r?\n|\r/)
|
|
100
|
+
.filter((l) => /^remote:/.test(l))
|
|
101
|
+
.map((l) => l.replace(/^remote:\s?/, '').replace(/\x1b\[[0-9;?]*[ -\/]*[@-~]/g, '').replace(/[\x00-\x1f\x7f]/g, '').trimEnd())
|
|
102
|
+
.filter((l) => l.trim() && !/^(Resolving deltas|Counting objects|Compressing objects|Processing changes|Total \d|Enumerating objects|Writing objects)\b/.test(l.trim()));
|
|
103
|
+
/* A very talkative hook: the lines that say what is wrong first (error, refused, must…), in their
|
|
104
|
+
order, then the end of what it said, up to REMOTE_LINES; "[N lines left out]" where lines went. */
|
|
105
|
+
let kept = lines;
|
|
106
|
+
if (lines.length > REMOTE_LINES) {
|
|
107
|
+
const telling = new Set(lines.map((l, i) => (/\b(error|errors|denied|reject|rejected|refused|must|fail|failed|failure|forbidden|invalid|not allowed|violation|required|missing|GH\d{3})\b/i.test(l) ? i : -1)).filter((i) => i >= 0).slice(0, REMOTE_LINES - 5));
|
|
108
|
+
for (let i = lines.length - 1; telling.size < REMOTE_LINES && i >= 0; i -= 1) telling.add(i);
|
|
109
|
+
const picked = [...telling].sort((a, b) => a - b);
|
|
110
|
+
kept = [];
|
|
111
|
+
picked.forEach((i, k) => { const gap = i - (k ? picked[k - 1] + 1 : 0); if (gap > 0) kept.push(`[${gap} line${gap > 1 ? 's' : ''} left out]`); kept.push(lines[i]); });
|
|
112
|
+
}
|
|
113
|
+
let text = kept.join('\n');
|
|
114
|
+
if (text.length > REMOTE_CHARS) text = `…${text.slice(-REMOTE_CHARS)}`;
|
|
115
|
+
return text;
|
|
116
|
+
}
|
|
117
|
+
|
|
86
118
|
/* An ed25519 key pair in the formats OpenSSH reads, made with Node's own
|
|
87
119
|
crypto: no program is run and nothing touches the disk. The private key is
|
|
88
120
|
the unencrypted "openssh-key-v1" container (it is encrypted by the vault). */
|
package/server/gitkeeper.mjs
CHANGED
|
@@ -396,10 +396,11 @@ export class GitKeeper {
|
|
|
396
396
|
#attached(name) { try { return Object.entries(this.#resources.list().find((x) => x.name === name)?.attachments ?? {}).filter(([, access]) => access && access !== 'none').map(([c]) => c).sort(); } catch { return []; } }
|
|
397
397
|
/* Marked as told only once somebody was: a line typed to no machine
|
|
398
398
|
(all asleep, a terminal that failed) is said again the next time. */
|
|
399
|
-
|
|
399
|
+
/* `full`: a longer text the line stands for (all a remote said), that the agent can be given to read. */
|
|
400
|
+
#toAgent(name, line, conversation, full) {
|
|
400
401
|
if (this.#record(name).toldAgent === line || this.#telling.get(name) === line) return;
|
|
401
402
|
this.#telling.set(name, line);
|
|
402
|
-
void Promise.resolve(this.#tellAgent(name, `Clavarium, repository ${name}: ${line}.`, conversation))
|
|
403
|
+
void Promise.resolve(this.#tellAgent(name, `Clavarium, repository ${name}: ${line}.`, conversation, full))
|
|
403
404
|
.then((heard) => { if (heard !== false) this.#patch(name, { toldAgent: line }); }, () => {})
|
|
404
405
|
.finally(() => { if (this.#telling.get(name) === line) this.#telling.delete(name); });
|
|
405
406
|
}
|
|
@@ -608,6 +609,8 @@ export class GitKeeper {
|
|
|
608
609
|
if (['look', 'confirm', 'busy'].includes(error.kind)) return;
|
|
609
610
|
this.#log(name, { ok: false, branch: branch ?? null, head: head ?? null, what: error.message });
|
|
610
611
|
if (error.alert) this.#tell(`${name}: sending needs a look`, error.message);
|
|
612
|
+
/* Refused by the remote, sent by hand: what it said is the agent's to act on too. */
|
|
613
|
+
if (error.kind === 'refused' && error.ai) this.#toAgent(name, error.ai, undefined, error.full);
|
|
611
614
|
if (error.kind === 'unknown-unreachable' && branch) this.#patch(name, { blocked: { ...(this.#record(name).blocked ?? {}), [branch]: { head, at: this.#now().toISOString() } } });
|
|
612
615
|
}
|
|
613
616
|
|
|
@@ -638,10 +641,10 @@ export class GitKeeper {
|
|
|
638
641
|
const said = held.said.get(b) ?? new Map();
|
|
639
642
|
if (said.get(conversation) === key) return;
|
|
640
643
|
said.set(conversation, key); held.said.set(b, said);
|
|
641
|
-
const { tell, ai, ...rest } = entry;
|
|
644
|
+
const { tell, ai, full, ...rest } = entry;
|
|
642
645
|
this.#log(name, { branch: b, head: tip.id, ok: false, ...(conversation ? { conversation } : {}), ...rest });
|
|
643
646
|
if (tell && this.settings(name).alert) this.#tell(`${name}: not sent`, entry.what);
|
|
644
|
-
if (ai) this.#toAgent(name, ai, conversation || undefined);
|
|
647
|
+
if (ai) this.#toAgent(name, ai, conversation || undefined, full);
|
|
645
648
|
/* A sending that the owner asked for, refused: said in that
|
|
646
649
|
conversation's chat with what to do. Not a branch outside every
|
|
647
650
|
list -- nothing was asked for it -- nor what is the repository's
|
|
@@ -732,7 +735,7 @@ export class GitKeeper {
|
|
|
732
735
|
routine notices says -- once, and once only. */
|
|
733
736
|
const grave = error instanceof GitFailure && error.alert;
|
|
734
737
|
if (grave && held.said.get(b)?.get(conversation) !== `${tip.id}:${why}`) this.#tell(`${name}: sending needs a look`, error.message);
|
|
735
|
-
once(why, { what: error instanceof Refusal ? error.message : 'Not sent: the sending failed.', tell: !grave, ...(error.ai ? { ai: error.ai.replace(/origin\/(\S+)/g, (m, x) => `origin/${plain(x)}`) } : {}) });
|
|
738
|
+
once(why, { what: error instanceof Refusal ? error.message : 'Not sent: the sending failed.', tell: !grave, ...(error.ai ? { ai: error.ai.replace(/origin\/(\S+)/g, (m, x) => `origin/${plain(x)}`) } : {}), ...(error.full ? { full: error.full } : {}) });
|
|
736
739
|
return false;
|
|
737
740
|
}
|
|
738
741
|
}
|
package/server/gitpush.mjs
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* password, which only ever goes back to the https origin it was given for.
|
|
28
28
|
*/
|
|
29
29
|
import { Refusal } from './conversations.mjs';
|
|
30
|
-
import { GitAccess, readAddress, explain } from './gitaccess.mjs';
|
|
30
|
+
import { GitAccess, readAddress, explain, remoteSaid, remoteAll } from './gitaccess.mjs';
|
|
31
31
|
import { GitRunner, GitFailure, EMPTY_TREE, branchProblem, protocolOf, isId } from './gitrunner.mjs';
|
|
32
32
|
|
|
33
33
|
export { branchProblem };
|
|
@@ -653,7 +653,20 @@ export class GitReview {
|
|
|
653
653
|
if (line && ours && (flag === '+' || /forced update/.test(summary))) throw new GitFailure(502, 'forced', 'The push was not as reviewed (a forced update): look at the remote.', { alert: true });
|
|
654
654
|
if (line && !ours && (flag === ' ' || flag === '*' || flag === '+')) throw new GitFailure(502, 'forced', 'The push was not as reviewed (another source): look at the remote.', { alert: true });
|
|
655
655
|
if (flag === '!' && /stale info|fetch first|non-fast-forward/.test(summary)) throw new GitFailure(409, 'remote-moved', `Not sent: the remote's ${target} moved (the lease was refused). Look again.`, { ai: `origin/${target} moved: pull origin/${target} first` });
|
|
656
|
-
if (pushed.code !== 0 || !(flag === ' ' || flag === '*'))
|
|
656
|
+
if (pushed.code !== 0 || !(flag === ' ' || flag === '*')) {
|
|
657
|
+
/* Why, as the remote put it: its verdict on our ref ("[remote rejected] (pre-receive hook
|
|
658
|
+
declined)") rather than git's closing "failed to push some refs", and what its hooks
|
|
659
|
+
said -- to the owner, and to the agent that can fix the commit. */
|
|
660
|
+
const verdict = flag === '!' && summary ? firstLine(summary) : '';
|
|
661
|
+
const hooks = remoteSaid(pushed.stderr);
|
|
662
|
+
const why = verdict || explain(pushed.stderr) || firstLine(summary);
|
|
663
|
+
const said = hooks ? `; it said: "${hooks.split('\n').join(' / ').replace(/"/g, "'")}"` : '';
|
|
664
|
+
const failure = new GitFailure(502, 'refused', `The remote refused: ${why}${said}`, { detail: hooks, ai: `the remote refused the sending to ${target}: ${why}${said}` });
|
|
665
|
+
/* All it said, when the summary left some out: put where the agent can read it (main.mjs). */
|
|
666
|
+
const all = remoteAll(pushed.stderr);
|
|
667
|
+
if (all && all !== hooks) failure.full = all;
|
|
668
|
+
throw failure;
|
|
669
|
+
}
|
|
657
670
|
/* (5) The pushed commits enter the reference only as the remote's history. */
|
|
658
671
|
const after = await this.#refreshLocked(r, { branch: target, head });
|
|
659
672
|
return sent(after.ok ? {} : { refreshed: false, note: 'Sent; the reference was not refreshed.' });
|
package/server/main.mjs
CHANGED
|
@@ -428,11 +428,16 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
428
428
|
automatic sending to the branches the owner listed: see gitkeeper.mjs. */
|
|
429
429
|
/* What could not be read is told to the agents that write in the repository, where they can act. */
|
|
430
430
|
/* `only`: the conversation whose automatic sending it is about: its agent alone can act on it. */
|
|
431
|
-
|
|
431
|
+
/* `full`: what the line sums up (all a remote said), put in each one's chat folder for it to read. */
|
|
432
|
+
const tellAgent = async (repository, line, only, full) => {
|
|
432
433
|
const writers = Object.entries(folders.list().find((x) => x.name === repository)?.attachments ?? {}).filter(([, access]) => access === 'write').map(([conversation]) => conversation).filter((c) => only === undefined || c === only);
|
|
433
434
|
/* Told: at least one of them had the line typed (see GitKeeper #toAgent). */
|
|
434
435
|
let heard = false;
|
|
435
|
-
for (const conversation of writers)
|
|
436
|
+
for (const conversation of writers) {
|
|
437
|
+
let path = null;
|
|
438
|
+
if (full) { try { path = talk.keepText(conversation, 'git-remote-refused.txt', full); } catch { path = null; } }
|
|
439
|
+
if (await wakeups.say(conversation, path ? `${line.replace(/\.$/, '')}; all it said: ${path}.` : line) === true) heard = true;
|
|
440
|
+
}
|
|
436
441
|
return heard;
|
|
437
442
|
};
|
|
438
443
|
/* What happened to a repository is said in the chat of the conversations it is attached to (talk.mjs). */
|
package/server/talk.mjs
CHANGED
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
*/
|
|
61
61
|
import { posix, join } from 'node:path';
|
|
62
62
|
import { randomUUID, createHash } from 'node:crypto';
|
|
63
|
-
import { mkdirSync, lstatSync, rmSync, readFileSync } from 'node:fs';
|
|
63
|
+
import { mkdirSync, lstatSync, rmSync, readFileSync, writeFileSync } from 'node:fs';
|
|
64
64
|
import { install, Parley, WAKE, reread, texts, fill, LANGUAGES, SHOWN_MAX, FILES_MAX } from 'clavarium-parley/host';
|
|
65
65
|
import { importFile } from './files.mjs';
|
|
66
66
|
import { KEYS } from 'clavarium-parley/ui';
|
|
@@ -494,6 +494,23 @@ export class Talk {
|
|
|
494
494
|
return { path: `${IN_MACHINE}/${FILES}/${id}/${kept.name}`, name: kept.name, size: kept.size };
|
|
495
495
|
}
|
|
496
496
|
|
|
497
|
+
/* A TEXT THIS SERVER GIVES THE TOOL TO READ (all a git remote said when it refused a sending): put
|
|
498
|
+
where the person's files go, in a folder of its own. Resolves with where the tool finds it, or
|
|
499
|
+
null when the chat is off or its folder is not as it should be. */
|
|
500
|
+
keepText(name, fileName, text) {
|
|
501
|
+
if (!this.of(name).on) return null;
|
|
502
|
+
const own = (path) => { const i = lstatSync(path, { throwIfNoEntry: false }); return i === undefined || (i.isDirectory() && !i.isSymbolicLink()); };
|
|
503
|
+
const dir = this.#dir(name);
|
|
504
|
+
if (!lstatSync(dir, { throwIfNoEntry: false }) || !own(dir) || !own(join(dir, FILES))) return null;
|
|
505
|
+
if (!lstatSync(join(dir, FILES), { throwIfNoEntry: false })) mkdirSync(join(dir, FILES));
|
|
506
|
+
if (!own(join(dir, FILES))) return null;
|
|
507
|
+
const id = randomUUID();
|
|
508
|
+
const file = String(fileName).replace(/[^A-Za-z0-9._-]/g, '-').slice(0, 80) || 'text.txt';
|
|
509
|
+
mkdirSync(join(dir, FILES, id));
|
|
510
|
+
writeFileSync(join(dir, FILES, id, file), String(text ?? ''), { flag: 'wx', mode: 0o644 });
|
|
511
|
+
return `${IN_MACHINE}/${FILES}/${id}/${file}`;
|
|
512
|
+
}
|
|
513
|
+
|
|
497
514
|
/* Whether a file (as the page opens it: "work:report.html") is one of
|
|
498
515
|
this chat: shown by the tool, cited in one of its messages (a path, a
|
|
499
516
|
picture placed in the text), or attached by the person. */
|