clavarium 0.2.143-next.1 → 0.2.144-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 +25 -0
- package/server/gitkeeper.mjs +2 -0
- package/server/gitpush.mjs +11 -2
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.144-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.144-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,31 @@ 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_LINES = 20;
|
|
90
|
+
export const REMOTE_CHARS = 1500;
|
|
91
|
+
export function remoteSaid(stderr) {
|
|
92
|
+
const lines = String(stderr ?? '').split(/\r?\n|\r/)
|
|
93
|
+
.filter((l) => /^remote:/.test(l))
|
|
94
|
+
.map((l) => l.replace(/^remote:\s?/, '').replace(/\x1b\[[0-9;?]*[ -\/]*[@-~]/g, '').replace(/[\x00-\x1f\x7f]/g, '').trimEnd())
|
|
95
|
+
.filter((l) => l.trim() && !/^(Resolving deltas|Counting objects|Compressing objects|Processing changes|Total \d|Enumerating objects|Writing objects)\b/.test(l.trim()));
|
|
96
|
+
/* A very talkative hook: the lines that say what is wrong first (error, refused, must…), in their
|
|
97
|
+
order, then the end of what it said, up to REMOTE_LINES; "[N lines left out]" where lines went. */
|
|
98
|
+
let kept = lines;
|
|
99
|
+
if (lines.length > REMOTE_LINES) {
|
|
100
|
+
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));
|
|
101
|
+
for (let i = lines.length - 1; telling.size < REMOTE_LINES && i >= 0; i -= 1) telling.add(i);
|
|
102
|
+
const picked = [...telling].sort((a, b) => a - b);
|
|
103
|
+
kept = [];
|
|
104
|
+
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]); });
|
|
105
|
+
}
|
|
106
|
+
let text = kept.join('\n');
|
|
107
|
+
if (text.length > REMOTE_CHARS) text = `…${text.slice(-REMOTE_CHARS)}`;
|
|
108
|
+
return text;
|
|
109
|
+
}
|
|
110
|
+
|
|
86
111
|
/* An ed25519 key pair in the formats OpenSSH reads, made with Node's own
|
|
87
112
|
crypto: no program is run and nothing touches the disk. The private key is
|
|
88
113
|
the unencrypted "openssh-key-v1" container (it is encrypted by the vault). */
|
package/server/gitkeeper.mjs
CHANGED
|
@@ -608,6 +608,8 @@ export class GitKeeper {
|
|
|
608
608
|
if (['look', 'confirm', 'busy'].includes(error.kind)) return;
|
|
609
609
|
this.#log(name, { ok: false, branch: branch ?? null, head: head ?? null, what: error.message });
|
|
610
610
|
if (error.alert) this.#tell(`${name}: sending needs a look`, error.message);
|
|
611
|
+
/* Refused by the remote, sent by hand: what it said is the agent's to act on too. */
|
|
612
|
+
if (error.kind === 'refused' && error.ai) this.#toAgent(name, error.ai);
|
|
611
613
|
if (error.kind === 'unknown-unreachable' && branch) this.#patch(name, { blocked: { ...(this.#record(name).blocked ?? {}), [branch]: { head, at: this.#now().toISOString() } } });
|
|
612
614
|
}
|
|
613
615
|
|
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 } 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,16 @@ 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
|
+
throw new GitFailure(502, 'refused', `The remote refused: ${why}${said}`, { detail: hooks, ai: `the remote refused the sending to ${target}: ${why}${said}` });
|
|
665
|
+
}
|
|
657
666
|
/* (5) The pushed commits enter the reference only as the remote's history. */
|
|
658
667
|
const after = await this.#refreshLocked(r, { branch: target, head });
|
|
659
668
|
return sent(after.ok ? {} : { refreshed: false, note: 'Sent; the reference was not refreshed.' });
|