@zabaca/zbc 0.17.0 → 0.18.0
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/package.json +1 -1
- package/templates/apps/walgit/CONTEXT.md +4 -0
- package/templates/apps/walgit/README.md +48 -1
- package/templates/apps/walgit/e2e/README.md +44 -0
- package/templates/apps/walgit/e2e/load-report.ts +240 -0
- package/templates/apps/walgit/e2e/load.ts +449 -0
- package/templates/apps/walgit/package.json +2 -1
- package/templates/apps/walgit/shared/capabilities.ts +52 -0
- package/templates/apps/walgit/shared/container-env.ts +8 -0
- package/templates/apps/walgit/shared/landing.ts +131 -3
- package/templates/apps/walgit/shared/llms.ts +74 -5
- package/templates/apps/walgit/shared/operator.ts +86 -0
- package/templates/apps/walgit/shared/policy.ts +25 -0
- package/templates/apps/walgit/shared/protocol.ts +15 -0
- package/templates/apps/walgit/src/git-backend.ts +12 -0
- package/templates/apps/walgit/src/hook-main.ts +20 -1
- package/templates/apps/walgit/src/http.ts +130 -1
- package/templates/apps/walgit/src/instructions.ts +17 -1
- package/templates/apps/walgit/src/rate-limit.ts +264 -0
- package/templates/apps/walgit/src/server.ts +5 -0
- package/templates/apps/walgit/worker/index.ts +29 -2
|
@@ -50,7 +50,8 @@
|
|
|
50
50
|
*/
|
|
51
51
|
|
|
52
52
|
import type { Capabilities } from './capabilities'
|
|
53
|
-
import {
|
|
53
|
+
import { contactHref, type Operator } from './operator'
|
|
54
|
+
import { describeBytes, describeWindow } from './policy'
|
|
54
55
|
import { EVENTS_PATH, SIGNERS_REF } from './protocol'
|
|
55
56
|
import { CONTENT_SIGNAL } from './robots'
|
|
56
57
|
|
|
@@ -107,6 +108,34 @@ function thirdClaim(caps: Capabilities): string {
|
|
|
107
108
|
return ''
|
|
108
109
|
}
|
|
109
110
|
|
|
111
|
+
/**
|
|
112
|
+
* What one client may spend in a window (`src/rate-limit.ts`).
|
|
113
|
+
*
|
|
114
|
+
* Its own term rather than a share of the slot above, because it answers a
|
|
115
|
+
* different question: the size caps say how big a thing may be, this says how
|
|
116
|
+
* much of the host is yours. A visitor about to point an agent loop at this
|
|
117
|
+
* page should read it here rather than in the refusal — which is the same
|
|
118
|
+
* reason every other limit is on this page at all.
|
|
119
|
+
*
|
|
120
|
+
* Absent when the deployment bounds nothing per source, which is the default.
|
|
121
|
+
*/
|
|
122
|
+
function sourceLimitClaim(caps: Capabilities): string {
|
|
123
|
+
if (!caps.sourceLimited) return ''
|
|
124
|
+
const window = describeWindow(caps.rateWindowSeconds)
|
|
125
|
+
const parts: string[] = []
|
|
126
|
+
if (caps.maxNewReposPerSource !== null) {
|
|
127
|
+
parts.push(`${caps.maxNewReposPerSource} new repositories`)
|
|
128
|
+
}
|
|
129
|
+
if (caps.maxPushesPerSource !== null) parts.push(`${caps.maxPushesPerSource} pushes`)
|
|
130
|
+
if (caps.maxPushBytesPerSource !== null) {
|
|
131
|
+
parts.push(describeBytes(caps.maxPushBytesPerSource))
|
|
132
|
+
}
|
|
133
|
+
return claim(
|
|
134
|
+
'Shared',
|
|
135
|
+
`<b>${parts.join(', ')} per client per ${window}.</b> One host serves everybody here, so no single client may take all of it.`,
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
|
|
110
139
|
/** The permanence sentence, which turns on the same variable as the claim. */
|
|
111
140
|
function permanence(caps: Capabilities): string {
|
|
112
141
|
return caps.retentionHours === null
|
|
@@ -478,6 +507,7 @@ function claims(caps: Capabilities): string {
|
|
|
478
507
|
privateClaim(caps),
|
|
479
508
|
proposalsClaim(caps),
|
|
480
509
|
thirdClaim(caps),
|
|
510
|
+
sourceLimitClaim(caps),
|
|
481
511
|
signingClaim(caps),
|
|
482
512
|
// Unconditional, unlike every term above it: nothing in `/robots.txt` is
|
|
483
513
|
// read from a flag. It is the one claim on this page addressed to the
|
|
@@ -617,6 +647,81 @@ function wireScript(): string {
|
|
|
617
647
|
return `${WIRE_CLIENT}`
|
|
618
648
|
}
|
|
619
649
|
|
|
650
|
+
/**
|
|
651
|
+
* Everything on this page is a constant of the template or a number read from
|
|
652
|
+
* the environment — except the two values below, which are free text somebody
|
|
653
|
+
* put in a deployment variable and which land in markup. So they are escaped
|
|
654
|
+
* here, once, at the only place they enter the document.
|
|
655
|
+
*/
|
|
656
|
+
function escapeHtml(raw: string): string {
|
|
657
|
+
return raw
|
|
658
|
+
.replaceAll('&', '&')
|
|
659
|
+
.replaceAll('<', '<')
|
|
660
|
+
.replaceAll('>', '>')
|
|
661
|
+
.replaceAll('"', '"')
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* Who runs this, and what happens to what you push.
|
|
666
|
+
*
|
|
667
|
+
* The one block on the page addressed to somebody who is not about to push:
|
|
668
|
+
* an aggregator asks who is answerable in the first ten minutes, and the page
|
|
669
|
+
* that could not answer sent them looking for a WHOIS record.
|
|
670
|
+
*
|
|
671
|
+
* The expiry promise stands here as well as in `The rules.` on purpose, and it
|
|
672
|
+
* is not the page saying one thing twice — the terms tell a visitor what the
|
|
673
|
+
* host will do with their push, and this tells somebody else what it already
|
|
674
|
+
* did with a stranger's. On a deployment that collects, "it expires in 24
|
|
675
|
+
* hours" is most of the answer to a takedown, so the two facts are read
|
|
676
|
+
* together or not at all. It is rendered from `retentionHours` like every
|
|
677
|
+
* other statement of the window, so it cannot outlive the config either.
|
|
678
|
+
*
|
|
679
|
+
* Absent whole where nothing is configured, for the reason `operatorFrom`
|
|
680
|
+
* returns `null` there: a page that printed a heading with nobody under it
|
|
681
|
+
* would be worse than one that never claimed to have an operator.
|
|
682
|
+
*/
|
|
683
|
+
function operatorSection(caps: Capabilities, operator: Operator | null): string {
|
|
684
|
+
if (operator === null) return ''
|
|
685
|
+
|
|
686
|
+
const rows: string[] = []
|
|
687
|
+
if (operator.name !== null) {
|
|
688
|
+
rows.push(claim('Operator', `<b>${escapeHtml(operator.name)}</b> runs this deployment.`))
|
|
689
|
+
}
|
|
690
|
+
if (operator.contact !== null) {
|
|
691
|
+
const text = escapeHtml(operator.contact)
|
|
692
|
+
const href = contactHref(operator.contact)
|
|
693
|
+
rows.push(
|
|
694
|
+
claim(
|
|
695
|
+
'Contact',
|
|
696
|
+
`<b>${href === null ? text : `<a href="${escapeHtml(href)}">${text}</a>`}</b> — takedowns, abuse and anything else about this host.`,
|
|
697
|
+
),
|
|
698
|
+
)
|
|
699
|
+
}
|
|
700
|
+
if (caps.retentionHours !== null) {
|
|
701
|
+
const window = describeHours(caps.retentionHours)
|
|
702
|
+
rows.push(
|
|
703
|
+
claim(
|
|
704
|
+
'Expiry',
|
|
705
|
+
`<b>A repository is collected ${window} after its last push</b>, whether or not anybody asks. Nothing here is archived.`,
|
|
706
|
+
),
|
|
707
|
+
)
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
// `operatorFrom` cannot return an `Operator` with neither half, so this is
|
|
711
|
+
// unreachable from the Worker — but a heading with nothing under it is the
|
|
712
|
+
// one output this block must never produce, and the guard costs a line.
|
|
713
|
+
if (rows.length === 0) return ''
|
|
714
|
+
|
|
715
|
+
return `
|
|
716
|
+
<section>
|
|
717
|
+
<h2>Who runs this.</h2>
|
|
718
|
+
<ul class="claims">
|
|
719
|
+
${rows.join('\n')}
|
|
720
|
+
</ul>
|
|
721
|
+
</section>
|
|
722
|
+
`
|
|
723
|
+
}
|
|
724
|
+
|
|
620
725
|
/**
|
|
621
726
|
* Every substitution passes a FUNCTION, never the string itself.
|
|
622
727
|
*
|
|
@@ -630,7 +735,18 @@ function wireScript(): string {
|
|
|
630
735
|
* runs. A function replacer is not interpreted at all, so the question stops
|
|
631
736
|
* being asked.
|
|
632
737
|
*/
|
|
633
|
-
export function renderLanding(
|
|
738
|
+
export function renderLanding(
|
|
739
|
+
host: string,
|
|
740
|
+
caps: Capabilities,
|
|
741
|
+
/**
|
|
742
|
+
* Who runs this deployment (`shared/operator.ts`), beside the capabilities
|
|
743
|
+
* rather than folded into them: nothing branches on it and the push path
|
|
744
|
+
* never sees it. Optional and `null` by default — a deployment that names
|
|
745
|
+
* nobody renders the page it renders today, which is also what every test
|
|
746
|
+
* fixture that is not about the operator wants to say.
|
|
747
|
+
*/
|
|
748
|
+
operator: Operator | null = null,
|
|
749
|
+
): string {
|
|
634
750
|
return PAGE.replaceAll('{{HOST}}', () => host)
|
|
635
751
|
.replace('{{META_DESCRIPTION}}', () => metaDescription(caps))
|
|
636
752
|
.replace('{{HERO_UNDER}}', () => heroUnder(caps))
|
|
@@ -641,6 +757,7 @@ export function renderLanding(host: string, caps: Capabilities): string {
|
|
|
641
757
|
.replace('{{OWNERSHIP}}', () => ownershipSection(host, caps))
|
|
642
758
|
.replace('{{WIRE_SCRIPT}}', () => (caps.events ? wireScript() : ''))
|
|
643
759
|
.replace('{{PERMANENCE}}', () => permanence(caps))
|
|
760
|
+
.replace('{{OPERATOR}}', () => operatorSection(caps, operator))
|
|
644
761
|
}
|
|
645
762
|
|
|
646
763
|
const WIRE_CLIENT = `
|
|
@@ -794,6 +911,14 @@ const PAGE = `<!doctype html>
|
|
|
794
911
|
margin: 0 0 2.75rem;
|
|
795
912
|
}
|
|
796
913
|
.lede em { font-style: normal; color: var(--copper); }
|
|
914
|
+
/* The second half of the pitch — what the service is FOR, as opposed to what
|
|
915
|
+
it does — set a step down so the two read as one thought rather than as
|
|
916
|
+
two competing opening lines. */
|
|
917
|
+
.lede-2 {
|
|
918
|
+
font-size: clamp(1.02rem, 2.3vw, 1.2rem);
|
|
919
|
+
color: var(--muted);
|
|
920
|
+
max-width: 44ch;
|
|
921
|
+
}
|
|
797
922
|
|
|
798
923
|
/* ── the command, which is the CTA ────────────────────── */
|
|
799
924
|
|
|
@@ -1174,12 +1299,14 @@ const PAGE = `<!doctype html>
|
|
|
1174
1299
|
<div class="wrap">
|
|
1175
1300
|
|
|
1176
1301
|
<main id="start">
|
|
1177
|
-
<span class="badge">
|
|
1302
|
+
<span class="badge">agentgit — open source, run your own</span>
|
|
1178
1303
|
|
|
1179
1304
|
<h1>Git for AI agents<span class="dot">.</span></h1>
|
|
1180
1305
|
|
|
1181
1306
|
<p class="lede">Your agent writes code all day and has nowhere of its own to put it. <em>Push to a name and the repository exists</em> — no account, no key, no API besides git itself.</p>
|
|
1182
1307
|
|
|
1308
|
+
<p class="lede lede-2">Scratch repositories, and the handoff between two agents: <em>handing work to another agent is the URL</em>, and there is nothing else to send.</p>
|
|
1309
|
+
|
|
1183
1310
|
<div class="cta">
|
|
1184
1311
|
<label class="repo-field" for="repo">
|
|
1185
1312
|
<span>Name it</span>
|
|
@@ -1219,6 +1346,7 @@ const PAGE = `<!doctype html>
|
|
|
1219
1346
|
</ul>
|
|
1220
1347
|
<p class="caveat">{{PERMANENCE}} Not a place for anything you cannot lose.</p>
|
|
1221
1348
|
</section>
|
|
1349
|
+
{{OPERATOR}}
|
|
1222
1350
|
</main>
|
|
1223
1351
|
|
|
1224
1352
|
<footer>
|
|
@@ -22,8 +22,9 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
import type { Capabilities } from './capabilities'
|
|
25
|
+
import type { Operator } from './operator'
|
|
25
26
|
import { MAX_REFS_PER_ENTRY, MAX_WATCH_ENTRIES } from './events'
|
|
26
|
-
import { describeBytes } from './policy'
|
|
27
|
+
import { describeBytes, describeWindow } from './policy'
|
|
27
28
|
import { CONTENT_SIGNAL } from './robots'
|
|
28
29
|
import {
|
|
29
30
|
CHALLENGE_PATH,
|
|
@@ -41,7 +42,17 @@ export function wantsLlms(method: string, pathname: string): boolean {
|
|
|
41
42
|
|
|
42
43
|
const hours = (n: number) => (n === 1 ? '1 hour' : `${n} hours`)
|
|
43
44
|
|
|
44
|
-
export function renderLlms(
|
|
45
|
+
export function renderLlms(
|
|
46
|
+
host: string,
|
|
47
|
+
caps: Capabilities,
|
|
48
|
+
/**
|
|
49
|
+
* Who runs this deployment (`shared/operator.ts`), passed beside the
|
|
50
|
+
* capabilities for the reason the host is: nothing here branches on it and
|
|
51
|
+
* the push path never sees it. `null` — nobody named — renders the document
|
|
52
|
+
* this host rendered before there was anywhere to name one.
|
|
53
|
+
*/
|
|
54
|
+
operator: Operator | null = null,
|
|
55
|
+
): string {
|
|
45
56
|
const ws = `wss://${host}${EVENTS_PATH}`
|
|
46
57
|
|
|
47
58
|
const limits: string[] = []
|
|
@@ -106,6 +117,33 @@ export function renderLlms(host: string, caps: Capabilities): string {
|
|
|
106
117
|
if (caps.maxRepoBytes !== null) {
|
|
107
118
|
limits.push(`- **One repository may not exceed ${describeBytes(caps.maxRepoBytes)}** in total.`)
|
|
108
119
|
}
|
|
120
|
+
// What one client may spend, as opposed to how big one thing may be
|
|
121
|
+
// (`src/rate-limit.ts`). Stated here because the reader of this document is
|
|
122
|
+
// exactly the client the limit is about: an agent loop reads it once and then
|
|
123
|
+
// pushes in a pattern it has already decided on, and a limit it learns from a
|
|
124
|
+
// refusal is one it learns halfway through that pattern. Each half is stated
|
|
125
|
+
// only where it is enforced, like every bullet above.
|
|
126
|
+
if (caps.sourceLimited) {
|
|
127
|
+
const window = describeWindow(caps.rateWindowSeconds)
|
|
128
|
+
if (caps.maxNewReposPerSource !== null) {
|
|
129
|
+
limits.push(
|
|
130
|
+
`- **You may create ${caps.maxNewReposPerSource} new repositories per client per ${window}.** Pushing to a name you already created does not count against it.`,
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
if (caps.maxPushesPerSource !== null) {
|
|
134
|
+
limits.push(
|
|
135
|
+
`- **You may make ${caps.maxPushesPerSource} pushes per client per ${window}.** Commit locally and push once rather than pushing every commit.`,
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
if (caps.maxPushBytesPerSource !== null) {
|
|
139
|
+
limits.push(
|
|
140
|
+
`- **You may push ${describeBytes(caps.maxPushBytesPerSource)} per client per ${window}.**`,
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
limits.push(
|
|
144
|
+
`- Each of those is refused in \`pre-receive\`, by a message naming the limit — not a transport failure. Waiting out the ${window} is the remedy; retrying immediately is not.`,
|
|
145
|
+
)
|
|
146
|
+
}
|
|
109
147
|
|
|
110
148
|
/**
|
|
111
149
|
* The answer to the question the bullet above raises and does not settle: a
|
|
@@ -569,6 +607,36 @@ commit are refused before anything is stored.
|
|
|
569
607
|
`
|
|
570
608
|
: ''
|
|
571
609
|
|
|
610
|
+
/**
|
|
611
|
+
* Who runs this, in the same place and the same order the page states it
|
|
612
|
+
* (`operatorSection`, `shared/landing.ts`): who, then where to write, then
|
|
613
|
+
* what expires on its own.
|
|
614
|
+
*
|
|
615
|
+
* It is the one fact in this document that is not a capability, and an agent
|
|
616
|
+
* asking who is answerable for a host it is about to push somebody else's
|
|
617
|
+
* work to has nowhere else to read it — the page is HTML and this is the
|
|
618
|
+
* document a harness fetches. Absent whole where nothing is configured, like
|
|
619
|
+
* every other section here.
|
|
620
|
+
*/
|
|
621
|
+
const whoRuns =
|
|
622
|
+
operator === null
|
|
623
|
+
? ''
|
|
624
|
+
: `
|
|
625
|
+
## Who runs this
|
|
626
|
+
|
|
627
|
+
${[
|
|
628
|
+
operator.name === null ? null : `- **Operator.** ${operator.name} runs this deployment.`,
|
|
629
|
+
operator.contact === null
|
|
630
|
+
? null
|
|
631
|
+
: `- **Contact.** ${operator.contact} — takedowns, abuse and anything else about this host.`,
|
|
632
|
+
caps.retentionHours === null
|
|
633
|
+
? null
|
|
634
|
+
: `- **Expiry.** A repository is collected ${hours(caps.retentionHours)} after its last push, whether or not anybody asks. Nothing here is archived.`,
|
|
635
|
+
]
|
|
636
|
+
.filter((line): line is string => line !== null)
|
|
637
|
+
.join('\n')}
|
|
638
|
+
`
|
|
639
|
+
|
|
572
640
|
const events = caps.events
|
|
573
641
|
? `
|
|
574
642
|
## Know when a ref moves, without asking
|
|
@@ -668,7 +736,9 @@ the worse failure. Everything else on this host has a public stream.`
|
|
|
668
736
|
|
|
669
737
|
return `# ${host}
|
|
670
738
|
|
|
671
|
-
|
|
739
|
+
agentgit — a git host for AI agents. Push to a name and the repository exists. There is no account to create, no repository to create first, and no API besides git itself.
|
|
740
|
+
|
|
741
|
+
Scratch repositories, and the handoff between two agents: handing work to another agent is the URL, and there is nothing else to send.
|
|
672
742
|
|
|
673
743
|
Smart-HTTP is the only transport.
|
|
674
744
|
|
|
@@ -725,8 +795,7 @@ the body names the helper, and git prints none of it. Fix it with the one config
|
|
|
725
795
|
line from *Keep a name private*, above, and push again.
|
|
726
796
|
`
|
|
727
797
|
: ''
|
|
728
|
-
}
|
|
729
|
-
|
|
798
|
+
}${whoRuns}
|
|
730
799
|
## What this is not
|
|
731
800
|
|
|
732
801
|
Not a forge: no pull requests, no code review, no CI, no issues.${
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who runs this deployment, and how to reach them.
|
|
3
|
+
*
|
|
4
|
+
* Deliberately NOT a capability (`shared/capabilities.ts`), and the distinction
|
|
5
|
+
* is the same one that keeps the host out of that type: a capability is
|
|
6
|
+
* something the push path enforces and the documents describe, derived from the
|
|
7
|
+
* variables the container is told about. An operator is nobody's capability —
|
|
8
|
+
* it is who is answerable for one — and no code path branches on it. So it is
|
|
9
|
+
* derived here, passed beside the capabilities and the host, and read by the
|
|
10
|
+
* two documents that state it.
|
|
11
|
+
*
|
|
12
|
+
* It is also EDGE-ONLY, and that is why neither variable appears in
|
|
13
|
+
* `CONTAINER_ENV` (`shared/container-env.ts`). Nothing the container serves
|
|
14
|
+
* names an operator, and adding a name there would cost a container restart on
|
|
15
|
+
* every copy edit — `reconcileEnv` replaces the container whenever the
|
|
16
|
+
* forwarded environment's fingerprint changes.
|
|
17
|
+
*
|
|
18
|
+
* Both halves are optional and either may stand alone: a host run by somebody
|
|
19
|
+
* who publishes no address still says who runs it, and an address with no name
|
|
20
|
+
* behind it is still somewhere to send a takedown. What must never happen is a
|
|
21
|
+
* deployment that configured neither printing a placeholder — mail to a name
|
|
22
|
+
* nobody reads is worse than the page admitting there is nobody to write to —
|
|
23
|
+
* which is why nothing configured derives to `null` and the block leaves.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/** The variables an operator is read from, and only those. */
|
|
27
|
+
export type OperatorVar = 'WALGIT_OPERATOR' | 'WALGIT_CONTACT'
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* An environment named exactly by those variables.
|
|
31
|
+
*
|
|
32
|
+
* What a caller writing a LITERAL should annotate it with — a misspelled name
|
|
33
|
+
* is then a compile error rather than a value quietly read as unset. That is
|
|
34
|
+
* what every fixture in this package is typed as, following `CapabilityEnv`.
|
|
35
|
+
*/
|
|
36
|
+
export type OperatorEnv = Partial<Record<OperatorVar, string>>
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Who runs this deployment, with absence spelled `null` on each half rather
|
|
40
|
+
* than as an omitted key — the same rule `Capabilities` follows, for the same
|
|
41
|
+
* reason: an optional field defaults to "off" at a construction site that
|
|
42
|
+
* forgot it.
|
|
43
|
+
*/
|
|
44
|
+
export type Operator = {
|
|
45
|
+
/** Who is answerable for this host. */
|
|
46
|
+
name: string | null
|
|
47
|
+
/** Where to write about it — an email address, a URL, or free text. */
|
|
48
|
+
contact: string | null
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Read an environment into who runs it, or `null` for "nobody is named here".
|
|
53
|
+
*
|
|
54
|
+
* Blank collapses to unset, the reading `seedValue` and `containerEnv` already
|
|
55
|
+
* make of a blank variable: a value cleared to an empty string is a line
|
|
56
|
+
* removed from the page, not a line with nothing in it.
|
|
57
|
+
*/
|
|
58
|
+
export function operatorFrom(
|
|
59
|
+
env: OperatorEnv | Record<string, string | undefined>,
|
|
60
|
+
): Operator | null {
|
|
61
|
+
const name = trimmed(env.WALGIT_OPERATOR)
|
|
62
|
+
const contact = trimmed(env.WALGIT_CONTACT)
|
|
63
|
+
if (name === null && contact === null) return null
|
|
64
|
+
return { name, contact }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const trimmed = (raw: string | undefined): string | null => {
|
|
68
|
+
if (raw === undefined) return null
|
|
69
|
+
const value = raw.trim()
|
|
70
|
+
return value === '' ? null : value
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Is this contact something a reader can click, and what does it become?
|
|
75
|
+
*
|
|
76
|
+
* Only the two shapes that are unambiguous — an address and an `https`/`http`
|
|
77
|
+
* URL — and anything else stays text. A contact is operator-supplied free text
|
|
78
|
+
* (a Matrix handle, a postal address, "open an issue on GitHub"), and guessing
|
|
79
|
+
* a scheme for it would produce a link that goes nowhere, which is worse than
|
|
80
|
+
* a line somebody has to copy.
|
|
81
|
+
*/
|
|
82
|
+
export function contactHref(contact: string): string | null {
|
|
83
|
+
if (/^https?:\/\/\S+$/.test(contact)) return contact
|
|
84
|
+
if (/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(contact)) return `mailto:${contact}`
|
|
85
|
+
return null
|
|
86
|
+
}
|
|
@@ -75,3 +75,28 @@ export function seedValue(raw: string | undefined): string | null {
|
|
|
75
75
|
const seed = raw.trim()
|
|
76
76
|
return seed === '' ? null : seed
|
|
77
77
|
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* A window in the words both halves state it in.
|
|
81
|
+
*
|
|
82
|
+
* Here for the reason `describeBytes` is: the refusal a push reads
|
|
83
|
+
* (`src/rate-limit.ts`) and the limit the two documents print are the same
|
|
84
|
+
* window, and two spellings of "per hour" would look like two different rules.
|
|
85
|
+
*
|
|
86
|
+
* Whole hours and whole minutes are named as such, because that is how an
|
|
87
|
+
* operator configured it and how a client waits it out. Anything else is stated
|
|
88
|
+
* in seconds rather than rounded into a number somebody would then wait the
|
|
89
|
+
* wrong amount of time on.
|
|
90
|
+
*/
|
|
91
|
+
export function describeWindow(seconds: number): string {
|
|
92
|
+
const whole = Math.round(seconds)
|
|
93
|
+
if (whole % 3600 === 0) {
|
|
94
|
+
const hours = whole / 3600
|
|
95
|
+
return hours === 1 ? 'hour' : `${hours} hours`
|
|
96
|
+
}
|
|
97
|
+
if (whole % 60 === 0) {
|
|
98
|
+
const minutes = whole / 60
|
|
99
|
+
return minutes === 1 ? 'minute' : `${minutes} minutes`
|
|
100
|
+
}
|
|
101
|
+
return `${whole} seconds`
|
|
102
|
+
}
|
|
@@ -52,6 +52,21 @@ export const COLD_HEADER = 'x-walgit-cold'
|
|
|
52
52
|
*/
|
|
53
53
|
export const INTERNAL_HEADER = 'x-walgit-internal'
|
|
54
54
|
|
|
55
|
+
/**
|
|
56
|
+
* The environment variable a per-request refusal travels down in — from the
|
|
57
|
+
* smart-HTTP handler, through `git http-backend`, to `pre-receive`, which
|
|
58
|
+
* prints it and exits non-zero (`src/rate-limit.ts`).
|
|
59
|
+
*
|
|
60
|
+
* A contract between three files, so it is named once here beside the headers
|
|
61
|
+
* rather than spelled out in each of them. It is per-REQUEST and never part of
|
|
62
|
+
* the container's own environment: it is set by the handler that judged this
|
|
63
|
+
* push, and `src/git-backend.ts` refuses to carry a process-level one, which
|
|
64
|
+
* would refuse every push on the instance with a message written for one
|
|
65
|
+
* client. It reaches the hook as a variable rather than a header because a hook
|
|
66
|
+
* is a process git spawns three levels down, where a request does not reach.
|
|
67
|
+
*/
|
|
68
|
+
export const REFUSE_ENV = 'WALGIT_REFUSE'
|
|
69
|
+
|
|
55
70
|
/** Stripped before the response leaves the Worker — internal, not protocol. */
|
|
56
71
|
export const INTERNAL_HEADERS = [SERVED_HEADER, REJECT_HEADER, COLD_HEADER] as const
|
|
57
72
|
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
import * as path from 'node:path'
|
|
14
14
|
|
|
15
|
+
import { REFUSE_ENV } from '../shared/protocol'
|
|
15
16
|
import type { BackendRequest } from './http'
|
|
16
17
|
|
|
17
18
|
export async function runGitHttpBackend(req: BackendRequest): Promise<Response> {
|
|
@@ -45,9 +46,20 @@ export async function runGitHttpBackend(req: BackendRequest): Promise<Response>
|
|
|
45
46
|
// chain can be broken. A hook that cannot see the store configuration
|
|
46
47
|
// refuses the push — correct, but a confusing way to discover a typo here.
|
|
47
48
|
for (const [key, value] of Object.entries(process.env)) {
|
|
49
|
+
// `WALGIT_REFUSE` is per-request and never the process's (see below). One
|
|
50
|
+
// left in the container's own environment would refuse EVERY push on this
|
|
51
|
+
// instance, with a message written for one client, so the process copy is
|
|
52
|
+
// not a source for it.
|
|
53
|
+
if (key === REFUSE_ENV) continue
|
|
48
54
|
if (key.startsWith('WALGIT_') && value !== undefined) env[key] = value
|
|
49
55
|
}
|
|
50
56
|
|
|
57
|
+
// What the handler decided about THIS request, over what the process was
|
|
58
|
+
// started with — `WALGIT_REFUSE`, the per-source refusal `pre-receive` speaks
|
|
59
|
+
// (`src/rate-limit.ts`). Last, so a per-request verdict is never shadowed by
|
|
60
|
+
// a variable of the same name in the container's own environment.
|
|
61
|
+
Object.assign(env, req.env ?? {})
|
|
62
|
+
|
|
51
63
|
const child = Bun.spawn(['git', 'http-backend'], {
|
|
52
64
|
env,
|
|
53
65
|
stdin: request.body ?? 'ignore',
|
|
@@ -18,7 +18,7 @@ import * as fs from 'node:fs'
|
|
|
18
18
|
import * as path from 'node:path'
|
|
19
19
|
|
|
20
20
|
import { capabilitiesFrom } from '../shared/capabilities'
|
|
21
|
-
import { ZERO_OID } from '../shared/protocol'
|
|
21
|
+
import { REFUSE_ENV, ZERO_OID } from '../shared/protocol'
|
|
22
22
|
import { announceConfigFromEnv } from './announce'
|
|
23
23
|
import { appendOnlyEnabled, checkAppendOnly } from './append-only'
|
|
24
24
|
import { configuredThreshold, isCompactionDue } from './compact'
|
|
@@ -83,6 +83,25 @@ async function main(): Promise<number> {
|
|
|
83
83
|
const stdin = await Bun.stdin.text()
|
|
84
84
|
|
|
85
85
|
if (hook === 'pre-receive') {
|
|
86
|
+
// A refusal the front door already reached, spoken here (`src/rate-limit.ts`).
|
|
87
|
+
//
|
|
88
|
+
// FIRST, above every verdict below it, because it is the only one not about
|
|
89
|
+
// this push's contents: the per-source window was judged before a byte of
|
|
90
|
+
// the pack was read, and re-deciding anything under a verdict that has
|
|
91
|
+
// already been taken would be work spent on a push that is not happening.
|
|
92
|
+
//
|
|
93
|
+
// It arrives as an environment variable rather than as a header because
|
|
94
|
+
// this is a process git spawned three levels down, where a request does not
|
|
95
|
+
// reach — and it is spoken HERE rather than answered as an HTTP status
|
|
96
|
+
// because git reports a status on this route as `RPC failed; HTTP …`, which
|
|
97
|
+
// reads as a transport fault and is retried. On stderr, so git puts it on
|
|
98
|
+
// the sideband as `remote:` lines, exactly as a size cap's refusal arrives.
|
|
99
|
+
const handed = (process.env[REFUSE_ENV] ?? '').trim()
|
|
100
|
+
if (handed !== '') {
|
|
101
|
+
process.stderr.write(`${handed}\n`)
|
|
102
|
+
return 1
|
|
103
|
+
}
|
|
104
|
+
|
|
86
105
|
// Who signed this push, settled here and handed down. It is read in this
|
|
87
106
|
// hook because this is the only one git shows the certificate to — the
|
|
88
107
|
// blob lives in the push's quarantine and is gone by the time the refs
|