@zabaca/zbc 0.12.0 → 0.13.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/CHANGELOG.md +63 -0
- package/package.json +2 -1
- package/templates/apps/inbox/package.json +1 -1
- package/templates/apps/walgit/CONTEXT.md +135 -0
- package/templates/apps/walgit/Dockerfile +40 -18
- package/templates/apps/walgit/README.md +518 -55
- package/templates/apps/walgit/e2e/README.md +100 -6
- package/templates/apps/walgit/e2e/harness.ts +262 -1
- package/templates/apps/walgit/e2e/live.ts +588 -0
- package/templates/apps/walgit/e2e/scenarios.ts +367 -5
- package/templates/apps/walgit/e2e/suite.ts +5 -5
- package/templates/apps/walgit/examples/watch.ts +209 -0
- package/templates/apps/walgit/package.json +12 -3
- package/templates/apps/walgit/registry.json +6 -11
- package/templates/apps/walgit/shared/capabilities.ts +189 -0
- package/templates/apps/walgit/shared/container-env.ts +114 -0
- package/templates/apps/walgit/shared/credentials.ts +81 -0
- package/templates/apps/walgit/shared/events.ts +277 -0
- package/templates/apps/walgit/shared/landing.ts +1241 -0
- package/templates/apps/walgit/shared/llms.ts +463 -0
- package/templates/apps/walgit/shared/outbox.ts +266 -0
- package/templates/apps/walgit/shared/policy.ts +59 -0
- package/templates/apps/walgit/shared/protocol.ts +197 -0
- package/templates/apps/walgit/shared/provenance.ts +154 -0
- package/templates/apps/walgit/shared/ref-cache.ts +181 -0
- package/templates/apps/walgit/shared/telemetry.ts +219 -0
- package/templates/apps/walgit/src/announce-main.ts +37 -0
- package/templates/apps/walgit/src/announce.ts +98 -0
- package/templates/apps/walgit/src/append-only.ts +112 -0
- package/templates/apps/walgit/src/cache.ts +172 -0
- package/templates/apps/walgit/src/cli.ts +493 -0
- package/templates/apps/walgit/src/compact.ts +25 -23
- package/templates/apps/walgit/src/delete-repo.ts +237 -0
- package/templates/apps/walgit/src/expire.ts +248 -0
- package/templates/apps/walgit/src/gc.ts +8 -16
- package/templates/apps/walgit/src/git-backend.ts +29 -0
- package/templates/apps/walgit/src/git.ts +78 -0
- package/templates/apps/walgit/src/hook-main.ts +259 -17
- package/templates/apps/walgit/src/hooks.ts +4 -3
- package/templates/apps/walgit/src/http.ts +237 -45
- package/templates/apps/walgit/src/instructions.ts +240 -0
- package/templates/apps/walgit/src/keys.ts +126 -0
- package/templates/apps/walgit/src/limits.ts +158 -0
- package/templates/apps/walgit/src/materialize.bench.ts +10 -10
- package/templates/apps/walgit/src/materialize.ts +48 -40
- package/templates/apps/walgit/src/mkdir-lock.ts +66 -0
- package/templates/apps/walgit/src/orphans.ts +2 -5
- package/templates/apps/walgit/src/pending.ts +201 -0
- package/templates/apps/walgit/src/push-cert.ts +254 -0
- package/templates/apps/walgit/src/push.ts +233 -46
- package/templates/apps/walgit/src/reconcile.ts +5 -8
- package/templates/apps/walgit/src/repo.ts +22 -77
- package/templates/apps/walgit/src/server.ts +148 -26
- package/templates/apps/walgit/src/signers.ts +577 -0
- package/templates/apps/walgit/src/store-env.ts +5 -4
- package/templates/apps/walgit/src/store.ts +47 -24
- package/templates/apps/walgit/src/usage.ts +404 -0
- package/templates/apps/walgit/src/verify.ts +171 -0
- package/templates/apps/walgit/src/wal-index.ts +189 -11
- package/templates/apps/walgit/tsconfig.json +8 -2
- package/templates/apps/walgit/tsconfig.worker.json +24 -0
- package/templates/apps/walgit/worker/events-do.ts +259 -0
- package/templates/apps/walgit/worker/index.ts +572 -0
- package/templates/apps/walgit/wrangler.jsonc +95 -0
- package/templates/apps/warehouse/package.json +1 -1
- package/templates/infra/modules/cloudflare/index.ts +77 -6
- package/templates/infra/modules/fly/index.ts +150 -10
- package/templates/infra/modules/turso/index.ts +43 -3
- package/templates/infra/package.json +1 -1
- package/templates/apps/walgit/entrypoint.sh +0 -59
- package/templates/apps/walgit/fly.toml +0 -52
- package/templates/apps/walgit/src/ssh-shell.ts +0 -36
- package/templates/apps/walgit/sshd_config +0 -38
|
@@ -1,50 +1,172 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
/**
|
|
3
|
-
* The smart-HTTP process
|
|
3
|
+
* The smart-HTTP process — the only front door, and the container's only
|
|
4
|
+
* process.
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* It serves the bare repos under WALGIT_REPOS_DIR and goes through src/repo.ts
|
|
7
|
+
* to decide which repo a request means. There used to be a second door (sshd
|
|
8
|
+
* running a forced command), which is what put walgit on a Fly machine with a
|
|
9
|
+
* dedicated IPv4: SSH needs raw inbound TCP. Dropping it is what let the app
|
|
10
|
+
* move onto a Cloudflare Container, where the Worker in worker/index.ts proxies
|
|
11
|
+
* straight to this port.
|
|
8
12
|
*/
|
|
9
13
|
|
|
10
|
-
import {
|
|
14
|
+
import { capabilitiesFrom } from '../shared/capabilities'
|
|
15
|
+
import { parseTokens } from '../shared/credentials'
|
|
16
|
+
import { ensureBareRepo } from './cache'
|
|
17
|
+
import { configuredExpiryMs, expireRepos } from './expire'
|
|
11
18
|
import { createHttpHandler } from './http'
|
|
12
19
|
import { runGitHttpBackend } from './git-backend'
|
|
20
|
+
import type { ObjectStore } from './store'
|
|
13
21
|
import { storeFromEnv } from './store-env'
|
|
14
22
|
import { syncRepo } from './sync'
|
|
23
|
+
import { loadIndex } from './wal-index'
|
|
15
24
|
|
|
16
25
|
const reposDir = process.env.WALGIT_REPOS_DIR ?? '/srv/walgit/repos'
|
|
17
26
|
const port = Number(process.env.PORT ?? 8080)
|
|
18
27
|
|
|
19
28
|
// Comma-separated so one deployment can rotate a credential without a window
|
|
20
|
-
// where neither the old nor the new token works.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
// where neither the old nor the new token works. Read through the same parser
|
|
30
|
+
// the Worker uses for the event stream's tokens: a credential accepted by one
|
|
31
|
+
// door and not the other would be indistinguishable, from the client, from a
|
|
32
|
+
// wrong token.
|
|
33
|
+
const tokens = parseTokens(process.env.WALGIT_HTTP_TOKENS)
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* What this deployment offers, and therefore what `GET /` is allowed to
|
|
37
|
+
* promise. One read of one derivation (`shared/capabilities.ts`), which
|
|
38
|
+
* `pre-receive` takes its caps from and the two edge documents state
|
|
39
|
+
* themselves from — so the page cannot state a rule the push path does not
|
|
40
|
+
* hold. Unset means unenforced, and unenforced limits are simply not
|
|
41
|
+
* mentioned.
|
|
42
|
+
*
|
|
43
|
+
* Read once at boot rather than per request, and that is a property rather
|
|
44
|
+
* than an oversight: a running process's environment is fixed, so re-reading
|
|
45
|
+
* would not make it fresher. The Worker's `reconcileEnv` is what replaces this
|
|
46
|
+
* container when a deploy changes a variable (shared/container-env.ts).
|
|
47
|
+
*/
|
|
48
|
+
const caps = capabilitiesFrom(process.env)
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Open to anyone, deliberately. This is the public service's whole shape: with
|
|
52
|
+
* writes open there is nothing a credential could prove, so demanding one only
|
|
53
|
+
* costs an agent a step. It is an explicit opt-in and NOT the absence of
|
|
54
|
+
* tokens — `createHttpHandler` refuses to serve when neither is configured, so
|
|
55
|
+
* a deployment that loses its secrets fails closed instead of opening to the
|
|
56
|
+
* world. Off unless set, so every existing deployment is unchanged.
|
|
57
|
+
*
|
|
58
|
+
* The GATE reads the same field `GET /` states it from, rather than its own
|
|
59
|
+
* `WALGIT_PUBLIC === '1'`. Those two spellings differed — `flagEnabled` takes
|
|
60
|
+
* `1` or `true` (docs/adr/0010), the gate took only `1` — so a deployment
|
|
61
|
+
* spelling it `true` had a front door demanding a credential under a page
|
|
62
|
+
* saying none was needed. Which spelling is right is settled by `flagEnabled`
|
|
63
|
+
* existing at all: it is there precisely so both halves read a boolean-ish
|
|
64
|
+
* variable the same way.
|
|
65
|
+
*/
|
|
66
|
+
const isPublic = caps.publicAccess
|
|
33
67
|
|
|
34
68
|
const store = storeFromEnv()
|
|
35
69
|
if (!store) {
|
|
36
70
|
// Warned, not fatal: reads still work off the local cache, and a push is
|
|
37
71
|
// refused by the hooks themselves rather than by guessing here.
|
|
38
|
-
console.error(
|
|
72
|
+
console.error(
|
|
73
|
+
'walgit: no object store configured — pushes will be REFUSED (see src/store-env.ts)',
|
|
74
|
+
)
|
|
39
75
|
}
|
|
40
76
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
77
|
+
/**
|
|
78
|
+
* The window, read once at boot from the same variable `GET /` renders its
|
|
79
|
+
* retention promise from — so the page and the sweeper can never disagree.
|
|
80
|
+
*/
|
|
81
|
+
const expiryMs = configuredExpiryMs()
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* What this process actually booted with, printed once.
|
|
85
|
+
*
|
|
86
|
+
* The policy above is read at boot, and that is correct for a process — but the
|
|
87
|
+
* variables come from the WORKER (worker/index.ts forwards them), and the
|
|
88
|
+
* Worker picks up a deploy the moment it lands while the container keeps the
|
|
89
|
+
* environment it started with until it is restarted. A deploy that only
|
|
90
|
+
* changes an env var therefore changes nothing in here, exits 0, and leaves the
|
|
91
|
+
* edge stating a policy this process does not enforce: on 2026-08-29 the
|
|
92
|
+
* landing page promised a 24-hour window while the container still had expiry
|
|
93
|
+
* off and answered 404 to every sweep.
|
|
94
|
+
*
|
|
95
|
+
* There is no way to make one deploy reach both halves at once from in here.
|
|
96
|
+
* What there is, is the difference between a drift that is visible and one that
|
|
97
|
+
* is not — so the process says what it believes on the way up, and `wrangler
|
|
98
|
+
* tail` answers "does the container agree with the page?" in one line instead
|
|
99
|
+
* of by inference from a missing paragraph.
|
|
100
|
+
*/
|
|
101
|
+
console.log(
|
|
102
|
+
`walgit boot: public=${isPublic} appendOnly=${caps.appendOnly} ` +
|
|
103
|
+
`retentionHours=${caps.retentionHours ?? 'off'} ` +
|
|
104
|
+
`maxPush=${caps.maxPushBytes ?? 'unset'} maxRepo=${caps.maxRepoBytes ?? 'unset'} ` +
|
|
105
|
+
`store=${store ? 'configured' : 'MISSING'}`,
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* One sweep, for real. `--yes` is the CLI's opt-in because a human at a
|
|
110
|
+
* terminal should have to ask; a scheduled sweep IS the asking, and a dry run
|
|
111
|
+
* on a timer would collect nothing forever while looking healthy.
|
|
112
|
+
*
|
|
113
|
+
* Logged as well as returned: the Worker's scheduled handler prints the report
|
|
114
|
+
* too, but this line is the one that survives in the container's own log when
|
|
115
|
+
* the question is what the sweeper actually did.
|
|
116
|
+
*/
|
|
117
|
+
async function runSweep(logStore: ObjectStore, windowMs: number) {
|
|
118
|
+
const result = await expireRepos(logStore, { windowMs, dryRun: false, reposDir })
|
|
119
|
+
console.log(
|
|
120
|
+
`walgit expire: collected ${result.collected.length}, retained ${result.retained.length}`,
|
|
121
|
+
)
|
|
122
|
+
return {
|
|
123
|
+
collected: result.collected.map((o) => ({ repoId: o.repoId, reason: o.decision.reason })),
|
|
124
|
+
retained: result.retained.length,
|
|
125
|
+
windowMs: result.windowMs,
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
let handler
|
|
130
|
+
try {
|
|
131
|
+
handler = createHttpHandler({
|
|
132
|
+
reposDir,
|
|
133
|
+
tokens,
|
|
134
|
+
public: isPublic,
|
|
135
|
+
ensureRepo: ensureBareRepo,
|
|
136
|
+
syncRepo: (repo) => syncRepo(store, repo),
|
|
137
|
+
runBackend: runGitHttpBackend,
|
|
138
|
+
capabilities: caps,
|
|
139
|
+
// Only when there is both a log to sweep and a window to sweep by. An
|
|
140
|
+
// instance with no retention configured has expiry off entirely, and the
|
|
141
|
+
// endpoint should not exist for it — `expireRepos` would return an empty
|
|
142
|
+
// report either way, but a deployment that cannot collect anything should
|
|
143
|
+
// not answer as though it might.
|
|
144
|
+
sweep: store && expiryMs !== null ? () => runSweep(store, expiryMs) : undefined,
|
|
145
|
+
// Answered from the Index, so a ref-event handshake states what is
|
|
146
|
+
// published rather than what this node's disk happens to hold. Absent
|
|
147
|
+
// without a store, in which case there is nothing authoritative to read
|
|
148
|
+
// and the endpoint should not exist.
|
|
149
|
+
readRefs: store ? async (repoId) => (await loadIndex(store, repoId)).index.refs : undefined,
|
|
150
|
+
// Who signed the pushes that put those refs where they are (docs/adr/0011),
|
|
151
|
+
// and which keys the repository's Signer List names (docs/adr/0012). Both
|
|
152
|
+
// absent when the Index has neither, which is every repository on a
|
|
153
|
+
// deployment where nobody signs and nobody claims — the fields are optional
|
|
154
|
+
// precisely so such an instance's index.json is unchanged, and this is
|
|
155
|
+
// where that costs the reader nothing: `?? {}` for the map, and a `claim`
|
|
156
|
+
// that stays undefined all the way out to a response that omits it.
|
|
157
|
+
readProvenance: store
|
|
158
|
+
? async (repoId) => {
|
|
159
|
+
const { index } = await loadIndex(store, repoId)
|
|
160
|
+
return { provenance: index.provenance ?? {}, claim: index.claim }
|
|
161
|
+
}
|
|
162
|
+
: undefined,
|
|
163
|
+
})
|
|
164
|
+
} catch (err) {
|
|
165
|
+
// Refusing to boot beats booting a half-configured git host — either an open
|
|
166
|
+
// one, or one that answers every request with a 401 nobody can satisfy.
|
|
167
|
+
console.error((err as Error).message)
|
|
168
|
+
process.exit(1)
|
|
169
|
+
}
|
|
48
170
|
|
|
49
171
|
Bun.serve({ port, idleTimeout: 0, fetch: handler })
|
|
50
172
|
console.log(`walgit smart-HTTP listening on :${port} (repos: ${reposDir})`)
|