@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.
@@ -22,6 +22,7 @@ import {
22
22
  READ_CHALLENGE_SCHEME,
23
23
  READ_VERDICT_PATH,
24
24
  REFS_PATH,
25
+ REFUSE_ENV,
25
26
  REJECT_HEADER,
26
27
  SERVED_HEADER,
27
28
  SMART_HTTP,
@@ -31,6 +32,7 @@ import { emptyReadResponse } from './empty-read'
31
32
  import { renderInstructions } from './instructions'
32
33
  import { acceptedNonces, readAllowed, readChallengeNonce, renderReadChallenge } from './private'
33
34
  import type { ProposalListing } from './proposals'
35
+ import { countsNewRepos, createSourceLimiter, rateLimitsEnforced, rateLimitsOf } from './rate-limit'
34
36
  import type { ResolvedRepo } from './repo'
35
37
  import { resolveRepo } from './repo'
36
38
  import type { Claim, Provenance } from './wal-index'
@@ -40,6 +42,16 @@ export type BackendRequest = {
40
42
  /** The path git http-backend sees, e.g. `/alpha.git/info/refs`. */
41
43
  pathInfo: string
42
44
  request: Request
45
+ /**
46
+ * Extra environment for THIS request's backend, over the process's own.
47
+ *
48
+ * One thing travels this way today: `WALGIT_REFUSE`, the per-source refusal
49
+ * `pre-receive` speaks (`src/rate-limit.ts`). It is a per-request channel
50
+ * because the verdict is per-request — the handler is the only layer that
51
+ * sees the source the edge attributed the push to, and a hook is a process
52
+ * git spawns three levels down, where a header does not reach.
53
+ */
54
+ env?: Record<string, string>
43
55
  }
44
56
 
45
57
  export type HttpHandlerDeps = {
@@ -140,6 +152,11 @@ export type HttpHandlerDeps = {
140
152
  * a gate is the failure this shape makes unrepresentable.
141
153
  */
142
154
  privateReads?: PrivateReads
155
+ /**
156
+ * The clock the per-source window is measured on, injectable so a test can
157
+ * stand still inside one or step over its edge (`src/rate-limit.ts`).
158
+ */
159
+ now?: () => number
143
160
  }
144
161
 
145
162
  /** Everything the Private gate needs, present or absent as a whole. */
@@ -268,6 +285,41 @@ export function createHttpHandler(deps: HttpHandlerDeps): (req: Request) => Prom
268
285
  function createRouter(deps: HttpHandlerDeps): (req: Request) => Promise<Response> {
269
286
  const priv = deps.privateReads
270
287
 
288
+ /**
289
+ * What one source may spend in a window, or `null` on the deployments that
290
+ * bound nothing — which is every deployment until an operator sets a limit.
291
+ *
292
+ * Built ONCE per handler rather than per request: the window is the state,
293
+ * and a limiter constructed per request would remember nothing and refuse
294
+ * nobody. The capabilities are the ones this instance advertises, so the page
295
+ * cannot state a rate limit the push path does not hold.
296
+ */
297
+ const rateLimits = rateLimitsOf(deps.capabilities ?? ADVERTISES_NOTHING)
298
+ const limiter = rateLimitsEnforced(rateLimits) ? createSourceLimiter(rateLimits, deps.now) : null
299
+
300
+ /**
301
+ * Does this push bring a name into existence?
302
+ *
303
+ * From the INDEX, for the reason every other question here is: the disk is a
304
+ * cache and a cold node's empty directory is not evidence. A repository that
305
+ * holds no ref is a name being created, which is the same reading
306
+ * `emptyReadResponse` makes one branch below — pushing is what brings a name
307
+ * into existence, so "holds a ref" is the question and "the directory exists"
308
+ * is not.
309
+ *
310
+ * Asked only where a limit needs the answer, and an Index that cannot be read
311
+ * answers `false`: a store outage must not invent a creation refusal for a
312
+ * repository that has existed for a month.
313
+ */
314
+ async function creatingName(repoId: string): Promise<boolean> {
315
+ if (!countsNewRepos(rateLimits) || !deps.readRefs) return false
316
+ try {
317
+ return Object.keys(await deps.readRefs(repoId)).length === 0
318
+ } catch {
319
+ return false
320
+ }
321
+ }
322
+
271
323
  /**
272
324
  * Refuse this read, or don't — the Private gate, for all three reads
273
325
  * (docs/adr/0013).
@@ -590,6 +642,46 @@ function createRouter(deps: HttpHandlerDeps): (req: Request) => Promise<Response
590
642
  }
591
643
  }
592
644
 
645
+ // What this source has spent in the window, and whether this push fits in
646
+ // what is left (`src/rate-limit.ts`).
647
+ //
648
+ // Only the POST, because only the POST is a push: the advertisement that
649
+ // precedes it hands over nothing and charging it would make every push cost
650
+ // two. Only here, because this is the one layer that sees both the source
651
+ // the edge attributed the request to and the repository it names.
652
+ //
653
+ // The verdict does not become a status code. git reports a 4xx on this
654
+ // route as `RPC failed; HTTP …`, which reads as a transport fault and gets
655
+ // retried — the exact failure the size caps were written to stop being. So
656
+ // the refusal rides down to `pre-receive`, which speaks it as a reject line
657
+ // before a single object is stored.
658
+ let refusal: string | undefined
659
+ if (limiter && route[2] === 'git-receive-pack' && request.method === 'POST') {
660
+ const source = sourceOf(request)
661
+ // Unattributable: a request that reached the container without passing
662
+ // the edge, or a local deployment. Pooling everything walgit cannot name
663
+ // into one bucket would let the first such request throttle every other.
664
+ if (source) {
665
+ let repoId: string | null = null
666
+ try {
667
+ repoId = resolveRepo(deps.reposDir, route[1]!).repoId
668
+ } catch {
669
+ // A name walgit would not serve is a 404 below; nothing is charged
670
+ // for a push that is about to be refused for a different reason.
671
+ repoId = null
672
+ }
673
+ if (repoId !== null) {
674
+ const verdict = limiter.admit({
675
+ source,
676
+ repoId,
677
+ creating: await creatingName(repoId),
678
+ bytes: declaredBytes(request),
679
+ })
680
+ if (!verdict.ok) refusal = verdict.message
681
+ }
682
+ }
683
+ }
684
+
593
685
  let repo
594
686
  try {
595
687
  repo = deps.ensureRepo(resolveRepo(deps.reposDir, route[1]!))
@@ -609,10 +701,47 @@ function createRouter(deps: HttpHandlerDeps): (req: Request) => Promise<Response
609
701
  }
610
702
  }
611
703
 
612
- return deps.runBackend({ repo, pathInfo: url.pathname, request })
704
+ return deps.runBackend({
705
+ repo,
706
+ pathInfo: url.pathname,
707
+ request,
708
+ ...(refusal ? { env: { [REFUSE_ENV]: refusal } } : {}),
709
+ })
613
710
  }
614
711
  }
615
712
 
713
+ /**
714
+ * The client this request is attributed to, or `null` when walgit cannot
715
+ * attribute it.
716
+ *
717
+ * `cf-connecting-ip` first: the container is reachable only through the Worker,
718
+ * and Cloudflare sets that header at the edge over whatever the client sent, so
719
+ * it is the one address here a client cannot choose for itself.
720
+ * `x-forwarded-for` is the fallback for a deployment fronted by something else,
721
+ * and its FIRST entry is the client — the rest are proxies.
722
+ */
723
+ function sourceOf(request: Request): string | null {
724
+ const direct = request.headers.get('cf-connecting-ip')?.trim()
725
+ if (direct) return direct
726
+ const forwarded = request.headers.get('x-forwarded-for')?.split(',')[0]?.trim()
727
+ return forwarded ? forwarded : null
728
+ }
729
+
730
+ /**
731
+ * What this push says it weighs.
732
+ *
733
+ * `content-length`, and a chunked push declares none — which reads as 0 and is
734
+ * charged as 0, deliberately. The exact size of a chunked push is known only
735
+ * once it has been uploaded, and by then the bytes have already been spent;
736
+ * the cap that bounds THAT is the per-push size cap, refused in `pre-receive`
737
+ * on the quarantine pack (`src/limits.ts`). This one bounds the volume a source
738
+ * declares, and a client under-declaring it is refused by the other.
739
+ */
740
+ function declaredBytes(request: Request): number {
741
+ const declared = Number(request.headers.get('content-length') ?? '0')
742
+ return Number.isFinite(declared) && declared > 0 ? declared : 0
743
+ }
744
+
616
745
  /**
617
746
  * The fingerprint this request PROVED, or `null`.
618
747
  *
@@ -16,7 +16,7 @@
16
16
  */
17
17
 
18
18
  import type { Capabilities } from '../shared/capabilities'
19
- import { describeBytes } from '../shared/policy'
19
+ import { describeBytes, describeWindow } from '../shared/policy'
20
20
  import { EVENTS_PATH, PROVENANCE_PATH } from '../shared/protocol'
21
21
 
22
22
  /**
@@ -121,6 +121,22 @@ function facts(caps: Capabilities): string[] {
121
121
  if (caps.maxRepoBytes !== null) {
122
122
  facts.push(`One repository may not exceed ${describeBytes(caps.maxRepoBytes)} in total.`)
123
123
  }
124
+ // What one client may spend, per window (`src/rate-limit.ts`). One line for
125
+ // all three halves rather than one each, because this document is the terse
126
+ // one and pays for every sentence out of a byte budget — the long form is
127
+ // `/llms.txt`.
128
+ if (caps.sourceLimited) {
129
+ const per = `per client per ${describeWindow(caps.rateWindowSeconds)}`
130
+ const parts: string[] = []
131
+ if (caps.maxNewReposPerSource !== null) {
132
+ parts.push(`${caps.maxNewReposPerSource} new repositories`)
133
+ }
134
+ if (caps.maxPushesPerSource !== null) parts.push(`${caps.maxPushesPerSource} pushes`)
135
+ if (caps.maxPushBytesPerSource !== null) {
136
+ parts.push(describeBytes(caps.maxPushBytesPerSource))
137
+ }
138
+ facts.push(`Rate limited: ${parts.join(', ')} ${per}. Waiting it out is the remedy.`)
139
+ }
124
140
 
125
141
  facts.push(
126
142
  'Put a random suffix on the name. Many agents run near-identical prompts at the same time; a plain name is probably taken already, and a taken name means your push is refused.',
@@ -0,0 +1,264 @@
1
+ /**
2
+ * Per-source rate limits: bound what one visitor can spend, in a window.
3
+ *
4
+ * The size caps beside this file (`src/limits.ts`) bound how big a push may be.
5
+ * They say nothing about how OFTEN one may arrive, and the two are different
6
+ * failures: a hundred 1 MiB pushes are each individually fine, and a hundred
7
+ * new names are each individually free. One container serves every repository
8
+ * (`wrangler.jsonc`, `max_instances: 1`), so a bored visitor filling the bucket
9
+ * during a traffic spike is not merely storage — it is the queue everyone else
10
+ * is behind.
11
+ *
12
+ * ── where the verdict is reached, and where it is spoken ────────────────────
13
+ *
14
+ * Reached in `src/http.ts`, because that is the only place that sees BOTH the
15
+ * source the edge attributed the request to and the repository it names: the
16
+ * hooks are processes git spawns, three down, and a header does not reach them.
17
+ * Spoken by `pre-receive`, because a refusal at the HTTP layer is a status code
18
+ * git reports as `RPC failed; HTTP …` — a transport fault, which a client
19
+ * retries. The handler therefore hands the backend a refusal and the hook
20
+ * prints it, so an over-limit push reads exactly the way an oversized one does:
21
+ * a `remote:` reject line naming the limit and what to do next.
22
+ *
23
+ * ── what a "source" is ──────────────────────────────────────────────────────
24
+ *
25
+ * Whatever the Worker can see, which is the client IP (`cf-connecting-ip`, set
26
+ * by Cloudflare at the edge and not forgeable by a client, since the container
27
+ * is reachable only through the Worker). A request carrying no such header is
28
+ * unattributable — a direct request to the container, a local deployment — and
29
+ * is NOT limited: pooling everything walgit cannot name into one bucket would
30
+ * make the first unattributable request throttle every other one.
31
+ *
32
+ * ── the counters are in memory, deliberately ────────────────────────────────
33
+ *
34
+ * A window that a container restart forgets. The alternative is a round trip to
35
+ * the object store on every push to enforce a limit whose entire purpose is to
36
+ * make a spike cheap, and the failure direction of forgetting is a visitor
37
+ * getting one more window than it should — against a Durable Object write per
38
+ * push, forever, on every deployment that turned this on. The table is capped
39
+ * so a spike of distinct addresses cannot grow it without bound.
40
+ *
41
+ * Every limit is UNSET by default, and an unset one is not enforced and not
42
+ * advertised — `capabilitiesFrom` (`shared/capabilities.ts`) is the one reading
43
+ * both this file and the three documents take their numbers from.
44
+ */
45
+
46
+ import type { Capabilities } from '../shared/capabilities'
47
+ import { describeBytes, describeWindow } from '../shared/policy'
48
+
49
+ export interface RateLimits {
50
+ /** The window every count below is taken over, in milliseconds. */
51
+ windowMs: number
52
+ /** New repository names one source may create per window. `null` is unlimited. */
53
+ maxNewRepos: number | null
54
+ /** Pushes one source may make per window. `null` is unlimited. */
55
+ maxPushes: number | null
56
+ /** Bytes one source may push per window. `null` is unlimited. */
57
+ maxPushBytes: number | null
58
+ }
59
+
60
+ /**
61
+ * The limits this instance enforces, as the four of the capabilities this file
62
+ * cares about — a projection, exactly as `limitsOf` is, so the number a page
63
+ * prints and the number a push is refused on cannot be arrived at two ways.
64
+ */
65
+ export function rateLimitsOf(caps: Capabilities): RateLimits {
66
+ return {
67
+ windowMs: caps.rateWindowSeconds * 1000,
68
+ maxNewRepos: caps.maxNewReposPerSource,
69
+ maxPushes: caps.maxPushesPerSource,
70
+ maxPushBytes: caps.maxPushBytesPerSource,
71
+ }
72
+ }
73
+
74
+ /** Is there anything to count? Nothing is tracked when there isn't. */
75
+ export function rateLimitsEnforced(limits: RateLimits): boolean {
76
+ return limits.maxNewRepos !== null || limits.maxPushes !== null || limits.maxPushBytes !== null
77
+ }
78
+
79
+ /** Does any configured limit need to know whether the name is a new one? */
80
+ export function countsNewRepos(limits: RateLimits): boolean {
81
+ return limits.maxNewRepos !== null
82
+ }
83
+
84
+ export type RateKind = 'new-repos' | 'pushes' | 'push-bytes'
85
+
86
+ export type RateVerdict = { ok: true } | { ok: false; kind: RateKind; message: string }
87
+
88
+ export interface RateCharge {
89
+ /** The client the edge attributed this request to. */
90
+ source: string
91
+ /** The repository this push names. */
92
+ repoId: string
93
+ /** Does this push bring a name into existence? */
94
+ creating: boolean
95
+ /** Bytes this push declared, or 0 when it declared none. */
96
+ bytes: number
97
+ }
98
+
99
+ /**
100
+ * How many sources one instance remembers at once.
101
+ *
102
+ * A bound rather than a tuning knob: this table is fed by whoever shows up, so
103
+ * an unbounded one is a memory leak an attacker chooses the size of. When it is
104
+ * full the least recently seen source is dropped — which forgives it, the same
105
+ * direction a restart forgives in, and the one that cannot refuse an innocent
106
+ * client because somebody else arrived.
107
+ */
108
+ const MAX_SOURCES = 10_000
109
+
110
+ type Spend = { at: number; bytes: number; creating: boolean }
111
+
112
+ export interface SourceLimiter {
113
+ /** Judge one push and, when it is allowed, charge it to its source. */
114
+ admit(charge: RateCharge): RateVerdict
115
+ }
116
+
117
+ /**
118
+ * The window, as a table of what each source spent in it.
119
+ *
120
+ * Charged only for pushes it ALLOWS. A refused push costs the client nothing
121
+ * further, so a client that keeps retrying is refused on the same spend rather
122
+ * than digging a deeper hole it cannot see the bottom of — and the window
123
+ * therefore always describes traffic walgit actually served.
124
+ */
125
+ export function createSourceLimiter(
126
+ limits: RateLimits,
127
+ now: () => number = Date.now,
128
+ ): SourceLimiter {
129
+ const spends = new Map<string, Spend[]>()
130
+
131
+ return {
132
+ admit(charge) {
133
+ const at = now()
134
+ const since = at - limits.windowMs
135
+
136
+ // Re-inserted on every touch, so Map iteration order is least-recently
137
+ // seen first and the eviction below drops the right one.
138
+ const previous = spends.get(charge.source)
139
+ spends.delete(charge.source)
140
+ const window = (previous ?? []).filter((spend) => spend.at > since)
141
+
142
+ const verdict = judge(limits, window, charge)
143
+ if (verdict.ok) window.push({ at, bytes: charge.bytes, creating: charge.creating })
144
+
145
+ if (window.length > 0) {
146
+ spends.set(charge.source, window)
147
+ if (spends.size > MAX_SOURCES) {
148
+ const oldest = spends.keys().next()
149
+ if (!oldest.done) spends.delete(oldest.value)
150
+ }
151
+ }
152
+ return verdict
153
+ },
154
+ }
155
+ }
156
+
157
+ /**
158
+ * Judge one push against a source's window.
159
+ *
160
+ * Creation is judged FIRST, and the reason is the same one that puts the
161
+ * per-push size cap ahead of the per-repository one: when a push trips both, the
162
+ * actionable message is the one about the thing the client chose to do. "You
163
+ * have created enough new names" tells it to push to a name it already has;
164
+ * "you have pushed enough" would send it away from the host entirely for a
165
+ * push that would have been fine under a name it already owns.
166
+ */
167
+ function judge(limits: RateLimits, window: Spend[], charge: RateCharge): RateVerdict {
168
+ const window_ = describeWindow(limits.windowMs / 1000)
169
+
170
+ if (charge.creating && limits.maxNewRepos !== null) {
171
+ const created = window.filter((spend) => spend.creating).length
172
+ if (created >= limits.maxNewRepos) {
173
+ return {
174
+ ok: false,
175
+ kind: 'new-repos',
176
+ message: tooManyNewRepos(charge.repoId, limits.maxNewRepos, window_),
177
+ }
178
+ }
179
+ }
180
+
181
+ if (limits.maxPushes !== null && window.length >= limits.maxPushes) {
182
+ return { ok: false, kind: 'pushes', message: tooManyPushes(limits.maxPushes, window_) }
183
+ }
184
+
185
+ if (limits.maxPushBytes !== null) {
186
+ const spent = window.reduce((total, spend) => total + spend.bytes, 0)
187
+ if (spent + charge.bytes > limits.maxPushBytes) {
188
+ return {
189
+ ok: false,
190
+ kind: 'push-bytes',
191
+ message: tooManyBytes(spent, charge.bytes, limits.maxPushBytes, window_),
192
+ }
193
+ }
194
+ }
195
+
196
+ return { ok: true }
197
+ }
198
+
199
+ /**
200
+ * Product copy, and the same discipline the size caps are written with: say
201
+ * which limit, say the number, and say the one thing to do next. A rate limit
202
+ * is the refusal most likely to be read by something that will simply try
203
+ * again, so each message states that waiting is the remedy and roughly what
204
+ * for.
205
+ */
206
+ function tooManyNewRepos(repoId: string, cap: number, window: string): string {
207
+ return [
208
+ `walgit: refused — ${repoId} would be your ${cap + 1}${ordinal(cap + 1)} new repository this ${window}.`,
209
+ '',
210
+ `This host lets one client create ${cap} ${plural(cap, 'repository', 'repositories')} per ${window}.`,
211
+ 'This is a walgit limit, not a network failure. Retrying now will be refused',
212
+ 'again in the same way.',
213
+ '',
214
+ 'What you can do instead:',
215
+ ` - push to a name you already created — the limit is on NEW names, not on pushes`,
216
+ ` - or wait out the ${window} and push again`,
217
+ '',
218
+ 'Nothing was uploaded; no repository was created.',
219
+ ].join('\n')
220
+ }
221
+
222
+ function tooManyPushes(cap: number, window: string): string {
223
+ return [
224
+ `walgit: refused — you have already made ${cap} ${plural(cap, 'push', 'pushes')} this ${window}.`,
225
+ '',
226
+ `This host lets one client push ${cap} ${plural(cap, 'time', 'times')} per ${window}.`,
227
+ 'This is a walgit limit, not a network failure. Retrying now will be refused',
228
+ 'again in the same way.',
229
+ '',
230
+ 'What you can do instead:',
231
+ ' - combine your work into fewer pushes: commit locally, then push once',
232
+ ` - or wait out the ${window} and push again`,
233
+ '',
234
+ 'Nothing was uploaded; the repository is unchanged.',
235
+ ].join('\n')
236
+ }
237
+
238
+ function tooManyBytes(spent: number, bytes: number, cap: number, window: string): string {
239
+ return [
240
+ `walgit: refused — this push would take you past ${describeBytes(cap)} pushed this ${window}.`,
241
+ '',
242
+ `You have pushed ${describeBytes(spent)} in the last ${window} and this push adds`,
243
+ `${describeBytes(bytes)}.`,
244
+ 'This is a walgit limit, not a network failure. Retrying now will be refused',
245
+ 'again in the same way.',
246
+ '',
247
+ 'What you can do instead:',
248
+ ' - push less at once, or leave large files out of the repository entirely',
249
+ ` - or wait out the ${window} and push again`,
250
+ '',
251
+ 'Nothing was uploaded; the repository is unchanged.',
252
+ ].join('\n')
253
+ }
254
+
255
+ const plural = (n: number, one: string, many: string) => (n === 1 ? one : many)
256
+
257
+ /** `1st`, `2nd`, `3rd`, `4th` — the suffix only, so the number reads naturally. */
258
+ function ordinal(n: number): string {
259
+ if (n % 100 >= 11 && n % 100 <= 13) return 'th'
260
+ if (n % 10 === 1) return 'st'
261
+ if (n % 10 === 2) return 'nd'
262
+ if (n % 10 === 3) return 'rd'
263
+ return 'th'
264
+ }
@@ -149,6 +149,11 @@ console.log(
149
149
  `retentionHours=${caps.retentionHours ?? 'off'} ` +
150
150
  `maxPush=${caps.maxPushBytes ?? 'unset'} maxRepo=${caps.maxRepoBytes ?? 'unset'} ` +
151
151
  `private=${caps.namesCanBePrivate} ` +
152
+ `perSource=${
153
+ caps.sourceLimited
154
+ ? `${caps.maxNewReposPerSource ?? '-'} repos/${caps.maxPushesPerSource ?? '-'} pushes/${caps.maxPushBytesPerSource ?? '-'} bytes per ${caps.rateWindowSeconds}s`
155
+ : 'off'
156
+ } ` +
152
157
  `store=${store ? 'configured' : 'MISSING'}`,
153
158
  )
154
159
 
@@ -33,6 +33,7 @@ import { parseTokens } from '../shared/credentials'
33
33
  import { authorizeAnnounce, authorizeSubscribe } from '../shared/events'
34
34
  import { renderLanding, wantsLanding } from '../shared/landing'
35
35
  import { renderLlms, wantsLlms } from '../shared/llms'
36
+ import { operatorFrom } from '../shared/operator'
36
37
  import { renderRobots, wantsRobots } from '../shared/robots'
37
38
  import {
38
39
  ANNOUNCE_PATH,
@@ -75,6 +76,16 @@ export interface Env {
75
76
  WALGIT_RETENTION_HOURS?: string
76
77
  WALGIT_MAX_PUSH_BYTES?: string
77
78
  WALGIT_MAX_REPO_BYTES?: string
79
+ /**
80
+ * What one source may spend in a window (src/rate-limit.ts). All off unless
81
+ * set; the window defaults when a count is set without one. Forwarded to the
82
+ * container, which is where the verdict is reached — this side only states
83
+ * them on the two documents below.
84
+ */
85
+ WALGIT_RATE_WINDOW_SECONDS?: string
86
+ WALGIT_MAX_NEW_REPOS_PER_SOURCE?: string
87
+ WALGIT_MAX_PUSHES_PER_SOURCE?: string
88
+ WALGIT_MAX_PUSH_BYTES_PER_SOURCE?: string
78
89
  /**
79
90
  * Where request-level telemetry goes — the half of observability the log
80
91
  * cannot produce (shared/telemetry.ts). Optional: a deployment without the
@@ -117,6 +128,18 @@ export interface Env {
117
128
  * default, and a secret.
118
129
  */
119
130
  WALGIT_PRIVATE_REPOS?: string
131
+ /**
132
+ * Who runs this deployment, and where to write about it
133
+ * (`shared/operator.ts`). Read ONLY through `operatorFrom`, like the policy
134
+ * above is read only through `capabilitiesFrom`.
135
+ *
136
+ * Deliberately absent from `CONTAINER_ENV`: nothing the container serves
137
+ * names an operator, and a name there would cost a container restart on
138
+ * every copy edit. Unset means the two edge documents carry no operator
139
+ * block at all, rather than a placeholder nobody reads.
140
+ */
141
+ WALGIT_OPERATOR?: string
142
+ WALGIT_CONTACT?: string
120
143
  WALGIT_EVENTS: DurableObjectNamespace<WalgitEvents>
121
144
  }
122
145
 
@@ -252,6 +275,10 @@ export default {
252
275
  // and the socket cannot describe three different deployments — they used
253
276
  // to read the environment three times, and only the size caps were shared.
254
277
  const caps = capabilitiesFrom(env)
278
+ // Who is answerable for this deployment (`shared/operator.ts`). Derived
279
+ // beside the capabilities and passed to both documents, so the page and
280
+ // the manual cannot name two different operators.
281
+ const operator = operatorFrom(env)
255
282
 
256
283
  // The browser half of `/`, answered at the edge (shared/landing.ts). Placed
257
284
  // before every other decision on purpose: a link on an aggregator points at
@@ -264,7 +291,7 @@ export default {
264
291
  // them: this document and `/llms.txt` want a bare hostname they prefix
265
292
  // with `https://`/`wss://` themselves, while `GET /` needs a full origin
266
293
  // including the scheme, and one field could not serve both.
267
- const page = renderLanding(url.host, caps)
294
+ const page = renderLanding(url.host, caps, operator)
268
295
  const bytes = new TextEncoder().encode(page)
269
296
  record(env, ctx, {
270
297
  kind: 'landing',
@@ -305,7 +332,7 @@ export default {
305
332
  // `/llms.txt` is not reachable as a repo route even for a repository called
306
333
  // `llms.txt`.
307
334
  if (wantsLlms(request.method, url.pathname)) {
308
- const doc = renderLlms(url.host, caps)
335
+ const doc = renderLlms(url.host, caps, operator)
309
336
  const bytes = new TextEncoder().encode(doc)
310
337
  record(env, ctx, {
311
338
  kind: 'landing',