@zabaca/zbc 0.22.0 → 0.23.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/CLAUDE.md +5 -0
- package/templates/apps/walgit/CONTEXT.md +5 -1
- package/templates/apps/walgit/README.md +159 -24
- package/templates/apps/walgit/package.json +2 -2
- package/templates/apps/walgit/registry.json +1 -1
- package/templates/apps/walgit/shared/browse.ts +18 -4
- package/templates/apps/walgit/shared/capabilities.ts +28 -3
- package/templates/apps/walgit/shared/container-env.ts +41 -2
- package/templates/apps/walgit/shared/container-lifecycle.ts +239 -0
- package/templates/apps/walgit/shared/container-snapshot.ts +219 -0
- package/templates/apps/walgit/shared/edge-refs.ts +612 -0
- package/templates/apps/walgit/{src → shared}/instructions.ts +8 -4
- package/templates/apps/walgit/shared/keys.ts +17 -0
- package/templates/apps/walgit/shared/landing.ts +10 -3
- package/templates/apps/walgit/shared/llms.ts +14 -5
- package/templates/apps/walgit/shared/policy.ts +1 -1
- package/templates/apps/walgit/shared/protocol.ts +35 -0
- package/templates/apps/walgit/shared/sleep-after.ts +44 -0
- package/templates/apps/walgit/shared/wal-index.ts +22 -1
- package/templates/apps/walgit/src/boot-residue.ts +58 -0
- package/templates/apps/walgit/src/cache.ts +9 -0
- package/templates/apps/walgit/src/cli.ts +39 -4
- package/templates/apps/walgit/src/delete-repo.ts +58 -9
- package/templates/apps/walgit/src/edge-refs.ts +148 -0
- package/templates/apps/walgit/src/expire.ts +75 -7
- package/templates/apps/walgit/src/hook-main.ts +2 -0
- package/templates/apps/walgit/src/http.ts +17 -4
- package/templates/apps/walgit/src/materialize.ts +34 -15
- package/templates/apps/walgit/src/push.ts +34 -8
- package/templates/apps/walgit/src/reconcile.ts +6 -1
- package/templates/apps/walgit/src/server.ts +69 -8
- package/templates/apps/walgit/src/sync.ts +10 -2
- package/templates/apps/walgit/worker/container-binding.ts +104 -0
- package/templates/apps/walgit/worker/durable-container.ts +786 -0
- package/templates/apps/walgit/worker/events-do.ts +16 -12
- package/templates/apps/walgit/worker/index.ts +235 -17
- package/templates/apps/walgit/worker/mcp.ts +9 -4
- package/templates/apps/walgit/wrangler.jsonc +44 -33
- package/templates/claude/settings.json +8 -0
- package/templates/infra/modules/cloudflare/index.ts +9 -0
- package/templates/infra/modules/d1/index.ts +30 -4
- package/templates/infra/modules/d1/registry.json +1 -1
package/package.json
CHANGED
package/templates/CLAUDE.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
This project uses [zbc](https://github.com/Zabaca/zbc) for infrastructure scaffolding.
|
|
4
4
|
|
|
5
|
+
The `zbc` Claude Code plugin teaches the rest: the `zbc` skill for operating
|
|
6
|
+
this project (instances, imports, secrets, apply/destroy), and `zbc-module` for
|
|
7
|
+
writing a module. `.claude/settings.json` enables it. To install it by hand, run
|
|
8
|
+
`/plugin marketplace add Zabaca/zbc` and then `/plugin install zbc@zbc`.
|
|
9
|
+
|
|
5
10
|
## Layout
|
|
6
11
|
|
|
7
12
|
- `packages/infra/` — infrastructure code (zbc modules)
|
|
@@ -27,11 +27,15 @@ One packfile published to the log, by one push or by one compaction, identified
|
|
|
27
27
|
The bare git repo on local disk. Disposable by definition: it can be deleted at any moment and rebuilt from the log, it is reconciled against the Index on every access, and nothing may be served from it that the log has not confirmed. Provisioned by `cache.ts`; git's own housekeeping is disabled on it, because a cache that repacks itself behind the log's back is a cache that disagrees with it.
|
|
28
28
|
_Avoid_: the repo (ambiguous with the repository the log describes), the replica, local state
|
|
29
29
|
|
|
30
|
+
**Snapshot**:
|
|
31
|
+
A point-in-time copy of the container's root filesystem — and so of every Cache on it — taken on the way to the idle stop and restored by the next start, when `WALGIT_SNAPSHOTS` is on (`shared/container-snapshot.ts`). Not a backup and not a second source of truth: a restored disk is a Cache like any other, reconciled against the Index on first access, so a Snapshot can only change how much a wake re-syncs, never what it serves. Tied to the image it was taken from and never restored onto another.
|
|
32
|
+
_Avoid_: backup, volume, persistent disk — each implies the disk is authoritative
|
|
33
|
+
|
|
30
34
|
**Reconcile**:
|
|
31
35
|
Force the Cache's refs to match the Index. Always one-directional — whatever the disk believes is discarded — and written as a single `packed-refs` file. A ref whose object is absent is reported rather than written: a stale clone is survivable, a broken one is not.
|
|
32
36
|
|
|
33
37
|
**Materialize** (walgit sense):
|
|
34
|
-
Rebuild a Cache from the Write-Ahead Log: download every WAL Entry above the Compaction Frontier, place its pack, then Reconcile. The container sleeps when idle and its disk is wiped on restart, so this is the normal path on ordinary first access after an idle pause, not disaster recovery.
|
|
38
|
+
Rebuild a Cache from the Write-Ahead Log: download every WAL Entry above the Compaction Frontier, place its pack, then Reconcile. The container sleeps when idle and its disk is wiped on restart unless a Snapshot is restored, so this is the normal path on ordinary first access after an idle pause, not disaster recovery.
|
|
35
39
|
_Disambiguate_: the zbc repository's warehouse uses the same word for a `dlt` extract plus `dbt run`. The two are unrelated; a bare "materialize" is ambiguous across that repo.
|
|
36
40
|
|
|
37
41
|
**Compaction**:
|
|
@@ -58,7 +58,7 @@ by layer:
|
|
|
58
58
|
| `src/signers.ts` | the Signer List a repository holds, resolved in `pre-receive` beside the size caps and re-asked at the publish |
|
|
59
59
|
| `src/private.ts`, `src/ssh-signature.ts` | the Reader List and the Read Challenge: who may read a Private repository, and the nonce-and-signature that proves it |
|
|
60
60
|
| `src/usage.ts` | what the log says this service holds, folded out of the indexes |
|
|
61
|
-
| `
|
|
61
|
+
| `shared/instructions.ts` | the plain-text `GET /` — the whole API surface, rendered from the limits actually enforced |
|
|
62
62
|
| `src/verify.ts`, `src/cli.ts` | the operator CLI: inspect, rebuild, verify, reclaim |
|
|
63
63
|
| `src/git.ts`, `src/mkdir-lock.ts` | the two shared primitives: running a git plumbing command, and locking with `mkdir` |
|
|
64
64
|
|
|
@@ -239,9 +239,11 @@ seq order, drops each `.pack`/`.idx` pair straight into `objects/pack/`, and
|
|
|
239
239
|
writes `packed-refs` from `index.json.refs` in one shot.
|
|
240
240
|
|
|
241
241
|
**It is not disaster recovery — it is the normal path.** The container sleeps
|
|
242
|
-
when idle and its disk is wiped completely on
|
|
243
|
-
loses its cache routinely and the next access
|
|
244
|
-
therefore exercised continuously rather than
|
|
242
|
+
when idle and, unless `WALGIT_SNAPSHOTS` is on, its disk is wiped completely on
|
|
243
|
+
every restart, so an idle repo loses its cache routinely and the next access
|
|
244
|
+
rebuilds it. The restore path is therefore exercised continuously rather than
|
|
245
|
+
only in a crisis — and with snapshots on it still runs, for whatever the
|
|
246
|
+
restored disk is missing; it simply has less to do.
|
|
245
247
|
|
|
246
248
|
`src/sync.ts` decides which of the two repairs an access needs, and a warm disk
|
|
247
249
|
pays for neither:
|
|
@@ -398,14 +400,34 @@ is not "long ago", and one in the future is clock skew rather than staleness.
|
|
|
398
400
|
Over-retaining costs storage; under-retaining deletes somebody's work with no
|
|
399
401
|
error anywhere.
|
|
400
402
|
|
|
403
|
+
A **claimed** repository — one with a Signer List — can be given a longer
|
|
404
|
+
window: `WALGIT_CLAIMED_RETENTION_HOURS`. It applies only where names can be
|
|
405
|
+
claimed (`WALGIT_SIGNER_LISTS` and `WALGIT_PUSH_CERT_SEED`), only with
|
|
406
|
+
`WALGIT_RETENTION_HOURS` set, and only when it is longer than that window;
|
|
407
|
+
otherwise it is read as unset. It is a capability like the base window, so
|
|
408
|
+
`GET /`, `/llms.txt`, the landing page and the browse pages state it from the
|
|
409
|
+
same reading the sweeper collects by. `walgit expire --claimed-after <hours>`
|
|
410
|
+
overrides it.
|
|
411
|
+
|
|
401
412
|
Collection is delegated to `delete-repo.ts`, so an expired repository is
|
|
402
413
|
tombstoned and collected a grace period later exactly like one deleted by hand.
|
|
403
414
|
Dry run is the default; `--yes` acts.
|
|
404
415
|
|
|
416
|
+
A push lifts expiry's tombstone — it was written because nobody pushed, and
|
|
417
|
+
somebody just did — so a push inside the grace period is kept, not acknowledged
|
|
418
|
+
and then collected. An operator's tombstone (`walgit delete`) stays. Both ends
|
|
419
|
+
of that window are compare-and-swaps on `index.json`: the tombstone is
|
|
420
|
+
re-judged on the Index it lands on, and the collection marks the Index
|
|
421
|
+
`collecting_at` before deleting anything, after which a push is refused with
|
|
422
|
+
"this repository is being deleted".
|
|
423
|
+
|
|
405
424
|
What runs it on a timer is the **deployment's** business. On Cloudflare that is
|
|
406
|
-
|
|
407
|
-
`scheduled` handler, which POSTs `/_walgit/expire` to the container and
|
|
408
|
-
report. The
|
|
425
|
+
two daily Cron Triggers (`wrangler.jsonc` → `triggers.crons`) firing the
|
|
426
|
+
Worker's `scheduled` handler, which POSTs `/_walgit/expire` to the container and
|
|
427
|
+
logs the report. The 04:00 sweep tombstones what has gone idle; the 05:15 one
|
|
428
|
+
(`?collect=only`, `walgit expire --collect-only`) collects what the first
|
|
429
|
+
tombstoned, a grace period later, and tombstones nothing itself. With one daily
|
|
430
|
+
sweep a tombstoned repository waited a whole day for the next. The timer lives out there rather than as an interval inside the
|
|
409
431
|
container because the container SLEEPS when idle — an internal timer would stop
|
|
410
432
|
firing at exactly the moment nothing is keeping it awake, which is precisely the
|
|
411
433
|
state a repository has to be in to be collectable.
|
|
@@ -437,6 +459,25 @@ A repository is created on first contact: pushing to a name nobody has used
|
|
|
437
459
|
creates it, with `receive.unpackLimit=0` so even a tiny push is retained as a
|
|
438
460
|
packfile (what the WAL will upload).
|
|
439
461
|
|
|
462
|
+
### Ref checks at the edge
|
|
463
|
+
|
|
464
|
+
An agent polling a ref (`git ls-remote`) sends a protocol-v2 `info/refs` and
|
|
465
|
+
then `command=ls-refs`. On a public deployment the Worker answers both itself,
|
|
466
|
+
off `index.json`, without waking the container (`shared/edge-refs.ts`) — the
|
|
467
|
+
bytes are those the container's git would send: the advertisement and the
|
|
468
|
+
headers are the container's own, published to the store at boot under
|
|
469
|
+
`walgit/upload-pack-v2/<env fingerprint>.json` (`src/edge-refs.ts`), and the
|
|
470
|
+
refs and `HEAD` come from the Index, with `HEAD` on the Default Branch on both
|
|
471
|
+
sides (`ensureHead` now asserts it on every access). Everything else is
|
|
472
|
+
forwarded unchanged: a v0/v1 client, a fetch, a token-gated deployment, a
|
|
473
|
+
Private name, an empty one, `peel` where a non-branch ref is listed, and any
|
|
474
|
+
request shape not shown equivalent in `src/edge-refs.test.ts`.
|
|
475
|
+
|
|
476
|
+
It needs `WALGIT_BUILD_ID` (the `cloudflare` module's `deployIdVar`). Without a
|
|
477
|
+
deploy id an image-only deploy keeps the environment fingerprint, and the edge
|
|
478
|
+
could serve one git's advertisement in front of another — so it answers
|
|
479
|
+
nothing and every ref check reaches the container, as before.
|
|
480
|
+
|
|
440
481
|
### The MCP endpoint
|
|
441
482
|
|
|
442
483
|
`/_walgit/mcp` is a Model Context Protocol server over Streamable HTTP
|
|
@@ -625,12 +666,95 @@ only its bare browse URL.
|
|
|
625
666
|
## Deployment
|
|
626
667
|
|
|
627
668
|
Through the `cloudflare` module, never by hand — `zbc apply <env>`. The Worker
|
|
628
|
-
(`worker/index.ts`) is a thin proxy in front of a
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
669
|
+
(`worker/index.ts`) is a thin proxy in front of a Container running this
|
|
670
|
+
package's Dockerfile under the **`durable_object` scheduling policy**: the
|
|
671
|
+
Durable Object `WalgitDurableContainer` (`worker/durable-container.ts`) starts,
|
|
672
|
+
proxies to, snapshots and stops it through `ctx.container` directly — once
|
|
673
|
+
`WALGIT_CONTAINER_POLICY=durable_object` routes to it. Unset, the Worker still
|
|
674
|
+
routes to the `default`-policy `WalgitContainer`; the move between the two is
|
|
675
|
+
below. `wrangler
|
|
676
|
+
deploy` builds the image, so Docker must be running at apply time, the account
|
|
677
|
+
must be on a Workers Paid plan with Containers enabled, and wrangler must be
|
|
678
|
+
4.147 or later (the policy is not in the schema of older ones).
|
|
679
|
+
|
|
680
|
+
There are **no container rollouts** under this policy, so
|
|
681
|
+
`immediateContainerRollout` does nothing for this container. A deploy that
|
|
682
|
+
builds a new image changes only the digest-pinned reference
|
|
683
|
+
`ctx.container.images.walgit` returns, and the Durable Object folds that
|
|
684
|
+
reference into the fingerprint it already keeps for the environment
|
|
685
|
+
(`bootFingerprint`, below) — so a new image, like a changed variable, replaces
|
|
686
|
+
the running container on the first request after the deploy.
|
|
687
|
+
|
|
688
|
+
**Lifecycle.** The first request after a sleep starts the container — from the
|
|
689
|
+
last snapshot when snapshots are on and it qualifies, from the image otherwise
|
|
690
|
+
— at `standard-1` (`CONTAINER_INSTANCE`, `shared/container-lifecycle.ts`, says
|
|
691
|
+
why that size), and waits for `/_walgit/health` on port 8080 to answer before
|
|
692
|
+
proxying. One start per request, inside 15 s: a start that fails, fails that
|
|
693
|
+
request in seconds and the next request tries again. Its response
|
|
694
|
+
is stamped cold for the telemetry. A bodiless read that lands on a container
|
|
695
|
+
that just exited is retried once. `WALGIT_SLEEP_AFTER` after the last request
|
|
696
|
+
**finished** — never while a clone streams or a push uploads — an alarm wakes
|
|
697
|
+
the object, snapshots the disk, SIGTERMs the process (which drains and exits)
|
|
698
|
+
and kills it after 15 s if it has not. With the container stopped the object
|
|
699
|
+
holds no alarm and nothing else keeps it awake.
|
|
700
|
+
|
|
701
|
+
**Snapshots** (`WALGIT_SNAPSHOTS=1`, off unless set, edge-only). The idle stop
|
|
702
|
+
snapshots the container's root filesystem, and the next start restores it, so a
|
|
703
|
+
wake re-syncs the Cache against the log instead of rebuilding every repository
|
|
704
|
+
it serves from nothing — the larger half of a cold start. Safe because the
|
|
705
|
+
Cache is reconciled against `index.json` on every access: a restored disk can
|
|
706
|
+
be any amount behind and only costs a bigger first sync, never a stale ref. A
|
|
707
|
+
snapshot is restored only if it was taken from the image this deploy starts,
|
|
708
|
+
against this deployment's log, within the platform's 30-day retention and under
|
|
709
|
+
4 GB; anything else, or a restore that does not come up, is a fresh start. The
|
|
710
|
+
process clears the per-process residue a restored disk can carry — a dead
|
|
711
|
+
push's hand-off record, a materialize lock — before it opens its port
|
|
712
|
+
(`src/boot-residue.ts`). Snapshots are a public-beta platform feature; turning
|
|
713
|
+
the variable off restarts nothing and makes every start cold again.
|
|
714
|
+
|
|
715
|
+
**Moving an existing deployment onto this policy.** A container application's
|
|
716
|
+
scheduling policy cannot be changed, so the `durable_object` application is a
|
|
717
|
+
new one beside the `default`-policy one `WalgitContainer` runs in, and
|
|
718
|
+
`wrangler.jsonc` carries both, each behind its own binding (`WALGIT_CONTAINER`,
|
|
719
|
+
`WALGIT_DURABLE_CONTAINER`). `WALGIT_CONTAINER_POLICY` picks which one the
|
|
720
|
+
Worker routes to; unset is the old one. It takes three phases, because
|
|
721
|
+
`wrangler deploy` puts the new Worker live **before** it creates the new
|
|
722
|
+
container application — after rolling the old one, so a rollout that throws
|
|
723
|
+
leaves the new application uncreated — and a Worker that routed to it in that
|
|
724
|
+
gap would fail every git request.
|
|
725
|
+
|
|
726
|
+
1. **Phase 1 — create it, route nothing to it.** Deploy this package with
|
|
727
|
+
`WALGIT_CONTAINER_POLICY` unset: the `v3` migration, the
|
|
728
|
+
`WalgitDurableContainer` class and binding, and the `durable_object`
|
|
729
|
+
container entry arrive, and traffic stays on `WalgitContainer`. Then confirm
|
|
730
|
+
the application exists: `wrangler containers list` shows a `durable_object`
|
|
731
|
+
application for `WalgitDurableContainer`. If it does not (the deploy failed
|
|
732
|
+
after the Worker went live), run the deploy again — nothing routes to it yet,
|
|
733
|
+
so nothing is broken in the meantime.
|
|
734
|
+
2. **Phase 2 — move the traffic.** Add
|
|
735
|
+
`{ name: 'WALGIT_CONTAINER_POLICY', value: 'durable_object' }` to the
|
|
736
|
+
instance's `workerVars` and deploy. The next request starts a container in
|
|
737
|
+
the new application; the old instance idles out on its own. **Rolling back**
|
|
738
|
+
is the same deploy with that var removed — a forward deploy. `wrangler
|
|
739
|
+
rollback` will not do it: it refuses to cross the `v3` migration, and the
|
|
740
|
+
migration and the class stay whichever way traffic points.
|
|
741
|
+
3. **Phase 3 — retire the old application**, once no rollback will be wanted. This
|
|
742
|
+
template ships already past it (agentgit.co did all three on 2026-10-03), so a
|
|
743
|
+
deployment still on `WalgitContainer` takes phases 1 and 2 from the release that
|
|
744
|
+
carried both bindings before taking this one. For the record, phase 3 was:
|
|
745
|
+
delete the `WalgitContainer` entry from `containers` and the
|
|
746
|
+
`WALGIT_CONTAINER` binding from `wrangler.jsonc`, drop
|
|
747
|
+
`immediateContainerRollout` from the instance, and deploy (keep
|
|
748
|
+
`WALGIT_CONTAINER_POLICY` set — with no old binding, an unset switch has
|
|
749
|
+
nothing to route to). Then `wrangler containers list`, find
|
|
750
|
+
`walgit-walgitcontainer`, and `wrangler containers delete <id>` — removing the
|
|
751
|
+
entry does **not** delete the application or its instances. Later still,
|
|
752
|
+
delete the `WalgitContainer` class (and `@cloudflare/containers` with it) and
|
|
753
|
+
add a `{ "tag": "v4", "deleted_classes": ["WalgitContainer"] }` migration,
|
|
754
|
+
which deletes the old namespace's storage — only a fingerprint.
|
|
755
|
+
|
|
756
|
+
Until phase 3, both `containers` entries build `./Dockerfile`, so every deploy
|
|
757
|
+
builds and pushes the image twice.
|
|
634
758
|
|
|
635
759
|
The container reads its configuration from environment variables the **Worker**
|
|
636
760
|
forwards (`CONTAINER_ENV` in `shared/container-env.ts`): `wrangler secret put`
|
|
@@ -639,11 +763,10 @@ arrives.
|
|
|
639
763
|
|
|
640
764
|
It reads them **once, at container start** — a running process's environment
|
|
641
765
|
cannot be changed, so re-reading `process.env` per request would return the same
|
|
642
|
-
value.
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
(`reconcileEnv`). Changing a forwarded variable therefore costs one container
|
|
766
|
+
value. So the Durable Object fingerprints the environment it would boot with,
|
|
767
|
+
together with the image reference, keeps that fingerprint in its own storage,
|
|
768
|
+
and destroys the running container the first time the two differ
|
|
769
|
+
(`reconcileEnv`, `bootFingerprint`). Changing a forwarded variable therefore costs one container
|
|
647
770
|
restart on the first request after the deploy, and takes effect immediately —
|
|
648
771
|
where previously the Worker picked it up and the container kept the old value
|
|
649
772
|
for as long as traffic kept it awake.
|
|
@@ -663,7 +786,7 @@ Optional instance configuration (plain env, not secrets): `WALGIT_APPEND_ONLY`,
|
|
|
663
786
|
`WALGIT_MAX_PUSH_BYTES`, `WALGIT_MAX_REPO_BYTES`,
|
|
664
787
|
`WALGIT_MAX_NEW_REPOS_PER_SOURCE`, `WALGIT_MAX_PUSHES_PER_SOURCE`,
|
|
665
788
|
`WALGIT_MAX_PUSH_BYTES_PER_SOURCE`, `WALGIT_RATE_WINDOW_SECONDS`,
|
|
666
|
-
`WALGIT_RETENTION_HOURS`,
|
|
789
|
+
`WALGIT_RETENTION_HOURS`, `WALGIT_CLAIMED_RETENTION_HOURS`,
|
|
667
790
|
`WALGIT_PUBLIC`, `WALGIT_SIGNER_LISTS`, `WALGIT_WEB` (the web view above) —
|
|
668
791
|
each unset means the behaviour is off
|
|
669
792
|
and `GET /` does not claim it. `WALGIT_EVENTS_URL` and `WALGIT_EVENTS_TOKEN` (a
|
|
@@ -694,6 +817,14 @@ snippet creates no profile for an anonymous reader; session replay follows
|
|
|
694
817
|
the PostHog project's own setting. Unset, the page carries no script at all (`analyticsFrom`,
|
|
695
818
|
`shared/analytics.ts`).
|
|
696
819
|
|
|
820
|
+
`WALGIT_SLEEP_AFTER` is how long the container idles before it stops — `20m`
|
|
821
|
+
unless set, as a number and one unit (`90s`, `5m`, `1h`; anything else is
|
|
822
|
+
ignored). Every request that reaches the container buys that much container
|
|
823
|
+
time, so on a quiet deployment it is most of the bill; shorter trades that for
|
|
824
|
+
cold starts, which `WALGIT_SNAPSHOTS` makes cheaper. The Durable Object in front
|
|
825
|
+
of it sleeps in between and wakes once to stop it. Edge-only, so changing it
|
|
826
|
+
restarts nothing (`shared/sleep-after.ts`).
|
|
827
|
+
|
|
697
828
|
For the three boolean flags — `WALGIT_APPEND_ONLY`, `WALGIT_PUBLIC` and
|
|
698
829
|
`WALGIT_SIGNER_LISTS` — **on means `1` or `true`, and nothing else**
|
|
699
830
|
(`flagEnabled`, `shared/policy.ts`). An unrecognised value (`yes`, `on`, `TRUE`)
|
|
@@ -767,14 +898,18 @@ because the name stopped being the secret when ownership landed — and the body
|
|
|
767
898
|
names the helper and the by-hand exchange.
|
|
768
899
|
|
|
769
900
|
The container sleeps when idle and the next request wakes it — one regime,
|
|
770
|
-
median 1.77 s, spread 0.93–6.45 s, and a ten-minute idle measures the same
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
901
|
+
median 1.77 s, spread 0.93–6.45 s, and a ten-minute idle measures the same
|
|
902
|
+
(measured under the `default` scheduling policy; Cloudflare reports the
|
|
903
|
+
`durable_object` policy walgit now runs under as roughly six times faster, not
|
|
904
|
+
yet measured here). Its disk is **wiped completely on every restart** unless a
|
|
905
|
+
snapshot is restored, which is exactly the assumption the cache-and-log design
|
|
906
|
+
was written against, so there is no volume and nothing to mount — and a
|
|
907
|
+
snapshot changes how much a wake re-syncs, never whether it does.
|
|
774
908
|
|
|
775
909
|
Trap worth knowing when tearing one down: `wrangler delete` on the Worker does
|
|
776
910
|
**not** delete its container application. That needs a separate
|
|
777
|
-
`wrangler containers delete`, or the instances stay live.
|
|
911
|
+
`wrangler containers delete`, or the instances stay live. A deployment that
|
|
912
|
+
moved policies has two (see Deployment).
|
|
778
913
|
|
|
779
914
|
## Append-only refs
|
|
780
915
|
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@cloudflare/containers": "^0.3.7",
|
|
29
|
-
"@cloudflare/workers-types": "^
|
|
29
|
+
"@cloudflare/workers-types": "^5.20261003.1",
|
|
30
30
|
"@types/bun": "^1.3.14",
|
|
31
31
|
"typescript": "^7.0.2",
|
|
32
|
-
"wrangler": "^4.
|
|
32
|
+
"wrangler": "^4.147.0"
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -17,5 +17,5 @@
|
|
|
17
17
|
],
|
|
18
18
|
"signupUrl": "https://dash.cloudflare.com/sign-up",
|
|
19
19
|
"tokenUrl": "https://dash.cloudflare.com/profile/api-tokens",
|
|
20
|
-
"instructions": "STATUS: the front door and the push path are deployable — a Cloudflare Worker proxying to a Durable-Object-bound Container that serves git smart-HTTP, with every push persisted to the write-ahead log in object storage before it is acknowledged and linearized by compare-and-swap on index.json. The bare repos on the container's filesystem are a cache, reconciled against the log on every access and materialized from it when the objects a ref needs are absent. A repo whose cache is gone is rebuilt from the log on first access — not disaster recovery but the normal path, since the container sleeps when idle and its disk is wiped completely on every restart. The log is compacted in the background: once a repo accumulates WALGIT_COMPACTION_THRESHOLD (default 50) un-superseded entries, a post-receive hook hands a detached process a `git repack -adf` whose single pack is published as one WAL entry under a per-repo lease, so a cold restore replays one entry however many pushes the repo has taken. Superseded entries and the packs rejected pushes leave behind are deleted only after WALGIT_GC_GRACE_MS (default one hour), never immediately — a restore that read index.json a moment before a compaction is still downloading what that compaction superseded, and deleting it out from under that restore fails silently. Both knobs are optional environment variables, not secrets.\n\nTRANSPORT: smart-HTTP only. walgit used to also serve SSH, which needed raw inbound TCP and is why it ran on Fly (docs/adr/0006 in the zbc repository); no Cloudflare product delivers raw inbound TCP, so the SSH transport was removed rather than kept on a second host. Clients send the token as the Basic-auth password: `git clone https://walgit:$TOKEN@<worker-host>/myrepo.git`. A repository is created on first push to a name nobody has used.\n\nDEPLOYMENT: through the `cloudflare` module. `wrangler deploy` builds the container image from this package's Dockerfile, so Docker must be running at apply time and the account must be on a Workers Paid plan with Containers enabled.
|
|
20
|
+
"instructions": "STATUS: the front door and the push path are deployable — a Cloudflare Worker proxying to a Durable-Object-bound Container that serves git smart-HTTP, with every push persisted to the write-ahead log in object storage before it is acknowledged and linearized by compare-and-swap on index.json. The bare repos on the container's filesystem are a cache, reconciled against the log on every access and materialized from it when the objects a ref needs are absent. A repo whose cache is gone is rebuilt from the log on first access — not disaster recovery but the normal path, since the container sleeps when idle and its disk is wiped completely on every restart unless WALGIT_SNAPSHOTS restores a snapshot of it. The log is compacted in the background: once a repo accumulates WALGIT_COMPACTION_THRESHOLD (default 50) un-superseded entries, a post-receive hook hands a detached process a `git repack -adf` whose single pack is published as one WAL entry under a per-repo lease, so a cold restore replays one entry however many pushes the repo has taken. Superseded entries and the packs rejected pushes leave behind are deleted only after WALGIT_GC_GRACE_MS (default one hour), never immediately — a restore that read index.json a moment before a compaction is still downloading what that compaction superseded, and deleting it out from under that restore fails silently. Both knobs are optional environment variables, not secrets.\n\nTRANSPORT: smart-HTTP only. walgit used to also serve SSH, which needed raw inbound TCP and is why it ran on Fly (docs/adr/0006 in the zbc repository); no Cloudflare product delivers raw inbound TCP, so the SSH transport was removed rather than kept on a second host. Clients send the token as the Basic-auth password: `git clone https://walgit:$TOKEN@<worker-host>/myrepo.git`. A repository is created on first push to a name nobody has used.\n\nDEPLOYMENT: through the `cloudflare` module. `wrangler deploy` builds the container image from this package's Dockerfile, so Docker must be running at apply time and the account must be on a Workers Paid plan with Containers enabled. The container runs under the `durable_object` scheduling policy (wrangler 4.147 or later): the Durable Object WalgitDurableContainer (worker/durable-container.ts) starts it, waits for its port, proxies to it, and stops it WALGIT_SLEEP_AFTER after the last request finished. There are no container rollouts under this policy, so `immediateContainerRollout` does nothing for it; the container reads its environment once at start, and the Durable Object fingerprints the environment AND the image reference it would boot with, keeps that in DO storage, and destroys the running container the first time the two differ (reconcileEnv). A changed var or a new image therefore costs one container restart on the next request and takes effect immediately. WALGIT_SNAPSHOTS=1 (edge-only, off by default — the platform feature is in public beta) snapshots the disk on the idle stop and restores it on the next start, so a wake re-syncs the cache instead of rebuilding it. The Worker routes to it only when WALGIT_CONTAINER_POLICY=durable_object; unset, it routes to the `default`-policy WalgitContainer, because `wrangler deploy` makes the Worker live before it creates the new container application. Moving a deployment is three phases (create, then switch, then retire the old application) and rolling back is a forward deploy unsetting the variable, never `wrangler rollback`: README.md \"Deployment\". CLOUDFLARE_API_TOKEN needs Workers Scripts: Edit and Containers: Edit. Trap when tearing one down: `wrangler delete` on the Worker does NOT delete its container application — that needs a separate `wrangler containers delete`, or the instances stay live.\n\nCONFIGURATION: the container runs outside the Worker's binding graph, so it reads the store over the S3 API rather than through an r2 binding, and it can only be told about it via environment variables the Worker forwards (CONTAINER_ENV in shared/container-env.ts). Wire these as the cloudflare instance's `workerSecrets`: WALGIT_HTTP_TOKENS (comma-separated bearer tokens, comma-separated so a credential can be rotated without a window where neither works), and the log's home — WALGIT_S3_ENDPOINT, WALGIT_S3_BUCKET, WALGIT_S3_ACCESS_KEY_ID and WALGIT_S3_SECRET_ACCESS_KEY, from an r2 module instance's S3-API credentials. Without those four the host still serves reads from its local cache but REFUSES every push — accepting one it cannot persist is the single failure this app exists to prevent. A secret that is not in that forward list reaches the Worker and stops there.\n\nOPERATOR CLI: src/cli.ts — `bun src/cli.ts <serve|materialize|verify|gc|compact>`, run inside the container so it reads the same credentials the app does; there is no separate config file. `verify` is read-only and exits non-zero when the disk disagrees with index.json; `gc` reclaims superseded and orphaned objects and only reports unless given --yes; `compact` forces a compaction now rather than waiting for the threshold, and `--force=false` asks whether one is due without causing it.\n\nREF EVENTS: optional, off unless configured. Set WALGIT_EVENTS_URL (the deployment's own public origin) and WALGIT_EVENTS_TOKEN (a shared secret, wired as a workerSecret and forwarded to the container) and walgit serves a WebSocket at /_walgit/events: a client sends {\"watch\":[{\"repo\":\"my-thing\",\"refs\":[\"refs/heads/main\"]}]}, is answered with the current sha of each watched ref, and is then sent the new sha every time one moves (sha null is a deletion; an omitted refs list watches every ref in that repository). Subscribing takes exactly the credential a read takes, so a public deployment has a public stream. Events are latest state, not a log — no cursor, no since, no sequence number on the wire; a reconnecting client gets current state in its handshake. The push path announces from post-receive, which git runs only after the compare-and-swap on index.json won, so a push that lost is never announced; the announcement is authenticated, bounded, and can never fail a push. With either variable unset the endpoint does not exist.\n\nMCP: the deployment answers the Model Context Protocol at /_walgit/mcp (Streamable HTTP), at the edge and on every deployment — there is no variable to set and nothing to install. `claude mcp add --transport http agentgit https://<host>/_walgit/mcp`. It carries only what the host can answer without the caller's disk: agentgit_status (does a name exist, is it claimed, is it private, and its refs), agentgit_watch (blocks until a ref moves, five minutes per call), agentgit_provenance (which key signed the push that moved a ref), and the /llms.txt manual as the resource agentgit://manual. agentgit_status and agentgit_provenance read through the same gate a clone passes, so a Private name refuses an unproven reader exactly as info/refs does; agentgit_watch needs the ref-event stream above and says so where it is unconfigured."
|
|
21
21
|
}
|
|
@@ -74,6 +74,12 @@ export interface BrowseRefsAnswer {
|
|
|
74
74
|
refs: BrowseRef[]
|
|
75
75
|
/** ISO instant of the newest push entry, or `null` when there is none. */
|
|
76
76
|
lastPush: string | null
|
|
77
|
+
/**
|
|
78
|
+
* The repository has a Signer List. Optional because the edge and the
|
|
79
|
+
* container deploy apart: a container older than the field answers without
|
|
80
|
+
* it, and the page then states the unclaimed window — the shorter one.
|
|
81
|
+
*/
|
|
82
|
+
claimed?: boolean
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
/** What `op=tree` answers: the same, plus one level of one directory. */
|
|
@@ -396,11 +402,17 @@ export async function browseResponse(
|
|
|
396
402
|
* the sweeper does not honour. Rounded UP, because "expires in 0 hours" on a
|
|
397
403
|
* repository that has 50 minutes left reads as gone.
|
|
398
404
|
*/
|
|
399
|
-
export function expiresIn(
|
|
405
|
+
export function expiresIn(
|
|
406
|
+
lastPush: string | null,
|
|
407
|
+
caps: Capabilities,
|
|
408
|
+
now: number,
|
|
409
|
+
claimed = false,
|
|
410
|
+
): string | null {
|
|
400
411
|
if (caps.retentionHours === null || lastPush === null) return null
|
|
401
412
|
const at = Date.parse(lastPush)
|
|
402
413
|
if (!Number.isFinite(at)) return null
|
|
403
|
-
const
|
|
414
|
+
const hours = (claimed ? caps.claimedRetentionHours : null) ?? caps.retentionHours
|
|
415
|
+
const left = Math.ceil((at + hours * 3_600_000 - now) / 3_600_000)
|
|
404
416
|
return left <= 0 ? 'expires at any moment' : `expires in ${describeHours(left)}`
|
|
405
417
|
}
|
|
406
418
|
|
|
@@ -467,7 +479,9 @@ function entryRow(repo: string, ref: string, path: string, entry: TreeEntry): st
|
|
|
467
479
|
}
|
|
468
480
|
|
|
469
481
|
/** What every page's chrome needs: the repository, the ref and the ref list. */
|
|
470
|
-
type PageCommon = Pick<BrowseRefsAnswer, 'repo' | 'refs' | 'lastPush'> & {
|
|
482
|
+
type PageCommon = Pick<BrowseRefsAnswer, 'repo' | 'refs' | 'lastPush' | 'claimed'> & {
|
|
483
|
+
ref?: string
|
|
484
|
+
}
|
|
471
485
|
|
|
472
486
|
function refList(answer: PageCommon): string {
|
|
473
487
|
if (answer.refs.length === 0) return ''
|
|
@@ -509,7 +523,7 @@ function breadcrumb(answer: PageCommon & { path?: string }, leaf?: string): stri
|
|
|
509
523
|
* The retention line every page carries, in the landing page's own words.
|
|
510
524
|
*/
|
|
511
525
|
function fineprint(answer: PageCommon, caps: Capabilities, now: number): string {
|
|
512
|
-
const expiry = expiresIn(answer.lastPush, caps, now)
|
|
526
|
+
const expiry = expiresIn(answer.lastPush, caps, now, answer.claimed === true)
|
|
513
527
|
return [
|
|
514
528
|
answer.lastPush === null ? '' : `last push ${escapeHtml(answer.lastPush.slice(0, 10))}`,
|
|
515
529
|
expiry === null ? '' : escapeHtml(expiry),
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* What this deployment advertises, derived once.
|
|
3
3
|
*
|
|
4
4
|
* Three agent-facing documents describe the same host — the plain-text `GET /`
|
|
5
|
-
* (`
|
|
5
|
+
* (`shared/instructions.ts`), the landing page (`shared/landing.ts`) and
|
|
6
6
|
* `/llms.txt` (`shared/llms.ts`) — and the push path enforces what they
|
|
7
7
|
* describe. Each of them used to read the environment for itself, from three
|
|
8
8
|
* types that disagreed about how to spell "unset" and about which variables a
|
|
@@ -55,6 +55,7 @@ type CapabilityVar = Extract<
|
|
|
55
55
|
| 'WALGIT_PUBLIC'
|
|
56
56
|
| 'WALGIT_APPEND_ONLY'
|
|
57
57
|
| 'WALGIT_RETENTION_HOURS'
|
|
58
|
+
| 'WALGIT_CLAIMED_RETENTION_HOURS'
|
|
58
59
|
| 'WALGIT_MAX_PUSH_BYTES'
|
|
59
60
|
| 'WALGIT_MAX_REPO_BYTES'
|
|
60
61
|
| 'WALGIT_EVENTS_URL'
|
|
@@ -198,6 +199,19 @@ export type Capabilities = {
|
|
|
198
199
|
web: boolean
|
|
199
200
|
/** A repository is collected this many hours after its last push. */
|
|
200
201
|
retentionHours: number | null
|
|
202
|
+
/**
|
|
203
|
+
* A CLAIMED repository's window instead, when it is longer — `null` means a
|
|
204
|
+
* claim buys no extra time and `retentionHours` governs every repository.
|
|
205
|
+
*
|
|
206
|
+
* Null unless names can actually be claimed and expiry is on, because the
|
|
207
|
+
* sentence it feeds is "claim a name and it is kept longer": on a deployment
|
|
208
|
+
* where nobody can claim, or nothing is collected, there is nothing to say.
|
|
209
|
+
* And null unless it is LONGER, because a claim that shortened a name's life
|
|
210
|
+
* would punish the one act this deployment asks agents to perform — a value
|
|
211
|
+
* at or below the base window is a misconfiguration, read as unset rather
|
|
212
|
+
* than enforced.
|
|
213
|
+
*/
|
|
214
|
+
claimedRetentionHours: number | null
|
|
201
215
|
/** Largest single push, in bytes. */
|
|
202
216
|
maxPushBytes: number | null
|
|
203
217
|
/** Largest total size of one repository, in bytes. */
|
|
@@ -271,6 +285,10 @@ export function capabilitiesFrom(
|
|
|
271
285
|
const signedPushes = signedPushEnabled(env.WALGIT_PUSH_CERT_SEED)
|
|
272
286
|
const publicAccess = flagEnabled(env.WALGIT_PUBLIC)
|
|
273
287
|
|
|
288
|
+
const namesCanBeClaimed = namesCanRefuse && signedPushes
|
|
289
|
+
const retentionHours = positiveNumber(env.WALGIT_RETENTION_HOURS)
|
|
290
|
+
const claimedHours = positiveNumber(env.WALGIT_CLAIMED_RETENTION_HOURS)
|
|
291
|
+
|
|
274
292
|
const maxNewReposPerSource = positiveNumber(env.WALGIT_MAX_NEW_REPOS_PER_SOURCE)
|
|
275
293
|
const maxPushesPerSource = positiveNumber(env.WALGIT_MAX_PUSHES_PER_SOURCE)
|
|
276
294
|
const maxPushBytesPerSource = positiveNumber(env.WALGIT_MAX_PUSH_BYTES_PER_SOURCE)
|
|
@@ -284,7 +302,7 @@ export function capabilitiesFrom(
|
|
|
284
302
|
events: nonBlank(env.WALGIT_EVENTS_URL) && nonBlank(env.WALGIT_EVENTS_TOKEN),
|
|
285
303
|
signedPushes,
|
|
286
304
|
namesCanRefuse,
|
|
287
|
-
namesCanBeClaimed
|
|
305
|
+
namesCanBeClaimed,
|
|
288
306
|
namesCanBePrivate:
|
|
289
307
|
namesCanRefuse &&
|
|
290
308
|
signedPushes &&
|
|
@@ -292,7 +310,14 @@ export function capabilitiesFrom(
|
|
|
292
310
|
seedValue(env.WALGIT_PRIVATE_REPOS) !== null,
|
|
293
311
|
proposals: namesCanRefuse && signedPushes && flagEnabled(env.WALGIT_PROPOSALS),
|
|
294
312
|
web: flagEnabled(env.WALGIT_WEB),
|
|
295
|
-
retentionHours
|
|
313
|
+
retentionHours,
|
|
314
|
+
claimedRetentionHours:
|
|
315
|
+
namesCanBeClaimed &&
|
|
316
|
+
retentionHours !== null &&
|
|
317
|
+
claimedHours !== null &&
|
|
318
|
+
claimedHours > retentionHours
|
|
319
|
+
? claimedHours
|
|
320
|
+
: null,
|
|
296
321
|
maxPushBytes: positiveNumber(env.WALGIT_MAX_PUSH_BYTES),
|
|
297
322
|
maxRepoBytes: positiveNumber(env.WALGIT_MAX_REPO_BYTES),
|
|
298
323
|
sourceLimited:
|
|
@@ -9,11 +9,19 @@
|
|
|
9
9
|
* The only way a new value reaches the container is a new container.
|
|
10
10
|
*
|
|
11
11
|
* A `wrangler deploy` that changes only vars produces no new container image,
|
|
12
|
-
* so `--containers-rollout immediate`
|
|
12
|
+
* so `--containers-rollout immediate` had nothing to roll: the Worker picks the
|
|
13
13
|
* value up on its next request and the container keeps serving the old one, for
|
|
14
14
|
* as long as traffic keeps it awake. The fingerprint below is what closes that
|
|
15
15
|
* gap — the Durable Object compares it against the one it last booted with and
|
|
16
|
-
* replaces the container when they differ (
|
|
16
|
+
* replaces the container when they differ (`WalgitDurableContainer` in
|
|
17
|
+
* worker/durable-container.ts).
|
|
18
|
+
*
|
|
19
|
+
* Under the `durable_object` scheduling policy that is no longer one mechanism
|
|
20
|
+
* among two: there are no rollouts at all, and a deploy that ships a new image
|
|
21
|
+
* only changes which reference `ctx.container.images` hands out on the NEXT
|
|
22
|
+
* start. So the image reference is folded into the same fingerprint
|
|
23
|
+
* (`bootFingerprint`), and the replacement that already fired for a changed
|
|
24
|
+
* variable is now also the whole of how a new image reaches a running container.
|
|
17
25
|
*/
|
|
18
26
|
|
|
19
27
|
/**
|
|
@@ -54,6 +62,7 @@ export const CONTAINER_ENV = [
|
|
|
54
62
|
'WALGIT_PUBLIC',
|
|
55
63
|
'WALGIT_APPEND_ONLY',
|
|
56
64
|
'WALGIT_RETENTION_HOURS',
|
|
65
|
+
'WALGIT_CLAIMED_RETENTION_HOURS',
|
|
57
66
|
'WALGIT_MAX_PUSH_BYTES',
|
|
58
67
|
'WALGIT_MAX_REPO_BYTES',
|
|
59
68
|
// The ref-event stream's two halves. The push path announces from inside the
|
|
@@ -157,6 +166,36 @@ export function fingerprintEnv(env: Record<string, string>): string {
|
|
|
157
166
|
return (hash >>> 0).toString(16).padStart(8, '0')
|
|
158
167
|
}
|
|
159
168
|
|
|
169
|
+
/**
|
|
170
|
+
* The key the image reference is filed under inside `bootFingerprint`.
|
|
171
|
+
*
|
|
172
|
+
* `=` is the one character a POSIX environment variable's NAME can never hold
|
|
173
|
+
* — it is the separator in `NAME=value` — so no forwarded variable can collide
|
|
174
|
+
* with it, whatever `CONTAINER_ENV` grows to.
|
|
175
|
+
*/
|
|
176
|
+
const IMAGE_KEY = '=image'
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Everything a container is booted FROM, as one digest: the forwarded
|
|
180
|
+
* environment and the image reference.
|
|
181
|
+
*
|
|
182
|
+
* The image is here because the `durable_object` scheduling policy has no
|
|
183
|
+
* rollouts: a deploy that builds a new image changes only the digest-pinned
|
|
184
|
+
* reference `ctx.container.images` returns, and a container already running
|
|
185
|
+
* keeps its old image until something stops it. Folding the reference into the
|
|
186
|
+
* fingerprint makes that something `reconcileContainerEnv` — the replacement
|
|
187
|
+
* that already fires for a changed variable fires for a changed image too, with
|
|
188
|
+
* no second record and no second rule.
|
|
189
|
+
*
|
|
190
|
+
* An empty reference is fingerprinted like any other value rather than
|
|
191
|
+
* special-cased: it is what a Worker with no named image would pass, and that
|
|
192
|
+
* deployment then simply never replaces on an image change, which is all it
|
|
193
|
+
* could ever observe.
|
|
194
|
+
*/
|
|
195
|
+
export function bootFingerprint(env: Record<string, string>, image: string): string {
|
|
196
|
+
return fingerprintEnv({ ...env, [IMAGE_KEY]: image })
|
|
197
|
+
}
|
|
198
|
+
|
|
160
199
|
/**
|
|
161
200
|
* The half of a Durable Object that `reconcileContainerEnv` needs: whether a
|
|
162
201
|
* container is running, how to kill it, and where the fingerprint it booted
|