Files
tajniak81andClaude Opus 5.5 ba394b8fac Finish Phase 0: lint, codegen, contributor docs and the two remaining spikes
Repository basics:
- CONTRIBUTING.md and CODE_OF_CONDUCT.md (Contributor Covenant 2.1)
- SPDX AGPL-3.0-or-later headers on all hand-written sources, checked in CI
- golangci-lint (shared .golangci.yml), ESLint and Prettier, all run in CI

API codegen from api/openapi.yaml (npm run generate, drift fails CI):
- Go types via oapi-codegen in Server/internal/api
- a contract test that the router and the spec list the same routes
- Dart models via Phone-App/tool/generate_api.dart; the app uses them

Spike: shared Tiptap editor in a Flutter WebView (ADR-4)
- @docwell/editor-bridge builds the editor into one HTML page with a
  versioned JSON protocol; Phone-App hosts it with webview_flutter and a
  native toolbar. Integration test passes on an Android API 35 emulator.
- flutter_inappwebview dropped: its Android plugin fails on AGP 9.

Spike: Wails v3 desktop (ADR-11)
- system tray, docwell:// deep links (page and space only) with
  single-instance hand-off, and the built-in updater with a required
  ed25519 signing key. Verified on Windows.
- regenerated build assets register the scheme and drop template
  placeholders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 16:11:07 +01:00

82 lines
1.9 KiB
Go

// SPDX-License-Identifier: AGPL-3.0-or-later
package directory
import "strings"
// Sibling pages are ordered by a fractional index: a string key that sorts
// byte-wise (SQLite's default collation), so moving a page rewrites only that
// page. Keys use base-62 digits and never end in the zero digit, which leaves
// room for a key below any other.
const digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
// maxKeyLen is when to renumber siblings instead of growing keys further
// (pages.position allows 128 characters).
const maxKeyLen = 64
// keyBetween returns a key that sorts strictly between a and b. "" means no
// bound: keyBetween("", "") is the first key of an empty list.
func keyBetween(a, b string) string {
if b != "" {
n := 0
for n < len(b) && digitAt(a, n) == b[n] {
n++
}
if n > 0 {
return b[:n] + keyBetween(a[min(n, len(a)):], b[n:])
}
}
da := 0
if a != "" {
da = strings.IndexByte(digits, a[0])
}
db := len(digits)
if b != "" {
db = strings.IndexByte(digits, b[0])
}
if db-da > 1 {
return string(digits[(da+db+1)/2])
}
if len(b) > 1 {
return b[:1]
}
rest := ""
if a != "" {
rest = a[1:]
}
return string(digits[da]) + keyBetween(rest, "")
}
// digitAt is a's n-th byte, or the zero digit past its end.
func digitAt(a string, n int) byte {
if n < len(a) {
return a[n]
}
return digits[0]
}
// evenKeys returns n ascending keys spread evenly, all the same short length.
func evenKeys(n int) []string {
width, space := 1, len(digits)
for space < 2*(n+1) {
width++
space *= len(digits)
}
step := space / (n + 1)
keys := make([]string, n)
for i := range keys {
v := (i + 1) * step
b := make([]byte, width)
for j := width - 1; j >= 0; j-- {
b[j] = digits[v%len(digits)]
v /= len(digits)
}
// step >= 2, so bumping a trailing zero digit keeps keys distinct and ordered.
if b[width-1] == digits[0] {
b[width-1] = digits[1]
}
keys[i] = string(b)
}
return keys
}