@zabaca/zbc 0.19.1 → 0.21.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.
@@ -29,6 +29,7 @@ import { CONTENT_SIGNAL } from './robots'
29
29
  import {
30
30
  CHALLENGE_PATH,
31
31
  EVENTS_PATH,
32
+ MCP_PATH,
32
33
  PROVENANCE_PATH,
33
34
  READ_CHALLENGE_NAMESPACE,
34
35
  SIGNERS_REF,
@@ -802,6 +803,21 @@ git clone https://${host}/$NAME.git
802
803
  \`\`\`
803
804
 
804
805
  Handing work to another agent is the URL and nothing else. There is no owner to ask, no invitation to send and no review to pass.
806
+
807
+ ## Ask this host directly
808
+
809
+ This host speaks the Model Context Protocol at \`https://${host}${MCP_PATH}\` (Streamable HTTP). There is nothing to install and nothing to spawn — point a client at the URL:
810
+
811
+ \`\`\`sh
812
+ claude mcp add --transport http agentgit https://${host}${MCP_PATH}
813
+ \`\`\`
814
+
815
+ It carries what this host can answer without your disk: \`agentgit_status\` (does a name exist, is it claimed, is it private, what are its refs), \`agentgit_watch\` (block until a ref moves — the handoff primitive, capped at five minutes per call)${
816
+ // Named only where a signature can be made. On a deployment with no nonce
817
+ // seed the tool answers `signer: null` for every ref, which is the honest
818
+ // answer and a useless one to send an agent after.
819
+ caps.signedPushes ? ', `agentgit_provenance` (which key signed the push that moved a ref)' : ''
820
+ }, and this document as the resource \`agentgit://manual\`. Everything that touches a clone stays a shell command, because this host cannot see your tree.
805
821
  ${signing}${ownership}${privacy}${proposing}${events}
806
822
  ## If a push is refused
807
823
 
@@ -0,0 +1,286 @@
1
+ /**
2
+ * The Model Context Protocol surface, as a value.
3
+ *
4
+ * An agent finds a tool through the registry its harness already reads. The
5
+ * first version of this shipped as a stdio server an agent's harness spawned
6
+ * (`npx -y @zabaca/agentgit mcp`), and both ways it could fail to start were
7
+ * spawn problems rather than protocol ones: a cold npx cache racing the
8
+ * client's startup timeout, and a workspace checkout resolving the unlinked
9
+ * package. A URL has neither failure mode, so the server moved to the host
10
+ * that already answers every other question about a repository.
11
+ *
12
+ * **It carries only what the host can answer without the agent's disk.** A
13
+ * name's state, a ref moving, who pushed it, and the manual. Accepting a
14
+ * Proposal, configuring a credential helper and fetching into a clone are the
15
+ * skill's, as shell commands — they act on a tree this process cannot see, and
16
+ * a tool that pretended otherwise would be a tool that could only fail.
17
+ *
18
+ * Nothing here reaches anything. Every fact comes through `McpDeps`, whose
19
+ * implementations (`worker/mcp.ts`) are the container round trip and the event
20
+ * socket — which is what lets the whole surface be driven by a real MCP client
21
+ * in `src/mcp.test.ts` with no runtime at all. `shared/`'s one rule holds: this
22
+ * module imports no runtime, and both halves may compile it (docs/adr/0010).
23
+ *
24
+ * **The names are protocol, not an opinion.** `walgit may gain capabilities,
25
+ * never opinions` (CONTEXT.md), and `agentgit_*` plus `agentgit://manual` look
26
+ * like one deployment's brand in the mechanism. They are not configurable for
27
+ * the same reason `refs/walgit/signers` is not: a client TYPES them. A skill,
28
+ * a plugin and a harness config all name a tool, so a deployment that renamed
29
+ * its tools would be a deployment no existing client can call — the opposite
30
+ * of what instance configuration is for. What IS per-deployment — the host,
31
+ * the capabilities, the operator, every limit in the manual — arrives through
32
+ * `McpDeps`, and every refusal below is prefixed `walgit:` like the rest of
33
+ * this package, because the mechanism is what refused.
34
+ *
35
+ * The one rule it DOES own is the refusal: a read that the host refused is
36
+ * reported as a refusal and nothing else. `status` on a Private name a caller
37
+ * cannot prove a key for must not leak refs, existence or the lists alongside
38
+ * the 401 — that is the property `info/refs` has, and the reason both reading
39
+ * tools go through the host's own gated routes rather than a second copy of
40
+ * the gate.
41
+ */
42
+
43
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
44
+ import { z } from 'zod'
45
+
46
+ import type { Capabilities } from './capabilities'
47
+ import { renderLlms } from './llms'
48
+ import type { Operator } from './operator'
49
+ import { REF_NAME, REPO_ID } from './protocol'
50
+
51
+ /** The manual, as a resource a client can read without calling a tool. */
52
+ export const MANUAL_URI = 'agentgit://manual'
53
+
54
+ /**
55
+ * The longest a single `agentgit_watch` holds a request open.
56
+ *
57
+ * A watch is a long poll over the ref-event stream, and the request it holds
58
+ * open is a Worker invocation — so the cap is the HOST's, not the caller's. A
59
+ * client that wants to wait longer calls again, and loses nothing by it:
60
+ * events are latest-state, so the next call's answer is current state rather
61
+ * than a replay it might have missed (docs/adr/0009).
62
+ */
63
+ export const MAX_WATCH_MS = 5 * 60_000
64
+
65
+ /** What a read of a repository answered, or the refusal the host made. */
66
+ export type Read<T> = ({ ok: true } & T) | { ok: false; status: number; message: string }
67
+
68
+ /** One repository's state, as the host sees it. */
69
+ export interface StatusFacts {
70
+ /** Anything has ever been pushed to this name. */
71
+ exists: boolean
72
+ /** It holds a Signer List, so a stranger's push is refused (docs/adr/0012). */
73
+ claimed: boolean
74
+ /** It holds a Reader List, so a stranger's read is refused (docs/adr/0013). */
75
+ private: boolean
76
+ /** Ref name → sha, as the Index holds it. */
77
+ refs: Record<string, string>
78
+ }
79
+
80
+ /** Who moved each ref, as the host recorded it (docs/adr/0011). */
81
+ export type ProvenanceFacts = Record<string, { signer: string; ts: string }>
82
+
83
+ /** What a watch saw: a ref that moved, or the deadline. */
84
+ export type WatchOutcome = { timedOut: false; ref: string; sha: string | null } | { timedOut: true }
85
+
86
+ /**
87
+ * Everything the tools touch that this module cannot compute.
88
+ *
89
+ * `status` and `provenance` return a `Read`, never throw, because a refusal is
90
+ * an ANSWER the host made and has to survive the trip verbatim — turning a 401
91
+ * into an exception here is how a refusal becomes "something went wrong".
92
+ * `watch` may throw: an event stream that cannot be reached is not a verdict
93
+ * about the repository, and reporting it as one would be a lie.
94
+ */
95
+ export interface McpDeps {
96
+ /** Reported in the handshake, so a client can name what it is talking to. */
97
+ version: string
98
+ /** This deployment's hostname, for the manual and for naming it in an error. */
99
+ host: string
100
+ /** What this deployment offers (`shared/capabilities.ts`). */
101
+ caps: Capabilities
102
+ /** Who runs it (`shared/operator.ts`), or nobody. */
103
+ operator: Operator | null
104
+ status(name: string): Promise<Read<StatusFacts>>
105
+ provenance(name: string): Promise<Read<{ repo: string; provenance: ProvenanceFacts }>>
106
+ watch(name: string, ref: string | null, timeoutMs: number): Promise<WatchOutcome>
107
+ }
108
+
109
+ interface ToolResult {
110
+ content: { type: 'text'; text: string }[]
111
+ isError?: boolean
112
+ [key: string]: unknown
113
+ }
114
+
115
+ const json = (value: unknown): ToolResult => ({
116
+ content: [{ type: 'text', text: JSON.stringify(value, null, 2) }],
117
+ })
118
+
119
+ const refuse = (message: string): ToolResult => ({
120
+ content: [{ type: 'text', text: message }],
121
+ isError: true,
122
+ })
123
+
124
+ /**
125
+ * The name grammar, applied before the host is asked.
126
+ *
127
+ * The same `REPO_ID` every other entry point applies (`src/repo.ts`,
128
+ * `shared/events.ts`): a name one surface accepts and another rejects is a
129
+ * repository half the service can see. Refused here rather than forwarded so a
130
+ * path-shaped name never becomes a request at all.
131
+ */
132
+ function badName(name: string): string | null {
133
+ return REPO_ID.test(name)
134
+ ? null
135
+ : `walgit: "${name}" is not a repository name here — one flat segment of letters, digits, dot, dash or underscore, starting with a letter or a digit.`
136
+ }
137
+
138
+ /**
139
+ * The MCP server this host serves, wired over `deps`.
140
+ *
141
+ * Returned unconnected: the transport is the caller's, which is what lets one
142
+ * function serve a Streamable HTTP request in the Worker and an in-memory pair
143
+ * in a test. The descriptions are written for the model that reads the tool
144
+ * list and nothing else — that list is the only documentation an MCP client
145
+ * sees before it calls something.
146
+ */
147
+ export function createAgentgitMcp(deps: McpDeps): McpServer {
148
+ const server = new McpServer({ name: 'agentgit', version: deps.version })
149
+
150
+ const name = z
151
+ .string()
152
+ .describe('The repository name — the `<name>` in `https://host/<name>.git`.')
153
+
154
+ server.registerTool(
155
+ 'agentgit_status',
156
+ {
157
+ description:
158
+ "What the host knows about a repository name: whether anything has been pushed to it, whether it holds a Signer List (claimed, so a stranger cannot push), whether it holds a Reader List (private, so a stranger cannot read), and every ref with its sha. Reads only; creates nothing. A free name answers exists: false rather than an error, so this is how you check before claiming one. signedPushes is the deployment's, not this name's: it says whether a push to anything here can be signed at all.",
159
+ inputSchema: { name },
160
+ },
161
+ async (input): Promise<ToolResult> => {
162
+ const bad = badName(input.name)
163
+ if (bad) return refuse(bad)
164
+ const read = await deps.status(input.name)
165
+ if (!read.ok) return refuse(read.message)
166
+ return json({
167
+ name: input.name,
168
+ exists: read.exists,
169
+ claimed: read.claimed,
170
+ private: read.private,
171
+ // An array rather than the map the Index holds: a tool result is read
172
+ // by a model, and a list of {ref, sha} survives truncation in a way an
173
+ // object whose KEYS are the interesting part does not.
174
+ refs: Object.entries(read.refs).map(([ref, sha]) => ({ ref, sha })),
175
+ signedPushes: deps.caps.signedPushes,
176
+ })
177
+ },
178
+ )
179
+
180
+ server.registerTool(
181
+ 'agentgit_watch',
182
+ {
183
+ description:
184
+ 'Block until a ref in a repository moves, then say what it is now. This is the handoff primitive: call it to wait for the other agent to push. Answers { ref, sha } when one moves, or { timedOut: true } when none did before the deadline — which is an answer, not a failure, so call it again to keep waiting. It touches no clone: fetching what it reports is yours to do.',
185
+ inputSchema: {
186
+ name,
187
+ ref: z
188
+ .string()
189
+ .optional()
190
+ .describe('A full ref name, e.g. refs/heads/main. Omit to watch every ref.'),
191
+ timeoutMs: z
192
+ .number()
193
+ .int()
194
+ // Positive, so a `0` or a negative does not become a watch that
195
+ // answers `{ timedOut: true }` before the socket is even open —
196
+ // which reads as "nothing moved" and is a claim about the repository
197
+ // rather than about the argument.
198
+ .positive()
199
+ .optional()
200
+ .describe(`How long to wait, capped at ${MAX_WATCH_MS}ms by the host.`),
201
+ },
202
+ },
203
+ async (input): Promise<ToolResult> => {
204
+ const bad = badName(input.name)
205
+ if (bad) return refuse(bad)
206
+ const ref = input.ref ?? null
207
+ if (ref !== null && !REF_NAME.test(ref)) {
208
+ return refuse(`walgit: "${ref}" is not a full ref name — refs/heads/main, not main.`)
209
+ }
210
+ // The host's cap, not the caller's (see `MAX_WATCH_MS`).
211
+ const timeoutMs = Math.min(input.timeoutMs ?? MAX_WATCH_MS, MAX_WATCH_MS)
212
+ let outcome: WatchOutcome
213
+ try {
214
+ outcome = await deps.watch(input.name, ref, timeoutMs)
215
+ } catch (error) {
216
+ // Named rather than hung, and the HOST is named: a watch that cannot
217
+ // reach the event stream is a fact about this deployment, and a client
218
+ // told only "failed" has nothing to retry against.
219
+ return refuse(
220
+ `walgit: could not watch ${input.name} on ${deps.host}: ${
221
+ error instanceof Error ? error.message : String(error)
222
+ }`,
223
+ )
224
+ }
225
+ return json({
226
+ timedOut: outcome.timedOut,
227
+ repo: input.name,
228
+ // Spelled out rather than left off, because shape alone is ambiguous: a
229
+ // deleted ref carries no sha, and `{ sha: null }` on its own reads as a
230
+ // handoff that landed.
231
+ ref: outcome.timedOut ? null : outcome.ref,
232
+ sha: outcome.timedOut ? null : outcome.sha,
233
+ })
234
+ },
235
+ )
236
+
237
+ server.registerTool(
238
+ 'agentgit_provenance',
239
+ {
240
+ description:
241
+ 'Who pushed a ref: the SSH key fingerprint that signed the push, and when it landed. A key, never a user — there are no accounts here. A ref nobody signed answers signer: null, which is the ordinary answer, because signing is opt-in.',
242
+ inputSchema: {
243
+ name,
244
+ ref: z.string().describe('A full ref name, e.g. refs/heads/main.'),
245
+ },
246
+ },
247
+ async (input): Promise<ToolResult> => {
248
+ const bad = badName(input.name)
249
+ if (bad) return refuse(bad)
250
+ const read = await deps.provenance(input.name)
251
+ if (!read.ok) return refuse(read.message)
252
+ const entry = read.provenance[input.ref]
253
+ return json({
254
+ repo: input.name,
255
+ ref: input.ref,
256
+ signer: entry?.signer ?? null,
257
+ ts: entry?.ts ?? null,
258
+ })
259
+ },
260
+ )
261
+
262
+ server.registerResource(
263
+ 'manual',
264
+ MANUAL_URI,
265
+ {
266
+ title: 'agentgit manual',
267
+ description:
268
+ "This host's own /llms.txt — push-to-create, claiming a name, Reader Lists, Proposals and the event stream, with every limit this deployment actually enforces.",
269
+ mimeType: 'text/markdown',
270
+ },
271
+ async (uri) => ({
272
+ contents: [
273
+ {
274
+ uri: uri.href,
275
+ mimeType: 'text/markdown',
276
+ // The same renderer the `/llms.txt` route calls, over the same
277
+ // capabilities: one document, two ways to it, and no second copy to
278
+ // promise a limit this deployment does not have.
279
+ text: renderLlms(deps.host, deps.caps, deps.operator),
280
+ },
281
+ ],
282
+ }),
283
+ )
284
+
285
+ return server
286
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * `/agentgit-og.png` — the picture the link becomes.
3
+ *
4
+ * The head used to argue for a `summary` card on the grounds that a preview
5
+ * image "has to be a fetchable raster at a stable URL, which means an asset in
6
+ * the Worker bundle and a route serving it, and neither exists yet". This is
7
+ * the route, and `assets/agentgit-og.png` is the asset: a card rendered once,
8
+ * from the mark that is already the favicon, and committed. It is NOT rendered
9
+ * per request — a crawler fetching a picture must not wake the container any
10
+ * more than a reader fetching the page does.
11
+ *
12
+ * Everything the document decides is here, and the bytes are not: the Worker
13
+ * imports the PNG (only `worker/` may reach a bundler), and this module states
14
+ * the path, the methods, the dimensions and the headers. That keeps `shared/`
15
+ * runtime-neutral (docs/adr/0010) and keeps the head's advertised size and the
16
+ * served picture's size one pair of numbers.
17
+ *
18
+ * No collision with a repository, the same argument `/robots.txt` and
19
+ * `/llms.txt` make: smart-HTTP paths are `/<name>.git/…`, so a repository
20
+ * literally called `agentgit-og.png` is reached at `/agentgit-og.png.git/…`
21
+ * and is untouched by this route.
22
+ */
23
+
24
+ /** The one path. Named for the site rather than `/og.png` so it reads as the
25
+ * card's picture in a log, a referrer and a README's `<img src>`. */
26
+ export const OG_IMAGE_PATH = '/agentgit-og.png'
27
+
28
+ /** The card size every platform specifies for the large-summary layout. The
29
+ * head advertises these two numbers and the committed PNG is rendered at
30
+ * them; a crawler that finds a different size crops it itself. */
31
+ export const OG_IMAGE_WIDTH = 1200
32
+ export const OG_IMAGE_HEIGHT = 630
33
+
34
+ export const OG_IMAGE_CONTENT_TYPE = 'image/png'
35
+
36
+ /**
37
+ * A day, where the page and the manual get a minute.
38
+ *
39
+ * The reason those two are short is that they render this deployment's limits
40
+ * and capabilities, so a stale copy at the edge states a cap the push path no
41
+ * longer has. The picture renders none of that — it is a mark and a wordmark —
42
+ * so nothing in it can outlive a config change, and the crawlers fetching it
43
+ * are exactly the traffic worth absorbing at the edge.
44
+ */
45
+ export const OG_IMAGE_CACHE_CONTROL = 'public, max-age=86400'
46
+
47
+ /** Only GET or HEAD on the one path. Nothing else is this picture. */
48
+ export function wantsOgImage(method: string, pathname: string): boolean {
49
+ if (method !== 'GET' && method !== 'HEAD') return false
50
+ return pathname === OG_IMAGE_PATH
51
+ }
@@ -146,6 +146,26 @@ export const READ_CHALLENGE_SCHEME = 'walgit-ssh'
146
146
  /** Where a subscriber connects. A WebSocket upgrade, and nothing else. */
147
147
  export const EVENTS_PATH = '/_walgit/events'
148
148
 
149
+ /**
150
+ * The Model Context Protocol endpoint (Streamable HTTP), answered at the edge.
151
+ *
152
+ * An MCP client reaches walgit by URL, so there is nothing to install and
153
+ * nothing to spawn — which is the whole reason it is here rather than in a
154
+ * package an agent's harness has to start. It carries only what the host can
155
+ * answer without the agent's disk: a name's state, a ref moving, who pushed it,
156
+ * and the manual. Everything that touches a clone stays a shell command.
157
+ *
158
+ * Under `/_walgit/` like health, events and provenance, and for the same
159
+ * reason: the prefix is reserved, and a repository is reached at
160
+ * `/<name>.git/…`, so this route cannot shadow one — not even a repository
161
+ * actually called `mcp`, which lives at `/mcp.git/…`.
162
+ *
163
+ * Both verbs, on one path: Streamable HTTP puts client messages on POST and the
164
+ * server-to-client stream on GET, and a transport that claimed only one of them
165
+ * is a client that connects and then hears nothing.
166
+ */
167
+ export const MCP_PATH = '/_walgit/mcp'
168
+
149
169
  /**
150
170
  * Where the container publishes a push it has already made durable.
151
171
  *
@@ -25,6 +25,7 @@
25
25
 
26
26
  import {
27
27
  HEALTH_PATH,
28
+ MCP_PATH,
28
29
  PROVENANCE_PATH,
29
30
  REJECT_HEADER,
30
31
  REPO_ID,
@@ -54,6 +55,17 @@ export type RequestKind =
54
55
  // would hide the one number a launch actually turns on: how many people read
55
56
  // the page versus how many clients read the protocol.
56
57
  | 'landing'
58
+ // The card's picture (`shared/og-image.ts`), answered at the edge like the
59
+ // page and, like the page, its own kind. A crawler burst fetching a 40 KB
60
+ // raster is not a burst of people reading the page, and counting the two
61
+ // together would put the second number into the first — which is the one
62
+ // number a launch is read by.
63
+ | 'og-image'
64
+ // `/favicon.ico` and the touch icons (`shared/favicon.ts`), answered at the
65
+ // edge. Its own kind rather than `other`, because `other` is the unroutable
66
+ // bucket and these are requests walgit now answers — and because the count
67
+ // is the measure of what the route absorbed.
68
+ | 'favicon'
57
69
  | 'health'
58
70
  // Someone asking who pushed (docs/adr/0011). Its own kind rather than
59
71
  // `other`, because `other` is the unroutable bucket and a provenance read is
@@ -61,6 +73,13 @@ export type RequestKind =
61
73
  // demand for the feature and any refusal it produces, and would lose the
62
74
  // repository name with them.
63
75
  | 'provenance'
76
+ // An MCP client calling a tool (`shared/mcp.ts`), answered at the edge like
77
+ // the documents above. Its own kind rather than `other` for the reason
78
+ // `provenance` is, and one kind for the whole endpoint rather than one per
79
+ // tool: the tool and the repository it names are inside a JSON-RPC body, and
80
+ // a classifier that read request bodies to label a row would be buffering
81
+ // every push to count it.
82
+ | 'mcp'
64
83
  | 'other'
65
84
 
66
85
  export type Outcome = 'ok' | 'reject'
@@ -69,6 +88,56 @@ export interface RequestFacts {
69
88
  kind: RequestKind
70
89
  /** The repository the path names, or `''` for a request that names none. */
71
90
  repo: string
91
+ /**
92
+ * For kind `other` only: which SHAPE of unroutable path this was. Present
93
+ * nowhere else, because nowhere else is a mystery.
94
+ */
95
+ bucket?: OtherBucket
96
+ }
97
+
98
+ /**
99
+ * The shape of an unroutable path, as a closed set.
100
+ *
101
+ * `other` is where every 404 lands, and until this existed a spike in it was
102
+ * unattributable: the dataset records no path, so the 282 rows of the
103
+ * 2026-09-18 launch burst could only be guessed at (browser favicons, plus a
104
+ * scanner baseline). One bounded blob makes the next such question a SQL query.
105
+ *
106
+ * Bounded is the whole design. A path is attacker-controlled and unbounded, so
107
+ * it never reaches the dataset; what reaches it is one of these seven names,
108
+ * and an input that matches none of them is `else`.
109
+ */
110
+ export type OtherBucket =
111
+ | 'favicon'
112
+ | 'apple-touch'
113
+ | 'well-known'
114
+ | 'dotfile'
115
+ | 'php'
116
+ | 'bare-name'
117
+ | 'else'
118
+
119
+ /**
120
+ * Sort a path into one of the seven. Pure, total and never throwing: a bucket
121
+ * is a count, and a count is never worth failing a request over, so anything
122
+ * unexpected is `else`.
123
+ *
124
+ * `favicon` and `apple-touch` should be empty once the edge routes answer them
125
+ * (`shared/favicon.ts`) — they are kept as tripwires, so a route that stops
126
+ * matching shows up as rows rather than as silence.
127
+ */
128
+ export function otherBucket(pathname: string): OtherBucket {
129
+ try {
130
+ if (pathname === '/favicon.ico' || pathname === '/favicon.svg') return 'favicon'
131
+ if (pathname.startsWith('/apple-touch-icon')) return 'apple-touch'
132
+ if (pathname.startsWith('/.well-known/')) return 'well-known'
133
+ const segments = pathname.split('/').filter((s) => s.length > 0)
134
+ if (segments.some((s) => s.startsWith('.'))) return 'dotfile'
135
+ if (pathname.endsWith('.php')) return 'php'
136
+ if (segments.length === 1 && !segments[0]!.includes('.')) return 'bare-name'
137
+ return 'else'
138
+ } catch {
139
+ return 'else'
140
+ }
72
141
  }
73
142
 
74
143
  /**
@@ -82,6 +151,9 @@ export interface RequestFacts {
82
151
  */
83
152
  export function classifyRequest(method: string, pathname: string, search: string): RequestFacts {
84
153
  if (pathname === HEALTH_PATH) return { kind: 'health', repo: '' }
154
+ // No repository: the name a tool acts on travels in the JSON-RPC body, and
155
+ // the body is not something this function reads (see `RequestKind`).
156
+ if (pathname === MCP_PATH) return { kind: 'mcp', repo: '' }
85
157
  if (pathname === '/' && (method === 'GET' || method === 'HEAD')) {
86
158
  return { kind: 'instructions', repo: '' }
87
159
  }
@@ -98,7 +170,7 @@ export function classifyRequest(method: string, pathname: string, search: string
98
170
  }
99
171
 
100
172
  const route = SMART_HTTP.exec(pathname)
101
- if (!route) return { kind: 'other', repo: '' }
173
+ if (!route) return { kind: 'other', repo: '', bucket: otherBucket(pathname) }
102
174
  const repo = route[1]!
103
175
 
104
176
  if (route[2] === 'git-upload-pack') return { kind: 'clone', repo }
@@ -109,7 +181,9 @@ export function classifyRequest(method: string, pathname: string, search: string
109
181
  const service = new URLSearchParams(search).get('service')
110
182
  if (service === 'git-receive-pack') return { kind: 'push-advertise', repo }
111
183
  if (service === 'git-upload-pack') return { kind: 'clone-advertise', repo }
112
- return { kind: 'other', repo }
184
+ // A smart-HTTP-shaped path that named no service: routable enough to name a
185
+ // repository, so the bucket is `else` rather than anything about the shape.
186
+ return { kind: 'other', repo, bucket: 'else' }
113
187
  }
114
188
 
115
189
  /**
@@ -146,6 +220,11 @@ function fromStatus(status: number): RejectKind {
146
220
  export interface RequestMetric {
147
221
  kind: RequestKind
148
222
  repo: string
223
+ /**
224
+ * For kind `other`: which shape of unroutable path. Every other kind writes
225
+ * `''`, so the column exists on every row and a `GROUP BY` over it is honest.
226
+ */
227
+ bucket?: OtherBucket
149
228
  outcome: Outcome
150
229
  reject: RejectKind | ''
151
230
  status: number
@@ -188,6 +267,10 @@ export function toDataPoint(metric: RequestMetric): DataPoint {
188
267
  metric.repo,
189
268
  metric.cold ? 'cold' : 'warm',
190
269
  metric.served ? 'container' : 'edge',
270
+ // Seventh blob, added after a launch burst of unattributable 404s. A
271
+ // bucket name or `''` — never the path (see `otherBucket`). Appending
272
+ // rather than inserting is what keeps every existing query working.
273
+ metric.kind === 'other' ? (metric.bucket ?? 'else') : '',
191
274
  ],
192
275
  doubles: [
193
276
  metric.status,
@@ -208,6 +291,7 @@ export const BLOB_COLUMNS = [
208
291
  'repo',
209
292
  'temperature',
210
293
  'answered',
294
+ 'bucket',
211
295
  ] as const
212
296
  export const DOUBLE_COLUMNS = [
213
297
  'status',
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Binary assets the Worker bundles.
3
+ *
4
+ * `wrangler.jsonc`'s `rules` entry gives `**\/*.png` the `Data` loader, so the
5
+ * bundler turns an import of one into the file's bytes. Only `worker/` may
6
+ * reach a bundler like this — `shared/` is compiled by two programs and may
7
+ * import no runtime (docs/adr/0010), which is why `shared/og-image.ts` holds
8
+ * the route's decisions and none of its bytes.
9
+ */
10
+ declare module '*.png' {
11
+ const bytes: ArrayBuffer
12
+ export default bytes
13
+ }